|
@@ -1,14 +1,21 @@
|
|
|
package com.persagy.proxy.object.controller;
|
|
|
|
|
|
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.persagy.proxy.object.model.AdmComponent;
|
|
|
+import com.persagy.dmp.common.exception.BusinessException;
|
|
|
+import com.persagy.proxy.adm.constant.AdmDictCategoryEnum;
|
|
|
import com.persagy.proxy.adm.request.AdmCreateRequest;
|
|
|
import com.persagy.proxy.adm.request.AdmQueryCriteria;
|
|
|
import com.persagy.proxy.adm.request.AdmResponse;
|
|
|
-import com.persagy.proxy.object.service.IAdmComponentService;
|
|
|
import com.persagy.proxy.adm.utils.AdmContextUtil;
|
|
|
import com.persagy.proxy.adm.utils.ObjectNameUtil;
|
|
|
+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.AdmComponent;
|
|
|
+import com.persagy.proxy.object.service.IAdmComponentService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
@@ -16,7 +23,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.ws.rs.QueryParam;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* Adm 部件 API
|
|
@@ -29,10 +38,11 @@ import java.util.List;
|
|
|
public class AdmComponentController {
|
|
|
@Autowired
|
|
|
private IAdmComponentService service;
|
|
|
+ @Autowired
|
|
|
+ private IAdmDictService dictService;
|
|
|
|
|
|
/**
|
|
|
* 统计
|
|
|
- *
|
|
|
* @param request
|
|
|
* @return
|
|
|
* @throws Exception
|
|
@@ -55,13 +65,44 @@ public class AdmComponentController {
|
|
|
if(CollUtil.isEmpty(vos)){
|
|
|
return AdmResponse.success();
|
|
|
}
|
|
|
- //创建部件
|
|
|
+ // 查询所有设备类型
|
|
|
+ AdmDict dictCond = AdmDict.builder().type(AdmDictCategoryEnum.COMPONENT.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(), 6), dict);
|
|
|
+ fullDictMap.put(dict.getCode(), dict);
|
|
|
+ }
|
|
|
+ // 设备属性调整
|
|
|
vos.stream().forEach(component -> {
|
|
|
+ // 如果不是Eq开头,则重新生成ID
|
|
|
+ if(StrUtil.startWith(component.getId(), "Ec")) {
|
|
|
+ component.setId("Ec"+ IdUtil.simpleUUID());
|
|
|
+ }
|
|
|
+ // 类型编码适配
|
|
|
+ String classCode = component.getClassCode();
|
|
|
+ // 如果编码为空,或在4位、6位里都不存在,则报错
|
|
|
+ if(StrUtil.isBlank(classCode) ||
|
|
|
+ (shortDictMap.get(classCode) == null && fullDictMap.get(classCode) == null)) {
|
|
|
+ throw new BusinessException(StrUtil.format("没有找到对象类型【{}】!", component.getClassCode()));
|
|
|
+ }
|
|
|
+ // 如果少于6位,则需要适配新编码
|
|
|
+ if(classCode.length() < 8) {
|
|
|
+ AdmObjectType dict = MapUtil.get(shortDictMap, classCode, AdmObjectType.class);
|
|
|
+ component.setClassCode(dict.getCode());
|
|
|
+ }
|
|
|
+ // 如果名称为空,则提供默认名称
|
|
|
if (StrUtil.isEmpty(component.getName())){
|
|
|
- component.setName(ObjectNameUtil.objectName("部件-"));
|
|
|
+ AdmObjectType dict = MapUtil.get(fullDictMap, component.getClassCode(), AdmObjectType.class);
|
|
|
+ String preName = dict == null ? "部件" : dict.getName();
|
|
|
+ component.setName(ObjectNameUtil.objectName(preName + "-"));
|
|
|
}
|
|
|
});
|
|
|
- vos = service.doInsertExt(AdmContextUtil.toDmpContext(), AdmComponent.class, vos);
|
|
|
+ vos = service.doInsert(AdmContextUtil.toDmpContext(), AdmComponent.class, vos);
|
|
|
return AdmResponse.success(vos);
|
|
|
}
|
|
|
|