AnalysisSearchServiceImpl.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package com.redxun.knowledge.analysis.service;
  2. import com.redxun.knowledge.analysis.entity.enums.SystemDetailVisitsEnum;
  3. import com.redxun.knowledge.analysis.entity.vo.SystemCompanyVo;
  4. import com.redxun.knowledge.analysis.entity.vo.SystemDetailVisitsVo;
  5. import com.redxun.knowledge.analysis.mapper.AnalysisSearchMapper;
  6. import com.redxun.knowledge.common.UserService;
  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.*;
  12. import java.util.stream.Collectors;
  13. /**
  14. * 文件名: AnalysisSearchServiceImpl
  15. * 作者: zizg
  16. * 时间: 2023/3/23
  17. * 描述:
  18. * 修改人:
  19. * 修改时间:
  20. * 修改内容:
  21. */
  22. @Service
  23. @Slf4j
  24. public class AnalysisSearchServiceImpl {
  25. @Autowired
  26. private AnalysisSearchMapper analysisSearchMapper;
  27. @Autowired
  28. private UserService userService;
  29. /**
  30. * 各业务系统分布
  31. * @param type
  32. * @return
  33. */
  34. public Map<String, Double> searchSystemDetailVisits(String type) {
  35. Map<String, Double> map = new HashMap<>();
  36. Calendar calendar = Calendar.getInstance();
  37. int year = calendar.get(Calendar.YEAR);
  38. List<SystemDetailVisitsVo> result = new ArrayList<>();
  39. if (("total").equals(type)){
  40. result = analysisSearchMapper.searchSystemDetailVisits(null,null);
  41. } else if (("year").equals(type)){
  42. result = analysisSearchMapper.searchSystemDetailVisits(DateUtils.format(DateUtils.getFirstOfYear(year)),
  43. DateUtils.format(DateUtils.getLastOfYear(year)));
  44. } else if (("month").equals(type)){
  45. int month = calendar.get(Calendar.MONTH);
  46. String firstOfMonth = DateUtils.getFirstOfMonth(year, month + 1, 15);
  47. String lastOfMonth = DateUtils.getLastOfMonth(year, month + 1, 15);
  48. result = analysisSearchMapper.searchSystemDetailVisits(firstOfMonth, lastOfMonth);
  49. }
  50. result.forEach(e -> map.put(SystemDetailVisitsEnum.getMessage(e.getPlatform()),e.getPercentage()));
  51. return map;
  52. }
  53. /**
  54. * 组织访问量
  55. * @param type
  56. * @param tops
  57. * @param sort
  58. * @return
  59. */
  60. public List<SystemCompanyVo> organizationSearchs(String type, Integer tops, String sort) {
  61. Calendar calendar = Calendar.getInstance();
  62. int year = calendar.get(Calendar.YEAR);
  63. List<SystemCompanyVo> result = new ArrayList<>();
  64. if (("total").equals(type)){
  65. result = analysisSearchMapper.organizationSearchs(null,null,sort);
  66. } else if (("year").equals(type)){
  67. result = analysisSearchMapper.organizationSearchs(DateUtils.format(DateUtils.getFirstOfYear(year)),
  68. DateUtils.format(DateUtils.getLastOfYear(year)),sort);
  69. } else if (("month").equals(type)){
  70. int month = calendar.get(Calendar.MONTH);
  71. String firstOfMonth = DateUtils.getFirstOfMonth(year, month + 1, 15);
  72. String lastOfMonth = DateUtils.getLastOfMonth(year, month + 1, 15);
  73. result = analysisSearchMapper.organizationSearchs(firstOfMonth, lastOfMonth,sort);
  74. }
  75. result = result.stream().limit(tops).collect(Collectors.toList());
  76. //公司名称赋值
  77. result.forEach(e -> e.setCompany(userService.findDeptByDeptId(e.getCompany()).getName()));
  78. return result;
  79. }
  80. }