<?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
        WHERE T.TRAN_CLASS_CODE  = ?
    </query>
    <query id = "writeDemand.insertDemand" desc = "插入运输需求">
        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,
        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#',
        '#MAT_TYPE#'
        )
    </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 = "writeOutDemand.selectPlineCode" desc = "查询投料库对应的产线">
        SELECT T.PLINE_CODE,T.PLINE_NAME FROM COM_BASE_PLINE T WHERE T.IN_REPOSITORY = ?
    </query>
    <query id = "writeOutDemand.selectStorageType" desc = "查询库类型">
        SELECT T.STORAGE_ATTR FROM YDM_BS_STORAGE T WHERE T.STORAGE_NO = ?
    </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 = "writeOutDemand.deleteDemand" desc = "删除运输需求">
        DELETE FROM TMS_DEMAND_M T WHERE T.DEMAND_NO = '#DEMAND_NO#'
    </query>
    <query id = "writeOutDemand.SelectDemand" desc = "查询运输需求">
        SELECT T.VALIDFLAG,T.CREATE_NAME FROM TMS_DEMAND_M T WHERE T.DEMAND_NO = '#DEMAND_NO#'
    </query>
</queryMap>