parent
2863e90f07
commit
756dea6abf
|
@ -0,0 +1,14 @@
|
|||
## 角色
|
||||
管理员<br>
|
||||
用户<br>
|
||||
教师<br>
|
||||
只要有多角色 就要设计 <br>
|
||||
RBAC——基于角色权限的模型
|
||||
|
||||
角色表 用户表 用户角色表 权限表 角色权限表 <br>
|
||||
|
||||
要做全控制
|
||||
表单 按钮 视图
|
||||
|
||||
|
||||
|
|
@ -10,7 +10,6 @@ public class Result<T> {
|
|||
private Integer code;
|
||||
private String message;
|
||||
private T data;
|
||||
private Long nums;
|
||||
private String time;
|
||||
|
||||
public Result() {
|
||||
|
|
|
@ -0,0 +1,98 @@
|
|||
package com.guwan.backend.common;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class SearchResult<T> {
|
||||
private Integer code;
|
||||
private String message;
|
||||
private T data;
|
||||
private Long total;
|
||||
private String time;
|
||||
|
||||
public SearchResult() {
|
||||
this.time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
|
||||
}
|
||||
|
||||
public static <T> SearchResult<T> success() {
|
||||
SearchResult<T> result = new SearchResult<>();
|
||||
result.setCode(200);
|
||||
result.setMessage("操作成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
public static <T> SearchResult<T> success(T data) {
|
||||
SearchResult<T> result = new SearchResult<>();
|
||||
result.setCode(200);
|
||||
result.setMessage("操作成功");
|
||||
result.setData(data);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static <T> SearchResult<T> success(T data, Long total) {
|
||||
SearchResult<T> result = new SearchResult<>();
|
||||
result.setCode(200);
|
||||
result.setMessage("操作成功");
|
||||
result.setData(data);
|
||||
result.setTotal(total);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static <T> SearchResult<T> success(String message, T data) {
|
||||
SearchResult<T> result = new SearchResult<>();
|
||||
result.setCode(200);
|
||||
result.setMessage(message);
|
||||
result.setData(data);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static <T> SearchResult<T> error(String message) {
|
||||
SearchResult<T> result = new SearchResult<>();
|
||||
result.setCode(500);
|
||||
result.setMessage(message);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static <T> SearchResult<T> error(Integer code, String message) {
|
||||
SearchResult<T> result = new SearchResult<>();
|
||||
result.setCode(code);
|
||||
result.setMessage(message);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static <T> SearchResult<T> error(Integer code, String message, T data) {
|
||||
SearchResult<T> result = new SearchResult<>();
|
||||
result.setCode(code);
|
||||
result.setMessage(message);
|
||||
result.setData(data);
|
||||
return result;
|
||||
}
|
||||
|
||||
// 常用状态码
|
||||
public static final int SUCCESS = 200;
|
||||
public static final int ERROR = 500;
|
||||
public static final int UNAUTHORIZED = 401;
|
||||
public static final int FORBIDDEN = 403;
|
||||
public static final int NOT_FOUND = 404;
|
||||
public static final int VALIDATE_FAILED = 400;
|
||||
|
||||
// 业务状态码
|
||||
public static <T> SearchResult<T> validateFailed(String message) {
|
||||
return error(VALIDATE_FAILED, message);
|
||||
}
|
||||
|
||||
public static <T> SearchResult<T> unauthorized(String message) {
|
||||
return error(UNAUTHORIZED, message);
|
||||
}
|
||||
|
||||
public static <T> SearchResult<T> forbidden(String message) {
|
||||
return error(FORBIDDEN, message);
|
||||
}
|
||||
|
||||
public static <T> SearchResult<T> notFound(String message) {
|
||||
return error(NOT_FOUND, message);
|
||||
}
|
||||
}
|
|
@ -12,7 +12,8 @@ public class CacheConstants {
|
|||
* 缓存内容
|
||||
*/
|
||||
public static final List<String> CACHE_LIST = List.of(
|
||||
"userCache"
|
||||
"userCache",
|
||||
"paperCache"
|
||||
);
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,114 @@
|
|||
package com.guwan.backend.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.guwan.backend.annotation.OperationLog;
|
||||
import com.guwan.backend.common.Result;
|
||||
import com.guwan.backend.common.SearchResult;
|
||||
import com.guwan.backend.pojo.entity.Papers;
|
||||
import com.guwan.backend.service.PapersService;
|
||||
import com.guwan.backend.util.UUIDUtil;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 试卷控制层
|
||||
*
|
||||
* @author Guwan
|
||||
* @since 2025-01-11 12:06:49
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/common/papers")
|
||||
@RequiredArgsConstructor
|
||||
public class PapersController {
|
||||
/**
|
||||
* 服务对象
|
||||
*/
|
||||
|
||||
private final PapersService papersService;
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param papers 筛选条件
|
||||
* @param pageRequest 分页对象
|
||||
* @return 查询结果
|
||||
*/
|
||||
@GetMapping
|
||||
public SearchResult<List<Papers>> queryByPage(@RequestParam(defaultValue = "1") int page,
|
||||
@RequestParam(defaultValue = "1") int size) {
|
||||
|
||||
|
||||
|
||||
Page<Papers> papersPage = new Page<>(page, size);
|
||||
|
||||
// 使用分页查询,注意 lambdaQuery().page() 方法
|
||||
IPage<Papers> resultPage = papersService.lambdaQuery()
|
||||
.page(papersPage);
|
||||
|
||||
|
||||
|
||||
return SearchResult.success(resultPage.getRecords(), resultPage.getTotal());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过主键查询单条数据
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 单条数据
|
||||
*/
|
||||
@GetMapping("{id}")
|
||||
@Operation(summary = "获取单张试卷信息")
|
||||
@OperationLog(description = "获取单张试卷信息")
|
||||
public Result<Papers> queryById(@PathVariable("id") Integer id) {
|
||||
return Result.success(this.papersService.getById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增数据
|
||||
*
|
||||
* @param papers 实体
|
||||
* @return 新增结果
|
||||
*/
|
||||
@PostMapping
|
||||
@Operation(summary = "创建试卷")
|
||||
@OperationLog(description = "创建试卷")
|
||||
public Result<Papers> add(@RequestBody Papers papers) {
|
||||
|
||||
|
||||
papers.setPaperUuid(UUIDUtil.uuid());
|
||||
|
||||
papersService.save(papers);
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑数据
|
||||
*
|
||||
* @param papers 实体
|
||||
* @return 编辑结果
|
||||
*/
|
||||
@PutMapping
|
||||
public Result<Papers> edit(Papers papers) {
|
||||
//return Result.success(this.papersService.update(papers));
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 删除是否成功
|
||||
*/
|
||||
@DeleteMapping
|
||||
public Result<Boolean> deleteById(Integer id) {
|
||||
return Result.success(this.papersService.removeById(id));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
package generator.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
*
|
||||
* @TableName papers
|
||||
*/
|
||||
@TableName(value ="papers")
|
||||
@Data
|
||||
public class Papers implements Serializable {
|
||||
/**
|
||||
* 试卷编号
|
||||
*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Integer paperId;
|
||||
|
||||
/**
|
||||
* 试卷名称
|
||||
*/
|
||||
private String paperName;
|
||||
|
||||
/**
|
||||
* 试卷描述
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 命题人
|
||||
*/
|
||||
private String paperSetter;
|
||||
|
||||
/**
|
||||
* 校对人
|
||||
*/
|
||||
private String paperReviewer;
|
||||
|
||||
/**
|
||||
* 开始时间
|
||||
*/
|
||||
private Date startTime;
|
||||
|
||||
/**
|
||||
* 结束时间
|
||||
*/
|
||||
private Date endTime;
|
||||
|
||||
/**
|
||||
* 考试时间
|
||||
*/
|
||||
private Integer duration;
|
||||
|
||||
/**
|
||||
* 试卷状态
|
||||
*/
|
||||
private Object status;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createdTime;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
private Date updatedTime;
|
||||
|
||||
@TableField(exist = false)
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package generator.mapper;
|
||||
|
||||
import generator.domain.Papers;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* @author 12455
|
||||
* @description 针对表【papers】的数据库操作Mapper
|
||||
* @createDate 2025-01-11 12:09:52
|
||||
* @Entity generator.domain.Papers
|
||||
*/
|
||||
public interface PapersMapper extends BaseMapper<Papers> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package generator.service;
|
||||
|
||||
import generator.domain.Papers;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* @author 12455
|
||||
* @description 针对表【papers】的数据库操作Service
|
||||
* @createDate 2025-01-11 12:09:52
|
||||
*/
|
||||
public interface PapersService extends IService<Papers> {
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package generator.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import generator.domain.Papers;
|
||||
import generator.service.PapersService;
|
||||
import generator.mapper.PapersMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author 12455
|
||||
* @description 针对表【papers】的数据库操作Service实现
|
||||
* @createDate 2025-01-11 12:09:52
|
||||
*/
|
||||
@Service
|
||||
public class PapersServiceImpl extends ServiceImpl<PapersMapper, Papers>
|
||||
implements PapersService{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package com.guwan.backend.mapper;
|
||||
|
||||
import com.guwan.backend.pojo.entity.Papers;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* @author 12455
|
||||
* @description 针对表【papers】的数据库操作Mapper
|
||||
* @createDate 2025-01-11 12:00:45
|
||||
* @Entity com.guwan.backend.pojo.entity.Papers
|
||||
*/
|
||||
public interface PapersMapper extends BaseMapper<Papers> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,100 @@
|
|||
package com.guwan.backend.pojo.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
/**
|
||||
*
|
||||
* @TableName papers
|
||||
*/
|
||||
@TableName(value ="papers")
|
||||
@Data
|
||||
public class Papers implements Serializable {
|
||||
/**
|
||||
* 试卷编号
|
||||
*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Integer paperId;
|
||||
|
||||
/**
|
||||
* 试卷uuid
|
||||
*/
|
||||
private String paperUuid;
|
||||
|
||||
/**
|
||||
* 试卷名称
|
||||
*/
|
||||
private String paperName;
|
||||
|
||||
/**
|
||||
* 试卷描述
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 试卷满分
|
||||
*/
|
||||
private int maxScore;
|
||||
|
||||
/**
|
||||
* 命题人
|
||||
*/
|
||||
private String paperSetter;
|
||||
|
||||
/**
|
||||
* 校对人
|
||||
*/
|
||||
private String paperReviewer;
|
||||
|
||||
|
||||
/**
|
||||
* 试卷状态
|
||||
*/
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 考试时间
|
||||
*/
|
||||
private Integer duration;
|
||||
|
||||
|
||||
/**
|
||||
* 开始时间
|
||||
*/
|
||||
@DateTimeFormat //此注解用来接收字符串类型的参数封装成LocalDateTime类型
|
||||
@JsonFormat //此注解将date类型数据转成字符串响应出去
|
||||
private LocalDateTime startTime;
|
||||
|
||||
/**
|
||||
* 结束时间
|
||||
*/
|
||||
@DateTimeFormat //此注解用来接收字符串类型的参数封装成LocalDateTime类型
|
||||
@JsonFormat //此注解将date类型数据转成字符串响应出去
|
||||
private LocalDateTime endTime;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@DateTimeFormat //此注解用来接收字符串类型的参数封装成LocalDateTime类型
|
||||
@JsonFormat //此注解将date类型数据转成字符串响应出去
|
||||
private LocalDateTime createdTime;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
@DateTimeFormat //此注解用来接收字符串类型的参数封装成LocalDateTime类型
|
||||
@JsonFormat //此注解将date类型数据转成字符串响应出去
|
||||
private LocalDateTime updatedTime;
|
||||
|
||||
@TableField(exist = false)
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.guwan.backend.service;
|
||||
|
||||
import com.guwan.backend.pojo.entity.Papers;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author 12455
|
||||
* @description 针对表【papers】的数据库操作Service
|
||||
* @createDate 2025-01-11 12:00:45
|
||||
*/
|
||||
public interface PapersService extends IService<Papers> {
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package com.guwan.backend.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.guwan.backend.pojo.dto.user.UserDTO;
|
||||
import com.guwan.backend.pojo.entity.Papers;
|
||||
import com.guwan.backend.service.PapersService;
|
||||
import com.guwan.backend.mapper.PapersMapper;
|
||||
import com.guwan.backend.util.RedisUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author 12455
|
||||
* @description 针对表【papers】的数据库操作Service实现
|
||||
* @createDate 2025-01-11 12:00:45
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class PapersServiceImpl extends ServiceImpl<PapersMapper, Papers>
|
||||
implements PapersService{
|
||||
|
||||
|
||||
|
||||
private static final String PAPER_CACHE_KEY = "paper:";
|
||||
|
||||
private final RedisUtils redisUtil;
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "paperCache", key = "#id")
|
||||
public Papers getById(Serializable id) {
|
||||
|
||||
System.out.println("id = " + id);
|
||||
|
||||
|
||||
Object cache = redisUtil.get(PAPER_CACHE_KEY + id);
|
||||
|
||||
|
||||
|
||||
|
||||
log.debug("开始查询数据库");
|
||||
|
||||
Papers paper = super.getById(id);
|
||||
|
||||
if (paper == null) {
|
||||
log.warn("试卷信息不存在");
|
||||
return null;
|
||||
}
|
||||
|
||||
redisUtil.set(PAPER_CACHE_KEY + id, paper);
|
||||
|
||||
return paper;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -34,6 +34,7 @@ public class SimpleXxlJob {
|
|||
System.out.println("执行定时任务,执行时间:"+sdf.format(new Date()));
|
||||
|
||||
for (String cache : CacheConstants.CACHE_LIST) {
|
||||
System.out.println("cache = " + cache);
|
||||
Map<String, Object> stats = getStats(cache);
|
||||
for (Map.Entry<String, Object> entry : stats.entrySet()) {
|
||||
System.out.println("Key: " + entry.getKey() + ", Value: " + entry.getValue());
|
||||
|
|
|
@ -212,7 +212,7 @@ logging:
|
|||
xxl:
|
||||
job:
|
||||
admin:
|
||||
addresses: http://192.168.1.127:9001/xxl-job-admin
|
||||
addresses: http://192.168.0.6:9001/xxl-job-admin
|
||||
accessToken: GuwanTest
|
||||
executor:
|
||||
appname: xxl-job-executor-guwan
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="generator.mapper.PapersMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="generator.domain.Papers">
|
||||
<id property="paperId" column="paper_id" jdbcType="INTEGER"/>
|
||||
<result property="paperName" column="paper_name" jdbcType="VARCHAR"/>
|
||||
<result property="description" column="description" jdbcType="VARCHAR"/>
|
||||
<result property="paperSetter" column="paper_setter" jdbcType="VARCHAR"/>
|
||||
<result property="paperReviewer" column="paper_reviewer" jdbcType="VARCHAR"/>
|
||||
<result property="startTime" column="start_time" jdbcType="TIMESTAMP"/>
|
||||
<result property="endTime" column="end_time" jdbcType="TIMESTAMP"/>
|
||||
<result property="duration" column="duration" jdbcType="INTEGER"/>
|
||||
<result property="status" column="status" jdbcType="OTHER"/>
|
||||
<result property="createdTime" column="created_time" jdbcType="TIMESTAMP"/>
|
||||
<result property="updatedTime" column="updated_time" jdbcType="TIMESTAMP"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
paper_id,paper_name,description,
|
||||
paper_setter,paper_reviewer,start_time,
|
||||
end_time,duration,status,
|
||||
created_time,updated_time
|
||||
</sql>
|
||||
</mapper>
|
Loading…
Reference in New Issue