SysUserMapper.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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="isSuperAdmin != null">
  142. is_super_admin_ = #{isSuperAdmin},
  143. </if>
  144. <if test="certificateType != null">
  145. certificate_type_ = #{certificateType},
  146. </if>
  147. </set>
  148. WHERE del_flag_ = 0 and id_ = #{id}
  149. </update>
  150. <update id="updatePasswordReq">
  151. UPDATE sys_user SET password_ = #{password} WHERE del_flag_ = 0 and phone_ = #{mobile}
  152. </update>
  153. <update id="refreshImToken">
  154. UPDATE sys_user SET im_token_ = #{imToken},update_time_ = NOW() WHERE del_flag_ = 0 and id_ = #{userId}
  155. </update>
  156. <!-- 根据主键删除一条记录 -->
  157. <delete id="delete">
  158. UPDATE sys_user SET del_flag_ = 1 WHERE id_ = #{id}
  159. </delete>
  160. <!-- 分页查询 -->
  161. <select id="queryPage" resultMap="SysUser" parameterType="map">
  162. SELECT * FROM sys_user
  163. <include refid="queryCondition"/>
  164. <include refid="global.orderby"/>
  165. <include refid="global.limit"/>
  166. </select>
  167. <!-- 查询当前表的总记录数 -->
  168. <select id="queryCount" resultType="int">
  169. SELECT COUNT(*) FROM sys_user
  170. <include refid="queryCondition"/>
  171. </select>
  172. <select id="queryByUsername" resultMap="SysUser">
  173. select * from sys_user where del_flag_ = 0 and username_ = #{username} OR phone_ = #{username} LIMIT 1 FOR UPDATE
  174. </select>
  175. <select id="queryByPhone" resultMap="SysUser">
  176. select * from sys_user where del_flag_ = 0 and phone_ = #{phone} OR username_ = #{phone} LIMIT 1
  177. </select>
  178. <select id="queryLockByPhone" resultMap="SysUser">
  179. select * from sys_user where del_flag_ = 0 and phone_ = #{phone} OR username_ = #{phone} LIMIT 1 FOR UPDATE
  180. </select>
  181. <resultMap id="ImUserModel" type="com.yonge.cooleshow.common.entity.ImUserModel">
  182. <result column="id_" property="id"/>
  183. <result property="name" column="username_"/>
  184. <result property="portrait" column="avatar_"/>
  185. </resultMap>
  186. <select id="getBasic" resultMap="ImUserModel">
  187. select CASE WHEN user_type_ LIKE '%TEACHER%' OR user_type_ LIKE '%SYSTEM%' THEN real_name_ ELSE username_ END username_,id_,avatar_
  188. from sys_user where del_flag_ = 0 and id_ = #{userId} LIMIT 1
  189. </select>
  190. <select id="queryByStatus" resultMap="SysUser">
  191. select * from sys_user where del_flag_ = 0 and lock_flag_ = #{status}
  192. </select>
  193. <select id="findUserBySalt" resultMap="SysUser">
  194. SELECT * FROM sys_user WHERE del_flag_ = 0 and salt_ IS NOT NULL AND salt_ = 'replace' AND user_type_ LIKE CONCAT('%',#{userType},'%') LIMIT 1
  195. </select>
  196. <select id="getTeacherOrganId" resultType="java.lang.Integer">
  197. SELECT organ_id_ FROM teacher WHERE id_ = #{userId}
  198. </select>
  199. <select id="queryByPhoneAndClient" resultMap="SysUser">
  200. select * from sys_user where del_flag_ = 0 and (phone_ = #{phone} OR username_ = #{phone}) AND user_type_ LIKE CONCAT('%',#{client},'%') LIMIT 1 FOR UPDATE
  201. </select>
  202. <update id="updateUserCard">
  203. UPDATE sys_user
  204. set
  205. <if test="param.realName != null and param.realName != ''">
  206. real_name_ = #{param.realName},
  207. </if>
  208. <if test="param.idCardNo != null and param.idCardNo != ''">
  209. id_card_no_ = #{param.idCardNo},
  210. </if>
  211. <if test="param.gender != null">
  212. gender_ = #{param.gender},
  213. </if>
  214. <if test="param.birthday != null">
  215. birthdate_ = #{param.birthday},
  216. </if>
  217. update_time_ = now()
  218. WHERE del_flag_ = 0 and id_ = #{param.userId}
  219. </update>
  220. <select id="getSetDetail" resultType="com.yonge.cooleshow.auth.api.vo.UserSetVo">
  221. SELECT
  222. u.avatar_ as avatar,
  223. u.username_ as username,
  224. u.gender_ as gender,
  225. u.phone_ as phone,
  226. u.birthdate_ as birthdate,
  227. (case when isnull(u.id_card_no_) then 0 else 1 end) as isReal
  228. FROM sys_user u
  229. where u.del_flag_ = 0 and u.id_ = #{id}
  230. </select>
  231. <update id="updatetSetDetail">
  232. UPDATE sys_user
  233. set
  234. <if test="param.avatar != null and param.avatar != ''">
  235. avatar_ = #{param.avatar},
  236. </if>
  237. <if test="param.username != null and param.username != ''">
  238. username_ = #{param.username},
  239. </if>
  240. <if test="param.gender != null">
  241. gender_ = #{param.gender},
  242. </if>
  243. <if test="param.birthdate != null">
  244. birthdate_ = #{param.birthdate},
  245. </if>
  246. update_time_ = now()
  247. WHERE del_flag_ = 0 and id_ = #{id}
  248. </update>
  249. <update id="updateImGroupMember">
  250. UPDATE im_group_member SET avatar_ = #{avatar},nickname_ = #{username} WHERE user_id_ = #{userId}
  251. </update>
  252. <update id="updateImUserFriend">
  253. UPDATE im_user_friend SET friend_avatar_ = #{avatar},friend_nickname_ = #{username} WHERE friend_id_ = #{userId}
  254. </update>
  255. <update id="logoffById">
  256. update sys_user set del_flag_ = ${num}, phone_ = concat('D', ${num}, '+', phone_) where id_ = ${userId}
  257. </update>
  258. <select id="queryEmployeeList" resultMap="SysUser">
  259. select su.*
  260. from employee e
  261. left join sys_user su on su.id_ = e.user_id_
  262. <where>
  263. su.del_flag_ = 0
  264. <if test="createStartDate != null and createStartDate != ''">
  265. and #{createStartDate} &lt;= e.create_time_
  266. </if>
  267. <if test="createEndDate != null and createEndDate != ''">
  268. and #{createEndDate} &gt; e.create_time_
  269. </if>
  270. </where>
  271. </select>
  272. <select id="queryMaxVersionById" resultType="java.lang.Integer">
  273. select max(del_flag_) from sys_user
  274. where phone_ like CONCAT('%',(select phone_ from sys_user where id_ = #{id} and del_flag_ = 0),'%')
  275. </select>
  276. </mapper>