Browse Source

修改farmmsg注解

zyh
Loki 3 years ago
parent
commit
5dd48e50a0
  1. 4
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsg.java
  2. 239
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsgAspect.java
  3. 20
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsgType.java
  4. 7
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/ProjectController.java
  5. 7
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/TaskController.java
  6. 9
      zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/WxCpServiceNoticeService.java

4
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsg.java

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

239
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsgAspect.java

@ -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){}
@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);
}
// 跟新项目 删除项目 更新任务 删除任务。。。
@Before(value = "farmMsgPointCut()") // 构造一个卡片消息 消息名称 : 回乡农场任务管理更新 , 小标题: xxx 创建了项目,请查看处理。
public void beforeSaveFarmMsg(JoinPoint joinPoint){ // appid 是小程序的appid
MethodSignature signature = (MethodSignature) joinPoint.getSignature(); // touser 可以传多个。
Method method = signature.getMethod(); // 这里处理完删除注释
FarmMsg farmMsg = method.getAnnotation(FarmMsg.class); }
if (method.getName().startsWith("get")){
if (farmMsg.type().equals("任务")){
}else if (farmMsg.type().equals("项目")){
}
} }
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); // FarmMsgDTO farmMsgDTO = this.assembleMsg(method, jointPoint.getArgs(), result);
//
//插入农场日志信息 // //插入农场日志信息
LogMsgDO logMsg = LogMsgDO.builder() // LogMsgDO logMsg = LogMsgDO.builder()
.type(farmMsgDTO.getType()) // .type(farmMsgDTO.getType())
.operation(farmMsgDTO.getOperation()) // .operation(farmMsgDTO.getOperation())
.title(farmMsgDTO.getTitle()) // .title(farmMsgDTO.getTitle())
.msg(farmMsgDTO.getMsg()) // .msg(farmMsgDTO.getMsg())
.userId(getLoginUserId()) // .userId(getLoginUserId())
.build(); // .build();
logMsgMapper.insert(logMsg); // logMsgMapper.insert(logMsg);
} // }
public FarmMsgDTO assembleMsg(Method method, Object[] objects, Object result){ // public FarmMsgDTO assembleMsg(Method method, Object[] objects, Object result){
String title = ""; // String title = "";
String msg = ""; // String msg = "";
//
FarmMsg farmMsg = method.getAnnotation(FarmMsg.class); // FarmMsg farmMsg = method.getAnnotation(FarmMsg.class);
if (method.getName().startsWith("get")){ // if (method.getName().startsWith("get")){
for (Object object : objects) { // for (Object object : objects) {
log.info("after用户{},{},{},{}",getLoginUserId(), farmMsg.type(), farmMsg.title(), object); // log.info("after用户{},{},{},{}",getLoginUserId(), farmMsg.type(), farmMsg.title(), object);
if (farmMsg.type().equals("项目")){ // if (farmMsg.type().equals("项目")){
CommonResult<ProjectRespVO> projectDO = (CommonResult<ProjectRespVO>) result; // CommonResult<ProjectRespVO> projectDO = (CommonResult<ProjectRespVO>) result;
title = projectDO.getData().getName(); // title = projectDO.getData().getName();
} // }
if (farmMsg.type().equals("任务")){ // if (farmMsg.type().equals("任务")){
CommonResult<TaskRespVO> taskDO = (CommonResult<TaskRespVO>) result; // CommonResult<TaskRespVO> taskDO = (CommonResult<TaskRespVO>) result;
ProjectDO project = projectMapper.selectOne(ProjectDO::getId, taskDO.getData().getProjectId()); // ProjectDO project = projectMapper.selectOne(ProjectDO::getId, taskDO.getData().getProjectId());
TaskCateDO taskCate = taskCateMapper.selectOne(TaskCateDO::getId, taskDO.getData().getTaskCateId()); // TaskCateDO taskCate = taskCateMapper.selectOne(TaskCateDO::getId, taskDO.getData().getTaskCateId());
title = project.getName(); // title = project.getName();
msg = taskCate.getName(); // msg = taskCate.getName();
} // }
} // }
} // }
//
if (method.getName().startsWith("update")){ // if (method.getName().startsWith("update")){
for (Object object : objects) { // for (Object object : objects) {
if (farmMsg.type().equals("项目")){ // if (farmMsg.type().equals("项目")){
ProjectUpdateReqVO projectDO = (ProjectUpdateReqVO) object; // ProjectUpdateReqVO projectDO = (ProjectUpdateReqVO) object;
title = projectDO.getName(); // title = projectDO.getName();
} // }
if (farmMsg.type().equals("任务")){ // if (farmMsg.type().equals("任务")){
TaskUpdateReqVO taskDO = (TaskUpdateReqVO) object; // TaskUpdateReqVO taskDO = (TaskUpdateReqVO) object;
ProjectDO project = projectMapper.selectOne(ProjectDO::getId, taskDO.getProjectId()); // ProjectDO project = projectMapper.selectOne(ProjectDO::getId, taskDO.getProjectId());
title = project.getName(); // title = project.getName();
TaskCateDO taskCate = taskCateMapper.selectOne(TaskCateDO::getId, taskDO.getTaskCateId()); // TaskCateDO taskCate = taskCateMapper.selectOne(TaskCateDO::getId, taskDO.getTaskCateId());
msg = taskCate.getName(); // msg = taskCate.getName();
} // }
} // }
} // }
//
if (method.getName().startsWith("create")){ // if (method.getName().startsWith("create")){
for (Object object : objects){ // for (Object object : objects){
if (farmMsg.type().equals("项目")){ // if (farmMsg.type().equals("项目")){
ProjectCreateReqVO projectDO = (ProjectCreateReqVO) object; // ProjectCreateReqVO projectDO = (ProjectCreateReqVO) object;
title = projectDO.getName(); // title = projectDO.getName();
} // }
if (farmMsg.type().equals("任务")){ // if (farmMsg.type().equals("任务")){
TaskCreateReqVO taskDO = (TaskCreateReqVO) object; // TaskCreateReqVO taskDO = (TaskCreateReqVO) object;
ProjectDO project = projectMapper.selectOne(ProjectDO::getId, taskDO.getProjectId()); // ProjectDO project = projectMapper.selectOne(ProjectDO::getId, taskDO.getProjectId());
title = project.getName(); // title = project.getName();
TaskCateDO taskCate = taskCateMapper.selectOne(TaskCateDO::getId, taskDO.getTaskCateId()); // TaskCateDO taskCate = taskCateMapper.selectOne(TaskCateDO::getId, taskDO.getTaskCateId());
msg = taskCate.getName(); // msg = taskCate.getName();
} // }
} // }
} // }
//
FarmMsgDTO farmMsgDTO = FarmMsgDTO.builder() // FarmMsgDTO farmMsgDTO = FarmMsgDTO.builder()
.type(farmMsg.type()) // .type(farmMsg.type())
.operation(farmMsg.operation()) // .operation(farmMsg.operation())
.title(title) // .title(title)
.msg(msg).build(); // .msg(msg).build();
return farmMsgDTO; // return farmMsgDTO;
} // }
} }

20
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsgType.java

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

7
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/project/ProjectController.java

@ -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)

7
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/task/TaskController.java

@ -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
zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/WxCpServiceNoticeService.java

@ -0,0 +1,9 @@
package cn.iocoder.yudao.module.farm.service;
import org.springframework.stereotype.Service;
@Service
public class WxCpServiceNoticeService {
}
Loading…
Cancel
Save