|
|
@@ -5,6 +5,7 @@ import cn.seecoder.seecoderportalcommon.vo.ObjectState;
|
|
|
import cn.seecoder.seecoderportalcommon.vo.UserVO;
|
|
|
import cn.seecoder.seecoderportalserver.domain.Course;
|
|
|
import cn.seecoder.seecoderportalserver.domain.CourseSelection;
|
|
|
+import cn.seecoder.seecoderportalserver.domain.User;
|
|
|
import cn.seecoder.seecoderportalserver.domain.key.CourseSelectionKey;
|
|
|
import cn.seecoder.seecoderportalserver.mapper.CourseMapper;
|
|
|
import cn.seecoder.seecoderportalserver.repository.CourseRepository;
|
|
|
@@ -20,7 +21,9 @@ import cn.seecoder.seecoderportalserver.utility.OssUtil;
|
|
|
import cn.seecoder.seecoderportalserver.web.rest.errors.CustomErrorException;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.google.common.io.Files;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.File;
|
|
|
@@ -55,8 +58,26 @@ public class CourseServiceImpl implements CourseService {
|
|
|
this.ossUtil = ossUtil;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
+ /*
|
|
|
+ // TODO:可以使用消息队列进行补偿,保证门户创建课程耗时短和eai课程创建的成功
|
|
|
+ // 创建课程成功后发送事件
|
|
|
+ rabbitTemplate.convertAndSend("course-created-topic", courseVO);
|
|
|
|
|
|
+ // 消费者处理补偿逻辑
|
|
|
+ @RabbitListener(queues = "course-created-topic")
|
|
|
+ public void handleCourseCreated(CourseVO courseVO) {
|
|
|
+ try {
|
|
|
+ eaiService.createCourse(courseVO); // 可能重试
|
|
|
+ coderService.createCourse(courseVO);
|
|
|
+ evalService.createCourse(courseVO);
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 记录失败日志,定时重试或人工介入
|
|
|
+ log.error("补偿失败", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = {RuntimeException.class, CustomErrorException.class, IOException.class})
|
|
|
public CourseVO createCourse(CourseVO courseVO, Long userId) {
|
|
|
System.out.println(courseVO);
|
|
|
|
|
|
@@ -138,7 +159,9 @@ public class CourseServiceImpl implements CourseService {
|
|
|
course.setMoocUrl(courseVO.getMoocUrl());
|
|
|
course.setPrice(courseVO.getPrice());
|
|
|
//eai修改课程信息
|
|
|
- eaiService.updateCourse(course, userId);
|
|
|
+ if(course.getEaiId() != null){
|
|
|
+ eaiService.updateCourse(course, userId);
|
|
|
+ }
|
|
|
Course result = courseRepository.save(courseMapper.courseVOToCourse(course));
|
|
|
return courseMapper.courseToCourseVO(result);
|
|
|
}
|
|
|
@@ -282,6 +305,7 @@ public class CourseServiceImpl implements CourseService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = {RuntimeException.class, CustomErrorException.class, IOException.class})
|
|
|
public String uploadCourseImage(String name, MultipartFile file) {
|
|
|
try {
|
|
|
Course course = courseRepository.findCourseByName(name).orElseThrow(CustomErrorException::courseNotFound);
|
|
|
@@ -289,7 +313,9 @@ public class CourseServiceImpl implements CourseService {
|
|
|
throw CustomErrorException.unauthorizedUser();
|
|
|
}
|
|
|
String imgUrl = ossUtil.upload(name + ".jpg", file.getInputStream());
|
|
|
+
|
|
|
course.setImageUrl(imgUrl);
|
|
|
+ eaiService.updateCourse(courseMapper.courseToCourseVO(course), null);
|
|
|
courseRepository.save(course);
|
|
|
return imgUrl;
|
|
|
} catch (IOException e) {
|
|
|
@@ -357,3 +383,4 @@ public class CourseServiceImpl implements CourseService {
|
|
|
return courseMapper.courseToCourseVO(courseRepository.findCourseByName(name).orElse(null));
|
|
|
}
|
|
|
}
|
|
|
+
|