Commit 26a84777 authored by tianbo's avatar tianbo

feat(jg): 更新安全问题追溯功能以支持设备使用期限计算

- 为设备超设计使用年限检查任务添加定时调度配置 - 在 updateEquipAndSendMessage 方法中添加事务管理和 ES 回滚注解 - 在 SafetyProblemTracingServiceImpl 中添加设备延期使用日期处理逻辑
parent 66e1081d
......@@ -160,8 +160,11 @@ public class SafetyProblemTracingDto extends BaseDto {
@ApiModelProperty(value = "投用年月")
private String useDate;
@ApiModelProperty(value = "制造日期")
private String productDate;
@ApiModelProperty(value = "安装监督检验日期")
private String installInspectionDate;
@ApiModelProperty(value = "首次使用截止日期/延长使用截止日期")
private String useDeadline;
@Data
@Getter
......
......@@ -3838,7 +3838,22 @@
si."ORG_BRANCH_NAME",
si."ORG_BRANCH_CODE",
si."COMPANY_ORG_BRANCH_CODE",
json_build_object('designWorkingLife', (SELECT MIN((num[1])::numeric) FROM regexp_matches(di."DESIGN_USE_DATE", '\d+', 'g') AS t(num)), 'useDate', ui."USE_DATE" ,'productDate', fi."PRODUCE_DATE")::text extraInfo,
parse_custom_date(
REGEXP_REPLACE(
REGEXP_REPLACE(
REGEXP_REPLACE(ui."USE_DATE", '[ 年月日/\-]', '-', 'g'),
'-+', '-', 'g'
),
'-$', '', 'g'
)) + ((SELECT MIN((num[1])::numeric) FROM regexp_matches(di."DESIGN_USE_DATE", '\d+', 'g') AS t(num)) ||'years')::"interval" as problemTime,
json_build_object('designWorkingLife', (SELECT MIN((num[1])::numeric) FROM regexp_matches(di."DESIGN_USE_DATE", '\d+', 'g') AS t(num)), 'useDate', ui."USE_DATE" ,'useDeadline', parse_custom_date(
REGEXP_REPLACE(
REGEXP_REPLACE(
REGEXP_REPLACE(ui."USE_DATE", '[ 年月日/\-]', '-', 'g'),
'-+', '-', 'g'
),
'-$', '', 'g'
)) + ((SELECT MIN((num[1])::numeric) FROM regexp_matches(di."DESIGN_USE_DATE", '\d+', 'g') AS t(num)) ||'years')::"interval")::text extraInfo,
parse_custom_date(
REGEXP_REPLACE(
REGEXP_REPLACE(
......@@ -3871,7 +3886,8 @@
si."ORG_BRANCH_NAME",
si."ORG_BRANCH_CODE",
si."COMPANY_ORG_BRANCH_CODE",
json_build_object('designWorkingLife', (SELECT MIN((num[1])::numeric) FROM regexp_matches(di."DESIGN_USE_DATE", '\d+', 'g') AS t(num)), 'useDate', ui."USE_DATE" ,'productDate', fi."PRODUCE_DATE")::text extraInfo,
(select "INSPECT_DATE" from idx_biz_jg_inspection_detection_info where "RECORD" = ui."RECORD" and "INSPECT_TYPE" = 'AZJDJY' ORDER BY "INSPECT_DATE" desc limit 1) + ((SELECT MIN((num[1])::numeric) FROM regexp_matches(di."DESIGN_USE_DATE", '\d+', 'g') AS t(num)) ||'years')::"interval" as problemTime,
json_build_object('designWorkingLife', (SELECT MIN((num[1])::numeric) FROM regexp_matches(di."DESIGN_USE_DATE", '\d+', 'g') AS t(num)),'installInspectionDate', (select "INSPECT_DATE" from idx_biz_jg_inspection_detection_info where "RECORD" = ui."RECORD" and "INSPECT_TYPE" = 'AZJDJY' ORDER BY "INSPECT_DATE" desc limit 1), 'useDeadline', (select "INSPECT_DATE" from idx_biz_jg_inspection_detection_info where "RECORD" = ui."RECORD" and "INSPECT_TYPE" = 'AZJDJY' ORDER BY "INSPECT_DATE" desc limit 1) + ((SELECT MIN((num[1])::numeric) FROM regexp_matches(di."DESIGN_USE_DATE", '\d+', 'g') AS t(num)) ||'years')::"interval")::text extraInfo,
case when (SELECT MIN((num[1])::numeric) FROM regexp_matches(di."DESIGN_USE_DATE", '\d+', 'g') AS t(num)) ~ '^\d{1,5}$' then
COALESCE((select "INSPECT_DATE" from idx_biz_jg_inspection_detection_info where "RECORD" = ui."RECORD" and "INSPECT_TYPE" = 'AZJDJY' ORDER BY "INSPECT_DATE" desc limit 1) + ((SELECT MIN((num[1])::numeric) FROM regexp_matches(di."DESIGN_USE_DATE", '\d+', 'g') AS t(num)) ||'years')::"interval" <![CDATA[<]]> #{currentDate}, false) else false end isExpired
from idx_biz_jg_use_info ui
......@@ -3893,7 +3909,6 @@
ui."USE_UNIT_NAME",
ui."USE_UNIT_CREDIT_CODE",
(select unit_type from tz_base_enterprise_info where use_unit_code = ui."USE_UNIT_CREDIT_CODE") unitType,
ri."EQU_LIST",
(SELECT name FROM tz_equipment_category WHERE code = ri."EQU_LIST") equList,
(SELECT name FROM tz_equipment_category WHERE code = ri."EQU_CATEGORY") equCategory,
ri."EQU_CATEGORY",
......@@ -3901,7 +3916,28 @@
si."ORG_BRANCH_NAME",
si."ORG_BRANCH_CODE",
si."COMPANY_ORG_BRANCH_CODE",
json_build_object('designWorkingLife', (SELECT MIN((num[1])::numeric) FROM regexp_matches(di."DESIGN_USE_DATE", '\d+', 'g') AS t(num)), 'useDate', ui."USE_DATE" ,'productDate', fi."PRODUCE_DATE")::text extraInfo,
di."DELAY_SERVICE_LIFE_DATE" as problemTime,
json_build_object (
'designWorkingLife',
(
SELECT MIN
( ( num [ 1 ] ) :: NUMERIC )
FROM
regexp_matches( di."DESIGN_USE_DATE", '\d+', 'g' ) AS T ( num )
),
'useDate',
CASE
WHEN ri."EQU_LIST" = '2000' THEN
ui."USE_DATE" ELSE NULL
END,
'installInspectionDate',
CASE
WHEN ri."EQU_LIST" = '6000' THEN
( SELECT "INSPECT_DATE" FROM idx_biz_jg_inspection_detection_info WHERE "RECORD" = ui."RECORD" AND "INSPECT_TYPE" = 'AZJDJY' ORDER BY "INSPECT_DATE" DESC LIMIT 1 ) ELSE NULL
END,
'useDeadline',
di."DELAY_SERVICE_LIFE_DATE"
) :: TEXT extraInfo,
di."DELAY_SERVICE_LIFE_DATE" <![CDATA[<]]> #{currentDate} isExpired
from idx_biz_jg_design_info di
LEFT JOIN idx_biz_jg_use_info ui on di."RECORD" = ui."RECORD"
......
......@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.yeejoin.amos.boot.biz.common.annotation.EnableEsRollback;
import com.yeejoin.amos.boot.biz.common.entity.BaseEntity;
import com.yeejoin.amos.boot.module.common.api.dao.ESEquipmentCategory;
import com.yeejoin.amos.boot.module.common.api.dto.ESEquipmentCategoryDto;
......@@ -26,6 +27,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.typroject.tyboot.component.emq.EmqKeeper;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
......@@ -71,7 +73,7 @@ public class SafetyProblemTracingGenServiceImpl{
executeEnterpriseQualificationCheck();
}
@Scheduled(cron = "0 0 1 * * ?")
@Scheduled(cron = "0 0 2 * * ?")
@SchedulerLock(name = "executePersonnelCertification", lockAtMostFor = "PT5H", lockAtLeastFor = "PT10M")
public void executePersonnelCertification() {
executePersonnalCertificationCheck();
......@@ -251,6 +253,7 @@ public class SafetyProblemTracingGenServiceImpl{
public void repairMaintenanceAndInspectionOverdueProblem() {
logger.info("开始设备维保备案和检验检测超期数据修正");
// TODO:待完善,考虑超设计使用年限的问题处理逻辑
Set<String> realOutOfMaintenanceRecord = Sets.newHashSet();
processLargeResultSet(() -> commonMapper.queryOutOfMaintenanceRecord(), realOutOfMaintenanceRecord);
Set<String> inMaintenanceRecord = Sets.newHashSet();
......@@ -317,7 +320,7 @@ public class SafetyProblemTracingGenServiceImpl{
if (ValidationUtil.isEmpty(realOutOfMaintenanceRecord) && ValidationUtil.isEmpty(inMaintenanceRecord)) {
return Lists.newArrayList();
}
logger.info("设备维保超期safety表数据修正开始,实际检验超期数据:{}条", realOutOfMaintenanceRecord.size());
logger.info("设备维保超期safety表数据修正开始,实际维保超期数据:{}条", realOutOfMaintenanceRecord.size());
List<SafetyProblemTracing> problemList = safetyProblemTracingService.list(new LambdaQueryWrapper<SafetyProblemTracing>()
.select(SafetyProblemTracing::getSourceId)
.eq(SafetyProblemTracing::getProblemStatusCode, SafetyProblemStatusEnum.UNHANDLED.getCode())
......@@ -448,7 +451,11 @@ public class SafetyProblemTracingGenServiceImpl{
T get();
}
private void updateEquipAndSendMessage(List<Map<String, Object>> mapList, SafetyProblemTypeEnum safetyProblemTypeEnum) {
@Transactional
@EnableEsRollback
public void updateEquipAndSendMessage(List<Map<String, Object>> mapList, SafetyProblemTypeEnum safetyProblemTypeEnum) {
try {
logger.info("updateEquipAndSendMessage设备异常处理开始,待处理数据:{}条", mapList.size());
if (ValidationUtil.isEmpty(mapList)) {
return;
}
......@@ -466,11 +473,16 @@ public class SafetyProblemTracingGenServiceImpl{
equipmentCategoryDto.setProblemStatus(SafetyProblemStatusEnum.UNHANDLED.getCode());
esEquipmentCategoryDto.add(equipmentCategoryDto);
}
esEquipmentCategory.saveAll(esEquipmentCategoryDto);
esEquipmentCategory.saveAllWithFallback(esEquipmentCategoryDto);
// mapList也根据batch分割
List<Map<String, Object>> mapListBatch = mapList.subList(i, Math.min(i + batchSize, mapList.size()));
sendSafetyProblemMessage(mapListBatch, safetyProblemTypeEnum);
}
logger.info("updateEquipAndSendMessage设备异常处理完成,已处理数据:{}条", records.size());
} catch (Exception e) {
logger.error("updateEquipAndSendMessage设备异常处理过程中发生异常", e);
throw new RuntimeException(e);
}
}
private void updateEnterpriseAndSendMessage(List<Map<String, Object>> mapList) {
......@@ -521,8 +533,8 @@ public class SafetyProblemTracingGenServiceImpl{
}
}
// @Scheduled(cron = "0 0 1 * * ?")
// @SchedulerLock(name = "executeOverDesignLifeCheck", lockAtMostFor = "PT5H", lockAtLeastFor = "PT10M")
@Scheduled(cron = "0 0 3 * * ?")
@SchedulerLock(name = "executeOverDesignLifeCheck", lockAtMostFor = "PT5H", lockAtLeastFor = "PT10M")
public void executeOverDesignLife() {
executeOverDesignLifeCheck();
}
......@@ -537,7 +549,7 @@ public class SafetyProblemTracingGenServiceImpl{
}
// 查询当天超设计使用年限的设备-办理超期登记后再次超期
List<Map<String, Object>> overDesignLifeAgainRecords = commonMapper.queryOverDesignLifeAgainRecord(new Date());
if (!ValidationUtil.isEmpty(overDesignLifeRecords)) {
if (!ValidationUtil.isEmpty(overDesignLifeAgainRecords)) {
allEquipRecords.addAll(overDesignLifeAgainRecords);
}
updateEquipAndSendMessage(allEquipRecords, SafetyProblemTypeEnum.SJNXCQ);
......
package com.yeejoin.amos.boot.module.jg.biz.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.map.MapUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
......@@ -19,7 +20,6 @@ import com.yeejoin.amos.boot.biz.common.entity.DataDictionary;
import com.yeejoin.amos.boot.biz.common.service.impl.DataDictionaryServiceImpl;
import com.yeejoin.amos.boot.module.common.api.constant.TZSCommonConstant;
import com.yeejoin.amos.boot.module.common.api.dao.ESEquipmentCategory;
import com.yeejoin.amos.boot.module.common.api.dto.ESEquipmentCategoryDto;
import com.yeejoin.amos.boot.module.jg.api.dto.SafetyProblemTracingDto;
import com.yeejoin.amos.boot.module.jg.api.entity.SafetyProblemTracing;
import com.yeejoin.amos.boot.module.jg.api.enums.SafetyProblemSourceTypeEnum;
......@@ -29,7 +29,7 @@ import com.yeejoin.amos.boot.module.jg.api.mapper.CommonMapper;
import com.yeejoin.amos.boot.module.jg.api.mapper.SafetyProblemTracingMapper;
import com.yeejoin.amos.boot.module.jg.api.service.ISafetyProblemTracingService;
import com.yeejoin.amos.boot.module.jg.biz.service.IIdxBizJgRegisterInfoService;
import com.yeejoin.amos.boot.module.ymt.api.dto.EquipWaitRefreshDataQualityScore;
import com.yeejoin.amos.boot.module.ymt.api.entity.IdxBizJgDesignInfo;
import com.yeejoin.amos.boot.module.ymt.api.entity.IdxBizJgInspectionDetectionInfo;
import com.yeejoin.amos.boot.module.ymt.api.entity.IdxBizJgMaintenanceRecordInfo;
import com.yeejoin.amos.boot.module.ymt.api.entity.IdxBizJgOtherInfo;
......@@ -70,6 +70,9 @@ public class SafetyProblemTracingServiceImpl extends BaseService<SafetyProblemTr
@Autowired
ESEquipmentCategory esEquipmentCategory;
@Autowired
IdxBizJgDesignInfoServiceImpl idxBizJgDesignInfoService;
private static Map<String, String> regionCodeOrgCodeMap = new ConcurrentHashMap<>();
@Autowired
CommonMapper commonMapper;
......@@ -145,8 +148,11 @@ public class SafetyProblemTracingServiceImpl extends BaseService<SafetyProblemTr
if (jsonObject.containsKey("useDate")) {
entity.setUseDate(jsonObject.getString("useDate"));
}
if (jsonObject.containsKey("productDate")) {
entity.setProductDate(jsonObject.getString("productDate"));
if (jsonObject.containsKey("installInspectionDate")) {
entity.setInstallInspectionDate(jsonObject.getString("installInspectionDate"));
}
if (jsonObject.containsKey("useDeadline")) {
entity.setUseDeadline(jsonObject.getString("useDeadline"));
}
} catch (Exception e) {
e.printStackTrace();
......@@ -312,6 +318,16 @@ public class SafetyProblemTracingServiceImpl extends BaseService<SafetyProblemTr
item.setProblemStatusCode(SafetyProblemStatusEnum.HANDLED.getCode());
item.setProblemStatus(SafetyProblemStatusEnum.HANDLED.getName());
}
if (item.getProblemTypeCode().equals(SafetyProblemTypeEnum.SJNXCQ.getProblemTypeCode())) {
IdxBizJgDesignInfo designInfo = idxBizJgDesignInfoService.getById(record);
if (!ValidationUtil.isEmpty(designInfo) && !ValidationUtil.isEmpty(designInfo.getDelayServiceLifeDate())) {
Date delayServiceLifeDate = DateUtil.parse(designInfo.getDelayServiceLifeDate());
if (new Date().before(delayServiceLifeDate)) {
item.setProblemStatusCode(SafetyProblemStatusEnum.HANDLED.getCode());
item.setProblemStatus(SafetyProblemStatusEnum.HANDLED.getName());
}
}
}
});
this.saveOrUpdateBatch(safetyProblemTracings);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment