SysUserMapper.xml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <!--
  4. 这个文件是自动生成的。
  5. 不要修改此文件。所有改动将在下次重新自动生成时丢失。
  6. -->
  7. <mapper namespace="com.yonge.cooleshow.auth.dal.dao.SysUserDao">
  8. <resultMap type="com.yonge.cooleshow.auth.api.entity.SysUser" id="SysUser">
  9. <result column="id_" property="id"/>
  10. <result column="username_" property="username"/>
  11. <result column="real_name_" property="realName"/>
  12. <result column="password_" property="password"/>
  13. <result column="salt_" property="salt"/>
  14. <result column="phone_" property="phone"/>
  15. <result column="avatar_" property="avatar"/>
  16. <result column="create_time_" property="createTime"/>
  17. <result column="update_time_" property="updateTime"/>
  18. <result column="lock_flag_" property="lockFlag"/>
  19. <result column="del_flag_" property="delFlag"/>
  20. <result column="wx_openid_" property="wxOpenid"/>
  21. <result column="qq_openid_" property="qqOpenid"/>
  22. <result column="user_type_" property="userType"/>
  23. <result column="gender_" property="gender"/>
  24. <result column="nation_" property="nation"/>
  25. <result column="birthdate_" property="birthdate"/>
  26. <result column="email_" property="email"/>
  27. <result column="im_token_" property="imToken"/>
  28. <result column="id_card_no_" property="idCardNo"/>
  29. <result column="wechat_id_" property="wechatId"/>
  30. <result column="is_super_admin_" property="isSuperAdmin"/>
  31. <result column="certificate_type_" property="certificateType"/>
  32. <result column="last_username_time_" property="lastUsernameTime"/>
  33. <result column="tenant_id_" property="tenantId"/>
  34. </resultMap>
  35. <!-- 查询条件 -->
  36. <sql id="queryCondition">
  37. <where>
  38. and del_flag_ = 0
  39. <if test="userStartDate != null">
  40. and create_time_ &gt;= #{createStartDate}
  41. </if>
  42. <if test="userEndDate != null">
  43. and create_time_ &lt;= #{createEndDate}
  44. </if>
  45. <if test="userType != null">
  46. and user_type_ = #{userType}
  47. </if>
  48. </where>
  49. </sql>
  50. <!-- 根据主键查询一条记录 -->
  51. <select id="get" resultMap="SysUser">
  52. SELECT su.* FROM sys_user su
  53. WHERE su.id_ = #{id}
  54. </select>
  55. <!-- 全查询 -->
  56. <select id="findAll" resultMap="SysUser">
  57. SELECT * FROM sys_user where del_flag_ = 0 ORDER BY id_
  58. </select>
  59. <!-- 向数据库增加一条记录 -->
  60. <insert id="insert" parameterType="com.yonge.cooleshow.auth.api.entity.SysUser" useGeneratedKeys="true" keyColumn="id"
  61. keyProperty="id">
  62. INSERT INTO sys_user
  63. (is_super_admin_,im_token_,id_,username_,salt_,phone_,avatar_,create_time_,update_time_,wx_openid_,qq_openid_,user_type_,
  64. gender_,nation_,birthdate_,email_,id_card_no_,wechat_id_,real_name_,certificate_type_)
  65. VALUES(#{isSuperAdmin},#{imToken},#{id},#{username},#{salt},#{phone},#{avatar},now(),now(),#{wxOpenid},#{qqOpenid},#{userType},
  66. #{gender},#{nation},#{birthdate},#{email},#{idCardNo},#{wechatId},#{realName},#{certificateType})
  67. </insert>
  68. <insert id="saveTeacher">
  69. INSERT INTO teacher (user_id_,create_time_,update_time_)VALUES(#{userId},NOW(),NOW())
  70. ON DUPLICATE KEY UPDATE user_id_ = VALUES(user_id_)
  71. </insert>
  72. <insert id="saveStudent">
  73. INSERT INTO student (user_id_,create_time_,update_time_,hide_flag_) VALUES(#{userId},NOW(),NOW(),0)
  74. ON DUPLICATE KEY UPDATE user_id_ = VALUES(user_id_)
  75. </insert>
  76. <select id="queryUserAccount" resultType="java.lang.Boolean">
  77. select count(1) from user_cash_account where #{userId}
  78. </select>
  79. <insert id="createUserAccount">
  80. INSERT INTO user_cash_account (user_id_,create_time_,update_time_)VALUES(#{userId},NOW(),NOW())
  81. ON DUPLICATE KEY UPDATE user_id_ = VALUES(user_id_)
  82. </insert>
  83. <!-- 根据主键查询一条记录 -->
  84. <update id="update" parameterType="com.yonge.cooleshow.auth.api.entity.SysUser">
  85. UPDATE sys_user
  86. <set>
  87. <if test="delFlag != null">
  88. del_flag_ = #{delFlag},
  89. </if>
  90. <if test="wxOpenid != null and wxOpenid != ''">
  91. wx_openid_ = #{wxOpenid},
  92. </if>
  93. <if test="avatar != null and avatar != ''">
  94. avatar_ = #{avatar},
  95. </if>
  96. <if test="email != null and email != ''">
  97. email_ = #{email},
  98. </if>
  99. <if test="gender != null">
  100. gender_ = #{gender},
  101. </if>
  102. <if test="salt != null and salt != ''">
  103. salt_ = #{salt},
  104. </if>
  105. <if test="username != null and username != ''">
  106. username_ = #{username},
  107. </if>
  108. <if test="userType != null and userType != ''">
  109. user_type_ = #{userType},
  110. </if>
  111. <if test="updateTime != null">
  112. update_time_ = NOW(),
  113. </if>
  114. <if test="lockFlag != null">
  115. lock_flag_ = #{lockFlag},
  116. </if>
  117. <if test="birthdate != null">
  118. birthdate_ = #{birthdate},
  119. </if>
  120. <if test="phone != null and phone != ''">
  121. phone_ = #{phone},
  122. </if>
  123. <if test="qqOpenid != null and qqOpenid != ''">
  124. qq_openid_ = #{qqOpenid},
  125. </if>
  126. <if test="nation != null and nation != ''">
  127. nation_ = #{nation},
  128. </if>
  129. <if test="imToken != null and imToken != ''">
  130. im_token_ = #{imToken},
  131. </if>
  132. <if test="idCardNo != null and idCardNo != ''">
  133. id_card_no_ = #{idCardNo},
  134. </if>
  135. <if test="password != null and password != ''">
  136. password_ = #{password},
  137. </if>
  138. <if test="wechatId != null and wechatId != ''">
  139. wechat_id_ = #{wechatId},
  140. </if>
  141. <if test="realName != null and realName != ''">
  142. real_name_ = #{realName},
  143. </if>
  144. <if test="certificateType != null">
  145. certificate_type_ = #{certificateType},
  146. </if>
  147. <if test="lastUsernameTime != null">
  148. last_username_time_ = #{lastUsernameTime},
  149. </if>
  150. </set>
  151. WHERE del_flag_ = 0 and id_ = #{id}
  152. </update>
  153. <update id="updatePasswordReq">
  154. UPDATE sys_user SET password_ = #{password} WHERE del_flag_ = 0 and phone_ = #{mobile}
  155. </update>
  156. <update id="refreshImToken">
  157. UPDATE sys_user SET im_token_ = #{imToken},update_time_ = NOW() WHERE del_flag_ = 0 and id_ = #{userId}
  158. </update>
  159. <!-- 根据主键删除一条记录 -->
  160. <delete id="delete">
  161. UPDATE sys_user SET del_flag_ = 1 WHERE id_ = #{id}
  162. </delete>
  163. <!-- 分页查询 -->
  164. <select id="queryPage" resultMap="SysUser" parameterType="map">
  165. SELECT * FROM sys_user
  166. <include refid="queryCondition"/>
  167. <include refid="global.orderby"/>
  168. <include refid="global.limit"/>
  169. </select>
  170. <!-- 查询当前表的总记录数 -->
  171. <select id="queryCount" resultType="int">
  172. SELECT COUNT(*) FROM sys_user
  173. <include refid="queryCondition"/>
  174. </select>
  175. <select id="queryByUsername" resultMap="SysUser">
  176. select * from sys_user where del_flag_ = 0 and username_ = #{username} OR phone_ = #{username} LIMIT 1 FOR UPDATE
  177. </select>
  178. <select id="queryByPhone" resultMap="SysUser">
  179. select * from sys_user where del_flag_ = 0 and phone_ = #{phone} OR username_ = #{phone} LIMIT 1
  180. </select>
  181. <select id="queryLockByPhone" resultMap="SysUser">
  182. select * from sys_user where del_flag_ = 0 and phone_ = #{phone} OR username_ = #{phone} LIMIT 1 FOR UPDATE
  183. </select>
  184. <resultMap id="ImUserModel" type="com.yonge.cooleshow.common.entity.ImUserModel">
  185. <result column="id_" property="id"/>
  186. <result property="name" column="username_"/>
  187. <result property="portrait" column="avatar_"/>
  188. </resultMap>
  189. <select id="getBasic" resultMap="ImUserModel">
  190. select CASE WHEN user_type_ LIKE '%TEACHER%' OR user_type_ LIKE '%SYSTEM%' THEN real_name_ ELSE username_ END username_,id_,avatar_
  191. from sys_user where del_flag_ = 0 and id_ = #{userId} LIMIT 1
  192. </select>
  193. <select id="queryByStatus" resultMap="SysUser">
  194. select * from sys_user where del_flag_ = 0 and lock_flag_ = #{status}
  195. </select>
  196. <select id="findUserBySalt" resultMap="SysUser">
  197. SELECT * FROM sys_user WHERE del_flag_ = 0 and salt_ IS NOT NULL AND salt_ = 'replace' AND user_type_ LIKE CONCAT('%',#{userType},'%') LIMIT 1
  198. </select>
  199. <select id="getTeacherOrganId" resultType="java.lang.Integer">
  200. SELECT organ_id_ FROM teacher WHERE id_ = #{userId}
  201. </select>
  202. <select id="queryByPhoneAndClient" resultMap="SysUser">
  203. select * from sys_user where del_flag_ = 0 and (phone_ = #{phone} OR username_ = #{phone}) AND user_type_ LIKE CONCAT('%',#{client},'%') LIMIT 1 FOR UPDATE
  204. </select>
  205. <update id="updateUserCard">
  206. UPDATE sys_user
  207. set
  208. <if test="param.realName != null and param.realName != ''">
  209. real_name_ = #{param.realName},
  210. </if>
  211. <if test="param.idCardNo != null and param.idCardNo != ''">
  212. id_card_no_ = #{param.idCardNo},
  213. </if>
  214. <if test="param.gender != null">
  215. gender_ = #{param.gender},
  216. </if>
  217. <if test="param.birthday != null">
  218. birthdate_ = #{param.birthday},
  219. </if>
  220. update_time_ = now()
  221. WHERE del_flag_ = 0 and id_ = #{param.userId}
  222. </update>
  223. <select id="getSetDetail" resultType="com.yonge.cooleshow.auth.api.vo.UserSetVo">
  224. SELECT
  225. u.avatar_ as avatar,
  226. u.username_ as username,
  227. u.gender_ as gender,
  228. u.phone_ as phone,
  229. u.birthdate_ as birthdate,
  230. (case when isnull(u.id_card_no_) then 0 else 1 end) as isReal
  231. FROM sys_user u
  232. where u.del_flag_ = 0 and u.id_ = #{id}
  233. </select>
  234. <update id="updatetSetDetail">
  235. UPDATE sys_user
  236. set
  237. <if test="param.avatar != null and param.avatar != ''">
  238. avatar_ = #{param.avatar},
  239. </if>
  240. <if test="param.username != null and param.username != ''">
  241. username_ = #{param.username},
  242. <if test="param.clientId != null and param.clientId == 'TEACHER'">
  243. last_username_time_ = now(),
  244. </if>
  245. </if>
  246. <if test="param.gender != null">
  247. gender_ = #{param.gender},
  248. </if>
  249. <if test="param.birthdate != null">
  250. birthdate_ = #{param.birthdate},
  251. </if>
  252. update_time_ = now()
  253. WHERE del_flag_ = 0 and id_ = #{id}
  254. </update>
  255. <update id="updateImGroupMember">
  256. UPDATE im_group_member SET avatar_ = #{avatar},nickname_ = #{username} WHERE user_id_ = #{userId}
  257. </update>
  258. <update id="updateImUserFriend">
  259. UPDATE im_user_friend SET friend_avatar_ = #{avatar},friend_nickname_ = #{username} WHERE friend_id_ = #{userId}
  260. </update>
  261. <update id="logoffById">
  262. update sys_user set del_flag_ = 1, phone_ = concat('D', ${num}, '+', phone_) where id_ = ${userId}
  263. </update>
  264. <select id="queryEmployeeList" resultMap="SysUser">
  265. select su.*
  266. from employee e
  267. left join sys_user su on su.id_ = e.user_id_
  268. <where>
  269. su.del_flag_ = 0
  270. <if test="createStartDate != null and createStartDate != ''">
  271. and #{createStartDate} &lt;= e.create_time_
  272. </if>
  273. <if test="createEndDate != null and createEndDate != ''">
  274. and #{createEndDate} &gt; e.create_time_
  275. </if>
  276. </where>
  277. </select>
  278. <select id="queryHistoryUserById" resultMap="SysUser">
  279. select * from sys_user
  280. where phone_ like CONCAT('%',(select phone_ from sys_user where id_ = #{id} and del_flag_ = 0),'%')
  281. </select>
  282. <select id="getUnCompCourseNum" resultType="java.lang.Integer">
  283. select count(1) from course_schedule cs
  284. where cs.teacher_id_ = #{userId}
  285. and status_ in ('NOT_START','ING')
  286. </select>
  287. <select id="getTenantByClient" resultType="java.lang.Long">
  288. select tenant_id_ from
  289. <choose>
  290. <when test="clientId == 'STUDENT'">
  291. student
  292. </when>
  293. <when test="clientId == 'TEACHER'">
  294. teacher
  295. </when>
  296. <when test="clientId == 'ORGANIZATION'">
  297. tenant_staff
  298. </when>
  299. <otherwise>
  300. employee
  301. </otherwise>
  302. </choose>
  303. where user_id_ = #{userId}
  304. </select>
  305. <update id="updateLockStatus">
  306. <if test="sysUserType == 'STUDENT'">
  307. update student set lock_flag_ = #{lockFlag} where user_id_ = #{userId}
  308. </if>
  309. <if test="sysUserType == 'TEACHER'">
  310. update teacher set lock_flag_ = #{lockFlag} where user_id_ = #{userId}
  311. </if>
  312. <if test="sysUserType == 'SYSTEM'">
  313. update employee set lock_flag_ = #{lockFlag} where user_id_ = #{userId}
  314. </if>
  315. </update>
  316. <update id="logoffByPhone">
  317. update sys_user set del_flag_ = 1, phone_ = concat(#{num},'D', phone_),update_time_ = now() where phone_ = #{phone}
  318. </update>
  319. <update id="updateLockStatusByPhone">
  320. update student set lock_flag_ = 1 where user_id_ = (select id_ from sys_user where phone_ = #{phone});
  321. update teacher set lock_flag_ = 1 where user_id_ = (select id_ from sys_user where phone_ = #{phone});
  322. update employee set lock_flag_ = 1 where user_id_ = (select id_ from sys_user where phone_ = #{phone});
  323. </update>
  324. <select id="countByPhone" resultType="java.lang.Integer">
  325. SELECT count(1) FROM sys_user WHERE phone_ LIKE CONCAT('%',#{phone},'%')
  326. </select>
  327. <select id="getSysUserByOpenId" resultType="com.yonge.cooleshow.auth.api.entity.SysUser">
  328. SELECT t1.*
  329. FROM sys_user t1 LEFT JOIN
  330. <choose>
  331. <when test="clientId == 'STUDENT'">
  332. student
  333. </when>
  334. <when test="clientId == 'TEACHER'">
  335. teacher
  336. </when>
  337. <when test="clientId == 'ORGANIZATION'">
  338. tenant_staff
  339. </when>
  340. <otherwise>
  341. employee
  342. </otherwise>
  343. </choose> t2 ON (t1.id_ = t2.user_id_)
  344. WHERE t1.del_flag_ = 0 and t2.wx_openid_ = #{openId} LIMIT 1
  345. </select>
  346. <update id="updateStudentHideFlag">
  347. update student set hide_flag_ = #{hideFlag} where user_id_ = #{userId}
  348. </update>
  349. <update id="updateAvatar">
  350. <if test="clientId == 'STUDENT'">
  351. update student set avatar_ = #{avatar} where user_id_ = #{id}
  352. </if>
  353. <if test="clientId == 'TEACHER'">
  354. update teacher set avatar_ = #{avatar} where user_id_ = #{id}
  355. </if>
  356. <if test="clientId == 'SYSTEM'">
  357. update sys_user set avatar_ = #{avatar} where id_ = #{id}
  358. </if>
  359. </update>
  360. <select id="getCustomerServiceByFriendLeast" resultMap="SysUser">
  361. select m.*
  362. from (SELECT te.user_id_,
  363. count(k.user_id_) friends
  364. from teacher te
  365. left join sys_user su on te.user_id_ = su.id_
  366. left join (select s.user_id_, s.customer_id_
  367. from student s
  368. where s.customer_id_ is not null
  369. union all
  370. select te.user_id_, te.customer_id_
  371. from teacher te
  372. where te.customer_service_ = 0 and te.customer_id_ is not null) k on te.user_id_ = k.customer_id_
  373. where te.lock_flag_ = 0
  374. and te.customer_service_ = 1
  375. and su.del_flag_ = 0
  376. and su.lock_flag_ = 0
  377. group by te.user_id_
  378. order by friends
  379. limit 1) t
  380. left join sys_user m on m.id_ = t.user_id_
  381. </select>
  382. <update id="updateNameAndImg">
  383. update sys_user set bak_username_ = username_,username_ = concat('账号已注销',id_)
  384. ,avatar_ = (select param_value_ from sys_config where param_name_ = 'logoff_img') where id_= #{userId};
  385. </update>
  386. </mapper>