Ver Fonte

发送已生成考核的消息,按照工厂、指标级别,分别下发给对应角色的人

sucheng há 1 ano atrás
pai
commit
f741c4a530

+ 24 - 0
cx-safe-check/cx-save-check-common/src/main/java/com/rongwei/sfcommon/sys/dao/AspSafetyProductObjectiveDao.java

@@ -1,7 +1,31 @@
 package com.rongwei.sfcommon.sys.dao;
 
 import com.rongwe.scentity.domian.AspSafetyProductObjective;
+import com.rongwe.scentity.vo.RoleIdAndUserIdsVo;
 import com.rongwei.rwcommon.base.BaseDao;
+import org.apache.ibatis.annotations.Select;
+
+import java.util.List;
 
 public interface AspSafetyProductObjectiveDao extends BaseDao<AspSafetyProductObjective> {
+    @Select("SELECT\n" +
+            "\tsr.ID AS 'id',\n" +
+            "\tGROUP_CONCAT( sur.USERID ) AS 'userIds' \n" +
+            "FROM\n" +
+            "\tsys_role sr\n" +
+            "\tLEFT JOIN sys_user_role sur ON sr.ID = sur.ROLEID \n" +
+            "\tAND sur.DELETED = 0\n" +
+            "\tLEFT JOIN sys_user_org suo ON suo.USERID = sur.USERID \n" +
+            "\tAND suo.DELETED = 0\n" +
+            "\tLEFT JOIN sys_organization so ON suo.ORGID = so.ID \n" +
+            "\tAND so.DELETED = 0 \n" +
+            "WHERE\n" +
+            "\tsr.DELETED = 0 \n" +
+            "\tAND sr.ID IN ( 'e9133e738d67492aa4b3a641894f85c2', 'b104293d47e34df8847d1634c29ab031', '16963f62b94149d9ae16eabc9248999b', '104ac71c72704bbd953da6d7c167ed3a', 'efed8df42bde46c9970c1476e74d6374' ) \n" +
+            "\tAND (\n" +
+            "\t\tso.ID = #{tenantId} \n" +
+            "\tOR so.FULLPID LIKE CONCAT( '%', #{tenantId}, '%' )) \n" +
+            "GROUP BY\n" +
+            "\tsr.ID")
+    List<RoleIdAndUserIdsVo> selectManagerByTenantId(String tenantId);
 }

+ 1 - 0
cx-safe-check/cx-save-check-common/src/main/java/com/rongwei/sfcommon/sys/dao/CheckItemsDao.java

@@ -23,6 +23,7 @@ public interface CheckItemsDao extends BaseDao<CheckItemsDo> {
     @Select("SELECT * FROM asp_check_items where DELETED = 0 and DATE_FORMAT(WARNDATE, '%Y-%m-%d') <= DATE_FORMAT(NOW(), '%Y-%m-%d')")
     List<CheckItemsDo> selectNeedReportEqu();
 
+    //特种设备管理员的ID:08e111e9dbc04706a3eb8367a65a3dc5
     @Select("SELECT\n" +
             "\tsu.ID \n" +
             "FROM\n" +

+ 65 - 3
cx-safe-check/cx-save-check-common/src/main/java/com/rongwei/sfcommon/sys/service/impl/AspSafetyProductObjectiveServiceImpl.java

@@ -9,7 +9,9 @@ import com.rongwe.scentity.domian.AspSafetyProductObjective;
 import com.rongwe.scentity.domian.AspSafetyProductObjectiveResult;
 import com.rongwe.scentity.domian.AspSafetyProductObjectiveResultScoreDetail;
 import com.rongwe.scentity.domian.AspSafetyProductObjectiveScoreDetail;
+import com.rongwe.scentity.vo.RoleIdAndUserIdsVo;
 import com.rongwei.rwcommon.utils.SecurityUtil;
+import com.rongwei.safecommon.utils.CXCommonUtils;
 import com.rongwei.sfcommon.sys.dao.AspSafetyProductObjectiveDao;
 import com.rongwei.sfcommon.sys.service.AspSafetyProductObjectiveResultScoreDetailService;
 import com.rongwei.sfcommon.sys.service.AspSafetyProductObjectiveResultService;
@@ -18,8 +20,7 @@ import com.rongwei.sfcommon.sys.service.AspSafetyProductObjectiveService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.LinkedList;
-import java.util.List;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -54,7 +55,7 @@ public class AspSafetyProductObjectiveServiceImpl extends ServiceImpl<AspSafetyP
 
         //遍历目标获取所有目标的ID集合
         List<String> collectIds = aspSafetyProductObjectives.stream().map(AspSafetyProductObjective::getId).collect(Collectors.toList());
-        if (ObjectUtil.isEmpty(collectIds)){
+        if (ObjectUtil.isEmpty(collectIds)) {
             return;
         }
         //查询出所有目标的子表数据
@@ -105,5 +106,66 @@ public class AspSafetyProductObjectiveServiceImpl extends ServiceImpl<AspSafetyP
         objectiveResultService.saveBatch(mainResList);
         //插入考核子表
         objectiveResultScoreDetailService.saveBatch(childResList);
+
+        //发送已生成考核的消息,按照工厂、指标级别,分别下发给对应角色的人
+        sendMessage(mainResList);
+
+    }
+
+    private void sendMessage(List<AspSafetyProductObjectiveResult> mainResList) {
+        //维护指标级别对应的角色ID
+        //objectivelevel:指标级别。
+        // 10:工厂级,副总:e9133e738d67492aa4b3a641894f85c2
+        // 20:部门级,部门长:b104293d47e34df8847d1634c29ab031
+        // 30:车间级,车间主任:16963f62b94149d9ae16eabc9248999b
+        // 40:工段级,工段主管:104ac71c72704bbd953da6d7c167ed3a
+        // 50:班组级,班长:efed8df42bde46c9970c1476e74d6374
+        Map<String, String> levelMap = new HashMap<>();
+        levelMap.put("10", "e9133e738d67492aa4b3a641894f85c2");
+        levelMap.put("20", "b104293d47e34df8847d1634c29ab031");
+        levelMap.put("30", "16963f62b94149d9ae16eabc9248999b");
+        levelMap.put("40", "104ac71c72704bbd953da6d7c167ed3a");
+        levelMap.put("50", "efed8df42bde46c9970c1476e74d6374");
+        //获取需要发送消息的工厂
+        Set<String> tenantIds = mainResList.stream().map(AspSafetyProductObjectiveResult::getTenantid).collect(Collectors.toSet());
+        //整理工厂下、各个指标级别、对应的角色(职位)下的员工ID,:<工厂ID,<角色ID,用户IDs(英文逗号隔开)>>
+        Map<String, Map<String, String>> tenantManagerMap = new HashMap<>();
+        tenantIds.forEach(tenantId -> {
+            List<RoleIdAndUserIdsVo> roleIdAndUserIdsVos = this.baseMapper.selectManagerByTenantId(tenantId);
+            Map<String, String> map = new HashMap<>();
+            roleIdAndUserIdsVos.forEach(item -> {
+                if (ObjectUtil.isNotEmpty(item.getId())) {
+                    map.put(item.getId(), item.getUserIds());
+                }
+            });
+            tenantManagerMap.put(tenantId, map);
+        });
+        //处理考核主表,发送消息
+        mainResList.forEach(item -> {
+            //判断工厂ID是否存在
+            if (ObjectUtil.isEmpty(item.getTenantid())) {
+                return;
+            }
+            //判断指标级别是否存在
+            if (ObjectUtil.isEmpty(item.getObjectivelevel())) {
+                return;
+            }
+            //获取该工厂下的角色对应的USERIDs
+            Map<String, String> map = tenantManagerMap.get(item.getTenantid());
+            //获取该数据的指标级别对应的角色ID
+            String roleId = levelMap.get(item.getObjectivelevel());
+            //获取该消息对应的用户IDs
+            if (ObjectUtil.isEmpty(roleId)) {
+                return;
+            }
+            List<String> userIdList = Arrays.asList(map.get(roleId).split(","));
+            //发送消息
+            CXCommonUtils.sendNotify("目标考核",
+                    "目标考核:【" + item.getYear().split("-")[0] + "】年,【" + item.getQuerter() + "】季度,【" + item.getDepartname() + "】单位的考核已生成,请及时完善",
+                    null,
+                    userIdList,
+                    item.getId(),
+                    "targetassessment");
+        });
     }
 }

+ 13 - 0
cx-safe-check/cx-save-check-entity/src/main/java/com/rongwe/scentity/vo/RoleIdAndUserIdsVo.java

@@ -0,0 +1,13 @@
+package com.rongwe.scentity.vo;
+
+import lombok.Data;
+
+/**
+ * @author :sc
+ * @since :2023/12/22
+ */
+@Data
+public class RoleIdAndUserIdsVo {
+    private String id;
+    private String userIds;
+}