瀏覽代碼

解决模型绑定后,设备楼层ID、建筑ID为空问题

yucheng 3 年之前
父節點
當前提交
925e7feb83
共有 1 個文件被更改,包括 18 次插入8 次删除
  1. 18 8
      src/main/java/com/persagy/proxy/dictionary/service/impl/AdmModelRelServiceImpl.java

+ 18 - 8
src/main/java/com/persagy/proxy/dictionary/service/impl/AdmModelRelServiceImpl.java

@@ -117,12 +117,12 @@ public class AdmModelRelServiceImpl extends AbstractAdmBaseServiceImpl<AdmModelR
     private void processRelObjects(InstanceUrlParam context, String oldBimId, String bimId, AdmFloor floor) {
         // 如果bimId不一致,则清空原来的楼层信息
         if(StrUtil.isNotBlank(oldBimId) && !StrUtil.equals(oldBimId, bimId)) {
-            updateRelEquipments(context, oldBimId, null);
-            updateRelISpace(context, oldBimId, null);
+            updateRelEquipments(context, oldBimId, floor, true);
+            updateRelISpace(context, oldBimId, floor, true);
         }
         // 更新新关联的
-        updateRelEquipments(context, bimId, floor);
-        updateRelISpace(context, bimId, floor);
+        updateRelEquipments(context, bimId, floor, false);
+        updateRelISpace(context, bimId, floor, false);
     }
 
     /**
@@ -131,13 +131,18 @@ public class AdmModelRelServiceImpl extends AbstractAdmBaseServiceImpl<AdmModelR
      * @param bimId
      * @param floor
      */
-    private void updateRelEquipments(InstanceUrlParam context, String bimId, AdmFloor floor) {
+    private void updateRelEquipments(InstanceUrlParam context, String bimId,
+                                     AdmFloor floor, boolean deleteFlag) {
         if(StrUtil.isBlank(bimId)) {
             return;
         }
         //查询模型下的设备信息
         AdmQueryCriteria criteria = new AdmQueryCriteria();
         criteria.addFilters("bimId startwith '" + bimId + ":'");
+        // 如果是删除,只删本楼层的
+        if(deleteFlag) {
+            criteria.addFilters("floorId = '" + floor.getId() + "'");
+        }
         criteria.setName(AdmEquipment.OBJ_TYPE);
         AdmResponse admResponse = equipmentService.doQuery(context, criteria, AdmEquipment.class);
         List<AdmEquipment> content = (List<AdmEquipment>) admResponse.getContent();
@@ -147,7 +152,7 @@ public class AdmModelRelServiceImpl extends AbstractAdmBaseServiceImpl<AdmModelR
         List<String> nullList = CollUtil.newArrayList("buildingId", "floorId");
         List<AdmEquipment> rsList = new ArrayList<>();
         for (AdmEquipment admEquipment : content) {
-            if(floor == null) {
+            if(deleteFlag) {
                 admEquipment.setNullList(nullList);
                 rsList.add(admEquipment);
                 continue;
@@ -172,13 +177,18 @@ public class AdmModelRelServiceImpl extends AbstractAdmBaseServiceImpl<AdmModelR
      * @param bimId
      * @param floor
      */
-    private void updateRelISpace(InstanceUrlParam context, String bimId, AdmFloor floor) {
+    private void updateRelISpace(InstanceUrlParam context, String bimId,
+                                 AdmFloor floor, boolean deleteFlag) {
         if(StrUtil.isBlank(bimId)) {
             return;
         }
         //查询模型下的设备信息
         AdmQueryCriteria criteria = new AdmQueryCriteria();
         criteria.addFilters("bimId startwith '" + bimId + ":'");
+        // 如果是删除,只删本楼层的
+        if(deleteFlag) {
+            criteria.addFilters("floorId = '" + floor.getId() + "'");
+        }
         criteria.setName(AdmISpace.OBJ_TYPE);
         AdmResponse admResponse = iSpaceService.doQuery(context, criteria, AdmISpace.class);
         List<AdmISpace> content = (List<AdmISpace>) admResponse.getContent();
@@ -187,7 +197,7 @@ public class AdmModelRelServiceImpl extends AbstractAdmBaseServiceImpl<AdmModelR
         }
         List<String> nullList = CollUtil.newArrayList("buildingId", "floorId");
         for (AdmISpace iSpace : content) {
-            if(floor == null) {
+            if(deleteFlag) {
                 iSpace.setNullList(nullList);
                 continue;
             }