SysUserMapper.xml 11 KB

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