UserMapper.xml 11 KB

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