AnalysisMapServiceImpl.java 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. package com.redxun.knowledge.analysis.service;
  2. import com.redxun.knowledge.analysis.entity.vo.*;
  3. import com.redxun.knowledge.analysis.mapper.AnalysisMapMapper;
  4. import com.redxun.knowledge.common.UserService;
  5. import com.redxun.knowledge.entity.vo.DicVo;
  6. import com.redxun.knowledge.mapper.CommonMapper;
  7. import com.redxun.knowledge.utils.DateUtils;
  8. import lombok.extern.slf4j.Slf4j;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.stereotype.Service;
  11. import java.util.ArrayList;
  12. import java.util.Calendar;
  13. import java.util.Comparator;
  14. import java.util.List;
  15. import java.util.stream.Collectors;
  16. /**
  17. * 文件名: AnalysisMapServiceImpl
  18. * 作者: zizg
  19. * 时间: 2023/3/22
  20. * 描述:
  21. * 修改人:
  22. * 修改时间:
  23. * 修改内容:
  24. */
  25. @Slf4j
  26. @Service
  27. public class AnalysisMapServiceImpl {
  28. @Autowired
  29. private AnalysisMapMapper analysisMapMapper;
  30. @Autowired
  31. private UserService userService;
  32. /**
  33. * 地图创建总量
  34. * @param type
  35. * @return
  36. */
  37. public CreateCountTotal mapAmount(String type) {
  38. CreateCountTotal createCountTotal = new CreateCountTotal();
  39. List<CreateCountLabel> createCountLabel = new ArrayList<>();
  40. Calendar calendar = Calendar.getInstance();
  41. int year = calendar.get(Calendar.YEAR);
  42. if (("total").equals(type)) {
  43. createCountLabel = analysisMapMapper.mapAmount(null, null);
  44. } else if ("year".equals(type)) {
  45. createCountLabel = analysisMapMapper.mapAmount(DateUtils.format(DateUtils.getFirstOfYear(year)),
  46. DateUtils.format(DateUtils.getLastOfYear(year)));
  47. } else if ("month".equals(type)) {
  48. int month = calendar.get(Calendar.MONTH);
  49. String firstOfMonth = DateUtils.getFirstOfMonth(year, month + 1, 15);
  50. String lastOfMonth = DateUtils.getLastOfMonth(year, month + 1, 15);
  51. createCountLabel = analysisMapMapper.mapAmount(firstOfMonth, lastOfMonth);
  52. }
  53. int sum = createCountLabel.stream().mapToInt(e -> Integer.parseInt(e.getValue())).sum();
  54. createCountTotal.setTotal(sum);
  55. createCountTotal.setLables(createCountLabel);
  56. return createCountTotal;
  57. }
  58. /**
  59. * 各类型地图创建数量
  60. * @param type
  61. * @return
  62. */
  63. public List<MapTypeCountVo> typeMapPie(String type) {
  64. List<MapTypeCountVo> result = new ArrayList<>();
  65. Calendar calendar = Calendar.getInstance();
  66. int year = calendar.get(Calendar.YEAR);
  67. if (("total").equals(type)){
  68. result = analysisMapMapper.typeMapPie(null,null);
  69. } else if (("year").equals(type)){
  70. result = analysisMapMapper.typeMapPie(DateUtils.format(DateUtils.getFirstOfYear(year)),
  71. DateUtils.format(DateUtils.getLastOfYear(year)));
  72. } else if (("month").equals(type)){
  73. int month = calendar.get(Calendar.MONTH);
  74. String firstOfMonth = DateUtils.getFirstOfMonth(year, month + 1, 15);
  75. String lastOfMonth = DateUtils.getLastOfMonth(year, month + 1, 15);
  76. result = analysisMapMapper.typeMapPie(firstOfMonth,lastOfMonth);
  77. }
  78. //类型名称赋值
  79. result.forEach(e -> {
  80. String name = analysisMapMapper.selectTypeName(e.getType());
  81. e.setType(name);
  82. });
  83. return result;
  84. }
  85. /**
  86. * 地图页面访问量
  87. * @param type
  88. * @return
  89. */
  90. public List<MapPagePvVo> mapPageHistogram(String type) {
  91. List<MapPagePvVo> result = new ArrayList<>();
  92. Calendar calendar = Calendar.getInstance();
  93. int year = calendar.get(Calendar.YEAR);
  94. if (("total").equals(type)){
  95. result = analysisMapMapper.mapPageHistogram(null,null);
  96. } else if (("year").equals(type)){
  97. result = analysisMapMapper.mapPageHistogram(DateUtils.format(DateUtils.getFirstOfYear(year)),
  98. DateUtils.format(DateUtils.getLastOfYear(year)));
  99. } else if (("month").equals(type)){
  100. int month = calendar.get(Calendar.MONTH);
  101. String firstOfMonth = DateUtils.getFirstOfMonth(year, month + 1, 15);
  102. String lastOfMonth = DateUtils.getLastOfMonth(year, month + 1, 15);
  103. result = analysisMapMapper.mapPageHistogram(firstOfMonth,lastOfMonth);
  104. }
  105. return result;
  106. }
  107. /**
  108. * 组织创建和访问地图数量
  109. * @param type
  110. * @param tops
  111. * @param sort
  112. * @return
  113. */
  114. public List<MapCompanyVo> organizationMaps(String type, Integer tops, String sort) {
  115. //创建过专辑的公司Id集合
  116. Calendar calendar = Calendar.getInstance();
  117. int year = calendar.get(Calendar.YEAR);
  118. List<MapCompanyVo> result = new ArrayList<>();
  119. if ("total".equals(type)) {
  120. result = analysisMapMapper.organizationMaps(null, null);
  121. } else if ("year".equals(type)) {
  122. result = analysisMapMapper.organizationMaps(DateUtils.format(DateUtils.getFirstOfYear(year)),
  123. DateUtils.format(DateUtils.getLastOfYear(year)));
  124. } else if ("month".equals(type)) {
  125. int month = calendar.get(Calendar.MONTH);
  126. String firstOfMonth = DateUtils.getFirstOfMonth(year, month + 1, 15);
  127. String lastOfMonth = DateUtils.getLastOfMonth(year, month + 1, 15);
  128. result = analysisMapMapper.organizationMaps(firstOfMonth, lastOfMonth);
  129. }
  130. //排序
  131. if (sort != null) {
  132. switch (sort) {
  133. case "mapDesc":
  134. result = result.stream().sorted((t1, t2) -> t2.getMap().compareTo(t1.getMap())).collect(Collectors.toList());
  135. break;
  136. case "mapAsc":
  137. result = result.stream().sorted(Comparator.comparing(MapCompanyVo::getMap)).collect(Collectors.toList());
  138. break;
  139. case "pvDesc":
  140. result = result.stream().sorted((t1, t2) -> t2.getPv().compareTo(t1.getPv())).collect(Collectors.toList());
  141. break;
  142. case "pvAsc":
  143. result = result.stream().sorted(Comparator.comparing(MapCompanyVo::getPv)).collect(Collectors.toList());
  144. break;
  145. }
  146. }
  147. //取tops10
  148. result = result.stream().limit(tops).collect(Collectors.toList());
  149. result.forEach(e -> e.setCompany(userService.findDeptByDeptId(e.getCompany()).getName()));
  150. return result;
  151. }
  152. }