package com.gkhy.exam.institutionalaccess.service.serviceImpl; import com.gkhy.exam.institutionalaccess.entity.*; import com.gkhy.exam.institutionalaccess.enums.CourseStatus; import com.gkhy.exam.institutionalaccess.enums.FinishStatus; import com.gkhy.exam.institutionalaccess.model.query.ThCourseQuery; import com.gkhy.exam.institutionalaccess.model.resp.ThCourseChapterRespDTO; import com.gkhy.exam.institutionalaccess.model.resp.ThCourseRespDTO; import com.gkhy.exam.institutionalaccess.model.resp.ThStudentStudyRespDTO; import com.gkhy.exam.institutionalaccess.model.vo.ThCourseChapterVO; import com.gkhy.exam.institutionalaccess.model.vo.ThStatisticStudentVO; import com.gkhy.exam.institutionalaccess.model.vo.ThStudentBatchVO; import com.gkhy.exam.institutionalaccess.model.vo.ThStudyDetailVO; import com.gkhy.exam.institutionalaccess.service.*; 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("ThCourseManagerService") public class ThCourseManagerServiceImpl implements ThCourseManagerService { @Autowired private ThCourseService courseService; @Autowired private ThCourseChapterService courseChapterService; @Autowired private ThStudentBatchService studentBatchService; @Autowired private ThStudentBatchService thStudentBatchService; @Autowired private ThStudyDetailService studyDetailService; @Override public List listByPage(ThCourseQuery query) { List courseList = courseService.listByPage(query); //分许获取数据 List thStatisticStudentVOS = studentBatchService.statisticByCourseUuid(); //List courseRespDTOList = new ArrayList<>(); if(!CollectionUtils.isEmpty(courseList)){ //根据courseids获取所有章节 List courseChapterVOS = new ArrayList<>(); List courseUuids = courseList.stream().map(ThCourseRespDTO::getUuid).collect(Collectors.toList()); if(!CollectionUtils.isEmpty(courseUuids)){ courseChapterVOS = courseChapterService.listByCourseUuids(courseUuids); } for (ThCourseRespDTO courseRespDTO : courseList) { //获取章 List finalCourseChapterVOS = courseChapterVOS; List chapterList = courseChapterVOS .stream() .filter(cc -> courseRespDTO.getUuid().equals(cc.getCourseUuid()) && cc.getParentUuid().equals("0")) .map(cc -> { ThCourseChapterRespDTO courseChapterRespDTO = new ThCourseChapterRespDTO(); BeanUtils.copyProperties(cc, courseChapterRespDTO); courseChapterRespDTO.setChildren(getChildren(finalCourseChapterVOS,cc.getUuid())); return courseChapterRespDTO; }) .collect(Collectors.toList()); courseRespDTO.setOutline(chapterList); //学员数量 List statisticList = thStatisticStudentVOS.stream().filter(s -> s.getCourseUuid().equals(courseRespDTO.getUuid())).collect(Collectors.toList()); if(statisticList.size()>0){ ThStatisticStudentVO thStatisticStudentVO = statisticList.get(0); courseRespDTO.setStudentCount(thStatisticStudentVO.getCount()); }else { courseRespDTO.setStudentCount(0); } } } return courseList; } //获取单条课程 @Override public ThCourseRespDTO findById(Long id) { ThCourse thCourse = courseService.getById(id); ThCourseRespDTO thCourseRespDTO = new ThCourseRespDTO(); BeanUtils.copyProperties(thCourse, thCourseRespDTO); List thCourseChapterVOS = courseChapterService.listByCourseUuid(thCourse.getUuid()); List chapterRespDTOS = thCourseChapterVOS.stream() .filter(c -> c.getParentUuid().equals("0")) .map(c -> { ThCourseChapterRespDTO chapterRespDTO = new ThCourseChapterRespDTO(); BeanUtils.copyProperties(c, chapterRespDTO); chapterRespDTO.setChildren(getChildren(thCourseChapterVOS,c.getUuid())); return chapterRespDTO; }).collect(Collectors.toList()); thCourseRespDTO.setOutline(chapterRespDTOS); return thCourseRespDTO; } @Override public List getSutdent(String courseUuid) { //获取该课程下所有学生 //获取学生信息 List thStudentBatches = thStudentBatchService.getStudentBatchVOByCourseUuid(courseUuid); //获取学生学习记录 List studyDetails = studyDetailService.listByCourseUuid(courseUuid); List 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()); thStudentStudyRespDTO.setCourseLessonNum(VO.getCourseLessonNum()); 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 = 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; } //课程审核 @Override public Boolean updateByCourse(ThCourseDTO thCourseDTO) { if (StringUtils.isEmpty(thCourseDTO.getStatus()) || StringUtils.isEmpty(thCourseDTO.getId())){ return false; } ThCourse byUuid = courseService.getById(thCourseDTO.getId()); if (!byUuid.getStatus().equals(CourseStatus.REVIEWED.getStatus())){ return false; } ThCourse thCourse = new ThCourse(); thCourse.setId(thCourseDTO.getId()); thCourse.setStatus(thCourseDTO.getStatus()); return courseService.updateById(thCourse); } //获取章节 private List getChildren(List courseChapterVOS, String parentUuid) { List chapterList = courseChapterVOS .stream() .filter(cc -> cc.getParentUuid().equals(parentUuid)) .map(cc -> { ThCourseChapterRespDTO courseChapterRespDTO = new ThCourseChapterRespDTO(); BeanUtils.copyProperties(cc, courseChapterRespDTO); return courseChapterRespDTO; }) .collect(Collectors.toList()); return chapterList; } }