|
@@ -1,61 +1,57 @@
|
|
|
-package cn.sagacloud.server.algorithm.common.utils;
|
|
|
+package cn.sagacloud.server.algorithm.common.utils
|
|
|
|
|
|
-import cn.sagacloud.server.algorithm.backstage.model.datacenter.DCFloor;
|
|
|
-import cn.sagacloud.server.algorithm.backstage.model.datacenter.DCISpace;
|
|
|
-import cn.sagacloud.server.algorithm.backstage.model.datacenter.QueryResponse;
|
|
|
-import cn.sagacloud.server.algorithm.backstage.model.datacenter.UpdateRequest;
|
|
|
-import cn.sagacloud.server.algorithm.models.entities.Space;
|
|
|
-import cn.sagacloud.server.algorithm.models.jsonAnalyzer.Point;
|
|
|
-import cn.sagacloud.server.algorithm.models.modelFile.ModelFile;
|
|
|
-import cn.sagacloud.server.algorithm.services.BaseDataService;
|
|
|
-import cn.sagacloud.server.algorithm.services.datacenter.DataCenterRequest;
|
|
|
-import com.sybotan.service.SObjectService;
|
|
|
-import com.sybotan.service.models.SCascadeQuery;
|
|
|
-import com.sybotan.service.models.requests.SQueryRequest;
|
|
|
-import com.sybotan.service.models.responses.SQueryResponse;
|
|
|
-import org.apache.commons.collections4.CollectionUtils;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
-
|
|
|
-import java.awt.*;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.stream.Collectors;
|
|
|
+import cn.sagacloud.server.algorithm.backstage.model.datacenter.DCFloor
|
|
|
+import cn.sagacloud.server.algorithm.backstage.model.datacenter.DCISpace
|
|
|
+import cn.sagacloud.server.algorithm.backstage.model.datacenter.QueryResponse
|
|
|
+import cn.sagacloud.server.algorithm.backstage.model.datacenter.UpdateRequest
|
|
|
+import cn.sagacloud.server.algorithm.models.entities.Space
|
|
|
+import cn.sagacloud.server.algorithm.models.jsonAnalyzer.Point
|
|
|
+import cn.sagacloud.server.algorithm.models.modelFile.ModelFile
|
|
|
+import cn.sagacloud.server.algorithm.services.BaseDataService.modelFileService
|
|
|
+import cn.sagacloud.server.algorithm.services.BaseDataService.spaceService
|
|
|
+import cn.sagacloud.server.algorithm.services.datacenter.DataCenterRequest
|
|
|
+import com.sybotan.service.SObjectService
|
|
|
+import com.sybotan.service.models.SCascadeQuery
|
|
|
+import com.sybotan.service.models.requests.SQueryRequest
|
|
|
+import com.sybotan.service.models.responses.SQueryResponse
|
|
|
+import org.apache.commons.collections4.CollectionUtils
|
|
|
+import org.apache.commons.lang3.StringUtils
|
|
|
+import org.springframework.beans.factory.annotation.Autowired
|
|
|
+import org.springframework.stereotype.Component
|
|
|
+import java.awt.Polygon
|
|
|
+import java.util.*
|
|
|
+import java.util.stream.Collectors
|
|
|
|
|
|
@Component
|
|
|
-public class SpaceAffectUtil {
|
|
|
+class SpaceAffectUtil {
|
|
|
|
|
|
@Autowired
|
|
|
- private DataCenterRequest service;
|
|
|
-
|
|
|
- public boolean affectedSpace(String projectId, String modelId) {
|
|
|
- if(StringUtils.isBlank(projectId) || StringUtils.isBlank(modelId)) {
|
|
|
- return true;
|
|
|
+ private val service: DataCenterRequest? = null
|
|
|
+ fun affectedSpace(projectId: String, modelId: String): Boolean {
|
|
|
+ if (StringUtils.isBlank(projectId) || StringUtils.isBlank(modelId)) {
|
|
|
+ return true
|
|
|
}
|
|
|
// 查楼层
|
|
|
- List<DCISpace> spaceList = querySpaceByFloorModel(projectId, modelId);
|
|
|
- if(CollectionUtils.isEmpty(spaceList)) {
|
|
|
- return true;
|
|
|
+ val spaceList = querySpaceByFloorModel(projectId, modelId)
|
|
|
+ if (CollectionUtils.isEmpty(spaceList)) {
|
|
|
+ return true
|
|
|
}
|
|
|
// 查原模型
|
|
|
- List<String> modelIds = queryModelFile(projectId, modelId);
|
|
|
- if(CollectionUtils.size(modelIds) != 2) {
|
|
|
- return true;
|
|
|
+ val modelIds = queryModelFile(projectId, modelId)
|
|
|
+ if (CollectionUtils.size(modelIds) != 2) {
|
|
|
+ return true
|
|
|
}
|
|
|
// 查模型关联的元空间
|
|
|
- Map<String, List<Space>> iSpaceMap = queryMetaSpaceByModel(modelIds);
|
|
|
- if(CollectionUtils.isEmpty(iSpaceMap.get(modelIds.get(1)))) {
|
|
|
+ val iSpaceMap = queryMetaSpaceByModel(modelIds)
|
|
|
+ if (CollectionUtils.isEmpty(iSpaceMap[modelIds!![1]])) {
|
|
|
// 旧模型没有关联的元空间不需要处理
|
|
|
- return true;
|
|
|
+ return true
|
|
|
}
|
|
|
// 获取有变化的空间列表
|
|
|
- List<DCISpace> spaces = getAffectedSpaceIds(spaceList, iSpaceMap.get(modelIds.get(0)), iSpaceMap.get(modelIds.get(1)));
|
|
|
+ val spaces = getAffectedSpaceIds(spaceList, iSpaceMap[modelIds[0]], iSpaceMap[modelIds[1]])
|
|
|
// 更新空间
|
|
|
- updateSpaceList(projectId, spaces);
|
|
|
- return true;
|
|
|
+ updateSpaceList(projectId, spaces)
|
|
|
+ return true
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -65,48 +61,51 @@ public class SpaceAffectUtil {
|
|
|
* @param oldMetaSpaces
|
|
|
* @return
|
|
|
*/
|
|
|
- private List<DCISpace> getAffectedSpaceIds(List<DCISpace> spaces, List<Space> newMetaSpaces, List<Space> oldMetaSpaces) {
|
|
|
+ private fun getAffectedSpaceIds(spaces: List<DCISpace?>?, newMetaSpaces: List<Space>?, oldMetaSpaces: List<Space>?): List<DCISpace?>? {
|
|
|
// 准备修改后的元空间
|
|
|
- Map<String, Space> newMetaSpaceMap = new HashMap<>();
|
|
|
- for(int i = 0,j = CollectionUtils.size(newMetaSpaces);i < j;i++) {
|
|
|
- Space space = newMetaSpaces.get(i);
|
|
|
- newMetaSpaceMap.put(space.getId(), space);
|
|
|
+ val newMetaSpaceMap: MutableMap<String?, Space> = HashMap()
|
|
|
+ var i = 0
|
|
|
+ val j = CollectionUtils.size(newMetaSpaces)
|
|
|
+ while (i < j) {
|
|
|
+ val space = newMetaSpaces!![i]
|
|
|
+ newMetaSpaceMap[space.id] = space
|
|
|
+ i++
|
|
|
}
|
|
|
// 截取有变化的元空间
|
|
|
- List<Polygon> affectList = new ArrayList<>();
|
|
|
- for(Space space:oldMetaSpaces) {
|
|
|
- Polygon polygon = createPolygon(space.getOutline());
|
|
|
- Space newSpace = newMetaSpaceMap.get(space.getId());
|
|
|
- if(newSpace == null) {
|
|
|
- affectList.add(polygon);
|
|
|
- continue;
|
|
|
+ val affectList: MutableList<Polygon?> = ArrayList()
|
|
|
+ for (space in oldMetaSpaces!!) {
|
|
|
+ val polygon = createPolygon(space.outline)
|
|
|
+ val newSpace = newMetaSpaceMap[space.id]
|
|
|
+ if (newSpace == null) {
|
|
|
+ affectList.add(polygon)
|
|
|
+ continue
|
|
|
}
|
|
|
- Polygon newPolygon = createPolygon(newSpace.getOutline());
|
|
|
+ val newPolygon = createPolygon(newSpace.outline)
|
|
|
// TODO 有交集则加入有变化的元空间列表
|
|
|
- if(newPolygon == null) {
|
|
|
- affectList.add(polygon);
|
|
|
- continue;
|
|
|
+ if (newPolygon == null) {
|
|
|
+ affectList.add(polygon)
|
|
|
+ continue
|
|
|
}
|
|
|
}
|
|
|
- if(CollectionUtils.isEmpty(affectList)) {
|
|
|
- return null;
|
|
|
+ if (CollectionUtils.isEmpty(affectList)) {
|
|
|
+ return null
|
|
|
}
|
|
|
// 与有变化的元空间有交集的空间
|
|
|
- List<DCISpace> rsList = new ArrayList<>();
|
|
|
- for(DCISpace space:spaces) {
|
|
|
- Polygon polygon = createPolygon(space.getOutline());
|
|
|
+ val rsList: MutableList<DCISpace?> = ArrayList()
|
|
|
+ for (space in spaces!!) {
|
|
|
+ val polygon = createPolygon(space!!.outline)
|
|
|
// TODO 有交集则加入有变化的空间列表
|
|
|
- if(polygon == null) {
|
|
|
+ if (polygon == null) {
|
|
|
// TODO state设置为1
|
|
|
- rsList.add(space);
|
|
|
- continue;
|
|
|
+ rsList.add(space)
|
|
|
+ continue
|
|
|
}
|
|
|
}
|
|
|
- return rsList;
|
|
|
+ return rsList
|
|
|
}
|
|
|
|
|
|
- private Polygon createPolygon(ArrayList<ArrayList<Point>> list) {
|
|
|
- return new Polygon();
|
|
|
+ private fun createPolygon(list: ArrayList<ArrayList<Point>>?): Polygon {
|
|
|
+ return Polygon()
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -114,10 +113,10 @@ public class SpaceAffectUtil {
|
|
|
* @param projectId
|
|
|
* @param spaces
|
|
|
*/
|
|
|
- private void updateSpaceList(String projectId, List<DCISpace> spaces) {
|
|
|
- UpdateRequest<DCISpace> request = new UpdateRequest<>();
|
|
|
- request.setContent((ArrayList<DCISpace>) spaces);
|
|
|
- service.iSpaceUpdate(request, projectId);
|
|
|
+ private fun updateSpaceList(projectId: String, spaces: List<DCISpace?>?) {
|
|
|
+ val request = UpdateRequest<DCISpace>()
|
|
|
+ request.content = spaces as ArrayList<DCISpace>
|
|
|
+ service!!.iSpaceUpdate(request, projectId)
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -126,29 +125,29 @@ public class SpaceAffectUtil {
|
|
|
* @param modelId
|
|
|
* @return
|
|
|
*/
|
|
|
- private List<DCISpace> querySpaceByFloorModel(String projectId, String modelId) {
|
|
|
- SQueryRequest request = new SQueryRequest();
|
|
|
- request.setPageSize(500);
|
|
|
- request.setFilters(" model_id = '" + modelId + "' ");
|
|
|
- SCascadeQuery cascade = new SCascadeQuery();
|
|
|
- cascade.setName("spaceList");
|
|
|
- ArrayList<SCascadeQuery> cascades = new ArrayList<>();
|
|
|
- cascades.add(cascade);
|
|
|
- request.setCascade(cascades);
|
|
|
- QueryResponse<DCFloor> response = service.floorQuery(request, projectId);
|
|
|
- if(response == null || CollectionUtils.isEmpty(response.getContent())) {
|
|
|
- return null;
|
|
|
+ private fun querySpaceByFloorModel(projectId: String, modelId: String): List<DCISpace?>? {
|
|
|
+ val request = SQueryRequest()
|
|
|
+ request.pageSize = 500
|
|
|
+ request.filters = " model_id = '$modelId' "
|
|
|
+ val cascade = SCascadeQuery()
|
|
|
+ cascade.name = "spaceList"
|
|
|
+ val cascades = ArrayList<SCascadeQuery>()
|
|
|
+ cascades.add(cascade)
|
|
|
+ request.cascade = cascades
|
|
|
+ val response: QueryResponse<DCFloor>? = service!!.floorQuery(request, projectId)
|
|
|
+ if (response == null || CollectionUtils.isEmpty(response.content)) {
|
|
|
+ return null
|
|
|
}
|
|
|
- ArrayList<DCFloor> floors = response.getContent();
|
|
|
- List<DCISpace> spaceList = new ArrayList<>();
|
|
|
- for(DCFloor floor:floors) {
|
|
|
- List<DCISpace> spaces = floor.getSpaceList();
|
|
|
- if(CollectionUtils.isEmpty(spaces)) {
|
|
|
- continue;
|
|
|
+ val floors = response.content
|
|
|
+ val spaceList: MutableList<DCISpace> = ArrayList<DCISpace>()
|
|
|
+ for (floor in floors!!) {
|
|
|
+ val spaces: List<DCISpace>? = floor!!.spaceList
|
|
|
+ if (CollectionUtils.isEmpty(spaces)) {
|
|
|
+ continue
|
|
|
}
|
|
|
- spaceList.addAll(spaces);
|
|
|
+ spaceList.addAll(spaces!!)
|
|
|
}
|
|
|
- return spaceList;
|
|
|
+ return spaceList
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -157,20 +156,20 @@ public class SpaceAffectUtil {
|
|
|
* @param modelId
|
|
|
* @return
|
|
|
*/
|
|
|
- private List<String> queryModelFile(String projectId, String modelId) {
|
|
|
- SObjectService modelFileService = BaseDataService.INSTANCE.getModelFileService();
|
|
|
- SQueryRequest request = new SQueryRequest();
|
|
|
- request.setFilters("model_floor_id = '"+modelId+"' and removed = false and status = 4 and version is not null");
|
|
|
- request.setOrders("version desc");
|
|
|
- ArrayList<String> projection = new ArrayList<>();
|
|
|
- projection.add("id");
|
|
|
- request.setProjection(projection);
|
|
|
- SQueryResponse<ModelFile> response = modelFileService.pageQuery(request, null);
|
|
|
- if(response == null || CollectionUtils.isEmpty(response.getContent())) {
|
|
|
- return null;
|
|
|
+ private fun queryModelFile(projectId: String, modelId: String): List<String>? {
|
|
|
+ val modelFileService: SObjectService<ModelFile> = modelFileService
|
|
|
+ val request = SQueryRequest()
|
|
|
+ request.filters = "model_floor_id = '$modelId' and removed = false and status = 4 and version is not null"
|
|
|
+ request.orders = "version desc"
|
|
|
+ val projection = ArrayList<String>()
|
|
|
+ projection.add("id")
|
|
|
+ request.projection = projection
|
|
|
+ val response: SQueryResponse<ModelFile> = modelFileService.pageQuery(request, null)
|
|
|
+ if (response == null || CollectionUtils.isEmpty(response.content)) {
|
|
|
+ return null
|
|
|
}
|
|
|
- List<ModelFile> floors = response.getContent();
|
|
|
- return floors.stream().map(ModelFile::getId).collect(Collectors.toList());
|
|
|
+ val floors = response.content
|
|
|
+ return floors!!.stream().map<String>(ModelFile::id).collect(Collectors.toList())
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -178,27 +177,27 @@ public class SpaceAffectUtil {
|
|
|
* @param modelIds
|
|
|
* @return
|
|
|
*/
|
|
|
- private Map<String, List<Space>> queryMetaSpaceByModel(List<String> modelIds) {
|
|
|
- Map<String, List<Space>> spaceMap = new HashMap<>(2);
|
|
|
- SObjectService spaceService = BaseDataService.INSTANCE.getSpaceService();
|
|
|
+ private fun queryMetaSpaceByModel(modelIds: List<String>?): Map<String, List<Space>?> {
|
|
|
+ val spaceMap: MutableMap<String, List<Space>?> = HashMap(2)
|
|
|
+ val spaceService: SObjectService<Space> = spaceService
|
|
|
// 查询新模型的元空间
|
|
|
- SQueryRequest request = new SQueryRequest();
|
|
|
- request.setFilters("model_id = '"+modelIds.get(0)+"' ");
|
|
|
- ArrayList<String> projection = new ArrayList<>();
|
|
|
- projection.add("sourceId");
|
|
|
- projection.add("outline");
|
|
|
- request.setProjection(projection);
|
|
|
- SQueryResponse<Space> response = spaceService.pageQuery(request, null);
|
|
|
- if(CollectionUtils.isNotEmpty(response.getContent())) {
|
|
|
- spaceMap.put(modelIds.get(0), response.getContent());
|
|
|
+ var request = SQueryRequest()
|
|
|
+ request.filters = "model_id = '" + modelIds!![0] + "' "
|
|
|
+ val projection = ArrayList<String>()
|
|
|
+ projection.add("sourceId")
|
|
|
+ projection.add("outline")
|
|
|
+ request.projection = projection
|
|
|
+ var response: SQueryResponse<Space> = spaceService.pageQuery(request, null)
|
|
|
+ if (CollectionUtils.isNotEmpty(response.content)) {
|
|
|
+ spaceMap[modelIds[0]] = response.content
|
|
|
}
|
|
|
// 查询旧模型的元空间
|
|
|
- request = new SQueryRequest();
|
|
|
- request.setFilters("model_id = '"+modelIds.get(1)+"' ");
|
|
|
- response = spaceService.pageQuery(request, null);
|
|
|
- if(CollectionUtils.isNotEmpty(response.getContent())) {
|
|
|
- spaceMap.put(modelIds.get(1), response.getContent());
|
|
|
+ request = SQueryRequest()
|
|
|
+ request.filters = "model_id = '" + modelIds[1] + "' "
|
|
|
+ response = spaceService.pageQuery(request, null)
|
|
|
+ if (CollectionUtils.isNotEmpty(response.content)) {
|
|
|
+ spaceMap[modelIds[1]] = response.content
|
|
|
}
|
|
|
- return spaceMap;
|
|
|
+ return spaceMap
|
|
|
}
|
|
|
-}
|
|
|
+}
|