SysUserMapper.xml 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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.ym.mec.auth.dal.dao.SysUserDao">
  8. <resultMap type="com.ym.mec.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="organ_id_" property="organId"/>
  17. <result column="create_time_" property="createTime"/>
  18. <result column="update_time_" property="updateTime"/>
  19. <result column="lock_flag_" property="lockFlag"/>
  20. <result column="del_flag_" property="delFlag" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  21. <result column="wx_openid_" property="wxOpenid"/>
  22. <result column="qq_openid_" property="qqOpenid"/>
  23. <result column="user_type_" property="userType"/>
  24. <result column="gender_" property="gender"/>
  25. <result column="nation_" property="nation"/>
  26. <result column="birthdate_" property="birthdate"/>
  27. <result column="email_" property="email"/>
  28. <result column="im_token_" property="imToken"/>
  29. <result column="id_card_no_" property="idCardNo"/>
  30. <result column="wechat_id_" property="wechatId"/>
  31. <result column="is_super_admin_" property="isSuperAdmin"/>
  32. <result column="current_grade_" property="currentGrade"/>
  33. <result column="current_grade_num_" property="currentGradeNum"/>
  34. <result column="current_class_" property="currentClass"/>
  35. <result column="certificate_type_" property="certificateType"/>
  36. </resultMap>
  37. <!-- 查询条件 -->
  38. <sql id="queryCondition">
  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. <if test="organId != null">
  49. and organ_id_ = #{organId}
  50. </if>
  51. </sql>
  52. <!-- 根据主键查询一条记录 -->
  53. <select id="get" resultMap="SysUser">
  54. SELECT su.*,s.current_class_,s.current_grade_num_
  55. FROM sys_user su LEFT JOIN student s ON su.id_ = s.user_id_
  56. WHERE su.id_ = #{id}
  57. </select>
  58. <!-- 全查询 -->
  59. <select id="findAll" resultMap="SysUser">
  60. SELECT * FROM sys_user ORDER BY id_
  61. </select>
  62. <!-- 向数据库增加一条记录 -->
  63. <insert id="insert" parameterType="com.ym.mec.auth.api.entity.SysUser" useGeneratedKeys="true" keyColumn="id"
  64. keyProperty="id">
  65. INSERT INTO sys_user
  66. (is_super_admin_,im_token_,id_,username_,salt_,phone_,avatar_,organ_id_,create_time_,update_time_,wx_openid_,qq_openid_,user_type_,
  67. gender_,nation_,birthdate_,email_,id_card_no_,wechat_id_,real_name_,certificate_type_)
  68. VALUES(#{isSuperAdmin},#{imToken},#{id},#{username},#{salt},#{phone},#{avatar},#{organId},now(),now(),#{wxOpenid},#{qqOpenid},#{userType},
  69. #{gender},#{nation},#{birthdate},#{email},#{idCardNo},#{wechatId},#{realName},#{certificateType})
  70. </insert>
  71. <insert id="insertTeacher">
  72. INSERT INTO teacher
  73. (id_,organ_id_,create_time_,update_time_)VALUES(#{userId},#{lesseeOrganId},NOW(),NOW())
  74. </insert>
  75. <insert id="insertSysTenantAccount">
  76. INSERT INTO sys_tenant_account
  77. (user_id_,available_minutes_,frozen_minutes_,status_,create_time_,update_time_)
  78. VALUES(#{userId},0,0,1,NOW(),NOW())
  79. </insert>
  80. <insert id="saveStudent">
  81. INSERT INTO student (user_id_,create_time_,update_time_,service_tag_,operating_tag_) VALUES(#{userId},NOW(),NOW(),0,0)
  82. </insert>
  83. <!-- 根据主键查询一条记录 -->
  84. <update id="update" parameterType="com.ym.mec.auth.api.entity.SysUser">
  85. UPDATE sys_user
  86. <set>
  87. <if test="delFlag != null">
  88. del_flag_ = #{delFlag, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  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="organId != null">
  130. organ_id_ = #{organId},
  131. </if>
  132. <if test="imToken != null and imToken != ''">
  133. im_token_ = #{imToken},
  134. </if>
  135. <if test="idCardNo != null and idCardNo != ''">
  136. id_card_no_ = #{idCardNo},
  137. </if>
  138. <if test="password != null and password != ''">
  139. password_ = #{password},
  140. </if>
  141. <if test="wechatId != null and wechatId != ''">
  142. wechat_id_ = #{wechatId},
  143. </if>
  144. <if test="realName != null and realName != ''">
  145. real_name_ = #{realName},
  146. </if>
  147. <if test="isSuperAdmin != null">
  148. is_super_admin_ = #{isSuperAdmin},
  149. </if>
  150. <if test="certificateType != null">
  151. certificate_type_ = #{certificateType},
  152. </if>
  153. </set>
  154. WHERE id_ = #{id}
  155. </update>
  156. <update id="updatePassword">
  157. UPDATE sys_user SET password_ = #{password} WHERE phone_ = #{mobile}
  158. </update>
  159. <update id="refreshImToken">
  160. UPDATE sys_user SET im_token_ = #{imToken},update_time_ = NOW() WHERE id_ = #{userId}
  161. </update>
  162. <!-- 根据主键删除一条记录 -->
  163. <delete id="delete">
  164. UPDATE sys_user SET del_flag_ = 1 WHERE id_ = #{id}
  165. </delete>
  166. <!-- 分页查询 -->
  167. <select id="queryPage" resultMap="SysUser" parameterType="map">
  168. SELECT * FROM sys_user ORDER BY id_
  169. <include refid="queryCondition"/>
  170. <include refid="global.orderby"/>
  171. <include refid="global.limit"/>
  172. </select>
  173. <!-- 查询当前表的总记录数 -->
  174. <select id="queryCount" resultType="int">
  175. SELECT COUNT(*) FROM sys_user
  176. <include refid="queryCondition"/>
  177. </select>
  178. <select id="queryByUsername" resultMap="SysUser">
  179. select * from sys_user where username_ = #{username} OR phone_ = #{username} LIMIT 1 FOR UPDATE
  180. </select>
  181. <select id="queryByPhone" resultMap="SysUser">
  182. select * from sys_user where phone_ = #{phone} OR username_ = #{phone} LIMIT 1
  183. </select>
  184. <select id="queryLockByPhone" resultMap="SysUser">
  185. select * from sys_user where phone_ = #{phone} OR username_ = #{phone} LIMIT 1 FOR UPDATE
  186. </select>
  187. <resultMap id="ImUserModel" type="com.ym.mec.common.entity.ImUserModel">
  188. <result column="id_" property="id"/>
  189. <result property="name" column="username_"/>
  190. <result property="portrait" column="avatar_"/>
  191. </resultMap>
  192. <select id="getBasic" resultMap="ImUserModel">
  193. select CASE WHEN user_type_ LIKE '%TEACHER%' OR user_type_ LIKE '%SYSTEM%' THEN real_name_ ELSE username_ END username_,id_,avatar_
  194. from sys_user where id_ = #{userId} LIMIT 1
  195. </select>
  196. <select id="queryByStatus" resultMap="SysUser">
  197. select * from sys_user where lock_flag_ = #{status}
  198. </select>
  199. <select id="findUserBySalt" resultMap="SysUser">
  200. SELECT * FROM sys_user WHERE salt_ IS NOT NULL AND salt_ = 'replace' AND user_type_ LIKE CONCAT('%',#{userType},'%') LIMIT 1
  201. </select>
  202. <select id="getTeacherOrganId" resultType="java.lang.Integer">
  203. SELECT organ_id_ FROM teacher WHERE id_ = #{userId}
  204. </select>
  205. <select id="queryByPhoneAndClient" resultMap="SysUser">
  206. select * from sys_user where (phone_ = #{phone} OR username_ = #{phone}) AND user_type_ LIKE CONCAT('%',#{client},'%') LIMIT 1 FOR UPDATE
  207. </select>
  208. </mapper>