教学统计

This commit is contained in:
joylink_zhangsai 2022-04-18 19:01:54 +08:00
parent 6f0aa02eb6
commit b808c220a8
4 changed files with 14 additions and 54 deletions

View File

@ -5,7 +5,6 @@ import club.joylink.rtss.controller.advice.Role;
import club.joylink.rtss.services.IUserExamService; import club.joylink.rtss.services.IUserExamService;
import club.joylink.rtss.vo.AccountVO; import club.joylink.rtss.vo.AccountVO;
import club.joylink.rtss.vo.client.*; import club.joylink.rtss.vo.client.*;
import club.joylink.rtss.vo.client.userExam.PersonalUserExamResultCurveQueryVO;
import club.joylink.rtss.vo.client.userExam.WholeOrgUserExamResult; import club.joylink.rtss.vo.client.userExam.WholeOrgUserExamResult;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
@ -101,9 +100,9 @@ public class UserExamController {
/** /**
* 查询个人考试成绩曲线 * 查询个人考试成绩曲线
*/ */
@GetMapping("/curve/personal") @GetMapping("/curve/{userId}")
public List<UserExamVO> getPersonalUserExamResults(PersonalUserExamResultCurveQueryVO queryVO) { public List<UserExamVO> getPersonalUserExamResults(@PathVariable Long userId) {
return iUserExamService.getPersonalUserExamResults(queryVO); return iUserExamService.getPersonalUserExamResults(userId);
} }
/** /**

View File

@ -3,7 +3,6 @@ package club.joylink.rtss.services;
import club.joylink.rtss.vo.AccountVO; import club.joylink.rtss.vo.AccountVO;
import club.joylink.rtss.vo.client.*; import club.joylink.rtss.vo.client.*;
import club.joylink.rtss.vo.client.userExam.PersonalUserExamResultCurveQueryVO;
import club.joylink.rtss.vo.client.userExam.WholeOrgUserExamResult; import club.joylink.rtss.vo.client.userExam.WholeOrgUserExamResult;
import java.util.List; import java.util.List;
@ -83,9 +82,9 @@ public interface IUserExamService {
/*** /***
* 获取组织中一个人的考试成绩 * 获取组织中一个人的考试成绩
* @param queryVO * @param userId
*/ */
List<UserExamVO> getPersonalUserExamResults(PersonalUserExamResultCurveQueryVO queryVO); List<UserExamVO> getPersonalUserExamResults(Long userId);
/** /**
* 获取某一次考试的全组织的用户考试成绩 * 获取某一次考试的全组织的用户考试成绩

View File

@ -1,7 +1,6 @@
package club.joylink.rtss.services; package club.joylink.rtss.services;
import club.joylink.rtss.constants.BusinessConsts; import club.joylink.rtss.constants.BusinessConsts;
import club.joylink.rtss.constants.StatusEnum;
import club.joylink.rtss.dao.*; import club.joylink.rtss.dao.*;
import club.joylink.rtss.entity.*; import club.joylink.rtss.entity.*;
import club.joylink.rtss.event.UserExamRecordEvent; import club.joylink.rtss.event.UserExamRecordEvent;
@ -14,7 +13,6 @@ import club.joylink.rtss.simulation.cbtc.GroupSimulationService;
import club.joylink.rtss.vo.AccountVO; import club.joylink.rtss.vo.AccountVO;
import club.joylink.rtss.vo.client.*; import club.joylink.rtss.vo.client.*;
import club.joylink.rtss.vo.client.training.TrainingResultVO; import club.joylink.rtss.vo.client.training.TrainingResultVO;
import club.joylink.rtss.vo.client.userExam.PersonalUserExamResultCurveQueryVO;
import club.joylink.rtss.vo.client.userExam.WholeOrgUserExamResult; import club.joylink.rtss.vo.client.userExam.WholeOrgUserExamResult;
import com.github.pagehelper.Page; import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
@ -360,38 +358,15 @@ public class UserExamService implements IUserExamService {
} }
@Override @Override
public List<UserExamVO> getPersonalUserExamResults(PersonalUserExamResultCurveQueryVO queryVO) { public List<UserExamVO> getPersonalUserExamResults(Long userId) {
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNotNull(queryVO.getOrgId());
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNotNull(queryVO.getUserId());
List<OrgExam> orgExams = iOrgExamService.findEntities(queryVO.getOrgId(), queryVO.getCreatorId());
//该组织下由指定用户创建的所有考试
List<Long> examIds = orgExams.stream().map(OrgExam::getExamId).collect(Collectors.toList());
List<ExamDefinition> exams = iExamService.findEntities(examIds, StatusEnum.Valid.getCode());
//该用户对这些考试的成绩
UserExamExample example = new UserExamExample(); UserExamExample example = new UserExamExample();
example.createCriteria() example.createCriteria().andUserIdEqualTo(userId);
.andUserIdEqualTo(queryVO.getUserId())
.andExamIdIn(examIds);
List<UserExam> userExams = userExamMapper.selectByExample(example); List<UserExam> userExams = userExamMapper.selectByExample(example);
Collection<UserExam> maxScoreUserExams = userExams.stream().collect(Collectors.toMap(UserExam::getExamId,
Map<Long, UserExam> examId_userExam_map = userExams.stream()
.collect(Collectors.toMap(UserExam::getExamId,
Function.identity(), Function.identity(),
BinaryOperator.maxBy(Comparator.comparing(UserExam::getScore)))); BinaryOperator.maxBy(Comparator.comparing(UserExam::getScore))))
return exams.stream().map(exam -> { .values();
UserExam userExam = examId_userExam_map.get(exam.getId()); return UserExamVO.convert(maxScoreUserExams);
UserExamVO vo;
if (userExam != null) {
vo = new UserExamVO(userExam);
} else { //该用户没有考这门试的记录
vo = new UserExamVO();
vo.setUserId(queryVO.getUserId().toString());
vo.setExamId(exam.getId().toString());
vo.setExamName(exam.getName());
vo.setScore(0f);
}
return vo;
}).collect(Collectors.toList());
} }
@Override @Override

View File

@ -1,6 +1,5 @@
package club.joylink.rtss.vo.client; package club.joylink.rtss.vo.client;
import club.joylink.rtss.entity.SysAccount;
import club.joylink.rtss.entity.UserExam; import club.joylink.rtss.entity.UserExam;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@ -8,9 +7,8 @@ import lombok.Setter;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -83,21 +81,10 @@ public class UserExamVO {
this.id = id.toString(); this.id = id.toString();
} }
public static List<UserExamVO> convert(List<UserExam> entities, List<SysAccount> accounts) { public static List<UserExamVO> convert(Collection<UserExam> entities) {
if (CollectionUtils.isEmpty(entities)) if (CollectionUtils.isEmpty(entities))
return new ArrayList<>(); return new ArrayList<>();
Map<Long, String> userId_userName_map; return entities.stream().map(UserExamVO::new).collect(Collectors.toList());
if (CollectionUtils.isEmpty(accounts)) {
userId_userName_map = new HashMap<>();
} else {
userId_userName_map = accounts.stream()
.collect(Collectors.toMap(SysAccount::getId, SysAccount::getName));
}
return entities.stream().map(userExam -> {
UserExamVO vo = new UserExamVO(userExam);
vo.setUsername(userId_userName_map.get(userExam.getUserId()));
return vo;
}).collect(Collectors.toList());
} }
} }