userMapper.xml 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC
  4. "-//mybatis.org//DTD Mapper 3.0//EN"
  5. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  6. <!-- 命名,每一个映射对象不一样
  7. namespace:必须与对应的接口全类名一致
  8. -->
  9. <mapper namespace="com.iamberry.app.mapper.UserMapper">
  10. <sql id="userAttribute">
  11. id,
  12. username,
  13. password,
  14. token,
  15. display_name,
  16. display_picture,
  17. created_on,
  18. ext_open_id,
  19. ext_name,
  20. ext_type,
  21. location,
  22. baby_nickname,
  23. baby_dob,
  24. baby_gender,
  25. status_,
  26. country_code,
  27. is_perfect_user
  28. </sql>
  29. <resultMap type="User" id="userMap">
  30. <id property="id" column="id"/>
  31. <result property="username" column="username"/>
  32. <result property="password" column="password"/>
  33. <result property="token" column="token"/>
  34. <result property="display_name" column="display_name"/>
  35. <result property="display_picture" column="display_picture"/>
  36. <result property="created_on" column="created_on"/>
  37. <result property="ext_open_id" column="ext_open_id"/>
  38. <result property="ext_name" column="ext_name"/>
  39. <result property="ext_type" column="ext_type"/>
  40. <result property="location" column="location"/>
  41. <result property="baby_nickname" column="baby_nickname"/>
  42. <result property="baby_dob" column="baby_dob"/>
  43. <result property="baby_gender" column="baby_gender"/>
  44. <result property="status_" column="status_"/>
  45. <result property="is_perfect_user" column="is_perfect_user"/>
  46. <result property="country_code" column="country_code"/>
  47. </resultMap>
  48. <!-- 根据id查询user所有信息 -->
  49. <select id="selectUserById" parameterType="java.lang.Long" resultMap="userMap">
  50. SELECT
  51. <include refid="userAttribute" />
  52. FROM USER WHERE ID = #{0}
  53. </select>
  54. <!-- 根据username查询user所有信息 -->
  55. <select id="selectUserByUsername" parameterType="java.lang.String" resultMap="userMap">
  56. SELECT <include refid="userAttribute" /> FROM USER WHERE USERNAME = #{0}
  57. </select>
  58. <!-- 通过ext_open_id查询user所有信息 -->
  59. <select id="selectUserByExtOpenId" parameterType="java.lang.String" resultMap="userMap">
  60. SELECT <include refid="userAttribute" /> FROM USER WHERE EXT_OPEN_ID = #{0}
  61. </select>
  62. <!-- 添加用户信息到user表中 -->
  63. <insert id="insertUser" parameterType="User" useGeneratedKeys="true" keyProperty="id">
  64. INSERT INTO USER
  65. (USERNAME,PASSWORD,TOKEN,DISPLAY_NAME,DISPLAY_PICTURE,CREATED_ON,EXT_OPEN_ID,EXT_NAME,EXT_TYPE,
  66. LOCATION,BABY_NICKNAME,BABY_DOB,BABY_GENDER,STATUS_,country_code,is_perfect_user)
  67. VALUES
  68. (#{username},#{password},#{token},#{display_name},#{display_picture},NOW(),#{ext_open_id},#{ext_name},#{ext_type},
  69. #{location},#{baby_nickname},#{baby_dob},#{baby_gender},#{status_},#{country_code},#{is_perfect_user})
  70. </insert>
  71. <!-- 根据id修改user表数据 -->
  72. <update id="updateUser" parameterType="User">
  73. UPDATE USER
  74. <set>
  75. <if test="username != null and username != ''">
  76. USERNAME = #{username},
  77. </if>
  78. <if test="password != null and password != ''">
  79. PASSWORD = #{password},
  80. </if>
  81. <if test="token != null and token != ''">
  82. TOKEN = #{token},
  83. </if>
  84. <if test="display_name != null and display_name != ''">
  85. DISPLAY_NAME = #{display_name},
  86. </if>
  87. <if test="display_picture != null and display_picture != ''">
  88. DISPLAY_PICTURE = #{display_picture},
  89. </if>
  90. <if test="ext_open_id != null and ext_open_id != ''">
  91. EXT_OPEN_ID = #{ext_open_id},
  92. </if>
  93. <if test="ext_name != null and ext_name != ''">
  94. EXT_NAME = #{ext_name},
  95. </if>
  96. <if test="ext_type != null and ext_type != ''">
  97. EXT_TYPE = #{ext_type},
  98. </if>
  99. <if test="location != null and location != ''">
  100. LOCATION = #{location},
  101. </if>
  102. <if test="baby_nickname != null and baby_nickname != ''">
  103. BABY_NICKNAME = #{baby_nickname},
  104. </if>
  105. <if test="baby_dob != null and baby_dob != ''">
  106. BABY_DOB = #{baby_dob},
  107. </if>
  108. <if test="baby_gender != null and baby_gender != ''">
  109. BABY_GENDER = #{baby_gender},
  110. </if>
  111. <if test="status_ != null and status_ != ''">
  112. STATUS_ = #{status_}
  113. </if>
  114. </set>
  115. WHERE
  116. ID = #{id}
  117. </update>
  118. <!-- 根据id修改user表的个人头像 -->
  119. <update id="updateDisplayPicture">
  120. UPDATE USER SET DISPLAY_PICTURE = #{0} WHERE ID = #{1}
  121. </update>
  122. <!-- 根据用户名和密码查询用户表信息 -->
  123. <select id="validateUser" parameterType="java.lang.String" resultMap="userMap">
  124. SELECT <include refid="userAttribute"/> FROM USER WHERE USERNAME=#{0} AND PASSWORD=#{1}
  125. </select>
  126. <!-- 通过id修改用户表密码 -->
  127. <update id="changePassword">
  128. UPDATE USER SET PASSWORD=#{1} WHERE ID=#{0}
  129. </update>
  130. <!-- 通过token查询user表所有信息 -->
  131. <select id="selectUserByToken" parameterType="java.lang.String" resultMap="userMap">
  132. SELECT <include refid="userAttribute"/> FROM USER WHERE TOKEN=#{0}
  133. </select>
  134. <!-- 根据id修改token值 -->
  135. <update id="updateUserToken">
  136. UPDATE USER SET TOKEN=#{0} WHERE ID=#{1}
  137. </update>
  138. <!-- 根据id修改user表的用户名 修改IS_PERFECT_USER字段未已完善状态-->
  139. <update id="updateUserName">
  140. UPDATE USER SET USERNAME=#{0},IS_PERFECT_USER=2 WHERE ID=#{1}
  141. </update>
  142. <!-- 根据id修改user表的用户名和国家代码 -->
  143. <update id="updateUserNameAndCountry">
  144. UPDATE USER SET USERNAME=#{0},country_code=#{1},IS_PERFECT_USER=2 WHERE ID=#{2}
  145. </update>
  146. <!-- 通过key_查询sys_config表数据 -->
  147. <select id="selectConfig" parameterType="java.lang.String" resultType="String">
  148. SELECT VALUE_ FROM SYS_CONFIG WHERE KEY_ = #{0}
  149. </select>
  150. <!-- USER_AVATOR表中添加数据 -->
  151. <insert id="insertUserAvator">
  152. INSERT INTO USER_AVATOR (USER_ID, AVATOR) VALUE (#{0}, #{1})
  153. </insert>
  154. <!-- 通过user_id修改USER_AVATOR表数据 -->
  155. <update id="updateUserAvator">
  156. UPDATE USER_AVATOR SET AVATOR = #{1} WHERE USER_ID = #{0}
  157. </update>
  158. <!-- 根据user_id查询USER_AVATOR表数据 -->
  159. <select id="selectUserAvator" parameterType="java.lang.Long" resultType="java.lang.String">
  160. SELECT avator FROM USER_AVATOR WHERE USER_ID = #{id}
  161. </select>
  162. </mapper>