SysRoleMapper.xml 6.7 KB

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