SysUserMapper.xml 9.9 KB

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