AnalysisMapServiceImpl.java 5.3 KB

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