CmHeheUserMapper.xml 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. <mapper namespace="com.caimei.modules.hehe.dao.CmHeheUserDao">
  4. <sql id="cmHeheUserColumns">
  5. a.id AS "id",
  6. a.userId AS "userId",
  7. a.name AS "name",
  8. a.mobile AS "mobile",
  9. a.userIdentity AS "userIdentity",
  10. a.nickName AS "nickName",
  11. a.openId AS "openId",
  12. a.addTime AS "addTime"
  13. </sql>
  14. <sql id="cmHeheUserJoins">
  15. </sql>
  16. <delete id="deleteUserActivity">
  17. delete from cm_hehe_user_activity where userId = #{userId} and productId = #{productId}
  18. </delete>
  19. <select id="get" resultType="CmHeheUser">
  20. SELECT
  21. <include refid="cmHeheUserColumns"/>
  22. FROM cm_hehe_user a
  23. <include refid="cmHeheUserJoins"/>
  24. WHERE a.id = #{id}
  25. </select>
  26. <select id="findList" resultType="CmHeheUser">
  27. SELECT
  28. <include refid="cmHeheUserColumns"/>
  29. FROM cm_hehe_user a
  30. <include refid="cmHeheUserJoins"/>
  31. <where>
  32. <if test="name != null and name != ''">
  33. AND a.name LIKE
  34. <if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
  35. <if test="dbName == 'mssql'">'%'+#{name}+'%'</if>
  36. <if test="dbName == 'mysql'">concat('%',#{name},'%')</if>
  37. </if>
  38. <if test="mobile != null and mobile != ''">
  39. AND a.mobile = #{mobile}
  40. </if>
  41. <if test="userIdentity != null and userIdentity != ''">
  42. AND a.userIdentity = #{userIdentity}
  43. </if>
  44. <if test="nickName != null and nickName != ''">
  45. AND a.nickName LIKE concat('%',#{nickName},'%')
  46. </if>
  47. </where>
  48. <choose>
  49. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  50. ORDER BY ${page.orderBy}
  51. </when>
  52. <otherwise>
  53. ORDER BY addTime DESC
  54. </otherwise>
  55. </choose>
  56. </select>
  57. <select id="findAllList" resultType="CmHeheUser">
  58. SELECT
  59. <include refid="cmHeheUserColumns"/>
  60. FROM cm_hehe_user a
  61. <include refid="cmHeheUserJoins"/>
  62. <where>
  63. </where>
  64. <choose>
  65. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  66. ORDER BY ${page.orderBy}
  67. </when>
  68. <otherwise>
  69. </otherwise>
  70. </choose>
  71. </select>
  72. <insert id="insert" parameterType="CmHeheUser" keyProperty="id" useGeneratedKeys="true">
  73. INSERT INTO cm_hehe_user(
  74. userId,
  75. name,
  76. mobile,
  77. userIdentity,
  78. nickName,
  79. openId,
  80. addTime
  81. ) VALUES (
  82. #{userId},
  83. #{name},
  84. #{mobile},
  85. #{userIdentity},
  86. #{nickName},
  87. #{openId},
  88. #{addTime}
  89. )
  90. </insert>
  91. <update id="update">
  92. UPDATE cm_hehe_user SET
  93. name = #{name},
  94. mobile = #{mobile},
  95. userIdentity = #{userIdentity},
  96. nickName = #{nickName},
  97. openId = #{openId},
  98. addTime = #{addTime}
  99. WHERE id = #{id}
  100. </update>
  101. <select id="findMobileOnly" resultType="integer">
  102. SELECT
  103. id
  104. FROM
  105. cm_hehe_user
  106. WHERE
  107. mobile = #{mobile}
  108. <if test="id != null and id != ''">
  109. AND id != #{id}
  110. </if>
  111. </select>
  112. <insert id="insertUser" parameterType="com.caimei.modules.user.entity.CmUser" keyColumn="userID" keyProperty="userID" useGeneratedKeys="true">
  113. INSERT INTO USER (
  114. bindMobile, userPermission, userIdentity,
  115. userName, password, name, registerTime,
  116. validFlag, registerUserTypeID
  117. )
  118. VALUES
  119. (
  120. #{bindMobile}, #{userPermission}, #{userIdentity},
  121. #{userName}, #{password}, #{name}, #{registerTime},
  122. #{validFlag}, #{registerUserTypeID}
  123. )
  124. </insert>
  125. <update id="updateUser">
  126. UPDATE
  127. user
  128. SET
  129. bindMobile = #{bindMobile},
  130. userName = #{userName},
  131. name = #{name}
  132. WHERE
  133. userID = #{userID}
  134. </update>
  135. <select id="activityProductList" resultType="com.caimei.modules.hehe.entity.CmHeheActivityProduct">
  136. SELECT
  137. a.id AS "id",
  138. a.userId AS "userId",
  139. a.activityId AS "activityId",
  140. a.productId AS "productId",
  141. a.sort AS "sort",
  142. chp.price AS "price",
  143. p.name AS "name",
  144. p.mainImage AS "mainImage",
  145. p.unit AS "unit",
  146. s.name AS "shopName"
  147. FROM
  148. cm_hehe_user_activity a
  149. LEFT JOIN cm_hehe_product chp ON chp.productId = a.productID
  150. LEFT JOIN product p ON a.productId = p.productID
  151. LEFT JOIN shop s ON s.shopID = p.shopID
  152. WHERE
  153. a.userId = #{userId}
  154. <if test="name != null and name != ''">
  155. AND p.name LIKE CONCAT('%',#{name},'%')
  156. </if>
  157. <if test="shopName != null and shopName != ''">
  158. AND s.name LIKE CONCAT('%',#{shopName},'%')
  159. </if>
  160. ORDER BY
  161. - a.sort DESC
  162. </select>
  163. <select id="findUserActivityProduct" resultType="integer">
  164. SELECT productId FROM cm_hehe_user_activity WHERE userId = #{userId}
  165. </select>
  166. <select id="findAllActivityProduct" resultType="com.caimei.modules.hehe.entity.CmHeheProduct">
  167. SELECT
  168. a.id AS "id",
  169. a.productId AS "productId",
  170. chp.price AS "price",
  171. p.name AS "name",
  172. p.mainImage AS "mainImage",
  173. s.name AS "shopName"
  174. FROM
  175. cm_hehe_activity_product a
  176. LEFT JOIN cm_hehe_product chp ON a.productId = chp.productId
  177. LEFT JOIN product p ON a.productId = p.productID
  178. LEFT JOIN shop s ON s.shopID = p.shopID
  179. WHERE
  180. a.delFlag = 0
  181. <if test="ids != null and ids.size() > 0 ">
  182. AND a.productId NOT IN
  183. <foreach collection="ids" open="(" close=")" item="id" separator=",">
  184. #{id}
  185. </foreach>
  186. </if>
  187. <if test="productId != null">
  188. AND a.productId = #{productId}
  189. </if>
  190. <if test="name != null and name != ''">
  191. AND p.name LIKE CONCAT('%',#{name},'%')
  192. </if>
  193. <if test="shopName != null and shopName != ''">
  194. AND s.name LIKE CONCAT('%',#{shopName},'%')
  195. </if>
  196. ORDER BY productId DESC
  197. </select>
  198. <insert id="insertUserActivity">
  199. INSERT INTO `cm_hehe_user_activity` (
  200. `userId`, `activityId`, `productId`,
  201. addTime
  202. )
  203. VALUES
  204. (
  205. #{userId}, #{activityId}, #{productId},
  206. NOW()
  207. )
  208. </insert>
  209. <update id="updateSortById">
  210. UPDATE cm_hehe_user_activity SET sort = #{sort} WHERE id =#{id}
  211. </update>
  212. </mapper>