<?xml version="1.0" encoding="UTF-8"?>
 
<queryMap desc="备料码基础管理">
	<query id="CorePhySample.QUERY" desc="查询">
		<![CDATA[
SELECT T.SIC,
       'FALSE' CHK,
       T.PHY_CODE_MIN,
       T.PHY_NAME_MIN,
       (SELECT LISTAGG(STD_CODE, ';') WITHIN group(order by STD_CODE)
          FROM COM_BASE_SAMPLE_R_STD A
         WHERE A.SIC = T.SIC) STD_CODE,
       (SELECT xmlagg(xmlparse(content A.STD_NAME||';' wellformed) order by A.STD_NAME).getclobval()
          FROM COM_BASE_SAMPLE_R_STD A
         WHERE A.SIC = T.SIC) STD_NAME,
       LENGTH,
       T.DESC_LENGTH,
       T.RATE,
       T.DESC_RATE,
       T.DESC_COUNT,
       T.POSITION,
       T.DESC_POSITION,
       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.DELETE_NAME,
       TO_CHAR(T.DELETE_TIME, 'YYYY-MM-DD HH24:MI:SS') DELETE_TIME,
       DECODE(T.VALIDFLAG, '1', '有效', '0', '无效') VALIDFLAG,
       T.MEMO,
       T.SAMPLE_COUNT,
       BAS.BASENAME SAMPLE_STYLE,
       WIDTH,
       T.MIN_D,
       T.MAX_D,
       T.MIN_H,
       T.MAX_H,
       T.MIN_D_SIGN,
       T.MAX_D_SIGN,
       T.MIN_H_SIGN,
       T.MAX_H_SIGN,
       T.BATCH_CNT,
       T.BATCH_UNIT,
       T.ATTACH_PERCENT,
       T.ATTACH_COUNT,
       T.TOP_STOVE,
       T.LOOP_VALUE,
       T2.BASENAME SSC_CONDITION,
       (SELECT WM_CONCAT(C.PHY_TYPE)
                            FROM COM_BASE_PHY_C C
                           WHERE INSTR(T.EXCLUDE_PHY_MIN, C.PHY_CODE) > 0) EXCLUDE_PHY_MIN_NAME
  FROM COM_BASE_SAMPLE T
  LEFT JOIN COM_BASE_INFO BAS
    ON BAS.BASECODE = T.SAMPLE_STYLE
   LEFT JOIN COM_BASE_INFO T2
     ON T2.BASECODE = T.SSC_CONDITION
 WHERE T.PHY_CODE_MIN = {0}
   AND T.VALIDFLAG = '1'
   AND ({1} IS NULL OR EXISTS (SELECT 1
                  FROM COM_BASE_SAMPLE_R_STD A
                 WHERE A.SIC = T.SIC
                   AND A.VALIDFLAG = '1'
                   AND A.STD_CODE = {1}) OR NOT EXISTS
        (SELECT 1
           FROM COM_BASE_SAMPLE_R_STD A
          WHERE A.SIC = T.SIC
            AND A.VALIDFLAG = '1'))
   AND ({2} IS NULL OR EXISTS (SELECT 1
                  FROM COM_BASE_SAMPLE_R_STEEL A
                 WHERE A.SIC = T.SIC
                   AND A.VALIDFLAG = '1'
                   AND A.STEELCODE = {2}) OR NOT EXISTS
        (SELECT 1
           FROM COM_BASE_SAMPLE_R_STEEL A
          WHERE A.SIC = T.SIC
            AND A.VALIDFLAG = '1'))
   AND ({3} IS NULL OR EXISTS (SELECT 1
                  FROM COM_BASE_SAMPLE_R_PRODUCT A
                 WHERE A.SIC = T.SIC
                   AND A.PRODUCCODE = {3}) OR NOT EXISTS
        (SELECT 1 FROM COM_BASE_SAMPLE_R_PRODUCT A WHERE A.SIC = T.SIC))
		]]>
	</query>
	
	<query id="CorePhySample.GetStdTest" desc="">
		<![CDATA[
SELECT MAX(T.STD_CODE_TEST) STD_CODE_TEST,
       MAX(T.STD_NAME_TEST) STD_NAME_TEST,
       PHY_CODE_MIN,
       T.ITEM_CODE_F,
       T.ITEM_CODE_C,
       T.ITEM_CODE_W
  FROM COM_MSC_PHY_SAMPLE T
 WHERE T.PIC = '#PIC#'
   AND T.VALIDFLAG = '1'
 GROUP BY T.PHY_CODE_MIN, T.ITEM_CODE_F, T.ITEM_CODE_C, T.ITEM_CODE_W
		]]>
	</query>
	
	<query id="CorePhySample.GetSIC" desc="取得SIC码">
		<![CDATA[
        SELECT SIC
  FROM COM_MSC_PHY_SAMPLE T
 WHERE T.PHY_CODE_MIN = '#PHY_CODE_MIN#'
   AND #ITEM_CODE_C#
   AND #ITEM_CODE_F#
   AND #ITEM_CODE_W#
   AND T.PIC = '#PIC#'
		]]>
	</query>
	
	<query id="CorePhySample.DELETE" desc="删除之前关联">
		<![CDATA[
DELETE FROM COM_MSC_PHY_SAMPLE A
 WHERE PIC = '#PIC#'
   AND PHY_CODE_MIN = '#PHY_CODE_MIN#'
   AND #ITEM_CODE_F#
   AND #ITEM_CODE_C#
   AND #ITEM_CODE_W#
    OR (PIC = '#PIC#' AND NOT EXISTS
        (SELECT 1
           FROM COM_MSC_STD_PHY B
          WHERE B.PIC = A.PIC
            AND B.PHY_CODE_MIN = A.PHY_CODE_MIN
            AND NVL(B.ITEM_CODE_F, '1') = NVL(A.ITEM_CODE_F, '1')
		    AND NVL(B.ITEM_CODE_S, '1') = NVL(A.ITEM_CODE_C, '1')
		    AND NVL(SUBSTR(B.ITEM_CODE_W, INSTR(B.ITEM_CODE_W, ';') + 1), '1') = NVL(A.ITEM_CODE_W, '1')
            AND B.VALIDFLAG <> '0'))
		]]>
	</query>
	
	<query id="CorePhySample.Link" desc="关联SIC和PHYCODE">
		<![CDATA[
INSERT INTO COM_MSC_PHY_SAMPLE
  (PIC,
   PHY_CODE_MIN,
   PHY_NAME_MIN,
   SIC,
   CREATE_NAME,
   CREATE_TIME,
   MEMO,
   STD_CODE_TEST,
   STD_NAME_TEST,
   SAMPLE_KEY,
   SAMPLE_KEY_DESC,
   ITEM_CODE_F,
   ITEM_CODE_W,
   ITEM_CODE_C)
VALUES
  ('#PIC#',
   '#PHY_CODE_MIN#',
   '#PHY_NAME_MIN#',
   '#SIC#',
   '#CREATE_NAME#',
   SYSDATE,
   '#MEMO#',
   '#STD_CODE_TEST#',
   '#STD_NAME_TEST#',
   '#SAMPLE_KEY#',
   '#SAMPLE_KEY_DESC#',
   '#ITEM_CODE_F#',
   '#ITEM_CODE_W#',
   '#ITEM_CODE_C#')
		]]>
	</query>
	
	<query id="CorePhySample.UpdateStdCodeTest" desc="更新试验标准">
		<![CDATA[
UPDATE COM_MSC_PHY_SAMPLE T
   SET T.STD_CODE_TEST = '#STD_CODE_TEST#',
       T.STD_NAME_TEST = '#STD_NAME_TEST#'
 WHERE T.PIC = '#PIC#'
   AND T.PHY_CODE_MIN = '#PHY_CODE_MIN#'
   AND T.STD_CODE_TEST IS NULL
		]]>
	</query>
	
	<query id="CorePhySample.InsertSpline" desc="新增试验关系">
		<![CDATA[
INSERT INTO COM_MSC_PHY_SPLINE2(
        PHY_CODE_MIN,
        PHY_NAME_MIN,
        EIC,
        CREATE_NAME,
        CREATE_TIME,
        MEMO,
        SAMPLE_KEY,
        SAMPLE_KEY_DESC,
        ITEM_CODE_F,
        ITEM_CODE_C,
        ITEM_CODE_W,
        STD_CODE_TEST,
        STD_NAME_TEST)
 VALUES( 
        '#PHY_CODE_MIN#',
        '#PHY_NAME_MIN#',
        '#EIC#',
        '#CREATE_NAME#',
        SYSDATE,
        '#MEMO#',
        '#SAMPLE_KEY#',
        '#SAMPLE_KEY_DESC#',
        '#ITEM_CODE_F#',
        '#ITEM_CODE_C#',
        '#ITEM_CODE_W#',
        '#STD_CODE_TEST#',
        '#STD_NAME_TEST#')
		]]>
	</query>
	
	<query id="CorePhySample.DeleteSpline" desc="删除试验关系">
		<![CDATA[
DELETE FROM COM_MSC_PHY_SPLINE2 A
 WHERE 
		]]>
	</query>
	 	
	<query id="CorePhySample.QuerySpline" desc="查询试样关系">
		<![CDATA[
SELECT T.*,
       B.MIN_D,
       B.MIN_D_SIGN,
       B.MAX_D,
       B.MAX_D_SIGN,
       B.MIN_H,
       B.MIN_H_SIGN,
       B.MAX_H,
       B.MAX_H_SIGN,
       B.FORMULA,
       B.MIN_F,
       B.MIN_F_SIGN,
       B.MAX_F,
       B.MAX_F_SIGN,
       F.STD_CODE
  FROM COM_BASE_SPLINE T
  LEFT JOIN COM_BASE_SPLINE_C B
    ON B.EIC = T.EIC
   AND B.VALIDFLAG = '1'
  LEFT JOIN COM_BASE_SPLINE_C_R_STD E
    ON E.TIC = B.TIC
   AND E.STD_CODE = {4}
  LEFT JOIN COM_BASE_SPLINE_C_R_PRODUCT C
    ON C.TIC = B.TIC
   AND C.PRODUCCODE = {7}
   AND C.VALIDFLAG = '1'
  LEFT JOIN COM_BASE_SPLINE_C_R_STEEL D
    ON D.TIC = B.TIC
   AND D.STEELCODE = {8}
   AND D.VALIDFLAG = '1'
  LEFT JOIN COM_BASE_SPLINE_C_R_MODEL G
    ON G.TIC = B.TIC
   AND G.MODEL_CODE = {9}
   AND G.VALIDFLAG = '1'
  LEFT JOIN COM_BASE_SPLINE_R_STD F
    ON F.EIC = T.EIC
   AND F.VALIDFLAG = '1'
 WHERE T.PHY_CODE_MIN = {0}
   AND DECODE({1}, NULL, '1', T.ITEM_CODE_F) = NVL({1}, '1')
   AND DECODE({2}, NULL, '1', T.ITEM_CODE_S) = NVL({2}, '1')
   AND T.VALIDFLAG = '1'
   AND (B.TIC IS NOT NULL OR NOT EXISTS
        (SELECT 1
           FROM COM_BASE_SPLINE_C B
          WHERE B.EIC = T.EIC
            AND B.VALIDFLAG = '1'))
   AND (E.TIC IS NOT NULL OR NOT EXISTS
        (SELECT 1 FROM COM_BASE_SPLINE_C_R_STD E WHERE E.TIC = B.TIC))
   AND (C.TIC IS NOT NULL OR NOT EXISTS
        (SELECT 1
           FROM COM_BASE_SPLINE_C_R_PRODUCT C
          WHERE C.TIC = B.TIC
            AND C.VALIDFLAG = '1'))
   AND (D.TIC IS NOT NULL OR NOT EXISTS
        (SELECT 1
           FROM COM_BASE_SPLINE_C_R_STEEL D
          WHERE D.TIC = B.TIC
            AND D.VALIDFLAG = '1'))
   AND (G.TIC IS NOT NULL OR NOT EXISTS
        (SELECT 1
           FROM COM_BASE_SPLINE_C_R_MODEL G
          WHERE G.TIC = B.TIC
            AND G.VALIDFLAG = '1'))
		]]>
	</query>
	
	<query id="CorePhySample.QueryStdRTest" desc="查询试样组与实验标准">
		<![CDATA[
SELECT C.STD_CODE STD_CODE_TEST, C.STD_NAME STD_NAME_TEST, C.MEMO
  FROM (SELECT REGEXP_SUBSTR(A.STD_CODE_TEST, '[^;]+', 1, L) AS STD_CODE
          FROM COM_BASE_STD_R_TEST A,
               (SELECT LEVEL L FROM DUAL CONNECT BY LEVEL <= 1000) B
         WHERE L <= LENGTH(A.STD_CODE_TEST) -
               LENGTH(REPLACE(A.STD_CODE_TEST, ';')) + 1
           AND A.PHY_CODE_MIN = '#PHY_CODE_MIN#'
           AND A.VALIDFLAG = '1') B,
       COM_BASE_STD C
 WHERE B.STD_CODE = C.STD_CODE
		]]>
	</query>
	
	<query id="CorePhySample.GetPicData" desc="查询理化标准数据">
		<![CDATA[
SELECT A.PIC,
       A.PHY_CODE_MIN,
       A.PHY_NAME_MIN,
       D.STD_CODE,
       D.STD_NAME,
       D.STEELCODE,
       D.STEELNAME,
       D.PRODUCCODE,
       D.PRODUCNAME,
       C.USE_CODE,
       C.USE_DESC,
       A.ITEM_CODE_F,
       A.ITEM_NAME_F,
       A.ITEM_CODE_S  ITEM_CODE_C,
       A.ITEM_NAME_S  ITEM_NAME_C,
       A.ITEM_CODE_W,
       A.ITEM_NAME_W
  FROM CRAFT_ORD_DESIGN_STD_PIC A,
       CRAFT_ORD_DESIGN_MSC     B,
       COM_PSC_R_MSC            C,
       COM_PSC                  D
 WHERE A.PIC = {0}
   AND A.DESGIN_KEY = {1}
   AND A.SPECL_FL IN ('0', '1')
   AND B.DESGIN_KEY = A.DESGIN_KEY
   AND B.VALIDFLAG = '1'
   AND B.MSC = C.MSC
   AND C.PSC = D.PSC
 GROUP BY A.PIC,
          A.PHY_CODE_MIN,
          A.PHY_NAME_MIN,
          D.STD_CODE,
          D.STD_NAME,
          D.STEELCODE,
          D.STEELNAME,
          D.PRODUCCODE,
          D.PRODUCNAME,
          C.USE_CODE,
          C.USE_DESC,
          A.ITEM_CODE_F,
          A.ITEM_NAME_F,
          A.ITEM_CODE_S,
          A.ITEM_NAME_S,
          A.ITEM_CODE_W,
          A.ITEM_NAME_W
UNION ALL
SELECT A.PIC,
       A.PHY_CODE_MIN,
       A.PHY_NAME_MIN,
       NULL           STD_CODE,
       NULL           STD_NAME,
       NULL           STEELCODE,
       NULL           STEELNAME,
       NULL           PRODUCCODE,
       NULL           PRODUCNAME,
       NULL           USE_CODE,
       NULL           USE_DESC,
       A.ITEM_CODE_F,
       A.ITEM_NAME_F,
       A.ITEM_CODE_S  ITEM_CODE_C,
       A.ITEM_NAME_S  ITEM_NAME_C,
       A.ITEM_CODE_W,
       A.ITEM_NAME_W
  FROM CRAFT_ORD_DESIGN_STD_PIC A
 WHERE A.PIC = {0}
   AND A.SPECL_FL = '2'
   AND A.DESGIN_KEY = {1}
   AND A.MSC_PLINE = {2}
   AND A.PROCESS_CODE = {3}
 GROUP BY A.PIC,
          A.PHY_CODE_MIN,
          A.PHY_NAME_MIN,
          A.ITEM_CODE_F,
          A.ITEM_NAME_F,
          A.ITEM_CODE_S,
          A.ITEM_NAME_S,
          A.ITEM_CODE_W,
          A.ITEM_NAME_W
		]]>
	</query>
	<query id="CorePhySample.deleteSetEic" desc="删除设定试样码">
		<![CDATA[
DELETE FROM CRAFT_ORD_DESIGN_STD_PIC_SMP_S T
 WHERE T.ORD_LN_PK = {0}
   AND T.PHY_CODE_MIN = {1}
   AND NVL(T.ITEM_CODE_F, '1') = NVL({2}, '1')
   AND NVL(T.ITEM_CODE_C, '1') = NVL({3}, '1')
   AND NVL(T.ITEM_CODE_W, '1') = NVL({4}, '1')
   
		]]>
	</query>
	<query id="CorePhySample.insertSetEic" desc="新增设定试样码">
		<![CDATA[
INSERT INTO CRAFT_ORD_DESIGN_STD_PIC_SMP_S
  (ORD_LN_PK, SET_EIC, PHY_CODE_MIN, ITEM_CODE_F, ITEM_CODE_C, ITEM_CODE_W)
VALUES
  ({0}, {1}, {2}, {3}, {4}, {5})
		]]>
	</query>
	<query id="CorePhySample.getOrderLineByPk" desc="通过主键获取合同行">
		<![CDATA[
SELECT * FROM SLM_ORDER_LINE WHERE ORD_LN_PK = {0}
		]]>
	</query>
	<query id="CorePhySample.getMsCBlByPk" desc="通过主键获取备料">
		<![CDATA[
SELECT * FROM COM_MSC_BL WHERE PSC_BL = {0}
		]]>
	</query>
	<query id="CorePhySample.querySetEic" desc="查询设定试样码">
		<![CDATA[
SELECT *
  FROM CRAFT_ORD_DESIGN_STD_PIC_SMP_S T
 WHERE T.ORD_LN_PK = {0}
   AND T.PHY_CODE_MIN = {1}
   AND NVL(T.ITEM_CODE_F, '1') = NVL({2}, '1')
   AND NVL(T.ITEM_CODE_C, '1') = NVL({3}, '1')
   AND NVL(T.ITEM_CODE_W, '1') = NVL({4}, '1')
		]]>
	</query>
	<query id="CorePhySample.getConvertPhy" desc="获取转换了的理化冲击">
		<![CDATA[
SELECT T.PHY_NAME_MAX,
       T.PHY_NAME_MIN,
       T.PHY_NAME,
       T.ITEM_NAME_F,
       T.ITEM_NAME_W,
       T.ITEM_NAME_S ITEM_NAME_C,
       T.STDMIN_SIGN,
       T.STDMIN,
       T.STDMAX_SIGN,
       T.STDMAX,
       T.STDMIN_SIGN2,
       T.STDMIN2,
       T.STDMAX_SIGN2,
       T.STDMAX2,
       DECODE(T.ADDCONDITION, '1', '符合标准时', '0', '不符合标准时') ADDCONDITION,
       D.BASENAME ADDSTDCON_NAME,
       T.ADDSTD_MIN_SIGN,
       T.ADDSTD_MIN,
       T.ADDSTD_MAX_SIGN,
       T.ADDSTD_MAX,
       T.ADDPERCENT
  FROM CRAFT_ORD_DESIGN_STD_PIC T
  LEFT JOIN COM_BASE_INFO D
    ON D.BASECODE = T.ADDSTDCON_CODE, CRAFT_ORD_DESIGN A
 WHERE A.ORD_LN_PK = {0}
   AND A.CRAFT_SEQ = (SELECT MAX(B.CRAFT_SEQ)
                        FROM CRAFT_ORD_DESIGN B
                       WHERE B.ORD_LN_PK = A.ORD_LN_PK)
   AND T.DESGIN_KEY = A.DESGIN_KEY
   AND NOT EXISTS
 (SELECT 1
          FROM COM_MSC_STD_PHY C
         WHERE C.PIC = T.PIC
           AND C.PHY_CODE_MAX = T.PHY_CODE_MAX
           AND C.PHY_CODE_MIN = T.PHY_CODE_MIN
           AND C.PHY_CODE = T.PHY_CODE
           AND NVL(C.ITEM_CODE_F, '1') = NVL(T.ITEM_CODE_F, '1')
           AND NVL(C.ITEM_CODE_W, '1') = NVL(T.ITEM_CODE_W, '1')
           AND NVL(C.ITEM_CODE_S, '1') = NVL(T.ITEM_CODE_S, '1'))
		]]>
	</query>
	<query id="CorePhySample.getSplineUnit" desc="获取试样码维护科室">
		<![CDATA[
SELECT B.DEPARTID, B.DEPARTNAME
  FROM CRAFT_SPLINE_UNIT A, CORE_APP_DEPARTMENT B
 WHERE A.UNIT_CODE = B.DEPARTID
		]]>
	</query>
</queryMap>