diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsg.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsg.java index 85c0d3fa..8aa2e0a7 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsg.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsg.java @@ -13,5 +13,9 @@ public @interface FarmMsg { String type() default ""; + String operation() default ""; + String title() default ""; + + String msg() default ""; } diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsgAspect.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsgAspect.java index 223160dd..d8af6c65 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsgAspect.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsgAspect.java @@ -1,25 +1,32 @@ package cn.iocoder.yudao.module.farm.annotation; -import cn.iocoder.yudao.framework.security.core.LoginUser; -import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; + + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.module.farm.annotation.FarmMsg; +import cn.iocoder.yudao.module.farm.controller.admin.project.vo.ProjectCreateReqVO; +import cn.iocoder.yudao.module.farm.controller.admin.project.vo.ProjectRespVO; +import cn.iocoder.yudao.module.farm.controller.admin.project.vo.ProjectUpdateReqVO; +import cn.iocoder.yudao.module.farm.controller.admin.task.vo.TaskCreateReqVO; +import cn.iocoder.yudao.module.farm.controller.admin.task.vo.TaskRespVO; +import cn.iocoder.yudao.module.farm.controller.admin.task.vo.TaskUpdateReqVO; import cn.iocoder.yudao.module.farm.dal.dataobject.logMsg.LogMsgDO; +import cn.iocoder.yudao.module.farm.dal.dataobject.project.ProjectDO; +import cn.iocoder.yudao.module.farm.dal.dataobject.task.TaskDO; +import cn.iocoder.yudao.module.farm.dal.dataobject.taskCate.TaskCateDO; import cn.iocoder.yudao.module.farm.dal.mysql.logMsg.LogMsgMapper; -import cn.iocoder.yudao.module.farm.service.logMsg.LogMsgService; +import cn.iocoder.yudao.module.farm.dal.mysql.project.ProjectMapper; +import cn.iocoder.yudao.module.farm.dal.mysql.taskCate.TaskCateMapper; import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.AfterReturning; import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Pointcut; import org.aspectj.lang.reflect.MethodSignature; import org.springframework.stereotype.Component; -import org.springframework.web.bind.annotation.RequestAttribute; -import org.springframework.web.context.request.RequestAttributes; -import org.springframework.web.context.request.RequestContextHolder; - import javax.annotation.Resource; -import javax.servlet.http.HttpServletRequest; import java.lang.reflect.Method; -import java.time.LocalDateTime; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; @@ -33,6 +40,10 @@ public class FarmMsgAspect { @Resource private LogMsgMapper logMsgMapper; + @Resource + private TaskCateMapper taskCateMapper; + @Resource + private ProjectMapper projectMapper; /** @@ -45,32 +56,106 @@ public class FarmMsgAspect { } + @Before(value = "farmMsgPointCut()") + public void beforeSaveFarmMsg(JoinPoint joinPoint){ + MethodSignature signature = (MethodSignature) joinPoint.getSignature(); + Method method = signature.getMethod(); + FarmMsg farmMsg = method.getAnnotation(FarmMsg.class); + + if (method.getName().startsWith("get")){ + if (farmMsg.type().equals("任务")){ + + }else if (farmMsg.type().equals("项目")){ + + } + } + + } + /** * 拦截用户操作日志, 连接点执行完成后记录, 如果连接点异常,则不会执行 * @param jointPoint 切入点 - * @param result 返回结果 **/ @AfterReturning(value = "farmMsgPointCut()", returning = "result") - public void saveFarmMsg(JoinPoint jointPoint, Object result){ - - RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes(); - HttpServletRequest request = (HttpServletRequest) requestAttributes.resolveReference(RequestAttributes.REFERENCE_REQUEST); - + public void afterSaveFarmMsg(JoinPoint jointPoint, Object result){ //从切入点通过反射获取切入点方法 MethodSignature signature = (MethodSignature) jointPoint.getSignature(); - //获取切入点的方法 Method method = signature.getMethod(); - //获取操作的type, title - FarmMsg farmMsg = method.getAnnotation(FarmMsg.class); + FarmMsgDTO farmMsgDTO = this.assembleMsg(method, jointPoint.getArgs(), result); //插入农场日志信息 - LogMsgDO msg = LogMsgDO.builder() - .type(farmMsg.type()) - .title(farmMsg.title()) + LogMsgDO logMsg = LogMsgDO.builder() + .type(farmMsgDTO.getType()) + .operation(farmMsgDTO.getOperation()) + .title(farmMsgDTO.getTitle()) + .msg(farmMsgDTO.getMsg()) .userId(getLoginUserId()) .build(); - logMsgMapper.insert(msg); + logMsgMapper.insert(logMsg); } + + public FarmMsgDTO assembleMsg(Method method, Object[] objects, Object result){ + String title = ""; + String msg = ""; + + FarmMsg farmMsg = method.getAnnotation(FarmMsg.class); + if (method.getName().startsWith("get")){ + for (Object object : objects) { + log.info("after用户{},{},{},{}",getLoginUserId(), farmMsg.type(), farmMsg.title(), object); + if (farmMsg.type().equals("项目")){ + CommonResult projectDO = (CommonResult) result; + title = projectDO.getData().getName(); + } + if (farmMsg.type().equals("任务")){ + CommonResult taskDO = (CommonResult) result; + ProjectDO project = projectMapper.selectOne(ProjectDO::getId, taskDO.getData().getProjectId()); + TaskCateDO taskCate = taskCateMapper.selectOne(TaskCateDO::getId, taskDO.getData().getTaskCateId()); + title = project.getName(); + msg = taskCate.getName(); + } + } + } + + if (method.getName().startsWith("update")){ + for (Object object : objects) { + if (farmMsg.type().equals("项目")){ + ProjectUpdateReqVO projectDO = (ProjectUpdateReqVO) object; + title = projectDO.getName(); + } + if (farmMsg.type().equals("任务")){ + TaskUpdateReqVO taskDO = (TaskUpdateReqVO) object; + ProjectDO project = projectMapper.selectOne(ProjectDO::getId, taskDO.getProjectId()); + title = project.getName(); + TaskCateDO taskCate = taskCateMapper.selectOne(TaskCateDO::getId, taskDO.getTaskCateId()); + msg = taskCate.getName(); + } + } + } + + if (method.getName().startsWith("create")){ + for (Object object : objects){ + if (farmMsg.type().equals("项目")){ + ProjectCreateReqVO projectDO = (ProjectCreateReqVO) object; + title = projectDO.getName(); + } + if (farmMsg.type().equals("任务")){ + TaskCreateReqVO taskDO = (TaskCreateReqVO) object; + ProjectDO project = projectMapper.selectOne(ProjectDO::getId, taskDO.getProjectId()); + title = project.getName(); + TaskCateDO taskCate = taskCateMapper.selectOne(TaskCateDO::getId, taskDO.getTaskCateId()); + msg = taskCate.getName(); + } + } + } + + FarmMsgDTO farmMsgDTO = FarmMsgDTO.builder() + .type(farmMsg.type()) + .operation(farmMsg.operation()) + .title(title) + .msg(msg).build(); + return farmMsgDTO; + } + } diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsgDTO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsgDTO.java new file mode 100644 index 00000000..92353e2e --- /dev/null +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsgDTO.java @@ -0,0 +1,20 @@ +package cn.iocoder.yudao.module.farm.annotation; + +import lombok.Builder; +import lombok.Data; + +/** + * @Created by jiu on 2022/6/17. + */ +@Data +@Builder +public class FarmMsgDTO { + + private String type; + + private String operation; + + private String title; + + private String msg; +} diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgBaseVO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgBaseVO.java index 638071e5..7d3514bb 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgBaseVO.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgBaseVO.java @@ -15,9 +15,13 @@ public class LogMsgBaseVO { @ApiModelProperty(value = "类型") private String type; + private String operation; + @ApiModelProperty(value = "标题") private String title; + private String msg; + @ApiModelProperty(value = "用户id") private Long userId; diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgExcelVO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgExcelVO.java index 10ff1d12..00929111 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgExcelVO.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgExcelVO.java @@ -20,9 +20,13 @@ public class LogMsgExcelVO { @ExcelProperty("类型") private String type; + private String operation; + @ExcelProperty("标题") private String title; + private String msg; + @ExcelProperty("用户id") private Long userId; diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgExportReqVO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgExportReqVO.java index e4ae8592..67bc4b03 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgExportReqVO.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgExportReqVO.java @@ -15,9 +15,13 @@ public class LogMsgExportReqVO { @ApiModelProperty(value = "类型") private String type; + private String operation; + @ApiModelProperty(value = "标题") private String title; + private String msg; + @ApiModelProperty(value = "用户id") private Long userId; diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgPageReqVO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgPageReqVO.java index f6637df1..6cc1f0c0 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgPageReqVO.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgPageReqVO.java @@ -17,9 +17,13 @@ public class LogMsgPageReqVO extends PageParam { @ApiModelProperty(value = "类型") private String type; + private String operation; + @ApiModelProperty(value = "标题") private String title; + private String msg; + @ApiModelProperty(value = "用户id") private Long userId; diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/ProjectController.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/ProjectController.java index b5225b71..6ae46294 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/ProjectController.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/ProjectController.java @@ -39,7 +39,7 @@ public class ProjectController { @Resource private ProjectService projectService; - @FarmMsg(type = "项目", title = "创建项目") + @FarmMsg(type = "项目", operation = "创建") @PostMapping("/create") @ApiOperation("创建农场项目") @PreAuthorize("@ss.hasPermission('farm:project:create')") @@ -47,7 +47,7 @@ public class ProjectController { return success(projectService.createProject(createReqVO)); } - @FarmMsg(type = "项目", title = "更新项目") + @FarmMsg(type = "项目", operation = "更新") @PutMapping("/update") @ApiOperation("更新农场项目") @PreAuthorize("@ss.hasPermission('farm:project:update')") @@ -65,7 +65,7 @@ public class ProjectController { return success(true); } - @FarmMsg(type = "项目", title = "查看项目#{id}") + @FarmMsg(type = "项目", operation = "查看") @GetMapping("/get") @ApiOperation("获得农场项目") @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/vo/ProjectPageReqVO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/vo/ProjectPageReqVO.java index 7be824ad..7d0b16e5 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/vo/ProjectPageReqVO.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/vo/ProjectPageReqVO.java @@ -61,7 +61,7 @@ public class ProjectPageReqVO extends PageParam { private Date endCreateTime; @ApiModelProperty("草稿") - private Boolean draft; + private Boolean draft = false; private Boolean pretendDelete = false; diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/TaskController.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/TaskController.java index 47d77378..ebb3a71c 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/TaskController.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/TaskController.java @@ -42,7 +42,7 @@ public class TaskController { @Resource private TaskService taskService; - @FarmMsg(type = "任务", title = "创建任务") + @FarmMsg(type = "任务", operation = "创建") @PostMapping("/create") @ApiOperation("创建农场项目") @PreAuthorize("@ss.hasPermission('farm:task:create')") @@ -50,7 +50,7 @@ public class TaskController { return success(taskService.createTask(createReqVO)); } - @FarmMsg(type = "任务", title = "更新任务") + @FarmMsg(type = "任务", operation = "更新") @PutMapping("/update") @ApiOperation("更新农场项目") @PreAuthorize("@ss.hasPermission('farm:task:update')") @@ -68,7 +68,7 @@ public class TaskController { return success(true); } - @FarmMsg(type = "任务", title = "查看任务") + @FarmMsg(type = "任务", operation = "查看") @GetMapping("/get") @ApiOperation("获得农场项目") @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/logMsg/LogMsgDO.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/logMsg/LogMsgDO.java index e390a64c..16e5c217 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/logMsg/LogMsgDO.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/logMsg/LogMsgDO.java @@ -28,10 +28,18 @@ public class LogMsgDO extends BaseDO { * 类型 */ private String type; + /** + * 操作 + **/ + private String operation; /** * 标题 */ private String title; + /** + * 信息 + **/ + private String msg; /** * 用户id */ diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/mysql/project/ProjectMapper.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/mysql/project/ProjectMapper.java index 2f4266e8..98840a27 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/mysql/project/ProjectMapper.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/mysql/project/ProjectMapper.java @@ -31,6 +31,7 @@ public interface ProjectMapper extends BaseMapperX { .eqIfPresent(ProjectDO::getWeight, reqVO.getWeight()) .betweenIfPresent(ProjectDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()) .eqIfPresent(ProjectDO::getPretendDelete, reqVO.getPretendDelete()) + .eqIfPresent(ProjectDO::getDraft, reqVO.getDraft()) .orderByDesc(ProjectDO::getId)); } @@ -47,6 +48,7 @@ public interface ProjectMapper extends BaseMapperX { .eqIfPresent(ProjectDO::getWeight, reqVO.getWeight()) .betweenIfPresent(ProjectDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime()) .eqIfPresent(ProjectDO::getPretendDelete, reqVO.getPretendDelete()) + .eqIfPresent(ProjectDO::getDraft, reqVO.getDraft()) .orderByDesc(ProjectDO::getId)); } diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/task/TaskServiceImpl.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/task/TaskServiceImpl.java index ddf2c850..acd32e9c 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/task/TaskServiceImpl.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/task/TaskServiceImpl.java @@ -213,11 +213,17 @@ public class TaskServiceImpl implements TaskService { Map> resourceMap = new HashMap<>(); for (TaskDO taskDO : taskDOList) { - for (Object area : taskDO.getAreas()) { - areaIdList.addAll(JSONArray.parseArray(area.toString(), Long.class)); + if (ObjectUtil.isNotEmpty(taskDO.getAreas())){ + for (Object area : taskDO.getAreas()) { + areaIdList.addAll(JSONArray.parseArray(area.toString(), Long.class)); + } + } + if (ObjectUtil.isNotEmpty(taskDO.getExecutorPerson())){ + executorIdList.addAll(taskDO.getExecutorPerson().toJavaList(Long.class)); + } + if (ObjectUtil.isNotEmpty(taskDO.getResources())){ + resourceMap.put(taskDO.getId(), taskDO.getResources().toJavaList(ResourceDTO.class)); } - executorIdList.addAll(taskDO.getExecutorPerson().toJavaList(Long.class)); - resourceMap.put(taskDO.getId(), taskDO.getResources().toJavaList(ResourceDTO.class)); } List areaDOList = areaMapper.selectList(new LambdaQueryWrapperX().inIfPresent(AreaDO::getId, areaIdList)); @@ -326,27 +332,31 @@ public class TaskServiceImpl implements TaskService { //执行人名 List executorNameList = new ArrayList<>(); preAssemblyDTO.getExecutorList().forEach(executor ->{ - taskDO.getExecutorPerson().toJavaList(Long.class).forEach(item ->{ - if (executor.getId().equals(item)){ - executorNameList.add( executor.getName()); - } - }); + if (ObjectUtil.isNotEmpty(taskDO.getExecutorPerson())){ + taskDO.getExecutorPerson().toJavaList(Long.class).forEach(item ->{ + if (executor.getId().equals(item)){ + executorNameList.add( executor.getName()); + } + }); + } }); dto.setExecutorNameList(executorNameList); //区域名 List areaNameList = new ArrayList<>(); - for (Object obj : taskDO.getAreas()) { - List areaList = JSONArray.parseArray(obj.toString(), Long.class); - StrBuilder areaName = new StrBuilder(); - areaList.forEach( one ->{ - preAssemblyDTO.getAreaDOList().stream().filter(item -> item.getId().equals(one)).findFirst() - .ifPresent(sonArea ->{ - areaName.append(sonArea.getName()); - }); - - }); - areaNameList.add(areaName.toString()); + if (ObjectUtil.isNotEmpty(taskDO.getAreas())) { + for (Object obj : taskDO.getAreas()) { + List areaList = JSONArray.parseArray(obj.toString(), Long.class); + StrBuilder areaName = new StrBuilder(); + areaList.forEach( one ->{ + preAssemblyDTO.getAreaDOList().stream().filter(item -> item.getId().equals(one)).findFirst() + .ifPresent(sonArea ->{ + areaName.append(sonArea.getName()); + }); + }); + areaNameList.add(areaName.toString()); + } } + dto.setAreaNameList(areaNameList); //资源 if (preAssemblyDTO.getTaskResouceMap().containsKey(taskDO.getId())){