mirror of
https://github.com/suyiiyii/SIMS.git
synced 2025-05-31 11:46:42 +08:00
commit
5b9e835108
3
.github/workflows/maven.yml
vendored
3
.github/workflows/maven.yml
vendored
@ -21,15 +21,18 @@ jobs:
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- run: rm -rf test.db
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
java-version: '17'
|
||||
distribution: 'temurin'
|
||||
cache: maven
|
||||
- run: mvn -B test --file pom.xml
|
||||
- name: Build with Maven
|
||||
run: mvn -B package -DskipTests --file pom.xml
|
||||
|
||||
|
||||
# Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive
|
||||
# - name: Update dependency graph
|
||||
# uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6
|
||||
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -31,4 +31,5 @@ build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
/src/main/resources/application.yaml
|
||||
/test.db
|
||||
/src/main/resources/application-prod.yaml
|
||||
|
19
.pre-commit-config.yaml
Normal file
19
.pre-commit-config.yaml
Normal file
@ -0,0 +1,19 @@
|
||||
repos:
|
||||
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v2.3.0
|
||||
hooks:
|
||||
- id: check-yaml
|
||||
- id: end-of-file-fixer
|
||||
- id: trailing-whitespace
|
||||
- id: check-case-conflict
|
||||
- id: check-merge-conflict
|
||||
- id: check-executables-have-shebangs
|
||||
args:
|
||||
- --autofix
|
||||
- repo: https://github.com/gherynos/pre-commit-java
|
||||
rev: v0.5.4
|
||||
hooks:
|
||||
- id: pmd
|
||||
- id: cpd
|
||||
- id: checkstyle
|
14
pom.xml
14
pom.xml
@ -45,6 +45,15 @@
|
||||
<artifactId>mybatis-plus-ext-spring-boot3-starter</artifactId>
|
||||
<version>3.5.7-EXT691</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.session</groupId>
|
||||
<artifactId>spring-session-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.modelmapper</groupId>
|
||||
<artifactId>modelmapper</artifactId>
|
||||
<version>2.3.9</version> <!-- 请确认最新版本 -->
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
@ -91,6 +100,11 @@
|
||||
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
||||
<version>2.3.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.xerial</groupId>
|
||||
<artifactId>sqlite-jdbc</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -1,11 +1,13 @@
|
||||
package top.suyiiyii.sims;
|
||||
|
||||
import com.tangzc.autotable.springboot.EnableAutoTable;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@EnableAutoTable
|
||||
@SpringBootApplication
|
||||
@MapperScan("top.suyiiyii.sims.mapper")
|
||||
public class SimsApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SimsApplication.class, args);
|
||||
|
@ -1,24 +0,0 @@
|
||||
package top.suyiiyii.sims.VO;
|
||||
|
||||
import lombok.Data;
|
||||
import top.suyiiyii.sims.entity.Role;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author tortoise
|
||||
* @Date 2024/8/15 16:04
|
||||
* @PackageName:top.suyiiyii.sims.VO
|
||||
* @ClassName: UserVO
|
||||
* @Description: TODO
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Data
|
||||
public class UserVO {
|
||||
private Integer userId;
|
||||
private String username;
|
||||
private String grade;
|
||||
private String group;
|
||||
private List<String> roles; // 角色名称列表
|
||||
|
||||
}
|
@ -1,9 +1,16 @@
|
||||
package top.suyiiyii.sims.common;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
|
||||
import top.suyiiyii.sims.service.RoleService;
|
||||
import top.suyiiyii.sims.service.UserService;
|
||||
import top.suyiiyii.sims.utils.JwtUtils;
|
||||
|
||||
/**
|
||||
* @Author tortoise
|
||||
@ -15,14 +22,23 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupp
|
||||
*/
|
||||
@Configuration
|
||||
public class InterceptorConfig extends WebMvcConfigurationSupport {
|
||||
@Autowired
|
||||
private RoleService roleService;
|
||||
|
||||
|
||||
|
||||
//UserService userService;
|
||||
@Override
|
||||
protected void addInterceptors(InterceptorRegistry registry) {
|
||||
// registry.addInterceptor(jwtInterceptor())
|
||||
// .addPathPatterns("/**")
|
||||
// .excludePathPatterns("/user/login") // 排除不需要验证的路径
|
||||
// .excludePathPatterns("/user/register")
|
||||
// .excludePathPatterns("/v3/api-docs/**");
|
||||
registry.addInterceptor(jwtInterceptor())
|
||||
.addPathPatterns("/**")
|
||||
.excludePathPatterns("/user/login") // 排除不需要验证的路径
|
||||
.excludePathPatterns("/user/register")
|
||||
.excludePathPatterns("/v3/api-docs/**");
|
||||
|
||||
// 注册AdminInterceptor,只拦截以admin/开头的路径
|
||||
registry.addInterceptor(new AdminInterceptor())
|
||||
.addPathPatterns("/admin/**");
|
||||
super.addInterceptors(registry);
|
||||
}
|
||||
|
||||
@ -31,5 +47,36 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupp
|
||||
return new JwtInterceptor();
|
||||
}
|
||||
|
||||
// AdminInterceptor的实现
|
||||
public class AdminInterceptor implements HandlerInterceptor {
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
|
||||
String path = request.getRequestURI();
|
||||
if (path.startsWith("/admin/") && !hasAdminPermission(request)) {
|
||||
// 如果用户没有管理员权限,返回403 Forbidden
|
||||
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean hasAdminPermission(HttpServletRequest request) {
|
||||
// 这里应该实现检查用户权限的逻辑
|
||||
// 例如,从session、token或者数据库中获取用户信息并判断权限
|
||||
// 以下仅为示例
|
||||
String token = (String) request.getAttribute("token");
|
||||
//非空
|
||||
if (token == null) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
Integer userId = Integer.valueOf(JwtUtils.extractUserId(token));
|
||||
return roleService.isRoleNameAdmin(userId);
|
||||
} catch (Exception e) {
|
||||
// 处理令牌解析过程中可能出现的异常
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,10 +42,6 @@ public class JwtInterceptor implements HandlerInterceptor {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// request.setAttribute();
|
||||
// request.getAttribute()
|
||||
|
||||
// 执行认证
|
||||
if (StrUtil.isBlank(token)) {
|
||||
//权限错误
|
||||
@ -65,6 +61,8 @@ public class JwtInterceptor implements HandlerInterceptor {
|
||||
if (!JwtUtils.verifyToken(token, user.getPassword())) {
|
||||
throw new ServiceException("401", "请登录");
|
||||
}
|
||||
// 验证token后,如果一切正常,将token存储到request的属性中
|
||||
request.setAttribute("token", token);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,44 @@
|
||||
package top.suyiiyii.sims.common;
|
||||
|
||||
import org.modelmapper.ModelMapper;
|
||||
import org.modelmapper.convention.MatchingStrategies;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import top.suyiiyii.sims.dto.RecordDto;
|
||||
import top.suyiiyii.sims.entity.User;
|
||||
|
||||
/**
|
||||
* @Author tortoise
|
||||
* @Date 2024/8/20 21:19
|
||||
* @PackageName:top.suyiiyii.sims.common
|
||||
* @ClassName: ModelMapperConfig
|
||||
* @Description: TODO
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Configuration
|
||||
public class ModelMapperConfig {
|
||||
@Bean
|
||||
public ModelMapper modelMapper() {
|
||||
ModelMapper modelMapper = new ModelMapper();
|
||||
// 设置完全匹配
|
||||
modelMapper.getConfiguration().setFullTypeMatchingRequired(true);
|
||||
|
||||
// 设置匹配策略为严格模式
|
||||
modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
|
||||
// configureUser(modelMapper);
|
||||
return modelMapper;
|
||||
}
|
||||
// 配置 User 类的映射规则
|
||||
private void configureUser(ModelMapper modelMapper) {
|
||||
// 定义 UserModel -> User 的映射规则
|
||||
// modelMapper.typeMap(RecordDto.class, Record.class)
|
||||
|
||||
// 跳过设置密码字段
|
||||
// 定义 User -> UserModel 的映射规则
|
||||
// modelMapper.typeMap(User.class, RecordDto.class)
|
||||
// .addMappings(mapper -> mapper.skip(RecordDto::setPassword)) // 跳过设置密码字段
|
||||
// .addMappings(mapper -> mapper.map(User::getRealName, UserModel::setName)); // 将 User 的 realName 映射为 UserModel 的 name
|
||||
// .addMappings(mapper -> mapper.using(dateToStringConverter).map(User::getCreateTime, UserModel::setCreateTime))
|
||||
// .addMappings(mapper -> mapper.using(dateToStringConverter).map(User::getUpdateTime, UserModel::setUpdateTime));
|
||||
}
|
||||
}
|
@ -1,45 +1,117 @@
|
||||
package top.suyiiyii.sims.controller;
|
||||
|
||||
import com.auth0.jwt.JWT;
|
||||
import com.auth0.jwt.exceptions.JWTDecodeException;
|
||||
import com.auth0.jwt.interfaces.DecodedJWT;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.modelmapper.ModelMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import top.suyiiyii.sims.common.Result;
|
||||
import top.suyiiyii.sims.dto.CommonResponse;
|
||||
import top.suyiiyii.sims.dto.RecordDto;
|
||||
import top.suyiiyii.sims.entity.Record;
|
||||
import top.suyiiyii.sims.entity.Role;
|
||||
import top.suyiiyii.sims.entity.User;
|
||||
import top.suyiiyii.sims.entity.UserRole;
|
||||
import top.suyiiyii.sims.mapper.CategoryMapper;
|
||||
import top.suyiiyii.sims.mapper.UserMapper;
|
||||
import top.suyiiyii.sims.service.CategoryService;
|
||||
import top.suyiiyii.sims.service.RecordService;
|
||||
import top.suyiiyii.sims.service.RoleService;
|
||||
import top.suyiiyii.sims.service.UserService;
|
||||
import top.suyiiyii.sims.utils.JwtUtils;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
public class RecordController {
|
||||
|
||||
public class
|
||||
RecordController {
|
||||
@Autowired
|
||||
RecordService recordService;
|
||||
@Autowired
|
||||
UserService UserService;
|
||||
@Autowired
|
||||
RoleService roleService;
|
||||
@Autowired
|
||||
CategoryService categoryService;
|
||||
@Autowired
|
||||
ModelMapper modelMapper;
|
||||
|
||||
@Operation(summary = "获取所有奖惩记录")
|
||||
@GetMapping("/admin/record")
|
||||
public Result<List<RecordDto>> adminRecord(Integer page, Integer size) {
|
||||
return Result.success(new ArrayList<>());
|
||||
public Result<List<RecordDto>> adminRecord(
|
||||
@RequestParam(defaultValue = "0") int page,
|
||||
@RequestParam(defaultValue = "10") int size) {
|
||||
List<Record> records = recordService.getAllRecords(page, size);
|
||||
List<RecordDto> recordDtos = new ArrayList<>();
|
||||
for (Record record : records) {
|
||||
|
||||
RecordDto recordDto = modelMapper.map(record, RecordDto.class);
|
||||
recordDto.setCategoryName(categoryService.getCategoryName(record.getCategoryId()));
|
||||
recordDto.setSubCategoryName(categoryService.getsubCategoryName( record.getCategoryId()));
|
||||
recordDtos.add(recordDto);
|
||||
}
|
||||
return Result.success(recordDtos);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取自己的奖惩记录")
|
||||
@GetMapping("/record")
|
||||
public Result<List<RecordDto>> record(Integer page, Integer size) {
|
||||
return Result.success(new ArrayList<>());
|
||||
public Result<List<RecordDto>> record(@RequestParam(defaultValue = "0") int page,
|
||||
@RequestParam(defaultValue = "10") int size,
|
||||
HttpServletRequest request) {
|
||||
String token = (String) request.getAttribute("token");
|
||||
String userId= JwtUtils.extractUserId(token);
|
||||
List<RecordDto> recordDtos=new ArrayList<>();
|
||||
|
||||
List<Record> records = recordService.getMyAllRecords(page, size,userId);
|
||||
for (Record record : records) {
|
||||
|
||||
RecordDto recordDto = modelMapper.map(record, RecordDto.class);
|
||||
|
||||
recordDto.setCategoryName(categoryService.getCategoryName(record.getCategoryId()));
|
||||
recordDto.setSubCategoryName(categoryService.getsubCategoryName( record.getCategoryId()));
|
||||
|
||||
recordDtos.add(recordDto);
|
||||
}
|
||||
return Result.success(recordDtos);
|
||||
|
||||
}
|
||||
|
||||
@Operation(summary = "更新单个奖惩记录")
|
||||
@PutMapping("/admin/record/{id}")
|
||||
public Result<CommonResponse> adminUpdateRecord(@PathVariable Integer id, @RequestBody RecordDto recordDto) {
|
||||
|
||||
Record record = modelMapper.map(recordDto, Record.class);
|
||||
recordService.updateRecord(record,id);
|
||||
return Result.msg("修改成功");
|
||||
}
|
||||
|
||||
@Operation(summary = "删除单个奖惩记录")
|
||||
@DeleteMapping("/admin/record/{id}")
|
||||
public Result<CommonResponse> adminDeleteRecord(@PathVariable Integer id) {
|
||||
|
||||
recordService.deleteRecord(id);
|
||||
return Result.msg("删除成功");
|
||||
}
|
||||
|
||||
|
||||
@Operation(summary = "添加奖惩记录")
|
||||
@PostMapping("/admin/record")
|
||||
public Result<CommonResponse> adminAddRecord(@RequestBody RecordDto recordDto) {
|
||||
Integer categoryId = categoryService.getIdBySubCategoryName(recordDto.getSubCategoryName());
|
||||
|
||||
Record record = modelMapper.map(recordDto, Record.class);
|
||||
if (categoryId == null) {
|
||||
Result.error("请选择奖惩类别,以及类型");
|
||||
}
|
||||
record.setCategoryId(categoryId);
|
||||
recordService.addRecord(record);
|
||||
return Result.msg("添加成功");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package top.suyiiyii.sims.controller;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -8,11 +10,14 @@ import org.springframework.web.bind.annotation.*;
|
||||
import top.suyiiyii.sims.common.AuthAccess;
|
||||
import top.suyiiyii.sims.common.Result;
|
||||
import top.suyiiyii.sims.dto.CommonResponse;
|
||||
import top.suyiiyii.sims.dto.UserDto;
|
||||
import top.suyiiyii.sims.entity.User;
|
||||
import top.suyiiyii.sims.exception.ServiceException;
|
||||
import top.suyiiyii.sims.service.RoleService;
|
||||
import top.suyiiyii.sims.service.UserService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @Author tortoise
|
||||
@ -32,6 +37,7 @@ public class UserController {
|
||||
@Autowired
|
||||
RoleService roleService;
|
||||
|
||||
|
||||
@AuthAccess
|
||||
@GetMapping("/")
|
||||
public Result hello() {
|
||||
@ -41,17 +47,20 @@ public class UserController {
|
||||
}
|
||||
|
||||
@PostMapping("/user/login")
|
||||
public Result<LoginResponse> login(@RequestBody LoginRequest request) {
|
||||
public Result<LoginResponse> login(@RequestBody LoginRequest request, HttpServletRequest httpServletRequest) {
|
||||
log.info("login request:{}", request);
|
||||
|
||||
if (StrUtil.isBlank(request.getUsername()) || StrUtil.isBlank(request.getPassword())) {
|
||||
|
||||
return Result.error("用户名或密码不能为空");
|
||||
}
|
||||
|
||||
User user = userService.login(request.getUsername(), request.getPassword());
|
||||
|
||||
return Result.success(new LoginResponse());
|
||||
String token = userService.login(request.getUsername(), request.getPassword());
|
||||
if (token == null) {
|
||||
return Result.error("用户名或密码错误");
|
||||
}
|
||||
LoginResponse response = new LoginResponse();
|
||||
response.setToken(token);
|
||||
return Result.success(response);
|
||||
}
|
||||
|
||||
@PostMapping("/user/register")
|
||||
@ -64,26 +73,46 @@ public class UserController {
|
||||
if (request.getPassword() == null || request.getPassword().length() < 3) {
|
||||
throw new ServiceException("密码长度不能小于3位");
|
||||
}
|
||||
|
||||
userService.register(new User());
|
||||
User user = new User();
|
||||
user.setUsername(request.getUsername());
|
||||
user.setPassword(request.getPassword());
|
||||
user.setEmail(request.getEmail());
|
||||
user.setGrade(request.getGrade());
|
||||
user.setUserGroup(request.getGroup());
|
||||
userService.register(user);
|
||||
|
||||
return Result.success(CommonResponse.factory("注册成功"));
|
||||
}
|
||||
|
||||
@Operation(description = "删除单个用户")
|
||||
@DeleteMapping("/admin/user/{id}")
|
||||
public Result<CommonResponse> adminDelete(@PathVariable Integer id) {
|
||||
log.info("delete request:{}", id);
|
||||
// userService.deleteUser(user.getId());
|
||||
userService.deleteUser(id);
|
||||
return Result.success(CommonResponse.factory("删除成功"));
|
||||
}
|
||||
|
||||
@Operation(description = "获取所有用户信息")
|
||||
@GetMapping("/admin/user")
|
||||
public Result<List<UserDto>> adminGet() {
|
||||
List<UserDto> allUsers = userService.findAllUsers();
|
||||
return Result.success(allUsers);
|
||||
}
|
||||
|
||||
@Operation(description = "根据 id 获取用户信息")
|
||||
@GetMapping("/admin/user/{id}")
|
||||
public Result<User> adminGetById(@PathVariable Integer id) {
|
||||
public Result<UserDto> adminGetById(@PathVariable Integer id) {
|
||||
log.info("selectById request:{}", id);
|
||||
User user = userService.selectById(id);
|
||||
UserDto user = userService.findUser(id);
|
||||
return Result.success(user);
|
||||
}
|
||||
|
||||
@Operation(description = "获取当前用户信息")
|
||||
@GetMapping("/user/me")
|
||||
public Result<UserDto> getSelf() {
|
||||
UserDto user = userService.findUser(0);
|
||||
return Result.success(user);
|
||||
}
|
||||
|
||||
|
||||
@Data
|
||||
|
@ -5,20 +5,22 @@ import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class RecordDto {
|
||||
private Integer id;
|
||||
|
||||
// 用户ID
|
||||
private Integer userId;
|
||||
// 奖惩类型
|
||||
private String type;
|
||||
// 奖惩类别ID
|
||||
private Integer categoryId;
|
||||
private Integer studentId;
|
||||
|
||||
|
||||
private String categoryName;
|
||||
|
||||
private String subCategoryName;
|
||||
// 奖惩日期
|
||||
private LocalDateTime date;
|
||||
private Long date;
|
||||
// 奖惩内容
|
||||
private String content;
|
||||
// 奖惩原因
|
||||
@ -30,7 +32,7 @@ public class RecordDto {
|
||||
// 是否撤销
|
||||
private Boolean isRevoked;
|
||||
// 撤销日期
|
||||
private LocalDateTime revokeDate;
|
||||
private Long revokeDate;
|
||||
// 撤销原因
|
||||
private String revokeReason;
|
||||
// 撤销备注
|
||||
@ -38,5 +40,5 @@ public class RecordDto {
|
||||
// 操作人ID
|
||||
private Integer operatorUserId;
|
||||
// 最近一次更新时间
|
||||
private LocalDateTime lastUpdateTime;
|
||||
private Long lastUpdateTime;
|
||||
}
|
||||
|
@ -14,8 +14,9 @@ import java.util.List;
|
||||
*/
|
||||
@Data
|
||||
public class UserDto {
|
||||
private Long userId;
|
||||
private Integer userId;
|
||||
private String username;
|
||||
private String grade;
|
||||
private String userGroup;
|
||||
private List<String> roles; // 角色名称列表
|
||||
private List<String> permissions; // 权限列表
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package top.suyiiyii.sims.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.tangzc.mpe.autotable.annotation.Table;
|
||||
import lombok.AllArgsConstructor;
|
||||
@ -12,7 +13,7 @@ import java.time.LocalDateTime;
|
||||
* @Author tortoise
|
||||
* @Date 2024/8/9 14:04
|
||||
* @PackageName:top.suyiiyii.sims.entity
|
||||
* @ClassName: Record
|
||||
* @ClassName: RecordMapper
|
||||
* @Description: TODO
|
||||
* @Version 1.0
|
||||
*/
|
||||
@ -21,16 +22,15 @@ import java.time.LocalDateTime;
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Record {
|
||||
@TableId("id")
|
||||
@TableId(type = IdType.AUTO)
|
||||
//自增
|
||||
private Integer id;
|
||||
// 用户ID
|
||||
private Integer userId;
|
||||
// 奖惩类型
|
||||
private String type;
|
||||
private Integer StudentId;
|
||||
// 奖惩类别ID
|
||||
private Integer categoryId;
|
||||
// 奖惩日期
|
||||
private LocalDateTime date;
|
||||
private Long date;
|
||||
// 奖惩内容
|
||||
private String content;
|
||||
// 奖惩原因
|
||||
@ -42,7 +42,7 @@ public class Record {
|
||||
// 是否撤销
|
||||
private Boolean isRevoked;
|
||||
// 撤销日期
|
||||
private LocalDateTime revokeDate;
|
||||
private Long revokeDate;
|
||||
// 撤销原因
|
||||
private String revokeReason;
|
||||
// 撤销备注
|
||||
@ -50,7 +50,7 @@ public class Record {
|
||||
// 操作人ID
|
||||
private Integer operatorUserId;
|
||||
// 最近一次更新时间
|
||||
private LocalDateTime lastUpdateTime;
|
||||
private Long lastUpdateTime;
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,14 +1,11 @@
|
||||
package top.suyiiyii.sims.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.tangzc.mpe.autotable.annotation.Table;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @Author tortoise
|
||||
* @Date 2024/8/9 14:02
|
||||
@ -29,9 +26,5 @@ public class User {
|
||||
private String password;
|
||||
private String email;
|
||||
private String grade;
|
||||
private String group;
|
||||
@TableField(exist = false)
|
||||
private String token;
|
||||
@TableField(exist = false)
|
||||
private Set<Permissions> permissions;
|
||||
private String userGroup;
|
||||
}
|
||||
|
23
src/main/java/top/suyiiyii/sims/mapper/CategoryMapper.java
Normal file
23
src/main/java/top/suyiiyii/sims/mapper/CategoryMapper.java
Normal file
@ -0,0 +1,23 @@
|
||||
package top.suyiiyii.sims.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
/**
|
||||
* @Author tortoise
|
||||
* @Date 2024/8/16 23:31
|
||||
* @PackageName:top.suyiiyii.sims.mapper
|
||||
* @ClassName: CategoryMapper
|
||||
* @Description: TODO
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Mapper
|
||||
public interface CategoryMapper {
|
||||
@Select("SELECT * FROM reward_punishment_category WHERE category_id=#{id}")
|
||||
String getCategoryName(Integer categoryId);
|
||||
|
||||
@Select("SELECT category_name FROM reward_punishment_category WHERE category_id=#{categoryId}")
|
||||
String getSubCategoryName(Integer categoryId);
|
||||
@Select("SELECT category_id FROM reward_punishment_category WHERE sub_category_name=#{subCategoryName}")
|
||||
Integer getIdBySubCategoryName(String subCategoryName);
|
||||
}
|
7
src/main/java/top/suyiiyii/sims/mapper/MpUserMapper.java
Normal file
7
src/main/java/top/suyiiyii/sims/mapper/MpUserMapper.java
Normal file
@ -0,0 +1,7 @@
|
||||
package top.suyiiyii.sims.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import top.suyiiyii.sims.entity.User;
|
||||
|
||||
public interface MpUserMapper extends BaseMapper<User> {
|
||||
}
|
52
src/main/java/top/suyiiyii/sims/mapper/RecordMapper.java
Normal file
52
src/main/java/top/suyiiyii/sims/mapper/RecordMapper.java
Normal file
@ -0,0 +1,52 @@
|
||||
package top.suyiiyii.sims.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.*;
|
||||
import top.suyiiyii.sims.dto.RecordDto;
|
||||
import top.suyiiyii.sims.entity.Record;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author tortoise
|
||||
* @Date 2024/8/16 21:39
|
||||
* @PackageName:top.suyiiyii.sims.mapper
|
||||
* @ClassName: RecordMapper
|
||||
* @Description: TODO
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Mapper
|
||||
public interface RecordMapper {
|
||||
//分页查询
|
||||
@Select("select * from record limit #{page},#{size}")
|
||||
List<Record> getAllRecords(Integer page, Integer size);
|
||||
//根据学号分页查询所以信息
|
||||
@Select("select * from record where student_id = #{id} limit #{page},#{size}")
|
||||
List<Record> getMyAllRecords(Integer page, Integer size, String id);
|
||||
|
||||
//根据id,更新对应信息
|
||||
@Update("UPDATE record SET "
|
||||
|
||||
+ "date = #{record.date}, "
|
||||
+ "content = #{record.content}, "
|
||||
+ "reason = #{record.reason}, "
|
||||
+ "amount = #{record.amount}, "
|
||||
+ "remark = #{record.remark}, "
|
||||
+ "is_revoked = #{record.isRevoked}, "
|
||||
+ "revoke_date = #{record.revokeDate}, "
|
||||
+ "revoke_reason = #{record.revokeReason}, "
|
||||
+ "revoke_remark = #{record.revokeRemark}, "
|
||||
+ "operator_user_id = #{record.operatorUserId}, "
|
||||
+ "last_update_time = #{record.lastUpdateTime} "
|
||||
+ "WHERE id = #{id}")
|
||||
void updateRecord(Record record, Integer id);
|
||||
|
||||
@Delete("delete from record where id = #{id}")
|
||||
void deleteRecord(Integer id);
|
||||
@Insert({
|
||||
"insert into record (student_id, category_id, `date`, content, reason, amount, remark, is_revoked,",
|
||||
"revoke_date, revoke_reason, revoke_remark, operator_user_id, last_update_time)",
|
||||
"VALUES (#{studentId}, #{categoryId}, #{date}, #{content}, #{reason}, #{amount}, #{remark}, #{isRevoked},",
|
||||
"#{revokeDate}, #{revokeReason}, #{revokeRemark}, #{operatorUserId}, #{lastUpdateTime})"
|
||||
})
|
||||
void addRecord(Record record);
|
||||
}
|
@ -51,8 +51,10 @@ public interface RoleMapper {
|
||||
"FROM role " +
|
||||
"WHERE role_id IN " +
|
||||
"(SELECT role_id FROM user_role WHERE user_id = #{user_id})")
|
||||
List<UserRole> selectRolesById(@Param("user_id") int id);
|
||||
List<Role> selectRolesById(@Param("user_id") int id);
|
||||
|
||||
@Select("SELECT role_name FROM role WHERE role_id=#{roleId}")
|
||||
List<String> selectRoleNamesByRoleId(Integer roleId);
|
||||
|
||||
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ public interface UserMapper extends BaseMapper<User> {
|
||||
* @param user 新用户对象
|
||||
* @return 影响的行数
|
||||
*/
|
||||
@Insert("insert INTO user (id,user_id, username, password, name, email, `group`) VALUES (#{id},#{userId}, #{username}, #{password}, #{name}, #{email}, #{group})")
|
||||
@Insert("insert INTO user (id,student_id, username, password, name, email, userGroup) VALUES (#{id},#{studentId}, #{username}, #{password}, #{name}, #{email}, #{userGroup})")
|
||||
int addUser(User user);
|
||||
|
||||
/**
|
||||
@ -39,39 +39,41 @@ public interface UserMapper extends BaseMapper<User> {
|
||||
* @return 影响的行数
|
||||
*/
|
||||
@Update("UPDATE user SET " +
|
||||
"user_id = #{userId}, " +
|
||||
"student_id = #{userId}, " +
|
||||
"username = #{username}, " +
|
||||
"name = #{name}, " +
|
||||
"email = #{email}, " +
|
||||
"`group` = #{group} " +
|
||||
"grade = #{grade}, " +
|
||||
"userGroup = #{group} " +
|
||||
"WHERE id = #{id}")
|
||||
int updateUser(User user);
|
||||
|
||||
/**
|
||||
* 根据ID查询用户信息
|
||||
* @param id 用户ID
|
||||
* @param
|
||||
* @return 用户对象
|
||||
*/
|
||||
@Select("SELECT id, user_id, username, password, name, email, `group` from user WHERE id = #{Id}")
|
||||
User selectByUserId(Integer userId);
|
||||
@Select("SELECT id, student_id, username, password, name, email,grade,user_group from user WHERE student_id = #{id}")
|
||||
User selectByUserId(Integer id);
|
||||
|
||||
/**
|
||||
* 根据iD查询用户信息
|
||||
* @param
|
||||
* @return 用户对象
|
||||
*/
|
||||
@Select("SELECT id, user_id, username, password, name, email, `group` from user WHERE id = #{Id}")
|
||||
User selectById(Integer Id);
|
||||
@Select("SELECT id, student_id, username, password, name, email,grade, user_group from user WHERE id = #{id}")
|
||||
User selectById(Integer id);
|
||||
/**
|
||||
* 查询所有用户信息
|
||||
* @return 用户列表
|
||||
*/
|
||||
@Select("SELECT id, user_id, username, password, name, email,grade, `group` FROM user")
|
||||
@Select("SELECT id, student_id, username, password, name, email, grade, user_group FROM user")
|
||||
List<User> selectAll();
|
||||
|
||||
@Select("select * from user where username = #{username}")
|
||||
User selectByUserName(@Param("username") String username);
|
||||
@Update("update user set password = #{password} where username = #{username}")
|
||||
void updatePassword(User user);
|
||||
|
||||
@Select("select student_id from user where id = #{userId}")
|
||||
String getStudentIdById(String userId);
|
||||
}
|
||||
|
34
src/main/java/top/suyiiyii/sims/service/CategoryService.java
Normal file
34
src/main/java/top/suyiiyii/sims/service/CategoryService.java
Normal file
@ -0,0 +1,34 @@
|
||||
package top.suyiiyii.sims.service;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import top.suyiiyii.sims.mapper.CategoryMapper;
|
||||
|
||||
/**
|
||||
* @Author tortoise
|
||||
* @Date 2024/8/16 23:32
|
||||
* @PackageName:top.suyiiyii.sims.service
|
||||
* @ClassName: CategoryService
|
||||
* @Description: TODO
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Service
|
||||
public class CategoryService {
|
||||
@Autowired
|
||||
CategoryMapper categoryMapper;
|
||||
|
||||
|
||||
public String getCategoryName(Integer id) {
|
||||
return categoryMapper.getCategoryName(id);
|
||||
}
|
||||
|
||||
public String getsubCategoryName(Integer categoryId) {
|
||||
return categoryMapper.getSubCategoryName(categoryId);
|
||||
}
|
||||
|
||||
|
||||
public Integer getIdBySubCategoryName(String subCategoryName) {
|
||||
return categoryMapper.getIdBySubCategoryName(subCategoryName);
|
||||
|
||||
}
|
||||
}
|
51
src/main/java/top/suyiiyii/sims/service/RecordService.java
Normal file
51
src/main/java/top/suyiiyii/sims/service/RecordService.java
Normal file
@ -0,0 +1,51 @@
|
||||
package top.suyiiyii.sims.service;
|
||||
|
||||
|
||||
import org.checkerframework.checker.units.qual.A;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import top.suyiiyii.sims.dto.RecordDto;
|
||||
import top.suyiiyii.sims.entity.Record;
|
||||
import top.suyiiyii.sims.mapper.RecordMapper;
|
||||
import top.suyiiyii.sims.mapper.UserMapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author tortoise
|
||||
* @Date 2024/8/16 21:47
|
||||
* @PackageName:top.suyiiyii.sims.service
|
||||
* @ClassName: RecordService
|
||||
* @Description: TODO
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Service
|
||||
public class RecordService {
|
||||
@Autowired
|
||||
RecordMapper recordMapper;
|
||||
@Autowired
|
||||
UserMapper userMapper;
|
||||
|
||||
public List<Record> getAllRecords(Integer page, Integer size) {
|
||||
|
||||
return recordMapper.getAllRecords(page, size);
|
||||
}
|
||||
|
||||
|
||||
public List<Record> getMyAllRecords(Integer page, Integer size, String userId) {
|
||||
String studentId = userMapper.getStudentIdById(userId);
|
||||
return recordMapper.getMyAllRecords(page, size, studentId);
|
||||
}
|
||||
|
||||
public void updateRecord(Record record, Integer id) {
|
||||
recordMapper.updateRecord(record, id);
|
||||
}
|
||||
|
||||
public void deleteRecord(Integer id) {
|
||||
recordMapper.deleteRecord(id);
|
||||
}
|
||||
|
||||
public void addRecord(Record record) {
|
||||
recordMapper.addRecord(record);
|
||||
}
|
||||
}
|
@ -22,15 +22,7 @@ import java.util.List;
|
||||
public class RoleService {
|
||||
@Autowired
|
||||
RoleMapper roleMapper;
|
||||
public void addRole(String name){
|
||||
roleMapper.addRole(name);
|
||||
}
|
||||
public void deleteRole(String name){
|
||||
roleMapper.deleteRole(name);
|
||||
}
|
||||
public void updateRole(String name,String newName){
|
||||
roleMapper.updateRole(name,newName);
|
||||
}
|
||||
|
||||
public List<User> findAllUsersWithRoles(){
|
||||
return roleMapper.selectAllUsersWithRoles();
|
||||
}
|
||||
@ -41,9 +33,20 @@ public class RoleService {
|
||||
* @param Id
|
||||
* @return: java.util.List<top.suyiiyii.sims.entity.Role>
|
||||
*/
|
||||
List<UserRole> selectRolesById(int id){
|
||||
public List<Role> selectRolesById(int id){
|
||||
return roleMapper.selectRolesById(id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public boolean isRoleNameAdmin(Integer id) {
|
||||
List<Role> roles = roleMapper.selectRolesById(id);
|
||||
for (Role role : roles) {
|
||||
if (role.getRoleName().equals("admin")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,8 @@ package top.suyiiyii.sims.service;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import top.suyiiyii.sims.VO.UserVO;
|
||||
|
||||
import top.suyiiyii.sims.dto.UserDto;
|
||||
import top.suyiiyii.sims.entity.*;
|
||||
import top.suyiiyii.sims.exception.ServiceException;
|
||||
import top.suyiiyii.sims.mapper.PermissionsMapper;
|
||||
@ -38,10 +39,6 @@ public class UserService {
|
||||
userMapper.addUser(user);
|
||||
}
|
||||
|
||||
public User selectById(int id) {
|
||||
return userMapper.selectById(id);
|
||||
}
|
||||
|
||||
public void updateUser(User user) {
|
||||
userMapper.updateUser(user);
|
||||
}
|
||||
@ -54,7 +51,8 @@ public class UserService {
|
||||
return userMapper.selectAll();
|
||||
}
|
||||
//TODO:返回一个DTO,用户基本信息
|
||||
public User login(String username, String password) {
|
||||
public String login(String username, String password) {
|
||||
|
||||
User dbUser = userMapper.selectByUserName(username);
|
||||
if (dbUser == null) {
|
||||
throw new ServiceException("账号不存在");
|
||||
@ -64,10 +62,10 @@ public class UserService {
|
||||
}
|
||||
HashSet<Permissions> permissionsSet = new HashSet<>();
|
||||
Integer id = dbUser.getId();
|
||||
List<UserRole> UserRoles = roleMapper.selectRolesById(id);
|
||||
for (UserRole userRole : UserRoles) {
|
||||
List<Role> roles = roleMapper.selectRolesById(id);
|
||||
for (Role role : roles) {
|
||||
//根据roleid找所有permissionId
|
||||
List<RolePermission> rolePerminsion = permissionsMapper.getRolePerminsionByRoleId(userRole.getRoleId());
|
||||
List<RolePermission> rolePerminsion = permissionsMapper.getRolePerminsionByRoleId(role.getRoleId());
|
||||
for (RolePermission rolePermission : rolePerminsion) {
|
||||
Integer permissionId = rolePermission.getPermissionId();
|
||||
//根据permissionId找permission
|
||||
@ -75,13 +73,15 @@ public class UserService {
|
||||
permissionsSet.add(permissions);
|
||||
}
|
||||
}
|
||||
dbUser.setPermissions(permissionsSet);
|
||||
|
||||
String token = JwtUtils.createToken(dbUser.getId().toString(), dbUser.getPassword());
|
||||
dbUser.setToken(token);
|
||||
return dbUser;
|
||||
|
||||
|
||||
return token;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public User register(User user) {
|
||||
|
||||
User dbUser = userMapper.selectByUserId(user.getStudentId());
|
||||
@ -101,7 +101,7 @@ public class UserService {
|
||||
if (user.getEmail() == null || user.getEmail().equals("")) {
|
||||
throw new ServiceException("邮箱不能为空");
|
||||
}
|
||||
if (user.getGroup() == null || user.getGroup().equals("")) {
|
||||
if (user.getUserGroup() == null || user.getUserGroup().equals("")) {
|
||||
throw new ServiceException("组别不能为空");
|
||||
}
|
||||
|
||||
@ -114,29 +114,57 @@ public class UserService {
|
||||
public void updatePassword(User user) {
|
||||
userMapper.updatePassword(user);
|
||||
}
|
||||
public List<UserVO> findAllUsers(){
|
||||
public List<UserDto> findAllUsers(){
|
||||
List<User> users = userMapper.selectAll();
|
||||
List<UserVO> userVOS = new ArrayList<>();
|
||||
List<UserDto> UserDtos = new ArrayList<>();
|
||||
|
||||
for (User user : users) {
|
||||
UserVO userVO = new UserVO();
|
||||
userVO.setUserId(user.getId());
|
||||
userVO.setUsername(user.getUsername());
|
||||
userVO.setGrade(user.getGrade());
|
||||
userVO.setGroup(user.getGroup());
|
||||
userVO.setRoles(new ArrayList<>());
|
||||
UserDto UserDto = new UserDto();
|
||||
UserDto.setUserId(user.getId());
|
||||
UserDto.setUsername(user.getUsername());
|
||||
UserDto.setGrade(user.getGrade());
|
||||
UserDto.setUserGroup(user.getUserGroup());
|
||||
UserDto.setRoles(new ArrayList<>());
|
||||
Integer id = user.getId();
|
||||
List<UserRole> userRoles = roleMapper.selectRolesById(id);
|
||||
for (UserRole userRole : userRoles) {
|
||||
Integer roleId = userRole.getRoleId();
|
||||
List<Role> roles = roleMapper.selectRolesById(id);
|
||||
for (Role role : roles) {
|
||||
Integer roleId = role.getRoleId();
|
||||
// 获取一个角色的名称列表
|
||||
List<String> roleNameList = roleMapper.selectRoleNamesByRoleId(roleId);
|
||||
// 累加角色名称到用户的角色列表中
|
||||
userVO.getRoles().addAll(roleNameList);
|
||||
UserDto.getRoles().addAll(roleNameList);
|
||||
}
|
||||
userVOS.add(userVO);
|
||||
UserDtos.add(UserDto);
|
||||
}
|
||||
return userVOS;
|
||||
return UserDtos;
|
||||
}
|
||||
public UserDto findUser(Integer id) {
|
||||
|
||||
UserDto UserDto = new UserDto();
|
||||
User user = userMapper.selectById(id);
|
||||
UserDto.setUserId(user.getId());
|
||||
UserDto.setUsername(user.getUsername());
|
||||
UserDto.setGrade(user.getGrade());
|
||||
UserDto.setUserGroup(user.getUserGroup());
|
||||
UserDto.setRoles(new ArrayList<>());
|
||||
List<Role> roles = roleMapper.selectRolesById(id);
|
||||
for (Role role : roles) {
|
||||
Integer roleId = role.getRoleId();
|
||||
// 获取一个角色的名称列表
|
||||
List<String> roleNameList = roleMapper.selectRoleNamesByRoleId(roleId);
|
||||
// 累加角色名称到用户的角色列表中
|
||||
UserDto.getRoles().addAll(roleNameList);
|
||||
}
|
||||
|
||||
|
||||
return UserDto;
|
||||
}
|
||||
|
||||
public User selectByUserId(Integer studentId) {
|
||||
return userMapper.selectByUserId(studentId);
|
||||
}
|
||||
|
||||
public List<Role> selectRolesById(Integer studentId) {
|
||||
return roleMapper.selectRolesById(studentId);
|
||||
}
|
||||
}
|
||||
|
8
src/main/resources/application-test.yaml
Normal file
8
src/main/resources/application-test.yaml
Normal file
@ -0,0 +1,8 @@
|
||||
spring:
|
||||
datasource:
|
||||
url: jdbc:sqlite:test.db:testdb?cache=shared
|
||||
driver-class-name: org.sqlite.JDBC
|
||||
username:
|
||||
password:
|
||||
|
||||
|
14
src/main/resources/application.yaml
Normal file
14
src/main/resources/application.yaml
Normal file
@ -0,0 +1,14 @@
|
||||
# datasource
|
||||
spring:
|
||||
profiles:
|
||||
active: prod
|
||||
datasource:
|
||||
url: ${DATASOURCE_URL}
|
||||
username: ${DATASOURCE_USERNAME}
|
||||
password: ${DATASOURCE_PASSWORD}
|
||||
driver-class-name: ${DATASOURCE_DRIVER_CLASS_NAME}
|
||||
|
||||
|
||||
auto-table:
|
||||
enable: true
|
||||
model-package: top.suyiiyii.sims.entity
|
@ -1,13 +0,0 @@
|
||||
package top.suyiiyii.sims;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class SimsApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
33
src/test/java/top/suyiiyii/sims/mapper/UserMapperTest.java
Normal file
33
src/test/java/top/suyiiyii/sims/mapper/UserMapperTest.java
Normal file
@ -0,0 +1,33 @@
|
||||
package top.suyiiyii.sims.mapper;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import top.suyiiyii.sims.entity.User;
|
||||
|
||||
@SpringBootTest
|
||||
@ActiveProfiles("test")
|
||||
public class UserMapperTest {
|
||||
|
||||
@Autowired
|
||||
private MpUserMapper userMapper;
|
||||
|
||||
@Test
|
||||
public void testAddUser() {
|
||||
User user = new User();
|
||||
user.setStudentId(1);
|
||||
user.setUsername("test");
|
||||
user.setPassword("test");
|
||||
user.setEmail("test");
|
||||
user.setGrade("test");
|
||||
user.setUserGroup("test");
|
||||
|
||||
|
||||
|
||||
int result = userMapper.insert(user);
|
||||
Assertions.assertEquals(1, result);
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user