Эх сурвалжийг харах

[task-1883]设备档案增加使用年限字段,并且到期提前1年提醒设备保管人到期,需要进行报废的消息

szjbdgzl 1 жил өмнө
parent
commit
8092ec9d10

+ 10 - 0
ibps-model-root/modules/org-model/src/main/java/com/lc/ibps/org/party/persistence/entity/PartyUserCalendarTbl.java

@@ -53,6 +53,16 @@ public class PartyUserCalendarTbl extends AbstractPo<String> {
     protected String dataInfo;
     @ApiModelProperty(value = "标记日期")
     protected String markDate;
+    @ApiModelProperty(value = "类型")
+    protected String type;
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
 
     public String getMarkDate() {
         return markDate;

+ 7 - 3
ibps-model-root/modules/org-model/src/main/resources/com/lc/ibps/org/party/persistence/mapping/PartyUserCalendar.map.xml

@@ -21,23 +21,24 @@
         <result property="dataSourceId" column="data_source_id_" jdbcType="VARCHAR"/>
         <result property="dataInfo" column="data_info_" jdbcType="LONGVARCHAR"/>
         <result property="markDate" column="mark_date_" jdbcType="VARCHAR"/>
+        <result property="type" column="type_" jdbcType="VARCHAR"/>
     </resultMap>
 
     <sql id="columns">
         id_,tenant_id_,ip_,create_by_,create_time_,update_by_,update_time_,user_id_,di_dian_,user_name_,title_,content_,
-        start_time_,end_time_,emergency_state_,serial_num_,data_source_id_,data_info_,mark_date_
+        start_time_,end_time_,emergency_state_,serial_num_,data_source_id_,data_info_,mark_date_,type_
     </sql>
 
     <insert id="create" parameterType="com.lc.ibps.org.party.persistence.entity.PartyUserCalendarPo">
         INSERT INTO IBPS_PARTY_USER_CALENDAR
         (ID_,TENANT_ID_,IP_,CREATE_BY_,CREATE_TIME_,UPDATE_BY_,UPDATE_TIME_,USER_ID_,DI_DIAN_,USER_NAME_,TITLE_,CONTENT_,
-         START_TIME_,END_TIME_,EMERGENCY_STATE_,SERIAL_NUM_,DATA_SOURCE_ID_,DATA_INFO_,MARK_DATE_)
+         START_TIME_,END_TIME_,EMERGENCY_STATE_,SERIAL_NUM_,DATA_SOURCE_ID_,DATA_INFO_,MARK_DATE_,TYPE_)
         VALUES
         (#{id,jdbcType=VARCHAR}, #{tenantId,jdbcType=VARCHAR}, #{ip,jdbcType=VARCHAR},#{createBy,jdbcType=VARCHAR},
          #{createTime,jdbcType=TIMESTAMP},#{updateBy,jdbcType=VARCHAR},#{updateTime,jdbcType=TIMESTAMP},#{userId,jdbcType=VARCHAR},
          #{diDian,jdbcType=VARCHAR},#{userName,jdbcType=VARCHAR},#{title,jdbcType=VARCHAR},#{content,jdbcType=LONGVARCHAR},
          #{startTime,jdbcType=VARCHAR},#{endTime,jdbcType=VARCHAR},#{emergencyState,jdbcType=VARCHAR},#{serialNum,jdbcType=VARCHAR},
-         #{dataSourceId,jdbcType=VARCHAR},#{dataInfo,jdbcType=LONGVARCHAR},#{markDate,jdbcType=VARCHAR})
+         #{dataSourceId,jdbcType=VARCHAR},#{dataInfo,jdbcType=LONGVARCHAR},#{markDate,jdbcType=VARCHAR},#{type,jdbcType=VARCHAR})
     </insert>
 
     <select id="get"  parameterType="java.lang.String" resultMap="PartyUserCalendar">
@@ -86,6 +87,9 @@
             <if test=" markDate !=null and markDate !='' ">
             ,MARK_DATE_ = #{markDate,jdbcType=VARCHAR}
             </if>
+            <if test=" type !=null and type !='' ">
+                ,TYPE_ = #{type,jdbcType=VARCHAR}
+            </if>
         WHERE ID_=#{id}
     </update>
 

+ 72 - 1
ibps-provider-root/modules/provider-platform/src/main/java/com/lc/ibps/platform/plan/job/EquipmentMaintenancePlanJob.java

@@ -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);
+                }
+            }
+        }
+    }
+
 }