SysUserMapper.xml 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. </resultMap>
  35. <!-- 查询条件 -->
  36. <sql id="queryCondition">
  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. <if test="organId != null">
  47. and organ_id_ = #{organId}
  48. </if>
  49. </sql>
  50. <!-- 根据主键查询一条记录 -->
  51. <select id="get" resultMap="SysUser">
  52. SELECT su.*,sr.current_class_,sr.current_grade_
  53. FROM sys_user su LEFT JOIN student_registration sr ON su.id_ = sr.user_id_
  54. WHERE su.id_ = #{id} LIMIT 1
  55. </select>
  56. <!-- 全查询 -->
  57. <select id="findAll" resultMap="SysUser">
  58. SELECT * FROM sys_user ORDER BY id_
  59. </select>
  60. <!-- 向数据库增加一条记录 -->
  61. <insert id="insert" parameterType="com.ym.mec.auth.api.entity.SysUser" useGeneratedKeys="true" keyColumn="id"
  62. keyProperty="id">
  63. INSERT INTO sys_user
  64. (is_super_admin_,im_token_,id_,username_,salt_,phone_,avatar_,organ_id_,create_time_,update_time_,wx_openid_,qq_openid_,user_type_,
  65. gender_,nation_,birthdate_,email_,id_card_no_,wechat_id_,real_name_)
  66. VALUES(#{isSuperAdmin},#{imToken},#{id},#{username},#{salt},#{phone},#{avatar},#{organId},now(),now(),#{wxOpenid},#{qqOpenid},#{userType},
  67. #{gender},#{nation},#{birthdate},#{email},#{idCardNo},#{wechatId},#{realName})
  68. </insert>
  69. <insert id="insertTeacher">
  70. INSERT INTO teacher
  71. (id_,organ_id_,create_time_,update_time_)VALUES(#{userId},#{lesseeOrganId},NOW(),NOW())
  72. </insert>
  73. <insert id="insertSysTenantAccount">
  74. INSERT INTO sys_tenant_account
  75. (user_id_,available_minutes_,frozen_minutes_,status_,create_time_,update_time_)
  76. VALUES(#{userId},0,0,1,NOW(),NOW())
  77. </insert>
  78. <insert id="saveStudent">
  79. INSERT INTO student (user_id_,create_time_,update_time_) VALUES(#{userId},NOW(),NOW())
  80. </insert>
  81. <!-- 根据主键查询一条记录 -->
  82. <update id="update" parameterType="com.ym.mec.auth.api.entity.SysUser">
  83. UPDATE sys_user
  84. <set>
  85. <if test="delFlag != null">
  86. del_flag_ = #{delFlag, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  87. </if>
  88. <if test="wxOpenid != null">
  89. wx_openid_ = #{wxOpenid},
  90. </if>
  91. <if test="avatar != null">
  92. avatar_ = #{avatar},
  93. </if>
  94. <if test="email != null">
  95. email_ = #{email},
  96. </if>
  97. <if test="gender != null">
  98. gender_ = #{gender},
  99. </if>
  100. <if test="salt != null">
  101. salt_ = #{salt},
  102. </if>
  103. <if test="username != null">
  104. username_ = #{username},
  105. </if>
  106. <if test="userType != null">
  107. user_type_ = #{userType},
  108. </if>
  109. <if test="updateTime != null">
  110. update_time_ = NOW(),
  111. </if>
  112. <if test="lockFlag != null">
  113. lock_flag_ = #{lockFlag},
  114. </if>
  115. <if test="birthdate != null">
  116. birthdate_ = #{birthdate},
  117. </if>
  118. <if test="phone != null">
  119. phone_ = #{phone},
  120. </if>
  121. <if test="qqOpenid != null">
  122. qq_openid_ = #{qqOpenid},
  123. </if>
  124. <if test="nation != null">
  125. nation_ = #{nation},
  126. </if>
  127. <if test="organId != null">
  128. organ_id_ = #{organId},
  129. </if>
  130. <if test="imToken != null">
  131. im_token_ = #{imToken},
  132. </if>
  133. <if test="idCardNo != null">
  134. id_card_no_ = #{idCardNo},
  135. </if>
  136. <if test="password != null">
  137. password_ = #{password},
  138. </if>
  139. <if test="wechatId != null">
  140. wechat_id_ = #{wechatId},
  141. </if>
  142. <if test="realName != null">
  143. real_name_ = #{realName},
  144. </if>
  145. <if test="isSuperAdmin != null">
  146. is_super_admin_ = #{isSuperAdmin},
  147. </if>
  148. </set>
  149. WHERE id_ = #{id}
  150. </update>
  151. <update id="updatePassword">
  152. UPDATE sys_user SET password_ = #{password} WHERE phone_ = #{mobile}
  153. </update>
  154. <update id="refreshImToken">
  155. UPDATE sys_user SET im_token_ = #{imToken},update_time_ = NOW() WHERE id_ = #{userId}
  156. </update>
  157. <!-- 根据主键删除一条记录 -->
  158. <delete id="delete">
  159. UPDATE sys_user SET del_flag_ = 1 WHERE id_ = #{id}
  160. </delete>
  161. <!-- 分页查询 -->
  162. <select id="queryPage" resultMap="SysUser" parameterType="map">
  163. SELECT * FROM sys_user ORDER BY id_
  164. <include refid="queryCondition"/>
  165. <include refid="global.orderby"/>
  166. <include refid="global.limit"/>
  167. </select>
  168. <!-- 查询当前表的总记录数 -->
  169. <select id="queryCount" resultType="int">
  170. SELECT COUNT(*) FROM sys_user
  171. <include refid="queryCondition"/>
  172. </select>
  173. <select id="queryByUsername" resultMap="SysUser">
  174. select * from sys_user where username_ = #{username} OR phone_ = #{username} LIMIT 1 FOR UPDATE
  175. </select>
  176. <select id="queryByPhone" resultMap="SysUser">
  177. select * from sys_user where phone_ = #{phone} OR username_ = #{phone} LIMIT 1 FOR UPDATE
  178. </select>
  179. <resultMap id="ImUserModel" type="com.ym.mec.common.entity.ImUserModel">
  180. <result column="id_" property="id"/>
  181. <result property="name" column="username_"/>
  182. <result property="portrait" column="avatar_"/>
  183. </resultMap>
  184. <select id="getBasic" resultMap="ImUserModel">
  185. select CASE WHEN user_type_ LIKE '%TEACHER%' OR user_type_ LIKE '%SYSTEM%' THEN real_name_ ELSE username_ END username_,id_,avatar_
  186. from sys_user where id_ = #{userId} LIMIT 1
  187. </select>
  188. <select id="queryByStatus" resultMap="SysUser">
  189. select * from sys_user where lock_flag_ = #{status}
  190. </select>
  191. <select id="findUserBySalt" resultMap="SysUser">
  192. SELECT * FROM sys_user WHERE salt_ IS NOT NULL AND salt_ = 'replace' AND user_type_ LIKE CONCAT('%',#{userType},'%') LIMIT 1
  193. </select>
  194. <select id="getTeacherOrganId" resultType="java.lang.Integer">
  195. SELECT organ_id_ FROM teacher WHERE id_ = #{userId}
  196. </select>
  197. <select id="queryByPhoneAndClient" resultMap="SysUser">
  198. select * from sys_user where (phone_ = #{phone} OR username_ = #{phone}) AND user_type_ LIKE CONCAT('%',#{client},'%') LIMIT 1 FOR UPDATE
  199. </select>
  200. </mapper>