|
|
@@ -9,13 +9,14 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import org.apache.http.NameValuePair;
|
|
|
import org.apache.http.message.BasicNameValuePair;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
|
|
|
@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,9 +41,23 @@ 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
|
|
|
public JSONObject findRecommendExamsByCourseId(int courseId) {
|
|
|
String uri = "https://coder-server.seec.seecoder.cn/api/unauthorizedCourseExams/" + courseId;
|
|
|
@@ -131,4 +146,282 @@ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除Coder课程
|
|
|
+ * @param examId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public JSONObject deleteCoderExam(int examId) {
|
|
|
+ String token = httpService.getToken();
|
|
|
+ String result = null;
|
|
|
+ try {
|
|
|
+ result = httpService.sendDelete(coderUrlPrefix+"/exam/"+examId, null, token);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return JSON.parseObject(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新Coder课程
|
|
|
+ * @param examId
|
|
|
+ * @param examDTO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public JSONObject updateCoderExam(int examId, JSONObject examDTO) {
|
|
|
+ String token = httpService.getToken();
|
|
|
+ String result = null;
|
|
|
+ try {
|
|
|
+ result = httpService.sendPut(coderUrlPrefix+"/exam/"+examId, examDTO, token);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return JSON.parseObject(result);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据id获得Coder的考试信息
|
|
|
+ * @param examId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public JSONObject getCoderExamByExamId(int examId) {
|
|
|
+ String token = httpService.getToken();
|
|
|
+ String result = null;
|
|
|
+ try {
|
|
|
+ result = httpService.sendGet(coderUrlPrefix+"/exam/"+examId,null, token);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return JSON.parseObject(result);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据id获取Coder代码题
|
|
|
+ * @param problemId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public JSONObject getCoderProblemByProblemId(int problemId) {
|
|
|
+ String token = httpService.getToken();
|
|
|
+ String result = null;
|
|
|
+ try {
|
|
|
+ result = httpService.sendGet(coderUrlPrefix+"/problem/"+problemId,null, token);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return JSON.parseObject(result);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * TODO 创建Coder代码题,文件上传
|
|
|
+ * @param problemDTO
|
|
|
+ * @param file
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public JSONObject createCoderProblem(JSONObject problemDTO, MultipartFile file) {
|
|
|
+ String token = httpService.getToken();
|
|
|
+ String result = null;
|
|
|
+ try{
|
|
|
+ result = httpService.sendPostFile(coderUrlPrefix+"/problem", file, problemDTO, token);
|
|
|
+// result = httpService.sendPostFile("http://localhost:8081/api/problem", file, problemDTO, token);
|
|
|
+// HttpPost httpPost = new HttpPost("http://localhost:8081/api/problem");
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return JSON.parseObject(result);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据id删除代码题
|
|
|
+ * @param problemId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public JSONObject deleteCoderProblem(int problemId) {
|
|
|
+ String token = httpService.getToken();
|
|
|
+ String result = null;
|
|
|
+ try {
|
|
|
+ result = httpService.sendDelete(coderUrlPrefix+"/problem/"+problemId, null, token);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return JSON.parseObject(result);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新Coder代码题
|
|
|
+ * @param problemId
|
|
|
+ * @param path
|
|
|
+ * @param file
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public JSONObject updateCoderProblem(int problemId, String path, MultipartFile file) {
|
|
|
+ String token = httpService.getToken();
|
|
|
+ String result = null;
|
|
|
+ try {
|
|
|
+ result = httpService.sendPutFile(coderUrlPrefix+"/problem/"+problemId, file, path, token);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return JSON.parseObject(result);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取代码题的具体文件信息
|
|
|
+ * @param problemId
|
|
|
+ * @param filename
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public JSONObject getProblemFile(int problemId, String filename) {
|
|
|
+ String token = httpService.getToken();
|
|
|
+ List<NameValuePair> params = new ArrayList<>();
|
|
|
+ params.add(new BasicNameValuePair("name", String.valueOf(filename)));
|
|
|
+ String result = null;
|
|
|
+ try {
|
|
|
+ result = httpService.sendGet(coderUrlPrefix+"/problem/"+problemId+"/file", params,token);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return JSON.parseObject(result);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据id获取考试结果
|
|
|
+ * @param examId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public JSONObject getResultByExamId(int examId) {
|
|
|
+ String token = httpService.getToken();
|
|
|
+ String result = null;
|
|
|
+ try {
|
|
|
+ result = httpService.sendGet(coderUrlPrefix+"/exam/"+examId+"/result", null, token);
|
|
|
+ }catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return JSON.parseObject(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据id获取某个结果的详细信息
|
|
|
+ * @param resultId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public JSONObject getResultByResultId(int resultId) {
|
|
|
+ String token = httpService.getToken();
|
|
|
+ String result = null;
|
|
|
+ try {
|
|
|
+ result = httpService.sendGet(coderUrlPrefix+"/result/"+resultId, null, token);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return JSON.parseObject(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据id获取某次提交的具体信息
|
|
|
+ * @param commitId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public JSONObject getCommitByCommitId(int commitId) {
|
|
|
+ String token = httpService.getToken();
|
|
|
+ String result = null;
|
|
|
+ try {
|
|
|
+ result = httpService.sendGet(coderUrlPrefix+"/commit/"+commitId, null, token);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return JSON.parseObject(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据id获取某次记录的具体信息
|
|
|
+ * @param recordId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public JSONObject getRecordByRecordId(int recordId) {
|
|
|
+ String token = httpService.getToken();
|
|
|
+ String result = null;
|
|
|
+ try {
|
|
|
+ result = httpService.sendGet(coderUrlPrefix+"/record/"+recordId, null, token);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return JSON.parseObject(result);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public JSONObject getExamConsole(int examId) {
|
|
|
+ String token = httpService.getToken();
|
|
|
+ String result = null;
|
|
|
+ try {
|
|
|
+ result = httpService.sendGet(coderUrlPrefix+"/exam/"+examId+"/showConsole", null, token);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return JSON.parseObject(result);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public JSONObject changeShowConsole(int examId, boolean showConsole) {
|
|
|
+ String token = httpService.getToken();
|
|
|
+ String result = null;
|
|
|
+// JSONObject requestBody = new JSONObject();
|
|
|
+// requestBody.put("showConsole", showConsole);
|
|
|
+ try {
|
|
|
+ result = httpService.sendPost(coderUrlPrefix+"/exam/"+examId+"/showConsole?showConsole="+showConsole, null, token);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return JSON.parseObject(result);
|
|
|
+ }
|
|
|
}
|