<?xml version="1.0" encoding="UTF-8"?>
 
<queryMap desc="备料码基础管理">
    <query id="CoreBaseSample.Init4010" desc="获取取样长度代码、描述">
		<![CDATA[ 
		      SELECT T.BASENAME,T.BASECODE 
		      FROM COM_BASE_INFO T
		      WHERE T.VALIDFLAG='1' 
		      AND T.SORTCODE='4010'
		]]>
	</query>
	<query id="CoreBaseSample.Init4011" desc="获取取样频率代码、描述">
		<![CDATA[ 
		     SELECT T.BASENAME,T.BASECODE 
		      FROM COM_BASE_INFO T
		      WHERE T.VALIDFLAG='1' 
		      AND T.SORTCODE='4011'
		]]>
	</query>
	
	<query id="CoreBaseSample.Init4012" desc="获取取样位置代码、描述">
		<![CDATA[ 
		     SELECT T.BASENAME,T.BASECODE 
		      FROM COM_BASE_INFO T
		      WHERE T.VALIDFLAG='1' 
		      AND T.SORTCODE='4012'
		]]>
	</query>
	
	<query id="CoreBaseSample.GetSIC" desc="获取最大SIC码">
		<![CDATA[ 
		SELECT T.SIC
        FROM 
        (SELECT SIC FROM COM_BASE_SAMPLE WHERE PHY_CODE_MIN=? ORDER BY SIC  DESC ) T
        WHERE ROWNUM='1'
      
		]]>
	</query>
	
	<query id="CoreBaseSample.DELETE" desc="删除">
		<![CDATA[ 
		 UPDATE COM_BASE_SAMPLE
		 SET VALIDFLAG='0',
		 DELETE_NAME=?,
		 DELETE_TIME=SYSDATE
		 WHERE SIC=? AND VALIDFLAG='1'
		]]>
	</query>
	
	<query id="CoreBaseSample.Resume" desc="恢复">
		<![CDATA[ 
		 UPDATE COM_BASE_SAMPLE
		 SET VALIDFLAG='1',
		 DELETE_NAME='',
		 DELETE_TIME=''
		 WHERE SIC=? AND VALIDFLAG='0'
		]]>
	</query>
	
	<query id="CoreBaseSample.QUERY" desc="查询">
		<![CDATA[
SELECT SIC,
       'FALSE' CHK,
       PHY_CODE_MIN,
       PHY_NAME_MIN,
       (SELECT LISTAGG(STD_CODE, ';') WITHIN group(order by STD_CODE)
          FROM COM_BASE_SAMPLE_R_STD A
         WHERE A.SIC = T.SIC) STD_CODE,
       (SELECT LISTAGG(STD_NAME, ';') WITHIN group(order by STD_NAME)
          FROM COM_BASE_SAMPLE_R_STD A
         WHERE A.SIC = T.SIC) STD_NAME,
       LENGTH,
       DESC_LENGTH,
       RATE,
       DESC_RATE,
       DESC_COUNT,
       POSITION,
       DESC_POSITION,
       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,
       SAMPLE_COUNT,
       SAMPLE_STYLE,
       WIDTH,
       MIN_D,
       MIN_D_SIGN,
       MAX_D,
       MAX_D_SIGN,
       MIN_H,
       MIN_H_SIGN,
       MAX_H,
       MAX_H_SIGN,
       (SELECT REPLACE(WM_CONCAT(STEELCODE), ',', ';')
          FROM COM_BASE_SAMPLE_R_STEEL A
         WHERE A.SIC = T.SIC) STEELCODE,
       (SELECT REPLACE(WM_CONCAT(STEELNAME), ',', ';')
          FROM COM_BASE_SAMPLE_R_STEEL A
         WHERE A.SIC = T.SIC) STEELNAME,
       (SELECT REPLACE(WM_CONCAT(A.PRODUCCODE), ',', ';')
          FROM COM_BASE_SAMPLE_R_PRODUCT A
         WHERE A.SIC = T.SIC) PRODUCCODE,
       (SELECT REPLACE(WM_CONCAT(B.PRODUCNAME), ',', ';')
          FROM COM_BASE_SAMPLE_R_PRODUCT A, COM_BASE_PRODUCT B
         WHERE A.SIC = T.SIC
           AND A.PRODUCCODE = B.PRODUCCODE) PRODUCNAME,
       BATCH_CNT,
       BATCH_UNIT,
       T.ATTACH_PERCENT,
       T.ATTACH_COUNT,
       T.TOP_STOVE,
       T.LOOP_VALUE,
       T.SSC_CONDITION,
       T.EXCLUDE_PHY_MIN,
        (SELECT WM_CONCAT(C.PHY_TYPE)
                            FROM COM_BASE_PHY_C C
                           WHERE INSTR(T.EXCLUDE_PHY_MIN, C.PHY_CODE) > 0) EXCLUDE_PHY_MIN_NAME
  FROM COM_BASE_SAMPLE T
 WHERE (? IS NULL OR PHY_CODE_MIN = ?)
   AND (? IS NULL OR PHY_NAME_MIN LIKE '%' || ? || '%')
   AND T.VALIDFLAG IN ('1', ?)
		]]>
	</query>
	
	
	<query id="CoreBaseSample.UPDATE" desc="更新">
		<![CDATA[
        UPDATE COM_BASE_SAMPLE
        SET  
        LENGTH        = '#LENGTH#',
        DESC_LENGTH   = '#DESC_LENGTH#',
        RATE          = '#RATE#',
        DESC_RATE     = '#DESC_RATE#',
        DESC_COUNT    = '#DESC_COUNT#',
        POSITION      = '#POSITION#',
        DESC_POSITION = '#DESC_POSITION#',
        UPDATE_NAME   = '#UPDATE_NAME#',
        UPDATE_TIME   =  SYSDATE,
        MEMO          =  '#MEMO#',
        SAMPLE_COUNT = '#SAMPLE_COUNT#',
        SAMPLE_STYLE = '#SAMPLE_STYLE#',
        WIDTH = '#WIDTH#',
        MIN_D = '#MIN_D#',
        MIN_D_SIGN = '#MIN_D_SIGN#',
        MAX_D = '#MAX_D#',
        MAX_D_SIGN = '#MAX_D_SIGN#',
        MIN_H = '#MIN_H#',
        MIN_H_SIGN = '#MIN_H_SIGN#',
        MAX_H = '#MAX_H#',
        MAX_H_SIGN = '#MAX_H_SIGN#',
        BATCH_CNT = '#BATCH_CNT#',
        BATCH_UNIT = '#BATCH_UNIT#',
        STD_CODE = NULL,
        STD_NAME = NULL,
        ATTACH_PERCENT = '#ATTACH_PERCENT#',
        ATTACH_COUNT = '#ATTACH_COUNT#',
        TOP_STOVE = '#TOP_STOVE#',
        LOOP_VALUE = '#LOOP_VALUE#',
        SSC_CONDITION = '#SSC_CONDITION#',
        EXCLUDE_PHY_MIN = '#EXCLUDE_PHY_MIN#'
        WHERE SIC = '#SIC#'
		]]>
	</query>
	
	
	<query id="CoreBaseSample.ADD" desc="新增">
		<![CDATA[
INSERT INTO COM_BASE_SAMPLE
  (SIC,
   PHY_CODE_MIN,
   PHY_NAME_MIN,
   LENGTH,
   DESC_LENGTH,
   RATE,
   DESC_RATE,
   DESC_COUNT,
   POSITION,
   DESC_POSITION,
   CREATE_NAME,
   CREATE_TIME,
   MEMO,
   SAMPLE_COUNT,
   SAMPLE_STYLE,
   WIDTH,
   MIN_D,
   MIN_D_SIGN,
   MAX_D,
   MAX_D_SIGN,
   MIN_H,
   MIN_H_SIGN,
   MAX_H,
   MAX_H_SIGN,
   BATCH_CNT,
   BATCH_UNIT,
   ATTACH_PERCENT,
   ATTACH_COUNT,
   TOP_STOVE,
   LOOP_VALUE,
   SSC_CONDITION,
   EXCLUDE_PHY_MIN)
VALUES
  ((SELECT '#PHY_CODE_MIN#' ||
          LPAD(NVL(SUBSTR(MAX(T.SIC), 6), 0) + 1, 3, '0')
     FROM COM_BASE_SAMPLE T
    WHERE T.PHY_CODE_MIN = '#PHY_CODE_MIN#'),
   '#PHY_CODE_MIN#',
   '#PHY_NAME_MIN#',
   '#LENGTH#',
   '#DESC_LENGTH#',
   '#RATE#',
   '#DESC_RATE#',
   '#DESC_COUNT#',
   '#POSITION#',
   '#DESC_POSITION#',
   '#CREATE_NAME#',
   SYSDATE,
   '#MEMO#',
   '#SAMPLE_COUNT#',
   '#SAMPLE_STYLE#',
   '#WIDTH#',
   '#MIN_D#',
   '#MIN_D_SIGN#',
   '#MAX_D#',
   '#MAX_D_SIGN#',
   '#MIN_H#',
   '#MIN_H_SIGN#',
   '#MAX_H#',
   '#MAX_H_SIGN#',
   '#BATCH_CNT#',
   '#BATCH_UNIT#',
   '#ATTACH_PERCENT#',
   '#ATTACH_COUNT#',
   '#TOP_STOVE#',
   '#LOOP_VALUE#',
   '#SSC_CONDITION#',
   '#EXCLUDE_PHY_MIN#')
		]]>
	</query>
	 
	<query id="CoreBaseSample.loadPhySmpCnt" desc="新增">
		<![CDATA[
		SELECT T.SAMPLE_COUNT
		  FROM COM_BASE_PHY_B T, COM_BASE_PHY_C A
		 WHERE T.PHY_CODE = A.PHY_TYPE_M
		   AND A.PHY_CODE = ?
		]]>
	</query>
	
	<query id="CoreBaseSample.insertBaseSampleRSteel" desc="新增取样码和钢级对应关系">
		<![CDATA[
INSERT INTO COM_BASE_SAMPLE_R_STEEL
  (SIC, STEELCODE, STEELNAME, CREATE_NAME, CREATE_TIME, VALIDFLAG)
VALUES
  ('#SIC#', '#STEELCODE#', '#STEELNAME#', '#CREATE_NAME#', SYSDATE, '1')
		]]>
	</query>
	
	<query id="CoreBaseSample.insertBaseSampleRStd" desc="新增取样码和标准对应关系">
		<![CDATA[
INSERT INTO COM_BASE_SAMPLE_R_STD
  (SIC, STD_CODE, STD_NAME, CREATE_NAME, CREATE_TIME, VALIDFLAG)
VALUES
  ('#SIC#', '#STD_CODE#', '#STD_NAME#', '#CREATE_NAME#', SYSDATE, '1')
		]]>
	</query>
	
	<query id="CoreBaseSample.insertBaseSampleRProduct" desc="新增取样码和品名对应关系">
		<![CDATA[
INSERT INTO COM_BASE_SAMPLE_R_PRODUCT (SIC, PRODUCCODE) VALUES ({0}, {1})
		]]>
	</query>
	
	<query id="CoreBaseSample.delBaseSampleRSteel" desc="删除取样码和钢级的关系">
		<![CDATA[
DELETE FROM COM_BASE_SAMPLE_R_STEEL WHERE SIC = '#SIC#'
		]]>
	</query>
	
	<query id="CoreBaseSample.delBaseSampleRStd" desc="删除取样码和标准的关系">
		<![CDATA[
DELETE FROM COM_BASE_SAMPLE_R_STD WHERE SIC = '#SIC#'
		]]>
	</query>
	
	<query id="CoreBaseSample.delBaseSampleRProduct" desc="删除取样码和品名的关系">
		<![CDATA[
DELETE FROM COM_BASE_SAMPLE_R_PRODUCT WHERE SIC = {0}
		]]>
	</query>
</queryMap>