Browse Source

空间关联查询

yucheng 3 years ago
parent
commit
e983072d03

+ 1 - 1
src/main/java/com/persagy/proxy/object/model/AdmSpace.java

@@ -44,7 +44,7 @@ public class AdmSpace extends AdmBaseEntity<AdmSpace> {
     /** 图片 - 信息点里已存在的信息点不应在实体中重复定义为其他格式 */
     private ArrayNode pic;
     /** 空间是否受影响 */
-    private String state;
+    private Integer state;
     /** 空间常驻人数 */
     private Integer permanentPeopleNum;
 

+ 86 - 81
src/main/java/com/persagy/proxy/report/controller/AdmReportEquipController.java

@@ -43,13 +43,12 @@ import org.springframework.web.bind.annotation.*;
 import javax.ws.rs.QueryParam;
 import java.lang.reflect.Field;
 import java.util.*;
-import java.util.stream.Collectors;
 
 /**
-*  设备报表API
-* @author lvxy
-* @date 2021/9/18
-*/
+ *  设备报表API
+ * @author lvxy
+ * @date 2021/9/18
+ */
 @RestController
 @RequestMapping("/equip-query")
 public class AdmReportEquipController {
@@ -171,7 +170,7 @@ public class AdmReportEquipController {
      */
     @GetMapping("/equip-compon")
     public AdmResponse getEquipCompon(@QueryParam("id") String id, @QueryParam("category") String category){
-        //return  rEquipComponService.getEquipCompon(id,category)        
+        //return  rEquipComponService.getEquipCompon(id,category)
         RequestData requestData = new RequestData();
         if(StrUtil.isNotEmpty(id)){
             requestData.setEquipmentId(id);
@@ -284,7 +283,7 @@ public class AdmReportEquipController {
             request.setName(AdmComponent.OBJ_TYPE);
             return pageQuery(request);
         }
-       return null;
+        return null;
     }
 
     /**
@@ -435,7 +434,7 @@ public class AdmReportEquipController {
         if(JSONUtil.isNull(equipUpDateEnclosureRequest)){
             return AdmResponse.failure(ResponseCode.A0400.getDesc()+",不能为空");
         }
-        
+
         List<EquipUpDateEnclosure> equipUpDateEnclosure = JSONUtil.toList(equipUpDateEnclosureRequest.get("content").toString(), EquipUpDateEnclosure.class);
         if(CollUtil.isNotEmpty(equipUpDateEnclosure)){
             Map<String, EquipUpDateEnclosure> equipUpDateEnclosureMap = CollUtil.fieldValueMap(equipUpDateEnclosure, BaseEntity.PROP_ID);
@@ -491,30 +490,39 @@ public class AdmReportEquipController {
         ObjectNode criteriaEquip = JsonNodeFactory.instance.objectNode();
         criteriaEquip.put("objType", AdmEquipment.OBJ_TYPE);
         criteriaEquip.put("taskState",-1);
-        ArrayNode array = criteriaEquip.putObject("modelId").putArray("$in");
-        equipComDelList.stream().forEach(nodeObj -> {
-            if(StrUtil.isNotEmpty(nodeObj.get("modelId").textValue())) {
-                array.add(nodeObj.get("modelId").textValue());
+        ArrayNode idList = criteriaEquip.putObject("modelId").putArray("$in");
+        // 组装结果Map 并 设置modelId数组
+        Map<String, ObjectNode> equipDelMap = new HashMap<>(equipComDelList.size());
+        for (ObjectNode equipComDel : equipComDelList) {
+            // 取id
+            JsonNode idNode = equipComDel.get("modelId");
+            if(idNode == null || !idNode.isTextual()) {
+                continue;
             }
-        });
+            // 设置默认count
+            JsonNode countNode = equipComDel.get("count");
+            if(countNode == null || !countNode.isIntegralNumber()) {
+                // 没有count,则设置为0
+                equipComDel.put("count", 0);
+            }
+            idList.add(idNode.textValue());
+            equipDelMap.put(idNode.textValue(), equipComDel);
+        }
         queryCriteriaEuip.setCriteria(criteriaEquip);
         List<ObjectNode> equipList = DigitalObjectFacade.query(AdmContextUtil.toDmpContext().getGroupCode(),AdmContextUtil.toDmpContext().getProjectId(),AdmCommonConstant.APP_ID,null, queryCriteriaEuip);
         if(CollUtil.isEmpty(equipList)){
             return AdmResponse.success(equipComDelList);
         }
-        Map<String, ObjectNode> equipDelMap = new HashMap<>(equipComDelList.size());
-        for (ObjectNode equipComDel : equipComDelList) {
-            String modelIdObj = equipComDel.get("modelId").toString();
-            equipDelMap.put(modelIdObj, equipComDel);
-        }
-        equipList.stream().forEach(euip -> {
-            String modelIdEq = euip.get("modelId").textValue();
-            if(equipDelMap.containsKey(modelIdEq)){
-                Integer count = Integer.parseInt(equipDelMap.get(modelIdEq).get("count").textValue()) + 1;
-                equipDelMap.get(modelIdEq).put("count", count);
+        // 按查询到的设备计数
+        equipList.stream().forEach(eq -> {
+            String modelId = eq.get("modelId").textValue();
+            if(equipDelMap.containsKey(modelId)){
+                ObjectNode delCounter = equipDelMap.get(modelId);
+                int count = delCounter.get("count").intValue() + 1;
+                delCounter.put("count", count);
             }
         });
-        return AdmResponse.success(equipDelMap.values().stream().collect(Collectors.toList()));
+        return AdmResponse.success(equipComDelList);
     }
 
 
@@ -527,8 +535,6 @@ public class AdmReportEquipController {
      */
     @PostMapping("/equip-supply")
     public AdmResponse equipPropertySupply(@RequestBody List<ObjectNode> equipComDelList){
-        //return EquipmentService.equipPropertySupplys(equipComDelList)
-        //
         if(CollUtil.isEmpty(equipComDelList)){
             return AdmResponse.success();
         }
@@ -536,14 +542,28 @@ public class AdmReportEquipController {
         QueryCriteria queryCriteria = new QueryCriteria();
         ObjectNode criteria = JsonNodeFactory.instance.objectNode();
         criteria.put("objType", AdmFloor.OBJ_TYPE);
-        ArrayNode arrayNode = criteria.putObject("modelId").putArray("$in");
-        equipComDelList.stream().forEach(node -> {
-            arrayNode.add(node.get("modelId").textValue());
-        });
+        ArrayNode idList = criteria.putObject("modelId").putArray("$in");
+        // 组装结果Map 并 设置modelId数组
+        Map<String, ObjectNode> equipDelMap = new HashMap<>(equipComDelList.size());
+        for (ObjectNode equipComDel : equipComDelList) {
+            // 取id
+            JsonNode idNode = equipComDel.get("modelId");
+            if(idNode == null || !idNode.isTextual()) {
+                continue;
+            }
+            // 设置默认count
+            JsonNode countNode = equipComDel.get("count");
+            if(countNode == null || !countNode.isIntegralNumber()) {
+                // 没有count,则设置为0
+                equipComDel.put("count", 0);
+            }
+            idList.add(idNode.textValue());
+            equipDelMap.put(idNode.textValue(), equipComDel);
+        }
         queryCriteria.setCriteria(criteria);
         List<ObjectNode> floorList = DigitalObjectFacade.query(AdmContextUtil.toDmpContext().getGroupCode(),AdmContextUtil.toDmpContext().getProjectId(),AdmCommonConstant.APP_ID,null,queryCriteria);
         if(CollUtil.isEmpty(floorList)){
-            return AdmResponse.success();
+            return AdmResponse.success(equipComDelList);
         }
         List<AdmFloor> admFloorList = JSONUtil.toList(floorList.toString(), AdmFloor.class);
         Map<String, AdmFloor> admFloorMap = CollUtil.fieldValueMap(admFloorList, BaseEntity.PROP_ID);
@@ -553,46 +573,33 @@ public class AdmReportEquipController {
         criteriaEquip.put("objType", AdmEquipment.OBJ_TYPE);
         ArrayNode array = criteriaEquip.putObject("floorId").putArray("$in");
         admFloorMap.keySet().stream().forEach(id -> array.add(id));
-
-        JSONObject bimId = new JSONObject();
-        bimId.put("$null", true);
-        criteria.putPOJO("bimId", bimId);
-
-        JSONObject bimLocation = new JSONObject();
-        bimId.put("$null", false);
-        criteriaEquip.putPOJO("bimLocation", bimLocation);
-
-        JSONObject modelId = new JSONObject();
-        modelId.put("$null", true);
-        criteriaEquip.putPOJO("modelId", modelId);
-
+        criteria.putObject("bimId").put("$null", true);
+        criteria.putObject("bimLocation").put("$null", false);
+        criteria.putObject("modelId").put("$null", true);
         queryCriteriaEuip.setCriteria(criteriaEquip);
         List<ObjectNode> equipList = DigitalObjectFacade.query(AdmContextUtil.toDmpContext().getGroupCode(),AdmContextUtil.toDmpContext().getProjectId(),AdmCommonConstant.APP_ID,null, queryCriteriaEuip);
         if(CollUtil.isEmpty(equipList)){
             return AdmResponse.success(equipComDelList);
         }
+        // 按楼层统计设备数量
         equipList.stream().forEach(equip -> {
-            String floolId = equip.get("floorId").textValue();
-            if(admFloorMap.containsKey(floolId)){
-                Integer count = Integer.parseInt(admFloorMap.get(floolId).getCount()) + 1;
-                admFloorMap.get(floolId).setCount(count.toString());
+            String floorId = equip.get("floorId").textValue();
+            if(admFloorMap.containsKey(floorId)){
+                AdmFloor floor = admFloorMap.get(floorId);
+                Integer count = floor.getCount() == null ? 0 : Integer.parseInt(floor.getCount());
+                floor.setCount(String.valueOf(count+1));
             }
         });
-
         // 3 根据floorId,modelId 汇总
-        Map<String, ObjectNode> equipDelMap = new HashMap<>(equipComDelList.size());
-        for (ObjectNode equipComDel : equipComDelList) {
-           String modelIdObj = equipComDel.get("modelId").toString();
-           equipDelMap.put(modelIdObj, equipComDel);
-        }
         admFloorMap.values().stream().forEach(floor -> {
-            String modelIdFl = floor.getModelId();
-            if(equipDelMap.containsKey(modelIdFl)){
-                Integer count = Integer.parseInt(equipDelMap.get(modelIdFl).get("count").textValue()) + Integer.parseInt(floor.getCount());
-                equipDelMap.get(modelIdFl).put("count", count);
+            String modelId = floor.getModelId();
+            if(equipDelMap.containsKey(modelId)){
+                ObjectNode delCounter = equipDelMap.get(modelId);
+                int count = delCounter.get("count").intValue() + Integer.parseInt(floor.getCount());
+                delCounter.put("count", count);
             }
         });
-        return AdmResponse.success(equipDelMap.values().stream().collect(Collectors.toList()));
+        return AdmResponse.success(equipComDelList);
     }
 
     /**
@@ -624,7 +631,7 @@ public class AdmReportEquipController {
      */
     @PostMapping("/property-equip-supp")
     public AdmResponse propertyEquip(@RequestBody AdmQueryCriteria request){
-        
+
         //return EquipmentService.equipPropertySupp(sQueryRequest)
         //equipment.bim_id IS NULL
         //  AND equipment.model_id IS NULL
@@ -669,23 +676,23 @@ public class AdmReportEquipController {
             filter =  filter + ";id in "+arrayNode.toString();
             request.setFilters(filter);
 
-           AdmResponse admResponse = equipmentService.query(request);
-           if(CollUtil.isNotEmpty(admResponse.getContent())){
-               //处理数据
-               List<ObjectNode> objectNodeList = (List<ObjectNode>) admResponse.getContent();
-               objectNodeList.stream().forEach(equip ->{
-                   JsonNode building = equip.get("building");
-                   JsonNode floor = equip.get("floor");
-                   if(!JSONUtil.isNull(building)){
-                       equip.put("buildingName", building.get("localName").textValue());
-                   }
-                   if(!JSONUtil.isNull(floor)){
-                       equip.put("floorName", floor.get("localName").textValue());
-                       equip.put("modelId", floor.get("modelId").textValue());
-                   }
-               });
-           }
-           return admResponse;
+            AdmResponse admResponse = equipmentService.query(request);
+            if(CollUtil.isNotEmpty(admResponse.getContent())){
+                //处理数据
+                List<ObjectNode> objectNodeList = (List<ObjectNode>) admResponse.getContent();
+                objectNodeList.stream().forEach(equip ->{
+                    JsonNode building = equip.get("building");
+                    JsonNode floor = equip.get("floor");
+                    if(!JSONUtil.isNull(building)){
+                        equip.put("buildingName", building.get("localName").textValue());
+                    }
+                    if(!JSONUtil.isNull(floor)){
+                        equip.put("floorName", floor.get("localName").textValue());
+                        equip.put("modelId", floor.get("modelId").textValue());
+                    }
+                });
+            }
+            return admResponse;
         }else{
             return AdmResponse.success();
         }
@@ -814,7 +821,7 @@ public class AdmReportEquipController {
         AdmGatherInfoPoint gatherInfoPoint = new AdmGatherInfoPoint();
 
         Integer controlInfoCounts = controlInfoCounts(AdmEquipment.OBJ_TYPE);
-       // 根据objType获取定义 获取采集的设备的classcode
+        // 根据objType获取定义 获取采集的设备的classcode
         Set<String> objTypes = new HashSet<>(1);
         objTypes.add(AdmEquipment.OBJ_TYPE);
         List<Map<String, Object>> codes = DigitalObjectSimpleFacade.queryDefineInfoByObjType(AdmContextUtil.toDmpContext().getGroupCode(), AdmContextUtil.toDmpContext().getProjectId(), AdmCommonConstant.APP_ID,null, RequestData.builder().objTypes(objTypes).build());
@@ -935,7 +942,7 @@ public class AdmReportEquipController {
         queryCriteria.setOnlyCount(true);
         List<ObjectNode> euipCom = DigitalObjectFacade.query(AdmContextUtil.toDmpContext().getGroupCode(),AdmContextUtil.toDmpContext().getProjectId(),AdmCommonConstant.APP_ID,null, queryCriteria);
         if(CollUtil.isNotEmpty(euipCom)){
-           return AdmResponse.success(euipCom);
+            return AdmResponse.success(euipCom);
         }else{
             return AdmResponse.success();
         }
@@ -1165,6 +1172,4 @@ public class AdmReportEquipController {
             infos.put(attribute, upTarget);
         }
     }
-
-
 }