Commit 809ddefb authored by wujipeng's avatar wujipeng
Browse files

教师-智能考评-成绩管理-优化

parent cd112ea9
package com.platform.business.model.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* 教师端成绩批阅保存参数。
*
* <p>接口只接收答卷记录主键和每道题的评分。考试、学生、阅卷教师等关键归属信息
* 均由服务端根据答卷及登录用户反查,防止前端伪造身份或跨考试提交分数。</p>
*/
@Data
public class ExamReviewDTO {
@ApiModelProperty(value = "exam_student表主键", required = true)
private Integer examStudentId;
@ApiModelProperty(value = "需要保存的主观题评分", required = true)
private List<ExamReviewItemDTO> items;
}
package com.platform.business.model.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 单道主观题的教师评分。
*/
@Data
public class ExamReviewItemDTO {
@ApiModelProperty(value = "exam_detail表主键", required = true)
private Integer examDetailId;
@ApiModelProperty(value = "教师给出的实际得分,支持0.5分等小数评分", required = true)
private Double score;
}
package com.platform.business.model.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 教师端成绩批阅列表查询条件。
*
* <p>教师编号不会由前端传入,而是由服务端从登录令牌中解析,避免通过篡改请求参数
* 越权查看其他教师负责的考试。</p>
*/
@Data
public class ExamReviewQueryDTO {
@ApiModelProperty(value = "页码", example = "1")
private int pageNum;
@ApiModelProperty(value = "每页条数", example = "10")
private int pageSize;
@ApiModelProperty(value = "考试id")
private Integer examId;
@ApiModelProperty(value = "班级id")
private Integer classId;
@ApiModelProperty(value = "学员姓名,支持模糊查询")
private String studentName;
@ApiModelProperty(value = "批阅状态:false-待批阅,true-已批阅;不传表示全部")
private Boolean markFlag;
}
...@@ -42,7 +42,7 @@ public class ExamDetailEntity { ...@@ -42,7 +42,7 @@ public class ExamDetailEntity {
private Boolean judge; private Boolean judge;
@ApiModelProperty(value = "得分") @ApiModelProperty(value = "得分")
private Integer score; private Double score;
@ApiModelProperty(value = "阅卷老师") @ApiModelProperty(value = "阅卷老师")
@TableField("read_teacher") @TableField("read_teacher")
......
...@@ -54,4 +54,12 @@ public class ExamEntity { ...@@ -54,4 +54,12 @@ public class ExamEntity {
@ApiModelProperty(value = "试卷名称") @ApiModelProperty(value = "试卷名称")
@TableField(exist = false) @TableField(exist = false)
private String paperName; private String paperName;
/**
* 当前考试已提交答卷是否全部完成批阅。
* 该字段用于教师端成绩管理列表快速展示考试批阅状态。
*/
@ApiModelProperty(value = "是否完成批阅")
@TableField("mark_flag")
private Boolean markFlag;
} }
...@@ -48,6 +48,14 @@ public class ExamStudentEntity { ...@@ -48,6 +48,14 @@ public class ExamStudentEntity {
@ApiModelProperty(value = "是否交卷") @ApiModelProperty(value = "是否交卷")
private Boolean submit; private Boolean submit;
/**
* 整份答卷是否已由教师完成批阅。
* false 表示仍可保存批阅草稿,true 表示已最终提交。
*/
@ApiModelProperty(value = "是否完成批阅")
@TableField("mark_flag")
private Boolean markFlag;
@ApiModelProperty(value = "答题时长") @ApiModelProperty(value = "答题时长")
private String duration; private String duration;
......
...@@ -22,6 +22,21 @@ public class ExamDetailVO { ...@@ -22,6 +22,21 @@ public class ExamDetailVO {
private String answer;//答案 private String answer;//答案
/** 学员提交的文本答案。 */
private String content;
/** 学员随主观题上传的附件名称。 */
private String fileName;
/** 题型,用于前端区分客观题和主观题。 */
private String type;
/** 当前题目是否已经完成批阅。 */
private Boolean markFlag;
/** 客观题系统判定结果。 */
private Boolean judge;
private List<ExamDetailVO> examDetailVOS; private List<ExamDetailVO> examDetailVOS;
} }
...@@ -8,6 +8,14 @@ import java.util.Set; ...@@ -8,6 +8,14 @@ import java.util.Set;
@Data @Data
public class ExamScoreDetailVO { public class ExamScoreDetailVO {
@ApiModelProperty(value = "考生答卷记录id")
private Integer examStudentId;
@ApiModelProperty(value = "考试id")
private Integer examId;
@ApiModelProperty(value = "学员id")
private String studentId;
@ApiModelProperty(value = "整份答卷是否完成批阅")
private Boolean markFlag;
@ApiModelProperty(value = "标题") @ApiModelProperty(value = "标题")
private String level; private String level;
@ApiModelProperty(value = "详细评分") @ApiModelProperty(value = "详细评分")
......
...@@ -18,7 +18,7 @@ import javax.annotation.Resource; ...@@ -18,7 +18,7 @@ import javax.annotation.Resource;
public class ExamDetailController extends BaseController { public class ExamDetailController extends BaseController {
@Resource @Resource
private ExamDetailService examDetailService; private ExamDetailService examDetailService;
@ApiOperation(value = "学生成绩详情") @ApiOperation(value = "学生成绩详情(管理员端只读)")
@PostMapping("/detail") @PostMapping("/detail")
public Result<ExamScoreDetailVO> queryDetail(@RequestBody ExamDetailDTO examDetailDTO){ public Result<ExamScoreDetailVO> queryDetail(@RequestBody ExamDetailDTO examDetailDTO){
return Result.data(examDetailService.queryQuestionList(examDetailDTO)); return Result.data(examDetailService.queryQuestionList(examDetailDTO));
......
package com.platform.business.controller;
import com.platform.business.model.dto.ExamReviewDTO;
import com.platform.business.model.dto.ExamReviewQueryDTO;
import com.platform.business.model.vo.ExamScoreDetailVO;
import com.platform.business.service.ExamReviewService;
import com.platform.business.utils.JwtTokenUtil;
import com.platform.controller.BaseController;
import com.platform.model.resp.Result;
import com.platform.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
/**
* 教师端“智能考评-成绩管理”批阅接口。
*
* <p>接口路径显式归属 teacher,管理员成绩管理不暴露任何批阅写接口。服务层还会基于
* 登录角色与考试归属进行二次校验,避免仅依靠菜单或路由名称控制权限。</p>
*/
@Api(tags = "教师端-成绩批阅")
@RestController
@RequestMapping("/teacher/score/review")
public class TeacherExamReviewController extends BaseController {
@Resource
private ExamReviewService examReviewService;
@Resource
private JwtTokenUtil jwtTokenUtil;
@ApiOperation(value = "分页查询教师可批阅答卷")
@PostMapping("/page")
public TableDataInfo page(@RequestBody ExamReviewQueryDTO query,
HttpServletRequest request) {
String userName = getCurrentUserName(request);
startPage(query.getPageNum(), query.getPageSize());
return getDataTable(examReviewService.queryReviewList(userName, query));
}
@ApiOperation(value = "查询待批阅答卷详情")
@GetMapping("/detail/{examStudentId}")
public Result<ExamScoreDetailVO> detail(@PathVariable Integer examStudentId,
HttpServletRequest request) {
return Result.data(examReviewService.reviewDetail(getCurrentUserName(request), examStudentId));
}
@ApiOperation(value = "保存批阅草稿")
@PutMapping("/draft")
public Result<Boolean> saveDraft(@RequestBody ExamReviewDTO examReviewDTO,
HttpServletRequest request) {
return Result.data(examReviewService.saveDraft(getCurrentUserName(request), examReviewDTO));
}
@ApiOperation(value = "提交并完成批阅")
@PutMapping("/submit")
public Result<Boolean> submit(@RequestBody ExamReviewDTO examReviewDTO,
HttpServletRequest request) {
return Result.data(examReviewService.submit(getCurrentUserName(request), examReviewDTO));
}
/**
* 统一从网关透传的 Authorization 请求头中解析当前账号,禁止前端传入教师编号。
*/
private String getCurrentUserName(HttpServletRequest request) {
String token = request.getHeader("Authorization");
return jwtTokenUtil.getUsernameFromToken(token);
}
}
package com.platform.business.mapper; package com.platform.business.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.platform.business.model.dto.ExamReviewQueryDTO;
import com.platform.business.model.entity.ExamStudentEntity; import com.platform.business.model.entity.ExamStudentEntity;
import com.platform.business.model.vo.ExamStudentVO; import com.platform.business.model.vo.ExamStudentVO;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
...@@ -23,4 +23,17 @@ public interface ExamStudentMapper extends BaseMapper<ExamStudentEntity> { ...@@ -23,4 +23,17 @@ public interface ExamStudentMapper extends BaseMapper<ExamStudentEntity> {
List<ExamStudentVO> queryOneselfTeacher(@Param("userId")String userId); List<ExamStudentVO> queryOneselfTeacher(@Param("userId")String userId);
/**
* 查询当前教师有权批阅的已交卷答卷。
* 教师数据范围由 SQL 根据主考、监考和授课班级关系共同限定。
*/
List<ExamStudentVO> queryTeacherReviewList(@Param("teacherId") String teacherId,
@Param("query") ExamReviewQueryDTO query);
/**
* 校验教师是否对指定答卷拥有批阅权限。
*/
int countTeacherReviewPermission(@Param("teacherId") String teacherId,
@Param("examStudentId") Integer examStudentId);
} }
package com.platform.business.service;
import com.platform.business.model.dto.ExamReviewDTO;
import com.platform.business.model.dto.ExamReviewQueryDTO;
import com.platform.business.model.vo.ExamScoreDetailVO;
import com.platform.business.model.vo.ExamStudentVO;
import java.util.List;
/**
* 教师端成绩批阅服务。
*
* <p>管理员端只保留成绩查看能力;所有批阅写操作统一收口到本服务,并在服务层再次
* 校验登录角色和考试归属,不能仅依赖前端菜单控制权限。</p>
*/
public interface ExamReviewService {
List<ExamStudentVO> queryReviewList(String userName, ExamReviewQueryDTO query);
ExamScoreDetailVO reviewDetail(String userName, Integer examStudentId);
boolean saveDraft(String userName, ExamReviewDTO examReviewDTO);
boolean submit(String userName, ExamReviewDTO examReviewDTO);
}
...@@ -39,9 +39,13 @@ public class ExamDetailServiceImpl extends ServiceImpl<ExamDetailMapper, ExamDet ...@@ -39,9 +39,13 @@ public class ExamDetailServiceImpl extends ServiceImpl<ExamDetailMapper, ExamDet
// 查询学生所有答题数据 // 查询学生所有答题数据
List<ExamDetailVO> flatList = baseMapper.queryQuestionList(examDetailDTO); List<ExamDetailVO> flatList = baseMapper.queryQuestionList(examDetailDTO);
ExamScoreDetailVO resultVO = new ExamScoreDetailVO(); ExamScoreDetailVO resultVO = new ExamScoreDetailVO();
resultVO.setExamId(examDetailDTO.getExamId());
resultVO.setStudentId(examDetailDTO.getStudentId());
//学生名 //学生名
UserEntity userEntity = userService.getById(examDetailDTO.getStudentId()); UserEntity userEntity = userService.getById(examDetailDTO.getStudentId());
if (userEntity != null) {
resultVO.setStudentName(userEntity.getNickName()); resultVO.setStudentName(userEntity.getNickName());
}
//阅卷老师 //阅卷老师
Set<String> readTeachers = new HashSet<>(); Set<String> readTeachers = new HashSet<>();
//考试时间 //考试时间
...@@ -50,8 +54,10 @@ public class ExamDetailServiceImpl extends ServiceImpl<ExamDetailMapper, ExamDet ...@@ -50,8 +54,10 @@ public class ExamDetailServiceImpl extends ServiceImpl<ExamDetailMapper, ExamDet
resultVO.setExamTime(examEntity.getExamTime()); resultVO.setExamTime(examEntity.getExamTime());
//班级名 //班级名
ClassEntity classEntity = classService.getById(examEntity.getClassId()); ClassEntity classEntity = classService.getById(examEntity.getClassId());
if (classEntity != null) {
resultVO.setClassName(classEntity.getName()); resultVO.setClassName(classEntity.getName());
} }
}
//总分 //总分
double resultTotalScore = 0.0; double resultTotalScore = 0.0;
double questionTotalScore = 0.0; double questionTotalScore = 0.0;
...@@ -65,7 +71,8 @@ public class ExamDetailServiceImpl extends ServiceImpl<ExamDetailMapper, ExamDet ...@@ -65,7 +71,8 @@ public class ExamDetailServiceImpl extends ServiceImpl<ExamDetailMapper, ExamDet
// 按secondTitle分组创建森林结构 // 按secondTitle分组创建森林结构
Map<String, List<ExamDetailVO>> groupMap = flatList.stream() Map<String, List<ExamDetailVO>> groupMap = flatList.stream()
.collect(Collectors.groupingBy(ExamDetailVO::getSecondTitle)); .collect(Collectors.groupingBy(ExamDetailVO::getSecondTitle,
LinkedHashMap::new, Collectors.toList()));
List<ExamDetailVO> forestStructure = new ArrayList<>(); List<ExamDetailVO> forestStructure = new ArrayList<>();
...@@ -74,15 +81,17 @@ public class ExamDetailServiceImpl extends ServiceImpl<ExamDetailMapper, ExamDet ...@@ -74,15 +81,17 @@ public class ExamDetailServiceImpl extends ServiceImpl<ExamDetailMapper, ExamDet
ExamDetailVO parentNode = new ExamDetailVO(); ExamDetailVO parentNode = new ExamDetailVO();
parentNode.setSecondTitle(entry.getKey()); parentNode.setSecondTitle(entry.getKey());
//获取每题得阅卷老师 //获取每题得阅卷老师
readTeachers = entry.getValue().stream() Set<String> groupReadTeachers = entry.getValue().stream()
.map(ExamDetailVO::getReadTeacher) .map(ExamDetailVO::getReadTeacher)
.filter(Objects::nonNull)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
readTeachers.addAll(groupReadTeachers);
// 计算该组的总分和实际得分 // 计算该组的总分和实际得分
double totalScore = entry.getValue().stream() double totalScore = entry.getValue().stream()
.mapToDouble(ExamDetailVO::getScore) .mapToDouble(detail -> detail.getScore() == null ? 0D : detail.getScore())
.sum(); .sum();
double resultScore = entry.getValue().stream() double resultScore = entry.getValue().stream()
.mapToDouble(ExamDetailVO::getResultScore) .mapToDouble(detail -> detail.getResultScore() == null ? 0D : detail.getResultScore())
.sum(); .sum();
parentNode.setTotalScore(totalScore); parentNode.setTotalScore(totalScore);
...@@ -170,6 +179,16 @@ public class ExamDetailServiceImpl extends ServiceImpl<ExamDetailMapper, ExamDet ...@@ -170,6 +179,16 @@ public class ExamDetailServiceImpl extends ServiceImpl<ExamDetailMapper, ExamDet
examQuestionReq.setScore(questionMap.get(examQuestionReq.getId())); examQuestionReq.setScore(questionMap.get(examQuestionReq.getId()));
} }
} }
// 客观题由系统自动判分。原实现只把满分写回了临时请求对象,未落入 exam_detail,
// 导致成绩详情和教师最终汇总时客观题实际得分始终为空。
for (ExamDetailEntity examDetail : examDetailList) {
if (Integer.valueOf(3).equals(examDetail.getLayer())
&& questionMap.containsKey(examDetail.getQuestionNo())) {
examDetail.setScore(Boolean.TRUE.equals(examDetail.getJudge())
? questionMap.get(examDetail.getQuestionNo()).doubleValue() : 0D);
}
}
} }
saveBatch(examDetailList); saveBatch(examDetailList);
} }
......
package com.platform.business.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.platform.business.mapper.ExamStudentMapper;
import com.platform.business.model.dto.ExamDetailDTO;
import com.platform.business.model.dto.ExamReviewDTO;
import com.platform.business.model.dto.ExamReviewItemDTO;
import com.platform.business.model.dto.ExamReviewQueryDTO;
import com.platform.business.model.entity.ExamDetailEntity;
import com.platform.business.model.entity.ExamEntity;
import com.platform.business.model.entity.ExamStudentEntity;
import com.platform.business.model.entity.QuestionThirdEntity;
import com.platform.business.model.entity.SysPhoneRoleEntity;
import com.platform.business.model.vo.ExamScoreDetailVO;
import com.platform.business.model.vo.ExamStudentVO;
import com.platform.business.model.vo.UserVO;
import com.platform.business.service.ExamDetailService;
import com.platform.business.service.ExamReviewService;
import com.platform.business.service.ExamService;
import com.platform.business.service.ExamStudentService;
import com.platform.business.service.QuestionThirdService;
import com.platform.business.service.UserService;
import com.platform.exception.BusinessException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* 教师端成绩批阅实现。
*
* <p>本实现把角色校验、答卷归属校验和分值校验全部放在服务端。即使管理员端误展示了
* 批阅按钮,或调用方直接构造请求,也不能越过这些校验写入成绩。</p>
*/
@Service
public class ExamReviewServiceImpl implements ExamReviewService {
@Resource
private UserService userService;
@Resource
private ExamStudentMapper examStudentMapper;
@Resource
private ExamStudentService examStudentService;
@Resource
private ExamDetailService examDetailService;
@Resource
private ExamService examService;
@Resource
private QuestionThirdService questionThirdService;
@Override
public List<ExamStudentVO> queryReviewList(String userName, ExamReviewQueryDTO query) {
UserVO teacher = getCurrentTeacher(userName);
return examStudentMapper.queryTeacherReviewList(teacher.getId(), query);
}
@Override
public ExamScoreDetailVO reviewDetail(String userName, Integer examStudentId) {
UserVO teacher = getCurrentTeacher(userName);
ExamStudentEntity examStudent = getReviewableExamStudent(teacher.getId(), examStudentId);
ExamDetailDTO detailDTO = new ExamDetailDTO();
detailDTO.setExamId(examStudent.getExamId());
detailDTO.setStudentId(examStudent.getStudentId());
ExamScoreDetailVO detailVO = examDetailService.queryQuestionList(detailDTO);
// 返回答卷主键与整卷批阅状态,前端保存评分时无需自行拼接考试和学员编号。
detailVO.setExamStudentId(examStudent.getId());
detailVO.setExamId(examStudent.getExamId());
detailVO.setStudentId(examStudent.getStudentId());
detailVO.setMarkFlag(Boolean.TRUE.equals(examStudent.getMarkFlag()));
return detailVO;
}
@Override
@Transactional
public boolean saveDraft(String userName, ExamReviewDTO examReviewDTO) {
return saveReview(userName, examReviewDTO, false);
}
@Override
@Transactional
public boolean submit(String userName, ExamReviewDTO examReviewDTO) {
return saveReview(userName, examReviewDTO, true);
}
/**
* 保存教师评分。草稿只更新本次传入的题目;最终提交要求所有主观题均有得分,
* 随后汇总客观题与主观题得分并锁定整份答卷。
*/
private boolean saveReview(String userName, ExamReviewDTO reviewDTO, boolean submit) {
if (reviewDTO == null || reviewDTO.getExamStudentId() == null) {
throw new BusinessException("答卷id不能为空");
}
UserVO teacher = getCurrentTeacher(userName);
ExamStudentEntity examStudent = getReviewableExamStudent(teacher.getId(), reviewDTO.getExamStudentId());
if (Boolean.TRUE.equals(examStudent.getMarkFlag())) {
throw new BusinessException("该答卷已完成批阅,不能重复提交");
}
// 一次读取整份仿真考试答题明细,后续所有更新均限定在这份答卷内。
List<ExamDetailEntity> allDetails = examDetailService.list(
new LambdaQueryWrapper<ExamDetailEntity>()
.eq(ExamDetailEntity::getExamId, examStudent.getExamId())
.eq(ExamDetailEntity::getStudentId, examStudent.getStudentId()));
if (CollectionUtils.isEmpty(allDetails)) {
throw new BusinessException("未找到该学员的答题明细");
}
Map<Integer, ExamDetailEntity> subjectiveLeafMap = new HashMap<>();
List<String> leafQuestionNos = new ArrayList<>();
for (ExamDetailEntity detail : allDetails) {
if (Integer.valueOf(3).equals(detail.getLayer())) {
leafQuestionNos.add(detail.getQuestionNo());
}
// 只有第三级叶子题且 mark_flag=false 的记录才允许教师手动评分;
// 客观题在提交作答时已由系统判分,教师不能覆盖系统分数。
if (Integer.valueOf(3).equals(detail.getLayer()) && !Boolean.TRUE.equals(detail.getMarkFlag())) {
subjectiveLeafMap.put(detail.getId(), detail);
}
}
List<ExamReviewItemDTO> reviewItems = reviewDTO.getItems() == null
? Collections.<ExamReviewItemDTO>emptyList() : reviewDTO.getItems();
if (!submit && reviewItems.isEmpty()) {
throw new BusinessException("请至少填写一道主观题评分");
}
Map<String, Integer> fullScoreMap = queryFullScoreMap(leafQuestionNos);
// 兼容修复前产生的存量客观题:旧逻辑记录了 judge,但没有把实际得分写入 score。
// 此处根据判定结果补齐,确保最终总分不会漏掉客观题。
for (ExamDetailEntity detail : allDetails) {
if (Integer.valueOf(3).equals(detail.getLayer())
&& Boolean.TRUE.equals(detail.getMarkFlag())
&& detail.getScore() == null) {
Integer fullScore = fullScoreMap.get(detail.getQuestionNo());
if (fullScore == null) {
throw new BusinessException("题目分值配置缺失,无法汇总客观题成绩");
}
detail.setScore(Boolean.TRUE.equals(detail.getJudge()) ? fullScore.doubleValue() : 0D);
}
}
Set<Integer> requestDetailIds = new HashSet<>();
for (ExamReviewItemDTO reviewItem : reviewItems) {
if (reviewItem == null || reviewItem.getExamDetailId() == null || reviewItem.getScore() == null) {
throw new BusinessException("题目id和评分不能为空");
}
if (!requestDetailIds.add(reviewItem.getExamDetailId())) {
throw new BusinessException("同一道题不能重复提交评分");
}
ExamDetailEntity detail = subjectiveLeafMap.get(reviewItem.getExamDetailId());
if (detail == null) {
throw new BusinessException("题目不属于当前答卷,或该题不允许手动评分");
}
Integer fullScore = fullScoreMap.get(detail.getQuestionNo());
if (fullScore == null) {
throw new BusinessException("题目分值配置缺失,无法保存评分");
}
if (reviewItem.getScore() < 0D || reviewItem.getScore() > fullScore.doubleValue()) {
throw new BusinessException("题目得分必须在0到" + fullScore + "分之间");
}
detail.setScore(reviewItem.getScore());
detail.setReadTeacher(teacher.getNickName());
}
if (submit) {
// 最终提交前校验全部主观题,防止部分题目漏评后提前发布不完整成绩。
for (ExamDetailEntity detail : subjectiveLeafMap.values()) {
if (detail.getScore() == null) {
throw new BusinessException("仍有主观题未评分,请完成后再提交批阅");
}
}
// 一级、二级记录是展示分组节点,也同步标记完成,保证整份答卷状态一致。
for (ExamDetailEntity detail : allDetails) {
if (!Boolean.TRUE.equals(detail.getMarkFlag())) {
detail.setMarkFlag(true);
if (ObjectUtils.isEmpty(detail.getReadTeacher())) {
detail.setReadTeacher(teacher.getNickName());
}
}
}
}
examDetailService.updateBatchById(allDetails);
if (!submit) {
return true;
}
// 最终成绩以叶子题实际得分为准,父级分组节点不参与累加,避免重复计分。
double totalScore = 0D;
for (ExamDetailEntity detail : allDetails) {
if (Integer.valueOf(3).equals(detail.getLayer()) && detail.getScore() != null) {
totalScore += detail.getScore();
}
}
examStudent.setScore(totalScore);
examStudent.setMarkFlag(true);
examStudentService.updateById(examStudent);
updateExamReviewStatus(examStudent.getExamId());
return true;
}
/**
* 查询主观题满分配置并按题号构建索引,用于阻止负分和超出满分的评分。
*/
private Map<String, Integer> queryFullScoreMap(List<String> questionNos) {
if (CollectionUtils.isEmpty(questionNos)) {
return Collections.emptyMap();
}
List<QuestionThirdEntity> questions = questionThirdService.selectListInQuestionNo(questionNos);
Map<String, Integer> fullScoreMap = new HashMap<>();
for (QuestionThirdEntity question : questions) {
fullScoreMap.put(question.getNo(), question.getScore());
}
return fullScoreMap;
}
/**
* 当一场考试当前所有已交卷答卷都完成批阅后,同步更新考试批阅状态。
*/
private void updateExamReviewStatus(Integer examId) {
long unreviewedCount = examStudentService.count(
new LambdaQueryWrapper<ExamStudentEntity>()
.eq(ExamStudentEntity::getExamId, examId)
.eq(ExamStudentEntity::getSubmit, true)
.and(wrapper -> wrapper.eq(ExamStudentEntity::getMarkFlag, false)
.or().isNull(ExamStudentEntity::getMarkFlag)));
ExamEntity exam = examService.getById(examId);
if (exam != null) {
exam.setMarkFlag(unreviewedCount == 0);
examService.updateById(exam);
}
}
/**
* 校验答卷存在、已经交卷且属于当前教师的数据范围。
*/
private ExamStudentEntity getReviewableExamStudent(String teacherId, Integer examStudentId) {
if (examStudentId == null) {
throw new BusinessException("答卷id不能为空");
}
ExamStudentEntity examStudent = examStudentService.getById(examStudentId);
if (examStudent == null || !Boolean.TRUE.equals(examStudent.getSubmit())) {
throw new BusinessException("答卷不存在或学员尚未交卷");
}
if (examStudentMapper.countTeacherReviewPermission(teacherId, examStudentId) == 0) {
throw new BusinessException("无权批阅该答卷");
}
return examStudent;
}
/**
* 从登录账号解析教师身份。兼容系统角色和手机号附加角色两种既有角色来源,
* 但明确排除仅具管理员身份的账号。
*/
private UserVO getCurrentTeacher(String userName) {
if (ObjectUtils.isEmpty(userName)) {
throw new BusinessException("登录信息已失效");
}
UserVO user = userService.getUserMessage(userName);
if (user == null || !hasTeacherRole(user)) {
throw new BusinessException("仅教师可以进行成绩批阅");
}
return user;
}
private boolean hasTeacherRole(UserVO user) {
if (isTeacherRoleName(user.getRoleName())) {
return true;
}
if (!CollectionUtils.isEmpty(user.getSysPhoneRoleEntities())) {
for (SysPhoneRoleEntity role : user.getSysPhoneRoleEntities()) {
if (role != null && isTeacherRoleName(role.getRoleName())) {
return true;
}
}
}
return false;
}
private boolean isTeacherRoleName(String roleName) {
if (ObjectUtils.isEmpty(roleName)) {
return false;
}
String normalizedRoleName = roleName.trim();
return normalizedRoleName.contains("教师")
|| normalizedRoleName.contains("教员")
|| normalizedRoleName.contains("考评员")
|| "teacher".equalsIgnoreCase(normalizedRoleName);
}
}
...@@ -65,6 +65,8 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, ExamEntity> impleme ...@@ -65,6 +65,8 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, ExamEntity> impleme
studentList.forEach(studentId -> examStudentEntityList.add(ExamStudentEntity.builder().studentId(studentId) studentList.forEach(studentId -> examStudentEntityList.add(ExamStudentEntity.builder().studentId(studentId)
.examId(examEntity.getId()) .examId(examEntity.getId())
.classId(examEntity.getClassId()) .classId(examEntity.getClassId())
// 新答卷默认处于待批阅状态,教师最终提交后才置为 true。
.markFlag(false)
.build())); .build()));
examStudentService.saveBatch(examStudentEntityList); examStudentService.saveBatch(examStudentEntityList);
} }
......
...@@ -4,14 +4,21 @@ ...@@ -4,14 +4,21 @@
<mapper namespace="com.platform.business.mapper.ExamDetailMapper"> <mapper namespace="com.platform.business.mapper.ExamDetailMapper">
<select id="queryQuestionList" resultType="com.platform.business.model.vo.ExamDetailVO"> <select id="queryQuestionList" resultType="com.platform.business.model.vo.ExamDetailVO">
select select
ed.score as resultScore, ed.id,
ed.exam_id as examId,
ifnull(ed.score, 0) as resultScore,
ed.question_no as questionNO, ed.question_no as questionNO,
qt.title as thirdTitle, qt.title as thirdTitle,
qs.title as secondTitle, qs.title as secondTitle,
qt.score as score, qt.score as score,
qb.level as level, qb.level as level,
ed.read_teacher as readTeacher, ed.read_teacher as readTeacher,
qt.answer as answer qt.answer as answer,
ed.content,
ed.file_name as fileName,
ed.type,
ed.mark_flag as markFlag,
ed.judge
from from
exam_detail ed exam_detail ed
left join left join
...@@ -28,12 +35,15 @@ ...@@ -28,12 +35,15 @@
qt.question_id = qb.id qt.question_id = qb.id
<where> <where>
<!-- 只查询实际计分的第三级叶子题,一级和二级分组节点不参与成绩汇总。 -->
ed.layer = 3
<if test="examId != null"> <if test="examId != null">
ed.exam_id = #{examId} and ed.exam_id = #{examId}
</if> </if>
<if test="studentId != null"> <if test="studentId != null">
and ed.student_id = #{studentId} and ed.student_id = #{studentId}
</if> </if>
</where> </where>
order by qs.id, qt.id
</select> </select>
</mapper> </mapper>
...@@ -43,7 +43,8 @@ ...@@ -43,7 +43,8 @@
exam_student es exam_student es
where where
es.class_id = #{classId} and es.exam_id = #{examId} es.class_id = #{classId} and es.exam_id = #{examId}
and es.mark_flag = 0 and es.submit = true
and ifnull(es.mark_flag, false) = false
</select> </select>
<select id="queryByStudentId" resultType="com.platform.business.model.vo.ExamStudentVO"> <select id="queryByStudentId" resultType="com.platform.business.model.vo.ExamStudentVO">
...@@ -110,4 +111,75 @@ ...@@ -110,4 +111,75 @@
e.chief_id = #{userId} or e.invigilation_id like concat('%',#{userId},'%') e.chief_id = #{userId} or e.invigilation_id like concat('%',#{userId},'%')
); );
</select> </select>
<!--
教师端批阅列表只返回已经交卷的数据。数据权限覆盖三种合理关系:
1. 当前教师是考试首席考评员;2. 当前教师是监考教师;3. 当前教师承担该班课程。
使用 FIND_IN_SET 解析逗号分隔的监考教师编号,避免普通 LIKE 造成编号部分匹配。
-->
<select id="queryTeacherReviewList" resultType="com.platform.business.model.vo.ExamStudentVO">
select
es.id,
es.exam_id as examId,
es.class_id as classId,
es.student_id as studentId,
es.score,
es.submit,
es.mark_flag as markFlag,
es.answer_time as answerTime,
es.duration,
u.nick_name as studentName,
u.id_card as idCard,
u.phone_number as phone,
c.name as className,
e.name as examName,
e.exam_time as examTime
from exam_student es
inner join exam e on e.id = es.exam_id
left join user u on u.id = es.student_id
left join class c on c.id = es.class_id
where es.submit = true
and (
e.chief_id = #{teacherId}
or find_in_set(#{teacherId}, replace(ifnull(e.invigilation_id, ''), ' ', '')) &gt; 0
or exists (
select 1
from class_subject cs
where cs.class_id = es.class_id
and cs.teacher_id = #{teacherId}
)
)
<if test="query != null and query.examId != null">
and es.exam_id = #{query.examId}
</if>
<if test="query != null and query.classId != null">
and es.class_id = #{query.classId}
</if>
<if test="query != null and query.studentName != null and query.studentName != ''">
and u.nick_name like concat('%', #{query.studentName}, '%')
</if>
<if test="query != null and query.markFlag != null">
and ifnull(es.mark_flag, false) = #{query.markFlag}
</if>
order by ifnull(es.mark_flag, false) asc, es.id asc
</select>
<!-- 与列表使用完全相同的数据权限条件,防止通过直接构造答卷主键绕过列表限制。 -->
<select id="countTeacherReviewPermission" resultType="int">
select count(1)
from exam_student es
inner join exam e on e.id = es.exam_id
where es.id = #{examStudentId}
and es.submit = true
and (
e.chief_id = #{teacherId}
or find_in_set(#{teacherId}, replace(ifnull(e.invigilation_id, ''), ' ', '')) &gt; 0
or exists (
select 1
from class_subject cs
where cs.class_id = es.class_id
and cs.teacher_id = #{teacherId}
)
)
</select>
</mapper> </mapper>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment