feat(项目仪表盘):#132587 项目仪表盘中知识库类型动态转换

This commit is contained in:
wanjia 2025-07-23 14:21:59 +08:00
parent 6dc2dda918
commit 30daa7b00c
8 changed files with 88 additions and 45 deletions

View File

@ -7,10 +7,7 @@ import com.microservices.system.api.domain.SysLogininfor;
import com.microservices.system.api.domain.SysOperLog; import com.microservices.system.api.domain.SysOperLog;
import com.microservices.system.api.factory.RemoteLogFallbackFactory; import com.microservices.system.api.factory.RemoteLogFallbackFactory;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List; import java.util.List;
@ -45,10 +42,13 @@ public interface RemoteLogService
/** /**
* 获取操作日志列表 * 获取操作日志列表
* *
* @param title 日志标题
* @param operUrl 操作地址
* @param status 操作状态
* @param topN 获取最新N条
* @return 操作日志列表 * @return 操作日志列表
*/ */
@PostMapping("/latest") @GetMapping("/operlog/latest")
R<List<SysOperLog>> getLatestOperLogList(@RequestParam(value = "title", required = false) String title, R<List<SysOperLog>> getLatestOperLogList(@RequestParam(value = "title", required = false) String title,
@RequestParam(value = "operUrl", required = false) String operUrl, @RequestParam(value = "operUrl", required = false) String operUrl,
@RequestParam(value = "status", required = false) Integer status, @RequestParam(value = "status", required = false) Integer status,

View File

@ -42,7 +42,7 @@ public class RemoteLogFallbackFactory implements FallbackFactory<RemoteLogServic
@Override @Override
public R<List<SysOperLog>> getLatestOperLogList(String title, String operUrl, Integer status, Integer topN, String source) public R<List<SysOperLog>> getLatestOperLogList(String title, String operUrl, Integer status, Integer topN, String source)
{ {
return null; return R.fail("获取最新操作日志失败:" + throwable.getMessage());
} }
}; };

View File

@ -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_SS = "yyyy-MM-dd HH:mm:ss";
public static String YYYY_MM_DD_HH_MM = "yyyy-MM-dd HH:mm";
private static String[] parsePatterns = { 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",
"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",

View File

@ -114,7 +114,9 @@ public class PmsDocumentController extends BaseController {
@ApiOperation(value = "删除项目管理-文档库") @ApiOperation(value = "删除项目管理-文档库")
public AjaxResult remove(@PathVariable Long[] ids, public AjaxResult remove(@PathVariable Long[] ids,
@ApiParam("企业id") @RequestParam(name = "enterpriseId") Long enterpriseId, @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)); return toAjax(pmsDocumentService.deletePmsDocumentByIds(ids, enterpriseId, pmsProjectId));
} }

View File

