<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="成分判定记录表">
	<query id="JdgQcmBcChemResult.insert" desc="新增">
		<![CDATA[
INSERT INTO QCM_BC_CHEM_RESULT(
        CHEM_JUDGE_ID,
        JUDGE_SEQ,
        CHEM_SEQ,
        CHEM_NAME,
        CHEM_VALUE,
        NK_MIN,
        NK_MAX,
        NK_QUALIFIED,
        JF_MIN,
        JF_MAX,
        JF_QUALIFIED,
        UNQUALIFIED_TYPE)
 VALUES( 
        '#CHEM_JUDGE_ID#',
        '#JUDGE_SEQ#',
        '#CHEM_SEQ#',
        '#CHEM_NAME#',
        '#CHEM_VALUE#',
        '#NK_MIN#',
        '#NK_MAX#',
        '#NK_QUALIFIED#',
        '#JF_MIN#',
        '#JF_MAX#',
        '#JF_QUALIFIED#',
        '#UNQUALIFIED_TYPE#')
		]]>
	</query>
	
	<query id="JdgQcmBcChemResult.getJudgeFail" desc="获取判定失败的记录">
		<![CDATA[
SELECT A.LOT_NO,
       A.JUDGE_STOVE_NO,
       A.BATCH_NO,
       A.SAMPLE_ID,
       A.SAMPLE_NO,
       A.PLINE_CODE,
       B.CHEM_NAME,
       C.CHEM_CODE,
       B.JF_QUALIFIED,
       B.NK_QUALIFIED,
       MIN(C.CHEM_TYPE) CHEM_TYPE,
       MIN(C.CHEM_FORMULA) CHEM_FORMULA
  FROM QCM_BC_CHEMJUDGE A, QCM_BC_CHEM_RESULT B, COM_BASE_CHEM C
 WHERE A.SAMPLE_ID = {0}
   AND A.JUDGE_STOVE_NO = {1}
   AND A.BATCH_NO = {2}
   AND A.PROCESS_CDOE = {3}
   AND A.VALIDFLAG = '1'
   AND B.CHEM_JUDGE_ID = A.CHEM_JUDGE_ID
   AND B.JUDGE_SEQ = A.JUDGE_SEQ
   AND B.NK_QUALIFIED IN ('0', '2')
   AND C.CHEM_NAME = B.CHEM_NAME
   AND C.VALIDFLAG = '1'
 GROUP BY A.LOT_NO,
          A.JUDGE_STOVE_NO,
          A.BATCH_NO,
          A.SAMPLE_ID,
          A.SAMPLE_NO,
          A.PLINE_CODE,
          B.CHEM_NAME,
          C.CHEM_CODE,
          B.JF_QUALIFIED,
          B.NK_QUALIFIED
		]]>
	</query>
	
	<query id="JdgQcmBcChemResult.getJudgeFailByChem" desc="获取判定失败的记录">
		<![CDATA[
SELECT A.LOT_NO,
       A.JUDGE_STOVE_NO,
       A.BATCH_NO,
       A.SAMPLE_ID,
       A.SAMPLE_NO,
       A.PLINE_CODE,
       B.CHEM_NAME,
       B.JF_QUALIFIED,
       B.NK_QUALIFIED
  FROM QCM_BC_CHEMJUDGE A, QCM_BC_CHEM_RESULT B
 WHERE A.SAMPLE_ID = {0}
   AND A.JUDGE_STOVE_NO = {1}
   AND A.BATCH_NO = {2}
   AND A.PROCESS_CDOE = {3}
   AND A.VALIDFLAG = '1'
   AND B.CHEM_JUDGE_ID = A.CHEM_JUDGE_ID
   AND B.JUDGE_SEQ = A.JUDGE_SEQ
   AND B.CHEM_NAME = {4}
   AND (B.NK_QUALIFIED = '1' AND B.JF_QUALIFIED = '1')
 GROUP BY A.LOT_NO,
          A.JUDGE_STOVE_NO,
          A.BATCH_NO,
          A.SAMPLE_ID,
          A.SAMPLE_NO,
          A.PLINE_CODE,
          B.CHEM_NAME,
          B.JF_QUALIFIED,
          B.NK_QUALIFIED
		]]>
	</query>
	
	<query id="JdgQcmBcChemResult.getGroupChemCnt" desc="获取成分分组数目">
		<![CDATA[
 SELECT CHEM_NAME, COUNT(1) COUNT
   FROM (SELECT T.CHEM_NAME
           FROM QCM_BC_CHEM_RESULT T, QCM_BC_CHEMJUDGE A
          WHERE T.CHEM_JUDGE_ID = {0}
            AND A.CHEM_JUDGE_ID = T.CHEM_JUDGE_ID
            AND A.JUDGE_SEQ = T.JUDGE_SEQ
          GROUP BY T.CHEM_NAME, A.SAMPLE_NO)
  GROUP BY CHEM_NAME
		]]>
	</query>
	
	<query id="JdgQcmBcChemResult.getGroupChemNoCnt" desc="获取不合格成分分组数目">
		<![CDATA[
 SELECT CHEM_NAME, COUNT(1) COUNT
   FROM (SELECT T.CHEM_NAME
           FROM QCM_BC_CHEM_RESULT T, QCM_BC_CHEMJUDGE A
          WHERE T.CHEM_JUDGE_ID = {0}
            AND T.NK_QUALIFIED = '0'
            AND A.CHEM_JUDGE_ID = T.CHEM_JUDGE_ID
            AND A.JUDGE_SEQ = T.JUDGE_SEQ
          GROUP BY T.CHEM_NAME, A.SAMPLE_NO)
  GROUP BY CHEM_NAME
		]]>
	</query>
	
	<query id="JdgQcmBcChemResult.updateJudgeResult" desc="修改判定记录">
		<![CDATA[
UPDATE QCM_BC_CHEM_RESULT T
      SET T.NK_QUALIFIED = DECODE(T.NK_QUALIFIED, '3', {5}, T.NK_QUALIFIED),
      T.JF_QUALIFIED = DECODE(T.JF_QUALIFIED, '3', {5}, T.JF_QUALIFIED)
    WHERE EXISTS (SELECT 1
             FROM QCM_BC_CHEMJUDGE A
            WHERE A.JUDGE_STOVE_NO = {0}
              AND A.BATCH_NO = {1}
              AND A.SAMPLE_ID = {2}
              AND A.SAMPLE_NO = {3}
              AND A.PROCESS_CDOE = {4}
              AND A.VALIDFLAG = '1'
              AND T.CHEM_JUDGE_ID = A.CHEM_JUDGE_ID
              AND T.JUDGE_SEQ = A.JUDGE_SEQ)
		]]>
	</query>
	
	<query id="JdgQcmBcChemResult.getFailCntByCheckNo" desc="获取不合格的数">
		<![CDATA[
SELECT COUNT(1) COUNT FROM QCM_BC_CHEMJUDGE C, QCM_BC_CHEM_RESULT D
 WHERE C.SAMPLE_ID = {0}
 AND C.JUDGE_STOVE_NO = {1}
 AND C.BATCH_NO = {2}
 AND C.VALIDFLAG = '1'
 AND D.CHEM_JUDGE_ID = C.CHEM_JUDGE_ID
 AND D.JUDGE_SEQ = C.JUDGE_SEQ
 AND D.NK_QUALIFIED IN('0', '3')
		]]>
	</query>
	
	<query id="JdgQcmBcChemResult.getChemResultBySampleNo" desc="通过试样号获取成分">
		<![CDATA[
SELECT B.NK_QUALIFIED, B.JF_QUALIFIED
  FROM QCM_BC_CHEMJUDGE A, QCM_BC_CHEM_RESULT B
 WHERE A.SAMPLE_ID = {0}
   AND A.JUDGE_STOVE_NO = {1}
   AND A.BATCH_NO = {2}
   AND A.SAMPLE_NO = {3}
   AND A.CRAFT_SOURCE = {4}
   AND A.VALIDFLAG = '1'
   AND B.CHEM_JUDGE_ID = A.CHEM_JUDGE_ID
   AND B.JUDGE_SEQ = A.JUDGE_SEQ
		]]>
	</query>
	
	<query id="JdgQcmBcChemResult.getByBatchNo" desc="通过炉批查询">
		<![CDATA[
SELECT A.SAMPLE_ID, A.SAMPLE_NO, A.PROCESS_CDOE PROCESS_CODE, B.*
  FROM QCM_BC_CHEMJUDGE           A,
       QCM_BC_CHEM_RESULT         B,
       QCM_ZC_CHECKCONSIGN_DETAIL C
 WHERE A.CHEM_JUDGE_ID = B.CHEM_JUDGE_ID
   AND A.JUDGE_SEQ = B.JUDGE_SEQ
   AND A.VALIDFLAG = '1'
   AND A.JUDGE_STOVE_NO = {0}
   AND A.BATCH_NO = {1}
   AND A.PROCESS_CDOE = {2}
   AND A.CRAFT_SOURCE = '0'
   AND C.CHECK_NO = A.SAMPLE_ID
   AND C.BATCH_NO = A.BATCH_NO
   AND C.SAMPLE_NO = A.SAMPLE_NO
   AND C.PHY_CODE_MAX = 'HX'
   AND C.IS_MAIN = {3}
		]]>
	</query>
	
	<query id="JdgQcmBcChemResult.getByJudgeStoveNo" desc="通过炉号查询">
		<![CDATA[
SELECT A.SAMPLE_ID, A.SAMPLE_NO, A.PROCESS_CDOE PROCESS_CODE, B.*
  FROM QCM_BC_CHEMJUDGE           A,
       QCM_BC_CHEM_RESULT         B,
       QCM_ZC_CHECKCONSIGN_DETAIL C
 WHERE A.CHEM_JUDGE_ID = B.CHEM_JUDGE_ID
   AND A.JUDGE_SEQ = B.JUDGE_SEQ
   AND A.VALIDFLAG = '1'
   AND A.JUDGE_STOVE_NO = {0}
   AND A.PROCESS_CDOE = {1}
   AND A.CRAFT_SOURCE = '0'
   AND C.CHECK_NO = A.SAMPLE_ID
   AND C.BATCH_NO = A.BATCH_NO
   AND C.SAMPLE_NO = A.SAMPLE_NO
   AND C.PHY_CODE_MAX = 'HX'
   AND C.IS_MAIN = {2}
		]]>
	</query>
</queryMap>