Quellcode durchsuchen

空间交通关系

caiaf vor 4 Jahren
Ursprung
Commit
9b972e1095

+ 12 - 0
datacenter/src/main/kotlin/com/persagy/server/controllers/relation_calc/RelationCalcController.kt

@@ -339,4 +339,16 @@ class RelationCalcController {
         return service.setMarks(projectId)
     } // Function calcSy2Sp()
 
+
+    /**
+     * 空间交通关系
+     */
+    @Operation(summary = "空间交通关系", description = "")
+    @PostMapping(value = ["/sp2sp"])
+    fun sp2spV3(@RequestParam buildingId: String,@RequestParam objectType: String,@RequestParam type: String): SBaseResponse {
+        val projectId = SPageContext.getHeader("projectId").toString()
+        logger.debug("calcSy2Sp --------------$projectId")
+        return service.calcSp2Sp(projectId,buildingId,objectType,type)
+    } // Function calcSy2Sp()
+
 } // Class RelationCalcController

+ 37 - 0
datacenter/src/main/kotlin/com/persagy/server/models/entities/BaseComponent.kt

@@ -0,0 +1,37 @@
+package cn.sagacloud.server.algorithm.models.entities
+
+import com.alibaba.fastjson.annotation.JSONField
+import com.fasterxml.jackson.annotation.JsonProperty
+import com.persagy.service.models.SBaseEntity
+import javax.persistence.Column
+import javax.persistence.Id
+
+/**
+ *
+ *
+ * @author jxing
+ */
+open class BaseComponent : SBaseEntity(){
+
+    /** 模型id */
+    @Column(name = "id", updatable = false)
+    @Id
+    var id: String? = null
+
+    /** 模型id(外键) */
+    @Column(name = "model_id")
+    var modelId: String? = null
+
+    @Column(name = "type")
+    var elementType : String? = null
+
+    @Column(name = "revit_id")
+    var revitId : String? = null
+
+    /** 对应Revit模型id */
+    @Column(name = "source_id")
+    var sourceId: String? = null
+
+    /** 模型所属楼层的id, 是uuid */
+    var modelFloorId: String? = null
+}

+ 102 - 0
datacenter/src/main/kotlin/com/persagy/server/models/entities/Door.kt

@@ -0,0 +1,102 @@
+/*
+ * ********************************************************************************************************************
+ *
+ *                      :*$@@%$*:                         ;:                ;;    ;;
+ *                    :@@%!  :!@@%:                       %!             ;%%@@%$ =@@@@@@@%;     @%@@@%%%%@@@@@
+ *                   :@%;       :$=                       %%$$$%$$         ;$$  ;$@=   !@$
+ *                   =@!                                  %!              @ $=;%   !@@@%:      !$$$$$$$$$$$$$$=
+ *                   =@*                                  %!              @ $= % %@=   =%@!      %=
+ *              *$%%! @@=        ;=$%%%$*:                %!              @ $= % =%%%%%%@$      *%:         =%
+ *            %@@!:    !@@@%=$@@@@%!  :*@@$:              %!              @ $= % $*     ;@      @*          :%*
+ *          ;@@!          ;!!!;:         ;@%:      =======@%========*     @ $$ % $%*****$@     :@$=*********=@$
+ *          $@*   ;@@@%=!:                *@*
+ *          =@$    ;;;!=%@@@@=!           =@!
+ *           %@$:      =@%: :*@@@*       %@=                    Copyright (c) 2016-2019.  北京上格云技术有限公司
+ *            ;%@@$=$@@%*       *@@@$=%@@%;
+ *               ::;::             ::;::                                              All rights reserved.
+ *
+ * ********************************************************************************************************************
+ */
+
+package cn.sagacloud.server.algorithm.models.entities
+
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties
+import com.persagy.server.datacenter.models.entities.graphtype.MLocation
+import com.persagy.server.datacenter.models.entities.graphtype.MPoint
+import javax.persistence.Column
+import javax.persistence.Table
+/**
+ * 门
+ *
+ * @author jxing
+ */
+@Table(name = "revit.door")
+@JsonIgnoreProperties(ignoreUnknown = true)
+class Door : WindowDoorBase() {
+
+    /** 名称 */
+    @Column(name = "name")
+    var name: String? = null
+
+
+    /** 定位点 */
+    @Column(name = "location")
+    var location: MLocation? = null
+
+    /** 轮廓线 */
+    @Column(name = "outline")
+    var outline: ArrayList<ArrayList<MPoint>>? = null
+
+    /** 面方向 */
+    @Column(name = "face_direction")
+    var faceDirection : MPoint? = null
+
+    /** Hand方向 */
+    @Column(name = "hand_direction")
+    var handDirection : MPoint? = null
+
+    /** 类型中文名称 */
+    @Column(name = "family_name")
+    var familyName: String? = null
+
+    /** 族符号 */
+    @Column(name = "family_symbol")
+    var familySymbol: String? = null
+
+
+    @Column(name = "thick")
+    var thick : Double? = null
+
+    // 以下是json解析字段
+
+//    @JSONField(name = "Owner")
+//    var jsonOwner : String? = null //
+//
+//    @JSONField(name = "Location")
+//    var jsonLocation : Location? = null //
+//
+//    @JSONField(name = "OutLine")
+//    var jsonOutline : ArrayList<ArrayList<Point>>? = null //
+//
+//    @JSONField(name = "SourceId")
+//    var jsonSourceId : String? = null //
+//
+//    @JSONField(name = "FaceDirection")
+//    var jsonFaceDirection : Point? = null //
+//
+//    @JSONField(name = "HandDirection")
+//    var jsonHandDirection : Point? = null //
+//
+//    @JSONField(name = "Thick")
+//    var jsonThick : Double? = null //
+//
+//    @JSONField(name = "Id")
+//    var jsonId : String? = null //
+//
+//    @JSONField(name = "ElementType")
+//    var jsonElementType : String? = null //
+//
+//    @JSONField(name = "Name")
+//    var jsonName: String? = null  //
+}

