Browse Source

fix bug:计算空间状态变化状态state失败的问题

lijie 3 years ago
parent
commit
5b94b5ba4e

+ 4 - 1
meiku/src/main/resources/application.yml

@@ -46,7 +46,10 @@ spring:
     mapper:
       # 属性按字母顺序输出
      sort_properties_alphabetically:   true
-
+persagy:
+  bdtp:
+    rwd:
+      service: http://dmp-rwd:8080
 # spring-doc 配置
 springdoc:
   # springdoc 扫描的包,多个包之间使用逗号分隔

+ 2 - 4
revit-algorithm/src/main/kotlin/cn/sagacloud/server/algorithm/backstage/model/datacenter/DCFloor.kt

@@ -2,8 +2,6 @@ package cn.sagacloud.server.algorithm.backstage.model.datacenter
 
 import cn.sagacloud.server.algorithm.models.jsonAnalyzer.Point
 import com.alibaba.fastjson.annotation.JSONField
-import io.swagger.annotations.ApiModelProperty
-import javax.persistence.Column
 
 /**
  *
@@ -39,6 +37,6 @@ class DCFloor {
     var buildingId: String? = null
 
     // 空间
-    @JSONField(name = "spaceList")
-    var spaceList : ArrayList<DCISpace>? = null
+    @JSONField(name = "spaceList",alternateNames = ["zoneSpaceList", "spaceList"])
+    var spaceList : ArrayList<DCSpace>? = null
 }

+ 56 - 0
revit-algorithm/src/main/kotlin/cn/sagacloud/server/algorithm/backstage/model/datacenter/DCSpace.kt

@@ -0,0 +1,56 @@
+package cn.sagacloud.server.algorithm.backstage.model.datacenter
+
+import cn.sagacloud.server.algorithm.models.jsonAnalyzer.Point
+import com.alibaba.fastjson.annotation.JSONField
+
+/**
+ *
+ *
+ * @author jxing
+ */
+class DCSpace : DCDataBase(){
+
+//    @JSONField(name = "BIMID")
+//    var bimId : String? = null
+
+    @JSONField(name = "id")
+    var id : String? = null
+
+    @JSONField(name = "bimLocation")
+    var bimLocation : String? = null
+
+    @JSONField(name = "localName")
+    var localName : String? = null
+
+    @JSONField(name = "floorId")
+    var floorId: String? = null
+
+    @JSONField(name = "height")
+    var height: Double? = null
+
+    @JSONField(name = "outline")
+    var outline: ArrayList<ArrayList<ArrayList<Point>>>? = null
+
+    @JSONField(name = "outerOutline")
+    var outerOutline: ArrayList<ArrayList<Point>>? = null
+
+    @JSONField(name = "cadId")
+    var cadId: String? = null
+
+    @JSONField(name = "modelId")
+    var modelId: String? = null
+
+    @JSONField(name = "state")
+    var state: Int? = null
+
+    /** 建筑id */
+    @JSONField(name = "buildingId")
+    var buildingId: String? = null
+
+    @JSONField(name = "customParam")
+    var customParam : HashMap<String, Any?>? = null
+
+    /** 转换后的信息点 */
+    @JSONField(name = "infos")
+    var infos: Map<String,Any?>? = null
+}

+ 58 - 29
revit-algorithm/src/main/kotlin/cn/sagacloud/server/algorithm/common/utils/SpaceAffectUtil.kt

@@ -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

+ 83 - 6
revit-algorithm/src/main/kotlin/cn/sagacloud/server/algorithm/controllers/TestModelController.kt

@@ -1,17 +1,19 @@
 package cn.sagacloud.server.algorithm.controllers
 
-import cn.sagacloud.server.algorithm.backstage.state.ExportPassedState_3
 import cn.sagacloud.server.algorithm.backstage.sync.SyncFloor
 import cn.sagacloud.server.algorithm.backstage.sync.SyncUtil
+import cn.sagacloud.server.algorithm.common.utils.SpaceAffectUtil
 import cn.sagacloud.server.algorithm.models.config.MyProperties
 import cn.sagacloud.server.algorithm.models.jsonAnalyzer.AllComponents
 import cn.sagacloud.server.algorithm.models.jsonAnalyzer.BaseObj
 import cn.sagacloud.server.algorithm.models.message.MessageType
 import cn.sagacloud.server.algorithm.models.modelFile.ModelFile
