8651bfedb99c3f870e7b51d11101bfc166a0eafb.svn-base 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. user_tel userTel
  27. </sql>
  28. <resultMap type="User" id="userMap">
  29. <id property="id" column="id"/>
  30. <result property="username" column="username"/>
  31. <result property="password" column="password"/>
  32. <result property="token" column="token"/>
  33. <result property="display_name" column="display_name"/>
  34. <result property="display_picture" column="display_picture"/>
  35. <result property="created_on" column="created_on"/>
  36. <result property="ext_open_id" column="ext_open_id"/>
  37. <result property="ext_name" column="ext_name"/>
  38. <result property="ext_type" column="ext_type"/>
  39. <result property="location" column="location"/>
  40. <result property="baby_nickname" column="baby_nickname"/>
  41. <result property="baby_dob" column="baby_dob"/>
  42. <result property="baby_gender" column="baby_gender"/>
  43. <result property="status_" column="status_"/>
  44. <result property="userTel" column="user_tel"/>
  45. </resultMap>
  46. <!-- 根据id查询user所有信息 -->
  47. <select id="selectUserById" parameterType="java.lang.Long" resultMap="userMap">
  48. SELECT
  49. <include refid="userAttribute" />
  50. FROM USER WHERE ID = #{0}
  51. </select>
  52. <!-- 根据username查询user所有信息 -->
  53. <select id="selectUserByUsername" parameterType="java.lang.String" resultMap="userMap">
  54. SELECT <include refid="userAttribute" /> FROM USER WHERE USERNAME = #{0}
  55. </select>
  56. <!-- 通过ext_open_id查询user所有信息 -->
  57. <select id="selectUserByExtOpenId" parameterType="java.lang.String" resultMap="userMap">
  58. SELECT <include refid="userAttribute" /> FROM USER WHERE EXT_OPEN_ID = #{0}
  59. </select>
  60. <!-- 添加用户信息到user表中 -->
  61. <insert id="insertUser" parameterType="User" useGeneratedKeys="true" keyProperty="id">
  62. INSERT INTO USER
  63. (
  64. USERNAME,PASSWORD,TOKEN,DISPLAY_NAME,DISPLAY_PICTURE,
  65. CREATED_ON,EXT_OPEN_ID,EXT_NAME,EXT_TYPE,
  66. LOCATION,BABY_NICKNAME,BABY_DOB,BABY_GENDER,STATUS_,USER_TEL)
  67. VALUES
  68. (
  69. #{username},#{password},#{token},#{display_name},#{display_picture},
  70. NOW(),#{ext_open_id},#{ext_name},#{ext_type},
  71. #{location},#{baby_nickname},#{baby_dob},#{baby_gender},#{status_}, #{userTel}
  72. )
  73. </insert>
  74. <!-- 根据id修改user表数据 -->
  75. <update id="updateUser" parameterType="User">
  76. UPDATE USER
  77. <set>
  78. <if test="username != null and username != ''">
  79. USERNAME = #{username},
  80. </if>
  81. <if test="password != null and password != ''">
  82. PASSWORD = #{password},
  83. </if>
  84. <if test="token != null and token != ''">
  85. TOKEN = #{token},
  86. </if>
  87. <if test="display_name != null and display_name != ''">
  88. DISPLAY_NAME = #{display_name},
  89. </if>
  90. <if test="display_picture != null and display_picture != ''">
  91. DISPLAY_PICTURE = #{display_picture},
  92. </if>
  93. <if test="ext_open_id != null and ext_open_id != ''">
  94. EXT_OPEN_ID = #{ext_open_id},
  95. </if>
  96. <if test="ext_name != null and ext_name != ''">
  97. EXT_NAME = #{ext_name},
  98. </if>
  99. <if test="ext_type != null and ext_type != ''">
  100. EXT_TYPE = #{ext_type},
  101. </if>
  102. <if test="location != null and location != ''">
  103. LOCATION = #{location},
  104. </if>
  105. <if test="baby_nickname != null and baby_nickname != ''">
  106. BABY_NICKNAME = #{baby_nickname},
  107. </if>
  108. <if test="baby_dob != null and baby_dob != ''">
  109. BABY_DOB = #{baby_dob},
  110. </if>
  111. <if test="baby_gender != null and baby_gender != ''">
  112. BABY_GENDER = #{baby_gender},
  113. </if>
  114. <if test="status_ != null and status_ != ''">
  115. STATUS_ = #{status_},
  116. </if>
  117. <if test="userTel != null and userTel != ''">
  118. USER_TEL = #{userTel}
  119. </if>
  120. </set>
  121. WHERE
  122. ID = #{id}
  123. </update>
  124. <!-- 根据id修改user表的个人头像 -->
  125. <update id="updateDisplayPicture">
  126. UPDATE USER SET DISPLAY_PICTURE = #{0} WHERE ID = #{1}
  127. </update>
  128. <!-- 根据用户名和密码查询用户表信息 -->
  129. <select id="validateUser" parameterType="java.lang.String" resultMap="userMap">
  130. SELECT <include refid="userAttribute"/> FROM USER WHERE USERNAME=#{0} AND PASSWORD=#{1}
  131. </select>
  132. <!-- 通过id修改用户表密码 -->
  133. <update id="changePassword">
  134. UPDATE USER SET PASSWORD=#{1} WHERE ID=#{0}
  135. </update>
  136. <!-- 通过token查询user表所有信息 -->
  137. <select id="selectUserByToken" parameterType="java.lang.String" resultMap="userMap">
  138. SELECT <include refid="userAttribute"/> FROM USER WHERE TOKEN=#{0}
  139. </select>
  140. <!-- 根据id修改token值 -->
  141. <update id="updateUserToken">
  142. UPDATE USER SET TOKEN=#{0} WHERE ID=#{1}
  143. </update>
  144. <!-- 根据id修改user表的用户名 -->
  145. <update id="updateUserName">
  146. UPDATE USER SET USERNAME=#{0} WHERE ID=#{1}
  147. </update>
  148. <!-- 通过key_查询sys_config表数据 -->
  149. <select id="selectConfig" parameterType="java.lang.String" resultType="String">
  150. SELECT VALUE_ FROM SYS_CONFIG WHERE KEY_ = #{0}
  151. </select>
  152. <!-- USER_AVATOR表中添加数据 -->
  153. <insert id="insertUserAvator">
  154. INSERT INTO USER_AVATOR (USER_ID, AVATOR) VALUE (#{0}, #{1})
  155. </insert>
  156. <!-- 通过user_id修改USER_AVATOR表数据 -->
  157. <update id="updateUserAvator">
  158. UPDATE USER_AVATOR SET AVATOR = #{1} WHERE USER_ID = #{0}
  159. </update>
  160. <!-- 根据user_id查询USER_AVATOR表数据 -->
  161. <select id="selectUserAvator" parameterType="java.lang.Long" resultType="java.lang.String">
  162. SELECT avator FROM USER_AVATOR WHERE USER_ID = #{id}
  163. </select>
  164. <!-- 根据user_id查询USER_AVATOR表数据 -->
  165. <select id="getOtherUserByTel" parameterType="java.util.Map" resultMap="userMap">
  166. SELECT
  167. <include refid="userAttribute"/>
  168. FROM
  169. USER
  170. WHERE
  171. USER_TEL = #{phone}
  172. AND
  173. ID != #{userId}
  174. AND
  175. STATUS_ = 'ACTIVE'
  176. LIMIT
  177. 0, 1
  178. </select>
  179. <select id="getAll" parameterType="java.util.Map" resultMap="userMap">
  180. SELECT
  181. <include refid="userAttribute"/>
  182. FROM
  183. USER
  184. LIMIT
  185. #{start}, #{end}
  186. </select>
  187. </mapper>