+ 23 - 0
datacenter/src/main/kotlin/com/persagy/server/models/entities/WindowDoorBase.kt

@@ -0,0 +1,23 @@
+package cn.sagacloud.server.algorithm.models.entities
+
+import com.alibaba.fastjson.annotation.JSONField
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties
+import com.fasterxml.jackson.annotation.JsonProperty
+import javax.persistence.Column
+
+/**
+ *
+ *
+ * @author jxing
+ */
+@JsonIgnoreProperties(ignoreUnknown = true)
+open class WindowDoorBase : BaseComponent() {
+
+    /** 所属墙 */
+    @Column(name = "wall_id")
+    var wallId: String? = null
+
+    /** 拥有者的RevitId */
+    @Column(name = "owner")
+    var owner: String? = null
+}

+ 27 - 0
datacenter/src/main/kotlin/com/persagy/server/models/object/TwicePoint.kt

@@ -0,0 +1,27 @@
+package com.persagy.server.models.`object`
+
+/**
+ *
+ * @author  Cainga
+ * @date  2021/2/13 14:47
+ */
+open class TwicePoint(x1: Double,y1:Double,x2:Double,y2:Double) {
+
+
+
+    var x1: Double? = null
+
+    var x2: Double? = null
+
+    var y1: Double? = null
+
+    var y2: Double? = null
+
+    //init代码块中可以访问主构造方法中的变量
+    init {
+        this.x1=x1
+        this.y1=y1
+        this.x2 = x2
+        this.y2 = y2
+    }
+}

+ 9 - 0
datacenter/src/main/kotlin/com/persagy/server/models/service/BaseDataService.kt

@@ -0,0 +1,9 @@
+package com.persagy.server.models.service
+
+import cn.sagacloud.server.algorithm.models.entities.Door
+import com.persagy.mybatis.SMybatisDao
+import com.persagy.service.SObjectService
+
+object BaseDataService {
+    val doorService = SObjectService(SMybatisDao(Door::class.java))
+}

+ 93 - 0
datacenter/src/main/kotlin/com/persagy/server/services/relation_calc/CommonService.kt

@@ -0,0 +1,93 @@
+package com.persagy.server.services.relation_calc
+
+
+import com.persagy.server.datacenter.models.entities.assistant.PointPosition
+import com.persagy.server.datacenter.models.entities.graphtype.MPoint
+import org.springframework.util.DigestUtils
+import java.awt.geom.Area
+import java.awt.geom.GeneralPath
+import java.awt.geom.Point2D
+
+
+
+/**
+ *
+ *
+ * @author jxing
+ */
+object CommonService {
+
+
+    /**
+     * 获取MD5值
+     */
+    fun getMD5(btInput : ByteArray) : String {
+        return DigestUtils.md5DigestAsHex(btInput)
+    }
+
+    /**
+     * 获取文件服务器中的文件路径
+     */
+    fun getFilePathInFileService(uploadPath : String, modelId : String) : String{
+        return "${uploadPath}${modelId}.rvt"
+    }
+
+    /**
+     * 获取文件服务器中的key
+     */
+    fun getFileKeyInFileService(dir : String, modelId : String) : String{
+        return "${dir}/${modelId}.rvt"
+    }
+
+    /**
+     * 是否点在多边形内
+     */
+    fun isPointInPolygonCheckWithJdkGeneralPath(point: MPoint, polygon: ArrayList<PointPosition>): Boolean {
+        if(polygon.isEmpty())
+            return false
+        val p = getGeneralPath(polygon)
+        val newPoint = Point2D.Double()
+        newPoint.x = point.x
+        newPoint.y = point.y
+        return p.contains(newPoint)
+    }
+
+    /**
+     * 生成bimid前缀
+     */
+    fun generateBIMIDPrefix(projectId : String, folderId : String, floorName : String, hasColon : Boolean): String{
+        if(hasColon){
+            return "${projectId}${folderId}${floorName}:"
+        }
+        return "${projectId}${folderId}${floorName}"
+    }
+
+
+    /**
+     * 根据点数组获取围成的GeneralPath对象
+     */
+    fun getGeneralPath(polygon : ArrayList<PointPosition>) : GeneralPath{
+        val p = GeneralPath()
+        val first = polygon[0]
+        p.moveTo(first.x!!, first.y!!)
+        for (index in polygon.indices) {
+            if(index == 0)
+                continue
+            val tmpPoint = polygon[index]
+            p.lineTo(tmpPoint.x!!, tmpPoint.y!!)
+        }
+        p.lineTo(first.x!!, first.y!!)
+        p.closePath()
+        return p
+    }
+
+
+
+
+    /**
+     * 获取异常的堆栈信息
+     */
+    fun getStackTrace(e : Throwable): String? {
+        return org.apache.commons.lang3.exception.ExceptionUtils.getStackTrace(e)
+    }
+}

