SysUserMapper.xml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  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. </resultMap>
  34. <!-- 查询条件 -->
  35. <sql id="queryCondition">
  36. <where>
  37. and del_flag_ = 0
  38. <if test="userStartDate != null">
  39. and create_time_ &gt;= #{createStartDate}
  40. </if>
  41. <if test="userEndDate != null">
  42. and create_time_ &lt;= #{createEndDate}
  43. </if>
  44. <if test="userType != null">
  45. and user_type_ = #{userType}
  46. </if>
  47. </where>
  48. </sql>
  49. <!-- 根据主键查询一条记录 -->
  50. <select id="get" resultMap="SysUser">
  51. SELECT su.* FROM sys_user su
  52. WHERE su.del_flag_ = 0 and su.id_ = #{id}
  53. </select>
  54. <!-- 全查询 -->
  55. <select id="findAll" resultMap="SysUser">
  56. SELECT * FROM sys_user where del_flag_ = 0 ORDER BY id_
  57. </select>
  58. <!-- 向数据库增加一条记录 -->
  59. <insert id="insert" parameterType="com.yonge.cooleshow.auth.api.entity.SysUser" useGeneratedKeys="true" keyColumn="id"
  60. keyProperty="id">
  61. INSERT INTO sys_user
  62. (is_super_admin_,im_token_,id_,username_,salt_,phone_,avatar_,create_time_,update_time_,wx_openid_,qq_openid_,user_type_,
  63. gender_,nation_,birthdate_,email_,id_card_no_,wechat_id_,real_name_,certificate_type_)
  64. VALUES(#{isSuperAdmin},#{imToken},#{id},#{username},#{salt},#{phone},#{avatar},now(),now(),#{wxOpenid},#{qqOpenid},#{userType},
  65. #{gender},#{nation},#{birthdate},#{email},#{idCardNo},#{wechatId},#{realName},#{certificateType})
  66. </insert>
  67. <insert id="saveTeacher">
  68. INSERT INTO teacher (user_id_,create_time_,update_time_)VALUES(#{userId},NOW(),NOW())
  69. ON DUPLICATE KEY UPDATE user_id_ = VALUES(user_id_)
  70. </insert>
  71. <insert id="saveStudent">
  72. INSERT INTO student (user_id_,create_time_,update_time_) VALUES(#{userId},NOW(),NOW())
  73. ON DUPLICATE KEY UPDATE user_id_ = VALUES(user_id_)
  74. </insert>
  75. <select id="queryUserAccount" resultType="java.lang.Boolean">
  76. select count(1) from user_cash_account where #{userId}
  77. </select>
  78. <insert id="createUserAccount">
  79. INSERT INTO user_cash_account (user_id_,create_time_,update_time_)VALUES(#{userId},NOW(),NOW())
  80. ON DUPLICATE KEY UPDATE user_id_ = VALUES(user_id_)
  81. </insert>
  82. <!-- 根据主键查询一条记录 -->
  83. <update id="update" parameterType="com.yonge.cooleshow.auth.api.entity.SysUser">
  84. UPDATE sys_user
  85. <set>
  86. <if test="delFlag != null">
  87. del_flag_ = #{delFlag},
  88. </if>
  89. <if test="wxOpenid != null and wxOpenid != ''">
  90. wx_openid_ = #{wxOpenid},
  91. </if>
  92. <if test="avatar != null and avatar != ''">
  93. avatar_ = #{avatar},
  94. </if>
  95. <if test="email != null and email != ''">
  96. email_ = #{email},
  97. </if>
  98. <if test="gender != null">
  99. gender_ = #{gender},
  100. </if>
  101. <if test="salt != null and salt != ''">
  102. salt_ = #{salt},
  103. </if>
  104. <if test="username != null and username != ''">
  105. username_ = #{username},
  106. </if>
  107. <if test="userType != null and userType != ''">
  108. user_type_ = #{userType},
  109. </if>
  110. <if test="updateTime != null">
  111. update_time_ = NOW(),
  112. </if>
  113. <if test="lockFlag != null">
  114. lock_flag_ = #{lockFlag},
  115. </if>
  116. <if test="birthdate != null">
  117. birthdate_ = #{birthdate},
  118. </if>
  119. <if test="phone != null and phone != ''">
  120. phone_ = #{phone},
  121. </if>
  122. <if test="qqOpenid != null and qqOpenid != ''">
  123. qq_openid_ = #{qqOpenid},
  124. </if>
  125. <if test="nation != null and nation != ''">
  126. nation_ = #{nation},
  127. </if>
  128. <if test="imToken != null and imToken != ''">
  129. im_token_ = #{imToken},
  130. </if>
  131. <if test="idCardNo != null and idCardNo != ''">
  132. id_card_no_ = #{idCardNo},
  133. </if>
  134. <if test="password != null and password != ''">
  135. password_ = #{password},
  136. </if>
  137. <if test="wechatId != null and wechatId != ''">
  138. wechat_id_ = #{wechatId},
  139. </if>
  140. <if test="realName != null and realName != ''">
  141. real_name_ = #{realName},
  142. </if>
  143. <if test="certificateType != null">
  144. certificate_type_ = #{certificateType},
  145. </if>
  146. <if test="lastUsernameTime != null">
  147. last_username_time_ = #{lastUsernameTime},
  148. </if>
  149. </set>
  150. WHERE del_flag_ = 0 and id_ = #{id}
  151. </update>
  152. <update id="updatePasswordReq">
  153. UPDATE sys_user SET password_ = #{password} WHERE del_flag_ = 0 and phone_ = #{mobile}
  154. </update>
  155. <update id="refreshImToken">
  156. UPDATE sys_user SET im_token_ = #{imToken},update_time_ = NOW() WHERE del_flag_ = 0 and id_ = #{userId}
  157. </update>
  158. <!-- 根据主键删除一条记录 -->
  159. <delete id="delete">
  160. UPDATE sys_user SET del_flag_ = 1 WHERE id_ = #{id}
  161. </delete>
  162. <!-- 分页查询 -->
  163. <select id="queryPage" resultMap="SysUser" parameterType="map">
  164. SELECT * FROM sys_user
  165. <include refid="queryCondition"/>
  166. <include refid="global.orderby"/>
  167. <include refid="global.limit"/>
  168. </select>
  169. <!-- 查询当前表的总记录数 -->
  170. <select id="queryCount" resultType="int">
  171. SELECT COUNT(*) FROM sys_user
  172. <include refid="queryCondition"/>
  173. </select>
  174. <select id="queryByUsername" resultMap="SysUser">
  175. select * from sys_user where del_flag_ = 0 and username_ = #{username} OR phone_ = #{username} LIMIT 1 FOR UPDATE
  176. </select>
  177. <select id="queryByPhone" resultMap="SysUser">
  178. select * from sys_user where del_flag_ = 0 and phone_ = #{phone} OR username_ = #{phone} LIMIT 1
  179. </select>
  180. <select id="queryLockByPhone" resultMap="SysUser">
  181. select * from sys_user where del_flag_ = 0 and phone_ = #{phone} OR username_ = #{phone} LIMIT 1 FOR UPDATE
  182. </select>
  183. <resultMap id="ImUserModel" type="com.yonge.cooleshow.common.entity.ImUserModel">
  184. <result column="id_" property="id"/>
  185. <result property="name" column="username_"/>
  186. <result property="portrait" column="avatar_"/>
  187. </resultMap>
  188. <select id="getBasic" resultMap="ImUserModel">
  189. select CASE WHEN user_type_ LIKE '%TEACHER%' OR user_type_ LIKE '%SYSTEM%' THEN real_name_ ELSE username_ END username_,id_,avatar_
  190. from sys_user where del_flag_ = 0 and id_ = #{userId} LIMIT 1
  191. </select>
  192. <select id="queryByStatus" resultMap="SysUser">
  193. select * from sys_user where del_flag_ = 0 and lock_flag_ = #{status}
  194. </select>
  195. <select id="findUserBySalt" resultMap="SysUser">
  196. SELECT * FROM sys_user WHERE del_flag_ = 0 and salt_ IS NOT NULL AND salt_ = 'replace' AND user_type_ LIKE CONCAT('%',#{userType},'%') LIMIT 1
  197. </select>
  198. <select id="getTeacherOrganId" resultType="java.lang.Integer">
  199. SELECT organ_id_ FROM teacher WHERE id_ = #{userId}
  200. </select>
  201. <select id="queryByPhoneAndClient" resultMap="SysUser">
  202. select * from sys_user where del_flag_ = 0 and (phone_ = #{phone} OR username_ = #{phone}) AND user_type_ LIKE CONCAT('%',#{client},'%') LIMIT 1 FOR UPDATE
  203. </select>
  204. <update id="updateUserCard">
  205. UPDATE sys_user
  206. set
  207. <if test="param.realName != null and param.realName != ''">
  208. real_name_ = #{param.realName},
  209. </if>
  210. <if test="param.idCardNo != null and param.idCardNo != ''">
  211. id_card_no_ = #{param.idCardNo},
  212. </if>
  213. <if test="param.gender != null">
  214. gender_ = #{param.gender},
  215. </if>
  216. <if test="param.birthday != null">
  217. birthdate_ = #{param.birthday},
  218. </if>
  219. update_time_ = now()
  220. WHERE del_flag_ = 0 and id_ = #{param.userId}
  221. </update>
  222. <select id="getSetDetail" resultType="com.yonge.cooleshow.auth.api.vo.UserSetVo">
  223. SELECT
  224. u.avatar_ as avatar,
  225. u.username_ as username,
  226. u.gender_ as gender,
  227. u.phone_ as phone,
  228. u.birthdate_ as birthdate,
  229. (case when isnull(u.id_card_no_) then 0 else 1 end) as isReal
  230. FROM sys_user u
  231. where u.del_flag_ = 0 and u.id_ = #{id}
  232. </select>
  233. <update id="updatetSetDetail">
  234. UPDATE sys_user
  235. set
  236. <if test="param.avatar != null and param.avatar != ''">
  237. avatar_ = #{param.avatar},
  238. </if>
  239. <if test="param.username != null and param.username != ''">
  240. username_ = #{param.username},
  241. <if test="param.clientId != null and param.clientId == 'TEACHER'">
  242. last_username_time_ = now(),
  243. </if>
  244. </if>
  245. <if test="param.gender != null">
  246. gender_ = #{param.gender},
  247. </if>
  248. <if test="param.birthdate != null">
  249. birthdate_ = #{param.birthdate},
  250. </if>
  251. update_time_ = now()
  252. WHERE del_flag_ = 0 and id_ = #{id}
  253. </update>
  254. <update id="updateImGroupMember">
  255. UPDATE im_group_member SET avatar_ = #{avatar},nickname_ = #{username} WHERE user_id_ = #{userId}
  256. </update>
  257. <update id="updateImUserFriend">
  258. UPDATE im_user_friend SET friend_avatar_ = #{avatar},friend_nickname_ = #{username} WHERE friend_id_ = #{userId}
  259. </update>
  260. <update id="logoffById">
  261. update sys_user set del_flag_ = 1, phone_ = concat('D', ${num}, '+', phone_) where id_ = ${userId}
  262. </update>
  263. <update id="logoffByPhone">
  264. update sys_user set del_flag_ = 1, phone_ = concat('D', phone_),update_time_ = now() where phone_ = #{phone}
  265. </update>
  266. <select id="queryEmployeeList" resultMap="SysUser">
  267. select su.*
  268. from employee e
  269. left join sys_user su on su.id_ = e.user_id_
  270. <where>
  271. su.del_flag_ = 0
  272. <if test="createStartDate != null and createStartDate != ''">
  273. and #{createStartDate} &lt;= e.create_time_
  274. </if>
  275. <if test="createEndDate != null and createEndDate != ''">
  276. and #{createEndDate} &gt; e.create_time_
  277. </if>
  278. </where>
  279. </select>
  280. <select id="queryHistoryUserById" resultMap="SysUser">
  281. select * from sys_user
  282. where phone_ like CONCAT('%',(select phone_ from sys_user where id_ = #{id} and del_flag_ = 0),'%')
  283. </select>
  284. <select id="getUnCompCourseNum" resultType="java.lang.Integer">
  285. select count(1) from course_schedule cs
  286. where cs.teacher_id_ = #{userId}
  287. and status_ in ('NOT_START','ING')
  288. </select>
  289. <select id="getTenantByClient" resultType="java.lang.Long">
  290. select tenant_id_ from
  291. <choose>
  292. <when test="clientId == 'STUDENT'">
  293. student
  294. </when>
  295. <when test="clientId == 'TEACHER'">
  296. teacher
  297. </when>
  298. <when test="clientId == 'ORGANIZATION'">
  299. tenant_staff
  300. </when>
  301. <otherwise>
  302. employee
  303. </otherwise>
  304. </choose>
  305. where user_id_ = #{userId}
  306. </select>
  307. <update id="updateLockStatus">
  308. <if test="sysUserType == 'STUDENT'">
  309. update student set lock_flag_ = #{lockFlag} where user_id_ = #{userId}
  310. </if>
  311. <if test="sysUserType == 'TEACHER'">
  312. update teacher set lock_flag_ = #{lockFlag} where user_id_ = #{userId}
  313. </if>
  314. <if test="sysUserType == 'SYSTEM'">
  315. update employee set lock_flag_ = #{lockFlag} where user_id_ = #{userId}
  316. </if>
  317. </update>
  318. <update id="logoffByPhone">
  319. update sys_user set del_flag_ = 1, phone_ = concat(#{num},'D', phone_),update_time_ = now() where phone_ = #{phone}
  320. </update>
  321. <update id="updateLockStatusByPhone">
  322. update student set lock_flag_ = 1 where user_id_ = (select id_ from sys_user where phone_ = #{phone});
  323. update teacher set lock_flag_ = 1 where user_id_ = (select id_ from sys_user where phone_ = #{phone});
  324. update employee set lock_flag_ = 1 where user_id_ = (select id_ from sys_user where phone_ = #{phone});
  325. </update>
  326. <select id="countByPhone" resultType="java.lang.Integer">
  327. SELECT count(1) FROM sys_user WHERE phone_ LIKE CONCAT('%',#{phone},'%')
  328. </select>
  329. <select id="getSysUserByOpenId" resultType="com.yonge.cooleshow.auth.api.entity.SysUser">
  330. SELECT t1.*
  331. FROM sys_user t1 LEFT JOIN
  332. <choose>
  333. <when test="clientId == 'STUDENT'">
  334. student
  335. </when>
  336. <when test="clientId == 'TEACHER'">
  337. teacher
  338. </when>
  339. <when test="clientId == 'ORGANIZATION'">
  340. tenant_staff
  341. </when>
  342. <otherwise>
  343. employee
  344. </otherwise>
  345. </choose> t2 ON (t1.id_ = t2.user_id_)
  346. WHERE t1.del_flag_ = 0 and t2.wx_openid_ = #{openId} LIMIT 1
  347. </select>
  348. </mapper>