Bladeren bron

官网连接计算

caiaf 4 jaren geleden
bovenliggende
commit
ca234dc399

+ 175 - 39
datacenter/src/main/kotlin/com/persagy/server/datacenter/services/relation_calc/CalcSpecialService.kt

@@ -24,19 +24,22 @@
  * *********************************************************************************************************************
  */
 
-package com.persagy.server.datacenter.services.relation_calc
+package com.persagy.server.services.relation_calc
 
+import com.persagy.base.extensions.toJson
 import com.persagy.database.SFilter
 import com.persagy.mybatis.SMybatisDao
-import com.persagy.server.datacenter.datacenter.wanda.rel.REq2Eq
 import com.persagy.server.datacenter.models.entities.graphtype.RelationTypeProject
 import com.persagy.server.datacenter.models.entities.graphtype.block.ConnectedBlock
+import com.persagy.server.datacenter.wanda.rel.REq2Eq
 import com.persagy.server.mappers.ICalcSpecialMapper
+import com.persagy.server.models.`object`.ClassCodeEnum
+import com.persagy.server.models.`object`.NetWork
 import com.persagy.server.models.entities.Connector
+import com.persagy.server.models.service.BaseDataService
 import com.persagy.server.services.assistant.RUpDateEquipAndSapceService
 import com.persagy.server.services.objects.EquipmentService
 import com.persagy.server.services.objects.FloorService
-import com.persagy.server.services.relation_calc.MepSystemCalcService
 import com.persagy.server.utils.IdUtils
 import com.persagy.service.SBaseService
 import com.persagy.service.SObjectService
@@ -47,6 +50,7 @@ import com.persagy.service.models.responses.SBaseResponse
 import org.json.JSONObject
 import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.stereotype.Service
