SysUserMapper.xml 7.8 KB

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