|
@@ -1,12 +1,9 @@
|
|
|
package com.ruoyi.demo.utils;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
-
|
|
|
-import com.ruoyi.common.utils.redis.RedisUtils;
|
|
|
import com.ruoyi.demo.constant.RedisContant;
|
|
|
import com.ruoyi.demo.entity.WdInfo;
|
|
|
import com.ruoyi.demo.mapper.WdInfoDao;
|
|
|
-import com.ruoyi.demo.service.WriteService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
import org.springframework.data.geo.Distance;
|
|
@@ -18,11 +15,9 @@ import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.HashMap;
|
|
|
+import java.util.Hashtable;
|
|
|
import java.util.List;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
-import java.util.concurrent.ExecutionException;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -34,18 +29,26 @@ public class WdRedisStoreage {
|
|
|
@Autowired
|
|
|
public WdInfoDao wdInfoDao;
|
|
|
|
|
|
-
|
|
|
@Autowired
|
|
|
- WriteService writeService;
|
|
|
+ @Qualifier("executor")
|
|
|
+ private ExecutorService executorService;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //@Autowired
|
|
|
+ //WriteService writeService;
|
|
|
|
|
|
|
|
|
/***
|
|
|
- * +
|
|
|
+ * 获取中心网点的周边标签
|
|
|
* @param wdInfo 中心网点信息
|
|
|
* @return
|
|
|
*/
|
|
|
public List<String> getWdTag(WdInfo wdInfo){
|
|
|
List<String> tag = (List<String>) redisTemplate.boundValueOps(RedisContant.WD_TAG+"_"+wdInfo.getWdId()).get();
|
|
|
+ System.out.println(RedisContant.WD_TAG+"_"+wdInfo.getWdId());
|
|
|
+ System.out.println(tag);
|
|
|
return tag;
|
|
|
}
|
|
|
|
|
@@ -54,67 +57,61 @@ public class WdRedisStoreage {
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
-// /***
|
|
|
-// * 分析网点周边标签,并把分析结果存入redis(默认范围:1km)
|
|
|
-// * @param wdInfo 中心网点信息
|
|
|
-// * @return
|
|
|
-// */
|
|
|
-// public List<String> wdTagAnalyse(WdInfo wdInfo){
|
|
|
-// //1. 找到距离中心网点半径1km的所有网点Id
|
|
|
-// Distance distance = new Distance(1, RedisGeoCommands.DistanceUnit.KILOMETERS);
|
|
|
-// GeoResults<RedisGeoCommands.GeoLocation<Object>> radius = redisTemplate.boundGeoOps(wdInfo.getAddrCode().substring(0, 4)).radius(wdInfo.getWdId(), distance);
|
|
|
-// List<GeoResult<RedisGeoCommands.GeoLocation<Object>>> content = radius.getContent();
|
|
|
-// List<String> aroundWdId = content.stream().map(item -> {
|
|
|
-// String name = (String) item.getContent().getName();
|
|
|
-// return name;
|
|
|
-// }).collect(Collectors.toList());
|
|
|
-//
|
|
|
-// //2. 查询周边网点标签的Set集
|
|
|
-// QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
|
|
|
-// queryWrapper.select("type_name_by")
|
|
|
-// .in("wd_id",aroundWdId)
|
|
|
-// .groupBy("type_name_by");
|
|
|
-// List<WdInfo> wdInfos = wdInfoDao.selectList(queryWrapper);
|
|
|
-//
|
|
|
-// //3. 打标签
|
|
|
-// List<String> tag = new ArrayList<>();
|
|
|
-// wdInfos.stream().forEach(item -> {
|
|
|
-// if(item != null){
|
|
|
-// String typeNameBy = item.getTypeNameBy();
|
|
|
-// if(typeNameBy != null && !typeNameBy.equals("")){
|
|
|
-// String[] split = typeNameBy.split(":");
|
|
|
-// if (split.length > 0)
|
|
|
-// tag.add(split[split.length-1]);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// });
|
|
|
-// redisTemplate.boundValueOps(RedisContant.WD_TAG+"_"+wdInfo.getWdId()).set(tag);
|
|
|
-// return tag;
|
|
|
-// }
|
|
|
-//
|
|
|
-// /**
|
|
|
-// * 将网点数据库 导入 redis
|
|
|
-// * */
|
|
|
-// public void writeWdGeoRedis(){
|
|
|
-// //清重
|
|
|
-// clearSql2();
|
|
|
-// try {
|
|
|
-// Thread.sleep(1000*60*10);
|
|
|
-// } catch (InterruptedException e) {
|
|
|
-// throw new RuntimeException(e);
|
|
|
-// }
|
|
|
-//
|
|
|
-// //将所有网点坐标导入redis
|
|
|
-// writeWdGeoRedis1();
|
|
|
-//
|
|
|
-// try {
|
|
|
-// Thread.sleep(1000*60*10);
|
|
|
-// } catch (InterruptedException e) {
|
|
|
-// throw new RuntimeException(e);
|
|
|
-// }
|
|
|
-// //给网点打标签并存入redis中
|
|
|
-// writeWdGeoRedis2();
|
|
|
-// }
|
|
|
+ /***
|
|
|
+ * 分析网点周边标签,并把分析结果存入redis(默认范围:1km)
|
|
|
+ * @param wdInfo 中心网点信息
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<String> wdTagAnalyse(WdInfo wdInfo){
|
|
|
+ //1. 找到距离中心网点半径1km的所有网点Id
|
|
|
+ Distance distance = new Distance(1, RedisGeoCommands.DistanceUnit.KILOMETERS);
|
|
|
+ GeoResults<RedisGeoCommands.GeoLocation<Object>> radius = redisTemplate.boundGeoOps(wdInfo.getAddrCode().substring(0, 4)).radius(wdInfo.getWdId(), distance);
|
|
|
+ List<GeoResult<RedisGeoCommands.GeoLocation<Object>>> content = radius.getContent();
|
|
|
+ List<String> aroundWdId = content.stream().map(item -> {
|
|
|
+ String name = (String) item.getContent().getName();
|
|
|
+ return name;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ //2. 查询周边网点标签的Set集
|
|
|
+ QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.select("type_name_by")
|
|
|
+ .in("wd_id",aroundWdId)
|
|
|
+ .groupBy("type_name_by");
|
|
|
+ List<WdInfo> wdInfos = wdInfoDao.selectList(queryWrapper);
|
|
|
+ //释放内存
|
|
|
+ aroundWdId = null;
|
|
|
+ aroundWdId = null;
|
|
|
+
|
|
|
+ //3. 打标签
|
|
|
+ List<String> tag = new ArrayList<>();
|
|
|
+ wdInfos.stream().forEach(item -> {
|
|
|
+ if(item != null){
|
|
|
+ String typeNameBy = item.getTypeNameBy();
|
|
|
+ if(typeNameBy != null && !typeNameBy.equals("")){
|
|
|
+ String[] split = typeNameBy.split(":");
|
|
|
+ if (split.length > 0)
|
|
|
+ tag.add(split[split.length-1]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ redisTemplate.boundValueOps(RedisContant.WD_TAG+"_"+wdInfo.getWdId()).set(tag);
|
|
|
+
|
|
|
+ return tag;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将网点数据库 导入 redis
|
|
|
+ * */
|
|
|
+ public void writeWdGeoRedis(){
|
|
|
+ //清重
|
|
|
+ //clearSql2();
|
|
|
+
|
|
|
+ //将所有网点坐标导入redis
|
|
|
+ //writeWdGeoRedis1("2023-09-25");
|
|
|
+
|
|
|
+ //给网点打标签并存入redis中
|
|
|
+ //writeWdGeoRedis2();
|
|
|
+ }
|
|
|
//
|
|
|
// public void clearSql2(){
|
|
|
// List<String> wdId = new ArrayList<>();
|
|
@@ -142,6 +139,7 @@ public class WdRedisStoreage {
|
|
|
// hashMap1.put("total",1);
|
|
|
// CompletableFuture<Void> future = null;
|
|
|
// for (String s : hashMap.keySet()) {
|
|
|
+// FutureTask
|
|
|
// future = CompletableFuture.runAsync(()->{
|
|
|
// synchronized (this){
|
|
|
// if(hashMap1.get("total")%1000 == 0){
|
|
@@ -199,65 +197,61 @@ public class WdRedisStoreage {
|
|
|
//
|
|
|
//
|
|
|
// }
|
|
|
-//
|
|
|
-// private void writeWdGeoRedis1(){
|
|
|
-// //1.将网点坐标存入redis中
|
|
|
-// long start = System.currentTimeMillis();
|
|
|
-// System.out.println("开始将网点坐标存入redis");
|
|
|
-// 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) {
|
|
|
-// //开启线程
|
|
|
-// 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);
|
|
|
-// }
|
|
|
-// long end = System.currentTimeMillis();
|
|
|
-// System.out.println("完成存入 "+(end-start)/(1000*60));
|
|
|
-// }
|
|
|
-//
|
|
|
-// private void writeWdGeoRedis2(){
|
|
|
-// //2.对所有网点坐标进行分析打标签
|
|
|
-// long start = System.currentTimeMillis();
|
|
|
-// System.out.println("开始打标签");
|
|
|
-// 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) {
|
|
|
-// //开启线程
|
|
|
-// 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);
|
|
|
-// }
|
|
|
-// long end = System.currentTimeMillis();
|
|
|
-// System.out.println("完成打标签 "+(end-start)/(1000*60));
|
|
|
-// }
|
|
|
+
|
|
|
+ public void writeWdGeoRedis1(String time) throws Exception{
|
|
|
+ //1.将网点坐标存入redis中
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
+ System.out.println("开始将网点坐标存入redis");
|
|
|
+ QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.select("wd_id","addr_code","lng","lat");
|
|
|
+ queryWrapper.ge("collect_time",time);
|
|
|
+
|
|
|
+ Hashtable<String,Integer> hashtable = new Hashtable<>();
|
|
|
+ hashtable.put("total",0);
|
|
|
+ List<CompletableFuture<Void>> completableFutureList = new ArrayList<>();
|
|
|
+ List<WdInfo> wdInfos = wdInfoDao.selectList(queryWrapper);
|
|
|
+ for (WdInfo wdInfo : wdInfos) {
|
|
|
+ //开启线程
|
|
|
+ completableFutureList.add(CompletableFuture.runAsync(()->{
|
|
|
+ redisTemplate.boundGeoOps(wdInfo.getAddrCode().substring(0,4)).add(new Point(wdInfo.getLng().doubleValue(),wdInfo.getLat().doubleValue()),wdInfo.getWdId());
|
|
|
+ wdTagAnalyse(wdInfo);
|
|
|
+ System.out.println("进度:"+wdInfos.size()+"/"+hashtable.get("total"));
|
|
|
+ hashtable.put("total",hashtable.get("total")+1);
|
|
|
+ },executorService));
|
|
|
+ }
|
|
|
+ CompletableFuture.allOf(completableFutureList.toArray(new CompletableFuture[0])).join();
|
|
|
+ long end = System.currentTimeMillis();
|
|
|
+ System.out.println("完成存入 "+(end-start)/(1000*60));
|
|
|
+ }
|
|
|
+
|
|
|
+ public void writeWdGeoRedis2(String[] wdTypeCodes){
|
|
|
+ //对所有网点坐标进行分析打标签
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
+ System.out.println("开始打标签");
|
|
|
+
|
|
|
+ //开始
|
|
|
+ QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.select("wd_id","addr_code");
|
|
|
+ queryWrapper.in("wd_type_code", wdTypeCodes);
|
|
|
+ List<WdInfo> wdInfos = wdInfoDao.selectList(queryWrapper);
|
|
|
+
|
|
|
+ ArrayList<CompletableFuture<Void>> list = new ArrayList<>();
|
|
|
+ Hashtable<String,Integer> hashtable = new Hashtable<>();
|
|
|
+ hashtable.put("total",1);
|
|
|
+ for (WdInfo wdInfo : wdInfos) {
|
|
|
+ //开启线程
|
|
|
+ CompletableFuture<Void> future = CompletableFuture.runAsync(()->{
|
|
|
+ wdTagAnalyse(wdInfo);
|
|
|
+ System.out.println("进度:"+wdInfos.size()+"/"+hashtable.get("total"));
|
|
|
+ hashtable.put("total",hashtable.get("total")+1);
|
|
|
+ },executorService);
|
|
|
+ list.add(future);
|
|
|
+ }
|
|
|
+ CompletableFuture.allOf(list.toArray(new CompletableFuture[list.size()])).join();
|
|
|
+ long end = System.currentTimeMillis();
|
|
|
+ System.out.println("完成打标签 "+(end-start)/(1000*60));
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
|
|
|
}
|