<?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.ProduceOrderMapper">
	<select id="getPage" resultType="com.fjhx.mes.entity.production.vo.ProductionOrderVo">
		select po.id,
               po.contract_id,
               po.code,
               po.produce_time,
               po.delivery_period,
               po.produce_status,
               po.create_user,
               po.create_time,
               po.update_user,
               po.update_time,
               po.company_id,
               c.prod_tag,
               c.prod_remark,
               po.finish_time,
               (if(IFNULL(po.finish_time, NOW()) > po.delivery_period, 1, 0)) AS isOverdue,
               po.confirm_status,
               c.contract_type,
               c.of_company_id                                                as contractCompanyId
        from production_order po
                 LEFT JOIN contract c ON po.contract_id = c.id
            ${ew.customSqlSegment}
    </select>
	<select id="getSchedulingList" resultType="com.fjhx.mes.entity.production.vo.ProductionOrderVo">
        SELECT po.id,
               po.`code`,
               GROUP_CONCAT(pi.`name` SEPARATOR '，')                          AS productName,
               po.create_time,
               po.produce_time,
               po.delivery_period,
               po.company_id,
               (if(IFNULL(po.finish_time, NOW()) > po.delivery_period, 1, 0)) AS isOverdue
        FROM production_order po
                 LEFT JOIN production_order_detail pod ON pod.produce_order_id = po.id
                 LEFT JOIN product_info pi ON pod.product_id = pi.id
            ${ew.customSqlSegment}
    </select>

</mapper>
