<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="产品规范管理">
    <query id="CoreProductManage.queryStdMax" desc="标准基础 最大标准代码">
		<![CDATA[
			SELECT STD_CODE
              FROM COM_BASE_STD
             WHERE STD_CODE = (SELECT MAX(T.STD_CODE) STD_CODE FROM COM_BASE_STD T  WHERE LENGTH(T.STD_CODE) = 10)
		]]>
	</query>
	
	 <query id="CoreProductManage.IsPSCLinkMSC" desc="产品规范码下是否存在冶金规范码">
		<![CDATA[
			 SELECT 1  FROM COM_PSC_R_MSC  WHERE PSC=?
			 AND VALIDFLAG = '1'
		]]>
	</query>
	
	 <query id="CoreProductManage.GetProductHead" desc="产品规范码下是否存在冶金规范码">
		<![CDATA[
			 SELECT BASECODE,BASENAME
       FROM COM_BASE_INFO 
       WHERE SORTCODE='4049' AND VALIDFLAG='1'
		]]>
	</query>
	

    <query id="CoreProductManage.queryStd" desc="标准基础 查询">
		<![CDATA[
SELECT S.STD_CODE,
       S.STD_NAME,
       S.STDSTYLE,
       S.STD_NOTE,
       S.STD_STYLE,
       S.STD_STYLE_NAME,
       S.STD_VERSION,
       S.PROCESS_CODE,
       S.PROCESS_DESC,
       S.DEPARTMENT_CODE,
       S.DEPARTMENT_DESC,
       S.UNIT_CODE,
       S.UNIT_DESC,
       S.CREATE_NAME,
       TO_CHAR(S.CREATE_TIME, 'yyyy-mm-dd hh24:mi:ss') CREATE_TIME,
       S.UPDATE_NAME,
       TO_CHAR(S.UPDATE_TIME, 'yyyy-mm-dd hh24:mi:ss') UPDATE_TIME,
       S.DELETE_NAME,
       TO_CHAR(S.DELETE_TIME, 'yyyy-mm-dd hh24:mi:ss') DELETE_TIME,
       DECODE(S.VALIDFLAG, '1', '有效', '无效') VALIDFLAG,
       S.MEMO,
       NVL(A.CNT, 0) CNT,
       DECODE(S.FORBIDDEN_ORDER, '1', '禁用', '有效') FORBIDDEN_ORDER
  FROM COM_BASE_STD S
  LEFT JOIN (SELECT COUNT(1) CNT, AA.STD_CODE
               FROM SLM_ORDER_LINE AA,SLM_ORDER_HEAD BB
			  WHERE
			    AA.ORD_PK = BB.ORD_PK
				AND AA.ORDER_LN_STATUS < '12020602'
				AND BB.VALIDFLAG = '1'
                AND AA.VALIDFLAG = '1'
                GROUP BY AA.STD_CODE) A
    ON A.STD_CODE = S.STD_CODE
 WHERE LOWER(S.STD_NAME) || '&' LIKE '%' || LOWER(?) || '%'
   AND S.VALIDFLAG IN ('1', ?)
   AND S.STDSTYLE IN ('G', 'X')
   AND DECODE(?, '', '1', S.STD_CODE) = DECODE(?, '', '1', ?)
		]]>
	</query>
	
	<query id="CoreProductManage.queryPsc" desc="产品规范 查询">
		<![CDATA[
		    SELECT P.PSC,
                   P.PSC_DESC,
                   P.PSC_DESC AS OLD_PSCDESC,
                   P.PRODUCCODE,
                   P.PRODUCNAME,
                   P.STD_CODE,
                   P.STD_NAME,
                   P.STEELCODE,
                   P.STEELNAME,
                   P.STD_STYLE,
                   P.STD_STYLE_DESC,
                   DECODE(P.NEW_PROC_CODE, '1', 'TRUE', 'FALSE') NEW_PROC_CODE,
                   P.NEW_PROC_DESC,
                   P.DEPARTMENT_CODE,
                   P.DEPARTMENT_DESC,
                   P.UNIT_CODE,
                   DECODE(P.AUTOJUDGE, '1', 'TRUE', 'FALSE') AUTOJUDGE,
                   P.UNIT_DESC,
                   P.CREATE_NAME,
                   TO_CHAR(P.CREATE_TIME, 'yyyy-mm-dd hh24:mi:ss') CREATE_TIME,
                   P.UPDATE_NAME,
                   TO_CHAR(P.UPDATE_TIME, 'yyyy-mm-dd hh24:mi:ss') UPDATE_TIME,
                   P.DELETE_NAME,
                   TO_CHAR(P.DELETE_TIME, 'yyyy-mm-dd hh24:mi:ss') DELETE_TIME,
                   DECODE(P.VALIDFLAG, '1', '有效', '无效') VALIDFLAG,
                   P.MEMO,
                   P.PRODUC_STYLE,
                   P.PRODUC_DESC,
                   P.PRODUC_HEAD,
                   DECODE(P.PRODUC_TYPE,'A','钢管（管坯）','B','钢管+接箍','C','短节+附件',
                   'D','接箍','E','双公短节','未定义') PRODUC_TYPE,
                   P.PRODUC_TYPE AS TYPECODE,
                   P.COMPRESSION_RATIO
              FROM COM_PSC P
             WHERE P.STD_CODE=?
             AND   P.VALIDFLAG IN ('1', ?)

          ORDER BY PSC
			]]>
	</query>
	
	<query id="CoreProductManage.queryAdd" desc="标准附加项 查询">
		<![CDATA[
		   SELECT A.STD_CODE,
                  A.STD_NAME,
                  A.ASK_ITME,
                  A.ASK_ITME_DESC,
                  A.ASK_SUB_ITME,
                  A.ASK_SUB_ITME_DESC,
                  A.ASK_SUB_ITME_VAL,
                  A.ASK_SUB_ITME_VAL_DESC,
                  A.PIC,
                  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', '有效', '无效') VALIDFLAG,
                  A.MEMO,
                  A.ROWID || 'ROWID' PK
             FROM COM_BASE_ADDITIONAL A
            WHERE A.STD_CODE = '#STD_CODE#'
              AND A.VALIDFLAG IN ('1', '#VALIDFLAG#')
			]]>
	</query>	
	
	<query id="CoreProductManage.queryAlpha" desc="标准附加项 查询">
		<![CDATA[
SELECT 'FALSE' CHC,
       ALPHA_CODE,
       ALPHA_NAME,
       STD_CODE,
       STD_NOTE,
       STD_STYLE,
       STD_STYLE_NAME,
       STD_VERSION,
       DEPARTMENT_CODE,
       DEPARTMENT_DESC,
       UNIT_CODE,
       UNIT_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,
       DECODE(VALIDFLAG, '1', '有效', '0', '无效') VALIDFLAG,
       MEMO
  FROM COM_BASE_STD_ALPHA T
 WHERE STD_CODE = ?
   AND VALIDFLAG IN ('1', ?)
   AND (DECODE(?, 'False', '1', '2') = 1 OR NOT EXISTS
        (SELECT 1
           FROM COM_MSC A, COM_PSC_R_MSC B, COM_PSC C
          WHERE A.MSC = B.MSC
            AND B.PSC = C.PSC
            AND DECODE(?, NULL, '1', B.PSC) = DECODE(?, NULL, '1', ?)
            AND (? IS NULL OR B.USE_CODE <> ?)
            AND C.STD_CODE = T.STD_CODE
            AND A.USE_CODE = T.ALPHA_CODE))
			]]>
	</query>	
	
	
	<query id="CoreProductManage.addStd" desc="标准基础   增加">
		<![CDATA[
			INSERT INTO COM_BASE_STD
                        (STD_CODE,
                         STD_NAME,
                         STDSTYLE,
                         STD_NOTE,
                         STD_STYLE,
                         STD_STYLE_NAME,
                         STD_VERSION,
                         PROCESS_CODE,
                         PROCESS_DESC,
                         DEPARTMENT_CODE,
                         DEPARTMENT_DESC,
                         UNIT_CODE,
                         UNIT_DESC,
                         CREATE_NAME,
                         CREATE_TIME,
                         VALIDFLAG,
                         MEMO)
                 VALUES
                 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, SYSDATE, DEFAULT, ?)
		]]>
	</query>
	
	<query id="CoreProductManage.updateStd" desc="标准基础 修改">
		<![CDATA[
			UPDATE COM_BASE_STD
               SET STD_CODE        = ?,
                   STD_NAME        = ?,
                   STDSTYLE        = ?,
                   STD_NOTE        = ?,
                   STD_STYLE       = ?,
                   STD_STYLE_NAME  = ?,
                   STD_VERSION     = ?,
                   PROCESS_CODE    = ?,
                   PROCESS_DESC    = ?,
                   DEPARTMENT_CODE = ?,
                   DEPARTMENT_DESC = ?,
                   UNIT_CODE       = ?,
                   UNIT_DESC       = ?,
                   UPDATE_NAME     = ?,
                   UPDATE_TIME     = SYSDATE,
                   MEMO            = ?
            WHERE STD_CODE = ?			
		]]>
	</query>
	
	<query id="CoreProductManage.addPsc" desc="产品规范 增加">
		<![CDATA[
INSERT INTO COM_PSC
  (MEMO,
   PRODUC_HEAD,
   PRODUC_TYPE,
   PRODUC_STYLE,
   PRODUC_DESC,
   PSC,
   PSC_DESC,
   PRODUCCODE,
   PRODUCNAME,
   STD_CODE,
   STD_NAME,
   STEELCODE,
   STEELNAME,
   STD_STYLE,
   STD_STYLE_DESC,
   NEW_PROC_CODE,
   NEW_PROC_DESC,
   DEPARTMENT_CODE,
   DEPARTMENT_DESC,
   UNIT_CODE,
   AUTOJUDGE,
   UNIT_DESC,
   CREATE_NAME,
   CREATE_TIME,
   COMPRESSION_RATIO)
VALUES
  ('#MEMO#',
   '#PRODUC_HEAD#',
   '#PRODUC_TYPE#',
   '#PRODUC_STYLE#',
   '#PRODUC_DESC#',
   '#PSC#',
   '#PSC_DESC#',
   '#PRODUCCODE#',
   '#PRODUCNAME#',
   '#STD_CODE#',
   '#STD_NAME#',
   '#STEELCODE#',
   '#STEELNAME#',
   '#STD_STYLE#',
   '#STD_STYLE_DESC#',
   '#NEW_PROC_CODE#',
   '#NEW_PROC_DESC#',
   '#DEPARTMENT_CODE#',
   '#DEPARTMENT_DESC#',
   '#UNIT_CODE#',
   '#AUTOJUDGE#',
   '#UNIT_DESC#',
   '#CREATE_NAME#',
   SYSDATE,
   '#COMPRESSION_RATIO#')
		]]>
	</query>
	
		<query id="CoreProductManage.getMaxPsc" desc="获取最大的冶金规范">
		<![CDATA[
SELECT TO_NUMBER(SUBSTR(NVL(MAX(PSC), 'PSC0000000'), 4, 7)) AS MAX_VALUE FROM COM_PSC
		]]>
	</query>
	
	<query id="CoreProductManage.addAlpha" desc="产品规范 增加">
		<![CDATA[
	INSERT INTO COM_BASE_STD_ALPHA
    (ALPHA_CODE,
     ALPHA_NAME,
     STD_CODE,
     STD_NOTE,
     STD_STYLE,
     STD_STYLE_NAME,
     STD_VERSION,
     DEPARTMENT_CODE,
     DEPARTMENT_DESC,
     UNIT_CODE,
     UNIT_DESC,
     CREATE_NAME,
     CREATE_TIME,
     VALIDFLAG,
     MEMO)
     VALUES
    ((SELECT ? || LPAD(TO_CHAR(TO_NUMBER(SUBSTR(NVL(MAX(ALPHA_CODE),?||'-01'),11,3)) + 1),3,'0') AS ALPHA_CODE FROM COM_BASE_STD_ALPHA WHERE STD_CODE=?), 
     ?,?,?,?,?,?,?,?,?,?,?, SYSDATE,DEFAULT,?)
			 
		]]>
	</query>
	
		<query id="CoreProductManage.addAlphaNew" desc="产品规范 增加">
		<![CDATA[
	INSERT INTO COM_BASE_STD_ALPHA
    (ALPHA_CODE,
     ALPHA_NAME,
     STD_CODE,
     STD_NOTE,
     STD_STYLE,
     STD_STYLE_NAME,
     STD_VERSION,
     DEPARTMENT_CODE,
     DEPARTMENT_DESC,
     UNIT_CODE,
     UNIT_DESC,
     CREATE_NAME,
     CREATE_TIME,
     VALIDFLAG,
     MEMO)
     VALUES
    (?,?,?,?,?,?,?,?,?,?,?,?, SYSDATE,DEFAULT,?)
			 
		]]>
	</query>
	
	<query id="CoreProductManage.queryStdMax1" desc="产品规范 增加">
		<![CDATA[
		SELECT SUBSTR(NVL(MAX(ALPHA_CODE),?||'-01'),11,3)
		FROM COM_BASE_STD_ALPHA WHERE STD_CODE=? AND LENGTH(ALPHA_CODE)=13
			 
		]]>
	</query>
	
	<query id="CoreProductManage.queryStdMax2" desc="产品规范 增加">
		<![CDATA[
		SELECT SUBSTR(NVL(MAX(ALPHA_CODE),?||'0999'),11,4)
		FROM COM_BASE_STD_ALPHA WHERE STD_CODE=? AND LENGTH(ALPHA_CODE)=14
			 
		]]>
	</query>
	
	<query id="CoreProductManage.updateAlpha" desc="产品规范 修改">
		<![CDATA[
		
			 UPDATE COM_BASE_STD_ALPHA
       SET  
       ALPHA_NAME      = ?,
       STD_CODE        = ?,
       STD_NOTE        = ?,
       STD_STYLE       = ?,
       STD_STYLE_NAME  = ?,
       STD_VERSION     = ?,
       DEPARTMENT_CODE = ?,
       DEPARTMENT_DESC = ?,
       UNIT_CODE       = ?,
       UNIT_DESC       = ?,
       UPDATE_NAME     = ?,
       UPDATE_TIME     = SYSDATE,
       MEMO            = ?
       WHERE  ALPHA_CODE     = ?
			 
		]]>
	</query>
	
	<query id="CoreProductManage.updateMscAlphaDesc" desc="修改冶金规范用途码描述">
		<![CDATA[
 UPDATE COM_MSC T SET T.USE_DESC = ? WHERE T.USE_CODE = ?
		]]>
	</query>
	
	<query id="CoreProductManage.updatePsc" desc="产品规范 修改">
		<![CDATA[
			UPDATE COM_PSC
               SET PSC_DESC        = ?,
                   PRODUCCODE      = ?,
                   PRODUCNAME      = ?,
                   STD_CODE        = ?,
                   STD_NAME        = ?,
                   STEELCODE       = ?,
                   STEELNAME       = ?,
                   STD_STYLE       = ?,
                   STD_STYLE_DESC  = ?,
                   NEW_PROC_CODE   = ?,
                   NEW_PROC_DESC   = ?,
                   DEPARTMENT_CODE = ?,
                   DEPARTMENT_DESC = ?,
                   UNIT_CODE       = ?,
                   AUTOJUDGE       = ?,
                   UNIT_DESC       = ?,
                   UPDATE_NAME     = ?,
                   UPDATE_TIME     = SYSDATE,
                   MEMO            = ?,
                   PRODUC_HEAD     = ?,
                   PRODUC_TYPE     = ?,
                   PRODUC_STYLE    = ?,
                   PRODUC_DESC     = ?,
                   COMPRESSION_RATIO=?
             WHERE PSC = ?
		]]>
	</query>
	
	<query id="CoreProductManage.addAdd" desc="标准附加项 增加">
		<![CDATA[
              INSERT INTO COM_BASE_ADDITIONAL
                         (STD_CODE,
                          STD_NAME,
                          ASK_ITME,
                          ASK_ITME_DESC,
                          ASK_SUB_ITME,
                          ASK_SUB_ITME_DESC,
                          ASK_SUB_ITME_VAL,
                          ASK_SUB_ITME_VAL_DESC,
                          PIC,
                          CREATE_NAME,
                          CREATE_TIME,
                          VALIDFLAG,
                          MEMO)
                  VALUES
                         (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, SYSDATE, DEFAULT, ?)
		]]>
	</query>
	
	<query id="CoreProductManage.updateAdd" desc="标准附加项 修改">
		<![CDATA[
			UPDATE COM_BASE_ADDITIONAL
   SET STD_CODE              = ?,
       STD_NAME              = ?,
       ASK_ITME              = ?,
       ASK_ITME_DESC         = ?,
       ASK_SUB_ITME          = ?,
       ASK_SUB_ITME_DESC     = ?,
       ASK_SUB_ITME_VAL      = ?,
       ASK_SUB_ITME_VAL_DESC = ?,
       PIC                   = ?,
       UPDATE_NAME           = ?,
       UPDATE_TIME           = SYSDATE,
       MEMO                  = ?
 WHERE ROWID = ?
		]]>
	</query>
	
	<query id="CoreProductManage.deleteStd" desc="标准基础 作废">
		<![CDATA[
			UPDATE COM_BASE_STD
               SET DELETE_NAME = ?, DELETE_TIME = SYSDATE, VALIDFLAG = '0'
             WHERE STD_CODE = ?
		]]>
	</query>
	
	<query id="CoreProductManage.resumeStd" desc="标准基础 恢复">
		<![CDATA[
			UPDATE COM_BASE_STD
               SET DELETE_NAME = ?, DELETE_TIME = NULL, VALIDFLAG = '1'
             WHERE STD_CODE = ?
		]]>
    </query>
		
	<query id="CoreProductManage.deletePsc" desc="产品规范 作废">
		<![CDATA[
			UPDATE COM_PSC
               SET DELETE_NAME = ?, DELETE_TIME = SYSDATE, VALIDFLAG = '0'
             WHERE PSC = ?
		]]>
	</query>
	
	<query id="CoreProductManage.resumePsc" desc="产品规范 恢复">
		<![CDATA[
			UPDATE COM_PSC
               SET DELETE_NAME = ?, DELETE_TIME = NULL, VALIDFLAG = '1'
             WHERE PSC = ?			
		]]>
	</query>
	
	<query id="CoreProductManage.deleteAdd" desc="附加项 作废">
		<![CDATA[
			UPDATE COM_BASE_ADDITIONAL
               SET DELETE_NAME = ?, DELETE_TIME = SYSDATE, VALIDFLAG = '0'
             WHERE STD_CODE = ?
               AND ASK_SUB_ITME_VAL = ?		
		]]>
	</query>
	
	<query id="CoreProductManage.resumeAdd" desc="附加项 恢复">
		<![CDATA[
			UPDATE COM_BASE_ADDITIONAL
               SET DELETE_NAME = ?, DELETE_TIME = NULL, VALIDFLAG = '1'
             WHERE STD_CODE = ?
               AND ASK_SUB_ITME_VAL = ?		
		]]>
	</query>
	
	<query id="CoreProductManage.deleteAlpha" desc="ALpha 作废">
		<![CDATA[
			UPDATE COM_BASE_STD_ALPHA
               SET DELETE_NAME = ?, DELETE_TIME = SYSDATE, VALIDFLAG = '0'
             WHERE ALPHA_CODE= ?
               AND VALIDFLAG = '1'		
		]]>
	</query>
	
	<query id="CoreProductManage.resumeAlpha" desc="Alpha 恢复">
		<![CDATA[
			UPDATE COM_BASE_STD_ALPHA
               SET DELETE_NAME = '', DELETE_TIME = NULL, VALIDFLAG = '1'
             WHERE ALPHA_CODE = ?
               AND VALIDFLAG = '0'		
		]]>
	</query>
	
	<query id="CoreProductManage.checkAdd" desc="附加项 检验">
		<![CDATA[
			SELECT 1  FROM COM_BASE_ADDITIONAL A
             WHERE A.STD_CODE = ?
               AND A.ASK_SUB_ITME_VAL = ?	
		]]>
	</query>
	
	<query id="CoreProductManage.checkPsc" desc="产品规范 检验">
		<![CDATA[
			SELECT 1 FROM COM_PSC P
			WHERE DECODE('#PRODUCCODE#', NULL, '1', P.PRODUCCODE) = DECODE('#PRODUCCODE#', NULL, '1', '#PRODUCCODE#')
			AND DECODE('#PRODUCCODE#', NULL, P.PRODUCCODE, NULL) IS NULL
			AND DECODE('#STD_STYLE#', NULL, '1', P.STD_STYLE) = DECODE('#STD_STYLE#', NULL, '1', '#STD_STYLE#')
			AND DECODE('#STD_STYLE#', NULL, P.STD_STYLE, NULL) IS NULL
			AND DECODE('#STEELCODE#', NULL, '1', P.STEELCODE) = DECODE('#STEELCODE#', NULL, '1', '#STEELCODE#')
			AND DECODE('#STEELCODE#', NULL, P.STEELCODE, NULL) IS NULL
			AND DECODE('#STD_CODE#', NULL, '1', P.STD_CODE) = DECODE('#STD_CODE#', NULL, '1', '#STD_CODE#')
			AND DECODE('#STD_CODE#', NULL, P.STD_CODE, NULL) IS NULL
		]]>
	</query>
	
	<query id="CoreProductManage.checkAlpha" desc="产品规范 检验">
		<![CDATA[
			SELECT COUNT(1) FROM COM_BASE_STD_ALPHA P WHERE P.ALPHA_NAME = ?
			AND P.STD_CODE = ?
		]]>
	</query>
	
	<query id="CoreProductManage.checkPscUpdate" desc="产品规范 检验">
		<![CDATA[
			SELECT 1
            FROM COM_PSC  P
            WHERE DECODE('#PRODUCCODE#', NULL, '1', P.PRODUCCODE) = DECODE('#PRODUCCODE#', NULL, '1', '#PRODUCCODE#')
            AND DECODE('#PRODUCCODE#', NULL, P.PRODUCCODE, NULL) IS NULL
			AND DECODE('#STD_STYLE#', NULL, '1', P.STD_STYLE) = DECODE('#STD_STYLE#', NULL, '1', '#STD_STYLE#')
			AND DECODE('#STD_STYLE#', NULL, P.STD_STYLE, NULL) IS NULL
			AND DECODE('#STEELCODE#', NULL, '1', P.STEELCODE) = DECODE('#STEELCODE#', NULL, '1', '#STEELCODE#')
			AND DECODE('#STEELCODE#', NULL, P.STEELCODE, NULL) IS NULL
			AND DECODE('#STD_CODE#', NULL, '1', P.STD_CODE) = DECODE('#STD_CODE#', NULL, '1', '#STD_CODE#')
			AND DECODE('#STD_CODE#', NULL, P.STD_CODE, NULL) IS NULL
			AND P.PSC != '#PSC#'
		]]>
	</query>
	
	<query id="CoreProductManage.checkAlphaUpdate" desc="产品规范 检验">
		<![CDATA[
		SELECT COUNT(1) FROM COM_BASE_STD_ALPHA P WHERE P.ALPHA_CODE != ?
               AND P.ALPHA_NAME = ? AND P.STD_CODE = ?
		]]>
	</query>
	
	<query id="CoreProductManage.checkStd" desc="标准名称 检验">
		<![CDATA[
SELECT 1
  FROM COM_BASE_STD S
 WHERE S.STD_NAME = '#STD_NAME#'
   AND S.STDSTYLE = '#STDSTYLE#'
		]]>
	</query>
	
	<query id="CoreProductManage.checkStdUpdate" desc="标准名称 检验">
		<![CDATA[
SELECT 1
  FROM (SELECT * FROM COM_BASE_STD S WHERE S.STD_CODE != '#STD_CODE#')
 WHERE STD_NAME = '#STD_NAME#'
   and STDSTYLE = '#STDSTYLE#'
		]]>
	</query>
	
	<query id="CoreProductManage.checkStdDelete" desc="标准名称 检验刪除时检验是否引用表是否已经删除">
		<![CDATA[
			SELECT SUM(COUM)
              FROM (SELECT COUNT(1) AS COUM
                      FROM COM_PSC P
                     WHERE P.STD_CODE = ?
                       AND P.VALIDFLAG = 1
                     UNION
                    SELECT COUNT(1) AS COUM
                      FROM COM_BASE_ADDITIONAL A
                     WHERE A.STD_CODE = ?
                       AND A.VALIDFLAG = 1
                       UNION 
                      SELECT COUNT(1) AS COUM
                       FROM COM_BASE_STD_ALPHA T
                       WHERE T.STD_CODE=?
                       AND T.VALIDFLAG='1')
		]]>
	</query>
	
	<query id="CoreProductManage.checkAlphaDelete" desc="标准名称 检验刪除时检验是否引用表是否已经删除">
		<![CDATA[
			 SELECT COUNT(1) FROM COM_BASE_STD_R_CUST
			 WHERE STD_CODE=? AND VALIDFLAG='1'
		]]>
	</query>
	
	<query id="CoreProductManage.checkFromResume" desc="标准名称 检验标准代码是否已经恢复">
		<![CDATA[
			SELECT 1
              FROM COM_BASE_STD S
             WHERE S.STD_CODE = ?
               AND S.VALIDFLAG = 0
		]]>
	</query>
	
	<query id="CoreProductManage.checkFromResumeAlpha" desc="标准名称 检验标准代码是否已经恢复">
		<![CDATA[
			SELECT 1
              FROM COM_BASE_STD_ALPHA S
             WHERE S.ALPHA_CODE = ?
               AND S.VALIDFLAG = 0
		]]>
	</query>
	
	<query id="CoreProductManage.getSubItem" desc="附加要求">
		<![CDATA[
			SELECT A.ASK_ITEM_NO, A.ASK_ITEM_DESC,A.PIC
              FROM SLM_BASE_ADD_ASK A
             WHERE A.ASK_P_ITEM_NO = ?
               AND DECODE(?, NULL, '1', A.STDFLAG) = DECODE(?, NULL, '1', ?)
               AND A.VALIDFLAG = 1
               ORDER BY ASK_ITEM_DESC		
		]]>
	</query>
	
	<query id="CoreProductManage.getSubItem2" desc="附加要求2">
		<![CDATA[
			SELECT A.ASK_ITEM_NO BASECODE, A.ASK_ITEM_DESC BASENAME
              FROM SLM_BASE_ADD_ASK A
             WHERE A.ASK_P_ITEM_NO = ?
               AND DECODE(?, NULL, '1', A.STDFLAG) = DECODE(?, NULL, '1', ?)
               AND A.VALIDFLAG = 1
               ORDER BY ASK_ITEM_DESC		
		]]>
	</query>
	
	<query id="CoreProductManage.getStdDesc" desc="附加要求">
		<![CDATA[
			SELECT PIC FROM 	SLM_BASE_ADD_ASK
			WHERE ASK_ITEM_NO =? AND VALIDFLAG='1'
		]]>
	</query>
	