@ -303,10 +303,10 @@ public class PmsProjectIssuesService {
private JSONObject genDeleteUserJsonObject() { private JSONObject genDeleteUserJsonObject() {
SysUser deleteUser = SysUser.genDeleteUser(); 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(); JSONObject user = new JSONObject();
user.put("id", gitlinkUserId); user.put("id", gitlinkUserId);
user.put("image_url", avatar); user.put("image_url", avatar);

View File

@ -109,10 +109,9 @@ public class PmsProjectServiceImpl implements IPmsProjectService {
@Autowired @Autowired
private RemoteLogService remoteLogService; private RemoteLogService remoteLogService;
@Resource
private PmsDocumentMapper pmsDocumentMapper;
private static final Logger logger = LoggerFactory.getLogger(PmsProjectServiceImpl.class); 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()); String operUrl = String.format("/%s/document", pmsEnterprise.getEnterpriseIdentifier());
List<SysOperLog> sysOperLogList = FeignUtils.getReturnData( List<SysOperLog> sysOperLogList = FeignUtils.getReturnData(
remoteLogService.getLatestOperLogList("项目管理-文档库", operUrl, 1, 10, SecurityConstants.INNER)); remoteLogService.getLatestOperLogList("项目管理-文档库", operUrl, 0, 10, SecurityConstants.INNER));
return sysOperLogList != null ? transferDocumentDynamics(sysOperLogList) : new JSONArray(); return sysOperLogList != null ? transferDocumentDynamics(sysOperLogList) : new JSONArray();
} }
@ -597,33 +596,46 @@ public class PmsProjectServiceImpl implements IPmsProjectService {
JSONArray journals = new JSONArray(); JSONArray journals = new JSONArray();
for (SysOperLog log : sysOperLogList) { for (SysOperLog log : sysOperLogList) {
JSONObject documentDynamics = new JSONObject(); 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()); 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"); String docName = operParam.getString("name");
Integer docType = operParam.getInteger("docType"); Integer docType = operParam.getInteger("docType");
Integer isTop = operParam.getInteger("isTop"); Integer isTop = operParam.getInteger("isTop");
Integer businessType = log.getBusinessType(); Integer businessType = log.getBusinessType();
if (BusinessType.DELETE.ordinal() == businessType) { String operateContent;
String operUrl = log.getOperUrl();
Long docId = Long.valueOf(operUrl.substring(operUrl.lastIndexOf("/") + 1)); Date operTime = log.getOperTime();
PmsDocument pmsDocument = pmsDocumentMapper.selectPmsDocumentById(docId); Long operTimeUnix = DateUtils.dateTimeToUnix(operTime);
if (pmsDocument != null) { documentDynamics.put("created_at", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM, operTime));
docName = pmsDocument.getName(); documentDynamics.put("updated_at", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM, operTime));
docType = pmsDocument.getDocType(); documentDynamics.put("created_time", operTimeUnix);
} documentDynamics.put("updated_time", operTimeUnix);
}
String docTypeName = PmsDocumentType.getNameByKey(docType); 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) { if (operateContent != null) {
documentDynamics.put("operate_content", operateContent); documentDynamics.put("operate_content", operateContent);
journals.add(documentDynamics); journals.add(documentDynamics);
@ -632,13 +644,39 @@ public class PmsProjectServiceImpl implements IPmsProjectService {
return journals; 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("<b>").append(nameArray[i]).append("</b>");
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) { switch (businessType) {
case 1: //新增 case 1: //新增
return String.format("在知识库%s了<b>%s</b>%s", return String.format("在知识库%s了<b>%s</b>%s",
docType == PmsDocumentType.ATTACHMENT.getKey() ? "上传" : "新建", docName, docTypeName); docType == PmsDocumentType.ATTACHMENT.getKey() ? "上传" : "新建", docName, docTypeName);
case 2: //更新 case 2: //更新
return String.format("在知识库%s了<b>%s</b>%s", isTop == 1 ? "置顶" : "更新", docName, docTypeName); return String.format("在知识库%s了<b>%s</b>%s", (isTop != null && isTop == 1) ? "置顶" : "更新", docName, docTypeName);
case 3: //删除 case 3: //删除
return String.format("在知识库删除了<b>%s</b>%s", docName, docTypeName); return String.format("在知识库删除了<b>%s</b>%s", docName, docTypeName);
default: default:
@ -647,7 +685,7 @@ public class PmsProjectServiceImpl implements IPmsProjectService {
} }
private JSONObject buildUserJson(SimpleSysUser simpleSysUser) { 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) { private void getTopNOrderedDynamics(JSONArray projectDynamics, int limit) {

View File

@ -1,5 +1,6 @@
package com.microservices.system.controller; 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.utils.poi.ExcelUtil;
import com.microservices.common.core.web.controller.BaseController; import com.microservices.common.core.web.controller.BaseController;
import com.microservices.common.core.web.domain.AjaxResult; import com.microservices.common.core.web.domain.AjaxResult;
@ -77,11 +78,11 @@ public class SysOperlogController extends BaseController
*/ */
@InnerAuth @InnerAuth
@GetMapping("/latest") @GetMapping("/latest")
public List<SysOperLog> list(@RequestParam(value = "title", required = false) String title, public R<List<SysOperLog>> latestList(@RequestParam(value = "title", required = false) String title,
@RequestParam(value = "operUrl", required = false) String operUrl, @RequestParam(value = "operUrl", required = false) String operUrl,
@RequestParam(value = "status", required = false) Integer status, @RequestParam(value = "status", required = false) Integer status,
@RequestParam(value = "topN") Integer topN) @RequestParam(value = "topN") Integer topN)
{ {
return operLogService.selectLatestOperLogList(title, operUrl, status, topN); return R.ok(operLogService.selectLatestOperLogList(title, operUrl, status, topN));
} }
} }

View File

@ -75,7 +75,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectOperLogVo"/> <include refid="selectOperLogVo"/>
where oper_id = #{operId} where oper_id = #{operId}
</select> </select>
<select id="selectLatestOperLogList" resultType="com.microservices.system.api.domain.SysOperLog"> <select id="selectLatestOperLogList" resultMap="SysOperLogResult">
<include refid="selectOperLogVo"/> <include refid="selectOperLogVo"/>
<where> <where>
<if test="title != null and title != ''"> <if test="title != null and title != ''">
@ -84,7 +84,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="status != null"> <if test="status != null">
AND status = #{status} AND status = #{status}
</if> </if>
<if test="oper_url != null and oper_url != ''"> <if test="operUrl != null and operUrl != ''">
AND oper_url like concat(#{operUrl}, '%') AND oper_url like concat(#{operUrl}, '%')
</if> </if>
</where> </where>