RoleDao.xml 7.3 KB

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