|
|
@@ -6,7 +6,9 @@ import com.lc.ibps.base.core.util.JacksonUtil;
|
|
|
import com.lc.ibps.base.core.util.string.StringUtil;
|
|
|
import com.lc.ibps.base.framework.id.UniqueIdUtil;
|
|
|
import com.lc.ibps.base.framework.table.ICommonDao;
|
|
|
-import com.lc.ibps.components.quartz.BaseJob2;
|
|
|
+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.jetbrains.annotations.NotNull;
|
|
|
import org.quartz.JobDataMap;
|
|
|
import org.quartz.JobExecutionContext;
|
|
|
@@ -16,6 +18,7 @@ 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.*;
|
|
|
|
|
|
public class EquipmentMaintenancePlanJob extends AbstractJob {
|
|
|
@@ -24,6 +27,8 @@ public class EquipmentMaintenancePlanJob extends AbstractJob {
|
|
|
public static final String PLAN_DATE = "plan-date";
|
|
|
public static final String ADVANCE_DAYS = "advance_days";// 设备校准计划提前通知天数
|
|
|
private ICommonDao<?> commonDao = AppUtil.getBean(ICommonDao.class);
|
|
|
+ private final PartyUserCalendarDao calendarDao = AppUtil.getBean(PartyUserCalendarDao.class);
|
|
|
+
|
|
|
@Override
|
|
|
public void executeJob(JobExecutionContext context) throws Exception {
|
|
|
//step1: 组装查询参数
|
|
|
@@ -41,6 +46,9 @@ public class EquipmentMaintenancePlanJob extends AbstractJob {
|
|
|
// 根据设备检定校准计划 开启检定校准记录
|
|
|
startSbjdjzjlFlow();
|
|
|
|
|
|
+ // 设备使用年限到期预提醒
|
|
|
+ equipmentScrapReminder();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private void generateRecords(List<Map<String, Object>> list) throws Exception {
|
|
|
@@ -153,4 +161,67 @@ public class EquipmentMaintenancePlanJob extends AbstractJob {
|
|
|
// 检定/校准计划与实施记录表_子表
|
|
|
startWorkflow("t_mjsbjdxzjhzb","jdxzjlb","Process_1drpy0r");
|
|
|
}
|
|
|
+
|
|
|
+ // 设备档案增加使用年限字段,并且到期提前1年提醒设备保管人到期,需要进行报废的消息
|
|
|
+ // 根据 出厂日期 和使用年限判断
|
|
|
+ private void equipmentScrapReminder(){
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ String sql = "select guan_li_ren_ from t_sbdj where guan_li_ren_ !='' and guan_li_ren_ is not null group by guan_li_ren_";
|
|
|
+ List<Map<String, Object>> list = (List<Map<String, Object>>) commonDao.query(sql);
|
|
|
+ if (BeanUtils.isNotEmpty(list)){
|
|
|
+ for (Map<String, Object> map : list) {
|
|
|
+ String sql2 = " select id_,she_bei_ming_cheng_,yuan_she_bei_bian,guan_li_ren_,he_cha_xiao_zhun_,chu_chang_ri_qi_ from t_sbdj " +
|
|
|
+ " where guan_li_ren_='"+map.get("guan_li_ren_")+"' and he_cha_xiao_zhun_!='' and he_cha_xiao_zhun_ is not null and chu_chang_ri_qi_!='' and chu_chang_ri_qi_ is not null ";
|
|
|
+ List<Map<String, Object>> equipList = (List<Map<String, Object>>) commonDao.query(sql2);
|
|
|
+ if (BeanUtils.isNotEmpty(equipList)){
|
|
|
+ addCalendar(equipList,formatter);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addCalendar(List<Map<String, Object>> equipList,DateTimeFormatter formatter){
|
|
|
+ for (Map<String, Object> eqMap : equipList) {
|
|
|
+ String sourceId = StringUtil.defaultString(eqMap.get("id_").toString(),"");
|
|
|
+ String heChaXiaoZhun = StringUtil.defaultString(eqMap.get("he_cha_xiao_zhun_").toString(),"");
|
|
|
+ String chuChangRiQi = StringUtil.defaultString(eqMap.get("chu_chang_ri_qi_").toString(),"");
|
|
|
+ int year;
|
|
|
+ LocalDate createDate;
|
|
|
+ try{
|
|
|
+ year = Integer.parseInt(heChaXiaoZhun);
|
|
|
+ createDate = LocalDate.parse(chuChangRiQi, formatter);
|
|
|
+ }catch (Exception e){
|
|
|
+ // logger.warn("出厂日期或使用年限格式错误,无法转换!设备id_:{},出厂日期:{}, 使用年限:{}",sourceId,chuChangRiQi,heChaXiaoZhun);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ LocalDate futureDate = createDate.plusYears(year);
|
|
|
+ LocalDate currDate = LocalDate.now();
|
|
|
+ // 比较 出厂日期 加上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(),"");
|
|
|
+
|
|
|
+ PartyUserCalendarPo calendarPo = new PartyUserCalendarPo();
|
|
|
+ calendarPo.setDataSourceId(sourceId);
|
|
|
+ calendarPo.setDataInfo("t_sbdj");
|
|
|
+ calendarPo.setUserId(guanLiRen);
|
|
|
+ calendarPo.setTitle("设备使用到期预提醒");
|
|
|
+ calendarPo.setContent("根据出厂日期和使用年限计算得知,设备:"+yuanSheBeiBian +" "+ sheBeiMingCheng + " 将在一年后到期。");
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|