rongrunxiang 1 vuosi sitten
vanhempi
commit
1e73f18e0d
24 muutettua tiedostoa jossa 399 lisäystä ja 362 poistoa
  1. 7 1
      pom.xml
  2. 0 29
      src/main/java/com/example/onlinejudge/common/BaseResponse.java
  3. 0 37
      src/main/java/com/example/onlinejudge/common/ErrorCode.java
  4. 0 46
      src/main/java/com/example/onlinejudge/common/ResultUtils.java
  5. 10 0
      src/main/java/com/example/onlinejudge/controller/JudgeController.java
  6. 98 92
      src/main/java/com/example/onlinejudge/controller/QuestionController.java
  7. 21 16
      src/main/java/com/example/onlinejudge/controller/QuestionSubmitController.java
  8. 6 3
      src/main/java/com/example/onlinejudge/exception/BusinessException.java
  9. 8 0
      src/main/java/com/example/onlinejudge/exception/GlobalExceptionHandler.java
  10. 4 4
      src/main/java/com/example/onlinejudge/exception/ThrowUtils.java
  11. 1 6
      src/main/java/com/example/onlinejudge/mapper/QuestionSubmitMapper.java
  12. 10 18
      src/main/java/com/example/onlinejudge/model/VO/UserVO.java
  13. 9 18
      src/main/java/com/example/onlinejudge/model/dto/question/QuestionAddRequest.java
  14. 14 20
      src/main/java/com/example/onlinejudge/model/dto/question/QuestionEditRequest.java
  15. 9 18
      src/main/java/com/example/onlinejudge/model/dto/question/QuestionQueryRequest.java
  16. 10 21
      src/main/java/com/example/onlinejudge/model/dto/question/QuestionUpdateRequest.java
  17. 4 12
      src/main/java/com/example/onlinejudge/model/dto/questionSubmit/QuestionSubmitQueryRequest.java
  18. 1 0
      src/main/java/com/example/onlinejudge/model/entity/Question.java
  19. 1 0
      src/main/java/com/example/onlinejudge/model/entity/User.java
  20. 4 0
      src/main/java/com/example/onlinejudge/model/entity/result/Result.java
  21. 4 2
      src/main/java/com/example/onlinejudge/model/entity/result/ResultCode.java
  22. 9 18
      src/main/java/com/example/onlinejudge/service/impl/QuestionServiceImpl.java
  23. 144 1
      src/main/java/com/example/onlinejudge/service/impl/QuestionSubmitServiceImpl.java
  24. 25 0
      src/main/java/com/example/onlinejudge/utils/SqlUtils.java

+ 7 - 1
pom.xml

@@ -36,8 +36,14 @@
             <scope>runtime</scope>
             <optional>true</optional>
         </dependency>
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-collections4</artifactId>
+            <version>4.4</version> <!-- 版本号可以根据您的需求进行更改 -->
+        </dependency>
+
 
-<!--         数据库相关 -->
+        <!--         数据库相关 -->
 <!--        <dependency>-->
 <!--            <groupId>mysql</groupId>-->
 <!--            <artifactId>mysql-connector-java</artifactId>-->

+ 0 - 29
src/main/java/com/example/onlinejudge/common/BaseResponse.java

@@ -1,29 +0,0 @@
-package com.example.onlinejudge.common;
-
-import lombok.Data;
-
-import java.io.Serializable;
-
-@Data
-public class BaseResponse<T> implements Serializable {
-
-    private int code;
-
-    private T data;
-
-    private String message;
-
-    public BaseResponse(int code, T data, String message) {
-        this.code = code;
-        this.data = data;
-        this.message = message;
-    }
-
-    public BaseResponse(int code, T data) {
-        this(code, data, "");
-    }
-
-    public BaseResponse(ErrorCode errorCode) {
-        this(errorCode.getCode(), null, errorCode.getMessage());
-    }
-}

+ 0 - 37
src/main/java/com/example/onlinejudge/common/ErrorCode.java

@@ -1,37 +0,0 @@
-package com.example.onlinejudge.common;
-
-public enum ErrorCode {
-
-    SUCCESS(0, "ok"),
-    PARAMS_ERROR(40000, "请求参数错误"),
-    NOT_LOGIN_ERROR(40100, "未登录"),
-    NO_AUTH_ERROR(40101, "无权限"),
-    NOT_FOUND_ERROR(40400, "请求数据不存在"),
-    FORBIDDEN_ERROR(40300, "禁止访问"),
-    SYSTEM_ERROR(50000, "系统内部异常"),
-    OPERATION_ERROR(50001, "操作失败");
-
-    /**
-     * 状态码
-     */
-    private final int code;
-
-    /**
-     * 信息
-     */
-    private final String message;
-
-    ErrorCode(int code, String message) {
-        this.code = code;
-        this.message = message;
-    }
-
-    public int getCode() {
-        return code;
-    }
-
-    public String getMessage() {
-        return message;
-    }
-
-}

+ 0 - 46
src/main/java/com/example/onlinejudge/common/ResultUtils.java

@@ -1,46 +0,0 @@
-package com.example.onlinejudge.common;
-
-public class ResultUtils {
-
-    /**
-     * 成功
-     *
-     * @param data
-     * @param <T>
-     * @return
-     */
-    public static <T> BaseResponse<T> success(T data) {
-        return new BaseResponse<>(0, data, "ok");
-    }
-
-    /**
-     * 失败
-     *
-     * @param errorCode
-     * @return
-     */
-    public static BaseResponse error(ErrorCode errorCode) {
-        return new BaseResponse<>(errorCode);
-    }
-
-    /**
-     * 失败
-     *
-     * @param code
-     * @param message
-     * @return
-     */
-    public static BaseResponse error(int code, String message) {
-        return new BaseResponse(code, null, message);
-    }
-
-    /**
-     * 失败
-     *
-     * @param errorCode
-     * @return
-     */
-    public static BaseResponse error(ErrorCode errorCode, String message) {
-        return new BaseResponse(errorCode.getCode(), null, message);
-    }
-}

+ 10 - 0
src/main/java/com/example/onlinejudge/controller/JudgeController.java

@@ -5,6 +5,8 @@ import com.example.onlinejudge.model.entity.result.ResultCode;
 import com.example.onlinejudge.model.enums.QuestionSubmitLanguageEnum;
 import com.example.onlinejudge.service.QuestionService;
 import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -26,6 +28,14 @@ public class JudgeController {
     }
 
     @ApiOperation(value = "提交代码")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "code", value = "代码", required = true, dataType = "String", paramType = "body"),
+            @ApiImplicitParam(name = "questionId", value = "问题id", required = true, dataType = "String", paramType = "body"),
+            @ApiImplicitParam(name = "language", value = "语言", required = true, dataType = "String", paramType = "body"),
+            @ApiImplicitParam(name = "userCases", value = "用户自定义测试用例", required = false, dataType = "String", paramType = "body"),
+            @ApiImplicitParam(name = "judgeMode", value = "判题模式", required = true, dataType = "int", paramType = "body"),
+
+    })
     @PostMapping("/submitCode")
     public Result submitCode(@RequestParam("code") String code,
                              @RequestParam("questionId") String questionID,

+ 98 - 92
src/main/java/com/example/onlinejudge/controller/QuestionController.java

@@ -1,19 +1,21 @@
 package com.example.onlinejudge.controller;
 
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.example.onlinejudge.common.BaseResponse;
+
 import com.example.onlinejudge.common.DeleteRequest;
-import com.example.onlinejudge.common.ErrorCode;
-import com.example.onlinejudge.common.ResultUtils;
-import com.example.onlinejudge.exception.BusinessException;
-import com.example.onlinejudge.exception.ThrowUtils;
+
+
 import com.example.onlinejudge.model.VO.QuestionVO;
 import com.example.onlinejudge.model.dto.question.*;
 import com.example.onlinejudge.model.entity.Question;
-import com.example.onlinejudge.model.entity.User;
+import com.example.onlinejudge.model.entity.result.Result;
+import com.example.onlinejudge.model.entity.result.ResultCode;
 import com.example.onlinejudge.service.QuestionService;
 import com.example.onlinejudge.service.UserService;
 import com.google.gson.Gson;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.web.bind.annotation.*;
@@ -38,16 +40,16 @@ public class QuestionController {
     // region 增删改查
 
     /**
-     * 创建
+     * 创建题目
      *
      * @param questionAddRequest
      * @param request
      * @return
      */
     @PostMapping("/add")
-    public BaseResponse<Long> addQuestion(@RequestBody QuestionAddRequest questionAddRequest, HttpServletRequest request) {
+    public Result<Long> addQuestion(@RequestBody QuestionAddRequest questionAddRequest, HttpServletRequest request) {
         if (questionAddRequest == null) {
-            throw new BusinessException(ErrorCode.PARAMS_ERROR);
+            return Result.error(ResultCode.PARAM_IS_BLANK);
         }
         Question question = new Question();
         BeanUtils.copyProperties(questionAddRequest, question);
@@ -64,12 +66,16 @@ public class QuestionController {
             question.setJudgeConfig(GSON.toJson(judgeConfig));
         }
         questionService.validQuestion(question, true);
+        //TODO:记录谁创建了这个题目
 //        User loginUser = userService.getLoginUser(request);
 //        question.setUserId(loginUser.getId());
         boolean result = questionService.save(question);
-        ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR);
+        if(!result){
+            return Result.error(ResultCode.PARAM_IS_INVALID);
+        }
+//        ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR);
         long newQuestionId = question.getId();
-        return ResultUtils.success(newQuestionId);
+        return Result.success(newQuestionId);
     }
 
     /**
@@ -80,20 +86,24 @@ public class QuestionController {
      * @return
      */
     @PostMapping("/delete")
-    public BaseResponse<Boolean> deleteQuestion(@RequestBody DeleteRequest deleteRequest, HttpServletRequest request) {
+    public Result<Boolean> deleteQuestion(@RequestBody DeleteRequest deleteRequest, HttpServletRequest request) {
         if (deleteRequest == null || deleteRequest.getId() <= 0) {
-            throw new BusinessException(ErrorCode.PARAMS_ERROR);
+            return Result.error(ResultCode.PARAM_IS_BLANK);
         }
         long id = deleteRequest.getId();
         // 判断是否存在
         Question oldQuestion = questionService.getById(id);
-        ThrowUtils.throwIf(oldQuestion == null, ErrorCode.NOT_FOUND_ERROR);
+        if(oldQuestion == null){
+            return Result.error(ResultCode.PARAM_IS_INVALID);
+        }
+        //ThrowUtils.throwIf(oldQuestion == null, ErrorCode.NOT_FOUND_ERROR);
         // 仅本人或管理员可删除
+        //TODO:判断是否是管理员
         if (false) {
-            throw new BusinessException(ErrorCode.NO_AUTH_ERROR);
+            return Result.error(ResultCode.PERMISSION_DENIED);
         }
         boolean b = questionService.removeById(id);
-        return ResultUtils.success(b);
+        return Result.success(b);
     }
 
 
@@ -104,98 +114,94 @@ public class QuestionController {
      * @return
      */
     @GetMapping("/get")
-    public BaseResponse<Question> getQuestionById(long id, HttpServletRequest request) {
+    public Result<Question> getQuestionById(long id, HttpServletRequest request) {
         if (id <= 0) {
-            throw new BusinessException(ErrorCode.PARAMS_ERROR);
+            return Result.error(ResultCode.PARAM_IS_INVALID);
         }
         Question question = questionService.getById(id);
         if (question == null) {
-            throw new BusinessException(ErrorCode.NOT_FOUND_ERROR);
+            return Result.error(ResultCode.NOT_FOUND_ERROR);
         }
+        //TODO:判断是否是管理员
 //        User loginUser = userService.getLoginUser(request);
 //        // 不是本人或管理员,不能直接获取所有信息
 //        if (!question.getUserId().equals(loginUser.getId()) && !userService.isAdmin(loginUser)) {
 //            throw new BusinessException(ErrorCode.NO_AUTH_ERROR);
 //        }
-        return ResultUtils.success(question);
+        return Result.success(question);
     }
 
-    /**
-     * 根据 id 获取(脱敏)
-     *
-     * @param id
-     * @return
-     */
+    @ApiOperation(value = "根据id获取题目(封装类)")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "id", value = "题目id", required = true, dataType = "long"),
+    })
     @GetMapping("/get/vo")
-    public BaseResponse<QuestionVO> getQuestionVOById(long id, HttpServletRequest request) {
+    public Result<QuestionVO> getQuestionVOById(long id, HttpServletRequest request) {
         if (id <= 0) {
-            throw new BusinessException(ErrorCode.PARAMS_ERROR);
+            return Result.error(ResultCode.PARAM_IS_INVALID);
         }
         Question question = questionService.getById(id);
         if (question == null) {
-            throw new BusinessException(ErrorCode.NOT_FOUND_ERROR);
+            return Result.error(ResultCode.NOT_FOUND_ERROR);
         }
-        return ResultUtils.success(questionService.getQuestionVO(question, request));
+        return Result.success(questionService.getQuestionVO(question, request));
     }
 
-    /**
-     * 分页获取列表(封装类)
-     *
-     * @param questionQueryRequest
-     * @param request
-     * @return
-     */
+
+    @ApiOperation(value = "分页获取题目列表(封装类)")
+    @ApiImplicitParams(
+            @ApiImplicitParam(name = "questionQueryRequest", value = "查询条件", required = true, dataType = "QuestionQueryRequest")
+    )
     @PostMapping("/list/page/vo")
-    public BaseResponse<Page<QuestionVO>> listQuestionVOByPage(@RequestBody QuestionQueryRequest questionQueryRequest,
+    public Result<Page<QuestionVO>> listQuestionVOByPage(@RequestBody QuestionQueryRequest questionQueryRequest,
                                                                HttpServletRequest request) {
         long current = questionQueryRequest.getCurrent();
         long size = questionQueryRequest.getPageSize();
         // 限制爬虫
-        ThrowUtils.throwIf(size > 20, ErrorCode.PARAMS_ERROR);
+        if(size > 20){
+            return Result.error(ResultCode.PARAM_IS_INVALID);
+        }
+        //ThrowUtils.throwIf(size > 20, ErrorCode.PARAMS_ERROR);
         Page<Question> questionPage = questionService.page(new Page<>(current, size),
                 questionService.getQueryWrapper(questionQueryRequest));
-        return ResultUtils.success(questionService.getQuestionVOPage(questionPage, request));
+        return Result.success(questionService.getQuestionVOPage(questionPage, request));
     }
 
-    /**
-     * 分页获取当前用户创建的资源列表
-     *
-     * @param questionQueryRequest
-     * @param request
-     * @return
-     */
+    @ApiOperation(value = "分页获取当前用户创建的题目列表(封装类)")
+    @ApiImplicitParams(
+            @ApiImplicitParam(name = "questionQueryRequest", value = "查询条件", required = true, dataType = "QuestionQueryRequest")
+    )
     @PostMapping("/my/list/page/vo")
-    public BaseResponse<Page<QuestionVO>> listMyQuestionVOByPage(@RequestBody QuestionQueryRequest questionQueryRequest,
+    public Result<Page<QuestionVO>> listMyQuestionVOByPage(@RequestBody QuestionQueryRequest questionQueryRequest,
                                                                  HttpServletRequest request) {
         if (questionQueryRequest == null) {
-            throw new BusinessException(ErrorCode.PARAMS_ERROR);
+            return Result.error(ResultCode.PARAM_IS_BLANK);
         }
 //        User loginUser = userService.getLoginUser(request);
 //        questionQueryRequest.setUserId(loginUser.getId());
         long current = questionQueryRequest.getCurrent();
         long size = questionQueryRequest.getPageSize();
         // 限制爬虫
-        ThrowUtils.throwIf(size > 20, ErrorCode.PARAMS_ERROR);
+        if(size > 20){
+            return Result.error(ResultCode.PARAM_IS_INVALID);
+        }
         Page<Question> questionPage = questionService.page(new Page<>(current, size),
                 questionService.getQueryWrapper(questionQueryRequest));
-        return ResultUtils.success(questionService.getQuestionVOPage(questionPage, request));
+        return Result.success(questionService.getQuestionVOPage(questionPage, request));
     }
 
-    /**
-     * 分页获取题目列表(仅管理员)
-     *
-     * @param questionQueryRequest
-     * @param request
-     * @return
-     */
+    @ApiOperation(value = "分页获取题目列表(仅管理员)")
+    @ApiImplicitParams(
+            @ApiImplicitParam(name = "questionQueryRequest", value = "查询条件", required = true, dataType = "QuestionQueryRequest")
+    )
     @PostMapping("/list/page")
-    public BaseResponse<Page<Question>> listQuestionByPage(@RequestBody QuestionQueryRequest questionQueryRequest,
+    public Result<Page<Question>> listQuestionByPage(@RequestBody QuestionQueryRequest questionQueryRequest,
                                                            HttpServletRequest request) {
         long current = questionQueryRequest.getCurrent();
         long size = questionQueryRequest.getPageSize();
         Page<Question> questionPage = questionService.page(new Page<>(current, size),
                 questionService.getQueryWrapper(questionQueryRequest));
-        return ResultUtils.success(questionPage);
+        return Result.success(questionPage);
     }
 
     // endregion
@@ -207,38 +213,38 @@ public class QuestionController {
      * @param request
      * @return
      */
-//    @PostMapping("/edit")
-//    public BaseResponse<Boolean> editQuestion(@RequestBody QuestionEditRequest questionEditRequest, HttpServletRequest request) {
-//        if (questionEditRequest == null || questionEditRequest.getId() <= 0) {
-//            throw new BusinessException(ErrorCode.PARAMS_ERROR);
-//        }
-//        Question question = new Question();
-//        BeanUtils.copyProperties(questionEditRequest, question);
-//        List<String> tags = questionEditRequest.getTags();
-//        if (tags != null) {
-//            question.setTags(GSON.toJson(tags));
-//        }
-//        List<JudgeCase> judgeCase = questionEditRequest.getJudgeCase();
-//        if (judgeCase != null) {
-//            question.setJudgeCase(GSON.toJson(judgeCase));
-//        }
-//        JudgeConfig judgeConfig = questionEditRequest.getJudgeConfig();
-//        if (judgeConfig != null) {
-//            question.setJudgeConfig(GSON.toJson(judgeConfig));
+    @PostMapping("/edit")
+    public Result<Boolean> editQuestion(@RequestBody QuestionEditRequest questionEditRequest, HttpServletRequest request) {
+        if (questionEditRequest == null || questionEditRequest.getId() <= 0) {
+            return Result.error(ResultCode.PARAM_IS_BLANK);
+        }
+        Question question = new Question();
+        BeanUtils.copyProperties(questionEditRequest, question);
+        List<String> tags = questionEditRequest.getTags();
+        if (tags != null) {
+            question.setTags(GSON.toJson(tags));
+        }
+        List<JudgeCase> judgeCase = questionEditRequest.getJudgeCase();
+        if (judgeCase != null) {
+            question.setJudgeCase(GSON.toJson(judgeCase));
+        }
+        JudgeConfig judgeConfig = questionEditRequest.getJudgeConfig();
+        if (judgeConfig != null) {
+            question.setJudgeConfig(GSON.toJson(judgeConfig));
+        }
+        // 参数校验
+        questionService.validQuestion(question, false);
+//        User loginUser = userService.getLoginUser(request);
+//        long id = questionEditRequest.getId();
+        // 判断是否存在
+//        Question oldQuestion = questionService.getById(id);
+//        ThrowUtils.throwIf(oldQuestion == null, ErrorCode.NOT_FOUND_ERROR);
+        // 仅本人或管理员可编辑
+//        if (!oldQuestion.getUserId().equals(loginUser.getId()) && !userService.isAdmin(loginUser)) {
+//            throw new BusinessException(ErrorCode.NO_AUTH_ERROR);
 //        }
-//        // 参数校验
-//        questionService.validQuestion(question, false);
-////        User loginUser = userService.getLoginUser(request);
-////        long id = questionEditRequest.getId();
-//        // 判断是否存在
-////        Question oldQuestion = questionService.getById(id);
-////        ThrowUtils.throwIf(oldQuestion == null, ErrorCode.NOT_FOUND_ERROR);
-//        // 仅本人或管理员可编辑
-////        if (!oldQuestion.getUserId().equals(loginUser.getId()) && !userService.isAdmin(loginUser)) {
-////            throw new BusinessException(ErrorCode.NO_AUTH_ERROR);
-////        }
-//        boolean result = questionService.updateById(question);
-//        return ResultUtils.success(result);
-//    }
+        boolean result = questionService.updateById(question);
+        return Result.success(result);
+    }
 
 }

+ 21 - 16
src/main/java/com/example/onlinejudge/controller/QuestionSubmitController.java

@@ -2,8 +2,7 @@ package com.example.onlinejudge.controller;
 
 
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.example.onlinejudge.common.BaseResponse;
-import com.example.onlinejudge.common.ResultUtils;
+
 import com.example.onlinejudge.model.VO.QuestionSubmitVO;
 import com.example.onlinejudge.model.dto.questionSubmit.QuestionSubmitAddRequest;
 import com.example.onlinejudge.model.dto.questionSubmit.QuestionSubmitQueryRequest;
@@ -13,6 +12,9 @@ import com.example.onlinejudge.model.entity.result.Result;
 import com.example.onlinejudge.model.entity.result.ResultCode;
 import com.example.onlinejudge.service.QuestionSubmitService;
 import com.example.onlinejudge.service.UserService;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -39,23 +41,21 @@ public class QuestionSubmitController {
     @Resource
     private UserService userService;
 
-    /**
-     * 提交题目
-     *
-     * @param questionSubmitAddRequest
-     * @param request
-     * @return 提交记录的 id
-     */
+    @ApiOperation(value = "提交题目")
+    @ApiImplicitParams(
+            @ApiImplicitParam(name = "questionSubmitAddRequest", value = "提交题目的请求", required = true, dataType = "QuestionSubmitAddRequest", paramType = "body")
+    )
     @PostMapping("/")
     public Result doQuestionSubmit(@RequestBody QuestionSubmitAddRequest questionSubmitAddRequest,
                                    HttpServletRequest request) {
         if (questionSubmitAddRequest == null || questionSubmitAddRequest.getQuestionId() <= 0) {
             return new Result(ResultCode.PARAM_IS_INVALID.getCode(),ResultCode.PARAM_IS_INVALID.getMessage());
         }
-        // 登录才能点赞
+        // TODO: 获取登录id
 //        final User loginUser = userService.getLoginUser(request);
-        long questionSubmitId = questionSubmitService.doQuestionSubmit(questionSubmitAddRequest, loginUser);
-        return Result.success(questionSubmitId);
+//        long questionSubmitId = questionSubmitService.doQuestionSubmit(questionSubmitAddRequest, loginUser);
+//        return Result.success(questionSubmitId);
+        return null;
     }
 
     /**
@@ -65,17 +65,22 @@ public class QuestionSubmitController {
      * @param request
      * @return
      */
+    @ApiOperation(value = "分页获取题目提交列表(除了管理员外,普通用户只能看到非答案、提交代码等公开信息)")
+    @ApiImplicitParams(
+            @ApiImplicitParam(name = "questionSubmitQueryRequest", value = "查询条件", required = true, dataType = "QuestionSubmitQueryRequest", paramType = "body")
+    )
     @PostMapping("/list/page")
-    public BaseResponse<Page<QuestionSubmitVO>> listQuestionSubmitByPage(@RequestBody QuestionSubmitQueryRequest questionSubmitQueryRequest,
+    public Result<Page<QuestionSubmitVO>> listQuestionSubmitByPage(@RequestBody QuestionSubmitQueryRequest questionSubmitQueryRequest,
                                                                          HttpServletRequest request) {
         long current = questionSubmitQueryRequest.getCurrent();
         long size = questionSubmitQueryRequest.getPageSize();
         // 从数据库中查询原始的题目提交分页信息
         Page<QuestionSubmit> questionSubmitPage = questionSubmitService.page(new Page<>(current, size),
                 questionSubmitService.getQueryWrapper(questionSubmitQueryRequest));
-        final User loginUser = userService.getLoginUser(request);
-        // 返回脱敏信息
-        return ResultUtils.success(questionSubmitService.getQuestionSubmitVOPage(questionSubmitPage, loginUser));
+//        final User loginUser = userService.getLoginUser(request);
+        // TODO 返回脱敏信息
+//        return ResultUtils.success(questionSubmitService.getQuestionSubmitVOPage(questionSubmitPage, loginUser));
+        return null;
     }
 
 

+ 6 - 3
src/main/java/com/example/onlinejudge/exception/BusinessException.java

@@ -1,9 +1,12 @@
 package com.example.onlinejudge.exception;
 
 
-import com.example.onlinejudge.common.ErrorCode;
+import com.example.onlinejudge.model.entity.result.ResultCode;
 
 public class BusinessException extends RuntimeException {
+    /**
+     * 错误码
+     */
     private final int code;
 
     public BusinessException(int code, String message) {
@@ -11,12 +14,12 @@ public class BusinessException extends RuntimeException {
         this.code = code;
     }
 
-    public BusinessException(ErrorCode errorCode) {
+    public BusinessException(ResultCode errorCode) {
         super(errorCode.getMessage());
         this.code = errorCode.getCode();
     }
 
-    public BusinessException(ErrorCode errorCode, String message) {
+    public BusinessException(ResultCode errorCode, String message) {
         super(message);
         this.code = errorCode.getCode();
     }

+ 8 - 0
src/main/java/com/example/onlinejudge/exception/GlobalExceptionHandler.java

@@ -4,6 +4,7 @@ import cn.dev33.satoken.exception.NotLoginException;
 import cn.dev33.satoken.util.SaResult;
 import com.example.onlinejudge.model.entity.result.Result;
 import com.example.onlinejudge.model.entity.result.ResultCode;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.web.bind.annotation.ExceptionHandler;
 import org.springframework.web.bind.annotation.RestControllerAdvice;
 
@@ -11,6 +12,7 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
  * 全局拦截异常
  */
 @RestControllerAdvice
+@Slf4j
 public class GlobalExceptionHandler {
     /**
      * 拦截未登录的用户进行非法权限操作
@@ -22,4 +24,10 @@ public class GlobalExceptionHandler {
         e.printStackTrace();
         return Result.error(ResultCode.USER_NOTLOGGED_IN);
     }
+
+    @ExceptionHandler(BusinessException.class)
+    public Result<?> businessExceptionHandler(BusinessException e) {
+        log.error("BusinessException", e);
+        return Result.error(e.getCode(), e.getMessage());
+    }
 }

+ 4 - 4
src/main/java/com/example/onlinejudge/exception/ThrowUtils.java

@@ -1,6 +1,6 @@
 package com.example.onlinejudge.exception;
 
-import com.example.onlinejudge.common.ErrorCode;
+import com.example.onlinejudge.model.entity.result.ResultCode;
 
 public class ThrowUtils {
 
@@ -22,7 +22,7 @@ public class ThrowUtils {
      * @param condition
      * @param errorCode
      */
-    public static void throwIf(boolean condition, ErrorCode errorCode) {
+    public static void throwIf(boolean condition, ResultCode errorCode) {
         throwIf(condition, new BusinessException(errorCode));
     }
 
@@ -33,7 +33,7 @@ public class ThrowUtils {
      * @param errorCode
      * @param message
      */
-    public static void throwIf(boolean condition, ErrorCode errorCode, String message) {
+    public static void throwIf(boolean condition, ResultCode errorCode, String message) {
         throwIf(condition, new BusinessException(errorCode, message));
     }
-}
+}

+ 1 - 6
src/main/java/com/example/onlinejudge/mapper/QuestionSubmitMapper.java

@@ -4,12 +4,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.example.onlinejudge.model.entity.QuestionSubmit;
 
 
-/**
-* @author 201250081
-* @description 针对表【question_submit】的数据库操作Mapper
-* @createDate 2023-08-18 18:18:47
-* @Entity generator.domain.QuestionSubmit
-*/
+
 public interface QuestionSubmitMapper extends BaseMapper<QuestionSubmit> {
 
 }

+ 10 - 18
src/main/java/com/example/onlinejudge/model/VO/UserVO.java

@@ -1,40 +1,32 @@
 package com.example.onlinejudge.model.VO;
 
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
 import java.io.Serializable;
 import java.util.Date;
 
 @Data
+@ApiModel("用户信息")
 public class UserVO implements Serializable {
-    /**
-     * id
-     */
+
+    @ApiModelProperty("用户ID")
     private Long id;
 
-    /**
-     * 用户昵称
-     */
+    @ApiModelProperty("用户名")
     private String userName;
 
-    /**
-     * 用户头像
-     */
+    @ApiModelProperty("用户头像")
     private String userAvatar;
 
-    /**
-     * 用户简介
-     */
+    @ApiModelProperty("用户简介")
     private String userProfile;
 
-    /**
-     * 用户角色:user/admin/ban
-     */
+    @ApiModelProperty("用户角色")
     private String userRole;
 
-    /**
-     * 创建时间
-     */
+    @ApiModelProperty("用户创建时间")
     private Date createTime;
 
     private static final long serialVersionUID = 1L;

+ 9 - 18
src/main/java/com/example/onlinejudge/model/dto/question/QuestionAddRequest.java

@@ -1,41 +1,32 @@
 package com.example.onlinejudge.model.dto.question;
 
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
 import java.io.Serializable;
 import java.util.List;
 
 @Data
+@ApiModel("创建问题请求")
 public class QuestionAddRequest implements Serializable {
 
-        /**
-        * 标题
-        */
+        @ApiModelProperty("标题")
         private String title;
 
-        /**
-        * 内容
-        */
+        @ApiModelProperty("内容")
         private String content;
 
-        /**
-        * 标签列表
-        */
+        @ApiModelProperty("标签列表")
         private List<String> tags;
 
-        /**
-        * 题目答案
-        */
+        @ApiModelProperty("题目答案")
         private String answer;
 
-        /**
-        * 判题用例
-        */
+        @ApiModelProperty("判题用例")
         private List<JudgeCase> judgeCase;
 
-        /**
-        * 判题配置
-        */
+        @ApiModelProperty("判题配置")
         private JudgeConfig judgeConfig;
 
         private static final long serialVersionUID = 1L;

+ 14 - 20
src/main/java/com/example/onlinejudge/model/dto/question/QuestionEditRequest.java

@@ -1,42 +1,36 @@
 package com.example.onlinejudge.model.dto.question;
 
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
 import java.io.Serializable;
 import java.util.List;
 
 @Data
-public class QuestionEditRequest implements Serializable{
+@ApiModel("编辑问题请求")
+public class QuestionEditRequest implements Serializable {
 
-        /**
-        * 标题
-        */
+        @ApiModelProperty("id")
+        private Long id;
+
+        @ApiModelProperty("标题")
         private String title;
 
-        /**
-        * 内容
-        */
+        @ApiModelProperty("内容")
         private String content;
 
-        /**
-        * 标签列表
-        */
+        @ApiModelProperty("标签列表")
         private List<String> tags;
 
-        /**
-        * 题目答案
-        */
+        @ApiModelProperty("题目答案")
         private String answer;
 
-        /**
-        * 判题用例
-        */
+        @ApiModelProperty("判题用例")
         private List<JudgeCase> judgeCase;
 
-        /**
-        * 判题配置
-        */
+        @ApiModelProperty("判题配置")
         private JudgeConfig judgeConfig;
 
         private static final long serialVersionUID = 1L;
-}
+}

+ 9 - 18
src/main/java/com/example/onlinejudge/model/dto/question/QuestionQueryRequest.java

@@ -1,6 +1,8 @@
 package com.example.onlinejudge.model.dto.question;
 
 import com.example.onlinejudge.common.PageRequest;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 
@@ -9,36 +11,25 @@ import java.util.List;
 
 
 @Data
+@ApiModel("查询问题请求")
 public class QuestionQueryRequest extends PageRequest implements Serializable {
 
-    /**
-     * id
-     */
+    @ApiModelProperty("id")
     private Long id;
 
-    /**
-     * 标题
-     */
+    @ApiModelProperty("标题")
     private String title;
 
-    /**
-     * 内容
-     */
+    @ApiModelProperty("内容")
     private String content;
 
-    /**
-     * 标签列表
-     */
+    @ApiModelProperty("标签列表")
     private List<String> tags;
 
-    /**
-     * 题目答案
-     */
+    @ApiModelProperty("题目答案")
     private String answer;
 
-    /**
-     * 创建用户 id
-     */
+    @ApiModelProperty("创建用户 id")
     private Long userId;
 
     private static final long serialVersionUID = 1L;

+ 10 - 21
src/main/java/com/example/onlinejudge/model/dto/question/QuestionUpdateRequest.java

@@ -1,46 +1,35 @@
 package com.example.onlinejudge.model.dto.question;
 
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
 import java.io.Serializable;
 import java.util.List;
 
 @Data
+@ApiModel("更新问题请求")
 public class QuestionUpdateRequest implements Serializable {
 
-    /**
-     * id
-     */
+    @ApiModelProperty("id")
     private Long id;
 
-    /**
-     * 标题
-     */
+    @ApiModelProperty("标题")
     private String title;
 
-    /**
-     * 内容
-     */
+    @ApiModelProperty("内容")
     private String content;
 
-    /**
-     * 标签列表
-     */
+    @ApiModelProperty("标签列表")
     private List<String> tags;
 
-    /**
-     * 题目答案
-     */
+    @ApiModelProperty("题目答案")
     private String answer;
 
-    /**
-     * 判题用例
-     */
+    @ApiModelProperty("判题用例")
     private List<JudgeCase> judgeCase;
 
-    /**
-     * 判题配置
-     */
+    @ApiModelProperty("判题配置")
     private JudgeConfig judgeConfig;
 
     private static final long serialVersionUID = 1L;

+ 4 - 12
src/main/java/com/example/onlinejudge/model/dto/questionSubmit/QuestionSubmitQueryRequest.java

@@ -13,25 +13,17 @@ import java.io.Serializable;
 @EqualsAndHashCode(callSuper = true)
 public class QuestionSubmitQueryRequest extends PageRequest implements Serializable {
 
-        /**
-         * 编程语言
-         */
+        @ApiModelProperty("编程语言")
         private String language;
 
-        /**
-         * 提交状态
-         */
+        @ApiModelProperty("提交状态")
         private Integer status;
 
-        /**
-         * 题目 id
-         */
+        @ApiModelProperty("题目 id")
         private Long questionId;
 
 
-        /**
-         * 用户 id
-         */
+        @ApiModelProperty("用户 id")
         private Long userId;
 
         private static final long serialVersionUID = 1L;

+ 1 - 0
src/main/java/com/example/onlinejudge/model/entity/Question.java

@@ -10,6 +10,7 @@ import java.util.Date;
 @ApiModel("题目")
 @Data
 public class Question {
+
     @ApiModelProperty("题目ID")
     @TableId(type = IdType.ASSIGN_ID)
     private Long id;

+ 1 - 0
src/main/java/com/example/onlinejudge/model/entity/User.java

@@ -19,6 +19,7 @@ import java.util.List;
 @AllArgsConstructor
 @NoArgsConstructor
 public class User {
+
     @ApiModelProperty("用户ID")
     @TableId(type = IdType.AUTO)
     private Long id;

+ 4 - 0
src/main/java/com/example/onlinejudge/model/entity/result/Result.java

@@ -16,6 +16,10 @@ public class Result<T> implements Serializable {
         this.code = code;
         this.message = message;
     }
+
+    public Result(int code, T data){
+        this(code, "", data);
+    }
     public Result(int code, String message,T data) {
         this.code = code;
         this.message = message;

+ 4 - 2
src/main/java/com/example/onlinejudge/model/entity/result/ResultCode.java

@@ -20,12 +20,14 @@ public enum ResultCode {
     /* 数据库异常 3001-3999*/
     DATABASE_ERROR(3001, "数据库异常"),
     DATABASE_DUPLICATE_INSERT(3002,"重复插入"),
+    NOT_FOUND_ERROR(3003,"请求的参数不存在"),
+
 
     /* 系统错误 10001-19999 */
     SYSTEM_ERROR(10000, "系统异常,请稍后重试")
     ;
-    private Integer code;
-    private String message;
+    private final Integer code;
+    private final String message;
 
     private ResultCode(Integer code, String message) {
         this.code = code;

+ 9 - 18
src/main/java/com/example/onlinejudge/service/impl/QuestionServiceImpl.java

@@ -1,38 +1,27 @@
 package com.example.onlinejudge.service.impl;
 
-import cn.dev33.satoken.stp.StpUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.example.onlinejudge.common.ErrorCode;
-import com.example.onlinejudge.constant.CommonConstant;
 import com.example.onlinejudge.exception.BusinessException;
 import com.example.onlinejudge.exception.ThrowUtils;
 import com.example.onlinejudge.mapper.QuestionMapper;
-import com.example.onlinejudge.mapper.QuestionSubmitMapper;
 import com.example.onlinejudge.model.VO.QuestionVO;
-import com.example.onlinejudge.model.VO.UserVO;
 import com.example.onlinejudge.model.dto.question.QuestionQueryRequest;
 import com.example.onlinejudge.model.entity.Question;
-import com.example.onlinejudge.model.entity.QuestionSubmit;
 import com.example.onlinejudge.model.entity.User;
 import com.example.onlinejudge.model.entity.result.Result;
 import com.example.onlinejudge.model.entity.result.ResultCode;
-import com.example.onlinejudge.model.enums.JudgeInfoMessageEnum;
-import com.example.onlinejudge.model.enums.QuestionSubmitLanguageEnum;
 import com.example.onlinejudge.service.QuestionService;
 import com.example.onlinejudge.service.UserService;
 import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 //import org.apache.commons.collections4.CollectionUtils;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
-import java.util.Date;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
 import java.util.stream.Collectors;
 
@@ -42,6 +31,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question>
         implements QuestionService{
 
 
+    //TODO:这个类增删改查修改一下
     @Resource
     private UserService userService;
 
@@ -53,7 +43,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question>
     @Override
     public void validQuestion(Question question, boolean add) {
         if (question == null) {
-            throw new BusinessException(ErrorCode.PARAMS_ERROR);
+            throw new BusinessException(ResultCode.PARAM_IS_BLANK);
         }
         String title = question.getTitle();
         String content = question.getContent();
@@ -63,23 +53,23 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question>
         String judgeConfig = question.getJudgeConfig();
         // 创建时,参数不能为空
         if (add) {
-            ThrowUtils.throwIf(StringUtils.isAnyBlank(title, content, tags), ErrorCode.PARAMS_ERROR);
+            ThrowUtils.throwIf(StringUtils.isAnyBlank(title, content, tags), ResultCode.PARAM_IS_INVALID);
         }
         // 有参数则校验
         if (StringUtils.isNotBlank(title) && title.length() > 80) {
-            throw new BusinessException(ErrorCode.PARAMS_ERROR, "标题过长");
+            throw new BusinessException(ResultCode.PARAM_IS_INVALID, "标题过长");
         }
         if (StringUtils.isNotBlank(content) && content.length() > 8192) {
-            throw new BusinessException(ErrorCode.PARAMS_ERROR, "内容过长");
+            throw new BusinessException(ResultCode.PARAM_IS_INVALID, "内容过长");
         }
         if (StringUtils.isNotBlank(answer) && answer.length() > 8192) {
-            throw new BusinessException(ErrorCode.PARAMS_ERROR, "答案过长");
+            throw new BusinessException(ResultCode.PARAM_IS_INVALID, "答案过长");
         }
         if (StringUtils.isNotBlank(judgeCase) && judgeCase.length() > 8192) {
-            throw new BusinessException(ErrorCode.PARAMS_ERROR, "判题用例过长");
+            throw new BusinessException(ResultCode.PARAM_IS_INVALID, "判题用例过长");
         }
         if (StringUtils.isNotBlank(judgeConfig) && judgeConfig.length() > 8192) {
-            throw new BusinessException(ErrorCode.PARAMS_ERROR, "判题配置过长");
+            throw new BusinessException(ResultCode.PARAM_IS_INVALID, "判题配置过长");
         }
     }
 
@@ -151,6 +141,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question>
             QuestionVO questionVO = QuestionVO.objToVo(question);
             Long userId = question.getUserId();
             User user = null;
+            //TODO 填充userID
 //            if (userIdUserListMap.containsKey(userId)) {
 //                user = userIdUserListMap.get(userId).get(0);
 //            }

+ 144 - 1
src/main/java/com/example/onlinejudge/service/impl/QuestionSubmitServiceImpl.java

@@ -1,4 +1,147 @@
 package com.example.onlinejudge.service.impl;
 
-public class QuestionSubmitServiceImpl {
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.example.onlinejudge.constant.CommonConstant;
+import com.example.onlinejudge.exception.BusinessException;
+import com.example.onlinejudge.judge.JudgeService;
+import com.example.onlinejudge.mapper.QuestionSubmitMapper;
+import com.example.onlinejudge.model.VO.QuestionSubmitVO;
+import com.example.onlinejudge.model.dto.questionSubmit.QuestionSubmitAddRequest;
+import com.example.onlinejudge.model.dto.questionSubmit.QuestionSubmitQueryRequest;
+import com.example.onlinejudge.model.entity.Question;
+import com.example.onlinejudge.model.entity.QuestionSubmit;
+import com.example.onlinejudge.model.entity.User;
+import com.example.onlinejudge.model.entity.result.ResultCode;
+import com.example.onlinejudge.model.enums.QuestionSubmitLanguageEnum;
+import com.example.onlinejudge.model.enums.QuestionSubmitStatusEnum;
+import com.example.onlinejudge.service.QuestionService;
+import com.example.onlinejudge.service.QuestionSubmitService;
+import com.example.onlinejudge.service.UserService;
+import com.example.onlinejudge.utils.SqlUtils;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.context.annotation.Lazy;
+
+import javax.annotation.Resource;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.stream.Collectors;
+
+public class QuestionSubmitServiceImpl extends ServiceImpl<QuestionSubmitMapper, QuestionSubmit>
+        implements QuestionSubmitService {
+
+    @Resource
+    private QuestionService questionService;
+
+    @Resource
+    private UserService userService;
+
+    @Resource
+    @Lazy
+    private JudgeService judgeService;
+
+    /**
+     * 提交题目
+     *
+     * @param questionSubmitAddRequest
+     * @param loginUser
+     * @return
+     */
+    @Override
+    public long doQuestionSubmit(QuestionSubmitAddRequest questionSubmitAddRequest, User loginUser) {
+        // 校验编程语言是否合法
+        String language = questionSubmitAddRequest.getLanguage();
+        QuestionSubmitLanguageEnum languageEnum = QuestionSubmitLanguageEnum.getEnumByValue(language);
+        if (languageEnum == null) {
+            throw new BusinessException(ResultCode.PARAM_IS_INVALID, "编程语言错误");
+        }
+        long questionId = questionSubmitAddRequest.getQuestionId();
+        // 判断实体是否存在,根据类别获取实体
+        Question question = questionService.getById(questionId);
+        if (question == null) {
+            throw new BusinessException(ResultCode.NOT_FOUND_ERROR);
+        }
+        // 是否已提交题目
+        long userId = loginUser.getId();
+        // 每个用户串行提交题目
+        QuestionSubmit questionSubmit = new QuestionSubmit();
+        questionSubmit.setUserId(userId);
+        questionSubmit.setQuestionId(questionId);
+        questionSubmit.setCode(questionSubmitAddRequest.getCode());
+        questionSubmit.setLanguage(language);
+        // 设置初始状态
+        questionSubmit.setStatus(QuestionSubmitStatusEnum.WAITING.getValue());
+        questionSubmit.setJudgeInfo("{}");
+        boolean save = this.save(questionSubmit);
+        if (!save){
+            throw new BusinessException(ResultCode.SYSTEM_ERROR, "数据插入失败");
+        }
+        Long questionSubmitId = questionSubmit.getId();
+        // 执行判题服务
+        CompletableFuture.runAsync(() -> {
+            judgeService.doJudge(questionSubmitId);
+        });
+        return questionSubmitId;
+    }
+
+
+    /**
+     * 获取查询包装类(用户根据哪些字段查询,根据前端传来的请求对象,得到 mybatis 框架支持的查询 QueryWrapper 类)
+     *
+     * @param questionSubmitQueryRequest
+     * @return
+     */
+    @Override
+    public QueryWrapper<QuestionSubmit> getQueryWrapper(QuestionSubmitQueryRequest questionSubmitQueryRequest) {
+        QueryWrapper<QuestionSubmit> queryWrapper = new QueryWrapper<>();
+        if (questionSubmitQueryRequest == null) {
+            return queryWrapper;
+        }
+        String language = questionSubmitQueryRequest.getLanguage();
+        Integer status = questionSubmitQueryRequest.getStatus();
+        Long questionId = questionSubmitQueryRequest.getQuestionId();
+        Long userId = questionSubmitQueryRequest.getUserId();
+        String sortField = questionSubmitQueryRequest.getSortField();
+        String sortOrder = questionSubmitQueryRequest.getSortOrder();
+
+        // 拼接查询条件
+        queryWrapper.eq(StringUtils.isNotBlank(language), "language", language);
+        queryWrapper.eq(ObjectUtils.isNotEmpty(userId), "userId", userId);
+        queryWrapper.eq(ObjectUtils.isNotEmpty(questionId), "questionId", questionId);
+        queryWrapper.eq(QuestionSubmitStatusEnum.getEnumByValue(status) != null, "status", status);
+        queryWrapper.eq("isDelete", false);
+        queryWrapper.orderBy(SqlUtils.validSortField(sortField), sortOrder.equals(CommonConstant.SORT_ORDER_ASC),
+                sortField);
+        return queryWrapper;
+    }
+
+    @Override
+    public QuestionSubmitVO getQuestionSubmitVO(QuestionSubmit questionSubmit, User loginUser) {
+        QuestionSubmitVO questionSubmitVO = QuestionSubmitVO.objToVo(questionSubmit);
+        // 脱敏:仅本人和管理员能看见自己(提交 userId 和登录用户 id 不同)提交的代码
+        long userId = loginUser.getId();
+        // 处理脱敏
+        //TODO  && !userService.isAdmin(loginUser)
+        if (userId != questionSubmit.getUserId() ) {
+            questionSubmitVO.setCode(null);
+        }
+        return questionSubmitVO;
+    }
+
+    @Override
+    public Page<QuestionSubmitVO> getQuestionSubmitVOPage(Page<QuestionSubmit> questionSubmitPage, User loginUser) {
+        List<QuestionSubmit> questionSubmitList = questionSubmitPage.getRecords();
+        Page<QuestionSubmitVO> questionSubmitVOPage = new Page<>(questionSubmitPage.getCurrent(), questionSubmitPage.getSize(), questionSubmitPage.getTotal());
+        if (CollectionUtils.isEmpty(questionSubmitList)) {
+            return questionSubmitVOPage;
+        }
+        List<QuestionSubmitVO> questionSubmitVOList = questionSubmitList.stream()
+                .map(questionSubmit -> getQuestionSubmitVO(questionSubmit, loginUser))
+                .collect(Collectors.toList());
+        questionSubmitVOPage.setRecords(questionSubmitVOList);
+        return questionSubmitVOPage;
+    }
 }

+ 25 - 0
src/main/java/com/example/onlinejudge/utils/SqlUtils.java

@@ -0,0 +1,25 @@
+package com.example.onlinejudge.utils;
+
+import org.apache.commons.lang3.StringUtils;
+
+/**
+ * SQL 工具
+ *
+ * @author <a href="https://github.com/liyupi">程序员鱼皮</a>
+ * @from <a href="https://yupi.icu">编程导航知识星球</a>
+ */
+public class SqlUtils {
+
+    /**
+     * 校验排序字段是否合法(防止 SQL 注入)
+     *
+     * @param sortField
+     * @return
+     */
+    public static boolean validSortField(String sortField) {
+        if (StringUtils.isBlank(sortField)) {
+            return false;
+        }
+        return !StringUtils.containsAny(sortField, "=", "(", ")", " ");
+    }
+}