123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- package com.redxun.knowledge.analysis.service;
- import com.redxun.knowledge.analysis.entity.vo.*;
- import com.redxun.knowledge.analysis.mapper.AnalysisMapMapper;
- import com.redxun.knowledge.common.UserService;
- import com.redxun.knowledge.entity.vo.DicVo;
- import com.redxun.knowledge.mapper.CommonMapper;
- import com.redxun.knowledge.utils.DateUtils;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.util.ArrayList;
- import java.util.Calendar;
- import java.util.Comparator;
- import java.util.List;
- import java.util.stream.Collectors;
- /**
- * 文件名: AnalysisMapServiceImpl
- * 作者: zizg
- * 时间: 2023/3/22
- * 描述:
- * 修改人:
- * 修改时间:
- * 修改内容:
- */
- @Slf4j
- @Service
- public class AnalysisMapServiceImpl {
- @Autowired
- private AnalysisMapMapper analysisMapMapper;
- @Autowired
- private UserService userService;
- /**
- * 地图创建总量
- * @param type
- * @return
- */
- public CreateCountTotal mapAmount(String type) {
- CreateCountTotal createCountTotal = new CreateCountTotal();
- List<CreateCountLabel> createCountLabel = new ArrayList<>();
- Calendar calendar = Calendar.getInstance();
- int year = calendar.get(Calendar.YEAR);
- if (("total").equals(type)) {
- createCountLabel = analysisMapMapper.mapAmount(null, null);
- } else if ("year".equals(type)) {
- createCountLabel = analysisMapMapper.mapAmount(DateUtils.format(DateUtils.getFirstOfYear(year)),
- DateUtils.format(DateUtils.getLastOfYear(year)));
- } else if ("month".equals(type)) {
- int month = calendar.get(Calendar.MONTH);
- String firstOfMonth = DateUtils.getFirstOfMonth(year, month + 1, 15);
- String lastOfMonth = DateUtils.getLastOfMonth(year, month + 1, 15);
- createCountLabel = analysisMapMapper.mapAmount(firstOfMonth, lastOfMonth);
- }
- int sum = createCountLabel.stream().mapToInt(e -> Integer.parseInt(e.getValue())).sum();
- createCountTotal.setTotal(sum);
- createCountTotal.setLables(createCountLabel);
- return createCountTotal;
- }
- /**
- * 各类型地图创建数量
- * @param type
- * @return
- */
- public List<MapTypeCountVo> typeMapPie(String type) {
- List<MapTypeCountVo> result = new ArrayList<>();
- Calendar calendar = Calendar.getInstance();
- int year = calendar.get(Calendar.YEAR);
- if (("total").equals(type)){
- result = analysisMapMapper.typeMapPie(null,null);
- } else if (("year").equals(type)){
- result = analysisMapMapper.typeMapPie(DateUtils.format(DateUtils.getFirstOfYear(year)),
- DateUtils.format(DateUtils.getLastOfYear(year)));
- } else if (("month").equals(type)){
- int month = calendar.get(Calendar.MONTH);
- String firstOfMonth = DateUtils.getFirstOfMonth(year, month + 1, 15);
- String lastOfMonth = DateUtils.getLastOfMonth(year, month + 1, 15);
- result = analysisMapMapper.typeMapPie(firstOfMonth,lastOfMonth);
- }
- //类型名称赋值
- result.forEach(e -> {
- String name = analysisMapMapper.selectTypeName(e.getType());
- e.setType(name);
- });
- return result;
- }
- /**
- * 地图页面访问量
- * @param type
- * @return
- */
- public List<MapPagePvVo> mapPageHistogram(String type) {
- List<MapPagePvVo> result = new ArrayList<>();
- Calendar calendar = Calendar.getInstance();
- int year = calendar.get(Calendar.YEAR);
- if (("total").equals(type)){
- result = analysisMapMapper.mapPageHistogram(null,null);
- } else if (("year").equals(type)){
- result = analysisMapMapper.mapPageHistogram(DateUtils.format(DateUtils.getFirstOfYear(year)),
- DateUtils.format(DateUtils.getLastOfYear(year)));
- } else if (("month").equals(type)){
- int month = calendar.get(Calendar.MONTH);
- String firstOfMonth = DateUtils.getFirstOfMonth(year, month + 1, 15);
- String lastOfMonth = DateUtils.getLastOfMonth(year, month + 1, 15);
- result = analysisMapMapper.mapPageHistogram(firstOfMonth,lastOfMonth);
- }
- return result;
- }
- /**
- * 组织创建和访问地图数量
- * @param type
- * @param tops
- * @param sort
- * @return
- */
- public List<MapCompanyVo> organizationMaps(String type, Integer tops, String sort) {
- //创建过专辑的公司Id集合
- Calendar calendar = Calendar.getInstance();
- int year = calendar.get(Calendar.YEAR);
- List<MapCompanyVo> result = new ArrayList<>();
- if ("total".equals(type)) {
- result = analysisMapMapper.organizationMaps(null, null);
- } else if ("year".equals(type)) {
- result = analysisMapMapper.organizationMaps(DateUtils.format(DateUtils.getFirstOfYear(year)),
- DateUtils.format(DateUtils.getLastOfYear(year)));
- } else if ("month".equals(type)) {
- int month = calendar.get(Calendar.MONTH);
- String firstOfMonth = DateUtils.getFirstOfMonth(year, month + 1, 15);
- String lastOfMonth = DateUtils.getLastOfMonth(year, month + 1, 15);
- result = analysisMapMapper.organizationMaps(firstOfMonth, lastOfMonth);
- }
- //排序
- if (sort != null) {
- switch (sort) {
- case "mapDesc":
- result = result.stream().sorted((t1, t2) -> t2.getMap().compareTo(t1.getMap())).collect(Collectors.toList());
- break;
- case "mapAsc":
- result = result.stream().sorted(Comparator.comparing(MapCompanyVo::getMap)).collect(Collectors.toList());
- break;
- case "pvDesc":
- result = result.stream().sorted((t1, t2) -> t2.getPv().compareTo(t1.getPv())).collect(Collectors.toList());
- break;
- case "pvAsc":
- result = result.stream().sorted(Comparator.comparing(MapCompanyVo::getPv)).collect(Collectors.toList());
- break;
- }
- }
- //取tops10
- result = result.stream().limit(tops).collect(Collectors.toList());
- result.forEach(e -> e.setCompany(userService.findDeptByDeptId(e.getCompany()).getName()));
- return result;
- }
- }
|