<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="权限功能表查询">
	
	<query id="CoreSaleRegion.GetSaleRegion" desc="获取销售组织数据源">
		<![CDATA[
			SELECT BASECODE,BASENAME FROM COM_BASE_INFO WHERE SORTCODE='1001' ORDER BY BASECODE
		]]>
	</query>
	
	<query id="CoreSaleRegion.GetMaxCode" desc="获取销售组织业务片区代码最大值">
		<![CDATA[
			SELECT MAX(SALE_AREA_NO) FROM SLM_BASE_SALE_AREA_TYP WHERE SALE_ORG=?
		]]>
	</query>
	
	<query id="CoreSaleRegion.GetDEPARTNAME" desc="获取销售组织科室名称">
		<![CDATA[
			SELECT DEPARTNAME,DEPARTID FROM CORE.CORE_APP_DEPARTMENT WHERE PID = ?
		]]>
	</query>

	<query id="CoreSaleRegion.GetDepartNameLike" desc="获取销售组织科室名称">
		<![CDATA[
			SELECT DEPARTNAME,DEPARTID FROM CORE.CORE_APP_DEPARTMENT WHERE PID like ?||'%' order by DEPARTID
		]]>
	</query>
	
	<query id="CoreSaleRegion.isRepeatName" desc="判断名称是否存在">
		<![CDATA[
			SELECT SALE_AREA_DESC FROM SLM_BASE_SALE_AREA_TYP WHERE SALE_AREA_DESC=? AND SALE_ORG=? AND DEPARTID = ?
		]]>
	</query>
	<query id="CoreSaleRegion.QUERY" desc="权限功能">
		<![CDATA[
			SELECT   A.SALE_ORG, A.DEPARTID, (SELECT NVL(MAX(DEPARTNAME),' ')
			                                   FROM CORE.CORE_APP_DEPARTMENT
			                                  WHERE DEPARTID = A.DEPARTID) DEPARTNAME,
			       B.BASENAME SALE_ORG_DESC, A.SALE_AREA_NO, A.SALE_AREA_DESC, A.MEMO,
			       A.VALIDFLAG, DECODE (A.VALIDFLAG,
			                            '1', '有效',
			                            '无效'
			                           ) VALIDFLAGNAME, A.CREATE_NAME,
			       TO_CHAR (A.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
			       A.UPDATE_NAME,
			       TO_CHAR (A.UPDATE_TIME, 'YYYY-MM-DD HH24:MI:SS') UPDATE_TIME,
			       A.DELETE_NAME,
			       TO_CHAR (A.DELETE_TIME, 'YYYY-MM-DD HH24:MI:SS') DELETE_TIME
					FROM SLM_BASE_SALE_AREA_TYP A,COM_BASE_INFO B
					   WHERE A.SALE_ORG=B.BASECODE AND A.VALIDFLAG IN ('1' , ?)
					   -- AND A.SALE_ORG ||'&' LIKE '%' || ? || '%'
					   ORDER BY SALE_ORG
		]]>
	</query>
	<query id="CoreSaleRegion.ADD" desc="新增">
		<![CDATA[
			 INSERT INTO SLM_BASE_SALE_AREA_TYP
							(SALE_ORG,
						    SALE_AREA_NO,
						    SALE_AREA_DESC,
							MEMO,
							VALIDFLAG,
					        CREATE_NAME,
					        CREATE_TIME,
					        DEPARTID
					        )
							VALUES(?,?,?,?,1,
							?,SYSDATE,?)
							
			  
		]]>
	</query>
	<query id="CoreSaleRegion.UPDATE" desc="修改">
		<![CDATA[
			 UPDATE SLM_BASE_SALE_AREA_TYP SET
							SALE_AREA_DESC=?, 
							MEMO=?, 
							UPDATE_NAME=?, 
							UPDATE_TIME=SYSDATE,
							DEPARTID=?
							WHERE SALE_AREA_NO=?
		]]>
	</query>
	<query id="CoreSaleRegion.DELETE" desc="作废">
		<![CDATA[
			 UPDATE SLM_BASE_SALE_AREA_TYP T
			   SET T.DELETE_NAME = ?, T.DELETE_TIME = SYSDATE, T.VALIDFLAG = '0'
			 WHERE T.SALE_AREA_NO = ?
		]]>
	</query>

	<query id="CoreSaleRegion.RESUME" desc="恢复">
		<![CDATA[
			UPDATE SLM_BASE_SALE_AREA_TYP T
               SET T.DELETE_NAME = '', T.DELETE_TIME = '', T.VALIDFLAG = '1'
             WHERE T.SALE_AREA_NO = ?
		]]>
	</query>
</queryMap>