package com.ruoyi.web.service; import cn.hutool.core.lang.Dict; import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.util.DateUtils; import com.ruoyi.common.annotation.Excel; import com.ruoyi.common.core.domain.AjaxResult2; import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.utils.NumberUtils; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.dz.domain.DzSubject; import com.ruoyi.dz.service.IDzSubjectService; import com.ruoyi.enums.ExamineeStatus; import com.ruoyi.enums.PaperType; import com.ruoyi.learn.domain.LearnExaminee; import com.ruoyi.learn.domain.LearnPaper; import com.ruoyi.learn.domain.LearnStudent; import com.ruoyi.learn.domain.LearnTestStudent; import com.ruoyi.learn.mapper.*; import com.ruoyi.learn.service.ILearnStudentService; import com.ruoyi.system.service.ISysUserService; import org.apache.commons.compress.utils.Lists; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import java.util.List; import java.util.Set; import java.util.stream.Collectors; @Service public class StudentService { private final LearnPaperMapper learnPaperMapper; private final LearnTestStudentMapper learnTestStudentMapper; private final ILearnStudentService learnStudentService; private final IDzSubjectService dzSubjectService; private final LearnTeacherService learnTeacherService; private final LearnExamineeMapper learnExamineeMapper; private final LearnAnswerMapper learnAnswerMapper; public StudentService(LearnPaperMapper learnPaperMapper, LearnTestStudentMapper learnTestStudentMapper, ILearnStudentService learnStudentService, IDzSubjectService dzSubjectService, LearnTeacherService learnTeacherService, LearnExamineeMapper learnExamineeMapper, LearnAnswerMapper learnAnswerMapper) { this.learnPaperMapper = learnPaperMapper; this.learnTestStudentMapper = learnTestStudentMapper; this.learnStudentService = learnStudentService; this.dzSubjectService = dzSubjectService; this.learnTeacherService = learnTeacherService; this.learnExamineeMapper = learnExamineeMapper; this.learnAnswerMapper = learnAnswerMapper; } public List getSubjectList(boolean directed) { SysUser sysUser = SecurityUtils.getLoginUser().getUser(); DzSubject sCond = new DzSubject(); sCond.setLocations(sysUser.getLocation()); sCond.setExamTypes(sysUser.getExamType().name()); List list = dzSubjectService.selectDzSubjectList(sCond); if (!directed) { return list; } LearnStudent learnStudent = learnStudentService.selectLearnStudentByStudentId(SecurityUtils.getUserId()); Set subjectIdSet; if (null == learnStudent || CollectionUtils.isEmpty((subjectIdSet = learnTeacherService.getSubjectIdSet(new Long[]{learnStudent.getMajorPlanId()})))) { return list; } return list.stream().filter(t -> subjectIdSet.contains(t.getSubjectId())).collect(Collectors.toList()); } public List selectStatsForStudent(Long studentId) { Integer undone = 0, done = 0; for(LearnTestStudent ts : learnTestStudentMapper.selectStatsForStudent(studentId)) { if(ExamineeStatus.Init.getVal().equals(ts.getStatus()) || ExamineeStatus.Exam.getVal().equals(ts.getStatus())) { undone += ts.getCount(); } else { done += ts.getCount(); } } List list = Lists.newArrayList(); list.add(Dict.create().set("全部", undone + done)); list.add(Dict.create().set("未完成", undone)); list.add(Dict.create().set("已完成", done)); return list; } public List selectLearnPaperForStudent(Long studentId, Integer status) { return learnPaperMapper.selectLearnPaperForStudent(studentId, status); } public List getSimulateStat(Long examineeId) { return learnAnswerMapper.selectSimulatedKnowledgeStats(examineeId); } public List getSimulateList(Long studentId) { LearnExaminee eCond = new LearnExaminee(); eCond.setStudentId(studentId); eCond.setPaperType(PaperType.Simulated.getVal()); List list = learnExamineeMapper.selectLearnExamineeList(eCond).stream().map(t -> { JSONObject info = JSONObject.parseObject(t.getPaperInfo()); DzSubject dzSubject = dzSubjectService.selectDzSubjectBySubjectId(Long.parseLong(t.getPaperKey())); String name = info.getString("universityName") + "-" + info.getString("majorName"); return JSONObject.of("id", t.getExamineeId(), "state", t.getState() , "subjectName", dzSubject.getSubjectName() , "name", name , "date", DateUtils.format(null != t.getEndTime() ? t.getEndTime() : t.getBeginTime(), "yyyy-MM-dd HH:mm") , "score", t.getScore()); }).collect(Collectors.toList()); return list; } }