111
This commit is contained in:
@@ -221,10 +221,10 @@ public class SchCustomGroupService implements ISchCustomGroupService {
|
||||
|
||||
// 1. 参数校验
|
||||
if (dto.getGroupName() == null || dto.getGroupName().trim().isEmpty()) {
|
||||
throw new IllegalArgumentException("组名不能为空");
|
||||
throw new DException("组名不能为空");
|
||||
}
|
||||
if (dto.getGroupType() == null) {
|
||||
throw new IllegalArgumentException("组类型不能为空");
|
||||
throw new DException("组类型不能为空");
|
||||
}
|
||||
|
||||
// 2. 重名校验(同学校同类型下组名唯一)
|
||||
@@ -235,18 +235,18 @@ public class SchCustomGroupService implements ISchCustomGroupService {
|
||||
nameExists = teacherCustomGroupRepository.existsBySchIdAndGroupTypeAndGroupName(
|
||||
schId, dto.getGroupType(), dto.getGroupName());
|
||||
if (nameExists) {
|
||||
throw new IllegalArgumentException("组名已存在:" + dto.getGroupName());
|
||||
throw new DException("组名已存在:" + dto.getGroupName());
|
||||
}
|
||||
} else {
|
||||
// 更新:排除自身,检查其他组同名
|
||||
nameExists = teacherCustomGroupRepository.existsBySchIdAndGroupTypeAndGroupNameAndIdNot(
|
||||
schId, dto.getGroupType(), dto.getGroupName(), dto.getId());
|
||||
if (nameExists) {
|
||||
throw new IllegalArgumentException("组名已存在:" + dto.getGroupName());
|
||||
throw new DException("组名已存在:" + dto.getGroupName());
|
||||
}
|
||||
// 查询旧实体,用于日志对比
|
||||
oldEntity = teacherCustomGroupRepository.findById(dto.getId())
|
||||
.orElseThrow(() -> new IllegalArgumentException("组不存在,ID=" + dto.getId()));
|
||||
.orElseThrow(() -> new DException("组不存在,ID=" + dto.getId()));
|
||||
}
|
||||
|
||||
// 3. 构建新实体并设置基础字段
|
||||
@@ -364,7 +364,7 @@ public class SchCustomGroupService implements ISchCustomGroupService {
|
||||
|
||||
// 1. 参数校验
|
||||
if (groupId == null || groupId <= 0) {
|
||||
throw new IllegalArgumentException("组ID无效");
|
||||
throw new DException("组ID无效");
|
||||
}
|
||||
if (teaIds == null) {
|
||||
// 如果传 null,视为不修改;传空列表表示清空
|
||||
@@ -373,7 +373,7 @@ public class SchCustomGroupService implements ISchCustomGroupService {
|
||||
|
||||
// 2. 检查组是否存在
|
||||
SchTeacherCustomGroup group = teacherCustomGroupRepository.findById(groupId)
|
||||
.orElseThrow(() -> new IllegalArgumentException("组不存在,ID=" + groupId));
|
||||
.orElseThrow(() -> new DException("组不存在,ID=" + groupId));
|
||||
|
||||
// 3. 查询当前组长ID(如果有),用于从组员列表中排除
|
||||
Integer leaderId = groupInTeacherRepository.findByCgGroupIdAndGroupType(groupId, 1)
|
||||
@@ -433,19 +433,19 @@ public class SchCustomGroupService implements ISchCustomGroupService {
|
||||
|
||||
// 1. 参数校验
|
||||
if (groupId == null || groupId <= 0) {
|
||||
throw new IllegalArgumentException("组ID无效");
|
||||
throw new DException("组ID无效");
|
||||
}
|
||||
|
||||
// 2. 检查组是否存在
|
||||
SchTeacherCustomGroup group = teacherCustomGroupRepository.findById(groupId)
|
||||
.orElseThrow(() -> new IllegalArgumentException("组不存在,ID=" + groupId));
|
||||
.orElseThrow(() -> new DException("组不存在,ID=" + groupId));
|
||||
|
||||
// 3. 获取该组所有成员(全部记录)
|
||||
List<SchTeacherCustomGroupInTeacher> allMembers = groupInTeacherRepository.findByCgGroupId(groupId);
|
||||
if (allMembers.isEmpty()) {
|
||||
// 如果组没有成员,但设置了组长,可以先添加成员,但这里要求必须从组员中选,所以先提示无成员
|
||||
// 根据业务,可以先添加组员再设组长,这里抛出异常
|
||||
throw new IllegalArgumentException("该组暂无成员,无法设置组长");
|
||||
throw new DException("该组暂无成员,无法设置组长");
|
||||
}
|
||||
|
||||
// 4. 将传入的ID去重
|
||||
@@ -462,7 +462,7 @@ public class SchCustomGroupService implements ISchCustomGroupService {
|
||||
.filter(tid -> !existTeaIds.contains(tid))
|
||||
.collect(Collectors.toList());
|
||||
if (!invalidIds.isEmpty()) {
|
||||
throw new IllegalArgumentException("以下教师不是该组成员,无法设为组长:" + invalidIds);
|
||||
throw new DException("以下教师不是该组成员,无法设为组长:" + invalidIds);
|
||||
}
|
||||
|
||||
// 6. 将当前所有组长降级为组员(groupType改为2)
|
||||
@@ -508,12 +508,12 @@ public class SchCustomGroupService implements ISchCustomGroupService {
|
||||
public void deleteSchCustomGroup(UserContext.UserInfo user, Integer groupId) {
|
||||
// 1. 参数校验
|
||||
if (groupId == null || groupId <= 0) {
|
||||
throw new IllegalArgumentException("组ID无效");
|
||||
throw new DException("组ID无效");
|
||||
}
|
||||
|
||||
// 2. 查询组是否存在,并获取组基本信息(用于日志和缓存)
|
||||
SchTeacherCustomGroup group = teacherCustomGroupRepository.findById(groupId)
|
||||
.orElseThrow(() -> new IllegalArgumentException("组不存在,ID=" + groupId));
|
||||
.orElseThrow(() -> new DException("组不存在,ID=" + groupId));
|
||||
|
||||
// 3. 级联删除关联数据
|
||||
// 3.1 删除年级关联
|
||||
|
||||
Reference in New Issue
Block a user