Browse Source

Merge branch 'develop' of http://39.106.8.246:3003/BDTP/adm-middleware.git into develop

zhangqiankun 3 years ago
parent
commit
6d54da2a5c

+ 4 - 6
src/main/java/com/persagy/proxy/object/controller/AdmSpaceController.java

@@ -29,10 +29,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.ws.rs.QueryParam;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 /**
  * Adm 空间 API
@@ -151,7 +148,7 @@ public class AdmSpaceController {
                         if(flowBuild.startsWith("Bd")){
                             admSpace.setBuildingId(flowBuild);
                             Map<String, Object> infos = new HashMap<String,Object>(16);
-                            infos.put("$remove","['floorId']");
+                            infos.put("$remove", Arrays.asList("floorId"));
                             admSpace.setInfos(infos);
                         }
                     }else {
@@ -164,9 +161,10 @@ public class AdmSpaceController {
                             admSpace.setFloorId(str[0]);
                         }
                     }
+                    admSpace.setFlowBuild(null);
                 }else{
                     Map<String, Object> infos = new HashMap<String,Object>(16);
-                    infos.put("$remove","['floorId','buildingId']");
+                    infos.put("$remove",Arrays.asList("floorId","buildingId"));
                     admSpace.setInfos(infos);
                 }
             });

+ 27 - 5
src/main/java/com/persagy/proxy/relation/controller/RelationShInBdController.java

@@ -1,6 +1,7 @@
 package com.persagy.proxy.relation.controller;
 
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.map.MapUtil;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.persagy.dmp.basic.model.QueryCriteria;
@@ -23,9 +24,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -61,7 +60,7 @@ public class RelationShInBdController {
         QueryCriteria criteria = new QueryCriteria();
         ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
         ObjectNode queryObj = objectMapper.createObjectNode();
-        queryObj.set("objFrom",objectMapper.readTree(objectMapper.writeValueAsString(buildingIdList)));
+        //queryObj.set("objFrom",objectMapper.readTree(objectMapper.writeValueAsString(buildingIdList)));
         queryObj.put("objTo",shaftId);
         queryObj.put("graphCode",graphCode);
         queryObj.put("relCode",relCode);
@@ -70,7 +69,7 @@ public class RelationShInBdController {
         List<ObjectRelation> relations = service.queryByCondition(AdmContextUtil.toDmpContext(), criteria);
         Set<String> havedBuildIds = CollUtil.newHashSet(CollUtil.isNotEmpty(relations),
                 relations.stream().map(ObjectRelation::getObjFrom).collect(Collectors.toSet()));
-        // 组装关系
+        // 3.新增新的关系
         for (String buildingId : buildingIdList) {
             if (havedBuildIds.contains(buildingId)){
                 continue;
@@ -80,6 +79,29 @@ public class RelationShInBdController {
             voList.add(relation);
         }
         service.doSave(AdmContextUtil.toDmpContext(), voList);
+        // 4.删除旧的关系
+        Set<String> deleteRelationIds = new HashSet<>();
+        if (CollUtil.isNotEmpty(relations)){
+            Map<String, List<ObjectRelation>> buildMap = relations.stream()
+                    .collect(Collectors.groupingBy(ObjectRelation::getObjFrom));
+            Set<Map.Entry<String, List<ObjectRelation>>> entries = buildMap.entrySet();
+            for (Map.Entry<String, List<ObjectRelation>> entry : entries) {
+                if (buildingIdList.contains(entry.getKey())
+                        || CollUtil.isEmpty(entry.getValue())){
+                    continue;
+                }
+                // 需删除的关系
+                deleteRelationIds
+                        .addAll(entry.getValue().stream().map(ObjectRelation::getId).collect(Collectors.toSet()));
+            }
+        }
+        if (CollUtil.isNotEmpty(deleteRelationIds)){
+            QueryCriteria deleteParam = new QueryCriteria();
+            ObjectNode deleteObj = objectMapper.createObjectNode();
+            deleteObj.set("id",objectMapper.readTree(objectMapper.writeValueAsString(deleteRelationIds)));
+            deleteParam.setCriteria(deleteObj);
+            service.doDelete(AdmContextUtil.toDmpContext(),deleteParam);
+        }
         return AdmResponse.success();
     }
 

+ 31 - 51
src/main/java/com/persagy/proxy/report/controller/AdmSpaceInfoController.java

@@ -1,18 +1,6 @@
 package com.persagy.proxy.report.controller;
 
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.QueryParam;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-import com.alibaba.fastjson.JSONObject;
-import com.fasterxml.jackson.databind.node.JsonNodeFactory;
-import com.fasterxml.jackson.databind.node.ObjectNode;
+import cn.hutool.core.util.StrUtil;
 import com.persagy.dmp.common.constant.ResponseCode;
 import com.persagy.proxy.adm.request.AdmDCSQueryRequest;
 import com.persagy.proxy.adm.request.AdmQueryCriteria;
@@ -24,12 +12,18 @@ import com.persagy.proxy.object.model.AdmSystem;
 import com.persagy.proxy.object.service.IAdmEquipmentService;
 import com.persagy.proxy.object.service.IAdmISpaceService;
 import com.persagy.proxy.object.service.IAdmSystemService;
-
-import cn.hutool.core.util.StrUtil;
 import lombok.RequiredArgsConstructor;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.QueryParam;
 
 /**
- * 
+ *
  * @version 1.0.0
  * @company persagy
  * @author zhangqiankun
@@ -40,28 +34,23 @@ import lombok.RequiredArgsConstructor;
 @RequestMapping("/space")
 public class AdmSpaceInfoController {
 
-	@Value("${middleware.group.code}")
-	private String defaultCode;
 	@Autowired
 	private IAdmISpaceService ispaceService;
 	@Autowired
 	private IAdmSystemService systemService;
 	@Autowired
 	private IAdmEquipmentService equipmentService;
-	
 	/**
 	 * 统计 属于多建筑楼层的空间
-	 * 
+	 *
 	 * @param request
 	 * @return
 	 */
 	@RequestMapping("/space-bd-fl")