<query id="CoreProductManage.setMsc" desc="新增msc">
		<![CDATA[
 INSERT INTO COM_MSC(
        MSC,
        MSC_DESC,
        USE_CODE,
        USE_DESC,
        DEPARTMENT_CODE,
        DEPARTMENT_DESC,
        UNIT_CODE,
        UNIT_DESC,
        MSC_STYLE,
        USER_COUNT,
        PRODUCCODE,
        PRODUCNAME,
        STD_CODE,
        STD_NAME,
        STEELCODE,
        STEELNAME,
        STD_STYLE,
        STD_STYLE_DESC,
        NEW_PROC_CODE,
        NEW_PROC_DESC,
        ALLOW_NK,
        MSC_SEQ,
        MSC_DESC_SEQ,
        CREATE_NAME,
        CREATE_TIME,
        PRODUC_HEAD,
        UNIT_CODE_PROCESS,
        UNIT_DESC_PROCESS)
 VALUES( 
        '#MSC#',
        '#MSC_DESC#',
        '#USE_CODE#',
        '#USE_DESC#',
        '#DEPARTMENT_CODE#',
        '#DEPARTMENT_DESC#',
        '#UNIT_CODE#',
        '#UNIT_DESC#',
        '#MSC_STYLE#',
        '#USER_COUNT#',
        '#PRODUCCODE#',
        '#PRODUCNAME#',
        '#STD_CODE#',
        '#STD_NAME#',
        '#STEELCODE#',
        '#STEELNAME#',
        '#STD_STYLE#',
        '#STD_STYLE_DESC#',
        '#NEW_PROC_CODE#',
        '#NEW_PROC_DESC#',
        '#ALLOW_NK#',
        '#MSC_SEQ#',
        '#MSC_DESC_SEQ#',
        '#CREATE_NAME#',
        SYSDATE,
        '#PRODUC_HEAD#',
        '#UNIT_CODE_PROCESS#',
        '#UNIT_DESC_PROCESS#')
		]]>
	</query>
	
	<query id="CoreProductManage.setPscRMsc" desc="新增psc和msc关系">
		<![CDATA[
 INSERT INTO COM_PSC_R_MSC(
        PSC,
        PSC_DESC,
        USE_CODE,
        USE_DESC,
        MSC,
        MSC_DESC,
        CREATE_NAME,
        CREATE_TIME)
 VALUES( 
        '#PSC#',
        '#PSC_DESC#',
        '#USE_CODE#',
        '#USE_DESC#',
        '#MSC#',
        '#MSC_DESC#',
        '#CREATE_NAME#',
        SYSDATE)
		]]>
	</query>
	
	<query id="CoreProductManage.setBaseStdAlpha" desc="新增用途码">
		<![CDATA[
 INSERT INTO COM_BASE_STD_ALPHA(
        ALPHA_CODE,
        ALPHA_NAME,
        STD_CODE,
        DEPARTMENT_CODE,
        DEPARTMENT_DESC,
        UNIT_CODE,
        UNIT_DESC,
        CREATE_NAME,
        CREATE_TIME)
 VALUES( 
        '#ALPHA_CODE#',
        '#ALPHA_NAME#',
        '#STD_CODE#',
        '#DEPARTMENT_CODE#',
        '#DEPARTMENT_DESC#',
        '#UNIT_CODE#',
        '#UNIT_DESC#',
        '#CREATE_NAME#',
        SYSDATE)
		]]>
	</query>
	
	<query id="CoreProductManage.deleteOrResumeStd" desc="删除或者作废标准向下数据">
		<![CDATA[
DECLARE
BEGIN
  IF '#DELETE_FLAG#' = 'True' THEN
    UPDATE COM_BASE_STD SET VALIDFLAG = '0' WHERE STD_CODE = '#STD_CODE#';
    UPDATE COM_PSC SET VALIDFLAG = '0' WHERE STD_CODE = '#STD_CODE#';
    UPDATE COM_BASE_STD_ALPHA
       SET VALIDFLAG = '0'
     WHERE STD_CODE = '#STD_CODE#';
    FOR V_ROW IN (SELECT ALPHA_CODE
                    FROM COM_BASE_STD_ALPHA
                   WHERE STD_CODE = '#STD_CODE#') LOOP
      UPDATE COM_BASE_STD_R_CUST
         SET VALIDFLAG = '0'
       WHERE STD_CODE = V_ROW.ALPHA_CODE;
    END LOOP;
    UPDATE COM_BASE_STD_R_SPEC
       SET VALIDFLAG = '0'
     WHERE STD_CODE = '#STD_CODE#';
    UPDATE COM_BASE_ADDITIONAL
       SET VALIDFLAG = '0'
     WHERE STD_CODE = '#STD_CODE#';
    FOR V_ROW IN (SELECT MSC
                    FROM COM_PSC_R_MSC A, COM_PSC B
                   WHERE A.PSC = B.PSC
                     AND B.STD_CODE = '#STD_CODE#') LOOP
      UPDATE COM_MSC
         SET VALIDFLAG    = 'D',
             DELETE_NAME  = '#DELETE_NAME#',
             DELETE_TIME  = SYSDATE,
             VALIDFLAG_NK = 'D'
       WHERE MSC = V_ROW.MSC;
      UPDATE COM_PSC_R_MSC T
         SET T.VALIDFLAG   = '0',
             T.DELETE_NAME = '#DELETE_NAME#',
             T.DELETE_TIME = SYSDATE
       WHERE T.MSC = V_ROW.MSC;
      UPDATE COM_MSC_STD_CIC T
         SET T.VALIDFLAG   = '0',
             T.DELETE_NAME = '#DELETE_NAME#',
             T.DELETE_TIME = SYSDATE
       WHERE T.MSC = V_ROW.MSC
         AND T.VALIDFLAG <> '0';
      UPDATE COM_MSC_STD_PIC T
         SET T.VALIDFLAG   = '0',
             T.DELETE_NAME = '#DELETE_NAME#',
             T.DELETE_TIME = SYSDATE
       WHERE T.MSC = V_ROW.MSC
         AND T.VALIDFLAG <> '0';
      UPDATE COM_MSC_STD_DETECTION T
         SET T.VALIDFLAG   = '0',
             T.DELETE_NAME = '#DELETE_NAME#',
             T.DELETE_TIME = SYSDATE
       WHERE T.MSC = V_ROW.MSC
         AND T.VALIDFLAG <> '0';
      UPDATE COM_MSC_STD_SPEC T
         SET T.VALIDFLAG   = '0',
             T.DELETE_NAME = '#DELETE_NAME#',
             T.DELETE_TIME = SYSDATE
       WHERE T.MSC = V_ROW.MSC
         AND T.VALIDFLAG <> '0';
      UPDATE COM_MSC_STD_WATER T
         SET T.VALIDFLAG   = '0',
             T.DELETE_NAME = '#DELETE_NAME#',
             T.DELETE_TIME = SYSDATE
       WHERE T.MSC = V_ROW.MSC
         AND T.VALIDFLAG <> '0';
      UPDATE COM_MSC_STD_PROCESS T
         SET T.VALIDFLAG   = '0',
             T.DELETE_NAME = '#DELETE_NAME#',
             T.DELETE_TIME = SYSDATE
       WHERE T.MSC = V_ROW.MSC
         AND T.VALIDFLAG <> '0';
      UPDATE COM_MSC_BACKLOG T
         SET T.VALIDFLAG    = '0',
             T.VALIDFLAG_NK = '0',
             T.DELETE_NAME  = '#DELETE_NAME#',
             T.DELETE_TIME  = SYSDATE
       WHERE T.MSC = V_ROW.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 IN
             (SELECT A.CIC FROM COM_MSC_STD_CIC A WHERE A.MSC = V_ROW.MSC);
      UPDATE COM_MSC_STD_PHY T
         SET T.VALIDFLAG   = '0',
             T.DELETE_NAME = '#DELETE_NAME#',
             T.DELETE_TIME = SYSDATE
       WHERE T.PIC IN
             (SELECT A.PIC FROM COM_MSC_STD_PIC A WHERE A.MSC = V_ROW.MSC);
      UPDATE COM_MSC_STD_DETECTION_C T
         SET T.VALIDFLAG   = '0',
             T.DELETE_NAME = '#DELETE_NAME#',
             T.DELETE_TIME = SYSDATE
       WHERE T.DIC IN (SELECT A.DIC
                         FROM COM_MSC_STD_DETECTION A
                        WHERE A.MSC = V_ROW.MSC);
      UPDATE COM_MSC_STD_SPEC_C T
         SET T.VALIDFLAG   = '0',
             T.DELETE_NAME = '#DELETE_NAME#',
             T.DELETE_TIME = SYSDATE
       WHERE T.SIC IN
             (SELECT A.SIC FROM COM_MSC_STD_SPEC A WHERE A.MSC = V_ROW.MSC);
      UPDATE Com_Msc_Std_Water_C T
         SET T.VALIDFLAG   = '0',
             T.DELETE_NAME = '#DELETE_NAME#',
             T.DELETE_TIME = SYSDATE
       WHERE T.WIC IN
             (SELECT A.WIC FROM Com_Msc_Std_Water A WHERE A.MSC = V_ROW.MSC);
      UPDATE Com_Msc_Std_Process_c T
         SET T.VALIDFLAG   = '0',
             T.DELETE_NAME = '#DELETE_NAME#',
             T.DELETE_TIME = SYSDATE
       WHERE T.GIC IN (SELECT A.GIC
                         FROM Com_Msc_Std_Process A
                        WHERE A.MSC = V_ROW.MSC);
      UPDATE Com_Msc_Process T
         SET T.VALIDFLAG   = '0',
             T.DELETE_NAME = '#DELETE_NAME#',
             T.DELETE_TIME = SYSDATE
       WHERE T.MSC = V_ROW.MSC;
      UPDATE Com_Msc_Station T
         SET T.VALIDFLAG   = '0',
             T.DELETE_NAME = '#DELETE_NAME#',
             T.DELETE_TIME = SYSDATE
       WHERE T.MSC = V_ROW.MSC;
      UPDATE Com_Msc_Grade T
         SET T.VALIDFLAG   = '0',
             T.DELETE_NAME = '#DELETE_NAME#',
             T.DELETE_TIME = SYSDATE
       WHERE T.MSC = V_ROW.MSC;
      UPDATE Com_Msc_Grade_r_Spec T
         SET T.VALIDFLAG   = '0',
             T.DELETE_NAME = '#DELETE_NAME#',
             T.DELETE_TIME = SYSDATE
       WHERE T.MSC = V_ROW.MSC;
      UPDATE COM_MSC_R_JG T
         SET T.VALIDFLAG   = '0',
             T.DELETE_NAME = '#DELETE_NAME#',
             T.DELETE_TIME = SYSDATE
       WHERE T.MSC = V_ROW.MSC;
      UPDATE COM_MSC_STD_CRAFT T
         SET T.VALIDFLAG   = '0',
             T.DELETE_NAME = '#DELETE_NAME#',
             T.DELETE_TIME = SYSDATE
       WHERE T.MSC = V_ROW.MSC;
    END LOOP;
  ELSE
    UPDATE COM_BASE_STD SET VALIDFLAG = '1' WHERE STD_CODE = '#STD_CODE#';
    UPDATE COM_PSC SET VALIDFLAG = '1' WHERE STD_CODE = '#STD_CODE#';
    UPDATE COM_BASE_STD_ALPHA
       SET VALIDFLAG = '1'
     WHERE STD_CODE = '#STD_CODE#';
    FOR V_ROW IN (SELECT ALPHA_CODE
                    FROM COM_BASE_STD_ALPHA
                   WHERE STD_CODE = '#STD_CODE#') LOOP
      UPDATE COM_BASE_STD_R_CUST
         SET VALIDFLAG = '1'
       WHERE STD_CODE = V_ROW.ALPHA_CODE;
    END LOOP;
    UPDATE COM_BASE_STD_R_SPEC
       SET VALIDFLAG = '1'
     WHERE STD_CODE = '#STD_CODE#';
    UPDATE COM_BASE_ADDITIONAL
       SET VALIDFLAG = '1'
     WHERE STD_CODE = '#STD_CODE#';
    FOR V_ROW IN (SELECT MSC
                    FROM COM_PSC_R_MSC A, COM_PSC B
                   WHERE A.PSC = B.PSC
                     AND B.STD_CODE = '#STD_CODE#') LOOP
      UPDATE COM_MSC
         SET VALIDFLAG    = 'A',
             DELETE_NAME  = NULL,
             DELETE_TIME  = NULL,
             VALIDFLAG_NK = 'A'
       WHERE MSC = V_ROW.MSC;
      UPDATE COM_PSC_R_MSC T
         SET T.VALIDFLAG = '1', T.DELETE_NAME = NULL, T.DELETE_TIME = NULL
       WHERE T.MSC = V_ROW.MSC;
      UPDATE COM_MSC_STD_CIC T
         SET T.VALIDFLAG = '1', T.DELETE_NAME = NULL, T.DELETE_TIME = NULL
       WHERE T.MSC = V_ROW.MSC;
      UPDATE COM_MSC_STD_PIC T
         SET T.VALIDFLAG = '1', T.DELETE_NAME = NULL, T.DELETE_TIME = NULL
       WHERE T.MSC = V_ROW.MSC;
      UPDATE COM_MSC_STD_DETECTION T
         SET T.VALIDFLAG = '1', T.DELETE_NAME = NULL, T.DELETE_TIME = NULL
       WHERE T.MSC = V_ROW.MSC;
      UPDATE COM_MSC_STD_SPEC T
         SET T.VALIDFLAG = '1', T.DELETE_NAME = NULL, T.DELETE_TIME = NULL
       WHERE T.MSC = V_ROW.MSC;
      UPDATE COM_MSC_STD_WATER T
         SET T.VALIDFLAG = '1', T.DELETE_NAME = NULL, T.DELETE_TIME = NULL
       WHERE T.MSC = V_ROW.MSC;
      UPDATE COM_MSC_STD_PROCESS T
         SET T.VALIDFLAG = '1', T.DELETE_NAME = NULL, T.DELETE_TIME = NULL
       WHERE T.MSC = V_ROW.MSC;
      UPDATE COM_MSC_BACKLOG T
         SET T.VALIDFLAG    = '1',
             T.VALIDFLAG_NK = NULL,
             T.DELETE_NAME  = NULL,
             T.DELETE_TIME  = SYSDATE
       WHERE T.MSC = V_ROW.MSC;
      UPDATE COM_MSC_STD_CHEM T
         SET T.VALIDFLAG = '1', T.DELETE_NAME = NULL, T.DELETE_TIME = NULL
       WHERE T.CIC IN
             (SELECT A.CIC FROM COM_MSC_STD_CIC A WHERE A.MSC = V_ROW.MSC);
      UPDATE COM_MSC_STD_PHY T
         SET T.VALIDFLAG = '1', T.DELETE_NAME = NULL, T.DELETE_TIME = NULL
       WHERE T.PIC IN
             (SELECT A.PIC FROM COM_MSC_STD_PIC A WHERE A.MSC = V_ROW.MSC);
      UPDATE COM_MSC_STD_DETECTION_C T
         SET T.VALIDFLAG = '1', T.DELETE_NAME = NULL, T.DELETE_TIME = NULL
       WHERE T.DIC IN (SELECT A.DIC
                         FROM COM_MSC_STD_DETECTION A
                        WHERE A.MSC = V_ROW.MSC);
      UPDATE COM_MSC_STD_SPEC_C T
         SET T.VALIDFLAG = '1', T.DELETE_NAME = NULL, T.DELETE_TIME = NULL
       WHERE T.SIC IN
             (SELECT A.SIC FROM COM_MSC_STD_SPEC A WHERE A.MSC = V_ROW.MSC);
      UPDATE Com_Msc_Std_Water_C T
         SET T.VALIDFLAG = '1', T.DELETE_NAME = NULL, T.DELETE_TIME = NULL
       WHERE T.WIC IN
             (SELECT A.WIC FROM Com_Msc_Std_Water A WHERE A.MSC = V_ROW.MSC);
      UPDATE Com_Msc_Std_Process_c T
         SET T.VALIDFLAG = '1', T.DELETE_NAME = NULL, T.DELETE_TIME = NULL
       WHERE T.GIC IN (SELECT A.GIC
                         FROM Com_Msc_Std_Process A
                        WHERE A.MSC = V_ROW.MSC);
      UPDATE Com_Msc_Process T
         SET T.VALIDFLAG = '1', T.DELETE_NAME = NULL, T.DELETE_TIME = NULL
       WHERE T.MSC = V_ROW.MSC;
      UPDATE Com_Msc_Station T
         SET T.VALIDFLAG = '1', T.DELETE_NAME = NULL, T.DELETE_TIME = NULL
       WHERE T.MSC = V_ROW.MSC;
      UPDATE Com_Msc_Grade T
         SET T.VALIDFLAG   = '1',
             T.DELETE_NAME = NULL,
             T.DELETE_TIME = SYSDATE
       WHERE T.MSC = V_ROW.MSC;
      UPDATE Com_Msc_Grade_r_Spec T
         SET T.VALIDFLAG = '1', T.DELETE_NAME = NULL, T.DELETE_TIME = NULL
       WHERE T.MSC = V_ROW.MSC;
      UPDATE COM_MSC_R_JG T
         SET T.VALIDFLAG = '1', T.DELETE_NAME = NULL, T.DELETE_TIME = NULL
       WHERE T.MSC = V_ROW.MSC;
      UPDATE COM_MSC_STD_CRAFT T
         SET T.VALIDFLAG = '1', T.DELETE_NAME = NULL, T.DELETE_TIME = NULL
       WHERE T.MSC = V_ROW.MSC;
    END LOOP;
  END IF;
END;
		]]>
	</query>
	
	<query id="CoreProductManage.getBaseStdByPk" desc="通过主键查询标准">
		<![CDATA[
SELECT * FROM COM_BASE_STD T WHERE T.STD_CODE = '#STD_CODE#'
		]]>
	</query>
	
	<query id="CoreProductManage.getBasePscByPk" desc="通过主键查询产品">
		<![CDATA[
SELECT * FROM COM_PSC T WHERE T.PSC = '#PSC#'
		]]>
	</query>
	
	<query id="CoreProductManage.getBaseStdRAlphaByPk" desc="通过主键查询用途码">
		<![CDATA[
SELECT * FROM COM_BASE_STD_ALPHA T WHERE T.ALPHA_CODE = '#ALPHA_CODE#'
		]]>
	</query>
	
	<query id="CoreProductManage.getComBaseStdByStyle" desc="查询标准基础数据">
		<![CDATA[
SELECT T.*, 'False' CHK FROM COM_BASE_STD T WHERE T.STDSTYLE IN (#SQL_STYLES#)
AND T.VALIDFLAG = '1'
		]]>
	</query>
	
	<query id="CoreProductManage.CopyStd" desc="查询标准基础数据">
		<![CDATA[
DECLARE
  P_STD_CODE  com_base_std.Std_Code%TYPE;
  P_PSC       COM_PSC.PSC%TYPE;
  P_PSC_DESC  COM_PSC.PSC_DESC%TYPE;
  P_MSC       COM_MSC.msc%TYPE;
  P_USE_CODE  COM_MSC.USE_CODE%TYPE;
  P_USE_DESC  COM_MSC.USE_DESC%TYPE;
  p_cic       com_msc_std_cic.cic%type;
  p_pic       com_msc_std_pic.pic%type;
  p_sic       com_msc_std_spec.sic%type;
  p_dic       com_msc_std_detection.dic%type;
  p_wic       com_msc_std_water.wic%type;
  p_gic       com_msc_std_process.gic%type;
  p_msc_pline com_msc_backlog.msc_pline%type;
  p_key_jg    com_msc_r_jg.key_jg%type;

BEGIN
  SELECT 'STD' || LPAD(SUBSTR(MAX(T.STD_CODE), 4) + 1, 7, '0')
    into P_STD_CODE
    FROM COM_BASE_STD T;
  --新增标准
  insert into com_base_std
    (std_code,
     std_name,
     stdstyle,
     std_note,
     std_style,
     std_style_name,
     std_version,
     department_code,
     department_desc,
     unit_code,
     unit_desc,
     create_name,
     create_time,
     update_name,
     update_time,
     delete_name,
     delete_time,
     validflag,
     memo,
     process_code,
     process_desc,
     std_code_old,
     accept_bid,
     purchase_std)
    (select P_STD_CODE,
            {1},
            stdstyle,
            std_note,
            std_style,
            std_style_name,
            std_version,
            department_code,
            department_desc,
            unit_code,
            unit_desc,
            create_name,
            create_time,
            update_name,
            update_time,
            delete_name,
            delete_time,
            validflag,
            '',
            process_code,
            process_desc,
            std_code_old,
            accept_bid,
            purchase_std
       from com_base_std
      WHERE STD_CODE = {0});
  --新增附加要求
  insert into com_base_additional
    (std_code,
     std_name,
     ask_itme,
     ask_itme_desc,
     ask_sub_itme,
     create_name,
     create_time,
     update_name,
     update_time,
     delete_name,
     delete_time,
     validflag,
     memo,
     ask_sub_itme_desc,
     ask_sub_itme_val,
     ask_sub_itme_val_desc,
     pic,
     stdflag)
    (select P_STD_CODE,
            {1},
            ask_itme,
            ask_itme_desc,
            ask_sub_itme,
            create_name,
            create_time,
            update_name,
            update_time,
            delete_name,
            delete_time,
            validflag,
            memo,
            ask_sub_itme_desc,
            ask_sub_itme_val,
            ask_sub_itme_val_desc,
            pic,
            stdflag
       from com_base_additional
      WHERE STD_CODE = {0}
        and validflag = '1');

  --新增用途码
  FOR USE IN (SELECT *
                FROM com_base_std_alpha t
               where t.std_code = {0}
                 and t.validflag = '1'
               ORDER BY T.ALPHA_CODE) loop
    SELECT P_STD_CODE || LPAD(NVL(SUBSTR(MAX(T.ALPHA_CODE), 11) + 1, '0'), 3, '0')
      INTO P_USE_CODE
      FROM COM_BASE_STD_ALPHA T
     WHERE T.STD_CODE = P_STD_CODE;
  
    insert into com_base_std_alpha
      (alpha_code,
       alpha_name,
       STD_CODE,
       STD_NOTE,
       std_style,
       std_style_name,
       std_version,
       department_code,
       department_desc,
       unit_code,
       unit_desc,
       create_name,
       create_time,
       update_name,
       update_time,
       delete_name,
       delete_time,
       validflag,
       memo,
       alpha_code_old)
      (select P_USE_CODE,
              alpha_name,
              P_STD_CODE,
              {1},
              std_style,
              std_style_name,
              std_version,
              department_code,
              department_desc,
              unit_code,
              unit_desc,
              create_name,
              create_time,
              update_name,
              update_time,
              delete_name,
              delete_time,
              validflag,
              memo,
              alpha_code_old
         from com_base_std_alpha
        where alpha_code = use.alpha_code);
  
    --用途码向下的客户
    insert into com_base_std_r_cust
      (std_code,
       std_name,
       cust_code,
       cust_name,
       create_name,
       create_time,
       update_name,
       update_time,
       delete_name,
       delete_time,
       validflag,
       memo,
       std_code_old,
       cust_code_old)
      (select P_USE_CODE,
              std_name,
              cust_code,
              cust_name,
              create_name,
              create_time,
              update_name,
              update_time,
              delete_name,
              delete_time,
              validflag,
              memo,
              std_code_old,
              cust_code_old
         from com_base_std_r_cust
        WHERE STD_CODE = USE.alpha_code
          and validflag = '1');
  
  end loop; --用途码

  --标准适用规格
  insert into com_base_std_r_spec
    (std_code,
     std_name,
     min_h,
     max_h,
     min_d,
     max_d,
     create_name,
     create_time,
     update_name,
     update_time,
     delete_name,
     delete_time,
     validflag,
     memo,
     msc_style,
     spec_code,
     spec_name)
    (select P_STD_CODE,
            {1},
            min_h,
            max_h,
            min_d,
            max_d,
            create_name,
            create_time,
            update_name,
            update_time,
            delete_name,
            delete_time,
            validflag,
            memo,
            msc_style,
            spec_code,
            spec_name
       from com_base_std_r_spec
      where validflag = '1'
      and std_code = {0});

  --产品标准
  FOR psc in (select * from com_psc t where t.std_code = {0} and t.validflag = '1' ORDER BY T.PSC) loop
    SELECT 'PSC' || LPAD(SUBSTR(MAX(T.PSC), 4) + 1, 7, '0')
      into p_psc
      FROM COM_PSC T;
    P_PSC_DESC := PSC.PRODUCNAME;
    IF PSC.STD_STYLE_DESC IS NOT NULL THEN
      P_PSC_DESC := P_PSC_DESC || ',' || PSC.STD_STYLE_DESC;
    END IF;
    P_PSC_DESC := P_PSC_DESC || ',' || PSC.STEELNAME || ',' || {1};
    insert into com_psc
      (psc,
       psc_desc,
       produccode,
       producname,
       std_code,
       std_name,
       steelcode,
       steelname,
       std_style,
       std_style_desc,
       new_proc_code,
       new_proc_desc,
       department_code,
       department_desc,
       unit_code,
       autojudge,
       unit_desc,
       create_name,
       create_time,
       update_name,
       update_time,
       delete_name,
       delete_time,
       validflag,
       memo,
       psc_old,
       produc_head,
       produc_type,
       produc_style,
       produc_desc,
       compression_ratio)
      (select p_psc,
              P_PSC_DESC,
              produccode,
              producname,
              p_std_code,
              {1},
              steelcode,
              steelname,
              std_style,
              std_style_desc,
              new_proc_code,
              new_proc_desc,
              department_code,
              department_desc,
              unit_code,
              autojudge,
              unit_desc,
              create_name,
              create_time,
              update_name,
              update_time,
              delete_name,
              delete_time,
              validflag,
              memo,
              psc_old,
              produc_head,
              produc_type,
              produc_style,
              produc_desc,
              compression_ratio
         from com_psc
        where psc = psc.psc);
  
    --产品标准与冶金规范关系表
    for PRM in (select B.MSC, B.USE_CODE, B.USE_DESC
                  from com_psc_r_msc a, COM_MSC B
                 where a.psc = psc.psc
                 AND A.MSC = B.MSC
                 AND B.VALIDFLAG <> 'D'
                 order by a.msc) loop
      SELECT 'MSC' || SUBSTR(P_PSC, 4) ||
             LPAD(NVL(SUBSTR(MAX(T.MSC), 11) + 1, 0), 3, '0')
        into P_MSC
        FROM COM_PSC_R_MSC T
       WHERE T.PSC = P_PSC;
    
      P_USE_CODE := P_STD_CODE || SUBSTR(PRM.USE_CODE, 11);
    
      insert into com_psc_r_msc
        (psc,
         psc_desc,
         use_code,
         use_desc,
         msc,
         msc_desc,
         create_name,
         create_time,
         update_name,
         update_time,
         delete_name,
         delete_time,
         validflag,
         memo,
         psc_old,
         use_code_old,
         msc_old,
         cust_alpha_no)
        (select P_psc,
                P_PSC_DESC,
                P_USE_CODE,
                use_desc,
                P_msc,
                P_PSC_DESC,
                create_name,
                create_time,
                update_name,
                update_time,
                delete_name,
                delete_time,
                validflag,
                memo,
                psc_old,
                use_code_old,
                msc_old,
                cust_alpha_no
           from com_psc_r_msc
          WHERE MSC = PRM.MSC);
    
      --冶金规范
      insert into com_msc
        (msc,
         msc_desc,
         use_code,
         use_desc,
         department_code,
         department_desc,
         unit_code,
         unit_desc,
         msc_style,
         user_count,
         produccode,
         producname,
         std_code,
         std_name,
         steelcode,
         steelname,
         std_style,
         std_style_desc,
         new_proc_code,
         new_proc_desc,
         allow_nk,
         msc_seq,
         msc_desc_seq,
         create_name,
         create_time,
         update_name,
         update_time,
         delete_name,
         delete_time,
         validflag,
         memo,
         produc_head,
         file_jpeg,
         unit_code_process,
         unit_desc_process,
         msc_old,
         use_code_old,
         remark,
         audit_name,
         audit_time,
         validflag_nk,
         audit_name_nk,
         audit_time_nk,
         remark_nk)
        (select P_MSC,
                P_PSC_DESC,
                P_USE_CODE,
                use_desc,
                department_code,
                department_desc,
                unit_code,
                unit_desc,
                msc_style,
                user_count,
                produccode,
                producname,
                P_STD_CODE,
                {1},
                steelcode,
                steelname,
                std_style,
                std_style_desc,
                new_proc_code,
                new_proc_desc,
                allow_nk,
                msc_seq,
                msc_desc_seq,
                create_name,
                create_time,
                update_name,
                update_time,
                delete_name,
                delete_time,
                validflag,
                memo,
                produc_head,
                file_jpeg,
                unit_code_process,
                unit_desc_process,
                msc_old,
                use_code_old,
                remark,
                audit_name,
                audit_time,
                validflag_nk,
                audit_name_nk,
                audit_time_nk,
                remark_nk
           from com_msc
          where PRM.msc = msc);
    
      --成分标准
      FOR CIC IN (SELECT *
                    FROM COM_MSC_STD_CIC T
                   WHERE T.MSC = PRM.msc
                     AND T.VALIDFLAG <> '0'
                   order by t.cic) LOOP
        SELECT 'CICG' || LPAD(SUBSTR(MAX(T.CIC), 5) + 1, 6, '0')
          into p_cic
          FROM com_msc_std_cic T where T.STDSTYLE IN ('G', 'X');
        insert into com_msc_std_cic
          (cic,
           psc,
           msc,
           stdstyle,
           std_code_nk,
           std_name_nk,
           process_code,
           process_desc,
           gradecode,
           gradename,
           std_code,
           std_name,
           create_name,
           create_time,
           update_name,
           update_time,
           delete_name,
           delete_time,
           validflag,
           memo,
           model_code,
           model_desc,
           produc_head,
           code_jg,
           steelcode_nk,
           steelname_nk,
           model_code_nk,
           model_desc_nk,
           produccode_nk,
           producname_nk,
           smelting_cnt,
           product_cnt)
          (select p_cic,
                  P_psc,
                  P_msc,
                  stdstyle,
                  std_code_nk,
                  std_name_nk,
                  process_code,
                  process_desc,
                  gradecode,
                  gradename,
                  std_code,
                  std_name,
                  create_name,
                  create_time,
                  update_name,
                  update_time,
                  delete_name,
                  delete_time,
                  validflag,
                  memo,
                  model_code,
                  model_desc,
                  produc_head,
                  code_jg,
                  steelcode_nk,
                  steelname_nk,
                  model_code_nk,
                  model_desc_nk,
                  produccode_nk,
                  producname_nk,
                  smelting_cnt,
                  product_cnt
             from com_msc_std_cic
            where cic = cic.cic);
        --成分子表
        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,
           update_name,
           update_time,
           delete_name,
           delete_time,
           validflag,
           rep_code,
           rep_name,
           rep_min_sign,
           rep_min,
           rep_max_sign,
           rep_max,
           rep_val)
          (select p_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,
                  update_name,
                  update_time,
                  delete_name,
                  delete_time,
                  validflag,
                  rep_code,
                  rep_name,
                  rep_min_sign,
                  rep_min,
                  rep_max_sign,
                  rep_max,
                  rep_val
             from com_msc_std_chem
            where cic = cic.cic
            and validflag = '1');
      END LOOP;
    
      --理化
      for pic in (select *
                    from com_msc_std_pic t
                   where t.msc = PRM.msc
                     and t.validflag <> '0'
                   order by t.pic) loop
        SELECT 'PICG' || LPAD(SUBSTR(MAX(T.PIC), 5) + 1, 6, '0')
          into p_pic
          FROM com_msc_std_Pic T where T.STDSTYLE IN ('G', 'X');
        insert into com_msc_std_pic
          (pic,
           psc,
           stdstyle,
           std_code_nk,
           std_name_nk,
           process_cdoe,
           process_desc,
           create_name,
           create_time,
           update_name,
           update_time,
           delete_name,
           delete_time,
           validflag,
           memo,
           msc,
           model_code,
           model_desc,
           produc_head,
           code_jg,
           steelcode,
           steelname,
           gradecode,
           gradename,
           batch_loca,
           steelcode_nk,
           steelname_nk,
           model_code_nk,
           model_desc_nk,
           produccode_nk,
           producname_nk)
          (select p_pic,
                  p_psc,
                  stdstyle,
                  std_code_nk,
                  std_name_nk,
                  process_cdoe,
                  process_desc,
                  create_name,
                  create_time,
                  update_name,
                  update_time,
                  delete_name,
                  delete_time,
                  validflag,
                  memo,
                  P_msc,
                  model_code,
                  model_desc,
                  produc_head,
                  code_jg,
                  steelcode,
                  steelname,
                  gradecode,
                  gradename,
                  batch_loca,
                  steelcode_nk,
                  steelname_nk,
                  model_code_nk,
                  model_desc_nk,
                  produccode_nk,
                  producname_nk
             from com_msc_std_pic
            where pic = pic.pic);
      
        --理化子记录
        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,
           update_name,
           update_time,
           delete_name,
           delete_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,
           billet_sample,
           FORMULA,
           MIN_F,
           MIN_F_SIGN,
           MAX_F,
           MAX_F_SIGN,
           PHY_MIN_SEQ,
           IS_PRODUCT_CHECK)
          (select p_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,
                  update_name,
                  update_time,
                  delete_name,
                  delete_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,
                  billet_sample,
                  FORMULA,
                  MIN_F,
                  MIN_F_SIGN,
                  MAX_F,
                  MAX_F_SIGN,
                  PHY_MIN_SEQ,
                  IS_PRODUCT_CHECK
             from com_msc_std_phy
            where pic = pic.pic
            and validflag = '1');
      
      end loop;
    
      --公差
      for sic in (select *
                    from com_msc_std_spec t
                   where t.msc = PRM.msc
                     and t.validflag <> '0'
                   order by t.sic) loop
        SELECT 'SICG' || LPAD(SUBSTR(MAX(T.SIC), 5) + 1, 6, '0')
          into p_Sic
          FROM com_msc_std_SPEC T where T.STDSTYLE IN ('G', 'X');
        insert into com_msc_std_spec
          (sic,
           psc,
           msc,
           stdstyle,
           std_code,
           std_name,
           process_code,
           process_desc,
           model_code,
           model_desc,
           stdmemo,
           create_name,
           create_time,
           update_name,
           update_time,
           delete_name,
           delete_time,
           validflag,
           produc_head,
           code_jg,
           special_path,
           steelcode_nk,
           steelname_nk,
           model_code_nk,
           model_desc_nk,
           produccode_nk,
           producname_nk)
          (select P_SIC,
                  P_psc,
                  P_msc,
                  stdstyle,
                  std_code,
                  std_name,
                  process_code,
                  process_desc,
                  model_code,
                  model_desc,
                  stdmemo,
                  create_name,
                  create_time,
                  update_name,
                  update_time,
                  delete_name,
                  delete_time,
                  validflag,
                  produc_head,
                  code_jg,
                  special_path,
                  steelcode_nk,
                  steelname_nk,
                  model_code_nk,
                  model_desc_nk,
                  produccode_nk,
                  producname_nk
             from com_msc_std_spec
            WHERE SIC = SIC.SIC);
      
        --公差子表
        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,
           update_name,
           update_time,
           delete_name,
           delete_time,
           validflag,
           group_seq)
          (select P_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,
                  update_name,
                  update_time,
                  delete_name,
                  delete_time,
                  validflag,
                  group_seq
             from com_msc_std_spec_c
            where sic = sic.sic
            and validflag = '1');
      
      end loop;
    
      --探伤
      for dic in (select *
                    from com_msc_std_detection t
                   where t.msc = PRM.msc
                     and t.validflag <> '0'
                   order by t.dic) loop
        SELECT 'DICG' || LPAD(SUBSTR(MAX(T.DIC), 5) + 1, 6, '0')
          into p_Dic
          FROM com_msc_std_detection T where T.STDSTYLE IN ('G', 'X');
        insert into com_msc_std_detection
          (dic,
           psc,
           msc,
           stdstyle,
           process_code,
           process_desc,
           std_code_nk,
           std_name_nk,
           model_code,
           model_desc,
           create_name,
           create_time,
           update_name,
           update_time,
           delete_name,
           delete_time,
           validflag,
           memo,
           produc_head,
           code_jg,
           steelcode_nk,
           steelname_nk,
           model_code_nk,
           model_desc_nk,
           produccode_nk,
           producname_nk,
           std_code_s_nk,
           std_name_s_nk,
           std_style_s_nk,
           std_style_desc_s_nk)
          (select p_Dic,
                  P_psc,
                  P_msc,
                  stdstyle,
                  process_code,
                  process_desc,
                  std_code_nk,
                  std_name_nk,
                  model_code,
                  model_desc,
                  create_name,
                  create_time,
                  update_name,
                  update_time,
                  delete_name,
                  delete_time,
                  validflag,
                  memo,
                  produc_head,
                  code_jg,
                  steelcode_nk,
                  steelname_nk,
                  model_code_nk,
                  model_desc_nk,
                  produccode_nk,
                  producname_nk,
                  std_code_s_nk,
                  std_name_s_nk,
                  std_style_s_nk,
                  std_style_desc_s_nk
             from com_msc_std_detection
            where dic = dic.dic);
      
        --探伤子表
        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,
           update_name,
           update_time,
           delete_name,
           delete_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_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,
                  update_name,
                  update_time,
                  delete_name,
                  delete_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
             from com_msc_std_detection_c
             where dic = dic.dic
             and validflag = '1');
      
      end loop;
    
      --水压
      for wic in (select *
                    from com_msc_std_water t
                   where t.msc = PRM.msc
                     and t.validflag <> '0'
                   order by t.wic) loop
        SELECT 'WICG' || LPAD(SUBSTR(MAX(T.WIC), 5) + 1, 6, '0')
          into p_Wic
          FROM com_msc_std_WATER T where T.STDSTYLE IN ('G', 'X');
        insert into com_msc_std_water
          (wic,
           psc,
           stdstyle,
           process_cdoe,
           process_desc,
           std_code_nk,
           std_name_nk,
           min_d,
           max_d,
           min_h,
           max_h,
           spec_jg,
           spec_jg_desc,
           model_code,
           model_desc,
           create_name,
           create_time,
           update_name,
           update_time,
           delete_name,
           delete_time,
           validflag,
           memo,
           msc,
           produc_head,
           code_jg,
           min_d_sign,
           max_d_sign,
           min_h_sign,
           max_h_sign,
           steelcode_nk,
           steelname_nk,
           model_code_nk,
           model_desc_nk,
           produccode_nk,
           producname_nk)
          (select p_Wic,
                  P_psc,
                  stdstyle,
                  process_cdoe,
                  process_desc,
                  std_code_nk,
                  std_name_nk,
                  min_d,
                  max_d,
                  min_h,
                  max_h,
                  spec_jg,
                  spec_jg_desc,
                  model_code,
                  model_desc,
                  create_name,
                  create_time,
                  update_name,
                  update_time,
                  delete_name,
                  delete_time,
                  validflag,
                  memo,
                  P_msc,
                  produc_head,
                  code_jg,
                  min_d_sign,
                  max_d_sign,
                  min_h_sign,
                  max_h_sign,
                  steelcode_nk,
                  steelname_nk,
                  model_code_nk,
                  model_desc_nk,
                  produccode_nk,
                  producname_nk
             from com_msc_std_water
            where wic = wic.wic);
      
        --水压子表
        insert into com_msc_std_water_c
          (wic,
           xh,
           pressure_y,
           pressure,
           formula,
           save_time,
           create_name,
           create_time,
           update_name,
           update_time,
           delete_name,
           delete_time,
           validflag,
           memo,
           get_maxvalue,
           get_minvalue,
           ROUND_RULE,
           OUTPUT_STYLE,
           ZBS_OUTPUT_STYLE)
          (select p_Wic,
                  xh,
                  pressure_y,
                  pressure,
                  formula,
                  save_time,
                  create_name,
                  create_time,
                  update_name,
                  update_time,
                  delete_name,
                  delete_time,
                  validflag,
                  memo,
                  get_maxvalue,
                  get_minvalue,
                  ROUND_RULE,
                  OUTPUT_STYLE,
                  ZBS_OUTPUT_STYLE
             from com_msc_std_water_c
            where wic = wic.wic
            and validflag = '1');
      
      end loop;
    
      --加工
      for gic in (select *
                    from com_msc_std_process t
                   where t.msc = PRM.msc
                     and t.validflag <> '0'
                   order by t.gic) loop
        SELECT 'GICG' || LPAD(SUBSTR(MAX(T.GIC), 5) + 1, 6, '0')
          into p_Gic
          FROM com_msc_std_process T where T.STDSTYLE IN ('G', 'X');
      
        insert into com_msc_std_process
          (gic,
           psc,
           msc,
           stdstyle,
           process_cdoe,
           process_desc,
           std_code_nk,
           std_name_nk,
           model_code,
           model_desc,
           create_name,
           create_time,
           update_name,
           update_time,
           delete_name,
           delete_time,
           validflag,
           memo,
           produc_head,
           code_jg,
           steelcode_nk,
           steelname_nk,
           model_code_nk,
           model_desc_nk,
           produccode_nk,
           producname_nk)
          (select p_Gic,
                  P_psc,
                  P_msc,
                  stdstyle,
                  process_cdoe,
                  process_desc,
                  std_code_nk,
                  std_name_nk,
                  model_code,
                  model_desc,
                  create_name,
                  create_time,
                  update_name,
                  update_time,
                  delete_name,
                  delete_time,
                  validflag,
                  memo,
                  produc_head,
                  code_jg,
                  steelcode_nk,
                  steelname_nk,
                  model_code_nk,
                  model_desc_nk,
                  produccode_nk,
                  producname_nk
             from com_msc_std_process
            where gic = gic.gic);
      
        --加工子表
        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,
           update_name,
           update_time,
           delete_name,
           delete_time,
           validflag,
           memo)
          (select p_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,
                  update_name,
                  update_time,
                  delete_name,
                  delete_time,
                  validflag,
                  memo
             from com_msc_std_process_c
            where gic = gic.gic
            and validflag = '1');
      
      end loop;
    
      --制程
      for pline in (select *
                      from com_msc_backlog t
                     where t.msc = PRM.msc
                       and t.validflag <> '0'
                     order by t.msc_pline) loop
        select lpad(nvl(max(t.msc_pline), '0') + 1, 6, '0')
          into p_msc_pline from com_msc_backlog t where t.msc = P_MSC;
        insert into com_msc_backlog
          (msc,
           msc_pline,
           whole_backlog,
           whole_backlog_desc,
           create_name,
           create_time,
           update_name,
           update_time,
           delete_name,
           delete_time,
           validflag,
           memo,
           msc_old,
           msc_pline_old,
           process_no,
           validflag_nk,
           process_name,
           craft_path,
           auto_craft)
          (select p_msc,
                  p_msc_pline,
                  whole_backlog,
                  whole_backlog_desc,
                  create_name,
                  create_time,
                  update_name,
                  update_time,
                  delete_name,
                  delete_time,
                  validflag,
                  memo,
                  msc_old,
                  msc_pline_old,
                  process_no,
                  validflag_nk,
                  process_name,
                  craft_path,
                  auto_craft
             from com_msc_backlog
            where msc = PRM.msc
              and msc_pline = pline.msc_pline);
      
        --工序
        for process in (select *
                          from com_msc_process t
                         where t.msc = PRM.msc
                           and t.msc_pline = pline.msc_pline
                           and t.validflag = '1'
                         order by t.process_code) loop
          insert into com_msc_process
            (index_seq,
             msc,
             msc_pline,
             backlog_seq,
             process_code,
             process_desc,
             minute_product,
             minute_waite,
             create_name,
             create_time,
             update_name,
             update_time,
             delete_name,
             delete_time,
             validflag,
             memo,
             process_seq,
             cic,
             pic,
             sic,
             dic,
             wic,
             process_code_c,
             process_desc_c,
             gic,
             msc_pline_old,
             minute_product_out,
             minute_waite_out,
             batch_waite,
             batch_waite_out)
            (select index_seq,
                    p_msc,
                    p_msc_pline,
                    backlog_seq,
                    process_code,
                    process_desc,
                    minute_product,
                    minute_waite,
                    create_name,
                    create_time,
                    update_name,
                    update_time,
                    delete_name,
                    delete_time,
                    validflag,
                    memo,
                    process_seq,
                    cic,
                    pic,
                    sic,
                    dic,
                    wic,
                    process_code_c,
                    process_desc_c,
                    gic,
                    msc_pline_old,
                    minute_product_out,
                    minute_waite_out,
                    batch_waite,
                    batch_waite_out
               from com_msc_process
              where msc = PRM.msc
                and msc_pline = pline.msc_pline
                and process_code = process.process_code);
        
          --工序点
          insert into com_msc_station
            (index_seq,
             msc,
             msc_pline,
             backlog_seq,
             process_code,
             process_desc,
             station_code,
             station_desc,
             station_type,
             station_id,
             cost,
             choose,
             return_result,
             send_checkplan,
             group_seq,
             create_name,
             create_time,
             update_name,
             update_time,
             delete_name,
             delete_time,
             validflag,
             memo,
             process_seq,
             process_code_c,
             process_desc_c)
            (select index_seq,
                    P_MSC,
                    p_msc_pline,
                    backlog_seq,
                    process_code,
                    process_desc,
                    station_code,
                    station_desc,
                    station_type,
                    station_id,
                    cost,
                    choose,
                    return_result,
                    send_checkplan,
                    group_seq,
                    create_name,
                    create_time,
                    update_name,
                    update_time,
                    delete_name,
                    delete_time,
                    validflag,
                    memo,
                    process_seq,
                    process_code_c,
                    process_desc_c
               from com_msc_station
              where msc = PRM.msc
                and msc_pline = pline.msc_pline
                and process_code = process.process_code
                and validflag = '1');
        
          --工艺参数
          for craft in (select *
                          from com_msc_std_craft t
                         where t.msc = PRM.msc
                           and t.msc_pline = pline.msc_pline
                           and t.process_cdoe = process.process_code
                           and validflag = '1'
                         order by t.craftitem_cdoe) loop
            insert into com_msc_std_craft
              (msc,
               msc_pline,
               backlog_seq,
               process_cdoe,
               process_desc,
               process_cdoe_c,
               process_desc_c,
               station_code,
               station_desc,
               min_d,
               max_d,
               min_h,
               max_h,
               model_code,
               model_desc,
               spec_jg,
               spec_jg_desc,
               grade_seq,
               craftitem_cdoe,
               craftitem_desc,
               allow_count,
               min_value,
               max_value,
               craftitem_cdoe1,
               craftitem_desc1,
               min_value1,
               max_value1,
               craftitem_cdoe2,
               craftitem_desc2,
               min_value2,
               max_value2,
               craftitem_cdoe3,
               craftitem_desc3,
               min_value3,
               max_value3,
               craftitem_cdoe4,
               craftitem_desc4,
               min_value4,
               max_value4,
               create_name,
               create_time,
               update_name,
               update_time,
               delete_name,
               delete_time,
               validflag,
               memo)
              (select P_MSC,
                      p_msc_pline,
                      backlog_seq,
                      process_cdoe,
                      process_desc,
                      process_cdoe_c,
                      process_desc_c,
                      station_code,
                      station_desc,
                      min_d,
                      max_d,
                      min_h,
                      max_h,
                      model_code,
                      model_desc,
                      spec_jg,
                      spec_jg_desc,
                      grade_seq,
                      craftitem_cdoe,
                      craftitem_desc,
                      allow_count,
                      min_value,
                      max_value,
                      craftitem_cdoe1,
                      craftitem_desc1,
                      min_value1,
                      max_value1,
                      craftitem_cdoe2,
                      craftitem_desc2,
                      min_value2,
                      max_value2,
                      craftitem_cdoe3,
                      craftitem_desc3,
                      min_value3,
                      max_value3,
                      craftitem_cdoe4,
                      craftitem_desc4,
                      min_value4,
                      max_value4,
                      create_name,
                      create_time,
                      update_name,
                      update_time,
                      delete_name,
                      delete_time,
                      validflag,
                      memo
                 from com_msc_std_craft
                where msc = PRM.msc
                  and msc_pline = pline.msc_pline
                  and STATION_CODE = craft.station_code
                  and CRAFTITEM_CDOE = craft.CRAFTITEM_CDOE
                  and ALLOW_COUNT = craft.ALLOW_COUNT);
          
          end loop;
        
        end loop; --工序
      
        --钢种
        for grade in (select *
                        from com_msc_grade t
                       where t.msc = PRM.msc
                         and t.msc_pline = pline.msc_pline
                         and t.validflag = '1'
                       order by t.gradecode) loop
          insert into com_msc_grade
            (msc,
             msc_pline,
             cic,
             gradecode,
             gradename,
             assortment_code,
             assortment_name,
             std_code,
             std_name,
             create_name,
             create_time,
             update_name,
             update_time,
             delete_name,
             delete_time,
             validflag,
             memo,
             gradecode_old,
             manage_category,
             priority)
            (select P_msc,
                    P_msc_pline,
                    cic,
                    gradecode,
                    gradename,
                    assortment_code,
                    assortment_name,
                    p_std_code,
                    {1},
                    create_name,
                    create_time,
                    update_name,
                    update_time,
                    delete_name,
                    delete_time,
                    validflag,
                    memo,
                    gradecode_old,
                    manage_category,
                    priority
               from com_msc_grade
              where msc = PRM.msc
                and msc_pline = pline.msc_pline
                and GRADECODE = grade.gradecode);
        
          --钢种适用规格
          insert into com_msc_grade_r_spec
            (msc,
             msc_pline,
             gradecode,
             gradename,
             height_min,
             dimater_min,
             dimater_max,
             height_miax,
             create_name,
             create_time,
             update_name,
             update_time,
             delete_name,
             delete_time,
             validflag,
             memo)
            (select P_msc,
                    P_msc_pline,
                    gradecode,
                    gradename,
                    height_min,
                    dimater_min,
                    dimater_max,
                    height_miax,
                    create_name,
                    create_time,
                    update_name,
                    update_time,
                    delete_name,
                    delete_time,
                    validflag,
                    memo
               from com_msc_grade_r_spec
              where msc = PRM.msc
                and msc_pline = pline.msc_pline
                and GRADECODE = grade.gradecode);
        
        end loop; --钢种
      end loop; --制程
    
      --接箍
      for JG IN (SELECT *
                   FROM COM_MSC_R_JG T
                  WHERE T.MSC = PRM.msc
                    and t.validflag = '1'
                    AND T.STOCK_STYLE = 'A'
                  order by t.code_jg) loop
        P_KEY_JG := sys_guid();
        insert into com_msc_r_jg
          (msc,
           msc_desc,
           code_jg,
           stock_style,
           create_name,
           create_time,
           update_name,
           update_time,
           delete_name,
           delete_time,
           validflag,
           memo,
           group_num,
           demand_detection,
           demand_bonderizing,
           demand_copper,
           demand_blast,
           produccode,
           producname,
           steelcode,
           steelname,
           min_h,
           max_h,
           min_d,
           max_d,
           cust_alpha_no,
           key_jg,
           order_special_desc,
           alpha_code)
          (select P_msc,
                  p_psc_desc,
                  code_jg,
                  stock_style,
                  create_name,
                  create_time,
                  update_name,
                  update_time,
                  delete_name,
                  delete_time,
                  validflag,
                  memo,
                  group_num,
                  demand_detection,
                  demand_bonderizing,
                  demand_copper,
                  demand_blast,
                  produccode,
                  producname,
                  steelcode,
                  steelname,
                  min_h,
                  max_h,
                  min_d,
                  max_d,
                  cust_alpha_no,
                  P_KEY_JG,
                  order_special_desc,
                  alpha_code
             from com_msc_r_jg
            where KEY_JG = JG.KEY_JG);
      
        --接箍料
        insert into com_msc_jg_r_bl
          (code_jg,
           psc_bl,
           create_name,
           create_time,
           update_name,
           update_time,
           delete_name,
           delete_time,
           validflag,
           memo,
           key_jg,
           cust_alpha_no,
           order_special_desc,
           alpha_code)
          (select code_jg,
                  psc_bl,
                  create_name,
                  create_time,
                  update_name,
                  update_time,
                  delete_name,
                  delete_time,
                  validflag,
                  memo,
                  P_KEY_JG,
                  cust_alpha_no,
                  order_special_desc,
                  alpha_code
             from com_msc_jg_r_bl
            WHERE key_jg = jg.key_jg);
      
        --接箍制程
        select lpad(nvl(max(t.msc_pline), '0') + 1, 6, '0')
          into p_msc_pline from com_msc_backlog t
         where t.msc = jg.key_jg;
        FOR JG_PLINE IN (SELECT *
                           FROM com_msc_backlog T
                          WHERE T.Msc = jg.key_jg
                            and validflag = '1'
                          order by t.msc_pline) loop
          insert into com_msc_backlog
            (msc,
             msc_pline,
             whole_backlog,
             whole_backlog_desc,
             create_name,
             create_time,
             update_name,
             update_time,
             delete_name,
             delete_time,
             validflag,
             memo,
             msc_old,
             msc_pline_old,
             process_no,
             validflag_nk,
             process_name,
             craft_path,
             auto_craft)
            (select p_key_jg,
                    p_msc_pline,
                    whole_backlog,
                    whole_backlog_desc,
                    create_name,
                    create_time,
                    update_name,
                    update_time,
                    delete_name,
                    delete_time,
                    validflag,
                    memo,
                    msc_old,
                    msc_pline_old,
                    process_no,
                    validflag_nk,
                    process_name,
                    craft_path,
                    auto_craft
               from com_msc_backlog
              where msc = jg.key_jg
                and validflag = '1');
        
          --接箍工序
          for jg_process in (select *
                               from com_msc_process t
                              where t.msc = jg.key_jg
                                and msc_pline = jg_pline.msc_pline
                                and validflag = '1'
                              order by t.process_code) loop
            insert into com_msc_process
              (index_seq,
               msc,
               msc_pline,
               backlog_seq,
               process_code,
               process_desc,
               minute_product,
               minute_waite,
               create_name,
               create_time,
               update_name,
               update_time,
               delete_name,
               delete_time,
               validflag,
               memo,
               process_seq,
               cic,
               pic,
               sic,
               dic,
               wic,
               process_code_c,
               process_desc_c,
               gic,
               msc_pline_old,
               minute_product_out,
               minute_waite_out,
               batch_waite,
               batch_waite_out)
              (select index_seq,
                      p_key_jg,
                      p_msc_pline,
                      backlog_seq,
                      process_code,
                      process_desc,
                      minute_product,
                      minute_waite,
                      create_name,
                      create_time,
                      update_name,
                      update_time,
                      delete_name,
                      delete_time,
                      validflag,
                      memo,
                      process_seq,
                      cic,
                      pic,
                      sic,
                      dic,
                      wic,
                      process_code_c,
                      process_desc_c,
                      gic,
                      msc_pline_old,
                      minute_product_out,
                      minute_waite_out,
                      batch_waite,
                      batch_waite_out
                 from com_msc_process
                where msc = jg.key_jg
                  and msc_pline = jg_pline.msc_pline
                  and process_code = jg_process.process_code);
          
            --接箍工序点
            insert into com_msc_station
              (index_seq,
               msc,
               msc_pline,
               backlog_seq,
               process_code,
               process_desc,
               station_code,
               station_desc,
               station_type,
               station_id,
               cost,
               choose,
               return_result,
               send_checkplan,
               group_seq,
               create_name,
               create_time,
               update_name,
               update_time,
               delete_name,
               delete_time,
               validflag,
               memo,
               process_seq,
               process_code_c,
               process_desc_c)
              (select index_seq,
                      p_key_jg,
                      p_msc_pline,
                      backlog_seq,
                      process_code,
                      process_desc,
                      station_code,
                      station_desc,
                      station_type,
                      station_id,
                      cost,
                      choose,
                      return_result,
                      send_checkplan,
                      group_seq,
                      create_name,
                      create_time,
                      update_name,
                      update_time,
                      delete_name,
                      delete_time,
                      validflag,
                      memo,
                      process_seq,
                      process_code_c,
                      process_desc_c
                 from com_msc_station
                where msc = jg.key_jg
                  and msc_pline = jg_pline.msc_pline
                  and process_code = jg_process.process_code
                  and validflag = '1');
          
            --工艺参数
            insert into com_msc_std_craft
              (msc,
               msc_pline,
               backlog_seq,
               process_cdoe,
               process_desc,
               process_cdoe_c,
               process_desc_c,
               station_code,
               station_desc,
               min_d,
               max_d,
               min_h,
               max_h,
               model_code,
               model_desc,
               spec_jg,
               spec_jg_desc,
               grade_seq,
               craftitem_cdoe,
               craftitem_desc,
               allow_count,
               min_value,
               max_value,
               craftitem_cdoe1,
               craftitem_desc1,
               min_value1,
               max_value1,
               craftitem_cdoe2,
               craftitem_desc2,
               min_value2,
               max_value2,
               craftitem_cdoe3,
               craftitem_desc3,
               min_value3,
               max_value3,
               craftitem_cdoe4,
               craftitem_desc4,
               min_value4,
               max_value4,
               create_name,
               create_time,
               update_name,
               update_time,
               delete_name,
               delete_time,
               validflag,
               memo)
              (select p_key_jg,
                      P_msc_pline,
                      backlog_seq,
                      process_cdoe,
                      process_desc,
                      process_cdoe_c,
                      process_desc_c,
                      station_code,
                      station_desc,
                      min_d,
                      max_d,
                      min_h,
                      max_h,
                      model_code,
                      model_desc,
                      spec_jg,
                      spec_jg_desc,
                      grade_seq,
                      craftitem_cdoe,
                      craftitem_desc,
                      allow_count,
                      min_value,
                      max_value,
                      craftitem_cdoe1,
                      craftitem_desc1,
                      min_value1,
                      max_value1,
                      craftitem_cdoe2,
                      craftitem_desc2,
                      min_value2,
                      max_value2,
                      craftitem_cdoe3,
                      craftitem_desc3,
                      min_value3,
                      max_value3,
                      craftitem_cdoe4,
                      craftitem_desc4,
                      min_value4,
                      max_value4,
                      create_name,
                      create_time,
                      update_name,
                      update_time,
                      delete_name,
                      delete_time,
                      validflag,
                      memo
                 from com_msc_std_craft
                where msc = jg.key_jg
                  and MSC_PLINE = jg_pline.msc_pline
                  and process_cdoe = jg_process.process_code
                  and validflag = '1');
          
          end loop; --接箍工序
        
        end loop; --接箍制程
      
      end loop; --接箍
    
      --备料
      insert into com_msc_r_jg
        (msc,
         msc_desc,
         code_jg,
         stock_style,
         create_name,
         create_time,
         update_name,
         update_time,
         delete_name,
         delete_time,
         validflag,
         memo,
         group_num,
         demand_detection,
         demand_bonderizing,
         demand_copper,
         demand_blast,
         produccode,
         producname,
         steelcode,
         steelname,
         min_h,
         max_h,
         min_d,
         max_d,
         cust_alpha_no,
         key_jg,
         order_special_desc,
         alpha_code)
        (select P_msc,
                P_PSC_DESC,
                code_jg,
                stock_style,
                create_name,
                create_time,
                update_name,
                update_time,
                delete_name,
                delete_time,
                validflag,
                memo,
                group_num,
                demand_detection,
                demand_bonderizing,
                demand_copper,
                demand_blast,
                produccode,
                producname,
                steelcode,
                steelname,
                min_h,
                max_h,
                min_d,
                max_d,
                cust_alpha_no,
                SYS_GUID(),
                order_special_desc,
                alpha_code
           from com_msc_r_jg
          where msc = PRM.msc
            and validflag = '1'
            and STOCK_STYLE = 'B');
    
      --备料适用规格
      insert into com_msc_r_bl_spec
        (msc,
         group_num,
         row_index,
         spec_code,
         spec_name,
         min_h,
         max_h,
         min_d,
         max_d,
         create_name,
         create_time,
         update_name,
         update_time,
         delete_name,
         delete_time, 
         validflag,
         memo)
        (select P_msc,
                group_num,
                row_index,
                spec_code,
                spec_name,
                min_h,
                max_h,
                min_d,
                max_d,
                create_name,
                create_time,
                update_name,
                update_time,
                delete_name,
                delete_time,
                validflag,
                memo
           from com_msc_r_bl_spec
          where msc = PRM.msc
            and VALIDFLAG = '1');
    
    end loop; --冶金规范
  end loop; --产品
END;
		]]>
	</query>
	
	<query id="CoreProductManage.IsExistStdName" desc="是否存在标准名称">
		<![CDATA[
SELECT COUNT(1) FROM COM_BASE_STD T WHERE T.STD_NAME = {0}
		]]>
	</query>
	
	<query id="CoreProductManage.ForbiddenOrder" desc="是否禁用合同录入">
		<![CDATA[
UPDATE COM_BASE_STD T
   SET T.FORBIDDEN_ORDER = {1},
       T.UPDATE_NAME     = {2},
       T.UPDATE_TIME     = SYSDATE
 WHERE T.STD_CODE = {0}
		]]>
	</query>
	
	<query id="CoreProductManage.OrderLineUseCnt" desc="合同使用次数">
		<![CDATA[
SELECT COUNT(1) CNT
  FROM SLM_ORDER_LINE AA
 WHERE AA.ORDER_LN_STATUS < '12020602'
   AND AA.VALIDFLAG = '1'
   AND AA.STD_CODE = {0}
		]]>
	</query>
</queryMap>