<?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.order.mapper.EvaluateMapper">
    
    <resultMap type="com.dgtly.order.domain.EvaluateDto" id="DeliverOrderBaseResult">
        <result property="id"    column="id"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="isDelete"    column="is_delete"    />
        <result property="orderNumber"    column="order_number"    />
        <result property="orderCreationTime"    column="order_creation_time"    />
        <result property="deliveryNumber"    column="delivery_number"    />
        <result property="shipmentNumber"    column="shipment_number"    />
        <result property="belongTo"    column="belong_to"    />
        <result property="confirmTime"    column="confirm_time"    />
        <result property="confirmBy"    column="confirm_by"    />
        <result property="confirmNotice"    column="confirm_notice"    />
        <result property="pushDisWarehouse"    column="push_dis_warehouse"    />
        <result property="evaluationStatus"    column="evaluation_status"    />
        <result property="evaluationServiceAttitude"    column="evaluation_service_attitude"    />
        <result property="evaluationDamageCondition"    column="evaluation_damage_condition"    />
        <result property="evaluationArriveTime"    column="evaluation_arrive_time"    />
        <result property="evaluationHandlingConditions"    column="evaluation_handling_conditions"    />
        <result property="evaluation"    column="evaluation"    />
        <result property="customersName"    column="chains_name"    />
    </resultMap>

    <sql id="selectDeliverOrderBaseVo">
        select dob.id, dob.order_number, dob.order_creation_time, dob.delivery_number,
        dob.shipment_number, dob.belong_to, dob.confirm_time, dob.confirm_by, dob.evaluation_status,
        dob.evaluation_service_attitude, dob.evaluation_damage_condition, dob.evaluation_arrive_time,
        dob.evaluation_handling_conditions, dob.evaluation,
		(select cu.chains_name from customers cu where cu.chains_code = dob.belong_to limit 1) as chains_name
        from deliver_order_base dob
    </sql>

    <select id="selectEvaluateDtoList" parameterType="com.dgtly.order.domain.EvaluateDto" resultMap="DeliverOrderBaseResult">
        <include refid="selectDeliverOrderBaseVo"/>
        <where>
            <if test="isDelete != null  and isDelete != ''"> and dob.is_delete = #{isDelete}</if>
            <if test="evaluationStatus != null  and evaluationStatus != ''"> and dob.evaluation_status = #{evaluationStatus}</if>
            <if test="orderNumber != null  and orderNumber != ''"> and dob.order_number like concat('%', #{orderNumber}, '%')</if>
            <if test="deliveryNumber != null  and deliveryNumber != ''"> and dob.delivery_number like concat('%', #{deliveryNumber}, '%')</if>
            <if test="shipmentNumber != null  and shipmentNumber != ''"> and dob.shipment_number like concat('%', #{shipmentNumber}, '%')</if>
            <if test="belongTo != null  and belongTo != ''"> and dob.belong_to like concat('%', #{belongTo}, '%')</if>
        </where>
        GROUP BY dob.shipment_number ORDER BY dob.id desc

    </select>
    
    <select id="selectEvaluateDtoById" parameterType="Long" resultMap="DeliverOrderBaseResult">
        <include refid="selectDeliverOrderBaseVo"/>
        where dob.is_delete = '0'
        and dob.evaluation_status = 'y'
        and dob.id = #{id}
        limit 1
    </select>
</mapper>