RoleMapper.xml 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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.juxiao.xchat.module.system.mapper.RoleMapper">
  6. <resultMap type="com.juxiao.xchat.module.system.domain.Role" id="RoleResult">
  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="selectRoleContactVo">
  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. <sql id="selectRoleVo">
  29. select r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status, r.del_flag, r.create_time, r.remark
  30. from sys_role r
  31. </sql>
  32. <select id="selectRoleList" parameterType="com.juxiao.xchat.module.system.domain.Role" resultMap="RoleResult">
  33. <include refid="selectRoleContactVo"/>
  34. where r.del_flag = '0'
  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="roleKey != null and roleKey != ''">
  42. AND r.role_key like concat('%', #{roleKey}, '%')
  43. </if>
  44. <if test="dataScope != null and dataScope != ''">
  45. AND r.data_scope = #{dataScope}
  46. </if>
  47. <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
  48. and date_format(r.create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
  49. </if>
  50. <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
  51. and date_format(r.create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
  52. </if>
  53. <!-- 数据范围过滤 -->
  54. ${params.dataScope}
  55. </select>
  56. <select id="selectRolesByUserId" parameterType="java.lang.Long" resultMap="RoleResult">
  57. <include refid="selectRoleContactVo"/>
  58. WHERE r.del_flag = '0' and ur.user_id = #{userId}
  59. </select>
  60. <select id="selectRoleById" parameterType="java.lang.Long" resultMap="RoleResult">
  61. <include refid="selectRoleVo"/>
  62. where r.del_flag = '0' and r.role_id = #{roleId}
  63. </select>
  64. <select id="checkRoleNameUnique" parameterType="java.lang.String" resultMap="RoleResult">
  65. <include refid="selectRoleVo"/>
  66. where r.role_name=#{roleName}
  67. </select>
  68. <select id="checkRoleKeyUnique" parameterType="java.lang.String" resultMap="RoleResult">
  69. <include refid="selectRoleVo"/>
  70. where r.role_key=#{roleKey}
  71. </select>
  72. <delete id="deleteRoleById" parameterType="java.lang.Long">
  73. delete from sys_role where role_id = #{roleId}
  74. </delete>
  75. <delete id="deleteRoleByIds" parameterType="java.lang.Long">
  76. update sys_role set del_flag = '2' where role_id in
  77. <foreach collection="array" item="roleId" open="(" separator="," close=")">
  78. #{roleId}
  79. </foreach>
  80. </delete>
  81. <update id="updateRole" parameterType="com.juxiao.xchat.module.system.domain.Role">
  82. update sys_role
  83. <set>
  84. <if test="roleName != null and roleName != ''">role_name = #{roleName},</if>
  85. <if test="roleKey != null and roleKey != ''">role_key = #{roleKey},</if>
  86. <if test="roleSort != null and roleSort != ''">role_sort = #{roleSort},</if>
  87. <if test="dataScope != null and dataScope != ''">data_scope = #{dataScope},</if>
  88. <if test="status != null and status != ''">status = #{status},</if>
  89. <if test="remark != null">remark = #{remark},</if>
  90. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  91. update_time = sysdate()
  92. </set>
  93. where role_id = #{roleId}
  94. </update>
  95. <insert id="insertRole" parameterType="com.juxiao.xchat.module.system.domain.Role" useGeneratedKeys="true" keyProperty="roleId">
  96. insert into sys_role(
  97. <if test="roleId != null and roleId != 0">role_id,</if>
  98. <if test="roleName != null and roleName != ''">role_name,</if>
  99. <if test="roleKey != null and roleKey != ''">role_key,</if>
  100. <if test="roleSort != null and roleSort != ''">role_sort,</if>
  101. <if test="dataScope != null and dataScope != ''">data_scope,</if>
  102. <if test="status != null and status != ''">status,</if>
  103. <if test="remark != null and remark != ''">remark,</if>
  104. <if test="createBy != null and createBy != ''">create_by,</if>
  105. create_time
  106. )values(
  107. <if test="roleId != null and roleId != 0">#{roleId},</if>
  108. <if test="roleName != null and roleName != ''">#{roleName},</if>
  109. <if test="roleKey != null and roleKey != ''">#{roleKey},</if>
  110. <if test="roleSort != null and roleSort != ''">#{roleSort},</if>
  111. <if test="dataScope != null and dataScope != ''">#{dataScope},</if>
  112. <if test="status != null and status != ''">#{status},</if>
  113. <if test="remark != null and remark != ''">#{remark},</if>
  114. <if test="createBy != null and createBy != ''">#{createBy},</if>
  115. sysdate()
  116. )
  117. </insert>
  118. </mapper>