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
169d9bfe
Commit
169d9bfe
authored
Nov 19, 2026
by
wujipeng
Browse files
优化项
parent
60e8951b
Changes
4
Hide whitespace changes
Inline
Side-by-side
practical-business/src/main/java/com/platform/business/service/impl/ClassAdminServiceImpl.java
View file @
169d9bfe
...
...
@@ -57,6 +57,7 @@ import java.util.LinkedHashSet;
import
java.util.List
;
import
java.util.Locale
;
import
java.util.Map
;
import
java.util.Objects
;
import
java.util.Set
;
import
java.util.TreeSet
;
import
java.util.TimeZone
;
...
...
@@ -188,6 +189,9 @@ public class ClassAdminServiceImpl implements ClassAdminService {
}
int
actualCount
=
classMapper
.
countAdminStudents
(
classId
);
validateSaveRequest
(
request
,
classId
,
actualCount
);
if
(
ClassAdminConstants
.
STATUS_ONGOING
.
equals
(
status
))
{
validateOngoingUpdate
(
existing
,
request
);
}
ClassEntity
entity
=
toEntity
(
request
);
entity
.
setId
(
classId
);
...
...
@@ -599,6 +603,31 @@ public class ClassAdminServiceImpl implements ClassAdminService {
}
}
/**
* 进行中的班级已经参与排课、考勤等业务,只允许维护仍可能发生变化的管理信息。
*
* <p>前端会将不可编辑字段置灰,但服务端仍必须逐项比对原始数据,防止调用者绕过
* 页面直接修改班级名称、工种、年度、等级或开始日期。结束日期只允许保持不变或
* 向后延长,避免已经生效的培训周期被缩短。</p>
*/
private
void
validateOngoingUpdate
(
ClassEntity
existing
,
ClassAdminSaveDTO
request
)
{
boolean
immutableFieldChanged
=
!
Objects
.
equals
(
trimToNull
(
existing
.
getName
()),
request
.
getName
())
||
!
Objects
.
equals
(
trimToNull
(
existing
.
getOccupation
()),
request
.
getOccupation
())
||
!
Objects
.
equals
(
existing
.
getTrainingYear
(),
request
.
getTrainingYear
())
||
!
Objects
.
equals
(
trimToNull
(
existing
.
getLevel
()),
String
.
valueOf
(
request
.
getLevelId
()))
||
!
Objects
.
equals
(
toLocalDate
(
existing
.
getStartDate
()),
toLocalDate
(
request
.
getStartDate
()));
if
(
immutableFieldChanged
)
{
throw
new
BusinessException
(
"进行中的班级仅允许修改结束日期、班主任、培训地点、计划人数和备注"
);
}
LocalDate
originalEndDate
=
toLocalDate
(
existing
.
getEndDate
());
LocalDate
requestedEndDate
=
toLocalDate
(
request
.
getEndDate
());
if
(
requestedEndDate
.
isBefore
(
originalEndDate
))
{
throw
new
BusinessException
(
"进行中班级的结束日期不能早于原结束日期"
);
}
}
/** 职业等级必须存在、未隐藏,并通过等级名称前缀确认所属工种。 */
private
void
validateLevel
(
Integer
levelId
,
String
occupation
)
{
SysLevelEntity
level
=
sysLevelService
.
getById
(
levelId
);
...
...
practical-business/src/main/java/com/platform/business/service/impl/CourseAdminServiceImpl.java
View file @
169d9bfe
...
...
@@ -33,8 +33,6 @@ import org.apache.poi.xwpf.usermodel.ParagraphAlignment;
import
org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow
;
import
org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTcPr
;
import
org.openxmlformats.schemas.wordprocessingml.x2006.main.CTVerticalJc
;
import
org.openxmlformats.schemas.wordprocessingml.x2006.main.CTVMerge
;
import
org.openxmlformats.schemas.wordprocessingml.x2006.main.STMerge
;
import
org.openxmlformats.schemas.wordprocessingml.x2006.main.STVerticalJc
;
import
org.apache.xmlbeans.XmlException
;
import
org.springframework.stereotype.Service
;
...
...
@@ -896,8 +894,12 @@ public class CourseAdminServiceImpl implements CourseAdminService {
}
/**
* 以参考文件的首条数据行为样式原型,逐组克隆课程行并替换内容。
* 同一排课组中的独立课程各占一行,共享字段按参考模板纵向合并。
* 以参考文件的首条数据行为样式原型,逐门课程克隆数据行并替换内容。
*
* <p>导入器按“一门课程一行”读取日期、课次、时段和课时,因此导出时每行必须写入
* 完整的课程字段,不能再把排课组公共列纵向合并。Word 的纵向合并续行在底层 XML
* 中只保留空单元格,旧实现导出的第二门课程会在回导时首先报“日期格式无法识别”;
* 即便继承日期,也无法从组汇总值还原每门课程各自的课次、时段和课时。</p>
*/
private
void
fillExportTable
(
XWPFDocument
document
,
CourseAdminDetailVO
detail
)
{
if
(
document
.
getTables
().
isEmpty
())
{
...
...
@@ -923,30 +925,21 @@ public class CourseAdminServiceImpl implements CourseAdminService {
if
(
items
.
isEmpty
())
{
continue
;
}
String
date
=
exportDateText
(
schedule
.
getDate
(),
schedule
.
getWeek
());
String
subjectTimes
=
valueOf
(
schedule
.
getSubjectTimes
());
String
timeFrames
=
exportGroupTimeFrames
(
items
);
String
hours
=
decimalText
(
schedule
.
getTotalHours
());
String
sequenceText
=
String
.
valueOf
(
sequence
++);
for
(
int
itemIndex
=
0
;
itemIndex
<
items
.
size
();
itemIndex
++)
{
CourseAdminScheduleVO
course
=
items
.
get
(
itemIndex
);
for
(
CourseAdminScheduleVO
course
:
items
)
{
XWPFTableRow
row
=
createTemplateRow
(
table
,
dataRowTemplateXml
);
boolean
first
=
itemIndex
==
0
;
writeTemplateCell
(
row
.
getCell
(
0
),
first
?
date
:
""
,
12
);
writeTemplateCell
(
row
.
getCell
(
1
),
first
?
subjectTimes
:
""
,
12
);
writeTemplateCell
(
row
.
getCell
(
2
),
first
?
timeFrames
:
""
,
9
);
writeTemplateCell
(
row
.
getCell
(
3
),
first
?
hours
:
""
,
12
);
// 课程通常沿用排课组日期;兼容历史数据缺少课程日期时再回退到组日期。
Date
courseDate
=
course
.
getDate
()
==
null
?
schedule
.
getDate
()
:
course
.
getDate
();
String
courseWeek
=
trimToNull
(
course
.
getWeek
())
==
null
?
schedule
.
getWeek
()
:
course
.
getWeek
();
writeTemplateCell
(
row
.
getCell
(
0
),
exportDateText
(
courseDate
,
courseWeek
),
12
);
writeTemplateCell
(
row
.
getCell
(
1
),
valueOf
(
course
.
getSubjectTimes
()),
12
);
writeTemplateCell
(
row
.
getCell
(
2
),
exportCourseTimeFrames
(
course
),
9
);
writeTemplateCell
(
row
.
getCell
(
3
),
decimalText
(
course
.
getSubjectHour
()),
12
);
writeTemplateCell
(
row
.
getCell
(
4
),
valueOf
(
course
.
getSubjectName
()),
12
);
writeTemplateCell
(
row
.
getCell
(
5
),
valueOf
(
course
.
getTeacherName
()),
12
);
writeTemplateCell
(
row
.
getCell
(
6
),
first
?
sequenceText
:
""
,
12
);
if
(
items
.
size
()
>
1
)
{
for
(
int
column
:
new
int
[]{
0
,
1
,
2
,
3
,
6
})
{
setVerticalMerge
(
row
.
getCell
(
column
),
first
);
}
}
writeTemplateCell
(
row
.
getCell
(
6
),
String
.
valueOf
(
sequence
++),
12
);
// 必须在替换文本后再挂入表格;POI挂入时会复制底层XML,之后修改旧包装对象不会生效。
table
.
addRow
(
row
);
}
...
...
@@ -994,14 +987,6 @@ public class CourseAdminServiceImpl implements CourseAdminService {
vertical
.
setVal
(
STVerticalJc
.
CENTER
);
}
private
void
setVerticalMerge
(
XWPFTableCell
cell
,
boolean
first
)
{
CTTcPr
properties
=
cell
.
getCTTc
().
isSetTcPr
()
?
cell
.
getCTTc
().
getTcPr
()
:
cell
.
getCTTc
().
addNewTcPr
();
CTVMerge
merge
=
properties
.
isSetVMerge
()
?
properties
.
getVMerge
()
:
properties
.
addNewVMerge
();
merge
.
setVal
(
first
?
STMerge
.
RESTART
:
STMerge
.
CONTINUE
);
}
private
String
exportDateText
(
Date
date
,
String
week
)
{
if
(
date
==
null
)
return
""
;
LocalDate
localDate
=
toLocalDate
(
date
);
...
...
@@ -1009,10 +994,16 @@ public class CourseAdminServiceImpl implements CourseAdminService {
return
localDate
.
getMonthValue
()
+
"/"
+
localDate
.
getDayOfMonth
()
+
resolvedWeek
;
}
private
String
exportGroupTimeFrames
(
List
<
CourseAdminScheduleVO
>
courses
)
{
return
courses
.
stream
()
.
flatMap
(
course
->
(
course
.
getTimeFrames
()
==
null
?
Collections
.<
String
>
emptyList
()
:
course
.
getTimeFrames
()).
stream
())
/**
* 将单门课程的结构化时段写回模板格式,确保导出的每一行都能独立导入。
* 历史查询结果若尚未填充结构化时段,则从数据库逗号串回退解析。
*/
private
String
exportCourseTimeFrames
(
CourseAdminScheduleVO
course
)
{
List
<
String
>
frames
=
course
.
getTimeFrames
();
if
(
frames
==
null
||
frames
.
isEmpty
())
{
frames
=
splitStoredFrames
(
course
.
getTimeFrame
());
}
return
frames
.
stream
()
.
filter
(
frame
->
trimToNull
(
frame
)
!=
null
)
.
distinct
()
.
sorted
(
Comparator
.
comparing
(
this
::
timeFrameStart
))
...
...
practical-business/src/test/java/com/platform/business/service/impl/ClassAdminServiceImplTest.java
View file @
169d9bfe
...
...
@@ -178,21 +178,69 @@ class ClassAdminServiceImplTest {
@Test
void
updateShouldAllowOngoingClass
()
{
LocalDate
today
=
LocalDate
.
now
(
ClassAdminConstants
.
BUSINESS_ZONE
);
ClassEntity
ongoing
=
new
ClassEntity
();
ongoing
.
setId
(
7
);
ongoing
.
setStartDate
(
Date
.
valueOf
(
today
.
minusDays
(
1
)));
ongoing
.
setEndDate
(
Date
.
valueOf
(
today
.
plusDays
(
30
)));
ClassEntity
ongoing
=
ongoingClass
(
today
);
when
(
classMapper
.
selectById
(
7
)).
thenReturn
(
ongoing
);
when
(
classMapper
.
countAdminStudents
(
7
)).
thenReturn
(
10
);
mockValidLevel
();
when
(
classMapper
.
countAdminDuplicateName
(
2026
,
"污水处理一级三班"
,
7
)).
thenReturn
(
0
);
when
(
classMapper
.
updateAdminClass
(
any
(
ClassEntity
.
class
))).
thenReturn
(
1
);
mockEmptyDetail
(
7
,
Date
.
valueOf
(
today
.
minusDays
(
1
)),
Date
.
valueOf
(
today
.
plusDays
(
3
0
)));
mockEmptyDetail
(
7
,
Date
.
valueOf
(
today
.
minusDays
(
1
)),
Date
.
valueOf
(
today
.
plusDays
(
3
1
)));
ClassAdminDetailVO
result
=
service
.
update
(
7
,
validRequest
());
ClassAdminSaveDTO
request
=
validRequest
();
// 进行中的班级保持固定字段不变,仅延长结束日期并修改允许维护的管理信息。
request
.
setStartDate
(
Date
.
valueOf
(
today
.
minusDays
(
1
)));
request
.
setEndDate
(
Date
.
valueOf
(
today
.
plusDays
(
31
)));
request
.
setLocation
(
"A302"
);
request
.
setCapacity
(
20
);
request
.
setRemark
(
"延长培训周期"
);
ClassAdminDetailVO
result
=
service
.
update
(
7
,
request
);
assertEquals
(
7
,
result
.
getId
());
verify
(
classMapper
).
updateAdminClass
(
any
(
ClassEntity
.
class
));
ArgumentCaptor
<
ClassEntity
>
captor
=
ArgumentCaptor
.
forClass
(
ClassEntity
.
class
);
verify
(
classMapper
).
updateAdminClass
(
captor
.
capture
());
assertEquals
(
Date
.
valueOf
(
today
.
plusDays
(
31
)),
captor
.
getValue
().
getEndDate
());
assertEquals
(
"A302"
,
captor
.
getValue
().
getLocation
());
}
@Test
void
updateShouldRejectShorterEndDateForOngoingClass
()
{
LocalDate
today
=
LocalDate
.
now
(
ClassAdminConstants
.
BUSINESS_ZONE
);
when
(
classMapper
.
selectById
(
7
)).
thenReturn
(
ongoingClass
(
today
));
when
(
classMapper
.
countAdminStudents
(
7
)).
thenReturn
(
10
);
mockValidLevel
();
when
(
classMapper
.
countAdminDuplicateName
(
2026
,
"污水处理一级三班"
,
7
)).
thenReturn
(
0
);
ClassAdminSaveDTO
request
=
validRequest
();
request
.
setStartDate
(
Date
.
valueOf
(
today
.
minusDays
(
1
)));
request
.
setEndDate
(
Date
.
valueOf
(
today
.
plusDays
(
29
)));
BusinessException
exception
=
assertThrows
(
BusinessException
.
class
,
()
->
service
.
update
(
7
,
request
));
assertEquals
(
"进行中班级的结束日期不能早于原结束日期"
,
exception
.
getMessage
());
verify
(
classMapper
,
never
()).
updateAdminClass
(
any
());
}
@Test
void
updateShouldRejectFixedFieldChangesForOngoingClass
()
{
LocalDate
today
=
LocalDate
.
now
(
ClassAdminConstants
.
BUSINESS_ZONE
);
when
(
classMapper
.
selectById
(
7
)).
thenReturn
(
ongoingClass
(
today
));
when
(
classMapper
.
countAdminStudents
(
7
)).
thenReturn
(
10
);
mockValidLevel
();
when
(
classMapper
.
countAdminDuplicateName
(
2026
,
"修改后的班级名称"
,
7
)).
thenReturn
(
0
);
ClassAdminSaveDTO
request
=
validRequest
();
request
.
setName
(
"修改后的班级名称"
);
request
.
setStartDate
(
Date
.
valueOf
(
today
.
minusDays
(
1
)));
request
.
setEndDate
(
Date
.
valueOf
(
today
.
plusDays
(
30
)));
BusinessException
exception
=
assertThrows
(
BusinessException
.
class
,
()
->
service
.
update
(
7
,
request
));
assertEquals
(
"进行中的班级仅允许修改结束日期、班主任、培训地点、计划人数和备注"
,
exception
.
getMessage
());
verify
(
classMapper
,
never
()).
updateAdminClass
(
any
());
}
@Test
...
...
@@ -324,4 +372,17 @@ class ClassAdminServiceImplTest {
entity
.
setEndDate
(
Date
.
valueOf
(
LocalDate
.
now
(
ClassAdminConstants
.
BUSINESS_ZONE
).
plusDays
(
30
)));
return
entity
;
}
/** 构造与validRequest固定字段一致的进行中班级,便于只验证本次编辑权限规则。 */
private
ClassEntity
ongoingClass
(
LocalDate
today
)
{
ClassEntity
entity
=
new
ClassEntity
();
entity
.
setId
(
7
);
entity
.
setName
(
"污水处理一级三班"
);
entity
.
setOccupation
(
"污水"
);
entity
.
setTrainingYear
(
2026
);
entity
.
setLevel
(
"1"
);
entity
.
setStartDate
(
Date
.
valueOf
(
today
.
minusDays
(
1
)));
entity
.
setEndDate
(
Date
.
valueOf
(
today
.
plusDays
(
30
)));
return
entity
;
}
}
practical-business/src/test/java/com/platform/business/service/impl/CourseAdminServiceImplTest.java
View file @
169d9bfe
...
...
@@ -40,6 +40,7 @@ import java.util.Collections;
import
java.util.List
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertFalse
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertNull
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertThrows
;
...
...
@@ -531,11 +532,14 @@ class CourseAdminServiceImplTest {
}
@Test
void
exportShouldReuseReferenceWordTemplateAnd
MergeScheduleGroup
()
throws
Exception
{
void
exportShouldReuseReferenceWordTemplateAnd
RemainImportable
()
throws
Exception
{
CourseAdminDetailVO
classDetail
=
new
CourseAdminDetailVO
();
classDetail
.
setClassId
(
1
);
classDetail
.
setClassName
(
"污泥处理工(四级)2026年1班"
);
when
(
classSubjectMapper
.
selectAdminCourseClass
(
1
)).
thenReturn
(
classDetail
);
when
(
classSubjectMapper
.
selectAdminCourseTeacherOptions
()).
thenReturn
(
Arrays
.
asList
(
new
ClassAdminOptionVO
(
"teacher-11"
,
"张三"
,
null
,
null
),
new
ClassAdminOptionVO
(
"teacher-12"
,
"李四"
,
null
,
null
)));
CourseAdminScheduleVO
morning
=
exportCourse
(
11
,
"group-1"
,
"09:00-10:20,10:40-12:00"
,
...
...
@@ -564,13 +568,32 @@ class CourseAdminServiceImplTest {
assertEquals
(
"课 程"
,
table
.
getRow
(
0
).
getCell
(
4
).
getText
());
assertEquals
(
3
,
table
.
getNumberOfRows
());
assertEquals
(
"4/22周三"
,
table
.
getRow
(
1
).
getCell
(
0
).
getText
());
assertEquals
(
"4/22周三"
,
table
.
getRow
(
2
).
getCell
(
0
).
getText
());
assertTrue
(
table
.
getRow
(
1
).
getCell
(
2
).
getText
().
contains
(
"09:00~10:20"
));
assertFalse
(
table
.
getRow
(
1
).
getCell
(
2
).
getText
().
contains
(
"13:00~14:20"
));
assertTrue
(
table
.
getRow
(
2
).
getCell
(
2
).
getText
().
contains
(
"13:00~14:20"
));
assertEquals
(
"污泥脱水工艺(实操)"
,
table
.
getRow
(
1
).
getCell
(
4
).
getText
());
assertEquals
(
"污泥处理设备操作(实操)"
,
table
.
getRow
(
2
).
getCell
(
4
).
getText
());
assertEquals
(
"restart"
,
table
.
getRow
(
1
).
getCell
(
0
).
getCTTc
()
.
getTcPr
().
getVMerge
().
getVal
().
toString
());
assertEquals
(
"continue"
,
table
.
getRow
(
2
).
getCell
(
0
).
getCTTc
()
.
getTcPr
().
getVMerge
().
getVal
().
toString
());
// 核心回归:把刚导出的文档直接交给同一套导入解析器,验证每门课程的
// 日期、独立时段和课时均可无损读取,而不是只检查Word外观相似。
ClassEntity
managedClass
=
new
ClassEntity
();
managedClass
.
setName
(
"污泥处理工(四级)2026年1班"
);
managedClass
.
setTrainingYear
(
2026
);
CourseAdminServiceImpl
.
ParsedImport
roundTrip
=
service
.
parseImportDocument
(
exported
,
managedClass
);
assertEquals
(
2
,
roundTrip
.
getCourses
().
size
());
assertEquals
(
Date
.
valueOf
(
LocalDate
.
of
(
2026
,
4
,
22
)),
roundTrip
.
getCourses
().
get
(
0
).
getDate
());
assertEquals
(
Arrays
.
asList
(
"09:00-10:20"
,
"10:40-12:00"
),
roundTrip
.
getCourses
().
get
(
0
).
getTimeFrames
());
assertEquals
(
Arrays
.
asList
(
"13:00-14:20"
,
"14:40-16:00"
),
roundTrip
.
getCourses
().
get
(
1
).
getTimeFrames
());
assertEquals
(
0
,
new
BigDecimal
(
"4.0"
).
compareTo
(
roundTrip
.
getCourses
().
get
(
0
).
getSubjectHour
()));
assertEquals
(
0
,
new
BigDecimal
(
"4.0"
).
compareTo
(
roundTrip
.
getCourses
().
get
(
1
).
getSubjectHour
()));
}
// 本地视觉核验时显式传入路径;常规CI不产生额外文件。
...
...
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