<?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.fjhx.mes.mapper.production.ProduceOrderDetailMapper">
	<select id="getPage" resultType="com.fjhx.mes.entity.production.vo.ProductionOrderDetailVo">
		SELECT pod.id,
               pod.produce_order_id,
               pod.contract_id,
               pod.contract_detail_id,
               pod.product_id,
               pod.quantity,
               pod.finish_quantity,
               pod.produce_status,
               pod.finish_time,
               pod.tenant_id,
               pod.create_user,
               pod.create_time,
               pod.update_user,
               pod.update_time,
               pod.del_flag,
               po.code                                                        AS orderCode,
               po.create_time                                                 AS orderCreateTime,
               po.produce_time,
               po.delivery_period,
               po.company_id,
               (if(IFNULL(po.finish_time, NOW()) > po.delivery_period, 1, 0)) AS isOverdue,
               pod.remark,
               c.prod_tag,
               c.prod_remark,
               c.create_user                                                  as saleUserId,
               c.contract_type,
               c.of_company_id                                                as contractCompanyId
        FROM production_order_detail pod
                 LEFT JOIN production_order po ON pod.produce_order_id = po.id
                 LEFT JOIN contract c ON pod.contract_id = c.id
            ${ew.customSqlSegment}
    </select>
</mapper>
