zhangf
2024-09-11 1a316551c8e46b793904090cfa84781bf77fef2a
exam-system/src/main/java/com/gkhy/exam/institutionalaccess/service/serviceImpl/ThBatchManagerServiceImpl.java
@@ -1,14 +1,10 @@
package com.gkhy.exam.institutionalaccess.service.serviceImpl;
import com.gkhy.exam.institutionalaccess.entity.ThBatchCourse;
import com.gkhy.exam.institutionalaccess.entity.ThBatchCourseChapter;
import com.gkhy.exam.institutionalaccess.entity.ThStudentBatch;
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;
import com.gkhy.exam.institutionalaccess.model.resp.ThCourseChapterRespDTO;
import com.gkhy.exam.institutionalaccess.model.resp.ThStudentCourseRespDTO;
import com.gkhy.exam.institutionalaccess.model.resp.ThStudentStudyRespDTO;
import com.gkhy.exam.institutionalaccess.model.vo.*;
@@ -23,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")
@@ -38,6 +33,8 @@
    private ThStudyDetailService thStudyDetailService;
    @Autowired
    private ThBatchCourseChapterService thBatchCourseChapterService;
    @Autowired
    private ThSubjectTypeService subjectTypeService;
    @Override
    public List<ThBatchVO> listByPage(ThBatchQuery query) {
@@ -51,6 +48,7 @@
            List<ThBatchCourseChapter> chapterList = thBatchCourseChapterService.getListByBatchUuids(batchUuids);
            for (ThBatchVO thBatchVO : thBatchVOS) {
                thBatchVO.setSubjectName(getObtainSuperiors(thBatchVO.getSubjectCode()));
                //课程
                List<ThBatchCourseVO> collect = batchCourseList.stream()
                        .filter(bc -> bc.getBatchUuid().equals(thBatchVO.getUuid()))
@@ -181,4 +179,40 @@
        }
        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;
   }
}