StudentService.java 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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.google.common.collect.Sets;
  6. import com.ruoyi.common.annotation.Excel;
  7. import com.ruoyi.common.core.domain.AjaxResult2;
  8. import com.ruoyi.common.core.domain.entity.SysUser;
  9. import com.ruoyi.common.enums.ExamType;
  10. import com.ruoyi.common.enums.SubjectType;
  11. import com.ruoyi.common.utils.CommonUtils;
  12. import com.ruoyi.common.utils.NumberUtils;
  13. import com.ruoyi.common.utils.SecurityUtils;
  14. import com.ruoyi.dz.domain.DzSubject;
  15. import com.ruoyi.dz.service.IDzSubjectService;
  16. import com.ruoyi.enums.ExamineeStatus;
  17. import com.ruoyi.enums.PaperType;
  18. import com.ruoyi.learn.domain.LearnExaminee;
  19. import com.ruoyi.learn.domain.LearnPaper;
  20. import com.ruoyi.learn.domain.LearnStudent;
  21. import com.ruoyi.learn.domain.LearnTestStudent;
  22. import com.ruoyi.learn.mapper.*;
  23. import com.ruoyi.learn.service.ILearnStudentService;
  24. import com.ruoyi.system.service.ISysUserService;
  25. import org.apache.commons.compress.utils.Lists;
  26. import org.apache.commons.lang3.StringUtils;
  27. import org.springframework.stereotype.Service;
  28. import org.springframework.util.CollectionUtils;
  29. import java.util.Date;
  30. import java.util.List;
  31. import java.util.Set;
  32. import java.util.stream.Collectors;
  33. @Service
  34. public class StudentService {
  35. private final LearnPaperMapper learnPaperMapper;
  36. private final LearnTestStudentMapper learnTestStudentMapper;
  37. private final ILearnStudentService learnStudentService;
  38. private final IDzSubjectService dzSubjectService;
  39. private final LearnTeacherService learnTeacherService;
  40. private final LearnExamineeMapper learnExamineeMapper;
  41. private final LearnAnswerMapper learnAnswerMapper;
  42. public StudentService(LearnPaperMapper learnPaperMapper, LearnTestStudentMapper learnTestStudentMapper, ILearnStudentService learnStudentService, IDzSubjectService dzSubjectService, LearnTeacherService learnTeacherService, LearnExamineeMapper learnExamineeMapper, LearnAnswerMapper learnAnswerMapper) {
  43. this.learnPaperMapper = learnPaperMapper;
  44. this.learnTestStudentMapper = learnTestStudentMapper;
  45. this.learnStudentService = learnStudentService;
  46. this.dzSubjectService = dzSubjectService;
  47. this.learnTeacherService = learnTeacherService;
  48. this.learnExamineeMapper = learnExamineeMapper;
  49. this.learnAnswerMapper = learnAnswerMapper;
  50. }
  51. public List<DzSubject> getSubjectList(boolean directed) {
  52. SysUser sysUser = SecurityUtils.getLoginUser().getUser();
  53. DzSubject sCond = new DzSubject();
  54. sCond.setLocations(sysUser.getLocation());
  55. sCond.setExamTypes(sysUser.getExamType().name());
  56. List<DzSubject> list = dzSubjectService.selectDzSubjectList(sCond);
  57. Set<Long> subjectIdSet;
  58. if (!directed) {
  59. if(!ExamType.VHS.equals(sysUser.getExamType())){
  60. return list;
  61. }
  62. subjectIdSet = Sets.newHashSet(1L, 2L, 3L);
  63. Integer userSubjectId = SecurityUtils.getLoginUser().getUser().getExamMajor();
  64. if(null != userSubjectId) {
  65. subjectIdSet.add(userSubjectId.longValue());
  66. }
  67. } else {
  68. LearnStudent learnStudent = learnStudentService.selectLearnStudentByStudentId(SecurityUtils.getUserId());
  69. if (null == learnStudent || CollectionUtils.isEmpty((subjectIdSet = learnTeacherService.getSubjectIdSet(new Long[]{learnStudent.getMajorPlanId()})))) {
  70. return list;
  71. }
  72. }
  73. return list.stream().filter(t -> subjectIdSet.contains(t.getSubjectId())).collect(Collectors.toList());
  74. }
  75. public List<Dict> selectStatsForStudent(Long studentId) {
  76. Integer undone = 0, done = 0;
  77. for(LearnTestStudent ts : learnTestStudentMapper.selectStatsForStudent(studentId)) {
  78. if(ts.getStatus() < ExamineeStatus.Exam.getVal()) {
  79. undone += ts.getCount();
  80. } else {
  81. done += ts.getCount();
  82. }
  83. }
  84. List<Dict> list = Lists.newArrayList();
  85. list.add(Dict.create().set("全部", undone + done));
  86. list.add(Dict.create().set("未完成", undone));
  87. list.add(Dict.create().set("已完成", done));
  88. return list;
  89. }
  90. public List<LearnPaper> selectLearnPaperForStudent(Long studentId, Integer status) {
  91. return learnPaperMapper.selectLearnPaperForStudent(studentId, status);
  92. }
  93. public List<JSONObject> getSimulateStat(Long examineeId) {
  94. List<JSONObject> stats = learnAnswerMapper.selectSimulatedKnowledgeStats(examineeId);
  95. stats.forEach(CommonUtils::normalRate);
  96. return stats;
  97. }
  98. public List<JSONObject> getSimulateList(Long studentId) {
  99. LearnExaminee eCond = new LearnExaminee();
  100. eCond.setStudentId(studentId);
  101. eCond.setPaperType(PaperType.Simulated.getVal());
  102. List<JSONObject> list = learnExamineeMapper.selectLearnExamineeList(eCond).stream().map(t -> {
  103. JSONObject info = JSONObject.parseObject(t.getPaperInfo());
  104. String name = null;
  105. if(null == info) {
  106. name = t.getPaperKey();
  107. } else if(StringUtils.isBlank(name = info.getString("paperName"))) {
  108. name = info.getString("universityName") + "-" + info.getString("majorName");
  109. }
  110. String[] paperKey = t.getPaperKey().split("_");
  111. DzSubject dzSubject = dzSubjectService.selectDzSubjectBySubjectId(Long.parseLong(paperKey[paperKey.length - 1]));
  112. return JSONObject.of("id", t.getPaperId(), "state", t.getState()
  113. , "subjectName", dzSubject.getSubjectName()
  114. , "name", name
  115. , "subjectGroup", (dzSubject.getSubjectId() < 10 ? "公共课" : "专业课")
  116. , "date", DateUtils.format(null != t.getEndTime() ? t.getEndTime() : t.getBeginTime(), "yyyy-MM-dd HH:mm")
  117. , "score", t.getScore());
  118. }).collect(Collectors.toList());
  119. return list;
  120. }
  121. public List<JSONObject> getTestList(Long studentId, Integer state) {
  122. List<JSONObject> list = learnTestStudentMapper.selectExamineeTestList(studentId, state);
  123. list.forEach(t -> {
  124. DzSubject dzSubject = dzSubjectService.selectDzSubjectBySubjectId(t.getLong("subjectId"));
  125. t.put("subjectName", dzSubject.getSubjectName());
  126. t.remove("beginTime");
  127. Date date = t.getDate("endTime");
  128. t.remove("endTime");
  129. if(null != date) {
  130. t.put("endTime", DateUtils.format(date, "yyyy-MM-dd HH:mm"));
  131. }
  132. date = t.getDate("publishTime");
  133. t.remove("publishTime");
  134. t.put("publishTime", DateUtils.format(date, "yyyy-MM-dd HH:mm"));
  135. t.put("directed", StringUtils.isNotBlank(t.getString("directKey")));
  136. t.remove("directKey");
  137. });
  138. return list;
  139. }
  140. }