“djh”
5 天以前 7acaebcb01438578ded72491f39105db893982ef
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
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();
        }
        if(startTime==null && endTime==null){
            endTime=new Date();
            startTime=DateUtil.offsetDay(endTime,-7);
        }else if(startTime!=null&&endTime==null){
            endTime=DateUtil.offsetDay(startTime,7);
        }else if(startTime==null&&endTime!=null){
            startTime=DateUtil.offsetDay(endTime,-7);
        }
        PageUtils.startPage();
        List<SysCompany> companyList=companyMapper.selectCompanyList(new SysCompany().setId(companyId));
        CommonPage commonPage= CommonPage.restPage(companyList);
        if(companyList.size()>0) {
            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.getCode())){
                        companyStatisticVO.setLevel1PhaseCount(cp.getPhaseCount());
                    }else if(cp.getLevel().equals(PhaseLevelEnum.DEPART.getCode())){
                        companyStatisticVO.setLevel2PhaseCount(cp.getPhaseCount());
                    }else if(cp.getLevel().equals(PhaseLevelEnum.WORkSHOP.getCode())) {
                        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.getCode())){
                        companyStatisticVO.setLevel1StudentCount(cp.getPhaseStudentCount());
                    }else if(cp.getLevel().equals(PhaseLevelEnum.DEPART.getCode())){
                        companyStatisticVO.setLevel2StudentCount(cp.getPhaseStudentCount());
                    }else if(cp.getLevel().equals(PhaseLevelEnum.WORkSHOP.getCode())) {
                        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;
    }
}