package com.redxun.knowledge.analysis.service; import com.redxun.knowledge.analysis.entity.enums.SystemDetailVisitsEnum; import com.redxun.knowledge.analysis.entity.vo.SystemCompanyVo; import com.redxun.knowledge.analysis.entity.vo.SystemDetailVisitsVo; import com.redxun.knowledge.analysis.mapper.AnalysisSearchMapper; import com.redxun.knowledge.common.UserService; import com.redxun.knowledge.utils.DateUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.*; import java.util.stream.Collectors; /** * 文件名: AnalysisSearchServiceImpl * 作者: zizg * 时间: 2023/3/23 * 描述: * 修改人: * 修改时间: * 修改内容: */ @Service @Slf4j public class AnalysisSearchServiceImpl { @Autowired private AnalysisSearchMapper analysisSearchMapper; @Autowired private UserService userService; /** * 各业务系统分布 * @param type * @return */ public Map searchSystemDetailVisits(String type) { Map map = new HashMap<>(); Calendar calendar = Calendar.getInstance(); int year = calendar.get(Calendar.YEAR); List result = new ArrayList<>(); if (("total").equals(type)){ result = analysisSearchMapper.searchSystemDetailVisits(null,null); } else if (("year").equals(type)){ result = analysisSearchMapper.searchSystemDetailVisits(DateUtils.format(DateUtils.getFirstOfYear(year)), DateUtils.format(DateUtils.getLastOfYear(year))); } else if (("month").equals(type)){ int month = calendar.get(Calendar.MONTH); String firstOfMonth = DateUtils.getFirstOfMonth(year, month + 1, 15); String lastOfMonth = DateUtils.getLastOfMonth(year, month + 1, 15); result = analysisSearchMapper.searchSystemDetailVisits(firstOfMonth, lastOfMonth); } result.forEach(e -> map.put(SystemDetailVisitsEnum.getMessage(e.getPlatform()),e.getPercentage())); return map; } /** * 组织访问量 * @param type * @param tops * @param sort * @return */ public List organizationSearchs(String type, Integer tops, String sort) { Calendar calendar = Calendar.getInstance(); int year = calendar.get(Calendar.YEAR); List result = new ArrayList<>(); if (("total").equals(type)){ result = analysisSearchMapper.organizationSearchs(null,null,sort); } else if (("year").equals(type)){ result = analysisSearchMapper.organizationSearchs(DateUtils.format(DateUtils.getFirstOfYear(year)), DateUtils.format(DateUtils.getLastOfYear(year)),sort); } else if (("month").equals(type)){ int month = calendar.get(Calendar.MONTH); String firstOfMonth = DateUtils.getFirstOfMonth(year, month + 1, 15); String lastOfMonth = DateUtils.getLastOfMonth(year, month + 1, 15); result = analysisSearchMapper.organizationSearchs(firstOfMonth, lastOfMonth,sort); } result = result.stream().limit(tops).collect(Collectors.toList()); //公司名称赋值 result.forEach(e -> e.setCompany(userService.findDeptByDeptId(e.getCompany()).getName())); return result; } }