DefineInfoMapper.xml 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.persagy.dmp.rwd.define.dao.ObjectInfoMapper">
  6. <!-- 因该对象dataSource字段需要使用自定义Handler处理,
  7. 且在xml自定义sql使用的是MybatisConfiguration类对象,
  8. 无法使用mybatis-plus,所以这里定义了一个ResultMap-->
  9. <resultMap id="BaseResultMap" type="com.persagy.dmp.define.entity.ObjectInfoDefine">
  10. <id property="id" column="id" jdbcType="VARCHAR"/>
  11. <result property="code" column="code" jdbcType="VARCHAR"/>
  12. <result property="name" column="name" jdbcType="VARCHAR"/>
  13. <result property="aliasCode" column="alias_code" jdbcType="VARCHAR"/>
  14. <result property="aliasName" column="alias_name" jdbcType="VARCHAR"/>
  15. <result property="classCode" column="class_code" jdbcType="VARCHAR"/>
  16. <result property="groupCode" column="group_code" jdbcType="VARCHAR"/>
  17. <result property="projectId" column="project_id" jdbcType="VARCHAR"/>
  18. <result property="category" column="category" jdbcType="VARCHAR"/>
  19. <result property="firstTag" column="first_tag" jdbcType="VARCHAR"/>
  20. <result property="secondTag" column="second_tag" jdbcType="VARCHAR"/>
  21. <result property="priority" column="priority" jdbcType="VARCHAR"/>
  22. <result property="inputMode" column="input_mode" jdbcType="VARCHAR"/>
  23. <result property="unit" column="unit" jdbcType="VARCHAR"/>
  24. <result property="dataType" column="data_type" jdbcType="VARCHAR"/>
  25. <result property="isMultiple" column="is_multiple" jdbcType="INTEGER"/>
  26. <result property="isRegion" column="is_region" jdbcType="INTEGER"/>
  27. <result property="formater" column="formater" jdbcType="VARCHAR"/>
  28. <result property="dataSource" column="data_source" jdbcType="OTHER" typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/>
  29. <result property="remark" column="remark" jdbcType="VARCHAR"/>
  30. <result property="subFlag" column="sub_flag" jdbcType="INTEGER"/>
  31. <result property="weakPoint" column="weak_point" jdbcType="INTEGER"/>
  32. <result property="showOrder" column="show_order" jdbcType="INTEGER"/>
  33. <result property="version" column="version" jdbcType="VARCHAR"/>
  34. <result property="creator" column="creator" jdbcType="VARCHAR"/>
  35. <result property="creationTime" column="creation_time" jdbcType="CHAR"/>
  36. <result property="modifier" column="modifier" jdbcType="VARCHAR"/>
  37. <result property="modifiedTime" column="modified_time" jdbcType="CHAR"/>
  38. <result property="valid" column="valid" jdbcType="TINYINT"/>
  39. <result property="ts" column="ts" jdbcType="TIMESTAMP"/>
  40. </resultMap>
  41. <!-- 类型如果重复则会出现多条,因此这里先用distinct容错.将基础类型的信息点与非基础信息点一起返回,且class_code改为对应的非基础对象类型 -->
  42. <sql id="SelectColumns">
  43. distinct
  44. dt_define_info.id, dt_define_info.code, dt_define_info.name, dt_define_info.alias_code,
  45. dt_define_info.alias_name, dt_define_type.code as class_code, dt_define_info.group_code,
  46. dt_define_info.project_id,dt_define_info.category,dt_define_info.first_tag,
  47. dt_define_info.second_tag, dt_define_info.priority,dt_define_info.input_mode,
  48. dt_define_info.unit,dt_define_info.data_type,dt_define_info.is_multiple,dt_define_info.is_region,
  49. dt_define_info.formater,dt_define_info.data_source,
  50. dt_define_info.remark,dt_define_info.sub_flag,
  51. dt_define_info.weak_point,dt_define_info.show_order,dt_define_info.version,dt_define_info.creator,
  52. dt_define_info.creation_time,dt_define_info.modifier,dt_define_info.modified_time,
  53. dt_define_info.valid,dt_define_info.ts
  54. </sql>
  55. <!--
  56. 1. 如果为基础类型、且为平台级,优先级100
  57. 2. 如果为基础类型、且为集团级,优先级200
  58. 3. 如果为基础类型、且为项目级,优先级300
  59. 4. 如果为非基础类型、且为平台级,优先级400
  60. 5. 如果为非基础类型、且为集团级,优先级500
  61. 6. 如果为非基础类型、且为项目级,优先级600
  62. -->
  63. <sql id="ShowLevelSQL">
  64. (case
  65. when dt_define_info.class_code in ('project','building','floor','space','system','equipment','shaft','component','virtual','tool','material')
  66. and dt_define_info.project_id = '0' then 100
  67. when dt_define_info.class_code in ('project','building','floor','space','system','equipment','shaft','component','virtual','tool','material')
  68. and dt_define_info.project_id = dt_define_info.group_code then 200
  69. when dt_define_info.class_code in ('project','building','floor','space','system','equipment','shaft','component','virtual','tool','material')
  70. and dt_define_info.project_id != dt_define_info.group_code then 300
  71. when dt_define_info.class_code not in ('project','building','floor','space','system','equipment','shaft','component','virtual','tool','material')
  72. and dt_define_info.project_id = '0' then 400
  73. when dt_define_info.class_code not in ('project','building','floor','space','system','equipment','shaft','component','virtual','tool','material')
  74. and dt_define_info.project_id = dt_define_info.group_code then 500
  75. when dt_define_info.class_code not in ('project','building','floor','space','system','equipment','shaft','component','virtual','tool','material')
  76. and dt_define_info.project_id != dt_define_info.group_code then 600
  77. else 0 end)
  78. </sql>
  79. <!-- 按项目查询信息点(包含上级信息点) -->
  80. <sql id="InfoTableSQL">
  81. select
  82. <include refid="SelectColumns"/>
  83. from dt_define_type inner join dt_define_info on dt_define_info.class_code in (dt_define_type.code, dt_define_type.obj_type)
  84. and dt_define_type.valid = 1 and dt_define_info.valid = 1
  85. <if test="projectIds!=null and projectIds.size>0">
  86. <foreach collection="projectIds" item="projectId" separator="," open=" and dt_define_info.project_id IN (" close=")">
  87. #{projectId}
  88. </foreach>
  89. </if>
  90. where exists(select 1 from (
  91. select dt_define_type.code class_code, dt_define_info.code code, max(<include refid="ShowLevelSQL"/>) max_show_level
  92. from dt_define_type inner join dt_define_info on dt_define_info.class_code in (dt_define_type.code, dt_define_type.obj_type)
  93. and dt_define_type.valid = 1 and dt_define_info.valid = 1
  94. <if test="projectIds!=null and projectIds.size>0">
  95. <foreach collection="projectIds" item="projectId" separator="," open="where dt_define_info.project_id IN (" close=")">
  96. #{projectId}
  97. </foreach>
  98. </if>
  99. group by dt_define_type.code, dt_define_info.code
  100. ) T
  101. where T.class_code = dt_define_type.code and T.code = dt_define_info.code and T.max_show_level = <include refid="ShowLevelSQL"/>)
  102. </sql>
  103. <select id="queryByClassCodes" resultMap="BaseResultMap">
  104. select ${ew.sqlSelect}
  105. from ( <include refid="InfoTableSQL"/> ) dt_define_info
  106. WHERE ${ew.expression.sqlSegment}
  107. </select>
  108. <select id="queryCollectInfos" resultType="java.util.Map">
  109. select dt_object.id, dt_object.local_id, dt_object.local_name, dt_define_info.class_code, dt_define_type.name as class_name,
  110. dt_define_info.code, dt_define_info.name,dt_define_info.first_tag, dt_define_info.data_type,dt_define_info.category,
  111. json_unquote(json_extract(dt_object.infos, concat('$.', dt_define_info.code))) as info_value
  112. from ( <include refid="InfoTableSQL"/> ) dt_define_info
  113. inner join dt_define_type on dt_define_info.class_code = dt_define_type.code and dt_define_type.valid = 1
  114. inner join dt_object on dt_object.class_code = dt_define_info.class_code and dt_object.valid = 1 and dt_define_info.code not in ('localId','localName')
  115. WHERE ${ew.expression.sqlSegment}
  116. </select>
  117. <select id="queryCollectReport" resultType="java.util.Map">
  118. select count(1) as all_num, sum(case when category = 'STATIC' then 1 else 0 end) as static_num,
  119. sum(case when category = 'STATIC' and info_value is not null then 1 else 0 end) as static_value_num,
  120. sum(case when category != 'STATIC' then 1 else 0 end) as dynamic_num,
  121. sum(case when category != 'STATIC' and info_value is not null then 1 else 0 end) as dynamic_value_num
  122. from (
  123. select dt_object.id, dt_object.local_id, dt_object.local_name, dt_define_info.class_code, dt_define_type.name as class_name,
  124. dt_define_info.code, dt_define_info.name,dt_define_info.first_tag, dt_define_info.data_type,dt_define_info.category,
  125. json_unquote(json_extract(dt_object.infos, concat('$.', dt_define_info.code))) as info_value
  126. from ( <include refid="InfoTableSQL"/> ) dt_define_info
  127. inner join dt_define_type on dt_define_info.class_code = dt_define_type.code and dt_define_type.valid = 1
  128. inner join dt_object on dt_object.class_code = dt_define_info.class_code and dt_object.valid = 1 and dt_define_info.code not in ('localId','localName')
  129. WHERE ${ew.expression.sqlSegment}
  130. ) R
  131. </select>
  132. </mapper>