SysUserMapper.xml 9.0 KB

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