<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="客户信息维护重生版">
	 
	<query id="CoreCustomerReborn.queryBaseInfo" desc="查询客户信息">
		<![CDATA[  
		SELECT BASECODE,BASENAME FROM COM_BASE_INFO WHERE SORTCODE = ? AND VALIDFLAG='1' ORDER BY BASECODE
        ]]>
	</query>
	
	<query id="CoreCustomerReborn.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,
       SEL.BIGAREA
       FROM SEL_ADMIN_REGION SEL
       LEFT JOIN SEL_ADMIN_REGION_T ST
       ON SEL.REGION_TYPE = ST.REGION_TYPE_NO
       ORDER BY REGION_NO

		]]>
	</query> 
	
	<query id="CoreCustomerReborn.queryCustomerInfo" desc="查询树形结构">
		<![CDATA[
		SELECT DISTINCT T.CUSTOMER_NO,
                T.CUSTOMER_NM,
                T.BIGAREA,
                T.REGION_NO,
                (SELECT BASENAME
                   FROM COM_BASE_INFO B
                  WHERE B.BASECODE = T.BIGAREA) BIGAREADESC,
                (SELECT REGION_NM
                   from sel_admin_region A
                  where A.REGION_NO = T.region_no) REGION_NM,
                T.USER_GRP,
                T.MARKET_SYS,
                T.ABRVITION,
                T.ORG,
                T.PY,
                DECODE(T.VALIDFLAG, '1', '有效', '无效') VALIDFLAG,
                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,
                T.CUSTOMER_NO_OLD
        FROM SLM_BASE_CUSTOMER T,
        SLM_BASE_CUSTM_RIGHT A
   WHERE UPPER(T.CUSTOMER_NM) LIKE '%' || ? || '%'
   AND T.CUSTOMER_NO = A.CUSTOMER_NO
   AND T.VALIDFLAG = '1'
   AND A.VALIDFLAG = '1'

		]]>
	</query> 
	
	<query id="CoreCustomerReborn.queryCustomerOrderUnit" desc="查询客户货运地址信息">
		<![CDATA[  
		  
		 SELECT T.CUSTOMER_NO,
       T.CHN_FL,
       (SELECT BASENAME FROM COM_BASE_INFO A WHERE A.BASECODE = T.CUSTM_CTGRY) CUSTM_CTGRY,
       (SELECT BASENAME FROM COM_BASE_INFO A WHERE A.BASECODE = T.CUSTM_PRPTY) CUSTM_PRPTY,
       (SELECT BASENAME FROM COM_BASE_INFO A WHERE A.BASECODE = T.CUSTM_LVL) CUSTM_LVL,
       T.LEGAL_PSN,
       T.AGENT,
       T.ADDRESS,
       T.BIGAREA,
       T.REGION_NO,
       T.ZIP_CODE,
       T.BANK,
       T.ACCOUNT,
       T.TAX_ID,
       T.PHONE,
       T.FAX,
       T.CUSTM_DATA,
       T.MEMO,
       DECODE(T.VALIDFLAG, '1', '有效', '无效') VALIDFLAG,
       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
  FROM SLM_BASE_ORDER_UNIT T
 WHERE T.CUSTOMER_NO = ?   AND  T.VALIDFLAG = '1'
		     
        ]]>
	</query>
	
	<query id="CoreCustomerReborn.queryCustomerReceiveUnit" desc="查询客户货运地址信息">
		<![CDATA[  
		  
	 SELECT T.CUSTOMER_NO,
       T.REGION_NO,
       T.ADDRESS,
       T.CONSIGNEE,
       T.PHONE,
       T.ZIP_CODE,
       T.FAX,
       T.MEMO,
       DECODE(T.VALIDFLAG, '1', '有效', '无效') VALIDFLAG,
       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
  FROM SLM_BASE_RECEIV_UNIT T 
  WHERE T.CUSTOMER_NO = ? AND  T.VALIDFLAG = '1'
	     
        ]]>
	</query>
	
   <query id="CoreCustomerReborn.validateCustomerNm" desc="查询客户货运地址信息">
		<![CDATA[  
		  SELECT T.CUSTOMER_NO FROM SLM_BASE_CUSTOMER T
		  WHERE T.CUSTOMER_NM = ?
		  AND T.VALIDFLAG = '1'
		    
        ]]>
	</query>

	<query id="CoreCustomerReborn.validateCustomerNmAndOrg" desc="查询客户货运地址信息">
		<![CDATA[
		  SELECT T.CUSTOMER_NM FROM SLM_BASE_CUSTOMER T
		  LEFT JOIN SLM_BASE_CUSTM_USE T1 ON T.CUSTOMER_NO = T1.CUSTOMER_NO
		  WHERE T.CUSTOMER_NM = ?  AND T1.SALE_ORG = ?
		  AND T.VALIDFLAG = '1'

        ]]>
	</query>
	
	<query id="CoreCustomerReborn.generateCustomerCode" desc="查询客户货运地址信息">
		<![CDATA[  
		  
		  SELECT ? || LPAD(nvl(MAX(SUBSTR(CUSTOMER_NO, length(?) + 1)), 0) + 1,
			                 10 - length(?),
			                 '0')
			    FROM SLM_BASE_CUSTOMER
			   WHERE substr(CUSTOMER_NO,1,length(?)) = ?
		    
        ]]>
	</query>
	
	<query id="CoreCustomerReborn.InsertCustomer" desc="新增客户编码">
		<![CDATA[
			 INSERT INTO SLM_BASE_CUSTOMER
  (CUSTOMER_NO,
   CUSTOMER_NM,
   BIGAREA,
   REGION_NO,
   USER_GRP,
   MARKET_SYS,
   ABRVITION,
   ORG,
   PY,
   CREATE_NAME,
   CREATE_TIME)
  VALUES
  ('#CUSTOMER_NO#',
   '#CUSTOMER_NM#',
   '#BIGAREA#',
   '#REGION_NO#',
   '#USER_GRP#',
   '#MARKET_SYS#',
   '#ABRVITION#',
   '#ORG#',
   '#PY#',
   '#CREATE_NAME#',
   SYSDATE)
			 
		]]>
	</query>
	
	<query id="CoreCustomerReborn.clearExistsSaleOrg" desc="查询客户定结算信息">
		<![CDATA[  
		     DELETE FROM  SLM_BASE_CUSTM_RIGHT T
		     WHERE  T.CUSTOMER_NO = ? 
		     AND T.SALE_ORG IN (?,?,?)
		     
        ]]>
	</query>
	
	<query id="CoreCustomerReborn.impowerSaleOrg" desc="查询客户定结算信息">
		<![CDATA[  
	  INSERT INTO SLM_BASE_CUSTM_RIGHT
     (CUSTOMER_NO, SALE_ORG, CREATE_NAME, CREATE_TIME)
     VALUES
     (?, ?, ?, SYSDATE)
		     
        ]]>
	</query>
	
	<query id="CoreCustomerReborn.queryCustomerUse" desc="新增客户定结算信息">
		<![CDATA[  
		    SELECT 1 FROM  SLM_BASE_CUSTM_USE T
		    WHERE T.CUSTOMER_NO = ?
		    AND   T.SALE_ORG = ?
		    AND T.CUSTM_USE = ?
		    AND T.VALIDFLAG = '1'
        ]]>
	</query>
	
	<query id="CoreCustomerReborn.insertCustomerUse" desc="新增客户定结算信息">
		<![CDATA[  
		  INSERT INTO SLM_BASE_CUSTM_USE
      (CUSTOMER_NO, SALE_ORG, CUSTM_USE, CREATE_NAME, CREATE_TIME)
       VALUES
       (?, ?, ?, ?, SYSDATE)
		     
        ]]>
	</query>
	
	<query id="CoreCustomerReborn.UpdateCustomer" desc="修改客户信息">
		<![CDATA[  
		 UPDATE SLM_BASE_CUSTOMER T
   SET T.CUSTOMER_NM = '#CUSTOMER_NM#',
       T.BIGAREA     = '#BIGAREA#',
       T.REGION_NO   = '#REGION_NO#',
       T.USER_GRP    = '#USER_GRP#',
       T.MARKET_SYS  = '#MARKET_SYS#',
       T.ABRVITION   = '#ABRVITION#',
       T.ORG         = '#ORG#',
       T.PY          = '#PY#',
       T.UPDATE_NAME = '#UPDATE_NAME#',
       T.UPDATE_TIME = SYSDATE
   WHERE T.CUSTOMER_NO = '#CUSTOMER_NO#'
		     
        ]]>
	</query>
	
	<query id="CoreCustomerReborn.InsertCustomerOrderUnit" desc="新增客户编码">
		<![CDATA[
	 			INSERT INTO SLM_BASE_ORDER_UNIT
  (CUSTOMER_NO,
   CHN_FL,
   CUSTM_CTGRY,
   CUSTM_PRPTY,
   CUSTM_LVL,
   LEGAL_PSN,
   AGENT,
   ADDRESS,
   BIGAREA,
   REGION_NO,
   ZIP_CODE,
   BANK,
   ACCOUNT,
   TAX_ID,
   PHONE,
   FAX,
   CUSTM_DATA,
   MEMO,
   CREATE_NAME,
   CREATE_TIME)
   VALUES
  ('#CUSTOMER_NO#',
   '#CHN_FL#',
   '#CUSTM_CTGRY#',
   '#CUSTM_PRPTY#',
   '#CUSTM_LVL#',
   '#LEGAL_PSN#',
   '#AGENT#',
   '#ADDRESS#',
   '#BIGAREA#',
   '#REGION_NO#',
   '#ZIP_CODE#',
   '#BANK#',
   '#ACCOUNT#',
   '#TAX_ID#',
   '#PHONE#',
   '#FAX#',
   '#CUSTM_DATA#',
   '#MEMO#',
   '#CREATE_NAME#',
   SYSDATE)
	 				 
		]]>
	</query>
	
	<query id="CoreCustomerReborn.UpdateCustomerOrderUnit" desc="修改客户信息">
		<![CDATA[  
 			UPDATE SLM_BASE_ORDER_UNIT T
   SET T.CUSTM_CTGRY = '#CUSTM_CTGRY#',
       T.CUSTM_PRPTY = '#CUSTM_PRPTY#',
       T.CUSTM_LVL   = '#CUSTM_LVL#',
       T.LEGAL_PSN   = '#LEGAL_PSN#',
       T.AGENT       = '#AGENT#',
       T.ADDRESS     = '#ADDRESS#',
       T.BIGAREA     = '#BIGAREA#',
       T.REGION_NO   = '#REGION_NO#',
       T.ZIP_CODE    = '#ZIP_CODE#',
       T.BANK        = '#BANK#',
       T.ACCOUNT     = '#ACCOUNT#',
       T.TAX_ID      = '#TAX_ID#',
       T.PHONE       = '#PHONE#',
       T.FAX         = '#FAX#',
       T.CUSTM_DATA  = '#CUSTM_DATA#',
       T.MEMO        = '#MEMO#',
       T.UPDATE_NAME = '#UPDATE_NAME#',
       T.UPDATE_TIME = SYSDATE
 WHERE T.CUSTOMER_NO = '#CUSTOMER_NO#'
 			  
        ]]>
	</query>
	
	<query id="CoreCustomerReborn.InsertCustomerReceiveUnit" desc="新增客户从数据信息_货运地址">
	 <![CDATA[  
			  INSERT INTO SLM_BASE_RECEIV_UNIT(
        CUSTOMER_NO,
        REGION_NO,
        ADDRESS,
        CONSIGNEE,
        PHONE,
        ZIP_CODE,
        FAX,
        MEMO,
        CREATE_NAME,
        CREATE_TIME)
       VALUES( 
        '#CUSTOMER_NO#',
        '#REGION_NO#',
        '#ADDRESS#',
        '#CONSIGNEE#',
        '#PHONE#',
        '#ZIP_CODE#',
        '#FAX#',
        '#MEMO#',
        '#CREATE_NAME#',
        SYSDATE)
            ]]>
	</query>
	
	<query id="CoreCustomerReborn.UpdateCustomerReceiveUnit" desc="新增客户从数据信息_货运地址">
	 <![CDATA[  
			 UPDATE SLM_BASE_RECEIV_UNIT T
   SET T.ADDRESS     = '#ADDRESS#',
       T.CONSIGNEE   = '#CONSIGNEE#',
       T.PHONE       = '#PHONE#',
       T.ZIP_CODE    = '#ZIP_CODE#',
       T.FAX         = '#FAX#',
       T.MEMO        = '#MEMO#',
       T.UPDATE_NAME = '#UPDATE_NAME#',
       T.UPDATE_TIME = SYSDATE
 WHERE T.CUSTOMER_NO = '#CUSTOMER_NO#'
			 
            ]]>
	</query>
 
	<query id="CoreCustomerReborn.queryCustomerOrderCount" desc="查询到站信息">
		<![CDATA[  
		 SELECT 1 FROM SLM_BASE_ORDER_UNIT T
		 WHERE T.CUSTOMER_NO = ? 
		 AND T.VALIDFLAG = '1'
		 
         ]]>
	</query>
	
	<query id="CoreCustomerReborn.queryCustomerReceiveCount" desc="查询到站信息">
		<![CDATA[  
		 SELECT 1 FROM SLM_BASE_RECEIV_UNIT T
		 WHERE T.CUSTOMER_NO = ? 
		 AND T.VALIDFLAG = '1'
		 
         ]]>
	</query>
	
	<query id="CoreCustomerReborn.deleteCustomerBaseInfo" desc="查询到站信息">
		<![CDATA[  
		     UPDATE  SLM_BASE_CUSTOMER  T
		     SET T.DELETE_NAME = ?,
		         T.DELETE_TIME = SYSDATE,
		         T.VALIDFLAG = '0'
		     WHERE T.CUSTOMER_NO = ?
		     AND T.VALIDFLAG = '1'
		 
         ]]>
	</query>
	
	<query id="CoreCustomerReborn.deleteCustomerOrderUnit" desc="查询到站信息">
		<![CDATA[  
		  DELETE FROM   SLM_BASE_ORDER_UNIT  T
		  WHERE T.CUSTOMER_NO = ?
		     AND T.VALIDFLAG = '1'
		 
         ]]>
	</query>
	
	<query id="CoreCustomerReborn.deleteCustomerReceiveUnit" desc="查询到站信息">
		<![CDATA[  
		 
		 DELETE FROM   SLM_BASE_RECEIV_UNIT  T
		     WHERE T.CUSTOMER_NO = ?
		     AND T.VALIDFLAG = '1'
         ]]>
	</query>
	
	<query id="CoreCustomerReborn.deleteCustomerUseAll" desc="查询到站信息">
		<![CDATA[  
		 
		    DELETE FROM  SLM_BASE_CUSTM_USE  T
		    WHERE  T.CUSTOMER_NO = ?
		    
         ]]>
	</query>
	
	<query id="CoreCustomerReborn.deleteCustomerUse" desc="查询到站信息">
		<![CDATA[  
		 
		    DELETE FROM  SLM_BASE_CUSTM_USE T
		    WHERE  T.CUSTOMER_NO = ?
		    AND  T.CUSTM_USE = ?
         ]]>
	</query>
	
	<query id="CoreCustomerReborn.queryCustomerList" desc="查询到站信息">
		<![CDATA[  
		SELECT DISTINCT A.CUSTOMER_NO,
                A.CUSTOMER_NM,
                (SELECT BASENAME
                   FROM COM_BASE_INFO D
                  WHERE D.BASECODE = A.BIGAREA) BIGAREA,
                (SELECT REGION_NM
                   FROM SEL_ADMIN_REGION E
                  WHERE E.REGION_NO = A.REGION_NO) REGION_NO,
                A.USER_GRP,
                A.MARKET_SYS,
                A.ABRVITION,
                A.ORG,
                A.PY,
                DECODE(A.VALIDFLAG, '1', '有效', '无效') VALIDFLAG,
                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,
                A.CUSTOMER_NO_OLD,
                B.CHN_FL,
                (SELECT BASENAME
                   FROM COM_BASE_INFO D
                  WHERE D.BASECODE = B.CUSTM_CTGRY) CUSTM_CTGRY,
                (SELECT BASENAME
                   FROM COM_BASE_INFO D
                  WHERE D.BASECODE = B.CUSTM_PRPTY) CUSTM_PRPTY,
                (SELECT BASENAME
                   FROM COM_BASE_INFO D
                  WHERE D.BASECODE = B.CUSTM_LVL) CUSTM_LVL,
                B.LEGAL_PSN,
                B.AGENT,
                B.ADDRESS,
                B.ZIP_CODE,
                B.BANK,
                B.ACCOUNT,
                B.TAX_ID,
                B.PHONE,
                B.FAX,
                B.CUSTM_DATA,
                C.ADDRESS READDRESS,
                C.CONSIGNEE,
                C.PHONE REPHONE,
                C.ZIP_CODE REZIP_CODE,
                C.FAX REFAX

  FROM SLM_BASE_CUSTOMER    A,
       SLM_BASE_ORDER_UNIT  B,
       SLM_BASE_RECEIV_UNIT C,
       SLM_BASE_CUSTM_RIGHT D
 WHERE A.CUSTOMER_NO = B.CUSTOMER_NO(+)
   AND A.CUSTOMER_NO = C.CUSTOMER_NO(+)
   AND A.CUSTOMER_NO = D.CUSTOMER_NO
   AND UPPER(A.CUSTOMER_NM) LIKE '%' || ? || '%'
   AND A.VALIDFLAG = '1'

         ]]>
	</query>
	 
	 
 
</queryMap>
