Explorar el Código

pms 瑞恒 瑞鹰 发送消息数据权限

zhangcl hace 1 semana
padre
commit
5628c041d7

+ 57 - 51
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotrhdailyreport/IotRhDailyReportServiceImpl.java

@@ -8,6 +8,7 @@ import cn.hutool.core.util.StrUtil;
 import cn.iocoder.yudao.framework.common.pojo.PageParam;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
+import cn.iocoder.yudao.framework.datapermission.core.util.DataPermissionUtils;
 import cn.iocoder.yudao.module.pms.constant.PmsConstants;
 import cn.iocoder.yudao.module.pms.controller.admin.iotcarzhbd.vo.IotCarZhbdPageReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.iotdevicecategorytemplateattrs.vo.IotDeviceProperty;
@@ -149,7 +150,7 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
         // 中航北斗车辆id集合
         Set<String> zhbdCarIds = new HashSet<>();
         // 井号
-        String wellName = StrUtil.EMPTY;
+        String wellName;
         if (CollUtil.isNotEmpty(tasks)) {
             IotProjectTaskDO task = tasks.get(0);
             // 暂时只考虑1个施工队伍只属于1个任务
@@ -212,6 +213,7 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
                         ));
             }
         } else {
+            wellName = StrUtil.EMPTY;
             // 当前队伍没有关联任务 不生成日报
             // throw exception(IOT_PROJECT_TASK_NOT_RELATED);
         }
