Browse Source

空间关联查询

yucheng 3 years ago
parent
commit
05b5fd1037

+ 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);
 	}
 }