Browse Source

********************WX***********************
添加微服务和数据中台通讯方式

zhangweixin 4 years ago
parent
commit
6568b72f19
28 changed files with 811 additions and 171 deletions
  1. 7 0
      data-core/src/main/kotlin/com/persagy/server/datacenter/models/entities/objects/Project.kt
  2. 27 2
      data-core/src/main/kotlin/com/persagy/server/datacenter/models/jms/SynchronousMessage.kt
  3. 6 0
      datacenter/src/main/kotlin/com/persagy/server/services/objects/EquipmentService.kt
  4. 1 5
      datacenter/src/main/kotlin/com/persagy/server/services/relation_calc/CalcSpaceService.kt
  5. 2 1
      datacenter/src/main/resources/application-dev.yml
  6. 12 0
      datasyn/src/main/kotlin/com/persagy/server/syn/Swagger3Config.kt
  7. 97 0
      datasyn/src/main/kotlin/com/persagy/server/syn/controllers/journal/JournalController.kt
  8. 10 10
      datasyn/src/main/kotlin/com/persagy/server/syn/controllers/obj/ObjectToFromController.kt
  9. 2 4
      datasyn/src/main/kotlin/com/persagy/server/syn/jms/MessageReceiver.kt
  10. 48 24
      datasyn/src/main/kotlin/com/persagy/server/syn/models/api/obj/BuildingApi.kt
  11. 26 31
      datasyn/src/main/kotlin/com/persagy/server/syn/models/api/obj/EquipApi.kt
  12. 34 0
      datasyn/src/main/kotlin/com/persagy/server/syn/models/api/obj/ProjectApi.kt
  13. 8 11
      datacenter/src/main/kotlin/com/persagy/server/mappers/ICalcSpaceMapper.kt
  14. 1 0
      datasyn/src/main/kotlin/com/persagy/server/syn/models/tools/ProjectUtil.kt
  15. 68 21
      datasyn/src/main/kotlin/com/persagy/server/syn/services/jms/DataCenterBuilding.kt
  16. 79 13
      datasyn/src/main/kotlin/com/persagy/server/syn/services/jms/DataCenterComponent.kt
  17. 88 16
      datasyn/src/main/kotlin/com/persagy/server/syn/services/jms/DataCenterEquipment.kt
  18. 3 3
      datasyn/src/main/kotlin/com/persagy/server/syn/services/jms/DataCenterShaft.kt
  19. 75 17
      datasyn/src/main/kotlin/com/persagy/server/syn/services/jms/DataCenterSpace.kt
  20. 3 3
      datasyn/src/main/kotlin/com/persagy/server/syn/services/jms/DataCenterSystem.kt
  21. 3 3
      datasyn/src/main/kotlin/com/persagy/server/syn/services/jms/DataCenterVOTn.kt
  22. 138 0
      datasyn/src/main/kotlin/com/persagy/server/syn/services/journal/SynchronousMessageService.kt
  23. 49 0
      datasyn/src/main/kotlin/com/persagy/server/syn/services/mappers/TypeMapper.kt
  24. 2 2
      datasyn/src/main/kotlin/com/persagy/server/syn/task/SchedulerTask.kt
  25. 2 2
      datasyn/src/main/kotlin/com/persagy/server/syn/task/SchedulerTaskRel.kt
  26. 1 2
      datasyn/src/main/kotlin/com/persagy/server/syn/task/SchedulerTaskTwo.kt
  27. 18 0
      datasyn/src/main/kotlin/com/persagy/server/syn/utils/ParamTools.kt
  28. 1 1
      gradle.properties

+ 7 - 0
data-core/src/main/kotlin/com/persagy/server/datacenter/models/entities/objects/Project.kt

@@ -66,6 +66,11 @@ open class Project : BaseInfo() {
     @Column(name = "introduction")
     var introduction: String? = null
 
+    /** 集团编码 */
+    @Schema(description = "集团编码")
+    @Column(name = "group_code")
+    var groupCode: String? = null
+
     /** 商业层数 */
     @Schema(description = "商业层数")
     @Column(name = "business_floor_num")
@@ -85,4 +90,6 @@ open class Project : BaseInfo() {
     @Column(name = "infos")
     var infos: HashMap<String,Any?>? = null
 
+
+
 }

+ 27 - 2
data-core/src/main/kotlin/com/persagy/server/datacenter/models/jms/SynchronousMessage.kt

@@ -61,13 +61,17 @@ class SynchronousMessage : Serializable {
     @Column(name = "object_type")
     var objectType: String? = null
 
-    /** 标记 0已处理,1待处理,2处理失败 */
+    /** 标记 0已处理,1待处理,2处理失败,3忽略操作 */
     @Column(name = "sign")
     var sign: Int? = null
 
     /** 操作符 */
     @Column(name = "ops")
     var ops: String? = null
+
+    /** 操作符名称 */
+    var opsName: String? = null
+
     /** 主 id */
     @Column(name = "from_id")
     var fromId: String? = null
@@ -78,6 +82,27 @@ class SynchronousMessage : Serializable {
     @Column(name = "count")
     var count: Int = 0
 
+    @Column(name = "error")
+    var error: String? = null
+
+    @Column(name = "class_code")
+    var classCode: String? = null
+
+    @Column(name = "local_name")
+    var localName: String? = null
+
+    @Column(name = "local_id")
+    var localId: String? = null
+
+    @Column(name = "name")
+    var name: String? = null
+
+    /** 对象类型名称 */
+    var objName: String? = null
+
+    /** 对象类型名称 */
+    var classCodeName: String? = null
+
     /** 最后更新日期 */
     @Column(name = "last_update", updatable = false, insertable = false)
     var lastUpdate: Date? = null
@@ -86,4 +111,4 @@ class SynchronousMessage : Serializable {
     @Column(name = "create_time", updatable = false, insertable = false)
     var createTime: Date? = null
 
-} // Class SynchronousMessageObj
+}

+ 6 - 0
datacenter/src/main/kotlin/com/persagy/server/services/objects/EquipmentService.kt

@@ -95,6 +95,12 @@ object EquipmentService : Service<Equipment>(SMybatisDao(Equipment::class.java))
             } else {
                 return false
             }
+        } else {
+            val entity = defClassService.select(
+                SFilter.eq("projectId", equip.projectId!!),
+                SFilter.endWith("code", equip.classCode!!)
+            ).entity()
+                ?: return false
         }
 
         /** 设备名字 */

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

@@ -26,8 +26,6 @@
 
 package com.persagy.server.services.relation_calc
 
-import com.persagy.server.mappers.ICalcSpaceMapper
-import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.stereotype.Service
 
 /**
@@ -37,9 +35,7 @@ import org.springframework.stereotype.Service
  */
 @Service
 open class CalcSpaceService {
-    /** 实例化 mapper 对象 */
-    @Autowired
-    lateinit var mapper: ICalcSpaceMapper
+
 
 
 } // Class CalcSpaceService

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

@@ -34,7 +34,8 @@ 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://192.168.64.15:5432/datacenterwanda
+#    url:                                jdbc:postgresql://192.168.64.15:5432/datacenterwanda
+    url:                                jdbc:postgresql://39.102.40.239:5432/datacenter
     username:                           postgres
 #    password:                           persagy_2020qwe!@#
     password:                           cGVyc2FneV8yMDIwcXdlIUAj

+ 12 - 0
datasyn/src/main/kotlin/com/persagy/server/syn/Swagger3Config.kt

