SysUserMapper.xml 10 KB

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