<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="需求管理">
    <query id="TmsDemand.doQuery" desc="查询需求">
        <![CDATA[

  select  M.DEMAND_NO,
    NVL(C.PLN_QTY_VAL,0)  PLAN_QTY_VAL ,NVL(C.PLN_WT_VAL,0) PLAN_WT_VAL,
    NVL(M.DEMAND_QTY_VAL,0) - NVL(C.PLN_QTY_VAL,0) UN_PLAN_QTY_VAL,
    NVL(M.DEMAND_WT_VAL,0) - NVL(C.PLN_WT_VAL,0) UN_PLAN_WT_VAL,


     NVL(WC.SUM_WAYBILL_QTY,0)  SUM_WAYBILL_QTY ,NVL(WC.SUM_WAYBILL_WT,0) SUM_WAYBILL_WT,
      NVL(M.DEMAND_QTY_VAL,0) - NVL(WC.SUM_WAYBILL_QTY,0) CAN_PLAN_QTY_VAL,
    NVL(M.DEMAND_WT_VAL,0) - NVL(WC.SUM_WAYBILL_WT,0) CAN_PLAN_WT_VAL,

    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_CHAR(TRANSPORT_START_TIME,'YYYY-MM-DD HH24:MI') TRANSPORT_START_TIME,
    TO_CHAR(TRANSPORT_END_TIME,'YYYY-MM-DD HH24:MI') 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, SOURCE_SIGN, VALIDFLAG, STATUS, ACCOUNT_YEAR_MONTH,
    ARCHIVE_FLAG, ARCHIVE_NO, ARCHIVE_DATE, MEMO, CREATE_USERID, CREATE_NAME, CREATE_TIME,
    UPDATE_USERID, UPDATE_NAME, UPDATE_TIME, DELETE_USERID, DELETE_NAME, DELETE_TIME,
    COST_COUNT,LOAD_TIME,LOT_NO,IS_SURE,MAT_TYPE
    from TMS_DEMAND_M M
    LEFT JOIN
    (SELECT C.DEMAND_NO,SUM(C.PLN_QTY_VAL) PLN_QTY_VAL,SUM(C.PLN_WT_VAL) PLN_WT_VAL FROM TMS_PLN_C C,
    TMS_PLN_M M WHERE M.PLN_NO = C.PLN_NO AND M.VALIDFLAG!='00' AND C.DEMAND_NO IS NOT NULL  GROUP BY DEMAND_NO) C
    ON M.DEMAND_NO = C.DEMAND_NO
      LEFT JOIN
    (SELECT DEMAND_NO, SUM(WC.WAYBILL_QTY_VAL) SUM_WAYBILL_QTY , SUM(WC.WAYBILL_WT_VAL) SUM_WAYBILL_WT
  FROM TMS_PLN_M M, TMS_PLN_C C, TMS_WAYBILL_C WC
 WHERE M.PLN_NO = C.PLN_NO
   AND M.VALIDFLAG != '00'
   AND WC.PLN_NO = M.PLN_NO
   AND WC.HEAT_NO = C.HEAT_NO
 GROUP BY C.DEMAND_NO) WC  ON M.DEMAND_NO = WC.DEMAND_NO

    WHERE 1=1
        ]]>
    </query>

    <query id="TmsDemand.doQueryPln" desc="查询计划">
        <![CDATA[
       SELECT M.* ,NVL(D.WAYBIL_QTY,0) WAYBIL_QTY,NVL(D.WAYBIL_WT,0) WAYBIL_WT,
    NVL(D.WAYBIL_COUNT,0) WAYBIL_COUNT,NVL(D.WAYBIL_COMPLETE_COUNT,0) WAYBIL_COMPLETE_COUNT,
    C.PLN_QTY_VAL, C.PLN_WT_VAL,
         (SELECT  DRIVER_NAME FROM TMS_COM_DRIVER WHERE DRIVER_CODE = M.DRIVER_CODE) DRIVER_NAME
    from TMS_PLN_M M
    LEFT JOIN (
    SELECT  PLN_NO , SUM(PLN_QTY_VAL) PLN_QTY_VAL,
    SUM(PLN_WT_VAL) PLN_WT_VAL
    FROM TMS_PLN_C GROUP BY PLN_NO
     ) C ON M.PLN_NO = C.PLN_NO
    LEFT JOIN
    (SELECT  B.PLN_NO , SUM(A.WAYBILL_QTY_VAL) WAYBIL_QTY,
    SUM(A.WAYBILL_WT_VAL) WAYBIL_WT,
    COUNT(DISTINCT B.WAYBILL_NO) WAYBIL_COUNT,
    COUNT(DISTINCT CASE
    WHEN B.VALIDFLAG IN ('60','70') THEN
    B.WAYBILL_NO
    ELSE
    NULL
    END) WAYBIL_COMPLETE_COUNT
    FROM  TMS_WAYBILL_M B LEFT JOIN TMS_WAYBILL_C  A ON A.WAYBILL_NO = B.WAYBILL_NO
    WHERE  B.VALIDFLAG != '00'
    GROUP BY B.PLN_NO) D ON M.PLN_NO = D.PLN_NO
    WHERE 1=1

        ]]>
    </query>



    <query id="TmsDemand.doQueryPlnC" desc="查询计划">
        <![CDATA[
        SELECT * FROM TMS_PLN_C M WHERE 1=1

        ]]>
    </query>


    <query id="TmsDemand.doQueryWaybill" desc="查询运单">
        <![CDATA[
     SELECT M.* FROM TMS_WAYBILL_M M
    WHERE 1=1

        ]]>
    </query>

    <query id="TmsDemand.doQueryStation" desc="查询需求">
        <![CDATA[

  select  *
    from TMS_COM_UNLOADING M
    WHERE VALIDFLAG = 1
    ORDER BY UNLOADING_DESC
        ]]>
    </query>

    <query id="TmsDemand.close" desc="关闭需求">
        <![CDATA[

  UPDATE  TMS_DEMAND_M SET  VALIDFLAG ='50',
      DELETE_NAME = ?,
       DELETE_TIME = SYSDATE
    WHERE 1=1 AND
    VALIDFLAG IN ('10','20','30','40')

        ]]>
    </query>


    <query id="TmsDemand.recover" desc="还原需求">
        <![CDATA[
UPDATE TMS_DEMAND_M M
    SET VALIDFLAG = DECODE((SELECT COUNT(1)
    FROM TMS_PLN_C
    WHERE DEMAND_NO = M.DEMAND_NO),
    0,
    '20',
    '30')，
     UPDATE_NAME = ?,
       UPDATE_TIME = SYSDATE
    WHERE M.VALIDFLAG = '50'

        ]]>
    </query>

    <query id="TmsDemand.updateDate" desc="还原需求">
        <![CDATA[
UPDATE TMS_DEMAND_M M
    SET TRANSPORT_START_TIME = TO_DATE(?, 'YYYY-MM-DD HH24:MI'),
      TRANSPORT_END_TIME = TO_DATE(?, 'YYYY-MM-DD HH24:MI'),
      START_NODE_CODE =?,
      START_NODE_DESC =?,
      START_AREA_CODE=?,
      START_AREA_DESC = ?,
      END_NODE_CODE = ?,
      END_NODE_DESC=?,
      END_AREA_CODE=?,
      END_AREA_DESC=?,
      MEMO=?,
        UPDATE_NAME = ?,
       UPDATE_TIME = SYSDATE
    WHERE DEMAND_NO = ?
        ]]>
    </query>


    <query id="TmsDemand.updatePln" desc="调整已派计划卸点">
        <![CDATA[
UPDATE TMS_PLN_M M
    SET
      END_NODE_CODE = ?,
      END_NODE_DESC=?,
      END_AREA_CODE=?,
      END_AREA_DESC=?,
      LINE_CODE=?,
      LINE_DESC=?,
      UPDATE_NAME = ?,
      UPDATE_TIME = SYSDATE
    WHERE PLN_NO = ?
        ]]>
    </query>


    <query id="TmsDemand.updatePlnC" desc="调整已派计划卸点">
        <![CDATA[
UPDATE TMS_PLN_C M
    SET
      END_NODE_CODE = ?,
      END_NODE_DESC=?,
      END_AREA_CODE=?,
      END_AREA_DESC=?
    WHERE PLN_NO = ?
        ]]>
    </query>


    <query id="TmsDemand.updateWaybillC" desc="调整已派计划卸点">
        <![CDATA[
UPDATE TMS_WAYBILL_C M
    SET
      END_NODE_CODE = ?,
      END_NODE_DESC=?,
      END_AREA_CODE=?,
      END_AREA_DESC=?
    WHERE WAYBILL_NO = ?
        ]]>
    </query>

    <query id="TmsDemand.updateWaybill" desc="调整运单线路卸点">
        <![CDATA[
UPDATE TMS_WAYBILL_M M
    SET
      LINE_CODE=?,
      LINE_DESC=?,
      UPDATE_NAME = ?,
      UPDATE_TIME = SYSDATE
    WHERE WAYBILL_NO = ?
        ]]>
    </query>

    <query id="TmsDemand.updateFlag" desc="还原需求">
        <![CDATA[
UPDATE TMS_DEMAND_M M
       SET TRANSPORT_START_TIME = TO_DATE(?, 'YYYY-MM-DD HH24:MI'),
      TRANSPORT_END_TIME = TO_DATE(?, 'YYYY-MM-DD HH24:MI'),
      START_NODE_CODE =?,
      START_NODE_DESC =?,
      START_AREA_CODE=?,
      START_AREA_DESC = ?,
      END_NODE_CODE = ?,
      END_NODE_DESC=?,
      END_AREA_CODE=?,
      END_AREA_DESC=?,
      MEMO=?,
        IS_SURE= ?,
       UPDATE_NAME = ?,
       UPDATE_TIME = SYSDATE
       WHERE DEMAND_NO = ?
        ]]>
    </query>

    <query id="TmsDemand.selectGroupMat" desc="查询库存">
        <![CDATA[
   SELECT M.JUDGE_STOVE_NO,
           M.BATCH_NO,
           M.FLAG_STOVE_NO_ZG,
           DECODE(M.QCM_STAUS,
                  '00',
                  '合格',
                  '11',
                  '待处理',
                  '22',
                  '废品',
                  '') QCM_STAUS,
           G.STORAGE_NAME,
           SUM(M.ACT_COUNT) ACT_COUNT,
           SUM(M.ACT_WEIGHT) ACT_WEIGHT,
           M.PLINE_NAME,
           NULL FIX_NUM,
           NULL FIX_LEN
      FROM MAT_BC_M M, YDM_BC_BUTTRESS B
      LEFT JOIN YDM_BS_STORAGE G
        ON B.STORAGE_NO = G.STORAGE_NO
     WHERE M.MAT_NO = B.MAT_NO
       AND M.JUDGE_STOVE_NO = '#{flagStoveNo}'
     GROUP BY M.FLAG_STOVE_NO_ZG,
              M.JUDGE_STOVE_NO,
              M.BATCH_NO,
              M.QCM_STAUS,
                M.PLINE_NAME,
              G.STORAGE_NAME
    UNION ALL
    SELECT 
           M.JUDGE_STOVE_NO,
           M.BATCH_NO,
            M.FLAG_STOVE_NO_ZG,
           '成品' QCM_STAUS,
           G.STORAGE_NAME,
           SUM(M.ACT_COUNT) ACT_COUNT,
           SUM(M.ACT_WEIGHT) ACT_WEIGHT,
             M.PLINE_NAME,
           NULL FIX_NUM,
           NULL FIX_LEN
      FROM MAT_ZC_M M, YDM_ZC_BUTTRESS B
      LEFT JOIN YDM_BS_STORAGE G
        ON B.STORAGE_NO = G.STORAGE_NO
     WHERE M.MAT_NO = B.MAT_NO
       AND M.JUDGE_STOVE_NO = '#{flagStoveNo}'
     GROUP BY M.FLAG_STOVE_NO_ZG,
              M.JUDGE_STOVE_NO,
              G.STORAGE_NAME,
                M.PLINE_NAME,
              M.BATCH_NO
    UNION ALL
    SELECT M.JUDGE_STOVE_NO,
           NULL,
           M.JUDGE_STOVE_NO,
           DECODE(M.QCM_STAUS,
                  '00',
                  '合格',
                  '11',
                  '待处理',
                  '22',
                  '废品',
                  '') QCM_STAUS,
           G.STORAGE_NAME,
           SUM(M.ACT_COUNT) ACT_COUNT,
           SUM(M.ACT_WEIGHT) ACT_WEIGHT,
             M.PLINE_NAME,
           M.FIX_NUM,
           M.FIX_LEN
      FROM MAT_GP_M M, YDM_GP_BUTTRESS B
      LEFT JOIN YDM_BS_STORAGE G
        ON B.STORAGE_NO = G.STORAGE_NO
     WHERE M.MAT_NO = B.MAT_NO
       AND M.JUDGE_STOVE_NO = '#{flagStoveNo}'
     GROUP BY M.JUDGE_STOVE_NO,
              G.STORAGE_NAME,
              QCM_STAUS,
              M.FIX_NUM,
                M.PLINE_NAME,
              M.FIX_LEN

        ]]>
    </query>


    <query id="TmsDemand.queryCar" desc="查询承运人车辆信息">
        <![CDATA[


    SELECT B.CAR_LICENSE ID,
    B.CAR_LICENSE,
    NVL(D.UNDONE_COUNT, 0) UNDONE_COUNT,
    NVL(D.UNDONE_QTY_VAL, 0) UNDONE_QTY_VAL,
    NVL(D.UNDONE_WT_VAL, 0) UNDONE_WT_VAL,
    CAR_TYPE_CODE,
    CAR_TYPE_DESC,
    CAR_STATUS_CODE,
    CAR_STATUS_DESC,
    TRANS_STATUS_CODE,
    TRANS_STATUS_DESC,
    CARRIER_CODE,
    CARRIER_NAME,
    CAR_PROPERTY_CODE,
    CAR_PROPERTY_DESC,
    CAR_LEN_VAL,
    CAR_WID_VAL,
    CAR_HIG_VAL,
    CAR_WT_VAL,
    CAR_MAP_PATH,
    ENGINE_NO,
    FRAME_NO,
    PURCHASE_DATE,
    PURCHASE_PRICE,
    OIL_CODE,
    OIL_DESC,
    FUEL_CONSUMPTION,
    DEPRECIATION_PRICE,
    MAINTENANCE_LEGEND_CYCLE,
    MAINTENANCE_DATE_CYCLE,
    TYRE_NM,
    VALIDFLAG,
    MEMO,
    CREATE_USERID,
    CREATE_NAME,
    CREATE_TIME,
    UPDATE_USERID,
    UPDATE_NAME,
    UPDATE_TIME,
    DELETE_USERID,
    DELETE_NAME,
    DELETE_TIME,
    CAR_NO,
    CAR_DISPLACEMENT,
    DRIVING_NO,
    CAR_BRAND_CODE,
    CAR_BRAND_NAME,
    TIPS_DATE,
    EXAMINATION_DATE,
    NEXT_EXAMINATION_DATE
    FROM TMS_CAR_BASE B
    LEFT JOIN (SELECT M.CAR_LICENSE,
    SUM(C.PLN_QTY_VAL) UNDONE_QTY_VAL,
    SUM(C.PLN_WT_VAL) UNDONE_WT_VAL,
    COUNT(DISTINCT M.PLN_NO) UNDONE_COUNT
    FROM TMS_PLN_M M, TMS_PLN_C C
    WHERE M.PLN_NO = C.PLN_NO
    AND M.VALIDFLAG IN ('30', '20')
    GROUP BY M.CAR_LICENSE) D
    ON B.CAR_LICENSE = D.CAR_LICENSE
    WHERE CAR_TYPE_CODE = 'CAR01'
    AND CAR_STATUS_CODE = 'CST01'
    AND VALIDFLAG = '1'
    ORDER BY CAR_LICENSE
        ]]>
    </query>


    <query id="TmsDemand.getCarByKey" desc="查询承运人车辆信息">
        <![CDATA[


    SELECT B.CAR_LICENSE ID,
    B.CAR_LICENSE,
    NVL(D.UNDONE_COUNT, 0) UNDONE_COUNT,
    NVL(D.UNDONE_QTY_VAL, 0) UNDONE_QTY_VAL,
    NVL(D.UNDONE_WT_VAL, 0) UNDONE_WT_VAL,
    CAR_TYPE_CODE,
    CAR_TYPE_DESC,
    CAR_STATUS_CODE,
    CAR_STATUS_DESC,
    TRANS_STATUS_CODE,
    TRANS_STATUS_DESC,
    CARRIER_CODE,
    CARRIER_NAME,
    CAR_PROPERTY_CODE,
    CAR_PROPERTY_DESC,
    CAR_LEN_VAL,
    CAR_WID_VAL,
    CAR_HIG_VAL,
    CAR_WT_VAL,
    CAR_MAP_PATH,
    ENGINE_NO,
    FRAME_NO,
    PURCHASE_DATE,
    PURCHASE_PRICE,
    OIL_CODE,
    OIL_DESC,
    FUEL_CONSUMPTION,
    DEPRECIATION_PRICE,
    MAINTENANCE_LEGEND_CYCLE,
    MAINTENANCE_DATE_CYCLE,
    TYRE_NM,
    VALIDFLAG,
    MEMO,
    CREATE_USERID,
    CREATE_NAME,
    CREATE_TIME,
    UPDATE_USERID,
    UPDATE_NAME,
    UPDATE_TIME,
    DELETE_USERID,
    DELETE_NAME,
    DELETE_TIME,
    CAR_NO,
    CAR_DISPLACEMENT,
    DRIVING_NO,
    CAR_BRAND_CODE,
    CAR_BRAND_NAME,
    TIPS_DATE,
    EXAMINATION_DATE,
    NEXT_EXAMINATION_DATE,
     (SELECT
      LISTAGG(DEMAND_ORG_CODE, ',') WITHIN GROUP(ORDER BY DEMAND_ORG_CODE) DEMAND_ORG_CODE
    FROM TMS_DRIVER_CAR_DEMAND D WHERE D.CAR_LICENSE = B.CAR_LICENSE)  DEMAND_LIST_STR
    FROM TMS_CAR_BASE B
    LEFT JOIN (SELECT M.CAR_LICENSE,
    SUM(C.PLN_QTY_VAL) UNDONE_QTY_VAL,
    SUM(C.PLN_WT_VAL) UNDONE_WT_VAL,
    COUNT(DISTINCT M.PLN_NO) UNDONE_COUNT
    FROM TMS_PLN_M M, TMS_PLN_C C
    WHERE M.PLN_NO = C.PLN_NO
    AND M.VALIDFLAG IN ('30', '20')
    GROUP BY M.CAR_LICENSE) D
    ON B.CAR_LICENSE = D.CAR_LICENSE
    WHERE B.CAR_LICENSE = ?
        ]]>
    </query>

    <query id="TmsDemand.getRule" desc="获取规则">
        <![CDATA[
    SELECT * FROM TMS_COM_RULE WHERE RULE_CLASS_CODE= ? AND VALIDFLAG= '1'
        ]]>
    </query>

    <query id="TmsDemand.GetNewID" desc="根据规则生成计划号">
        <![CDATA[
    SELECT ? || TO_CHAR(SYSDATE,'YYYYMMDD' ) ||
        LPAD(NVL(MAX(TO_NUMBER(SUBSTR(PLN_NO, LENGTH(PLN_NO) - 4))),
        0) + 1,
        5,
        '0') PLN_NO
        FROM TMS_PLN_M
        WHERE PLN_NO LIKE ? || TO_CHAR(SYSDATE,'YYYYMMDD' )  ||  '_____'
        ]]>
    </query>

    <query id="TmsDemand.GetLine" desc="">
      SELECT M.*,
        A.UNLOADING_AREA_CODE START_AREA_CODE,
        A.UNLOADING_AREA_DESC START_AREA_DESC,
        B.UNLOADING_AREA_CODE END_AREA_CODE,
        B.UNLOADING_AREA_DESC END_AREA_DESC
        FROM TMS_COM_LINE_M M
        LEFT JOIN TMS_COM_UNLOADING A
        ON M.START_NODE_CODE = A.UNLOADING_CODE
        LEFT JOIN TMS_COM_UNLOADING B
        ON M.END_NODE_CODE = B.UNLOADING_CODE
        WHERE 1= 1
    </query>


    <query id="TmsDemand.insertPlnM">
        INSERT INTO TMS_PLN_M(
        PLN_NO,
        PLN_DESC,
        URGENCY_TYPE_CODE,
        URGENCY_TYPE_DESC,
        TRAN_CLASS_CODE,
        TRAN_CLASS_DESC,
        COST_TYPE_CODE,
        COST_TYPE_DESC,
        DEMAND_ORG_CODE,
        DEMAND_ORG_DESC,
        LINE_CODE,
        LINE_DESC,
        START_NODE_CODE,
        START_NODE_DESC,
        END_NODE_CODE,
        END_NODE_DESC,
        START_AREA_CODE,
        START_AREA_DESC,
        END_AREA_DESC,
        END_AREA_CODE,
        TRANSPORT_START_TIME,
        TRANSPORT_END_TIME,
        CAR_USE_CODE,
        CAR_USE_DESC,
        CAR_TYPE_CODE,
        CAR_TYPE_DESC,
        CARRIER_CODE,
        CARRIER_NAME,
        CAR_LICENSE,
        CAR_ASSIGN_TIME,
        DRIVER_CODE,
        RECEIVING_TIME,
        WEIGHING_IF,
        SOURCE_SIGN,
        VALIDFLAG,
        STATUS,
        MEMO,
        CREATE_USERID,
        CREATE_NAME,
        CREATE_TIME,
        COST_COUNT)
        VALUES(
        '#PLN_NO#',
        '#PLN_DESC#',
        '#URGENCY_TYPE_CODE#',
        '#URGENCY_TYPE_DESC#',
        '#TRAN_CLASS_CODE#',
        '#TRAN_CLASS_DESC#',
        '#COST_TYPE_CODE#',
        '#COST_TYPE_DESC#',
        '#DEMAND_ORG_CODE#',
        '#DEMAND_ORG_DESC#',
        '#LINE_CODE#',
        '#LINE_DESC#',
        '#START_NODE_CODE#',
        '#START_NODE_DESC#',
        '#END_NODE_CODE#',
        '#END_NODE_DESC#',
        '#START_AREA_CODE#',
        '#START_AREA_DESC#',
        '#END_AREA_DESC#',
        '#END_AREA_CODE#',
        SYSDATE,
        SYSDATE,
        '#CAR_USE_CODE#',
        '#CAR_USE_DESC#',
        '#CAR_TYPE_CODE#',
        '#CAR_TYPE_DESC#',
        '#CARRIER_CODE#',
        '#CARRIER_NAME#',
        '#CAR_LICENSE#',
        SYSDATE,
        '#DRIVER_CODE#',
        null,
        '#WEIGHING_IF#',
        '#SOURCE_SIGN#',
        '#VALIDFLAG#',
        '#STATUS#',
        '#MEMO#',
        '#CREATE_USERID#',
        '#CREATE_NAME#',
        SYSDATE,
        '#COST_COUNT#')

    </query>


    <query id="TmsDemand.insertPlnC">

        INSERT INTO TMS_PLN_C(
        PLN_NO,
        PLN_SQE,
        DEMAND_NO,
        REFE_NO,
        HEAT_NO,
        BATCH_NO,
        LOGO_NO,
        GROUP_NO,
        MATERIALS_CODE,
        MATERIALS_DESC,
        MATERIALS_SPEC,
        PLN_QTY_VAL,
        PLN_WT_VAL,
        UOM_CODE,
        UOM_DESC,
        PRO_ORDER_NO,
        PRO_ORDER_SQE,
        CURRENT_JOB_NO,
        PREVIOUS_JOB_NO,
        MEMO,

        MEMO2,
        CREATE_USERID,
        CREATE_NAME,
        CREATE_TIME,
        START_NODE_CODE,
        START_NODE_DESC,
        END_NODE_CODE,
        END_NODE_DESC,
        START_AREA_CODE,
        START_AREA_DESC,
        END_AREA_DESC,
        END_AREA_CODE
      )
        VALUES(
        '#PLN_NO#',
        '#PLN_SQE#',
        '#DEMAND_NO#',
        '#REFE_NO#',
        '#HEAT_NO#',
        '#BATCH_NO#',
        '#LOGO_NO#',
        '#GROUP_NO#',
        '#MATERIALS_CODE#',
        '#MATERIALS_DESC#',
        '#MATERIALS_SPEC#',
        '#PLN_QTY_VAL#',
        '#PLN_WT_VAL#',
        '#UOM_CODE#',
        '#UOM_DESC#',
        '#PRO_ORDER_NO#',
        '#PRO_ORDER_SQE#',
        '#CURRENT_JOB_NO#',
        '#PREVIOUS_JOB_NO#',
        '#MEMO#',

        '#MEMO2#',
        '#CREATE_USERID#',
        '#CREATE_NAME#',
        SYSDATE,
        '#START_NODE_CODE#',
        '#START_NODE_DESC#',
        '#END_NODE_CODE#',
        '#END_NODE_DESC#',
        '#START_AREA_CODE#',
        '#START_AREA_DESC#',
        '#END_AREA_DESC#',
        '#END_AREA_CODE#')
    </query>



    <query id ="TmsDemand.updateEndPlnC">
        <![CDATA[
        UPDATE TMS_PLN_C T
     SET T.PLN_QTY_VAL =
         (SELECT SUM(C.WAYBILL_QTY_VAL)
            FROM TMS_WAYBILL_M M, TMS_WAYBILL_C C
           WHERE M.WAYBILL_NO = C.WAYBILL_NO
              AND C.HEAT_NO = T.HEAT_NO
             AND M.VALIDFLAG != '00'
             AND T.PLN_NO = C.PLN_NO),
         T.PLN_WT_VAL =
         (SELECT SUM(C.WAYBILL_WT_VAL)
            FROM TMS_WAYBILL_M M, TMS_WAYBILL_C C
           WHERE M.WAYBILL_NO = C.WAYBILL_NO
              AND C.HEAT_NO = T.HEAT_NO
             AND M.VALIDFLAG != '00'
             AND T.PLN_NO = C.PLN_NO)
   WHERE T.PLN_NO = ?
 ]]>
    </query>

    <query id ="TmsDemand.updateDemand">
        <![CDATA[
       UPDATE TMS_DEMAND_M D
        SET VALIDFLAG = DECODE((SELECT MIN(M.VALIDFLAG)
        FROM TMS_PLN_C C, TMS_PLN_M M
        WHERE M.PLN_NO = C.PLN_NO
        AND M.VALIDFLAG != '00'
        AND C.DEMAND_NO = D.DEMAND_NO),
        NULL,
        '20',
        '30',
        '30',
        '20',
        '30',
        '40',
        (CASE
        WHEN NVL(D.DEMAND_QTY_VAL, 0)  <=
        NVL((SELECT SUM(PLN_QTY_VAL)
        FROM TMS_PLN_C C, TMS_PLN_M M
        WHERE M.PLN_NO = C.PLN_NO
        AND M.VALIDFLAG != '00'
        AND C.DEMAND_NO = D.DEMAND_NO),
        0) THEN
        '40'
        ELSE
        '30'
        END),
        '50',
        (CASE
        WHEN NVL(D.DEMAND_QTY_VAL, 0)  <=
        NVL((SELECT SUM(PLN_QTY_VAL)
        FROM TMS_PLN_C C, TMS_PLN_M M
        WHERE M.PLN_NO = C.PLN_NO
        AND M.VALIDFLAG != '00'
        AND C.DEMAND_NO = D.DEMAND_NO),
        0) THEN
        '40'
        ELSE
        '30'
        END))
        WHERE 1=1
            AND DEMAND_NO IN (SELECT DEMAND_NO FROM  TMS_PLN_C WHERE PLN_NO = ?)

 ]]>
    </query>


    <query id ="TmsDemand.updateCar">
        UPDATE TMS_CAR_BASE T
        SET TRANS_STATUS_CODE = DECODE((SELECT MAX(VALIDFLAG) VALIDFLAG
        FROM TMS_PLN_M M
        WHERE M.CAR_LICENSE IS NOT NULL
        AND M.CAR_LICENSE = T.CAR_LICENSE
        AND M.VALIDFLAG IN ('20', '30')),
        '30',
        'YS03',
        '20',
        'YS02',
        DECODE((SELECT COUNT(1)  FROM TMS_DRIVER_CAR WHERE CAR_LICENSE =
        T.CAR_LICENSE AND DRIVER_CODE IS NOT NULL)
        ,0,'YS00','YS01'
        )),
        TRANS_STATUS_DESC = DECODE((SELECT MAX(VALIDFLAG) VALIDFLAG
        FROM TMS_PLN_M M
        WHERE M.CAR_LICENSE IS NOT NULL
        AND M.CAR_LICENSE = T.CAR_LICENSE
        AND M.VALIDFLAG IN ('20', '30')),
        '30',
        (SELECT BASE_NAME FROM TMS_COM_INFO WHERE BASE_CODE = 'YS03'),
        '20',
        (SELECT BASE_NAME FROM TMS_COM_INFO WHERE BASE_CODE = 'YS02'),

        DECODE((SELECT COUNT(1)  FROM TMS_DRIVER_CAR WHERE CAR_LICENSE =
        T.CAR_LICENSE AND DRIVER_CODE IS NOT NULL)
        ,0,
        (SELECT BASE_NAME FROM TMS_COM_INFO WHERE BASE_CODE = 'YS00')
        ,  (SELECT BASE_NAME FROM TMS_COM_INFO WHERE BASE_CODE = 'YS01')
        )),
        PLN_NO = (SELECT MAX(PLN_NO) FROM  TMS_PLN_M WHERE CAR_LICENSE = T.CAR_LICENSE AND VALIDFLAG ='30')
        WHERE   CAR_LICENSE = ?
    </query>


    <query id="TmsDemand.GetMessageNo" desc="">
        <![CDATA[
  SELECT  TO_CHAR(SYSDATE,'YYYYMMDD' ) ||
    LPAD(NVL(MAX(TO_NUMBER(SUBSTR(MESSAGE_NO, LENGTH(MESSAGE_NO) - 4))),
    0) + 1,
    5,
    '0') MESSAGE_NO
    FROM TMS_DISPATCH_MESSAGE
    WHERE MESSAGE_NO LIKE  TO_CHAR(SYSDATE,'YYYYMMDD' )  ||  '_____'
        ]]>
    </query>

    <query id="TmsDemand.InsertMessageM">
        INSERT INTO TMS_DISPATCH_MESSAGE
        (MESSAGE_NO,
        MESSAGE_TITLE,
        MESSAGE_LEVEL_CODE,
        MESSAGE_LEVEL_DESC,
        MESSAGE_CLASS_CODE,
        MESSAGE_CLASS_DESC,
        MESSAGE_CONTENT,
        MESSAGE_PATH,
        RELEASE_ORG_CODE,
        RELEASE_ORG_DESC,
        RELEASE_USERID,
        RELEASE_NAME,
        RELEASE_TIME,
        VALIDFLAG,
        MEMO,
        CREATE_USERID,
        CREATE_NAME,
        CREATE_TIME)
        VALUES
        (?,
        ?,
        'L1',
        '*',
        'XF04',
        '计划分派',
        ?,
        NULL,
        NULL,
        NULL,
        NULL,
        ?,
        SYSDATE,
        '20',
        '产销分派',
        '',
        ?,
        SYSDATE)


    </query>

    <query  id="TmsDemand.InsertMessageTarget">
        <![CDATA[
        INSERT INTO TMS_DISPATCH_TARGET
        (MESSAGE_NO, TARGET_CODE, TARGET_NAME, TARGET_TYPE)
        VALUES
        (?, ?, NULL, '30')
             ]]>
    </query>

    <query id ="TmsDemand.InsertMessageUser">
        INSERT INTO TMS_DISPATCH_USER
        (MESSAGE_NO,
        TARGET_USERID,
        TARGET_NAME,
        READ_TIME,
        VALIDFLAG,
        TARGET_LOGO)
        SELECT
        ?, DRIVER_CODE, (SELECT DRIVER_NAME FROM TMS_COM_DRIVER WHERE DRIVER_CODE = C.DRIVER_CODE),NULL,'00',NULL
        FROM TMS_DRIVER_CAR C WHERE CAR_LICENSE = ?

        UNION ALL
        SELECT ?, C.DRIVER_CODE, C.DRIVER_NAME, NULL, '00', NULL
        FROM TMS_SCHEDULING_C C
        WHERE VALIDFLAG = '10'
        AND C.CAR_LICENSE = ?
        AND EXISTS
        (SELECT 1
        FROM TMS_SCHEDULING_M
        WHERE CLASS_NO = C.CLASS_NO
        AND VALIDFLAG = '1'
        AND SYSDATE BETWEEN PRO_START_TIME AND PRO_END_TIME)
        AND NOT EXISTS (SELECT 1 FROM tms_driver_car WHERE CAR_LICENSE = c.car_license)



    </query>

    <query id ="TmsDemand.completePlan">
        update TMS_PLN_M
        set
        VALIDFLAG = '40',
        UPDATE_NAME = ?,
        UPDATE_TIME = SYSDATE
        where PLN_NO = ?
    </query>

    <query id ="TmsDemand.closePlan">
        update TMS_PLN_M
        set
        VALIDFLAG = '00',
        UPDATE_NAME = ?,
        UPDATE_TIME = SYSDATE
        where PLN_NO = ?
    </query>

    <query id ="TmsDemand.doQueryPline">
        SELECT * FROM COM_BASE_PLINE WHERE PLINE_CODE=?
    </query>


    <query id ="TmsDemand.doQueryLoad">
        SELECT SUM(ACT_COUNT) ACT_COUNT, SUM(ACT_WEIGHT) ACT_WEIGHT
        FROM (SELECT ACT_COUNT, ACT_WEIGHT
        FROM YDM_BC_OUTLIST T
        WHERE T.OUTSTOCK_PLAN_NO = ?
        AND OUTSTOCK_TYPE_CODE = '800809'
        UNION ALL
        SELECT ACT_COUNT, ACT_WEIGHT
        FROM YDM_GP_OUTLIST T
        WHERE T.OUTSTOCK_PLAN_NO = ?
        AND OUTSTOCK_TYPE_CODE = '800809')
    </query>


    <query id ="TmsDemand.doQueryOut">

        SELECT SUM(ACT_COUNT) ACT_COUNT, SUM(ACT_WEIGHT) ACT_WEIGHT
        FROM (SELECT ACT_COUNT, ACT_WEIGHT
        FROM YDM_BC_INLIST T
        WHERE INSTOCK_TYPE_CODE = '800701'
        AND T.JUDGE_STOVE_NO = ?
        AND PLINE_CODE = ?
        UNION ALL
        SELECT ACT_COUNT, ACT_WEIGHT
        FROM YDM_GP_INLIST T
        WHERE INSTOCK_TYPE_CODE = ?
        AND T.JUDGE_STOVE_NO =?
        AND PLINE_CODE = 'C010')

    </query>


    <query id ="TmsDemand.doQueryUnLoad">
        SELECT SUM(ACT_COUNT) ACT_COUNT, SUM(ACT_WEIGHT) ACT_WEIGHT
        FROM (SELECT ACT_COUNT, ACT_WEIGHT
        FROM MAT_BC_M M, YDM_BC_BUTTRESS B
        WHERE M.MAT_NO = B.MAT_NO
        AND B.STORAGE_NO = ?
        AND M.HEAT_PLAN_NO_NEXT = ?
        UNION ALL
        SELECT ACT_COUNT, ACT_WEIGHT
        FROM MAT_GP_M M, YDM_GP_BUTTRESS B
        WHERE M.MAT_NO = B.MAT_NO
        AND B.STORAGE_NO = ?
        AND M.HEAT_PLAN_NO_NEXT = ?
        )


    </query>

    <query id ="TmsDemand.doQueryNeedTransport">
        SELECT SUM(ACT_COUNT) ACT_COUNT, SUM(ACT_WEIGHT) ACT_WEIGHT,MAX(STORAGE_NO) STORAGE_NO
        FROM (SELECT ACT_COUNT, ACT_WEIGHT, B.STORAGE_NO
        FROM MAT_BC_M M, YDM_BC_BUTTRESS B
        WHERE M.MAT_NO = B.MAT_NO
        AND B.STORAGE_NO != ?
        AND M.HEAT_PLAN_NO_NEXT = ?
        UNION ALL
        SELECT ACT_COUNT, ACT_WEIGHT,B.STORAGE_NO
        FROM MAT_GP_M M, YDM_GP_BUTTRESS B
        WHERE M.MAT_NO = B.MAT_NO
        AND B.STORAGE_NO != ?
        AND M.HEAT_PLAN_NO_NEXT = ?
        )
    </query>


    <query id ="TmsDemand.updateDemandStatus">
        UPDATE TMS_DEMAND_M
        SET VALIDFLAG       = ?,
        OUTPUT_QTY_VAL  = ?,
        OUTPUT_WT_VAL   = ?,
        START_NODE_CODE = ?,
        START_NODE_DESC = ?,
        START_AREA_CODE = ?,
        START_AREA_DESC = ?
        WHERE DEMAND_NO = ?
    </query>

    <query id="TmsDemand.queryUnloading">
        SELECT * FROM TMS_COM_UNLOADING WHERE UNLOADING_AREA_CODE =?
    </query>


    <query id="TmsDemand.insertCopy">
        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,
        SOURCE_SIGN,
        VALIDFLAG,
        STATUS,
        ACCOUNT_YEAR_MONTH,
        ARCHIVE_FLAG,
        ARCHIVE_NO,
        ARCHIVE_DATE,
        MEMO,
        CREATE_USERID,
        CREATE_NAME,
        CREATE_TIME,
        UPDATE_USERID,
        UPDATE_NAME,
        UPDATE_TIME,
        DELETE_USERID,
        DELETE_NAME,
        DELETE_TIME,
        COST_COUNT,
        LOAD_TIME,
        LOT_NO,
        IS_SURE)
        SELECT  (SELECT M.TRAN_CLASS_CODE  || TO_CHAR(SYSDATE,'YYYYMMDD' ) ||
        LPAD(NVL(MAX(TO_NUMBER(SUBSTR(DEMAND_NO, LENGTH(DEMAND_NO) - 4))),
        0) + 1,
        5,
        '0') DEMAND_NO
        FROM TMS_DEMAND_M
        WHERE DEMAND_NO LIKE M.TRAN_CLASS_CODE || TO_CHAR(SYSDATE,'YYYYMMDD' )  ||  '_____'),
        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,
        ?,
        ?,
        null,
        null,
        null,
        null,
        null,
        null,
        PRO_ORDER_NO,
        PRO_ORDER_SQE,
        CURRENT_JOB_NO,
        PREVIOUS_JOB_NO,
        SOURCE_SIGN,
        '20',
        '20',
        ACCOUNT_YEAR_MONTH,
        ARCHIVE_FLAG,
        ARCHIVE_NO,
        ARCHIVE_DATE,
        MEMO,
        CREATE_USERID,
        ?,
        SYSDATE,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        COST_COUNT,
        LOAD_TIME,
        LOT_NO,
        IS_SURE
        FROM TMS_DEMAND_M M
        WHERE DEMAND_NO =?
    </query>


    <query id="TmsDemand.updateDemandQty" desc="">
        <![CDATA[
UPDATE TMS_DEMAND_M M
    SET
      DEMAND_QTY_VAL =?,
      DEMAND_WT_VAL =?
    WHERE DEMAND_NO = ?
        ]]>
    </query>



    <query id="TmsDemand.updateDemandQty2" desc="">
        <![CDATA[
UPDATE TMS_DEMAND_M
    SET
      DEMAND_QTY_VAL =?,
      DEMAND_WT_VAL =?,
      OUTPUT_QTY_VAL=?,
      OUTPUT_WT_VAL=?,
     OFFLINE_QTY_VAL=?,
     OFFLINE_WT_VAL=?,
     SCRAP_QTY_VAL=?,
     SCRAP_WT_VAL=?
    WHERE DEMAND_NO = ?
        ]]>
    </query>

    <query id="TmsDemand.deleteDemand" desc="">
        <![CDATA[
DELETE FROM TMS_DEMAND_M
    WHERE DEMAND_NO = ?
        ]]>
    </query>


    <query id ="TmsDemand.getLineID" desc="">
        SELECT 'XL' ||
        LPAD(NVL(MAX(TO_NUMBER(SUBSTR(LINE_CODE, LENGTH(LINE_CODE) - 4))),
        0) + 1,
        5,
        '0') LINE_CODE
        FROM TMS_COM_LINE_M
        WHERE LINE_CODE LIKE 'XL_____'
    </query>

    <query id ="TmsDemand.InsertLineC" >
        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,
        DISTANCE_VAL,
        VALIDFLAG,
        MEMO,
        CREATE_USERID,
        CREATE_NAME,
        CREATE_TIME)
        SELECT
        (SELECT 'XD' ||
        LPAD(NVL(MAX(TO_NUMBER(SUBSTR(SEGMENT_CODE, LENGTH(SEGMENT_CODE) - 3))),
        0) + 1,
        4,
        '0') SEGMENT_CODE
        FROM TMS_COM_LINE_C
        WHERE LINE_CODE = ?
        AND SEGMENT_CODE LIKE 'XD____'),
        T1.UNLOADING_DESC || '->' || T2.UNLOADING_DESC ,
        ?,
        ( SELECT NVL(MAX(SEGMENT_SQE),0) +1  FROM TMS_COM_LINE_C WHERE LINE_CODE =? ),
        'YST01',
        '公路',
        T1.UNLOADING_CODE,
        T1.UNLOADING_DESC,
        T1.LONGITUDE_VAL,
        T1.LATITUDE_VAL,
        T2.UNLOADING_CODE,
        T2.UNLOADING_DESC,
        T2.LONGITUDE_VAL,
        T2.LATITUDE_VAL,
        0,
        '1',
        '系统生成',
        'admin',
        'admin',
        SYSDATE
        FROM TMS_COM_UNLOADING T1,TMS_COM_UNLOADING T2
        WHERE T1.UNLOADING_CODE = ?
        AND T2.UNLOADING_CODE = ?
    </query>

    <query id = "TmsDemand.InsertLineM">
        INSERT INTO TMS_COM_LINE_M
        (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,
        VALIDFLAG,
        MEMO,
        CREATE_USERID,
        CREATE_NAME,
        CREATE_TIME,
        DISTANCE_VAL)
        SELECT T1.LINE_CODE,
        (SELECT LISTAGG(C.START_NODE_DESC, '->') WITHIN GROUP(ORDER BY C.SEGMENT_SQE)
        FROM TMS_COM_LINE_C C
        WHERE C.LINE_CODE = T1.LINE_CODE) || '->' || T2.END_NODE_DESC,
        T1.START_NODE_CODE,
        T1.START_NODE_DESC,
        T1.START_LONGITUDE_VAL,
        T1.START_LATITUDE_VAL,
        T2.END_NODE_CODE,
        T2.END_NODE_DESC,
        T2.END_LONGITUDE_VAL,
        T2.END_LATITUDE_VAL,
        '1',
        '系统生成',
        'admin',
        'admin',
        SYSDATE,
        0
        FROM TMS_COM_LINE_C T1, TMS_COM_LINE_C T2
        WHERE T1.LINE_CODE = T2.LINE_CODE
        AND T1.LINE_CODE = ?
        AND T1.SEGMENT_SQE =
        (SELECT MIN(SEGMENT_SQE)
        FROM TMS_COM_LINE_C T3
        WHERE T3.LINE_CODE = T1.LINE_CODE)
        AND T2.SEGMENT_SQE =
        (SELECT MAX(SEGMENT_SQE)
        FROM TMS_COM_LINE_C T3
        WHERE T3.LINE_CODE = T1.LINE_CODE)
    </query>
    <query id = "TmsDemand.selectMatBcCount" desc = "查询是否有库存">
        SELECT COUNT(1) ACOUNT
        FROM MAT_BC_M T
        LEFT JOIN YDM_BC_BUTTRESS S
        ON T.MAT_NO = S.MAT_NO
        WHERE T.JUDGE_STOVE_NO = '#HEAT_NO#'
        AND T.QCM_STAUS IN ('00', '11')
    </query>
    <query id = "TmsDemand.selectMatBc" desc = "查询管材库存地点">
       SELECT (SELECT COUNT(1) ACOUNT
        FROM MAT_BC_M T, YDM_BC_BUTTRESS S
        WHERE T.MAT_NO = S.MAT_NO
        AND T.JUDGE_STOVE_NO = '#HEAT_NO#'
        AND S.STORAGE_NO = '#START_AREA_CODE#'
        AND T.QCM_STAUS IN ('00', '11'))
        + 
         (SELECT COUNT(1) ACOUNT
        FROM MAT_ZC_M T, YDM_ZC_BUTTRESS S
        WHERE T.MAT_NO = S.MAT_NO
        AND T.JUDGE_STOVE_NO = '#HEAT_NO#'
        AND S.STORAGE_NO = '#START_AREA_CODE#'
        ) ACOUNT
        FROM DUAL
    </query>
    <query id = "TmsDemand.selectMatGpCount" desc = "查询是否有库存">
        SELECT COUNT(1) ACOUNT
        FROM MAT_GP_M T
        LEFT JOIN YDM_GP_BUTTRESS S
        ON T.MAT_NO = S.MAT_NO
        WHERE T.JUDGE_STOVE_NO = '#HEAT_NO#'
        AND T.QCM_STAUS = '00'
    </query>
    <query id = "TmsDemand.selectMatGp" desc = "查询管材库存地点">
        SELECT COUNT(1)ACOUNT
        FROM MAT_GP_M T, YDM_GP_BUTTRESS S
        WHERE T.MAT_NO = S.MAT_NO
        AND T.JUDGE_STOVE_NO = '#HEAT_NO#'
        AND S.STORAGE_NO = '#START_AREA_CODE#'
        AND T.QCM_STAUS = '00'
    </query>
</queryMap>