<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="行政区域的编码信息管理"> 
	<query id="CoreRegion.GetRegionTree" desc="查询树形结构">
		<![CDATA[
			SELECT   sel.region_no, st.region_type_nm || '  ' || sel.region_nm region_nm,
			         sel.p_region_no, st.region_lvl_no,
			         (SELECT region_nm
			            FROM sel_admin_region
			           WHERE region_no = sel.p_region_no) region_lvl_nm
			    FROM (select * from sel_admin_region where VALIDFLAG='1') sel LEFT JOIN sel_admin_region_t st
			         ON sel.region_type = st.region_type_no 
                ORDER BY region_no
		]]>
	</query> 
	<query id="CoreRegion.GetRegIonCode" desc="查询区域属性">
		<![CDATA[
			SELECT region_type_nm, region_type_no
				   FROM sel_admin_region_t
				   WHERE region_lvl_no = ?  and VALIDFLAG = '1'  
		]]>
	</query> 
	<query id="CoreRegion.GetRegIonCodeNo" desc="过滤区域属性">
		<![CDATA[
			SELECT tz.region_type_nm, tz.region_type_no
				  FROM sel_admin_region_t tz
				 WHERE LENGTH (tz.region_type_no) > (SELECT LENGTH (region_type)
				                                       FROM sel_admin_region
				                                      WHERE region_no = ?)  and VALIDFLAG = '1'  
		]]>
	</query> 
	<query id="CoreRegion.GetRegIonCodeS" desc="查询所有区域属性">
		<![CDATA[
			SELECT   region_type_nm, region_type_no
				    FROM sel_admin_region_t
				    where  VALIDFLAG = '1'  
				ORDER BY region_type_no
		]]>
	</query> 
	<query id="CoreRegion.GetSelAdminRegion" desc="查询上级区域属性">
		<![CDATA[
			SELECT   region_nm, region_no
				     FROM sel_admin_region 
				     where VALIDFLAG = '1'  
					 ORDER BY region_no
		]]>
	</query> 
	<!--  	<query id="CoreRegion.GetSelAdminRegionFilter" desc="查询上级+本级区域属性">
	SELECT   region_nm, region_no
				     FROM sel_admin_region
				   WHERE region_no IN (
				            SELECT p_region_no
				              FROM sel_admin_region
				             WHERE region_no = ?
				            UNION ALL
				            SELECT p_region_no
				              FROM sel_admin_region
				             WHERE region_no IN (SELECT p_region_no
				                                   FROM sel_admin_region
				                                  WHERE region_no = ?)
				            UNION ALL
				            SELECT REGION_NO
				              FROM sel_admin_region
				             WHERE region_no = ?)
				     AND validflag = '1'
				ORDER BY region_no  -->
	<query id="CoreRegion.GetSelAdminRegionFilter" desc="查询本级区域属性">
		<![CDATA[
			SELECT   region_nm, region_no
				     FROM sel_admin_region
				   WHERE region_no IN ( 
				            SELECT REGION_NO
				              FROM sel_admin_region
				             WHERE region_no = ?)
				     AND validflag = '1'
				ORDER BY region_no
		]]>
	</query> 
	<query id="CoreRegion.doQueryRegIonCode" desc="单击树形查询Grid">
		<![CDATA[
			 SELECT region_no, region_nm, p_region_no,
		       (SELECT region_nm
		          FROM sel_admin_region
		         WHERE region_no = sel.p_region_no) p_region_nm,
		       (SELECT region_type_nm
		          FROM sel_admin_region_t
		         WHERE region_type_no = sel.region_type) region_type_nm,
		       (SELECT region_type_no
		          FROM sel_admin_region_t
		         WHERE region_type_no = sel.region_type) region_type_no,
		       (SELECT region_lvl_no
		          FROM sel_admin_region_t
		         WHERE region_type_no = sel.region_type) region_lvl_no, memo,
		       validflag, create_name, (SELECT MAX (basename)
		                                  FROM com_base_info
		                                 WHERE BASECODE = sel.bigarea) bigarea,
		       TO_CHAR (create_time, 'yyyy-mm-dd hh24:mi:ss') create_time,
		       update_name, TO_CHAR (update_time,
		                             'yyyy-mm-dd hh24:mi:ss') update_time,
		       delete_name, TO_CHAR (delete_time,
		                             'yyyy-mm-dd hh24:mi:ss') delete_time
		  FROM sel_admin_region sel
				WHERE p_region_no = ? and  VALIDFLAG = '1'  order by create_time desc
		]]>
	</query> 
	<query id="CoreRegion.doQuery" desc="查询所有Grid">
		<![CDATA[
			SELECT region_no, region_nm, p_region_no,
		       (SELECT region_nm
		          FROM sel_admin_region
		         WHERE region_no = sel.p_region_no) p_region_nm,
		       (SELECT region_type_nm
		          FROM sel_admin_region_t
		         WHERE region_type_no = sel.region_type) region_type_nm,
		       (SELECT region_type_no
		          FROM sel_admin_region_t
		         WHERE region_type_no = sel.region_type) region_type_no,
		       (SELECT region_lvl_no
		          FROM sel_admin_region_t
		         WHERE region_type_no = sel.region_type) region_lvl_no, memo,
		       validflag, create_name, (SELECT MAX (basename)
		                                  FROM com_base_info
		                                 WHERE BASECODE = sel.bigarea) bigarea,
		       TO_CHAR (create_time, 'yyyy-mm-dd hh24:mi:ss') create_time,
		       update_name, TO_CHAR (update_time,
		                             'yyyy-mm-dd hh24:mi:ss') update_time,
		       delete_name, TO_CHAR (delete_time,
		                             'yyyy-mm-dd hh24:mi:ss') delete_time
		  FROM sel_admin_region sel where  VALIDFLAG = '1'   order by create_time desc
		]]>
	</query> 
	<query id="CoreRegion.saveQuery" desc="查询区域名称是否存在">
		<![CDATA[
			 SELECT REGION_NO,VALIDFLAG FROM SEL_ADMIN_REGION WHERE REGION_NM = ? AND P_REGION_NO = ?
		]]>
	</query> 
	
	<query id="CoreRegion.saveQueryName" desc="查询区域名称是否存在">
		<![CDATA[
			 SELECT REGION_NO,VALIDFLAG,BIGAREA  FROM SEL_ADMIN_REGION WHERE REGION_NM = ? 
		]]>
	</query> 

	<query id="CoreRegion.toAdd" desc="新增">
		<![CDATA[
		INSERT INTO sel_admin_region
            (region_no,
             region_nm, p_region_no, region_type,
             region_seq,
             memo, create_name,BIGAREA, create_time
            )
     VALUES ((SELECT DECODE (MAX (region_no),
                             '', ? || '01',
                             MAX (region_no) + 1
                            )
                FROM sel_admin_region
               WHERE p_region_no = ?),
             ?, ?, ?,
             (SELECT DECODE (MAX (region_seq), '', '1', MAX (region_seq) + 1)
                FROM sel_admin_region
               WHERE p_region_no = ?),
             ?, ?,?, SYSDATE
            )
		]]>
	</query> 
	<query id="CoreRegion.toDlete" desc="删除">
		<![CDATA[
			update sel_admin_region set VALIDFLAG = ?,DELETE_NAME=?,DELETE_TIME=sysdate where REGION_NO = ?
		]]>
	</query>  
	<query id="CoreRegion.doResume" desc="恢复">
		<![CDATA[
			update sel_admin_region set VALIDFLAG = ? where REGION_NO = ?
		]]>
	</query>  
	<query id="CoreRegion.toUpdate" desc="更新">
		<![CDATA[
			UPDATE sel_admin_region
				   SET region_nm = ?,
				       region_type = ?,
				       memo = ?,
				       UPDATE_NAME = ?,
				       BIGAREA = ?,
				       P_REGION_NO = ?,
				       UPDATE_TIME = sysdate
				   WHERE region_no = ?
		]]>
	</query> 
</queryMap>