<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.tmerclub.cloud.product.mapper.SpuConsignmentChangeMapper">
  <resultMap id="spuConsignmentChangeMap" type="com.tmerclub.cloud.product.model.SpuConsignmentChange">
    <id column="consignment_change_id" property="consignmentChangeId" />
    <result column="spu_id" property="spuId"/>
    <result column="name_change" property="nameChange"/>
    <result column="image_change" property="imageChange"/>
    <result column="selling_point_change" property="sellingPointChange"/>
    <result column="video_change" property="videoChange"/>
    <result column="measure_unit_change" property="measureUnitChange"/>
    <result column="brand_change" property="brandChange"/>
    <result column="detail_change" property="detailChange"/>
    <result column="create_time" property="createTime"/>
    <result column="update_time" property="updateTime"/>
    <result column="spu_code_change" property="spuCodeChange"/>
  </resultMap>
  <sql id="Vo_Column_List">
    `consignment_change_id`,`spu_id`,`name_change`,`image_change`,`selling_point_change`,`video_change`,`measure_unit_change`,`brand_change`,`detail_change`,`spu_code_change`,`create_time`,`update_time`
  </sql>
  <select id="list" resultMap="spuConsignmentChangeMap">
    select <include refid="Vo_Column_List"/> from spu_consignment_change order by consignment_change_id desc
  </select>
  <select id="getByConsignmentChangeId" resultMap="spuConsignmentChangeMap">
    select <include refid="Vo_Column_List"/> from spu_consignment_change where consignment_change_id = #{consignmentChangeId}
  </select>
  <insert id="save">
    insert into spu_consignment_change (`spu_id`)
    values (#{spuConsignmentChange.spuId})
  </insert>
  <update id="update">
    update spu_consignment_change
    <set>
      <if test="spuConsignmentChange.spuId != null">
        `spu_id` = #{spuConsignmentChange.spuId},
      </if>
      <if test="spuConsignmentChange.nameChange != null">
        `name_change` = #{spuConsignmentChange.nameChange},
      </if>
      <if test="spuConsignmentChange.imageChange != null">
        `image_change` = #{spuConsignmentChange.imageChange},
      </if>
      <if test="spuConsignmentChange.sellingPointChange != null">
        `selling_point_change` = #{spuConsignmentChange.sellingPointChange},
      </if>
      <if test="spuConsignmentChange.videoChange != null">
        `video_change` = #{spuConsignmentChange.videoChange},
      </if>
      <if test="spuConsignmentChange.measureUnitChange != null">
        `measure_unit_change` = #{spuConsignmentChange.measureUnitChange},
      </if>
      <if test="spuConsignmentChange.brandChange != null">
        `brand_change` = #{spuConsignmentChange.brandChange},
      </if>
      <if test="spuConsignmentChange.detailChange != null">
        `detail_change` = #{spuConsignmentChange.detailChange},
      </if>
    </set>
    where consignment_change_id = #{spuConsignmentChange.consignmentChangeId}
  </update>
  <delete id="deleteById">
    delete from spu_consignment_change where consignment_change_id = #{consignmentChangeId}
  </delete>

  <update id="updateBySpuId">
    update spu_consignment_change
    <set>
      <if test="spuConsignmentChange.nameChange != null">
        `name_change` = #{spuConsignmentChange.nameChange},
      </if>
      <if test="spuConsignmentChange.imageChange != null">
        `image_change` = #{spuConsignmentChange.imageChange},
      </if>
      <if test="spuConsignmentChange.sellingPointChange != null">
        `selling_point_change` = #{spuConsignmentChange.sellingPointChange},
      </if>
      <if test="spuConsignmentChange.videoChange != null">
        `video_change` = #{spuConsignmentChange.videoChange},
      </if>
      <if test="spuConsignmentChange.measureUnitChange != null">
        `measure_unit_change` = #{spuConsignmentChange.measureUnitChange},
      </if>
      <if test="spuConsignmentChange.brandChange != null">
        `brand_change` = #{spuConsignmentChange.brandChange},
      </if>
      <if test="spuConsignmentChange.detailChange != null">
        `detail_change` = #{spuConsignmentChange.detailChange},
      </if>
      <if test="spuConsignmentChange.spuCodeChange != null">
        `spu_code_change` = #{spuConsignmentChange.spuCodeChange},
      </if>
    </set>
    where spu_id = #{spuConsignmentChange.spuId}
  </update>

  <select id="getBySpuId" resultMap="spuConsignmentChangeMap">
    select <include refid="Vo_Column_List"/> from spu_consignment_change where spu_id = #{spuId}
  </select>

  <select id="batchGetBySpuIdList" resultMap="spuConsignmentChangeMap">
    select <include refid="Vo_Column_List"/> from spu_consignment_change where spu_id in
    <foreach collection="spuIdList" item="spuId"  open="(" separator="," close=")">
      #{spuId}
    </foreach>
  </select>
</mapper>
