<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="首日检成分标准">
	<query id="CraftOrdFdCic.query" desc="查询">
		<![CDATA[
SELECT T.ORD_LN_PK,
       T.CIC,
       T.INDEX_SEQ,
       T.CHEM_CODE,
       T.CHEM_NAME,
       T.CHEM_TYPE,
       T.CHEM_FORMULA,
       DECODE(T.ISCHECK, '1', 'True', 'False') ISCHECK,
       DECODE(T.ISJUDGE, '1', 'True', 'False') ISJUDGE,
       DECODE(T.ISQUOTE, '1', 'True', 'False') ISQUOTE,
       DECODE(T.COMPLEX_TYPE, '1', 'True', 'False') COMPLEX_TYPE,
       T.STDMIN_SIGN,
       T.STDMIN,
       T.STDMAX_SIGN,
       T.STDMAX,
       T.STDTARGET,
       T.STDMEMO,
       T.ELE_CODE,
       T.ELE_NAME,
       T.ELE_MIN_SIGN,
       T.ELE_MIN,
       T.ELE_MAX_SIGN,
       T.ELE_MAX,
       T.VALIDFLAG,
       T.CREATE_NAME,
       TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
       T.UPDATE_NAME,
       TO_CHAR(T.UPDATE_TIME, 'YYYY-MM-DD HH24:MI:SS') UPDATE_TIME,
       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.CIC_MEMO,
       T.ORD_SEQ
  FROM CRAFT_ORD_FD_CIC T
 WHERE T.ORD_LN_PK = {0}
   AND T.MSC_PLINE = {1}
   AND T.PROCESS_CODE = {2}
   AND T.CIC = {3}
		]]>
	</query>
	
	<query id="CraftOrdFdCic.queryM" desc="查询">
		<![CDATA[
SELECT T.MSC_PLINE,
       T.PROCESS_CODE,
       MIN(T2.PROCESS_DESC) PROCESS_DESC,
       T.CIC,
       MIN(T.CIC_MEMO) CIC_MEMO
  FROM CRAFT_ORD_FD_CIC T
  LEFT JOIN COM_BASE_PROCESS T2
    ON T2.PROCESS_CODE = T.PROCESS_CODE
 WHERE T.ORD_LN_PK = {0}
 GROUP BY T.MSC_PLINE, T.PROCESS_CODE, T.CIC
		]]>
	</query>
	
	<query id="CraftOrdFdCic.GetMscPlineProcess" desc="获取制程工序">
        <![CDATA[
SELECT T.MSC_PLINE,
       MIN(T.WHOLE_BACKLOG) WHOLE_BACKLOG,
       MIN(T.WHOLE_BACKLOG_DESC) WHOLE_BACKLOG_DESC,
       T.PROCESS_CODE,
       MIN(T.PROCESS_DESC) PROCESS_DESC,
       A.CIC
  FROM CRAFT_ORD_DESIGN_MSC_PL_PRC T, CRAFT_ORD_DESIGN_STD_CIC A
 WHERE T.DESGIN_KEY = {0}
   AND A.DESGIN_KEY = T.DESGIN_KEY
   AND A.MSC_PLINE = T.MSC_PLINE
   AND A.PROCESS_CODE = T.PROCESS_CODE
   AND A.CRAFT_SOURCE = '0'
 GROUP BY T.MSC_PLINE, T.PROCESS_CODE, A.CIC
 ORDER BY T.MSC_PLINE, T.PROCESS_CODE, A.CIC
        ]]>
    </query>
	
	 <query id="CraftOrdFdCic.Insert" desc="新增">
        <![CDATA[
 INSERT INTO CRAFT_ORD_FD_CIC
  (ORD_LN_PK,
   CIC,
   INDEX_SEQ,
   CHEM_CODE,
   CHEM_NAME,
   CHEM_TYPE,
   CHEM_FORMULA,
   ISCHECK,
   ISJUDGE,
   ISQUOTE,
   COMPLEX_TYPE,
   STDMIN_SIGN,
   STDMIN,
   STDMAX_SIGN,
   STDMAX,
   STDTARGET,
   STDMEMO,
   ELE_CODE,
   ELE_NAME,
   ELE_MIN_SIGN,
   ELE_MIN,
   ELE_MAX_SIGN,
   ELE_MAX,
   CREATE_NAME,
   CREATE_TIME,
   REP_CODE,
   REP_NAME,
   REP_MIN_SIGN,
   REP_MIN,
   REP_MAX_SIGN,
   REP_MAX,
   REP_VAL,
   MSC_PLINE,
   PROCESS_CODE,
   CIC_MEMO,
   ORD_SEQ)
VALUES
  ('#ORD_LN_PK#',
   '#CIC#',
   (SELECT NVL(MAX(T.INDEX_SEQ), 0) + 1 INDEX_SEQ
  FROM CRAFT_ORD_FD_CIC T
 WHERE T.ORD_LN_PK = '#ORD_LN_PK#'
   AND T.PROCESS_CODE = '#PROCESS_CODE#'
   AND T.MSC_PLINE = '#MSC_PLINE#'
   AND T.CIC = '#CIC#'),
   '#CHEM_CODE#',
   '#CHEM_NAME#',
   '#CHEM_TYPE#',
   '#CHEM_FORMULA#',
   '#ISCHECK#',
   '#ISJUDGE#',
   '#ISQUOTE#',
   '#COMPLEX_TYPE#',
   '#STDMIN_SIGN#',
   '#STDMIN#',
   '#STDMAX_SIGN#',
   '#STDMAX#',
   '#STDTARGET#',
   '#STDMEMO#',
   '#ELE_CODE#',
   '#ELE_NAME#',
   '#ELE_MIN_SIGN#',
   '#ELE_MIN#',
   '#ELE_MAX_SIGN#',
   '#ELE_MAX#',
   '#CREATE_NAME#',
   SYSDATE,
   '#REP_CODE#',
   '#REP_NAME#',
   '#REP_MIN_SIGN#',
   '#REP_MIN#',
   '#REP_MAX_SIGN#',
   '#REP_MAX#',
   '#REP_VAL#',
   '#MSC_PLINE#',
   '#PROCESS_CODE#',
   '#CIC_MEMO#',
   (SELECT NVL(MAX(T.ORD_SEQ), 0) + 1
      FROM CRAFT_ORD_FD_CIC T
     WHERE T.ORD_LN_PK = '#ORD_LN_PK#'))
        ]]>
    </query>
    
     <query id="CraftOrdFdCic.Update" desc="修改">
        <![CDATA[
UPDATE CRAFT_ORD_FD_CIC T
   SET T.CIC          = '#CIC#',
       T.INDEX_SEQ    = '#INDEX_SEQ#',
       T.CHEM_CODE    = '#CHEM_CODE#',
       T.CHEM_NAME    = '#CHEM_NAME#',
       T.CHEM_TYPE    = '#CHEM_TYPE#',
       T.CHEM_FORMULA = '#CHEM_FORMULA#',
       T.ISCHECK      = '#ISCHECK#',
       T.ISJUDGE      = '#ISJUDGE#',
       T.ISQUOTE      = '#ISQUOTE#',
       T.COMPLEX_TYPE = '#COMPLEX_TYPE#',
       T.STDMIN_SIGN  = '#STDMIN_SIGN#',
       T.STDMIN       = '#STDMIN#',
       T.STDMAX_SIGN  = '#STDMAX_SIGN#',
       T.STDMAX       = '#STDMAX#',
       T.STDTARGET    = '#STDTARGET#',
       T.STDMEMO      = '#STDMEMO#',
       T.ELE_CODE     = '#ELE_CODE#',
       T.ELE_NAME     = '#ELE_NAME#',
       T.ELE_MIN_SIGN = '#ELE_MIN_SIGN#',
       T.ELE_MIN      = '#ELE_MIN#',
       T.ELE_MAX_SIGN = '#ELE_MAX_SIGN#',
       T.ELE_MAX      = '#ELE_MAX#',
       T.VALIDFLAG    = '#VALIDFLAG#',
       T.CREATE_NAME  = '#CREATE_NAME#',
       T.CREATE_TIME  = SYSDATE,
       T.UPDATE_NAME  = '#UPDATE_NAME#',
       T.UPDATE_TIME  = SYSDATE,
       T.DELETE_NAME  = '#DELETE_NAME#',
       T.DELETE_TIME  = SYSDATE,
       T.REP_CODE     = '#REP_CODE#',
       T.REP_NAME     = '#REP_NAME#',
       T.REP_MIN_SIGN = '#REP_MIN_SIGN#',
       T.REP_MIN      = '#REP_MIN#',
       T.REP_MAX_SIGN = '#REP_MAX_SIGN#',
       T.REP_MAX      = '#REP_MAX#',
       T.REP_VAL      = '#REP_VAL#',
       T.MSC_PLINE    = '#MSC_PLINE#',
       T.PROCESS_CODE = '#PROCESS_CODE#',
       T.CIC_MEMO     = '#CIC_MEMO#'
 WHERE T.ORD_LN_PK = '#ORD_LN_PK#'
   AND T.ORD_SEQ = '#ORD_SEQ#'
        ]]>
    </query>
	
	<query id="CraftOrdFdCic.Delete" desc="删除">
        <![CDATA[
DELETE FROM (SELECT *
               FROM CRAFT_ORD_FD_CIC T
              WHERE T.ORD_LN_PK = '#ORD_LN_PK#'
                AND T.ORD_SEQ = '#ORD_SEQ#')
        ]]>
    </query>
    
    <query id="CraftOrdFdCic.exist" desc="是否存在">
        <![CDATA[
SELECT T.CIC
  FROM CRAFT_ORD_FD_CIC T
 WHERE T.ORD_LN_PK = '#ORD_LN_PK#'
   AND T.CIC <> '#CIC#'
        ]]>
    </query>
    
    <query id="CraftOrdFdCic.setOrdSeq" desc="更新SEQ">
        <![CDATA[
UPDATE CRAFT_ORD_FD_CIC T
   SET T.ORD_SEQ = T.ORD_SEQ - 1
 WHERE T.ORD_LN_PK = '#ORD_LN_PK#'
   AND T.ORD_SEQ > '#ORD_SEQ#'
        ]]>
    </query>
    
    <query id="CraftOrdFdCic.setIndexSeq" desc="更新SEQ">
        <![CDATA[
UPDATE CRAFT_ORD_FD_CIC T
      SET T.INDEX_SEQ = T.INDEX_SEQ - 1
    WHERE T.ORD_LN_PK = '#ORD_LN_PK#'
      AND T.MSC_PLINE = '#MSC_PLINE#'
      AND T.PROCESS_CODE = '#PROCESS_CODE#'
      AND T.INDEX_SEQ > '#INDEX_SEQ#'
        ]]>
    </query>
    
    <query id="CraftOrdFdCic.getCraftCic" desc="获取工艺记录">
        <![CDATA[
SELECT T.*
  FROM CRAFT_ORD_DESIGN_STD_CIC T
  LEFT JOIN COM_BASE_CHEM A
    ON A.CHEM_CODE = T.CHEM_CODE
 WHERE T.DESGIN_KEY = {0}
   AND T.MSC_PLINE = {1}
   AND T.PROCESS_CODE = {2}
   AND T.CIC = {3}
   AND T.SPECL_FL = '2'
   AND T.CRAFT_SOURCE = '0'
 ORDER BY A.CHEM_SEQ
        ]]>
    </query>
    
    <query id="CraftOrdFdCic.DeleteAll" desc="删除制程工序下的所有水压">
        <![CDATA[
DELETE FROM (SELECT *
               FROM CRAFT_ORD_FD_CIC T
              WHERE T.ORD_LN_PK = {0}
                AND T.MSC_PLINE = {1}
                AND T.PROCESS_CODE = {2})
        ]]>
    </query>
    
    <query id="CraftOrdFdCic.deleteFdCicCount" desc="删除首日检成分套数">
        <![CDATA[
DELETE FROM (SELECT *
               FROM CRAFT_ORD_FD_CIC_COUNT T
              WHERE T.ORD_LN_PK = {0})
        ]]>
    </query>
    
    <query id="CraftOrdFdCic.insertFdCicCount" desc="新增首日检成分套数">
        <![CDATA[
insert into craft_ord_fd_cic_count
  (ord_ln_pk, product_cnt_fd, RATE_FD, COMMON)
values
  ({0}, {1}, {2}, {3})
        ]]>
    </query>
    
    <query id="CraftOrdFdCic.updateFdCicMemo" desc="修改首日检索引码备注">
        <![CDATA[
UPDATE CRAFT_ORD_FD_CIC T
   SET T.CIC_MEMO = {3}
 WHERE T.ORD_LN_PK = {0}
   AND T.MSC_PLINE = {1}
   AND T.PROCESS_CODE = {2}
        ]]>
    </query>
    
    <query id="CraftOrdFdCic.getFdCicCount" desc="获取成分首日检套数">
        <![CDATA[
SELECT * FROM CRAFT_ORD_FD_CIC_COUNT T WHERE T.ORD_LN_PK = {0}
        ]]>
    </query>
</queryMap>