ProductDao.xml 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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.admin.dao.ProductDao">
  4. <resultMap type="com.kmall.admin.entity.ProductEntity" id="productMap">
  5. <result property="id" column="id"/>
  6. <result property="goodsId" column="goods_id"/>
  7. <result property="goodsSpecificationIds" column="goods_specification_ids"/>
  8. <result property="goodsSpecificationNameValue" column="goods_specification_name_value"/>
  9. <result property="goodsSn" column="goods_sn"/>
  10. <result property="goodsNumber" column="goods_number"/>
  11. <result property="goodsDefault" column="goods_default"/>
  12. </resultMap>
  13. <select id="queryObject" resultType="com.kmall.admin.entity.ProductEntity">
  14. select
  15. id,
  16. goods_id,
  17. goods_specification_ids,
  18. goods_specification_name_value,
  19. goods_sn,
  20. goods_number,
  21. goods_default
  22. from mall_product
  23. where id = #{id}
  24. </select>
  25. <select id="queryObjectByGoodsIdAndStoreId" resultType="com.kmall.admin.entity.ProductEntity">
  26. select
  27. p.id,
  28. p.goods_id,
  29. p.goods_specification_ids,
  30. p.goods_specification_name_value,
  31. p.goods_sn,
  32. p.goods_number,
  33. p.goods_default
  34. from mall_product p
  35. <if test="storeId != null and storeId != ''">
  36. left join mall_product_store_rela r on p.id = r.product_id and p.goods_id = r.goods_id
  37. </if>
  38. where p.goods_id = #{goodsId}
  39. <if test="storeId != null and storeId != ''">
  40. and r.store_id = #{storeId}
  41. </if>
  42. </select>
  43. <select id="queryList" resultType="com.kmall.admin.entity.ProductEntity">
  44. select
  45. mall_product.*,
  46. mall_goods.name goods_name
  47. from mall_product
  48. LEFT JOIN mall_goods ON mall_product.goods_id = mall_goods.id
  49. WHERE 1=1
  50. <if test="goodsId != null and goodsId != ''">
  51. AND mall_product.goods_id = #{goodsId}
  52. </if>
  53. <if test="goodsSpecificationIds != null and goodsSpecificationIds != ''">
  54. AND mall_product.goods_specification_ids = #{goodsSpecificationIds}
  55. </if>
  56. <if test="goodsName != null and goodsName.trim() != ''">
  57. AND mall_goods.name LIKE concat('%',#{goodsName},'%')
  58. </if>
  59. <if test="goodsSn != null and goodsSn.trim() != ''">
  60. AND mall_goods.goods_sn LIKE concat('%',#{goodsSn},'%')
  61. </if>
  62. <choose>
  63. <when test="sidx != null and sidx.trim() != ''">
  64. order by ${sidx} ${order}
  65. </when>
  66. <otherwise>
  67. order by mall_product.id desc
  68. </otherwise>
  69. </choose>
  70. <if test="offset != null and limit != null">
  71. limit #{offset}, #{limit}
  72. </if>
  73. </select>
  74. <select id="queryTotal" resultType="int">
  75. select count(*) from mall_product
  76. LEFT JOIN mall_goods ON mall_product.goods_id = mall_goods.id
  77. WHERE 1=1
  78. <if test="goodsId != null and goodsId != ''">
  79. AND mall_product.goods_id = #{goodsId}
  80. </if>
  81. <if test="goodsName != null and goodsName.trim() != ''">
  82. AND mall_goods.name LIKE concat('%',#{goodsName},'%')
  83. </if>
  84. <if test="goodsSpecificationIds != null and goodsSpecificationIds != ''">
  85. AND mall_product.goods_specification_ids = #{goodsSpecificationIds}
  86. </if>
  87. <if test="goodsSn != null and goodsSn.trim() != ''">
  88. AND mall_goods.goods_sn LIKE concat('%',#{goodsSn},'%')
  89. </if>
  90. </select>
  91. <insert id="save" parameterType="com.kmall.admin.entity.ProductEntity" useGeneratedKeys="true" keyProperty="id">
  92. insert into mall_product(
  93. `goods_id`,
  94. `goods_specification_ids`,
  95. `goods_specification_name_value`,
  96. `goods_sn`,
  97. `goods_number`,
  98. `goods_default`
  99. )
  100. values(
  101. #{goodsId},
  102. #{goodsSpecificationIds},
  103. #{goodsSpecificationNameValue},
  104. #{goodsSn},
  105. #{goodsNumber},
  106. #{goodsDefault}
  107. )
  108. </insert>
  109. <update id="update" parameterType="com.kmall.admin.entity.ProductEntity">
  110. update mall_product
  111. <set>
  112. <if test="goodsId != null">`goods_id` = #{goodsId},</if>
  113. <if test="goodsSpecificationIds != null">`goods_specification_ids` = #{goodsSpecificationIds},</if>
  114. <if test="goodsSpecificationNameValue != null">`goods_specification_name_value` =
  115. #{goodsSpecificationNameValue},
  116. </if>
  117. <if test="goodsSn != null">`goods_sn` = #{goodsSn},</if>
  118. <if test="goodsNumber != null">`goods_number` = #{goodsNumber},</if>
  119. <if test="goodsDefault != null">`goods_default` = #{goodsDefault},</if>
  120. </set>
  121. where id = #{id}
  122. </update>
  123. <delete id="delete">
  124. delete from mall_product where id = #{id}
  125. </delete>
  126. <delete id="deleteByGoodsId">
  127. delete from mall_product where goods_id = #{goodsId}
  128. </delete>
  129. <delete id="deleteBatch">
  130. delete from mall_product where id in
  131. <foreach item="id" collection="array" open="(" separator="," close=")">
  132. #{id}
  133. </foreach>
  134. </delete>
  135. <insert id="saveBatch" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">
  136. insert into mall_product(
  137. `goods_id`,
  138. `goods_specification_ids`,
  139. `goods_specification_name_value`,
  140. `goods_sn`,
  141. `goods_number`,
  142. `goods_default`
  143. )
  144. values
  145. <foreach collection="list" index="index" item="item" separator=",">
  146. (
  147. #{item.goodsId},
  148. #{item.goodsSpecificationIds},
  149. #{item.goodsSpecificationNameValue},
  150. #{item.goodsSn},
  151. #{item.goodsNumber},
  152. #{item.goodsDefault}
  153. )
  154. </foreach>
  155. </insert>
  156. <update id="updateBatch" parameterType="java.util.List">
  157. <foreach collection="list" item="item" index="index" open="" close="" separator=";">
  158. update mall_product
  159. <set>
  160. <if test="item.goodsId != null">`goods_id` = #{item.goodsId},</if>
  161. <if test="item.goodsSpecificationIds != null">`goods_specification_ids` = #{item.goodsSpecificationIds},</if>
  162. <if test="item.goodsSpecificationNameValue != null">`goods_specification_name_value` =
  163. #{item.goodsSpecificationNameValue},
  164. </if>
  165. <if test="item.goodsSn != null">`goods_sn` = #{item.goodsSn},</if>
  166. <if test="item.goodsNumber != null">`goods_number` = #{item.goodsNumber},</if>
  167. <if test="item.goodsDefault != null">`goods_default` = #{item.goodsDefault},</if>
  168. </set>
  169. where id = #{item.id}
  170. </foreach>
  171. </update>
  172. </mapper>