<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc=" 生成运输需求">
    <query id = "writeDemand.getDemandNo" desc = "查询需求编号">
        SELECT ? ||TO_CHAR(SYSDATE,'YYYYMMDD')||
        LPAD(NVL(MAX(TO_NUMBER(SUBSTR(T.DEMAND_NO, LENGTH(T.DEMAND_NO) - 4))),
        0) + 1,
        5,
        '0') DEMAND_NO
        FROM TMS_DEMAND_M T
        WHERE T.DEMAND_NO LIKE ?||TO_CHAR(SYSDATE,'YYYYMMDD') ||'_____'
    </query>
    <query id = "writeDemand.getDemandSeq" desc = "最大执行顺序号">
        SELECT
        NVL(MAX(TO_NUMBER(T.EXECUTE_SQE)),0) + 1 EXECUTE_SQE
        FROM TMS_DEMAND_M T
    </query>
    <query id = "writeDemand.getStorageNo" desc = "查询产线对应的产出库">
        SELECT T.OUT_REPOSITORY AS STORAGE_NO,
        (SELECT S.STORAGE_NAME
        FROM YDM_BS_STORAGE S
        WHERE S.STORAGE_NO = T.OUT_REPOSITORY) STORAGE_NAME
        FROM COM_BASE_PLINE T
        WHERE T.PLINE_CODE = ?
    </query>
    <query id = "writeDemand.getStorageNoTl" desc = "查询产线对应的投料库">
        SELECT T.IN_REPOSITORY AS STORAGE_NO,
        (SELECT S.STORAGE_NAME
        FROM YDM_BS_STORAGE S
        WHERE S.STORAGE_NO = T.IN_REPOSITORY) STORAGE_NAME
        FROM COM_BASE_PLINE T
        WHERE T.PLINE_CODE = ?
    </query>
    <query id = "writeDemand.getPlanZyZgM" desc = "查询轧管虚拟炉计划信息">
        <![CDATA[
             SELECT
       T.HEAT_PLAN_NO,
       T.GX_PRO_SEQ,
       T.ZY_BATCH_ID,
       CASE
         WHEN T.STOVE_NO IS NULL AND T.UPPER_PROCESS_CODE = 'B' THEN
          (SELECT O.STOVE_NO
             FROM PLN_STEELFOR_ORD O
            WHERE O.FURNACENO || '/' || O.SEQUENCENO = T.UPPER_HEATPLAN_ID)
         WHEN T.STOVE_NO IS NULL AND T.UPPER_PROCESS_CODE = 'C' THEN
            (SELECT O.STOVE_NO
             FROM PLN_STEELFOR_ORD O,PLN_ZY_DZ_M D
            WHERE O.FURNACENO || '/' || O.SEQUENCENO =D.UPPER_HEATPLAN_ID
            AND D.HEAT_PLAN_NO=T.UPPER_HEATPLAN_ID)
         ELSE
          T.STOVE_NO
       END STOVE_NO,
         CASE
         WHEN T.JUDGE_STOVE_NO IS NULL AND T.UPPER_PROCESS_CODE = 'B' THEN
          (SELECT O.JUDGE_STOVE_NO
             FROM PLN_STEELFOR_ORD O
            WHERE O.FURNACENO || '/' || O.SEQUENCENO = T.UPPER_HEATPLAN_ID)
         WHEN T.JUDGE_STOVE_NO IS NULL AND T.UPPER_PROCESS_CODE = 'C' THEN
            (SELECT O.JUDGE_STOVE_NO
             FROM PLN_STEELFOR_ORD O,PLN_ZY_DZ_M D
            WHERE O.FURNACENO || '/' || O.SEQUENCENO = D.UPPER_HEATPLAN_ID
            AND D.HEAT_PLAN_NO=T.UPPER_HEATPLAN_ID)
         ELSE
          T.JUDGE_STOVE_NO
       END JUDGE_STOVE_NO,
        CASE
         WHEN T.FLAG_STOVE_NO IS NULL AND T.UPPER_PROCESS_CODE = 'B' THEN
          (SELECT O.FLAG_STOVE_NO
             FROM PLN_STEELFOR_ORD O
            WHERE O.FURNACENO || '/' || O.SEQUENCENO = T.UPPER_HEATPLAN_ID)
         WHEN T.FLAG_STOVE_NO IS NULL AND T.UPPER_PROCESS_CODE = 'C' THEN
            (SELECT O.FLAG_STOVE_NO
             FROM PLN_STEELFOR_ORD O,PLN_ZY_DZ_M D
            WHERE O.FURNACENO || '/' || O.SEQUENCENO = D.UPPER_HEATPLAN_ID
            AND D.HEAT_PLAN_NO=T.UPPER_HEATPLAN_ID)
         ELSE
          T.FLAG_STOVE_NO
       END FLAG_STOVE_NO,
       T.PLANSTATUS,
       T.UPPER_HEATPLAN_ID,
       T.PRO_PLAN_ID,
       T.GX_PLAN_NO,
       T.CCM_PRO_PLAN_ID,
       T.CCM_GX_PLAN_NO,
       T.PLINE_CODE,
       T.PLINE_NAME,
       T.PROCESS_CODE_C,
       T.PROCESS_DESC_C,
       T.UPPER_PROCESS_CODE,
       T.NEXT_PROCESS_CODE,
       T.ISENDGX,
       T.IF_MATCH_ODD,
       T.IF_DO_HEAT_PLAN,
       T.ORDER_SOURCE,
       T.ORD_LN_DLY_PK,
       T.ORDER_NO,
       T.ORDER_SEQ,
       T.DELIVERY_NO,
       T.REQ_BL_ID,
       T.IF_EXPORT,
       T.PRIORITY,
       T.PRIORITY_MEMO,
       T.PRO_MONTH,
       T.IF_LEN_CONTROL,
       T.IF_MINUS_SIC_ROLL,
       T.PROD_STANDARD,
       T.OUTPUT_STANDARD,
       T.DECISION,
       T.PROGY_MEMO,
       T.GOWHERE_CODE,
       T.GOWHERE_NAME,
       T.OUTS_BILLET_FL,
       T.GPTYPE,
       T.INWL_ID,
       T.INWL_DESC,
       T.OUTWL_ID,
       T.OUTWL_DESC,
       T.GRADECODE,
       T.GRADENAME,
       T.STEELCODE,
       T.STEELNAME,
       T.PRODUCCODE,
       T.PRODUCNAME,
       T.MODEL_CODE,
       T.MODEL_DESC,
       T.DIAMETER,
       T.LEN_GP_SINGLE,
       T.WT_GP_SINGLE,
       T.PLN_INSINGLE_NUM,
       T.PLN_INSINGLE_WT,
       T.PLN_OUTSINGLE_NUM,
       T.PLN_OUTSINGLE_W,
       T.OUTDIAMETER,
       T.WALLTHICK,
       T.OUTDIAMETER_ZG,
       T.WALLTHICK_ZG,
       T.AIMOUTDIAMETER,
       T.AIMWALLTHICK,
       T.THICKNESS_WALL,
       T.LEN_ROLL_MAX,
       T.LEN_ROLL_MIN,
       T.AIMLENGTH,
       T.ROLL_LENGTH,
       T.OUTNUM_CUT,
       T.CUT_TYPE,
       T.LEN_CUTEND,
       T.LEN_CUTHEAD,
       T.DIAMETER_MANDREL,
       T.PASS_CODE,
       T.PASS_NAME,
       T.IF_MONITOR,
       T.PRDCR_NO,
       T.MONITOR_POINT,
       T.BOM,
       T.WHOLE_BACKLOG,
       T.WHOLE_BACKLOG_DESC,
       T.CIC,
       T.PIC,
       T.SIC,
       T.DIC,
       T.CRAFT_FILE_NO,
       T.CRAFT_FILE_MAN,
       T.CRAFT_SEQ,
       T.SEC_CRAFT_FILE_NO,
       T.STATION_ROAD,
       T.PRO_DAY,
       T.BAL_YEAR_MONTH,
       T.CREATE_NAME,
       TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
       T.UPDATE_NAME,
       TO_CHAR(T.UPDATE_TIME, 'YYYY-MM-DD HH24:MI:SS') UPDATE_TIME,
       T.DOWNMAN,
       TO_CHAR(T.DOWNTIME, 'YYYY-MM-DD HH24:MI:SS') DOWNTIME,
       T.IS_LOAD,
       T.PLN_TYPE,
       T.INDEX_SEQ,T.MEMO,T.FEED_HEAT_NO,(SELECT Y.ABRVITION
          FROM SLM_BASE_CUSTOMER Y
         WHERE Y.CUSTOMER_NO = S.FINAL_USER) FINAL_USER_DESC,
       S.FINAL_USER,
       S.SPEC_CODE,
       REPLACE(UPPER(S.SPEC_NAME), 'X', '*') SPEC_NAME,
       S.LENGTHDISC,
       S.STD_STYLE_DESC,
       S.STD_CODE,
       S.STD_NAME,
       (SELECT '【' || BASENAME || '】'
          FROM COM_BASE_INFO
         WHERE BASECODE = S.MONITORDEMAND) MONITORDEMAND,
       T.FEED_HEAT_NO,
 (SELECT L.STD_STYLE FROM SLM_ORDER_LINE L WHERE L.ORD_PK=S.ORD_PK AND L.ORD_LN_PK=S.ORD_LN_PK) STD_STYLE,T1.PLN_DIVIDE_ID
FROM PLN_ZY_ZG_M T, PLN_SALEORD S, PLN_ORDER_ZG_S T1
WHERE T.ORD_LN_DLY_PK = S.ORD_LN_DLY_PK
AND T.PRO_PLAN_ID=T1.PRO_PLAN_ID
AND T.GX_PLAN_NO =T1.GX_PLAN_NO
AND T.PRO_PLAN_ID = ?
AND T.GX_PLAN_NO = ?
]]>
    </query>
    <query id = "writeDemand.getPlanZyDbkM" desc = "查询敦拔扩虚拟炉计划">
        <![CDATA[
        SELECT * FROM PLN_ZY_DBK_M T WHERE T.PRO_PLAN_ID = ? AND T.GX_PLAN_NO = ?
        ]]>
    </query>
    <query id = "writeDemand.getPlanZyRclM" desc = "查询热处理虚拟炉计划">
        SELECT * FROM PLN_ZY_RCL_M T WHERE T.PRO_PLAN_ID = ? AND T.GX_PLAN_NO = ?
    </query>
    <query id = "writeDemand.getPlanZyJgxM" desc = "查询加工虚拟炉计划">
        SELECT * FROM PLN_ZY_JGX_M T WHERE T.PRO_PLAN_ID = ? AND T.GX_PLAN_NO = ?
    </query>

    <query id = "writeDemand.getQureyZyJgM" desc = "查询接箍炉计划">
        SELECT T.* FROM PLN_ZY_JG_M T WHERE T.HEAT_PLAN_NO = ?
    </query>
    <query id = "writeDemand.getQureyZyJgBill" desc = "查询接箍工单信息">
        SELECT
        SUBCONTRACT_NO,
        DECISION,
        INDEX_SEQ,
        CRAFT_SEQ,
        CRAFT_FILE_NO,
        PLINE_CODE_W,
        PLINE_NAME_W,
        GX_PRO_SEQ,
        BUYER_ID,
        BUYER_NAME,
        MONITOR_POINT,
        MIN_D,
        MIN_H,
        MONITORDEMAND,
        IFSPLIT,
        BELONG_CODE,
        BELONG_NAME,
        IS_LOAD_FLAG,
        WO_ID,
        HEAT_PLAN_NO,
        JUDGE_STOVE_NO,
        BATCH_NO,
        BATCH_GROUD_NO,
        PLINE_CODE,
        PLINE_NAME,
        IF_ALL_OUT_WORK,
        IF_OUT_CUT,
        IF_OUT_CJG,
        IF_OUT_IMPRESS,
        IF_OUT_LATHE,
        IF_OUT_DETECT,
        IF_OUT_BLAST,
        IF_OUT_COAT,
        COAT_TYPE,
        PLAN_JG_NUM,
        CS_JG_NUM,
        XQ_JG_NUM,
        DEMAND_COPPER,
        LATHE_GRP_NO,
        LATHE_GRP_NM,
        DEMAND_DETECTION,
        DEMAND_BLAST,
        DEMAND_BONDERIZING,
        ZY_BILL_STATUS,
        MEMO,
        CREATE_NAME,
        TO_CHAR(CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
        UPDATE_NAME,
        TO_CHAR(UPDATE_TIME, 'YYYY-MM-DD HH24:MI:SS') UPDATE_TIME,
        IF_OUT_COPPER,
        TO_CHAR(CLOSE_TIME, 'YYYY-MM-DD HH24:MI:SS') CLOSE_TIME,
        PLAN_BL_NUM,
        PLAN_BL_WT,
        IF_OUT_THREAD,
        REAL_BL_NUM,
        REAL_BL_WT,
        STOVE_NO,
        FLAG_STOVE_NO,
        OUT_NUM,
        OUT_WT,
        STEELCODE,
        STEELNAME,
        GRADECODE,
        GRADENAME,
        SPEC_JG_DESC,
        SPEC_JG,
        STYLE_JG,
        STD_CODE,
        STD_NAME,
        STD_STYLE,
        STD_STYLE_DESC,
        PRODUCCODE_JG,
        PRODUCCODE_JG_DESC,
        CODE_JG,
        CODE_JG_BL,
        CODE_BL_ALL,
        MODEL_CODE,
        MODEL_DESC,
        IF_MONITOR_JG,
        PRDCR_NO,
        HEAT_PLAN_SQE,
        KEY,
        BL_WL_ID,
        BL_WL_DESC,
        OUTWL_ID,
        OUTWL_DESC,
        AIMLENGTH_BL,
        AIM_CUT_LEN,
        SINGLE_CUT_NUN,
        SINGLEWEIGHT,
        PER_STATUS,
        BESIDE_STATUS,
        JG_ORDERNO_ALL,
        CRAFT_NO_JG2,
        CRAFT_SEQ2,
        CRAFT_PATH,
        ORD_LN_DLY_PK,
        ORDER_NO,
        ORDER_SEQ,
        DELIVERY_NO,
        LATHE_CUT_NM
        FROM PLN_ZY_JG_WORKBILL
        WHERE WO_ID = ?
    </query>
    <query id = "writeDemand.getPlanSteelforOrd" desc = "查询炼钢切割炉计划信息">
        SELECT * FROM PLN_STEELFOR_ORD T WHERE T.JUDGE_STOVE_NO = ?
    </query>
    <query id = "writeDemand.getQureyZgPln" desc = "根据上工序炉计划ID查询轧管炉计划">
        SELECT * FROM PLN_ZY_ZG_M T WHERE T.HEAT_PLAN_NO = ?
    </query>
    <query id = "writeDemand.getQueryDbkPln" desc = "根据上工序炉计划ID查询敦拔扩计划">
        SELECT * FROM PLN_ZY_DBK_M T WHERE T.HEAT_PLAN_NO = ?
    </query>
    <query id = "writeDemand.getQueryDbkPlnOrdS" desc = "查询敦拔扩订单信息">
        SELECT
        REAL_BATCH_WT,
        REAL_BATCH_NUM,
        IF_STOVE_ISSUED,
        TO_CHAR(STOVE_ISSUED_TIME, 'YYYY-MM-DD HH24:MI:SS') STOVE_ISSUED_TIME,
        STOVE_ISSUED_MAN,
        IS_ONLOAD_LINE,
        PROCESS_CODE_C,
        PROCESS_DESC_C,
        MSC,
        INDEX_SEQ,
        BOM,
        WHOLE_BACKLOG_DESC,
        IF_CRAFT_LOCKED,
        WEIGTH_S_MIN,
        PRIORITY,
        PRIORITY_MEMO,
        VALIDFLAG,
        DECISION,
        FINAL_USER_DESC,
        PASS_CODE,
        PASS_NAME,
        OUTDIAMETER_IN,
        WALLTHICK_IN,
        LENGTH_IN,
        LEN_CUTHEAD,
        LEN_CUTEND,
        LENGTHMAX_IN,
        LENGTHMIN_IN,
        IN_WEIGHT_S,
        IN_NUM_S,
        ADD_WT_IN,
        ADD_NUM_IN,
        MATCH_WT_IN,
        MATCH_NUM_IN,
        ISENDGX,
        IF_MONITOR_DBK,
        PRDCR_NO,
        MONITOR_POINT,
        CIC,
        PIC,
        SIC,
        DIC,
        WIC,
        GIC,
        CRAFT_FILE_NO,
        CRAFT_FILE_MAN,
        CRAFT_SEQ,
        STATION_ROAD,
        BATCHED_WT,
        BATCHED_NUM,
        FINISHWEIGHT,
        FINISHNUM,
        IS_PLAN_OK,
        ZY_BATCH_ID,
        GRADECODE,
        GRADENAME,
        PRO_MONTH,
        PREVIOUS_GX,
        PREV_GXPLAN_ID,
        IF_EXPORT,
        TO_CHAR(CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
        MEMO,
        TO_CHAR(ISSUED_TIME, 'YYYY-MM-DD HH24:MI:SS') ISSUED_TIME,
        ISSUED_MAN,
        TO_CHAR(LAST_UNDOWN_TIME, 'YYYY-MM-DD HH24:MI:SS') LAST_UNDOWN_TIME,
        LAST_UNDOWN_MAN,
        VERSION_NO,
        PROCESSING_COST,
        TOTAL_COST,
        PRO_ORDER_NO,
        PRO_PLAN_ID,
        GX_PLAN_NO,
        PLAN_GROUP_ID,
        ORDER_SOURCE,
        ORD_LN_DLY_PK,
        PLN_DIVIDE_ID,
        ORDER_NO,
        ORDER_SEQ,
        DELIVERY_NO,
        REQ_BL_ID,
        PLINE_CODE,
        PLINE_NAME,
        INWL_ID,
        INWL_DESC,
        OUTWL_ID,
        OUTWL_DESC,
        WEIGTH_S,
        NUM_S,
        GX_PRO_SEQ,
        PLAN_USETIME,
        TO_CHAR(PLAN_TIME_B, 'YYYY-MM-DD HH24:MI:SS') PLAN_TIME_B,
        TO_CHAR(PLAN_TIME_E, 'YYYY-MM-DD HH24:MI:SS') PLAN_TIME_E,
        EXE_STATUS,
        IS_REPAIR_PLN,
        REPAIR_TYPE,
        OUTDIAMETER,
        WALLTHICK,
        LENGTHDISC,
        AIMOUTDIAMETER,
        AIMWALLTHICK,
        AIMLENGTH
        FROM PLN_ORDER_DBK_S T WHERE T.PRO_PLAN_ID = ? AND T.GX_PLAN_NO = ?
    </query>
    <query id = "writeDemand.getQueryRclPln" desc = "根据上工序炉计划ID查询热处理计划">
        SELECT * FROM PLN_ZY_RCL_M T WHERE T.HEAT_PLAN_NO = ?
    </query>
    <query id = "writeDemand.getQueryRclPlnS" desc = "查询热处理订单信息">
        SELECT IF_STOVE_ISSUED,
        TO_CHAR(STOVE_ISSUED_TIME, 'YYYY-MM-DD HH24:MI:SS') STOVE_ISSUED_TIME,
        STOVE_ISSUED_MAN,
        IS_ONLOAD_LINE,
        PROCESS_CODE_C,
        PROCESS_DESC_C,
        MSC,
        INDEX_SEQ,
        BOM,
        WHOLE_BACKLOG_DESC,
        IF_CRAFT_LOCKED,
        WEIGTH_S_MIN,
        PRIORITY,
        PRIORITY_MEMO,
        VALIDFLAG,
        DECISION,
        PRDCR_ADVC_DAY,
        GROUP_RCL,
        PRO_ORDER_NO,
        PRO_PLAN_ID,
        GX_PLAN_NO,
        PLAN_GROUP_ID,
        ORDER_SOURCE,
        ORD_LN_DLY_PK,
        PLN_DIVIDE_ID,
        ORDER_NO,
        ORDER_SEQ,
        DELIVERY_NO,
        REQ_BL_ID,
        PLINE_CODE,
        PLINE_NAME,
        INWL_ID,
        INWL_DESC,
        OUTWL_ID,
        OUTWL_DESC,
        GRADECODE,
        GRADENAME,
        OUTDIAMETER,
        WALLTHICK,
        LENGTHDISC,
        LENGTHMAX_IN,
        LENGTHMIN_IN,
        LENGTH_IN,
        AIMLENGTH,
        IN_WEIGHT_S,
        IN_NUM_S,
        WEIGTH_S,
        NUM_S,
        MATCH_WT_IN,
        MATCH_NUM_IN,
        IF_MONITOR_RCL,
        PRDCR_NO,
        MONITOR_POINT,
        CRAFT_FILE_NO,
        CRAFT_FILE_MAN,
        CRAFT_SEQ,
        STATION_ROAD,
        GX_PRO_SEQ,
        PLAN_USETIME,
        TO_CHAR(PLAN_TIME_B, 'YYYY-MM-DD HH24:MI:SS') PLAN_TIME_B,
        TO_CHAR(PLAN_TIME_E, 'YYYY-MM-DD HH24:MI:SS') PLAN_TIME_E,
        BATCHED_WT,
        BATCHED_NUM,
        FINISHWEIGHT,
        FINISHNUM,
        EXE_STATUS,
        IS_REPAIR_PLN,
        REPAIR_TYPE,
        ZY_BATCH_ID,
        ADD_WT_IN,
        ADD_NUM_IN,
        ISENDGX,
        CIC,
        PIC,
        SIC,
        DIC,
        WIC,
        GIC,
        IS_PLAN_OK,
        STEELCODE,
        STEELNAME,
        PRO_MONTH,
        PREVIOUS_GX,
        PREV_GXPLAN_ID,
        IF_EXPORT,
        TO_CHAR(CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
        MEMO,
        TO_CHAR(ISSUED_TIME, 'YYYY-MM-DD HH24:MI:SS') ISSUED_TIME,
        ISSUED_MAN,
        TO_CHAR(LAST_UNDOWN_TIME, 'YYYY-MM-DD HH24:MI:SS') LAST_UNDOWN_TIME,
        LAST_UNDOWN_MAN,
        VERSION_NO,
        PROCESSING_COST,
        TOTAL_COST
        FROM PLN_ORDER_RCL_S T WHERE T.PRO_PLAN_ID = ? AND T.GX_PLAN_NO = ?
    </query>
    <query id = "writeDemand.getQueryJgxPln" desc = "查询加工炉计划">
        SELECT * FROM PLN_ZY_JGX_M T WHERE T.HEAT_PLAN_NO = ?
    </query>
    <query id = "writeDemand.getQueryJgxPlnS" desc = "查询加工订单信息">
        SELECT
        IF_STOVE_ISSUED,
        TO_CHAR(STOVE_ISSUED_TIME, 'YYYY-MM-DD HH24:MI:SS') STOVE_ISSUED_TIME,
        STOVE_ISSUED_MAN,
        IS_ONLOAD_LINE,
        PROCESS_CODE_C,
        PROCESS_DESC_C,
        MSC,
        INDEX_SEQ,
        BOM,
        IF_CRAFT_LOCKED,
        VALIDFLAG,
        DECISION,
        GROUP_JGX,
        PRO_ORDER_NO,
        PRO_PLAN_ID,
        GX_PLAN_NO,
        PLAN_GROUP_ID,
        ORDER_SOURCE,
        ORD_LN_DLY_PK,
        PLN_DIVIDE_ID,
        ORDER_NO,
        ORDER_SEQ,
        DELIVERY_NO,
        REQ_BL_ID,
        PLINE_CODE,
        PLINE_NAME,
        INWL_ID,
        INWL_DESC,
        OUTWL_ID,
        OUTWL_DESC,
        WEIGTH_S,
        NUM_S,
        GX_PRO_SEQ,
        PLAN_USETIME,
        TO_CHAR(PLAN_TIME_B, 'YYYY-MM-DD HH24:MI:SS') PLAN_TIME_B,
        TO_CHAR(PLAN_TIME_E, 'YYYY-MM-DD HH24:MI:SS') PLAN_TIME_E,
        EXE_STATUS,
        IS_REPAIR_PLN,
        REPAIR_TYPE,
        STEELCODE,
        STEELNAME,
        OUTDIAMETER,
        WALLTHICK,
        LENGTHMAX,
        LENGTHMIN,
        LENGTHDISC,
        AIMWALLTHICK,
        AIMLENGTH,
        SHRT_LEN_RATO,
        SHORTEST,
        LONG_LEN_RATO,
        LONGEST,
        SHRT_STOVE,
        AVG_LEN_MIN,
        DIFRNC_LEN_MAX,
        SIGL_LEN,
        ENDLEN_SPECSTD,
        MODEL_CODE,
        MODEL_DESC,
        LENGTHMAX_IN,
        LENGTHMIN_IN,
        LENGTH_IN,
        OUTNUM_CUT,
        IN_WEIGHT_S,
        IN_NUM_S,
        ADD_WT_IN,
        ADD_NUM_IN,
        MATCH_WT_IN,
        MATCH_NUM_IN,
        IF_MONITOR_JGX,
        PRDCR_NO,
        MONITOR_POINT,
        CIC,
        PIC,
        SIC,
        DIC,
        WIC,
        GIC,
        CRAFT_FILE_NO,
        CRAFT_FILE_MAN,
        CRAFT_SEQ,
        STATION_ROAD,
        BATCHED_WT,
        BATCHED_NUM,
        FINISHWEIGHT,
        FINISHNUM,
        IS_PLAN_OK,
        ZY_BATCH_ID,
        PRO_MONTH,
        PREVIOUS_GX,
        PREV_GXPLAN_ID,
        IF_EXPORT,
        FINAL_USER_DESC,
        PROCESS_DESC_C_ZG,
        GROUP_ROLL_NAME,
        TO_CHAR(BEGIN_TIME_ZG, 'YYYY-MM-DD HH24:MI:SS') BEGIN_TIME_ZG,
        PRDCR_ADVC_DAY,
        WHOLE_BACKLOG_DESC,
        PRIORITY,
        PRIORITY_MEMO,
        TO_CHAR(DELVRY_EDATE, 'YYYY-MM-DD HH24:MI:SS') DELVRY_EDATE,
        STATION_NM,
        OUTLINE_SITE_250,
        TO_CHAR(CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
        MEMO,
        TO_CHAR(ISSUED_TIME, 'YYYY-MM-DD HH24:MI:SS') ISSUED_TIME,
        ISSUED_MAN,
        TO_CHAR(LAST_UNDOWN_TIME, 'YYYY-MM-DD HH24:MI:SS') LAST_UNDOWN_TIME,
        LAST_UNDOWN_MAN,
        VERSION_NO,
        PROCESSING_COST,
        TOTAL_COST
        FROM PLN_ORDER_JGX_S T
        WHERE T.PRO_PLAN_ID = ? AND T.GX_PLAN_NO = ?
    </query>
    <query id = "writeDemand.insertDemand" desc = "插入下线运输需求">
        DECLARE
        V_COUNT NUMBER := 0;
        BEGIN
        SELECT COUNT(1)
        INTO V_COUNT
        FROM TMS_DEMAND_M T
        WHERE T.CURRENT_JOB_NO = '#CURRENT_JOB_NO#'
        AND T.PRO_ORDER_NO = '#PRO_ORDER_NO#'
        AND T.PRO_ORDER_SQE = '#PRO_ORDER_SQE#'
        AND T.TRAN_CLASS_CODE = 'XX';
        IF (V_COUNT = 0) THEN
        INSERT INTO TMS_DEMAND_M
        (DEMAND_NO,
        DEMAND_DESC,
        EXECUTE_SQE,
        URGENCY_TYPE_CODE,
        URGENCY_TYPE_DESC,
        TRAN_CLASS_CODE,
        TRAN_CLASS_DESC,
        DEMAND_VERTICAL_NO,
        COST_TYPE_CODE,
        COST_TYPE_DESC,
        CARRIER_CODE,
        CARRIER_NAME,
        REFE_NO,
        REFE_TYPE_CODE,
        REFE_TYPE_NAME,
        START_NODE_CODE,
        START_NODE_DESC,
        END_NODE_CODE,
        END_NODE_DESC,
        START_AREA_CODE,
        START_AREA_DESC,
        END_AREA_CODE,
        END_AREA_DESC,
        DEMAND_ORG_CODE,
        DEMAND_ORG_DESC,
        TRANSPORT_START_TIME,
        TRANSPORT_END_TIME,
        CAR_USE_CODE,
        CAR_USE_DESC,
        CAR_TYPE_CODE,
        CAR_TYPE_DESC,
        CALCULATE_CAR_VAL,
        CAR_WT_VAL,
        WEIGHING_IF,
        HEAT_NO,
        BATCH_NO,
        LOGO_NO,
        GROUP_NO,
        MATERIALS_CODE,
        MATERIALS_DESC,
        MATERIALS_SPEC,
        DIMATER_VAL,
        WIDE_VAL,
        HEIGHT_VAL,
        LEN_VAL,
        LEN_MIN_VAL,
        LEN_MAX_VAL,
        UOM_CODE,
        UOM_DESC,
        DEMAND_QTY_VAL,
        DEMAND_WT_VAL,
        OUTPUT_QTY_VAL,
        OUTPUT_WT_VAL,
        OFFLINE_QTY_VAL,
        OFFLINE_WT_VAL,
        SCRAP_QTY_VAL,
        SCRAP_WT_VAL,
        PRO_ORDER_NO,
        PRO_ORDER_SQE,
        CURRENT_JOB_NO,
        PREVIOUS_JOB_NO,
        STATUS,
        MEMO,
        CREATE_USERID,
        CREATE_NAME,
        CREATE_TIME,
        LOT_NO,
        MAXIMUM,
        MAT_TYPE)
        VALUES
        ('#DEMAND_NO#',
        '#DEMAND_DESC#',
        '#EXECUTE_SQE#',
        '#URGENCY_TYPE_CODE#',
        '#URGENCY_TYPE_DESC#',
        '#TRAN_CLASS_CODE#',
        '#TRAN_CLASS_DESC#',
        '#DEMAND_VERTICAL_NO#',
        '#COST_TYPE_CODE#',
        '#COST_TYPE_DESC#',
        '#CARRIER_CODE#',
        '#CARRIER_NAME#',
        '#REFE_NO#',
        '#REFE_TYPE_CODE#',
        '#REFE_TYPE_NAME#',
        '#START_NODE_CODE#',
        '#START_NODE_DESC#',
        '#END_NODE_CODE#',
        '#END_NODE_DESC#',
        '#START_AREA_CODE#',
        '#START_AREA_DESC#',
        '#END_AREA_CODE#',
        '#END_AREA_DESC#',
        '#DEMAND_ORG_CODE#',
        '#DEMAND_ORG_DESC#',
        TO_DATE('#TRANSPORT_START_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
        TO_DATE('#TRANSPORT_END_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
        '#CAR_USE_CODE#',
        '#CAR_USE_DESC#',
        '#CAR_TYPE_CODE#',
        '#CAR_TYPE_DESC#',
        '#CALCULATE_CAR_VAL#',
        '#CAR_WT_VAL#',
        '#WEIGHING_IF#',
        '#HEAT_NO#',
        '#BATCH_NO#',
        '#LOGO_NO#',
        '#GROUP_NO#',
        '#MATERIALS_CODE#',
        '#MATERIALS_DESC#',
        '#MATERIALS_SPEC#',
        '#DIMATER_VAL#',
        '#WIDE_VAL#',
        '#HEIGHT_VAL#',
        '#LEN_VAL#',
        '#LEN_MIN_VAL#',
        '#LEN_MAX_VAL#',
        '#UOM_CODE#',
        '#UOM_DESC#',
        '#DEMAND_QTY_VAL#',
        '#DEMAND_WT_VAL#',
        '#OUTPUT_QTY_VAL#',
        '#OUTPUT_WT_VAL#',
        '#OFFLINE_QTY_VAL#',
        '#OFFLINE_WT_VAL#',
        '#SCRAP_QTY_VAL#',
        '#SCRAP_WT_VAL#',
        '#PRO_ORDER_NO#',
        '#PRO_ORDER_SQE#',
        '#CURRENT_JOB_NO#',
        '#PREVIOUS_JOB_NO#',
        '#STATUS#',
        '#MEMO#',
        '#CREATE_USERID#',
        '#CREATE_NAME#',
        TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
        '#LOT_NO#',
        '#MAXIMUM#',
        '#MAT_TYPE#');
        END IF;
        END;
    </query>
    <query id = "writeDemand.insertDemandTL" desc = "插入投料运输需求">
        DECLARE
        V_COUNT NUMBER := 0;
        BEGIN
        SELECT COUNT(1)
        INTO V_COUNT
        FROM TMS_DEMAND_M T
        WHERE T.CURRENT_JOB_NO = '#CURRENT_JOB_NO#'
        AND T.TRAN_CLASS_CODE = 'TL';
        IF (V_COUNT = 0) THEN
        INSERT INTO TMS_DEMAND_M
        (DEMAND_NO,
        DEMAND_DESC,
        EXECUTE_SQE,
        URGENCY_TYPE_CODE,
        URGENCY_TYPE_DESC,
        TRAN_CLASS_CODE,
        TRAN_CLASS_DESC,
        DEMAND_VERTICAL_NO,
        COST_TYPE_CODE,
        COST_TYPE_DESC,
        CARRIER_CODE,
        CARRIER_NAME,
        REFE_NO,
        REFE_TYPE_CODE,
        REFE_TYPE_NAME,
        START_NODE_CODE,
        START_NODE_DESC,
        END_NODE_CODE,
        END_NODE_DESC,
        START_AREA_CODE,
        START_AREA_DESC,
        END_AREA_CODE,
        END_AREA_DESC,
        DEMAND_ORG_CODE,
        DEMAND_ORG_DESC,
        TRANSPORT_START_TIME,
        TRANSPORT_END_TIME,
        CAR_USE_CODE,
        CAR_USE_DESC,
        CAR_TYPE_CODE,
        CAR_TYPE_DESC,
        CALCULATE_CAR_VAL,
        CAR_WT_VAL,
        WEIGHING_IF,
        HEAT_NO,
        BATCH_NO,
        LOGO_NO,
        GROUP_NO,
        MATERIALS_CODE,
        MATERIALS_DESC,
        MATERIALS_SPEC,
        DIMATER_VAL,
        WIDE_VAL,
        HEIGHT_VAL,
        LEN_VAL,
        LEN_MIN_VAL,
        LEN_MAX_VAL,
        UOM_CODE,
        UOM_DESC,
        DEMAND_QTY_VAL,
        DEMAND_WT_VAL,
        OUTPUT_QTY_VAL,
        OUTPUT_WT_VAL,
        OFFLINE_QTY_VAL,
        OFFLINE_WT_VAL,
        SCRAP_QTY_VAL,
        SCRAP_WT_VAL,
        PRO_ORDER_NO,
        PRO_ORDER_SQE,
        CURRENT_JOB_NO,
        PREVIOUS_JOB_NO,
        STATUS,
        MEMO,
        CREATE_USERID,
        CREATE_NAME,
        CREATE_TIME,
        LOT_NO,
        MAXIMUM,
        MAT_TYPE)
        VALUES
        ('#DEMAND_NO#',
        '#DEMAND_DESC#',
        '#EXECUTE_SQE#',
        '#URGENCY_TYPE_CODE#',
        '#URGENCY_TYPE_DESC#',
        '#TRAN_CLASS_CODE#',
        '#TRAN_CLASS_DESC#',
        '#DEMAND_VERTICAL_NO#',
        '#COST_TYPE_CODE#',
        '#COST_TYPE_DESC#',
        '#CARRIER_CODE#',
        '#CARRIER_NAME#',
        '#REFE_NO#',
        '#REFE_TYPE_CODE#',
        '#REFE_TYPE_NAME#',
        '#START_NODE_CODE#',
        '#START_NODE_DESC#',
        '#END_NODE_CODE#',
        '#END_NODE_DESC#',
        '#START_AREA_CODE#',
        '#START_AREA_DESC#',
        '#END_AREA_CODE#',
        '#END_AREA_DESC#',
        '#DEMAND_ORG_CODE#',
        '#DEMAND_ORG_DESC#',
        TO_DATE('#TRANSPORT_START_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
        TO_DATE('#TRANSPORT_END_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
        '#CAR_USE_CODE#',
        '#CAR_USE_DESC#',
        '#CAR_TYPE_CODE#',
        '#CAR_TYPE_DESC#',
        '#CALCULATE_CAR_VAL#',
        '#CAR_WT_VAL#',
        '#WEIGHING_IF#',
        '#HEAT_NO#',
        '#BATCH_NO#',
        '#LOGO_NO#',
        '#GROUP_NO#',
        '#MATERIALS_CODE#',
        '#MATERIALS_DESC#',
        '#MATERIALS_SPEC#',
        '#DIMATER_VAL#',
        '#WIDE_VAL#',
        '#HEIGHT_VAL#',
        '#LEN_VAL#',
        '#LEN_MIN_VAL#',
        '#LEN_MAX_VAL#',
        '#UOM_CODE#',
        '#UOM_DESC#',
        '#DEMAND_QTY_VAL#',
        '#DEMAND_WT_VAL#',
        '#OUTPUT_QTY_VAL#',
        '#OUTPUT_WT_VAL#',
        '#OFFLINE_QTY_VAL#',
        '#OFFLINE_WT_VAL#',
        '#SCRAP_QTY_VAL#',
        '#SCRAP_WT_VAL#',
        '#PRO_ORDER_NO#',
        '#PRO_ORDER_SQE#',
        '#CURRENT_JOB_NO#',
        '#PREVIOUS_JOB_NO#',
        '#STATUS#',
        '#MEMO#',
        '#CREATE_USERID#',
        '#CREATE_NAME#',
        TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
        '#LOT_NO#',
        '#MAXIMUM#',
        '#MAT_TYPE#');
        END IF;
        END;
    </query>
    <query id = "writeDemand.cancelWriteDemandPln" desc = "删除运输需求">
        DELETE FROM TMS_DEMAND_M T
        WHERE T.DEMAND_ORG_CODE = '#PLINE_CODE#'
        AND (T.CURRENT_JOB_NO = '#HEAT_PLAN_NO#' OR
        T.CURRENT_JOB_NO = '#UPPER_HEATPLAN_ID#')
    </query>
    <query id = "writeDemand.cancelWriteDemandPlnJg" desc = "删除运输需求">
        DELETE FROM TMS_DEMAND_M T
        WHERE T.DEMAND_NO = '#DEMAND_NO#'
    </query>
    <query id = "writeDemand.selectTmsVlaflg" desc = "查询需求状态">
        SELECT *
        FROM TMS_DEMAND_M T
        WHERE T.DEMAND_ORG_CODE = '#PLINE_CODE#'
        AND (T.CURRENT_JOB_NO = '#HEAT_PLAN_NO#' OR
        T.CURRENT_JOB_NO = '#UPPER_HEATPLAN_ID#')
    </query>
    <query id = "writeDemand.selectTmsVlaflgJg" desc = "查询需求状态">
        SELECT *
        FROM TMS_DEMAND_M T
        WHERE T.CURRENT_JOB_NO = ?
    </query>
    <query id = "writeDemand.getStorageNoUn" desc = "查询装卸点">
        SELECT T.UNLOADING_CODE, T.UNLOADING_DESC
        FROM TMS_COM_UNLOADING T
        WHERE T.UNLOADING_AREA_CODE = ?
        AND T.VALIDFLAG = '1'
    </query>

    <query id= "writeDemand.getNextPline" desc= "查询后工序产线">
        SELECT (CASE
        WHEN T.WHOLE_BACKLOG_DESC LIKE '%镦拔扩%' THEN
        (SELECT MAX(S3.PLINE_CODE)
        FROM PLN_ORDER_DBK_S S3
        WHERE S3.PREV_GXPLAN_ID = T.PRO_PLAN_ID)
        WHEN T.WHOLE_BACKLOG_DESC LIKE '%热处理%' THEN
        (SELECT MAX(S3.PLINE_CODE)
        FROM PLN_ORDER_RCL_S S3
        WHERE S3.PREV_GXPLAN_ID = T.PRO_PLAN_ID)
        WHEN T.WHOLE_BACKLOG_DESC LIKE '%加工%' THEN
        (SELECT  MAX(S3.PLINE_CODE)
        FROM PLN_ORDER_JGX_S S3
        WHERE S3.PREV_GXPLAN_ID = T.PRO_PLAN_ID)
        ELSE
        ''
        END)NEXT_PLINE_CODE
        FROM PLN_ORDER_ZG_S T WHERE T.PRO_PLAN_ID = ? AND T.GX_PLAN_NO = ?
        UNION ALL
        SELECT (CASE
        WHEN T.WHOLE_BACKLOG_DESC LIKE '%热处理%' THEN
        (SELECT MAX(S3.PLINE_CODE)
        FROM PLN_ORDER_RCL_S S3
        WHERE S3.PREV_GXPLAN_ID = T.PRO_PLAN_ID)
        WHEN T.WHOLE_BACKLOG_DESC LIKE '%加工%' THEN
        (SELECT  MAX(S3.PLINE_CODE)
        FROM PLN_ORDER_JGX_S S3
        WHERE S3.PREV_GXPLAN_ID = T.PRO_PLAN_ID)
        ELSE
        ''
        END)NEXT_PLINE_CODE
        FROM PLN_ORDER_DBK_S T WHERE T.PRO_PLAN_ID = ? AND T.GX_PLAN_NO = ?
        UNION ALL
        SELECT (CASE WHEN T.ORD_LN_DLY_PK LIKE '%ZZBY-J%' AND T.WHOLE_BACKLOG_DESC NOT LIKE '%加工%' THEN
        (SELECT MAX(M.PLINE_CODE)
        FROM PLN_GX_JG_M M, PLN_JG_AND_BL B
        WHERE M.PRO_PLAN_ID = B.PRO_PLAN_ID
        AND B.REQ_BL_ID = T.ORD_LN_DLY_PK)
        ELSE
        DECODE(T.ISENDGX,
        '1',
        '',
        (CASE
        WHEN T.WHOLE_BACKLOG_DESC LIKE '%加工%' THEN
        (SELECT
        MAX(S3.PLINE_CODE)
        FROM PLN_ORDER_JGX_S S3
        WHERE S3.PREV_GXPLAN_ID = T.PRO_PLAN_ID)
        ELSE
        ''
        END))END)NEXT_PLINE_CODE
        FROM PLN_ORDER_RCL_S T WHERE T.PRO_PLAN_ID = ? AND T.GX_PLAN_NO = ?
    </query>
    <query id = "writeDemand.getStorageNoUnPline" desc = "根据产线查装卸点">
        SELECT T.UNLOADING_CODE, T.UNLOADING_DESC
        FROM TMS_COM_UNLOADING T
        WHERE T.PLINE_CODE = ?
        AND T.VALIDFLAG = '1'
        AND ROWNUM = 1
    </query>
    <query id = "writeDemand.getCarry" desc = "查询默认承运商单位">
        SELECT T.CARRIER_CODE, T.CARRIER_NAME
        FROM TMS_COM_PLINE T
        WHERE T.PLINE_CODE = ?
    </query>
    <query id = "writeDemand.insertComLine" desc = "生成运输线路">
        <![CDATA[
        DECLARE
        V_COUNT     NUMBER := 0;
        V_LINE_CODE TMS_COM_LINE_M.LINE_CODE%TYPE := NULL;
        V_SEGMENT_CODE TMS_COM_LINE_C.SEGMENT_CODE%TYPE := NULL;
        BEGIN
        SELECT COUNT(1)
        INTO V_COUNT
        FROM TMS_COM_LINE_M T
        WHERE T.START_NODE_CODE = '#START_NODE_CODE#'
        AND T.END_NODE_CODE = '#END_NODE_CODE#'
        AND T.VALIDFLAG = '1';
        SELECT 'XL' || LPAD(NVL(MAX(SUBSTR(T.LINE_CODE, 3)), 0) + 1, 5, 0)
        INTO V_LINE_CODE
        FROM TMS_COM_LINE_M T;
        SELECT 'XD' || LPAD(NVL(MAX(SUBSTR(T1.SEGMENT_CODE, 3)), 0) + 1, 4, 0)
       INTO V_SEGMENT_CODE
       FROM TMS_COM_LINE_C T1
       WHERE T1.LINE_CODE = V_LINE_CODE;
        IF (V_COUNT = 0) THEN
        INSERT INTO TMS_COM_LINE_M
        (CREATE_USERID,
        CREATE_NAME,
        CREATE_TIME,
        UPDATE_USERID,
        UPDATE_NAME,
        UPDATE_TIME,
        DELETE_USERID,
        DELETE_NAME,
        DELETE_TIME,
        LINE_CODE,
        LINE_DESC,
        START_NODE_CODE,
        START_NODE_DESC,
        START_LONGITUDE_VAL,
        START_LATITUDE_VAL,
        END_NODE_CODE,
        END_NODE_DESC,
        END_LONGITUDE_VAL,
        END_LATITUDE_VAL,
        MEMO)
        VALUES
        ('',
        '#CREATE_NAME#',
        TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
        '',
        '',
        '',
        '',
        '',
        '',
        V_LINE_CODE,
        '#LINE_DESC#',
        '#START_NODE_CODE#',
        '#START_NODE_DESC#',
        '#START_LONGITUDE_VAL#',
        '#START_LATITUDE_VAL#',
        '#END_NODE_CODE#',
        '#END_NODE_DESC#',
        '#END_LONGITUDE_VAL#',
        '#END_LATITUDE_VAL#',
        '');
        INSERT INTO TMS_COM_LINE_C
      (SEGMENT_CODE,
       SEGMENT_DESC,
       LINE_CODE,
       SEGMENT_SQE,
       TRANSIT_TYPE_CODE,
       TRANSIT_TYPE_DESC,
       START_NODE_CODE,
       START_NODE_DESC,
       START_LONGITUDE_VAL,
       START_LATITUDE_VAL,
       END_NODE_CODE,
       END_NODE_DESC,
       END_LONGITUDE_VAL,
       END_LATITUDE_VAL,
       CREATE_USERID,
       CREATE_NAME,
       CREATE_TIME)
    VALUES
      (V_SEGMENT_CODE,
       '#SEGMENT_DESC#',
       V_LINE_CODE,
       '1',
       'YST01',
       '公路',
       '#START_NODE_CODE#',
       '#START_NODE_DESC#',
       '1',
       '1',
       '#END_NODE_CODE#',
       '#END_NODE_DESC#',
       '1',
       '1',
       '#CREATE_USERID#',
       '#CREATE_NAME#',
       TO_DATE('#CREATE_TIME#', 'YYYY-MM-DD HH24:MI:SS'));
        END IF;
        END;
        ]]>
    </query>
    <query id = "writeDemand.getMatGpWg" desc = "查询外购坯所在库存地">
        SELECT MAX(S.STORAGE_NO)STORAGE_NO,
        MAX((SELECT S1.STORAGE_NAME
        FROM YDM_BS_STORAGE S1
        WHERE S1.STORAGE_NO = S.STORAGE_NO)) STORAGE_NAME,
        SUM(T.ACT_COUNT) ACT_COUNT,
        SUM(T.ACT_WEIGHT)ACT_WEIGHT,
        MAX(T.DIMATER)DIMATER,
        MAX(T.ACT_LEN)ACT_LEN,
        MAX(T.MATERIAL_NO)MATERIAL_NO,
        MAX(T.MATERIAL_NAME)MATERIAL_NAME,
        MAX(T.PRO_PLAN_ID)PRO_PLAN_ID,
        MAX(T.GX_PLAN_NO)GX_PLAN_NO
        FROM MAT_GP_M T LEFT JOIN YDM_GP_BUTTRESS S
        ON T.MAT_NO = S.MAT_NO
        WHERE T.PRO_PLAN_ID_ZG = ?
        AND T.GX_PLAN_NO_ZG = ?
        AND T.JUDGE_STOVE_NO = ?
        AND T.QCM_STAUS = '00'
    </query>
    <query id = "writeDemand.getMaxWgt" desc = "查询最大吊勾量">
        SELECT T.MAX_WGT FROM YDM_BS_MAXWGT T WHERE T.STORAGE_NO = ?AND T.UNLOADING_CODE = ?
    </query>
</queryMap>