|
|
|
@ -17,13 +17,15 @@ 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.dal.mysql.project.ProjectMapper; |
|
|
|
|
import cn.iocoder.yudao.module.farm.dal.mysql.taskCate.TaskCateMapper; |
|
|
|
|
import cn.iocoder.yudao.module.farm.service.WxCpServiceNoticeService; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import me.chanjar.weixin.cp.api.WxCpService; |
|
|
|
|
import me.chanjar.weixin.cp.bean.message.WxCpMessage; |
|
|
|
|
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.ProceedingJoinPoint; |
|
|
|
|
import org.aspectj.lang.annotation.*; |
|
|
|
|
import org.aspectj.lang.reflect.MethodSignature; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
import javax.annotation.Resource; |
|
|
|
|
import java.lang.reflect.Method; |
|
|
|
@ -45,117 +47,158 @@ public class FarmMsgAspect {
|
|
|
|
|
@Resource |
|
|
|
|
private ProjectMapper projectMapper; |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private WxCpServiceNoticeService wxCpServiceNoticeService; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private WxCpService wxCpService; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 定义切入点 @PointCut |
|
|
|
|
* 使用了@FarmMsg注解的地方切入 |
|
|
|
|
* |
|
|
|
|
**/ |
|
|
|
|
@Pointcut("@annotation(cn.iocoder.yudao.module.farm.annotation.FarmMsg)") |
|
|
|
|
public void farmMsgPointCut(){ |
|
|
|
|
@Pointcut("@annotation(farmMsg)") |
|
|
|
|
public void farmMsgPointCut(FarmMsg farmMsg){} |
|
|
|
|
|
|
|
|
|
@Around("farmMsgPointCut(farmMsg)") |
|
|
|
|
public Object doAround(ProceedingJoinPoint pjp,FarmMsg farmMsg) throws Throwable { |
|
|
|
|
Object object = pjp.proceed(); |
|
|
|
|
if (object instanceof CommonResult){ |
|
|
|
|
// 只处理接口正常result
|
|
|
|
|
if (farmMsg.type() == FarmMsgType.NONE |
|
|
|
|
|| farmMsg.operation() == FarmMsgType.NONE |
|
|
|
|
|| ((CommonResult<?>) object).getCode()!=0 ){ |
|
|
|
|
return object; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@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("项目")){ |
|
|
|
|
// 构造一个企业推送消息
|
|
|
|
|
WxCpMessage message = new WxCpMessage(); |
|
|
|
|
|
|
|
|
|
if (farmMsg.type() == FarmMsgType.PROJECT){ |
|
|
|
|
if (farmMsg.operation() == FarmMsgType.CREATE){ |
|
|
|
|
Long id = (Long) ((CommonResult<?>) object).getData(); |
|
|
|
|
// 发企业微信
|
|
|
|
|
// 拼接全部的参与用户
|
|
|
|
|
message.setToUser(""); |
|
|
|
|
//把主题填充
|
|
|
|
|
message.setTitle(""); |
|
|
|
|
wxCpService.getMessageService().send(message); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// 跟新项目 删除项目 更新任务 删除任务。。。
|
|
|
|
|
|
|
|
|
|
// 构造一个卡片消息 消息名称 : 回乡农场任务管理更新 , 小标题: xxx 创建了项目,请查看处理。
|
|
|
|
|
// appid 是小程序的appid
|
|
|
|
|
// touser 可以传多个。
|
|
|
|
|
// 这里处理完删除注释
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 拦截用户操作日志, 连接点执行完成后记录, 如果连接点异常,则不会执行 |
|
|
|
|
* @param jointPoint 切入点 |
|
|
|
|
**/ |
|
|
|
|
@AfterReturning(value = "farmMsgPointCut()", returning = "result") |
|
|
|
|
public void afterSaveFarmMsg(JoinPoint jointPoint, Object result){ |
|
|
|
|
//从切入点通过反射获取切入点方法
|
|
|
|
|
MethodSignature signature = (MethodSignature) jointPoint.getSignature(); |
|
|
|
|
//获取切入点的方法
|
|
|
|
|
Method method = signature.getMethod(); |
|
|
|
|
|
|
|
|
|
FarmMsgDTO farmMsgDTO = this.assembleMsg(method, jointPoint.getArgs(), result); |
|
|
|
|
|
|
|
|
|
//插入农场日志信息
|
|
|
|
|
LogMsgDO logMsg = LogMsgDO.builder() |
|
|
|
|
.type(farmMsgDTO.getType()) |
|
|
|
|
.operation(farmMsgDTO.getOperation()) |
|
|
|
|
.title(farmMsgDTO.getTitle()) |
|
|
|
|
.msg(farmMsgDTO.getMsg()) |
|
|
|
|
.userId(getLoginUserId()) |
|
|
|
|
.build(); |
|
|
|
|
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(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return object; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// @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("项目")){
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
FarmMsgDTO farmMsgDTO = FarmMsgDTO.builder() |
|
|
|
|
.type(farmMsg.type()) |
|
|
|
|
.operation(farmMsg.operation()) |
|
|
|
|
.title(title) |
|
|
|
|
.msg(msg).build(); |
|
|
|
|
return farmMsgDTO; |
|
|
|
|
} |
|
|
|
|
/** |
|
|
|
|
* 拦截用户操作日志, 连接点执行完成后记录, 如果连接点异常,则不会执行 |
|
|
|
|
* @param jointPoint 切入点 |
|
|
|
|
**/ |
|
|
|
|
// @AfterReturning(value = "farmMsgPointCut()", returning = "result")
|
|
|
|
|
// public void afterSaveFarmMsg(JoinPoint jointPoint, Object result){
|
|
|
|
|
// //从切入点通过反射获取切入点方法
|
|
|
|
|
// MethodSignature signature = (MethodSignature) jointPoint.getSignature();
|
|
|
|
|
// //获取切入点的方法
|
|
|
|
|
// Method method = signature.getMethod();
|
|
|
|
|
//
|
|
|
|
|
// FarmMsgDTO farmMsgDTO = this.assembleMsg(method, jointPoint.getArgs(), result);
|
|
|
|
|
//
|
|
|
|
|
// //插入农场日志信息
|
|
|
|
|
// LogMsgDO logMsg = LogMsgDO.builder()
|
|
|
|
|
// .type(farmMsgDTO.getType())
|
|
|
|
|
// .operation(farmMsgDTO.getOperation())
|
|
|
|
|
// .title(farmMsgDTO.getTitle())
|
|
|
|
|
// .msg(farmMsgDTO.getMsg())
|
|
|
|
|
// .userId(getLoginUserId())
|
|
|
|
|
// .build();
|
|
|
|
|
// 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;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|