StaffRightMapper.xml 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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.StaffRightMapper">
  4. <!-- 通用设置 -->
  5. <!-- 通用查询列 -->
  6. <sql id="Base_Column_List">
  7. staff_id
  8. , fun_uuid, right_type, 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.StaffRight">
  12. <id column="staff_id" property="staffId"/>
  13. <result column="fun_uuid" property="funUuid" typeHandler="UuidTypeHandler"/>
  14. <result column="right_type" property="rightType"/>
  15. <result column="cp_id" property="cpId"/>
  16. <result column="op_create_time" property="opCreateTime" typeHandler="TimestampTypeHandler"/>
  17. <result column="op_create_user_id" property="opCreateUserId" typeHandler="UuidTypeHandler"/>
  18. <result column="op_update_time" property="opUpdateTime" typeHandler="TimestampTypeHandler"/>
  19. <result column="op_update_user_id" property="opUpdateUserId" typeHandler="UuidTypeHandler"/>
  20. <result column="op_app_code" property="opAppCode"/>
  21. <result column="op_timestamp" property="opTimestamp" typeHandler="TimestampTypeHandler"/>
  22. <result column="op_db_user" property="opDbUser"/>
  23. </resultMap>
  24. <!-- 通用条件列 -->
  25. <sql id="Condition">
  26. <where>
  27. <if test="funUuid != null and funUuid != ''">
  28. AND fun_uuid = #{funUuid}
  29. </if>
  30. <if test="rightType != null">
  31. AND right_type = #{rightType}
  32. </if>
  33. <if test="cpId != null">
  34. AND cp_id = #{cpId}
  35. </if>
  36. <if test="opCreateTime != null">
  37. AND op_create_time = #{opCreateTime}
  38. </if>
  39. <if test="opCreateUserId != null and opCreateUserId != ''">
  40. AND op_create_user_id = #{opCreateUserId}
  41. </if>
  42. <if test="opUpdateTime != null">
  43. AND op_update_time = #{opUpdateTime}
  44. </if>
  45. <if test="opUpdateUserId != null and opUpdateUserId != ''">
  46. AND op_update_user_id = #{opUpdateUserId}
  47. </if>
  48. <if test="opAppCode != null and opAppCode != ''">
  49. AND op_app_code = #{opAppCode}
  50. </if>
  51. <if test="opTimestamp != null">
  52. AND op_timestamp = #{opTimestamp}
  53. </if>
  54. <if test="opDbUser != null and opDbUser != ''">
  55. AND op_db_user = #{opDbUser}
  56. </if>
  57. </where>
  58. </sql>
  59. <sql id="idsForeach">
  60. <!-- 根据主键staffId批量操作 -->
  61. WHERE staff_id in
  62. <foreach collection="ids" index="index" item="item" separator="," open="(" close=")">
  63. #{item}
  64. </foreach>
  65. </sql>
  66. <!-- 查询表t_mst_staff_right,(条件查询+分页)列表 -->
  67. <select id="selectByCond" resultMap="BaseResultMap">
  68. SELECT
  69. <include refid="Base_Column_List"/>
  70. FROM t_mst_staff_right
  71. <include refid="Condition"/>
  72. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  73. limit #{end} offset #{start}
  74. </if>
  75. </select>
  76. <!-- 查询表t_mst_staff_right,(条件查询)个数 -->
  77. <select id="countByCond" resultType="Long">
  78. SELECT
  79. count(1)
  80. FROM t_mst_staff_right
  81. <include refid="Condition"/>
  82. </select>
  83. <!-- 根据主键查询表t_mst_staff_right的一行数据 -->
  84. <select id="selectById" resultMap="BaseResultMap">
  85. SELECT
  86. <include refid="Base_Column_List"/>
  87. FROM t_mst_staff_right
  88. WHERE staff_id = #{staffId}::uuid
  89. </select>
  90. <!-- 根据主键锁定表t_mst_staff_right的一行数据 -->
  91. <select id="selectByIdForUpdate" resultMap="BaseResultMap">
  92. SELECT
  93. <include refid="Base_Column_List"/>
  94. FROM t_mst_staff_right
  95. WHERE staff_id = #{staffId}
  96. for update
  97. </select>
  98. <!-- 根据主键锁定表t_mst_staff_right的多行数据 -->
  99. <select id="selectByIdsForUpdate" resultMap="BaseResultMap">
  100. SELECT
  101. <include refid="Base_Column_List"/>
  102. FROM t_mst_staff_right
  103. <include refid="idsForeach"/>
  104. for update
  105. </select>
  106. <insert id="insertBatch">
  107. insert into t_mst_staff_right
  108. (
  109. <trim suffixOverrides=",">
  110. fun_uuid,
  111. right_type,
  112. cp_id,
  113. staff_id,
  114. </trim>
  115. )
  116. values
  117. <foreach collection="list" index="index" item="item" separator=",">
  118. (
  119. <trim suffixOverrides=",">
  120. #{item.funUuid}::uuid,
  121. #{item.rightType},
  122. #{item.cpId},
  123. #{item.staffId}::uuid,
  124. </trim>
  125. )
  126. </foreach>
  127. </insert>
  128. <!-- 删除功能权限 -->
  129. <delete id="deleteById" >
  130. DELETE FROM dkic_b.t_mst_staff_right WHERE staff_id = #{staffId}::uuid;
  131. </delete>
  132. <!-- 获取功能权限 -->
  133. <select id="getStaffRight" resultType="java.util.Map">
  134. SELECT menu.menu_uuid AS "menuUuid",
  135. menu.menu_uuid AS "id",
  136. menu.menu_name AS "menuName",
  137. menu.app_code AS "appCode",
  138. menu.parent_uuid AS "parentId",
  139. menu.flg_menu AS "flgMenu",
  140. staffRight.staff_id AS "staffId",
  141. menu.fun_uuid AS "funUuid",
  142. CASE WHEN staffRight.staff_id IS NULL THEN FALSE ELSE TRUE END AS "checked"
  143. FROM sys.t_app_menu menu
  144. inner JOIN dkic_b.t_mst_role_fun roleFun ON menu.fun_uuid = roleFun.fun_uuid and roleFun.role_id::uuid = any ( (
  145. select role_ids from dkic_b.t_mst_staff where staff_id = #{staffId}::uuid)::uuid[])
  146. left JOIN dkic_b.t_mst_staff_right staffRight ON menu.fun_uuid = staffRight.fun_uuid and staffRight.staff_id = #{staffId}::uuid
  147. WHERE menu.flg_valid
  148. AND menu.flg_right
  149. AND menu.object_code != 'home'
  150. ORDER BY menu.level_code;
  151. </select>
  152. <!-- WEB获取功能权限 -->
  153. <select id="getStaffRightWeb" resultType="java.util.Map">
  154. SELECT menu.menu_uuid AS "menuUuid",
  155. menu.menu_uuid AS "id",
  156. menu.menu_name AS "menuName",
  157. menu.app_code AS "appCode",
  158. menu.parent_uuid AS "parentId",
  159. menu.flg_menu AS "flgMenu",
  160. staffRight.staff_id AS "staffId",
  161. menu.fun_uuid AS "funUuid",
  162. CASE WHEN staffRight.staff_id IS NULL THEN FALSE ELSE TRUE END AS "checked"
  163. FROM sys.t_app_menu menu
  164. left JOIN dkic_b.t_mst_role_fun roleFun ON menu.fun_uuid = roleFun.fun_uuid and roleFun.role_id::uuid = any ( (
  165. select role_ids from dkic_b.t_mst_staff where staff_id = #{staffId}::uuid)::uuid[])
  166. left JOIN dkic_b.t_mst_staff_right staffRight ON menu.fun_uuid = staffRight.fun_uuid and staffRight.staff_id = #{staffId}::uuid
  167. WHERE menu.flg_valid
  168. AND menu.flg_right
  169. AND menu.object_code != 'home'
  170. ORDER BY menu.level_code;
  171. </select>
  172. </mapper>