|
@@ -36,6 +36,7 @@ import org.springframework.web.client.RestTemplate;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
|
import java.util.concurrent.ExecutionException;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -112,7 +113,119 @@ public class ChannelAnalyseServiceImpl implements ChannelAnalyseService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- //TODO 待测试(redis版本)
|
|
|
+ //版本1
|
|
|
+// @Override
|
|
|
+// public HashMap<String, Object> tagAnalyse(ChannelMapAceeptVo channelMapAceeptVo) {
|
|
|
+// //1.根据条件的到位网点信息
|
|
|
+// QueryWrapper<WdInfo> queryWrapper = new QueryWrapper<>();
|
|
|
+// queryWrapper.select("wd_id");
|
|
|
+// assembleQueryWrapper(queryWrapper,channelMapAceeptVo);
|
|
|
+// queryWrapper.and(queryWrapper2 ->{
|
|
|
+// queryWrapper2.eq("show_delete",0);
|
|
|
+// });
|
|
|
+// List<WdInfo> queryWd = wdInfoDao.selectList(queryWrapper);
|
|
|
+//
|
|
|
+// //2.获取周边标签
|
|
|
+// List<String> collect = queryWd.stream().map(item -> {
|
|
|
+// return RedisContant.WD_TAG + "_" + item.getWdId();
|
|
|
+// }).collect(Collectors.toList());
|
|
|
+//
|
|
|
+// //切割获取redis数据
|
|
|
+// int split = 60000;
|
|
|
+// int splitCount = collect.size()/split;
|
|
|
+// int p1 = 0,p2 = split;
|
|
|
+// ArrayList<CompletableFuture<List<List<String>>>> splitList = new ArrayList<>();
|
|
|
+// for (int i=1;i<=splitCount;i++){
|
|
|
+// if (p2 > collect.size())
|
|
|
+// p2 = collect.size();
|
|
|
+// List<String> list2 = collect.subList(p1, p2);
|
|
|
+// CompletableFuture<List<List<String>>> future = CompletableFuture.supplyAsync(()->{
|
|
|
+// return wdRedisStoreage.getWdTagList(list2);
|
|
|
+// },executor);
|
|
|
+// splitList.add(future);
|
|
|
+// p1 = p2;
|
|
|
+// p2+=split;
|
|
|
+// }
|
|
|
+//
|
|
|
+// //3.统计
|
|
|
+// Hashtable<String, Integer> hashtable = new Hashtable<>();
|
|
|
+// hashtable.put("total",0);
|
|
|
+// ArrayList<CompletableFuture<Void>> list1 = new ArrayList<>();
|
|
|
+// for (CompletableFuture<List<List<String>>> listCompletableFuture : splitList) {
|
|
|
+// try {
|
|
|
+// List<List<String>> lists = listCompletableFuture.get();
|
|
|
+// for (List<String> list : lists) {
|
|
|
+// if (list != null && !list.isEmpty()){
|
|
|
+// CompletableFuture<Void> future = CompletableFuture.runAsync(()->{
|
|
|
+// for (String s : list) {
|
|
|
+// s += "边";
|
|
|
+// Integer integer = hashtable.get(s);
|
|
|
+// if (integer == null)
|
|
|
+// hashtable.put(s,1);
|
|
|
+// else
|
|
|
+// hashtable.put(s,integer+1);
|
|
|
+// }
|
|
|
+// hashtable.put("total",hashtable.get("total")+1);
|
|
|
+// },executor);
|
|
|
+// list1.add(future);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// CompletableFuture.allOf(list1.toArray(new CompletableFuture[list1.size()])).join();
|
|
|
+// lists = null;
|
|
|
+// } catch (InterruptedException e) {
|
|
|
+// throw new RuntimeException(e);
|
|
|
+// } catch (ExecutionException e) {
|
|
|
+// throw new RuntimeException(e);
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|
|
|
+//
|
|
|
+// collect = null;
|
|
|
+// queryWd = null;
|
|
|
+//
|
|
|
+//
|
|
|
+// //4.封装统计值
|
|
|
+// HashMap<String, Object> result = new HashMap<>();
|
|
|
+// List<TagAnalyse> list = new ArrayList<>();
|
|
|
+// Integer total = hashtable.get("total");
|
|
|
+// for (String s : hashtable.keySet()) {
|
|
|
+// if (s.equals("total"))
|
|
|
+// continue;
|
|
|
+//
|
|
|
+// TagAnalyse tagAnalyse = new TagAnalyse();
|
|
|
+// tagAnalyse.setName(s);
|
|
|
+// tagAnalyse.setCount(hashtable.get(s));
|
|
|
+// BigDecimal bigDecimal = new BigDecimal((double) tagAnalyse.getCount() / total);
|
|
|
+// double v = bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
|
+// tagAnalyse.setRadio(v);
|
|
|
+// list.add(tagAnalyse);
|
|
|
+// }
|
|
|
+//
|
|
|
+// //5.对结果集进行排序
|
|
|
+// Collections.sort(list, new Comparator<TagAnalyse>() {
|
|
|
+// @Override
|
|
|
+// public int compare(TagAnalyse o1, TagAnalyse o2) {
|
|
|
+// return o2.getCount() - o1.getCount();
|
|
|
+// }
|
|
|
+// });
|
|
|
+//
|
|
|
+//
|
|
|
+// //5.分页返回结果集
|
|
|
+// int i = 1;
|
|
|
+// int start = 0,end = 6;
|
|
|
+// while(start<list.size()){
|
|
|
+// if(end>=list.size())
|
|
|
+// end = list.size();
|
|
|
+// result.put(""+i++,new ArrayList(list.subList(start,end)));
|
|
|
+// start=end;
|
|
|
+// end+=6;
|
|
|
+// }
|
|
|
+// result.put("pages",i-1);
|
|
|
+// result.put("total",total);
|
|
|
+// return result;
|
|
|
+// }
|
|
|
+
|
|
|
+ //版本2
|
|
|
@Override
|
|
|
public HashMap<String, Object> tagAnalyse(ChannelMapAceeptVo channelMapAceeptVo) {
|
|
|
//1.根据条件的到位网点信息
|
|
@@ -128,18 +241,22 @@ public class ChannelAnalyseServiceImpl implements ChannelAnalyseService {
|
|
|
List<String> collect = queryWd.stream().map(item -> {
|
|
|
return RedisContant.WD_TAG + "_" + item.getWdId();
|
|
|
}).collect(Collectors.toList());
|
|
|
+ queryWd = null;
|
|
|
+
|
|
|
+ //切割网点 并 统计分析标签
|
|
|
+ ConcurrentHashMap<String, Integer> concurrentHashMap = new ConcurrentHashMap<>();
|
|
|
+ concurrentHashMap.put("total",0);
|
|
|
|
|
|
- //切割获取redis数据
|
|
|
- int split = 60000;
|
|
|
+ int split = 8000;
|
|
|
int splitCount = collect.size()/split;
|
|
|
int p1 = 0,p2 = split;
|
|
|
- ArrayList<CompletableFuture<List<List<String>>>> splitList = new ArrayList<>();
|
|
|
+ ArrayList<CompletableFuture<Void>> splitList = new ArrayList<>();
|
|
|
for (int i=1;i<=splitCount;i++){
|
|
|
if (p2 > collect.size())
|
|
|
p2 = collect.size();
|
|
|
List<String> list2 = collect.subList(p1, p2);
|
|
|
- CompletableFuture<List<List<String>>> future = CompletableFuture.supplyAsync(()->{
|
|
|
- return wdRedisStoreage.getWdTagList(list2);
|
|
|
+ CompletableFuture<Void> future = CompletableFuture.runAsync(()->{
|
|
|
+ tagAnalyseItem(concurrentHashMap,list2);
|
|
|
},executor);
|
|
|
splitList.add(future);
|
|
|
p1 = p2;
|
|
@@ -147,53 +264,20 @@ public class ChannelAnalyseServiceImpl implements ChannelAnalyseService {
|
|
|
}
|
|
|
|
|
|
//3.统计
|
|
|
- Hashtable<String, Integer> hashtable = new Hashtable<>();
|
|
|
- hashtable.put("total",0);
|
|
|
- ArrayList<CompletableFuture<Void>> list1 = new ArrayList<>();
|
|
|
- for (CompletableFuture<List<List<String>>> listCompletableFuture : splitList) {
|
|
|
- try {
|
|
|
- List<List<String>> lists = listCompletableFuture.get();
|
|
|
- for (List<String> list : lists) {
|
|
|
- if (list != null && !list.isEmpty()){
|
|
|
- CompletableFuture<Void> future = CompletableFuture.runAsync(()->{
|
|
|
- for (String s : list) {
|
|
|
- s += "边";
|
|
|
- Integer integer = hashtable.get(s);
|
|
|
- if (integer == null)
|
|
|
- hashtable.put(s,1);
|
|
|
- else
|
|
|
- hashtable.put(s,integer+1);
|
|
|
- }
|
|
|
- hashtable.put("total",hashtable.get("total")+1);
|
|
|
- },executor);
|
|
|
- list1.add(future);
|
|
|
- }
|
|
|
- }
|
|
|
- CompletableFuture.allOf(list1.toArray(new CompletableFuture[list1.size()])).join();
|
|
|
- lists = null;
|
|
|
- } catch (InterruptedException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- } catch (ExecutionException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- collect = null;
|
|
|
- queryWd = null;
|
|
|
-
|
|
|
+ CompletableFuture.allOf(splitList.toArray(new CompletableFuture[splitList.size()])).join();
|
|
|
+ splitList = null;
|
|
|
|
|
|
//4.封装统计值
|
|
|
HashMap<String, Object> result = new HashMap<>();
|
|
|
List<TagAnalyse> list = new ArrayList<>();
|
|
|
- Integer total = hashtable.get("total");
|
|
|
- for (String s : hashtable.keySet()) {
|
|
|
+ Integer total = concurrentHashMap.get("total");
|
|
|
+ for (String s : concurrentHashMap.keySet()) {
|
|
|
if (s.equals("total"))
|
|
|
continue;
|
|
|
|
|
|
TagAnalyse tagAnalyse = new TagAnalyse();
|
|
|
tagAnalyse.setName(s);
|
|
|
- tagAnalyse.setCount(hashtable.get(s));
|
|
|
+ tagAnalyse.setCount(concurrentHashMap.get(s));
|
|
|
BigDecimal bigDecimal = new BigDecimal((double) tagAnalyse.getCount() / total);
|
|
|
double v = bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
|
tagAnalyse.setRadio(v);
|
|
@@ -211,19 +295,40 @@ public class ChannelAnalyseServiceImpl implements ChannelAnalyseService {
|
|
|
|
|
|
//5.分页返回结果集
|
|
|
int i = 1;
|
|
|
- int start = 0,end = 6;
|
|
|
+ int start = 0,end = channelMapAceeptVo.getPageSize();
|
|
|
while(start<list.size()){
|
|
|
if(end>=list.size())
|
|
|
end = list.size();
|
|
|
result.put(""+i++,new ArrayList(list.subList(start,end)));
|
|
|
start=end;
|
|
|
- end+=6;
|
|
|
+ end += channelMapAceeptVo.getPageSize();
|
|
|
}
|
|
|
result.put("pages",i-1);
|
|
|
- result.put("total",total);
|
|
|
+ result.put("total",list.size());
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ public void tagAnalyseItem(ConcurrentHashMap<String,Integer> concurrentHashMap, List<String> keys){
|
|
|
+ //2.获取网点周边标签,并进行统计
|
|
|
+ int total = 0;
|
|
|
+ List<List<String>> wdTagList = wdRedisStoreage.getWdTagList(keys);
|
|
|
+ for (List<String> list : wdTagList) {
|
|
|
+ if (list == null || list.size() == 0)
|
|
|
+ continue;
|
|
|
+ for (String s : list) {
|
|
|
+ s += "边";
|
|
|
+ Integer integer = concurrentHashMap.get(s);
|
|
|
+ if (integer == null)
|
|
|
+ concurrentHashMap.put(s,1);
|
|
|
+ else
|
|
|
+ concurrentHashMap.put(s,integer+1);
|
|
|
+ }
|
|
|
+ total++;
|
|
|
+ }
|
|
|
+ wdTagList = null;
|
|
|
+ concurrentHashMap.put("total",concurrentHashMap.get("total")+total);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public List<StoreWdCategoryCount> category(ChannelMapAceeptVo channelMapAceeptVo) {
|
|
|
|