@@ -331,63 +333,67 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
         DeptDO dept = deptService.getDept(deptId);
         Long parentId = dept.getParentId();
         if (ObjUtil.isNotEmpty(parentId)) {
-            DeptDO projectDept = deptService.getDept(parentId);
-            if (ObjUtil.isNotEmpty(projectDept) && "2".equals(projectDept.getType())) {
-                // 查询项目部下具有 项目部日报审批RH 角色的人员
-                Set<Long> projectIds = new HashSet<>();
-                projectIds.add(projectDept.getId());
-                List<AdminUserDO> receivedMsgUsers = adminUserService.getUserListByDeptIds(projectIds);
-                if (CollUtil.isNotEmpty(receivedMsgUsers)) {
-                    Set<Long> userIds = new HashSet<>();
-                    receivedMsgUsers.forEach(user -> {
-                        userIds.add(user.getId());
-                    });
-                    RoleDO role = roleService.getRoleByCode("项目部日报审批RH");
-                    if (ObjUtil.isNotEmpty(role)) {
-                        Set<Long> roleIds = new HashSet<>();
-                        roleIds.add(role.getId());
-                        List<UserRoleDO> userRoles = userRoleMapper.selectListByRoleIds(roleIds);
-                        if (CollUtil.isNotEmpty(userRoles)) {
-                            // 提取有审批角色的所有用户ID(去重+空值过滤)
-                            Set<Long> roleUserIds = userRoles.stream()
-                                    .map(UserRoleDO::getUserId)
-                                    .filter(Objects::nonNull) // 过滤空userId
-                                    .collect(Collectors.toSet());
-                            // 计算两个集合的交集,得到最终目标用户ID
-                            Set<Long> targetUserIds = userIds.stream()
-                                    .filter(roleUserIds::contains)
-                                    .collect(Collectors.toSet());
-                            // 异步发送 站内信 钉钉消息
-                            if (CollUtil.isNotEmpty(targetUserIds)) {
-                                Map<Long, AdminUserRespDTO> users = adminUserApi.getUserMap(targetUserIds);
-                                // 给多个用户发送 相同 的 提醒消息
-                                if (CollUtil.isNotEmpty(users)) {
-                                    // 生成消息提醒标题 部门名称-井号
-                                    String msgTitle = dept.getName();
-                                    if (StrUtil.isNotBlank(wellName)) {
-                                        msgTitle = StrUtil.join("-", msgTitle, wellName);
-                                    }
-                                    CountDownLatch latch = new CountDownLatch(users.size());
-                                    String finalMsgTitle = msgTitle;
-                                    users.forEach((userId, user) -> {
-                                        pmsThreadPoolTaskExecutor.execute(() -> {
-                                            try {
-                                                String mobile = user.getMobile();
-                                                if (StrUtil.isNotBlank(mobile) && StrUtil.isNotBlank(finalMsgTitle)) {
-                                                    /* pmsMessage.sendMessage(iotRhDailyReport.getId(), finalMsgTitle, PmsConstants.RH_DAILY_REPORT_APPROVAL,
-                                                            userId, mobile); */
+            AtomicReference<DeptDO> projectDept = new AtomicReference<>();
+            DataPermissionUtils.executeIgnore(() -> {
+                projectDept.set(deptService.getDept(parentId));
+
+                if (ObjUtil.isNotEmpty(projectDept) && "2".equals(projectDept.get().getType())) {
+                    // 查询项目部下具有 项目部日报审批RH 角色的人员
+                    Set<Long> projectIds = new HashSet<>();
+                    projectIds.add(projectDept.get().getId());
+                    List<AdminUserDO> receivedMsgUsers = adminUserService.getUserListByDeptIds(projectIds);
+                    if (CollUtil.isNotEmpty(receivedMsgUsers)) {
+                        Set<Long> userIds = new HashSet<>();
+                        receivedMsgUsers.forEach(user -> {
+                            userIds.add(user.getId());
+                        });
+                        RoleDO role = roleService.getRoleByCode("项目部日报审批RH");
+                        if (ObjUtil.isNotEmpty(role)) {
+                            Set<Long> roleIds = new HashSet<>();
+                            roleIds.add(role.getId());
+                            List<UserRoleDO> userRoles = userRoleMapper.selectListByRoleIds(roleIds);
+                            if (CollUtil.isNotEmpty(userRoles)) {
+                                // 提取有审批角色的所有用户ID(去重+空值过滤)
+                                Set<Long> roleUserIds = userRoles.stream()
+                                        .map(UserRoleDO::getUserId)
+                                        .filter(Objects::nonNull) // 过滤空userId
+                                        .collect(Collectors.toSet());
+                                // 计算两个集合的交集,得到最终目标用户ID
+                                Set<Long> targetUserIds = userIds.stream()
+                                        .filter(roleUserIds::contains)
+                                        .collect(Collectors.toSet());
+                                // 异步发送 站内信 钉钉消息
+                                if (CollUtil.isNotEmpty(targetUserIds)) {
+                                    Map<Long, AdminUserRespDTO> users = adminUserApi.getUserMap(targetUserIds);
+                                    // 给多个用户发送 相同 的 提醒消息
+                                    if (CollUtil.isNotEmpty(users)) {
+                                        // 生成消息提醒标题 部门名称-井号
+                                        String msgTitle = dept.getName();
+                                        if (StrUtil.isNotBlank(wellName)) {
+                                            msgTitle = StrUtil.join("-", msgTitle, wellName);
+                                        }
+                                        CountDownLatch latch = new CountDownLatch(users.size());
+                                        String finalMsgTitle = msgTitle;
+                                        users.forEach((userId, user) -> {
+                                            pmsThreadPoolTaskExecutor.execute(() -> {
+                                                try {
+                                                    String mobile = user.getMobile();
+                                                    if (StrUtil.isNotBlank(mobile) && StrUtil.isNotBlank(finalMsgTitle)) {
+                                                        pmsMessage.sendMessage(iotRhDailyReport.getId(), finalMsgTitle, PmsConstants.RH_DAILY_REPORT_APPROVAL,
+                                                                userId, mobile);
+                                                    }
+                                                } finally {
+                                                    latch.countDown();
                                                 }
-                                            } finally {
-                                                latch.countDown();
-                                            }
+                                            });
                                         });
-                                    });
+                                    }
                                 }
                             }
                         }
                     }
                 }
-            }
+            });
         }
         return iotRhDailyReport.getId();
     }

+ 57 - 53
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotrydailyreport/IotRyDailyReportServiceImpl.java

@@ -8,6 +8,7 @@ import cn.hutool.core.util.StrUtil;
 import cn.iocoder.yudao.framework.common.pojo.PageParam;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
+import cn.iocoder.yudao.framework.datapermission.core.util.DataPermissionUtils;
 import cn.iocoder.yudao.module.pms.constant.PmsConstants;
 import cn.iocoder.yudao.module.pms.controller.admin.depttype.vo.IotDeptTypePageReqVO;
 import cn.iocoder.yudao.module.pms.controller.admin.iotdevicecategorytemplateattrs.vo.IotDeviceProperty;
@@ -126,7 +127,7 @@ public class IotRyDailyReportServiceImpl implements IotRyDailyReportService {
         // 查询包含当前日报施工队伍的任务
         List<IotProjectTaskDO> tasks = iotProjectTaskMapper.selectList(reqVO);
         // 井号
-        String wellName = StrUtil.EMPTY;
+        String wellName;
         if (CollUtil.isNotEmpty(tasks)) {
             IotProjectTaskDO task = tasks.get(0);
             wellName = task.getWellName();
@@ -144,6 +145,7 @@ public class IotRyDailyReportServiceImpl implements IotRyDailyReportService {
             // 查询任务的设备列表
             deviceIds = task.getDeviceIds();
         } else {
+            wellName = StrUtil.EMPTY;
             // 当前队伍没有关联任务 不生成日报
             // throw exception(IOT_PROJECT_TASK_NOT_RELATED);
         }
@@ -218,65 +220,67 @@ public class IotRyDailyReportServiceImpl implements IotRyDailyReportService {
         Long parentId = dept.getParentId();
         if (ObjUtil.isNotEmpty(parentId)) {
             DeptDO projectDept = deptService.getDept(parentId);
-            // 查找队伍上级项目部 拥有‘项目部日报审批RY’角色 的审批人 如果查找不到 则使用 瑞鹰国际 下拥有‘项目部日报审批RY’角色的审批人
-            if (ObjUtil.isNotEmpty(projectDept) && "2".equals(projectDept.getType())) {
-                // 查询项目部下具有 项目部日报审批RH 角色的人员 如果查找不到 查询 瑞鹰国际下 拥有‘项目部日报审批RH’角色的审批人
-                // 瑞鹰国际 158
-                Set<Long> projectIds = new HashSet<>();
-                projectIds.add(projectDept.getId());
-                projectIds.add(158l);
-                List<AdminUserDO> receivedMsgUsers = adminUserService.getUserListByDeptIds(projectIds);
-                if (CollUtil.isNotEmpty(receivedMsgUsers)) {
-                    Set<Long> userIds = new HashSet<>();
-                    receivedMsgUsers.forEach(user -> {
-                        userIds.add(user.getId());
-                    });
-                    RoleDO role = roleService.getRoleByCode("项目部日报审批RY");
-                    if (ObjUtil.isNotEmpty(role)) {
-                        Set<Long> roleIds = new HashSet<>();
-                        roleIds.add(role.getId());
-                        List<UserRoleDO> userRoles = userRoleMapper.selectListByRoleIds(roleIds);
-                        if (CollUtil.isNotEmpty(userRoles)) {
-                            // 提取有审批角色的所有用户ID(去重+空值过滤)
-                            Set<Long> roleUserIds = userRoles.stream()
-                                    .map(UserRoleDO::getUserId)
-                                    .filter(Objects::nonNull) // 过滤空userId
-                                    .collect(Collectors.toSet());
-                            // 计算两个集合的交集,得到最终目标用户ID
-                            Set<Long> targetUserIds = userIds.stream()
-                                    .filter(roleUserIds::contains)
-                                    .collect(Collectors.toSet());
-                            // 异步发送 站内信 钉钉消息
-                            if (CollUtil.isNotEmpty(targetUserIds)) {
-                                Map<Long, AdminUserRespDTO> users = adminUserApi.getUserMap(targetUserIds);
-                                // 给多个用户发送 相同 的 提醒消息
-                                if (CollUtil.isNotEmpty(users)) {
-                                    // 生成消息提醒标题 部门名称-井号
-                                    String msgTitle = dept.getName();
-                                    if (StrUtil.isNotBlank(wellName)) {
-                                        msgTitle = StrUtil.join("-", msgTitle, wellName);
-                                    }
-                                    CountDownLatch latch = new CountDownLatch(users.size());
-                                    String finalMsgTitle = msgTitle;
-                                    users.forEach((userId, user) -> {
-                                        pmsThreadPoolTaskExecutor.execute(() -> {
-                                            try {
-                                                String mobile = user.getMobile();
-                                                if (StrUtil.isNotBlank(mobile) && StrUtil.isNotBlank(finalMsgTitle)) {
-                                                    /* pmsMessage.sendMessage(iotRyDailyReport.getId(), finalMsgTitle, PmsConstants.RY_DAILY_REPORT_APPROVAL,
-                                                            userId, mobile); */
+            DataPermissionUtils.executeIgnore(() -> {
+                // 查找队伍上级项目部 拥有‘项目部日报审批RY’角色 的审批人 如果查找不到 则使用 瑞鹰国际 下拥有‘项目部日报审批RY’角色的审批人
+                if (ObjUtil.isNotEmpty(projectDept) && "2".equals(projectDept.getType())) {
+                    // 查询项目部下具有 项目部日报审批RH 角色的人员 如果查找不到 查询 瑞鹰国际下 拥有‘项目部日报审批RH’角色的审批人
+                    // 瑞鹰国际 158
+                    Set<Long> projectIds = new HashSet<>();
+                    projectIds.add(projectDept.getId());
+                    projectIds.add(158l);
+                    List<AdminUserDO> receivedMsgUsers = adminUserService.getUserListByDeptIds(projectIds);
+                    if (CollUtil.isNotEmpty(receivedMsgUsers)) {
+                        Set<Long> userIds = new HashSet<>();
+                        receivedMsgUsers.forEach(user -> {
+                            userIds.add(user.getId());
+                        });
+                        RoleDO role = roleService.getRoleByCode("项目部日报审批RY");
+                        if (ObjUtil.isNotEmpty(role)) {
+                            Set<Long> roleIds = new HashSet<>();
+                            roleIds.add(role.getId());
+                            List<UserRoleDO> userRoles = userRoleMapper.selectListByRoleIds(roleIds);
+                            if (CollUtil.isNotEmpty(userRoles)) {
+                                // 提取有审批角色的所有用户ID(去重+空值过滤)
+                                Set<Long> roleUserIds = userRoles.stream()
+                                        .map(UserRoleDO::getUserId)
+                                        .filter(Objects::nonNull) // 过滤空userId
+                                        .collect(Collectors.toSet());
+                                // 计算两个集合的交集,得到最终目标用户ID
+                                Set<Long> targetUserIds = userIds.stream()
+                                        .filter(roleUserIds::contains)
+                                        .collect(Collectors.toSet());
+                                // 异步发送 站内信 钉钉消息
+                                if (CollUtil.isNotEmpty(targetUserIds)) {
+                                    Map<Long, AdminUserRespDTO> users = adminUserApi.getUserMap(targetUserIds);
+                                    // 给多个用户发送 相同 的 提醒消息
+                                    if (CollUtil.isNotEmpty(users)) {
+                                        // 生成消息提醒标题 部门名称-井号
+                                        String msgTitle = dept.getName();
+                                        if (StrUtil.isNotBlank(wellName)) {
+                                            msgTitle = StrUtil.join("-", msgTitle, wellName);
+                                        }
+                                        CountDownLatch latch = new CountDownLatch(users.size());
+                                        String finalMsgTitle = msgTitle;
+                                        users.forEach((userId, user) -> {
+                                            pmsThreadPoolTaskExecutor.execute(() -> {
+                                                try {
+                                                    String mobile = user.getMobile();
+                                                    if (StrUtil.isNotBlank(mobile) && StrUtil.isNotBlank(finalMsgTitle)) {
+                                                        pmsMessage.sendMessage(iotRyDailyReport.getId(), finalMsgTitle, PmsConstants.RY_DAILY_REPORT_APPROVAL,
+                                                                userId, mobile);
+                                                    }
+                                                } finally {
+                                                    latch.countDown();
                                                 }
-                                            } finally {
-                                                latch.countDown();
-                                            }
+                                            });
                                         });
-                                    });
+                                    }
                                 }
                             }
                         }
                     }
                 }
-            }
+            });
         }
         // 返回
         return iotRyDailyReport.getId();