<?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.ms.dal.mapper.PlatformPurchaseOrderSkuMapper">

    <resultMap id="BaseResultMap" type="com.ms.dal.entity.PlatformPurchaseOrderSku">
            <id property="purSkuOrderId" column="pur_sku_order_id" jdbcType="VARCHAR"/>
            <result property="purOrderId" column="pur_order_id" jdbcType="VARCHAR"/>
            <result property="shopId" column="shop_id" jdbcType="BIGINT"/>
            <result property="skuOrderId" column="sku_order_id" jdbcType="VARCHAR"/>
            <result property="outerProductId" column="outer_product_id" jdbcType="VARCHAR"/>
            <result property="outerSkuId" column="outer_sku_id" jdbcType="VARCHAR"/>
            <result property="cargoId" column="cargo_id" jdbcType="BIGINT"/>
            <result property="cargoSkuId" column="cargo_sku_id" jdbcType="BIGINT"/>
            <result property="productId" column="product_id" jdbcType="BIGINT"/>
            <result property="skuId" column="sku_id" jdbcType="BIGINT"/>
            <result property="num" column="num" jdbcType="BIGINT"/>
            <result property="gmtCreate" column="gmt_create" jdbcType="TIMESTAMP"/>
            <result property="gmtModified" column="gmt_modified" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="Base_Column_List">
        pur_sku_order_id,pur_order_id,shop_id,
        sku_order_id,outer_product_id,outer_sku_id,
        cargo_id,cargo_sku_id,product_id,
        sku_id,num,gmt_create,
        gmt_modified
    </sql>

    <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from platform_purchase_order_sku
        where  pur_sku_order_id = #{purSkuOrderId,jdbcType=VARCHAR} 
    </select>

    <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
        delete from platform_purchase_order_sku
        where  pur_sku_order_id = #{purSkuOrderId,jdbcType=VARCHAR} 
    </delete>
    <insert id="insert" keyColumn="pur_sku_order_id" keyProperty="purSkuOrderId" parameterType="com.ms.dal.entity.PlatformPurchaseOrderSku" useGeneratedKeys="true">
        insert into platform_purchase_order_sku
        ( pur_sku_order_id,pur_order_id,shop_id
        ,sku_order_id,outer_product_id,outer_sku_id
        ,cargo_id,cargo_sku_id,product_id
        ,sku_id,num,gmt_create
        ,gmt_modified)
        values (#{purSkuOrderId,jdbcType=VARCHAR},#{purOrderId,jdbcType=VARCHAR},#{shopId,jdbcType=BIGINT}
        ,#{skuOrderId,jdbcType=VARCHAR},#{outerProductId,jdbcType=VARCHAR},#{outerSkuId,jdbcType=VARCHAR}
        ,#{cargoId,jdbcType=BIGINT},#{cargoSkuId,jdbcType=BIGINT},#{productId,jdbcType=BIGINT}
        ,#{skuId,jdbcType=BIGINT},#{num,jdbcType=BIGINT},#{gmtCreate,jdbcType=TIMESTAMP}
        ,#{gmtModified,jdbcType=TIMESTAMP})
    </insert>
    <update id="insertOrUpdate"  keyColumn="pur_sku_order_id" keyProperty="purSkuOrderId" parameterType="com.ms.dal.entity.PlatformPurchaseOrderSku"
        useGeneratedKeys="true">
        insert into platform_purchase_order_sku
        <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="purSkuOrderId != null">pur_sku_order_id,</if>
                <if test="purOrderId != null">pur_order_id,</if>
                <if test="shopId != null">shop_id,</if>
                <if test="skuOrderId != null">sku_order_id,</if>
                <if test="outerProductId != null">outer_product_id,</if>
                <if test="outerSkuId != null">outer_sku_id,</if>
                <if test="cargoId != null">cargo_id,</if>
                <if test="cargoSkuId != null">cargo_sku_id,</if>
                <if test="productId != null">product_id,</if>
                <if test="skuId != null">sku_id,</if>
                <if test="num != null">num,</if>
                <if test="gmtCreate != null">gmt_create,</if>
                <if test="gmtModified != null">gmt_modified,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                <if test="purSkuOrderId != null">#{purSkuOrderId,jdbcType=VARCHAR},</if>
                <if test="purOrderId != null">#{purOrderId,jdbcType=VARCHAR},</if>
                <if test="shopId != null">#{shopId,jdbcType=BIGINT},</if>
                <if test="skuOrderId != null">#{skuOrderId,jdbcType=VARCHAR},</if>
                <if test="outerProductId != null">#{outerProductId,jdbcType=VARCHAR},</if>
                <if test="outerSkuId != null">#{outerSkuId,jdbcType=VARCHAR},</if>
                <if test="cargoId != null">#{cargoId,jdbcType=BIGINT},</if>
                <if test="cargoSkuId != null">#{cargoSkuId,jdbcType=BIGINT},</if>
                <if test="productId != null">#{productId,jdbcType=BIGINT},</if>
                <if test="skuId != null">#{skuId,jdbcType=BIGINT},</if>
                <if test="num != null">#{num,jdbcType=BIGINT},</if>
                <if test="gmtCreate != null">#{gmtCreate,jdbcType=TIMESTAMP},</if>
                <if test="gmtModified != null">#{gmtModified,jdbcType=TIMESTAMP},</if>
        </trim>
        ON DUPLICATE KEY UPDATE
        <trim  suffixOverrides=",">
                <if test="purOrderId != null">
                    pur_order_id = #{purOrderId,jdbcType=VARCHAR},
                </if>
                <if test="shopId != null">
                    shop_id = #{shopId,jdbcType=BIGINT},
                </if>
                <if test="skuOrderId != null">
                    sku_order_id = #{skuOrderId,jdbcType=VARCHAR},
                </if>
                <if test="outProductId != null">
                    outer_product_id = #{outProductId,jdbcType=VARCHAR},
                </if>
                <if test="outSkuId != null">
                    outer_sku_id = #{outSkuId,jdbcType=VARCHAR},
                </if>
                <if test="cargoId != null">
                    cargo_id = #{cargoId,jdbcType=BIGINT},
                </if>
                <if test="cargoSkuId != null">
                    cargo_sku_id = #{cargoSkuId,jdbcType=BIGINT},
                </if>
                <if test="productId != null">
                    product_id = #{productId,jdbcType=BIGINT},
                </if>
                <if test="skuId != null">
                    sku_id = #{skuId,jdbcType=BIGINT},
                </if>
                <if test="num != null">
                    num = #{num,jdbcType=BIGINT},
                </if>
                <if test="gmtCreate != null">
                    gmt_create = #{gmtCreate,jdbcType=TIMESTAMP},
                </if>
                <if test="gmtModified != null">
                    gmt_modified = #{gmtModified,jdbcType=TIMESTAMP},
                </if>
        </trim>
    </update>
    <insert id="insertSelective" keyColumn="pur_sku_order_id" keyProperty="purSkuOrderId" parameterType="com.ms.dal.entity.PlatformPurchaseOrderSku" useGeneratedKeys="true">
        insert into platform_purchase_order_sku
        <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="purSkuOrderId != null">pur_sku_order_id,</if>
                <if test="purOrderId != null">pur_order_id,</if>
                <if test="shopId != null">shop_id,</if>
                <if test="skuOrderId != null">sku_order_id,</if>
                <if test="outerProductId != null">outer_product_id,</if>
                <if test="outerSkuId != null">outer_sku_id,</if>
                <if test="cargoId != null">cargo_id,</if>
                <if test="cargoSkuId != null">cargo_sku_id,</if>
                <if test="productId != null">product_id,</if>
                <if test="skuId != null">sku_id,</if>
                <if test="num != null">num,</if>
                <if test="gmtCreate != null">gmt_create,</if>
                <if test="gmtModified != null">gmt_modified,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                <if test="purSkuOrderId != null">#{purSkuOrderId,jdbcType=VARCHAR},</if>
                <if test="purOrderId != null">#{purOrderId,jdbcType=VARCHAR},</if>
                <if test="shopId != null">#{shopId,jdbcType=BIGINT},</if>
                <if test="skuOrderId != null">#{skuOrderId,jdbcType=VARCHAR},</if>
                <if test="outerProductId != null">#{outerProductId,jdbcType=VARCHAR},</if>
                <if test="outerSkuId != null">#{outerSkuId,jdbcType=VARCHAR},</if>
                <if test="cargoId != null">#{cargoId,jdbcType=BIGINT},</if>
                <if test="cargoSkuId != null">#{cargoSkuId,jdbcType=BIGINT},</if>
                <if test="productId != null">#{productId,jdbcType=BIGINT},</if>
                <if test="skuId != null">#{skuId,jdbcType=BIGINT},</if>
                <if test="num != null">#{num,jdbcType=BIGINT},</if>
                <if test="gmtCreate != null">#{gmtCreate,jdbcType=TIMESTAMP},</if>
                <if test="gmtModified != null">#{gmtModified,jdbcType=TIMESTAMP},</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.ms.dal.entity.PlatformPurchaseOrderSku">
        update platform_purchase_order_sku
        <set>
                <if test="purOrderId != null">
                    pur_order_id = #{purOrderId,jdbcType=VARCHAR},
                </if>
                <if test="shopId != null">
                    shop_id = #{shopId,jdbcType=BIGINT},
                </if>
                <if test="skuOrderId != null">
                    sku_order_id = #{skuOrderId,jdbcType=VARCHAR},
                </if>
                <if test="outProductId != null">
                    outer_product_id = #{outerProductId,jdbcType=VARCHAR},
                </if>
                <if test="outSkuId != null">
                    outer_sku_id = #{outerSkuId,jdbcType=VARCHAR},
                </if>
                <if test="cargoId != null">
                    cargo_id = #{cargoId,jdbcType=BIGINT},
                </if>
                <if test="cargoSkuId != null">
                    cargo_sku_id = #{cargoSkuId,jdbcType=BIGINT},
                </if>
                <if test="productId != null">
                    product_id = #{productId,jdbcType=BIGINT},
                </if>
                <if test="skuId != null">
                    sku_id = #{skuId,jdbcType=BIGINT},
                </if>
                <if test="num != null">
                    num = #{num,jdbcType=BIGINT},
                </if>
                <if test="gmtCreate != null">
                    gmt_create = #{gmtCreate,jdbcType=TIMESTAMP},
                </if>
                <if test="gmtModified != null">
                    gmt_modified = #{gmtModified,jdbcType=TIMESTAMP},
                </if>
        </set>
        where   pur_sku_order_id = #{purSkuOrderId,jdbcType=VARCHAR} 
    </update>
    <update id="updateByPrimaryKey" parameterType="com.ms.dal.entity.PlatformPurchaseOrderSku">
        update platform_purchase_order_sku
        set 
            pur_order_id =  #{purOrderId,jdbcType=VARCHAR},
            shop_id =  #{shopId,jdbcType=BIGINT},
            sku_order_id =  #{skuOrderId,jdbcType=VARCHAR},
            outer_product_id =  #{outerProductId,jdbcType=VARCHAR},
            outer_sku_id =  #{outerSkuId,jdbcType=VARCHAR},
            cargo_id =  #{cargoId,jdbcType=BIGINT},
            cargo_sku_id =  #{cargoSkuId,jdbcType=BIGINT},
            product_id =  #{productId,jdbcType=BIGINT},
            sku_id =  #{skuId,jdbcType=BIGINT},
            num =  #{num,jdbcType=BIGINT},
            gmt_create =  #{gmtCreate,jdbcType=TIMESTAMP},
            gmt_modified =  #{gmtModified,jdbcType=TIMESTAMP}
        where   pur_sku_order_id = #{purSkuOrderId,jdbcType=VARCHAR} 
    </update>
    <insert id="insertBatch" keyColumn="purchase_order_item_id" keyProperty="purchaseOrderItemId" useGeneratedKeys="true">
        insert into platform_purchase_order_sku
        (pur_sku_order_id,pur_order_id,shop_id
        ,sku_order_id,outer_product_id,outer_sku_id
        ,cargo_id,cargo_sku_id,product_id
        ,sku_id,num,gmt_create
        ,gmt_modified)
        values
        <foreach item="item" collection="list" separator="," >
            (#{item.purSkuOrderId,jdbcType=VARCHAR},#{item.purOrderId,jdbcType=VARCHAR},#{item.shopId,jdbcType=BIGINT}
            ,#{item.skuOrderId,jdbcType=VARCHAR},#{item.outerProductId,jdbcType=VARCHAR},#{item.outerSkuId,jdbcType=VARCHAR}
            ,#{item.cargoId,jdbcType=BIGINT},#{item.cargoSkuId,jdbcType=BIGINT},#{item.productId,jdbcType=BIGINT}
            ,#{item.skuId,jdbcType=BIGINT},#{item.num,jdbcType=BIGINT},#{item.gmtCreate,jdbcType=TIMESTAMP}
            ,#{item.gmtModified,jdbcType=TIMESTAMP})
        </foreach>
    </insert>
    <select id="getListByPurOrderIds" resultType="com.ms.dal.entity.PlatformPurchaseOrderSku">
        select
        <include refid="Base_Column_List" />
        from platform_purchase_order_sku
        where 1=1
        <choose>
            <when test="purOrderIds!=null and purOrderIds.size>0">
                and pur_order_id in
                <foreach collection="purOrderIds" index="index" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </when>
            <otherwise>
                AND 1=0
            </otherwise>
        </choose>
    </select>
</mapper>
