|
@@ -1,6 +1,7 @@
|
|
|
package com.example.onlinejudge.service.impl;
|
|
|
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.example.onlinejudge.mapper.QuestionSubmitMapper;
|
|
|
import com.example.onlinejudge.model.entity.QuestionSubmit;
|
|
|
import com.example.onlinejudge.model.entity.result.Result;
|
|
@@ -20,10 +21,12 @@ public class QuestionServiceImpl implements QuestionService {
|
|
|
private QuestionSubmitMapper questionSubmitMapper;
|
|
|
|
|
|
@Override
|
|
|
- public Result receiveCode(Long questionID, String code, String language) {
|
|
|
+ public Result receiveCode(Long questionID, String code, String language, String userCases, Integer judgeMode) {
|
|
|
Long userID = StpUtil.getLoginIdAsLong();
|
|
|
if (questionID == null)
|
|
|
- return Result.error(ResultCode.PARAM_IS_INVALID);
|
|
|
+ return Result.error(ResultCode.PARAM_IS_INVALID);
|
|
|
+ if (!checkIsSubmitValid(userID, questionID))
|
|
|
+ return Result.error(ResultCode.SYSTEM_ERROR.getCode(), "频繁提交,请稍后再试");
|
|
|
String chooseLanguage;
|
|
|
if ("java".equals(language) || "Java".equals(language) || "JAVA".equals(language)) {
|
|
|
chooseLanguage = QuestionSubmitLanguageEnum.JAVA.getValue();
|
|
@@ -34,10 +37,50 @@ public class QuestionServiceImpl implements QuestionService {
|
|
|
} else {
|
|
|
chooseLanguage = QuestionSubmitLanguageEnum.JAVA.getValue();
|
|
|
}
|
|
|
- QuestionSubmit questionSubmit = new QuestionSubmit(null, chooseLanguage, code, JudgeInfoMessageEnum.WAITING.getValue(), 0, questionID, userID, new Date(), new Date(), 0);
|
|
|
+ QuestionSubmit questionSubmit;
|
|
|
+ if (judgeMode == 0) {
|
|
|
+ questionSubmit = new QuestionSubmit(
|
|
|
+ null,
|
|
|
+ chooseLanguage,
|
|
|
+ code,
|
|
|
+ JudgeInfoMessageEnum.WAITING.getValue(),
|
|
|
+ 0, questionID, userID,
|
|
|
+ new Date(),
|
|
|
+ new Date(),
|
|
|
+ null,
|
|
|
+ null,
|
|
|
+ 0,
|
|
|
+ 0);
|
|
|
+ } else {
|
|
|
+ questionSubmit = new QuestionSubmit(
|
|
|
+ null,
|
|
|
+ chooseLanguage,
|
|
|
+ code,
|
|
|
+ JudgeInfoMessageEnum.WAITING.getValue(),
|
|
|
+ 0, questionID, userID,
|
|
|
+ new Date(),
|
|
|
+ new Date(),
|
|
|
+ userCases,
|
|
|
+ null,
|
|
|
+ 1,
|
|
|
+ 0);
|
|
|
+ }
|
|
|
questionSubmitMapper.insert(questionSubmit);
|
|
|
System.out.println(questionSubmit);
|
|
|
// TODO: 1.提交代码到判题系统 2.更改数据库刷新状态 3.返回判题信息
|
|
|
return Result.success();
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean checkIsSubmitValid(Long userId, Long questionID) {
|
|
|
+ QueryWrapper<QuestionSubmit> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("user_id", userId).orderByDesc("create_time").last("limit 1");
|
|
|
+ QuestionSubmit record = questionSubmitMapper.selectOne(queryWrapper);
|
|
|
+ System.out.println(record);
|
|
|
+ if (record == null) {
|
|
|
+ return true;
|
|
|
+ } else if (record.getStatus() == 0 || record.getStatus() == 1) {
|
|
|
+ return false;
|
|
|
+ } else return System.currentTimeMillis() - record.getCreateTime().getTime() >= 2000;
|
|
|
+ }
|
|
|
}
|