TopicMapper.xml 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  4. <mapper namespace="com.ozs.kpim.mapper.topic.TopicMapper">
  5. <sql id="base_column_list">
  6. id,topic_code,name,description,level,update_time,update_user_id,create_time
  7. </sql>
  8. <!--插入(所有字段)-->
  9. <insert id="insert" parameterType="com.ozs.kpim.dto.topic.TopicDTO">
  10. INSERT INTO kpim_info_topic(id,topic_code,name,description,level,update_time,update_user_id,create_time)
  11. VALUE(UUID(),#{topicCode},#{name},#{description},#{level},NOW(),#{updateUserId},NOW());
  12. </insert>
  13. <!--更新(所有字段,id,topic_code,level除外)-->
  14. <update id="update" parameterType="com.ozs.kpim.dto.topic.TopicDTO">
  15. UPDATE kpim_info_topic
  16. SET
  17. name = #{name},
  18. description = #{description},
  19. update_time = NOW(),
  20. update_user_id = #{updateUserId}
  21. WHERE 1 = 1
  22. <if test="id != null and id != '' ">
  23. and id = #{id}
  24. </if>
  25. <if test="topicCode != null and topicCode != '' ">
  26. and topic_code = #{topicCode}
  27. </if>
  28. </update>
  29. <!--删除主题-->
  30. <delete id="delete">
  31. DELETE FROM kpim_info_topic WHERE id = #{id}
  32. </delete>
  33. <!--删除主题及子主题,根据主题编码-->
  34. <delete id="deleteByTopicCode">
  35. DELETE FROM kpim_info_topic WHERE topic_code LIKE CONCAT(#{topicCode},'%')
  36. </delete>
  37. <!--根据ID查询详情-->
  38. <select id="getById" resultType="com.ozs.kpim.dto.topic.TopicDTO">
  39. SELECT
  40. A.id,A.topic_code,
  41. A.name,A.description,
  42. A.level,A.update_time,A.create_time,
  43. A.update_user_id,
  44. /*B.topic_code as parentTopicCode,*/
  45. IFNULL(B.topic_code,'0') AS parentTopicCode,
  46. B.name as parentTopic,
  47. SU.nickname as updateUserName
  48. FROM kpim_info_topic A
  49. LEFT JOIN kpim_info_topic B
  50. ON LEFT(A.topic_code,LENGTH(A.topic_code)-3) = B.topic_code
  51. LEFT JOIN dc_info_user SU
  52. ON A.update_user_id = SU.id
  53. WHERE A.id = #{id}
  54. </select>
  55. <!--根据topic_code查询详情-->
  56. <select id="getByTopicCode" resultType="com.ozs.kpim.dto.topic.TopicDTO">
  57. SELECT
  58. A.id,A.topic_code,
  59. A.name,A.description,
  60. A.level,A.update_time,A.create_time,
  61. A.update_user_id,
  62. /*B.topic_code as parentTopicCode,*/
  63. IFNULL(B.topic_code,'0') AS parentTopicCode,
  64. B.name as parentTopic ,
  65. SU.nickname as updateUserName
  66. FROM kpim_info_topic A
  67. LEFT JOIN kpim_info_topic B
  68. ON LEFT(A.topic_code,LENGTH(A.topic_code)-3) = B.topic_code
  69. LEFT JOIN dc_info_user SU
  70. ON A.update_user_id = SU.id
  71. WHERE A.topic_code = #{topicCode}
  72. </select>
  73. <!--根据topic_code查询主题列表-->
  74. <select id="listTopicsByTopicCodes" resultType="com.ozs.kpim.dto.topic.TopicDTO">
  75. SELECT
  76. A.id,A.topic_code,
  77. A.name,A.description,
  78. A.level,A.update_time,A.create_time,
  79. A.update_user_id,
  80. B.topic_code as parentTopicCode,
  81. B.name as parentTopic ,
  82. SU.nickname as updateUserName
  83. FROM kpim_info_topic A
  84. LEFT JOIN kpim_info_topic B
  85. ON LEFT(A.topic_code,LENGTH(A.topic_code)-3) = B.topic_code
  86. LEFT JOIN dc_info_user SU
  87. ON A.update_user_id = SU.id
  88. <if test="list != null and list.size > 0 ">
  89. WHERE A.topic_code IN
  90. <foreach collection="list" item="item" open="(" close=")" separator=",">
  91. #{item}
  92. </foreach>
  93. </if>
  94. </select>
  95. <!--根据KpiId查询主题列表-->
  96. <select id="listTopicsByKpiId" resultType="com.ozs.kpim.dto.topic.TopicDTO">
  97. SELECT
  98. A.id,A.topic_code,
  99. A.name,A.description,
  100. A.level,A.update_time,A.create_time,
  101. A.update_user_id,
  102. B.topic_code as parentTopicCode,
  103. B.name as parentTopic ,
  104. SU.nickname as updateUserName
  105. FROM kpim_info_topic A
  106. LEFT JOIN kpim_info_topic B
  107. ON LEFT(A.topic_code,LENGTH(A.topic_code)-3) = B.topic_code
  108. LEFT JOIN dc_info_user SU
  109. ON A.update_user_id = SU.id
  110. LEFT JOIN kpim_rel_kpi_topic D
  111. ON A.id = D.topic_id
  112. WHERE D.kpi_id = #{kpiId}
  113. </select>
  114. <!--根据ID查询数量-->
  115. <select id="getCountById" resultType="java.lang.Integer">
  116. SELECT COUNT(1) FROM kpim_info_topic WHERE id = #{id}
  117. </select>
  118. <!--根据topicCode查询数量-->
  119. <select id="getCountByTopicCode" resultType="java.lang.Integer">
  120. SELECT COUNT(1) FROM kpim_info_topic WHERE topic_code = #{topicCode}
  121. </select>
  122. <!--判断主题是否在使用中-->
  123. <select id="ifTopicInfoUse" resultType="java.lang.Integer">
  124. SELECT COUNT(1) FROM kpim_rel_kpi_topic WHERE topic_id = #{topicId}
  125. </select>
  126. <!--判断主题或者主题下的子主题是否被使用-->
  127. <select id="ifTopicOrSubTopicsInUse" resultType="java.lang.Integer">
  128. SELECT COUNT(1) FROM kpim_rel_kpi_topic WHERE topic_id IN
  129. <foreach collection="list" item="item" open="(" close=")" separator=",">
  130. #{item}
  131. </foreach>
  132. </select>
  133. <!--主题列表查询-->
  134. <select id="listTopics" resultType="com.ozs.kpim.dto.topic.TopicDTO">
  135. SELECT
  136. A.id,A.topic_code,
  137. A.name,A.description,
  138. A.level,A.update_time,A.create_time,
  139. A.update_user_id,
  140. B.topic_code as parentTopicCode,
  141. B.name as parentTopic ,
  142. SU.nickname as updateUserName
  143. FROM kpim_info_topic A
  144. LEFT JOIN kpim_info_topic B
  145. ON LEFT(A.topic_code,LENGTH(A.topic_code)-3) = B.topic_code
  146. LEFT JOIN dc_info_user SU
  147. ON A.update_user_id = SU.id
  148. <where>
  149. <if test="name != null and name != '' ">
  150. A.name LIKE CONCAT('%',#{name},'%')
  151. </if>
  152. </where>
  153. </select>
  154. <!--查询上级主题编码查询下级主题-->
  155. <select id="listSubTopics" resultType="com.ozs.kpim.dto.topic.TopicDTO">
  156. SELECT
  157. <include refid="base_column_list"/>
  158. FROM kpim_info_topic
  159. <where>
  160. <if test=" parentTopicCode != null and parentTopicCode !='' ">
  161. topic_code LIKE CONCAT(#{parentTopicCode},'%')
  162. AND topic_code != #{parentTopicCode}
  163. AND level = LENGTH(#{parentTopicCode})/3 + 1
  164. </if>
  165. <if test=" parentTopicCode == null or parentTopicCode == '' ">
  166. level = 1
  167. </if>
  168. </where>
  169. </select>
  170. <!--20190331查询主题的所有子主题不分级别-->
  171. <select id="listAllSubTopics" resultType="com.ozs.kpim.dto.topic.TopicDTO">
  172. SELECT
  173. <include refid="base_column_list"/>
  174. FROM kpim_info_topic
  175. WHERE topic_code LIKE CONCAT(#{parentTopicCode},'%') AND topic_code != #{parentTopicCode}
  176. </select>
  177. <!--给ztree使用的格式-->
  178. <select id="topicForZtree" resultType="com.ozs.kpim.dto.topic.TopicZtreeDTO">
  179. SELECT
  180. A.id,
  181. A.topic_code as code,
  182. A.name as name,
  183. /*B.topic_code as pcode*/
  184. IFNULL(B.topic_code,'0') AS pcode
  185. FROM kpim_info_topic A
  186. LEFT JOIN kpim_info_topic B
  187. ON LEFT(A.topic_code,LENGTH(A.topic_code)-3) = B.topic_code
  188. <where>
  189. <if test="name != null and name != '' ">
  190. A.name LIKE CONCAT('%',#{name},'%')
  191. </if>
  192. </where>
  193. order by A.create_time asc
  194. </select>
  195. </mapper>