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



    <insert id="saveTmsLogisticsStatus" parameterType="com.dgtly.system.domain.TmsLogisticsStatus">
        insert into
        tms_logistics_status(
            create_by,create_time,update_by,update_time,is_delete,order_number,
            order_creation_time,delivery_number,tms_shipment_number,customer_code,
            status,driver_name,car_number,driver_phone,assign_time,get_goods_time,
            factory_time,arrival_goods_time,transfer_order
        )
        values
        <foreach collection="list" item="item" separator=",">
            (
            #{item.createBy},#{item.createTime},#{item.updateBy},#{item.updateTime},
            #{item.isDelete},#{item.orderNumber},#{item.orderCreationTime},
            #{item.deliveryNumber},#{item.tmsShipmentNumber},#{item.customerCode},
            #{item.status},#{item.driverName},#{item.carNumber},#{item.driverPhone},
            #{item.assignTime},#{item.getGoodsTime},#{item.factoryTime},
            #{item.arrivalGoodsTime},#{item.transferOrder}
            )
        </foreach>
    </insert>

    <update id="updateBatchTmsStatus" parameterType="java.util.List">
        <foreach item="item" index="index" collection="list" open="" separator=";" close="">
            update tms_logistics_status
            <set>
                create_by =#{item.createBy},
                create_time =#{item.createTime},
                update_by =#{item.updateBy},
                update_time =#{item.updateTime},
                is_delete =#{item.isDelete},
                order_number =#{item.orderNumber},
                order_creation_time =#{item.orderCreationTime},
                delivery_number =#{item.deliveryNumber},
                tms_shipment_number =#{item.tmsShipmentNumber},
                customer_code =#{item.customerCode},
                status =#{item.status},
                driver_name =#{item.driverName},
                car_number =#{item.carNumber},
                driver_phone =#{item.driverPhone},
                assign_time =#{item.assignTime},
                get_goods_time =#{item.getGoodsTime},
                factory_time =#{item.factoryTime},
                arrival_goods_time =#{item.arrivalGoodsTime},
                transfer_order =#{item.transferOrder}
            </set>
                where id=#{item.id}
        </foreach>
    </update>

    <insert id="saveDeliverOrderBaseList" parameterType="com.dgtly.system.domain.DeliverOrderBase">
        insert into
        deliver_order_base(
                create_by,create_time,update_by,update_time,
                is_delete,order_number,order_creation_time,delivery_number,
                shipment_number,belong_to,confirm_time,confirm_by,confirm_notice,
                push_dis_warehouse,evaluation_status,evaluation_time,evaluation_by,
                evaluation_service_attitude,evaluation_damage_condition,evaluation_arrive_time,
                evaluation_handling_conditions,evaluation
        )
        values
        <foreach collection="list" item="item" separator=",">
            (
            #{item.createBy},#{item.createTime},#{item.updateBy},
            #{item.updateTime},#{item.isDelete},#{item.OrderNumber},
            #{item.orderCreationTime},#{item.deliveryNumber},#{item.shipmentNumber},
            #{item.belongTo},#{item.confirmTime},#{item.confirmBy},
            #{item.confirmNotice},#{item.pushDisWarehouse},#{item.evaluationStatus},
            #{item.evaluationTime},#{item.evaluationBy},#{item.evaluationServiceAttitude},
            #{item.evaluationDamageCondition},#{item.evaluationArriveTime},#{item.evaluationHandlingConditions},
            #{item.evaluation}
            )
        </foreach>

    </insert>


    <delete id="delete">
      delete from tms_logistics_status where delivery_number in
      <foreach collection="list" item="item" open="(" close=")" separator="," index="">
        #{item}
    </foreach>


  </delete>


    <select id="selectByDeliveryNumber" resultType="java.util.Map" parameterType="java.util.List">
        select
            IFNULL(DOC_NUMBER,'') as docNumber,
            IFNULL(CUSTOMER_CODE,'') as customerCode,
            IFNULL(CREATE_DATE_DELIVER,'') as createDate,
            IFNULL(DELIVER_NUMBER,'') as deliverNum
        from meta_hana_deliver_order WHERE DELIVER_NUMBER IN
        <foreach collection="list" item="valueList" open="(" close=")" separator=",">
            #{valueList}
        </foreach>
        GROUP BY DELIVER_NUMBER
    </select>
    
    <select id="selectByDelivery" resultType="com.dgtly.system.domain.TmsLogisticsStatus">
        SELECT
            id,create_by as createBy,create_time as createTime,update_by as updateBy,update_time as updateTime,is_delete as isDelete,
            order_number as orderNumber,
            order_creation_time as orderCreationTime,
            delivery_number as deliveryNumber,
            tms_shipment_number as tmsShipmentNumber,
            customer_code as customerCode,
            STATUS as status,
            driver_name as driverName,
            car_number as carNumber,
            driver_phone as driverPhone,
            assign_time as assignTime,
            get_goods_time as getGoodsTime,
            factory_time as factoryTime,
            arrival_goods_time as arrivalGoodsTime,
            transfer_order as transferOrder
        FROM
            tms_logistics_status
    where 1=1
      and is_delete=0 and  create_time between now() - interval 100 day and now()
    </select>

    <select id="selectDeliverySelf" resultType="java.util.Map" parameterType="String">
        select  tms.customer_code customerCode,GROUP_CONCAT(distinct tms.delivery_number SEPARATOR ',') deliveryNumber
        from tms_logistics_status tms LEFT JOIN meta_hana_deliver_order d on d.DELIVER_NUMBER = tms.delivery_number
        where 1=1
          and tms.is_delete=0
          and ( d.REVIEW_STATUS='未复核' or (tms.delivery_number in(select distinct deliver_number from meta_hana_self_deliver_order)))
          and tms.get_goods_time IS NULL
          AND tms.self_pick_time BETWEEN DATE_SUB( NOW(), INTERVAL 46 DAY ) AND DATE_SUB(NOW(), INTERVAL 1 DAY )
        group by tms.customer_code
    </select>


</mapper>