From 790c2ba4a0b46edf191e3bac84931f796bd42b8f Mon Sep 17 00:00:00 2001 From: zhangf <1603559716@qq.com> Date: 星期三, 24 七月 2024 09:02:49 +0800 Subject: [PATCH] 三方对接接口优化 --- exam-system/src/main/java/com/gkhy/exam/institutionalaccess/service/serviceImpl/ThCourseManagerServiceImpl.java | 79 +++++++++++++++++++++++++++++++++------ 1 files changed, 67 insertions(+), 12 deletions(-) diff --git a/exam-system/src/main/java/com/gkhy/exam/institutionalaccess/service/serviceImpl/ThCourseManagerServiceImpl.java b/exam-system/src/main/java/com/gkhy/exam/institutionalaccess/service/serviceImpl/ThCourseManagerServiceImpl.java index 4593d20..bcccccd 100644 --- a/exam-system/src/main/java/com/gkhy/exam/institutionalaccess/service/serviceImpl/ThCourseManagerServiceImpl.java +++ b/exam-system/src/main/java/com/gkhy/exam/institutionalaccess/service/serviceImpl/ThCourseManagerServiceImpl.java @@ -1,19 +1,28 @@ package com.gkhy.exam.institutionalaccess.service.serviceImpl; +import com.gkhy.exam.institutionalaccess.entity.ThBatchCourse; import com.gkhy.exam.institutionalaccess.entity.ThCourse; import com.gkhy.exam.institutionalaccess.entity.ThCourseChapter; +import com.gkhy.exam.institutionalaccess.entity.ThStudentBatch; +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.Collections; import java.util.List; import java.util.stream.Collectors; @@ -25,32 +34,34 @@ @Autowired private ThCourseChapterService courseChapterService; @Autowired - private ThStudentCourseService studentCourseService; + private ThStudentBatchService studentBatchService; + @Autowired + private ThStudentBatchService thStudentBatchService; + @Autowired + private ThStudyDetailService studyDetailService; @Override public List<ThCourseRespDTO> listByPage(ThCourseQuery query) { - List<ThCourse> courseList = courseService.listByPage(query); + List<ThCourseRespDTO> courseList = courseService.listByPage(query); //分许获取数据 - List<ThStatisticStudentVO> thStatisticStudentVOS = studentCourseService.statisticByCourseUuid(); + List<ThStatisticStudentVO> thStatisticStudentVOS = studentBatchService.statisticByCourseUuid(); - List<ThCourseRespDTO> courseRespDTOList = new ArrayList<>(); + //List<ThCourseRespDTO> courseRespDTOList = new ArrayList<>(); if(!CollectionUtils.isEmpty(courseList)){ //根据courseids获取所有章节 List<ThCourseChapterVO> courseChapterVOS = new ArrayList<>(); - List<String> courseUuids = courseList.stream().map(ThCourse::getUuid).collect(Collectors.toList()); + List<String> courseUuids = courseList.stream().map(ThCourseRespDTO::getUuid).collect(Collectors.toList()); if(!CollectionUtils.isEmpty(courseUuids)){ courseChapterVOS = courseChapterService.listByCourseUuids(courseUuids); } - for (ThCourse course : courseList) { - ThCourseRespDTO courseRespDTO = new ThCourseRespDTO(); - BeanUtils.copyProperties(course, courseRespDTO); + for (ThCourseRespDTO courseRespDTO : courseList) { //获取章 List<ThCourseChapterVO> finalCourseChapterVOS = courseChapterVOS; List<ThCourseChapterRespDTO> chapterList = courseChapterVOS .stream() - .filter(cc -> course.getUuid().equals(cc.getCourseUuid()) && cc.getParentUuid().equals("0")) + .filter(cc -> courseRespDTO.getUuid().equals(cc.getCourseUuid()) && cc.getParentUuid().equals("0")) .map(cc -> { ThCourseChapterRespDTO courseChapterRespDTO = new ThCourseChapterRespDTO(); BeanUtils.copyProperties(cc, courseChapterRespDTO); @@ -60,17 +71,16 @@ .collect(Collectors.toList()); courseRespDTO.setOutline(chapterList); //学员数量 - List<ThStatisticStudentVO> statisticList = thStatisticStudentVOS.stream().filter(s -> s.getCourseUuid().equals(course.getUuid())).collect(Collectors.toList()); + List<ThStatisticStudentVO> 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); } - courseRespDTOList.add(courseRespDTO); } } - return courseRespDTOList; + return courseList; } //获取单条课程 @@ -92,6 +102,51 @@ return thCourseRespDTO; } + @Override + public List<ThStudentStudyRespDTO> getSutdent(String courseUuid) { + //获取该课程下所有学生 + //获取学生信息 + List<ThStudentBatchVO> thStudentBatches = thStudentBatchService.getStudentBatchVOByCourseUuid(courseUuid); + //获取学生学习记录 + List<ThStudyDetailVO> studyDetails = studyDetailService.listByCourseUuid(courseUuid); + 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()); + thStudentStudyRespDTO.setCourseLessonNum(VO.getCourseLessonNum()); + 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; + } + //获取章节 private List<ThCourseChapterRespDTO> getChildren(List<ThCourseChapterVO> courseChapterVOS, String parentUuid) { List<ThCourseChapterRespDTO> chapterList = courseChapterVOS -- Gitblit v1.9.2