<?xml version="1.0" encoding="UTF-8"?>
 
<queryMap desc="标准类型基础管理">
   <query id="JGRBLCode.InitJGRSTEEL" desc="获取接箍码信息">
		<![CDATA[ 
		   SELECT CODE_JG,
           SPEC_JG,
           SPEC_JG_DESC,
           PRODUCCODE_JG,
           PRODUCCODE_JG_DESC,
           STEELCODE_JG,
           STEELCODE_JG_DESC,
           MODEL_CODE,
           MODEL_DESC,
           STYLE_JG,
           MIN_D,
           MIN_H,
           DIAMETER_JG,
           HEIGHT_JG,
           LENGTH_JG,
           WEIGHT_JG,
           DIAMETER,
           ALPHA,
           DIAMETER_PL,
           HEIGHT_PL,
           LENGTH_MIN,
           LENGTH_MAX,
           PRODUCCODE,
           PRODUCNAME,
           MIN_H_CP,
           MAX_H_CP,
           MIN_D_CP,
           MAX_D_CP,
           MEMO
           FROM COM_MSC_JG T
	       WHERE T.VALIDFLAG='1'   
		]]>
	</query>
	<query id="JGRBLCode.QUERY" desc="接箍备料关联查询">
		<![CDATA[   
       SELECT 
       'TRUE' CHK,
       T1.CODE_JG,
       T1.PSC_BL,
       T2.PRODUCCODE,
       T2.PRODUCNAME,
       T2.STD_CODE,
       T2.STD_NAME,
       T2.STEELCODE,
       T2.STEELNAME,
       T2.STD_STYLE,
       T2.STD_STYLE_DESC,
       T2.MODEL_CODE,
       T2.MODEL_DESC,
       T2.MIN_D,
       T2.MIN_H,
       T2.USE_CODE,
       T2.USE_DESC,
       T1.CREATE_NAME,
       TO_CHAR(T1.CREATE_TIME,'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
       T1.UPDATE_NAME,
       TO_CHAR(T1.UPDATE_TIME,'YYYY-MM-DD HH24:MI:SS') UPDATE_TIME,
       T1.DELETE_NAME,
       TO_CHAR(T1.DELETE_TIME,'YYYY-MM-DD HH24:MI:SS') DELETE_TIME,
       T1.VALIDFLAG,
       T1.MEMO
       FROM COM_MSC_JG_R_BL T1 ,COM_MSC_BL T2
       WHERE T1.CODE_JG=? AND T1.PSC_BL=T2.PSC_BL
       UNION 
       SELECT 
       'FALSE' CHK,
        '' CODE_JG,
        PSC_BL,
        PRODUCCODE,
        PRODUCNAME,
        STD_CODE,
        STD_NAME,
        STEELCODE,
        STEELNAME,
        STD_STYLE,
        STD_STYLE_DESC,
        MODEL_CODE,
        MODEL_DESC,
        MIN_D,
        MIN_H,
        USE_CODE,
        USE_DESC,    
        CREATE_NAME,
        TO_CHAR(T.CREATE_TIME,'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
        UPDATE_NAME,
        TO_CHAR(T.UPDATE_TIME,'YYYY-MM-DD HH24:MI:SS') UPDATE_TIME,
        DELETE_NAME,
        TO_CHAR(T.DELETE_TIME,'YYYY-MM-DD HH24:MI:SS') DELETE_TIME,
        VALIDFLAG,
        MEMO
       FROM COM_MSC_BL T
       WHERE T.VALIDFLAG='1' AND  NOT EXISTS 
       (SELECT 1 FROM COM_MSC_JG_R_BL WHERE CODE_JG=? AND PSC_BL=T.PSC_BL)
		]]>
	</query> 
	
	<query id="JGRBLCode.QUERY2" desc="接箍备料关联查询2">
		<![CDATA[
SELECT 'TRUE' CHK,
       T1.CODE_JG,
       T1.PSC_BL,
       T1.CUST_ALPHA_NO,
       T1.ORDER_SPECIAL_DESC,
       T1.ALPHA_CODE,
       AP.ALPHA_NAME,
       T2.PRODUCCODE,
       T2.PRODUCNAME,
       T2.STD_CODE,
       T2.STD_NAME,
       T2.STEELCODE,
       T2.STEELNAME,
       T2.STD_STYLE,
       T2.STD_STYLE_DESC,
       T2.MODEL_CODE,
       T2.MODEL_DESC,
       T2.MIN_D,
       T2.MIN_H,
       T2.USE_CODE,
       T2.USE_DESC,
       T1.CREATE_NAME,
       TO_CHAR(T1.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
       T1.UPDATE_NAME,
       TO_CHAR(T1.UPDATE_TIME, 'YYYY-MM-DD HH24:MI:SS') UPDATE_TIME,
       T1.DELETE_NAME,
       TO_CHAR(T1.DELETE_TIME, 'YYYY-MM-DD HH24:MI:SS') DELETE_TIME,
       T1.VALIDFLAG,
       T1.MEMO,
       '备料评审' REVIEW,
       DECODE(T2.REVIEW_STATUS,
              '0',
              '待技术评审',
              '1',
              '技术评审中',
              '2',
              '技术评审通过',
              '3',
              '技术评审失败') REVIEW_STATUS,
       DECODE(T3.VALIDFLAG,
              '0',
              '无效',
              '1',
              '生效',
              '2',
              '制定中',
              '3',
              '待审核',
              '4',
              '待审批',
              '未制定') CRAFT_STATUS,
       DECODE(L.DESIGN_STS, 'S', KK.UNIT_DESC, MM.UNIT_DESC) UNIT_DESC,
       T3.CRAFT_NO,
       T3.MEMO CRAFT_MEMO,
       T3.CRAFT_PATH,
       T2.BL_LEVEL
  FROM COM_MSC_JG_R_BL T1
  LEFT JOIN COM_BASE_STD_ALPHA AP
    ON AP.ALPHA_CODE = T1.ALPHA_CODE, COM_MSC_BL T2
  LEFT JOIN CRAFT_ORD_DESIGN T3
    ON T3.ORD_LN_PK = T2.PSC_BL
  LEFT JOIN SLM_ORD_DESIGN_BL J
    ON J.PSC_BL = T2.PSC_BL
   AND J.VALIDFLAG = '1'
  LEFT JOIN (SELECT K.UNIT_DESC, K.DESGIN_KEY
               FROM SLM_ORD_DESIGN_STS_TKLG_LST K
              WHERE K.VALIDFLAG = '1'
                AND K.DESIGN_STS = 'S'
                AND K.SEQ_INDEX = (SELECT MAX(KKK.SEQ_INDEX)
                                     FROM SLM_ORD_DESIGN_STS_TKLG_LST KKK
                                    WHERE KKK.DESGIN_KEY = K.DESGIN_KEY
                                      AND KKK.VALIDFLAG = '1')) KK
    ON KK.DESGIN_KEY = J.DESGIN_KEY
  LEFT JOIN (SELECT MAX(M.UNIT_DESC) UNIT_DESC, M.DESGIN_KEY
               FROM SLM_ORD_DESIGN_STS_TKLG_LST M
              WHERE M.VALIDFLAG = '1'
                AND M.DESIGN_STS = 'F'
              GROUP BY M.DESGIN_KEY) MM
    ON MM.DESGIN_KEY = J.DESGIN_KEY
  LEFT JOIN SLM_ORD_DESIGN_STS_TKLG L
    ON L.DESGIN_KEY = J.DESGIN_KEY
   AND L.VALIDFLAG = '1'
 WHERE T1.CODE_JG = ?
   AND T1.CUST_ALPHA_NO = ?
   AND T1.ALPHA_CODE = ?
   AND T1.PSC_BL = T2.PSC_BL
   AND NVL(T3.CRAFT_SEQ, '1') =
       DECODE(T3.CRAFT_SEQ,
              NULL,
              '1',
              (SELECT MAX(CRAFT_SEQ)
                 FROM CRAFT_ORD_DESIGN
                WHERE ORD_LN_PK = T1.PSC_BL))
		]]>
	</query> 
	
	<query id="JGRBLCode.DELETE" desc="删除存在备料代码、描述">
		<![CDATA[ 
		       DELETE FROM COM_MSC_JG_R_BL  T
		       WHERE T.KEY_JG = ?
		]]>
	</query>
	
	<query id="JGRBLCode.ADD" desc="添加备料代码、描述">
		<![CDATA[ 
		   INSERT INTO COM_MSC_JG_R_BL
           (CODE_JG,
            CUST_ALPHA_NO,
            ORDER_SPECIAL_DESC,
            ALPHA_CODE,
            PSC_BL,
            CREATE_NAME,
            CREATE_TIME,
            MEMO
           ) VALUES (?, ?, ?, ?, ?, ?,SYSDATE,?)
		]]>
	</query>
	
	<query id="JGRBLCode.checkJgRBlIsRepeat" desc="备料码和接箍的关系是否重复">
		<![CDATA[ 
SELECT 1 FROM COM_MSC_JG_R_BL T
WHERE T.CODE_JG = '#CODE_JG#' AND T.PSC_BL = '#PSC_BL#'
AND T.CUST_ALPHA_NO = '#CUST_ALPHA_NO#' AND T.ALPHA_CODE = '#ALPHA_CODE#'
		]]>
	</query>
	
	<query id="JGRBLCode.delete" desc="删除备料和接箍的关系">
		<![CDATA[ 
DELETE COM_MSC_JG_R_BL T WHERE T.CODE_JG = '#CODE_JG#' AND T.PSC_BL = '#PSC_BL#'
AND T.CUST_ALPHA_NO = '#CUST_ALPHA_NO#' AND T.ALPHA_CODE = '#ALPHA_CODE#'
		]]>
	</query>
	<query id="JGRBLCode.getComMscJgByKeyJg" desc="获取接箍的成品最大和最小外径">
		<![CDATA[
SELECT MIN_D_JG, MAX_D_JG
  FROM COM_MSC_R_JG A, COM_MSC_JG B
 WHERE A.KEY_JG = {0}
   AND B.CODE_JG = A.CODE_JG
		]]>
	</query>
</queryMap>