CASE WHEN zsd.PLANNED_COMP_DATE IS NOT NULL AND zsd.ACTUAL_COMPLETE_DATE IS NULL THEN TO_CHAR(TO_NUMBER(zsd.PLANNED_COMP_DATE + 8/24 - SYSDATE),'FM9999990.000')
ELSE ''
END SURPLUS_DAY,
CASE WHEN zsd.ACTUAL_START_DATE IS NOT NULL AND cf3.VALUE IS NOT NULL AND cf3.VALUE != 0 AND zsd.ACTUAL_COMPLETE_DATE IS NULL
THEN ROUND(TO_NUMBER(SYSDATE - (zsd.ACTUAL_START_DATE+8/24))*24/TO_NUMBER(cf3.VALUE),2)*100 || '%'
WHEN zsd.ACTUAL_START_DATE IS NOT NULL AND cf3.VALUE IS NOT NULL AND cf3.VALUE != 0 AND zsd.ACTUAL_COMPLETE_DATE IS NOT NULL
THEN ROUND(TO_NUMBER((zsd.ACTUAL_COMPLETE_DATE+8/24) - (zsd.ACTUAL_START_DATE+8/24))*24/TO_NUMBER(cf3.VALUE),2)*100 || '%'
ELSE ''
END PROCESS_HOURS
FROM Z_SFC_DISPATCH zsd
LEFT JOIN WORK_CENTER wc ON wc.WORK_CENTER = zsd.WORK_CENTER
LEFT JOIN WORK_CENTER_T wct ON wct.WORK_CENTER_BO = wc.HANDLE AND wct.LOCALE = 'zh'
LEFT JOIN SHOP_ORDER so ON so.SHOP_ORDER = zsd.SHOP_ORDER AND so.SITE = zsd.SITE
LEFT JOIN CUSTOM_FIELDS cf ON cf.HANDLE = so.HANDLE AND cf."ATTRIBUTE" = 'ITEM_NUMBER'
LEFT JOIN CUSTOM_FIELDS cf2 ON cf2.HANDLE = so.HANDLE AND cf2."ATTRIBUTE" = 'PRODUCT_CATEGORY'
LEFT JOIN ITEM i On i.HANDLE = so.ITEM_BO
LEFT JOIN ITEM_T it ON it.ITEM_BO = so.ITEM_BO
LEFT JOIN RESRCE r ON r.RESRCE = zsd.RESRCE AND r.SITE = zsd.SITE
LEFT JOIN SFC s ON s.SFC = zsd.SFC AND s.SITE = zsd.SITE
LEFT JOIN SFC_ROUTING sr ON sr.SFC_BO = s.HANDLE
LEFT JOIN SFC_ROUTER st ON st.SFC_ROUTING_BO = sr.HANDLE AND st.IN_USE = 'true'
LEFT JOIN SFC_STEP ss ON ss.SFC_ROUTER_BO = st.HANDLE AND (ss.QTY_IN_QUEUE > 0 OR ss.QTY_IN_WORK > 0)
LEFT JOIN OPERATION o ON o.OPERATION = SUBSTR(SS.OPERATION_BO,INSTR(SS.OPERATION_BO,',',1,1)+1,INSTR(SS.OPERATION_BO,',',1,2) - INSTR(SS.OPERATION_BO,',') -1) AND o.SITE = zsd.SITE
LEFT JOIN OPERATION_T ot ON ot.OPERATION_BO = o.HANDLE AND ot.LOCALE = 'zh'
LEFT JOIN OPERATION o2 ON o2.OPERATION = zsd.OPERATION AND o2.SITE = zsd.SITE
LEFT JOIN OPERATION_T ot2 ON ot2.OPERATION_BO = o2.HANDLE AND ot2.LOCALE = 'zh'
LEFT JOIN Z_ABNORMAL_BILL zab ON zab.SFC = zsd.SFC AND zab.OPERATION = zsd.OPERATION AND zab.SITE = zsd.SITE
LEFT JOIN ROUTER_STEP rs ON zsd.ROUTER_BO = rs.ROUTER_BO AND rs.STEP_ID = zsd.STEP_ID
LEFT JOIN ROUTER_OPERATION ro ON ro.ROUTER_STEP_BO = rs.HANDLE AND ro.OPERATION_BO = ss.OPERATION_BO
LEFT JOIN CUSTOM_FIELDS cf3 ON cf3.HANDLE = ro.HANDLE AND cf3."ATTRIBUTE" = 'PROD_TIME'
INNER JOIN DATA_FIELD df ON df.DATA_FIELD = 'PRODUCT_CATEGORY'
LEFT JOIN DATA_FIELD_LIST dfl ON dfl.DATA_FIELD_BO = df.HANDLE AND dfl.DATA_VALUE = zab.PRODUCT_CATEGORY
LEFT JOIN DATA_FIELD_LIST_T dflt ON dflt.DATA_FIELD_LIST_BO = dfl.HANDLE AND dflt.LOCALE = #{locale}
<where>
zsd.SITE = #{site}
<iftest="workCenter != null and workCenter != ''">
AND (wc.WORK_CENTER = #{workCenter} OR wct.DESCRIPTION = #{workCenter})
</if>
<iftest="itemNumber != null and itemNumber != ''">
AND cf.VALUE = #{itemNumber}
</if>
<iftest="productCategory != null and productCategory != ''">
AND (dflt.DATA_TAG = #{productCategory} OR
zab.PRODUCT_CATEGORY = #{productCategory} OR
cf2.VALUE = #{productCategory}
)
</if>
<iftest="shopOrder != null and shopOrder != ''">
AND so.SHOP_ORDER LIKE '%${shopOrder}%'
</if>
<iftest="startDateTime != null and startDateTime != ''">
AND zsd.PLANNED_COMP_DATE >= TO_DATE(#{startDateTime},'YYYY-MM-DD')-8/24
</if>
<iftest="endDateTime != null and endDateTime != ''">
AND zsd.PLANNED_COMP_DATE <= TO_DATE(#{endDateTime}|| '15:59:59','YYYY-MM-DD HH24:MI:SS')
-- CASE WHEN ss.STEP_ID = zsd.STEP_ID AND zsd.DISPATCH_STATUS != 'START' AND o.OPERATION = zsd.OPERATION THEN ''
-- ELSE ot.DESCRIPTION
-- END CURRENT_OPERATION_DESCRIPTION,
ot2.DESCRIPTION OPERATION_DESCRIPTION,
CASE WHEN zab.HANDLE IS NOT NULL THEN '是'
ELSE '否'
END IS_ANOMALY,
CASE WHEN zsd.PLANNED_COMP_DATE IS NOT NULL AND zsd.ACTUAL_COMPLETE_DATE IS NULL AND zsd.DISPATCH_STATUS != 'CANCEL' THEN TO_CHAR(TO_NUMBER(zsd.PLANNED_COMP_DATE + 8/24 - SYSDATE),'FM9999990.000')
ELSE ''
END SURPLUS_DAY,
CASE WHEN zsd.ACTUAL_START_DATE IS NOT NULL AND cf3.VALUE IS NOT NULL AND cf3.VALUE != 0 AND zsd.ACTUAL_COMPLETE_DATE IS NULL
THEN ROUND(TO_NUMBER(SYSDATE - (zsd.ACTUAL_START_DATE+8/24))*24/TO_NUMBER(cf3.VALUE),2)*100 || '%'
WHEN zsd.ACTUAL_START_DATE IS NOT NULL AND cf3.VALUE IS NOT NULL AND cf3.VALUE != 0 AND zsd.ACTUAL_COMPLETE_DATE IS NOT NULL
THEN ROUND(TO_NUMBER((zsd.ACTUAL_COMPLETE_DATE+8/24) - (zsd.ACTUAL_START_DATE+8/24))*24/TO_NUMBER(cf3.VALUE),2)*100 || '%'
ELSE ''
END PROCESS_HOURS
FROM Z_SFC_DISPATCH zsd
LEFT JOIN WORK_CENTER wc ON wc.WORK_CENTER = zsd.WORK_CENTER
LEFT JOIN WORK_CENTER_T wct ON wct.WORK_CENTER_BO = wc.HANDLE AND wct.LOCALE = 'zh'
LEFT JOIN SHOP_ORDER so ON so.SHOP_ORDER = zsd.SHOP_ORDER AND so.SITE = zsd.SITE
LEFT JOIN CUSTOM_FIELDS cf ON cf.HANDLE = so.HANDLE AND cf."ATTRIBUTE" = 'ITEM_NUMBER'
LEFT JOIN CUSTOM_FIELDS cf2 ON cf2.HANDLE = so.HANDLE AND cf2."ATTRIBUTE" = 'PRODUCT_CATEGORY'
LEFT JOIN ITEM i On i.HANDLE = so.ITEM_BO
LEFT JOIN ITEM_T it ON it.ITEM_BO = so.ITEM_BO
LEFT JOIN RESRCE r ON r.RESRCE = zsd.RESRCE AND r.SITE = zsd.SITE
LEFT JOIN SFC s ON s.SFC = zsd.SFC AND s.SITE = zsd.SITE
LEFT JOIN SFC_ROUTING sr ON sr.SFC_BO = s.HANDLE
LEFT JOIN SFC_ROUTER st ON st.SFC_ROUTING_BO = sr.HANDLE AND st.IN_USE = 'true'
LEFT JOIN SFC_STEP ss ON ss.SFC_ROUTER_BO = st.HANDLE AND (ss.QTY_IN_QUEUE > 0 OR ss.QTY_IN_WORK > 0)
LEFT JOIN OPERATION o ON o.OPERATION = SUBSTR(SS.OPERATION_BO,INSTR(SS.OPERATION_BO,',',1,1)+1,INSTR(SS.OPERATION_BO,',',1,2) - INSTR(SS.OPERATION_BO,',') -1) AND o.SITE = zsd.SITE
LEFT JOIN OPERATION_T ot ON ot.OPERATION_BO = o.HANDLE AND ot.LOCALE = 'zh'
LEFT JOIN OPERATION o2 ON o2.OPERATION = zsd.OPERATION AND o2.SITE = zsd.SITE
LEFT JOIN OPERATION_T ot2 ON ot2.OPERATION_BO = o2.HANDLE AND ot2.LOCALE = 'zh'
LEFT JOIN Z_ABNORMAL_BILL zab ON zab.SFC = zsd.SFC AND zab.OPERATION = zsd.OPERATION AND zab.SITE = zsd.SITE
LEFT JOIN ROUTER_STEP rs ON zsd.ROUTER_BO = rs.ROUTER_BO AND rs.STEP_ID = zsd.STEP_ID
LEFT JOIN ROUTER_OPERATION ro ON ro.ROUTER_STEP_BO = rs.HANDLE AND ro.OPERATION_BO = ss.OPERATION_BO
LEFT JOIN CUSTOM_FIELDS cf3 ON cf3.HANDLE = ro.HANDLE AND cf3."ATTRIBUTE" = 'PROD_TIME'
INNER JOIN DATA_FIELD df ON df.DATA_FIELD = 'PRODUCT_CATEGORY'
LEFT JOIN DATA_FIELD_LIST dfl ON dfl.DATA_FIELD_BO = df.HANDLE AND dfl.DATA_VALUE = zab.PRODUCT_CATEGORY
LEFT JOIN DATA_FIELD_LIST_T dflt ON dflt.DATA_FIELD_LIST_BO = dfl.HANDLE AND dflt.LOCALE = #{locale}
<where>
zsd.SITE = #{site}
<iftest="workCenter != null and workCenter != ''">
AND (wc.WORK_CENTER = #{workCenter} OR wct.DESCRIPTION = #{workCenter})
</if>
<iftest="itemNumber != null and itemNumber != ''">
AND cf.VALUE = #{itemNumber}
</if>
<iftest="productCategory != null and productCategory != ''">
AND (dflt.DATA_TAG = #{productCategory} OR
zab.PRODUCT_CATEGORY = #{productCategory} OR
cf2.VALUE = #{productCategory}
)
</if>
<iftest="shopOrder != null and shopOrder != ''">
AND so.SHOP_ORDER LIKE '%${shopOrder}%'
</if>
<iftest="startDateTime != null and startDateTime != ''">
AND zsd.PLANNED_COMP_DATE >= TO_DATE(#{startDateTime},'YYYY-MM-DD')-8/24
</if>
<iftest="endDateTime != null and endDateTime != ''">
AND zsd.PLANNED_COMP_DATE <= TO_DATE(#{endDateTime}|| '15:59:59','YYYY-MM-DD HH24:MI:SS')