Jelajahi Sumber

建筑:增加验证
租户:objType调整
空间:接口中关系处理调整

lvxianyun 3 tahun lalu
induk
melakukan
c28a15f3f5

+ 66 - 5
src/main/java/com/persagy/proxy/adm/controller/AdmBuildingController.java

@@ -1,12 +1,16 @@
 package com.persagy.proxy.adm.controller;
 
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.StrUtil;
+import com.persagy.dmp.common.model.entity.BaseEntity;
 import com.persagy.proxy.adm.constant.AdmCommonConstant;
-import com.persagy.proxy.adm.model.AdmBuilding;
+import com.persagy.proxy.adm.model.*;
 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.adm.service.IAdmBuildingService;
+import com.persagy.proxy.adm.service.*;
+import com.persagy.proxy.adm.utils.ObjectNameUtil;
+import com.persagy.proxy.common.entity.DmpResult;
 import com.persagy.proxy.common.entity.InstanceUrlParam;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -17,6 +21,7 @@ import org.springframework.web.bind.annotation.RestController;
 
 import javax.ws.rs.QueryParam;
 import java.util.List;
+import java.util.Map;
 
 /**
  * ADM 建筑 API
@@ -29,6 +34,14 @@ public class AdmBuildingController {
 
     @Autowired
     private IAdmBuildingService service;
+    @Autowired
+    private IAdmEquipmentService equipmentService;
+    @Autowired
+    private IAdmFloorService floorService;
+    @Autowired
+    private IAdmISpaceService iAdmISpaceService;
+    @Autowired
+    private IAdmSpaceService spaceService;
     @Value("${middleware.group.code}")
     private String groupCode;
 
@@ -44,6 +57,11 @@ public class AdmBuildingController {
         InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
         List<AdmBuilding> vos = CollUtil.newArrayList(createRequest.getContent());
         vos = service.doInsert(context, AdmBuilding.class, vos);
+        vos.stream().forEach(admBuilding -> {
+            if (StrUtil.isEmpty(admBuilding.getName())){
+                admBuilding.setName(ObjectNameUtil.objectName("建筑-"));
+            }
+        });
         return AdmResponse.success(vos);
     }
 
@@ -57,6 +75,46 @@ public class AdmBuildingController {
     public AdmResponse delete(@RequestBody List<AdmBuilding> vos) throws Exception {
         // 组装上下文条件
         InstanceUrlParam context = new InstanceUrlParam(groupCode, null, null, AdmCommonConstant.APP_ID);
+        if(CollUtil.isEmpty(vos)){
+            return AdmResponse.failure("参数不能为空");
+        }
+        //验证楼层 空间 设备 等信息是否存在,不存在关系可以删除
+        Map<String, AdmBuilding> admBuildingMap = CollUtil.fieldValueMap(vos, BaseEntity.PROP_ID);
+        String msg = "建筑下包含其他对象实例,请解除关系后删除";
+        AdmQueryCriteria admQueryCriteria = new AdmQueryCriteria();
+        StringBuilder stringBuilder = new StringBuilder();
+        stringBuilder.append("buildingId in [");
+        admBuildingMap.keySet().stream().forEach(buildingId -> {
+            stringBuilder.append("'").append(buildingId).append("'").append(",");
+        });
+
+        String filters = StrUtil.sub(stringBuilder.toString(),0, -1);
+        filters+= "]";
+
+        admQueryCriteria.setFilters(filters);
+        admQueryCriteria.setOnlyCount(true);
+
+        admQueryCriteria.setName("floor");
+        AdmResponse admResponseF = floorService.doQuery(context, admQueryCriteria, AdmFloor.class);
+        if(DmpResult.SUCCESS.equals(admResponseF.getResult()) && admResponseF.getTotal() > 0){
+            return AdmResponse.failure(msg);
+        }
+        admQueryCriteria.setName("space");
+        AdmResponse admResponseSpace = spaceService.doQuery(context, admQueryCriteria, AdmSpace.class);
+        if(admResponseSpace.getResult().equals(DmpResult.SUCCESS) && admResponseSpace.getTotal() > 0){
+            return AdmResponse.failure(msg);
+        }
+        admQueryCriteria.setName("ispace");
+        AdmResponse admResponseISpace = iAdmISpaceService.doQuery(context, admQueryCriteria, AdmISpace.class);
+        if(admResponseISpace.getResult().equals(DmpResult.SUCCESS) && admResponseISpace.getTotal() > 0){
+            return AdmResponse.failure(msg);
+        }
+
+        admQueryCriteria.setName("equipment");
+        AdmResponse admResponseEuip = equipmentService.doQuery(context, admQueryCriteria, AdmEquipment.class);
+        if(admResponseEuip.getResult().equals(DmpResult.SUCCESS) && admResponseEuip.getTotal() > 0){
+            return AdmResponse.failure(msg);
+        }
         service.doDelete(context, vos);
         return AdmResponse.success();
     }
@@ -69,9 +127,7 @@ public class AdmBuildingController {
      */
     @PostMapping("/single/delete")
     public AdmResponse deleteSingle(@RequestBody List<AdmBuilding> vos) throws Exception {
-        // 组装上下文条件
-        InstanceUrlParam context = new InstanceUrlParam(groupCode, null, null, AdmCommonConstant.APP_ID);
-        service.doDelete(context, vos);
+        delete(vos);
         return AdmResponse.success();
     }
 
