SysRoleMapper.xml 5.9 KB

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