|
|
@@ -25,6 +25,7 @@ import java.time.LocalDate;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.time.format.DateTimeParseException;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
public class EquipmentMaintenancePlanJob extends AbstractJob {
|
|
|
|
|
|
@@ -203,6 +204,7 @@ public class EquipmentMaintenancePlanJob extends AbstractJob {
|
|
|
int year;
|
|
|
String str = "一年";
|
|
|
LocalDate createDate;
|
|
|
+ ArrayList<String> pushuser = new ArrayList<>();
|
|
|
try{
|
|
|
year = Integer.parseInt(heChaXiaoZhun);
|
|
|
createDate = LocalDate.parse(chuChangRiQi, formatter);
|
|
|
@@ -217,29 +219,79 @@ public class EquipmentMaintenancePlanJob extends AbstractJob {
|
|
|
str = "一个月";
|
|
|
}
|
|
|
LocalDate currDate = LocalDate.now();
|
|
|
+
|
|
|
+ String guanLiRen = StringUtil.defaultString(eqMap.get("guan_li_ren_").toString(),"");
|
|
|
+ changeMessagePushUser(guanLiRen,pushuser);
|
|
|
+ if(pushuser.isEmpty()){
|
|
|
+ //当保管人所在的所有组都没有专业组组长的时候推送给保管者
|
|
|
+ pushuser.add(guanLiRen);
|
|
|
+ //过滤掉重复数据
|
|
|
+ pushuser.stream()
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
// 比较 出厂日期 加上N年后是否小于等于 当前日期
|
|
|
if (futureDate.isBefore(currDate) || futureDate.isEqual(currDate)) {
|
|
|
- Map<String, Object> rili = commonDao.queryOne("select id_ from ibps_party_user_calendar where type_='EQUIP_OVERDUE' and data_info_='t_sbdj' and data_source_id_='"+sourceId+"' limit 1");
|
|
|
- // 已经 添加过的日程不再提醒
|
|
|
- if (BeanUtils.isEmpty(rili)){
|
|
|
- String guanLiRen = StringUtil.defaultString(eqMap.get("guan_li_ren_").toString(),"");
|
|
|
- String yuanSheBeiBian = StringUtil.defaultString(eqMap.get("yuan_she_bei_bian").toString(),"");
|
|
|
- String sheBeiMingCheng = StringUtil.defaultString(eqMap.get("she_bei_ming_cheng_").toString(),"");
|
|
|
+ for(String zhanghao : pushuser){
|
|
|
+ Map<String, Object> rili = commonDao.queryOne("select id_ from ibps_party_user_calendar where type_='EQUIP_OVERDUE' and data_info_='t_sbdj' and data_source_id_='"+sourceId+"' and user_id_ = '"+zhanghao+"' limit 1");
|
|
|
+ // 已经 添加过的日程不再提醒
|
|
|
+ if (BeanUtils.isEmpty(rili)){
|
|
|
+ String yuanSheBeiBian = StringUtil.defaultString(eqMap.get("yuan_she_bei_bian").toString(),"");
|
|
|
+ String sheBeiMingCheng = StringUtil.defaultString(eqMap.get("she_bei_ming_cheng_").toString(),"");
|
|
|
+
|
|
|
+ PartyUserCalendarPo calendarPo = new PartyUserCalendarPo();
|
|
|
+ calendarPo.setDataSourceId(sourceId);
|
|
|
+ calendarPo.setDataInfo("t_sbdj");
|
|
|
+ //calendarPo.setUserId(guanLiRen);
|
|
|
+ calendarPo.setUserId(zhanghao);
|
|
|
+ calendarPo.setTitle("设备使用到期预提醒");
|
|
|
+ calendarPo.setContent("根据出厂日期和使用年限计算得知,\n设备:【"+yuanSheBeiBian +" "+ sheBeiMingCheng + "】 已达最大使用年限或将在"+str+"后到期。\n出厂日期:"+chuChangRiQi+"。\n使用年限:"+heChaXiaoZhun+"年。");
|
|
|
+ calendarPo.setStartTime(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
|
|
|
+ calendarPo.setEndTime(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
|
|
|
+ calendarPo.setEmergencyState("2");
|
|
|
+ calendarPo.setId(UniqueIdUtil.getId());
|
|
|
+ calendarPo.setCreateBy("1");
|
|
|
+ calendarPo.setType("EQUIP_OVERDUE");
|
|
|
+ calendarDao.create(calendarPo);
|
|
|
+ logger.warn("设备到期提醒"+yuanSheBeiBian +":" + sheBeiMingCheng);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- PartyUserCalendarPo calendarPo = new PartyUserCalendarPo();
|
|
|
- calendarPo.setDataSourceId(sourceId);
|
|
|
- calendarPo.setDataInfo("t_sbdj");
|
|
|
- calendarPo.setUserId(guanLiRen);
|
|
|
- calendarPo.setTitle("设备使用到期预提醒");
|
|
|
- calendarPo.setContent("根据出厂日期和使用年限计算得知,\n设备:【"+yuanSheBeiBian +" "+ sheBeiMingCheng + "】 已达最大使用年限或将在"+str+"后到期。\n出厂日期:"+chuChangRiQi+"。\n使用年限:"+heChaXiaoZhun+"年。");
|
|
|
- calendarPo.setStartTime(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
|
|
|
- calendarPo.setEndTime(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
|
|
|
- calendarPo.setEmergencyState("2");
|
|
|
- calendarPo.setId(UniqueIdUtil.getId());
|
|
|
- calendarPo.setCreateBy("1");
|
|
|
- calendarPo.setType("EQUIP_OVERDUE");
|
|
|
- calendarDao.create(calendarPo);
|
|
|
- logger.warn("设备到期提醒"+yuanSheBeiBian +":" + sheBeiMingCheng);
|
|
|
+ private void changeMessagePushUser(String guanLiRen,List<String> pushuser) {
|
|
|
+ String sql = "select id_,positions_ from IBPS_PARTY_EMPLOYEE WHERE ID_='"+guanLiRen+"' limit 1";
|
|
|
+ List<Map<String, Object>> positions = (List<Map<String, Object>>) commonDao.query(sql);
|
|
|
+ if(BeanUtils.isEmpty(positions)){
|
|
|
+ logger.warn("设备保管人:"+guanLiRen+"查询不到用户信息");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Map<String, Object> positionMap = positions.get(0);
|
|
|
+ if(BeanUtils.isNotEmpty(positionMap.get("positions_"))){
|
|
|
+ String position = positionMap.get("positions_").toString().trim();
|
|
|
+ String positionsStr = convertToSqlInFormat(position);
|
|
|
+ String groupSql = "select id_,name_,depth_ from ibps_party_entity where DEPTH_>=4 and id_ in "+positionsStr;//DEPTH_为4以上的是组 1.0 获取用户所在部门类型为组的数据
|
|
|
+ List<Map<String, Object>> entity = (List<Map<String, Object>>) commonDao.query(groupSql);
|
|
|
+ if(BeanUtils.isEmpty(entity) || entity.size()<1){
|
|
|
+ logger.warn("设备保管人:"+guanLiRen+"查询不到用户所属组信息");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for(Map groupInfo :entity){
|
|
|
+ String roleIdSql = "select id_ from ibps_party_entity where PARTY_ALIAS_='zhsfzr' limit 1";//专业组组长角色
|
|
|
+ List<Map<String, Object>> role = (List<Map<String, Object>>) commonDao.query(roleIdSql);
|
|
|
+ String roleId = role.get(0).get("id_").toString().trim();
|
|
|
+ String group = (String) groupInfo.get("id_");
|
|
|
+ //获取和设备保管人一个组并且是专业组组长的用户
|
|
|
+ String teamLeaderSql = "SELECT id_,name_,status_,positions_,job_ FROM IBPS_PARTY_EMPLOYEE WHERE STATUS_='actived' and POSITIONS_ LIKE '%"+group.trim()+"%' AND JOB_ LIKE '%"+roleId+"%';";
|
|
|
+ List<Map<String, Object>> userList = (List<Map<String, Object>>) commonDao.query(teamLeaderSql);
|
|
|
+ if(BeanUtils.isEmpty(userList) || userList.size()<1){
|
|
|
+ logger.warn("设备保管人:"+guanLiRen+"所属组为【"+group+"】,该组下不存在专业组组长");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ for(Map user :userList){
|
|
|
+ pushuser.add(user.get("id_").toString());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -274,5 +326,10 @@ public class EquipmentMaintenancePlanJob extends AbstractJob {
|
|
|
}
|
|
|
return danWeiMingChen;
|
|
|
}
|
|
|
+ public String convertToSqlInFormat(String input) {
|
|
|
+ String[] parts = input.split(",");
|
|
|
+ String quoted = String.join("','", parts); // 用 ',' 连接
|
|
|
+ return "('" + quoted + "')"; // 首尾加括号和引号
|
|
|
+ }
|
|
|
|
|
|
}
|