StudentService.java 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. package com.ruoyi.web.service;
  2. import cn.hutool.core.lang.Dict;
  3. import com.alibaba.fastjson2.JSONObject;
  4. import com.alibaba.fastjson2.util.DateUtils;
  5. import com.ruoyi.common.annotation.Excel;
  6. import com.ruoyi.common.core.domain.AjaxResult2;
  7. import com.ruoyi.common.core.domain.entity.SysUser;
  8. import com.ruoyi.common.utils.NumberUtils;
  9. import com.ruoyi.common.utils.SecurityUtils;
  10. import com.ruoyi.dz.domain.DzSubject;
  11. import com.ruoyi.dz.service.IDzSubjectService;
  12. import com.ruoyi.enums.ExamineeStatus;
  13. import com.ruoyi.enums.PaperType;
  14. import com.ruoyi.learn.domain.LearnExaminee;
  15. import com.ruoyi.learn.domain.LearnPaper;
  16. import com.ruoyi.learn.domain.LearnStudent;
  17. import com.ruoyi.learn.domain.LearnTestStudent;
  18. import com.ruoyi.learn.mapper.*;
  19. import com.ruoyi.learn.service.ILearnStudentService;
  20. import com.ruoyi.system.service.ISysUserService;
  21. import org.apache.commons.compress.utils.Lists;
  22. import org.springframework.stereotype.Service;
  23. import org.springframework.util.CollectionUtils;
  24. import java.util.List;
  25. import java.util.Set;
  26. import java.util.stream.Collectors;
  27. @Service
  28. public class StudentService {
  29. private final LearnPaperMapper learnPaperMapper;
  30. private final LearnTestStudentMapper learnTestStudentMapper;
  31. private final ILearnStudentService learnStudentService;
  32. private final IDzSubjectService dzSubjectService;
  33. private final LearnTeacherService learnTeacherService;
  34. private final LearnExamineeMapper learnExamineeMapper;
  35. private final LearnAnswerMapper learnAnswerMapper;
  36. public StudentService(LearnPaperMapper learnPaperMapper, LearnTestStudentMapper learnTestStudentMapper, ILearnStudentService learnStudentService, IDzSubjectService dzSubjectService, LearnTeacherService learnTeacherService, LearnExamineeMapper learnExamineeMapper, LearnAnswerMapper learnAnswerMapper) {
  37. this.learnPaperMapper = learnPaperMapper;
  38. this.learnTestStudentMapper = learnTestStudentMapper;
  39. this.learnStudentService = learnStudentService;
  40. this.dzSubjectService = dzSubjectService;
  41. this.learnTeacherService = learnTeacherService;
  42. this.learnExamineeMapper = learnExamineeMapper;
  43. this.learnAnswerMapper = learnAnswerMapper;
  44. }
  45. public List<DzSubject> getSubjectList(boolean directed) {
  46. SysUser sysUser = SecurityUtils.getLoginUser().getUser();
  47. DzSubject sCond = new DzSubject();
  48. sCond.setLocations(sysUser.getLocation());
  49. sCond.setExamTypes(sysUser.getExamType().name());
  50. List<DzSubject> list = dzSubjectService.selectDzSubjectList(sCond);
  51. if (!directed) {
  52. return list;
  53. }
  54. LearnStudent learnStudent = learnStudentService.selectLearnStudentByStudentId(SecurityUtils.getUserId());
  55. Set<Long> subjectIdSet;
  56. if (null == learnStudent || CollectionUtils.isEmpty((subjectIdSet = learnTeacherService.getSubjectIdSet(new Long[]{learnStudent.getMajorPlanId()})))) {
  57. return list;
  58. }
  59. return list.stream().filter(t -> subjectIdSet.contains(t.getSubjectId())).collect(Collectors.toList());
  60. }
  61. public List<Dict> selectStatsForStudent(Long studentId) {
  62. Integer undone = 0, done = 0;
  63. for(LearnTestStudent ts : learnTestStudentMapper.selectStatsForStudent(studentId)) {
  64. if(ExamineeStatus.Init.getVal().equals(ts.getStatus()) || ExamineeStatus.Exam.getVal().equals(ts.getStatus())) {
  65. undone += ts.getCount();
  66. } else {
  67. done += ts.getCount();
  68. }
  69. }
  70. List<Dict> list = Lists.newArrayList();
  71. list.add(Dict.create().set("全部", undone + done));
  72. list.add(Dict.create().set("未完成", undone));
  73. list.add(Dict.create().set("已完成", done));
  74. return list;
  75. }
  76. public List<LearnPaper> selectLearnPaperForStudent(Long studentId, Integer status) {
  77. return learnPaperMapper.selectLearnPaperForStudent(studentId, status);
  78. }
  79. public List<JSONObject> getSimulateStat(Long examineeId) {
  80. return learnAnswerMapper.selectSimulatedKnowledgeStats(examineeId);
  81. }
  82. public List<JSONObject> getSimulateList(Long studentId) {
  83. LearnExaminee eCond = new LearnExaminee();
  84. eCond.setStudentId(studentId);
  85. eCond.setPaperType(PaperType.Simulated.getVal());
  86. List<JSONObject> list = learnExamineeMapper.selectLearnExamineeList(eCond).stream().map(t -> {
  87. JSONObject info = JSONObject.parseObject(t.getPaperInfo());
  88. DzSubject dzSubject = dzSubjectService.selectDzSubjectBySubjectId(Long.parseLong(t.getPaperKey()));
  89. String name = info.getString("universityName") + "-" + info.getString("majorName");
  90. return JSONObject.of("id", t.getExamineeId(), "state", t.getState()
  91. , "subjectName", dzSubject.getSubjectName()
  92. , "name", name
  93. , "date", DateUtils.format(null != t.getEndTime() ? t.getEndTime() : t.getBeginTime(), "yyyy-MM-dd HH:mm")
  94. , "score", t.getScore());
  95. }).collect(Collectors.toList());
  96. return list;
  97. }
  98. }