RoleMapper.xml 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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.huaxu.dao.RoleMapper">
  4. <!-- 结果集 -->
  5. <resultMap type="com.huaxu.entity.Role" id="RoleMap">
  6. <result property="id" column="ID" jdbcType="INTEGER"/>
  7. <result property="tenantId" column="TENANT_ID" jdbcType="VARCHAR"/>
  8. <result property="roleName" column="ROLE_NAME" jdbcType="VARCHAR"/>
  9. <result property="description" column="DESCRIPTION" jdbcType="VARCHAR"/>
  10. <result property="roleState" column="ROLE_STATE" jdbcType="INTEGER"/>
  11. <result property="permissionType" column="PERMISSION_TYPE" jdbcType="INTEGER"/>
  12. <result property="remark" column="REMARK" jdbcType="VARCHAR"/>
  13. <result property="status" column="STATUS" jdbcType="INTEGER"/>
  14. <result property="dateCreate" column="DATE_CREATE" jdbcType="TIMESTAMP"/>
  15. <result property="createBy" column="CREATE_BY" jdbcType="VARCHAR"/>
  16. <result property="dateUpdate" column="DATE_UPDATE" jdbcType="TIMESTAMP"/>
  17. <result property="updateBy" column="UPDATE_BY" jdbcType="VARCHAR"/>
  18. </resultMap>
  19. <resultMap type="com.huaxu.dto.RoleDto" id="RoleDtoMap">
  20. <result property="id" column="ID" jdbcType="INTEGER"/>
  21. <result property="roleName" column="ROLE_NAME" jdbcType="VARCHAR"/>
  22. <result property="users" column="users" jdbcType="INTEGER"/>
  23. <result property="roleState" column="ROLE_STATE" jdbcType="INTEGER"/>
  24. </resultMap>
  25. <!-- 基本字段 -->
  26. <sql id="Base_Column_List">
  27. ID, TENANT_ID, ROLE_NAME, DESCRIPTION, ROLE_STATE, PERMISSION_TYPE, REMARK, STATUS, DATE_CREATE, CREATE_BY, DATE_UPDATE, UPDATE_BY </sql>
  28. <!-- 查询单个 -->
  29. <select id="selectById" resultMap="RoleMap">
  30. select
  31. <include refid="Base_Column_List"/>
  32. from uims_role
  33. where ID = #{id}
  34. </select>
  35. <!-- 查询全部 -->
  36. <select id="selectAll" resultMap="RoleMap">
  37. select
  38. <include refid="Base_Column_List"/>
  39. from uims_role
  40. </select>
  41. <!--通过实体作为筛选条件查询-->
  42. <select id="selectList" resultMap="RoleMap">
  43. select
  44. <include refid="Base_Column_List"/>
  45. from uims_role
  46. <where>
  47. and status!=0
  48. <if test="id != null">
  49. and ID = #{id}
  50. </if>
  51. <if test="tenantId != null and tenantId != ''">
  52. and TENANT_ID = #{tenantId}
  53. </if>
  54. <if test="roleName != null and roleName != ''">
  55. and ROLE_NAME = #{roleName}
  56. </if>
  57. <if test="description != null and description != ''">
  58. and DESCRIPTION = #{description}
  59. </if>
  60. <if test="roleState != null">
  61. and ROLE_STATE = #{roleState}
  62. </if>
  63. <if test="permissionType != null">
  64. and PERMISSION_TYPE = #{permissionType}
  65. </if>
  66. <if test="remark != null and remark != ''">
  67. and REMARK = #{remark}
  68. </if>
  69. <if test="status != null">
  70. and STATUS = #{status}
  71. </if>
  72. <if test="dateCreate != null">
  73. and DATE_CREATE = #{dateCreate}
  74. </if>
  75. <if test="createBy != null and createBy != ''">
  76. and CREATE_BY = #{createBy}
  77. </if>
  78. <if test="dateUpdate != null">
  79. and DATE_UPDATE = #{dateUpdate}
  80. </if>
  81. <if test="updateBy != null and updateBy != ''">
  82. and UPDATE_BY = #{updateBy}
  83. </if>
  84. </where>
  85. </select>
  86. <!-- 新增所有列 -->
  87. <insert id="insert" keyProperty="id" useGeneratedKeys="true">
  88. insert into uims_role(ID, TENANT_ID, ROLE_NAME, DESCRIPTION, ROLE_STATE, PERMISSION_TYPE, REMARK, STATUS, DATE_CREATE, CREATE_BY, DATE_UPDATE, UPDATE_BY)
  89. values ( #{id}, #{tenantId}, #{roleName}, #{description}, #{roleState}, #{permissionType}, #{remark}, #{status}, #{dateCreate}, #{createBy}, #{dateUpdate}, #{updateBy})
  90. </insert>
  91. <!-- 批量新增 -->
  92. <insert id="batchInsert">
  93. insert into uims_role(ID, TENANT_ID, ROLE_NAME, DESCRIPTION, ROLE_STATE, PERMISSION_TYPE, REMARK, STATUS,
  94. DATE_CREATE, CREATE_BY, DATE_UPDATE, UPDATE_BY)
  95. values
  96. <foreach collection="roles" item="item" index="index" separator=",">
  97. (
  98. #{item.id}, #{item.tenantId}, #{item.roleName}, #{item.description}, #{item.roleState},
  99. #{item.permissionType}, #{item.remark}, #{item.status}, #{item.dateCreate}, #{item.createBy},
  100. #{item.dateUpdate}, #{item.updateBy} )
  101. </foreach>
  102. </insert>
  103. <!-- 通过主键修改数据 -->
  104. <update id="update">
  105. update uims.uims_role
  106. <set>
  107. <if test="tenantId != null and tenantId != ''">
  108. TENANT_ID = #{tenantId},
  109. </if>
  110. <if test="roleName != null and roleName != ''">
  111. ROLE_NAME = #{roleName},
  112. </if>
  113. <if test="description != null and description != ''">
  114. DESCRIPTION = #{description},
  115. </if>
  116. <if test="roleState != null">
  117. ROLE_STATE = #{roleState},
  118. </if>
  119. <if test="permissionType != null">
  120. PERMISSION_TYPE = #{permissionType},
  121. </if>
  122. <if test="remark != null and remark != ''">
  123. REMARK = #{remark},
  124. </if>
  125. <if test="status != null">
  126. STATUS = #{status},
  127. </if>
  128. <if test="dateCreate != null">
  129. DATE_CREATE = #{dateCreate},
  130. </if>
  131. <if test="createBy != null and createBy != ''">
  132. CREATE_BY = #{createBy},
  133. </if>
  134. <if test="dateUpdate != null">
  135. DATE_UPDATE = #{dateUpdate},
  136. </if>
  137. <if test="updateBy != null and updateBy != ''">
  138. UPDATE_BY = #{updateBy},
  139. </if>
  140. </set>
  141. where ID = #{id}
  142. </update>
  143. <!--通过主键删除-->
  144. <delete id="deleteById">
  145. delete from uims_role where ID = #{id}
  146. </delete>
  147. <!-- 总数 -->
  148. <select id="count" resultType="int">
  149. select count(*) from uims_role
  150. </select>
  151. <select id="selectPage" resultMap="RoleDtoMap">
  152. select
  153. <include refid="Base_Column_List"/>,users
  154. from uims_role a left join
  155. (select count(*) users ,ROLE_ID from uims_user_role b
  156. <where>
  157. and status!=0
  158. </where>
  159. group by b.ROLE_ID ) b
  160. ON a.id=b.ROLE_ID
  161. <where>
  162. and status!=0
  163. <if test="role.id != null">
  164. and ID = #{role.id}
  165. </if>
  166. <if test="role.tenantId != null and role.tenantId != ''">
  167. and TENANT_ID = #{role.tenantId}
  168. </if>
  169. <if test="role.roleName != null and role.roleName != ''">
  170. and ROLE_NAME like concat('%', #{role.roleName}, '%')
  171. </if>
  172. <if test="role.description != null and role.description != ''">
  173. and DESCRIPTION = #{role.description}
  174. </if>
  175. <if test="role.roleState != null">
  176. and ROLE_STATE = #{role.roleState}
  177. </if>
  178. <if test="role.permissionType != null">
  179. and PERMISSION_TYPE = #{role.permissionType}
  180. </if>
  181. <if test="role.remark != null and role.remark != ''">
  182. and REMARK = #{role.remark}
  183. </if>
  184. <if test="role.status != null">
  185. and STATUS = #{role.status}
  186. </if>
  187. <if test="role.dateCreate != null">
  188. and DATE_CREATE = #{role.dateCreate}
  189. </if>
  190. <if test="role.createBy != null and role.createBy != ''">
  191. and CREATE_BY = #{role.createBy}
  192. </if>
  193. <if test="role.dateUpdate != null">
  194. and DATE_UPDATE = #{role.dateUpdate}
  195. </if>
  196. <if test="role.updateBy != null and role.updateBy != ''">
  197. and UPDATE_BY = #{role.updateBy}
  198. </if>
  199. </where>
  200. </select>
  201. <select id="findRoleUser" resultType="com.huaxu.entity.Role">
  202. select a.id,b.ROLE_NAME from uims_user_role a join uims_role b on a.ROLE_ID=b.ID
  203. where a.ROLE_ID=#{id} and a.status!=0 limit 1
  204. </select>
  205. <sql id="sysAreaJoins">
  206. left join uims_org com ON com.id = a.company_org_id
  207. left join uims_org dep ON dep.id = a.dept_org_id
  208. left join uims_user_role userrole ON userrole.USER_ID=a.id
  209. </sql>
  210. <sql id="userColumns">
  211. a.id as "id" ,
  212. a.tenant_id as "tenantId" ,
  213. a.username as "username" ,
  214. a.phone as "phone" ,
  215. a.company_org_id as "companyOrgId" ,
  216. a.dept_org_id as "deptOrgId" ,
  217. a.photo as "photo" ,
  218. a.user_type as "userType" ,
  219. a.enable_state as "enableState" ,
  220. a.remark as "remark" ,
  221. a.email as "email" ,
  222. a.status as "status" ,
  223. a.date_create as "dateCreate" ,
  224. a.create_by as "createBy" ,
  225. a.date_update as "dateUpdate" ,
  226. a.update_by as "updateBy",
  227. com.org_name as "companyOrgName" ,
  228. dep.org_name as "deptOrgName",
  229. userrole.id as roleId
  230. </sql>
  231. <select id="findUsersByRole" resultType="com.huaxu.entity.UserEntity">
  232. select <include refid="userColumns"/>
  233. from uims_user_role b join uims_user a on b.USER_ID=a.ID
  234. <include refid="sysAreaJoins"/>
  235. where b.ROLE_ID=#{id} and b.status!=0 and userrole.status!=0
  236. </select>
  237. <update id="deleteRoleUser">
  238. update uims_user_role set status=0 where ROLE_ID=#{id}
  239. </update>
  240. <update id="deleteRoleMenu">
  241. update uims_role_menu set status=0 where ROLE_ID=#{id}
  242. </update>
  243. </mapper>