<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="质量设计回退功能">

	<query id="QualityDesignFallback.getItemByOrdLnPk" desc="查询合同行质量设计明细项">
         <![CDATA[
           SELECT ORD_LN_PK, SEQ_INDEX, LST_ITEM
             FROM SLM_ORD_DESIGN_STS_TKLG_LST T
            WHERE T.ORD_LN_PK = ?
              AND T.VALIDFLAG = '1'
         ORDER BY T.SEQ_INDEX ASC    
         ]]>
	</query>
	
	<query id="QualityDesignFallback.getCraftItemByOrdLnPk" desc="查询工艺质量设计明细项">
         <![CDATA[
SELECT *
  FROM (SELECT T.ORD_LN_PK, T.SEQ_INDEX, T.LST_ITEM, T.DESIGN_STS
          FROM CRAFT_ORD_DESIGN_STS_TKLG_LST T, CRAFT_ORD_DESIGN A
         WHERE T.VALIDFLAG = '1'
           AND A.ORD_LN_PK = {0}
           AND A.DESGIN_KEY = T.DESGIN_KEY
           AND T.VALIDFLAG = '1'
           AND A.CRAFT_SEQ = (SELECT MAX(CRAFT_SEQ)
                                FROM CRAFT_ORD_DESIGN C
                               WHERE C.ORD_LN_PK = A.ORD_LN_PK
                                 AND C.VALIDFLAG <> '0')
           AND T.LST_ITEM NOT IN ('试样码', '首日检')
        UNION ALL
        SELECT T.ORD_LN_PK,
               T.SEQ_INDEX,
               T.LST_ITEM || '(MSC0)',
               T.DESIGN_STS
          FROM CRAFT_ORD_DESIGN_STS_TKLG_LST T, CRAFT_ORD_DESIGN A
         WHERE T.VALIDFLAG = '1'
           AND A.ORD_LN_PK = {0}
           AND A.DESGIN_KEY = T.DESGIN_KEY
           AND T.VALIDFLAG = '1'
           AND A.CRAFT_SEQ = (SELECT MAX(CRAFT_SEQ)
                                FROM CRAFT_ORD_DESIGN C
                               WHERE C.ORD_LN_PK = A.ORD_LN_PK
                                 AND C.VALIDFLAG <> '0')
           AND T.LST_ITEM = '试样码'
           AND EXISTS (SELECT 1
                  FROM CRAFT_ORD_DESIGN_STD_PIC B
                 WHERE B.DESGIN_KEY = T.DESGIN_KEY
                   AND B.SPECL_FL = '0')
        UNION ALL
        SELECT T.ORD_LN_PK,
               T.SEQ_INDEX,
               T.LST_ITEM || '(MSCn)',
               T.DESIGN_STS
          FROM CRAFT_ORD_DESIGN_STS_TKLG_LST T, CRAFT_ORD_DESIGN A
         WHERE T.VALIDFLAG = '1'
           AND A.ORD_LN_PK = {0}
           AND A.DESGIN_KEY = T.DESGIN_KEY
           AND T.VALIDFLAG = '1'
           AND A.CRAFT_SEQ = (SELECT MAX(CRAFT_SEQ)
                                FROM CRAFT_ORD_DESIGN C
                               WHERE C.ORD_LN_PK = A.ORD_LN_PK
                                 AND C.VALIDFLAG <> '0')
           AND T.LST_ITEM = '试样码'
           AND EXISTS (SELECT 1
                  FROM CRAFT_ORD_DESIGN_STD_PIC B
                 WHERE B.DESGIN_KEY = T.DESGIN_KEY
                   AND B.SPECL_FL = '1')
        UNION ALL
        SELECT T.ORD_LN_PK,
               T.SEQ_INDEX,
               T.LST_ITEM || '(内控)',
               T.DESIGN_STS
          FROM CRAFT_ORD_DESIGN_STS_TKLG_LST T, CRAFT_ORD_DESIGN A
         WHERE T.VALIDFLAG = '1'
           AND A.ORD_LN_PK = {0}
           AND A.DESGIN_KEY = T.DESGIN_KEY
           AND T.VALIDFLAG = '1'
           AND A.CRAFT_SEQ = (SELECT MAX(CRAFT_SEQ)
                                FROM CRAFT_ORD_DESIGN C
                               WHERE C.ORD_LN_PK = A.ORD_LN_PK
                                 AND C.VALIDFLAG <> '0')
           AND T.LST_ITEM = '试样码'
           AND EXISTS (SELECT 1
                  FROM CRAFT_ORD_DESIGN_STD_PIC B
                 WHERE B.DESGIN_KEY = T.DESGIN_KEY
                   AND B.SPECL_FL = '2')
        UNION ALL
        SELECT T.ORD_LN_PK,
               T.SEQ_INDEX,
               T.LST_ITEM || '（成分）',
               T.DESIGN_STS
          FROM CRAFT_ORD_DESIGN_STS_TKLG_LST T, CRAFT_ORD_DESIGN A
         WHERE T.VALIDFLAG = '1'
           AND A.ORD_LN_PK = {0}
           AND A.DESGIN_KEY = T.DESGIN_KEY
           AND T.VALIDFLAG = '1'
           AND A.CRAFT_SEQ = (SELECT MAX(CRAFT_SEQ)
                                FROM CRAFT_ORD_DESIGN C
                               WHERE C.ORD_LN_PK = A.ORD_LN_PK
                                 AND C.VALIDFLAG <> '0')
           AND T.LST_ITEM = '首日检'
        UNION ALL
        SELECT T.ORD_LN_PK,
               T.SEQ_INDEX,
               T.LST_ITEM || '（理化）',
               T.DESIGN_STS
          FROM CRAFT_ORD_DESIGN_STS_TKLG_LST T, CRAFT_ORD_DESIGN A
         WHERE T.VALIDFLAG = '1'
           AND A.ORD_LN_PK = {0}
           AND A.DESGIN_KEY = T.DESGIN_KEY
           AND T.VALIDFLAG = '1'
           AND A.CRAFT_SEQ = (SELECT MAX(CRAFT_SEQ)
                                FROM CRAFT_ORD_DESIGN C
                               WHERE C.ORD_LN_PK = A.ORD_LN_PK
                                 AND C.VALIDFLAG <> '0')
           AND T.LST_ITEM = '首日检'
        UNION ALL
        SELECT T.ORD_LN_PK,
               T.SEQ_INDEX,
               T.LST_ITEM || '（水压）',
               T.DESIGN_STS
          FROM CRAFT_ORD_DESIGN_STS_TKLG_LST T, CRAFT_ORD_DESIGN A
         WHERE T.VALIDFLAG = '1'
           AND A.ORD_LN_PK = {0}
           AND A.DESGIN_KEY = T.DESGIN_KEY
           AND T.VALIDFLAG = '1'
           AND A.CRAFT_SEQ = (SELECT MAX(CRAFT_SEQ)
                                FROM CRAFT_ORD_DESIGN C
                               WHERE C.ORD_LN_PK = A.ORD_LN_PK
                                 AND C.VALIDFLAG <> '0')
           AND T.LST_ITEM = '首日检')
 ORDER BY SEQ_INDEX ASC, LST_ITEM
         ]]>
	</query>
	
	<query id="QualityDesignFallback.getCraftDesignStsByOrdLnPk" desc="查询工艺质量设计主表">
         <![CDATA[
SELECT A.*
  FROM CRAFT_ORD_DESIGN_STS_TKLG A, CRAFT_ORD_DESIGN B
 WHERE A.DESGIN_KEY = B.DESGIN_KEY
   AND B.LOCK_FLAG = '1'
   AND B.VALIDFLAG = '2'
   AND B.ORD_LN_PK = '#ORD_LN_PK#' 
         ]]>
	</query>
	
	<query id="QualityDesignFallback.craftFallBack" desc="回退工艺">
         <![CDATA[
DECLARE
  P_DESIGN_KEY   CRAFT_ORD_DESIGN_STS_TKLG_LST.DESGIN_KEY%TYPE;
  P_SEQ_INDEX    CRAFT_ORD_DESIGN_STS_TKLG_LST.SEQ_INDEX%TYPE;
  P_SEQ_INDEX_PL CRAFT_ORD_DESIGN_STS_TKLG_LST.SEQ_INDEX%TYPE;
  P_SEQ_INDEX_JG CRAFT_ORD_DESIGN_STS_TKLG_LST.SEQ_INDEX%TYPE;
  P_LST_ITEM     CRAFT_ORD_DESIGN_STS_TKLG_LST.LST_ITEM%TYPE;
BEGIN
  IF (INSTR('#LST_ITEM#', '试样码') > 0) THEN
    P_LST_ITEM := '试样码';
  ELSIF (INSTR('#LST_ITEM#', '首日检') > 0) THEN
  	P_LST_ITEM := '首日检';
  ELSE
    P_LST_ITEM := '#LST_ITEM#';
  END IF;

  SELECT DESGIN_KEY
    INTO P_DESIGN_KEY
    FROM CRAFT_ORD_DESIGN T
   WHERE T.ORD_LN_PK = '#ORD_LN_PK#'
     AND T.CRAFT_SEQ = (SELECT MAX(CRAFT_SEQ)
                          FROM CRAFT_ORD_DESIGN A
                         WHERE A.ORD_LN_PK = T.ORD_LN_PK
                           AND A.VALIDFLAG <> '0');
  SELECT SEQ_INDEX
    INTO P_SEQ_INDEX
    FROM CRAFT_ORD_DESIGN_STS_TKLG_LST T
   WHERE T.DESGIN_KEY = P_DESIGN_KEY
     AND T.LST_ITEM = P_LST_ITEM
     AND T.VALIDFLAG = '1';
  SELECT SEQ_INDEX
    INTO P_SEQ_INDEX_PL
    FROM CRAFT_ORD_DESIGN_STS_TKLG_LST T
   WHERE T.DESGIN_KEY = P_DESIGN_KEY
     AND T.LST_ITEM = '制程'
     AND T.VALIDFLAG = '1';
  SELECT SEQ_INDEX
    INTO P_SEQ_INDEX_JG
    FROM CRAFT_ORD_DESIGN_STS_TKLG_LST T
   WHERE T.DESGIN_KEY = P_DESIGN_KEY
     AND T.LST_ITEM = '接箍'
     AND T.VALIDFLAG = '1';
  UPDATE CRAFT_ORD_DESIGN_STS_TKLG_LST T
     SET T.DESIGN_STS      = 'F',
         T.DESIGN_STS_RS   = '21',
         T.DESIGN_STS_DESC = '人工回退到该节点 ' || '#REASON#'
   WHERE T.DESGIN_KEY = P_DESIGN_KEY
     AND T.LST_ITEM = P_LST_ITEM
     AND T.VALIDFLAG = '1';
  UPDATE CRAFT_ORD_DESIGN_STS_TKLG_LST T
     SET T.DESIGN_STS = 'W', T.DESIGN_STS_RS = '21', T.DESIGN_STS_DESC = ''
   WHERE T.DESGIN_KEY = P_DESIGN_KEY
     AND T.SEQ_INDEX > P_SEQ_INDEX
     AND T.VALIDFLAG = '1';
  UPDATE CRAFT_ORD_DESIGN_STS_TKLG T
     SET T.DESIGN_STS = 'F'
   WHERE T.DESGIN_KEY = P_DESIGN_KEY
     AND T.VALIDFLAG = '1';

  IF P_SEQ_INDEX <= P_SEQ_INDEX_PL THEN
    DELETE CRAFT_ORD_DESIGN_MSC_PL T
     WHERE T.DESGIN_KEY = P_DESIGN_KEY
       AND T.SET_FL = '1';
    UPDATE CRAFT_ORD_DESIGN_STS_TKLG_LST T
       SET T.DESIGN_OBJ_KEY = '1'
     WHERE T.DESGIN_KEY = P_DESIGN_KEY
       AND T.LST_ITEM = '制程'
       AND T.VALIDFLAG = '1';
  END IF;

  IF P_SEQ_INDEX <= P_SEQ_INDEX_JG THEN
    DELETE FROM CRAFT_ORD_DESIGN_MSC_JG T
     WHERE T.DESGIN_KEY = P_DESIGN_KEY;
  END IF;

  IF '#LST_ITEM#' = '镦拔扩' THEN

UPDATE CRAFT_ORD_DESIGN_STS_TKLG_LST c
   SET C.Design_Obj_Key =
       (SELECT T.MSC_PLINE || ',' || B.PROCESS_CODE_C
          FROM CRAFT_ORD_DESIGN_MSC_PL T,
               CRAFT_ORD_DESIGN_MSC        A,
               COM_MSC_PROCESS             B
         WHERE T.DESGIN_KEY = P_DESIGN_KEY
           AND A.DESGIN_KEY = T.DESGIN_KEY
           AND A.MSC = B.MSC
           AND B.PROCESS_CODE = 'E'
           AND T.MSC_PLINE = B.MSC_PLINE
           AND ROWNUM <= 1)
 WHERE c.DESGIN_KEY = P_DESIGN_KEY
   AND c.LST_ITEM = '镦拔扩';
DELETE FROM (SELECT *
               FROM craft_ord_design_msc_gz_gg_s C
              WHERE C.ORD_LN_PK = '#ORD_LN_PK#');
  END IF;

  IF '#LST_ITEM#' = '试样码(MSC0)' THEN
    UPDATE CRAFT_ORD_DESIGN_STS_TKLG_LST T
       SET T.Design_Obj_Key =
           (SELECT PIC || ',0'
              FROM CRAFT_ORD_DESIGN_STD_PIC A
             WHERE A.DESGIN_KEY = T.DESGIN_KEY
               AND A.SPECL_FL = '0'
             GROUP BY A.PIC)
     WHERE T.DESGIN_KEY = P_DESIGN_KEY
       AND T.LST_ITEM = '试样码';
  ELSIF '#LST_ITEM#' = '试样码(MSCn)' THEN
    UPDATE CRAFT_ORD_DESIGN_STS_TKLG_LST T
       SET T.Design_Obj_Key =
           (SELECT PIC || ',1'
              FROM CRAFT_ORD_DESIGN_STD_PIC A
             WHERE A.DESGIN_KEY = T.DESGIN_KEY
               AND A.SPECL_FL = '1'
             GROUP BY A.PIC)
     WHERE T.DESGIN_KEY = P_DESIGN_KEY
       AND T.LST_ITEM = '试样码';
  ELSIF '#LST_ITEM#' = '试样码(内控)' THEN
    UPDATE CRAFT_ORD_DESIGN_STS_TKLG_LST T
       SET T.Design_Obj_Key = '#PIC#' || ',2,' || '#DIMATER#' || ',' || '#HEIGHT#' || ',' || '#MSC_PLINE#' ||
              ',' || '#PROCESS_CODE#'
     WHERE T.DESGIN_KEY = P_DESIGN_KEY
       AND T.LST_ITEM = '试样码';
  END IF;
  
  IF '#LST_ITEM#' = '附件图片' THEN
    UPDATE CRAFT_ORD_DESIGN_STS_TKLG_LST c
       SET C.Design_Obj_Key = '1'
     WHERE c.DESGIN_KEY = P_DESIGN_KEY
       AND c.LST_ITEM = '附件图片';
  END IF;
  
  IF '#LST_ITEM#' = '首日检（成分）' THEN
    UPDATE CRAFT_ORD_DESIGN_STS_TKLG_LST c
       SET C.Design_Obj_Key = 'Cic'
     WHERE c.DESGIN_KEY = P_DESIGN_KEY
       AND c.LST_ITEM = '首日检';
  END IF;
  
  IF '#LST_ITEM#' = '首日检（理化）' THEN
    UPDATE CRAFT_ORD_DESIGN_STS_TKLG_LST c
       SET C.Design_Obj_Key = 'Pic'
     WHERE c.DESGIN_KEY = P_DESIGN_KEY
       AND c.LST_ITEM = '首日检';
  END IF;
  
  IF '#LST_ITEM#' = '首日检（公差）' THEN
    UPDATE CRAFT_ORD_DESIGN_STS_TKLG_LST c
       SET C.Design_Obj_Key = 'Sic'
     WHERE c.DESGIN_KEY = P_DESIGN_KEY
       AND c.LST_ITEM = '首日检';
  END IF;
  
  IF '#LST_ITEM#' = '首日检（探伤）' THEN
    UPDATE CRAFT_ORD_DESIGN_STS_TKLG_LST c
       SET C.Design_Obj_Key = 'Dic'
     WHERE c.DESGIN_KEY = P_DESIGN_KEY
       AND c.LST_ITEM = '首日检';
  END IF;
  
  IF '#LST_ITEM#' = '首日检（水压）' THEN
    UPDATE CRAFT_ORD_DESIGN_STS_TKLG_LST c
       SET C.Design_Obj_Key = 'Wic'
     WHERE c.DESGIN_KEY = P_DESIGN_KEY
       AND c.LST_ITEM = '首日检';
  END IF;
  
  IF '#LST_ITEM#' = '水压标准' THEN
    DELETE FROM CRAFT_ORD_DESIGN_STD_WIC_S T WHERE T.ORD_LN_PK = '#ORD_LN_PK#';
  END IF;
END;
         ]]>
	</query>

	<query id="QualityDesignFallback.getOrderLineStatus" desc="查询合同行当前状态">
         <![CDATA[
    SELECT T.ORDER_LN_STATUS
      FROM SLM_ORDER_LINE T
     WHERE T.ORD_LN_PK = ?
       AND T.VALIDFLAG = '1'
         ]]>
	</query>


	<query id="QualityDesignFallback.getListItemStatusByitem" desc="根据节点查询明细状态">
         <![CDATA[
         SELECT DESGIN_KEY,
       ORD_LN_PK,
       SEQ_INDEX,
       LST_ITEM,
       DESIGN_STS,
       DESIGN_STS_RS,
       DESIGN_STS_DESC,
       PSC,
       MSC,
       USE_CODE,
       FINAL_USER,
       GRADECODE,
       DESIGN_OBJ_KEY,
       UNIT_CODE,
       UNIT_DESC,
       VALIDFLAG,
       CREATE_NAME,
       CREATE_TIME,
       UPDATE_NAME,
       UPDATE_TIME,
       DELETE_NAME,
       DELETE_TIME
  FROM SLM_ORD_DESIGN_STS_TKLG_LST T
 WHERE T.ORD_LN_PK = ?
   AND T.LST_ITEM = ?
   AND T.VALIDFLAG = '1'
         ]]>
	</query>


	<query id="QualityDesignFallback.getNextMaxListItemStatus" desc="查询明细状态当前状态">
         <![CDATA[
    SELECT DESGIN_KEY,
       ORD_LN_PK,
       SEQ_INDEX,
       LST_ITEM,
       DESIGN_STS,
       DESIGN_STS_RS,
       DESIGN_STS_DESC,
       PSC,
       MSC,
       USE_CODE,
       FINAL_USER,
       GRADECODE,
       DESIGN_OBJ_KEY,
       UNIT_CODE,
       UNIT_DESC,
       VALIDFLAG,
       CREATE_NAME,
       CREATE_TIME,
       UPDATE_NAME,
       UPDATE_TIME,
       DELETE_NAME,
       DELETE_TIME
  FROM SLM_ORD_DESIGN_STS_TKLG_LST T
 WHERE TO_NUMBER(T.SEQ_INDEX) =
       (SELECT DECODE(TO_NUMBER(MAX(T.SEQ_INDEX)),
                      null,
                      ?,
                      TO_NUMBER(MAX(T.SEQ_INDEX)))
          FROM SLM_ORD_DESIGN_STS_TKLG_LST T
         WHERE T.ORD_LN_PK = ?
           and t.design_sts = 'F'
           AND T.VALIDFLAG = '1')
   AND T.ORD_LN_PK = ?
   AND T.VALIDFLAG = '1'
         ]]>
	</query>

	<query id="QualityDesignFallback.updateListItemStatusAfterItem"
		desc="修改回退点后明细状态为等待">
         <![CDATA[
    UPDATE SLM_ORD_DESIGN_STS_TKLG_LST T
       SET T.DESIGN_STS = 'W',
           T.DESIGN_STS_RS='',
           T.DESIGN_STS_DESC=''
     WHERE T.ORD_LN_PK = ?
       AND T.VALIDFLAG = '1'
       AND TO_NUMBER(T.SEQ_INDEX) > TO_NUMBER(?) 
         ]]>
	</query>

	<query id="QualityDesignFallback.updateListItemStatusByItem"
		desc="修改回退点明细状态">
         <![CDATA[
            UPDATE SLM_ORD_DESIGN_STS_TKLG_LST T
               SET T.DESIGN_STS = 'F', T.DESIGN_STS_DESC = ?,T.DESIGN_STS_RS='91'
             WHERE T.ORD_LN_PK = ?
               AND T.VALIDFLAG = '1'
               AND T.SEQ_INDEX = ?
         ]]>
	</query>

	<query id="QualityDesignFallback.updateListItemStatusByZC" desc="修改制程明细状态">
         <![CDATA[
            UPDATE SLM_ORD_DESIGN_STS_TKLG_LST T
   SET 
       T.DESIGN_OBJ_KEY  = '1'
 WHERE T.ORD_LN_PK = ?
   AND T.VALIDFLAG = '1'
   AND T.LST_ITEM = '制程'
         ]]>
	</query>

	<query id="QualityDesignFallback.updateTklgStatusByOrdLnPK" desc="修改质量设计状态">
         <![CDATA[
            UPDATE SLM_ORD_DESIGN_STS_TKLG T
               SET T.DESIGN_STS = 'F'
             WHERE T.ORD_LN_PK = ?
               AND T.VALIDFLAG = '1'
         ]]>
	</query>

	<query id="QualityDesignFallback.addFallBack" desc="新增回退状态记录">
         <![CDATA[
           INSERT INTO SLM_ORD_DESIGN_FALL_BACK(
        ORDER_LN_PK,
        INDEX_SEQ,
        FALLBACK_ITEM,
        FALLBACK_REASON,
        FALLBACK_MAN,
        FALLBACK_DEPT_CODE,
        FALLBACK_DEPT_DESC,
        FALLBACK_TIME,
        FLAG)
 VALUES( 
        '#ORDER_LN_PK#',
        (SELECT TO_CHAR(TO_NUMBER(NVL(MAX(T.INDEX_SEQ), '0')) + 1) INDEX_SEQ
           FROM SLM_ORD_DESIGN_FALL_BACK T
          WHERE T.ORDER_LN_PK = '#ORDER_LN_PK#'),
        '#FALLBACK_ITEM#',
        '#FALLBACK_REASON#',
        '#FALLBACK_MAN#',
        '#FALLBACK_DEPT_CODE#',
        '#FALLBACK_DEPT_DESC#',
        SYSDATE,
        '#FLAG#')
         ]]>
	</query>

	<query id="QualityDesignFallback.deleteDept" desc="删除管理科室">
         <![CDATA[
         DELETE SLM_ORD_DESIGN_DEPT WHERE ORD_LN_PK = ?        
         ]]>
	</query>

	<query id="QualityDesignFallback.deleteSetMscPline" desc="删除指定制程">
         <![CDATA[
         DELETE SLM_ORD_DESIGN_MSC_PL T
          WHERE T.ORD_LN_PK = ?
            AND T.SET_FL = '1'
         ]]>
	</query>
	
	<query id="QualityDesignFallback.deleteMscJg" desc="删除设定接箍">
         <![CDATA[
DELETE FROM SLM_ORD_DESIGN_MSC_JG T
 WHERE T.DESGIN_KEY = (SELECT DESGIN_KEY
                         FROM SLM_ORD_DESIGN_STS_TKLG
                        WHERE ORD_LN_PK = '#ORD_LN_PK#' AND VALIDFLAG = '1')
         ]]>
	</query>
	
	<query id="QualityDesignFallback.deleteSetWaterRatio" desc="删除设定水压系数">
         <![CDATA[
DELETE FROM CRAFT_ORD_DESIGN_STD_WIC_S T WHERE T.ORD_LN_PK = '#ORD_LN_PK#'
         ]]>
	</query>

	<query id="QualityDesignFallback.deleteMPS" desc="删除MPS">
         <![CDATA[
         DELETE FROM SLM_ORD_DESIGN_MSC_PL_STI_TC T WHERE T.DESGIN_KEY = ?
         ]]>
	</query>

	<query id="QualityDesignFallback.deleteLength" desc="删除长度">
         <![CDATA[
         DELETE SLM_ORD_DESIGN_LENGTH WHERE ORD_LN_PK = ?
         ]]>
	</query>

	<query id="QualityDesignFallback.deleteFallBack" desc="修改回退记录为无效">
         <![CDATA[
         UPDATE  SLM_ORD_DESIGN_FALL_BACK T  SET T.FLAG='0' WHERE T.ORDER_LN_PK=?
         ]]>
	</query>

	<query id="QualityDesignFallback.checkFallBack" desc="验证是否回退">
         <![CDATA[
         SELECT ORDER_LN_PK,
       INDEX_SEQ,
       FALLBACK_ITEM,
       FALLBACK_REASON,
       FALLBACK_MAN,
       FALLBACK_DEPT_CODE,
       FALLBACK_DEPT_DESC,
       FALLBACK_TIME,
       FLAG
  FROM SLM_ORD_DESIGN_FALL_BACK T
 WHERE T.ORDER_LN_PK = ?
   AND T.FLAG = '1'
         ]]>
	</query>


	<query id="QualityDesignFallback.getOrdLineInfo" desc="查询合同信息">
         <![CDATA[
SELECT ORD_PK,ORD_LN_PK,ORDER_SEQ,CUST_ALPHA_NO,PSC,PSC_DESC,MSC,MSC_DESC,MSC_STYLE,
       USE_CODE,USE_DESC,PRD_CLS,PRODUCCODE,PRODUCNAME,STD_CODE,STD_NAME,STEELCODE,
       STEELNAME,STD_STYLE,STD_STYLE_DESC,ORDER_SPEC_CODE,ORDER_SPEC_DESC,SPEC_CODE,
       SPEC_NAME,DIMATER,HEIGHT,MODEL_CODE,MODEL_DESC,LEN_NO,LEN_DESC,LEN_UNIT,LEN_MIN,
       LEN_MAX,SHRT_LEN_RATO,SHORTEST,LONG_LEN_RATO,LONGEST,SHRT_STOVE,AVG_LEN_MIN,
       DIFRNC_LEN_MAX,ENDLEN_SPECSTD,SIGL_LEN,ORDER_UNIT,ORDER_QTY,ORD_ENSU_TOTL_LEN,
       PRDCT_WGT,DELVRY_RANGE_TPE,DELVRY_RANGE_MIN,DELVRY_RANGE_MAX,FINAL_USER,
       FINAL_USER_DESC,OUTS_BILLET_FL,OUTS_STL_PIPE_FL,ASSEL_FL,PRODUCER_FL,PRDCR_NO,
       PRDCR_DESC,MPS_FL,MPS_NO,MPS_DESC,DELVRY_BDATE,DELVRY_EDATE,DELVRY_DESC,TRANS_DESC,
       ADD_ASK_NO,ORDER_ADD_DESC,ORDER_SPECIAL_FL,ORDER_SPECIAL_HEAD,ORDER_SPECIAL_PATH,
       ORDER_SPECIAL_DESC,ZBS,ORDER_PRICE,TRANS_PRICE,TEST_ID,TEST_PRICE,OUT_PRICE,
       BALNCE_PRICE,BE_ORDER_LN_STATUS,BE_OBJ_STS_OP,ORDER_LN_STATUS,OBJ_STS_OP, MEMO,
       VALIDFLAG,CREATE_NAME,CREATE_TIME,UPDATE_NAME,UPDATE_TIME,DELETE_NAME,
       DELETE_TIME,ORD_LN_PK_OLD
  FROM SLM_ORDER_LINE T
 WHERE T.ORD_LN_PK = ?
   AND T.VALIDFLAG = '1'
         ]]>
	</query>


	<query id="QualityDesignFallback.addListItemStartStatusItem"
		desc="新增回退起始点明细状态">
         <![CDATA[
              INSERT INTO SLM_ORD_DESIGN_STS_TKLG_LST(
        DESGIN_KEY,
        ORD_LN_PK,
        SEQ_INDEX,
        LST_ITEM,
        DESIGN_STS,
        DESIGN_STS_RS,
        DESIGN_STS_DESC,
        PSC,
        MSC,
        USE_CODE,
        FINAL_USER,
        GRADECODE,
        DESIGN_OBJ_KEY,
        UNIT_CODE,
        UNIT_DESC,
        VALIDFLAG,
        CREATE_NAME,
        CREATE_TIME,
        UPDATE_NAME,
        UPDATE_TIME,
        DELETE_NAME,
        DELETE_TIME)
 VALUES( 
         SYS_GUID(),
        '#ORD_LN_PK#',
        '#SEQ_INDEX#',
        '#LST_ITEM#',
        '#DESIGN_STS#',
        '#DESIGN_STS_RS#',
        '#DESIGN_STS_DESC#',
        '#PSC#',
        '#MSC#',
        '#USE_CODE#',
        '#FINAL_USER#',
        '#GRADECODE#',
        '#DESIGN_OBJ_KEY#',
        '#UNIT_CODE#',
        '#UNIT_DESC#',
        '#VALIDFLAG#',
        '#CREATE_NAME#',
        SYSDATE,
        '#UPDATE_NAME#',
        SYSDATE,
        NULL,
        NULL)
         ]]>
	</query>

	<query id="QualityDesignFallback.updateListItemEndStatusItem"
		desc="修改回退点明细状态">
         <![CDATA[        
         UPDATE SLM_ORD_DESIGN_STS_TKLG_LST T
   SET T.DESIGN_STS      = '#DESIGN_STS#',
       T.DESIGN_STS_RS   = '#DESIGN_STS_RS#',
       T.DESIGN_STS_DESC = '#DESIGN_STS_DESC#',
       CREATE_NAME       = '#CREATE_NAME#',
       CREATE_TIME       = SYSDATE
 WHERE T.DESGIN_KEY = '#DESGIN_KEY#'
   AND T.ORD_LN_PK = '#ORD_LN_PK#'
   AND T.SEQ_INDEX = '#SEQ_INDEX#'
   AND T.LST_ITEM = '#LST_ITEM#'
   AND T.VALIDFLAG = '1'
         ]]>
	</query>

	<query id="QualityDesignFallback.getCraftBackLogProcess" desc="获取工艺中的制程和工序">
         <![CDATA[
SELECT T.MSC_PLINE,
       MIN(T.WHOLE_BACKLOG) WHOLE_BACKLOG,
       MIN(T.WHOLE_BACKLOG_DESC) WHOLE_BACKLOG_DESC,
       MIN(T.PROCESS_DESC) PROCESS_DESC,
       MIN(T.PROCESS_CODE) PROCESS_CODE,
       C.PIC,
       MIN(b.DIMATER) DIMATER,
       MIN(b.HEIGHT) HEIGHT
  FROM CRAFT_ORD_DESIGN_MSC_PL_PRC T,
       CRAFT_ORD_DESIGN            A,
       CRAFT_ORD_DESIGN_MSC_GZ_GG  B,
       CRAFT_ORD_DESIGN_STD_PIC    C
 WHERE A.ORD_LN_PK = {0}
   AND A.CRAFT_SEQ = {1}
   AND T.DESGIN_KEY = A.DESGIN_KEY
   AND B.DESGIN_KEY = A.DESGIN_KEY
   AND C.DESGIN_KEY = A.DESGIN_KEY
   AND C.PROCESS_CODE = T.PROCESS_CODE
   AND C.MSC_PLINE = T.MSC_PLINE
 GROUP BY T.MSC_PLINE, T.PROCESS_CODE, C.PIC
UNION ALL
SELECT T.MSC_PLINE,
       MIN(T.WHOLE_BACKLOG) WHOLE_BACKLOG,
       MIN(T.WHOLE_BACKLOG_DESC) WHOLE_BACKLOG_DESC,
       MIN(T.PROCESS_DESC) PROCESS_DESC,
       MIN(T.PROCESS_CODE) PROCESS_CODE,
       C.PIC,
       MIN(b.DIMATER) DIMATER,
       MIN(b.HEIGHT) HEIGHT
  FROM CRAFT_ORD_DESIGN_MSC_PL_PRC T,
       CRAFT_ORD_DESIGN            A,
       CRAFT_ORD_DESIGN_MSC        B,
       CRAFT_ORD_DESIGN_STD_PIC    C
 WHERE A.ORD_LN_PK = {0}
   AND A.CRAFT_SEQ = {1}
   AND T.DESGIN_KEY = A.DESGIN_KEY
   AND B.DESGIN_KEY = A.DESGIN_KEY
   AND C.DESGIN_KEY = A.DESGIN_KEY
   AND C.PROCESS_CODE = T.PROCESS_CODE
   AND C.MSC_PLINE = T.MSC_PLINE
   AND EXISTS (SELECT 1
          FROM CRAFT_ORD_DESIGN_MSC_PL_PRC T2
         WHERE T2.DESGIN_KEY = T.DESGIN_KEY
           AND T2.PROCESS_CODE = 'E')
 GROUP BY T.MSC_PLINE, T.PROCESS_CODE, C.PIC
         ]]>
	</query>
</queryMap>