+import org.springframework.web.bind.annotation.RequestParam
 
 /**
  * 关系计算-管网
@@ -254,63 +258,195 @@ open class CalcSpecialService {
      * @Return:
      */
     fun calcNetworks(projectId: String,buildingId: String): SBaseResponse{
-        val floors = FloorService.select(SFilter.eq("projectId",projectId), SFilter.eq("buildingId",buildingId)).exec()
-        val rEq2Eqs = ArrayList<REq2Eq>()
+        val floors = FloorService.select(SFilter.eq("projectId",projectId), SFilter.eq("buildingId",buildingId),SFilter.eq("id","Fl440307000355ee6382da6d42cf87f19551cc4b4e60")).exec()
+        val connectedBlocks = ArrayList<ConnectedBlock>()
+//        val connectorList = listOf("Equipment","JoinObject")
         for (floor in floors) {
-            if(!floor.modelId.isNullOrEmpty()){
+            if (!floor.modelId.isNullOrEmpty()) {
                 val connectors = mapper.connectorOrder(floor.modelId!!)
-                val dcEquipments = EquipmentService.select(SFilter.eq("projectId",projectId), SFilter.eq("floorId",floor.id!!)).exec()
-                val dcEquipMap = HashMap<String,String>(1024)
-                for (equipment in dcEquipments) {
-                    dcEquipMap[equipment.bimId!!] = equipment.id!!
-                }
+//                val dcEquipments = EquipmentService.select(SFilter.eq("projectId",projectId), SFilter.eq("floorId",floor.id!!)).exec()
+//                val dcEquipMap = HashMap<String,Equipment>(1024)
+//                for (equipment in dcEquipments) {
+//                    if(!equipment.bimId.isNullOrEmpty()){
+//                        dcEquipMap[equipment.bimId!!] = equipment
+//                    }
+//
+//                }
 
 
-                var currentConnector: Connector? = null
-                val map = HashMap<String,Connector>(100000)
+                val equipmentsConnector = ArrayList<Connector>()
+//                val map = HashMap<String, ArrayList<Connector>>(10000)
+                val connectorMap = HashMap<String, Connector>(100000)
+                val typeMap = HashMap<String, String>(10000)
                 for (connector in connectors) {
-                    map[connector.revitId!!] = connector
+                    connectorMap[connector.revitId!!] = connector
+                    if (connector.belongType == "Equipment") {
+                        equipmentsConnector.add(connector)
+                    }
+
+                    val belong = connector.belong ?: continue
+                    //                    if (map.containsKey(belong)) {
+//                        val connectorss = map[belong]!!
+//                        connectorss.add(connector)
+//                        map[belong] = connectorss
+//
+//                    } else {
+//                        map[belong] = arrayListOf(connector)
+//                    }
+                    val belongType = connector.belongType
+                    if (belongType != null) {
+                        typeMap[belong] = belongType
+                    }
+
                 }
+                val belongMap = HashMap<String, HashSet<String>>()
+
+                //遍历连接件
                 for (connector in connectors) {
-                    if(connector.isUsed == true){
-                        continue
+                    //拿到所属类
+                    val belongType = connector.belongType
+                    //拿到所属id
+                    val belong = connector.belong
+
+
+//                    //如果连接件有连接
+                    if (connector.connectedIds!!.size > 0 && belong != null) {
+                        val revitId = connector!!.connectedIds?.get(0)
+                        var currentConnector = connectorMap[revitId!!]
+                        val cBelong = currentConnector?.belong
+                        if (cBelong != null) {
+
+                            if (belongMap.containsKey(belong)) {
+                                val belongs = belongMap[belong]!!
+                                belongs.add(cBelong)
+                                belongMap[belong] = belongs
+                            } else {
+                                belongMap[belong] = hashSetOf(cBelong)
+                            }
+                        }
                     }
-                    currentConnector = connector
-                    val id1 = dcEquipMap[connector.belongBimId]
-                    if(id1 == null){
+                }
+                for (key in belongMap.keys) {
+                    if(typeMap[key] != "Equipment"){
                         continue
                     }
-                    while(currentConnector!!.connectedIds!!.size == 1){
-                        val revitId = currentConnector!!.connectedIds?.get(0)
-                        currentConnector = map[revitId]!!
-                        if(currentConnector!!.belongType == "Equipment" && connector!!.belongType == "Equipment" && currentConnector != connector){
-
-                            val id2 = dcEquipMap[currentConnector.belongBimId]
-                            if(id2 != null){
-                                val rEq2Eq = REq2Eq()
-                                rEq2Eq.id1 = id1
-                                rEq2Eq.id2 = id2
-                                rEq2Eq.sign = 1
-                                rEq2Eq.projectId = projectId
-                                rEq2Eq.hasDirection = false
-                                rEq2Eq.type = ""
-                                rEq2Eqs.add(rEq2Eq)
+                    val belongSet = belongMap[key]!!
+                    val newWork = dist(belongSet,belongSet, belongMap,typeMap,belongSet)
+                    for (s in newWork.fullConnectors!!) {
+                        if(typeMap[s] == "Equipment" && key != s){
+
+                            val connectedBlock = ConnectedBlock()
+                            connectedBlock.id1 = key
+                            connectedBlock.id2 = s
+                            connectedBlock.type1 = "Equipment"
+                            connectedBlock.type2 = "Equipment"
+                            connectedBlock.modelId1 = floor.modelId
+                            connectedBlock.modelId2 = floor.modelId
+//                                connectedBlock.domain = connector.domain
+//                                connectedBlock.mepSystemType = connector.mepSystemType
+                            connectedBlock.projectId = projectId
+                            connectedBlock.buildingId = buildingId
+                            connectedBlock.depth = 1
+//                                connectedBlock.typeCode1 = e1?.classCode
+//                                connectedBlock.typeCode2 = e2?.classCode
+                            if (!connectedBlocks.contains(connectedBlock)) {
+                                connectedBlocks.add(connectedBlock)
                             }
 
+                        }
+                    }
+                    for (s in newWork.directConnectors!!) {
+                        if(typeMap[s] == "Equipment" && key != s){
 
+                            val connectedBlock = ConnectedBlock()
+                            connectedBlock.id1 = key
+                            connectedBlock.id2 = s
+                            connectedBlock.type1 = "Equipment"
+                            connectedBlock.type2 = "Equipment"
+                            connectedBlock.modelId1 = floor.modelId
+                            connectedBlock.modelId2 = floor.modelId
+//                                connectedBlock.domain = connector.domain
+//                                connectedBlock.mepSystemType = connector.mepSystemType
+                            connectedBlock.projectId = projectId
+                            connectedBlock.buildingId = buildingId
+                            connectedBlock.depth = 0
+//                                connectedBlock.typeCode1 = e1?.classCode
+//                                connectedBlock.typeCode2 = e2?.classCode
+                            if (!connectedBlocks.contains(connectedBlock)) {
+                                connectedBlocks.add(connectedBlock)
+                            }
 
                         }
-                        currentConnector.isUsed = true
                     }
+
                 }
             }
 
+
         }
-        val request = SCreateRequest<REq2Eq>()
-        request.content = rEq2Eqs
-        rEq2EqService.createList(request)
-        return SBaseResponse(SResponseType.failure, "e.message!!")
+        connectedBlockService.delete(SFilter.eq("projectId",projectId), SFilter.eq("buildingId",buildingId))
+        val request = SCreateRequest<ConnectedBlock>()
+        request.content = connectedBlocks
+        connectedBlockService.createList(request)
+        return SBaseResponse(SResponseType.success, "")
 
     }
 
+    /**
+     * @Description:递归查找连接
+     * @Param:
+     * @Return:
+     */
+     fun searchConnector(connector: Connector,currentConnector: Connector,map: HashMap<String,ArrayList<Connector>>,connectorMap: HashMap<String,Connector>): Connector?{
+        val belong = currentConnector.belong ?: return null
+        if(currentConnector.belongType == "Equipment" && currentConnector != connector){
+            return currentConnector
+        }else{
+//            println(currentConnector.belong)
+            val connectors = map[belong] ?: return null
+            for (connector in connectors) {
+                if(currentConnector.revitId != connector.revitId && connector.isConnected == true){
+                    val revitId = connector.connectedIds!![0]!!
+                    val ccConnector = connectorMap[revitId]!!
+                    return searchConnector(connector,ccConnector,map,connectorMap)
+                }else{
+                    continue
+                }
+            }
+            return null
+        }
+     }
+
+    fun dist(list: HashSet<String>,directList:HashSet<String>, belongMap: HashMap<String,HashSet<String>>,typeMap: HashMap<String,String>,newList: HashSet<String>): NetWork{
+//        val list = belongMap[key]!!
+//                    val connectList = ArrayList<String>()
+//        while(list)
+        val beforeList = HashSet<String>(list)
+        for (belong in newList) {
+            if(belongMap[belong] == null){
+                continue
+            }
+            if(typeMap[belong] != "Equipment"){
+                directList.addAll(belongMap[belong]!!)
+            }
+            list.addAll(belongMap[belong]!!)
+        }
+        if(beforeList.containsAll(list)){
+            return NetWork(list,directList)
+        }else{
+            newList.remove(beforeList)
+            return dist(list,beforeList,belongMap,typeMap,newList)
+        }
+
+    }
+
+//    fun calcNetworks(projectId: String,buildingId: String): SBaseResponse{
+//        val connectedBlocks = connectedBlockService.select(SFilter.eq("projectId",projectId), SFilter.eq("buildingId",buildingId)).exec()
+//        val classCodeList = ArrayList<String>()
+//        for (classCodeEnum in ClassCodeEnum.values()) {
+//            classCodeList.add(classCodeEnum.name)
+//        }
+//        val cb = connectedBlocks.filter { s -> classCodeList.contains(s.typeCode1)  || classCodeList.contains(s.typeCode2) }
+//    }
+
 } // Class CalcSpecialService

+ 18 - 0
datacenter/src/main/kotlin/com/persagy/server/models/object/NetWork.kt

@@ -0,0 +1,18 @@
+package com.persagy.server.models.`object`
+
+/**
+ *
+ * @author  Cainga
+ * @date  2021/2/27 11:08
+ */
+open class NetWork {
+
+    var fullConnectors: HashSet<String>? = null
+
+    constructor(fullConnectors: HashSet<String>?, directConnectors: HashSet<String>?) {
+        this.fullConnectors = fullConnectors
+        this.directConnectors = directConnectors
+    }
+
+    var directConnectors: HashSet<String>? = null
+}