package com.gkhy.exam.institutionalaccess.service.serviceImpl; import com.gkhy.exam.institutionalaccess.entity.ThStudyDetail; 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.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; @Service("ThBatchManagerService") public class ThBatchManagerServiceImpl implements ThBatchManagerService { @Autowired private ThBatchService thBatchService; @Autowired private ThBatchCourseService thBatchCourseService; @Autowired private ThStudentCourseService thStudentCourseService; @Autowired private ThStudyDetailService thStudyDetailService; @Override public List listByPage(ThBatchQuery query) { List thBatchVOS = thBatchService.listByPage(query); //统计学员 List thStatisticStudentVOS = thStudentCourseService.statisticByBatchUuid(); if (!CollectionUtils.isEmpty(thBatchVOS)) { List batchUuids = thBatchVOS.stream().map(ThBatchVO::getUuid).collect(Collectors.toList()); List batchCourseVOS = thBatchCourseService.getListByBatchUuids(batchUuids); for (ThBatchVO thBatchVO : thBatchVOS) { //课程 List collect = batchCourseVOS.stream().filter(bc -> bc.getBatchUuid().equals(thBatchVO.getUuid())).collect(Collectors.toList()); //学员 List 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; } @Override public List period(String batchUuid) { //获取批次关联课程 List batchCourseVOS = thBatchCourseService.getListByBatchUuid(batchUuid); //获取关联学生 List thStudentCourseVOS = thStudentCourseService.getListByBatchUuid(batchUuid); //根据批次获取学习记录 List studyVOS = thStudyDetailService.statisticDurationByIdcard(batchUuid); List 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 studentList = thStudentCourseVOS .stream() .filter(sc -> sc.getBatchUuid().equals(VO.getBatchUuid())) .map(sc -> { ThStudentCourseRespDTO thStudentCourseRespDTO = new ThStudentCourseRespDTO(); BeanUtils.copyProperties(sc, thStudentCourseRespDTO); List collect = studyVOS.stream().filter(s -> s.getIdcard().equals(sc.getIdcard())).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 getStudent(String batchUuid) { //获取学生信息 List thStudentCourseVOS = thStudentCourseService.getListByBatchUuid(batchUuid); //获取学生学习记录 List studyDetails = thStudyDetailService.listByBatchUuid(batchUuid); List respDTOS = new ArrayList<>(); if (!CollectionUtils.isEmpty(thStudentCourseVOS)) { for (ThStudentCourseVO VO : thStudentCourseVOS) { ThStudentStudyRespDTO thStudentStudyRespDTO = new ThStudentStudyRespDTO(); thStudentStudyRespDTO.setIdcard(VO.getIdcard()); thStudentStudyRespDTO.setName(VO.getName()); thStudentStudyRespDTO.setCourseName(VO.getCourseName()); thStudentStudyRespDTO.setLessonTocal(VO.getLessTotal()); BigDecimal lessNum = new BigDecimal(0); List 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.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.setFinishStatus(VO.getFinishStatus()); thStudentStudyRespDTO.setLessonNum(lessNum); respDTOS.add(thStudentStudyRespDTO); } } return respDTOS; } }