<?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.ProductionTaskDetailMapper">
    <select id="getPage" resultType="com.fjhx.mes.entity.production.vo.ProductionTaskDetailVo">
        select
            ptd.id,
            ptd.product_id,
            ptd.production_task_id,
            ptd.product_sn,
            ptd.production_processes_id,
            ptd.finish_time,
            ptd.finish_status,
            ptd.person_liable_id,
            ptd.create_user,
            ptd.create_time,
            ptd.update_user,
            ptd.update_time,
            ptd.next_production_processes_id,
            ptd.circulation_user_id,
            ptd.circulation_status
        from production_task_detail ptd
            ${ew.customSqlSegment}
    </select>
    <select id="getWorkOrderByProductionTask" resultType="com.fjhx.mes.entity.work.vo.WorkOrderVo">
        SELECT
            wo.*,
            pt.id productionTaskId
        FROM
            work_order wo
                LEFT JOIN production_plan pp ON pp.work_order_id = wo.id
                LEFT JOIN production_task pt ON pt.production_plan_id = pp.id
            ${ew.customSqlSegment}
    </select>
    <select id="snInfo" resultType="com.fjhx.mes.entity.production.vo.ProductionTaskDetailVo">
        SELECT
            ptd.product_id,
            ptd.product_sn,
            sc.`code`,
            wo.id workOrderId
        FROM
            production_task_detail ptd
                JOIN production_task pt ON ptd.production_task_id = pt.id
                JOIN production_plan pp ON pt.production_plan_id = pp.id
                JOIN work_order wo ON pp.work_order_id = wo.id
                JOIN bytesailing_jxst.sales_contract sc ON wo.source_id = sc.id
        WHERE
            ptd.product_sn = #{sn}
    </select>

</mapper>
