1
0

ApiProductMapper.xml 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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.kmall.api.dao.ApiProductMapper">
  4. <!-- 可根据自己的需求,是否要使用 -->
  5. <resultMap type="com.kmall.api.entity.ProductVo" id="productMap">
  6. <result property="id" column="id"/>
  7. <result property="goods_id" column="goods_id"/>
  8. <result property="goods_specification_ids" column="goods_specification_ids"/>
  9. <result property="goods_specification_name_value" column="goods_specification_name_value"/>
  10. <result property="goods_sn" column="goods_sn"/>
  11. <result property="retail_price" column="retail_price"/>
  12. <result property="market_price" column="market_price"/>
  13. <result property="store_id" column="store_id"/>
  14. <result property="stock_num" column="stock_num"/>
  15. <result property="sell_volume" column="sell_volume"/>
  16. <result property="goods_default" column="goods_default"/>
  17. </resultMap>
  18. <select id="queryObject" resultMap="productMap">
  19. SELECT
  20. a.*
  21. FROM
  22. mall_product a
  23. where id = #{value}
  24. </select>
  25. <select id="queryObjectByStoreId" resultMap="productMap">
  26. SELECT
  27. a.id,
  28. a.goods_id,
  29. a.goods_specification_ids,
  30. a.goods_specification_name_value,
  31. a.goods_sn,
  32. a.goods_default,
  33. b.sell_volume,
  34. b.market_price,
  35. b.retail_price,
  36. b.store_id,
  37. b.stock_num
  38. FROM
  39. mall_product a
  40. LEFT JOIN mall_product_store_rela b ON a.id = b.product_id
  41. where b.stock_num is not null and b.stock_num > 0 and a.id = #{id} and b.store_id = #{store_id}
  42. </select>
  43. <select id="queryByStoreId" resultMap="productMap">
  44. SELECT
  45. a.id,
  46. a.goods_id,
  47. a.goods_specification_ids,
  48. a.goods_specification_name_value,
  49. a.goods_sn,
  50. a.goods_default,
  51. b.sell_volume,
  52. b.market_price,
  53. b.retail_price,
  54. b.store_id,
  55. b.stock_num
  56. FROM
  57. mall_product a
  58. LEFT JOIN mall_product_store_rela b ON a.id = b.product_id
  59. where a.id = #{id} and b.store_id = #{store_id}
  60. </select>
  61. <select id="queryOneByGoodsId" resultMap="productMap">
  62. SELECT
  63. a.id,
  64. a.goods_id,
  65. a.goods_specification_ids,
  66. a.goods_specification_name_value,
  67. a.goods_sn,
  68. a.goods_default,
  69. b.sell_volume,
  70. b.market_price,
  71. b.retail_price,
  72. b.store_id,
  73. b.stock_num
  74. FROM
  75. mall_product a
  76. LEFT JOIN mall_product_store_rela b ON a.id = b.product_id
  77. where b.stock_num is not null and a.goods_id = #{goods_id} and b.store_id = #{store_id}
  78. order by b.stock_num desc,a.id desc
  79. limit 1
  80. </select>
  81. <select id="queryList" resultMap="productMap">
  82. SELECT
  83. a.*,
  84. b.sell_volume,
  85. b.market_price,
  86. b.retail_price,
  87. b.stock_num
  88. FROM
  89. mall_product a
  90. LEFT JOIN mall_product_store_rela b ON a.id = b.product_id
  91. <where>
  92. b.stock_num > 0
  93. <if test="goods_id != null">
  94. and a.goods_id = #{goods_id}
  95. </if>
  96. <if test="store_id != null">
  97. and b.store_id = #{store_id}
  98. </if>
  99. </where>
  100. <choose>
  101. <when test="sidx != null and sidx.trim() != ''">
  102. order by ${sidx} ${order}
  103. </when>
  104. <otherwise>
  105. order by id desc
  106. </otherwise>
  107. </choose>
  108. <if test="offset != null and limit != null">
  109. limit #{offset}, #{limit}
  110. </if>
  111. </select>
  112. <select id="queryTotal" resultType="int">
  113. select count(id) from mall_product
  114. FROM
  115. mall_product a
  116. LEFT JOIN mall_product_store_rela b ON a.id = b.product_id
  117. <where>
  118. b.stock_num > 0
  119. <if test="goods_id != null">
  120. and a.goods_id = #{goods_id}
  121. </if>
  122. <if test="store_id != null">
  123. and b.store_id = #{store_id}
  124. </if>
  125. </where>
  126. </select>
  127. <update id="updateStockNum" parameterType="com.kmall.api.entity.ProductVo">
  128. update mall_product_store_rela a
  129. <set>
  130. <if test="stock_num != null">a.`stock_num` = #{stock_num},</if>
  131. <if test="sell_volume != null">a.`sell_volume` = #{sell_volume},</if>
  132. </set>
  133. where a.product_id = #{id} and a.store_id = #{store_id}
  134. </update>
  135. <update id="updateSellVolumeNum" parameterType="com.kmall.api.entity.ProductVo">
  136. update mall_product_store_rela a
  137. <set>
  138. <if test="sell_volume != null">a.`sell_volume` = #{sell_volume},</if>
  139. </set>
  140. where a.product_id = #{id} and a.store_id = #{store_id}
  141. </update>
  142. </mapper>