SysUserMapper.xml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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.ruoyi.system.mapper.SysUserMapper">
  6. <resultMap type="SysUser" id="SysUserResult">
  7. <id property="userId" column="user_id" />
  8. <result property="deptId" column="dept_id" />
  9. <result property="userName" column="user_name" />
  10. <result property="nickName" column="nick_name" />
  11. <result property="email" column="email" />
  12. <result property="phonenumber" column="phonenumber" />
  13. <result property="sex" column="sex" />
  14. <result property="avatar" column="avatar" />
  15. <result property="password" column="password" />
  16. <result property="status" column="status" />
  17. <result property="delFlag" column="del_flag" />
  18. <result property="loginIp" column="login_ip" />
  19. <result property="loginDate" column="login_date" />
  20. <result property="createBy" column="create_by" />
  21. <result property="createTime" column="create_time" />
  22. <result property="updateBy" column="update_by" />
  23. <result property="updateTime" column="update_time" />
  24. <result property="remark" column="remark" />
  25. <association property="dept" column="dept_id" javaType="SysDept" resultMap="deptResult" />
  26. <collection property="roles" javaType="java.util.List" resultMap="RoleResult" />
  27. </resultMap>
  28. <resultMap id="deptResult" type="SysDept">
  29. <id property="deptId" column="dept_id" />
  30. <result property="parentId" column="parent_id" />
  31. <result property="deptName" column="dept_name" />
  32. <result property="orderNum" column="order_num" />
  33. <result property="leader" column="leader" />
  34. <result property="status" column="dept_status" />
  35. </resultMap>
  36. <resultMap id="RoleResult" type="SysRole">
  37. <id property="roleId" column="role_id" />
  38. <result property="roleName" column="role_name" />
  39. <result property="roleKey" column="role_key" />
  40. <result property="roleSort" column="role_sort" />
  41. <result property="dataScope" column="data_scope" />
  42. <result property="status" column="role_status" />
  43. </resultMap>
  44. <sql id="selectUserVo">
  45. select u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,
  46. d.dept_id, d.parent_id, d.dept_name, d.order_num, d.leader, d.status as dept_status,
  47. r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status
  48. from sys_user u
  49. left join sys_dept d on u.dept_id = d.dept_id
  50. left join sys_user_role ur on u.user_id = ur.user_id
  51. left join sys_role r on r.role_id = ur.role_id
  52. </sql>
  53. <select id="selectUserList" parameterType="SysUser" resultMap="SysUserResult">
  54. select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader from sys_user u
  55. left join sys_dept d on u.dept_id = d.dept_id
  56. where u.del_flag = '0'
  57. <if test="userId != null and userId != 0">
  58. AND u.user_id = #{userId}
  59. </if>
  60. <if test="userName != null and userName != ''">
  61. AND u.user_name like concat('%', #{userName}, '%')
  62. </if>
  63. <if test="status != null and status != ''">
  64. AND u.status = #{status}
  65. </if>
  66. <if test="phonenumber != null and phonenumber != ''">
  67. AND u.phonenumber like concat('%', #{phonenumber}, '%')
  68. </if>
  69. <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
  70. AND date_format(u.create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
  71. </if>
  72. <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
  73. AND date_format(u.create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
  74. </if>
  75. <if test="deptId != null and deptId != 0">
  76. AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE find_in_set(#{deptId}, ancestors) ))
  77. </if>
  78. <!-- 数据范围过滤 -->
  79. ${params.dataScope}
  80. </select>
  81. <select id="selectAllocatedList" parameterType="SysUser" resultMap="SysUserResult">
  82. select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time
  83. from sys_user u
  84. left join sys_dept d on u.dept_id = d.dept_id
  85. left join sys_user_role ur on u.user_id = ur.user_id
  86. left join sys_role r on r.role_id = ur.role_id
  87. where u.del_flag = '0' and r.role_id = #{roleId}
  88. <if test="userName != null and userName != ''">
  89. AND u.user_name like concat('%', #{userName}, '%')
  90. </if>
  91. <if test="phonenumber != null and phonenumber != ''">
  92. AND u.phonenumber like concat('%', #{phonenumber}, '%')
  93. </if>
  94. <!-- 数据范围过滤 -->
  95. ${params.dataScope}
  96. </select>
  97. <select id="selectUnallocatedList" parameterType="SysUser" resultMap="SysUserResult">
  98. select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time
  99. from sys_user u
  100. left join sys_dept d on u.dept_id = d.dept_id
  101. left join sys_user_role ur on u.user_id = ur.user_id
  102. left join sys_role r on r.role_id = ur.role_id
  103. where u.del_flag = '0' and (r.role_id != #{roleId} or r.role_id IS NULL)
  104. and u.user_id not in (select u.user_id from sys_user u inner join sys_user_role ur on u.user_id = ur.user_id and ur.role_id = #{roleId})
  105. <if test="userName != null and userName != ''">
  106. AND u.user_name like concat('%', #{userName}, '%')
  107. </if>
  108. <if test="phonenumber != null and phonenumber != ''">
  109. AND u.phonenumber like concat('%', #{phonenumber}, '%')
  110. </if>
  111. <!-- 数据范围过滤 -->
  112. ${params.dataScope}
  113. </select>
  114. <select id="selectUserByUserName" parameterType="String" resultMap="SysUserResult">
  115. <include refid="selectUserVo"/>
  116. where u.user_name = #{userName}
  117. </select>
  118. <select id="selectUserById" parameterType="Long" resultMap="SysUserResult">
  119. <include refid="selectUserVo"/>
  120. where u.user_id = #{userId}
  121. </select>
  122. <select id="checkUserNameUnique" parameterType="String" resultType="int">
  123. select count(1) from sys_user where user_name = #{userName} limit 1
  124. </select>
  125. <select id="checkPhoneUnique" parameterType="String" resultMap="SysUserResult">
  126. select user_id, phonenumber from sys_user where phonenumber = #{phonenumber} limit 1
  127. </select>
  128. <select id="checkEmailUnique" parameterType="String" resultMap="SysUserResult">
  129. select user_id, email from sys_user where email = #{email} limit 1
  130. </select>
  131. <insert id="insertUser" parameterType="SysUser" useGeneratedKeys="true" keyProperty="userId">
  132. insert into sys_user(
  133. <if test="userId != null and userId != 0">user_id,</if>
  134. <if test="deptId != null and deptId != 0">dept_id,</if>
  135. <if test="userName != null and userName != ''">user_name,</if>
  136. <if test="nickName != null and nickName != ''">nick_name,</if>
  137. <if test="email != null and email != ''">email,</if>
  138. <if test="avatar != null and avatar != ''">avatar,</if>
  139. <if test="phonenumber != null and phonenumber != ''">phonenumber,</if>
  140. <if test="sex != null and sex != ''">sex,</if>
  141. <if test="password != null and password != ''">password,</if>
  142. <if test="status != null and status != ''">status,</if>
  143. <if test="createBy != null and createBy != ''">create_by,</if>
  144. <if test="remark != null and remark != ''">remark,</if>
  145. create_time
  146. )values(
  147. <if test="userId != null and userId != ''">#{userId},</if>
  148. <if test="deptId != null and deptId != ''">#{deptId},</if>
  149. <if test="userName != null and userName != ''">#{userName},</if>
  150. <if test="nickName != null and nickName != ''">#{nickName},</if>
  151. <if test="email != null and email != ''">#{email},</if>
  152. <if test="avatar != null and avatar != ''">#{avatar},</if>
  153. <if test="phonenumber != null and phonenumber != ''">#{phonenumber},</if>
  154. <if test="sex != null and sex != ''">#{sex},</if>
  155. <if test="password != null and password != ''">#{password},</if>
  156. <if test="status != null and status != ''">#{status},</if>
  157. <if test="createBy != null and createBy != ''">#{createBy},</if>
  158. <if test="remark != null and remark != ''">#{remark},</if>
  159. sysdate()
  160. )
  161. </insert>
  162. <update id="updateUser" parameterType="SysUser">
  163. update sys_user
  164. <set>
  165. <if test="deptId != null and deptId != 0">dept_id = #{deptId},</if>
  166. <if test="userName != null and userName != ''">user_name = #{userName},</if>
  167. <if test="nickName != null and nickName != ''">nick_name = #{nickName},</if>
  168. <if test="email != null ">email = #{email},</if>
  169. <if test="phonenumber != null ">phonenumber = #{phonenumber},</if>
  170. <if test="sex != null and sex != ''">sex = #{sex},</if>
  171. <if test="avatar != null and avatar != ''">avatar = #{avatar},</if>
  172. <if test="password != null and password != ''">password = #{password},</if>
  173. <if test="status != null and status != ''">status = #{status},</if>
  174. <if test="loginIp != null and loginIp != ''">login_ip = #{loginIp},</if>
  175. <if test="loginDate != null">login_date = #{loginDate},</if>
  176. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  177. <if test="remark != null">remark = #{remark},</if>
  178. update_time = sysdate()
  179. </set>
  180. where user_id = #{userId}
  181. </update>
  182. <update id="updateUserStatus" parameterType="SysUser">
  183. update sys_user set status = #{status} where user_id = #{userId}
  184. </update>
  185. <update id="updateUserAvatar" parameterType="SysUser">
  186. update sys_user set avatar = #{avatar} where user_name = #{userName}
  187. </update>
  188. <update id="resetUserPwd" parameterType="SysUser">
  189. update sys_user set password = #{password} where user_name = #{userName}
  190. </update>
  191. <delete id="deleteUserById" parameterType="Long">
  192. update sys_user set del_flag = '2' where user_id = #{userId}
  193. </delete>
  194. <delete id="deleteUserByIds" parameterType="Long">
  195. update sys_user set del_flag = '2' where user_id in
  196. <foreach collection="array" item="userId" open="(" separator="," close=")">
  197. #{userId}
  198. </foreach>
  199. </delete>
  200. </mapper>