Commit 958e4d48 authored by suhuiguang's avatar suhuiguang

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

1.写es移动到最后执行
parent 470ee84f
......@@ -138,14 +138,14 @@ import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import java.util.zip.ZipEntry;
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.entity.EsUseRegistrationInfo.UNDERSCORE_TO_CAMEL;
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.toSet;
import static java.util.stream.Collectors.*;
/**
* 服务实现类
......@@ -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
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());
}
// 构建设备删除的 DTO 列表
List<ESEquipmentCategoryDto> esDtoList = records.stream().map(v -> {
ESEquipmentCategoryDto esDto = new ESEquipmentCategoryDto();
esDto.setSEQUENCE_NBR(v);
return esDto;
}).collect(Collectors.toList());
//删除涉及的19张表的数据
superviseInfoMapper.deleteDataAll(records);
//删除es中的数据
esEquipmentCategory.deleteAll(esDtoList);
// 构建设备删除的 新索引的DTO 列表
List<ESEquipmentInfo> esNewDtoList = records.stream().map(v -> {
ESEquipmentInfo esDto = new ESEquipmentInfo();
esDto.setSEQUENCE_NBR(v);
return esDto;
}).collect(Collectors.toList());
//删除es新索引中的数据
esEquipmentDao.deleteAll(esNewDtoList);
//作废使用登记证 & 生成使用登记证的流水
this.invalidUseRegistrationCertificate(jgUseRegistration);
// 单据逻辑删除
this.lambdaUpdate().set(JgUseRegistration::getIsDelete, Boolean.TRUE).eq(JgUseRegistration::getSequenceNbr, sequenceNbr).update();
// 管道作废工程装置
if (!ValidationUtil.isEmpty(jgUseRegistration.getProjectContraptionId())) {
idxBizJgProjectContraptionMapper.delete(new LambdaQueryWrapper<IdxBizJgProjectContraption>().eq(IdxBizJgProjectContraption::getSequenceNbr, jgUseRegistration.getProjectContraptionId()));
Iterable<ESEquipmentCategoryDto> equipmentCategoryDtosSnapshot = esEquipmentCategory.findAllById(records);
Iterable<ESEquipmentInfo> esEquipmentInfosSnapshot = esEquipmentDao.findAllById(records);
try {
// 构建设备删除的 DTO 列表
List<ESEquipmentCategoryDto> esDtoList = records.stream().map(v -> {
ESEquipmentCategoryDto esDto = new ESEquipmentCategoryDto();
esDto.setSEQUENCE_NBR(v);
return esDto;
}).collect(Collectors.toList());
//删除涉及的19张表的数据
superviseInfoMapper.deleteDataAll(records);
// 构建设备删除的 新索引的DTO 列表
List<ESEquipmentInfo> esNewDtoList = records.stream().map(v -> {
ESEquipmentInfo esDto = new ESEquipmentInfo();
esDto.setSEQUENCE_NBR(v);
return esDto;
}).collect(Collectors.toList());
//作废使用登记证 & 生成使用登记证的流水
this.invalidUseRegistrationCertificate(jgUseRegistration);
// 单据逻辑删除
this.lambdaUpdate().set(JgUseRegistration::getIsDelete, Boolean.TRUE).eq(JgUseRegistration::getSequenceNbr, sequenceNbr).update();
// 管道作废工程装置
if (!ValidationUtil.isEmpty(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 {
//判断是否管道
......@@ -3514,182 +3553,214 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD
}
}
if (jgUseRegistration.getProjectContraptionId() != null) {
//2.合并后作废
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() + "");
if (isRollBack) { // 进行过编辑逻辑
// 1.还原子工程装置的下的管道信息(装置id)
eqList.stream()
.filter(v -> jgUseRegistration.getOriginProjectContraptionIds().contains(v.getOriginProjectContraptionId()))
.forEach(v -> esEquipmentCategory.findById(v.getEquId()).ifPresent(equInfoEs -> {
equInfoEs.setProjectContraptionId(v.getOriginProjectContraptionId());
esEquipmentCategory.save(equInfoEs);
Optional<ESEquipmentInfo> esEquipmentInfoOp = esEquipmentDao.findById(v.getEquId());
if(esEquipmentInfoOp.isPresent()){
ESEquipmentInfo esEquipmentInfo = esEquipmentInfoOp.get();
esEquipmentInfo.setProjectContraptionId(v.getOriginProjectContraptionId());
esEquipmentDao.save(esEquipmentInfo);
}
LambdaQueryWrapper<IdxBizJgUseInfo> lambda = new QueryWrapper<IdxBizJgUseInfo>().lambda();
lambda.eq(IdxBizJgUseInfo::getRecord, String.valueOf(v.getEquId()));
IdxBizJgUseInfo useInfo = useInfoMapper.selectOne(lambda);
useInfo.setProjectContraptionId(v.getOriginProjectContraptionId());
useInfoMapper.updateById(useInfo);
IdxBizJgProjectContraption originProjectContraption = jgProjectContraptionService.getById(v.getOriginProjectContraptionId());
//还原 原工程装置下equCode和监管码
LambdaUpdateWrapper<IdxBizJgRegisterInfo> updateWrapper = new UpdateWrapper<IdxBizJgRegisterInfo>().lambda()
.eq(IdxBizJgRegisterInfo::getRecord, v.getEquId());
updateWrapper.set(IdxBizJgRegisterInfo::getEquCode, originProjectContraption.getEquCode());
updateWrapper.set(IdxBizJgRegisterInfo::getUseOrgCode, null);
idxBizJgRegisterInfoMapper.update(null, updateWrapper);
LambdaUpdateWrapper<IdxBizJgOtherInfo> otherInfoLambdaUpdateWrapper = new UpdateWrapper<IdxBizJgOtherInfo>().lambda()
.eq(IdxBizJgOtherInfo::getRecord, v.getEquId());
IdxBizJgOtherInfo idxBizJgOtherInfo = new IdxBizJgOtherInfo();
idxBizJgOtherInfo.setSupervisoryCode(originProjectContraption.getSupervisoryCode());
otherInfoMapper.update(idxBizJgOtherInfo, otherInfoLambdaUpdateWrapper);
}));
// 2.根据工程装置ID查询工程装置父级,重置子工程装置父级为空
jgProjectContraptionService.update(
new LambdaUpdateWrapper<IdxBizJgProjectContraption>()
.in(BaseEntity::getSequenceNbr, Arrays.asList(jgUseRegistration.getOriginProjectContraptionIds().split(",")))
.set(IdxBizJgProjectContraption::getProjectContraptionParentId, null)
);
// 3.原装置、新装置重新计算管道长度
this.updateTotalPieLineLength(jgUseRegistration.getOriginProjectContraptionIds(), jgUseRegistration.getProjectContraptionId());
// 4.父工程装置按照是否为有证装置进行更新
JgRegistrationHistory history = jgRegistrationHistoryService.queryLatestRegistrationHistory(Long.valueOf(jgUseRegistration.getProjectContraptionId()));
if (history != null && history.getChangeData() != null) {
JSONObject hisJson = JSON.parseObject(history.getChangeData());
boolean isFirstMerge = Optional.ofNullable(hisJson.get("isFirstMerge"))
.map(Boolean.class::cast)
.orElse(false);
//合并到无证总工程
IdxBizJgProjectContraption projectContraption = jgProjectContraptionService.getById(jgUseRegistration.getProjectContraptionId());
if (isFirstMerge) {
projectContraption.setIsIntoManagement(false);
projectContraption.setIsFirstMerge(true);
projectContraption.setSupervisoryCode(null);
projectContraption.setEquCode(null);
projectContraption.setUseRegistrationCode(null);
projectContraption.setPipelineLength(0.0);
// 处理非批量导入数据,更新关联业务状态
processElseDataByStatus(oldStatus, jgUseRegistration);
// 统一处理设备的纳管状态【注册事务提交后的操作】
Set<String> pIds = new HashSet<>();
pIds.add(jgUseRegistration.getProjectContraptionId());
pIds.addAll(Arrays.asList(jgUseRegistration.getOriginProjectContraptionIds().split(",")));
registerAfterCommitTask(records, pIds);
} else {
// 查询原工程装置及 useInfo 记录
List<String> originProjectContraptionIds = Arrays.asList(jgUseRegistration.getOriginProjectContraptionIds().split(","));
records = idxBizJgUseInfoService.lambdaQuery()
.select(IdxBizJgUseInfo::getRecord)
.in(IdxBizJgUseInfo::getProjectContraptionId, originProjectContraptionIds)
.list()
.stream()
.map(IdxBizJgUseInfo::getRecord)
.collect(Collectors.toList());
Set<String> pIds = new HashSet<>();
pIds.add(jgUseRegistration.getProjectContraptionId());
pIds.addAll(Arrays.asList(jgUseRegistration.getOriginProjectContraptionIds().split(",")));
processElseDataByStatus(oldStatus, jgUseRegistration);
// 统一处理设备的纳管状态
registerAfterCommitTask(records, pIds);
try {
if (isRollBack) { // 进行过编辑逻辑
// 1.还原子工程装置的下的管道信息(装置id)
eqList.stream()
.filter(v -> jgUseRegistration.getOriginProjectContraptionIds().contains(v.getOriginProjectContraptionId()))
.forEach(v -> {
LambdaQueryWrapper<IdxBizJgUseInfo> lambda = new QueryWrapper<IdxBizJgUseInfo>().lambda();
lambda.eq(IdxBizJgUseInfo::getRecord, String.valueOf(v.getEquId()));
IdxBizJgUseInfo useInfo = useInfoMapper.selectOne(lambda);
useInfo.setProjectContraptionId(v.getOriginProjectContraptionId());
useInfoMapper.updateById(useInfo);
IdxBizJgProjectContraption originProjectContraption = jgProjectContraptionService.getById(v.getOriginProjectContraptionId());
Optional.ofNullable(equipmentCategoryDtoMap.get(v.getEquId())).ifPresent(p->{
p.setProjectContraptionId(String.valueOf(originProjectContraption.getSequenceNbr()));
p.setPROJECT_CONTRAPTION(originProjectContraption.getProjectContraption());
p.setOrgBranchCode(originProjectContraption.getOrgCode());
p.setORG_BRANCH_NAME(originProjectContraption.getOrgName());
});
Optional.ofNullable(esEquipmentInfoDtoMap.get(v.getEquId())).ifPresent(p->{
p.setProjectContraptionId(String.valueOf(originProjectContraption.getSequenceNbr()));
p.setPROJECT_CONTRAPTION(originProjectContraption.getProjectContraption());
p.setORG_BRANCH_CODE(originProjectContraption.getOrgCode());
p.setORG_BRANCH_NAME(originProjectContraption.getOrgName());
});
//还原 原工程装置下equCode和监管码
LambdaUpdateWrapper<IdxBizJgRegisterInfo> updateWrapper = new UpdateWrapper<IdxBizJgRegisterInfo>().lambda()
.eq(IdxBizJgRegisterInfo::getRecord, v.getEquId());
updateWrapper.set(IdxBizJgRegisterInfo::getEquCode, originProjectContraption.getEquCode());
updateWrapper.set(IdxBizJgRegisterInfo::getUseOrgCode, null);
idxBizJgRegisterInfoMapper.update(null, updateWrapper);
LambdaUpdateWrapper<IdxBizJgOtherInfo> otherInfoLambdaUpdateWrapper = new UpdateWrapper<IdxBizJgOtherInfo>().lambda()
.eq(IdxBizJgOtherInfo::getRecord, v.getEquId());
IdxBizJgOtherInfo idxBizJgOtherInfo = new IdxBizJgOtherInfo();
idxBizJgOtherInfo.setSupervisoryCode(originProjectContraption.getSupervisoryCode());
otherInfoMapper.update(idxBizJgOtherInfo, otherInfoLambdaUpdateWrapper);
});
// 2.根据工程装置ID查询工程装置父级,重置子工程装置父级为空
jgProjectContraptionService.update(
new LambdaUpdateWrapper<IdxBizJgProjectContraption>()
.in(BaseEntity::getSequenceNbr, Arrays.asList(jgUseRegistration.getOriginProjectContraptionIds().split(",")))
.set(IdxBizJgProjectContraption::getProjectContraptionParentId, null)
);
// 3.原装置、新装置重新计算管道长度
this.updateTotalPieLineLength(jgUseRegistration.getOriginProjectContraptionIds(), jgUseRegistration.getProjectContraptionId());
// 4.父工程装置按照是否为有证装置进行更新
JgRegistrationHistory history = jgRegistrationHistoryService.queryLatestRegistrationHistory(Long.valueOf(jgUseRegistration.getProjectContraptionId()));
if (history != null && history.getChangeData() != null) {
JSONObject hisJson = JSON.parseObject(history.getChangeData());
boolean isFirstMerge = Optional.ofNullable(hisJson.get("isFirstMerge"))
.map(Boolean.class::cast)
.orElse(false);
//合并到无证总工程
IdxBizJgProjectContraption projectContraption = jgProjectContraptionService.getById(jgUseRegistration.getProjectContraptionId());
if (isFirstMerge) {
projectContraption.setIsIntoManagement(false);
projectContraption.setIsFirstMerge(true);
projectContraption.setSupervisoryCode(null);
projectContraption.setEquCode(null);
projectContraption.setUseRegistrationCode(null);
projectContraption.setPipelineLength(0.0);
// 处理非批量导入数据,更新关联业务状态
processElseDataByStatus(oldStatus, jgUseRegistration);
// 统一处理设备的纳管状态【注册事务提交后的操作】
Set<String> pIds = new HashSet<>();
pIds.add(jgUseRegistration.getProjectContraptionId());
pIds.addAll(Arrays.asList(jgUseRegistration.getOriginProjectContraptionIds().split(",")));
registerAfterCommitTask(records, pIds);
} else {
// 查询原工程装置及 useInfo 记录
List<String> originProjectContraptionIds = Arrays.asList(jgUseRegistration.getOriginProjectContraptionIds().split(","));
records = idxBizJgUseInfoService.lambdaQuery()
.select(IdxBizJgUseInfo::getRecord)
.in(IdxBizJgUseInfo::getProjectContraptionId, originProjectContraptionIds)
.list()
.stream()
.map(IdxBizJgUseInfo::getRecord)
.collect(Collectors.toList());
Set<String> pIds = new HashSet<>();
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()
.filter(v -> jgUseRegistration.getOriginProjectContraptionIds().contains(v.getOriginProjectContraptionId()))
.forEach(v -> esEquipmentCategory.findById(v.getEquId()).ifPresent(equInfoEs -> {
equInfoEs.setProjectContraptionId(v.getOriginProjectContraptionId());
esEquipmentCategory.save(equInfoEs);
LambdaQueryWrapper<IdxBizJgUseInfo> lambda = new QueryWrapper<IdxBizJgUseInfo>().lambda();
lambda.eq(IdxBizJgUseInfo::getRecord, String.valueOf(v.getEquId()));
IdxBizJgUseInfo useInfo = useInfoMapper.selectOne(lambda);
useInfo.setProjectContraptionId(v.getOriginProjectContraptionId());
useInfoMapper.updateById(useInfo);
IdxBizJgProjectContraption originProjectContraption = jgProjectContraptionService.getById(v.getOriginProjectContraptionId());
//还原 原工程装置下equCode和监管码
LambdaUpdateWrapper<IdxBizJgRegisterInfo> updateWrapper = new UpdateWrapper<IdxBizJgRegisterInfo>().lambda()
.eq(IdxBizJgRegisterInfo::getRecord, v.getEquId());
IdxBizJgRegisterInfo idxBizJgRegisterInfo = new IdxBizJgRegisterInfo();
idxBizJgRegisterInfo.setEquCode(originProjectContraption.getEquCode());
idxBizJgRegisterInfoMapper.update(idxBizJgRegisterInfo, updateWrapper);
LambdaUpdateWrapper<IdxBizJgOtherInfo> otherInfoLambdaUpdateWrapper = new UpdateWrapper<IdxBizJgOtherInfo>().lambda()
.eq(IdxBizJgOtherInfo::getRecord, v.getEquId());
IdxBizJgOtherInfo idxBizJgOtherInfo = new IdxBizJgOtherInfo();
idxBizJgOtherInfo.setSupervisoryCode(originProjectContraption.getSupervisoryCode());
otherInfoMapper.update(idxBizJgOtherInfo, otherInfoLambdaUpdateWrapper);
}));
//2.根据工程装置ID查询工程装置父级,重置子工程装置父级为空
jgProjectContraptionService.update(
new LambdaUpdateWrapper<IdxBizJgProjectContraption>()
.in(BaseEntity::getSequenceNbr, Arrays.asList(jgUseRegistration.getOriginProjectContraptionIds().split(",")))
.set(IdxBizJgProjectContraption::getProjectContraptionParentId, null)
);
JgRegistrationHistory history = jgRegistrationHistoryService.queryLatestRegistrationHistory(Long.valueOf(jgUseRegistration.getProjectContraptionId()));
if (history != null && history.getChangeData() != null) {
JSONObject hisJson = JSON.parseObject(history.getChangeData());
boolean isFirstMerge = Optional.ofNullable(hisJson.get("isFirstMerge"))
.map(Boolean.class::cast)
.orElse(false);
//合并到无证总工程
IdxBizJgProjectContraption projectContraption = jgProjectContraptionService.getById(jgUseRegistration.getProjectContraptionId());
if (isFirstMerge) {
projectContraption.setIsIntoManagement(false);
projectContraption.setIsFirstMerge(true);
projectContraption.setSupervisoryCode(null);
projectContraption.setEquCode(null);
projectContraption.setUseRegistrationCode(null);
projectContraption.setPipelineLength(0.0);
// 处理非批量导入数据,更新关联业务状态
processElseDataByStatus(oldStatus, jgUseRegistration);
// 统一处理设备的纳管状态【注册事务提交后的操作】
Set<String> pIds = new HashSet<>();
pIds.add(jgUseRegistration.getProjectContraptionId());
pIds.addAll(Arrays.asList(jgUseRegistration.getOriginProjectContraptionIds().split(",")));
registerAfterCommitTask(records, pIds);
} else {
// 查询原工程装置及 useInfo 记录
List<String> originProjectContraptionIds = Arrays.asList(jgUseRegistration.getOriginProjectContraptionIds().split(","));
List<IdxBizJgProjectContraption> originProjectContraptionList = jgProjectContraptionService.lambdaQuery()
.in(BaseEntity::getSequenceNbr, originProjectContraptionIds)
.list();
records = idxBizJgUseInfoService.lambdaQuery()
.select(IdxBizJgUseInfo::getRecord)
.in(IdxBizJgUseInfo::getProjectContraptionId, originProjectContraptionIds)
.list()
.stream()
.map(IdxBizJgUseInfo::getRecord)
.collect(Collectors.toList());
// 统一处理设备的纳管状态
Set<String> pIds = new HashSet<>();
pIds.add(jgUseRegistration.getProjectContraptionId());
pIds.addAll(Arrays.asList(jgUseRegistration.getOriginProjectContraptionIds().split(",")));
registerAfterCommitTask(records, pIds);
processElseDataByStatus(oldStatus, jgUseRegistration);
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);
} else { // 未进行过编辑逻辑,走原来逻辑
eqList.stream()
.filter(v -> jgUseRegistration.getOriginProjectContraptionIds().contains(v.getOriginProjectContraptionId()))
.forEach(v -> {
LambdaQueryWrapper<IdxBizJgUseInfo> lambda = new QueryWrapper<IdxBizJgUseInfo>().lambda();
lambda.eq(IdxBizJgUseInfo::getRecord, String.valueOf(v.getEquId()));
IdxBizJgUseInfo useInfo = useInfoMapper.selectOne(lambda);
useInfo.setProjectContraptionId(v.getOriginProjectContraptionId());
useInfoMapper.updateById(useInfo);
IdxBizJgProjectContraption originProjectContraption = jgProjectContraptionService.getById(v.getOriginProjectContraptionId());
Optional.ofNullable(equipmentCategoryDtoMap.get(v.getEquId())).ifPresent(p->{
p.setProjectContraptionId(String.valueOf(originProjectContraption.getSequenceNbr()));
p.setPROJECT_CONTRAPTION(originProjectContraption.getProjectContraption());
p.setOrgBranchCode(originProjectContraption.getOrgCode());
p.setORG_BRANCH_NAME(originProjectContraption.getOrgName());
});
Optional.ofNullable(esEquipmentInfoDtoMap.get(v.getEquId())).ifPresent(p->{
p.setProjectContraptionId(String.valueOf(originProjectContraption.getSequenceNbr()));
p.setPROJECT_CONTRAPTION(originProjectContraption.getProjectContraption());
p.setORG_BRANCH_CODE(originProjectContraption.getOrgCode());
p.setORG_BRANCH_NAME(originProjectContraption.getOrgName());
});
//还原 原工程装置下equCode和监管码
LambdaUpdateWrapper<IdxBizJgRegisterInfo> updateWrapper = new UpdateWrapper<IdxBizJgRegisterInfo>().lambda()
.eq(IdxBizJgRegisterInfo::getRecord, v.getEquId());
IdxBizJgRegisterInfo idxBizJgRegisterInfo = new IdxBizJgRegisterInfo();
idxBizJgRegisterInfo.setEquCode(originProjectContraption.getEquCode());
idxBizJgRegisterInfoMapper.update(idxBizJgRegisterInfo, updateWrapper);
LambdaUpdateWrapper<IdxBizJgOtherInfo> otherInfoLambdaUpdateWrapper = new UpdateWrapper<IdxBizJgOtherInfo>().lambda()
.eq(IdxBizJgOtherInfo::getRecord, v.getEquId());
IdxBizJgOtherInfo idxBizJgOtherInfo = new IdxBizJgOtherInfo();
idxBizJgOtherInfo.setSupervisoryCode(originProjectContraption.getSupervisoryCode());
otherInfoMapper.update(idxBizJgOtherInfo, otherInfoLambdaUpdateWrapper);
});
//2.根据工程装置ID查询工程装置父级,重置子工程装置父级为空
jgProjectContraptionService.update(
new LambdaUpdateWrapper<IdxBizJgProjectContraption>()
.in(BaseEntity::getSequenceNbr, Arrays.asList(jgUseRegistration.getOriginProjectContraptionIds().split(",")))
.set(IdxBizJgProjectContraption::getProjectContraptionParentId, null)
);
JgRegistrationHistory history = jgRegistrationHistoryService.queryLatestRegistrationHistory(Long.valueOf(jgUseRegistration.getProjectContraptionId()));
if (history != null && history.getChangeData() != null) {
JSONObject hisJson = JSON.parseObject(history.getChangeData());
boolean isFirstMerge = Optional.ofNullable(hisJson.get("isFirstMerge"))
.map(Boolean.class::cast)
.orElse(false);
//合并到无证总工程
IdxBizJgProjectContraption projectContraption = jgProjectContraptionService.getById(jgUseRegistration.getProjectContraptionId());
if (isFirstMerge) {
projectContraption.setIsIntoManagement(false);
projectContraption.setIsFirstMerge(true);
projectContraption.setSupervisoryCode(null);
projectContraption.setEquCode(null);
projectContraption.setUseRegistrationCode(null);
projectContraption.setPipelineLength(0.0);
// 处理非批量导入数据,更新关联业务状态
processElseDataByStatus(oldStatus, jgUseRegistration);
// 统一处理设备的纳管状态【注册事务提交后的操作】
Set<String> pIds = new HashSet<>();
pIds.add(jgUseRegistration.getProjectContraptionId());
pIds.addAll(Arrays.asList(jgUseRegistration.getOriginProjectContraptionIds().split(",")));
registerAfterCommitTask(records, pIds);
} else {
// 查询原工程装置及 useInfo 记录
List<String> originProjectContraptionIds = Arrays.asList(jgUseRegistration.getOriginProjectContraptionIds().split(","));
List<IdxBizJgProjectContraption> originProjectContraptionList = jgProjectContraptionService.lambdaQuery()
.in(BaseEntity::getSequenceNbr, originProjectContraptionIds)
.list();
records = idxBizJgUseInfoService.lambdaQuery()
.select(IdxBizJgUseInfo::getRecord)
.in(IdxBizJgUseInfo::getProjectContraptionId, originProjectContraptionIds)
.list()
.stream()
.map(IdxBizJgUseInfo::getRecord)
.collect(Collectors.toList());
// 统一处理设备的纳管状态
Set<String> pIds = new HashSet<>();
pIds.add(jgUseRegistration.getProjectContraptionId());
pIds.addAll(Arrays.asList(jgUseRegistration.getOriginProjectContraptionIds().split(",")));
registerAfterCommitTask(records, pIds);
processElseDataByStatus(oldStatus, jgUseRegistration);
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.子工程装置作废,正常逻辑
......@@ -3704,25 +3775,81 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD
this.rollBackForPieLine(jgUseRegistration);
processElseDataByStatus(oldStatus, jgUseRegistration);
registerAfterCommitTask(records, Sets.newHashSet(jgUseRegistration.getProjectContraptionId()));
this.updateById(jgUseRegistration);
}
}
//气瓶
else {
// 处理非批量导入数据,更新关联业务状态
processElseDataByStatus(oldStatus, jgUseRegistration);
// 统一处理设备的纳管状态【注册事务提交后的操作】
registerAfterCommitTask(records);
Iterable<ESEquipmentCategoryDto> equipmentCategoryDtosSnapshot = esEquipmentCategory.findAllById(records);
Iterable<ESEquipmentInfo> esEquipmentInfosSnapshot = esEquipmentDao.findAllById(records);
try {
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 {
// 处理非批量导入数据,更新关联业务状态
processElseDataByStatus(oldStatus, jgUseRegistration);
// 统一处理设备的纳管状态【注册事务提交后的操作】
registerAfterCommitTask(records);
Iterable<ESEquipmentCategoryDto> equipmentCategoryDtosSnapshot = esEquipmentCategory.findAllById(records);
Iterable<ESEquipmentInfo> esEquipmentInfosSnapshot = esEquipmentDao.findAllById(records);
try {
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;
}
......@@ -3783,14 +3910,6 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD
Boolean flag = Boolean.FALSE;
LambdaQueryWrapper<IdxBizJgRegisterInfo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
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.使用信息表部分字段赋空
this.rollBackUseInfo(record, flag);
// 2.回滚更新idx_biz_jg_register_info表
......@@ -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) {
if (!StringUtils.isEmpty(jgUseRegistration.getProjectContraptionId())) {
// 清除使用登记证编号
......@@ -3893,6 +4037,71 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD
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) {
LambdaQueryWrapper<IdxBizJgConstructionInfo> wrapper = new LambdaQueryWrapper<>();
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