Explorar el Código

Merge branch 'rongrunxiang/judge' of rongrunxiang/OnlineJudge into master

rongrunxiang hace 2 años
padre
commit
3009434b92
Se han modificado 28 ficheros con 1085 adiciones y 10 borrados
  1. 5 0
      README.md
  2. 59 0
      pom.xml
  3. 25 0
      src/main/java/com/example/onlinejudge/controller/JudgeController.java
  4. 0 2
      src/main/java/com/example/onlinejudge/controller/UserController.java
  5. 1 2
      src/main/java/com/example/onlinejudge/mapper/UserMapper.java
  6. 106 0
      src/main/java/com/example/onlinejudge/model/VO/QuestionSubmitVO.java
  7. 125 0
      src/main/java/com/example/onlinejudge/model/VO/QuestionVO.java
  8. 41 0
      src/main/java/com/example/onlinejudge/model/VO/UserVO.java
  9. 20 0
      src/main/java/com/example/onlinejudge/model/dto/question/JudgeCase.java
  10. 25 0
      src/main/java/com/example/onlinejudge/model/dto/question/JudgeConfig.java
  11. 22 0
      src/main/java/com/example/onlinejudge/model/dto/questionSubmit/JudgeInfo.java
  12. 26 0
      src/main/java/com/example/onlinejudge/model/dto/questionSubmit/QuestionSubmitAddRequest.java
  13. 27 0
      src/main/java/com/example/onlinejudge/model/dto/questionSubmit/QuestionSubmitQueryRequest.java
  14. 92 0
      src/main/java/com/example/onlinejudge/model/entity/Question.java
  15. 69 0
      src/main/java/com/example/onlinejudge/model/entity/QuestionSubmit.java
  16. 62 0
      src/main/java/com/example/onlinejudge/model/entity/SubmitCode.java
  17. 1 1
      src/main/java/com/example/onlinejudge/model/entity/User.java
  18. 75 0
      src/main/java/com/example/onlinejudge/model/entity/result/Result.java
  19. 41 0
      src/main/java/com/example/onlinejudge/model/entity/result/ResultCode.java
  20. 68 0
      src/main/java/com/example/onlinejudge/model/enums/JudgeInfoMessageEnum.java
  21. 60 0
      src/main/java/com/example/onlinejudge/model/enums/QuestionSubmitLanguageEnum.java
  22. 59 0
      src/main/java/com/example/onlinejudge/model/enums/QuestionSubmitStatusEnum.java
  23. 58 0
      src/main/java/com/example/onlinejudge/model/enums/UserRoleEnum.java
  24. 4 0
      src/main/java/com/example/onlinejudge/service/QuestionService.java
  25. 4 0
      src/main/java/com/example/onlinejudge/service/impl/QuestionServiceImpl.java
  26. 1 3
      src/main/java/com/example/onlinejudge/service/impl/UserServiceImpl.java
  27. 7 0
      src/main/resources/application.yml
  28. 2 2
      src/main/resources/mapper/userMapper.xml

+ 5 - 0
README.md

@@ -1,2 +1,7 @@
 # OnlineJudge
 
+判题字段
+
+* sourceCode(需要使用base64进行编码)
+* languageID
+* stdin

+ 59 - 0
pom.xml

@@ -19,25 +19,84 @@
     <dependencies>
         <dependency>
             <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-web</artifactId>
         </dependency>
         <dependency>
             <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-devtools</artifactId>
             <scope>runtime</scope>
             <optional>true</optional>
         </dependency>
+
+        <!-- 数据库相关 -->
+        <dependency>
+            <groupId>mysql</groupId>
+            <artifactId>mysql-connector-java</artifactId>
+            <version>8.0.28</version>
+        </dependency>
+        <dependency>
+            <groupId>org.mybatis.spring.boot</groupId>
+            <artifactId>mybatis-spring-boot-starter</artifactId>
+            <version>2.3.1</version>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-jdbc</artifactId>
+            <version>5.3.14</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-lang3</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.baomidou</groupId>
+            <artifactId>mybatis-plus-boot-starter</artifactId>
+            <version>3.5.2</version>
+        </dependency>
+
+        <!-- 登陆/权限相关 -->
+        <dependency>
+            <groupId>cn.dev33</groupId>
+            <artifactId>sa-token-spring-boot-starter</artifactId>
+            <version>1.34.0.temp1</version>
+        </dependency>
+
+        <!-- 工具类 -->
         <dependency>
             <groupId>org.projectlombok</groupId>
             <artifactId>lombok</artifactId>
             <optional>true</optional>
         </dependency>
         <dependency>