@@ -96,6 +96,18 @@ open class Swagger3Config {
      * 默认分组
      */
     @Bean
+    open fun recordApiGroup(): GroupedOpenApi {
+        return GroupedOpenApi.builder()
+            .group("日志记录")
+            .pathsToMatch("/record/**")
+            .build()
+    }
+
+
+    /**
+     * 默认分组
+     */
+    @Bean
     open fun dictApiGroup(): GroupedOpenApi {
         return GroupedOpenApi.builder()
             .group("字典")

+ 97 - 0
datasyn/src/main/kotlin/com/persagy/server/syn/controllers/journal/JournalController.kt

@@ -0,0 +1,97 @@
+/*
+ * *********************************************************************************************************************
+ *
+ *          !!
+ *        .F88X
+ *        X8888Y
+ *      .}888888N;
+ *        i888888N;        .:!              .I$WI:
+ *          R888888I      .'N88~            i8}+8Y&8"l8i$8>8W~'>W8}8]KW+8IIN"8&
+ *          .R888888I    .;N8888~          .X8'  "8I.!,/8"  !%NY8`"8I8~~8>,88I
+ *            +888888N;  .8888888Y                                  "&&8Y.}8,
+ *            ./888888N;  .R888888Y        .'}~    .>}'.`+>  i}!    "i'  +/'  .'i~  !11,.:">,  .~]!  .i}i
+ *              ~888888%:  .I888888l      .]88~`1/iY88Ii+1'.R$8$8]"888888888>  Y8$  W8E  X8E  W8888'188Il}Y88$*
+ *              18888888    E8888881    .]W%8$`R8X'&8%++N8i,8N%N8+l8%`  .}8N:.R$RE%N88N%N$K$R  188,FE$8%~Y88I
+ *            .E888888I  .i8888888'      .:$8I;88+`E8R:/8N,.>881.`$8E/1/]N8X.Y8N`"KF&&FK!'88*."88K./$88%RN888+~
+ *            8888888I  .,N888888~        ~88i"8W,!N8*.I88.}888%F,i$88"F88"  888:E8X.>88!i88>`888*.}Fl1]*}1YKi'
+ *          i888888N'      I888Y          ]88;/EX*IFKFK88X  K8R  .l8W  88Y  ~88}'88E&%8W.X8N``]88!.$8K  .:W8I
+ *        .i888888N;        I8Y          .&8$  .X88!  i881.:%888>I88  ;88]  +88+.';;;;:.Y88X  18N.,88l  .+88/
+ *      .:R888888I
+ *      .&888888I                                          Copyright (c) 2009-2021.  博锐尚格科技股份有限公司
+ *        ~8888'
+ *        .!88~                                                                     All rights reserved.
+ *
+ * *********************************************************************************************************************
+ */
+
+package com.persagy.server.syn.controllers.journal
+
+import com.persagy.server.datacenter.models.entities.dictnew.DefClass
+import com.persagy.server.datacenter.models.jms.SynchronousMessage
+import com.persagy.server.syn.services.journal.SynchronousMessageService
+import com.persagy.service.models.requests.SQueryRequest
+import com.persagy.service.models.requests.SUpdateRequest
+import com.persagy.service.models.responses.SBaseResponse
+import com.persagy.service.models.responses.SQueryResponse
+import io.swagger.v3.oas.annotations.Operation
+import io.swagger.v3.oas.annotations.tags.Tag
+import org.springframework.web.bind.annotation.*
+
+/**
+ * 同步日志
+ *
+ * @author wx  <zhangweixin@sagacloud.com>
+ * @date  2021/2/25 10:32
+ */
+@Tag(name = "日志-同步日志")
+@RestController
+@RequestMapping("/record")
+class JournalController {
+
+
+    /**
+     * 查询同步日志
+     */
+    @Operation(summary = "日志查询", description = "")
+    @PostMapping(value = ["/query"])
+    fun query(@RequestBody request: SQueryRequest): SQueryResponse<SynchronousMessage> {
+        return SynchronousMessageService.pageQuery(request)
+    }
+
+    /**
+     * 查询项目下对应的对象类型(设备、系统、空间)
+     */
+    @Operation(summary = "查询项目下对应的对象类型(设备、系统、空间)", description = "")
+    @GetMapping(value = ["/query/type"])
+    fun queryClassCode(@RequestParam objType: String,@RequestParam projectId: String): SQueryResponse<DefClass>{
+        return SynchronousMessageService.typeQuery(objType,projectId)
+    }
+
+    /**
+     * 更新日志信息
+     *
+     * @param   request        更新的内容对象
+     * @return                  更新的结果
+     */
+    @Operation(summary = "更新日志信息", description = "忽略(sign = 3)")
+    @PostMapping(value = ["/update"])
+    fun update(@RequestBody request: SUpdateRequest<SynchronousMessage>): SBaseResponse {
+        return SynchronousMessageService.updateList(request)
+    }
+
+    /**
+     * 重新同步消息
+     */
+    @Operation(summary = "重新同步消息", description = "")
+    @PostMapping(value = ["/syn/data"])
+    fun synData(@RequestBody request: SUpdateRequest<SynchronousMessage>): SBaseResponse {
+        return SynchronousMessageService.synData(request)
+    }
+
+    @Operation(summary = "中台是否在线", description = "groupCode 集团编码 ")
+    @GetMapping(value = ["/query/online"])
+    fun isOnline(@RequestParam groupCode: String,@RequestParam projectId: String): SBaseResponse{
+        return SynchronousMessageService.isOnline(groupCode,projectId)
+    }
+
+}

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

@@ -101,10 +101,10 @@ class ObjectToFromController {
             if (buildingList.size>0){
                 for (building in buildingList){
                     val createBuilding = BuildingApi.createObj(dictProject!!.groupCode!!,projectId, building)
-                    if (!createBuilding){
+                    if (createBuilding!=null&&createBuilding.result == "success") {
                         logger.debug("建筑创建失败:${building}")
                         val updateBuilding = BuildingApi.updateObj(dictProject!!.groupCode!!,projectId, building)
-                        if (!updateBuilding){
+                        if (updateBuilding!=null&&updateBuilding.result == "success") {
                             logger.debug("建筑更新失败:${building.toJson()}")
                         }
                     }
@@ -161,10 +161,10 @@ class ObjectToFromController {
             for (equip in equipList) {
                 val createObj =
                     EquipApi.createObj(dictProject!!.groupCode!!, projectId, EquipUtil.equipTools(projectId, equip))
-                if (!createObj) {
+                if (createObj!!.result == "success") {
                     val updateObj =
                         EquipApi.updateObj(dictProject!!.groupCode!!, projectId, EquipUtil.equipTools(projectId, equip))
-                    if (!updateObj) {
+                    if (updateObj!=null&&updateObj.result == "success") {
                         logger.debug("设备更新失败:${equip.toJson()}")
                     }
                 }
@@ -202,10 +202,10 @@ class ObjectToFromController {
                 for (system in systemList) {
                     val createObj =
                         EquipApi.createObj(dictProject!!.groupCode!!, projectId, SystemUtil.systemTools(projectId, system))
-                    if (!createObj) {
+                    if (createObj!!.result == "success") {
                         val updateObj =
                             EquipApi.updateObj(dictProject!!.groupCode!!, projectId, SystemUtil.systemTools(projectId, system))
-                        if (!updateObj) {
+                        if (updateObj!=null&&updateObj.result == "success") {
                             logger.debug("系统更新失败:${system.toJson()}")
                         }
                     }
@@ -231,10 +231,10 @@ class ObjectToFromController {
                 for (shaft in shaftList){
                     val createObj =
                         EquipApi.createObj(dictProject!!.groupCode!!, projectId,ShaftUtil.shaftTools(projectId, shaft))
-                    if (!createObj) {
+                    if (createObj!!.result == "success") {
                         val updateObj =
                             EquipApi.updateObj(dictProject!!.groupCode!!, projectId, ShaftUtil.shaftTools(projectId, shaft))
-                        if (!updateObj) {
+                        if (updateObj!=null&&updateObj.result == "success") {
                             logger.debug("竖井更新失败:${shaft.toJson()}")
                         }
                     }
@@ -265,10 +265,10 @@ class ObjectToFromController {
 //                    }
                     val createObj =
                         EquipApi.createObj(dictProject!!.groupCode!!, projectId,SpaceUtil.spaceTools(projectId, space))
-                    if (!createObj) {
+                    if (createObj!!.result == "success") {
                         val updateObj =
                             EquipApi.updateObj(dictProject!!.groupCode!!, projectId,SpaceUtil.spaceTools(projectId, space))
-                        if (!updateObj) {
+                        if (updateObj!=null&&updateObj.result == "success") {
                             logger.debug("空间更新失败:${space.toJson()}")
                         }
                     }

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

@@ -35,8 +35,6 @@ import com.persagy.server.syn.jms.bean.SyncRwdDatacenterMessage
 import com.persagy.service.SObjectService
 import com.persagy.service.utils.SJsonUtil
 import org.slf4j.LoggerFactory
-import org.springframework.amqp.rabbit.annotation.RabbitHandler
-import org.springframework.amqp.rabbit.annotation.RabbitListener
 import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.stereotype.Component
 import org.springframework.stereotype.Service
@@ -72,8 +70,8 @@ class MessageReceiver {
     /**
      * 接收中台消息
      */
-    @RabbitListener(queues = ["queue-center-syn"])
-    @RabbitHandler
+//    @RabbitListener(queues = ["queue-center-syn"])
+//    @RabbitHandler
     fun process(mess: String) {
         logger.debug("接收中台消息:${mess}")
         /** 解析消息 */

+ 48 - 24
datasyn/src/main/kotlin/com/persagy/server/syn/models/api/obj/BuildingApi.kt

@@ -86,27 +86,23 @@ object BuildingApi {
      * @param building      建筑对象
      * @return 是否成功
      */
-    fun  createObj(groupCode: String,projectId: String, building:Building): Boolean {
+    fun  createObj(groupCode: String,projectId: String, building:Building): MiddleGroundDataRespose? {
         try {
             val buildingTools = BuildingUtil.buildingTools(projectId, building)
             /** 直接 http 请求还是通过注册中心 */
             if (!Configure.customProperties.eurekaorhttp) {
                 val url = "${Configure.opts.dataPlatform}/rwd/instance/object/create?groupCode=$groupCode&projectId=${projectId}&appId=datacenter"
                 val postObject = SHttpUtil.postObject<MiddleGroundDataRespose>(url, buildingTools)
-                if (postObject.result == "success") {
-                    return true
-                }
+                    return postObject
             } else {
                 val url = "http://${Configure.serviceNameConfig.DMPRWD}/rwd/instance/object/create?groupCode=$groupCode&projectId=${projectId}&appId=datacenter"
                 val postObject = Configure.restTemplate.postForObject(url, buildingTools, MiddleGroundDataRespose::class.java)
-                if (postObject.result == "success") {
-                    return true
-                }
+                    return postObject
             }
         } catch (e: Exception) {
             e.printStackTrace()
         }
-        return false
+        return null
     }
 
     /**
@@ -116,27 +112,24 @@ object BuildingApi {
      * @param building      建筑对象
      * @return 是否成功
      */
-    fun  updateObj(groupCode: String,projectId: String, building:Building): Boolean {
+    fun  updateObj(groupCode: String,projectId: String, building:Building): MiddleGroundDataRespose? {
         try {
             val buildingTools = BuildingUtil.buildingTools(projectId, building)
             /** 直接 http 请求还是通过注册中心 */
             if (!Configure.customProperties.eurekaorhttp) {
                 val url = "${Configure.opts.dataPlatform}/rwd/instance/object/update?groupCode=$groupCode&projectId=${projectId}&appId=datacenter"
                 val postObject = SHttpUtil.postObject<MiddleGroundDataRespose>(url, buildingTools)
-                if (postObject.result == "success") {
-                    return true
-                }
+                return postObject
+
             } else {
                 val url = "http://${Configure.serviceNameConfig.DMPRWD}/rwd/instance/object/update?groupCode=$groupCode&projectId=${projectId}&appId=datacenter"
                 val postObject = Configure.restTemplate.postForObject(url, buildingTools, MiddleGroundDataRespose::class.java)
-                if (postObject.result == "success") {
-                    return true
-                }
+                return postObject
             }
         } catch (e: Exception) {
             e.printStackTrace()
         }
-        return false
+        return null
     }
 
     /**
@@ -146,7 +139,7 @@ object BuildingApi {
      * @param building      建筑对象
      * @return 是否成功
      */
-    fun  deleteObj(groupCode: String,projectId: String, buildingId: String): Boolean {
+    fun  deleteObj(groupCode: String,projectId: String, buildingId: String): MiddleGroundDataRespose? {
         try {
             val listId = ArrayList<String>()
             listId.add(buildingId)
@@ -154,20 +147,17 @@ object BuildingApi {
             if (!Configure.customProperties.eurekaorhttp) {
                 val url = "${Configure.opts.dataPlatform}/rwd/instance/object/delete?groupCode=$groupCode&projectId=${projectId}&appId=datacenter"
                 val postObject = SHttpUtil.postObject<MiddleGroundDataRespose>(url, listId)
-                if (postObject.result == "success") {
-                    return true
-                }
+                return postObject
+
             } else {
                 val url = "http://${Configure.serviceNameConfig.DMPRWD}/rwd/instance/object/delete?groupCode=$groupCode&projectId=${projectId}&appId=datacenter"
                 val postObject = Configure.restTemplate.postForObject(url, listId, MiddleGroundDataRespose::class.java)
-                if (postObject.result == "success") {
-                    return true
-                }
+                return postObject
             }
         } catch (e: Exception) {
             e.printStackTrace()
+            return null
         }
-        return false
     }
 
     /**
@@ -205,4 +195,38 @@ object BuildingApi {
         return ArrayList<HashMap<String, Any?>>()
     }
 
+
+    /**
+     * 根据 id 查询对象
+     *
+     * @param projectId     项目 id
+     * @param id             对象 id
+     * @return 返回结果
+     */
+    fun queryIdTwo(groupCode: String, projectId: String,id: String): MiddleGroundDataRespose? {
+        try {
+            val jsonObject = JSONObject()
+            val jsonObject2 = JSONObject()
+            jsonObject2["id"] = id
+            jsonObject2["valid"] = 1
+            jsonObject["criteria"] = jsonObject2
+            /** 直接 http 请求还是通过注册中心 */
+            if (!Configure.customProperties.eurekaorhttp) {
+                val url = "${Configure.opts.dataPlatform}/rwd/instance/object/query?groupCode=$groupCode&projectId=${projectId}"
+                val postObject = SHttpUtil.postObject<MiddleGroundDataRespose>(url, jsonObject)
+
+                return postObject
+
+            } else {
+                val url = "http://${Configure.serviceNameConfig.DMPRWD}/rwd/instance/object/query?groupCode=$groupCode&projectId=${projectId}"
+                val postObject = Configure.restTemplate.postForObject(url, jsonObject, MiddleGroundDataRespose::class.java)
+                return postObject
+
+            }
+        } catch (e: Exception) {
+            e.printStackTrace()
+        }
+        return null
+    }
+
 }

+ 26 - 31
datasyn/src/main/kotlin/com/persagy/server/syn/models/api/obj/EquipApi.kt

@@ -218,23 +218,25 @@ object EquipApi {
      * @param floor        对象
      * @return 是否成功
      */
-    fun  createObj(groupCode: String,projectId: String, listObj: ArrayList<HashMap<String,Any?>>): Boolean {
+    fun  createObj(groupCode: String,projectId: String, listObj: ArrayList<HashMap<String,Any?>>): MiddleGroundDataRespose? {
         /** 直接 http 请求还是通过注册中心 */
-        if (!Configure.customProperties.eurekaorhttp) {
-            val url = "${opts.dataPlatform}/rwd/instance/object/create?groupCode=$groupCode&projectId=${projectId}&appId=datacenter"
-            val postObject = SHttpUtil.postObject<MiddleGroundDataRespose>(url, listObj)
-            if (postObject.result == "success") {
-                return true
-            }
-        } else {
-            val url = "http://${Configure.serviceNameConfig.DMPRWD}/rwd/instance/object/create?groupCode=$groupCode&projectId=${projectId}&appId=datacenter"
-            val postObject = Configure.restTemplate.postForObject(url, listObj, MiddleGroundDataRespose::class.java)
-            if (postObject.result == "success") {
-                return true
+        try {
+            if (!Configure.customProperties.eurekaorhttp) {
+                val url = "${opts.dataPlatform}/rwd/instance/object/create?groupCode=$groupCode&projectId=${projectId}&appId=datacenter"
+                val postObject = SHttpUtil.postObject<MiddleGroundDataRespose>(url, listObj)
+                return postObject
+            } else {
+                val url = "http://${Configure.serviceNameConfig.DMPRWD}/rwd/instance/object/create?groupCode=$groupCode&projectId=${projectId}&appId=datacenter"
+                val postObject = Configure.restTemplate.postForObject(url, listObj, MiddleGroundDataRespose::class.java)
+                if (postObject.result == "success") {
+                    return postObject
+                }
             }
+            return null
+        } catch (e: Exception) {
+            e.printStackTrace()
+            return null
         }
-
-        return false
     }
 
     /**
@@ -244,7 +246,7 @@ object EquipApi {
      * @param listObj       对象列表
      * @return 是否成功
      */
-    fun  updateObj(groupCode: String,projectId: String, listObj: ArrayList<HashMap<String,Any?>>): Boolean {
+    fun  updateObj(groupCode: String,projectId: String, listObj: ArrayList<HashMap<String,Any?>>): MiddleGroundDataRespose? {
         /** 直接 http 请求还是通过注册中心 */
         try {
             if (!Configure.customProperties.eurekaorhttp) {
@@ -253,20 +255,18 @@ object EquipApi {
                 logger.debug("boby= ${listObj.toJson()}")
                 val postObject = SHttpUtil.postObject<MiddleGroundDataRespose>(url, listObj)
                 logger.debug("结果= ${postObject.toJson()}")
-                if (postObject.result == "success") {
-                    return true
-                }
+                    return postObject
             }else {
                 val url = "http://${Configure.serviceNameConfig.DMPRWD}/rwd/instance/object/update?groupCode=$groupCode&projectId=${projectId}&appId=datacenter"
                 val postObject = Configure.restTemplate.postForObject(url, listObj, MiddleGroundDataRespose::class.java)
-                if (postObject.result == "success") {
-                    return true
-                }
+
+                return postObject
+
             }
         } catch (e: Exception) {
             e.printStackTrace()
         }
-        return false
+        return null
     }
 
     /**
@@ -276,25 +276,20 @@ object EquipApi {
      * @param id            对象 id
      * @return 是否成功
      */
-    fun  deleteObj(groupCode: String,projectId: String, id: String): Boolean {
+    fun  deleteObj(groupCode: String,projectId: String, id: String): MiddleGroundDataRespose? {
         val listId = ArrayList<String>()
         listId.add(id)
         /** 直接 http 请求还是通过注册中心 */
         if (!Configure.customProperties.eurekaorhttp) {
             val url = "${opts.dataPlatform}/rwd/instance/object/delete?groupCode=$groupCode&projectId=${projectId}&appId=datacenter"
             val postObject = SHttpUtil.postObject<MiddleGroundDataRespose>(url, listId)
-            if (postObject.result == "success") {
-                return true
-            }
+                return postObject
         } else {
             val url = "http://${Configure.serviceNameConfig.DMPRWD}/rwd/instance/object/delete?groupCode=$groupCode&projectId=${projectId}&appId=datacenter"
             val postObject = Configure.restTemplate.postForObject(url, listId, MiddleGroundDataRespose::class.java)
-            if (postObject.result == "success") {
-                return true
-            }
+                return postObject
         }
-
-        return false
+        return null
     }
 
 

+ 34 - 0
datasyn/src/main/kotlin/com/persagy/server/syn/models/api/obj/ProjectApi.kt

@@ -106,5 +106,39 @@ object ProjectApi {
         return ArrayList<HashMap<String, Any?>>()
     }
 
+    /**
+     * 根据集团查询集团下所有的项目
+     *
+     * @param projectId     集团编码
+     * @return
+     */
+    fun projectQueryTwo(groupCode: String,projectId: String): MiddleGroundDataRespose? {
+        try {
+            val jsonObject = JSONObject()
+            val jsonObject2 = JSONObject()
+            jsonObject2["classCode"] = "project"
+            jsonObject2["valid"] = 1
+            jsonObject["criteria"] = jsonObject2
+            /** 判断是否使用注册中心 */
+            if (!Configure.customProperties.eurekaorhttp) {
+                val url = "${Configure.opts.dataPlatform}/rwd/instance/object/query?groupCode=$groupCode&projectId=${projectId}"
+                val postObject = SHttpUtil.postObject<MiddleGroundDataRespose>(url, jsonObject)
+                return postObject
+//                if (postObject.result == "success"&&!postObject.data.isNullOrEmpty()) {
+//                    return postObject.data!!
+//                }
+            } else {
+                val url = "http://${Configure.serviceNameConfig.DMPRWD}/rwd/instance/object/query?groupCode=$groupCode&projectId=${projectId}"
+                val postObject = Configure.restTemplate.postForObject(url, jsonObject, MiddleGroundDataRespose::class.java)
+                return postObject
+//                if (postObject.result == "success"&&!postObject.data.isNullOrEmpty()) {
+//                    return postObject.data!!
+//                }
+            }
+        } catch (e: Exception) {
+            e.printStackTrace()
+        }
+        return null
+    }
 
 }

+ 8 - 11
datacenter/src/main/kotlin/com/persagy/server/mappers/ICalcSpaceMapper.kt

@@ -17,26 +17,23 @@
  *          i888888N'      I888Y          ]88;/EX*IFKFK88X  K8R  .l8W  88Y  ~88}'88E&%8W.X8N``]88!.$8K  .:W8I
  *        .i888888N;        I8Y          .&8$  .X88!  i881.:%888>I88  ;88]  +88+.';;;;:.Y88X  18N.,88l  .+88/
  *      .:R888888I
- *      .&888888I                                          Copyright (c) 2009-2020.  博锐尚格科技股份有限公司
+ *      .&888888I                                          Copyright (c) 2009-2021.  博锐尚格科技股份有限公司
  *        ~8888'
  *        .!88~                                                                     All rights reserved.
  *
  * *********************************************************************************************************************
  */
 
-package com.persagy.server.mappers
+package com.persagy.server.syn.models.journal
 
-import org.apache.ibatis.annotations.Mapper
-import org.apache.ibatis.annotations.Select
-import org.springframework.stereotype.Repository
 /**
- * 关系计算-空间
  *
- * @author 邓婷婷
+ * @author wx  <zhangweixin@sagacloud.com>
+ * @date  2021/2/25 11:56
  */
-@Mapper
-@Repository
-interface ICalcSpaceMapper {
+class TypeCode {
 
 
-} // Interface ICalcSpaceMapper
+    var code: String? = null
+
+}

+ 1 - 0
datasyn/src/main/kotlin/com/persagy/server/syn/models/tools/ProjectUtil.kt

@@ -85,6 +85,7 @@ object ProjectUtil {
         }
 
         val project = Project()
+        project.groupCode = groupCode
         for (key in mapObj.keys) {
             val containsKey = mapEx.containsKey(key)
             if (containsKey){

+ 68 - 21
datasyn/src/main/kotlin/com/persagy/server/syn/services/jms/DataCenterBuilding.kt

@@ -34,6 +34,8 @@ import com.persagy.server.datacenter.models.entities.objects.Building
 import com.persagy.server.datacenter.models.jms.SynchronousMessage
 import com.persagy.server.syn.Configure
 import com.persagy.server.syn.models.api.obj.BuildingApi
+import com.persagy.server.syn.models.tools.BuildingUtil
+import com.persagy.server.syn.utils.ParamTools
 import com.persagy.service.SBaseService
 import com.persagy.service.SObjectService
 import org.slf4j.LoggerFactory
@@ -74,13 +76,22 @@ class DataCenterBuilding {
                 /** 建筑不为空 */
                 if (building!=null) {
                     val sign = BuildingApi.createObj(dictProject!!.groupCode!!,message.projectId!!, building)
-                    if (sign){
+                    upDateMessage(message,building)
+                    if (sign!=null && sign.result == "success"){
                         /** 成功 */
                         message.sign = 0
                     }else {
-                        /** 失败 */
-                        message.sign = 2
-                        message.count+1
+                        if (sign!=null){
+                            /** 失败 */
+                            message.sign = 2
+                            message.error = sign!!.toJson()
+                            message.count+1
+                        } else {
+                            /** 失败 */
+                            message.sign = 2
+                            message.error = "服务未连通"
+                            message.count+1
+                        }
                     }
                 }else {
                     message.sign = 0
@@ -98,21 +109,23 @@ class DataCenterBuilding {
                 /** 建筑不为空 */
                 if (building!=null) {
                     val sign = BuildingApi.updateObj(dictProject!!.groupCode!!,message.projectId!!, building)
-                    if (sign){
+                    upDateMessage(message,building)
+                    if (sign!=null && sign.result == "success"){
                         /** 成功 */
                         message.sign = 0
                     } else {
-                        val sign = BuildingApi.createObj(dictProject!!.groupCode!!,message.projectId!!, building)
-                        if (sign){
-                            /** 成功 */
-                            message.sign = 0
-                        }else {
+                        if (sign!=null){
                             /** 失败 */
                             message.sign = 2
-                            message.count +1
+                            message.error = sign!!.toJson()
+                            message.count+1
+                        } else {
+                            /** 失败 */
+                            message.sign = 2
+                            message.error = "服务未连通"
+                            message.count+1
                         }
                     }
-
                 } else {
                     /** 成功 */
                     message.sign = 0
@@ -121,15 +134,38 @@ class DataCenterBuilding {
                 synchronousMessageObjService.update(message)
             }
             Configure.DELETE -> {
-                /** 删除 */
-               val sign = BuildingApi.deleteObj(dictProject!!.groupCode!!,message.projectId!!, message.objId!!)
-                if (sign){
-                    /** 成功 */
-                    message.sign = 0
-                }else {
-                    /** 失败 */
-                    message.sign = 2
-                    message.count +1
+                val query = BuildingApi.queryIdTwo(dictProject!!.groupCode!!, message.projectId!!, message.objId!!)
+                if (query!=null&&query.result == "success"&&!query.data.isNullOrEmpty()) {
+                    val building = BuildingUtil.buildingDataConversions(
+                        message.projectId!!,
+                        dictProject!!.groupCode!!,
+                        query.data!![0]
+                    )
+                    /** 删除 */
+                    val sign = BuildingApi.deleteObj(dictProject!!.groupCode!!,message.projectId!!, message.objId!!)
+                    upDateMessage(message,building)
+                    if (sign!=null&&sign.result == "success"){
+                        /** 成功 */
+                        message.sign = 0
+                    }else {
+                        /** 失败 */
+                        message.sign = 2
+                        message.error = sign!!.toJson()
+                        message.count +1
+                    }
+
+                } else {
+                    if (query!=null&&query.result == "success"&&query.data.isNullOrEmpty()) {
+                        message.sign = 0
+                    }else if (query!=null){
+                        message.sign = 2
+                        message.error = query!!.toJson()
+                        message.count +1
+                    }else {
+                        message.sign = 2
+                        message.error = "服务未连通"
+                        message.count +1
+                    }
                 }
                 /** 更改标记 */
                 synchronousMessageObjService.update(message)
@@ -137,4 +173,15 @@ class DataCenterBuilding {
         }
     }
 
+    /**
+     * 更新消息
+     */
+    fun upDateMessage(message: SynchronousMessage,equip: Building){
+        message.localId = equip.localId
+        message.localName = equip.localName
+        message.name = equip.localName
+        message.objName = "建筑"
+        message.opsName = ParamTools.operationType(message.ops!!)
+    }
+
 }

+ 79 - 13
datasyn/src/main/kotlin/com/persagy/server/syn/services/jms/DataCenterComponent.kt

@@ -26,14 +26,18 @@
 
 package com.persagy.server.syn.services.jms
 
+import com.persagy.base.extensions.toJson
 import com.persagy.database.SFilter
 import com.persagy.mybatis.SMybatisDao
 import com.persagy.server.datacenter.models.entities.dictnew.DictProject
 import com.persagy.server.datacenter.models.entities.objects.Equipment
 import com.persagy.server.datacenter.models.jms.SynchronousMessage
 import com.persagy.server.syn.Configure
+import com.persagy.server.syn.models.api.obj.BuildingApi
 import com.persagy.server.syn.models.api.obj.EquipApi
 import com.persagy.server.syn.models.tools.EquipUtil
+import com.persagy.server.syn.services.dict.DClassDefService
+import com.persagy.server.syn.utils.ParamTools
 import com.persagy.service.SBaseService
 import com.persagy.service.SObjectService
 import org.springframework.stereotype.Service
@@ -70,7 +74,8 @@ class DataCenterComponent {
                 if (equip!=null) {
                     val equipList = EquipUtil.equipTools(message.projectId!!, equip)
                     val sign = EquipApi.createObj(dictProject!!.groupCode!!, message.projectId!!, equipList)
-                    if (sign){
+                    upDateMessage(message,equip)
+                    if (sign!=null&& sign.result == "success"){
                         /** 成功 */
                         message.sign = 0
                         if (!equip.parentId.isNullOrEmpty()){
@@ -82,6 +87,7 @@ class DataCenterComponent {
                                     EquipApi.createRel(dictProject.groupCode!!, message.projectId!!, toJsonObjArray)
                                 if (!createRel) {
                                     message.sign = 2
+                                    message.error = "设备和部件的关系失败"
                                     message.count +1
                                 }
                             } else {
@@ -90,9 +96,14 @@ class DataCenterComponent {
                             }
                         }
                     }else {
+                        if (sign!=null){
+                            message.error = sign.toJson()
+                        } else {
+                            message.error = "服务未连通"
+                        }
                         /** 失败 */
                         message.sign = 2
-                        message.count +1
+                        message.count = message.count  +1
                     }
 
                 }else {
@@ -110,15 +121,22 @@ class DataCenterComponent {
                 ).entity()
                 /** floor不为空 */
                 if (equip!=null) {
+                    upDateMessage(message,equip)
                     val equipList = EquipUtil.equipTools(message.projectId!!, equip)
                     val sign = EquipApi.updateObj(dictProject!!.groupCode!!,message.projectId!!, equipList)
-                    if (sign){
+                    if (sign!=null&& sign.result == "success"){
                         /** 成功 */
                         message.sign = 0
                     }else {
-                        /** 失败 */
-                        message.sign = 2
+                        if (sign != null) {
+                            /** 失败 */
+                            message.error = sign.toJson()
+                        } else {
+                            /** 失败 */
+                            message.error = "服务未连通"
+                        }
                         message.count +1
+                        message.sign = 2
                     }
 
                 }else {
@@ -128,15 +146,44 @@ class DataCenterComponent {
                 synchronousMessageObjService.update(message)
             }
             Configure.DELETE -> {
-                /** 删除 */
-               val sign = EquipApi.deleteObj(dictProject!!.groupCode!!,message.projectId!!, message.objId!!)
-                if (sign){
-                    /** 成功 */
-                    message.sign = 0
+
+                val query = BuildingApi.queryIdTwo(dictProject!!.groupCode!!, message.projectId!!, message.objId!!)
+                if (query!=null&&query.result == "success"&&!query.data.isNullOrEmpty()) {
+
+                    val equipment = EquipUtil.equipSyns(
+                        message.projectId!!,
+                        dictProject!!.groupCode!!,
+                        query.data!![0]
+                    )
+                    /** 删除 */
+                    val sign = EquipApi.deleteObj(dictProject!!.groupCode!!,message.projectId!!, message.objId!!)
+                    upDateMessage(message,equipment)
+                    if (sign!=null&&sign.result == "success"){
+                        /** 成功 */
+                        message.sign = 0
+                    }else {
+                        if (sign!=null){
+                            message.error = sign.toJson()
+                        } else {
+                            message.error = "服务器未连通"
+                        }
+                        /** 失败 */
+                        message.sign = 2
+                        message.count +1
+                    }
                 }else {
-                    /** 失败 */
-                    message.sign = 2
-                    message.count +1
+                    if (query!=null&&query.result == "success"&&query.data.isNullOrEmpty()) {
+                        message.sign = 0
+                    }else if (query!=null){
+                        message.sign = 2
+                        message.error = query.toJson()
+                        message.count +1
+                    }else {
+                        message.sign = 2
+                        message.error = "服务未连通"
+                        message.count +1
+                    }
+
                 }
                 /** 更改标记 */
                 synchronousMessageObjService.update(message)
@@ -144,4 +191,23 @@ class DataCenterComponent {
         }
     }
 
+    /**
+     * 更新消息
+     */
+    fun upDateMessage(message: SynchronousMessage,equip: Equipment){
+        message.classCode = equip.classCode
+        message.localId = equip.localId
+        message.localName = equip.localName
+        message.name = equip.localName
+        message.objName = "部件"
+        message.opsName = ParamTools.operationType(message.ops!!)
+        val entity =
+            DClassDefService.select(SFilter.eq("projectId", equip.projectId!!), SFilter.eq("code", equip.classCode!!))
+                .entity()
+        if (entity!=null) {
+            message.classCodeName = entity.name
+        }
+    }
+
+
 }

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

@@ -26,14 +26,18 @@
 
 package com.persagy.server.syn.services.jms
 
+import com.persagy.base.extensions.toJson
 import com.persagy.database.SFilter
 import com.persagy.mybatis.SMybatisDao
 import com.persagy.server.datacenter.models.entities.dictnew.DictProject
 import com.persagy.server.datacenter.models.entities.objects.Equipment
 import com.persagy.server.datacenter.models.jms.SynchronousMessage
 import com.persagy.server.syn.Configure
+import com.persagy.server.syn.models.api.obj.BuildingApi
 import com.persagy.server.syn.models.api.obj.EquipApi
 import com.persagy.server.syn.models.tools.EquipUtil
+import com.persagy.server.syn.services.dict.DClassDefService
+import com.persagy.server.syn.utils.ParamTools
 import com.persagy.service.SBaseService
 import com.persagy.service.SObjectService
 import org.springframework.stereotype.Service
@@ -72,10 +76,10 @@ class DataCenterEquipment {
                 if (equip!=null) {
                     val equipList = EquipUtil.equipTools(message.projectId!!, equip)
                     val sign = EquipApi.createObj(dictProject!!.groupCode!!,message.projectId!!, equipList)
-                    if (sign){
+                    upDateMessage(message,equip)
+                    if (sign!=null&& sign.result == "success"){
                         /** 成功 */
                         message.sign = 0
-
                             if (!equip.buildingId.isNullOrEmpty()&&!equip.floorId.isNullOrEmpty()){
                                 try {
                                     val toJsonObjArray =
@@ -88,6 +92,7 @@ class DataCenterEquipment {
                                     val createRel = EquipApi.createRel(dictProject.groupCode!!, message.projectId!!, toJsonObjArray)
                                     if (!createRel){
                                         message.sign = 2
+                                        message.error = "设备和建筑楼层的关系存储失败"
                                         message.count = message.count+1
                                     }
                                 } catch (e: Exception) {
@@ -101,22 +106,31 @@ class DataCenterEquipment {
                                 val createRel = EquipApi.createRel(dictProject.groupCode!!, message.projectId!!, toJsonObjArray)
                                 if (!createRel){
                                     message.sign = 2
+                                    message.error = "设备和建筑的关系存储失败"
                                     message.count = message.count+1
                                 }
                             }
                         } else {
                             /** 失败 */
-                            message.sign = 2
-                            message.count = message.count+1
+                        if (sign!=null){
+                            message.error = sign.toJson()
+                        } else {
+                            message.error = "服务未连通"
+                        }
+                        /** 失败 */
+                        message.sign = 2
+                        message.count = message.count  +1
                         }
                     }else {
                         /** 失败 */
                         message.sign = 2
+                        message.error = "设备不存在可能已删除"
                         message.count = message.count+1
                     }
                 } else {
                     /** 失败 */
                     message.sign = 2
+                    message.error = "集团信息为空"
                     message.count = message.count+1
                 }
                 /** 更改标记 */
@@ -134,20 +148,32 @@ class DataCenterEquipment {
                     if (equip != null) {
                         val equipList = EquipUtil.equipTools(message.projectId!!, equip)
                         val sign = EquipApi.updateObj(dictProject!!.groupCode!!, message.projectId!!, equipList)
-                        if (sign) {
+                        upDateMessage(message,equip)
+                        if (sign!=null&& sign.result == "success"){
                             /** 成功 */
                             message.sign = 0
                         } else {
                             /** 失败 */
+                            if (sign != null) {
+                                /** 失败 */
+                                message.error = sign.toJson()
+                            } else {
+                                /** 失败 */
+                                message.error = "服务未连通"
+                            }
+                            message.count +1
                             message.sign = 2
-                            message.count = message.count + 1
                         }
 
                     } else {
-                        message.sign = 0
+                        /** 失败 */
+                        message.sign = 2
+                        message.error = "设备不存在可能已删除"
+                        message.count = message.count+1
                     }
                 } else {
                     message.sign = 2
+                    message.error = "集团信息为空"
                     message.count = message.count + 1
                 }
                 /** 更改标记 */
@@ -155,19 +181,49 @@ class DataCenterEquipment {
             }
             Configure.DELETE -> {
                 if (dictProject!=null) {
-                    /** 删除 */
-                    val sign = EquipApi.deleteObj(dictProject!!.groupCode!!, message.projectId!!, message.objId!!)
-                    if (sign) {
-                        /** 成功 */
-                        message.sign = 0
+
+                    val query = BuildingApi.queryIdTwo(dictProject!!.groupCode!!, message.projectId!!, message.objId!!)
+                    if (query!=null&&query.result == "success"&&!query.data.isNullOrEmpty()) {
+
+                        val equipment = EquipUtil.equipSyns(
+                            message.projectId!!,
+                            dictProject.groupCode!!,
+                            query.data!![0]
+                        )
+                        /** 删除 */
+                        val sign = EquipApi.deleteObj(dictProject!!.groupCode!!, message.projectId!!, message.objId!!)
+                        upDateMessage(message,equipment)
+                        if (sign!=null&&sign.result == "success"){
+                            /** 成功 */
+                            message.sign = 0
+                        } else {
+                            /** 失败 */
+                            if (sign!=null){
+                                message.error = sign.toJson()
+                            } else {
+                                message.error = "服务器未连通"
+                            }
+                            /** 失败 */
+                            message.sign = 2
+                            message.count +1
+                        }
                     } else {
-                        /** 失败 */
-                        message.sign = 2
-                        message.count = message.count + 1
+                        if (query!=null&&query.result == "success"&&query.data.isNullOrEmpty()) {
+                            message.sign = 0
+                        }else if (query!=null){
+                            message.sign = 2
+                            message.error = query.toJson()
+                            message.count +1
+                        }else {
+                            message.sign = 2
+                            message.error = "服务未连通"
+                            message.count +1
+                        }
                     }
                 } else {
                     /** 失败 */
                     message.sign = 2
+                    message.error = "集团信息为空"
                     message.count = message.count + 1
                 }
                 /** 更改标记 */
@@ -239,5 +295,21 @@ class DataCenterEquipment {
     }
 
 
-
+    /**
+     * 更新消息
+     */
+    fun upDateMessage(message: SynchronousMessage,equip: Equipment){
+        message.classCode = equip.classCode
+        message.localId = equip.localId
+        message.localName = equip.localName
+        message.name = equip.localName
+        message.objName = "设备"
+        message.opsName = ParamTools.operationType(message.ops!!)
+        val entity =
+            DClassDefService.select(SFilter.eq("projectId", equip.projectId!!), SFilter.eq("code", equip.classCode!!))
+                .entity()
+        if (entity!=null) {
+            message.classCodeName = entity.name
+        }
+    }
 }

+ 3 - 3
datasyn/src/main/kotlin/com/persagy/server/syn/services/jms/DataCenterShaft.kt

@@ -72,7 +72,7 @@ class DataCenterShaft {
                 if (shaft!=null) {
                     val shaftList = ShaftUtil.shaftTools(message.projectId!!, shaft)
                     val sign = EquipApi.createObj(dictProject!!.groupCode!!,message.projectId!!, shaftList)
-                    if (sign){
+                    if (sign!=null&&sign.result == "success") {
                         /** 成功 */
                         message.sign = 0
                     }else {
@@ -97,7 +97,7 @@ class DataCenterShaft {
                 if (shaft!=null) {
                     val shaftList = ShaftUtil.shaftTools(message.projectId!!, shaft)
                     val sign = EquipApi.updateObj(dictProject!!.groupCode!!,message.projectId!!, shaftList)
-                    if (sign){
+                    if (sign!=null&&sign.result == "success") {
                         /** 成功 */
                         message.sign = 0
                     }else {
@@ -114,7 +114,7 @@ class DataCenterShaft {
             Configure.DELETE -> {
                 /** 删除 */
                val sign = EquipApi.deleteObj(dictProject!!.groupCode!!,message.projectId!!, message.objId!!)
-                if (sign){
+                if (sign!=null&&sign.result == "success") {
                     /** 成功 */
                     message.sign = 0
                 }else {

+ 75 - 17
datasyn/src/main/kotlin/com/persagy/server/syn/services/jms/DataCenterSpace.kt

@@ -28,6 +28,7 @@ package com.persagy.server.syn.services.jms
 
 import com.alibaba.fastjson.JSONArray
 import com.alibaba.fastjson.JSONObject
+import com.persagy.base.extensions.toJson
 import com.persagy.database.SFilter
 import com.persagy.mybatis.SMybatisDao
 import com.persagy.server.datacenter.models.entities.dictnew.DictProject
@@ -36,8 +37,11 @@ import com.persagy.server.datacenter.models.entities.rel.RSpinBd
 import com.persagy.server.datacenter.models.entities.rel.RSpinFl
 import com.persagy.server.datacenter.models.jms.SynchronousMessage
 import com.persagy.server.syn.Configure
+import com.persagy.server.syn.models.api.obj.BuildingApi
 import com.persagy.server.syn.models.api.obj.EquipApi
 import com.persagy.server.syn.models.tools.SpaceUtil
+import com.persagy.server.syn.services.dict.DClassDefService
+import com.persagy.server.syn.utils.ParamTools
 import com.persagy.service.SBaseService
 import com.persagy.service.SObjectService
 import org.springframework.stereotype.Service
@@ -78,13 +82,12 @@ class DataCenterSpace {
                 ).entity()
                 /** 不为空 */
                 if (space!=null) {
+                    upDateMessage(message,space)
                     val spaceList = SpaceUtil.spaceTools(message.projectId!!, space)
                     val sign = EquipApi.createObj(dictProject!!.groupCode!!,message.projectId!!, spaceList)
-                    if (sign){
+                    if (sign!=null&& sign.result == "success"){
                         /** 成功 */
                         message.sign = 0
-
-                        if (dictProject!=null){
                             val rSpinBdList = rSpinBdService.select(
                                 SFilter.eq("projectId", message.projectId!!),
                                 SFilter.eq("spaceId", space.id!!)
@@ -115,18 +118,22 @@ class DataCenterSpace {
                                 val createRel = EquipApi.createRel(dictProject.groupCode!!, message.projectId!!, jsonArray)
                                 if (!createRel){
                                     message.sign = 2
+                                    message.error = "空间的建筑楼层关系存储失败"
                                     message.count +1
                                 }
                             }
 
+
+                    }else {
+                        /** 失败 */
+                        if (sign!=null){
+                            message.error = sign.toJson()
                         } else {
-                            message.sign = 2
-                            message.count +1
+                            message.error = "服务未连通"
                         }
-                    }else {
                         /** 失败 */
                         message.sign = 2
-                        message.count +1
+                        message.count = message.count  +1
                     }
 
                 }else {
@@ -144,15 +151,23 @@ class DataCenterSpace {
                 ).entity()
                 /** 不为空 */
                 if (space!=null) {
+                    upDateMessage(message,space!!)
                     val spaceList = SpaceUtil.spaceTools(message.projectId!!, space)
                     val sign = EquipApi.updateObj(dictProject!!.groupCode!!,message.projectId!!, spaceList)
-                    if (sign){
+                    if (sign!=null&& sign.result == "success"){
                         /** 成功 */
                         message.sign = 0
                     }else {
                         /** 失败 */
-                        message.sign = 2
+                        if (sign != null) {
+                            /** 失败 */
+                            message.error = sign.toJson()
+                        } else {
+                            /** 失败 */
+                            message.error = "服务未连通"
+                        }
                         message.count +1
+                        message.sign = 2
                     }
                 }else {
                     message.sign = 0
@@ -161,15 +176,43 @@ class DataCenterSpace {
                 synchronousMessageObjService.update(message)
             }
             Configure.DELETE -> {
-                /** 删除 */
-               val sign = EquipApi.deleteObj(dictProject!!.groupCode!!,message.projectId!!, message.objId!!)
-                if (sign){
-                    /** 成功 */
-                    message.sign = 0
+                val query = BuildingApi.queryIdTwo(dictProject!!.groupCode!!, message.projectId!!, message.objId!!)
+                if (query!=null&&query.result == "success"&&!query.data.isNullOrEmpty()) {
+
+                    val space = SpaceUtil.spaceDataConversions(
+                        message.projectId!!,
+                        dictProject!!.groupCode!!,
+                        query.data!![0]
+                    )
+                    upDateMessage(message,space)
+                    /** 删除 */
+                    val sign = EquipApi.deleteObj(dictProject!!.groupCode!!, message.projectId!!, message.objId!!)
+                    if (sign != null && sign.result == "success") {
+                        /** 成功 */
+                        message.sign = 0
+                    } else {
+                        /** 失败 */
+                        if (sign != null) {
+                            message.error = sign.toJson()
+                        } else {
+                            message.error = "服务器未连通"
+                        }
+                        /** 失败 */
+                        message.sign = 2
+                        message.count + 1
+                    }
                 }else {
-                    /** 失败 */
-                    message.sign = 2
-                    message.count +1
+                    if (query!=null&&query.result == "success"&&query.data.isNullOrEmpty()) {
+                        message.sign = 0
+                    }else if (query!=null){
+                        message.sign = 2
+                        message.error = query.toJson()
+                        message.count +1
+                    }else {
+                        message.sign = 2
+                        message.error = "服务未连通"
+                        message.count +1
+                    }
                 }
                 /** 更改标记 */
                 synchronousMessageObjService.update(message)
@@ -203,4 +246,19 @@ class DataCenterSpace {
         return jsonObject
     }
 
+    fun upDateMessage(message: SynchronousMessage,equip: ZoneSpace){
+        message.classCode = equip.classCode
+        message.localId = equip.localId
+        message.localName = equip.localName
+        message.name = equip.localName
+        message.objName = "空间"
+        message.opsName = ParamTools.operationType(message.ops!!)
+        val entity =
+            DClassDefService.select(SFilter.eq("projectId", equip.projectId!!), SFilter.eq("code", equip.classCode!!))
+                .entity()
+        if (entity!=null) {
+            message.classCodeName = entity.name
+        }
+    }
+
 }

+ 3 - 3
datasyn/src/main/kotlin/com/persagy/server/syn/services/jms/DataCenterSystem.kt

@@ -71,7 +71,7 @@ class DataCenterSystem {
                 if (system!=null) {
                     val systemList = SystemUtil.systemTools(message.projectId!!, system)
                     val sign = EquipApi.createObj(dictProject!!.groupCode!!,message.projectId!!, systemList)
-                    if (sign){
+                    if (sign!=null&&sign.result == "success") {
                         /** 成功 */
                         message.sign = 0
                     }else {
@@ -97,7 +97,7 @@ class DataCenterSystem {
                 if (system!=null) {
                     val systemList = SystemUtil.systemTools(message.projectId!!, system)
                     val sign = EquipApi.updateObj(dictProject!!.groupCode!!,message.projectId!!, systemList)
-                    if (sign){
+                    if (sign!=null&&sign.result == "success") {
                         /** 成功 */
                         message.sign = 0
                     }else {
@@ -114,7 +114,7 @@ class DataCenterSystem {
             Configure.DELETE -> {
                 /** 删除 */
                val sign = EquipApi.deleteObj(dictProject!!.groupCode!!,message.projectId!!, message.objId!!)
-                if (sign){
+                if (sign!=null&&sign.result == "success") {
                     /** 成功 */
                     message.sign = 0
                 }else {

+ 3 - 3
datasyn/src/main/kotlin/com/persagy/server/syn/services/jms/DataCenterVOTn.kt

@@ -48,7 +48,7 @@ class DataCenterVOTn {
                 if (tenant!=null) {
                     val tenantList = VOTnUtil.equipTools(message.projectId!!, tenant)
                     val sign = EquipApi.createObj(dictProject!!.groupCode!!,message.projectId!!, tenantList)
-                    if (sign){
+                    if (sign!=null&&sign.result == "success") {
                         /** 成功 */
                         message.sign = 0
                     }else {
@@ -70,7 +70,7 @@ class DataCenterVOTn {
                 if (tenant!=null) {
                     val equipList = VOTnUtil.equipTools(message.projectId!!, tenant)
                     val sign = EquipApi.updateObj(dictProject!!.groupCode!!,message.projectId!!, equipList)
-                    if (sign){
+                    if (sign!=null&&sign.result == "success") {
                         /** 成功 */
                         message.sign = 0
                     }else {
@@ -84,7 +84,7 @@ class DataCenterVOTn {
             Configure.DELETE -> {
                 /** 删除 */
                 val sign = EquipApi.deleteObj(dictProject!!.groupCode!!,message.projectId!!, message.objId!!)
-                if (sign){
+                if (sign!=null&&sign.result == "success") {
                     /** 成功 */
                     message.sign = 0
                 }else {

+ 138 - 0
datasyn/src/main/kotlin/com/persagy/server/syn/services/journal/SynchronousMessageService.kt

@@ -0,0 +1,138 @@
+/*
+ * *********************************************************************************************************************
+ *
+ *          !!
+ *        .F88X
+ *        X8888Y
+ *      .}888888N;
+ *        i888888N;        .:!              .I$WI:
+ *          R888888I      .'N88~            i8}+8Y&8"l8i$8>8W~'>W8}8]KW+8IIN"8&
+ *          .R888888I    .;N8888~          .X8'  "8I.!,/8"  !%NY8`"8I8~~8>,88I
+ *            +888888N;  .8888888Y                                  "&&8Y.}8,
+ *            ./888888N;  .R888888Y        .'}~    .>}'.`+>  i}!    "i'  +/'  .'i~  !11,.:">,  .~]!  .i}i
+ *              ~888888%:  .I888888l      .]88~`1/iY88Ii+1'.R$8$8]"888888888>  Y8$  W8E  X8E  W8888'188Il}Y88$*
+ *              18888888    E8888881    .]W%8$`R8X'&8%++N8i,8N%N8+l8%`  .}8N:.R$RE%N88N%N$K$R  188,FE$8%~Y88I
+ *            .E888888I  .i8888888'      .:$8I;88+`E8R:/8N,.>881.`$8E/1/]N8X.Y8N`"KF&&FK!'88*."88K./$88%RN888+~
+ *            8888888I  .,N888888~        ~88i"8W,!N8*.I88.}888%F,i$88"F88"  888:E8X.>88!i88>`888*.}Fl1]*}1YKi'
+ *          i888888N'      I888Y          ]88;/EX*IFKFK88X  K8R  .l8W  88Y  ~88}'88E&%8W.X8N``]88!.$8K  .:W8I
+ *        .i888888N;        I8Y          .&8$  .X88!  i881.:%888>I88  ;88]  +88+.';;;;:.Y88X  18N.,88l  .+88/
+ *      .:R888888I
+ *      .&888888I                                          Copyright (c) 2009-2021.  博锐尚格科技股份有限公司
+ *        ~8888'
+ *        .!88~                                                                     All rights reserved.
+ *
+ * *********************************************************************************************************************
+ */
+
+package com.persagy.server.syn.services.journal
+
+import com.persagy.database.SFilter
+import com.persagy.mybatis.SMybatisDao
+import com.persagy.server.datacenter.models.entities.dictnew.DefClass
+import com.persagy.server.datacenter.models.jms.SynchronousMessage
+import com.persagy.server.syn.jms.DataCenterSync
+import com.persagy.server.syn.models.api.obj.ProjectApi
+import com.persagy.server.syn.models.tools.ProjectUtil
+import com.persagy.server.syn.services.BaseDataService
+import com.persagy.server.syn.services.dict.DClassDefService
+import com.persagy.server.syn.services.mappers.TypeMapper
+import com.persagy.service.SObjectService
+import com.persagy.service.models.enums.SResponseType
+import com.persagy.service.models.requests.SUpdateRequest
+import com.persagy.service.models.responses.SBaseResponse
+import com.persagy.service.models.responses.SQueryResponse
+import com.persagy.service.utils.SSpringContextUtil
+
+/**
+ * 日志 服务
+ *
+ * @author wx  <zhangweixin@sagacloud.com>
+ * @date  2021/2/25 10:33
+ */
+object SynchronousMessageService : SObjectService<SynchronousMessage>(SMybatisDao(SynchronousMessage::class.java)) {
+
+
+
+    /** 类型统计 */
+    private val typeMapper by lazy {
+        SSpringContextUtil.getBean(TypeMapper::class.java) as TypeMapper
+    }
+
+    /** 数据中心处理数据同步到数据中台 */
+    private val dataCenterSync by lazy {
+        SSpringContextUtil.getBean(DataCenterSync::class.java) as DataCenterSync
+    }
+
+
+    /**
+     * 查询未同步的对象分类
+     *
+     * @param objType   对象类型
+     */
+    fun typeQuery(objType: String,projectId: String): SQueryResponse<DefClass> {
+        try {
+            val sQueryResponse = SQueryResponse<DefClass>(SResponseType.success)
+            val typeCountList = typeMapper.typeCount(projectId, objType)
+            if (!typeCountList.isNullOrEmpty()) {
+                val listCode = ArrayList<String>()
+                for (typeCount in typeCountList){
+                    listCode.add(typeCount.code!!)
+                }
+                val dClassDefList = DClassDefService.select(SFilter.eq("projectId", projectId), SFilter.inList("code", listCode)).exec()
+                sQueryResponse.content = dClassDefList
+                sQueryResponse.total = dClassDefList.size.toLong()
+            }else {
+                sQueryResponse.content = ArrayList()
+            }
+            return sQueryResponse
+        } catch (e: Exception) {
+            e.printStackTrace()
+            return  SQueryResponse( SResponseType.failure,e.message.toString())
+        }
+
+    }
+
+    /**
+     *  重新同步数据
+     *
+     *  @param request  日志对象列表
+     */
+    fun synData(request: SUpdateRequest<SynchronousMessage>): SBaseResponse {
+        if (!request.content.isNullOrEmpty()) {
+            dataCenterSync.dataSync(request.content!!)
+        }
+        return SBaseResponse(SResponseType.success)
+    }
+
+    /**
+     * 测试服务器是否在线
+     *
+     * @param groupCode  集团编码
+     */
+    fun isOnline(groupCode: String,projectId: String): SBaseResponse{
+        try {
+            val sBaseResponse = SBaseResponse()
+            val postObject = ProjectApi.projectQueryTwo(groupCode,projectId)
+            if (postObject!=null&&postObject.result == "success"&&!postObject.data.isNullOrEmpty()) {
+                if (postObject.data!!.size > 0) {
+                    for (projectQuery in postObject.data!!) {
+                        val projectDataConversion = ProjectUtil.projectDataConversions(groupCode, projectQuery)
+                        BaseDataService.projectService.replace(projectDataConversion)
+                    }
+                }
+                sBaseResponse.result = SResponseType.success
+                sBaseResponse.message = "服务正常"
+            } else {
+                sBaseResponse.result = SResponseType.failure
+                sBaseResponse.message = "f服务器异常"
+            }
+            return sBaseResponse
+        } catch (e: Exception) {
+            e.printStackTrace()
+            return SBaseResponse(SResponseType.failure,"服务器异常")
+        }
+    }
+
+
+
+}

+ 49 - 0
datasyn/src/main/kotlin/com/persagy/server/syn/services/mappers/TypeMapper.kt

@@ -0,0 +1,49 @@
+/*
+ * *********************************************************************************************************************
+ *
+ *          !!
+ *        .F88X
+ *        X8888Y
+ *      .}888888N;
+ *        i888888N;        .:!              .I$WI:
+ *          R888888I      .'N88~            i8}+8Y&8"l8i$8>8W~'>W8}8]KW+8IIN"8&
+ *          .R888888I    .;N8888~          .X8'  "8I.!,/8"  !%NY8`"8I8~~8>,88I
+ *            +888888N;  .8888888Y                                  "&&8Y.}8,
+ *            ./888888N;  .R888888Y        .'}~    .>}'.`+>  i}!    "i'  +/'  .'i~  !11,.:">,  .~]!  .i}i
+ *              ~888888%:  .I888888l      .]88~`1/iY88Ii+1'.R$8$8]"888888888>  Y8$  W8E  X8E  W8888'188Il}Y88$*
+ *              18888888    E8888881    .]W%8$`R8X'&8%++N8i,8N%N8+l8%`  .}8N:.R$RE%N88N%N$K$R  188,FE$8%~Y88I
+ *            .E888888I  .i8888888'      .:$8I;88+`E8R:/8N,.>881.`$8E/1/]N8X.Y8N`"KF&&FK!'88*."88K./$88%RN888+~
+ *            8888888I  .,N888888~        ~88i"8W,!N8*.I88.}888%F,i$88"F88"  888:E8X.>88!i88>`888*.}Fl1]*}1YKi'
+ *          i888888N'      I888Y          ]88;/EX*IFKFK88X  K8R  .l8W  88Y  ~88}'88E&%8W.X8N``]88!.$8K  .:W8I
+ *        .i888888N;        I8Y          .&8$  .X88!  i881.:%888>I88  ;88]  +88+.';;;;:.Y88X  18N.,88l  .+88/
+ *      .:R888888I
+ *      .&888888I                                          Copyright (c) 2009-2021.  博锐尚格科技股份有限公司
+ *        ~8888'
+ *        .!88~                                                                     All rights reserved.
+ *
+ * *********************************************************************************************************************
+ */
+
+package com.persagy.server.syn.services.mappers
+
+import com.persagy.server.syn.models.journal.TypeCode
+import org.apache.ibatis.annotations.Mapper
+import org.apache.ibatis.annotations.Param
+import org.apache.ibatis.annotations.Select
+import org.springframework.stereotype.Repository
+
+/**
+ * 对象类型
+ * @author wx  <zhangweixin@sagacloud.com>
+ * @date  2021/2/25 11:49
+ */
+@Mapper
+@Repository
+interface TypeMapper {
+
+    /** 对象分类统计 */
+    @Select("SELECT class_code as code FROM synchronization.sync_data WHERE project_id = #{projectId} AND  object_type = #{objType} AND   NOT class_code IS NULL   GROUP BY class_code")
+    fun typeCount(@Param("projectId") projectId:String,@Param("objType") objType:String ): ArrayList<TypeCode>
+
+
+}

+ 2 - 2
datasyn/src/main/kotlin/com/persagy/server/syn/task/SchedulerTask.kt

@@ -51,9 +51,9 @@ class SchedulerTask {
     lateinit var messageProcessing: MessageProcessing
 
     //cron表达式:每隔5秒执行一次
-    @Scheduled(cron = "0 */5 * * * ?")
+//    @Scheduled(cron = "0 */5 * * * ?")
 //    @Scheduled(cron="0/30 * *  * * ? ")   //每5秒执行一次
-//    @Scheduled(cron = "0 */1 * * * ?")
+    @Scheduled(cron = "0 */1 * * * ?")
     fun scheduled() {
         logger.info("同步数据中心任务开始至中台")
         messageProcessing.syncDataCenter()

+ 2 - 2
datasyn/src/main/kotlin/com/persagy/server/syn/task/SchedulerTaskRel.kt

@@ -51,9 +51,9 @@ class SchedulerTaskRel {
     lateinit var messageProcessing: MessageProcessing
 
     //cron表达式:每隔5秒执行一次
-    @Scheduled(cron = "0 */5 * * * ?")
+//    @Scheduled(cron = "0 */5 * * * ?")
 //    @Scheduled(cron="0/5 * *  * * ? ")   //每5秒执行一次
-//    @Scheduled(cron = "0 */1 * * * ?")
+    @Scheduled(cron = "0 */1 * * * ?")
     fun scheduled() {
         logger.info("同步数据中心任务开始至数据中台-关系数据")
         messageProcessing.syncDataCenterRel()

+ 1 - 2
datasyn/src/main/kotlin/com/persagy/server/syn/task/SchedulerTaskTwo.kt

@@ -29,7 +29,6 @@ package com.persagy.server.syn.task
 import com.persagy.server.syn.jms.MessageProcessing
 import org.slf4j.LoggerFactory
 import org.springframework.beans.factory.annotation.Autowired
-import org.springframework.scheduling.annotation.Scheduled
 import org.springframework.stereotype.Service
 
 /**
@@ -51,7 +50,7 @@ class SchedulerTaskTwo {
     lateinit var messageProcessing: MessageProcessing
     //cron表达式:每隔5秒执行一次
 //    @Scheduled(cron = "0 */3 * * * ?")
-    @Scheduled(cron = "0 */1 * * * ?")
+//    @Scheduled(cron = "0 */1 * * * ?")
 //    @Scheduled(cron="0/5 * *  * * ? ")   //每5秒执行一次
     fun scheduled() {
         try {

+ 18 - 0
datasyn/src/main/kotlin/com/persagy/server/syn/utils/ParamTools.kt

@@ -627,6 +627,24 @@ object ParamTools {
 //        }
 //    }
 
+    /**
+     * 操作类型
+     */
+    fun operationType(type: String): String {
+        when(type){
+            "create" -> {
+                return "创建"
+            }
+            "delete" -> {
+                return "删除"
+            }
+            "update" ->{
+                return "修改"
+            }
+        }
+        return ""
+    }
+
 
 
 } // Object ParamTools

+ 1 - 1
gradle.properties

@@ -26,7 +26,7 @@
 
 PERSAGY_URL = http://www.persagy.cn
 PERSAGY_KOTLIN_VERSION = 1.4.121
-PERSAGY_SERVICE_VERSION = 1.4.163
+PERSAGY_SERVICE_VERSION = 1.4.164
 
 MAVEN_REPO_PUBLIC_URL = http://dev.dp.sagacloud.cn:8082/repository/maven-public/
 MAVEN_REPO_RELEASE_URL = http://dev.dp.sagacloud.cn:8082/repository/maven-releases/