Jelajahi Sumber

feat: Zhurui 门户新建Coder考试

Leone 4 tahun lalu
induk
melakukan
c701a53fd2

+ 4 - 0
seecoder-portal-server/src/main/java/cn/seecoder/seecoderportalserver/service/CourseService.java

@@ -3,6 +3,7 @@ package cn.seecoder.seecoderportalserver.service;
 import cn.seecoder.seecoderportalcommon.vo.*;
 import cn.seecoder.seecoderportalserver.domain.Course;
 import cn.seecoder.seecoderportalserver.web.rest.errors.CustomErrorException;
+import com.alibaba.fastjson.JSONObject;
 
 import java.util.List;
 
@@ -16,6 +17,8 @@ public interface CourseService {
 
     List<CourseVO> findAllCourses();
 
+    JSONObject findAllCoderCourses(int page, int limit);
+
     List<CourseVO> findTeacherCourses(Long teacherId);
 
     List<CourseVO> findStudentCourses(Long studentId);
@@ -39,4 +42,5 @@ public interface CourseService {
     CourseVO findCourseByEvalId(int evalId) throws Exception;
 
     Boolean isCourseNameExisted(String name);
+
 }

+ 5 - 0
seecoder-portal-server/src/main/java/cn/seecoder/seecoderportalserver/service/ExamService.java

@@ -20,6 +20,8 @@ public interface ExamService {
 
     JSONArray findCoderStudentExamsByCourseId(int courseId);
 
+    JSONObject createCoderExam(JSONObject examDTO);
+
     //--------------------------------------------------------
 
     JSONArray findEvalRecommendExams();
@@ -37,4 +39,7 @@ public interface ExamService {
     JSONArray findEvalStudentExamsByCourseId(int courseId);
 
     JSONArray findEvalTeacherExamsByCourseId(int courseId);
+
+    JSONObject retrievePageProblem(int page, int limit, String typeStr, String name);
+
 }

+ 55 - 0
seecoder-portal-server/src/main/java/cn/seecoder/seecoderportalserver/serviceImpl/CoderService.java

@@ -16,6 +16,7 @@ import java.util.List;
 @Service("coderService")
 public class CoderService implements SubsystemService {
     HttpService httpService;
+    public final String coderUrlPrefix = "https://coder-server.seec.seecoder.cn/api";
 
     public CoderService(HttpService httpService) {
         this.httpService = httpService;
@@ -40,7 +41,20 @@ public class CoderService implements SubsystemService {
 
     @Override
     public void deleteCourse(CourseVO courseVO) {
+    }
 
+    public JSONObject getAllCourse(int page, int limit){
+        String token = httpService.getToken();
+        List<NameValuePair> params = new ArrayList<>();
+        params.add(new BasicNameValuePair("page", String.valueOf(page)));
+        params.add(new BasicNameValuePair("limit", String.valueOf(limit)));
+        String result = null;
+        try {
+            result = httpService.sendGet(coderUrlPrefix+"/course", params, token);
+        } catch (Exception e){
+            e.printStackTrace();
+        }
+        return JSON.parseObject(result);
     }
 
     @Override
@@ -131,4 +145,45 @@ public class CoderService implements SubsystemService {
         }
         return JSON.parseObject(result);
     }
+
+    /**
+     * 获取Coder题目
+     * @param page 页号
+     * @param limit 页容量
+     * @param typeStr 题目类型(固定格式的字符串)
+     * @param name 搜索内容
+     * @return Json格式数据
+     */
+    public JSONObject retrievePageProblem(int page, int limit, String typeStr, String name) {
+        String token = httpService.getToken();
+        List<NameValuePair> params = new ArrayList<>();
+        params.add(new BasicNameValuePair("page", String.valueOf(page)));
+        params.add(new BasicNameValuePair("limit", String.valueOf(limit)));
+        params.add(new BasicNameValuePair("typeStr", String.valueOf(typeStr)));
+        params.add(new BasicNameValuePair("name", String.valueOf(name)));
+        String result = null;
+        try {
+            result = httpService.sendGet(coderUrlPrefix+"/problem", params, token);
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+        return JSON.parseObject(result);
+    }
+
+    /**
+     * 创建Coder考试
+     * @param examDTO 考试对象
+     * @return 返回Json格式数据,前端自行处理。TODO 各个子系统返回的数据,后端进行处理,统一返回格式化数据
+     */
+    public JSONObject createCoderExam(JSONObject examDTO){
+        String token = httpService.getToken();
+        JSONObject requestBody = new JSONObject(examDTO);
+        String result = null;
+        try {
+            result = httpService.sendPost(coderUrlPrefix+"/exam",requestBody, token);
+        } catch (Exception e){
+            e.printStackTrace();
+        }
+        return JSON.parseObject(result);
+    }
 }

+ 15 - 0
seecoder-portal-server/src/main/java/cn/seecoder/seecoderportalserver/serviceImpl/CourseServiceImpl.java

@@ -12,6 +12,7 @@ import cn.seecoder.seecoderportalserver.repository.CourseSelectionRepository;
 import cn.seecoder.seecoderportalserver.service.CourseService;
 import cn.seecoder.seecoderportalserver.service.UserService;
 import cn.seecoder.seecoderportalserver.web.rest.errors.CustomErrorException;
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import org.springframework.stereotype.Service;
 
@@ -114,6 +115,18 @@ public class CourseServiceImpl implements CourseService {
                 .collect(Collectors.toList());
     }
 
+    /**
+     * 查询Coder中的所有课程。TODO 子系统课程与门户系统课程中一致
+     * @param page
+     * @param limit
+     * @return
+     */
+    @Override
+    public JSONObject findAllCoderCourses(int page, int limit) {
+        return coderService.getAllCourse(page, limit);
+    }
+
+
     public List<CourseVO> findTeacherCourses(Long teacherId) {
         List<Course> courses = courseRepository.findCoursesByTeacherId(teacherId);
         return courses.stream()
@@ -216,4 +229,6 @@ public class CourseServiceImpl implements CourseService {
         Course course = courseRepository.findCourseByName(name).orElse(null);
         return course != null;
     }
+
+
 }

+ 10 - 0
seecoder-portal-server/src/main/java/cn/seecoder/seecoderportalserver/serviceImpl/ExamServiceImpl.java

@@ -78,6 +78,16 @@ public class ExamServiceImpl implements ExamService {
         return coderService.findStudentExamsByCourseId(courseId).getJSONArray("array");
     }
 
+    @Override
+    public JSONObject createCoderExam(JSONObject examDTO) {
+        return coderService.createCoderExam(examDTO);
+    }
+
+    @Override
+    public JSONObject retrievePageProblem(int page, int limit, String typeStr, String name) {
+        return coderService.retrievePageProblem(page, limit, typeStr, name);
+    }
+
     @Override
     public JSONArray findEvalRecommendExams() {
         JSONArray result = new JSONArray();

+ 1 - 0
seecoder-portal-server/src/main/java/cn/seecoder/seecoderportalserver/serviceImpl/HelperService.java

@@ -45,4 +45,5 @@ public class HelperService implements SubsystemService {
     public JSONObject findStudentExams(int page, int limit, int state) {
         return null;
     }
+
 }

+ 7 - 0
seecoder-portal-server/src/main/java/cn/seecoder/seecoderportalserver/web/rest/CourseController.java

@@ -5,6 +5,7 @@ import cn.seecoder.seecoderportalcommon.vo.CourseVO;
 import cn.seecoder.seecoderportalserver.security.SecurityUtils;
 import cn.seecoder.seecoderportalserver.service.CourseService;
 import cn.seecoder.seecoderportalserver.utility.OkResponse;
+import com.alibaba.fastjson.JSONObject;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
@@ -41,6 +42,11 @@ public class CourseController {
         return OkResponse.of(courseService.findAllCourses());
     }
 
+    @GetMapping("/coder_all")
+    public JSONObject findAllCoderCourses(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "20") int limit) {
+        return courseService.findAllCoderCourses(page, limit);
+    }
+
     @GetMapping("/teacher")
     public OkResponse<List<CourseVO>> findTeacherCourses() {
         return OkResponse.of(courseService.findTeacherCourses(SecurityUtils.getCurrentUser().getId()));
@@ -94,4 +100,5 @@ public class CourseController {
             throw new RuntimeException(e);
         }
     }
+
 }

+ 20 - 4
seecoder-portal-server/src/main/java/cn/seecoder/seecoderportalserver/web/rest/ExamController.java

@@ -5,10 +5,7 @@ import cn.seecoder.seecoderportalserver.service.ExamService;
 import cn.seecoder.seecoderportalserver.utility.OkResponse;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 @RestController
 @RequestMapping("/api")
@@ -61,6 +58,25 @@ public class ExamController {
         return OkResponse.of(examService.findCoderStudentExamsByCourseId(courseId));
     }
 
+    /**
+     * 创建Coder考试
+     */
+    @PostMapping("/coder/exam/create")
+    public JSONObject createCoderExam(@RequestBody JSONObject examDTO) {
+        return examService.createCoderExam(examDTO);
+    }
+
+    /**
+     * 获取Coder题目列表
+     */
+    @GetMapping("/coder/problem")
+    public JSONObject retrievePageProblem(@RequestParam(defaultValue = "1") int page,
+                                          @RequestParam(defaultValue = "10") int limit,
+                                          @RequestParam(defaultValue = "") String typeStr,
+                                          @RequestParam(defaultValue = "") String name){
+        return examService.retrievePageProblem(page, limit, typeStr, name);
+    }
+
     //--------------------------------------------------------
 
     @GetMapping("/eval/exam/recommend")