<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="冶金规范">
		<query id="MscManage.queryPsc" desc="查询产品规范数据">
		<![CDATA[
SELECT T.PSC,
       T.PSC_DESC,
       T.MEMO,
       T.PRODUCCODE,
       T.PRODUCNAME,
       T.STD_CODE,
       T.STD_NAME,
       T.STEELCODE,
       T.STEELNAME,
       T.STD_STYLE,
       T.STD_STYLE_DESC,
       T.NEW_PROC_CODE,
       T.NEW_PROC_DESC,
       A.PRODUC_HEAD,
       DECODE((SELECT B.PSC
                FROM COM_PSC_R_MSC B
               WHERE B.PSC = T.PSC
                 AND B.VALIDFLAG = '1'
                 AND ROWNUM = 1
                 AND EXISTS (SELECT 1
                        FROM COM_MSC
                       WHERE MSC = B.MSC
                         AND VALIDFLAG <> 'D')),
              NULL,
              'False',
              'True') HAVE_MSC
  FROM COM_PSC T
  LEFT JOIN COM_BASE_PRODUCT A
    ON A.PRODUCCODE = T.PRODUCCODE
 WHERE T.VALIDFLAG = '1'
   AND DECODE('#PRODUCCODE#', NULL, '1', T.PRODUCCODE) =
       DECODE('#PRODUCCODE#', NULL, '1', '#PRODUCCODE#')
   AND DECODE('#STD_NAME#', NULL, '1', LOWER(T.STD_NAME)) LIKE
       DECODE('#STD_NAME#', NULL, '1', '%' || LOWER('#STD_NAME#') || '%')
   AND DECODE('#STEELNAME#', NULL, '1', LOWER(T.STEELNAME)) LIKE
       DECODE('#STEELNAME#', NULL, '1', '%' || LOWER('#STEELNAME#') || '%')
   AND DECODE('#PSC#', NULL, '1', T.PSC) =
       DECODE('#PSC#', NULL, '1', '#PSC#')
		]]>
	</query>
	
	<query id="MscManage.queryMsc" desc="根据产品规范码查询冶金规范">
		<![CDATA[
			SELECT T.MSC,
			       A.MSC_DESC,
			       A.MSC_DESC OLD_MSC_DESC,
			       A.USE_CODE,
			       A.USE_CODE OLD_USE_CODE,
			       A.USE_DESC,
			       A.USE_DESC OLD_USE_DESC,
			       A.UNIT_CODE_PROCESS,
			       A.DEPARTMENT_CODE,
			       A.DEPARTMENT_DESC,
			       A.UNIT_CODE,
			       A.UNIT_DESC,
			       A.MSC_STYLE,
			       A.USER_COUNT,
			       A.MSC_SEQ,
			       A.MSC_DESC_SEQ,
			       A.MSC_SEQ OLD_MSC_SEQ,
			       A.ALLOW_NK,
			       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,
			       A.MEMO,
			       A.REMARK,
			       TO_CHAR(A.AUDIT_TIME, 'YYYY-MM-DD HH24:MI:SS') AUDIT_TIME,
			       A.AUDIT_NAME,
			       A.VALIDFLAG_NK,
			       DECODE(A.VALIDFLAG_NK, 'A', '录入状态', 'B', '提交审核', 
			       			'C', '已生效', 'D', '无效',  'E', '提交修改', '未识别') VALIDFLAG_NK_NAME,
			       A.AUDIT_NAME_NK,
			       TO_CHAR(A.AUDIT_TIME_NK, 'YYYY-MM-DD HH24:MI:SS') AUDIT_TIME_NK,
			       A.REMARK_NK,
			       A.PRODUC_HEAD,
			       A.VALIDFLAG,
			       DECODE(A.VALIDFLAG, 'A', '录入状态', 'B', '提交审核', 
			       			'C', '已生效', 'D', '无效',  'E', '提交修改', '未识别') VALIDFLAG_NAME
			  FROM COM_PSC_R_MSC T
			  FULL JOIN COM_MSC A ON T.MSC = A.MSC
			 WHERE T.PSC = '#PSC#'
			 AND T.VALIDFLAG = '1'
			 AND A.VALIDFLAG IN ('A', 'B', 'C', 'E', '#VALIDFLAG#')
			 ORDER BY T.MSC
		]]>
	</query>
	
	<query id="MscManage.queryJG" desc="查询接箍">
		<![CDATA[
SELECT A.MSC,
       A.MSC_DESC,
       A.CODE_JG,
       A.STOCK_STYLE,
       B.PRODUCCODE,
       B.PRODUCNAME,
       B.STEELCODE_JG      STEELCODE,
       B.STEELCODE_JG_DESC STEELNAME,
       B.MIN_H_CP          MIN_H,
       B.MAX_H_CP          MAX_H,
       B.MIN_D_JG          MIN_D,
       B.MAX_D_JG          MAX_D,
       A.CREATE_NAME,
       A.CREATE_TIME,
       A.UPDATE_NAME,
       A.UPDATE_TIME,
       A.DELETE_NAME,
       A.DELETE_TIME,
       A.VALIDFLAG,
       A.MEMO
  FROM COM_MSC_R_JG A
  LEFT JOIN COM_MSC_JG B
    ON B.CODE_JG = A.CODE_JG
 WHERE A.STOCK_STYLE = 'A'
   AND A.VALIDFLAG = '1'
   AND DECODE('#MSC#', NULL, '1', A.MSC) =
       DECODE('#MSC#', NULL, '1', '#MSC#')
   AND EXISTS
 (SELECT 1
          FROM COM_MSC D
          LEFT JOIN COM_PSC_R_MSC C
            ON C.MSC = D.MSC
         WHERE A.MSC = D.MSC
           AND C.PSC = '#PSC#'
           AND D.VALIDFLAG IN ('A', 'B', 'C', 'E', '#VALIDFLAG#'))
		 ]]>
	</query>
	
	<query id="MscManage.insertMsc" desc="新增冶金规范">
		<![CDATA[
DECLARE
  P_MSC               COM_MSC.MSC%TYPE;
  P_MSC_DESC          COM_MSC.MSC_DESC%TYPE := '#MSC_DESC#';
  P_USE_CODE          COM_MSC.USE_CODE%TYPE := '#USE_CODE#';
  P_USE_DESC          COM_MSC.USE_DESC%TYPE := '#USE_DESC#';
  P_DEPARTMENT_CODE   COM_MSC.DEPARTMENT_CODE%TYPE := '#DEPARTMENT_CODE#';
  P_DEPARTMENT_DESC   COM_MSC.DEPARTMENT_DESC%TYPE := '#DEPARTMENT_DESC#';
  P_UNIT_CODE         COM_MSC.UNIT_CODE%TYPE := '#UNIT_CODE#';
  P_UNIT_DESC         COM_MSC.UNIT_DESC%TYPE := '#UNIT_DESC#';
  P_UNIT_CODE_PROCESS COM_MSC.UNIT_CODE_PROCESS%TYPE := '#UNIT_CODE_PROCESS#';
  P_UNIT_DESC_PROCESS COM_MSC.UNIT_DESC_PROCESS%TYPE := '#UNIT_DESC_PROCESS#';
  P_MSC_STYLE         COM_MSC.MSC_STYLE%TYPE := '#MSC_STYLE#';
  P_USER_COUNT        COM_MSC.USER_COUNT%TYPE := '#USER_COUNT#';
  P_ALLOW_NK          COM_MSC.ALLOW_NK%TYPE := '#ALLOW_NK#';
  P_MSC_SEQ           COM_MSC.MSC_SEQ%TYPE := '#MSC_SEQ#';
  P_MSC_DESC_SEQ      COM_MSC.MSC_DESC_SEQ%TYPE := '#MSC_DESC_SEQ#';
  P_CREATE_NAME       COM_MSC.CREATE_NAME%TYPE := '#CREATE_NAME#';
  P_MEMO              COM_MSC.MEMO%TYPE := '#MEMO#';
  P_PRODUC_HEAD       COM_MSC.PRODUC_HEAD%TYPE;
  P_PRODUCCODE        COM_MSC.PRODUCCODE%TYPE := '#PRODUCCODE#';
  P_PRODUCNAME        COM_MSC.PRODUCNAME%TYPE := '#PRODUCNAME#';
  P_STD_CODE          COM_MSC.STD_CODE%TYPE := '#STD_CODE#';
  P_STD_NAME          COM_MSC.STD_NAME%TYPE := '#STD_NAME#';
  P_STEELCODE         COM_MSC.STEELCODE%TYPE := '#STEELCODE#';
  P_STEELNAME         COM_MSC.STEELNAME%TYPE := '#STEELNAME#';
  P_STD_STYLE         COM_MSC.STD_STYLE%TYPE := '#STD_STYLE#';
  P_STD_STYLE_DESC    COM_MSC.STD_STYLE_DESC%TYPE := '#STD_STYLE_DESC#';
  P_NEW_PROC_CODE     COM_MSC.NEW_PROC_CODE%TYPE := '#NEW_PROC_CODE#';
  P_NEW_PROC_DESC     COM_MSC.NEW_PROC_DESC%TYPE := '#NEW_PROC_DESC#';
  P_PSC               COM_PSC_R_MSC.PSC%TYPE := '#PSC#';
  P_PSC_DESC          COM_PSC_R_MSC.PSC_DESC%TYPE := '#PSC_DESC#';
  P_ITEM_C            COM_MSC_ITEM.ITEM_C%TYPE;
  P_INDEX_SEQ         COM_MSC_ITEM.INDEX_SEQ%TYPE := 0;

BEGIN
  SELECT PRODUC_HEAD INTO P_PRODUC_HEAD FROM COM_PSC WHERE PSC = '#PSC#';
  SELECT REPLACE('#PSC#', 'P', 'M') || LPAD(SUBSTR(NVL(MAX(T.MSC), '#PSC#' || '000'), 11, 3) + DECODE(MAX(T.MSC), NULL, 0, 1), 3, '0')
			 INTO P_MSC  FROM com_psc_r_msc T WHERE T.PSC = '#PSC#';
  FOR VROW IN (SELECT BASECODE, BASENAME
                 FROM COM_BASE_INFO
                WHERE SORTCODE = '4030') LOOP
    IF P_MSC LIKE '__________000' THEN
      P_ITEM_C := VROW.BASECODE || '01';
    ELSE
      P_ITEM_C := VROW.BASECODE || '02';
    END IF;
    P_INDEX_SEQ := P_INDEX_SEQ + 1;
    INSERT INTO COM_MSC_ITEM T
      (T.MSC,
       T.INDEX_SEQ,
       T.ITEM,
       T.ITEM_C,
       T.CREATE_NAME,
       T.MEMO,
       T.CREATE_TIME,
       T.VALIDFLAG)
    VALUES
      (P_MSC,
       P_INDEX_SEQ,
       VROW.BASECODE,
       P_ITEM_C,
       P_CREATE_NAME,
       P_MEMO,
       SYSDATE,
       '1');
  END LOOP;

  INSERT INTO COM_MSC
    (MSC,
     MSC_DESC,
     USE_CODE,
     USE_DESC,
     DEPARTMENT_CODE,
     DEPARTMENT_DESC,
     UNIT_CODE,
     UNIT_DESC,
     UNIT_CODE_PROCESS,
     UNIT_DESC_PROCESS,
     MSC_STYLE,
     USER_COUNT,
     ALLOW_NK,
     MSC_SEQ,
     MSC_DESC_SEQ,
     CREATE_NAME,
     MEMO,
     PRODUC_HEAD,
     PRODUCCODE,
     PRODUCNAME,
     STD_CODE,
     STD_NAME,
     STEELCODE,
     STEELNAME,
     STD_STYLE,
     STD_STYLE_DESC,
     NEW_PROC_CODE,
     NEW_PROC_DESC,
     VALIDFLAG,
     CREATE_TIME)
  VALUES
    (P_MSC,
     P_MSC_DESC,
     P_USE_CODE,
     P_USE_DESC,
     P_DEPARTMENT_CODE,
     P_DEPARTMENT_DESC,
     P_UNIT_CODE,
     P_UNIT_DESC,
     P_UNIT_CODE_PROCESS,
     P_UNIT_DESC_PROCESS,
     P_MSC_STYLE,
     P_USER_COUNT,
     P_ALLOW_NK,
     P_MSC_SEQ,
     P_MSC_DESC_SEQ,
     P_CREATE_NAME,
     P_MEMO,
     P_PRODUC_HEAD,
     P_PRODUCCODE,
     P_PRODUCNAME,
     P_STD_CODE,
     P_STD_NAME,
     P_STEELCODE,
     P_STEELNAME,
     P_STD_STYLE,
     P_STD_STYLE_DESC,
     P_NEW_PROC_CODE,
     P_NEW_PROC_DESC,
     'A',
     SYSDATE);

  INSERT INTO COM_PSC_R_MSC
    (PSC,
     PSC_DESC,
     USE_CODE,
     USE_DESC,
     MSC,
     MSC_DESC,
     CREATE_NAME,
     CREATE_TIME,
     VALIDFLAG)
  VALUES
    (P_PSC,
     P_PSC_DESC,
     P_USE_CODE,
     P_USE_DESC,
     P_MSC,
     P_MSC_DESC,
     P_CREATE_NAME,
     SYSDATE,
     '1');
END;
		 ]]>
	</query> 
	
	<query id="MscManage.updateMsc" desc="更新冶金规范">
		<![CDATA[
				UPDATE COM_MSC
								   SET 
								        MSC_DESC = '#MSC_DESC#',
								        USE_CODE = '#USE_CODE#',
								        USE_DESC = '#USE_DESC#',
								        DEPARTMENT_CODE = '#DEPARTMENT_CODE#',
								        DEPARTMENT_DESC = '#DEPARTMENT_DESC#',
								        UNIT_CODE = '#UNIT_CODE#',
								        UNIT_DESC = '#UNIT_DESC#',
								        UNIT_CODE_PROCESS = '#UNIT_CODE_PROCESS#',
								        UNIT_DESC_PROCESS = '#UNIT_DESC_PROCESS#',
								        MSC_STYLE = '#MSC_STYLE#',
								        USER_COUNT = '#USER_COUNT#',
								        ALLOW_NK = '#ALLOW_NK#',
								        MSC_SEQ = '#MSC_SEQ#',
								        MSC_DESC_SEQ = '#MSC_DESC_SEQ#',
								        UPDATE_NAME = '#UPDATE_NAME#',
								        UPDATE_TIME = SYSDATE,
								        MEMO = '#MEMO#',
								        PRODUC_HEAD = '#PRODUC_HEAD#'
								        --PRODUCCODE = '#PRODUCCODE#',
								        --PRODUCNAME = '#PRODUCNAME#',
								        --STD_CODE = '#STD_CODE#',
								        --STD_NAME = '#STD_NAME#',
								        --STEELCODE = '#STEELCODE#',
								        --STEELNAME = '#STEELNAME#',
								        --STD_STYLE = '#STD_STYLE#',
								        --STD_STYLE_DESC = '#STD_STYLE_DESC#',
								        --NEW_PROC_CODE = '#NEW_PROC_CODE#',
								        --NEW_PROC_DESC = '#NEW_PROC_DESC#'
								 WHERE
								 MSC = '#MSC#'
		 ]]>
	</query> 
	
	<query id="MscManage.isExistAlpha" desc="冶金规范中是否存在Alpha">
		<![CDATA[
			 SELECT COUNT(1) FROM com_psc_r_msc T WHERE T.PSC = '#PSC#' AND T.USE_CODE = '#USE_CODE#'
		]]>
	</query>
	
	<query id="MscManage.isCompleteMsc" desc="是否完整的MSC">
		<![CDATA[
			 SELECT DECODE(COUNT(1), 0, 0, 1) CNT, '制程' TYPE
			  FROM COM_MSC_BACKLOG A
			 WHERE A.MSC = '#MSC#'
			   AND A.VALIDFLAG = '1'
			UNION ALL
			SELECT DECODE(COUNT(1), 0, 0, 1) CNT, '工序' TYPE
			  FROM COM_MSC_PROCESS A
			 WHERE A.MSC = '#MSC#'
			   AND A.VALIDFLAG = '1'
			UNION ALL
			SELECT DECODE(COUNT(1), 0, 0, 1) CNT, '工序点' TYPE
			  FROM COM_MSC_STATION A
			 WHERE A.MSC = '#MSC#'
			   AND A.VALIDFLAG = '1'
			UNION ALL
			SELECT DECODE(COUNT(1), 0, 0, 1) CNT, '钢种' TYPE
			  FROM COM_MSC_GRADE A
			 WHERE A.MSC = '#MSC#'
			   AND A.VALIDFLAG = '1'
		 ]]>
	</query>
	
	<query id="MscManage.isCompleteMsc2" desc="是否完整的MSC">
		<![CDATA[
SELECT SUM(CNT) CNT, '成分标准' TYPE FROM (SELECT DECODE(COUNT(1), 0, 0, 1) CNT
           FROM COM_MSC_STD_CIC A
          WHERE DECODE('#MSC#', NULL, '1', A.MSC) = DECODE('#MSC#', NULL, '1', '#MSC#')
            AND A.VALIDFLAG = '1'
         UNION ALL
         SELECT 1 CNT
           FROM DUAL
          WHERE NOT EXISTS (SELECT 1
                   FROM COM_MSC_STATION T
                  WHERE T.STATION_TYPE = '403201'
                    AND T.VALIDFLAG = '1'
                    AND T.MSC = '#MSC#')) UNION ALL
  SELECT SUM(CNT) CNT, '理化标准' TYPE FROM (SELECT DECODE(COUNT(1), 0, 0, 1) CNT
           FROM COM_MSC_STD_PIC A
          WHERE DECODE('#MSC#', NULL, '1', A.MSC) = DECODE('#MSC#', NULL, '1', '#MSC#')
            AND VALIDFLAG = '1'
         UNION ALL
         SELECT 1 CNT
           FROM DUAL
          WHERE NOT EXISTS (SELECT 1
                   FROM COM_MSC_STATION T
                  WHERE T.STATION_TYPE = '403202'
                    AND T.VALIDFLAG = '1'
                    AND T.MSC = '#MSC#')) UNION ALL
   SELECT SUM(CNT) CNT, '公差标准' TYPE FROM (SELECT DECODE(COUNT(1), 0, 0, 1) CNT
           FROM COM_MSC_STD_SPEC A
          WHERE DECODE('#MSC#', NULL, '1', A.MSC) = DECODE('#MSC#', NULL, '1', '#MSC#')
            AND VALIDFLAG = '1'
         UNION ALL
         SELECT 1 CNT
           FROM DUAL
          WHERE NOT EXISTS (SELECT 1
                   FROM COM_MSC_STATION T
                  WHERE T.STATION_TYPE = '403203'
                    AND T.VALIDFLAG = '1'
                    AND T.MSC = '#MSC#')) UNION ALL
   SELECT SUM(CNT) CNT, '探伤标准' TYPE FROM (SELECT DECODE(COUNT(1), 0, 0, 1) CNT
           FROM COM_MSC_STD_DETECTION A
          WHERE DECODE('#MSC#', NULL, '1', A.MSC) = DECODE('#MSC#', NULL, '1', '#MSC#')
            AND VALIDFLAG = '1'
         UNION ALL
         SELECT 1 CNT
           FROM DUAL
          WHERE NOT EXISTS (SELECT 1
                   FROM COM_MSC_STATION T
                  WHERE T.STATION_TYPE = '403204'
                    AND T.VALIDFLAG = '1'
                    AND T.MSC = '#MSC#')) UNION ALL
   SELECT SUM(CNT) CNT, '水压标准' TYPE FROM (SELECT DECODE(COUNT(1), 0, 0, 1) CNT
           FROM COM_MSC_STD_WATER A
          WHERE DECODE('#MSC#', NULL, '1', A.MSC) = DECODE('#MSC#', NULL, '1', '#MSC#')
            AND VALIDFLAG = '1'
         UNION ALL
         SELECT 1 CNT
           FROM DUAL
          WHERE NOT EXISTS (SELECT 1
                   FROM COM_MSC_STATION T
                  WHERE T.STATION_TYPE = '403205'
                    AND T.VALIDFLAG = '1'
                    AND T.MSC = '#MSC#')) UNION ALL
    SELECT SUM(CNT) CNT, '加工标准' TYPE FROM (SELECT DECODE(COUNT(1), 0, 0, 1) CNT
           FROM COM_MSC_STD_PROCESS A
          WHERE DECODE('#MSC#', NULL, '1', A.MSC) = DECODE('#MSC#', NULL, '1', '#MSC#')
            AND VALIDFLAG = '1'
         UNION ALL
         SELECT 1 CNT
           FROM DUAL
          WHERE NOT EXISTS (SELECT 1
                   FROM COM_MSC_STATION T
                  WHERE T.STATION_TYPE = '403208'
                    AND T.VALIDFLAG = '1'
                    AND T.MSC = '#MSC#'))
       
        UNION ALL 
    SELECT SUM(CNT) CNT, '成分类工序点' TYPE FROM (SELECT DECODE(COUNT(1), 0, 0, 1) CNT
                     FROM COM_MSC_STATION T
                    WHERE T.STATION_TYPE = '403201'
                      AND T.VALIDFLAG = '1'
                      AND T.MSC = '#MSC#'
                   UNION ALL
                   SELECT 1 CNT
                     FROM DUAL
                    WHERE NOT EXISTS (SELECT 1
                             FROM COM_MSC_STD_CIC A
                            WHERE DECODE('#MSC#', NULL, '1', A.MSC) =
                                  DECODE('#MSC#', NULL, '1', '#MSC#')
                              AND A.VALIDFLAG = '1')) UNION ALL
     SELECT SUM(CNT) CNT, '理化类工序点' TYPE FROM (SELECT DECODE(COUNT(1), 0, 0, 1) CNT
           FROM COM_MSC_STATION T
          WHERE T.STATION_TYPE = '403202'
            AND T.VALIDFLAG = '1'
            AND T.MSC = '#MSC#'
         UNION ALL
         SELECT 1 CNT
           FROM DUAL
          WHERE NOT EXISTS
          (SELECT 1
                   FROM COM_MSC_STD_PIC A
                  WHERE DECODE('#MSC#', NULL, '1', A.MSC) = DECODE('#MSC#', NULL, '1', '#MSC#')
                    AND VALIDFLAG = '1')) UNION ALL
    SELECT SUM(CNT) CNT, '公差类工序点' TYPE FROM (SELECT DECODE(COUNT(1), 0, 0, 1) CNT
           FROM COM_MSC_STATION T
          WHERE T.STATION_TYPE = '403203'
            AND T.VALIDFLAG = '1'
            AND T.MSC = '#MSC#'
         UNION ALL
         SELECT 1 CNT
           FROM DUAL
          WHERE NOT EXISTS
          (SELECT 1
                   FROM COM_MSC_STD_SPEC A
                  WHERE DECODE('#MSC#', NULL, '1', A.MSC) = DECODE('#MSC#', NULL, '1', '#MSC#')
                    AND VALIDFLAG = '1')) UNION ALL
    SELECT SUM(CNT) CNT, '探伤类工序点' TYPE FROM (SELECT DECODE(COUNT(1), 0, 0, 1) CNT
           FROM COM_MSC_STATION T
          WHERE T.STATION_TYPE = '403204'
            AND T.VALIDFLAG = '1'
            AND T.MSC = '#MSC#'
         UNION ALL
         SELECT 1 CNT
           FROM DUAL
          WHERE NOT EXISTS
          (SELECT 1
                   FROM COM_MSC_STD_DETECTION A
                  WHERE DECODE('#MSC#', NULL, '1', A.MSC) = DECODE('#MSC#', NULL, '1', '#MSC#')
                    AND VALIDFLAG = '1')) UNION ALL
    SELECT SUM(CNT) CNT, '水压类工序点' TYPE FROM (SELECT DECODE(COUNT(1), 0, 0, 1) CNT
           FROM COM_MSC_STATION T
          WHERE T.STATION_TYPE = '403205'
            AND T.VALIDFLAG = '1'
            AND T.MSC = '#MSC#'
         UNION ALL
         SELECT 1 CNT
           FROM DUAL
          WHERE NOT EXISTS
          (SELECT 1
                   FROM COM_MSC_STD_WATER A
                  WHERE DECODE('#MSC#', NULL, '1', A.MSC) = DECODE('#MSC#', NULL, '1', '#MSC#')
                    AND VALIDFLAG = '1')) UNION ALL
    SELECT SUM(CNT) CNT, '加工类工序点' TYPE FROM (SELECT DECODE(COUNT(1), 0, 0, 1) CNT
           FROM COM_MSC_STATION T
          WHERE T.STATION_TYPE = '403208'
            AND T.VALIDFLAG = '1'
            AND T.MSC = '#MSC#'
         UNION ALL
         SELECT 1 CNT
           FROM DUAL
          WHERE NOT EXISTS
          (SELECT 1
                   FROM COM_MSC_STD_PROCESS A
                  WHERE DECODE('#MSC#', NULL, '1', A.MSC) = DECODE('#MSC#', NULL, '1', '#MSC#')
                    AND VALIDFLAG = '1'))

		 ]]>
	</query>
	
	<query id="MscManage.updateMscState" desc="作废或者恢复冶金规范">
		<![CDATA[
		 DECLARE 
		 P_VALIDFLAG COM_MSC.VALIDFLAG%TYPE := '#VALIDFLAG#';
		 P_MSC COM_MSC.MSC%TYPE := '#MSC#';
		 P_NAME COM_MSC.DELETE_NAME%TYPE := '#DELETE_NAME#';
		 P_ACTION_TYPE VARCHAR2(20) := '#ACTION_TYPE#';
		 
		 BEGIN
		 
		 IF P_ACTION_TYPE <> 'Audit' THEN
			 IF P_ACTION_TYPE = 'Delete' THEN
			    UPDATE COM_MSC SET VALIDFLAG = P_VALIDFLAG, DELETE_NAME = P_NAME,
			    	 DELETE_TIME = SYSDATE, VALIDFLAG_NK = P_VALIDFLAG WHERE MSC = P_MSC;
			    UPDATE COM_MSC_STD_CIC T
					   SET T.VALIDFLAG   = '#VALIDFLAG2#',
					       T.DELETE_NAME = '#DELETE_NAME#',
					       T.DELETE_TIME = SYSDATE
					 WHERE T.MSC = '#MSC#' AND T.VALIDFLAG <> '0';
				UPDATE COM_MSC_STD_PIC T
					   SET T.VALIDFLAG   = '#VALIDFLAG2#',
					       T.DELETE_NAME = '#DELETE_NAME#',
					       T.DELETE_TIME = SYSDATE
					 WHERE T.MSC = '#MSC#' AND T.VALIDFLAG <> '0';
				UPDATE COM_MSC_STD_DETECTION T
					   SET T.VALIDFLAG   = '#VALIDFLAG2#',
					       T.DELETE_NAME = '#DELETE_NAME#',
					       T.DELETE_TIME = SYSDATE
					 WHERE T.MSC = '#MSC#' AND T.VALIDFLAG <> '0';
				 UPDATE COM_MSC_STD_SPEC T
					   SET T.VALIDFLAG   = '#VALIDFLAG2#',
					       T.DELETE_NAME = '#DELETE_NAME#',
					       T.DELETE_TIME = SYSDATE
					 WHERE T.MSC = '#MSC#' AND T.VALIDFLAG <> '0';
				 UPDATE COM_MSC_STD_WATER T
					   SET T.VALIDFLAG   = '#VALIDFLAG2#',
					       T.DELETE_NAME = '#DELETE_NAME#',
					       T.DELETE_TIME = SYSDATE
					 WHERE T.MSC = '#MSC#' AND T.VALIDFLAG <> '0';
			     UPDATE COM_MSC_STD_PROCESS T
					   SET T.VALIDFLAG   = '#VALIDFLAG2#',
					       T.DELETE_NAME = '#DELETE_NAME#',
					       T.DELETE_TIME = SYSDATE
					 WHERE T.MSC = '#MSC#' AND T.VALIDFLAG <> '0';
				 UPDATE COM_MSC_BACKLOG T
					   SET T.VALIDFLAG   = '#VALIDFLAG2#',
					       T.VALIDFLAG_NK = '#VALIDFLAG2#', 
					       T.DELETE_NAME = '#DELETE_NAME#',
					       T.DELETE_TIME = SYSDATE
					 WHERE T.MSC = '#MSC#' AND T.VALIDFLAG <> '0';
				 UPDATE COM_MSC_STD_CHEM T
					   SET T.VALIDFLAG   = '0',
					       T.DELETE_NAME = '#DELETE_NAME#',
					       T.DELETE_TIME = SYSDATE
					 WHERE T.CIC = (SELECT A.CIC FROM COM_MSC_STD_CIC A WHERE A.MSC = '#MSC#');
				 UPDATE COM_MSC_STD_PHY T
					   SET T.VALIDFLAG   = '0',
					       T.DELETE_NAME = '#DELETE_NAME#',
					       T.DELETE_TIME = SYSDATE
					 WHERE T.PIC = (SELECT A.PIC FROM COM_MSC_STD_PIC A WHERE A.MSC = '#MSC#');
				 UPDATE COM_MSC_STD_DETECTION_C T
					   SET T.VALIDFLAG   = '0',
					       T.DELETE_NAME = '#DELETE_NAME#',
					       T.DELETE_TIME = SYSDATE
					 WHERE T.DIC = (SELECT A.DIC FROM COM_MSC_STD_DETECTION A WHERE A.MSC = '#MSC#');
				 UPDATE COM_MSC_STD_SPEC_C T
					   SET T.VALIDFLAG   = '0',
					       T.DELETE_NAME = '#DELETE_NAME#',
					       T.DELETE_TIME = SYSDATE
					 WHERE T.SIC = (SELECT A.SIC FROM COM_MSC_STD_SPEC A WHERE A.MSC = '#MSC#');
				 UPDATE Com_Msc_Std_Water_C T
					   SET T.VALIDFLAG   = '0',
					       T.DELETE_NAME = '#DELETE_NAME#',
					       T.DELETE_TIME = SYSDATE
					 WHERE T.WIC = (SELECT A.WIC FROM Com_Msc_Std_Water A WHERE A.MSC = '#MSC#');
				UPDATE Com_Msc_Std_Process_c T
					   SET T.VALIDFLAG   = '0',
					       T.DELETE_NAME = '#DELETE_NAME#',
					       T.DELETE_TIME = SYSDATE
					 WHERE T.GIC = (SELECT A.GIC FROM Com_Msc_Std_Process A WHERE A.MSC = '#MSC#');
			                UPDATE Com_Msc_Process T
					     SET T.VALIDFLAG   = '0',
					         T.DELETE_NAME = '#DELETE_NAME#',
					         T.DELETE_TIME = SYSDATE
					   WHERE T.MSC = '#MSC#';
	           UPDATE Com_Msc_Station T
	               SET T.VALIDFLAG   = '0',
	                   T.DELETE_NAME = '#DELETE_NAME#',
						         T.DELETE_TIME = SYSDATE
	             WHERE T.MSC = '#MSC#';
		         UPDATE Com_Msc_Grade T
		             SET T.VALIDFLAG   = '0',
		                 T.DELETE_NAME = '#DELETE_NAME#',
							       T.DELETE_TIME = SYSDATE
		           WHERE T.MSC = '#MSC#';
		        UPDATE Com_Msc_Grade_r_Spec T
		             SET T.VALIDFLAG   = '0',
		                 T.DELETE_NAME = '#DELETE_NAME#',
							         T.DELETE_TIME = SYSDATE
		           WHERE T.MSC = '#MSC#';
		        UPDATE COM_MSC_R_JG T
				     SET T.VALIDFLAG   = '0',
				         T.DELETE_NAME = '#DELETE_NAME#',
				         T.DELETE_TIME = SYSDATE
				   WHERE T.MSC = '#MSC#';
			 ELSIF P_ACTION_TYPE = 'SubMitModify' THEN
			 	 UPDATE COM_MSC SET VALIDFLAG = P_VALIDFLAG, UPDATE_NAME = P_NAME,
			    	 UPDATE_TIME = SYSDATE WHERE MSC = P_MSC;
			 ELSIF P_ACTION_TYPE = 'Resume' THEN
			 	  UPDATE COM_MSC SET VALIDFLAG = P_VALIDFLAG, UPDATE_NAME = P_NAME,
			    	 UPDATE_TIME = SYSDATE, VALIDFLAG_NK = P_VALIDFLAG WHERE MSC = P_MSC;
			      UPDATE COM_MSC_STD_CIC T
					   SET T.VALIDFLAG   = '#VALIDFLAG2#',
					       T.UPDATE_NAME = '#UPDATE_NAME#',
					       T.UPDATE_TIME = SYSDATE,
					       T.DELETE_NAME = '',
					       T.DELETE_TIME = ''
					 WHERE T.MSC = '#MSC#';
				UPDATE COM_MSC_STD_PIC T
					   SET T.VALIDFLAG   = '#VALIDFLAG2#',
					       T.UPDATE_NAME = '#UPDATE_NAME#',
					       T.UPDATE_TIME = SYSDATE,
					       T.DELETE_NAME = '',
					       T.DELETE_TIME = ''
					 WHERE T.MSC = '#MSC#';
				UPDATE COM_MSC_STD_DETECTION T
					   SET T.VALIDFLAG   = '#VALIDFLAG2#',
					       T.UPDATE_NAME = '#UPDATE_NAME#',
					       T.UPDATE_TIME = SYSDATE,
					       T.DELETE_NAME = '',
					       T.DELETE_TIME = ''
					 WHERE T.MSC = '#MSC#';
				 UPDATE COM_MSC_STD_SPEC T
					   SET T.VALIDFLAG   = '#VALIDFLAG2#',
					       T.UPDATE_NAME = '#UPDATE_NAME#',
					       T.UPDATE_TIME = SYSDATE,
					       T.DELETE_NAME = '',
					       T.DELETE_TIME = ''
					 WHERE T.MSC = '#MSC#';
				 UPDATE COM_MSC_STD_WATER T
					   SET T.VALIDFLAG   = '#VALIDFLAG2#',
					       T.UPDATE_NAME = '#UPDATE_NAME#',
					       T.UPDATE_TIME = SYSDATE,
					       T.DELETE_NAME = '',
					       T.DELETE_TIME = ''
					 WHERE T.MSC = '#MSC#';
			     UPDATE COM_MSC_STD_PROCESS T
					   SET T.VALIDFLAG   = '#VALIDFLAG2#',
					   	   T.UPDATE_NAME = '#UPDATE_NAME#',
					       T.UPDATE_TIME = SYSDATE,
					       T.DELETE_NAME = '',
					       T.DELETE_TIME = ''
					 WHERE T.MSC = '#MSC#';
				 UPDATE COM_MSC_BACKLOG T
					   SET T.VALIDFLAG   = '#VALIDFLAG2#',
					       T.VALIDFLAG_NK = '#VALIDFLAG2#',
					       T.UPDATE_NAME = '#UPDATE_NAME#',
					       T.UPDATE_TIME = SYSDATE,
					       T.DELETE_NAME = '',
					       T.DELETE_TIME = ''
					 WHERE T.MSC = '#MSC#';
				 UPDATE COM_MSC_STD_CHEM T
			             SET T.VALIDFLAG   = '1',
			                 T.DELETE_NAME = '',
			                 T.DELETE_TIME = '',
			                 T.UPDATE_NAME = '#UPDATE_NAME#',
			                 T.UPDATE_TIME = SYSDATE
			           WHERE T.CIC = (SELECT A.CIC FROM COM_MSC_STD_CIC A WHERE A.MSC = '#MSC#');
			         UPDATE COM_MSC_STD_PHY T
			             SET T.VALIDFLAG   = '1',
			                 T.DELETE_NAME = '',
			                 T.DELETE_TIME = '',
			                 T.UPDATE_NAME = '#UPDATE_NAME#',
			                 T.UPDATE_TIME = SYSDATE
			           WHERE T.PIC = (SELECT A.PIC FROM COM_MSC_STD_PIC A WHERE A.MSC = '#MSC#');
			         UPDATE COM_MSC_STD_DETECTION_C T
			             SET T.VALIDFLAG   = '1',
			                 T.DELETE_NAME = '',
			                 T.DELETE_TIME = '',
			                 T.UPDATE_NAME = '#UPDATE_NAME#',
			                 T.UPDATE_TIME = SYSDATE
			           WHERE T.DIC = (SELECT A.DIC FROM COM_MSC_STD_DETECTION A WHERE A.MSC = '#MSC#');
			         UPDATE COM_MSC_STD_SPEC_C T
			             SET T.VALIDFLAG   = '1',
			                 T.DELETE_NAME = '',
			                 T.DELETE_TIME = '',
			                 T.UPDATE_NAME = '#UPDATE_NAME#',
			                 T.UPDATE_TIME = SYSDATE
			           WHERE T.SIC = (SELECT A.SIC FROM COM_MSC_STD_SPEC A WHERE A.MSC = '#MSC#');
			         UPDATE Com_Msc_Std_Water_C T
			             SET T.VALIDFLAG   = '1',
			                 T.DELETE_NAME = '',
			                 T.DELETE_TIME = '',
			                 T.UPDATE_NAME = '#UPDATE_NAME#',
			                 T.UPDATE_TIME = SYSDATE
			           WHERE T.WIC = (SELECT A.WIC FROM Com_Msc_Std_Water A WHERE A.MSC = '#MSC#');
			        UPDATE Com_Msc_Std_Process_c T
			             SET T.VALIDFLAG   = '1',
			                 T.DELETE_NAME = '',
			                 T.DELETE_TIME = '',
			                 T.UPDATE_NAME = '#UPDATE_NAME#',
			                 T.UPDATE_TIME = SYSDATE
			           WHERE T.GIC = (SELECT A.GIC FROM Com_Msc_Std_Process A WHERE A.MSC = '#MSC#');
			       UPDATE Com_Msc_Process T
					     SET T.VALIDFLAG   = '1',
					         T.DELETE_NAME = '',
					         T.DELETE_TIME = '',
					         T.UPDATE_NAME = '#UPDATE_NAME#',
					         T.UPDATE_TIME = SYSDATE
					   WHERE T.MSC = '#MSC#';
				   UPDATE Com_Msc_Station T
					     SET T.VALIDFLAG   = '1',
					         T.DELETE_NAME = '',
					         T.DELETE_TIME = '',
					         T.UPDATE_NAME = '#UPDATE_NAME#',
					         T.UPDATE_TIME = SYSDATE
					   WHERE T.MSC = '#MSC#';
				 UPDATE Com_Msc_Grade T
				     SET T.VALIDFLAG   = '1',
				         T.DELETE_NAME = '',
				         T.DELETE_TIME = '',
				         T.UPDATE_NAME = '#UPDATE_NAME#',
				         T.UPDATE_TIME = SYSDATE
				   WHERE T.MSC = '#MSC#';
				UPDATE Com_Msc_Grade_r_Spec T
				     SET T.VALIDFLAG   = '1',
				         T.DELETE_NAME = '',
				         T.DELETE_TIME = '',
				         T.UPDATE_NAME = '#UPDATE_NAME#',
				         T.UPDATE_TIME = SYSDATE
				   WHERE T.MSC = '#MSC#';
				   UPDATE COM_MSC_R_JG T
					     SET T.VALIDFLAG   = '1',
					         T.DELETE_NAME = '',
					         T.DELETE_TIME = '',
					         T.UPDATE_NAME = '#UPDATE_NAME#',
					         T.UPDATE_TIME = SYSDATE
					   WHERE T.MSC = '#MSC#';
			 ELSE
			 	UPDATE COM_MSC SET VALIDFLAG = P_VALIDFLAG, UPDATE_NAME = P_NAME,
			 	    UPDATE_TIME = SYSDATE, DELETE_NAME = '', DELETE_TIME = '' WHERE MSC = P_MSC;
			 	UPDATE COM_MSC_STD_CIC T
					   SET T.VALIDFLAG   = '#VALIDFLAG2#',
					       T.UPDATE_NAME = '#UPDATE_NAME#',
					       T.UPDATE_TIME = SYSDATE,
					       T.DELETE_NAME = '',
					       T.DELETE_TIME = ''
					 WHERE T.MSC = '#MSC#' AND T.VALIDFLAG <> '0';
				UPDATE COM_MSC_STD_PIC T
					   SET T.VALIDFLAG   = '#VALIDFLAG2#',
					       T.UPDATE_NAME = '#UPDATE_NAME#',
					       T.UPDATE_TIME = SYSDATE,
					       T.DELETE_NAME = '',
					       T.DELETE_TIME = ''
					 WHERE T.MSC = '#MSC#' AND T.VALIDFLAG <> '0';
				UPDATE COM_MSC_STD_DETECTION T
					   SET T.VALIDFLAG   = '#VALIDFLAG2#',
					       T.UPDATE_NAME = '#UPDATE_NAME#',
					       T.UPDATE_TIME = SYSDATE,
					       T.DELETE_NAME = '',
					       T.DELETE_TIME = ''
					 WHERE T.MSC = '#MSC#' AND T.VALIDFLAG <> '0';
				 UPDATE COM_MSC_STD_SPEC T
					   SET T.VALIDFLAG   = '#VALIDFLAG2#',
					       T.UPDATE_NAME = '#UPDATE_NAME#',
					       T.UPDATE_TIME = SYSDATE,
					       T.DELETE_NAME = '',
					       T.DELETE_TIME = ''
					 WHERE T.MSC = '#MSC#' AND T.VALIDFLAG <> '0';
				 UPDATE COM_MSC_STD_WATER T
					   SET T.VALIDFLAG   = '#VALIDFLAG2#',
					       T.UPDATE_NAME = '#UPDATE_NAME#',
					       T.UPDATE_TIME = SYSDATE,
					       T.DELETE_NAME = '',
					       T.DELETE_TIME = ''
					 WHERE T.MSC = '#MSC#' AND T.VALIDFLAG <> '0';
			     UPDATE COM_MSC_STD_PROCESS T
					   SET T.VALIDFLAG   = '#VALIDFLAG2#',
					   	   T.UPDATE_NAME = '#UPDATE_NAME#',
					       T.UPDATE_TIME = SYSDATE,
					       T.DELETE_NAME = '',
					       T.DELETE_TIME = ''
					 WHERE T.MSC = '#MSC#' AND T.VALIDFLAG <> '0';
				 UPDATE COM_MSC_BACKLOG T
					   SET T.VALIDFLAG   = '#VALIDFLAG2#',
					       T.UPDATE_NAME = '#UPDATE_NAME#',
					       T.UPDATE_TIME = SYSDATE,
					       T.DELETE_NAME = '',
					       T.DELETE_TIME = ''
					 WHERE T.MSC = '#MSC#' AND T.VALIDFLAG <> '0';
			 END IF;
		 ELSE
		 	UPDATE COM_MSC SET VALIDFLAG = P_VALIDFLAG, AUDIT_NAME = P_NAME,
		 		AUDIT_TIME = SYSDATE, REMARK = '#REMARK#' WHERE MSC = P_MSC;
		 	UPDATE COM_MSC_STD_CIC T
					   SET T.VALIDFLAG   = '#VALIDFLAG2#',
					       T.UPDATE_NAME = '#UPDATE_NAME#',
					       T.UPDATE_TIME = SYSDATE,
					       T.DELETE_NAME = '',
					       T.DELETE_TIME = ''
					 WHERE T.MSC = '#MSC#' AND T.VALIDFLAG <> '0';
				UPDATE COM_MSC_STD_PIC T
					   SET T.VALIDFLAG   = '#VALIDFLAG2#',
					       T.UPDATE_NAME = '#UPDATE_NAME#',
					       T.UPDATE_TIME = SYSDATE,
					       T.DELETE_NAME = '',
					       T.DELETE_TIME = ''
					 WHERE T.MSC = '#MSC#' AND T.VALIDFLAG <> '0';
				UPDATE COM_MSC_STD_DETECTION T
					   SET T.VALIDFLAG   = '#VALIDFLAG2#',
					       T.UPDATE_NAME = '#UPDATE_NAME#',
					       T.UPDATE_TIME = SYSDATE,
					       T.DELETE_NAME = '',
					       T.DELETE_TIME = ''
					 WHERE T.MSC = '#MSC#' AND T.VALIDFLAG <> '0';
				 UPDATE COM_MSC_STD_SPEC T
					   SET T.VALIDFLAG   = '#VALIDFLAG2#',
					       T.UPDATE_NAME = '#UPDATE_NAME#',
					       T.UPDATE_TIME = SYSDATE,
					       T.DELETE_NAME = '',
					       T.DELETE_TIME = ''
					 WHERE T.MSC = '#MSC#' AND T.VALIDFLAG <> '0';
				 UPDATE COM_MSC_STD_WATER T
					   SET T.VALIDFLAG   = '#VALIDFLAG2#',
					       T.UPDATE_NAME = '#UPDATE_NAME#',
					       T.UPDATE_TIME = SYSDATE,
					       T.DELETE_NAME = '',
					       T.DELETE_TIME = ''
					 WHERE T.MSC = '#MSC#' AND T.VALIDFLAG <> '0';
			     UPDATE COM_MSC_STD_PROCESS T
					   SET T.VALIDFLAG   = '#VALIDFLAG2#',
					   	   T.UPDATE_NAME = '#UPDATE_NAME#',
					       T.UPDATE_TIME = SYSDATE,
					       T.DELETE_NAME = '',
					       T.DELETE_TIME = ''
					 WHERE T.MSC = '#MSC#' AND T.VALIDFLAG <> '0';
				UPDATE COM_MSC_BACKLOG T
					   SET T.VALIDFLAG   = '#VALIDFLAG2#',
					       T.UPDATE_NAME = '#UPDATE_NAME#',
					       T.UPDATE_TIME = SYSDATE,
					       T.DELETE_NAME = '',
					       T.DELETE_TIME = ''
					 WHERE T.MSC = '#MSC#' AND T.VALIDFLAG <> '0';
		 END IF;
		 END;	 
		 ]]>
	</query> 
	
	<query id="MscManage.updateMscNkState" desc="更新冶金规范内控状态位">
	UPDATE COM_MSC T
   SET T.VALIDFLAG_NK  = '#VALIDFLAG_NK#',
       T.AUDIT_NAME_NK = DECODE('#ACTION_TYPE#', 'Audit', '#AUDIT_NAME_NK#', 'AuditFail', '#AUDIT_NAME_NK#', T.AUDIT_NAME_NK),
       T.AUDIT_TIME_NK    = TO_DATE(DECODE('#ACTION_TYPE#', 'Audit', TO_CHAR(SYSDATE, 'YYYYMMDDHH24MISS'), 
       				'AuditFail', TO_CHAR(SYSDATE, 'YYYYMMDDHH24MISS'), NULL), 'YYYYMMDDHH24MISS'),
       T.REMARK_NK     = DECODE('#ACTION_TYPE#', 'Audit', '#REMARK_NK#', 'AuditFail', '#REMARK_NK#', T.REMARK_NK)
       WHERE T.MSC = '#MSC#'
	</query>
	
	<query id="MscManage.updateBackLogNkState" desc="更新制程内控状态位">
	<![CDATA[
		UPDATE COM_MSC_BACKLOG T
   SET T.VALIDFLAG_NK   = '#VALIDFLAG_NK#',
       T.UPDATE_NAME = '#UPDATE_NAME#',
       T.UPDATE_TIME = SYSDATE,
       T.DELETE_NAME = '',
       T.DELETE_TIME = ''
 WHERE T.MSC = '#MSC#' AND T.VALIDFLAG_NK <> '0'
  	]]>
	</query>
	
	<query id="MscManage.loadMsc" desc="加载冶金规范码（MSC以000结尾的为标志MSC）">
		<![CDATA[
			SELECT A.MSC, A.MSC_DESC
			  FROM COM_PSC_R_MSC A
			  FULL JOIN COM_MSC B ON A.MSC = B.MSC
			 WHERE B.VALIDFLAG = 'C'
			   AND A.PSC = '#PSC#'
			   AND B.MSC LIKE '__________000'
			 ORDER BY A.MSC
		 ]]>
	</query>
	
	<query id="MscManage.queryMscBackLog" desc="查询冶金规范产线">
		<![CDATA[
			SELECT MSC,
			       MSC_PLINE,
			       WHOLE_BACKLOG,
			       WHOLE_BACKLOG_DESC,
			       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,
			       VALIDFLAG,
			       DECODE(VALIDFLAG, '1', '录入状态', '2', '提交审核',  '3', '已审核', '0', '无效', '未识别') VALIDFLAG_NAME,
			       VALIDFLAG_NK,
			       DECODE(VALIDFLAG_NK, '1', '录入状态', '2', '提交审核',  '3', '已审核', '0', '无效', '未识别') VALIDFLAG_NK_NAME,
			       MEMO,
			       PROCESS_NO
			  FROM COM_MSC_BACKLOG
			 WHERE MSC = '#MSC#'
			 AND VALIDFLAG IN ('1', '2', '3', '#VALIDFLAG#')
			 ORDER BY MSC_PLINE ASC
		 ]]>
	</query>
	
	<query id="MscManage.queryMaxBackLogPline" desc="查询最大冶金规范产线号">
		<![CDATA[
			SELECT REPLACE(LPAD(NVL(MAX(MSC_PLINE + 1), '1'), 6), ' ', '0') MAX_VALUE
				      FROM COM_MSC_BACKLOG
				     WHERE MSC = '#MSC#'
		 ]]>
	</query>
	
	<query id="MscManage.insertMscBackLog" desc="新增冶金规范产线">
		<![CDATA[
			 INSERT INTO COM_MSC_BACKLOG
				  (MSC,
				   MSC_PLINE,
				   WHOLE_BACKLOG,
				   WHOLE_BACKLOG_DESC,
				   CREATE_NAME,
				   PROCESS_NO,
				   MEMO,
				   CREATE_TIME)
				VALUES
				  ('#MSC#',
				   '#MSC_PLINE#',
				   '#WHOLE_BACKLOG#',
				   '#WHOLE_BACKLOG_DESC#',
				   '#CREATE_NAME#',
				   '#PROCESS_NO#',
				   '#MEMO#',
				   SYSDATE)
		 ]]>
	</query>
	
	<query id="MscManage.getMscBackLogCnt" desc="获取冶金规范产线数目">
		<![CDATA[
SELECT COUNT(1) COUNT
  FROM COM_MSC_BACKLOG T
 WHERE T.MSC = '#MSC#'
   AND T.MSC_PLINE = '#MSC_PLINE#'
		 ]]>
	</query>
	
	<query id="MscManage.updateMscBackLog" desc="设置冶金规范产线">
		<![CDATA[
UPDATE COM_MSC_BACKLOG
   SET UPDATE_NAME = '#UPDATE_NAME#',
       UPDATE_TIME = SYSDATE,
       MEMO        = '#MEMO#',
       PROCESS_NO  = '#PROCESS_NO#',
       WHOLE_BACKLOG = '#WHOLE_BACKLOG#',
       WHOLE_BACKLOG_DESC = '#WHOLE_BACKLOG_DESC#'
 WHERE MSC = '#MSC#'
   AND MSC_PLINE = '#MSC_PLINE#'
		 ]]>
	</query>
	
	<query id="MscManage.deleteMscProcess" desc="删除工序表">
		<![CDATA[
		 DELETE FROM COM_MSC_PROCESS WHERE MSC = '#MSC#' AND MSC_PLINE = '#MSC_PLINE#'
		 ]]>
	</query>
	
	<query id="MscManage.insertMscProcess" desc="添加工序基础">
		<![CDATA[
		   INSERT INTO COM_MSC_PROCESS
		  				  (MSC,
		  				   MSC_PLINE,
		  				   BACKLOG_SEQ,
		  				   CREATE_NAME,
		  				   PROCESS_CODE,
		  				   PROCESS_DESC,
		  				   MINUTE_PRODUCT,
		  				   MINUTE_WAITE,
		  				   BATCH_WAITE,
		  				   MINUTE_PRODUCT_OUT,
		  				   MINUTE_WAITE_OUT,
		  				   BATCH_WAITE_OUT,
		  				   CIC,
		  				   PIC,
		  				   SIC,
		  				   DIC,
		  				   WIC,
		  				   GIC,
		  				   PROCESS_CODE_C,
		  				   PROCESS_DESC_C,
		  				   PROCESS_SEQ,
		  				   CREATE_TIME)
		  				VALUES
		  				  ('#MSC#', '#MSC_PLINE#', 
		  				  (SELECT NVL(MAX(BACKLOG_SEQ) + 1, '1') BACKLOG_SEQ
			    					  FROM COM_MSC_PROCESS
			    					 WHERE MSC = '#MSC#'
			    					   AND MSC_PLINE = '#MSC_PLINE#'), '#CREATE_NAME#', '#PROCESS_CODE#', 
		            '#PROCESS_DESC#', '#MINUTE_PRODUCT#', '#MINUTE_WAITE#', '#BATCH_WAITE#',
		  			'#MINUTE_PRODUCT_OUT#', '#MINUTE_WAITE_OUT#', '#BATCH_WAITE_OUT#',
		            '#CIC#', '#PIC#', '#SIC#', '#DIC#', '#WIC#',  '#GIC#', '#PROCESS_CODE_C#', '#PROCESS_DESC_C#',
		            '#PROCESS_SEQ#', SYSDATE)
		 ]]>
	</query>
	
	<query id="MscManage.deleteMscStation" desc="删除工序点">
		<![CDATA[
		DELETE FROM COM_MSC_STATION T WHERE T.MSC = '#MSC#' AND T.MSC_PLINE = '#MSC_PLINE#'
		 AND T.PROCESS_CODE = '#PROCESS_CODE#'
		 ]]>
	</query>
	
	<query id="MscManage.insertMscStation" desc="添加工序点">
		<![CDATA[
			    INSERT INTO COM_MSC_STATION
			    				  (MSC,
			    				   MSC_PLINE,
			    				   BACKLOG_SEQ,
			    				   PROCESS_CODE,
			    				   PROCESS_DESC,
			    				   STATION_CODE,
			    				   STATION_DESC,
			    				   STATION_TYPE,
			    				   STATION_ID,
			    				   COST,
			    				   CHOOSE,
			    				   RETURN_RESULT,
			    				   SEND_CHECKPLAN,
			    				   CREATE_NAME,
			    				   PROCESS_SEQ,
			               		   MEMO,
			               		   PROCESS_CODE_C,
			               		   PROCESS_DESC_C,
			    				   CREATE_TIME)
			    				VALUES
			    				  ('#MSC#', '#MSC_PLINE#', 
			    				  (SELECT NVL(MAX(BACKLOG_SEQ) + 1, '1') BACKLOG_SEQ
			    					  FROM COM_MSC_STATION
			    					 WHERE MSC = '#MSC#'
			    					   AND MSC_PLINE = '#MSC_PLINE#'
			    					   AND PROCESS_CODE = '#PROCESS_CODE#'), 
			    				  '#PROCESS_CODE#', '#PROCESS_DESC#', '#STATION_CODE#', '#STATION_DESC#',
			              '#STATION_TYPE#', '#STATION_ID#', '#COST#', '#CHOOSE#', '#RETURN_RESULT#',
			              '#SEND_CHECKPLAN#', '#CREATE_NAME#', '#PROCESS_SEQ#', '#MEMO#',
			              '#PROCESS_CODE_C#', '#PROCESS_DESC_C#', SYSDATE)
		 ]]>
	</query>
	
	<query id="MscManage.copyMustStation" desc="复制工序点中的必选项数据到冶金规范工序点表">
		<![CDATA[
DECLARE
  P_PROCESS_CODE   COM_BASE_PROCESS.PROCESS_CODE%TYPE := '#PROCESS_CODE#';
  P_NAME           COM_BASE_PROCESS.CREATE_NAME%TYPE := '#CREATE_NAME#';
  P_MSC            COM_MSC_BACKLOG.MSC%TYPE := '#MSC#';
  P_MSC_PLINE      COM_MSC_BACKLOG.MSC_PLINE%TYPE := '#MSC_PLINE#';
  P_PROCESS_CODE_C COM_MSC_PROCESS.PROCESS_CODE_C%TYPE := '#PROCESS_CODE_C#';
  P_ICOUNT         COM_BASE_PROCESS.ICOUNT%TYPE := '#ICOUNT#';
  I                NUMBER(3);
  P_STAION_COUNT   NUMBER(3);
BEGIN
  FOR VROW IN (SELECT A.*
                 FROM COM_BASE_STATION A, COM_BASE_PROCESS_R_STATION B
                WHERE A.PROCESS_CODE = P_PROCESS_CODE
                  AND A.VALIDFLAG = '1'
                  AND A.CHOOSE = '1'
                  AND A.STATION_CODE = B.STATION_CODE
                  AND B.VALIDFLAG = '1'
                  AND B.PROCESS_CDOE_C = P_PROCESS_CODE_C) LOOP
    SELECT COUNT(1)
      INTO P_STAION_COUNT
      FROM COM_MSC_STATION T
     WHERE T.MSC = P_MSC
       AND T.MSC_PLINE = P_MSC_PLINE
       AND T.PROCESS_CODE = P_PROCESS_CODE;
    IF P_STAION_COUNT = 0 THEN
      FOR I IN 1 .. P_ICOUNT LOOP
        INSERT INTO COM_MSC_STATION
          (MSC,
           MSC_PLINE,
           BACKLOG_SEQ,
           PROCESS_CODE,
           PROCESS_DESC,
           STATION_CODE,
           STATION_DESC,
           STATION_TYPE,
           STATION_ID,
           COST,
           CHOOSE,
           RETURN_RESULT,
           SEND_CHECKPLAN,
           CREATE_NAME,
           PROCESS_SEQ,
           PROCESS_CODE_C,
           PROCESS_DESC_C,
           MEMO,
           CREATE_TIME)
        VALUES
          (P_MSC,
           P_MSC_PLINE,
           (SELECT NVL(MAX(BACKLOG_SEQ) + 1, '1') BACKLOG_SEQ
              FROM COM_MSC_STATION
             WHERE MSC = P_MSC
               AND MSC_PLINE = P_MSC_PLINE
               AND PROCESS_CODE = P_PROCESS_CODE),
           VROW.PROCESS_CODE,
           VROW.PROCESS_DESC,
           VROW.STATION_CODE,
           VROW.STATION_DESC,
           VROW.STATION_TYPE,
           VROW.STATION_ID,
           VROW.COST,
           VROW.CHOOSE,
           VROW.RETURN_RESULT,
           VROW.SEND_CHECKPLAN,
           P_NAME,
           I,
           '#PROCESS_CODE_C#',
           '#PROCESS_DESC_C#',
           '',
           SYSDATE);
      END LOOP;
    END IF;
  END LOOP;
END;
		 ]]>
	</query>
	
	<query id="MscManage.queryMaxMscPline" desc="查询最大冶金规范产线号">
		<![CDATA[
			SELECT REPLACE(LPAD(NVL(MAX(MSC_PLINE + 1), '1'), 6), ' ', '0') MSC_PLINE
				      FROM COM_MSC_BACKLOG
				     WHERE MSC = '#MSC#'
		 ]]>
	</query>
	
	<query id="MscManage.updateBackLogState" desc="修改冶金规范产线状态">
		<![CDATA[
		DECLARE
		P_VALIDFLAG COM_MSC_BACKLOG.VALIDFLAG%TYPE := '#VALIDFLAG#';
		P_MSC COM_MSC_BACKLOG.MSC%TYPE := '#MSC#';
		P_MSC_PLINE COM_MSC_BACKLOG.MSC_PLINE%TYPE := '#MSC_PLINE#';
		P_NAME COM_MSC_BACKLOG.UPDATE_NAME%TYPE := '#UPDATE_NAME#';
		
		
		BEGIN
		IF P_VALIDFLAG = '1' THEN
		  UPDATE COM_MSC_BACKLOG
		     SET VALIDFLAG   = '1',
		         UPDATE_NAME = P_NAME,
		         UPDATE_TIME = SYSDATE,
		         DELETE_NAME = '',
		         DELETE_TIME = ''
		   WHERE MSC = P_MSC
		     AND MSC_PLINE = P_MSC_PLINE;
		ELSIF P_VALIDFLAG = '0' THEN
		   UPDATE COM_MSC_BACKLOG
		     SET VALIDFLAG   = '0',
		         DELETE_NAME = P_NAME,
		         DELETE_TIME = SYSDATE
		   WHERE MSC = P_MSC
		     AND MSC_PLINE = P_MSC_PLINE; 
		END IF;
		END;
		 ]]>
	</query>
	
	<query id="MscManage.isExistProcess" desc="制程下面是否存在工序">
		<![CDATA[
		 SELECT COUNT(1)
		  FROM COM_MSC_PROCESS T
		 WHERE T.MSC = '#MSC#'
		   AND T.MSC_PLINE = '#MSC_PLINE#'
		   AND T.VALIDFLAG = '1'
		 ]]>
	</query>
	
	<query id="MscManage.isExistGrade" desc="制程下面是否存在钢种">
		<![CDATA[
		 SELECT COUNT(1) FROM COM_MSC_GRADE T WHERE T.MSC = '#MSC#' 
		 AND T.MSC_PLINE = '#MSC_PLINE#' AND T.VALIDFLAG = '1'
		 ]]>
	</query>
	
	<query id="MscManage.queryMscStationCnt" desc="查询工序下的工序点个数">
		<![CDATA[
			SELECT COUNT(1)
			  FROM COM_BASE_PROCESS_R_STATION B,COM_BASE_STATION BS
			  WHERE BS.PROCESS_CODE = '#PROCESS_CODE#'
			  AND B.PROCESS_CDOE_C = '#PROCESS_CDOE_C#'
			  AND BS.VALIDFLAG = '1'
			  AND B.STATION_CODE = BS.STATION_CODE
			  AND B.VALIDFLAG = '1'
		 ]]>
	</query>
	
	<query id="MscManage.queryMscProcess" desc="查询MSC工序">
		<![CDATA[
			SELECT DECODE(BE.STYLE, 'A', '一级工序', 'B', '二级工序', '未识别') STYLE,
				       BE.PROCESS_ID,
				       BE.COST,
				       NVL(MS.MINUTE_PRODUCT, BE.MINUTE_PRODUCT) MINUTE_PRODUCT,
				       NVL(MS.MINUTE_WAITE, BE.MINUTE_WAITE) MINUTE_WAITE,
				       NVL(MS.BATCH_WAITE, BE.BATCH_WAITE) BATCH_WAITE,
				       NVL(MS.MINUTE_PRODUCT_OUT, BE.MINUTE_PRODUCT_OUT) MINUTE_PRODUCT_OUT,
				       NVL(MS.MINUTE_WAITE_OUT, BE.MINUTE_WAITE_OUT) MINUTE_WAITE_OUT,
			           NVL(MS.BATCH_WAITE_OUT, BE.BATCH_WAITE_OUT) BATCH_WAITE_OUT,
				       BE.ICOUNT MAX_COUNT,
				       1 ICOUNT,
				       MS.MEMO,
				       MS.MSC,
				       BE.PROCESS_CODE,
				       BE.PROCESS_DESC,
				       MS.BACKLOG_SEQ,
				       MS.CIC,
				       MS.PIC,
				       MS.SIC,
				       MS.DIC,
				       MS.WIC,
				       MS.GIC,
				       NVL(MS.PROCESS_SEQ, '1') PROCESS_SEQ,
				       NVL(MS.PROCESS_SEQ, '1') PROCESS_SEQ_OLD,
				       MS.PROCESS_CODE_C,
				       MS.PROCESS_CODE_C PROCESS_CODE_C_OLD,
				       MS.PROCESS_DESC_C
				  FROM COM_BASE_PROCESS BE
				  LEFT JOIN COM_MSC_PROCESS MS
				    ON MS.PROCESS_CODE = BE.PROCESS_CODE
				   AND MS.MSC = '#MSC#'
				   AND MS.MSC_PLINE = '#MSC_PLINE#'
				   AND MS.VALIDFLAG = '1'
				 WHERE BE.VALIDFLAG = '1'
				   AND DECODE('#PROCESS_CODE#', NULL, '1', BE.PROCESS_CODE) =
				       DECODE('#PROCESS_CODE#', NULL, '1', '#PROCESS_CODE#')
				 ORDER BY BE.PROCESS_ID

		 ]]>
	</query>
	
	<query id="MscManage.queryMscProcess2" desc="查询工序基础（用于树形结构）">
		<![CDATA[
			SELECT 
			       MS.MSC,
			       MS.MSC_PLINE,
			       MS.PROCESS_CODE,
			       MS.CIC,
			       MS.PIC,
			       MS.SIC,
			       MS.DIC,
			       MS.WIC,
			       MS.GIC,
			       A.PROCESS_DESC,
			       BS.PROCESS_ID
			  FROM COM_MSC_PROCESS MS
			  LEFT JOIN COM_BASE_PROCESS BS ON MS.PROCESS_CODE = BS.PROCESS_CODE
			  LEFT JOIN COM_BASE_PROCESS A ON A.PROCESS_CODE = MS.PROCESS_CODE
			  WHERE MS.MSC = '#MSC#' AND MS.VALIDFLAG = '1'
			  ORDER BY BS.PROCESS_ID ASC
		 ]]>
	</query>
	
	<query id="MscManage.queryMscStation" desc="查询冶金工序点">
		<![CDATA[
SELECT A.BASENAME STATION_TYPE_DESC,
       BS.STATION_TYPE,
       BS.STATION_ID,
       BS.PROCESS_DESC,
       BS.PROCESS_CODE,
       BS.STATION_CODE,
       BS.STATION_DESC,
       NVL(MS.PROCESS_SEQ, '1') PROCESS_SEQ,
       B.PROCESS_CDOE_C PROCESS_CODE_C,
       B.PROCESS_DESC_C,
       DECODE(NVL(MS.CHOOSE, BS.CHOOSE), '1', 'True', 'False') CHOOSE,
       DECODE(NVL(MS.RETURN_RESULT, BS.RETURN_RESULT), '1', 'True', 'False') RETURN_RESULT,
       DECODE(NVL(MS.SEND_CHECKPLAN, BS.SEND_CHECKPLAN), '1', 'True', 'False') SEND_CHECKPLAN,
       DECODE(BS.CHOOSE, '1', 'True', 'False') CHK,
       MS.CREATE_NAME,
       TO_CHAR(MS.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS')  CREATE_TIME,
       MS.UPDATE_NAME,
       TO_CHAR(MS.UPDATE_TIME, 'YYYY-MM-DD HH24:MI:SS') UPDATE_TIME,
       MS.DELETE_NAME,
       TO_CHAR(MS.DELETE_TIME, 'YYYY-MM-DD HH24:MI:SS') DELETE_TIME,
       MS.VALIDFLAG,
       DECODE(MS.VALIDFLAG, '1', '有效', '0', '无效', '未识别') VALIDFLAG_NAME,
       MS.MSC,
       MS.MSC_PLINE,
       NVL(MS.COST, BS.COST) COST,
       MS.GROUP_SEQ,
       MS.PROCESS_SEQ,
       MS.BACKLOG_SEQ,
       MS.MEMO
  FROM COM_BASE_PROCESS_R_STATION B, COM_BASE_STATION BS
  LEFT JOIN COM_MSC_STATION MS
    ON MS.STATION_CODE = BS.STATION_CODE
   AND MS.MSC = '#MSC#'
   AND MS.MSC_PLINE = '#MSC_PLINE#'
   AND MS.PROCESS_CODE = '#PROCESS_CODE#'
   AND MS.VALIDFLAG = '1'
  LEFT JOIN COM_BASE_INFO A
    ON A.BASECODE = BS.STATION_TYPE
 WHERE BS.VALIDFLAG = '1'
 AND BS.PROCESS_CODE = '#PROCESS_CODE#'
 AND B.STATION_CODE = BS.STATION_CODE
 AND B.VALIDFLAG = '1'
 AND B.PROCESS_CDOE_C = '#PROCESS_CODE_C#'
 ORDER BY BS.STATION_ID
		 ]]>
	</query>
	
	<query id="MscManage.queryMscStation2" desc="查询工序点2(用于树形结构)">
		<![CDATA[
			SELECT MS.MSC,
			       MS.MSC_PLINE,
			       MS.PROCESS_CODE,
			       MS.STATION_CODE,
			       NVL(MS.PROCESS_SEQ, '1') PROCESS_SEQ
			       A.STATION_DESC,
			       MS.STATION_ID,
			       C.PROCESS_ID
			  FROM COM_MSC_STATION MS
			  LEFT JOIN COM_BASE_STATION A ON A.STATION_CODE = MS.STATION_CODE
			  LEFT JOIN COM_BASE_PROCESS C ON C.PROCESS_CODE = MS.PROCESS_CODE
			  AND C.VALIDFLAG = '1'
              WHERE MS.MSC = '#MSC#' AND MS.VALIDFLAG = '1'
              ORDER BY C.PROCESS_ID, MS.PROCESS_SEQ, MS.STATION_ID
		 ]]>
	</query>
	
	<query id="MscManage.queryProcessC" desc="查询二级工序">
		<![CDATA[
		SELECT T.PROCESS_CDOE_C, T.PROCESS_DESC_C, T.PROCESS_CDOE, T.PROCESS_DESC
		 from com_base_process_c t WHERE T.VALIDFLAG = '1'
		 ORDER BY T.PROCESS_DESC_C ASC
		 ]]>
	</query>
	
	<query id="MscManage.queryProcessCode" desc="查询工序代码">
		<![CDATA[
		SELECT T.PROCESS_CODE
		  FROM COM_BASE_PROCESS T
		 WHERE T.VALIDFLAG = '1'
		 ORDER BY T.PROCESS_ID
		 ]]>
	</query>
	
	<query id="MscManage.queryGrade" desc="查询钢种">
		<![CDATA[
			SELECT MSC,
		       MSC_PLINE,
		       GRADECODE,
		       GRADENAME,
		       ASSORTMENT_CODE,
		       ASSORTMENT_NAME,
		       CREATE_NAME,
		       CREATE_TIME,
		       UPDATE_NAME,
		       UPDATE_TIME,
		       DELETE_NAME,
		       DELETE_TIME,
		       VALIDFLAG,
		       MEMO,
		       STD_CODE,
		       STD_NAME,
		       CIC
		  FROM COM_MSC_GRADE
		 WHERE MSC = '#MSC#'
		   AND MSC_PLINE = '#MSC_PLINE#'
		   AND VALIDFLAG = '1'
		 ]]>
	</query>
	
	<query id="MscManage.queryGradeRSpec" desc="查询钢种下的规格表（从表）">
		<![CDATA[
SELECT MSC,
       MSC_PLINE,
       GRADECODE,
       GRADENAME,
       HEIGHT_MIN,
       DIMATER_MIN,
       DIMATER_MAX,
       HEIGHT_MIAX,
       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,
       VALIDFLAG,
       MEMO
  FROM COM_MSC_GRADE_R_SPEC T
 WHERE MSC = '#MSC#'
   AND MSC_PLINE = '#MSC_PLINE#'
   AND VALIDFLAG = '1'
   AND EXISTS (SELECT 1
          FROM COM_MSC_GRADE A
         WHERE MSC = '#MSC#'
           AND MSC_PLINE = '#MSC_PLINE#'
           AND VALIDFLAG = '1'
           AND  A.GRADECODE = T.GRADECODE)
		 ]]>
	</query>
	
	<query id="MscManage.queryMscItemByMsc" desc="查询冶金规范项目">
		<![CDATA[
		SELECT T.ITEM, A.BASENAME ITEM_NAME, T.ITEM_C
		  FROM COM_MSC_ITEM T
		  LEFT JOIN COM_BASE_INFO A ON A.BASECODE = T.ITEM
		 WHERE T.MSC = '#MSC#'
		 AND T.VALIDFLAG = '1'
		 ORDER BY T.INDEX_SEQ
		 ]]>
	</query>
	
	<query id="MscManage.queryMscBackLogByMsc" desc="查询冶金产线">
		<![CDATA[
		SELECT T.MSC_PLINE
		  FROM COM_MSC_BACKLOG T
		 WHERE T.MSC = '#MSC#'
		   AND T.VALIDFLAG IN ('1', '2', '3')
		 ]]>
	</query>
	
	<query id="MscManage.queryMscProcessByMsc" desc="查询冶金工序">
		<![CDATA[
SELECT T.MSC_PLINE,
       T.PROCESS_CODE,
       T.PROCESS_DESC,
       T.CIC,
       T.PIC,
       T.DIC,
       T.SIC,
       T.WIC,
       T.GIC
  FROM COM_MSC_PROCESS T
 WHERE T.MSC = '#MSC#'
   AND T.VALIDFLAG = '1'
 ORDER BY MSC_PLINE, BACKLOG_SEQ
		 ]]>
	</query>
	
	<query id="MscManage.queryMscStationByMsc" desc="查询冶金工序点">
		<![CDATA[
		SELECT T.MSC_PLINE, T.PROCESS_CODE, T.STATION_CODE, T.STATION_DESC, NVL(T.PROCESS_SEQ, '1') PROCESS_SEQ
		  FROM COM_MSC_STATION T
		 WHERE T.MSC = '#MSC#'
		   AND T.VALIDFLAG = '1'
		   ORDER BY T.MSC_PLINE, T.PROCESS_CODE, T.PROCESS_SEQ, T.STATION_ID
		 ]]>
	</query>
	
	<query id="MscManage.queryIsExistStdMsc" desc="查询是否存在标准MSC">
		<![CDATA[
		SELECT COUNT(1) FROM COM_PSC_R_MSC T WHERE T.PSC = '#PSC#'
			AND T.MSC LIKE '__________000'
		 ]]>
	</query>
	
	<query id="MscManage.queryProductType" desc="查询品名类型">
		<![CDATA[
			 SELECT PRODUC_TYPE
			  FROM COM_BASE_PRODUCT T
			 WHERE T.PRODUCCODE = '#PRODUCCODE#'
		]]>
	</query>
	
	<query id="MscManage.queryUnitCodeByPsc" desc="查询PSC表科室">
		<![CDATA[
		SELECT T.UNIT_CODE, T.DEPARTMENT_CODE FROM COM_PSC T WHERE T.PSC = '#PSC#'
		 ]]>
	</query>
	
	<query id="MscManage.queryJgByMsc" desc="冶金规范界面根据冶金规范码查询接箍信息">
		<![CDATA[
			SELECT AA.*,
       B.SPEC_NAME  SPEC_JG_DESC,
       C.BASENAME   PRODUCCODE_JG_DESC,
       D.STEELNAME  STEELCODE_JG_DESC,
       F.MODEL_DESC,
       G.PRODUCNAME,
       H.BASENAME STYLE_JG_DESC
  FROM (SELECT T.DEMAND_DETECTION,
               DECODE(T.DEMAND_BONDERIZING, '1', 'TRUE', 'FALSE') DEMAND_BONDERIZING,
               DECODE(T.DEMAND_COPPER, '1', 'TRUE', 'FALSE') DEMAND_COPPER,
               DECODE(T.DEMAND_BLAST, '1', 'TRUE', 'FALSE') DEMAND_BLAST,
               T.MSC,
               T.MEMO,
               A.STD_NAME,
               A.STD_STYLE_DESC,
               A.CHECK_J_VAL,
               (SELECT REPLACE(WM_CONCAT(A.STEELCODE_JG_DESC),',',';') 
                       FROM COM_MSC_JG_R_STEEL N WHERE N.STEELCODE= A.STEELCODE_JG) REP_STEELNAME,
               A.TAPER,
               A.MIN_D_JG,
               A.MAX_D_JG,
               A.CODE_JG,
               A.SPEC_JG,
               A.PRODUCCODE_JG,
               A.STEELCODE_JG,
               (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = A.STYLE_JG) STYLE_JG,
               A.PRODUCCODE,
               A.MODEL_CODE,
               A.DIAMETER_JG,
               A.LENGTH_JG,
               A.HEIGHT_JG,
               A.WEIGHT_JG,
               A.MIN_D,
               A.MIN_H,
               A.DIAMETER_PL,
               A.HEIGHT_PL,
               A.LENGTH_MIN,
               A.LENGTH_MAX,
               A.MIN_H_CP,
               A.MAX_H_CP,
               A.MIN_D_CP,
               A.MAX_D_CP,
               A.DIAMETER,
               A.ALPHA,
               A.VALIDFLAG,
               DECODE(A.VALIDFLAG, '1', '有效', '0', '无效', '未识别') VALIDFLAG_NAME,
               A.CREATE_NAME,
               A.CREATE_TIME,
               A.UPDATE_NAME,
               A.UPDATE_TIME,
               A.DELETE_NAME,
               A.DELETE_TIME
          FROM COM_MSC_R_JG T, COM_MSC_JG A
         WHERE T.MSC = '#MSC#'
           AND T.STOCK_STYLE = 'A'
           AND T.VALIDFLAG = '1'
           AND T.CODE_JG = A.CODE_JG) AA
  LEFT JOIN COM_BASE_SPEC B
    ON B.SPEC_CODE = AA.SPEC_JG
  LEFT JOIN COM_BASE_INFO C
    ON C.BASECODE = AA.PRODUCCODE_JG
  LEFT JOIN COM_BASE_STEEL D
    ON D.STEELCODE = AA.STEELCODE_JG
  LEFT JOIN COM_BASE_MODEL F
    ON F.MODEL_CODE = AA.MODEL_CODE
  LEFT JOIN COM_BASE_PRODUCT G
    ON G.PRODUCCODE = AA.PRODUCCODE
  LEFT JOIN COM_BASE_INFO H 
    ON H.BASECODE = AA.STYLE_JG

		]]>
	</query>
	
	<query id="MscManage.queryBlByJg" desc="接箍备料关联查询2">
		<![CDATA[   
       SELECT 
       'TRUE' CHK,
       T1.CODE_JG,
       T1.PSC_BL,
       T2.PRODUCCODE,
       T2.PRODUCNAME,
       T2.STD_CODE,
       T2.STD_NAME,
       T2.STEELCODE,
       T2.STEELNAME,
       T2.STD_STYLE,
       T2.STD_STYLE_DESC,
       T2.MODEL_CODE,
       T2.MODEL_DESC,
       T2.MIN_D,
       T2.MIN_H,
       T2.USE_CODE,
       T2.USE_DESC,
       T1.CREATE_NAME,
       TO_CHAR(T1.CREATE_TIME,'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
       T1.UPDATE_NAME,
       TO_CHAR(T1.UPDATE_TIME,'YYYY-MM-DD HH24:MI:SS') UPDATE_TIME,
       T1.DELETE_NAME,
       TO_CHAR(T1.DELETE_TIME,'YYYY-MM-DD HH24:MI:SS') DELETE_TIME,
       T1.VALIDFLAG,
       T1.MEMO
       FROM COM_MSC_JG_R_BL T1 ,COM_MSC_BL T2
       WHERE T1.CODE_JG=? AND T1.PSC_BL=T2.PSC_BL
		]]>
	</query> 
	
	<query id="MscManage.saveMscRJg" desc="保存接箍和冶金规范关系表中的3个附加要求">
		<![CDATA[
		UPDATE COM_MSC_R_JG T
		   SET T.DEMAND_DETECTION   = '#DEMAND_DETECTION#',
		       T.DEMAND_BONDERIZING = '#DEMAND_BONDERIZING#',
		       T.DEMAND_COPPER      = '#DEMAND_COPPER#',
		       T.DEMAND_BLAST = '#DEMAND_BLAST#',
		       T.UPDATE_NAME = '#UPDATE_NAME#',
		       T.UPDATE_TIME = SYSDATE,
		       T.MEMO = '#MEMO#'
		 WHERE T.MSC = '#MSC#'
		   AND T.CODE_JG = '#CODE_JG#'
		 ]]>
	</query>
	
	<query id="MscManage.queryMscRBlByMsc" desc="冶金规范中的备料查询">
		<![CDATA[
   SELECT 'False' CHK,
           T.MSC,
           T.GROUP_NUM,
           A.PSC_BL,
	       A.PRODUCCODE,
	       NVL(B.PRODUCNAME, A.PRODUCNAME) PRODUCNAME,
	       A.STD_CODE,
	       NVL(C.STD_NAME, A.STD_NAME) STD_NAME,
	       A.STEELCODE,
	       NVL(D.STEELNAME, A.STEELNAME) STEELNAME,
	       A.STD_STYLE,
	       NVL(F.STD_STYLE_DESC, A.STD_STYLE_DESC) STD_STYLE_DESC,
	       A.MODEL_CODE,
	       NVL(G.MODEL_DESC, A.MODEL_DESC) MODEL_DESC,
	       A.MIN_D,
	       A.MIN_H,
	       A.USE_CODE,
	       NVL(H.STD_NAME, A.USE_DESC) USE_DESC,
	       A.CREATE_NAME,
	       A.CREATE_TIME,
	       A.UPDATE_NAME,
	       A.UPDATE_TIME,
	       A.DELETE_NAME,
	       A.DELETE_TIME,
	       A.VALIDFLAG,
	       DECODE(A.VALIDFLAG, '1', '有效', '0', '无效', '未识别') VALIDFLAG_NAME,
	       A.MEMO
	  FROM COM_MSC_R_JG T, COM_MSC_BL A
	  LEFT JOIN COM_BASE_PRODUCT B ON B.PRODUCCODE = A.PRODUCCODE
	  LEFT JOIN COM_BASE_STD C ON C.STD_CODE = A.STD_CODE
	  LEFT JOIN COM_BASE_STEEL D ON D.STEELCODE = A.STEELCODE
	  LEFT JOIN COM_BASE_STD_STYLE F ON F.STD_STYLE = A.STD_STYLE
	  LEFT JOIN COM_BASE_MODEL G ON G.MODEL_CODE = A.MODEL_CODE
	  LEFT JOIN COM_BASE_STD H ON H.STD_CODE = A.USE_CODE
	 WHERE A.PSC_BL = T.CODE_JG
   AND T.MSC = ?
   AND T.STOCK_STYLE = 'B'
   AND T.VALIDFLAG = 1
   AND A.VALIDFLAG = '1'
		]]>
	</query>
	
	<query id="MscManage.groupBl" desc="分组">
		<![CDATA[ 
		UPDATE COM_MSC_R_JG T SET T.GROUP_NUM = ? WHERE T.MSC = ? AND T.CODE_JG = ?
		]]>
	</query>
	
	<query id="MscManage.queryClient" desc="查询客户">
		<![CDATA[ 
SELECT T.CUST_NAME, T.CUST_CODE
  FROM COM_BASE_STD_R_CUST T
 WHERE T.STD_CODE = '#USE_CODE#'
		]]>
	</query>
	
	<query id="MscManage.queryStdNameStyle" desc="查询冶金规范码所属的标准和协议。">
		<![CDATA[ 
SELECT A.STD_CODE, A.STD_NAME, A.STD_STYLE, B.BASENAME STD_STYLE_NAME
  FROM COM_BASE_STD A
  LEFT JOIN COM_BASE_INFO B
    ON A.STD_STYLE = B.BASECODE
 WHERE A.STD_CODE =
       (SELECT B.STD_CODE
          FROM COM_PSC B
         WHERE B.PSC =
               (SELECT C.PSC FROM COM_PSC_R_MSC C WHERE C.MSC = '#MSC#'))
		]]>
	</query>
</queryMap>
