|
|
@@ -27,9 +27,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* @author: Leonezhurui
|
|
|
@@ -193,10 +191,15 @@ public class CourseServiceImpl implements CourseService {
|
|
|
throw MyException.create(HttpStatus.BAD_REQUEST, "课程不存在");
|
|
|
}
|
|
|
|
|
|
- if (user.getRole() != Role.ADMIN
|
|
|
- && !(course.getTeacherIds().contains(String.valueOf(user.getId())) ||
|
|
|
- course.getTeacherPid().equals(user.getPid()))) {
|
|
|
- throw MyException.create(HttpStatus.BAD_REQUEST, "无权限删除");
|
|
|
+ if (user.getRole() != Role.ADMIN) {
|
|
|
+ List<String> teacherIds = Collections.singletonList(Optional.ofNullable(course.getTeacherIds())
|
|
|
+ .orElse(Collections.emptyList().toString()));
|
|
|
+ String userIdStr = String.valueOf(user.getId());
|
|
|
+ boolean hasTeacherId = teacherIds.contains(userIdStr);
|
|
|
+ boolean pidMatches = Objects.equals(course.getTeacherPid(), user.getPid());
|
|
|
+ if (!hasTeacherId && !pidMatches) {
|
|
|
+ throw MyException.create(HttpStatus.BAD_REQUEST, "无权限创建");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
@@ -348,6 +351,7 @@ public class CourseServiceImpl implements CourseService {
|
|
|
}
|
|
|
// 2. getTeacherPid
|
|
|
if(StringUtils.isNotBlank(course.getTeacherPid())){
|
|
|
+ res.setTeacherPid(Long.valueOf(course.getTeacherPid()));
|
|
|
teacherNames.add(userMapper.selectNameByPid(Long.valueOf(course.getTeacherPid())));
|
|
|
}
|
|
|
res.setTeacherNames(teacherNames);
|