+import cn.sagacloud.server.algorithm.models.modelFile.StatusInfo
 import cn.sagacloud.server.algorithm.models.monitor.MntSaveData
 import cn.sagacloud.server.algorithm.models.monitor.ModelMonitor
 import cn.sagacloud.server.algorithm.services.BaseDataService
 import cn.sagacloud.server.algorithm.services.CommonService
+import cn.sagacloud.server.algorithm.services.datacenter.DataCenterService
 import cn.sagacloud.server.algorithm.services.endpoint.ModelFileService
 import cn.sagacloud.server.algorithm.services.excel.ExcelService
 import cn.sagacloud.server.algorithm.services.json.JSONAnalyzerService
@@ -21,10 +23,10 @@ import cn.sagacloud.server.algorithm.services.monitor.ModelMonitorService
 import com.alibaba.fastjson.JSONObject
 import com.fasterxml.jackson.databind.DeserializationFeature
 import com.fasterxml.jackson.databind.ObjectMapper
-import com.sybotan.base.extensions.toJson
 import com.sybotan.database.SFilter
+import com.sybotan.database.enums.SDirection
 import com.sybotan.service.models.enums.SResponseType
-import com.sybotan.service.utils.SJsonUtil
+import com.sybotan.service.models.requests.SUpdateRequest
 import com.sybotan.service.utils.SSpringContextUtil
 import io.swagger.annotations.Api
 import io.swagger.annotations.ApiOperation
@@ -33,9 +35,6 @@ import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.web.bind.annotation.PostMapping
 import org.springframework.web.bind.annotation.RequestMapping
 import org.springframework.web.bind.annotation.RestController
-import java.io.File
-import java.io.FileInputStream
-import java.io.FileReader
 import java.util.*
 
 /**
@@ -75,6 +74,12 @@ class TestModelController {
     @Autowired
     lateinit var monitorService: ModelMonitorService
 
+    @Autowired
+    lateinit var dataCenterService: DataCenterService
+
+    @Autowired
+    lateinit var spaceAffectUtil: SpaceAffectUtil
+
     val dataService = BaseDataService
 
     var modelList: ArrayList<ModelFile>? = null
@@ -196,6 +201,78 @@ class TestModelController {
 
     }
 
+    @ApiOperation(value = "检查模型解析文件", notes = "")
+    @PostMapping(value = ["/test/finishState"])
+    fun finishState(floorModelId: String?, id: String?){
+        try {
+            val modelList = dataService.modelFileService.select(SFilter.eq("id", id!!),
+                    SFilter.eq("removed", false)).exec()
+            if (modelList.isNullOrEmpty()) {
+                return
+            }
+            val it = modelList[0]
+            // 先给模型文件版本号和接收时间
+            addVersionChangeName(modelList!!)
+            modelList!!.forEach {
+                try {
+                    // 获取模型的statusInfo的affectedSpace是否是true
+                    // 如果不是true
+                    if (it.statusInfo == null || it.statusInfo!!.affectedSpace != true) {
+                        if (it.floorModelId == null) {
+                            return@forEach
+                        }
+                        val floorModel = dataService.floorModelService.select(SFilter.and(SFilter.eq("currentModelId", it.id!!), SFilter.eq("id", it.floorModelId!!))).entity()
+                                ?: return@forEach
+                        // 判断数据中心是否有楼层绑定了该模型
+                        val floors = dataCenterService.getFloorWithModelId(it.floorModelId!!, it.projectId!!)
+                        // 如果有绑定, 则执行受影响的业务空间函数
+                        if (!floors.isNullOrEmpty()) {
+                            val calcAffected = spaceAffectUtil.affectedSpace(it.projectId!!, it.floorModelId!!)
+//                                floorMapper.calcAffected(it.floorModelId!!)
+                            // 如果返回true, 更新模型的statusInfo信息点
+                            if (calcAffected == true) {
+                                it.statusInfo = StatusInfo()
+                                it.statusInfo!!.affectedSpace = true
+                                dataService.modelFileService.update(it, arrayListOf("statusInfo"))
+                            }
+                        }
+                    }
+                }catch (ex : java.lang.Exception){
+                    ex.printStackTrace()
+                }
+            }
+        } catch (e: Exception) {
+            // 转状态到31
+            try {
+            }catch (e : Exception){}
+            e.printStackTrace()
+        }
+
+
+    }
+
+    private val projection = arrayListOf("version", "acceptTime")
+    private fun addVersionChangeName(modelList: java.util.ArrayList<ModelFile>) {
+        modelList.forEach {
+            // 检验数据合法性
+            if(it.floorModelId == null || it.floorModelId!!.isEmpty())
+                return@forEach
+            if(it.version != null)  // 已经改过的忽略掉
+                return@forEach
+            val largestVersion = dataService.modelFileService.select(SFilter.and(SFilter.eq("floorModelId", it.floorModelId!!), SFilter.not(SFilter.isNull("version")), SFilter.eq("removed", false))).order("version", SDirection.DESC).limit(1).entity()
+            if(largestVersion == null){
+                it.version = 1
+            }else {
+                it.version = largestVersion.version!! + 1
+            }
+            it.acceptTime = Date()
+            val request = SUpdateRequest<ModelFile>()
+            request.content = arrayListOf(it)
+            request.projection = projection
+            dataService.modelFileService.updateList(request)
+        }
+    }
+
     fun handleSingleJSON(json: JSONObject): BaseObj<AllComponents>? {
         val mapper = ObjectMapper()
         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)

+ 2 - 1
revit-algorithm/src/main/kotlin/cn/sagacloud/server/algorithm/services/datacenter/DataCenterRequest.kt

@@ -200,7 +200,7 @@ class DataCenterRequest{
     /**
      * 空间更新
      */
