SysUserMapper.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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="userSystem" column="user_system" />
  16. <result property="password" column="password" />
  17. <result property="userType" column="user_type" />
  18. <result property="openId" column="open_id" />
  19. <result property="imgSrc" column="img_src" />
  20. <result property="sessionKey" column="session_key" />
  21. <result property="relatedNo" column="related_no" />
  22. <result property="status" column="status" />
  23. <result property="delFlag" column="del_flag" />
  24. <result property="loginIp" column="login_ip" />
  25. <result property="loginDate" column="login_date" />
  26. <result property="createBy" column="create_by" />
  27. <result property="createTime" column="create_time" />
  28. <result property="updateBy" column="update_by" />
  29. <result property="updateTime" column="update_time" />
  30. <result property="remark" column="remark" />
  31. <association property="dept" column="dept_id" javaType="SysDept" resultMap="deptResult" />
  32. <collection property="roles" javaType="java.util.List" resultMap="RoleResult" />
  33. </resultMap>
  34. <resultMap id="deptResult" type="SysDept">
  35. <id property="deptId" column="dept_id" />
  36. <result property="parentId" column="parent_id" />
  37. <result property="deptName" column="dept_name" />
  38. <result property="orderNum" column="order_num" />
  39. <result property="leader" column="leader" />
  40. <result property="status" column="dept_status" />
  41. </resultMap>
  42. <resultMap id="RoleResult" type="SysRole">
  43. <id property="roleId" column="role_id" />
  44. <result property="roleName" column="role_name" />
  45. <result property="roleKey" column="role_key" />
  46. <result property="roleSort" column="role_sort" />
  47. <result property="dataScope" column="data_scope" />
  48. <result property="status" column="role_status" />
  49. </resultMap>
  50. <sql id="selectUserVo">
  51. select u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.avatar, u.phonenumber, u.password, u.user_type, u.user_system, u.open_id, u.img_src, u.session_key,
  52. u.related_no, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,
  53. d.dept_id, d.parent_id, d.dept_name, d.order_num, d.leader, d.status as dept_status,
  54. r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status
  55. from sys_user u
  56. left join sys_dept d on u.dept_id = d.dept_id
  57. left join sys_user_role ur on u.user_id = ur.user_id
  58. left join sys_role r on r.role_id = ur.role_id
  59. </sql>
  60. <select id="selectUserList" parameterType="SysUser" resultMap="SysUserResult">
  61. select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.password, u.user_type, u.user_system, u.open_id, u.img_src, u.session_key, u.related_no, 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
  62. left join sys_dept d on u.dept_id = d.dept_id
  63. where u.del_flag = '0'
  64. <if test="userName != null and userName != ''">
  65. AND u.user_name like concat('%', #{userName}, '%')
  66. </if>
  67. <if test="status != null and status != ''">
  68. AND u.status = #{status}
  69. </if>
  70. <if test="userType != null and userType != ''">
  71. AND u.user_type = #{userType}
  72. </if>
  73. <if test="userType != null and userType != ''">
  74. AND u.user_system = #{userSystem}
  75. </if>
  76. <if test="openId != null and openId != ''">
  77. AND u.open_id = #{openId}
  78. </if>
  79. <if test="sessionKey != null and sessionKey != ''">
  80. AND u.session_key = #{sessionKey}
  81. </if>
  82. <if test="relatedNo != null and relatedNo != ''">
  83. AND u.related_no = #{relatedNo}
  84. </if>
  85. <if test="phonenumber != null and phonenumber != ''">
  86. AND u.phonenumber like concat('%', #{phonenumber}, '%')
  87. </if>
  88. <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
  89. AND date_format(u.create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
  90. </if>
  91. <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
  92. AND date_format(u.create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
  93. </if>
  94. <if test="deptId != null and deptId != 0">
  95. AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE find_in_set(#{deptId}, ancestors) ))
  96. </if>
  97. <!-- 数据范围过滤 -->
  98. ${params.dataScope}
  99. </select>
  100. <select id="selectUserByUserName" parameterType="String" resultMap="SysUserResult">
  101. <include refid="selectUserVo"/>
  102. where u.user_name = #{userName}
  103. </select>
  104. <select id="selectUserById" parameterType="Long" resultMap="SysUserResult">
  105. <include refid="selectUserVo"/>
  106. where u.user_id = #{userId}
  107. </select>
  108. <select id="selectUserByopenId" parameterType="String" resultMap="SysUserResult">
  109. SELECT user_id, user_name, nick_name, user_type, user_system, open_id, open_id, del_flag FROM sys_user WHERE open_id = #{openId}
  110. </select>
  111. <select id="selectUserByTel" parameterType="String" resultMap="SysUserResult">
  112. SELECT user_id, user_name, nick_name, user_type, user_system, phonenumber, open_id, session_key, del_flag FROM sys_user WHERE phonenumber = #{phonenumber} and user_type = '11'
  113. </select>
  114. <select id="checkUserNameUnique" parameterType="String" resultType="int">
  115. select count(1) from sys_user where user_name = #{userName} limit 1
  116. </select>
  117. <select id="checkPhoneUnique" parameterType="String" resultMap="SysUserResult">
  118. select user_id, phonenumber from sys_user where phonenumber = #{phonenumber} limit 1
  119. </select>
  120. <select id="checkEmailUnique" parameterType="String" resultMap="SysUserResult">
  121. select user_id, email from sys_user where email = #{email} limit 1
  122. </select>
  123. <select id="warehouseSelectUserByTel" resultType="com.ruoyi.common.core.domain.entity.SysUser">
  124. SELECT user_id, user_name, nick_name, user_type, user_system, phonenumber, open_id, session_key, del_flag FROM sys_user WHERE phonenumber = #{phonenumber} and user_type = '00'
  125. </select>
  126. <insert id="insertUser" parameterType="SysUser" useGeneratedKeys="true" keyProperty="userId">
  127. insert into sys_user(
  128. <if test="userId != null and userId != 0">user_id,</if>
  129. <if test="deptId != null and deptId != 0">dept_id,</if>
  130. <if test="userName != null and userName != ''">user_name,</if>
  131. <if test="nickName != null and nickName != ''">nick_name,</if>
  132. <if test="email != null and email != ''">email,</if>
  133. <if test="avatar != null and avatar != ''">avatar,</if>
  134. <if test="phonenumber != null and phonenumber != ''">phonenumber,</if>
  135. <if test="sex != null and sex != ''">sex,</if>
  136. <if test="password != null and password != ''">password,</if>
  137. <if test="userType != null and userType != ''">user_type,</if>
  138. <if test="userSystem != null and userSystem != ''">user_system,</if>
  139. <if test="openId != null and openId != ''">open_id,</if>
  140. <if test="imgSrc != null and imgSrc != ''">img_src,</if>
  141. <if test="sessionKey != null and sessionKey != ''">session_key,</if>
  142. <if test="relatedNo != null and relatedNo != ''">related_no,</if>
  143. <if test="status != null and status != ''">status,</if>
  144. <if test="createBy != null and createBy != ''">create_by,</if>
  145. <if test="remark != null and remark != ''">remark,</if>
  146. create_time
  147. )values(
  148. <if test="userId != null and userId != ''">#{userId},</if>
  149. <if test="deptId != null and deptId != ''">#{deptId},</if>
  150. <if test="userName != null and userName != ''">#{userName},</if>
  151. <if test="nickName != null and nickName != ''">#{nickName},</if>
  152. <if test="email != null and email != ''">#{email},</if>
  153. <if test="avatar != null and avatar != ''">#{avatar},</if>
  154. <if test="phonenumber != null and phonenumber != ''">#{phonenumber},</if>
  155. <if test="sex != null and sex != ''">#{sex},</if>
  156. <if test="password != null and password != ''">#{password},</if>
  157. <if test="userType != null and userType != ''">#{userType},</if>
  158. <if test="userSystem != null and userSystem != ''">#{userSystem},</if>
  159. <if test="openId != null and openId != ''">#{openId},</if>
  160. <if test="imgSrc != null and imgSrc != ''">#{imgSrc},</if>
  161. <if test="sessionKey != null and sessionKey != ''">#{sessionKey},</if>
  162. <if test="status != null and status != ''">#{status},</if>
  163. <if test="createBy != null and createBy != ''">#{createBy},</if>
  164. <if test="remark != null and remark != ''">#{remark},</if>
  165. sysdate()
  166. )
  167. </insert>
  168. <update id="updateUser" parameterType="SysUser">
  169. update sys_user
  170. <set>
  171. <if test="deptId != null and deptId != 0">dept_id = #{deptId},</if>
  172. <if test="userName != null and userName != ''">user_name = #{userName},</if>
  173. <if test="nickName != null and nickName != ''">nick_name = #{nickName},</if>
  174. <if test="email != null and email != ''">email = #{email},</if>
  175. <if test="phonenumber != null and phonenumber != ''">phonenumber = #{phonenumber},</if>
  176. <if test="sex != null and sex != ''">sex = #{sex},</if>
  177. <if test="avatar != null and avatar != ''">avatar = #{avatar},</if>
  178. <if test="password != null and password != ''">password = #{password},</if>
  179. <if test="userType != null and userType != ''">user_type = #{userType},</if>
  180. <if test="userSystem != null and userSystem != ''">user_system = #{userSystem},</if>
  181. <if test="openId != null and openId != ''">open_id = #{openId},</if>
  182. <if test="imgSrc != null and imgSrc != ''">img_src = #{imgSrc},</if>
  183. <if test="sessionKey != null and sessionKey != ''">session_key = #{sessionKey},</if>
  184. <if test="relatedNo != null and relatedNo != ''">related_no = #{relatedNo},</if>
  185. <if test="status != null and status != ''">status = #{status},</if>
  186. <if test="loginIp != null and loginIp != ''">login_ip = #{loginIp},</if>
  187. <if test="loginDate != null">login_date = #{loginDate},</if>
  188. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  189. <if test="remark != null">remark = #{remark},</if>
  190. update_time = sysdate()
  191. </set>
  192. where user_id = #{userId}
  193. </update>
  194. <update id="updateUserRelatedNo" parameterType="SysUser">
  195. update sys_user set related_no = #{relatedNo}, img_src = #{imgSrc} where open_id = #{openId}
  196. </update>
  197. <update id="unsubscribeUserRelatedNo" parameterType="SysUser">
  198. update sys_user set related_no = #{relatedNo}, status = '1', del_flag = '2' where open_id = #{openId}
  199. </update>
  200. <update id="updateUserStatus" parameterType="SysUser">
  201. update sys_user set status = #{status} where user_id = #{userId}
  202. </update>
  203. <update id="updateUserAvatar" parameterType="SysUser">
  204. update sys_user set avatar = #{avatar} where user_name = #{userName}
  205. </update>
  206. <update id="resetUserPwd" parameterType="SysUser">
  207. update sys_user set password = #{password} where user_name = #{userName}
  208. </update>
  209. <update id="updateCarsDriverNamePhone" parameterType="Long">
  210. UPDATE sys_user u
  211. LEFT JOIN F_TMSORDERBILLSCARS car ON u.user_id = car.driver_user_id
  212. SET car.driver_name = u.nick_name,
  213. car.driver_tel = u.phonenumber
  214. WHERE
  215. car.driver_user_id IS NOT NULL
  216. AND u.user_id = #{userId}
  217. </update>
  218. <delete id="deleteUserById" parameterType="Long">
  219. delete from sys_user where user_id = #{userId}
  220. </delete>
  221. <delete id="deleteUserByIds" parameterType="Long">
  222. update sys_user set del_flag = '2' where user_id in
  223. <foreach collection="array" item="userId" open="(" separator="," close=")">
  224. #{userId}
  225. </foreach>
  226. </delete>
  227. <select id="selectUserNameFO" resultType="map">
  228. SELECT
  229. su.user_id userId,
  230. su.user_name userName
  231. FROM
  232. sys_user su
  233. LEFT JOIN sys_dict_data sd ON sd.dict_value = su.user_system
  234. AND sd.dict_type = 'user_system'
  235. WHERE
  236. su.STATUS = '0'
  237. AND sd.dict_label = '凯和'
  238. ORDER BY
  239. su.user_id
  240. </select>
  241. </mapper>