<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc = "二级排产下发写CRM">
    <query id = "ProducCrm.insertCrmD" desc = "插入CRM表">
        INSERT INTO CRM_ORDER_PRODUCE(
        WGT_ESTMT,
        D_PLINE_CODE,
        D_PLINE_NAME,
        PASS_CODE,
        PASS_NAME,
        PLAN_TIME_B,
        EXE_STATUS,
        GRADECODE,
        GRADENAME,
        DIAMETER_GP,
        PLAN_TIME_DBK,
        PLAN_TIME_RCL,
        PLAN_TIME_JGX,
        DATA_STATUS,
        ORD_LN_DLY_PK,
        CREATE_NAME,
        CREATE_TIME,
        APP_NUM,
        APP_UNIT,
        PSS_NUM,
        PSS_WGT,
        OUTS_BILLET_FL)
        VALUES(
        '#WGT_ESTMT#',
        '#D_PLINE_CODE#',
        '#D_PLINE_NAME#',
        '#PASS_CODE#',
        '#PASS_NAME#',
        TO_DATE('#PLAN_TIME_B#','YYYY-MM-DD HH24:MI:SS'),
        '#EXE_STATUS#',
        '#GRADECODE#',
        '#GRADENAME#',
        '#DIAMETER_GP#',
        TO_DATE('#PLAN_TIME_DBK#','YYYY-MM-DD HH24:MI:SS'),
        TO_DATE('#PLAN_TIME_RCL#','YYYY-MM-DD HH24:MI:SS'),
        TO_DATE('#PLAN_TIME_JGX#','YYYY-MM-DD HH24:MI:SS'),
        '#DATA_STATUS#',
        '#ORD_LN_DLY_PK#',
        '#CREATE_NAME#',
        SYSDATE,
        '#APP_NUM#',
        '#APP_UNIT#',
        '#PSS_NUM#',
        '#PSS_WGT#',
        '#OUTS_BILLET_FL#')
    </query>
    <query id = "ProducCrm.selectCrmOrder" desc = "查询CRM信息">
        SELECT WGT_ESTMT,
        LG_NUM,
        LG_WGT,
        TO_CHAR(LG_TIME, 'YYYY-MM-DD HH24:MI:SS') LG_TIME,
        D_PLINE_CODE,
        D_PLINE_NAME,
        PASS_CODE,
        PASS_NAME,
        TO_CHAR(PLAN_TIME_B, 'YYYY-MM-DD HH24:MI:SS') PLAN_TIME_B,
        EXE_STATUS,
        EXE_STATUS_DBK,
        EXE_STATUS_RCL,
        EXE_STATUS_JGX,
        GRADECODE,
        GRADENAME,
        DIAMETER_GP,
        ZG_NUM,
        ZG_WGT,
        TO_CHAR(PLAN_TIME_DBK, 'YYYY-MM-DD HH24:MI:SS') PLAN_TIME_DBK,
        DBK_NUM,
        DBK_WGT,
        TO_CHAR(PLAN_TIME_RCL, 'YYYY-MM-DD HH24:MI:SS') PLAN_TIME_RCL,
        RCL_NUM,
        RCL_WGT,
        TO_CHAR(PLAN_TIME_JGX, 'YYYY-MM-DD HH24:MI:SS') PLAN_TIME_JGX,
        JGX_NUM,
        JGX_WGT,
        PRODUCT_NUM,
        PRODUCT_WGT,
        PRODUCT_LEN,
        DATA_STATUS,
        IS_FLAG,
        TO_CHAR(SYNCHRO_TIME, 'YYYY-MM-DD HH24:MI:SS') SYNCHRO_TIME,
        INITIAL_ID,
        ORD_LN_DLY_PK,
        CREATE_NAME,
        TO_CHAR(CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
        APP_NUM,
        APP_UNIT,
        PSS_NUM,
        PSS_WGT,
        OUTS_BILLET_FL
        FROM CRM_ORDER_PRODUCE T
        WHERE T.ORD_LN_DLY_PK = '#ORD_LN_DLY_PK#'
        ORDER BY T.CREATE_TIME DESC
    </query>
    <query id = "ProducCrm.insertCrmStatus" desc = "状态调整插入CRM">
        INSERT INTO CRM_ORDER_PRODUCE
        (WGT_ESTMT,
        D_PLINE_CODE,
        D_PLINE_NAME,
        PASS_CODE,
        PASS_NAME,
        PLAN_TIME_B,
        EXE_STATUS,
        GRADECODE,
        GRADENAME,
        DIAMETER_GP,
        PLAN_TIME_DBK,
        PLAN_TIME_RCL,
        PLAN_TIME_JGX,
        DATA_STATUS,
        ORD_LN_DLY_PK,
        CREATE_NAME,
        CREATE_TIME,
        APP_NUM,
        APP_UNIT,
        PSS_NUM,
        PSS_WGT,
        OUTS_BILLET_FL,
        EXE_STATUS_DBK,
        EXE_STATUS_RCL,
        EXE_STATUS_JGX)
        SELECT
        WGT_ESTMT,
        D_PLINE_CODE,
        D_PLINE_NAME,
        PASS_CODE,
        PASS_NAME,
        PLAN_TIME_B,
        '#EXE_STATUS#',
        GRADECODE,
        GRADENAME,
        DIAMETER_GP,
        PLAN_TIME_DBK,
        PLAN_TIME_RCL,
        PLAN_TIME_JGX,
        '1',
        ORD_LN_DLY_PK,
        CREATE_NAME,
        SYSDATE,
        APP_NUM,
        APP_UNIT,
        PSS_NUM,
        PSS_WGT,
        OUTS_BILLET_FL,
        '#EXE_STATUS_DBK#',
        '#EXE_STATUS_RCL#',
        '#EXE_STATUS_JGX#'
        FROM (SELECT WGT_ESTMT,
        D_PLINE_CODE,
        D_PLINE_NAME,
        PASS_CODE,
        PASS_NAME,
        PLAN_TIME_B,
        '#EXE_STATUS#',
        GRADECODE,
        GRADENAME,
        DIAMETER_GP,
        PLAN_TIME_DBK,
        PLAN_TIME_RCL,
        PLAN_TIME_JGX,
        '1',
        ORD_LN_DLY_PK,
        CREATE_NAME,
        SYSDATE,
        APP_NUM,
        APP_UNIT,
        PSS_NUM,
        PSS_WGT,
        OUTS_BILLET_FL,
        '#EXE_STATUS_DBK#',
        '#EXE_STATUS_RCL#',
        '#EXE_STATUS_JGX#'
        FROM CRM_ORDER_PRODUCE T
        WHERE T.ORD_LN_DLY_PK = '#ORD_LN_DLY_PK#'
        ORDER BY T.CREATE_TIME DESC)
        WHERE ROWNUM = 1
    </query>
    <query id = "ProducCrm.selectZgs" desc = "查询轧管订单">
        <![CDATA[
        SELECT T.PRO_PLAN_ID, T.GX_PLAN_NO, T.EXE_STATUS,T.ORD_LN_DLY_PK,T.GX_PRO_SEQ
        FROM PLN_ORDER_ZG_S T
        WHERE T.PLINE_CODE = ?
        AND T.EXE_STATUS IN('0','1')
        AND TO_NUMBER(T.GX_PRO_SEQ) <= TO_NUMBER(?)
        AND TO_NUMBER(T.GX_PRO_SEQ)  > 0
        ]]>
    </query>
    <query id = "ProducCrm.selectDbks" desc = "查询镦拔扩订单">
        <![CDATA[
        SELECT T.PRO_PLAN_ID, T.GX_PLAN_NO, T.EXE_STATUS,T.ORD_LN_DLY_PK,T.GX_PRO_SEQ
        FROM PLN_ORDER_DBK_S T
        WHERE T.PLINE_CODE = ?
        AND T.EXE_STATUS IN('0','1')
        AND TO_NUMBER(T.GX_PRO_SEQ) <= TO_NUMBER(?)
        AND TO_NUMBER(T.GX_PRO_SEQ)  > 0
        ]]>
    </query>
    <query id = "ProducCrm.selectRcls" desc = "查询热处理订单">
        <![CDATA[
        SELECT T.PRO_PLAN_ID, T.GX_PLAN_NO, T.EXE_STATUS,T.ORD_LN_DLY_PK,T.GX_PRO_SEQ
        FROM PLN_ORDER_RCL_S T
        WHERE T.PLINE_CODE = ?
        AND T.EXE_STATUS IN('0','1')
        AND TO_NUMBER(T.GX_PRO_SEQ) <= TO_NUMBER(?)
        AND TO_NUMBER(T.GX_PRO_SEQ)  > 0
        ]]>
    </query>
    <query id = "ProducCrm.selectJgxs" desc = "查询加工订单">
        <![CDATA[
        SELECT T.PRO_PLAN_ID, T.GX_PLAN_NO, T.EXE_STATUS,T.ORD_LN_DLY_PK,T.GX_PRO_SEQ
        FROM PLN_ORDER_JGX_S T
        WHERE T.PLINE_CODE = ?
        AND T.EXE_STATUS IN('0','1')
        AND TO_NUMBER(T.GX_PRO_SEQ) <= TO_NUMBER(?)
        AND TO_NUMBER(T.GX_PRO_SEQ)  > 0
        ]]>
    </query>
</queryMap>