<?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="vip.xiaonuo.biz.modular.bizorder.mapper.BizOrderMapper">

    <select id="getPage" resultType="vip.xiaonuo.biz.modular.bizorder.entity.BizOrder">
        select
            bo.id,
            bo.order_number,
            bo.order_name,
            bo.customer_id,
            bc.name customerName,
            bc.contact customerContactName,
            bc.phone customerPhone,
            bc.address customerAddress,
            bo.good_id,
            bg.`GOODS_NAME` goodsName,
            bg.GOODS_MODEL goodsModel,
            bo.order_type,
            bo.order_source,
            bo.order_status,
            bo.order_weight/1000 order_weight,
            bo.net_weight/1000 net_weight,
            bgc.CONF_START_TIME,
            bgc.CONF_END_TIME,
            bo.sale_order_info,
            bo.delivery_time_id,
            bo.order_sign,
            bo.order_reason,
            bo.end_reason
        from biz_order bo
        left join biz_customer bc on bo.customer_id = bc.id
        left join biz_goods bg on bg.id = bo.good_id
        left join biz_goods_conf bgc on bgc.id = bo.delivery_time_id
        ${ew.customSqlSegment}
    </select>

    <select id="getOrderTotal" resultType="vip.xiaonuo.biz.modular.bizorder.entity.BizOrder">
        select
            a.*
        from(
            select
                bo.id,
                bo.order_number,
                bo.order_name,
                bc.name customerName,
                bo.order_weight/1000 order_weight,
                bo.net_weight/1000 net_weight,
                IFNULL(br.actualWeight/1000,0) actualWeight,
                case
                    when IFNULL(br.actualWeight,0)>bo.net_weight then '1'
                    else '0'
                end as 	orderFlag
            from biz_order bo
            left join biz_customer bc on bo.customer_id = bc.id
            left join (select order_id,IFNULL(sum(net_weight),0) actualWeight from biz_record  where delete_flag = 'NOT_DELETE' group by order_id) br
            on br.order_id = bo.id
            ${ew.customSqlSegment}
        ) a
        order by a.orderFlag desc
    </select>
</mapper>
