Browse Source

************************************* WX *******************************
update:添加注释

zhangweixin 3 years ago
parent
commit
4c2cf5ddeb

+ 209 - 0
revit-algorithm/src/main/kotlin/cn/sagacloud/server/algorithm/controllers/TestModelController.kt

@@ -0,0 +1,209 @@
+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.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.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.excel.ExcelService
+import cn.sagacloud.server.algorithm.services.json.JSONAnalyzerService
+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.service.models.enums.SResponseType
+import com.sybotan.service.utils.SJsonUtil
+import com.sybotan.service.utils.SSpringContextUtil
+import io.swagger.annotations.Api
+import io.swagger.annotations.ApiOperation
+import org.slf4j.LoggerFactory
+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.*
+
+/**
+ * 模型解析后数据测试
+ *
+ * @author wx <zhangweixin@sagacloud.cn>
+ * @date 2021/9/1811:10
+ */
+@Api(tags = ["测试检查模型解析文件"])
+@RestController
+@RequestMapping("/test/model")
+class TestModelController {
+
+    companion object {
+        // 日志
+        private val logger = LoggerFactory.getLogger(TestModelController::class.java)
+    } // Companion object
+
+    @Autowired
+    lateinit var jsonAnalyzerService: JSONAnalyzerService
+    val dataService = BaseDataService
+    @Autowired
+    lateinit var monitorService: ModelMonitorService
+
+    /**
+     *
+     */
+    @ApiOperation(value = "检查模型解析文件", notes = "")
+    @PostMapping(value = ["/test/data"])
+    fun testModelData(floorModelId: String?, id: String?){
+        try {
+            val it = ModelFile()
+            it.floorModelId = floorModelId
+            it.id = id
+//            if (it.floorModelId == null || it.id == null)
+//                return@forEach
+//            val floorModelArr = dataService.floorModelService.select(SFilter.eq("id", it.floorModelId!!)).exec()
+//            if (floorModelArr.size != 1)
+//                return@forEach
+//            val floor = floorModelArr[0]
+//            val folderFloorName = CommonService.getReportPrefix(floor)
+            val fileInputStream = FileInputStream(File("D:\\testModel\\b52612021546a9431eb1a38ca02d3b1b.rvt_20210917181820.json"))
+            var file = FileInputStream("D:\\testModel\\b52612021546a9431eb1a38ca02d3b1b.rvt_20210917181820.json")
+            var byteArr = file.readBytes()
+
+            val str = String(byteArr, charset("utf-8"))
+            val objData =  handleSingleJSON(JSONObject.parseObject(str)) //JSONObject(str)
+
+//            logger.debug("model = ${obj.toJson()}")
+
+
+              // 导入数据进数据库
+//            val bimIdPrefix = CommonService.generateBIMIDPrefix(it.projectId!!, floor.folderId!!, floor.floorName!!, true)
+            try {
+               persistenceData(it.id!!, objData!!, "123456")
+            } catch (e: Exception) {
+                e.printStackTrace()
+            }
+//            // excel报告
+//            val excelService = SSpringContextUtil.getBean(ExcelService::class.java) as ExcelService
+//            excelService.readBlockingExcel2007()
+//            // 多楼层的模型检查
+//            var isPassed = monitorService.doMultiFloorCheck(it, excelService, floor.projectId!!, floor.folderId!!, floor.floorName)
+//            // 如果标高和轴网检查没通过, 则删除所有数据, 并回退到上个版本
+//            /************************************************** 轴网计算 处理标志 *********************************************************************/
+//            if(!isPassed){
+//                modelFileService.removeSingle(it, myProperties, isForce = true, isMarkDelete = false)
+//                //发送标高和轴网检查没通过的消息
+//                val message = messageService.buildMultiModelCheckErrorMessage(floor.projectId!!, it.userId?: "",
+//                    "${folderFloorName.first}的${folderFloorName.second}未通过模型检查,请修改后重新上传", excelService.getDownloadUrl(it.id!!), folderFloorName)
+//                messageService.sendMessage(message)
+//                return@forEach
+//            }
+//
+//            val syncFloor = SSpringContextUtil.getBean(SyncFloor::class.java) as SyncFloor
+//            syncFloor.init(floor).prepareDataCenterData()
+//            // 开始同步设备, 部件, 元空间
+//            syncUtil.syncDataWithBindingFloor(syncFloor, it, floor)
+//            // 转状态到4
+//            it.status = 4
+//            dataService.modelFileService.update(it, arrayListOf("status"))
+//            val message = messageService.buildMessageEntityWithoutLink("${folderFloorName.first}的${folderFloorName.second}模型上传成功", MessageType.Success, it.projectId, arrayListOf(it.userId?:""), "")
+//            messageService.sendMessage(message)
+        } catch (e: Exception) {
+            // 转状态到31
+            try {
+//                it.status = 31
+//                it.syncRetryDate = Date()
+//                it.syncErrorMsg = e.message + CommonService.getStackTrace(e)
+//                dataService.modelFileService.update(it, arrayListOf("status", "syncRetryDate", "syncErrorMsg"))
+            }catch (e : Exception){}
+            e.printStackTrace()
+//            ExportPassedState_3.logger.error(e.message)
+        }
+
+
+    }
+
+    fun handleSingleJSON(json: JSONObject): BaseObj<AllComponents>? {
+        val mapper = ObjectMapper()
+        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
+        val baseObj = mapper.readValue<BaseObj<AllComponents>>(json.toString(), mapper.typeFactory.constructParametricType(
+            BaseObj::class.java, AllComponents::class.java))
+        return baseObj
+    }
+
+
+    /**
+     * 持久化数据
+     */
+    fun persistenceData(id: String, objData: BaseObj<AllComponents>, bimIdPrefix : String) {
+        beginPersistenceData(id)
+
+        try {
+            val importResult = jsonAnalyzerService.importModelData(objData, bimIdPrefix)
+            if(importResult.result == SResponseType.failure){
+                endPersistenceDataExceptionally(id, importResult.message)
+                throw Exception(importResult.message)
+            }
+        } catch (e: Exception) {
+            e.printStackTrace()
+        }
+        endPersistenceData(id)
+    }
+
+    /**
+     * 开始持久化数据
+     */
+    private fun beginPersistenceData(id: String) {
+        val modelMonitor = getModelMonitorById(id)
+        if(modelMonitor.saveData!= null && modelMonitor.saveData!!.beginTime != null)
+            return
+        modelMonitor.saveData = MntSaveData()
+        modelMonitor.saveData!!.beginTime = Date()
+        dataService.modelMonitorService.update(modelMonitor, arrayListOf("saveData"))
+    }
+
+    /**
+     * 持久化数据异常
+     */
+    private fun endPersistenceDataExceptionally(id: String, errorInfo: String) {
+        val modelMonitor = getModelMonitorById(id)
+        modelMonitor.saveData!!.hasError = true
+        modelMonitor.saveData!!.errorMsg = errorInfo
+        dataService.modelMonitorService.update(modelMonitor, arrayListOf("saveData"))
+    }
+
+    /**
+     * 获取后台监控信息by id
+     */
+    fun getModelMonitorById(modelId : String): ModelMonitor {
+        var modelMonitor = dataService.modelMonitorService.select(SFilter.Companion.eq("id", modelId)).entity()
+        if(modelMonitor == null)
+        {
+            modelMonitor = ModelMonitor()
+            modelMonitor.id = modelId
+            dataService.modelMonitorService.insert(modelMonitor)
+        }
+        return modelMonitor
+    }
+
+    /**
+     * 正常结束持久化
+     */
+    private fun endPersistenceData(id: String) {
+        val modelMonitor = getModelMonitorById(id)
+        if(modelMonitor.saveData != null && modelMonitor.saveData!!.endTime != null) {
+            return
+        }
+        modelMonitor.saveData!!.endTime = Date()
+        modelMonitor.saveData!!.hasError = false
+        dataService.modelMonitorService.update(modelMonitor, arrayListOf("saveData"))
+    }
+
+
+}

