优化农场日志记录
This commit is contained in:
+4
@@ -13,5 +13,9 @@ public @interface FarmMsg {
|
||||
|
||||
String type() default "";
|
||||
|
||||
String operation() default "";
|
||||
|
||||
String title() default "";
|
||||
|
||||
String msg() default "";
|
||||
}
|
||||
|
||||
+107
-22
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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;
|
||||
|
||||
|
||||
+3
-3
@@ -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)
|
||||
|
||||
+1
-1
@@ -61,7 +61,7 @@ public class ProjectPageReqVO extends PageParam {
|
||||
private Date endCreateTime;
|
||||
|
||||
@ApiModelProperty("草稿")
|
||||
private Boolean draft;
|
||||
private Boolean draft = false;
|
||||
|
||||
private Boolean pretendDelete = false;
|
||||
|
||||
|
||||
+3
-3
@@ -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
@@ -28,10 +28,18 @@ public class LogMsgDO extends BaseDO {
|
||||
* 类型
|
||||
*/
|
||||
private String type;
|
||||
/**
|
||||
* 操作
|
||||
**/
|
||||
private String operation;
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
private String title;
|
||||
/**
|
||||
* 信息
|
||||
**/
|
||||
private String msg;
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
|
||||
+2
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
+30
-20
@@ -213,11 +213,17 @@ public class TaskServiceImpl implements TaskService {
|
||||
Map<Long,List<ResourceDTO>> 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<AreaDO> areaDOList = areaMapper.selectList(new LambdaQueryWrapperX<AreaDO>().inIfPresent(AreaDO::getId, areaIdList));
|
||||
@@ -326,27 +332,31 @@ public class TaskServiceImpl implements TaskService {
|
||||
//执行人名
|
||||
List<String> 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<String> areaNameList = new ArrayList<>();
|
||||
for (Object obj : taskDO.getAreas()) {
|
||||
List<Long> 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<Long> 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())){
|
||||
|
||||
Reference in New Issue
Block a user