Commit 66392f2e authored by wujipeng's avatar wujipeng
Browse files

bug修复

parent 4e10634c
package com.platform.business.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.platform.business.model.entity.ExamTeacherAssignmentEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/** 考试教师多角色关系数据访问层。 */
@Mapper
public interface ExamTeacherAssignmentMapper extends BaseMapper<ExamTeacherAssignmentEntity> {
int insertBatch(@Param("assignments") List<ExamTeacherAssignmentEntity> assignments);
int deleteByExamId(@Param("examId") Integer examId);
List<ExamTeacherAssignmentEntity> selectByExamIds(@Param("examIds") List<Integer> examIds);
}
...@@ -2,6 +2,12 @@ package com.platform.business.mapper; ...@@ -2,6 +2,12 @@ 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.PracticePaperRuleEntity; import com.platform.business.model.entity.PracticePaperRuleEntity;
import com.platform.business.model.entity.PracticePaperRuleDefinitionEntity;
import com.platform.business.model.entity.PracticePaperRuleDetailEntity;
import com.platform.business.model.dto.PracticePaperRuleQueryDTO;
import com.platform.business.model.vo.ClassAdminOptionVO;
import com.platform.business.model.vo.PracticePaperRuleConfigurationVO;
import com.platform.business.model.vo.PracticePaperRuleItemVO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
...@@ -11,11 +17,37 @@ import java.util.List; ...@@ -11,11 +17,37 @@ import java.util.List;
@Mapper @Mapper
public interface PracticePaperRuleMapper extends BaseMapper<PracticePaperRuleEntity> { public interface PracticePaperRuleMapper extends BaseMapper<PracticePaperRuleEntity> {
/** List<PracticePaperRuleConfigurationVO> pageDefinitions(
* 按稳定ID顺序锁定一个等级的全部规则。 @Param("query") PracticePaperRuleQueryDTO query);
*
* <p>整套配置保存前加行锁,保证两个管理员同时保存时不会分别通过“五题上限” PracticePaperRuleDefinitionEntity selectDefinition(@Param("ruleId") Integer ruleId);
* 校验后交叉覆盖,最终产生一套从未被任何请求完整校验过的组合。</p>
*/ PracticePaperRuleDefinitionEntity lockDefinition(@Param("ruleId") Integer ruleId);
List<PracticePaperRuleEntity> selectByGradeForUpdate(@Param("grade") String grade);
List<PracticePaperRuleItemVO> selectDefinitionDetails(@Param("ruleId") Integer ruleId);
int countDuplicateDefinition(@Param("grade") String grade,
@Param("name") String name,
@Param("excludeId") Integer excludeId);
int insertDefinition(PracticePaperRuleDefinitionEntity definition);
int updateDefinition(PracticePaperRuleDefinitionEntity definition);
int updateDefinitionStatus(@Param("ruleId") Integer ruleId,
@Param("status") String status,
@Param("updatedBy") String updatedBy,
@Param("updatedTime") java.util.Date updatedTime);
int insertDefinitionDetails(@Param("items") List<PracticePaperRuleDetailEntity> items);
int deleteDefinitionDetails(@Param("ruleId") Integer ruleId);
int deleteDefinition(@Param("ruleId") Integer ruleId);
int countDefinitionUsage(@Param("ruleId") Integer ruleId);
List<ClassAdminOptionVO> selectPublishedOptions(@Param("grade") String grade);
PracticePaperRuleDefinitionEntity selectPublishedDefinition(@Param("ruleId") Integer ruleId);
} }
...@@ -13,8 +13,9 @@ import java.util.List; ...@@ -13,8 +13,9 @@ import java.util.List;
/** /**
* 教师端成绩管理专用查询。 * 教师端成绩管理专用查询。
* *
* <p>所有涉及考试内容的方法都显式接收 teacherId,并在 SQL 中使用 exam.chief_id * <p>所有涉及考试内容的方法都显式接收 teacherId,并在 SQL 中优先通过教师关系表校验
* 校验归属。该限制不能只放在 Controller 中,否则猜测 examId 仍可能造成越权读取。</p> * 首席考评员身份;尚未迁移的历史考试才回退到 exam.chief_id。该限制不能只放在
* Controller 中,否则猜测 examId 仍可能造成越权读取。</p>
*/ */
@Mapper @Mapper
public interface TeacherScoreMapper { public interface TeacherScoreMapper {
......
package com.platform.business.service; package com.platform.business.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.platform.business.model.dto.PracticePaperRuleSaveDTO; import com.platform.business.model.dto.PracticePaperRuleSaveDTO;
import com.platform.business.model.entity.PracticePaperRuleEntity; import com.platform.business.model.dto.PracticePaperRuleQueryDTO;
import com.platform.business.model.entity.PracticePaperRuleDefinitionEntity;
import com.platform.business.model.vo.ClassAdminOptionVO;
import com.platform.business.model.vo.PracticePaperRuleConfigurationVO; import com.platform.business.model.vo.PracticePaperRuleConfigurationVO;
import com.platform.business.model.vo.PracticePaperRuleItemVO;
/** 实操自动组卷规则的查询和整套保存服务。 */ import java.util.List;
public interface PracticePaperRuleService extends IService<PracticePaperRuleEntity> {
/** 管理页面读取全部标准类目,包括题量为0的未选类目。 */ /** 具名实操试卷规则的目录、查询、保存、发布和删除服务。 */
PracticePaperRuleConfigurationVO configuration(String level); public interface PracticePaperRuleService {
/** recent接口仅读取题量大于0的当前生效配分规则。 */ List<PracticePaperRuleConfigurationVO> queryPage(PracticePaperRuleQueryDTO query);
PracticePaperRuleConfigurationVO effectiveConfiguration(String level);
/** 管理员整套保存一个等级的配置。 */ List<PracticePaperRuleItemVO> catalog(String level);
PracticePaperRuleConfigurationVO saveConfiguration(PracticePaperRuleSaveDTO request,
String updaterId); PracticePaperRuleConfigurationVO detail(Integer ruleId);
PracticePaperRuleConfigurationVO create(PracticePaperRuleSaveDTO request, String operatorId);
PracticePaperRuleConfigurationVO update(Integer ruleId, PracticePaperRuleSaveDTO request,
String operatorId);
PracticePaperRuleConfigurationVO publish(Integer ruleId, String status, String operatorId);
boolean delete(Integer ruleId);
/** 按考试保存的规则ID读取不可变的已发布规则,仅返回题量大于0的明细。 */
PracticePaperRuleConfigurationVO effectiveConfiguration(Integer ruleId);
List<ClassAdminOptionVO> publishedOptions(String level);
PracticePaperRuleDefinitionEntity requirePublishedDefinition(Integer ruleId, String level);
} }
...@@ -48,12 +48,14 @@ public class ExamStaudentServiceImpl extends ServiceImpl<ExamStudentMapper, Exam ...@@ -48,12 +48,14 @@ public class ExamStaudentServiceImpl extends ServiceImpl<ExamStudentMapper, Exam
return null; return null;
} }
/* /*
* 为保持现有扩展字段兼容,不固化实操规则快照:每次请求都根据学生职级读取 * 实训规则必须来自考试创建时选择的不可变已发布规则,不能再按学生当前职级读取
* 当前最新配置,无论最近一场考试的实际类型为何,字段结构均保持不变。 * “最新配置”,否则学生调级或管理员新增规则都会改变既有考试内容。理论考试不
* 规则服务会把“污水一级”“污泥一级”统一匹配为Excel中的“一级”。 * 返回该扩展字段;历史实训考试由迁移脚本回填默认规则ID。
*/ */
examStudentVO.setPracticeRule( if ("实训".equals(examStudentVO.getType()) && examStudentVO.getPracticeRuleId() != null) {
practicePaperRuleService.effectiveConfiguration(examStudentVO.getLev())); examStudentVO.setPracticeRule(practicePaperRuleService
.effectiveConfiguration(examStudentVO.getPracticeRuleId()));
}
//获取同一场考试的学生 //获取同一场考试的学生
List<ExamStudentVO> data = baseMapper.theSameEvent(examStudentVO.getExamId()); List<ExamStudentVO> data = baseMapper.theSameEvent(examStudentVO.getExamId());
examStudentVO.setData(data); examStudentVO.setData(data);
......
...@@ -37,7 +37,8 @@ import java.util.Set; ...@@ -37,7 +37,8 @@ import java.util.Set;
* 教师端成绩查询与导出实现。 * 教师端成绩查询与导出实现。
* *
* <p>权限采用“双层保护”:Controller 负责校验当前用户确实具有教师角色,本服务传递 * <p>权限采用“双层保护”:Controller 负责校验当前用户确实具有教师角色,本服务传递
* JWT 中的教师 ID,Mapper 的每一条考试查询再通过 exam.chief_id 校验业务归属。</p> * JWT 中的教师 ID,Mapper 的每一条考试查询再通过首席考评员关系校验业务归属;没有
* 关系记录的历史考试才回退到 exam.chief_id。</p>
*/ */
@Service @Service
public class TeacherScoreServiceImpl implements TeacherScoreService { public class TeacherScoreServiceImpl implements TeacherScoreService {
......
...@@ -201,6 +201,8 @@ ...@@ -201,6 +201,8 @@
coalesce(nullif(invigilator.nick_name, ''), invigilator.username) as invigilatorName, coalesce(nullif(invigilator.nick_name, ''), invigilator.username) as invigilatorName,
e.paper_id as paperId, e.paper_id as paperId,
paper.name as paperName, paper.name as paperName,
e.practice_rule_id as practiceRuleId,
practice_rule.name as practiceRuleName,
e.location, e.location,
(select count(*) (select count(*)
from exam_student attempt from exam_student attempt
...@@ -218,6 +220,7 @@ ...@@ -218,6 +220,7 @@
left join user chief_user on chief_user.id = e.chief_id left join user chief_user on chief_user.id = e.chief_id
left join user invigilator on invigilator.id = e.invigilation_id left join user invigilator on invigilator.id = e.invigilation_id
left join theoretical_paper paper on paper.id = e.paper_id left join theoretical_paper paper on paper.id = e.paper_id
left join practice_paper_rule_definition practice_rule on practice_rule.id = e.practice_rule_id
where e.class_id = #{classId} where e.class_id = #{classId}
<!-- <!--
考试管理需要保留已结束场次供管理员追溯,不能再按“开始时间+时长”过滤历史数据。 考试管理需要保留已结束场次供管理员追溯,不能再按“开始时间+时长”过滤历史数据。
...@@ -233,6 +236,7 @@ ...@@ -233,6 +236,7 @@
left join user chief_user on chief_user.id = e.chief_id left join user chief_user on chief_user.id = e.chief_id
left join user invigilator on invigilator.id = e.invigilation_id left join user invigilator on invigilator.id = e.invigilation_id
left join theoretical_paper paper on paper.id = e.paper_id left join theoretical_paper paper on paper.id = e.paper_id
left join practice_paper_rule_definition practice_rule on practice_rule.id = e.practice_rule_id
where e.id = #{examId} where e.id = #{examId}
</select> </select>
...@@ -318,6 +322,19 @@ ...@@ -318,6 +322,19 @@
and coalesce(teacher.del_flag, 0) = 0 and coalesce(teacher.del_flag, 0) = 0
</select> </select>
<select id="selectAdminExamActiveTeacherIds" resultType="java.lang.String">
select distinct teacher.id
from user teacher
inner join phone_role role_info
on role_info.phone = teacher.phone_number and role_info.role_name = '教师'
where coalesce(teacher.del_flag, 0) = 0
and teacher.id in
<foreach collection="teacherIds" item="teacherId" open="(" separator="," close=")">
#{teacherId}
</foreach>
order by teacher.id
</select>
<select id="countAdminExamDuplicateName" resultType="java.lang.Integer"> <select id="countAdminExamDuplicateName" resultType="java.lang.Integer">
select count(*) select count(*)
from exam from exam
...@@ -336,6 +353,7 @@ ...@@ -336,6 +353,7 @@
left join user chief_user on chief_user.id = e.chief_id left join user chief_user on chief_user.id = e.chief_id
left join user invigilator on invigilator.id = e.invigilation_id left join user invigilator on invigilator.id = e.invigilation_id
left join theoretical_paper paper on paper.id = e.paper_id left join theoretical_paper paper on paper.id = e.paper_id
left join practice_paper_rule_definition practice_rule on practice_rule.id = e.practice_rule_id
where e.exam_time &lt; timestampadd(minute, #{duration}, #{startTime}) where e.exam_time &lt; timestampadd(minute, #{duration}, #{startTime})
and timestampadd(minute, coalesce(e.duration, 0), e.exam_time) &gt; #{startTime} and timestampadd(minute, coalesce(e.duration, 0), e.exam_time) &gt; #{startTime}
<if test="excludeId != null"> <if test="excludeId != null">
...@@ -343,9 +361,38 @@ ...@@ -343,9 +361,38 @@
</if> </if>
and ( and (
e.class_id = #{classId} e.class_id = #{classId}
or e.chief_id in (#{chiefId}, #{invigilatorId}) or (
or find_in_set(#{chiefId}, replace(coalesce(e.invigilation_id, ''), ' ', '')) &gt; 0 not exists (
or find_in_set(#{invigilatorId}, replace(coalesce(e.invigilation_id, ''), ' ', '')) &gt; 0 select 1 from exam_teacher_assignment any_chief
where any_chief.exam_id = e.id and any_chief.role = 'CHIEF'
)
and e.chief_id in
<foreach collection="teacherIds" item="teacherId" open="(" separator="," close=")">
#{teacherId}
</foreach>
)
or exists (
select 1
from exam_teacher_assignment teacher_assignment
where teacher_assignment.exam_id = e.id
and teacher_assignment.teacher_id in
<foreach collection="teacherIds" item="teacherId" open="(" separator="," close=")">
#{teacherId}
</foreach>
)
or (
not exists (
select 1 from exam_teacher_assignment any_invigilator
where any_invigilator.exam_id = e.id
and any_invigilator.role = 'INVIGILATOR'
)
and (
<foreach collection="teacherIds" item="teacherId" separator=" or ">
find_in_set(#{teacherId},
replace(coalesce(e.invigilation_id, ''), ' ', '')) &gt; 0
</foreach>
)
)
or exists ( or exists (
select 1 select 1
from exam_student conflict_student from exam_student conflict_student
...@@ -363,7 +410,7 @@ ...@@ -363,7 +410,7 @@
resultType="com.platform.business.model.entity.ExamEntity"> resultType="com.platform.business.model.entity.ExamEntity">
select select
id, class_id, name, exam_time, type, duration, forbid, chief_id, id, class_id, name, exam_time, type, duration, forbid, chief_id,
invigilation_id, paper_id, location, total_score, pass_score, invigilation_id, paper_id, practice_rule_id, location, total_score, pass_score,
create_time, update_time, mark_flag create_time, update_time, mark_flag
from exam from exam
where id = #{examId} where id = #{examId}
...@@ -395,6 +442,9 @@ ...@@ -395,6 +442,9 @@
exam_time = #{examTime}, exam_time = #{examTime},
duration = #{duration}, duration = #{duration},
chief_id = #{chiefId}, chief_id = #{chiefId},
invigilation_id = #{invigilationId},
practice_rule_id = #{practiceRuleId,jdbcType=INTEGER},
total_score = #{totalScore},
location = #{location,jdbcType=VARCHAR}, location = #{location,jdbcType=VARCHAR},
pass_score = #{passScore}, pass_score = #{passScore},
update_time = #{updateTime} update_time = #{updateTime}
......
...@@ -3,6 +3,22 @@ ...@@ -3,6 +3,22 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.platform.business.mapper.ExamReviewMapper"> <mapper namespace="com.platform.business.mapper.ExamReviewMapper">
<!-- 新关系表是事实来源,旧chief_id精确匹配仅用于尚未迁移的历史考试。 -->
<sql id="chiefPermission">
(exists (
select 1 from exam_teacher_assignment chief_assignment
where chief_assignment.exam_id = e.id
and chief_assignment.teacher_id = #{teacherId}
and chief_assignment.role = 'CHIEF'
) or (
not exists (
select 1 from exam_teacher_assignment any_chief
where any_chief.exam_id = e.id and any_chief.role = 'CHIEF'
)
and e.chief_id = #{teacherId}
))
</sql>
<!-- <!--
教师只能看到本人作为首席考评员的考试。任务状态按已交卷考生的 mark_flag 聚合: 教师只能看到本人作为首席考评员的考试。任务状态按已交卷考生的 mark_flag 聚合:
任意一份已交试卷尚未发布即为 PENDING,全部发布后才是 COMPLETED。 任意一份已交试卷尚未发布即为 PENDING,全部发布后才是 COMPLETED。
...@@ -32,7 +48,7 @@ ...@@ -32,7 +48,7 @@
INNER JOIN exam_student es ON es.exam_id = e.id INNER JOIN exam_student es ON es.exam_id = e.id
LEFT JOIN class c ON c.id = e.class_id LEFT JOIN class c ON c.id = e.class_id
LEFT JOIN theoretical_paper tp ON tp.id = e.paper_id LEFT JOIN theoretical_paper tp ON tp.id = e.paper_id
WHERE e.chief_id = #{teacherId} WHERE <include refid="chiefPermission"/>
<if test="query.keyword != null and query.keyword != ''"> <if test="query.keyword != null and query.keyword != ''">
AND e.name LIKE CONCAT('%', #{query.keyword}, '%') AND e.name LIKE CONCAT('%', #{query.keyword}, '%')
</if> </if>
...@@ -75,7 +91,7 @@ ...@@ -75,7 +91,7 @@
LEFT JOIN class c ON c.id = e.class_id LEFT JOIN class c ON c.id = e.class_id
LEFT JOIN theoretical_paper tp ON tp.id = e.paper_id LEFT JOIN theoretical_paper tp ON tp.id = e.paper_id
WHERE e.id = #{examId} WHERE e.id = #{examId}
AND e.chief_id = #{teacherId} AND <include refid="chiefPermission"/>
GROUP BY e.id, e.class_id, e.name, c.name, e.type, e.paper_id, tp.name, GROUP BY e.id, e.class_id, e.name, c.name, e.type, e.paper_id, tp.name,
e.total_score, e.exam_time, e.duration e.total_score, e.exam_time, e.duration
</select> </select>
...@@ -85,7 +101,7 @@ ...@@ -85,7 +101,7 @@
SELECT e.* SELECT e.*
FROM exam e FROM exam e
WHERE e.id = #{examId} WHERE e.id = #{examId}
AND e.chief_id = #{teacherId} AND <include refid="chiefPermission"/>
FOR UPDATE FOR UPDATE
</select> </select>
...@@ -116,7 +132,7 @@ ...@@ -116,7 +132,7 @@
AND d.actual_score IS NOT NULL) AS scoredSubjectiveCount, AND d.actual_score IS NOT NULL) AS scoredSubjectiveCount,
CASE WHEN IFNULL(es.mark_flag, 0) = 1 THEN TRUE ELSE FALSE END AS published CASE WHEN IFNULL(es.mark_flag, 0) = 1 THEN TRUE ELSE FALSE END AS published
FROM exam_student es FROM exam_student es
INNER JOIN exam e ON e.id = es.exam_id AND e.chief_id = #{teacherId} INNER JOIN exam e ON e.id = es.exam_id AND <include refid="chiefPermission"/>
LEFT JOIN user u ON u.id = es.student_id LEFT JOIN user u ON u.id = es.student_id
LEFT JOIN class c ON c.id = es.class_id LEFT JOIN class c ON c.id = es.class_id
WHERE es.exam_id = #{query.examId} WHERE es.exam_id = #{query.examId}
...@@ -159,7 +175,7 @@ ...@@ -159,7 +175,7 @@
AND d.actual_score IS NOT NULL) AS scoredSubjectiveCount, AND d.actual_score IS NOT NULL) AS scoredSubjectiveCount,
CASE WHEN IFNULL(es.mark_flag, 0) = 1 THEN TRUE ELSE FALSE END AS published CASE WHEN IFNULL(es.mark_flag, 0) = 1 THEN TRUE ELSE FALSE END AS published
FROM exam_student es FROM exam_student es
INNER JOIN exam e ON e.id = es.exam_id AND e.chief_id = #{teacherId} INNER JOIN exam e ON e.id = es.exam_id AND <include refid="chiefPermission"/>
LEFT JOIN user u ON u.id = es.student_id LEFT JOIN user u ON u.id = es.student_id
LEFT JOIN class c ON c.id = es.class_id LEFT JOIN class c ON c.id = es.class_id
WHERE es.id = #{examStudentId} WHERE es.id = #{examStudentId}
...@@ -170,7 +186,7 @@ ...@@ -170,7 +186,7 @@
<select id="lockStudent" resultType="com.platform.business.model.entity.ExamStudentEntity"> <select id="lockStudent" resultType="com.platform.business.model.entity.ExamStudentEntity">
SELECT es.* SELECT es.*
FROM exam_student es FROM exam_student es
INNER JOIN exam e ON e.id = es.exam_id AND e.chief_id = #{teacherId} INNER JOIN exam e ON e.id = es.exam_id AND <include refid="chiefPermission"/>
WHERE es.id = #{examStudentId} WHERE es.id = #{examStudentId}
AND es.submit = 1 AND es.submit = 1
FOR UPDATE FOR UPDATE
......
...@@ -72,9 +72,24 @@ ...@@ -72,9 +72,24 @@
from exam_student es from exam_student es
left join exam e on es.exam_id = e.id left join exam e on es.exam_id = e.id
left join class c on c.id = e.class_id left join class c on c.id = e.class_id
where es.submit = false and ( where es.submit = false
e.chief_id = #{userId} or e.invigilation_id like concat('%',#{userId},'%') and (
); exists (
select 1 from exam_teacher_assignment assignment
where assignment.exam_id = e.id and assignment.teacher_id = #{userId}
)
or (
not exists (select 1 from exam_teacher_assignment a
where a.exam_id = e.id and a.role = 'CHIEF')
and e.chief_id = #{userId}
)
or (
not exists (select 1 from exam_teacher_assignment a
where a.exam_id = e.id and a.role = 'INVIGILATOR')
and find_in_set(#{userId},
replace(coalesce(e.invigilation_id, ''), ' ', '')) &gt; 0
)
);
</select> </select>
<select id="recent" resultType="com.platform.business.model.vo.RecentExamStudentVO"> <select id="recent" resultType="com.platform.business.model.vo.RecentExamStudentVO">
select u.level as lev, select u.level as lev,
...@@ -85,6 +100,7 @@ ...@@ -85,6 +100,7 @@
e.forbid, e.forbid,
e.chief_id as chiefId, e.chief_id as chiefId,
e.invigilation_id as invigilationId, e.invigilation_id as invigilationId,
e.practice_rule_id as practiceRuleId,
es.exam_id as examId, es.exam_id as examId,
c.name as className c.name as className
from exam_student es from exam_student es
......
<?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.ExamTeacherAssignmentMapper">
<insert id="insertBatch">
insert into exam_teacher_assignment (exam_id, teacher_id, role, display_order)
values
<foreach collection="assignments" item="item" separator=",">
(#{item.examId}, #{item.teacherId}, #{item.role}, #{item.displayOrder})
</foreach>
</insert>
<delete id="deleteByExamId">
delete from exam_teacher_assignment where exam_id = #{examId}
</delete>
<select id="selectByExamIds"
resultType="com.platform.business.model.entity.ExamTeacherAssignmentEntity">
select assignment.id,
assignment.exam_id as examId,
assignment.teacher_id as teacherId,
assignment.role,
assignment.display_order as displayOrder,
coalesce(nullif(teacher.nick_name, ''), teacher.username) as teacherName
from exam_teacher_assignment assignment
left join user teacher on teacher.id = assignment.teacher_id
where assignment.exam_id in
<foreach collection="examIds" item="examId" open="(" separator="," close=")">
#{examId}
</foreach>
order by assignment.exam_id, assignment.role, assignment.display_order, assignment.id
</select>
</mapper>
...@@ -3,21 +3,151 @@ ...@@ -3,21 +3,151 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.platform.business.mapper.PracticePaperRuleMapper"> <mapper namespace="com.platform.business.mapper.PracticePaperRuleMapper">
<select id="selectByGradeForUpdate" <!--
resultType="com.platform.business.model.entity.PracticePaperRuleEntity"> 列表只读主表快照总计,避免每页对明细重复聚合。保存规则时主表和明细在同一事务
select id, 更新,因此这些快照与明细始终一致;usageCount则实时统计,确保删除按钮不会过期。
level_grade, -->
project_name, <select id="pageDefinitions"
unit_content, resultType="com.platform.business.model.vo.PracticePaperRuleConfigurationVO">
assessment_duration, select rule.id,
score, rule.name,
question_count, rule.level_grade as grade,
created_time, rule.level_grade as lev,
updated_time, rule.question_count as totalQuestionCount,
updated_by rule.total_duration as totalDuration,
from practice_paper_rule rule.total_score as totalScore,
where level_grade = #{grade} rule.status,
order by id asc rule.created_time as createdTime,
rule.updated_time as updatedTime,
(select count(*) from exam e where e.practice_rule_id = rule.id) as usageCount
from practice_paper_rule_definition rule
<where>
<if test="query != null and query.name != null and query.name != ''">
rule.name like concat('%', #{query.name}, '%')
</if>
<if test="query != null and query.lev != null and query.lev != ''">
and rule.level_grade = #{query.lev}
</if>
<if test="query != null and query.status != null and query.status != ''">
and rule.status = #{query.status}
</if>
</where>
order by rule.updated_time desc, rule.id desc
</select>
<select id="selectDefinition"
resultType="com.platform.business.model.entity.PracticePaperRuleDefinitionEntity">
select id, name, level_grade, question_count, total_duration, total_score, status,
created_by, created_time, updated_by, updated_time
from practice_paper_rule_definition
where id = #{ruleId}
</select>
<select id="lockDefinition"
resultType="com.platform.business.model.entity.PracticePaperRuleDefinitionEntity">
select id, name, level_grade, question_count, total_duration, total_score, status,
created_by, created_time, updated_by, updated_time
from practice_paper_rule_definition
where id = #{ruleId}
for update for update
</select> </select>
<select id="selectDefinitionDetails"
resultType="com.platform.business.model.vo.PracticePaperRuleItemVO">
select detail.id,
detail.catalog_id as catalogId,
catalog.project_name as projectName,
catalog.unit_content as unitContent,
detail.assessment_duration as assessmentDuration,
detail.score,
detail.question_count as questionCount,
detail.assessment_duration * detail.question_count as subtotalDuration,
detail.score * detail.question_count as subtotalScore
from practice_paper_rule_detail detail
inner join practice_paper_rule catalog on catalog.id = detail.catalog_id
where detail.rule_id = #{ruleId}
order by catalog.id asc
</select>
<select id="countDuplicateDefinition" resultType="java.lang.Integer">
select count(*)
from practice_paper_rule_definition
where level_grade = #{grade}
and name = #{name}
<if test="excludeId != null">
and id &lt;&gt; #{excludeId}
</if>
</select>
<insert id="insertDefinition" useGeneratedKeys="true" keyProperty="id">
insert into practice_paper_rule_definition
(name, level_grade, question_count, total_duration, total_score, status,
created_by, created_time, updated_by, updated_time)
values
(#{name}, #{levelGrade}, #{questionCount}, #{totalDuration}, #{totalScore}, #{status},
#{createdBy}, #{createdTime}, #{updatedBy}, #{updatedTime})
</insert>
<update id="updateDefinition">
update practice_paper_rule_definition
set name = #{name},
level_grade = #{levelGrade},
question_count = #{questionCount},
total_duration = #{totalDuration},
total_score = #{totalScore},
updated_by = #{updatedBy},
updated_time = #{updatedTime}
where id = #{id}
and status = 'DRAFT'
</update>
<update id="updateDefinitionStatus">
update practice_paper_rule_definition
set status = #{status}, updated_by = #{updatedBy}, updated_time = #{updatedTime}
where id = #{ruleId}
and status = 'DRAFT'
</update>
<insert id="insertDefinitionDetails">
insert into practice_paper_rule_detail
(rule_id, catalog_id, assessment_duration, score, question_count)
values
<foreach collection="items" item="item" separator=",">
(#{item.ruleId}, #{item.catalogId}, #{item.assessmentDuration},
#{item.score}, #{item.questionCount})
</foreach>
</insert>
<delete id="deleteDefinitionDetails">
delete from practice_paper_rule_detail where rule_id = #{ruleId}
</delete>
<delete id="deleteDefinition">
delete from practice_paper_rule_definition where id = #{ruleId}
</delete>
<select id="countDefinitionUsage" resultType="java.lang.Integer">
select count(*) from exam where practice_rule_id = #{ruleId}
</select>
<select id="selectPublishedOptions"
resultType="com.platform.business.model.vo.ClassAdminOptionVO">
select cast(id as char) as value,
name as label,
level_grade as parentValue,
concat(question_count, '题 · ', total_score, '分') as extra
from practice_paper_rule_definition
where level_grade = #{grade}
and status = 'PUBLISHED'
order by updated_time desc, id desc
</select>
<select id="selectPublishedDefinition"
resultType="com.platform.business.model.entity.PracticePaperRuleDefinitionEntity">
select id, name, level_grade, question_count, total_duration, total_score, status,
created_by, created_time, updated_by, updated_time
from practice_paper_rule_definition
where id = #{ruleId}
and status = 'PUBLISHED'
</select>
</mapper> </mapper>
...@@ -3,6 +3,34 @@ ...@@ -3,6 +3,34 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.platform.business.mapper.TeacherHomeMapper"> <mapper namespace="com.platform.business.mapper.TeacherHomeMapper">
<sql id="chiefPermission">
(exists (
select 1 from exam_teacher_assignment chief_assignment
where chief_assignment.exam_id = e.id
and chief_assignment.teacher_id = #{teacherId}
and chief_assignment.role = 'CHIEF'
) or (
not exists (select 1 from exam_teacher_assignment any_chief
where any_chief.exam_id = e.id and any_chief.role = 'CHIEF')
and e.chief_id = #{teacherId}
))
</sql>
<sql id="participantPermission">
(exists (
select 1 from exam_teacher_assignment assignment
where assignment.exam_id = e.id and assignment.teacher_id = #{teacherId}
) or (
not exists (select 1 from exam_teacher_assignment any_chief
where any_chief.exam_id = e.id and any_chief.role = 'CHIEF')
and e.chief_id = #{teacherId}
) or (
not exists (select 1 from exam_teacher_assignment any_invigilator
where any_invigilator.exam_id = e.id and any_invigilator.role = 'INVIGILATOR')
and find_in_set(#{teacherId}, replace(coalesce(e.invigilation_id, ''), ' ', '')) &gt; 0
))
</sql>
<select id="selectCourseNames" resultType="java.lang.String"> <select id="selectCourseNames" resultType="java.lang.String">
select distinct subject.subject_name select distinct subject.subject_name
from class_subject subject from class_subject subject
...@@ -42,15 +70,14 @@ ...@@ -42,15 +70,14 @@
(select count(distinct e.id) (select count(distinct e.id)
from exam e from exam e
inner join exam_student attempt on attempt.exam_id = e.id inner join exam_student attempt on attempt.exam_id = e.id
where e.chief_id = #{teacherId} where <include refid="chiefPermission"/>
and coalesce(attempt.submit, 0) = 1 and coalesce(attempt.submit, 0) = 1
and coalesce(attempt.mark_flag, 0) = 0) as pendingReviewCount, and coalesce(attempt.mark_flag, 0) = 0) as pendingReviewCount,
(select count(distinct e.id) (select count(distinct e.id)
from exam e from exam e
where e.exam_time &gt;= #{monthStart} where e.exam_time &gt;= #{monthStart}
and e.exam_time &lt; #{nextMonthStart} and e.exam_time &lt; #{nextMonthStart}
and (e.chief_id = #{teacherId} and <include refid="participantPermission"/>)
or find_in_set(#{teacherId}, replace(coalesce(e.invigilation_id, ''), ' ', '')) &gt; 0))
as monthlyExamCount as monthlyExamCount
</select> </select>
...@@ -68,7 +95,7 @@ ...@@ -68,7 +95,7 @@
from exam e from exam e
inner join exam_student attempt on attempt.exam_id = e.id inner join exam_student attempt on attempt.exam_id = e.id
left join `class` c on c.id = e.class_id left join `class` c on c.id = e.class_id
where e.chief_id = #{teacherId} where <include refid="chiefPermission"/>
group by e.id, e.name, e.class_id, c.name, e.type, e.exam_time group by e.id, e.name, e.class_id, c.name, e.type, e.exam_time
having sum(case when coalesce(attempt.submit, 0) = 1 having sum(case when coalesce(attempt.submit, 0) = 1
and coalesce(attempt.mark_flag, 0) = 0 then 1 else 0 end) &gt; 0 and coalesce(attempt.mark_flag, 0) = 0 then 1 else 0 end) &gt; 0
...@@ -89,8 +116,7 @@ ...@@ -89,8 +116,7 @@
left join `class` c on c.id = e.class_id left join `class` c on c.id = e.class_id
where e.exam_time &gt;= #{startTime} where e.exam_time &gt;= #{startTime}
and e.exam_time &lt; #{endTime} and e.exam_time &lt; #{endTime}
and (e.chief_id = #{teacherId} and <include refid="participantPermission"/>
or find_in_set(#{teacherId}, replace(coalesce(e.invigilation_id, ''), ' ', '')) &gt; 0)
order by e.exam_time asc, e.id asc order by e.exam_time asc, e.id asc
</select> </select>
......
...@@ -3,13 +3,25 @@ ...@@ -3,13 +3,25 @@
<mapper namespace="com.platform.business.mapper.TeacherScoreMapper"> <mapper namespace="com.platform.business.mapper.TeacherScoreMapper">
<!-- <!--
管理端创建考试时会把负责教师写入 exam.chief_id。成绩管理按该字段判断业务归属, 管理端创建考试时会把所有首席考评员写入关系表,exam.chief_id只保留第一人兼容旧端。
成绩管理优先按关系表判断业务归属,并让没有关系记录的历史考试回退到旧字段;
不再用考试结束时间限制列表可见性,确保未来场次创建成功后也能立即同步到负责教师端。 不再用考试结束时间限制列表可见性,确保未来场次创建成功后也能立即同步到负责教师端。
未开始、未交卷或未发布的场次仍由下方统计列返回空成绩,并由服务层禁止导出, 未开始、未交卷或未发布的场次仍由下方统计列返回空成绩,并由服务层禁止导出,
因而提前展示考试计划不会泄露成绩,也不会把暂存分当成正式成绩。 因而提前展示考试计划不会泄露成绩,也不会把暂存分当成正式成绩。
--> -->
<sql id="visibleExamCondition"> <sql id="visibleExamCondition">
e.chief_id = #{teacherId} (exists (
select 1 from exam_teacher_assignment chief_assignment
where chief_assignment.exam_id = e.id
and chief_assignment.teacher_id = #{teacherId}
and chief_assignment.role = 'CHIEF'
) or (
not exists (
select 1 from exam_teacher_assignment any_chief
where any_chief.exam_id = e.id and any_chief.role = 'CHIEF'
)
and e.chief_id = #{teacherId}
))
</sql> </sql>
<!-- <!--
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
- `teachers`:未删除且具有教师角色的用户,首席考评员和监考教师共用。 - `teachers`:未删除且具有教师角色的用户,首席考评员和监考教师共用。
- `papers`:`theoretical_paper.lev` 与班级等级名称完全一致的理论试卷;实训考试不使用。 - `papers`:`theoretical_paper.lev` 与班级等级名称完全一致的理论试卷;实训考试不使用。
- `practiceRules`:班级等级末尾与规则的一级至五级匹配、且状态为已发布的实操规则。
- `students`:当前班级有效学员,包含身份证号、性别、手机号、单位和个人出勤率。 - `students`:当前班级有效学员,包含身份证号、性别、手机号、单位和个人出勤率。
出勤率按 `NORMAL/LATE` 占 `NORMAL/LATE/ABSENT/LEAVE` 的百分比计算;没有有效记录时为 出勤率按 `NORMAL/LATE` 占 `NORMAL/LATE/ABSENT/LEAVE` 的百分比计算;没有有效记录时为
...@@ -57,8 +58,8 @@ ...@@ -57,8 +58,8 @@
"examTime": "2026-09-18 09:00:00", "examTime": "2026-09-18 09:00:00",
"duration": 90, "duration": 90,
"forbid": 30, "forbid": 30,
"chiefExaminerId": "1900000000000000001", "chiefExaminerIds": ["1900000000000000001", "1900000000000000003"],
"invigilatorId": "1900000000000000002", "invigilatorIds": ["1900000000000000002"],
"paperId": "1900000000000000100", "paperId": "1900000000000000100",
"location": "教学楼A-301", "location": "教学楼A-301",
"passScore": 60, "passScore": 60,
...@@ -69,8 +70,10 @@ ...@@ -69,8 +70,10 @@
- 类型只支持“理论”“实训”;考试日期必须位于班级培训起止日期内。 - 类型只支持“理论”“实训”;考试日期必须位于班级培训起止日期内。
- 时长为15~600分钟;`forbid` 为0~考试时长。 - 时长为15~600分钟;`forbid` 为0~考试时长。
- 理论考试必须选择与班级等级一致的试卷,总分从试卷复制,不能提交`totalScore`。 - 理论考试必须选择与班级等级一致的试卷,总分从试卷复制,不能提交`totalScore`。
- 实训考试不传`paperId`,必须提交`totalScore`;试卷由第三方仿真系统创建。 - 实训考试不传`paperId`和`totalScore`,必须提交已发布的`practiceRuleId`;总分从规则复制。
- 两类考试的`passScore`不传时均默认为总分的60%。 - 两类考试的`passScore`不传时均默认为总分的60%。
- 两组教师各至少一人、组内自动去重,允许同一教师同时承担两个角色;任一首席考评员
均可阅卷和发布成绩。
- 至少选择1名、最多500名班级学员,ID不得重复。 - 至少选择1名、最多500名班级学员,ID不得重复。
- 同班级、首席考评员、监考教师或任一应考学员的考试时间不能重叠。 - 同班级、首席考评员、监考教师或任一应考学员的考试时间不能重叠。
- 同一班级内考试名称不能重复。 - 同一班级内考试名称不能重复。
...@@ -87,14 +90,21 @@ ...@@ -87,14 +90,21 @@
"type": "理论", "type": "理论",
"examTime": "2026-09-18 09:30:00", "examTime": "2026-09-18 09:30:00",
"duration": 90, "duration": 90,
"chiefExaminerId": "1900000000000000001", "chiefExaminerIds": ["1900000000000000001", "1900000000000000003"],
"invigilatorIds": ["1900000000000000002"],
"practiceRuleId": 5,
"location": "教学楼A-302", "location": "教学楼A-302",
"passScore": 60 "passScore": 60
} }
``` ```
编辑不允许切换考试类型,也不改变试卷、总分快照、监考教师、禁止交卷时间或应考学员。考试已到开始时间,或任一 编辑不允许切换考试类型,也不改变理论试卷、禁止交卷时间或应考学员;实训考试可切换
考生已开始、交卷、产生分数后禁止编辑。新的时间和教师安排仍会执行完整冲突校验。 已发布规则并刷新总分快照,两组教师均可重新多选。考试已到开始时间,或任一考生已开始、
交卷、产生分数后禁止编辑。新的时间和任一教师安排仍会执行完整冲突校验。
新数组字段非null时优先;没有数组字段的旧客户端仍可提交`chiefExaminerId`和
`invigilatorId`。响应旧字段返回列表第一人,同时通过`chiefExaminerIds/chiefExaminers`
及`invigilatorIds/invigilators`返回完整人员。
## 7. 删除考试 ## 7. 删除考试
......
# 管理员端实操自动组卷规则接口 # 管理员端实操试卷规则接口
页面位置为“管理员 → 智能考评 → 试卷管理 → 自动组卷 → 实操”。实操与理论的 页面位置为“管理员 → 智能考评 → 试卷管理 → 实操试卷规则”。部署时先执行
行为不同:这里只配置类目、考核时间、配分和题量,不生成正式试卷。 `sql/exam_management.sql`,再执行 `sql/practice_paper_rule.sql`。后者会创建规则主表、
明细表和考试教师关系表,并把原一级至五级配置迁移成五条已发布默认规则。
部署前执行: 状态仅有 `DRAFT`(草稿)和 `PUBLISHED`(已发布)。草稿可编辑、发布和删除;已发布
规则不可编辑或退回草稿,但未被考试使用时仍可删除。任何被考试引用的规则均不可删除。
```text ## 1. 规则列表
practical-business/src/main/resources/sql/practice_paper_rule.sql
```
## 1. 查询配置 `POST /theoretical/paper/admin/practice/page`
`GET /theoretical/paper/admin/practice/auto-configuration?lev=污水一级` ```json
{"pageNum":1,"pageSize":10,"name":"默认","lev":"污水一级","status":"PUBLISHED"}
```
`污水一级`、`污泥一级`和`一级`都会匹配 Excel 中的`一级`类目。返回全部标准类目, `lev` 会归一化为一级至五级,因此污水一级与污泥一级查询同一组共享规则。列表返回
包括当前题量为0的未选类目。初始考核时间和配分均为20;每个等级按 Excel 顺序默认 `id/name/lev/grade/totalQuestionCount/totalDuration/totalScore/status/statusLabel/usageCount`
启用前5项各1题,其余类目题量为0,因此初始总时间100分钟、总分100分。 以及 `publishable/editable/deletable`,页面应直接依据这三个布尔值显示操作按钮。
## 2. 保存配置 ## 2. 新建、详情和编辑
`PUT /theoretical/paper/admin/practice/auto-configuration` - `GET /theoretical/paper/admin/practice/catalog?lev=污水一级`:返回该标准等级的全部类目、
`catalogId`和默认数值,供新建表单初始化。
- `POST /theoretical/paper/admin/practice`:创建草稿。
- `GET /theoretical/paper/admin/practice/{ruleId}`:返回主表和全部标准类目明细。
- `PUT /theoretical/paper/admin/practice/{ruleId}`:仅允许编辑草稿。
新建和编辑请求示例:
```json ```json
{ {
"lev": "污水五级", "name": "一级实操规则A",
"lev": "污水一级",
"ruleList": [ "ruleList": [
{"id": 1, "assessmentDuration": 20, "score": 20, "questionCount": 1}, {"catalogId": 1, "assessmentDuration": 20, "score": 20, "questionCount": 1},
{"id": 2, "assessmentDuration": 20, "score": 20, "questionCount": 1}, {"catalogId": 2, "assessmentDuration": 20, "score": 20, "questionCount": 0}
{"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更新考核时间、配分和题量,不能 必须回传详情中该等级的全部标准类目,不能跨等级混用 `catalogId`。每项时间为1~600
修改 Excel 标准项目与单元内容。所有类目的`questionCount`合计必须为1至5。 分钟、配分大于0且不超过99999.99,所有类目的题量合计必须为1~5。题量、总时间和总分
由服务端计算,客户端提交同名字段不会作为事实来源。同一等级内规则名称不能重复。
## 3. 学员最近考试 ## 3. 发布与删除
`GET /exam/student/recent/{studentId}` 按最近一场考试返回数据库中的实际 `type`,并在 - `PUT /theoretical/paper/admin/practice/{ruleId}/status`,请求体固定为
原有字段基础上新增 `practiceRule`: `{"status":"PUBLISHED"}`;只有草稿可以发布。
- `DELETE /theoretical/paper/admin/practice/{ruleId}`;草稿和已发布规则均可调用,但使用次数
必须为0。
```json 旧版 `/practice/auto-configuration` GET/PUT 已移除,不再按职级覆盖唯一配置。
{
"practiceRule": { ## 4. 考试使用
"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 `GET /exam/admin/classes/{classId}/options` 的 `practiceRules` 只包含与班级等级后缀匹配的
的当前生效规则。 已发布规则。实训考试提交 `practiceRuleId`,服务端从规则复制总分到考试快照。学员最近
考试的 `practiceRule` 也按考试保存的规则ID读取,不会随新增规则或学员职级变化。
-- 管理员端“智能考评-试卷管理-自动组卷(实操)”规则配置(MySQL 5.7+/8.0)。 -- 管理员端“智能考评-试卷管理-自动组卷(实操)”规则配置(MySQL 5.7+/8.0)。
-- --
-- 业务口径: -- 业务口径:
-- 1. 实操自动组卷只保存规则,不生成theoretical_paper或正式试卷明细。 -- 1. practice_paper_rule保留为一级至五级标准类目目录,不生成theoretical_paper。
-- 2. level_grade使用Excel中的一级至五级;污水一级、污泥一级等职级在服务层统一匹配一级。 -- 2. level_grade使用Excel中的一级至五级;污水一级、污泥一级等职级在服务层统一匹配一级。
-- 3. 考核时间和单题配分默认20;每级默认启用Excel顺序前5项各1题,整套题量1至5由服务层校验。 -- 3. 考核时间和单题配分默认20;目录数值会迁移成每级一条已发布默认规则。
-- 4. INSERT IGNORE只补充缺失类目,重复执行不会覆盖管理员已经保存的时间、配分和题量。 -- 4. INSERT IGNORE只补充缺失类目,重复执行不会覆盖已经迁移的具名规则。
create table if not exists practice_paper_rule ( create table if not exists practice_paper_rule (
id int not null auto_increment comment '规则ID', id int not null auto_increment comment '规则ID',
...@@ -89,3 +89,135 @@ select level_grade, count(*) as category_count ...@@ -89,3 +89,135 @@ select level_grade, count(*) as category_count
from practice_paper_rule from practice_paper_rule
group by level_grade group by level_grade
order by field(level_grade, '五级', '四级', '三级', '二级', '一级'); order by field(level_grade, '五级', '四级', '三级', '二级', '一级');
-- ==================== 具名规则主表与明细 ====================
create table if not exists practice_paper_rule_definition (
id int not null auto_increment comment '实操试卷规则ID',
name varchar(200) not null comment '规则名称',
level_grade varchar(8) not null comment '共享标准等级:一级至五级',
question_count int not null comment '规则总题量快照',
total_duration int not null comment '规则总考核时间(分钟)',
total_score decimal(8,2) not null comment '规则总分快照',
status varchar(16) not null default 'DRAFT' comment 'DRAFT/PUBLISHED',
created_by varchar(64) null comment '创建管理员ID',
created_time datetime not null default current_timestamp comment '创建时间',
updated_by varchar(64) null comment '最后更新管理员ID',
updated_time datetime not null default current_timestamp comment '更新时间',
primary key (id),
unique key uk_practice_definition_grade_name (level_grade, name),
key idx_practice_definition_grade_status (level_grade, status, updated_time, id)
) engine=InnoDB default charset=utf8mb4 collate=utf8mb4_unicode_ci
comment='具名实操试卷规则主表';
create table if not exists practice_paper_rule_detail (
id int not null auto_increment comment '规则明细ID',
rule_id int not null comment '实操试卷规则ID',
catalog_id int not null comment '标准类目ID',
assessment_duration int not null comment '单题考核时间(分钟)',
score decimal(8,2) not null comment '单题配分',
question_count int not null default 0 comment '该类目考核题量',
primary key (id),
unique key uk_practice_detail_rule_catalog (rule_id, catalog_id),
key idx_practice_detail_rule (rule_id, id)
) engine=InnoDB default charset=utf8mb4 collate=utf8mb4_unicode_ci
comment='具名实操试卷规则明细';
-- 把升级前每个等级的唯一配置固化成已发布默认规则;唯一键保证脚本可重复执行。
insert ignore into practice_paper_rule_definition
(name, level_grade, question_count, total_duration, total_score, status,
created_by, created_time, updated_by, updated_time)
select concat(catalog.level_grade, '实操默认规则'),
catalog.level_grade,
sum(catalog.question_count),
sum(catalog.assessment_duration * catalog.question_count),
sum(catalog.score * catalog.question_count),
'PUBLISHED', null, now(), null, now()
from practice_paper_rule catalog
group by catalog.level_grade;
insert ignore into practice_paper_rule_detail
(rule_id, catalog_id, assessment_duration, score, question_count)
select definition.id, catalog.id, catalog.assessment_duration, catalog.score, catalog.question_count
from practice_paper_rule catalog
inner join practice_paper_rule_definition definition
on definition.level_grade = catalog.level_grade
and definition.name = concat(catalog.level_grade, '实操默认规则');
-- ==================== 考试规则引用与教师多选关系 ====================
create table if not exists exam_teacher_assignment (
id int not null auto_increment comment '关系ID',
exam_id int not null comment '考试ID',
teacher_id varchar(64) not null comment '教师用户ID',
role varchar(16) not null comment 'CHIEF/INVIGILATOR',
display_order int not null default 0 comment '表单选择顺序',
primary key (id),
unique key uk_exam_teacher_role (exam_id, teacher_id, role),
key idx_exam_teacher_permission (teacher_id, role, exam_id),
key idx_exam_teacher_exam (exam_id, role, display_order, id)
) engine=InnoDB default charset=utf8mb4 collate=utf8mb4_unicode_ci
comment='考试首席考评员与监考教师多选关系';
delimiter $$
drop procedure if exists migrate_exam_practice_rule$$
create procedure migrate_exam_practice_rule()
begin
if not exists (
select 1 from information_schema.columns
where table_schema = database() and table_name = 'exam'
and column_name = 'practice_rule_id'
) then
alter table exam
add column practice_rule_id int null comment '实训试卷规则ID' after paper_id;
end if;
if not exists (
select 1 from information_schema.statistics
where table_schema = database() and table_name = 'exam'
and index_name = 'idx_exam_practice_rule'
) then
alter table exam add index idx_exam_practice_rule (practice_rule_id, id);
end if;
end$$
call migrate_exam_practice_rule()$$
drop procedure if exists migrate_exam_practice_rule$$
delimiter ;
-- 首席考评员历史字段为单值,可直接迁移;空值不会生成无效关系。
insert ignore into exam_teacher_assignment (exam_id, teacher_id, role, display_order)
select e.id, trim(e.chief_id), 'CHIEF', 0
from exam e
where e.chief_id is not null and trim(e.chief_id) <> '';
-- 监考教师历史字段可能是逗号分隔值。MySQL 5.7没有JSON_TABLE,因此使用有限序列表拆分;
-- 现有业务不会超过20名监考教师,超过部分仍可由查询端旧字段回退逻辑识别。
insert ignore into exam_teacher_assignment (exam_id, teacher_id, role, display_order)
select e.id,
trim(substring_index(substring_index(e.invigilation_id, ',', seq_table.seq), ',', -1)),
'INVIGILATOR', seq_table.seq - 1
from exam e
inner join (
select 1 seq union all select 2 union all select 3 union all select 4 union all select 5
union all select 6 union all select 7 union all select 8 union all select 9 union all select 10
union all select 11 union all select 12 union all select 13 union all select 14 union all select 15
union all select 16 union all select 17 union all select 18 union all select 19 union all select 20
) seq_table
on seq_table.seq <= 1 + length(e.invigilation_id) - length(replace(e.invigilation_id, ',', ''))
where e.invigilation_id is not null
and trim(substring_index(substring_index(e.invigilation_id, ',', seq_table.seq), ',', -1)) <> '';
-- 历史实训考试按班级职级末尾的一级至五级匹配默认规则,延续原先跨工种共享规则的口径。
update exam e
inner join `class` c on c.id = e.class_id
inner join sys_level level_info on cast(level_info.id as char) = c.level
inner join practice_paper_rule_definition definition
on right(trim(level_info.name), char_length(definition.level_grade)) = definition.level_grade
and definition.name = concat(definition.level_grade, '实操默认规则')
set e.practice_rule_id = definition.id,
e.total_score = coalesce(e.total_score, definition.total_score),
e.pass_score = coalesce(e.pass_score, round(definition.total_score * 0.60, 2))
where e.type = '实训' and e.practice_rule_id is null;
...@@ -2,6 +2,8 @@ package com.platform.business.controller; ...@@ -2,6 +2,8 @@ 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.PracticePaperRuleSaveDTO;
import com.platform.business.model.dto.PracticePaperRuleQueryDTO;
import com.platform.business.model.dto.PracticePaperRuleStatusDTO;
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;
...@@ -63,18 +65,27 @@ class TheoreticalPaperAdminControllerTest { ...@@ -63,18 +65,27 @@ class TheoreticalPaperAdminControllerTest {
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());
when(practicePaperRuleService.queryPage(org.mockito.ArgumentMatchers.any()))
.thenReturn(Collections.emptyList());
TheoreticalPaperDTO query = new TheoreticalPaperDTO(); TheoreticalPaperDTO query = new TheoreticalPaperDTO();
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(); PracticePaperRuleSaveDTO practiceRule = new PracticePaperRuleSaveDTO();
PracticePaperRuleStatusDTO practiceStatus = new PracticePaperRuleStatusDTO();
practiceStatus.setStatus("PUBLISHED");
status.setStatus("ARCHIVED"); status.setStatus("ARCHIVED");
controller.page(query, request); controller.page(query, request);
controller.autoConfiguration("污水一级", request); controller.autoConfiguration("污水一级", request);
controller.practiceAutoConfiguration("污水一级", request); controller.practicePage(new PracticePaperRuleQueryDTO(), request);
controller.savePracticeAutoConfiguration(practiceRule, request); controller.createPracticeRule(practiceRule, request);
controller.practiceCatalog("污水一级", request);
controller.practiceRuleDetail(1, request);
controller.updatePracticeRule(1, practiceRule, request);
controller.publishPracticeRule(1, practiceStatus, request);
controller.deletePracticeRule(1, 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);
...@@ -85,9 +96,13 @@ class TheoreticalPaperAdminControllerTest { ...@@ -85,9 +96,13 @@ 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(13)).requireAdmin(administrator); verify(authenticatedUserService, times(18)).requireAdmin(administrator);
verify(practicePaperRuleService).configuration("污水一级"); verify(practicePaperRuleService).create(practiceRule, "admin-1");
verify(practicePaperRuleService).saveConfiguration(practiceRule, "admin-1"); verify(practicePaperRuleService).catalog("污水一级");
verify(practicePaperRuleService).detail(1);
verify(practicePaperRuleService).update(1, practiceRule, "admin-1");
verify(practicePaperRuleService).publish(1, "PUBLISHED", "admin-1");
verify(practicePaperRuleService).delete(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", "管理员甲");
......
...@@ -42,8 +42,7 @@ class ExamMapperXmlTest { ...@@ -42,8 +42,7 @@ class ExamMapperXmlTest {
conflictParameters.put("startTime", Timestamp.valueOf("2026-09-18 09:00:00")); conflictParameters.put("startTime", Timestamp.valueOf("2026-09-18 09:00:00"));
conflictParameters.put("duration", 90); conflictParameters.put("duration", 90);
conflictParameters.put("classId", 1); conflictParameters.put("classId", 1);
conflictParameters.put("chiefId", "teacher-1"); conflictParameters.put("teacherIds", Arrays.asList("teacher-1", "teacher-2"));
conflictParameters.put("invigilatorId", "teacher-2");
conflictParameters.put("studentIds", Arrays.asList("student-1", "student-2")); conflictParameters.put("studentIds", Arrays.asList("student-1", "student-2"));
conflictParameters.put("excludeId", null); conflictParameters.put("excludeId", null);
String conflictSql = configuration.getMappedStatement( String conflictSql = configuration.getMappedStatement(
...@@ -61,6 +60,7 @@ class ExamMapperXmlTest { ...@@ -61,6 +60,7 @@ class ExamMapperXmlTest {
"timestampadd(minute, coalesce(e.duration, 0), e.exam_time) > ?")); "timestampadd(minute, coalesce(e.duration, 0), e.exam_time) > ?"));
assertTrue(conflictSql.contains("from exam_student conflict_student")); assertTrue(conflictSql.contains("from exam_student conflict_student"));
assertTrue(conflictSql.contains("conflict_student.student_id in")); assertTrue(conflictSql.contains("conflict_student.student_id in"));
assertTrue(conflictSql.contains("from exam_teacher_assignment teacher_assignment"));
/* /*
* 通用考试分页必须查出时长供服务层计算三态;顶部汇总则必须独立统计全表, * 通用考试分页必须查出时长供服务层计算三态;顶部汇总则必须独立统计全表,
......
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