<?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.SpuSkuAttrValueMapper">
  <resultMap id="spuSkuAttrValueMap" type="com.tmerclub.cloud.product.model.SpuSkuAttrValue">
    <id column="spu_sku_attr_id" property="spuSkuAttrId" />
    <result column="create_time" property="createTime"/>
    <result column="update_time" property="updateTime"/>
    <result column="spu_id" property="spuId"/>
    <result column="sku_id" property="skuId"/>
    <result column="attr_id" property="attrId"/>
    <result column="attr_name" property="attrName"/>
    <result column="attr_value_id" property="attrValueId"/>
    <result column="attr_value_name" property="attrValueName"/>
    <result column="status" property="status"/>
  </resultMap>
  <sql id="Vo_Column_List">
    `spu_sku_attr_id`,`create_time`,`update_time`,`spu_id`,`sku_id`,`attr_id`,`attr_value_id`,`status`
  </sql>

  <insert id="batchSave" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="spuSkuAttrId">
    insert into spu_sku_attr_value (`spu_id`,`sku_id`,`lang`,`attr_id`,`attr_value_id`,`status`) values
    <foreach collection="spuSkuAttrValues" item="spuSkuAttrValue" separator=",">
      (#{spuSkuAttrValue.spuId},#{spuSkuAttrValue.skuId},#{spuSkuAttrValue.lang},#{spuSkuAttrValue.attrId},
      #{spuSkuAttrValue.attrValueId},#{spuSkuAttrValue.status})
    </foreach>
  </insert>

  <update id="updateBySpuId">
    update spu_sku_attr_value set status = -1 where spu_id = #{spuId}
  </update>

  <update id="updateBatch">
    <foreach collection="spuSkuAttrValues" item="spuSkuAttrValue">
        update spu_sku_attr_value set update_time = NOW()
        WHERE spu_sku_attr_id = #{spuSkuAttrValue.spuSkuAttrId};
    </foreach>
  </update>
  <delete id="deleteById">
    delete from spu_sku_attr_value where spu_sku_attr_id = #{spuSkuAttrId}
  </delete>

  <update id="changeStatusBySkuId">
    update spu_sku_attr_value set `status` = #{status} where sku_id in
      <foreach collection="skuIds" item="skuId" open="(" close=")" separator=",">
        #{skuId}
      </foreach>
  </update>
</mapper>
