Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
邬吉朋
practical_train
Commits
66392f2e
Commit
66392f2e
authored
Sep 15, 2026
by
wujipeng
Browse files
bug修复
parent
4e10634c
Changes
46
Hide whitespace changes
Inline
Side-by-side
practical-business/src/main/java/com/platform/business/mapper/ExamTeacherAssignmentMapper.java
0 → 100644
View file @
66392f2e
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
);
}
practical-business/src/main/java/com/platform/business/mapper/PracticePaperRuleMapper.java
View file @
66392f2e
...
@@ -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
);
}
}
practical-business/src/main/java/com/platform/business/mapper/TeacherScoreMapper.java
View file @
66392f2e
...
@@ -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
{
...
...
practical-business/src/main/java/com/platform/business/service/PracticePaperRuleService.java
View file @
66392f2e
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的未选类目
。 */
/** 具名实操试卷规则的目录、查询、保存、发布和删除服务
。 */
PracticePaperRule
ConfigurationVO
configuration
(
String
level
);
public
interface
PracticePaperRule
Service
{
/** 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
);
}
}
practical-business/src/main/java/com/platform/business/service/impl/ExamAdminServiceImpl.java
View file @
66392f2e
...
@@ -3,11 +3,14 @@ package com.platform.business.service.impl;
...
@@ -3,11 +3,14 @@ package com.platform.business.service.impl;
import
com.platform.business.constant.AccountAdminConstants
;
import
com.platform.business.constant.AccountAdminConstants
;
import
com.platform.business.constant.ExamAdminConstants
;
import
com.platform.business.constant.ExamAdminConstants
;
import
com.platform.business.mapper.ExamMapper
;
import
com.platform.business.mapper.ExamMapper
;
import
com.platform.business.mapper.ExamTeacherAssignmentMapper
;
import
com.platform.business.model.dto.ExamAdminSaveDTO
;
import
com.platform.business.model.dto.ExamAdminSaveDTO
;
import
com.platform.business.model.dto.ExamAdminUpdateDTO
;
import
com.platform.business.model.dto.ExamAdminUpdateDTO
;
import
com.platform.business.model.dto.NotificationPublishDTO
;
import
com.platform.business.model.dto.NotificationPublishDTO
;
import
com.platform.business.model.entity.ExamEntity
;
import
com.platform.business.model.entity.ExamEntity
;
import
com.platform.business.model.entity.ExamStudentEntity
;
import
com.platform.business.model.entity.ExamStudentEntity
;
import
com.platform.business.model.entity.ExamTeacherAssignmentEntity
;
import
com.platform.business.model.entity.PracticePaperRuleDefinitionEntity
;
import
com.platform.business.model.entity.TheoreticalPaperEntity
;
import
com.platform.business.model.entity.TheoreticalPaperEntity
;
import
com.platform.business.model.vo.ClassAdminOptionVO
;
import
com.platform.business.model.vo.ClassAdminOptionVO
;
import
com.platform.business.model.vo.ClassAdminTreeVO
;
import
com.platform.business.model.vo.ClassAdminTreeVO
;
...
@@ -19,6 +22,7 @@ import com.platform.business.service.BusinessNotificationPublisher;
...
@@ -19,6 +22,7 @@ import com.platform.business.service.BusinessNotificationPublisher;
import
com.platform.business.service.ClassAdminService
;
import
com.platform.business.service.ClassAdminService
;
import
com.platform.business.service.ExamAdminService
;
import
com.platform.business.service.ExamAdminService
;
import
com.platform.business.service.ExamStudentService
;
import
com.platform.business.service.ExamStudentService
;
import
com.platform.business.service.PracticePaperRuleService
;
import
com.platform.business.service.TheoreticalPaperService
;
import
com.platform.business.service.TheoreticalPaperService
;
import
com.platform.exception.BusinessException
;
import
com.platform.exception.BusinessException
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
...
@@ -34,7 +38,10 @@ import java.util.ArrayList;
...
@@ -34,7 +38,10 @@ import java.util.ArrayList;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.LinkedHashSet
;
import
java.util.LinkedHashSet
;
import
java.util.Map
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.Set
;
import
java.util.TreeSet
;
import
java.util.TreeSet
;
...
@@ -49,15 +56,24 @@ import java.util.TreeSet;
...
@@ -49,15 +56,24 @@ import java.util.TreeSet;
@Service
@Service
public
class
ExamAdminServiceImpl
implements
ExamAdminService
{
public
class
ExamAdminServiceImpl
implements
ExamAdminService
{
private
static
final
String
TEACHER_ROLE_CHIEF
=
"CHIEF"
;
private
static
final
String
TEACHER_ROLE_INVIGILATOR
=
"INVIGILATOR"
;
@Resource
@Resource
private
ExamMapper
examMapper
;
private
ExamMapper
examMapper
;
@Resource
private
ExamTeacherAssignmentMapper
examTeacherAssignmentMapper
;
@Resource
@Resource
private
ClassAdminService
classAdminService
;
private
ClassAdminService
classAdminService
;
@Resource
@Resource
private
TheoreticalPaperService
theoreticalPaperService
;
private
TheoreticalPaperService
theoreticalPaperService
;
@Resource
private
PracticePaperRuleService
practicePaperRuleService
;
@Resource
@Resource
private
ExamStudentService
examStudentService
;
private
ExamStudentService
examStudentService
;
...
@@ -86,6 +102,7 @@ public class ExamAdminServiceImpl implements ExamAdminService {
...
@@ -86,6 +102,7 @@ public class ExamAdminServiceImpl implements ExamAdminService {
for
(
ExamAdminDetailVO
exam
:
exams
)
{
for
(
ExamAdminDetailVO
exam
:
exams
)
{
applyStatus
(
exam
,
now
);
applyStatus
(
exam
,
now
);
}
}
populateTeacherAssignments
(
exams
);
result
.
setExams
(
exams
);
result
.
setExams
(
exams
);
// plannedCount现在表示页面实际返回的全部考试数量,包含已结束考试。
// plannedCount现在表示页面实际返回的全部考试数量,包含已结束考试。
result
.
setPlannedCount
(
exams
.
size
());
result
.
setPlannedCount
(
exams
.
size
());
...
@@ -107,6 +124,7 @@ public class ExamAdminServiceImpl implements ExamAdminService {
...
@@ -107,6 +124,7 @@ public class ExamAdminServiceImpl implements ExamAdminService {
List
<
ExamAdminStudentOptionVO
>
students
=
examMapper
.
selectAdminExamStudentOptions
(
classId
);
List
<
ExamAdminStudentOptionVO
>
students
=
examMapper
.
selectAdminExamStudentOptions
(
classId
);
result
.
setTeachers
(
teachers
==
null
?
Collections
.
emptyList
()
:
teachers
);
result
.
setTeachers
(
teachers
==
null
?
Collections
.
emptyList
()
:
teachers
);
result
.
setPapers
(
papers
==
null
?
Collections
.
emptyList
()
:
papers
);
result
.
setPapers
(
papers
==
null
?
Collections
.
emptyList
()
:
papers
);
result
.
setPracticeRules
(
practicePaperRuleService
.
publishedOptions
(
managedClass
.
getLevelName
()));
result
.
setStudents
(
students
==
null
?
Collections
.
emptyList
()
:
students
);
result
.
setStudents
(
students
==
null
?
Collections
.
emptyList
()
:
students
);
return
result
;
return
result
;
}
}
...
@@ -121,6 +139,7 @@ public class ExamAdminServiceImpl implements ExamAdminService {
...
@@ -121,6 +139,7 @@ public class ExamAdminServiceImpl implements ExamAdminService {
}
}
List
<
String
>
studentIds
=
examMapper
.
selectAdminExamStudentIds
(
examId
);
List
<
String
>
studentIds
=
examMapper
.
selectAdminExamStudentIds
(
examId
);
detail
.
setStudentIds
(
studentIds
==
null
?
Collections
.
emptyList
()
:
studentIds
);
detail
.
setStudentIds
(
studentIds
==
null
?
Collections
.
emptyList
()
:
studentIds
);
populateTeacherAssignments
(
Collections
.
singletonList
(
detail
));
applyStatus
(
detail
,
businessNow
());
applyStatus
(
detail
,
businessNow
());
return
detail
;
return
detail
;
}
}
...
@@ -140,11 +159,11 @@ public class ExamAdminServiceImpl implements ExamAdminService {
...
@@ -140,11 +159,11 @@ public class ExamAdminServiceImpl implements ExamAdminService {
ExamAdminClassVO
managedClass
=
requireManagedClass
(
request
.
getClassId
());
ExamAdminClassVO
managedClass
=
requireManagedClass
(
request
.
getClassId
());
List
<
String
>
studentIds
=
normalizeStudentIds
(
request
.
getStudentIds
());
List
<
String
>
studentIds
=
normalizeStudentIds
(
request
.
getStudentIds
());
PreparedExam
prepared
=
prepareCreate
(
request
,
managedClass
,
studentIds
);
PreparedExam
prepared
=
prepareCreate
(
request
,
managedClass
,
studentIds
);
lockAndValidateRelationships
(
request
.
getClassId
(),
prepared
.
chiefId
,
lockAndValidateRelationships
(
request
.
getClassId
(),
prepared
.
chiefId
s
,
prepared
.
invigilatorId
,
studentIds
);
prepared
.
invigilatorId
s
,
studentIds
);
validateDuplicateName
(
request
.
getClassId
(),
prepared
.
name
,
null
);
validateDuplicateName
(
request
.
getClassId
(),
prepared
.
name
,
null
);
validateConflicts
(
request
.
getClassId
(),
prepared
.
name
,
prepared
.
examTime
,
validateConflicts
(
request
.
getClassId
(),
prepared
.
name
,
prepared
.
examTime
,
prepared
.
duration
,
prepared
.
chiefId
,
prepared
.
invigilatorId
,
studentIds
,
null
);
prepared
.
duration
,
prepared
.
chiefId
s
,
prepared
.
invigilatorId
s
,
studentIds
,
null
);
ExamEntity
entity
=
new
ExamEntity
();
ExamEntity
entity
=
new
ExamEntity
();
entity
.
setClassId
(
request
.
getClassId
());
entity
.
setClassId
(
request
.
getClassId
());
...
@@ -153,10 +172,11 @@ public class ExamAdminServiceImpl implements ExamAdminService {
...
@@ -153,10 +172,11 @@ public class ExamAdminServiceImpl implements ExamAdminService {
entity
.
setExamTime
(
prepared
.
examTime
);
entity
.
setExamTime
(
prepared
.
examTime
);
entity
.
setDuration
(
prepared
.
duration
);
entity
.
setDuration
(
prepared
.
duration
);
entity
.
setForbid
(
prepared
.
forbid
);
entity
.
setForbid
(
prepared
.
forbid
);
entity
.
setChiefId
(
prepared
.
chiefId
);
entity
.
setChiefId
(
prepared
.
chiefId
s
.
get
(
0
)
);
entity
.
setInvigilationId
(
prepared
.
invigilatorId
);
entity
.
setInvigilationId
(
prepared
.
invigilatorId
s
.
get
(
0
)
);
//
实训考试的试卷完全由第三方系统负责,本系统必须显式保存空paper_id
。
//
兼容字段只保留第一人;完整角色关系写入exam_teacher_assignment
。
entity
.
setPaperId
(
prepared
.
paper
==
null
?
null
:
prepared
.
paper
.
getId
());
entity
.
setPaperId
(
prepared
.
paper
==
null
?
null
:
prepared
.
paper
.
getId
());
entity
.
setPracticeRuleId
(
prepared
.
practiceRuleId
);
entity
.
setLocation
(
prepared
.
location
);
entity
.
setLocation
(
prepared
.
location
);
entity
.
setTotalScore
(
prepared
.
totalScore
);
entity
.
setTotalScore
(
prepared
.
totalScore
);
entity
.
setPassScore
(
prepared
.
passScore
);
entity
.
setPassScore
(
prepared
.
passScore
);
...
@@ -167,6 +187,7 @@ public class ExamAdminServiceImpl implements ExamAdminService {
...
@@ -167,6 +187,7 @@ public class ExamAdminServiceImpl implements ExamAdminService {
if
(
examMapper
.
insert
(
entity
)
!=
1
||
entity
.
getId
()
<=
0
)
{
if
(
examMapper
.
insert
(
entity
)
!=
1
||
entity
.
getId
()
<=
0
)
{
throw
new
BusinessException
(
"考试计划创建失败,请稍后重试"
);
throw
new
BusinessException
(
"考试计划创建失败,请稍后重试"
);
}
}
saveTeacherAssignments
(
entity
.
getId
(),
prepared
.
chiefIds
,
prepared
.
invigilatorIds
);
List
<
ExamStudentEntity
>
candidates
=
new
ArrayList
<>(
studentIds
.
size
());
List
<
ExamStudentEntity
>
candidates
=
new
ArrayList
<>(
studentIds
.
size
());
for
(
String
studentId
:
studentIds
)
{
for
(
String
studentId
:
studentIds
)
{
...
@@ -182,7 +203,8 @@ public class ExamAdminServiceImpl implements ExamAdminService {
...
@@ -182,7 +203,8 @@ public class ExamAdminServiceImpl implements ExamAdminService {
throw
new
BusinessException
(
"应考学员保存失败,请稍后重试"
);
throw
new
BusinessException
(
"应考学员保存失败,请稍后重试"
);
}
}
// 考试主表、应考名单和两端通知发件箱原子提交,任何一步失败都不会产生孤立消息。
// 考试主表、应考名单和两端通知发件箱原子提交,任何一步失败都不会产生孤立消息。
publishExamNotification
(
entity
,
managedClass
,
studentIds
);
publishExamNotification
(
entity
,
managedClass
,
studentIds
,
prepared
.
chiefIds
,
prepared
.
invigilatorIds
);
return
detail
(
entity
.
getId
());
return
detail
(
entity
.
getId
());
}
}
...
@@ -193,7 +215,8 @@ public class ExamAdminServiceImpl implements ExamAdminService {
...
@@ -193,7 +215,8 @@ public class ExamAdminServiceImpl implements ExamAdminService {
* 两条消息都能由消息中心独立去重。</p>
* 两条消息都能由消息中心独立去重。</p>
*/
*/
private
void
publishExamNotification
(
ExamEntity
exam
,
ExamAdminClassVO
managedClass
,
private
void
publishExamNotification
(
ExamEntity
exam
,
ExamAdminClassVO
managedClass
,
List
<
String
>
studentIds
)
{
List
<
String
>
studentIds
,
List
<
String
>
chiefIds
,
List
<
String
>
invigilatorIds
)
{
String
className
=
trimToNull
(
managedClass
.
getClassName
())
==
null
String
className
=
trimToNull
(
managedClass
.
getClassName
())
==
null
?
"对应班级"
:
managedClass
.
getClassName
().
trim
();
?
"对应班级"
:
managedClass
.
getClassName
().
trim
();
...
@@ -208,7 +231,10 @@ public class ExamAdminServiceImpl implements ExamAdminService {
...
@@ -208,7 +231,10 @@ public class ExamAdminServiceImpl implements ExamAdminService {
teacherMessage
.
setBusinessId
(
String
.
valueOf
(
exam
.
getId
()));
teacherMessage
.
setBusinessId
(
String
.
valueOf
(
exam
.
getId
()));
teacherMessage
.
setActionUrl
(
"/exam/teacher/scores/exams/"
+
exam
.
getId
());
teacherMessage
.
setActionUrl
(
"/exam/teacher/scores/exams/"
+
exam
.
getId
());
teacherMessage
.
setPriority
(
"IMPORTANT"
);
teacherMessage
.
setPriority
(
"IMPORTANT"
);
teacherMessage
.
setRecipientUserIds
(
Arrays
.
asList
(
exam
.
getChiefId
(),
exam
.
getInvigilationId
()));
// 同一教师允许跨角色任职,通知接收人必须去重,避免同一考试收到两条相同消息。
LinkedHashSet
<
String
>
teacherRecipients
=
new
LinkedHashSet
<>(
chiefIds
);
teacherRecipients
.
addAll
(
invigilatorIds
);
teacherMessage
.
setRecipientUserIds
(
new
ArrayList
<>(
teacherRecipients
));
notificationPublisher
.
publish
(
teacherMessage
,
null
,
AccountAdminConstants
.
ROLE_ADMIN
);
notificationPublisher
.
publish
(
teacherMessage
,
null
,
AccountAdminConstants
.
ROLE_ADMIN
);
NotificationPublishDTO
studentMessage
=
new
NotificationPublishDTO
();
NotificationPublishDTO
studentMessage
=
new
NotificationPublishDTO
();
...
@@ -245,11 +271,11 @@ public class ExamAdminServiceImpl implements ExamAdminService {
...
@@ -245,11 +271,11 @@ public class ExamAdminServiceImpl implements ExamAdminService {
throw
new
BusinessException
(
"考试没有应考学员,无法编辑"
);
throw
new
BusinessException
(
"考试没有应考学员,无法编辑"
);
}
}
PreparedUpdate
prepared
=
prepareUpdate
(
request
,
existing
,
managedClass
);
PreparedUpdate
prepared
=
prepareUpdate
(
request
,
existing
,
managedClass
);
lockAndValidateRelationships
(
existing
.
getClassId
(),
prepared
.
chiefId
,
lockAndValidateRelationships
(
existing
.
getClassId
(),
prepared
.
chiefId
s
,
existing
.
getInvigilationId
()
,
studentIds
);
prepared
.
invigilatorIds
,
studentIds
);
validateDuplicateName
(
existing
.
getClassId
(),
prepared
.
name
,
examId
);
validateDuplicateName
(
existing
.
getClassId
(),
prepared
.
name
,
examId
);
validateConflicts
(
existing
.
getClassId
(),
prepared
.
name
,
prepared
.
examTime
,
validateConflicts
(
existing
.
getClassId
(),
prepared
.
name
,
prepared
.
examTime
,
prepared
.
duration
,
prepared
.
chiefId
,
existing
.
getI
nvigilat
ionId
()
,
studentIds
,
examId
);
prepared
.
duration
,
prepared
.
chiefId
s
,
prepared
.
i
nvigilat
orIds
,
studentIds
,
examId
);
ExamEntity
update
=
new
ExamEntity
();
ExamEntity
update
=
new
ExamEntity
();
update
.
setId
(
examId
);
update
.
setId
(
examId
);
...
@@ -257,13 +283,18 @@ public class ExamAdminServiceImpl implements ExamAdminService {
...
@@ -257,13 +283,18 @@ public class ExamAdminServiceImpl implements ExamAdminService {
update
.
setType
(
prepared
.
type
);
update
.
setType
(
prepared
.
type
);
update
.
setExamTime
(
prepared
.
examTime
);
update
.
setExamTime
(
prepared
.
examTime
);
update
.
setDuration
(
prepared
.
duration
);
update
.
setDuration
(
prepared
.
duration
);
update
.
setChiefId
(
prepared
.
chiefId
);
update
.
setChiefId
(
prepared
.
chiefIds
.
get
(
0
));
update
.
setInvigilationId
(
prepared
.
invigilatorIds
.
get
(
0
));
update
.
setPracticeRuleId
(
prepared
.
practiceRuleId
);
update
.
setTotalScore
(
prepared
.
totalScore
);
update
.
setLocation
(
prepared
.
location
);
update
.
setLocation
(
prepared
.
location
);
update
.
setPassScore
(
prepared
.
passScore
);
update
.
setPassScore
(
prepared
.
passScore
);
update
.
setUpdateTime
(
businessNow
());
update
.
setUpdateTime
(
businessNow
());
if
(
examMapper
.
updateAdminExam
(
update
)
!=
1
)
{
if
(
examMapper
.
updateAdminExam
(
update
)
!=
1
)
{
throw
new
BusinessException
(
"考试计划已发生变化,请刷新后重试"
);
throw
new
BusinessException
(
"考试计划已发生变化,请刷新后重试"
);
}
}
examTeacherAssignmentMapper
.
deleteByExamId
(
examId
);
saveTeacherAssignments
(
examId
,
prepared
.
chiefIds
,
prepared
.
invigilatorIds
);
return
detail
(
examId
);
return
detail
(
examId
);
}
}
...
@@ -274,6 +305,7 @@ public class ExamAdminServiceImpl implements ExamAdminService {
...
@@ -274,6 +305,7 @@ public class ExamAdminServiceImpl implements ExamAdminService {
ExamEntity
existing
=
lockMutableExam
(
examId
);
ExamEntity
existing
=
lockMutableExam
(
examId
);
// 先删除尚未作答的应考关系,再删除主记录,避免没有数据库外键的旧环境遗留孤儿数据。
// 先删除尚未作答的应考关系,再删除主记录,避免没有数据库外键的旧环境遗留孤儿数据。
examMapper
.
deleteAdminExamStudents
(
examId
);
examMapper
.
deleteAdminExamStudents
(
examId
);
examTeacherAssignmentMapper
.
deleteByExamId
(
examId
);
if
(
examMapper
.
deleteById
(
existing
.
getId
())
!=
1
)
{
if
(
examMapper
.
deleteById
(
existing
.
getId
())
!=
1
)
{
throw
new
BusinessException
(
"考试计划已发生变化,请刷新后重试"
);
throw
new
BusinessException
(
"考试计划已发生变化,请刷新后重试"
);
}
}
...
@@ -282,7 +314,7 @@ public class ExamAdminServiceImpl implements ExamAdminService {
...
@@ -282,7 +314,7 @@ public class ExamAdminServiceImpl implements ExamAdminService {
/**
/**
* 新增时按考试类型确定唯一分值来源并生成不可变总分快照。
* 新增时按考试类型确定唯一分值来源并生成不可变总分快照。
* 理论考试只信任已发布
到本系统的试卷总分;实训考试只信任管理员填写的
总分。
* 理论考试只信任已发布
试卷,实训考试只信任已发布实操规则,均不接受手填
总分。
*/
*/
private
PreparedExam
prepareCreate
(
ExamAdminSaveDTO
request
,
ExamAdminClassVO
managedClass
,
private
PreparedExam
prepareCreate
(
ExamAdminSaveDTO
request
,
ExamAdminClassVO
managedClass
,
List
<
String
>
studentIds
)
{
List
<
String
>
studentIds
)
{
...
@@ -292,14 +324,19 @@ public class ExamAdminServiceImpl implements ExamAdminService {
...
@@ -292,14 +324,19 @@ public class ExamAdminServiceImpl implements ExamAdminService {
prepared
.
examTime
=
requireFutureExamTime
(
request
.
getExamTime
(),
managedClass
);
prepared
.
examTime
=
requireFutureExamTime
(
request
.
getExamTime
(),
managedClass
);
prepared
.
duration
=
validateDuration
(
request
.
getDuration
());
prepared
.
duration
=
validateDuration
(
request
.
getDuration
());
prepared
.
forbid
=
validateForbid
(
request
.
getForbid
(),
prepared
.
duration
);
prepared
.
forbid
=
validateForbid
(
request
.
getForbid
(),
prepared
.
duration
);
prepared
.
chiefId
=
requireText
(
request
.
getChiefExaminerId
(),
"首席考评员ID"
,
64
);
prepared
.
chiefIds
=
normalizeTeacherIds
(
request
.
getChiefExaminerIds
(),
prepared
.
invigilatorId
=
requireText
(
request
.
getInvigilatorId
(),
"监考教师ID"
,
64
);
request
.
getChiefExaminerId
(),
null
,
"首席考评员"
);
prepared
.
invigilatorIds
=
normalizeTeacherIds
(
request
.
getInvigilatorIds
(),
request
.
getInvigilatorId
(),
null
,
"监考教师"
);
prepared
.
location
=
optionalText
(
request
.
getLocation
(),
"考场"
,
ExamAdminConstants
.
MAX_LOCATION_LENGTH
);
prepared
.
location
=
optionalText
(
request
.
getLocation
(),
"考场"
,
ExamAdminConstants
.
MAX_LOCATION_LENGTH
);
if
(
ExamAdminConstants
.
TYPE_THEORY
.
equals
(
prepared
.
type
))
{
if
(
ExamAdminConstants
.
TYPE_THEORY
.
equals
(
prepared
.
type
))
{
if
(
request
.
getTotalScore
()
!=
null
)
{
if
(
request
.
getTotalScore
()
!=
null
)
{
throw
new
BusinessException
(
"理论考试总分由试卷确定,不能手动填写"
);
throw
new
BusinessException
(
"理论考试总分由试卷确定,不能手动填写"
);
}
}
if
(
request
.
getPracticeRuleId
()
!=
null
)
{
throw
new
BusinessException
(
"理论考试不能选择实操试卷规则"
);
}
String
paperId
=
requireText
(
request
.
getPaperId
(),
"试卷ID"
,
64
);
String
paperId
=
requireText
(
request
.
getPaperId
(),
"试卷ID"
,
64
);
TheoreticalPaperEntity
paper
=
theoreticalPaperService
.
getById
(
paperId
);
TheoreticalPaperEntity
paper
=
theoreticalPaperService
.
getById
(
paperId
);
if
(
paper
==
null
)
{
if
(
paper
==
null
)
{
...
@@ -313,14 +350,21 @@ public class ExamAdminServiceImpl implements ExamAdminService {
...
@@ -313,14 +350,21 @@ public class ExamAdminServiceImpl implements ExamAdminService {
throw
new
BusinessException
(
"所选试卷总分无效"
);
throw
new
BusinessException
(
"所选试卷总分无效"
);
}
}
prepared
.
paper
=
paper
;
prepared
.
paper
=
paper
;
prepared
.
practiceRuleId
=
null
;
prepared
.
totalScore
=
normalizeTotalScore
(
prepared
.
totalScore
=
normalizeTotalScore
(
BigDecimal
.
valueOf
(
paper
.
getSum
()),
"所选试卷总分"
);
BigDecimal
.
valueOf
(
paper
.
getSum
()),
"所选试卷总分"
);
}
else
{
}
else
{
if
(
trimToNull
(
request
.
getPaperId
())
!=
null
)
{
if
(
trimToNull
(
request
.
getPaperId
())
!=
null
)
{
throw
new
BusinessException
(
"实训考试由第三方创建试卷,不能选择本系统试卷"
);
throw
new
BusinessException
(
"实训考试由第三方创建试卷,不能选择本系统试卷"
);
}
}
if
(
request
.
getTotalScore
()
!=
null
)
{
throw
new
BusinessException
(
"实训考试总分由实操试卷规则确定,不能手动填写"
);
}
PracticePaperRuleDefinitionEntity
rule
=
practicePaperRuleService
.
requirePublishedDefinition
(
request
.
getPracticeRuleId
(),
managedClass
.
getLevelName
());
prepared
.
paper
=
null
;
prepared
.
paper
=
null
;
prepared
.
totalScore
=
normalizeTotalScore
(
request
.
getTotalScore
(),
"实训考试总分"
);
prepared
.
practiceRuleId
=
rule
.
getId
();
prepared
.
totalScore
=
normalizeTotalScore
(
rule
.
getTotalScore
(),
"所选实操试卷规则总分"
);
}
}
prepared
.
passScore
=
normalizePassScore
(
request
.
getPassScore
(),
prepared
.
totalScore
,
true
);
prepared
.
passScore
=
normalizePassScore
(
request
.
getPassScore
(),
prepared
.
totalScore
,
true
);
if
(
studentIds
.
size
()
>
ExamAdminConstants
.
MAX_STUDENT_COUNT
)
{
if
(
studentIds
.
size
()
>
ExamAdminConstants
.
MAX_STUDENT_COUNT
)
{
...
@@ -329,7 +373,7 @@ public class ExamAdminServiceImpl implements ExamAdminService {
...
@@ -329,7 +373,7 @@ public class ExamAdminServiceImpl implements ExamAdminService {
return
prepared
;
return
prepared
;
}
}
/**
编辑不改变试卷及总分快照,合格分为空时保留旧值
。 */
/**
理论考试保持试卷快照;实训考试允许切换规则并据此刷新总分快照
。 */
private
PreparedUpdate
prepareUpdate
(
ExamAdminUpdateDTO
request
,
ExamEntity
existing
,
private
PreparedUpdate
prepareUpdate
(
ExamAdminUpdateDTO
request
,
ExamEntity
existing
,
ExamAdminClassVO
managedClass
)
{
ExamAdminClassVO
managedClass
)
{
PreparedUpdate
prepared
=
new
PreparedUpdate
();
PreparedUpdate
prepared
=
new
PreparedUpdate
();
...
@@ -341,34 +385,65 @@ public class ExamAdminServiceImpl implements ExamAdminService {
...
@@ -341,34 +385,65 @@ public class ExamAdminServiceImpl implements ExamAdminService {
}
}
prepared
.
examTime
=
requireFutureExamTime
(
request
.
getExamTime
(),
managedClass
);
prepared
.
examTime
=
requireFutureExamTime
(
request
.
getExamTime
(),
managedClass
);
prepared
.
duration
=
validateDuration
(
request
.
getDuration
());
prepared
.
duration
=
validateDuration
(
request
.
getDuration
());
prepared
.
chiefId
=
requireText
(
request
.
getChiefExaminerId
(),
"首席考评员ID"
,
64
);
List
<
String
>
existingChiefIds
=
currentTeacherIds
(
existing
.
getId
(),
TEACHER_ROLE_CHIEF
,
existing
.
getChiefId
());
List
<
String
>
existingInvigilatorIds
=
currentTeacherIds
(
existing
.
getId
(),
TEACHER_ROLE_INVIGILATOR
,
existing
.
getInvigilationId
());
prepared
.
chiefIds
=
normalizeTeacherIds
(
request
.
getChiefExaminerIds
(),
request
.
getChiefExaminerId
(),
existingChiefIds
,
"首席考评员"
);
prepared
.
invigilatorIds
=
normalizeTeacherIds
(
request
.
getInvigilatorIds
(),
request
.
getInvigilatorId
(),
existingInvigilatorIds
,
"监考教师"
);
prepared
.
location
=
optionalText
(
request
.
getLocation
(),
"考场"
,
ExamAdminConstants
.
MAX_LOCATION_LENGTH
);
prepared
.
location
=
optionalText
(
request
.
getLocation
(),
"考场"
,
ExamAdminConstants
.
MAX_LOCATION_LENGTH
);
if
(
existing
.
getTotalScore
()
==
null
||
existing
.
getTotalScore
().
compareTo
(
BigDecimal
.
ZERO
)
<=
0
)
{
if
(
ExamAdminConstants
.
TYPE_THEORY
.
equals
(
prepared
.
type
))
{
if
(
request
.
getPracticeRuleId
()
!=
null
)
{
throw
new
BusinessException
(
"理论考试不能选择实操试卷规则"
);
}
prepared
.
practiceRuleId
=
null
;
prepared
.
totalScore
=
existing
.
getTotalScore
();
}
else
{
Integer
ruleId
=
request
.
getPracticeRuleId
()
==
null
?
existing
.
getPracticeRuleId
()
:
request
.
getPracticeRuleId
();
PracticePaperRuleDefinitionEntity
rule
=
practicePaperRuleService
.
requirePublishedDefinition
(
ruleId
,
managedClass
.
getLevelName
());
prepared
.
practiceRuleId
=
rule
.
getId
();
prepared
.
totalScore
=
normalizeTotalScore
(
rule
.
getTotalScore
(),
"所选实操试卷规则总分"
);
}
if
(
prepared
.
totalScore
==
null
||
prepared
.
totalScore
.
compareTo
(
BigDecimal
.
ZERO
)
<=
0
)
{
throw
new
BusinessException
(
"考试总分快照缺失,请先执行考试管理数据库迁移脚本"
);
throw
new
BusinessException
(
"考试总分快照缺失,请先执行考试管理数据库迁移脚本"
);
}
}
BigDecimal
requestedPass
=
request
.
getPassScore
()
==
null
boolean
switchedPracticeRule
=
ExamAdminConstants
.
TYPE_PRACTICE
.
equals
(
prepared
.
type
)
&&
!
java
.
util
.
Objects
.
equals
(
existing
.
getPracticeRuleId
(),
prepared
.
practiceRuleId
);
/*
* 切换实操规则会刷新总分快照。此时前端若未显式填写合格分,必须用新总分的60%
* 重新计算,不能沿用旧规则的合格分;未切换规则时则保留管理员原来设置的合格分。
*/
BigDecimal
requestedPass
=
request
.
getPassScore
()
==
null
&&
!
switchedPracticeRule
?
existing
.
getPassScore
()
:
request
.
getPassScore
();
?
existing
.
getPassScore
()
:
request
.
getPassScore
();
prepared
.
passScore
=
normalizePassScore
(
requestedPass
,
existing
.
getTotalScore
(),
false
);
prepared
.
passScore
=
normalizePassScore
(
requestedPass
,
prepared
.
totalScore
,
switchedPracticeRule
);
return
prepared
;
return
prepared
;
}
}
/**
/**
* 锁定并校验教师与班级成员。返回数量必须与请求完全一致,不能静默忽略跨班学员。
* 锁定并校验教师与班级成员。返回数量必须与请求完全一致,不能静默忽略跨班学员。
*/
*/
private
void
lockAndValidateRelationships
(
Integer
classId
,
String
chiefId
,
private
void
lockAndValidateRelationships
(
Integer
classId
,
List
<
String
>
chiefIds
,
String
invigilatorId
,
List
<
String
>
studentIds
)
{
List
<
String
>
invigilatorIds
,
Set
<
String
>
teacherIds
=
new
TreeSet
<>(
Arrays
.
asList
(
chiefId
,
invigilatorId
));
List
<
String
>
studentIds
)
{
Set
<
String
>
teacherIds
=
new
TreeSet
<>(
chiefIds
);
teacherIds
.
addAll
(
invigilatorIds
);
Set
<
String
>
allUserIds
=
new
TreeSet
<>(
teacherIds
);
Set
<
String
>
allUserIds
=
new
TreeSet
<>(
teacherIds
);
allUserIds
.
addAll
(
studentIds
);
allUserIds
.
addAll
(
studentIds
);
List
<
String
>
lockedUsers
=
examMapper
.
lockAdminExamUsers
(
new
ArrayList
<>(
allUserIds
));
List
<
String
>
lockedUsers
=
examMapper
.
lockAdminExamUsers
(
new
ArrayList
<>(
allUserIds
));
if
(
lockedUsers
==
null
||
new
LinkedHashSet
<>(
lockedUsers
).
size
()
!=
allUserIds
.
size
())
{
if
(
lockedUsers
==
null
||
new
LinkedHashSet
<>(
lockedUsers
).
size
()
!=
allUserIds
.
size
())
{
throw
new
BusinessException
(
"所选教师或应考学员不存在"
);
throw
new
BusinessException
(
"所选教师或应考学员不存在"
);
}
}
if
(
examMapper
.
countAdminExamActiveTeacher
(
chiefId
)
!=
1
)
{
List
<
String
>
activeTeachers
=
examMapper
.
selectAdminExamActiveTeacherIds
(
throw
new
BusinessException
(
"所选首席考评员不存在、已停用或不具有教师角色"
);
new
ArrayList
<>(
teacherIds
));
}
Set
<
String
>
activeTeacherIds
=
activeTeachers
==
null
if
(
examMapper
.
countAdminExamActiveTeacher
(
invigilatorId
)
!=
1
)
{
?
Collections
.
emptySet
()
:
new
HashSet
<>(
activeTeachers
);
throw
new
BusinessException
(
"所选监考教师不存在、已停用或不具有教师角色"
);
if
(!
activeTeacherIds
.
containsAll
(
teacherIds
))
{
throw
new
BusinessException
(
"所选考评员或监考教师已停用或不具有教师角色"
);
}
}
List
<
String
>
lockedStudents
=
examMapper
.
lockAdminExamStudents
(
classId
,
studentIds
);
List
<
String
>
lockedStudents
=
examMapper
.
lockAdminExamStudents
(
classId
,
studentIds
);
...
@@ -387,37 +462,41 @@ public class ExamAdminServiceImpl implements ExamAdminService {
...
@@ -387,37 +462,41 @@ public class ExamAdminServiceImpl implements ExamAdminService {
/** 将数据库返回的冲突场次转换为页面可直接展示的明确错误。 */
/** 将数据库返回的冲突场次转换为页面可直接展示的明确错误。 */
private
void
validateConflicts
(
Integer
classId
,
String
name
,
Date
startTime
,
Integer
duration
,
private
void
validateConflicts
(
Integer
classId
,
String
name
,
Date
startTime
,
Integer
duration
,
String
chiefId
,
String
invigilatorId
,
List
<
String
>
studentIds
,
List
<
String
>
chiefIds
,
List
<
String
>
invigilatorIds
,
List
<
String
>
studentIds
,
Integer
excludeId
)
{
Integer
excludeId
)
{
LinkedHashSet
<
String
>
teacherIds
=
new
LinkedHashSet
<>(
chiefIds
);
teacherIds
.
addAll
(
invigilatorIds
);
List
<
ExamAdminDetailVO
>
conflicts
=
examMapper
.
selectAdminExamConflicts
(
startTime
,
duration
,
List
<
ExamAdminDetailVO
>
conflicts
=
examMapper
.
selectAdminExamConflicts
(
startTime
,
duration
,
classId
,
chiefId
,
invigilato
rId
,
studentIds
,
excludeId
);
classId
,
new
ArrayList
<>(
teache
rId
s
)
,
studentIds
,
excludeId
);
if
(
conflicts
==
null
||
conflicts
.
isEmpty
())
{
if
(
conflicts
==
null
||
conflicts
.
isEmpty
())
{
return
;
return
;
}
}
ExamAdminDetailVO
conflict
=
conflicts
.
get
(
0
);
ExamAdminDetailVO
conflict
=
conflicts
.
get
(
0
);
populateTeacherAssignments
(
conflicts
);
String
conflictName
=
trimToNull
(
conflict
.
getName
())
==
null
?
"未命名考试"
:
conflict
.
getName
();
String
conflictName
=
trimToNull
(
conflict
.
getName
())
==
null
?
"未命名考试"
:
conflict
.
getName
();
if
(
classId
.
equals
(
conflict
.
getClassId
()))
{
if
(
classId
.
equals
(
conflict
.
getClassId
()))
{
throw
new
BusinessException
(
"与本班考试“"
+
conflictName
+
"”时间冲突"
);
throw
new
BusinessException
(
"与本班考试“"
+
conflictName
+
"”时间冲突"
);
}
}
if
(
teacherMatches
(
conflict
,
chiefId
))
{
if
(
teacherMatches
(
conflict
,
chiefId
s
))
{
throw
new
BusinessException
(
"首席考评员与考试“"
+
conflictName
+
"”时间冲突"
);
throw
new
BusinessException
(
"首席考评员与考试“"
+
conflictName
+
"”时间冲突"
);
}
}
if
(
teacherMatches
(
conflict
,
invigilatorId
))
{
if
(
teacherMatches
(
conflict
,
invigilatorId
s
))
{
throw
new
BusinessException
(
"监考教师与考试“"
+
conflictName
+
"”时间冲突"
);
throw
new
BusinessException
(
"监考教师与考试“"
+
conflictName
+
"”时间冲突"
);
}
}
throw
new
BusinessException
(
"应考学员与考试“"
+
conflictName
+
"”时间冲突"
);
throw
new
BusinessException
(
"应考学员与考试“"
+
conflictName
+
"”时间冲突"
);
}
}
private
boolean
teacherMatches
(
ExamAdminDetailVO
conflict
,
String
teacherId
)
{
private
boolean
teacherMatches
(
ExamAdminDetailVO
conflict
,
List
<
String
>
teacherIds
)
{
if
(
teacherId
.
equals
(
conflict
.
getChiefExaminerId
()))
{
Set
<
String
>
conflictTeachers
=
new
HashSet
<>();
return
true
;
if
(
conflict
.
getChiefExaminerIds
()
!=
null
)
{
conflictTeachers
.
addAll
(
conflict
.
getChiefExaminerIds
());
}
}
String
stored
=
trimToNull
(
conflict
.
getInvigilatorId
());
if
(
conflict
.
getInvigilatorIds
()
!=
null
)
{
if
(
stored
==
null
)
{
conflictTeachers
.
addAll
(
conflict
.
getInvigilatorIds
());
return
false
;
}
}
for
(
String
value
:
stored
.
split
(
","
)
)
{
for
(
String
teacherId
:
teacherIds
)
{
if
(
teacherId
.
equals
(
value
.
trim
()
))
{
if
(
conflictTeachers
.
contains
(
teacherId
))
{
return
true
;
return
true
;
}
}
}
}
...
@@ -441,6 +520,163 @@ public class ExamAdminServiceImpl implements ExamAdminService {
...
@@ -441,6 +520,163 @@ public class ExamAdminServiceImpl implements ExamAdminService {
return
existing
;
return
existing
;
}
}
/**
* 新数组字段非null时具有最高优先级;否则读取旧单值字段,编辑请求两者都未传时才保留
* 数据库现有关系。该顺序可以区分“旧客户端没有数组字段”和“新客户端显式提交空数组”。
*/
private
List
<
String
>
normalizeTeacherIds
(
List
<
String
>
submitted
,
String
legacyValue
,
List
<
String
>
existing
,
String
fieldName
)
{
List
<
String
>
source
;
if
(
submitted
!=
null
)
{
source
=
submitted
;
}
else
if
(
trimToNull
(
legacyValue
)
!=
null
)
{
source
=
splitLegacyIds
(
legacyValue
);
}
else
{
source
=
existing
==
null
?
Collections
.
emptyList
()
:
existing
;
}
if
(
source
.
isEmpty
())
{
throw
new
BusinessException
(
fieldName
+
"至少选择一人"
);
}
LinkedHashSet
<
String
>
normalized
=
new
LinkedHashSet
<>();
for
(
String
value
:
source
)
{
normalized
.
add
(
requireText
(
value
,
fieldName
+
"ID"
,
64
));
}
return
new
ArrayList
<>(
normalized
);
}
private
List
<
String
>
splitLegacyIds
(
String
stored
)
{
String
normalized
=
trimToNull
(
stored
);
if
(
normalized
==
null
)
{
return
Collections
.
emptyList
();
}
List
<
String
>
values
=
new
ArrayList
<>();
for
(
String
value
:
normalized
.
split
(
","
))
{
if
(
trimToNull
(
value
)
!=
null
)
{
values
.
add
(
value
.
trim
());
}
}
return
values
;
}
/** 在考试主记录成功写入后一次批量保存两类人员,事务失败时与考试一并回滚。 */
private
void
saveTeacherAssignments
(
Integer
examId
,
List
<
String
>
chiefIds
,
List
<
String
>
invigilatorIds
)
{
List
<
ExamTeacherAssignmentEntity
>
assignments
=
new
ArrayList
<>();
appendAssignments
(
assignments
,
examId
,
chiefIds
,
TEACHER_ROLE_CHIEF
);
appendAssignments
(
assignments
,
examId
,
invigilatorIds
,
TEACHER_ROLE_INVIGILATOR
);
if
(
examTeacherAssignmentMapper
.
insertBatch
(
assignments
)
!=
assignments
.
size
())
{
throw
new
BusinessException
(
"考试教师关系保存失败,请稍后重试"
);
}
}
private
void
appendAssignments
(
List
<
ExamTeacherAssignmentEntity
>
target
,
Integer
examId
,
List
<
String
>
teacherIds
,
String
role
)
{
for
(
int
index
=
0
;
index
<
teacherIds
.
size
();
index
++)
{
ExamTeacherAssignmentEntity
assignment
=
new
ExamTeacherAssignmentEntity
();
assignment
.
setExamId
(
examId
);
assignment
.
setTeacherId
(
teacherIds
.
get
(
index
));
assignment
.
setRole
(
role
);
assignment
.
setDisplayOrder
(
index
);
target
.
add
(
assignment
);
}
}
private
List
<
String
>
currentTeacherIds
(
Integer
examId
,
String
role
,
String
legacyValue
)
{
List
<
ExamTeacherAssignmentEntity
>
assignments
=
examTeacherAssignmentMapper
.
selectByExamIds
(
Collections
.
singletonList
(
examId
));
List
<
String
>
result
=
new
ArrayList
<>();
if
(
assignments
!=
null
)
{
for
(
ExamTeacherAssignmentEntity
assignment
:
assignments
)
{
if
(
role
.
equals
(
assignment
.
getRole
()))
{
result
.
add
(
assignment
.
getTeacherId
());
}
}
}
return
result
.
isEmpty
()
?
splitLegacyIds
(
legacyValue
)
:
result
;
}
/**
* 管理端响应同时返回完整数组和旧单值字段。关系表没有记录的历史考试从旧字段回退,
* 展示名再使用有效教师选项补齐,避免逗号分隔历史数据与user表直接关联失败。
*/
private
void
populateTeacherAssignments
(
List
<
ExamAdminDetailVO
>
exams
)
{
if
(
exams
==
null
||
exams
.
isEmpty
())
{
return
;
}
List
<
Integer
>
examIds
=
new
ArrayList
<>();
for
(
ExamAdminDetailVO
exam
:
exams
)
{
examIds
.
add
(
exam
.
getId
());
}
List
<
ExamTeacherAssignmentEntity
>
assignments
=
examTeacherAssignmentMapper
.
selectByExamIds
(
examIds
);
Map
<
Integer
,
List
<
ExamTeacherAssignmentEntity
>>
byExam
=
new
HashMap
<>();
if
(
assignments
!=
null
)
{
for
(
ExamTeacherAssignmentEntity
assignment
:
assignments
)
{
byExam
.
computeIfAbsent
(
assignment
.
getExamId
(),
key
->
new
ArrayList
<>())
.
add
(
assignment
);
}
}
Map
<
String
,
String
>
teacherNames
=
new
HashMap
<>();
if
(
assignments
!=
null
)
{
for
(
ExamTeacherAssignmentEntity
assignment
:
assignments
)
{
if
(
trimToNull
(
assignment
.
getTeacherName
())
!=
null
)
{
teacherNames
.
put
(
assignment
.
getTeacherId
(),
assignment
.
getTeacherName
());
}
}
}
List
<
ClassAdminOptionVO
>
teacherOptions
=
examMapper
.
selectAdminExamTeacherOptions
();
if
(
teacherOptions
!=
null
)
{
for
(
ClassAdminOptionVO
option
:
teacherOptions
)
{
teacherNames
.
put
(
option
.
getValue
(),
option
.
getLabel
());
}
}
for
(
ExamAdminDetailVO
exam
:
exams
)
{
List
<
String
>
chiefIds
=
assignmentIds
(
byExam
.
get
(
exam
.
getId
()),
TEACHER_ROLE_CHIEF
);
List
<
String
>
invigilatorIds
=
assignmentIds
(
byExam
.
get
(
exam
.
getId
()),
TEACHER_ROLE_INVIGILATOR
);
if
(
chiefIds
.
isEmpty
())
{
chiefIds
=
splitLegacyIds
(
exam
.
getChiefExaminerId
());
}
if
(
invigilatorIds
.
isEmpty
())
{
invigilatorIds
=
splitLegacyIds
(
exam
.
getInvigilatorId
());
}
exam
.
setChiefExaminerIds
(
chiefIds
);
exam
.
setInvigilatorIds
(
invigilatorIds
);
exam
.
setChiefExaminers
(
toTeacherOptions
(
chiefIds
,
teacherNames
));
exam
.
setInvigilators
(
toTeacherOptions
(
invigilatorIds
,
teacherNames
));
exam
.
setChiefExaminerId
(
chiefIds
.
isEmpty
()
?
null
:
chiefIds
.
get
(
0
));
exam
.
setInvigilatorId
(
invigilatorIds
.
isEmpty
()
?
null
:
invigilatorIds
.
get
(
0
));
exam
.
setChiefExaminerName
(
firstName
(
chiefIds
,
teacherNames
));
exam
.
setInvigilatorName
(
firstName
(
invigilatorIds
,
teacherNames
));
}
}
private
List
<
String
>
assignmentIds
(
List
<
ExamTeacherAssignmentEntity
>
assignments
,
String
role
)
{
List
<
String
>
ids
=
new
ArrayList
<>();
if
(
assignments
!=
null
)
{
for
(
ExamTeacherAssignmentEntity
assignment
:
assignments
)
{
if
(
role
.
equals
(
assignment
.
getRole
()))
{
ids
.
add
(
assignment
.
getTeacherId
());
}
}
}
return
ids
;
}
private
List
<
ClassAdminOptionVO
>
toTeacherOptions
(
List
<
String
>
ids
,
Map
<
String
,
String
>
names
)
{
List
<
ClassAdminOptionVO
>
result
=
new
ArrayList
<>();
for
(
String
id
:
ids
)
{
result
.
add
(
new
ClassAdminOptionVO
(
id
,
names
.
getOrDefault
(
id
,
id
),
null
,
null
));
}
return
result
;
}
private
String
firstName
(
List
<
String
>
ids
,
Map
<
String
,
String
>
names
)
{
return
ids
.
isEmpty
()
?
null
:
names
.
getOrDefault
(
ids
.
get
(
0
),
ids
.
get
(
0
));
}
private
ExamAdminClassVO
requireManagedClass
(
Integer
classId
)
{
private
ExamAdminClassVO
requireManagedClass
(
Integer
classId
)
{
ExamAdminClassVO
managedClass
=
examMapper
.
selectAdminExamClass
(
classId
);
ExamAdminClassVO
managedClass
=
examMapper
.
selectAdminExamClass
(
classId
);
if
(
managedClass
==
null
)
{
if
(
managedClass
==
null
)
{
...
@@ -639,10 +875,11 @@ public class ExamAdminServiceImpl implements ExamAdminService {
...
@@ -639,10 +875,11 @@ public class ExamAdminServiceImpl implements ExamAdminService {
private
Date
examTime
;
private
Date
examTime
;
private
int
duration
;
private
int
duration
;
private
int
forbid
;
private
int
forbid
;
private
String
chiefId
;
private
List
<
String
>
chiefId
s
;
private
String
invigilatorId
;
private
List
<
String
>
invigilatorId
s
;
private
String
location
;
private
String
location
;
private
TheoreticalPaperEntity
paper
;
private
TheoreticalPaperEntity
paper
;
private
Integer
practiceRuleId
;
private
BigDecimal
totalScore
;
private
BigDecimal
totalScore
;
private
BigDecimal
passScore
;
private
BigDecimal
passScore
;
}
}
...
@@ -653,7 +890,10 @@ public class ExamAdminServiceImpl implements ExamAdminService {
...
@@ -653,7 +890,10 @@ public class ExamAdminServiceImpl implements ExamAdminService {
private
String
type
;
private
String
type
;
private
Date
examTime
;
private
Date
examTime
;
private
int
duration
;
private
int
duration
;
private
String
chiefId
;
private
List
<
String
>
chiefIds
;
private
List
<
String
>
invigilatorIds
;
private
Integer
practiceRuleId
;
private
BigDecimal
totalScore
;
private
String
location
;
private
String
location
;
private
BigDecimal
passScore
;
private
BigDecimal
passScore
;
}
}
...
...
practical-business/src/main/java/com/platform/business/service/impl/ExamStaudentServiceImpl.java
View file @
66392f2e
...
@@ -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
);
...
...
practical-business/src/main/java/com/platform/business/service/impl/PracticePaperRuleServiceImpl.java
View file @
66392f2e
package
com.platform.business.service.impl
;
package
com.platform.business.service.impl
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
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.mapper.PracticePaperRuleMapper
;
import
com.platform.business.model.dto.PracticePaperRuleItemDTO
;
import
com.platform.business.model.dto.PracticePaperRuleItemDTO
;
import
com.platform.business.model.dto.PracticePaperRuleQueryDTO
;
import
com.platform.business.model.dto.PracticePaperRuleSaveDTO
;
import
com.platform.business.model.dto.PracticePaperRuleSaveDTO
;
import
com.platform.business.model.entity.PracticePaperRuleDefinitionEntity
;
import
com.platform.business.model.entity.PracticePaperRuleDetailEntity
;
import
com.platform.business.model.entity.PracticePaperRuleEntity
;
import
com.platform.business.model.entity.PracticePaperRuleEntity
;
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
com.platform.business.model.vo.PracticePaperRuleItemVO
;
import
com.platform.business.service.PracticePaperRuleService
;
import
com.platform.business.service.PracticePaperRuleService
;
import
com.platform.exception.BusinessException
;
import
com.platform.exception.BusinessException
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.StringUtils
;
import
javax.annotation.Resource
;
import
java.math.BigDecimal
;
import
java.math.BigDecimal
;
import
java.math.RoundingMode
;
import
java.math.RoundingMode
;
...
@@ -19,197 +25,408 @@ import java.util.ArrayList;
...
@@ -19,197 +25,408 @@ import java.util.ArrayList;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.HashSet
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.Set
;
/**
/**
*
实操规则核心
业务实现。
*
具名实操试卷规则
业务实现。
*
*
* <p>
污水一级、污泥一级等业务职级统一截取末尾“一级”匹配 Excel 类目,因此不同
* <p>
{@code practice_paper_rule}只承担标准类目目录职责;每一套可发布规则分别写入主表和
*
工种共用同等级规则。规则保存采用完整列表覆盖,但标准项目和单元内容始终以数据库
*
明细表。发布后规则不可编辑,被考试引用后不可删除,从而保证考试保存的规则引用和总分
*
种子数据为准,客户端仅能修改时间、配分和题量
。</p>
*
快照始终能还原同一套业务配置
。</p>
*/
*/
@Service
@Service
public
class
PracticePaperRuleServiceImpl
public
class
PracticePaperRuleServiceImpl
implements
PracticePaperRuleService
{
extends
ServiceImpl
<
PracticePaperRuleMapper
,
PracticePaperRuleEntity
>
implements
PracticePaperRuleService
{
public
static
final
String
STATUS_DRAFT
=
"DRAFT"
;
public
static
final
String
STATUS_PUBLISHED
=
"PUBLISHED"
;
/** 经业务确认的五个标准等级;固定数组顺序保证匹配与错误提示口径稳定。 */
private
static
final
List
<
String
>
GRADES
=
Collections
.
unmodifiableList
(
private
static
final
List
<
String
>
GRADES
=
Collections
.
unmodifiableList
(
Arrays
.
asList
(
"一级"
,
"二级"
,
"三级"
,
"四级"
,
"五级"
));
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_TOTAL_QUESTION_COUNT
=
5
;
private
static
final
int
MAX_DURATION
=
600
;
private
static
final
int
MAX_DURATION
=
600
;
private
static
final
BigDecimal
MAX_SCORE
=
new
BigDecimal
(
"99999.99"
);
private
static
final
BigDecimal
MAX_SCORE
=
new
BigDecimal
(
"99999.99"
);
@Resource
private
PracticePaperRuleMapper
ruleMapper
;
@Override
@Override
@Transactional
(
readOnly
=
true
)
@Transactional
(
readOnly
=
true
)
public
PracticePaperRuleConfigurationVO
configuration
(
String
level
)
{
public
List
<
PracticePaperRuleConfigurationVO
>
queryPage
(
PracticePaperRuleQueryDTO
query
)
{
String
grade
=
normalizeGrade
(
level
);
PracticePaperRuleQueryDTO
safe
=
query
==
null
?
new
PracticePaperRuleQueryDTO
()
:
query
;
List
<
PracticePaperRuleEntity
>
rows
=
list
(
new
LambdaQueryWrapper
<
PracticePaperRuleEntity
>()
safe
.
setName
(
optionalText
(
safe
.
getName
(),
"规则名称"
,
200
));
.
eq
(
PracticePaperRuleEntity:
:
getLevelGrade
,
grade
)
if
(
StringUtils
.
hasText
(
safe
.
getLev
()))
{
.
orderByAsc
(
PracticePaperRuleEntity:
:
getId
));
safe
.
setLev
(
normalizeGrade
(
safe
.
getLev
()));
requireCatalog
(
grade
,
rows
);
}
return
assemble
(
level
,
grade
,
rows
,
false
);
if
(
StringUtils
.
hasText
(
safe
.
getStatus
()))
{
safe
.
setStatus
(
normalizeStatus
(
safe
.
getStatus
()));
}
List
<
PracticePaperRuleConfigurationVO
>
rows
=
ruleMapper
.
pageDefinitions
(
safe
);
if
(
rows
==
null
)
{
return
Collections
.
emptyList
();
}
for
(
PracticePaperRuleConfigurationVO
row
:
rows
)
{
decorate
(
row
);
}
return
rows
;
}
}
@Override
@Override
@Transactional
(
readOnly
=
true
)
@Transactional
(
readOnly
=
true
)
public
PracticePaperRule
ConfigurationVO
effectiveConfiguration
(
String
level
)
{
public
List
<
PracticePaperRule
ItemVO
>
catalog
(
String
level
)
{
String
grade
=
normalizeGrade
(
level
);
String
grade
=
normalizeGrade
(
level
);
List
<
PracticePaperRuleEntity
>
rows
=
list
(
new
LambdaQueryWrapper
<
PracticePaperRuleEntity
>()
List
<
PracticePaperRuleEntity
>
catalog
=
ruleMapper
.
selectList
(
.
eq
(
PracticePaperRuleEntity:
:
getLevelGrade
,
grade
)
new
LambdaQueryWrapper
<
PracticePaperRuleEntity
>()
.
gt
(
PracticePaperRuleEntity:
:
getQuestionCount
,
0
)
.
eq
(
PracticePaperRuleEntity:
:
getLevelGrade
,
grade
)
.
orderByAsc
(
PracticePaperRuleEntity:
:
getId
));
.
orderByAsc
(
PracticePaperRuleEntity:
:
getId
));
// recent只返回已选类目,但空结果仍表示该等级尚未完成有效配置,应明确报错。
if
(
catalog
==
null
||
catalog
.
isEmpty
())
{
if
(
rows
==
null
||
rows
.
isEmpty
())
{
throw
new
BusinessException
(
grade
+
"实操标准类目不存在,请先执行数据库迁移脚本"
);
throw
new
BusinessException
(
grade
+
"实操组卷规则尚未配置考核题量"
);
}
}
List
<
PracticePaperRuleItemVO
>
result
=
new
ArrayList
<>(
catalog
.
size
());
PracticePaperRuleConfigurationVO
result
=
assemble
(
level
,
grade
,
rows
,
true
);
for
(
PracticePaperRuleEntity
row
:
catalog
)
{
validateTotalQuestionCount
(
result
.
getTotalQuestionCount
());
PracticePaperRuleItemVO
item
=
new
PracticePaperRuleItemVO
();
item
.
setCatalogId
(
row
.
getId
());
item
.
setProjectName
(
row
.
getProjectName
());
item
.
setUnitContent
(
row
.
getUnitContent
());
item
.
setAssessmentDuration
(
row
.
getAssessmentDuration
());
item
.
setScore
(
row
.
getScore
());
item
.
setQuestionCount
(
row
.
getQuestionCount
());
int
count
=
row
.
getQuestionCount
()
==
null
?
0
:
row
.
getQuestionCount
();
int
duration
=
row
.
getAssessmentDuration
()
==
null
?
0
:
row
.
getAssessmentDuration
();
BigDecimal
score
=
row
.
getScore
()
==
null
?
BigDecimal
.
ZERO
:
row
.
getScore
();
item
.
setSubtotalDuration
(
duration
*
count
);
item
.
setSubtotalScore
(
score
.
multiply
(
BigDecimal
.
valueOf
(
count
))
.
setScale
(
2
,
RoundingMode
.
HALF_UP
));
result
.
add
(
item
);
}
return
result
;
return
result
;
}
}
@Override
@Transactional
(
readOnly
=
true
)
public
PracticePaperRuleConfigurationVO
detail
(
Integer
ruleId
)
{
requirePositiveId
(
ruleId
,
"规则ID"
);
PracticePaperRuleDefinitionEntity
definition
=
ruleMapper
.
selectDefinition
(
ruleId
);
if
(
definition
==
null
)
{
throw
new
BusinessException
(
"实操试卷规则不存在或已删除"
);
}
return
assemble
(
definition
,
false
);
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
PracticePaperRuleConfigurationVO
create
(
PracticePaperRuleSaveDTO
request
,
String
operatorId
)
{
PreparedRule
prepared
=
prepare
(
request
,
operatorId
);
ensureUniqueName
(
prepared
.
grade
,
prepared
.
name
,
null
);
Date
now
=
new
Date
();
PracticePaperRuleDefinitionEntity
definition
=
definition
(
prepared
,
operatorId
,
now
);
definition
.
setStatus
(
STATUS_DRAFT
);
definition
.
setCreatedBy
(
operatorId
);
definition
.
setCreatedTime
(
now
);
if
(
ruleMapper
.
insertDefinition
(
definition
)
!=
1
||
definition
.
getId
()
==
null
)
{
throw
new
BusinessException
(
"实操试卷规则创建失败,请稍后重试"
);
}
bindRuleId
(
prepared
.
details
,
definition
.
getId
());
insertDetails
(
prepared
.
details
);
return
detail
(
definition
.
getId
());
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
PracticePaperRuleConfigurationVO
update
(
Integer
ruleId
,
PracticePaperRuleSaveDTO
request
,
String
operatorId
)
{
requirePositiveId
(
ruleId
,
"规则ID"
);
PracticePaperRuleDefinitionEntity
existing
=
lock
(
ruleId
);
if
(!
STATUS_DRAFT
.
equals
(
existing
.
getStatus
()))
{
throw
new
BusinessException
(
"已发布实操试卷规则不能编辑"
);
}
PreparedRule
prepared
=
prepare
(
request
,
operatorId
);
ensureUniqueName
(
prepared
.
grade
,
prepared
.
name
,
ruleId
);
PracticePaperRuleDefinitionEntity
update
=
definition
(
prepared
,
operatorId
,
new
Date
());
update
.
setId
(
ruleId
);
if
(
ruleMapper
.
updateDefinition
(
update
)
!=
1
)
{
throw
new
BusinessException
(
"实操试卷规则状态已变化,请刷新后重试"
);
}
ruleMapper
.
deleteDefinitionDetails
(
ruleId
);
bindRuleId
(
prepared
.
details
,
ruleId
);
insertDetails
(
prepared
.
details
);
return
detail
(
ruleId
);
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
PracticePaperRuleConfigurationVO
publish
(
Integer
ruleId
,
String
status
,
String
operatorId
)
{
requirePositiveId
(
ruleId
,
"规则ID"
);
String
target
=
normalizeStatus
(
status
);
if
(!
STATUS_PUBLISHED
.
equals
(
target
))
{
throw
new
BusinessException
(
"实操试卷规则只支持发布为PUBLISHED状态"
);
}
PracticePaperRuleDefinitionEntity
existing
=
lock
(
ruleId
);
if
(!
STATUS_DRAFT
.
equals
(
existing
.
getStatus
()))
{
throw
new
BusinessException
(
"只有草稿状态的实操试卷规则可以发布"
);
}
// 保存草稿时已经执行完整校验;发布前仍核对明细,防止人工改库产生空规则。
List
<
PracticePaperRuleItemVO
>
details
=
ruleMapper
.
selectDefinitionDetails
(
ruleId
);
if
(
details
==
null
||
details
.
isEmpty
()
||
existing
.
getQuestionCount
()
==
null
||
existing
.
getQuestionCount
()
<
1
||
existing
.
getQuestionCount
()
>
MAX_TOTAL_QUESTION_COUNT
)
{
throw
new
BusinessException
(
"实操试卷规则明细不完整,不能发布"
);
}
String
normalizedOperator
=
requireText
(
operatorId
,
"操作人ID"
,
64
);
if
(
ruleMapper
.
updateDefinitionStatus
(
ruleId
,
target
,
normalizedOperator
,
new
Date
())
!=
1
)
{
throw
new
BusinessException
(
"实操试卷规则状态已变化,请刷新后重试"
);
}
return
detail
(
ruleId
);
}
@Override
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
PracticePaperRuleConfigurationVO
saveConfiguration
(
PracticePaperRuleSaveDTO
request
,
public
boolean
delete
(
Integer
ruleId
)
{
String
updaterId
)
{
requirePositiveId
(
ruleId
,
"规则ID"
);
lock
(
ruleId
);
if
(
ruleMapper
.
countDefinitionUsage
(
ruleId
)
>
0
)
{
throw
new
BusinessException
(
"实操试卷规则已被考试使用,不能删除"
);
}
ruleMapper
.
deleteDefinitionDetails
(
ruleId
);
if
(
ruleMapper
.
deleteDefinition
(
ruleId
)
!=
1
)
{
throw
new
BusinessException
(
"实操试卷规则删除失败,请刷新后重试"
);
}
return
true
;
}
@Override
@Transactional
(
readOnly
=
true
)
public
PracticePaperRuleConfigurationVO
effectiveConfiguration
(
Integer
ruleId
)
{
requirePositiveId
(
ruleId
,
"实操试卷规则ID"
);
PracticePaperRuleDefinitionEntity
definition
=
ruleMapper
.
selectPublishedDefinition
(
ruleId
);
if
(
definition
==
null
)
{
throw
new
BusinessException
(
"考试关联的实操试卷规则不存在或未发布"
);
}
return
assemble
(
definition
,
true
);
}
@Override
@Transactional
(
readOnly
=
true
)
public
List
<
ClassAdminOptionVO
>
publishedOptions
(
String
level
)
{
List
<
ClassAdminOptionVO
>
options
=
ruleMapper
.
selectPublishedOptions
(
normalizeGrade
(
level
));
return
options
==
null
?
Collections
.
emptyList
()
:
options
;
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
PracticePaperRuleDefinitionEntity
requirePublishedDefinition
(
Integer
ruleId
,
String
level
)
{
requirePositiveId
(
ruleId
,
"实操试卷规则ID"
);
/*
* 考试创建与规则删除必须锁定同一条规则主记录。否则“删除已确认usageCount为0”与
* “考试刚读取到已发布规则”可能并发穿透,最终留下指向已删除规则的考试。
*/
PracticePaperRuleDefinitionEntity
definition
=
ruleMapper
.
lockDefinition
(
ruleId
);
if
(
definition
==
null
||
!
STATUS_PUBLISHED
.
equals
(
definition
.
getStatus
()))
{
throw
new
BusinessException
(
"所选实操试卷规则不存在、已删除或尚未发布"
);
}
String
grade
=
normalizeGrade
(
level
);
if
(!
grade
.
equals
(
definition
.
getLevelGrade
()))
{
throw
new
BusinessException
(
"所选实操试卷规则与班级职业等级不匹配"
);
}
if
(
definition
.
getTotalScore
()
==
null
||
definition
.
getTotalScore
().
compareTo
(
BigDecimal
.
ZERO
)
<=
0
)
{
throw
new
BusinessException
(
"所选实操试卷规则总分无效"
);
}
return
definition
;
}
/**
* 保存请求必须完整回传该等级的全部标准类目。这样服务端可以分辨“题量为0”与“漏传”,
* 也能阻止客户端把其他等级的目录项混入当前规则。
*/
private
PreparedRule
prepare
(
PracticePaperRuleSaveDTO
request
,
String
operatorId
)
{
if
(
request
==
null
)
{
if
(
request
==
null
)
{
throw
new
BusinessException
(
"实操
组卷配置
不能为空"
);
throw
new
BusinessException
(
"实操
试卷规则
不能为空"
);
}
}
String
name
=
requireText
(
request
.
getName
(),
"规则名称"
,
200
);
String
grade
=
normalizeGrade
(
request
.
getLev
());
String
grade
=
normalizeGrade
(
request
.
getLev
());
String
normalizedUpdater
=
requireText
(
updaterId
,
"更新人ID"
,
64
);
requireText
(
operatorId
,
"操作人ID"
,
64
);
List
<
PracticePaperRuleEntity
>
stored
=
baseMapper
.
selectByGradeForUpdate
(
grade
);
List
<
PracticePaperRuleEntity
>
catalog
=
ruleMapper
.
selectList
(
requireCatalog
(
grade
,
stored
);
new
LambdaQueryWrapper
<
PracticePaperRuleEntity
>()
.
eq
(
PracticePaperRuleEntity:
:
getLevelGrade
,
grade
)
.
orderByAsc
(
PracticePaperRuleEntity:
:
getId
));
if
(
catalog
==
null
||
catalog
.
isEmpty
())
{
throw
new
BusinessException
(
grade
+
"实操标准类目不存在,请先执行数据库迁移脚本"
);
}
List
<
PracticePaperRuleItemDTO
>
submitted
=
request
.
getRuleList
();
List
<
PracticePaperRuleItemDTO
>
submitted
=
request
.
getRuleList
();
if
(
submitted
==
null
||
submitted
.
size
()
!=
stored
.
size
())
{
if
(
submitted
==
null
||
submitted
.
size
()
!=
catalog
.
size
())
{
throw
new
BusinessException
(
"必须提交"
+
grade
+
"全部"
+
stored
.
size
()
+
"条标准类目规则"
);
throw
new
BusinessException
(
"必须提交"
+
grade
+
"全部"
+
catalog
.
size
()
+
"条标准类目规则"
);
}
}
Map
<
Integer
,
PracticePaperRuleItemDTO
>
submittedBy
Id
=
new
Linked
HashMap
<>();
Map
<
Integer
,
PracticePaperRuleItemDTO
>
byCatalog
Id
=
new
HashMap
<>();
for
(
PracticePaperRuleItemDTO
item
:
submitted
)
{
for
(
PracticePaperRuleItemDTO
item
:
submitted
)
{
if
(
item
==
null
||
item
.
getId
()
==
null
||
item
.
getId
()
<=
0
)
{
if
(
item
==
null
||
item
.
get
Catalog
Id
()
==
null
||
item
.
get
Catalog
Id
()
<=
0
)
{
throw
new
BusinessException
(
"
实操规则
ID必须为正整数"
);
throw
new
BusinessException
(
"
标准类目
ID必须为正整数"
);
}
}
if
(
submittedBy
Id
.
put
(
item
.
getId
(),
item
)
!=
null
)
{
if
(
byCatalog
Id
.
put
(
item
.
get
Catalog
Id
(),
item
)
!=
null
)
{
throw
new
BusinessException
(
"
实操规则
不能重复提交"
);
throw
new
BusinessException
(
"
同一标准类目
不能重复提交"
);
}
}
}
}
int
totalQuestionCount
=
0
;
PreparedRule
result
=
new
PreparedRule
();
Date
now
=
new
Date
();
result
.
name
=
name
;
Set
<
Integer
>
storedIds
=
new
HashSet
<>();
result
.
grade
=
grade
;
for
(
PracticePaperRuleEntity
row
:
stored
)
{
result
.
details
=
new
ArrayList
<>(
catalog
.
size
());
storedIds
.
add
(
row
.
getId
());
result
.
totalScore
=
BigDecimal
.
ZERO
;
PracticePaperRuleItemDTO
item
=
submittedById
.
get
(
row
.
getId
());
Set
<
Integer
>
catalogIds
=
new
HashSet
<>();
for
(
PracticePaperRuleEntity
catalogItem
:
catalog
)
{
catalogIds
.
add
(
catalogItem
.
getId
());
PracticePaperRuleItemDTO
item
=
byCatalogId
.
get
(
catalogItem
.
getId
());
if
(
item
==
null
)
{
if
(
item
==
null
)
{
throw
new
BusinessException
(
"提交内容缺少标准类目:"
+
row
.
getProjectName
()
throw
new
BusinessException
(
"提交内容缺少标准类目:"
+
catalogItem
.
getProjectName
()
+
" / "
+
row
.
getUnitContent
());
+
" / "
+
catalogItem
.
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
(
"实操组卷规则保存失败,请稍后重试"
);
}
}
int
duration
=
normalizeDuration
(
item
.
getAssessmentDuration
());
BigDecimal
score
=
normalizeScore
(
item
.
getScore
());
int
count
=
normalizeQuestionCount
(
item
.
getQuestionCount
());
PracticePaperRuleDetailEntity
detail
=
new
PracticePaperRuleDetailEntity
();
detail
.
setCatalogId
(
catalogItem
.
getId
());
detail
.
setAssessmentDuration
(
duration
);
detail
.
setScore
(
score
);
detail
.
setQuestionCount
(
count
);
result
.
details
.
add
(
detail
);
result
.
totalQuestionCount
+=
count
;
result
.
totalDuration
+=
duration
*
count
;
result
.
totalScore
=
result
.
totalScore
.
add
(
score
.
multiply
(
BigDecimal
.
valueOf
(
count
)));
}
}
return
assemble
(
request
.
getLev
(),
grade
,
stored
,
false
);
if
(!
catalogIds
.
equals
(
byCatalogId
.
keySet
()))
{
}
throw
new
BusinessException
(
"提交内容包含不属于"
+
grade
+
"的标准类目"
);
/** 将“污水一级”“污泥一级”以及直接传入的“一级”统一为Excel中的标准等级。 */
String
normalizeGrade
(
String
level
)
{
String
normalized
=
requireText
(
level
,
"职级"
,
32
);
for
(
String
grade
:
GRADES
)
{
if
(
normalized
.
endsWith
(
grade
))
{
return
grade
;
}
}
}
throw
new
BusinessException
(
"实操职级必须以一级、二级、三级、四级或五级结尾"
);
if
(
result
.
totalQuestionCount
<
1
||
result
.
totalQuestionCount
>
MAX_TOTAL_QUESTION_COUNT
)
{
throw
new
BusinessException
(
"考核总题数必须在1到5题之间"
);
}
result
.
totalScore
=
result
.
totalScore
.
setScale
(
2
,
RoundingMode
.
HALF_UP
);
return
result
;
}
}
/** 数据库没有执行配套SQL时及时给出可操作提示,而不是返回一个看似有效的空配置。 */
private
PracticePaperRuleDefinitionEntity
definition
(
PreparedRule
prepared
,
String
operatorId
,
private
void
requireCatalog
(
String
grade
,
List
<
PracticePaperRuleEntity
>
rows
)
{
Date
now
)
{
if
(
rows
==
null
||
rows
.
isEmpty
())
{
PracticePaperRuleDefinitionEntity
result
=
new
PracticePaperRuleDefinitionEntity
();
throw
new
BusinessException
(
grade
+
"实操类目不存在,请先执行实操组卷规则SQL脚本"
);
result
.
setName
(
prepared
.
name
);
}
result
.
setLevelGrade
(
prepared
.
grade
);
result
.
setQuestionCount
(
prepared
.
totalQuestionCount
);
result
.
setTotalDuration
(
prepared
.
totalDuration
);
result
.
setTotalScore
(
prepared
.
totalScore
);
result
.
setUpdatedBy
(
operatorId
);
result
.
setUpdatedTime
(
now
);
return
result
;
}
}
private
PracticePaperRuleConfigurationVO
assemble
(
String
level
,
String
grade
,
private
PracticePaperRuleConfigurationVO
assemble
(
PracticePaperRuleDefinitionEntity
definition
,
List
<
PracticePaperRuleEntity
>
rows
,
boolean
effectiveOnly
)
{
boolean
effectiveOnly
)
{
List
<
PracticePaperRuleItemVO
>
stored
=
ruleMapper
.
selectDefinitionDetails
(
definition
.
getId
());
List
<
PracticePaperRuleItemVO
>
items
=
new
ArrayList
<>();
List
<
PracticePaperRuleItemVO
>
items
=
new
ArrayList
<>();
int
totalCount
=
0
;
if
(
stored
!=
null
)
{
int
totalDuration
=
0
;
for
(
PracticePaperRuleItemVO
item
:
stored
)
{
BigDecimal
totalScore
=
BigDecimal
.
ZERO
;
if
(!
effectiveOnly
||
(
item
.
getQuestionCount
()
!=
null
&&
item
.
getQuestionCount
()
>
0
))
{
for
(
PracticePaperRuleEntity
row
:
rows
)
{
if
(
item
.
getScore
()
!=
null
)
{
int
count
=
row
.
getQuestionCount
()
==
null
?
0
:
row
.
getQuestionCount
();
item
.
setScore
(
item
.
getScore
().
setScale
(
2
,
RoundingMode
.
HALF_UP
));
if
(
effectiveOnly
&&
count
<=
0
)
{
}
continue
;
if
(
item
.
getSubtotalScore
()
!=
null
)
{
item
.
setSubtotalScore
(
item
.
getSubtotalScore
().
setScale
(
2
,
RoundingMode
.
HALF_UP
));
}
items
.
add
(
item
);
}
}
}
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
();
PracticePaperRuleConfigurationVO
result
=
new
PracticePaperRuleConfigurationVO
();
result
.
setLev
(
level
==
null
?
null
:
level
.
trim
());
result
.
setId
(
definition
.
getId
());
result
.
setGrade
(
grade
);
result
.
setName
(
definition
.
getName
());
result
.
setTotalQuestionCount
(
totalCount
);
result
.
setLev
(
definition
.
getLevelGrade
());
result
.
setTotalDuration
(
totalDuration
);
result
.
setGrade
(
definition
.
getLevelGrade
());
result
.
setTotalScore
(
totalScore
.
setScale
(
2
,
RoundingMode
.
HALF_UP
));
result
.
setStatus
(
definition
.
getStatus
());
result
.
setTotalQuestionCount
(
definition
.
getQuestionCount
());
result
.
setTotalDuration
(
definition
.
getTotalDuration
());
result
.
setTotalScore
(
definition
.
getTotalScore
()
==
null
?
null
:
definition
.
getTotalScore
().
setScale
(
2
,
RoundingMode
.
HALF_UP
));
result
.
setCreatedTime
(
definition
.
getCreatedTime
());
result
.
setUpdatedTime
(
definition
.
getUpdatedTime
());
result
.
setUsageCount
(
ruleMapper
.
countDefinitionUsage
(
definition
.
getId
()));
result
.
setRuleList
(
items
);
result
.
setRuleList
(
items
);
decorate
(
result
);
return
result
;
return
result
;
}
}
private
void
decorate
(
PracticePaperRuleConfigurationVO
rule
)
{
int
usage
=
rule
.
getUsageCount
()
==
null
?
0
:
rule
.
getUsageCount
();
rule
.
setUsageCount
(
usage
);
rule
.
setStatusLabel
(
STATUS_DRAFT
.
equals
(
rule
.
getStatus
())
?
"草稿"
:
"已发布"
);
rule
.
setPublishable
(
STATUS_DRAFT
.
equals
(
rule
.
getStatus
()));
rule
.
setEditable
(
STATUS_DRAFT
.
equals
(
rule
.
getStatus
()));
rule
.
setDeletable
(
usage
==
0
);
}
private
void
ensureUniqueName
(
String
grade
,
String
name
,
Integer
excludeId
)
{
if
(
ruleMapper
.
countDuplicateDefinition
(
grade
,
name
,
excludeId
)
>
0
)
{
throw
new
BusinessException
(
"同一职级下实操试卷规则名称已存在"
);
}
}
private
PracticePaperRuleDefinitionEntity
lock
(
Integer
ruleId
)
{
PracticePaperRuleDefinitionEntity
definition
=
ruleMapper
.
lockDefinition
(
ruleId
);
if
(
definition
==
null
)
{
throw
new
BusinessException
(
"实操试卷规则不存在或已删除"
);
}
return
definition
;
}
private
void
insertDetails
(
List
<
PracticePaperRuleDetailEntity
>
details
)
{
if
(
details
.
isEmpty
()
||
ruleMapper
.
insertDefinitionDetails
(
details
)
!=
details
.
size
())
{
throw
new
BusinessException
(
"实操试卷规则明细保存失败,请稍后重试"
);
}
}
private
void
bindRuleId
(
List
<
PracticePaperRuleDetailEntity
>
details
,
Integer
ruleId
)
{
for
(
PracticePaperRuleDetailEntity
detail
:
details
)
{
detail
.
setRuleId
(
ruleId
);
}
}
String
normalizeGrade
(
String
level
)
{
String
normalized
=
requireText
(
level
,
"使用职级"
,
32
);
for
(
String
grade
:
GRADES
)
{
if
(
normalized
.
endsWith
(
grade
))
{
return
grade
;
}
}
throw
new
BusinessException
(
"使用职级必须以一级、二级、三级、四级或五级结尾"
);
}
private
String
normalizeStatus
(
String
status
)
{
String
normalized
=
requireText
(
status
,
"规则状态"
,
16
).
toUpperCase
();
if
(!
STATUS_DRAFT
.
equals
(
normalized
)
&&
!
STATUS_PUBLISHED
.
equals
(
normalized
))
{
throw
new
BusinessException
(
"规则状态只支持DRAFT或PUBLISHED"
);
}
return
normalized
;
}
private
int
normalizeDuration
(
Integer
value
)
{
private
int
normalizeDuration
(
Integer
value
)
{
int
duration
=
value
==
null
?
DEFAULT_DURATION
:
value
;
if
(
value
==
null
||
value
<=
0
||
value
>
MAX_DURATION
)
{
if
(
duration
<=
0
||
duration
>
MAX_DURATION
)
{
throw
new
BusinessException
(
"单题考核时间必须在1到600分钟之间"
);
throw
new
BusinessException
(
"单题考核时间必须在1到600分钟之间"
);
}
}
return
duration
;
return
value
;
}
}
private
BigDecimal
normalizeScore
(
BigDecimal
value
)
{
private
BigDecimal
normalizeScore
(
BigDecimal
value
)
{
BigDecimal
score
=
value
==
null
?
DEFAULT_SCORE
:
value
.
setScale
(
2
,
RoundingMode
.
HALF_UP
);
if
(
value
==
null
)
{
throw
new
BusinessException
(
"单题配分不能为空"
);
}
BigDecimal
score
=
value
.
setScale
(
2
,
RoundingMode
.
HALF_UP
);
if
(
score
.
compareTo
(
BigDecimal
.
ZERO
)
<=
0
||
score
.
compareTo
(
MAX_SCORE
)
>
0
)
{
if
(
score
.
compareTo
(
BigDecimal
.
ZERO
)
<=
0
||
score
.
compareTo
(
MAX_SCORE
)
>
0
)
{
throw
new
BusinessException
(
"单题配分必须大于0且不超过99999.99"
);
throw
new
BusinessException
(
"单题配分必须大于0且不超过99999.99"
);
}
}
...
@@ -224,21 +441,36 @@ public class PracticePaperRuleServiceImpl
...
@@ -224,21 +441,36 @@ public class PracticePaperRuleServiceImpl
return
count
;
return
count
;
}
}
/** 除“不超过五题”外要求至少一题,防止保存后recent接口没有可执行规则。 */
private
void
requirePositiveId
(
Integer
value
,
String
fieldName
)
{
private
void
validateTotalQuestionCount
(
Integer
count
)
{
if
(
value
==
null
||
value
<=
0
)
{
if
(
count
==
null
||
count
<=
0
||
count
>
MAX_TOTAL_QUESTION_COUNT
)
{
throw
new
BusinessException
(
fieldName
+
"无效"
);
throw
new
BusinessException
(
"考核总题数必须在1到5题之间"
);
}
}
}
}
private
String
requireText
(
String
value
,
String
fieldName
,
int
maxLength
)
{
private
String
requireText
(
String
value
,
String
fieldName
,
int
maxLength
)
{
String
normalized
=
value
==
null
?
null
:
value
.
trim
();
if
(!
StringUtils
.
hasText
(
value
))
{
if
(
normalized
==
null
||
normalized
.
isEmpty
())
{
throw
new
BusinessException
(
fieldName
+
"不能为空"
);
throw
new
BusinessException
(
fieldName
+
"不能为空"
);
}
}
String
normalized
=
value
.
trim
();
if
(
normalized
.
length
()
>
maxLength
)
{
if
(
normalized
.
length
()
>
maxLength
)
{
throw
new
BusinessException
(
fieldName
+
"不能超过"
+
maxLength
+
"个字符"
);
throw
new
BusinessException
(
fieldName
+
"不能超过"
+
maxLength
+
"个字符"
);
}
}
return
normalized
;
return
normalized
;
}
}
private
String
optionalText
(
String
value
,
String
fieldName
,
int
maxLength
)
{
if
(!
StringUtils
.
hasText
(
value
))
{
return
null
;
}
return
requireText
(
value
,
fieldName
,
maxLength
);
}
private
static
final
class
PreparedRule
{
private
String
name
;
private
String
grade
;
private
int
totalQuestionCount
;
private
int
totalDuration
;
private
BigDecimal
totalScore
;
private
List
<
PracticePaperRuleDetailEntity
>
details
;
}
}
}
practical-business/src/main/java/com/platform/business/service/impl/TeacherScoreServiceImpl.java
View file @
66392f2e
...
@@ -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
{
...
...
practical-business/src/main/resources/com/platform/business/mapper/ExamMapper.xml
View file @
66392f2e
...
@@ -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
<
timestampadd(minute, #{duration}, #{startTime})
where e.exam_time
<
timestampadd(minute, #{duration}, #{startTime})
and timestampadd(minute, coalesce(e.duration, 0), e.exam_time)
>
#{startTime}
and timestampadd(minute, coalesce(e.duration, 0), e.exam_time)
>
#{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, ''), ' ', ''))
>
0
not exists (
or find_in_set(#{invigilatorId}, replace(coalesce(e.invigilation_id, ''), ' ', ''))
>
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, ''), ' ', ''))
>
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}
...
...
practical-business/src/main/resources/com/platform/business/mapper/ExamReviewMapper.xml
View file @
66392f2e
...
@@ -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.chi
ef
_
id
= #{teacherId}
WHERE
<include
r
efid
=
"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.chi
ef
_
id
= #{teacherId}
AND
<include
r
efid
=
"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.chi
ef
_
id
= #{teacherId}
AND
<include
r
efid
=
"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.chi
ef
_
id
= #{teacherId}
INNER JOIN exam e ON e.id = es.exam_id AND
<include
r
efid
=
"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.chi
ef
_
id
= #{teacherId}
INNER JOIN exam e ON e.id = es.exam_id AND
<include
r
efid
=
"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.chi
ef
_
id
= #{teacherId}
INNER JOIN exam e ON e.id = es.exam_id AND
<include
r
efid
=
"chiefPermission"
/>
WHERE es.id = #{examStudentId}
WHERE es.id = #{examStudentId}
AND es.submit = 1
AND es.submit = 1
FOR UPDATE
FOR UPDATE
...
...
practical-business/src/main/resources/com/platform/business/mapper/ExamStudentMapper.xml
View file @
66392f2e
...
@@ -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, ''), ' ', ''))
>
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
...
...
practical-business/src/main/resources/com/platform/business/mapper/ExamTeacherAssignmentMapper.xml
0 → 100644
View file @
66392f2e
<?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>
practical-business/src/main/resources/com/platform/business/mapper/PracticePaperRuleMapper.xml
View file @
66392f2e
...
@@ -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
<>
#{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>
practical-business/src/main/resources/com/platform/business/mapper/TeacherHomeMapper.xml
View file @
66392f2e
...
@@ -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, ''), ' ', ''))
>
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.chi
ef
_
id
= #{teacherId}
where
<include
r
efid
=
"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
>
= #{monthStart}
where e.exam_time
>
= #{monthStart}
and e.exam_time
<
#{nextMonthStart}
and e.exam_time
<
#{nextMonthStart}
and (e.chief_id = #{teacherId}
and
<include
refid=
"participantPermission"
/>
)
or find_in_set(#{teacherId}, replace(coalesce(e.invigilation_id, ''), ' ', ''))
>
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.chi
ef
_
id
= #{teacherId}
where
<include
r
efid
=
"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)
>
0
and coalesce(attempt.mark_flag, 0) = 0 then 1 else 0 end)
>
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
>
= #{startTime}
where e.exam_time
>
= #{startTime}
and e.exam_time
<
#{endTime}
and e.exam_time
<
#{endTime}
and (e.chief_id = #{teacherId}
and
<include
refid=
"participantPermission"
/>
or find_in_set(#{teacherId}, replace(coalesce(e.invigilation_id, ''), ' ', ''))
>
0)
order by e.exam_time asc, e.id asc
order by e.exam_time asc, e.id asc
</select>
</select>
...
...
practical-business/src/main/resources/com/platform/business/mapper/TeacherScoreMapper.xml
View file @
66392f2e
...
@@ -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>
<!--
<!--
...
...
practical-business/src/main/resources/exam-management-api.md
View file @
66392f2e
...
@@ -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"
,
"chiefExaminerId
s
"
:
[
"1900000000000000001"
,
"1900000000000000003"
],
"invigilatorId"
:
"1900000000000000002"
,
"invigilatorId
s
"
:
[
"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. 删除考试
...
...
practical-business/src/main/resources/practice-paper-rule-api.md
View file @
66392f2e
# 管理员端实操
自动组
卷规则接口
# 管理员端实操
试
卷规则接口
页面位置为“管理员 → 智能考评 → 试卷管理 → 自动组卷 → 实操”。实操与理论的
页面位置为“管理员 → 智能考评 → 试卷管理 → 实操试卷规则”。部署时先执行
行为不同:这里只配置类目、考核时间、配分和题量,不生成正式试卷。
`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读取,不会随新增规则或学员职级变化。
practical-business/src/main/resources/sql/practice_paper_rule.sql
View file @
66392f2e
-- 管理员端“智能考评-试卷管理-自动组卷(实操)”规则配置(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
;
practical-business/src/test/java/com/platform/business/controller/TheoreticalPaperAdminControllerTest.java
View file @
66392f2e
...
@@ -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"
,
"管理员甲"
);
...
...
practical-business/src/test/java/com/platform/business/mapper/ExamMapperXmlTest.java
View file @
66392f2e
...
@@ -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"
));
/*
/*
* 通用考试分页必须查出时长供服务层计算三态;顶部汇总则必须独立统计全表,
* 通用考试分页必须查出时长供服务层计算三态;顶部汇总则必须独立统计全表,
...
...
Prev
1
2
3
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment