|
|
@@ -1,11 +1,11 @@
|
|
|
package cn.seecoder.seecoderportalserver.serviceImpl;
|
|
|
|
|
|
-import cn.seecoder.seecoderportalserver.domain.key.CourseSelectionKey;
|
|
|
import cn.seecoder.seecoderportalcommon.vo.CourseVO;
|
|
|
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.key.CourseSelectionKey;
|
|
|
import cn.seecoder.seecoderportalserver.mapper.CourseMapper;
|
|
|
import cn.seecoder.seecoderportalserver.repository.CourseRepository;
|
|
|
import cn.seecoder.seecoderportalserver.repository.CourseSelectionRepository;
|
|
|
@@ -15,17 +15,22 @@ import cn.seecoder.seecoderportalserver.service.CourseService;
|
|
|
import cn.seecoder.seecoderportalserver.service.UserService;
|
|
|
import cn.seecoder.seecoderportalserver.serviceImpl.subsystem.CoderService;
|
|
|
import cn.seecoder.seecoderportalserver.serviceImpl.subsystem.EvalService;
|
|
|
-import cn.seecoder.seecoderportalserver.serviceImpl.subsystem.HelperService;
|
|
|
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.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileWriter;
|
|
|
import java.io.IOException;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+
|
|
|
@Service
|
|
|
public class CourseServiceImpl implements CourseService {
|
|
|
private final CourseRepository courseRepository;
|
|
|
@@ -33,23 +38,25 @@ public class CourseServiceImpl implements CourseService {
|
|
|
private final CourseSelectionRepository courseSelectionRepository;
|
|
|
private final UserService userService;
|
|
|
private final CoderService coderService;
|
|
|
- private final HelperService helperService;
|
|
|
+ //private final HelperService helperService;
|
|
|
private final EvalService evalService;
|
|
|
private final OssUtil ossUtil;
|
|
|
|
|
|
- public CourseServiceImpl(CourseRepository courseRepository, CourseMapper courseMapper, CourseSelectionRepository courseSelectionRepository, CoderService coderService, HelperService helperService, EvalService evalService, UserService userService, OssUtil ossUtil) {
|
|
|
+ public CourseServiceImpl(CourseRepository courseRepository, CourseMapper courseMapper, CourseSelectionRepository courseSelectionRepository, CoderService coderService, /*HelperService helperService,*/ EvalService evalService, UserService userService, OssUtil ossUtil) {
|
|
|
this.courseRepository = courseRepository;
|
|
|
this.courseMapper = courseMapper;
|
|
|
this.courseSelectionRepository = courseSelectionRepository;
|
|
|
this.userService = userService;
|
|
|
this.coderService = coderService;
|
|
|
- this.helperService = helperService;
|
|
|
+ //this.helperService = helperService;
|
|
|
this.evalService = evalService;
|
|
|
this.ossUtil = ossUtil;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public CourseVO createCourse(CourseVO courseVO, Long userId) {
|
|
|
+ System.out.println(courseVO);
|
|
|
+
|
|
|
// 确认授课教师
|
|
|
UserVO teacher = userService.findUserById(userId);
|
|
|
if (!courseVO.getTeacher().getId().equals(userId) || !userService.isTeacher(teacher.getRole())) {
|
|
|
@@ -85,6 +92,9 @@ public class CourseServiceImpl implements CourseService {
|
|
|
Course course = courseMapper.courseVOToCourse(courseVO);
|
|
|
course.setState(ObjectState.NORMAL);
|
|
|
Course result = courseRepository.save(course);
|
|
|
+ System.out.println(5);
|
|
|
+ System.out.println(course);
|
|
|
+ System.out.println(result);
|
|
|
return courseMapper.courseToCourseVO(result);
|
|
|
}
|
|
|
|
|
|
@@ -191,10 +201,10 @@ public class CourseServiceImpl implements CourseService {
|
|
|
if (course.getEvalId() != null) {
|
|
|
JSONObject evalRes = evalService.chooseCourse(course.getInvitationCode());
|
|
|
}
|
|
|
- // 门户系统选课
|
|
|
- if (course.getHelperId() != null) {
|
|
|
- JSONObject jsonObject = helperService.chooseCourse(course.getInvitationCode());
|
|
|
- }
|
|
|
+// // 门户系统选课
|
|
|
+// if (course.getHelperId() != null) {
|
|
|
+// JSONObject jsonObject = helperService.chooseCourse(course.getInvitationCode());
|
|
|
+// }
|
|
|
CourseSelection courseSelection = new CourseSelection(courseSelectionKey);
|
|
|
courseSelection.setState(true);
|
|
|
courseSelectionRepository.save(courseSelection);
|
|
|
@@ -267,4 +277,46 @@ public class CourseServiceImpl implements CourseService {
|
|
|
}
|
|
|
return checkSelection(user.getId(), id);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean uploadCarouselChart(List<String> courses) {
|
|
|
+ try {
|
|
|
+ File file=new File("p.txt");
|
|
|
+ file.delete();
|
|
|
+ file.createNewFile();
|
|
|
+ String content="";
|
|
|
+ for (int i=0;i<3;i++){
|
|
|
+ String className=courses.get(i);
|
|
|
+ if (className!=null && className.length()!=0){
|
|
|
+ if (!isCourseNameExisted(className)){
|
|
|
+ throw CustomErrorException.courseNotFound();
|
|
|
+ }else {
|
|
|
+ content=content.concat(className).concat("\n");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ FileWriter fileWriter = new FileWriter(file.getPath(),true);
|
|
|
+ fileWriter.write(content);
|
|
|
+ fileWriter.close();
|
|
|
+ return true;
|
|
|
+ }catch (IOException e) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<CourseVO> queryCarouselChart() {
|
|
|
+ try{
|
|
|
+ File file=new File("p.txt");
|
|
|
+ List<String> names= Files.readLines(file, StandardCharsets.UTF_8);
|
|
|
+ List<CourseVO> ans=new ArrayList<>();
|
|
|
+ for (String name : names) {
|
|
|
+ ans.add(courseMapper.courseToCourseVO(courseRepository.findCourseByName(name).get()));
|
|
|
+ }
|
|
|
+ return ans;
|
|
|
+ }catch (IOException e){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|