Browse Source

2021-1109 服务调整,配置工具完善

zhaoyk 3 years ago
parent
commit
d372a2783f

+ 2 - 2
src/main/java/com/persagy/bdtp/adm/client/RwdClient.java

@@ -1,11 +1,11 @@
 package com.persagy.bdtp.adm.client;
 
+import com.persagy.bdtp.adm.entity.InfoDef;
 import com.persagy.bdtp.adm.entity.TypeDef;
 import com.persagy.dmp.basic.config.DigitalFeignConfig;
 import com.persagy.dmp.basic.model.QueryCriteria;
 import com.persagy.dmp.common.model.response.CommonResult;
 import com.persagy.dmp.define.entity.GraphDefine;
-import com.persagy.dmp.define.entity.ObjectInfoDefine;
 import com.persagy.dmp.define.entity.RelationDefine;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -36,7 +36,7 @@ public interface RwdClient {
 			@RequestBody QueryCriteria criteria);
 
 	@PostMapping("/rwd/def/funcid")
-	CommonResult<List<ObjectInfoDefine>> queryFunc(
+	CommonResult<List<InfoDef>> queryFunc(
 			@RequestParam("groupCode") String groupCode,
 			@RequestParam("projectId") String projectId,
 			@RequestParam("appId") String appId,

+ 10 - 5
src/main/java/com/persagy/bdtp/adm/controller/AppController.java

@@ -32,6 +32,16 @@ public class AppController {
 	@Autowired
 	private DataTxHandler dataTxHandler;
 
+	@RequestMapping("/dict")
+	public AdmResult<Map<String, Object>> dict(@RequestBody AdmRequest req){
+		return AdmResult.success(syncApp.downloadDict(req.getGroupCode(), req.getProjectId(), req.getUserId()));
+	}
+
+	@RequestMapping("/config")
+	public AdmResult<Map<String, Object>> config(@RequestBody AdmRequest req){
+		return AdmResult.success(syncApp.downloadConfig(req.getGroupCode(), req.getProjectId(), req.getUserId()));
+	}
+
 	@RequestMapping("/frame")
 	public AdmResult<Map<String, Object>> frame(@RequestBody AdmRequest req){
 //		ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
@@ -70,11 +80,6 @@ public class AppController {
 		return AdmResult.success(syncApp.downloadFrameData(req.getGroupCode(), req.getProjectId(), req.getUserId()));
 	}
 
-	@RequestMapping("/dict")
-	public AdmResult<Map<String, Object>> dict(@RequestBody AdmRequest req){
-		return AdmResult.success(syncApp.downloadDictAndConfig(req.getGroupCode(), req.getProjectId(), req.getUserId()));
-	}
-
 	@RequestMapping("/download")
 	public AdmResult<SyncData> download(@RequestBody AdmRequest req){
 		return AdmResult.success(syncApp.downloadBuildingData(req.getProjectId(), req.getBuildingId(), req.getUploadFlag(), req.getLastDownloadTime()));

+ 82 - 14
src/main/java/com/persagy/bdtp/adm/controller/ToolController.java

@@ -10,19 +10,17 @@ import com.persagy.bdtp.adm.common.AdmConst;
 import com.persagy.bdtp.adm.common.AdmRequest;
 import com.persagy.bdtp.adm.common.AdmResult;
 import com.persagy.bdtp.adm.dao.AdmContainerConfigMapper;
+import com.persagy.bdtp.adm.dao.AdmInfosConfigMapper;
 import com.persagy.bdtp.adm.dao.AdmPipeConfigMapper;
 import com.persagy.bdtp.adm.dao.AdmRelsConfigMapper;
 import com.persagy.bdtp.adm.entity.*;
 import com.persagy.bdtp.adm.service.IConfigService;
 import com.persagy.bdtp.adm.service.ISyncApp;
-import com.persagy.bdtp.adm.service.ISyncOldAdm;
 import com.persagy.bdtp.adm.service.ServiceUtil;
 import com.persagy.dmp.basic.model.QueryCriteria;
 import com.persagy.dmp.common.constant.ResponseCode;
 import com.persagy.dmp.common.exception.BusinessException;
-import com.persagy.dmp.common.helper.SpringHelper;
 import com.persagy.dmp.define.entity.GraphDefine;
-import com.persagy.dmp.define.entity.ObjectInfoDefine;
 import com.persagy.dmp.define.entity.RelationDefine;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
@@ -49,7 +47,7 @@ public class ToolController {
 
 	@RequestMapping("/dict")
 	public AdmResult<Object> dict(@RequestBody AdmRequest req, @RequestParam(required = false) String module){
-		Map<String,Object> map = syncApp.queryDict(req.getGroupCode(), req.getProjectId(), req.getUserId());
+		Map<String,Object> map = syncApp.queryDict(req.getGroupCode(), req.getProjectId(), req.getUserId(), !"infos".equals(module), false);
 
 		List<Map<String, Object>> majorList = (List)map.get("major");
 		List<TypeDef> sysList = (List)map.get("system");
@@ -61,7 +59,7 @@ public class ToolController {
 		clearTime(sysList);
 		clearTime(equipList);
 
-		//组织树形结构
+		//组织专业-系统树形结构
 		for(Map<String, Object> major : majorList){
 			ArrayList<TypeDef> childrenSys = new ArrayList<>();
 			major.put("children", childrenSys);
@@ -77,7 +75,6 @@ public class ToolController {
 		map.remove("system");
 
 		if("infos".equals(module)) { //信息点配置
-			map.remove("relation");
 
 		} else { //关系、管道、无模型设备
 			List<RelationDefine> relDefs = (List<RelationDefine>)map.get("relation");
@@ -103,12 +100,17 @@ public class ToolController {
 		return AdmResult.success(map);
 	}
 
-	private void distinct(List<TypeDef> list){
-		List<TypeDef> result = new ArrayList<>();
+	private <T> void distinct(List<T> list){
+		List<T> result = new ArrayList<>();
 		HashSet<String> codes = new HashSet<>();
-		for(TypeDef def : list) {
-			if(!codes.contains(def.getCode())) {
-				codes.add(def.getCode());
+		for(T def : list) {
+			String code = null;
+			if(def instanceof TypeDef)
+				code = ((TypeDef) def).getCode();
+			else if(def instanceof InfoDef)
+				code = ((InfoDef) def).getCode();
+			if(!codes.contains(code)) {
+				codes.add(code);
 				result.add(def);
 			}
 		}
@@ -136,7 +138,8 @@ public class ToolController {
 
 		//配置数据查询
 		if("infos".equals(module)) { //信息点配置
-
+			List<AdmInfosConfig> infoConfig = configService.queryInfosConfig(projectId);
+			data.put("infoConfig", infoConfig);
 		} else {
 			List<AdmRelsConfig> relConfig = configService.queryRelsConfig(projectId);
 			List<AdmPipeConfig> pipeConfig = configService.queryPipeConfig(projectId);
@@ -157,8 +160,46 @@ public class ToolController {
 		node.put("classCode", typeCode);
 		criteria.setCriteria(node);
 
-		List<ObjectInfoDefine> funcList = ServiceUtil.call(() -> rwdClient.queryFunc(req.getGroupCode(), req.getProjectId(), AdmConst.APP_ID, req.getUserId(), criteria));
-		return AdmResult.success(funcList);
+		List<Object> roots = new ArrayList<>();
+
+		List<InfoDef> funcList = ServiceUtil.call(() -> rwdClient.queryFunc(req.getGroupCode(), req.getProjectId(), AdmConst.APP_ID, req.getUserId(), criteria));
+		distinct(funcList);
+		for(InfoDef infoDef : funcList) {
+			buildInfosTree(roots, infoDef);
+		}
+
+		return AdmResult.success(roots);
+	}
+
+	private void buildInfosTree(List<Object> roots, InfoDef infoDef){
+		Map<String, Object> folder = null;
+		if(StrUtil.isNotBlank(infoDef.getFirstTag())) {
+			folder = findParent(roots, infoDef.getFirstTag());
+			if(StrUtil.isNotBlank(infoDef.getSecondTag())){
+				folder = findParent((List<Object>) folder.get("children"), infoDef.getSecondTag());
+			}
+		}
+		if(folder == null)
+			roots.add(infoDef);
+		else
+			((List<Object>) folder.get("children")).add(infoDef);
+	}
+
+	private Map<String, Object> findParent(List<Object> list, String tag){
+		for(Object o : list){
+			if(o instanceof Map){
+				if(tag.equals(((Map) o).get("code")))
+					return (Map<String, Object>) o;
+			}
+		}
+
+		Map<String, Object> p = new HashMap<>();
+		p.put("code", tag);
+		p.put("name", tag);
+		p.put("info_tag", true);
+		p.put("children", new ArrayList<>());
+		list.add(p);
+		return p;
 	}
 
 	@Autowired
@@ -213,4 +254,31 @@ public class ToolController {
 		}
 	}
 
+	@Autowired
+	private AdmInfosConfigMapper infosConfigMapper;
+
+	@PostMapping("/updateInfos")
+	public AdmResult<Object> updateInfos(@RequestBody AdmInfosConfig cfg) {
+		String newId = null;
+		if(StrUtil.isBlank(cfg.getId())){
+			newId = IdUtil.fastSimpleUUID();
+			cfg.setId(newId);
+		}
+		if(cfg.getInfos() != null) {
+			for(Object o : cfg.getInfos()) {
+				if(o instanceof Map){
+					((Map<?, ?>) o).remove("name");
+					((Map<?, ?>) o).remove("cfgItemType");
+				}
+			}
+		}
+
+		if(newId != null)
+			infosConfigMapper.insert(cfg);
+		else
+			infosConfigMapper.updateById(cfg);
+
+		return AdmResult.success(newId);
+	}
+
 }

+ 43 - 0
src/main/java/com/persagy/bdtp/adm/entity/InfoDef.java

@@ -0,0 +1,43 @@
+package com.persagy.bdtp.adm.entity;
+
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import lombok.Data;
+
+@Data
+public class InfoDef {
+
+	private String groupCode;
+
+	private String projectId;
+
+	private String code;
+
+	private String name;
+
+	private String aliasCode;
+
+//	private String aliasName;
+
+	private String classCode;
+
+	private String firstTag;
+
+	private String secondTag;
+
+//	private String inputMode;
+
+	private String unit;
+
+	private String dataType;
+
+//	private Boolean isMultiple = false;
+
+//	private Boolean isRegion = false;
+
+	private ArrayNode dataSource;
+
+	private Long showOrder;
+
+	private String version;
+
+}

+ 4 - 2
src/main/java/com/persagy/bdtp/adm/service/ISyncApp.java

@@ -10,9 +10,11 @@ import java.util.Map;
  */
 public interface ISyncApp {
 
-	Map<String, Object> queryDict(String groupCode, String projectId, String userId);
+	Map<String, Object> queryDict(String groupCode, String projectId, String userId, boolean includeRel, boolean includeInfos);
 
-	Map<String, Object> downloadDictAndConfig(String groupCode, String projectId, String userId);
+	Map<String, Object> downloadDict(String groupCode, String projectId, String userId);
+
+	Map<String, Object> downloadConfig(String groupCode, String projectId, String userId);
 
 	Map<String, Object> downloadFrameData(String groupCode, String projectId, String userId);
 

+ 42 - 46
src/main/java/com/persagy/bdtp/adm/service/impl/SyncAppImpl.java

@@ -24,6 +24,7 @@ import com.persagy.dmp.common.constant.ResponseCode;
 import com.persagy.dmp.common.constant.ValidEnum;
 import com.persagy.dmp.common.helper.SpringHelper;
 import com.persagy.dmp.common.model.response.CommonResult;
+import com.persagy.dmp.define.entity.ObjectInfoDefine;
 import com.persagy.dmp.define.entity.RelationDefine;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -90,10 +91,14 @@ public class SyncAppImpl implements ISyncApp {
 //	@Autowired
 //	ResourceLoader resourceLoader;
 
+
 	@Override
-	public Map<String, Object> downloadDictAndConfig(String groupCode, String projectId, String userId) {
-		Map<String, Object> dict = queryDict(groupCode, projectId, userId);
+	public Map<String, Object> downloadDict(String groupCode, String projectId, String userId) {
+		return queryDict(groupCode, projectId, userId, true, true);
+	}
 
+	@Override
+	public Map<String, Object> downloadConfig(String groupCode, String projectId, String userId) {
 		//配置数据查询
 		List<AdmM2dEquip> m2dTypes = configService.queryM2dEquip(projectId);
 		List<AdmInfosConfig> infosConfig = configService.queryInfosConfig(projectId);
@@ -104,7 +109,6 @@ public class SyncAppImpl implements ISyncApp {
 		List<AdmContainerConfig> containerConfig = configService.queryContainerConfig(projectId);
 
 		HashMap<String, Object> data = new HashMap<>();
-		data.put("dict", dict);
 		data.put("m2dTypes", m2dTypes);
 		data.put("infosConfig", serializeJsonProp(infosConfig));
 		data.put("relConfig", relConfig);
@@ -117,7 +121,9 @@ public class SyncAppImpl implements ISyncApp {
 	}
 
 	@Override
-	public Map<String, Object> queryDict(String groupCode, String projectId, String userId){
+	public Map<String, Object> queryDict(String groupCode, String projectId, String userId, boolean includeRel, boolean includeInfos){
+		boolean newDict = "JD".equalsIgnoreCase(groupCode);
+
 		//从知识库服务获取专业分类
 		QueryCriteria majorCriteria = ServiceUtil.getQueryCriteria(null, objectMapper);
 		majorCriteria.getCriteria().put("type", "major");
@@ -128,11 +134,8 @@ public class SyncAppImpl implements ISyncApp {
 		criteria.getCriteria().putArray("objType").add("system").add("equipment");
 		List<TypeDef> typeList = queryAllPage(() -> rwdClient.queryObjectType(groupCode, projectId, AdmConst.APP_ID, userId, criteria), criteria, new Pagination(500));
 
-		//查询关系定义
-		List<RelationDefine> relList = ServiceUtil.call(() -> rwdClient.queryRelDef(groupCode, projectId, AdmConst.APP_ID, userId, new QueryCriteria()));
-
 		//查询重命名设备类型
-		ObjectNode renameNode = configService.queryRenameEquipTypes(projectId);
+		ObjectNode renameNode = !newDict ? configService.queryRenameEquipTypes(projectId) : null;
 
 		LinkedList<TypeDef> sysList = new LinkedList<>();
 		LinkedList<TypeDef> equipList = new LinkedList<>();
@@ -140,10 +143,12 @@ public class SyncAppImpl implements ISyncApp {
 			if(def.getObjType().equals("system"))
 				sysList.add(def);
 			else if(def.getObjType().equals("equipment")) {
-				if (renameNode != null) { //设备类型重命名
-					JsonNode n = renameNode.get(def.getCode());
-					if(n != null)
-						def.setName(n.asText());
+				if(!newDict) {
+					if (renameNode != null) { //设备类型重命名
+						JsonNode n = renameNode.get(def.getCode());
+						if(n != null)
+							def.setName(n.asText());
+					}
 				}
 				equipList.add(def);
 			}
@@ -157,45 +162,36 @@ public class SyncAppImpl implements ISyncApp {
 //		}catch (Exception e) {
 //
 //		}
-		ArrayNode arr = configService.queryNewEquipTypes(projectId);
-		if(arr != null) {
-			try{
-				List<TypeDef> types = objectMapper.readValue(objectMapper.writeValueAsString(arr), new TypeReference<List<TypeDef>>(){});
-				equipList.addAll(types);
-			}catch (Exception e) {
+		if(!newDict) {
+			ArrayNode arr = configService.queryNewEquipTypes(projectId);
+			if(arr != null) {
+				try{
+					List<TypeDef> types = objectMapper.readValue(objectMapper.writeValueAsString(arr), new TypeReference<List<TypeDef>>(){});
+					equipList.addAll(types);
+				}catch (Exception e) {
 
+				}
 			}
 		}
 
-		//组织树形结构
-//		for(Map<String, Object> major : majorList){
-//			ArrayList<TypeDef> childrenSys = new ArrayList<>();
-//			major.put("children", childrenSys);
-//			String majorCode = (String) major.get("code");
-//			for(Iterator<TypeDef> sysIter = sysList.iterator();sysIter.hasNext();){
-//				TypeDef sysDef = sysIter.next();
-//				if(sysDef.getMajorCode() != null && sysDef.getMajorCode().equals(majorCode)){
-//					childrenSys.add(sysDef);
-//
-//					for(Iterator<TypeDef> equipIter = equipList.iterator();equipIter.hasNext();){
-//						TypeDef equipDef = equipIter.next();
-//						if(equipDef.getSystemCode() != null && equipDef.getSystemCode().equals(sysDef.getCode())){
-//							sysDef.addChild(equipDef);
-//							equipIter.remove();
-//						}
-//					}
-//
-//					sysIter.remove();
-//					break;
-//				}
-//			}
-//		}
-
 		HashMap<String, Object> data = new HashMap<>();
 		data.put("major", majorList);
 		data.put("system", sysList);
 		data.put("equipment", equipList);
-		data.put("relation", relList);
+
+		//查询关系定义
+		if(includeRel) {
+			List<RelationDefine> relList = ServiceUtil.call(() -> rwdClient.queryRelDef(groupCode, projectId, AdmConst.APP_ID, userId, new QueryCriteria()));
+			data.put("relation", relList);
+		}
+		//查询信息点定义
+		if(includeInfos) {
+			QueryCriteria qc = new QueryCriteria();
+			qc.setCriteria(objectMapper.createObjectNode());
+			List<InfoDef> funcList = ServiceUtil.call(() -> rwdClient.queryFunc(groupCode, projectId, AdmConst.APP_ID, userId, qc));
+			data.put("infos", funcList);
+		}
+
 		return data;
 	}
 
@@ -464,9 +460,9 @@ public class SyncAppImpl implements ISyncApp {
 
 	private <T extends BaseAdmEntity> List<T> serializeJsonProp(List<T> list){
 		//app端完善,不需要做tostr处理了
-		for(BaseAdmEntity entity : list) {
-			entity.serializeJsonProp();
-		}
+//		for(BaseAdmEntity entity : list) {
+//			entity.serializeJsonProp();
+//		}
 		return list;
 	}
 

+ 0 - 1
src/main/java/com/persagy/bdtp/adm/service/impl/SyncOldAdmImpl.java

@@ -33,7 +33,6 @@ import com.persagy.dmp.file.model.FileInfo;
 import com.persagy.dmp.file.model.FileInfoCreator;
 import com.persagy.dmp.storage.utils.FileStorageHelper;
 import feign.Response;
-import org.checkerframework.checker.units.qual.A;
 import org.locationtech.jts.geom.Polygon;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;

+ 47 - 0
src/main/java/com/persagy/bdtp/adm/util/DataExtrasUtil.java

@@ -0,0 +1,47 @@
+package com.persagy.bdtp.adm.util;
+
+import cn.hutool.core.util.ReflectUtil;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.persagy.dmp.digital.entity.ObjectDigital;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.HashSet;
+import java.util.Iterator;
+
+public class DataExtrasUtil {
+
+	private static HashSet<String> admObjFields = getEntityFields(ObjectDigital.class);
+
+	private static String objExtraCol = "infos";
+
+	private static HashSet<String> getEntityFields(Class<?> cls){
+		HashSet<String> set = new HashSet<String>();
+		Field[] fields = ReflectUtil.getFields(cls);
+		for(Field field : fields) {
+			if(Modifier.isStatic(field.getModifiers()))
+				continue;
+			TableField tableField = (TableField)field.getAnnotation(TableField.class);
+			if(tableField == null || tableField.exist())
+				set.add(field.getName());
+		}
+		return set;
+	}
+
+	public static void collectObjExtras(ObjectNode objNode){
+		ObjectNode extraNode = objNode.putObject(objExtraCol);
+		Iterator<String> iter = objNode.fieldNames();
+
+		while(iter.hasNext()) {
+			String fieldName = iter.next();
+			if(admObjFields.contains(fieldName))
+				continue;
+			else {
+				extraNode.set(fieldName, objNode.get(fieldName));
+				iter.remove();
+			}
+		}
+	}
+
+}