Commit 958e4d48 authored by suhuiguang's avatar suhuiguang

fix(设备创建) :使用登记作废

1.写es移动到最后执行
parent 470ee84f
...@@ -138,14 +138,14 @@ import java.util.function.Function; ...@@ -138,14 +138,14 @@ import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.IntStream; import java.util.stream.IntStream;
import java.util.stream.Stream; import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
import static com.yeejoin.amos.boot.module.common.api.constant.TZSCommonConstant.ES_INDEX_NAME_USE_REGISTRATION_INFO; import static com.yeejoin.amos.boot.module.common.api.constant.TZSCommonConstant.ES_INDEX_NAME_USE_REGISTRATION_INFO;
import static com.yeejoin.amos.boot.module.common.api.entity.EsUseRegistrationInfo.UNDERSCORE_TO_CAMEL; import static com.yeejoin.amos.boot.module.common.api.entity.EsUseRegistrationInfo.UNDERSCORE_TO_CAMEL;
import static com.yeejoin.amos.boot.module.jg.biz.service.impl.CommonServiceImpl.getCompanyType; import static com.yeejoin.amos.boot.module.jg.biz.service.impl.CommonServiceImpl.getCompanyType;
import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.*;
import static java.util.stream.Collectors.toSet;
/** /**
* 服务实现类 * 服务实现类
...@@ -3437,6 +3437,31 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD ...@@ -3437,6 +3437,31 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD
} }
} }
private void processElseDataByStatusSet(String flowStatus, JgUseRegistration jgUseRegistration) {
switch (flowStatus) {
case "使用单位待提交":
// 1.删除暂存时生成的待办
commonServiceImpl.deleteTasksByRelationId(jgUseRegistration.getSequenceNbr() + "");
break;
case "已完成":
// 1.删除与设备的关系,设备可再次发起使用登记
this.clearUseInfoOfEquipSet(jgUseRegistration);
// 2.清空redis(缓存的流程中及已完成使用登记的设备)
this.clearDataForCheckEquipRepeatUsed(jgUseRegistration);
// 3.作废对应的使用登记证
this.invalidUseRegistrationCertificate(jgUseRegistration);
break;
default:
// 流程中
// 1.待办任务更新为已完成
this.finishedTask(jgUseRegistration);
// 2.终止流程-工作流报错暂时注释掉
cmWorkflowService.stopProcess(jgUseRegistration.getInstanceId(), jgUseRegistration.getCancelReason());
// 3.清空redis(缓存的流程中及已完成使用登记的设备)
this.clearDataForCheckEquipRepeatUsed(jgUseRegistration);
}
}
/** /**
* 使用登记单条作废 * 使用登记单条作废
* *
...@@ -3468,31 +3493,45 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD ...@@ -3468,31 +3493,45 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD
if (!ValidationUtil.isEmpty(jgUseRegistration.getProjectContraptionId())) { if (!ValidationUtil.isEmpty(jgUseRegistration.getProjectContraptionId())) {
records = idxBizJgUseInfoService.list(new LambdaQueryWrapper<IdxBizJgUseInfo>().eq(IdxBizJgUseInfo::getProjectContraptionId, jgUseRegistration.getProjectContraptionId()).select(IdxBizJgUseInfo::getRecord)).stream().map(IdxBizJgUseInfo::getRecord).collect(toList()); records = idxBizJgUseInfoService.list(new LambdaQueryWrapper<IdxBizJgUseInfo>().eq(IdxBizJgUseInfo::getProjectContraptionId, jgUseRegistration.getProjectContraptionId()).select(IdxBizJgUseInfo::getRecord)).stream().map(IdxBizJgUseInfo::getRecord).collect(toList());
} }
// 构建设备删除的 DTO 列表 Iterable<ESEquipmentCategoryDto> equipmentCategoryDtosSnapshot = esEquipmentCategory.findAllById(records);
List<ESEquipmentCategoryDto> esDtoList = records.stream().map(v -> { Iterable<ESEquipmentInfo> esEquipmentInfosSnapshot = esEquipmentDao.findAllById(records);
ESEquipmentCategoryDto esDto = new ESEquipmentCategoryDto(); try {
esDto.setSEQUENCE_NBR(v); // 构建设备删除的 DTO 列表
return esDto; List<ESEquipmentCategoryDto> esDtoList = records.stream().map(v -> {
}).collect(Collectors.toList()); ESEquipmentCategoryDto esDto = new ESEquipmentCategoryDto();
//删除涉及的19张表的数据 esDto.setSEQUENCE_NBR(v);
superviseInfoMapper.deleteDataAll(records); return esDto;
//删除es中的数据 }).collect(Collectors.toList());
esEquipmentCategory.deleteAll(esDtoList); //删除涉及的19张表的数据
// 构建设备删除的 新索引的DTO 列表 superviseInfoMapper.deleteDataAll(records);
List<ESEquipmentInfo> esNewDtoList = records.stream().map(v -> { // 构建设备删除的 新索引的DTO 列表
ESEquipmentInfo esDto = new ESEquipmentInfo(); List<ESEquipmentInfo> esNewDtoList = records.stream().map(v -> {
esDto.setSEQUENCE_NBR(v); ESEquipmentInfo esDto = new ESEquipmentInfo();
return esDto; esDto.setSEQUENCE_NBR(v);
}).collect(Collectors.toList()); return esDto;
//删除es新索引中的数据 }).collect(Collectors.toList());
esEquipmentDao.deleteAll(esNewDtoList); //作废使用登记证 & 生成使用登记证的流水
//作废使用登记证 & 生成使用登记证的流水 this.invalidUseRegistrationCertificate(jgUseRegistration);
this.invalidUseRegistrationCertificate(jgUseRegistration); // 单据逻辑删除
// 单据逻辑删除 this.lambdaUpdate().set(JgUseRegistration::getIsDelete, Boolean.TRUE).eq(JgUseRegistration::getSequenceNbr, sequenceNbr).update();
this.lambdaUpdate().set(JgUseRegistration::getIsDelete, Boolean.TRUE).eq(JgUseRegistration::getSequenceNbr, sequenceNbr).update(); // 管道作废工程装置
// 管道作废工程装置 if (!ValidationUtil.isEmpty(jgUseRegistration.getProjectContraptionId())) {
if (!ValidationUtil.isEmpty(jgUseRegistration.getProjectContraptionId())) { idxBizJgProjectContraptionMapper.delete(new LambdaQueryWrapper<IdxBizJgProjectContraption>().eq(IdxBizJgProjectContraption::getSequenceNbr, jgUseRegistration.getProjectContraptionId()));
idxBizJgProjectContraptionMapper.delete(new LambdaQueryWrapper<IdxBizJgProjectContraption>().eq(IdxBizJgProjectContraption::getSequenceNbr, jgUseRegistration.getProjectContraptionId())); }
this.updateById(jgUseRegistration);
//删除es中的数据
esEquipmentCategory.deleteAll(esDtoList);
//删除es新索引中的数据
esEquipmentDao.deleteAll(esNewDtoList);
} catch (Exception e) {
// 报错时回滚
if(equipmentCategoryDtosSnapshot.iterator().hasNext()){
esEquipmentCategory.saveAll(equipmentCategoryDtosSnapshot);
}
if(esEquipmentInfosSnapshot.iterator().hasNext()){
esEquipmentDao.saveAll(esEquipmentInfosSnapshot);
}
throw new RuntimeException(e);
} }
} else { } else {
//判断是否管道 //判断是否管道
...@@ -3514,182 +3553,214 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD ...@@ -3514,182 +3553,214 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD
} }
} }
if (jgUseRegistration.getProjectContraptionId() != null) { if (jgUseRegistration.getProjectContraptionId() != null) {
//2.合并后作废 //2.合并后作废
if (!jgUseRegistration.getOriginProjectContraptionIds().contains(jgUseRegistration.getProjectContraptionId())) { if (!jgUseRegistration.getOriginProjectContraptionIds().contains(jgUseRegistration.getProjectContraptionId())) {
List<String> mergePipelineRecords = eqList.stream()
.filter(v -> jgUseRegistration.getOriginProjectContraptionIds().contains(v.getOriginProjectContraptionId())).map(JgUseRegistrationEq::getEquId).collect(toList());
List<ESEquipmentCategoryDto> equipmentCategoryDtosSnapshot = StreamSupport.stream(esEquipmentCategory.findAllById(mergePipelineRecords).spliterator(), false).collect(toList());
List<ESEquipmentInfo> esEquipmentInfosSnapshot = StreamSupport.stream(esEquipmentDao.findAllById(mergePipelineRecords).spliterator(), false).collect(toList());
Map<String, ESEquipmentCategoryDto> equipmentCategoryDtoMap = equipmentCategoryDtosSnapshot.stream().collect(toMap(ESEquipmentCategoryDto::getSEQUENCE_NBR,e-> BeanUtil.copyProperties(e,ESEquipmentCategoryDto.class)));
Map<String, ESEquipmentInfo> esEquipmentInfoDtoMap = esEquipmentInfosSnapshot.stream().collect(toMap(ESEquipmentInfo::getSEQUENCE_NBR, e-> BeanUtil.copyProperties(e,ESEquipmentInfo.class)));
Boolean isRollBack = useRegisterBackupManager.restore(jgUseRegistration.getSequenceNbr() + ""); Boolean isRollBack = useRegisterBackupManager.restore(jgUseRegistration.getSequenceNbr() + "");
if (isRollBack) { // 进行过编辑逻辑 try {
// 1.还原子工程装置的下的管道信息(装置id) if (isRollBack) { // 进行过编辑逻辑
eqList.stream() // 1.还原子工程装置的下的管道信息(装置id)
.filter(v -> jgUseRegistration.getOriginProjectContraptionIds().contains(v.getOriginProjectContraptionId())) eqList.stream()
.forEach(v -> esEquipmentCategory.findById(v.getEquId()).ifPresent(equInfoEs -> { .filter(v -> jgUseRegistration.getOriginProjectContraptionIds().contains(v.getOriginProjectContraptionId()))
equInfoEs.setProjectContraptionId(v.getOriginProjectContraptionId()); .forEach(v -> {
esEquipmentCategory.save(equInfoEs); LambdaQueryWrapper<IdxBizJgUseInfo> lambda = new QueryWrapper<IdxBizJgUseInfo>().lambda();
lambda.eq(IdxBizJgUseInfo::getRecord, String.valueOf(v.getEquId()));
Optional<ESEquipmentInfo> esEquipmentInfoOp = esEquipmentDao.findById(v.getEquId()); IdxBizJgUseInfo useInfo = useInfoMapper.selectOne(lambda);
if(esEquipmentInfoOp.isPresent()){ useInfo.setProjectContraptionId(v.getOriginProjectContraptionId());
ESEquipmentInfo esEquipmentInfo = esEquipmentInfoOp.get(); useInfoMapper.updateById(useInfo);
esEquipmentInfo.setProjectContraptionId(v.getOriginProjectContraptionId());
esEquipmentDao.save(esEquipmentInfo); IdxBizJgProjectContraption originProjectContraption = jgProjectContraptionService.getById(v.getOriginProjectContraptionId());
}
Optional.ofNullable(equipmentCategoryDtoMap.get(v.getEquId())).ifPresent(p->{
LambdaQueryWrapper<IdxBizJgUseInfo> lambda = new QueryWrapper<IdxBizJgUseInfo>().lambda(); p.setProjectContraptionId(String.valueOf(originProjectContraption.getSequenceNbr()));
lambda.eq(IdxBizJgUseInfo::getRecord, String.valueOf(v.getEquId())); p.setPROJECT_CONTRAPTION(originProjectContraption.getProjectContraption());
IdxBizJgUseInfo useInfo = useInfoMapper.selectOne(lambda); p.setOrgBranchCode(originProjectContraption.getOrgCode());
useInfo.setProjectContraptionId(v.getOriginProjectContraptionId()); p.setORG_BRANCH_NAME(originProjectContraption.getOrgName());
useInfoMapper.updateById(useInfo); });
Optional.ofNullable(esEquipmentInfoDtoMap.get(v.getEquId())).ifPresent(p->{
IdxBizJgProjectContraption originProjectContraption = jgProjectContraptionService.getById(v.getOriginProjectContraptionId()); p.setProjectContraptionId(String.valueOf(originProjectContraption.getSequenceNbr()));
//还原 原工程装置下equCode和监管码 p.setPROJECT_CONTRAPTION(originProjectContraption.getProjectContraption());
LambdaUpdateWrapper<IdxBizJgRegisterInfo> updateWrapper = new UpdateWrapper<IdxBizJgRegisterInfo>().lambda() p.setORG_BRANCH_CODE(originProjectContraption.getOrgCode());
.eq(IdxBizJgRegisterInfo::getRecord, v.getEquId()); p.setORG_BRANCH_NAME(originProjectContraption.getOrgName());
updateWrapper.set(IdxBizJgRegisterInfo::getEquCode, originProjectContraption.getEquCode()); });
updateWrapper.set(IdxBizJgRegisterInfo::getUseOrgCode, null); //还原 原工程装置下equCode和监管码
idxBizJgRegisterInfoMapper.update(null, updateWrapper); LambdaUpdateWrapper<IdxBizJgRegisterInfo> updateWrapper = new UpdateWrapper<IdxBizJgRegisterInfo>().lambda()
.eq(IdxBizJgRegisterInfo::getRecord, v.getEquId());
LambdaUpdateWrapper<IdxBizJgOtherInfo> otherInfoLambdaUpdateWrapper = new UpdateWrapper<IdxBizJgOtherInfo>().lambda() updateWrapper.set(IdxBizJgRegisterInfo::getEquCode, originProjectContraption.getEquCode());
.eq(IdxBizJgOtherInfo::getRecord, v.getEquId()); updateWrapper.set(IdxBizJgRegisterInfo::getUseOrgCode, null);
IdxBizJgOtherInfo idxBizJgOtherInfo = new IdxBizJgOtherInfo(); idxBizJgRegisterInfoMapper.update(null, updateWrapper);
idxBizJgOtherInfo.setSupervisoryCode(originProjectContraption.getSupervisoryCode());
otherInfoMapper.update(idxBizJgOtherInfo, otherInfoLambdaUpdateWrapper); LambdaUpdateWrapper<IdxBizJgOtherInfo> otherInfoLambdaUpdateWrapper = new UpdateWrapper<IdxBizJgOtherInfo>().lambda()
})); .eq(IdxBizJgOtherInfo::getRecord, v.getEquId());
// 2.根据工程装置ID查询工程装置父级,重置子工程装置父级为空 IdxBizJgOtherInfo idxBizJgOtherInfo = new IdxBizJgOtherInfo();
jgProjectContraptionService.update( idxBizJgOtherInfo.setSupervisoryCode(originProjectContraption.getSupervisoryCode());
new LambdaUpdateWrapper<IdxBizJgProjectContraption>() otherInfoMapper.update(idxBizJgOtherInfo, otherInfoLambdaUpdateWrapper);
.in(BaseEntity::getSequenceNbr, Arrays.asList(jgUseRegistration.getOriginProjectContraptionIds().split(","))) });
.set(IdxBizJgProjectContraption::getProjectContraptionParentId, null) // 2.根据工程装置ID查询工程装置父级,重置子工程装置父级为空
); jgProjectContraptionService.update(
// 3.原装置、新装置重新计算管道长度 new LambdaUpdateWrapper<IdxBizJgProjectContraption>()
this.updateTotalPieLineLength(jgUseRegistration.getOriginProjectContraptionIds(), jgUseRegistration.getProjectContraptionId()); .in(BaseEntity::getSequenceNbr, Arrays.asList(jgUseRegistration.getOriginProjectContraptionIds().split(",")))
// 4.父工程装置按照是否为有证装置进行更新 .set(IdxBizJgProjectContraption::getProjectContraptionParentId, null)
JgRegistrationHistory history = jgRegistrationHistoryService.queryLatestRegistrationHistory(Long.valueOf(jgUseRegistration.getProjectContraptionId())); );
if (history != null && history.getChangeData() != null) { // 3.原装置、新装置重新计算管道长度
JSONObject hisJson = JSON.parseObject(history.getChangeData()); this.updateTotalPieLineLength(jgUseRegistration.getOriginProjectContraptionIds(), jgUseRegistration.getProjectContraptionId());
boolean isFirstMerge = Optional.ofNullable(hisJson.get("isFirstMerge")) // 4.父工程装置按照是否为有证装置进行更新
.map(Boolean.class::cast) JgRegistrationHistory history = jgRegistrationHistoryService.queryLatestRegistrationHistory(Long.valueOf(jgUseRegistration.getProjectContraptionId()));
.orElse(false); if (history != null && history.getChangeData() != null) {
//合并到无证总工程 JSONObject hisJson = JSON.parseObject(history.getChangeData());
IdxBizJgProjectContraption projectContraption = jgProjectContraptionService.getById(jgUseRegistration.getProjectContraptionId()); boolean isFirstMerge = Optional.ofNullable(hisJson.get("isFirstMerge"))
if (isFirstMerge) { .map(Boolean.class::cast)
projectContraption.setIsIntoManagement(false); .orElse(false);
projectContraption.setIsFirstMerge(true); //合并到无证总工程
projectContraption.setSupervisoryCode(null); IdxBizJgProjectContraption projectContraption = jgProjectContraptionService.getById(jgUseRegistration.getProjectContraptionId());
projectContraption.setEquCode(null); if (isFirstMerge) {
projectContraption.setUseRegistrationCode(null); projectContraption.setIsIntoManagement(false);
projectContraption.setPipelineLength(0.0); projectContraption.setIsFirstMerge(true);
// 处理非批量导入数据,更新关联业务状态 projectContraption.setSupervisoryCode(null);
processElseDataByStatus(oldStatus, jgUseRegistration); projectContraption.setEquCode(null);
// 统一处理设备的纳管状态【注册事务提交后的操作】 projectContraption.setUseRegistrationCode(null);
Set<String> pIds = new HashSet<>(); projectContraption.setPipelineLength(0.0);
pIds.add(jgUseRegistration.getProjectContraptionId()); // 处理非批量导入数据,更新关联业务状态
pIds.addAll(Arrays.asList(jgUseRegistration.getOriginProjectContraptionIds().split(","))); processElseDataByStatus(oldStatus, jgUseRegistration);
registerAfterCommitTask(records, pIds); // 统一处理设备的纳管状态【注册事务提交后的操作】
} else { Set<String> pIds = new HashSet<>();
// 查询原工程装置及 useInfo 记录 pIds.add(jgUseRegistration.getProjectContraptionId());
List<String> originProjectContraptionIds = Arrays.asList(jgUseRegistration.getOriginProjectContraptionIds().split(",")); pIds.addAll(Arrays.asList(jgUseRegistration.getOriginProjectContraptionIds().split(",")));
records = idxBizJgUseInfoService.lambdaQuery() registerAfterCommitTask(records, pIds);
.select(IdxBizJgUseInfo::getRecord) } else {
.in(IdxBizJgUseInfo::getProjectContraptionId, originProjectContraptionIds) // 查询原工程装置及 useInfo 记录
.list() List<String> originProjectContraptionIds = Arrays.asList(jgUseRegistration.getOriginProjectContraptionIds().split(","));
.stream() records = idxBizJgUseInfoService.lambdaQuery()
.map(IdxBizJgUseInfo::getRecord) .select(IdxBizJgUseInfo::getRecord)
.collect(Collectors.toList()); .in(IdxBizJgUseInfo::getProjectContraptionId, originProjectContraptionIds)
Set<String> pIds = new HashSet<>(); .list()
pIds.add(jgUseRegistration.getProjectContraptionId()); .stream()
pIds.addAll(Arrays.asList(jgUseRegistration.getOriginProjectContraptionIds().split(","))); .map(IdxBizJgUseInfo::getRecord)
processElseDataByStatus(oldStatus, jgUseRegistration); .collect(Collectors.toList());
// 统一处理设备的纳管状态 Set<String> pIds = new HashSet<>();
registerAfterCommitTask(records, pIds); pIds.add(jgUseRegistration.getProjectContraptionId());
pIds.addAll(Arrays.asList(jgUseRegistration.getOriginProjectContraptionIds().split(",")));
processElseDataByStatus(oldStatus, jgUseRegistration);
// 统一处理设备的纳管状态
registerAfterCommitTask(records, pIds);
}
jgProjectContraptionService.updateById(projectContraption);
} }
jgProjectContraptionService.updateById(projectContraption); } else { // 未进行过编辑逻辑,走原来逻辑
} eqList.stream()
} else { // 未进行过编辑逻辑,走原来逻辑 .filter(v -> jgUseRegistration.getOriginProjectContraptionIds().contains(v.getOriginProjectContraptionId()))
eqList.stream() .forEach(v -> {
.filter(v -> jgUseRegistration.getOriginProjectContraptionIds().contains(v.getOriginProjectContraptionId())) LambdaQueryWrapper<IdxBizJgUseInfo> lambda = new QueryWrapper<IdxBizJgUseInfo>().lambda();
.forEach(v -> esEquipmentCategory.findById(v.getEquId()).ifPresent(equInfoEs -> { lambda.eq(IdxBizJgUseInfo::getRecord, String.valueOf(v.getEquId()));
equInfoEs.setProjectContraptionId(v.getOriginProjectContraptionId()); IdxBizJgUseInfo useInfo = useInfoMapper.selectOne(lambda);
esEquipmentCategory.save(equInfoEs); useInfo.setProjectContraptionId(v.getOriginProjectContraptionId());
useInfoMapper.updateById(useInfo);
LambdaQueryWrapper<IdxBizJgUseInfo> lambda = new QueryWrapper<IdxBizJgUseInfo>().lambda();
lambda.eq(IdxBizJgUseInfo::getRecord, String.valueOf(v.getEquId())); IdxBizJgProjectContraption originProjectContraption = jgProjectContraptionService.getById(v.getOriginProjectContraptionId());
IdxBizJgUseInfo useInfo = useInfoMapper.selectOne(lambda); Optional.ofNullable(equipmentCategoryDtoMap.get(v.getEquId())).ifPresent(p->{
useInfo.setProjectContraptionId(v.getOriginProjectContraptionId()); p.setProjectContraptionId(String.valueOf(originProjectContraption.getSequenceNbr()));
useInfoMapper.updateById(useInfo); p.setPROJECT_CONTRAPTION(originProjectContraption.getProjectContraption());
p.setOrgBranchCode(originProjectContraption.getOrgCode());
IdxBizJgProjectContraption originProjectContraption = jgProjectContraptionService.getById(v.getOriginProjectContraptionId()); p.setORG_BRANCH_NAME(originProjectContraption.getOrgName());
//还原 原工程装置下equCode和监管码 });
LambdaUpdateWrapper<IdxBizJgRegisterInfo> updateWrapper = new UpdateWrapper<IdxBizJgRegisterInfo>().lambda() Optional.ofNullable(esEquipmentInfoDtoMap.get(v.getEquId())).ifPresent(p->{
.eq(IdxBizJgRegisterInfo::getRecord, v.getEquId()); p.setProjectContraptionId(String.valueOf(originProjectContraption.getSequenceNbr()));
IdxBizJgRegisterInfo idxBizJgRegisterInfo = new IdxBizJgRegisterInfo(); p.setPROJECT_CONTRAPTION(originProjectContraption.getProjectContraption());
idxBizJgRegisterInfo.setEquCode(originProjectContraption.getEquCode()); p.setORG_BRANCH_CODE(originProjectContraption.getOrgCode());
idxBizJgRegisterInfoMapper.update(idxBizJgRegisterInfo, updateWrapper); p.setORG_BRANCH_NAME(originProjectContraption.getOrgName());
});
LambdaUpdateWrapper<IdxBizJgOtherInfo> otherInfoLambdaUpdateWrapper = new UpdateWrapper<IdxBizJgOtherInfo>().lambda() //还原 原工程装置下equCode和监管码
.eq(IdxBizJgOtherInfo::getRecord, v.getEquId()); LambdaUpdateWrapper<IdxBizJgRegisterInfo> updateWrapper = new UpdateWrapper<IdxBizJgRegisterInfo>().lambda()
IdxBizJgOtherInfo idxBizJgOtherInfo = new IdxBizJgOtherInfo(); .eq(IdxBizJgRegisterInfo::getRecord, v.getEquId());
idxBizJgOtherInfo.setSupervisoryCode(originProjectContraption.getSupervisoryCode()); IdxBizJgRegisterInfo idxBizJgRegisterInfo = new IdxBizJgRegisterInfo();
otherInfoMapper.update(idxBizJgOtherInfo, otherInfoLambdaUpdateWrapper); idxBizJgRegisterInfo.setEquCode(originProjectContraption.getEquCode());
})); idxBizJgRegisterInfoMapper.update(idxBizJgRegisterInfo, updateWrapper);
//2.根据工程装置ID查询工程装置父级,重置子工程装置父级为空
jgProjectContraptionService.update( LambdaUpdateWrapper<IdxBizJgOtherInfo> otherInfoLambdaUpdateWrapper = new UpdateWrapper<IdxBizJgOtherInfo>().lambda()
new LambdaUpdateWrapper<IdxBizJgProjectContraption>() .eq(IdxBizJgOtherInfo::getRecord, v.getEquId());
.in(BaseEntity::getSequenceNbr, Arrays.asList(jgUseRegistration.getOriginProjectContraptionIds().split(","))) IdxBizJgOtherInfo idxBizJgOtherInfo = new IdxBizJgOtherInfo();
.set(IdxBizJgProjectContraption::getProjectContraptionParentId, null) idxBizJgOtherInfo.setSupervisoryCode(originProjectContraption.getSupervisoryCode());
); otherInfoMapper.update(idxBizJgOtherInfo, otherInfoLambdaUpdateWrapper);
JgRegistrationHistory history = jgRegistrationHistoryService.queryLatestRegistrationHistory(Long.valueOf(jgUseRegistration.getProjectContraptionId())); });
if (history != null && history.getChangeData() != null) { //2.根据工程装置ID查询工程装置父级,重置子工程装置父级为空
JSONObject hisJson = JSON.parseObject(history.getChangeData()); jgProjectContraptionService.update(
boolean isFirstMerge = Optional.ofNullable(hisJson.get("isFirstMerge")) new LambdaUpdateWrapper<IdxBizJgProjectContraption>()
.map(Boolean.class::cast) .in(BaseEntity::getSequenceNbr, Arrays.asList(jgUseRegistration.getOriginProjectContraptionIds().split(",")))
.orElse(false); .set(IdxBizJgProjectContraption::getProjectContraptionParentId, null)
//合并到无证总工程 );
IdxBizJgProjectContraption projectContraption = jgProjectContraptionService.getById(jgUseRegistration.getProjectContraptionId()); JgRegistrationHistory history = jgRegistrationHistoryService.queryLatestRegistrationHistory(Long.valueOf(jgUseRegistration.getProjectContraptionId()));
if (isFirstMerge) { if (history != null && history.getChangeData() != null) {
projectContraption.setIsIntoManagement(false); JSONObject hisJson = JSON.parseObject(history.getChangeData());
projectContraption.setIsFirstMerge(true); boolean isFirstMerge = Optional.ofNullable(hisJson.get("isFirstMerge"))
projectContraption.setSupervisoryCode(null); .map(Boolean.class::cast)
projectContraption.setEquCode(null); .orElse(false);
projectContraption.setUseRegistrationCode(null); //合并到无证总工程
projectContraption.setPipelineLength(0.0); IdxBizJgProjectContraption projectContraption = jgProjectContraptionService.getById(jgUseRegistration.getProjectContraptionId());
// 处理非批量导入数据,更新关联业务状态 if (isFirstMerge) {
processElseDataByStatus(oldStatus, jgUseRegistration); projectContraption.setIsIntoManagement(false);
// 统一处理设备的纳管状态【注册事务提交后的操作】 projectContraption.setIsFirstMerge(true);
Set<String> pIds = new HashSet<>(); projectContraption.setSupervisoryCode(null);
pIds.add(jgUseRegistration.getProjectContraptionId()); projectContraption.setEquCode(null);
pIds.addAll(Arrays.asList(jgUseRegistration.getOriginProjectContraptionIds().split(","))); projectContraption.setUseRegistrationCode(null);
registerAfterCommitTask(records, pIds); projectContraption.setPipelineLength(0.0);
} else { // 处理非批量导入数据,更新关联业务状态
// 查询原工程装置及 useInfo 记录 processElseDataByStatus(oldStatus, jgUseRegistration);
List<String> originProjectContraptionIds = Arrays.asList(jgUseRegistration.getOriginProjectContraptionIds().split(",")); // 统一处理设备的纳管状态【注册事务提交后的操作】
List<IdxBizJgProjectContraption> originProjectContraptionList = jgProjectContraptionService.lambdaQuery() Set<String> pIds = new HashSet<>();
.in(BaseEntity::getSequenceNbr, originProjectContraptionIds) pIds.add(jgUseRegistration.getProjectContraptionId());
.list(); pIds.addAll(Arrays.asList(jgUseRegistration.getOriginProjectContraptionIds().split(",")));
registerAfterCommitTask(records, pIds);
records = idxBizJgUseInfoService.lambdaQuery() } else {
.select(IdxBizJgUseInfo::getRecord) // 查询原工程装置及 useInfo 记录
.in(IdxBizJgUseInfo::getProjectContraptionId, originProjectContraptionIds) List<String> originProjectContraptionIds = Arrays.asList(jgUseRegistration.getOriginProjectContraptionIds().split(","));
.list() List<IdxBizJgProjectContraption> originProjectContraptionList = jgProjectContraptionService.lambdaQuery()
.stream() .in(BaseEntity::getSequenceNbr, originProjectContraptionIds)
.map(IdxBizJgUseInfo::getRecord) .list();
.collect(Collectors.toList());
records = idxBizJgUseInfoService.lambdaQuery()
// 统一处理设备的纳管状态 .select(IdxBizJgUseInfo::getRecord)
Set<String> pIds = new HashSet<>(); .in(IdxBizJgUseInfo::getProjectContraptionId, originProjectContraptionIds)
pIds.add(jgUseRegistration.getProjectContraptionId()); .list()
pIds.addAll(Arrays.asList(jgUseRegistration.getOriginProjectContraptionIds().split(","))); .stream()
registerAfterCommitTask(records, pIds); .map(IdxBizJgUseInfo::getRecord)
processElseDataByStatus(oldStatus, jgUseRegistration); .collect(Collectors.toList());
if (FlowStatusEnum.TO_BE_FINISHED.getName().equals(oldStatus)) {
// 计算管道长度并更新 // 统一处理设备的纳管状态
double originPipelineLength = originProjectContraptionList.stream() Set<String> pIds = new HashSet<>();
.map(IdxBizJgProjectContraption::getPipelineLength) pIds.add(jgUseRegistration.getProjectContraptionId());
.filter(Objects::nonNull) pIds.addAll(Arrays.asList(jgUseRegistration.getOriginProjectContraptionIds().split(",")));
.mapToDouble(Double::doubleValue) registerAfterCommitTask(records, pIds);
.sum(); processElseDataByStatus(oldStatus, jgUseRegistration);
projectContraption.setPipelineLength(projectContraption.getPipelineLength() - originPipelineLength); if (FlowStatusEnum.TO_BE_FINISHED.getName().equals(oldStatus)) {
// 计算管道长度并更新
double originPipelineLength = originProjectContraptionList.stream()
.map(IdxBizJgProjectContraption::getPipelineLength)
.filter(Objects::nonNull)
.mapToDouble(Double::doubleValue)
.sum();
projectContraption.setPipelineLength(projectContraption.getPipelineLength() - originPipelineLength);
}
} }
jgProjectContraptionService.updateById(projectContraption);
} }
jgProjectContraptionService.updateById(projectContraption);
} }
this.updateById(jgUseRegistration);
esEquipmentCategory.saveAll(equipmentCategoryDtoMap.values());
esEquipmentDao.saveAll(esEquipmentInfoDtoMap.values());
} catch (Exception e) {
if(!equipmentCategoryDtosSnapshot.isEmpty()){
esEquipmentCategory.saveAll(equipmentCategoryDtosSnapshot);
}
if(!esEquipmentInfosSnapshot.isEmpty()){
esEquipmentDao.saveAll(esEquipmentInfosSnapshot);
}
throw new RuntimeException(e);
} }
} }
//1.子工程装置作废,正常逻辑 //1.子工程装置作废,正常逻辑
...@@ -3704,25 +3775,81 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD ...@@ -3704,25 +3775,81 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD
this.rollBackForPieLine(jgUseRegistration); this.rollBackForPieLine(jgUseRegistration);
processElseDataByStatus(oldStatus, jgUseRegistration); processElseDataByStatus(oldStatus, jgUseRegistration);
registerAfterCommitTask(records, Sets.newHashSet(jgUseRegistration.getProjectContraptionId())); registerAfterCommitTask(records, Sets.newHashSet(jgUseRegistration.getProjectContraptionId()));
this.updateById(jgUseRegistration);
} }
} }
//气瓶 //气瓶
else { else {
// 处理非批量导入数据,更新关联业务状态 Iterable<ESEquipmentCategoryDto> equipmentCategoryDtosSnapshot = esEquipmentCategory.findAllById(records);
processElseDataByStatus(oldStatus, jgUseRegistration); Iterable<ESEquipmentInfo> esEquipmentInfosSnapshot = esEquipmentDao.findAllById(records);
// 统一处理设备的纳管状态【注册事务提交后的操作】 try {
registerAfterCommitTask(records); this.updateById(jgUseRegistration);
// 处理非批量导入数据,更新关联业务状态
processElseDataByStatusSet(oldStatus, jgUseRegistration);
// es数据处理 提出来便于进行异常回调
if (FlowStatusEnum.TO_BE_FINISHED.getName().equals(oldStatus)) {
List<ESEquipmentCategoryDto> equipmentCategoryDtos = new ArrayList<>();
List<ESEquipmentInfo> esEquipmentInfos = new ArrayList<>();
buildEsInfoForRollBack(records, jgUseRegistration, equipmentCategoryDtos, esEquipmentInfos);
if (!equipmentCategoryDtos.isEmpty()) {
esEquipmentCategory.saveAll(equipmentCategoryDtos);
}
if (!esEquipmentInfos.isEmpty()) {
esEquipmentDao.saveAll(esEquipmentInfos);
}
}
// 统一处理设备的纳管状态【注册事务提交后的操作】
registerAfterCommitTask(records);
}catch (Exception e) {
// 报错时按照快照数据恢复
if(oldStatus.equals(FlowStatusEnum.TO_BE_FINISHED.getName())) {
if(equipmentCategoryDtosSnapshot.iterator().hasNext()){
esEquipmentCategory.saveAll(equipmentCategoryDtosSnapshot);
}
if(esEquipmentInfosSnapshot.iterator().hasNext()){
esEquipmentDao.saveAll(esEquipmentInfosSnapshot);
}
}
throw new RuntimeException(e);
}
} }
} }
} }
//台套办理 //台套办理
else { else {
// 处理非批量导入数据,更新关联业务状态 Iterable<ESEquipmentCategoryDto> equipmentCategoryDtosSnapshot = esEquipmentCategory.findAllById(records);
processElseDataByStatus(oldStatus, jgUseRegistration); Iterable<ESEquipmentInfo> esEquipmentInfosSnapshot = esEquipmentDao.findAllById(records);
// 统一处理设备的纳管状态【注册事务提交后的操作】 try {
registerAfterCommitTask(records); this.updateById(jgUseRegistration);
// 处理非批量导入数据,更新关联业务状态
processElseDataByStatusSet(oldStatus, jgUseRegistration);
// es数据处理 提出来便于进行异常回调
if(FlowStatusEnum.TO_BE_FINISHED.getName().equals(oldStatus)) {
List<ESEquipmentCategoryDto> equipmentCategoryDtos = new ArrayList<>();
List<ESEquipmentInfo> esEquipmentInfos = new ArrayList<>();
buildEsInfoForRollBack(records, jgUseRegistration, equipmentCategoryDtos, esEquipmentInfos);
if(!equipmentCategoryDtos.isEmpty()){
esEquipmentCategory.saveAll(equipmentCategoryDtos);
}
if(!esEquipmentInfos.isEmpty()){
esEquipmentDao.saveAll(esEquipmentInfos);
}
}
// 统一处理设备的纳管状态【注册事务提交后的操作】
registerAfterCommitTask(records);
} catch (Exception e) {
// 报错时按照快照数据恢复
if(oldStatus.equals(FlowStatusEnum.TO_BE_FINISHED.getName())) {
if(equipmentCategoryDtosSnapshot.iterator().hasNext()){
esEquipmentCategory.saveAll(equipmentCategoryDtosSnapshot);
}
if(equipmentCategoryDtosSnapshot.iterator().hasNext()){
esEquipmentDao.saveAll(esEquipmentInfosSnapshot);
}
}
throw new RuntimeException(e);
}
} }
this.updateById(jgUseRegistration);
return jgUseRegistration; return jgUseRegistration;
} }
...@@ -3783,14 +3910,6 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD ...@@ -3783,14 +3910,6 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD
Boolean flag = Boolean.FALSE; Boolean flag = Boolean.FALSE;
LambdaQueryWrapper<IdxBizJgRegisterInfo> lambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<IdxBizJgRegisterInfo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(IdxBizJgRegisterInfo::getRecord, record); lambdaQueryWrapper.eq(IdxBizJgRegisterInfo::getRecord, record);
IdxBizJgRegisterInfo idxBizJgRegisterInfo = idxBizJgRegisterInfoMapper.selectOne(lambdaQueryWrapper);
if (!ObjectUtils.isEmpty(idxBizJgRegisterInfo)) {
String equCategory = idxBizJgRegisterInfo.getEquCategory();
List<String> codes = UseRegisterCancelEquipEnum.getCodes();
if (codes.contains(equCategory)) {
flag = Boolean.TRUE;
}
}
// 1.使用信息表部分字段赋空 // 1.使用信息表部分字段赋空
this.rollBackUseInfo(record, flag); this.rollBackUseInfo(record, flag);
// 2.回滚更新idx_biz_jg_register_info表 // 2.回滚更新idx_biz_jg_register_info表
...@@ -3812,6 +3931,31 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD ...@@ -3812,6 +3931,31 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD
} }
} }
private void clearUseInfoOfEquipSet(JgUseRegistration jgUseRegistration) {
List<JgUseRegistrationEq> eqList = getJgUseRegistrationEqs(jgUseRegistration);
eqList.forEach(e -> {
String record = e.getEquId();
Boolean flag = Boolean.FALSE;
LambdaQueryWrapper<IdxBizJgRegisterInfo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(IdxBizJgRegisterInfo::getRecord, record);
// 1.使用信息表部分字段赋空
this.rollBackUseInfo(record, flag);
// 2.回滚更新idx_biz_jg_register_info表
this.rollBackRegisterInfo(record, jgUseRegistration);
// 3.回滚更新idx_biz_jg_supervision_info表
this.rollBackSupervisionInfo(record);
// 4.历史设备处理
this.dealHisRegEquipData(jgUseRegistration, record);
});
Set<String> equipTransferIds = eqList.stream()
.map(JgUseRegistrationEq::getEquipTransferId)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
if (!equipTransferIds.isEmpty()) {
jgResumeInfoService.deleteBatchByBusinessId(equipTransferIds);
}
}
private void rollBackForPieLine(JgUseRegistration jgUseRegistration) { private void rollBackForPieLine(JgUseRegistration jgUseRegistration) {
if (!StringUtils.isEmpty(jgUseRegistration.getProjectContraptionId())) { if (!StringUtils.isEmpty(jgUseRegistration.getProjectContraptionId())) {
// 清除使用登记证编号 // 清除使用登记证编号
...@@ -3893,6 +4037,71 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD ...@@ -3893,6 +4037,71 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD
return jgRelationEquipMapper.selectList(eqLambdaQueryWrapper); return jgRelationEquipMapper.selectList(eqLambdaQueryWrapper);
} }
private void buildEsInfoForRollBack(List<String> records, JgUseRegistration jgUseRegistration, List<ESEquipmentCategoryDto> equipmentCategoryDtos, List<ESEquipmentInfo> esEquipmentInfos) {
for (String record: records){
LambdaQueryWrapper<IdxBizJgConstructionInfo> wrapper = new LambdaQueryWrapper<>();
wrapper.select(IdxBizJgConstructionInfo::getUscUnitCreditCode,
IdxBizJgConstructionInfo::getUscUnitName,
IdxBizJgConstructionInfo::getInformCode,
IdxBizJgConstructionInfo::getInformFilePath)
.eq(IdxBizJgConstructionInfo::getRecord, record)
.orderByDesc(TzsBaseEntity::getRecDate)
.last("limit 1");
IdxBizJgConstructionInfo jgConstructionInfo = constructionInfoMapper.selectOne(wrapper);
IdxBizJgOtherInfo otherInfo = otherInfoMapper.selectOne(
new LambdaQueryWrapper<IdxBizJgOtherInfo>()
.eq(IdxBizJgOtherInfo::getRecord, record)
.select(IdxBizJgOtherInfo::getSupervisoryCode, IdxBizJgOtherInfo::getCode96333Type));
Optional<ESEquipmentCategoryDto> optional = esEquipmentCategory.findById(record);
Optional<ESEquipmentInfo> esEquipmentDaoOptional = esEquipmentDao.findById(record);
if (optional.isPresent()) {
ESEquipmentCategoryDto esEquipmentCategoryDto = optional.get();
// 非历史有证设备,作废清除使用登记证编号
if (!"1".equals(jgUseRegistration.getRegType())) {
esEquipmentCategoryDto.setUSE_ORG_CODE(null);
}
// 历史有证设备、历史无证设备,系统生成的96333清空
if (("1".equals(jgUseRegistration.getRegType()) || "2".equals(jgUseRegistration.getRegType())) && "2".equals(otherInfo.getCode96333Type())) {
esEquipmentCategoryDto.setCODE96333(null);
}
esEquipmentCategoryDto.setUSE_ORG_CODE(null);
//esEquipmentCategoryDto.setSTATUS(null);
esEquipmentCategoryDto.setEQU_STATE(null);
esEquipmentCategoryDto.setOrgBranchCode(null);
esEquipmentCategoryDto.setORG_BRANCH_NAME(null);
if (jgConstructionInfo != null) {
esEquipmentCategoryDto.setUSC_UNIT_NAME(jgConstructionInfo.getUscUnitName());
esEquipmentCategoryDto.setUSC_UNIT_CREDIT_CODE(jgConstructionInfo.getUscUnitCreditCode());
}
equipmentCategoryDtos.add(esEquipmentCategoryDto);
}
if (esEquipmentDaoOptional.isPresent()) {
ESEquipmentInfo esEquipmentInfo = esEquipmentDaoOptional.get();
// 非历史有证设备,作废清除使用登记证编号
if (!"1".equals(jgUseRegistration.getRegType())) {
esEquipmentInfo.setUSE_ORG_CODE(null);
}
// 历史有证设备、历史无证设备,系统生成的96333清空
if (("1".equals(jgUseRegistration.getRegType()) || "2".equals(jgUseRegistration.getRegType())) && "2".equals(otherInfo.getCode96333Type())) {
esEquipmentInfo.setCODE96333(null);
}
esEquipmentInfo.setUSE_ORG_CODE(null);
//esEquipmentCategoryDto.setSTATUS(null);
esEquipmentInfo.setEQU_STATE(null);
esEquipmentInfo.setORG_BRANCH_CODE(null);
esEquipmentInfo.setORG_BRANCH_NAME(null);
if (jgConstructionInfo != null) {
esEquipmentInfo.setUSC_UNIT_NAME(jgConstructionInfo.getUscUnitName());
esEquipmentInfo.setUSC_UNIT_CREDIT_CODE(jgConstructionInfo.getUscUnitCreditCode());
}
esEquipmentInfos.add(esEquipmentInfo);
}
}
}
private void rollBackForEquipEsInfo(String record, Boolean flag, JgUseRegistration jgUseRegistration) { private void rollBackForEquipEsInfo(String record, Boolean flag, JgUseRegistration jgUseRegistration) {
LambdaQueryWrapper<IdxBizJgConstructionInfo> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<IdxBizJgConstructionInfo> wrapper = new LambdaQueryWrapper<>();
wrapper.select(IdxBizJgConstructionInfo::getUscUnitCreditCode, wrapper.select(IdxBizJgConstructionInfo::getUscUnitCreditCode,
......
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