package com.gkhy.exam.system.service.impl;
|
|
import cn.hutool.core.date.DateUtil;
|
import com.gkhy.exam.common.api.CommonPage;
|
import com.gkhy.exam.common.domain.entity.SysUser;
|
import com.gkhy.exam.common.enums.PhaseLevelEnum;
|
import com.gkhy.exam.common.enums.UserTypeEnum;
|
import com.gkhy.exam.common.utils.PageUtils;
|
import com.gkhy.exam.common.utils.SecurityUtils;
|
import com.gkhy.exam.system.domain.SysCompany;
|
import com.gkhy.exam.system.domain.vo.CompanyPaperStudentVO;
|
import com.gkhy.exam.system.domain.vo.CompanyPhaseStudentVO;
|
import com.gkhy.exam.system.domain.vo.CompanyPhaseVO;
|
import com.gkhy.exam.system.domain.vo.CompanyStatisticVO;
|
import com.gkhy.exam.system.mapper.SysCompanyMapper;
|
import com.gkhy.exam.system.service.ExStatisticService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.util.Date;
|
import java.util.LinkedHashMap;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.stream.Collectors;
|
|
@Service
|
public class ExStatisticServiceImpl implements ExStatisticService {
|
@Autowired
|
private SysCompanyMapper companyMapper;
|
@Override
|
public CommonPage companyStatic(Long companyId, Date startTime, Date endTime,Integer type) {
|
SysUser user= SecurityUtils.getLoginUser().getUser();
|
if(!user.getUserType().equals(UserTypeEnum.SYSTEM_USER.getCode())){
|
companyId=user.getCompanyId();
|
}
|
PageUtils.startPage();
|
List<SysCompany> companyList=companyMapper.selectCompanyList(new SysCompany().setId(companyId));
|
CommonPage commonPage= CommonPage.restPage(companyList);
|
List<CompanyStatisticVO>companyStatisticVOList=staticData(companyList, DateUtil.formatDateTime(DateUtil.beginOfDay(startTime)),DateUtil.formatDateTime(DateUtil.endOfDay(endTime)),type);
|
commonPage.setList(companyStatisticVOList);
|
return commonPage;
|
}
|
|
public List<CompanyStatisticVO> staticData(List<SysCompany> companyList,String startTime,String endTime,Integer type){
|
List<Long> companyIds=companyList.stream().map(item -> item.getId()).collect(Collectors.toList());
|
|
List<CompanyPhaseVO> companyPhaseVOList=null;
|
if(type==1) {
|
companyPhaseVOList=companyMapper.getOnlineCompanyPhaseCount(companyIds, startTime, endTime);
|
}else{
|
companyPhaseVOList=companyMapper.getOfflineCompanyPhaseCount(companyIds, startTime, endTime);
|
}
|
Map<Long,List<CompanyPhaseVO>> companyPhaseVOMap=companyPhaseVOList.stream().collect(Collectors.groupingBy(CompanyPhaseVO::getCompanyId, LinkedHashMap::new,Collectors.toList()));
|
List<CompanyPhaseStudentVO> companyPhaseStudentVOList=null;
|
if(type==1) {
|
companyPhaseStudentVOList=companyMapper.getOnlineCompanyPhaseStudentCount(companyIds, startTime, endTime);
|
}else{
|
companyPhaseStudentVOList=companyMapper.getOfflineCompanyPhaseStudentCount(companyIds, startTime, endTime);
|
}
|
Map<Long,List<CompanyPhaseStudentVO>> companyPhaseStudentVOMap=companyPhaseStudentVOList.stream().collect(Collectors.groupingBy(CompanyPhaseStudentVO::getCompanyId,LinkedHashMap::new,Collectors.toList()));
|
|
List<CompanyPaperStudentVO> companyPaperStudentVOList=null;
|
if(type==1) {
|
companyPaperStudentVOList=companyMapper.getOnlineCompanyPaperStudentCount(companyIds, startTime, endTime);
|
}else{
|
companyPaperStudentVOList=companyMapper.getOfflineCompanyPaperStudentCount(companyIds, startTime, endTime);
|
}
|
Map<Long,CompanyPaperStudentVO> companyPaperStudentVOMap=companyPaperStudentVOList.stream().collect(Collectors.toMap(CompanyPaperStudentVO::getCompanyId,a ->a));
|
List<CompanyStatisticVO> companyStatisticVOList=companyList.stream().map(item -> {
|
CompanyStatisticVO companyStatisticVO=new CompanyStatisticVO();
|
companyStatisticVO.setCompanyId(item.getId());
|
companyStatisticVO.setCompanyName(item.getName());
|
List<CompanyPhaseVO> companyPhaseVOs=companyPhaseVOMap.get(item.getId());
|
if(companyPhaseVOs!=null&&companyPhaseVOs.size()>0){
|
companyPhaseVOs.forEach(cp -> {
|
if(cp.getLevel().equals(PhaseLevelEnum.COMPANY)){
|
companyStatisticVO.setLevel1PhaseCount(cp.getPhaseCount());
|
}else if(cp.getLevel().equals(PhaseLevelEnum.DEPART)){
|
companyStatisticVO.setLevel2PhaseCount(cp.getPhaseCount());
|
}else if(cp.getLevel().equals(PhaseLevelEnum.WORkSHOP)) {
|
companyStatisticVO.setLevel3PhaseCount(cp.getPhaseCount());
|
}
|
});
|
companyStatisticVO.setPhaseCount(companyPhaseVOs.stream().mapToInt(CompanyPhaseVO::getPhaseCount).sum());
|
}
|
List<CompanyPhaseStudentVO> companyPhaseStudentVOs=companyPhaseStudentVOMap.get(item.getId());
|
if(companyPhaseStudentVOs!=null&&companyPhaseStudentVOs.size()>0){
|
companyPhaseStudentVOs.forEach(cp -> {
|
if(cp.getLevel().equals(PhaseLevelEnum.COMPANY)){
|
companyStatisticVO.setLevel1StudentCount(cp.getPhaseStudentCount());
|
}else if(cp.getLevel().equals(PhaseLevelEnum.DEPART)){
|
companyStatisticVO.setLevel2StudentCount(cp.getPhaseStudentCount());
|
}else if(cp.getLevel().equals(PhaseLevelEnum.WORkSHOP)) {
|
companyStatisticVO.setLevel3StudentCount(cp.getPhaseStudentCount());
|
}
|
});
|
companyStatisticVO.setPhaseStudentCount(companyPhaseStudentVOs.stream().mapToInt(CompanyPhaseStudentVO::getPhaseStudentCount).sum());
|
}
|
CompanyPaperStudentVO companyPaperStudentVO=companyPaperStudentVOMap.get(item.getId());
|
if(companyPaperStudentVO!=null){
|
companyStatisticVO.setPaperStudentCount(companyPaperStudentVO.getPaperStudentCount());
|
companyStatisticVO.setPassStudentCount(companyPaperStudentVO.getPassStudentCount());
|
}
|
return companyStatisticVO;
|
}).collect(Collectors.toList());
|
return companyStatisticVOList;
|
}
|
}
|