PrivDao.xml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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="cn.com.goldenwater.dcproj.dao.PrivDao">
  4. <resultMap type="cn.com.goldenwater.dcproj.model.Priv" id="privResultMap">
  5. <result property="id" column="ID"/>
  6. <result property="flagLeaf" column="FLAG_LEAF"/>
  7. <result property="seq" column="SEQ"/>
  8. <result property="privType" column="PRIV_TYPE"/>
  9. <result property="privName" column="PRIV_NAME"/>
  10. <result property="ownerSystem" column="OWNER_SYSTEM"/>
  11. <result property="code" column="CODE"/>
  12. <result property="parentId" column="PARENT_ID"/>
  13. <result property="privUri" column="PRIV_URI"/>
  14. </resultMap>
  15. <resultMap type="cn.com.goldenwater.dcproj.dto.PrivDto" id="dtoPrivResultMap">
  16. <result property="id" column="ID"/>
  17. <result property="privName" column="PRIV_NAME"/>
  18. <result property="privType" column="PRIV_TYPE"/>
  19. <result property="privUri" column="PRIV_URI"/>
  20. <result property="parentId" column="PARENT_ID"/>
  21. <result property="parentName" column="PARENT_NAME"/>
  22. <result property="flagLeaf" column="FLAG_LEAF"/>
  23. <result property="flagLeafCn" column="FLAG_LEAF_CN"/>
  24. <result property="roleId" column="ROLE_ID"/>
  25. <result property="checked" column="CHECKED"/>
  26. <result property="ownerSystem" column="OWNER_SYSTEM"/>
  27. <result property="code" column="CODE"/>
  28. </resultMap>
  29. <sql id="table_columns">
  30. ID ,
  31. FLAG_LEAF ,
  32. SEQ ,
  33. PRIV_TYPE ,
  34. PRIV_NAME ,
  35. OWNER_SYSTEM ,
  36. CODE ,
  37. PARENT_ID ,
  38. PRIV_URI
  39. </sql>
  40. <sql id="table_columns2">
  41. ID ,
  42. FLAG_LEAF ,
  43. SEQ ,
  44. PRIV_TYPE ,
  45. PRIV_NAME ,
  46. OWNER_SYSTEM ,
  47. CODE ,
  48. PARENT_ID ,
  49. PRIV_URI
  50. </sql>
  51. <sql id="entity_properties">
  52. #{id},
  53. #{flagLeaf},
  54. #{seq},
  55. #{privType},
  56. #{privName},
  57. #{ownerSystem},
  58. #{code},
  59. #{parentId},
  60. #{privUri}
  61. </sql>
  62. <!-- 使用like用法:columnName like concat('%',#columnName#,'%') -->
  63. <sql id="page_where">
  64. <trim prefix="where" prefixOverrides="and | or ">
  65. <if test="id != null and id != ''">and ID = #{id}</if>
  66. <if test="flagLeaf != null and flagLeaf != ''">and FLAG_LEAF = #{flagLeaf}</if>
  67. <if test="seq != null">and SEQ = #{seq}</if>
  68. <if test="privType != null and privType != ''">and PRIV_TYPE = #{privType}</if>
  69. <if test="privName != null and privName != ''">and PRIV_NAME LIKE '%'||#{privName}||'%'</if>
  70. <if test="ownerSystem != null and ownerSystem != ''">and OWNER_SYSTEM = #{ownerSystem}</if>
  71. <if test="code != null and code != ''">and CODE = #{code}</if>
  72. <if test="parentId != null and parentId != ''">and PARENT_ID = #{parentId}</if>
  73. <if test="privUri != null and privUri != ''">and PRIV_URI = #{privUri}</if>
  74. </trim>
  75. </sql>
  76. <select id="get" resultMap="privResultMap" parameterType="String">
  77. select
  78. <include refid="table_columns"/>
  79. from GW_SYS_PRIV where ID = #{id}
  80. </select>
  81. <select id="getBy" resultMap="privResultMap">
  82. select
  83. <include refid="table_columns"/>
  84. from GW_SYS_PRIV
  85. <include refid="page_where"/>
  86. </select>
  87. <select id="findAll" resultMap="privResultMap">
  88. select
  89. <include refid="table_columns"/>
  90. from GW_SYS_PRIV
  91. </select>
  92. <select id="findList" resultMap="privResultMap">
  93. select
  94. <include refid="table_columns"/>
  95. from GW_SYS_PRIV
  96. <include refid="page_where"/>
  97. ORDER BY ID
  98. </select>
  99. <select id="selectCount" resultType="int">
  100. select count(ID) from GW_SYS_PRIV
  101. <include refid="page_where"/>
  102. </select>
  103. <insert id="insert" parameterType="cn.com.goldenwater.dcproj.model.Priv">
  104. insert into GW_SYS_PRIV(
  105. <include refid="table_columns2"/>
  106. )
  107. values (
  108. <include refid="entity_properties"/>
  109. )
  110. </insert>
  111. <delete id="delete" parameterType="java.lang.String">
  112. delete from GW_SYS_PRIV where ID = #{id}
  113. </delete>
  114. <delete id="deleteBy" parameterType="cn.com.goldenwater.dcproj.model.Priv">
  115. delete from GW_SYS_PRIV
  116. <include refid="page_where"/>
  117. </delete>
  118. <update id="deleteInFlag" parameterType="java.lang.String">
  119. update GW_SYS_PRIV set flag_valid = 0 where ID = #{id}
  120. </update>
  121. <update id="update" parameterType="cn.com.goldenwater.dcproj.model.Priv">
  122. update GW_SYS_PRIV
  123. <trim prefix="set" suffixOverrides=",">
  124. <if test="id != null and id != ''">ID = #{id},</if>
  125. <if test="flagLeaf != null and flagLeaf != ''">FLAG_LEAF = #{flagLeaf},</if>
  126. <if test="seq != null">SEQ = #{seq},</if>
  127. <if test="privType != null and privType != ''">PRIV_TYPE = #{privType},</if>
  128. <if test="privName != null and privName != ''">PRIV_NAME = #{privName},</if>
  129. <if test="ownerSystem != null and ownerSystem != ''">OWNER_SYSTEM = #{ownerSystem},</if>
  130. <if test="code != null and code != ''">CODE = #{code},</if>
  131. <if test="parentId != null and parentId != ''">PARENT_ID = #{parentId},</if>
  132. <if test="privUri != null and privUri != ''">PRIV_URI = #{privUri},</if>
  133. </trim>
  134. <where>ID = #{id}</where>
  135. </update>
  136. <!-- 其他自定义SQL -->
  137. <!-- 分页获取列表 -->
  138. <select id="findPageStatic" resultMap="dtoPrivResultMap" parameterType="cn.com.goldenwater.dcproj.param.PrivParam">
  139. select
  140. A.ID,A.PRIV_NAME,A.PARENT_ID,A.PRIV_URI,B.PRIV_NAME PARENT_NAME,A.PRIV_TYPE,A.FLAG_LEAF,
  141. CASE WHEN A.FLAG_LEAF='1' THEN '是' ELSE '否' END FLAG_LEAF_CN
  142. from GW_SYS_PRIV A
  143. LEFT JOIN GW_SYS_PRIV B ON A.PARENT_ID=B.ID
  144. where 1 = 1
  145. <if test="id != null and id != ''">and A.id = #{id}</if>
  146. <if test="privName != null and privName != ''">and A.priv_name like '%'||#{privName}||'%'</if>
  147. <if test="privType != null and privType != ''">and A.parent_type = #{privType}</if>
  148. <if test="privUri != null and privUri != ''">and A.priv_uri =#{privUri}</if>
  149. <if test="parentId != null and parentId != ''">and A.parent_id = #{parentId}</if>
  150. <if test="flagLeaf != null and flagLeaf != ''">and A.flagleaf=#{flagLeaf}</if>
  151. order by A.id desc
  152. </select>
  153. <!-- 根据角色id获取树 -->
  154. <select id="findTreeByRoleId" resultMap="dtoPrivResultMap" parameterType="String">
  155. select
  156. A.ID,
  157. A.PRIV_NAME,
  158. A.PRIV_TYPE,
  159. A.PRIV_URI,
  160. A.PARENT_ID,
  161. A.CODE,
  162. A.OWNER_SYSTEM,
  163. B.PRIV_NAME AS PARENT_NAME,
  164. A.FLAG_LEAF
  165. <if test="roleId != null and roleId != ''">
  166. ,B.ROLE_ID,
  167. CASE B.ROLE_ID WHEN #{roleId} THEN 1 ELSE 0 END CHECKED
  168. </if>
  169. FROM GW_SYS_PRIV A
  170. left JOIN GW_SYS_MENU M ON A.ID = M.PRIV_ID
  171. LEFT JOIN GW_SYS_PRIV B ON A.PARENT_ID=B.ID
  172. <if test="roleId != null and roleId != ''">
  173. LEFT JOIN (SELECT ROLE_ID,PRIV_ID FROM GW_SYS_REL_ROLE_PRIV WHERE ROLE_ID=#{roleId}) B ON B.PRIV_ID=A.ID
  174. </if>
  175. WHERE 1=1
  176. <if test="persId != null and persId!=''">
  177. AND A.ID IN
  178. (select distinct priv_id
  179. from gw_sys_rel_role_priv t
  180. where role_id in
  181. (select role_id from gw_sys_rel_user_role where user_id in (#{persId}))
  182. )
  183. </if>
  184. <if test="list != null and list.size()>0">
  185. AND A.OWNER_SYSTEM IN
  186. <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
  187. #{item}
  188. </foreach>
  189. </if>
  190. <if test="name != null and name!=''">
  191. AND A.PRIV_NAME LIKE '%'||#{name}||'%'
  192. </if>
  193. ORDER BY M.OWN_APP, TO_NUMBER(A.SEQ)
  194. </select>
  195. <select id="findFirstLevelTree" resultMap="privResultMap" parameterType="String">
  196. select
  197. <include refid="table_columns"/>
  198. FROM GW_SYS_PRIV
  199. <where>
  200. <if test="list != null and list.size()>0">
  201. AND A.OWNER_SYSTEM IN
  202. <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
  203. #{item}
  204. </foreach>
  205. </if>
  206. <choose>
  207. <when test="name != null and name!=''">
  208. AND A.PRIV_NAME LIKE '%'||#{name}||'%'
  209. </when>
  210. <otherwise>
  211. and PARENT_ID = '0'
  212. </otherwise>
  213. </choose>
  214. </where>
  215. ORDER BY ID, SEQ
  216. </select>
  217. <select id="getListByUserId" resultType="cn.com.goldenwater.dcproj.dto.PrivSysDto" parameterType="string">
  218. select DISTINCT C.ID,C.PRIV_NAME,D.DICT_DESC
  219. PRIV_TYPE,C.PRIV_URI,C.PARENT_ID,C.FLAG_LEAF,C.CODE,C.SEQ,C.OWNER_SYSTEM
  220. from GW_SYS_REL_USER_ROLE A LEFT JOIN GW_SYS_REL_ROLE_PRIV B ON A.ROLE_ID=B.ROLE_ID LEFT JOIN GW_SYS_PRIV C ON
  221. B.PRIV_ID=C.ID LEFT JOIN GW_COM_DICT D ON C.PRIV_TYPE=D.DICT_CD
  222. WHERE A.USER_ID=#{userId}
  223. <!--<if test="ownerSystem != null and ownerSystem != ''">-->
  224. <!--AND C.OWNER_SYSTEM=#{ownerSystem}-->
  225. <!--</if>-->
  226. ORDER BY C.SEQ
  227. </select>
  228. <select id="getPriViewListByUserId" resultType="cn.com.goldenwater.dcproj.dto.PrivSysDto" parameterType="string">
  229. select DISTINCT C.ID,C.PRIV_NAME,D.DICT_DESC
  230. PRIV_TYPE,C.PRIV_URI,C.PARENT_ID,C.FLAG_LEAF,C.CODE,C.SEQ,C.OWNER_SYSTEM
  231. from GW_SYS_REL_USER_ROLE A left join gw_sys_role r on A.Role_Id=r.id LEFT JOIN GW_SYS_REL_ROLE_PRIV B
  232. ON A.ROLE_ID=B.ROLE_ID LEFT JOIN GW_SYS_PRIV C ON
  233. B.PRIV_ID=C.ID LEFT JOIN GW_COM_DICT D ON C.PRIV_TYPE=D.DICT_CD
  234. WHERE A.USER_ID=#{userId} and c.priv_name like '%${privName}%'
  235. <if test="orgId !='' and orgId !=null">
  236. and r.org_id=#{orgId}
  237. </if>
  238. ORDER BY C.SEQ
  239. </select>
  240. <select id="selectMaxSeqByParentId" resultType="java.lang.Long" parameterType="string">
  241. SELECT MAX(SEQ) SEQ FROM GW_SYS_PRIV WHERE PARENT_ID=#{parentId}
  242. </select>
  243. </mapper>