SysUserMapper.xml 12 KB

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