Commit ae80aae0 authored by suhuiguang's avatar suhuiguang

fix(设备创建) :es双写优化

1.写es移动到最后执行
parent 5ba6d6ed
......@@ -639,6 +639,9 @@ public class JgChangeRegistrationReformServiceImpl extends BaseService<JgChangeR
taskModelDto.setModel(conveterTaskMessageDTO(jgChangeRegistrationReform));
commonServiceImpl.buildTaskModel(Collections.singletonList(taskModelDto));
}
// redis流程实时数据更新
commonServiceImpl.saveExecuteFlowData2Redis(instanceId, this.buildInstanceRuntimeData(jgChangeRegistrationReform));
this.getBaseMapper().updateById(jgChangeRegistrationReform);
} else {
jgChangeRegistrationReform.setAuditPassDate(new Date());
jgChangeRegistrationReform.setAuditStatus(FlowStatusEnum.TO_BE_FINISHED.getName());
......@@ -672,11 +675,24 @@ public class JgChangeRegistrationReformServiceImpl extends BaseService<JgChangeR
// 创建设备履历
this.createResume(jgChangeRegistrationReform, taskV2Model.getRoutePath());
}
this.sendDataRefreshMsg(jgChangeRegistrationReform);
}
// redis流程实时数据更新
commonServiceImpl.saveExecuteFlowData2Redis(instanceId, this.buildInstanceRuntimeData(jgChangeRegistrationReform));
this.getBaseMapper().updateById(jgChangeRegistrationReform);
// 清除施工单位信息
this.clearUscInfoEs(jgChangeRegistrationReform);
this.sendDataRefreshMsg(jgChangeRegistrationReform);
}
}
private void clearUscInfoEs(JgChangeRegistrationReform reform) {
// es
List<JgChangeRegistrationReformEq> reformEqs = jgChangeRegistrationReformEqMapper.selectList(new LambdaQueryWrapper<JgChangeRegistrationReformEq>().eq(JgChangeRegistrationReformEq::getEquipTransferId, reform.getSequenceNbr()));
Iterable<ESEquipmentCategoryDto> esEquipmentCategoryDtos = esEquipmentCategory.findAllById(reformEqs.stream().map(JgChangeRegistrationReformEq::getEquId).collect(Collectors.toList()));
esEquipmentCategoryDtos.forEach(esEquipmentCategoryDto -> {
esEquipmentCategoryDto.setUSC_UNIT_NAME(null);
esEquipmentCategoryDto.setUSC_UNIT_CREDIT_CODE(null);
});
esEquipmentCategory.saveAll(esEquipmentCategoryDtos);
}
/**
......@@ -747,17 +763,6 @@ public class JgChangeRegistrationReformServiceImpl extends BaseService<JgChangeR
.set(IdxBizJgProjectContraption::getUscUnitCreditCode, null)
.set(IdxBizJgProjectContraption::getUscUnitName, null)
.update();
// es
List<JgChangeRegistrationReformEq> reformEqs = jgChangeRegistrationReformEqMapper.selectList(new LambdaQueryWrapper<JgChangeRegistrationReformEq>().eq(JgChangeRegistrationReformEq::getEquipTransferId, reform.getSequenceNbr()));
reformEqs.forEach(reformEq -> {
Optional<ESEquipmentCategoryDto> optional = esEquipmentCategory.findById(reformEq.getEquId());
if (optional.isPresent()) {
ESEquipmentCategoryDto esEquipmentCategoryDto = optional.get();
esEquipmentCategoryDto.setUSC_UNIT_NAME(null);
esEquipmentCategoryDto.setUSC_UNIT_CREDIT_CODE(null);
esEquipmentCategory.save(esEquipmentCategoryDto);
}
});
}
private void clearUscWInfo(JgChangeRegistrationReform reform) {
......@@ -769,14 +774,6 @@ public class JgChangeRegistrationReformServiceImpl extends BaseService<JgChangeR
updateWrapper.set(IdxBizJgUseInfo::getUSC_UNIT_CREDIT_CODE, null);
updateWrapper.set(IdxBizJgUseInfo::getUSC_UNIT_NAME, null);
idxBizJgUseInfoService.update(updateWrapper);
// es清空
Optional<ESEquipmentCategoryDto> optional = esEquipmentCategory.findById(reformEq.getEquId());
if (optional.isPresent()) {
ESEquipmentCategoryDto esEquipmentCategoryDto = optional.get();
esEquipmentCategoryDto.setUSC_UNIT_NAME(null);
esEquipmentCategoryDto.setUSC_UNIT_CREDIT_CODE(null);
esEquipmentCategory.save(esEquipmentCategoryDto);
}
});
}
......
......@@ -53,6 +53,7 @@ import com.yeejoin.amos.boot.module.ymt.api.mapper.IdxBizJgUseInfoMapper;
import com.yeejoin.amos.feign.systemctl.model.TaskV2Model;
import com.yeejoin.amos.feign.workflow.Workflow;
import com.yeejoin.amos.feign.workflow.model.*;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.BeanUtils;
......@@ -82,6 +83,7 @@ import static java.util.stream.Collectors.toSet;
* @date 2023-12-25
*/
@Service
@Slf4j
public class JgEnableDisableServiceImpl extends BaseService<JgEnableDisableDto, JgEnableDisable, JgEnableDisableMapper> implements IJgEnableDisableService, ICompensateFlowDataOfRedis<JgEnableDisable> {
......@@ -587,7 +589,7 @@ public class JgEnableDisableServiceImpl extends BaseService<JgEnableDisableDto,
// 执行工作流并返回组装好的工作流信息
WorkflowResultDto workflowResultDto = getWorkflowResultDto(operate, comment, jgEnableDisable);
List<ESEquipmentCategoryDto> esEquipmentCategoryDtos = new ArrayList<>();
jgEnableDisable.setPromoter(reginParams.getUserModel().getUserId());
TaskV2Model taskV2Model = new TaskV2Model();
if ("0".equals(operate)) {
......@@ -606,7 +608,7 @@ public class JgEnableDisableServiceImpl extends BaseService<JgEnableDisableDto,
BeanUtils.copyProperties(jgEnableDisable, taskMessageDto);
taskMap.put("model", jgEnableDisable);
// 更新业务数据
updateInfoOther(jgEnableDisable);
esEquipmentCategoryDtos = updateInfoOther(jgEnableDisable);
// 保存json历史数据
commonService.saveOrUpdateHistory(this.getRegistrationClass(jgEnableDisable), map, null, jgEnableDisable.getSequenceNbr().toString());
TaskV2Model taskV2Model1 = commonService.updateTaskModel(taskMap);
......@@ -679,6 +681,9 @@ public class JgEnableDisableServiceImpl extends BaseService<JgEnableDisableDto,
// redis流程实时数据更新
commonService.saveExecuteFlowData2Redis(instanceId, this.buildInstanceRuntimeData(jgEnableDisable));
this.delRepeatUseEquipData(jgEnableDisable);
if(!esEquipmentCategoryDtos.isEmpty()){
esEquipmentCategory.saveAll(esEquipmentCategoryDtos);
}
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
......@@ -731,7 +736,8 @@ public class JgEnableDisableServiceImpl extends BaseService<JgEnableDisableDto,
eventPublisher.publish(new DataRefreshEvent(this, records, DataRefreshEvent.DataType.equipment.name(), DataRefreshEvent.Operation.UPDATE));
}
private void updateInfoOther(JgEnableDisable jgEnableDisable) {
private List<ESEquipmentCategoryDto> updateInfoOther(JgEnableDisable jgEnableDisable) {
List<ESEquipmentCategoryDto> esEquipmentCategoryDtos = new ArrayList<>();
// 1.更新设备的使用信息:启用->停用,停用->启用
LambdaQueryWrapper<JgEnableDisableEq> lambdaEq = new QueryWrapper<JgEnableDisableEq>().lambda();
lambdaEq.eq(JgEnableDisableEq::getEnableDisableApplyId, jgEnableDisable.getSequenceNbr());
......@@ -749,7 +755,8 @@ public class JgEnableDisableServiceImpl extends BaseService<JgEnableDisableDto,
wrapper.eq(IdxBizJgUseInfo::getRecord, jgEnableDisableEq.getEquId());
idxBizJgUseInfoMapper.update(idxBizJgUseInfo, wrapper);
// 2.更新设备的es数据的状态:启用->停用,停用->启用
updateEquipEsData(jgEnableDisableEq, idxBizJgUseInfo);
ESEquipmentCategoryDto equipmentCategoryDto = updateEquipEsData(jgEnableDisableEq, idxBizJgUseInfo);
esEquipmentCategoryDtos.add(equipmentCategoryDto);
});
String useRegistrationCodeStr = jgEnableDisable.getUseRegistrationCode();
List<String> useRegistrationCodeList = Optional.ofNullable(useRegistrationCodeStr)
......@@ -765,18 +772,19 @@ public class JgEnableDisableServiceImpl extends BaseService<JgEnableDisableDto,
.in(JgUseRegistrationManage::getUseRegistrationCode, useRegistrationCodeList)
.update();
}
return esEquipmentCategoryDtos;
}
private void updateEquipEsData(JgEnableDisableEq jgScrapCancelEq, IdxBizJgUseInfo idxBizJgUseInfo) {
Map<String, Map<String, Object>> resultMap = new HashMap<>();
Map<String, Object> map1 = new HashMap<>();
map1.put("EQU_STATE", idxBizJgUseInfo.getEquState());
resultMap.put(jgScrapCancelEq.getEquId(), map1);
try {
tzsServiceFeignClient.commonUpdateEsDataByIds(resultMap);
} catch (Exception e) {
log.error("更新es失败", e.getCause());
private ESEquipmentCategoryDto updateEquipEsData(JgEnableDisableEq jgScrapCancelEq, IdxBizJgUseInfo idxBizJgUseInfo) {
Optional<ESEquipmentCategoryDto> optional = esEquipmentCategory.findById(jgScrapCancelEq.getEquId());
if(optional.isPresent()){
ESEquipmentCategoryDto dto = optional.get();
dto.setEQU_STATE(Integer.parseInt(idxBizJgUseInfo.getEquState()));
return dto;
}
log.error("办理使用登记的设备{},在es中不存在", jgScrapCancelEq.getEquId());
throw new BadRequest("设备数据不存在");
}
......
......@@ -73,6 +73,7 @@ import org.typroject.tyboot.core.restful.utils.ResponseModel;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import static java.util.stream.Collectors.toSet;
......@@ -1032,11 +1033,13 @@ public class JgScrapCancelServiceImpl extends BaseService<JgScrapCancelDto, JgSc
// 执行流程
ProcessTaskDTO processTaskDTO = cmWorkflowService.completeOrReject(taskId, dto, operate);
// 更新下一步执行人、创建待办
updateExecuteIds(equList, instanceId, id, operate, processTaskDTO);
List<ESEquipmentCategoryDto> esEquipmentCategoryDtos = updateExecuteIds(equList, instanceId, id, operate, processTaskDTO);
// redis流程实时数据更新
commonService.saveExecuteFlowData2Redis(instanceId, this.buildInstanceRuntimeData(jgScrapCancel));
this.delRepeatUseEquipData(jgScrapCancel);
if(!esEquipmentCategoryDtos.isEmpty()){
esEquipmentCategory.saveAll(esEquipmentCategoryDtos);
}
} catch (InterruptedException e) {
e.printStackTrace();
} catch (BadRequest e) {
......@@ -1058,7 +1061,8 @@ public class JgScrapCancelServiceImpl extends BaseService<JgScrapCancelDto, JgSc
.build();
}
public void updateExecuteIds(String equList, String instanceId, Long sequenceNbr, String operate, ProcessTaskDTO processTaskDTO) {
public List<ESEquipmentCategoryDto> updateExecuteIds(String equList, String instanceId, Long sequenceNbr, String operate, ProcessTaskDTO processTaskDTO) {
List<ESEquipmentCategoryDto> esEquipmentCategoryDtos = new ArrayList<>();
List<String> roleListNext = new ArrayList<>();
List<String> roleListAll = new ArrayList<>();
String taskCode = FlowStatusEnum.TO_BE_FINISHED.getName();
......@@ -1107,13 +1111,28 @@ public class JgScrapCancelServiceImpl extends BaseService<JgScrapCancelDto, JgSc
// 更新代办
TaskV2Model taskV2Model = updateTaskModel(scrapCancelDto, operate);
// 修改业务信息
updateInfoOther(jgScrapCancel, taskV2Model.getRoutePath());
List<String> records = updateInfoOther(jgScrapCancel, taskV2Model.getRoutePath());
esEquipmentCategoryDtos = this.buildEsData(records, jgScrapCancel);
// 发送数据变更消息
this.sendDataRefreshMsg(jgScrapCancel);
// 创建设备履历
this.createResume(jgScrapCancel, taskV2Model.getRoutePath());
}
this.getBaseMapper().updateById(jgScrapCancel);
return esEquipmentCategoryDtos;
}
private List<ESEquipmentCategoryDto> buildEsData(List<String> records, JgScrapCancel jgScrapCancel) {
Iterable<ESEquipmentCategoryDto> equipmentCategoryDtos = esEquipmentCategory.findAllById(records);
Integer equState;
if (CancelTypeEnum.SCRAPPED.getCode().equals(jgScrapCancel.getCancelType())) {
equState = EquipmentEnum.BAOFEI.getCode();
} else {
equState = EquipmentEnum.ZHUXIAO.getCode();
}
Integer finalEquState = equState;
equipmentCategoryDtos.forEach(e-> e.setEQU_STATE(finalEquState));
return StreamSupport.stream(equipmentCategoryDtos.spliterator(), false).collect(Collectors.toList());
}
private void createResume(JgScrapCancel jgScrapCancel, String routePath) {
......@@ -1142,7 +1161,7 @@ public class JgScrapCancelServiceImpl extends BaseService<JgScrapCancelDto, JgSc
eventPublisher.publish(new DataRefreshEvent(this, records, DataRefreshEvent.DataType.equipment.name(), DataRefreshEvent.Operation.UPDATE));
}
private void updateInfoOther(JgScrapCancel jgScrapCancel, String routePath) {
private List<String> updateInfoOther(JgScrapCancel jgScrapCancel, String routePath) {
LambdaQueryWrapper<JgScrapCancelEq> lambdaEq = new LambdaQueryWrapper<>();
lambdaEq.eq(JgScrapCancelEq::getEquipTransferId, jgScrapCancel.getSequenceNbr());
lambdaEq.select(JgScrapCancelEq::getEquId, JgScrapCancelEq::getUseRegistrationCode);
......@@ -1233,6 +1252,7 @@ public class JgScrapCancelServiceImpl extends BaseService<JgScrapCancelDto, JgSc
}
jgScrapCancel.setAuditStatus(FlowStatusEnum.TO_BE_FINISHED.getName());
jgScrapCancel.setAuditPassDate(new Date());
return equipIds;
}
private void updateProjectContraption(String projectContraptionId) {
......
......@@ -2178,6 +2178,7 @@ public class JgVehicleInformationServiceImpl extends BaseService<JgVehicleInform
}
}
List<ESEquipmentCategoryDto> esEquipmentCategoryDtos = new ArrayList<>();
// 更新关联气瓶信息
if (!CollectionUtils.isEmpty(equipmentLists)) {
List<JgVehicleInformationEq> equipList = new ArrayList<>();
......@@ -2239,7 +2240,8 @@ public class JgVehicleInformationServiceImpl extends BaseService<JgVehicleInform
if(!Arrays.asList("temp", "tempEdit").contains(submitType)){
this.updateEquipInfo(vehicleInformation, registerInfo, otherInfo, String.valueOf(x.get("record")));
// 更新es
this.updateEquipEsData(vehicleInformation, otherInfo, registerInfo, String.valueOf(x.get("record")), useInfo);
ESEquipmentCategoryDto equipmentCategoryDto = this.updateEquipEsData(vehicleInformation, otherInfo, registerInfo, String.valueOf(x.get("record")), useInfo);
esEquipmentCategoryDtos.add(equipmentCategoryDto);
}
// 查询设备制造信息
LambdaQueryWrapper<IdxBizJgFactoryInfo> factoryInfoWrapper = new LambdaQueryWrapper<>();
......@@ -2261,6 +2263,9 @@ public class JgVehicleInformationServiceImpl extends BaseService<JgVehicleInform
Set<String> recordSet = equipmentLists.stream()
.map(v -> (String) v.get("record"))
.collect(Collectors.toSet());
if(!esEquipmentCategoryDtos.isEmpty()){
esEquipmentCategory.saveAll(esEquipmentCategoryDtos);
}
eventPublisher.publish(new EquipCreateOrEditEvent(this, BusinessTypeEnum.JG_NEW_EQUIP.name(), recordSet, EquipCreateOrEditEvent.EquipType.equip));
return Collections.singletonList(vehicleInformation);
}
......@@ -2572,15 +2577,16 @@ public class JgVehicleInformationServiceImpl extends BaseService<JgVehicleInform
this.createCode(jgVehicleInformation, registerInfo, otherInfo);
}
private void updateEquipEsData(JgVehicleInformation jgVehicleInformation, IdxBizJgOtherInfo otherInfo,
private ESEquipmentCategoryDto updateEquipEsData(JgVehicleInformation jgVehicleInformation, IdxBizJgOtherInfo otherInfo,
IdxBizJgRegisterInfo registerInfo, String equId ,IdxBizJgUseInfo useInfo) {
Optional<ESEquipmentCategoryDto> op = esEquipmentCategory.findById((String) equId);
if(op.isPresent()){
// 更新es
HashMap<String, Map<String, Object>> objMap = new HashMap<>();
HashMap<String, Object> param = new HashMap<>();
param.put("SUPERVISORY_CODE", otherInfo.getSupervisoryCode());
param.put("USE_UNIT_CREDIT_CODE", jgVehicleInformation.getUseUnitCreditCode());
param.put("USE_UNIT_NAME", jgVehicleInformation.getUseUnitName());
//param.put("ADDRESS", otherInfo.get);
param.put("USE_PLACE", jgVehicleInformation.getUseUnitAddress());
param.put("STATUS", "已认领");
param.put("EQU_STATE", Optional.ofNullable(useInfo.getEquState())
......@@ -2590,8 +2596,12 @@ public class JgVehicleInformationServiceImpl extends BaseService<JgVehicleInform
param.put("ORG_BRANCH_NAME", jgVehicleInformation.getOrgBranchName());
param.put("EQU_CODE", registerInfo.getEquCode());
param.put("USE_ORG_CODE", jgVehicleInformation.getUseRegistrationCode());
objMap.put(equId, param);
tzsServiceFeignClient.commonUpdateEsDataByIds(objMap);
ESEquipmentCategoryDto categoryDto = op.get();
BeanUtil.copyProperties(param, categoryDto, true);
return categoryDto;
}
log.error("办理车用使用登记的设备{},在es中不存在", equId);
throw new BadRequest("设备数据不存在");
}
@Override
......
......@@ -398,10 +398,19 @@ public class CommonServiceImpl {
return "no";
}
public void updateEquipNextInspectDate(JyjcInspectionResultModel model, String record) {
updateEsInspectDate(record, model.getNextInspectionDate());
public void updateEquipNextInspectDateBatch(Date nextInspectionDate, List<String> records) {
if (nextInspectionDate != null) {
Iterable<ESEquipmentCategoryDto> equipmentCategoryDtos = esEquipmentCategory.findAllById(records);
equipmentCategoryDtos.forEach(esEquipmentCategoryDto->{
esEquipmentCategoryDto.setNEXT_INSPECT_DATE(nextInspectionDate.getTime());
});
esEquipmentCategory.saveAll(equipmentCategoryDtos);
}
}
public void updateEquipNextInspectDate(JyjcInspectionResult model, String record) {
updateEsInspectDate(record, model.getNextInspectionDate());
}
......
......@@ -372,8 +372,6 @@ public class JyjcInspectionResultServiceImpl extends BaseService<JyjcInspectionR
}
// 3.更新使用信息表,最新检验信息
useInfoMapper.updateByRecord(record, model.getNextInspectionDate(), model.getInspectionType(), model.getApplicationNo());
// 4.更新es下次检验日期
commonService.updateEquipNextInspectDate(model, record);
});
// 更新装置的汇总的管道长度
calAndWriteTotalPipelineLength(model.getEquipUnicode());
......@@ -405,10 +403,10 @@ public class JyjcInspectionResultServiceImpl extends BaseService<JyjcInspectionR
}
// 3.更新使用信息表最新的检验信息
useInfoMapper.updateByRecord(model.getEquipUnicode(), model.getNextInspectionDate(), model.getInspectionType(), model.getApplicationNo());
// 4.es更新下次检验日期
commonService.updateEquipNextInspectDate(model, model.getEquipUnicode());
records.add(model.getEquipUnicode());
}
// 4.es更新下次检验日期
commonService.updateEquipNextInspectDateBatch(model.getNextInspectionDate(), new ArrayList<>(records));
return records;
}
......
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