|
|
@@ -43,11 +43,7 @@ public class CourseServiceImpl implements CourseService {
|
|
|
public CourseVO createCourse(CourseDTO courseDTO) {
|
|
|
log.info("解析CourseDTO:"+courseDTO.toString());
|
|
|
// 类型转换
|
|
|
- Course targetCourse = new Course();
|
|
|
- BeanUtils.copyProperties(courseDTO, targetCourse);
|
|
|
- targetCourse.setTeacherIds(ConvertUtil.listToString(courseDTO.getTeacherIds()));
|
|
|
- if (courseDTO.getCourseImages() != null)
|
|
|
- targetCourse.setCourseImages(ConvertUtil.listToString(courseDTO.getCourseImages()));
|
|
|
+ Course targetCourse = convertToPO(courseDTO);
|
|
|
targetCourse.setCreateTime(new Date());
|
|
|
|
|
|
log.info("类型转换后的targetCourse"+targetCourse);
|
|
|
@@ -59,12 +55,41 @@ public class CourseServiceImpl implements CourseService {
|
|
|
throw new MyException(HttpStatus.INTERNAL_SERVER_ERROR.value(), HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase()+":"+"创建课程错误");
|
|
|
}
|
|
|
|
|
|
- // 将结果输出
|
|
|
+ return convertToVO(targetCourse);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CourseVO findByCourseId(Long courseId) {
|
|
|
+ Course res = courseMapper.selectById(courseId);
|
|
|
+ return convertToVO(res);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将DTO转换成PO
|
|
|
+ * @param courseDTO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Course convertToPO(CourseDTO courseDTO) {
|
|
|
+ Course course = new Course();
|
|
|
+ BeanUtils.copyProperties(courseDTO, course);
|
|
|
+ course.setTeacherIds(ConvertUtil.listToString(courseDTO.getTeacherIds()));
|
|
|
+ if (courseDTO.getCourseImages() != null)
|
|
|
+ course.setCourseImages(ConvertUtil.listToString(courseDTO.getCourseImages()));
|
|
|
+ return course;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将PO转换成VO
|
|
|
+ * @param course
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private CourseVO convertToVO(Course course) {
|
|
|
CourseVO res = new CourseVO();
|
|
|
- BeanUtils.copyProperties(targetCourse, res);
|
|
|
- res.setTeacherIds(ConvertUtil.stringToList(targetCourse.getTeacherIds(), Long::valueOf));
|
|
|
- if (targetCourse.getCourseImages() != null)
|
|
|
- res.setCourseImages(ConvertUtil.stringToList(targetCourse.getCourseImages(), String::valueOf));
|
|
|
+ BeanUtils.copyProperties(course, res);
|
|
|
+ res.setTeacherIds(ConvertUtil.stringToList(course.getTeacherIds(), Long::valueOf));
|
|
|
+ if (course.getCourseImages() != null)
|
|
|
+ res.setCourseImages(ConvertUtil.stringToList(course.getCourseImages(), String::valueOf));
|
|
|
|
|
|
return res;
|
|
|
}
|