OJ判题测评系统--项目基础环境搭建

发布时间 2023-12-30 12:41:59作者: Cyrui_13

写在前面

在线访问:暂无..
GitHub:https://github.com/975131701/ojSystem/
个人博客:https://www.cnblogs.com/cyrui/
使用说明
1、启动nacos -> startup.cmd -m standalone
2、启动rabbitmq -> rabbitmq-plugins enable rabbitmq_management
3、启动redis -> redis-server
4、启动mysql服务
5、启动前端服务 -> npm run serve
6、启动所有后端服务

项目介绍(业务)

OJ = Online Judge 在线判题评测系统
管理员可以创建,修改,删除题目;用户可以选择题目,在线做题并且提交代码;系统会对用户提交的代码,根据预设答案判断用户的提交结果是否正确。
核心模块:代码沙箱模块,题目模块,判题模块等。

项目介绍(技术)

后端技术:Spring Boot、Spring Cloud、Mybatis Plus、MySQL、Redis、RabbitMq、Docker、Java安全管理器和Spring Cloud Alibaba相关微服务组件。

核心业务流程

image
image

后期考虑把判题服务和代码沙箱通过消息队列解耦

功能

  1. 题目模块
    1. 创建题目(管理员)
    2. 修改题目(管理员)
    3. 删除题目(管理员)
    4. 搜索题目(用户)
    5. 搜索提交题目(用户)
    6. 在线做题
    7. 提交题目代码
  2. 用户模块
    1. 登录
    2. 注销
    3. 注册
  3. 判题模块
    1. 提交判题
    2. 限制处理
    3. 代码沙箱

库表设计

用户表

主要是id、账号和密码以及用户角色

-- 用户表
create table if not exists user
(
    id           bigint auto_increment comment 'id' primary key,
    userAccount  varchar(256)                           not null comment '账号',
    userPassword varchar(512)                           not null comment '密码',
    unionId      varchar(256)                           null comment '微信开放平台id',
    mpOpenId     varchar(256)                           null comment '公众号openId',
    userName     varchar(256)                           null comment '用户昵称',
    userAvatar   varchar(1024)                          null comment '用户头像',
    userProfile  varchar(512)                           null comment '用户简介',
    userRole     varchar(256) default 'user'            not null comment '用户角色:user/admin/ban',
    createTime   datetime     default CURRENT_TIMESTAMP not null comment '创建时间',
    updateTime   datetime     default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
    isDelete     tinyint      default 0                 not null comment '是否删除',
    index idx_unionId (unionId)
    ) comment '用户' collate = utf8mb4_unicode_ci;

题目表

题目标题
题目内容:题目介绍、输入输出提示、描述、具体详情
题目标签(json 数组):简单、中等、困难、字符串、二叉树
题目答案:管理员设置的标准答案
提交数、通过题目的用户数:便于分析统计(可以考虑根据通过率给题目打难易度标签)
判题用例(json 数组):多组 输入用例和输出用例
判题配置(json 对象):时间限制和内存限制

-- 题目表
create table if not exists question
(
    id         bigint auto_increment comment 'id' primary key,
    title      varchar(512)                       null comment '标题',
    content    text                               null comment '内容',
    tags       varchar(1024)                      null comment '标签列表(json 数组)',
    answer     text                               null comment '题目答案',
    submitNum  int  default 0 not null comment '题目提交数',
    acceptedNum  int  default 0 not null comment '题目通过数',
    judgeCase text null comment '判题用例(json 数组)',
    judgeConfig text null comment '判题配置(json 对象)',
    thumbNum   int      default 0                 not null comment '点赞数',
    favourNum  int      default 0                 not null comment '收藏数',
    userId     bigint                             not null comment '创建用户 id',
    createTime datetime default CURRENT_TIMESTAMP not null comment '创建时间',
    updateTime datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
    isDelete   tinyint  default 0                 not null comment '是否删除',
    index idx_userId (userId)
    ) comment '题目' collate = utf8mb4_unicode_ci;

题目提交表

提交的编程语言类型
提交的代码
提交的题目 id
提交的用户 id
判题的状态(0 - 带判题、1 - 判题中、2 - 成功、 3 - 失败)
判题信息(判题过程中的信息,比如程序的失败原因,执行消耗的时间、空间)
判题信息枚举值

  • Accepted 成功
  • Wrong Answer 答案错误
  • Compile Error 编译错误
  • Memory Limit Exceeded 内存溢出
  • Time Limit Exceeded 超时
  • Presentation Error 展示错误
  • Output Limit Exceeded 输出溢出
  • Waiting 等待中
  • Dangerous Operation 危险操作
  • Runtime Error 运行错误(用户程序的问题)
  • System Error 系统错误(做系统人的问题)
-- 题目提交表
create table if not exists question_submit
(
    id         bigint auto_increment comment 'id' primary key,
    language   varchar(128)                       not null comment '编程语言',
    code       text                               not null comment '用户代码',
    judgeInfo  text                               null comment '判题信息(json 对象)',
    status     int      default 0                 not null comment '判题状态(0 - 待判题、1 - 判题中、2 - 成功、3 - 失败)',
    questionId bigint                             not null comment '题目 id',
    userId     bigint                             not null comment '创建用户 id',
    createTime datetime default CURRENT_TIMESTAMP not null comment '创建时间',
    updateTime datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间',
    isDelete   tinyint  default 0                 not null comment '是否删除',
    index idx_questionId (questionId),
    index idx_userId (userId)
    ) comment '题目提交';

后端项目初始化

创建一个Spring Cloud项目结构如下
image

application.yml配置如下

# 公共配置文件
# @author cyr
# 
spring:
  application:
    name: cyroj-user-service
  profiles:
    active: dev
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/cyroj
    username: root
    password: 123456
  cloud:
    nacos:
      discovery:
        server-addr: 127.0.0.1:8848
server:
  address: 0.0.0.0
  port: 8102
  servlet:
    context-path: /api/user
mybatis-plus:
  configuration:
    map-underscore-to-camel-case: false
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

写一个Controller接口尝试运行项目

@RestController
@RequestMapping("/")
@Slf4j
public class UserController {

    @GetMapping("/test")
    public String test() {
        return "hello world";
    }
}

成功运行项目!
image

上传项目到GitHub:https://blog.csdn.net/Saintmm/article/details/122213995