ApiProductMapper.xml 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. left join mall_goods g on g.id=b.goods_id
  92. <where>
  93. 1=1 and (g.goods_number > 0 or b.stock_num > 0 )
  94. <if test="goods_id != null">
  95. and a.goods_id = #{goods_id}
  96. </if>
  97. <if test="store_id != null">
  98. and b.store_id = #{store_id}
  99. </if>
  100. </where>
  101. <choose>
  102. <when test="sidx != null and sidx.trim() != ''">
  103. order by ${sidx} ${order}
  104. </when>
  105. <otherwise>
  106. order by id desc
  107. </otherwise>
  108. </choose>
  109. <if test="offset != null and limit != null">
  110. limit #{offset}, #{limit}
  111. </if>
  112. </select>
  113. <select id="queryTotal" resultType="int">
  114. select count(id) from mall_product
  115. FROM
  116. mall_product a
  117. LEFT JOIN mall_product_store_rela b ON a.id = b.product_id
  118. left join mall_goods g on g.id=b.goods_id
  119. <where>
  120. 1=1 and (g.goods_number > 0 or b.stock_num > 0 )
  121. <if test="goods_id != null">
  122. and a.goods_id = #{goods_id}
  123. </if>
  124. <if test="store_id != null">
  125. and b.store_id = #{store_id}
  126. </if>
  127. </where>
  128. </select>
  129. <update id="updateStockNum" parameterType="com.kmall.api.entity.ProductVo">
  130. update mall_product_store_rela a
  131. <set>
  132. <if test="stock_num != null">a.`stock_num` = #{stock_num},</if>
  133. <if test="sell_volume != null">a.`sell_volume` = #{sell_volume},</if>
  134. </set>
  135. where a.product_id = #{id} and a.store_id = #{store_id} and a.goods_id = #{goods_id}
  136. </update>
  137. <update id="updateSellVolumeNum" parameterType="com.kmall.api.entity.ProductVo">
  138. update mall_product_store_rela a
  139. <set>
  140. <if test="sell_volume != null">a.`sell_volume` = #{sell_volume},</if>
  141. </set>
  142. where a.product_id = #{id} and a.store_id = #{store_id}
  143. </update>
  144. </mapper>