4
0

AnalysisSearchServiceImpl.java 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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.consts.ComanyColumnsConst;
  6. import com.redxun.knowledge.analysis.entity.dto.PersonVisitDto;
  7. import com.redxun.knowledge.analysis.entity.enums.SystemDetailVisitsEnum;
  8. import com.redxun.knowledge.analysis.entity.vo.MapCompanyVo;
  9. import com.redxun.knowledge.analysis.entity.vo.OrganizationSearchVo;
  10. import com.redxun.knowledge.analysis.entity.vo.SystemCompanyVo;
  11. import com.redxun.knowledge.analysis.entity.vo.SystemDetailVisitsVo;
  12. import com.redxun.knowledge.analysis.mapper.AnalysisSearchMapper;
  13. import com.redxun.knowledge.analysis.mapper.PvLogMapper;
  14. import com.redxun.knowledge.common.UserService;
  15. import com.redxun.knowledge.utils.DateUtils;
  16. import com.redxun.knowledge.utils.PageListUtils;
  17. import lombok.extern.slf4j.Slf4j;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.stereotype.Service;
  20. import org.springframework.util.CollectionUtils;
  21. import java.math.BigDecimal;
  22. import java.util.*;
  23. import java.util.stream.Collectors;
  24. /**
  25. * 文件名: AnalysisSearchServiceImpl
  26. * 作者: zizg
  27. * 时间: 2023/3/23
  28. * 描述:
  29. * 修改人:
  30. * 修改时间:
  31. * 修改内容:
  32. */
  33. @Service
  34. @Slf4j
  35. public class AnalysisSearchServiceImpl {
  36. @Autowired
  37. private AnalysisSearchMapper analysisSearchMapper;
  38. @Autowired
  39. private PvLogMapper pvLogMapper;
  40. @Autowired
  41. private UserService userService;
  42. /**
  43. * 各业务系统分布
  44. *
  45. * @param type
  46. * @return
  47. */
  48. public List<SystemDetailVisitsVo> searchSystemDetailVisits(String type) {
  49. Calendar calendar = Calendar.getInstance();
  50. int year = calendar.get(Calendar.YEAR);
  51. List<SystemDetailVisitsVo> result = new ArrayList<>();
  52. if (("total").equals(type)) {
  53. result = analysisSearchMapper.searchSystemDetailVisits(null, null);
  54. } else if (("year").equals(type)) {
  55. result = analysisSearchMapper.searchSystemDetailVisits(DateUtils.format(DateUtils.getFirstOfYear(year)),
  56. DateUtils.format(DateUtils.getLastOfYear(year)));
  57. } else if (("month").equals(type)) {
  58. int month = calendar.get(Calendar.MONTH);
  59. String firstOfMonth = DateUtils.getFirstOfMonth(year, month + 1, 15);
  60. String lastOfMonth = DateUtils.getLastOfMonth(year, month + 1, 15);
  61. result = analysisSearchMapper.searchSystemDetailVisits(firstOfMonth, lastOfMonth);
  62. }
  63. return result;
  64. }
  65. /**
  66. * 组织访问量
  67. *
  68. * @param queryData
  69. * @return
  70. */
  71. public Map<String, List> organizationSearchs(QueryData queryData) {
  72. //获取排序规则
  73. String sort = queryData.getSortField();
  74. if (sort != null) {
  75. sort = sort + queryData.getSortOrder();
  76. }
  77. Calendar calendar = Calendar.getInstance();
  78. int year = calendar.get(Calendar.YEAR);
  79. List<SystemCompanyVo> result = new ArrayList<>();
  80. if (("total").equals(queryData.getParams().get("type"))) {
  81. result = analysisSearchMapper.organizationSearchs(null, null, sort);
  82. } else if (("year").equals(queryData.getParams().get("type"))) {
  83. result = analysisSearchMapper.organizationSearchs(DateUtils.format(DateUtils.getFirstOfYear(year)),
  84. DateUtils.format(DateUtils.getLastOfYear(year)), sort);
  85. } else if (("month").equals(queryData.getParams().get("type"))) {
  86. int month = calendar.get(Calendar.MONTH);
  87. String firstOfMonth = DateUtils.getFirstOfMonth(year, month + 1, 15);
  88. String lastOfMonth = DateUtils.getLastOfMonth(year, month + 1, 15);
  89. result = analysisSearchMapper.organizationSearchs(firstOfMonth, lastOfMonth, sort);
  90. }
  91. String tops = queryData.getParams().get("tops");
  92. if (StringUtils.isNotEmpty(tops)) {
  93. result = result.stream().limit(Long.parseLong(tops)).collect(Collectors.toList());
  94. } else {
  95. result = result.stream().limit(10).collect(Collectors.toList());
  96. }
  97. //公司名称赋值
  98. result.forEach(e -> e.setCompany(userService.findDeptByDeptId(e.getCompany()).getName()));
  99. Map<String, List> mapList = new LinkedHashMap<>();
  100. mapList.put("columns", ComanyColumnsConst.companyColumnsList());
  101. mapList.put("rows", result);
  102. return mapList;
  103. }
  104. /**
  105. * 组织访问量(新)
  106. *
  107. * @param type
  108. * @param organizationId
  109. * @return
  110. */
  111. public OrganizationSearchVo organizationSearch(String type, String organizationId,String createTime,String endTime,List<String> personId) {
  112. //存在人员,统计人员
  113. if (!CollectionUtils.isEmpty(personId)){
  114. organizationId = null;
  115. }
  116. //开始时间和结束时间都不为空,按照选中时间过滤,忽略type
  117. if (!StringUtils.isEmpty(createTime) && !StringUtils.isEmpty(endTime)){
  118. type = null;
  119. }
  120. Calendar calendar = Calendar.getInstance();
  121. int year = calendar.get(Calendar.YEAR);
  122. OrganizationSearchVo organizationSearchVo = new OrganizationSearchVo();
  123. List<Map<String, Object>> item = new ArrayList<>();
  124. if (("total").equals(type)) {
  125. item = analysisSearchMapper.organizationSearch(null, null, organizationId,personId);
  126. } else if (("year").equals(type)) {
  127. item = analysisSearchMapper.organizationSearch(DateUtils.format(DateUtils.getFirstOfYear(year)),
  128. DateUtils.format(DateUtils.getLastOfYear(year)), organizationId,personId);
  129. } else if (("month").equals(type)) {
  130. int month = calendar.get(Calendar.MONTH);
  131. String firstOfMonth = DateUtils.getFirstOfMonth(year, month + 1, 15);
  132. String lastOfMonth = DateUtils.getLastOfMonth(year, month + 1, 15);
  133. item = analysisSearchMapper.organizationSearch(firstOfMonth, lastOfMonth, organizationId,personId);
  134. } else {
  135. item = analysisSearchMapper.organizationSearch(createTime,endTime, organizationId,personId);
  136. }
  137. String deptPath = pvLogMapper.findAllDeptIdByDeptId(organizationId);
  138. if (CollectionUtils.isEmpty(personId)) {
  139. if (StringUtils.isNotEmpty(deptPath)) {
  140. deptPath = deptPath.substring(deptPath.indexOf(".") + 1);
  141. String[] split = deptPath.split("\\.");
  142. if (split.length > 6) {
  143. String first = Arrays.stream(split).limit(3).map(e -> userService.findDeptByDeptId(e).getName()).collect(Collectors.joining(">"));
  144. String end = Arrays.stream(split).skip(split.length - 3).map(e -> userService.findDeptByDeptId(e).getName()).collect(Collectors.joining(">"));
  145. organizationSearchVo.setOrganization(first + ">...>" + end);
  146. } else {
  147. String organization = Arrays.stream(split).map(e -> userService.findDeptByDeptId(e).getName()).collect(Collectors.joining(">"));
  148. organizationSearchVo.setOrganization(organization);
  149. }
  150. }
  151. } else {
  152. String fullName = personId.parallelStream().map(e -> userService.queryOsUserDto(e).getFullName()).collect(Collectors.joining(","));
  153. organizationSearchVo.setOrganization(fullName);
  154. }
  155. Optional<BigDecimal> total = item.stream().map(e -> (BigDecimal) e.get("value")).reduce(BigDecimal::add);
  156. Map<String, Object> map = new HashMap<>();
  157. map.put("name", "访问总量");
  158. map.put("value", total.get());
  159. item.add(0,map);
  160. organizationSearchVo.setItem(item);
  161. return organizationSearchVo;
  162. }
  163. /**
  164. * 人员访问量
  165. * @param personVisitDto
  166. * @return
  167. */
  168. public OrganizationSearchVo personSearch(PersonVisitDto personVisitDto) {
  169. //如果组织id不为空,人员id为空情况下,显示组织访问量
  170. OrganizationSearchVo organizationSearchVo = this.organizationSearch(personVisitDto.getType(), personVisitDto.getOrganizationId(),
  171. personVisitDto.getCreateTime(), personVisitDto.getEndTime(), personVisitDto.getPersonId());
  172. return organizationSearchVo;
  173. }
  174. }