GoodsAttributeDao.xml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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.GoodsAttributeDao">
  4. <!-- 可根据自己的需求,是否要使用 -->
  5. <resultMap type="com.kmall.admin.entity.GoodsAttributeEntity" id="goodsAttributeMap">
  6. <result property="id" column="id"/>
  7. <result property="goodsId" column="goods_id"/>
  8. <result property="merchSn" column="merch_sn"/>
  9. <result property="attributeId" column="attribute_id"/>
  10. <result property="value" column="value"/>
  11. </resultMap>
  12. <select id="queryObject" resultType="com.kmall.admin.entity.GoodsAttributeEntity">
  13. select
  14. id,
  15. goods_id,
  16. merch_sn,
  17. attribute_id,
  18. value
  19. from mall_goods_attribute
  20. where id = #{id}
  21. </select>
  22. <select id="queryList" resultType="com.kmall.admin.entity.GoodsAttributeEntity">
  23. select
  24. mall_goods_attribute.id,
  25. mall_goods_attribute.goods_id,
  26. mall_goods_attribute.merch_sn,
  27. mall_goods_attribute.attribute_id,
  28. mall_goods_attribute.value,
  29. mall_goods.name goods_name,
  30. mall_attribute.name attribute_name
  31. from mall_goods_attribute
  32. LEFT JOIN mall_goods ON mall_goods.id = mall_goods_attribute.goods_id
  33. LEFT JOIN mall_attribute ON mall_attribute.id = mall_goods_attribute.attribute_id
  34. WHERE 1=1
  35. <if test="goodsId != null and goodsId != ''">
  36. AND mall_goods_attribute.goods_id = #{goodsId}
  37. </if>
  38. <if test="storeId != null and storeId != ''">
  39. AND mall_goods_attribute.store_id = #{storeId}
  40. </if>
  41. <if test="attributeId != null and attributeId != ''">
  42. AND mall_goods_attribute.attribute_id = #{attributeId}
  43. </if>
  44. <choose>
  45. <when test="sidx != null and sidx.trim() != ''">
  46. order by ${sidx} ${order}
  47. </when>
  48. <otherwise>
  49. order by id desc
  50. </otherwise>
  51. </choose>
  52. <if test="offset != null and limit != null">
  53. limit #{offset}, #{limit}
  54. </if>
  55. </select>
  56. <select id="queryTotal" resultType="int">
  57. select count(*) from mall_goods_attribute
  58. WHERE 1=1
  59. <if test="goodsId != null and goodsId != ''">
  60. AND goods_id = #{goodsId}
  61. </if>
  62. <if test="attributeId != null and attributeId != ''">
  63. AND attribute_id = #{attributeId}
  64. </if>
  65. </select>
  66. <insert id="save" parameterType="com.kmall.admin.entity.GoodsAttributeEntity" useGeneratedKeys="true" keyProperty="id">
  67. insert into mall_goods_attribute(
  68. store_id,
  69. `goods_id`,
  70. `merch_sn`,
  71. `attribute_id`,
  72. `value`)
  73. values(
  74. #{storeId},
  75. #{goodsId},
  76. #{merchSn},
  77. #{attributeId},
  78. #{value})
  79. </insert>
  80. <update id="update" parameterType="com.kmall.admin.entity.GoodsAttributeEntity">
  81. update mall_goods_attribute
  82. <set>
  83. <if test="storeId != null">`store_id` = #{storeId},</if>
  84. <if test="goodsId != null">`goods_id` = #{goodsId},</if>
  85. <if test="merchSn != null">`merch_sn` = #{merchSn},</if>
  86. <if test="attributeId != null">`attribute_id` = #{attributeId},</if>
  87. <if test="value != null">`value` = #{value}</if>
  88. </set>
  89. where id = #{id}
  90. </update>
  91. <update id="updateByGoodsIdAttributeId" parameterType="com.kmall.admin.entity.GoodsAttributeEntity">
  92. update mall_goods_attribute
  93. <set>
  94. <if test="value != null">`value` = #{value}</if>
  95. </set>
  96. where goods_id = #{goodsId} AND attribute_id = #{attributeId} and store_id = #{storeId}
  97. </update>
  98. <delete id="delete">
  99. delete from mall_goods_attribute where id = #{value}
  100. </delete>
  101. <delete id="deleteByGoodsId">
  102. delete from mall_goods_attribute where goods_id = #{goodsId}
  103. </delete>
  104. <delete id="deleteBatch">
  105. delete from mall_goods_attribute where id in
  106. <foreach item="id" collection="array" open="(" separator="," close=")">
  107. #{id}
  108. </foreach>
  109. </delete>
  110. </mapper>