ProductDao.xml 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. <choose>
  60. <when test="sidx != null and sidx.trim() != ''">
  61. order by ${sidx} ${order}
  62. </when>
  63. <otherwise>
  64. order by mall_product.id desc
  65. </otherwise>
  66. </choose>
  67. <if test="offset != null and limit != null">
  68. limit #{offset}, #{limit}
  69. </if>
  70. </select>
  71. <select id="queryTotal" resultType="int">
  72. select count(*) from mall_product
  73. LEFT JOIN mall_goods ON mall_product.goods_id = mall_goods.id
  74. WHERE 1=1
  75. <if test="goodsId != null and goodsId != ''">
  76. AND mall_product.goods_id = #{goodsId}
  77. </if>
  78. <if test="goodsName != null and goodsName.trim() != ''">
  79. AND mall_goods.name LIKE concat('%',#{goodsName},'%')
  80. </if>
  81. <if test="goodsSpecificationIds != null and goodsSpecificationIds != ''">
  82. AND mall_product.goods_specification_ids = #{goodsSpecificationIds}
  83. </if>
  84. </select>
  85. <insert id="save" parameterType="com.kmall.admin.entity.ProductEntity" useGeneratedKeys="true" keyProperty="id">
  86. insert into mall_product(
  87. `goods_id`,
  88. `goods_specification_ids`,
  89. `goods_specification_name_value`,
  90. `goods_sn`,
  91. `goods_number`,
  92. `goods_default`
  93. )
  94. values(
  95. #{goodsId},
  96. #{goodsSpecificationIds},
  97. #{goodsSpecificationNameValue},
  98. #{goodsSn},
  99. #{goodsNumber},
  100. #{goodsDefault}
  101. )
  102. </insert>
  103. <update id="update" parameterType="com.kmall.admin.entity.ProductEntity">
  104. update mall_product
  105. <set>
  106. <if test="goodsId != null">`goods_id` = #{goodsId},</if>
  107. <if test="goodsSpecificationIds != null">`goods_specification_ids` = #{goodsSpecificationIds},</if>
  108. <if test="goodsSpecificationNameValue != null">`goods_specification_name_value` =
  109. #{goodsSpecificationNameValue},
  110. </if>
  111. <if test="goodsSn != null">`goods_sn` = #{goodsSn},</if>
  112. <if test="goodsNumber != null">`goods_number` = #{goodsNumber},</if>
  113. <if test="goodsDefault != null">`goods_default` = #{goodsDefault},</if>
  114. </set>
  115. where id = #{id}
  116. </update>
  117. <delete id="delete">
  118. delete from mall_product where id = #{id}
  119. </delete>
  120. <delete id="deleteByGoodsId">
  121. delete from mall_product where goods_id = #{goodsId}
  122. </delete>
  123. <delete id="deleteBatch">
  124. delete from mall_product where id in
  125. <foreach item="id" collection="array" open="(" separator="," close=")">
  126. #{id}
  127. </foreach>
  128. </delete>
  129. </mapper>