|
|
|
@ -1,13 +1,11 @@
|
|
|
|
|
package cn.iocoder.yudao.module.farm.annotation; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
|
import cn.hutool.core.date.LocalDateTimeUtil; |
|
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
|
|
|
|
import cn.iocoder.yudao.module.farm.controller.admin.task.dto.TaskAssemblyDTO; |
|
|
|
|
import cn.iocoder.yudao.module.farm.controller.admin.task.dto.TaskDetailDTO; |
|
|
|
|
import cn.iocoder.yudao.module.farm.dal.dataobject.area.AreaDO; |
|
|
|
|
import cn.iocoder.yudao.module.farm.dal.dataobject.discuss.DiscussDO; |
|
|
|
|
import cn.iocoder.yudao.module.farm.dal.dataobject.logMsg.LogMsgDO; |
|
|
|
@ -25,21 +23,20 @@ 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 com.alibaba.fastjson.JSONObject; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import me.chanjar.weixin.common.error.WxErrorException; |
|
|
|
|
import me.chanjar.weixin.cp.api.WxCpMessageService; |
|
|
|
|
import me.chanjar.weixin.cp.api.WxCpService; |
|
|
|
|
import me.chanjar.weixin.cp.bean.message.WxCpAppChatMessage; |
|
|
|
|
import me.chanjar.weixin.cp.bean.message.WxCpMessage; |
|
|
|
|
import me.chanjar.weixin.cp.bean.message.WxCpMessageSendResult; |
|
|
|
|
import me.chanjar.weixin.cp.bean.messagebuilder.MiniProgramNoticeMsgBuilder; |
|
|
|
|
import me.chanjar.weixin.cp.tp.message.WxCpTpMessageHandler; |
|
|
|
|
import org.aspectj.lang.ProceedingJoinPoint; |
|
|
|
|
import org.aspectj.lang.annotation.*; |
|
|
|
|
import org.aspectj.lang.annotation.Around; |
|
|
|
|
import org.aspectj.lang.annotation.Aspect; |
|
|
|
|
import org.aspectj.lang.annotation.Pointcut; |
|
|
|
|
import org.aspectj.lang.reflect.MethodSignature; |
|
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
|
import java.lang.reflect.Method; |
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
@ -79,6 +76,9 @@ public class FarmMsgAspect {
|
|
|
|
|
@Value("${wxma.app_id}") |
|
|
|
|
private String appid; |
|
|
|
|
|
|
|
|
|
@Value("${spring.profiles.active}") |
|
|
|
|
private String active; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 定义切入点 @PointCut |
|
|
|
|
* 使用了@FarmMsg注解的地方切入 |
|
|
|
@ -90,51 +90,50 @@ public class FarmMsgAspect {
|
|
|
|
|
@Around("farmMsgPointCut(farmMsg)") |
|
|
|
|
public Object doAround(ProceedingJoinPoint pjp,FarmMsg farmMsg) throws Throwable { |
|
|
|
|
Object object = pjp.proceed(); |
|
|
|
|
if (object instanceof CommonResult){ |
|
|
|
|
// 只处理接口正常result
|
|
|
|
|
if (farmMsg.type() == FarmMsgTypeEnum.NONE |
|
|
|
|
|| farmMsg.operation() == FarmMsgTypeEnum.NONE |
|
|
|
|
|| ((CommonResult<?>) object).getCode()!=0 ){ |
|
|
|
|
return object; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (farmMsg.type() == FarmMsgTypeEnum.PROJECT || farmMsg.type() == FarmMsgTypeEnum.TASK){ |
|
|
|
|
//处理所需要数据
|
|
|
|
|
MethodSignature signature = (MethodSignature) pjp.getSignature(); |
|
|
|
|
Method method = signature.getMethod(); |
|
|
|
|
FarmMsgDTO farmMsgDTO = this.assembleMsg(method, pjp.getArgs(), (CommonResult<?>) object); |
|
|
|
|
|
|
|
|
|
if (farmMsgDTO.getNoSendMsg()){ |
|
|
|
|
//草稿不发送
|
|
|
|
|
if (active.equalsIgnoreCase("prod")){ |
|
|
|
|
if (object instanceof CommonResult){ |
|
|
|
|
// 只处理接口正常result
|
|
|
|
|
if (farmMsg.type() == FarmMsgTypeEnum.NONE |
|
|
|
|
|| farmMsg.operation() == FarmMsgTypeEnum.NONE |
|
|
|
|
|| ((CommonResult<?>) object).getCode()!=0 ){ |
|
|
|
|
return object; |
|
|
|
|
} |
|
|
|
|
//创建 更新 删除 发送信息
|
|
|
|
|
if (farmMsg.operation().equals(FarmMsgTypeEnum.CREATE) || farmMsg.operation().equals(FarmMsgTypeEnum.UPDATE) |
|
|
|
|
|| farmMsg.operation().equals(FarmMsgTypeEnum.DELETE)){ |
|
|
|
|
//接受消息的人
|
|
|
|
|
String toUserStr = this.assembleCpUserId(farmMsg.type(), farmMsgDTO.getId()); |
|
|
|
|
//发起人
|
|
|
|
|
AdminUserDO adminUser = adminUserMapper.selectOne(AdminUserDO::getId, getLoginUserId()); |
|
|
|
|
CpUserDO user = cpUserMapper.selectOne(CpUserDO::getUserId, adminUser.getCpUserId()); |
|
|
|
|
|
|
|
|
|
// if (!toUserStr.contains("WeiLaiKeQi")){
|
|
|
|
|
// return object;
|
|
|
|
|
// }
|
|
|
|
|
if (!farmMsgDTO.getNoSendMsg()){ |
|
|
|
|
//企业微信小程序通知消息
|
|
|
|
|
this.sendMiniMsg(user, farmMsgDTO, toUserStr); |
|
|
|
|
if (farmMsg.type() == FarmMsgTypeEnum.PROJECT || farmMsg.type() == FarmMsgTypeEnum.TASK){ |
|
|
|
|
//处理所需要数据
|
|
|
|
|
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(), farmMsgDTO.getId()); |
|
|
|
|
//发起人
|
|
|
|
|
AdminUserDO adminUser = adminUserMapper.selectOne(AdminUserDO::getId, getLoginUserId()); |
|
|
|
|
CpUserDO user = cpUserMapper.selectOne(CpUserDO::getUserId, adminUser.getCpUserId()); |
|
|
|
|
|
|
|
|
|
//插入日志
|
|
|
|
|
LogMsgDO logMsgDO = LogMsgDO.builder() |
|
|
|
|
.type(farmMsgDTO.getType().getDesc()) |
|
|
|
|
.operation(farmMsgDTO.getOperation().getDesc()) |
|
|
|
|
.title(farmMsgDTO.getTitle()) |
|
|
|
|
.msg(farmMsgDTO.getMsg()) |
|
|
|
|
.userId(getLoginUserId()) |
|
|
|
|
.build(); |
|
|
|
|
logMsgMapper.insert(logMsgDO); |
|
|
|
|
if (!farmMsgDTO.getNoSendMsg()){ |
|
|
|
|
//企业微信小程序通知消息
|
|
|
|
|
this.sendMiniMsg(user, farmMsgDTO, toUserStr); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//插入日志
|
|
|
|
|
LogMsgDO logMsgDO = LogMsgDO.builder() |
|
|
|
|
.type(farmMsgDTO.getType().getDesc()) |
|
|
|
|
.operation(farmMsgDTO.getOperation().getDesc()) |
|
|
|
|
.title(farmMsgDTO.getTitle()) |
|
|
|
|
.msg(farmMsgDTO.getMsg()) |
|
|
|
|
.userId(getLoginUserId()) |
|
|
|
|
.build(); |
|
|
|
|
logMsgMapper.insert(logMsgDO); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return object; |
|
|
|
|