|
@@ -1,7 +1,7 @@
|
|
|
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.DCSpace
|
|
|
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
|
|
@@ -23,6 +23,7 @@ import org.springframework.beans.factory.annotation.Autowired
|
|
|
import org.springframework.stereotype.Component
|
|
|
import java.util.*
|
|
|
import java.util.stream.Collectors
|
|
|
+import kotlin.collections.ArrayList
|
|
|
|
|
|
/**
|
|
|
* 空间冲突计算工具
|
|
@@ -75,7 +76,7 @@ class SpaceAffectUtil {
|
|
|
* @param oldMetaSpaces
|
|
|
* @return
|
|
|
*/
|
|
|
- private fun getAffectedSpaceIds(spaces: List<DCISpace?>?, newMetaSpaces: List<Space>?, oldMetaSpaces: List<Space>?): List<DCISpace?>? {
|
|
|
+ private fun getAffectedSpaceIds(spaces: List<DCSpace?>?, newMetaSpaces: List<Space>?, oldMetaSpaces: List<Space>?): List<DCSpace?>? {
|
|
|
// 准备修改后的元空间
|
|
|
val newMetaSpaceMap: MutableMap<String?, Space> = HashMap()
|
|
|
var i = 0
|
|
@@ -88,35 +89,47 @@ class SpaceAffectUtil {
|
|
|
// 截取有变化的元空间
|
|
|
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
|
|
|
- }
|
|
|
- val newPolygon = createPolygon(newSpace.outline)
|
|
|
- // 有交集则加入有变化的元空间列表
|
|
|
- if (isGeoContains(polygon, newPolygon)) {
|
|
|
- affectList.add(polygon)
|
|
|
- continue
|
|
|
+ for (outLines in space.outline!!) {
|
|
|
+ val polygon = createPolygonV2(outLines)
|
|
|
+ val newSpace = newMetaSpaceMap[space.id]
|
|
|
+ if (newSpace == null) {
|
|
|
+ affectList.add(polygon)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ for (newOutLines in newSpace.outline!!) {
|
|
|
+ val newPolygon = createPolygonV2(newOutLines)
|
|
|
+ // 有交集则加入有变化的元空间列表
|
|
|
+ if (isGeoContains(polygon, newPolygon)) {
|
|
|
+ affectList.add(polygon)
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
if (CollectionUtils.isEmpty(affectList)) {
|
|
|
return null
|
|
|
}
|
|
|
// 与有变化的元空间有交集的空间
|
|
|
- val rsList: MutableList<DCISpace?> = ArrayList()
|
|
|
+ val rsList: MutableList<DCSpace?> = ArrayList()
|
|
|
for (space in spaces!!) {
|
|
|
- val polygon = createPolygon(space!!.outline)
|
|
|
- // 有交集则加入有变化的空间列表
|
|
|
- for(affect in affectList) {
|
|
|
- if (isGeoContains(polygon, affect!!)) {
|
|
|
- // state设置为1
|
|
|
- space.state = 1
|
|
|
- rsList.add(space)
|
|
|
- break;
|
|
|
+ out@
|
|
|
+ for (outLines in space!!.outline!!) {
|
|
|
+ for (subOutLine in outLines){
|
|
|
+ val polygon = createPolygonV2(subOutLine)
|
|
|
+ // 有交集则加入有变化的空间列表
|
|
|
+ for(affect in affectList) {
|
|
|
+ if (isGeoContains(polygon, affect!!)) {
|
|
|
+ // state设置为1
|
|
|
+ space.state = 1
|
|
|
+ rsList.add(space)
|
|
|
+ break@out;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
return rsList
|
|
|
}
|
|
@@ -156,15 +169,30 @@ class SpaceAffectUtil {
|
|
|
val ring = geometryFactory.createLinearRing(coordinates)
|
|
|
return geometryFactory.createPolygon(ring, null)
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 创建平面对象
|
|
|
+ * @param list 轮廓线
|
|
|
+ */
|
|
|
+ private fun createPolygonV2(list: ArrayList<Point>?): Polygon {
|
|
|
+ val geometryFactory = JTSFactoryFinder.getGeometryFactory()
|
|
|
+ val objects: MutableList<Coordinate> = ArrayList()
|
|
|
+ for (point in list!!) {
|
|
|
+ objects.add(Coordinate(point.x, point.y, point.z))
|
|
|
+ }
|
|
|
+ //注意数据的闭合
|
|
|
+ val coordinates = objects.toTypedArray()
|
|
|
+ val ring = geometryFactory.createLinearRing(coordinates)
|
|
|
+ return geometryFactory.createPolygon(ring, null)
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 更新空间列表
|
|
|
* @param projectId
|
|
|
* @param spaces
|
|
|
*/
|
|
|
- private fun updateSpaceList(projectId: String, spaces: List<DCISpace?>?) {
|
|
|
- val request = UpdateRequest<DCISpace>()
|
|
|
- request.content = spaces as ArrayList<DCISpace>
|
|
|
+ private fun updateSpaceList(projectId: String, spaces: List<DCSpace?>?) {
|
|
|
+ val request = UpdateRequest<DCSpace>()
|
|
|
+ request.content = spaces as ArrayList<DCSpace>
|
|
|
service!!.spaceUpdate(request, projectId)
|
|
|
}
|
|
|
|
|
@@ -174,7 +202,7 @@ class SpaceAffectUtil {
|
|
|
* @param modelId
|
|
|
* @return
|
|
|
*/
|
|
|
- private fun querySpaceByFloorModel(projectId: String, modelId: String): List<DCISpace?>? {
|
|
|
+ private fun querySpaceByFloorModel(projectId: String, modelId: String): List<DCSpace?>? {
|
|
|
val request = SQueryRequest()
|
|
|
request.pageSize = 500
|
|
|
request.filters = " modelId = '$modelId' "
|
|
@@ -188,9 +216,9 @@ class SpaceAffectUtil {
|
|
|
return null
|
|
|
}
|
|
|
val floors = response.content
|
|
|
- val spaceList: MutableList<DCISpace> = ArrayList()
|
|
|
+ val spaceList: MutableList<DCSpace> = ArrayList()
|
|
|
for (floor in floors!!) {
|
|
|
- val spaces: List<DCISpace>? = floor!!.spaceList
|
|
|
+ val spaces: List<DCSpace>? = floor!!.spaceList
|
|
|
if (CollectionUtils.isEmpty(spaces)) {
|
|
|
continue
|
|
|
}
|
|
@@ -208,8 +236,9 @@ class SpaceAffectUtil {
|
|
|
private fun queryModelFile(projectId: String, modelId: String): List<String>? {
|
|
|
val modelFileService: SObjectService<ModelFile> = modelFileService
|
|
|
val request = SQueryRequest()
|
|
|
- request.filters = "floorModelId = '$modelId' and removed = false and status = 4 and version is not null"
|
|
|
+ request.filters = "floorModelId = '$modelId' and removed = false and status = 4 and not version isnull"
|
|
|
request.orders = "version desc"
|
|
|
+ request.pageSize=2
|
|
|
val projection = ArrayList<String>()
|
|
|
projection.add("id")
|
|
|
request.projection = projection
|