SysUserMapper.xml 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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.qmrb.system.mapper.SysUserMapper">
  6. <!-- 用户分页列表 -->
  7. <select id="getUserPage" resultType="com.qmrb.system.pojo.bo.UserBO">
  8. SELECT
  9. u.id,
  10. u.username,
  11. u.nickname,
  12. u.mobile,
  13. u.gender,
  14. u.avatar,
  15. u.STATUS,
  16. u.user_type,
  17. d.NAME AS dept_name,
  18. GROUP_CONCAT( r.NAME ) AS roleNames,
  19. u.create_time,
  20. b.name as levelName
  21. FROM
  22. sys_user u
  23. LEFT JOIN sys_dept d ON u.dept_id = d.id
  24. LEFT JOIN sys_user_role sur ON u.id = sur.user_id
  25. LEFT JOIN sys_role r ON sur.role_id = r.id
  26. left join sys_dict b on b.type_code='doctor_level' and u.level_name=b.value
  27. <where>
  28. u.deleted = 0 AND u.username != 'root'
  29. <if test='queryParams.keywords!=null and queryParams.keywords.trim() neq ""'>
  30. AND (
  31. u.username LIKE CONCAT('%',#{queryParams.keywords},'%')
  32. OR u.nickname LIKE CONCAT('%',#{queryParams.keywords},'%')
  33. OR u.mobile LIKE CONCAT('%',#{queryParams.keywords},'%')
  34. )
  35. </if>
  36. <if test='queryParams.status!=null'>
  37. AND u.status = #{queryParams.status}
  38. </if>
  39. <if test='queryParams.deptId!=null'>
  40. AND concat(',',concat(d.tree_path,',',d.id),',') like concat('%,',#{queryParams.deptId},',%')
  41. </if>
  42. <if test='queryParams.userType!=null and queryParams.userType.trim() neq ""'>
  43. AND u.user_type = #{queryParams.userType}
  44. </if>
  45. </where>
  46. GROUP BY u.id,b.name
  47. </select>
  48. <!-- 用户表单信息映射 -->
  49. <resultMap id="UserFormMap" type="com.qmrb.system.pojo.bo.UserFormBO">
  50. <id property="id" column="id" jdbcType="BIGINT"/>
  51. <result property="username" column="username" jdbcType="VARCHAR"/>
  52. <result property="nickname" column="nickname" jdbcType="VARCHAR"/>
  53. <result property="mobile" column="mobile" jdbcType="VARCHAR"/>
  54. <result property="gender" column="gender" jdbcType="TINYINT"/>
  55. <result property="avatar" column="avatar" jdbcType="VARCHAR"/>
  56. <result property="email" column="email" jdbcType="VARCHAR"/>
  57. <result property="status" column="status" jdbcType="BOOLEAN"/>
  58. <result property="deptId" column="dept_id" jdbcType="BIGINT"></result>
  59. <collection
  60. property="roleIds"
  61. column="id"
  62. select="com.qmrb.system.mapper.SysUserRoleMapper.listRoleIdsByUserId" >
  63. <result column="role_id" />
  64. </collection>
  65. </resultMap>
  66. <!-- 根据用户ID获取用户详情 -->
  67. <select id="getUserDetail" resultMap="UserFormMap">
  68. SELECT id,
  69. username,
  70. nickname,
  71. mobile,
  72. gender,
  73. avatar,
  74. email,
  75. STATUS,
  76. user_type,
  77. dept_id
  78. FROM sys_user
  79. WHERE id = #{userId}
  80. AND deleted = 0
  81. </select>
  82. <!-- 用户认证信息映射 -->
  83. <resultMap id="UserAuthMap" type="com.qmrb.system.pojo.bo.UserAuthInfo">
  84. <id property="userId" column="userId" jdbcType="BIGINT"/>
  85. <result property="username" column="username" jdbcType="VARCHAR"/>
  86. <result property="password" column="password" jdbcType="VARCHAR"/>
  87. <result property="status" column="status" jdbcType="BOOLEAN"/>
  88. <result property="deptId" column="dept_id" jdbcType="BIGINT"></result>
  89. <collection property="roles" ofType="string" javaType="java.util.Set">
  90. <result column="code"></result>
  91. </collection>
  92. </resultMap>
  93. <!-- 根据用户名获取认证信息 -->
  94. <select id="getUserAuthInfo" resultMap="UserAuthMap">
  95. SELECT
  96. t1.id userId,
  97. t1.username,
  98. t1.nickname,
  99. t1.PASSWORD,
  100. t1.STATUS,
  101. t1.dept_id ,
  102. t3.CODE
  103. FROM
  104. sys_user t1
  105. LEFT JOIN sys_user_role t2 ON t2.user_id = t1.id
  106. LEFT JOIN sys_role t3 ON t3.id = t2.role_id
  107. WHERE
  108. t1.username = #{username} AND t1.deleted=0
  109. </select>
  110. <!-- 获取用户导出列表 -->
  111. <select id="listExportUsers" resultType="com.qmrb.system.pojo.vo.UserExportVO">
  112. SELECT
  113. u.username,
  114. u.nickname,
  115. u.mobile,
  116. CASE u.gender
  117. WHEN 1 THEN '男'
  118. WHEN 2 THEN '女'
  119. ELSE '未知'
  120. END gender,
  121. d.NAME AS dept_name,
  122. u.create_time
  123. FROM
  124. sys_user u
  125. LEFT JOIN sys_dept d ON u.dept_id = d.id
  126. <where>
  127. u.deleted = 0 AND u.username != 'root'
  128. <if test='keywords!=null and keywords.trim() neq ""'>
  129. AND (u.username LIKE CONCAT('%',#{keywords},'%')
  130. OR u.nickname LIKE CONCAT('%',#{keywords},'%')
  131. OR u.mobile LIKE CONCAT('%',#{keywords},'%'))
  132. </if>
  133. <if test='status!=null'>
  134. AND u.status = #{status}
  135. </if>
  136. <if test='deptId!=null'>
  137. AND concat(',',concat(d.tree_path,',',d.id),',') like concat('%,',#{deptId},',%')
  138. </if>
  139. </where>
  140. GROUP BY u.id
  141. </select>
  142. </mapper>