CASE WHEN WIP.DISPATCH_SEQ = 1 OR V1.DISPATCH_STATUS = 'COMPLETE' THEN N'是' ELSE N'否' END IS_COMPLETED,
CASE WHEN SD.DISPATCH_STATUS = 'COMPLETE' THEN SD.DISPATCH_QTY ELSE 0 END COMPLETED_QTY, SD.PLANNED_START_DATE, SD.PLANNED_COMP_DATE, SD.WORK_CENTER, SD.IS_DISPATCH, SD.EMPLOYEE_DESCRIPTION,
CASE WHEN WIP.DISPATCH_STATUS = 'NEW' THEN N'新建' WHEN WIP.DISPATCH_STATUS = 'CANCEL' THEN N'取消'
WHEN WIP.DISPATCH_STATUS = 'PAUSE' THEN N'暂停' WHEN WIP.DISPATCH_STATUS = 'RELEASE' THEN N'发布'
CASE WHEN IM.LOT_SIZE = 1 THEN N'是' ELSE N'否' END IS_MAJOR, CASE WHEN SD.TURN_OPERATION = 'true' THEN N'是' ELSE N'否' END TURN_OPERATION, SD.BLANKING_SIZE,
INNER JOIN SHOP_ORDER SO ON SO.SITE = SD.SITE AND SO.SHOP_ORDER = SD.SHOP_ORDER
CASE WHEN SD.DISPATCH_STATUS = 'COMPLETE' THEN SD.DISPATCH_QTY ELSE 0 END COMPLETED_QTY, SD.PLANNED_START_DATE, SD.PLANNED_COMP_DATE, SD.WORK_CENTER, SD.IS_DISPATCH, SD.EMPLOYEE_DESCRIPTION,
LEFT JOIN CUSTOM_FIELDS C1 ON C1.HANDLE = SO.HANDLE AND C1."ATTRIBUTE" = 'WORK_ORDER'
LEFT JOIN CUSTOM_FIELDS C2 ON C2.HANDLE = SO.HANDLE AND C2."ATTRIBUTE" = 'ITEM_NUMBER'
CASE WHEN IM.LOT_SIZE = 1 THEN N'是' ELSE N'否' END IS_MAJOR, CASE WHEN SD.TURN_OPERATION = 'true' THEN N'是' ELSE N'否' END TURN_OPERATION, SD.BLANKING_SIZE,
INNER JOIN ITEM IM ON IM.HANDLE = SO.ITEM_BO
WR.WORK_CENTER RESOURCE_WORK_CENTER
LEFT JOIN ITEM_T IT ON IT.ITEM_BO = IM.HANDLE AND IT.LOCALE = 'zh'
FROM Z_SFC_DISPATCH SD
INNER JOIN OPERATION O ON O.SITE = SD.SITE AND O.OPERATION = SD.OPERATION AND O.CURRENT_REVISION = 'true'
LEFT JOIN RESRCE RS ON SD.SITE = RS.SITE AND SD.RESRCE = RS.RESRCE
LEFT JOIN OPERATION_T OT ON OT.OPERATION_BO = O.HANDLE AND OT.LOCALE = 'zh'
INNER JOIN SHOP_ORDER SO ON SO.SITE = SD.SITE AND SO.SHOP_ORDER = SD.SHOP_ORDER
INNER JOIN BOM_COMPONENT BC ON BC.BOM_BO = SO.BOM_BO
LEFT JOIN CUSTOM_FIELDS C1 ON C1.HANDLE = SO.HANDLE AND C1."ATTRIBUTE" = 'WORK_ORDER'
INNER JOIN ITEM CP ON CP.HANDLE = BC.COMPONENT_GBO
LEFT JOIN CUSTOM_FIELDS C2 ON C2.HANDLE = SO.HANDLE AND C2."ATTRIBUTE" = 'ITEM_NUMBER'
LEFT JOIN ITEM_T CPT ON CPT.ITEM_BO = CP.HANDLE AND CPT.LOCALE = 'zh'
INNER JOIN ITEM IM ON IM.HANDLE = SO.ITEM_BO
LEFT JOIN WORK_CENTER_MEMBER WCM ON WCM.WORK_CENTER_OR_RESOURCE_GBO = 'ResourceBO:' || SD.SITE || ',' || SD.RESRCE
LEFT JOIN ITEM_T IT ON IT.ITEM_BO = IM.HANDLE AND IT.LOCALE = 'zh'
LEFT JOIN WORK_CENTER WR ON WR.HANDLE = WCM.WORK_CENTER_BO
INNER JOIN OPERATION O ON O.SITE = SD.SITE AND O.OPERATION = SD.OPERATION AND O.CURRENT_REVISION = 'true'
WHERE SD.SITE = #{site}
LEFT JOIN OPERATION_T OT ON OT.OPERATION_BO = O.HANDLE AND OT.LOCALE = 'zh'
<iftest="workCenter != null and workCenter != ''">
INNER JOIN BOM_COMPONENT BC ON BC.BOM_BO = SO.BOM_BO
AND SD.OPERATION LIKE #{workCenter}||'%'
INNER JOIN ITEM CP ON CP.HANDLE = BC.COMPONENT_GBO
</if>
LEFT JOIN ITEM_T CPT ON CPT.ITEM_BO = CP.HANDLE AND CPT.LOCALE = 'zh'
<iftest="dispatchStatus != null and dispatchStatus != ''">
LEFT JOIN WORK_CENTER_MEMBER WCM ON WCM.WORK_CENTER_OR_RESOURCE_GBO = 'ResourceBO:' || SD.SITE || ',' || SD.RESRCE
AND SD.DISPATCH_STATUS = #{dispatchStatus}
LEFT JOIN WORK_CENTER WR ON WR.HANDLE = WCM.WORK_CENTER_BO
</if>
WHERE SD.SITE = #{site}
<iftest="item != null and item != ''">
<iftest="workCenter != null and workCenter != ''">
AND IM.ITEM = #{item}
AND SD.OPERATION LIKE #{workCenter}||'%'
</if>
</if>
<iftest="workOrder != null and workOrder != ''">
<iftest="dispatchStatus != null and dispatchStatus != ''">
AND C1.VALUE LIKE '%' ||#{workOrder}|| '%'
AND SD.DISPATCH_STATUS = #{dispatchStatus}
</if>
</if>
<iftest="itemNumber != null and itemNumber != ''">
<iftest="item != null and item != ''">
AND C2.VALUE LIKE '%' ||#{itemNumber}|| '%'
AND IM.ITEM = #{item}
</if>
</if>
<iftest="shopOrder != null and shopOrder != ''">
<iftest="workOrder != null and workOrder != ''">
AND SD.SHOP_ORDER = #{shopOrder}
AND C1.VALUE LIKE '%' ||#{workOrder}|| '%'
</if>
</if>
<iftest="resourceType != null and resourceType != ''">
<iftest="itemNumber != null and itemNumber != ''">
AND SD.RESOURCE_TYPE = #{resourceType}
AND C2.VALUE LIKE '%' ||#{itemNumber}|| '%'
</if>
</if>
<iftest="resrce != null and resrce != ''">
<iftest="shopOrder != null and shopOrder != ''">
AND SD.RESRCE = #{resrce}
AND SD.SHOP_ORDER = #{shopOrder}
</if>
</if>
<iftest="operation != null and operation != ''">
<iftest="resourceType != null and resourceType != ''">
AND SD.OPERATION = #{operation}
AND SD.RESOURCE_TYPE = #{resourceType}
</if>
</if>
<iftest="operationDescription != null and operationDescription != ''">
<iftest="resrce != null and resrce != ''">
AND OT.DESCRIPTION = #{operationDescription}
AND SD.RESRCE = #{resrce}
</if>
</if>
<iftest="sfc != null and sfc != ''">
<iftest="operation != null and operation != ''">
AND SD.SFC = #{sfc}
AND SD.OPERATION = #{operation}
</if>
</if>
<iftest="turnOperation != null and turnOperation != ''">
<iftest="operationDescription != null and operationDescription != ''">
AND SD.TURN_OPERATION = #{turnOperation}
AND OT.DESCRIPTION = #{operationDescription}
</if>
</if>
<iftest="component != null and component != ''">
<iftest="sfc != null and sfc != ''">
AND CP.ITEM = #{component}
AND SD.SFC = #{sfc}
</if>
</if>
<iftest="componentDescription != null and componentDescription != ''">
<iftest="turnOperation != null and turnOperation != ''">
AND CPT.DESCRIPTION LIKE '%' || #{componentDescription} || '%'
AND SD.TURN_OPERATION = #{turnOperation}
</if>
</if>
<iftest="isDispatch != null and isDispatch != ''">
<iftest="component != null and component != ''">
AND SD.IS_DISPATCH = #{isDispatch}
AND CP.ITEM = #{component}
</if>
</if>
<iftest="blankingSize != null and blankingSize != ''">
<iftest="componentDescription != null and componentDescription != ''">
AND SD.BLANKING_SIZE LIKE '%'||#{blankingSize}||'%'
AND CPT.DESCRIPTION LIKE '%' || #{componentDescription} || '%'
</if>
</if>
<iftest="startFromDate != null">
<iftest="isDispatch != null and isDispatch != ''">
AND SO.PLANNED_START_DATE >= #{startFromDate}
AND SD.IS_DISPATCH = #{isDispatch}
</if>
</if>
<iftest="startToDate != null">
<iftest="blankingSize != null and blankingSize != ''">
AND SO.PLANNED_START_DATE <= #{startToDate}
AND SD.BLANKING_SIZE LIKE '%'||#{blankingSize}||'%'
</if>
</if>
<iftest="completeFromDate != null">
<iftest="startFromDate != null">
AND SO.PLANNED_COMP_DATE >= TO_DATE(#{completeFromDate}, 'YYYY-MM-DD')
AND SO.PLANNED_START_DATE >= TO_DATE(#{startFromDate}, 'YYYY-MM-DD')
</if>
</if>
<iftest="completeToDate != null">
<iftest="startToDate != null">
AND SO.PLANNED_COMP_DATE <= TO_DATE(#{completeToDate}|| '23:59:59', 'YYYY-MM-DD HH24:MI:SS')
AND SO.PLANNED_START_DATE <= TO_DATE(#{startToDate}|| '23:59:59', 'YYYY-MM-DD HH24:MI:SS')
</if>
</if>
<iftest="completeFromDate != null">
AND SO.PLANNED_COMP_DATE >= TO_DATE(#{completeFromDate}, 'YYYY-MM-DD')
</if>
<iftest="completeToDate != null">
AND SO.PLANNED_COMP_DATE <= TO_DATE(#{completeToDate}|| '23:59:59', 'YYYY-MM-DD HH24:MI:SS')
</if>
) WIP
LEFT JOIN Z_SFC_DISPATCH V1 ON V1.SITE = WIP.SITE AND V1.SFC = WIP.SFC AND V1.DISPATCH_SEQ = WIP.BEFORE_SEQ
LEFT JOIN Z_SFC_DISPATCH V2 ON V2.SITE = WIP.SITE AND V2.SFC = WIP.SFC AND V2.DISPATCH_SEQ = WIP.AFTER_SEQ
) WIP
) WIP
LEFT JOIN Z_SFC_DISPATCH V1 ON V1.SITE = WIP.SITE AND V1.SFC = WIP.SFC AND V1.DISPATCH_SEQ = WIP.BEFORE_SEQ
<iftest="isCompleted != null and isCompleted != ''">
LEFT JOIN Z_SFC_DISPATCH V2 ON V2.SITE = WIP.SITE AND V2.SFC = WIP.SFC AND V2.DISPATCH_SEQ = WIP.AFTER_SEQ
WHERE WIP.IS_COMPLETED = #{isCompleted}
WHERE 1 = 1
<iftest="isCompleted != null and isCompleted != '' and isCompleted = 'true'">
AND V1.DISPATCH_STATUS = 'COMPLETE'
</if>
</if>
ORDER BY WIP.SHOP_ORDER, WIP.SFC, TO_NUMBER(WIP.DISPATCH_SEQ)
ORDER BY WIP.SHOP_ORDER, WIP.SFC, TO_NUMBER(WIP.DISPATCH_SEQ)