-	public JSONObject queryCount(HttpServletRequest request) {
-		JSONObject result = new JSONObject();
-		result.put("count", 0);
-		result.put("message", "");
-		result.put("result", "success");
-		return result;
+	public AdmResponse queryCount(HttpServletRequest request) {
+		AdmResponse response = AdmResponse.success();
+		response.setCount(0L);
+		return response;
 	}
 
 	/**
@@ -74,14 +63,9 @@ public class AdmSpaceInfoController {
 	 */
 	@RequestMapping("/unspace-in-sys")
 	public AdmResponse unSpaceSys(@QueryParam("type") String type, @QueryParam("spaceId") String spaceId, @RequestBody AdmQueryCriteria request){
-		//sy2sp
-		ObjectNode relationFrom = JsonNodeFactory.instance.objectNode();
-		relationFrom.put("relCode", "Sy2Sp");
-		relationFrom.put("graphCode", "MechInArch");
-		relationFrom.put("objTo", spaceId);
-		relationFrom.put("$bindFlag",false);
-		request.setRelationFrom(relationFrom);
 		request.setName(AdmSystem.OBJ_TYPE);
+		// 设置关系条件
+		request.resetRelationCond(true, "MechInArch", "Sy2Sp", spaceId, false);
 		return systemService.doQuery(AdmContextUtil.toDmpContext(),request, AdmSystem.class);
 	}
 
@@ -127,20 +111,20 @@ public class AdmSpaceInfoController {
 	 */
 	@PostMapping("/unspace-ispace")
 	public AdmResponse unSpaceIspace(@QueryParam("objectType") String objectType, @RequestBody AdmDCSQueryRequest request) {
-		//si2sp
-		ObjectNode relationFrom = JsonNodeFactory.instance.objectNode();
-		relationFrom.put("relCode", "Si2Sp");
-		relationFrom.put("$bindFlag",false);
-		request.setRelationFrom(relationFrom);
 		request.setName(AdmISpace.OBJ_TYPE);
-		String floorFilter = "floorId = '" + request.getFloorId()+"'";
-		if(StrUtil.isNotEmpty(request.getFilters())){
-			request.setFilters(request.getFilters()+";"+floorFilter);
-		}else{
-			request.setFilters(floorFilter);
+		// 设置关系条件
+		request.resetRelationCond(true, null, "Si2Sp", objectType, null, false);
+		StringBuilder sb = new StringBuilder();
+		// 补充filter条件
+		if(StrUtil.isNotBlank(request.getFilters())) {
+			sb.append(request.getFilters() + ";");
+		}
+		// 补充楼层条件
+		if(StrUtil.isNotBlank(request.getFloorId())) {
+			sb.append("floorId = '" + request.getFloorId()+"';");
 		}
-		if(StrUtil.isNotEmpty(objectType)){
-			request.setFilters(request.getFilters()+"; classCode='"+objectType+"'");
+		if(sb.length() > 0) {
+			request.setFilters(sb.substring(0, sb.length() - 1));
 		}
 		return ispaceService.doQuery(AdmContextUtil.toDmpContext(),request, AdmISpace.class);
 	}
@@ -150,12 +134,8 @@ public class AdmSpaceInfoController {
 			return AdmResponse.failure(ResponseCode.A0400.getDesc() + "空间id为空");
 		}
 		request.setName(AdmEquipment.OBJ_TYPE);
-		ObjectNode relationFrom = JsonNodeFactory.instance.objectNode();
-		relationFrom.put("relCode", "Eq2Sp");
-		relationFrom.put("graphCode", graphCode);
-		relationFrom.put("objTo", spaceId);
-		relationFrom.put("$bindFlag", false);
-		request.setRelationFrom(relationFrom);
+		// 设置关系条件
+		request.resetRelationCond(true, graphCode, "Eq2Sp", type, spaceId, false);
 		return equipmentService.doQuery(AdmContextUtil.toDmpContext(), request, AdmEquipment.class);
 	}
 }