use of com.dimple.project.home.domain.KeyValue in project DimpleBlog by martin-chips.
the class DashboardServiceImpl method getAccessData.
@Override
public AccessDataResult getAccessData() {
List<KeyValue> accessDataList = dashBoardMapper.getAccessData();
if (accessDataList.isEmpty()) {
return new AccessDataResult();
}
// handle data
accessDataList = accessDataList.stream().map(e -> new KeyValue(getTopDomain(e.getKey()), e.getValue())).collect(Collectors.toList());
AccessData direct = new AccessData("直达", 0);
AccessData localRedirect = new AccessData("本地跳转", 0);
AccessData searchEngine = new AccessData("搜索引擎", 0);
AccessData link = new AccessData("友链跳转", 0);
AccessData other = new AccessData("其他", 0);
// 搜索引擎
List<AccessDataItem> searchEngineAccessDataItemList = getSearchEngineAccessDataItemList();
// 友链跳转
List<AccessDataItem> linkAccessDataItemList = getLinkAccessDataItemList();
for (KeyValue keyValue : accessDataList) {
String url = keyValue.getKey();
Long count = keyValue.getValue();
Optional<AccessDataItem> searchAny = searchEngineAccessDataItemList.stream().filter(e -> e.getFilter().equals(url)).findAny();
Optional<AccessDataItem> linkAny = linkAccessDataItemList.stream().filter(e -> Objects.equals(e.getFilter(), url)).findAny();
if (StringUtils.isEmpty(url)) {
direct.setValue(direct.getValue() + count);
} else if (url.contains(INTERNAL_KEY)) {
localRedirect.setValue(localRedirect.getValue() + count);
} else if (searchAny.isPresent()) {
AccessDataItem accessDataItem = searchAny.get();
accessDataItem.setValue(accessDataItem.getValue() + count);
} else if (linkAny.isPresent()) {
AccessDataItem accessDataItem = linkAny.get();
accessDataItem.setValue(accessDataItem.getValue() + count);
} else {
other.setValue(other.getValue() + count);
}
}
searchEngine.setValue(searchEngineAccessDataItemList.stream().mapToLong(e -> e.getValue()).sum());
link.setValue(linkAccessDataItemList.stream().mapToLong(e -> e.getValue()).sum());
AccessDataResult accessDataResult = new AccessDataResult();
List<AccessData> innerResult = new ArrayList<>();
innerResult.add(direct);
innerResult.add(searchEngine);
innerResult.add(link);
innerResult.add(localRedirect);
innerResult.add(other);
accessDataResult.setInner(innerResult.stream().filter(e -> e.getValue() != 0).sorted(Comparator.comparing(AccessData::getValue).reversed()).collect(Collectors.toList()));
List<AccessData> outResult = new ArrayList<>();
linkAccessDataItemList.addAll(searchEngineAccessDataItemList);
for (AccessDataItem accessDataItem : linkAccessDataItemList) {
AccessData accessData = new AccessData();
BeanUtils.copyProperties(accessDataItem, accessData);
outResult.add(accessData);
}
accessDataResult.setOut(outResult.stream().filter(e -> e.getValue() != 0).sorted(Comparator.comparing(AccessData::getValue).reversed()).collect(Collectors.toList()));
return accessDataResult.complete();
}
Aggregations