教育训练处考试制证系统后端
zhangf
2024-09-11 1a316551c8e46b793904090cfa84781bf77fef2a
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
package com.gkhy.exam.institutionalaccess.service.serviceImpl;
 
 
import com.gkhy.exam.institutionalaccess.entity.*;
import com.gkhy.exam.institutionalaccess.enums.FinishStatus;
import com.gkhy.exam.institutionalaccess.model.query.ThBatchQuery;
import com.gkhy.exam.institutionalaccess.model.resp.ThBatchCourseRespDTO;
import com.gkhy.exam.institutionalaccess.model.resp.ThStudentCourseRespDTO;
import com.gkhy.exam.institutionalaccess.model.resp.ThStudentStudyRespDTO;
import com.gkhy.exam.institutionalaccess.model.vo.*;
import com.gkhy.exam.institutionalaccess.service.*;
import com.gkhy.exam.institutionalaccess.utils.ConvertTimeUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
 
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
 
@Service("ThBatchManagerService")
public class ThBatchManagerServiceImpl implements ThBatchManagerService {
    @Autowired
    private ThBatchService thBatchService;
    @Autowired
    private ThBatchCourseService thBatchCourseService;
    @Autowired
    private ThStudentBatchService thStudentBatchService;
    @Autowired
    private ThStudyDetailService thStudyDetailService;
    @Autowired
    private ThBatchCourseChapterService thBatchCourseChapterService;
    @Autowired
    private ThSubjectTypeService subjectTypeService;
 
    @Override
    public List<ThBatchVO> listByPage(ThBatchQuery query) {
        List<ThBatchVO> thBatchVOS = thBatchService.listByPage(query);
        //统计学员
        List<ThStatisticStudentVO> thStatisticStudentVOS = thStudentBatchService.statisticByBatchUuid();
        if (!CollectionUtils.isEmpty(thBatchVOS)) {
            List<String> batchUuids = thBatchVOS.stream().map(ThBatchVO::getUuid).collect(Collectors.toList());
            List<ThBatchCourse> batchCourseList = thBatchCourseService.getListByBatchUuids(batchUuids);
            //章节
            List<ThBatchCourseChapter> chapterList = thBatchCourseChapterService.getListByBatchUuids(batchUuids);
 
            for (ThBatchVO thBatchVO : thBatchVOS) {
                thBatchVO.setSubjectName(getObtainSuperiors(thBatchVO.getSubjectCode()));
                //课程
                List<ThBatchCourseVO> collect = batchCourseList.stream()
                        .filter(bc -> bc.getBatchUuid().equals(thBatchVO.getUuid()))
                        .map(bc -> {
                            ThBatchCourseVO thBatchCourseVO = new ThBatchCourseVO();
                            BeanUtils.copyProperties(bc, thBatchCourseVO);
 
                            List<ThBatchCourseChapterVO> chapterVOs = chapterList.stream().
                                    filter(cc -> cc.getCourseUuid().equals(bc.getCourseUuid()) && cc.getParentUuid().equals("0"))
                                    .map(cc -> {
                                        ThBatchCourseChapterVO thBatchCourseChapterVO = new ThBatchCourseChapterVO();
                                        BeanUtils.copyProperties(cc, thBatchCourseChapterVO);
                                        thBatchCourseChapterVO.setChildren(getChildren(chapterList,cc.getChapterUuid()));
                                        return thBatchCourseChapterVO;
                                    })
                                    .collect(Collectors.toList());
                            thBatchCourseVO.setChapterList(chapterVOs);
                            return thBatchCourseVO;
                        })
                        .collect(Collectors.toList());
                //学员
                List<ThStatisticStudentVO> ssList = thStatisticStudentVOS.stream().filter(ss -> ss.getBatchUuid().equals(thBatchVO.getUuid())).collect(Collectors.toList());
                if(ssList.size() > 0) {
                    thBatchVO.setStudentCount(ssList.get(0).getCount());
                }else {
                    thBatchVO.setStudentCount(0);
                }
                thBatchVO.setCourseVOList(collect);
            }
        }
        return thBatchVOS;
    }
 
