<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="下拉框动态数据获取管理">
	 
	 <query id="CoreWaterRatio.GetStd" desc="标准基础">
		<![CDATA[	
          SELECT 
          STD_NAME,
          STD_CODE
          FROM COM_BASE_STD
          WHERE VALIDFLAG='1'
          AND (STDSTYLE = 'G' OR STDSTYLE = 'X')
          AND DECODE(?,'','1',STD_CODE) = DECODE(?,'','1',?)
          ORDER BY STD_NAME
		]]>
	</query>
	
	 <query id="CoreWaterRatio.GetStdStyle" desc="标准基础">
		<![CDATA[	
          SELECT 
          STD_STYLE,STD_STYLE_DESC
          FROM COM_BASE_STD_STYLE 
          WHERE VALIDFLAG='1'
          ORDER BY STD_STYLE
		]]>
	</query>
	
	 <query id="CoreWaterRatio.GetMaxId" desc="标准基础">
		<![CDATA[	
          SELECT MAX(RATIO_ID) ID
          FROM COM_BASE_WATER_RATIO
		]]>
	</query>
	
	<query id="CoreWaterRatio.GetModel" desc="获取扣型">
	<![CDATA[
	  SELECT 'TRUE' CHK,
         TO_NUMBER(T1.RATIO_ID) RATIO_ID,
         T1.MODEL_CODE,
         T1.MODEL_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_BASE_WATER_RATIO_MODEL T1
   WHERE T1.RATIO_ID = ?
   UNION ALL
   SELECT 'FALSE' CHK,
         TO_NUMBER(?) RATIO_ID,
         MODEL_CODE,
         MODEL_DESC,
         '' CREATE_NAME,
         NULL CREATE_TIME,
         '' UPDATE_NAME,
         NULL UPDATE_TIME,
         '' DELETE_NAME,
         NULL DELETE_TIME,
         '' VALIDFLAG,
         '' MEMO
    FROM COM_BASE_MODEL T
   WHERE T.VALIDFLAG = '1'
     AND T.MODEL_CODE NOT IN
         (SELECT MODEL_CODE
            FROM COM_BASE_WATER_RATIO_MODEL
           WHERE RATIO_ID = ?
             AND MODEL_CODE = T.MODEL_CODE)
   ORDER BY MODEL_DESC ASC
	
	]]>
	</query>
	
	<query id="CoreWaterRatio.GetSteel" desc="关联查询">
		<![CDATA[	
      SELECT 
       'TRUE' CHK,
       TO_NUMBER(T1.RATIO_ID) RATIO_ID,
       T1.STEELCODE,
       T1.STEELNAME,
       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_BASE_WATER_RATIO_STEEL T1 ,COM_BASE_STEEL T2
       WHERE T1.RATIO_ID=? AND T1.STEELCODE=T2.STEELCODE
       AND T1.STEELCODE IN (SELECT T3.STEELCODE FROM COM_PSC T3, COM_BASE_WATER_RATIO T4 WHERE 
          T3.STD_CODE = T4.STD_CODE AND T4.RATIO_ID = T1.RATIO_ID)
       UNION  ALL
       SELECT 
       'FALSE' CHK,
       TO_NUMBER(?)   RATIO_ID,
            STEELCODE, 
            STEELNAME, 
       ''   CREATE_NAME,
       NULL CREATE_TIME,
       ''   UPDATE_NAME,
       NULL UPDATE_TIME,
       ''   DELETE_NAME,
       NULL DELETE_TIME,
       ''   VALIDFLAG,
       ''   MEMO
       FROM COM_BASE_STEEL T
       WHERE T.VALIDFLAG='1'
       AND T.STEELCODE IN (SELECT T3.STEELCODE FROM COM_PSC T3, COM_BASE_WATER_RATIO T4 WHERE 
          T3.STD_CODE = T4.STD_CODE AND T4.RATIO_ID = ?)
        AND  NOT EXISTS 
       (SELECT 1 FROM COM_BASE_WATER_RATIO_STEEL WHERE RATIO_ID=? AND STEELCODE=T.STEELCODE)
       ORDER BY STEELNAME ASC
		]]>
	</query>
	
	<query id="CoreWaterRatio.GetSteelNew" desc="关联查询">
		<![CDATA[	
         SELECT  DISTINCT 'FALSE' CHK, STEELCODE, STEELNAME
          FROM COM_PSC T
          WHERE T.STD_CODE = ?
         
		]]>
	</query>
	
	<query id="CoreWaterRatio.DeleteRatioSteel" desc="关联查询">
		<![CDATA[	
       DELETE COM_BASE_WATER_RATIO_STEEL
       WHERE RATIO_ID = ?
		]]>
	</query>
	
	
	<query id="CoreWaterRatio.AddRatio_Steel" desc="关联增加">
		<![CDATA[	
     INSERT INTO COM_BASE_WATER_RATIO_STEEL
     (RATIO_ID,
      STEELCODE,
      STEELNAME,
      CREATE_NAME,
      CREATE_TIME,
      MEMO)
      VALUES (?,?,?,?,SYSDATE,? )
 
		]]>
	</query>
	
	<query id="CoreWaterRatio.DeleteRatioModel" desc="关联查询">
		<![CDATA[	
       DELETE COM_BASE_WATER_RATIO_MODEL
       WHERE RATIO_ID = ?
		]]>
	</query>
	
	<query id="CoreWaterRatio.AddRatio_Model" desc="关联增加">
		<![CDATA[	
     INSERT INTO COM_BASE_WATER_RATIO_MODEL
     (RATIO_ID,
      MODEL_CODE,
      MODEL_DESC,
      CREATE_NAME,
      CREATE_TIME,
      MEMO)
      VALUES (?,?,?,?,SYSDATE,? )
 
		]]>
	</query>
	
	<query id="CoreWaterRatio.Query" desc="标准查询">
		<![CDATA[	
SELECT 'FALSE' CHK,
       T.RATIO_ID,
       T.STD_CODE,
       T.STD_NAME,
       T.SIZE_MIN_SIGN,
       T.SIZE_MIN,
       T.SIZE_MAX_SIGN,
       T.SIZE_MAX,
       T.RATIO_STD,
       T.RATIO_REPLACE,
       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.MAX_PRESS,
       T.STD_STYLE,
       T.STD_STYLE_DESC,
       T.STD_CODE_NK
  FROM COM_BASE_WATER_RATIO T
 WHERE DECODE(?, NULL, '1', T.STD_CODE) = DECODE(?, NULL, '1', ?)
   AND VALIDFLAG IN ('1', ?)
   AND (NVL(T.STD_STYLE_DESC, '1') = NVL(?, '1') OR ? = '1')
   AND (DECODE(?, NULL, '1', T.STD_CODE_NK) = NVL(?, '1') OR T.STD_CODE_NK IS NULL)
		]]>
	</query>
	
	 <query id="CoreWaterRatio.Add" desc="标准新增">
		<![CDATA[	
         INSERT INTO COM_BASE_WATER_RATIO
      (
      RATIO_ID,
      STD_CODE,
      STD_NAME,
      SIZE_MIN_SIGN,
      SIZE_MIN,
      SIZE_MAX_SIGN,
      SIZE_MAX,
      RATIO_STD,
      RATIO_REPLACE,
      CREATE_NAME,
      CREATE_TIME,
      MEMO,
      MAX_PRESS,
      STD_STYLE,
      STD_STYLE_DESC,
      STD_CODE_NK
      )
      VALUES  (?,?,?,?,?,?,?,?,?,?,SYSDATE,?, ?,?,?, ?)
		]]>
	</query>
	   
     <query id="CoreWaterRatio.Update" desc="标准修改">
	 <![CDATA[	
     UPDATE COM_BASE_WATER_RATIO
     SET RATIO_ID     = ?,
        STD_CODE      = ?,
        STD_NAME      = ?,
        SIZE_MIN_SIGN = ?,
        SIZE_MIN      = ?,
        SIZE_MAX_SIGN = ?,
        SIZE_MAX      = ?,
        RATIO_STD     = ?,
        RATIO_REPLACE = ?,
        UPDATE_NAME   = ?,
        UPDATE_TIME   = SYSDATE,
        MEMO          = ?,
        MAX_PRESS = ?,
        STD_STYLE= ?,
        STD_STYLE_DESC=?,
        STD_CODE_NK = ?
     WHERE RATIO_ID = ? AND VALIDFLAG='1'
 
		]]>
	</query>
	
	 <query id="CoreWaterRatio.DELETE" desc="删除">
	 <![CDATA[	
     UPDATE COM_BASE_WATER_RATIO
     SET  
        DELETE_NAME   = ?,
        DELETE_TIME   = SYSDATE,
        VALIDFLAG     = '0'
     WHERE RATIO_ID = ? AND VALIDFLAG='1'
 
		]]>
	</query>
	
	 <query id="CoreWaterRatio.Resume" desc="恢复">
	 <![CDATA[	
     UPDATE COM_BASE_WATER_RATIO
     SET  
        DELETE_NAME   = '',
        DELETE_TIME   = '',
        VALIDFLAG     = '1'
     WHERE RATIO_ID = ? AND VALIDFLAG='0'
 
		]]>
	</query>
	
	 <query id="CoreWaterRatio.IsRefrenced" desc="要增加的标准是否被引用">
	 <![CDATA[	
     SELECT 1
     FROM COM_BASE_WATER_RATIO_STD T
     WHERE STD_CODE_C= ?  
     AND (STD_STYLE_C = ? OR STD_STYLE_C IS NULL)
 
		]]>
	</query>
	
	 <query id="CoreWaterRatio.IsReapt" desc="要增加的标准是否被引用">
	 <![CDATA[	
         SELECT RATIO_ID
     FROM COM_BASE_WATER_RATIO
     WHERE STD_CODE = ?
     AND '&'||STD_STYLE =  '&'||?
     AND '&'||SIZE_MIN_SIGN =  '&'||?
     AND '&'||SIZE_MIN =  '&'||?
     AND '&'||SIZE_MAX_SIGN =  '&'||?
     AND '&'||SIZE_MAX  =  '&'||?
     AND RATIO_STD =  ?
     AND MAX_PRESS =  ?
     AND VALIDFLAG = '1'

		]]>
	</query>
	
	 <query id="CoreWaterRatio.IsReaptUpdate" desc="要增加的标准是否被引用">
	 <![CDATA[	
         SELECT RATIO_ID
     FROM COM_BASE_WATER_RATIO
     WHERE STD_CODE = ?
     AND '&'||STD_STYLE =  '&'||?
     AND '&'||SIZE_MIN_SIGN =  '&'||?
     AND '&'||SIZE_MIN =  '&'||?
     AND '&'||SIZE_MAX_SIGN =  '&'||?
     AND '&'||SIZE_MAX  =  '&'||?
     AND RATIO_STD =  ?
     AND MAX_PRESS =  ?
     AND RATIO_ID  != ?
     AND VALIDFLAG = '1'
		]]>
	</query>
	
	 <query id="CoreWaterRatio.IsReaptResume" desc="要增加的标准是否被引用">
	 <![CDATA[	
         SELECT RATIO_ID
     FROM COM_BASE_WATER_RATIO
     WHERE STD_CODE = ?
     AND '&'||STD_STYLE =  '&'||?
     AND '&'||SIZE_MIN_SIGN =  '&'||?
     AND '&'||SIZE_MIN =  '&'||?
     AND '&'||SIZE_MAX_SIGN =  '&'||?
     AND '&'||SIZE_MAX  =  '&'||?
     AND RATIO_STD =  ?
     AND MAX_PRESS =  ?
     AND RATIO_ID  != ?
     AND VALIDFLAG = '1'
		]]>
	</query>
	
	 <query id="CoreWaterRatio.IsReaptDelete" desc="要作废的标准是否被引用">
	 <![CDATA[	
         SELECT 1
     FROM COM_BASE_WATER_RATIO_STD
     WHERE STD_CODE = (SELECT STD_CODE FROM COM_BASE_WATER_RATIO WHERE RATIO_ID = ? AND VALIDFLAG = '1')
     AND STD_STYLE  = (SELECT STD_STYLE FROM COM_BASE_WATER_RATIO WHERE RATIO_ID = ? AND VALIDFLAG = '1')
    
		]]>
	</query>
	   
	<query id="CoreWaterRatio.getSetRatio" desc="获取设定的水压系数">
	 <![CDATA[	
SELECT T.RATIO_ID FROM CRAFT_ORD_DESIGN_STD_WIC_S T
		]]>
	</query>
	
	<query id="CoreWaterRatio.insertCraftRatio" desc="设定水压系数">
	 <![CDATA[	
INSERT INTO CRAFT_ORD_DESIGN_STD_WIC_S
  (ORD_LN_PK, RATIO_ID)
VALUES
  ({0}, {1})
		]]>
	</query>
	
	<query id="CoreWaterRatio.deleteCraftRatio" desc="删除设定的水压系数">
	 <![CDATA[	
DELETE FROM CRAFT_ORD_DESIGN_STD_WIC_S T WHERE T.ORD_LN_PK = {0}
		]]>
	</query>
	
	<query id="CoreWaterRatio.getMatchRatioId" desc="获取匹配的水压主键">
	 <![CDATA[	
SELECT A.RATIO_ID
  FROM COM_BASE_WATER_RATIO A
  JOIN COM_BASE_WATER_RATIO_MODEL B
    ON A.RATIO_ID = B.RATIO_ID
  JOIN COM_BASE_WATER_RATIO_STEEL C
    ON A.RATIO_ID = C.RATIO_ID, SLM_ORDER_LINE D
 WHERE D.ORD_LN_PK = {0}
   AND B.MODEL_CODE = D.MODEL_CODE
   AND A.STD_CODE = D.STD_CODE
   AND C.STEELCODE = D.STEELCODE
   AND NVL(A.STD_STYLE, '1') = NVL(D.STD_STYLE, '1')
   AND A.VALIDFLAG = 1
   AND B.VALIDFLAG = 1
   AND C.VALIDFLAG = 1
   AND COMPARE_VALUE(D.DIMATER, A.SIZE_MIN_SIGN, A.SIZE_MIN) = 1
   AND COMPARE_VALUE(D.DIMATER, A.SIZE_MAX_SIGN, A.SIZE_MAX) = 1
UNION ALL
SELECT A.RATIO_ID
  FROM COM_BASE_WATER_RATIO A
  JOIN COM_BASE_WATER_RATIO_MODEL B
    ON A.RATIO_ID = B.RATIO_ID
  JOIN COM_BASE_WATER_RATIO_STEEL C
    ON A.RATIO_ID = C.RATIO_ID, COM_MSC_BL D
 WHERE D.PSC_BL = {0}
   AND B.MODEL_CODE = D.MODEL_CODE
   AND A.STD_CODE = D.STD_CODE
   AND C.STEELCODE = D.STEELCODE
   AND NVL(A.STD_STYLE, '1') = NVL(D.STD_STYLE, '1')
   AND A.VALIDFLAG = 1
   AND B.VALIDFLAG = 1
   AND C.VALIDFLAG = 1
   AND COMPARE_VALUE(D.MIN_D, A.SIZE_MIN_SIGN, A.SIZE_MIN) = 1
   AND COMPARE_VALUE(D.MIN_D, A.SIZE_MAX_SIGN, A.SIZE_MAX) = 1
		]]>
	</query>
	
	<query id="CoreWaterRatio.getMatchRatioIdFrm" desc="查询条件获取匹配的水压系数主键">
	 <![CDATA[	
SELECT T.RATIO_ID
  FROM COM_BASE_WATER_RATIO T
 WHERE DECODE({0}, NULL, '1', T.STD_NAME) = NVL({0}, '1')
   AND (COMPARE_VALUE({1}, T.SIZE_MIN_SIGN, T.SIZE_MIN) = 1 OR {1} IS NULL)
   AND (COMPARE_VALUE({1}, T.SIZE_MAX_SIGN, T.SIZE_MAX) = 1 OR {1} IS NULL)
   AND (NVL(T.STD_STYLE_DESC, '1') = NVL({2}, '1') OR {2} = '1')
   AND (EXISTS (SELECT 1
           FROM COM_BASE_WATER_RATIO_MODEL A
          WHERE A.RATIO_ID = T.RATIO_ID
            AND A.MODEL_DESC = {3}) OR {3} IS NULL)
   AND (EXISTS (SELECT 1
           FROM COM_BASE_WATER_RATIO_STEEL B
          WHERE B.RATIO_ID = T.RATIO_ID
            AND B.STEELNAME = {4}) OR {4} IS NULL)
		]]>
	</query>
	
	<query id="CoreWaterRatio.existsWaterRatio" desc="查询条件获取匹配的水压系数主键">
	 <![CDATA[	
SELECT T.RATIO_ID
  FROM COM_BASE_WATER_RATIO T
 WHERE T.STD_CODE = {0}
   AND NVL(T.STD_STYLE, 'A') = NVL({1}, 'A')
   AND NVL(T.SIZE_MIN_SIGN, 'A') = NVL({2}, 'A')
   AND NVL(TO_NUMBER(T.SIZE_MIN), -1) = NVL(TO_NUMBER({3}), -1)
   AND NVL(T.SIZE_MAX_SIGN, 'A') = NVL({4}, 'A')
   AND NVL(TO_NUMBER(T.SIZE_MAX), -1) = NVL(TO_NUMBER({5}), -1)
   AND T.RATIO_STD = {6}
   AND T.MAX_PRESS = {7}
   AND T.RATIO_ID <> {8}
   AND T.STD_CODE_NK= {9}
   AND (EXISTS (SELECT 1
                  FROM COM_BASE_WATER_RATIO_STEEL A
                 WHERE A.RATIO_ID = T.RATIO_ID
                   AND A.STEELCODE IN (#STEELCODE#)
                   AND A.VALIDFLAG = '1') AND EXISTS
        (SELECT 1
           FROM COM_BASE_WATER_RATIO_MODEL B
          WHERE B.RATIO_ID = T.RATIO_ID
            AND B.MODEL_CODE IN (#MODEL_CODE#)
            AND B.VALIDFLAG = '1'))
		]]>
	</query>
	
	<query id="CoreWaterRatio.copyRatioByStd" desc="复制标准对应的水压系数">
	 <![CDATA[	
DECLARE
  P_RATIO_ID COM_BASE_WATER_RATIO.RATIO_ID%TYPE;
BEGIN
  FOR V_ROW IN (SELECT *
                  FROM COM_BASE_WATER_RATIO A
                 WHERE A.STD_CODE = {0}
                   AND A.VALIDFLAG = '1') LOOP
    SELECT MAX(T.RATIO_ID) + 1 INTO P_RATIO_ID FROM COM_BASE_WATER_RATIO T;
    INSERT INTO COM_BASE_WATER_RATIO
      (RATIO_ID,
       STD_CODE,
       STD_NAME,
       SIZE_MIN_SIGN,
       SIZE_MIN,
       SIZE_MAX_SIGN,
       SIZE_MAX,
       RATIO_STD,
       RATIO_REPLACE,
       CREATE_NAME,
       CREATE_TIME,
       UPDATE_NAME,
       UPDATE_TIME,
       DELETE_NAME,
       DELETE_TIME,
       VALIDFLAG,
       MEMO,
       MAX_PRESS,
       STD_STYLE,
       STD_STYLE_DESC,
       STD_CODE_NK)
    VALUES
      (P_RATIO_ID,
       {1},
       {2},
       V_ROW.SIZE_MIN_SIGN,
       V_ROW.SIZE_MIN,
       V_ROW.SIZE_MAX_SIGN,
       V_ROW.SIZE_MAX,
       V_ROW.RATIO_STD,
       V_ROW.RATIO_REPLACE,
       V_ROW.CREATE_NAME,
       V_ROW.CREATE_TIME,
       V_ROW.UPDATE_NAME,
       V_ROW.UPDATE_TIME,
       V_ROW.DELETE_NAME,
       V_ROW.DELETE_TIME,
       V_ROW.VALIDFLAG,
       '复制' || V_ROW.STD_NAME,
       V_ROW.MAX_PRESS,
       V_ROW.STD_STYLE,
       V_ROW.STD_STYLE_DESC,
       V_ROW.STD_CODE_NK);
  
    FOR V_MODEL IN (SELECT *
                      FROM COM_BASE_WATER_RATIO_MODEL B
                     WHERE B.RATIO_ID = V_ROW.RATIO_ID
                       AND B.VALIDFLAG = '1') LOOP
      INSERT INTO COM_BASE_WATER_RATIO_MODEL
        (RATIO_ID,
         MODEL_CODE,
         MODEL_DESC,
         CREATE_NAME,
         CREATE_TIME,
         UPDATE_NAME,
         UPDATE_TIME,
         DELETE_NAME,
         DELETE_TIME,
         VALIDFLAG,
         MEMO)
      VALUES
        (P_RATIO_ID,
         V_MODEL.MODEL_CODE,
         V_MODEL.MODEL_DESC,
         V_MODEL.CREATE_NAME,
         V_MODEL.CREATE_TIME,
         V_MODEL.UPDATE_NAME,
         V_MODEL.UPDATE_TIME,
         V_MODEL.DELETE_NAME,
         V_MODEL.DELETE_TIME,
         V_MODEL.VALIDFLAG,
         V_MODEL.MEMO);
    END LOOP;
  
    FOR V_STEEL IN (SELECT *
                      FROM COM_BASE_WATER_RATIO_STEEL C
                     WHERE C.RATIO_ID = V_ROW.RATIO_ID
                       AND C.VALIDFLAG = '1'
                       AND EXISTS(SELECT 1 FROM COM_PSC T WHERE T.STD_CODE = {1} AND T.VALIDFLAG = '1'
                       AND T.STEELCODE = C.STEELCODE)) LOOP
      INSERT INTO COM_BASE_WATER_RATIO_STEEL
        (RATIO_ID,
         STEELCODE,
         STEELNAME,
         CREATE_NAME,
         CREATE_TIME,
         UPDATE_NAME,
         UPDATE_TIME,
         DELETE_NAME,
         DELETE_TIME,
         VALIDFLAG,
         MEMO)
      VALUES
        (P_RATIO_ID,
         V_STEEL.STEELCODE,
         V_STEEL.STEELNAME,
         V_STEEL.CREATE_NAME,
         V_STEEL.CREATE_TIME,
         V_STEEL.UPDATE_NAME,
         V_STEEL.UPDATE_TIME,
         V_STEEL.DELETE_NAME,
         V_STEEL.DELETE_TIME,
         V_STEEL.VALIDFLAG,
         V_STEEL.MEMO);
    END LOOP;
  END LOOP;
END;
		]]>
	</query>
</queryMap>