update
This commit is contained in:
@@ -15,10 +15,8 @@ import org.jeecg.common.aspect.annotation.AutoLog;
|
||||
import org.jeecg.common.system.base.controller.JeecgController;
|
||||
import org.jeecg.common.system.query.QueryGenerator;
|
||||
import org.jeecg.common.system.util.JwtUtil;
|
||||
import org.jeecg.modules.database.entity.DocumentHome;
|
||||
import org.jeecg.modules.database.entity.DocumentLibrary;
|
||||
import org.jeecg.modules.database.service.IDocumentFavoritesService;
|
||||
import org.jeecg.modules.database.service.IDocumentLibraryService;
|
||||
import org.jeecg.modules.database.entity.*;
|
||||
import org.jeecg.modules.database.service.*;
|
||||
import org.jeecg.modules.system.entity.SysUser;
|
||||
import org.jeecg.modules.system.service.ISysUserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -45,7 +43,9 @@ public class DocumentLibraryController extends JeecgController<DocumentLibrary,
|
||||
private IDocumentFavoritesService documentFavoritesService;
|
||||
|
||||
@Autowired
|
||||
private ISysUserService userService;
|
||||
private ISysUserService userService;
|
||||
@Autowired
|
||||
private IDocumentVisitHistoryService documentVisitHistoryService;
|
||||
|
||||
@Operation(summary = "知识库-首页查询")
|
||||
@GetMapping(value = "/home")
|
||||
@@ -111,8 +111,15 @@ public class DocumentLibraryController extends JeecgController<DocumentLibrary,
|
||||
@Operation(summary = "知识库-添加")
|
||||
@RequiresPermissions("library:document_library:add")
|
||||
@PostMapping(value = "/add")
|
||||
public Result<String> add(@RequestBody DocumentLibrary documentLibrary) {
|
||||
public Result<String> add(@RequestBody DocumentLibrary documentLibrary, HttpServletRequest request) {
|
||||
documentLibraryService.save(documentLibrary);
|
||||
String username = JwtUtil.getUserNameByToken(request);
|
||||
SysUser userByName = userService.getUserByName(username);
|
||||
DocumentVisitHistory his = new DocumentVisitHistory();
|
||||
his.setDocumentId(documentLibrary.getId());
|
||||
his.setUserId(userByName.getId());
|
||||
his.setVisitCount(1);
|
||||
documentVisitHistoryService.save(his);
|
||||
return Result.OK("添加成功!");
|
||||
}
|
||||
|
||||
@@ -126,8 +133,16 @@ public class DocumentLibraryController extends JeecgController<DocumentLibrary,
|
||||
@Operation(summary = "知识库-编辑")
|
||||
@RequiresPermissions("library:document_library:edit")
|
||||
@RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
|
||||
public Result<String> edit(@RequestBody DocumentLibrary documentLibrary) {
|
||||
public Result<String> edit(@RequestBody DocumentLibrary documentLibrary, HttpServletRequest request) {
|
||||
documentLibraryService.updateById(documentLibrary);
|
||||
|
||||
String username = JwtUtil.getUserNameByToken(request);
|
||||
SysUser userByName = userService.getUserByName(username);
|
||||
DocumentVisitHistory his = documentVisitHistoryService.findByUserAndDocId(userByName.getId(), documentLibrary.getId());
|
||||
his.setDocumentId(documentLibrary.getId());
|
||||
his.setUserId(userByName.getId());
|
||||
his.addVisitCount();
|
||||
documentVisitHistoryService.saveOrUpdate(his);
|
||||
return Result.OK("编辑成功!");
|
||||
}
|
||||
|
||||
@@ -170,11 +185,19 @@ public class DocumentLibraryController extends JeecgController<DocumentLibrary,
|
||||
//@AutoLog(value = "知识库-通过id查询")
|
||||
@Operation(summary = "知识库-通过id查询")
|
||||
@GetMapping(value = "/queryById")
|
||||
public Result<DocumentLibrary> queryById(@RequestParam(name = "id", required = true) String id) {
|
||||
public Result<DocumentLibrary> queryById(@RequestParam(name = "id", required = true) String id, HttpServletRequest request) {
|
||||
DocumentLibrary documentLibrary = documentLibraryService.getById(id);
|
||||
if (documentLibrary == null) {
|
||||
return Result.error("未找到对应数据");
|
||||
}
|
||||
|
||||
String username = JwtUtil.getUserNameByToken(request);
|
||||
SysUser userByName = userService.getUserByName(username);
|
||||
DocumentVisitHistory his = documentVisitHistoryService.findByUserAndDocId(userByName.getId(), documentLibrary.getId());
|
||||
his.setDocumentId(documentLibrary.getId());
|
||||
his.setUserId(userByName.getId());
|
||||
his.addVisitCount();
|
||||
documentVisitHistoryService.saveOrUpdate(his);
|
||||
return Result.OK(documentLibrary);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,162 @@
|
||||
package org.jeecg.modules.database.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.aspect.annotation.AutoLog;
|
||||
import org.jeecg.common.system.base.controller.JeecgController;
|
||||
import org.jeecg.common.system.query.QueryGenerator;
|
||||
import org.jeecg.modules.database.entity.DocumentVisitHistory;
|
||||
import org.jeecg.modules.database.service.IDocumentVisitHistoryService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @Description: 文档访问历史
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2024-11-14
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Tag(name = "文档访问历史")
|
||||
@RestController
|
||||
@RequestMapping("/library/documentVisitHistory")
|
||||
@Slf4j
|
||||
public class DocumentVisitHistoryController extends JeecgController<DocumentVisitHistory, IDocumentVisitHistoryService> {
|
||||
@Autowired
|
||||
private IDocumentVisitHistoryService documentVisitHistoryService;
|
||||
|
||||
/**
|
||||
* 分页列表查询
|
||||
*
|
||||
* @param documentVisitHistory
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
//@AutoLog(value = "文档访问历史-分页列表查询")
|
||||
@Operation(summary = "文档访问历史-分页列表查询")
|
||||
@GetMapping(value = "/list")
|
||||
public Result<IPage<DocumentVisitHistory>> queryPageList(DocumentVisitHistory documentVisitHistory,
|
||||
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
|
||||
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
|
||||
HttpServletRequest req) {
|
||||
QueryWrapper<DocumentVisitHistory> queryWrapper = QueryGenerator.initQueryWrapper(documentVisitHistory, req.getParameterMap());
|
||||
Page<DocumentVisitHistory> page = new Page<DocumentVisitHistory>(pageNo, pageSize);
|
||||
IPage<DocumentVisitHistory> pageList = documentVisitHistoryService.page(page, queryWrapper);
|
||||
return Result.OK(pageList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @param documentVisitHistory
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "文档访问历史-添加")
|
||||
@Operation(summary = "文档访问历史-添加")
|
||||
@RequiresPermissions("library:document_visit_history:add")
|
||||
@PostMapping(value = "/add")
|
||||
public Result<String> add(@RequestBody DocumentVisitHistory documentVisitHistory) {
|
||||
documentVisitHistoryService.save(documentVisitHistory);
|
||||
return Result.OK("添加成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param documentVisitHistory
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "文档访问历史-编辑")
|
||||
@Operation(summary = "文档访问历史-编辑")
|
||||
@RequiresPermissions("library:document_visit_history:edit")
|
||||
@RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
|
||||
public Result<String> edit(@RequestBody DocumentVisitHistory documentVisitHistory) {
|
||||
documentVisitHistoryService.updateById(documentVisitHistory);
|
||||
return Result.OK("编辑成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "文档访问历史-通过id删除")
|
||||
@Operation(summary = "文档访问历史-通过id删除")
|
||||
@RequiresPermissions("library:document_visit_history:delete")
|
||||
@DeleteMapping(value = "/delete")
|
||||
public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
|
||||
documentVisitHistoryService.removeById(id);
|
||||
return Result.OK("删除成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "文档访问历史-批量删除")
|
||||
@Operation(summary = "文档访问历史-批量删除")
|
||||
@RequiresPermissions("library:document_visit_history:deleteBatch")
|
||||
@DeleteMapping(value = "/deleteBatch")
|
||||
public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
|
||||
this.documentVisitHistoryService.removeByIds(Arrays.asList(ids.split(",")));
|
||||
return Result.OK("批量删除成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查询
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
//@AutoLog(value = "文档访问历史-通过id查询")
|
||||
@Operation(summary = "文档访问历史-通过id查询")
|
||||
@GetMapping(value = "/queryById")
|
||||
public Result<DocumentVisitHistory> queryById(@RequestParam(name = "id", required = true) String id) {
|
||||
DocumentVisitHistory documentVisitHistory = documentVisitHistoryService.getById(id);
|
||||
if (documentVisitHistory == null) {
|
||||
return Result.error("未找到对应数据");
|
||||
}
|
||||
return Result.OK(documentVisitHistory);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出excel
|
||||
*
|
||||
* @param request
|
||||
* @param documentVisitHistory
|
||||
*/
|
||||
@RequiresPermissions("library:document_visit_history:exportXls")
|
||||
@RequestMapping(value = "/exportXls")
|
||||
public ModelAndView exportXls(HttpServletRequest request, DocumentVisitHistory documentVisitHistory) {
|
||||
return super.exportXls(request, documentVisitHistory, DocumentVisitHistory.class, "文档访问历史");
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过excel导入数据
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("library:document_visit_history:importExcel")
|
||||
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
||||
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
||||
return super.importExcel(request, response, DocumentVisitHistory.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
package org.jeecg.modules.database.entity;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@@ -19,7 +20,10 @@ import java.util.List;
|
||||
public class DocumentHome implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "我的收藏")
|
||||
private List<DocumentFavorites> favorite;
|
||||
@Schema(description = "最新文档")
|
||||
private List<DocumentLibrary> latest;
|
||||
@Schema(description = "最近访问")
|
||||
private List<DocumentLibrary> recently;
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package org.jeecg.modules.database.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Description: 文档访问历史
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2024-11-14
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Data
|
||||
@TableName("document_visit_history")
|
||||
@Accessors(chain = true)
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Schema(description = "文档访问历史")
|
||||
public class DocumentVisitHistory implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@Schema(description = "主键")
|
||||
private String id;
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
@Schema(description = "创建人")
|
||||
private String createBy;
|
||||
/**
|
||||
* 创建日期
|
||||
*/
|
||||
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Schema(description = "创建日期")
|
||||
private Date createTime;
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
@Schema(description = "更新人")
|
||||
private String updateBy;
|
||||
/**
|
||||
* 更新日期
|
||||
*/
|
||||
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Schema(description = "更新日期")
|
||||
private Date updateTime;
|
||||
/**
|
||||
* 所属部门
|
||||
*/
|
||||
@Schema(description = "所属部门")
|
||||
private String sysOrgCode;
|
||||
/**
|
||||
* 文档ID
|
||||
*/
|
||||
@Excel(name = "文档ID", width = 15)
|
||||
@Schema(description = "文档ID")
|
||||
private String documentId;
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
@Excel(name = "用户ID", width = 15)
|
||||
@Schema(description = "用户ID")
|
||||
private String userId;
|
||||
/**
|
||||
* 文档标题
|
||||
*/
|
||||
@Excel(name = "文档标题", width = 15)
|
||||
@Schema(description = "文档标题")
|
||||
private String documentTitle;
|
||||
/**
|
||||
* 访问次数
|
||||
*/
|
||||
@Excel(name = "访问次数", width = 15)
|
||||
@Schema(description = "访问次数")
|
||||
private Integer visitCount;
|
||||
|
||||
public void addVisitCount() {
|
||||
if (this.visitCount == null) {
|
||||
this.visitCount = 0;
|
||||
}
|
||||
this.visitCount++;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.jeecg.modules.database.mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.jeecg.modules.database.entity.DocumentVisitHistory;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* @Description: 文档访问历史
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2024-11-14
|
||||
* @Version: V1.0
|
||||
*/
|
||||
public interface DocumentVisitHistoryMapper extends BaseMapper<DocumentVisitHistory> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.jeecg.modules.database.mapper.DocumentVisitHistoryMapper">
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,14 @@
|
||||
package org.jeecg.modules.database.service;
|
||||
|
||||
import org.jeecg.modules.database.entity.DocumentVisitHistory;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* @Description: 文档访问历史
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2024-11-14
|
||||
* @Version: V1.0
|
||||
*/
|
||||
public interface IDocumentVisitHistoryService extends IService<DocumentVisitHistory> {
|
||||
DocumentVisitHistory findByUserAndDocId(String userId, String documentId);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package org.jeecg.modules.database.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.jeecg.modules.database.entity.DocumentVisitHistory;
|
||||
import org.jeecg.modules.database.mapper.DocumentVisitHistoryMapper;
|
||||
import org.jeecg.modules.database.service.IDocumentVisitHistoryService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @Description: 文档访问历史
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2024-11-14
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Service
|
||||
public class DocumentVisitHistoryServiceImpl extends ServiceImpl<DocumentVisitHistoryMapper, DocumentVisitHistory>
|
||||
implements IDocumentVisitHistoryService {
|
||||
|
||||
@Override
|
||||
public DocumentVisitHistory findByUserAndDocId(String userId, String documentId) {
|
||||
DocumentVisitHistory one = getOne(new LambdaQueryWrapper<DocumentVisitHistory>().eq(DocumentVisitHistory::getUserId, userId)
|
||||
.eq(DocumentVisitHistory::getDocumentId, documentId));
|
||||
if (Objects.isNull(one)) {
|
||||
DocumentVisitHistory documentVisitHistory = new DocumentVisitHistory();
|
||||
documentVisitHistory.setUserId(userId);
|
||||
documentVisitHistory.setDocumentId(documentId);
|
||||
documentVisitHistory.setVisitCount(1);
|
||||
return documentVisitHistory;
|
||||
}
|
||||
return one;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user