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
ad868040
Commit
ad868040
authored
Aug 26, 2026
by
wujipeng
Browse files
管理端-课程管理-优化
parent
9a033119
Changes
18
Hide whitespace changes
Inline
Side-by-side
practical-api/practical-business-api/src/main/java/com/platform/business/model/dto/CourseAdminBatchSaveDTO.java
View file @
ad868040
...
...
@@ -11,6 +11,14 @@ public class CourseAdminBatchSaveDTO {
/** 所属班级ID。 */
private
Integer
classId
;
/**
* 本批课程统一使用的课程类型。
*
* <p>新版页面在表格上方统一选择类型;为兼容旧客户端,行内仍可携带type,
* 但两处同时提交时必须保持一致。</p>
*/
private
String
type
;
/** 待新增课程,单次最多100节。 */
private
List
<
CourseAdminSaveDTO
>
courses
;
}
practical-api/practical-business-api/src/main/java/com/platform/business/model/dto/CourseAdminScheduleGroupSaveDTO.java
0 → 100644
View file @
ad868040
package
com.platform.business.model.dto
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
lombok.Data
;
import
java.util.Date
;
import
java.util.List
;
/** 新版编辑弹窗一次保存整行上午、下午课程的请求。 */
@Data
public
class
CourseAdminScheduleGroupSaveDTO
{
/** 排课组日期,组内所有独立课程使用同一天。 */
@JsonFormat
(
pattern
=
"yyyy-MM-dd"
,
timezone
=
"GMT+8"
)
private
Date
date
;
/** 一至两条课程,且上午、下午最多各一条。 */
private
List
<
CourseAdminScheduleItemSaveDTO
>
courses
;
}
practical-api/practical-business-api/src/main/java/com/platform/business/model/dto/CourseAdminScheduleItemSaveDTO.java
0 → 100644
View file @
ad868040
package
com.platform.business.model.dto
;
import
lombok.Data
;
import
java.math.BigDecimal
;
import
java.util.List
;
/**
* 编辑一个排课组时提交的独立上午或下午课程。
*
* <p>已有课程必须回传id以保留签到等业务引用;新增的上午或下午课程不传id。
* 日期统一放在排课组请求上,防止同一组出现不同日期。</p>
*/
@Data
public
class
CourseAdminScheduleItemSaveDTO
{
/** 已有课程ID;新增期间课程时为空。 */
private
Integer
id
;
/** 课次数量,按照新版页面允许0到40。 */
private
Integer
subjectTimes
;
/** 同一期间内的一个或多个HH:mm-HH:mm时间段。 */
private
List
<
String
>
timeFrames
;
/** 课时数,允许0到16并以0.5递增。 */
private
BigDecimal
subjectHour
;
private
String
subjectName
;
private
String
teacherId
;
private
String
location
;
private
String
type
;
private
String
remark
;
}
practical-api/practical-business-api/src/main/java/com/platform/business/model/entity/ClassSubjectEntity.java
View file @
ad868040
...
...
@@ -32,6 +32,14 @@ public class ClassSubjectEntity {
/** 所属班级ID。 */
private
int
classId
;
/**
* 页面排课行分组ID。
*
* <p>上午和下午课程仍各自保留独立主键,以便签到、请假和评价继续精确关联;
* 同一页面行内的课程通过本字段聚合,不改变任何历史{@code subject_id}关系。</p>
*/
private
String
scheduleGroupId
;
/** 服务端根据课程日期生成的中文星期,例如“周一”。 */
private
String
week
;
...
...
practical-api/practical-business-api/src/main/java/com/platform/business/model/vo/CourseAdminDetailVO.java
View file @
ad868040
...
...
@@ -32,6 +32,11 @@ public class CourseAdminDetailVO {
private
Integer
studentCount
;
private
Integer
courseCount
;
/** 页面聚合后的排课行数量。 */
private
Integer
scheduleCount
;
private
BigDecimal
totalHours
;
/** 兼容旧调用方的独立课程平铺数组。 */
private
List
<
CourseAdminScheduleVO
>
courses
;
/** 新版课程管理表格使用的排课组数组。 */
private
List
<
CourseAdminScheduleGroupVO
>
schedules
;
}
practical-api/practical-business-api/src/main/java/com/platform/business/model/vo/CourseAdminScheduleGroupVO.java
0 → 100644
View file @
ad868040
package
com.platform.business.model.vo
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
lombok.Data
;
import
java.math.BigDecimal
;
import
java.util.Date
;
import
java.util.List
;
/**
* 新版课程表中的一行排课。
*
* <p>一行通常包含上午、下午两个独立课程item;每个item仍拥有自己的课程ID,
* 本对象只负责页面聚合和汇总,不作为签到等业务的关联目标。</p>
*/
@Data
public
class
CourseAdminScheduleGroupVO
{
private
String
scheduleGroupId
;
private
Integer
classId
;
@JsonFormat
(
pattern
=
"yyyy-MM-dd"
,
timezone
=
"GMT+8"
)
private
Date
date
;
private
String
week
;
private
Integer
subjectTimes
;
private
BigDecimal
totalHours
;
private
List
<
CourseAdminScheduleVO
>
items
;
}
practical-api/practical-business-api/src/main/java/com/platform/business/model/vo/CourseAdminScheduleVO.java
View file @
ad868040
...
...
@@ -14,6 +14,8 @@ public class CourseAdminScheduleVO {
private
Integer
id
;
private
Integer
classId
;
/** 同一页面排课行内的上午、下午课程共享此ID。 */
private
String
scheduleGroupId
;
@JsonFormat
(
pattern
=
"yyyy-MM-dd"
,
timezone
=
"GMT+8"
)
private
Date
date
;
...
...
@@ -29,6 +31,8 @@ public class CourseAdminScheduleVO {
private
String
timeFrame
;
private
List
<
String
>
timeFrames
;
/** 根据时间段派生:AM、PM;历史跨上午下午记录返回ALL_DAY。 */
private
String
period
;
private
BigDecimal
subjectHour
;
private
String
subjectName
;
private
String
teacherId
;
...
...
practical-business/src/main/java/com/platform/business/controller/CourseAdminController.java
View file @
ad868040
...
...
@@ -2,11 +2,13 @@ package com.platform.business.controller;
import
com.platform.business.model.dto.CourseAdminBatchSaveDTO
;
import
com.platform.business.model.dto.CourseAdminSaveDTO
;
import
com.platform.business.model.dto.CourseAdminScheduleGroupSaveDTO
;
import
com.platform.business.model.entity.UserEntity
;
import
com.platform.business.model.vo.ClassAdminTreeVO
;
import
com.platform.business.model.vo.CourseAdminDetailVO
;
import
com.platform.business.model.vo.CourseAdminOptionsVO
;
import
com.platform.business.model.vo.CourseAdminScheduleVO
;
import
com.platform.business.model.vo.CourseAdminScheduleGroupVO
;
import
com.platform.business.service.AuthenticatedUserService
;
import
com.platform.business.service.CourseAdminService
;
import
com.platform.model.resp.Result
;
...
...
@@ -93,6 +95,16 @@ public class CourseAdminController {
return
Result
.
data
(
courseAdminService
.
update
(
courseId
,
body
));
}
@ApiOperation
(
"编辑同一排课行内的上午和下午课程"
)
@PutMapping
(
"/schedules/{scheduleGroupId}"
)
public
Result
<
CourseAdminScheduleGroupVO
>
updateSchedule
(
@PathVariable
(
"scheduleGroupId"
)
String
scheduleGroupId
,
@RequestBody
CourseAdminScheduleGroupSaveDTO
body
,
HttpServletRequest
request
)
{
requireAdmin
(
request
);
return
Result
.
data
(
courseAdminService
.
updateSchedule
(
scheduleGroupId
,
body
));
}
@ApiOperation
(
"删除未产生业务数据的课程"
)
@DeleteMapping
(
"/{courseId}"
)
public
Result
<
Boolean
>
delete
(
@PathVariable
(
"courseId"
)
Integer
courseId
,
...
...
practical-business/src/main/java/com/platform/business/mapper/ClassSubjectMapper.java
View file @
ad868040
...
...
@@ -58,11 +58,15 @@ public interface ClassSubjectMapper extends BaseMapper<ClassSubjectEntity> {
/** 查询单节课程并补充教师姓名。 */
CourseAdminScheduleVO
selectAdminCourseById
(
@Param
(
"courseId"
)
Integer
courseId
);
/** 查询一个排课组的全部独立课程;服务层在取得班级锁后会再次读取。 */
List
<
ClassSubjectEntity
>
selectAdminCourseGroupEntities
(
@Param
(
"scheduleGroupId"
)
String
scheduleGroupId
);
/** 查询同日、同班级或同教师的候选记录,具体时段重叠由Java精确判断。 */
List
<
ClassSubjectEntity
>
selectAdminConflictCandidates
(
@Param
(
"date"
)
Date
date
,
@Param
(
"classId"
)
Integer
classId
,
@Param
(
"teacherId"
)
String
teacherId
,
@Param
(
"excludeId"
)
Integer
excludeId
);
@Param
(
"excludeId
s
"
)
List
<
Integer
>
excludeId
s
);
/** 教师必须是未删除且在phone_role中具有教师角色的用户。 */
int
countAdminActiveTeacher
(
@Param
(
"teacherId"
)
String
teacherId
);
...
...
practical-business/src/main/java/com/platform/business/service/CourseAdminService.java
View file @
ad868040
...
...
@@ -2,10 +2,12 @@ package com.platform.business.service;
import
com.platform.business.model.dto.CourseAdminBatchSaveDTO
;
import
com.platform.business.model.dto.CourseAdminSaveDTO
;
import
com.platform.business.model.dto.CourseAdminScheduleGroupSaveDTO
;
import
com.platform.business.model.vo.ClassAdminTreeVO
;
import
com.platform.business.model.vo.CourseAdminDetailVO
;
import
com.platform.business.model.vo.CourseAdminOptionsVO
;
import
com.platform.business.model.vo.CourseAdminScheduleVO
;
import
com.platform.business.model.vo.CourseAdminScheduleGroupVO
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
...
...
@@ -25,6 +27,10 @@ public interface CourseAdminService {
CourseAdminScheduleVO
update
(
Integer
courseId
,
CourseAdminSaveDTO
request
);
/** 一次保存页面同一行内的一至两条上午、下午独立课程。 */
CourseAdminScheduleGroupVO
updateSchedule
(
String
scheduleGroupId
,
CourseAdminScheduleGroupSaveDTO
request
);
void
delete
(
Integer
courseId
);
void
export
(
Integer
classId
,
Date
startDate
,
Date
endDate
,
...
...
practical-business/src/main/java/com/platform/business/service/impl/ClassSubjectServiceImpl.java
View file @
ad868040
package
com.platform.business.service.impl
;
import
cn.hutool.core.collection.CollUtil
;
import
com.baomidou.mybatisplus.core.toolkit.IdWorker
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.platform.business.mapper.ClassSubjectMapper
;
import
com.platform.business.model.dto.ClassSubjectDTO
;
...
...
@@ -50,6 +51,7 @@ public class ClassSubjectServiceImpl extends ServiceImpl<ClassSubjectMapper, Cla
public
boolean
saveOrUpdateSubject
(
ClassSubjectDTO
classSubjectDTO
)
{
//先删除当天课程数据
baseMapper
.
deleteByClassIdAndDate
(
classSubjectDTO
);
ensureLegacyScheduleGroupIds
(
classSubjectDTO
.
getClassSubjectList
());
return
saveOrUpdateBatch
(
classSubjectDTO
.
getClassSubjectList
());
}
...
...
@@ -85,11 +87,27 @@ public class ClassSubjectServiceImpl extends ServiceImpl<ClassSubjectMapper, Cla
baseMapper
.
deleteByClassIdAndDate
(
classSubjectDTO
);
if
(
CollUtil
.
isNotEmpty
(
classSubjectDTO
.
getClassSubjectList
()))
{
//保存课程数据
ensureLegacyScheduleGroupIds
(
classSubjectDTO
.
getClassSubjectList
());
return
saveBatch
(
classSubjectDTO
.
getClassSubjectList
());
}
return
true
;
}
/**
* 为历史排课保存入口补齐新版数据库要求的排课组ID。
*
* <p>旧接口没有“上午/下午整行编辑”语义,因此每条新记录使用独立组ID;这既保持原有
* 保存行为,也避免把同日多条历史课程错误聚合。新版管理页面创建的组ID会原样保留。</p>
*/
private
void
ensureLegacyScheduleGroupIds
(
List
<
ClassSubjectEntity
>
courses
)
{
if
(
CollUtil
.
isEmpty
(
courses
))
return
;
for
(
ClassSubjectEntity
course
:
courses
)
{
if
(
course
!=
null
&&
StringUtils
.
isEmpty
(
course
.
getScheduleGroupId
()))
{
course
.
setScheduleGroupId
(
IdWorker
.
getIdStr
());
}
}
}
@Override
public
List
<
ClassSubjectVO
>
countByTeacherId
(
String
id
)
{
return
baseMapper
.
countByTeacherId
(
id
);
...
...
practical-business/src/main/java/com/platform/business/service/impl/CourseAdminServiceImpl.java
View file @
ad868040
package
com.platform.business.service.impl
;
import
com.baomidou.mybatisplus.core.toolkit.IdWorker
;
import
com.platform.business.constant.ClassAdminConstants
;
import
com.platform.business.constant.CourseAdminConstants
;
import
com.platform.business.mapper.ClassMapper
;
import
com.platform.business.mapper.ClassSubjectMapper
;
import
com.platform.business.model.dto.CourseAdminBatchSaveDTO
;
import
com.platform.business.model.dto.CourseAdminSaveDTO
;
import
com.platform.business.model.dto.CourseAdminScheduleGroupSaveDTO
;
import
com.platform.business.model.dto.CourseAdminScheduleItemSaveDTO
;
import
com.platform.business.model.entity.ClassEntity
;
import
com.platform.business.model.entity.ClassSubjectEntity
;
import
com.platform.business.model.vo.ClassAdminOptionVO
;
...
...
@@ -13,6 +16,7 @@ import com.platform.business.model.vo.ClassAdminTreeVO;
import
com.platform.business.model.vo.CourseAdminDetailVO
;
import
com.platform.business.model.vo.CourseAdminOptionsVO
;
import
com.platform.business.model.vo.CourseAdminScheduleVO
;
import
com.platform.business.model.vo.CourseAdminScheduleGroupVO
;
import
com.platform.business.service.ClassAdminService
;
import
com.platform.business.service.CourseAdminService
;
import
com.platform.exception.BusinessException
;
...
...
@@ -38,7 +42,12 @@ import java.util.ArrayList;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Objects
;
import
java.util.Set
;
import
java.util.TreeSet
;
import
java.util.stream.Collectors
;
...
...
@@ -60,6 +69,11 @@ public class CourseAdminServiceImpl implements CourseAdminService {
""
,
"周一"
,
"周二"
,
"周三"
,
"周四"
,
"周五"
,
"周六"
,
"周日"
};
private
static
final
LocalTime
NOON
=
LocalTime
.
NOON
;
private
static
final
String
PERIOD_AM
=
"AM"
;
private
static
final
String
PERIOD_PM
=
"PM"
;
private
static
final
String
PERIOD_ALL_DAY
=
"ALL_DAY"
;
@Resource
private
ClassSubjectMapper
classSubjectMapper
;
...
...
@@ -104,14 +118,16 @@ public class CourseAdminServiceImpl implements CourseAdminService {
BigDecimal
totalHours
=
BigDecimal
.
ZERO
;
for
(
CourseAdminScheduleVO
course
:
courses
)
{
// 数据库存储格式只在服务内部存在,接口始终返回结构化的时段数组。
course
.
setTimeFrames
(
splitStoredFrames
(
course
.
getTimeFrame
()));
populateCourseReadFields
(
course
);
if
(
course
.
getSubjectHour
()
!=
null
)
{
totalHours
=
totalHours
.
add
(
course
.
getSubjectHour
());
}
}
result
.
setCourses
(
courses
);
result
.
setCourseCount
(
courses
.
size
());
List
<
CourseAdminScheduleGroupVO
>
schedules
=
buildScheduleGroups
(
courses
);
result
.
setSchedules
(
schedules
);
result
.
setScheduleCount
(
schedules
.
size
());
result
.
setTotalHours
(
totalHours
);
return
result
;
}
...
...
@@ -130,15 +146,30 @@ public class CourseAdminServiceImpl implements CourseAdminService {
throw
new
BusinessException
(
"单次最多新增100节课程"
);
}
String
batchType
=
normalizeCourseType
(
request
.
getType
(),
false
);
ClassEntity
managedClass
=
lockAndLoadClass
(
request
.
getClassId
());
lockTeachers
(
collectTeacherIds
(
request
.
getCourses
()));
Date
now
=
new
Date
();
Map
<
LocalDate
,
String
>
groupIdsByDate
=
new
HashMap
<>();
Map
<
LocalDate
,
Set
<
String
>>
periodsByDate
=
new
HashMap
<>();
for
(
int
index
=
0
;
index
<
request
.
getCourses
().
size
();
index
++)
{
CourseAdminSaveDTO
item
=
request
.
getCourses
().
get
(
index
);
try
{
PreparedCourse
prepared
=
prepareCourse
(
item
,
request
.
getClassId
(),
managedClass
);
ensureNoConflict
(
prepared
.
entity
,
prepared
.
timeRanges
,
null
);
PreparedCourse
prepared
=
prepareCourse
(
item
,
request
.
getClassId
(),
managedClass
,
batchType
);
requireWritablePeriod
(
prepared
.
period
);
LocalDate
courseDate
=
toLocalDate
(
prepared
.
entity
.
getDate
());
Set
<
String
>
datePeriods
=
periodsByDate
.
computeIfAbsent
(
courseDate
,
ignored
->
new
HashSet
<>());
if
(!
datePeriods
.
add
(
prepared
.
period
))
{
throw
new
BusinessException
(
"同一天的上午或下午最多只能添加一节课程"
);
}
// 同一批请求中相同日期的上午、下午共享排课组;不同批次不会误合并历史数据。
prepared
.
entity
.
setScheduleGroupId
(
groupIdsByDate
.
computeIfAbsent
(
courseDate
,
ignored
->
IdWorker
.
getIdStr
()));
ensureNoConflict
(
prepared
.
entity
,
prepared
.
timeRanges
,
Collections
.
emptyList
());
prepared
.
entity
.
setCreateTime
(
now
);
prepared
.
entity
.
setUpdateTime
(
now
);
if
(
classSubjectMapper
.
insert
(
prepared
.
entity
)
!=
1
)
{
...
...
@@ -176,10 +207,14 @@ public class CourseAdminServiceImpl implements CourseAdminService {
request
==
null
?
null
:
request
.
getTeacherId
()));
rejectIfCourseHasDependencies
(
courseId
,
"课程已产生签到、请假或评价数据,不能直接编辑"
);
PreparedCourse
prepared
=
prepareCourse
(
request
,
existing
.
getClassId
(),
managedClass
);
PreparedCourse
prepared
=
prepareCourse
(
request
,
existing
.
getClassId
(),
managedClass
,
null
);
requireWritablePeriod
(
prepared
.
period
);
prepared
.
entity
.
setId
(
courseId
);
prepared
.
entity
.
setScheduleGroupId
(
resolveStoredGroupId
(
existing
));
prepared
.
entity
.
setUpdateTime
(
new
Date
());
ensureNoConflict
(
prepared
.
entity
,
prepared
.
timeRanges
,
courseId
);
ensureNoDuplicatePeriodInStoredGroup
(
existing
,
prepared
.
period
,
courseId
);
ensureNoConflict
(
prepared
.
entity
,
prepared
.
timeRanges
,
Collections
.
singletonList
(
courseId
));
if
(
classSubjectMapper
.
updateAdminCourse
(
prepared
.
entity
)
!=
1
)
{
throw
new
BusinessException
(
"课程信息已发生变化,请刷新后重试"
);
}
...
...
@@ -188,10 +223,162 @@ public class CourseAdminServiceImpl implements CourseAdminService {
if
(
result
==
null
)
{
throw
new
BusinessException
(
"课程更新成功但读取失败,请刷新后重试"
);
}
result
.
setTimeFrames
(
splitStoredFrames
(
result
.
getTimeFrame
())
);
populateCourseReadFields
(
result
);
return
result
;
}
/**
* 补齐独立课程的结构化时段与期间标识。
*
* <p>读取历史数据时不执行新版写入校验:旧记录可能同时覆盖上午、下午,
* 此类记录以ALL_DAY返回,管理员在无下游业务数据时可通过组编辑拆成两条。</p>
*/
private
void
populateCourseReadFields
(
CourseAdminScheduleVO
course
)
{
List
<
String
>
frames
=
splitStoredFrames
(
course
.
getTimeFrame
());
course
.
setTimeFrames
(
frames
);
if
(
trimToNull
(
course
.
getScheduleGroupId
())
==
null
)
{
course
.
setScheduleGroupId
(
"legacy-"
+
course
.
getId
());
}
try
{
course
.
setPeriod
(
resolvePeriod
(
normalizeTimeFrames
(
frames
)));
}
catch
(
BusinessException
ignored
)
{
// 列表必须能够打开并展示历史脏数据,精确格式错误会在编辑或冲突校验时明确提示。
course
.
setPeriod
(
PERIOD_ALL_DAY
);
}
}
/** 按稳定查询顺序聚合排课行,并精确累计组内课次和课时。 */
private
List
<
CourseAdminScheduleGroupVO
>
buildScheduleGroups
(
List
<
CourseAdminScheduleVO
>
courses
)
{
Map
<
String
,
CourseAdminScheduleGroupVO
>
groups
=
new
LinkedHashMap
<>();
for
(
CourseAdminScheduleVO
course
:
courses
)
{
String
groupId
=
course
.
getScheduleGroupId
();
CourseAdminScheduleGroupVO
group
=
groups
.
computeIfAbsent
(
groupId
,
ignored
->
{
CourseAdminScheduleGroupVO
value
=
new
CourseAdminScheduleGroupVO
();
value
.
setScheduleGroupId
(
groupId
);
value
.
setClassId
(
course
.
getClassId
());
value
.
setDate
(
course
.
getDate
());
value
.
setWeek
(
course
.
getWeek
());
value
.
setSubjectTimes
(
0
);
value
.
setTotalHours
(
BigDecimal
.
ZERO
);
value
.
setItems
(
new
ArrayList
<>());
return
value
;
});
group
.
getItems
().
add
(
course
);
if
(
course
.
getSubjectTimes
()
!=
null
)
{
group
.
setSubjectTimes
(
group
.
getSubjectTimes
()
+
course
.
getSubjectTimes
());
}
if
(
course
.
getSubjectHour
()
!=
null
)
{
group
.
setTotalHours
(
group
.
getTotalHours
().
add
(
course
.
getSubjectHour
()));
}
}
return
new
ArrayList
<>(
groups
.
values
());
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
CourseAdminScheduleGroupVO
updateSchedule
(
String
scheduleGroupId
,
CourseAdminScheduleGroupSaveDTO
request
)
{
String
normalizedGroupId
=
requireScheduleGroupId
(
scheduleGroupId
);
validateScheduleRequest
(
request
);
List
<
ClassSubjectEntity
>
snapshot
=
classSubjectMapper
.
selectAdminCourseGroupEntities
(
normalizedGroupId
);
if
(
snapshot
==
null
||
snapshot
.
isEmpty
())
{
throw
new
BusinessException
(
"排课记录不存在或已删除"
);
}
int
classId
=
requireSingleGroupClass
(
snapshot
);
ClassEntity
managedClass
=
lockAndLoadClass
(
classId
);
// 班级锁取得后重新读取,防止等待锁期间组内课程被其他管理员改删。
List
<
ClassSubjectEntity
>
existingCourses
=
classSubjectMapper
.
selectAdminCourseGroupEntities
(
normalizedGroupId
);
if
(
existingCourses
==
null
||
existingCourses
.
isEmpty
())
{
throw
new
BusinessException
(
"排课记录不存在或已删除"
);
}
if
(
requireSingleGroupClass
(
existingCourses
)
!=
classId
)
{
throw
new
BusinessException
(
"排课所属班级已发生变化,请刷新后重试"
);
}
Map
<
Integer
,
ClassSubjectEntity
>
existingById
=
existingCourses
.
stream
()
.
collect
(
Collectors
.
toMap
(
ClassSubjectEntity:
:
getId
,
value
->
value
));
List
<
Integer
>
existingIds
=
existingCourses
.
stream
()
.
map
(
ClassSubjectEntity:
:
getId
).
collect
(
Collectors
.
toList
());
lockTeachers
(
collectScheduleTeacherIds
(
existingCourses
,
request
.
getCourses
()));
Set
<
Integer
>
submittedIds
=
new
HashSet
<>();
Set
<
String
>
submittedPeriods
=
new
HashSet
<>();
List
<
PreparedCourse
>
preparedCourses
=
new
ArrayList
<>();
for
(
int
index
=
0
;
index
<
request
.
getCourses
().
size
();
index
++)
{
CourseAdminScheduleItemSaveDTO
item
=
request
.
getCourses
().
get
(
index
);
try
{
PreparedCourse
prepared
=
prepareCourse
(
toCourseSaveRequest
(
request
.
getDate
(),
item
),
classId
,
managedClass
,
null
);
requireWritablePeriod
(
prepared
.
period
);
if
(!
submittedPeriods
.
add
(
prepared
.
period
))
{
throw
new
BusinessException
(
"上午或下午最多只能保留一节课程"
);
}
prepared
.
entity
.
setScheduleGroupId
(
normalizedGroupId
);
if
(
item
.
getId
()
!=
null
)
{
ClassSubjectEntity
existing
=
existingById
.
get
(
item
.
getId
());
if
(
existing
==
null
)
{
throw
new
BusinessException
(
"课程ID不属于当前排课组"
);
}
if
(!
submittedIds
.
add
(
item
.
getId
()))
{
throw
new
BusinessException
(
"同一课程ID不能重复提交"
);
}
prepared
.
entity
.
setId
(
item
.
getId
());
if
(!
sameCourseContent
(
existing
,
prepared
.
entity
)
&&
hasCourseDependencies
(
item
.
getId
()))
{
throw
new
BusinessException
(
"课程已产生签到、请假或评价数据,不能修改"
);
}
}
preparedCourses
.
add
(
prepared
);
}
catch
(
BusinessException
e
)
{
throw
new
BusinessException
(
"第"
+
(
index
+
1
)
+
"节课程:"
+
e
.
getMessage
());
}
}
// 请求未回传的旧item表示删除;有下游数据时必须阻止删除,避免产生孤立业务记录。
List
<
ClassSubjectEntity
>
removedCourses
=
existingCourses
.
stream
()
.
filter
(
existing
->
!
submittedIds
.
contains
(
existing
.
getId
()))
.
collect
(
Collectors
.
toList
());
for
(
ClassSubjectEntity
removed
:
removedCourses
)
{
rejectIfCourseHasDependencies
(
removed
.
getId
(),
"课程已产生签到、请假或评价数据,不能从排课中删除"
);
}
// 组内旧记录全部排除,再用规范化后的新快照逐条校验外部班级、教师冲突。
for
(
PreparedCourse
prepared
:
preparedCourses
)
{
ensureNoConflict
(
prepared
.
entity
,
prepared
.
timeRanges
,
existingIds
);
}
Date
now
=
new
Date
();
for
(
PreparedCourse
prepared
:
preparedCourses
)
{
prepared
.
entity
.
setUpdateTime
(
now
);
if
(
prepared
.
entity
.
getId
()
==
null
)
{
prepared
.
entity
.
setCreateTime
(
now
);
if
(
classSubjectMapper
.
insert
(
prepared
.
entity
)
!=
1
)
{
throw
new
BusinessException
(
"课程新增失败,请稍后重试"
);
}
}
else
if
(
classSubjectMapper
.
updateAdminCourse
(
prepared
.
entity
)
!=
1
)
{
throw
new
BusinessException
(
"课程信息已发生变化,请刷新后重试"
);
}
}
for
(
ClassSubjectEntity
removed
:
removedCourses
)
{
if
(
classSubjectMapper
.
deleteById
(
removed
.
getId
())
!=
1
)
{
throw
new
BusinessException
(
"课程信息已发生变化,请刷新后重试"
);
}
}
CourseAdminDetailVO
refreshed
=
detail
(
classId
,
null
,
null
);
return
refreshed
.
getSchedules
().
stream
()
.
filter
(
group
->
normalizedGroupId
.
equals
(
group
.
getScheduleGroupId
()))
.
findFirst
()
.
orElseThrow
(()
->
new
BusinessException
(
"课程保存成功但读取失败,请刷新后重试"
));
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
delete
(
Integer
courseId
)
{
...
...
@@ -233,14 +420,16 @@ public class CourseAdminServiceImpl implements CourseAdminService {
response
.
getOutputStream
(),
StandardCharsets
.
UTF_8
));
// Excel识别UTF-8 CSV依赖BOM,否则中文可能按本地ANSI编码打开并出现乱码。
writer
.
write
(
'\ufeff'
);
writeCsvRow
(
writer
,
"序号"
,
"日期"
,
"星期"
,
"课次"
,
"时段"
,
"课时"
,
writeCsvRow
(
writer
,
"序号"
,
"排课组ID"
,
"日期"
,
"星期"
,
"期间"
,
"课次"
,
"时段"
,
"课时"
,
"课程名称"
,
"课程类型"
,
"授课教师"
,
"上课地点"
,
"备注"
);
int
sequence
=
1
;
for
(
CourseAdminScheduleVO
course
:
detail
.
getCourses
())
{
writeCsvRow
(
writer
,
String
.
valueOf
(
sequence
++),
course
.
getScheduleGroupId
(),
formatDate
(
course
.
getDate
()),
course
.
getWeek
(),
course
.
getPeriod
(),
valueOf
(
course
.
getSubjectTimes
()),
String
.
join
(
" / "
,
course
.
getTimeFrames
()),
valueOf
(
course
.
getSubjectHour
()),
...
...
@@ -258,7 +447,7 @@ public class CourseAdminServiceImpl implements CourseAdminService {
* 校验表单、规范字符串和时段,并构建只包含可写字段的实体。
*/
private
PreparedCourse
prepareCourse
(
CourseAdminSaveDTO
request
,
Integer
classId
,
ClassEntity
managedClass
)
{
ClassEntity
managedClass
,
String
batchType
)
{
if
(
request
==
null
)
{
throw
new
BusinessException
(
"课程信息不能为空"
);
}
...
...
@@ -268,16 +457,16 @@ public class CourseAdminServiceImpl implements CourseAdminService {
validateCourseDate
(
request
.
getDate
(),
managedClass
);
if
(
request
.
getSubjectTimes
()
==
null
||
request
.
getSubjectTimes
()
<
1
||
request
.
getSubjectTimes
()
<
0
||
request
.
getSubjectTimes
()
>
CourseAdminConstants
.
MAX_SUBJECT_TIMES
)
{
throw
new
BusinessException
(
"课次必须在
1
到40之间"
);
throw
new
BusinessException
(
"课次必须在
0
到40之间"
);
}
BigDecimal
hours
=
request
.
getSubjectHour
();
if
(
hours
==
null
||
hours
.
compareTo
(
new
BigDecimal
(
"0.5"
)
)
<
0
if
(
hours
==
null
||
hours
.
compareTo
(
BigDecimal
.
ZERO
)
<
0
||
hours
.
compareTo
(
new
BigDecimal
(
"16"
))
>
0
||
hours
.
multiply
(
new
BigDecimal
(
"2"
)).
stripTrailingZeros
().
scale
()
>
0
)
{
throw
new
BusinessException
(
"课时必须在0
.5
到16之间并以0.5递增"
);
throw
new
BusinessException
(
"课时必须在0到16之间并以0.5递增"
);
}
String
subjectName
=
requireText
(
request
.
getSubjectName
(),
"课程名称"
,
...
...
@@ -286,15 +475,18 @@ public class CourseAdminServiceImpl implements CourseAdminService {
if
(
classSubjectMapper
.
countAdminActiveTeacher
(
teacherId
)
!=
1
)
{
throw
new
BusinessException
(
"所选授课教师不存在、已停用或不具有教师角色"
);
}
String
t
ype
=
requireText
(
request
.
getType
(),
"课程类型"
,
16
);
if
(
!
CourseAdminConstants
.
COURSE_TYPES
.
contains
(
t
ype
))
{
throw
new
BusinessException
(
"课程类型
只支持理论、实训或考核
"
);
String
rowT
ype
=
normalizeCourseType
(
request
.
getType
(),
false
);
if
(
batchType
!=
null
&&
rowType
!=
null
&&
!
batchType
.
equals
(
rowT
ype
))
{
throw
new
BusinessException
(
"
行内
课程类型
必须与批次课程类型一致
"
);
}
String
type
=
batchType
==
null
?
rowType
:
batchType
;
if
(
type
==
null
)
throw
new
BusinessException
(
"课程类型不能为空"
);
String
location
=
optionalText
(
request
.
getLocation
(),
"上课地点"
,
CourseAdminConstants
.
MAX_LOCATION_LENGTH
);
String
remark
=
optionalText
(
request
.
getRemark
(),
"课程备注"
,
CourseAdminConstants
.
MAX_REMARK_LENGTH
);
List
<
TimeRange
>
ranges
=
normalizeTimeFrames
(
request
.
getTimeFrames
());
String
period
=
resolvePeriod
(
ranges
);
ClassSubjectEntity
entity
=
new
ClassSubjectEntity
();
entity
.
setClassId
(
classId
);
...
...
@@ -309,7 +501,7 @@ public class CourseAdminServiceImpl implements CourseAdminService {
entity
.
setLocation
(
location
);
entity
.
setType
(
type
);
entity
.
setRemark
(
remark
);
return
new
PreparedCourse
(
entity
,
ranges
);
return
new
PreparedCourse
(
entity
,
ranges
,
period
);
}
/**
...
...
@@ -317,9 +509,9 @@ public class CourseAdminServiceImpl implements CourseAdminService {
* 相邻时段(例如10:00结束、10:00开始)允许保存。
*/
private
void
ensureNoConflict
(
ClassSubjectEntity
subject
,
List
<
TimeRange
>
newRanges
,
Integer
excludeId
)
{
List
<
Integer
>
excludeId
s
)
{
List
<
ClassSubjectEntity
>
candidates
=
classSubjectMapper
.
selectAdminConflictCandidates
(
subject
.
getDate
(),
subject
.
getClassId
(),
subject
.
getTeacherId
(),
excludeId
);
subject
.
getDate
(),
subject
.
getClassId
(),
subject
.
getTeacherId
(),
excludeId
s
);
if
(
candidates
==
null
)
{
return
;
}
...
...
@@ -374,6 +566,26 @@ public class CourseAdminServiceImpl implements CourseAdminService {
return
normalizeTimeFrames
(
frames
);
}
/**
* 根据全部时间段判断课程期间。12:00结束仍属于上午,12:00开始属于下午;
* 只要一行同时覆盖两个期间或有单段跨越中午,就标记为ALL_DAY。
*/
private
String
resolvePeriod
(
List
<
TimeRange
>
ranges
)
{
boolean
allMorning
=
ranges
.
stream
()
.
allMatch
(
range
->
!
range
.
end
.
isAfter
(
NOON
));
if
(
allMorning
)
return
PERIOD_AM
;
boolean
allAfternoon
=
ranges
.
stream
()
.
allMatch
(
range
->
!
range
.
start
.
isBefore
(
NOON
));
return
allAfternoon
?
PERIOD_PM
:
PERIOD_ALL_DAY
;
}
/** 新版写接口要求一行只表示上午或下午,避免拆分时无法可靠分摊课时。 */
private
void
requireWritablePeriod
(
String
period
)
{
if
(
PERIOD_ALL_DAY
.
equals
(
period
))
{
throw
new
BusinessException
(
"同一行时间段不能同时跨上午和下午,请拆成两行提交"
);
}
}
private
TimeRange
parseTimeRange
(
String
value
)
{
String
normalized
=
trimToNull
(
value
);
if
(
normalized
==
null
)
{
...
...
@@ -419,6 +631,75 @@ public class CourseAdminServiceImpl implements CourseAdminService {
return
managedClass
;
}
private
void
validateScheduleRequest
(
CourseAdminScheduleGroupSaveDTO
request
)
{
if
(
request
==
null
)
{
throw
new
BusinessException
(
"排课信息不能为空"
);
}
if
(
request
.
getDate
()
==
null
)
{
throw
new
BusinessException
(
"课程日期不能为空"
);
}
if
(
request
.
getCourses
()
==
null
||
request
.
getCourses
().
isEmpty
())
{
throw
new
BusinessException
(
"排课组至少需要保留一节课程"
);
}
if
(
request
.
getCourses
().
size
()
>
2
)
{
throw
new
BusinessException
(
"排课组最多包含上午、下午两节课程"
);
}
}
/** 把组级日期与item字段合成为原有单课程校验模型,保证新旧入口规则一致。 */
private
CourseAdminSaveDTO
toCourseSaveRequest
(
Date
date
,
CourseAdminScheduleItemSaveDTO
item
)
{
if
(
item
==
null
)
throw
new
BusinessException
(
"课程信息不能为空"
);
CourseAdminSaveDTO
request
=
new
CourseAdminSaveDTO
();
request
.
setDate
(
date
);
request
.
setSubjectTimes
(
item
.
getSubjectTimes
());
request
.
setTimeFrames
(
item
.
getTimeFrames
());
request
.
setSubjectHour
(
item
.
getSubjectHour
());
request
.
setSubjectName
(
item
.
getSubjectName
());
request
.
setTeacherId
(
item
.
getTeacherId
());
request
.
setLocation
(
item
.
getLocation
());
request
.
setType
(
item
.
getType
());
request
.
setRemark
(
item
.
getRemark
());
return
request
;
}
/** 排课组异常关联多个班级时拒绝写入,避免一次请求跨班修改数据。 */
private
int
requireSingleGroupClass
(
List
<
ClassSubjectEntity
>
courses
)
{
int
classId
=
courses
.
get
(
0
).
getClassId
();
if
(
classId
<=
0
||
courses
.
stream
().
anyMatch
(
item
->
item
.
getClassId
()
!=
classId
))
{
throw
new
BusinessException
(
"排课组数据异常,请联系管理员修复"
);
}
return
classId
;
}
private
String
requireScheduleGroupId
(
String
scheduleGroupId
)
{
String
normalized
=
requireText
(
scheduleGroupId
,
"排课组ID"
,
32
);
return
normalized
;
}
/**
* 旧单课程编辑接口也遵守“上午、下午各一条”约束,防止绕过组接口写入重复期间。
*/
private
void
ensureNoDuplicatePeriodInStoredGroup
(
ClassSubjectEntity
existing
,
String
newPeriod
,
Integer
excludeId
)
{
String
groupId
=
trimToNull
(
existing
.
getScheduleGroupId
());
if
(
groupId
==
null
)
return
;
List
<
ClassSubjectEntity
>
siblings
=
classSubjectMapper
.
selectAdminCourseGroupEntities
(
groupId
);
if
(
siblings
==
null
)
return
;
for
(
ClassSubjectEntity
sibling
:
siblings
)
{
if
(
Objects
.
equals
(
sibling
.
getId
(),
excludeId
))
continue
;
String
siblingPeriod
=
resolvePeriod
(
normalizeStoredTimeFrames
(
sibling
.
getTimeFrame
()));
if
(
newPeriod
.
equals
(
siblingPeriod
))
{
throw
new
BusinessException
(
"当前排课组已存在同一上午或下午课程"
);
}
}
}
private
String
resolveStoredGroupId
(
ClassSubjectEntity
existing
)
{
String
groupId
=
trimToNull
(
existing
.
getScheduleGroupId
());
return
groupId
==
null
?
"legacy-"
+
existing
.
getId
()
:
groupId
;
}
private
void
lockTeachers
(
List
<
String
>
teacherIds
)
{
if
(!
teacherIds
.
isEmpty
())
{
classSubjectMapper
.
lockAdminCourseTeachers
(
teacherIds
);
...
...
@@ -435,6 +716,23 @@ public class CourseAdminServiceImpl implements CourseAdminService {
return
new
ArrayList
<>(
teacherIds
);
}
private
List
<
String
>
collectScheduleTeacherIds
(
List
<
ClassSubjectEntity
>
existing
,
List
<
CourseAdminScheduleItemSaveDTO
>
requests
)
{
Set
<
String
>
teacherIds
=
new
TreeSet
<>();
for
(
ClassSubjectEntity
course
:
existing
)
{
if
(
trimToNull
(
course
.
getTeacherId
())
!=
null
)
{
teacherIds
.
add
(
course
.
getTeacherId
().
trim
());
}
}
for
(
CourseAdminScheduleItemSaveDTO
request
:
requests
)
{
if
(
request
!=
null
&&
trimToNull
(
request
.
getTeacherId
())
!=
null
)
{
teacherIds
.
add
(
request
.
getTeacherId
().
trim
());
}
}
return
new
ArrayList
<>(
teacherIds
);
}
private
List
<
String
>
collectTeacherIds
(
String
first
,
String
second
)
{
Set
<
String
>
teacherIds
=
new
TreeSet
<>();
if
(
trimToNull
(
first
)
!=
null
)
teacherIds
.
add
(
first
.
trim
());
...
...
@@ -462,11 +760,46 @@ public class CourseAdminServiceImpl implements CourseAdminService {
}
private
void
rejectIfCourseHasDependencies
(
Integer
courseId
,
String
message
)
{
if
(
classSubjectMapper
.
countAdmin
CourseDependencies
(
courseId
)
>
0
)
{
if
(
has
CourseDependencies
(
courseId
))
{
throw
new
BusinessException
(
message
);
}
}
private
boolean
hasCourseDependencies
(
Integer
courseId
)
{
return
classSubjectMapper
.
countAdminCourseDependencies
(
courseId
)
>
0
;
}
/**
* 判断有业务引用的课程是否被实质修改。数据库时段先规范化后比较,避免仅分隔符不同
* 被误判成修改;BigDecimal忽略无意义的小数位差异。
*/
private
boolean
sameCourseContent
(
ClassSubjectEntity
existing
,
ClassSubjectEntity
submitted
)
{
String
existingFrames
=
normalizeStoredTimeFrames
(
existing
.
getTimeFrame
()).
stream
()
.
map
(
TimeRange:
:
asText
).
collect
(
Collectors
.
joining
(
","
));
return
toLocalDate
(
existing
.
getDate
()).
equals
(
toLocalDate
(
submitted
.
getDate
()))
&&
existing
.
getSubjectTimes
()
==
submitted
.
getSubjectTimes
()
&&
existingFrames
.
equals
(
submitted
.
getTimeFrame
())
&&
sameDecimal
(
existing
.
getSubjectHour
(),
submitted
.
getSubjectHour
())
&&
Objects
.
equals
(
trimToNull
(
existing
.
getSubjectName
()),
submitted
.
getSubjectName
())
&&
Objects
.
equals
(
trimToNull
(
existing
.
getTeacherId
()),
submitted
.
getTeacherId
())
&&
Objects
.
equals
(
trimToNull
(
existing
.
getLocation
()),
submitted
.
getLocation
())
&&
Objects
.
equals
(
trimToNull
(
existing
.
getType
()),
submitted
.
getType
())
&&
Objects
.
equals
(
trimToNull
(
existing
.
getRemark
()),
submitted
.
getRemark
());
}
private
boolean
sameDecimal
(
BigDecimal
left
,
BigDecimal
right
)
{
return
left
==
null
?
right
==
null
:
right
!=
null
&&
left
.
compareTo
(
right
)
==
0
;
}
private
String
normalizeCourseType
(
String
value
,
boolean
required
)
{
String
type
=
optionalText
(
value
,
"课程类型"
,
16
);
if
(
type
==
null
&&
required
)
throw
new
BusinessException
(
"课程类型不能为空"
);
if
(
type
!=
null
&&
!
CourseAdminConstants
.
COURSE_TYPES
.
contains
(
type
))
{
throw
new
BusinessException
(
"课程类型只支持理论、实训或考核"
);
}
return
type
;
}
private
String
chineseWeekday
(
Date
date
)
{
DayOfWeek
day
=
toLocalDate
(
date
).
getDayOfWeek
();
return
CHINESE_WEEKDAYS
[
day
.
getValue
()];
...
...
@@ -568,10 +901,13 @@ public class CourseAdminServiceImpl implements CourseAdminService {
private
static
final
class
PreparedCourse
{
private
final
ClassSubjectEntity
entity
;
private
final
List
<
TimeRange
>
timeRanges
;
private
final
String
period
;
private
PreparedCourse
(
ClassSubjectEntity
entity
,
List
<
TimeRange
>
timeRanges
)
{
private
PreparedCourse
(
ClassSubjectEntity
entity
,
List
<
TimeRange
>
timeRanges
,
String
period
)
{
this
.
entity
=
entity
;
this
.
timeRanges
=
timeRanges
;
this
.
period
=
period
;
}
}
...
...
practical-business/src/main/resources/com/platform/business/mapper/ClassSubjectMapper.xml
View file @
ad868040
...
...
@@ -335,6 +335,7 @@
select
subject.id,
subject.class_id as classId,
subject.schedule_group_id as scheduleGroupId,
subject.date,
subject.week,
subject.subject_times as subjectTimes,
...
...
@@ -364,6 +365,7 @@
select
subject.id,
subject.class_id as classId,
subject.schedule_group_id as scheduleGroupId,
subject.date,
subject.week,
subject.subject_times as subjectTimes,
...
...
@@ -382,6 +384,21 @@
where subject.id = #{courseId}
</select>
<!--
排课组编辑需要读取组内全部独立课程。这里不直接FOR UPDATE:服务层先根据快照确定班级,
锁定班级行后再执行本查询,从而让同一班级的新增、编辑、删除按统一顺序串行。
-->
<select
id=
"selectAdminCourseGroupEntities"
resultType=
"com.platform.business.model.entity.ClassSubjectEntity"
>
select
id, class_id, schedule_group_id, date, week, subject_times, time_frame,
subject_hour, subject_name, teacher_id, location, type, remark,
create_time, update_time
from class_subject
where schedule_group_id = #{scheduleGroupId}
order by date asc, time_frame asc, id asc
</select>
<!-- SQL先按日期和资源范围缩小候选集合,时段文本的精确重叠判断交给服务层。 -->
<select
id=
"selectAdminConflictCandidates"
resultType=
"com.platform.business.model.entity.ClassSubjectEntity"
>
...
...
@@ -390,8 +407,11 @@
from class_subject
where date = #{date}
and (class_id = #{classId} or teacher_id = #{teacherId})
<if
test=
"excludeId != null"
>
and id != #{excludeId}
<if
test=
"excludeIds != null and excludeIds.size() > 0"
>
and id not in
<foreach
collection=
"excludeIds"
item=
"excludeId"
open=
"("
close=
")"
separator=
","
>
#{excludeId}
</foreach>
</if>
order by id
</select>
...
...
@@ -448,6 +468,7 @@
location = #{location,jdbcType=VARCHAR},
type = #{type},
remark = #{remark,jdbcType=VARCHAR},
schedule_group_id = #{scheduleGroupId},
update_time = #{updateTime}
where id = #{id}
</update>
...
...
practical-business/src/main/resources/course-management-api.md
View file @
ad868040
# 管理员端课程管理接口
接口统一使用
`/class/subject/admin`
前缀,所有请求都必须携带
`Authorization`
。服务端从
JWT解析当前用户
,
并校验
`phone_role.role_name=
管理员
`
,不接受客户端提交管理员用户ID。
JWT解析当前用户并校验管理员
角色
,不接受客户端提交管理员用户ID。
部署前依次执行:
1.
`src/main/resources/sql/class_management.sql`
2.
`src/main/resources/sql/course_management.sql`
第二个脚本将
`class_subject.subject_hour`
调整为
`decimal(5,1)`
,补充创建/更新时间和班级、
教师日期索引。两个脚本都可重复执行。
课程脚本会补充
`class_subject.schedule_group_id`
、审计列和查询索引。上午、下午课程仍分别
保存为独立
`class_subject`
记录,因此原有签到、请假和评价表继续使用课程
`id`
,不需要迁移
任何业务外键。旧课程会回填为独立排课组,避免把同日历史记录错误合并。
## 1. 班级导航树
...
...
@@ -23,41 +24,78 @@ JWT解析当前用户,并校验 `phone_role.role_name=管理员`,不接受
`GET /class/subject/admin/options`
返回有效授课教师和固定课程类型:
`理论`
、
`实训`
、
`考核`
。教师选项的
`value`
是用户ID,
`label`
是姓名,
`extra`
是手机号;
保存时必须提交ID,不能提交教师姓名。
`label`
是姓名,保存时必须提交ID,不能提交教师姓名。
## 3. 查询班级课程表
`GET /class/subject/admin/classes/{classId}`
可选参数:
`startDate=2026-09-01&endDate=2026-09-30`
。返回班级名称、工种、年度、等级、
培训起止日期、学期展示值
`termName`
、学员人数、课程数量、总课时和课程数组。
`termName`
按开班月份生成(1~6月为春季、7~12月为秋季)。每节课程示例:
可选参数:
`startDate=2026-09-01&endDate=2026-09-30`
。
响应同时保留两种数据结构:
-
`courses`
:独立课程平铺数组,兼容旧调用方;
-
`schedules`
:新版页面使用的排课组数组,同一行的上午、下午课程位于
`items`
中。
```
json
{
"id"
:
1001
,
"classId"
:
10
,
"date"
:
"2026-09-08"
,
"week"
:
"周二"
,
"subjectTimes"
:
2
,
"timeFrames"
:
[
"09:00-10:20"
,
"10:40-12:00"
],
"subjectHour"
:
2.0
,
"subjectName"
:
"水污染知识"
,
"teacherId"
:
"1900000000000000001"
,
"teacherName"
:
"王建国"
,
"location"
:
"A栋302"
,
"type"
:
"理论"
,
"remark"
:
null
"className"
:
"污水处理一级一班"
,
"termName"
:
"2026 秋"
,
"studentCount"
:
35
,
"courseCount"
:
2
,
"scheduleCount"
:
1
,
"totalHours"
:
4.0
,
"courses"
:
[
{
"id"
:
1001
,
"scheduleGroupId"
:
"1900000000000000100"
,
"date"
:
"2026-09-08"
,
"week"
:
"周二"
,
"period"
:
"AM"
,
"subjectTimes"
:
2
,
"timeFrames"
:
[
"09:00-10:20"
,
"10:40-12:00"
],
"subjectHour"
:
2.0
,
"subjectName"
:
"水污染知识"
,
"teacherId"
:
"1900000000000000001"
,
"teacherName"
:
"王建国"
,
"type"
:
"理论"
}
],
"schedules"
:
[
{
"scheduleGroupId"
:
"1900000000000000100"
,
"classId"
:
10
,
"date"
:
"2026-09-08"
,
"week"
:
"周二"
,
"subjectTimes"
:
4
,
"totalHours"
:
4.0
,
"items"
:
[
{
"id"
:
1001
,
"period"
:
"AM"
,
"subjectName"
:
"水污染知识"
},
{
"id"
:
1002
,
"period"
:
"PM"
,
"subjectName"
:
"污水处理工艺"
}
]
}
]
}
```
`period`
取值:
-
`AM`
:全部时段均在12:00前结束;
-
`PM`
:全部时段均从12:00或之后开始;
-
`ALL_DAY`
:仅用于兼容历史跨上午、下午记录,新写接口不接受此类型。
## 4. 批量新增课程
`POST /class/subject/admin/batch`
新版页面在批次顶部统一选择课程类型,每行分别选择上课日期。同一请求中日期相同的上午、
下午行会自动获得同一个
`scheduleGroupId`
。
```
json
{
"classId"
:
10
,
"type"
:
"理论"
,
"courses"
:
[
{
"date"
:
"2026-09-08"
,
...
...
@@ -67,40 +105,84 @@ JWT解析当前用户,并校验 `phone_role.role_name=管理员`,不接受
"subjectName"
:
"水污染知识"
,
"teacherId"
:
"1900000000000000001"
,
"location"
:
"A栋302"
,
"type"
:
"理论"
,
"remark"
:
"第一章"
},
{
"date"
:
"2026-09-08"
,
"subjectTimes"
:
2
,
"timeFrames"
:
[
"13:00-14:20"
,
"14:40-16:00"
],
"subjectHour"
:
2.0
,
"subjectName"
:
"污水处理工艺"
,
"teacherId"
:
"1900000000000000002"
,
"location"
:
"A栋302"
}
]
}
```
-
单次至少1节、最多100节。
-
课程日期必须位于班级培训起止日期内;星期由服务端根据日期生成。
-
课次为1~40;课时为0.5~16并以0.5递增。
-
每节课程允许1~8个时段,格式为
`HH:mm-HH:mm`
;同时兼容原型中的
`~`
、
`—`
、
`–`
。
兼容规则:旧客户端可以不传批次
`type`
,改为在每个课程内提交
`type`
;如果两处同时提交,
值必须一致。
校验规则:
-
单次至少1节、最多100节;任意行失败时整个事务回滚,错误消息包含“第N节课程”;
-
日期必须位于班级培训起止日期内,星期由服务端计算;
-
课次允许0~40,课时允许0~16并以0.5递增;
-
每行允许1~8个时段,格式为
`HH:mm-HH:mm`
,兼容
`~`
、
`—`
、
`–`
、
`→`
;
-
同一行只能属于上午或下午,跨越12:00必须拆成两行;
-
同一日期最多提交一条上午和一条下午课程;
-
同班级或同教师的时段不能重叠,首尾相接不算冲突;
-
课程名称最多100字,地点最多255字,备注最多1000字。
-
同一班级或同一教师的课程时段不能重叠;首尾相接的时段不算冲突。
-
批量保存使用事务,任意一行失败都会整体回滚。错误消息带“第N节课程”行号。
成功后返回
该班级
刷新后的完整课程表。
成功后返回刷新后的完整
班级
课程表。
## 5. 编辑课
程
## 5. 编辑
整行排
课
`PUT /class/subject/admin/
{course
Id}`
`PUT /class/subject/admin/
schedules/{scheduleGroup
Id}`
请求体为批量新增中
`courses`
数组的单个元素,不接收
`classId`
。编辑后返回该节课程。
课程一旦产生签到记录/签到场次、关联请假或评价任务,就禁止直接修改,以防业务数据与排课
信息不一致。
新版编辑弹窗使用本接口一次保存上午、下午课程。组级日期只提交一次;已有课程必须回传
`id`
,新增的期间课程不传
`id`
。请求未包含的旧课程表示删除。
```
json
{
"date"
:
"2026-09-09"
,
"courses"
:
[
{
"id"
:
1001
,
"subjectTimes"
:
2
,
"timeFrames"
:
[
"09:00-10:20"
,
"10:40-12:00"
],
"subjectHour"
:
2.0
,
"subjectName"
:
"水污染知识"
,
"teacherId"
:
"1900000000000000001"
,
"location"
:
"A栋302"
,
"type"
:
"理论"
,
"remark"
:
"第一章"
},
{
"subjectTimes"
:
2
,
"timeFrames"
:
[
"13:00-14:20"
,
"14:40-16:00"
],
"subjectHour"
:
2.0
,
"subjectName"
:
"污水处理工艺"
,
"teacherId"
:
"1900000000000000002"
,
"location"
:
"A栋302"
,
"type"
:
"理论"
}
]
}
```
## 6. 删除课程
服务端在一个事务内完成更新、插入和删除,并尽量保留已有课程ID。已产生签到、签到场次、
请假或评价的课程允许原样回传,但不能修改或删除;改变组日期也会被视为修改组内每条课程。
成功后返回刷新后的单个排课组。
`DELETE /class/subject/admin/{courseId}`
## 6. 兼容的单课程编辑与删除
仅允许删除尚未产生签到、请假或评价数据的课程,成功返回
`true`
。
-
`PUT /class/subject/admin/{courseId}`
:保留旧单课程编辑接口,同时执行期间和冲突校验;
-
`DELETE /class/subject/admin/{courseId}`
:删除没有签到、请假或评价数据的独立课程。
## 7. 导出课程表
`GET /class/subject/admin/classes/{classId}/export`
支持与列表相同的
`startDate`
、
`endDate`
参数,返回带UTF-8 BOM的CSV
文件,可直接使用Excel
打开。导出内容使用服务端实时查询结果,不信任客户端拼装的数据
。
支持与列表相同的
日期范围
参数,返回带UTF-8 BOM的CSV
。上午、下午课程按独立行输出,并包含
排课组ID和
`AM/PM/ALL_DAY`
期间,确保不同课程名或教师的信息不会在导出时丢失
。
practical-business/src/main/resources/sql/course_management.sql
View file @
ad868040
...
...
@@ -2,9 +2,10 @@
--
-- 执行顺序:先执行class_management.sql补齐班级培训日期等字段,再执行本脚本。
-- 设计说明:
-- 1. 项目已存在class_subject表,本脚本
只
调整课时精度、补充审计列和常用索引。
-- 1. 项目已存在class_subject表,本脚本调整课时精度、补充
排课组、
审计列和常用索引。
-- 2. 旧数据允许审计时间为空;新增/编辑接口会自动维护create_time和update_time。
-- 3. 项目历史表主要由服务层维护关系完整性,本脚本不额外引入外键,避免阻断旧数据迁移。
-- 3. 上午、下午仍是独立class_subject记录,schedule_group_id只负责聚合页面中的同一排课行。
-- 4. 项目历史表主要由服务层维护关系完整性,本脚本不额外引入外键,避免阻断旧数据迁移。
delimiter
$$
...
...
@@ -22,6 +23,49 @@ begin
modify
column
subject_hour
decimal
(
5
,
1
)
null
comment
'课时数,支持0.5课时粒度'
;
end
if
;
--
-- 新版页面允许一行展示上午、下午两条独立课程。旧记录逐条分组,不按日期自动合并,
-- 可以避免把历史上同日但业务含义不同的课程错误组合到同一编辑单元。
--
if
not
exists
(
select
1
from
information_schema
.
columns
where
table_schema
=
database
()
and
table_name
=
'class_subject'
and
column_name
=
'schedule_group_id'
)
then
alter
table
class_subject
add
column
schedule_group_id
varchar
(
32
)
null
comment
'课程管理页面排课组ID,组内课程仍保留独立主键'
after
class_id
;
end
if
;
-- 编辑弹窗仅携带全局唯一的排课组ID,组ID前导索引避免首次定位班级时扫描全表。
if
not
exists
(
select
1
from
information_schema
.
statistics
where
table_schema
=
database
()
and
table_name
=
'class_subject'
and
index_name
=
'idx_subject_schedule_group'
)
then
alter
table
class_subject
add
index
idx_subject_schedule_group
(
schedule_group_id
,
id
);
end
if
;
update
class_subject
set
schedule_group_id
=
concat
(
'legacy-'
,
id
)
where
schedule_group_id
is
null
or
trim
(
schedule_group_id
)
=
''
;
-- 回填完成后设置非空,确保后续新增数据不会出现无法聚合的课程。
if
exists
(
select
1
from
information_schema
.
columns
where
table_schema
=
database
()
and
table_name
=
'class_subject'
and
column_name
=
'schedule_group_id'
and
is_nullable
=
'YES'
)
then
alter
table
class_subject
modify
column
schedule_group_id
varchar
(
32
)
not
null
comment
'课程管理页面排课组ID,组内课程仍保留独立主键'
;
end
if
;
if
not
exists
(
select
1
from
information_schema
.
columns
where
table_schema
=
database
()
...
...
@@ -32,6 +76,17 @@ begin
add
column
create_time
datetime
null
comment
'创建时间'
after
type
;
end
if
;
-- 排课组详情按班级和组ID读取,日期、ID作为稳定排序后缀。
if
not
exists
(
select
1
from
information_schema
.
statistics
where
table_schema
=
database
()
and
table_name
=
'class_subject'
and
index_name
=
'idx_subject_class_schedule'
)
then
alter
table
class_subject
add
index
idx_subject_class_schedule
(
class_id
,
schedule_group_id
,
date
,
id
);
end
if
;
if
not
exists
(
select
1
from
information_schema
.
columns
where
table_schema
=
database
()
...
...
@@ -74,3 +129,16 @@ delimiter ;
update
class_subject
set
update_time
=
coalesce
(
update_time
,
now
())
where
update_time
is
null
;
-- 部署后核验:以下两个结果都应为0;查询只读,不改变业务数据。
select
count
(
*
)
as
missing_schedule_group_count
from
class_subject
where
schedule_group_id
is
null
or
trim
(
schedule_group_id
)
=
''
;
select
count
(
*
)
as
cross_class_schedule_group_count
from
(
select
schedule_group_id
from
class_subject
group
by
schedule_group_id
having
count
(
distinct
class_id
)
&
gt
;
1
)
invalid_groups
;
practical-business/src/test/java/com/platform/business/controller/CourseAdminControllerTest.java
View file @
ad868040
package
com.platform.business.controller
;
import
com.platform.business.model.entity.UserEntity
;
import
com.platform.business.model.dto.CourseAdminScheduleGroupSaveDTO
;
import
com.platform.business.model.vo.CourseAdminOptionsVO
;
import
com.platform.business.service.AuthenticatedUserService
;
import
com.platform.business.service.CourseAdminService
;
...
...
@@ -60,4 +61,17 @@ class CourseAdminControllerTest {
assertThrows
(
BusinessException
.
class
,
()
->
controller
.
options
(
request
));
}
@Test
void
updateScheduleShouldRequireAdminAndDelegateGroupId
()
{
MockHttpServletRequest
request
=
new
MockHttpServletRequest
();
UserEntity
administrator
=
new
UserEntity
();
CourseAdminScheduleGroupSaveDTO
body
=
new
CourseAdminScheduleGroupSaveDTO
();
when
(
authenticatedUserService
.
current
(
request
)).
thenReturn
(
administrator
);
controller
.
updateSchedule
(
"group-1"
,
body
,
request
);
verify
(
authenticatedUserService
).
requireAdmin
(
administrator
);
verify
(
courseAdminService
).
updateSchedule
(
"group-1"
,
body
);
}
}
practical-business/src/test/java/com/platform/business/service/impl/CourseAdminServiceImplTest.java
View file @
ad868040
...
...
@@ -4,10 +4,13 @@ import com.platform.business.mapper.ClassMapper;
import
com.platform.business.mapper.ClassSubjectMapper
;
import
com.platform.business.model.dto.CourseAdminBatchSaveDTO
;
import
com.platform.business.model.dto.CourseAdminSaveDTO
;
import
com.platform.business.model.dto.CourseAdminScheduleGroupSaveDTO
;
import
com.platform.business.model.dto.CourseAdminScheduleItemSaveDTO
;
import
com.platform.business.model.entity.ClassEntity
;
import
com.platform.business.model.entity.ClassSubjectEntity
;
import
com.platform.business.model.vo.CourseAdminDetailVO
;
import
com.platform.business.model.vo.CourseAdminScheduleVO
;
import
com.platform.business.model.vo.CourseAdminScheduleGroupVO
;
import
com.platform.business.service.ClassAdminService
;
import
com.platform.exception.BusinessException
;
import
org.junit.jupiter.api.Test
;
...
...
@@ -21,10 +24,12 @@ import java.math.BigDecimal;
import
java.sql.Date
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.List
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertThrows
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
ArgumentMatchers
.
anyList
;
import
static
org
.
mockito
.
ArgumentMatchers
.
eq
;
import
static
org
.
mockito
.
Mockito
.
never
;
import
static
org
.
mockito
.
Mockito
.
verify
;
...
...
@@ -51,7 +56,7 @@ class CourseAdminServiceImplTest {
mockWritableClass
();
when
(
classSubjectMapper
.
countAdminActiveTeacher
(
"teacher-1"
)).
thenReturn
(
1
);
when
(
classSubjectMapper
.
selectAdminConflictCandidates
(
any
(),
eq
(
1
),
eq
(
"teacher-1"
),
eq
(
null
))).
thenReturn
(
Collections
.
emptyList
());
eq
(
"teacher-1"
),
anyList
(
))).
thenReturn
(
Collections
.
emptyList
());
when
(
classSubjectMapper
.
insert
(
any
(
ClassSubjectEntity
.
class
))).
thenAnswer
(
invocation
->
{
ClassSubjectEntity
entity
=
invocation
.
getArgument
(
0
);
entity
.
setId
(
99
);
...
...
@@ -60,7 +65,7 @@ class CourseAdminServiceImplTest {
mockEmptyDetail
();
CourseAdminSaveDTO
item
=
validCourse
();
item
.
setTimeFrames
(
Arrays
.
asList
(
"1
3:00~14:2
0"
,
"9:00—10:20"
));
item
.
setTimeFrames
(
Arrays
.
asList
(
"1
0:40→12:0
0"
,
"9:00—10:20"
));
item
.
setSubjectHour
(
new
BigDecimal
(
"1.5"
));
CourseAdminBatchSaveDTO
request
=
new
CourseAdminBatchSaveDTO
();
request
.
setClassId
(
1
);
...
...
@@ -71,10 +76,62 @@ class CourseAdminServiceImplTest {
ArgumentCaptor
<
ClassSubjectEntity
>
captor
=
ArgumentCaptor
.
forClass
(
ClassSubjectEntity
.
class
);
verify
(
classSubjectMapper
).
insert
(
captor
.
capture
());
assertEquals
(
"09:00-10:20,1
3:00-14:2
0"
,
captor
.
getValue
().
getTimeFrame
());
assertEquals
(
"09:00-10:20,1
0:40-12:0
0"
,
captor
.
getValue
().
getTimeFrame
());
assertEquals
(
"周二"
,
captor
.
getValue
().
getWeek
());
assertEquals
(
new
BigDecimal
(
"1.5"
),
captor
.
getValue
().
getSubjectHour
());
assertEquals
(
"测试课程"
,
captor
.
getValue
().
getSubjectName
());
// 排课组ID由服务端生成,客户端不能伪造或遗漏。
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertNotNull
(
captor
.
getValue
().
getScheduleGroupId
());
}
@Test
void
createBatchShouldGroupMorningAndAfternoonOfSameDate
()
{
mockWritableClass
();
when
(
classSubjectMapper
.
countAdminActiveTeacher
(
any
())).
thenReturn
(
1
);
when
(
classSubjectMapper
.
selectAdminConflictCandidates
(
any
(),
eq
(
1
),
any
(),
anyList
())).
thenReturn
(
Collections
.
emptyList
());
when
(
classSubjectMapper
.
insert
(
any
(
ClassSubjectEntity
.
class
))).
thenReturn
(
1
);
mockEmptyDetail
();
CourseAdminSaveDTO
morning
=
validCourse
();
morning
.
setType
(
null
);
CourseAdminSaveDTO
afternoon
=
validCourse
();
afternoon
.
setTeacherId
(
"teacher-2"
);
afternoon
.
setType
(
null
);
afternoon
.
setTimeFrames
(
Collections
.
singletonList
(
"13:00-14:20"
));
CourseAdminBatchSaveDTO
request
=
new
CourseAdminBatchSaveDTO
();
request
.
setClassId
(
1
);
request
.
setType
(
"理论"
);
request
.
setCourses
(
Arrays
.
asList
(
morning
,
afternoon
));
service
.
createBatch
(
request
);
ArgumentCaptor
<
ClassSubjectEntity
>
captor
=
ArgumentCaptor
.
forClass
(
ClassSubjectEntity
.
class
);
verify
(
classSubjectMapper
,
org
.
mockito
.
Mockito
.
times
(
2
)).
insert
(
captor
.
capture
());
List
<
ClassSubjectEntity
>
inserted
=
captor
.
getAllValues
();
assertEquals
(
inserted
.
get
(
0
).
getScheduleGroupId
(),
inserted
.
get
(
1
).
getScheduleGroupId
());
assertEquals
(
"理论"
,
inserted
.
get
(
0
).
getType
());
assertEquals
(
"理论"
,
inserted
.
get
(
1
).
getType
());
}
@Test
void
createBatchShouldRejectTimeFramesCrossingNoon
()
{
mockWritableClass
();
when
(
classSubjectMapper
.
countAdminActiveTeacher
(
"teacher-1"
)).
thenReturn
(
1
);
CourseAdminSaveDTO
item
=
validCourse
();
item
.
setTimeFrames
(
Collections
.
singletonList
(
"11:00-13:00"
));
CourseAdminBatchSaveDTO
request
=
new
CourseAdminBatchSaveDTO
();
request
.
setClassId
(
1
);
request
.
setCourses
(
Collections
.
singletonList
(
item
));
BusinessException
error
=
assertThrows
(
BusinessException
.
class
,
()
->
service
.
createBatch
(
request
));
assertEquals
(
"第1节课程:同一行时间段不能同时跨上午和下午,请拆成两行提交"
,
error
.
getMessage
());
verify
(
classSubjectMapper
,
never
()).
insert
(
any
(
ClassSubjectEntity
.
class
));
}
@Test
...
...
@@ -88,7 +145,7 @@ class CourseAdminServiceImplTest {
existing
.
setSubjectName
(
"已有课程"
);
existing
.
setTimeFrame
(
"09:30-11:00"
);
when
(
classSubjectMapper
.
selectAdminConflictCandidates
(
any
(),
eq
(
1
),
eq
(
"teacher-1"
),
eq
(
null
))).
thenReturn
(
Collections
.
singletonList
(
existing
));
eq
(
"teacher-1"
),
anyList
(
))).
thenReturn
(
Collections
.
singletonList
(
existing
));
CourseAdminBatchSaveDTO
request
=
new
CourseAdminBatchSaveDTO
();
request
.
setClassId
(
1
);
...
...
@@ -138,9 +195,21 @@ class CourseAdminServiceImplTest {
when
(
classSubjectMapper
.
selectAdminCourseClass
(
1
)).
thenReturn
(
detail
);
CourseAdminScheduleVO
first
=
new
CourseAdminScheduleVO
();
first
.
setId
(
1
);
first
.
setClassId
(
1
);
first
.
setScheduleGroupId
(
"group-1"
);
first
.
setDate
(
Date
.
valueOf
(
"2026-09-08"
));
first
.
setWeek
(
"周二"
);
first
.
setSubjectTimes
(
2
);
first
.
setTimeFrame
(
"09:00-10:20,10:40-12:00"
);
first
.
setSubjectHour
(
new
BigDecimal
(
"1.5"
));
CourseAdminScheduleVO
second
=
new
CourseAdminScheduleVO
();
second
.
setId
(
2
);
second
.
setClassId
(
1
);
second
.
setScheduleGroupId
(
"group-1"
);
second
.
setDate
(
Date
.
valueOf
(
"2026-09-08"
));
second
.
setWeek
(
"周二"
);
second
.
setSubjectTimes
(
1
);
second
.
setTimeFrame
(
"13:00-14:20"
);
second
.
setSubjectHour
(
new
BigDecimal
(
"2.0"
));
when
(
classSubjectMapper
.
selectAdminCourseList
(
1
,
null
,
null
))
...
...
@@ -152,6 +221,61 @@ class CourseAdminServiceImplTest {
assertEquals
(
new
BigDecimal
(
"3.5"
),
result
.
getTotalHours
());
assertEquals
(
Arrays
.
asList
(
"09:00-10:20"
,
"10:40-12:00"
),
result
.
getCourses
().
get
(
0
).
getTimeFrames
());
assertEquals
(
1
,
result
.
getScheduleCount
());
assertEquals
(
3
,
result
.
getSchedules
().
get
(
0
).
getSubjectTimes
());
assertEquals
(
"AM"
,
result
.
getSchedules
().
get
(
0
).
getItems
().
get
(
0
).
getPeriod
());
assertEquals
(
"PM"
,
result
.
getSchedules
().
get
(
0
).
getItems
().
get
(
1
).
getPeriod
());
}
@Test
void
updateScheduleShouldKeepExistingIdAndInsertMissingPeriod
()
{
ClassSubjectEntity
existing
=
existingCourse
(
11
,
"group-1"
,
"09:00-10:20"
);
when
(
classSubjectMapper
.
selectAdminCourseGroupEntities
(
"group-1"
))
.
thenReturn
(
Collections
.
singletonList
(
existing
));
mockWritableClass
();
when
(
classSubjectMapper
.
countAdminActiveTeacher
(
any
())).
thenReturn
(
1
);
when
(
classSubjectMapper
.
selectAdminConflictCandidates
(
any
(),
eq
(
1
),
any
(),
anyList
())).
thenReturn
(
Collections
.
emptyList
());
when
(
classSubjectMapper
.
updateAdminCourse
(
any
(
ClassSubjectEntity
.
class
))).
thenReturn
(
1
);
when
(
classSubjectMapper
.
insert
(
any
(
ClassSubjectEntity
.
class
))).
thenReturn
(
1
);
mockGroupDetail
(
"group-1"
);
CourseAdminScheduleItemSaveDTO
morning
=
scheduleItem
(
11
,
"teacher-1"
,
"09:00-10:20"
);
CourseAdminScheduleItemSaveDTO
afternoon
=
scheduleItem
(
null
,
"teacher-2"
,
"13:00-14:20"
);
CourseAdminScheduleGroupSaveDTO
request
=
new
CourseAdminScheduleGroupSaveDTO
();
request
.
setDate
(
Date
.
valueOf
(
"2026-09-08"
));
request
.
setCourses
(
Arrays
.
asList
(
morning
,
afternoon
));
CourseAdminScheduleGroupVO
result
=
service
.
updateSchedule
(
"group-1"
,
request
);
ArgumentCaptor
<
ClassSubjectEntity
>
updateCaptor
=
ArgumentCaptor
.
forClass
(
ClassSubjectEntity
.
class
);
verify
(
classSubjectMapper
).
updateAdminCourse
(
updateCaptor
.
capture
());
assertEquals
(
11
,
updateCaptor
.
getValue
().
getId
());
assertEquals
(
"group-1"
,
updateCaptor
.
getValue
().
getScheduleGroupId
());
verify
(
classSubjectMapper
).
insert
(
any
(
ClassSubjectEntity
.
class
));
assertEquals
(
"group-1"
,
result
.
getScheduleGroupId
());
}
@Test
void
updateScheduleShouldRejectChangingReferencedCourse
()
{
ClassSubjectEntity
existing
=
existingCourse
(
11
,
"group-1"
,
"09:00-10:20"
);
when
(
classSubjectMapper
.
selectAdminCourseGroupEntities
(
"group-1"
))
.
thenReturn
(
Collections
.
singletonList
(
existing
));
mockWritableClass
();
when
(
classSubjectMapper
.
countAdminActiveTeacher
(
"teacher-2"
)).
thenReturn
(
1
);
when
(
classSubjectMapper
.
countAdminCourseDependencies
(
11
)).
thenReturn
(
1
);
CourseAdminScheduleItemSaveDTO
changed
=
scheduleItem
(
11
,
"teacher-2"
,
"09:00-10:20"
);
CourseAdminScheduleGroupSaveDTO
request
=
new
CourseAdminScheduleGroupSaveDTO
();
request
.
setDate
(
Date
.
valueOf
(
"2026-09-08"
));
request
.
setCourses
(
Collections
.
singletonList
(
changed
));
BusinessException
error
=
assertThrows
(
BusinessException
.
class
,
()
->
service
.
updateSchedule
(
"group-1"
,
request
));
assertEquals
(
"第1节课程:课程已产生签到、请假或评价数据,不能修改"
,
error
.
getMessage
());
verify
(
classSubjectMapper
,
never
()).
updateAdminCourse
(
any
(
ClassSubjectEntity
.
class
));
}
private
void
mockWritableClass
()
{
...
...
@@ -183,4 +307,56 @@ class CourseAdminServiceImplTest {
request
.
setType
(
"理论"
);
return
request
;
}
private
ClassSubjectEntity
existingCourse
(
Integer
id
,
String
groupId
,
String
timeFrame
)
{
ClassSubjectEntity
entity
=
new
ClassSubjectEntity
();
entity
.
setId
(
id
);
entity
.
setClassId
(
1
);
entity
.
setScheduleGroupId
(
groupId
);
entity
.
setDate
(
Date
.
valueOf
(
"2026-09-08"
));
entity
.
setWeek
(
"周二"
);
entity
.
setSubjectTimes
(
2
);
entity
.
setTimeFrame
(
timeFrame
);
entity
.
setSubjectHour
(
new
BigDecimal
(
"1.0"
));
entity
.
setSubjectName
(
"测试课程"
);
entity
.
setTeacherId
(
"teacher-1"
);
entity
.
setType
(
"理论"
);
return
entity
;
}
private
CourseAdminScheduleItemSaveDTO
scheduleItem
(
Integer
id
,
String
teacherId
,
String
timeFrame
)
{
CourseAdminScheduleItemSaveDTO
item
=
new
CourseAdminScheduleItemSaveDTO
();
item
.
setId
(
id
);
item
.
setSubjectTimes
(
2
);
item
.
setTimeFrames
(
Collections
.
singletonList
(
timeFrame
));
item
.
setSubjectHour
(
new
BigDecimal
(
"1.0"
));
item
.
setSubjectName
(
"测试课程"
);
item
.
setTeacherId
(
teacherId
);
item
.
setType
(
"理论"
);
return
item
;
}
private
void
mockGroupDetail
(
String
groupId
)
{
CourseAdminDetailVO
detail
=
new
CourseAdminDetailVO
();
detail
.
setClassId
(
1
);
detail
.
setClassName
(
"测试班级"
);
when
(
classSubjectMapper
.
selectAdminCourseClass
(
1
)).
thenReturn
(
detail
);
CourseAdminScheduleVO
morning
=
new
CourseAdminScheduleVO
();
morning
.
setId
(
11
);
morning
.
setClassId
(
1
);
morning
.
setScheduleGroupId
(
groupId
);
morning
.
setDate
(
Date
.
valueOf
(
"2026-09-08"
));
morning
.
setTimeFrame
(
"09:00-10:20"
);
morning
.
setSubjectHour
(
new
BigDecimal
(
"1.0"
));
CourseAdminScheduleVO
afternoon
=
new
CourseAdminScheduleVO
();
afternoon
.
setId
(
12
);
afternoon
.
setClassId
(
1
);
afternoon
.
setScheduleGroupId
(
groupId
);
afternoon
.
setDate
(
Date
.
valueOf
(
"2026-09-08"
));
afternoon
.
setTimeFrame
(
"13:00-14:20"
);
afternoon
.
setSubjectHour
(
new
BigDecimal
(
"1.0"
));
when
(
classSubjectMapper
.
selectAdminCourseList
(
1
,
null
,
null
))
.
thenReturn
(
Arrays
.
asList
(
morning
,
afternoon
));
}
}
practical-business/src/test/java/com/platform/business/sql/CourseMigrationSqlTest.java
View file @
ad868040
...
...
@@ -32,6 +32,20 @@ class CourseMigrationSqlTest {
assertTrue
(
sql
.
contains
(
"idx_subject_teacher_date"
));
}
@Test
void
courseMigrationShouldBackfillAndIndexScheduleGroups
()
throws
Exception
{
String
sql
=
resource
(
"sql/course_management.sql"
).
toLowerCase
();
assertTrue
(
sql
.
contains
(
"schedule_group_id varchar(32)"
));
assertTrue
(
sql
.
contains
(
"concat('legacy-', id)"
));
assertTrue
(
sql
.
contains
(
"modify column schedule_group_id varchar(32) not null"
));
assertTrue
(
sql
.
contains
(
"idx_subject_class_schedule"
));
assertTrue
(
sql
.
contains
(
"class_id, schedule_group_id, date, id"
));
assertTrue
(
sql
.
contains
(
"idx_subject_schedule_group"
));
assertTrue
(
sql
.
contains
(
"schedule_group_id, id"
));
assertTrue
(
sql
.
contains
(
"missing_schedule_group_count"
));
}
private
static
String
resource
(
String
path
)
throws
Exception
{
try
(
InputStream
input
=
Thread
.
currentThread
().
getContextClassLoader
().
getResourceAsStream
(
path
))
{
assertTrue
(
input
!=
null
,
"迁移SQL资源必须存在:"
+
path
);
...
...
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