|
|
@@ -177,6 +177,56 @@ public class CourseServiceImpl implements CourseService {
|
|
|
return convertToVO(courseMapper.selectById(courseId));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 门户更新课程信息
|
|
|
+ * @param userPid
|
|
|
+ * @param courseId
|
|
|
+ * @param courseUpdateDTO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public CourseVO updateCourseByPortal(Long userId, Long userPid, Long courseId, CourseUpdateDTO courseUpdateDTO) {
|
|
|
+ User targetUser;
|
|
|
+ if (userPid == null){
|
|
|
+ targetUser = userMapper.selectById(userId);
|
|
|
+ } else {
|
|
|
+ QueryWrapper<User> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("pid", userPid);
|
|
|
+ targetUser = userMapper.selectOne(queryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ Course targetCourse = courseMapper.selectById(courseId);
|
|
|
+
|
|
|
+ if (targetCourse == null)
|
|
|
+ throw MyException.create(HttpStatus.BAD_REQUEST, "课程不存在");
|
|
|
+
|
|
|
+ if (targetUser.getRole() != Role.ADMIN) {
|
|
|
+ List<String> teacherIds = Collections.singletonList(Optional.ofNullable(targetCourse.getTeacherIds())
|
|
|
+ .orElse(Collections.emptyList().toString()));
|
|
|
+ String userIdStr = String.valueOf(targetUser.getId());
|
|
|
+ boolean hasTeacherId = teacherIds.contains(userIdStr);
|
|
|
+ boolean pidMatches = Objects.equals(targetCourse.getTeacherPid(), targetUser.getPid());
|
|
|
+ if (!hasTeacherId && !pidMatches) {
|
|
|
+ throw MyException.create(HttpStatus.BAD_REQUEST, "无权限更新");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Course opeCourse = convertToPO(courseUpdateDTO);
|
|
|
+ opeCourse.setCourseId(courseId);
|
|
|
+
|
|
|
+ try {
|
|
|
+ int code = courseMapper.updateById(opeCourse);
|
|
|
+ if (code == 0) {
|
|
|
+ throw MyException.create(HttpStatus.INTERNAL_SERVER_ERROR, "更新课程失败");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ throw MyException.create(HttpStatus.INTERNAL_SERVER_ERROR, "更新课程失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ return convertToVO(courseMapper.selectById(courseId));
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 删除课程
|
|
|
@@ -335,7 +385,8 @@ public class CourseServiceImpl implements CourseService {
|
|
|
private CourseVO convertToVO(Course course) {
|
|
|
CourseVO res = new CourseVO();
|
|
|
BeanUtils.copyProperties(course, res);
|
|
|
- res.setCourseImages(ConvertUtil.stringToList(course.getCourseImages(), String::valueOf));
|
|
|
+ if(course.getCourseImages() != null)
|
|
|
+ res.setCourseImages(ConvertUtil.stringToList(course.getCourseImages(), String::valueOf));
|
|
|
log.info(res.toString());
|
|
|
// 组装教师名字
|
|
|
List<String> teacherNames = new ArrayList<>();
|