Commit cd0c4552 authored by tianbo's avatar tianbo

refactor(jg):重构设备问题处理逻辑并优化认领流程

- 提取公共方法 updateOtherTableAndES 到 SafetyProblemTracingServiceImpl - 优化设备记录集合类型从 List 调整为 Set 提高去重效率 - 完善设备认领流程中的异常处理和数据校验 - 添加设备代码和出厂编号的空值过滤逻辑 - 优化气瓶容积计算逻辑,增加数值解析异常处理
parent 231481a2
......@@ -3,20 +3,17 @@ package com.yeejoin.amos.boot.module.jg.biz.handler.strategy;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
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.entity.SafetyProblemTracing;
import com.yeejoin.amos.boot.module.jg.api.enums.SafetyProblemStatusEnum;
import com.yeejoin.amos.boot.module.jg.api.enums.SafetyProblemTypeEnum;
import com.yeejoin.amos.boot.module.jg.biz.service.impl.IdxBizJgOtherInfoServiceImpl;
import com.yeejoin.amos.boot.module.jg.biz.service.impl.SafetyProblemTracingServiceImpl;
import com.yeejoin.amos.boot.module.ymt.api.entity.IdxBizJgOtherInfo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
......@@ -63,40 +60,17 @@ public class EquipmentProblemStrategy implements ProblemHandleStrategy {
.list().stream().map(SafetyProblemTracing::getSourceId).collect(Collectors.toCollection(HashSet::new));
// 确定无未处理问题的设备列表
List<String> resolvedRecords = equipRecords.stream()
Set<String> resolvedRecords = equipRecords.stream()
.filter(record -> !problemEquipIds.contains(record))
.collect(Collectors.toCollection(ArrayList::new));
.collect(Collectors.toCollection(HashSet::new));
// 更新无未处理问题的设备状态
if (!ValidationUtil.isEmpty(resolvedRecords)) {
log.info("可更新状态的设备record:---> {}", resolvedRecords);
updateOtherTableAndES(resolvedRecords);
safetyProblemTracingService.updateOtherTableAndES(resolvedRecords);
}
log.info("安全追溯-设备问题处理完成!");
}
/**
* 更新Other表和ES状态(提取公共方法)
*/
private void updateOtherTableAndES(List<String> records) {
// 更新Other表
idxBizJgOtherInfoService.lambdaUpdate()
.set(IdxBizJgOtherInfo::getStatus, SafetyProblemStatusEnum.HANDLED.getCode())
.in(IdxBizJgOtherInfo::getRecord, records)
.update();
// 更新ES状态(添加异常处理)
try {
Iterable<ESEquipmentCategoryDto> esEquipmentIter = esEquipmentCategory.findAllById(records);
esEquipmentIter.forEach(dto ->
dto.setProblemStatus(SafetyProblemStatusEnum.HANDLED.getCode()));
esEquipmentCategory.saveAll(esEquipmentIter);
log.info("ES状态更新成功,记录数:{}", records.size());
} catch (Exception e) {
log.error("ES状态更新失败,设备record:{},错误原因:{}", records, e.getMessage(), e);
}
}
}
......@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSON;
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.entity.BaseEntity;
import com.yeejoin.amos.boot.module.common.api.dao.ESEquipmentCategory;
import com.yeejoin.amos.boot.module.common.api.dto.ESEquipmentCategoryDto;
......@@ -270,13 +271,7 @@ public class SafetyProblemTracingGenServiceImpl{
correctData.addAll(inspectionSet);
}
idxBizJgOtherInfoService.lambdaUpdate().set(IdxBizJgOtherInfo::getStatus, null)
.in(IdxBizJgOtherInfo::getRecord, correctData).update();
Iterable<ESEquipmentCategoryDto> equipEsDtoIter = esEquipmentCategory.findAllById(correctData);
for (ESEquipmentCategoryDto equipEsDto : equipEsDtoIter) {
equipEsDto.setProblemStatus(null);
}
esEquipmentCategory.saveAll(equipEsDtoIter);
safetyProblemTracingService.updateOtherTableAndES(Sets.newHashSet(correctData));
logger.info("设备维保备案和检验超期数据修正完成,更新数据:{}条", correctData.size());
}
......@@ -304,6 +299,7 @@ public class SafetyProblemTracingGenServiceImpl{
safetyProblemTracingService.lambdaUpdate()
.set(SafetyProblemTracing::getProblemStatusCode, SafetyProblemStatusEnum.HANDLED.getCode())
.set(SafetyProblemTracing::getProblemStatus, SafetyProblemStatusEnum.HANDLED.getName())
.set(SafetyProblemTracing::getRecDate, new Date())
.in(SafetyProblemTracing::getSourceId, outOfMaintenanceEquipIds)
.eq(SafetyProblemTracing::getProblemTypeCode, SafetyProblemTypeEnum.WBCQ.getProblemTypeCode())
.eq(SafetyProblemTracing::getIsDelete,Boolean.FALSE)
......@@ -335,6 +331,7 @@ public class SafetyProblemTracingGenServiceImpl{
safetyProblemTracingService.lambdaUpdate()
.set(SafetyProblemTracing::getProblemStatusCode, SafetyProblemStatusEnum.HANDLED.getCode())
.set(SafetyProblemTracing::getProblemStatus, SafetyProblemStatusEnum.HANDLED.getName())
.set(SafetyProblemTracing::getRecDate, new Date())
.in(SafetyProblemTracing::getSourceId, outOfInspectionEquipIds)
.eq(SafetyProblemTracing::getProblemTypeCode, SafetyProblemTypeEnum.JYCQ.getProblemTypeCode())
.eq(SafetyProblemTracing::getIsDelete,Boolean.FALSE)
......
......@@ -15,6 +15,8 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
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.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;
......@@ -23,6 +25,8 @@ 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.entity.IdxBizJgOtherInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -45,6 +49,7 @@ import static org.springframework.jdbc.object.BatchSqlUpdate.DEFAULT_BATCH_SIZE;
* @date 2024-05-21
*/
@Service
@Slf4j
public class SafetyProblemTracingServiceImpl extends BaseService<SafetyProblemTracingDto, SafetyProblemTracing, SafetyProblemTracingMapper> implements ISafetyProblemTracingService {
@Autowired
......@@ -52,6 +57,12 @@ public class SafetyProblemTracingServiceImpl extends BaseService<SafetyProblemTr
@Autowired
DataDictionaryServiceImpl iDataDictionaryService;
@Autowired
IdxBizJgOtherInfoServiceImpl idxBizJgOtherInfoService;
@Autowired
ESEquipmentCategory esEquipmentCategory;
private static Map<String, String> regionCodeOrgCodeMap = new ConcurrentHashMap<>();
@Autowired
CommonMapper commonMapper;
......@@ -232,4 +243,26 @@ public class SafetyProblemTracingServiceImpl extends BaseService<SafetyProblemTr
public Page<Map<String, Object>> queryUserListProblemById(Page<Map<String, Object>> page, String problemId) {
return this.baseMapper.queryUserListProblemById(page, problemId);
}
/**
* 更新Other表和ES状态(提取公共方法)
*/
public void updateOtherTableAndES(Set<String> records) {
// 更新Other表
idxBizJgOtherInfoService.lambdaUpdate()
.set(IdxBizJgOtherInfo::getStatus, SafetyProblemStatusEnum.HANDLED.getCode())
.in(IdxBizJgOtherInfo::getRecord, records)
.update();
// 更新ES状态(添加异常处理)
try {
Iterable<ESEquipmentCategoryDto> esEquipmentIter = esEquipmentCategory.findAllById(records);
esEquipmentIter.forEach(dto ->
dto.setProblemStatus(SafetyProblemStatusEnum.HANDLED.getCode()));
esEquipmentCategory.saveAll(esEquipmentIter);
log.info("ES状态更新成功,记录数:{}", records.size());
} catch (Exception e) {
log.error("ES状态更新失败,设备record:{},错误原因:{}", records, e.getMessage(), e);
}
}
}
\ No newline at end of file
......@@ -198,12 +198,12 @@ public class ShCarServiceImpl extends BaseService<ShCar, ShCar, ShCarMapper> imp
HashMap<Object, Object> completeDataSanHuanMap = JSON.parseObject(toJSONString(paramMap.get("completeDataSanHuan")), HashMap.class);
// 自己认领
if (isOneSelf) {
records = this.claimOneselfMet(isOneSelf, completeDataSanHuanMap);
records = this.claimOneselfMet(true, completeDataSanHuanMap);
}
// 帮别人认领 + 单位变更登记到自己名下
if (!isOneSelf) {
HashMap<String, Object> gasCylinderChangeMap = JSON.parseObject(toJSONString(paramMap.get("gasCylinderChange")), HashMap.class);
this.claimOthersMet(isOneSelf, completeDataSanHuanMap, gasCylinderChangeMap);
records = this.claimOthersMet(completeDataSanHuanMap, gasCylinderChangeMap);
}
} catch (Exception exception) {
this.handleClaimFailed(records);
......@@ -220,10 +220,10 @@ public class ShCarServiceImpl extends BaseService<ShCar, ShCar, ShCarMapper> imp
* @param gasCylinderChangeMap 车用气瓶单位变更登记表单信息
* @return result
*/
private Boolean claimOthersMet(Boolean isOneSelf, HashMap<?, ?> completeDataSanHuanMap, HashMap<String, Object> gasCylinderChangeMap) {
private List<String> claimOthersMet(HashMap<?, ?> completeDataSanHuanMap, HashMap<String, Object> gasCylinderChangeMap) {
ReginParams reginParams = JSONObject.parseObject(redisUtils.get(RedisKey.buildReginKey(RequestContext.getExeUserId(), RequestContext.getToken())).toString(), ReginParams.class);
// 认领设备及证管理信息完善
List<String> records = this.claimOneselfMet(isOneSelf, completeDataSanHuanMap);
List<String> records = this.claimOneselfMet(false, completeDataSanHuanMap);
// 发起车用气瓶单位变更登记
List<Map<String, Object>> equList = changeVehicleRegistrationUnitService.getBaseMapper().getEquList(records)
.stream()
......@@ -248,7 +248,7 @@ public class ShCarServiceImpl extends BaseService<ShCar, ShCar, ShCarMapper> imp
dictionarieValueModel.setDictDataKey((String) completeDataSanHuanMap.get("useUnitName"));
Systemctl.dictionarieClient.createValue(dictionarieValueModel);
}
return Boolean.TRUE;
return records;
}
/**
......@@ -259,6 +259,7 @@ public class ShCarServiceImpl extends BaseService<ShCar, ShCar, ShCarMapper> imp
* @return 设备record集合
*/
private List<String> claimOneselfMet(Boolean isOneSelf, Map<?, ?> paramMap) {
List<String> records = new ArrayList<>();
// ShCar表的seq
String shCarSequenceNbr = String.valueOf(paramMap.get("sequenceNbr"));
if (ValidationUtil.isEmpty(shCarSequenceNbr)) {
......@@ -279,7 +280,11 @@ public class ShCarServiceImpl extends BaseService<ShCar, ShCar, ShCarMapper> imp
Set<String> equCodeSet = equList.stream().map(equ -> {
JSONObject jsonObject = JSON.parseObject(toJSONString(equ));
return jsonObject.getString("equCode");
}).collect(Collectors.toSet());
}).filter(equCode -> equCode != null && !equCode.trim().isEmpty()) // 过滤掉 null 和空字符串
.collect(Collectors.toSet());
if (equCodeSet.isEmpty()) {
throw new BadRequest("设备代码不能为空!");
}
if (equCodeSet.size() < equList.size())
throw new BadRequest("设备代码重复!");
equCodeSet.forEach(equCode -> {
......@@ -292,7 +297,11 @@ public class ShCarServiceImpl extends BaseService<ShCar, ShCar, ShCarMapper> imp
Set<String> factoryNumSet = equList.stream().map(equ -> {
JSONObject jsonObject = JSON.parseObject(toJSONString(equ));
return jsonObject.getString("factoryNum");
}).collect(Collectors.toSet());
}).filter(factoryNum -> factoryNum != null && !factoryNum.trim().isEmpty()) // 过滤掉 null 和空字符串
.collect(Collectors.toSet());
if (factoryNumSet.isEmpty()) {
throw new BadRequest("出厂编号/产品编号不能为空!");
}
if (factoryNumSet.size() < equList.size())
throw new BadRequest("出厂编号/产品编码重复!");
factoryNumSet.forEach(factoryNum -> {
......@@ -302,13 +311,12 @@ public class ShCarServiceImpl extends BaseService<ShCar, ShCar, ShCarMapper> imp
}
});
try {
// 清除seq,避免后续所有 业务表 都使用此 seq
paramMap.remove("sequenceNbr");
// 1. 生成设备信息 + 保存es
this.claimGenEquInfo(useRegistrationCode, paramMap, equList, reginParams, isOneSelf);
records = this.claimGenEquInfo(useRegistrationCode, paramMap, equList, reginParams, isOneSelf);
// 2. 生成车用气瓶使用登记证单据( JgVehicleInformation JgVehicleInformationEq )信息
JgVehicleInformation jgVehicleInformation = this.claimGenVehicleInfoAbout(paramMap, equList, reginParams, isOneSelf);
......@@ -320,10 +328,12 @@ public class ShCarServiceImpl extends BaseService<ShCar, ShCar, ShCarMapper> imp
ShCar shCar = ShCar.builder().claimedFlag("1").build();
shCar.setSequenceNbr(shCarSequenceNbr);
this.baseMapper.updateById(shCar);
return equList.stream().map(x -> (String) JSON.parseObject(toJSONString(x)).get("record")).collect(Collectors.toList());
return records;
} catch (Exception e) {
log.error("三环系统数据认领失败,使用登记证代码:{}", paramMap.get("useRegistrationCode"));
log.error("失败原因:{}", e.getMessage());
e.printStackTrace();
handleClaimFailed(records);
throw new BadRequest("认领时出现异常,请联系管理员!");
}
}
......@@ -349,8 +359,23 @@ public class ShCarServiceImpl extends BaseService<ShCar, ShCar, ShCarMapper> imp
equType.put("equCategoryCode", "2300");
equType.put("equDefine", "特种气瓶");
equType.put("equDefineCode", "23T0");
BigDecimal totalVolume = equList.stream().map(x -> new BigDecimal(String.valueOf(JSON.parseObject(JSON.toJSONString(x)).get("singleBottleVolume"))))
// 计算总容积
BigDecimal totalVolume = equList.stream()
.map(x -> {
try {
JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(x));
Object volumeObj = jsonObject.get("singleBottleVolume");
if (volumeObj == null || volumeObj.toString().trim().isEmpty()) {
return BigDecimal.ZERO;
}
return new BigDecimal(volumeObj.toString().trim());
} catch (Exception e) {
log.error("解析单个气瓶容积失败,设备信息: {}", x, e);
return BigDecimal.ZERO;
}
})
.reduce(BigDecimal.ZERO, BigDecimal::add);
JgUseRegistrationManage registrationManage = JgUseRegistrationManage.builder()
.equList("压力容器").equListCode("2000")
.equCategory("气瓶").equCategoryCode("2300")
......@@ -414,9 +439,11 @@ public class ShCarServiceImpl extends BaseService<ShCar, ShCar, ShCarMapper> imp
* 认领流程-生成设备信息
*
* @param equList 设备集合
* @return 设备records
*/
public void claimGenEquInfo(String useRegistrationCode, Map<?, ?> paramMap, JSONArray equList, ReginParams reginParams, Boolean isOneSelf) {
public List<String> claimGenEquInfo(String useRegistrationCode, Map<?, ?> paramMap, JSONArray equList, ReginParams reginParams, Boolean isOneSelf) {
CompanyBo company = reginParams.getCompany();
List<String> equRecords = new ArrayList<>();
// 保存设备后 后续业务需要的设备信息
for (int i = 0; i < equList.size(); i++) {
JSONObject equObj = equList.getJSONObject(i);
......@@ -541,9 +568,11 @@ public class ShCarServiceImpl extends BaseService<ShCar, ShCar, ShCarMapper> imp
// 保存es
idxBizJgRegisterInfoService.checkEsData(equRecord);
equRecords.add(equRecord);
// 更新 equList 中的元素
equList.set(i, equJson);
}
return equRecords;
}
/**
......
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