-    fun spaceUpdate(request : UpdateRequest<DCISpace>, projectId : String) : BaseResponse?{
+    fun spaceUpdate(request : UpdateRequest<DCSpace>, projectId : String) : BaseResponse?{
         try {
             val postBody = JSON.toJSONString(request)
             val resultStr = HttpService.sendPostDataCenter(properties.datacenter.spaceUpdate, postBody, projectId)
@@ -232,6 +232,7 @@ class DataCenterRequest{
             val resultStr = HttpService.sendPostDataCenter(properties.datacenter.floorQuery, postBody, projectId)
             return JSON.parseObject(resultStr, object : TypeReference<QueryResponse<DCFloor>>() { })
         } catch (e: Exception) {
+            e.printStackTrace()
         }
         return null
     }

+ 12 - 5
revit-algorithm/src/main/resources-dev/application.yml

@@ -18,17 +18,23 @@ spring:
     name:                               revit-algorithm
     type:                               com.alibaba.druid.pool.DruidDataSource
     driver-class-name:                  com.mysql.cj.jdbc.Driver
-    url:                                jdbc:mysql://rm-2ze20ntn5y9ljsx147o.mysql.rds.aliyuncs.com:3306/revit?allowMultiQueries=true&serverTimezone=UTC&useUnicode=true&useSSL=false&characterEncoding=UTF-8
+#    url:                                jdbc:mysql://rm-2ze20ntn5y9ljsx147o.mysql.rds.aliyuncs.com:3306/revit?allowMultiQueries=true&serverTimezone=UTC&useUnicode=true&useSSL=false&characterEncoding=UTF-8
+#    username:                           root
+#    password:                           zVmW58LaAtjIKbb
+    url:                                jdbc:mysql://192.168.100.91:9934/revit?allowMultiQueries=true&serverTimezone=UTC&useUnicode=true&useSSL=false&characterEncoding=UTF-8
     username:                           root
-    password:                           zVmW58LaAtjIKbb
+    password:                           persagy@2021
 
   second_datasource:
     name:                               revit-algorithm
     type:                               com.alibaba.druid.pool.DruidDataSource
     driver-class-name:                  com.mysql.cj.jdbc.Driver
-    url:                                jdbc:mysql://rm-2ze20ntn5y9ljsx147o.mysql.rds.aliyuncs.com:3306/revit_calc?allowMultiQueries=true&serverTimezone=UTC&useUnicode=true&useSSL=false&characterEncoding=UTF-8
+#    url:                                jdbc:mysql://rm-2ze20ntn5y9ljsx147o.mysql.rds.aliyuncs.com:3306/revit_calc?allowMultiQueries=true&serverTimezone=UTC&useUnicode=true&useSSL=false&characterEncoding=UTF-8
+#    username:                           root
+#    password:                           zVmW58LaAtjIKbb
+    url:                                jdbc:mysql://192.168.100.91:9934/revit_calc?allowMultiQueries=true&serverTimezone=UTC&useUnicode=true&useSSL=false&characterEncoding=UTF-8
     username:                           root
-    password:                           zVmW58LaAtjIKbb
+    password:                           persagy@2021
 
   jackson:
     date-format:                        yyyy-MM-dd HH:mm:ss
@@ -113,7 +119,8 @@ properties:
 
 
   datacenter:
-    url:                                http://39.105.112.36/datacenter/
+    #url:                                http://39.105.112.36/datacenter/
+    url:                                http://localhost:8876/
     # 设备相关接口
     equipCreate: ${properties.datacenter.url}object/equip/create
     equipDelete: ${properties.datacenter.url}object/equip/delete

+ 12 - 5
revit-algorithm/src/main/resources-prod/application.yml

@@ -18,16 +18,22 @@ spring:
     name:                               revit
     type:                               com.alibaba.druid.pool.DruidDataSource
     driver-class-name:                  com.mysql.cj.jdbc.Driver
-    url:                                jdbc:mysql://rm-2ze20ntn5y9ljsx147o.mysql.rds.aliyuncs.com:3306/revit?allowMultiQueries=true&serverTimezone=UTC&useUnicode=true&useSSL=false&characterEncoding=UTF-8
+#    url:                                jdbc:mysql://rm-2ze20ntn5y9ljsx147o.mysql.rds.aliyuncs.com:3306/revit?allowMultiQueries=true&serverTimezone=UTC&useUnicode=true&useSSL=false&characterEncoding=UTF-8
+#    username:                           root
+#    password:                           zVmW58LaAtjIKbb
+    url:                                jdbc:mysql://192.168.100.91:9934/revit?allowMultiQueries=true&serverTimezone=UTC&useUnicode=true&useSSL=false&characterEncoding=UTF-8
     username:                           root
-    password:                           zVmW58LaAtjIKbb
+    password:                           persagy@2021
   second-datasource:
     name:                               revit_calc
     type:                               com.alibaba.druid.pool.DruidDataSource
     driver-class-name:                  com.mysql.cj.jdbc.Driver
-    url:                                jdbc:mysql://rm-2ze20ntn5y9ljsx147o.mysql.rds.aliyuncs.com:3306/revit_calc?allowMultiQueries=true&serverTimezone=UTC&useUnicode=true&useSSL=false&characterEncoding=UTF-8
+#    url:                                jdbc:mysql://rm-2ze20ntn5y9ljsx147o.mysql.rds.aliyuncs.com:3306/revit_calc?allowMultiQueries=true&serverTimezone=UTC&useUnicode=true&useSSL=false&characterEncoding=UTF-8
+#    username:                           root
+#    password:                           zVmW58LaAtjIKbb
+    url:                                jdbc:mysql://192.168.100.91:9934/revit_calc?allowMultiQueries=true&serverTimezone=UTC&useUnicode=true&useSSL=false&characterEncoding=UTF-8
     username:                           root
-    password:                           zVmW58LaAtjIKbb
+    password:                           persagy@2021
 
   jackson:
     date-format:                        yyyy-MM-dd HH:mm:ss
@@ -112,7 +118,8 @@ properties:
 
 
   datacenter:
-    url:                               http://39.105.112.36/datacenter/
+    #url:                               http://39.105.112.36/datacenter/
+    url:                               http://localhost:8876/
     # 设备相关接口
     equipCreate: ${properties.datacenter.url}object/equip/create
     equipDelete: ${properties.datacenter.url}object/equip/delete

+ 1 - 0
revit-algorithm/src/main/resources-test/application.yml

@@ -107,6 +107,7 @@ properties:
 
   datacenter:
     url:                               http://192.168.64.14:28888/datacenter/
+    #url:                               http://localhost:8876/
     # 设备相关接口
     equipCreate: ${properties.datacenter.url}object/equip/create
     equipDelete: ${properties.datacenter.url}object/equip/delete