123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- package com.redxun.knowledge.analysis.service;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import com.redxun.common.base.entity.QueryData;
- import com.redxun.common.tool.StringUtils;
- import com.redxun.knowledge.analysis.entity.dto.PersonVisitDto;
- import com.redxun.knowledge.analysis.entity.vo.*;
- import com.redxun.knowledge.analysis.mapper.AnalysisMapMapper;
- import com.redxun.knowledge.analysis.mapper.PvLogMapper;
- 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 com.redxun.knowledge.utils.PageListUtils;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.util.CollectionUtils;
- import java.util.*;
- import java.util.stream.Collectors;
- /**
- * 文件名: AnalysisMapServiceImpl
- * 作者: zizg
- * 时间: 2023/3/22
- * 描述:
- * 修改人:
- * 修改时间:
- * 修改内容:
- */
- @Slf4j
- @Service
- public class AnalysisMapServiceImpl {
- @Autowired
- private AnalysisMapMapper analysisMapMapper;
- @Autowired
- private UserService userService;
- @Autowired
- private PvLogMapper pvLogMapper;
- /**
- * 地图创建总量
- *
- * @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, "total");
- } else if ("year".equals(type)) {
- createCountLabel = analysisMapMapper.mapAmount(DateUtils.format(DateUtils.getFirstOfYear(year)),
- DateUtils.format(DateUtils.getLastOfYear(year)), "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.mapAmountByMonth(firstOfMonth, lastOfMonth, "month");
- }
- int sum = createCountLabel.stream().mapToInt(CreateCountLabel::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 queryData
- * @return
- */
- public IPage organizationMaps(QueryData queryData) {
- //创建过专辑的公司Id集合
- Calendar calendar = Calendar.getInstance();
- int year = calendar.get(Calendar.YEAR);
- List<MapCompanyVo> result = new ArrayList<>();
- if ("total".equals(queryData.getParams().get("type"))) {
- result = analysisMapMapper.organizationMaps(null, null);
- } else if ("year".equals(queryData.getParams().get("type"))) {
- result = analysisMapMapper.organizationMaps(DateUtils.format(DateUtils.getFirstOfYear(year)),
- DateUtils.format(DateUtils.getLastOfYear(year)));
- } else if ("month".equals(queryData.getParams().get("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);
- }
- //排序
- String sort = queryData.getSortField();
- if (sort != null) {
- sort = sort + queryData.getSortOrder();
- 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
- String tops = queryData.getParams().get("tops");
- if (StringUtils.isNotEmpty(tops)) {
- result = result.stream().limit(Long.parseLong(tops)).collect(Collectors.toList());
- } else {
- result = result.stream().limit(10).collect(Collectors.toList());
- }
- result.forEach(e -> e.setOrganization(userService.findDeptByDeptId(e.getOrganization()).getName()));
- return PageListUtils.getPages(queryData.getPageNo(), queryData.getPageSize(), result);
- }
- /**
- * 组织创建和访问地图数量(新)
- *
- * @param type
- * @param organizationId
- * @return
- */
- public MapCompanyVo organizationMap(String type, String organizationId,String createTime,String endTime,List<String> personId) {
- //存在人员,统计人员
- if (!CollectionUtils.isEmpty(personId)){
- organizationId = null;
- }
- //开始时间和结束时间都不为空,按照选中时间过滤,忽略type
- if (!StringUtils.isEmpty(createTime) && !StringUtils.isEmpty(endTime)){
- type = null;
- }
- Calendar calendar = Calendar.getInstance();
- int year = calendar.get(Calendar.YEAR);
- MapCompanyVo result = new MapCompanyVo();
- if ("total".equals(type)) {
- result = analysisMapMapper.organizationMap(null, null, organizationId,personId);
- } else if ("year".equals(type)) {
- result = analysisMapMapper.organizationMap(DateUtils.format(DateUtils.getFirstOfYear(year)),
- DateUtils.format(DateUtils.getLastOfYear(year)), organizationId,personId);
- } 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.organizationMap(firstOfMonth, lastOfMonth, organizationId,personId);
- } else {
- result = analysisMapMapper.organizationMap(createTime, endTime, organizationId,personId);
- }
- if (CollectionUtils.isEmpty(personId)) {
- String deptPath = pvLogMapper.findAllDeptIdByDeptId(organizationId);
- if (StringUtils.isNotEmpty(deptPath)) {
- deptPath = deptPath.substring(deptPath.indexOf(".") + 1);
- String[] split = deptPath.split("\\.");
- if (split.length > 6) {
- String first = Arrays.stream(split).limit(3).map(e -> userService.findDeptByDeptId(e).getName()).collect(Collectors.joining(">"));
- String end = Arrays.stream(split).skip(split.length - 3).map(e -> userService.findDeptByDeptId(e).getName()).collect(Collectors.joining(">"));
- result.setOrganization(first + ">...>" + end);
- } else {
- String organization = Arrays.stream(split).map(e -> userService.findDeptByDeptId(e).getName()).collect(Collectors.joining(">"));
- result.setOrganization(organization);
- }
- }
- } else {
- String fullName = personId.parallelStream().map(e -> userService.queryOsUserDto(e).getFullName()).collect(Collectors.joining(","));
- result.setOrganization(fullName);
- }
- return result;
- }
- /**
- * 人员创建和访问地图数量
- * @param personVisitDto
- * @return
- */
- public MapCompanyVo personMap(PersonVisitDto personVisitDto) {
- //如果组织id不为空,人员id为空情况下,显示组织访问量
- MapCompanyVo mapCompanyVo = this.organizationMap(personVisitDto.getType(), personVisitDto.getOrganizationId(),
- personVisitDto.getCreateTime(), personVisitDto.getEndTime(), personVisitDto.getPersonId());
- return mapCompanyVo;
- }
- }
|