修改farmmsg注解
This commit is contained in:
+2
-2
@@ -11,9 +11,9 @@ import java.lang.annotation.*;
|
|||||||
@Documented
|
@Documented
|
||||||
public @interface FarmMsg {
|
public @interface FarmMsg {
|
||||||
|
|
||||||
String type() default "";
|
FarmMsgType type() default FarmMsgType.NONE;
|
||||||
|
|
||||||
String operation() default "";
|
FarmMsgType operation() default FarmMsgType.NONE;
|
||||||
|
|
||||||
String title() default "";
|
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.logMsg.LogMsgMapper;
|
||||||
import cn.iocoder.yudao.module.farm.dal.mysql.project.ProjectMapper;
|
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.dal.mysql.taskCate.TaskCateMapper;
|
||||||
|
import cn.iocoder.yudao.module.farm.service.WxCpServiceNoticeService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
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.JoinPoint;
|
||||||
import org.aspectj.lang.annotation.AfterReturning;
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
import org.aspectj.lang.annotation.*;
|
||||||
import org.aspectj.lang.annotation.Before;
|
|
||||||
import org.aspectj.lang.annotation.Pointcut;
|
|
||||||
import org.aspectj.lang.reflect.MethodSignature;
|
import org.aspectj.lang.reflect.MethodSignature;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
@@ -45,117 +47,158 @@ public class FarmMsgAspect {
|
|||||||
@Resource
|
@Resource
|
||||||
private ProjectMapper projectMapper;
|
private ProjectMapper projectMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private WxCpServiceNoticeService wxCpServiceNoticeService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private WxCpService wxCpService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 定义切入点 @PointCut
|
* 定义切入点 @PointCut
|
||||||
* 使用了@FarmMsg注解的地方切入
|
* 使用了@FarmMsg注解的地方切入
|
||||||
*
|
*
|
||||||
**/
|
**/
|
||||||
@Pointcut("@annotation(cn.iocoder.yudao.module.farm.annotation.FarmMsg)")
|
@Pointcut("@annotation(farmMsg)")
|
||||||
public void farmMsgPointCut(){
|
public void farmMsgPointCut(FarmMsg farmMsg){}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@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("项目")){
|
|
||||||
|
|
||||||
|
@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 切入点
|
* @param jointPoint 切入点
|
||||||
**/
|
**/
|
||||||
@AfterReturning(value = "farmMsgPointCut()", returning = "result")
|
// @AfterReturning(value = "farmMsgPointCut()", returning = "result")
|
||||||
public void afterSaveFarmMsg(JoinPoint jointPoint, Object result){
|
// public void afterSaveFarmMsg(JoinPoint jointPoint, Object result){
|
||||||
//从切入点通过反射获取切入点方法
|
// //从切入点通过反射获取切入点方法
|
||||||
MethodSignature signature = (MethodSignature) jointPoint.getSignature();
|
// MethodSignature signature = (MethodSignature) jointPoint.getSignature();
|
||||||
//获取切入点的方法
|
// //获取切入点的方法
|
||||||
Method method = signature.getMethod();
|
// 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);
|
// public FarmMsgDTO assembleMsg(Method method, Object[] objects, Object result){
|
||||||
|
// String title = "";
|
||||||
//插入农场日志信息
|
// String msg = "";
|
||||||
LogMsgDO logMsg = LogMsgDO.builder()
|
//
|
||||||
.type(farmMsgDTO.getType())
|
// FarmMsg farmMsg = method.getAnnotation(FarmMsg.class);
|
||||||
.operation(farmMsgDTO.getOperation())
|
// if (method.getName().startsWith("get")){
|
||||||
.title(farmMsgDTO.getTitle())
|
// for (Object object : objects) {
|
||||||
.msg(farmMsgDTO.getMsg())
|
// log.info("after用户{},{},{},{}",getLoginUserId(), farmMsg.type(), farmMsg.title(), object);
|
||||||
.userId(getLoginUserId())
|
// if (farmMsg.type().equals("项目")){
|
||||||
.build();
|
// CommonResult<ProjectRespVO> projectDO = (CommonResult<ProjectRespVO>) result;
|
||||||
logMsgMapper.insert(logMsg);
|
// title = projectDO.getData().getName();
|
||||||
}
|
// }
|
||||||
|
// if (farmMsg.type().equals("任务")){
|
||||||
public FarmMsgDTO assembleMsg(Method method, Object[] objects, Object result){
|
// CommonResult<TaskRespVO> taskDO = (CommonResult<TaskRespVO>) result;
|
||||||
String title = "";
|
// ProjectDO project = projectMapper.selectOne(ProjectDO::getId, taskDO.getData().getProjectId());
|
||||||
String msg = "";
|
// TaskCateDO taskCate = taskCateMapper.selectOne(TaskCateDO::getId, taskDO.getData().getTaskCateId());
|
||||||
|
// title = project.getName();
|
||||||
FarmMsg farmMsg = method.getAnnotation(FarmMsg.class);
|
// msg = taskCate.getName();
|
||||||
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;
|
// if (method.getName().startsWith("update")){
|
||||||
title = projectDO.getData().getName();
|
// for (Object object : objects) {
|
||||||
}
|
// if (farmMsg.type().equals("项目")){
|
||||||
if (farmMsg.type().equals("任务")){
|
// ProjectUpdateReqVO projectDO = (ProjectUpdateReqVO) object;
|
||||||
CommonResult<TaskRespVO> taskDO = (CommonResult<TaskRespVO>) result;
|
// title = projectDO.getName();
|
||||||
ProjectDO project = projectMapper.selectOne(ProjectDO::getId, taskDO.getData().getProjectId());
|
// }
|
||||||
TaskCateDO taskCate = taskCateMapper.selectOne(TaskCateDO::getId, taskDO.getData().getTaskCateId());
|
// if (farmMsg.type().equals("任务")){
|
||||||
title = project.getName();
|
// TaskUpdateReqVO taskDO = (TaskUpdateReqVO) object;
|
||||||
msg = taskCate.getName();
|
// 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("update")){
|
// }
|
||||||
for (Object object : objects) {
|
// }
|
||||||
if (farmMsg.type().equals("项目")){
|
//
|
||||||
ProjectUpdateReqVO projectDO = (ProjectUpdateReqVO) object;
|
// if (method.getName().startsWith("create")){
|
||||||
title = projectDO.getName();
|
// for (Object object : objects){
|
||||||
}
|
// if (farmMsg.type().equals("项目")){
|
||||||
if (farmMsg.type().equals("任务")){
|
// ProjectCreateReqVO projectDO = (ProjectCreateReqVO) object;
|
||||||
TaskUpdateReqVO taskDO = (TaskUpdateReqVO) object;
|
// title = projectDO.getName();
|
||||||
ProjectDO project = projectMapper.selectOne(ProjectDO::getId, taskDO.getProjectId());
|
// }
|
||||||
title = project.getName();
|
// if (farmMsg.type().equals("任务")){
|
||||||
TaskCateDO taskCate = taskCateMapper.selectOne(TaskCateDO::getId, taskDO.getTaskCateId());
|
// TaskCreateReqVO taskDO = (TaskCreateReqVO) object;
|
||||||
msg = taskCate.getName();
|
// 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;
|
// FarmMsgDTO farmMsgDTO = FarmMsgDTO.builder()
|
||||||
title = projectDO.getName();
|
// .type(farmMsg.type())
|
||||||
}
|
// .operation(farmMsg.operation())
|
||||||
if (farmMsg.type().equals("任务")){
|
// .title(title)
|
||||||
TaskCreateReqVO taskDO = (TaskCreateReqVO) object;
|
// .msg(msg).build();
|
||||||
ProjectDO project = projectMapper.selectOne(ProjectDO::getId, taskDO.getProjectId());
|
// return farmMsgDTO;
|
||||||
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.framework.common.page.PageVO;
|
||||||
import cn.iocoder.yudao.module.farm.annotation.FarmMsg;
|
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.ProjectListDTO;
|
||||||
import cn.iocoder.yudao.module.farm.controller.admin.project.dto.ProjectPageDTO;
|
import cn.iocoder.yudao.module.farm.controller.admin.project.dto.ProjectPageDTO;
|
||||||
import com.zsw.base.R;
|
import com.zsw.base.R;
|
||||||
@@ -39,7 +40,7 @@ public class ProjectController {
|
|||||||
@Resource
|
@Resource
|
||||||
private ProjectService projectService;
|
private ProjectService projectService;
|
||||||
|
|
||||||
@FarmMsg(type = "项目", operation = "创建")
|
@FarmMsg(type = FarmMsgType.PROJECT, operation = FarmMsgType.CREATE)
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
@ApiOperation("创建农场项目")
|
@ApiOperation("创建农场项目")
|
||||||
@PreAuthorize("@ss.hasPermission('farm:project:create')")
|
@PreAuthorize("@ss.hasPermission('farm:project:create')")
|
||||||
@@ -47,7 +48,7 @@ public class ProjectController {
|
|||||||
return success(projectService.createProject(createReqVO));
|
return success(projectService.createProject(createReqVO));
|
||||||
}
|
}
|
||||||
|
|
||||||
@FarmMsg(type = "项目", operation = "更新")
|
@FarmMsg(type = FarmMsgType.PROJECT, operation = FarmMsgType.UPDATE)
|
||||||
@PutMapping("/update")
|
@PutMapping("/update")
|
||||||
@ApiOperation("更新农场项目")
|
@ApiOperation("更新农场项目")
|
||||||
@PreAuthorize("@ss.hasPermission('farm:project:update')")
|
@PreAuthorize("@ss.hasPermission('farm:project:update')")
|
||||||
@@ -56,6 +57,7 @@ public class ProjectController {
|
|||||||
return success(true);
|
return success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@FarmMsg(type = FarmMsgType.PROJECT,operation = FarmMsgType.DELETE)
|
||||||
@DeleteMapping("/delete")
|
@DeleteMapping("/delete")
|
||||||
@ApiOperation("删除农场项目")
|
@ApiOperation("删除农场项目")
|
||||||
@ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
|
@ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
|
||||||
@@ -65,7 +67,6 @@ public class ProjectController {
|
|||||||
return success(true);
|
return success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@FarmMsg(type = "项目", operation = "查看")
|
|
||||||
@GetMapping("/get")
|
@GetMapping("/get")
|
||||||
@ApiOperation("获得农场项目")
|
@ApiOperation("获得农场项目")
|
||||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
||||||
|
|||||||
+3
-4
@@ -42,7 +42,7 @@ public class TaskController {
|
|||||||
@Resource
|
@Resource
|
||||||
private TaskService taskService;
|
private TaskService taskService;
|
||||||
|
|
||||||
@FarmMsg(type = "任务", operation = "创建")
|
// @FarmMsg(type = "任务", operation = "创建")
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
@ApiOperation("创建农场项目")
|
@ApiOperation("创建农场项目")
|
||||||
@PreAuthorize("@ss.hasPermission('farm:task:create')")
|
@PreAuthorize("@ss.hasPermission('farm:task:create')")
|
||||||
@@ -50,7 +50,7 @@ public class TaskController {
|
|||||||
return success(taskService.createTask(createReqVO));
|
return success(taskService.createTask(createReqVO));
|
||||||
}
|
}
|
||||||
|
|
||||||
@FarmMsg(type = "任务", operation = "更新")
|
// @FarmMsg(type = "任务", operation = "更新")
|
||||||
@PutMapping("/update")
|
@PutMapping("/update")
|
||||||
@ApiOperation("更新农场项目")
|
@ApiOperation("更新农场项目")
|
||||||
@PreAuthorize("@ss.hasPermission('farm:task:update')")
|
@PreAuthorize("@ss.hasPermission('farm:task:update')")
|
||||||
@@ -68,7 +68,7 @@ public class TaskController {
|
|||||||
return success(true);
|
return success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@FarmMsg(type = "任务", operation = "查看")
|
// @FarmMsg(type = "任务", operation = "查看")
|
||||||
@GetMapping("/get")
|
@GetMapping("/get")
|
||||||
@ApiOperation("获得农场项目")
|
@ApiOperation("获得农场项目")
|
||||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
||||||
@@ -124,7 +124,6 @@ public class TaskController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@FarmMsg(type = "任务", title = "查看任务")
|
|
||||||
@GetMapping("/appGet")
|
@GetMapping("/appGet")
|
||||||
@ApiOperation("APP查看农场任务详情")
|
@ApiOperation("APP查看农场任务详情")
|
||||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
@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