diff --git a/src/main/java/com/bruce/sams/common/annotation/DataPermission.java b/src/main/java/com/bruce/sams/common/annotation/DataPermission.java deleted file mode 100644 index beaa98e3..00000000 --- a/src/main/java/com/bruce/sams/common/annotation/DataPermission.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.bruce.sams.common.annotation; - -import java.lang.annotation.*; -import org.springframework.security.access.prepost.PreAuthorize; - -/** - * 自定义数据权限注解 - * 适用于 Spring Security 6,结合 `@PreAuthorize` 进行权限控制 - */ -@Target({ElementType.METHOD}) // 作用于方法 -@Retention(RetentionPolicy.RUNTIME) // 运行时生效 -@Documented -@PreAuthorize("@dataPermissionEvaluator.hasPermission(authentication, #field, #type)") -public @interface DataPermission { - - /** - * 数据权限字段,比如 "creator_id" 或 "club_id" - */ - String field() default "user_id"; - - /** - * 数据权限类型: - * - USER: 只能访问当前用户的数据 - * - CLUB: 只能访问当前社团的数据 - * - ADMIN: 允许访问所有数据 - */ - String type() default "USER"; -} diff --git a/src/main/java/com/bruce/sams/common/config/SecurityConfig.java b/src/main/java/com/bruce/sams/common/config/SecurityConfig.java index 7bdd82d9..9f0f2da5 100644 --- a/src/main/java/com/bruce/sams/common/config/SecurityConfig.java +++ b/src/main/java/com/bruce/sams/common/config/SecurityConfig.java @@ -1,6 +1,6 @@ package com.bruce.sams.common.config; -import com.bruce.sams.common.security.JwtAuthFilter; +import com.bruce.sams.common.filter.JwtAuthFilter; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; diff --git a/src/main/java/com/bruce/sams/common/security/GlobalExceptionHandler.java b/src/main/java/com/bruce/sams/common/filter/GlobalExceptionHandler.java similarity index 90% rename from src/main/java/com/bruce/sams/common/security/GlobalExceptionHandler.java rename to src/main/java/com/bruce/sams/common/filter/GlobalExceptionHandler.java index 0f3f281c..bd47cf33 100644 --- a/src/main/java/com/bruce/sams/common/security/GlobalExceptionHandler.java +++ b/src/main/java/com/bruce/sams/common/filter/GlobalExceptionHandler.java @@ -1,7 +1,7 @@ -package com.bruce.sams.common.security; +package com.bruce.sams.common.filter; import com.bruce.sams.common.exception.CustomException; -import com.bruce.sams.utils.AjaxResult; +import com.bruce.sams.common.utils.AjaxResult; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; diff --git a/src/main/java/com/bruce/sams/common/security/JwtAuthFilter.java b/src/main/java/com/bruce/sams/common/filter/JwtAuthFilter.java similarity index 89% rename from src/main/java/com/bruce/sams/common/security/JwtAuthFilter.java rename to src/main/java/com/bruce/sams/common/filter/JwtAuthFilter.java index e72865d2..724d9548 100644 --- a/src/main/java/com/bruce/sams/common/security/JwtAuthFilter.java +++ b/src/main/java/com/bruce/sams/common/filter/JwtAuthFilter.java @@ -1,7 +1,7 @@ -package com.bruce.sams.common.security; +package com.bruce.sams.common.filter; import com.bruce.sams.service.impl.CustomUserDetailsService; -import com.bruce.sams.utils.TokenUtil; +import com.bruce.sams.common.utils.TokenUtil; import jakarta.servlet.FilterChain; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; @@ -51,8 +51,4 @@ public class JwtAuthFilter extends OncePerRequestFilter { return new CustomUserDetailsService(); // 认证逻辑 } - @Bean - public DataPermissionEvaluator dataPermissionEvaluator() { - return new DataPermissionEvaluator(); // 注册数据权限控制器 - } } diff --git a/src/main/java/com/bruce/sams/common/security/DataPermissionEvaluator.java b/src/main/java/com/bruce/sams/common/security/DataPermissionEvaluator.java deleted file mode 100644 index 448b190c..00000000 --- a/src/main/java/com/bruce/sams/common/security/DataPermissionEvaluator.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.bruce.sams.common.security; - -import com.bruce.sams.domain.entity.LoginUser; -import org.springframework.security.access.PermissionEvaluator; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.GrantedAuthority; -import org.springframework.stereotype.Component; -import java.io.Serializable; -import java.util.List; - -/** - * 数据权限评估器 - * 负责解析 `@DataPermission` 逻辑,并执行数据权限校验 - */ -@Component -public class DataPermissionEvaluator implements PermissionEvaluator { - - @Override - public boolean hasPermission(Authentication authentication, Object targetDomainObject, Object permission) { - return false; // 这里我们不处理 Object 级别的权限 - } - - /** - * 解析 `@DataPermission` 逻辑,判断用户是否有访问权限 - * - * @param authentication 当前用户认证信息 - * @param field 需要进行数据权限控制的字段(如 creator_id, club_id) - * @param type 数据权限类型(USER, CLUB, ADMIN) - * @return boolean 是否有访问权限 - */ - public boolean hasPermission(Authentication authentication, String field, String type) { - // 获取当前登录用户 - LoginUser loginUser = (LoginUser) authentication.getPrincipal(); - Long userId = loginUser.getUserId(); - List roles = loginUser.getAuthorities().stream() - .map(GrantedAuthority::getAuthority) - .toList(); - - // 如果用户是管理员,直接放行 - if (roles.contains("ROLE_ADMIN") || "ADMIN".equals(type)) { - return true; - } - - // 如果 type = "USER",只允许访问自己的数据 - if ("USER".equals(type)) { - return checkUserDataPermission(userId, field); - } - - // 如果 type = "CLUB",只允许访问自己所属社团的数据 - if ("CLUB".equals(type)) { - Long clubId = getUserClubId(userId); // 通过用户ID获取社团ID - return checkClubDataPermission(clubId, field); - } - - return false; - } - - /** - * 检查用户是否有权限访问自己的数据 - */ - private boolean checkUserDataPermission(Long userId, String field) { - return field.equals("creator_id") && userId != null; // 用户只能访问自己创建的数据 - } - - /** - * 检查用户是否有权限访问社团数据 - */ - private boolean checkClubDataPermission(Long clubId, String field) { - return field.equals("club_id") && clubId != null; // 只能访问所属社团的数据 - } - - /** - * 通过用户ID查询社团ID(可使用 MyBatis-Plus 查询数据库) - * todo 完善该内容 - */ -// private Long getUserClubId(Long userId) { -// return userMapper.getUserClubId(userId); // 假设 UserMapper 里有方法查询用户所属社团 -// } - - @Override - public boolean hasPermission(Authentication authentication, Serializable targetId, String targetType, Object permission) { - return false; // 这里不做特殊处理 - } -} - diff --git a/src/main/java/com/bruce/sams/utils/AjaxResult.java b/src/main/java/com/bruce/sams/common/utils/AjaxResult.java similarity index 99% rename from src/main/java/com/bruce/sams/utils/AjaxResult.java rename to src/main/java/com/bruce/sams/common/utils/AjaxResult.java index 0baa2738..0bd62eb7 100644 --- a/src/main/java/com/bruce/sams/utils/AjaxResult.java +++ b/src/main/java/com/bruce/sams/common/utils/AjaxResult.java @@ -1,4 +1,4 @@ -package com.bruce.sams.utils; +package com.bruce.sams.common.utils; import com.bruce.sams.common.constant.HttpStatus; diff --git a/src/main/java/com/bruce/sams/utils/PasswordUtil.java b/src/main/java/com/bruce/sams/common/utils/PasswordUtil.java similarity index 95% rename from src/main/java/com/bruce/sams/utils/PasswordUtil.java rename to src/main/java/com/bruce/sams/common/utils/PasswordUtil.java index 5005255c..11876e0c 100644 --- a/src/main/java/com/bruce/sams/utils/PasswordUtil.java +++ b/src/main/java/com/bruce/sams/common/utils/PasswordUtil.java @@ -1,4 +1,4 @@ -package com.bruce.sams.utils; +package com.bruce.sams.common.utils; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; diff --git a/src/main/java/com/bruce/sams/utils/TokenUtil.java b/src/main/java/com/bruce/sams/common/utils/TokenUtil.java similarity index 98% rename from src/main/java/com/bruce/sams/utils/TokenUtil.java rename to src/main/java/com/bruce/sams/common/utils/TokenUtil.java index af3042b8..c5a6998d 100644 --- a/src/main/java/com/bruce/sams/utils/TokenUtil.java +++ b/src/main/java/com/bruce/sams/common/utils/TokenUtil.java @@ -1,4 +1,4 @@ -package com.bruce.sams.utils; +package com.bruce.sams.common.utils; import com.bruce.sams.domain.sys.User; import io.jsonwebtoken.Claims; diff --git a/src/main/java/com/bruce/sams/controller/AuthController.java b/src/main/java/com/bruce/sams/controller/AuthController.java index 76934deb..9db0b889 100644 --- a/src/main/java/com/bruce/sams/controller/AuthController.java +++ b/src/main/java/com/bruce/sams/controller/AuthController.java @@ -2,7 +2,7 @@ package com.bruce.sams.controller; import com.bruce.sams.domain.entity.LoginRequest; import com.bruce.sams.service.AuthService; -import com.bruce.sams.utils.AjaxResult; +import com.bruce.sams.common.utils.AjaxResult; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; diff --git a/src/main/java/com/bruce/sams/controller/UserController.java b/src/main/java/com/bruce/sams/controller/UserController.java deleted file mode 100644 index 6f08f367..00000000 --- a/src/main/java/com/bruce/sams/controller/UserController.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.bruce.sams.controller; - -import com.bruce.sams.domain.sys.User; -import com.bruce.sams.utils.AjaxResult; -import com.bruce.sams.service.UserService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -/** - * 用户管理控制器(仅管理员可用) - */ -@RestController -@RequestMapping("/api/admin/user") -public class UserController { - - @Autowired - private UserService userService; - - /** - * 批量导入用户 - * - * @param users 用户列表 - * @return 操作结果 - */ - @PostMapping("/import") - public AjaxResult importUsers(@RequestBody List users) { - userService.importUsers(users); - return AjaxResult.success("用户导入成功"); - } - - /** - * 查询用户列表(可按学号、用户名、邮箱搜索) - * - * @param keyword 关键字(可选) - * @return 用户列表 - */ - @GetMapping("/list") - public AjaxResult listUsers(@RequestParam(required = false) String keyword) { - return AjaxResult.success("查询成功", userService.listUsers(keyword)); - } - - /** - * 更新用户信息(角色、状态、密码) - * - * @param user 用户对象 - * @return 操作结果 - */ - @PutMapping("/update") - public AjaxResult updateUser(@RequestBody User user) { - userService.updateUser(user); - return AjaxResult.success("用户信息更新成功"); - } - - /** - * 删除用户(逻辑删除) - * - * @param userId 用户ID - * @return 操作结果 - */ - @DeleteMapping("/delete/{userId}") - public AjaxResult deleteUser(@PathVariable Long userId) { - userService.deleteUser(userId); - return AjaxResult.success("用户删除成功"); - } -} diff --git a/src/main/java/com/bruce/sams/controller/UserProfileController.java b/src/main/java/com/bruce/sams/controller/UserProfileController.java deleted file mode 100644 index 77b53c83..00000000 --- a/src/main/java/com/bruce/sams/controller/UserProfileController.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.bruce.sams.controller; - -import com.bruce.sams.domain.sys.User; -import com.bruce.sams.utils.AjaxResult; -import com.bruce.sams.service.UserService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; - -/** - * 普通用户修改个人信息控制器 - */ -@RestController -@RequestMapping("/api/user/profile") -public class UserProfileController { - - @Autowired - private UserService userService; - - /** - * 修改密码 - */ - @PutMapping("/change-password") - public AjaxResult changePassword(@RequestAttribute Long userId, - @RequestParam String oldPassword, - @RequestParam String newPassword) { - userService.changePassword(userId, oldPassword, newPassword); - return AjaxResult.success("密码修改成功"); - } - - /** - * 修改个人信息 - */ - @PutMapping("/update") - public AjaxResult updateProfile(@RequestAttribute Long userId, @RequestBody User user) { - userService.updateProfile(userId, user); - return AjaxResult.success("个人信息更新成功"); - } -} diff --git a/src/main/java/com/bruce/sams/controller/sms/CollegeController.java b/src/main/java/com/bruce/sams/controller/sms/CollegeController.java new file mode 100644 index 00000000..80f49104 --- /dev/null +++ b/src/main/java/com/bruce/sams/controller/sms/CollegeController.java @@ -0,0 +1,137 @@ +package com.bruce.sams.controller.sms; + +import com.bruce.sams.domain.sms.College; +import com.bruce.sams.domain.sms.CollegeLeader; +import com.bruce.sams.service.CollegeLeaderService; +import com.bruce.sams.service.CollegeService; +import com.bruce.sams.common.utils.AjaxResult; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; +import org.springframework.security.access.prepost.PreAuthorize; + + +import java.util.List; + +/** + * 学院管理控制器(校级 & 院级权限分类) + */ +@RestController +@RequestMapping("/api/admin/college") +public class CollegeController { + + @Autowired + private CollegeService collegeService; + + @Autowired + private CollegeLeaderService collegeLeaderService; + + /** + * 校级管理员:添加学院 + */ + @PreAuthorize("hasRole('ADMIN') or hasRole('COLLEGE_ADMIN')") + @PostMapping("/add") + public AjaxResult addCollege(@RequestBody College college) { + collegeService.addCollege(college); + return AjaxResult.success("学院添加成功"); + } + + /** + * 校级管理员:更新学院信息 + */ + @PreAuthorize("hasRole('ADMIN') or hasRole('COLLEGE_ADMIN')") + @PutMapping("/update") + public AjaxResult updateCollege(@RequestBody College college) { + collegeService.updateCollege(college); + return AjaxResult.success("学院更新成功"); + } + + /** + * 校级管理员:删除学院 + */ + @PreAuthorize("hasRole('ADMIN') or hasRole('COLLEGE_ADMIN')") + @DeleteMapping("/delete/{collegeId}") + public AjaxResult deleteCollege(@PathVariable Long collegeId) { + collegeService.deleteCollege(collegeId); + return AjaxResult.success("学院删除成功"); + } + + /** + * 校级管理员:获取学院详情 + */ + @PreAuthorize("hasRole('ADMIN') or hasRole('COLLEGE_ADMIN')") + @GetMapping("/{collegeId}") + public AjaxResult getCollegeById(@PathVariable Long collegeId) { + return AjaxResult.success(collegeService.getCollegeById(collegeId)); + } + + /** + * 院级管理员:获取所属学院信息 + */ + @PreAuthorize("hasRole('DEPARTMENT_ADMIN')") + @GetMapping("/my-college") + public AjaxResult getMyCollege(@RequestParam Long userId) { + College myCollege = collegeService.getCollegeById(userId); // 这里可以改为通过 `userId` 查询学院 + return AjaxResult.success(myCollege); + } + + /** + * 校级管理员 & 院级管理员:查询学院列表(校级查询所有,院级只能查自己的) + */ + @PreAuthorize("hasRole('ADMIN') or hasRole('COLLEGE_ADMIN') or hasRole('DEPARTMENT_ADMIN')") + @GetMapping("/list") + public AjaxResult listColleges(@RequestParam(required = false) String keyword, @RequestParam Long userId) { + if (userHasRole("ADMIN") || userHasRole("COLLEGE_ADMIN")) { + return AjaxResult.success(collegeService.listColleges(keyword)); + } else if (userHasRole("DEPARTMENT_ADMIN")) { + College myCollege = collegeService.getCollegeById(userId); // 查询自己所属学院 + return AjaxResult.success(List.of(myCollege)); + } + return AjaxResult.error("无权限"); + } + + /** + * 校级管理员:指派学院负责人 + */ + @PreAuthorize("hasRole('ADMIN') or hasRole('COLLEGE_ADMIN')") + @PostMapping("/assign") + public AjaxResult assignLeader(@RequestParam Long collegeId, @RequestParam Long userId) { + collegeLeaderService.assignLeader(collegeId, userId); + return AjaxResult.success("负责人指派成功"); + } + + /** + * 校级管理员:移除学院负责人 + */ + @PreAuthorize("hasRole('ADMIN') or hasRole('COLLEGE_ADMIN')") + @DeleteMapping("/remove") + public AjaxResult removeLeader(@RequestParam Long collegeId, @RequestParam Long userId) { + collegeLeaderService.removeLeader(collegeId, userId); + return AjaxResult.success("负责人移除成功"); + } + + /** + * 校级 & 院级管理员:获取学院负责人 + */ + @PreAuthorize("hasRole('ADMIN') or hasRole('COLLEGE_ADMIN') or hasRole('DEPARTMENT_ADMIN')") + @GetMapping("/{collegeId}") + public AjaxResult getLeader(@PathVariable Long collegeId, @RequestParam Long userId) { + if (userHasRole("ADMIN") || userHasRole("COLLEGE_ADMIN")) { + return AjaxResult.success(collegeLeaderService.getLeaderByCollegeId(collegeId)); + } else if (userHasRole("DEPARTMENT_ADMIN")) { + CollegeLeader myLeader = collegeLeaderService.getLeaderByCollegeId(userId); // 只能查询自己学院的负责人 + return AjaxResult.success(myLeader); + } + return AjaxResult.error("无权限"); + } + + /** + * 判断当前用户是否具有指定角色 + */ + private boolean userHasRole(String role) { + return org.springframework.security.core.context.SecurityContextHolder.getContext() + .getAuthentication() + .getAuthorities() + .stream() + .anyMatch(auth -> auth.getAuthority().equals("ROLE_" + role)); + } +} diff --git a/src/main/java/com/bruce/sams/controller/sys/AdminUserController.java b/src/main/java/com/bruce/sams/controller/sys/AdminUserController.java new file mode 100644 index 00000000..c49e9a68 --- /dev/null +++ b/src/main/java/com/bruce/sams/controller/sys/AdminUserController.java @@ -0,0 +1,91 @@ +package com.bruce.sams.controller.sys; + +import com.bruce.sams.domain.sys.User; +import com.bruce.sams.service.UserService; +import com.bruce.sams.common.utils.AjaxResult; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * 管理端 - 用户管理控制器 + */ +@RestController +@RequestMapping("/api/admin/user") +public class AdminUserController { + + @Autowired + private UserService userService; + + /** + * 批量导入用户 + * + * @param users 用户列表 + * @return AjaxResult + */ + @PostMapping("/import") + public AjaxResult importUsers(@RequestBody List users) { + userService.importUsers(users); + return AjaxResult.success("用户导入成功"); + } + + /** + * 查询用户列表(支持关键字搜索) + * + * @param keyword 关键字(用户名、学号、邮箱) + * @return AjaxResult + */ + @GetMapping("/list") + public AjaxResult listUsers(@RequestParam(required = false) String keyword) { + return AjaxResult.success(userService.listUsers(keyword)); + } + + /** + * 管理员更新用户信息(角色、状态、密码) + * + * @param user 用户对象 + * @return AjaxResult + */ + @PutMapping("/update") + public AjaxResult updateUser(@RequestBody User user) { + userService.updateUser(user); + return AjaxResult.success("用户信息更新成功"); + } + + /** + * 管理员重置用户密码(默认123456) + * + * @param userId 用户ID + * @return AjaxResult + */ + @PutMapping("/reset-password/{userId}") + public AjaxResult resetPassword(@PathVariable Long userId) { + userService.resetPassword(userId); + return AjaxResult.success("密码已重置为 123456"); + } + + /** + * 管理员封禁用户 + * + * @param userId 用户ID + * @return AjaxResult + */ + @PutMapping("/ban/{userId}") + public AjaxResult banUser(@PathVariable Long userId) { + userService.banUser(userId); + return AjaxResult.success("用户已封禁"); + } + + /** + * 管理员删除用户 + * + * @param userId 用户ID + * @return AjaxResult + */ + @DeleteMapping("/{userId}") + public AjaxResult deleteUser(@PathVariable Long userId) { + userService.deleteUser(userId); + return AjaxResult.success("用户已删除"); + } +} diff --git a/src/main/java/com/bruce/sams/controller/sys/UserController.java b/src/main/java/com/bruce/sams/controller/sys/UserController.java new file mode 100644 index 00000000..d0e227fe --- /dev/null +++ b/src/main/java/com/bruce/sams/controller/sys/UserController.java @@ -0,0 +1,56 @@ +package com.bruce.sams.controller.sys; + +import com.bruce.sams.domain.sys.User; +import com.bruce.sams.service.UserService; +import com.bruce.sams.common.utils.AjaxResult; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +/** + * 用户端 - 个人信息管理控制器 + */ +@RestController +@RequestMapping("/api/user") +public class UserController { + + @Autowired + private UserService userService; + + /** + * 用户修改密码 + * + * @param userId 用户ID + * @param oldPassword 旧密码 + * @param newPassword 新密码 + * @return AjaxResult + */ + @PutMapping("/change-password") + public AjaxResult changePassword(@RequestParam Long userId, @RequestParam String oldPassword, @RequestParam String newPassword) { + userService.changePassword(userId, oldPassword, newPassword); + return AjaxResult.success("密码修改成功"); + } + + /** + * 用户修改个人信息(昵称、邮箱、头像) + * + * @param userId 用户ID + * @param updatedUser 用户提交的新信息(昵称、邮箱、头像) + * @return AjaxResult + */ + @PutMapping("/profile") + public AjaxResult updateProfile(@RequestParam Long userId, @RequestBody User updatedUser) { + userService.updateProfile(userId, updatedUser); + return AjaxResult.success("个人信息更新成功"); + } + + /** + * 获取用户详情(查看个人信息) + * + * @param userId 用户ID + * @return AjaxResult + */ + @GetMapping("/{userId}") + public AjaxResult getUserProfile(@PathVariable Long userId) { + return AjaxResult.success(userService.getUserProfile(userId)); + } +} diff --git a/src/main/java/com/bruce/sams/domain/sms/Club.java b/src/main/java/com/bruce/sams/domain/sms/Club.java new file mode 100644 index 00000000..ddbf7d82 --- /dev/null +++ b/src/main/java/com/bruce/sams/domain/sms/Club.java @@ -0,0 +1,104 @@ +package com.bruce.sams.domain.sms; + +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.util.Date; +import lombok.Data; + +/** + * 社团表 + * @TableName sms_club + */ +@TableName(value ="sms_club") +@Data +public class Club { + /** + * 社团ID + */ + @TableId(type = IdType.AUTO) + private Long clubId; + + /** + * 社团名称 + */ + private String clubName; + + /** + * 社团简介 + */ + private String description; + + /** + * 社团类型 + */ + private Object category; + + /** + * 所属院系 + */ + private Long collegeId; + + /** + * 负责人ID + */ + private Long leaderId; + + /** + * 创建时间 + */ + private Date createdAt; + + @Override + public boolean equals(Object that) { + if (this == that) { + return true; + } + if (that == null) { + return false; + } + if (getClass() != that.getClass()) { + return false; + } + Club other = (Club) that; + return (this.getClubId() == null ? other.getClubId() == null : this.getClubId().equals(other.getClubId())) + && (this.getClubName() == null ? other.getClubName() == null : this.getClubName().equals(other.getClubName())) + && (this.getDescription() == null ? other.getDescription() == null : this.getDescription().equals(other.getDescription())) + && (this.getCategory() == null ? other.getCategory() == null : this.getCategory().equals(other.getCategory())) + && (this.getCollegeId() == null ? other.getCollegeId() == null : this.getCollegeId().equals(other.getCollegeId())) + && (this.getLeaderId() == null ? other.getLeaderId() == null : this.getLeaderId().equals(other.getLeaderId())) + && (this.getCreatedAt() == null ? other.getCreatedAt() == null : this.getCreatedAt().equals(other.getCreatedAt())); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((getClubId() == null) ? 0 : getClubId().hashCode()); + result = prime * result + ((getClubName() == null) ? 0 : getClubName().hashCode()); + result = prime * result + ((getDescription() == null) ? 0 : getDescription().hashCode()); + result = prime * result + ((getCategory() == null) ? 0 : getCategory().hashCode()); + result = prime * result + ((getCollegeId() == null) ? 0 : getCollegeId().hashCode()); + result = prime * result + ((getLeaderId() == null) ? 0 : getLeaderId().hashCode()); + result = prime * result + ((getCreatedAt() == null) ? 0 : getCreatedAt().hashCode()); + return result; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()); + sb.append(" ["); + sb.append("Hash = ").append(hashCode()); + sb.append(", clubId=").append(clubId); + sb.append(", clubName=").append(clubName); + sb.append(", description=").append(description); + sb.append(", category=").append(category); + sb.append(", collegeId=").append(collegeId); + sb.append(", leaderId=").append(leaderId); + sb.append(", createdAt=").append(createdAt); + sb.append("]"); + return sb.toString(); + } +} \ No newline at end of file diff --git a/src/main/java/com/bruce/sams/domain/sms/ClubUser.java b/src/main/java/com/bruce/sams/domain/sms/ClubUser.java new file mode 100644 index 00000000..7ca894c6 --- /dev/null +++ b/src/main/java/com/bruce/sams/domain/sms/ClubUser.java @@ -0,0 +1,96 @@ +package com.bruce.sams.domain.sms; + +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.util.Date; +import lombok.Data; + +/** + * 社团用户关系表 + * @TableName sms_club_user + */ +@TableName(value ="sms_club_user") +@Data +public class ClubUser { + /** + * ID + */ + @TableId(type = IdType.AUTO) + private Long sucId; + + /** + * 用户ID + */ + private Long userId; + + /** + * 社团ID + */ + private Long clubId; + + /** + * 角色ID + */ + private Long roleId; + + /** + * 是否活跃 + */ + private Integer isActive; + + /** + * 加入日期 + */ + private Date joinDate; + + @Override + public boolean equals(Object that) { + if (this == that) { + return true; + } + if (that == null) { + return false; + } + if (getClass() != that.getClass()) { + return false; + } + ClubUser other = (ClubUser) that; + return (this.getSucId() == null ? other.getSucId() == null : this.getSucId().equals(other.getSucId())) + && (this.getUserId() == null ? other.getUserId() == null : this.getUserId().equals(other.getUserId())) + && (this.getClubId() == null ? other.getClubId() == null : this.getClubId().equals(other.getClubId())) + && (this.getRoleId() == null ? other.getRoleId() == null : this.getRoleId().equals(other.getRoleId())) + && (this.getIsActive() == null ? other.getIsActive() == null : this.getIsActive().equals(other.getIsActive())) + && (this.getJoinDate() == null ? other.getJoinDate() == null : this.getJoinDate().equals(other.getJoinDate())); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((getSucId() == null) ? 0 : getSucId().hashCode()); + result = prime * result + ((getUserId() == null) ? 0 : getUserId().hashCode()); + result = prime * result + ((getClubId() == null) ? 0 : getClubId().hashCode()); + result = prime * result + ((getRoleId() == null) ? 0 : getRoleId().hashCode()); + result = prime * result + ((getIsActive() == null) ? 0 : getIsActive().hashCode()); + result = prime * result + ((getJoinDate() == null) ? 0 : getJoinDate().hashCode()); + return result; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()); + sb.append(" ["); + sb.append("Hash = ").append(hashCode()); + sb.append(", sucId=").append(sucId); + sb.append(", userId=").append(userId); + sb.append(", clubId=").append(clubId); + sb.append(", roleId=").append(roleId); + sb.append(", isActive=").append(isActive); + sb.append(", joinDate=").append(joinDate); + sb.append("]"); + return sb.toString(); + } +} \ No newline at end of file diff --git a/src/main/java/com/bruce/sams/domain/sms/College.java b/src/main/java/com/bruce/sams/domain/sms/College.java new file mode 100644 index 00000000..2c53cec3 --- /dev/null +++ b/src/main/java/com/bruce/sams/domain/sms/College.java @@ -0,0 +1,88 @@ +package com.bruce.sams.domain.sms; + +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.util.Date; +import lombok.Data; + +/** + * 高校及院系表 + * @TableName sms_college + */ +@TableName(value ="sms_college") +@Data +public class College { + /** + * 院系ID + */ + @TableId(type = IdType.AUTO) + private Long collegeId; + + /** + * 名称(高校或院系) + */ + private String collegeName; + + /** + * 父院系ID(高校此值为空) + */ + private Long parentId; + + /** + * 邮箱 + */ + private String email; + + /** + * 创建时间 + */ + private Date createdAt; + + @Override + public boolean equals(Object that) { + if (this == that) { + return true; + } + if (that == null) { + return false; + } + if (getClass() != that.getClass()) { + return false; + } + College other = (College) that; + return (this.getCollegeId() == null ? other.getCollegeId() == null : this.getCollegeId().equals(other.getCollegeId())) + && (this.getCollegeName() == null ? other.getCollegeName() == null : this.getCollegeName().equals(other.getCollegeName())) + && (this.getParentId() == null ? other.getParentId() == null : this.getParentId().equals(other.getParentId())) + && (this.getEmail() == null ? other.getEmail() == null : this.getEmail().equals(other.getEmail())) + && (this.getCreatedAt() == null ? other.getCreatedAt() == null : this.getCreatedAt().equals(other.getCreatedAt())); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((getCollegeId() == null) ? 0 : getCollegeId().hashCode()); + result = prime * result + ((getCollegeName() == null) ? 0 : getCollegeName().hashCode()); + result = prime * result + ((getParentId() == null) ? 0 : getParentId().hashCode()); + result = prime * result + ((getEmail() == null) ? 0 : getEmail().hashCode()); + result = prime * result + ((getCreatedAt() == null) ? 0 : getCreatedAt().hashCode()); + return result; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()); + sb.append(" ["); + sb.append("Hash = ").append(hashCode()); + sb.append(", collegeId=").append(collegeId); + sb.append(", collegeName=").append(collegeName); + sb.append(", parentId=").append(parentId); + sb.append(", email=").append(email); + sb.append(", createdAt=").append(createdAt); + sb.append("]"); + return sb.toString(); + } +} \ No newline at end of file diff --git a/src/main/java/com/bruce/sams/domain/sms/CollegeLeader.java b/src/main/java/com/bruce/sams/domain/sms/CollegeLeader.java new file mode 100644 index 00000000..2bea15b2 --- /dev/null +++ b/src/main/java/com/bruce/sams/domain/sms/CollegeLeader.java @@ -0,0 +1,73 @@ +package com.bruce.sams.domain.sms; + +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.util.Date; +import lombok.Data; + +/** + * 院系负责人表 + * @TableName sms_college_leader + */ +@TableName(value ="sms_college_leader") +@Data +public class CollegeLeader { + /** + * 院系ID + */ + @TableId + private Long collegeId; + + /** + * 负责人ID + */ + @TableId + private Long userId; + + /** + * 指派时间 + */ + private Date assignedAt; + + @Override + public boolean equals(Object that) { + if (this == that) { + return true; + } + if (that == null) { + return false; + } + if (getClass() != that.getClass()) { + return false; + } + CollegeLeader other = (CollegeLeader) that; + return (this.getCollegeId() == null ? other.getCollegeId() == null : this.getCollegeId().equals(other.getCollegeId())) + && (this.getUserId() == null ? other.getUserId() == null : this.getUserId().equals(other.getUserId())) + && (this.getAssignedAt() == null ? other.getAssignedAt() == null : this.getAssignedAt().equals(other.getAssignedAt())); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((getCollegeId() == null) ? 0 : getCollegeId().hashCode()); + result = prime * result + ((getUserId() == null) ? 0 : getUserId().hashCode()); + result = prime * result + ((getAssignedAt() == null) ? 0 : getAssignedAt().hashCode()); + return result; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()); + sb.append(" ["); + sb.append("Hash = ").append(hashCode()); + sb.append(", collegeId=").append(collegeId); + sb.append(", userId=").append(userId); + sb.append(", assignedAt=").append(assignedAt); + sb.append("]"); + return sb.toString(); + } +} \ No newline at end of file diff --git a/src/main/java/com/bruce/sams/mapper/ClubMapper.java b/src/main/java/com/bruce/sams/mapper/ClubMapper.java new file mode 100644 index 00000000..dd5a0d50 --- /dev/null +++ b/src/main/java/com/bruce/sams/mapper/ClubMapper.java @@ -0,0 +1,18 @@ +package com.bruce.sams.mapper; + +import com.bruce.sams.domain.sms.Club; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** +* @author bruce +* @description 针对表【sms_club(社团表)】的数据库操作Mapper +* @createDate 2025-02-19 20:18:22 +* @Entity com.bruce.sams.domain.sms.Club +*/ +public interface ClubMapper extends BaseMapper { + +} + + + + diff --git a/src/main/java/com/bruce/sams/mapper/ClubUserMapper.java b/src/main/java/com/bruce/sams/mapper/ClubUserMapper.java new file mode 100644 index 00000000..9c0f3da1 --- /dev/null +++ b/src/main/java/com/bruce/sams/mapper/ClubUserMapper.java @@ -0,0 +1,18 @@ +package com.bruce.sams.mapper; + +import com.bruce.sams.domain.sms.ClubUser; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** +* @author bruce +* @description 针对表【sms_club_user(社团用户关系表)】的数据库操作Mapper +* @createDate 2025-02-19 20:18:31 +* @Entity com.bruce.sams.domain.sms.ClubUser +*/ +public interface ClubUserMapper extends BaseMapper { + +} + + + + diff --git a/src/main/java/com/bruce/sams/mapper/CollegeLeaderMapper.java b/src/main/java/com/bruce/sams/mapper/CollegeLeaderMapper.java new file mode 100644 index 00000000..c8df93ac --- /dev/null +++ b/src/main/java/com/bruce/sams/mapper/CollegeLeaderMapper.java @@ -0,0 +1,18 @@ +package com.bruce.sams.mapper; + +import com.bruce.sams.domain.sms.CollegeLeader; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** +* @author bruce +* @description 针对表【sms_college_leader(院系负责人表)】的数据库操作Mapper +* @createDate 2025-02-19 20:18:55 +* @Entity com.bruce.sams.domain.sms.CollegeLeader +*/ +public interface CollegeLeaderMapper extends BaseMapper { + +} + + + + diff --git a/src/main/java/com/bruce/sams/mapper/CollegeMapper.java b/src/main/java/com/bruce/sams/mapper/CollegeMapper.java new file mode 100644 index 00000000..80781837 --- /dev/null +++ b/src/main/java/com/bruce/sams/mapper/CollegeMapper.java @@ -0,0 +1,18 @@ +package com.bruce.sams.mapper; + +import com.bruce.sams.domain.sms.College; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** +* @author bruce +* @description 针对表【sms_college(高校及院系表)】的数据库操作Mapper +* @createDate 2025-02-19 20:18:40 +* @Entity com.bruce.sams.domain.sms.College +*/ +public interface CollegeMapper extends BaseMapper { + +} + + + + diff --git a/src/main/java/com/bruce/sams/mapper/UserMapper.java b/src/main/java/com/bruce/sams/mapper/UserMapper.java index 37490e65..bfcdb8ef 100644 --- a/src/main/java/com/bruce/sams/mapper/UserMapper.java +++ b/src/main/java/com/bruce/sams/mapper/UserMapper.java @@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; +import org.apache.ibatis.annotations.Update; import java.util.List; @@ -28,6 +29,17 @@ public interface UserMapper extends BaseMapper { "WHERE ur.user_id = #{userId}") List findRolesByUserId(@Param("userId") Long userId); + @Update("UPDATE sys_user SET nick_name = #{nickName}, email = #{email} WHERE user_id = #{userId}") + void updateUser(@Param("userId") Long userId, @Param("nickName") String nickName, @Param("email") String email); + + @Update("UPDATE sys_user SET password = #{password} WHERE user_id = #{userId}") + void updatePassword(@Param("userId") Long userId, @Param("password") String password); + + @Update("UPDATE sys_user SET status = #{status} WHERE user_id = #{userId}") + void updateStatus(@Param("userId") Long userId, @Param("status") String status); + + @Select("SELECT * FROM sys_user WHERE user_id = #{userId}") + User getUserById(@Param("userId") Long userId); } diff --git a/src/main/java/com/bruce/sams/service/ClubService.java b/src/main/java/com/bruce/sams/service/ClubService.java new file mode 100644 index 00000000..b6420989 --- /dev/null +++ b/src/main/java/com/bruce/sams/service/ClubService.java @@ -0,0 +1,13 @@ +package com.bruce.sams.service; + +import com.bruce.sams.domain.sms.Club; +import com.baomidou.mybatisplus.extension.service.IService; + +/** +* @author bruce +* @description 针对表【sms_club(社团表)】的数据库操作Service +* @createDate 2025-02-19 20:18:22 +*/ +public interface ClubService extends IService { + +} diff --git a/src/main/java/com/bruce/sams/service/ClubUserService.java b/src/main/java/com/bruce/sams/service/ClubUserService.java new file mode 100644 index 00000000..a85d9beb --- /dev/null +++ b/src/main/java/com/bruce/sams/service/ClubUserService.java @@ -0,0 +1,13 @@ +package com.bruce.sams.service; + +import com.bruce.sams.domain.sms.ClubUser; +import com.baomidou.mybatisplus.extension.service.IService; + +/** +* @author bruce +* @description 针对表【sms_club_user(社团用户关系表)】的数据库操作Service +* @createDate 2025-02-19 20:18:31 +*/ +public interface ClubUserService extends IService { + +} diff --git a/src/main/java/com/bruce/sams/service/CollegeLeaderService.java b/src/main/java/com/bruce/sams/service/CollegeLeaderService.java new file mode 100644 index 00000000..a9296503 --- /dev/null +++ b/src/main/java/com/bruce/sams/service/CollegeLeaderService.java @@ -0,0 +1,36 @@ +package com.bruce.sams.service; + +import com.bruce.sams.domain.sms.CollegeLeader; +import com.baomidou.mybatisplus.extension.service.IService; + +/** +* @author bruce +* @description 针对表【sms_college_leader(院系负责人表)】的数据库操作Service +* @createDate 2025-02-19 20:18:55 +*/ +public interface CollegeLeaderService extends IService { + + /** + * 指派学院负责人 + * + * @param collegeId 学院ID + * @param userId 负责人用户ID + */ + void assignLeader(Long collegeId, Long userId); + + /** + * 移除学院负责人 + * + * @param collegeId 学院ID + * @param userId 负责人用户ID + */ + void removeLeader(Long collegeId, Long userId); + + /** + * 根据学院ID获取负责人 + * + * @param collegeId 学院ID + * @return 负责人对象 + */ + CollegeLeader getLeaderByCollegeId(Long collegeId); +} diff --git a/src/main/java/com/bruce/sams/service/CollegeService.java b/src/main/java/com/bruce/sams/service/CollegeService.java new file mode 100644 index 00000000..ac62292b --- /dev/null +++ b/src/main/java/com/bruce/sams/service/CollegeService.java @@ -0,0 +1,52 @@ +package com.bruce.sams.service; + +import com.bruce.sams.domain.sms.College; +import com.baomidou.mybatisplus.extension.service.IService; + +import java.util.List; + +/** +* @author bruce +* @description 针对表【sms_college(高校及院系表)】的数据库操作Service +* @createDate 2025-02-19 20:18:40 +*/ +public interface CollegeService extends IService { + + /** + * 添加学院 + * + * @param college 学院对象 + */ + void addCollege(College college); + + /** + * 更新学院信息 + * + * @param college 学院对象 + */ + void updateCollege(College college); + + /** + * 删除学院 + * + * @param collegeId 学院ID + */ + void deleteCollege(Long collegeId); + + /** + * 根据ID获取学院详情 + * + * @param collegeId 学院ID + * @return 学院对象 + */ + College getCollegeById(Long collegeId); + + /** + * 查询学院列表(支持关键字搜索) + * + * @param keyword 关键字(学院名称) + * @return 学院列表 + */ + List listColleges(String keyword); +} + diff --git a/src/main/java/com/bruce/sams/service/UserService.java b/src/main/java/com/bruce/sams/service/UserService.java index 90fad651..414e98b3 100644 --- a/src/main/java/com/bruce/sams/service/UserService.java +++ b/src/main/java/com/bruce/sams/service/UserService.java @@ -28,6 +28,28 @@ public interface UserService { */ void updateUser(User user); + /** + * 管理员重置用户密码(管理端) + * + * @param userId 用户ID + */ + void resetPassword(Long userId); + + /** + * 封禁用户(管理端) + * + * @param userId 用户ID + */ + void banUser(Long userId); + + /** + * 获取用户详情(用户端) + * + * @param userId 用户ID + * @return 用户信息 + */ + User getUserProfile(Long userId); + /** * 用户修改密码 * diff --git a/src/main/java/com/bruce/sams/service/impl/AuthServiceImpl.java b/src/main/java/com/bruce/sams/service/impl/AuthServiceImpl.java index 63e418aa..d66c787d 100644 --- a/src/main/java/com/bruce/sams/service/impl/AuthServiceImpl.java +++ b/src/main/java/com/bruce/sams/service/impl/AuthServiceImpl.java @@ -8,8 +8,8 @@ import com.bruce.sams.common.exception.UserNotFoundException; import com.bruce.sams.mapper.RoleMapper; import com.bruce.sams.mapper.UserMapper; import com.bruce.sams.service.AuthService; -import com.bruce.sams.utils.PasswordUtil; -import com.bruce.sams.utils.TokenUtil; +import com.bruce.sams.common.utils.PasswordUtil; +import com.bruce.sams.common.utils.TokenUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; diff --git a/src/main/java/com/bruce/sams/service/impl/ClubServiceImpl.java b/src/main/java/com/bruce/sams/service/impl/ClubServiceImpl.java new file mode 100644 index 00000000..6395570b --- /dev/null +++ b/src/main/java/com/bruce/sams/service/impl/ClubServiceImpl.java @@ -0,0 +1,22 @@ +package com.bruce.sams.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.bruce.sams.domain.sms.Club; +import com.bruce.sams.service.ClubService; +import com.bruce.sams.mapper.ClubMapper; +import org.springframework.stereotype.Service; + +/** +* @author bruce +* @description 针对表【sms_club(社团表)】的数据库操作Service实现 +* @createDate 2025-02-19 20:18:22 +*/ +@Service +public class ClubServiceImpl extends ServiceImpl + implements ClubService{ + +} + + + + diff --git a/src/main/java/com/bruce/sams/service/impl/ClubUserServiceImpl.java b/src/main/java/com/bruce/sams/service/impl/ClubUserServiceImpl.java new file mode 100644 index 00000000..61c85a1a --- /dev/null +++ b/src/main/java/com/bruce/sams/service/impl/ClubUserServiceImpl.java @@ -0,0 +1,22 @@ +package com.bruce.sams.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.bruce.sams.domain.sms.ClubUser; +import com.bruce.sams.service.ClubUserService; +import com.bruce.sams.mapper.ClubUserMapper; +import org.springframework.stereotype.Service; + +/** +* @author bruce +* @description 针对表【sms_club_user(社团用户关系表)】的数据库操作Service实现 +* @createDate 2025-02-19 20:18:31 +*/ +@Service +public class ClubUserServiceImpl extends ServiceImpl + implements ClubUserService{ + +} + + + + diff --git a/src/main/java/com/bruce/sams/service/impl/CollegeLeaderServiceImpl.java b/src/main/java/com/bruce/sams/service/impl/CollegeLeaderServiceImpl.java new file mode 100644 index 00000000..6f2a9c33 --- /dev/null +++ b/src/main/java/com/bruce/sams/service/impl/CollegeLeaderServiceImpl.java @@ -0,0 +1,47 @@ +package com.bruce.sams.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.bruce.sams.domain.sms.CollegeLeader; +import com.bruce.sams.service.CollegeLeaderService; +import com.bruce.sams.mapper.CollegeLeaderMapper; +import org.springframework.stereotype.Service; + +import java.util.Date; + +/** +* @author bruce +* @description 针对表【sms_college_leader(院系负责人表)】的数据库操作Service实现 +* @createDate 2025-02-19 20:18:55 +*/ +@Service +public class CollegeLeaderServiceImpl extends ServiceImpl implements CollegeLeaderService { + + /** + * 指派学院负责人 + */ + @Override + public void assignLeader(Long collegeId, Long userId) { + CollegeLeader leader = new CollegeLeader(); + leader.setCollegeId(collegeId); + leader.setUserId(userId); + leader.setAssignedAt(new Date(System.currentTimeMillis())); // 记录指派时间 + + this.save(leader); + } + + /** + * 移除学院负责人 + */ + @Override + public void removeLeader(Long collegeId, Long userId) { + this.removeById(collegeId); + } + + /** + * 根据学院ID获取负责人 + */ + @Override + public CollegeLeader getLeaderByCollegeId(Long collegeId) { + return this.getById(collegeId); + } +} \ No newline at end of file diff --git a/src/main/java/com/bruce/sams/service/impl/CollegeServiceImpl.java b/src/main/java/com/bruce/sams/service/impl/CollegeServiceImpl.java new file mode 100644 index 00000000..f3fcdbbf --- /dev/null +++ b/src/main/java/com/bruce/sams/service/impl/CollegeServiceImpl.java @@ -0,0 +1,66 @@ +package com.bruce.sams.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.bruce.sams.domain.sms.College; +import com.bruce.sams.service.CollegeService; +import com.bruce.sams.mapper.CollegeMapper; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** +* @author bruce +* @description 针对表【sms_college(高校及院系表)】的数据库操作Service实现 +* @createDate 2025-02-19 20:18:40 +*/ +@Service +public class CollegeServiceImpl extends ServiceImpl implements CollegeService { + + /** + * 添加学院 + */ + @Override + public void addCollege(College college) { + this.save(college); + } + + /** + * 更新学院信息 + */ + @Override + public void updateCollege(College college) { + this.updateById(college); + } + + /** + * 删除学院 + */ + @Override + public void deleteCollege(Long collegeId) { + this.removeById(collegeId); + } + + /** + * 根据ID获取学院详情 + */ + @Override + public College getCollegeById(Long collegeId) { + return this.getById(collegeId); + } + + /** + * 查询学院列表(支持关键字搜索) + */ + @Override + public List listColleges(String keyword) { + LambdaQueryWrapper query = new LambdaQueryWrapper<>(); + if (keyword != null && !keyword.isEmpty()) { + query.like(College::getCollegeName, keyword); + } + return this.list(query); + } +} + + + diff --git a/src/main/java/com/bruce/sams/service/impl/UserServiceImpl.java b/src/main/java/com/bruce/sams/service/impl/UserServiceImpl.java index 837ef81b..57f8acff 100644 --- a/src/main/java/com/bruce/sams/service/impl/UserServiceImpl.java +++ b/src/main/java/com/bruce/sams/service/impl/UserServiceImpl.java @@ -7,7 +7,7 @@ import com.bruce.sams.common.exception.PasswordIncorrectException; import com.bruce.sams.common.exception.UserNotFoundException; import com.bruce.sams.mapper.UserMapper; import com.bruce.sams.service.UserService; -import com.bruce.sams.utils.PasswordUtil; +import com.bruce.sams.common.utils.PasswordUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -21,19 +21,21 @@ public class UserServiceImpl extends ServiceImpl private UserMapper userMapper; /** - * 批量导入用户 + * 批量导入用户(管理端) * * @param users 用户列表 */ public void importUsers(List users) { for (User user : users) { - // 加密用户密码(默认密码123456) - if (user.getPassword() == null || user.getPassword().isEmpty()) { - user.setPassword(PasswordUtil.encode("123456")); // 默认密码 - } else { - user.setPassword(PasswordUtil.encode(user.getPassword())); + // 检查用户是否存在 + User existUser = userMapper.selectOne( + new LambdaQueryWrapper().eq(User::getSchoolId, user.getSchoolId())); + + if (existUser == null) { + // 加密默认密码 123456 + user.setPassword(PasswordUtil.encode("123456")); + userMapper.insert(user); } - userMapper.insert(user); } } @@ -54,7 +56,7 @@ public class UserServiceImpl extends ServiceImpl } /** - * 更新用户信息(角色、状态、密码) + * 更新用户信息 * * @param user 用户对象 */ @@ -68,14 +70,45 @@ public class UserServiceImpl extends ServiceImpl /** - * 用户修改密码 + * 管理员重置用户密码(管理端) + * + * @param userId 用户ID + */ + public void resetPassword(Long userId) { + User user = userMapper.selectById(userId); + if (user == null) { + throw new UserNotFoundException(); + } + + // 设定默认密码 123456 + user.setPassword(PasswordUtil.encode("123456")); + userMapper.updateById(user); + } + + /** + * 封禁用户(管理端) + * + * @param userId 用户ID + */ + public void banUser(Long userId) { + User user = userMapper.selectById(userId); + if (user == null) { + throw new UserNotFoundException(); + } + + // 更新状态为 banned + user.setStatus("banned"); + userMapper.updateById(user); + } + + /** + * 用户修改密码(用户端) * * @param userId 用户ID * @param oldPassword 旧密码 * @param newPassword 新密码 */ public void changePassword(Long userId, String oldPassword, String newPassword) { - // 获取用户 User user = userMapper.selectById(userId); if (user == null) { throw new UserNotFoundException(); @@ -86,15 +119,15 @@ public class UserServiceImpl extends ServiceImpl throw new PasswordIncorrectException(); } - // 更新新密码(加密存储) + // 加密新密码 user.setPassword(PasswordUtil.encode(newPassword)); userMapper.updateById(user); } /** - * 用户修改个人信息(昵称、邮箱、头像) + * 用户修改个人信息(用户端) * - * @param userId 用户ID(从 JWT 获取) + * @param userId 用户ID * @param updatedUser 用户提交的新信息(昵称、邮箱、头像) */ public void updateProfile(Long userId, User updatedUser) { @@ -111,6 +144,20 @@ public class UserServiceImpl extends ServiceImpl userMapper.updateById(user); } + /** + * 获取用户详情(用户端) + * + * @param userId 用户ID + * @return 用户信息 + */ + public User getUserProfile(Long userId) { + User user = userMapper.selectById(userId); + if (user == null) { + throw new UserNotFoundException(); + } + return user; + } + /** * 删除用户 * diff --git a/src/main/resources/mapper/ClubMapper.xml b/src/main/resources/mapper/ClubMapper.xml new file mode 100644 index 00000000..ef4affcd --- /dev/null +++ b/src/main/resources/mapper/ClubMapper.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + club_id,club_name,description,category,college_id,leader_id, + created_at + + diff --git a/src/main/resources/mapper/ClubUserMapper.xml b/src/main/resources/mapper/ClubUserMapper.xml new file mode 100644 index 00000000..e168228b --- /dev/null +++ b/src/main/resources/mapper/ClubUserMapper.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + suc_id,user_id,club_id,role_id,is_active,join_date + + diff --git a/src/main/resources/mapper/CollegeLeaderMapper.xml b/src/main/resources/mapper/CollegeLeaderMapper.xml new file mode 100644 index 00000000..cc67deb1 --- /dev/null +++ b/src/main/resources/mapper/CollegeLeaderMapper.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + college_id,user_id,assigned_at + + diff --git a/src/main/resources/mapper/CollegeMapper.xml b/src/main/resources/mapper/CollegeMapper.xml new file mode 100644 index 00000000..534e9c5b --- /dev/null +++ b/src/main/resources/mapper/CollegeMapper.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + college_id,college_name,parent_id,email,created_at + + diff --git a/src/test/java/com/bruce/sams/SamsApplicationTests.java b/src/test/java/com/bruce/sams/SamsApplicationTests.java index ca022015..dd6bf643 100644 --- a/src/test/java/com/bruce/sams/SamsApplicationTests.java +++ b/src/test/java/com/bruce/sams/SamsApplicationTests.java @@ -1,6 +1,6 @@ package com.bruce.sams; -import com.bruce.sams.utils.PasswordUtil; +import com.bruce.sams.common.utils.PasswordUtil; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest;