Ver código fonte

[task-2125] 设备检定校准到期提醒功能开发

Li Yuan 1 ano atrás
pai
commit
fad1bfe08f

+ 84 - 17
ibps-provider-root/modules/provider-platform/src/main/java/com/lc/ibps/platform/plan/job/DeviceToDoRemindJob.java

@@ -32,21 +32,65 @@ public class DeviceToDoRemindJob extends BaseJob2 {
                 context.getTrigger().getKey().getName());
         logger.warn("jobDataMap=is {}.", JacksonUtil.toJsonString(dataMap.getWrappedMap()));
 
-
         // 按部门分组,查询每个部门没做保养的设备数量
-        String sql = "select bian_zhi_bu_men_, count(1) total from t_mjsbwhbyjlby where shi_fou_guo_shen_ ='待处理' and ji_hua_shi_jian_=current_date group by bian_zhi_bu_men_";
-        List<Map<String, Object>> deptList = (List<Map<String, Object>>)commonDao.query(sql);
-        if (BeanUtils.isNotEmpty(deptList)){
-            for (Map<String,Object> map : deptList){
+        try {
+            executeEquipmentCheck();
+        }catch (Exception e){
+                logger.error("executeEquipmentCheck error!",e);
+        }
+        // 设施环境待处理推送
+        try {
+            executeFacilityEnvironment();
+        }catch (Exception e){
+                logger.error("executeFacilityEnvironment error!",e);
+        }
+        //未编检定校准计划,且需要校准的设备,这类设备需在校准到期前一个月发消息和日程提醒用户
+        try {
+            executeCalibrationCheck();
+        }catch (Exception e){
+            logger.error("executeCalibrationCheck error!",e);
+        }
+    }
+
+    private void executeCalibrationCheck() {
+        //  设备检定校准到期提醒
+        String sshjSql = "SELECT she_bei_shi_bie_h,she_bei_ming_cheng_,xiao_zhun_you_xia,bian_zhi_bu_men_ FROM t_sbdj" +
+                " WHERE shi_fou_xiao_zhun ='是' AND TO_DAYS(xiao_zhun_you_xia) - TO_DAYS(NOW())   <= 30 AND she_bei_zhuang_ta='合格'" +
+                " AND id_ NOT IN (SELECT c.she_bei_bian_hao_ FROM t_mjsbjdxzjh p,t_mjsbjdxzjhzb c WHERE p.id_=c.parent_id_ AND p.shi_fou_guo_shen_='已完成')" +
+                " ORDER BY bian_zhi_bu_men_,xiao_zhun_you_xia DESC";
+        List<Map<String, Object>> mapList = (List<Map<String, Object>>)commonDao.query(sshjSql);
+        if (BeanUtils.isNotEmpty(mapList)){
+            String preBumen = null;
+            String headerString = "您好,%s存在未编检定校准计划,且需要校准的设备,这类设备校准时间即将到期或已过期,请及时安排人员处理!详细情况如下:";
+            String format = "【%s】 %s 有效期至 %s";
+            StringJoiner content = new StringJoiner("<br />").add(headerString);
+            for (Map<String,Object> map : mapList){
                 String deptId = map.get("bian_zhi_bu_men_").toString();
-                long count = (long)map.get("total");
-                // 发系统消息给对应的专业组组长和设备管理小组负责人
-                this.sendLeaders(deptId,"%s设备维护保养提醒","您的专业组有"+count+"条待处理的设备维护保养记录,请通知相关人员及时处理!","sbglxzfzr","/sbgls/mywh");
+                if(preBumen == null) preBumen = deptId;
+                if(!preBumen.equals(deptId)){
+                    // 发系统消息给对应的专业组设备管理员和科室设备管理小组负责人
+                    this.sendLeaders(preBumen,"%s设备检定校准到期提醒",content.toString(),
+                            "sbglxzfzr","/sbgls/jlsy/sbjdxzjhsb","sbgly");
+                    preBumen = deptId;
+                    content = new StringJoiner("<br />").add(headerString);
+                }
+                String code = map.get("she_bei_shi_bie_h").toString();
+                String name = map.get("she_bei_ming_cheng_").toString();
+                String expDate = map.get("xiao_zhun_you_xia").toString();
+                content.add(String.format(format,code,name,expDate));
+            }
+            //last one
+            if(preBumen !=null){
+                // 发系统消息给对应的专业组设备管理员和科室设备管理小组负责人
+                this.sendLeaders(preBumen,"%s设备检定校准到期提醒",content.toString(),"sbglxzfzr","/sbgls/jlsy/sbjdxzjhsb","sbgly");
             }
         }
+    }
 
+    private void executeFacilityEnvironment() {
         // 设施环境待处理推送
-        String sshjSql = "SELECT facs_type,bian_zhi_bu_men_,COUNT(1) AS total FROM v_facs_summary_daily WHERE shi_fou_guo_shen_ ='待处理'" +
+        String sshjSql = "SELECT facs_type,bian_zhi_bu_men_,COUNT(1) AS total" +
+                " FROM v_facs_summary_daily WHERE shi_fou_guo_shen_ ='待处理'" +
                 " GROUP BY bian_zhi_bu_men_,facs_type ORDER BY bian_zhi_bu_men_,facs_type";
         List<Map<String, Object>> mapList = (List<Map<String, Object>>)commonDao.query(sshjSql);
         if (BeanUtils.isNotEmpty(mapList)){
@@ -57,7 +101,8 @@ public class DeviceToDoRemindJob extends BaseJob2 {
                 if(preBumen == null) preBumen = deptId;
                 if(!preBumen.equals(deptId)){
                     // 发系统消息给对应的专业组组长和安全管理小组负责人
-                    this.sendLeaders(deptId,"%s设施环境监控提醒",content.toString(),"aqglxzfzr","/sshjgl/sshjjk/sshjkzzl");
+                    this.sendLeaders(preBumen,"%s设施环境监控提醒",content.toString(),
+                            "aqglxzfzr","/sshjgl/sshjjk/sshjkzzl");
                     preBumen = deptId;
                     content = new StringJoiner("<br />").add("您好,今天%s存在待处理的设施环境监控数据,请及时安排人员处理!详细情况如下:");
                 }
@@ -74,7 +119,28 @@ public class DeviceToDoRemindJob extends BaseJob2 {
         }
     }
 
+    private void executeEquipmentCheck() {
+        // 按部门分组,查询每个部门没做保养的设备数量
+        String sql = "select bian_zhi_bu_men_, count(1) total from t_mjsbwhbyjlby where shi_fou_guo_shen_ ='待处理'" +
+                " and ji_hua_shi_jian_=current_date group by bian_zhi_bu_men_";
+        List<Map<String, Object>> deptList = (List<Map<String, Object>>)commonDao.query(sql);
+        if (BeanUtils.isNotEmpty(deptList)){
+            for (Map<String,Object> map : deptList){
+                String deptId = map.get("bian_zhi_bu_men_").toString();
+                long count = (long)map.get("total");
+                // 发系统消息给对应的专业组组长和设备管理小组负责人
+                this.sendLeaders(deptId,"%s设备维护保养提醒","您的专业组有"+count+"条待处理的设备维护保养记录,请通知相关人员及时处理!",
+                        "sbglxzfzr","/sbgls/mywh");
+            }
+        }
+    }
+
     private void sendLeaders(String deptId,String subject ,String content,String roleString,String routeString){
+        //默认专业组组长
+        sendLeaders(deptId,subject,content,roleString,routeString,"zhsfzr");
+    }
+
+    private void sendLeaders(String deptId,String subject ,String content,String roleString,String routeString,String leader){
         Map<String, Object> map2 = new HashMap<>();
         map2.put("skipTypeMsg","{\"skipType\": 3,\"pathInfo\": \""+routeString+"\"}");
 
@@ -93,7 +159,7 @@ public class DeviceToDoRemindJob extends BaseJob2 {
         }catch (Exception e){
             diDian = path.split(StringPool.BACK_SLASH+StringPool.DOT)[0];
         }
-        // 推送提醒到专业组组长
+        // 推送提醒
         String sql2 = "SELECT ID_ " +
                 "FROM ibps_party_employee " +
                 "WHERE positions_ LIKE '%%%s%%' " +
@@ -103,18 +169,18 @@ public class DeviceToDoRemindJob extends BaseJob2 {
                 "    WHERE `ibps_party_user_role`.`ROLE_ID_` IN " +
                 "        (SELECT `ibps_party_role`.`ID_` " +
                 "        FROM `ibps_party_role` " +
-                "        WHERE `ibps_party_role`.`ROLE_ALIAS_` = 'zhsfzr'))";
-        sql2 = String.format(sql2,deptId);
+                "        WHERE `ibps_party_role`.`ROLE_ALIAS_` = '%s'))";
+        sql2 = String.format(sql2,deptId,leader);
         List<Map<String, Object>> leads = (List<Map<String, Object>>)commonDao.query(sql2);
         if (BeanUtils.isNotEmpty(leads)){
             for (Map<String,Object> lead : leads){
                 List<String> receiver = new ArrayList<>();
                 receiver.add(lead.get("ID_").toString());
-                MessageQueueProductorUtil.send("DeviceToDoRemindJob", "DeviceToDoRemindJob" , "inner" , receiver,null , subject, content, null, null, map2);
-                //TODO 消息模版
+                MessageQueueProductorUtil.send("DeviceToDoRemindJob", "DeviceToDoRemindJob" ,
+                        "inner" , receiver,null , subject, content, null, null, map2);
             }
         }
-        //推送提醒到其他负责人
+        //推送提醒到科室相关负责人
         if(StringUtils.isNotBlank(roleString)){
             String sql3 = "SELECT ID_ " +
                     "FROM IBPS_PARTY_EMPLOYEE C  " +
@@ -134,7 +200,8 @@ public class DeviceToDoRemindJob extends BaseJob2 {
                 for (Map<String,Object> lead : lead2){
                     List<String> receiver = new ArrayList<>();
                     receiver.add(lead.get("ID_").toString());
-                    MessageQueueProductorUtil.send("DeviceToDoRemindJob", "DeviceToDoRemindJob" , "inner" , receiver,null , subject, content, null, null, map2);
+                    MessageQueueProductorUtil.send("DeviceToDoRemindJob", "DeviceToDoRemindJob" ,
+                            "inner" , receiver,null , subject, content, null, null, map2);
                 }
             }
         }