<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="客户信息管理">
	<query id="CoreBuyerBase.doQueryCustomer" desc="根据客户名称查询客户编码">
		<![CDATA[
			 SELECT customer_no FROM slm_base_customer WHERE customer_nm = ? 
		]]>
	</query>
	<query id="CoreBuyerBase.doQueryReceivUnit" desc="根据客户ID查询收货单位是否存在">
		<![CDATA[
			 SELECT CUSTOMER_NO from SLM_BASE_RECEIV_UNIT where CUSTOMER_NO = ?   and SALE_ORG = ?
		]]>
	</query>
	<query id="CoreBuyerBase.doQueryAbrviTion" desc="根据客户简称查询是否存在">
		<![CDATA[
			 SELECT ABRVITION from slm_base_customer where ABRVITION = ? 
		]]>
	</query>
	<query id="CoreBuyerBase.doQueryOrderUnit" desc="根据客户ID查询订货单位是否存在">
		<![CDATA[
			  SELECT CUSTOMER_NO from SLM_BASE_ORDER_UNIT where CUSTOMER_NO = ?  and SALE_ORG = ?
		]]>
	</query>
	<query id="CoreBuyerBase.doQueryCustm_Use" desc="根据客户用途ID查询订货单位是否存在">
		<![CDATA[
			 SELECT CUSTOMER_NO from SLM_BASE_CUSTM_USE where CUSTOMER_NO = ?  and CUSTM_USE = ? AND  SALE_ORG = ?
		]]>
	</query>
	<query id="CoreBuyerBase.SetUpCustm_Use" desc="根据客户用途ID查询订货单位是否存在">
		<![CDATA[
			UPDATE SLM_BASE_CUSTM_USE SET validflag = '1' where CUSTOMER_NO = ?  and CUSTM_USE = ? AND  SALE_ORG = ?
		]]>
	</query>
	<query id="CoreBuyerBase.doInsertCustomer" desc="新增客户编码">
		<![CDATA[
			INSERT INTO SLM_BASE_CUSTOMER
			  (CUSTOMER_NO,
			   CUSTOMER_NM,
			   BIGAREA,
			   REGION_NO,
			   ABRVITION,
			   ORG,
			   CREATE_NAME,
			   PY,
			   MARKET_SYS,
			   USER_GRP,
			   CREATE_TIME)
			VALUES
			  ((SELECT ? || LPAD(nvl(MAX(SUBSTR(CUSTOMER_NO, length(?) + 1)), 0) + 1,
			                 10 - length(?),
			                 '0')
			    FROM SLM_BASE_CUSTOMER
			   WHERE substr(CUSTOMER_NO,1,length(?)) = ?),
			   ?,
			   ?,
			   ?,
			   ?,
			   ?,
			   ?,
			   ?,
			   ?,
			   ?,
			   SYSDATE)
		]]>
	</query>
	<query id="CoreBuyerBase.doInsertCustmRight" desc="新增客户授权">
		<![CDATA[
			INSERT INTO slm_base_custm_right
		            (customer_no, sale_org, memo, create_name, create_time
		            )
		     	   VALUES (?, ?, ?, ?, sysdate
		            )	
            ]]>
	</query>
	<query id="CoreBuyerBase.doInsertCustmUse" desc="新增客户用途类型">
		<![CDATA[
			INSERT INTO slm_base_custm_use
			            (customer_no, sale_org, custm_use, create_name, create_time
			            )
					    VALUES (?, ?, ?, ?, sysdate
					            )	
            ]]>
	</query>
	<query id="CoreBuyerBase.doUpdateCustomer" desc="修改客户编码信息">
		<![CDATA[
			UPDATE slm_base_customer
				   SET customer_nm = ?,
				       bigarea = ?,
				       region_no = ?,
				       abrvition = ?,
				       org = ?,
				       create_name = ?,
				       py = ?,
				       MARKET_SYS = ?,
				       USER_GRP = ?,
				       UPDATE_NAME = ?,
				       UPDATE_TIME = SYSDATE 
				 WHERE customer_no = ?
            ]]>
	</query>
	<query id="CoreBuyerBase.doUpdateCustomerALLS" desc="删除客户主表编码信息">
		<![CDATA[ 
		   UPDATE slm_base_customer
		      SET validflag = ?,
		          DELETE_NAME = ?,
		          DELETE_TIME = sysdate          
		    WHERE customer_no = ? 
            ]]>
	</query>
	<query id="CoreBuyerBase.doUpdateRightALL" desc="删除客户授权编码信息">
		<![CDATA[  
		   UPDATE slm_base_custm_right
		      SET validflag = ?
		    WHERE customer_no = ? AND sale_org = ?
            ]]>
	</query>
	<query id="CoreBuyerBase.doUpdateUseALL" desc="删除客户用途类型信息">
		<![CDATA[  
		   UPDATE slm_base_custm_use
		      SET validflag = ?
		    WHERE customer_no = ? AND sale_org = ?
            ]]>
	</query>
	<query id="CoreBuyerBase.doDeleteUseALL" desc="删除客户用途类型信息">
		<![CDATA[  
		   DELETE slm_base_custm_use
		    WHERE customer_no = ? AND CUSTM_USE = ?
            ]]>
	</query>
	<query id="CoreBuyerBase.doUpdateReceivUnitALL" desc="删除客户收货单位信息">
		<![CDATA[  
		   UPDATE slm_base_receiv_unit
		      SET validflag = ?
		    WHERE customer_no = ? AND sale_org = ?
            ]]>
	</query>
	<query id="CoreBuyerBase.doUpdateOrderUnitALL" desc="删除客户订结算信息">
		<![CDATA[  
		    UPDATE slm_base_order_unit
		      SET validflag = ?
		    WHERE customer_no = ? AND sale_org = ?
            ]]>
	</query>
	<query id="CoreBuyerBase.doUpdateFreightALL" desc="删除客户订结算货运地址信息">
		<![CDATA[  
		    UPDATE slm_base_custm_freight
		      SET validflag = ?
		    WHERE customer_no = ?
            ]]>
	</query>
	<query id="CoreBuyerBase.doUpdateReceivUnit" desc="收货客户编码信息">
		<![CDATA[  
		   UPDATE slm_base_receiv_unit
		      SET validflag = ?
		    WHERE customer_no = ? AND sale_org = ? AND CUSTM_USE = ?
            ]]>
	</query>
	<query id="CoreBuyerBase.doUpdateOrderUnit" desc="订结客户编码信息">
		<![CDATA[  
		   UPDATE SLM_BASE_ORDER_UNIT
		      SET validflag = ?
		    WHERE customer_no = ? AND sale_org = ? AND CUSTM_USE = ?
            ]]>
	</query>
	<query id="CoreBuyerBase.doUpdateUse" desc="客户用途类型信息">
		<![CDATA[  
		   UPDATE slm_base_custm_use
		      SET validflag = ?
		    WHERE customer_no = ? AND sale_org = ? AND CUSTM_USE = ?
            ]]>
	</query>
	<query id="CoreBuyerBase.doQueryCTMR" desc="">
		<![CDATA[  
		    SELECT customer_no FROM slm_base_customer
		     WHERE customer_nm = ? AND validflag = '0'
            ]]>
	</query>
	<query id="CoreBuyerBase.doUpdateDeleteCTMR" desc="恢复删除数据">
		<![CDATA[
			UPDATE slm_base_customer
				   SET user_grp = ?,
				       bigarea = ?,
				       region_no = ?,
				       abrvition = ?,
				       org = ?,
				       create_name = ?,
				       py = ?,
				       market_sys = ?,
				       validflag = ?,
				       create_time = SYSDATE
				 WHERE customer_no = ? AND validflag = '0'
            ]]>
	</query>
<query id="CoreBuyerBase.doQueyPubuleCustomer" desc="查询订结或者收货电话邮编等公用属性">
		<![CDATA[
SELECT NVL2(A.PHONE, A.PHONE, B.PHONE) PHONE,
       NVL2(A.FAX, A.FAX, B.FAX) FAX,
       NVL2(A.ZIP_CODE, A.ZIP_CODE, B.ZIP_CODE) ZIP_CODE,
       NVL2(A.AGENT, A.AGENT, B.CONSIGNEE) CONSIGNEE,
       NVL2(A.ADDRESS, A.ADDRESS, B.ADDRESS) ADDRESS,
       Q.CUSTOMER_NM
  FROM SLM_BASE_CUSTOMER Q
  LEFT JOIN SLM_BASE_ORDER_UNIT A
    ON A.CUSTOMER_NO = Q.CUSTOMER_NO
   AND A.SALE_ORG = '#SALE_ORG#'
  LEFT JOIN SLM_BASE_RECEIV_UNIT B
    ON B.CUSTOMER_NO = Q.CUSTOMER_NO
   AND B.SALE_ORG = '#SALE_ORG#'
 WHERE Q.CUSTOMER_NO = '#CUSTOMER_NO#'
            ]]>
	</query>
</queryMap>