    //获取章节
    private List<ThBatchCourseChapterVO> getChildren(List<ThBatchCourseChapter> chapterList, String parentUuid) {
        List<ThBatchCourseChapterVO> sectionList = chapterList
                .stream()
                .filter(cc -> cc.getParentUuid().equals(parentUuid))
                .map(cc -> {
                    ThBatchCourseChapterVO thBatchCourseChapterVO = new ThBatchCourseChapterVO();
                    BeanUtils.copyProperties(cc, thBatchCourseChapterVO);
                    return thBatchCourseChapterVO;
                })
                .collect(Collectors.toList());
        return sectionList;
    }
 
 
    @Override
    public List<ThBatchCourseRespDTO> period(String batchUuid) {
        //获取批次关联课程(课程的视频总时长)
        List<ThBatchCourseVO> batchCourseVOS = thBatchCourseService.getListByBatchUuid(batchUuid);
        //获取关联学生(学时)
        List<ThStudentBatchCourseVO> thStudentCourseVOS = thStudentBatchService.getStudentBatchCourseVOByBatchUuid(batchUuid);
        //根据批次获取学习记录
        List<ThStudyVO> studyVOS = thStudyDetailService.statisticDurationByIdcard(batchUuid);
        List<ThBatchCourseRespDTO> batchCourseRespDTOS = new ArrayList<>();
        if (!CollectionUtils.isEmpty(batchCourseVOS)) {
            for (ThBatchCourseVO VO : batchCourseVOS) {
                ThBatchCourseRespDTO thBatchCourseRespDTO = new ThBatchCourseRespDTO();
                BeanUtils.copyProperties(VO, thBatchCourseRespDTO);
                //视频时长
                thBatchCourseRespDTO.setDurationDesc(ConvertTimeUtils.convertTimeToString(VO.getDuration()));
                //过滤学生
                List<ThStudentCourseRespDTO> studentList = thStudentCourseVOS
                        .stream()
                        .filter(sc -> sc.getCourseUuid().equals(VO.getCourseUuid()))
                        .map(sc -> {
                            ThStudentCourseRespDTO thStudentCourseRespDTO = new ThStudentCourseRespDTO();
                            BeanUtils.copyProperties(sc, thStudentCourseRespDTO);
                            List<ThStudyVO> collect = studyVOS.stream().filter(s -> s.getIdcard().equals(sc.getIdcard()) && s.getCourseUuid().equals(VO.getCourseUuid())).collect(Collectors.toList());
                           if(collect.size() > 0) {
                               thStudentCourseRespDTO.setDuration(collect.get(0).getDuration());
                           }else {
                               thStudentCourseRespDTO.setDuration(0l);
                           }
                            return thStudentCourseRespDTO;
                        })
                        .collect(Collectors.toList());
                thBatchCourseRespDTO.setStudentList(studentList);
                batchCourseRespDTOS.add(thBatchCourseRespDTO);
            }
        }
 
 
        return batchCourseRespDTOS;
    }
 
    @Override
    public List<ThStudentStudyRespDTO> getStudent(String batchUuid) {
        //获取学生信息
        List<ThStudentBatchVO> thStudentBatches = thStudentBatchService.getStudentBatchVOByBatchUuid(batchUuid);
        //获取学生学习记录
        List<ThStudyDetailVO> studyDetails = thStudyDetailService.listByBatchUuid(batchUuid);
        List<ThStudentStudyRespDTO> respDTOS = new ArrayList<>();
        if (!CollectionUtils.isEmpty(thStudentBatches)) {
            for (ThStudentBatchVO VO : thStudentBatches) {
                ThStudentStudyRespDTO thStudentStudyRespDTO = new ThStudentStudyRespDTO();
                thStudentStudyRespDTO.setIdcard(VO.getIdcard());
                thStudentStudyRespDTO.setName(VO.getName());
                thStudentStudyRespDTO.setBatchLessonNum(VO.getBatchLessonNum());
                thStudentStudyRespDTO.setFinishStatus(VO.getFinishStatus());
                thStudentStudyRespDTO.setBatchUuid(VO.getBatchUuid());
                BigDecimal lessNum = new BigDecimal(0);
 
                List<ThStudyDetailVO> collect = studyDetails
                        .stream()
                        .filter(sd -> sd.getIdcard().equals(VO.getIdcard()))
                        .collect(Collectors.toList());
                StringBuffer stringBuffer = new StringBuffer();
                for (ThStudyDetailVO studyDetail : collect) {
                    //是否完成
                    if(studyDetail.getFinishStatus().equals(FinishStatus.YES.getStatus())){
                        lessNum = lessNum.add(studyDetail.getLessonNum());
                    }
                    //是否有学时报告
                    if(!StringUtils.isEmpty(studyDetail.getLessonReportUrl())){
                        stringBuffer.append(studyDetail.getLessonReportUrl()).append(",");
                    }
                }
                if(!StringUtils.isEmpty(stringBuffer.toString())){
                    stringBuffer.deleteCharAt(stringBuffer.length()-1);
                }
                thStudentStudyRespDTO.setUrl(stringBuffer.toString());
                thStudentStudyRespDTO.setLessonNum(lessNum);
                respDTOS.add(thStudentStudyRespDTO);
            }
        }
        return respDTOS;
    }
 
    public String getObtainSuperiors(String code){
        List<ThSubjectType> subjectTypeList = subjectTypeService.getSubjectTypeList();
        if(StringUtils.isEmpty(code)){
            return "未知";
        }
        StringBuffer stringBuffer = new StringBuffer();
        String subjectName = "未知";
        ThSubjectType currentSubject = getThSubejctInfoByCode(subjectTypeList,code);
        if(currentSubject != null){
            subjectName = currentSubject.getName();
        }
        //一级
        if(code.length() == 1){
            stringBuffer.append(subjectName);
        }
        //二级
        if(code.length() == 3){
            ThSubjectType parentSubject = getThSubejctInfoByCode(subjectTypeList,currentSubject.getParentCode());
            stringBuffer.append(parentSubject.getName()).append("/").append(subjectName);
        }
        //三级
        if(code.length() == 5){
            ThSubjectType parentSubject = getThSubejctInfoByCode(subjectTypeList,currentSubject.getParentCode());
            ThSubjectType grandpaSubject = getThSubejctInfoByCode(subjectTypeList,parentSubject.getParentCode());
            stringBuffer.append(grandpaSubject.getName()).append("/").append(parentSubject.getName()).append("/").append(subjectName);
        }
        return stringBuffer.toString();
    }
   public ThSubjectType getThSubejctInfoByCode(List<ThSubjectType> list, String code){
       List<ThSubjectType> selectList = list.stream().filter(subjectType -> subjectType.getCode().equals(code)).collect(Collectors.toList());
        if(selectList.size() > 0){
            return selectList.get(0);
        }
        return null;
   }
}