<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="工艺文件适用范围">
    <query id="CraftFileApplyDAL.query" desc="查询工艺文件适用范围">
		<![CDATA[
SELECT T.CRAFT_NO,
       T.CRAFT_NO_V,
       T.CRAFT_KEY,
       T.CREATE_NAME,
       TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
       T.MSC,
       T.MSC_DESC,
       T.MIN_H,
       T.MAX_H,
       T.MIN_D,
       T.MAX_D,
       T.SPEC_CODE,
       T.MODEL_CODE,
       T.MODEL_DESC,
       T.CRAFT_ID
  FROM CRAFT_FILE_APPLY T
 WHERE T.CRAFT_KEY = '#CRAFT_KEY#'
   ORDER BY T.MSC_DESC
		]]>
	</query>
	
    <query id="CraftFileApplyDAL.insert" desc="新增工艺文件适用范围">
		<![CDATA[
INSERT INTO CRAFT_FILE_APPLY
  (CRAFT_NO,
   CRAFT_NO_V,
   CRAFT_KEY,
   CREATE_NAME,
   CREATE_TIME,
   MSC,
   MSC_DESC,
   MIN_H,
   MAX_H,
   MIN_D,
   MAX_D,
   SPEC_CODE,
   MODEL_CODE,
   MODEL_DESC)
VALUES
  ('#CRAFT_NO#',
   '#CRAFT_NO_V#',
   '#CRAFT_KEY#',
   '#CREATE_NAME#',
   SYSDATE,
   '#MSC#',
   '#MSC_DESC#',
   '#MIN_H#',
   '#MAX_H#',
   '#MIN_D#',
   '#MAX_D#',
   '#SPEC_CODE#',
   '#MODEL_CODE#',
   '#MODEL_DESC#')
		]]>
	</query>
	
    <query id="CraftFileApplyDAL.delete" desc="删除工艺文件适用范围">
		<![CDATA[
DELETE FROM CRAFT_FILE_APPLY T WHERE T.CRAFT_ID = '#CRAFT_ID#'
		]]>
	</query>
	
    <query id="CraftFileApplyDAL.getSampeCnt" desc="获取相同项目的数目">
		<![CDATA[
SELECT COUNT(1) COUNT,
       MAX(T.CRAFT_NO) CRAFT_NO,
       MAX(T.CRAFT_NO_V) CRAFT_NO_V
  FROM CRAFT_FILE_APPLY T
 WHERE T.MSC = '#MSC#'
   AND ((TO_NUMBER(T.MIN_H) <= TO_NUMBER('#MIN_H#') AND TO_NUMBER(T.MAX_H) >= TO_NUMBER('#MIN_H#')) OR
       (TO_NUMBER(T.MIN_H) <= TO_NUMBER('#MAX_H#') AND TO_NUMBER(T.MAX_H) >= TO_NUMBER('#MAX_H#')))
   AND ((TO_NUMBER(T.MIN_D) <= TO_NUMBER('#MIN_D#') AND TO_NUMBER(T.MAX_D) >= TO_NUMBER('#MIN_D#')) OR
       (TO_NUMBER(T.MIN_D) <= TO_NUMBER('#MAX_D#') AND TO_NUMBER(T.MAX_D) >= TO_NUMBER('#MAX_D#')))
   AND T.SPEC_CODE = '#SPEC_CODE#'
   AND INSTR(NVL(T.MODEL_CODE, 'C001'), NVL('#MODEL_CODE#', 'C001')) > 0
   AND T.CRAFT_ID <> NVL('#CRAFT_ID#', '1')
		]]>
	</query>
	
    <query id="CraftFileApplyDAL.getMatchCraftFile" desc="获取匹配的工艺文件">
		<![CDATA[
SELECT T.CRAFT_NO, T.CRAFT_NO_V, C.CRAFT_PATH
  FROM CRAFT_FILE_APPLY      T,
       SLM_ORDER_LINE        A,
       COM_BASE_SPEC         B,
       CRAFT_ORD_DESIGN_FILE C
 WHERE A.ORD_LN_PK = '#ORD_LN_PK#'
   AND T.CRAFT_NO = C.CRAFT_NO
   AND T.CRAFT_NO_V = C.CRAFT_NO_V
   AND A.SPEC_CODE = B.SPEC_CODE
   AND A.MSC = T.MSC
   AND DECODE(B.MSC_STYLE, 'C', T.SPEC_CODE, '1') =
       DECODE(B.MSC_STYLE, 'C', T.SPEC_CODE, '1')
   AND DECODE(B.MSC_STYLE, 'C', 1, TO_NUMBER(T.MIN_D)) <=
       DECODE(B.MSC_STYLE, 'C', 1, TO_NUMBER(A.DIMATER))
   AND DECODE(B.MSC_STYLE, 'C', 1, TO_NUMBER(T.MAX_D)) >=
       DECODE(B.MSC_STYLE, 'C', 1, TO_NUMBER(A.DIMATER))
   AND DECODE(B.MSC_STYLE, 'C', 1, TO_NUMBER(T.MIN_H)) <=
       DECODE(B.MSC_STYLE, 'C', 1, TO_NUMBER(A.HEIGHT))
   AND DECODE(B.MSC_STYLE, 'C', 1, TO_NUMBER(T.MAX_H)) >=
       DECODE(B.MSC_STYLE, 'C', 1, TO_NUMBER(A.HEIGHT))
   AND INSTR(NVL(T.MODEL_CODE, 'C001'), NVL(A.MODEL_CODE, 'C001')) > 0
UNION ALL
SELECT T.CRAFT_NO, T.CRAFT_NO_V, C.CRAFT_PATH
  FROM CRAFT_FILE_APPLY T, COM_MSC_BL A, COM_PSC P, CRAFT_ORD_DESIGN_FILE C
 WHERE A.PSC_BL = '#ORD_LN_PK#'
   AND T.CRAFT_NO = C.CRAFT_NO
   AND T.CRAFT_NO_V = C.CRAFT_NO_V
   AND A.PRODUCCODE = P.PRODUCCODE
   AND A.STEELCODE = P.STEELCODE
   AND A.STD_CODE = P.STD_CODE
   AND NVL(A.STD_STYLE, '004') = NVL(P.STD_STYLE, '004')
   AND P.MSC = T.MSC
   AND TO_NUMBER(T.MIN_D) <= TO_NUMBER(A.MIN_D)
   AND TO_NUMBER(T.MAX_D) >= TO_NUMBER(A.MIN_D)
   AND TO_NUMBER(T.MIN_H) <= TO_NUMBER(A.MIN_H)
   AND TO_NUMBER(T.MAX_H) >= TO_NUMBER(A.MIN_H)
   AND INSTR(NVL(T.MODEL_CODE, 'C001'), NVL(A.MODEL_CODE, 'C001')) > 0
		]]>
	</query>
</queryMap>