|
|
|
@ -2,34 +2,39 @@ package cn.iocoder.yudao.module.farm.annotation;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
|
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.discuss.DiscussDO; |
|
|
|
|
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.discuss.DiscussMapper; |
|
|
|
|
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.task.TaskMapper; |
|
|
|
|
import cn.iocoder.yudao.module.farm.dal.mysql.taskCate.TaskCateMapper; |
|
|
|
|
import cn.iocoder.yudao.module.farm.service.WxCpServiceNoticeService; |
|
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.CpUser.CpUserDO; |
|
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; |
|
|
|
|
import cn.iocoder.yudao.module.system.dal.mysql.CpUser.CpUserMapper; |
|
|
|
|
import cn.iocoder.yudao.module.system.dal.mysql.user.AdminUserMapper; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import me.chanjar.weixin.cp.api.WxCpMessageService; |
|
|
|
|
import me.chanjar.weixin.cp.api.WxCpService; |
|
|
|
|
import me.chanjar.weixin.cp.bean.message.WxCpMessage; |
|
|
|
|
import org.aspectj.lang.JoinPoint; |
|
|
|
|
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; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
|
|
|
|
|
|
|
|
@ -47,11 +52,19 @@ public class FarmMsgAspect {
|
|
|
|
|
private TaskCateMapper taskCateMapper; |
|
|
|
|
@Resource |
|
|
|
|
private ProjectMapper projectMapper; |
|
|
|
|
@Resource |
|
|
|
|
private DiscussMapper discussMapper; |
|
|
|
|
@Resource |
|
|
|
|
private TaskMapper taskMapper; |
|
|
|
|
@Resource |
|
|
|
|
private CpUserMapper cpUserMapper; |
|
|
|
|
@Resource |
|
|
|
|
private AdminUserMapper adminUserMapper; |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private WxCpServiceNoticeService wxCpServiceNoticeService; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
@Resource |
|
|
|
|
private WxCpService wxCpService; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -67,8 +80,8 @@ public class FarmMsgAspect {
|
|
|
|
|
Object object = pjp.proceed(); |
|
|
|
|
if (object instanceof CommonResult){ |
|
|
|
|
// 只处理接口正常result
|
|
|
|
|
if (farmMsg.type() == FarmMsgType.NONE |
|
|
|
|
|| farmMsg.operation() == FarmMsgType.NONE |
|
|
|
|
if (farmMsg.type() == FarmMsgTypeEnum.NONE |
|
|
|
|
|| farmMsg.operation() == FarmMsgTypeEnum.NONE |
|
|
|
|
|| ((CommonResult<?>) object).getCode()!=0 ){ |
|
|
|
|
return object; |
|
|
|
|
} |
|
|
|
@ -76,15 +89,55 @@ public class FarmMsgAspect {
|
|
|
|
|
// 构造一个企业推送消息
|
|
|
|
|
WxCpMessage message = new WxCpMessage(); |
|
|
|
|
|
|
|
|
|
if (farmMsg.type() == FarmMsgType.PROJECT){ |
|
|
|
|
if (farmMsg.operation() == FarmMsgType.CREATE){ |
|
|
|
|
if (farmMsg.type() == FarmMsgTypeEnum.PROJECT){ |
|
|
|
|
if (farmMsg.operation() == FarmMsgTypeEnum.CREATE){ |
|
|
|
|
Long id = (Long) ((CommonResult<?>) object).getData(); |
|
|
|
|
|
|
|
|
|
//处理所需要数据
|
|
|
|
|
MethodSignature signature = (MethodSignature) pjp.getSignature(); |
|
|
|
|
Method method = signature.getMethod(); |
|
|
|
|
FarmMsgDTO farmMsgDTO = this.assembleMsg(method, pjp.getArgs(), (CommonResult<?>) object); |
|
|
|
|
|
|
|
|
|
//接受消息的人
|
|
|
|
|
String toUserStr = this.assembleCpUserId(farmMsg.type(), id); |
|
|
|
|
//发起人
|
|
|
|
|
AdminUserDO adminUser = adminUserMapper.selectOne(AdminUserDO::getId, getLoginUserId()); |
|
|
|
|
CpUserDO user = cpUserMapper.selectOne(CpUserDO::getUserId, adminUser.getCpUserId()); |
|
|
|
|
StringBuilder description = new StringBuilder() |
|
|
|
|
.append(user.getName()) |
|
|
|
|
.append(" ") |
|
|
|
|
.append(farmMsgDTO.getOperation().getDesc()) |
|
|
|
|
.append(farmMsgDTO.getType().getDesc()) |
|
|
|
|
.append(":") |
|
|
|
|
.append(farmMsgDTO.getTitle()) |
|
|
|
|
.append("(其中有你)"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!toUserStr.contains("WeiLaiKeQi")){ |
|
|
|
|
return object; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 发企业微信
|
|
|
|
|
// 拼接全部的参与用户
|
|
|
|
|
message.setToUser(""); |
|
|
|
|
//把主题填充
|
|
|
|
|
message.setTitle(""); |
|
|
|
|
wxCpService.getMessageService().send(message); |
|
|
|
|
WxCpMessageService wxCpMessageService = wxCpService.getMessageService(); |
|
|
|
|
|
|
|
|
|
//消息类型 必填 此处固定为 文本卡片
|
|
|
|
|
message.setMsgType("textcard"); |
|
|
|
|
//企业应用id 必填
|
|
|
|
|
message.setAgentId(wxCpService.getWxCpConfigStorage().getAgentId()); |
|
|
|
|
//消息标题 必填
|
|
|
|
|
message.setTitle("回乡农场任务管理更新"); |
|
|
|
|
//消息描述 必填
|
|
|
|
|
message.setDescription(description.toString()); |
|
|
|
|
//点击后跳转链接 必填
|
|
|
|
|
message.setUrl("https://www.baidu.com"); |
|
|
|
|
|
|
|
|
|
//接受消息成员 选填
|
|
|
|
|
message.setToUser(toUserStr); |
|
|
|
|
|
|
|
|
|
// WxCpMessageSendResult result = wxCpMessageService.send(message);
|
|
|
|
|
// log.info("企业微信消息发送结果:{}",result);
|
|
|
|
|
System.out.println(message); |
|
|
|
|
} |
|
|
|
|
// 跟新项目 删除项目 更新任务 删除任务。。。
|
|
|
|
|
|
|
|
|
@ -100,107 +153,95 @@ public class FarmMsgAspect {
|
|
|
|
|
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 切入点 |
|
|
|
|
* @Description 获取需要接受信息的成员 |
|
|
|
|
* @param id 可能是 projectId taskId 或 discussId |
|
|
|
|
**/ |
|
|
|
|
public String assembleCpUserId(FarmMsgTypeEnum farmMsgType, Long id){ |
|
|
|
|
List<Long> idList = new ArrayList<>(); |
|
|
|
|
if (farmMsgType.equals(FarmMsgTypeEnum.PROJECT)){ |
|
|
|
|
ProjectDO project = projectMapper.selectOne(ProjectDO::getId, id); |
|
|
|
|
idList.addAll(project.getMembers().toJavaList(Long.class)); |
|
|
|
|
}else if (farmMsgType.equals(FarmMsgTypeEnum.TASK)){ |
|
|
|
|
TaskDO task = taskMapper.selectOne(TaskDO::getId, id); |
|
|
|
|
idList.add(task.getMainPerson()); |
|
|
|
|
idList.addAll(task.getExecutorPerson().toJavaList(Long.class)); |
|
|
|
|
}else if (farmMsgType.equals(FarmMsgTypeEnum.DISCUSS)){ |
|
|
|
|
DiscussDO discuss = discussMapper.selectOne(DiscussDO::getId, id); |
|
|
|
|
TaskDO task = taskMapper.selectOne(TaskDO::getId, discuss.getId()); |
|
|
|
|
idList.add(task.getMainPerson()); |
|
|
|
|
idList.addAll(task.getExecutorPerson().toJavaList(Long.class)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
StringBuilder builder = new StringBuilder(); |
|
|
|
|
List<CpUserDO> userList = cpUserMapper.selectList(CpUserDO::getId, idList); |
|
|
|
|
userList.forEach(user ->{ |
|
|
|
|
builder.append(user.getUserId()).append("|"); |
|
|
|
|
}); |
|
|
|
|
return builder.toString().substring(0, builder.length() -1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public FarmMsgDTO assembleMsg(Method method, Object[] objects, Object result){ |
|
|
|
|
String title = ""; |
|
|
|
|
String msg = ""; |
|
|
|
|
|
|
|
|
|
// @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;
|
|
|
|
|
// }
|
|
|
|
|
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(FarmMsgTypeEnum.PROJECT)){ |
|
|
|
|
CommonResult<ProjectRespVO> projectDO = (CommonResult<ProjectRespVO>) result; |
|
|
|
|
title = projectDO.getData().getName(); |
|
|
|
|
} |
|
|
|
|
if (farmMsg.type().equals(FarmMsgTypeEnum.TASK)){ |
|
|
|
|
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(FarmMsgTypeEnum.PROJECT)){ |
|
|
|
|
ProjectUpdateReqVO projectDO = (ProjectUpdateReqVO) object; |
|
|
|
|
title = projectDO.getName(); |
|
|
|
|
} |
|
|
|
|
if (farmMsg.type().equals(FarmMsgTypeEnum.TASK)){ |
|
|
|
|
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(FarmMsgTypeEnum.PROJECT)){ |
|
|
|
|
ProjectCreateReqVO projectDO = (ProjectCreateReqVO) object; |
|
|
|
|
title = projectDO.getName(); |
|
|
|
|
} |
|
|
|
|
if (farmMsg.type().equals(FarmMsgTypeEnum.TASK)){ |
|
|
|
|
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(FarmMsgTypeEnum.getDescBtType(farmMsg.type())) |
|
|
|
|
.operation(FarmMsgTypeEnum.getDescBtType(farmMsg.operation())) |
|
|
|
|
.title(title) |
|
|
|
|
.msg(msg).build(); |
|
|
|
|
return farmMsgDTO; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|