mirror of
https://github.com/suyiiyii/SIMS.git
synced 2025-06-05 13:36:12 +08:00
登陆,注册,加上异常集中处理,mybatis和mybatisplus不兼容好像是
This commit is contained in:
parent
ce69219012
commit
d56316ea0a
5
pom.xml
5
pom.xml
@ -56,6 +56,11 @@
|
|||||||
<artifactId>mysql-connector-j</artifactId>
|
<artifactId>mysql-connector-j</artifactId>
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.hutool</groupId>
|
||||||
|
<artifactId>hutool-all</artifactId>
|
||||||
|
<version>5.8.11</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||||
|
45
src/main/java/top/suyiiyii/sims/common/Result.java
Normal file
45
src/main/java/top/suyiiyii/sims/common/Result.java
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
package top.suyiiyii.sims.common;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author tortoise
|
||||||
|
* @Date 2024/8/10 21:18
|
||||||
|
* @PackageName:top.suyiiyii.sims.common
|
||||||
|
* @ClassName: Result
|
||||||
|
* @Description: TODO
|
||||||
|
* @Version 1.0
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class Result {
|
||||||
|
|
||||||
|
public static final String CODE_SUCCESS="200";
|
||||||
|
public static final String CODE_AUTH_ERROR="401";
|
||||||
|
public static final String CODE_SYS_ERROR="500";
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
private String msg;
|
||||||
|
private Object data;
|
||||||
|
public static Result success(){
|
||||||
|
return new Result(CODE_SUCCESS,"success",null);
|
||||||
|
}
|
||||||
|
public static Result success(Object data){
|
||||||
|
return new Result(CODE_SUCCESS,"success",data);
|
||||||
|
}
|
||||||
|
public static Result error(String msg) {
|
||||||
|
return new Result(CODE_SYS_ERROR, msg, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Result error(String code,String msg){
|
||||||
|
return new Result(code,msg,null);
|
||||||
|
}
|
||||||
|
public static Result authError(String msg){
|
||||||
|
return new Result(CODE_AUTH_ERROR,"系统错误",null);
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,7 @@ package top.suyiiyii.sims.controller;
|
|||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import top.suyiiyii.sims.common.Result;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -18,5 +19,9 @@ public class HelloController {
|
|||||||
List<String> list = List.of(username,age.toString());
|
List<String> list = List.of(username,age.toString());
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
@GetMapping("/helloResult")
|
||||||
|
public Result healthz() {
|
||||||
|
return Result.success("Hello World");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,65 @@
|
|||||||
|
package top.suyiiyii.sims.controller;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import top.suyiiyii.sims.common.Result;
|
||||||
|
import top.suyiiyii.sims.entity.User;
|
||||||
|
import top.suyiiyii.sims.exception.ServiceException;
|
||||||
|
import top.suyiiyii.sims.service.UserService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author tortoise
|
||||||
|
* @Date 2024/8/10 22:25
|
||||||
|
* @PackageName:top.suyiiyii.sims.controller
|
||||||
|
* @ClassName: UserController
|
||||||
|
* @Description: TODO
|
||||||
|
* @Version 1.0
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/user")
|
||||||
|
public class UserController {
|
||||||
|
@Autowired
|
||||||
|
UserService userService;
|
||||||
|
@GetMapping("/")
|
||||||
|
public Result hello(){
|
||||||
|
|
||||||
|
return Result.success("success");
|
||||||
|
|
||||||
|
}
|
||||||
|
@PostMapping("/login")
|
||||||
|
public Result login(@RequestBody User user){
|
||||||
|
if(StrUtil.isBlank(user.getUsername())||StrUtil.isBlank(user.getPassword())){
|
||||||
|
|
||||||
|
return Result.error("用户名或密码不能为空");
|
||||||
|
}
|
||||||
|
user =userService.login(user);
|
||||||
|
|
||||||
|
|
||||||
|
return Result.success(user);
|
||||||
|
}
|
||||||
|
@PostMapping("/register")
|
||||||
|
public Result register(@RequestBody User user){
|
||||||
|
if(StrUtil.isBlank(user.getUsername())||StrUtil.isBlank(user.getPassword())){
|
||||||
|
|
||||||
|
return Result.error("用户名或密码不能为空");
|
||||||
|
}
|
||||||
|
if(user.getPassword() == null || user.getPassword().length() < 3) {
|
||||||
|
throw new ServiceException("密码长度不能小于3位");
|
||||||
|
}
|
||||||
|
|
||||||
|
user =userService.register(user);
|
||||||
|
|
||||||
|
return Result.success(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping("/selectAll")
|
||||||
|
public Result selectAll() {
|
||||||
|
List<User> users = userService.selectAll();
|
||||||
|
return Result.success(users);
|
||||||
|
}
|
||||||
|
}
|
@ -4,7 +4,9 @@ import com.baomidou.mybatisplus.annotation.IdType;
|
|||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.tangzc.mpe.autotable.annotation.Table;
|
import com.tangzc.mpe.autotable.annotation.Table;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author tortoise
|
* @Author tortoise
|
||||||
@ -16,7 +18,10 @@ import lombok.Data;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Table
|
@Table
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
public class Attachment {
|
public class Attachment {
|
||||||
|
@TableId("id")
|
||||||
private Integer id;
|
private Integer id;
|
||||||
private Integer recordId;
|
private Integer recordId;
|
||||||
// 文件路径
|
// 文件路径
|
||||||
|
@ -4,7 +4,9 @@ import com.baomidou.mybatisplus.annotation.IdType;
|
|||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.tangzc.mpe.autotable.annotation.Table;
|
import com.tangzc.mpe.autotable.annotation.Table;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author tortoise
|
* @Author tortoise
|
||||||
@ -16,8 +18,10 @@ import lombok.Data;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Table
|
@Table
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
public class HierarchyRelation {
|
public class HierarchyRelation {
|
||||||
|
@TableId("id")
|
||||||
private Integer id;
|
private Integer id;
|
||||||
|
|
||||||
// 上级用户ID
|
// 上级用户ID
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package top.suyiiyii.sims.entity;
|
package top.suyiiyii.sims.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.tangzc.mpe.autotable.annotation.Table;
|
import com.tangzc.mpe.autotable.annotation.Table;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
@ -15,7 +18,10 @@ import java.time.LocalDateTime;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Table
|
@Table
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
public class Notification {
|
public class Notification {
|
||||||
|
@TableId("id")
|
||||||
private Integer id;
|
private Integer id;
|
||||||
private String title;
|
private String title;
|
||||||
private String content;
|
private String content;
|
||||||
|
@ -3,7 +3,9 @@ package top.suyiiyii.sims.entity;
|
|||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.tangzc.mpe.autotable.annotation.Table;
|
import com.tangzc.mpe.autotable.annotation.Table;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author tortoise
|
* @Author tortoise
|
||||||
@ -15,8 +17,10 @@ import lombok.Data;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Table
|
@Table
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
public class Permissions {
|
public class Permissions {
|
||||||
|
@TableId("id")
|
||||||
private Integer id;
|
private Integer id;
|
||||||
//权限id
|
//权限id
|
||||||
private Integer permissionId;
|
private Integer permissionId;
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package top.suyiiyii.sims.entity;
|
package top.suyiiyii.sims.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.tangzc.mpe.autotable.annotation.Table;
|
import com.tangzc.mpe.autotable.annotation.Table;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
@ -15,8 +18,10 @@ import java.time.LocalDateTime;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Table
|
@Table
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
public class RevokeRequest {
|
public class RevokeRequest {
|
||||||
|
@TableId("id")
|
||||||
private Integer id;
|
private Integer id;
|
||||||
private Integer recordId;
|
private Integer recordId;
|
||||||
private Integer userId;
|
private Integer userId;
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package top.suyiiyii.sims.entity;
|
package top.suyiiyii.sims.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.tangzc.mpe.autotable.annotation.Table;
|
import com.tangzc.mpe.autotable.annotation.Table;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
@ -15,8 +18,10 @@ import java.time.LocalDateTime;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Table
|
@Table
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
public class RevokedRecord {
|
public class RevokedRecord {
|
||||||
|
@TableId("id")
|
||||||
private Integer id;
|
private Integer id;
|
||||||
// 被撤销的奖惩记录ID
|
// 被撤销的奖惩记录ID
|
||||||
private Integer recordId;
|
private Integer recordId;
|
||||||
|
@ -3,7 +3,9 @@ package top.suyiiyii.sims.entity;
|
|||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.tangzc.mpe.autotable.annotation.Table;
|
import com.tangzc.mpe.autotable.annotation.Table;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author tortoise
|
* @Author tortoise
|
||||||
@ -15,8 +17,10 @@ import lombok.Data;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Table
|
@Table
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
public class RewardPunishmentCategory {
|
public class RewardPunishmentCategory {
|
||||||
|
@TableId("id")
|
||||||
private Integer id;
|
private Integer id;
|
||||||
|
|
||||||
private Integer categoryId;
|
private Integer categoryId;
|
||||||
|
@ -4,7 +4,9 @@ import com.baomidou.mybatisplus.annotation.IdType;
|
|||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.tangzc.mpe.autotable.annotation.Table;
|
import com.tangzc.mpe.autotable.annotation.Table;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
@ -18,8 +20,10 @@ import java.time.LocalDateTime;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Table
|
@Table
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
public class RewardPunishmentRecord {
|
public class RewardPunishmentRecord {
|
||||||
|
@TableId("id")
|
||||||
private Integer id;
|
private Integer id;
|
||||||
// 用户ID
|
// 用户ID
|
||||||
private Integer userId;
|
private Integer userId;
|
||||||
|
@ -3,7 +3,9 @@ package top.suyiiyii.sims.entity;
|
|||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.tangzc.mpe.autotable.annotation.Table;
|
import com.tangzc.mpe.autotable.annotation.Table;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author tortoise
|
* @Author tortoise
|
||||||
@ -15,8 +17,10 @@ import lombok.Data;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Table
|
@Table
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
public class Role {
|
public class Role {
|
||||||
|
@TableId("id")
|
||||||
private Integer id;
|
private Integer id;
|
||||||
private Integer roleId;
|
private Integer roleId;
|
||||||
//管理员,普通用户,组员,组长,队长
|
//管理员,普通用户,组员,组长,队长
|
||||||
|
@ -4,7 +4,9 @@ import com.baomidou.mybatisplus.annotation.IdType;
|
|||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.tangzc.mpe.autotable.annotation.Table;
|
import com.tangzc.mpe.autotable.annotation.Table;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.security.Permission;
|
import java.security.Permission;
|
||||||
|
|
||||||
@ -18,8 +20,11 @@ import java.security.Permission;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Table
|
@Table
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
public class RolePermission {
|
public class RolePermission {
|
||||||
private Integer rolePermissionId;
|
@TableId("id")
|
||||||
|
private Integer id;
|
||||||
private Integer roleId;
|
private Integer roleId;
|
||||||
private Integer permissionId;
|
private Integer permissionId;
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,9 @@ import com.baomidou.mybatisplus.annotation.IdType;
|
|||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.tangzc.mpe.autotable.annotation.Table;
|
import com.tangzc.mpe.autotable.annotation.Table;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author tortoise
|
* @Author tortoise
|
||||||
@ -16,8 +18,10 @@ import lombok.Data;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Table
|
@Table
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
public class User {
|
public class User {
|
||||||
|
@TableId("id")
|
||||||
private Integer id;
|
private Integer id;
|
||||||
private Integer userId;
|
private Integer userId;
|
||||||
private String username;
|
private String username;
|
||||||
|
@ -3,7 +3,9 @@ package top.suyiiyii.sims.entity;
|
|||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.tangzc.mpe.autotable.annotation.Table;
|
import com.tangzc.mpe.autotable.annotation.Table;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author tortoise
|
* @Author tortoise
|
||||||
@ -15,8 +17,10 @@ import lombok.Data;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Table
|
@Table
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
public class UserRole {
|
public class UserRole {
|
||||||
|
@TableId("id")
|
||||||
private Integer id;
|
private Integer id;
|
||||||
private Integer userId;
|
private Integer userId;
|
||||||
private Integer roleId;
|
private Integer roleId;
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
package top.suyiiyii.sims.exception;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||||
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
import top.suyiiyii.sims.common.Result;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author tortoise
|
||||||
|
* @Date 2024/8/11 1:38
|
||||||
|
* @PackageName:top.suyiiyii.sims.exception
|
||||||
|
* @ClassName: GlobalException
|
||||||
|
* @Description: TODO
|
||||||
|
* @Version 1.0
|
||||||
|
*/
|
||||||
|
@ControllerAdvice
|
||||||
|
public class GlobalException {
|
||||||
|
@ExceptionHandler(ServiceException.class)
|
||||||
|
@ResponseBody
|
||||||
|
public Result ServiceException(ServiceException e){
|
||||||
|
return Result.error(e.getCode(),e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package top.suyiiyii.sims.exception;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author tortoise
|
||||||
|
* @Date 2024/8/11 1:38
|
||||||
|
* @PackageName:top.suyiiyii.sims.exception
|
||||||
|
* @ClassName: ServiceException
|
||||||
|
* @Description: TODO
|
||||||
|
* @Version 1.0
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
public class ServiceException extends RuntimeException{
|
||||||
|
public final String code;
|
||||||
|
|
||||||
|
public ServiceException(String msg){
|
||||||
|
super(msg);
|
||||||
|
this.code = "500";
|
||||||
|
}
|
||||||
|
public ServiceException(String code ,String msg){
|
||||||
|
super(msg);
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
}
|
69
src/main/java/top/suyiiyii/sims/mapper/UserMapper.java
Normal file
69
src/main/java/top/suyiiyii/sims/mapper/UserMapper.java
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
package top.suyiiyii.sims.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.*;
|
||||||
|
import top.suyiiyii.sims.entity.User;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author tortoise
|
||||||
|
* @Date 2024/8/10 22:21
|
||||||
|
* @PackageName:top.suyiiyii.sims.mapper
|
||||||
|
* @ClassName: UserMapper
|
||||||
|
* @Description: TODO
|
||||||
|
* @Version 1.0
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface UserMapper extends BaseMapper<User> {
|
||||||
|
/**
|
||||||
|
* 添加新用户
|
||||||
|
* @param user 新用户对象
|
||||||
|
* @return 影响的行数
|
||||||
|
*/
|
||||||
|
@Insert("insert INTO users (userId, username, password, name, email, group) " +
|
||||||
|
"VALUES (#{userId}, #{username}, #{password}, #{name}, #{email}, #{group})")
|
||||||
|
int addUser(User user);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID删除用户
|
||||||
|
* @param id 用户ID
|
||||||
|
* @return 影响的行数
|
||||||
|
*/
|
||||||
|
@Delete("DELETE FROM users WHERE id = #{id}")
|
||||||
|
int deleteUser(Integer id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新用户信息
|
||||||
|
* @param user 更新后的用户对象
|
||||||
|
* @return 影响的行数
|
||||||
|
*/
|
||||||
|
@Update("UPDATE users SET " +
|
||||||
|
"userId = #{userId}, " +
|
||||||
|
"username = #{username}, " +
|
||||||
|
"password = #{password}, " +
|
||||||
|
"name = #{name}, " +
|
||||||
|
"email = #{email}, " +
|
||||||
|
"group = #{group} " +
|
||||||
|
"WHERE id = #{id}")
|
||||||
|
int updateUser(User user);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID查询用户信息
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @return 用户对象
|
||||||
|
*/
|
||||||
|
@Select("SELECT id, userId, username, password, name, email, group FROM users WHERE userId = #{userId}")
|
||||||
|
User selectByUserId(Integer userId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有用户信息
|
||||||
|
* @return 用户列表
|
||||||
|
*/
|
||||||
|
@Select("SELECT id, userId, username, password, name, email, group FROM users")
|
||||||
|
List<User> selectAll();
|
||||||
|
|
||||||
|
@Select("select * from user where username = #{username}")
|
||||||
|
User selectByUserName(@Param("username") String username);
|
||||||
|
|
||||||
|
}
|
87
src/main/java/top/suyiiyii/sims/service/UserService.java
Normal file
87
src/main/java/top/suyiiyii/sims/service/UserService.java
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
package top.suyiiyii.sims.service;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import top.suyiiyii.sims.entity.User;
|
||||||
|
import top.suyiiyii.sims.exception.ServiceException;
|
||||||
|
import top.suyiiyii.sims.mapper.UserMapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author tortoise
|
||||||
|
* @Date 2024/8/10 22:22
|
||||||
|
* @PackageName:top.suyiiyii.sims.service
|
||||||
|
* @ClassName: UserService
|
||||||
|
* @Description: TODO
|
||||||
|
* @Version 1.0
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class UserService {
|
||||||
|
@Autowired
|
||||||
|
UserMapper userMapper;
|
||||||
|
|
||||||
|
public void addUser(User user) {
|
||||||
|
userMapper.addUser(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public User selectByUserId(int id) {
|
||||||
|
return userMapper.selectByUserId(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateUser(User user) {
|
||||||
|
userMapper.updateUser(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteUser(int id) {
|
||||||
|
userMapper.deleteUser(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<User> selectAll() {
|
||||||
|
return userMapper.selectAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
public User login(User user) {
|
||||||
|
User dbUser = userMapper.selectByUserName(user.getUsername());
|
||||||
|
if (dbUser == null) {
|
||||||
|
throw new ServiceException("账号不存在");
|
||||||
|
}
|
||||||
|
if (!dbUser.getPassword().equals(user.getPassword())) {
|
||||||
|
throw new ServiceException("密码或用户名错误");
|
||||||
|
}
|
||||||
|
return dbUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
public User register(User user) {
|
||||||
|
|
||||||
|
User dbUser = userMapper.selectByUserId(user.getUserId());
|
||||||
|
|
||||||
|
if (user.getUsername() == null || user.getUsername().equals("")) {
|
||||||
|
throw new ServiceException("用户名不能为空");
|
||||||
|
}
|
||||||
|
if (dbUser != null) {
|
||||||
|
throw new ServiceException("账号已经存在");
|
||||||
|
}
|
||||||
|
if (user.getUserId() == null || user.getUserId().equals("")) {
|
||||||
|
throw new ServiceException("用户id不能为空");
|
||||||
|
}
|
||||||
|
if( user.getPassword() == null || user.getPassword().equals("")) {
|
||||||
|
throw new ServiceException("密码不能为空");
|
||||||
|
}
|
||||||
|
if (user.getEmail() == null || user.getEmail().equals("")) {
|
||||||
|
throw new ServiceException("邮箱不能为空");
|
||||||
|
}
|
||||||
|
if (user.getGroup() == null || user.getGroup().equals("")) {
|
||||||
|
throw new ServiceException("组别不能为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
userMapper.addUser(user);
|
||||||
|
return user;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user