<?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.RefundPurchaseOrderSkuMapper">

    <resultMap id="BaseResultMap" type="com.ms.dal.entity.RefundPurchaseOrderSku">
            <id property="refundPurchaseOrderSkuId" column="refund_purchase_order_sku_id" jdbcType="BIGINT"/>
            <result property="refundId" column="refund_id" jdbcType="VARCHAR"/>
            <result property="shopId" column="shop_id" jdbcType="BIGINT"/>
            <result property="purOrderId" column="pur_order_id" jdbcType="VARCHAR"/>
            <result property="purSkuOrderId" column="pur_sku_order_id" jdbcType="VARCHAR"/>
            <result property="orderId" column="order_id" jdbcType="VARCHAR"/>
            <result property="subItemId" column="sub_item_id" jdbcType="VARCHAR"/>
            <result property="num" column="num" jdbcType="INTEGER"/>
            <result property="gmtCreate" column="gmt_create" jdbcType="TIMESTAMP"/>
            <result property="gmtModified" column="gmt_modified" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="Base_Column_List">
        refund_purchase_order_sku_id,refund_id,shop_id,
        pur_order_id,pur_sku_order_id,order_id,
        sub_item_id,num,gmt_create,
        gmt_modified
    </sql>

    <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from refund_purchase_order_sku
        where  refund_purchase_order_sku_id = #{refundPurchaseOrderSkuId,jdbcType=BIGINT} 
    </select>

    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
        delete from refund_purchase_order_sku
        where  refund_purchase_order_sku_id = #{refundPurchaseOrderSkuId,jdbcType=BIGINT} 
    </delete>
    <insert id="insert" keyColumn="refund_purchase_order_sku_id" keyProperty="refundPurchaseOrderSkuId" parameterType="com.ms.dal.entity.RefundPurchaseOrderSku" useGeneratedKeys="true">
        insert into refund_purchase_order_sku
        ( refund_purchase_order_sku_id,refund_id,shop_id
        ,pur_order_id,pur_sku_order_id,order_id
        ,sub_item_id,num,gmt_create
        ,gmt_modified)
        values (#{refundPurchaseOrderSkuId,jdbcType=BIGINT},#{refundId,jdbcType=VARCHAR},#{shopId,jdbcType=BIGINT}
        ,#{purOrderId,jdbcType=VARCHAR},#{purSkuOrderId,jdbcType=VARCHAR},#{orderId,jdbcType=VARCHAR}
        ,#{subItemId,jdbcType=VARCHAR},#{num,jdbcType=INTEGER},#{gmtCreate,jdbcType=TIMESTAMP}
        ,#{gmtModified,jdbcType=TIMESTAMP})
    </insert>
    <update id="insertOrUpdate"  keyColumn="refund_purchase_order_sku_id" keyProperty="refundPurchaseOrderSkuId" parameterType="com.ms.dal.entity.RefundPurchaseOrderSku"
        useGeneratedKeys="true">
        insert into refund_purchase_order_sku
        <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="refundPurchaseOrderSkuId != null">refund_purchase_order_sku_id,</if>
                <if test="refundId != null">refund_id,</if>
                <if test="shopId != null">shop_id,</if>
                <if test="purOrderId != null">pur_order_id,</if>
                <if test="purSkuOrderId != null">pur_sku_order_id,</if>
                <if test="orderId != null">order_id,</if>
                <if test="subItemId != null">sub_item_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="refundPurchaseOrderSkuId != null">#{refundPurchaseOrderSkuId,jdbcType=BIGINT},</if>
                <if test="refundId != null">#{refundId,jdbcType=VARCHAR},</if>
                <if test="shopId != null">#{shopId,jdbcType=BIGINT},</if>
                <if test="purOrderId != null">#{purOrderId,jdbcType=VARCHAR},</if>
                <if test="purSkuOrderId != null">#{purSkuOrderId,jdbcType=VARCHAR},</if>
                <if test="orderId != null">#{orderId,jdbcType=VARCHAR},</if>
                <if test="subItemId != null">#{subItemId,jdbcType=VARCHAR},</if>
                <if test="num != null">#{num,jdbcType=INTEGER},</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="refundId != null">
                    refund_id = #{refundId,jdbcType=VARCHAR},
                </if>
                <if test="shopId != null">
                    shop_id = #{shopId,jdbcType=BIGINT},
                </if>
                <if test="purOrderId != null">
                    pur_order_id = #{purOrderId,jdbcType=VARCHAR},
                </if>
                <if test="purSkuOrderId != null">
                    pur_sku_order_id = #{purSkuOrderId,jdbcType=VARCHAR},
                </if>
                <if test="orderId != null">
                    order_id = #{orderId,jdbcType=VARCHAR},
                </if>
                <if test="subItemId != null">
                    sub_item_id = #{subItemId,jdbcType=VARCHAR},
                </if>
                <if test="num != null">
                    num = #{num,jdbcType=INTEGER},
                </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="refund_purchase_order_sku_id" keyProperty="refundPurchaseOrderSkuId" parameterType="com.ms.dal.entity.RefundPurchaseOrderSku" useGeneratedKeys="true">
        insert into refund_purchase_order_sku
        <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="refundPurchaseOrderSkuId != null">refund_purchase_order_sku_id,</if>
                <if test="refundId != null">refund_id,</if>
                <if test="shopId != null">shop_id,</if>
                <if test="purOrderId != null">pur_order_id,</if>
                <if test="purSkuOrderId != null">pur_sku_order_id,</if>
                <if test="orderId != null">order_id,</if>
                <if test="subItemId != null">sub_item_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="refundPurchaseOrderSkuId != null">#{refundPurchaseOrderSkuId,jdbcType=BIGINT},</if>
                <if test="refundId != null">#{refundId,jdbcType=VARCHAR},</if>
                <if test="shopId != null">#{shopId,jdbcType=BIGINT},</if>
                <if test="purOrderId != null">#{purOrderId,jdbcType=VARCHAR},</if>
                <if test="purSkuOrderId != null">#{purSkuOrderId,jdbcType=VARCHAR},</if>
                <if test="orderId != null">#{orderId,jdbcType=VARCHAR},</if>
                <if test="subItemId != null">#{subItemId,jdbcType=VARCHAR},</if>
                <if test="num != null">#{num,jdbcType=INTEGER},</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.RefundPurchaseOrderSku">
        update refund_purchase_order_sku
        <set>
                <if test="refundId != null">
                    refund_id = #{refundId,jdbcType=VARCHAR},
                </if>
                <if test="shopId != null">
                    shop_id = #{shopId,jdbcType=BIGINT},
                </if>
                <if test="purOrderId != null">
                    pur_order_id = #{purOrderId,jdbcType=VARCHAR},
                </if>
                <if test="purSkuOrderId != null">
                    pur_sku_order_id = #{purSkuOrderId,jdbcType=VARCHAR},
                </if>
                <if test="orderId != null">
                    order_id = #{orderId,jdbcType=VARCHAR},
                </if>
                <if test="subItemId != null">
                    sub_item_id = #{subItemId,jdbcType=VARCHAR},
                </if>
                <if test="num != null">
                    num = #{num,jdbcType=INTEGER},
                </if>
                <if test="gmtCreate != null">
                    gmt_create = #{gmtCreate,jdbcType=TIMESTAMP},
                </if>
                <if test="gmtModified != null">
                    gmt_modified = #{gmtModified,jdbcType=TIMESTAMP},
                </if>
        </set>
        where   refund_purchase_order_sku_id = #{refundPurchaseOrderSkuId,jdbcType=BIGINT} 
    </update>
    <update id="updateByPrimaryKey" parameterType="com.ms.dal.entity.RefundPurchaseOrderSku">
        update refund_purchase_order_sku
        set 
            refund_id =  #{refundId,jdbcType=VARCHAR},
            shop_id =  #{shopId,jdbcType=BIGINT},
            pur_order_id =  #{purOrderId,jdbcType=VARCHAR},
            pur_sku_order_id =  #{purSkuOrderId,jdbcType=VARCHAR},
            order_id =  #{orderId,jdbcType=VARCHAR},
            sub_item_id =  #{subItemId,jdbcType=VARCHAR},
            num =  #{num,jdbcType=INTEGER},
            gmt_create =  #{gmtCreate,jdbcType=TIMESTAMP},
            gmt_modified =  #{gmtModified,jdbcType=TIMESTAMP}
        where   refund_purchase_order_sku_id = #{refundPurchaseOrderSkuId,jdbcType=BIGINT} 
    </update>
    <insert id="insertBatch" keyColumn="refund_purchase_order_sku_id" keyProperty="refundPurchaseOrderSkuId" useGeneratedKeys="true">
        insert into refund_purchase_order_sku
        ( refund_purchase_order_sku_id,refund_id,shop_id
        ,pur_order_id,pur_sku_order_id,order_id
        ,sub_item_id,num,gmt_create
        ,gmt_modified)
        values
        <foreach item="item" collection="list" separator="," >
            (#{item.refundPurchaseOrderSkuId,jdbcType=BIGINT},#{item.refundId,jdbcType=VARCHAR},#{item.shopId,jdbcType=BIGINT}
            ,#{item.purOrderId,jdbcType=VARCHAR},#{item.purSkuOrderId,jdbcType=VARCHAR},#{item.orderId,jdbcType=VARCHAR}
            ,#{item.subItemId,jdbcType=VARCHAR},#{item.num,jdbcType=INTEGER},#{item.gmtCreate,jdbcType=TIMESTAMP}
            ,#{item.gmtModified,jdbcType=TIMESTAMP})
        </foreach>
    </insert>
</mapper>
