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