PrivilegeDAOImplMapper.xml 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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="privilegeDAOImpl">
  6. <select id="queryUserDefaultPrivilege" parameterType="map" resultType="map">
  7. SELECT a.`p_id` pId,a.`privilege_flag` privilegeFlag,a.`user_id` userId FROM p_privilege_user a WHERE a.`p_id` =
  8. #{pId}
  9. AND a.`user_id` = #{userId}
  10. AND a.`privilege_flag` = '1'
  11. AND a.`status_cd` = '0'
  12. </select>
  13. <!-- 保存属性信息 c_business_attrs -->
  14. <insert id="saveUserDefaultPrivilege" parameterType="Map">
  15. <![CDATA[
  16. INSERT INTO p_privilege_user(p_id,privilege_flag,user_id,store_id) VALUES(#{pId},'1',#{userId},#{storeId})
  17. ]]>
  18. </insert>
  19. <!-- 删除用户所有权限-->
  20. <update id="deleteUserAllPrivilege" parameterType="Map">
  21. UPDATE p_privilege_user a SET a.`status_cd` = '1' WHERE a.`user_id` = #{userId}
  22. </update>
  23. <insert id="savePrivilegeGroup" parameterType="map">
  24. INSERT INTO p_privilege_group(pg_id,`name`,description,store_id,domain)
  25. VALUES(#{pgId},#{name},#{description},#{storeId},#{storeTypeCd})
  26. </insert>
  27. <update id="updatePrivilegeGroup" parameterType="Map">
  28. UPDATE p_privilege_group a SET
  29. <if test="name != null and name != ''">
  30. a.name = #{name},
  31. </if>
  32. <if test="description != null and description != ''">
  33. a.description = #{description}
  34. </if>
  35. WHERE 1= 1
  36. <if test="storeId != null and storeId != ''">
  37. and a.store_id = #{storeId}
  38. </if>
  39. and a.pg_id = #{pgId}
  40. <if test="storeTypeCd != null and storeTypeCd != ''">
  41. and a.domain= #{storeTypeCd}
  42. </if>
  43. </update>
  44. <!-- 删除权限组 -->
  45. <update id="deletePrivilegeGroup" parameterType="Map">
  46. UPDATE p_privilege_group a SET a.`status_cd` = '1'
  47. WHERE 1= 1
  48. <if test="storeId != null and storeId != ''">
  49. and a.store_id = #{storeId}
  50. </if>
  51. and a.pg_id = #{pgId}
  52. <if test="storeTypeCd != null and storeTypeCd != ''">
  53. and a.domain= #{storeTypeCd}
  54. </if>
  55. </update>
  56. <!-- 删除权限组 -->
  57. <update id="deletePrivilegeRel" parameterType="Map">
  58. UPDATE p_privilege_rel a SET a.`status_cd` = '1'
  59. WHERE 1=1
  60. <if test="pgId != null and pgId != ''">
  61. and a.`pg_id` = #{pgId}
  62. </if>
  63. <if test="pId != null and pId != ''">
  64. and a.`p_id` = #{pId}
  65. </if>
  66. </update>
  67. <select id="queryPrivilegeRel" parameterType="Map" resultType="Map">
  68. SELECT
  69. pp.`name`,
  70. pp.`domain`,
  71. pp.`p_id` pId,
  72. pp.`description`,
  73. pp.`create_time` createTime
  74. FROM
  75. p_privilege pp,
  76. p_privilege_rel ppr
  77. WHERE ppr.`p_id` = pp.`p_id`
  78. AND ppr.`status_cd` = '0'
  79. AND pp.`status_cd` = '0'
  80. AND ppr.`pg_id` = #{pgId}
  81. </select>
  82. <select id="queryPrivilegeGroup" parameterType="Map" resultType="Map">
  83. select ppg.pg_id pgId,ppg.name,ppg.description,ppg.create_time createTime,ppg.store_id storeId,ppg.domain
  84. from p_privilege_group ppg
  85. where 1=1
  86. <if test="pgId !=null and pgId !=''">
  87. and ppg.pg_id = #{pgId}
  88. </if>
  89. <if test="storeId != null and storeId != ''">
  90. and ppg.store_id = #{storeId}
  91. </if>
  92. <if test="storeTypeCd != null and storeTypeCd != ''">
  93. and ppg.domain = #{storeTypeCd}
  94. </if>
  95. and ppg.status_cd = '0'
  96. </select>
  97. <insert id="addPrivilegeRel" parameterType="Map">
  98. insert into p_privilege_rel(p_id,pg_id)
  99. values(#{pId},#{pgId})
  100. </insert>
  101. <!-- 查询权限 -->
  102. <select id="queryPrivilege" parameterType="Map" resultType="Map">
  103. SELECT
  104. pp.`p_id` pId,pp.`name`,pp.`description`,pp.`create_time` createTime,pp.`domain`
  105. FROM p_privilege pp
  106. WHERE 1= 1
  107. <if test="pId != null and pId != ''">
  108. and pp.p_id = #{pId}
  109. </if>
  110. <if test="pId != null and pId != ''">
  111. AND pp.domain = '800900000003'
  112. </if>
  113. AND pp.`status_cd` = '0'
  114. </select>
  115. <!-- 查询用户权限 -->
  116. <select id="queryUserPrivilege" parameterType="Map" resultType="Map">
  117. SELECT
  118. ppu.`pu_id` puId,
  119. ppu.`p_id` pId,
  120. ppu.`privilege_flag` privilegeFlag,
  121. ppu.`user_id` userId
  122. FROM
  123. p_privilege_user ppu
  124. WHERE 1 = 1
  125. <if test="privilegeFlag != null and privilegeFlag != ''">
  126. AND ppu.`privilege_flag` = #{privilegeFlag}
  127. </if>
  128. <if test="pId != null and pId != ''">
  129. AND ppu.`p_id` = #{pId}
  130. </if>
  131. <if test="userId != null and userId != ''">
  132. AND ppu.`user_id` = #{userId}
  133. </if>
  134. AND ppu.`status_cd` = '0'
  135. </select>
  136. <!-- 保存属性信息 c_business_attrs -->
  137. <insert id="addUserPrivilege" parameterType="Map">
  138. <![CDATA[
  139. INSERT INTO p_privilege_user(p_id,privilege_flag,user_id,store_id) VALUES(#{pId},#{privilegeFlag},#{userId},#{storeId})
  140. ]]>
  141. </insert>
  142. <!-- 删除权限组 -->
  143. <update id="deleteUserPrivilege" parameterType="Map">
  144. update p_privilege_user ppu set ppu.status_cd = '1'
  145. where 1=1
  146. <if test="pId != null and pId != ''">
  147. and ppu.p_id= #{pId}
  148. </if>
  149. <if test="privilegeFlag != null and privilegeFlag != ''">
  150. and ppu.privilege_flag = #{privilegeFlag}
  151. </if>
  152. <if test="userId != null and userId != ''">
  153. and ppu.user_id = #{userId}
  154. </if>
  155. and ppu.status_cd = '0'
  156. </update>
  157. <select id="queryPrivilegeUsers" parameterType="map" resultType="map">
  158. select t.user_id userId
  159. from p_privilege_user t
  160. INNER JOIN p_privilege p on t.p_id = p.p_id and p.status_cd = '0'
  161. where t.privilege_flag = '0'
  162. and t.status_cd = '0'
  163. and p.resource = #{resource}
  164. and t.store_id = #{storeId}
  165. union ALL
  166. select t.user_id userId
  167. from p_privilege_user t
  168. inner join p_privilege_group pg on t.p_id = pg.pg_id and pg.status_cd = '0' and pg.pg_id != '600201904002'
  169. inner join p_privilege_rel pr on pg.pg_id = pr.pg_id and pr.status_cd ='0'
  170. INNER JOIN p_privilege p on pr.p_id = p.p_id and p.status_cd = '0'
  171. where t.status_cd = '0'
  172. and t.privilege_flag = '1'
  173. and p.resource = #{resource}
  174. and t.store_id = #{storeId}
  175. </select>
  176. </mapper>