SysUserMapper.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. <if test="userStartDate != null">
  36. and create_time_ &gt;= #{createStartDate}
  37. </if>
  38. <if test="userEndDate != null">
  39. and create_time_ &lt;= #{createEndDate}
  40. </if>
  41. <if test="userType != null">
  42. and user_type_ = #{userType}
  43. </if>
  44. </sql>
  45. <!-- 根据主键查询一条记录 -->
  46. <select id="get" resultMap="SysUser">
  47. SELECT su.* FROM sys_user su
  48. WHERE su.id_ = #{id}
  49. </select>
  50. <!-- 全查询 -->
  51. <select id="findAll" resultMap="SysUser">
  52. SELECT * FROM sys_user ORDER BY id_
  53. </select>
  54. <!-- 向数据库增加一条记录 -->
  55. <insert id="insert" parameterType="com.yonge.cooleshow.auth.api.entity.SysUser" useGeneratedKeys="true" keyColumn="id"
  56. keyProperty="id">
  57. INSERT INTO sys_user
  58. (is_super_admin_,im_token_,id_,username_,salt_,phone_,avatar_,create_time_,update_time_,wx_openid_,qq_openid_,user_type_,
  59. gender_,nation_,birthdate_,email_,id_card_no_,wechat_id_,real_name_,certificate_type_)
  60. VALUES(#{isSuperAdmin},#{imToken},#{id},#{username},#{salt},#{phone},#{avatar},now(),now(),#{wxOpenid},#{qqOpenid},#{userType},
  61. #{gender},#{nation},#{birthdate},#{email},#{idCardNo},#{wechatId},#{realName},#{certificateType})
  62. </insert>
  63. <insert id="saveTeacher">
  64. INSERT INTO teacher (user_id_,create_time_,update_time_)VALUES(#{userId},NOW(),NOW())
  65. </insert>
  66. <insert id="saveStudent">
  67. INSERT INTO student (user_id_,create_time_,update_time_) VALUES(#{userId},NOW(),NOW())
  68. </insert>
  69. <select id="queryUserAccount" resultType="java.lang.Boolean">
  70. select count(1) from user_cash_account where #{userId}
  71. </select>
  72. <insert id="createUserAccount">
  73. INSERT INTO user_cash_account (user_id_,create_time_,update_time_)VALUES(#{userId},NOW(),NOW())
  74. ON DUPLICATE KEY UPDATE
  75. user_id_ = VALUES(user_id_)
  76. </insert>
  77. <!-- 根据主键查询一条记录 -->
  78. <update id="update" parameterType="com.yonge.cooleshow.auth.api.entity.SysUser">
  79. UPDATE sys_user
  80. <set>
  81. <if test="delFlag != null">
  82. del_flag_ = #{delFlag},
  83. </if>
  84. <if test="wxOpenid != null and wxOpenid != ''">
  85. wx_openid_ = #{wxOpenid},
  86. </if>
  87. <if test="avatar != null and avatar != ''">
  88. avatar_ = #{avatar},
  89. </if>
  90. <if test="email != null and email != ''">
  91. email_ = #{email},
  92. </if>
  93. <if test="gender != null">
  94. gender_ = #{gender},
  95. </if>
  96. <if test="salt != null and salt != ''">
  97. salt_ = #{salt},
  98. </if>
  99. <if test="username != null and username != ''">
  100. username_ = #{username},
  101. </if>
  102. <if test="userType != null and userType != ''">
  103. user_type_ = #{userType},
  104. </if>
  105. <if test="updateTime != null">
  106. update_time_ = NOW(),
  107. </if>
  108. <if test="lockFlag != null">
  109. lock_flag_ = #{lockFlag},
  110. </if>
  111. <if test="birthdate != null">
  112. birthdate_ = #{birthdate},
  113. </if>
  114. <if test="phone != null and phone != ''">
  115. phone_ = #{phone},
  116. </if>
  117. <if test="qqOpenid != null and qqOpenid != ''">
  118. qq_openid_ = #{qqOpenid},
  119. </if>
  120. <if test="nation != null and nation != ''">
  121. nation_ = #{nation},
  122. </if>
  123. <if test="imToken != null and imToken != ''">
  124. im_token_ = #{imToken},
  125. </if>
  126. <if test="idCardNo != null and idCardNo != ''">
  127. id_card_no_ = #{idCardNo},
  128. </if>
  129. <if test="password != null and password != ''">
  130. password_ = #{password},
  131. </if>
  132. <if test="wechatId != null and wechatId != ''">
  133. wechat_id_ = #{wechatId},
  134. </if>
  135. <if test="realName != null and realName != ''">
  136. real_name_ = #{realName},
  137. </if>
  138. <if test="isSuperAdmin != null">
  139. is_super_admin_ = #{isSuperAdmin},
  140. </if>
  141. <if test="certificateType != null">
  142. certificate_type_ = #{certificateType},
  143. </if>
  144. </set>
  145. WHERE id_ = #{id}
  146. </update>
  147. <update id="updatePasswordReq">
  148. UPDATE sys_user SET password_ = #{password} WHERE phone_ = #{mobile}
  149. </update>
  150. <update id="refreshImToken">
  151. UPDATE sys_user SET im_token_ = #{imToken},update_time_ = NOW() WHERE 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 ORDER BY id_
  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 username_ = #{username} OR phone_ = #{username} LIMIT 1 FOR UPDATE
  171. </select>
  172. <select id="queryByPhone" resultMap="SysUser">
  173. select * from sys_user where phone_ = #{phone} OR username_ = #{phone} LIMIT 1
  174. </select>
  175. <select id="queryLockByPhone" resultMap="SysUser">
  176. select * from sys_user where 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 id_ = #{userId} LIMIT 1
  186. </select>
  187. <select id="queryByStatus" resultMap="SysUser">
  188. select * from sys_user where lock_flag_ = #{status}
  189. </select>
  190. <select id="findUserBySalt" resultMap="SysUser">
  191. SELECT * FROM sys_user WHERE 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 (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 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.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 id_ = #{id}
  245. </update>
  246. <select id="queryEmployeeList" resultMap="SysUser">
  247. select su.*
  248. from employee e
  249. left join sys_user su on su.id_ = e.user_id_
  250. <where>
  251. <if test="createStartDate != null and createStartDate != ''">
  252. and #{createStartDate} &lt;= e.create_time_
  253. </if>
  254. <if test="createEndDate != null and createEndDate != ''">
  255. and #{createEndDate} &gt; e.create_time_
  256. </if>
  257. </where>
  258. </select>
  259. </mapper>