From 40bfb646d1b962d33841c1ebbceb0dd7cb668bfb Mon Sep 17 00:00:00 2001 From: liujie <1793218484@qq.com> Date: 星期二, 29 四月 2025 14:54:04 +0800 Subject: [PATCH] 后台日志管理 --- springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/aspectj/OperLogAspect.java | 211 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 197 insertions(+), 14 deletions(-) diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/aspectj/OperLogAspect.java b/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/aspectj/OperLogAspect.java index 8163ffe..444a2e6 100644 --- a/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/aspectj/OperLogAspect.java +++ b/springcloud_k8s_panzhihuazhihuishequ/service_sangeshenbian/src/main/java/com/panzhihua/sangeshenbian/aspectj/OperLogAspect.java @@ -3,9 +3,13 @@ import com.alibaba.fastjson.JSONObject; import com.panzhihua.common.controller.BaseController; import com.panzhihua.common.model.vos.sangeshenbian.SystemUserVo; +import com.panzhihua.common.utlis.StringUtils; import com.panzhihua.sangeshenbian.annotation.SysLog; -import com.panzhihua.sangeshenbian.model.entity.SystemLog; +import com.panzhihua.sangeshenbian.model.entity.*; import com.panzhihua.sangeshenbian.service.ISystemLogService; +import com.panzhihua.sangeshenbian.warpper.AddSystemRole; +import com.panzhihua.sangeshenbian.warpper.EditSystemRole; +import com.panzhihua.sangeshenbian.warpper.PartyMemberDTO; import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.AfterReturning; @@ -53,29 +57,208 @@ MethodSignature signature = (MethodSignature)joinPoint.getSignature(); // 获取切入点所在的方法 Method method = signature.getMethod(); + Object[] args = joinPoint.getArgs(); try { // 获取操作 SysLog opLog = method.getAnnotation(SysLog.class); SystemLog sysLog = new SystemLog(); - if("登录".equals(opLog.operatorCategory())){ - // 将返回结果转为JSON对象 - JSONObject jsonResult = JSONObject.parseObject(JSONObject.toJSONString(keys)); + JSONObject jsonResult = JSONObject.parseObject(JSONObject.toJSONString(keys)); - // 提取data字段中的TokenVo信息 - JSONObject data = jsonResult.getJSONObject("data"); - Long userId = data.getLong("userId"); - String name = data.getString("name");// 直接获取userId - sysLog.setOperatorId(Long.valueOf(userId)); - sysLog.setTargetName(name); - }else { + + switch (opLog.operId()){ + // 登录 + case 1:// 将返回结果转为JSON对象 + // 提取data字段中的TokenVo信息 + JSONObject data = jsonResult.getJSONObject("data"); + Long userId = data.getLong("userId"); + String name = data.getString("name");// 直接获取userId + sysLog.setOperatorId(Long.valueOf(userId)); + sysLog.setTargetName(name); + break; + // 职位 + case 2: + if(opLog.operatorCategory().contains("删除")){ + String postName = jsonResult.get("data").toString(); + sysLog.setTargetName(postName); + }else { + for (Object arg : args) { + if (arg instanceof SystemPost) { + SystemPost systemPost = (SystemPost) arg; + sysLog.setTargetName(systemPost.getName()); + } + } + } + + break; + // 角色 + case 3: + if(opLog.operatorCategory().contains("删除")){ + String postName = jsonResult.get("data").toString(); + sysLog.setTargetName(postName); + }else { + for (Object arg : args) { + if (arg instanceof AddSystemRole) { + AddSystemRole systemRole = (AddSystemRole) arg; + sysLog.setTargetName(systemRole.getName()); + } + if (arg instanceof EditSystemRole) { + EditSystemRole systemRole = (EditSystemRole) arg; + sysLog.setTargetName(systemRole.getName()); + } + } + } + + break; + // 账号 + case 4: + if(opLog.operatorCategory().contains("删除")){ + String postName = jsonResult.get("data").toString(); + sysLog.setTargetName(postName); + }else { + for (Object arg : args) { + if (arg instanceof SystemUser) { + SystemUser systemUser = (SystemUser) arg; + sysLog.setTargetName(systemUser.getName()); + } + } + } + break; + // 工单 + case 5: + for (Object arg : args) { + if (arg instanceof WorkOrderItemConfig) { + WorkOrderItemConfig workOrderItemConfig = (WorkOrderItemConfig) arg; + // 拿到返回原来的数据 + JSONObject configData = jsonResult.getJSONObject("data"); + String targetName=""; + // 判断是否修改了诉求处理时间 + if(workOrderItemConfig.getDemandProcessingTime()!=configData.getInteger("demandProcessingTime")){ + targetName += "修改诉求处理时间、"; + } + // 判断是否修改了市级账号诉求处理时间 + if(workOrderItemConfig.getCityHandlingTime()!=configData.getInteger("cityHandlingTime") + || workOrderItemConfig.getDistrictHandlingTime()!=configData.getInteger("districtHandlingTime") + || workOrderItemConfig.getStreetHandlingTime()!=configData.getInteger("streetHandlingTime") + || workOrderItemConfig.getCommunityHandlingTime()!=configData.getInteger("communityHandlingTime") + || workOrderItemConfig.getPartyMemberHandlingTime()!=configData.getInteger("partyMemberHandlingTime")){ + targetName += "修改处理超时时间、"; + } + if(workOrderItemConfig.getCityDeadlineReminder()!=configData.getInteger("cityDeadlineReminder") + || workOrderItemConfig.getDistrictDeadlineReminder()!=configData.getInteger("districtDeadlineReminder") + || workOrderItemConfig.getStreetDeadlineReminder()!=configData.getInteger("streetDeadlineReminder") + || workOrderItemConfig.getCommunityDeadlineReminder()!=configData.getInteger("communityDeadlineReminder") + ){ + targetName += "修改临期提醒时间、"; + } + if(StringUtils.isNotEmpty(targetName)){ + targetName= targetName.substring(0,targetName.length()-1); + sysLog.setTargetName(targetName); + } + } + } + break; + // 问题 + case 6: + if(opLog.operatorCategory().contains("删除")){ + String postName = jsonResult.get("data").toString(); + sysLog.setTargetName(postName); + }else { + for (Object arg : args) { + if (arg instanceof ProblemType) { + ProblemType problemType = (ProblemType) arg; + sysLog.setTargetName(problemType.getName()); + } + } + } + // banner + case 7: + if(opLog.operatorCategory().contains("删除")){ + String postName = jsonResult.get("data").toString(); + sysLog.setTargetName(postName); + }else { + for (Object arg : args) { + if (arg instanceof Banner) { + Banner banner = (Banner) arg; + sysLog.setTargetName(banner.getName()); + } + } + } + break; + // 党员 + case 8: + if(opLog.operatorCategory().contains("删除")){ + String postName = jsonResult.get("data").toString(); + sysLog.setOperatorCategory("删除党员"); + sysLog.setTargetName(postName); + }else { + for (Object arg : args) { + if (arg instanceof PartyMemberDTO) { + PartyMemberDTO memberDTO = (PartyMemberDTO) arg; + sysLog.setTargetName(memberDTO.getName()); + if(opLog.operatorCategory().contains("添加")){ + if(memberDTO.getId()==null){ + sysLog.setOperatorCategory("添加党员"); + }else { + sysLog.setOperatorCategory("编辑党员"); + } + } + }else if(opLog.operatorCategory().contains("冻结")){ + JSONObject freezeData = jsonResult.getJSONObject("data"); + sysLog.setTargetName(freezeData.getString("name")); + if(freezeData.getInteger("freezeStatus")==1){ + sysLog.setOperatorCategory("冻结党员"); + }else { + sysLog.setOperatorCategory("解冻党员"); + } + }else { + sysLog.setOperatorCategory(opLog.operatorCategory()); + } + } + } + break; + // 党员审核 + case 9: + + JSONObject auditData = jsonResult.getJSONObject("data"); + sysLog.setTargetName(auditData.getString("name")); + if(auditData.getInteger("auditStatus")==1){ + sysLog.setOperatorCategory("党员审核通过"); + }else { + sysLog.setOperatorCategory("党员审核拒绝"); + } + break; + // 导出 + case 10: + if(opLog.operatorCategory().equals("单导出")){ + String type = args[1].toString(); + if("1".equals(type)){ + sysLog.setOperatorCategory("导出社区问题单 "); + } + if("2".equals(type)){ + sysLog.setOperatorCategory("导出问题处理单"); + } + if("3".equals(type)){ + sysLog.setOperatorCategory("导出协调通知单"); + } + String postName = jsonResult.get("data").toString(); + sysLog.setTargetName(postName); + } + break; + default: + break; + } + if(opLog.operId()!=1){ SystemUserVo systemUserVo = this.getLoginUserInfoSanGeShenBian(); sysLog.setOperatorId(Long.valueOf(systemUserVo.getId())); - sysLog.setTargetName(systemUserVo.getName()); } - sysLog.setOperatorCategory(opLog.operatorCategory()); + if(opLog.operId()<8){ + sysLog.setOperatorCategory(opLog.operatorCategory()); + } sysLog.setIp(this.getRequest().getRemoteAddr()); sysLog.setOperatorInto(opLog.operatorCategory()); - systemLogService.save(sysLog); + if(opLog.operId()!=5 || sysLog.getTargetName()!=null){ + systemLogService.save(sysLog); + } } catch (Exception e) { e.printStackTrace(); } -- Gitblit v1.7.1