Browse Source

********************WX***********************
同步关系

zhangweixin 4 năm trước cách đây
mục cha
commit
d7e00fdd17

+ 21 - 1
datacenter/src/main/kotlin/com/persagy/server/services/assistant/SchemeService.kt

@@ -29,7 +29,9 @@ package com.persagy.server.services.assistant
 import com.persagy.database.SFilter
 import com.persagy.server.Opt
 import com.persagy.server.datacenter.dao.mappers.SchemeMapper
+import com.persagy.server.jms.RabbitMqService
 import com.persagy.server.services.objects.FloorService
+import com.persagy.service.utils.SSpringContextUtil
 import org.slf4j.LoggerFactory
 import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.stereotype.Service
@@ -45,8 +47,14 @@ open class SchemeService {
     companion object {
         /** 日志 */
         private val logger = LoggerFactory.getLogger(SchemeService::class.java)
+
     } // Companion object
 
+    /** RabbitMQ消息对象 */
+    val rabbitMqService by lazy {
+        SSpringContextUtil.getBean(RabbitMqService::class.java) as RabbitMqService
+    }
+
     /** 实例化 mapper 对象 */
     @Autowired
     lateinit var mapper: SchemeMapper
@@ -133,6 +141,8 @@ open class SchemeService {
            if (!oldBimId.isNullOrEmpty()){
                oldBimIdNew = oldBimId
            }
+           logger.debug( "前缀数据bimId =  ${bimId} *******************************************************")
+           logger.debug( "前缀数据oldBimId =  ${oldBimId} *******************************************************")
             val rUpDateEquipAndSapce = mapper.rUpDateEquipAndSapce(projectId, oldBimIdNew, bimId, floorId)
 
            val floorEntity = FloorService.select(SFilter.eq("id", floorId)).entity()
@@ -152,6 +162,11 @@ open class SchemeService {
                    floorEntity.infos = map
                }
                floorEntity.modelId = modelId
+               if (!floorEntity.bimIdPre.isNullOrEmpty()) {
+                   floorEntity.bimIdPre = bimId
+               } else {
+                   floorEntity.bimIdPre = bimId
+               }
                /** 处理楼层标高 */
                if (!attributeMap.isNullOrEmpty()&&attributeMap.size>0){
                    val containsKey = attributeMap.containsKey(Opt.FLOORELEVATION)
@@ -168,7 +183,12 @@ open class SchemeService {
                }
                var list = ArrayList<SFilter>()
                list.add(SFilter.eq("id",floorId))
-               FloorService.update(floorEntity,null,list)
+
+               val update = FloorService.update(floorEntity, null, list)
+               if (update){
+                   rabbitMqService.sendObjects(projectId!!, Opt.UPDATE,floorEntity.id!!)
+                   rabbitMqService.sendObjects(projectId!!, "equip",floorEntity.id!!)
+               }
            }
            return rUpDateEquipAndSapce
         } catch (e: Exception) {

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

@@ -360,7 +360,7 @@ open class RelationCalcService {
             if(result!=null && result == 0){
                 try {
                     /** 发送消息 */
-                    rabbitMqService.sendRel(Opt.projectId!!, "Eq2Sh_in","20",tables!!,"456")
+                    rabbitMqService.sendRel(Opt.projectId!!, "Eq2Sp_in","20",tables!!,"456")
                     upDate(projectId,"fl2sp")
                     upDate(projectId,"eq2fl")
                     val entity = relationTypeProjectservice.select(SFilter.eq("projectId", projectId), SFilter.eq("relationType", "eq2sp_in"), SFilter.eq("zoneType",tables!!)).entity()

+ 9 - 9
datacenter/src/main/resources/application-prod.yml

@@ -31,20 +31,20 @@ spring:
 #    url:                                jdbc:postgresql://data-center:5432/datacenter
 #    username:                           postgres
 #    password:                           123qwe!@#
-#    url:                                jdbc:postgresql://172.17.100.16:5432/datacenter
-    url:                                jdbc:postgresql://172.17.11.228:5432/datacenterlabsl
+    url:                                jdbc:postgresql://172.17.100.16:5432/datacenter
+#    url:                                jdbc:postgresql://172.17.11.228:5432/datacenterlabsl
 #    url:                                jdbc:postgresql://192.168.64.14:5432/datacenterlabsl
     username:                           postgres
 #    password:                           persagy_2020qwe!@#
     password:                           cGVyc2FneV8yMDIwcXdlIUAj
 
-#  rabbitmq:
-#    host: 39.102.43.179
-#    port: 9936
-#    username: admin
-#    password: brzj123456
-#    #虚拟host 可以不设置,使用server默认host
-#    virtual-host: /test
+  rabbitmq:
+    host: 39.102.43.179
+    port: 9936
+    username: admin
+    password: brzj123456
+    #虚拟host 可以不设置,使用server默认host
+    virtual-host: /test
 
   servlet:
     multipart:

+ 11 - 8
datasyn/src/main/kotlin/com/persagy/server/syn/controllers/obj/ObjectToFromController.kt

@@ -168,15 +168,18 @@ class ObjectToFromController {
                         logger.debug("设备更新失败:${equip.toJson()}")
                     }
                 }
-                val toJsonObjArray =
-                    Configure.toJsonObjArray("MechInArch", "Eq2Bd", equip.id!!, equip.buildingId!!)
-                val toJsonObjArray2 =
-                    Configure.toJsonObjArray("MechInArch", "Eq2Fl", equip.id!!, equip.floorId!!)
-                toJsonObjArray.plus(toJsonObjArray2[0])
-                val createRel = EquipApi.createRel(dictProject.groupCode!!, projectId, toJsonObjArray)
-                if (!createRel){
-                    logger.debug("设备和楼层的关系失败:${equip.toJson()}")
+                if (!equip.buildingId.isNullOrEmpty()) {
+                    val toJsonObjArray =
+                        Configure.toJsonObjArray("MechInArch", "Eq2Bd", equip.id!!, equip.buildingId!!)
+                    val toJsonObjArray2 =
+                        Configure.toJsonObjArray("MechInArch", "Eq2Fl", equip.id!!, equip.floorId!!)
+                    toJsonObjArray.plus(toJsonObjArray2[0])
+                    val createRel = EquipApi.createRel(dictProject.groupCode!!, projectId, toJsonObjArray)
+                    if (!createRel){
+                        logger.debug("设备和楼层的关系失败:${equip.toJson()}")
+                    }
                 }
+
             }
             return SBaseResponse(SResponseType.success)
         } catch (e: Exception) {

+ 5 - 0
datasyn/src/main/kotlin/com/persagy/server/syn/jms/DataCenterSync.kt

@@ -75,9 +75,11 @@ class DataCenterSync {
                     dataCenterFloor.floorType(message)
                 }
                 Configure.EQUIPMENT -> {
+
                     /** 设备 */
                     dataCenterEquip.equipType(message)
                 }
+
                 Configure.COMPONENT -> {
                     /** 部件 */
                     dataCenterComponent.equipType(message)
@@ -98,6 +100,9 @@ class DataCenterSync {
                     /** 租户 */
 //                    dataCenterVOTn.tenantType(message)
                 }
+                "equip" -> {
+                    dataCenterEquip.equipAllUpDate(message)
+                }
             }
         }
         return true

+ 18 - 13
datasyn/src/main/kotlin/com/persagy/server/syn/jms/MessageProcessing.kt

@@ -110,25 +110,30 @@ class MessageProcessing {
 //            }
 //        }
         try {
-            logger.debug("标记状态= ${messageTypeDataCerten}              *********************************************************")
+            logger.debug("标记状态= ${messageTypeDataCerten}  *********************************************************")
             /** 不等于 0 时候执行同步 */
             if (messageTypeDataCerten!=0){
                 logger.debug("执行任务*********************************************************")
                 /** 设置为 0  防止重复执行 */
                 messageTypeDataCerten =0
                 /** 查询待处理的消息 */
-                val messageList =
-                    synchronousMessageObjService.select(SFilter.not(SFilter.eq("sign", 0)),SFilter.lte("count",20)).order("createTime").exec()
-                if (messageList.size>0) {
-                    /** 处理消息 */
-                    dataCenterSync.dataSync(messageList)
-                    /** 开启执行 */
-                    messageTypeDataCerten = 1
-                    /** 查询是否有待处理的消息 */
-                    syncDataCenter()
-                } else {
-                    logger.debug("释放状态*********************************************************")
-                    /** 开启下次执行 */
+                try {
+                    val messageList =
+                        synchronousMessageObjService.select(SFilter.not(SFilter.eq("sign", 0)),SFilter.lte("count",20)).order("createTime").exec()
+                    if (messageList.size>0) {
+                        /** 处理消息 */
+                        dataCenterSync.dataSync(messageList)
+                        /** 开启执行 */
+                        messageTypeDataCerten = 1
+                        /** 查询是否有待处理的消息 */
+                        syncDataCenter()
+                    } else {
+                        logger.debug("释放状态*********************************************************")
+                        /** 开启下次执行 */
+                        messageTypeDataCerten = 1
+                    }
+                }catch (e:Exception){
+                    e.printStackTrace()
                     messageTypeDataCerten = 1
                 }
             }

+ 11 - 2
datasyn/src/main/kotlin/com/persagy/server/syn/jms/MessageReceiver.kt

@@ -44,7 +44,8 @@ import java.util.*
 
 
 /**
- * 消息的接收者
+ *   消息的接收者- 接收消息服务
+ *
  * @author wx  <zhangweixin@sagacloud.com>
  * @date  2020/10/27 17:25
  */
@@ -128,7 +129,11 @@ class MessageReceiver {
                                     messageObj.objId = id
                                     messageObj.id =  UUID.randomUUID().toString().replace("-", "")
                                     messageObj.sign = 1
-                                    messageObj.objectType = objType(id)
+                                    if (messageNotice.type != "equip") {
+                                        messageObj.objectType = objType(id)
+                                    }else{
+                                        messageObj.objectType = "equip"
+                                    }
                                     messageObj.type = messageNotice.type
                                     /** 插入数据 */
                                     synchronousMessageObjService.insert(messageObj)
@@ -188,6 +193,10 @@ class MessageReceiver {
             id.startsWith("Ec") -> {
                 return "component"
             }
+            id.startsWith("20") -> {
+                return "equip"
+            }
+
             else -> return "object"
         }
     }

+ 67 - 2
datasyn/src/main/kotlin/com/persagy/server/syn/services/jms/DataCenterEquipment.kt

@@ -53,7 +53,8 @@ class DataCenterEquipment {
     var synchronousMessageObjService = SObjectService(SMybatisDao(SynchronousMessage::class.java))
     /** 项目所属的集团 */
     private val dictProjectService = SObjectService(SMybatisDao(DictProject::class.java))
-
+    /** 设备服务*/
+    private val equipmentService = SObjectService(SMybatisDao(Equipment::class.java))
     /**
      * 处理 数据中心到 - 数据中台的floor
      */
@@ -83,7 +84,7 @@ class DataCenterEquipment {
                                     val toJsonObjArray2 =
                                             Configure.toJsonObjArray("MechInArch", "Eq2Fl", equip.id!!, equip.floorId!!)
                                     if (!toJsonObjArray2.isNullOrEmpty()) {
-                                        toJsonObjArray.plus(toJsonObjArray2[0])
+                                        toJsonObjArray.add(toJsonObjArray2[0])
                                     }
                                     val createRel = EquipApi.createRel(dictProject.groupCode!!, message.projectId!!, toJsonObjArray)
                                     if (!createRel){
@@ -167,4 +168,68 @@ class DataCenterEquipment {
         }
     }
 
+    /**
+     * 所有的设备修改
+     *
+     * @param message   消息实体类
+     */
+    fun equipAllUpDate(message: SynchronousMessage){
+        val dictProject = dictProjectService.select(SFilter.eq("id", message.projectId!!)).entity()
+        message.sign = 0
+        if (dictProject!=null){
+            val  equipmentList = equipmentService.select(
+                SFilter.eq("projectId", message.projectId!!),
+                SFilter.eq("floorId", message.objId!!)
+            ).exec()
+            if (!equipmentList.isNullOrEmpty()){
+                for (equipment in equipmentList) {
+                    try {
+                        val equipList = EquipUtil.equipTools(message.projectId!!, equipment)
+                        val sign = EquipApi.updateObj(dictProject!!.groupCode!!,message.projectId!!, equipList)
+                        if (!equipment.buildingId.isNullOrEmpty()&&!equipment.floorId.isNullOrEmpty()){
+                            try {
+                                val toJsonObjArray =
+                                    Configure.toJsonObjArray("MechInArch", "Eq2Bd", equipment.id!!, equipment.buildingId!!)
+                                val toJsonObjArray2 =
+                                    Configure.toJsonObjArray("MechInArch", "Eq2Fl", equipment.id!!, equipment.floorId!!)
+                                if (!toJsonObjArray2.isNullOrEmpty()) {
+                                    toJsonObjArray.add(toJsonObjArray2[0])
+                                }
+                                val createRel = EquipApi.createRel(dictProject.groupCode!!, message.projectId!!, toJsonObjArray)
+                                if (!createRel){
+                                    message.sign = 2
+                                    message.count = message.count+1
+                                }
+                            } catch (e: Exception) {
+                                e.printStackTrace()
+                                message.sign = 2
+                                message.count = message.count+1
+                            }
+                        }else if (!equipment.buildingId.isNullOrEmpty()) {
+                            val toJsonObjArray =
+                                Configure.toJsonObjArray("MechInArch", "Eq2Bd", equipment.id!!, equipment.buildingId!!)
+                            val createRel = EquipApi.createRel(dictProject.groupCode!!, message.projectId!!, toJsonObjArray)
+                            if (!createRel){
+                                message.sign = 2
+                                message.count = message.count+1
+                            }
+                        }
+                    } catch (e: Exception) {
+                        e.printStackTrace()
+                    }
+                }
+            }
+        } else {
+            /** 失败 */
+            message.sign = 2
+            message.count = message.count+1
+        }
+
+        /** 更改标记 */
+        synchronousMessageObjService.update(message, arrayListOf("sign","count"))
+
+    }
+
+
+
 }

+ 27 - 25
datasyn/src/main/kotlin/com/persagy/server/syn/services/jms/DataCenterFloor.kt

@@ -67,38 +67,40 @@ class DataCenterFloor {
                     SFilter.eq("projectId", message.projectId!!),
                     SFilter.eq("id", message.objId!!)
                 ).entity()
-                /** floor不为空 */
-                if (floor!=null) {
-                    val sign = FloorApi.createObj(dictProject!!.groupCode!!,message.projectId!!, floor)
-                    if (sign){
-                        /** 成功 */
-                        message.sign = 0
+                if (dictProject!=null) {
+                    /** floor不为空 */
+                    if (floor!=null) {
+                        val sign = FloorApi.createObj(dictProject!!.groupCode!!,message.projectId!!, floor)
+                        if (sign){
+                            /** 成功 */
+                            message.sign = 0
 
-                        if (dictProject!=null) {
-                            try {
-                                /** 关系列表 */
-                                val ObjArray = toJsonObjArray("ArchSubset", "Bd2Fl", floor.buildingId!!, floor.id!!)
-                                val createRel = EquipApi.createRel(dictProject.groupCode!!, message.projectId!!, ObjArray)
-                                if (!createRel){
-                                    message.sign = 2
-                                    message.count +1
+                                try {
+                                    /** 关系列表 */
+                                    val ObjArray = toJsonObjArray("ArchSubset", "Bd2Fl", floor.buildingId!!, floor.id!!)
+                                    val createRel = EquipApi.createRel(dictProject.groupCode!!, message.projectId!!, ObjArray)
+                                    if (!createRel){
+                                        message.sign = 2
+                                        message.count +1
+                                    }
+                                } catch (e: Exception) {
+                                    e.printStackTrace()
                                 }
-                            } catch (e: Exception) {
-                                e.printStackTrace()
-                            }
-                        } else {
+                        }else {
+                            /** 失败 */
                             message.sign = 2
                             message.count +1
                         }
+
                     }else {
-                        /** 失败 */
-                        message.sign = 2
-                        message.count +1
+                        message.sign = 0
                     }
-
-                }else {
-                    message.sign = 0
+                } else {
+                    /** 失败 */
+                    message.sign = 2
+                    message.count +1
                 }
+
                 /** 更改标记 */
                 synchronousMessageObjService.update(message, arrayListOf("sign","count"))
             }
@@ -166,7 +168,7 @@ class DataCenterFloor {
         /** 从对象 id */
         jsonObject["objTo"] = objTo
         /** 添加到列表 */
-        jsonArray.plus(jsonObject)
+        jsonArray.add(jsonObject)
         return jsonArray
     }