CmHeheProductMapper.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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.CmHeheProductDao">
  4. <sql id="cmHeheProductColumns">
  5. a.id AS "id",
  6. a.productId AS "productId",
  7. ifnull(a.bigTypeId,0) AS "bigTypeId",
  8. ifnull(a.smallTypeId,0) AS "smallTypeId",
  9. a.validFlag AS "validFlag",
  10. a.includedTax AS "includedTax",
  11. a.invoiceType AS "invoiceType",
  12. a.clubTaxPoint AS "clubTaxPoint",
  13. a.shopTaxPoint AS "shopTaxPoint",
  14. a.oldProductId,
  15. a.addTime AS "addTime",
  16. p.name AS "name",
  17. p.mainImage AS "mainImage",
  18. s.name AS "shopName",
  19. chap.activityId,
  20. group_concat(chfp.floorId) as floorIds
  21. </sql>
  22. <sql id="cmHeheProductJoins">
  23. LEFT JOIN product p ON a.productId = p.productID
  24. LEFT JOIN shop s ON s.shopID = p.shopID
  25. left join cm_hehe_activity_product chap on a.productId = chap.productId
  26. left join cm_hehe_floor_product chfp on a.productId = chfp.productId
  27. </sql>
  28. <select id="get" resultType="CmHeheProduct">
  29. SELECT
  30. <include refid="cmHeheProductColumns"/>
  31. FROM cm_hehe_product a
  32. <include refid="cmHeheProductJoins"/>
  33. WHERE a.id = #{id}
  34. group by a.id
  35. </select>
  36. <select id="findList" resultType="CmHeheProduct">
  37. SELECT
  38. <include refid="cmHeheProductColumns"/>
  39. FROM cm_hehe_product a
  40. <include refid="cmHeheProductJoins"/>
  41. <where>
  42. <if test="productId != null and productId != ''">
  43. AND a.productId = #{productId}
  44. </if>
  45. <if test="validFlag != null and validFlag != ''">
  46. AND a.validFlag = #{validFlag}
  47. </if>
  48. <if test="includedTax != null and includedTax != ''">
  49. AND a.includedTax = #{includedTax}
  50. </if>
  51. <if test="invoiceType != null and invoiceType != ''">
  52. AND a.invoiceType = #{invoiceType}
  53. </if>
  54. <if test="id != null and id != ''">
  55. AND a.id = #{id}
  56. </if>
  57. <if test="name != null and name != ''">
  58. AND p.name LIKE CONCAT('%',#{name},'%')
  59. </if>
  60. <if test="shopName != null and shopName != ''">
  61. AND s.name LIKE CONCAT('%',#{shopName},'%')
  62. </if>
  63. </where>
  64. group by a.id
  65. <choose>
  66. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  67. ORDER BY ${page.orderBy}
  68. </when>
  69. <otherwise>
  70. ORDER BY addTime DESC
  71. </otherwise>
  72. </choose>
  73. </select>
  74. <select id="findAllList" resultType="CmHeheProduct">
  75. SELECT
  76. <include refid="cmHeheProductColumns"/>
  77. FROM cm_hehe_product a
  78. <include refid="cmHeheProductJoins"/>
  79. <where>
  80. </where>
  81. <choose>
  82. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  83. ORDER BY ${page.orderBy}
  84. </when>
  85. <otherwise>
  86. </otherwise>
  87. </choose>
  88. </select>
  89. <insert id="insert" parameterType="CmHeheProduct" keyProperty="id" useGeneratedKeys="true">
  90. INSERT INTO cm_hehe_product(productId,
  91. bigTypeId,
  92. smallTypeId,
  93. validFlag,
  94. includedTax,
  95. invoiceType,
  96. clubTaxPoint,
  97. shopTaxPoint,
  98. addTime)
  99. VALUES (#{productId},
  100. #{bigTypeId},
  101. #{smallTypeId},
  102. #{validFlag},
  103. #{includedTax},
  104. #{invoiceType},
  105. #{clubTaxPoint},
  106. #{shopTaxPoint},
  107. NOW())
  108. </insert>
  109. <insert id="addActivityProduct">
  110. insert into cm_hehe_activity_product (activityId, productId, addTime, delFlag)
  111. values (#{activityId}, #{productId}, NOW(), 0)
  112. </insert>
  113. <insert id="addFloorProduct">
  114. insert into cm_hehe_floor_product(floorId, productId, validFlag, recommend, sort, addTime)
  115. VALUES (#{floorId}, #{productId}, 1, 0, 1, NOW())
  116. </insert>
  117. <insert id="insertHeHeSkuPrice">
  118. insert into cm_hehe_sku(skuid, productid, price)
  119. values (#{skuId}, #{productId}, #{price})
  120. </insert>
  121. <update id="update">
  122. UPDATE cm_hehe_product
  123. SET productId = #{productId},
  124. bigTypeId = #{bigTypeId},
  125. smallTypeId = #{smallTypeId},
  126. validFlag = #{validFlag},
  127. includedTax = #{includedTax},
  128. invoiceType = #{invoiceType},
  129. clubTaxPoint = #{clubTaxPoint},
  130. shopTaxPoint = #{shopTaxPoint}
  131. WHERE id = #{id}
  132. </update>
  133. <delete id="delete">
  134. DELETE
  135. FROM cm_hehe_product
  136. WHERE id = #{id}
  137. </delete>
  138. <select id="findHeHeProductId" resultType="integer">
  139. SELECT productId
  140. FROM cm_hehe_product
  141. </select>
  142. <select id="findAllProduct" resultType="com.caimei.modules.product.entity.Product">
  143. SELECT
  144. a.*,s.name AS "shopName"
  145. FROM product a
  146. left join cm_organize_product_info copi on copi.productId = a.productID
  147. LEFT JOIN shop s on s.shopID = a.shopID
  148. <where>
  149. a.splitCode is not null and a.splitCode != '' and copi.validFlag=2
  150. and s.shopID in(SELECT shopID FROM shop WHERE name ='深圳市采美奥泰贸易有限公司')
  151. <if test="productID != null">
  152. AND a.productID = #{productID}
  153. </if>
  154. <if test="name != null and name != ''">
  155. AND a.name LIKE concat('%',#{name},'%')
  156. </if>
  157. <if test="shopName != null and shopName != ''">
  158. AND s.name LIKE concat('%',#{shopName},'%')
  159. </if>
  160. <if test="ids != null and ids.size() > 0 ">
  161. AND a.productID NOT IN
  162. <foreach collection="ids" open="(" close=")" item="id" separator=",">
  163. #{id}
  164. </foreach>
  165. </if>
  166. </where>
  167. group by a.productID
  168. <choose>
  169. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  170. ORDER BY ${page.orderBy}
  171. </when>
  172. <otherwise>
  173. order by a.productID
  174. </otherwise>
  175. </choose>
  176. </select>
  177. <select id="findCouponProduct" resultType="com.caimei.modules.product.entity.Product">
  178. SELECT
  179. a.*,s.name AS "shopName"
  180. FROM cm_hehe_product
  181. product a
  182. LEFT JOIN shop s on s.shopID = a.shopID
  183. <where>
  184. <if test="productID != null">
  185. AND a.productID = #{productID}
  186. </if>
  187. <if test="name != null and name != ''">
  188. AND a.name LIKE concat('%',#{name},'%')
  189. </if>
  190. <if test="shopName != null and shopName != ''">
  191. AND s.name LIKE concat('%',#{shopName},'%')
  192. </if>
  193. <if test="ids != null and ids.size() > 0 ">
  194. AND a.productID NOT IN
  195. <foreach collection="ids" open="(" close=")" item="id" separator=",">
  196. #{id}
  197. </foreach>
  198. </if>
  199. </where>
  200. group by a.productID
  201. <choose>
  202. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  203. ORDER BY ${page.orderBy}
  204. </when>
  205. <otherwise>
  206. order by a.productID
  207. </otherwise>
  208. </choose>
  209. </select>
  210. <select id="findProductActivity" resultType="java.lang.Integer">
  211. select activityId
  212. from cm_hehe_activity_product
  213. where productId = #{productId}
  214. </select>
  215. <select id="getNewProductId" resultType="java.lang.Integer">
  216. select productId
  217. from cm_hehe_product
  218. where oldProductId = #{oldProductId}
  219. </select>
  220. <select id="findHeHeFloorProductIds" resultType="java.lang.Integer">
  221. select i.productId
  222. from new_page_floor_image i
  223. left join cm_page_centre c on i.centreId = c.id
  224. left join cm_page p on c.pageId = p.id
  225. where p.type = 8
  226. </select>
  227. <select id="findAllHeheProduct" resultType="com.caimei.modules.product.entity.Product">
  228. SELECT
  229. a.*,s.name AS "shopName"
  230. FROM cm_hehe_product chp left join product a on chp.productId = a.productID
  231. LEFT JOIN shop s on s.shopID = a.shopID
  232. <where>
  233. chp.validFlag = 1
  234. <if test="productID != null">
  235. AND a.productID = #{productID}
  236. </if>
  237. <if test="name != null and name != ''">
  238. AND a.name LIKE concat('%',#{name},'%')
  239. </if>
  240. <if test="shopName != null and shopName != ''">
  241. AND s.name LIKE concat('%',#{shopName},'%')
  242. </if>
  243. <if test="ids != null and ids.size() > 0 ">
  244. AND a.productID NOT IN
  245. <foreach collection="ids" open="(" close=")" item="id" separator=",">
  246. #{id}
  247. </foreach>
  248. </if>
  249. </where>
  250. <choose>
  251. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  252. ORDER BY ${page.orderBy}
  253. </when>
  254. <otherwise>
  255. order by a.productID
  256. </otherwise>
  257. </choose>
  258. </select>
  259. <select id="findActivityProductIds" resultType="java.lang.Integer">
  260. SELECT a.productId
  261. FROM cm_hehe_activity_product a
  262. LEFT JOIN cm_hehe_activity cha ON a.activityId = cha.id
  263. WHERE a.delFlag = 0
  264. AND cha.delFlag = 0
  265. </select>
  266. <select id="findCollageProductIds" resultType="java.lang.Integer">
  267. select productId
  268. from cm_hehe_collage_product
  269. </select>
  270. <select id="findDiscountProductIds" resultType="java.lang.Integer">
  271. select productId
  272. from hehe_discount_activity_product hdap
  273. left join cm_hehe_discount_activity chda on hdap.activityId = chda.id
  274. where chda.id is not null
  275. </select>
  276. <select id="findProductElement" resultType="com.caimei.modules.hehe.entity.CmHeheProduct">
  277. select ifnull(chs.price, 0) as price,
  278. ifnull(cs.shopPercent, 0) as shopPercent,
  279. ifnull(cs.organizePercent, 0) as organizePercent,
  280. ifnull(cs.cmPercent, 0) as cmPercent,
  281. ifnull((SELECT costCheckFlag FROM cm_organize_product_info WHERE productId = cs.productId AND organizeId = cs.organizeId ), 0) as costType,
  282. ifnull(cs.costPrice, 0) as costPrice
  283. ,cs.organizeId
  284. from cm_sku cs
  285. left join cm_hehe_sku chs on cs.skuId = chs.skuId
  286. where cs.productId = #{productId}
  287. and cs.organizeId=(SELECT SUBSTRING(groundMall, 1, 1)FROM product WHERE productID=cs.productId)
  288. order by chs.price asc
  289. limit 1
  290. </select>
  291. <update id="deleteActivityProduct">
  292. UPDATE cm_hehe_activity_product
  293. SET delFlag = 1
  294. WHERE productId = #{productId}
  295. </update>
  296. <update id="deleteCmHeHeSku">
  297. delete from cm_hehe_sku
  298. WHERE productId = #{productId}
  299. </update>
  300. <update id="updateProductId">
  301. update cm_hehe_product
  302. set oldProductId = #{oldProductId},
  303. productId = #{newProductId}
  304. where productId = #{oldProductId}
  305. </update>
  306. <update id="updateHeHeSkuPrice">
  307. update cm_hehe_sku
  308. set price=#{price}
  309. where skuId = #{skuId}
  310. </update>
  311. <select id="findLadderList" resultType="com.caimei.modules.product.entity.CmLadderPrice">
  312. select id, buyPrice, buyNum
  313. from cm_hehe_activity_ladder
  314. where skuId = #{skuId}
  315. </select>
  316. <select id="findMobileByUserYear" resultType="String">
  317. select chu.mobile
  318. from cm_hehe_user chu
  319. left join user u on u.userID = chu.userID
  320. where chu.userIdentity='1' and u.validFlag='1' and u.loginTime >= DATE_SUB(NOW(), INTERVAL #{num} YEAR)
  321. </select>
  322. <select id="getMonthCount" resultType="java.lang.Integer">
  323. <if test="type != null and type == 1">
  324. select count(1)
  325. from cm_hehe_collage_product
  326. where addTime >= DATE_SUB(NOW(), INTERVAL #{num} MONTH)
  327. </if>
  328. <if test="type != null and type == 2">
  329. select count(1)
  330. from cm_hehe_activity_product
  331. where addTime >= DATE_SUB(NOW(), INTERVAL #{num} MONTH)
  332. </if>
  333. <if test="type != null and type == 3">
  334. select count(1)
  335. from hehe_discount_activity_product
  336. where addTime >= DATE_SUB(NOW(), INTERVAL #{num} MONTH)
  337. </if>
  338. </select>
  339. </mapper>