+ 149 - 3
datacenter/src/main/kotlin/com/persagy/server/services/relation_calc/RelationCalcService.kt

@@ -29,24 +29,29 @@ package com.persagy.server.services.relation_calc
 import com.persagy.database.SFilter
 import com.persagy.mybatis.SMybatisDao
 import com.persagy.server.Opt
+import com.persagy.server.datacenter.models.entities.graphtype.MPoint
 import com.persagy.server.datacenter.models.entities.graphtype.RelationTypeProject
-import com.persagy.server.datacenter.models.entities.rel.REq2Sp
+import com.persagy.server.datacenter.models.entities.rel.RSp2Sp
 import com.persagy.server.jms.RabbitMqService
 import com.persagy.server.mappers.IRelationCalcMapper
+import com.persagy.server.models.`object`.TwicePoint
+import com.persagy.server.models.service.BaseDataService
 import com.persagy.server.services.assistant.RUpDateEquipAndSapceService
+import com.persagy.server.services.base.RService
 import com.persagy.server.services.objects.EquipmentService
+import com.persagy.server.services.objects.FloorService
 import com.persagy.server.services.objects.ZoneSpaceBaseService
 import com.persagy.server.services.rel.REq2SpService
 import com.persagy.server.utils.IdUtils
 import com.persagy.service.SBaseService
 import com.persagy.service.models.enums.SResponseType
+import com.persagy.service.models.requests.SCreateRequest
 import com.persagy.service.models.responses.SBaseResponse
 import com.persagy.service.utils.SSpringContextUtil
+import com.vividsolutions.jts.geom.GeometryFactory
 import org.slf4j.LoggerFactory
 import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.stereotype.Service
