Selaa lähdekoodia

sql报错问题修复

linhuili 3 vuotta sitten
vanhempi
commit
41a393315b

+ 11 - 1
scanbuilding/build.gradle

@@ -41,7 +41,12 @@ compileKotlin {
 compileTestKotlin {
     kotlinOptions.jvmTarget = JVM_TARGET
 }
-
+repositories {
+    maven{url MAVEN_REPO_NEXUS_PUBLIC_URL}
+    maven{url MAVEN_REPO_NEXUS_RELEASE_URL}
+    mavenCentral()
+    jcenter()
+}
 dependencies {
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     // kotlin 依赖
@@ -90,6 +95,7 @@ dependencies {
     compile group: "com.persagy", name: "persagy-service-base", version: PERSAGY_SERVICE_VERSION_LAST
     compile group: "com.persagy", name: "persagy-service-mybatis", version: PERSAGY_SERVICE_VERSION_LAST
     compile group: "com.persagy", name: "persagy-kotlin-mysql", version: PERSAGY_KOTLIN_VERSION
+    compile group: "com.persagy", name: "dmp-digital-starter", version: DIGITAL_START_VERSION
 
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     // 数据中心依赖  
@@ -98,6 +104,10 @@ dependencies {
     //Gson
     compile 'com.google.code.gson:gson:2.8.0'
 
+    // spring cloud 依赖
+    compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-netflix-eureka-client', version:  SPRING_CLOUD_CONFIG_VERSION
+    // Log 工具
+    compile group: "org.projectlombok", name: "lombok", version: LOMBOK_VERSION
 
 //    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //    // 二维码与条形码

+ 30 - 0
scanbuilding/src/main/kotlin/com/persagy/server/client/DmpDicClient.kt

@@ -0,0 +1,30 @@
+package com.persagy.server.client
+
+import com.alibaba.fastjson.JSONArray
+import com.alibaba.fastjson.JSONObject
+import com.persagy.dmp.basic.config.DigitalFeignConfig
+import com.persagy.server.constant.DmpUrlConstant
+import com.persagy.server.entities.request.InstanceUrlParam
+import com.persagy.server.entities.response.DmpResult
+import org.springframework.cloud.openfeign.FeignClient
+import org.springframework.cloud.openfeign.SpringQueryMap
+import org.springframework.web.bind.annotation.PostMapping
+import org.springframework.web.bind.annotation.RequestBody
+
+/**
+ * @description:数据中台dmp-rwd 物理世界、数据字典、IOT 接口feign
+ * @author:lgy
+ * @data:2021/8/11 14:56
+ */
+@FeignClient(name = "dmp-rwd", configuration = [DigitalFeignConfig::class])
+interface DmpDicClient {
+    /**
+     * @description: 查询对象列表
+     * @param: objectUrlParam 对象请求url通用参数
+     * @param: criteria post请求参数
+     * @return: com.persagy.dmp.common.DmpResult
+     */
+    @PostMapping(DmpUrlConstant.DEF_CLASS)
+    fun queryDictObjectType(@SpringQueryMap objectUrlParam: InstanceUrlParam?, @RequestBody criteria: JSONObject?): DmpResult<JSONArray?>?
+
+ }

+ 162 - 0
scanbuilding/src/main/kotlin/com/persagy/server/constant/DmpUrlConstant.java

@@ -0,0 +1,162 @@
+package com.persagy.server.constant;
+
+
+/**
+ *@description:dmp服务请求url常量
+ *@author:lgy
+ *@data:2021/8/11 15:00
+ */
+public class DmpUrlConstant {
+
+    /**
+     * 创建对象
+     */
+    public final static String OBJECT_CREATE = "/rwd/instance/object/create";
+
+    /**
+     * 更新对象
+     */
+    public final static String OBJECT_UPDATE = "/rwd/instance/object/update";
+
+    /**
+     * 删除对象
+     */
+    public final static String OBJECT_DELETE = "/rwd/instance/object/delete";
+
+    /**
+     * 查询对象
+     */
+    public final static String OBJECT_QUERY = "/rwd/instance/object/query";
+
+    /**
+     * 查询实时数据
+     */
+    public final static String OBJECT_CURRENT_DATA = "/rwd/iot/data/current";
+
+    /**
+     * 查询历史数据/分精度数据
+     */
+    public final static String OBJECT_HISTORY_DATA = "/rwd/iot/data/history";
+
+    /**
+     * 查询图实例
+     */
+    public final static String GRAPH_QUERY = "/rwd/graph/query";
+
+    /**
+     * 创建关系
+     */
+    public final static String RELATION_CREATE = "/rwd/instance/relation/create";
+
+    /**
+     * 删除关系
+     */
+    public final static String RELATION_DELETE = "/rwd/instance/relation/delete";
+
+    /**
+     * 查询关系
+     */
+    public final static String RELATION_QUERY = "/rwd/instance/relation/query";
+
+    /**
+     * 查询关系对象
+     */
+    public final static String RELATION_OBJECT_QUERY = "/rwd/instance/relation/object/query";
+
+
+
+    /**
+     * 查询信息点描述信息
+     */
+    public final static String DEF_FUNCID = "/rwd/def/funcid";
+
+    /**
+     * 创建信息点
+     */
+    public final static String DEF_FUNCID_CREATE = "/rwd/def/funcid/create";
+
+    /**
+     * 批量修改信息点
+     */
+    public final static String DEF_FUNCID_UPDATE_BATCH = "/rwd/def/funcid/updateBatch";
+
+
+    /**
+     * 批量删除信息点
+     */
+    public final static String DEF_FUNCID_DEL_BATCH = "/rwd/def/funcid/deleteBatch";
+
+    /**
+     * 类型查询
+     */
+    public final static String DEF_CLASS = "/rwd/def/class";
+
+    // ==================中台组织结构=========================================================================
+
+    /**
+     * 中台人员组织权限服务--查询用户
+     */
+    public static final String ORG_USER_QUERY = "/org/user/query";
+
+    /**
+     * 集团查询
+     */
+    public static final String ORG_GROUP_QUERY = "/org/group/query";
+
+    /**
+     * 项目查询
+     */
+    public static final String ORG_PROJECT_QUERY = "/org/project/query";
+
+    /**批量查询项目接口URI*/
+    public static final  String OBJECT_BATCH_QUERY_PROJECT_BY_IDS = "/rwd/instance/object/batchQueryProjectByIds";
+
+    // ==================中台知识库=========================================================================
+
+    /**
+     * 字典数据查询
+     */
+    public static final String DIC_DATA_QUERY = "/dic/dt/data/query";
+
+    // ==================中台关系计算入口=========================================================================
+    /**
+     * 关系计算创建
+     */
+    public static final String OBJECT_COMPATIBLE_CREATE = "rwd/instance/object/compatible/createObjRelationsByKeywordAndObjType";
+
+    /**
+     * 关系计算删除
+     */
+    public static final String OBJECT_COMPATIBLE_DELETE = "rwd/instance/object/compatible/deleteObjRelationsByRelId";
+
+
+    /**
+     * 查询
+     */
+    public static final String RELATION_PROJECT_CAL_QUERY = "/rwd/instance/relation/project/cal/query";
+    /**
+     * 字典数据查询
+     */
+    public static final String RELATION_PROJECT_CAL_CREATE = "/rwd/instance/relation/project/cal/create";
+    /**
+     * 更新
+     */
+    public static final String RELATION_PROJECT_CAL_UPDATE = "/rwd/instance/relation/project/cal/update";
+
+    /**
+     * 删除
+     */
+    public static final String RELATION_PROJECT_CAL_DELETE = "/rwd/instance/relation/project/cal/delete";
+
+    /**
+     * 查询采集信息点
+     */
+    public final static String DEF_FUNCID_COLLECT = "/rwd/def/funcid/collect/query";
+
+    /**
+     * 批量设置采集信息点
+     */
+    public final static String DEF_FUNCID_COLLECT_SET = "/rwd/def/funcid/collect/updateBatch";
+
+
+}

+ 32 - 0
scanbuilding/src/main/kotlin/com/persagy/server/entities/request/InstanceUrlParam.kt

@@ -0,0 +1,32 @@
+package com.persagy.server.entities.request
+
+import lombok.NoArgsConstructor
+import lombok.AllArgsConstructor
+import com.fasterxml.jackson.annotation.JsonInclude
+import lombok.Builder
+import lombok.Data
+import java.io.Serializable
+import java.math.BigInteger
+
+/**
+ * @description: 对象、关系请求url通用参数
+ */
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+@JsonInclude(JsonInclude.Include.NON_NULL)
+class InstanceUrlParam {
+        /**
+         * 集团编码
+         */
+        var groupCode: String? = null
+        /**
+         * 项目id
+         */
+        var projectId: String? = null
+
+
+        val serialVersionUID : Long? = -994117732505752231L
+
+}

+ 76 - 0
scanbuilding/src/main/kotlin/com/persagy/server/entities/response/DmpResult.kt

@@ -0,0 +1,76 @@
+package com.persagy.server.entities.response
+
+import com.alibaba.fastjson.JSONArray
+import lombok.NoArgsConstructor
+import lombok.extern.slf4j.Slf4j
+import java.lang.Exception
+import lombok.Data
+import java.io.Serializable
+import java.lang.IllegalArgumentException
+import java.lang.reflect.*
+import java.lang.reflect.Array
+
+/**
+ * @description: 数据中台返回值通用类
+ * @author: lgy
+ * @since: 2021/08/11 15:40
+ * @version: V1.0
+ */
+@Data
+@NoArgsConstructor
+@Slf4j
+class DmpResult<T> : Serializable {
+    val result: String? = null
+    val data: T? = null
+    val count: Int? = null
+    val message: String? = null
+    fun getData(clazz: Class<T>): T? {
+        if (data == null) {
+            var t: T? = null
+            try {
+                t = clazz.newInstance()
+            } catch (e: Exception) {
+                //DmpResult.log.error(e.message, e)
+            }
+            return t
+        }
+        return data
+    }
+
+    fun getData(t: T): T {
+        return data ?: t
+    }
+
+    companion object {
+        /**
+         * 成功
+         */
+        const val SUCCESS = "success"
+
+        /**
+         * 失败
+         */
+        const val FAILURE = "failure"
+        private const val serialVersionUID = 1L
+
+        // type不能直接实例化对象,通过type获取class的类型,然后实例化对象
+        fun getRawType(type: Type?): Class<*> {
+            return if (type is Class<*>) {
+                type
+            } else if (type is ParameterizedType) {
+                val rawType = type.rawType
+                rawType as Class<*>
+            } else if (type is GenericArrayType) {
+                val componentType = type.genericComponentType
+                Array.newInstance(getRawType(componentType), 0).javaClass
+            } else if (type is TypeVariable<*>) {
+                Any::class.java
+            } else if (type is WildcardType) {
+                getRawType(type.upperBounds[0])
+            } else {
+                val className = if (type == null) "null" else type.javaClass.name
+                throw IllegalArgumentException("Expected a Class, ParameterizedType, or GenericArrayType, but <$type> is of type $className")
+            }
+        }
+    }
+}

+ 45 - 0
scanbuilding/src/main/kotlin/com/persagy/server/services/DmpBaseService.kt

@@ -0,0 +1,45 @@
+package com.persagy.server.services
+
+import com.alibaba.fastjson.JSONArray
+import com.alibaba.fastjson.JSONObject
+import com.persagy.server.Opts
+import com.persagy.server.client.DmpDicClient
+import com.persagy.server.datacenter.models.entities.task.EquipCategoryDic
+import com.persagy.server.entities.request.InstanceUrlParam
+import com.persagy.server.util.AdmEntityTransferUtil
+import com.persagy.service.utils.SSpringContextUtil
+import org.springframework.stereotype.Service
+
+/**
+ * 物理世界对象查询
+ * @author:linhuili
+ * @date:2021/10/19
+ */
+@Service
+class DmpBaseService {
+
+    /** 自定义 sql */
+    private val rwdClient by lazy {
+        SSpringContextUtil.getBean(DmpDicClient::class.java) as DmpDicClient
+    }
+
+    /**
+     * 查询字典类型
+     * @param params
+     * @return
+     */
+    fun queryDictType(params: JSONObject?): List<EquipCategoryDic>? {
+        //封装基础查询参数
+        val instanceUrlParam = InstanceUrlParam()
+        instanceUrlParam.groupCode = Opts.groupCode
+        instanceUrlParam.projectId = Opts.projectId
+        //查询对象信息
+        val dmpResult = rwdClient!!.queryDictObjectType(instanceUrlParam, params) ?: return ArrayList()
+        if(dmpResult.data == null){
+            return ArrayList<EquipCategoryDic>()
+        }
+        return AdmEntityTransferUtil.toAdmMultiEntity(dmpResult.data, null, EquipCategoryDic::class.java)
+    }
+
+
+}

+ 32 - 14
scanbuilding/src/main/kotlin/com/persagy/server/services/task/ScanTaskBaseService.kt

@@ -26,6 +26,7 @@
 
 package com.persagy.server.services.task
 
+import com.alibaba.fastjson.JSONObject
 import com.google.gson.Gson
 import com.google.gson.reflect.TypeToken
 import com.persagy.database.SFilter
@@ -34,6 +35,7 @@ import com.persagy.mybatis.SMybatisDao
 import com.persagy.server.datacenter.models.entities.task.*
 import com.persagy.server.datacenter.models.entities.task.base.ScanTaskBase
 import com.persagy.server.mappers.StatisticsCountMapper
+import com.persagy.server.services.DmpBaseService
 import com.persagy.server.services.base.RService
 import com.persagy.service.SBaseService
 import com.persagy.service.SPageContext
@@ -41,6 +43,7 @@ import com.persagy.service.models.enums.SResponseType
 import com.persagy.service.models.requests.SQueryRequest
 import com.persagy.service.models.responses.SQueryResponse
 import com.persagy.service.utils.SSpringContextUtil
+import org.springframework.beans.factory.annotation.Autowired
 
 /**
  * 任务父表
@@ -54,25 +57,40 @@ object ScanTaskBaseService : RService<ScanTaskBase>(SMybatisDao(ScanTaskBase::cl
         SSpringContextUtil.getBean(StatisticsCountMapper::class.java) as StatisticsCountMapper
     }
 
+    @Autowired
+    private val dmpBaseService: DmpBaseService? = DmpBaseService()
+
     /**
      * 查询所有设备类型或设备族
      */
     fun equipCategoryQuery(type: String): SQueryResponse<EquipCategoryDic> {
-        val pageQuery: SPageQueryInfo<EquipCategoryDic>
+        /*val pageQuery: SPageQueryInfo<EquipCategoryDic>
         return try {
-            val equipCategoryDicService = SBaseService(SMybatisDao(EquipCategoryDic::class.java))
-            var request = SQueryRequest()
-            val queryBuilder = equipCategoryDicService.select(request.filters)
-
-            val projectId = SPageContext.getHeader("projectId").toString()
-            queryBuilder.tableName = "scantask.f_get_category('$type','$projectId')"
-            pageQuery = queryBuilder.pageQuery(1, 1000)
-            SQueryResponse(pageQuery)
-        } catch (e: Exception) {
-            e.printStackTrace()
-            SQueryResponse(SResponseType.failure, e.message!!)
-        }
-    } //  Fun equipCategoryQuery
+             val equipCategoryDicService = SBaseService(SMybatisDao(EquipCategoryDic::class.java))
+             var request = SQueryRequest()
+             val queryBuilder = equipCategoryDicService.select(request.filters)
+
+             val projectId = SPageContext.getHeader("projectId").toString()
+             queryBuilder.tableName = "scantask.f_get_category('$type','$projectId')"
+             pageQuery = queryBuilder.pageQuery(1, 1000)
+             SQueryResponse(pageQuery)
+         } catch (e: Exception) {
+             e.printStackTrace()
+             SQueryResponse(SResponseType.failure, e.message!!)
+         }*/
+        val sQueryResponse = SQueryResponse<EquipCategoryDic>(SResponseType.success)
+        val param = JSONObject()
+        val criteria = JSONObject()
+         if ("equip" == type) {
+             criteria["objType"] = "equipment"
+        }else{
+             criteria["objType"] = type
+         }
+        param["criteria"] = criteria
+        val queryDictType = dmpBaseService!!.queryDictType(param)
+        sQueryResponse.content = queryDictType
+        return sQueryResponse
+    }
 
     /**
      * 查询所有建筑和楼层

+ 138 - 0
scanbuilding/src/main/kotlin/com/persagy/server/util/AdmEntityTransferUtil.kt

@@ -0,0 +1,138 @@
+package com.persagy.server.util
+
+import com.persagy.dmp.basic.utils.JsonNodeUtils
+import cn.hutool.core.collection.CollUtil
+import cn.hutool.core.util.ArrayUtil
+import com.fasterxml.jackson.databind.JsonNode
+import com.fasterxml.jackson.databind.node.ArrayNode
+import com.fasterxml.jackson.databind.node.ObjectNode
+
+/**
+ * ADM通用查询条件
+ * @author Charlie Yu
+ * @date 2021-08-16
+ */
+object AdmEntityTransferUtil {
+    /**
+     * 转换为数据中台对象
+     * @param objList
+     * @return
+     */
+    fun toDmpMultiEntity(objList: List<*>?): ArrayNode {
+        return JsonNodeUtils.toArrayNode(objList, "infos", null)
+    }
+
+    /**
+     * 转换为数据中台对象
+     * @param obj
+     * @return
+     */
+    fun toDmpSingleEntity(obj: Any?): JsonNode {
+        return JsonNodeUtils.toObjectNode(obj, "infos", null)
+    }
+
+    /**
+     * 转换为数据中心对象
+     * @param array 数据中台对象
+     * @param clazz 数据中心对象class
+     * @param <T>
+     * @return
+    </T> */
+    fun <T> toAdmMultiEntity(array: List<*>?, projection: List<String?>?, clazz: Class<T>?): List<T>? {
+        val dataNode = JsonNodeUtils.toArrayNode(array, null, null)
+        return toAdmMultiEntity(dataNode, projection, clazz)
+    }
+
+    /**
+     * 转换为数据中心对象
+     * @param clazz
+     * @param <T>
+     * @return
+     * @param array
+    </T> */
+    fun <T> toAdmMultiEntity(array: ArrayNode, projection: List<String?>?, clazz: Class<T>?): List<T>? {
+        if (ArrayUtil.isEmpty(array)) {
+            return null
+        }
+        // 转换属性名
+        var i = 0
+        val j = array.size()
+        while (i < j) {
+            val node = array[i]
+            if (node != null && node.isObject) {
+                resetAdmProperty(node as ObjectNode, projection)
+            }
+            i++
+        }
+        return JsonNodeUtils.toEntity(array, clazz, "infos")
+    }
+
+    /**
+     * 转换为数据中心对象
+     * @param node
+     * @param clazz
+     * @param <T>
+     * @return
+    </T> */
+    fun <T> toAdmSingleEntity(node: ObjectNode, projection: List<String?>?, clazz: Class<T>?): T {
+        resetAdmProperty(node, projection)
+        return JsonNodeUtils.toEntity(node, clazz, "infos")
+    }
+
+    /**
+     * 处理dmp转adm对象的属性名
+     * @param node
+     */
+    private fun resetAdmProperty(node: ObjectNode, projection: List<String?>?) {
+        // 转换属性名 TODO 目前只有创建时间和修改时间需要转换,后续有其他时通过建立映射在此转换即可
+        copyProperty(node, "creationTime", "createTime")
+        copyProperty(node, "modifiedTime", "lastUpdate")
+        copyProperty(node, "objType", "objectType")
+        removeProperty(node, projection)
+    }
+
+    /**
+     * 拷贝属性
+     * @param dmpData 数据中台对象
+     * @param srcProp 数据中台属性名
+     * @param desProp 对应的数据中心属性名
+     */
+    private fun copyProperty(dmpData: ObjectNode?, srcProp: String, desProp: String) {
+        if (dmpData == null) {
+            return
+        }
+        val value = dmpData[srcProp]
+        if (value == null || value.isNull) {
+            return
+        }
+        dmpData.set<JsonNode>(desProp, value)
+        dmpData.remove(srcProp)
+    }
+
+    /**
+     * 删除掉数据中心不需要的属性
+     * @param dmpData
+     */
+    private fun removeProperty(dmpData: ObjectNode, projection: List<String?>?) {
+        if (CollUtil.isNotEmpty(projection)) {
+            // 转换为Set,提供遍历效率
+            val fieldSet: Set<String?> = CollUtil.newHashSet(projection)
+            val fields = dmpData.fieldNames()
+            while (fields.hasNext()) {
+                val field = fields.next()
+                // 返回结果中包含的不处理
+                if (fieldSet.contains(field)) {
+                    continue
+                }
+                // 去掉不包含的属性
+                fields.remove()
+            }
+        } else {
+            // 返回全部时,去掉不需要属性
+            val removeList: List<String> = CollUtil.newArrayList("creator", "valid", "createApp", "virtualCodes", "updateApp", "grouping", "modifier")
+            for (removeField in removeList) {
+                dmpData.remove(removeField)
+            }
+        }
+    }
+}

+ 6 - 5
scanbuilding/src/main/resources/application.yml

@@ -1,9 +1,9 @@
 ###############################################################################################################
 # spring-cloud相关配置
-#eureka:
-#  client:                                   #客户端注册进eureka服务列表内
-#    service-url:
-#      defaultZone:                          http://eureka-service:8761/eureka
+eureka:
+  client:                                   #客户端注册进eureka服务列表内
+    service-url:
+      defaultZone:                          http://frame:123456@develop.persagy.com/integrated-eureka/eureka/
 #启用监控
 management:
   endpoints:
@@ -53,7 +53,8 @@ spring:
     mapper:
       # 属性按字母顺序输出
      sort_properties_alphabetically:   true
-
+  main:
+    allow-bean-definition-overriding: true
 # spring-doc 配置
 springdoc:
   # springdoc 扫描的包,多个包之间使用逗号分隔