SysRoleMapper.xml 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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="com.usky.system.mapper.SysRoleMapper">
  6. <resultMap type="com.usky.system.domain.SysRole" id="SysRoleResult">
  7. <id property="roleId" column="role_id" />
  8. <result property="roleName" column="role_name" />
  9. <result property="roleKey" column="role_key" />
  10. <result property="roleSort" column="role_sort" />
  11. <result property="dataScope" column="data_scope" />
  12. <result property="menuCheckStrictly" column="menu_check_strictly" />
  13. <result property="deptCheckStrictly" column="dept_check_strictly" />
  14. <result property="status" column="status" />
  15. <result property="delFlag" column="del_flag" />
  16. <result property="createBy" column="create_by" />
  17. <result property="createTime" column="create_time" />
  18. <result property="updateBy" column="update_by" />
  19. <result property="updateTime" column="update_time" />
  20. <result property="remark" column="remark" />
  21. <result property="tenantId" column="tenant_id" />
  22. </resultMap>
  23. <sql id="selectRoleVo">
  24. select distinct r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.menu_check_strictly, r.dept_check_strictly,
  25. r.status, r.del_flag, r.create_time, r.remark
  26. from sys_role r
  27. left join sys_user_role ur on ur.role_id = r.role_id
  28. left join sys_user u on u.user_id = ur.user_id
  29. left join sys_dept d on u.dept_id = d.dept_id
  30. </sql>
  31. <select id="selectRoleList" parameterType="com.usky.system.domain.SysRole" resultMap="SysRoleResult">
  32. <include refid="selectRoleVo"/>
  33. where r.del_flag = '0'
  34. <if test="roleName != null and roleName != ''">
  35. AND r.role_name like concat('%', #{roleName}, '%')
  36. </if>
  37. <if test="createBy != null and createBy != ''">
  38. AND r.create_by = #{createBy}
  39. </if>
  40. <if test="status != null and status != ''">
  41. AND r.status = #{status}
  42. </if>
  43. <if test="tenantId != null and tenantId != '' and tenantId !=0">
  44. AND r.tenant_id = #{tenantId}
  45. </if>
  46. <if test="roleKey != null and roleKey != ''">
  47. AND r.role_key like concat('%', #{roleKey}, '%')
  48. </if>
  49. <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
  50. and date_format(r.create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
  51. </if>
  52. <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
  53. and date_format(r.create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
  54. </if>
  55. <!-- 数据范围过滤 -->
  56. ${params.dataScope}
  57. order by r.role_sort
  58. </select>
  59. <select id="selectRolePermissionByUserId" parameterType="Long" resultMap="SysRoleResult">
  60. <include refid="selectRoleVo"/>
  61. WHERE r.del_flag = '0' and ur.user_id = #{userId}
  62. </select>
  63. <select id="selectRoleAll" resultMap="SysRoleResult">
  64. <include refid="selectRoleVo"/>
  65. </select>
  66. <select id="selectRoleListByUserId" parameterType="map" resultType="Integer">
  67. SELECT r.role_id
  68. FROM sys_role r
  69. LEFT JOIN sys_user_role ur ON ur.role_id = r.role_id
  70. LEFT JOIN sys_user u ON u.user_id = ur.user_id
  71. WHERE u.user_id = #{userId, jdbcType=BIGINT} AND r.tenant_id = #{tenantId, jdbcType=INTEGER}
  72. </select>
  73. <select id="selectRoleById" parameterType="Long" resultMap="SysRoleResult">
  74. <include refid="selectRoleVo"/>
  75. where r.role_id = #{roleId}
  76. </select>
  77. <select id="selectRolesByUserName" parameterType="Map" resultMap="SysRoleResult">
  78. <include refid="selectRoleVo"/>
  79. WHERE r.del_flag = '0'
  80. and u.user_name = #{userName}
  81. and r.tenant_id = #{tenantId, jdbcType=INTEGER}
  82. </select>
  83. <select id="checkRoleNameUnique" parameterType="String" resultMap="SysRoleResult">
  84. <include refid="selectRoleVo"/>
  85. where r.role_name=#{roleName} AND r.del_flag = 0 and r.status = 0
  86. <if test="tenantId != null and tenantId != '' and tenantId !=0">
  87. AND r.tenant_id = #{tenantId}
  88. </if>
  89. limit 1
  90. </select>
  91. <select id="checkRoleKeyUnique" parameterType="String" resultMap="SysRoleResult">
  92. <include refid="selectRoleVo"/>
  93. where r.role_key=#{roleKey} AND r.del_flag = 0 and r.status = 0
  94. <if test="tenantId != null and tenantId != '' and tenantId !=0">
  95. AND r.tenant_id = #{tenantId}
  96. </if>
  97. limit 1
  98. </select>
  99. <insert id="insertRole" parameterType="com.usky.system.domain.SysRole" useGeneratedKeys="true" keyProperty="roleId">
  100. insert into sys_role(
  101. <if test="roleId != null and roleId != 0">role_id,</if>
  102. <if test="roleName != null and roleName != ''">role_name,</if>
  103. <if test="roleKey != null and roleKey != ''">role_key,</if>
  104. <if test="roleSort != null and roleSort != ''">role_sort,</if>
  105. <if test="dataScope != null and dataScope != ''">data_scope,</if>
  106. <if test="menuCheckStrictly != null">menu_check_strictly,</if>
  107. <if test="deptCheckStrictly != null">dept_check_strictly,</if>
  108. <if test="status != null and status != ''">status,</if>
  109. <if test="remark != null and remark != ''">remark,</if>
  110. <if test="createBy != null and createBy != ''">create_by,</if>
  111. <if test="tenantId != null and tenantId != '' and tenantId !=0">tenant_id,</if>
  112. create_time
  113. )values(
  114. <if test="roleId != null and roleId != 0">#{roleId},</if>
  115. <if test="roleName != null and roleName != ''">#{roleName},</if>
  116. <if test="roleKey != null and roleKey != ''">#{roleKey},</if>
  117. <if test="roleSort != null and roleSort != ''">#{roleSort},</if>
  118. <if test="dataScope != null and dataScope != ''">#{dataScope},</if>
  119. <if test="menuCheckStrictly != null">#{menuCheckStrictly},</if>
  120. <if test="deptCheckStrictly != null">#{deptCheckStrictly},</if>
  121. <if test="status != null and status != ''">#{status},</if>
  122. <if test="remark != null and remark != ''">#{remark},</if>
  123. <if test="createBy != null and createBy != ''">#{createBy},</if>
  124. <if test="tenantId != null and tenantId != '' and tenantId !=0">#{tenantId},</if>
  125. sysdate()
  126. )
  127. </insert>
  128. <update id="updateRole" parameterType="com.usky.system.domain.SysRole">
  129. update sys_role
  130. <set>
  131. <if test="roleName != null and roleName != ''">role_name = #{roleName},</if>
  132. <if test="roleKey != null and roleKey != ''">role_key = #{roleKey},</if>
  133. <if test="roleSort != null and roleSort != ''">role_sort = #{roleSort},</if>
  134. <if test="dataScope != null and dataScope != ''">data_scope = #{dataScope},</if>
  135. <if test="menuCheckStrictly != null">menu_check_strictly = #{menuCheckStrictly},</if>
  136. <if test="deptCheckStrictly != null">dept_check_strictly = #{deptCheckStrictly},</if>
  137. <if test="status != null and status != ''">status = #{status},</if>
  138. <if test="remark != null">remark = #{remark},</if>
  139. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  140. update_time = sysdate()
  141. </set>
  142. where role_id = #{roleId}
  143. </update>
  144. <delete id="deleteRoleById" parameterType="Long">
  145. update sys_role set del_flag = '2' where role_id = #{roleId}
  146. </delete>
  147. <delete id="deleteRoleByIds" parameterType="Long">
  148. update sys_role set del_flag = '2' where role_id in
  149. <foreach collection="roleIds" item="roleIds" open="(" separator="," close=")">
  150. #{roleIds}
  151. </foreach>
  152. </delete>
  153. </mapper>