<?xml version="1.0" encoding='UTF-8'?>

<queryMap desc="炼钢实绩添加料">
    <query id="StlChemicalStd.Select" desc="通过工艺卡号获取化学成分标准">
        <![CDATA[
      SELECT B.CHEM_CODE,
        B.CHEM_NAME,
        B.CHEM_FORMULA,
        B.STDMIN_SIGN,
        B.STDMIN,
        B.STDMAX_SIGN,
        B.STDMAX
   FROM CRAFT_LG2_M A
   LEFT JOIN CRAFT_LG2_CIC B
     ON A.CIC_GID = B.CIC_GID
  WHERE CRAFT_NO = ?
    AND (STDMIN IS NOT NULL OR STDMAX IS NOT NULL)
 UNION ALL
 SELECT T.CHEM_CODE, T.CHEM_NAME, T.CHEM_FORMULA, '', '', '', ''
   FROM COM_BASE_CHEM T
  WHERE CHEM_CODE IN ('C029', 'C030', 'C031')
    AND NOT EXISTS
  (SELECT 1
           FROM CRAFT_LG2_M A
           LEFT JOIN CRAFT_LG2_CIC B
             ON A.CIC_GID = B.CIC_GID
          WHERE CRAFT_NO = ?
            AND B.CHEM_CODE = T.CHEM_CODE
            AND (STDMIN IS NOT NULL OR STDMAX IS NOT NULL))

                 ]]>
    </query>

    <query id="StlChemicalStd.Select1" desc="通过工艺卡号获取化学成分标准">
        <![CDATA[
                 SELECT *
  FROM CRAFT_LG2_CIC
 WHERE 1=1 {0}
  AND CHEM_TYPE='A'
                 ]]>
    </query>

    <query id="StlChemica.Select" desc="查询元素实绩值">
        <![CDATA[
        SELECT SAMPLE_NO,
            AL,
            PB,
            SN,
            CA,
            LA,
            SB,
            CE,
            SE,
            MG,
            NB,
            CD,
            ASN,
            MN,
            NI,
            CR,
            CU,
            MO,
            ZN,
            TI,
            SI,
            BI,
            FE,
            C,
            P,
            S,
            V,
            B,
            W,
            N,
            H,
            O,ALT
  FROM QCM_JHY_ELEMENTS
 WHERE STOVE_NO = ?
            ORDER BY SAMPLE_NO DESC


                 ]]>
    </query>

    <query id="StlChemica.Std" desc="获取成分标准上下限">
        <![CDATA[
              SELECT C.GPREQ_ID 铸造订单,A.AUDIT_NAME 科室审核人,D.CHEM_NAME 化学元素,D.STDMIN_SIGN||D.STDMIN 下限,D.STDMAX_SIGN||D.STDMAX 上限
   FROM CRAFT_ORD_DESIGN A,
        PLN_SALEORD B,
        (SELECT DISTINCT ORD_LN_DLY_PK,
                         CRAFT_SEQ CRAFT_SEQ,
                         GPREQ_ID,
                         CIC_GP,
                         RANK() OVER(PARTITION BY GPREQ_ID ORDER BY ORD_LN_DLY_PK) RK
           FROM PLN_ORDER_ZG_S
          WHERE 1 = 1
                 {0}) C,
        CRAFT_ORD_DESIGN_STD_CIC D
  WHERE A.ORD_LN_PK = B.ORD_LN_PK
        AND A.CRAFT_SEQ = C.CRAFT_SEQ
        AND C.CIC_GP = D.CIC
        AND D.ISCHECK ='1'
        AND B.ORD_LN_DLY_PK = C.ORD_LN_DLY_PK
        AND A.DESGIN_KEY = D.DESGIN_KEY
        AND (D.STDMIN IS NOT NULL OR D.STDMAX IS NOT NULL)
        {1}
	]]>
    </query>

    <query id="StlChemica.Std1" desc="获取成分标准上下限">
        <![CDATA[
              SELECT C.GPREQ_ID 铸造订单,A.AUDIT_NAME 科室审核人,D.CHEM_NAME 化学元素,D.STDMIN_SIGN||D.STDMIN 下限,D.STDMAX_SIGN||D.STDMAX 上限
   FROM CRAFT_ORD_DESIGN A,
        PLN_SALEORD B,
        (SELECT DISTINCT ORD_LN_DLY_PK,
                         CRAFT_SEQ CRAFT_SEQ,
                         GPREQ_ID,
                         CIC_GP,
                         RANK() OVER(PARTITION BY GPREQ_ID ORDER BY ORD_LN_DLY_PK) RK
           FROM PLN_ORDER_ZG_S
          WHERE 1 = 1
                 {0}) C,
        CRAFT_ORD_DESIGN_STD_CIC D
  WHERE A.ORD_LN_PK = B.ORD_LN_PK
        AND A.CRAFT_SEQ = C.CRAFT_SEQ
        AND B.ORD_LN_DLY_PK = C.ORD_LN_DLY_PK
        AND A.DESGIN_KEY = D.DESGIN_KEY
        AND D.ISCHECK ='1'
        AND (D.STDMIN IS NOT NULL OR D.STDMAX IS NOT NULL)
        AND SPECL_FL IN ('0','1')
	]]>
    </query>

</queryMap>