| 
					
				 | 
			
			
				@@ -1,37 +1,47 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-package com.skyversation.poiaddr.addquery; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+package com.skyversation.poiaddr.service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.alibaba.fastjson.JSONArray; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.alibaba.fastjson.JSONObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.skyversation.poiaddr.addquery.AddressQueryEngine; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.skyversation.poiaddr.addquery.AddressTools; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.skyversation.poiaddr.addquery.Constant; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.skyversation.poiaddr.addquery.TransfromDataTool; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.skyversation.poiaddr.bean.AddressResult; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.skyversation.poiaddr.bean.GeoJsonBean; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.skyversation.poiaddr.util.address_spliter.SplitAddress; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.skyversation.poiaddr.service.AreaService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.skyversation.poiaddr.util.CoordTransform2; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.skyversation.poiaddr.util.address_spliter.ShanghaiAddressSplitUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.skyversation.poiaddr.util.jpa.entity.TAddressCallback; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.skyversation.poiaddr.util.jpa.entity.YyszAddressQp; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.skyversation.poiaddr.util.jpa.rep.TAddressCallbackRep; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.skyversation.poiaddr.util.jpa.rep.YyszAddressQpRep; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.skyversation.poiaddr.bean.TAddressCallback; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.skyversation.poiaddr.bean.YyszAddressQp; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.skyversation.poiaddr.repository.TAddressCallbackRep; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.skyversation.poiaddr.repository.YyszAddressQpRep; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.skyversation.poiaddr.util.net.AddressNetTools; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.skyversation.poiaddr.util.status.AddressLevel; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.skyversation.poiaddr.util.status.AddressResultEnum; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import lombok.Getter; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.data.domain.Page; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.data.domain.PageRequest; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.http.ResponseEntity; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.stereotype.Service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.transaction.PlatformTransactionManager; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.transaction.TransactionStatus; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.transaction.support.TransactionCallbackWithoutResult; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.transaction.support.TransactionTemplate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.util.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import javax.annotation.Resource; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.time.Instant; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.HashMap; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.List; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.Map; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.util.concurrent.ExecutorService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.util.concurrent.Executors; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.util.regex.Matcher; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.util.regex.Pattern; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 @Service 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-public class DataCallBack { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private DataCallBack(){}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+public class DataCallBackService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private DataCallBackService(){}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Getter 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private static final DataCallBack instance = new DataCallBack(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private static final DataCallBackService instance = new DataCallBackService(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private final ExecutorService successES = Executors.newSingleThreadExecutor(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private final ExecutorService failES = Executors.newSingleThreadExecutor(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Resource 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -40,6 +50,8 @@ public class DataCallBack { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private YyszAddressQpRep yyszAddressQpRep; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Resource 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private ShanghaiAddressSplitUtil shanghaiAddressSplitUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Resource 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private AddressQueryEngine addressQueryEngine; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Resource 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private PlatformTransactionManager transactionManager; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -57,6 +69,9 @@ public class DataCallBack { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         CHINESE_TO_ARABIC.put("第九", "09"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 成功数据入库 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public void successDataCallBack(AddressResult addressResult){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         for (AddressResult.ContentBean bean :addressResult.getData()){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             successES.execute(() -> { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -153,6 +168,10 @@ public class DataCallBack { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 失败数据入库 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public void failDataCallBack(List<String> addr){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         for (String addrStr:addr){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             failES.execute(()->{ 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -165,11 +184,46 @@ public class DataCallBack { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 int id = tAddressCallbackRep.findMaxId().orElse(0)+1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 TAddressCallback tAddressCallback = new TAddressCallback(id, Instant.now(),addrStr, splitAddress.getAddr(), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         splitAddress.getProvince(),splitAddress.getCity(),splitAddress.getStreet(), splitAddress.getCommunity(), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        (short) 0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        (short) 0, (short) 0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 tAddressCallbackRep.save(tAddressCallback); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 System.out.println("回流成功,等待进一检查处理"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 用于将失败数据调高德接口回流 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void dbFailDataCallBackTask(){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        int pageNum = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        int pageSize = 1000; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Page<String> page; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        do { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            page = tAddressCallbackRep.findAllInNative(PageRequest.of(pageNum,pageSize )); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            pageNum++; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            for (String tAddressCallback : page.getContent()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                transactionTemplate.execute(new TransactionCallbackWithoutResult() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    protected void doInTransactionWithoutResult(TransactionStatus status) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            System.out.println("尝试从szx接口获取地址:" + tAddressCallback); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            AddressResult addressResult = addressQueryEngine.gdV3MultiSearch(Collections.singletonList(tAddressCallback),AddressLevel.LEVEL_1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            if (addressResult ==null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                System.out.println("无结果:" + tAddressCallback); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                tAddressCallbackRep.updateAllProcessStatus(tAddressCallback,1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            }else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                System.out.println("有结果,回流:" + tAddressCallback); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                tAddressCallbackRep.updateAllProcessStatus(tAddressCallback,2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                successDataCallBack(addressResult); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            status.setRollbackOnly(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } while (page.hasNext()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |