├── src ├── main │ ├── resources │ │ └── mapper │ │ │ ├── CourseMapper.xml │ │ │ ├── LockerMapper.xml │ │ │ ├── RepairMapper.xml │ │ │ ├── RoleMapper.xml │ │ │ ├── InstrumentMapper.xml │ │ │ ├── UserMapper.xml │ │ │ └── MenuMapper.xml │ └── java │ │ └── com │ │ └── yang │ │ └── springboot │ │ ├── param │ │ ├── CourseParam.java │ │ ├── LockerUseParam.java │ │ ├── LoginParam.java │ │ ├── UserInfoParam.java │ │ ├── LockerSaveParam.java │ │ ├── vo │ │ │ ├── UserVo.java │ │ │ └── UserInfoVo.java │ │ ├── RegisterParam.java │ │ └── LoginUser.java │ │ ├── service │ │ ├── MenuService.java │ │ ├── RoleService.java │ │ ├── impl │ │ │ ├── MenuServiceImpl.java │ │ │ ├── RoleServiceImpl.java │ │ │ ├── UserDetailsServiceImpl.java │ │ │ ├── RepairServiceImpl.java │ │ │ ├── CourseServiceImpl.java │ │ │ ├── InstrumentServiceImpl.java │ │ │ ├── LockerServiceImpl.java │ │ │ └── UserServiceImpl.java │ │ ├── RepairService.java │ │ ├── CourseService.java │ │ ├── InstrumentService.java │ │ ├── LockerService.java │ │ └── UserService.java │ │ ├── mapper │ │ ├── RoleDao.java │ │ ├── CourseDao.java │ │ ├── LockerDao.java │ │ ├── RepairDao.java │ │ ├── InstrumentDao.java │ │ ├── MenuDao.java │ │ └── UserDao.java │ │ ├── controller │ │ ├── MenuController.java │ │ ├── RoleController.java │ │ ├── RepairController.java │ │ ├── CourseController.java │ │ ├── InstrumentController.java │ │ ├── UploadController.java │ │ ├── LockerController.java │ │ ├── CaptchaController.java │ │ └── UserController.java │ │ ├── common │ │ ├── Constants.java │ │ └── lang │ │ │ └── Result.java │ │ ├── SpringbootApplication.java │ │ ├── utils │ │ ├── WebUtils.java │ │ ├── UserUtils.java │ │ ├── AliOosUtils.java │ │ ├── CodeGenerator.java │ │ ├── CaptchaUtils.java │ │ ├── JwtUtils.java │ │ └── RedisCache.java │ │ ├── config │ │ ├── MyBatisPlusConfig.java │ │ ├── LocalDateTimeSerializerConfig.java │ │ ├── CaptchaConfig.java │ │ ├── RedisConfig.java │ │ ├── SwaggerConfig.java │ │ ├── FastJsonRedisSerializer.java │ │ ├── CorsConfig.java │ │ └── SecurityConfig.java │ │ ├── entity │ │ ├── Role.java │ │ ├── Menu.java │ │ ├── Repair.java │ │ ├── Course.java │ │ ├── Locker.java │ │ ├── Instrument.java │ │ └── User.java │ │ ├── handler │ │ ├── AccessDeniedHandlerImpl.java │ │ └── AuthenticationEntryPointImpl.java │ │ └── filter │ │ └── JwtAuthenticationTokenFilter.java └── test │ └── java │ └── com │ └── yang │ └── springboot │ └── SpringbootApplicationTests.java ├── .gitignore └── pom.xml /src/main/resources/mapper/CourseMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/main/resources/mapper/LockerMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/main/resources/mapper/RepairMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/main/resources/mapper/RoleMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/main/resources/mapper/InstrumentMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/param/CourseParam.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.param; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class CourseParam { 7 | 8 | private String name; 9 | 10 | private String description; 11 | 12 | private String content; 13 | 14 | private Long coachId; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/test/java/com/yang/springboot/SpringbootApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class SpringbootApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/param/LockerUseParam.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.param; 2 | 3 | import lombok.Data; 4 | 5 | import java.time.LocalDateTime; 6 | 7 | @Data 8 | public class LockerUseParam { 9 | 10 | private Long id; 11 | 12 | private Long userId; 13 | 14 | private LocalDateTime useTime; 15 | 16 | private LocalDateTime returnTime; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/service/MenuService.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.service; 2 | 3 | import com.yang.springboot.entity.Menu; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | 6 | /** 7 | *

8 | * 服务类 9 | *

10 | * 11 | * @author LambCcc 12 | * @since 2022-04-16 13 | */ 14 | public interface MenuService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/mapper/RoleDao.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.mapper; 2 | 3 | import com.yang.springboot.entity.Role; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | import org.apache.ibatis.annotations.Mapper; 6 | 7 | /** 8 | *

9 | * Mapper 接口 10 | *

11 | * 12 | * @author LambCcc 13 | * @since 2022-04-14 14 | */ 15 | @Mapper 16 | public interface RoleDao extends BaseMapper { 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/controller/MenuController.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.controller; 2 | 3 | import org.springframework.web.bind.annotation.RequestMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | /** 7 | *

8 | * 前端控制器 9 | *

10 | * 11 | * @author LambCcc 12 | * @since 2022-04-16 13 | */ 14 | @RestController 15 | @RequestMapping("/menu") 16 | public class MenuController { 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/common/Constants.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.common; 2 | 3 | public interface Constants { 4 | Integer CODE_200 = 200; 5 | Integer CODE_400 = 400; 6 | Integer CODE_401 = 401; 7 | Integer CODE_500 = 500; 8 | 9 | String VERIFY_CODE_REGISTER_ADMIN = "YangLiCcc_Admin"; 10 | String VERIFY_CODE_REGISTER_STUFF = "YangLiCcc_Stuff"; 11 | String VERIFY_CODE_REGISTER_COACH = "YangLiCcc_Coach"; 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/mapper/CourseDao.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.mapper; 2 | 3 | import com.yang.springboot.entity.Course; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | import org.apache.ibatis.annotations.Mapper; 6 | 7 | /** 8 | *

9 | * Mapper 接口 10 | *

11 | * 12 | * @author LambCcc 13 | * @since 2022-04-14 14 | */ 15 | @Mapper 16 | public interface CourseDao extends BaseMapper { 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/mapper/LockerDao.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.mapper; 2 | 3 | import com.yang.springboot.entity.Locker; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | import org.apache.ibatis.annotations.Mapper; 6 | 7 | /** 8 | *

9 | * Mapper 接口 10 | *

11 | * 12 | * @author LambCcc 13 | * @since 2022-04-14 14 | */ 15 | @Mapper 16 | public interface LockerDao extends BaseMapper { 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/mapper/RepairDao.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.mapper; 2 | 3 | import com.yang.springboot.entity.Repair; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | import org.apache.ibatis.annotations.Mapper; 6 | 7 | /** 8 | *

9 | * Mapper 接口 10 | *

11 | * 12 | * @author LambCcc 13 | * @since 2022-04-14 14 | */ 15 | @Mapper 16 | public interface RepairDao extends BaseMapper { 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/mapper/InstrumentDao.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.mapper; 2 | 3 | import com.yang.springboot.entity.Instrument; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | import org.apache.ibatis.annotations.Mapper; 6 | 7 | /** 8 | *

9 | * Mapper 接口 10 | *

11 | * 12 | * @author LambCcc 13 | * @since 2022-04-14 14 | */ 15 | @Mapper 16 | public interface InstrumentDao extends BaseMapper { 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/service/RoleService.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.service; 2 | 3 | import com.yang.springboot.common.lang.Result; 4 | import com.yang.springboot.entity.Role; 5 | import com.baomidou.mybatisplus.extension.service.IService; 6 | 7 | /** 8 | *

9 | * 服务类 10 | *

11 | * 12 | * @author LambCcc 13 | * @since 2022-04-14 14 | */ 15 | public interface RoleService extends IService { 16 | 17 | Result getRoleList(); 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/common/lang/Result.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.common.lang; 2 | 3 | import com.fasterxml.jackson.annotation.JsonInclude; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | @Data 9 | @AllArgsConstructor 10 | @NoArgsConstructor 11 | @JsonInclude(JsonInclude.Include.NON_NULL) 12 | public class Result { 13 | private Integer code; 14 | private String msg; 15 | private Object data; 16 | } 17 | -------------------------------------------------------------------------------- /src/main/resources/mapper/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 11 | 12 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/SpringbootApplication.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import springfox.documentation.oas.annotations.EnableOpenApi; 6 | 7 | @SpringBootApplication 8 | @EnableOpenApi 9 | public class SpringbootApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(SpringbootApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/mapper/MenuDao.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.mapper; 2 | 3 | import com.yang.springboot.entity.Menu; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | import org.apache.ibatis.annotations.Mapper; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | *

11 | * Mapper 接口 12 | *

13 | * 14 | * @author LambCcc 15 | * @since 2022-04-16 16 | */ 17 | @Mapper 18 | public interface MenuDao extends BaseMapper { 19 | 20 | List selectPermissionsByUserRoleId(Integer roleId); 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/param/LoginParam.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.param; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | /** 8 | * 用户登录所需的参数 9 | */ 10 | @Data 11 | @AllArgsConstructor 12 | @NoArgsConstructor 13 | public class LoginParam { 14 | 15 | private String username; // 用户名 16 | private String password; // 密码 17 | private Integer roleId; // 用户职别(权限) 18 | private String captchaCode; // 验证码 19 | private String uuid; // 随机生成的uuid 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/param/UserInfoParam.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.param; 2 | 3 | import lombok.Data; 4 | 5 | import java.time.LocalDateTime; 6 | 7 | @Data 8 | public class UserInfoParam { 9 | 10 | private String nickname; 11 | 12 | private Boolean sex; 13 | 14 | private Integer age; 15 | 16 | private String phone; 17 | 18 | private String email; 19 | 20 | private String address; 21 | 22 | private String avatarUrl; 23 | 24 | private LocalDateTime createdTime; 25 | 26 | private LocalDateTime expiredTime; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/param/LockerSaveParam.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.param; 2 | 3 | import lombok.Data; 4 | 5 | import java.time.LocalDateTime; 6 | 7 | @Data 8 | public class LockerSaveParam { 9 | 10 | private Long id; 11 | 12 | private String name; 13 | 14 | private Boolean sex; 15 | 16 | private String area; 17 | 18 | private LocalDateTime createdTime; 19 | 20 | private LocalDateTime repairTime; 21 | 22 | private LocalDateTime deletedTime; 23 | 24 | private LocalDateTime modifiedTime; 25 | 26 | private Boolean status; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/mapper/UserDao.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.mapper; 2 | 3 | import com.yang.springboot.entity.Role; 4 | import com.yang.springboot.entity.User; 5 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 6 | import com.yang.springboot.param.vo.UserVo; 7 | import org.apache.ibatis.annotations.Mapper; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | *

13 | * Mapper 接口 14 | *

15 | * 16 | * @author LambCcc 17 | * @since 2022-04-14 18 | */ 19 | @Mapper 20 | public interface UserDao extends BaseMapper { 21 | 22 | Role getRoleByUserId(Long userId); 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/service/impl/MenuServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.service.impl; 2 | 3 | import com.yang.springboot.entity.Menu; 4 | import com.yang.springboot.mapper.MenuDao; 5 | import com.yang.springboot.service.MenuService; 6 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * 服务实现类 12 | *

13 | * 14 | * @author LambCcc 15 | * @since 2022-04-16 16 | */ 17 | @Service 18 | public class MenuServiceImpl extends ServiceImpl implements MenuService { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | 35 | ### Spring Boot ### 36 | src/main/resources/application.yml 37 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/param/vo/UserVo.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.param.vo; 2 | 3 | import com.yang.springboot.entity.Role; 4 | import lombok.Data; 5 | 6 | import java.time.LocalDateTime; 7 | 8 | @Data 9 | public class UserVo { 10 | 11 | private Long id; 12 | 13 | private String username; 14 | 15 | private String nickname; 16 | 17 | private Boolean sex; 18 | 19 | private String avatarUrl; 20 | 21 | private LocalDateTime createdTime; 22 | 23 | private LocalDateTime expiredTime; 24 | 25 | private Boolean status; 26 | 27 | private Boolean isExpired; 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/service/RepairService.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.service; 2 | 3 | import com.yang.springboot.common.lang.Result; 4 | import com.yang.springboot.entity.Repair; 5 | import com.baomidou.mybatisplus.extension.service.IService; 6 | 7 | /** 8 | *

9 | * 服务类 10 | *

11 | * 12 | * @author LambCcc 13 | * @since 2022-04-14 14 | */ 15 | public interface RepairService extends IService { 16 | 17 | Result getRepairPage(Integer currentPage, Integer pageSize, String type, String name); 18 | 19 | Result insertRecord(Repair repair); 20 | 21 | Result updateRecordById(Repair repair); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/param/vo/UserInfoVo.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.param.vo; 2 | 3 | import com.yang.springboot.entity.Role; 4 | import lombok.Data; 5 | 6 | import java.time.LocalDateTime; 7 | 8 | @Data 9 | public class UserInfoVo { 10 | 11 | private Role role; 12 | 13 | private String nickname; 14 | 15 | private Boolean sex; 16 | 17 | private Integer age; 18 | 19 | private String phone; 20 | 21 | private String email; 22 | 23 | private String address; 24 | 25 | private String avatarUrl; 26 | 27 | private LocalDateTime createdTime; 28 | 29 | private LocalDateTime expiredTime; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/utils/WebUtils.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.utils; 2 | 3 | import javax.servlet.http.HttpServletResponse; 4 | import java.io.IOException; 5 | 6 | public class WebUtils { 7 | 8 | public static String renderString(HttpServletResponse response, String str) { 9 | try { 10 | response.setStatus(200); 11 | response.setContentType("application/json"); 12 | response.setCharacterEncoding("utf-8"); 13 | response.getWriter().print(str); 14 | } catch (IOException e) { 15 | e.printStackTrace(); 16 | } 17 | return null; 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/resources/mapper/MenuMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 14 | 15 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/utils/UserUtils.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.utils; 2 | 3 | import com.yang.springboot.entity.User; 4 | import com.yang.springboot.param.LoginUser; 5 | import org.springframework.security.core.Authentication; 6 | import org.springframework.security.core.context.SecurityContextHolder; 7 | 8 | public class UserUtils { 9 | 10 | public static User getUserInfo() { 11 | // 从SecurityContextHolder中获取用户信息 12 | Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); 13 | LoginUser loginUser = (LoginUser) authentication.getPrincipal(); 14 | // 获取用户的基本信息 15 | return loginUser.getUser(); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/service/CourseService.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.service; 2 | 3 | import com.yang.springboot.common.lang.Result; 4 | import com.yang.springboot.entity.Course; 5 | import com.baomidou.mybatisplus.extension.service.IService; 6 | import com.yang.springboot.param.CourseParam; 7 | 8 | /** 9 | *

10 | * 服务类 11 | *

12 | * 13 | * @author LambCcc 14 | * @since 2022-04-14 15 | */ 16 | public interface CourseService extends IService { 17 | 18 | Result getCoursePage(Integer currentPage, Integer pageSize, String coachName); 19 | 20 | Result insertCourse(CourseParam insertParam); 21 | 22 | Result updateCourse(Course course); 23 | 24 | Result deleteCourseById(Long id); 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/param/RegisterParam.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.param; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @NoArgsConstructor 9 | @AllArgsConstructor 10 | public class RegisterParam { 11 | 12 | private Integer roleId; 13 | 14 | private String username; 15 | 16 | private String nickname; 17 | 18 | private String password; 19 | 20 | private Boolean sex; 21 | 22 | private Integer age; 23 | 24 | private String phone; 25 | 26 | private String email; 27 | 28 | private String address; 29 | 30 | private String verifyCode; 31 | 32 | private String uuid; 33 | 34 | private String captchaCode; 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/service/InstrumentService.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.service; 2 | 3 | import com.yang.springboot.common.lang.Result; 4 | import com.yang.springboot.entity.Instrument; 5 | import com.baomidou.mybatisplus.extension.service.IService; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | *

11 | * 服务类 12 | *

13 | * 14 | * @author LambCcc 15 | * @since 2022-04-14 16 | */ 17 | public interface InstrumentService extends IService { 18 | 19 | Result getInstrumentPage(Integer currentPage, Integer pageSize, String name); 20 | 21 | Result getUnusedInstrument(); 22 | 23 | Result insertInstrument(Instrument instrument); 24 | 25 | Result updateInstrument(Instrument instrument); 26 | 27 | Result deleteInstrumentById(Long id); 28 | 29 | Result deleteInstrumentBatchByIds(List ids); 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/config/MyBatisPlusConfig.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.config; 2 | 3 | import com.baomidou.mybatisplus.annotation.DbType; 4 | import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; 5 | import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; 6 | import org.mybatis.spring.annotation.MapperScan; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | 10 | @Configuration 11 | @MapperScan("com.yang.springboot.mapper") 12 | public class MyBatisPlusConfig { 13 | @Bean 14 | public MybatisPlusInterceptor mybatisPlusInterceptor() { 15 | MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); 16 | interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.H2)); 17 | return interceptor; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/controller/RoleController.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.controller; 2 | 3 | import com.yang.springboot.common.lang.Result; 4 | import com.yang.springboot.service.RoleService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | /** 11 | *

12 | * 前端控制器 13 | *

14 | * 15 | * @author LambCcc 16 | * @since 2022-04-14 17 | */ 18 | @RestController 19 | @RequestMapping("/role") 20 | public class RoleController { 21 | 22 | private final RoleService roleService; 23 | 24 | @Autowired 25 | public RoleController(RoleService roleService) { 26 | this.roleService = roleService; 27 | } 28 | 29 | @GetMapping 30 | public Result getRoleList() { 31 | return roleService.getRoleList(); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/entity/Role.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableField; 5 | import com.baomidou.mybatisplus.annotation.TableId; 6 | import com.baomidou.mybatisplus.annotation.TableName; 7 | import java.io.Serializable; 8 | 9 | import lombok.Data; 10 | import lombok.Getter; 11 | import lombok.Setter; 12 | 13 | /** 14 | *

15 | * 16 | *

17 | * 18 | * @author LambCcc 19 | * @since 2022-04-14 20 | */ 21 | @Data 22 | @TableName("sys_role") 23 | public class Role implements Serializable { 24 | 25 | private static final long serialVersionUID = 1L; 26 | 27 | /** 28 | * 主键 29 | */ 30 | @TableId(value = "id", type = IdType.AUTO) 31 | private Integer id; 32 | 33 | /** 34 | * 名称 35 | */ 36 | @TableField("name") 37 | private String name; 38 | 39 | /** 40 | * 类型 41 | */ 42 | @TableField("type") 43 | private String type; 44 | 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/service/LockerService.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.service; 2 | 3 | import com.yang.springboot.common.lang.Result; 4 | import com.yang.springboot.entity.Locker; 5 | import com.baomidou.mybatisplus.extension.service.IService; 6 | import com.yang.springboot.param.LockerSaveParam; 7 | import com.yang.springboot.param.LockerUseParam; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | *

13 | * 服务类 14 | *

15 | * 16 | * @author LambCcc 17 | * @since 2022-04-14 18 | */ 19 | public interface LockerService extends IService { 20 | 21 | Result getLockerPage(Integer currentPage, Integer pageSize, String name, String sex, String area); 22 | 23 | Result insertLocker(LockerSaveParam lockerSaveParam); 24 | 25 | Result deleteLockerById(Long id); 26 | 27 | Result deleteLockerBatchByIds(List ids); 28 | 29 | Result updateLocker(LockerSaveParam lockerSaveParam); 30 | 31 | Result useLockerByUserId(LockerUseParam lockerUseParam); 32 | 33 | Result getUnusedLockerList(); 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/handler/AccessDeniedHandlerImpl.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.handler; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.yang.springboot.common.lang.Result; 5 | import com.yang.springboot.utils.WebUtils; 6 | import org.springframework.http.HttpStatus; 7 | import org.springframework.security.access.AccessDeniedException; 8 | import org.springframework.security.web.access.AccessDeniedHandler; 9 | import org.springframework.stereotype.Component; 10 | 11 | import javax.servlet.ServletException; 12 | import javax.servlet.http.HttpServletRequest; 13 | import javax.servlet.http.HttpServletResponse; 14 | import java.io.IOException; 15 | 16 | @Component 17 | public class AccessDeniedHandlerImpl implements AccessDeniedHandler { 18 | 19 | @Override 20 | public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException { 21 | // 异常处理 22 | WebUtils.renderString(response, JSON.toJSONString(new Result(HttpStatus.FORBIDDEN.value(), "权限不足!", null))); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/handler/AuthenticationEntryPointImpl.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.handler; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.yang.springboot.common.lang.Result; 5 | import com.yang.springboot.utils.WebUtils; 6 | import org.springframework.http.HttpStatus; 7 | import org.springframework.security.core.AuthenticationException; 8 | import org.springframework.security.web.AuthenticationEntryPoint; 9 | import org.springframework.stereotype.Component; 10 | 11 | import javax.servlet.ServletException; 12 | import javax.servlet.http.HttpServletRequest; 13 | import javax.servlet.http.HttpServletResponse; 14 | import java.io.IOException; 15 | 16 | @Component 17 | public class AuthenticationEntryPointImpl implements AuthenticationEntryPoint { 18 | @Override 19 | public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { 20 | // 异常处理 21 | WebUtils.renderString(response, JSON.toJSONString(new Result(HttpStatus.UNAUTHORIZED.value(), "认证失败,请检查是否登录!", null))); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/config/LocalDateTimeSerializerConfig.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.config; 2 | 3 | import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; 4 | import org.springframework.beans.factory.annotation.Value; 5 | import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | import java.time.LocalDateTime; 10 | import java.time.format.DateTimeFormatter; 11 | 12 | /** 13 | * 全局时间格式化 14 | * 将项目中的LocalDateTime类型进行时间格式化 15 | */ 16 | @Configuration 17 | public class LocalDateTimeSerializerConfig { 18 | 19 | @Value("${spring.jackson.date-format:yyyy-MM-dd HH:mm:ss}") 20 | private String pattern; 21 | 22 | @Bean 23 | public LocalDateTimeSerializer localDateTimeSerializer() { 24 | return new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(pattern)); 25 | } 26 | 27 | @Bean 28 | public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() { 29 | return jacksonObjectMapperBuilder -> jacksonObjectMapperBuilder.serializerByType(LocalDateTime.class, localDateTimeSerializer()); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/entity/Menu.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableField; 5 | import com.baomidou.mybatisplus.annotation.TableId; 6 | import com.baomidou.mybatisplus.annotation.TableName; 7 | import java.io.Serializable; 8 | 9 | import lombok.Data; 10 | import lombok.Getter; 11 | import lombok.Setter; 12 | 13 | /** 14 | *

15 | * 16 | *

17 | * 18 | * @author LambCcc 19 | * @since 2022-04-16 20 | */ 21 | @Data 22 | @TableName("sys_menu") 23 | public class Menu implements Serializable { 24 | 25 | private static final long serialVersionUID = 1L; 26 | 27 | /** 28 | * 主键 29 | */ 30 | @TableId(value = "id", type = IdType.AUTO) 31 | private Long id; 32 | 33 | /** 34 | * 菜单名称 35 | */ 36 | @TableField("menu_name") 37 | private String menuName; 38 | 39 | /** 40 | * 权限关键字 41 | */ 42 | @TableField("permission_key") 43 | private String permissionKey; 44 | 45 | @TableField("pid") 46 | private Long pid; 47 | 48 | @TableField("menu_path") 49 | private String menuPath; 50 | 51 | @TableField("menu_icon") 52 | private String menuIcon; 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/config/CaptchaConfig.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.config; 2 | 3 | import com.google.code.kaptcha.impl.DefaultKaptcha; 4 | import com.google.code.kaptcha.util.Config; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | 8 | import java.util.Properties; 9 | 10 | @Configuration 11 | public class CaptchaConfig { 12 | @Bean 13 | public DefaultKaptcha producer() { 14 | DefaultKaptcha defaultKaptcha = new DefaultKaptcha(); 15 | Properties properties = new Properties(); 16 | properties.setProperty("kaptcha.border", "no"); 17 | properties.setProperty("kaptcha.border.color", "105,179,90"); 18 | properties.setProperty("kaptcha.textproducer.font.color", "black"); 19 | properties.setProperty("kaptcha.image.width", "110"); 20 | properties.setProperty("kaptcha.image.height", "40"); 21 | properties.setProperty("kaptcha.textproducer.font.size", "30"); 22 | properties.setProperty("kaptcha.session.key", "code"); 23 | properties.setProperty("kaptcha.textproducer.char.length", "4"); 24 | properties.setProperty("kaptcha.textproducer.font.names", "宋体,楷体,微软雅黑"); 25 | 26 | Config config = new Config(properties); 27 | defaultKaptcha.setConfig(config); 28 | 29 | return defaultKaptcha; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/config/RedisConfig.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.data.redis.connection.RedisConnectionFactory; 6 | import org.springframework.data.redis.core.RedisTemplate; 7 | import org.springframework.data.redis.serializer.StringRedisSerializer; 8 | 9 | /** 10 | * 重新定义Redis序列化规则 11 | * 将value的值转化为JSON格式 12 | */ 13 | @Configuration 14 | public class RedisConfig { 15 | 16 | @Bean 17 | @SuppressWarnings(value = { "rawtypes" }) 18 | RedisTemplate redisTemplate(RedisConnectionFactory factory) { 19 | RedisTemplate redisTemplate = new RedisTemplate<>(); 20 | redisTemplate.setConnectionFactory(factory); 21 | 22 | FastJsonRedisSerializer jsonRedisSerializer = new FastJsonRedisSerializer<>(Object.class); 23 | 24 | // 使用StringRedisSerializer来序列化和反序列化redis的key值 25 | redisTemplate.setKeySerializer(new StringRedisSerializer()); 26 | redisTemplate.setValueSerializer(jsonRedisSerializer); 27 | 28 | // Hash的key也采用StringRedisSerializer的序列化方式 29 | redisTemplate.setHashKeySerializer(new StringRedisSerializer()); 30 | redisTemplate.setHashValueSerializer(jsonRedisSerializer); 31 | 32 | return redisTemplate; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.service; 2 | 3 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 4 | import com.yang.springboot.common.lang.Result; 5 | import com.yang.springboot.entity.User; 6 | import com.baomidou.mybatisplus.extension.service.IService; 7 | import com.yang.springboot.param.LoginParam; 8 | import com.yang.springboot.param.RegisterParam; 9 | import com.yang.springboot.param.UserInfoParam; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | *

15 | * 服务类 16 | *

17 | * 18 | * @author LambCcc 19 | * @since 2022-04-14 20 | */ 21 | public interface UserService extends IService { 22 | 23 | Result getUserPage(String type, Integer currentPage, Integer pageSize, String username, String nickname, String phone); 24 | 25 | Result deleteUserById(Long id); 26 | 27 | Result deleteBatchByUserIds(List ids); 28 | 29 | Result login(LoginParam loginParam); 30 | 31 | Result logout(); 32 | 33 | Result getUserInfo(); 34 | 35 | Result updateUserInfoById(UserInfoParam userInfoParam, String token); 36 | 37 | Result insertUser(User user); 38 | 39 | Result changeUserStatus(Long id, Boolean status); 40 | 41 | Result changeUserPassword(Long id, String password); 42 | 43 | Result register(RegisterParam registerParam); 44 | 45 | List listUserIds(LambdaQueryWrapper lambdaQueryWrapper); 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/config/SwaggerConfig.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.config; 2 | 3 | import io.swagger.annotations.ApiOperation; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import springfox.documentation.builders.ApiInfoBuilder; 7 | import springfox.documentation.builders.PathSelectors; 8 | import springfox.documentation.builders.RequestHandlerSelectors; 9 | import springfox.documentation.service.ApiInfo; 10 | import springfox.documentation.service.Contact; 11 | import springfox.documentation.spi.DocumentationType; 12 | import springfox.documentation.spring.web.plugins.Docket; 13 | 14 | @Configuration 15 | public class SwaggerConfig { 16 | 17 | @Bean 18 | public Docket createRestApi() { 19 | return new Docket(DocumentationType.OAS_30) 20 | .apiInfo(apiInfo()) 21 | .enable(true) 22 | .select() 23 | .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) 24 | .paths(PathSelectors.any()) 25 | .build(); 26 | } 27 | 28 | private ApiInfo apiInfo() { 29 | return new ApiInfoBuilder() 30 | .title("YangLiCcc-Gym-System Swagger3 接口文档") 31 | .description("基于SSM框架的健身房管理系统 Spring Boot后端接口文档") 32 | .contact(new Contact("YangLiCcc", "http://yangliccc.asia", "407345329@qq.com")) 33 | .version("1.0") 34 | .build(); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/controller/RepairController.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.controller; 2 | 3 | import com.yang.springboot.common.lang.Result; 4 | import com.yang.springboot.entity.Repair; 5 | import com.yang.springboot.service.RepairService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.*; 8 | 9 | /** 10 | *

11 | * 前端控制器 12 | *

13 | * 14 | * @author LambCcc 15 | * @since 2022-04-14 16 | */ 17 | @RestController 18 | @RequestMapping("/repair") 19 | public class RepairController { 20 | 21 | private final RepairService repairService; 22 | 23 | @Autowired 24 | public RepairController(RepairService repairService) { 25 | this.repairService = repairService; 26 | } 27 | 28 | @GetMapping("/get/page") 29 | public Result getRepairPage(@RequestParam Integer currentPage, 30 | @RequestParam Integer pageSize, 31 | @RequestParam(defaultValue = "") String type, 32 | @RequestParam(defaultValue = "") String name) { 33 | return repairService.getRepairPage(currentPage, pageSize, type, name); 34 | } 35 | 36 | @PostMapping("/insert") 37 | public Result insertRepairRecord(@RequestBody Repair repair) { 38 | return repairService.insertRecord(repair); 39 | } 40 | 41 | @PostMapping("/update") 42 | public Result updateRepairRecordById(@RequestBody Repair repair) { 43 | return repairService.updateRecordById(repair); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/service/impl/RoleServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.service.impl; 2 | 3 | import com.yang.springboot.common.Constants; 4 | import com.yang.springboot.common.lang.Result; 5 | import com.yang.springboot.entity.Role; 6 | import com.yang.springboot.mapper.RoleDao; 7 | import com.yang.springboot.service.RoleService; 8 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 9 | import com.yang.springboot.utils.RedisCache; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Service; 12 | 13 | import java.util.List; 14 | import java.util.Objects; 15 | import java.util.concurrent.TimeUnit; 16 | 17 | /** 18 | *

19 | * 服务实现类 20 | *

21 | * 22 | * @author LambCcc 23 | * @since 2022-04-14 24 | */ 25 | @Service 26 | public class RoleServiceImpl extends ServiceImpl implements RoleService { 27 | 28 | private final RoleDao roleDao; 29 | 30 | private final RedisCache redisCache; 31 | 32 | @Autowired 33 | public RoleServiceImpl(RoleDao roleDao, RedisCache redisCache) { 34 | this.roleDao = roleDao; 35 | this.redisCache = redisCache; 36 | } 37 | 38 | @Override 39 | public Result getRoleList() { 40 | List list = list(); 41 | if (Objects.isNull(list)) { 42 | return new Result(Constants.CODE_500, "获取权限列表失败!", null); 43 | } 44 | redisCache.setCacheObject("RoleList:", list, 1, TimeUnit.HOURS); 45 | return new Result(Constants.CODE_200, "获取权限列表成功!", list); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/controller/CourseController.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.controller; 2 | 3 | import com.yang.springboot.common.lang.Result; 4 | import com.yang.springboot.entity.Course; 5 | import com.yang.springboot.param.CourseParam; 6 | import com.yang.springboot.service.CourseService; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.web.bind.annotation.*; 9 | 10 | /** 11 | *

12 | * 前端控制器 13 | *

14 | * 15 | * @author LambCcc 16 | * @since 2022-04-14 17 | */ 18 | @RestController 19 | @RequestMapping("/course") 20 | public class CourseController { 21 | 22 | private final CourseService courseService; 23 | 24 | @Autowired 25 | public CourseController(CourseService courseService) { 26 | this.courseService = courseService; 27 | } 28 | 29 | @GetMapping("/get/page") 30 | public Result getCoursePage(@RequestParam Integer currentPage, 31 | @RequestParam Integer pageSize, 32 | @RequestParam(defaultValue = "") String coachName) { 33 | return courseService.getCoursePage(currentPage, pageSize, coachName); 34 | } 35 | 36 | @PostMapping("/insert") 37 | public Result insertCourse(@RequestBody CourseParam insertParam) { 38 | return courseService.insertCourse(insertParam); 39 | } 40 | 41 | @PostMapping("/update") 42 | public Result updateCourse(@RequestBody Course course) { 43 | return courseService.updateCourse(course); 44 | } 45 | 46 | @PostMapping("/delete/{id}") 47 | public Result deleteCourse(@PathVariable Long id) { 48 | return courseService.deleteCourseById(id); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/config/FastJsonRedisSerializer.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.config; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.alibaba.fastjson.parser.ParserConfig; 5 | import com.alibaba.fastjson.serializer.SerializerFeature; 6 | import com.fasterxml.jackson.databind.JavaType; 7 | import com.fasterxml.jackson.databind.type.TypeFactory; 8 | import org.springframework.data.redis.serializer.RedisSerializer; 9 | import org.springframework.data.redis.serializer.SerializationException; 10 | 11 | import java.nio.charset.Charset; 12 | import java.nio.charset.StandardCharsets; 13 | 14 | public class FastJsonRedisSerializer implements RedisSerializer { 15 | 16 | public static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8; 17 | 18 | private final Class clazz; 19 | 20 | static { 21 | ParserConfig.getGlobalInstance().setAutoTypeSupport(true); 22 | } 23 | 24 | public FastJsonRedisSerializer(Class clazz) { 25 | super(); 26 | this.clazz = clazz; 27 | } 28 | 29 | @Override 30 | public byte[] serialize(T t) throws SerializationException { 31 | if (t == null) { 32 | return new byte[0]; 33 | } 34 | 35 | return JSON.toJSONString(t, SerializerFeature.WriteClassName).getBytes(DEFAULT_CHARSET); 36 | } 37 | 38 | @Override 39 | public T deserialize(byte[] bytes) throws SerializationException { 40 | if (bytes == null || bytes.length <= 0) { 41 | return null; 42 | } 43 | String str = new String(bytes, DEFAULT_CHARSET); 44 | 45 | return JSON.parseObject(str, clazz); 46 | } 47 | 48 | protected JavaType getJavaType(Class clazz) { 49 | return TypeFactory.defaultInstance().constructType(clazz); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/entity/Repair.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableField; 5 | import com.baomidou.mybatisplus.annotation.TableId; 6 | import com.baomidou.mybatisplus.annotation.TableName; 7 | import java.io.Serializable; 8 | import java.time.LocalDateTime; 9 | 10 | import lombok.Data; 11 | import lombok.Getter; 12 | import lombok.Setter; 13 | 14 | /** 15 | *

16 | * 17 | *

18 | * 19 | * @author LambCcc 20 | * @since 2022-04-14 21 | */ 22 | @Data 23 | @TableName("sys_repair") 24 | public class Repair implements Serializable { 25 | 26 | private static final long serialVersionUID = 1L; 27 | 28 | /** 29 | * 主键 30 | */ 31 | @TableId(value = "id", type = IdType.AUTO) 32 | private Long id; 33 | 34 | /** 35 | * 维修物品名称 36 | */ 37 | @TableField("name") 38 | private String name; 39 | 40 | /** 41 | * 维修物品类型 42 | */ 43 | @TableField("type") 44 | private String type; 45 | 46 | /** 47 | * 提交时间 48 | */ 49 | @TableField("submit_time") 50 | private LocalDateTime submitTime; 51 | 52 | /** 53 | * 申请维修人员 54 | */ 55 | @TableField("submit_by") 56 | private Long submitBy; 57 | 58 | /** 59 | * 维修状态 60 | */ 61 | @TableField("status") 62 | private Boolean status; 63 | 64 | /** 65 | * 维修时间 66 | */ 67 | @TableField("repair_time") 68 | private LocalDateTime repairTime; 69 | 70 | /** 71 | * 维修结束时间 72 | */ 73 | @TableField("repair_done_time") 74 | private LocalDateTime repairDoneTime; 75 | 76 | /** 77 | * 维修人员 78 | */ 79 | @TableField("repair_by") 80 | private Long repairBy; 81 | 82 | 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/service/impl/UserDetailsServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.service.impl; 2 | 3 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 4 | import com.yang.springboot.entity.User; 5 | import com.yang.springboot.mapper.MenuDao; 6 | import com.yang.springboot.mapper.UserDao; 7 | import com.yang.springboot.param.LoginUser; 8 | import org.springframework.security.core.userdetails.UserDetails; 9 | import org.springframework.security.core.userdetails.UserDetailsService; 10 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 11 | import org.springframework.stereotype.Service; 12 | 13 | import java.util.List; 14 | import java.util.Objects; 15 | 16 | @Service 17 | public class UserDetailsServiceImpl implements UserDetailsService { 18 | 19 | private final UserDao userDao; 20 | 21 | private final MenuDao menuDao; 22 | 23 | public UserDetailsServiceImpl(UserDao userDao, MenuDao menuDao) { 24 | this.userDao = userDao; 25 | this.menuDao = menuDao; 26 | } 27 | 28 | @Override 29 | public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { 30 | // 根据用户名查找id 31 | LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); 32 | lambdaQueryWrapper.eq(User::getUsername, username); 33 | lambdaQueryWrapper.eq(User::getStatus, true); 34 | User user = userDao.selectOne(lambdaQueryWrapper); 35 | if (Objects.isNull(user)) { 36 | throw new RuntimeException("登录失败"); 37 | } 38 | 39 | // 根据用户查询权限信息 添加到LoginUser中 40 | // List permKey 表示该权限可以访问的接口 41 | // 主要是后端鉴权使用的 42 | List permission = menuDao.selectPermissionsByUserRoleId(user.getRoleId()); 43 | 44 | return new LoginUser(user, permission); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/config/CorsConfig.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.web.cors.CorsConfiguration; 6 | import org.springframework.web.cors.UrlBasedCorsConfigurationSource; 7 | import org.springframework.web.filter.CorsFilter; 8 | import org.springframework.web.servlet.config.annotation.CorsRegistry; 9 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 10 | 11 | @Configuration 12 | public class CorsConfig { 13 | // 当前跨域请求最大有效时长。这里默认1天 14 | private static final long MAX_AGE = 24 * 60 * 60; 15 | 16 | @Bean 17 | public CorsFilter corsFilter() { 18 | UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); 19 | CorsConfiguration corsConfiguration = new CorsConfiguration(); 20 | corsConfiguration.addAllowedOrigin("http://localhost:8080"); // 1 设置访问源地址 21 | corsConfiguration.addAllowedHeader("*"); // 2 设置访问源请求头 22 | corsConfiguration.addAllowedMethod("*"); // 3 设置访问源请求方法 23 | corsConfiguration.setAllowCredentials(true); // 4 设置允许凭证 24 | corsConfiguration.setMaxAge(MAX_AGE); 25 | source.registerCorsConfiguration("/**", corsConfiguration); // 5 对接口配置跨域设置 26 | return new CorsFilter(source); 27 | } 28 | /*@Configuration 29 | public class SpringMvcConfig implements WebMvcConfigurer { 30 | 31 | @Override 32 | public void addCorsMappings(CorsRegistry corsRegistry) { 33 | corsRegistry.addMapping("/**") 34 | .allowedOrigins("http://localhost:8080") 35 | .allowedHeaders("*") 36 | .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") 37 | .allowCredentials(true); 38 | } 39 | 40 | }*/ 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/controller/InstrumentController.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.controller; 2 | 3 | import com.yang.springboot.common.lang.Result; 4 | import com.yang.springboot.entity.Instrument; 5 | import com.yang.springboot.service.InstrumentService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.*; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | *

13 | * 前端控制器 14 | *

15 | * 16 | * @author LambCcc 17 | * @since 2022-04-14 18 | */ 19 | @RestController 20 | @RequestMapping("/instrument") 21 | public class InstrumentController { 22 | 23 | private final InstrumentService instrumentService; 24 | 25 | @Autowired 26 | public InstrumentController(InstrumentService instrumentService) { 27 | this.instrumentService = instrumentService; 28 | } 29 | 30 | @GetMapping("/get/page") 31 | public Result getInstrumentPage(@RequestParam Integer currentPage, 32 | @RequestParam Integer pageSize, 33 | @RequestParam(defaultValue = "") String name) { 34 | 35 | return instrumentService.getInstrumentPage(currentPage, pageSize, name); 36 | } 37 | 38 | @GetMapping("/get/unused") 39 | public Result getUnusedInstrument() { 40 | return instrumentService.getUnusedInstrument(); 41 | } 42 | 43 | @PostMapping("/insert") 44 | public Result insertInstrument(@RequestBody Instrument instrument) { 45 | return instrumentService.insertInstrument(instrument); 46 | } 47 | 48 | @PostMapping("/update") 49 | public Result updateInstrument(@RequestBody Instrument instrument) { 50 | return instrumentService.updateInstrument(instrument); 51 | } 52 | 53 | @PostMapping("/delete/{id}") 54 | public Result deleteInstrumentById(@PathVariable Long id) { 55 | return instrumentService.deleteInstrumentById(id); 56 | } 57 | 58 | @PostMapping("/delete/batch/{ids}") 59 | public Result deleteInstrumentBatchByIds(@PathVariable List ids) { 60 | return instrumentService.deleteInstrumentBatchByIds(ids); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/entity/Course.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableField; 5 | import com.baomidou.mybatisplus.annotation.TableId; 6 | import com.baomidou.mybatisplus.annotation.TableName; 7 | import java.io.Serializable; 8 | import java.time.LocalDateTime; 9 | 10 | import lombok.Data; 11 | import lombok.Getter; 12 | import lombok.Setter; 13 | 14 | /** 15 | *

16 | * 17 | *

18 | * 19 | * @author LambCcc 20 | * @since 2022-04-14 21 | */ 22 | @Data 23 | @TableName("sys_course") 24 | public class Course implements Serializable { 25 | 26 | private static final long serialVersionUID = 1L; 27 | 28 | /** 29 | * 主键 30 | */ 31 | @TableId(value = "id", type = IdType.AUTO) 32 | private Long id; 33 | 34 | /** 35 | * 课程名 36 | */ 37 | @TableField("name") 38 | private String name; 39 | 40 | /** 41 | * 教练id 42 | */ 43 | @TableField("couch_id") 44 | private Long couchId; 45 | 46 | /** 47 | * 学员id 48 | */ 49 | @TableField("student_id") 50 | private Long studentId; 51 | 52 | /** 53 | * 课程描述 54 | */ 55 | @TableField("description") 56 | private String description; 57 | 58 | /** 59 | * 课程内容 60 | */ 61 | @TableField("content") 62 | private String content; 63 | 64 | /** 65 | * 创建时间 66 | */ 67 | @TableField("created_time") 68 | private LocalDateTime createdTime; 69 | 70 | /** 71 | * 修改时间 72 | */ 73 | @TableField("modified_time") 74 | private LocalDateTime modifiedTime; 75 | 76 | /** 77 | * 课程状态 78 | */ 79 | @TableField("status") 80 | private Boolean status; 81 | 82 | /** 83 | * 发布者 84 | */ 85 | @TableField("created_by") 86 | private Long createdBy; 87 | 88 | /** 89 | * 修改者 90 | */ 91 | @TableField("modified_by") 92 | private Long modifiedBy; 93 | 94 | /** 95 | * 删除时间 96 | */ 97 | @TableField("deleted_time") 98 | private LocalDateTime deletedTime; 99 | 100 | /** 101 | * 删除者 102 | */ 103 | @TableField("deleted_by") 104 | private Long deletedBy; 105 | 106 | @TableField("is_deleted") 107 | private Boolean isDeleted; 108 | 109 | 110 | } 111 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/controller/UploadController.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.controller; 2 | 3 | import cn.hutool.core.util.StrUtil; 4 | import com.yang.springboot.common.Constants; 5 | import com.yang.springboot.common.lang.Result; 6 | import com.yang.springboot.utils.AliOosUtils; 7 | import com.yang.springboot.utils.JwtUtils; 8 | import com.yang.springboot.utils.RedisCache; 9 | import io.jsonwebtoken.Claims; 10 | import io.swagger.annotations.ApiOperation; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.web.bind.annotation.*; 13 | import org.springframework.web.multipart.MultipartFile; 14 | 15 | import java.util.concurrent.TimeUnit; 16 | 17 | @RestController 18 | @RequestMapping("/upload") 19 | public class UploadController { 20 | 21 | private final AliOosUtils aliOosUtils; 22 | 23 | private final RedisCache redisCache; 24 | 25 | @Autowired 26 | public UploadController(AliOosUtils aliOosUtils, RedisCache redisCache) { 27 | this.aliOosUtils = aliOosUtils; 28 | this.redisCache = redisCache; 29 | } 30 | 31 | @ApiOperation("阿里云OOS文件上传") 32 | @PostMapping("/{type}") 33 | public Result upload(@PathVariable String type, @RequestParam MultipartFile file, @RequestHeader String token) throws Exception { 34 | String uploadUrl = aliOosUtils.upload(type, file); 35 | if (StrUtil.isNotEmpty(uploadUrl)) { 36 | Claims claims = JwtUtils.parseJWT(token); 37 | String userId = claims.getSubject(); 38 | String key = type + ": "; 39 | // 设置Redis过期时间为10min 40 | redisCache.setCacheObject(key + userId, uploadUrl, 10, TimeUnit.MINUTES); 41 | return new Result(Constants.CODE_200, "文件上传成功!", uploadUrl); 42 | } 43 | return new Result(Constants.CODE_500, "文件上传失败!", null); 44 | } 45 | 46 | @PostMapping("/test/{type}") 47 | public Result uploadTest(@PathVariable String type, @RequestParam MultipartFile file) { 48 | String uploadUrl = aliOosUtils.upload(type, file); 49 | if (StrUtil.isNotEmpty(uploadUrl)) { 50 | String key = "UploadTest" + type + ": "; 51 | // 设置Redis过期时间为10min 52 | redisCache.setCacheObject(key, uploadUrl, 10, TimeUnit.MINUTES); 53 | return new Result(Constants.CODE_200, "文件上传成功!", uploadUrl); 54 | } 55 | return new Result(Constants.CODE_500, "文件上传失败!", null); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/service/impl/RepairServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.service.impl; 2 | 3 | import cn.hutool.core.util.StrUtil; 4 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 5 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 6 | import com.yang.springboot.common.Constants; 7 | import com.yang.springboot.common.lang.Result; 8 | import com.yang.springboot.entity.Repair; 9 | import com.yang.springboot.entity.User; 10 | import com.yang.springboot.mapper.RepairDao; 11 | import com.yang.springboot.service.RepairService; 12 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 13 | import com.yang.springboot.utils.UserUtils; 14 | import org.springframework.stereotype.Service; 15 | 16 | import java.time.LocalDateTime; 17 | 18 | /** 19 | *

20 | * 服务实现类 21 | *

22 | * 23 | * @author LambCcc 24 | * @since 2022-04-14 25 | */ 26 | @Service 27 | public class RepairServiceImpl extends ServiceImpl implements RepairService { 28 | 29 | @Override 30 | public Result getRepairPage(Integer currentPage, Integer pageSize, String type, String name) { 31 | Page page = new Page<>(currentPage, pageSize); 32 | LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); 33 | if (StrUtil.isNotEmpty(type)) { 34 | lambdaQueryWrapper.like(Repair::getType, type); 35 | } 36 | if (StrUtil.isNotEmpty(name)) { 37 | lambdaQueryWrapper.like(Repair::getName, name); 38 | } 39 | 40 | return new Result(Constants.CODE_200, "获取分页信息成功!", page(page, lambdaQueryWrapper)); 41 | } 42 | 43 | @Override 44 | public Result insertRecord(Repair repair) { 45 | User user = UserUtils.getUserInfo(); 46 | repair.setSubmitBy(user.getId()); 47 | repair.setSubmitTime(LocalDateTime.now()); 48 | if (save(repair)) { 49 | return new Result(Constants.CODE_200, "新增维修记录成功!", null); 50 | } 51 | 52 | return new Result(Constants.CODE_500, "新增维修记录失败!", null); 53 | } 54 | 55 | @Override 56 | public Result updateRecordById(Repair repair) { 57 | User user = UserUtils.getUserInfo(); 58 | repair.setRepairBy(user.getId()); 59 | if (updateById(repair)) { 60 | return new Result(Constants.CODE_200, "更新维修记录成功!", null); 61 | } 62 | 63 | return new Result(Constants.CODE_500, "更新维修记录失败!", null); 64 | } 65 | 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/controller/LockerController.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.controller; 2 | 3 | import com.yang.springboot.common.lang.Result; 4 | import com.yang.springboot.param.LockerSaveParam; 5 | import com.yang.springboot.param.LockerUseParam; 6 | import com.yang.springboot.service.LockerService; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.web.bind.annotation.*; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | *

14 | * 前端控制器 15 | *

16 | * 17 | * @author LambCcc 18 | * @since 2022-04-14 19 | */ 20 | @RestController 21 | @RequestMapping("/locker") 22 | public class LockerController { 23 | 24 | private final LockerService lockerService; 25 | 26 | @Autowired 27 | public LockerController(LockerService lockerService) { 28 | this.lockerService = lockerService; 29 | } 30 | 31 | @GetMapping("/get/page") 32 | public Result getLockerPage(@RequestParam Integer currentPage, 33 | @RequestParam Integer pageSize, 34 | @RequestParam(defaultValue = "") String name, 35 | @RequestParam(defaultValue = "") String sex, 36 | @RequestParam(defaultValue = "") String area) { 37 | return lockerService.getLockerPage(currentPage, pageSize, name, sex, area); 38 | } 39 | 40 | @PostMapping("/insert") 41 | public Result insertLocker(@RequestBody LockerSaveParam lockerSaveParam) { 42 | return lockerService.insertLocker(lockerSaveParam); 43 | } 44 | 45 | @PostMapping("/delete/{id}") 46 | public Result deleteLockerById(@PathVariable Long id) { 47 | return lockerService.deleteLockerById(id); 48 | } 49 | 50 | @PostMapping("/delete/batch/{ids}") 51 | public Result deleteLockerBatchByIds(@PathVariable List ids) { 52 | return lockerService.deleteLockerBatchByIds(ids); 53 | } 54 | 55 | @PostMapping("/update") 56 | public Result updateLocker(@RequestBody LockerSaveParam lockerSaveParam) { 57 | return lockerService.updateLocker(lockerSaveParam); 58 | } 59 | 60 | @PostMapping("/get/unused") 61 | public Result getUnusedLockerList() { 62 | return lockerService.getUnusedLockerList(); 63 | } 64 | 65 | @PostMapping("/use") 66 | public Result useLockerByUserId(@RequestBody LockerUseParam lockerUseParam) { 67 | return lockerService.useLockerByUserId(lockerUseParam); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/filter/JwtAuthenticationTokenFilter.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.filter; 2 | 3 | import cn.hutool.core.util.StrUtil; 4 | import com.yang.springboot.param.LoginUser; 5 | import com.yang.springboot.utils.JwtUtils; 6 | import com.yang.springboot.utils.RedisCache; 7 | import io.jsonwebtoken.Claims; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; 10 | import org.springframework.security.core.context.SecurityContextHolder; 11 | import org.springframework.stereotype.Component; 12 | import org.springframework.web.filter.OncePerRequestFilter; 13 | 14 | import javax.servlet.FilterChain; 15 | import javax.servlet.ServletException; 16 | import javax.servlet.http.HttpServletRequest; 17 | import javax.servlet.http.HttpServletResponse; 18 | import java.io.IOException; 19 | 20 | @Component 21 | public class JwtAuthenticationTokenFilter extends OncePerRequestFilter { 22 | 23 | private final RedisCache redisCache; 24 | 25 | @Autowired 26 | public JwtAuthenticationTokenFilter(RedisCache redisCache) { 27 | this.redisCache = redisCache; 28 | } 29 | 30 | @Override 31 | protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { 32 | // 获取token 33 | String token = request.getHeader("token"); 34 | if (StrUtil.isEmpty(token)) { 35 | // 如果为空 直接放行 36 | filterChain.doFilter(request, response); 37 | // 因为没有token 所以不进行下面的解析操作 直接返回 38 | return; 39 | } 40 | 41 | // 解析token 42 | String userId = null; 43 | try { 44 | Claims claims = JwtUtils.parseJWT(token); 45 | userId = claims.getSubject(); 46 | } catch (Exception e) { 47 | e.printStackTrace(); 48 | } 49 | 50 | // 如果token解析成功 从redis中获取用户信息 51 | // 如果token解析失败 则返回错误 52 | String redisKey = "UserLogin: " + userId; 53 | LoginUser loginUser = redisCache.getCacheObject(redisKey); 54 | // 存放用户信息到SecurityContextHolder 55 | // setAuthentication需要一个Authentication对象 56 | UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(loginUser, null, loginUser.getAuthorities()); 57 | SecurityContextHolder.getContext().setAuthentication(authenticationToken); 58 | 59 | // 放行到下一个过滤器 60 | filterChain.doFilter(request, response); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/entity/Locker.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableField; 5 | import com.baomidou.mybatisplus.annotation.TableId; 6 | import com.baomidou.mybatisplus.annotation.TableName; 7 | import java.io.Serializable; 8 | import java.time.LocalDateTime; 9 | 10 | import lombok.Data; 11 | import lombok.Getter; 12 | import lombok.Setter; 13 | 14 | /** 15 | *

16 | * 17 | *

18 | * 19 | * @author LambCcc 20 | * @since 2022-04-14 21 | */ 22 | @Data 23 | @TableName("sys_locker") 24 | public class Locker implements Serializable { 25 | 26 | private static final long serialVersionUID = 1L; 27 | 28 | /** 29 | * 主键 30 | */ 31 | @TableId(value = "id", type = IdType.AUTO) 32 | private Long id; 33 | 34 | /** 35 | * 储物柜名 36 | */ 37 | @TableField("name") 38 | private String name; 39 | 40 | /** 41 | * 性别 42 | */ 43 | @TableField("sex") 44 | private Boolean sex; 45 | 46 | /** 47 | * 所在区域 48 | */ 49 | @TableField("area") 50 | private String area; 51 | 52 | /** 53 | * 创建时间 54 | */ 55 | @TableField("created_time") 56 | private LocalDateTime createdTime; 57 | 58 | /** 59 | * 维修时间 60 | */ 61 | @TableField("repair_time") 62 | private LocalDateTime repairTime; 63 | 64 | /** 65 | * 删除时间 66 | */ 67 | @TableField("deleted_time") 68 | private LocalDateTime deletedTime; 69 | 70 | @TableField("is_deleted") 71 | private Boolean isDeleted; 72 | 73 | /** 74 | * 储物柜状态 75 | */ 76 | @TableField("status") 77 | private Boolean status; 78 | 79 | /** 80 | * 借用者id 81 | */ 82 | @TableField("used_by") 83 | private Long usedBy; 84 | 85 | /** 86 | * 借用时间 87 | */ 88 | @TableField("use_time") 89 | private LocalDateTime useTime; 90 | 91 | /** 92 | * 归还时间 93 | */ 94 | @TableField("return_time") 95 | private LocalDateTime returnTime; 96 | 97 | /** 98 | * 申请维修人员id 99 | */ 100 | @TableField("submit_repair_by") 101 | private Long submitRepairBy; 102 | 103 | /** 104 | * 维修人员id 105 | */ 106 | @TableField("repair_by") 107 | private Long repairBy; 108 | 109 | @TableField("modified_time") 110 | private LocalDateTime modifiedTime; 111 | 112 | @TableField("modified_by") 113 | private Long modifiedBy; 114 | 115 | 116 | } 117 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/utils/AliOosUtils.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.utils; 2 | 3 | import cn.hutool.core.date.DateTime; 4 | import cn.hutool.core.util.IdUtil; 5 | import com.aliyun.oss.OSS; 6 | import com.aliyun.oss.OSSClientBuilder; 7 | import com.aliyun.oss.model.CannedAccessControlList; 8 | import org.springframework.beans.factory.annotation.Value; 9 | import org.springframework.stereotype.Component; 10 | import org.springframework.web.multipart.MultipartFile; 11 | 12 | import java.io.InputStream; 13 | 14 | @Component 15 | public class AliOosUtils { 16 | 17 | @Value("${aliyun.oos.file.Endpoint}") 18 | private String Endpoint; 19 | 20 | @Value("${aliyun.oos.file.AccessKeyId}") 21 | private String AccessKeyId; 22 | 23 | @Value("${aliyun.oos.file.AccessKeySecret}") 24 | private String AccessKeySecret; 25 | 26 | @Value("${aliyun.oos.file.BucketName}") 27 | private String BucketName; 28 | 29 | // 文件上传 30 | public String upload(String type, MultipartFile file) { 31 | 32 | // 文件上传地址 33 | String uploadUrl = null; 34 | try { 35 | // 判断oos实例是否存在 不存在则创建 存在则获取 36 | OSS ossClient = new OSSClientBuilder().build(Endpoint, AccessKeyId, AccessKeySecret); 37 | if (!ossClient.doesBucketExist(BucketName)) { 38 | // Bucket不存在 创建Bucket 39 | ossClient.createBucket(BucketName); 40 | // 设置Bucket的访问权限为 公共读写 41 | ossClient.setBucketAcl(BucketName, CannedAccessControlList.PublicReadWrite); 42 | } 43 | 44 | // 获取文件上传流 45 | InputStream inputStream = file.getInputStream(); 46 | // 构建文件上传路径为 日期路径 /fileType/yyyyMMdd/file 47 | String filePath = new DateTime().toString("yyyyMMdd"); 48 | // 构建文件名为 uuid.fileType 49 | String origin = file.getOriginalFilename(); 50 | String fileName = IdUtil.fastSimpleUUID(); 51 | assert origin != null; 52 | String fileType = origin.substring(origin.lastIndexOf(".")); 53 | String uploadFileName = fileName + fileType; 54 | // 上传到Bucket后的路径格式 如avatar/20220612/uuid.jpg 55 | String objectName = type + "/" + filePath + "/" + uploadFileName; 56 | 57 | // 上传文件至阿里云OOS Bucket 58 | ossClient.putObject(BucketName, objectName, inputStream); 59 | // 关闭OSSClient 60 | ossClient.shutdown(); 61 | // 获取上传地址 62 | uploadUrl = "https://" + BucketName + "." + Endpoint + "/" + objectName; 63 | } catch (Exception e) { 64 | e.printStackTrace(); 65 | } 66 | 67 | return uploadUrl; 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/utils/CodeGenerator.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.utils; 2 | 3 | import com.baomidou.mybatisplus.generator.FastAutoGenerator; 4 | import com.baomidou.mybatisplus.generator.config.OutputFile; 5 | import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine; 6 | 7 | import java.util.Collections; 8 | 9 | public class CodeGenerator { 10 | public static void main(String[] args) { 11 | fastAutoCodeGenerator(); 12 | } 13 | 14 | public static void fastAutoCodeGenerator() { 15 | FastAutoGenerator.create("jdbc:mysql://localhost:3306/gym_system", 16 | "root", 17 | "Ylc0612.") 18 | .globalConfig(builder -> { 19 | builder.author("LambCcc") // 作者 20 | .disableOpenDir() // 关闭自动打开目录 21 | .outputDir("D:\\Desktop\\GraduationDesign\\version1\\springboot\\src\\main\\java"); // 输出路径 22 | }) 23 | .packageConfig(builder -> { 24 | builder.parent("com.yang.springboot") //设置父包名 25 | .pathInfo(Collections.singletonMap(OutputFile.xml, "D:\\Desktop\\GraduationDesign\\version1\\springboot\\src\\main\\resources\\mapper")); // 设置mapper.xml生成路径 26 | }) 27 | .strategyConfig(builder -> { 28 | builder.entityBuilder() // 实体类策略配置 29 | .enableLombok() // 开启lombok模型 30 | .enableTableFieldAnnotation() // 开启生成实体类时 生成字段注解 31 | .build(); 32 | builder.mapperBuilder() // Mapper策略配置 33 | .enableMapperAnnotation() // 开启@Mapper注解 34 | .formatMapperFileName("%sDao") 35 | .build(); 36 | builder.controllerBuilder() // Controller策略配置 37 | .enableHyphenStyle() // 开启驼峰转连字符 38 | .enableRestStyle() // 开启生成@RestController控制器 39 | .build(); 40 | builder.serviceBuilder() // Service策略配置 41 | .formatServiceFileName("%sService") // 格式化service接口文件名称 XxService 42 | .formatServiceImplFileName("%sServiceImpl") // 格式化service实现类文件名称 XxServiceImpl 43 | .build(); 44 | builder.addInclude("sys_menu") // 增加表匹配 45 | .addTablePrefix("sys_", "t_"); // 增加过滤表前缀 46 | }) 47 | .templateEngine(new FreemarkerTemplateEngine()) // 使用FreeMarker引擎模板 48 | .execute(); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/entity/Instrument.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableField; 5 | import com.baomidou.mybatisplus.annotation.TableId; 6 | import com.baomidou.mybatisplus.annotation.TableName; 7 | import java.io.Serializable; 8 | import java.time.LocalDateTime; 9 | 10 | import lombok.Data; 11 | import lombok.Getter; 12 | import lombok.Setter; 13 | 14 | /** 15 | *

16 | * 17 | *

18 | * 19 | * @author LambCcc 20 | * @since 2022-04-14 21 | */ 22 | @Data 23 | @TableName("sys_instrument") 24 | public class Instrument implements Serializable { 25 | 26 | private static final long serialVersionUID = 1L; 27 | 28 | /** 29 | * 主键 30 | */ 31 | @TableId(value = "id", type = IdType.AUTO) 32 | private Long id; 33 | 34 | /** 35 | * 器械类型id 36 | */ 37 | @TableField("type_id") 38 | private Long typeId; 39 | 40 | /** 41 | * 器械名称 42 | */ 43 | @TableField("name") 44 | private String name; 45 | 46 | /** 47 | * 创建时间 48 | */ 49 | @TableField("created_time") 50 | private LocalDateTime createdTime; 51 | 52 | @TableField("created_by") 53 | private Long createdBy; 54 | 55 | /** 56 | * 维修时间 57 | */ 58 | @TableField("repair_time") 59 | private LocalDateTime repairTime; 60 | 61 | /** 62 | * 删除时间 63 | */ 64 | @TableField("deleted_time") 65 | private LocalDateTime deletedTime; 66 | 67 | @TableField("deleted_by") 68 | private Long deletedBy; 69 | 70 | @TableField("is_deleted") 71 | private Boolean isDeleted; 72 | 73 | /** 74 | * 修改时间 75 | */ 76 | @TableField("modified_time") 77 | private LocalDateTime modifiedTime; 78 | 79 | @TableField("modified_by") 80 | private Long modifiedBy; 81 | 82 | /** 83 | * 器械状态 84 | */ 85 | @TableField("status") 86 | private Boolean status; 87 | 88 | /** 89 | * 借用者id 90 | */ 91 | @TableField("used_by") 92 | private Long usedBy; 93 | 94 | /** 95 | * 借用时间 96 | */ 97 | @TableField("use_time") 98 | private LocalDateTime useTime; 99 | 100 | /** 101 | * 归还时间 102 | */ 103 | @TableField("return_time") 104 | private LocalDateTime returnTime; 105 | 106 | /** 107 | * 申请维修人员id 108 | */ 109 | @TableField("submit_repair_by") 110 | private Long submitRepairBy; 111 | 112 | /** 113 | * 维修人员id 114 | */ 115 | @TableField("repair_by") 116 | private Long repairBy; 117 | 118 | 119 | } 120 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/controller/CaptchaController.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.controller; 2 | 3 | import cn.hutool.core.lang.UUID; 4 | import com.google.code.kaptcha.Producer; 5 | import com.yang.springboot.utils.RedisCache; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | import org.springframework.web.servlet.ModelAndView; 10 | 11 | import javax.imageio.ImageIO; 12 | import javax.servlet.ServletOutputStream; 13 | import javax.servlet.http.Cookie; 14 | import javax.servlet.http.HttpServletRequest; 15 | import javax.servlet.http.HttpServletResponse; 16 | import java.awt.image.BufferedImage; 17 | import java.util.concurrent.TimeUnit; 18 | 19 | @RestController 20 | public class CaptchaController { 21 | 22 | private final Producer captchaProducer; 23 | 24 | private final RedisCache redisCache; 25 | 26 | @Autowired 27 | public CaptchaController(Producer captchaProducer, RedisCache redisCache) { 28 | this.captchaProducer = captchaProducer; 29 | this.redisCache = redisCache; 30 | } 31 | 32 | @GetMapping("/captcha") 33 | public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { 34 | // 禁止server端缓存 35 | response.setDateHeader("Expires", 0); 36 | // 设置标准的 HTTP/1.1 no-cache headers 37 | response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate"); 38 | // 设置IE扩展 HTTP/1.1 no-cache headers (use addHeader) 39 | response.addHeader("Cache-Control", "post-check=0, pre-check=0"); 40 | // 设置标准 HTTP/1.0 不缓存图片 41 | response.setHeader("Pragma", "no-cache"); 42 | // 返回一个 JPEG图片 默认是text/html(输出文档的类型) 43 | response.setContentType("image/jpeg"); 44 | // 为图片创建文本 45 | String capText = captchaProducer.createText(); 46 | 47 | // 给每个用户生成uuid 防止并发访问时出现问题 48 | String uuid = String.valueOf(UUID.randomUUID()); 49 | // 设置Redis缓存的过期时间为60*10s 即10min 50 | redisCache.setCacheObject(uuid, capText, 60 * 10, TimeUnit.SECONDS); 51 | Cookie cookie = new Cookie("captchaCode", uuid); 52 | response.addCookie(cookie); 53 | 54 | // 创建带有文本的图片 55 | BufferedImage bufferedImage = captchaProducer.createImage(capText); 56 | ServletOutputStream outputStream = response.getOutputStream(); 57 | // 图片数据输出 58 | ImageIO.write(bufferedImage, "jpg", outputStream); 59 | try { 60 | outputStream.flush(); 61 | } finally { 62 | outputStream.close(); 63 | } 64 | return null; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/utils/CaptchaUtils.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.utils; 2 | 3 | import cn.hutool.core.util.StrUtil; 4 | import com.google.code.kaptcha.Constants; 5 | import com.google.code.kaptcha.Producer; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | 8 | import javax.imageio.ImageIO; 9 | import javax.servlet.ServletOutputStream; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | import javax.servlet.http.HttpSession; 13 | import java.awt.image.BufferedImage; 14 | import java.io.IOException; 15 | 16 | public class CaptchaUtils { 17 | @Autowired 18 | private Producer captchaProducer; 19 | 20 | // 生成验证码 21 | public void setCaptchaCode(HttpServletRequest request, HttpServletResponse response) throws IOException { 22 | HttpSession session = request.getSession(); 23 | response.setDateHeader("Expires", 0); 24 | response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate"); 25 | response.addHeader("Cache-Control", "post-check=0, pre-check=0"); 26 | response.setHeader("Pragma", "no-cache"); 27 | response.setContentType("image/jpeg"); 28 | //生成验证码 29 | String capText=captchaProducer.createText(); 30 | session.setAttribute(Constants.KAPTCHA_SESSION_KEY,capText); 31 | //向客户端写出 32 | BufferedImage bi = captchaProducer.createImage(capText); 33 | ServletOutputStream out = response.getOutputStream(); 34 | ImageIO.write(bi, "jpg", out); 35 | try { 36 | out.flush(); 37 | } finally { 38 | out.close(); 39 | } 40 | } 41 | 42 | // 将从前端获取的参数转为String类型 43 | public static String getCaptchaCode(HttpServletRequest request, String key) { 44 | try { 45 | String result = request.getParameter(key); 46 | if (StrUtil.isNotEmpty(result)) { 47 | result = result.trim(); 48 | } 49 | return result; 50 | } catch (Exception e) { 51 | throw new RuntimeException(e); 52 | } 53 | } 54 | 55 | // 校验验证码 56 | public static boolean checkCaptchaCode(HttpServletRequest request) { 57 | // 获取生成的验证码 58 | String verifyCodeExpected = (String) request.getSession().getAttribute(com.google.code.kaptcha.Constants.KAPTCHA_SESSION_KEY); 59 | System.out.println("生成的验证码为: "+verifyCodeExpected); 60 | // 获取用户输入的验证码 61 | String verifyCodeActual = CaptchaUtils.getCaptchaCode(request, "verifyCodeActual"); 62 | System.out.println("用户输入的验证码: " + verifyCodeActual); 63 | return verifyCodeActual != null && verifyCodeActual.equals(verifyCodeExpected); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/param/LoginUser.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.param; 2 | 3 | import com.alibaba.fastjson.annotation.JSONField; 4 | import com.yang.springboot.entity.User; 5 | import lombok.AllArgsConstructor; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | import org.springframework.security.core.GrantedAuthority; 9 | import org.springframework.security.core.authority.SimpleGrantedAuthority; 10 | import org.springframework.security.core.userdetails.UserDetails; 11 | 12 | import java.util.Collection; 13 | import java.util.List; 14 | import java.util.stream.Collectors; 15 | 16 | @Data 17 | @AllArgsConstructor 18 | @NoArgsConstructor 19 | public class LoginUser implements UserDetails { 20 | 21 | private User user; 22 | 23 | private List permissions; 24 | 25 | @JSONField(serialize = false) 26 | private List authorities; 27 | 28 | public LoginUser(User user, List permissions) { 29 | this.user = user; 30 | this.permissions = permissions; 31 | } 32 | 33 | /** 34 | * 获取权限 35 | * 因为 Collection 参数需要继承 GrantedAuthority 36 | * 所以选择 SimpleGrantedAuthority 这个实现了 GrantedAuthority 37 | * @return 38 | */ 39 | @Override 40 | public Collection getAuthorities() { 41 | if (authorities == null) { 42 | authorities = permissions.stream() 43 | .map(SimpleGrantedAuthority::new) 44 | .distinct() 45 | .collect(Collectors.toList()); 46 | } 47 | return authorities; 48 | } 49 | 50 | /** 51 | * 获取用户密码 用于回调 52 | * @return 53 | */ 54 | @Override 55 | public String getPassword() { 56 | return user.getPassword(); 57 | } 58 | 59 | /** 60 | * 获取用户名 61 | * @return 62 | */ 63 | @Override 64 | public String getUsername() { 65 | return user.getUsername(); 66 | } 67 | 68 | /** 69 | * 账号是否过期 70 | * @return 71 | */ 72 | @Override 73 | public boolean isAccountNonExpired() { 74 | return true; 75 | } 76 | 77 | /** 78 | * 账号是否被锁定 79 | * @return 80 | */ 81 | @Override 82 | public boolean isAccountNonLocked() { 83 | return user.getStatus(); 84 | } 85 | 86 | /** 87 | * 凭证是否过期 88 | * @return 89 | */ 90 | @Override 91 | public boolean isCredentialsNonExpired() { 92 | return true; 93 | } 94 | 95 | /** 96 | * 是否禁用 97 | * @return 98 | */ 99 | @Override 100 | public boolean isEnabled() { 101 | return true; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableField; 5 | import com.baomidou.mybatisplus.annotation.TableId; 6 | import com.baomidou.mybatisplus.annotation.TableName; 7 | import java.io.Serializable; 8 | import java.time.LocalDateTime; 9 | 10 | import com.fasterxml.jackson.annotation.JsonFormat; 11 | import com.fasterxml.jackson.annotation.JsonIgnore; 12 | import lombok.Data; 13 | import lombok.Getter; 14 | import lombok.Setter; 15 | 16 | /** 17 | *

18 | * 19 | *

20 | * 21 | * @author LambCcc 22 | * @since 2022-04-14 23 | */ 24 | @Data 25 | @TableName("sys_user") 26 | public class User implements Serializable { 27 | 28 | private static final long serialVersionUID = 1L; 29 | 30 | @TableField(exist = false) 31 | private String registerVerifyCode; 32 | 33 | /** 34 | * 主键 35 | */ 36 | @TableId(value = "id", type = IdType.AUTO) 37 | private Long id; 38 | 39 | /** 40 | * 用户权限 41 | */ 42 | @TableField("role_id") 43 | private Integer roleId; 44 | 45 | /** 46 | * 用户名 47 | */ 48 | @TableField("username") 49 | private String username; 50 | 51 | /** 52 | * 昵称 53 | */ 54 | @TableField("nickname") 55 | private String nickname; 56 | 57 | /** 58 | * 密码 59 | */ 60 | @TableField("password") 61 | @JsonIgnore 62 | private String password; 63 | 64 | /** 65 | * 年龄 66 | */ 67 | @TableField("age") 68 | private Integer age; 69 | 70 | /** 71 | * 性别 72 | */ 73 | @TableField("sex") 74 | private Boolean sex; 75 | 76 | /** 77 | * 手机号 78 | */ 79 | @TableField("phone") 80 | private String phone; 81 | 82 | /** 83 | * 邮箱 84 | */ 85 | @TableField("email") 86 | private String email; 87 | 88 | /** 89 | * 地址 90 | */ 91 | @TableField("address") 92 | private String address; 93 | 94 | /** 95 | * 头像(URL地址) 96 | */ 97 | @TableField("avatar_url") 98 | private String avatarUrl; 99 | 100 | /** 101 | * 用户状态 102 | */ 103 | @TableField("status") 104 | private Boolean status; 105 | 106 | /** 107 | * 注册时间 108 | */ 109 | @TableField("created_time") 110 | private LocalDateTime createdTime; 111 | 112 | /** 113 | * 创建者id 114 | */ 115 | @TableField("created_by") 116 | private Long createdBy; 117 | 118 | /** 119 | * 到期时间 120 | */ 121 | @TableField("expired_time") 122 | private LocalDateTime expiredTime; 123 | 124 | /** 125 | * 是否到期 126 | */ 127 | @TableField("is_expired") 128 | private Boolean isExpired; 129 | 130 | /** 131 | * 修改时间 132 | */ 133 | @TableField("modified_time") 134 | private LocalDateTime modifiedTime; 135 | 136 | /** 137 | * 修改者id 138 | */ 139 | @TableField("modified_by") 140 | private Long modifiedBy; 141 | 142 | } 143 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.controller; 2 | 3 | import com.yang.springboot.common.lang.Result; 4 | import com.yang.springboot.entity.User; 5 | import com.yang.springboot.param.LoginParam; 6 | import com.yang.springboot.param.RegisterParam; 7 | import com.yang.springboot.param.UserInfoParam; 8 | import com.yang.springboot.service.UserService; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.web.bind.annotation.*; 11 | 12 | import java.util.List; 13 | 14 | /** 15 | *

16 | * 前端控制器 17 | *

18 | * 19 | * @author LambCcc 20 | * @since 2022-04-14 21 | */ 22 | @RestController 23 | @RequestMapping("/user") 24 | public class UserController { 25 | 26 | private final UserService userService; 27 | 28 | @Autowired 29 | public UserController(UserService userService) { 30 | this.userService = userService; 31 | } 32 | 33 | @PostMapping("/login") 34 | public Result userLogin(@RequestBody LoginParam loginParam, @CookieValue("captchaCode") String uuid) { 35 | loginParam.setUuid(uuid); 36 | return userService.login(loginParam); 37 | } 38 | 39 | @PostMapping("/register") 40 | public Result userRegister(@RequestBody RegisterParam registerParam, @CookieValue("captchaCode") String uuid) { 41 | registerParam.setUuid(uuid); 42 | return userService.register(registerParam); 43 | } 44 | 45 | @PostMapping("/logout") 46 | public Result userLogout() { 47 | return userService.logout(); 48 | } 49 | 50 | @GetMapping("/info/get") 51 | public Result getUserInfo() { 52 | return userService.getUserInfo(); 53 | } 54 | 55 | @PostMapping("/info/update") 56 | public Result updateUserInfoById(@RequestBody UserInfoParam userInfoParam, @RequestHeader String token) { 57 | return userService.updateUserInfoById(userInfoParam, token); 58 | } 59 | 60 | @GetMapping("/get/page/{type}") 61 | public Result getUserPage(@PathVariable String type, 62 | @RequestParam Integer currentPage, 63 | @RequestParam Integer pageSize, 64 | @RequestParam(defaultValue = "") String username, 65 | @RequestParam(defaultValue = "") String nickname, 66 | @RequestParam(defaultValue = "") String phone) { 67 | return userService.getUserPage(type, currentPage, pageSize, username, nickname, phone); 68 | } 69 | 70 | @PostMapping("/insert") 71 | public Result insertUser(@RequestBody User user) { 72 | return userService.insertUser(user); 73 | } 74 | 75 | @PostMapping("/delete/{id}") 76 | public Result deleteUserById(@PathVariable Long id) { 77 | return userService.deleteUserById(id); 78 | } 79 | 80 | @PostMapping("/delete/batch/{ids}") 81 | public Result deleteUserByIds(@PathVariable List ids) { 82 | return userService.deleteBatchByUserIds(ids); 83 | } 84 | 85 | @PostMapping("/info/change/status") 86 | public Result changeUserStatus(Long id, Boolean status) { 87 | return userService.changeUserStatus(id, status); 88 | } 89 | 90 | @PostMapping("/info/change/password") 91 | public Result changeUserPassword(Long id, String password) { 92 | return userService.changeUserPassword(id, password); 93 | } 94 | 95 | } 96 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/utils/JwtUtils.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.utils; 2 | 3 | import cn.hutool.core.lang.UUID; 4 | import io.jsonwebtoken.Claims; 5 | import io.jsonwebtoken.JwtBuilder; 6 | import io.jsonwebtoken.Jwts; 7 | import io.jsonwebtoken.SignatureAlgorithm; 8 | 9 | import javax.crypto.SecretKey; 10 | import javax.crypto.spec.SecretKeySpec; 11 | import java.util.Base64; 12 | import java.util.Date; 13 | 14 | /** 15 | * JWT工具类 16 | */ 17 | public class JwtUtils { 18 | 19 | private static final Long JWT_TTL = 60 * 60 * 1000L; // JWT有效期 60 * 60 * 1000 一个小时 20 | private static final String JWT_KEY = "YangLiCcc"; // JWT秘钥明文 21 | 22 | public static String getUUID() { 23 | return UUID.randomUUID().toString().replaceAll("-", ""); 24 | } 25 | 26 | /** 27 | * 生成jwt 28 | * @param subject token中存放的数据 JSON格式 29 | * @return 30 | */ 31 | public static String createJWT(String subject) { 32 | JwtBuilder jwtBuilder = getJwtBuilder(subject, null, getUUID()); 33 | return jwtBuilder.compact(); 34 | } 35 | 36 | /** 37 | * 生成jwt 38 | * @param subject token中存放的数据 JSON格式 39 | * @param ttlMillis token超时时间 40 | * @return 41 | */ 42 | public static String createJWT(String subject, Long ttlMillis) { 43 | JwtBuilder jwtBuilder = getJwtBuilder(subject, ttlMillis, getUUID()); 44 | return jwtBuilder.compact(); 45 | } 46 | 47 | /** 48 | * 生成jwt 49 | * @param id 唯一标识 50 | * @param subject token中存放的数据 JSON格式 51 | * @param ttlMillis token超时时间 52 | * @return 53 | */ 54 | public static String createJWT(String id, String subject, Long ttlMillis) { 55 | JwtBuilder jwtBuilder = getJwtBuilder(subject, ttlMillis, id); 56 | return jwtBuilder.compact(); 57 | } 58 | 59 | public static JwtBuilder getJwtBuilder(String subject, Long ttlMillis, String uuid) { 60 | SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256; 61 | SecretKey secretKey = generalKey(); 62 | long nowMillis = System.currentTimeMillis(); 63 | Date now = new Date(nowMillis); 64 | if (ttlMillis == null) { 65 | ttlMillis = JwtUtils.JWT_TTL; 66 | } 67 | long expMillis = nowMillis + ttlMillis; 68 | Date expDate = new Date(expMillis); 69 | 70 | return Jwts.builder() 71 | .setId(uuid) // 唯一标识id 72 | .setSubject(subject) // 主题 可以是JSON数据 73 | .setIssuer("YangLiCcc") // 签发者 74 | .setIssuedAt(now) // 签发时间 75 | .signWith(signatureAlgorithm, secretKey) // 使用HS256对称加密算法前面 第二个参数是秘钥 76 | .setExpiration(expDate); // 有效期 77 | } 78 | 79 | /** 80 | * 生成加密后的秘钥 81 | * @return secretKey 82 | */ 83 | public static SecretKey generalKey() { 84 | byte[] encodeKey = Base64.getDecoder().decode(JwtUtils.JWT_KEY); 85 | return new SecretKeySpec(encodeKey, 0, encodeKey.length, "AES"); 86 | } 87 | 88 | /** 89 | * 解析token 90 | * @param jwt token 91 | * @return 92 | * @throws Exception 93 | */ 94 | public static Claims parseJWT(String jwt) throws Exception { 95 | SecretKey secretKey = generalKey(); 96 | return Jwts.parser() 97 | .setSigningKey(secretKey) 98 | .parseClaimsJws(jwt) 99 | .getBody(); 100 | } 101 | 102 | } 103 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/service/impl/CourseServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.service.impl; 2 | 3 | import cn.hutool.core.bean.BeanUtil; 4 | import cn.hutool.core.util.StrUtil; 5 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 6 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 7 | import com.yang.springboot.common.Constants; 8 | import com.yang.springboot.common.lang.Result; 9 | import com.yang.springboot.entity.Course; 10 | import com.yang.springboot.entity.User; 11 | import com.yang.springboot.mapper.CourseDao; 12 | import com.yang.springboot.param.CourseParam; 13 | import com.yang.springboot.service.CourseService; 14 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 15 | import com.yang.springboot.service.UserService; 16 | import com.yang.springboot.utils.UserUtils; 17 | import org.springframework.beans.factory.annotation.Autowired; 18 | import org.springframework.stereotype.Service; 19 | 20 | import java.time.LocalDateTime; 21 | import java.util.List; 22 | 23 | /** 24 | *

25 | * 服务实现类 26 | *

27 | * 28 | * @author LambCcc 29 | * @since 2022-04-14 30 | */ 31 | @Service 32 | public class CourseServiceImpl extends ServiceImpl implements CourseService { 33 | 34 | private final UserService userService; 35 | 36 | @Autowired 37 | public CourseServiceImpl(UserService userService) { 38 | this.userService = userService; 39 | } 40 | 41 | @Override 42 | public Result getCoursePage(Integer currentPage, Integer pageSize, String coachName) { 43 | Page page = new Page<>(currentPage, pageSize); 44 | LambdaQueryWrapper courseLambdaQueryWrapper = new LambdaQueryWrapper<>(); 45 | if (StrUtil.isNotEmpty(coachName)) { 46 | LambdaQueryWrapper userLambdaQueryWrapper = new LambdaQueryWrapper<>(); 47 | userLambdaQueryWrapper.like(User::getNickname, coachName); 48 | List userIds = userService.listUserIds(userLambdaQueryWrapper); 49 | courseLambdaQueryWrapper.eq(Course::getCouchId, userIds); 50 | } 51 | 52 | return new Result(Constants.CODE_200, "获取分页信息成功!", page(page, courseLambdaQueryWrapper)); 53 | } 54 | 55 | @Override 56 | public Result insertCourse(CourseParam insertParam) { 57 | User userInfo = UserUtils.getUserInfo(); 58 | Course course = new Course(); 59 | BeanUtil.copyProperties(insertParam, course, true); 60 | course.setCreatedBy(userInfo.getId()); 61 | course.setCreatedTime(LocalDateTime.now()); 62 | if (save(course)) { 63 | return new Result(Constants.CODE_200, "新增课程成功!", null); 64 | } 65 | 66 | return new Result(Constants.CODE_500, "新增课程失败!", null); 67 | } 68 | 69 | @Override 70 | public Result updateCourse(Course course) { 71 | User userInfo = UserUtils.getUserInfo(); 72 | course.setModifiedBy(userInfo.getId()); 73 | course.setModifiedTime(LocalDateTime.now()); 74 | if (updateById(course)) { 75 | return new Result(Constants.CODE_200, "更新课程成功!", null); 76 | } 77 | 78 | return new Result(Constants.CODE_500, "更新课程失败!", null); 79 | } 80 | 81 | @Override 82 | public Result deleteCourseById(Long id) { 83 | User userInfo = UserUtils.getUserInfo(); 84 | Course course = getById(id); 85 | course.setDeletedBy(userInfo.getId()); 86 | course.setDeletedTime(LocalDateTime.now()); 87 | course.setIsDeleted(true); 88 | course.setStatus(false); 89 | if (updateById(course)) { 90 | return new Result(Constants.CODE_200, "删除课程成功!", null); 91 | } 92 | 93 | return new Result(Constants.CODE_500, "删除课程失败!", null); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/config/SecurityConfig.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.config; 2 | 3 | import com.yang.springboot.filter.JwtAuthenticationTokenFilter; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.security.authentication.AuthenticationManager; 8 | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; 9 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 10 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 11 | import org.springframework.security.config.http.SessionCreationPolicy; 12 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 13 | import org.springframework.security.crypto.password.PasswordEncoder; 14 | import org.springframework.security.web.AuthenticationEntryPoint; 15 | import org.springframework.security.web.access.AccessDeniedHandler; 16 | import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; 17 | 18 | @Configuration 19 | @EnableGlobalMethodSecurity(prePostEnabled = true) 20 | public class SecurityConfig extends WebSecurityConfigurerAdapter { 21 | 22 | private final JwtAuthenticationTokenFilter jwtAuthenticationTokenFilter; 23 | 24 | private final AccessDeniedHandler accessDeniedHandler; 25 | 26 | private final AuthenticationEntryPoint authenticationEntryPoint; 27 | 28 | @Autowired 29 | public SecurityConfig(JwtAuthenticationTokenFilter jwtAuthenticationTokenFilter, AccessDeniedHandler accessDeniedHandler, AuthenticationEntryPoint authenticationEntryPoint) { 30 | this.jwtAuthenticationTokenFilter = jwtAuthenticationTokenFilter; 31 | this.accessDeniedHandler = accessDeniedHandler; 32 | this.authenticationEntryPoint = authenticationEntryPoint; 33 | } 34 | 35 | @Bean 36 | public PasswordEncoder passwordEncoder() { 37 | return new BCryptPasswordEncoder(); 38 | } 39 | 40 | /* 41 | SpringSecurity配置 42 | */ 43 | @Override 44 | protected void configure(HttpSecurity httpSecurity) throws Exception { 45 | httpSecurity 46 | // 关闭csrf 47 | .csrf().disable() 48 | // 不通过Session获取SecurityContext 49 | .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) 50 | .and() 51 | .authorizeRequests() 52 | // 对于登录注册接口 允许匿名访问 53 | .antMatchers("/user/login", "/user/register", "/captcha").anonymous() 54 | // 开放权限相关的接口 55 | .antMatchers("/role").permitAll() 56 | // 开放Swagger接口 57 | .antMatchers("/swagger-ui.html").permitAll() 58 | .antMatchers("/webjars/**").permitAll() 59 | .antMatchers("/swagger-ui/**").permitAll() 60 | .antMatchers("/swagger-resources/**").permitAll() 61 | .antMatchers("/v2/**").permitAll() 62 | .antMatchers("/v3/**").permitAll() 63 | // 开放测试接口 64 | .antMatchers("/upload/test/**").permitAll() 65 | // 除上面外的所有请求 全部需要鉴权认证 66 | .anyRequest().authenticated() 67 | .and() 68 | // 将自定义的过滤器添加到SpringSecurity过滤器链中 69 | .addFilterBefore(jwtAuthenticationTokenFilter, UsernamePasswordAuthenticationFilter.class); 70 | // 加入自定义的异常处理 71 | httpSecurity.exceptionHandling().accessDeniedHandler(accessDeniedHandler).authenticationEntryPoint(authenticationEntryPoint); 72 | // 开启跨域 73 | // httpSecurity.cors(); 74 | } 75 | 76 | @Bean 77 | @Override 78 | public AuthenticationManager authenticationManagerBean() throws Exception { 79 | return super.authenticationManagerBean(); 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/service/impl/InstrumentServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.service.impl; 2 | 3 | import cn.hutool.core.util.StrUtil; 4 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 5 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 6 | import com.yang.springboot.common.Constants; 7 | import com.yang.springboot.common.lang.Result; 8 | import com.yang.springboot.entity.Instrument; 9 | import com.yang.springboot.entity.User; 10 | import com.yang.springboot.mapper.InstrumentDao; 11 | import com.yang.springboot.service.InstrumentService; 12 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 13 | import com.yang.springboot.utils.RedisCache; 14 | import com.yang.springboot.utils.UserUtils; 15 | import org.springframework.beans.factory.annotation.Autowired; 16 | import org.springframework.stereotype.Service; 17 | 18 | import java.time.LocalDateTime; 19 | import java.util.List; 20 | 21 | /** 22 | *

23 | * 服务实现类 24 | *

25 | * 26 | * @author LambCcc 27 | * @since 2022-04-14 28 | */ 29 | @Service 30 | public class InstrumentServiceImpl extends ServiceImpl implements InstrumentService { 31 | 32 | private final InstrumentDao instrumentDao; 33 | 34 | private final RedisCache redisCache; 35 | 36 | @Autowired 37 | public InstrumentServiceImpl(InstrumentDao dao, RedisCache redisCache) { 38 | this.instrumentDao = dao; 39 | this.redisCache = redisCache; 40 | } 41 | 42 | 43 | @Override 44 | public Result getInstrumentPage(Integer currentPage, Integer pageSize, String name) { 45 | Page page = new Page<>(currentPage, pageSize); 46 | LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); 47 | if (StrUtil.isNotEmpty(name)) { 48 | lambdaQueryWrapper.like(Instrument::getName, name); 49 | } 50 | 51 | return new Result(Constants.CODE_200, "获取分页信息成功!", page(page, lambdaQueryWrapper)); 52 | } 53 | 54 | @Override 55 | public Result getUnusedInstrument() { 56 | LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); 57 | lambdaQueryWrapper.eq(Instrument::getStatus, true); 58 | 59 | return new Result(Constants.CODE_200, "获取可用器械信息成功!", list(lambdaQueryWrapper)); 60 | } 61 | 62 | @Override 63 | public Result insertInstrument(Instrument instrument) { 64 | // 获取当前操作用户id 65 | User user = UserUtils.getUserInfo(); 66 | instrument.setCreatedBy(user.getId()); 67 | instrument.setCreatedTime(LocalDateTime.now()); 68 | if (save(instrument)) { 69 | return new Result(Constants.CODE_200, "新增器械成功!", null); 70 | } 71 | 72 | return new Result(Constants.CODE_500, "新增器械失败!", null); 73 | } 74 | 75 | @Override 76 | public Result updateInstrument(Instrument instrument) { 77 | // 获取当前操作用户id 78 | User user = UserUtils.getUserInfo(); 79 | instrument.setModifiedBy(user.getId()); 80 | instrument.setModifiedTime(LocalDateTime.now()); 81 | if (updateById(instrument)) { 82 | return new Result(Constants.CODE_200, "修改器械成功!", null); 83 | } 84 | 85 | return new Result(Constants.CODE_500, "修改器械失败!", null); 86 | } 87 | 88 | @Override 89 | public Result deleteInstrumentById(Long id) { 90 | // 获取当前操作用户id 91 | User user = UserUtils.getUserInfo(); 92 | Instrument instrument = getById(id); 93 | instrument.setDeletedBy(user.getId()); 94 | instrument.setDeletedTime(LocalDateTime.now()); 95 | instrument.setIsDeleted(true); 96 | instrument.setStatus(false); 97 | if (updateById(instrument)) { 98 | return new Result(Constants.CODE_200, "删除器械成功!", null); 99 | } 100 | 101 | return new Result(Constants.CODE_500, "删除器械失败!", null); 102 | } 103 | 104 | @Override 105 | public Result deleteInstrumentBatchByIds(List ids) { 106 | return null; 107 | } 108 | 109 | } 110 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/service/impl/LockerServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.service.impl; 2 | 3 | import cn.hutool.core.bean.BeanUtil; 4 | import cn.hutool.core.util.StrUtil; 5 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 6 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 7 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 8 | import com.yang.springboot.common.Constants; 9 | import com.yang.springboot.common.lang.Result; 10 | import com.yang.springboot.entity.Locker; 11 | import com.yang.springboot.entity.User; 12 | import com.yang.springboot.mapper.LockerDao; 13 | import com.yang.springboot.param.LockerSaveParam; 14 | import com.yang.springboot.param.LockerUseParam; 15 | import com.yang.springboot.service.LockerService; 16 | import com.yang.springboot.utils.RedisCache; 17 | import com.yang.springboot.utils.UserUtils; 18 | import org.springframework.beans.factory.annotation.Autowired; 19 | import org.springframework.stereotype.Service; 20 | 21 | import java.time.LocalDateTime; 22 | import java.util.List; 23 | import java.util.Map; 24 | import java.util.concurrent.TimeUnit; 25 | 26 | /** 27 | *

28 | * 服务实现类 29 | *

30 | * 31 | * @author LambCcc 32 | * @since 2022-04-14 33 | */ 34 | @Service 35 | public class LockerServiceImpl extends ServiceImpl implements LockerService { 36 | 37 | private final RedisCache redisCache; 38 | 39 | @Autowired 40 | public LockerServiceImpl(RedisCache redisCache) { 41 | this.redisCache = redisCache; 42 | } 43 | 44 | @Override 45 | public Result getLockerPage(Integer currentPage, Integer pageSize, String name, String sex, String area) { 46 | Page page = new Page<>(currentPage, pageSize); 47 | // 根据查询条件进行分页查询 48 | LambdaQueryWrapper lockerLambdaQueryWrapper = new LambdaQueryWrapper<>(); 49 | // 判断条件是否为空 若不为空则进行条件拼接 50 | if (StrUtil.isNotEmpty(name)) { 51 | lockerLambdaQueryWrapper.like(Locker::getName, name); 52 | } 53 | if (StrUtil.isNotEmpty(sex)) { 54 | Boolean sexFlag = sex.equals("男"); 55 | lockerLambdaQueryWrapper.eq(Locker::getSex, sexFlag); 56 | } 57 | if (StrUtil.isNotEmpty(area)) { 58 | lockerLambdaQueryWrapper.like(Locker::getArea, area); 59 | } 60 | // 将查询到的数据存入Redis 61 | redisCache.setCacheObject("LockerList: ", list(), 1, TimeUnit.DAYS); 62 | 63 | return new Result(Constants.CODE_200, "获取分页数据成功!", page(page, lockerLambdaQueryWrapper)); 64 | } 65 | 66 | @Override 67 | public Result insertLocker(LockerSaveParam lockerSaveParam) { 68 | Locker locker = new Locker(); 69 | BeanUtil.copyProperties(lockerSaveParam, locker); 70 | locker.setCreatedTime(LocalDateTime.now()); 71 | if (save(locker)) { 72 | return new Result(Constants.CODE_200, "新建存储柜成功!", null); 73 | } 74 | 75 | return new Result(Constants.CODE_500, "新建存储柜失败!", null); 76 | } 77 | 78 | @Override 79 | public Result deleteLockerById(Long id) { 80 | Locker locker = getById(id); 81 | locker.setDeletedTime(LocalDateTime.now()); 82 | // 假删除 更改删除状态为true 即已删除 83 | locker.setIsDeleted(true); 84 | locker.setStatus(false); 85 | if (updateById(locker)) { 86 | return new Result(Constants.CODE_200, "删除存储柜成功!", null); 87 | } 88 | 89 | return new Result(Constants.CODE_500, "删除存储柜失败!", null); 90 | } 91 | 92 | // 未完成 93 | @Override 94 | public Result deleteLockerBatchByIds(List ids) { 95 | LambdaQueryWrapper lockerLambdaQueryWrapper = new LambdaQueryWrapper<>(); 96 | lockerLambdaQueryWrapper.eq(Locker::getId, ids); 97 | Map map = getMap(lockerLambdaQueryWrapper); 98 | 99 | // updateBatchById() 100 | return new Result(Constants.CODE_500, "批量删除失败!", map); 101 | } 102 | 103 | @Override 104 | public Result updateLocker(LockerSaveParam lockerSaveParam) { 105 | Locker locker = getById(lockerSaveParam.getId()); 106 | BeanUtil.copyProperties(lockerSaveParam, locker); 107 | // 获取当前操作用户的id 108 | User user = UserUtils.getUserInfo(); 109 | locker.setModifiedTime(lockerSaveParam.getModifiedTime()); 110 | locker.setModifiedBy(user.getId()); 111 | if (updateById(locker)) { 112 | return new Result(Constants.CODE_200, "更新存储柜信息成功!", null); 113 | } 114 | 115 | return new Result(Constants.CODE_500, "更新存储柜信息失败!", null); 116 | } 117 | 118 | @Override 119 | public Result useLockerByUserId(LockerUseParam lockerUseParam) { 120 | 121 | Locker locker = getById(lockerUseParam.getId()); 122 | locker.setUsedBy(lockerUseParam.getUserId()); 123 | locker.setUseTime(lockerUseParam.getUseTime()); 124 | locker.setReturnTime(lockerUseParam.getReturnTime()); 125 | locker.setStatus(false); 126 | if (updateById(locker)) { 127 | return new Result(Constants.CODE_200, "借用储物柜成功!请按时归还!", null); 128 | } 129 | 130 | return new Result(Constants.CODE_500, "借用储物柜失败!请稍后再试!", null); 131 | } 132 | 133 | @Override 134 | public Result getUnusedLockerList() { 135 | // 获取查询用户的性别 根据用户性别查询相应存储柜 136 | User user = UserUtils.getUserInfo(); 137 | LambdaQueryWrapper lockerLambdaQueryWrapper = new LambdaQueryWrapper<>(); 138 | // 查询条件 status为true 即可用状态 139 | lockerLambdaQueryWrapper.eq(Locker::getStatus, true); 140 | // 查询条件 sex为user的sex 141 | lockerLambdaQueryWrapper.eq(Locker::getSex, user.getSex()); 142 | 143 | return new Result(Constants.CODE_200, "获取可用存储柜成功", list(lockerLambdaQueryWrapper)); 144 | } 145 | 146 | } 147 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.6.6 9 | 10 | 11 | com.yang 12 | springboot 13 | 0.0.1-SNAPSHOT 14 | springboot 15 | springboot 16 | 17 | 1.8 18 | 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter-data-redis 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter-freemarker 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-security 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-web 35 | 36 | 37 | org.mybatis.spring.boot 38 | mybatis-spring-boot-starter 39 | 2.2.2 40 | 41 | 42 | 43 | org.springframework.boot 44 | spring-boot-devtools 45 | runtime 46 | true 47 | 48 | 49 | mysql 50 | mysql-connector-java 51 | runtime 52 | 53 | 54 | org.projectlombok 55 | lombok 56 | true 57 | 58 | 59 | org.springframework.boot 60 | spring-boot-starter-test 61 | test 62 | 63 | 64 | org.springframework.security 65 | spring-security-test 66 | test 67 | 68 | 69 | 70 | 71 | com.alibaba 72 | druid 73 | 1.2.8 74 | 75 | 76 | 77 | com.alibaba 78 | fastjson 79 | 1.2.80 80 | 81 | 82 | 83 | com.aliyun.oss 84 | aliyun-sdk-oss 85 | 3.10.2 86 | 87 | 88 | 89 | com.baomidou 90 | mybatis-plus-boot-starter 91 | 3.5.1 92 | 93 | 94 | com.baomidou 95 | mybatis-plus-generator 96 | 3.5.2 97 | 98 | 99 | 100 | cn.hutool 101 | hutool-all 102 | 5.8.0.M2 103 | 104 | 105 | 106 | io.jsonwebtoken 107 | jjwt 108 | 0.9.1 109 | 110 | 111 | javax.xml.bind 112 | jaxb-api 113 | 2.3.1 114 | 115 | 116 | org.apache.commons 117 | commons-lang3 118 | 3.8.1 119 | 120 | 121 | 122 | com.github.penggle 123 | kaptcha 124 | 2.3.2 125 | 126 | 127 | 128 | io.springfox 129 | springfox-boot-starter 130 | 3.0.0 131 | 132 | 133 | 134 | 135 | 136 | 137 | org.springframework.boot 138 | spring-boot-maven-plugin 139 | 140 | 141 | 142 | org.projectlombok 143 | lombok 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/utils/RedisCache.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.utils; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.data.redis.core.BoundSetOperations; 5 | import org.springframework.data.redis.core.HashOperations; 6 | import org.springframework.data.redis.core.RedisTemplate; 7 | import org.springframework.data.redis.core.ValueOperations; 8 | import org.springframework.stereotype.Component; 9 | 10 | import java.util.*; 11 | import java.util.concurrent.TimeUnit; 12 | 13 | @SuppressWarnings(value = { "unchecked", "rawtypes" }) 14 | @Component 15 | public class RedisCache { 16 | 17 | public RedisTemplate redisTemplate; 18 | 19 | @Autowired 20 | public RedisCache(RedisTemplate redisTemplate) { 21 | this.redisTemplate = redisTemplate; 22 | } 23 | 24 | /** 25 | * 缓存基本的对象,Integer、String、实体类等 26 | * 27 | * @param key 缓存的键值 28 | * @param value 缓存的值 29 | */ 30 | public void setCacheObject(final String key, final T value) { 31 | redisTemplate.opsForValue().set(key, value); 32 | } 33 | 34 | /** 35 | * 缓存基本的对象,Integer、String、实体类等 36 | * 37 | * @param key 缓存的键值 38 | * @param value 缓存的值 39 | * @param timeout 时间 40 | * @param timeUnit 时间颗粒度 41 | */ 42 | public void setCacheObject(final String key, final T value, final Integer timeout, final TimeUnit timeUnit) { 43 | redisTemplate.opsForValue().set(key, value, timeout, timeUnit); 44 | } 45 | 46 | /** 47 | * 设置有效时间 48 | * 49 | * @param key Redis键 50 | * @param timeout 超时时间 51 | * @return true=设置成功;false=设置失败 52 | */ 53 | public boolean expire(final String key, final long timeout) { 54 | return expire(key, timeout, TimeUnit.SECONDS); 55 | } 56 | 57 | /** 58 | * 设置有效时间 59 | * 60 | * @param key Redis键 61 | * @param timeout 超时时间 62 | * @param unit 时间单位 63 | * @return true=设置成功;false=设置失败 64 | */ 65 | public boolean expire(final String key, final long timeout, final TimeUnit unit) { 66 | return redisTemplate.expire(key, timeout, unit); 67 | } 68 | 69 | /** 70 | * 获得缓存的基本对象。 71 | * 72 | * @param key 缓存键值 73 | * @return 缓存键值对应的数据 74 | */ 75 | public T getCacheObject(final String key) { 76 | ValueOperations operation = redisTemplate.opsForValue(); 77 | return operation.get(key); 78 | } 79 | 80 | /** 81 | * 删除单个对象 82 | * 83 | * @param key 84 | */ 85 | public boolean deleteObject(final String key) { 86 | return redisTemplate.delete(key); 87 | } 88 | 89 | /** 90 | * 删除集合对象 91 | * 92 | * @param collection 多个对象 93 | * @return 94 | */ 95 | public long deleteObject(final Collection collection) { 96 | return redisTemplate.delete(collection); 97 | } 98 | 99 | /** 100 | * 缓存List数据 101 | * 102 | * @param key 缓存的键值 103 | * @param dataList 待缓存的List数据 104 | * @return 缓存的对象 105 | */ 106 | public long setCacheList(final String key, final List dataList) { 107 | Long count = redisTemplate.opsForList().rightPushAll(key, dataList); 108 | return count == null ? 0 : count; 109 | } 110 | 111 | /** 112 | * 获得缓存的list对象 113 | * 114 | * @param key 缓存的键值 115 | * @return 缓存键值对应的数据 116 | */ 117 | public List getCacheList(final String key) { 118 | return redisTemplate.opsForList().range(key, 0, -1); 119 | } 120 | 121 | /** 122 | * 缓存Set 123 | * 124 | * @param key 缓存键值 125 | * @param dataSet 缓存的数据 126 | * @return 缓存数据的对象 127 | */ 128 | public BoundSetOperations setCacheSet(final String key, final Set dataSet) { 129 | BoundSetOperations setOperation = redisTemplate.boundSetOps(key); 130 | for (T t : dataSet) { 131 | setOperation.add(t); 132 | } 133 | return setOperation; 134 | } 135 | 136 | /** 137 | * 获得缓存的set 138 | * 139 | * @param key 140 | * @return 141 | */ 142 | public Set getCacheSet(final String key) { 143 | return redisTemplate.opsForSet().members(key); 144 | } 145 | 146 | /** 147 | * 缓存Map 148 | * 149 | * @param key 150 | * @param dataMap 151 | */ 152 | public void setCacheMap(final String key, final Map dataMap) { 153 | if (dataMap != null) { 154 | redisTemplate.opsForHash().putAll(key, dataMap); 155 | } 156 | } 157 | 158 | /** 159 | * 获得缓存的Map 160 | * 161 | * @param key 162 | * @return 163 | */ 164 | public Map getCacheMap(final String key) { 165 | return redisTemplate.opsForHash().entries(key); 166 | } 167 | 168 | /** 169 | * 往Hash中存入数据 170 | * 171 | * @param key Redis键 172 | * @param hKey Hash键 173 | * @param value 值 174 | */ 175 | public void setCacheMapValue(final String key, final String hKey, final T value) 176 | { 177 | redisTemplate.opsForHash().put(key, hKey, value); 178 | } 179 | 180 | /** 181 | * 获取Hash中的数据 182 | * 183 | * @param key Redis键 184 | * @param hKey Hash键 185 | * @return Hash中的对象 186 | */ 187 | public T getCacheMapValue(final String key, final String hKey) { 188 | HashOperations opsForHash = redisTemplate.opsForHash(); 189 | return opsForHash.get(key, hKey); 190 | } 191 | 192 | /** 193 | * 删除Hash中的数据 194 | * 195 | * @param key 196 | * @param hkey 197 | */ 198 | public void delCacheMapValue(final String key, final String hkey) { 199 | HashOperations hashOperations = redisTemplate.opsForHash(); 200 | hashOperations.delete(key, hkey); 201 | } 202 | 203 | /** 204 | * 获取多个Hash中的数据 205 | * 206 | * @param key Redis键 207 | * @param hKeys Hash键集合 208 | * @return Hash对象集合 209 | */ 210 | public List getMultiCacheMapValue(final String key, final Collection hKeys) { 211 | return redisTemplate.opsForHash().multiGet(key, hKeys); 212 | } 213 | 214 | /** 215 | * 获得缓存的基本对象列表 216 | * 217 | * @param pattern 字符串前缀 218 | * @return 对象列表 219 | */ 220 | public Collection keys(final String pattern) { 221 | return redisTemplate.keys(pattern); 222 | } 223 | 224 | } 225 | -------------------------------------------------------------------------------- /src/main/java/com/yang/springboot/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.yang.springboot.service.impl; 2 | 3 | import cn.hutool.core.bean.BeanUtil; 4 | import cn.hutool.core.util.StrUtil; 5 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 6 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 7 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 8 | import com.yang.springboot.common.Constants; 9 | import com.yang.springboot.common.lang.Result; 10 | import com.yang.springboot.entity.Role; 11 | import com.yang.springboot.entity.User; 12 | import com.yang.springboot.mapper.UserDao; 13 | import com.yang.springboot.param.LoginParam; 14 | import com.yang.springboot.param.LoginUser; 15 | import com.yang.springboot.param.RegisterParam; 16 | import com.yang.springboot.param.UserInfoParam; 17 | import com.yang.springboot.param.vo.UserInfoVo; 18 | import com.yang.springboot.service.UserService; 19 | import com.yang.springboot.utils.JwtUtils; 20 | import com.yang.springboot.utils.RedisCache; 21 | import com.yang.springboot.utils.UserUtils; 22 | import io.jsonwebtoken.Claims; 23 | import org.springframework.beans.factory.annotation.Autowired; 24 | import org.springframework.security.authentication.AuthenticationManager; 25 | import org.springframework.security.authentication.InternalAuthenticationServiceException; 26 | import org.springframework.security.authentication.LockedException; 27 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; 28 | import org.springframework.security.core.Authentication; 29 | import org.springframework.security.core.context.SecurityContextHolder; 30 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 31 | import org.springframework.stereotype.Service; 32 | 33 | import java.time.LocalDateTime; 34 | import java.util.*; 35 | import java.util.concurrent.TimeUnit; 36 | 37 | /** 38 | *

39 | * 服务实现类 40 | *

41 | * 42 | * @author LambCcc 43 | * @since 2022-04-14 44 | */ 45 | @Service 46 | public class UserServiceImpl extends ServiceImpl implements UserService { 47 | 48 | private final AuthenticationManager authenticationManager; 49 | 50 | private final RedisCache redisCache; 51 | 52 | private final UserDao userDao; 53 | 54 | @Autowired 55 | public UserServiceImpl(AuthenticationManager authenticationManager, RedisCache redisCache, UserDao userDao) { 56 | this.authenticationManager = authenticationManager; 57 | this.redisCache = redisCache; 58 | this.userDao = userDao; 59 | } 60 | 61 | @Override 62 | public Result getUserPage(String type, Integer currentPage, Integer pageSize, String username, String nickname, String phone) { 63 | // 根据currentPage和pageSize 设置分页查询范围 64 | Page userPage = new Page<>(currentPage, pageSize); 65 | LambdaQueryWrapper userLambdaQueryWrapper = new LambdaQueryWrapper<>(); 66 | // 根据username nickname phone查询数据库 67 | // 判断参数是否为空 决定是否拼接条件 68 | // 使用like对查询条件进行模糊查询 69 | switch (type) { 70 | case "admin": 71 | userLambdaQueryWrapper.eq(User::getRoleId, 1); 72 | break; 73 | case "stuff": 74 | userLambdaQueryWrapper.eq(User::getRoleId, 2); 75 | break; 76 | case "coach": 77 | userLambdaQueryWrapper.eq(User::getRoleId, 3); 78 | break; 79 | case "member": 80 | userLambdaQueryWrapper.eq(User::getRoleId, 4); 81 | break; 82 | case "all": 83 | default: 84 | break; 85 | } 86 | if (StrUtil.isNotEmpty(username)) { 87 | userLambdaQueryWrapper.like(User::getUsername, username); 88 | } 89 | if (StrUtil.isNotEmpty(nickname)) { 90 | userLambdaQueryWrapper.like(User::getNickname, nickname); 91 | } 92 | if (StrUtil.isNotEmpty(phone)) { 93 | userLambdaQueryWrapper.like(User::getPhone, phone); 94 | } 95 | 96 | return new Result(Constants.CODE_200, "获取分页信息成功!", page(userPage, userLambdaQueryWrapper)); 97 | } 98 | 99 | /** 100 | * 登录操作的实现类 101 | * 1. 首先验证 输入的验证码是否正确 如果不正确直接返回错误 102 | * 2. 调用自定义的登录接口 调用ProviderManager的authenticate方法进行认证 如果认证通过则进行生成jwt 103 | * 3. 将token存入Redis中进行缓存 104 | * @param loginParam 登录所需要的参数 105 | */ 106 | @Override 107 | public Result login(LoginParam loginParam) { 108 | // 获取Cookie中携带的uuid 根据uuid获取Redis中的验证码 109 | String uuid = loginParam.getUuid(); 110 | String codeInRedis = redisCache.getCacheObject(uuid).toString(); 111 | // 校验token 112 | if (StrUtil.isEmpty(codeInRedis)) { 113 | return new Result(Constants.CODE_500, "验证码不存在!请重试!", null); 114 | } else if (!codeInRedis.equals(loginParam.getCaptchaCode())) { 115 | return new Result(Constants.CODE_500, "验证码错误!请重新输入!", null); 116 | } 117 | UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(loginParam.getUsername(), loginParam.getPassword()); 118 | Authentication authentication = null; 119 | try { 120 | authentication = authenticationManager.authenticate(authenticationToken); 121 | } catch (LockedException e) { 122 | return new Result(Constants.CODE_500, "账号已停用!", null); 123 | } catch (InternalAuthenticationServiceException e) { 124 | return new Result(Constants.CODE_500, "登录失败!", null); 125 | } 126 | if (Objects.isNull(authentication)) { 127 | throw new RuntimeException("用户名或密码错误!"); 128 | } 129 | LoginUser loginUser = (LoginUser) authentication.getPrincipal(); 130 | // 获取用户id生成token 131 | String userId = loginUser.getUser().getId().toString(); 132 | String token = JwtUtils.createJWT(userId); 133 | // 将数据存入Redis 根据ID查找和存储 134 | redisCache.setCacheObject("UserLogin: " + userId, loginUser, 1, TimeUnit.DAYS); 135 | // 以KEY-VALUE形式返回给前端 136 | Map map = new HashMap<>(); 137 | map.put("token", token); 138 | 139 | return new Result(Constants.CODE_200, "登录成功!", map); 140 | } 141 | 142 | /** 143 | * 注册操作 144 | * 1. 首先校验验证码 如果输入错误 直接返回错误 145 | * 2. 如果选择的职别是健身教练/工作人员/管理员 校验内部验证码是否正确 如果错误 直接返回错误 146 | * 3. 查询数据库中是否已存在username 如果有相同username 直接返回错误 147 | * @param registerParam 注册所需要的参数 148 | */ 149 | @Override 150 | public Result register(RegisterParam registerParam) { 151 | // 获取Cookie中携带的uuid 根据uuid获取Redis中的验证码 152 | String uuid = registerParam.getUuid(); 153 | String codeInRedis = redisCache.getCacheObject(uuid).toString(); 154 | // 校验验证码 155 | if (StrUtil.isEmpty(codeInRedis)) { 156 | return new Result(Constants.CODE_500, "验证码不存在!请重试!", null); 157 | } else if (!codeInRedis.equals(registerParam.getCaptchaCode())) { 158 | return new Result(Constants.CODE_500, "验证码错误!请重新输入!", null); 159 | } 160 | // 如果注册的不是会员用户 则进行校验码判断 161 | switch (registerParam.getRoleId()) { 162 | case 1: // roleId为1 表示管理员 163 | if (Constants.VERIFY_CODE_REGISTER_ADMIN.equals(registerParam.getVerifyCode())) { 164 | return new Result(Constants.CODE_401, "内部验证码输入错误!请重试!", null); 165 | } 166 | break; 167 | case 2: // roleId为2 表示工作人员 168 | if (Constants.VERIFY_CODE_REGISTER_STUFF.equals(registerParam.getVerifyCode())) { 169 | return new Result(Constants.CODE_401, "内部验证码输入错误!请重试!", null); 170 | } 171 | break; 172 | case 3: // roleId为3 表示健身教练 173 | if (Constants.VERIFY_CODE_REGISTER_COACH.equals(registerParam.getVerifyCode())) { 174 | return new Result(Constants.CODE_401, "内部验证码输入错误!请重试!", null); 175 | } 176 | break; 177 | default: 178 | break; 179 | } 180 | // 判断用户名是否重复 181 | LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); 182 | lambdaQueryWrapper.eq(User::getUsername, registerParam.getUsername()); 183 | User one = getOne(lambdaQueryWrapper); 184 | if (!Objects.isNull(one)) { 185 | return new Result(Constants.CODE_500, "用户名已存在!请重试!", null); 186 | } 187 | User register = new User(); 188 | // 将注册的参数赋值给User对象 189 | BeanUtil.copyProperties(registerParam, register); 190 | // 创建时间为当前时间 191 | register.setCreatedTime(LocalDateTime.now()); 192 | // 头像为默认头像 193 | register.setAvatarUrl("https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif"); 194 | 195 | if (save(register)) { 196 | return new Result(Constants.CODE_200, "注册成功!", null); 197 | } 198 | 199 | return new Result(Constants.CODE_500, "注册失败!请稍后重试!", null); 200 | } 201 | 202 | /** 203 | * 根据条件 获取用户ids 204 | * 1. 传入查询条件 根据条件查询所有相关用户 205 | * 2. 将查询到的用户的ids返回 206 | * @param lambdaQueryWrapper 查询条件 207 | * @return ids 208 | */ 209 | @Override 210 | public List listUserIds(LambdaQueryWrapper lambdaQueryWrapper) { 211 | List userList = list(lambdaQueryWrapper); 212 | List userIds = new ArrayList<>(); 213 | for (User user : userList) { 214 | userIds.add(user.getId()); 215 | } 216 | 217 | return userIds; 218 | } 219 | 220 | /** 221 | * 登出操作 222 | * 1. 从SecurityContextHolder中获取用户数据 223 | * 2. 根据用户数据 删除Redis中的数据 224 | */ 225 | @Override 226 | public Result logout() { 227 | UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); 228 | LoginUser loginUser = (LoginUser) authentication.getPrincipal(); 229 | String userId = loginUser.getUser().getId().toString(); 230 | redisCache.deleteObject("UserLogin: " + userId); 231 | 232 | return new Result(Constants.CODE_200, "退出登录成功!", null); 233 | } 234 | 235 | /** 236 | * 获取用户信息 237 | * 1. 在校验token的过滤器中 已经将用户信息存入SecurityContextHolder中 所以这里可以直接获取存放的用户信息 238 | * 2. 除了基本信息 还需要通过role表去查询用户的权限信息 239 | */ 240 | @Override 241 | public Result getUserInfo() { 242 | User user = UserUtils.getUserInfo(); 243 | // 获取用户的权限信息 根据roleId查找role 244 | Role role = userDao.getRoleByUserId(user.getId()); 245 | // 把需要的内容复制到UserInfoVo中 并传给前端 246 | UserInfoVo userInfoVo = copyToVo(user, role); 247 | 248 | return new Result(Constants.CODE_200, "获取用户信息成功!", userInfoVo); 249 | } 250 | 251 | @Override 252 | public Result updateUserInfoById(UserInfoParam userInfoParam, String token) { 253 | try { 254 | // 1. 从token中获取当前操作用户的userId 255 | Claims claims = JwtUtils.parseJWT(token); 256 | String userId = claims.getSubject(); 257 | // 2. 从Redis中获取存放的User数据 258 | LoginUser loginUser = redisCache.getCacheObject("UserLogin: " + userId); 259 | User user = loginUser.getUser(); 260 | UpdateUser(user, userInfoParam); 261 | // 3. 进行更新操作 262 | if (userDao.updateById(user) < 0) { 263 | return new Result(Constants.CODE_400, "更新用户信息失败!", null); 264 | } 265 | loginUser.setUser(user); 266 | // 4. 将更新后的数据写入Redis中 267 | redisCache.setCacheObject("UserLogin: " + userId, loginUser, 1, TimeUnit.DAYS); 268 | } catch (Exception e) { 269 | e.printStackTrace(); 270 | } 271 | 272 | return new Result(Constants.CODE_400, "更新用户信息成功!", null); 273 | } 274 | 275 | @Override 276 | public Result insertUser(User user) { 277 | // 获取当前管理员用户信息 278 | User admin = UserUtils.getUserInfo(); 279 | // 如果新添加的用户的用户名已存在 则返回 280 | if (!IsNotExistUsername(user.getUsername())) { 281 | return new Result(Constants.CODE_500, "用户名已存在!", null); 282 | } 283 | // 如果没有上传头像 则设置默认头像 284 | if (StrUtil.isEmpty(user.getAvatarUrl())) { 285 | user.setAvatarUrl("https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif"); 286 | } 287 | user.setCreatedBy(admin.getId()); 288 | user.setModifiedTime(LocalDateTime.now()); 289 | user.setModifiedBy(admin.getId()); 290 | // 加密密码 291 | BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder(); 292 | user.setPassword(bCryptPasswordEncoder.encode(user.getPassword())); 293 | if (userDao.insert(user) < 0) { 294 | return new Result(Constants.CODE_500, "系统错误!添加失败!", null); 295 | } 296 | 297 | return new Result(Constants.CODE_200, "添加用户成功!", null); 298 | } 299 | 300 | @Override 301 | public Result changeUserStatus(Long id, Boolean status) { 302 | // 获取当前管理员用户信息 303 | User admin = UserUtils.getUserInfo(); 304 | // 根据id查询对应的用户 305 | LambdaQueryWrapper userLambdaQueryWrapper = new LambdaQueryWrapper<>(); 306 | userLambdaQueryWrapper.eq(User::getId, id); 307 | User user = getOne(userLambdaQueryWrapper); 308 | user.setStatus(status); 309 | user.setModifiedBy(admin.getId()); 310 | user.setModifiedTime(LocalDateTime.now()); 311 | if (updateById(user)) { 312 | return new Result(Constants.CODE_200, "修改用户状态成功!", null); 313 | } 314 | 315 | return new Result(Constants.CODE_500, "修改用户状态失败!", null); 316 | } 317 | 318 | @Override 319 | public Result changeUserPassword(Long id, String password) { 320 | // 获取当前用户信息 321 | User userInfo = UserUtils.getUserInfo(); 322 | // 判断当前用户是否为超级管理员或需要修改密码的用户 323 | if (userInfo.getRoleId() != 1 || !Objects.equals(userInfo.getId(), id)) { 324 | return new Result(Constants.CODE_401, "没有权限修改该用户密码!", null); 325 | } 326 | LambdaQueryWrapper userLambdaQueryWrapper = new LambdaQueryWrapper<>(); 327 | userLambdaQueryWrapper.eq(User::getId, id); 328 | User one = getOne(userLambdaQueryWrapper); 329 | one.setPassword(password); 330 | one.setModifiedBy(userInfo.getId()); 331 | one.setModifiedTime(LocalDateTime.now()); 332 | if (updateById(one)) { 333 | return new Result(Constants.CODE_200, "修改密码成功!", null); 334 | } 335 | 336 | return new Result(Constants.CODE_500, "修改密码失败!", null); 337 | } 338 | 339 | @Override 340 | public Result deleteUserById(Long id) { 341 | if (removeById(id)) { 342 | return new Result(Constants.CODE_200, "删除用户成功!", null); 343 | } 344 | return new Result(Constants.CODE_500, "删除用户失败!", null); 345 | } 346 | 347 | @Override 348 | public Result deleteBatchByUserIds(List ids) { 349 | if (removeBatchByIds(ids)) { 350 | return new Result(Constants.CODE_200, "批量删除用户成功!", null); 351 | } 352 | return new Result(Constants.CODE_500, "批量删除用户失败!", null); 353 | } 354 | 355 | public UserInfoVo copyToVo(User user, Role role) { 356 | UserInfoVo userInfoVo = new UserInfoVo(); 357 | BeanUtil.copyProperties(user, userInfoVo); 358 | userInfoVo.setRole(role); 359 | return userInfoVo; 360 | } 361 | 362 | public void UpdateUser(User user, UserInfoParam userInfoParam) { 363 | BeanUtil.copyProperties(userInfoParam, user); 364 | user.setModifiedBy(user.getId()); 365 | user.setModifiedTime(LocalDateTime.now()); 366 | } 367 | 368 | public boolean IsNotExistUsername(String username) { 369 | LambdaQueryWrapper userLambdaQueryWrapper = new LambdaQueryWrapper<>(); 370 | userLambdaQueryWrapper.eq(User::getUsername, username); 371 | User one = getOne(userLambdaQueryWrapper); 372 | return Objects.isNull(one); 373 | } 374 | 375 | 376 | 377 | } 378 | --------------------------------------------------------------------------------