+ 1 - 0
revit-algorithm/src/main/kotlin/cn/sagacloud/server/algorithm/controllers/modelFile/ModelFileController.kt

@@ -249,6 +249,7 @@ class ModelFileController {
 
             // 更新楼层, 失败则被抢占
             modelFileService.updateCurrentModelId(floor, model.id!!)
+
             return uploadModelResponse
         }catch (e : Exception){
             return SBaseResponse(SResponseType.failure, e.message?:"")

+ 15 - 6
revit-algorithm/src/main/kotlin/cn/sagacloud/server/algorithm/services/endpoint/ModelFileService.kt

@@ -405,12 +405,21 @@ class ModelFileService {
     }
 
     fun registerMultipartUpload(model: ModelFile, properties: MyProperties): String {
-        val result = HttpService.sendPost(properties.fileService.registerMultipartUpload + model.fileKey, "")
-        val resultObj = JSON.parseObject(result)
-        val uploadId = resultObj.getString("UploadId")
-        if(uploadId.isNullOrEmpty())
-            throw Exception("获取UploadId失败")
-        return uploadId
+        try {
+
+            val result = HttpService.sendPost(properties.fileService.registerMultipartUpload + model.fileKey, "")
+            logger.debug("结果 = ${result}")
+            val resultObj = JSON.parseObject(result)
+            val uploadId = resultObj.getString("UploadId")
+            if(uploadId.isNullOrEmpty())
+                throw Exception("获取UploadId失败")
+            return uploadId
+        } catch (e: Exception) {
+
+            logger.debug("url = ${properties.fileService.registerMultipartUpload + model.fileKey}")
+            e.printStackTrace()
+            return "获取UploadId失败"
+        }
     }
 
     val floorNamePattern = "^([F|B][1-9][0-9]{0,4}|RF)(M([1-9][0-9]{0,4})?)?\$"

+ 1 - 1
revit-algorithm/src/main/kotlin/cn/sagacloud/server/algorithm/services/json/EquipmentAnalyzer.kt

@@ -1,4 +1,4 @@
-package com.persagy.revit.services.json
+package cn.sagacloud.server.algorithm.services.json
 
 import cn.sagacloud.server.algorithm.models.entities.*
 import cn.sagacloud.server.algorithm.models.jsonAnalyzer.AllComponents

+ 30 - 8
revit-algorithm/src/main/kotlin/cn/sagacloud/server/algorithm/services/json/JSONAnalyzerService.kt

@@ -20,6 +20,7 @@
 
 package cn.sagacloud.server.algorithm.services.json
 
+import cn.sagacloud.server.algorithm.controllers.TestModelController
 import cn.sagacloud.server.algorithm.models.entities.*
 import cn.sagacloud.server.algorithm.models.jsonAnalyzer.AllComponents
 import cn.sagacloud.server.algorithm.models.jsonAnalyzer.BaseObj
@@ -31,12 +32,11 @@ import com.alibaba.fastjson.JSONObject
 import com.alibaba.fastjson.util.ParameterizedTypeImpl
 import com.fasterxml.jackson.databind.DeserializationFeature
 import com.fasterxml.jackson.databind.ObjectMapper
-import com.persagy.revit.services.json.EquipmentAnalyzer
 import com.sybotan.database.SFilter
-import com.sybotan.mybatis.SMybatisDao
 import com.sybotan.service.SObjectService
 import com.sybotan.service.models.enums.SResponseType
 import com.sybotan.service.models.responses.SBaseResponse
+import org.slf4j.LoggerFactory
 import org.springframework.stereotype.Component
 import java.io.InputStream
 import java.lang.reflect.Type
@@ -60,6 +60,11 @@ open class JSONAnalyzerService {
 //    private var modelService = SObjectService(SMybatisDao(ModelFile::class.java))
 //    private var boundarySegmentService = SObjectService(SMybatisDao(BoundarySegment::class.java))
 
+    companion object {
+        // 日志
+        private val logger = LoggerFactory.getLogger(JSONAnalyzerService::class.java)
+    } // Companion object
+
     var dataService = BaseDataService
 
     /**
@@ -114,6 +119,8 @@ open class JSONAnalyzerService {
         if (!result) {
             return "获取model异常"
         }
+        logger.debug("异常1*************************************************************************************************")
+
         // 处理VirtualWall, 填充数据, replace插入表
         result = result and BaseBehavier.analyze(
                 dataService.virtualWallService as SObjectService<BaseComponent>,
@@ -123,6 +130,7 @@ open class JSONAnalyzerService {
         if (!result) {
             return "处理VirtualWall异常"
         }
+        logger.debug("异常2*************************************************************************************************")
         // 处理Wall, 填充数据, replace插入表
         result = result and BaseBehavier.analyze(
                 dataService.wallService as SObjectService<BaseComponent>,
@@ -132,6 +140,7 @@ open class JSONAnalyzerService {
         if (!result) {
             return "处理Wall异常"
         }
+        logger.debug("异常3*************************************************************************************************")
         // 处理door, 填充数据, 填充wallId, replace插入表
         result = result and DoorWindowAnalyzer.analyze(
                 dataService.doorService as SObjectService<WindowDoorBase>,
@@ -141,6 +150,7 @@ open class JSONAnalyzerService {
         if (!result) {
             return "处理door异常"
         }
+        logger.debug("异常4*************************************************************************************************")
         // 处理Window, 填充数据, 填充wallId, replace插入表
         result = result and DoorWindowAnalyzer.analyze(
                 dataService.windowService as SObjectService<WindowDoorBase>,
@@ -150,6 +160,7 @@ open class JSONAnalyzerService {
         if (!result) {
             return "处理Window异常"
         }
+        logger.debug("异常5*************************************************************************************************")
         // 处理column, 填充数据, replace插入表
         result = result and BaseBehavier.analyze(
                 dataService.columnService as SObjectService<BaseComponent>,
@@ -159,11 +170,13 @@ open class JSONAnalyzerService {
         if (!result) {
             return "处理column异常"
         }
+        logger.debug("异常6*************************************************************************************************")
         // 处理Space, 填充数据, replace插入表
         result = result and SpaceAnalyzer.analyze(dataService.spaceService, baseObj, baseObj.elements!!.spaces)
         if (!result) {
             return "处理Space异常"
         }
+        logger.debug("异常7*************************************************************************************************")
         //---------------------------------------------------------
         //12.20临时演示方案,room当作space
         if(checkProject){
@@ -172,7 +185,7 @@ open class JSONAnalyzerService {
                 return "处理Room异常"
             }
         }
-
+        logger.debug("异常8*************************************************************************************************")
 
 //        //处理Room, 填充数据, replace插入表
 //        result = result and RoomAnalyzer.analyze(dataService.roomService, baseObj, baseObj.elements!!.rooms)
@@ -190,7 +203,7 @@ open class JSONAnalyzerService {
         if (!result) {
             return "处理BoundarySegment异常"
         }
-
+        logger.debug("异常9*************************************************************************************************")
         var pipes = baseObj.elements!!.pipes as ArrayList<BaseComponent>?
         var flexPipes = baseObj.elements!!.flexPipes as ArrayList<BaseComponent>?
         var ducts = baseObj.elements!!.ducts as ArrayList<BaseComponent>?
@@ -228,6 +241,7 @@ open class JSONAnalyzerService {
         if (!result) {
             return "处理Pipe异常"
         }
+        logger.debug("异常10*************************************************************************************************")
         // 处理flexPipe
         result = result and RevitIdAnalyzer.analyzePipesDucts(
                 dataService.pipeService as SObjectService<BaseComponent>,
@@ -241,6 +255,7 @@ open class JSONAnalyzerService {
         if (!result) {
             return "处理FlexPipe异常"
         }
+        logger.debug("异常11*************************************************************************************************")
         // 处理duct
         result = result and RevitIdAnalyzer.analyzePipesDucts(
                 dataService.ductService as SObjectService<BaseComponent>,
@@ -254,6 +269,7 @@ open class JSONAnalyzerService {
         if (!result) {
             return "处理Duct异常"
         }
+        logger.debug("异常12*************************************************************************************************")
         // 处理flexDuct
         result = result and RevitIdAnalyzer.analyzePipesDucts(
                 dataService.ductService as SObjectService<BaseComponent>,
@@ -267,7 +283,7 @@ open class JSONAnalyzerService {
         if (!result) {
             return "处理FlexDuct异常"
         }
-
+        logger.debug("异常13*************************************************************************************************")
         // 处理other
         result = result and RevitIdAnalyzer.analyze(
                 dataService.otherService as SObjectService<BaseComponent>,
@@ -278,6 +294,7 @@ open class JSONAnalyzerService {
         if (!result) {
             return "处理other异常"
         }
+        logger.debug("异常14*************************************************************************************************")
         // 处理joinObject
         result = result and RevitIdAnalyzer.analyze(
                 dataService.joinObjectService as SObjectService<BaseComponent>,
@@ -288,6 +305,7 @@ open class JSONAnalyzerService {
         if (!result) {
             return "处理joinObject异常"
         }
+        logger.debug("异常15*************************************************************************************************")
         // 处理equipment
 //        result = result and EquipmentAnalyzer.analyze(
 //                dataService.equipmentService,
@@ -302,7 +320,8 @@ open class JSONAnalyzerService {
                 dataService.equipmentService,
                 baseObj,
                 baseObj.elements!!.equipments,
-                bimIdPrefix, revitIdMap,
+                bimIdPrefix,
+                revitIdMap,
                 checkProject,
                 dataService.equipCompService,
                 dataService.infoPointCompService,
@@ -312,6 +331,7 @@ open class JSONAnalyzerService {
         if (!result) {
             return "处理equipment异常"
         }
+        logger.debug("异常16*************************************************************************************************")
         // 处理部件(component)
         result = result and EquipmentAnalyzer.analyzeComponent(
                 dataService.componentService,
@@ -323,7 +343,7 @@ open class JSONAnalyzerService {
         if (!result) {
             return "处理component异常"
         }
-
+        logger.debug("异常17*************************************************************************************************")
         // 处理连接件
         result = result and RevitIdAnalyzer.analyzeConnector(
                 dataService.connectorService,
@@ -336,7 +356,7 @@ open class JSONAnalyzerService {
         if (!result) {
             return "处理连接件异常"
         }
-
+        logger.debug("异常18*************************************************************************************************")
         // 处理level, 标高
         result = result and BaseBehavier.analyze(
                 dataService.levelService as SObjectService<BaseComponent>,
@@ -346,6 +366,7 @@ open class JSONAnalyzerService {
         if (!result) {
             return "处理level异常"
         }
+        logger.debug("异常19*************************************************************************************************")
         // 处理grid, 轴网
         result = result and BaseBehavier.analyze(
                 dataService.gridService as SObjectService<BaseComponent>,
@@ -355,6 +376,7 @@ open class JSONAnalyzerService {
         if (!result) {
             return "处理grid异常"
         }
+        logger.debug("异常20*************************************************************************************************")
         return null
     }
 

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

@@ -18,7 +18,7 @@ spring:
     name:                               revit-algorithm
     type:                               com.alibaba.druid.pool.DruidDataSource
     driver-class-name:                  org.postgresql.Driver
-    url:                                jdbc:postgresql://172.17.100.16:5432/datacenter
+    url:                                jdbc:postgresql://172.17.23.64:5432/datacenter
     #    url:                                jdbc:postgresql://192.168.20.250:5432/postgres
     #    url:                                jdbc:postgresql://47.94.89.44:5432/datacenter
     username:                           postgres
@@ -75,7 +75,8 @@ properties:
   fileService:
     # 基本属性
     #url:                               http://api.sagacloud.cn/dp-auxiliary/image-service/ # http://47.93.33.207:28888/image-service/ #http://adm.sagacloud.cn/image-service/
-    url:                               http//39.97.179.199:8891/image-service/
+    url:                               http://47.93.22.124:8080/image-service/
+#    url:                               http//172.17.11.254:8891/image-service/
     systemId:                          revit
     secret:                            63afbef6906c342b
     dir:                               model
@@ -99,7 +100,7 @@ properties:
     mergeMultipartUpload:              ${properties.fileService.url}common/merge_multipart${properties.fileService.suffixWithSecret}&uploadId=
 
   scheduler:
-    url:                               http://172.17.100.16:8080/scheduler/
+    url:                               http://172.17.100.16:28888/scheduler/
     createTask:                        ${properties.scheduler.url}task/create
     queryTask:                         ${properties.scheduler.url}task/query
     queryTaskResult:                   ${properties.scheduler.url}result/query
@@ -107,7 +108,7 @@ properties:
 
 
   datacenter:
-    url:                               http://172.17.100.16:8080/datacenter/
+    url:                               http://172.17.100.16:28888/datacenter/
     # 设备相关接口
     equipCreate: ${properties.datacenter.url}object/equip/create
     equipDelete: ${properties.datacenter.url}object/equip/delete
@@ -137,6 +138,6 @@ properties:
     doorCreate: ${properties.datacenter.url}door/create_ignore
 
   message:
-    url: http://172.17.100.16:8080/message-center/
+    url: http://172.17.100.16:28888/message-center/
     # 发送消息接口
     createPath: ${properties.message.url}message/create