Browse Source

fix : space 更新 楼层和建筑的关系丢失

lvxianyun 3 years ago
parent
commit
04b9bfb433

+ 42 - 1
src/main/java/com/persagy/proxy/object/controller/AdmSpaceController.java

@@ -8,6 +8,8 @@ import com.fasterxml.jackson.databind.node.JsonNodeFactory;
 import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.persagy.dmp.basic.model.QueryCriteria;
 import com.persagy.dmp.basic.utils.JsonNodeUtils;
+import com.persagy.dmp.common.model.entity.BaseEntity;
+import com.persagy.proxy.adm.constant.AdmRelationTypeEnum;
 import com.persagy.proxy.adm.handler.SpaceRelationInfoHandler;
 import com.persagy.proxy.adm.request.*;
 import com.persagy.proxy.adm.service.IAdmRelationService;
@@ -29,6 +31,7 @@ import org.springframework.web.bind.annotation.RestController;
 import javax.ws.rs.QueryParam;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 
 /**
  * Adm 空间 API
@@ -118,7 +121,45 @@ public class AdmSpaceController {
     @PostMapping("/update")
     public AdmResponse update(@RequestBody AdmCreateRequest<AdmSpace> createRequest, @QueryParam("projectId") String projectId) throws Exception {
         List<AdmSpace> vos = CollUtil.newArrayList(createRequest.getContent());
-        vos = service.doUpdate( AdmContextUtil.toDmpContext(), AdmSpace.class, vos);
+        if(CollUtil.isNotEmpty(vos)) {
+            Map<String, AdmSpace> admSpaceMap = CollUtil.fieldValueMap(vos, BaseEntity.PROP_ID);
+            AdmRelationTypeEnum typeEnumBd = AdmRelationTypeEnum.BD2SP;
+
+            AdmRelationTypeEnum typeEnumFl = AdmRelationTypeEnum.FL2SP;
+            QueryCriteria criteria = new QueryCriteria();
+            ObjectNode node = JsonNodeFactory.instance.objectNode();
+
+            admSpaceMap.keySet().stream().forEach(spId -> {
+                node.put("relCode", typeEnumBd.getRelCode());
+                node.put("objTo", spId);
+                node.put("graphCode", typeEnumBd.getGraphCode());
+                criteria.setCriteria(node);
+                relationService.doDelete(AdmContextUtil.toDmpContext(), criteria);
+
+                node.put("relCode", typeEnumFl.getRelCode());
+                node.put("objTo", spId);
+                node.put("graphCode", typeEnumFl.getGraphCode());
+                criteria.setCriteria(node);
+                relationService.doDelete(AdmContextUtil.toDmpContext(), criteria);
+            });
+
+            List<RelationDTO> relationDTOList = new ArrayList<>(vos.size());
+            admSpaceMap.keySet().stream().forEach(spaceId -> {
+                if (StrUtil.isNotEmpty(admSpaceMap.get(spaceId).getBuildingId())) {
+                    RelationDTO relationBd = new RelationDTO(null, typeEnumBd.getGraphCode(), typeEnumBd.getRelCode(), null, admSpaceMap.get(spaceId).getBuildingId(), spaceId);
+                    relationDTOList.add(relationBd);
+                }
+                if (StrUtil.isNotEmpty(admSpaceMap.get(spaceId).getFloorId())) {
+                    RelationDTO relationFl = new RelationDTO(null, typeEnumFl.getGraphCode(), typeEnumFl.getRelCode(), null, admSpaceMap.get(spaceId).getFloorId(), spaceId);
+                    relationDTOList.add(relationFl);
+                }
+            });
+
+            if (CollUtil.isNotEmpty(relationDTOList)) {
+                relationService.doSave(AdmContextUtil.toDmpContext(), relationDTOList);
+            }
+            vos = service.doUpdate(AdmContextUtil.toDmpContext(), AdmSpace.class, vos);
+        }
         return AdmResponse.success(vos);
     }