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
f6b4653f
Commit
f6b4653f
authored
Sep 02, 2026
by
王蔡翾
Browse files
Merge remote-tracking branch 'origin/dev-v1.0' into dev-v1.0
parents
56d0958c
0f48de00
Changes
21
Hide whitespace changes
Inline
Side-by-side
practical-api/practical-business-api/src/main/java/com/platform/business/model/vo/TheoreticalPracticeLevelOptionVO.java
0 → 100644
View file @
f6b4653f
package
com.platform.business.model.vo
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
/** 管理端理论练习列表的等级筛选选项。 */
@Data
public
class
TheoreticalPracticeLevelOptionVO
{
/**
* 提交给分页接口 {@code lev} 字段的值。
*
* <p>该值直接来源于已有理论练习数据,而不是班级树的某一条分支,因此历史练习、
* 技能竞赛以及分散在不同工种和学年下的等级都能被完整筛选。</p>
*/
@ApiModelProperty
(
"等级筛选值"
)
private
String
value
;
/** 页面下拉框展示的等级名称。 */
@ApiModelProperty
(
"等级展示名称"
)
private
String
label
;
}
practical-api/practical-business-api/src/main/java/com/platform/business/model/vo/TheoreticalPracticeVO.java
View file @
f6b4653f
...
@@ -23,12 +23,12 @@ public class TheoreticalPracticeVO extends TheoreticalPracticeEntity {
...
@@ -23,12 +23,12 @@ public class TheoreticalPracticeVO extends TheoreticalPracticeEntity {
@ApiModelProperty
(
value
=
"人数"
)
@ApiModelProperty
(
value
=
"人数"
)
private
String
studentCount
;
private
String
studentCount
;
@ApiModelProperty
(
value
=
"状态"
)
@ApiModelProperty
(
value
=
"状态
:未开始/进行中/已结束
"
)
private
String
status
;
private
String
status
;
/**
/**
* 供前端筛选和样式判断使用的稳定状态码。
保留
status
中文文案以兼容旧页面
,
* 供前端筛选和样式判断使用的稳定状态码。status
与状态码保持一一对应
,
*
新
页面应优先使用PENDING、ONGOING、ENDED三个状态码。
* 页面应优先使用PENDING、ONGOING、ENDED三个状态码
进行逻辑判断
。
*/
*/
@ApiModelProperty
(
value
=
"状态码:PENDING/ONGOING/ENDED"
)
@ApiModelProperty
(
value
=
"状态码:PENDING/ONGOING/ENDED"
)
private
String
statusCode
;
private
String
statusCode
;
...
...
practical-business/src/main/java/com/platform/business/constant/TheoreticalPracticeConstants.java
View file @
f6b4653f
...
@@ -12,6 +12,14 @@ public final class TheoreticalPracticeConstants {
...
@@ -12,6 +12,14 @@ public final class TheoreticalPracticeConstants {
public
static
final
String
STATUS_ONGOING
=
"ONGOING"
;
public
static
final
String
STATUS_ONGOING
=
"ONGOING"
;
public
static
final
String
STATUS_ENDED
=
"ENDED"
;
public
static
final
String
STATUS_ENDED
=
"ENDED"
;
/**
* 管理端列表统一使用产品定义的三态文案。手动关闭只影响状态判定,
* 对外仍展示“已结束”,避免同一个ENDED状态码对应两种列表文案。
*/
public
static
final
String
STATUS_LABEL_PENDING
=
"未开始"
;
public
static
final
String
STATUS_LABEL_ONGOING
=
"进行中"
;
public
static
final
String
STATUS_LABEL_ENDED
=
"已结束"
;
public
static
final
String
STUDENT_NOT_STARTED
=
"NOT_STARTED"
;
public
static
final
String
STUDENT_NOT_STARTED
=
"NOT_STARTED"
;
public
static
final
String
STUDENT_EXCELLENT
=
"EXCELLENT"
;
public
static
final
String
STUDENT_EXCELLENT
=
"EXCELLENT"
;
public
static
final
String
STUDENT_GOOD
=
"GOOD"
;
public
static
final
String
STUDENT_GOOD
=
"GOOD"
;
...
...
practical-business/src/main/java/com/platform/business/controller/TheoreticalPracticeController.java
View file @
f6b4653f
...
@@ -4,6 +4,7 @@ import com.platform.business.model.dto.TheoreticalPracticeDTO;
...
@@ -4,6 +4,7 @@ import com.platform.business.model.dto.TheoreticalPracticeDTO;
import
com.platform.business.model.dto.TheoreticalPracticeStatisticsQueryDTO
;
import
com.platform.business.model.dto.TheoreticalPracticeStatisticsQueryDTO
;
import
com.platform.business.model.entity.UserEntity
;
import
com.platform.business.model.entity.UserEntity
;
import
com.platform.business.model.vo.TheoreticalPracticeStatisticsOverviewVO
;
import
com.platform.business.model.vo.TheoreticalPracticeStatisticsOverviewVO
;
import
com.platform.business.model.vo.TheoreticalPracticeLevelOptionVO
;
import
com.platform.business.model.vo.TheoreticalPracticeStudentStatisticsDetailVO
;
import
com.platform.business.model.vo.TheoreticalPracticeStudentStatisticsDetailVO
;
import
com.platform.business.model.vo.TheoreticalPracticeSummaryVO
;
import
com.platform.business.model.vo.TheoreticalPracticeSummaryVO
;
import
com.platform.business.model.vo.TheoreticalPracticeVO
;
import
com.platform.business.model.vo.TheoreticalPracticeVO
;
...
@@ -20,6 +21,7 @@ import io.swagger.annotations.ApiOperation;
...
@@ -20,6 +21,7 @@ import io.swagger.annotations.ApiOperation;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.util.List
;
/**
/**
...
@@ -55,6 +57,13 @@ public class TheoreticalPracticeController extends BaseController {
...
@@ -55,6 +57,13 @@ public class TheoreticalPracticeController extends BaseController {
return
getDataTable
(
theoreticalPracticeService
.
page
(
theoreticalPracticeDTO
));
return
getDataTable
(
theoreticalPracticeService
.
page
(
theoreticalPracticeDTO
));
}
}
@ApiOperation
(
"理论练习列表完整等级筛选项"
)
@GetMapping
(
"/levels"
)
public
Result
<
List
<
TheoreticalPracticeLevelOptionVO
>>
levels
(
HttpServletRequest
request
)
{
requireAdmin
(
request
);
return
Result
.
data
(
theoreticalPracticeService
.
levelOptions
());
}
@ApiOperation
(
"一级页面练习总数、进行中和已结束统计"
)
@ApiOperation
(
"一级页面练习总数、进行中和已结束统计"
)
@GetMapping
(
"/summary"
)
@GetMapping
(
"/summary"
)
public
Result
<
TheoreticalPracticeSummaryVO
>
summary
(
HttpServletRequest
request
)
{
public
Result
<
TheoreticalPracticeSummaryVO
>
summary
(
HttpServletRequest
request
)
{
...
...
practical-business/src/main/java/com/platform/business/mapper/ClassMapper.java
View file @
f6b4653f
...
@@ -22,9 +22,14 @@ public interface ClassMapper extends BaseMapper<ClassEntity> {
...
@@ -22,9 +22,14 @@ public interface ClassMapper extends BaseMapper<ClassEntity> {
List
<
ClassVO
>
queryList
(
ClassDTO
classDTO
);
List
<
ClassVO
>
queryList
(
ClassDTO
classDTO
);
/** 管理员卡片分页和导航树复用同一套过滤条件。 */
/**
* 管理员卡片分页和导航树复用同一套过滤条件。
*
* @param orderByCreateTime true时按创建时间倒序返回卡片列表;false时保留导航树所需的分组顺序
*/
List
<
ClassAdminCardVO
>
selectAdminClasses
(
@Param
(
"query"
)
ClassAdminQueryDTO
query
,
List
<
ClassAdminCardVO
>
selectAdminClasses
(
@Param
(
"query"
)
ClassAdminQueryDTO
query
,
@Param
(
"today"
)
Date
today
);
@Param
(
"today"
)
Date
today
,
@Param
(
"orderByCreateTime"
)
boolean
orderByCreateTime
);
ClassAdminDetailVO
selectAdminDetail
(
@Param
(
"classId"
)
Integer
classId
);
ClassAdminDetailVO
selectAdminDetail
(
@Param
(
"classId"
)
Integer
classId
);
...
...
practical-business/src/main/java/com/platform/business/mapper/TheoreticalPracticeMapper.java
View file @
f6b4653f
...
@@ -5,6 +5,7 @@ import com.platform.business.model.dto.TheoreticalPracticeDTO;
...
@@ -5,6 +5,7 @@ import com.platform.business.model.dto.TheoreticalPracticeDTO;
import
com.platform.business.model.entity.TheoreticalPracticeEntity
;
import
com.platform.business.model.entity.TheoreticalPracticeEntity
;
import
com.platform.business.model.vo.TheoreticalPracticeVO
;
import
com.platform.business.model.vo.TheoreticalPracticeVO
;
import
com.platform.business.model.vo.TheoreticalPracticeKnowledgeStatisticsVO
;
import
com.platform.business.model.vo.TheoreticalPracticeKnowledgeStatisticsVO
;
import
com.platform.business.model.vo.TheoreticalPracticeLevelOptionVO
;
import
com.platform.business.model.vo.TheoreticalPracticeStatisticsOverviewVO
;
import
com.platform.business.model.vo.TheoreticalPracticeStatisticsOverviewVO
;
import
com.platform.business.model.vo.TheoreticalPracticeStudentStatisticsVO
;
import
com.platform.business.model.vo.TheoreticalPracticeStudentStatisticsVO
;
import
com.platform.business.model.vo.TheoreticalPracticeSummaryVO
;
import
com.platform.business.model.vo.TheoreticalPracticeSummaryVO
;
...
@@ -26,6 +27,11 @@ public interface TheoreticalPracticeMapper extends BaseMapper<TheoreticalPractic
...
@@ -26,6 +27,11 @@ public interface TheoreticalPracticeMapper extends BaseMapper<TheoreticalPractic
List
<
TheoreticalPracticeVO
>
page
(
@Param
(
"query"
)
TheoreticalPracticeDTO
theoreticalPracticeDTO
,
List
<
TheoreticalPracticeVO
>
page
(
@Param
(
"query"
)
TheoreticalPracticeDTO
theoreticalPracticeDTO
,
@Param
(
"now"
)
Date
now
);
@Param
(
"now"
)
Date
now
);
/**
* 从理论练习自身的数据全集提取等级,避免通过班级导航树取值时只遍历到部分分支。
*/
List
<
TheoreticalPracticeLevelOptionVO
>
selectLevelOptions
();
TheoreticalPracticeVO
detail
(
@Param
(
"id"
)
String
id
);
TheoreticalPracticeVO
detail
(
@Param
(
"id"
)
String
id
);
TheoreticalPracticeSummaryVO
summary
(
@Param
(
"now"
)
Date
now
);
TheoreticalPracticeSummaryVO
summary
(
@Param
(
"now"
)
Date
now
);
...
...
practical-business/src/main/java/com/platform/business/service/TheoreticalPracticeService.java
View file @
f6b4653f
...
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
...
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
import
com.platform.business.model.dto.TheoreticalPracticeDTO
;
import
com.platform.business.model.dto.TheoreticalPracticeDTO
;
import
com.platform.business.model.entity.TheoreticalPracticeEntity
;
import
com.platform.business.model.entity.TheoreticalPracticeEntity
;
import
com.platform.business.model.vo.TheoreticalPracticeVO
;
import
com.platform.business.model.vo.TheoreticalPracticeVO
;
import
com.platform.business.model.vo.TheoreticalPracticeLevelOptionVO
;
import
com.platform.business.model.vo.TheoreticalPracticeStatisticsOverviewVO
;
import
com.platform.business.model.vo.TheoreticalPracticeStatisticsOverviewVO
;
import
com.platform.business.model.vo.TheoreticalPracticeStudentStatisticsDetailVO
;
import
com.platform.business.model.vo.TheoreticalPracticeStudentStatisticsDetailVO
;
import
com.platform.business.model.vo.TheoreticalPracticeStudentStatisticsVO
;
import
com.platform.business.model.vo.TheoreticalPracticeStudentStatisticsVO
;
...
@@ -24,6 +25,9 @@ import java.util.List;
...
@@ -24,6 +25,9 @@ import java.util.List;
public
interface
TheoreticalPracticeService
extends
IService
<
TheoreticalPracticeEntity
>
{
public
interface
TheoreticalPracticeService
extends
IService
<
TheoreticalPracticeEntity
>
{
List
<
TheoreticalPracticeVO
>
page
(
TheoreticalPracticeDTO
theoreticalPracticeDTO
);
List
<
TheoreticalPracticeVO
>
page
(
TheoreticalPracticeDTO
theoreticalPracticeDTO
);
/** 返回一级列表全部可筛选的等级,选项来源与列表数据保持一致。 */
List
<
TheoreticalPracticeLevelOptionVO
>
levelOptions
();
TheoreticalPracticeVO
detail
(
String
id
);
TheoreticalPracticeVO
detail
(
String
id
);
Result
<
Boolean
>
saveOrUpdateData
(
TheoreticalPracticeDTO
theoreticalPracticeDTO
);
Result
<
Boolean
>
saveOrUpdateData
(
TheoreticalPracticeDTO
theoreticalPracticeDTO
);
...
...
practical-business/src/main/java/com/platform/business/service/impl/ClassAdminServiceImpl.java
View file @
f6b4653f
...
@@ -64,7 +64,9 @@ public class ClassAdminServiceImpl implements ClassAdminService {
...
@@ -64,7 +64,9 @@ public class ClassAdminServiceImpl implements ClassAdminService {
public
List
<
ClassAdminCardVO
>
page
(
ClassAdminQueryDTO
query
)
{
public
List
<
ClassAdminCardVO
>
page
(
ClassAdminQueryDTO
query
)
{
ClassAdminQueryDTO
normalized
=
query
==
null
?
new
ClassAdminQueryDTO
()
:
query
;
ClassAdminQueryDTO
normalized
=
query
==
null
?
new
ClassAdminQueryDTO
()
:
query
;
normalizeQuery
(
normalized
);
normalizeQuery
(
normalized
);
List
<
ClassAdminCardVO
>
classes
=
classMapper
.
selectAdminClasses
(
normalized
,
businessSqlDate
());
// 卡片分页必须在数据库分页前完成创建时间排序,确保跨页、筛选和搜索时顺序始终一致。
List
<
ClassAdminCardVO
>
classes
=
classMapper
.
selectAdminClasses
(
normalized
,
businessSqlDate
(),
true
);
LocalDate
today
=
businessToday
();
LocalDate
today
=
businessToday
();
classes
.
forEach
(
item
->
applyClassStatus
(
item
,
today
));
classes
.
forEach
(
item
->
applyClassStatus
(
item
,
today
));
return
classes
;
return
classes
;
...
@@ -75,7 +77,9 @@ public class ClassAdminServiceImpl implements ClassAdminService {
...
@@ -75,7 +77,9 @@ public class ClassAdminServiceImpl implements ClassAdminService {
ClassAdminQueryDTO
query
=
new
ClassAdminQueryDTO
();
ClassAdminQueryDTO
query
=
new
ClassAdminQueryDTO
();
query
.
setKeyword
(
keyword
);
query
.
setKeyword
(
keyword
);
normalizeQuery
(
query
);
normalizeQuery
(
query
);
List
<
ClassAdminCardVO
>
classes
=
classMapper
.
selectAdminClasses
(
query
,
businessSqlDate
());
// 导航树仍按年度、工种和等级分组排序,避免卡片排序需求改变左侧树的既有结构。
List
<
ClassAdminCardVO
>
classes
=
classMapper
.
selectAdminClasses
(
query
,
businessSqlDate
(),
false
);
return
buildTree
(
classes
);
return
buildTree
(
classes
);
}
}
...
@@ -138,6 +142,10 @@ public class ClassAdminServiceImpl implements ClassAdminService {
...
@@ -138,6 +142,10 @@ public class ClassAdminServiceImpl implements ClassAdminService {
if
(
existing
==
null
)
{
if
(
existing
==
null
)
{
throw
new
BusinessException
(
"班级不存在或已删除"
);
throw
new
BusinessException
(
"班级不存在或已删除"
);
}
}
String
status
=
resolveClassStatus
(
existing
.
getStartDate
(),
existing
.
getEndDate
(),
businessToday
());
if
(!
ClassAdminConstants
.
STATUS_UPCOMING
.
equals
(
status
))
{
throw
new
BusinessException
(
"只有待开课班级可以编辑"
);
}
int
actualCount
=
classMapper
.
countAdminStudents
(
classId
);
int
actualCount
=
classMapper
.
countAdminStudents
(
classId
);
validateSaveRequest
(
request
,
classId
,
actualCount
);
validateSaveRequest
(
request
,
classId
,
actualCount
);
...
...
practical-business/src/main/java/com/platform/business/service/impl/CourseAdminServiceImpl.java
View file @
f6b4653f
...
@@ -158,6 +158,7 @@ public class CourseAdminServiceImpl implements CourseAdminService {
...
@@ -158,6 +158,7 @@ public class CourseAdminServiceImpl implements CourseAdminService {
try
{
try
{
PreparedCourse
prepared
=
prepareCourse
(
PreparedCourse
prepared
=
prepareCourse
(
item
,
request
.
getClassId
(),
managedClass
,
batchType
);
item
,
request
.
getClassId
(),
managedClass
,
batchType
);
validateNewCourseDate
(
prepared
,
managedClass
);
requireWritablePeriod
(
prepared
.
period
);
requireWritablePeriod
(
prepared
.
period
);
LocalDate
courseDate
=
toLocalDate
(
prepared
.
entity
.
getDate
());
LocalDate
courseDate
=
toLocalDate
(
prepared
.
entity
.
getDate
());
...
@@ -752,6 +753,23 @@ public class CourseAdminServiceImpl implements CourseAdminService {
...
@@ -752,6 +753,23 @@ public class CourseAdminServiceImpl implements CourseAdminService {
}
}
}
}
private
void
validateNewCourseDate
(
PreparedCourse
course
,
ClassEntity
managedClass
)
{
validateCourseDate
(
course
.
entity
.
getDate
(),
managedClass
);
LocalDate
courseDate
=
toLocalDate
(
course
.
entity
.
getDate
());
LocalDate
today
=
LocalDate
.
now
(
ClassAdminConstants
.
BUSINESS_ZONE
);
if
(
courseDate
.
isBefore
(
today
))
{
throw
new
BusinessException
(
"课程日期不能早于当前日期"
);
}
if
(
courseDate
.
equals
(
today
))
{
LocalTime
now
=
LocalTime
.
now
(
ClassAdminConstants
.
BUSINESS_ZONE
);
boolean
started
=
course
.
timeRanges
.
stream
()
.
anyMatch
(
range
->
!
range
.
start
.
isAfter
(
now
));
if
(
started
)
{
throw
new
BusinessException
(
"课程开始时间不能早于当前时间"
);
}
}
}
private
void
validateQueryDateRange
(
Date
startDate
,
Date
endDate
)
{
private
void
validateQueryDateRange
(
Date
startDate
,
Date
endDate
)
{
if
(
startDate
!=
null
&&
endDate
!=
null
if
(
startDate
!=
null
&&
endDate
!=
null
&&
toLocalDate
(
startDate
).
isAfter
(
toLocalDate
(
endDate
)))
{
&&
toLocalDate
(
startDate
).
isAfter
(
toLocalDate
(
endDate
)))
{
...
...
practical-business/src/main/java/com/platform/business/service/impl/TheoreticalPaperAdminServiceImpl.java
View file @
f6b4653f
...
@@ -412,7 +412,7 @@ public class TheoreticalPaperAdminServiceImpl implements TheoreticalPaperAdminSe
...
@@ -412,7 +412,7 @@ public class TheoreticalPaperAdminServiceImpl implements TheoreticalPaperAdminSe
if
(!
TheoreticalPaperAdminConstants
.
QUESTION_TYPES
.
contains
(
type
))
{
if
(!
TheoreticalPaperAdminConstants
.
QUESTION_TYPES
.
contains
(
type
))
{
throw
new
BusinessException
(
prefix
+
"题型只支持判断题、单选题、多选题或主观题"
);
throw
new
BusinessException
(
prefix
+
"题型只支持判断题、单选题、多选题或主观题"
);
}
}
String
problem
=
requireText
(
input
.
get
Problem
(
),
4000
,
prefix
+
"题干"
);
String
problem
=
normalizeQuestion
Problem
(
input
,
prefix
);
String
answer
=
requireText
(
input
.
getAnswer
(),
4000
,
prefix
+
"答案"
);
String
answer
=
requireText
(
input
.
getAnswer
(),
4000
,
prefix
+
"答案"
);
BigDecimal
score
=
decimal
(
input
.
getScore
(),
prefix
+
"分值"
);
BigDecimal
score
=
decimal
(
input
.
getScore
(),
prefix
+
"分值"
);
if
(
score
.
compareTo
(
BigDecimal
.
ZERO
)
<=
0
||
score
.
compareTo
(
new
BigDecimal
(
"1000"
))
>
0
)
{
if
(
score
.
compareTo
(
BigDecimal
.
ZERO
)
<=
0
||
score
.
compareTo
(
new
BigDecimal
(
"1000"
))
>
0
)
{
...
@@ -456,6 +456,59 @@ public class TheoreticalPaperAdminServiceImpl implements TheoreticalPaperAdminSe
...
@@ -456,6 +456,59 @@ public class TheoreticalPaperAdminServiceImpl implements TheoreticalPaperAdminSe
return
target
;
return
target
;
}
}
/**
* 取得可直接写入试卷明细表的纯题干。
*
* <p>旧版题库分页接口为了方便页面展示,会把选择题格式化成
* “题干\nA.选项A\nB.选项B...”后放回 {@code problem},同时又保留独立的
* {@code optionA-optionE} 字段。手动组卷页面把该对象原样提交后,如果继续保存这个
* 展示字符串,不但预览时会重复显示选项,还可能超过试卷明细表 {@code problem}
* 的128字符限制并触发数据库异常,最终表现为保存草稿和发布均返回500。</p>
*
* <p>这里只在题干末尾与独立选项能逐字对应时剥离旧版展示后缀,避免误删用户题干中
* 正常出现的“A.”等文本。兼容前端保留或去掉末尾换行的两种提交形式;清洗完成后再按
* 当前数据库真实长度校验,使异常输入返回明确业务提示,而不是进入数据库后报500。</p>
*/
private
String
normalizeQuestionProblem
(
TheoreticalPaperDetailEntity
question
,
String
prefix
)
{
String
submitted
=
requireText
(
question
.
getProblem
(),
4000
,
prefix
+
"题干"
);
String
normalizedLineBreaks
=
submitted
.
replace
(
"\r\n"
,
"\n"
).
replace
(
'\r'
,
'\n'
);
String
legacyOptionSuffix
=
buildLegacyOptionSuffix
(
question
);
if
(
legacyOptionSuffix
!=
null
)
{
String
suffixWithTrailingLineBreak
=
"\n"
+
legacyOptionSuffix
;
String
suffixWithoutTrailingLineBreak
=
suffixWithTrailingLineBreak
.
substring
(
0
,
suffixWithTrailingLineBreak
.
length
()
-
1
);
if
(
normalizedLineBreaks
.
endsWith
(
suffixWithTrailingLineBreak
))
{
normalizedLineBreaks
=
normalizedLineBreaks
.
substring
(
0
,
normalizedLineBreaks
.
length
()
-
suffixWithTrailingLineBreak
.
length
());
}
else
if
(
normalizedLineBreaks
.
endsWith
(
suffixWithoutTrailingLineBreak
))
{
normalizedLineBreaks
=
normalizedLineBreaks
.
substring
(
0
,
normalizedLineBreaks
.
length
()
-
suffixWithoutTrailingLineBreak
.
length
());
}
}
return
requireText
(
normalizedLineBreaks
,
128
,
prefix
+
"题干"
);
}
/**
* 按旧版 {@code TheoreticalLibraryMapper.pageData} 完全相同的格式重建选项后缀。
* 使用“非null”而非“非空”判断,是为了与旧SQL中的 {@code IS NOT NULL} 保持一致。
*/
private
String
buildLegacyOptionSuffix
(
TheoreticalPaperDetailEntity
question
)
{
StringBuilder
suffix
=
new
StringBuilder
();
appendLegacyOption
(
suffix
,
'A'
,
question
.
getOptionA
());
appendLegacyOption
(
suffix
,
'B'
,
question
.
getOptionB
());
appendLegacyOption
(
suffix
,
'C'
,
question
.
getOptionC
());
appendLegacyOption
(
suffix
,
'D'
,
question
.
getOptionD
());
appendLegacyOption
(
suffix
,
'E'
,
question
.
getOptionE
());
return
suffix
.
length
()
==
0
?
null
:
suffix
.
toString
();
}
/** 每个旧版展示选项固定以“字母.内容\n”拼接,末尾同样保留换行。 */
private
void
appendLegacyOption
(
StringBuilder
suffix
,
char
label
,
String
option
)
{
if
(
option
!=
null
)
{
suffix
.
append
(
label
).
append
(
'.'
).
append
(
option
).
append
(
'\n'
);
}
}
private
String
normalizeAnswer
(
String
type
,
String
answer
,
private
String
normalizeAnswer
(
String
type
,
String
answer
,
TheoreticalPaperDetailEntity
question
,
String
prefix
)
{
TheoreticalPaperDetailEntity
question
,
String
prefix
)
{
if
(
"单选题"
.
equals
(
type
))
{
if
(
"单选题"
.
equals
(
type
))
{
...
...
practical-business/src/main/java/com/platform/business/service/impl/TheoreticalPracticeServiceImpl.java
View file @
f6b4653f
...
@@ -10,6 +10,7 @@ import com.platform.business.model.dto.TheoreticalPracticeDTO;
...
@@ -10,6 +10,7 @@ import com.platform.business.model.dto.TheoreticalPracticeDTO;
import
com.platform.business.model.dto.TheoreticalPracticeStatisticsQueryDTO
;
import
com.platform.business.model.dto.TheoreticalPracticeStatisticsQueryDTO
;
import
com.platform.business.model.entity.*
;
import
com.platform.business.model.entity.*
;
import
com.platform.business.model.vo.TheoreticalPracticeKnowledgeStatisticsVO
;
import
com.platform.business.model.vo.TheoreticalPracticeKnowledgeStatisticsVO
;
import
com.platform.business.model.vo.TheoreticalPracticeLevelOptionVO
;
import
com.platform.business.model.vo.TheoreticalPracticeStatisticsOverviewVO
;
import
com.platform.business.model.vo.TheoreticalPracticeStatisticsOverviewVO
;
import
com.platform.business.model.vo.TheoreticalPracticeStudentStatisticsDetailVO
;
import
com.platform.business.model.vo.TheoreticalPracticeStudentStatisticsDetailVO
;
import
com.platform.business.model.vo.TheoreticalPracticeStudentStatisticsVO
;
import
com.platform.business.model.vo.TheoreticalPracticeStudentStatisticsVO
;
...
@@ -76,27 +77,37 @@ public class TheoreticalPracticeServiceImpl extends ServiceImpl<TheoreticalPract
...
@@ -76,27 +77,37 @@ public class TheoreticalPracticeServiceImpl extends ServiceImpl<TheoreticalPract
TheoreticalPracticeDTO
safeQuery
=
normalizePageQuery
(
theoreticalPracticeDTO
);
TheoreticalPracticeDTO
safeQuery
=
normalizePageQuery
(
theoreticalPracticeDTO
);
Date
now
=
new
Date
();
Date
now
=
new
Date
();
List
<
TheoreticalPracticeVO
>
result
=
baseMapper
.
page
(
safeQuery
,
now
);
List
<
TheoreticalPracticeVO
>
result
=
baseMapper
.
page
(
safeQuery
,
now
);
//
中文状态继续兼容旧页面,同时补充稳定状态码供新筛选项和样式判断使用
。
//
列表按产品定义统一为“未开始、进行中、已结束”三态;手动关闭也归入已结束
。
for
(
TheoreticalPracticeVO
theoreticalPracticeVO
:
result
)
{
for
(
TheoreticalPracticeVO
theoreticalPracticeVO
:
result
)
{
if
(
Boolean
.
TRUE
.
equals
(
theoreticalPracticeVO
.
getIsClose
()))
{
if
(
Boolean
.
TRUE
.
equals
(
theoreticalPracticeVO
.
getIsClose
()))
{
theoreticalPracticeVO
.
setStatus
(
"已手动关闭"
);
theoreticalPracticeVO
.
setStatus
(
TheoreticalPracticeConstants
.
STATUS_LABEL_ENDED
);
theoreticalPracticeVO
.
setStatusCode
(
TheoreticalPracticeConstants
.
STATUS_ENDED
);
theoreticalPracticeVO
.
setStatusCode
(
TheoreticalPracticeConstants
.
STATUS_ENDED
);
continue
;
continue
;
}
}
if
(
theoreticalPracticeVO
.
getStartTime
().
after
(
now
))
{
if
(
theoreticalPracticeVO
.
getStartTime
().
after
(
now
))
{
theoreticalPracticeVO
.
setStatus
(
"未开放"
);
theoreticalPracticeVO
.
setStatus
(
TheoreticalPracticeConstants
.
STATUS_LABEL_PENDING
);
theoreticalPracticeVO
.
setStatusCode
(
TheoreticalPracticeConstants
.
STATUS_PENDING
);
theoreticalPracticeVO
.
setStatusCode
(
TheoreticalPracticeConstants
.
STATUS_PENDING
);
}
else
if
(
theoreticalPracticeVO
.
getEndTime
().
before
(
now
))
{
}
else
if
(
theoreticalPracticeVO
.
getEndTime
().
before
(
now
))
{
theoreticalPracticeVO
.
setStatus
(
"已结束"
);
theoreticalPracticeVO
.
setStatus
(
TheoreticalPracticeConstants
.
STATUS_LABEL_ENDED
);
theoreticalPracticeVO
.
setStatusCode
(
TheoreticalPracticeConstants
.
STATUS_ENDED
);
theoreticalPracticeVO
.
setStatusCode
(
TheoreticalPracticeConstants
.
STATUS_ENDED
);
}
else
{
}
else
{
theoreticalPracticeVO
.
setStatus
(
"已开放"
);
theoreticalPracticeVO
.
setStatus
(
TheoreticalPracticeConstants
.
STATUS_LABEL_ONGOING
);
theoreticalPracticeVO
.
setStatusCode
(
TheoreticalPracticeConstants
.
STATUS_ONGOING
);
theoreticalPracticeVO
.
setStatusCode
(
TheoreticalPracticeConstants
.
STATUS_ONGOING
);
}
}
}
}
return
result
;
return
result
;
}
}
/**
* 筛选选项直接由理论练习表聚合,确保页面中出现过的每一个等级都可被筛选。
* 班级导航树按“工种-学年-等级”分支组织,不适合作为扁平等级下拉框的数据源。
*/
@Override
@Transactional
(
readOnly
=
true
)
public
List
<
TheoreticalPracticeLevelOptionVO
>
levelOptions
()
{
return
baseMapper
.
selectLevelOptions
();
}
@Override
@Override
public
TheoreticalPracticeVO
detail
(
String
id
)
{
public
TheoreticalPracticeVO
detail
(
String
id
)
{
List
<
TheoreticalPracticeStudentVO
>
studentList
=
theoreticalPracticeStudentService
.
selectStudentListByPracticeId
(
id
);
List
<
TheoreticalPracticeStudentVO
>
studentList
=
theoreticalPracticeStudentService
.
selectStudentListByPracticeId
(
id
);
...
@@ -302,6 +313,12 @@ public class TheoreticalPracticeServiceImpl extends ServiceImpl<TheoreticalPract
...
@@ -302,6 +313,12 @@ public class TheoreticalPracticeServiceImpl extends ServiceImpl<TheoreticalPract
/** 校验列表筛选并统一状态大小写,防止无效状态被静默当成“全部”。 */
/** 校验列表筛选并统一状态大小写,防止无效状态被静默当成“全部”。 */
private
TheoreticalPracticeDTO
normalizePageQuery
(
TheoreticalPracticeDTO
query
)
{
private
TheoreticalPracticeDTO
normalizePageQuery
(
TheoreticalPracticeDTO
query
)
{
TheoreticalPracticeDTO
safe
=
query
==
null
?
new
TheoreticalPracticeDTO
()
:
query
;
TheoreticalPracticeDTO
safe
=
query
==
null
?
new
TheoreticalPracticeDTO
()
:
query
;
// 与等级选项接口返回的去空格值保持一致,并将纯空白条件视为未筛选。
if
(
StrUtil
.
isNotBlank
(
safe
.
getLev
()))
{
safe
.
setLev
(
safe
.
getLev
().
trim
());
}
else
{
safe
.
setLev
(
null
);
}
if
(
StrUtil
.
isNotBlank
(
safe
.
getStatus
()))
{
if
(
StrUtil
.
isNotBlank
(
safe
.
getStatus
()))
{
String
status
=
safe
.
getStatus
().
trim
().
toUpperCase
(
Locale
.
ROOT
);
String
status
=
safe
.
getStatus
().
trim
().
toUpperCase
(
Locale
.
ROOT
);
if
(!
TheoreticalPracticeConstants
.
ALLOWED_STATUSES
.
contains
(
status
))
{
if
(!
TheoreticalPracticeConstants
.
ALLOWED_STATUSES
.
contains
(
status
))
{
...
...
practical-business/src/main/resources/com/platform/business/mapper/ClassMapper.xml
View file @
f6b4653f
...
@@ -80,7 +80,16 @@
...
@@ -80,7 +80,16 @@
</when>
</when>
</choose>
</choose>
</where>
</where>
order by c.training_year desc, c.occupation asc, sl.id asc, c.name asc, c.id asc
<choose>
<when
test=
"orderByCreateTime"
>
<!-- ID倒序用于稳定排列同一时刻创建的班级,也让没有创建时间的历史数据保持确定顺序。 -->
order by c.create_time desc, c.id desc
</when>
<otherwise>
<!-- 导航树依赖该顺序稳定组装年度、工种、等级和班级节点。 -->
order by c.training_year desc, c.occupation asc, sl.id asc, c.name asc, c.id asc
</otherwise>
</choose>
</select>
</select>
<!--
<!--
...
...
practical-business/src/main/resources/com/platform/business/mapper/ExamMapper.xml
View file @
f6b4653f
...
@@ -250,7 +250,17 @@
...
@@ -250,7 +250,17 @@
student.id_card as idCard,
student.id_card as idCard,
student.sex,
student.sex,
student.phone_number as phone,
student.phone_number as phone,
student.factory,
<!--
账号详情优先展示“实际用工单位”,其次展示“劳动关系单位”,最后兼容历史
factory 字段。考试新增弹窗必须遵循同一口径,否则新版账号只维护
company_name1/company_name2 时,这里的 factory 会返回 null,表格单位列为空。
NULLIF(TRIM(...), '') 同时跳过空字符串,避免空的新字段遮蔽有效的旧字段。
-->
coalesce(
nullif(trim(student.company_name2), ''),
nullif(trim(student.company_name1), ''),
nullif(trim(student.factory), '')
) as factory,
attendance.attendanceRate
attendance.attendanceRate
from class_student member
from class_student member
inner join user student on student.id = member.user_id
inner join user student on student.id = member.user_id
...
...
practical-business/src/main/resources/com/platform/business/mapper/TheoreticalPracticeMapper.xml
View file @
f6b4653f
...
@@ -36,7 +36,7 @@
...
@@ -36,7 +36,7 @@
cs.class_id = tp.class_id
cs.class_id = tp.class_id
<where>
<where>
<if
test=
"query.lev != null and query.lev != ''"
>
<if
test=
"query.lev != null and query.lev != ''"
>
and tp.lev = #{query.lev}
and
trim(
tp.lev
)
= #{query.lev}
</if>
</if>
<if
test=
"query.status == 'PENDING'"
>
<if
test=
"query.status == 'PENDING'"
>
and coalesce(tp.is_close, false) = false
and coalesce(tp.is_close, false) = false
...
@@ -61,6 +61,22 @@
...
@@ -61,6 +61,22 @@
tp.id, tp.lev, tp.class_id, c.name, tp.start_time, tp.end_time, tp.creator, tp.creator_id, tp.create_time, tp.is_close
tp.id, tp.lev, tp.class_id, c.name, tp.start_time, tp.end_time, tp.creator, tp.creator_id, tp.create_time, tp.is_close
order by tp.create_time desc
order by tp.create_time desc
</select>
</select>
<!--
列表筛选必须覆盖理论练习表中真实存在的全部等级。不能从班级导航树的固定层级
或单个工种分支截取,否则历史数据缺少工种、同一年度存在多个工种时会漏选项。
trim同时合并旧数据中仅首尾空格不同的重复等级,并与分页筛选条件保持一致。
-->
<select
id=
"selectLevelOptions"
resultType=
"com.platform.business.model.vo.TheoreticalPracticeLevelOptionVO"
>
select trim(tp.lev) as value,
trim(tp.lev) as label
from theoretical_practice tp
where tp.lev is not null
and trim(tp.lev) != ''
group by trim(tp.lev)
order by trim(tp.lev) asc
</select>
<select
id=
"detail"
resultType=
"com.platform.business.model.vo.TheoreticalPracticeVO"
>
<select
id=
"detail"
resultType=
"com.platform.business.model.vo.TheoreticalPracticeVO"
>
select
select
id,
id,
...
...
practical-business/src/main/resources/theoretical-practice-api.md
View file @
f6b4653f
...
@@ -16,6 +16,27 @@ practical-business/src/main/resources/sql/theoretical_practice_statistics.sql
...
@@ -16,6 +16,27 @@ practical-business/src/main/resources/sql/theoretical_practice_statistics.sql
## 2. 一级页面分页
## 2. 一级页面分页
### 2.1 等级筛选项
`GET /theoretical/practice/levels`
返回理论练习表中实际存在的全部非空等级,每项包含相同语义的
`value`
和
`label`
。
页面应直接使用该接口渲染等级下拉框,不再从“工种 → 学年 → 等级 → 班级”导航树的
局部分支提取等级。这样历史班级缺少工种、跨学年或跨工种时都不会遗漏筛选项。
```
json
{
"code"
:
200
,
"data"
:
[
{
"value"
:
"技能竞赛"
,
"label"
:
"技能竞赛"
},
{
"value"
:
"污水四级"
,
"label"
:
"污水四级"
},
{
"value"
:
"污泥五级"
,
"label"
:
"污泥五级"
}
]
}
```
### 2.2 分页查询
`POST /theoretical/practice/page`
`POST /theoretical/practice/page`
```
json
```
json
...
@@ -31,8 +52,9 @@ practical-business/src/main/resources/sql/theoretical_practice_statistics.sql
...
@@ -31,8 +52,9 @@ practical-business/src/main/resources/sql/theoretical_practice_statistics.sql
-
`status`
:
`PENDING`
、
`ONGOING`
、
`ENDED`
,忽略大小写。
-
`status`
:
`PENDING`
、
`ONGOING`
、
`ENDED`
,忽略大小写。
-
时间采用完整包含口径:练习开始时间不早于起始日,结束时间不晚于结束日当天。
-
时间采用完整包含口径:练习开始时间不早于起始日,结束时间不晚于结束日当天。
-
返回仍为项目统一
`TableDataInfo`
。原有中文
`status`
保留,并新增
`statusCode`
。
-
返回仍为项目统一
`TableDataInfo`
,并同时提供中文
`status`
和稳定的
`statusCode`
。
-
`ENDED`
同时包含自然到期和手动关闭;中文状态仍区分“已结束”和“已手动关闭”。
-
状态统一为
`PENDING`
/ 未开始、
`ONGOING`
/ 进行中、
`ENDED`
/ 已结束。
-
`ENDED`
同时包含自然到期和手动关闭,列表中均展示“已结束”。
## 3. 一级页面全局统计
## 3. 一级页面全局统计
...
...
practical-business/src/test/java/com/platform/business/controller/TheoreticalPracticeControllerTest.java
View file @
f6b4653f
package
com.platform.business.controller
;
package
com.platform.business.controller
;
import
com.platform.business.model.entity.UserEntity
;
import
com.platform.business.model.entity.UserEntity
;
import
com.platform.business.model.vo.TheoreticalPracticeLevelOptionVO
;
import
com.platform.business.service.AuthenticatedUserService
;
import
com.platform.business.service.AuthenticatedUserService
;
import
com.platform.business.service.TheoreticalPracticeService
;
import
com.platform.business.service.TheoreticalPracticeService
;
import
com.platform.exception.BusinessException
;
import
com.platform.exception.BusinessException
;
...
@@ -13,6 +14,8 @@ import org.springframework.mock.web.MockHttpServletRequest;
...
@@ -13,6 +14,8 @@ import org.springframework.mock.web.MockHttpServletRequest;
import
org.springframework.mock.web.MockHttpServletResponse
;
import
org.springframework.mock.web.MockHttpServletResponse
;
import
org.springframework.test.util.ReflectionTestUtils
;
import
org.springframework.test.util.ReflectionTestUtils
;
import
java.util.Collections
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertThrows
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertThrows
;
import
static
org
.
mockito
.
Mockito
.
doThrow
;
import
static
org
.
mockito
.
Mockito
.
doThrow
;
import
static
org
.
mockito
.
Mockito
.
times
;
import
static
org
.
mockito
.
Mockito
.
times
;
...
@@ -58,6 +61,24 @@ class TheoreticalPracticeControllerTest {
...
@@ -58,6 +61,24 @@ class TheoreticalPracticeControllerTest {
verify
(
theoreticalPracticeService
).
exportStudentStatistics
(
"p1"
,
"s1"
,
response
);
verify
(
theoreticalPracticeService
).
exportStudentStatistics
(
"p1"
,
"s1"
,
response
);
}
}
@Test
void
levelOptionsShouldRequireAdminAndForwardCompleteOptions
()
{
MockHttpServletRequest
request
=
new
MockHttpServletRequest
();
UserEntity
administrator
=
new
UserEntity
();
TheoreticalPracticeLevelOptionVO
option
=
new
TheoreticalPracticeLevelOptionVO
();
option
.
setValue
(
"污泥五级"
);
option
.
setLabel
(
"污泥五级"
);
when
(
authenticatedUserService
.
current
(
request
)).
thenReturn
(
administrator
);
when
(
theoreticalPracticeService
.
levelOptions
())
.
thenReturn
(
Collections
.
singletonList
(
option
));
controller
.
levels
(
request
);
// 等级选项包含管理端业务数据,与练习列表使用相同的管理员权限边界。
verify
(
authenticatedUserService
).
requireAdmin
(
administrator
);
verify
(
theoreticalPracticeService
).
levelOptions
();
}
@Test
@Test
void
statisticsEndpointShouldStopWhenCurrentUserIsNotAdmin
()
{
void
statisticsEndpointShouldStopWhenCurrentUserIsNotAdmin
()
{
MockHttpServletRequest
request
=
new
MockHttpServletRequest
();
MockHttpServletRequest
request
=
new
MockHttpServletRequest
();
...
...
practical-business/src/test/java/com/platform/business/mapper/ClassMapperXmlTest.java
0 → 100644
View file @
f6b4653f
package
com.platform.business.mapper
;
import
com.platform.business.model.dto.ClassAdminQueryDTO
;
import
org.apache.ibatis.builder.xml.XMLMapperBuilder
;
import
org.apache.ibatis.io.Resources
;
import
org.apache.ibatis.session.Configuration
;
import
org.junit.jupiter.api.Test
;
import
java.io.InputStream
;
import
java.util.HashMap
;
import
java.util.Map
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertFalse
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
/** 管理员班级列表与导航树排序规则的Mapper XML回归测试。 */
class
ClassMapperXmlTest
{
@Test
void
adminClassQueryShouldUseTheOrderingRequestedByItsCaller
()
throws
Exception
{
String
resource
=
"com/platform/business/mapper/ClassMapper.xml"
;
Configuration
configuration
=
new
Configuration
();
try
(
InputStream
input
=
Resources
.
getResourceAsStream
(
resource
))
{
new
XMLMapperBuilder
(
input
,
configuration
,
resource
,
configuration
.
getSqlFragments
()).
parse
();
}
// 模拟卡片分页调用,验证排序发生在数据库分页之前,并以ID作为稳定的第二排序键。
String
cardSql
=
compactSql
(
adminClassSql
(
configuration
,
true
));
assertTrue
(
cardSql
.
contains
(
"order by c.create_time desc, c.id desc"
));
assertFalse
(
cardSql
.
contains
(
"order by c.training_year desc"
));
// 导航树与卡片列表共用过滤SQL,但应继续保持原有的分组顺序。
String
treeSql
=
compactSql
(
adminClassSql
(
configuration
,
false
));
assertTrue
(
treeSql
.
contains
(
"order by c.training_year desc, c.occupation asc, sl.id asc, c.name asc, c.id asc"
));
assertFalse
(
treeSql
.
contains
(
"order by c.create_time desc"
));
}
private
static
String
adminClassSql
(
Configuration
configuration
,
boolean
orderByCreateTime
)
{
Map
<
String
,
Object
>
parameters
=
new
HashMap
<>();
parameters
.
put
(
"query"
,
new
ClassAdminQueryDTO
());
parameters
.
put
(
"today"
,
java
.
sql
.
Date
.
valueOf
(
"2026-09-02"
));
parameters
.
put
(
"orderByCreateTime"
,
orderByCreateTime
);
return
configuration
.
getMappedStatement
(
"com.platform.business.mapper.ClassMapper.selectAdminClasses"
)
.
getBoundSql
(
parameters
).
getSql
();
}
private
static
String
compactSql
(
String
sql
)
{
return
sql
.
replaceAll
(
"\\s+"
,
" "
).
trim
();
}
}
practical-business/src/test/java/com/platform/business/mapper/ExamMapperXmlTest.java
View file @
f6b4653f
...
@@ -6,6 +6,7 @@ import org.apache.ibatis.session.Configuration;
...
@@ -6,6 +6,7 @@ import org.apache.ibatis.session.Configuration;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.util.Collections
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
...
@@ -28,5 +29,21 @@ class ExamMapperXmlTest {
...
@@ -28,5 +29,21 @@ class ExamMapperXmlTest {
"com.platform.business.mapper.ExamMapper.selectAdminExamConflicts"
));
"com.platform.business.mapper.ExamMapper.selectAdminExamConflicts"
));
assertTrue
(
configuration
.
hasStatement
(
assertTrue
(
configuration
.
hasStatement
(
"com.platform.business.mapper.ExamMapper.updateAdminExam"
));
"com.platform.business.mapper.ExamMapper.updateAdminExam"
));
/*
* 学员详情使用新版 company_name1/company_name2 保存单位,旧数据则仍可能只保存
* factory。这里直接检查 MyBatis 最终生成的 SQL,防止后续改动又退回只查询旧字段,
* 导致新增考试弹窗的“单位”列再次为空。
*/
String
studentOptionsSql
=
configuration
.
getMappedStatement
(
"com.platform.business.mapper.ExamMapper.selectAdminExamStudentOptions"
)
.
getBoundSql
(
Collections
.
singletonMap
(
"classId"
,
1
))
.
getSql
()
.
replaceAll
(
"\\s+"
,
" "
)
.
toLowerCase
();
assertTrue
(
studentOptionsSql
.
contains
(
"coalesce( nullif(trim(student.company_name2), ''), "
+
"nullif(trim(student.company_name1), ''), "
+
"nullif(trim(student.factory), '') ) as factory"
));
}
}
}
}
practical-business/src/test/java/com/platform/business/mapper/TheoreticalPracticeMapperXmlTest.java
View file @
f6b4653f
...
@@ -19,6 +19,8 @@ class TheoreticalPracticeMapperXmlTest {
...
@@ -19,6 +19,8 @@ class TheoreticalPracticeMapperXmlTest {
assertTrue
(
configuration
.
hasStatement
(
assertTrue
(
configuration
.
hasStatement
(
"com.platform.business.mapper.TheoreticalPracticeMapper.summary"
));
"com.platform.business.mapper.TheoreticalPracticeMapper.summary"
));
assertTrue
(
configuration
.
hasStatement
(
"com.platform.business.mapper.TheoreticalPracticeMapper.selectLevelOptions"
));
assertTrue
(
configuration
.
hasStatement
(
assertTrue
(
configuration
.
hasStatement
(
"com.platform.business.mapper.TheoreticalPracticeMapper.statisticsOverview"
));
"com.platform.business.mapper.TheoreticalPracticeMapper.statisticsOverview"
));
assertTrue
(
configuration
.
hasStatement
(
assertTrue
(
configuration
.
hasStatement
(
...
...
practical-business/src/test/java/com/platform/business/service/impl/TheoreticalPaperAdminServiceImplTest.java
View file @
f6b4653f
...
@@ -20,6 +20,7 @@ import org.mockito.InjectMocks;
...
@@ -20,6 +20,7 @@ import org.mockito.InjectMocks;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.junit.jupiter.MockitoExtension
;
import
org.mockito.junit.jupiter.MockitoExtension
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.Collections
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
...
@@ -107,6 +108,64 @@ class TheoreticalPaperAdminServiceImplTest {
...
@@ -107,6 +108,64 @@ class TheoreticalPaperAdminServiceImplTest {
assertEquals
(
"teacher-1"
,
paperCaptor
.
getValue
().
getCreatorId
());
assertEquals
(
"teacher-1"
,
paperCaptor
.
getValue
().
getCreatorId
());
}
}
@Test
void
manualPublishShouldStripLegacyRenderedOptionsBeforeSavingQuestion
()
{
String
stem
=
"污水处理过程中,下列说法正确的是( )。"
;
TheoreticalPaperDetailEntity
question
=
new
TheoreticalPaperDetailEntity
();
question
.
setType
(
"单选题"
);
question
.
setOptionA
(
"应当严格执行工艺操作规程,完整记录关键运行参数并及时处理异常情况"
);
question
.
setOptionB
(
"设备出现异常后仍可不经任何检查,继续长时间运行直至完成全部生产任务"
);
question
.
setOptionC
(
"为了减少日常工作量,可以省略全部巡检、运行记录以及班组交接记录"
);
question
.
setOptionD
(
"任何运行工况和检修状态下,都可以绕过安全联锁直接强制启动设备"
);
question
.
setAnswer
(
"A"
);
question
.
setScore
(
2
D
);
// 模拟旧题库分页接口:problem 已经包含一份用于页面展示的 A-D 选项,
// 同一个请求中又带有独立 optionA-optionD 字段;拼接结果超过明细表128字符限制。
question
.
setProblem
(
stem
+
"\nA."
+
question
.
getOptionA
()
+
"\nB."
+
question
.
getOptionB
()
+
"\nC."
+
question
.
getOptionC
()
+
"\nD."
+
question
.
getOptionD
()
+
"\n"
);
assertTrue
(
question
.
getProblem
().
length
()
>
128
);
TheoreticalPaperManualSaveDTO
request
=
new
TheoreticalPaperManualSaveDTO
();
request
.
setLev
(
"污水四级"
);
request
.
setName
(
"旧版展示字段兼容卷"
);
request
.
setSequence
(
"顺序"
);
request
.
setStatus
(
"PUBLISHED"
);
request
.
setQuestions
(
Collections
.
singletonList
(
question
));
when
(
paperMapper
.
countAdminDuplicateName
(
request
.
getName
(),
null
)).
thenReturn
(
0
);
when
(
paperMapper
.
insert
(
any
(
TheoreticalPaperEntity
.
class
))).
thenAnswer
(
invocation
->
{
TheoreticalPaperEntity
paper
=
invocation
.
getArgument
(
0
);
paper
.
setId
(
"paper-legacy-rendered"
);
return
1
;
});
when
(
paperDetailService
.
saveBatch
(
any
())).
thenReturn
(
true
);
TheoreticalPaperVO
saved
=
new
TheoreticalPaperVO
();
saved
.
setId
(
"paper-legacy-rendered"
);
saved
.
setStatus
(
"PUBLISHED"
);
when
(
paperMapper
.
selectAdminDetail
(
"paper-legacy-rendered"
)).
thenReturn
(
saved
);
when
(
paperMapper
.
selectAdminQuestions
(
"paper-legacy-rendered"
))
.
thenReturn
(
Collections
.
singletonList
(
question
));
service
.
createManual
(
request
,
"管理员甲"
);
// 捕获真正交给 MyBatis-Plus 批量保存的对象,确保落库的是纯题干而不是页面展示串。
@SuppressWarnings
(
"unchecked"
)
ArgumentCaptor
<
Collection
<
TheoreticalPaperDetailEntity
>>
questionsCaptor
=
ArgumentCaptor
.
forClass
(
Collection
.
class
);
verify
(
paperDetailService
).
saveBatch
(
questionsCaptor
.
capture
());
TheoreticalPaperDetailEntity
persisted
=
questionsCaptor
.
getValue
().
iterator
().
next
();
assertEquals
(
stem
,
persisted
.
getProblem
());
assertEquals
(
question
.
getOptionA
(),
persisted
.
getOptionA
());
assertTrue
(
persisted
.
getProblem
().
length
()
<=
128
);
ArgumentCaptor
<
TheoreticalPaperEntity
>
paperCaptor
=
ArgumentCaptor
.
forClass
(
TheoreticalPaperEntity
.
class
);
verify
(
paperMapper
).
insert
(
paperCaptor
.
capture
());
assertEquals
(
"PUBLISHED"
,
paperCaptor
.
getValue
().
getStatus
());
}
@Test
@Test
void
automaticCreateShouldRejectWhenQuestionBankIsInsufficient
()
{
void
automaticCreateShouldRejectWhenQuestionBankIsInsufficient
()
{
TheoreticalPaperAutoSaveDTO
request
=
new
TheoreticalPaperAutoSaveDTO
();
TheoreticalPaperAutoSaveDTO
request
=
new
TheoreticalPaperAutoSaveDTO
();
...
...
Prev
1
2
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