From 8f96db14833ec43faf8a738426edbdebceec134f Mon Sep 17 00:00:00 2001 From: zhanyunjiu <787952492@qq.com> Date: Mon, 8 Aug 2022 10:53:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B6=88=E6=81=AF=E9=80=80=E9=80=81=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/farm/annotation/FarmMsgAspect.java | 73 +++++++++++-------- .../farm/service/area/AreaServiceImpl.java | 1 - 2 files changed, 43 insertions(+), 31 deletions(-) diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsgAspect.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsgAspect.java index e577130f..486be6f6 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsgAspect.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/annotation/FarmMsgAspect.java @@ -7,7 +7,7 @@ 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.dal.dataobject.area.AreaDO; -import cn.iocoder.yudao.module.farm.dal.dataobject.discuss.DiscussDO; +import cn.iocoder.yudao.module.farm.dal.dataobject.crop.CropDO; 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.task.TaskDO; @@ -18,10 +18,13 @@ 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.area.AreaService; +import cn.iocoder.yudao.module.farm.service.crop.CropService; import cn.iocoder.yudao.module.farm.service.task.TaskService; 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.Data; import lombok.extern.slf4j.Slf4j; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.cp.api.WxCpMessageService; @@ -71,6 +74,8 @@ public class FarmMsgAspect { private TaskService taskService; @Resource private AreaService areaService; + @Resource + private CropService cropService; @Value("${wxma.app_id}") private String appid; @@ -108,20 +113,16 @@ public class FarmMsgAspect { //草稿不发送 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 (!farmMsgDTO.getNoSendMsg()){ -// //企业微信小程序通知消息 -// this.sendMiniMsg(user, farmMsgDTO, toUserStr); -// } -// } + //创建 更新 删除 发送信息 + if (farmMsg.operation().equals(FarmMsgTypeEnum.CREATE) || farmMsg.operation().equals(FarmMsgTypeEnum.UPDATE) + || farmMsg.operation().equals(FarmMsgTypeEnum.DELETE)){ + CombineMsg combineMsg = this.assembleCpUserId(farmMsg.type(), farmMsgDTO.getId()); + //发起人 + AdminUserDO adminUser = adminUserMapper.selectOne(AdminUserDO::getId, getLoginUserId()); + CpUserDO user = cpUserMapper.selectOne(CpUserDO::getUserId, adminUser.getCpUserId()); + //企业微信小程序通知消息 + this.sendMiniMsg(user, farmMsgDTO, combineMsg); + } //插入日志 LogMsgDO logMsgDO = LogMsgDO.builder() @@ -141,14 +142,14 @@ public class FarmMsgAspect { //发送小程序通知消息 - public void sendMiniMsg(CpUserDO createUser, FarmMsgDTO farmMsgDTO, String toUserStr) throws WxErrorException { + public void sendMiniMsg(CpUserDO createUser, FarmMsgDTO farmMsgDTO, CombineMsg combineMsg) throws WxErrorException { // 发小程序 WxCpMessageService wxCpMessageService = wxCpService.getMessageService(); // 构造一个企业推送消息 WxCpMessage message = new WxCpMessage(); //接受者 - message.setToUser(toUserStr); + message.setToUser(combineMsg.getToUserStr()); //消息类型 message.setMsgType("miniprogram_notice"); @@ -159,8 +160,10 @@ public class FarmMsgAspect { LinkedHashMap map = new LinkedHashMap<>(); map.put("发起人", createUser.getName()); + map.put("负责人", combineMsg.getMainPersonName()); if (farmMsgDTO.getType().equals(FarmMsgTypeEnum.PROJECT)){ - map.put("内容", farmMsgDTO.getTitle()); + map.put("项目批次号", farmMsgDTO.getId().toString()); + map.put("作物", combineMsg.getCropName()); }else if(farmMsgDTO.getType().equals(FarmMsgTypeEnum.TASK)){ this.taskDetail(farmMsgDTO.getId(), map); } @@ -189,31 +192,41 @@ public class FarmMsgAspect { } /** - * @Description 获取需要接受信息的成员 + * @Description 获取需要发送的相关信息 * @param id 可能是 projectId taskId 或 discussId **/ - public String assembleCpUserId(FarmMsgTypeEnum farmMsgType, Long id){ + public CombineMsg assembleCpUserId(FarmMsgTypeEnum farmMsgType, Long id){ List idList = new ArrayList<>(); + Long cropId = 0L; if (farmMsgType.equals(FarmMsgTypeEnum.PROJECT)){ ProjectDO project = projectMapper.selectOne(ProjectDO::getId, id); - idList.addAll(project.getMembers()); - }else if (farmMsgType.equals(FarmMsgTypeEnum.TASK)){ + idList.add(project.getMainPerson()); + cropId = project.getCropId(); + }else { TaskDO task = taskMapper.selectOne(TaskDO::getId, id); idList.add(task.getMainPerson()); - idList.addAll(task.getExecutorPerson()); - }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()); + cropId = task.getCropId(); } - + CombineMsg combineMsg = new CombineMsg(); StringBuilder builder = new StringBuilder(); List userList = cpUserMapper.selectList(CpUserDO::getId, idList); userList.forEach(user ->{ builder.append(user.getUserId()).append("|"); + combineMsg.setMainPersonName(user.getName()); }); - return builder.toString().substring(0, builder.length() -1); + combineMsg.setToUserStr(builder.toString().substring(0, builder.length() -1)); + CropDO crop = cropService.getCrop(cropId); + combineMsg.setCropName(crop.getName()); + return combineMsg; + } + + @Data + public class CombineMsg{ + private String toUserStr; //接受消息的人 目前是就负责人一个人接收消息 + + private String mainPersonName; //负责人名字 + + private String cropName; //作物名 } diff --git a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/area/AreaServiceImpl.java b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/area/AreaServiceImpl.java index 43c40ead..30a997bf 100644 --- a/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/area/AreaServiceImpl.java +++ b/zsw-farm/zsw-farm-impl/src/main/java/cn/iocoder/yudao/module/farm/service/area/AreaServiceImpl.java @@ -222,7 +222,6 @@ public class AreaServiceImpl implements AreaService { } List distinctIdList = areaList.stream().map(AreaDO::getId).distinct().collect(Collectors.toList()); - System.out.println(oneArea.getName() +",,"+ secondList.size()+">>>>" + distinctIdList.toString()); AreaProjectDTO areaProject = AreaProjectDTO.builder() .areaId(oneArea.getId()) .areaName(oneArea.getName())