"src/main/git@gitlab.ruzhoukj.com:wujipeng/relation.git" did not exist on "3fa4400316a8f25d750ca65b2ae05871e847283d"
Commit 67ead0bb authored by 王蔡翾's avatar 王蔡翾
Browse files

bug修复

parent 2c66995a
package com.platform.business.model.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
import java.util.List;
/**
* 学员最近一场考试信息。
*
* <p>该接口返回的是考试安排本身,因此开始时间和考试时长分别使用
* {@code exam.exam_time} 与 {@code exam.duration}。不能复用
* {@link com.platform.business.model.entity.ExamStudentEntity} 中的同名字段:
* 后者表示考生实际开始答题的毫秒时间戳和实际答题时长字符串,类型及语义均不同。</p>
*/
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class RecentExamStudentVO {
/**
* 保留历史响应中的关联记录占位字段。
*
* <p>当前查询不返回关联记录主键,因此值保持为0,与原接口响应兼容。</p>
*/
@ApiModelProperty(value = "考试学员关联记录id")
private int id;
/**
* 保留历史响应中的班级占位字段。
*
* <p>班级名称来自考试安排;当前接口未返回班级主键,因此值保持为0。</p>
*/
@ApiModelProperty(value = "班级id")
private int classId;
@ApiModelProperty(value = "考试id")
private int examId;
@ApiModelProperty(value = "考试名称")
private String examName;
@ApiModelProperty(value = "考试类型")
private String type;
@ApiModelProperty(value = "班级名称")
private String className;
@ApiModelProperty(value = "等级")
private String lev;
/** 考试安排的开始时间,统一按北京时间返回完整日期和时间。 */
@ApiModelProperty(value = "开始时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date startTime;
/** 考试安排的规定时长,单位为分钟。 */
@ApiModelProperty(value = "考试时长,单位:分钟")
private Integer duration;
@ApiModelProperty(value = "禁止交卷时间,单位:分钟")
private Integer forbid;
@ApiModelProperty(value = "首席考评员id")
private String chiefId;
@ApiModelProperty(value = "监考教师id,多个id使用英文逗号分隔")
private String invigilationId;
/**
* 当前最新的实操组卷及配分规则扩展字段。
*
* <p>该字段是现有项目在基础接口契约上的扩展。为保持调用方兼容,无论最近考试的
* 实际类型为何,字段结构均会保留,并按学生等级读取最新实操配置。</p>
*/
@ApiModelProperty(value = "当前最新实操组卷及配分规则")
private PracticePaperRuleConfigurationVO practiceRule;
/** 同一场考试的全部学员;列表项保留原接口使用的精简学员结构。 */
@ApiModelProperty(value = "同场考试学生")
private List<ExamStudentVO> data;
}
...@@ -52,6 +52,11 @@ ...@@ -52,6 +52,11 @@
<version>0.11.5</version> <version>0.11.5</version>
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- logstash --> <!-- logstash -->
<!-- <dependency>--> <!-- <dependency>-->
......
...@@ -17,32 +17,34 @@ ...@@ -17,32 +17,34 @@
ur.user_id = #{userId} ur.user_id = #{userId}
</select> </select>
<select id="queryExamType" resultType="java.lang.String"> <select id="queryExamType" resultType="java.lang.String">
select IF((count(*) > 0), '考试', '演示') type <!--
from exam_student exam_time现在保存考试开始时刻,结束时刻由duration计算。开始时刻计入考试中,
where student_id = #{id} 结束时刻不再计入,边界与业务模块的考试状态判定保持一致。
and exam_id in (SELECT -->
id select if(count(*) &gt; 0, '考试', '演示') type
FROM from exam_student es
exam inner join exam e on e.id = es.exam_id
WHERE where es.student_id = #{id}
NOW() BETWEEN and e.exam_time &lt;= now()
STR_TO_DATE(TRIM(SUBSTRING_INDEX(exam_time, '-', 1)), '%Y.%m.%d %H:%i:%s') and timestampadd(
AND minute,
STR_TO_DATE(TRIM(SUBSTRING_INDEX(exam_time, '-', -1)), '%Y.%m.%d %H:%i:%s')); greatest(coalesce(e.duration, 0), 0),
e.exam_time
) &gt; now()
</select> </select>
<select id="queryExamId" resultType="java.lang.Integer"> <select id="queryExamId" resultType="java.lang.Integer">
select exam_id <!-- 登录接口依赖该查询决定type;只返回当前时间确实处于考试区间内的考试。 -->
from exam_student select es.exam_id
where student_id = #{id} from exam_student es
and exam_id in (SELECT inner join exam e on e.id = es.exam_id
id where es.student_id = #{id}
FROM and e.exam_time &lt;= now()
exam and timestampadd(
WHERE minute,
NOW() BETWEEN greatest(coalesce(e.duration, 0), 0),
STR_TO_DATE(TRIM(SUBSTRING_INDEX(exam_time, '-', 1)), '%Y.%m.%d %H:%i:%s') e.exam_time
AND ) &gt; now()
STR_TO_DATE(TRIM(SUBSTRING_INDEX(exam_time, '-', -1)), '%Y.%m.%d %H:%i:%s')) order by e.exam_time desc, es.exam_id desc
limit 1; limit 1
</select> </select>
</mapper> </mapper>
package com.platform.auth.mapper;
import org.apache.ibatis.builder.xml.XMLMapperBuilder;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.session.Configuration;
import org.junit.jupiter.api.Test;
import java.io.InputStream;
import java.util.Collections;
import java.util.Locale;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
/** 验证登录接口使用当前数据模型判断学员是否正处于考试时间段。 */
class UserRoleMapperXmlTest {
@Test
void queryExamIdShouldUseStartTimeAndDuration() throws Exception {
Configuration configuration = parseMapper();
BoundSql boundSql = configuration.getMappedStatement(
"com.platform.auth.mapper.UserRoleMapper.queryExamId")
.getBoundSql(Collections.singletonMap("id", "student-1"));
String sql = normalize(boundSql.getSql());
// 开始时刻属于考试中,结束时刻不属于考试中;该边界与业务模块统一。
assertTrue(sql.contains("e.exam_time <= now()"));
assertTrue(sql.contains("greatest(coalesce(e.duration, 0), 0)"));
assertTrue(sql.contains(") > now()"));
// exam_time已经是DATETIME,禁止再次按旧版字符串区间拆分,否则日期中的“-”会被误拆。
assertFalse(sql.contains("substring_index"));
assertFalse(sql.contains("str_to_date"));
}
@Test
void queryExamTypeShouldUseTheSameActiveTimeRange() throws Exception {
Configuration configuration = parseMapper();
BoundSql boundSql = configuration.getMappedStatement(
"com.platform.auth.mapper.UserRoleMapper.queryExamType")
.getBoundSql(Collections.singletonMap("id", "student-1"));
String sql = normalize(boundSql.getSql());
// queryExamType虽不是当前登录主路径,也必须保持相同规则,避免后续调用重新出现误判。
assertTrue(sql.contains("e.exam_time <= now()"));
assertTrue(sql.contains("greatest(coalesce(e.duration, 0), 0)"));
assertTrue(sql.contains(") > now()"));
}
/** 解析真实Mapper XML,让断言覆盖MyBatis最终交给数据库执行的SQL。 */
private Configuration parseMapper() throws Exception {
String resource = "com/platform/auth/mapper/UserRoleMapper.xml";
Configuration configuration = new Configuration();
try (InputStream input = getClass().getClassLoader().getResourceAsStream(resource)) {
assertNotNull(input);
new XMLMapperBuilder(input, configuration, resource,
configuration.getSqlFragments()).parse();
}
return configuration;
}
private String normalize(String sql) {
return sql.replaceAll("\\s+", " ").trim().toLowerCase(Locale.ROOT);
}
}
...@@ -5,6 +5,7 @@ import com.platform.business.model.vo.ExamPageVO; ...@@ -5,6 +5,7 @@ import com.platform.business.model.vo.ExamPageVO;
import com.platform.business.model.vo.ExamStudentVO; import com.platform.business.model.vo.ExamStudentVO;
import com.platform.business.model.vo.ExamSummaryVO; import com.platform.business.model.vo.ExamSummaryVO;
import com.platform.business.model.vo.ExamVO; import com.platform.business.model.vo.ExamVO;
import com.platform.business.model.vo.RecentExamStudentVO;
import com.platform.business.service.ExamService; import com.platform.business.service.ExamService;
import com.platform.business.service.ExamStudentService; import com.platform.business.service.ExamStudentService;
import com.platform.controller.BaseController; import com.platform.controller.BaseController;
...@@ -76,7 +77,7 @@ public class ExamController extends BaseController { ...@@ -76,7 +77,7 @@ public class ExamController extends BaseController {
@ApiOperation(value = "根据学生id查询最近的一场考试") @ApiOperation(value = "根据学生id查询最近的一场考试")
@GetMapping("/student/recent/{studentId}") @GetMapping("/student/recent/{studentId}")
public Result<ExamStudentVO> recent(@PathVariable String studentId) { public Result<RecentExamStudentVO> recent(@PathVariable String studentId) {
return Result.data(examStudentService.recent(studentId)); return Result.data(examStudentService.recent(studentId));
} }
} }
...@@ -11,6 +11,7 @@ import com.platform.business.model.entity.UserEntity; ...@@ -11,6 +11,7 @@ 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.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.TheoreticalPaperAdminService;
import com.platform.business.service.TheoreticalPaperService; import com.platform.business.service.TheoreticalPaperService;
import com.platform.business.service.TheoreticalPaperTeacherService; import com.platform.business.service.TheoreticalPaperTeacherService;
import com.platform.controller.BaseController; import com.platform.controller.BaseController;
...@@ -37,8 +38,8 @@ import javax.servlet.http.HttpServletResponse; ...@@ -37,8 +38,8 @@ import javax.servlet.http.HttpServletResponse;
* 教师端“智能考评-理论试卷管理”接口。 * 教师端“智能考评-理论试卷管理”接口。
* *
* <p>保留历史页面使用的/page、/auto、/create、/detail和/export路径,同时提供完整的 * <p>保留历史页面使用的/page、/auto、/create、/detail和/export路径,同时提供完整的
* REST接口。所有入口都从Authorization解析当前教师,不接收客户端teacherId;服务层 * REST接口。教师私有数据与写入口从Authorization解析当前教师,并由服务层继续按
* 再按theoretical_paper.creator_id校验归属,形成角色与数据范围两层保护。</p> * theoretical_paper.creator_id校验归属;历史GET /auto仅向已登录用户返回公共组卷配置。</p>
*/ */
@Api(tags = "教师端-理论试卷管理") @Api(tags = "教师端-理论试卷管理")
@RestController @RestController
...@@ -55,6 +56,10 @@ public class TheoreticalPaperController extends BaseController { ...@@ -55,6 +56,10 @@ public class TheoreticalPaperController extends BaseController {
@Resource @Resource
private AuthenticatedUserService authenticatedUserService; private AuthenticatedUserService authenticatedUserService;
/** 复用不包含端侧权限判断的公共组卷配置校验,具体访问权限由控制器入口负责。 */
@Resource
private TheoreticalPaperAdminService paperManagementService;
@ApiOperation("分页查询当前教师创建的试卷") @ApiOperation("分页查询当前教师创建的试卷")
@PostMapping("/page") @PostMapping("/page")
public TableDataInfo page(@RequestBody(required = false) TheoreticalPaperDTO query, public TableDataInfo page(@RequestBody(required = false) TheoreticalPaperDTO query,
...@@ -88,7 +93,12 @@ public class TheoreticalPaperController extends BaseController { ...@@ -88,7 +93,12 @@ public class TheoreticalPaperController extends BaseController {
public Result<CombinationVO> legacyAutoConfiguration(@RequestParam("lev") String level, public Result<CombinationVO> legacyAutoConfiguration(@RequestParam("lev") String level,
HttpServletRequest request) { HttpServletRequest request) {
authenticatedUserService.current(request); authenticatedUserService.current(request);
return Result.data(legacyPaperService.auto(level)); /*
* 必须复用当前正式组卷配置服务:它会规范职级、补全题量与配分,并在配置为空时
* 明确报错。旧auto()会把缺失配置静默返回为空列表,随后模拟考场会创建空试卷。
* 此处只读取公共配置,教师试卷的创建、编辑等写接口仍由currentTeacher()保护。
*/
return Result.data(paperManagementService.autoConfiguration(level));
} }
@ApiOperation("按数据库最新规则自动创建当前教师的试卷") @ApiOperation("按数据库最新规则自动创建当前教师的试卷")
......
...@@ -3,6 +3,7 @@ package com.platform.business.mapper; ...@@ -3,6 +3,7 @@ package com.platform.business.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
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.model.vo.RecentExamStudentVO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
...@@ -19,7 +20,7 @@ public interface ExamStudentMapper extends BaseMapper<ExamStudentEntity> { ...@@ -19,7 +20,7 @@ public interface ExamStudentMapper extends BaseMapper<ExamStudentEntity> {
List<ExamStudentVO> queryOneselfTeacher(@Param("userId")String userId); List<ExamStudentVO> queryOneselfTeacher(@Param("userId")String userId);
ExamStudentVO recent(@Param("studentId") String studentId); RecentExamStudentVO recent(@Param("studentId") String studentId);
List<ExamStudentVO> theSameEvent(@Param("examId") Integer examId); List<ExamStudentVO> theSameEvent(@Param("examId") Integer examId);
......
...@@ -7,6 +7,7 @@ import com.platform.business.model.vo.UserVO; ...@@ -7,6 +7,7 @@ import com.platform.business.model.vo.UserVO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.Date;
import java.util.List; import java.util.List;
@Mapper @Mapper
...@@ -20,4 +21,11 @@ public interface UserMapper extends BaseMapper<UserEntity> { ...@@ -20,4 +21,11 @@ public interface UserMapper extends BaseMapper<UserEntity> {
void closeSimulation(@Param("studentId") String studentId); void closeSimulation(@Param("studentId") String studentId);
/**
* 批量激活已经到达开始时间、尚未结束且尚未交卷的考试。
*
* <p>返回实际发生状态变化的用户数;SQL本身保持幂等,允许多个应用实例重复调度。</p>
*/
int activateDueExams(@Param("now") Date now);
} }
...@@ -3,6 +3,7 @@ package com.platform.business.service; ...@@ -3,6 +3,7 @@ package com.platform.business.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
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.model.vo.RecentExamStudentVO;
import java.util.List; import java.util.List;
...@@ -22,6 +23,6 @@ public interface ExamStudentService extends IService<ExamStudentEntity> { ...@@ -22,6 +23,6 @@ public interface ExamStudentService extends IService<ExamStudentEntity> {
List<ExamStudentVO> queryOneselfTeacher(String userId); List<ExamStudentVO> queryOneselfTeacher(String userId);
ExamStudentVO recent(String studentId); RecentExamStudentVO recent(String studentId);
} }
...@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; ...@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.platform.business.mapper.ExamStudentMapper; 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.model.vo.RecentExamStudentVO;
import com.platform.business.service.ExamStudentService; import com.platform.business.service.ExamStudentService;
import com.platform.business.service.PracticePaperRuleService; import com.platform.business.service.PracticePaperRuleService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -40,14 +41,15 @@ public class ExamStaudentServiceImpl extends ServiceImpl<ExamStudentMapper, Exam ...@@ -40,14 +41,15 @@ public class ExamStaudentServiceImpl extends ServiceImpl<ExamStudentMapper, Exam
} }
@Override @Override
public ExamStudentVO recent(String studentId) { public RecentExamStudentVO recent(String studentId) {
ExamStudentVO examStudentVO = baseMapper.recent(studentId); RecentExamStudentVO examStudentVO = baseMapper.recent(studentId);
// 没有实训考试时保持历史接口的null语义,同时避免继续读取examId造成空指针。 // 没有考试时保持历史接口的null语义,同时避免继续读取examId造成空指针。
if (examStudentVO == null) { if (examStudentVO == null) {
return null; return null;
} }
/* /*
* 业务确认不固化考试快照:每次请求都根据学生职级读取当前最新配置。 * 为保持现有扩展字段兼容,不固化实操规则快照:每次请求都根据学生职级读取
* 当前最新配置,无论最近一场考试的实际类型为何,字段结构均保持不变。
* 规则服务会把“污水一级”“污泥一级”统一匹配为Excel中的“一级”。 * 规则服务会把“污水一级”“污泥一级”统一匹配为Excel中的“一级”。
*/ */
examStudentVO.setPracticeRule( examStudentVO.setPracticeRule(
......
...@@ -74,6 +74,8 @@ public class TeachingPlanServiceImpl implements TeachingPlanService { ...@@ -74,6 +74,8 @@ public class TeachingPlanServiceImpl implements TeachingPlanService {
private static final String TEACHING_PLAN_WORD_TEMPLATE = private static final String TEACHING_PLAN_WORD_TEMPLATE =
"templates/teaching-plan/B8-teaching-plan.docx"; "templates/teaching-plan/B8-teaching-plan.docx";
private static final String TEACHING_PLAN_WORD_FONT = "Songti SC"; private static final String TEACHING_PLAN_WORD_FONT = "Songti SC";
/** 表格内固定标签和动态内容统一使用相同字号,避免同一张表出现视觉跳变。 */
private static final int TEACHING_PLAN_WORD_CELL_FONT_SIZE = 10;
@Resource @Resource
private TeachingPlanMapper teachingPlanMapper; private TeachingPlanMapper teachingPlanMapper;
...@@ -807,18 +809,13 @@ public class TeachingPlanServiceImpl implements TeachingPlanService { ...@@ -807,18 +809,13 @@ public class TeachingPlanServiceImpl implements TeachingPlanService {
setWordRowMinimumHeight(summary.getRow(4), setWordRowMinimumHeight(summary.getRow(4),
TeachingPlanConstants.COURSE_TYPE_PRACTICE.equals(plan.getCourseType()) ? 1400 : 1200); TeachingPlanConstants.COURSE_TYPE_PRACTICE.equals(plan.getCourseType()) ? 1400 : 1200);
setWordRowMinimumHeight(summary.getRow(5), 1200); setWordRowMinimumHeight(summary.getRow(5), 1200);
// 四个竖排标签使用较小字号,既完整显示四个汉字,也避免把页下注挤到下一页。
setWordCellFontSize(summary.getRow(4).getCell(0), 10);
setWordCellFontSize(summary.getRow(4).getCell(2), 10);
setWordCellFontSize(summary.getRow(5).getCell(0), 10);
setWordCellFontSize(summary.getRow(5).getCell(2), 10);
setWordRowMinimumHeight(summary.getRow(6), 760); setWordRowMinimumHeight(summary.getRow(6), 760);
setWordRowMinimumHeight(summary.getRow(7), 760); setWordRowMinimumHeight(summary.getRow(7), 760);
setWordRowMinimumHeight(summary.getRow(8), 1300); setWordRowMinimumHeight(summary.getRow(8), 1300);
writeWordCell(summary.getRow(0).getCell(1), plan.getVocationalLevel()); writeWordCell(summary.getRow(0).getCell(1), plan.getVocationalLevel());
writeWordCell(summary.getRow(0).getCell(4), plan.getClassName(), 9); writeWordCell(summary.getRow(0).getCell(4), plan.getClassName());
writeWordCell(summary.getRow(1).getCell(1), plan.getApplicableCourse()); writeWordCell(summary.getRow(1).getCell(1), plan.getApplicableCourse());
writeWordCell(summary.getRow(1).getCell(4), teachingDateAndDuration(plan), 9); writeWordCell(summary.getRow(1).getCell(4), teachingDateAndDuration(plan));
writeWordCell(summary.getRow(2).getCell(1), teachingPlanTopic(plan)); writeWordCell(summary.getRow(2).getCell(1), teachingPlanTopic(plan));
writeWordCell(summary.getRow(3).getCell(1), plan.getTeachingPurpose()); writeWordCell(summary.getRow(3).getCell(1), plan.getTeachingPurpose());
writeWordCell(summary.getRow(4).getCell(1), practiceValue(plan.getPracticeContent(), plan)); writeWordCell(summary.getRow(4).getCell(1), practiceValue(plan.getPracticeContent(), plan));
...@@ -827,7 +824,7 @@ public class TeachingPlanServiceImpl implements TeachingPlanService { ...@@ -827,7 +824,7 @@ public class TeachingPlanServiceImpl implements TeachingPlanService {
writeWordCell(summary.getRow(5).getCell(3), plan.getDifficultPoints()); writeWordCell(summary.getRow(5).getCell(3), plan.getDifficultPoints());
writeWordCell(summary.getRow(6).getCell(1), plan.getTeachingAids()); writeWordCell(summary.getRow(6).getCell(1), plan.getTeachingAids());
writeWordCell(summary.getRow(7).getCell(1), plan.getTeachingNote()); writeWordCell(summary.getRow(7).getCell(1), plan.getTeachingNote());
writeWordCell(summary.getRow(8).getCell(1), approvalText(plan), 10); writeWordCell(summary.getRow(8).getCell(1), approvalText(plan));
XWPFTable stepsTable = document.getTables().get(1); XWPFTable stepsTable = document.getTables().get(1);
if (stepsTable.getRows().size() < 2 || stepsTable.getRow(1).getTableCells().size() < 3) { if (stepsTable.getRows().size() < 2 || stepsTable.getRow(1).getTableCells().size() < 3) {
...@@ -837,7 +834,10 @@ public class TeachingPlanServiceImpl implements TeachingPlanService { ...@@ -837,7 +834,10 @@ public class TeachingPlanServiceImpl implements TeachingPlanService {
writeTeachingPlanSteps(stepsTable.getRow(1), plan.getSteps()); writeTeachingPlanSteps(stepsTable.getRow(1), plan.getSteps());
} }
/** 将模板中未显式指定中文字体的固定文字统一为宋体风格,避免不同系统替换成无字形字体。 */ /**
* 统一模板字体:页眉文字保留原字号,所有表格单元格则统一为同一字体、字号和颜色。
* 动态单元格写入时也使用相同常量,从而保证替换占位内容后样式仍然一致。
*/
private void normalizeTeachingPlanTemplateFont(XWPFDocument document) { private void normalizeTeachingPlanTemplateFont(XWPFDocument document) {
for (XWPFParagraph paragraph : document.getParagraphs()) { for (XWPFParagraph paragraph : document.getParagraphs()) {
setWordRunsFont(paragraph); setWordRunsFont(paragraph);
...@@ -847,6 +847,9 @@ public class TeachingPlanServiceImpl implements TeachingPlanService { ...@@ -847,6 +847,9 @@ public class TeachingPlanServiceImpl implements TeachingPlanService {
for (XWPFTableCell cell : row.getTableCells()) { for (XWPFTableCell cell : row.getTableCells()) {
for (XWPFParagraph paragraph : cell.getParagraphs()) { for (XWPFParagraph paragraph : cell.getParagraphs()) {
setWordRunsFont(paragraph); setWordRunsFont(paragraph);
for (XWPFRun run : paragraph.getRuns()) {
run.setFontSize(TEACHING_PLAN_WORD_CELL_FONT_SIZE);
}
} }
} }
} }
...@@ -861,14 +864,6 @@ public class TeachingPlanServiceImpl implements TeachingPlanService { ...@@ -861,14 +864,6 @@ public class TeachingPlanServiceImpl implements TeachingPlanService {
} }
} }
private void setWordCellFontSize(XWPFTableCell cell, int fontSize) {
for (XWPFParagraph paragraph : cell.getParagraphs()) {
for (XWPFRun run : paragraph.getRuns()) {
run.setFontSize(fontSize);
}
}
}
/** 清空可编辑段落原有占位符,再按模板字号写入动态内容。 */ /** 清空可编辑段落原有占位符,再按模板字号写入动态内容。 */
private void writeWordParagraph(XWPFParagraph paragraph, String content, private void writeWordParagraph(XWPFParagraph paragraph, String content,
ParagraphAlignment alignment, boolean bold, int fontSize) { ParagraphAlignment alignment, boolean bold, int fontSize) {
...@@ -887,10 +882,6 @@ public class TeachingPlanServiceImpl implements TeachingPlanService { ...@@ -887,10 +882,6 @@ public class TeachingPlanServiceImpl implements TeachingPlanService {
/** 保留单元格、边框和合并关系,仅替换其正文;空值显示“无”,避免表单含义不清。 */ /** 保留单元格、边框和合并关系,仅替换其正文;空值显示“无”,避免表单含义不清。 */
private void writeWordCell(XWPFTableCell cell, String content) { private void writeWordCell(XWPFTableCell cell, String content) {
writeWordCell(cell, content, 11);
}
private void writeWordCell(XWPFTableCell cell, String content, int fontSize) {
while (cell.getParagraphs().size() > 1) { while (cell.getParagraphs().size() > 1) {
cell.removeParagraph(cell.getParagraphs().size() - 1); cell.removeParagraph(cell.getParagraphs().size() - 1);
} }
...@@ -898,7 +889,7 @@ public class TeachingPlanServiceImpl implements TeachingPlanService { ...@@ -898,7 +889,7 @@ public class TeachingPlanServiceImpl implements TeachingPlanService {
paragraph.setSpacingBefore(0); paragraph.setSpacingBefore(0);
paragraph.setSpacingAfter(0); paragraph.setSpacingAfter(0);
writeWordParagraph(paragraph, StringUtils.hasText(content) ? content : "无", writeWordParagraph(paragraph, StringUtils.hasText(content) ? content : "无",
ParagraphAlignment.LEFT, false, fontSize); ParagraphAlignment.LEFT, false, TEACHING_PLAN_WORD_CELL_FONT_SIZE);
} }
/** 行高只作为下限,内容较多时仍可自动增高,避免固定高度裁切正文。 */ /** 行高只作为下限,内容较多时仍可自动增高,避免固定高度裁切正文。 */
...@@ -924,9 +915,9 @@ public class TeachingPlanServiceImpl implements TeachingPlanService { ...@@ -924,9 +915,9 @@ public class TeachingPlanServiceImpl implements TeachingPlanService {
appendWordListItem(contents, i, step.getContent(), null); appendWordListItem(contents, i, step.getContent(), null);
appendWordListItem(methods, i, step.getMethod(), null); appendWordListItem(methods, i, step.getMethod(), null);
} }
writeWordCell(row.getCell(0), stages.toString(), 9); writeWordCell(row.getCell(0), stages.toString());
writeWordCell(row.getCell(1), contents.toString(), 10); writeWordCell(row.getCell(1), contents.toString());
writeWordCell(row.getCell(2), methods.toString(), 10); writeWordCell(row.getCell(2), methods.toString());
} }
private void appendWordListItem(StringBuilder builder, int index, String content, private void appendWordListItem(StringBuilder builder, int index, String content,
...@@ -954,14 +945,12 @@ public class TeachingPlanServiceImpl implements TeachingPlanService { ...@@ -954,14 +945,12 @@ public class TeachingPlanServiceImpl implements TeachingPlanService {
? value(content) : "—"; ? value(content) : "—";
} }
/** 审批槽统一容纳管理端状态、审核记录、教师签名和附件,确保原导出字段不丢失。 */ /** 审批槽只展示审批流程信息,附件等教案资料不混入审批内容。 */
private String approvalText(TeachingPlanVO plan) { private String approvalText(TeachingPlanVO plan) {
return "状态:" + statusName(plan.getStatus()) return "状态:" + statusName(plan.getStatus())
+ " 审核人:" + value(plan.getReviewerName()) + " 审核人:" + value(plan.getReviewerName())
+ "\n审核意见:" + value(plan.getReviewOpinion()) + "\n审核意见:" + value(plan.getReviewOpinion())
+ "\n审核时间:" + formatDate(plan.getReviewTime(), "yyyy-MM-dd HH:mm") + "\n审核时间:" + formatDate(plan.getReviewTime(), "yyyy-MM-dd HH:mm");
+ " 教师签名:" + value(plan.getSignature())
+ " 附件:" + attachmentNames(plan.getAttachments());
} }
private String courseTypeName(String courseType) { private String courseTypeName(String courseType) {
...@@ -994,21 +983,6 @@ public class TeachingPlanServiceImpl implements TeachingPlanService { ...@@ -994,21 +983,6 @@ public class TeachingPlanServiceImpl implements TeachingPlanService {
} }
} }
/** 将附件名称汇总为可读列表;导出不暴露服务器文件路径和文件ID。 */
private String attachmentNames(List<TeachingPlanAttachmentVO> attachments) {
if (attachments == null || attachments.isEmpty()) {
return "无";
}
StringBuilder builder = new StringBuilder();
for (int i = 0; i < attachments.size(); i++) {
if (i > 0) {
builder.append('\n');
}
builder.append(i + 1).append(". ").append(value(attachments.get(i).getFileName()));
}
return builder.toString();
}
private String formatDate(Date date, String pattern) { private String formatDate(Date date, String pattern) {
return date == null ? "" : new SimpleDateFormat(pattern).format(date); return date == null ? "" : new SimpleDateFormat(pattern).format(date);
} }
......
...@@ -12,6 +12,7 @@ import com.platform.business.model.vo.TheoreticalPracticeStudentSimulationVO; ...@@ -12,6 +12,7 @@ import com.platform.business.model.vo.TheoreticalPracticeStudentSimulationVO;
import com.platform.business.service.TheoreticalLibraryService; import com.platform.business.service.TheoreticalLibraryService;
import com.platform.business.service.TheoreticalPracticeStudentSimulationDetailService; import com.platform.business.service.TheoreticalPracticeStudentSimulationDetailService;
import com.platform.business.service.TheoreticalPracticeStudentSimulationService; import com.platform.business.service.TheoreticalPracticeStudentSimulationService;
import com.platform.business.service.StudentHomeService;
import com.platform.business.service.UserService; import com.platform.business.service.UserService;
import com.platform.exception.BusinessException; import com.platform.exception.BusinessException;
import com.platform.utils.StringUtils; import com.platform.utils.StringUtils;
...@@ -31,6 +32,8 @@ public class TheoreticalPracticeStudentSimulationServiceImpl extends ServiceImpl ...@@ -31,6 +32,8 @@ public class TheoreticalPracticeStudentSimulationServiceImpl extends ServiceImpl
private TheoreticalPracticeStudentSimulationDetailService theoreticalPracticeStudentSimulationDetailService; private TheoreticalPracticeStudentSimulationDetailService theoreticalPracticeStudentSimulationDetailService;
@Resource @Resource
private UserService userService; private UserService userService;
@Resource
private StudentHomeService studentHomeService;
@Override @Override
public List<TheoreticalPracticeStudentSimulationVO> pageData(TheoreticalPracticeStudentSimulationDTO theoreticalPracticeStudentSimulationDTO) { public List<TheoreticalPracticeStudentSimulationVO> pageData(TheoreticalPracticeStudentSimulationDTO theoreticalPracticeStudentSimulationDTO) {
...@@ -226,8 +229,13 @@ public class TheoreticalPracticeStudentSimulationServiceImpl extends ServiceImpl ...@@ -226,8 +229,13 @@ public class TheoreticalPracticeStudentSimulationServiceImpl extends ServiceImpl
Map<String, String> result = new HashMap<>(); Map<String, String> result = new HashMap<>();
UserEntity user = userService.getOne(new LambdaQueryWrapper<UserEntity>().eq(UserEntity::getPhoneNumber, userName)); UserEntity user = userService.getOne(new LambdaQueryWrapper<UserEntity>().eq(UserEntity::getPhoneNumber, userName));
long count = count(new LambdaQueryWrapper<TheoreticalPracticeStudentSimulationEntity>().eq(TheoreticalPracticeStudentSimulationEntity::getStudentId, user.getId())); long count = count(new LambdaQueryWrapper<TheoreticalPracticeStudentSimulationEntity>().eq(TheoreticalPracticeStudentSimulationEntity::getStudentId, user.getId()));
result.put("name", user.getLevel() + "模拟试卷" + (count + 1)); /*
result.put("lev", user.getLevel()); * user.level可能保存花名册中的前一证书等级,不能代表学员当前在培职级。
* 复用学员首页的当前班级选择规则,确保模拟组卷、首页和换班后的职级展示口径一致。
*/
String currentLevel = studentHomeService.profile(user).getLevel();
result.put("name", currentLevel + "模拟试卷" + (count + 1));
result.put("lev", currentLevel);
return result; return result;
} }
} }
package com.platform.business.task;
import com.platform.business.mapper.UserMapper;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Date;
/** 定时把已经进入计划考试时段的应考学员标记为“考试进行中”。 */
@Component
public class ExamFlagSyncTask {
@Resource
private UserMapper userMapper;
/**
* 默认每5秒执行一次批量更新,使考试开始后最多延迟一个轮询周期生效。
*
* <p>更新SQL只修改状态尚未同步的用户,因此重复执行和多实例同时调度均不会改变
* 已经正确的记录。两个时间参数均可通过配置覆盖,便于不同环境调整数据库压力。</p>
*/
@Scheduled(initialDelayString = "${exam.flag-sync.initial-delay-millis:1000}",
fixedDelayString = "${exam.flag-sync.poll-interval-millis:5000}")
public void activateDueExams() {
userMapper.activateDueExams(new Date());
}
}
...@@ -76,12 +76,12 @@ ...@@ -76,12 +76,12 @@
e.chief_id = #{userId} or e.invigilation_id like concat('%',#{userId},'%') e.chief_id = #{userId} or e.invigilation_id like concat('%',#{userId},'%')
); );
</select> </select>
<select id="recent" resultType="com.platform.business.model.vo.ExamStudentVO"> <select id="recent" resultType="com.platform.business.model.vo.RecentExamStudentVO">
select u.level as lev, select u.level as lev,
e.type, e.type,
e.name as examName, e.name as examName,
es.start_time as startTime, e.exam_time as startTime,
es.duration, e.duration,
e.forbid, e.forbid,
e.chief_id as chiefId, e.chief_id as chiefId,
e.invigilation_id as invigilationId, e.invigilation_id as invigilationId,
...@@ -92,7 +92,6 @@ ...@@ -92,7 +92,6 @@
left join user u on es.student_id = u.id left join user u on es.student_id = u.id
left join class c on e.class_id = c.id left join class c on e.class_id = c.id
where u.id = #{studentId} where u.id = #{studentId}
and e.type = '实训考试'
order by es.start_time desc order by es.start_time desc
limit 1 limit 1
</select> </select>
......
...@@ -82,4 +82,31 @@ ...@@ -82,4 +82,31 @@
simulation_id = null simulation_id = null
where id = #{studentId} where id = #{studentId}
</update> </update>
<update id="activateDueExams">
<!--
到达计划开始时间后批量激活学员考试状态。结束时间采用[开始时间, 开始时间+时长)
半开区间,与新增考试的冲突判断完全一致,因此首尾相接的两场考试不会同时生效。
理论与实训考试共用该状态;submit历史空值按未交卷处理。
-->
update `user` target_user
inner join (
select candidate.student_id,
min(candidate.id) as exam_student_id
from exam_student candidate
inner join exam exam_plan on exam_plan.id = candidate.exam_id
where exam_plan.exam_time &lt;= #{now}
and timestampadd(
minute,
greatest(coalesce(exam_plan.duration, 0), 0),
exam_plan.exam_time
) &gt; #{now}
and coalesce(candidate.submit, 0) = 0
group by candidate.student_id
) active_exam on active_exam.student_id = target_user.id
set target_user.exam_flag = true,
target_user.exam_oneself_id = active_exam.exam_student_id
where coalesce(target_user.exam_flag, 0) = 0
or target_user.exam_oneself_id is null
or target_user.exam_oneself_id &lt;&gt; active_exam.exam_student_id
</update>
</mapper> </mapper>
...@@ -38,9 +38,10 @@ practical-business/src/main/resources/sql/practice_paper_rule.sql ...@@ -38,9 +38,10 @@ practical-business/src/main/resources/sql/practice_paper_rule.sql
必须回传查询接口返回的该等级全部类目。服务端只按ID更新考核时间、配分和题量,不能 必须回传查询接口返回的该等级全部类目。服务端只按ID更新考核时间、配分和题量,不能
修改 Excel 标准项目与单元内容。所有类目的`questionCount`合计必须为1至5。 修改 Excel 标准项目与单元内容。所有类目的`questionCount`合计必须为1至5。
## 3. 学员最近实训考试 ## 3. 学员最近考试
`GET /exam/student/recent/{studentId}` 原有字段不变,新增 `practiceRule`: `GET /exam/student/recent/{studentId}` 按最近一场考试返回数据库中的实际 `type`,并在
原有字段基础上新增 `practiceRule`:
```json ```json
{ {
......
...@@ -109,7 +109,7 @@ practical-business/src/main/resources/sql/theoretical_paper_management.sql ...@@ -109,7 +109,7 @@ practical-business/src/main/resources/sql/theoretical_paper_management.sql
## 6. 旧页面兼容路径 ## 6. 旧页面兼容路径
- `GET /theoretical/paper/auto` 返回相同的公共规则配置,并保留给已登录学员的模拟考场兼容调用;教师端优先使用 `/auto-configuration`。 - `GET /theoretical/paper/auto` 复用当前正式组卷配置校验与汇总,并保留给已登录学员的模拟考场兼容调用;教师端优先使用 `/auto-configuration`。
- `POST /theoretical/paper/create` 接收旧 `CombinationDTO`,但忽略客户端 `num`、`sum`、 - `POST /theoretical/paper/create` 接收旧 `CombinationDTO`,但忽略客户端 `num`、`sum`、
`createUser`、抽题分布和配分规则,服务端重新读取数据库规则;为保持历史行为固定创建 `createUser`、抽题分布和配分规则,服务端重新读取数据库规则;为保持历史行为固定创建
`PUBLISHED` 试卷,并继续返回布尔型 `data`。 `PUBLISHED` 试卷,并继续返回布尔型 `data`。
......
...@@ -8,6 +8,7 @@ import com.platform.business.model.dto.TheoreticalPaperManualSaveDTO; ...@@ -8,6 +8,7 @@ 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.TheoreticalPaperAdminService;
import com.platform.business.service.TheoreticalPaperService; import com.platform.business.service.TheoreticalPaperService;
import com.platform.business.service.TheoreticalPaperTeacherService; import com.platform.business.service.TheoreticalPaperTeacherService;
import com.platform.exception.BusinessException; import com.platform.exception.BusinessException;
...@@ -42,6 +43,8 @@ class TheoreticalPaperControllerTest { ...@@ -42,6 +43,8 @@ class TheoreticalPaperControllerTest {
private TheoreticalPaperService legacyPaperService; private TheoreticalPaperService legacyPaperService;
@Mock @Mock
private AuthenticatedUserService authenticatedUserService; private AuthenticatedUserService authenticatedUserService;
@Mock
private TheoreticalPaperAdminService paperManagementService;
private TheoreticalPaperController controller; private TheoreticalPaperController controller;
...@@ -51,6 +54,7 @@ class TheoreticalPaperControllerTest { ...@@ -51,6 +54,7 @@ class TheoreticalPaperControllerTest {
ReflectionTestUtils.setField(controller, "paperTeacherService", paperTeacherService); ReflectionTestUtils.setField(controller, "paperTeacherService", paperTeacherService);
ReflectionTestUtils.setField(controller, "legacyPaperService", legacyPaperService); ReflectionTestUtils.setField(controller, "legacyPaperService", legacyPaperService);
ReflectionTestUtils.setField(controller, "authenticatedUserService", authenticatedUserService); ReflectionTestUtils.setField(controller, "authenticatedUserService", authenticatedUserService);
ReflectionTestUtils.setField(controller, "paperManagementService", paperManagementService);
} }
@Test @Test
...@@ -93,7 +97,7 @@ class TheoreticalPaperControllerTest { ...@@ -93,7 +97,7 @@ class TheoreticalPaperControllerTest {
} }
@Test @Test
void legacyAutoConfigurationShouldAllowAuthenticatedStudentReadOnlyAccess() { void legacyAutoConfigurationShouldUseValidatedCurrentRulesForStudent() {
MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletRequest request = new MockHttpServletRequest();
UserEntity student = new UserEntity(); UserEntity student = new UserEntity();
student.setId("student-1"); student.setId("student-1");
...@@ -101,8 +105,10 @@ class TheoreticalPaperControllerTest { ...@@ -101,8 +105,10 @@ class TheoreticalPaperControllerTest {
controller.legacyAutoConfiguration("污水一级", request); controller.legacyAutoConfiguration("污水一级", request);
// 模拟考场只读取公共规则,不应触发教师角色校验或教师试卷写服务。 // 模拟考场必须读取带完整校验和汇总的新规则,不能再使用会静默返回空配置的旧服务。
verify(legacyPaperService).auto("污水一级"); verify(paperManagementService).autoConfiguration("污水一级");
verify(paperTeacherService, org.mockito.Mockito.never()).autoConfiguration(any(), any());
verify(legacyPaperService, org.mockito.Mockito.never()).auto(any());
verify(authenticatedUserService, org.mockito.Mockito.never()).requireTeacher(student); verify(authenticatedUserService, org.mockito.Mockito.never()).requireTeacher(student);
} }
......
...@@ -7,7 +7,10 @@ import org.junit.jupiter.api.Test; ...@@ -7,7 +7,10 @@ import org.junit.jupiter.api.Test;
import java.io.InputStream; import java.io.InputStream;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
...@@ -35,6 +38,30 @@ class ExamMapperXmlTest { ...@@ -35,6 +38,30 @@ class ExamMapperXmlTest {
assertTrue(configuration.hasStatement( assertTrue(configuration.hasStatement(
"com.platform.business.mapper.ExamMapper.summary")); "com.platform.business.mapper.ExamMapper.summary"));
Map<String, Object> conflictParameters = new HashMap<>();
conflictParameters.put("startTime", Timestamp.valueOf("2026-09-18 09:00:00"));
conflictParameters.put("duration", 90);
conflictParameters.put("classId", 1);
conflictParameters.put("chiefId", "teacher-1");
conflictParameters.put("invigilatorId", "teacher-2");
conflictParameters.put("studentIds", Arrays.asList("student-1", "student-2"));
conflictParameters.put("excludeId", null);
String conflictSql = configuration.getMappedStatement(
"com.platform.business.mapper.ExamMapper.selectAdminExamConflicts")
.getBoundSql(conflictParameters)
.getSql()
.replaceAll("\\s+", " ")
.toLowerCase();
/*
* 新考试与旧考试采用半开区间重叠判断,并通过应考关系检查任一重复学员。
* 即使学员属于不同班级、教师也不同,只要考试时间重叠就必须拒绝新增。
*/
assertTrue(conflictSql.contains("e.exam_time < timestampadd(minute, ?, ?)"));
assertTrue(conflictSql.contains(
"timestampadd(minute, coalesce(e.duration, 0), e.exam_time) > ?"));
assertTrue(conflictSql.contains("from exam_student conflict_student"));
assertTrue(conflictSql.contains("conflict_student.student_id in"));
/* /*
* 通用考试分页必须查出时长供服务层计算三态;顶部汇总则必须独立统计全表, * 通用考试分页必须查出时长供服务层计算三态;顶部汇总则必须独立统计全表,
* 不能意外继承分页中的名称、类型、等级或班级筛选条件。 * 不能意外继承分页中的名称、类型、等级或班级筛选条件。
......
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