Commit 82b91c9f authored by 刘林's avatar 刘林

fix(jg):管道工程装置新增接口修改

parent ae6375a0
......@@ -94,7 +94,6 @@ import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static com.alibaba.fastjson.JSON.toJSONString;
import static com.yeejoin.amos.boot.module.jg.api.enums.CylinderTypeEnum.SPECIAL_CYLINDER;
import static com.yeejoin.amos.boot.module.jg.api.enums.VehicleApanageEnum.XIAN_YANG;
......@@ -115,6 +114,8 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste
public final static String MAINTENANCE_TYPE_NAME = "安装改造维修单位";
// 设备种类
public static final String EQU_LIST = "EQU_LIST";
// 管道信息
public static final String PIPELINE_LIST = "pipelineList";
// 模版上传集合
public static final String EQU_LISTS = "equLists";
// 设备类别
......@@ -155,6 +156,11 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste
// 新增修改标识
private static final String OPERATESAVE = "save";
private static final String OPERATEEDIT = "edit";
//市区县
private static final String CITY = "CITY";
private static final String COUNTY = "COUNTY";
private static final String REGION = "REGION";
private static final String STREET = "STREET";
// 单位办理类型
private static final String MANAGE_TYPE_UNIT = "unit";
private static final String RECORD = "RECORD";
......@@ -284,6 +290,8 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste
private ShCarEquServiceImpl shCarEquService;
@Autowired
private ShCarServiceImpl shCarService;
@Autowired
private IIdxBizJgProjectContraptionService idxBizJgProjectContraptionService;
/**
* 将对象的属性由驼峰转为纯大写下划线格式
......@@ -382,6 +390,11 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste
}
LinkedHashMap equipmentInfoForm = (LinkedHashMap) checkAndCast(paramMap.get(EQUIP_INFO_FORM_ID));
String dataSource = (String) equipmentInfoForm.get(DATA_SOURCE);
String equ_category = (String) equipmentInfoForm.get(EQU_CATEGORY);
//管道添加设备
if ("8300".equals(equ_category)) {
return this.pipelineEquipCreateOrUpdate(paramMap);
}
if(dataSource.contains("black")){
return this.blackEquipCreateOrUpdate(paramMap);
} else {
......@@ -389,6 +402,282 @@ public class IdxBizJgRegisterInfoServiceImpl extends BaseService<IdxBizJgRegiste
}
}
/**
* 管道设备新增或更新
*
* @param paramMap 前端参数
* @return record
*/
private ResponseModel pipelineEquipCreateOrUpdate(Map<String, Object> paramMap) {
try {
// 获取表单数据并进行类型检查
LinkedHashMap equipmentClassForm = castToLinkedHashMap(paramMap.get(EQUIP_CLASS_FORM_ID));
LinkedHashMap equipmentInfoForm = castToLinkedHashMap(paramMap.get(EQUIP_INFO_FORM_ID));
LinkedHashMap equipmentParamsForm = castToLinkedHashMap(paramMap.get(EQUIP_PARAMS_FORM_ID));
String submitType = String.valueOf(paramMap.get("submitType"));
Long sequenceNbr = (Long) equipmentInfoForm.get(SEQUENCE_NBR);
// 保存管道数据
sequenceNbr = batchSubmitOrUpdatePipeline(equipmentClassForm, equipmentInfoForm, equipmentParamsForm, submitType);
return ResponseHelper.buildResponse(sequenceNbr);
} catch (Exception e) {
log.error("操作失败,数据异常: {}", e.getMessage(), e);
handleError(e, String.valueOf(paramMap.getOrDefault(SEQUENCE_NBR, "未知序号")));
return ResponseHelper.buildResponse(null);
}
}
/**
* 检查并转换对象为 LinkedHashMap
*
* @param obj 要转换的对象
* @return LinkedHashMap
* @throws IllegalArgumentException 如果类型不匹配
*/
@SuppressWarnings("unchecked")
private LinkedHashMap castToLinkedHashMap(Object obj) {
if (obj instanceof LinkedHashMap) {
return (LinkedHashMap) obj;
}
throw new IllegalArgumentException("参数类型错误,期望 LinkedHashMap 类型: " + obj);
}
private Long batchSubmitOrUpdatePipeline(LinkedHashMap equipmentClassForm, LinkedHashMap equipmentInfoForm, LinkedHashMap equipmentParamsForm, String submitType) {
Date date = new Date();
String operateType = ValidationUtil.isEmpty(equipmentInfoForm.get(SEQUENCE_NBR)) ? OPERATESAVE : OPERATEEDIT;
// 设备是否复制而来,复制来的设备走新增
boolean isCopy = !ValidationUtil.isEmpty(equipmentInfoForm.get(IS_COPY));
operateType = isCopy ? OPERATESAVE : operateType;
// 新增设备保存时 : 历史设备=》dataSource为"his" jg新录入设备dataSource为"jg"
String dataSource = this.getDataSource(operateType, equipmentInfoForm);
List<Map<String, Object>> pipelineList = (List<Map<String, Object>>) equipmentInfoForm.get(PIPELINE_LIST);
String equListName = jgVehicleInformationMapper.getEquCategoryNameByCode((String) equipmentInfoForm.get("EQU_LIST"));
String equCategoryName = jgVehicleInformationMapper.getEquCategoryNameByCode( (String) equipmentInfoForm.get("EQU_CATEGORY"));
String equDefineName = jgVehicleInformationMapper.getEquCategoryNameByCode((String) equipmentInfoForm.get("EQU_DEFINE"));
// 单位类型
Map<String, Object> companyInfoMap = jgInstallationNoticeService.getCompanyType();
String companyTypeStr = companyInfoMap.get("companyType").toString();
Long sequenceNbr = OPERATESAVE.equals(operateType) ? UUID.randomUUID().getMostSignificantBits() : (Long) equipmentInfoForm.get(SEQUENCE_NBR);
// 工程装置信息
IdxBizJgProjectContraption projectContraption = JSON.parseObject(toJSONString(equipmentInfoForm), IdxBizJgProjectContraption.class);
projectContraption.setSequenceNbr(sequenceNbr);
projectContraption.setDataSource(dataSource);
projectContraption.setIsIntoManagement(false);
projectContraption.setProvinceName("陕西省");
projectContraption.setCityName(getRegionName(CITY, CITY, equipmentInfoForm));
projectContraption.setCountyName(getRegionName(REGION, COUNTY, equipmentInfoForm));
projectContraption.setStreetName(getRegionName(STREET, STREET, equipmentInfoForm));
projectContraption.setEquListName(equListName);
projectContraption.setEquCategoryName(equCategoryName);
projectContraption.setEquDefineName(equDefineName);
projectContraption.setPipelineLength(pipelineList.stream()
.mapToDouble(pipeline -> Double.parseDouble((String) pipeline.get("pipeLength")))
.sum());
projectContraption.setUscUnitName(companyInfoMap.get("companyName").toString());
projectContraption.setUscUnitCreditCode(companyInfoMap.get("creditCode").toString());
idxBizJgProjectContraptionService.saveOrUpdateData(projectContraption);
List<IdxBizJgUseInfo> useInfoList = new ArrayList<>(10);
List<IdxBizJgDesignInfo> designInfoList = new ArrayList<>(10);
List<IdxBizJgFactoryInfo> factoryInfoList = new ArrayList<>(10);
List<IdxBizJgConstructionInfo> constructionInfoList = new ArrayList<>(10);
List<IdxBizJgRegisterInfo> registerInfoList = new ArrayList<>(10);
List<IdxBizJgSupervisionInfo> supervisionInfoList = new ArrayList<>(10);
List<IdxBizJgOtherInfo> otherInfoList = new ArrayList<>(10);
List<IdxBizJgInspectionDetectionInfo> inspectionDetectionInfoList = new ArrayList<>(10);
List<IdxBizJgTechParamsPipeline> paramsPipelineList = new ArrayList<>(10);
List<ESEquipmentCategoryDto> esEquipmentCategoryList = new ArrayList<>(10);
//设备信息
for (Map<String, Object> pipeline : pipelineList) {
String record = OPERATESAVE.equals(operateType) ? UUID.randomUUID().toString() : pipeline.get(RECORD).toString();
if (isCopy) {
String sourceRecord = pipeline.get(RECORD).toString();
// bug-21203
if (equipmentInfoForm.containsKey("DATA_SOURCE")) {
String dataSourceCopy = equipmentInfoForm.get("DATA_SOURCE").toString();
if (dataSourceCopy.startsWith("jg_his_black")) {
dataSource = "jg_his_black_" + sourceRecord;
} else if (dataSourceCopy.startsWith("jg_his")) {
dataSource = "jg_his_" + sourceRecord;
} else {
dataSource = "jg_" + sourceRecord;
}
} else {
throw new BadRequest("数据异常,请联系管理员");
}
}
//更新时工业管道(8300)检验检测信息
IdxBizJgInspectionDetectionInfo inspectionDetectionInfo = JSON.parseObject(toJSONString(pipeline), IdxBizJgInspectionDetectionInfo.class);
List<Map<String, Object>> inspectionAndTestingInstitutions = commonService.getUnitListByType("inspection", "gasCylindersForCars");
Optional<Map<String, Object>> optional = inspectionAndTestingInstitutions.stream().filter(x -> x.get("useCode").equals(inspectionDetectionInfo.getInspectOrgCode())).findFirst();
Map<String, Object> mapOrDefault = optional.orElse(Collections.emptyMap());
inspectionDetectionInfo.setInspectOrgName((String) mapOrDefault.getOrDefault("useUnit", inspectionDetectionInfo.getInspectOrgName()));
inspectionDetectionInfo.setRecord(record);
inspectionDetectionInfo.setRecDate(date);
if (inspectionDetectionInfo.getNextInspectDate() != null) {
inspectionDetectionInfo.setNextInspectDate(DateUtil.parse(DateUtil.format(inspectionDetectionInfo.getNextInspectDate(), DatePattern.NORM_DATE_PATTERN)));
}
inspectionDetectionInfo.setSequenceNbr(OPERATESAVE.equals(operateType) ? null : String.valueOf(equipmentInfoForm.get("INSPECTIONDETECTIONINFO_SEQ")));
inspectionDetectionInfoList.add(inspectionDetectionInfo);
// 使用信息
IdxBizJgUseInfo useInfo = JSON.parseObject(toJSONString(pipeline), IdxBizJgUseInfo.class);
// 使用信息
useInfo.setRecord(record);
useInfo.setRecDate(date);
useInfo.setDataSource(dataSource);
useInfo.setIsIntoManagement(Boolean.FALSE);
useInfo.setSequenceNbr(OPERATESAVE.equals(operateType) ? null : String.valueOf(equipmentInfoForm.get("USEINFO_SEQ")));
if (companyTypeStr.contains(CompanyTypeEnum.USE.getCode()) || companyTypeStr.contains(CompanyTypeEnum.INDIVIDUAL.getCode())) {
useInfo.setUseUnitCreditCode(companyInfoMap.get("creditCode").toString());
useInfo.setUseUnitName(companyInfoMap.get("companyName").toString());
}
if (isCopy) {
// 设备状态置空
useInfo.setEquState("");
// 如果为安改维单位复制设备,则将使用单位信息置空
if (companyTypeStr.equals(CompanyTypeEnum.CONSTRUCTION.getCode())) {
useInfo.setUseUnitCreditCode("");
useInfo.setUseUnitName("");
}
}
useInfo.setProjectContraption(((String) equipmentInfoForm.get("PROJECT_CONTRAPTION")).trim());
useInfo.setProjectContraptionId(String.valueOf(sequenceNbr));
useInfoList.add(useInfo);
// 设计信息
IdxBizJgDesignInfo designInfo = JSON.parseObject(toJSONString(pipeline), IdxBizJgDesignInfo.class);
designInfo.setRecord(record);
designInfo.setRecDate(date);
designInfo.setSequenceNbr(OPERATESAVE.equals(operateType) ? null : String.valueOf(equipmentInfoForm.get("DESIGNINFO_SEQ")));
designInfoList.add(designInfo);
// 制造信息
IdxBizJgFactoryInfo factoryInfo = JSON.parseObject(toJSONString(pipeline), IdxBizJgFactoryInfo.class);
factoryInfo.setRecord(record);
factoryInfo.setRecDate(date);
factoryInfo.setSequenceNbr(OPERATESAVE.equals(operateType) ? null : String.valueOf(equipmentInfoForm.get("FACTORYINFO_SEQ")));
factoryInfoList.add(factoryInfo);
// 施工信息
IdxBizJgConstructionInfo constructionInfo = JSON.parseObject(toJSONString(pipeline), IdxBizJgConstructionInfo.class);
String companyName = companyInfoMap.get("companyName").toString();
String companyCode = companyInfoMap.get("creditCode").toString();
constructionInfo.setRecord(record);
constructionInfo.setRecDate(date);
if (companyTypeStr.contains(CompanyTypeEnum.CONSTRUCTION.getCode())) {
constructionInfo.setUscUnitCreditCode(companyCode);
constructionInfo.setUscUnitName(companyName);
}
if (isCopy) {
if (companyTypeStr.equals(CompanyTypeEnum.USE.getCode()) || companyTypeStr.equals(CompanyTypeEnum.INDIVIDUAL.getCode())) {
constructionInfo.setUscUnitCreditCode("");
constructionInfo.setUscUnitName("");
}
}
constructionInfo.setSequenceNbr(OPERATESAVE.equals(operateType) ? null : String.valueOf(equipmentInfoForm.get("CONSTRUCTIONINFO_SEQ")));
constructionInfoList.add(constructionInfo);
// 注册登记信息
IdxBizJgRegisterInfo registerInfo = JSON.parseObject(toJSONString(equipmentInfoForm), IdxBizJgRegisterInfo.class);
registerInfo.setRecord(record);
registerInfo.setRecDate(date);
registerInfo.setRegisterState(this.getRegCode());
registerInfo.setSequenceNbr(OPERATESAVE.equals(operateType) ? null : String.valueOf(equipmentInfoForm.get("REGISTERINFO_SEQ")));
// 补丁:saveOrUpdate在update数据时不会更新字段为null的字段,但是编辑设备的代码时,从有改成无,equCode解析成null,但是此时需要将equcode删掉
registerInfo.setEquCode(ObjectUtils.isEmpty(registerInfo.getEquCode()) ? "" : registerInfo.getEquCode());
// copy设备 =》 使用登记证号置空
String useOrgCode = ValidationUtil.isEmpty(equipmentInfoForm.get("useRegistrationCode")) ? "" : String.valueOf(equipmentInfoForm.get("useRegistrationCode"));
registerInfo.setUseOrgCode(isCopy && !"1".equals(equipmentInfoForm.get("WHETHER_VEHICLE_CYLINDER")) ? "" : useOrgCode);
registerInfoList.add(registerInfo);
// 监督管理
IdxBizJgSupervisionInfo supervisionInfo = JSON.parseObject(toJSONString(pipeline), IdxBizJgSupervisionInfo.class);
supervisionInfo.setRecord(record);
supervisionInfo.setRecDate(date);
supervisionInfo.setSequenceNbr(OPERATESAVE.equals(operateType) ? null : String.valueOf(equipmentInfoForm.get("SUPERVISIONINFO_SEQ")));
supervisionInfoList.add(supervisionInfo);
// 其他信息
IdxBizJgOtherInfo otherInfo = JSON.parseObject(toJSONString(pipeline), IdxBizJgOtherInfo.class);
otherInfo.setRecord(record);
otherInfo.setClaimStatus("已认领");
otherInfo.setRecDate(date);
otherInfo.setSequenceNbr(OPERATESAVE.equals(operateType) ? null : String.valueOf(equipmentInfoForm.get("OTHERINFO_SEQ")));
if (isCopy) {
// 监管码置空
otherInfo.setSupervisoryCode("");
otherInfo.setCylinderStampAttachment("");
otherInfo.setInformationSituation("");
otherInfo.setInformationManageCode("");
}
otherInfoList.add(otherInfo);
//管道技术参数
IdxBizJgTechParamsPipeline pipelineInfo = JSON.parseObject(toJSONString(equipmentParamsForm), IdxBizJgTechParamsPipeline.class);
if (!ValidationUtil.isEmpty(pipelineInfo)) {
pipelineInfo.setRecord(record);
pipelineInfo.setRecDate(date);
pipelineInfo.setSequenceNbr(OPERATESAVE.equals(operateType) ? null : String.valueOf(equipmentParamsForm.get("PIPELINE_SEQ")));
paramsPipelineList.add(pipelineInfo);
}
ESEquipmentCategoryDto esEquipmentDto = JSON.parseObject(toJSONString(equipmentInfoForm), ESEquipmentCategoryDto.class);
esEquipmentDto.setDATA_SOURCE(useInfo.getDataSource());
if (inspectionDetectionInfo.getNextInspectDate() != null) {
esEquipmentDto.setNEXT_INSPECT_DATE(inspectionDetectionInfo.getNextInspectDate().getTime());
}
esEquipmentDto.setREC_DATE(System.currentTimeMillis());
esEquipmentDto.setSEQUENCE_NBR(record);
esEquipmentDto.setIS_INTO_MANAGEMENT(false);
esEquipmentDto.setEQU_CATEGORY_CODE(registerInfo.getEquCategory());
esEquipmentDto.setEQU_CATEGORY(equCategoryName);
esEquipmentDto.setEQU_LIST_CODE(registerInfo.getEquList());
esEquipmentDto.setEQU_LIST(equListName);
esEquipmentDto.setEQU_DEFINE_CODE(registerInfo.getEquDefine());
esEquipmentDto.setEQU_DEFINE(equListName);
esEquipmentDto.setSTATUS("已认领");
esEquipmentCategoryList.add(esEquipmentDto);
}
idxBizJgUseInfoService.saveOrUpdateBatch(useInfoList);
iIdxBizJgDesignInfoService.saveOrUpdateBatch(designInfoList);
iIdxBizJgConstructionInfoService.saveOrUpdateBatch(constructionInfoList);
iIdxBizJgFactoryInfoService.saveOrUpdateBatch(factoryInfoList);
this.saveOrUpdateBatch(registerInfoList);
iIdxBizJgOtherInfoService.saveOrUpdateBatch(otherInfoList);
iIdxBizJgSupervisionInfoService.saveOrUpdateBatch(supervisionInfoList);
iIdxBizJgInspectionDetectionInfoService.saveOrUpdateBatch(inspectionDetectionInfoList);
iIdxBizJgTechParamsPipelineService.saveOrUpdateBatch(paramsPipelineList);
esEquipmentCategory.saveAll(esEquipmentCategoryList);
return sequenceNbr;
}
/**
* 根据code获取市区县名字
* @param key key
* @param codeKey codeKey
* @param equipmentInfoForm 表单信息
* @return name
*/
private String getRegionName(String key, String codeKey, Map<String, Object> equipmentInfoForm) {
return Optional.ofNullable((List<LinkedHashMap>) redisUtils.get(key))
.flatMap(list -> list.stream()
.filter(item -> String.valueOf(item.get("regionCode"))
.equals(String.valueOf(equipmentInfoForm.get(codeKey))))
.map(item -> (String) item.get("regionName"))
.findFirst())
.orElse("");
}
private ResponseModel blackEquipCreateOrUpdate(Map<String, Object> paramMap) {
LinkedHashMap equipmentClassForm = (LinkedHashMap) checkAndCast(paramMap.get(EQUIP_CLASS_FORM_ID));
LinkedHashMap equipmentInfoForm = (LinkedHashMap) checkAndCast(paramMap.get(EQUIP_INFO_FORM_ID));
......
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