<?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.wms.mapper.stock.StockWaitDetailsMapper">
    <select id="getPage" resultType="com.fjhx.wms.entity.stock.vo.StockWaitDetailsVo">
        SELECT
            swd.id,
            sw.business_code,
            sw.business_id,
            sw.business_type,
            swd.`status`,
            swd.stock_wait_id,
            swd.product_id,
            swd.quantity,
            swd.receipt_quantity,
            swd.create_user,
            swd.create_time,
            swd.update_user,
            swd.update_time,
            swd.victoriatourist_json,
            swd.purchase_detail_id,
            if(sw.business_type =2,(SELECT ptd.product_sn from bytesailing_mes.production_task_detail ptd where ptd.id=sw.business_id),'') as productSn,
            IF( sw.business_type = 2,( SELECT sc.customer_id FROM bytesailing_jxst.sales_contract sc
                LEFT JOIN bytesailing_mes.work_order wo ON wo.source_id = sc.id AND wo.del_flag = 0
                LEFT JOIN bytesailing_mes.production_plan pp ON pp.work_order_id = wo.id AND pp.del_flag = 0
                LEFT JOIN bytesailing_mes.production_task pt ON pt.production_plan_id = pp.id AND pt.del_flag = 0
                LEFT JOIN bytesailing_mes.production_task_detail ptd ON ptd.production_task_id = pt.id AND ptd.del_flag = 0
            WHERE
                sc.del_flag = 0 and ptd.id = sw.business_id ), '' ) AS customerId
        FROM
            stock_wait_details swd
                JOIN stock_wait sw ON swd.stock_wait_id = sw.id
            ${ew.customSqlSegment}
    </select>
    <select id="getList" resultType="com.fjhx.wms.entity.stock.vo.StockWaitDetailsVo">
        SELECT
            swd.*
        FROM
            stock_wait_details swd
                LEFT JOIN stock_wait sw ON swd.stock_wait_id = sw.id
            ${ew.customSqlSegment}
    </select>

</mapper>
