Browse Source

设备关系处理移到impl中,防止出现关系中有obj_from为空的设备关系。

yucheng 3 years ago
parent
commit
2b977b3e0f

+ 2 - 64
adm-business/adm-middleware/src/main/java/com/persagy/proxy/object/controller/AdmEquipmentController.java

@@ -4,8 +4,6 @@ import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.io.IoUtil;
-import cn.hutool.core.map.MapUtil;
-import cn.hutool.core.util.IdUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.json.JSONUtil;
 import cn.hutool.poi.excel.ExcelReader;
@@ -31,7 +29,6 @@ import com.persagy.dmp.define.entity.ObjectTypeDefine;
 import com.persagy.dmp.digital.client.DigitalObjectFacade;
 import com.persagy.dmp.simple.client.DigitalObjectSimpleFacade;
 import com.persagy.proxy.adm.constant.AdmCommonConstant;
-import com.persagy.proxy.adm.constant.AdmDictCategoryEnum;
 import com.persagy.proxy.adm.constant.AdmRelationTypeEnum;
 import com.persagy.proxy.adm.request.*;
 import com.persagy.proxy.adm.service.IAdmRelationService;
@@ -41,8 +38,6 @@ import com.persagy.proxy.adm.utils.AdmQueryCriteriaHelper;
 import com.persagy.proxy.adm.utils.ObjectNameUtil;
 import com.persagy.proxy.common.entity.InstanceUrlParam;
 import com.persagy.proxy.common.entity.RelationDTO;
-import com.persagy.proxy.dictionary.model.AdmDict;
-import com.persagy.proxy.dictionary.model.AdmObjectType;
 import com.persagy.proxy.dictionary.service.IAdmDictService;
 import com.persagy.proxy.object.model.AdmEquipment;
 import com.persagy.proxy.object.model.AdmProject;