+            <groupId>cn.hutool</groupId>
+            <artifactId>hutool-all</artifactId>
+            <version>5.8.18</version>
+        </dependency>
+        <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-test</artifactId>
             <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.github.xiaoymin</groupId>
+            <artifactId>knife4j-openapi2-spring-boot-starter</artifactId>
+            <version>4.1.0</version>
+        </dependency>
+        <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-jdbc</artifactId>
         </dependency>

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

@@ -0,0 +1,25 @@
+package com.example.onlinejudge.controller;
+
+import com.example.onlinejudge.model.entity.result.Result;
+import com.example.onlinejudge.model.entity.result.ResultCode;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@Api(tags = "提交判题")
+@RestController
+@RequestMapping("/judge")
+@Slf4j
+public class JudgeController {
+
+    @ApiOperation(value = "上传代码进行判题")
+    @PostMapping("/insertDataset")
+    public Result insertDataset(){
+
+        return Result.success();
+    }
+}

+ 0 - 2
src/main/java/com/example/onlinejudge/controller/UserController.java

@@ -2,8 +2,6 @@ package com.example.onlinejudge.controller;
 
 import cn.dev33.satoken.stp.StpUtil;
 import cn.dev33.satoken.util.SaResult;
-import com.example.onlinejudge.bean.User;
-import com.example.onlinejudge.mapper.UserMapper;
 import com.example.onlinejudge.service.UserService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;

+ 1 - 2
src/main/java/com/example/onlinejudge/mapper/UserMapper.java

@@ -1,8 +1,7 @@
 package com.example.onlinejudge.mapper;
 
-import com.example.onlinejudge.bean.User;
+import com.example.onlinejudge.model.entity.User;
 import org.apache.ibatis.annotations.Mapper;
