CmHeheDiscountMapper.xml 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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.CmHeheDiscountDao">
  4. <sql id="cmHeheDiscountColumns">
  5. a.id AS "id",
  6. a.title AS "title",
  7. a.discount AS "discount",
  8. a.status AS "status",
  9. a.productType AS "productType",
  10. a.addTime AS "addTime"
  11. </sql>
  12. <sql id="cmHeheDiscountJoins">
  13. </sql>
  14. <select id="get" resultType="CmHeheDiscount">
  15. SELECT
  16. <include refid="cmHeheDiscountColumns"/>
  17. FROM cm_hehe_discount a
  18. <include refid="cmHeheDiscountJoins"/>
  19. WHERE a.id = #{id}
  20. </select>
  21. <select id="findList" resultType="CmHeheDiscount">
  22. SELECT
  23. <include refid="cmHeheDiscountColumns"/>
  24. FROM cm_hehe_discount a
  25. <include refid="cmHeheDiscountJoins"/>
  26. <where>
  27. <if test="title != null and title != ''">
  28. AND a.title LIKE
  29. <if test="dbName == 'oracle'">'%'||#{title}||'%'</if>
  30. <if test="dbName == 'mssql'">'%'+#{title}+'%'</if>
  31. <if test="dbName == 'mysql'">concat('%',#{title},'%')</if>
  32. </if>
  33. <if test="status != null and status != ''">
  34. AND a.status = #{status}
  35. </if>
  36. </where>
  37. <choose>
  38. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  39. ORDER BY ${page.orderBy}
  40. </when>
  41. <otherwise>
  42. order by addTime desc
  43. </otherwise>
  44. </choose>
  45. </select>
  46. <select id="findAllList" resultType="CmHeheDiscount">
  47. SELECT
  48. <include refid="cmHeheDiscountColumns"/>
  49. FROM cm_hehe_discount a
  50. <include refid="cmHeheDiscountJoins"/>
  51. <where>
  52. </where>
  53. <choose>
  54. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  55. ORDER BY ${page.orderBy}
  56. </when>
  57. <otherwise>
  58. </otherwise>
  59. </choose>
  60. </select>
  61. <insert id="insert" parameterType="CmHeheDiscount" keyProperty="id" useGeneratedKeys="true">
  62. INSERT INTO cm_hehe_discount(
  63. title,
  64. discount,
  65. status,
  66. productType,
  67. addTime
  68. ) VALUES (
  69. #{title},
  70. #{discount},
  71. #{status},
  72. #{productType},
  73. NOW()
  74. )
  75. </insert>
  76. <update id="update">
  77. UPDATE cm_hehe_discount SET
  78. title = #{title},
  79. discount = #{discount},
  80. status = #{status},
  81. productType = #{productType}
  82. WHERE id = #{id}
  83. </update>
  84. <update id="updateStatus">
  85. update cm_hehe_discount
  86. set status = #{status}
  87. where id = #{id}
  88. </update>
  89. <delete id="delete">
  90. DELETE FROM cm_hehe_discount
  91. WHERE id = #{id}
  92. </delete>
  93. <select id="findDiscountProductIds" resultType="java.lang.Integer">
  94. SELECT id FROM cm_hehe_discount_product WHERE discountId = #{discountId}
  95. </select>
  96. <select id="findDiscountUserIds" resultType="java.lang.Integer">
  97. SELECT id FROM cm_hehe_discount_user where discountId = #{discountId}
  98. </select>
  99. <insert id="insertDiscountProduct">
  100. INSERT INTO `cm_hehe_discount_product` (
  101. `discountId`, `productId`, discountPrice, `status`,
  102. `sort`, `addTime`
  103. )
  104. VALUES
  105. (
  106. #{discountId}, #{productId}, #{discountPrice}, #{status},
  107. #{sort}, #{addTime}
  108. )
  109. </insert>
  110. <insert id="insertDiscountUser">
  111. insert into cm_hehe_discount_user (discountId, userId, addTime) values (#{discountId}, #{userId}, #{addTime})
  112. </insert>
  113. <update id="updateDiscountProduct">
  114. UPDATE
  115. `cm_hehe_discount_product`
  116. <set>
  117. <if test="status != null">
  118. `status` = #{status},
  119. </if>
  120. <if test="sort != null">
  121. `sort` = #{sort},
  122. </if>
  123. discountPrice = #{discountPrice}
  124. </set>
  125. WHERE
  126. `id` = #{id}
  127. </update>
  128. <delete id="deleteDiscountProduct">
  129. delete from cm_hehe_discount_product where id = #{id}
  130. </delete>
  131. <delete id="deleteDiscountUser">
  132. delete from cm_hehe_discount_user where id = #{id}
  133. </delete>
  134. <delete id="deleteUserByDiscountId">
  135. delete from cm_hehe_discount_user where discountId = #{id}
  136. </delete>
  137. <select id="findDiscountProductList" resultType="com.caimei.modules.hehe.entity.CmHeheDiscountProduct">
  138. SELECT
  139. cca.id,
  140. cca.discountId,
  141. cca.productId,
  142. cca.discountPrice,
  143. cca.status,
  144. cca.sort,
  145. cca.addTime,
  146. s.name AS shopName,
  147. p.name AS productName,
  148. p.mainImage AS image
  149. FROM
  150. cm_hehe_discount_product cca
  151. left join cm_hehe_product chp on cca.productId = chp.productId
  152. LEFT JOIN product p ON chp.productId = p.productID
  153. LEFT JOIN shop s ON p.shopID = s.shopID
  154. WHERE
  155. cca.discountId = #{discountId}
  156. ORDER BY
  157. - cca.sort DESC
  158. </select>
  159. <select id="findDiscountUserList" resultType="com.caimei.modules.hehe.entity.CmHeheDiscountUser">
  160. select chu.id, chu.userId, chu.discountId, chu.addTime, u.nickName, u.mobile, u.userIdentity
  161. from cm_hehe_discount_user chu
  162. left join cm_hehe_user u on chu.userId = u.userId
  163. where chu.discountId = #{id}
  164. order by chu.addTime desc
  165. </select>
  166. <select id="findAllUserIds" resultType="java.lang.String">
  167. select group_concat(userId) from cm_hehe_discount_user;
  168. </select>
  169. </mapper>