|
|
@@ -10,7 +10,6 @@ import com.lc.ibps.base.saas.token.ITenantTokenService;
|
|
|
import com.lc.ibps.base.web.context.ContextUtil;
|
|
|
import com.lc.ibps.bpmn.api.IBpmInstService;
|
|
|
import com.lc.ibps.cloud.entity.APIResult;
|
|
|
-import com.lc.ibps.cloud.message.util.MessageQueueProductorUtil;
|
|
|
import com.lc.ibps.org.party.persistence.dao.PartyUserCalendarDao;
|
|
|
import com.lc.ibps.org.party.persistence.entity.PartyUserCalendarPo;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
@@ -23,7 +22,6 @@ import org.slf4j.LoggerFactory;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
-import java.time.format.DateTimeParseException;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -34,6 +32,8 @@ public class EquipmentMaintenancePlanJob extends AbstractJob {
|
|
|
public static final String ADVANCE_DAYS = "advance_days";// 设备校准计划提前通知天数
|
|
|
private ICommonDao<?> commonDao = AppUtil.getBean(ICommonDao.class);
|
|
|
private final PartyUserCalendarDao calendarDao = AppUtil.getBean(PartyUserCalendarDao.class);
|
|
|
+ public static final String HS_DAY1 = "日保养";
|
|
|
+ public static final String HS_DAY2 = "每天";
|
|
|
|
|
|
@Override
|
|
|
public void executeJob(JobExecutionContext context) throws Exception {
|
|
|
@@ -45,6 +45,8 @@ public class EquipmentMaintenancePlanJob extends AbstractJob {
|
|
|
transform(list, queryParam);
|
|
|
|
|
|
if (BeanUtils.isNotEmpty(list)){
|
|
|
+ //恒生医院增加写入逻辑
|
|
|
+ addPusher(list);
|
|
|
//step4: 写入数据库
|
|
|
generateRecords(list);
|
|
|
}
|
|
|
@@ -57,6 +59,184 @@ public class EquipmentMaintenancePlanJob extends AbstractJob {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ private void addPusher(List<Map<String, Object>> list) {
|
|
|
+ //step1 读取恒生医院配置
|
|
|
+ if(!"深圳恒生医院".equals(getSetting())){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ logger.warn("深圳恒生医院设备使用与维护添加推送人start");
|
|
|
+ HashMap<String, String> deptRelatPusher = new HashMap<>();//编制部门对应该推送的人
|
|
|
+ Map<String, String> sbglxzfzrMap = new HashMap<>();//四级部门设备管理组组长
|
|
|
+ //step2 便利插入的数据增加推送人字段
|
|
|
+ for(Map data : list){
|
|
|
+ //设备的编制部门,设备的编制部门在编制计划的时候不允许为空,所以这里不用校验了
|
|
|
+ String sbDept = data.get("bian_zhi_bu_men_").toString();
|
|
|
+ String pusher = "";
|
|
|
+ //如果是每天维护的数据则无需添加指定的推送人
|
|
|
+ String zhuZhouQi = data.get("zhu_zhou_qi_").toString();
|
|
|
+ if(BeanUtils.isNotEmpty(zhuZhouQi) &&
|
|
|
+ (HS_DAY1.equals(zhuZhouQi) || HS_DAY2.equals(zhuZhouQi))){//每天都要推送的跳过指定推送人
|
|
|
+ logger.warn("每天都要推送的跳过指定推送人");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if(BeanUtils.isEmpty(deptRelatPusher.get(sbDept))){
|
|
|
+ pusher = getDeptRelatPusher(data,sbglxzfzrMap);
|
|
|
+ data.put("ke_tui_song_ren_",pusher);
|
|
|
+ deptRelatPusher.put(data.get("bian_zhi_bu_men_").toString(),pusher);
|
|
|
+ }else{
|
|
|
+ data.put("ke_tui_song_ren_",deptRelatPusher.get(sbDept));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getDeptRelatPusher(Map data,Map sbglxzfzrMap) {
|
|
|
+ String sbDept = data.get("bian_zhi_bu_men_").toString();
|
|
|
+ String sbglyID = "";
|
|
|
+ String sbglxzfzrID = "";
|
|
|
+ String Level3Sbglxzfzr ="";//三级部门推送要加上名下所有四级部门的设备管理组长角色
|
|
|
+ Boolean deptLevel3 = false;
|
|
|
+ Boolean deptLevel4 = true;//默认只存在四级部门
|
|
|
+ String result = "";
|
|
|
+ //1.0 获取设备管理员和设备管理组长角色ID
|
|
|
+ String roleIdsSql = "SELECT ROLE_ALIAS_,ID_ FROM ibps_party_role WHERE ROLE_ALIAS_ IN ('sbgly','sbglxzfzr')";
|
|
|
+
|
|
|
+
|
|
|
+ List<Map<String, Object>> equipList = (List<Map<String, Object>>) commonDao.query(roleIdsSql);
|
|
|
+ if (BeanUtils.isNotEmpty(equipList)){
|
|
|
+ for(Map<String, Object> role : equipList){
|
|
|
+ if("sbgly".equals(role.get("ROLE_ALIAS_"))){
|
|
|
+ sbglyID = (String) role.get("ID_");
|
|
|
+ }
|
|
|
+ if("sbglxzfzr".equals(role.get("ROLE_ALIAS_"))){
|
|
|
+ sbglxzfzrID = (String) role.get("ID_");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //2.0 判断是三级部门(检验科)还是四级部门(临检组)
|
|
|
+ Map<String, String> allSbglxzfzrMap = new HashMap<>();
|
|
|
+ String levelSql = "select * from ibps_party_entity where party_type_='position' and PATH_ like '%"+sbDept+"%';";
|
|
|
+ List<Map<String, Object>> dataList = (List<Map<String, Object>>) commonDao.query(levelSql);
|
|
|
+ if (BeanUtils.isNotEmpty(dataList)){
|
|
|
+ for(Map<String, Object> dept : dataList){
|
|
|
+ int depthLevel = findPosition(dept.get("PATH_").toString(), sbDept.trim());
|
|
|
+ if("3".equals(String.valueOf(depthLevel))){
|
|
|
+ deptLevel3 = true;
|
|
|
+ deptLevel4 = false;
|
|
|
+ //获取该三级部门下所有的四级部门设备管理组组长(如果有)
|
|
|
+ allSbglxzfzrMap = getAllSbglxzfzr(sbDept, sbglxzfzrID, sbglxzfzrMap);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if("4".equals(String.valueOf(depthLevel))){
|
|
|
+ deptLevel3 = false;
|
|
|
+ deptLevel4 = true;
|
|
|
+ Map<String, Object> path = getNumberByIndex(dept.get("PATH_").toString(), 3);//获取三级部门ID
|
|
|
+ allSbglxzfzrMap = getAllSbglxzfzr((String) path.get("id"), sbglxzfzrID, sbglxzfzrMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //3.0 查找不到指定推送人则推送所有人
|
|
|
+ String pusherIdsSql = "select GROUP_CONCAT(ID_ SEPARATOR ',') as id_concat,\n" +
|
|
|
+ " GROUP_CONCAT(NAME_ SEPARATOR ',') as name_concat from ibps_party_employee where POSITIONS_ like '%"+sbDept+"%' " +
|
|
|
+ "and (JOB_ like '%"+sbglyID+"%' or JOB_ like '%"+sbglxzfzrID+"%')";//指定部门的推送人
|
|
|
+ Map<String, Object> pusherIds = commonDao.queryOne(pusherIdsSql);
|
|
|
+
|
|
|
+ if (BeanUtils.isEmpty(pusherIds) ||
|
|
|
+ BeanUtils.isEmpty(pusherIds.get("id_concat"))) {
|
|
|
+ if(deptLevel4){
|
|
|
+ logger.warn("查询不到四级编制部门为:{},角色ID包含{},或者{}的账号数据", sbDept,sbglyID,sbglxzfzrID);
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ if(deptLevel3 && allSbglxzfzrMap.isEmpty()){
|
|
|
+ logger.warn("查询不到三级编制部门为:{},角色ID包含{},或者{}的账号数据", sbDept,sbglyID,sbglxzfzrID);
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (BeanUtils.isEmpty(pusherIds) || pusherIds.get("id_concat").toString().isEmpty()) {
|
|
|
+ result = allSbglxzfzrMap.isEmpty() ? "" : String.join(",", allSbglxzfzrMap.values());
|
|
|
+ } else if (allSbglxzfzrMap.isEmpty()) {
|
|
|
+ result = pusherIds.get("id_concat").toString();
|
|
|
+ } else {
|
|
|
+ result = String.join(",", allSbglxzfzrMap.values()) + "," + pusherIds.get("id_concat").toString();
|
|
|
+ }
|
|
|
+ result = Arrays.stream(result.split(","))
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.joining(","));
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, String> getAllSbglxzfzr(String sbDept, String sbglxzfzrID, Map sbglxzfzrCacheMap) {
|
|
|
+ //获取三级部门下所有的部门
|
|
|
+ Map<String, String> sbglxzfzrMap = new HashMap<>();
|
|
|
+ String sql = "select * from ibps_party_entity where party_type_ ='position' and PATH_ like '%"+sbDept+"%' and DEPTH_>3 ";
|
|
|
+ List<Map<String, Object>> dataList = (List<Map<String, Object>>) commonDao.query(sql);
|
|
|
+ if(BeanUtils.isEmpty(dataList))return sbglxzfzrMap;
|
|
|
+ for(Map<String, Object> dept : dataList){
|
|
|
+ if(sbglxzfzrCacheMap.containsKey(dept.get("ID_"))){
|
|
|
+ sbglxzfzrMap.put(dept.get("ID_").toString(), (String) sbglxzfzrCacheMap.get(dept.get("ID_").toString()));
|
|
|
+ }else {
|
|
|
+ //四级部门名下的设备管理组长,正常来说只有一个或者没有在科室名下
|
|
|
+ String sqlSbglxzfzr ="select * from ibps_party_employee where POSITIONS_ like '%"+dept.get("ID_")+"%' and JOB_ like '%"+sbglxzfzrID+"%' limit 1";
|
|
|
+ Map<String, Object> sbglxzfzrUserId = commonDao.queryOne(sqlSbglxzfzr);
|
|
|
+ //生化组存入生化组的设备管理组组长-举例
|
|
|
+ if(BeanUtils.isNotEmpty(sbglxzfzrUserId)){
|
|
|
+ sbglxzfzrMap.put(dept.get("ID_").toString(),sbglxzfzrUserId.get("ID_").toString());
|
|
|
+ sbglxzfzrCacheMap.put(dept.get("ID_"),sbglxzfzrUserId.get("ID_"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return sbglxzfzrMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据数字查找在字符串中的位置
|
|
|
+ * @param input 输入字符串,包含用.分隔的数字
|
|
|
+ * @param target 要查找的目标数字字符串
|
|
|
+ * @return 位置序号(从1开始),如果不存在返回-1
|
|
|
+ */
|
|
|
+ public static int findPosition(String input, String target) {
|
|
|
+ if (input == null || target == null || input.trim().isEmpty() || target.trim().isEmpty()) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 按.分割字符串
|
|
|
+ String[] parts = input.split("\\.");
|
|
|
+
|
|
|
+ // 遍历查找目标字符串
|
|
|
+ for (int i = 0; i < parts.length; i++) {
|
|
|
+ if (parts[i].equals(target)) {
|
|
|
+ return i + 1; // 位置从1开始
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return -1; // 未找到
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Map<String, Object> getNumberByIndex(String input, int index) {
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+
|
|
|
+ // 检查输入是否为空或索引小于1
|
|
|
+ if (input == null || input.trim().isEmpty() || index < 1) {
|
|
|
+ result.put("id", "");
|
|
|
+ result.put("depth", -1);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ // 按点号分割字符串
|
|
|
+ String[] parts = input.split("\\.");
|
|
|
+ // 检查索引是否超出范围
|
|
|
+ if (index > parts.length) {
|
|
|
+ result.put("id", "");
|
|
|
+ result.put("depth", -1);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ // 返回对应索引的元素和深度信息
|
|
|
+ result.put("id", parts[index - 1]);
|
|
|
+ result.put("depth", index); // DEPTH_就是索引位置
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
private void generateRecords(List<Map<String, Object>> list) throws Exception {
|
|
|
int success = 0;
|
|
|
int error = 0;
|
|
|
@@ -90,7 +270,7 @@ public class EquipmentMaintenancePlanJob extends AbstractJob {
|
|
|
" END AS period_num,device.wei_hu_ri_qi_ AS zhu_zhou_qi_ ,device.id_ AS she_bei_bian_hao_,device.bian_zhi_bu_men_, " +
|
|
|
" device.she_bei_ming_cheng_ AS she_bei_ming_chen,device.she_bei_shi_bie_h AS ri_qi_,device.cun_fang_di_dian_ AS sheng_xiao_ri_qi_, " +
|
|
|
" jhb.id_ AS ji_hua_zong_wai_j,jhzb.id_ AS ji_hua_wai_jian_ ,device.wei_hu_fang_shi_ AS wei_hu_gang_wei_ , " +
|
|
|
- " device.di_dian_ ,device.wei_hu_lei_xing_,device.yuan_she_bei_bian AS original_device_n " +
|
|
|
+ " device.di_dian_ ,device.wei_hu_lei_xing_,device.yuan_she_bei_bian AS original_device_n ,'' as ke_tui_song_ren_ " +
|
|
|
" FROM `t_mjsbwhjhb` jhb,`t_mjsbwhjhzb` jhzb,`v_device_devicemaintenance` device " +
|
|
|
" WHERE jhb.shi_fou_guo_shen_='已完成' AND jhb.zhi_xing_zhuang_t='正常' " +
|
|
|
" AND jhb.id_ = jhzb.parent_id_ " +
|