Browse Source

优化农场日志记录

zyh
小久哥 3 years ago
parent
commit
73a8bf4a35
  1. 4
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsg.java
  2. 129
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsgAspect.java
  3. 20
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsgDTO.java
  4. 4
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgBaseVO.java
  5. 4
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgExcelVO.java
  6. 4
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgExportReqVO.java
  7. 4
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/logMsg/vo/LogMsgPageReqVO.java
  8. 6
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/ProjectController.java
  9. 2
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/vo/ProjectPageReqVO.java
  10. 6
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/TaskController.java
  11. 8
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/dataobject/logMsg/LogMsgDO.java
  12. 2
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/dal/mysql/project/ProjectMapper.java
  13. 12
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/task/TaskServiceImpl.java

4
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 "";
}

129
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<ProjectRespVO> projectDO = (CommonResult<ProjectRespVO>) result;
title = projectDO.getData().getName();
}
if (farmMsg.type().equals("任务")){
CommonResult<TaskRespVO> taskDO = (CommonResult<TaskRespVO>) 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;
}
}

20
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;
}

4
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;

4
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;

4
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;

4
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;

6
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)

2
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;

6
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)

8
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
*/

2
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<ProjectDO> {
.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<ProjectDO> {
.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));
}

12
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/task/TaskServiceImpl.java

@ -213,12 +213,18 @@ public class TaskServiceImpl implements TaskService {
Map<Long,List<ResourceDTO>> resourceMap = new HashMap<>();
for (TaskDO taskDO : taskDOList) {
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));
}
}
List<AreaDO> areaDOList = areaMapper.selectList(new LambdaQueryWrapperX<AreaDO>().inIfPresent(AreaDO::getId, areaIdList));
List<CpUserDO> executorList = cpUserMapper.selectList(new LambdaQueryWrapperX<CpUserDO>().inIfPresent(CpUserDO::getId, executorIdList));
@ -326,15 +332,18 @@ public class TaskServiceImpl implements TaskService {
//执行人名
List<String> executorNameList = new ArrayList<>();
preAssemblyDTO.getExecutorList().forEach(executor ->{
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<String> areaNameList = new ArrayList<>();
if (ObjectUtil.isNotEmpty(taskDO.getAreas())) {
for (Object obj : taskDO.getAreas()) {
List<Long> areaList = JSONArray.parseArray(obj.toString(), Long.class);
StrBuilder areaName = new StrBuilder();
@ -343,10 +352,11 @@ public class TaskServiceImpl implements TaskService {
.ifPresent(sonArea ->{
areaName.append(sonArea.getName());
});
});
areaNameList.add(areaName.toString());
}
}
dto.setAreaNameList(areaNameList);
//资源
if (preAssemblyDTO.getTaskResouceMap().containsKey(taskDO.getId())){

Loading…
Cancel
Save