|
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.benyun.core.constant.RedisContant;
|
|
|
import com.benyun.core.dao.WdInfoDao;
|
|
|
import com.benyun.core.entity.WdInfo;
|
|
|
+import com.benyun.core.service.WriteService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
import org.springframework.data.geo.Distance;
|
|
@@ -16,6 +17,7 @@ import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.concurrent.ExecutionException;
|
|
@@ -35,13 +37,17 @@ public class WdRedisStoreage {
|
|
|
private ExecutorService executorService;
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
+ WriteService writeService;
|
|
|
+
|
|
|
+
|
|
|
/***
|
|
|
* 获取中心网点的周边标签
|
|
|
* @param wdInfo 中心网点信息
|
|
|
* @return
|
|
|
*/
|
|
|
public List<String> getWdTag(WdInfo wdInfo){
|
|
|
- List<String> tag = (List<String>) redisTemplate.boundHashOps(RedisContant.WD_TAG).get(wdInfo.getWdId());
|
|
|
+ List<String> tag = (List<String>) redisTemplate.boundValueOps(RedisContant.WD_TAG+"_"+wdInfo.getWdId()).get();
|
|
|
if (tag != null)
|
|
|
return tag;
|
|
|
|
|
@@ -84,7 +90,7 @@ public class WdRedisStoreage {
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
- redisTemplate.boundHashOps(RedisContant.WD_TAG).put(wdInfo.getWdId(),tag);
|
|
|
+ redisTemplate.boundValueOps(RedisContant.WD_TAG+"_"+wdInfo.getWdId()).set(tag);
|
|
|
return tag;
|
|
|
}
|
|
|
|
|
@@ -92,29 +98,113 @@ public class WdRedisStoreage {
|
|
|
* 将网点数据库 导入 redis
|
|
|
* */
|
|
|
public void writeWdGeoRedis(){
|
|
|
+ //清重
|
|
|
+ clearSql2();
|
|
|
+
|
|
|
//将所有网点坐标导入redis
|
|
|
- //writeWdGeoRedis1();
|
|
|
+ writeWdGeoRedis1();
|
|
|
|
|
|
//给网点打标签并存入redis中
|
|
|
writeWdGeoRedis2();
|
|
|
}
|
|
|
|
|
|
+ public void clearSql2(){
|
|
|
+ List<String> wdId = new ArrayList<>();
|
|
|
+ List<String> storeId = new ArrayList<>();
|
|
|
+ List<String> houseId = new ArrayList<>();
|
|
|
+ List<String> buildId = new ArrayList<>();
|
|
|
+ List<String> trafficId = new ArrayList<>();
|
|
|
+ List<String> enterpriseId = new ArrayList<>();
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
+
|
|
|
+ try{
|
|
|
+ System.out.println("开始清理");
|
|
|
+
|
|
|
+ QueryWrapper<WdInfo> wdInfoOriginQueryWrapper = new QueryWrapper<>();
|
|
|
+ wdInfoOriginQueryWrapper.select("hash", "count(hash) as audit").groupBy("hash").having("count(hash) >= 2");
|
|
|
+ List<WdInfo> wdInfoOrigins = wdInfoDao.selectList(wdInfoOriginQueryWrapper);
|
|
|
+
|
|
|
+ HashMap<String, Integer> hashMap = new HashMap<>();
|
|
|
+ for (WdInfo wdInfo : wdInfoOrigins) {
|
|
|
+ hashMap.put(wdInfo.getHash(), wdInfo.getAudit());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ HashMap<String,Integer> hashMap1 = new HashMap<>();
|
|
|
+ hashMap1.put("total",1);
|
|
|
+ CompletableFuture<Void> future = null;
|
|
|
+ for (String s : hashMap.keySet()) {
|
|
|
+ future = CompletableFuture.runAsync(()->{
|
|
|
+ QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("hash",s);
|
|
|
+ queryWrapper.orderByDesc("collect_time");
|
|
|
+ queryWrapper.last("limit " + (hashMap.get(s) - 1));
|
|
|
+ List<WdInfo> wdInfos = wdInfoDao.selectList(queryWrapper);
|
|
|
+ for (WdInfo wdInfo : wdInfos) {
|
|
|
+ wdId.add(wdInfo.getWdId());
|
|
|
+
|
|
|
+ switch (wdInfo.getWdTypeCode()){
|
|
|
+ case "1":
|
|
|
+ storeId.add(wdInfo.getWdId());
|
|
|
+ break;
|
|
|
+ case "2":
|
|
|
+ houseId.add(wdInfo.getWdId());
|
|
|
+ break;
|
|
|
+ case "3":
|
|
|
+ buildId.add(wdInfo.getWdId());
|
|
|
+ break;
|
|
|
+ case "4":
|
|
|
+ trafficId.add(wdInfo.getWdId());
|
|
|
+ break;
|
|
|
+ case "5":
|
|
|
+ enterpriseId.add(wdInfo.getWdId());
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ System.out.println("进度:"+wdInfoOrigins.size()+"/"+hashMap1.get("total"));
|
|
|
+ hashMap1.put("total",hashMap1.get("total")+1);
|
|
|
+ },executorService);
|
|
|
+ }
|
|
|
+ future.get();
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }finally {
|
|
|
+ //删除
|
|
|
+ //writeService.clearSql2(wdId,storeId,houseId,buildId,trafficId,enterpriseId);
|
|
|
+ long end = System.currentTimeMillis();
|
|
|
+ System.out.println("完成清理 "+(end-start)/(1000*60));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
private void writeWdGeoRedis1(){
|
|
|
//1.将网点坐标存入redis中
|
|
|
long start = System.currentTimeMillis();
|
|
|
System.out.println("开始将网点坐标存入redis");
|
|
|
- for (WdInfo wdInfo : wdInfoDao.selectList(null)) {
|
|
|
+ QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.likeRight("collect_time","2023-09-");
|
|
|
+
|
|
|
+ HashMap<String,Integer> hashMap = new HashMap<>();
|
|
|
+ hashMap.put("total",1);
|
|
|
+ CompletableFuture<Void> future = null;
|
|
|
+ List<WdInfo> wdInfos = wdInfoDao.selectList(queryWrapper);
|
|
|
+ for (WdInfo wdInfo : wdInfos) {
|
|
|
//开启线程
|
|
|
- CompletableFuture<Void> future = CompletableFuture.runAsync(()->{
|
|
|
+ future = CompletableFuture.runAsync(()->{
|
|
|
redisTemplate.boundGeoOps(wdInfo.getAddrCode().substring(0,4)).add(new Point(wdInfo.getLng().doubleValue(),wdInfo.getLat().doubleValue()),wdInfo.getWdId());
|
|
|
+ System.out.println("进度:"+wdInfos.size()+"/"+hashMap.get("total"));
|
|
|
+ hashMap.put("total",hashMap.get("total")+1);
|
|
|
},executorService);
|
|
|
- try {
|
|
|
- future.get();
|
|
|
- } catch (InterruptedException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- } catch (ExecutionException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- }
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ future.get();
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ } catch (ExecutionException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
}
|
|
|
long end = System.currentTimeMillis();
|
|
|
System.out.println("完成存入 "+(end-start)/(1000*60));
|
|
@@ -127,18 +217,23 @@ public class WdRedisStoreage {
|
|
|
QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
|
|
|
queryWrapper.in("wd_type_code", Arrays.asList("1","2","3","5"));
|
|
|
List<WdInfo> wdInfos = wdInfoDao.selectList(queryWrapper);
|
|
|
+ CompletableFuture<Void> future = null;
|
|
|
+ HashMap<String,Integer> hashMap = new HashMap<>();
|
|
|
+ hashMap.put("total",1);
|
|
|
for (WdInfo wdInfo : wdInfos) {
|
|
|
//开启线程
|
|
|
- CompletableFuture<Void> future = CompletableFuture.runAsync(()->{
|
|
|
+ future = CompletableFuture.runAsync(()->{
|
|
|
wdTagAnalyse(wdInfo);
|
|
|
+ System.out.println("进度:"+wdInfos.size()+"/"+hashMap.get("total"));
|
|
|
+ hashMap.put("total",hashMap.get("total")+1);
|
|
|
},executorService);
|
|
|
- try {
|
|
|
- future.get();
|
|
|
- } catch (InterruptedException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- } catch (ExecutionException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- }
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ future.get();
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ } catch (ExecutionException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
}
|
|
|
long end = System.currentTimeMillis();
|
|
|
System.out.println("完成打标签 "+(end-start)/(1000*60));
|