<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="工序成分自动判定">
	<query id="BcChemJudgeTask.getJhyElementSampleId" desc="获取检化验信息检验编号">
		<![CDATA[
 SELECT *
  FROM (SELECT A.SAMPLE_ID, A.JUDGE_STOVE_NO, A.BATCH_NO
          FROM QCM_JHY_ELEMENTS A, COM_BASE_PLINE B
         WHERE A.VALIDFLAG = '1'
           AND A.ASSAYTYPE = 'B'
           AND A.PLINE_CODE = B.PLINE_CODE
           AND B.PROCESS_CODE = {0}
           AND A.LG_JUDGE_FLAG = '00'
         GROUP BY A.SAMPLE_ID, JUDGE_STOVE_NO, A.BATCH_NO
         ORDER BY A.SAMPLE_ID)
 WHERE ROWNUM <= 50
		]]>
	</query>
	
	<query id="BcChemJudgeTask.getApplyJudgeStoveNo" desc="获取申请判定表中的判定炉号">
		<![CDATA[
SELECT *
  FROM (SELECT A.JUDGE_STOVE_NO, A.BATCH_NO
          FROM QCM_ZG_JUGDE_APPLY A, QCM_JHY_ELEMENTS B, COM_BASE_PLINE B2
         WHERE EXISTS (SELECT 1
                  FROM QCM_ZG_JUGDE_APPLY C
                 WHERE C.JUDGE_STOVE_NO = A.JUDGE_STOVE_NO
                   AND C.BATCH_NO = A.BATCH_NO
                   AND C.PROCESS_CODE = A.PROCESS_CODE
                   AND C.IS_FLAG = '0'
                   AND NOT EXISTS
                 (SELECT 1
                          FROM QCM_BC_CHEMJUDGE C2
                         WHERE C2.JUDGE_STOVE_NO = C.JUDGE_STOVE_NO
                           AND C2.BATCH_NO = C.BATCH_NO
                           AND C2.PROCESS_CDOE = C.PROCESS_CODE
                           AND C2.VALIDFLAG = '1')
                   AND INSTR(C.STEEL_STANDRAD, 'CIC') > 0
                   AND (C.PRO_ORDER_ID IS NOT NULL OR
                       C.PRO_PLAN_ID_NEXT IS NOT NULL))
           AND A.JUDGE_STOVE_NO = B.JUDGE_STOVE_NO
           AND B2.PLINE_CODE = B.PLINE_CODE
           AND B2.PROCESS_CODE = A.PROCESS_CODE
           AND B2.PROCESS_CODE = {0}
           AND A.IS_FLAG = '0'
           AND A.IS_ALL_SCRAP = '0'
           AND B.VALIDFLAG = '1'
           AND B.ASSAYTYPE = 'B'
         GROUP BY A.JUDGE_STOVE_NO, A.BATCH_NO)
 WHERE ROWNUM <= 50
		]]>
	</query>
	
	<query id="BcChemJudgeTask.getMaxChemJudgeId" desc="查询最大的成分判定记录号（自动判定尾号0）">
		<![CDATA[
SELECT NVL(SUBSTR(MAX(T.CHEM_JUDGE_ID), 1, 13), TO_CHAR(SYSDATE, 'YYYYMMDD') || '00000') + 1 || '0' MAX_VALUE
  FROM QCM_BC_CHEMJUDGE T
 WHERE T.CHEM_JUDGE_ID LIKE TO_CHAR(SYSDATE, 'YYYYMMDD') || '%'
		]]>
	</query>
	
	<query id="BcChemJudgeTask.getZcCheckByJudgeStoveNo" desc="获取委托信息">
		<![CDATA[
SELECT T.CHECK_NO,
       T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.ORD_LN_DLY_PK,
       T.CRAFT_SEQ,
       T.INDEX_SEQ,
       T.PROCESS_CODE,
       T.CIC,
       T.LOT_NO,
       T.PLINE_CODE,
       T.STOVE_NO
  FROM QCM_ZC_CHECKCONSIGN T
 WHERE T.CHECK_NO = {0}
   AND T.JUDGE_STOVE_NO = {1}
   AND T.BATCH_NO = {2}
   AND T.PROCESS_CODE = {3}
   AND T.IS_FLAG = '0'
		]]>
	</query>
	
	<query id="BcChemJudgeTask.getApplyPlnIdByBatchNo" desc="获取计划ID">
		<![CDATA[
SELECT T.PRO_ORDER_ID,
       T.GX_PLAN_NO,
       T.PRO_PLAN_ID_NEXT,
       T.GX_PLAN_NO_NEXT,
       MAX(T.PLINE_CODE) PLINE_CODE
  FROM QCM_ZG_JUGDE_APPLY T
 WHERE T.JUDGE_STOVE_NO = {0}
   AND T.BATCH_NO = {1}
   AND T.PROCESS_CODE = {2}
   AND T.IS_FLAG = '0'
   AND T.IS_ALL_SCRAP = '0'
 GROUP BY T.PRO_ORDER_ID,
          T.GX_PLAN_NO,
          T.PRO_PLAN_ID_NEXT,
          T.GX_PLAN_NO_NEXT
		]]>
	</query>
	
	<query id="BcChemJudgeTask.queryCraftCicByZgProPlanId" desc="查询工艺DesignKey">
		<![CDATA[
SELECT MIN(DESGIN_KEY) DESGIN_KEY, MIN(MSC_PLINE) MSC_PLINE, CIC
  FROM (SELECT FIRST_VALUE(C.DESGIN_KEY) OVER(PARTITION BY A.CIC ORDER BY A.PRO_PLAN_ID) DESGIN_KEY,
               FIRST_VALUE(A.INDEX_SEQ) OVER(PARTITION BY A.CIC ORDER BY A.PRO_PLAN_ID) MSC_PLINE,
               A.CIC CIC
          FROM PLN_ZY_ZG_M A, PLN_SALEORD B, CRAFT_ORD_DESIGN C
         WHERE B.ORD_LN_DLY_PK = A.ORD_LN_DLY_PK
           AND B.ORD_LN_PK = C.ORD_LN_PK
           AND A.CRAFT_SEQ = C.CRAFT_SEQ
           AND A.PRO_PLAN_ID || A.GX_PLAN_NO IN {0}
           AND A.JUDGE_STOVE_NO = {1})
 GROUP BY CIC
		]]>
	</query>
	
	<query id="BcChemJudgeTask.queryCraftCicByDbkProPlanId" desc="查询工艺DesignKey">
		<![CDATA[
SELECT MIN(DESGIN_KEY) DESGIN_KEY, MIN(MSC_PLINE) MSC_PLINE, CIC
  FROM (SELECT FIRST_VALUE(C.DESGIN_KEY) OVER(PARTITION BY A.CIC ORDER BY A.PRO_PLAN_ID) DESGIN_KEY,
               FIRST_VALUE(A.INDEX_SEQ) OVER(PARTITION BY A.CIC ORDER BY A.PRO_PLAN_ID) MSC_PLINE,
               A.CIC CIC
          FROM PLN_ZY_DBK_M A, PLN_SALEORD B, CRAFT_ORD_DESIGN C
         WHERE B.ORD_LN_DLY_PK = A.ORD_LN_DLY_PK
           AND B.ORD_LN_PK = C.ORD_LN_PK
           AND A.CRAFT_SEQ = C.CRAFT_SEQ
           AND A.PRO_PLAN_ID || A.GX_PLAN_NO IN {0}
           AND A.JUDGE_STOVE_NO = {1})
 GROUP BY CIC
		]]>
	</query>
	
	<query id="BcChemJudgeTask.queryCraftCicByRclProPlanId" desc="查询工艺DesignKey">
		<![CDATA[
SELECT MIN(DESGIN_KEY) DESGIN_KEY, MIN(MSC_PLINE) MSC_PLINE, CIC
  FROM (SELECT FIRST_VALUE(C.DESGIN_KEY) OVER(PARTITION BY A.CIC ORDER BY A.PRO_PLAN_ID) DESGIN_KEY,
               FIRST_VALUE(A.INDEX_SEQ) OVER(PARTITION BY A.CIC ORDER BY A.PRO_PLAN_ID) MSC_PLINE,
               A.CIC CIC
          FROM PLN_ZY_RCL_M A, PLN_SALEORD B, CRAFT_ORD_DESIGN C
         WHERE B.ORD_LN_DLY_PK = A.ORD_LN_DLY_PK
           AND B.ORD_LN_PK = C.ORD_LN_PK
           AND A.CRAFT_SEQ = C.CRAFT_SEQ
           AND A.PRO_PLAN_ID || A.GX_PLAN_NO IN {0}
           AND A.JUDGE_STOVE_NO = {1})
 GROUP BY CIC
		]]>
	</query>
	
	<query id="BcChemJudgeTask.queryCraftCicByJgxProPlanId" desc="查询工艺DesignKey">
		<![CDATA[
SELECT MIN(DESGIN_KEY) DESGIN_KEY, MIN(MSC_PLINE) MSC_PLINE, CIC
  FROM (SELECT FIRST_VALUE(C.DESGIN_KEY) OVER(PARTITION BY A.CIC ORDER BY A.PRO_PLAN_ID) DESGIN_KEY,
               FIRST_VALUE(A.INDEX_SEQ) OVER(PARTITION BY A.CIC ORDER BY A.PRO_PLAN_ID) MSC_PLINE,
               A.CIC CIC
          FROM PLN_ZY_JGX_M A, PLN_SALEORD B, CRAFT_ORD_DESIGN C
         WHERE B.ORD_LN_DLY_PK = A.ORD_LN_DLY_PK
           AND B.ORD_LN_PK = C.ORD_LN_PK
           AND A.CRAFT_SEQ = C.CRAFT_SEQ
           AND A.PRO_PLAN_ID || A.GX_PLAN_NO IN {0}
           AND A.JUDGE_STOVE_NO = {1})
 GROUP BY CIC
		]]>
	</query>
	
	<query id="BcChemJudgeTask.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_ID = {2}
   AND T.SAMPLE_NO = {3}
   AND T.PROCESS_CDOE = {4}
		]]>
	</query>
	
	<query id="BcChemJudgeTask.getZgApplyByBatchNo" desc="通过判定炉号查询申请判定表">
		<![CDATA[
SELECT * FROM QCM_ZG_JUGDE_APPLY T WHERE T.JUDGE_STOVE_NO = {0}
AND T.BATCH_NO = {1}
AND T.PROCESS_CODE = {2}
AND T.IS_FLAG = '0'
AND T.IS_ALL_SCRAP = '0'
		]]>
	</query>
	
	<query id="BcChemJudgeTask.getJhyElementsByCheckNo" desc="检化验成分数据">
		<![CDATA[
SELECT A.ASSAYNO,
       A.STOVE_NO,
       A.JUDGE_STOVE_NO,
       A.BATCH_NO,
       A.ASSAYTYPE,
       A.FLAG,
       A.C,
       A.SI,
       A.MN,
       A.P,
       A.S,
       A.NI,
       A.CR,
       A.MO,
       A.CU,
       A.AL,
       A.CA,
       A.V,
       A.NB,
       A.TI,
       A.B,
       A.PB,
       A.SN,
       A.ASN,
       A.SB,
       A.BI,
       A.O,
       A.N,
       A.H,
       A.ZR,
       A.W,
       A.ZN,
       A.ALS,
       A.ALT,
       A.SE,
       A.ZR,
       A.CO,
       A.TA,
       A.SAMPLE_ID,
       A.XH,
       A.MACHINE,
       A.CREATE_NAME,
       A.CREATE_TIME,
       A.UPDATE_NAME,
       A.UPDATE_TIME,
       A.DELETE_NAME,
       A.DELETE_TIME,
       A.VALIDFLAG,
       A.MEMO,
       A.SAMPLE_NO,
       A.PLINE_CODE
  FROM QCM_JHY_ELEMENTS A, COM_BASE_PLINE C
 WHERE A.PLINE_CODE = C.PLINE_CODE
   AND C.PROCESS_CODE = {2}
   AND A.VALIDFLAG = '1'
   AND A.ASSAYTYPE = 'B'
   AND A.SAMPLE_ID = {0}
   AND A.JUDGE_STOVE_NO = {1}
		]]>
	</query>
	
	<query id="BcChemJudgeTask.queryCraftChem" desc="查询工艺评审成分记录">
		<![CDATA[
SELECT *
  FROM CRAFT_ORD_DESIGN_STD_CIC T
 WHERE T.DESGIN_KEY = {0}
   AND T.MSC_PLINE = {1}
   AND T.CIC = {2}
   AND T.PROCESS_CODE = {3}
		]]>
	</query>
	
	<query id="BcChemJudgeTask.updateChemResult" desc="修改委托表成分结果">
        <![CDATA[
UPDATE QCM_ZC_CHECKCONSIGN T
   SET T.CHEM_RESULT_CODE = {4}
 WHERE T.CHECK_NO = {0}
   AND T.JUDGE_STOVE_NO = {1}
   AND T.BATCH_NO = {2}
   AND T.PROCESS_CODE = {3}
        ]]>
    </query>
	
	<query id="BcChemJudgeTask.updateQcmJhyElement" desc="获取检化验信息">
		<![CDATA[
UPDATE QCM_JHY_ELEMENTS T
   SET T.LG_JUDGE_FLAG = {1}
 WHERE T.SAMPLE_ID = {0}
		]]>
	</query>
	
	<query id="BcChemJudgeTask.getApplyPlnIdByBatchNo" desc="获取申请判定信息">
		<![CDATA[
SELECT T.PRO_PLAN_ID,
       T.GX_PLAN_NO,
       T.PRO_PLAN_ID_NEXT,
       T.GX_PLAN_NO_NEXT,
       MAX(T.PLINE_CODE) PLINE_CODE
  FROM QCM_ZG_JUGDE_APPLY T
 WHERE T.JUDGE_STOVE_NO = {0}
   AND T.BATCH_NO = {1}
   AND T.PROCESS_CODE = {2}
   AND T.IS_FLAG = '0'
   AND T.IS_ALL_SCRAP = '0'
 GROUP BY T.PRO_PLAN_ID,
          T.GX_PLAN_NO,
          T.PRO_PLAN_ID_NEXT,
          T.GX_PLAN_NO_NEXT
		]]>
	</query>
	
	<query id="BcChemJudgeTask.udpateZgJudgeApplyChemResult" desc="查询计划轧管表">
		<![CDATA[
UPDATE QCM_ZG_JUGDE_APPLY T
   SET T.CHEM_RESULT_CODE = {3}
 WHERE T.JUDGE_STOVE_NO = {0}
   AND T.BATCH_NO = {1}
   AND T.PROCESS_CODE = {2}
   AND T.IS_FLAG = '0'
   AND T.IS_ALL_SCRAP = '0'
    ]]>
  </query>
  
  <query id="BcChemJudgeTask.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="BcChemJudgeTask.queryCraftChem" desc="查询工艺评审成分记录">
		<![CDATA[
SELECT *
  FROM CRAFT_ORD_DESIGN_STD_CIC T
 WHERE T.DESGIN_KEY = {0}
   AND T.MSC_PLINE = {1}
   AND T.CIC = {2}
   AND T.PROCESS_CODE = {3}
		]]>
	</query>
	
	<query id="BcChemJudgeTask.getCraftJfChem" desc="获取工艺评审成分">
		<![CDATA[
SELECT *
  FROM CRAFT_ORD_DESIGN_STD_CIC T
 WHERE T.DESGIN_KEY = {0}
   AND T.SPECL_FL = '0'
   AND NOT EXISTS (SELECT 1
          FROM CRAFT_ORD_DESIGN_STD_CIC A
         WHERE A.DESGIN_KEY = T.DESGIN_KEY
           AND A.SPECL_FL = '1'
           AND T.CHEM_CODE = A.CHEM_CODE)
UNION ALL
SELECT *
  FROM CRAFT_ORD_DESIGN_STD_CIC T
 WHERE T.DESGIN_KEY = {0}
   AND T.SPECL_FL = '1'
		]]>
	</query>
	
	<query id="BcChemJudgeTask.insertChemJudge" 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="BcChemJudgeTask.insertChemResult" 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)
 VALUES( 
        '#CHEM_JUDGE_ID#',
        '#JUDGE_SEQ#',
        '#CHEM_SEQ#',
        '#CHEM_NAME#',
        '#CHEM_VALUE#',
        '#NK_MIN#',
        '#NK_MAX#',
        '#NK_QUALIFIED#',
        '#JF_MIN#',
        '#JF_MAX#',
        '#JF_QUALIFIED#')
		]]>
	</query>
	<query id="BcChemJudgeTask.queryCraftChemByDlyLnPk" desc="通过交货行PK获取工艺评审成分">
		<![CDATA[
 SELECT TT.*, A.CHEM_SEQ
  FROM (SELECT T.DESGIN_KEY,
               T.CIC,
               T.USE_CODE,
               T.USE_DESC,
               T.SPECL_FL,
               T.INDEX_SEQ,
               T.CHEM_CODE,
               T.CHEM_NAME,
               T.CHEM_TYPE,
               T.CHEM_FORMULA,
               T.ISCHECK,
               T.ISJUDGE,
               T.ISQUOTE,
               T.COMPLEX_TYPE,
               T.STDMIN_SIGN,
               T.STDMIN,
               T.STDMAX_SIGN,
               T.STDMAX,
               T.STDTARGET,
               T.MODEL_CODE,
               T.MODEL_DESC,
               T.STDMEMO,
               T.ELE_CODE,
               T.ELE_NAME,
               T.ELE_MIN_SIGN,
               T.ELE_MIN,
               T.ELE_MAX_SIGN,
               T.ELE_MAX,
               T.REP_CODE,
               T.REP_NAME,
               T.REP_MIN_SIGN,
               T.REP_MIN,
               T.REP_MAX_SIGN,
               T.REP_MAX,
               T.REP_VAL,
               T.MSC_PLINE,
               T.PROCESS_CODE,
               T.CRAFT_SOURCE,
               T.CIC_MEMO,
               T.GROUP_SEQ
          FROM CRAFT_ORD_DESIGN_STD_CIC T, PLN_SALEORD B, CRAFT_ORD_DESIGN C
         WHERE B.ORD_LN_DLY_PK = {0}
           AND B.ORD_LN_PK = C.ORD_LN_PK
           AND C.CRAFT_SEQ = {1}
           AND T.DESGIN_KEY = C.DESGIN_KEY
           AND ({5} = '1' AND T.CRAFT_SOURCE = '2' OR {5} <> '1' AND T.MSC_PLINE = {2}
           AND T.PROCESS_CODE = {3}
           AND T.CIC = {4})
           AND T.CHEM_CODE NOT IN ('C012', 'C013', 'C014', 'C032', 'C043', 'C051', 'C064', 'C065')
        UNION ALL
        SELECT E.DESGIN_KEY,
               {4} CIC,
               E.USE_CODE,
               E.USE_DESC,
               '2' SPECL_FL,
               E.INDEX_SEQ,
               E.CHEM_CODE,
               E.CHEM_NAME,
               E.CHEM_TYPE,
               E.CHEM_FORMULA,
               E.ISCHECK,
               E.ISJUDGE,
               E.ISQUOTE,
               E.COMPLEX_TYPE,
               E.STDMIN_SIGN,
               E.STDMIN,
               E.STDMAX_SIGN,
               E.STDMAX,
               E.STDTARGET,
               E.MODEL_CODE,
               E.MODEL_DESC,
               E.STDMEMO,
               E.ELE_CODE,
               E.ELE_NAME,
               E.ELE_MIN_SIGN,
               E.ELE_MIN,
               E.ELE_MAX_SIGN,
               E.ELE_MAX,
               E.REP_CODE,
               E.REP_NAME,
               E.REP_MIN_SIGN,
               E.REP_MIN,
               E.REP_MAX_SIGN,
               E.REP_MAX,
               E.REP_VAL,
               E.MSC_PLINE,
               E.PROCESS_CODE,
               E.CRAFT_SOURCE,
               E.CIC_MEMO,
               E.GROUP_SEQ
          FROM CRAFT_ORD_DESIGN_STD_CIC E, PLN_SALEORD F, CRAFT_ORD_DESIGN G
         WHERE F.ORD_LN_DLY_PK = {0}
           AND G.ORD_LN_PK = F.ORD_LN_PK
           AND G.CRAFT_SEQ = {1}
           AND E.DESGIN_KEY = G.DESGIN_KEY
           AND E.SPECL_FL = '1'
           AND E.CHEM_CODE IN ('C012', 'C013', 'C014', 'C032', 'C043', 'C051', 'C064', 'C065')
        UNION ALL
        SELECT E.DESGIN_KEY,
               {4} CIC,
               E.USE_CODE,
               E.USE_DESC,
               '2' SPECL_FL,
               E.INDEX_SEQ,
               E.CHEM_CODE,
               E.CHEM_NAME,
               E.CHEM_TYPE,
               E.CHEM_FORMULA,
               E.ISCHECK,
               E.ISJUDGE,
               E.ISQUOTE,
               E.COMPLEX_TYPE,
               E.STDMIN_SIGN,
               E.STDMIN,
               E.STDMAX_SIGN,
               E.STDMAX,
               E.STDTARGET,
               E.MODEL_CODE,
               E.MODEL_DESC,
               E.STDMEMO,
               E.ELE_CODE,
               E.ELE_NAME,
               E.ELE_MIN_SIGN,
               E.ELE_MIN,
               E.ELE_MAX_SIGN,
               E.ELE_MAX,
               E.REP_CODE,
               E.REP_NAME,
               E.REP_MIN_SIGN,
               E.REP_MIN,
               E.REP_MAX_SIGN,
               E.REP_MAX,
               E.REP_VAL,
               E.MSC_PLINE,
               E.PROCESS_CODE,
               E.CRAFT_SOURCE,
               E.CIC_MEMO,
               E.GROUP_SEQ
          FROM CRAFT_ORD_DESIGN_STD_CIC E, PLN_SALEORD F, CRAFT_ORD_DESIGN G
         WHERE F.ORD_LN_DLY_PK = {0}
           AND G.ORD_LN_PK = F.ORD_LN_PK
           AND G.CRAFT_SEQ = {1}
           AND E.DESGIN_KEY = G.DESGIN_KEY
           AND E.SPECL_FL = '0'
           AND E.CHEM_CODE IN ('C012', 'C013', 'C014', 'C032', 'C043', 'C051', 'C064', 'C065')
           AND NOT EXISTS (SELECT 1
                  FROM CRAFT_ORD_DESIGN_STD_CIC E2
                 WHERE E2.CHEM_CODE = E.CHEM_CODE
                   AND E2.DESGIN_KEY = E.DESGIN_KEY
                   AND E2.SPECL_FL = '1')) TT
  LEFT JOIN COM_BASE_CHEM A
    ON A.CHEM_CODE = TT.CHEM_CODE
   AND A.VALIDFLAG = '1'
 ORDER BY A.CHEM_SEQ
		]]>
	</query>
	<query id="BcChemJudgeTask.getCraftJfChemByDlyLnPk" desc="获取工艺评审成分">
		<![CDATA[
SELECT T.*, A.CHEM_SEQ
  FROM CRAFT_ORD_DESIGN_STD_CIC T
   LEFT JOIN COM_BASE_CHEM A
            ON A.CHEM_CODE = T.CHEM_CODE
           AND A.VALIDFLAG = '1'
  , PLN_SALEORD B, CRAFT_ORD_DESIGN C
 WHERE B.ORD_LN_DLY_PK = {0}
   AND B.ORD_LN_PK = C.ORD_LN_PK
   AND C.CRAFT_SEQ = {1}
   AND C.DESGIN_KEY = T.DESGIN_KEY
   AND T.SPECL_FL = '0'
   AND NOT EXISTS (SELECT 1
          FROM CRAFT_ORD_DESIGN_STD_CIC A
         WHERE A.DESGIN_KEY = T.DESGIN_KEY
           AND A.SPECL_FL = '1'
           AND T.CHEM_CODE = A.CHEM_CODE)
UNION ALL
SELECT T.*, A.CHEM_SEQ
  FROM CRAFT_ORD_DESIGN_STD_CIC T
  LEFT JOIN COM_BASE_CHEM A
            ON A.CHEM_CODE = T.CHEM_CODE
           AND A.VALIDFLAG = '1'
  , PLN_SALEORD B, CRAFT_ORD_DESIGN C
 WHERE B.ORD_LN_DLY_PK = {0}
   AND B.ORD_LN_PK = C.ORD_LN_PK
   AND C.CRAFT_SEQ = {1}
   AND T.DESGIN_KEY = C.DESGIN_KEY
   AND T.SPECL_FL = '1'
 ORDER BY CHEM_SEQ
		]]>
	</query>
	
		<query id="BcChemJudgeTask.getCraftJfChemByOrdLnPk" desc="获取工艺评审成分">
		<![CDATA[
SELECT T.*, A.CHEM_SEQ
  FROM CRAFT_ORD_DESIGN_STD_CIC T
  LEFT JOIN COM_BASE_CHEM A
    ON A.CHEM_CODE = T.CHEM_CODE
   AND A.VALIDFLAG = '1', CRAFT_ORD_DESIGN C,PLN_SALEORD B
 WHERE B.ORD_LN_DLY_PK = {0}
   AND B.ORD_LN_PK = C.ORD_LN_PK
   AND C.CRAFT_SEQ = {1}
   AND C.DESGIN_KEY = T.DESGIN_KEY
   AND T.SPECL_FL = '0'
   AND A.CHEM_CODE NOT IN ('C012',
                               'C013',
                               'C014',
                               'C032',
                               'C043',
                               'C051',
                               'C064',
                               'C065')
   AND NOT EXISTS (SELECT 1
          FROM CRAFT_ORD_DESIGN_STD_CIC A
         WHERE A.DESGIN_KEY = T.DESGIN_KEY
           AND A.SPECL_FL = '1'
           AND T.CHEM_CODE = A.CHEM_CODE)
UNION ALL
SELECT T.*, A.CHEM_SEQ
  FROM CRAFT_ORD_DESIGN_STD_CIC T
  LEFT JOIN COM_BASE_CHEM A
    ON A.CHEM_CODE = T.CHEM_CODE
   AND A.VALIDFLAG = '1'
  LEFT JOIN craft_ord_design_msc MSC
    ON MSC.DESGIN_KEY = T.DESGIN_KEY, CRAFT_ORD_DESIGN C,PLN_SALEORD B
 WHERE B.ORD_LN_DLY_PK = {0}
   AND B.ORD_LN_PK = C.ORD_LN_PK
   AND C.CRAFT_SEQ = {1}
   AND C.DESGIN_KEY = T.DESGIN_KEY
   AND T.SPECL_FL = '0'
   AND MSC.JUDGEFLAG IN ('2','3')
   AND A.CHEM_CODE IN ('C012',
                               'C013',
                               'C014',
                               'C032',
                               'C043',
                               'C051',
                               'C064',
                               'C065')
   AND NOT EXISTS (SELECT 1
          FROM CRAFT_ORD_DESIGN_STD_CIC A
         WHERE A.DESGIN_KEY = T.DESGIN_KEY
           AND A.SPECL_FL = '1'
           AND T.CHEM_CODE = A.CHEM_CODE)
UNION ALL
SELECT T.*, A.CHEM_SEQ
  FROM CRAFT_ORD_DESIGN_STD_CIC T
  LEFT JOIN COM_BASE_CHEM A
    ON A.CHEM_CODE = T.CHEM_CODE
   AND A.VALIDFLAG = '1', CRAFT_ORD_DESIGN C,PLN_SALEORD B
 WHERE B.ORD_LN_DLY_PK = {0}
   AND B.ORD_LN_PK = C.ORD_LN_PK
   AND C.CRAFT_SEQ = {1}
   AND T.DESGIN_KEY = C.DESGIN_KEY
   AND T.SPECL_FL = '1'
 ORDER BY CHEM_SEQ
		]]>
	</query>
	
	<query id="BcChemJudgeTask.getCraftJfChemByOrdLnPkMaking" desc="获取工艺评审成分">
		<![CDATA[		
SELECT TT.*,A.CHEM_SEQ FROM( SELECT T.DESGIN_KEY,
               T.CIC,
               T.USE_CODE,
               T.USE_DESC,
               T.SPECL_FL,
               T.INDEX_SEQ,
               T.CHEM_CODE,
               T.CHEM_NAME,
               T.CHEM_TYPE,
               T.CHEM_FORMULA,
               T.ISCHECK,
               T.ISJUDGE,
               T.ISQUOTE,
               T.COMPLEX_TYPE,
               T.STDMIN_SIGN,
               T.STDMIN,
               T.STDMAX_SIGN,
               T.STDMAX,
               T.STDTARGET,
               T.MODEL_CODE,
               T.MODEL_DESC,
               T.STDMEMO,
               T.ELE_CODE,
               T.ELE_NAME,
               T.ELE_MIN_SIGN,
               T.ELE_MIN,
               T.ELE_MAX_SIGN,
               T.ELE_MAX,
               T.REP_CODE,
               T.REP_NAME,
               T.REP_MIN_SIGN,
               T.REP_MIN,
               T.REP_MAX_SIGN,
               T.REP_MAX,
               T.REP_VAL,
               T.MSC_PLINE,
               T.PROCESS_CODE,
               T.CRAFT_SOURCE,
               T.CIC_MEMO,
               T.GROUP_SEQ
  FROM CRAFT_ORD_DESIGN_STD_CIC T, CRAFT_ORD_DESIGN C,PLN_SALEORD B
 WHERE B.ORD_LN_DLY_PK = {0}
   AND B.ORD_LN_PK = C.ORD_LN_PK
   AND C.CRAFT_SEQ = {1}
   AND C.DESGIN_KEY = T.DESGIN_KEY
   AND T.SPECL_FL = '0'
   AND T.CHEM_CODE NOT IN ('C012',
                               'C013',
                               'C014',
                               'C032',
                               'C043',
                               'C051',
                               'C064',
                               'C065')
   AND NOT EXISTS (SELECT 1
          FROM CRAFT_ORD_DESIGN_STD_CIC A
         WHERE A.DESGIN_KEY = T.DESGIN_KEY
           AND A.SPECL_FL = '1'
           AND T.CHEM_CODE = A.CHEM_CODE)
UNION ALL
SELECT T.DESGIN_KEY,
               T.CIC,
               T.USE_CODE,
               T.USE_DESC,
               '0' SPECL_FL,
               T.INDEX_SEQ,
               T.CHEM_CODE,
               T.CHEM_NAME,
               T.CHEM_TYPE,
               T.CHEM_FORMULA,
               T.ISCHECK,
               T.ISJUDGE,
               T.ISQUOTE,
               T.COMPLEX_TYPE,
               T.STDMIN_SIGN,
               T.STDMIN,
               T.STDMAX_SIGN,
               T.STDMAX,
               T.STDTARGET,
               T.MODEL_CODE,
               T.MODEL_DESC,
               T.STDMEMO,
               T.ELE_CODE,
               T.ELE_NAME,
               T.ELE_MIN_SIGN,
               T.ELE_MIN,
               T.ELE_MAX_SIGN,
               T.ELE_MAX,
               T.REP_CODE,
               T.REP_NAME,
               T.REP_MIN_SIGN,
               T.REP_MIN,
               T.REP_MAX_SIGN,
               T.REP_MAX,
               T.REP_VAL,
               T.MSC_PLINE,
               T.PROCESS_CODE,
               T.CRAFT_SOURCE,
               T.CIC_MEMO,
               T.GROUP_SEQ
  FROM CRAFT_ORD_DESIGN_STD_CIC T, CRAFT_ORD_DESIGN C,craft_ord_design_msc msc,PLN_SALEORD B
 WHERE B.ORD_LN_DLY_PK = {0}
   AND B.ORD_LN_PK = C.ORD_LN_PK
   AND C.CRAFT_SEQ = {1}
   AND T.CIC = {2}
   AND C.DESGIN_KEY = T.DESGIN_KEY
   AND MSC.DESGIN_KEY = T.DESGIN_KEY
   AND MSC.JUDGEFLAG IN ('1','3')
   AND T.SPECL_FL = '2'
   AND PROCESS_CODE = 'A'
   AND T.CHEM_CODE IN ('C012',
                               'C013',
                               'C014',
                               'C032',
                               'C043',
                               'C051',
                               'C064',
                               'C065')
   AND NOT EXISTS (SELECT 1
          FROM CRAFT_ORD_DESIGN_STD_CIC A
         WHERE A.DESGIN_KEY = T.DESGIN_KEY
           AND A.SPECL_FL = '1'
           AND T.CHEM_CODE = A.CHEM_CODE)
UNION ALL
SELECT T.DESGIN_KEY,
               T.CIC,
               T.USE_CODE,
               T.USE_DESC,
               T.SPECL_FL,
               T.INDEX_SEQ,
               T.CHEM_CODE,
               T.CHEM_NAME,
               T.CHEM_TYPE,
               T.CHEM_FORMULA,
               T.ISCHECK,
               T.ISJUDGE,
               T.ISQUOTE,
               T.COMPLEX_TYPE,
               T.STDMIN_SIGN,
               T.STDMIN,
               T.STDMAX_SIGN,
               T.STDMAX,
               T.STDTARGET,
               T.MODEL_CODE,
               T.MODEL_DESC,
               T.STDMEMO,
               T.ELE_CODE,
               T.ELE_NAME,
               T.ELE_MIN_SIGN,
               T.ELE_MIN,
               T.ELE_MAX_SIGN,
               T.ELE_MAX,
               T.REP_CODE,
               T.REP_NAME,
               T.REP_MIN_SIGN,
               T.REP_MIN,
               T.REP_MAX_SIGN,
               T.REP_MAX,
               T.REP_VAL,
               T.MSC_PLINE,
               T.PROCESS_CODE,
               T.CRAFT_SOURCE,
               T.CIC_MEMO,
               T.GROUP_SEQ 
  FROM CRAFT_ORD_DESIGN_STD_CIC T, CRAFT_ORD_DESIGN C,PLN_SALEORD B
 WHERE B.ORD_LN_DLY_PK = {0}
   AND B.ORD_LN_PK = C.ORD_LN_PK
   AND C.CRAFT_SEQ = {1}
   AND T.DESGIN_KEY = C.DESGIN_KEY
   AND T.SPECL_FL = '1')TT
   LEFT JOIN COM_BASE_CHEM A
    ON A.CHEM_CODE = TT.CHEM_CODE
   AND A.VALIDFLAG = '1'
 ORDER BY CHEM_SEQ
		]]>
	</query>
    
    <query id="BcChemJudgeTask.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="BcChemJudgeTask.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>
</queryMap>