<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="连浇群组">
	<query id="ComBaseWaterGroupDAL.queryWaterGroup" desc="查询连浇群组">
		<![CDATA[
SELECT T.WATER_GROUP, T.WATER_GROUP_CODE FROM COM_BASE_WATER_GROUP T GROUP BY T.WATER_GROUP, T.WATER_GROUP_CODE
ORDER BY WATER_GROUP
		]]>
	</query>
	
	<query id="ComBaseWaterGroupDAL.queryWaterGroupGrade" desc="查询连浇群组对应的钢种">
		<![CDATA[
SELECT T.GRADENAME,
       T.GRADECODE,
       A.GRADE_INDEX,
       TO_CHAR(A.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
       A.CREATE_NAME,
       A.WATER_GROUP_CODE,
       A.WATER_GROUP_CODE,
       A.WATER_GROUP
  FROM COM_BASE_GRADE T
  LEFT JOIN COM_BASE_WATER_GROUP A
    ON A.WATER_GROUP_CODE = '#WATER_GROUP_CODE#'
   AND A.GRADECODE = T.GRADECODE
 WHERE T.VALIDFLAG = '1'
		]]>
	</query>
	
	<query id="ComBaseWaterGroupDAL.getMaxWaterGroupCode" desc="获取最大的代码">
		<![CDATA[
SELECT LPAD(NVL(MAX(WATER_GROUP_CODE), '0') + 1, 5, '0') MAX_VALUE
             FROM COM_BASE_WATER_GROUP
		]]>
	</query>
	
	<query id="ComBaseWaterGroupDAL.setWaterGroupGrade" desc="新增连浇群组对应钢种">
		<![CDATA[
INSERT INTO COM_BASE_WATER_GROUP
  (WATER_GROUP_CODE,
   WATER_GROUP,
   GRADECODE,
   GRADENAME,
   GRADE_INDEX,
   CREATE_TIME,
   CREATE_NAME)
VALUES
  ('#WATER_GROUP_CODE#',
   '#WATER_GROUP#',
   '#GRADECODE#',
   '#GRADENAME#',
   DECODE('#GRADE_INDEX#', NULL, (SELECT NVL(MAX(GRADE_INDEX), 0) + 1
      FROM COM_BASE_WATER_GROUP T
     WHERE T.WATER_GROUP_CODE = '#WATER_GROUP_CODE#'), '#GRADE_INDEX#'),
   SYSDATE,
   '#CREATE_NAME#')
		]]>
	</query>
	
	<query id="ComBaseWaterGroupDAL.delWaterGroupGrade" desc="删除连浇群组对应钢种">
		<![CDATA[
DELETE COM_BASE_WATER_GROUP T WHERE T.WATER_GROUP_CODE = '#WATER_GROUP_CODE#'
		]]>
	</query>
	
	<query id="ComBaseWaterGroupDAL.getWaterGroupCnt" desc="查询连浇群组名称是否存在">
		<![CDATA[
SELECT COUNT(1)
  FROM COM_BASE_WATER_GROUP T
 WHERE T.WATER_GROUP = '#WATER_GROUP#'
   AND T.WATER_GROUP_CODE <> NVL('#WATER_GROUP_CODE#', '1')
		]]>
	</query>
	
	<query id="ComBaseWaterGroupDAL.getWaterGroupGradeCnt" desc="查询连浇群组钢种组合是否存在">
		<![CDATA[
SELECT *
  FROM (SELECT MAX(T.WATER_GROUP) WATER_GROUP, WATER_GROUP_CODE,
               (SELECT LISTAGG(A.GRADECODE, ',') WITHIN GROUP(ORDER BY A.GRADE_INDEX)
                  FROM COM_BASE_WATER_GROUP A
                 WHERE A.WATER_GROUP_CODE = T.WATER_GROUP_CODE) GRADECODES
          FROM COM_BASE_WATER_GROUP T
         GROUP BY T.WATER_GROUP_CODE) B
 WHERE TO_CHAR(B.GRADECODES) = '#GRADECODES#'
 AND B.WATER_GROUP_CODE <> NVL('#WATER_GROUP_CODE#', '1')
		]]>
	</query>
</queryMap>