@@ -86,6 +142,11 @@ public class AdmBuildingController {
         // 组装上下文条件
         InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
         List<AdmBuilding> vos = CollUtil.newArrayList(createRequest.getContent());
+        vos.forEach(admBuilding -> {
+            if(StrUtil.isEmpty(admBuilding.getName())){
+                admBuilding.setName(ObjectNameUtil.objectName("建筑-"));
+            }
+        });
         vos = service.doUpdate(context, AdmBuilding.class, vos);
         return AdmResponse.success(vos);
     }

+ 16 - 15
src/main/java/com/persagy/proxy/adm/controller/AdmSpaceController.java

@@ -3,9 +3,7 @@ package com.persagy.proxy.adm.controller;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.json.JSONUtil;
-import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
-import com.fasterxml.jackson.databind.node.ArrayNode;
 import com.fasterxml.jackson.databind.node.JsonNodeFactory;
 import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.persagy.dmp.basic.model.QueryCriteria;
@@ -18,7 +16,6 @@ import com.persagy.proxy.adm.service.IAdmBuildingService;
 import com.persagy.proxy.adm.service.IAdmFloorService;
 import com.persagy.proxy.adm.service.IAdmRelationService;
 import com.persagy.proxy.adm.service.IAdmSpaceService;
-import com.persagy.proxy.common.entity.DmpResult;
 import com.persagy.proxy.common.entity.InstanceUrlParam;
 import com.persagy.proxy.common.entity.RelationDTO;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -107,6 +104,12 @@ public class AdmSpaceController {
         // 组装上下文条件
         InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
         service.doDelete(context, vos);
+        QueryCriteria queryCriteria = new QueryCriteria();
+        vos.forEach(vo -> {
+            /** 清除空间和建筑楼层的的数据 */
+            dealRelation(vo.getId(),context,queryCriteria,"Bd2Sp");
+            dealRelation(vo.getId(),context,queryCriteria,"Fl2Sp");
+        });
         return AdmResponse.success();
     }
 
@@ -195,7 +198,6 @@ public class AdmSpaceController {
         }
         // 组装上下文条件
         InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
-        //List<AdmSpace> vos = service.doUpdateFloorORBuilding(context, upDataFloorAndBuildingRequestsList);
         //TODO 循环删除 需要改为 批量删除
         List<RelationDTO> RSpInBd_up = new ArrayList<>();
         List<RelationDTO> RSpInFl_up = new ArrayList<>();
@@ -207,17 +209,8 @@ public class AdmSpaceController {
             String type = requestData.getType();//classCode
 
             /** 清除空间和建筑楼层的的数据 */
-            ObjectNode rBd = JsonNodeFactory.instance.objectNode();
-            rBd.put("objTo",spaceId);
-            rBd.put("relCode","Bd2Sp");
-            queryCriteria.setCriteria(rBd);
-            relationService.doDelete(context, queryCriteria);
-
-            ObjectNode rFl = JsonNodeFactory.instance.objectNode();
-            rFl.put("objTo",spaceId);
-            rFl.put("relCode","Fl2Sp");
-            queryCriteria.setCriteria(rFl);
-            relationService.doDelete(context, queryCriteria);
+            dealRelation(spaceId,context,queryCriteria,"Bd2Sp");
+            dealRelation(spaceId,context,queryCriteria,"Fl2Sp");
 
             if(StrUtil.isNotEmpty(id)){
                 if(id.startsWith("Fl") && StrUtil.isNotEmpty(spaceId)){
@@ -367,4 +360,12 @@ public class AdmSpaceController {
         return service.doQuery(context, request, AdmSpace.class);
     }
 
+
+    private void dealRelation(String spaceId, InstanceUrlParam context, QueryCriteria queryCriteria, String relCode){
+        ObjectNode rBd = JsonNodeFactory.instance.objectNode();
+        rBd.put("objTo",spaceId);
+        rBd.put("relCode",relCode);
+        queryCriteria.setCriteria(rBd);
+        relationService.doDelete(context, queryCriteria);
+    }
 }

+ 3 - 3
src/main/java/com/persagy/proxy/adm/controller/AdmTenantController.java

@@ -44,7 +44,7 @@ public class AdmTenantController {
                              @RequestBody AdmQueryCriteria request) throws Exception {
         // 组装上下文条件
         InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
-        request.setName("tenant");
+        request.setName("virtual");
         request.setOnlyCount(true);
         return service.doQuery(context, request, AdmTenant.class);
     }
@@ -105,7 +105,7 @@ public class AdmTenantController {
                              @RequestBody AdmQueryCriteria request) throws Exception {
         // 组装上下文条件
         InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
-        request.setName("tenant");
+        request.setName("virtual");
         return service.doQuery(context, request, AdmTenant.class);
     }
 
@@ -122,7 +122,7 @@ public class AdmTenantController {
                              @RequestBody AdmQueryCriteria request) throws Exception {
         // 组装上下文条件
         InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
-        request.setName("tenant");
+        request.setName("virtual");
         return service.doQuery(context, request, AdmTenant.class);
     }