4
0

AnalysisMapServiceImpl.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. package com.redxun.knowledge.analysis.service;
  2. import com.baomidou.mybatisplus.core.metadata.IPage;
  3. import com.redxun.common.base.entity.QueryData;
  4. import com.redxun.common.tool.StringUtils;
  5. import com.redxun.knowledge.analysis.entity.dto.PersonVisitDto;
  6. import com.redxun.knowledge.analysis.entity.vo.*;
  7. import com.redxun.knowledge.analysis.mapper.AnalysisMapMapper;
  8. import com.redxun.knowledge.analysis.mapper.PvLogMapper;
  9. import com.redxun.knowledge.common.UserService;
  10. import com.redxun.knowledge.entity.vo.DicVo;
  11. import com.redxun.knowledge.mapper.CommonMapper;
  12. import com.redxun.knowledge.utils.DateUtils;
  13. import com.redxun.knowledge.utils.PageListUtils;
  14. import lombok.extern.slf4j.Slf4j;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.stereotype.Service;
  17. import org.springframework.util.CollectionUtils;
  18. import java.util.*;
  19. import java.util.stream.Collectors;
  20. /**
  21. * 文件名: AnalysisMapServiceImpl
  22. * 作者: zizg
  23. * 时间: 2023/3/22
  24. * 描述:
  25. * 修改人:
  26. * 修改时间:
  27. * 修改内容:
  28. */
  29. @Slf4j
  30. @Service
  31. public class AnalysisMapServiceImpl {
  32. @Autowired
  33. private AnalysisMapMapper analysisMapMapper;
  34. @Autowired
  35. private UserService userService;
  36. @Autowired
  37. private PvLogMapper pvLogMapper;
  38. /**
  39. * 地图创建总量
  40. *
  41. * @param type
  42. * @return
  43. */
  44. public CreateCountTotal mapAmount(String type) {
  45. CreateCountTotal createCountTotal = new CreateCountTotal();
  46. List<CreateCountLabel> createCountLabel = new ArrayList<>();
  47. Calendar calendar = Calendar.getInstance();
  48. int year = calendar.get(Calendar.YEAR);
  49. if (("total").equals(type)) {
  50. createCountLabel = analysisMapMapper.mapAmount(null, null, "total");
  51. } else if ("year".equals(type)) {
  52. createCountLabel = analysisMapMapper.mapAmount(DateUtils.format(DateUtils.getFirstOfYear(year)),
  53. DateUtils.format(DateUtils.getLastOfYear(year)), "year");
  54. } else if ("month".equals(type)) {
  55. int month = calendar.get(Calendar.MONTH);
  56. String firstOfMonth = DateUtils.getFirstOfMonth(year, month + 1, 15);
  57. String lastOfMonth = DateUtils.getLastOfMonth(year, month + 1, 15);
  58. createCountLabel = analysisMapMapper.mapAmountByMonth(firstOfMonth, lastOfMonth, "month");
  59. }
  60. int sum = createCountLabel.stream().mapToInt(CreateCountLabel::getValue).sum();
  61. createCountTotal.setTotal(sum);
  62. createCountTotal.setLables(createCountLabel);
  63. return createCountTotal;
  64. }
  65. /**
  66. * 各类型地图创建数量
  67. *
  68. * @param type
  69. * @return
  70. */
  71. public List<MapTypeCountVo> typeMapPie(String type) {
  72. List<MapTypeCountVo> result = new ArrayList<>();
  73. Calendar calendar = Calendar.getInstance();
  74. int year = calendar.get(Calendar.YEAR);
  75. if (("total").equals(type)) {
  76. result = analysisMapMapper.typeMapPie(null, null);
  77. } else if (("year").equals(type)) {
  78. result = analysisMapMapper.typeMapPie(DateUtils.format(DateUtils.getFirstOfYear(year)),
  79. DateUtils.format(DateUtils.getLastOfYear(year)));
  80. } else if (("month").equals(type)) {
  81. int month = calendar.get(Calendar.MONTH);
  82. String firstOfMonth = DateUtils.getFirstOfMonth(year, month + 1, 15);
  83. String lastOfMonth = DateUtils.getLastOfMonth(year, month + 1, 15);
  84. result = analysisMapMapper.typeMapPie(firstOfMonth, lastOfMonth);
  85. }
  86. //类型名称赋值
  87. result.forEach(e -> {
  88. String name = analysisMapMapper.selectTypeName(e.getType());
  89. e.setType(name);
  90. });
  91. return result;
  92. }
  93. /**
  94. * 地图页面访问量
  95. *
  96. * @param type
  97. * @return
  98. */
  99. public List<MapPagePvVo> mapPageHistogram(String type) {
  100. List<MapPagePvVo> result = new ArrayList<>();
  101. Calendar calendar = Calendar.getInstance();
  102. int year = calendar.get(Calendar.YEAR);
  103. if (("total").equals(type)) {
  104. result = analysisMapMapper.mapPageHistogram(null, null);
  105. } else if (("year").equals(type)) {
  106. result = analysisMapMapper.mapPageHistogram(DateUtils.format(DateUtils.getFirstOfYear(year)),
  107. DateUtils.format(DateUtils.getLastOfYear(year)));
  108. } else if (("month").equals(type)) {
  109. int month = calendar.get(Calendar.MONTH);
  110. String firstOfMonth = DateUtils.getFirstOfMonth(year, month + 1, 15);
  111. String lastOfMonth = DateUtils.getLastOfMonth(year, month + 1, 15);
  112. result = analysisMapMapper.mapPageHistogram(firstOfMonth, lastOfMonth);
  113. }
  114. return result;
  115. }
  116. /**
  117. * 组织创建和访问地图数量
  118. *
  119. * @param queryData
  120. * @return
  121. */
  122. public IPage organizationMaps(QueryData queryData) {
  123. //创建过专辑的公司Id集合
  124. Calendar calendar = Calendar.getInstance();
  125. int year = calendar.get(Calendar.YEAR);
  126. List<MapCompanyVo> result = new ArrayList<>();
  127. if ("total".equals(queryData.getParams().get("type"))) {
  128. result = analysisMapMapper.organizationMaps(null, null);
  129. } else if ("year".equals(queryData.getParams().get("type"))) {
  130. result = analysisMapMapper.organizationMaps(DateUtils.format(DateUtils.getFirstOfYear(year)),
  131. DateUtils.format(DateUtils.getLastOfYear(year)));
  132. } else if ("month".equals(queryData.getParams().get("type"))) {
  133. int month = calendar.get(Calendar.MONTH);
  134. String firstOfMonth = DateUtils.getFirstOfMonth(year, month + 1, 15);
  135. String lastOfMonth = DateUtils.getLastOfMonth(year, month + 1, 15);
  136. result = analysisMapMapper.organizationMaps(firstOfMonth, lastOfMonth);
  137. }
  138. //排序
  139. String sort = queryData.getSortField();
  140. if (sort != null) {
  141. sort = sort + queryData.getSortOrder();
  142. switch (sort) {
  143. case "mapdesc":
  144. result = result.stream().sorted((t1, t2) -> t2.getMap().compareTo(t1.getMap())).collect(Collectors.toList());
  145. break;
  146. case "mapasc":
  147. result = result.stream().sorted(Comparator.comparing(MapCompanyVo::getMap)).collect(Collectors.toList());
  148. break;
  149. case "pvdesc":
  150. result = result.stream().sorted((t1, t2) -> t2.getPv().compareTo(t1.getPv())).collect(Collectors.toList());
  151. break;
  152. case "pvasc":
  153. result = result.stream().sorted(Comparator.comparing(MapCompanyVo::getPv)).collect(Collectors.toList());
  154. break;
  155. }
  156. }
  157. //取tops10
  158. String tops = queryData.getParams().get("tops");
  159. if (StringUtils.isNotEmpty(tops)) {
  160. result = result.stream().limit(Long.parseLong(tops)).collect(Collectors.toList());
  161. } else {
  162. result = result.stream().limit(10).collect(Collectors.toList());
  163. }
  164. result.forEach(e -> e.setOrganization(userService.findDeptByDeptId(e.getOrganization()).getName()));
  165. return PageListUtils.getPages(queryData.getPageNo(), queryData.getPageSize(), result);
  166. }
  167. /**
  168. * 组织创建和访问地图数量(新)
  169. *
  170. * @param type
  171. * @param organizationId
  172. * @return
  173. */
  174. public MapCompanyVo organizationMap(String type, String organizationId,String createTime,String endTime,List<String> personId) {
  175. //存在人员,统计人员
  176. if (!CollectionUtils.isEmpty(personId)){
  177. organizationId = null;
  178. }
  179. //开始时间和结束时间都不为空,按照选中时间过滤,忽略type
  180. if (!StringUtils.isEmpty(createTime) && !StringUtils.isEmpty(endTime)){
  181. type = null;
  182. }
  183. Calendar calendar = Calendar.getInstance();
  184. int year = calendar.get(Calendar.YEAR);
  185. MapCompanyVo result = new MapCompanyVo();
  186. if ("total".equals(type)) {
  187. result = analysisMapMapper.organizationMap(null, null, organizationId,personId);
  188. } else if ("year".equals(type)) {
  189. result = analysisMapMapper.organizationMap(DateUtils.format(DateUtils.getFirstOfYear(year)),
  190. DateUtils.format(DateUtils.getLastOfYear(year)), organizationId,personId);
  191. } else if ("month".equals(type)) {
  192. int month = calendar.get(Calendar.MONTH);
  193. String firstOfMonth = DateUtils.getFirstOfMonth(year, month + 1, 15);
  194. String lastOfMonth = DateUtils.getLastOfMonth(year, month + 1, 15);
  195. result = analysisMapMapper.organizationMap(firstOfMonth, lastOfMonth, organizationId,personId);
  196. } else {
  197. result = analysisMapMapper.organizationMap(createTime, endTime, organizationId,personId);
  198. }
  199. if (CollectionUtils.isEmpty(personId)) {
  200. String deptPath = pvLogMapper.findAllDeptIdByDeptId(organizationId);
  201. if (StringUtils.isNotEmpty(deptPath)) {
  202. deptPath = deptPath.substring(deptPath.indexOf(".") + 1);
  203. String[] split = deptPath.split("\\.");
  204. if (split.length > 6) {
  205. String first = Arrays.stream(split).limit(3).map(e -> userService.findDeptByDeptId(e).getName()).collect(Collectors.joining(">"));
  206. String end = Arrays.stream(split).skip(split.length - 3).map(e -> userService.findDeptByDeptId(e).getName()).collect(Collectors.joining(">"));
  207. result.setOrganization(first + ">...>" + end);
  208. } else {
  209. String organization = Arrays.stream(split).map(e -> userService.findDeptByDeptId(e).getName()).collect(Collectors.joining(">"));
  210. result.setOrganization(organization);
  211. }
  212. }
  213. } else {
  214. String fullName = personId.parallelStream().map(e -> userService.queryOsUserDto(e).getFullName()).collect(Collectors.joining(","));
  215. result.setOrganization(fullName);
  216. }
  217. return result;
  218. }
  219. /**
  220. * 人员创建和访问地图数量
  221. * @param personVisitDto
  222. * @return
  223. */
  224. public MapCompanyVo personMap(PersonVisitDto personVisitDto) {
  225. //如果组织id不为空,人员id为空情况下,显示组织访问量
  226. MapCompanyVo mapCompanyVo = this.organizationMap(personVisitDto.getType(), personVisitDto.getOrganizationId(),
  227. personVisitDto.getCreateTime(), personVisitDto.getEndTime(), personVisitDto.getPersonId());
  228. return mapCompanyVo;
  229. }
  230. }