SysRoleMapper.xml 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <!--
  4. 这个文件是自动生成的。
  5. 不要修改此文件。所有改动将在下次重新自动生成时丢失。
  6. -->
  7. <mapper namespace="com.ym.mec.auth.dal.dao.SysRoleDao">
  8. <resultMap type="com.ym.mec.auth.api.entity.SysRole" id="SysRole">
  9. <result column="id_" property="id"/>
  10. <result column="role_name_" property="roleName"/>
  11. <result column="role_code_" property="roleCode"/>
  12. <result column="role_desc_" property="roleDesc"/>
  13. <result column="create_time_" property="createTime"/>
  14. <result column="update_time_" property="updateTime"/>
  15. <result column="del_flag_" property="delFlag"/>
  16. <result column="organ_id_" property="organId"/>
  17. <result column="tenant_id_" property="tenantId"/>
  18. </resultMap>
  19. <!-- 根据主键查询一条记录 -->
  20. <select id="get" resultMap="SysRole">
  21. SELECT * FROM sys_role WHERE id_ = #{id}
  22. </select>
  23. <!-- 全查询 -->
  24. <select id="findAll" resultMap="SysRole">
  25. SELECT * FROM sys_role WHERE del_flag_ = 0 and tenant_id_ = #{tenantId} ORDER BY upate_time_ DESC
  26. </select>
  27. <!-- 向数据库增加一条记录 -->
  28. <insert id="insert" parameterType="com.ym.mec.auth.api.entity.SysRole" useGeneratedKeys="true" keyColumn="id"
  29. keyProperty="id">
  30. INSERT INTO sys_role (id_,role_name_,role_code_,role_desc_,create_time_,update_time_,organ_id_,tenant_id_)
  31. VALUES(#{id},#{roleName},#{roleCode},#{roleDesc},now(),now(),#{organId},#{tenantId})
  32. </insert>
  33. <!-- 根据主键查询一条记录 -->
  34. <update id="update" parameterType="com.ym.mec.auth.api.entity.SysRole">
  35. UPDATE sys_role
  36. <set>
  37. <if test="delFlag != null">
  38. del_flag_ = #{delFlag},
  39. </if>
  40. <if test="roleCode != null">
  41. role_code_ = #{roleCode},
  42. </if>
  43. <if test="roleName != null">
  44. role_name_ = #{roleName},
  45. </if>
  46. <if test="roleDesc != null">
  47. role_desc_ = #{roleDesc},
  48. </if>
  49. <if test="updateTime != null">
  50. update_time_ = NOW(),
  51. </if>
  52. <if test="organId != null">
  53. organ_id_ = #{organId},
  54. </if>
  55. </set>
  56. WHERE id_ = #{id} and tenant_id_ = #{tenantId}
  57. </update>
  58. <!-- 根据主键删除一条记录 -->
  59. <delete id="delete">
  60. UPDATE sys_role SET del_flag_ = 1 WHERE id_ = #{id}
  61. </delete>
  62. <!-- 分页查询 -->
  63. <select id="queryPage" resultMap="SysRole" parameterType="map">
  64. SELECT * FROM sys_role WHERE del_flag_ = 0 and tenant_id_ = #{tenantId} ORDER BY update_time_ DESC
  65. <include refid="global.limit"/>
  66. </select>
  67. <!-- 查询当前表的总记录数 -->
  68. <select id="queryCount" resultType="int">
  69. SELECT COUNT(*) FROM sys_role WHERE del_flag_ = 0 and tenant_id_ = #{tenantId}
  70. </select>
  71. <select id="findRoleByUserId" resultMap="SysRole">
  72. SELECT sr.* FROM sys_user_role sur LEFT JOIN sys_role sr ON sur.role_id_ = sr.id_ WHERE sur.user_id_ = #{userId} AND sr.del_flag_ = 0
  73. </select>
  74. <select id="findRoleByCode" resultMap="SysRole">
  75. SELECT sr.* FROM sys_role WHERE role_code_ = #{code} AND sr.del_flag_ = 0 and tenant_id_ = #{tenantId}
  76. </select>
  77. <select id="findByRoleName" resultMap="SysRole">
  78. SELECT * FROM sys_role WHERE role_name_ = #{roleName} AND del_flag_ = 0 and tenant_id_ = #{tenantId} LIMIT 1
  79. </select>
  80. </mapper>