SysRoleMapper.xml 6.0 KB

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