|
|
@ -1,6 +1,8 @@ |
|
|
|
package com.ruoyi.web.controller.system; |
|
|
|
|
|
|
|
import cn.hutool.core.util.ObjUtil; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.github.xiaoymin.knife4j.core.util.StrUtil; |
|
|
|
import com.ruoyi.common.core.domain.AjaxResult; |
|
|
|
import com.ruoyi.common.core.domain.entity.SysUser; |
|
|
|
import com.ruoyi.common.core.domain.model.JudgeBody; |
|
|
@ -14,11 +16,13 @@ import com.ruoyi.system.domain.Projectinfo.ScoreDto; |
|
|
|
import com.ruoyi.system.mapper.*; |
|
|
|
import com.ruoyi.system.service.ISrootService; |
|
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
import org.apache.commons.lang3.ObjectUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.util.*; |
|
|
|
import java.util.function.Function; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
@RestController |
|
|
@ -155,67 +159,96 @@ public class ScoreController { |
|
|
|
} |
|
|
|
@ApiOperation("导出评分表") |
|
|
|
@PostMapping("/export") |
|
|
|
public void export(HttpServletResponse response, Session session ) |
|
|
|
{ |
|
|
|
// 创建查询结果存储列表
|
|
|
|
List<exProject> listp = new ArrayList<>(); |
|
|
|
List<exScore> listS = new ArrayList<>(); |
|
|
|
// 查询 Judge 数据,按 session ID 过滤
|
|
|
|
List<Judge> jlist = judgeMapper.selectList(new QueryWrapper<Judge>().eq("srole", session.getId())); |
|
|
|
if (jlist.isEmpty()) { |
|
|
|
// 如果 jlist 为空,直接返回空结果
|
|
|
|
return; |
|
|
|
} |
|
|
|
// 查询 Sroot 数据
|
|
|
|
Sroot sroot = iSrootService.selectSrootById((long) session.getRoot()); |
|
|
|
// 查询 Project 数据,按 sessionid 过滤并按 score 降序排列
|
|
|
|
List<Project> plist = projectMapper.selectList( |
|
|
|
new QueryWrapper<Project>().eq("sessionid", session.getId()).orderByDesc("score") |
|
|
|
); |
|
|
|
// 获取所有评分数据并按项目 ID 和用户 ID 分组
|
|
|
|
Map<Long, Map<Long, Score>> scoreMap = scoreMapper.selectList(new QueryWrapper<>()) |
|
|
|
.stream() |
|
|
|
.collect(Collectors.groupingBy( |
|
|
|
score -> (long) score.getPid(), // 将 Integer 转换为 Long
|
|
|
|
Collectors.toMap( |
|
|
|
score -> (long) score.getUid(), // 将 Integer 转换为 Long
|
|
|
|
score -> score |
|
|
|
) |
|
|
|
)); |
|
|
|
// 遍历项目列表并构建 exScore 和 exProject 列表
|
|
|
|
for (Project project : plist) { |
|
|
|
exProject exProject = new exProject(project, session.getSession(), sroot.getTask()); |
|
|
|
listp.add(exProject); |
|
|
|
|
|
|
|
// 遍历 Judge 列表并构建 exScore 对象
|
|
|
|
for (Judge judge : jlist) { |
|
|
|
Score score = scoreMap.getOrDefault(project.getId(), Collections.emptyMap()).get(judge.getUserid()); |
|
|
|
|
|
|
|
// 构建 exScore 对象并设置评分信息
|
|
|
|
exScore exScore = new exScore(exProject); |
|
|
|
if (score != null) { |
|
|
|
exScore.setPscore(score.getScore()); |
|
|
|
exScore.setMes(score.getMes()); |
|
|
|
} |
|
|
|
exScore.setPname(judge.getName()); |
|
|
|
listS.add(exScore); |
|
|
|
} |
|
|
|
} |
|
|
|
// 批量计算评分总数和平均值
|
|
|
|
Map<Long, List<Score>> scoresByPid = scoreMap.values().stream() |
|
|
|
.flatMap(map -> map.values().stream()) |
|
|
|
.collect(Collectors.groupingBy(score -> (long) score.getPid())); // 将 Integer 转为 Long
|
|
|
|
public void export(HttpServletResponse response, Session session) { |
|
|
|
// 获取当前会话的评委列表
|
|
|
|
List<Judge> judges = judgeMapper.selectList( |
|
|
|
new QueryWrapper<Judge>().eq("srole", session.getId()) |
|
|
|
); |
|
|
|
if (judges.isEmpty()) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
for (exScore exScore : listS) { |
|
|
|
List<Score> slist = scoresByPid.getOrDefault(exScore.getId(), Collections.emptyList()); |
|
|
|
int count = slist.size(); |
|
|
|
// 获取关联的Sroot信息
|
|
|
|
Sroot sroot = iSrootService.selectSrootById((long) session.getRoot()); |
|
|
|
|
|
|
|
exScore.setSconum(count); |
|
|
|
exScore.setScore(count > 0 ? (int) slist.stream().mapToInt(Score::getScore).average().orElse(0) : 0); |
|
|
|
} |
|
|
|
ExcelUtil<exScore> util = new ExcelUtil<>(exScore.class); |
|
|
|
util.exportExcel(response, listS, "分数汇总"); |
|
|
|
} |
|
|
|
// 获取当前会话的项目列表并按分数降序排列
|
|
|
|
List<Project> projects = projectMapper.selectList( |
|
|
|
new QueryWrapper<Project>() |
|
|
|
.eq("sessionid", session.getId()) |
|
|
|
.orderByDesc("score") |
|
|
|
); |
|
|
|
if (projects.isEmpty()) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// 收集项目ID以优化Score查询
|
|
|
|
List<Integer> projectIds = projects.stream() |
|
|
|
.map(Project::getId) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
|
|
// 仅查询相关项目的评分记录(关键修复1:添加类型转换)
|
|
|
|
List<Score> scores = scoreMapper.selectList( |
|
|
|
new QueryWrapper<Score>().in("pid", projectIds) |
|
|
|
); |
|
|
|
|
|
|
|
// 构建评分映射: pid -> (uid -> Score)(关键修复2:保持Integer类型)
|
|
|
|
Map<Integer, Map<Integer, Score>> scoreMap = scores.stream() |
|
|
|
.collect(Collectors.groupingBy( |
|
|
|
Score::getPid, |
|
|
|
Collectors.toMap(Score::getUid, Function.identity()) |
|
|
|
)); |
|
|
|
|
|
|
|
// 预计算每个项目的评分统计(关键修复3:统一使用Integer类型)
|
|
|
|
Map<Integer, Integer> scoreCounts = new HashMap<>(); |
|
|
|
Map<Integer, Double> averageScores = new HashMap<>(); |
|
|
|
scoreMap.forEach((pid, uidMap) -> { |
|
|
|
List<Score> projectScores = new ArrayList<>(uidMap.values()); |
|
|
|
int count = projectScores.size(); |
|
|
|
double average = projectScores.stream() |
|
|
|
.mapToInt(Score::getScore) |
|
|
|
.average() |
|
|
|
.orElse(0.0); |
|
|
|
System.out.println("评分人数:---------pid-------"+pid+"-----count----"+count); |
|
|
|
scoreCounts.put(pid, count); |
|
|
|
averageScores.put(pid, average); |
|
|
|
}); |
|
|
|
|
|
|
|
// 构建导出数据列表
|
|
|
|
List<exScore> exportData = new ArrayList<>(); |
|
|
|
for (Project project : projects) { |
|
|
|
exProject exProj = new exProject(project, session.getSession(), sroot.getTask()); |
|
|
|
int projectId = project.getId(); |
|
|
|
System.out.println("分数信息:---------pid-------"+projectId+"-----count----"); |
|
|
|
// 获取当前项目的统计信息(关键修复4:直接使用Integer类型)
|
|
|
|
int count = ObjUtil.isNotNull(scoreCounts.get(projectId))?scoreCounts.get(projectId):0; |
|
|
|
double average = ObjUtil.isNotNull(averageScores.get(projectId))?averageScores.get(projectId):0; |
|
|
|
|
|
|
|
|
|
|
|
for (Judge judge : judges) { |
|
|
|
exScore exSc = new exScore(exProj); |
|
|
|
exSc.setPname(judge.getName()); |
|
|
|
|
|
|
|
// 获取对应评分(空值安全处理)
|
|
|
|
Score score = Optional.ofNullable(scoreMap.get(projectId)) |
|
|
|
.map(uidMap -> uidMap.get(judge.getUserid())) |
|
|
|
.orElse(null); |
|
|
|
|
|
|
|
if (score != null) { |
|
|
|
exSc.setPscore(score.getScore()); |
|
|
|
exSc.setMes(score.getMes()); |
|
|
|
} |
|
|
|
|
|
|
|
// 设置统计信息(添加四舍五入处理)
|
|
|
|
exSc.setSconum(count); |
|
|
|
exSc.setScore((int) Math.round(average)); |
|
|
|
exportData.add(exSc); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 导出Excel
|
|
|
|
new ExcelUtil<exScore>(exScore.class) |
|
|
|
.exportExcel(response, exportData, "分数汇总"); |
|
|
|
} |
|
|
|
public void init(){ |
|
|
|
List<Session> lists=sessionMapper.selectList(null); |
|
|
|
for(Session session:lists){ |
|
|
|