diff --git a/microservices-api/microservices-api-system/src/main/java/com/microservices/system/api/RemoteLogService.java b/microservices-api/microservices-api-system/src/main/java/com/microservices/system/api/RemoteLogService.java index 18f310ebd..73472188e 100644 --- a/microservices-api/microservices-api-system/src/main/java/com/microservices/system/api/RemoteLogService.java +++ b/microservices-api/microservices-api-system/src/main/java/com/microservices/system/api/RemoteLogService.java @@ -7,10 +7,7 @@ import com.microservices.system.api.domain.SysLogininfor; import com.microservices.system.api.domain.SysOperLog; import com.microservices.system.api.factory.RemoteLogFallbackFactory; import org.springframework.cloud.openfeign.FeignClient; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.*; import java.util.List; @@ -45,10 +42,13 @@ public interface RemoteLogService /** * 获取操作日志列表 * - + * @param title 日志标题 + * @param operUrl 操作地址 + * @param status 操作状态 + * @param topN 获取最新N条 * @return 操作日志列表 */ - @PostMapping("/latest") + @GetMapping("/operlog/latest") R> getLatestOperLogList(@RequestParam(value = "title", required = false) String title, @RequestParam(value = "operUrl", required = false) String operUrl, @RequestParam(value = "status", required = false) Integer status, diff --git a/microservices-api/microservices-api-system/src/main/java/com/microservices/system/api/factory/RemoteLogFallbackFactory.java b/microservices-api/microservices-api-system/src/main/java/com/microservices/system/api/factory/RemoteLogFallbackFactory.java index 2d8205526..3454bc42e 100644 --- a/microservices-api/microservices-api-system/src/main/java/com/microservices/system/api/factory/RemoteLogFallbackFactory.java +++ b/microservices-api/microservices-api-system/src/main/java/com/microservices/system/api/factory/RemoteLogFallbackFactory.java @@ -42,7 +42,7 @@ public class RemoteLogFallbackFactory implements FallbackFactory> getLatestOperLogList(String title, String operUrl, Integer status, Integer topN, String source) { - return null; + return R.fail("获取最新操作日志失败:" + throwable.getMessage()); } }; diff --git a/microservices-common/microservices-common-core/src/main/java/com/microservices/common/core/utils/DateUtils.java b/microservices-common/microservices-common-core/src/main/java/com/microservices/common/core/utils/DateUtils.java index 03404a2d5..7746da938 100644 --- a/microservices-common/microservices-common-core/src/main/java/com/microservices/common/core/utils/DateUtils.java +++ b/microservices-common/microservices-common-core/src/main/java/com/microservices/common/core/utils/DateUtils.java @@ -26,6 +26,8 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss"; + public static String YYYY_MM_DD_HH_MM = "yyyy-MM-dd HH:mm"; + private static String[] parsePatterns = { "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM", "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM", diff --git a/microservices-modules/microservices-modules-pms/src/main/java/com/microservices/pms/document/controller/PmsDocumentController.java b/microservices-modules/microservices-modules-pms/src/main/java/com/microservices/pms/document/controller/PmsDocumentController.java index 0712f6382..88060590f 100644 --- a/microservices-modules/microservices-modules-pms/src/main/java/com/microservices/pms/document/controller/PmsDocumentController.java +++ b/microservices-modules/microservices-modules-pms/src/main/java/com/microservices/pms/document/controller/PmsDocumentController.java @@ -114,7 +114,9 @@ public class PmsDocumentController extends BaseController { @ApiOperation(value = "删除项目管理-文档库") public AjaxResult remove(@PathVariable Long[] ids, @ApiParam("企业id") @RequestParam(name = "enterpriseId") Long enterpriseId, - @ApiParam("项目id") @RequestParam(name = "pmsProjectId", defaultValue = "0") Long pmsProjectId) { + @ApiParam("项目id") @RequestParam(name = "pmsProjectId", defaultValue = "0") Long pmsProjectId, + @ApiParam("文档名称,多个逗号分隔") @RequestParam(name = "names", required = false) String names, + @ApiParam("文件类型 1-文档目录 2-文档 3-附件 4-wiki库,多个逗号分隔") @RequestParam(name = "docTypes", required = false) String docTypes) { return toAjax(pmsDocumentService.deletePmsDocumentByIds(ids, enterpriseId, pmsProjectId)); } diff --git a/microservices-modules/microservices-modules-pms/src/main/java/com/microservices/pms/project/service/PmsProjectIssuesService.java b/microservices-modules/microservices-modules-pms/src/main/java/com/microservices/pms/project/service/PmsProjectIssuesService.java index baa9b2c2a..912af6012 100644 --- a/microservices-modules/microservices-modules-pms/src/main/java/com/microservices/pms/project/service/PmsProjectIssuesService.java +++ b/microservices-modules/microservices-modules-pms/src/main/java/com/microservices/pms/project/service/PmsProjectIssuesService.java @@ -303,10 +303,10 @@ public class PmsProjectIssuesService { private JSONObject genDeleteUserJsonObject() { SysUser deleteUser = SysUser.genDeleteUser(); - return getUserJsonObject(deleteUser.getGitlinkUserId(), deleteUser.getAvatar(), deleteUser.getUserName(), deleteUser.getNickName(), simpleSysUser); + return getUserJsonObject(deleteUser.getGitlinkUserId(), deleteUser.getAvatar(), deleteUser.getUserName(), deleteUser.getNickName()); } - public JSONObject getUserJsonObject(Long gitlinkUserId, String avatar, String userName, String nickName, SimpleSysUser simpleSysUser) { + public JSONObject getUserJsonObject(Long gitlinkUserId, String avatar, String userName, String nickName) { JSONObject user = new JSONObject(); user.put("id", gitlinkUserId); user.put("image_url", avatar); diff --git a/microservices-modules/microservices-modules-pms/src/main/java/com/microservices/pms/project/service/impl/PmsProjectServiceImpl.java b/microservices-modules/microservices-modules-pms/src/main/java/com/microservices/pms/project/service/impl/PmsProjectServiceImpl.java index 070fb94d3..5c300923d 100644 --- a/microservices-modules/microservices-modules-pms/src/main/java/com/microservices/pms/project/service/impl/PmsProjectServiceImpl.java +++ b/microservices-modules/microservices-modules-pms/src/main/java/com/microservices/pms/project/service/impl/PmsProjectServiceImpl.java @@ -109,10 +109,9 @@ public class PmsProjectServiceImpl implements IPmsProjectService { @Autowired private RemoteLogService remoteLogService; - @Resource - private PmsDocumentMapper pmsDocumentMapper; - private static final Logger logger = LoggerFactory.getLogger(PmsProjectServiceImpl.class); + @Autowired + private PmsDocumentMapper pmsDocumentMapper; /** * 查询项目 @@ -589,7 +588,7 @@ public class PmsProjectServiceImpl implements IPmsProjectService { String operUrl = String.format("/%s/document", pmsEnterprise.getEnterpriseIdentifier()); List sysOperLogList = FeignUtils.getReturnData( - remoteLogService.getLatestOperLogList("项目管理-文档库", operUrl, 1, 10, SecurityConstants.INNER)); + remoteLogService.getLatestOperLogList("项目管理-文档库", operUrl, 0, 10, SecurityConstants.INNER)); return sysOperLogList != null ? transferDocumentDynamics(sysOperLogList) : new JSONArray(); } @@ -597,33 +596,46 @@ public class PmsProjectServiceImpl implements IPmsProjectService { JSONArray journals = new JSONArray(); for (SysOperLog log : sysOperLogList) { JSONObject documentDynamics = new JSONObject(); - JSONObject user = buildUserJson(pmsCommonService.getSimpleSysUserByUsername(log.getOperName())); - documentDynamics.put("user", user); - - Date operTime = log.getOperTime(); - Long operTimeUnix = DateUtils.dateTimeToUnix(operTime); - documentDynamics.put("created_at", operTime); - documentDynamics.put("updated_at", operTime); - documentDynamics.put("operate_time", operTimeUnix); - documentDynamics.put("updated_time", operTimeUnix); - JSONObject operParam = JSONObject.parseObject(log.getOperParam()); + Integer pmsProjectId = operParam.getInteger("pmsProjectId"); + if (pmsProjectId == 0) { + continue; + } + Long documentId = operParam.getLong("id"); String docName = operParam.getString("name"); Integer docType = operParam.getInteger("docType"); Integer isTop = operParam.getInteger("isTop"); Integer businessType = log.getBusinessType(); - if (BusinessType.DELETE.ordinal() == businessType) { - String operUrl = log.getOperUrl(); - Long docId = Long.valueOf(operUrl.substring(operUrl.lastIndexOf("/") + 1)); - PmsDocument pmsDocument = pmsDocumentMapper.selectPmsDocumentById(docId); - if (pmsDocument != null) { - docName = pmsDocument.getName(); - docType = pmsDocument.getDocType(); - } - } - String docTypeName = PmsDocumentType.getNameByKey(docType); + String operateContent; + + Date operTime = log.getOperTime(); + Long operTimeUnix = DateUtils.dateTimeToUnix(operTime); + documentDynamics.put("created_at", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM, operTime)); + documentDynamics.put("updated_at", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM, operTime)); + documentDynamics.put("created_time", operTimeUnix); + documentDynamics.put("updated_time", operTimeUnix); + + JSONObject user = buildUserJson(pmsCommonService.getSimpleSysUserByUsername(log.getOperName())); + documentDynamics.put("user", user); + + if (BusinessType.DELETE.ordinal() == businessType) { + String docNames = operParam.getString("names"); + String docTypes = operParam.getString("docTypes"); + operateContent = generateBatchDeleteOperateContent(docNames, docTypes); + } else { + if (isTop != null && isTop == 1) { + PmsDocument pmsDocument = pmsDocumentMapper.selectPmsDocumentById(documentId); + if (pmsDocument != null) { + docName = pmsDocument.getName(); + docType = pmsDocument.getDocType(); + } + } + if (docName == null || docType == null) { + continue; + } + operateContent = generateOperateContent(businessType, docType, docName, isTop); + } - String operateContent = generateOperateContent(businessType, docType, docName, docTypeName, isTop); if (operateContent != null) { documentDynamics.put("operate_content", operateContent); journals.add(documentDynamics); @@ -632,13 +644,39 @@ public class PmsProjectServiceImpl implements IPmsProjectService { return journals; } - private String generateOperateContent(Integer businessType, Integer docType, String docName, String docTypeName, Integer isTop) { + private String generateBatchDeleteOperateContent(String docNames, String docTypes) { + if (docNames == null || docTypes == null) { + return null; + } + String[] nameArray = docNames.split(","); + String[] typeArray = docTypes.split(","); + if (nameArray.length != typeArray.length) { + return null; + } + StringBuilder sb = new StringBuilder(); + sb.append("在知识库删除了"); + for (int i = 0; i < nameArray.length; i++) { + if (i > 0) { + sb.append(" , "); + } + sb.append("").append(nameArray[i]).append(""); + sb.append(getNameByKey(Integer.parseInt(typeArray[i]))); + } + return sb.toString(); + } + + private static String getNameByKey(Integer docType) { + return PmsDocumentType.getNameByKey(docType); + } + + private String generateOperateContent(Integer businessType, Integer docType, String docName, Integer isTop) { + String docTypeName = getNameByKey(docType); switch (businessType) { case 1: //新增 return String.format("在知识库%s了%s%s", docType == PmsDocumentType.ATTACHMENT.getKey() ? "上传" : "新建", docName, docTypeName); case 2: //更新 - return String.format("在知识库%s了%s%s", isTop == 1 ? "置顶" : "更新", docName, docTypeName); + return String.format("在知识库%s了%s%s", (isTop != null && isTop == 1) ? "置顶" : "更新", docName, docTypeName); case 3: //删除 return String.format("在知识库删除了%s%s", docName, docTypeName); default: @@ -647,7 +685,7 @@ public class PmsProjectServiceImpl implements IPmsProjectService { } private JSONObject buildUserJson(SimpleSysUser simpleSysUser) { - return pmsProjectIssuesService.getUserJsonObject(simpleSysUser.getGitlinkUserId(), simpleSysUser.getAvatar(), simpleSysUser.getUserName(), simpleSysUser.getNickName(), simpleSysUser); + return pmsProjectIssuesService.getUserJsonObject(simpleSysUser.getGitlinkUserId(), simpleSysUser.getAvatar(), simpleSysUser.getUserName(), simpleSysUser.getNickName()); } private void getTopNOrderedDynamics(JSONArray projectDynamics, int limit) { diff --git a/microservices-modules/microservices-modules-system/src/main/java/com/microservices/system/controller/SysOperlogController.java b/microservices-modules/microservices-modules-system/src/main/java/com/microservices/system/controller/SysOperlogController.java index b64e023c8..cef415f6f 100644 --- a/microservices-modules/microservices-modules-system/src/main/java/com/microservices/system/controller/SysOperlogController.java +++ b/microservices-modules/microservices-modules-system/src/main/java/com/microservices/system/controller/SysOperlogController.java @@ -1,5 +1,6 @@ package com.microservices.system.controller; +import com.microservices.common.core.domain.R; import com.microservices.common.core.utils.poi.ExcelUtil; import com.microservices.common.core.web.controller.BaseController; import com.microservices.common.core.web.domain.AjaxResult; @@ -77,11 +78,11 @@ public class SysOperlogController extends BaseController */ @InnerAuth @GetMapping("/latest") - public List list(@RequestParam(value = "title", required = false) String title, - @RequestParam(value = "operUrl", required = false) String operUrl, - @RequestParam(value = "status", required = false) Integer status, - @RequestParam(value = "topN") Integer topN) + public R> latestList(@RequestParam(value = "title", required = false) String title, + @RequestParam(value = "operUrl", required = false) String operUrl, + @RequestParam(value = "status", required = false) Integer status, + @RequestParam(value = "topN") Integer topN) { - return operLogService.selectLatestOperLogList(title, operUrl, status, topN); + return R.ok(operLogService.selectLatestOperLogList(title, operUrl, status, topN)); } } diff --git a/microservices-modules/microservices-modules-system/src/main/resources/mapper/system/SysOperLogMapper.xml b/microservices-modules/microservices-modules-system/src/main/resources/mapper/system/SysOperLogMapper.xml index e3c508edf..ba9706f65 100644 --- a/microservices-modules/microservices-modules-system/src/main/resources/mapper/system/SysOperLogMapper.xml +++ b/microservices-modules/microservices-modules-system/src/main/resources/mapper/system/SysOperLogMapper.xml @@ -75,7 +75,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where oper_id = #{operId} - @@ -84,7 +84,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" AND status = #{status} - + AND oper_url like concat(#{operUrl}, '%')