Search in sources :

Example 1 with AccessDataResult

use of com.dimple.project.home.domain.AccessDataResult 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();
}
Also used : AccessDataResult(com.dimple.project.home.domain.AccessDataResult) QuartzJobLog(com.dimple.project.log.domain.QuartzJobLog) DictData(com.dimple.project.system.domain.DictData) Cacheable(org.springframework.cache.annotation.Cacheable) URL(java.net.URL) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) AccessDataResult(com.dimple.project.home.domain.AccessDataResult) DashBoardMapper(com.dimple.project.home.mapper.DashBoardMapper) OperateLog(com.dimple.project.log.domain.OperateLog) KeyValue(com.dimple.project.home.domain.KeyValue) ArrayList(java.util.ArrayList) AccessDataItem(com.dimple.project.home.domain.AccessDataItem) Matcher(java.util.regex.Matcher) DateUtils(com.dimple.common.utils.DateUtils) Service(org.springframework.stereotype.Service) Map(java.util.Map) AccessData(com.dimple.project.home.domain.AccessData) LinkedList(java.util.LinkedList) TimeType(com.dimple.framework.config.redis.TimeType) LoginLog(com.dimple.project.log.domain.LoginLog) Link(com.dimple.project.system.domain.Link) StringUtils(com.dimple.common.utils.StringUtils) LinkService(com.dimple.project.system.service.LinkService) MalformedURLException(java.net.MalformedURLException) LineChartData(com.dimple.project.home.domain.LineChartData) DictDataService(com.dimple.project.system.service.DictDataService) Collectors(java.util.stream.Collectors) VisitLog(com.dimple.project.log.domain.VisitLog) Objects(java.util.Objects) CacheExpire(com.dimple.framework.config.redis.CacheExpire) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) Comparator(java.util.Comparator) DashboardService(com.dimple.project.home.service.DashboardService) BeanUtils(org.springframework.beans.BeanUtils) KeyValue(com.dimple.project.home.domain.KeyValue) AccessData(com.dimple.project.home.domain.AccessData) ArrayList(java.util.ArrayList) AccessDataItem(com.dimple.project.home.domain.AccessDataItem)

Aggregations

DateUtils (com.dimple.common.utils.DateUtils)1 StringUtils (com.dimple.common.utils.StringUtils)1 CacheExpire (com.dimple.framework.config.redis.CacheExpire)1 TimeType (com.dimple.framework.config.redis.TimeType)1 AccessData (com.dimple.project.home.domain.AccessData)1 AccessDataItem (com.dimple.project.home.domain.AccessDataItem)1 AccessDataResult (com.dimple.project.home.domain.AccessDataResult)1 KeyValue (com.dimple.project.home.domain.KeyValue)1 LineChartData (com.dimple.project.home.domain.LineChartData)1 DashBoardMapper (com.dimple.project.home.mapper.DashBoardMapper)1 DashboardService (com.dimple.project.home.service.DashboardService)1 LoginLog (com.dimple.project.log.domain.LoginLog)1 OperateLog (com.dimple.project.log.domain.OperateLog)1 QuartzJobLog (com.dimple.project.log.domain.QuartzJobLog)1 VisitLog (com.dimple.project.log.domain.VisitLog)1 DictData (com.dimple.project.system.domain.DictData)1 Link (com.dimple.project.system.domain.Link)1 DictDataService (com.dimple.project.system.service.DictDataService)1 LinkService (com.dimple.project.system.service.LinkService)1 MalformedURLException (java.net.MalformedURLException)1