RoleDao.xml 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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.RoleDao">
  4. <resultMap type="cn.com.goldenwater.dcproj.model.Role" id="roleResultMap">
  5. <result property="id" column="ID"/>
  6. <result property="ofcId" column="OFC_ID"/>
  7. <result property="roleName" column="ROLE_NAME"/>
  8. <result property="flagValid" column="FLAG_VALID"/>
  9. <result property="dataScope" column="DATA_SCOPE"/>
  10. <result property="ownerSystem" column="OWNER_SYSTEM"/>
  11. <result property="orgId" column="ORG_ID"/>
  12. <result property="persType" column="PERS_TYPE"/>
  13. </resultMap>
  14. <resultMap type="cn.com.goldenwater.dcproj.dto.RoleDto" id="dtoRoleResultMap">
  15. <result property="id" column="ID"/>
  16. <result property="ofcId" column="OFC_ID"/>
  17. <result property="ofcName" column="OFC_NAME"/>
  18. <result property="roleName" column="ROLE_NAME"/>
  19. <result property="flagValid" column="FLAG_VALID"/>
  20. <result property="dataScope" column="DATA_SCOPE"/>
  21. <result property="isCurrentUser" column="IS_CURRENT_USER"/>
  22. <result property="ownerSystem" column="OWNER_SYSTEM"/>
  23. <result property="orgId" column="ORG_ID"/>
  24. <result property="persType" column="PERS_TYPE"/>
  25. </resultMap>
  26. <sql id="table_columns">
  27. ID,
  28. ROLE_NAME,
  29. OFC_ID,
  30. OWNER_SYSTEM,
  31. FLAG_VALID,
  32. DATA_SCOPE,
  33. ORG_ID,
  34. PERS_TYPE
  35. </sql>
  36. <sql id="table_columns2">
  37. ID ,
  38. ROLE_NAME ,
  39. OFC_ID ,
  40. OWNER_SYSTEM ,
  41. FLAG_VALID ,
  42. DATA_SCOPE,
  43. ORG_ID,
  44. PERS_TYPE
  45. </sql>
  46. <sql id="entity_properties">
  47. #{id},
  48. #{roleName},
  49. #{ofcId},
  50. #{ownerSystem},
  51. #{flagValid},
  52. #{dataScope},
  53. #{orgId},
  54. #{persType}
  55. </sql>
  56. <!-- 使用like用法:columnName like concat('%',#columnName#,'%') -->
  57. <sql id="page_where">
  58. <trim prefix="where" prefixOverrides="and | or ">
  59. <if test="id != null and id != ''">and ID = #{id}</if>
  60. <if test="persType != null and persType != ''">and PERS_TYPE IN (${persType})</if>
  61. <if test="roleName != null and roleName != ''">and ROLE_NAME LIKE '%'||#{roleName}||'%'</if>
  62. <if test="ofcId != null and ofcId != ''">and OFC_ID = #{ofcId}</if>
  63. <if test="ownerSystem != null and ownerSystem != ''">and OWNER_SYSTEM = #{ownerSystem}</if>
  64. <if test="flagValid != null and flagValid != ''">and FLAG_VALID = #{flagValid}</if>
  65. <if test="dataScope != null and dataScope != ''">and DATA_SCOPE = #{dataScope}</if>
  66. <if test="orgId != null and orgId != ''">and ORG_ID = #{orgId}</if>
  67. </trim>
  68. </sql>
  69. <select id="get" resultMap="roleResultMap" parameterType="String">
  70. select
  71. <include refid="table_columns"/>
  72. from GW_SYS_ROLE where ID = #{id}
  73. </select>
  74. <select id="getone" parameterType="String" resultMap="roleResultMap">
  75. select
  76. <include refid="table_columns"/>
  77. from GW_SYS_ROLE where role_name=#{roleName}
  78. <choose>
  79. <when test="ofcId !=null and ofcId !=''">
  80. and ofc_id=#{ofcId}
  81. </when>
  82. <otherwise>
  83. and ofc_id is null
  84. </otherwise>
  85. </choose>
  86. </select>
  87. <select id="getBy" resultMap="roleResultMap">
  88. select
  89. <include refid="table_columns"/>
  90. from GW_SYS_ROLE
  91. <include refid="page_where"/>
  92. </select>
  93. <select id="findAll" resultMap="roleResultMap">
  94. select
  95. <include refid="table_columns"/>
  96. from GW_SYS_ROLE
  97. </select>
  98. <select id="findList" resultMap="roleResultMap">
  99. select
  100. <include refid="table_columns"/>
  101. from GW_SYS_ROLE
  102. <include refid="page_where"/>
  103. ORDER BY ID
  104. </select>
  105. <select id="selectCount" resultType="int">
  106. select count(ID) from GW_SYS_ROLE
  107. <include refid="page_where"/>
  108. </select>
  109. <insert id="insert" parameterType="cn.com.goldenwater.dcproj.model.Role">
  110. insert into GW_SYS_ROLE(
  111. <include refid="table_columns2"/>
  112. )
  113. values (
  114. <include refid="entity_properties"/>
  115. )
  116. </insert>
  117. <delete id="delete" parameterType="java.lang.String">
  118. delete from GW_SYS_ROLE where ID = #{id}
  119. </delete>
  120. <delete id="deleteBy" parameterType="cn.com.goldenwater.dcproj.model.Role">
  121. delete from GW_SYS_ROLE
  122. <include refid="page_where"/>
  123. </delete>
  124. <update id="deleteInFlag" parameterType="java.lang.String">
  125. update GW_SYS_ROLE set flag_valid = 0 where ID = #{id}
  126. </update>
  127. <update id="update" parameterType="cn.com.goldenwater.dcproj.model.Role">
  128. update GW_SYS_ROLE
  129. <trim prefix="set" suffixOverrides=",">
  130. <if test="id != null and id != ''">ID = #{id},</if>
  131. <if test="persType != null and persType != ''">PERS_TYPE = #{persType},</if>
  132. <if test="roleName != null and roleName != ''">ROLE_NAME = #{roleName},</if>
  133. <if test="ofcId != null and ofcId != ''">OFC_ID = #{ofcId},</if>
  134. <if test="ownerSystem != null and ownerSystem != ''">OWNER_SYSTEM = #{ownerSystem},</if>
  135. <if test="flagValid != null and flagValid != ''">FLAG_VALID = #{flagValid},</if>
  136. <if test="dataScope != null and dataScope != ''">DATA_SCOPE = #{dataScope},</if>
  137. <if test="orgId != null and orgId != ''">ORG_ID = #{orgId},</if>
  138. </trim>
  139. <where>ID = #{id}</where>
  140. </update>
  141. <!-- 根据用户id获取角色列表 -->
  142. <select id="getRoleByUserId" parameterType="String" resultMap="dtoRoleResultMap">
  143. SELECT
  144. B.ID,B.OFC_ID,B.ROLE_NAME,B.FLAG_VALID,B.DATA_SCOPE,B.OWNER_SYSTEM, B.PERS_TYPE,
  145. CASE A.USER_ID WHEN #{userId} THEN 1 ELSE 0 END IS_CURRENT_USER
  146. FROM
  147. (SELECT * FROM GW_SYS_REL_USER_ROLE where user_id=#{userId}) A
  148. RIGHT JOIN
  149. GW_SYS_ROLE B ON A.ROLE_ID=B.ID
  150. WHERE
  151. B.FLAG_VALID='1'
  152. <if test="list != null and list.size()>0">
  153. AND B.OWNER_SYSTEM IN
  154. <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
  155. #{item}
  156. </foreach>
  157. </if>
  158. <include refid="choseSql"/>
  159. <if test="name != null and name!=''">
  160. AND B.ROLE_NAME LIKE '%'||#{name}||'%'
  161. </if>
  162. <!--湖南的加判断,行政区长度未4代表是市级,市级追加角色id,县级追加角色id-->
  163. <if test="province != null and province!=''">
  164. <if test="province.substring(0,2)=='43'">
  165. <if test="province.length()==4">
  166. or b.id ='17b940e607b849f19b5b5a02831cd1eb' or b.id ='41c478fac0a64d9ea17d08cb598b1d40'
  167. </if>
  168. <if test="province.length()==6">
  169. or b.id ='41c478fac0a64d9ea17d08cb598b1d40'
  170. </if>
  171. </if>
  172. </if>
  173. <!--湖南的加判断,行政区长度未4代表是市级,市级追加角色id,县级追加角色id-->
  174. <if test="province != null and province!=''">
  175. <if test="province.substring(0,2)=='51'">
  176. <if test="province.length()==4">
  177. or b.id ='9138a4e7ae68415da39e602c0a9b3793' or b.id ='383c1793308b4a9f9c9f22bae755d1d4'
  178. </if>
  179. <if test="province.length()==6">
  180. or b.id ='383c1793308b4a9f9c9f22bae755d1d4'
  181. </if>
  182. </if>
  183. </if>
  184. ORDER BY B.ID
  185. </select>
  186. <sql id="choseSql">
  187. <choose>
  188. <when test="orgId !=null and orgId !=''">
  189. and B.ofc_id = #{orgId}
  190. </when>
  191. <otherwise>
  192. and B.ofc_id is null
  193. </otherwise>
  194. </choose>
  195. </sql>
  196. <!-- 分页获取角色列表 -->
  197. <select id="findPageDto" parameterType="cn.com.goldenwater.dcproj.param.RoleParam" resultMap="dtoRoleResultMap">
  198. SELECT B.ID,B.OFC_ID,B.ROLE_NAME,B.FLAG_VALID,B.DATA_SCOPE, B.PERS_TYPE
  199. FROM GW_SYS_ROLE B
  200. WHERE 1=1
  201. <if test="roleName != null and roleName != ''">and B.ROLE_NAME LIKE '%'||#{roleName}||'%'</if>
  202. <if test="flagValid != null">and B.FLAG_VALID = #{flagValid}</if>
  203. <if test="dataScope != null and dataScope != ''">and B.DATA_SCOPE = #{dataScope}</if>
  204. <include refid="choseSql"/>
  205. ORDER BY B.ID DESC
  206. </select>
  207. <!-- 福建省标准化工地 移动端查询权限 -->
  208. <select id="getTabPriByUserId" resultMap="roleResultMap">
  209. select r.* from GW_SYS_ROLE r
  210. where r.org_id = #{orgId} and r.id in (select ur.role_id from GW_SYS_REL_USER_ROLE ur where ur.user_id = #{userId} )
  211. </select>
  212. </mapper>