<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="成分内控标准">
	<query id="CoreInnerMSCRGRD2.QueryMscStdCic" desc="查询化学元素标准索引">
			<![CDATA[
			 SELECT CIC,
	       PSC,
	       DECODE(STDSTYLE,'N','内控','K','客户','G','国标') STDSTYLE,
	       STD_CODE_NK,
	       STD_NAME_NK,
	       PROCESS_CODE,
	       PROCESS_DESC,
	       GRADECODE,
	       GRADENAME,
	       STD_CODE,
	       STD_NAME,
	       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,
	       DELETE_NAME,
	       TO_CHAR(DELETE_TIME,'yyyy-mm-dd hh24:mi:ss') DELETE_TIME,
	       DECODE(VALIDFLAG,'1','有效','无效') VALIDFLAGNAME,
	       MEMO
	       FROM COM_MSC_STD_CIC
	       WHERE
	       DECODE(?, NULL, '1', STD_NAME_NK) LIKE DECODE(?, NULL, '1', '%' || ? || '%')
	       AND  DECODE(?, NULL, '1', PROCESS_DESC) LIKE DECODE(?, NULL, '1', '%' || ? || '%')
	       AND  DECODE(?, NULL, '1', GRADENAME) LIKE DECODE(?, NULL, '1', '%' || ? || '%')
	       AND VALIDFLAG = '1'
	       AND STDSTYLE='N'
	       ORDER BY CIC 
			]]>
	</query>

	<query id="CoreInnerMSCRGRD2.QueryMscStdChem" desc="查询化学元素标准">
			<![CDATA[
			SELECT 
			   A.CIC,
		       A.INDEX_SEQ,
		       A.CHEM_CODE,
		       A.CHEM_NAME,
		       DECODE(A.CHEM_TYPE,'A','单一元素','复合元素') CHEM_TYPE,
		       A.CHEM_FORMULA,
		       DECODE(A.ISCHECK,'1','TRUE','FALSE') ISCHECK,
		       A.STDMIN_SIGN,
		       A.STDMIN,
		       A.STDMAX_SIGN,
		       A.STDMAX,
		       A.STDTARGET,
		       A.MODEL_CODE,
		       A.MODEL_DESC,
		       A.STDMEMO,
		       A.SPEC_JG,
		       A.SPEC_JG_DESC,
		       A.CREATE_NAME,
		       TO_CHAR(A.CREATE_TIME,'yyyy-mm-dd hh24:mi:ss') CREATE_TIME,
		       A.UPDATE_NAME,
		       TO_CHAR(A.UPDATE_TIME,'yyyy-mm-dd hh24:mi:ss') UPDATE_TIME,
		       A.DELETE_NAME,
		       TO_CHAR(A.DELETE_TIME,'yyyy-mm-dd hh24:mi:ss') DELETE_TIME,
		       DECODE(A.VALIDFLAG,'1','有效','无效') VALIDFLAGNAME
		       FROM COM_MSC_STD_CHEM A
		       WHERE A.VALIDFLAG = '1'
		       AND EXISTS(SELECT 1 FROM COM_MSC_STD_CIC B WHERE
		       				   DECODE(?, NULL, '1', STD_NAME_NK) LIKE DECODE(?, NULL, '1', '%' || ? || '%')
						       AND  DECODE(?, NULL, '1', PROCESS_DESC) LIKE DECODE(?, NULL, '1', '%' || ? || '%')
						       AND  DECODE(?, NULL, '1', GRADENAME) LIKE DECODE(?, NULL, '1', '%' || ? || '%')
						       AND B.VALIDFLAG = '1'
						       AND B.STDSTYLE='N'
						       AND A.CIC = B.CIC)
		       ORDER BY A.INDEX_SEQ 
			]]>
	</query>
	
	<query id="CoreInnerMSCRGRD2.QueryMscGrade" desc="查询全程产线号与钢种对应关系">
			<![CDATA[
			SELECT MSC,
			   CIC,
		       MSC_PLINE,
		       GRADECODE,
		       GRADENAME,
		       ASSORTMENT_CODE,
		       ASSORTMENT_NAME,
		       CREATE_NAME,
		       CREATE_TIME,
		       UPDATE_NAME,
		       UPDATE_TIME,
		       DELETE_NAME,
		       DELETE_TIME,
		       VALIDFLAG,
		       MEMO
		  FROM COM_MSC_GRADE
		 WHERE MSC = ?
		   AND MSC_PLINE = ?
		   AND VALIDFLAG = '1'
			]]>
	</query>
	
	<query id="CoreInnerMSCRGRD2.InsertMscGrade" desc="添加全程产线号与钢种对应关系">
			<![CDATA[
			DECLARE
			P_COUNT NUMBER(5);
			P_DELETE_FLAG VARCHAR(10) := ?;
			P_MSC COM_MSC_GRADE.MSC%TYPE := ?;
			P_MSC_PLINE COM_MSC_GRADE.MSC_PLINE%TYPE := ?;
			P_CIC COM_MSC_GRADE.CIC%TYPE := ?;
			P_GRADECODE COM_MSC_GRADE.GRADECODE%TYPE := ?;
			P_GRADENAME COM_MSC_GRADE.GRADENAME%TYPE := ?;
			P_ASSORTMENT_CODE COM_BASE_GRADE.ASSORTMENT_CODE%TYPE := ?;
			P_ASSORTMENT_NAME COM_BASE_GRADE.ASSORTMENT_NAME%TYPE := ?;
			P_STD_CODE COM_MSC_GRADE.STD_CODE%TYPE := ?;
			P_STD_NAME COM_MSC_GRADE.STD_NAME%TYPE := ?;
			P_NAME COM_MSC_GRADE.CREATE_NAME%TYPE := ?;
			P_MEMO COM_MSC_GRADE.MEMO%TYPE := ?;
			
			BEGIN
			SELECT COUNT(1) INTO P_COUNT FROM COM_MSC_GRADE WHERE MSC = P_MSC AND MSC_PLINE = P_MSC_PLINE
			       AND GRADECODE = P_GRADECODE;
			IF P_DELETE_FLAG = 'DELETE' THEN
			   IF P_COUNT > 0 THEN
			      UPDATE COM_MSC_GRADE SET VALIDFLAG = '0', DELETE_NAME = P_NAME,
			             DELETE_TIME = SYSDATE WHERE MSC = P_MSC AND MSC_PLINE = P_MSC_PLINE
			             AND GRADECODE = P_GRADECODE;
			      UPDATE COM_MSC_GRADE_R_SPEC T
					   SET T.VALIDFLAG = '0'
					 WHERE T.MSC = P_MSC
					   AND T.MSC_PLINE = P_MSC_PLINE
					   AND T.GRADECODE = P_GRADECODE;
			   END IF;
			ELSE
			    IF P_COUNT > 0 THEN
			       UPDATE COM_MSC_GRADE SET VALIDFLAG = '1', DELETE_NAME = '',
			             DELETE_TIME = '', UPDATE_NAME = P_NAME, UPDATE_TIME = SYSDATE
			             WHERE MSC = P_MSC AND MSC_PLINE = P_MSC_PLINE
			             AND GRADECODE = P_GRADECODE;
			    ELSE
			        INSERT INTO COM_MSC_GRADE
							  (MSC,
							   MSC_PLINE,
							   CIC,
							   GRADECODE,
							   GRADENAME,
							   ASSORTMENT_CODE,
							   ASSORTMENT_NAME,
							   STD_CODE,
							   STD_NAME,
							   CREATE_NAME,
							   CREATE_TIME,
							   VALIDFLAG,
							   MEMO)
							VALUES
							  (P_MSC,
							   P_MSC_PLINE,
							   P_CIC,
							   P_GRADECODE,
							   P_GRADENAME,
							   (SELECT ASSORTMENT_CODE FROM COM_BASE_GRADE WHERE GRADECODE = P_ASSORTMENT_CODE),
							   (SELECT ASSORTMENT_NAME FROM COM_BASE_GRADE WHERE GRADECODE = P_ASSORTMENT_NAME),
							   P_STD_CODE,
							   P_STD_NAME,
							   P_NAME,
							   SYSDATE,
							   '1',
							   P_MEMO);
			    END IF;
			END IF;
			END;
			]]>
	</query>
	
	<query id="CoreInnerMSCRGRD2.queryStdNkCnt" desc="查询所选择的内控标准索引号，所对应的内控标准是否唯一">
			<![CDATA[
			SELECT COUNT(DISTINCT STD_CODE_NK)
			  FROM (SELECT T.STD_CODE_NK
			          FROM com_msc_std_pic T
			         WHERE T.PIC IN (:PIC:)
			           AND T.VALIDFLAG = '1'
			        UNION ALL
			        SELECT STD_CODE_NK
			          FROM COM_MSC_STD_CIC A
			         WHERE A.CIC IN (:CIC:)
			           AND A.VALIDFLAG = '1'
			        UNION ALL
			        SELECT STD_CODE STD_CODE_NK
			          FROM COM_MSC_STD_SPEC B
			         WHERE B.SIC IN (:SIC:)
			           AND B.VALIDFLAG = '1'
			        UNION ALL
			        SELECT STD_CODE_NK
			          FROM COM_MSC_STD_DETECTION C
			         WHERE C.DIC IN (:DIC:)
			           AND C.VALIDFLAG = '1'
			        UNION ALL
			        SELECT STD_CODE_NK
			          FROM COM_MSC_STD_WATER D
			         WHERE D.WIC IN (:WIC:)
			           AND D.VALIDFLAG = '1')
			]]>
	</query>
	
	<query id="CoreInnerMSCRGRD2.isUsedGrade" desc="是否被使用">
			<![CDATA[
SELECT 1
      FROM COM_MSC_STD_CIC T
     WHERE EXISTS (SELECT 1
              FROM COM_MSC_PROCESS A
             WHERE A.MSC = '#MSC#'
               AND A.MSC_PLINE = '#MSC_PLINE#'
               AND INSTR(A.CIC, T.CIC) > 0)
       AND T.GRADECODE = '#GRADECODE#'
			]]>
	</query>
	
	<query id="CoreInnerMSCRGRD2.copyStandPay" desc="复制交付标准">
		<![CDATA[
DECLARE
  P_MSC_SEQ       COM_MSC.MSC_SEQ%TYPE;
  P_IC            COM_MSC_STD_CIC.CIC%TYPE;
  P_PRODUCCODE    COM_PSC.PRODUCCODE%TYPE;
  P_PRODUCNAME    COM_PSC.PRODUCNAME%TYPE;
  P_STEELCODE     COM_PSC.STEELCODE%TYPE;
  P_STEELNAME     COM_PSC.STEELNAME%TYPE;
  P_PROCESS_CODES COM_BASE_STD.PROCESS_CODE%TYPE;
  P_PROCESS_DESCS COM_BASE_STD.PROCESS_DESC%TYPE;
  P_STATION_TYPES VARCHAR2(3000);
  P_GRADE_CODES   VARCHAR2(3000);
  P_GRADE_NAMES   VARCHAR2(3000);
  P_INSERT_CIC    VARCHAR2(1) := '0';
  P_INSERT_PIC    VARCHAR2(1) := '0';
  P_INSERT_SIC    VARCHAR2(1) := '0';
  P_INSERT_DIC    VARCHAR2(1) := '0';
  P_INSERT_WIC    VARCHAR2(1) := '0';
  P_INSERT_GIC    VARCHAR2(1) := '0';

BEGIN
  SELECT MSC_SEQ INTO P_MSC_SEQ FROM COM_MSC WHERE MSC = '#MSC#';
  SELECT A.PRODUCCODE, A.STEELCODE, A.PRODUCNAME, A.STEELNAME
    INTO P_PRODUCCODE, P_STEELCODE, P_PRODUCNAME, P_STEELNAME
    FROM COM_PSC A, COM_PSC_R_MSC B, COM_MSC C
   WHERE A.PSC = B.PSC
     AND B.MSC = C.MSC
     AND C.MSC = '#MSC#';

  SELECT PROCESS_CODE, PROCESS_DESC
    INTO P_PROCESS_CODES, P_PROCESS_DESCS
    FROM COM_BASE_STD
   WHERE STD_CODE = '#STD_CODE_NK#';

  SELECT WM_CONCAT(STATION_TYPE)
    INTO P_STATION_TYPES
    FROM COM_MSC_STATION T
   WHERE T.MSC = '#MSC#'
     AND T.MSC_PLINE = '#MSC_PLINE#'
     AND T.PROCESS_CODE = '#PROCESS_CODE#';

  SELECT LISTAGG(T.GRADECODE, ';') WITHIN GROUP(ORDER BY T.GRADENAME)
    INTO P_GRADE_CODES
    FROM COM_MSC_GRADE T
   WHERE T.MSC = '#MSC#'
     AND T.MSC_PLINE = '#MSC_PLINE#'
     AND T.VALIDFLAG = '1';
  SELECT LISTAGG(T.GRADENAME, ';') WITHIN GROUP(ORDER BY T.GRADENAME)
    INTO P_GRADE_NAMES
    FROM COM_MSC_GRADE T
   WHERE T.MSC = '#MSC#'
     AND T.MSC_PLINE = '#MSC_PLINE#'
     AND T.VALIDFLAG = '1';

  IF INSTR(P_STATION_TYPES, '403201') > 0 AND 1 > 1 THEN
    FOR V_ROW IN (SELECT *
                    FROM COM_MSC_STD_CIC T
                   WHERE MSC = '#MSC#'
                     AND T.VALIDFLAG <> '0'
                  UNION ALL
                  SELECT *
                    FROM COM_MSC_STD_CIC T
                   WHERE MSC = P_MSC_SEQ
                     AND T.VALIDFLAG <> '0') LOOP
    
      IF (P_INSERT_CIC = '0') THEN
        P_INSERT_CIC := '1';
        SELECT 'CICN' ||
               LPAD(((TO_NUMBER(NVL(SUBSTR(MAX(CIC), 5, 6), 000000))) + 1),
                    6,
                    '0')
          INTO P_IC
          FROM COM_MSC_STD_CIC
         WHERE STDSTYLE = 'N';
      
        IF ('#GRADE_CODE#' IS NULL) THEN
          RAISE_APPLICATION_ERROR(-20000, '请至少选择一个制程钢种！');
        END IF;
      
        INSERT INTO COM_MSC_STD_CIC
          (CIC,
           STDSTYLE,
           STD_CODE_NK,
           STD_NAME_NK,
           PROCESS_CODE,
           PROCESS_DESC,
           CREATE_NAME,
           CREATE_TIME,
           VALIDFLAG,
           PRODUC_HEAD,
           MEMO,
           GRADECODE,
           GRADENAME,
           PRODUCCODE_NK,
           PRODUCNAME_NK,
           STEELCODE_NK,
           STEELNAME_NK)
        VALUES
          (P_IC, --5
           'N',
           '#STD_CODE_NK#',
           '#STD_NAME_NK#',
           P_PROCESS_CODES,
           P_PROCESS_DESCS,
           '#CREATE_NAME#',
           SYSDATE,
           '1',
           V_ROW.PRODUC_HEAD,
           NVL(V_ROW.MEMO, '交付标准复制数据'),
           '#GRADE_CODE#',
           '#GRADE_NAME#',
           P_PRODUCCODE,
           P_PRODUCNAME,
           P_STEELCODE,
           P_STEELNAME);
      END IF;
    
      INSERT INTO COM_MSC_STD_CHEM
        (CIC,
         INDEX_SEQ,
         CHEM_CODE,
         CHEM_NAME,
         CHEM_TYPE,
         CHEM_FORMULA,
         ISCHECK,
         ISJUDGE,
         ISQUOTE,
         COMPLEX_TYPE,
         STDMIN_SIGN,
         STDMIN,
         STDMAX_SIGN,
         STDMAX,
         STDTARGET,
         MODEL_CODE,
         MODEL_DESC,
         STDMEMO,
         ELE_CODE,
         ELE_NAME,
         ELE_MIN_SIGN,
         ELE_MIN,
         ELE_MAX_SIGN,
         ELE_MAX,
         SIZE_CODE2,
         SIZE_NAME2,
         SIZE_MIN_SIGN2,
         SIZE_MIN2,
         SIZE_MAX_SIGN2,
         SIZE_MAX2,
         SIZE_CODE,
         SIZE_NAME,
         SIZE_MIN_SIGN,
         SIZE_MIN,
         SIZE_MAX_SIGN,
         SIZE_MAX,
         SPEC_JG,
         SPEC_JG_DESC,
         CREATE_NAME,
         CREATE_TIME,
         VALIDFLAG,
         REP_CODE,
         REP_NAME,
         REP_MIN_SIGN,
         REP_MIN,
         REP_MAX_SIGN,
         REP_MAX,
         REP_VAL)
        (SELECT P_IC,
                (SELECT NVL(MAX(INDEX_SEQ), 0)
                   FROM COM_MSC_STD_CHEM A
                  WHERE A.CIC = P_IC) + ROWNUM,
                T.CHEM_CODE,
                T.CHEM_NAME,
                T.CHEM_TYPE,
                T.CHEM_FORMULA,
                T.ISCHECK,
                T.ISJUDGE,
                T.ISQUOTE,
                T.COMPLEX_TYPE,
                T.STDMIN_SIGN,
                T.STDMIN,
                T.STDMAX_SIGN,
                T.STDMAX,
                T.STDTARGET,
                T.MODEL_CODE,
                T.MODEL_DESC,
                T.STDMEMO,
                T.ELE_CODE,
                T.ELE_NAME,
                T.ELE_MIN_SIGN,
                T.ELE_MIN,
                T.ELE_MAX_SIGN,
                T.ELE_MAX,
                T.SIZE_CODE2,
                T.SIZE_NAME2,
                T.SIZE_MIN_SIGN2,
                T.SIZE_MIN2,
                T.SIZE_MAX_SIGN2,
                T.SIZE_MAX2,
                T.SIZE_CODE,
                T.SIZE_NAME,
                T.SIZE_MIN_SIGN,
                T.SIZE_MIN,
                T.SIZE_MAX_SIGN,
                T.SIZE_MAX,
                T.SPEC_JG,
                T.SPEC_JG_DESC,
                '#CREATE_NAME#',
                SYSDATE,
                '1',
                T.REP_CODE,
                T.REP_NAME,
                T.REP_MIN_SIGN,
                T.REP_MIN,
                T.REP_MAX_SIGN,
                T.REP_MAX,
                T.REP_VAL
           FROM COM_MSC_STD_CHEM T
          WHERE T.CIC = V_ROW.CIC
            AND T.VALIDFLAG <> '0'
            AND NOT EXISTS (SELECT 1
                   FROM COM_MSC_STD_CHEM A
                  WHERE A.CIC = P_IC
                    AND A.CHEM_CODE = T.CHEM_CODE));
    
    END LOOP;
  END IF;

  IF INSTR(P_STATION_TYPES, '403202') > 0 AND 1 > 1 THEN
    FOR V_ROW IN (SELECT *
                    FROM COM_MSC_STD_PIC T
                   WHERE MSC = '#MSC#'
                     AND T.VALIDFLAG <> '0'
                  UNION ALL
                  SELECT *
                    FROM COM_MSC_STD_PIC T
                   WHERE MSC = P_MSC_SEQ
                     AND T.VALIDFLAG <> '0') LOOP
    
      IF P_INSERT_PIC = '0' THEN
        P_INSERT_PIC := '1';
        SELECT 'PICN' ||
               LPAD(((TO_NUMBER(NVL(SUBSTR(MAX(PIC), 5, 6), 000000))) + 1),
                    6,
                    '0')
          INTO P_IC
          FROM COM_MSC_STD_PIC
         WHERE STDSTYLE = 'N';
      
        INSERT INTO COM_MSC_STD_PIC
          (PIC,
           STDSTYLE,
           STD_CODE_NK,
           STD_NAME_NK,
           PROCESS_CDOE,
           PROCESS_DESC,
           CREATE_NAME,
           CREATE_TIME,
           VALIDFLAG,
           STEELCODE,
           STEELNAME,
           GRADECODE,
           GRADENAME,
           MEMO,
           PRODUCCODE_NK,
           PRODUCNAME_NK,
           STEELCODE_NK,
           STEELNAME_NK)
        VALUES
          (P_IC,
           'N',
           '#STD_CODE_NK#',
           '#STD_NAME_NK#',
           P_PROCESS_CODES,
           P_PROCESS_DESCS,
           '#CREATE_NAME#',
           SYSDATE,
           '1',
           V_ROW.STEELCODE,
           V_ROW.STEELNAME,
           P_GRADE_CODES,
           P_GRADE_NAMES,
           NVL(V_ROW.MEMO, '交付标准复制数据'),
           P_PRODUCCODE,
           P_PRODUCNAME,
           P_STEELCODE,
           P_STEELNAME);
      END IF;
    
      INSERT INTO COM_MSC_STD_PHY
        (PIC,
         INDEX_SEQ,
         PHY_CODE_MAX,
         PHY_NAME_MAX,
         PHY_CODE_MIN,
         PHY_NAME_MIN,
         PHY_CODE,
         PHY_NAME,
         ITEM_CODE_F,
         ITEM_NAME_F,
         ITEM_CODE_W,
         ITEM_NAME_W,
         ITEM_CODE_S,
         ITEM_NAME_S,
         GROUP_SEQ,
         RESULT_COUNT,
         ISCHECK,
         ISJUDGE,
         ISQUOTE,
         PHY_TYPE,
         PHY_FORMULA,
         STDMIN_SIGN,
         STDMIN,
         STDMAX_SIGN,
         STDMAX,
         JUDGE_BASIS,
         DELIVERYSTATE,
         MODEL_CODE,
         MODEL_DESC,
         STDMEMO,
         SIZE_CODE2,
         SIZE_NAME2,
         SIZE_MIN_SIGN2,
         SIZE_MIN2,
         SIZE_MAX_SIGN2,
         SIZE_MAX2,
         SIZE_CODE,
         SIZE_NAME,
         SIZE_MIN_SIGN,
         SIZE_MIN,
         SIZE_MAX_SIGN,
         SIZE_MAX,
         SPEC_JG,
         SPEC_JG_DESC,
         CREATE_NAME,
         CREATE_TIME,
         VALIDFLAG,
         ADDCONDITION,
         ADDSTDCON_CODE,
         ADDSTD_MIN_SIGN,
         ADDSTD_MIN,
         ADDSTD_MAX_SIGN,
         ADDSTD_MAX,
         ADDPERCENT,
         STDMIN_SIGN2,
         STDMIN2,
         STDMAX_SIGN2,
         STDMAX2,
         STD_CHOOSE,
         GUID)
        (SELECT P_IC,
                (SELECT NVL(MAX(INDEX_SEQ), 0)
                   FROM COM_MSC_STD_PHY A
                  WHERE A.PIC = P_IC) + ROWNUM,
                T.PHY_CODE_MAX,
                T.PHY_NAME_MAX,
                T.PHY_CODE_MIN,
                T.PHY_NAME_MIN,
                T.PHY_CODE,
                T.PHY_NAME,
                T.ITEM_CODE_F,
                T.ITEM_NAME_F,
                T.ITEM_CODE_W,
                T.ITEM_NAME_W,
                T.ITEM_CODE_S,
                T.ITEM_NAME_S,
                NULL,
                T.RESULT_COUNT,
                T.ISCHECK,
                T.ISJUDGE,
                T.ISQUOTE,
                T.PHY_TYPE,
                T.PHY_FORMULA,
                T.STDMIN_SIGN,
                T.STDMIN,
                T.STDMAX_SIGN,
                T.STDMAX,
                T.JUDGE_BASIS,
                T.DELIVERYSTATE,
                T.MODEL_CODE,
                T.MODEL_DESC,
                T.STDMEMO,
                T.SIZE_CODE2,
                T.SIZE_NAME2,
                T.SIZE_MIN_SIGN2,
                T.SIZE_MIN2,
                T.SIZE_MAX_SIGN2,
                T.SIZE_MAX2,
                T.SIZE_CODE,
                T.SIZE_NAME,
                T.SIZE_MIN_SIGN,
                T.SIZE_MIN,
                T.SIZE_MAX_SIGN,
                T.SIZE_MAX,
                T.SPEC_JG,
                T.SPEC_JG_DESC,
                '#CREATE_NAME#',
                SYSDATE,
                '1',
                T.ADDCONDITION,
                T.ADDSTDCON_CODE,
                T.ADDSTD_MIN_SIGN,
                T.ADDSTD_MIN,
                T.ADDSTD_MAX_SIGN,
                T.ADDSTD_MAX,
                T.ADDPERCENT,
                T.STDMIN_SIGN2,
                T.STDMIN2,
                T.STDMAX_SIGN2,
                T.STDMAX2,
                T.STD_CHOOSE,
                T.GUID
           FROM COM_MSC_STD_PHY T
          WHERE T.PIC = V_ROW.PIC
            AND T.VALIDFLAG <> '0'
            AND NOT EXISTS
          (SELECT 1
                   FROM COM_MSC_STD_PHY A
                  WHERE A.PIC = P_IC
                    AND A.PHY_CODE_MAX = T.PHY_CODE_MAX
                    AND A.PHY_CODE_MIN = T.PHY_CODE_MIN
                    AND A.PHY_CODE = T.PHY_CODE
                    AND NVL(A.ITEM_CODE_F, '1') = NVL(T.ITEM_CODE_F, '1')
                    AND NVL(A.ITEM_CODE_W, '1') = NVL(T.ITEM_CODE_W, '1')
                    AND NVL(A.ITEM_CODE_S, '1') = NVL(T.ITEM_CODE_S, '1')));
    END LOOP;
  END IF;

  IF INSTR(P_STATION_TYPES, '403204') > 0 AND 1 > 1 THEN
    FOR V_ROW IN (SELECT *
                    FROM COM_MSC_STD_DETECTION T
                   WHERE MSC = '#MSC#'
                     AND T.VALIDFLAG <> '0'
                  UNION ALL
                  SELECT *
                    FROM COM_MSC_STD_DETECTION T
                   WHERE MSC = P_MSC_SEQ
                     AND T.VALIDFLAG <> '0') LOOP
      IF P_INSERT_DIC = '0' THEN
        P_INSERT_DIC := '1';
        SELECT 'DICN' ||
               LPAD(((TO_NUMBER(NVL(SUBSTR(MAX(DIC), 5, 6), 000000))) + 1),
                    6,
                    '0')
          INTO P_IC
          FROM COM_MSC_STD_DETECTION
         WHERE STDSTYLE = 'N';
      
        INSERT INTO COM_MSC_STD_DETECTION
          (DIC,
           STDSTYLE,
           PROCESS_CODE,
           PROCESS_DESC,
           STD_CODE_NK,
           STD_NAME_NK,
           CREATE_NAME,
           CREATE_TIME,
           VALIDFLAG,
           PRODUC_HEAD,
           MEMO,
           PRODUCCODE_NK,
           PRODUCNAME_NK,
           STEELCODE_NK,
           STEELNAME_NK)
        VALUES
          (P_IC,
           'N',
           P_PROCESS_CODES,
           P_PROCESS_DESCS,
           '#STD_CODE_NK#',
           '#STD_NAME_NK#',
           '#CREATE_NAME#',
           SYSDATE,
           '1',
           V_ROW.PRODUC_HEAD,
           NVL(V_ROW.MEMO, '交付标准复制数据'),
           P_PRODUCCODE,
           P_PRODUCNAME,
           P_STEELCODE,
           P_STEELNAME);
      END IF;
    
      INSERT INTO COM_MSC_STD_DETECTION_C
        (DIC,
         XH,
         PHY_CODE,
         PHY_NAME,
         POSITION_CODE,
         POSITION_DESC,
         STD_DESC,
         LV_CODE,
         GROOVE_POS,
         GROOVE_DIR,
         LV_DESC,
         COVERAGE,
         CREATE_NAME,
         CREATE_TIME,
         VALIDFLAG,
         MEMO,
         RATE,
         DESC_RATE,
         DESC_VAL,
         GROUP_SEQ,
         MIN_D,
         MAX_D,
         MIN_H,
         MAX_H,
         MIN_D_SIGN,
         MAX_D_SIGN,
         MIN_H_SIGN,
         MAX_H_SIGN)
        (SELECT P_IC,
                (SELECT NVL(MAX(xh), 0)
                   FROM COM_MSC_STD_DETECTION_C A
                  WHERE A.DIC = P_IC) + ROWNUM,
                T.PHY_CODE,
                T.PHY_NAME,
                T.POSITION_CODE,
                T.POSITION_DESC,
                T.STD_DESC,
                T.LV_CODE,
                T.GROOVE_POS,
                T.GROOVE_DIR,
                T.LV_DESC,
                T.COVERAGE,
                '#CREATE_NAME#',
                SYSDATE,
                '1',
                T.MEMO,
                T.RATE,
                T.DESC_RATE,
                T.DESC_VAL,
                T.GROUP_SEQ,
                T.MIN_D,
                T.MAX_D,
                T.MIN_H,
                T.MAX_H,
                T.MIN_D_SIGN,
                T.MAX_D_SIGN,
                T.MIN_H_SIGN,
                T.MAX_H_SIGN
           FROM COM_MSC_STD_DETECTION_C T
          WHERE T.DIC = V_ROW.DIC
            AND T.VALIDFLAG <> '0'
            AND NOT EXISTS
          (SELECT 1
                   FROM COM_MSC_STD_DETECTION_C A
                  WHERE A.DIC = P_IC
                    AND NVL(A.PHY_CODE, '1') = NVL(T.PHY_CODE, '1')
                    AND NVL(A.POSITION_CODE, '1') =
                        NVL(T.POSITION_CODE, '1')
                    AND NVL(A.STD_DESC, '1') = NVL(T.STD_DESC, '1')
                    AND NVL(A.LV_CODE, '1') = NVL(T.LV_CODE, '1')
                    AND NVL(A.GROOVE_POS, '1') = NVL(T.GROOVE_POS, '1')
                    AND NVL(A.GROOVE_DIR, '1') = NVL(T.GROOVE_DIR, '1')
                    AND NVL(A.COVERAGE, '1') = NVL(T.COVERAGE, '1')
                    AND NVL(A.DESC_RATE, '1') = NVL(T.DESC_RATE, '1')
                    AND NVL(A.DESC_VAL, '1') = NVL(T.DESC_VAL, '1')));
    
    END LOOP;
  END IF;

  IF INSTR(P_STATION_TYPES, '403203') > 0 THEN
    FOR V_ROW IN (SELECT *
                    FROM COM_MSC_STD_SPEC T
                   WHERE MSC = '#MSC#'
                     AND T.VALIDFLAG <> '0'
                  UNION ALL
                  SELECT *
                    FROM COM_MSC_STD_SPEC T
                   WHERE MSC = P_MSC_SEQ
                     AND T.VALIDFLAG <> '0') LOOP
      IF P_INSERT_SIC = '0' THEN
        P_INSERT_SIC := '1';
        SELECT 'SICN' ||
               LPAD(((TO_NUMBER(NVL(SUBSTR(MAX(SIC), 5, 6), 000000))) + 1),
                    6,
                    '0')
          INTO P_IC
          FROM COM_MSC_STD_SPEC
         WHERE STDSTYLE = 'N';
      
        INSERT INTO COM_MSC_STD_SPEC
          (SIC,
           STDSTYLE,
           STD_CODE,
           STD_NAME,
           PROCESS_CODE,
           PROCESS_DESC,
           CREATE_NAME,
           CREATE_TIME,
           VALIDFLAG,
           SPECIAL_PATH,
           PRODUC_HEAD,
           STDMEMO,
           PRODUCCODE_NK,
           PRODUCNAME_NK,
           STEELCODE_NK,
           STEELNAME_NK)
        VALUES
          (P_IC,
           'N',
           '#STD_CODE_NK#',
           '#STD_NAME_NK#',
           P_PROCESS_CODES,
           P_PROCESS_DESCS,
           '#CREATE_NAME#',
           SYSDATE,
           '1',
           V_ROW.SPECIAL_PATH,
           V_ROW.PRODUC_HEAD,
           NVL(V_ROW.STDMEMO, '交付标准复制数据'),
           P_PRODUCCODE,
           P_PRODUCNAME,
           P_STEELCODE,
           P_STEELNAME);
      END IF;
    
      INSERT INTO COM_MSC_STD_SPEC_C
        (SIC,
         INDEX_SEQ,
         BIAS_CODE,
         BIAS_NAME,
         LV,
         BIAS_CODE_Z,
         BIAS_NAME_Z,
         ZMIN_SIGN,
         ZMIN,
         ZMAX_SIGN,
         ZMAX,
         BIAS_CODE_C,
         BIAS_NAME_C,
         CMIN_SIGN,
         CMIN,
         CMAX_SIGN,
         CMAX,
         BIAS_CODE_S,
         BIAS_NAME_S,
         SMIN_SIGN,
         SMIN,
         SMAX_SIGN,
         SMAX,
         ISCHECK,
         STD_MIN_VAL,
         STD_MAX_VAL,
         STD_MIN_IN,
         STD_MAX_IN,
         STD_MIN_PERCENT,
         STD_MAX_PERCENT,
         STD_MIN_FORMULA,
         STD_MAX_FORMULA,
         STD_MIN_FORMULA_V,
         STD_MAX_FORMULA_V,
         STDMEMO,
         CREATE_NAME,
         CREATE_TIME,
         VALIDFLAG,
         GROUP_SEQ)
        (SELECT P_IC,
                (SELECT NVL(MAX(INDEX_SEQ), 0)
                   FROM COM_MSC_STD_SPEC_C A
                  WHERE A.SIC = P_IC) + ROWNUM,
                T.BIAS_CODE,
                T.BIAS_NAME,
                T.LV,
                T.BIAS_CODE_Z,
                T.BIAS_NAME_Z,
                T.ZMIN_SIGN,
                T.ZMIN,
                T.ZMAX_SIGN,
                T.ZMAX,
                T.BIAS_CODE_C,
                T.BIAS_NAME_C,
                T.CMIN_SIGN,
                T.CMIN,
                T.CMAX_SIGN,
                T.CMAX,
                T.BIAS_CODE_S,
                T.BIAS_NAME_S,
                T.SMIN_SIGN,
                T.SMIN,
                T.SMAX_SIGN,
                T.SMAX,
                T.ISCHECK,
                T.STD_MIN_VAL,
                T.STD_MAX_VAL,
                T.STD_MIN_IN,
                T.STD_MAX_IN,
                T.STD_MIN_PERCENT,
                T.STD_MAX_PERCENT,
                T.STD_MIN_FORMULA,
                T.STD_MAX_FORMULA,
                T.STD_MIN_FORMULA_V,
                T.STD_MAX_FORMULA_V,
                T.STDMEMO,
                '#CREATE_NAME#',
                SYSDATE,
                '1',
                T.GROUP_SEQ
           FROM COM_MSC_STD_SPEC_C T
          WHERE T.SIC = V_ROW.SIC
            AND T.VALIDFLAG <> '0'
            AND NOT EXISTS
          (SELECT 1
                   FROM COM_MSC_STD_SPEC_C A
                  WHERE A.SIC = P_IC
                    AND NVL(A.BIAS_CODE, '1') = NVL(T.BIAS_CODE, '1')));
    END LOOP;
  END IF;

  IF INSTR(P_STATION_TYPES, '403205') > 0 THEN
    FOR V_ROW IN (SELECT *
                    FROM COM_MSC_STD_WATER T
                   WHERE MSC = '#MSC#'
                     AND T.VALIDFLAG <> '0'
                  UNION ALL
                  SELECT *
                    FROM COM_MSC_STD_WATER T
                   WHERE MSC = P_MSC_SEQ
                     AND T.VALIDFLAG <> '0') LOOP
      IF P_INSERT_WIC = '0' THEN
        P_INSERT_WIC := '1';
        SELECT 'WICN' ||
               LPAD(((TO_NUMBER(NVL(SUBSTR(MAX(WIC), 5, 6), 000000))) + 1),
                    6,
                    '0')
          INTO P_IC
          FROM COM_MSC_STD_WATER
         WHERE STDSTYLE = 'N';
      
        INSERT INTO COM_MSC_STD_WATER
          (WIC,
           STDSTYLE,
           PROCESS_CDOE,
           PROCESS_DESC,
           STD_CODE_NK,
           STD_NAME_NK,
           MIN_D,
           MAX_D,
           MIN_H,
           MAX_H,
           SPEC_JG,
           SPEC_JG_DESC,
           CREATE_NAME,
           CREATE_TIME,
           VALIDFLAG,
           MEMO,
           PRODUC_HEAD,
           PRODUCCODE_NK,
           PRODUCNAME_NK,
           STEELCODE_NK,
           STEELNAME_NK)
        VALUES
          (P_IC,
           'N',
           P_PROCESS_CODES,
           P_PROCESS_DESCS,
           '#STD_CODE_NK#',
           '#STD_NAME_NK#',
           V_ROW.MIN_D,
           V_ROW.MAX_D,
           V_ROW.MIN_H,
           V_ROW.MAX_H,
           V_ROW.SPEC_JG,
           V_ROW.SPEC_JG_DESC,
           '#CREATE_NAME#',
           SYSDATE,
           '1',
           NVL(V_ROW.MEMO, '交付标准复制数据'),
           V_ROW.PRODUC_HEAD,
           P_PRODUCCODE,
           P_PRODUCNAME,
           P_STEELCODE,
           P_STEELNAME);
      END IF;
    
      INSERT INTO COM_MSC_STD_WATER_C
        (WIC,
         XH,
         PRESSURE_Y,
         PRESSURE,
         FORMULA,
         SAVE_TIME,
         CREATE_NAME,
         CREATE_TIME,
         VALIDFLAG,
         MEMO,
         GET_MAXVALUE,
         GET_MINVALUE)
        (SELECT P_IC,
                (SELECT NVL(MAX(XH), 0)
                   FROM COM_MSC_STD_WATER_C A
                  WHERE A.WIC = P_IC) + ROWNUM,
                T.PRESSURE_Y,
                T.PRESSURE,
                T.FORMULA,
                T.SAVE_TIME,
                '#CREATE_NAME#',
                SYSDATE,
                '1',
                T.MEMO,
                T.GET_MAXVALUE,
                T.GET_MINVALUE
           FROM COM_MSC_STD_WATER_C T
          WHERE T.WIC = V_ROW.WIC
            AND T.VALIDFLAG <> '0'
            AND NOT EXISTS
          (SELECT 1
                   FROM COM_MSC_STD_WATER_C A
                  WHERE A.WIC = P_IC
                    AND NVL(A.PRESSURE_Y, '1') = NVL(T.PRESSURE_Y, '1')
                    AND NVL(A.FORMULA, '1') = NVL(T.FORMULA, '1')
                    AND NVL(A.SAVE_TIME, '1') = NVL(T.SAVE_TIME, '1')));
    END LOOP;
  END IF;

  IF INSTR(P_STATION_TYPES, '403208') > 0 THEN
  
    FOR V_ROW IN (SELECT *
                    FROM COM_MSC_STD_PROCESS T
                   WHERE MSC = '#MSC#'
                     AND T.VALIDFLAG <> '0'
                  UNION ALL
                  SELECT *
                    FROM COM_MSC_STD_PROCESS T
                   WHERE MSC = P_MSC_SEQ
                     AND T.VALIDFLAG <> '0') LOOP
      IF P_INSERT_GIC = '0' THEN
        P_INSERT_GIC := '1';
        SELECT 'GICN' ||
               LPAD(((TO_NUMBER(NVL(SUBSTR(MAX(GIC), 5, 6), 000000))) + 1),
                    6,
                    '0')
          INTO P_IC
          FROM COM_MSC_STD_PROCESS
         WHERE STDSTYLE = 'N';
      
        INSERT INTO COM_MSC_STD_PROCESS
          (GIC,
           STDSTYLE,
           PROCESS_CDOE,
           PROCESS_DESC,
           STD_CODE_NK,
           STD_NAME_NK,
           CREATE_NAME,
           CREATE_TIME,
           VALIDFLAG,
           MEMO,
           PRODUC_HEAD,
           PRODUCCODE_NK,
           PRODUCNAME_NK,
           STEELCODE_NK,
           STEELNAME_NK)
        VALUES
          (P_IC,
           'N',
           P_PROCESS_CODES,
           P_PROCESS_DESCS,
           '#STD_CODE_NK#',
           '#STD_NAME_NK#',
           '#CREATE_NAME#',
           SYSDATE,
           '1',
           NVL(V_ROW.MEMO, '交付标准复制数据'),
           V_ROW.PRODUC_HEAD,
           P_PRODUCCODE,
           P_PRODUCNAME,
           P_STEELCODE,
           P_STEELNAME);
      END IF;
    
      INSERT INTO COM_MSC_STD_PROCESS_C
        (GIC,
         XH,
         STATION_CODE,
         STATION_DESC,
         PROCESS_CDOE,
         PROCESS_DESC,
         PROCESS_CDOE_C,
         PROCESS_DESC_C,
         VALUE_TEXT,
         VALUE_NUM,
         VALUE_MEMO,
         GROUP_SEQ,
         CREATE_NAME,
         CREATE_TIME,
         VALIDFLAG,
         MEMO)
        (SELECT P_IC,
                (SELECT NVL(MAX(XH), 0)
                   FROM COM_MSC_STD_PROCESS_C A
                  WHERE A.GIC = P_IC) + ROWNUM,
                T.STATION_CODE,
                T.STATION_DESC,
                T.PROCESS_CDOE,
                T.PROCESS_DESC,
                T.PROCESS_CDOE_C,
                T.PROCESS_DESC_C,
                T.VALUE_TEXT,
                T.VALUE_NUM,
                T.VALUE_MEMO,
                T.GROUP_SEQ,
                '#CREATE_NAME#',
                SYSDATE,
                '1',
                T.MEMO
           FROM COM_MSC_STD_PROCESS_C T
          WHERE T.GIC = V_ROW.GIC
            AND T.VALIDFLAG <> '0'
            AND NOT EXISTS
          (SELECT 1
                   FROM COM_MSC_STD_PROCESS_C A
                  WHERE A.GIC = P_IC
                    AND NVL(A.STATION_CODE, '1') = NVL(T.STATION_CODE, '1')
                    AND NVL(A.PROCESS_CDOE, '1') = NVL(T.PROCESS_CDOE, '1')
                    AND NVL(A.VALUE_TEXT, '1') = NVL(T.VALUE_TEXT, '1')
                    AND NVL(A.VALUE_NUM, '1') = NVL(T.VALUE_NUM, '1')
                    AND NVL(A.VALUE_MEMO, '1') = NVL(T.VALUE_MEMO, '1')));
    END LOOP;
  END IF;
END;
		]]>
	</query>
	
	<query id="CoreInnerMSCRGRD2.updateMscProcessNk" desc="更新工序表中的内控索引号">
			<![CDATA[
UPDATE COM_MSC_PROCESS T
   SET T.CIC = '#CIC#',
       T.PIC = '#PIC#',
       T.SIC = '#SIC#',
       T.DIC = '#DIC#',
       T.WIC = '#WIC#',
       T.GIC = '#GIC#'
 WHERE T.MSC = '#MSC#'
   AND T.MSC_PLINE = '#MSC_PLINE#'
   AND T.PROCESS_CODE = '#PROCESS_CODE#'
			]]>
	</query>
	
	<query id="CoreInnerMSCRGRD2.getProcessByStdCode" desc="查询内控适用工序">
			<![CDATA[
SELECT T.PROCESS_CODE, T.PROCESS_DESC FROM COM_BASE_STD T WHERE T.STD_CODE = '#STD_CODE#'
			]]>
	</query>
	
	<query id="CoreInnerMSCRGRD2.getProcessNkIndex" desc="获取工序关联的内控索引号">
			<![CDATA[
SELECT *
  FROM COM_MSC_PROCESS T
 WHERE T.MSC = '#MSC#'
   AND T.MSC_PLINE = '#MSC_PLINE#'
   AND T.PROCESS_CODE = '#PROCESS_CODE#'
			]]>
	</query>
	
	<query id="CoreInnerMSCRGRD2.getStdCic" desc="查询成分">
			<![CDATA[
SELECT '成分' STD_TYPE,
       CIC AS IDX,
       STD_NAME_NK,
       PROCESS_DESC,
       GRADENAME,
       MODEL_DESC_NK,
       STEELNAME_NK,
       PRODUCNAME_NK
  FROM COM_MSC_STD_CIC A
 WHERE A.CIC IN (#CICS#)
			]]>
	</query>
	
	<query id="CoreInnerMSCRGRD2.getStdPic" desc="查询理化">
			<![CDATA[
 SELECT '理化' STD_TYPE,
        PIC AS IDX,
        STD_NAME_NK,
        PROCESS_DESC,
        MODEL_DESC_NK,
        STEELNAME_NK,
        PRODUCNAME_NK
   FROM COM_MSC_STD_PIC A
  WHERE A.PIC IN (#PICS#)
			]]>
	</query>
	
	<query id="CoreInnerMSCRGRD2.getStdSic" desc="查询公差">
			<![CDATA[
 SELECT '公差' STD_TYPE,
        SIC AS IDX,
        STD_NAME STD_NAME_NK,
        PROCESS_DESC,
        MODEL_DESC_NK,
        STEELNAME_NK,
        PRODUCNAME_NK
   FROM COM_MSC_STD_SPEC A
  WHERE A.SIC IN (#SICS#)
			]]>
	</query>
	
	<query id="CoreInnerMSCRGRD2.getStdDic" desc="查询探伤">
			<![CDATA[
SELECT '探伤' STD_TYPE,
       DIC AS IDX,
       STD_NAME_NK,
       PROCESS_DESC,
       MODEL_DESC_NK,
       STEELNAME_NK,
       PRODUCNAME_NK
  FROM COM_MSC_STD_DETECTION A
 WHERE A.DIC IN (#DICS#)
			]]>
	</query>
	
	<query id="CoreInnerMSCRGRD2.getStdWic" desc="查询水压">
			<![CDATA[
SELECT '水压' STD_TYPE,
       WIC AS IDX,
       STD_NAME_NK,
       PROCESS_DESC,
       MODEL_DESC_NK,
       STEELNAME_NK,
       PRODUCNAME_NK
  FROM COM_MSC_STD_WATER A
 WHERE A.WIC IN (#WICS#)
			]]>
	</query>
	
	<query id="CoreInnerMSCRGRD2.getStdGic" desc="查询加工">
			<![CDATA[
SELECT '加工' STD_TYPE,
       GIC AS IDX,
       STD_NAME_NK,
       PROCESS_DESC,
       MODEL_DESC_NK,
       STEELNAME_NK,
       PRODUCNAME_NK
  FROM COM_MSC_STD_PROCESS A
 WHERE A.GIC IN (#GICS#)
			]]>
	</query>
	
	<query id="CoreInnerMSCRGRD2.getStdByPk" desc="通过主键查询标准">
			<![CDATA[
SELECT * FROM COM_BASE_STD T WHERE T.STD_CODE = {0}
			]]>
	</query>
	
	<query id="CoreInnerMSCRGRD2.getOrderLineByPk" desc="通过主键查询合同行">
			<![CDATA[
SELECT * FROM SLM_ORDER_LINE T WHERE T.ORD_LN_PK = {0}
			]]>
	</query>
	
	<query id="CoreInnerMSCRGRD2.getBlInfoByPk" desc="通过主键查询备料">
			<![CDATA[
SELECT * FROM COM_MSC_BL T WHERE T.PSC_BL = {0}
			]]>
	</query>
	
	<query id="CoreInnerMSCRGRD2.getSameGradeCnt" desc="获取相同钢种的标准数量">
			<![CDATA[
SELECT COUNT(1) CNT
  FROM COM_MSC_STD_CIC T
 WHERE T.GRADECODE = {0}
   AND T.VALIDFLAG = '1'
   AND T.STD_CODE_NK = {1}
			]]>
	</query>
	
	<query id="CoreInnerMSCRGRD2.getMscGrade" desc="获取相同制程向下的钢种">
			<![CDATA[
SELECT T.GRADECODE, T.GRADENAME
  FROM COM_MSC_GRADE T
 WHERE T.MSC = {0}
   AND T.MSC_PLINE = {1}
   AND T.VALIDFLAG = '1'
			]]>
	</query>
</queryMap>