<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="成分判定记录表">
	<query id="JdgQcmBcChemJudgeDAL.query" desc="查询成分判定记录表">
		<![CDATA[
SELECT T.CHEM_JUDGE_ID,
       T.LOT_NO,
       T.STOVE_NO,
       T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.OBJECTNO,
       T3.PLINE_NAME PLINE_CODE,
       T.PROCESS_CDOE,
       T.PROCESS_DESC,
       T.JUDGE_PROORDER,
       T2.BASENAME JUDGERESULT_CHEM,
       T.ASSAYNO,
       DECODE(T.ORDERISUNCHAIN, '1', '是', '0', '否') ORDERISUNCHAIN,
       DECODE(T.VALIDFLAG, '1', '有效', '0', '无效') VALIDFLAG,
       T.MEMO,
       T.CREATE_NAME,
       TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
       T.JUGDE_APPLY_CODE,
       T4.BASENAME JF_CHEM_RESULT,
       DECODE(T.SAMPLE_TYPE, '1', '初验', '2', '复验') SAMPLE_TYPE
  FROM QCM_BC_CHEMJUDGE T
  LEFT JOIN COM_BASE_INFO T2
    ON T2.BASECODE = T.JUDGERESULT_CHEM
  LEFT JOIN COM_BASE_PLINE T3
    ON T3.PLINE_CODE = T.PLINE_CODE
  LEFT JOIN COM_BASE_INFO T4
    ON T4.BASECODE = T.JUDGERESULT_CHEM
 WHERE ({0} IS NULL OR T.JUDGE_STOVE_NO LIKE '%' || {0} || '%')
   AND ({1} IS NULL OR T.BATCH_NO LIKE '%' || {1} || '%')
   AND ({2} IS NULL OR
       T.CREATE_TIME >= TO_DATE({2}, 'YYYY-MM-DD HH24:MI:SS') AND
       T.CREATE_TIME <= TO_DATE({3}, 'YYYY-MM-DD HH24:MI:SS'))
   AND ({4} IS NULL OR {4} = '0' AND T.JUDGERESULT_CHEM IS NULL OR
       {4} = '1' AND T.JUDGERESULT_CHEM IS NOT NULL OR
       T.JUDGERESULT_CHEM = {4})
   AND ({5} = '0' OR T.PLINE_CODE IN {6})
   AND T.VALIDFLAG = '1'
   AND T.PROCESS_CDOE = {7}
 ORDER BY T.CHEM_JUDGE_ID DESC
		]]>
	</query>
	
	<query id="JdgQcmBcChemJudgeDAL.insert" desc="新增成分判定记录表">
		<![CDATA[
 INSERT INTO QCM_BC_CHEMJUDGE(
        CHEM_JUDGE_ID,
        LOT_NO,
        STOVE_NO,
        JUDGE_STOVE_NO,
        BATCH_NO,
        OBJECTNO,
        PLINE_CODE,
        PROCESS_CDOE,
        PROCESS_DESC,
        JUDGE_PROORDER,
        JUDGERESULT_CHEM,
        ASSAYNO,
        ORDERISUNCHAIN,
        MEMO,
        CREATE_NAME,
        CREATE_TIME,
        JUGDE_APPLY_CODE,
        PRO_PLAN_ID,
        DESIGN_KEY,
        MSC_PLINE,
        CIC,
        SAMPLE_NO,
        JUDGE_SEQ,
        OLD_GRADECODE,
        OLD_GRADENAME,
        OLD_CIC,
        SAMPLE_TYPE,
        MERGE_CHEM_RESULT,
        JF_CHEM_RESULT,
        ORD_LN_DLY_PK,
        CRAFT_SEQ,
        SAMPLE_ID,
        JUDGESTEELCODE,
        JUDGEGRADECODE,
        CRAFT_SOURCE)
 VALUES( 
        '#CHEM_JUDGE_ID#',
        '#LOT_NO#',
        '#STOVE_NO#',
        '#JUDGE_STOVE_NO#',
        '#BATCH_NO#',
        '#OBJECTNO#',
        '#PLINE_CODE#',
        '#PROCESS_CDOE#',
        (SELECT T.PROCESS_DESC
			  FROM COM_BASE_PROCESS T
			 WHERE T.PROCESS_CODE = '#PROCESS_CDOE#'
			),
        '#JUDGE_PROORDER#',
        '#JUDGERESULT_CHEM#',
        '#ASSAYNO#',
        '#ORDERISUNCHAIN#',
        '#MEMO#',
        '#CREATE_NAME#',
        SYSDATE,
        '#JUGDE_APPLY_CODE#',
        '#PRO_PLAN_ID#',
        '#DESIGN_KEY#',
        '#MSC_PLINE#',
        '#CIC#',
        '#SAMPLE_NO#',
        '#JUDGE_SEQ#',
        '#OLD_GRADECODE#',
        '#OLD_GRADENAME#',
        '#OLD_CIC#',
        '#SAMPLE_TYPE#',
        '#MERGE_CHEM_RESULT#',
        '#JF_CHEM_RESULT#',
        '#ORD_LN_DLY_PK#',
        '#CRAFT_SEQ#',
        '#SAMPLE_ID#',
        '#JUDGESTEELCODE#',
        '#JUDGEGRADECODE#',
        '#CRAFT_SOURCE#')
		]]>
	</query>
	
	<query id="JdgQcmBcChemJudgeDAL.getMaxChemJudgeId" desc="查询最大的成分判定记录号（人工判定尾号1）">
		<![CDATA[
SELECT NVL(SUBSTR(MAX(T.CHEM_JUDGE_ID), 1, 13), TO_CHAR(SYSDATE, 'YYYYMMDD') || '00000') + 1 || '1' MAX_VALUE
  FROM QCM_BC_CHEMJUDGE T
 WHERE T.CHEM_JUDGE_ID LIKE TO_CHAR(SYSDATE, 'YYYYMMDD') || '%'
		]]>
	</query>
	
	<query id="JdgQcmBcChemJudgeDAL.setValidflag" desc="修改有效标志">
		<![CDATA[
UPDATE QCM_BC_CHEMJUDGE T
   SET T.VALIDFLAG = {5}
 WHERE T.JUDGE_STOVE_NO = {0}
   AND T.BATCH_NO = {1}
   AND T.SAMPLE_NO = {2}
   AND T.SAMPLE_ID = {3}
   AND T.PROCESS_CDOE = {4}
		]]>
	</query>
	
	<query id="JdgQcmBcChemJudgeDAL.setValidflagByCheckNo" desc="修改有效标志">
		<![CDATA[
UPDATE QCM_BC_CHEMJUDGE T
   SET T.VALIDFLAG = {1}
 WHERE T.SAMPLE_ID = {0}
		]]>
	</query>
	
	<query id="JdgQcmBcChemJudgeDAL.setSampleType" desc="修改试样类型和合并成分结果">
		<![CDATA[
UPDATE QCM_BC_CHEMJUDGE T
   SET T.SAMPLE_TYPE       = DECODE((SELECT COUNT(1)
                                      FROM QCM_BC_CHEMJUDGE A
                                     WHERE A.CHEM_JUDGE_ID = T.CHEM_JUDGE_ID
                                       AND A.SAMPLE_ID LIKE 'F%'),
                                    0,
                                    '1',
                                    '2'),
       T.MERGE_CHEM_RESULT = {1}
 WHERE T.CHEM_JUDGE_ID = {0}
		]]>
	</query>
	
	<query id="JdgQcmBcChemJudgeDAL.queryCntByBatchNo" desc="通过批号查询判定记录数">
		<![CDATA[
SELECT COUNT(1) COUNT FROM QCM_BC_CHEMJUDGE T
 WHERE T.JUDGE_STOVE_NO = {0}
   AND T.BATCH_NO = {1}
   AND T.PROCESS_CDOE = {2}
   AND T.CRAFT_SOURCE IN {3}
   AND T.VALIDFLAG = '1'
		]]>
	</query>
	
	<query id="JdgQcmBcChemJudgeDAL.updateMemo" desc="修改备注">
		<![CDATA[
UPDATE QCM_BC_CHEMJUDGE T
   SET T.MEMO = {3}
 WHERE T.JUDGE_STOVE_NO = {0}
   AND T.BATCH_NO = {1}
   AND T.PROCESS_CDOE = {2}
   AND T.VALIDFLAG = '1'
		]]>
	</query>
	
	<query id="JdgQcmBcChemJudgeDAL.getChemJudge" desc="获取成分判定记录">
        <![CDATA[
SELECT T.CHEM_JUDGE_ID,
       T.LOT_NO,
       T.STOVE_NO,
       T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.OBJECTNO,
       T.PLINE_CODE,
       T.PROCESS_CDOE,
       T.PROCESS_DESC,
       T.JUDGE_PROORDER,
       T.JUDGERESULT_CHEM,
       T.ASSAYNO,
       T.ORDERISUNCHAIN,
       T.VALIDFLAG,
       T.MEMO,
       T.CREATE_NAME,
       TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
       T.JUGDE_APPLY_CODE,
       T.PRO_PLAN_ID,
       T.DESIGN_KEY,
       T.MSC_PLINE,
       T.CIC,
       T.SAMPLE_NO,
       T.JUDGE_SEQ,
       T.OLD_GRADECODE,
       T.OLD_GRADENAME,
       T.OLD_CIC,
       T.SAMPLE_TYPE,
       T.MERGE_CHEM_RESULT,
       T.JF_CHEM_RESULT
  FROM QCM_BC_CHEMJUDGE T
 WHERE T.JUDGE_STOVE_NO = {0}
   AND T.PROCESS_CDOE = {1}
   AND T.VALIDFLAG = '1'
        ]]>
    </query>
    
    <query id="JdgQcmBcChemJudgeDAL.getChemJudgeByJudgeId" desc="获取成分判定记录">
        <![CDATA[
SELECT T.CHEM_JUDGE_ID,
       T.LOT_NO,
       T.STOVE_NO,
       T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.OBJECTNO,
       T.PLINE_CODE,
       T.PROCESS_CDOE,
       T.PROCESS_DESC,
       T.JUDGE_PROORDER,
       T.JUDGERESULT_CHEM,
       T.ASSAYNO,
       T.ORDERISUNCHAIN,
       T.VALIDFLAG,
       T.MEMO,
       T.CREATE_NAME,
       TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
       T.JUGDE_APPLY_CODE,
       T.PRO_PLAN_ID,
       T.DESIGN_KEY,
       T.MSC_PLINE,
       T.CIC,
       T.SAMPLE_NO,
       T.JUDGE_SEQ,
       T.OLD_GRADECODE,
       T.OLD_GRADENAME,
       T.OLD_CIC,
       T.SAMPLE_TYPE,
       T.MERGE_CHEM_RESULT,
       T.JF_CHEM_RESULT
  FROM QCM_BC_CHEMJUDGE T
 WHERE T.CHEM_JUDGE_ID = {0}
        ]]>
    </query>
    
    <query id="JdgQcmBcChemJudgeDAL.getChemResult" desc="获取成分判定结果">
        <![CDATA[
SELECT A.CHEM_NAME,
       B.SAMPLE_NO,
       B.SAMPLE_ID,
       CASE
         WHEN C.CHEM_NAME IS NULL THEN
          NULL
         WHEN C.NK_QUALIFIED IN ('0', '2') THEN
          '不合格'
         ELSE
          '合格'
       END NK_RESULT,
       CASE
         WHEN C.CHEM_NAME IS NULL THEN
          NULL
         WHEN C.JF_QUALIFIED IN ('0', '2') THEN
          '不合格'
         ELSE
          '合格'
       END JF_RESULT
  FROM CRAFT_ORD_DESIGN_STD_CIC A
  LEFT JOIN QCM_BC_CHEMJUDGE B
    ON B.JUDGE_STOVE_NO = {5}
    AND B.PROCESS_CDOE = {6}
   AND B.VALIDFLAG = '1'
  LEFT JOIN QCM_BC_CHEM_RESULT C
    ON B.CHEM_JUDGE_ID IS NOT NULL
   AND C.CHEM_JUDGE_ID = B.CHEM_JUDGE_ID
   AND C.JUDGE_SEQ = B.JUDGE_SEQ
   AND C.CHEM_NAME = A.CHEM_NAME
  , CRAFT_ORD_DESIGN D, PLN_SALEORD E
 WHERE E.ORD_LN_DLY_PK = {0}
   AND D.ORD_LN_PK = E.ORD_LN_PK
   AND D.CRAFT_SEQ = {1}
   AND A.DESGIN_KEY = D.DESGIN_KEY
   AND A.MSC_PLINE = {2}
   AND A.PROCESS_CODE = {3}
   AND A.CIC = {4}
        ]]>
    </query>
    
    <query id="JdgQcmBcChemJudgeDAL.updateJudgeResult" desc="修改判定结果">
        <![CDATA[
UPDATE QCM_BC_CHEMJUDGE T
   SET T.JUDGERESULT_CHEM = {4},
    T.MERGE_CHEM_RESULT = {4},
    T.JF_CHEM_RESULT = {5}
 WHERE T.JUDGE_STOVE_NO = {0}
   AND T.BATCH_NO = {1}
   AND T.SAMPLE_ID = {2}
   AND T.PROCESS_CDOE = {3}
   AND T.VALIDFLAG = '1'
        ]]>
    </query>
</queryMap>