From 1a316551c8e46b793904090cfa84781bf77fef2a Mon Sep 17 00:00:00 2001
From: zhangf <1603559716@qq.com>
Date: 星期三, 11 九月 2024 15:51:49 +0800
Subject: [PATCH] 增加科目类别

---
 exam-system/src/main/java/com/gkhy/exam/institutionalaccess/service/serviceImpl/ThBatchManagerServiceImpl.java |  112 +++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 94 insertions(+), 18 deletions(-)

diff --git a/exam-system/src/main/java/com/gkhy/exam/institutionalaccess/service/serviceImpl/ThBatchManagerServiceImpl.java b/exam-system/src/main/java/com/gkhy/exam/institutionalaccess/service/serviceImpl/ThBatchManagerServiceImpl.java
index 6cc4a93..34efd7f 100644
--- a/exam-system/src/main/java/com/gkhy/exam/institutionalaccess/service/serviceImpl/ThBatchManagerServiceImpl.java
+++ b/exam-system/src/main/java/com/gkhy/exam/institutionalaccess/service/serviceImpl/ThBatchManagerServiceImpl.java
@@ -1,7 +1,7 @@
 package com.gkhy.exam.institutionalaccess.service.serviceImpl;
 
 
-import com.gkhy.exam.institutionalaccess.entity.ThStudyDetail;
+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;
@@ -19,7 +19,6 @@
 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")
@@ -29,21 +28,47 @@
     @Autowired
     private ThBatchCourseService thBatchCourseService;
     @Autowired
-    private ThStudentCourseService thStudentCourseService;
+    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 = thStudentCourseService.statisticByBatchUuid();
+        List<ThStatisticStudentVO> thStatisticStudentVOS = thStudentBatchService.statisticByBatchUuid();
         if (!CollectionUtils.isEmpty(thBatchVOS)) {
             List<String> batchUuids = thBatchVOS.stream().map(ThBatchVO::getUuid).collect(Collectors.toList());
-            List<ThBatchCourseVO> batchCourseVOS = thBatchCourseService.getListByBatchUuids(batchUuids);
+            List<ThBatchCourse> batchCourseList = thBatchCourseService.getListByBatchUuids(batchUuids);
+            //章节
+            List<ThBatchCourseChapter> chapterList = thBatchCourseChapterService.getListByBatchUuids(batchUuids);
+
             for (ThBatchVO thBatchVO : thBatchVOS) {
+                thBatchVO.setSubjectName(getObtainSuperiors(thBatchVO.getSubjectCode()));
                 //课程
-                List<ThBatchCourseVO> collect = batchCourseVOS.stream().filter(bc -> bc.getBatchUuid().equals(thBatchVO.getUuid())).collect(Collectors.toList());
+                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) {
@@ -57,12 +82,27 @@
         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<ThStudentCourseVO> thStudentCourseVOS = thStudentCourseService.getListByBatchUuid(batchUuid);
+        //获取关联学生(学时)
+        List<ThStudentBatchCourseVO> thStudentCourseVOS = thStudentBatchService.getStudentBatchCourseVOByBatchUuid(batchUuid);
         //根据批次获取学习记录
         List<ThStudyVO> studyVOS = thStudyDetailService.statisticDurationByIdcard(batchUuid);
         List<ThBatchCourseRespDTO> batchCourseRespDTOS = new ArrayList<>();
@@ -75,11 +115,11 @@
                 //过滤学生
                 List<ThStudentCourseRespDTO> studentList = thStudentCourseVOS
                         .stream()
-                        .filter(sc -> sc.getBatchUuid().equals(VO.getBatchUuid()))
+                        .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())).collect(Collectors.toList());
+                            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 {
@@ -100,17 +140,18 @@
     @Override
     public List<ThStudentStudyRespDTO> getStudent(String batchUuid) {
         //获取学生信息
-        List<ThStudentCourseVO> thStudentCourseVOS = thStudentCourseService.getListByBatchUuid(batchUuid);
+        List<ThStudentBatchVO> thStudentBatches = thStudentBatchService.getStudentBatchVOByBatchUuid(batchUuid);
         //获取学生学习记录
         List<ThStudyDetailVO> studyDetails = thStudyDetailService.listByBatchUuid(batchUuid);
         List<ThStudentStudyRespDTO> respDTOS = new ArrayList<>();
-        if (!CollectionUtils.isEmpty(thStudentCourseVOS)) {
-            for (ThStudentCourseVO VO : thStudentCourseVOS) {
+        if (!CollectionUtils.isEmpty(thStudentBatches)) {
+            for (ThStudentBatchVO VO : thStudentBatches) {
                 ThStudentStudyRespDTO thStudentStudyRespDTO = new ThStudentStudyRespDTO();
                 thStudentStudyRespDTO.setIdcard(VO.getIdcard());
                 thStudentStudyRespDTO.setName(VO.getName());
-                thStudentStudyRespDTO.setCourseName(VO.getCourseName());
-                thStudentStudyRespDTO.setLessonTocal(VO.getLessTotal());
+                thStudentStudyRespDTO.setBatchLessonNum(VO.getBatchLessonNum());
+                thStudentStudyRespDTO.setFinishStatus(VO.getFinishStatus());
+                thStudentStudyRespDTO.setBatchUuid(VO.getBatchUuid());
                 BigDecimal lessNum = new BigDecimal(0);
 
                 List<ThStudyDetailVO> collect = studyDetails
@@ -121,7 +162,7 @@
                 for (ThStudyDetailVO studyDetail : collect) {
                     //是否完成
                     if(studyDetail.getFinishStatus().equals(FinishStatus.YES.getStatus())){
-                        lessNum.add(studyDetail.getLessonNum());
+                        lessNum = lessNum.add(studyDetail.getLessonNum());
                     }
                     //是否有学时报告
                     if(!StringUtils.isEmpty(studyDetail.getLessonReportUrl())){
@@ -132,11 +173,46 @@
                     stringBuffer.deleteCharAt(stringBuffer.length()-1);
                 }
                 thStudentStudyRespDTO.setUrl(stringBuffer.toString());
-                thStudentStudyRespDTO.setFinishStatus(VO.getFinishStatus());
                 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;
+   }
 }

--
Gitblit v1.9.2