<?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.dgtly.system.mapper.DeliverQuantityConfirmMapper">
    <resultMap type="com.dgtly.system.domain.DeliverQuantityConfirm" id="DeliverQuantityConfirmResult">
        <result property="orderNumber"    column="order_number"    />
        <result property="orderItem"    column="order_item"    />
        <result property="orderCreationTime"    column="order_creation_time"    />
        <result property="belongTo"    column="belong_to"    />
        <result property="deliveryNumber"    column="delivery_number"    />
        <result property="deliverItem"    column="deliver_item"    />
        <result property="shipmentNumber"    column="shipment_number"    />
        <result property="shipToAddress"    column="ship_to_address"    />
        <result property="materialCode"    column="material_code"    />
        <result property="materialName"    column="material_name"    />
        <result property="sizeDim"    column="size_dim"    />
        <result property="deliverQty"    column="deliver_qty"    />
        <result property="deliverWt"    column="deliver_wt"    />
        <result property="confirmQuantity"    column="confirm_quantity"    />
    </resultMap>

    <sql id="selectDeliverQuantityConfirmVo">
        select id, create_by, create_time, update_by, update_time, is_delete, order_number, order_item, order_creation_time, belong_to, delivery_number, deliver_item,concat(delivery_number,deliver_item)as code, shipment_number, ship_to_address, material_code, material_name, size_dim, deliver_qty, deliver_wt, confirm_quantity from deliver_quantity_confirm
    </sql>

    <select id="selectDeliverQuantityConfirmList" parameterType="DeliverQuantityConfirm" resultMap="DeliverQuantityConfirmResult">
        <include refid="selectDeliverQuantityConfirmVo"/>
        <where>
            1=1
            <if test="isDelete != null  and isDelete != ''"> and is_delete = #{isDelete}</if>
            <if test="orderNumber != null  and orderNumber != ''"> and order_number = #{orderNumber}</if>
            <if test="orderItem != null  and orderItem != ''"> and order_item = #{orderItem}</if>
            <if test="orderCreationTime != null  and orderCreationTime != ''"> and order_creation_time = #{orderCreationTime}</if>
            <if test="belongTo != null  and belongTo != ''"> and belong_to = #{belongTo}</if>
            <if test="deliveryNumber != null  and deliveryNumber != ''"> and delivery_number = #{deliveryNumber}</if>
            <if test="deliverItem != null  and deliverItem != ''"> and deliver_item = #{deliverItem}</if>
            <if test="shipmentNumber != null  and shipmentNumber != ''"> and shipment_number = #{shipmentNumber}</if>
            <if test="shipToAddress != null  and shipToAddress != ''"> and ship_to_address = #{shipToAddress}</if>
            <if test="materialCode != null  and materialCode != ''"> and material_code = #{materialCode}</if>
            <if test="materialName != null  and materialName != ''"> and material_name like concat('%', #{materialName}, '%')</if>
            <if test="sizeDim != null  and sizeDim != ''"> and size_dim = #{sizeDim}</if>
            <if test="deliverQty != null "> and deliver_qty = #{deliverQty}</if>
            <if test="deliverWt != null "> and deliver_wt = #{deliverWt}</if>
            <if test="confirmQuantity != null "> and confirm_quantity = #{confirmQuantity}</if>
            and  create_time between now() - interval 100 day and now()
        </where>
    </select>

    <select id="selectDeliverQuantityConfirmById" parameterType="Long" resultMap="DeliverQuantityConfirmResult">
        <include refid="selectDeliverQuantityConfirmVo"/>
        where id = #{id}
    </select>

    <insert id="insertDeliverQuantityConfirm" parameterType="DeliverQuantityConfirm" useGeneratedKeys="true" keyProperty="id">
        insert into deliver_quantity_confirm
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="createBy != null  and createBy != ''">create_by,</if>
            <if test="createTime != null ">create_time,</if>
            <if test="updateBy != null  and updateBy != ''">update_by,</if>
            <if test="updateTime != null ">update_time,</if>
            <if test="isDelete != null  and isDelete != ''">is_delete,</if>
            <if test="orderNumber != null  and orderNumber != ''">order_number,</if>
            <if test="orderItem != null  and orderItem != ''">order_item,</if>
            <if test="orderCreationTime != null  and orderCreationTime != ''">order_creation_time,</if>
            <if test="belongTo != null  and belongTo != ''">belong_to,</if>
            <if test="deliveryNumber != null  and deliveryNumber != ''">delivery_number,</if>
            <if test="deliverItem != null  and deliverItem != ''">deliver_item,</if>
            <if test="shipmentNumber != null  and shipmentNumber != ''">shipment_number,</if>
            <if test="shipToAddress != null  and shipToAddress != ''">ship_to_address,</if>
            <if test="materialCode != null  and materialCode != ''">material_code,</if>
            <if test="materialName != null  and materialName != ''">material_name,</if>
            <if test="sizeDim != null  and sizeDim != ''">size_dim,</if>
            <if test="deliverQty != null ">deliver_qty,</if>
            <if test="deliverWt != null ">deliver_wt,</if>
            <if test="confirmQuantity != null ">confirm_quantity,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="createBy != null  and createBy != ''">#{createBy},</if>
            <if test="createTime != null ">#{createTime},</if>
            <if test="updateBy != null  and updateBy != ''">#{updateBy},</if>
            <if test="updateTime != null ">#{updateTime},</if>
            <if test="isDelete != null  and isDelete != ''">#{isDelete},</if>
            <if test="orderNumber != null  and orderNumber != ''">#{orderNumber},</if>
            <if test="orderItem != null  and orderItem != ''">#{orderItem},</if>
            <if test="orderCreationTime != null  and orderCreationTime != ''">#{orderCreationTime},</if>
            <if test="belongTo != null  and belongTo != ''">#{belongTo},</if>
            <if test="deliveryNumber != null  and deliveryNumber != ''">#{deliveryNumber},</if>
            <if test="deliverItem != null  and deliverItem != ''">#{deliverItem},</if>
            <if test="shipmentNumber != null  and shipmentNumber != ''">#{shipmentNumber},</if>
            <if test="shipToAddress != null  and shipToAddress != ''">#{shipToAddress},</if>
            <if test="materialCode != null  and materialCode != ''">#{materialCode},</if>
            <if test="materialName != null  and materialName != ''">#{materialName},</if>
            <if test="sizeDim != null  and sizeDim != ''">#{sizeDim},</if>
            <if test="deliverQty != null ">#{deliverQty},</if>
            <if test="deliverWt != null ">#{deliverWt},</if>
            <if test="confirmQuantity != null ">#{confirmQuantity},</if>
        </trim>
    </insert>

    <insert id="saveDeliverNumber" parameterType="com.dgtly.system.domain.DeliverQuantityConfirm">
        insert into
        deliver_quantity_confirm(
        create_by,create_time,update_by,update_time,is_delete,order_number, order_item, order_creation_time, belong_to, delivery_number, deliver_item, shipment_number, ship_to_address, material_code, material_name, size_dim, deliver_qty, deliver_wt, confirm_quantity
        )
        values
        <foreach collection="list" item="item" separator=",">
            (
            #{item.createBy},#{item.createTime},#{item.updateBy},#{item.updateTime},
            #{item.isDelete},#{item.orderNumber},#{item.orderItem},
            #{item.orderCreationTime},#{item.belongTo},#{item.deliveryNumber},
            #{item.deliverItem},#{item.shipmentNumber},#{item.shipToAddress},#{item.materialCode},
            #{item.materialName},#{item.sizeDim},#{item.deliverQty},
            #{item.deliverWt},#{item.confirmQuantity}
            )
        </foreach>
    </insert>


</mapper>