-import java.util.*
-import kotlin.collections.ArrayList
 
 /**
  * 自动关系计算
@@ -1181,4 +1186,145 @@ open class RelationCalcService {
         }
     }
 
+    /**
+     * @Description: 空间交通关系
+     * @Param:
+     * @Return:
+     */
+    fun calcSp2Sp(projectId: String,buildingId: String,objectType: String,type: String):SBaseResponse{
+        val distance = 100.00
+        val floors = FloorService.select(SFilter.eq("projectId",projectId), SFilter.eq("buildingId",buildingId)).exec()
+        val rSp2Sps =  ArrayList<RSp2Sp>()
+        for (floor in floors) {
+            if(!floor.modelId.isNullOrEmpty()){
+                val zoneSpaces = ZoneSpaceBaseService.select(SFilter.eq("projectId",projectId), SFilter.eq("floorId",floor.id!!), SFilter.eq("classCode",objectType)).exec()
+                val doors = BaseDataService.doorService.select(SFilter.eq("modelId",floor.modelId!!)).exec()
+                val pointList = ArrayList<TwicePoint>()
+
+                for (door in doors) {
+                    val outline = door.outline
+                    val point = door!!.location!!.points?.get(0)!!
+                    if(!outline.isNullOrEmpty()){
+                        val point1 = outline[0]!![0]
+                        val point2 = outline[0]!![1]
+                        val k = get_points(point1.x,point1.y,point2.x,point2.y)
+                        var twicePoint: TwicePoint
+                        if(k== null){
+                            twicePoint = TwicePoint(point.x,point.y+distance,point.x,point.y-distance)
+                        }else{
+//                            val distance = get_segment_distance(point1.x,point1.y,point2.x,point2.y)
+                            twicePoint = get_point_by_distance(point.x,point.y,k,distance*2)
+                        }
+                        pointList.add(twicePoint)
+                    }
+                }
+
+                val map = HashMap<Int,ArrayList<String>>()
+                for (index in 0 until pointList.size) {
+                    val mPoint1= MPoint(pointList[index].x1!!,pointList[index].y1!!,0.00)
+                    val mPoint2= MPoint(pointList[index].x2!!,pointList[index].y2!!,0.00)
+                    var isLocal1: Boolean
+                    var isLocal2: Boolean
+
+                    for (zoneSpace in zoneSpaces) {
+                        val zoneOutline = zoneSpace.outline
+                        if(zoneOutline.isNullOrEmpty()){
+                            continue
+                        }
+                        isLocal1 = CommonService.isPointInPolygonCheckWithJdkGeneralPath(mPoint1, zoneOutline?.get(0)?.get(0)!!)
+                        isLocal2 = CommonService.isPointInPolygonCheckWithJdkGeneralPath(mPoint2, zoneOutline?.get(0)?.get(0)!!)
+                        val spaceId = zoneSpace.id!!
+                        if(isLocal1 || isLocal2)
+                            if(map.containsKey(index)){
+                                val list = map[index]!!
+                                list.add(spaceId)
+                                map[index] = list
+                            }else{
+                                map[index] = arrayListOf(spaceId)
+                            }
+
+                    }
+
+                }
+                //map遍历
+                for (v in map.values) {
+
+                    val key = v[0] !!
+                    if(v.size > 1){
+                        for (index in  1 until v.size) {
+                            val rSp2SP = RSp2Sp()
+                            rSp2SP.id1 = key
+                            rSp2SP.id2 = v[index]
+                            rSp2SP.projectId = projectId
+                            rSp2SP.sign = 1
+                            rSp2SP.type = type
+                            rSp2SP.zoneType = objectType
+                            if(!rSp2Sps.contains(rSp2SP)){
+                                rSp2Sps.add(rSp2SP)
+                            }
+                        }
+                    }
+
+
+
+                }
+            }
+            val rSp2SpService = RService(SMybatisDao(RSp2Sp::class.java))
+            for (rSp2Sp in rSp2Sps) {
+                rSp2SpService.replace(rSp2Sp)
+            }
+        }
+        return SBaseResponse(SResponseType.success,"")
+    }
+
+
+    fun get_points(x1: Double, y1: Double , x2: Double, y2: Double): Double?{
+        if (x1 == y1 && x2 == y2){
+            return null
+        }
+        var k:Double? = null
+        // 计算当前线段的 k
+        if (x1 == x2){
+
+        }else{
+            k = (y2 - y1) / (x2 - x1)
+        }
+        var k2:Double?
+        //计算垂直方向的k
+        if (k == null){
+            k2 = 0.00
+        }else if(k == 0.00){
+            k2 = null
+        }else{
+            k2 = 1/k
+        }
+        return k2
+    }
+
+    //获取两点之间的距离
+    fun get_segment_distance(x1: Double, y1: Double , x2: Double, y2: Double): Double{
+        val x_diff = x2 - x1
+        val y_diff = y2 - y1
+        return Math.sqrt(x_diff * x_diff + y_diff * y_diff)
+    }
+
+    //获取坐标
+    fun  get_point_by_distance(base_x: Double, base_y: Double, k: Double, distance: Double): TwicePoint{
+        if(k == null){
+            return TwicePoint(base_x, base_y + distance, base_x, base_y - distance)
+        }
+        val vector_x1 = Math.sqrt(distance * distance / (1 + k * k))
+        val vector_x2 = -vector_x1
+        val vector_y1 = k * vector_x1
+        val vector_y2 = k * vector_x2
+        return TwicePoint(base_x + vector_x1,base_y + vector_y1,base_x + vector_x2,base_y + vector_y2)
+    }
+
+
+
+
+
+
+
+
 } // Class RelationCalcService

+ 2 - 2
datacenter/src/main/resources/application-dev.yml

@@ -34,7 +34,7 @@ spring:
     type:                               com.alibaba.druid.pool.DruidDataSource
     driver-class-name:                  org.postgresql.Driver
 #    url:                                jdbc:postgresql://60.205.177.43:5432/datacenterlabsl
-    url:                                jdbc:postgresql://39.102.40.239:5432/datacenter
+    url:                                jdbc:postgresql://192.168.64.15:5432/datacenterwanda
     username:                           postgres
 #    password:                           persagy_2020qwe!@#
     password:                           cGVyc2FneV8yMDIwcXdlIUAj
@@ -46,7 +46,7 @@ spring:
 
     #配置rabbitMq 服务器
   rabbitmq:
-    host: 39.102.43.179
+    host: 192.168.64.15
     port: 9936
     username: admin
     password: brzj123456