package com.gkhy.exam.institutionalaccess.service.serviceImpl; import com.gkhy.exam.institutionalaccess.entity.*; import com.gkhy.exam.institutionalaccess.model.query.ThStudyDetailQuery; import com.gkhy.exam.institutionalaccess.model.vo.ThStudyAuthVO; import com.gkhy.exam.institutionalaccess.model.vo.ThStudyDetailVO; import com.gkhy.exam.institutionalaccess.model.vo.ThStudyTrackVO; 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 java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @Service("ThStudyRecordManagerService") public class ThStudyRecordManagerServiceImpl implements ThStudyRecordManagerService { @Autowired private ThStudyDetailService thStudyDetailService; @Autowired private ThStudyTrackService thStudyTrackService; @Autowired private ThStudyAuthService thStudyAuthService; @Autowired private ThCourseChapterService thCourseChapterService;; @Autowired private ThCourseService thCourseService; @Autowired private ThBatchService thBatchService; @Autowired private ThStudentService studentService;; @Override public List listByPage(ThStudyDetailQuery query) { query.setStartSize((query.getPageNum()-1)*query.getPageSize()); List thStudyDetailVOS = thStudyDetailService.listByPage(query); if(!CollectionUtils.isEmpty(thStudyDetailVOS)){ List detailUuids = thStudyDetailVOS.stream().map(ThStudyDetailVO::getUuid).collect(Collectors.toList()); //获取认证记录 List authList = thStudyAuthService.getByStudyDetaiUuids(detailUuids); //获取轨迹 List trackList = thStudyTrackService.getListByStudyDetaiIds(detailUuids); //获取章节名称 List chapterUuids = thStudyDetailVOS.stream().map(ThStudyDetailVO::getChapterUuid).collect(Collectors.toList()); List chapterList = thCourseChapterService.getChapterNameByUuids(chapterUuids); //获取课程名称 List courseUuids = thStudyDetailVOS.stream().map(ThStudyDetailVO::getCourseUuid).collect(Collectors.toList()); List courseList = thCourseService.getCourseNameByUuids(courseUuids); //获取批次名称 List batchUuids = thStudyDetailVOS.stream().map(ThStudyDetailVO::getBatchUuid).collect(Collectors.toList()); List batchList = thBatchService.getBatchNameByUuids(batchUuids); //学生信息 List idcards = thStudyDetailVOS.stream().map(ThStudyDetailVO::getIdcard).collect(Collectors.toList()); List studentList = studentService.getNameByIdcards(idcards); for(ThStudyDetailVO thStudyDetailVO : thStudyDetailVOS){ thStudyDetailVO.setDurationDesc(ConvertTimeUtils.convertTimeToString(thStudyDetailVO.getDuration())); thStudyDetailVO.setStartPositionDesc(ConvertTimeUtils.convertTimeToString(thStudyDetailVO.getStartPosition())); thStudyDetailVO.setFinishPositionDesc(ConvertTimeUtils.convertTimeToString(thStudyDetailVO.getFinishPosition())); List thStudyAuthVOList = authList.stream().filter(a -> a.getStudyDetailUuid().equals(thStudyDetailVO.getUuid())) .map(a -> { ThStudyAuthVO thStudyAuthVO = new ThStudyAuthVO(); BeanUtils.copyProperties(a, thStudyAuthVO); thStudyAuthVO.setAuthPostionDesc(ConvertTimeUtils.convertTimeToString(a.getAuthPosition())); return thStudyAuthVO; }).collect(Collectors.toList()); List trackVOList = trackList.stream().filter(t -> t.getStudyDetailUuid().equals(thStudyDetailVO.getUuid())) .map(t -> { ThStudyTrackVO thStudyTrackVO = new ThStudyTrackVO(); BeanUtils.copyProperties(t, thStudyTrackVO); thStudyTrackVO.setTimeIntervalDesc(ConvertTimeUtils.convertTimeToString(t.getTimeInterval())); return thStudyTrackVO; }).collect(Collectors.toList()); thStudyDetailVO.setAuthList(thStudyAuthVOList); thStudyDetailVO.setTrackList(trackVOList); List chapterSelectList = chapterList.stream().filter(chapter -> chapter.getUuid().equals(thStudyDetailVO.getChapterUuid())).collect(Collectors.toList()); if(!CollectionUtils.isEmpty(chapterSelectList)){ thStudyDetailVO.setChapterName(chapterSelectList.get(0).getChapterName()); } List courseSelectList = courseList.stream().filter(c -> c.getUuid().equals(thStudyDetailVO.getCourseUuid())).collect(Collectors.toList()); if(!CollectionUtils.isEmpty(courseSelectList)){ thStudyDetailVO.setCourseName(courseSelectList.get(0).getCourseName()); } List batchSelectList = batchList.stream().filter(b -> b.getUuid().equals(thStudyDetailVO.getBatchUuid())).collect(Collectors.toList()); if(!CollectionUtils.isEmpty(batchSelectList)){ thStudyDetailVO.setBatchName(batchSelectList.get(0).getBatchName()); } List studentSelectList = studentList.stream().filter(thStudent -> thStudent.getIdcard().equals(thStudyDetailVO.getIdcard())).collect(Collectors.toList()); if(!CollectionUtils.isEmpty(studentSelectList)){ thStudyDetailVO.setName(studentSelectList.get(0).getName()); } } } return thStudyDetailVOS; } }