StaffPurviewMapper.xml 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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.StaffPurviewMapper">
  4. <!-- 通用设置 -->
  5. <!-- 通用查询列 -->
  6. <sql id="Base_Column_List">
  7. staff_id
  8. , purview_code, flg_nolimit, data_ids, cp_id, op_create_time, op_create_user_id, op_update_time, op_update_user_id, op_app_code, op_timestamp, op_db_user
  9. </sql>
  10. <!-- 通用查询映射结果 -->
  11. <resultMap id="BaseResultMap" type="com.dk.mdm.model.pojo.mst.StaffPurview">
  12. <id column="staff_id" property="staffId"/>
  13. <result column="purview_code" property="purviewCode"/>
  14. <result column="flg_nolimit" property="flgNolimit"/>
  15. <result column="data_ids" property="dataIds" typeHandler="UuidListTypeHandler"/>
  16. <result column="cp_id" property="cpId"/>
  17. <result column="op_create_time" property="opCreateTime" typeHandler="TimestampTypeHandler"/>
  18. <result column="op_create_user_id" property="opCreateUserId" typeHandler="UuidTypeHandler"/>
  19. <result column="op_update_time" property="opUpdateTime" typeHandler="TimestampTypeHandler"/>
  20. <result column="op_update_user_id" property="opUpdateUserId" typeHandler="UuidTypeHandler"/>
  21. <result column="op_app_code" property="opAppCode"/>
  22. <result column="op_timestamp" property="opTimestamp" typeHandler="TimestampTypeHandler"/>
  23. <result column="op_db_user" property="opDbUser"/>
  24. </resultMap>
  25. <!-- 通用条件列 -->
  26. <sql id="Condition">
  27. <where>
  28. <if test="purviewCode != null and purviewCode != ''">
  29. AND purview_code = #{purviewCode}
  30. </if>
  31. <if test="flgNolimit != null">
  32. AND flg_nolimit = #{flgNolimit}
  33. </if>
  34. <if test="dataIds != null and dataIds != ''">
  35. AND data_ids = #{dataIds}
  36. </if>
  37. <if test="cpId != null">
  38. AND cp_id = #{cpId}
  39. </if>
  40. <if test="opCreateTime != null">
  41. AND op_create_time = #{opCreateTime}
  42. </if>
  43. <if test="opCreateUserId != null and opCreateUserId != ''">
  44. AND op_create_user_id = #{opCreateUserId}
  45. </if>
  46. <if test="opUpdateTime != null">
  47. AND op_update_time = #{opUpdateTime}
  48. </if>
  49. <if test="opUpdateUserId != null and opUpdateUserId != ''">
  50. AND op_update_user_id = #{opUpdateUserId}
  51. </if>
  52. <if test="opAppCode != null and opAppCode != ''">
  53. AND op_app_code = #{opAppCode}
  54. </if>
  55. <if test="opTimestamp != null">
  56. AND op_timestamp = #{opTimestamp}
  57. </if>
  58. <if test="opDbUser != null and opDbUser != ''">
  59. AND op_db_user = #{opDbUser}
  60. </if>
  61. </where>
  62. </sql>
  63. <sql id="idsForeach">
  64. <!-- 根据主键staffId批量操作 -->
  65. WHERE staff_id in
  66. <foreach collection="ids" index="index" item="item" separator="," open="(" close=")">
  67. #{item}
  68. </foreach>
  69. </sql>
  70. <!-- 查询表t_mst_staff_purview,(条件查询+分页)列表 -->
  71. <select id="selectByCond" resultMap="BaseResultMap">
  72. SELECT
  73. <include refid="Base_Column_List"/>
  74. FROM t_mst_staff_purview
  75. <include refid="Condition"/>
  76. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  77. limit #{end} offset #{start}
  78. </if>
  79. </select>
  80. <!-- 查询表t_mst_staff_purview,(条件查询)个数 -->
  81. <select id="countByCond" resultType="Long">
  82. SELECT
  83. count(1)
  84. FROM t_mst_staff_purview
  85. <include refid="Condition"/>
  86. </select>
  87. <!-- 根据主键查询表t_mst_staff_purview的一行数据 -->
  88. <select id="selectById" resultMap="BaseResultMap">
  89. SELECT
  90. <include refid="Base_Column_List"/>
  91. FROM t_mst_staff_purview
  92. WHERE staff_id = #{staffId}::uuid
  93. </select>
  94. <!-- 根据主键锁定表t_mst_staff_purview的一行数据 -->
  95. <select id="selectByIdForUpdate" resultMap="BaseResultMap">
  96. SELECT
  97. <include refid="Base_Column_List"/>
  98. FROM t_mst_staff_purview
  99. WHERE staff_id = #{staffId}
  100. for update
  101. </select>
  102. <!-- 根据主键锁定表t_mst_staff_purview的多行数据 -->
  103. <select id="selectByIdsForUpdate" resultMap="BaseResultMap">
  104. SELECT
  105. <include refid="Base_Column_List"/>
  106. FROM t_mst_staff_purview
  107. <include refid="idsForeach"/>
  108. for update
  109. </select>
  110. <insert id="insertBatch">
  111. insert into t_mst_staff_purview
  112. (
  113. <trim suffixOverrides=",">
  114. purview_code,
  115. flg_nolimit,
  116. data_ids,
  117. cp_id,
  118. </trim>
  119. )
  120. values
  121. <foreach collection="list" index="index" item="item" separator=",">
  122. (
  123. <trim suffixOverrides=",">
  124. #{item.purviewCode},
  125. #{item.flgNolimit},
  126. #{item.dataIds},
  127. #{item.cpId},
  128. </trim>
  129. )
  130. </foreach>
  131. </insert>
  132. <!-- 获取范围权限 -->
  133. <select id="getStaffPurview" resultType="java.util.Map">
  134. SELECT org.org_id AS "id",
  135. org.org_name AS "orgName",
  136. org.parent_id AS "parentId",
  137. orgb.org_id AS "orgId",
  138. org.level_no AS "levelNo",
  139. org.level_code as "levelCode",
  140. CASE WHEN orgb.org_id IS NULL THEN FALSE ELSE TRUE END AS "checked"
  141. FROM dkic_b.t_mst_org org
  142. left JOIN dkic_b.t_mst_org orgb ON orgb.org_id = org.org_id and org.org_id::uuid = any ( (
  143. select data_ids from dkic_b.t_mst_staff_purview where staff_id = #{staffId}::uuid)::uuid[])
  144. WHERE org.flg_valid
  145. AND org.cp_id = #{cpId}
  146. ORDER BY org.level_code;
  147. </select>
  148. <!-- 批量插入 -->
  149. <insert id="insertOrUpdateCondition">
  150. insert into t_mst_staff_purview
  151. (
  152. <trim suffixOverrides=",">
  153. staff_id,
  154. purview_code,
  155. flg_nolimit,
  156. data_ids,
  157. cp_id,
  158. </trim>
  159. )
  160. values
  161. <foreach collection="list" index="index" item="item" separator=",">
  162. (
  163. <trim suffixOverrides=",">
  164. #{item.staffId}::uuid,
  165. #{item.purviewCode},
  166. #{item.flgNolimit},
  167. #{item.dataIds, typeHandler=UuidListTypeHandler},
  168. #{item.cpId},
  169. </trim>
  170. )
  171. </foreach>
  172. on conflict (staff_id,purview_code) do update set
  173. flg_nolimit = excluded."flg_nolimit",
  174. data_ids = excluded."data_ids";
  175. </insert>
  176. </mapper>