fix: 学生排名增加学生头像

11111
winter 1 year ago
parent 2f972c65e3
commit 83bdf4d6c1

@ -1,6 +1,5 @@
package cn.teammodel.controller.admin.service.impl;
import cn.hutool.core.lang.Pair;
import cn.teammodel.common.ErrorCode;
import cn.teammodel.common.PK;
import cn.teammodel.config.exception.ServiceException;
@ -302,12 +301,20 @@ public class AdminAppraiseServiceImpl implements AdminAppraiseService {
if (ObjectUtils.isEmpty(res)) return null;
Set<String> studentIdSet = res.stream().map(StudentRankVo::getId).collect(Collectors.toSet());
if (ObjectUtils.isEmpty(studentIdSet)) return res;
List<Student> students = studentRepository.findAllByCodeAndIdIn(String.format(PK.STUDENT, schoolId), studentIdSet);
// 提取 Student 中的 name 和 classId
Map<String, Pair<String, String>> idNameMap = students.stream().collect(Collectors.toMap(Student::getId, item -> new Pair<>(item.getName(), item.getClassId())));
// 利用数组作为三元组,提取 Student 中的 name 和 classId, picture
Map<String, String[]> idNameMap = students.stream().collect(Collectors.toMap(Student::getId, item -> {
String[] studentInfo = new String[3];
studentInfo[0] = item.getName();
studentInfo[1]= item.getClassId();
studentInfo[2] = item.getPicture();
return studentInfo;
}));
res.forEach(rankVo -> {
rankVo.setName(idNameMap.get(rankVo.getId()).getKey());
rankVo.setClassName(idNameMap.get(rankVo.getId()).getValue());
rankVo.setName(idNameMap.get(rankVo.getId())[0]);
rankVo.setClassName(idNameMap.get(rankVo.getId())[1]);
rankVo.setPicture(idNameMap.get(rankVo.getId())[2]);
});
// 设置 class name

@ -11,4 +11,5 @@ import lombok.EqualsAndHashCode;
@Data
public class StudentRankVo extends RankVo{
private String className;
private String picture;
}

@ -496,9 +496,14 @@ public class EvaluationServiceImpl implements EvaluationService {
int n = 1;
for (int i = 0; i <= ruleSize - 1; i++) {
// 直接从第二个开始算
// 头尾的情况要特判(理清逻辑就很简单)
AchievementRule curRule = rules.get(i);
int flag = praiseCount / curRule.getPromotionCount();
// 只有一个节点也特殊处理
if (ruleSize == 1) {
n = praiseCount / curRule.getLevelCount() + 1;
break;
}
if (flag >= 1) {
if (i == 0) {
curAchievement = curRule;

Loading…
Cancel
Save