Commit 7f2f8ec0 authored by suhuiguang's avatar suhuiguang

feat(综合搜索):数据同步调整

1.日期格式化增加兼容业务错误数据
parent a2c7d00a
package com.yeejoin.amos.boot.module.jg.biz.refresh; package com.yeejoin.amos.boot.module.jg.biz.refresh;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.yeejoin.amos.boot.module.common.api.dto.ITechParamDefine; import com.yeejoin.amos.boot.module.common.api.dto.ITechParamDefine;
import com.yeejoin.amos.boot.module.common.api.dto.TechParamItem; import com.yeejoin.amos.boot.module.common.api.dto.TechParamItem;
import com.yeejoin.amos.boot.module.common.api.entity.ESEquipmentInfo; import com.yeejoin.amos.boot.module.common.api.entity.ESEquipmentInfo;
import com.yeejoin.amos.boot.module.common.biz.utils.TechParamUtil; import com.yeejoin.amos.boot.module.common.biz.utils.TechParamUtil;
import com.yeejoin.amos.boot.module.jg.biz.edit.backup.TechParamsBackupService; import com.yeejoin.amos.boot.module.jg.biz.edit.backup.TechParamsBackupService;
import com.yeejoin.amos.boot.module.ymt.api.entity.IdxBizJgInspectionDetectionInfo;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.time.ZoneId;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
@Slf4j
public class StatisticsDataUpdateService { public class StatisticsDataUpdateService {
private final TechParamsBackupService techParamsBackupService; private final TechParamsBackupService techParamsBackupService;
public static final String USE_DATE_KEY = "USE_DATE";
public List<ESEquipmentInfo.TechParam> getTechParams(String equList, String record) { public List<ESEquipmentInfo.TechParam> getTechParams(String equList, String record) {
List<ESEquipmentInfo.TechParam> techParams = new ArrayList<>(); List<ESEquipmentInfo.TechParam> techParams = new ArrayList<>();
...@@ -44,7 +51,7 @@ public class StatisticsDataUpdateService { ...@@ -44,7 +51,7 @@ public class StatisticsDataUpdateService {
/** /**
* 判断字符串是否为合法的 JSON 格式 * 判断字符串是否为合法的 JSON 格式
*/ */
public static boolean isJSONValid(String test) { public static boolean isJSONValid(String test) {
try { try {
...@@ -55,13 +62,10 @@ public class StatisticsDataUpdateService { ...@@ -55,13 +62,10 @@ public class StatisticsDataUpdateService {
} }
} }
public static String castList2String(List<String> posts){
return String.join(",", posts);
}
public static String castStrList2String(String jsonTypesStr){ public static String castStrList2String(String jsonTypesStr) {
if(!isNullOrEmpty(jsonTypesStr)){ if (!isNullOrEmpty(jsonTypesStr)) {
if(isJSONValid(jsonTypesStr)){ if (isJSONValid(jsonTypesStr)) {
List<String> posts = JSON.parseArray(jsonTypesStr, String.class); List<String> posts = JSON.parseArray(jsonTypesStr, String.class);
return String.join(",", posts); return String.join(",", posts);
} }
...@@ -74,4 +78,35 @@ public class StatisticsDataUpdateService { ...@@ -74,4 +78,35 @@ public class StatisticsDataUpdateService {
return str == null || str.trim().isEmpty() || "null".equals(str); return str == null || str.trim().isEmpty() || "null".equals(str);
} }
public static void formatUseDate(Map<String, Object> detail) {
if (detail.containsKey(USE_DATE_KEY) && detail.get(USE_DATE_KEY) != null) {
if (detail.get(USE_DATE_KEY).toString().isEmpty() || detail.get(USE_DATE_KEY).toString().equals("null")) {
detail.put(USE_DATE_KEY, null);
} else {
String useDateStr = "";
try {
useDateStr = detail.get(USE_DATE_KEY).toString();
detail.put(USE_DATE_KEY, DateUtil.parse(useDateStr));
} catch (Exception e) {
log.error("非法的USE_DATE格式:{}", useDateStr);
detail.put(USE_DATE_KEY, null);
}
}
}
}
public static void formatInspectDate(ESEquipmentInfo esEquipmentInfo, IdxBizJgInspectionDetectionInfo inspectionDetectionInfo, String record) {
try {
esEquipmentInfo.setINSPECT_DATE(inspectionDetectionInfo.getSequenceNbr() != null ? inspectionDetectionInfo.getInspectDate() != null ? inspectionDetectionInfo.getInspectDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate() : null :null);
} catch (Exception e) {
log.error("INSPECT_DATE时区转换失败:{}", record, e);
}
try {
esEquipmentInfo.setNEXT_INSPECT_DATE(inspectionDetectionInfo.getSequenceNbr() != null ? inspectionDetectionInfo.getNextInspectDate() != null ? inspectionDetectionInfo.getNextInspectDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate() : null :null);
} catch (Exception e) {
log.error("NEXT_INSPECT_DATE时区转换失败:{}", record, e);
}
}
} }
...@@ -57,16 +57,12 @@ public class EquipmentRefreshHandler implements IDataRefreshHandler { ...@@ -57,16 +57,12 @@ public class EquipmentRefreshHandler implements IDataRefreshHandler {
String record = message.getDataId(); String record = message.getDataId();
ESEquipmentInfo esEquipmentInfo = new ESEquipmentInfo(); ESEquipmentInfo esEquipmentInfo = new ESEquipmentInfo();
Map<String, Object> detail = useInfoService.getBaseMapper().queryDetail(record); Map<String, Object> detail = useInfoService.getBaseMapper().queryDetail(record);
StatisticsDataUpdateService.formatUseDate(detail);
BeanUtil.copyProperties(detail, esEquipmentInfo, true); BeanUtil.copyProperties(detail, esEquipmentInfo, true);
List<IdxBizJgInspectionDetectionInfo> inspectionDetectionInfos = iIdxBizJgInspectionDetectionInfoService.queryLastedGroupByInspectType(record); List<IdxBizJgInspectionDetectionInfo> inspectionDetectionInfos = iIdxBizJgInspectionDetectionInfoService.queryLastedGroupByInspectType(record);
IdxBizJgInspectionDetectionInfo inspectionDetectionInfo = iIdxBizJgInspectionDetectionInfoService.queryNewestDetailByRecord(record); IdxBizJgInspectionDetectionInfo inspectionDetectionInfo = iIdxBizJgInspectionDetectionInfoService.queryNewestDetailByRecord(record);
IdxBizJgMaintenanceRecordInfo lastMaintenanceRecordInfo = maintenanceRecordInfoService.queryNewestDetailByRecord(record); IdxBizJgMaintenanceRecordInfo lastMaintenanceRecordInfo = maintenanceRecordInfoService.queryNewestDetailByRecord(record);
try { StatisticsDataUpdateService.formatInspectDate(esEquipmentInfo, inspectionDetectionInfo, record);
esEquipmentInfo.setINSPECT_DATE(inspectionDetectionInfo.getSequenceNbr() != null ? inspectionDetectionInfo.getInspectDate() != null ? inspectionDetectionInfo.getInspectDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate() : null : null);
esEquipmentInfo.setNEXT_INSPECT_DATE(inspectionDetectionInfo.getSequenceNbr() != null ? inspectionDetectionInfo.getNextInspectDate() != null ? inspectionDetectionInfo.getNextInspectDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate() : null : null);
} catch (Exception e) {
log.error("时区转换失败:{}", record, e);
}
esEquipmentInfo.setIssueDate(getIssueDate(esEquipmentInfo.getUSE_ORG_CODE())); esEquipmentInfo.setIssueDate(getIssueDate(esEquipmentInfo.getUSE_ORG_CODE()));
esEquipmentInfo.setMAINTAIN_UNIT(lastMaintenanceRecordInfo.getMeUnitCreditCode()); esEquipmentInfo.setMAINTAIN_UNIT(lastMaintenanceRecordInfo.getMeUnitCreditCode());
esEquipmentInfo.setMAINTAIN_UNIT_NAME(lastMaintenanceRecordInfo.getMeUnitName()); esEquipmentInfo.setMAINTAIN_UNIT_NAME(lastMaintenanceRecordInfo.getMeUnitName());
...@@ -80,6 +76,7 @@ public class EquipmentRefreshHandler implements IDataRefreshHandler { ...@@ -80,6 +76,7 @@ public class EquipmentRefreshHandler implements IDataRefreshHandler {
} }
} }
private List<ESEquipmentInfo.TechParam> buildTechParamByEquList(String record, String equListCode) { private List<ESEquipmentInfo.TechParam> buildTechParamByEquList(String record, String equListCode) {
return StringUtils.isNotEmpty(equListCode) ? statisticsDataUpdateService.getTechParams(equListCode, record) : new ArrayList<>(); return StringUtils.isNotEmpty(equListCode) ? statisticsDataUpdateService.getTechParams(equListCode, record) : new ArrayList<>();
} }
......
...@@ -1510,6 +1510,7 @@ public class DataHandlerServiceImpl { ...@@ -1510,6 +1510,7 @@ public class DataHandlerServiceImpl {
try { try {
esEquipmentInfo = new ESEquipmentInfo(); esEquipmentInfo = new ESEquipmentInfo();
Map<String,Object> detail = useInfoService.getBaseMapper().queryDetail(record); Map<String,Object> detail = useInfoService.getBaseMapper().queryDetail(record);
StatisticsDataUpdateService.formatUseDate(detail);
BeanUtil.copyProperties(detail, esEquipmentInfo, true); BeanUtil.copyProperties(detail, esEquipmentInfo, true);
Optional<ESEquipmentCategoryDto> esOptional = esEquipmentCategory.findById(record); Optional<ESEquipmentCategoryDto> esOptional = esEquipmentCategory.findById(record);
if(esOptional.isPresent()){ if(esOptional.isPresent()){
...@@ -1522,12 +1523,7 @@ public class DataHandlerServiceImpl { ...@@ -1522,12 +1523,7 @@ public class DataHandlerServiceImpl {
List<IdxBizJgInspectionDetectionInfo> inspectionDetectionInfos = iIdxBizJgInspectionDetectionInfoService.queryLastedGroupByInspectType(record); List<IdxBizJgInspectionDetectionInfo> inspectionDetectionInfos = iIdxBizJgInspectionDetectionInfoService.queryLastedGroupByInspectType(record);
IdxBizJgInspectionDetectionInfo inspectionDetectionInfo = iIdxBizJgInspectionDetectionInfoService.queryNewestDetailByRecord(record); IdxBizJgInspectionDetectionInfo inspectionDetectionInfo = iIdxBizJgInspectionDetectionInfoService.queryNewestDetailByRecord(record);
IdxBizJgMaintenanceRecordInfo lastMaintenanceRecordInfo = maintenanceRecordInfoService.queryNewestDetailByRecord(record); IdxBizJgMaintenanceRecordInfo lastMaintenanceRecordInfo = maintenanceRecordInfoService.queryNewestDetailByRecord(record);
try { StatisticsDataUpdateService.formatInspectDate(esEquipmentInfo, inspectionDetectionInfo, record);
esEquipmentInfo.setINSPECT_DATE(inspectionDetectionInfo.getSequenceNbr() != null ? inspectionDetectionInfo.getInspectDate() != null ? inspectionDetectionInfo.getInspectDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate() : null :null);
esEquipmentInfo.setNEXT_INSPECT_DATE(inspectionDetectionInfo.getSequenceNbr() != null ? inspectionDetectionInfo.getNextInspectDate() != null ? inspectionDetectionInfo.getNextInspectDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate() : null :null);
} catch (Exception e) {
log.error("时区转换失败:{}", record, e);
}
esEquipmentInfo.setIssueDate(getIssueDate(esEquipmentInfo.getUSE_ORG_CODE())); esEquipmentInfo.setIssueDate(getIssueDate(esEquipmentInfo.getUSE_ORG_CODE()));
esEquipmentInfo.setMAINTAIN_UNIT(lastMaintenanceRecordInfo.getMeUnitCreditCode()); esEquipmentInfo.setMAINTAIN_UNIT(lastMaintenanceRecordInfo.getMeUnitCreditCode());
esEquipmentInfo.setMAINTAIN_UNIT_NAME(lastMaintenanceRecordInfo.getMeUnitName()); esEquipmentInfo.setMAINTAIN_UNIT_NAME(lastMaintenanceRecordInfo.getMeUnitName());
...@@ -1552,6 +1548,8 @@ public class DataHandlerServiceImpl { ...@@ -1552,6 +1548,8 @@ public class DataHandlerServiceImpl {
return refreshRecords.size(); return refreshRecords.size();
} }
private List<ESEquipmentInfo.TechParam> buildTechParamByEquList(String record, String equListCode) { private List<ESEquipmentInfo.TechParam> buildTechParamByEquList(String record, String equListCode) {
return StringUtils.isNotEmpty(equListCode) ? statisticsDataUpdateService.getTechParams(equListCode, record) : new ArrayList<>(); return StringUtils.isNotEmpty(equListCode) ? statisticsDataUpdateService.getTechParams(equListCode, record) : new ArrayList<>();
} }
......
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