Commit 995750f8 authored by suhuiguang's avatar suhuiguang

1.编辑代码整理

parent a928be6d
package com.yeejoin.amos.boot.module.jg.api.dto;
import java.io.Serializable;
public class BaseTechParamsFieldDto implements Serializable {
public class BaseTechParamsFieldDto extends BaseChangeDataDto {
}
package com.yeejoin.amos.boot.module.jg.api.dto;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.annotation.TableField;
import com.yeejoin.amos.boot.biz.common.annotation.FieldDisplayDefine;
import com.yeejoin.amos.boot.biz.common.annotation.Group;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.Date;
@EqualsAndHashCode(callSuper = true)
@Data
@Group(value = "jg_inspection_detection_info")
public class EquipInspectChangeDataDto extends BaseChangeDataDto {
@FieldDisplayDefine(value = "设计单位统一社会信用代码")
private String designUnitCreditCode;
@FieldDisplayDefine(value ="检验类型")
private String inspectType;
@FieldDisplayDefine(value ="检验机构名称")
private String inspectOrgName;
@FieldDisplayDefine(value ="检验报告", type = JSON.class)
private String inspectReport;
@FieldDisplayDefine(value ="检验日期")
private Date inspectDate;
@FieldDisplayDefine(value ="检验结论")
private String inspectConclusion;
@FieldDisplayDefine(value ="下次检验日期")
private Date nextInspectDate;
@FieldDisplayDefine(value ="检验机构统一信用代码")
private String inspectOrgCode;
@FieldDisplayDefine(value ="检验报告编号")
private String inspectReportNo;
@FieldDisplayDefine(value ="检验流水唯一主键",isExist = false)
private String jySeq;
}
package com.yeejoin.amos.boot.module.jg.api.dto;
import lombok.Data;
import java.util.Map;
@Data
public class ProjectContraptionChangeItem {
private String projectContraptionId;
Map<String, Object> detail;
}
......@@ -2,19 +2,48 @@ package com.yeejoin.amos.boot.module.jg.api.dto;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.boot.module.jg.api.service.IBizDataChangeHandleStrategy;
import java.util.HashMap;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
public class RequestChangeData extends JSONObject {
/**
* 批量编辑时表格key
*/
public static final String multiDataKey = "tableData";
/**
* 分类
*/
private static final String modelTypeKey = "modelType";
/**
* 删除的数据表格key
*/
public static final String deletedDataKey = "deleteData";
/**
* 变更说明
*/
public static final String changeReasonKey = "changeReason";
/**
* 变更说明附件
*/
public static final String changeReasonAttachmentKey = "changeReasonAttachment";
public IBizDataChangeHandleStrategy.ModelType getModelType() {
if (!this.containsKey(multiDataKey)) {
return IBizDataChangeHandleStrategy.ModelType.single;
if (this.containsKey(modelTypeKey)) {
return IBizDataChangeHandleStrategy.ModelType.valueOf(this.getString(modelTypeKey));
}
return null;
}
public void validated (){
if(!this.containsKey(changeReasonKey) || !this.containsKey(changeReasonAttachmentKey) ) {
throw new BadRequest("变更说明和变更说明附件不能为空!");
}
return IBizDataChangeHandleStrategy.ModelType.batch;
}
}
......@@ -19,7 +19,7 @@ import lombok.experimental.Accessors;
public class TechParamsPipelineChangeFieldDto extends BaseTechParamsFieldDto {
@FieldDisplayDefine(value = "w唯一标识", isExist = false)
@FieldDisplayDefine(value = "唯一标识", isExist = false)
private String record;
......
......@@ -25,7 +25,7 @@ public interface IBizDataChangeHandleStrategy {
* 保存
*
* @param applyNo 单据编号
* @param model single, batch
* @param model @see ModelType
* @param changeData 变更数据
*/
void doSave(String applyNo, ModelType model, Map<String, Object> changeData);
......@@ -35,8 +35,11 @@ public interface IBizDataChangeHandleStrategy {
* 单据方式:单个处理、批量处理
*/
enum ModelType {
single,
batch
singleProject,
batchProject,
singleEquip,
batchEquip,
batchCylinder
}
String DEFAULT_VALUE = "default";
......
......@@ -15,7 +15,7 @@ import java.util.Optional;
* @author Administrator
*/
@Component
public class DataProcessStrategyContext implements ApplicationContextAware {
public class EquipDataProcessStrategyContext implements ApplicationContextAware {
private static final Map<IBizDataChangeHandleStrategy.ModelType, IChangeDataProcessStrategy> dataProcessStrategyHashMap = new HashMap<>();
......
......@@ -5,12 +5,14 @@ import com.yeejoin.amos.boot.module.jg.api.service.IBizDataChangeHandleStrategy;
import com.yeejoin.amos.boot.module.jg.biz.service.impl.BizDataChangeServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import javax.validation.constraints.NotBlank;
import java.util.Map;
@RestController
......@@ -27,7 +29,7 @@ public class BizDataChangeController {
@TycloudOperation(ApiLevel = UserType.AGENCY)
@PostMapping(value = "/{bizType}/save")
@ApiOperation(value = "业务数据变更保存", httpMethod = "POST")
@ApiOperation(value = "业务数据变更保存--西安专用", httpMethod = "POST")
public ResponseModel<String> save(@RequestParam String applyNo,
@PathVariable String bizType,
@RequestBody RequestChangeData changeData) {
......@@ -45,4 +47,17 @@ public class BizDataChangeController {
@RequestParam(required = false) String bizId) {
return ResponseHelper.buildResponse(bizDataChangeService.queryDetail(applyNo, bizType, model, bizId));
}
@TycloudOperation(ApiLevel = UserType.AGENCY)
@PostMapping(value = "/v2/{bizType}/save")
@ApiOperation(value = "编辑保存", httpMethod = "POST")
public ResponseModel<String> saveV2(@ApiParam(required = true, value = "单据编号") @RequestParam String applyNo,
@ApiParam(required = true, value = "业务类型")@PathVariable String bizType,
@RequestBody RequestChangeData changeData) {
// 基础数据校验
changeData.validated();
bizDataChangeService.save(applyNo, bizType, changeData);
return ResponseHelper.buildResponse("success");
}
}
......@@ -7,22 +7,19 @@ import java.util.List;
import java.util.Map;
/**
* 事件处理监听器,将前端数据解析为java对象格式
* 处理监策略类
*/
public interface IChangeDataProcessStrategy {
/**
* 事件处理
* 处理
*/
List<ChangeDataDto> handle(Map<String, Object> changeData, String defaultChangeId);
Map<String, Object> getDetail(String applyNo, String bizId);
/**
* 可处理类型
*
* @return 可处理的事件
* @return 可处理的类型
*/
IBizDataChangeHandleStrategy.ModelType canHandleMode();
}
package com.yeejoin.amos.boot.module.jg.biz.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.boot.module.jg.api.dto.*;
import com.yeejoin.amos.boot.module.jg.api.service.IBizDataChangeHandleStrategy;
import com.yeejoin.amos.boot.module.jg.biz.service.IChangeDataProcessStrategy;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* 批量维护气瓶-策略实现类
*/
@Component
public class BatchCylinderDataChangeProcessStrategy implements IChangeDataProcessStrategy {
private final CommonEquipDataProcessService commonEquipDataProcessService;
public BatchCylinderDataChangeProcessStrategy(CommonEquipDataProcessService commonEquipDataProcessService) {
this.commonEquipDataProcessService = commonEquipDataProcessService;
}
@Override
public List<ChangeDataDto> handle(Map<String, Object> changeData, String defaultChangeId) {
JSONObject data = (JSONObject) changeData;
JSONArray equips = data.getJSONArray(RequestChangeData.multiDataKey);
List<ChangeDataDto> allChangeColumns = new ArrayList<>();
List<MultiChangeItemData> items = equips.toJavaList(MultiChangeItemData.class);
// 校验
items.forEach(item -> {
String record = item.getRecord();
Map<String, Object> itemData = item.getDetail();
if (itemData != null) {
EquipRegisterChangeDataDto registerChangeDataDto = commonEquipDataProcessService.castMap2Bean(itemData, EquipRegisterChangeDataDto.class);
EquipFactoryChangeDataDto factoryChangeDataDto = commonEquipDataProcessService.castMap2Bean(itemData, EquipFactoryChangeDataDto.class);
EquipDesignChangeDataDto designChangeDataDto = commonEquipDataProcessService.castMap2Bean(itemData, EquipDesignChangeDataDto.class);
// 前置检验
commonEquipDataProcessService.checkValidField(record, registerChangeDataDto, null, null, null);
commonEquipDataProcessService.checkValidField(record, factoryChangeDataDto, registerChangeDataDto.getEquList(), registerChangeDataDto.getEquCategory(), registerChangeDataDto.getEquDefine());
commonEquipDataProcessService.checkValidField(record, designChangeDataDto, registerChangeDataDto.getEquList(), registerChangeDataDto.getEquCategory(), registerChangeDataDto.getEquDefine());
}
});
// 入库
items.forEach(item -> {
String record = item.getRecord();
Map<String, Object> itemData = item.getDetail();
if (itemData != null) {
EquipRegisterChangeDataDto registerChangeDataDto = commonEquipDataProcessService.castMap2Bean(itemData, EquipRegisterChangeDataDto.class);
EquipFactoryChangeDataDto factoryChangeDataDto = commonEquipDataProcessService.castMap2Bean(itemData, EquipFactoryChangeDataDto.class);
EquipDesignChangeDataDto designChangeDataDto = commonEquipDataProcessService.castMap2Bean(itemData, EquipDesignChangeDataDto.class);
commonEquipDataProcessService.buildChangeFields(record, designChangeDataDto, factoryChangeDataDto, registerChangeDataDto, allChangeColumns);
// 设备制造、设计、注册信息业务处理落库
commonEquipDataProcessService.dealBizDataForEquip(record, registerChangeDataDto);
commonEquipDataProcessService.dealBizDataForEquip(record, factoryChangeDataDto);
commonEquipDataProcessService.dealBizDataForEquip(record, designChangeDataDto);
// 设备技术参数入库处理
commonEquipDataProcessService.updateTechParamInfo(registerChangeDataDto, record, itemData, allChangeColumns);
}
});
return allChangeColumns;
}
// private void updateUseRegisterProjectInfo(JgUseRegistration jgUseRegistration, ProjectContraptionChangeDataDto projectContraptionChangeDataDto) {
// LambdaUpdateWrapper<JgUseRegistration> updateWrapper = new LambdaUpdateWrapper<>();
// updateWrapper.eq(JgUseRegistration::getSequenceNbr, jgUseRegistration.getSequenceNbr());
// updateWrapper.set(JgUseRegistration::getProjectContraption, projectContraptionChangeDataDto.getProjectContraption());
// useRegistrationService.update(null, updateWrapper);
// }
//
// private void calTotalPieLineLength(ProjectContraptionChangeDataDto projectContraptionChangeDataDto, List<PipelineChangeItemDto> items) {
// projectContraptionChangeDataDto.setPipelineLength(items.stream().filter(i -> i.getPipeLength() != null).mapToDouble(TechParamsPipelineChangeFieldDto::getPipeLength).sum());
// }
// public Map<String, Object> getDetail(String applyNo, String bizId) {
// Map<String, Object> result = new HashMap<>();
// JgUseRegistration jgUseRegistration = useRegistrationService.getOne(new LambdaQueryWrapper<JgUseRegistration>()
// .eq(JgUseRegistration::getApplyNo, applyNo).select(BaseEntity::getSequenceNbr, JgUseRegistration::getProjectContraptionId));
// LambdaQueryWrapper<JgUseRegistrationEq> lambda = new QueryWrapper<JgUseRegistrationEq>().lambda();
// lambda.eq(JgUseRegistrationEq::getEquipTransferId, jgUseRegistration.getSequenceNbr());
// lambda.select(JgUseRegistrationEq::getEquId);
// List<JgUseRegistrationEq> eqs = useRegistrationEqService.getBaseMapper().selectList(lambda);
// List<String> records = eqs.stream().map(JgUseRegistrationEq::getEquId).collect(toList());
// IdxBizJgRegisterInfo registerInfo = useRegistrationService.getRegisterInfo(jgUseRegistration);
// List<Map<String, Object>> tableData;
// if (EquipmentClassifityEnum.YLGD.getCode().equals(registerInfo.getEquList())){
// IdxBizJgProjectContraption idxBizJgProjectContraption = idxBizJgProjectContraptionService.getById(jgUseRegistration.getProjectContraptionId());
// Map<String, Object> map = IdxBizJgRegisterInfoServiceImpl.convertCamelToUnderscore(idxBizJgProjectContraption, IdxBizJgProjectContraptionServiceImpl.jsonFields);
// result.putAll(map);
// result.put("projectContraptionId", idxBizJgProjectContraption.getSequenceNbr());
// tableData = jgUseRegistrationMapper.queryForUnitPipelineEquipmentForEdit(records);
// } else {
// List<DictionarieValueModel> fillingMedium = Systemctl.dictionarieClient.dictValues("FILLING_MEDIUM").getResult();
// Map<String, Object> fillingMediumMap = fillingMedium.stream().collect(Collectors.toMap(DictionarieValueModel::getDictDataKey, DictionarieValueModel::getDictDataValue));
// tableData = jgUseRegistrationMapper.queryForUnitVesselEquipment(records);
// tableData.forEach(i -> i.put("chargingMedium", fillingMediumMap.get(i.get("chargingMedium"))));
// }
// result.put("tableData", tableData);
// return result;
// }
// private Map<String, Object> cast2UnderCase(Map<String, Object> re) {
// // 由于历史遗留问题,和前端保存统一,要转成大写下滑线驼峰
// Map<String, Object> result = new HashMap<>();
// re.forEach((k, v) -> {
// result.put(CharSequenceUtil.toUnderlineCase(k).toUpperCase(), v);
// });
// return result;
// }
@Override
public IBizDataChangeHandleStrategy.ModelType canHandleMode() {
return IBizDataChangeHandleStrategy.ModelType.batchCylinder;
}
}
package com.yeejoin.amos.boot.module.jg.biz.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.boot.module.jg.api.dto.*;
import com.yeejoin.amos.boot.module.jg.api.service.IBizDataChangeHandleStrategy;
import com.yeejoin.amos.boot.module.jg.biz.service.IChangeDataProcessStrategy;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* 批量维护设备-策略实现类
*/
@Component
public class BatchEquipDataChangeProcessStrategy implements IChangeDataProcessStrategy {
private final CommonEquipDataProcessService commonEquipDataProcessService;
public BatchEquipDataChangeProcessStrategy(CommonEquipDataProcessService commonEquipDataProcessService) {
this.commonEquipDataProcessService = commonEquipDataProcessService;
}
@Override
public List<ChangeDataDto> handle(Map<String, Object> changeData, String defaultChangeId) {
JSONObject data = (JSONObject) changeData;
JSONArray equips = data.getJSONArray(RequestChangeData.multiDataKey);
List<ChangeDataDto> allChangeColumns = new ArrayList<>();
List<MultiChangeItemData> items = equips.toJavaList(MultiChangeItemData.class);
// 校验
items.forEach(item -> {
String record = item.getRecord();
Map<String, Object> itemData = item.getDetail();
if (itemData != null) {
EquipRegisterChangeDataDto registerChangeDataDto = commonEquipDataProcessService.castMap2Bean(itemData, EquipRegisterChangeDataDto.class);
EquipFactoryChangeDataDto factoryChangeDataDto = commonEquipDataProcessService.castMap2Bean(itemData, EquipFactoryChangeDataDto.class);
EquipDesignChangeDataDto designChangeDataDto = commonEquipDataProcessService.castMap2Bean(itemData, EquipDesignChangeDataDto.class);
// 前置检验
commonEquipDataProcessService.checkValidField(record, registerChangeDataDto, null, null, null);
commonEquipDataProcessService.checkValidField(record, factoryChangeDataDto, registerChangeDataDto.getEquList(), registerChangeDataDto.getEquCategory(), registerChangeDataDto.getEquDefine());
commonEquipDataProcessService.checkValidField(record, designChangeDataDto, registerChangeDataDto.getEquList(), registerChangeDataDto.getEquCategory(), registerChangeDataDto.getEquDefine());
}
});
// 入库
items.forEach(item -> {
String record = item.getRecord();
Map<String, Object> itemData = item.getDetail();
if (itemData != null) {
EquipRegisterChangeDataDto registerChangeDataDto = commonEquipDataProcessService.castMap2Bean(itemData, EquipRegisterChangeDataDto.class);
EquipFactoryChangeDataDto factoryChangeDataDto = commonEquipDataProcessService.castMap2Bean(itemData, EquipFactoryChangeDataDto.class);
EquipDesignChangeDataDto designChangeDataDto = commonEquipDataProcessService.castMap2Bean(itemData, EquipDesignChangeDataDto.class);
commonEquipDataProcessService.buildChangeFields(record, designChangeDataDto, factoryChangeDataDto, registerChangeDataDto, allChangeColumns);
// 设备制造、设计、注册信息业务处理落库
commonEquipDataProcessService.dealBizDataForEquip(record, registerChangeDataDto);
commonEquipDataProcessService.dealBizDataForEquip(record, factoryChangeDataDto);
commonEquipDataProcessService.dealBizDataForEquip(record, designChangeDataDto);
// 设备技术参数入库处理
commonEquipDataProcessService.updateTechParamInfo(registerChangeDataDto, record, itemData, allChangeColumns);
}
});
return allChangeColumns;
}
@Override
public IBizDataChangeHandleStrategy.ModelType canHandleMode() {
return IBizDataChangeHandleStrategy.ModelType.batchEquip;
}
}
package com.yeejoin.amos.boot.module.jg.biz.service.impl;
import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.boot.module.jg.api.dto.*;
import com.yeejoin.amos.boot.module.jg.api.service.IBizDataChangeHandleStrategy;
import com.yeejoin.amos.boot.module.jg.biz.service.IChangeDataProcessStrategy;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* 批量维护装置及下属管道-策略实现类
*/
@Component
@RequiredArgsConstructor
public class BatchProjectDataChangeProcessStrategy implements IChangeDataProcessStrategy {
private final CommonEquipDataProcessService commonEquipDataProcessService;
private final PieLineDataChangeServiceImpl pieLineDataChangeService;
@Override
public List<ChangeDataDto> handle(Map<String, Object> changeData, String defaultChangeId) {
JSONObject data = (JSONObject) changeData;
JSONArray projectContraptions = data.getJSONArray(RequestChangeData.multiDataKey);
List<ChangeDataDto> allChangeColumns = new ArrayList<>();
// 装置列表
List<ProjectContraptionChangeItem> projectContraptionsJavaList = projectContraptions.toJavaList(ProjectContraptionChangeItem.class);
// 入库前校验
projectContraptionsJavaList.forEach(item -> {
Map<String, Object> itemData = item.getDetail();
if (itemData != null) {
JSONObject changeJson = (JSONObject) itemData;
JSONArray equips = changeJson.getJSONArray(RequestChangeData.multiDataKey);
List<PipelineChangeItemDto> items = equips.toJavaList(PipelineChangeItemDto.class);
// 1.设备技术参数入库前校验,约束:同一个装置下的管道编号不能重复
if (items.size() != items.stream().map(TechParamsPipelineChangeFieldDto::getPipelineNumber).distinct().count()) {
throw new BadRequest("同一工程装置下管道编号不能重复!");
}
}
});
// 入库
projectContraptionsJavaList.forEach(item -> {
// todo 依赖前端组件
String projectContraptionId = item.getProjectContraptionId();
Map<String, Object> itemData = item.getDetail();
if (itemData != null) {
JSONObject changeJson = (JSONObject) itemData;
// 删除的删除--------------------deleteData
// 新增编辑的管道insert和edit------tableData
JSONArray insertOrEditPieLines = changeJson.getJSONArray(RequestChangeData.multiDataKey);
JSONArray deletedPieLines = changeJson.getJSONArray(RequestChangeData.deletedDataKey);
if(deletedPieLines != null && !deletedPieLines.isEmpty()) {
List<PipelineChangeItemDto> deletedPieLinesJavaList = deletedPieLines.toJavaList(PipelineChangeItemDto.class);
pieLineDataChangeService.deletePieLineBatch(deletedPieLinesJavaList, allChangeColumns, defaultChangeId);
}
List<PipelineChangeItemDto> items = insertOrEditPieLines.toJavaList(PipelineChangeItemDto.class);
// 1.保存(前端返回的装置信息为大写 需注意)
ProjectContraptionChangeDataDto projectContraptionChangeDataDto = commonEquipDataProcessService.castMap2Bean(itemData, ProjectContraptionChangeDataDto.class);
projectContraptionChangeDataDto.setProjectContraptionId(projectContraptionId);
this.calTotalPieLineLength(projectContraptionChangeDataDto, items);
pieLineDataChangeService.update(projectContraptionChangeDataDto, allChangeColumns);
// 2.管道信息入库保存
items.forEach(it -> {
String record = it.getRecord();
if(record == null) { // 新增的管道逻辑
this.newPieLine(projectContraptionId, it, allChangeColumns, defaultChangeId);
} else { // 更新逻辑
// 设计信息更新
pieLineDataChangeService.saveDesignForPieLine(record, allChangeColumns, it);
// 技术参数入库保存
TechParamsPipelineChangeFieldDto paramsPipelineChangeFieldDto = new TechParamsPipelineChangeFieldDto();
BeanUtil.copyProperties(it, paramsPipelineChangeFieldDto, false);
commonEquipDataProcessService.savePieLineTechParam(record, allChangeColumns, paramsPipelineChangeFieldDto);
}
});
// 4.更新所有管道的的冗余的管道名称字段(重点注意包括本次没做使用登记的管道也要更新)
pieLineDataChangeService.updateEs(projectContraptionChangeDataDto);
}
});
return allChangeColumns;
}
private void newPieLine(String projectContraptionId, PipelineChangeItemDto it, List<ChangeDataDto> allChangeColumns, String applyNo) {
// todo 创建管道的设备几张表
// todo 创建道的es
// todo 构建变更流水 beforeData = null
}
private void calTotalPieLineLength(ProjectContraptionChangeDataDto projectContraptionChangeDataDto, List<PipelineChangeItemDto> items) {
projectContraptionChangeDataDto.setPipelineLength(items.stream().filter(i -> i.getPipeLength() != null).mapToDouble(TechParamsPipelineChangeFieldDto::getPipeLength).sum());
}
@Override
public IBizDataChangeHandleStrategy.ModelType canHandleMode() {
return IBizDataChangeHandleStrategy.ModelType.batchProject;
}
}
......@@ -56,6 +56,8 @@ public class CommonEquipDataProcessService {
private final IdxBizJgUseInfoServiceImpl idxBizJgUseInfoService;
private final JgUseRegistrationServiceImpl jgUseRegistrationService;
private final List<String> jsonFields = new ArrayList<>();
......@@ -138,9 +140,9 @@ public class CommonEquipDataProcessService {
void buildChangeFields(String record, EquipDesignChangeDataDto equipDesignChangeDataDto, EquipFactoryChangeDataDto equipFactoryChangeDataDto, EquipRegisterChangeDataDto registerChangeDataDto, List<ChangeDataDto> allChangeColumns) {
// 构造新对象行转列
List<ChangeDataDto> designInfoNew = this.buildDesignInfoNew(equipDesignChangeDataDto, record);
List<ChangeDataDto> factoryInfoNew = this.buildFactoryInfoNew(equipFactoryChangeDataDto, record);
List<ChangeDataDto> registerInfoNew = this.buildRegisterInfoNew(registerChangeDataDto, record);
List<ChangeDataDto> designInfoNew = this.convertBeanField2Column2(equipDesignChangeDataDto, record);
List<ChangeDataDto> factoryInfoNew = this.convertBeanField2Column2(equipFactoryChangeDataDto, record);
List<ChangeDataDto> registerInfoNew = this.convertBeanField2Column2(registerChangeDataDto, record);
// 老数据查询行转列
List<ChangeDataDto> designInfoOld = this.buildDesignInfoOld(record);
List<ChangeDataDto> factoryInfoOld = this.buildFactoryInfoOld(record);
......@@ -152,9 +154,9 @@ public class CommonEquipDataProcessService {
void buildChangeFields(String record, EquipDesignChangeDataDto equipDesignChangeDataDto, EquipFactoryChangeDataDto equipFactoryChangeDataDto, EquipRegisterChangeDataDto registerChangeDataDto, EquipUseInfoChangeDataDto useInfoChangeDataDto, List<ChangeDataDto> allChangeColumns) {
// 构造新对象行转列
List<ChangeDataDto> designInfoNew = this.buildDesignInfoNew(equipDesignChangeDataDto, record);
List<ChangeDataDto> factoryInfoNew = this.buildFactoryInfoNew(equipFactoryChangeDataDto, record);
List<ChangeDataDto> registerInfoNew = this.buildRegisterInfoNew(registerChangeDataDto, record);
List<ChangeDataDto> designInfoNew = this.convertBeanField2Column2(equipDesignChangeDataDto, record);
List<ChangeDataDto> factoryInfoNew = this.convertBeanField2Column2(equipFactoryChangeDataDto, record);
List<ChangeDataDto> registerInfoNew = this.convertBeanField2Column2(registerChangeDataDto, record);
List<ChangeDataDto> useInfoChangeNew = this.convertBeanField2Column2(useInfoChangeDataDto, record);
// 老数据查询行转列
List<ChangeDataDto> designInfoOld = this.buildDesignInfoOld(record);
......@@ -194,6 +196,11 @@ public class CommonEquipDataProcessService {
EquipUseInfoChangeDataDto equipUseInfoChangeDataDto = (EquipUseInfoChangeDataDto) changeDataDto;
equipChangeDataUpdateService.updateUseInfoChangeData(record, equipUseInfoChangeDataDto);
}
// 检验信息
if(changeDataDto instanceof EquipInspectChangeDataDto){
EquipInspectChangeDataDto equipUseInfoChangeDataDto = (EquipInspectChangeDataDto) changeDataDto;
equipChangeDataUpdateService.updateOrSaveInspectInfo(record, equipUseInfoChangeDataDto);
}
}
private String buildTableName(Class<?> clazz) {
......@@ -423,10 +430,10 @@ public class CommonEquipDataProcessService {
allChange.addAll(pipelineChangeFields);
}
public List<ChangeDataDto> convertBeanField2Column2(Object beanData, String changeId) {
public <T extends BaseChangeDataDto> List<ChangeDataDto> convertBeanField2Column2(T beanData, String changeId) {
List<ChangeDataDto> changeData = new ArrayList<>();
Group group = beanData.getClass().getAnnotation(Group.class);
Field[] fields = beanData.getClass().getDeclaredFields();
List<Field> fields = getAllFields(beanData.getClass());
for (Field field : fields) {
field.setAccessible(true);
FieldDisplayDefine displayDefine = field.getAnnotation(FieldDisplayDefine.class);
......@@ -457,17 +464,6 @@ public class CommonEquipDataProcessService {
return changeData;
}
public List<ChangeDataDto> buildDesignInfoNew(Object changeDataDto, String record) {
return this.convertBeanField2Column2(changeDataDto, record);
}
private List<ChangeDataDto> buildFactoryInfoNew(EquipFactoryChangeDataDto changeDataDto, String record) {
return this.convertBeanField2Column2(changeDataDto, record);
}
private List<ChangeDataDto> buildRegisterInfoNew(EquipRegisterChangeDataDto changeDataDto, String record) {
return this.convertBeanField2Column2(changeDataDto, record);
}
public List<ChangeDataDto> buildDesignInfoOld(String record) {
EquipDesignChangeDataDto changeDataDto = new EquipDesignChangeDataDto();
......@@ -546,4 +542,32 @@ public class CommonEquipDataProcessService {
BeanUtil.copyProperties(useInfo, changeDataDto);
return changeDataDto;
}
public void buildChangeFields(String record, EquipDesignChangeDataDto designChangeDataDto, EquipFactoryChangeDataDto factoryChangeDataDto, EquipRegisterChangeDataDto registerChangeDataDto, EquipInspectChangeDataDto inspectChangeDataDto, List<ChangeDataDto> allChangeColumns) {
this.buildChangeFields(record, designChangeDataDto, factoryChangeDataDto, registerChangeDataDto, allChangeColumns);
this.buildInspectChangeFields(record, inspectChangeDataDto, allChangeColumns);
}
public void buildInspectChangeFields(String record, EquipInspectChangeDataDto inspectChangeDataDto, List<ChangeDataDto> allChangeColumns) {
if(StringUtils.isNotEmpty(inspectChangeDataDto.getJySeq())) {
Map<String, Object> oldData = jgUseRegistrationService.getInspectDetail(inspectChangeDataDto.getJySeq());
EquipInspectChangeDataDto inspectChangeDataOld = new EquipInspectChangeDataDto();
BeanUtil.copyProperties(oldData, inspectChangeDataOld);
List<ChangeDataDto> newChangeFields = this.convertBeanField2Column2(inspectChangeDataDto, record);
List<ChangeDataDto> oldChangeFields = this.convertBeanField2Column2(inspectChangeDataOld, record);
allChangeColumns.addAll(this.mergeChangeFields(newChangeFields, oldChangeFields));
} else {
List<ChangeDataDto> newChangeFields = this.convertBeanField2Column2(inspectChangeDataDto, record);
allChangeColumns.addAll(newChangeFields);
}
}
private static List<Field> getAllFields(Class<?> clazz) {
List<Field> fields = new ArrayList<>();
while (clazz != null && clazz != Object.class) {
fields.addAll(Arrays.asList(clazz.getDeclaredFields()));
clazz = clazz.getSuperclass(); // 递归向上获取父类
}
return fields;
}
}
package com.yeejoin.amos.boot.module.jg.biz.service.impl;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.yeejoin.amos.boot.biz.common.utils.SnowflakeIdUtil;
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.*;
......@@ -11,13 +13,11 @@ import com.yeejoin.amos.boot.module.jg.api.enums.CylinderTypeEnum;
import com.yeejoin.amos.boot.module.jg.api.mapper.CommonMapper;
import com.yeejoin.amos.boot.module.ymt.api.entity.*;
import com.yeejoin.amos.boot.module.ymt.api.enums.EquCodeTypeEnum;
import com.yeejoin.amos.boot.module.ymt.api.mapper.EquipmentCategoryMapper;
import com.yeejoin.amos.boot.module.ymt.api.mapper.IdxBizJgDesignInfoMapper;
import com.yeejoin.amos.boot.module.ymt.api.mapper.IdxBizJgFactoryInfoMapper;
import com.yeejoin.amos.boot.module.ymt.api.mapper.IdxBizJgRegisterInfoMapper;
import com.yeejoin.amos.boot.module.ymt.api.mapper.*;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.typroject.tyboot.core.foundation.utils.Bean;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
import java.util.Date;
......@@ -43,6 +43,10 @@ public class EquipChangeDataUpdateService {
private final IdxBizJgUseInfoServiceImpl idxBizJgUseInfoService;
private final InspectionDetectionInfoMapper inspectionDetectionInfoMapper;
private final SnowflakeIdUtil sequence;
public void updateRegisterChangeData(String record, EquipRegisterChangeDataDto registerChangeDataDto) {
LambdaUpdateWrapper<IdxBizJgRegisterInfo> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(IdxBizJgRegisterInfo::getRecord, record);
......@@ -226,4 +230,32 @@ public class EquipChangeDataUpdateService {
esEquipmentCategory.save(esEquipmentCategoryDto);
}
}
public void updateOrSaveInspectInfo(String record, EquipInspectChangeDataDto equipUseInfoChangeDataDto) {
if (equipUseInfoChangeDataDto.getJySeq() != null) {
// 更新逻辑
InspectionDetectionInfo inspectionDetectionInfoDb = inspectionDetectionInfoMapper.selectById(equipUseInfoChangeDataDto.getJySeq());
String inspectionSeq = inspectionDetectionInfoDb.getSequenceNbr();
Bean.copyExistPropertis(equipUseInfoChangeDataDto, inspectionDetectionInfoDb);
inspectionDetectionInfoDb.setSequenceNbr(inspectionSeq);
inspectionDetectionInfoDb.setRecord(record);
inspectionDetectionInfoDb.setRecDate(new Date());
inspectionDetectionInfoMapper.updateById(inspectionDetectionInfoDb);
} else {
// 插入逻辑
InspectionDetectionInfo inspectionDetectionInfo = new InspectionDetectionInfo();
Bean.copyExistPropertis(equipUseInfoChangeDataDto, inspectionDetectionInfo);
inspectionDetectionInfo.setRecord(record);
inspectionDetectionInfo.setRecDate(new Date());
inspectionDetectionInfo.setSequenceNbr(sequence.nextId() + "");
inspectionDetectionInfoMapper.insert(inspectionDetectionInfo);
}
// es 数据更新
Optional<ESEquipmentCategoryDto> optional = esEquipmentCategory.findById(record);
if (optional.isPresent()) {
ESEquipmentCategoryDto esEquipmentCategoryDto = optional.get();
esEquipmentCategoryDto.setNEXT_INSPECT_DATE(DateUtil.parse(DateUtil.format(equipUseInfoChangeDataDto.getNextInspectDate(), DatePattern.NORM_DATE_PATTERN)).getTime());
esEquipmentCategory.save(esEquipmentCategoryDto);
}
}
}
......@@ -2373,7 +2373,7 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD
return record;
}
private Map<String, Object> getInspectDetail(String record) {
public Map<String, Object> getInspectDetail(String record) {
// 去掉约束
return this.baseMapper.getInspectDetail(record, null);
}
......
......@@ -29,7 +29,7 @@ public class PieLineDataChangeServiceImpl {
public void update(ProjectContraptionChangeDataDto projectContraptionChangeDataDtoNew, List<ChangeDataDto> allChangeColumns) {
// 原有对象行转列
ProjectContraptionChangeDataDto projectContraptionChangeDataDtoOld = getOldProjectContratData(projectContraptionChangeDataDtoNew);
ProjectContraptionChangeDataDto projectContraptionChangeDataDtoOld = getOldProjectContraptionData(projectContraptionChangeDataDtoNew);
List<ChangeDataDto> newProjectContraptionChangeData = commonEquipDataProcessService.convertBeanField2Column2(projectContraptionChangeDataDtoNew, projectContraptionChangeDataDtoNew.getProjectContraptionId());
// 新对象构造行转列
List<ChangeDataDto> oldProjectContraptionChangeData = commonEquipDataProcessService.convertBeanField2Column2(projectContraptionChangeDataDtoOld, projectContraptionChangeDataDtoNew.getProjectContraptionId());
......@@ -47,7 +47,7 @@ public class PieLineDataChangeServiceImpl {
idxBizJgProjectContraptionServiceImpl.update(null, updateWrapper);
}
private ProjectContraptionChangeDataDto getOldProjectContratData(ProjectContraptionChangeDataDto projectContraptionChangeDataDtoNew) {
private ProjectContraptionChangeDataDto getOldProjectContraptionData(ProjectContraptionChangeDataDto projectContraptionChangeDataDtoNew) {
IdxBizJgProjectContraption projectContraption = idxBizJgProjectContraptionServiceImpl.getById(projectContraptionChangeDataDtoNew.getProjectContraptionId());
return BeanUtil.copyProperties(projectContraption, ProjectContraptionChangeDataDto.class);
}
......@@ -56,7 +56,7 @@ public class PieLineDataChangeServiceImpl {
// 1.记录变化的数据对象
PieLineDesignChangeDataDto pieLineDesignChangeDataDto = BeanUtil.copyProperties(pipelineChangeItemDto, PieLineDesignChangeDataDto.class);
// 构造新对象行转列
List<ChangeDataDto> designInfoNew = commonEquipDataProcessService.buildDesignInfoNew(pieLineDesignChangeDataDto, record);
List<ChangeDataDto> designInfoNew = commonEquipDataProcessService.convertBeanField2Column2(pieLineDesignChangeDataDto, record);
// 老数据查询行转列
List<ChangeDataDto> designInfoOld = commonEquipDataProcessService.buildDesignInfoOld(record);
allChangeColumns.addAll(commonEquipDataProcessService.mergeChangeFields(designInfoNew, designInfoOld));
......@@ -67,4 +67,10 @@ public class PieLineDataChangeServiceImpl {
public void updateEs(ProjectContraptionChangeDataDto projectContraptionChangeDataDto) {
equipChangeDataUpdateService.updateRegisterEsDataPieLine(projectContraptionChangeDataDto);
}
public void deletePieLineBatch(List<PipelineChangeItemDto> deletedPieLines, List<ChangeDataDto> allChangeColumns, String applyNo) {
// todo 构建日志 allChangeColumns afterData = null
// todo 数据库管道删除
// todo es管道删除
}
}
package com.yeejoin.amos.boot.module.jg.biz.service.impl;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.yeejoin.amos.boot.biz.common.entity.BaseEntity;
import com.yeejoin.amos.boot.module.jg.api.dto.*;
import com.yeejoin.amos.boot.module.jg.api.entity.JgUseRegistration;
import com.yeejoin.amos.boot.module.jg.api.entity.JgUseRegistrationEq;
import com.yeejoin.amos.boot.module.jg.api.entity.JgUseRegistrationManage;
import com.yeejoin.amos.boot.module.jg.api.mapper.JgUseRegistrationEqMapper;
import com.yeejoin.amos.boot.module.jg.api.mapper.JgUseRegistrationManageMapper;
import com.yeejoin.amos.boot.module.jg.api.service.IBizDataChangeHandleStrategy;
import com.yeejoin.amos.boot.module.jg.biz.service.*;
import com.yeejoin.amos.boot.module.ymt.api.entity.EquipmentCategory;
import com.yeejoin.amos.boot.module.ymt.api.enums.FlowStatusEnum;
import com.yeejoin.amos.boot.module.ymt.api.mapper.EquipmentCategoryMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
import java.util.*;
/**
* 单个维护使用登记策略实现类
*/
@Component
public class SingleDataChangeProcessStrategy implements IChangeDataProcessStrategy {
private final JgUseRegistrationServiceImpl useRegistrationService;
private final JgUseRegistrationEqMapper jgRelationEquipMapper;
private final CommonEquipDataProcessService commonEquipDataProcessService;
private final JgUseRegistrationManageMapper registrationManageMapper;
private final EquipmentCategoryMapper equipmentCategoryMapper;
public SingleDataChangeProcessStrategy( JgUseRegistrationServiceImpl useRegistrationService, JgUseRegistrationEqMapper jgRelationEquipMapper, CommonEquipDataProcessService commonEquipDataProcessService, JgUseRegistrationManageMapper registrationManageMapper, EquipmentCategoryMapper equipmentCategoryMapper) {
this.useRegistrationService = useRegistrationService;
this.jgRelationEquipMapper = jgRelationEquipMapper;
this.commonEquipDataProcessService = commonEquipDataProcessService;
this.registrationManageMapper = registrationManageMapper;
this.equipmentCategoryMapper = equipmentCategoryMapper;
}
@Override
public List<ChangeDataDto> handle(Map<String, Object> changeData, String defaultChangeId) {
String record = this.getRecord(defaultChangeId);
List<ChangeDataDto> allChangeColumns = new ArrayList<>();
// 新数据解析
EquipRegisterChangeDataDto registerChangeDataDto = commonEquipDataProcessService.castMap2Bean(changeData, EquipRegisterChangeDataDto.class);
EquipFactoryChangeDataDto factoryChangeDataDto = commonEquipDataProcessService.castMap2Bean(changeData, EquipFactoryChangeDataDto.class);
EquipDesignChangeDataDto designChangeDataDto = commonEquipDataProcessService.castMap2Bean(changeData, EquipDesignChangeDataDto.class);
commonEquipDataProcessService.buildChangeFields(record, designChangeDataDto, factoryChangeDataDto, registerChangeDataDto, allChangeColumns);
// 前置校验
commonEquipDataProcessService.checkValidField(record, registerChangeDataDto, null, null, null);
commonEquipDataProcessService.checkValidField(record, factoryChangeDataDto, registerChangeDataDto.getEquList(), registerChangeDataDto.getEquCategory(), registerChangeDataDto.getEquDefine());
commonEquipDataProcessService.checkValidField(record, designChangeDataDto, registerChangeDataDto.getEquList(), registerChangeDataDto.getEquCategory(), registerChangeDataDto.getEquDefine());
// 设备制造、设计、注册信息业务处理落库
commonEquipDataProcessService.dealBizDataForEquip(record, registerChangeDataDto);
commonEquipDataProcessService.dealBizDataForEquip(record, factoryChangeDataDto);
commonEquipDataProcessService.dealBizDataForEquip(record, designChangeDataDto);
// 设备技术参数入库处理
commonEquipDataProcessService.updateTechParamInfo(registerChangeDataDto, record, changeData, allChangeColumns);
// 更新单据对应的证信息
this.updateManagerCertInfo(defaultChangeId, record, registerChangeDataDto);
return allChangeColumns;
}
private void updateManagerCertInfo(String applyNo, String record, EquipRegisterChangeDataDto registerChangeDataDto) {
JgUseRegistration jgUseRegistration = useRegistrationService.getOne(new LambdaQueryWrapper<JgUseRegistration>()
.eq(JgUseRegistration::getApplyNo, applyNo).select(BaseEntity::getSequenceNbr, JgUseRegistration::getStatus, JgUseRegistration::getUseRegistrationCode));
if (FlowStatusEnum.TO_BE_FINISHED.getName().equals(jgUseRegistration.getStatus())) {
LambdaQueryWrapper<JgUseRegistrationManage> queryWrapper = new LambdaQueryWrapper<JgUseRegistrationManage>()
.eq(JgUseRegistrationManage::getUseRegistrationCode, jgUseRegistration.getUseRegistrationCode())
.eq(JgUseRegistrationManage::getIsDelete, 0).select(BaseEntity::getSequenceNbr,JgUseRegistrationManage::getVersion);
JgUseRegistrationManage jgUseRegistrationManage = registrationManageMapper.selectOne(queryWrapper);
if (jgUseRegistrationManage != null && !StringUtils.equals(jgUseRegistrationManage.getEquDefineCode(), registerChangeDataDto.getEquDefine())) {
LambdaUpdateWrapper<JgUseRegistrationManage> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(BaseEntity::getSequenceNbr, jgUseRegistrationManage.getSequenceNbr());
if (StringUtils.isNotEmpty(registerChangeDataDto.getEquDefine())) {
EquipmentCategory equipmentCategory = getEquipmentCategory(registerChangeDataDto);
updateWrapper.set(JgUseRegistrationManage::getEquDefineCode, registerChangeDataDto.getEquDefine());
updateWrapper.set(JgUseRegistrationManage::getEquDefine, equipmentCategory.getName());
} else {
updateWrapper.set(JgUseRegistrationManage::getEquDefineCode, null);
updateWrapper.set(JgUseRegistrationManage::getEquDefine, null);
}
updateWrapper.set(JgUseRegistrationManage::getVersion, jgUseRegistrationManage.getVersion() + 1);
updateWrapper.set(JgUseRegistrationManage::getRecDate, new Date());
updateWrapper.set(JgUseRegistrationManage::getChangeReason, "设备信息变更");
registrationManageMapper.update(null, updateWrapper);
}
}
}
private EquipmentCategory getEquipmentCategory(EquipRegisterChangeDataDto registerChangeDataDto) {
return equipmentCategoryMapper.selectOne(new LambdaQueryWrapper<EquipmentCategory>().eq(EquipmentCategory::getCode, registerChangeDataDto.getEquDefine()));
}
@Override
public Map<String, Object> getDetail(String applyNo, String bizId) {
if (StringUtils.isEmpty(applyNo) && StringUtils.isEmpty(bizId)) {
throw new BadRequest("applyNo and bizId can't be empty");
}
if (StringUtils.isNotEmpty(applyNo)) {
return this.getDetailByApplyNo(applyNo);
} else {
return this.getDetailByBizId(bizId);
}
}
private Map<String, Object> getDetailByBizId(String record) {
Map<String, Object> re = new HashMap<>();
// 注册信息(基本信息)构建
EquipRegisterChangeDataDto equipRegisterChangeDataDto = commonEquipDataProcessService.buildRegisterInfo(record);
// 制造信息构建
EquipFactoryChangeDataDto factoryChangeDataDto = commonEquipDataProcessService.buildFactoryInfo(record);
// 设计信息构建
EquipDesignChangeDataDto designChangeDataDto = commonEquipDataProcessService.buildDesignInfo(record);
// 技术参数构建
BaseTechParamsFieldDto techParamsFieldDto = commonEquipDataProcessService.buildTechParamInfo(equipRegisterChangeDataDto, record);
re.putAll(BeanUtil.beanToMap(equipRegisterChangeDataDto));
re.putAll(BeanUtil.beanToMap(factoryChangeDataDto));
re.putAll(BeanUtil.beanToMap(designChangeDataDto));
re.putAll(BeanUtil.beanToMap(techParamsFieldDto));
commonEquipDataProcessService.castJsonFields(re);
return commonEquipDataProcessService.cast2UnderCase(re);
}
public Map<String, Object> getDetailByApplyNo(String bizId) {
String record = this.getRecord(bizId);
return getDetailByBizId(record);
}
public String getRecord(String applyNo) {
JgUseRegistration jgUseRegistration = useRegistrationService.getOne(new LambdaQueryWrapper<JgUseRegistration>()
.eq(JgUseRegistration::getApplyNo, applyNo).select(BaseEntity::getSequenceNbr));
LambdaQueryWrapper<JgUseRegistrationEq> eq = new QueryWrapper<JgUseRegistrationEq>().lambda()
.eq(JgUseRegistrationEq::getEquipTransferId, jgUseRegistration.getSequenceNbr())
.eq(JgUseRegistrationEq::getIsDelete, false).select(JgUseRegistrationEq::getEquId);
JgUseRegistrationEq jgUseRegistrationEq = jgRelationEquipMapper.selectOne(eq);
return jgUseRegistrationEq.getEquId();
}
@Override
public IBizDataChangeHandleStrategy.ModelType canHandleMode() {
return IBizDataChangeHandleStrategy.ModelType.single;
}
}
package com.yeejoin.amos.boot.module.jg.biz.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yeejoin.amos.boot.biz.common.entity.BaseEntity;
import com.yeejoin.amos.boot.module.jg.api.dto.ChangeDataDto;
import com.yeejoin.amos.boot.module.jg.api.dto.EquipDesignChangeDataDto;
import com.yeejoin.amos.boot.module.jg.api.dto.EquipFactoryChangeDataDto;
import com.yeejoin.amos.boot.module.jg.api.dto.EquipRegisterChangeDataDto;
import com.yeejoin.amos.boot.module.jg.api.entity.JgUseRegistration;
import com.yeejoin.amos.boot.module.jg.api.entity.JgUseRegistrationEq;
import com.yeejoin.amos.boot.module.jg.api.mapper.JgUseRegistrationEqMapper;
import com.yeejoin.amos.boot.module.jg.api.service.IBizDataChangeHandleStrategy;
import com.yeejoin.amos.boot.module.jg.biz.service.IChangeDataProcessStrategy;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* 单个维护设备-策略实现类
*/
@Component
public class SingleEquipChangeProcessStrategy implements IChangeDataProcessStrategy {
private final JgUseRegistrationServiceImpl useRegistrationService;
private final JgUseRegistrationEqMapper jgRelationEquipMapper;
private final CommonEquipDataProcessService commonEquipDataProcessService;
public SingleEquipChangeProcessStrategy(JgUseRegistrationServiceImpl useRegistrationService, JgUseRegistrationEqMapper jgRelationEquipMapper, CommonEquipDataProcessService commonEquipDataProcessService) {
this.useRegistrationService = useRegistrationService;
this.jgRelationEquipMapper = jgRelationEquipMapper;
this.commonEquipDataProcessService = commonEquipDataProcessService;
}
@Override
public List<ChangeDataDto> handle(Map<String, Object> changeData, String defaultChangeId) {
String record = this.getRecord(defaultChangeId);
List<ChangeDataDto> allChangeColumns = new ArrayList<>();
// 新数据解析
EquipRegisterChangeDataDto registerChangeDataDto = commonEquipDataProcessService.castMap2Bean(changeData, EquipRegisterChangeDataDto.class);
EquipFactoryChangeDataDto factoryChangeDataDto = commonEquipDataProcessService.castMap2Bean(changeData, EquipFactoryChangeDataDto.class);
EquipDesignChangeDataDto designChangeDataDto = commonEquipDataProcessService.castMap2Bean(changeData, EquipDesignChangeDataDto.class);
commonEquipDataProcessService.buildChangeFields(record, designChangeDataDto, factoryChangeDataDto, registerChangeDataDto, allChangeColumns);
// 前置校验
commonEquipDataProcessService.checkValidField(record, registerChangeDataDto, null, null, null);
commonEquipDataProcessService.checkValidField(record, factoryChangeDataDto, registerChangeDataDto.getEquList(), registerChangeDataDto.getEquCategory(), registerChangeDataDto.getEquDefine());
commonEquipDataProcessService.checkValidField(record, designChangeDataDto, registerChangeDataDto.getEquList(), registerChangeDataDto.getEquCategory(), registerChangeDataDto.getEquDefine());
// 设备制造、设计、注册信息业务处理落库
commonEquipDataProcessService.dealBizDataForEquip(record, registerChangeDataDto);
commonEquipDataProcessService.dealBizDataForEquip(record, factoryChangeDataDto);
commonEquipDataProcessService.dealBizDataForEquip(record, designChangeDataDto);
// 设备技术参数入库处理
commonEquipDataProcessService.updateTechParamInfo(registerChangeDataDto, record, changeData, allChangeColumns);
return allChangeColumns;
}
public String getRecord(String applyNo) {
JgUseRegistration jgUseRegistration = useRegistrationService.getOne(new LambdaQueryWrapper<JgUseRegistration>()
.eq(JgUseRegistration::getApplyNo, applyNo).select(BaseEntity::getSequenceNbr));
LambdaQueryWrapper<JgUseRegistrationEq> eq = new QueryWrapper<JgUseRegistrationEq>().lambda()
.eq(JgUseRegistrationEq::getEquipTransferId, jgUseRegistration.getSequenceNbr())
.eq(JgUseRegistrationEq::getIsDelete, false).select(JgUseRegistrationEq::getEquId);
JgUseRegistrationEq jgUseRegistrationEq = jgRelationEquipMapper.selectOne(eq);
return jgUseRegistrationEq.getEquId();
}
@Override
public IBizDataChangeHandleStrategy.ModelType canHandleMode() {
return IBizDataChangeHandleStrategy.ModelType.singleEquip;
}
}
package com.yeejoin.amos.boot.module.jg.biz.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.text.CharSequenceUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.boot.module.jg.api.dto.*;
import com.yeejoin.amos.boot.module.jg.api.service.IBizDataChangeHandleStrategy;
import com.yeejoin.amos.boot.module.jg.biz.service.IChangeDataProcessStrategy;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 单个装置维护-策略实现类
*/
@Component
@RequiredArgsConstructor
public class SingleProjectDataChangeProcessStrategy implements IChangeDataProcessStrategy {
private final CommonEquipDataProcessService commonEquipDataProcessService;
private final PieLineDataChangeServiceImpl pieLineDataChangeService;
@Override
public List<ChangeDataDto> handle(Map<String, Object> changeData, String defaultChangeId) {
JSONObject data = (JSONObject) changeData;
JSONArray equips = data.getJSONArray(RequestChangeData.multiDataKey);
List<ChangeDataDto> allChangeColumns = new ArrayList<>();
List<PipelineChangeItemDto> items = equips.toJavaList(PipelineChangeItemDto.class);
// 1.设备技术参数入库前校验,约束:同一个装置下的管道编号不能重复
if (items.size() != items.stream().map(TechParamsPipelineChangeFieldDto::getPipelineNumber).distinct().count()) {
throw new BadRequest("同一工程装置下管道编号不能重复!");
}
// 2.装置基本信息校验、保存(前端返回的装置信息为大写 需注意)
ProjectContraptionChangeDataDto projectContraptionChangeDataDto = commonEquipDataProcessService.castMap2Bean(changeData, ProjectContraptionChangeDataDto.class);
this.calTotalPieLineLength(projectContraptionChangeDataDto, items);
pieLineDataChangeService.update(projectContraptionChangeDataDto, allChangeColumns);
// 3.管道信息入库保存
items.forEach(item -> {
String record = item.getRecord();
// 设计信息更新
pieLineDataChangeService.saveDesignForPieLine(record, allChangeColumns, item);
// 技术参数入库保存
TechParamsPipelineChangeFieldDto paramsPipelineChangeFieldDto = new TechParamsPipelineChangeFieldDto();
BeanUtil.copyProperties(item, paramsPipelineChangeFieldDto, false);
commonEquipDataProcessService.savePieLineTechParam(record, allChangeColumns, paramsPipelineChangeFieldDto);
});
// 4.更新所有管道的的冗余的管道名称字段(重点注意包括本次没做使用登记的管道也要更新)
pieLineDataChangeService.updateEs(projectContraptionChangeDataDto);
return allChangeColumns;
}
private void calTotalPieLineLength(ProjectContraptionChangeDataDto projectContraptionChangeDataDto, List<PipelineChangeItemDto> items) {
projectContraptionChangeDataDto.setPipelineLength(items.stream().filter(i -> i.getPipeLength() != null).mapToDouble(TechParamsPipelineChangeFieldDto::getPipeLength).sum());
}
private Map<String, Object> cast2UnderCase(Map<String, Object> re) {
// 由于历史遗留问题,和前端保存统一,要转成大写下滑线驼峰
Map<String, Object> result = new HashMap<>();
re.forEach((k, v) -> {
result.put(CharSequenceUtil.toUnderlineCase(k).toUpperCase(), v);
});
return result;
}
@Override
public IBizDataChangeHandleStrategy.ModelType canHandleMode() {
return IBizDataChangeHandleStrategy.ModelType.singleProject;
}
}
package com.yeejoin.amos.boot.module.jg.biz.service.impl;
import com.yeejoin.amos.boot.module.jg.api.dto.ChangeDataDto;
import cn.hutool.core.bean.BeanUtil;
import com.yeejoin.amos.boot.module.jg.api.dto.*;
import com.yeejoin.amos.boot.module.jg.api.service.IBizDataChangeHandleStrategy;
import com.yeejoin.amos.boot.module.jg.biz.context.DataProcessStrategyContext;
import com.yeejoin.amos.boot.module.jg.biz.context.EquipDataProcessStrategyContext;
import com.yeejoin.amos.boot.module.jg.biz.event.ChangeDataEvent;
import com.yeejoin.amos.boot.module.jg.biz.event.publisher.EventPublisher;
import com.yeejoin.amos.boot.module.jg.biz.service.IChangeDataProcessStrategy;
......@@ -10,6 +11,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -22,6 +24,7 @@ public class UseRegisterDataChangeHandleImpl implements IBizDataChangeHandleStra
private final UseRegisterUpdateService useRegisterUpdateService;
public UseRegisterDataChangeHandleImpl(EventPublisher publisher, UseRegisterUpdateService useRegisterUpdateService) {
this.publisher = publisher;
this.useRegisterUpdateService = useRegisterUpdateService;
......@@ -44,14 +47,19 @@ public class UseRegisterDataChangeHandleImpl implements IBizDataChangeHandleStra
@Override
@Transactional(rollbackFor = Exception.class)
public void doSave(String applyNo, ModelType model, Map<String, Object> changeData) {
// 1.根据任务状态进行单据数据的处理
// 1.1 流程中,不更业务相关字段,只更新设备
// 1.2 已完成,更新证相关、批量方式的设备公共字段信息
// 选择是台套、还是单位办理的方式,进行分类数据的解析
IChangeDataProcessStrategy dataProcessor = DataProcessStrategyContext.getStrategy(model);
IChangeDataProcessStrategy dataProcessor = EquipDataProcessStrategyContext.getStrategy(model);
List<ChangeDataDto> allChangeColumns = dataProcessor.handle(changeData, applyNo);
if (!allChangeColumns.isEmpty()) {
// todo 数据库记录此次流水主键和es的batchId关联
// 更新历史的JSON的数据
this.updateHistoryJson(applyNo);
this.buildLogData(allChangeColumns);
// 异步记录日志
// todo activeMQ 发送数据变更(业务+设备records)消息,已单据维度发送(观察者模式)
// todo activeMQ 异步记录日志--保证可靠
publisher.publish(new ChangeDataEvent(this, allChangeColumns, RequestContext.cloneRequestContext()));
}
}
......@@ -69,9 +77,59 @@ public class UseRegisterDataChangeHandleImpl implements IBizDataChangeHandleStra
@Override
public Map<String, ?> getDetail(String applyNo, ModelType model, String bizId) {
IChangeDataProcessStrategy dataProcessor = DataProcessStrategyContext.getStrategy(model);
IChangeDataProcessStrategy dataProcessor = EquipDataProcessStrategyContext.getStrategy(model);
// 兼容:台套类打开变更详情(使用applyNo) 和 单位办理批量时选择单个设备打开详情(使用record)
return dataProcessor.getDetail(applyNo, bizId);
// return dataProcessor.getDetail(applyNo, bizId);
return null;
}
// private void updateManagerCertInfo(String applyNo, String record, EquipRegisterChangeDataDto registerChangeDataDto) {
// JgUseRegistration jgUseRegistration = useRegistrationService.getOne(new LambdaQueryWrapper<JgUseRegistration>()
// .eq(JgUseRegistration::getApplyNo, applyNo).select(BaseEntity::getSequenceNbr, JgUseRegistration::getStatus, JgUseRegistration::getUseRegistrationCode));
// if (FlowStatusEnum.TO_BE_FINISHED.getName().equals(jgUseRegistration.getStatus())) {
// LambdaQueryWrapper<JgUseRegistrationManage> queryWrapper = new LambdaQueryWrapper<JgUseRegistrationManage>()
// .eq(JgUseRegistrationManage::getUseRegistrationCode, jgUseRegistration.getUseRegistrationCode())
// .eq(JgUseRegistrationManage::getIsDelete, 0).select(BaseEntity::getSequenceNbr,JgUseRegistrationManage::getVersion);
// JgUseRegistrationManage jgUseRegistrationManage = registrationManageMapper.selectOne(queryWrapper);
// if (jgUseRegistrationManage != null && !StringUtils.equals(jgUseRegistrationManage.getEquDefineCode(), registerChangeDataDto.getEquDefine())) {
// LambdaUpdateWrapper<JgUseRegistrationManage> updateWrapper = new LambdaUpdateWrapper<>();
// updateWrapper.eq(BaseEntity::getSequenceNbr, jgUseRegistrationManage.getSequenceNbr());
// if (StringUtils.isNotEmpty(registerChangeDataDto.getEquDefine())) {
// EquipmentCategory equipmentCategory = getEquipmentCategory(registerChangeDataDto);
// updateWrapper.set(JgUseRegistrationManage::getEquDefineCode, registerChangeDataDto.getEquDefine());
// updateWrapper.set(JgUseRegistrationManage::getEquDefine, equipmentCategory.getName());
// } else {
// updateWrapper.set(JgUseRegistrationManage::getEquDefineCode, null);
// updateWrapper.set(JgUseRegistrationManage::getEquDefine, null);
// }
// updateWrapper.set(JgUseRegistrationManage::getVersion, jgUseRegistrationManage.getVersion() + 1);
// updateWrapper.set(JgUseRegistrationManage::getRecDate, new Date());
// updateWrapper.set(JgUseRegistrationManage::getChangeReason, "设备信息变更");
// registrationManageMapper.update(null, updateWrapper);
// }
// }
// }
// private EquipmentCategory getEquipmentCategory(EquipRegisterChangeDataDto registerChangeDataDto) {
// return equipmentCategoryMapper.selectOne(new LambdaQueryWrapper<EquipmentCategory>().eq(EquipmentCategory::getCode, registerChangeDataDto.getEquDefine()));
// }
// private Map<String, Object> getDetailByBizId(String record) {
// Map<String, Object> re = new HashMap<>();
// // 注册信息(基本信息)构建
// EquipRegisterChangeDataDto equipRegisterChangeDataDto = commonEquipDataProcessService.buildRegisterInfo(record);
// // 制造信息构建
// EquipFactoryChangeDataDto factoryChangeDataDto = commonEquipDataProcessService.buildFactoryInfo(record);
// // 设计信息构建
// EquipDesignChangeDataDto designChangeDataDto = commonEquipDataProcessService.buildDesignInfo(record);
// // 技术参数构建
// BaseTechParamsFieldDto techParamsFieldDto = commonEquipDataProcessService.buildTechParamInfo(equipRegisterChangeDataDto, record);
// re.putAll(BeanUtil.beanToMap(equipRegisterChangeDataDto));
// re.putAll(BeanUtil.beanToMap(factoryChangeDataDto));
// re.putAll(BeanUtil.beanToMap(designChangeDataDto));
// re.putAll(BeanUtil.beanToMap(techParamsFieldDto));
// commonEquipDataProcessService.castJsonFields(re);
// return commonEquipDataProcessService.cast2UnderCase(re);
// }
}
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