"src/main/git@gitlab.ruzhoukj.com:wujipeng/ops.git" did not exist on "d6b07d2cdcce29c7a75ba0d6686e05cbf673bf2e"
Commit bb7667c7 authored by wujipeng's avatar wujipeng
Browse files

自动组卷-实操题

parent 43f7e17d
package com.platform.business.model.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
/** 管理员保存单条实操规则时允许修改的字段。 */
@Data
public class PracticePaperRuleItemDTO {
@ApiModelProperty("规则ID;项目和单元内容由该ID对应的标准类目确定")
private Integer id;
@ApiModelProperty("单题考核时间,单位:分钟")
private Integer assessmentDuration;
@ApiModelProperty("单题配分")
private BigDecimal score;
@ApiModelProperty("该类目考核题量;所有类目合计最多5题")
private Integer questionCount;
}
package com.platform.business.model.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/** 管理员按等级保存整套实操自动组卷配置的请求体。 */
@Data
public class PracticePaperRuleSaveDTO {
@ApiModelProperty("职级;支持一级或污水一级/污泥一级等以标准等级结尾的名称")
private String lev;
@ApiModelProperty("该等级完整规则列表,类目必须与服务端Excel标准类目完全对应")
private List<PracticePaperRuleItemDTO> ruleList;
}
package com.platform.business.model.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
import java.util.Date;
/**
* 实操自动组卷规则持久化实体。
*
* <p>这里保存的是“按等级选择哪些考核类目,以及每个类目的时间、配分和题量”,
* 不保存也不生成正式试卷。项目名称与单元内容来自业务确认的 Excel 类目,管理员
* 只能调整三个数值字段,避免前端任意新增或篡改标准类目。</p>
*/
@Data
@TableName("practice_paper_rule")
public class PracticePaperRuleEntity {
@TableId(type = IdType.AUTO)
private Integer id;
@ApiModelProperty("标准等级:一级、二级、三级、四级或五级")
@TableField("level_grade")
private String levelGrade;
@ApiModelProperty("项目名称")
@TableField("project_name")
private String projectName;
@ApiModelProperty("单元内容")
@TableField("unit_content")
private String unitContent;
@ApiModelProperty("单题考核时间,单位:分钟")
@TableField("assessment_duration")
private Integer assessmentDuration;
@ApiModelProperty("单题配分")
private BigDecimal score;
@ApiModelProperty("该类目考核题量")
@TableField("question_count")
private Integer questionCount;
@TableField("created_time")
private Date createdTime;
@TableField("updated_time")
private Date updatedTime;
@TableField("updated_by")
private String updatedBy;
}
...@@ -80,5 +80,14 @@ public class ExamStudentVO extends ExamStudentEntity { ...@@ -80,5 +80,14 @@ public class ExamStudentVO extends ExamStudentEntity {
@ApiModelProperty(value = "监考教师id") @ApiModelProperty(value = "监考教师id")
private String invigilationId; private String invigilationId;
/**
* 当前最新的实操组卷及配分规则。
*
* <p>recent接口本身只查询最近的实训考试,因此这里不做考试快照;管理员修改规则后,
* 后续调用会立即返回最新配置,供仿真实操系统按当前标准组织本场考核。</p>
*/
@ApiModelProperty(value = "当前最新实操组卷及配分规则")
private PracticePaperRuleConfigurationVO practiceRule;
private List<ExamStudentVO> data; private List<ExamStudentVO> data;
} }
package com.platform.business.model.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
import java.util.List;
/** 一套按标准等级归一化后的实操自动组卷配置。 */
@Data
public class PracticePaperRuleConfigurationVO {
@ApiModelProperty("请求使用的原始职级名称")
private String lev;
@ApiModelProperty("用于匹配Excel类目的标准等级")
private String grade;
@ApiModelProperty("考核总题数,必须在1到5题之间")
private Integer totalQuestionCount;
@ApiModelProperty("考核总时间,单位:分钟")
private Integer totalDuration;
@ApiModelProperty("配分合计")
private BigDecimal totalScore;
@ApiModelProperty("实操类目及其当前配分规则")
private List<PracticePaperRuleItemVO> ruleList;
}
package com.platform.business.model.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
/** 页面展示和第三方实操系统读取的单条配分规则。 */
@Data
public class PracticePaperRuleItemVO {
private Integer id;
private String projectName;
private String unitContent;
private Integer assessmentDuration;
private BigDecimal score;
private Integer questionCount;
@ApiModelProperty("该类目总考核时间:单题时间乘以题量")
private Integer subtotalDuration;
@ApiModelProperty("该类目配分小计:单题配分乘以题量")
private BigDecimal subtotalScore;
}
package com.platform.business.controller; package com.platform.business.controller;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.platform.business.model.dto.PracticePaperRuleSaveDTO;
import com.platform.business.model.dto.TheoreticalPaperAutoSaveDTO; import com.platform.business.model.dto.TheoreticalPaperAutoSaveDTO;
import com.platform.business.model.dto.TheoreticalPaperDTO; import com.platform.business.model.dto.TheoreticalPaperDTO;
import com.platform.business.model.dto.TheoreticalPaperManualSaveDTO; import com.platform.business.model.dto.TheoreticalPaperManualSaveDTO;
import com.platform.business.model.dto.TheoreticalPaperStatusDTO; import com.platform.business.model.dto.TheoreticalPaperStatusDTO;
import com.platform.business.model.entity.UserEntity; import com.platform.business.model.entity.UserEntity;
import com.platform.business.model.vo.CombinationVO; import com.platform.business.model.vo.CombinationVO;
import com.platform.business.model.vo.PracticePaperRuleConfigurationVO;
import com.platform.business.model.vo.TheoreticalPaperVO; import com.platform.business.model.vo.TheoreticalPaperVO;
import com.platform.business.service.AuthenticatedUserService; import com.platform.business.service.AuthenticatedUserService;
import com.platform.business.service.PracticePaperRuleService;
import com.platform.business.service.TheoreticalPaperAdminService; import com.platform.business.service.TheoreticalPaperAdminService;
import com.platform.business.service.TheoreticalPaperService; import com.platform.business.service.TheoreticalPaperService;
import com.platform.controller.BaseController; import com.platform.controller.BaseController;
...@@ -45,6 +48,13 @@ public class TheoreticalPaperAdminController extends BaseController { ...@@ -45,6 +48,13 @@ public class TheoreticalPaperAdminController extends BaseController {
@Resource @Resource
private TheoreticalPaperAdminService paperAdminService; private TheoreticalPaperAdminService paperAdminService;
/**
* 实操入口只维护规则,不调用理论试卷服务生成主表和题目明细。
* 单独服务可以明确隔离两类“自动组卷”在业务语义上的差异。
*/
@Resource
private PracticePaperRuleService practicePaperRuleService;
/** 复用经过多年使用的Word模板导出能力,写操作由新的管理端服务负责。 */ /** 复用经过多年使用的Word模板导出能力,写操作由新的管理端服务负责。 */
@Resource @Resource
private TheoreticalPaperService legacyPaperService; private TheoreticalPaperService legacyPaperService;
...@@ -76,6 +86,22 @@ public class TheoreticalPaperAdminController extends BaseController { ...@@ -76,6 +86,22 @@ public class TheoreticalPaperAdminController extends BaseController {
return Result.data(paperAdminService.autoConfiguration(level)); return Result.data(paperAdminService.autoConfiguration(level));
} }
@ApiOperation("查询实操自动组卷规则;仅返回规则配置,不生成正式试卷")
@GetMapping("/practice/auto-configuration")
public Result<PracticePaperRuleConfigurationVO> practiceAutoConfiguration(
@RequestParam("lev") String level, HttpServletRequest request) {
currentAdmin(request);
return Result.data(practicePaperRuleService.configuration(level));
}
@ApiOperation("保存实操自动组卷规则;所有类目考核题量合计最多5题")
@PutMapping("/practice/auto-configuration")
public Result<PracticePaperRuleConfigurationVO> savePracticeAutoConfiguration(
@RequestBody PracticePaperRuleSaveDTO body, HttpServletRequest request) {
UserEntity administrator = currentAdmin(request);
return Result.data(practicePaperRuleService.saveConfiguration(body, administrator.getId()));
}
@ApiOperation("按数据库组卷规则自动创建试卷") @ApiOperation("按数据库组卷规则自动创建试卷")
@PostMapping("/auto") @PostMapping("/auto")
public Result<TheoreticalPaperVO> createAutomatic( public Result<TheoreticalPaperVO> createAutomatic(
......
package com.platform.business.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.platform.business.model.entity.PracticePaperRuleEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/** 实操自动组卷规则数据访问接口。 */
@Mapper
public interface PracticePaperRuleMapper extends BaseMapper<PracticePaperRuleEntity> {
/**
* 按稳定ID顺序锁定一个等级的全部规则。
*
* <p>整套配置保存前加行锁,保证两个管理员同时保存时不会分别通过“五题上限”
* 校验后交叉覆盖,最终产生一套从未被任何请求完整校验过的组合。</p>
*/
List<PracticePaperRuleEntity> selectByGradeForUpdate(@Param("grade") String grade);
}
package com.platform.business.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.platform.business.model.dto.PracticePaperRuleSaveDTO;
import com.platform.business.model.entity.PracticePaperRuleEntity;
import com.platform.business.model.vo.PracticePaperRuleConfigurationVO;
/** 实操自动组卷规则的查询和整套保存服务。 */
public interface PracticePaperRuleService extends IService<PracticePaperRuleEntity> {
/** 管理页面读取全部标准类目,包括题量为0的未选类目。 */
PracticePaperRuleConfigurationVO configuration(String level);
/** recent接口仅读取题量大于0的当前生效配分规则。 */
PracticePaperRuleConfigurationVO effectiveConfiguration(String level);
/** 管理员整套保存一个等级的配置。 */
PracticePaperRuleConfigurationVO saveConfiguration(PracticePaperRuleSaveDTO request,
String updaterId);
}
...@@ -5,13 +5,19 @@ import com.platform.business.mapper.ExamStudentMapper; ...@@ -5,13 +5,19 @@ import com.platform.business.mapper.ExamStudentMapper;
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 com.platform.business.service.ExamStudentService; import com.platform.business.service.ExamStudentService;
import com.platform.business.service.PracticePaperRuleService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List; import java.util.List;
@Service @Service
public class ExamStaudentServiceImpl extends ServiceImpl<ExamStudentMapper, ExamStudentEntity> implements ExamStudentService { public class ExamStaudentServiceImpl extends ServiceImpl<ExamStudentMapper, ExamStudentEntity> implements ExamStudentService {
@Resource
private PracticePaperRuleService practicePaperRuleService;
@Override @Override
public List<ExamStudentVO> queryByExamId(int id) { public List<ExamStudentVO> queryByExamId(int id) {
return baseMapper.queryByExamId(id); return baseMapper.queryByExamId(id);
...@@ -36,6 +42,16 @@ public class ExamStaudentServiceImpl extends ServiceImpl<ExamStudentMapper, Exam ...@@ -36,6 +42,16 @@ public class ExamStaudentServiceImpl extends ServiceImpl<ExamStudentMapper, Exam
@Override @Override
public ExamStudentVO recent(String studentId) { public ExamStudentVO recent(String studentId) {
ExamStudentVO examStudentVO = baseMapper.recent(studentId); ExamStudentVO examStudentVO = baseMapper.recent(studentId);
// 没有实训考试时保持历史接口的null语义,同时避免继续读取examId造成空指针。
if (examStudentVO == null) {
return null;
}
/*
* 业务确认不固化考试快照:每次请求都根据学生职级读取当前最新配置。
* 规则服务会把“污水一级”“污泥一级”统一匹配为Excel中的“一级”。
*/
examStudentVO.setPracticeRule(
practicePaperRuleService.effectiveConfiguration(examStudentVO.getLev()));
//获取同一场考试的学生 //获取同一场考试的学生
List<ExamStudentVO> data = baseMapper.theSameEvent(examStudentVO.getExamId()); List<ExamStudentVO> data = baseMapper.theSameEvent(examStudentVO.getExamId());
examStudentVO.setData(data); examStudentVO.setData(data);
......
package com.platform.business.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.platform.business.mapper.PracticePaperRuleMapper;
import com.platform.business.model.dto.PracticePaperRuleItemDTO;
import com.platform.business.model.dto.PracticePaperRuleSaveDTO;
import com.platform.business.model.entity.PracticePaperRuleEntity;
import com.platform.business.model.vo.PracticePaperRuleConfigurationVO;
import com.platform.business.model.vo.PracticePaperRuleItemVO;
import com.platform.business.service.PracticePaperRuleService;
import com.platform.exception.BusinessException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* 实操规则核心业务实现。
*
* <p>污水一级、污泥一级等业务职级统一截取末尾“一级”匹配 Excel 类目,因此不同
* 工种共用同等级规则。规则保存采用完整列表覆盖,但标准项目和单元内容始终以数据库
* 种子数据为准,客户端仅能修改时间、配分和题量。</p>
*/
@Service
public class PracticePaperRuleServiceImpl
extends ServiceImpl<PracticePaperRuleMapper, PracticePaperRuleEntity>
implements PracticePaperRuleService {
/** 经业务确认的五个标准等级;固定数组顺序保证匹配与错误提示口径稳定。 */
private static final List<String> GRADES = Collections.unmodifiableList(
Arrays.asList("一级", "二级", "三级", "四级", "五级"));
private static final int DEFAULT_DURATION = 20;
private static final BigDecimal DEFAULT_SCORE = new BigDecimal("20.00");
private static final int MAX_TOTAL_QUESTION_COUNT = 5;
private static final int MAX_DURATION = 600;
private static final BigDecimal MAX_SCORE = new BigDecimal("99999.99");
@Override
@Transactional(readOnly = true)
public PracticePaperRuleConfigurationVO configuration(String level) {
String grade = normalizeGrade(level);
List<PracticePaperRuleEntity> rows = list(new LambdaQueryWrapper<PracticePaperRuleEntity>()
.eq(PracticePaperRuleEntity::getLevelGrade, grade)
.orderByAsc(PracticePaperRuleEntity::getId));
requireCatalog(grade, rows);
return assemble(level, grade, rows, false);
}
@Override
@Transactional(readOnly = true)
public PracticePaperRuleConfigurationVO effectiveConfiguration(String level) {
String grade = normalizeGrade(level);
List<PracticePaperRuleEntity> rows = list(new LambdaQueryWrapper<PracticePaperRuleEntity>()
.eq(PracticePaperRuleEntity::getLevelGrade, grade)
.gt(PracticePaperRuleEntity::getQuestionCount, 0)
.orderByAsc(PracticePaperRuleEntity::getId));
// recent只返回已选类目,但空结果仍表示该等级尚未完成有效配置,应明确报错。
if (rows == null || rows.isEmpty()) {
throw new BusinessException(grade + "实操组卷规则尚未配置考核题量");
}
PracticePaperRuleConfigurationVO result = assemble(level, grade, rows, true);
validateTotalQuestionCount(result.getTotalQuestionCount());
return result;
}
@Override
@Transactional(rollbackFor = Exception.class)
public PracticePaperRuleConfigurationVO saveConfiguration(PracticePaperRuleSaveDTO request,
String updaterId) {
if (request == null) {
throw new BusinessException("实操组卷配置不能为空");
}
String grade = normalizeGrade(request.getLev());
String normalizedUpdater = requireText(updaterId, "更新人ID", 64);
List<PracticePaperRuleEntity> stored = baseMapper.selectByGradeForUpdate(grade);
requireCatalog(grade, stored);
List<PracticePaperRuleItemDTO> submitted = request.getRuleList();
if (submitted == null || submitted.size() != stored.size()) {
throw new BusinessException("必须提交" + grade + "全部" + stored.size() + "条标准类目规则");
}
Map<Integer, PracticePaperRuleItemDTO> submittedById = new LinkedHashMap<>();
for (PracticePaperRuleItemDTO item : submitted) {
if (item == null || item.getId() == null || item.getId() <= 0) {
throw new BusinessException("实操规则ID必须为正整数");
}
if (submittedById.put(item.getId(), item) != null) {
throw new BusinessException("实操规则不能重复提交");
}
}
int totalQuestionCount = 0;
Date now = new Date();
Set<Integer> storedIds = new HashSet<>();
for (PracticePaperRuleEntity row : stored) {
storedIds.add(row.getId());
PracticePaperRuleItemDTO item = submittedById.get(row.getId());
if (item == null) {
throw new BusinessException("提交内容缺少标准类目:" + row.getProjectName()
+ " / " + row.getUnitContent());
}
row.setAssessmentDuration(normalizeDuration(item.getAssessmentDuration()));
row.setScore(normalizeScore(item.getScore()));
row.setQuestionCount(normalizeQuestionCount(item.getQuestionCount()));
row.setUpdatedBy(normalizedUpdater);
row.setUpdatedTime(now);
totalQuestionCount += row.getQuestionCount();
}
if (!storedIds.equals(submittedById.keySet())) {
throw new BusinessException("提交内容包含不属于" + grade + "的实操规则");
}
validateTotalQuestionCount(totalQuestionCount);
// 逐行按主键更新,项目、单元和等级不进入SET子句,杜绝标准类目被请求覆盖。
for (PracticePaperRuleEntity row : stored) {
PracticePaperRuleEntity update = new PracticePaperRuleEntity();
update.setId(row.getId());
update.setAssessmentDuration(row.getAssessmentDuration());
update.setScore(row.getScore());
update.setQuestionCount(row.getQuestionCount());
update.setUpdatedBy(row.getUpdatedBy());
update.setUpdatedTime(row.getUpdatedTime());
if (baseMapper.updateById(update) != 1) {
throw new BusinessException("实操组卷规则保存失败,请稍后重试");
}
}
return assemble(request.getLev(), grade, stored, false);
}
/** 将“污水一级”“污泥一级”以及直接传入的“一级”统一为Excel中的标准等级。 */
String normalizeGrade(String level) {
String normalized = requireText(level, "职级", 32);
for (String grade : GRADES) {
if (normalized.endsWith(grade)) {
return grade;
}
}
throw new BusinessException("实操职级必须以一级、二级、三级、四级或五级结尾");
}
/** 数据库没有执行配套SQL时及时给出可操作提示,而不是返回一个看似有效的空配置。 */
private void requireCatalog(String grade, List<PracticePaperRuleEntity> rows) {
if (rows == null || rows.isEmpty()) {
throw new BusinessException(grade + "实操类目不存在,请先执行实操组卷规则SQL脚本");
}
}
private PracticePaperRuleConfigurationVO assemble(String level, String grade,
List<PracticePaperRuleEntity> rows,
boolean effectiveOnly) {
List<PracticePaperRuleItemVO> items = new ArrayList<>();
int totalCount = 0;
int totalDuration = 0;
BigDecimal totalScore = BigDecimal.ZERO;
for (PracticePaperRuleEntity row : rows) {
int count = row.getQuestionCount() == null ? 0 : row.getQuestionCount();
if (effectiveOnly && count <= 0) {
continue;
}
int duration = row.getAssessmentDuration() == null
? DEFAULT_DURATION : row.getAssessmentDuration();
BigDecimal score = row.getScore() == null ? DEFAULT_SCORE : row.getScore();
PracticePaperRuleItemVO item = new PracticePaperRuleItemVO();
item.setId(row.getId());
item.setProjectName(row.getProjectName());
item.setUnitContent(row.getUnitContent());
item.setAssessmentDuration(duration);
item.setScore(score.setScale(2, RoundingMode.HALF_UP));
item.setQuestionCount(count);
item.setSubtotalDuration(duration * count);
item.setSubtotalScore(score.multiply(BigDecimal.valueOf(count))
.setScale(2, RoundingMode.HALF_UP));
items.add(item);
totalCount += count;
totalDuration += item.getSubtotalDuration();
totalScore = totalScore.add(item.getSubtotalScore());
}
PracticePaperRuleConfigurationVO result = new PracticePaperRuleConfigurationVO();
result.setLev(level == null ? null : level.trim());
result.setGrade(grade);
result.setTotalQuestionCount(totalCount);
result.setTotalDuration(totalDuration);
result.setTotalScore(totalScore.setScale(2, RoundingMode.HALF_UP));
result.setRuleList(items);
return result;
}
private int normalizeDuration(Integer value) {
int duration = value == null ? DEFAULT_DURATION : value;
if (duration <= 0 || duration > MAX_DURATION) {
throw new BusinessException("单题考核时间必须在1到600分钟之间");
}
return duration;
}
private BigDecimal normalizeScore(BigDecimal value) {
BigDecimal score = value == null ? DEFAULT_SCORE : value.setScale(2, RoundingMode.HALF_UP);
if (score.compareTo(BigDecimal.ZERO) <= 0 || score.compareTo(MAX_SCORE) > 0) {
throw new BusinessException("单题配分必须大于0且不超过99999.99");
}
return score;
}
private int normalizeQuestionCount(Integer value) {
int count = value == null ? 0 : value;
if (count < 0 || count > MAX_TOTAL_QUESTION_COUNT) {
throw new BusinessException("单个类目考核题量必须在0到5题之间");
}
return count;
}
/** 除“不超过五题”外要求至少一题,防止保存后recent接口没有可执行规则。 */
private void validateTotalQuestionCount(Integer count) {
if (count == null || count <= 0 || count > MAX_TOTAL_QUESTION_COUNT) {
throw new BusinessException("考核总题数必须在1到5题之间");
}
}
private String requireText(String value, String fieldName, int maxLength) {
String normalized = value == null ? null : value.trim();
if (normalized == null || normalized.isEmpty()) {
throw new BusinessException(fieldName + "不能为空");
}
if (normalized.length() > maxLength) {
throw new BusinessException(fieldName + "不能超过" + maxLength + "个字符");
}
return normalized;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.platform.business.mapper.PracticePaperRuleMapper">
<select id="selectByGradeForUpdate"
resultType="com.platform.business.model.entity.PracticePaperRuleEntity">
select id,
level_grade,
project_name,
unit_content,
assessment_duration,
score,
question_count,
created_time,
updated_time,
updated_by
from practice_paper_rule
where level_grade = #{grade}
order by id asc
for update
</select>
</mapper>
# 管理员端实操自动组卷规则接口
页面位置为“管理员 → 智能考评 → 试卷管理 → 自动组卷 → 实操”。实操与理论的
行为不同:这里只配置类目、考核时间、配分和题量,不生成正式试卷。
部署前执行:
```text
practical-business/src/main/resources/sql/practice_paper_rule.sql
```
## 1. 查询配置
`GET /theoretical/paper/admin/practice/auto-configuration?lev=污水一级`
`污水一级`、`污泥一级`和`一级`都会匹配 Excel 中的`一级`类目。返回全部标准类目,
包括当前题量为0的未选类目。初始考核时间和配分均为20;每个等级按 Excel 顺序默认
启用前5项各1题,其余类目题量为0,因此初始总时间100分钟、总分100分。
## 2. 保存配置
`PUT /theoretical/paper/admin/practice/auto-configuration`
```json
{
"lev": "污水五级",
"ruleList": [
{"id": 1, "assessmentDuration": 20, "score": 20, "questionCount": 1},
{"id": 2, "assessmentDuration": 20, "score": 20, "questionCount": 1},
{"id": 3, "assessmentDuration": 20, "score": 20, "questionCount": 1},
{"id": 4, "assessmentDuration": 20, "score": 20, "questionCount": 1},
{"id": 5, "assessmentDuration": 20, "score": 20, "questionCount": 1},
{"id": 6, "assessmentDuration": 20, "score": 20, "questionCount": 0}
]
}
```
必须回传查询接口返回的该等级全部类目。服务端只按ID更新考核时间、配分和题量,不能
修改 Excel 标准项目与单元内容。所有类目的`questionCount`合计必须为1至5。
## 3. 学员最近实训考试
`GET /exam/student/recent/{studentId}` 原有字段不变,新增 `practiceRule`:
```json
{
"practiceRule": {
"lev": "五级",
"grade": "五级",
"totalQuestionCount": 5,
"totalDuration": 100,
"totalScore": 100.00,
"ruleList": [
{
"id": 1,
"projectName": "运行管理",
"unitContent": "日常运行管理",
"assessmentDuration": 20,
"score": 20.00,
"questionCount": 1,
"subtotalDuration": 20,
"subtotalScore": 20.00
}
]
}
}
```
该字段每次请求读取管理员当前最新配置,不固化到考试快照。`ruleList`只包含题量大于0
的当前生效规则。
-- 管理员端“智能考评-试卷管理-自动组卷(实操)”规则配置(MySQL 5.7+/8.0)。
--
-- 业务口径:
-- 1. 实操自动组卷只保存规则,不生成theoretical_paper或正式试卷明细。
-- 2. level_grade使用Excel中的一级至五级;污水一级、污泥一级等职级在服务层统一匹配一级。
-- 3. 考核时间和单题配分默认20;每级默认启用Excel顺序前5项各1题,整套题量1至5由服务层校验。
-- 4. INSERT IGNORE只补充缺失类目,重复执行不会覆盖管理员已经保存的时间、配分和题量。
create table if not exists practice_paper_rule (
id int not null auto_increment comment '规则ID',
level_grade varchar(8) not null comment '标准等级:一级至五级',
project_name varchar(64) not null comment 'Excel项目名称',
unit_content varchar(128) not null comment 'Excel单元内容',
assessment_duration int not null default 20 comment '单题考核时间(分钟)',
score decimal(8,2) not null default 20.00 comment '单题配分',
question_count int not null default 0 comment '该类目考核题量;整套合计最多5题',
created_time datetime not null default current_timestamp comment '创建时间',
updated_time datetime not null default current_timestamp comment '更新时间',
updated_by varchar(64) null comment '最后更新管理员ID',
primary key (id),
unique key uk_practice_rule_grade_project_unit (level_grade, project_name, unit_content),
key idx_practice_rule_grade_id (level_grade, id)
) engine=InnoDB default charset=utf8mb4 collate=utf8mb4_unicode_ci
comment='实操自动组卷类目、考核时间及配分规则';
-- 五级(6条)
insert ignore into practice_paper_rule
(level_grade, project_name, unit_content, assessment_duration, score, question_count)
values
('五级', '运行管理', '日常运行管理', 20, 20.00, 1),
('五级', '运行管理', '基础化验', 20, 20.00, 1),
('五级', '设施设备管理', '基础设备操作', 20, 20.00, 1),
('五级', '设施设备管理', '常用仪表操作', 20, 20.00, 1),
('五级', '安全管理', '安全生产管理', 20, 20.00, 1),
('五级', '安全管理', '安全操作注意事项', 20, 20.00, 0);
-- 四级(6条)
insert ignore into practice_paper_rule
(level_grade, project_name, unit_content, assessment_duration, score, question_count)
values
('四级', '运行管理', '日常运行管理', 20, 20.00, 1),
('四级', '运行管理', '日常运行操作', 20, 20.00, 1),
('四级', '设施设备管理', '设备维护', 20, 20.00, 1),
('四级', '设施设备管理', '仪表维护', 20, 20.00, 1),
('四级', '安全管理', '日常防护操作', 20, 20.00, 1),
('四级', '安全管理', '常见急救操作', 20, 20.00, 0);
-- 三级(6条)
insert ignore into practice_paper_rule
(level_grade, project_name, unit_content, assessment_duration, score, question_count)
values
('三级', '运行管理', '工艺运行分析', 20, 20.00, 1),
('三级', '运行管理', '工艺运行调整', 20, 20.00, 1),
('三级', '设施设备管理', '设备维修', 20, 20.00, 1),
('三级', '设施设备管理', '仪表校验', 20, 20.00, 1),
('三级', '安全管理', '特种设备操作管理', 20, 20.00, 1),
('三级', '安全管理', '应急预案管理', 20, 20.00, 0);
-- 二级(9条)
insert ignore into practice_paper_rule
(level_grade, project_name, unit_content, assessment_duration, score, question_count)
values
('二级', '运行管理', '工艺管理', 20, 20.00, 1),
('二级', '运行管理', '工艺优化', 20, 20.00, 1),
('二级', '设施设备管理', '设施设备操作', 20, 20.00, 1),
('二级', '设施设备管理', '电气自动化操作', 20, 20.00, 1),
('二级', '设施设备管理', '生产仪表操作', 20, 20.00, 1),
('二级', '技术管理', '智能应用', 20, 20.00, 0),
('二级', '技术管理', '前沿技术探索', 20, 20.00, 0),
('二级', '安全管理', '制度制定与管理', 20, 20.00, 0),
('二级', '安全管理', '安全评估', 20, 20.00, 0);
-- 一级(9条)。Excel原“设施设备擦欧总”经业务确认修正为“设施设备操作”。
insert ignore into practice_paper_rule
(level_grade, project_name, unit_content, assessment_duration, score, question_count)
values
('一级', '运行管理', '项目开发', 20, 20.00, 1),
('一级', '运行管理', '项目应用', 20, 20.00, 1),
('一级', '设施设备管理', '设施设备操作', 20, 20.00, 1),
('一级', '设施设备管理', '电气自动化操作', 20, 20.00, 1),
('一级', '设施设备管理', '生产仪表操作', 20, 20.00, 1),
('一级', '技术管理', '智能应用', 20, 20.00, 0),
('一级', '技术管理', '前沿技术探索', 20, 20.00, 0),
('一级', '安全管理', '现场安全管理', 20, 20.00, 0),
('一级', '安全管理', '新业态项目安全管理', 20, 20.00, 0);
-- 部署后核对:应返回五级6、四级6、三级6、二级9、一级9,共36条。
select level_grade, count(*) as category_count
from practice_paper_rule
group by level_grade
order by field(level_grade, '五级', '四级', '三级', '二级', '一级');
package com.platform.business.controller;
import com.platform.business.model.dto.ExamReviewSaveDTO;
import com.platform.business.model.dto.ExamReviewStudentQueryDTO;
import com.platform.business.model.dto.ExamReviewTaskQueryDTO;
import com.platform.business.model.entity.UserEntity;
import com.platform.business.service.AuthenticatedUserService;
import com.platform.business.service.ExamReviewService;
import com.platform.exception.BusinessException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.Collections;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/** 教师成绩批阅接口的路径、角色校验、分页边界和参数转发测试。 */
@ExtendWith(MockitoExtension.class)
class ExamReviewControllerTest {
@Mock
private ExamReviewService examReviewService;
@Mock
private AuthenticatedUserService authenticatedUserService;
private ExamReviewController controller;
@BeforeEach
void setUp() {
controller = new ExamReviewController();
ReflectionTestUtils.setField(controller, "examReviewService", examReviewService);
ReflectionTestUtils.setField(controller, "authenticatedUserService", authenticatedUserService);
}
@Test
void canonicalPathShouldBelongToTeacherScoreManagementAndKeepLegacyAlias() {
RequestMapping mapping = ExamReviewController.class.getAnnotation(RequestMapping.class);
assertArrayEquals(new String[]{"/exam/teacher/scores/review", "/exam/review"},
mapping.value());
}
@Test
void allReviewEndpointsShouldRequireTeacherAndForwardTrustedTeacherId() {
MockHttpServletRequest request = new MockHttpServletRequest();
UserEntity teacher = new UserEntity();
teacher.setId("teacher-1");
when(authenticatedUserService.current(request)).thenReturn(teacher);
when(examReviewService.queryTasks(any(ExamReviewTaskQueryDTO.class), eq("teacher-1")))
.thenReturn(Collections.emptyList());
when(examReviewService.queryStudents(any(ExamReviewStudentQueryDTO.class), eq("teacher-1")))
.thenReturn(Collections.emptyList());
when(examReviewService.history(22, "teacher-1")).thenReturn(Collections.emptyList());
ExamReviewTaskQueryDTO taskQuery = new ExamReviewTaskQueryDTO();
taskQuery.setPageNum(0);
taskQuery.setPageSize(1000);
ExamReviewStudentQueryDTO studentQuery = new ExamReviewStudentQueryDTO();
studentQuery.setPageNum(-1);
studentQuery.setPageSize(0);
ExamReviewSaveDTO saveDTO = new ExamReviewSaveDTO();
controller.taskPage(taskQuery, request);
controller.studentPage(studentQuery, request);
controller.paper(22, request);
controller.saveScores(22, saveDTO, request);
controller.publish(11, request);
controller.history(22, request);
verify(authenticatedUserService, times(6)).requireTeacher(teacher);
verify(examReviewService).paper(22, "teacher-1");
verify(examReviewService).saveScores(22, saveDTO, "teacher-1");
verify(examReviewService).publish(11, "teacher-1");
assertEquals(1, taskQuery.getPageNum());
assertEquals(100, taskQuery.getPageSize());
assertEquals(1, studentQuery.getPageNum());
assertEquals(20, studentQuery.getPageSize());
}
@Test
void administratorRoleFailureShouldStopBeforeReviewService() {
MockHttpServletRequest request = new MockHttpServletRequest();
UserEntity administrator = new UserEntity();
administrator.setId("admin-1");
when(authenticatedUserService.current(request)).thenReturn(administrator);
doThrow(new BusinessException("只有教师可以访问教师端接口"))
.when(authenticatedUserService).requireTeacher(administrator);
assertThrows(BusinessException.class, () -> controller.publish(11, request));
verify(examReviewService, never()).publish(any(), any());
}
}
package com.platform.business.controller; package com.platform.business.controller;
import com.platform.business.model.dto.TheoreticalPaperAutoSaveDTO; import com.platform.business.model.dto.TheoreticalPaperAutoSaveDTO;
import com.platform.business.model.dto.PracticePaperRuleSaveDTO;
import com.platform.business.model.dto.TheoreticalPaperDTO; import com.platform.business.model.dto.TheoreticalPaperDTO;
import com.platform.business.model.dto.TheoreticalPaperManualSaveDTO; import com.platform.business.model.dto.TheoreticalPaperManualSaveDTO;
import com.platform.business.model.dto.TheoreticalPaperStatusDTO; import com.platform.business.model.dto.TheoreticalPaperStatusDTO;
import com.platform.business.model.entity.UserEntity; import com.platform.business.model.entity.UserEntity;
import com.platform.business.service.AuthenticatedUserService; import com.platform.business.service.AuthenticatedUserService;
import com.platform.business.service.PracticePaperRuleService;
import com.platform.business.service.TheoreticalPaperAdminService; import com.platform.business.service.TheoreticalPaperAdminService;
import com.platform.business.service.TheoreticalPaperService; import com.platform.business.service.TheoreticalPaperService;
import com.platform.exception.BusinessException; import com.platform.exception.BusinessException;
...@@ -37,6 +39,8 @@ class TheoreticalPaperAdminControllerTest { ...@@ -37,6 +39,8 @@ class TheoreticalPaperAdminControllerTest {
private TheoreticalPaperService legacyPaperService; private TheoreticalPaperService legacyPaperService;
@Mock @Mock
private AuthenticatedUserService authenticatedUserService; private AuthenticatedUserService authenticatedUserService;
@Mock
private PracticePaperRuleService practicePaperRuleService;
private TheoreticalPaperAdminController controller; private TheoreticalPaperAdminController controller;
...@@ -46,6 +50,7 @@ class TheoreticalPaperAdminControllerTest { ...@@ -46,6 +50,7 @@ class TheoreticalPaperAdminControllerTest {
ReflectionTestUtils.setField(controller, "paperAdminService", paperAdminService); ReflectionTestUtils.setField(controller, "paperAdminService", paperAdminService);
ReflectionTestUtils.setField(controller, "legacyPaperService", legacyPaperService); ReflectionTestUtils.setField(controller, "legacyPaperService", legacyPaperService);
ReflectionTestUtils.setField(controller, "authenticatedUserService", authenticatedUserService); ReflectionTestUtils.setField(controller, "authenticatedUserService", authenticatedUserService);
ReflectionTestUtils.setField(controller, "practicePaperRuleService", practicePaperRuleService);
} }
@Test @Test
...@@ -54,6 +59,7 @@ class TheoreticalPaperAdminControllerTest { ...@@ -54,6 +59,7 @@ class TheoreticalPaperAdminControllerTest {
MockHttpServletResponse response = new MockHttpServletResponse(); MockHttpServletResponse response = new MockHttpServletResponse();
UserEntity administrator = new UserEntity(); UserEntity administrator = new UserEntity();
administrator.setNickName("管理员甲"); administrator.setNickName("管理员甲");
administrator.setId("admin-1");
when(authenticatedUserService.current(request)).thenReturn(administrator); when(authenticatedUserService.current(request)).thenReturn(administrator);
when(paperAdminService.page(org.mockito.ArgumentMatchers.any())) when(paperAdminService.page(org.mockito.ArgumentMatchers.any()))
.thenReturn(Collections.emptyList()); .thenReturn(Collections.emptyList());
...@@ -62,10 +68,13 @@ class TheoreticalPaperAdminControllerTest { ...@@ -62,10 +68,13 @@ class TheoreticalPaperAdminControllerTest {
TheoreticalPaperAutoSaveDTO automatic = new TheoreticalPaperAutoSaveDTO(); TheoreticalPaperAutoSaveDTO automatic = new TheoreticalPaperAutoSaveDTO();
TheoreticalPaperManualSaveDTO manual = new TheoreticalPaperManualSaveDTO(); TheoreticalPaperManualSaveDTO manual = new TheoreticalPaperManualSaveDTO();
TheoreticalPaperStatusDTO status = new TheoreticalPaperStatusDTO(); TheoreticalPaperStatusDTO status = new TheoreticalPaperStatusDTO();
PracticePaperRuleSaveDTO practiceRule = new PracticePaperRuleSaveDTO();
status.setStatus("ARCHIVED"); status.setStatus("ARCHIVED");
controller.page(query, request); controller.page(query, request);
controller.autoConfiguration("污水一级", request); controller.autoConfiguration("污水一级", request);
controller.practiceAutoConfiguration("污水一级", request);
controller.savePracticeAutoConfiguration(practiceRule, request);
controller.createAutomatic(automatic, request); controller.createAutomatic(automatic, request);
controller.createManual(manual, request); controller.createManual(manual, request);
controller.detail("paper-1", request); controller.detail("paper-1", request);
...@@ -76,7 +85,9 @@ class TheoreticalPaperAdminControllerTest { ...@@ -76,7 +85,9 @@ class TheoreticalPaperAdminControllerTest {
controller.export("paper-1", request, response); controller.export("paper-1", request, response);
controller.exportWithAnswer("paper-1", request, response); controller.exportWithAnswer("paper-1", request, response);
verify(authenticatedUserService, times(11)).requireAdmin(administrator); verify(authenticatedUserService, times(13)).requireAdmin(administrator);
verify(practicePaperRuleService).configuration("污水一级");
verify(practicePaperRuleService).saveConfiguration(practiceRule, "admin-1");
verify(paperAdminService).createAutomatic(automatic, "管理员甲"); verify(paperAdminService).createAutomatic(automatic, "管理员甲");
verify(paperAdminService).createManual(manual, "管理员甲"); verify(paperAdminService).createManual(manual, "管理员甲");
verify(paperAdminService).copy("paper-1", "管理员甲"); verify(paperAdminService).copy("paper-1", "管理员甲");
......
package com.platform.business.service.impl;
import com.platform.business.mapper.ExamStudentMapper;
import com.platform.business.model.vo.ExamStudentVO;
import com.platform.business.model.vo.PracticePaperRuleConfigurationVO;
import com.platform.business.service.PracticePaperRuleService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.util.ReflectionTestUtils;
import java.util.Collections;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/** 最近实训考试接口接入当前最新实操配分规则的回归测试。 */
@ExtendWith(MockitoExtension.class)
class ExamStaudentServiceImplTest {
@Mock
private ExamStudentMapper mapper;
@Mock
private PracticePaperRuleService practicePaperRuleService;
private ExamStaudentServiceImpl service;
@BeforeEach
void setUp() {
service = new ExamStaudentServiceImpl();
ReflectionTestUtils.setField(service, "baseMapper", mapper);
ReflectionTestUtils.setField(service, "practicePaperRuleService", practicePaperRuleService);
}
@Test
void recentShouldAttachLatestEffectiveRuleAndSameEventStudents() {
ExamStudentVO recent = new ExamStudentVO();
recent.setExamId(88);
recent.setLev("污水一级");
PracticePaperRuleConfigurationVO configuration = new PracticePaperRuleConfigurationVO();
configuration.setGrade("一级");
when(mapper.recent("student-1")).thenReturn(recent);
when(practicePaperRuleService.effectiveConfiguration("污水一级"))
.thenReturn(configuration);
when(mapper.theSameEvent(88)).thenReturn(Collections.singletonList(new ExamStudentVO()));
ExamStudentVO result = service.recent("student-1");
assertEquals(configuration, result.getPracticeRule());
assertEquals(1, result.getData().size());
}
@Test
void recentShouldReturnNullWithoutQueryingRulesWhenStudentHasNoPracticeExam() {
when(mapper.recent("student-2")).thenReturn(null);
assertNull(service.recent("student-2"));
verify(practicePaperRuleService, never()).effectiveConfiguration(org.mockito.ArgumentMatchers.anyString());
verify(mapper, never()).theSameEvent(org.mockito.ArgumentMatchers.anyInt());
}
}
package com.platform.business.service.impl;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.platform.business.mapper.PracticePaperRuleMapper;
import com.platform.business.model.dto.PracticePaperRuleItemDTO;
import com.platform.business.model.dto.PracticePaperRuleSaveDTO;
import com.platform.business.model.entity.PracticePaperRuleEntity;
import com.platform.business.model.vo.PracticePaperRuleConfigurationVO;
import com.platform.exception.BusinessException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.util.ReflectionTestUtils;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/** 实操组卷规则的等级归一化、默认值、汇总和五题上限测试。 */
@ExtendWith(MockitoExtension.class)
class PracticePaperRuleServiceImplTest {
@Mock
private PracticePaperRuleMapper mapper;
private PracticePaperRuleServiceImpl service;
@BeforeEach
void setUp() {
service = new PracticePaperRuleServiceImpl();
// ServiceImpl通过protected baseMapper访问数据库,单元测试显式注入以隔离Spring容器。
ReflectionTestUtils.setField(service, "baseMapper", mapper);
}
@Test
@SuppressWarnings("unchecked")
void configurationShouldShareSuffixGradeAndCalculateTotals() {
List<PracticePaperRuleEntity> rows = Arrays.asList(
rule(1, "一级", "运行管理", "项目开发", 20, "20.00", 2),
rule(2, "一级", "安全管理", "现场安全管理", 30, "10.50", 1));
when(mapper.selectList(any(Wrapper.class))).thenReturn(rows);
PracticePaperRuleConfigurationVO result = service.configuration("污泥一级");
assertEquals("一级", result.getGrade());
assertEquals("污泥一级", result.getLev());
assertEquals(3, result.getTotalQuestionCount());
assertEquals(70, result.getTotalDuration());
assertEquals(new BigDecimal("50.50"), result.getTotalScore());
assertEquals(2, result.getRuleList().size());
}
@Test
void saveShouldRejectMoreThanFiveQuestionsBeforeAnyUpdate() {
List<PracticePaperRuleEntity> stored = new ArrayList<>();
List<PracticePaperRuleItemDTO> submitted = new ArrayList<>();
for (int index = 1; index <= 6; index++) {
stored.add(rule(index, "五级", "项目" + index, "单元" + index,
20, "20.00", 0));
submitted.add(item(index, 20, "20.00", 1));
}
when(mapper.selectByGradeForUpdate("五级")).thenReturn(stored);
PracticePaperRuleSaveDTO request = new PracticePaperRuleSaveDTO();
request.setLev("污水五级");
request.setRuleList(submitted);
BusinessException error = assertThrows(BusinessException.class,
() -> service.saveConfiguration(request, "admin-1"));
assertEquals("考核总题数必须在1到5题之间", error.getMessage());
verify(mapper, never()).updateById(any(PracticePaperRuleEntity.class));
}
@Test
void saveShouldApplyTwentyDefaultsAndOnlyUpdateMutableColumns() {
PracticePaperRuleEntity stored = rule(7, "三级", "运行管理", "工艺运行分析",
15, "15.00", 0);
when(mapper.selectByGradeForUpdate("三级")).thenReturn(Arrays.asList(stored));
when(mapper.updateById(any(PracticePaperRuleEntity.class))).thenReturn(1);
PracticePaperRuleItemDTO submitted = new PracticePaperRuleItemDTO();
submitted.setId(7);
submitted.setQuestionCount(1);
PracticePaperRuleSaveDTO request = new PracticePaperRuleSaveDTO();
request.setLev("污水三级");
request.setRuleList(Arrays.asList(submitted));
PracticePaperRuleConfigurationVO result = service.saveConfiguration(request, "admin-2");
assertEquals(20, result.getTotalDuration());
assertEquals(new BigDecimal("20.00"), result.getTotalScore());
ArgumentCaptor<PracticePaperRuleEntity> captor =
ArgumentCaptor.forClass(PracticePaperRuleEntity.class);
verify(mapper).updateById(captor.capture());
PracticePaperRuleEntity update = captor.getValue();
assertEquals(7, update.getId());
assertEquals(20, update.getAssessmentDuration());
assertEquals(new BigDecimal("20.00"), update.getScore());
assertEquals(1, update.getQuestionCount());
// 标准类目不进入更新对象,确保客户端永远不能修改Excel类目。
assertEquals(null, update.getProjectName());
assertEquals(null, update.getUnitContent());
}
private PracticePaperRuleEntity rule(int id, String grade, String project, String unit,
int duration, String score, int count) {
PracticePaperRuleEntity row = new PracticePaperRuleEntity();
row.setId(id);
row.setLevelGrade(grade);
row.setProjectName(project);
row.setUnitContent(unit);
row.setAssessmentDuration(duration);
row.setScore(new BigDecimal(score));
row.setQuestionCount(count);
return row;
}
private PracticePaperRuleItemDTO item(int id, int duration, String score, int count) {
PracticePaperRuleItemDTO item = new PracticePaperRuleItemDTO();
item.setId(id);
item.setAssessmentDuration(duration);
item.setScore(new BigDecimal(score));
item.setQuestionCount(count);
return item;
}
}
package com.platform.business.sql;
import org.junit.jupiter.api.Test;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
/** 验证实操规则SQL包含幂等表结构、默认值、Excel类目及已确认的错字修正。 */
class PracticePaperRuleMigrationSqlTest {
@Test
void migrationShouldSeedConfirmedCatalogWithoutOverwritingSavedConfiguration() throws Exception {
String sql;
try (InputStream input = Thread.currentThread().getContextClassLoader()
.getResourceAsStream("sql/practice_paper_rule.sql")) {
assertTrue(input != null, "实操规则SQL资源必须存在");
byte[] buffer = new byte[8192];
StringBuilder content = new StringBuilder();
int length;
while ((length = input.read(buffer)) >= 0) {
content.append(new String(buffer, 0, length, StandardCharsets.UTF_8));
}
sql = content.toString().toLowerCase();
}
assertTrue(sql.contains("create table if not exists practice_paper_rule"));
assertTrue(sql.contains("assessment_duration int not null default 20"));
assertTrue(sql.contains("score decimal(8,2) not null default 20.00"));
assertTrue(sql.contains("insert ignore into practice_paper_rule"));
assertTrue(sql.contains("'设施设备操作'"));
assertFalse(sql.contains("'设施设备擦欧总'"));
assertTrue(sql.contains("'新业态项目安全管理'"));
}
}
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