-import org.apache.ibatis.annotations.Select;
 
 @Mapper
 public interface UserMapper {

+ 106 - 0
src/main/java/com/example/onlinejudge/model/VO/QuestionSubmitVO.java

@@ -0,0 +1,106 @@
+package com.example.onlinejudge.model.VO;
+
+import cn.hutool.json.JSONUtil;
+import com.example.onlinejudge.model.dto.questionSubmit.JudgeInfo;
+import com.example.onlinejudge.model.entity.QuestionSubmit;
+import lombok.Data;
+import org.springframework.beans.BeanUtils;
+
+import java.io.Serializable;
+import java.util.Date;
+
+@Data
+public class QuestionSubmitVO implements Serializable {
+    /**
+     * id
+     */
+    private Long id;
+
+    /**
+     * 编程语言
+     */
+    private String language;
+
+    /**
+     * 用户代码
+     */
+    private String code;
+
+    /**
+     * 判题信息
+     */
+    private JudgeInfo judgeInfo;
+
+    /**
+     * 判题状态(0 - 待判题、1 - 判题中、2 - 成功、3 - 失败)
+     */
+    private Integer status;
+
+    /**
+     * 题目 id
+     */
+    private Long questionId;
+
+    /**
+     * 创建用户 id
+     */
+    private Long userId;
+
+    /**
+     * 创建时间
+     */
+    private Date createTime;
+
+    /**
+     * 更新时间
+     */
+    private Date updateTime;
+
+    /**
+     * 提交用户信息
+     */
+    private UserVO userVO;
+
+    /**
+     * 对应题目信息
+     */
+    private QuestionVO questionVO;
+
+    /**
+     * 包装类转对象
+     *
+     * @param questionSubmitVO
+     * @return
+     */
+    public static QuestionSubmit voToObj(QuestionSubmitVO questionSubmitVO) {
+        if (questionSubmitVO == null) {
+            return null;
+        }
+        QuestionSubmit questionSubmit = new QuestionSubmit();
+        BeanUtils.copyProperties(questionSubmitVO, questionSubmit);
+        JudgeInfo judgeInfoObj = questionSubmitVO.getJudgeInfo();
+        if (judgeInfoObj != null) {
+            questionSubmit.setJudgeInfo(JSONUtil.toJsonStr(judgeInfoObj));
+        }
+        return questionSubmit;
+    }
+
+    /**
+     * 对象转包装类
+     *
+     * @param questionSubmit
+     * @return
+     */
+    public static QuestionSubmitVO objToVo(QuestionSubmit questionSubmit) {
+        if (questionSubmit == null) {
+            return null;
+        }
+        QuestionSubmitVO questionSubmitVO = new QuestionSubmitVO();
+        BeanUtils.copyProperties(questionSubmit, questionSubmitVO);
+        String judgeInfoStr = questionSubmit.getJudgeInfo();
+        questionSubmitVO.setJudgeInfo(JSONUtil.toBean(judgeInfoStr, JudgeInfo.class));
+        return questionSubmitVO;
+    }
+
+    private static final long serialVersionUID = 1L;
+}

+ 125 - 0
src/main/java/com/example/onlinejudge/model/VO/QuestionVO.java

@@ -0,0 +1,125 @@
+package com.example.onlinejudge.model.VO;
+
+import cn.hutool.json.JSONUtil;
+import com.example.onlinejudge.model.dto.question.JudgeConfig;
+import com.example.onlinejudge.model.entity.Question;
+import lombok.Data;
+import org.springframework.beans.BeanUtils;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 题目封装类
+ */
+@Data
+public class QuestionVO {
+    /**
+     * id
+     */
+    private Long id;
+
+    /**
+     * 标题
+     */
+    private String title;
+
+    /**
+     * 内容
+     */
+    private String content;
+
+    /**
+     * 标签列表
+     */
+    private List<String> tags;
+
+    /**
+     * 题目提交数
+     */
+    private Integer submitNum;
+
+    /**
+     * 题目通过数
+     */
+    private Integer acceptedNum;
+
+    /**
+     * 判题配置(json 对象)
+     */
+    private JudgeConfig judgeConfig;
+
+    /**
+     * 点赞数
+     */
+    private Integer thumbNum;
+
+    /**
+     * 收藏数
+     */
+    private Integer favourNum;
+
+    /**
+     * 创建用户 id
+     */
+    private Long userId;
+
+    /**
+     * 创建时间
+     */
+    private Date createTime;
+
+    /**
+     * 更新时间
+     */
+    private Date updateTime;
+
+    /**
+     * 创建题目人的信息
+     */
+    private UserVO userVO;
+
+    /**
+     * 包装类转对象
+     *
+     * @param questionVO
+     * @return
+     */
+    public static Question voToObj(QuestionVO questionVO) {
+        if (questionVO == null) {
+            return null;
+        }
+        Question question = new Question();
+        BeanUtils.copyProperties(questionVO, question);
+        List<String> tagList = questionVO.getTags();
+        if (tagList != null) {
+            question.setTags(JSONUtil.toJsonStr(tagList));
+        }
+        JudgeConfig voJudgeConfig = questionVO.getJudgeConfig();
+        if (voJudgeConfig != null) {
+            question.setJudgeConfig(JSONUtil.toJsonStr(voJudgeConfig));
+        }
+        return question;
+    }
+
+    /**
+     * 对象转包装类
+     *
+     * @param question
+     * @return
+     */
+    public static QuestionVO objToVo(Question question) {
+        if (question == null) {
+            return null;
+        }
+        QuestionVO questionVO = new QuestionVO();
+        BeanUtils.copyProperties(question, questionVO);
+        List<String> tagList = JSONUtil.toList(question.getTags(), String.class);
+        questionVO.setTags(tagList);
+        String judgeConfigStr = question.getJudgeConfig();
+        questionVO.setJudgeConfig(JSONUtil.toBean(judgeConfigStr, JudgeConfig.class));
+        return questionVO;
+    }
+
+    private static final long serialVersionUID = 1L;
+}

+ 41 - 0
src/main/java/com/example/onlinejudge/model/VO/UserVO.java

@@ -0,0 +1,41 @@
+package com.example.onlinejudge.model.VO;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+@Data
+public class UserVO implements Serializable {
+    /**
+     * id
+     */
+    private Long id;
+
+    /**
+     * 用户昵称
+     */
+    private String userName;
+
+    /**
+     * 用户头像
+     */
+    private String userAvatar;
+
+    /**
+     * 用户简介
+     */
+    private String userProfile;
+
+    /**
+     * 用户角色:user/admin/ban
+     */
+    private String userRole;
+
+    /**
+     * 创建时间
+     */
+    private Date createTime;
+
+    private static final long serialVersionUID = 1L;
+}

+ 20 - 0
src/main/java/com/example/onlinejudge/model/dto/question/JudgeCase.java

@@ -0,0 +1,20 @@
+package com.example.onlinejudge.model.dto.question;
+
+import lombok.Data;
+
+/**
+ * 题目用例
+ */
+@Data
+public class JudgeCase {
+
+        /**
+        * 输入用例
+        */
+        private String input;
+
+        /**
+        * 输出用例
+        */
+        private String output;
+}

+ 25 - 0
src/main/java/com/example/onlinejudge/model/dto/question/JudgeConfig.java

@@ -0,0 +1,25 @@
+package com.example.onlinejudge.model.dto.question;
+
+import lombok.Data;
+
+/**
+ * 题目配置
+ */
+@Data
+public class JudgeConfig {
+
+        /**
+        * 时间限制(ms)
+        */
+        private Long timeLimit;
+
+        /**
+        * 内存限制(KB)
+        */
+        private Long memoryLimit;
+
+        /**
+        * 堆栈限制(KB)
+        */
+        private Long stackLimit;
+}

+ 22 - 0
src/main/java/com/example/onlinejudge/model/dto/questionSubmit/JudgeInfo.java

@@ -0,0 +1,22 @@
+package com.example.onlinejudge.model.dto.questionSubmit;
+
+import lombok.Data;
+
+@Data
+public class JudgeInfo {
+
+        /**
+        * 程序执行信息
+        */
+        private String message;
+
+        /**
+        * 消耗内存
+        */
+        private Long memory;
+
+        /**
+        * 消耗时间(KB)
+        */
+        private Long time;
+}

+ 26 - 0
src/main/java/com/example/onlinejudge/model/dto/questionSubmit/QuestionSubmitAddRequest.java

@@ -0,0 +1,26 @@
+package com.example.onlinejudge.model.dto.questionSubmit;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class QuestionSubmitAddRequest implements Serializable {
+    /**
+     * 编程语言
+     */
+    private String language;
+
+    /**
+     * 用户代码
+     */
+    private String code;
+
+    /**
+     * 题目 id
+     */
+    private Long questionId;
+
+    private static final long serialVersionUID = 1L;
+
+}

+ 27 - 0
src/main/java/com/example/onlinejudge/model/dto/questionSubmit/QuestionSubmitQueryRequest.java

@@ -0,0 +1,27 @@
+package com.example.onlinejudge.model.dto.questionSubmit;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class QuestionSubmitQueryRequest implements Serializable {
+
+        /**
+        * 编程语言
+        */
+        private String language;
+
+        /**
+        * 用户代码
+        */
+        private String code;
+
+        /**
+        * 题目 id
+        */
+        private Long questionId;
+
+        private static final long serialVersionUID = 1L;
+
+}

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

@@ -0,0 +1,92 @@
+package com.example.onlinejudge.model.entity;
+
+import lombok.Data;
+import com.baomidou.mybatisplus.annotation.*;
+
+import java.util.Date;
+
+/**
+ * 题目
+ */
+@Data
+public class Question {
+    /**
+     * id
+     */
+    @TableId(type = IdType.ASSIGN_ID)
+    private Long id;
+
+    /**
+     * 标题
+     */
+    private String title;
+
+    /**
+     * 内容
+     */
+    private String content;
+
+    /**
+     * 标签列表(json 数组)
+     */
+    private String tags;
+
+    /**
+     * 题目答案
+     */
+    private String answer;
+
+    /**
+     * 题目提交数
+     */
+    private Integer submitNum;
+
+    /**
+     * 题目通过数
+     */
+    private Integer acceptedNum;
+
+    /**
+     * 判题用例(json 数组)
+     */
+    private String judgeCase;
+
+    /**
+     * 判题配置(json 对象)
+     */
+    private String judgeConfig;
+
+    /**
+     * 点赞数
+     */
+    private Integer thumbNum;
+
+    /**
+     * 收藏数
+     */
+    private Integer favourNum;
+
+    /**
+     * 创建用户 id
+     */
+    private Long userId;
+
+    /**
+     * 创建时间
+     */
+    private Date createTime;
+
+    /**
+     * 更新时间
+     */
+    private Date updateTime;
+
+    /**
+     * 是否删除
+     */
+    @TableLogic
+    private Integer isDelete;
+
+    @TableField(exist = false)
+    private static final long serialVersionUID = 1L;
+}

+ 69 - 0
src/main/java/com/example/onlinejudge/model/entity/QuestionSubmit.java

@@ -0,0 +1,69 @@
+package com.example.onlinejudge.model.entity;
+
+import com.baomidou.mybatisplus.annotation.*;
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * 题目提交
+ */
+@TableName(value ="question_submit")
+@Data
+public class QuestionSubmit {
+    /**
+     * id
+     */
+    @TableId(type = IdType.ASSIGN_ID)
+    private Long id;
+
+    /**
+     * 编程语言
+     */
+    private String language;
+
+    /**
+     * 用户代码
+     */
+    private String code;
+
+    /**
+     * 判题信息(json 对象)
+     */
+    private String judgeInfo;
+
+    /**
+     * 判题状态(0 - 待判题、1 - 判题中、2 - 成功、3 - 失败)
+     */
+    private Integer status;
+
+    /**
+     * 题目 id
+     */
+    private Long questionId;
+
+    /**
+     * 创建用户 id
+     */
+    private Long userId;
+
+    /**
+     * 创建时间
+     */
+    private Date createTime;
+
+    /**
+     * 更新时间
+     */
+    private Date updateTime;
+
+    /**
+     * 是否删除
+     */
+    @TableLogic
+    private Integer isDelete;
+
+    @TableField(exist = false)
+    private static final long serialVersionUID = 1L;
+
+}

+ 62 - 0
src/main/java/com/example/onlinejudge/model/entity/SubmitCode.java

@@ -0,0 +1,62 @@
+package com.example.onlinejudge.model.entity;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@Data
+@ApiModel("提交代码")
+public class SubmitCode {
+    @ApiModelProperty("提交代码id")
+    int id;
+
+    @ApiModelProperty("提交用户id")
+    int userID;
+
+    @ApiModelProperty("提交题目id")
+    int problemID;
+
+    @ApiModelProperty("提交时间")
+    String submitTime;
+
+    @ApiModelProperty("提交结果")
+    String result;
+
+    @ApiModelProperty("运行时间")
+    int runTime;
+
+    @ApiModelProperty("运行内存")
+    int runMemory;
+
+    @ApiModelProperty("提交代码")
+    String sourceCode;
+
+    @ApiModelProperty("语言id")
+    String language;
+
+    @ApiModelProperty("输入")
+    String stdin;
+
+    @ApiModelProperty("输出")
+    String stdout;
+
+    @ApiModelProperty("错误")
+    String stderr;
+
+    @ApiModelProperty("编译信息")
+    String compileInfo;
+
+    @ApiModelProperty("是否公开")
+    boolean isPublic;
+
+    @ApiModelProperty("是否评测")
+    boolean isJudge;
+
+    @ApiModelProperty("是否删除")
+    boolean isDelete;
+
+    @ApiModelProperty("状态")
+    String state;
+
+
+}

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

@@ -1,4 +1,4 @@
-package com.example.onlinejudge.bean;
+package com.example.onlinejudge.model.entity;
 
 import lombok.AllArgsConstructor;
 import lombok.Data;

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

@@ -0,0 +1,75 @@
+package com.example.onlinejudge.model.entity.result;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class Result<T> implements Serializable {
+    private Integer code;
+    private String message;
+    private T data;
+    public Result() {
+
+    }
+    public Result(int code, String message) {
+        this.code = code;
+        this.message = message;
+    }
+    public Result(int code, String message,T data) {
+        this.code = code;
+        this.message = message;
+        this.data = data;
+    }
+
+    private void setResultCode(ResultCode resultCode) {
+        this.code = resultCode.getCode();
+        this.message = resultCode.getMessage();
+    }
+
+    /**
+     * 成功
+     */
+    public static <T> Result<T> success() {
+        Result<T> result = new Result<T>();
+        result.setCode(ResultCode.SUCCESS.getCode());
+        result.setMessage(ResultCode.SUCCESS.getMessage());
+        return result;
+    }
+
+    /**
+     * 成功
+     */
+    public static <T> Result<T> success(T data) {
+        Result<T> result = new Result<T>();
+        result.setCode(ResultCode.SUCCESS.getCode());
+        result.setMessage(ResultCode.SUCCESS.getMessage());
+        result.setData(data);
+        return result;
+    }
+
+    /**
+     * 失败
+     */
+    public static <T> Result<T> error(int code, String message) {
+        return new Result(code, message);
+    }
+
+    /**
+     * 失败
+     */
+    public static <T> Result<T> error(ResultCode resultCode) {
+        return new Result(resultCode.getCode(), resultCode.getMessage());
+    }
+
+    /**
+     * 判断数据库操作
+     */
+    public static <T> Result<T> dbResult(int result) {
+        if (result > 0) {
+            return Result.success(null);
+        } else {
+            return Result.error(ResultCode.DATABASE_ERROR);
+        }
+    }
+}

+ 41 - 0
src/main/java/com/example/onlinejudge/model/entity/result/ResultCode.java

@@ -0,0 +1,41 @@
+package com.example.onlinejudge.model.entity.result;
+
+public enum ResultCode {
+    /* 成功状态码 */
+    SUCCESS(1, "成功"),
+
+    /* 参数错误 */
+    PARAM_IS_INVALID(1001, "参数无效"),
+    PARAM_IS_BLANK(1002, "参数为空"),
+    PARAM_TYPE_BIND_ERROR(1003, "参数类型错误"),
+    PARAM_NOT_COMPLETE(1004, "参数缺失"),
+
+    /* 用户错误 2001-2999*/
+    USER_NOTLOGGED_IN(2001, "用户未登录"),
+    USER_LOGIN_ERROR(2002, "账号不存在或密码错误"),
+    USER_HAS_EXISTED(2003, "用户已存在"),
+    USER_NOT_EXIST(2004, "用户不存在"),
+    PERMISSION_DENIED(2005,"用户权限不够"),
+
+    /* 数据库异常 3001-3999*/
+    DATABASE_ERROR(3001, "数据库异常"),
+    DATABASE_DUPLICATE_INSERT(3002,"重复插入"),
+
+    /* 系统错误 10001-19999 */
+    SYSTEM_ERROR(10000, "系统异常,请稍后重试")
+    ;
+    private Integer code;
+    private String message;
+
+    private ResultCode(Integer code, String message) {
+        this.code = code;
+        this.message = message;
+    }
+
+    public Integer getCode() {
+        return this.code;
+    }
+    public String getMessage() {
+        return this.message;
+    }
+}

+ 68 - 0
src/main/java/com/example/onlinejudge/model/enums/JudgeInfoMessageEnum.java

@@ -0,0 +1,68 @@
+package com.example.onlinejudge.model.enums;
+
+import org.apache.commons.lang3.ObjectUtils;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * 判题信息枚举
+ */
+public enum JudgeInfoMessageEnum {
+    ACCEPTED("成功", "Accepted"),
+    WRONG_ANSWER("答案错误", "Wrong Answer"),
+    COMPILE_ERROR("Compile Error", "编译错误"),
+    MEMORY_LIMIT_EXCEEDED("", "内存溢出"),
+    TIME_LIMIT_EXCEEDED("Time Limit Exceeded", "超时"),
+    PRESENTATION_ERROR("Presentation Error", "展示错误"),
+    WAITING("Waiting", "等待中"),
+    OUTPUT_LIMIT_EXCEEDED("Output Limit Exceeded", "输出溢出"),
+    DANGEROUS_OPERATION("Dangerous Operation", "危险操作"),
+    RUNTIME_ERROR("Runtime Error", "运行错误"),
+    SYSTEM_ERROR("System Error", "系统错误");
+
+    private final String text;
+
+    private final String value;
+
+    JudgeInfoMessageEnum(String text, String value) {
+        this.text = text;
+        this.value = value;
+    }
+
+    /**
+     * 获取值列表
+     *
+     * @return
+     */
+    public static List<String> getValues() {
+        return Arrays.stream(values()).map(item -> item.value).collect(Collectors.toList());
+    }
+
+    /**
+     * 根据 value 获取枚举
+     *
+     * @param value
+     * @return
+     */
+    public static JudgeInfoMessageEnum getEnumByValue(String value) {
+        if (ObjectUtils.isEmpty(value)) {
+            return null;
+        }
+        for (JudgeInfoMessageEnum anEnum : JudgeInfoMessageEnum.values()) {
+            if (anEnum.value.equals(value)) {
+                return anEnum;
+            }
+        }
+        return null;
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    public String getText() {
+        return text;
+    }
+}

+ 60 - 0
src/main/java/com/example/onlinejudge/model/enums/QuestionSubmitLanguageEnum.java

@@ -0,0 +1,60 @@
+package com.example.onlinejudge.model.enums;
+
+import org.apache.commons.lang3.ObjectUtils;;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public enum QuestionSubmitLanguageEnum {
+
+    JAVA("java","java"),
+    C("c","c"),
+    CPP("cpp","cpp")
+    ;
+
+    private String text;
+    private String value;
+
+    QuestionSubmitLanguageEnum(String language, String languageName) {
+        this.text = language;
+        this.value = languageName;
+    }
+
+    /**
+     * 获取值列表
+     *
+     * @return
+     */
+    public static List<String> getValues() {
+        return Arrays.stream(values()).map(item -> item.value).collect(Collectors.toList());
+    }
+
+    /**
+     * 根据 value 获取枚举
+     *
+     * @param value
+     * @return
+     */
+    public static QuestionSubmitLanguageEnum getEnumByValue(String value) {
+        if (ObjectUtils.isEmpty(value)) {
+            return null;
+        }
+        for (QuestionSubmitLanguageEnum anEnum : QuestionSubmitLanguageEnum.values()) {
+            if (anEnum.value.equals(value)) {
+                return anEnum;
+            }
+        }
+        return null;
+    }
+
+
+
+    public String getText() {
+        return text;
+    }
+
+    public String getValue() {
+        return value;
+    }
+}

+ 59 - 0
src/main/java/com/example/onlinejudge/model/enums/QuestionSubmitStatusEnum.java

@@ -0,0 +1,59 @@
+package com.example.onlinejudge.model.enums;
+
+import org.apache.commons.lang3.ObjectUtils;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public enum QuestionSubmitStatusEnum {
+    // 0 - 待判题、1 - 判题中、2 - 成功、3 - 失败
+    WAITING("等待中", 0),
+    RUNNING("判题中", 1),
+    SUCCEED("成功", 2),
+    FAILED("失败", 3);
+
+    private final String text;
+
+    private final Integer value;
+
+    QuestionSubmitStatusEnum(String text, Integer value) {
+        this.text = text;
+        this.value = value;
+    }
+
+    /**
+     * 获取值列表
+     *
+     * @return
+     */
+    public static List<Integer> getValues() {
+        return Arrays.stream(values()).map(item -> item.value).collect(Collectors.toList());
+    }
+
+    /**
+     * 根据 value 获取枚举
+     *
+     * @param value
+     * @return
+     */
+    public static QuestionSubmitStatusEnum getEnumByValue(Integer value) {
+        if (ObjectUtils.isEmpty(value)) {
+            return null;
+        }
+        for (QuestionSubmitStatusEnum anEnum : QuestionSubmitStatusEnum.values()) {
+            if (anEnum.value.equals(value)) {
+                return anEnum;
+            }
+        }
+        return null;
+    }
+
+    public Integer getValue() {
+        return value;
+    }
+
+    public String getText() {
+        return text;
+    }
+}

+ 58 - 0
src/main/java/com/example/onlinejudge/model/enums/UserRoleEnum.java

@@ -0,0 +1,58 @@
+package com.example.onlinejudge.model.enums;
+
+import org.apache.commons.lang3.ObjectUtils;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public enum UserRoleEnum {
+
+    USER("用户", "user"),
+    ADMIN("管理员", "admin"),
+    BAN("被封号", "ban");
+
+    private final String text;
+
+    private final String value;
+
+    UserRoleEnum(String text, String value) {
+        this.text = text;
+        this.value = value;
+    }
+
+    /**
+     * 获取值列表
+     *
+     * @return
+     */
+    public static List<String> getValues() {
+        return Arrays.stream(values()).map(item -> item.value).collect(Collectors.toList());
+    }
+
+    /**
+     * 根据 value 获取枚举
+     *
+     * @param value
+     * @return
+     */
+    public static UserRoleEnum getEnumByValue(String value) {
+        if (ObjectUtils.isEmpty(value)) {
+            return null;
+        }
+        for (UserRoleEnum anEnum : UserRoleEnum.values()) {
+            if (anEnum.value.equals(value)) {
+                return anEnum;
+            }
+        }
+        return null;
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    public String getText() {
+        return text;
+    }
+}

+ 4 - 0
src/main/java/com/example/onlinejudge/service/QuestionService.java

@@ -0,0 +1,4 @@
+package com.example.onlinejudge.service;
+
+public interface QuestionService {
+}

+ 4 - 0
src/main/java/com/example/onlinejudge/service/impl/QuestionServiceImpl.java

@@ -0,0 +1,4 @@
+package com.example.onlinejudge.service.impl;
+
+public class QuestionServiceImpl {
+}

+ 1 - 3
src/main/java/com/example/onlinejudge/service/impl/UserServiceImpl.java

@@ -2,13 +2,11 @@ package com.example.onlinejudge.service.impl;
 
 import cn.dev33.satoken.stp.StpUtil;
 import cn.dev33.satoken.util.SaResult;
-import com.example.onlinejudge.bean.User;
+import com.example.onlinejudge.model.entity.User;
 import com.example.onlinejudge.mapper.UserMapper;
 import com.example.onlinejudge.service.UserService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.ResponseBody;
 
 /**
  * 实现用户服务

+ 7 - 0
src/main/resources/application.yml

@@ -1,3 +1,6 @@
+server:
+  port: 8089
+
 spring:
   datasource:
     type: com.alibaba.druid.pool.DruidDataSource
@@ -31,3 +34,7 @@ sa-token:
   token-style: uuid
   # 是否输出操作日志
   is-log: true
+
+knife4j:
+  enable: true
+

+ 2 - 2
src/main/resources/mapper/userMapper.xml

@@ -3,10 +3,10 @@
         PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.example.onlinejudge.mapper.UserMapper">
-    <select id="selectUserById" resultType="com.example.onlinejudge.bean.User">
+    <select id="selectUserById" resultType="com.example.onlinejudge.model.entity.User">
         SELECT * FROM t_user WHERE id = #{id}
     </select>
-    <select id="selectUserByUsernameAndPassword" resultType="com.example.onlinejudge.bean.User">
+    <select id="selectUserByUsernameAndPassword" resultType="com.example.onlinejudge.model.entity.User">
         SELECT * FROM t_user WHERE username = #{param1} and password = #{param2}
     </select>
 </mapper>