|
|
@@ -0,0 +1,45 @@
|
|
|
+package cn.seecoder.ojserver.service.impl;
|
|
|
+
|
|
|
+import cn.seecoder.codejudge.client.JudgeDTO;
|
|
|
+import cn.seecoder.codejudge.client.JudgeResult;
|
|
|
+import cn.seecoder.ojserver.exception.ThirdPartyServiceException;
|
|
|
+import cn.seecoder.ojserver.manager.JudgeManager;
|
|
|
+import cn.seecoder.ojserver.manager.QuestionManager;
|
|
|
+import cn.seecoder.ojserver.model.vo.CodeJudgeVO;
|
|
|
+import cn.seecoder.ojserver.model.vo.CompleteQuestionVO;
|
|
|
+import cn.seecoder.ojserver.service.JudgeService;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class JudgeServiceImpl implements JudgeService {
|
|
|
+ private final QuestionManager questionManager;
|
|
|
+ private final JudgeManager judgeManager;
|
|
|
+
|
|
|
+ public JudgeServiceImpl(QuestionManager questionManager, JudgeManager judgeManager) {
|
|
|
+ this.questionManager = questionManager;
|
|
|
+ this.judgeManager = judgeManager;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public JudgeResult judgeCode(String questionId, CodeJudgeVO codeJudgeVO) {
|
|
|
+ try {
|
|
|
+ JudgeDTO judgeDTO = new JudgeDTO();
|
|
|
+ judgeDTO.setCode(codeJudgeVO.getCode());
|
|
|
+ judgeDTO.setLanguage(codeJudgeVO.getLanguage());
|
|
|
+
|
|
|
+ CompleteQuestionVO question = questionManager.getQuestionById(questionId).get();
|
|
|
+ judgeDTO.setMemoryLimit(question.getMemoryLimit());
|
|
|
+ judgeDTO.setInputList(question.getInputOutputMapping().entrySet().stream().map(Map.Entry<String, String>::getKey).collect(Collectors.toList()));
|
|
|
+ judgeDTO.setOutputList(question.getInputOutputMapping().entrySet().stream().map(Map.Entry<String, String>::getValue).collect(Collectors.toList()));
|
|
|
+
|
|
|
+ return judgeManager.judgeCodeQuestionAnswers(judgeDTO);
|
|
|
+ } catch (ThirdPartyServiceException exception) {
|
|
|
+ throw exception;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+}
|