| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- 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<DzSubject> getSubjectList(boolean directed) {
- SysUser sysUser = SecurityUtils.getLoginUser().getUser();
- DzSubject sCond = new DzSubject();
- sCond.setLocations(sysUser.getLocation());
- sCond.setExamTypes(sysUser.getExamType().name());
- List<DzSubject> list = dzSubjectService.selectDzSubjectList(sCond);
- if (!directed) {
- return list;
- }
- LearnStudent learnStudent = learnStudentService.selectLearnStudentByStudentId(SecurityUtils.getUserId());
- Set<Long> 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<Dict> 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<Dict> 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<LearnPaper> selectLearnPaperForStudent(Long studentId, Integer status) {
- return learnPaperMapper.selectLearnPaperForStudent(studentId, status);
- }
- public List<JSONObject> getSimulateStat(Long examineeId) {
- return learnAnswerMapper.selectSimulatedKnowledgeStats(examineeId);
- }
- public List<JSONObject> getSimulateList(Long studentId) {
- LearnExaminee eCond = new LearnExaminee();
- eCond.setStudentId(studentId);
- eCond.setPaperType(PaperType.Simulated.getVal());
- List<JSONObject> 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;
- }
- }
|