|
|
@ -2,14 +2,15 @@ package cn.iocoder.yudao.module.farm.annotation; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
|
|
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
|
|
|
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.ProjectRespVO; |
|
|
|
import cn.iocoder.yudao.module.farm.controller.admin.project.vo.ProjectUpdateReqVO; |
|
|
|
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.TaskRespVO; |
|
|
|
import cn.iocoder.yudao.module.farm.controller.admin.task.vo.TaskUpdateReqVO; |
|
|
|
import cn.iocoder.yudao.module.farm.controller.admin.task.vo.TaskUpdateReqVO; |
|
|
|
import cn.iocoder.yudao.module.farm.dal.dataobject.discuss.DiscussDO; |
|
|
|
import cn.iocoder.yudao.module.farm.dal.dataobject.discuss.DiscussDO; |
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.farm.dal.dataobject.logMsg.LogMsgDO; |
|
|
|
import cn.iocoder.yudao.module.farm.dal.dataobject.project.ProjectDO; |
|
|
|
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.task.TaskDO; |
|
|
|
import cn.iocoder.yudao.module.farm.dal.dataobject.taskCate.TaskCateDO; |
|
|
|
import cn.iocoder.yudao.module.farm.dal.dataobject.taskCate.TaskCateDO; |
|
|
@ -27,6 +28,8 @@ import lombok.extern.slf4j.Slf4j; |
|
|
|
import me.chanjar.weixin.cp.api.WxCpMessageService; |
|
|
|
import me.chanjar.weixin.cp.api.WxCpMessageService; |
|
|
|
import me.chanjar.weixin.cp.api.WxCpService; |
|
|
|
import me.chanjar.weixin.cp.api.WxCpService; |
|
|
|
import me.chanjar.weixin.cp.bean.message.WxCpMessage; |
|
|
|
import me.chanjar.weixin.cp.bean.message.WxCpMessage; |
|
|
|
|
|
|
|
import me.chanjar.weixin.cp.bean.message.WxCpMessageSendResult; |
|
|
|
|
|
|
|
import org.apache.poi.ss.formula.functions.T; |
|
|
|
import org.aspectj.lang.ProceedingJoinPoint; |
|
|
|
import org.aspectj.lang.ProceedingJoinPoint; |
|
|
|
import org.aspectj.lang.annotation.*; |
|
|
|
import org.aspectj.lang.annotation.*; |
|
|
|
import org.aspectj.lang.reflect.MethodSignature; |
|
|
|
import org.aspectj.lang.reflect.MethodSignature; |
|
|
@ -34,6 +37,7 @@ import org.springframework.stereotype.Component; |
|
|
|
import javax.annotation.Resource; |
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.lang.reflect.Method; |
|
|
|
import java.lang.reflect.Method; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
|
|
|
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
|
|
@ -86,73 +90,81 @@ public class FarmMsgAspect { |
|
|
|
return object; |
|
|
|
return object; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 构造一个企业推送消息
|
|
|
|
if (farmMsg.type() == FarmMsgTypeEnum.PROJECT || farmMsg.type() == FarmMsgTypeEnum.TASK){ |
|
|
|
WxCpMessage message = new WxCpMessage(); |
|
|
|
//处理所需要数据
|
|
|
|
|
|
|
|
MethodSignature signature = (MethodSignature) pjp.getSignature(); |
|
|
|
if (farmMsg.type() == FarmMsgTypeEnum.PROJECT){ |
|
|
|
Method method = signature.getMethod(); |
|
|
|
if (farmMsg.operation() == FarmMsgTypeEnum.CREATE){ |
|
|
|
FarmMsgDTO farmMsgDTO = this.assembleMsg(method, pjp.getArgs(), (CommonResult<?>) object); |
|
|
|
Long id = (Long) ((CommonResult<?>) object).getData(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//处理所需要数据
|
|
|
|
|
|
|
|
MethodSignature signature = (MethodSignature) pjp.getSignature(); |
|
|
|
|
|
|
|
Method method = signature.getMethod(); |
|
|
|
|
|
|
|
FarmMsgDTO farmMsgDTO = this.assembleMsg(method, pjp.getArgs(), (CommonResult<?>) object); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (farmMsgDTO.getNoSendMsg()){ |
|
|
|
|
|
|
|
//草稿不发送
|
|
|
|
|
|
|
|
return object; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//创建 更新 删除 发送信息
|
|
|
|
|
|
|
|
if (farmMsg.operation().equals(FarmMsgTypeEnum.CREATE) || farmMsg.operation().equals(FarmMsgTypeEnum.UPDATE) |
|
|
|
|
|
|
|
|| farmMsg.operation().equals(FarmMsgTypeEnum.DELETE)){ |
|
|
|
//接受消息的人
|
|
|
|
//接受消息的人
|
|
|
|
String toUserStr = this.assembleCpUserId(farmMsg.type(), id); |
|
|
|
String toUserStr = this.assembleCpUserId(farmMsg.type(), farmMsgDTO.getId()); |
|
|
|
//发起人
|
|
|
|
//发起人
|
|
|
|
AdminUserDO adminUser = adminUserMapper.selectOne(AdminUserDO::getId, getLoginUserId()); |
|
|
|
AdminUserDO adminUser = adminUserMapper.selectOne(AdminUserDO::getId, getLoginUserId()); |
|
|
|
CpUserDO user = cpUserMapper.selectOne(CpUserDO::getUserId, adminUser.getCpUserId()); |
|
|
|
CpUserDO user = cpUserMapper.selectOne(CpUserDO::getUserId, adminUser.getCpUserId()); |
|
|
|
|
|
|
|
|
|
|
|
StringBuilder description = new StringBuilder() |
|
|
|
StringBuilder description = new StringBuilder() |
|
|
|
.append(user.getName()) |
|
|
|
.append(user.getName()) |
|
|
|
.append(" ") |
|
|
|
.append(" ") |
|
|
|
.append(farmMsgDTO.getOperation().getDesc()) |
|
|
|
.append(farmMsgDTO.getOperation().getDesc()) |
|
|
|
.append(farmMsgDTO.getType().getDesc()) |
|
|
|
.append(farmMsgDTO.getType().getDesc()) |
|
|
|
.append(":") |
|
|
|
.append(":") |
|
|
|
.append(farmMsgDTO.getTitle()) |
|
|
|
.append(ObjectUtil.isEmpty(farmMsgDTO.getMsg()) ? farmMsgDTO.getTitle() : farmMsgDTO.getMsg()) |
|
|
|
.append("(其中有你)"); |
|
|
|
.append("(其中有你)"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!toUserStr.contains("WeiLaiKeQi")){ |
|
|
|
if (!toUserStr.contains("WeiLaiKeQi")){ |
|
|
|
return object; |
|
|
|
return object; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!farmMsgDTO.getNoSendMsg()){ |
|
|
|
|
|
|
|
//发送信息
|
|
|
|
// 发企业微信
|
|
|
|
this.sendCpMsg(description.toString(), toUserStr); |
|
|
|
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); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
// 跟新项目 删除项目 更新任务 删除任务。。。
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 构造一个卡片消息 消息名称 : 回乡农场任务管理更新 , 小标题: xxx 创建了项目,请查看处理。
|
|
|
|
//插入日志
|
|
|
|
// appid 是小程序的appid
|
|
|
|
LogMsgDO logMsgDO = LogMsgDO.builder() |
|
|
|
// touser 可以传多个。
|
|
|
|
.type(farmMsgDTO.getType().getDesc()) |
|
|
|
// 这里处理完删除注释
|
|
|
|
.operation(farmMsgDTO.getOperation().getDesc()) |
|
|
|
|
|
|
|
.title(farmMsgDTO.getTitle()) |
|
|
|
|
|
|
|
.msg(farmMsgDTO.getMsg()) |
|
|
|
|
|
|
|
.userId(getLoginUserId()) |
|
|
|
|
|
|
|
.build(); |
|
|
|
|
|
|
|
logMsgMapper.insert(logMsgDO); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return object; |
|
|
|
return object; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void sendCpMsg(String desc, String userStr) throws Throwable{ |
|
|
|
|
|
|
|
// 构造一个企业推送消息
|
|
|
|
|
|
|
|
WxCpMessage message = new WxCpMessage(); |
|
|
|
|
|
|
|
// 发企业微信
|
|
|
|
|
|
|
|
WxCpMessageService wxCpMessageService = wxCpService.getMessageService(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//消息类型 必填 此处固定为 文本卡片
|
|
|
|
|
|
|
|
message.setMsgType("textcard"); |
|
|
|
|
|
|
|
//企业应用id 必填
|
|
|
|
|
|
|
|
message.setAgentId(wxCpService.getWxCpConfigStorage().getAgentId()); |
|
|
|
|
|
|
|
//消息标题 必填
|
|
|
|
|
|
|
|
message.setTitle("回乡农场通知"); |
|
|
|
|
|
|
|
//消息描述 必填
|
|
|
|
|
|
|
|
message.setDescription(desc); |
|
|
|
|
|
|
|
//点击后跳转链接 必填
|
|
|
|
|
|
|
|
message.setUrl("https://www.baidu.com"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//接受消息成员 选填
|
|
|
|
|
|
|
|
message.setToUser(userStr); |
|
|
|
|
|
|
|
log.info("企业微信消息发送内容:{}", message); |
|
|
|
|
|
|
|
WxCpMessageSendResult result = wxCpMessageService.send(message); |
|
|
|
|
|
|
|
log.info("企业微信消息发送结果:{}",result); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @Description 获取需要接受信息的成员 |
|
|
|
* @Description 获取需要接受信息的成员 |
|
|
|
* @param id 可能是 projectId taskId 或 discussId |
|
|
|
* @param id 可能是 projectId taskId 或 discussId |
|
|
@ -185,62 +197,45 @@ public class FarmMsgAspect { |
|
|
|
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 = ""; |
|
|
|
|
|
|
|
Long id = 0L; |
|
|
|
|
|
|
|
Boolean noSendMsg = false; |
|
|
|
|
|
|
|
|
|
|
|
FarmMsg farmMsg = method.getAnnotation(FarmMsg.class); |
|
|
|
FarmMsg farmMsg = method.getAnnotation(FarmMsg.class); |
|
|
|
if (method.getName().startsWith("get")){ |
|
|
|
Object obj = Arrays.stream(objects).findFirst().get(); |
|
|
|
for (Object object : objects) { |
|
|
|
|
|
|
|
log.info("after用户{},{},{},{}",getLoginUserId(), farmMsg.type(), farmMsg.title(), object); |
|
|
|
if (farmMsg.type().equals(FarmMsgTypeEnum.PROJECT)){ |
|
|
|
if (farmMsg.type().equals(FarmMsgTypeEnum.PROJECT)){ |
|
|
|
ProjectDO projectDO = new ProjectDO(); |
|
|
|
CommonResult<ProjectRespVO> projectDO = (CommonResult<ProjectRespVO>) result; |
|
|
|
if (farmMsg.operation().equals(FarmMsgTypeEnum.CREATE) || farmMsg.operation().equals(FarmMsgTypeEnum.UPDATE)){ |
|
|
|
title = projectDO.getData().getName(); |
|
|
|
projectDO = BeanUtil.copyProperties(obj, ProjectDO.class); |
|
|
|
} |
|
|
|
}else if (farmMsg.operation().equals(FarmMsgTypeEnum.DELETE) || farmMsg.operation().equals(FarmMsgTypeEnum.SELECT)){ |
|
|
|
if (farmMsg.type().equals(FarmMsgTypeEnum.TASK)){ |
|
|
|
projectDO = projectMapper.selectOne(ProjectDO::getId, obj); |
|
|
|
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(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
title = projectDO.getName(); |
|
|
|
|
|
|
|
noSendMsg = ObjectUtil.isEmpty(projectDO.getDraft()) ? true : projectDO.getDraft(); |
|
|
|
if (method.getName().startsWith("create")){ |
|
|
|
id = farmMsg.operation() == FarmMsgTypeEnum.CREATE ? (Long) ((CommonResult<?>) result).getData() : projectDO.getId(); |
|
|
|
for (Object object : objects){ |
|
|
|
}else if (farmMsg.type().equals(FarmMsgTypeEnum.TASK)){ |
|
|
|
if (farmMsg.type().equals(FarmMsgTypeEnum.PROJECT)){ |
|
|
|
TaskDO taskDO = new TaskDO(); |
|
|
|
ProjectCreateReqVO projectDO = (ProjectCreateReqVO) object; |
|
|
|
if (farmMsg.operation().equals(FarmMsgTypeEnum.CREATE) || farmMsg.operation().equals(FarmMsgTypeEnum.UPDATE)){ |
|
|
|
title = projectDO.getName(); |
|
|
|
taskDO = BeanUtil.copyProperties(obj, TaskDO.class); |
|
|
|
} |
|
|
|
}else if (farmMsg.operation().equals(FarmMsgTypeEnum.DELETE) || farmMsg.operation().equals(FarmMsgTypeEnum.SELECT)){ |
|
|
|
if (farmMsg.type().equals(FarmMsgTypeEnum.TASK)){ |
|
|
|
taskDO = taskMapper.selectOne(TaskDO::getId, obj); |
|
|
|
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(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
ProjectDO project = projectMapper.selectOne(ProjectDO::getId, taskDO.getProjectId()); |
|
|
|
|
|
|
|
TaskCateDO taskCate = taskCateMapper.selectOne(TaskCateDO::getId, taskDO.getTaskCateId()); |
|
|
|
|
|
|
|
title = project.getName(); |
|
|
|
|
|
|
|
msg = taskCate.getName(); |
|
|
|
|
|
|
|
noSendMsg = ObjectUtil.isEmpty(taskDO.getDraft()) ? true : taskDO.getDraft(); |
|
|
|
|
|
|
|
id = farmMsg.operation() == FarmMsgTypeEnum.CREATE ? (Long) ((CommonResult<?>) result).getData() : taskDO.getId(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
FarmMsgDTO farmMsgDTO = FarmMsgDTO.builder() |
|
|
|
FarmMsgDTO farmMsgDTO = FarmMsgDTO.builder() |
|
|
|
.type(FarmMsgTypeEnum.getDescBtType(farmMsg.type())) |
|
|
|
.type(FarmMsgTypeEnum.getDescBtType(farmMsg.type())) |
|
|
|
.operation(FarmMsgTypeEnum.getDescBtType(farmMsg.operation())) |
|
|
|
.operation(FarmMsgTypeEnum.getDescBtType(farmMsg.operation())) |
|
|
|
.title(title) |
|
|
|
.title(title) |
|
|
|
.msg(msg).build(); |
|
|
|
.msg(msg) |
|
|
|
|
|
|
|
.id(id) |
|
|
|
|
|
|
|
.noSendMsg(noSendMsg) |
|
|
|
|
|
|
|
.build(); |
|
|
|
return farmMsgDTO; |
|
|
|
return farmMsgDTO; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|