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

    <resultMap id="BaseResultMap" type="com.ms.dal.entity.PurchaseOrder">
            <id property="purchaseOrderId" column="purchase_order_id" jdbcType="BIGINT"/>
            <result property="shopId" column="shop_id" jdbcType="BIGINT"/>
            <result property="purOrderId" column="pur_order_id" jdbcType="VARCHAR"/>
            <result property="orderId" column="order_id" jdbcType="BIGINT"/>
            <result property="purchasePlatform" column="purchase_platform" jdbcType="VARCHAR"/>
            <result property="purchaseOrderSn" column="purchase_order_sn" jdbcType="VARCHAR"/>
            <result property="purchaseOrderBuyer" column="purchase_order_buyer" jdbcType="VARCHAR"/>
            <result property="purchaseOrderSeller" column="purchase_order_seller" jdbcType="VARCHAR"/>
            <result property="purchaseOrderPayment" column="purchase_order_payment" jdbcType="DECIMAL"/>
            <result property="purchaseOrderStatus" column="purchase_order_status" jdbcType="VARCHAR"/>
            <result property="purchaseOrderLogisticsName" column="purchase_order_logistics_name" jdbcType="VARCHAR"/>
            <result property="purchaseOrderWaybillCode" column="purchase_order_waybill_code" jdbcType="VARCHAR"/>
            <result property="purchaseOrderSendTime" column="purchase_order_send_time" jdbcType="TIMESTAMP"/>
            <result property="purchaseOrderFullname" column="purchase_order_fullname" jdbcType="VARCHAR"/>
            <result property="purchaseOrderMobile" column="purchase_order_mobile" jdbcType="VARCHAR"/>
            <result property="purchaseOrderFullAddress" column="purchase_order_full_address" jdbcType="VARCHAR"/>
            <result property="purchaseOrderStartTime" column="purchase_order_start_time" jdbcType="TIMESTAMP"/>
            <result property="logisticsIsAccept" column="logistics_is_accept" jdbcType="TINYINT"/>
            <result property="status" column="status" jdbcType="VARCHAR"/>
            <result property="gmtCreate" column="gmt_create" jdbcType="TIMESTAMP"/>
            <result property="gmtModified" column="gmt_modified" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="Base_Column_List">
        purchase_order_id,shop_id,pur_order_id,order_id,
        purchase_platform,purchase_order_sn,purchase_order_buyer,
        purchase_order_seller,purchase_order_payment,purchase_order_status,
        purchase_order_logistics_name,purchase_order_waybill_code,purchase_order_send_time,
        purchase_order_fullname,purchase_order_mobile,purchase_order_full_address,
        purchase_order_start_time,logistics_is_accept,status,
        gmt_create,gmt_modified
    </sql>

    <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from purchase_order
        where  purchase_order_id = #{purchaseOrderId,jdbcType=BIGINT} 
    </select>
    <select id="getByPurchaseOrderSn" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from purchase_order
        where purchase_order_sn = #{purchaseOrderSn,jdbcType=VARCHAR}
    </select>
    <select id="getByPurOrderId" resultType="com.ms.dal.entity.PurchaseOrder">
        select
        <include refid="Base_Column_List" />
        from purchase_order
        where pur_order_id = #{purOrderId,jdbcType=VARCHAR}
    </select>

    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
        delete from purchase_order
        where  purchase_order_id = #{purchaseOrderId,jdbcType=BIGINT} 
    </delete>
    <insert id="insert" keyColumn="purchase_order_id" keyProperty="purchaseOrderId" parameterType="com.ms.dal.entity.PurchaseOrder" useGeneratedKeys="true">
        insert into purchase_order
        ( purchase_order_id,shop_id,pur_order_id,order_id
        ,purchase_platform,purchase_order_sn,purchase_order_buyer
        ,purchase_order_seller,purchase_order_payment,purchase_order_status
        ,purchase_order_logistics_name,purchase_order_waybill_code,purchase_order_send_time
        ,purchase_order_fullname,purchase_order_mobile,purchase_order_full_address
        ,purchase_order_start_time,logistics_is_accept,status
        ,gmt_create,gmt_modified)
        values (#{purchaseOrderId,jdbcType=BIGINT},#{shopId,jdbcType=BIGINT},#{purOrderId,jdbcType=VARCHAR},#{orderId,jdbcType=BIGINT}
        ,#{purchasePlatform,jdbcType=VARCHAR},#{purchaseOrderSn,jdbcType=VARCHAR},#{purchaseOrderBuyer,jdbcType=VARCHAR}
        ,#{purchaseOrderSeller,jdbcType=VARCHAR},#{purchaseOrderPayment,jdbcType=DECIMAL},#{purchaseOrderStatus,jdbcType=VARCHAR}
        ,#{purchaseOrderLogisticsName,jdbcType=VARCHAR},#{purchaseOrderWaybillCode,jdbcType=VARCHAR},#{purchaseOrderSendTime,jdbcType=TIMESTAMP}
        ,#{purchaseOrderFullname,jdbcType=VARCHAR},#{purchaseOrderMobile,jdbcType=VARCHAR},#{purchaseOrderFullAddress,jdbcType=VARCHAR}
        ,#{purchaseOrderStartTime,jdbcType=TIMESTAMP},#{logisticsIsAccept,jdbcType=TINYINT},#{status,jdbcType=VARCHAR}
        ,#{gmtCreate,jdbcType=TIMESTAMP},#{gmtModified,jdbcType=TIMESTAMP})
    </insert>
    <update id="insertOrUpdate"  keyColumn="purchase_order_id" keyProperty="purchaseOrderId" parameterType="com.ms.dal.entity.PurchaseOrder"
        useGeneratedKeys="true">
        insert into purchase_order
        <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="purchaseOrderId != null">purchase_order_id,</if>
                <if test="shopId != null">shop_id,</if>
                <if test="purOrderId != null">pur_order_id,</if>
                <if test="orderId != null">order_id,</if>
                <if test="purchasePlatform != null">purchase_platform,</if>
                <if test="purchaseOrderSn != null">purchase_order_sn,</if>
                <if test="purchaseOrderBuyer != null">purchase_order_buyer,</if>
                <if test="purchaseOrderSeller != null">purchase_order_seller,</if>
                <if test="purchaseOrderPayment != null">purchase_order_payment,</if>
                <if test="purchaseOrderStatus != null">purchase_order_status,</if>
                <if test="purchaseOrderLogisticsName != null">purchase_order_logistics_name,</if>
                <if test="purchaseOrderWaybillCode != null">purchase_order_waybill_code,</if>
                <if test="purchaseOrderSendTime != null">purchase_order_send_time,</if>
                <if test="purchaseOrderFullname != null">purchase_order_fullname,</if>
                <if test="purchaseOrderMobile != null">purchase_order_mobile,</if>
                <if test="purchaseOrderFullAddress != null">purchase_order_full_address,</if>
                <if test="purchaseOrderStartTime != null">purchase_order_start_time,</if>
                <if test="logisticsIsAccept != null">logistics_is_accept,</if>
                <if test="status != null">status,</if>
                <if test="gmtCreate != null">gmt_create,</if>
                <if test="gmtModified != null">gmt_modified,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                <if test="purchaseOrderId != null">#{purchaseOrderId,jdbcType=BIGINT},</if>
                <if test="shopId != null">#{shopId,jdbcType=BIGINT},</if>
                <if test="purOrderId != null">#{purOrderId,jdbcType=VARCHAR},</if>
                <if test="orderId != null">#{orderId,jdbcType=BIGINT},</if>
                <if test="purchasePlatform != null">#{purchasePlatform,jdbcType=VARCHAR},</if>
                <if test="purchaseOrderSn != null">#{purchaseOrderSn,jdbcType=VARCHAR},</if>
                <if test="purchaseOrderBuyer != null">#{purchaseOrderBuyer,jdbcType=VARCHAR},</if>
                <if test="purchaseOrderSeller != null">#{purchaseOrderSeller,jdbcType=VARCHAR},</if>
                <if test="purchaseOrderPayment != null">#{purchaseOrderPayment,jdbcType=DECIMAL},</if>
                <if test="purchaseOrderStatus != null">#{purchaseOrderStatus,jdbcType=VARCHAR},</if>
                <if test="purchaseOrderLogisticsName != null">#{purchaseOrderLogisticsName,jdbcType=VARCHAR},</if>
                <if test="purchaseOrderWaybillCode != null">#{purchaseOrderWaybillCode,jdbcType=VARCHAR},</if>
                <if test="purchaseOrderSendTime != null">#{purchaseOrderSendTime,jdbcType=TIMESTAMP},</if>
                <if test="purchaseOrderFullname != null">#{purchaseOrderFullname,jdbcType=VARCHAR},</if>
                <if test="purchaseOrderMobile != null">#{purchaseOrderMobile,jdbcType=VARCHAR},</if>
                <if test="purchaseOrderFullAddress != null">#{purchaseOrderFullAddress,jdbcType=VARCHAR},</if>
                <if test="purchaseOrderStartTime != null">#{purchaseOrderStartTime,jdbcType=TIMESTAMP},</if>
                <if test="logisticsIsAccept != null">#{logisticsIsAccept,jdbcType=TINYINT},</if>
                <if test="status != null">#{status,jdbcType=VARCHAR},</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="orderId != null">
                    order_id = #{orderId,jdbcType=BIGINT},
                </if>
                <if test="purchasePlatform != null">
                    purchase_platform = #{purchasePlatform,jdbcType=VARCHAR},
                </if>
                <if test="purchaseOrderSn != null">
                    purchase_order_sn = #{purchaseOrderSn,jdbcType=VARCHAR},
                </if>
                <if test="purchaseOrderBuyer != null">
                    purchase_order_buyer = #{purchaseOrderBuyer,jdbcType=VARCHAR},
                </if>
                <if test="purchaseOrderSeller != null">
                    purchase_order_seller = #{purchaseOrderSeller,jdbcType=VARCHAR},
                </if>
                <if test="purchaseOrderPayment != null">
                    purchase_order_payment = #{purchaseOrderPayment,jdbcType=DECIMAL},
                </if>
                <if test="purchaseOrderStatus != null">
                    purchase_order_status = #{purchaseOrderStatus,jdbcType=VARCHAR},
                </if>
                <if test="purchaseOrderLogisticsName != null">
                    purchase_order_logistics_name = #{purchaseOrderLogisticsName,jdbcType=VARCHAR},
                </if>
                <if test="purchaseOrderWaybillCode != null">
                    purchase_order_waybill_code = #{purchaseOrderWaybillCode,jdbcType=VARCHAR},
                </if>
                <if test="purchaseOrderSendTime != null">
                    purchase_order_send_time = #{purchaseOrderSendTime,jdbcType=TIMESTAMP},
                </if>
                <if test="purchaseOrderFullname != null">
                    purchase_order_fullname = #{purchaseOrderFullname,jdbcType=VARCHAR},
                </if>
                <if test="purchaseOrderMobile != null">
                    purchase_order_mobile = #{purchaseOrderMobile,jdbcType=VARCHAR},
                </if>
                <if test="purchaseOrderFullAddress != null">
                    purchase_order_full_address = #{purchaseOrderFullAddress,jdbcType=VARCHAR},
                </if>
                <if test="purchaseOrderStartTime != null">
                    purchase_order_start_time = #{purchaseOrderStartTime,jdbcType=TIMESTAMP},
                </if>
                <if test="logisticsIsAccept != null">
                    logistics_is_accept = #{logisticsIsAccept,jdbcType=TINYINT},
                </if>
                <if test="status != null">
                    status = #{status,jdbcType=VARCHAR},
                </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="purchase_order_id" keyProperty="purchaseOrderId" parameterType="com.ms.dal.entity.PurchaseOrder" useGeneratedKeys="true">
        insert into purchase_order
        <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="purchaseOrderId != null">purchase_order_id,</if>
                <if test="shopId != null">shop_id,</if>
                <if test="purOrderId != null">pur_order_id,</if>
                <if test="orderId != null">order_id,</if>
                <if test="purchasePlatform != null">purchase_platform,</if>
                <if test="purchaseOrderSn != null">purchase_order_sn,</if>
                <if test="purchaseOrderBuyer != null">purchase_order_buyer,</if>
                <if test="purchaseOrderSeller != null">purchase_order_seller,</if>
                <if test="purchaseOrderPayment != null">purchase_order_payment,</if>
                <if test="purchaseOrderStatus != null">purchase_order_status,</if>
                <if test="purchaseOrderLogisticsName != null">purchase_order_logistics_name,</if>
                <if test="purchaseOrderWaybillCode != null">purchase_order_waybill_code,</if>
                <if test="purchaseOrderSendTime != null">purchase_order_send_time,</if>
                <if test="purchaseOrderFullname != null">purchase_order_fullname,</if>
                <if test="purchaseOrderMobile != null">purchase_order_mobile,</if>
                <if test="purchaseOrderFullAddress != null">purchase_order_full_address,</if>
                <if test="purchaseOrderStartTime != null">purchase_order_start_time,</if>
                <if test="logisticsIsAccept != null">logistics_is_accept,</if>
                <if test="status != null">status,</if>
                <if test="gmtCreate != null">gmt_create,</if>
                <if test="gmtModified != null">gmt_modified,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                <if test="purchaseOrderId != null">#{purchaseOrderId,jdbcType=BIGINT},</if>
                <if test="shopId != null">#{shopId,jdbcType=BIGINT},</if>
                <if test="purOrderId != null">#{purOrderId,jdbcType=VARCHAR},</if>
                <if test="orderId != null">#{orderId,jdbcType=BIGINT},</if>
                <if test="purchasePlatform != null">#{purchasePlatform,jdbcType=VARCHAR},</if>
                <if test="purchaseOrderSn != null">#{purchaseOrderSn,jdbcType=VARCHAR},</if>
                <if test="purchaseOrderBuyer != null">#{purchaseOrderBuyer,jdbcType=VARCHAR},</if>
                <if test="purchaseOrderSeller != null">#{purchaseOrderSeller,jdbcType=VARCHAR},</if>
                <if test="purchaseOrderPayment != null">#{purchaseOrderPayment,jdbcType=DECIMAL},</if>
                <if test="purchaseOrderStatus != null">#{purchaseOrderStatus,jdbcType=VARCHAR},</if>
                <if test="purchaseOrderLogisticsName != null">#{purchaseOrderLogisticsName,jdbcType=VARCHAR},</if>
                <if test="purchaseOrderWaybillCode != null">#{purchaseOrderWaybillCode,jdbcType=VARCHAR},</if>
                <if test="purchaseOrderSendTime != null">#{purchaseOrderSendTime,jdbcType=TIMESTAMP},</if>
                <if test="purchaseOrderFullname != null">#{purchaseOrderFullname,jdbcType=VARCHAR},</if>
                <if test="purchaseOrderMobile != null">#{purchaseOrderMobile,jdbcType=VARCHAR},</if>
                <if test="purchaseOrderFullAddress != null">#{purchaseOrderFullAddress,jdbcType=VARCHAR},</if>
                <if test="purchaseOrderStartTime != null">#{purchaseOrderStartTime,jdbcType=TIMESTAMP},</if>
                <if test="logisticsIsAccept != null">#{logisticsIsAccept,jdbcType=TINYINT},</if>
                <if test="status != null">#{status,jdbcType=VARCHAR},</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.PurchaseOrder">
        update purchase_order
        <set>
                <if test="shopId != null">
                    shop_id = #{shopId,jdbcType=BIGINT},
                </if>
                <if test="purOrderId != null">
                    pur_order_id = #{purOrderId,jdbcType=VARCHAR},
                </if>
                <if test="orderId != null">
                    order_id = #{orderId,jdbcType=BIGINT},
                </if>
                <if test="purchasePlatform != null">
                    purchase_platform = #{purchasePlatform,jdbcType=VARCHAR},
                </if>
                <if test="purchaseOrderSn != null">
                    purchase_order_sn = #{purchaseOrderSn,jdbcType=VARCHAR},
                </if>
                <if test="purchaseOrderBuyer != null">
                    purchase_order_buyer = #{purchaseOrderBuyer,jdbcType=VARCHAR},
                </if>
                <if test="purchaseOrderSeller != null">
                    purchase_order_seller = #{purchaseOrderSeller,jdbcType=VARCHAR},
                </if>
                <if test="purchaseOrderPayment != null">
                    purchase_order_payment = #{purchaseOrderPayment,jdbcType=DECIMAL},
                </if>
                <if test="purchaseOrderStatus != null">
                    purchase_order_status = #{purchaseOrderStatus,jdbcType=VARCHAR},
                </if>
                <if test="purchaseOrderLogisticsName != null">
                    purchase_order_logistics_name = #{purchaseOrderLogisticsName,jdbcType=VARCHAR},
                </if>
                <if test="purchaseOrderWaybillCode != null">
                    purchase_order_waybill_code = #{purchaseOrderWaybillCode,jdbcType=VARCHAR},
                </if>
                <if test="purchaseOrderSendTime != null">
                    purchase_order_send_time = #{purchaseOrderSendTime,jdbcType=TIMESTAMP},
                </if>
                <if test="purchaseOrderFullname != null">
                    purchase_order_fullname = #{purchaseOrderFullname,jdbcType=VARCHAR},
                </if>
                <if test="purchaseOrderMobile != null">
                    purchase_order_mobile = #{purchaseOrderMobile,jdbcType=VARCHAR},
                </if>
                <if test="purchaseOrderFullAddress != null">
                    purchase_order_full_address = #{purchaseOrderFullAddress,jdbcType=VARCHAR},
                </if>
                <if test="purchaseOrderStartTime != null">
                    purchase_order_start_time = #{purchaseOrderStartTime,jdbcType=TIMESTAMP},
                </if>
                <if test="logisticsIsAccept != null">
                    logistics_is_accept = #{logisticsIsAccept,jdbcType=TINYINT},
                </if>
                <if test="status != null">
                    status = #{status,jdbcType=VARCHAR},
                </if>
                <if test="gmtCreate != null">
                    gmt_create = #{gmtCreate,jdbcType=TIMESTAMP},
                </if>
                <if test="gmtModified != null">
                    gmt_modified = #{gmtModified,jdbcType=TIMESTAMP},
                </if>
        </set>
        where   purchase_order_id = #{purchaseOrderId,jdbcType=BIGINT} 
    </update>
    <update id="updateByPrimaryKey" parameterType="com.ms.dal.entity.PurchaseOrder">
        update purchase_order
        set
            shop_id = #{shopId,jdbcType=BIGINT},
            pur_order_id =  #{purOrderId,jdbcType=VARCHAR},
            order_id =  #{orderId,jdbcType=BIGINT},
            purchase_platform =  #{purchasePlatform,jdbcType=VARCHAR},
            purchase_order_sn =  #{purchaseOrderSn,jdbcType=VARCHAR},
            purchase_order_buyer =  #{purchaseOrderBuyer,jdbcType=VARCHAR},
            purchase_order_seller =  #{purchaseOrderSeller,jdbcType=VARCHAR},
            purchase_order_payment =  #{purchaseOrderPayment,jdbcType=DECIMAL},
            purchase_order_status =  #{purchaseOrderStatus,jdbcType=VARCHAR},
            purchase_order_logistics_name =  #{purchaseOrderLogisticsName,jdbcType=VARCHAR},
            purchase_order_waybill_code =  #{purchaseOrderWaybillCode,jdbcType=VARCHAR},
            purchase_order_send_time =  #{purchaseOrderSendTime,jdbcType=TIMESTAMP},
            purchase_order_fullname =  #{purchaseOrderFullname,jdbcType=VARCHAR},
            purchase_order_mobile =  #{purchaseOrderMobile,jdbcType=VARCHAR},
            purchase_order_full_address =  #{purchaseOrderFullAddress,jdbcType=VARCHAR},
            purchase_order_start_time =  #{purchaseOrderStartTime,jdbcType=TIMESTAMP},
            logistics_is_accept =  #{logisticsIsAccept,jdbcType=TINYINT},
            status =  #{status,jdbcType=VARCHAR},
            gmt_create =  #{gmtCreate,jdbcType=TIMESTAMP},
            gmt_modified =  #{gmtModified,jdbcType=TIMESTAMP}
        where   purchase_order_id = #{purchaseOrderId,jdbcType=BIGINT} 
    </update>
    <insert id="insertBatch" keyColumn="purchase_order_id" keyProperty="purchaseOrderId" useGeneratedKeys="true">
        insert into purchase_order
        (purchase_order_id,shop_id,order_id,purchase_platform,pur_order_id
        ,purchase_order_sn,purchase_order_buyer,purchase_order_seller
        ,purchase_order_payment,purchase_order_status,purchase_order_logistics_name
        ,purchase_order_waybill_code,purchase_order_send_time,purchase_order_fullname
        ,purchase_order_mobile,purchase_order_full_address,purchase_order_start_time
        ,logistics_is_accept,status,gmt_create
        ,gmt_modified)
        values
        <foreach item="item" collection="list" separator="," >
            (#{item.purchaseOrderId,jdbcType=BIGINT},#{item.shopId,jdbcType=BIGINT},#{item.orderId,jdbcType=BIGINT},#{item.purchasePlatform,jdbcType=VARCHAR},#{item.purOrderId,jdbcType=VARCHAR}
            ,#{item.purchaseOrderSn,jdbcType=VARCHAR},#{item.purchaseOrderBuyer,jdbcType=VARCHAR},#{item.purchaseOrderSeller,jdbcType=VARCHAR}
            ,#{item.purchaseOrderPayment,jdbcType=DECIMAL},#{item.purchaseOrderStatus,jdbcType=VARCHAR},#{item.purchaseOrderLogisticsName,jdbcType=VARCHAR}
            ,#{item.purchaseOrderWaybillCode,jdbcType=VARCHAR},#{item.purchaseOrderSendTime,jdbcType=TIMESTAMP},#{item.purchaseOrderFullname,jdbcType=VARCHAR}
            ,#{item.purchaseOrderMobile,jdbcType=VARCHAR},#{item.purchaseOrderFullAddress,jdbcType=VARCHAR},#{item.purchaseOrderStartTime,jdbcType=TIMESTAMP}
            ,#{item.logisticsIsAccept,jdbcType=TINYINT},#{item.status,jdbcType=VARCHAR},#{item.gmtCreate,jdbcType=TIMESTAMP}
            ,#{item.gmtModified,jdbcType=TIMESTAMP})
        </foreach>
    </insert>
</mapper>
