修改farmmsg注解
This commit is contained in:
+2
-2
@@ -11,9 +11,9 @@ import java.lang.annotation.*;
|
||||
@Documented
|
||||
public @interface FarmMsg {
|
||||
|
||||
String type() default "";
|
||||
FarmMsgType type() default FarmMsgType.NONE;
|
||||
|
||||
String operation() default "";
|
||||
FarmMsgType operation() default FarmMsgType.NONE;
|
||||
|
||||
String title() default "";
|
||||
|
||||
|
||||
+143
-100
@@ -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(){
|
||||
|
||||
}
|
||||
|
||||
@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("项目")){
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
||||
// 构造一个企业推送消息
|
||||
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 可以传多个。
|
||||
// 这里处理完删除注释
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
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("项目")){
|
||||
//
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
/**
|
||||
* 拦截用户操作日志, 连接点执行完成后记录, 如果连接点异常,则不会执行
|
||||
* @param jointPoint 切入点
|
||||
**/
|
||||
@AfterReturning(value = "farmMsgPointCut()", returning = "result")
|
||||
public void afterSaveFarmMsg(JoinPoint jointPoint, Object result){
|
||||
//从切入点通过反射获取切入点方法
|
||||
MethodSignature signature = (MethodSignature) jointPoint.getSignature();
|
||||
//获取切入点的方法
|
||||
Method method = signature.getMethod();
|
||||
// @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);
|
||||
// }
|
||||
|
||||
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;
|
||||
}
|
||||
// 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.Getter;
|
||||
|
||||
@Getter
|
||||
public enum FarmMsgType {
|
||||
|
||||
PROJECT,
|
||||
TASK,
|
||||
DISCUSS,
|
||||
|
||||
|
||||
CREATE,
|
||||
UPDATE,
|
||||
SELECT,
|
||||
EDIT,
|
||||
DELETE,
|
||||
|
||||
NONE;
|
||||
}
|
||||
+4
-3
@@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.farm.controller.admin.project;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.page.PageVO;
|
||||
import cn.iocoder.yudao.module.farm.annotation.FarmMsg;
|
||||
import cn.iocoder.yudao.module.farm.annotation.FarmMsgType;
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.project.dto.ProjectListDTO;
|
||||
import cn.iocoder.yudao.module.farm.controller.admin.project.dto.ProjectPageDTO;
|
||||
import com.zsw.base.R;
|
||||
@@ -39,7 +40,7 @@ public class ProjectController {
|
||||
@Resource
|
||||
private ProjectService projectService;
|
||||
|
||||
@FarmMsg(type = "项目", operation = "创建")
|
||||
@FarmMsg(type = FarmMsgType.PROJECT, operation = FarmMsgType.CREATE)
|
||||
@PostMapping("/create")
|
||||
@ApiOperation("创建农场项目")
|
||||
@PreAuthorize("@ss.hasPermission('farm:project:create')")
|
||||
@@ -47,7 +48,7 @@ public class ProjectController {
|
||||
return success(projectService.createProject(createReqVO));
|
||||
}
|
||||
|
||||
@FarmMsg(type = "项目", operation = "更新")
|
||||
@FarmMsg(type = FarmMsgType.PROJECT, operation = FarmMsgType.UPDATE)
|
||||
@PutMapping("/update")
|
||||
@ApiOperation("更新农场项目")
|
||||
@PreAuthorize("@ss.hasPermission('farm:project:update')")
|
||||
@@ -56,6 +57,7 @@ public class ProjectController {
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@FarmMsg(type = FarmMsgType.PROJECT,operation = FarmMsgType.DELETE)
|
||||
@DeleteMapping("/delete")
|
||||
@ApiOperation("删除农场项目")
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
|
||||
@@ -65,7 +67,6 @@ public class ProjectController {
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@FarmMsg(type = "项目", operation = "查看")
|
||||
@GetMapping("/get")
|
||||
@ApiOperation("获得农场项目")
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
||||
|
||||
+3
-4
@@ -42,7 +42,7 @@ public class TaskController {
|
||||
@Resource
|
||||
private TaskService taskService;
|
||||
|
||||
@FarmMsg(type = "任务", operation = "创建")
|
||||
// @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 = "任务", operation = "更新")
|
||||
// @FarmMsg(type = "任务", operation = "更新")
|
||||
@PutMapping("/update")
|
||||
@ApiOperation("更新农场项目")
|
||||
@PreAuthorize("@ss.hasPermission('farm:task:update')")
|
||||
@@ -68,7 +68,7 @@ public class TaskController {
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@FarmMsg(type = "任务", operation = "查看")
|
||||
// @FarmMsg(type = "任务", operation = "查看")
|
||||
@GetMapping("/get")
|
||||
@ApiOperation("获得农场项目")
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
||||
@@ -124,7 +124,6 @@ public class TaskController {
|
||||
}
|
||||
|
||||
|
||||
@FarmMsg(type = "任务", title = "查看任务")
|
||||
@GetMapping("/appGet")
|
||||
@ApiOperation("APP查看农场任务详情")
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package cn.iocoder.yudao.module.farm.service;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class WxCpServiceNoticeService {
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user