@@ -115,51 +110,8 @@ public class AdmEquipmentController {
 		if(CollUtil.isEmpty(vos)){
 			return AdmCreateResponse.success();
 		}
-		// 查询所有设备类型
-		AdmDict dictCond = AdmDict.builder().type(AdmDictCategoryEnum.EQUIPMENT.getValue()).build();
-		AdmResponse dictResponse = dictService.queryCategory(AdmContextUtil.toDmpContext(), dictCond, AdmObjectType.class);
-		List<AdmObjectType> dicts = (List<AdmObjectType>) dictResponse.getContent();
-		// 转换为Map,key为编码后4位。用于适配旧类型编码
-		Map<String, AdmObjectType> shortDictMap = new HashMap<>();
-		Map<String, AdmObjectType> fullDictMap = new HashMap<>();
-		for(int i = 0,j = CollUtil.size(dicts);i < j;i++) {
-			AdmObjectType dict = dicts.get(i);
-			shortDictMap.put(StrUtil.subSufByLength(dict.getCode(), 4), dict);
-			fullDictMap.put(dict.getCode(), dict);
-		}
-		// 设备属性调整
-		List<AdmEquipment> filterVOs = new ArrayList<>();
-		for(AdmEquipment equipment:vos) {
-			// 如果不是Eq开头,则重新生成ID
-			if(StrUtil.startWith(equipment.getId(), "Eq")) {
-				equipment.setId("Eq"+ IdUtil.simpleUUID());
-			}
-			// 类型编码适配
-			String classCode = equipment.getClassCode();
-			// 如果编码为空,或在4位、6位里都不存在,则报错
-			if(StrUtil.isBlank(classCode) ||
-					(shortDictMap.get(classCode) == null && fullDictMap.get(classCode) == null)) {
-				log.error(StrUtil.format("没有找到对象类型【{}】!", equipment.getClassCode()));
-				continue;
-			}
-			filterVOs.add(equipment);
-			// 如果少于6位,则需要适配新编码
-			if(classCode.length() < 6) {
-				AdmObjectType dict = MapUtil.get(shortDictMap, classCode, AdmObjectType.class);
-				equipment.setClassCode(dict.getCode());
-			}
-			// 如果名称为空,则提供默认名称
-			if (StrUtil.isEmpty(equipment.getName())){
-				AdmObjectType dict = MapUtil.get(fullDictMap, equipment.getClassCode(), AdmObjectType.class);
-				String preName = dict == null ? "设备" : dict.getName();
-				equipment.setName(ObjectNameUtil.objectName(preName + "-"));
-			}
-		}
-		if(CollUtil.isEmpty(filterVOs)){
-			return AdmCreateResponse.success();
-		}
-		filterVOs = service.doInsert(AdmContextUtil.toDmpContext(), AdmEquipment.class, filterVOs);
-		return AdmCreateResponse.success(filterVOs);
+		vos = service.doInsert(AdmContextUtil.toDmpContext(), AdmEquipment.class, vos);
+		return AdmCreateResponse.success(vos);
 	}
 
 	/**
@@ -187,20 +139,6 @@ public class AdmEquipmentController {
 		if(CollUtil.isEmpty(vos)) {
 			return AdmResponse.success(vos);
 		}
-		for(AdmEquipment vo:vos) {
-			if(StrUtil.isNotBlank(vo.getFlowBuild())) {
-				// 处理建筑-楼层信息点
-				List<String> flows = StrUtil.splitTrim(vo.getFlowBuild(), "-");
-				for(String flow:flows) {
-					if(StrUtil.startWith(flow, "Bd")) {
-						vo.setBuildingId(flow);
-					} else if(StrUtil.startWith(flow, "fl")) {
-						vo.setFloorId(flow);
-					}
-				}
-				vo.setFlowBuild(null);
-			}
-		}
 		vos = service.doUpdate(AdmContextUtil.toDmpContext(), AdmEquipment.class, vos);
 		return AdmResponse.success(vos);
 	}

+ 66 - 2
adm-business/adm-middleware/src/main/java/com/persagy/proxy/object/service/impl/AdmEquipmentServiceImpl.java

@@ -1,6 +1,8 @@
 package com.persagy.proxy.object.service.impl;
 
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.map.MapUtil;
+import cn.hutool.core.util.IdUtil;
 import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
@@ -14,6 +16,7 @@ import com.persagy.dmp.common.model.entity.BaseEntity;
 import com.persagy.dmp.digital.client.DigitalRelationFacade;
 import com.persagy.dmp.digital.entity.ObjectRelation;
 import com.persagy.proxy.adm.constant.AdmCommonConstant;
+import com.persagy.proxy.adm.constant.AdmDictCategoryEnum;
 import com.persagy.proxy.adm.constant.AdmRelationTypeEnum;
 import com.persagy.proxy.adm.request.AdmQueryCriteria;
 import com.persagy.proxy.adm.request.AdmResponse;
@@ -21,6 +24,7 @@ import com.persagy.proxy.adm.service.IAdmRelationService;
 import com.persagy.proxy.adm.service.impl.AbstractAdmBaseServiceImpl;
 import com.persagy.proxy.adm.utils.AdmContextUtil;
 import com.persagy.proxy.adm.utils.AdmEntityTransferUtil;
+import com.persagy.proxy.adm.utils.ObjectNameUtil;
 import com.persagy.proxy.calculation.service.AdmRelCalService;
 import com.persagy.proxy.common.client.DmpRwdClient;
 import com.persagy.proxy.common.entity.DmpResult;
@@ -102,12 +106,72 @@ public class AdmEquipmentServiceImpl extends AbstractAdmBaseServiceImpl<AdmEquip
 
     @Override
     public List<AdmEquipment> doInsert(InstanceUrlParam context, Class<AdmEquipment> clazz, List<AdmEquipment> voList) {
-        processFloorRelations(context, voList, false);
-        return super.doInsert(context, clazz, voList);
+        // 查询所有设备类型
+        AdmDict dictCond = AdmDict.builder().type(AdmDictCategoryEnum.EQUIPMENT.getValue()).build();
+        AdmResponse dictResponse = dictService.queryCategory(AdmContextUtil.toDmpContext(), dictCond, AdmObjectType.class);
+        List<AdmObjectType> dicts = (List<AdmObjectType>) dictResponse.getContent();
+        // 转换为Map,key为编码后4位。用于适配旧类型编码
+        Map<String, AdmObjectType> shortDictMap = new HashMap<>();
+        Map<String, AdmObjectType> fullDictMap = new HashMap<>();
+        for(int i = 0,j = CollUtil.size(dicts);i < j;i++) {
+            AdmObjectType dict = dicts.get(i);
+            shortDictMap.put(StrUtil.subSufByLength(dict.getCode(), 4), dict);
+            fullDictMap.put(dict.getCode(), dict);
+        }
+        // 设备属性调整
+        List<AdmEquipment> filterVOs = new ArrayList<>();
+        for(AdmEquipment equipment:voList) {
+            // 如果不是Eq开头,则重新生成ID
+            if(!StrUtil.startWith(equipment.getId(), "Eq")) {
+                equipment.setId("Eq"+ IdUtil.simpleUUID());
+            }
+            // 类型编码适配
+            String classCode = equipment.getClassCode();
+            // 如果编码为空,或在4位、6位里都不存在,则报错
+            if(StrUtil.isBlank(classCode) ||
+                    (shortDictMap.get(classCode) == null && fullDictMap.get(classCode) == null)) {
+                log.error(StrUtil.format("没有找到对象类型【{}】!", equipment.getClassCode()));
+                continue;
+            }
+            filterVOs.add(equipment);
+            // 如果少于6位,则需要适配新编码
+            if(classCode.length() < 6) {
+                AdmObjectType dict = MapUtil.get(shortDictMap, classCode, AdmObjectType.class);
+                equipment.setClassCode(dict.getCode());
+            }
+            // 如果名称为空,则提供默认名称
+            if (StrUtil.isEmpty(equipment.getName())){
+                AdmObjectType dict = MapUtil.get(fullDictMap, equipment.getClassCode(), AdmObjectType.class);
+                String preName = dict == null ? "设备" : dict.getName();
+                equipment.setName(ObjectNameUtil.objectName(preName + "-"));
+            }
+        }
+        if(CollUtil.isEmpty(filterVOs)) {
+            return null;
+        }
+        // 处理楼层关系
+        processFloorRelations(context, filterVOs, false);
+        return super.doInsert(context, clazz, filterVOs);
     }
 
     @Override
     public List<AdmEquipment> doUpdate(InstanceUrlParam context, Class<AdmEquipment> clazz, List<AdmEquipment> voList) {
+        // 处理楼层属性
+        for(AdmEquipment vo:voList) {
+            if(StrUtil.isNotBlank(vo.getFlowBuild())) {
+                // 处理建筑-楼层信息点
+                List<String> flows = StrUtil.splitTrim(vo.getFlowBuild(), "-");
+                for(String flow:flows) {
+                    if(StrUtil.startWith(flow, "Bd")) {
+                        vo.setBuildingId(flow);
+                    } else if(StrUtil.startWith(flow, "fl")) {
+                        vo.setFloorId(flow);
+                    }
+                }
+                vo.setFlowBuild(null);
+            }
+        }
+        // 处理楼层关系
         processFloorRelations(context, voList, false);
         List<AdmEquipment> equipmentList = super.doUpdate(context, clazz, voList);
         // 处理关系标记

+ 1 - 1
adm-business/adm-middleware/src/main/java/com/persagy/proxy/report/controller/AdmReportEquipController.java

@@ -322,7 +322,7 @@ public class AdmReportEquipController {
     public AdmResponse create(@RequestBody AdmCreateRequest<AdmEquipment> createRequest){
         //return EquipmentProSyService.createList(request)
         List<AdmEquipment> vos = CollUtil.newArrayList(createRequest.getContent());
-        vos = equipmentService.doInsertEuip(AdmContextUtil.toDmpContext(), AdmEquipment.class, vos);
+        vos = equipmentService.doInsert(AdmContextUtil.toDmpContext(), AdmEquipment.class, vos);
         return AdmResponse.success(vos);
     }