RoleSensitiveMapper.xml 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.dk.mdm.mapper.mst.RoleSensitiveMapper">
  4. <!-- 通用设置 -->
  5. <!-- 通用查询列 -->
  6. <sql id="Base_Column_List">
  7. role_id, sen_item_code, flg_show, cp_id, op_create_time, op_create_user_id, op_update_time, op_update_user_id, op_app_code, op_timestamp, op_db_user
  8. </sql>
  9. <!-- 通用查询映射结果 -->
  10. <resultMap id="BaseResultMap" type="com.dk.mdm.model.pojo.mst.RoleSensitive">
  11. <id column="role_id" property="roleId"/>
  12. <result column="sen_item_code" property="senItemCode"/>
  13. <result column="flg_show" property="flgShow"/>
  14. <result column="cp_id" property="cpId"/>
  15. <result column="op_create_time" property="opCreateTime" typeHandler="TimestampTypeHandler"/>
  16. <result column="op_create_user_id" property="opCreateUserId" typeHandler="UuidTypeHandler"/>
  17. <result column="op_update_time" property="opUpdateTime" typeHandler="TimestampTypeHandler"/>
  18. <result column="op_update_user_id" property="opUpdateUserId" typeHandler="UuidTypeHandler"/>
  19. <result column="op_app_code" property="opAppCode"/>
  20. <result column="op_timestamp" property="opTimestamp" typeHandler="TimestampTypeHandler"/>
  21. <result column="op_db_user" property="opDbUser"/>
  22. </resultMap>
  23. <!-- 通用条件列 -->
  24. <sql id="Condition">
  25. <where>
  26. <if test="senItemCode != null and senItemCode != ''">
  27. AND sen_item_code = #{senItemCode}
  28. </if>
  29. <if test="flgShow != null">
  30. AND flg_show = #{flgShow}
  31. </if>
  32. <if test="cpId != null">
  33. AND cp_id = #{cpId}
  34. </if>
  35. <if test="opCreateTime != null">
  36. AND op_create_time = #{opCreateTime}
  37. </if>
  38. <if test="opCreateUserId != null and opCreateUserId != ''">
  39. AND op_create_user_id = #{opCreateUserId}
  40. </if>
  41. <if test="opUpdateTime != null">
  42. AND op_update_time = #{opUpdateTime}
  43. </if>
  44. <if test="opUpdateUserId != null and opUpdateUserId != ''">
  45. AND op_update_user_id = #{opUpdateUserId}
  46. </if>
  47. <if test="opAppCode != null and opAppCode != ''">
  48. AND op_app_code = #{opAppCode}
  49. </if>
  50. <if test="opTimestamp != null">
  51. AND op_timestamp = #{opTimestamp}
  52. </if>
  53. <if test="opDbUser != null and opDbUser != ''">
  54. AND op_db_user = #{opDbUser}
  55. </if>
  56. </where>
  57. </sql>
  58. <sql id="idsForeach">
  59. <!-- 根据主键roleId批量操作 -->
  60. WHERE role_id in
  61. <foreach collection="ids" index="index" item="item" separator="," open="(" close=")">
  62. #{item}
  63. </foreach>
  64. </sql>
  65. <!-- 查询表t_mst_role_sensitive,(条件查询+分页)列表 -->
  66. <select id="selectByCond" resultMap="BaseResultMap">
  67. SELECT
  68. <include refid="Base_Column_List"/>
  69. FROM dkic_b.t_mst_role_sensitive
  70. <include refid="Condition"/>
  71. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  72. limit #{end} offset #{start}
  73. </if>
  74. </select>
  75. <!-- 查询表t_mst_role_sensitive,(条件查询)个数 -->
  76. <select id="countByCond" resultType="Long">
  77. SELECT
  78. count(1)
  79. FROM dkic_b.t_mst_role_sensitive
  80. <include refid="Condition"/>
  81. </select>
  82. <!-- 获取角色敏感信息权限 -->
  83. <select id="getRoleSensitive" resultType="java.util.Map">
  84. SELECT
  85. tsi.item_code AS "itemCode",
  86. tsi.item_name_i18n ->> 'zh_CN' AS "itemName",
  87. CASE
  88. WHEN tsi.parent_code = '0' THEN NULL
  89. ELSE tsi.parent_code END AS "parentCode",
  90. tsi.display_no AS "displayNo",
  91. tsi.level_no AS "levelNo",
  92. tsi.level_code AS "levelCode",
  93. tmrs.role_id AS "roleId",
  94. CASE
  95. WHEN tmrs.role_id IS NULL THEN FALSE
  96. ELSE TRUE END AS "checked"
  97. FROM sys.t_sensitive_item tsi
  98. LEFT JOIN dkic_b.t_mst_role_sensitive tmrs
  99. ON tsi.item_code = tmrs.sen_item_code and tmrs.role_id = #{roleId}::uuid
  100. WHERE tsi.flg_valid
  101. <if test="searchText != null">
  102. AND (position(#{searchText} in tsi.item_name_i18n ->> 'zh_CN') > 0 OR position(#{searchText} in tsi.item_code) > 0 )
  103. </if>
  104. ORDER BY tsi.level_code;
  105. </select>
  106. <delete id="deleteRoleId" >
  107. DELETE FROM dkic_b.t_mst_role_sensitive tmrs WHERE tmrs.role_id = #{roleId}::uuid;
  108. </delete>
  109. <!-- 根据主键查询表t_mst_role_sensitive的一行数据 -->
  110. <select id="selectById" resultMap="BaseResultMap">
  111. SELECT
  112. <include refid="Base_Column_List"/>
  113. FROM dkic_b.t_mst_role_sensitive
  114. WHERE role_id = #{roleId}::uuid
  115. </select>
  116. <!-- 根据主键锁定表t_mst_role_sensitive的一行数据 -->
  117. <select id="selectByIdForUpdate" resultMap="BaseResultMap">
  118. SELECT
  119. <include refid="Base_Column_List"/>
  120. FROM dkic_b.t_mst_role_sensitive
  121. WHERE role_id = #{roleId}
  122. for update
  123. </select>
  124. <!-- 根据主键锁定表t_mst_role_sensitive的多行数据 -->
  125. <select id="selectByIdsForUpdate" resultMap="BaseResultMap">
  126. SELECT
  127. <include refid="Base_Column_List"/>
  128. FROM dkic_b.t_mst_role_sensitive
  129. <include refid="idsForeach"/>
  130. for update
  131. </select>
  132. <insert id="insertBatch">
  133. insert into dkic_b.t_mst_role_sensitive
  134. (
  135. <trim suffixOverrides=",">
  136. role_id,
  137. sen_item_code,
  138. flg_show,
  139. cp_id,
  140. op_app_code,
  141. </trim>
  142. )
  143. values
  144. <foreach collection="list" index="index" item="item" separator=",">
  145. (
  146. <trim suffixOverrides=",">
  147. #{item.roleId}::uuid,
  148. #{item.senItemCode},
  149. #{item.flgShow},
  150. #{item.cpId},
  151. #{item.opAppCode},
  152. </trim>
  153. )
  154. </foreach>
  155. </insert>
  156. </mapper>