├── .gitignore ├── my.log ├── spring.log ├── spring.log.2022-04-03.0.gz ├── spring.log.2022-04-06.0.gz ├── spring.log.2022-04-08.0.gz └── spring.log.2022-04-09.0.gz ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── lt │ │ └── health │ │ ├── PersonalHealthApplication.java │ │ ├── aop │ │ ├── WebLogAspect.java │ │ └── log │ │ │ ├── SystemCrmLog.java │ │ │ └── SystemLogAspect.java │ │ ├── config │ │ ├── MybatisPlusConfig.java │ │ ├── QiniuConfig.java │ │ ├── ReidsConfig.java │ │ ├── Swagger2Config.java │ │ ├── WebMvcConfig.java │ │ ├── captcha │ │ │ ├── CaptchaConfig.java │ │ │ └── KaptchaTextCreator.java │ │ └── security │ │ │ ├── SecurityConfig.java │ │ │ ├── contents │ │ │ └── SecurityContents.java │ │ │ ├── entity │ │ │ └── LoginUser.java │ │ │ ├── filter │ │ │ └── JwtAuthenticationFilter.java │ │ │ ├── handler │ │ │ ├── JwtAccessDeniedHandler.java │ │ │ └── JwtAuthenticationEntryPoint.java │ │ │ └── service │ │ │ └── UserDetailServiceImpl.java │ │ ├── constant │ │ ├── Constants.java │ │ ├── MessageConstant.java │ │ ├── Result.java │ │ ├── TableNameConstant.java │ │ └── UserConstant.java │ │ ├── controller │ │ ├── CaptchaController.java │ │ ├── FoodController.java │ │ ├── GoodsController.java │ │ ├── LogMessageController.java │ │ ├── MenuController.java │ │ ├── MiniController.java │ │ ├── MotionController.java │ │ ├── OrderController.java │ │ ├── PermissionController.java │ │ ├── RoleController.java │ │ ├── SportController.java │ │ ├── TestController.java │ │ ├── ToolController.java │ │ └── UserController.java │ │ ├── entity │ │ ├── Food.java │ │ ├── FoodType.java │ │ ├── Goods.java │ │ ├── LogMessage.java │ │ ├── Menu.java │ │ ├── Motion.java │ │ ├── Permission.java │ │ ├── Role.java │ │ ├── RolesMenus.java │ │ ├── RolesPermissions.java │ │ ├── Sport.java │ │ ├── User.java │ │ ├── UserRoles.java │ │ ├── WxRun.java │ │ └── dto │ │ │ ├── Encrypted.java │ │ │ ├── LoginUserDTO.java │ │ │ ├── MailDTO.java │ │ │ └── PageInfoDTO.java │ │ ├── event │ │ └── demo │ │ │ ├── AbstractEvent.java │ │ │ ├── EventListener.java │ │ │ ├── EventMulticaster.java │ │ │ ├── EventTest.java │ │ │ ├── MyConfig.java │ │ │ ├── SendEmailOnUserRegisterSuccessListener.java │ │ │ ├── SimpleEventMulticaster.java │ │ │ ├── UserRegisterListener.java │ │ │ ├── UserRegisterService.java │ │ │ └── UserRegisterSuccessEvent.java │ │ ├── exception │ │ ├── CaptchaException.java │ │ ├── CaptchaExpireException.java │ │ └── GlobalException.java │ │ ├── mapper │ │ ├── FoodMapper.java │ │ ├── FoodTypeMapper.java │ │ ├── GoodsMapper.java │ │ ├── LogMessageMapper.java │ │ ├── MenuMapper.java │ │ ├── MotionMapper.java │ │ ├── PermissionMapper.java │ │ ├── RoleMapper.java │ │ ├── RolesMenusMapper.java │ │ ├── RolesPermissionsMapper.java │ │ ├── SportMapper.java │ │ ├── UserMapper.java │ │ ├── UserRolesMapper.java │ │ └── WxRunMapper.java │ │ ├── service │ │ ├── FoodService.java │ │ ├── FoodTypeService.java │ │ ├── GoodsService.java │ │ ├── LogMessageService.java │ │ ├── MenuService.java │ │ ├── MotionService.java │ │ ├── PermissionService.java │ │ ├── RoleService.java │ │ ├── RolesMenusService.java │ │ ├── RolesPermissionsService.java │ │ ├── SportService.java │ │ ├── ToolService.java │ │ ├── UserRolesService.java │ │ ├── UserService.java │ │ ├── WxRunService.java │ │ └── impl │ │ │ ├── FoodServiceImpl.java │ │ │ ├── FoodTypeServiceImpl.java │ │ │ ├── GoodsServiceImpl.java │ │ │ ├── LogMessageServiceImpl.java │ │ │ ├── MenuServiceImpl.java │ │ │ ├── MotionServiceImpl.java │ │ │ ├── PermissionServiceImpl.java │ │ │ ├── RoleServiceImpl.java │ │ │ ├── RolesMenusServiceImpl.java │ │ │ ├── RolesPermissionsServiceImpl.java │ │ │ ├── SportServiceImpl.java │ │ │ ├── ToolServiceImpl.java │ │ │ ├── UserRolesServiceImpl.java │ │ │ ├── UserServiceImpl.java │ │ │ └── WxRunServiceImpl.java │ │ ├── test │ │ └── Test.java │ │ └── utils │ │ ├── DateUtil.java │ │ ├── DecryptDataUtil.java │ │ ├── EasyExcelUtil.java │ │ ├── HttpUtil.java │ │ ├── JwtTokenUtil.java │ │ ├── MD5Util.java │ │ ├── MailUtil.java │ │ ├── QiniuUtil.java │ │ ├── RedisUtil.java │ │ ├── SecurityUtil.java │ │ ├── SmsUtil.java │ │ └── WebUtil.java └── resources │ ├── application-dev.yml │ ├── application-prod.yml │ ├── application.yml │ ├── banner.txt │ └── mapper │ ├── FoodMapper.xml │ ├── FoodTypeMapper.xml │ ├── GoodsMapper.xml │ ├── LogMessageMapper.xml │ ├── MenuMapper.xml │ ├── MotionMapper.xml │ ├── PermissionMapper.xml │ ├── RoleMapper.xml │ ├── RolesMenusMapper.xml │ ├── RolesPermissionsMapper.xml │ ├── SportMapper.xml │ ├── UserMapper.xml │ ├── UserRolesMapper.xml │ └── WxRunMapper.xml └── test └── java └── com └── lt └── health ├── PersonalHealthApplicationTests.java └── mapper ├── MenuMapperTest.java ├── PermissionMapperTest.java └── RoleMapperTest.java /.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 | -------------------------------------------------------------------------------- /my.log/spring.log.2022-04-03.0.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeTeng/personalHealth/dbfe781bd7c562171aabf424ab1898bdbb301840/my.log/spring.log.2022-04-03.0.gz -------------------------------------------------------------------------------- /my.log/spring.log.2022-04-06.0.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeTeng/personalHealth/dbfe781bd7c562171aabf424ab1898bdbb301840/my.log/spring.log.2022-04-06.0.gz -------------------------------------------------------------------------------- /my.log/spring.log.2022-04-08.0.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeTeng/personalHealth/dbfe781bd7c562171aabf424ab1898bdbb301840/my.log/spring.log.2022-04-08.0.gz -------------------------------------------------------------------------------- /my.log/spring.log.2022-04-09.0.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeTeng/personalHealth/dbfe781bd7c562171aabf424ab1898bdbb301840/my.log/spring.log.2022-04-09.0.gz -------------------------------------------------------------------------------- /src/main/java/com/lt/health/PersonalHealthApplication.java: -------------------------------------------------------------------------------- 1 | package com.lt.health; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | * 项目启动 9 | * 10 | * @author 狂小腾 11 | */ 12 | @SpringBootApplication 13 | @MapperScan("com.lt.health.mapper") 14 | public class PersonalHealthApplication { 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(PersonalHealthApplication.class, args); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/aop/WebLogAspect.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.aop; 2 | 3 | import com.sun.istack.logging.Logger; 4 | import org.aspectj.lang.JoinPoint; 5 | import org.aspectj.lang.annotation.AfterReturning; 6 | import org.aspectj.lang.annotation.Aspect; 7 | import org.aspectj.lang.annotation.Before; 8 | import org.aspectj.lang.annotation.Pointcut; 9 | import org.springframework.stereotype.Component; 10 | import org.springframework.web.context.request.RequestContextHolder; 11 | import org.springframework.web.context.request.ServletRequestAttributes; 12 | 13 | import javax.servlet.http.HttpServletRequest; 14 | import java.util.Arrays; 15 | 16 | /** 17 | * @description: 日志切面类 18 | * @author: 狂小腾 19 | * @date: 2022/3/31 21:02 20 | */ 21 | @Component 22 | @Aspect 23 | public class WebLogAspect { 24 | 25 | private Logger logger = Logger.getLogger(WebLogAspect.class); 26 | 27 | private ThreadLocal startTime = new ThreadLocal<>(); 28 | 29 | /** 30 | * 切入点 TestController下的hello函数 31 | */ 32 | @Pointcut("execution(public * com.lt.health.controller.TestController.hello(..))") 33 | public void point() {} 34 | 35 | @Before("point()") 36 | public void doBefore(JoinPoint joinpoint) { 37 | // 设置初始时间 38 | startTime.set(System.currentTimeMillis()); 39 | // 接收到请求内容,记录请求内容 40 | ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); 41 | HttpServletRequest request = attributes.getRequest(); 42 | logger.info("URL : " + request.getRequestURI()); 43 | logger.info("HTTP_METHOD : " + request.getMethod()); 44 | logger.info("IP : " + request.getRemoteAddr()); 45 | logger.info("CLASS_METHOD : " + joinpoint.getSignature().getDeclaringTypeName() + "." + joinpoint.getSignature().getName()); 46 | logger.info("ARGS : " + Arrays.toString(joinpoint.getArgs())); 47 | } 48 | 49 | @AfterReturning(pointcut = "point()", returning = "obj") 50 | public void doAfterRunning(Object obj) { 51 | // 处理完请求 返回内容 52 | logger.info("RESPONSE : " + obj); 53 | logger.info("SPEND TIME : " + (System.currentTimeMillis() - startTime.get())); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/aop/log/SystemCrmLog.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.aop.log; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * @description: AOP日志记录 自定义注解类 7 | * @author: 狂小腾 8 | * @date: 2022/4/1 18:32 9 | */ 10 | @Target({ElementType.PARAMETER, ElementType.METHOD}) 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Documented 13 | public @interface SystemCrmLog { 14 | 15 | /** 16 | * 日志描述 17 | * 对于什么表格进行了什么操作 18 | */ 19 | String description() default ""; 20 | 21 | /** 22 | * 操作了的表名---可以有多个 23 | */ 24 | String[] tableName() default ""; 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/config/MybatisPlusConfig.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.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.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | 10 | /** 11 | * Mybatis-Plus分页插件 12 | * 13 | * @author 狂小腾 14 | */ 15 | @Configuration 16 | public class MybatisPlusConfig { 17 | 18 | /** 19 | * 新的分页插件,一缓和二缓遵循mybatis的规则,需要设置 MybatisConfiguration#useDeprecatedExecutor = false 避免缓存出现问题(该属性会在旧插件移除后一同移除) 20 | */ 21 | @Bean 22 | public MybatisPlusInterceptor mybatisPlusInterceptor() { 23 | MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); 24 | interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.H2)); 25 | return interceptor; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/config/QiniuConfig.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.config; 2 | 3 | import com.qiniu.storage.Region; 4 | import com.qiniu.storage.UploadManager; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | 8 | /** 9 | * @description: 七牛云配置类 10 | * @author: 狂小腾 11 | * @date: 2022/3/29 22:16 12 | */ 13 | @Configuration 14 | public class QiniuConfig { 15 | 16 | @Bean 17 | public UploadManager uploadManager() { 18 | com.qiniu.storage.Configuration configuration = new com.qiniu.storage.Configuration(Region.region2()); 19 | return new UploadManager(configuration); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/config/ReidsConfig.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.config; 2 | 3 | import com.fasterxml.jackson.annotation.JsonAutoDetect; 4 | import com.fasterxml.jackson.annotation.JsonTypeInfo; 5 | import com.fasterxml.jackson.annotation.PropertyAccessor; 6 | import com.fasterxml.jackson.databind.ObjectMapper; 7 | import com.fasterxml.jackson.databind.jsontype.impl.LaissezFaireSubTypeValidator; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.context.annotation.Configuration; 10 | import org.springframework.data.redis.connection.RedisConnectionFactory; 11 | import org.springframework.data.redis.core.RedisTemplate; 12 | import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; 13 | import org.springframework.data.redis.serializer.StringRedisSerializer; 14 | 15 | /** 16 | * reids配置类 17 | * 18 | * @author 狂小腾 19 | */ 20 | @Configuration 21 | public class ReidsConfig { 22 | 23 | /** 24 | * 配置redis的模板类 25 | * 26 | * @param redisConnectionFactory Redis的连接信息 27 | * @return redis模板 28 | */ 29 | @Bean 30 | public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory) { 31 | //初始化redis模板 32 | RedisTemplate template = new RedisTemplate<>(); 33 | //设置Redis的连接信息 34 | template.setConnectionFactory(redisConnectionFactory); 35 | StringRedisSerializer stringRedisSerializer = new StringRedisSerializer(); 36 | // key采用String的序列化方式 将redis的键设置为string类型 37 | template.setKeySerializer(stringRedisSerializer); 38 | // hash的key也采用String的序列化方式 39 | template.setHashKeySerializer(stringRedisSerializer); 40 | Jackson2JsonRedisSerializer serializer = new Jackson2JsonRedisSerializer<>(Object.class); 41 | ObjectMapper objectMapper = new ObjectMapper(); 42 | //redis中必须加上这两项 43 | objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); 44 | objectMapper.activateDefaultTyping(LaissezFaireSubTypeValidator.instance, ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY); 45 | serializer.setObjectMapper(objectMapper); 46 | //将模板的value信息设置为Jackson2 47 | template.setValueSerializer(serializer); 48 | template.setHashValueSerializer(serializer); 49 | template.afterPropertiesSet(); 50 | return template; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/config/Swagger2Config.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.config; 2 | 3 | import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j; 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.*; 10 | import springfox.documentation.spi.DocumentationType; 11 | import springfox.documentation.spi.service.contexts.SecurityContext; 12 | import springfox.documentation.spring.web.plugins.Docket; 13 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 14 | 15 | import java.util.ArrayList; 16 | import java.util.List; 17 | 18 | /** 19 | * @description: Swagger配置类 20 | * @author: 狂小腾 21 | * @date: 2022/3/31 23:03 22 | */ 23 | @Configuration 24 | @EnableSwagger2 25 | @EnableKnife4j 26 | public class Swagger2Config { 27 | 28 | /** 29 | * 创建API应用 30 | * apiInfo() 增加API相关信息 31 | * 通过select()函数返回一个ApiSelectorBuilder实例,用来控制哪些接口暴露给Swagger来展现, 32 | * 本例采用指定扫描的包路径来定义指定要建立API的目录。 33 | * 多人开发可以设置多个Docket 34 | */ 35 | @Bean 36 | public Docket createRestApi() { 37 | return new Docket(DocumentationType.SWAGGER_2) 38 | .useDefaultResponseMessages(false) 39 | .apiInfo(apiInfo()) 40 | .select() 41 | // 配置扫描接口的方式,基于包去扫描 42 | .apis(RequestHandlerSelectors.basePackage("com.lt.health.controller")) 43 | // paths()过滤什么路径 44 | .paths(PathSelectors.any()) 45 | .build() 46 | .securitySchemes(this.securitySchemes()) 47 | .securityContexts(this.securityContexts()); 48 | } 49 | 50 | /** 51 | * 创建该API的基本信息(这些基本信息会展现在文档页面中) 52 | * 访问地址:http://localhost:8000/swagger-ui.html 53 | */ 54 | private ApiInfo apiInfo() { 55 | return new ApiInfoBuilder() 56 | .title("Spring Boot中使用Swagger2构建RESTful APIs") 57 | .description("大学生饮食、运动健康管理平台接口文档") 58 | .termsOfServiceUrl("https://github.com/CodeTeng/personalHealth") 59 | .version("1.3.1") 60 | .contact(new Contact("狂小腾", "http://localhost:8000/doc.html", "liteng2002823@outlook.com")) 61 | .build(); 62 | } 63 | 64 | /** 65 | * 设置请求的信息 66 | */ 67 | private List securitySchemes() { 68 | List list = new ArrayList<>(); 69 | ApiKey key = new ApiKey("Authorization", "Authorization", "Header"); 70 | list.add(key); 71 | return list; 72 | } 73 | 74 | /** 75 | * 配置security对swagger测试的权限 过滤不需要进行验证的页面 76 | */ 77 | public List securityContexts() { 78 | List list = new ArrayList<>(); 79 | list.add(getSecurityContext()); 80 | return list; 81 | } 82 | 83 | /** 84 | * 得到授权路径 85 | */ 86 | private SecurityContext getSecurityContext() { 87 | return SecurityContext 88 | .builder() 89 | .securityReferences(securityReferences()) 90 | // 带有auth的页面将不用提供token即可访问 91 | // .forPaths(PathSelectors.regex("^(?!auth).*$")) 92 | .forPaths(PathSelectors.regex("hello/.*")) 93 | .build(); 94 | } 95 | 96 | /** 97 | * 给授权swagger,可以进行接口测试 全局的token配置 98 | */ 99 | private List securityReferences() { 100 | List list = new ArrayList<>(); 101 | //授权范围 全局 102 | AuthorizationScope scope = new AuthorizationScope("global", "accessEverything"); 103 | AuthorizationScope[] scopes = new AuthorizationScope[1]; 104 | scopes[0] = scope; 105 | list.add(new SecurityReference("Authorization", scopes)); 106 | return list; 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/config/WebMvcConfig.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.config; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.web.servlet.config.annotation.CorsRegistry; 5 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 6 | 7 | /** 8 | * @description: 9 | * @author: 狂小腾 10 | * @date: 2022/3/22 19:32 11 | */ 12 | @Configuration 13 | public class WebMvcConfig implements WebMvcConfigurer { 14 | @Override 15 | public void addCorsMappings(CorsRegistry registry) { 16 | registry 17 | // 过滤所有的请求 18 | .addMapping("/**") 19 | //配置跨域来源 20 | .allowedOrigins("http://localhost:8888") 21 | // 是否支持跨域Cookie 22 | .allowCredentials(true) 23 | // 最大响应时间 24 | .maxAge(3600) 25 | // 设置允许访问的方法 26 | .allowedMethods("GET", "POST", "DELETE", "PUT", "OPTION"); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/config/captcha/CaptchaConfig.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.config.captcha; 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 | import static com.google.code.kaptcha.Constants.*; 11 | 12 | /** 13 | * @description: 验证码配置类 14 | * @author: 狂小腾 15 | * @date: 2022/4/10 16:07 16 | */ 17 | @Configuration 18 | public class CaptchaConfig { 19 | 20 | @Bean(name = "captchaProducer") 21 | public DefaultKaptcha getKaptchaBean() { 22 | DefaultKaptcha defaultKaptcha = new DefaultKaptcha(); 23 | Properties properties = new Properties(); 24 | // 是否有边框 默认为true 我们可以自己设置yes,no 25 | properties.setProperty(KAPTCHA_BORDER, "yes"); 26 | // 验证码文本字符颜色 默认为Color.BLACK 27 | properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_COLOR, "black"); 28 | // 验证码图片宽度 默认为200 29 | properties.setProperty(KAPTCHA_IMAGE_WIDTH, "160"); 30 | // 验证码图片高度 默认为50 31 | properties.setProperty(KAPTCHA_IMAGE_HEIGHT, "60"); 32 | // 验证码文本字符大小 默认为40 33 | properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_SIZE, "38"); 34 | // KAPTCHA_SESSION_KEY 35 | properties.setProperty(KAPTCHA_SESSION_CONFIG_KEY, "kaptchaCode"); 36 | // 验证码文本字符长度 默认为5 37 | properties.setProperty(KAPTCHA_TEXTPRODUCER_CHAR_LENGTH, "4"); 38 | // 验证码文本字体样式 默认为new Font("Arial", 1, fontSize), new Font("Courier", 1, fontSize) 39 | properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_NAMES, "Arial,Courier"); 40 | // 图片样式 水纹com.google.code.kaptcha.impl.WaterRipple 鱼眼com.google.code.kaptcha.impl.FishEyeGimpy 阴影com.google.code.kaptcha.impl.ShadowGimpy 41 | properties.setProperty(KAPTCHA_OBSCURIFICATOR_IMPL, "com.google.code.kaptcha.impl.ShadowGimpy"); 42 | Config config = new Config(properties); 43 | defaultKaptcha.setConfig(config); 44 | return defaultKaptcha; 45 | } 46 | 47 | @Bean(name = "captchaProducerMath") 48 | public DefaultKaptcha getKaptchaBeanMath() { 49 | DefaultKaptcha defaultKaptcha = new DefaultKaptcha(); 50 | Properties properties = new Properties(); 51 | // 是否有边框 默认为true 我们可以自己设置yes,no 52 | properties.setProperty(KAPTCHA_BORDER, "yes"); 53 | // 边框颜色 默认为Color.BLACK 54 | properties.setProperty(KAPTCHA_BORDER_COLOR, "105,179,90"); 55 | // 验证码文本字符颜色 默认为Color.BLACK 56 | properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_COLOR, "blue"); 57 | // 验证码图片宽度 默认为200 58 | properties.setProperty(KAPTCHA_IMAGE_WIDTH, "160"); 59 | // 验证码图片高度 默认为50 60 | properties.setProperty(KAPTCHA_IMAGE_HEIGHT, "60"); 61 | // 验证码文本字符大小 默认为40 62 | properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_SIZE, "35"); 63 | // KAPTCHA_SESSION_KEY 64 | properties.setProperty(KAPTCHA_SESSION_CONFIG_KEY, "kaptchaCodeMath"); 65 | // 验证码文本生成器 66 | properties.setProperty(KAPTCHA_TEXTPRODUCER_IMPL, "com.lt.health.config.captcha.KaptchaTextCreator"); 67 | // 验证码文本字符间距 默认为2 68 | properties.setProperty(KAPTCHA_TEXTPRODUCER_CHAR_SPACE, "3"); 69 | // 验证码文本字符长度 默认为5 70 | properties.setProperty(KAPTCHA_TEXTPRODUCER_CHAR_LENGTH, "6"); 71 | // 验证码文本字体样式 默认为new Font("Arial", 1, fontSize), new Font("Courier", 1, fontSize) 72 | properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_NAMES, "Arial,Courier"); 73 | // 验证码噪点颜色 默认为Color.BLACK 74 | properties.setProperty(KAPTCHA_NOISE_COLOR, "white"); 75 | // 干扰实现类 76 | properties.setProperty(KAPTCHA_NOISE_IMPL, "com.google.code.kaptcha.impl.NoNoise"); 77 | // 图片样式 水纹com.google.code.kaptcha.impl.WaterRipple 鱼眼com.google.code.kaptcha.impl.FishEyeGimpy 阴影com.google.code.kaptcha.impl.ShadowGimpy 78 | properties.setProperty(KAPTCHA_OBSCURIFICATOR_IMPL, "com.google.code.kaptcha.impl.ShadowGimpy"); 79 | Config config = new Config(properties); 80 | defaultKaptcha.setConfig(config); 81 | return defaultKaptcha; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/config/captcha/KaptchaTextCreator.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.config.captcha; 2 | 3 | import com.google.code.kaptcha.text.impl.DefaultTextCreator; 4 | 5 | import java.util.Random; 6 | 7 | /** 8 | * @description: 验证码文本生成器 9 | * @author: 狂小腾 10 | * @date: 2022/4/10 16:35 11 | */ 12 | public class KaptchaTextCreator extends DefaultTextCreator { 13 | private static final String[] CNUMBERS = "0,1,2,3,4,5,6,7,8,9,10".split(","); 14 | 15 | @Override 16 | public String getText() { 17 | Integer result = 0; 18 | Random random = new Random(); 19 | int x = random.nextInt(10); 20 | int y = random.nextInt(10); 21 | StringBuilder suChinese = new StringBuilder(); 22 | int randomoperands = (int) Math.round(Math.random() * 2); 23 | if (randomoperands == 0) { 24 | result = x * y; 25 | suChinese.append(CNUMBERS[x]); 26 | suChinese.append("*"); 27 | suChinese.append(CNUMBERS[y]); 28 | } else if (randomoperands == 1) { 29 | if (!(x == 0) && y % x == 0) { 30 | result = y / x; 31 | suChinese.append(CNUMBERS[y]); 32 | suChinese.append("/"); 33 | suChinese.append(CNUMBERS[x]); 34 | } else { 35 | result = x + y; 36 | suChinese.append(CNUMBERS[x]); 37 | suChinese.append("+"); 38 | suChinese.append(CNUMBERS[y]); 39 | } 40 | } else if (randomoperands == 2) { 41 | if (x >= y) { 42 | result = x - y; 43 | suChinese.append(CNUMBERS[x]); 44 | suChinese.append("-"); 45 | suChinese.append(CNUMBERS[y]); 46 | } else { 47 | result = y - x; 48 | suChinese.append(CNUMBERS[y]); 49 | suChinese.append("-"); 50 | suChinese.append(CNUMBERS[x]); 51 | } 52 | } else { 53 | result = x + y; 54 | suChinese.append(CNUMBERS[x]); 55 | suChinese.append("+"); 56 | suChinese.append(CNUMBERS[y]); 57 | } 58 | suChinese.append("=?@" + result); 59 | return suChinese.toString(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/config/security/SecurityConfig.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.config.security; 2 | 3 | import com.lt.health.config.security.contents.SecurityContents; 4 | import com.lt.health.config.security.filter.JwtAuthenticationFilter; 5 | import com.lt.health.config.security.handler.JwtAccessDeniedHandler; 6 | import com.lt.health.config.security.handler.JwtAuthenticationEntryPoint; 7 | import com.lt.health.config.security.service.UserDetailServiceImpl; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.context.annotation.Bean; 10 | import org.springframework.context.annotation.Configuration; 11 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 12 | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; 13 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 14 | import org.springframework.security.config.annotation.web.builders.WebSecurity; 15 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 16 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 17 | import org.springframework.security.config.http.SessionCreationPolicy; 18 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 19 | import org.springframework.security.crypto.password.PasswordEncoder; 20 | import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; 21 | 22 | 23 | /** 24 | * @description: security的配置 25 | * @author: 狂小腾 26 | * @date: 2022/3/22 19:35 27 | */ 28 | @Configuration 29 | @EnableWebSecurity 30 | @EnableGlobalMethodSecurity(prePostEnabled = true) 31 | public class SecurityConfig extends WebSecurityConfigurerAdapter { 32 | 33 | @Autowired 34 | private UserDetailServiceImpl userDetailService; 35 | 36 | @Autowired 37 | private JwtAuthenticationEntryPoint authenticationEntryPoint; 38 | 39 | @Autowired 40 | private JwtAccessDeniedHandler accessDeniedHandler; 41 | 42 | @Autowired 43 | private JwtAuthenticationFilter authenticationFilter; 44 | 45 | /** 46 | * 一般用于配置白名单 47 | * 白名单:可以没有权限也可以访问的资源 48 | */ 49 | @Override 50 | public void configure(WebSecurity web) throws Exception { 51 | web.ignoring() 52 | .mvcMatchers(SecurityContents.WHITE_LIST); 53 | } 54 | 55 | /** 56 | * Security的核心配置 57 | */ 58 | @Override 59 | protected void configure(HttpSecurity http) throws Exception { 60 | //1. 使用jwt,首先关闭跨域攻击 61 | http.csrf().disable(); 62 | //2. 关闭session 63 | http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS); 64 | //3. 请求都需要进行认证之后才能访问,除白名单以外的资源 65 | http.authorizeRequests().anyRequest().authenticated(); 66 | //4. 关闭缓存 67 | http.headers().cacheControl(); 68 | //5. token过滤器,校验token 69 | http.addFilterBefore(authenticationFilter, UsernamePasswordAuthenticationFilter.class); 70 | //6. 没有登录、没有权限访问资源自定义返回结果 71 | http.exceptionHandling().authenticationEntryPoint(authenticationEntryPoint).accessDeniedHandler(accessDeniedHandler); 72 | } 73 | 74 | /** 75 | * 自定义登录逻辑的配置 76 | * 也即是配置到security中进行认证 77 | */ 78 | @Override 79 | protected void configure(AuthenticationManagerBuilder auth) throws Exception { 80 | auth.userDetailsService(userDetailService).passwordEncoder(passwordEncoder()); 81 | } 82 | 83 | @Bean 84 | public PasswordEncoder passwordEncoder() { 85 | return new BCryptPasswordEncoder(); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/config/security/contents/SecurityContents.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.config.security.contents; 2 | 3 | /** 4 | * @description: 白名单 5 | * @author: 狂小腾 6 | * @date: 2022/3/26 21:53 7 | */ 8 | public class SecurityContents { 9 | public static final String[] WHITE_LIST = { 10 | //后端登录接口 11 | "/user/login", 12 | "/user/logout", 13 | "/oauth/**", 14 | "/captchaImage", 15 | 16 | //swagger相关 17 | "/favicon.ico", 18 | "/swagger-ui.html", 19 | "/doc.html", 20 | "/webjars/**", 21 | "/swagger-resources/**", 22 | "/v2/**", 23 | "/configuration/ui", 24 | "/configuration/security", 25 | "/tool/forget/password", 26 | "/tool/sms", 27 | "/user/sms/login", 28 | "/goods/batchExport", 29 | 30 | // 小程序相关 31 | "/mini/login", 32 | }; 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/config/security/entity/LoginUser.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.config.security.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnore; 4 | import com.lt.health.entity.Permission; 5 | import com.lt.health.entity.Role; 6 | import com.lt.health.entity.User; 7 | import lombok.NoArgsConstructor; 8 | import org.apache.commons.lang3.StringUtils; 9 | import org.springframework.security.core.GrantedAuthority; 10 | import org.springframework.security.core.authority.SimpleGrantedAuthority; 11 | import org.springframework.security.core.userdetails.UserDetails; 12 | 13 | import java.io.Serializable; 14 | import java.util.ArrayList; 15 | import java.util.Collection; 16 | import java.util.List; 17 | 18 | /** 19 | * @description: security中的用户实体 20 | * @author: 狂小腾 21 | * @date: 2022/3/22 20:04 22 | */ 23 | @NoArgsConstructor 24 | public class LoginUser implements UserDetails, Serializable { 25 | 26 | private static final long serialVersionUID = -7240861075043737094L; 27 | 28 | private User user; 29 | 30 | public LoginUser(User user) { 31 | this.user = user; 32 | } 33 | 34 | public User getUser() { 35 | return user; 36 | } 37 | 38 | public void setUser(User user) { 39 | this.user = user; 40 | } 41 | 42 | /** 43 | * 权限数据 44 | * 45 | * @return 权限数据 46 | * @JsonIgnore 在返回的数据中,将该方法对应的属性数据给排除 47 | */ 48 | @Override 49 | @JsonIgnore 50 | public Collection getAuthorities() { 51 | List authorities = new ArrayList<>(); 52 | List roles = user.getRoles(); 53 | List permissions = user.getPermissions(); 54 | if (roles != null && roles.size() > 0) { 55 | roles.forEach(role -> { 56 | if (StringUtils.isNotEmpty(role.getCode())) { 57 | authorities.add(new SimpleGrantedAuthority("ROLE_" + role.getCode())); 58 | } 59 | }); 60 | } 61 | if (permissions != null && permissions.size() > 0) { 62 | permissions.forEach(permission -> { 63 | if (StringUtils.isNotEmpty(permission.getCode())) { 64 | authorities.add(new SimpleGrantedAuthority(permission.getCode())); 65 | } 66 | }); 67 | } 68 | return authorities; 69 | } 70 | 71 | @Override 72 | public String getPassword() { 73 | return user.getPassword(); 74 | } 75 | 76 | @Override 77 | public String getUsername() { 78 | return user.getUserName(); 79 | } 80 | 81 | @Override 82 | public boolean isAccountNonExpired() { 83 | return false; 84 | } 85 | 86 | @Override 87 | public boolean isAccountNonLocked() { 88 | return false; 89 | } 90 | 91 | @Override 92 | public boolean isCredentialsNonExpired() { 93 | return false; 94 | } 95 | 96 | @Override 97 | public boolean isEnabled() { 98 | return user.getUserStatus() != 0; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/config/security/filter/JwtAuthenticationFilter.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.config.security.filter; 2 | 3 | import com.lt.health.config.security.service.UserDetailServiceImpl; 4 | import com.lt.health.utils.JwtTokenUtil; 5 | import lombok.extern.slf4j.Slf4j; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.beans.factory.annotation.Value; 8 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; 9 | import org.springframework.security.core.context.SecurityContextHolder; 10 | import org.springframework.security.core.userdetails.UserDetails; 11 | import org.springframework.security.web.authentication.WebAuthenticationDetails; 12 | import org.springframework.stereotype.Component; 13 | import org.springframework.web.filter.OncePerRequestFilter; 14 | 15 | import javax.servlet.FilterChain; 16 | import javax.servlet.ServletException; 17 | import javax.servlet.http.HttpServletRequest; 18 | import javax.servlet.http.HttpServletResponse; 19 | import java.io.IOException; 20 | 21 | /** 22 | * @description: token过滤器 23 | * @author: 狂小腾 24 | * @date: 2022/3/22 22:56 25 | */ 26 | @Component 27 | @Slf4j 28 | public class JwtAuthenticationFilter extends OncePerRequestFilter { 29 | 30 | @Autowired 31 | private JwtTokenUtil jwtTokenUtil; 32 | 33 | @Autowired 34 | private UserDetailServiceImpl userDetailService; 35 | 36 | @Value("${jwt.tokenHeader}") 37 | private String tokenHeader; 38 | 39 | @Value("${jwt.tokenHead}") 40 | private String tokenHead; 41 | 42 | @Override 43 | protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { 44 | // 1.获取token 45 | String header = request.getHeader(tokenHeader); 46 | // 2.判断token是否存在 47 | if (header != null && header.startsWith(tokenHead)) { 48 | // 拿到token主体 49 | String token = header.substring(tokenHead.length()); 50 | // 根据token获取用户名 51 | String username = jwtTokenUtil.getUserNameFromToken(token); 52 | // 3 token存在,但是没有登录信息 53 | if (username != null && null == SecurityContextHolder.getContext().getAuthentication()) { 54 | // 没有登录信息 直接登录 55 | UserDetails userDetails = userDetailService.loadUserByUsername(username); 56 | // 判断token是否有效 57 | if (!jwtTokenUtil.isExpiration(token) && username.equals(userDetails.getUsername())) { 58 | // 刷新security用户中的信息 59 | UsernamePasswordAuthenticationToken authenticationToken 60 | = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities()); 61 | authenticationToken.setDetails(new WebAuthenticationDetails(request)); 62 | SecurityContextHolder.getContext().setAuthentication(authenticationToken); 63 | } 64 | } 65 | } 66 | // 4.过滤器放行 67 | filterChain.doFilter(request, response); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/config/security/handler/JwtAccessDeniedHandler.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.config.security.handler; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import com.lt.health.constant.Result; 5 | import org.springframework.security.access.AccessDeniedException; 6 | import org.springframework.security.web.access.AccessDeniedHandler; 7 | import org.springframework.stereotype.Component; 8 | 9 | import javax.servlet.ServletException; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | import java.io.IOException; 13 | import java.io.PrintWriter; 14 | 15 | /** 16 | * @description: 没有权限访问时返回结果 17 | * @author: 狂小腾 18 | * @date: 2022/3/22 22:59 19 | */ 20 | @Component 21 | public class JwtAccessDeniedHandler implements AccessDeniedHandler { 22 | @Override 23 | public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException { 24 | response.setCharacterEncoding("UTF-8"); 25 | response.setContentType("application/json"); 26 | response.setStatus(403); 27 | PrintWriter printWriter = response.getWriter(); 28 | printWriter.write(new ObjectMapper().writeValueAsString(Result.fail("权限不足,请联系管理员!"))); 29 | printWriter.flush(); 30 | printWriter.close(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/config/security/handler/JwtAuthenticationEntryPoint.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.config.security.handler; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import com.lt.health.constant.Result; 5 | import org.springframework.security.core.AuthenticationException; 6 | import org.springframework.security.web.AuthenticationEntryPoint; 7 | import org.springframework.stereotype.Component; 8 | 9 | import javax.servlet.ServletException; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | import java.io.IOException; 13 | import java.io.PrintWriter; 14 | 15 | /** 16 | * @description: 当未登录或者token失效访问接口时,自定义的返回结果 17 | * @author: 狂小腾 18 | * @date: 2022/3/22 22:58 19 | */ 20 | @Component 21 | public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint { 22 | @Override 23 | public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { 24 | response.setStatus(401); 25 | response.setCharacterEncoding("UTF-8"); 26 | response.setContentType("application/json"); 27 | PrintWriter writer = response.getWriter(); 28 | writer.write(new ObjectMapper().writeValueAsString(Result.fail("你尚为登录,请登录后操作!"))); 29 | writer.flush(); 30 | writer.close(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/config/security/service/UserDetailServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.config.security.service; 2 | 3 | import com.lt.health.constant.UserConstant; 4 | import com.lt.health.entity.Menu; 5 | import com.lt.health.entity.User; 6 | import com.lt.health.config.security.entity.LoginUser; 7 | import com.lt.health.mapper.MenuMapper; 8 | import com.lt.health.mapper.PermissionMapper; 9 | import com.lt.health.mapper.RoleMapper; 10 | import com.lt.health.mapper.UserMapper; 11 | import com.lt.health.utils.RedisUtil; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.security.core.userdetails.UserDetails; 14 | import org.springframework.security.core.userdetails.UserDetailsService; 15 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 16 | import org.springframework.stereotype.Service; 17 | 18 | import java.util.List; 19 | 20 | /** 21 | * @description: 实现UserDetailsService接口 实现自定义登录逻辑 22 | * @author: 狂小腾 23 | * @date: 2022/3/26 21:01 24 | */ 25 | @Service 26 | public class UserDetailServiceImpl implements UserDetailsService { 27 | 28 | @Autowired 29 | private UserMapper userMapper; 30 | 31 | @Autowired 32 | private RoleMapper roleMapper; 33 | 34 | @Autowired 35 | private PermissionMapper permissionMapper; 36 | 37 | @Autowired 38 | private MenuMapper menuMapper; 39 | 40 | @Autowired 41 | private RedisUtil redisUtil; 42 | 43 | @Override 44 | public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { 45 | User user; 46 | // 1.判断缓存中是否存在该用户 存在直接获取 不存在从数据库中获取并存入缓存中 47 | if (redisUtil.haskey(UserConstant.USER_KEY_PRE + username)) { 48 | // 缓存中存在 直接获取 49 | user = (User) redisUtil.getValue(UserConstant.USER_KEY_PRE + username); 50 | // 设置设置过期时间 5min 51 | redisUtil.expire(UserConstant.USER_KEY_PRE + username, UserConstant.EXPIRE_TIME); 52 | } else { 53 | // 从数据库中根据用户名获取用户 54 | user = userMapper.findByUserName(username); 55 | if (user == null) { 56 | throw new UsernameNotFoundException("用户名或密码错误!!!"); 57 | } 58 | if (user.getIsAdmin() == 1) { 59 | // 管理员拥有所有权限 不需要设置任何查询信息 60 | // 非管理员需要查询角色信息 61 | user.setRoles(roleMapper.findRolesByUserId(null)); 62 | user.setPermissions(permissionMapper.findPermissionsByUserId(null)); 63 | // 获取父级菜单 64 | List menus = menuMapper.findMenusByUserId(null); 65 | // 获取子级菜单 66 | menus.forEach(item -> item.setChildren(menuMapper.findChildrenMenuByPidAndUserId(item.getId(), null))); 67 | user.setMenus(menus); 68 | } else { 69 | // 不是管理员需要设置菜单与角色条件 70 | user.setRoles(roleMapper.findRolesByUserId(user.getId())); 71 | user.setPermissions(permissionMapper.findPermissionsByUserId(user.getId())); 72 | // 获取父级菜单 73 | List menus = menuMapper.findMenusByUserId(user.getId()); 74 | // 获取子级菜单 75 | menus.forEach(item -> item.setChildren(menuMapper.findChildrenMenuByPidAndUserId(item.getId(), user.getId()))); 76 | user.setMenus(menus); 77 | } 78 | // 向redis中存入该用户并指定过期时间 5min 79 | redisUtil.setValueTime(UserConstant.USER_KEY_PRE + username, user, UserConstant.EXPIRE_TIME); 80 | } 81 | return new LoginUser(user); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/constant/Constants.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.constant; 2 | 3 | /** 4 | * @description: 通用常量 5 | * @author: 狂小腾 6 | * @date: 2022/4/10 16:09 7 | */ 8 | public class Constants { 9 | /** 10 | * 验证码 redis key 11 | */ 12 | public static final String CAPTCHA_CODE_KEY = "captcha_codes:"; 13 | 14 | /** 15 | * 登录用户 redis key 16 | */ 17 | public static final String LOGIN_TOKEN_KEY = "login_tokens:"; 18 | 19 | /** 20 | * 验证码有效期(分钟) 21 | */ 22 | public static final Integer CAPTCHA_EXPIRATION = 2; 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/constant/Result.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.constant; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | import lombok.Data; 6 | 7 | import java.io.Serializable; 8 | 9 | /** 10 | * @description: 结果集 11 | * @author: 狂小腾 12 | * @date: 2022/3/21 22:53 13 | */ 14 | @Data 15 | @ApiModel("同一返回结果实体类") 16 | public class Result implements Serializable { 17 | /** 18 | * 响应给前端是否成功的标识 19 | */ 20 | @ApiModelProperty("是否成功 true-成功 false-失败") 21 | private boolean flag; 22 | 23 | /** 24 | * 响应信息 25 | */ 26 | @ApiModelProperty("响应信息") 27 | private String message; 28 | 29 | /** 30 | * 响应数据 31 | */ 32 | @ApiModelProperty("响应数据") 33 | private Object data; 34 | 35 | public Result() { 36 | } 37 | 38 | public Result(boolean flag, String message, Object data) { 39 | this.flag = flag; 40 | this.message = message; 41 | this.data = data; 42 | } 43 | 44 | public Result(boolean flag, String message) { 45 | this.flag = flag; 46 | this.message = message; 47 | } 48 | 49 | /** 50 | * 响应成功的结果 51 | */ 52 | public static Result success(String message, Object data) { 53 | return new Result(true, message, data); 54 | } 55 | 56 | /** 57 | * 响应成功的结果 58 | */ 59 | public static Result success(String message) { 60 | return new Result(true, message); 61 | } 62 | 63 | /** 64 | * 响应失败的结果 65 | */ 66 | public static Result fail(String message) { 67 | return new Result(false, message); 68 | } 69 | } -------------------------------------------------------------------------------- /src/main/java/com/lt/health/constant/TableNameConstant.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.constant; 2 | 3 | /** 4 | * @description: 表名常量类 5 | * @author: 狂小腾 6 | * @date: 2022/4/1 23:15 7 | */ 8 | public interface TableNameConstant { 9 | 10 | /** 11 | * 用户表 12 | */ 13 | String USER_TABLE_NAME = "sys_user"; 14 | 15 | /** 16 | * 食物表 17 | */ 18 | String FOOD_TABLE_NAME = "sys_food"; 19 | 20 | /** 21 | * 食物类别表 22 | */ 23 | String FOOD_TYPE_TABLE_NAME = "sys_food_type"; 24 | 25 | /** 26 | * 用户日志表 27 | */ 28 | String LOG_MESSAGE_TABLE_NAME = "sys_log_message"; 29 | 30 | /** 31 | * 角色表 32 | */ 33 | String ROLE_TABLE_NAME = "sys_role"; 34 | 35 | /** 36 | * 角色-菜单表 37 | */ 38 | String ROLE_MENU_TABLE_NAME = "sys_roles_menus"; 39 | 40 | /** 41 | * 角色权限表 42 | */ 43 | String ROLE_PERMISSIONS_TABLE_NAME = "sys_roles_permissions"; 44 | 45 | /** 46 | * 菜单权限表 47 | */ 48 | String MENU_TABLE_NAME = "sys_menu"; 49 | 50 | /** 51 | * 运动项目表 52 | */ 53 | String MOTION_TABLE_NAME = "sys_motion"; 54 | 55 | /** 56 | * 数据权限表 57 | */ 58 | String PERMISSIONS_TABLE_NAME = "sys_permission"; 59 | 60 | /** 61 | * 运动咨询表 62 | */ 63 | String SPORT_TABLE_NAME = "sys_port"; 64 | 65 | /** 66 | * WX运动步数表 67 | */ 68 | String WX_RUN_TABLE_NAME = "sys_wx_run"; 69 | 70 | /** 71 | * 用户-角色表 72 | */ 73 | String USER_ROLE_TABLE_NAME = "sys_user_roles"; 74 | 75 | /** 76 | * 商品表 77 | */ 78 | String GOODS_TABLE_NAME = "sys_goods"; 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/constant/UserConstant.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.constant; 2 | 3 | /** 4 | * @description: 用户常量信息 5 | * @author: 狂小腾 6 | * @date: 2022/3/28 19:44 7 | */ 8 | public interface UserConstant { 9 | /** 10 | * 用户缓存的key的前缀 11 | */ 12 | String USER_KEY_PRE = "userInfo"; 13 | 14 | /** 15 | * 用户缓存过期时间 5min 16 | */ 17 | long EXPIRE_TIME = 5L; 18 | 19 | /** 20 | * 用户Session的key 21 | */ 22 | String USER_SESSION_KEY = "userSession"; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/controller/CaptchaController.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.controller; 2 | 3 | import cn.hutool.core.codec.Base64; 4 | import cn.hutool.core.lang.UUID; 5 | import com.google.code.kaptcha.Producer; 6 | import com.lt.health.constant.Constants; 7 | import com.lt.health.constant.MessageConstant; 8 | import com.lt.health.constant.Result; 9 | import com.lt.health.utils.RedisUtil; 10 | import io.swagger.annotations.Api; 11 | import io.swagger.annotations.ApiOperation; 12 | import lombok.extern.slf4j.Slf4j; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.beans.factory.annotation.Value; 15 | import org.springframework.util.FastByteArrayOutputStream; 16 | import org.springframework.web.bind.annotation.GetMapping; 17 | import org.springframework.web.bind.annotation.RestController; 18 | 19 | import javax.annotation.Resource; 20 | import javax.imageio.ImageIO; 21 | import java.awt.image.BufferedImage; 22 | import java.io.IOException; 23 | import java.util.HashMap; 24 | import java.util.Map; 25 | 26 | /** 27 | * @description: 验证码控制器 28 | * @author: 狂小腾 29 | * @date: 2022/4/10 16:01 30 | */ 31 | @RestController 32 | @Api(tags = "验证码控制器") 33 | @Slf4j 34 | public class CaptchaController { 35 | 36 | @Autowired 37 | private RedisUtil redisUtil; 38 | 39 | @Resource(name = "captchaProducer") 40 | private Producer captchaProducer; 41 | 42 | @Resource(name = "captchaProducerMath") 43 | private Producer captchaProducerMath; 44 | 45 | @Value("${lt.captchaType}") 46 | private String captchaType; 47 | 48 | /** 49 | * 生成验证码 50 | */ 51 | @GetMapping("/captchaImage") 52 | @ApiOperation("生成验证码接口") 53 | public Result getCode() throws IOException { 54 | // 1.生成验证码的key 55 | String uuid = UUID.randomUUID().toString(); 56 | String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid; 57 | 58 | String capStr = null, code = null; 59 | BufferedImage image = null; 60 | 61 | // 2.生成验证码 62 | if ("math".equals(captchaType)) { 63 | String capText = captchaProducerMath.createText(); 64 | capStr = capText.substring(0, capText.lastIndexOf("@")); 65 | code = capText.substring(capText.lastIndexOf("@") + 1); 66 | image = captchaProducerMath.createImage(capStr); 67 | } else if ("char".equals(captchaType)) { 68 | capStr = code = captchaProducer.createText(); 69 | image = captchaProducer.createImage(capStr); 70 | } 71 | log.info("验证码为:{}", capStr); 72 | log.info("结果为:{}", code); 73 | // 3.存入redis中 2min 74 | redisUtil.setValueTime(verifyKey, code, Constants.CAPTCHA_EXPIRATION); 75 | // 4.转换流信息写出 76 | FastByteArrayOutputStream os = new FastByteArrayOutputStream(); 77 | try { 78 | ImageIO.write(image, "jpg", os); 79 | } catch (IOException e) { 80 | return Result.fail(e.getMessage()); 81 | } 82 | 83 | // 5.返回给前端key和image 84 | Map map = new HashMap<>(2); 85 | map.put("uuid", uuid); 86 | map.put("image", Base64.encode(os.toByteArray())); 87 | return Result.success(MessageConstant.CAPTCHA_IMAGE_SEND_SUCCESS, map); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/controller/LogMessageController.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.controller; 2 | 3 | import com.lt.health.constant.MessageConstant; 4 | import com.lt.health.constant.Result; 5 | import com.lt.health.entity.LogMessage; 6 | import com.lt.health.service.LogMessageService; 7 | import io.swagger.annotations.Api; 8 | import io.swagger.annotations.ApiOperation; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.web.bind.annotation.GetMapping; 11 | import org.springframework.web.bind.annotation.RequestMapping; 12 | import org.springframework.web.bind.annotation.RestController; 13 | 14 | import java.util.List; 15 | 16 | /** 17 | * @description: 日志控制器 18 | * @author: 狂小腾 19 | * @date: 2022/4/1 23:50 20 | */ 21 | @RestController 22 | @RequestMapping("/logMessage") 23 | @Api(tags = "日志接口") 24 | public class LogMessageController { 25 | 26 | @Autowired 27 | private LogMessageService logMessageService; 28 | 29 | @GetMapping("/findAll") 30 | @ApiOperation("查看用户日志接口") 31 | public Result findAll() { 32 | List list = logMessageService.list(); 33 | return Result.success(MessageConstant.LOG_MESSAGE_SELECT_SUCCESS, list); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/controller/MenuController.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.controller; 2 | 3 | import com.lt.health.aop.log.SystemCrmLog; 4 | import com.lt.health.constant.MessageConstant; 5 | import com.lt.health.constant.Result; 6 | import com.lt.health.constant.TableNameConstant; 7 | import com.lt.health.entity.Menu; 8 | import com.lt.health.entity.dto.PageInfoDTO; 9 | import com.lt.health.service.MenuService; 10 | import io.swagger.annotations.Api; 11 | import io.swagger.annotations.ApiOperation; 12 | import org.apache.commons.lang3.StringUtils; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.web.bind.annotation.*; 15 | 16 | /** 17 | * @description: 菜单控制器 18 | * @author: 狂小腾 19 | * @date: 2022/3/22 11:07 20 | */ 21 | @RestController 22 | @RequestMapping("/menu") 23 | @Api(tags = "菜单接口") 24 | public class MenuController { 25 | 26 | @Autowired 27 | private MenuService menuService; 28 | 29 | /** 30 | * 查询所有的父级菜单 31 | * 32 | * @return 父级菜单 33 | */ 34 | @GetMapping("/findParent") 35 | @ApiOperation("查询所有父级菜单接口") 36 | public Result findParentMenu() { 37 | return menuService.findParentMenu(); 38 | } 39 | 40 | /** 41 | * 分页查询 42 | * 43 | * @param pageInfoDTO 查询条件---菜单标题 44 | * @return 分页结果 45 | */ 46 | @PostMapping("/findPage") 47 | @ApiOperation("分页查询所有菜单接口") 48 | public Result findPage(@RequestBody PageInfoDTO pageInfoDTO) { 49 | Integer pageNumber = pageInfoDTO.getPageNumber(); 50 | Integer pageSize = pageInfoDTO.getPageSize(); 51 | if (StringUtils.isAnyBlank(String.valueOf(pageNumber), String.valueOf(pageSize))) { 52 | return Result.fail(MessageConstant.PAGE_FAIL); 53 | } 54 | return menuService.findPage(pageInfoDTO); 55 | } 56 | 57 | /** 58 | * 添加菜单接口 59 | * 60 | * @param menu 添加菜单信息 61 | * @return 成功或者失败信息 62 | */ 63 | @PostMapping("/insert") 64 | @ApiOperation("添加菜单接口") 65 | @SystemCrmLog(description = "进行添加菜单操作", tableName = {TableNameConstant.MENU_TABLE_NAME}) 66 | public Result insert(@RequestBody Menu menu) { 67 | return menuService.insert(menu); 68 | } 69 | 70 | /** 71 | * 更新菜单接口 72 | * 73 | * @param menu 更新的菜单信息 74 | * @return 修改提示信息 75 | */ 76 | @PutMapping("/update") 77 | @ApiOperation("修改菜单接口") 78 | @SystemCrmLog(description = "进行更新菜单操作", tableName = {TableNameConstant.MENU_TABLE_NAME}) 79 | public Result update(@RequestBody Menu menu) { 80 | return menuService.update(menu); 81 | } 82 | 83 | /** 84 | * 删除菜单接口 85 | * 86 | * @param id 菜单id 87 | * @return 删除提示信息 88 | */ 89 | @DeleteMapping("/delete/{id}") 90 | @ApiOperation("删除菜单接口") 91 | @SystemCrmLog(description = "进行删除菜单操作", tableName = {TableNameConstant.MENU_TABLE_NAME}) 92 | public Result delete(@PathVariable("id") long id) { 93 | return menuService.delete(id); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/controller/MotionController.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.controller; 2 | 3 | import com.lt.health.aop.log.SystemCrmLog; 4 | import com.lt.health.constant.MessageConstant; 5 | import com.lt.health.constant.Result; 6 | import com.lt.health.constant.TableNameConstant; 7 | import com.lt.health.entity.Motion; 8 | import com.lt.health.entity.dto.PageInfoDTO; 9 | import com.lt.health.service.MotionService; 10 | import io.swagger.annotations.Api; 11 | import io.swagger.annotations.ApiOperation; 12 | import org.apache.commons.lang3.StringUtils; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.web.bind.annotation.*; 15 | 16 | /** 17 | * @description: 运动项目控制器 18 | * @author: 狂小腾 19 | * @date: 2022/4/1 13:15 20 | */ 21 | @RestController 22 | @RequestMapping("/motion") 23 | @Api(tags = "运动项目接口") 24 | public class MotionController { 25 | 26 | @Autowired 27 | private MotionService motionService; 28 | 29 | /** 30 | * 查询单个运动项目 31 | * 32 | * @param id 运动项目id 33 | * @return 该运动项目信息 34 | */ 35 | @GetMapping("/{id}") 36 | @SystemCrmLog(description = "进行查看单个运动项目操作", tableName = {TableNameConstant.MOTION_TABLE_NAME}) 37 | @ApiOperation("查询单个运动项目接口") 38 | public Result findInfo(@PathVariable Long id) { 39 | return motionService.findInfo(id); 40 | } 41 | 42 | /** 43 | * 分页查询 44 | * 45 | * @param pageInfoDTO 分页参数---根据运动项目名称 46 | * @return 分页结果集 47 | */ 48 | @PostMapping("/findPage") 49 | @SystemCrmLog(description = "进行查看运动项目操作", tableName = {TableNameConstant.MOTION_TABLE_NAME}) 50 | @ApiOperation("运动项目分页查询接口") 51 | public Result findPage(@RequestBody PageInfoDTO pageInfoDTO) { 52 | Integer pageNumber = pageInfoDTO.getPageNumber(); 53 | Integer pageSize = pageInfoDTO.getPageSize(); 54 | if (StringUtils.isAnyBlank(String.valueOf(pageNumber), String.valueOf(pageSize))) { 55 | return Result.fail(MessageConstant.PAGE_FAIL); 56 | } 57 | return motionService.findPage(pageInfoDTO); 58 | } 59 | 60 | /** 61 | * 增加运动项目 62 | * 63 | * @param sport 运动项目 64 | * @return 成功或失败信息 65 | */ 66 | @SystemCrmLog(description = "进行增加运动项目操作", tableName = {TableNameConstant.MOTION_TABLE_NAME}) 67 | @PostMapping("/add") 68 | @ApiOperation("增加运动项目接口") 69 | public Result add(@RequestBody Motion sport) { 70 | return motionService.add(sport); 71 | } 72 | 73 | /** 74 | * 修改运动项目名称 75 | * 76 | * @param sport 运动项目 77 | * @return 成功或失败信息 78 | */ 79 | @PutMapping("/edit") 80 | @ApiOperation("修改运动项目接口") 81 | @SystemCrmLog(description = "进行修改运动项目操作", tableName = {TableNameConstant.MOTION_TABLE_NAME}) 82 | public Result edit(@RequestBody Motion sport) { 83 | return motionService.edit(sport); 84 | } 85 | 86 | /** 87 | * 删除运动项目 88 | * 89 | * @param id 运动项目id 90 | * @return 成功或失败 91 | */ 92 | @DeleteMapping("/delete/{id}") 93 | @ApiOperation("删除运动项目接口") 94 | @SystemCrmLog(description = "进行删除运动项目操作", tableName = {TableNameConstant.MOTION_TABLE_NAME}) 95 | public Result delete(@PathVariable Long id) { 96 | return motionService.delete(id); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/controller/OrderController.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.controller; 2 | 3 | /** 4 | * @description: 订单控制器 5 | * @author: 狂小腾 6 | * @date: 2022/3/22 11:34 7 | */ 8 | public class OrderController { 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/controller/PermissionController.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.controller; 2 | 3 | import com.lt.health.constant.MessageConstant; 4 | import com.lt.health.constant.Result; 5 | import com.lt.health.entity.Permission; 6 | import com.lt.health.entity.dto.PageInfoDTO; 7 | import com.lt.health.service.PermissionService; 8 | import io.swagger.annotations.Api; 9 | import io.swagger.annotations.ApiOperation; 10 | import org.apache.commons.lang3.StringUtils; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.web.bind.annotation.*; 13 | 14 | /** 15 | * @description: 数据权限控制器 16 | * @author: 狂小腾 17 | * @date: 2022/3/31 14:00 18 | */ 19 | @RestController 20 | @RequestMapping("/permission") 21 | @Api(tags = "数据权限接口") 22 | public class PermissionController { 23 | 24 | @Autowired 25 | private PermissionService permissionService; 26 | 27 | /** 28 | * 查询所有的权限 29 | * 30 | * @return 返回结果 31 | */ 32 | @GetMapping("/findAll") 33 | @ApiOperation("查看所有权限接口") 34 | public Result findAll() { 35 | return permissionService.findAll(); 36 | } 37 | 38 | /** 39 | * 分页查询 40 | * 41 | * @param pageInfoDTO 分页参数---权限标签或数据权限标签 42 | * @return 分页结果 43 | */ 44 | @PostMapping("/findPage") 45 | @ApiOperation("数据权限分页查询接口") 46 | public Result findPage(@RequestBody PageInfoDTO pageInfoDTO) { 47 | Integer pageNumber = pageInfoDTO.getPageNumber(); 48 | Integer pageSize = pageInfoDTO.getPageSize(); 49 | if (StringUtils.isAnyBlank(String.valueOf(pageNumber), String.valueOf(pageSize))) { 50 | return Result.fail(MessageConstant.PAGE_FAIL); 51 | } 52 | return permissionService.findPage(pageInfoDTO); 53 | } 54 | 55 | /** 56 | * 添加权限 57 | * 58 | * @param permission 添加权限数据 59 | * @return 成功或失败结果 60 | */ 61 | @PostMapping("/insert") 62 | @ApiOperation("添加数据权限接口") 63 | public Result insert(@RequestBody Permission permission) { 64 | return permissionService.insert(permission); 65 | } 66 | 67 | /** 68 | * 修改权限 69 | * 70 | * @param permission 修改的权限数据 71 | * @return 成功或失败的结果 72 | */ 73 | @PutMapping("/update") 74 | @ApiOperation("修改数据权限接口") 75 | public Result update(@RequestBody Permission permission) { 76 | return permissionService.update(permission); 77 | } 78 | 79 | /** 80 | * 删除权限 81 | * 82 | * @param id 权限id 83 | * @return 成功或失败结果 84 | */ 85 | @DeleteMapping("/delete/{id}") 86 | @ApiOperation("删除数据权限接口") 87 | public Result delete(@PathVariable("id") Long id) { 88 | return permissionService.delete(id); 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/controller/RoleController.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.controller; 2 | 3 | import com.lt.health.constant.MessageConstant; 4 | import com.lt.health.constant.Result; 5 | import com.lt.health.entity.Role; 6 | import com.lt.health.entity.dto.PageInfoDTO; 7 | import com.lt.health.service.RoleService; 8 | import io.swagger.annotations.Api; 9 | import io.swagger.annotations.ApiOperation; 10 | import org.apache.commons.lang3.StringUtils; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.web.bind.annotation.*; 13 | 14 | /** 15 | * @description: 角色控制器 16 | * @author: 狂小腾 17 | * @date: 2022/3/28 22:42 18 | */ 19 | @RestController 20 | @RequestMapping("/role") 21 | @Api(tags = "用户角色控制接口") 22 | public class RoleController { 23 | 24 | @Autowired 25 | private RoleService roleService; 26 | 27 | /** 28 | * 添加用户时角色信息列表 29 | */ 30 | @GetMapping("/findAll") 31 | public Result findAll() { 32 | return roleService.findAll(); 33 | } 34 | 35 | /** 36 | * 分页查询 37 | * 38 | * @param pageInfoDTO 分页参数 39 | * @return 分页结果集 40 | */ 41 | @PostMapping("/findPage") 42 | @ApiOperation("角色分页查询接口") 43 | public Result findPage(@RequestBody PageInfoDTO pageInfoDTO) { 44 | Integer pageNumber = pageInfoDTO.getPageNumber(); 45 | Integer pageSize = pageInfoDTO.getPageSize(); 46 | if (StringUtils.isAnyBlank(String.valueOf(pageNumber), String.valueOf(pageSize))) { 47 | return Result.fail(MessageConstant.ROLE_SELECT_FAIL); 48 | } 49 | return roleService.findPage(pageInfoDTO); 50 | } 51 | 52 | /** 53 | * 添加角色 54 | * 55 | * @param role 角色信息 56 | * @return 成功或者失败信息 57 | */ 58 | @PostMapping("/insert") 59 | @ApiOperation("添加角色接口") 60 | public Result insert(@RequestBody Role role) { 61 | String label = role.getLabel(); 62 | String code = role.getCode(); 63 | if (StringUtils.isAnyBlank(label, code)) { 64 | return Result.fail(MessageConstant.COMPLETE_USER_INFO); 65 | } 66 | return roleService.insert(role); 67 | } 68 | 69 | /** 70 | * 修改角色 71 | * 72 | * @param role 角色信息 73 | * @return 修改提示信息 74 | */ 75 | @PutMapping("/update") 76 | @ApiOperation("修改角色接口") 77 | public Result update(@RequestBody Role role) { 78 | return roleService.update(role); 79 | } 80 | 81 | /** 82 | * 删除角色 83 | * 84 | * @param roleId 角色id 85 | * @return 删除提示信息 86 | */ 87 | @DeleteMapping("/delete/{id}") 88 | @ApiOperation("删除角色接口") 89 | public Result delete(@PathVariable("id") Long roleId) { 90 | return roleService.delete(roleId); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/controller/SportController.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.controller; 2 | 3 | import com.lt.health.aop.log.SystemCrmLog; 4 | import com.lt.health.constant.MessageConstant; 5 | import com.lt.health.constant.Result; 6 | import com.lt.health.constant.TableNameConstant; 7 | import com.lt.health.entity.Sport; 8 | import com.lt.health.entity.dto.PageInfoDTO; 9 | import com.lt.health.service.SportService; 10 | import io.swagger.annotations.Api; 11 | import io.swagger.annotations.ApiOperation; 12 | import org.apache.commons.lang3.StringUtils; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.web.bind.annotation.*; 15 | 16 | /** 17 | * @description: 运动咨询控制器 18 | * @author: 狂小腾 19 | * @date: 2022/3/31 15:40 20 | */ 21 | @RestController 22 | @RequestMapping("/sport") 23 | @Api(tags = "运动咨询管理接口") 24 | public class SportController { 25 | 26 | @Autowired 27 | private SportService sportService; 28 | 29 | /** 30 | * 分页查询 31 | * 32 | * @param pageInfoDTO 分页参数条件---标题或者内容 33 | * @return 分页结果 34 | */ 35 | @PostMapping("/findPage") 36 | @ApiOperation("分页查询接口") 37 | public Result findPage(@RequestBody PageInfoDTO pageInfoDTO) { 38 | Integer pageNumber = pageInfoDTO.getPageNumber(); 39 | Integer pageSize = pageInfoDTO.getPageSize(); 40 | if (StringUtils.isAnyBlank(String.valueOf(pageNumber), String.valueOf(pageSize))) { 41 | return Result.fail(MessageConstant.PAGE_FAIL); 42 | } 43 | return sportService.findPage(pageInfoDTO); 44 | } 45 | 46 | /** 47 | * 获取运动咨询详细信息 48 | * 49 | * @param id id 50 | * @return 详细信息 51 | */ 52 | @GetMapping("/{id}") 53 | @SystemCrmLog(description = "进行获取运动咨询操作", tableName = TableNameConstant.SPORT_TABLE_NAME) 54 | @ApiOperation("获取运动咨询详细信息接口") 55 | public Result getInfo(@PathVariable Long id) { 56 | return sportService.getInfo(id); 57 | } 58 | 59 | /** 60 | * 添加运动咨询 61 | * 62 | * @param sport 添加运动咨询信息 63 | * @return 成功或者失败信息 64 | */ 65 | @PostMapping("/insert") 66 | @SystemCrmLog(description = "进行添加运动咨询操作", tableName = TableNameConstant.SPORT_TABLE_NAME) 67 | @ApiOperation("添加运动咨询接口") 68 | public Result insert(@RequestBody Sport sport) { 69 | return sportService.insert(sport); 70 | } 71 | 72 | /** 73 | * 修改运动咨询信息 74 | * 75 | * @param sport 修改运动咨询信息 76 | * @return 成功或者失败信息 77 | */ 78 | @PutMapping("/update") 79 | @ApiOperation("修改运动咨询接口") 80 | @SystemCrmLog(description = "进行更新运动咨询操作", tableName = TableNameConstant.SPORT_TABLE_NAME) 81 | public Result update(@RequestBody Sport sport) { 82 | return sportService.update(sport); 83 | } 84 | 85 | 86 | /** 87 | * 删除运动咨询信息 88 | * 89 | * @param id id 90 | * @return 删除提示信息 91 | */ 92 | @DeleteMapping("/delete/{id}") 93 | @ApiOperation("删除运动咨询接口") 94 | @SystemCrmLog(description = "进行删除运动咨询操作", tableName = TableNameConstant.SPORT_TABLE_NAME) 95 | public Result delete(@PathVariable("id") Long id) { 96 | return sportService.delete(id); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/controller/TestController.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.controller; 2 | 3 | import com.lt.health.aop.log.SystemCrmLog; 4 | import com.lt.health.constant.TableNameConstant; 5 | import io.swagger.annotations.ApiImplicitParam; 6 | import io.swagger.annotations.ApiOperation; 7 | import org.springframework.security.access.prepost.PreAuthorize; 8 | import org.springframework.web.bind.annotation.GetMapping; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RequestParam; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | /** 14 | * @description: 测试控制器 15 | * @author: 狂小腾 16 | * @date: 2022/3/31 20:58 17 | */ 18 | @RestController 19 | @RequestMapping("/test") 20 | public class TestController { 21 | 22 | /** 23 | * 普通用户没有删除权限 24 | */ 25 | @ApiOperation("测试hello接口") 26 | @ApiImplicitParam(name = "name", value = "用户名称", required = true) 27 | @GetMapping("/hello") 28 | @PreAuthorize("hasAuthority('USER_DELETE')") 29 | @SystemCrmLog(description = "进行测试权限操作", tableName = {TableNameConstant.USER_TABLE_NAME, TableNameConstant.ROLE_TABLE_NAME, TableNameConstant.MENU_TABLE_NAME}) 30 | public String hello(@RequestParam String name) { 31 | return "Hello " + name; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/entity/Food.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.entity; 2 | 3 | import cn.afterturn.easypoi.excel.annotation.Excel; 4 | import com.baomidou.mybatisplus.annotation.IdType; 5 | import com.baomidou.mybatisplus.annotation.TableField; 6 | import com.baomidou.mybatisplus.annotation.TableId; 7 | import com.baomidou.mybatisplus.annotation.TableName; 8 | import com.fasterxml.jackson.annotation.JsonIgnore; 9 | import io.swagger.annotations.ApiModel; 10 | import io.swagger.annotations.ApiModelProperty; 11 | import lombok.Data; 12 | 13 | import java.io.Serializable; 14 | 15 | /** 16 | * 食物详情表 17 | * 18 | * @author: 狂小腾 19 | * @TableName sys_food 20 | */ 21 | @TableName(value = "sys_food") 22 | @Data 23 | @ApiModel("食物实体类") 24 | public class Food implements Serializable { 25 | 26 | @TableId(type = IdType.AUTO) 27 | @ApiModelProperty("主键") 28 | private Long id; 29 | 30 | @Excel(name = "食物名称") 31 | @ApiModelProperty("食物名称") 32 | private String title; 33 | 34 | @ApiModelProperty("食物类别") 35 | private Long typeId; 36 | 37 | @ApiModelProperty("图片地址") 38 | @Excel(name = "食物图片", type = 2) 39 | private String imageUrls; 40 | 41 | @Excel(name = "营养元素") 42 | @ApiModelProperty("营养元素") 43 | private String nutrient; 44 | 45 | @Excel(name = "热量") 46 | @ApiModelProperty("热量") 47 | private Float heat; 48 | 49 | @Excel(name = "蛋白质") 50 | @ApiModelProperty("蛋白质") 51 | private Float protein; 52 | 53 | @Excel(name = "脂肪") 54 | @ApiModelProperty("脂肪") 55 | private Float fat; 56 | 57 | @Excel(name = "碳水化合物") 58 | @ApiModelProperty("碳水化合物") 59 | private Float carbonWater; 60 | 61 | @Excel(name = "膳食纤维") 62 | @ApiModelProperty("膳食纤维") 63 | private Float dietaryFiber; 64 | 65 | @Excel(name = "维生素A") 66 | @ApiModelProperty("维生素A") 67 | private Float vitaminA; 68 | 69 | @Excel(name = "维生素C") 70 | @ApiModelProperty("维生素C") 71 | private Float vitaminC; 72 | 73 | @Excel(name = "维生素E") 74 | @ApiModelProperty("维生素E") 75 | private Float vitaminE; 76 | 77 | @Excel(name = "胡萝卜素") 78 | @ApiModelProperty("胡萝卜素") 79 | private Float carrot; 80 | 81 | @Excel(name = "维生素B1") 82 | @ApiModelProperty("维生素B1") 83 | private Float vitaminB1; 84 | 85 | @Excel(name = "维生素B2") 86 | @ApiModelProperty("维生素B2") 87 | private Float vitaminB2; 88 | 89 | @Excel(name = "烟酸") 90 | @ApiModelProperty("烟酸") 91 | private Float niacin; 92 | 93 | @Excel(name = "胆固醇") 94 | @ApiModelProperty("胆固醇") 95 | private Float cholesterol; 96 | 97 | @Excel(name = "镁") 98 | @ApiModelProperty("镁") 99 | private Float magnesium; 100 | 101 | @Excel(name = "铁") 102 | @ApiModelProperty("铁") 103 | private Float iron; 104 | 105 | @Excel(name = "钙") 106 | @ApiModelProperty("钙") 107 | private Float calcium; 108 | 109 | @Excel(name = "锌") 110 | @ApiModelProperty("锌") 111 | private Float zinc; 112 | 113 | @Excel(name = "铜") 114 | @ApiModelProperty("铜") 115 | private Float copper; 116 | 117 | @Excel(name = "锰") 118 | @ApiModelProperty("锰") 119 | private Float manganese; 120 | 121 | @Excel(name = "钾") 122 | @ApiModelProperty("钾") 123 | private Float potassium; 124 | 125 | @Excel(name = "磷") 126 | @ApiModelProperty("磷") 127 | private Float phosphorus; 128 | 129 | @Excel(name = "钠") 130 | @ApiModelProperty("钠") 131 | private Float sodium; 132 | 133 | @Excel(name = "硒") 134 | @ApiModelProperty("硒") 135 | private Float selenium; 136 | 137 | @Excel(name = "食物类别标题") 138 | @TableField(exist = false) 139 | @ApiModelProperty("食物分类标题") 140 | @JsonIgnore 141 | private String typeTitle; 142 | 143 | @TableField(exist = false) 144 | private static final long serialVersionUID = 1L; 145 | } -------------------------------------------------------------------------------- /src/main/java/com/lt/health/entity/FoodType.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.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 io.swagger.annotations.ApiModel; 8 | import io.swagger.annotations.ApiModelProperty; 9 | import lombok.Data; 10 | 11 | import java.io.Serializable; 12 | import java.util.List; 13 | 14 | /** 15 | * 食物分类表 16 | * 17 | * @author: 狂小腾 18 | * @TableName sys_food_type 19 | */ 20 | @TableName(value = "sys_food_type") 21 | @Data 22 | @ApiModel("食物分类实体类") 23 | public class FoodType implements Serializable { 24 | /** 25 | * 主键 26 | */ 27 | @TableId(type = IdType.AUTO) 28 | @ApiModelProperty("主键id") 29 | private Long id; 30 | 31 | /** 32 | * 分类标题 33 | */ 34 | @ApiModelProperty("分类标题") 35 | private String title; 36 | 37 | /** 38 | * 分类图标 39 | */ 40 | @ApiModelProperty("分类图标") 41 | private String icon; 42 | 43 | /** 44 | * 食物下的分类 45 | */ 46 | @TableField(exist = false) 47 | @ApiModelProperty("食物下的分类") 48 | private List foods; 49 | 50 | @TableField(exist = false) 51 | private static final long serialVersionUID = 1L; 52 | } -------------------------------------------------------------------------------- /src/main/java/com/lt/health/entity/Goods.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.entity; 2 | 3 | import com.alibaba.excel.annotation.ExcelIgnore; 4 | import com.alibaba.excel.annotation.ExcelProperty; 5 | import com.baomidou.mybatisplus.annotation.IdType; 6 | import com.baomidou.mybatisplus.annotation.TableField; 7 | import com.baomidou.mybatisplus.annotation.TableId; 8 | import com.baomidou.mybatisplus.annotation.TableName; 9 | import com.fasterxml.jackson.annotation.JsonFormat; 10 | import io.swagger.annotations.ApiModel; 11 | import io.swagger.annotations.ApiModelProperty; 12 | import lombok.Data; 13 | 14 | import java.io.Serializable; 15 | import java.util.Date; 16 | 17 | /** 18 | * 商品表 19 | * 20 | * @author 狂小腾 21 | * @TableName sys_goods 22 | */ 23 | @TableName(value = "sys_goods") 24 | @Data 25 | @ApiModel("商品实体类") 26 | public class Goods implements Serializable { 27 | /** 28 | * 主键id 29 | */ 30 | @ExcelIgnore 31 | @TableId(type = IdType.AUTO) 32 | @ApiModelProperty("主键id") 33 | private Long id; 34 | 35 | /** 36 | * 商品名称 37 | */ 38 | @ExcelProperty(value = "商品名称") 39 | @ApiModelProperty("商品名称") 40 | private String name; 41 | 42 | /** 43 | * 商品价格 44 | */ 45 | @ExcelProperty(value = "商品价格") 46 | @ApiModelProperty("商品价格") 47 | private Double price; 48 | 49 | /** 50 | * 商品数量 51 | */ 52 | @ExcelProperty(value = "商品数量") 53 | @ApiModelProperty("商品数量") 54 | private Integer number; 55 | 56 | /** 57 | * 入库时间 58 | */ 59 | @ExcelProperty(value = "入库时间") 60 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 61 | @ApiModelProperty("商品入库时间") 62 | private Date createTime; 63 | 64 | /** 65 | * 入库的管理员 66 | */ 67 | @ExcelIgnore 68 | @ApiModelProperty("入库的管理员") 69 | private Long createUserId; 70 | 71 | /** 72 | * 图片地址 73 | */ 74 | @ExcelIgnore 75 | @ApiModelProperty("商品图片地址") 76 | private String imageUrl; 77 | 78 | /** 79 | * 适配机型 80 | */ 81 | @ExcelProperty(value = "适配机型") 82 | @ApiModelProperty("适配机型") 83 | private String modelType; 84 | 85 | /** 86 | * 控制方式 87 | */ 88 | @ApiModelProperty("控制方式") 89 | @ExcelProperty(value = "控制方式") 90 | private String controlMode; 91 | 92 | /** 93 | * 主要功能 94 | */ 95 | @ExcelProperty(value = "主要功能") 96 | @ApiModelProperty("主要功能") 97 | private String mainFunction; 98 | 99 | /** 100 | * 无线功能 101 | */ 102 | @ExcelProperty(value = "无线功能") 103 | @ApiModelProperty("无线功能") 104 | private String wifiFunction; 105 | 106 | /** 107 | * 电池规格 108 | */ 109 | @ExcelProperty(value = "电池规格") 110 | @ApiModelProperty("电池规格") 111 | private String battery; 112 | 113 | /** 114 | * 特色功能 115 | */ 116 | @ExcelProperty(value = "特色功能") 117 | @ApiModelProperty("特色功能") 118 | private String characteristic; 119 | 120 | /** 121 | * 外观尺寸 122 | */ 123 | @ExcelProperty(value = "外观尺寸") 124 | @ApiModelProperty("外观尺寸") 125 | private String size; 126 | 127 | /** 128 | * 其他功能 129 | */ 130 | @ExcelProperty(value = "其他功能") 131 | @ApiModelProperty("其它功能") 132 | private String other; 133 | 134 | /** 135 | * 备注 136 | */ 137 | @ExcelIgnore 138 | @ApiModelProperty("备注") 139 | private String remark; 140 | 141 | @TableField(exist = false) 142 | private static final long serialVersionUID = 1L; 143 | } -------------------------------------------------------------------------------- /src/main/java/com/lt/health/entity/LogMessage.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.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 com.fasterxml.jackson.annotation.JsonIgnore; 8 | import io.swagger.annotations.ApiModel; 9 | import io.swagger.annotations.ApiModelProperty; 10 | import lombok.AllArgsConstructor; 11 | import lombok.Data; 12 | import lombok.NoArgsConstructor; 13 | 14 | import java.io.Serializable; 15 | 16 | /** 17 | * 日志表 18 | * 19 | * @author 狂小腾 20 | * @TableName sys_log_message 21 | */ 22 | @TableName(value = "sys_log_message") 23 | @Data 24 | @AllArgsConstructor 25 | @NoArgsConstructor 26 | @ApiModel("日志实体类") 27 | public class LogMessage implements Serializable { 28 | /** 29 | * 主键id 30 | */ 31 | @TableId(type = IdType.AUTO) 32 | @ApiModelProperty("主键id") 33 | private Integer id; 34 | 35 | /** 36 | * 用户姓名 37 | */ 38 | @ApiModelProperty("用户姓名") 39 | private String userName; 40 | 41 | /** 42 | * 日志表述 43 | */ 44 | @ApiModelProperty("日志描述") 45 | private String content; 46 | 47 | /** 48 | * 参数集合 49 | */ 50 | @ApiModelProperty("参数集合") 51 | @JsonIgnore 52 | private String remarks; 53 | 54 | /** 55 | * 表格名称 56 | */ 57 | @ApiModelProperty("操作表格名称") 58 | private String tableName; 59 | 60 | /** 61 | * 操作时间 62 | */ 63 | @ApiModelProperty("操作时间") 64 | private String dateTime; 65 | 66 | /** 67 | * 返回值 68 | */ 69 | @ApiModelProperty("返回值") 70 | private String resultValue; 71 | 72 | /** 73 | * ip地址 74 | */ 75 | @ApiModelProperty("ip地址") 76 | private String ip; 77 | 78 | /** 79 | * 请求地址 80 | */ 81 | @ApiModelProperty("请求地址") 82 | private String requestUrl; 83 | 84 | /** 85 | * 操作结果 86 | */ 87 | @ApiModelProperty("操作结果") 88 | private String result; 89 | 90 | /** 91 | * 错误信息 92 | */ 93 | @ApiModelProperty("错误信息") 94 | private String exString; 95 | 96 | @TableField(exist = false) 97 | private static final long serialVersionUID = 1L; 98 | } -------------------------------------------------------------------------------- /src/main/java/com/lt/health/entity/Menu.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.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 io.swagger.annotations.ApiModel; 8 | import io.swagger.annotations.ApiModelProperty; 9 | import lombok.Data; 10 | 11 | import java.io.Serializable; 12 | import java.util.List; 13 | 14 | /** 15 | * 菜单表 16 | * 17 | * @author 狂小腾 18 | * @TableName sys_menu 19 | */ 20 | @TableName(value = "sys_menu") 21 | @Data 22 | @ApiModel("菜单实体类") 23 | public class Menu implements Serializable { 24 | /** 25 | * 主键 26 | */ 27 | @TableId(type = IdType.AUTO) 28 | @ApiModelProperty("主键id") 29 | private Long id; 30 | 31 | /** 32 | * 菜单路径 33 | */ 34 | @ApiModelProperty("菜单路径") 35 | private String path; 36 | 37 | /** 38 | * 菜单图标 39 | */ 40 | @ApiModelProperty("菜单图标") 41 | private String icon; 42 | 43 | /** 44 | * 菜单名称 45 | */ 46 | @ApiModelProperty("菜单名称") 47 | private String title; 48 | 49 | /** 50 | * 菜单组件 51 | */ 52 | @ApiModelProperty("菜单组件") 53 | private String component; 54 | 55 | /** 56 | * 父级菜单 57 | */ 58 | @ApiModelProperty("父级菜单id") 59 | private Long parentId; 60 | 61 | /** 62 | * 显示状态(0不显示、1显示) 63 | */ 64 | @ApiModelProperty("菜单显示状态 0-不显示 1-显示") 65 | private boolean status; 66 | 67 | /** 68 | * 子菜单 69 | */ 70 | @TableField(exist = false) 71 | @ApiModelProperty("子菜单") 72 | private List children; 73 | 74 | @TableField(exist = false) 75 | private static final long serialVersionUID = 1L; 76 | } -------------------------------------------------------------------------------- /src/main/java/com/lt/health/entity/Motion.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.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 io.swagger.annotations.ApiModel; 8 | import io.swagger.annotations.ApiModelProperty; 9 | import lombok.Data; 10 | 11 | import java.io.Serializable; 12 | 13 | /** 14 | * 运动项目表 15 | * 16 | * @author 狂小腾 17 | * @TableName sys_motion 18 | */ 19 | @TableName(value = "sys_motion") 20 | @Data 21 | @ApiModel("运动项目实体类") 22 | public class Motion implements Serializable { 23 | /** 24 | * 主键 25 | */ 26 | @ApiModelProperty("主键id") 27 | @TableId(type = IdType.AUTO) 28 | private Integer id; 29 | 30 | /** 31 | * 运动名称 32 | */ 33 | @ApiModelProperty("运动名称") 34 | private String name; 35 | 36 | /** 37 | * 适用年龄 38 | */ 39 | @ApiModelProperty("适用年龄") 40 | private String applicableAge; 41 | 42 | /** 43 | * 身体收益部位 44 | */ 45 | @ApiModelProperty("身体收益部位") 46 | 47 | private String beneficialPosition; 48 | 49 | /** 50 | * 简介(对该运动的描述) 51 | */ 52 | @ApiModelProperty("简介") 53 | private String introduction; 54 | 55 | @TableField(exist = false) 56 | private static final long serialVersionUID = 1L; 57 | } -------------------------------------------------------------------------------- /src/main/java/com/lt/health/entity/Permission.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.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 io.swagger.annotations.ApiModel; 8 | import io.swagger.annotations.ApiModelProperty; 9 | import lombok.Data; 10 | 11 | import java.io.Serializable; 12 | 13 | /** 14 | * 数据权限表 15 | * 16 | * @author 狂小腾 17 | * @TableName sys_permission 18 | */ 19 | @TableName(value = "sys_permission") 20 | @Data 21 | @ApiModel("数据权限实体类") 22 | public class Permission implements Serializable { 23 | /** 24 | * 主键 25 | */ 26 | @TableId(type = IdType.AUTO) 27 | @ApiModelProperty("主键id") 28 | private Long id; 29 | 30 | /** 31 | * 权限标签 32 | */ 33 | @ApiModelProperty("权限标签") 34 | private String label; 35 | 36 | /** 37 | * 数据权限标签值 38 | */ 39 | @ApiModelProperty("权限标签值") 40 | private String code; 41 | 42 | /** 43 | * 显示状态(0不显示、1显示) 44 | */ 45 | @ApiModelProperty("数据权限显示状态 0-不显示 1-显示") 46 | private boolean status; 47 | 48 | @TableField(exist = false) 49 | private static final long serialVersionUID = 1L; 50 | } -------------------------------------------------------------------------------- /src/main/java/com/lt/health/entity/Role.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.*; 4 | import io.swagger.annotations.ApiModel; 5 | import io.swagger.annotations.ApiModelProperty; 6 | import lombok.Data; 7 | 8 | import java.io.Serializable; 9 | import java.util.List; 10 | 11 | /** 12 | * 角色表 13 | * 14 | * @author 狂小腾 15 | * @TableName sys_role 16 | */ 17 | @TableName(value = "sys_role") 18 | @Data 19 | @ApiModel("角色实体类") 20 | public class Role implements Serializable { 21 | /** 22 | * 主键 23 | */ 24 | @TableId(type = IdType.AUTO) 25 | @ApiModelProperty("主键id") 26 | private Long id; 27 | 28 | /** 29 | * 角色标签 30 | */ 31 | @ApiModelProperty("角色标签") 32 | private String label; 33 | 34 | /** 35 | * 角色对应的标签值 36 | */ 37 | @ApiModelProperty("角色对应的标签值") 38 | private String code; 39 | 40 | /** 41 | * 显示状态(0不显示、1显示) 42 | */ 43 | @ApiModelProperty("角色显示状态 0-不显示 1-显示") 44 | private boolean status; 45 | 46 | @TableLogic 47 | @ApiModelProperty("受否删除") 48 | private Integer isDelete; 49 | 50 | /** 51 | * 菜单列表 52 | */ 53 | @ApiModelProperty("菜单列表") 54 | @TableField(exist = false) 55 | private List menus; 56 | 57 | /** 58 | * 权限列表 59 | */ 60 | @TableField(exist = false) 61 | @ApiModelProperty("数据权限列表") 62 | private List permissions; 63 | 64 | @TableField(exist = false) 65 | private static final long serialVersionUID = 1L; 66 | } -------------------------------------------------------------------------------- /src/main/java/com/lt/health/entity/RolesMenus.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.TableField; 4 | import com.baomidou.mybatisplus.annotation.TableName; 5 | import io.swagger.annotations.ApiModel; 6 | import io.swagger.annotations.ApiModelProperty; 7 | import lombok.Data; 8 | 9 | import java.io.Serializable; 10 | 11 | /** 12 | * 角色-菜单权限表 13 | * 14 | * @author 狂小腾 15 | * @TableName sys_roles_menus 16 | */ 17 | @TableName(value = "sys_roles_menus") 18 | @Data 19 | @ApiModel("角色菜单权限实体类") 20 | public class RolesMenus implements Serializable { 21 | /** 22 | * 角色ID 23 | */ 24 | @ApiModelProperty("角色id") 25 | private Long roleId; 26 | 27 | /** 28 | * 菜单权限ID 29 | */ 30 | @ApiModelProperty("菜单id") 31 | private Long menuId; 32 | 33 | @TableField(exist = false) 34 | private static final long serialVersionUID = 1L; 35 | } -------------------------------------------------------------------------------- /src/main/java/com/lt/health/entity/RolesPermissions.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.TableField; 4 | import com.baomidou.mybatisplus.annotation.TableName; 5 | import io.swagger.annotations.ApiModel; 6 | import io.swagger.annotations.ApiModelProperty; 7 | import lombok.Data; 8 | 9 | import java.io.Serializable; 10 | 11 | /** 12 | * 角色-数据权限表 13 | * @author 狂小腾 14 | * @TableName sys_roles_permissions 15 | */ 16 | @TableName(value ="sys_roles_permissions") 17 | @Data 18 | @ApiModel("角色数据权限实体类") 19 | public class RolesPermissions implements Serializable { 20 | /** 21 | * 角色ID 22 | */ 23 | @ApiModelProperty("角色id") 24 | private Long roleId; 25 | 26 | /** 27 | * 数据权限ID 28 | */ 29 | @ApiModelProperty("数据权限id") 30 | private Long permissionId; 31 | 32 | @TableField(exist = false) 33 | private static final long serialVersionUID = 1L; 34 | } -------------------------------------------------------------------------------- /src/main/java/com/lt/health/entity/Sport.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.*; 4 | import com.fasterxml.jackson.annotation.JsonFormat; 5 | import io.swagger.annotations.ApiModel; 6 | import io.swagger.annotations.ApiModelProperty; 7 | import lombok.Data; 8 | 9 | import java.io.Serializable; 10 | import java.util.Date; 11 | 12 | /** 13 | * 运动咨询 14 | * @author 狂小腾 15 | * @TableName sys_sport 16 | */ 17 | @TableName(value ="sys_sport") 18 | @Data 19 | @ApiModel("运动咨询实体类") 20 | public class Sport implements Serializable { 21 | /** 22 | * 主键 23 | */ 24 | @TableId(type = IdType.AUTO) 25 | @ApiModelProperty(value = "主键") 26 | private Long id; 27 | 28 | /** 29 | * 标题 30 | */ 31 | @ApiModelProperty(value = "标题") 32 | private String title; 33 | 34 | /** 35 | * 内容 36 | */ 37 | @ApiModelProperty(value = "内容") 38 | private String content; 39 | 40 | /** 41 | * 创建时间 42 | */ 43 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 44 | @ApiModelProperty(value = "创建时间") 45 | private Date createTime; 46 | 47 | /** 48 | * 创建人 49 | */ 50 | @ApiModelProperty(value = "创建者") 51 | private String createName; 52 | 53 | /** 54 | * 更新时间 55 | */ 56 | @ApiModelProperty(value = "更新时间") 57 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 58 | private Date updateTime; 59 | 60 | /** 61 | * 更新人 62 | */ 63 | @ApiModelProperty(value = "更新者") 64 | private String updateName; 65 | 66 | /** 67 | * 删除标记---逻辑删除 68 | */ 69 | @TableLogic 70 | @ApiModelProperty(value = "删除标记") 71 | private Integer isDelete; 72 | 73 | @TableField(exist = false) 74 | private static final long serialVersionUID = 1L; 75 | } -------------------------------------------------------------------------------- /src/main/java/com/lt/health/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.*; 4 | import io.swagger.annotations.ApiModel; 5 | import io.swagger.annotations.ApiModelProperty; 6 | import lombok.Data; 7 | 8 | import java.io.Serializable; 9 | import java.util.Date; 10 | import java.util.List; 11 | 12 | /** 13 | * 用户实体类 14 | * 15 | * @author 狂小腾 16 | * @TableName sys_user 17 | */ 18 | @TableName(value = "sys_user") 19 | @Data 20 | @ApiModel("用户实体类") 21 | public class User implements Serializable { 22 | /** 23 | * 主键 24 | */ 25 | @TableId(type = IdType.AUTO) 26 | @ApiModelProperty("主键id") 27 | private Long id; 28 | 29 | /** 30 | * 登录名 31 | */ 32 | @ApiModelProperty("用户名") 33 | private String userName; 34 | 35 | /** 36 | * 密码 37 | */ 38 | @ApiModelProperty("密码") 39 | @TableField("password") 40 | private String password; 41 | 42 | /** 43 | * 昵称 44 | */ 45 | @ApiModelProperty("昵称") 46 | private String nickName; 47 | 48 | /** 49 | * 性别(0男,1女,2未知) 50 | */ 51 | @ApiModelProperty("性别") 52 | private Integer sex; 53 | 54 | /** 55 | * 用户头像地址 56 | */ 57 | @ApiModelProperty("用户头像地址") 58 | private String avatarUrl; 59 | 60 | /** 61 | * 地址 62 | */ 63 | @ApiModelProperty("用户地址") 64 | private String address; 65 | 66 | /** 67 | * 微信小程序openid,每个用户对应一个,且唯一 68 | */ 69 | @ApiModelProperty("WX唯一id") 70 | private String openId; 71 | 72 | /** 73 | * 当前状态 1-正常 0-不正常 74 | */ 75 | @ApiModelProperty("当前用户状态") 76 | private Integer userStatus; 77 | 78 | /** 79 | * 是否是管理员 1-管理员 0-非管理员 80 | */ 81 | @ApiModelProperty("用户是否是管理员") 82 | private Integer isAdmin; 83 | 84 | /** 85 | * 电话号码 86 | */ 87 | @ApiModelProperty("用户电话号码") 88 | private String phoneNumber; 89 | 90 | /** 91 | * 用户邮箱 92 | */ 93 | @ApiModelProperty("用户邮箱") 94 | private String email; 95 | 96 | /** 97 | * 创建时间 98 | */ 99 | @ApiModelProperty("创建时间") 100 | private Date createTime; 101 | 102 | /** 103 | * 更新时间 104 | */ 105 | @ApiModelProperty("更新时间") 106 | private Date updateTime; 107 | 108 | /** 109 | * 是否删除 1-删除 0-未删除 110 | */ 111 | @ApiModelProperty("是否删除") 112 | @TableLogic 113 | private Integer isDelete; 114 | 115 | /** 116 | * 角色信息 117 | */ 118 | @TableField(exist = false) 119 | @ApiModelProperty(value = "角色信息") 120 | private List roles; 121 | 122 | /** 123 | * 用户对应的菜单信息 124 | */ 125 | @TableField(exist = false) 126 | @ApiModelProperty(value = "用户对应的菜单列表") 127 | private List menus; 128 | 129 | /** 130 | * 用户对应的权限列表 131 | */ 132 | @TableField(exist = false) 133 | @ApiModelProperty(value = "用户对应的权限数据") 134 | private List permissions; 135 | 136 | @TableField(exist = false) 137 | private static final long serialVersionUID = 1L; 138 | } -------------------------------------------------------------------------------- /src/main/java/com/lt/health/entity/UserRoles.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.TableField; 4 | import com.baomidou.mybatisplus.annotation.TableName; 5 | import io.swagger.annotations.ApiModel; 6 | import io.swagger.annotations.ApiModelProperty; 7 | import lombok.Data; 8 | 9 | import java.io.Serializable; 10 | 11 | /** 12 | * 用户角色表 13 | * 14 | * @author 狂小腾 15 | * @TableName sys_user_roles 16 | */ 17 | @TableName(value = "sys_user_roles") 18 | @Data 19 | @ApiModel("用户角色实体类") 20 | public class UserRoles implements Serializable { 21 | /** 22 | * 用户ID 23 | */ 24 | @ApiModelProperty("用户id") 25 | private Long userId; 26 | 27 | /** 28 | * 角色ID 29 | */ 30 | @ApiModelProperty("角色id") 31 | private Long roleId; 32 | 33 | @TableField(exist = false) 34 | private static final long serialVersionUID = 1L; 35 | } -------------------------------------------------------------------------------- /src/main/java/com/lt/health/entity/WxRun.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.TableField; 4 | import com.baomidou.mybatisplus.annotation.TableName; 5 | import io.swagger.annotations.ApiModel; 6 | import io.swagger.annotations.ApiModelProperty; 7 | import lombok.AllArgsConstructor; 8 | import lombok.Data; 9 | import lombok.NoArgsConstructor; 10 | 11 | import java.io.Serializable; 12 | 13 | /** 14 | * 微信运动步数记录表 15 | * 16 | * @author: 狂小腾 17 | * @TableName sys_wx_run 18 | */ 19 | @TableName(value = "sys_wx_run") 20 | @Data 21 | @AllArgsConstructor 22 | @NoArgsConstructor 23 | @ApiModel("WX运动步数实体类") 24 | public class WxRun implements Serializable { 25 | /** 26 | * 微信唯一标识 27 | */ 28 | @ApiModelProperty("WX唯一标识") 29 | private String openid; 30 | 31 | /** 32 | * 时间 33 | */ 34 | @ApiModelProperty("时间") 35 | private String time; 36 | 37 | /** 38 | * 运动步数 39 | */ 40 | @ApiModelProperty("运动步数") 41 | private Integer step; 42 | 43 | @TableField(exist = false) 44 | private static final long serialVersionUID = 1L; 45 | } -------------------------------------------------------------------------------- /src/main/java/com/lt/health/entity/dto/Encrypted.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.entity.dto; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | import lombok.Data; 6 | 7 | /** 8 | * @description: WX小程序加密数据 9 | * @author: 狂小腾 10 | * @date: 2022/4/2 21:50 11 | */ 12 | @Data 13 | @ApiModel("WX小程序加密实体类") 14 | public class Encrypted { 15 | /** 16 | * 加密数据 17 | */ 18 | @ApiModelProperty("加密数据") 19 | private String encryptedData; 20 | 21 | /** 22 | * 调用微信运动传递的矢量加密算法 23 | */ 24 | @ApiModelProperty("矢量加密算法") 25 | private String iv; 26 | 27 | /** 28 | * 微信小程序登陆获取的会话key 29 | */ 30 | @ApiModelProperty("会话key") 31 | private String sessionKey; 32 | 33 | /** 34 | * 微信小程序唯一标志 35 | */ 36 | @ApiModelProperty("小程序唯一标志") 37 | private String openid; 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/entity/dto/LoginUserDTO.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.entity.dto; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | import lombok.Data; 6 | 7 | /** 8 | * @description: 登录参数 9 | * @author: 狂小腾 10 | * @date: 2022/3/22 19:23 11 | */ 12 | @Data 13 | @ApiModel("用户登录参数") 14 | public class LoginUserDTO { 15 | 16 | /** 17 | * 用户名 18 | */ 19 | @ApiModelProperty("用户名") 20 | private String username; 21 | 22 | /** 23 | * 密码 24 | */ 25 | @ApiModelProperty("密码") 26 | private String password; 27 | 28 | /** 29 | * 手机号码 30 | */ 31 | @ApiModelProperty("手机号码") 32 | private String phoneNumber; 33 | 34 | /** 35 | * 手机验证码 36 | */ 37 | @ApiModelProperty("手机验证码") 38 | private String code; 39 | 40 | /** 41 | * 1-账号密码登录 2-手机验证码登录 42 | */ 43 | @ApiModelProperty("登录方式 1-普通登录 2-手机验证码登录") 44 | private String type; 45 | 46 | /** 47 | * 唯一标识 48 | */ 49 | @ApiModelProperty("图片验证唯一标识") 50 | private String uuid; 51 | 52 | /** 53 | * 登录图片验证码 54 | */ 55 | @ApiModelProperty("图片验证码") 56 | private String captchaCode; 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/entity/dto/MailDTO.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.entity.dto; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | import lombok.Data; 6 | 7 | import java.io.Serializable; 8 | 9 | /** 10 | * @description: 发送邮件参数 11 | * @author: 狂小腾 12 | * @date: 2022/3/27 21:58 13 | */ 14 | @Data 15 | @ApiModel("发送邮件参数") 16 | public class MailDTO implements Serializable { 17 | 18 | /** 19 | * 是否是HTML格式 20 | */ 21 | @ApiModelProperty("是否是HTML格式") 22 | private boolean html = false; 23 | 24 | /** 25 | * 接收人的邮箱 可以有多个 26 | */ 27 | @ApiModelProperty("接收人的邮箱") 28 | private String[] receivers; 29 | 30 | /** 31 | * 邮件主题 32 | */ 33 | @ApiModelProperty("邮件主题") 34 | private String subject; 35 | 36 | /** 37 | * 邮件内容 38 | */ 39 | @ApiModelProperty("邮件内容") 40 | private String content; 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/entity/dto/PageInfoDTO.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.entity.dto; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | import lombok.Data; 6 | 7 | /** 8 | * @description: 分页参数 9 | * @author: 狂小腾 10 | * @date: 2022/3/21 23:07 11 | */ 12 | @Data 13 | @ApiModel("分页参数") 14 | public class PageInfoDTO { 15 | 16 | /** 17 | * 当前页码 18 | */ 19 | @ApiModelProperty("当前页码") 20 | private Integer pageNumber; 21 | 22 | /** 23 | * 页数 24 | */ 25 | @ApiModelProperty("当前页显示多少页数") 26 | private Integer pageSize; 27 | 28 | /** 29 | * 分页查询的条件---用户名、昵称、手机号码 30 | */ 31 | @ApiModelProperty("分页查询条件") 32 | private String queryString; 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/event/demo/AbstractEvent.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.event.demo; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | /** 8 | * @description: 抽象事件对象---描述了发生什么事件的对象 9 | * @author: 狂小腾 10 | * @date: 2022/4/2 16:12 11 | */ 12 | @Data 13 | @AllArgsConstructor 14 | @NoArgsConstructor 15 | public abstract class AbstractEvent { 16 | 17 | /** 18 | * 事件源 19 | */ 20 | private Object source; 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/event/demo/EventListener.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.event.demo; 2 | 3 | /** 4 | * @param 当前监听器感兴趣的事件 5 | * @description: 事件监听器的接口 6 | * @author: 狂小腾 7 | * @date: 2022/4/2 16:15 8 | */ 9 | public interface EventListener { 10 | 11 | /** 12 | * 处理事件 13 | * 14 | * @param event 事件 15 | */ 16 | void onEvent(E event); 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/event/demo/EventMulticaster.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.event.demo; 2 | 3 | /** 4 | * @description: 事件广播器接口 5 | * 1. 负责事件监听器的管理 (注册监听器&移除监听器,将事件和监听器关联起来) 6 | * 2. 负责事件的广播 (将事件广播给所有的监听器,对该事件感兴趣的监听器会处理该事件) 7 | * @author: 狂小腾 8 | * @date: 2022/4/2 16:18 9 | */ 10 | public interface EventMulticaster { 11 | 12 | /** 13 | * 将事件广播给所有的监听器 14 | * 15 | * @param event 事件 16 | */ 17 | void multicastEvent(AbstractEvent event); 18 | 19 | /** 20 | * 添加一个事件监听器(监听器中包含了监听器能够处理的事件) 21 | * 22 | * @param listener 具体的事件监听器 23 | */ 24 | void addEventListener(EventListener listener); 25 | 26 | /** 27 | * 移除事件监听器 28 | * 29 | * @param listener 需要移除的具体的事件监听器 30 | */ 31 | void removeEventListener(EventListener listener); 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/event/demo/EventTest.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.event.demo; 2 | 3 | import org.junit.Test; 4 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 5 | 6 | /** 7 | * @description: 事件测试 8 | * @author: 狂小腾 9 | * @date: 2022/4/2 16:59 10 | */ 11 | public class EventTest { 12 | 13 | @Test 14 | public void test() { 15 | AnnotationConfigApplicationContext context = new 16 | AnnotationConfigApplicationContext(MyConfig.class); 17 | // 获取用户注册服务 18 | UserRegisterService userRegisterService = context.getBean(UserRegisterService.class); 19 | // 模拟用户注册 20 | userRegisterService.registerUser("路人甲Java"); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/event/demo/MyConfig.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.event.demo; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * @description: 事件配置类 11 | * @author: 狂小腾 12 | * @date: 2022/4/2 16:50 13 | */ 14 | @Configuration 15 | public class MyConfig { 16 | 17 | /** 18 | * 注册一个bean:事件发布者 19 | * 20 | * @param eventListeners 事件监听者 21 | * @return 事件发布者 22 | */ 23 | @Bean 24 | @Autowired(required = false) 25 | public EventMulticaster eventMulticaster(List eventListeners) { 26 | EventMulticaster eventMulticaster = new SimpleEventMulticaster(); 27 | if (eventListeners != null) { 28 | eventListeners.forEach(eventMulticaster::addEventListener); 29 | } 30 | return eventMulticaster; 31 | } 32 | 33 | /** 34 | * 注册一个bean:用户注册服务 35 | * 36 | * @param eventMulticaster 事件广播器 37 | * @return 用户注册服务 38 | */ 39 | @Bean 40 | public UserRegisterService userRegisterService(EventMulticaster eventMulticaster) { 41 | UserRegisterService userRegisterService = new UserRegisterService(); 42 | userRegisterService.setEventMulticaster(eventMulticaster); 43 | return userRegisterService; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/event/demo/SendEmailOnUserRegisterSuccessListener.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.event.demo; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | /** 6 | * @description: 用户注册成功事件监听器---负责给用户发送邮件 7 | * @author: 狂小腾 8 | * @date: 2022/4/2 17:04 9 | */ 10 | @Component 11 | public class SendEmailOnUserRegisterSuccessListener implements EventListener { 12 | 13 | @Override 14 | public void onEvent(UserRegisterSuccessEvent event) { 15 | System.out.println(String.format("给用户【%s】发送注册成功邮件!", event.getUserName())); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/event/demo/SimpleEventMulticaster.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.event.demo; 2 | 3 | import java.lang.reflect.ParameterizedType; 4 | import java.lang.reflect.Type; 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | import java.util.Map; 8 | import java.util.concurrent.ConcurrentHashMap; 9 | 10 | /** 11 | * @description: 具体的事件广播器 12 | * @author: 狂小腾 13 | * @date: 2022/4/2 16:26 14 | */ 15 | public class SimpleEventMulticaster implements EventMulticaster { 16 | 17 | private Map, List> eventObjectEventListenerMap 18 | = new ConcurrentHashMap<>(); 19 | 20 | @Override 21 | public void multicastEvent(AbstractEvent event) { 22 | // 根据事件获取监听器 23 | List eventListeners = eventObjectEventListenerMap.get(event.getClass()); 24 | if (eventListeners != null) { 25 | for (EventListener eventListener : eventListeners) { 26 | // 监听器处理事件 27 | eventListener.onEvent(event); 28 | } 29 | } 30 | } 31 | 32 | @Override 33 | public void addEventListener(EventListener listener) { 34 | // 获取事件监听器需要监听的事件类型 35 | Class eventType = this.getEventType(listener); 36 | // 根据事件类型获取监听器 37 | List eventListeners = eventObjectEventListenerMap.get(eventType); 38 | if (eventListeners == null) { 39 | // 监听器为空 40 | eventListeners = new ArrayList<>(); 41 | eventObjectEventListenerMap.put(eventType, eventListeners); 42 | } 43 | // 不为空 直接add 44 | eventListeners.add(listener); 45 | } 46 | 47 | @Override 48 | public void removeEventListener(EventListener listener) { 49 | // 获取事件监听器需要监听的事件类型 50 | Class eventType = this.getEventType(listener); 51 | // 根据事件类型获取监听器 52 | List eventListeners = eventObjectEventListenerMap.get(eventType); 53 | if (eventListeners != null) { 54 | eventListeners.remove(listener); 55 | } 56 | } 57 | 58 | /** 59 | * 根据事件监听器获取监听事件的类型 60 | * 61 | * @param listener 事件监听器 62 | * @return 监听事件的类型 63 | */ 64 | protected Class getEventType(EventListener listener) { 65 | // 获取抽象接口的类型 66 | ParameterizedType parameterizedType = (ParameterizedType) listener.getClass().getGenericInterfaces()[0]; 67 | // 获取该接口方法的参数类型 68 | Type eventType = parameterizedType.getActualTypeArguments()[0]; 69 | return (Class) eventType; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/event/demo/UserRegisterListener.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.event.demo; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | /** 6 | * @description: 用户注册监听器 7 | * @author: 狂小腾 8 | * @date: 2022/4/2 17:16 9 | */ 10 | @Component 11 | public class UserRegisterListener { 12 | 13 | // @org.springframework.context.event.EventListener 14 | // public void sendMail(UserRegisterEvent event) { 15 | // System.out.println(String.format("给用户【%s】发送注册成功邮件!", 16 | // event.getUserName())); 17 | // } 18 | // 19 | // @EventListener 20 | // public void sendCompon(UserRegisterEvent event) { 21 | // System.out.println(String.format("给用户【%s】发送优惠券!", 22 | // event.getUserName())); 23 | // } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/event/demo/UserRegisterService.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.event.demo; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * @description: 用户注册服务 7 | * @author: 狂小腾 8 | * @date: 2022/4/2 16:47 9 | */ 10 | @Data 11 | public class UserRegisterService { 12 | 13 | /** 14 | * 事件发布者 15 | */ 16 | private EventMulticaster eventMulticaster; 17 | 18 | /** 19 | * 注册用户 20 | * 21 | * @param userName 用户名 22 | */ 23 | public void registerUser(String userName) { 24 | // 将用户信息存入数据库 25 | System.out.println(String.format("用户【%s】注册成功", userName)); 26 | // 发送广播 27 | eventMulticaster.multicastEvent(new UserRegisterSuccessEvent(this, userName)); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/event/demo/UserRegisterSuccessEvent.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.event.demo; 2 | 3 | import lombok.Data; 4 | import lombok.EqualsAndHashCode; 5 | 6 | /** 7 | * @description: 用户注册成功具体事件 8 | * @author: 狂小腾 9 | * @date: 2022/4/2 16:43 10 | */ 11 | @EqualsAndHashCode(callSuper = true) 12 | @Data 13 | public class UserRegisterSuccessEvent extends AbstractEvent { 14 | 15 | /** 16 | * 用户名 17 | */ 18 | private String userName; 19 | 20 | /** 21 | * 创建用户注册成功事件对象 22 | * 23 | * @param source 事件源 24 | * @param userName 当前注册的用户名 25 | */ 26 | public UserRegisterSuccessEvent(Object source, String userName) { 27 | super(source); 28 | this.userName = userName; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/exception/CaptchaException.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.exception; 2 | 3 | /** 4 | * @description: 验证码错误异常 5 | * @author: 狂小腾 6 | * @date: 2022/4/11 12:40 7 | */ 8 | public class CaptchaException extends RuntimeException { 9 | 10 | public CaptchaException() { 11 | super("验证码错误!!!"); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/exception/CaptchaExpireException.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.exception; 2 | 3 | /** 4 | * @description: 验证码失效异常类 5 | * @author: 狂小腾 6 | * @date: 2022/4/11 12:35 7 | */ 8 | public class CaptchaExpireException extends RuntimeException { 9 | 10 | public CaptchaExpireException() { 11 | super("验证码已失效!!!"); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/exception/GlobalException.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.exception; 2 | 3 | import com.lt.health.constant.Result; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.http.HttpStatus; 6 | import org.springframework.security.access.AccessDeniedException; 7 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 8 | import org.springframework.web.HttpRequestMethodNotSupportedException; 9 | import org.springframework.web.bind.annotation.ExceptionHandler; 10 | import org.springframework.web.bind.annotation.ResponseStatus; 11 | import org.springframework.web.bind.annotation.RestControllerAdvice; 12 | 13 | /** 14 | * @description: 自定义全局异常 15 | * @author: 狂小腾 16 | * @date: 2022/3/23 13:26 17 | */ 18 | @Slf4j 19 | @RestControllerAdvice 20 | public class GlobalException { 21 | @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) 22 | @ExceptionHandler(value = RuntimeException.class) 23 | public Result exception(RuntimeException e) { 24 | e.printStackTrace(); 25 | log.error("系统运行时异常--->{}", e.getMessage()); 26 | return Result.fail(e.getMessage()); 27 | } 28 | 29 | @ResponseStatus(HttpStatus.FORBIDDEN) 30 | @ExceptionHandler(value = AccessDeniedException.class) 31 | public Result exception(AccessDeniedException e) { 32 | e.printStackTrace(); 33 | log.error("权限不足--->{}", e.getMessage()); 34 | return Result.fail("权限不足,请联系管理员!"); 35 | } 36 | 37 | @ResponseStatus(HttpStatus.BAD_REQUEST) 38 | @ExceptionHandler(value = UsernameNotFoundException.class) 39 | public Result exception(UsernameNotFoundException e) { 40 | log.error("用户名没有找到-->{}", e.getMessage()); 41 | return Result.fail(e.getMessage()); 42 | } 43 | 44 | @ResponseStatus(HttpStatus.BAD_REQUEST) 45 | @ExceptionHandler(value = HttpRequestMethodNotSupportedException.class) 46 | public Result exception(HttpRequestMethodNotSupportedException e) { 47 | String message = e.getMessage(); 48 | log.error("请求方式错误-->{}", message); 49 | return Result.fail("不需要" + message.split("'")[1] + "请求"); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/mapper/FoodMapper.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.mapper; 2 | 3 | import com.lt.health.entity.Food; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | import org.apache.ibatis.annotations.Param; 6 | import org.apache.ibatis.annotations.Select; 7 | import org.springframework.stereotype.Repository; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * @author 狂小腾 13 | * @description 针对表【sys_food(食物详情表)】的数据库操作Mapper 14 | * @createDate 2022-03-26 20:36:16 15 | * @Entity com.lt.health.entity.Food 16 | */ 17 | @Repository 18 | public interface FoodMapper extends BaseMapper { 19 | 20 | /** 21 | * 根据食物名称查找食物 22 | * 23 | * @param title 食物名称 24 | * @return 食物 25 | */ 26 | @Select("select * from sys_food where title = #{title}") 27 | Food findByTitle(@Param("title") String title); 28 | 29 | /** 30 | * 插入食物列表 31 | * 32 | * @param foods 食物列表 33 | */ 34 | void insertList(@Param("foods") List foods); 35 | } 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/mapper/FoodTypeMapper.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.lt.health.entity.FoodType; 5 | import org.apache.ibatis.annotations.Param; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * @author 狂小腾 12 | * @description 针对表【sys_food_type(食物分类表)】的数据库操作Mapper 13 | * @createDate 2022-03-26 20:36:16 14 | * @Entity com.lt.health.entity.FoodType 15 | */ 16 | @Repository 17 | public interface FoodTypeMapper extends BaseMapper { 18 | 19 | /** 20 | * 分页查询 查询出食物类别和食物信息 21 | * 22 | * @param queryString 查询条件---菜单分类标题 23 | * @return 食物信息 24 | */ 25 | List findPage(@Param("title") String queryString); 26 | } 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/mapper/GoodsMapper.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.mapper; 2 | 3 | import com.lt.health.entity.Goods; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | import org.springframework.stereotype.Repository; 6 | 7 | /** 8 | * @author 狂小腾 9 | * @description 针对表【sys_goods】的数据库操作Mapper 10 | * @createDate 2022-03-26 20:36:16 11 | * @Entity com.lt.health.entity.Goods 12 | */ 13 | @Repository 14 | public interface GoodsMapper extends BaseMapper { 15 | 16 | } 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/mapper/LogMessageMapper.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.mapper; 2 | 3 | import com.lt.health.entity.LogMessage; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | import org.springframework.stereotype.Repository; 6 | 7 | /** 8 | * @author 腾腾 9 | * @description 针对表【sys_log_message(日志表)】的数据库操作Mapper 10 | * @createDate 2022-04-01 23:06:33 11 | * @Entity com.lt.health.entity.LogMessage 12 | */ 13 | @Repository 14 | public interface LogMessageMapper extends BaseMapper { 15 | 16 | } 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/mapper/MenuMapper.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.mapper; 2 | 3 | import com.lt.health.entity.Menu; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | import org.apache.ibatis.annotations.Param; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * @author 狂小腾 12 | * @description 针对表【sys_menu】的数据库操作Mapper 13 | * @createDate 2022-03-26 20:36:16 14 | * @Entity com.lt.health.entity.Menu 15 | */ 16 | @Repository 17 | public interface MenuMapper extends BaseMapper { 18 | 19 | 20 | /** 21 | * 根据用户ID查询菜单信息 22 | * 23 | * @param userId 用户id 24 | * @return 菜单信息 25 | */ 26 | List findMenusByUserId(@Param("userId") Long userId); 27 | 28 | /** 29 | * 根据父级id和用户id查询子级菜单 30 | * 31 | * @param parentId 父级id 32 | * @param userId 用户id 33 | * @return 子级菜单 34 | */ 35 | List findChildrenMenuByPidAndUserId(@Param("parentId") Long parentId, @Param("userId") Long userId); 36 | 37 | /** 38 | * 根据角色id查询父级菜单权限 39 | * 40 | * @param roleId 角色id 41 | * @return 菜单数据 42 | */ 43 | List findByRoleId(@Param("roleId") Long roleId); 44 | 45 | /** 46 | * 根据角色id和菜单的父级id查询子菜单 47 | * 48 | * @param roleId 角色id 49 | * @param parentId 菜单父级id 50 | * @return 子级菜单 51 | */ 52 | List findByRoleIdAndParentId(@Param("roleId") Long roleId, @Param("parentId") Long parentId); 53 | } 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/mapper/MotionMapper.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.mapper; 2 | 3 | import com.lt.health.entity.Motion; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | import org.springframework.stereotype.Repository; 6 | 7 | /** 8 | * @author 狂小腾 9 | * @description 针对表【sys_motion(运动表)】的数据库操作Mapper 10 | * @createDate 2022-03-26 20:36:16 11 | * @Entity com.lt.health.entity.Motion 12 | */ 13 | @Repository 14 | public interface MotionMapper extends BaseMapper { 15 | 16 | } 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/mapper/PermissionMapper.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.mapper; 2 | 3 | import com.lt.health.entity.Permission; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | import org.apache.ibatis.annotations.Param; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * @author 狂小腾 12 | * @description 针对表【sys_permission】的数据库操作Mapper 13 | * @createDate 2022-03-26 20:36:16 14 | * @Entity com.lt.health.entity.Permission 15 | */ 16 | @Repository 17 | public interface PermissionMapper extends BaseMapper { 18 | 19 | /** 20 | * 根据用户ID查询权限数据 21 | * 22 | * @param userId 用户id 23 | * @return 权限数据 24 | */ 25 | List findPermissionsByUserId(@Param("userId") Long userId); 26 | 27 | /** 28 | * 根据角色id查询对应数据权限 29 | * 30 | * @param roleId 角色id 31 | * @return 数据权限 32 | */ 33 | List findByRoleId(@Param("roleId") Long roleId); 34 | } 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/mapper/RoleMapper.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.lt.health.entity.Role; 5 | import org.apache.ibatis.annotations.Param; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * @author 狂小腾 12 | * @description 针对表【sys_role】的数据库操作Mapper 13 | * @createDate 2022-03-26 20:36:16 14 | * @Entity com.lt.health.entity.Role 15 | */ 16 | @Repository 17 | public interface RoleMapper extends BaseMapper { 18 | 19 | /** 20 | * 根据用户ID查询角色信息 21 | * 22 | * @param userId 用户id 23 | * @return 该用户角色信息 24 | */ 25 | List findRolesByUserId(@Param("userId") Long userId); 26 | } 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/mapper/RolesMenusMapper.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.mapper; 2 | 3 | import com.lt.health.entity.RolesMenus; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | import org.apache.ibatis.annotations.Delete; 6 | import org.apache.ibatis.annotations.Insert; 7 | import org.apache.ibatis.annotations.Param; 8 | import org.springframework.stereotype.Repository; 9 | 10 | /** 11 | * @author 狂小腾 12 | * @description 针对表【sys_roles_menus】的数据库操作Mapper 13 | * @createDate 2022-03-26 20:36:16 14 | * @Entity com.lt.health.entity.RolesMenus 15 | */ 16 | @Repository 17 | public interface RolesMenusMapper extends BaseMapper { 18 | 19 | /** 20 | * 根据角色id和菜单id插入数据 21 | * 22 | * @param roleId 角色id 23 | * @param menuId 菜单id 24 | */ 25 | @Insert("insert into sys_roles_menus values (#{roleId}, #{menuId})") 26 | void insertRolesMenus(@Param("roleId") Long roleId, @Param("menuId") Long menuId); 27 | 28 | /** 29 | * 根据角色id删除对应菜单 30 | * 31 | * @param roleId 角色id 32 | */ 33 | @Delete("delete from sys_roles_menus where role_id = #{roleId}") 34 | void deleteMenusByRoleId(@Param("roleId") Long roleId); 35 | } 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/mapper/RolesPermissionsMapper.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.mapper; 2 | 3 | import com.lt.health.entity.RolesPermissions; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | import org.apache.ibatis.annotations.Delete; 6 | import org.apache.ibatis.annotations.Insert; 7 | import org.apache.ibatis.annotations.Param; 8 | import org.springframework.stereotype.Repository; 9 | 10 | /** 11 | * @author 狂小腾 12 | * @description 针对表【sys_roles_permissions】的数据库操作Mapper 13 | * @createDate 2022-03-26 20:36:16 14 | * @Entity com.lt.health.entity.RolesPermissions 15 | */ 16 | @Repository 17 | public interface RolesPermissionsMapper extends BaseMapper { 18 | 19 | /** 20 | * 根据角色id和权限id插入数据 21 | * 22 | * @param roleId 角色id 23 | * @param permissionId 权限id 24 | */ 25 | @Insert("insert into sys_roles_permissions values (#{roleId}, #{permissionId})") 26 | void insertRolesPermissions(@Param("roleId") Long roleId, @Param("permissionId") Long permissionId); 27 | 28 | /** 29 | * 根据角色id删除对应的权限 30 | * 31 | * @param roleId 角色id 32 | */ 33 | @Delete("delete from sys_roles_permissions where role_id = #{roleId}") 34 | void deletePermissionByRoleId(@Param("roleId") Long roleId); 35 | } 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/mapper/SportMapper.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.mapper; 2 | 3 | import com.lt.health.entity.Sport; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | import org.springframework.stereotype.Repository; 6 | 7 | /** 8 | * @author 狂小腾 9 | * @description 针对表【sys_sport(运动咨询)】的数据库操作Mapper 10 | * @createDate 2022-03-26 20:36:16 11 | * @Entity com.lt.health.entity.Sport 12 | */ 13 | @Repository 14 | public interface SportMapper extends BaseMapper { 15 | 16 | } 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.lt.health.entity.User; 5 | import org.apache.ibatis.annotations.Insert; 6 | import org.apache.ibatis.annotations.Param; 7 | import org.apache.ibatis.annotations.Update; 8 | import org.springframework.stereotype.Repository; 9 | 10 | /** 11 | * @author 狂小腾 12 | * @description 针对表【sys_user】的数据库操作Mapper 13 | * @createDate 2022-03-26 20:36:16 14 | * @Entity com.lt.health.entity.User 15 | */ 16 | @Repository 17 | public interface UserMapper extends BaseMapper { 18 | 19 | /** 20 | * 根据用户名查询用户 21 | * 22 | * @param username 用户名 23 | * @return 用户对象 24 | */ 25 | User findByUserName(@Param("value") String username); 26 | 27 | /** 28 | * 根据邮箱更改用户密码 29 | * 30 | * @param email 邮箱 31 | * @param password 加密后的密码 32 | */ 33 | @Update("update sys_user set password = #{password} where email = #{email}") 34 | void updatePasswordByMail(@Param("email") String email, @Param("password") String password); 35 | 36 | /** 37 | * 插入WX用户的openid 38 | * 39 | * @param openid WX用户的唯一标识 40 | */ 41 | @Insert("insert into sys_user(open_id, user_status) values (#{openid}, 0)") 42 | void insertOpenid(@Param("openid") String openid); 43 | 44 | /** 45 | * 根据openid更新用户信息 46 | * 47 | * @param user 用户信息 48 | */ 49 | void updateByOpenId(User user); 50 | } 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/mapper/UserRolesMapper.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.mapper; 2 | 3 | import com.lt.health.entity.UserRoles; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | import org.apache.ibatis.annotations.Param; 6 | import org.springframework.stereotype.Repository; 7 | 8 | /** 9 | * @author 狂小腾 10 | * @description 针对表【sys_user_roles】的数据库操作Mapper 11 | * @createDate 2022-03-26 20:36:16 12 | * @Entity com.lt.health.entity.UserRoles 13 | */ 14 | @Repository 15 | public interface UserRolesMapper extends BaseMapper { 16 | 17 | /** 18 | * 添加用户id和角色id 19 | * 20 | * @param userId 用户id 21 | * @param roleId 角色id 22 | */ 23 | void insertUserRoles(@Param("userId") Long userId, @Param("roleId") Long roleId); 24 | } 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/mapper/WxRunMapper.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.mapper; 2 | 3 | import com.lt.health.entity.WxRun; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | import org.apache.ibatis.annotations.Param; 6 | import org.apache.ibatis.annotations.Select; 7 | import org.apache.ibatis.annotations.Update; 8 | import org.springframework.stereotype.Repository; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | * @author 狂小腾 14 | * @description 针对表【sys_wx_run(微信运动步数记录表)】的数据库操作Mapper 15 | * @createDate 2022-03-26 20:36:16 16 | * @Entity com.lt.health.entity.WxRun 17 | */ 18 | @Repository 19 | public interface WxRunMapper extends BaseMapper { 20 | 21 | /** 22 | * 根据时间和openid查找WX运动 23 | * 24 | * @param time 时间 25 | * @param openid openid 26 | * @return 微信运动 27 | */ 28 | @Select("select * from sys_wx_run where openid = #{openid} and time = #{time}") 29 | WxRun findStepByTimeAndOpenid(@Param("time") String time, @Param("openid") String openid); 30 | 31 | /** 32 | * 更新WX步数 33 | * 34 | * @param time 时间 35 | * @param openid openid 36 | * @param step 步数 37 | */ 38 | @Update("update sys_wx_run set step = #{step} where openid = #{openid} and time = #{time}") 39 | void updateStep(@Param("time") String time, @Param("openid") String openid, @Param("step") Integer step); 40 | 41 | /** 42 | * 插入WX步数集合 43 | * 44 | * @param wxRuns WX步数 45 | */ 46 | void insertStep(@Param("wxRuns") List wxRuns); 47 | 48 | /** 49 | * 查询前一周的WX步数 50 | * 51 | * @param dateTime 当前时间 52 | * @param endTime 前一周时间 53 | * @param openId openid 54 | * @return 一周的WX步数 55 | */ 56 | @Select("select * from sys_wx_run where openid = #{openid} and (time <= #{beginTime} and time >= #{endTime})") 57 | List findByTime(@Param("beginTime") String dateTime, @Param("endTime") String endTime, @Param("openid") String openId); 58 | } 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/service/FoodService.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.service; 2 | 3 | import com.lt.health.constant.Result; 4 | import com.lt.health.entity.Food; 5 | import com.baomidou.mybatisplus.extension.service.IService; 6 | import com.lt.health.entity.dto.PageInfoDTO; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * @author 狂小腾 12 | * @description 针对表【sys_food(食物详情表)】的数据库操作Service 13 | * @createDate 2022-03-26 20:36:16 14 | */ 15 | public interface FoodService extends IService { 16 | 17 | /** 18 | * 通过excel批量导入食物 19 | * 20 | * @param list 食物列表 21 | * @return 提示信息 22 | */ 23 | Result batchImport(List list); 24 | 25 | /** 26 | * 分页查询菜品分类和菜品信息 27 | * 28 | * @param pageInfoDTO 分页参数---菜品分类标题 29 | * @return 分页结果 30 | */ 31 | Result findPage(PageInfoDTO pageInfoDTO); 32 | 33 | /** 34 | * 分页查询菜品信息 35 | * 36 | * @param pageInfoDTO 分页参数---食物名称标题 37 | * @return 分页结果 38 | */ 39 | Result findFoodPage(PageInfoDTO pageInfoDTO); 40 | 41 | /** 42 | * 添加菜品 43 | * 44 | * @param food 菜品 45 | * @return 成功或失败信息 46 | */ 47 | Result insert(Food food); 48 | 49 | /** 50 | * 修改菜品 51 | * 52 | * @param food 菜品 53 | * @return 成功或失败信息 54 | */ 55 | Result update(Food food); 56 | 57 | /** 58 | * 删除菜品 59 | * 60 | * @param id 菜品id 61 | * @return 成功或失败信息 62 | */ 63 | Result delete(Long id); 64 | 65 | /** 66 | * 根据食物类别进行分页查询 67 | * 68 | * @param pageInfoDTO 分页参数 69 | * @return 分页结果 70 | */ 71 | Result findFoodPageByTypeId(PageInfoDTO pageInfoDTO); 72 | 73 | /** 74 | * 根据菜品id获取菜品 75 | * 76 | * @param id 菜品id 77 | * @return 菜品信息 78 | */ 79 | Result findInfo(Long id); 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/service/FoodTypeService.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.service; 2 | 3 | import com.lt.health.constant.Result; 4 | import com.lt.health.entity.FoodType; 5 | import com.baomidou.mybatisplus.extension.service.IService; 6 | 7 | /** 8 | * @author 狂小腾 9 | * @description 针对表【sys_food_type(食物分类表)】的数据库操作Service 10 | * @createDate 2022-03-26 20:36:16 11 | */ 12 | public interface FoodTypeService extends IService { 13 | 14 | /** 15 | * 添加菜品分类 16 | * 17 | * @param foodType 菜品分类 18 | * @return 成功或失败信息 19 | */ 20 | Result insertType(FoodType foodType); 21 | 22 | /** 23 | * 修改菜品分类 24 | * 25 | * @param foodType 菜品分类 26 | * @return 成功或失败信息 27 | */ 28 | Result updateType(FoodType foodType); 29 | 30 | /** 31 | * 删除菜品分类 32 | * 33 | * @param id 菜品分类id 34 | * @return 成功或失败信息 35 | */ 36 | Result deleteType(Long id); 37 | 38 | /** 39 | * 查询所有的菜品分类信息 40 | * 41 | * @return 菜品分类信息 42 | */ 43 | Result typeAll(); 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/service/GoodsService.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.service; 2 | 3 | import com.lt.health.constant.Result; 4 | import com.lt.health.entity.Goods; 5 | import com.baomidou.mybatisplus.extension.service.IService; 6 | import com.lt.health.entity.dto.PageInfoDTO; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * @author 狂小腾 12 | * @description 针对表【sys_goods】的数据库操作Service 13 | * @createDate 2022-03-26 20:36:16 14 | */ 15 | public interface GoodsService extends IService { 16 | 17 | /** 18 | * 根据商品名称分页查询 19 | * 20 | * @param pageInfoDTO 分页参数 21 | * @return 分页结果集 22 | */ 23 | Result findPage(PageInfoDTO pageInfoDTO); 24 | 25 | /** 26 | * 查询单个商品信息 27 | * 28 | * @param id 商品id 29 | * @return 商品信息 30 | */ 31 | Result findInfo(Long id); 32 | 33 | /** 34 | * 添加商品 35 | * 36 | * @param goods 商品信息 37 | * @return 成功或失败信息 38 | */ 39 | Result insert(Goods goods); 40 | 41 | /** 42 | * 修改商品 43 | * 44 | * @param goods 商品信息 45 | * @return 成功或失败信息 46 | */ 47 | Result update(Goods goods); 48 | 49 | /** 50 | * 删除商品 51 | * 52 | * @param id 商品id 53 | * @return 成功或失败信息 54 | */ 55 | Result delete(Long id); 56 | 57 | /** 58 | * 通过excel导入添加商品信息 59 | * 60 | * @param list 商品信息数据 61 | * @return 结果集 62 | */ 63 | Result batchImport(List list); 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/service/LogMessageService.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import com.lt.health.entity.LogMessage; 5 | 6 | /** 7 | * @author 腾腾 8 | * @description 针对表【sys_log_message(日志表)】的数据库操作Service 9 | * @createDate 2022-04-01 23:06:33 10 | */ 11 | public interface LogMessageService extends IService { 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/service/MenuService.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.service; 2 | 3 | import com.lt.health.constant.Result; 4 | import com.lt.health.entity.Menu; 5 | import com.baomidou.mybatisplus.extension.service.IService; 6 | import com.lt.health.entity.dto.PageInfoDTO; 7 | 8 | /** 9 | * @author 狂小腾 10 | * @description 针对表【sys_menu】的数据库操作Service 11 | * @createDate 2022-03-26 20:36:16 12 | */ 13 | public interface MenuService extends IService { 14 | 15 | /** 16 | * 分页查询 17 | * 18 | * @param pageInfoDTO 查询条件 19 | * @return 分页结果 20 | */ 21 | Result findPage(PageInfoDTO pageInfoDTO); 22 | 23 | /** 24 | * 添加菜单接口 25 | * 26 | * @param menu 添加菜单信息 27 | * @return 成功或者失败信息 28 | */ 29 | Result insert(Menu menu); 30 | 31 | /** 32 | * 更新菜单接口 33 | * 34 | * @param menu 更新的菜单信息 35 | * @return 修改提示信息 36 | */ 37 | Result update(Menu menu); 38 | 39 | /** 40 | * 删除菜单接口 41 | * 42 | * @param id 菜单id 43 | * @return 删除提示信息 44 | */ 45 | Result delete(long id); 46 | 47 | /** 48 | * 查询所有的父级菜单 49 | * 50 | * @return 父级菜单 51 | */ 52 | Result findParentMenu(); 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/service/MotionService.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.service; 2 | 3 | import com.lt.health.constant.Result; 4 | import com.lt.health.entity.Motion; 5 | import com.baomidou.mybatisplus.extension.service.IService; 6 | import com.lt.health.entity.dto.PageInfoDTO; 7 | 8 | /** 9 | * @author 狂小腾 10 | * @description 针对表【sys_motion(运动表)】的数据库操作Service 11 | * @createDate 2022-03-26 20:36:16 12 | */ 13 | public interface MotionService extends IService { 14 | 15 | /** 16 | * 查询单个运动项目 17 | * 18 | * @param id 运动项目id 19 | * @return 该运动项目信息 20 | */ 21 | Result findInfo(Long id); 22 | 23 | /** 24 | * 分页查询 25 | * 26 | * @param pageInfoDTO 分页参数---根据运动项目名称 27 | * @return 分页结果集 28 | */ 29 | Result findPage(PageInfoDTO pageInfoDTO); 30 | 31 | /** 32 | * 增加运动项目 33 | * 34 | * @param sport 运动项目 35 | * @return 成功或失败信息 36 | */ 37 | Result add(Motion sport); 38 | 39 | /** 40 | * 修改运动项目名称 41 | * 42 | * @param sport 运动项目 43 | * @return 成功或失败信息 44 | */ 45 | Result edit(Motion sport); 46 | 47 | /** 48 | * 删除运动项目 49 | * 50 | * @param id 运动项目id 51 | * @return 成功或失败 52 | */ 53 | Result delete(Long id); 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/service/PermissionService.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.service; 2 | 3 | import com.lt.health.constant.Result; 4 | import com.lt.health.entity.Permission; 5 | import com.baomidou.mybatisplus.extension.service.IService; 6 | import com.lt.health.entity.dto.PageInfoDTO; 7 | 8 | /** 9 | * @author 狂小腾 10 | * @description 针对表【sys_permission】的数据库操作Service 11 | * @createDate 2022-03-26 20:36:16 12 | */ 13 | public interface PermissionService extends IService { 14 | 15 | /** 16 | * 查询所有的权限 17 | * 18 | * @return 返回结果 19 | */ 20 | Result findAll(); 21 | 22 | /** 23 | * 分页查询 24 | * 25 | * @param pageInfoDTO 分页参数---权限标签或数据权限标签 26 | * @return 分页结果 27 | */ 28 | Result findPage(PageInfoDTO pageInfoDTO); 29 | 30 | /** 31 | * 添加权限 32 | * 33 | * @param permission 添加权限数据 34 | * @return 成功或失败结果 35 | */ 36 | Result insert(Permission permission); 37 | 38 | /** 39 | * 修改权限 40 | * 41 | * @param permission 修改的权限数据 42 | * @return 成功或失败的结果 43 | */ 44 | Result update(Permission permission); 45 | 46 | /** 47 | * 删除权限 48 | * 49 | * @param id 权限id 50 | * @return 成功或失败结果 51 | */ 52 | Result delete(Long id); 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/service/RoleService.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.service; 2 | 3 | import com.lt.health.constant.Result; 4 | import com.lt.health.entity.Role; 5 | import com.baomidou.mybatisplus.extension.service.IService; 6 | import com.lt.health.entity.dto.PageInfoDTO; 7 | 8 | /** 9 | * @author 狂小腾 10 | * @description 针对表【sys_role】的数据库操作Service 11 | * @createDate 2022-03-26 20:36:16 12 | */ 13 | public interface RoleService extends IService { 14 | 15 | /** 16 | * 添加用户时角色信息列表 17 | */ 18 | Result findAll(); 19 | 20 | /** 21 | * 分页查询 22 | * 23 | * @param pageInfoDTO 分页参数 24 | * @return 分页结果集 25 | */ 26 | Result findPage(PageInfoDTO pageInfoDTO); 27 | 28 | /** 29 | * 添加角色 30 | * 31 | * @param role 角色信息 32 | * @return 成功或者失败信息 33 | */ 34 | Result insert(Role role); 35 | 36 | /** 37 | * 修改角色 38 | * 39 | * @param role 角色信息 40 | * @return 修改提示信息 41 | */ 42 | Result update(Role role); 43 | 44 | /** 45 | * 删除角色 46 | * 47 | * @param roleId 角色id 48 | * @return 删除提示信息 49 | */ 50 | Result delete(Long roleId); 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/service/RolesMenusService.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.service; 2 | 3 | import com.lt.health.entity.RolesMenus; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | 6 | /** 7 | * @author 狂小腾 8 | * @description 针对表【sys_roles_menus】的数据库操作Service 9 | * @createDate 2022-03-26 20:36:16 10 | */ 11 | public interface RolesMenusService extends IService { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/service/RolesPermissionsService.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.service; 2 | 3 | import com.lt.health.entity.RolesPermissions; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | 6 | /** 7 | * @author 狂小腾 8 | * @description 针对表【sys_roles_permissions】的数据库操作Service 9 | * @createDate 2022-03-26 20:36:16 10 | */ 11 | public interface RolesPermissionsService extends IService { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/service/SportService.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.service; 2 | 3 | import com.lt.health.constant.Result; 4 | import com.lt.health.entity.Sport; 5 | import com.baomidou.mybatisplus.extension.service.IService; 6 | import com.lt.health.entity.dto.PageInfoDTO; 7 | 8 | /** 9 | * @author 狂小腾 10 | * @description 针对表【sys_sport(运动咨询)】的数据库操作Service 11 | * @createDate 2022-03-26 20:36:16 12 | */ 13 | public interface SportService extends IService { 14 | 15 | /** 16 | * 分页查询 17 | * 18 | * @param pageInfoDTO 分页参数条件---标题或者内容 19 | * @return 分页结果 20 | */ 21 | Result findPage(PageInfoDTO pageInfoDTO); 22 | 23 | /** 24 | * 获取运动咨询详细信息 25 | * 26 | * @param id id 27 | * @return 详细信息 28 | */ 29 | Result getInfo(Long id); 30 | 31 | /** 32 | * 添加运动咨询 33 | * 34 | * @param sport 添加运动咨询信息 35 | * @return 成功或者失败信息 36 | */ 37 | Result insert(Sport sport); 38 | 39 | /** 40 | * 修改运动咨询信息 41 | * 42 | * @param sport 修改运动咨询信息 43 | * @return 成功或者失败信息 44 | */ 45 | Result update(Sport sport); 46 | 47 | /** 48 | * 删除运动咨询信息 49 | * 50 | * @param id id 51 | * @return 删除提示信息 52 | */ 53 | Result delete(Long id); 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/service/ToolService.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.service; 2 | 3 | import com.lt.health.constant.Result; 4 | import com.lt.health.entity.dto.MailDTO; 5 | 6 | /** 7 | * @description: 工具控制器的服务接口 8 | * @author: 狂小腾 9 | * @date: 2022/3/27 22:15 10 | */ 11 | public interface ToolService { 12 | /** 13 | * 发送邮件 14 | * 15 | * @param mailDTO 邮件参数 16 | * @return 邮件发送的结果 成功或失败 17 | */ 18 | Result sendMail(MailDTO mailDTO); 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/service/UserRolesService.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.service; 2 | 3 | import com.lt.health.entity.UserRoles; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | 6 | /** 7 | * @author 狂小腾 8 | * @description 针对表【sys_user_roles】的数据库操作Service 9 | * @createDate 2022-03-26 20:36:16 10 | */ 11 | public interface UserRolesService extends IService { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.service; 2 | 3 | import com.lt.health.constant.Result; 4 | import com.lt.health.entity.User; 5 | import com.baomidou.mybatisplus.extension.service.IService; 6 | import com.lt.health.entity.dto.LoginUserDTO; 7 | import com.lt.health.entity.dto.PageInfoDTO; 8 | 9 | /** 10 | * @author 狂小腾 11 | * @description 针对表【sys_user】的数据库操作Service 12 | * @createDate 2022-03-26 20:36:16 13 | */ 14 | public interface UserService extends IService { 15 | 16 | /** 17 | * 登录接口 18 | * 19 | * @param loginUserDTO 登录参数请求体 20 | * @return 返回token,用token去获取资源 21 | */ 22 | Result login(LoginUserDTO loginUserDTO); 23 | 24 | /** 25 | * 根据邮箱更新密码 26 | * 27 | * @param email 邮箱 28 | * @param password 加密后的密码 29 | */ 30 | void updatePasswordByMail(String email, String password); 31 | 32 | /** 33 | * 根据(查询条件---用户名、昵称、手机号码)分页查询 34 | * 35 | * @param pageInfoDTO 分页参数 36 | * @return 分页结果集 37 | */ 38 | Result findPage(PageInfoDTO pageInfoDTO); 39 | 40 | /** 41 | * 添加用户接口 42 | * 43 | * @param user 添加用户信息 44 | * @return 成功或者失败信息 45 | */ 46 | Result insert(User user); 47 | 48 | /** 49 | * 更新用户 50 | * 51 | * @param user 更新的用户信息 52 | * @return 提示信息 53 | */ 54 | Result update(User user); 55 | 56 | /** 57 | * 删除用户 58 | * 59 | * @param id 用户id 60 | * @return 删除提示信息 61 | */ 62 | Result delete(Long id); 63 | 64 | /** 65 | * WX小程序登录 66 | * 67 | * @param openid WX用户的唯一标识 68 | * @param sessionKey 会话密钥 69 | * @return token openid sessionKey 70 | */ 71 | Result miniLogin(String openid, String sessionKey); 72 | 73 | /** 74 | * 根据openid更新用户信息 75 | * 76 | * @param user 用户信息 77 | * @return 成功或失败信息 78 | */ 79 | Result updateInfoByOpenid(User user); 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/service/WxRunService.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import com.lt.health.constant.Result; 5 | import com.lt.health.entity.WxRun; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * @author 狂小腾 11 | * @description 针对表【sys_wx_run(微信运动步数记录表)】的数据库操作Service 12 | * @createDate 2022-03-26 20:36:16 13 | */ 14 | public interface WxRunService extends IService { 15 | 16 | /** 17 | * 获取WX运动步数接口 18 | * 19 | * @param runs 实时WX步数 20 | * @return WX步数和提示信息 21 | */ 22 | Result getRunStep(List runs); 23 | 24 | /** 25 | * WX步数记录接口 26 | * 27 | * @return WX步数记录 28 | */ 29 | Result stepReport(); 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/service/impl/FoodTypeServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.service.impl; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | import com.lt.health.constant.MessageConstant; 5 | import com.lt.health.constant.Result; 6 | import com.lt.health.entity.FoodType; 7 | import com.lt.health.service.FoodTypeService; 8 | import com.lt.health.mapper.FoodTypeMapper; 9 | import lombok.extern.slf4j.Slf4j; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Service; 12 | import org.springframework.transaction.annotation.Transactional; 13 | 14 | import java.util.List; 15 | 16 | /** 17 | * @author 狂小腾 18 | * @description 针对表【sys_food_type(食物分类表)】的数据库操作Service实现 19 | * @createDate 2022-03-26 20:36:16 20 | */ 21 | @Service 22 | @Slf4j 23 | public class FoodTypeServiceImpl extends ServiceImpl 24 | implements FoodTypeService { 25 | 26 | @Autowired 27 | private FoodTypeMapper foodTypeMapper; 28 | 29 | @Transactional 30 | @Override 31 | public Result insertType(FoodType foodType) { 32 | log.info("添加食物分类"); 33 | Long id = foodType.getId(); 34 | FoodType findFoodType = foodTypeMapper.selectById(id); 35 | if (findFoodType != null) { 36 | return Result.fail(MessageConstant.FOOD_TYPE_INSERT_FAIL); 37 | } 38 | foodTypeMapper.insert(foodType); 39 | return Result.success(MessageConstant.FOOD_TYPE_INSERT_SUCCESS); 40 | } 41 | 42 | @Transactional 43 | @Override 44 | public Result updateType(FoodType foodType) { 45 | log.info("更新食物分类"); 46 | int flag = foodTypeMapper.updateById(foodType); 47 | if (flag == 0) { 48 | return Result.fail(MessageConstant.FOOD_TYPE_UPDATE_FAIL); 49 | } 50 | return Result.success(MessageConstant.FOOD_TYPE_UPDATE_SUCCESS); 51 | } 52 | 53 | @Override 54 | public Result deleteType(Long id) { 55 | log.info("删除食物分类"); 56 | if (id < 0) { 57 | return Result.fail(MessageConstant.FOOD_TYPE_DELETE_FAIL); 58 | } 59 | int flag = foodTypeMapper.deleteById(id); 60 | if (flag == 0) { 61 | return Result.fail(MessageConstant.FOOD_TYPE_DELETE_FAIL); 62 | } 63 | return Result.success(MessageConstant.FOOD_TYPE_DELETE_SUCCESS); 64 | } 65 | 66 | @Override 67 | public Result typeAll() { 68 | List foodTypes = foodTypeMapper.selectList(null); 69 | return Result.success(MessageConstant.FOOD_TYPE_SELECT_SUCCESS, foodTypes); 70 | } 71 | } 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/service/impl/LogMessageServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.service.impl; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | import com.lt.health.entity.LogMessage; 5 | import com.lt.health.mapper.LogMessageMapper; 6 | import com.lt.health.service.LogMessageService; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | * @author 腾腾 11 | * @description 针对表【sys_log_message(日志表)】的数据库操作Service实现 12 | * @createDate 2022-04-01 23:06:33 13 | */ 14 | @Service 15 | public class LogMessageServiceImpl extends ServiceImpl 16 | implements LogMessageService { 17 | } 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/service/impl/MenuServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.service.impl; 2 | 3 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 4 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 5 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 6 | import com.lt.health.constant.MessageConstant; 7 | import com.lt.health.constant.Result; 8 | import com.lt.health.constant.UserConstant; 9 | import com.lt.health.entity.Menu; 10 | import com.lt.health.entity.dto.PageInfoDTO; 11 | import com.lt.health.mapper.MenuMapper; 12 | import com.lt.health.service.MenuService; 13 | import com.lt.health.utils.RedisUtil; 14 | import com.lt.health.utils.SecurityUtil; 15 | import lombok.extern.slf4j.Slf4j; 16 | import org.apache.commons.lang3.StringUtils; 17 | import org.springframework.beans.factory.annotation.Autowired; 18 | import org.springframework.stereotype.Service; 19 | import org.springframework.transaction.annotation.Transactional; 20 | 21 | import java.util.List; 22 | 23 | /** 24 | * @author 狂小腾 25 | * @description 针对表【sys_menu】的数据库操作Service实现 26 | * @createDate 2022-03-26 20:36:16 27 | */ 28 | @Service 29 | @Slf4j 30 | public class MenuServiceImpl extends ServiceImpl 31 | implements MenuService { 32 | 33 | @Autowired 34 | private MenuMapper menuMapper; 35 | 36 | @Autowired 37 | private RedisUtil redisUtil; 38 | 39 | @Override 40 | public Result findParentMenu() { 41 | QueryWrapper queryWrapper = new QueryWrapper<>(); 42 | queryWrapper.isNull("parent_id"); 43 | List menus = menuMapper.selectList(queryWrapper); 44 | return Result.success(MessageConstant.PARENT_MENU_SELECT_SUCCESS, menus); 45 | } 46 | 47 | @Override 48 | public Result findPage(PageInfoDTO pageInfoDTO) { 49 | Integer pageNumber = pageInfoDTO.getPageNumber(); 50 | Integer pageSize = pageInfoDTO.getPageSize(); 51 | String queryString = pageInfoDTO.getQueryString(); 52 | log.info("开始数据分页-->页码{}, --->{}页数--->查询内容{}", pageNumber, pageSize, queryString); 53 | Page page = new Page<>(pageNumber, pageSize); 54 | QueryWrapper query = new QueryWrapper<>(); 55 | query.like(StringUtils.isNotEmpty(queryString), "title", queryString); 56 | Page menuPage = menuMapper.selectPage(page, query); 57 | long total = menuPage.getTotal(); 58 | List records = menuPage.getRecords(); 59 | log.info("查询的总条数-->{}", total); 60 | log.info("分页列表-->{}", records); 61 | return Result.success(MessageConstant.PAGE_SUCCESS, menuPage); 62 | } 63 | 64 | @Transactional 65 | @Override 66 | public Result insert(Menu menu) { 67 | log.info("添加菜单信息"); 68 | menuMapper.insert(menu); 69 | redisUtil.delKey(UserConstant.USER_KEY_PRE + SecurityUtil.getUsername()); 70 | return Result.success(MessageConstant.MENU_INSERT_SUCCESS); 71 | } 72 | 73 | @Transactional 74 | @Override 75 | public Result update(Menu menu) { 76 | log.info("修改菜单信息"); 77 | menuMapper.updateById(menu); 78 | redisUtil.delKey(UserConstant.USER_KEY_PRE + SecurityUtil.getUsername()); 79 | return Result.success(MessageConstant.MENU_UPDATE_SUCCESS); 80 | } 81 | 82 | @Override 83 | public Result delete(long id) { 84 | log.info("删除菜单信息"); 85 | menuMapper.deleteById(id); 86 | redisUtil.delKey(UserConstant.USER_KEY_PRE + SecurityUtil.getUsername()); 87 | return Result.success(MessageConstant.MENU_DELETE_SUCCESS); 88 | } 89 | } 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/service/impl/MotionServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.service.impl; 2 | 3 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 4 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 5 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 6 | import com.lt.health.constant.MessageConstant; 7 | import com.lt.health.constant.Result; 8 | import com.lt.health.entity.Motion; 9 | import com.lt.health.entity.dto.PageInfoDTO; 10 | import com.lt.health.mapper.MotionMapper; 11 | import com.lt.health.service.MotionService; 12 | import lombok.extern.slf4j.Slf4j; 13 | import org.apache.commons.lang3.StringUtils; 14 | import org.springframework.beans.factory.annotation.Autowired; 15 | import org.springframework.stereotype.Service; 16 | import org.springframework.transaction.annotation.Transactional; 17 | 18 | import java.util.List; 19 | 20 | /** 21 | * @author 狂小腾 22 | * @description 针对表【sys_motion(运动表)】的数据库操作Service实现 23 | * @createDate 2022-03-26 20:36:16 24 | */ 25 | @Service 26 | @Slf4j 27 | public class MotionServiceImpl extends ServiceImpl implements MotionService { 28 | 29 | @Autowired 30 | private MotionMapper motionMapper; 31 | 32 | @Override 33 | public Result findInfo(Long id) { 34 | log.info("获取单个运动项目信息"); 35 | Motion motion = motionMapper.selectById(id); 36 | if (motion == null) { 37 | return Result.fail(MessageConstant.MOTION_SELECT_FAIL); 38 | } 39 | return Result.success(MessageConstant.MOTION_SELECT_SUCCESS, motion); 40 | } 41 | 42 | @Override 43 | public Result findPage(PageInfoDTO pageInfoDTO) { 44 | Integer pageNumber = pageInfoDTO.getPageNumber(); 45 | Integer pageSize = pageInfoDTO.getPageSize(); 46 | String queryString = pageInfoDTO.getQueryString(); 47 | log.info("开始数据分页-->页码{}, --->{}页数--->查询内容{}", pageNumber, pageSize, queryString); 48 | Page page = new Page<>(pageNumber, pageSize); 49 | QueryWrapper query = new QueryWrapper<>(); 50 | query.like(StringUtils.isNotEmpty(queryString), "name", queryString). 51 | or().like(StringUtils.isNotEmpty(queryString), "beneficial_position", queryString); 52 | Page motionPage = motionMapper.selectPage(page, query); 53 | long total = motionPage.getTotal(); 54 | List records = motionPage.getRecords(); 55 | log.info("查询的总条数-->{}", total); 56 | log.info("分页列表-->{}", records); 57 | return Result.success(MessageConstant.PAGE_SUCCESS, motionPage); 58 | } 59 | 60 | @Transactional 61 | @Override 62 | public Result add(Motion sport) { 63 | log.info("添加运动项目"); 64 | Integer id = sport.getId(); 65 | Motion motion = motionMapper.selectById(id); 66 | if (motion != null) { 67 | return Result.fail(MessageConstant.MOTION_INSERT_TIP); 68 | } 69 | int flag = motionMapper.insert(sport); 70 | if (flag <= 0) { 71 | return Result.fail(MessageConstant.MOTION_INSERT_FAIL); 72 | } 73 | return Result.success(MessageConstant.MOTION_INSERT_SUCCESS); 74 | } 75 | 76 | @Transactional 77 | @Override 78 | public Result edit(Motion sport) { 79 | log.info("修改运动项目"); 80 | int flag = motionMapper.updateById(sport); 81 | if (flag <= 0) { 82 | return Result.fail(MessageConstant.MOTION_UPDATE_FAIL); 83 | } 84 | return Result.success(MessageConstant.MOTION_UPDATE_SUCCESS); 85 | } 86 | 87 | @Override 88 | public Result delete(Long id) { 89 | log.info("删除运动项目"); 90 | int flag = motionMapper.deleteById(id); 91 | if (flag <= 0) { 92 | return Result.fail(MessageConstant.MOTION_DELETE_FAIL); 93 | } 94 | return Result.success(MessageConstant.MOTION_DELETE_SUCCESS); 95 | } 96 | } 97 | 98 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/service/impl/PermissionServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.service.impl; 2 | 3 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 4 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 5 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 6 | import com.lt.health.constant.MessageConstant; 7 | import com.lt.health.constant.Result; 8 | import com.lt.health.constant.UserConstant; 9 | import com.lt.health.entity.Permission; 10 | import com.lt.health.entity.dto.PageInfoDTO; 11 | import com.lt.health.mapper.PermissionMapper; 12 | import com.lt.health.service.PermissionService; 13 | import com.lt.health.utils.RedisUtil; 14 | import com.lt.health.utils.SecurityUtil; 15 | import lombok.extern.slf4j.Slf4j; 16 | import org.apache.commons.lang3.StringUtils; 17 | import org.springframework.beans.factory.annotation.Autowired; 18 | import org.springframework.stereotype.Service; 19 | import org.springframework.transaction.annotation.Transactional; 20 | 21 | import java.util.List; 22 | 23 | /** 24 | * @author 狂小腾 25 | * @description 针对表【sys_permission】的数据库操作Service实现 26 | * @createDate 2022-03-26 20:36:16 27 | */ 28 | @Service 29 | @Slf4j 30 | public class PermissionServiceImpl extends ServiceImpl 31 | implements PermissionService { 32 | 33 | @Autowired 34 | private PermissionMapper permissionMapper; 35 | 36 | @Autowired 37 | private RedisUtil redisUtil; 38 | 39 | @Override 40 | public Result findAll() { 41 | log.info("查询所有权限数据"); 42 | List permissions = permissionMapper.selectList(null); 43 | return Result.success(MessageConstant.PREMISSION_GET_SUCCESS, permissions); 44 | } 45 | 46 | @Override 47 | public Result findPage(PageInfoDTO pageInfoDTO) { 48 | Integer pageNumber = pageInfoDTO.getPageNumber(); 49 | Integer pageSize = pageInfoDTO.getPageSize(); 50 | String queryString = pageInfoDTO.getQueryString(); 51 | log.info("开始数据分页-->页码{}, --->{}页数--->查询内容{}", pageNumber, pageSize, queryString); 52 | Page page = new Page<>(pageNumber, pageSize); 53 | QueryWrapper query = new QueryWrapper<>(); 54 | query.like(StringUtils.isNotEmpty(queryString), "label", queryString) 55 | .or().like(StringUtils.isNotEmpty(queryString), "code", queryString); 56 | Page permissionPage = permissionMapper.selectPage(page, query); 57 | long total = permissionPage.getTotal(); 58 | List records = permissionPage.getRecords(); 59 | log.info("查询的总条数-->{}", total); 60 | log.info("分页列表-->{}", records); 61 | return Result.success(MessageConstant.PAGE_SUCCESS, permissionPage); 62 | } 63 | 64 | @Transactional 65 | @Override 66 | public Result insert(Permission permission) { 67 | log.info("数据权限插入"); 68 | permissionMapper.insert(permission); 69 | redisUtil.delKey(UserConstant.USER_KEY_PRE + SecurityUtil.getUsername()); 70 | return Result.success(MessageConstant.PREMISSION_INSERT_SUCCESS); 71 | } 72 | 73 | @Transactional 74 | @Override 75 | public Result update(Permission permission) { 76 | log.info("数据权限修改"); 77 | permissionMapper.updateById(permission); 78 | redisUtil.delKey(UserConstant.USER_KEY_PRE + SecurityUtil.getUsername()); 79 | return Result.success(MessageConstant.PREMISSION_UPDATE_SUCCESS); 80 | } 81 | 82 | @Override 83 | public Result delete(Long id) { 84 | log.info("数据权限删除"); 85 | permissionMapper.deleteById(id); 86 | redisUtil.delKey(UserConstant.USER_KEY_PRE + SecurityUtil.getUsername()); 87 | return Result.success(MessageConstant.PREMISSION_DELETE_SUCCESS); 88 | } 89 | } 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/service/impl/RolesMenusServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.service.impl; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | import com.lt.health.entity.RolesMenus; 5 | import com.lt.health.service.RolesMenusService; 6 | import com.lt.health.mapper.RolesMenusMapper; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | * @author 狂小腾 11 | * @description 针对表【sys_roles_menus】的数据库操作Service实现 12 | * @createDate 2022-03-26 20:36:16 13 | */ 14 | @Service 15 | public class RolesMenusServiceImpl extends ServiceImpl 16 | implements RolesMenusService { 17 | 18 | } 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/service/impl/RolesPermissionsServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.service.impl; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | import com.lt.health.entity.RolesPermissions; 5 | import com.lt.health.service.RolesPermissionsService; 6 | import com.lt.health.mapper.RolesPermissionsMapper; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | * @author 狂小腾 11 | * @description 针对表【sys_roles_permissions】的数据库操作Service实现 12 | * @createDate 2022-03-26 20:36:16 13 | */ 14 | @Service 15 | public class RolesPermissionsServiceImpl extends ServiceImpl 16 | implements RolesPermissionsService { 17 | 18 | } 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/service/impl/SportServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.service.impl; 2 | 3 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 4 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 5 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 6 | import com.lt.health.constant.MessageConstant; 7 | import com.lt.health.constant.Result; 8 | import com.lt.health.entity.Sport; 9 | import com.lt.health.entity.dto.PageInfoDTO; 10 | import com.lt.health.mapper.SportMapper; 11 | import com.lt.health.service.SportService; 12 | import com.lt.health.utils.SecurityUtil; 13 | import lombok.extern.slf4j.Slf4j; 14 | import org.apache.commons.lang3.StringUtils; 15 | import org.springframework.beans.factory.annotation.Autowired; 16 | import org.springframework.stereotype.Service; 17 | import org.springframework.transaction.annotation.Transactional; 18 | 19 | import java.util.Date; 20 | import java.util.List; 21 | 22 | /** 23 | * @author 狂小腾 24 | * @description 针对表【sys_sport(运动咨询)】的数据库操作Service实现 25 | * @createDate 2022-03-26 20:36:16 26 | */ 27 | @Service 28 | @Slf4j 29 | public class SportServiceImpl extends ServiceImpl 30 | implements SportService { 31 | 32 | @Autowired 33 | private SportMapper sportmapper; 34 | 35 | @Override 36 | public Result findPage(PageInfoDTO pageInfoDTO) { 37 | Integer pageNumber = pageInfoDTO.getPageNumber(); 38 | Integer pageSize = pageInfoDTO.getPageSize(); 39 | String queryString = pageInfoDTO.getQueryString(); 40 | log.info("开始数据分页-->页码{},--->页数{}--->查询内容{}", pageNumber, pageSize, queryString); 41 | Page page = new Page<>(pageNumber, pageSize); 42 | QueryWrapper queryWrapper = new QueryWrapper<>(); 43 | queryWrapper.like(StringUtils.isNotEmpty(queryString), "title", queryString) 44 | .or().like(StringUtils.isNotEmpty(queryString), "content", queryString); 45 | Page sportPage = sportmapper.selectPage(page, queryWrapper); 46 | List records = sportPage.getRecords(); 47 | long total = sportPage.getTotal(); 48 | log.info("查询的总条数-->{}", total); 49 | log.info("分页列表-->{}", records); 50 | return Result.success(MessageConstant.PAGE_SUCCESS, sportPage); 51 | } 52 | 53 | @Override 54 | public Result getInfo(Long id) { 55 | Sport sport = sportmapper.selectById(id); 56 | return Result.success(MessageConstant.SPORT_SELECT_SUCCESS, sport); 57 | } 58 | 59 | @Transactional 60 | @Override 61 | public Result insert(Sport sport) { 62 | sport.setCreateName(SecurityUtil.getUsername()); 63 | sportmapper.insert(sport); 64 | return Result.success(MessageConstant.SPORT_CONSULT_INSERT_SUCCESS); 65 | } 66 | 67 | @Transactional 68 | @Override 69 | public Result update(Sport sport) { 70 | sport.setUpdateName(SecurityUtil.getUsername()); 71 | sport.setUpdateTime(new Date()); 72 | sportmapper.updateById(sport); 73 | return Result.success(MessageConstant.SPORT_CONSULT_UPDATE_SUCCESS); 74 | } 75 | 76 | @Override 77 | public Result delete(Long id) { 78 | sportmapper.deleteById(id); 79 | return Result.success(MessageConstant.SPORT_CONSULT_DELETE_SUCCESS); 80 | } 81 | } 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/service/impl/ToolServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.service.impl; 2 | 3 | import com.lt.health.constant.Result; 4 | import com.lt.health.entity.dto.MailDTO; 5 | import com.lt.health.service.ToolService; 6 | import com.lt.health.utils.MailUtil; 7 | import lombok.extern.slf4j.Slf4j; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Service; 10 | 11 | /** 12 | * @description: 具体实现的工具服务类 13 | * @author: 狂小腾 14 | * @date: 2022/3/27 22:16 15 | */ 16 | @Service 17 | @Slf4j 18 | public class ToolServiceImpl implements ToolService { 19 | 20 | @Autowired 21 | private MailUtil mailUtil; 22 | 23 | @Override 24 | public Result sendMail(MailDTO mailDTO) { 25 | try { 26 | String msg = mailUtil.sendMail(mailDTO); 27 | return Result.success(msg); 28 | } catch (Exception e) { 29 | e.printStackTrace(); 30 | return Result.fail("邮件发送失败!"); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/service/impl/UserRolesServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.service.impl; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | import com.lt.health.entity.UserRoles; 5 | import com.lt.health.service.UserRolesService; 6 | import com.lt.health.mapper.UserRolesMapper; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | * @author 狂小腾 11 | * @description 针对表【sys_user_roles】的数据库操作Service实现 12 | * @createDate 2022-03-26 20:36:16 13 | */ 14 | @Service 15 | public class UserRolesServiceImpl extends ServiceImpl 16 | implements UserRolesService { 17 | 18 | } 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/service/impl/WxRunServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.service.impl; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | import com.lt.health.constant.MessageConstant; 5 | import com.lt.health.constant.Result; 6 | import com.lt.health.entity.WxRun; 7 | import com.lt.health.mapper.WxRunMapper; 8 | import com.lt.health.service.WxRunService; 9 | import com.lt.health.utils.DateUtil; 10 | import com.lt.health.utils.SecurityUtil; 11 | import lombok.extern.slf4j.Slf4j; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.stereotype.Service; 14 | 15 | import java.util.ArrayList; 16 | import java.util.HashMap; 17 | import java.util.List; 18 | import java.util.Map; 19 | 20 | /** 21 | * @author 狂小腾 22 | * @description 针对表【sys_wx_run(微信运动步数记录表)】的数据库操作Service实现 23 | * @createDate 2022-03-26 20:36:16 24 | */ 25 | @Service 26 | @Slf4j 27 | public class WxRunServiceImpl extends ServiceImpl 28 | implements WxRunService { 29 | 30 | @Autowired 31 | private WxRunMapper wxRunMapper; 32 | 33 | @Override 34 | public Result getRunStep(List runs) { 35 | List wxRuns = new ArrayList<>(); 36 | for (WxRun run : runs) { 37 | // 根据时间和openid查找WX运动 38 | WxRun stepWxRun = wxRunMapper.findStepByTimeAndOpenid(run.getTime(), run.getOpenid()); 39 | if (stepWxRun == null) { 40 | wxRuns.add(run); 41 | } else if (!stepWxRun.getStep().equals(run.getStep())) { 42 | // 更新WX步数 43 | wxRunMapper.updateStep(run.getTime(), run.getOpenid(), run.getStep()); 44 | } 45 | } 46 | if (wxRuns.size() > 0) { 47 | wxRunMapper.insertStep(wxRuns); 48 | } 49 | return Result.success(MessageConstant.WX_STEP_UPDATE_SUCCESS, runs.get(runs.size() - 1).getStep()); 50 | } 51 | 52 | @Override 53 | public Result stepReport() { 54 | String openId = SecurityUtil.getOpenId(); 55 | String dateTime = DateUtil.getDateTime(); 56 | Map> map = new HashMap<>(4); 57 | // 从今天起 第一周 获取今天是星期几 <---> 周日 58 | int week1 = DateUtil.getWeekOfDate(dateTime); 59 | //周日 60 | String date1 = DateUtil.getWeekBeforeDate(dateTime, week1 - 1); 61 | List runs1 = wxRunMapper.findByTime(dateTime, date1, openId); 62 | map.put("week1", runs1); 63 | //获取第二周 周日 <---> 周1 64 | String date2 = DateUtil.getWeekBeforeDate(date1, 1); 65 | String week2 = DateUtil.getWeekBeforeDate(date2, 6); 66 | List runs2 = wxRunMapper.findByTime(date2, week2, openId); 67 | map.put("week2", runs2); 68 | //第三周 周日 --- 周1 69 | String date3 = DateUtil.getWeekBeforeDate(week2, 1); 70 | String week3 = DateUtil.getWeekBeforeDate(date3, 6); 71 | List runs3 = wxRunMapper.findByTime(date3, week3, openId); 72 | map.put("week3", runs3); 73 | //第四周 周日 --- 周1 74 | String date4 = DateUtil.getWeekBeforeDate(date3, 1); 75 | String week5 = DateUtil.getWeekBeforeDate(date4, 6); 76 | List runs4 = wxRunMapper.findByTime(date4, week5, openId); 77 | map.put("week4", runs4); 78 | return Result.success(MessageConstant.WX_STEP_COUNT_SUCCESS, map); 79 | } 80 | } 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/test/Test.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.test; 2 | 3 | /** 4 | * @description: 测试copilot 5 | * @author: 狂小腾 6 | * @date: 2022/4/4 13:05 7 | */ 8 | public class Test { 9 | public static void main(String[] args) { 10 | System.out.println("hello world"); 11 | int[] array = new int[]{1, 2, 3, 55, 33, 23}; 12 | // 冒泡排序 13 | for (int i = 0; i < array.length - 1; i++) { 14 | for (int j = 0; j < array.length - 1 - i; j++) { 15 | if (array[j] > array[j + 1]) { 16 | int temp = array[j]; 17 | array[j] = array[j + 1]; 18 | array[j + 1] = temp; 19 | } 20 | } 21 | } 22 | // 手机号码正则表达式 23 | String phone = "17702304261"; 24 | String regex = "^((13[0-9])|(14[5,7,9])|(15[^4])|(18[0-9])|(17[0,1,3,5,6,7,8]))\\d{8}$"; 25 | boolean matches = phone.matches(regex); 26 | System.out.println(matches); 27 | // 用户名不能带特殊字符 28 | String username = "123456T123%"; 29 | String regex1 = "^[a-zA-Z0-9_]{6,16}$"; 30 | boolean matches1 = username.matches(regex1); 31 | System.out.println(matches1); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/utils/DateUtil.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.utils; 2 | 3 | import java.text.ParseException; 4 | import java.text.SimpleDateFormat; 5 | import java.util.Calendar; 6 | import java.util.Date; 7 | import java.util.Objects; 8 | 9 | /** 10 | * @description: 时间格式转换工具类 11 | * @author: 狂小腾 12 | * @date: 2022/3/22 9:06 13 | */ 14 | public class DateUtil { 15 | private static final String YYYY_MM_DD = "yyyy-MM-dd"; 16 | 17 | private static final String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss"; 18 | 19 | /** 20 | * 返回当前时间字符串 21 | * 22 | * @return 当前时间字符串---年月日 23 | */ 24 | public static String getDate() { 25 | SimpleDateFormat format = new SimpleDateFormat(YYYY_MM_DD); 26 | return format.format(new Date()); 27 | } 28 | 29 | /** 30 | * 返回当前时间字符串 年月日时分秒 31 | * 32 | * @return 当前时间字符串---年月日十分秒 33 | */ 34 | public static String getDateTime() { 35 | SimpleDateFormat format = new SimpleDateFormat(YYYY_MM_DD_HH_MM_SS); 36 | return format.format(new Date()); 37 | } 38 | 39 | /** 40 | * 返回当前时间字符串 年月日时分秒 41 | */ 42 | public static String parseDateTime(Date date, String format) { 43 | SimpleDateFormat dateFormat = new SimpleDateFormat(format); 44 | return dateFormat.format(date); 45 | } 46 | 47 | /** 48 | * 将时间字符串转换为时间对象 49 | */ 50 | public static Date formatDate(String time, String format) { 51 | SimpleDateFormat dateFormat = new SimpleDateFormat(format); 52 | try { 53 | return dateFormat.parse(time); 54 | } catch (ParseException e) { 55 | return null; 56 | } 57 | } 58 | 59 | /** 60 | * 传递10位时间戳返回正常的YYYY-MM-DD的格式 61 | */ 62 | public static String timeStampConvertString(long timestamp) { 63 | Date date = new Date(timestamp * 1000); 64 | return parseDateTime(date, YYYY_MM_DD); 65 | } 66 | 67 | /** 68 | * 传入时间字符串和天数 69 | * 返回该日期一周前的时间 70 | * 71 | * @param date 时间字符串 72 | * @param day 天数 73 | */ 74 | public static String getWeekBeforeDate(String date, int day) { 75 | Calendar cal = Calendar.getInstance(); 76 | cal.setTime(Objects.requireNonNull(formatDate(date, YYYY_MM_DD))); 77 | cal.add(Calendar.DATE, -day); 78 | Date time = cal.getTime(); 79 | return parseDateTime(time, YYYY_MM_DD); 80 | } 81 | 82 | /** 83 | * 根据时间得到本周是星期几 84 | */ 85 | public static int getWeekOfDate(String date) { 86 | int[] week = {7, 1, 2, 3, 4, 5, 6}; 87 | Calendar cal = Calendar.getInstance(); 88 | cal.setTime(Objects.requireNonNull(formatDate(date, YYYY_MM_DD))); 89 | int w = cal.get(Calendar.DAY_OF_WEEK) - 1; 90 | if (w < 0) { 91 | w = 0; 92 | } 93 | return week[w]; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/utils/DecryptDataUtil.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.utils; 2 | 3 | import org.bouncycastle.jce.provider.BouncyCastleProvider; 4 | import org.bouncycastle.util.Arrays; 5 | import org.bouncycastle.util.encoders.Base64; 6 | 7 | import javax.crypto.Cipher; 8 | import javax.crypto.spec.IvParameterSpec; 9 | import javax.crypto.spec.SecretKeySpec; 10 | import java.security.Key; 11 | import java.security.Security; 12 | 13 | /** 14 | * @description: WX解密工具类 15 | * @author: 狂小腾 16 | * @date: 2022/4/2 21:53 17 | */ 18 | public class DecryptDataUtil { 19 | 20 | private static final String KEY_ALGORITHM = "AES"; 21 | private static final String ALGORITHM_STR = "AES/CBC/PKCS7Padding"; 22 | private static Key key; 23 | private static Cipher cipher; 24 | 25 | /** 26 | * 最终解密出来的数据 27 | * 28 | * @param encryptData WX加密数据 29 | * @param sessionKey sessionKey 30 | * @param iv iv 31 | */ 32 | public static String decryptData(String encryptData, String sessionKey, String iv) { 33 | return new String( 34 | decryptOfDiyIV(Base64.decode(encryptData), 35 | Base64.decode(sessionKey), 36 | Base64.decode(iv)) 37 | ); 38 | } 39 | 40 | private static void init(byte[] keyBytes) { 41 | // 如果密钥不足16位,那么就补足. 这个if 中的内容很重要 42 | int base = 16; 43 | if (keyBytes.length % base != 0) { 44 | int groups = keyBytes.length / base + 1; 45 | byte[] temp = new byte[groups * base]; 46 | Arrays.fill(temp, (byte) 0); 47 | System.arraycopy(keyBytes, 0, temp, 0, keyBytes.length); 48 | keyBytes = temp; 49 | } 50 | // 初始化 51 | Security.addProvider(new BouncyCastleProvider()); 52 | // 转化成JAVA的密钥格式 53 | key = new SecretKeySpec(keyBytes, KEY_ALGORITHM); 54 | try { 55 | // 初始化cipher 56 | cipher = Cipher.getInstance(ALGORITHM_STR, "BC"); 57 | } catch (Exception e) { 58 | e.printStackTrace(); 59 | } 60 | } 61 | 62 | /** 63 | * 解密方法 64 | * 65 | * @param encryptedData 要解密的字符串 66 | * @param keyBytes 解密密钥 67 | * @param ivs 自定义对称解密算法初始向量 iv 68 | * @return 解密后的字节数组 69 | */ 70 | private static byte[] decryptOfDiyIV(byte[] encryptedData, byte[] keyBytes, byte[] ivs) { 71 | byte[] encryptedText = null; 72 | init(keyBytes); 73 | try { 74 | cipher.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(ivs)); 75 | encryptedText = cipher.doFinal(encryptedData); 76 | } catch (Exception e) { 77 | e.printStackTrace(); 78 | } 79 | return encryptedText; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/utils/EasyExcelUtil.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.utils; 2 | 3 | import com.alibaba.excel.EasyExcel; 4 | import com.alibaba.excel.context.AnalysisContext; 5 | import com.alibaba.excel.event.AnalysisEventListener; 6 | import com.alibaba.excel.support.ExcelTypeEnum; 7 | 8 | import java.io.InputStream; 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | /** 13 | * @description: 封装的excel工具类 14 | * @author: 狂小腾 15 | * @date: 2022/3/22 8:53 16 | */ 17 | public class EasyExcelUtil { 18 | /** 19 | * 读取excel 20 | */ 21 | public static List readExcel(InputStream file, Class model) { 22 | List list = new ArrayList<>(); 23 | EasyExcel 24 | //读取的文件 25 | .read(file) 26 | //反射获取类型 27 | .head(model) 28 | //excel类型 29 | .excelType(ExcelTypeEnum.XLSX) 30 | //读取的excel左下角的名字 31 | .sheet(0) 32 | //注册监听器 33 | .registerReadListener(new AnalysisEventListener() { 34 | @Override 35 | public void invoke(T t, AnalysisContext analysisContext) { 36 | list.add(t); 37 | } 38 | 39 | @Override 40 | public void doAfterAllAnalysed(AnalysisContext analysisContext) { 41 | System.out.println("读取完毕" + model); 42 | } 43 | }).doRead(); 44 | return list; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/utils/HttpUtil.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.utils; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.apache.http.NameValuePair; 5 | import org.apache.http.client.entity.UrlEncodedFormEntity; 6 | import org.apache.http.client.methods.CloseableHttpResponse; 7 | import org.apache.http.client.methods.HttpGet; 8 | import org.apache.http.client.methods.HttpPost; 9 | import org.apache.http.impl.client.CloseableHttpClient; 10 | import org.apache.http.impl.client.HttpClientBuilder; 11 | import org.apache.http.message.BasicNameValuePair; 12 | import org.apache.http.util.EntityUtils; 13 | 14 | import java.util.ArrayList; 15 | import java.util.List; 16 | import java.util.Map; 17 | 18 | /** 19 | * @description: 与微信小程序连同的工具类 20 | * @author: 狂小腾 21 | * @date: 2022/4/2 20:51 22 | */ 23 | @Slf4j 24 | public class HttpUtil { 25 | /** 26 | * 发送GET请求获取信息 27 | * 28 | * @param url url 29 | */ 30 | public static String getResponse(String url) { 31 | try { 32 | // 创建一个client请求 33 | CloseableHttpClient client = HttpClientBuilder.create().build(); 34 | HttpGet get = new HttpGet(url); 35 | // 发送请求 36 | CloseableHttpResponse response = client.execute(get); 37 | log.info("请求响应码:{}", response.getStatusLine().getStatusCode()); 38 | return EntityUtils.toString(response.getEntity()); 39 | } catch (Exception e) { 40 | log.error("GET网络请求发送失败: {}", e.getMessage()); 41 | return ""; 42 | } 43 | } 44 | 45 | /** 46 | * 发送POST请求获取信息 47 | * 48 | * @param url url 49 | */ 50 | public static String postResponse(String url, Map params) { 51 | try { 52 | // 创建一个client请求 53 | CloseableHttpClient client = HttpClientBuilder.create().build(); 54 | HttpPost post = new HttpPost(url); 55 | if (params != null && params.size() > 0) { 56 | List param = new ArrayList<>(); 57 | params.forEach((key, value) -> param.add(new BasicNameValuePair(key, value))); 58 | post.setEntity(new UrlEncodedFormEntity(param, "UTF-8")); 59 | } 60 | // 发送请求 61 | CloseableHttpResponse response = client.execute(post); 62 | log.info("请求响应码: {}", response.getStatusLine().getStatusCode()); 63 | String result = EntityUtils.toString(response.getEntity()); 64 | log.info("请求结果: {}", result); 65 | return result; 66 | } catch (Exception e) { 67 | log.error("POST网络请求发送失败: {}", e.getMessage()); 68 | return ""; 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/utils/JwtTokenUtil.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.utils; 2 | 3 | import io.jsonwebtoken.Claims; 4 | import io.jsonwebtoken.Jwts; 5 | import io.jsonwebtoken.SignatureAlgorithm; 6 | import org.springframework.beans.factory.annotation.Value; 7 | import org.springframework.security.core.userdetails.UserDetails; 8 | import org.springframework.stereotype.Component; 9 | 10 | import java.util.Date; 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | /** 15 | * @description: jwt工具类 16 | * @author: 狂小腾 17 | * @date: 2022/3/22 19:44 18 | */ 19 | @Component 20 | public class JwtTokenUtil { 21 | private static final String CLAIM_KEY_USERNAME = "sub"; 22 | private static final String CLAIM_KEY_CREATED = "created"; 23 | 24 | @Value("${jwt.secret}") 25 | private String secret; 26 | 27 | @Value("${jwt.expiration}") 28 | private Long expiration; 29 | 30 | public String generateToken(UserDetails userDetails) { 31 | Map claims = new HashMap<>(); 32 | claims.put(CLAIM_KEY_USERNAME, userDetails.getUsername()); 33 | claims.put(CLAIM_KEY_CREATED, new Date()); 34 | return generateToken(claims); 35 | } 36 | 37 | /** 38 | * 根据荷载生成token 39 | */ 40 | public String generateToken(Map claims) { 41 | return Jwts.builder() 42 | .setClaims(claims) 43 | .signWith(SignatureAlgorithm.HS512, secret) 44 | .setExpiration(new Date(System.currentTimeMillis() + expiration * 1000)) 45 | .compact(); 46 | } 47 | 48 | /** 49 | * 从token中获取用户名 50 | */ 51 | public String getUserNameFromToken(String token) { 52 | Claims claims = this.getTokenBody(token); 53 | if (claims == null) { 54 | throw new RuntimeException("获取用户名失败"); 55 | } 56 | return claims.getSubject(); 57 | } 58 | 59 | /** 60 | * token是否过期 61 | */ 62 | public boolean isExpiration(String token) { 63 | return getTokenBody(token).getExpiration().before(new Date()); 64 | } 65 | 66 | /** 67 | * 验证token是否有效 68 | */ 69 | public boolean validateToken(String token, UserDetails userDetails) { 70 | String username = getUserNameFromToken(token); 71 | return username.equals(userDetails.getUsername()) && !isExpiration(token); 72 | } 73 | 74 | /** 75 | * 判断token是否可以被刷新 76 | */ 77 | public boolean canRefresh(String token) { 78 | return !isExpiration(token); 79 | } 80 | 81 | /** 82 | * 刷新token 83 | */ 84 | public String refreshToken(String token) { 85 | Claims claims = getTokenBody(token); 86 | claims.setExpiration(new Date()); 87 | return generateToken(claims); 88 | } 89 | 90 | /** 91 | * 获取token中的信息 92 | */ 93 | public Claims getTokenBody(String token) { 94 | try { 95 | return Jwts.parser() 96 | .setSigningKey(secret) 97 | .parseClaimsJws(token) 98 | .getBody(); 99 | } catch (Exception e) { 100 | return null; 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/utils/MD5Util.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.utils; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.apache.commons.lang3.StringUtils; 5 | 6 | import java.math.BigInteger; 7 | import java.security.MessageDigest; 8 | import java.security.NoSuchAlgorithmException; 9 | 10 | /** 11 | * @description: MD5加密工具类 12 | * MD5加密是单向加密 不可逆==>不能解密 13 | * BCryptPasswordEncoder(强散哈希算法): 双向加密 可逆的 可解密 14 | * @author: 狂小腾 15 | * @date: 2022/3/21 23:44 16 | */ 17 | @Slf4j 18 | public class MD5Util { 19 | /** 20 | * md5加密 21 | * 22 | * @param password 要加密的内容 23 | * @return 32位的加密串 24 | */ 25 | public static String md5(String password) { 26 | if (StringUtils.isNotBlank(password)) { 27 | byte[] bytes = null; 28 | try { 29 | bytes = MessageDigest.getInstance("md5").digest(password.getBytes()); 30 | } catch (NoSuchAlgorithmException e) { 31 | log.error("没有MD5这个加密算法!"); 32 | } 33 | // 由md5加密算法得到的字节数组转换为16进制数字 34 | StringBuilder code = new StringBuilder(new BigInteger(1, bytes).toString(16)); 35 | //保证md5加密后是32位 36 | for (int i = 0; i < 32 - code.length(); i++) { 37 | code.insert(0, "0"); 38 | } 39 | return code.toString(); 40 | } else { 41 | return null; 42 | } 43 | } 44 | 45 | public static void main(String[] args) { 46 | System.out.println(md5("123456")); 47 | } 48 | } -------------------------------------------------------------------------------- /src/main/java/com/lt/health/utils/MailUtil.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.utils; 2 | 3 | import com.lt.health.entity.dto.MailDTO; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.beans.factory.annotation.Value; 7 | import org.springframework.mail.SimpleMailMessage; 8 | import org.springframework.mail.javamail.JavaMailSender; 9 | import org.springframework.mail.javamail.MimeMessageHelper; 10 | import org.springframework.stereotype.Component; 11 | 12 | import javax.mail.internet.MimeMessage; 13 | import java.util.Arrays; 14 | 15 | /** 16 | * @description: 邮件工具类 17 | * @author: 狂小腾 18 | * @date: 2022/3/27 23:11 19 | */ 20 | @Slf4j 21 | @Component 22 | public class MailUtil { 23 | 24 | @Autowired 25 | private JavaMailSender mailSender; 26 | 27 | @Value("${spring.mail.username}") 28 | private String from; 29 | 30 | /** 31 | * 发送邮件 32 | * 33 | * @param mail 发送内容 34 | * @return 发送成功或失败信息 35 | */ 36 | public String sendMail(MailDTO mail) { 37 | try { 38 | if (mail.isHtml()) { 39 | MimeMessage mimeMessage = mailSender.createMimeMessage(); 40 | MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage, true); 41 | messageHelper.setFrom(from); 42 | messageHelper.setSubject(mail.getSubject()); 43 | messageHelper.setText(mail.getContent(), true); 44 | messageHelper.setTo(mail.getReceivers()); 45 | mailSender.send(mimeMessage); 46 | log.info("HTML邮件发送成功!收件人---{}---", Arrays.asList(mail.getReceivers())); 47 | } else { 48 | // 创建邮件对象 49 | SimpleMailMessage mailMessage = new SimpleMailMessage(); 50 | // 发件人 51 | mailMessage.setFrom(from); 52 | // 收件人 53 | mailMessage.setTo(mail.getReceivers()); 54 | // 邮件主题 55 | mailMessage.setSubject(mail.getSubject()); 56 | // 邮件内容 57 | mailMessage.setText(mail.getContent()); 58 | mailSender.send(mailMessage); 59 | log.info("普通邮件发送成功! 收件人---{}---", Arrays.asList(mail.getReceivers())); 60 | } 61 | return "邮件发送成功!"; 62 | } catch (Exception e) { 63 | log.error("邮件发送失败--> {}", e.getMessage()); 64 | return "邮件发送失败!"; 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/utils/RedisUtil.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.utils; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.data.redis.core.RedisTemplate; 6 | import org.springframework.stereotype.Component; 7 | 8 | import java.util.concurrent.TimeUnit; 9 | 10 | /** 11 | * @description: reids工具类 12 | * @author: 狂小腾 13 | * @date: 2022/3/26 20:52 14 | */ 15 | @Slf4j 16 | @Component 17 | public class RedisUtil { 18 | 19 | @Autowired 20 | private RedisTemplate redisTemplate; 21 | 22 | /** 23 | * 向redis中存值 24 | * 25 | * @param key 键 26 | * @param value 值 27 | * @return 是否存入成功 28 | */ 29 | public boolean setValue(String key, Object value) { 30 | try { 31 | redisTemplate.opsForValue().set(key, value); 32 | return true; 33 | } catch (Exception e) { 34 | log.error("向redis中存入值时异常-->{}", e.getMessage()); 35 | return false; 36 | } 37 | } 38 | 39 | /** 40 | * 向redis中存值并指定过期时间 分钟 41 | * SECONDS: 秒 42 | * MINUTES: 分 43 | * HOURS: 时 44 | * DAYS: 天 45 | */ 46 | public boolean setValueTime(String key, Object value, long time) { 47 | try { 48 | if (time > 0) { 49 | redisTemplate.opsForValue().set(key, value, time, TimeUnit.MINUTES); 50 | } else { 51 | redisTemplate.opsForValue().set(key, value); 52 | } 53 | return true; 54 | } catch (Exception e) { 55 | log.error("设置缓存并指定过期时间异常-->{}", e.getMessage()); 56 | return false; 57 | } 58 | } 59 | 60 | /** 61 | * 根据key获取redis中的值 62 | */ 63 | public Object getValue(String key) { 64 | return key == null ? null : redisTemplate.opsForValue().get(key); 65 | } 66 | 67 | /** 68 | * 根据key删除redis中的缓存 69 | */ 70 | public void delKey(String... keys) { 71 | if (keys != null && keys.length > 0) { 72 | if (keys.length == 1) { 73 | redisTemplate.delete(keys[0]); 74 | } else { 75 | for (String key : keys) { 76 | redisTemplate.delete(key); 77 | } 78 | } 79 | } 80 | } 81 | 82 | /** 83 | * 判断值是否存在 84 | */ 85 | public boolean haskey(String key) { 86 | try { 87 | return redisTemplate.hasKey(key); 88 | } catch (Exception e) { 89 | log.error("redis值不存在-->{}", e.getMessage()); 90 | return false; 91 | } 92 | } 93 | 94 | /** 95 | * 获取redis键的过期时间 96 | * 0代表永久有效 97 | * 大于0就剩多少分钟失效 98 | */ 99 | public Long isExpire(String key) { 100 | return redisTemplate.getExpire(key, TimeUnit.MINUTES); 101 | } 102 | 103 | /** 104 | * 给key加过期时间 105 | */ 106 | public boolean expire(String key, long time) { 107 | try { 108 | if (time > 0) { 109 | redisTemplate.expire(key, time, TimeUnit.MINUTES); 110 | } 111 | return true; 112 | } catch (Exception e) { 113 | log.error("给旧的缓存设置新的过期时间异常--> {}", e.getMessage()); 114 | return false; 115 | } 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/utils/SecurityUtil.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.utils; 2 | 3 | import com.lt.health.config.security.entity.LoginUser; 4 | import com.lt.health.entity.User; 5 | import org.springframework.security.core.context.SecurityContextHolder; 6 | 7 | /** 8 | * @description: 用于获取当前登录用户的基本信息 9 | * @author: 狂小腾 10 | * @date: 2022/3/28 19:14 11 | */ 12 | public class SecurityUtil { 13 | 14 | /** 15 | * 从Security主体信息中获取用户信息 16 | */ 17 | public static User getUser() { 18 | User user = null; 19 | try { 20 | LoginUser loginUser = (LoginUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); 21 | if (loginUser == null) { 22 | throw new Exception("用户不存在!!!"); 23 | } 24 | user = loginUser.getUser(); 25 | if (user == null) { 26 | throw new Exception("用户不存在!!!"); 27 | } 28 | } catch (Exception e) { 29 | e.printStackTrace(); 30 | } 31 | // 用户脱敏 32 | user.setPassword(null); 33 | return user; 34 | } 35 | 36 | /** 37 | * 在security中获取用户名 38 | */ 39 | public static String getUsername() { 40 | return getUser().getUserName(); 41 | } 42 | 43 | /** 44 | * 在security中获取用户id 45 | */ 46 | public static Long getUserId() { 47 | return getUser().getId(); 48 | } 49 | 50 | /** 51 | * 在security中获取用户小程序ID 52 | */ 53 | public static String getOpenId() { 54 | return getUser().getOpenId(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/utils/SmsUtil.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.utils; 2 | 3 | import com.aliyun.dysmsapi20170525.Client; 4 | import com.aliyun.dysmsapi20170525.models.SendSmsRequest; 5 | import com.aliyun.dysmsapi20170525.models.SendSmsResponse; 6 | import com.aliyun.teaopenapi.models.Config; 7 | import lombok.extern.slf4j.Slf4j; 8 | import org.springframework.beans.factory.annotation.Value; 9 | import org.springframework.stereotype.Component; 10 | 11 | /** 12 | * @description: 阿里云发送短信服务工具类 13 | * @author: 狂小腾 14 | * @date: 2022/3/31 14:20 15 | */ 16 | @Component 17 | @Slf4j 18 | public class SmsUtil { 19 | @Value("${aliyun.accessKey}") 20 | private String accessKey; 21 | 22 | @Value("${aliyun.secretKey}") 23 | private String secretKey; 24 | 25 | @Value("${aliyun.signName}") 26 | private String signName; 27 | 28 | @Value("${aliyun.templateCode}") 29 | private String templateCode; 30 | 31 | /** 32 | * 构建发送短信的连接 33 | * 34 | * @return 短信的连接 35 | * @throws Exception exception 36 | */ 37 | public Client createClient() throws Exception { 38 | Config config = new Config(); 39 | config.setAccessKeyId(accessKey) 40 | .setAccessKeySecret(secretKey); 41 | config.endpoint = "dysmsapi.aliyuncs.com"; 42 | return new Client(config); 43 | } 44 | 45 | /** 46 | * 发送短信 47 | * 48 | * @param phoneNumber 手机号码 49 | * @param code 验证码 50 | */ 51 | public void sendSms(String phoneNumber, int code) { 52 | try { 53 | Client client = this.createClient(); 54 | SendSmsRequest request = new SendSmsRequest(); 55 | request.setPhoneNumbers(phoneNumber) 56 | .setSignName(signName) 57 | .setTemplateCode(templateCode) 58 | .setTemplateParam("{ code: " + code + " }"); 59 | SendSmsResponse response = client.sendSms(request); 60 | log.info("短信发送结果--> {}", response.getBody().code + "----------" + response.getBody().message); 61 | } catch (Exception e) { 62 | log.error("短信发送失败--> {}", e.getMessage()); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/lt/health/utils/WebUtil.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.utils; 2 | 3 | import com.lt.health.constant.UserConstant; 4 | import org.springframework.stereotype.Component; 5 | 6 | import javax.servlet.http.HttpServletRequest; 7 | import java.util.Map; 8 | 9 | /** 10 | * @description: 日志工具类 用来获取session中的用户信息来存入数据库 11 | * @author: 狂小腾 12 | * @date: 2022/4/1 18:47 13 | */ 14 | @Component 15 | public class WebUtil { 16 | 17 | /** 18 | * 从session中获取用户对象 19 | * 20 | * @param request request 21 | * @return 用户对象 22 | */ 23 | public Map getUser(HttpServletRequest request) { 24 | Map attributes = null; 25 | if (request != null) { 26 | Object user = request.getSession().getAttribute(UserConstant.USER_SESSION_KEY); 27 | attributes = (Map) user; 28 | } 29 | return attributes; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/resources/application-dev.yml: -------------------------------------------------------------------------------- 1 | # 开发环境配置 2 | 3 | # 配置mysql数据源 4 | spring: 5 | datasource: 6 | # 用户名 7 | username: root 8 | # 密码 9 | password: 806823 10 | # mysql的连接路径 11 | url: jdbc:mysql://localhost:3306/health?useUnicode=true&characterEncoding=UTF-8&useSSL=false 12 | # 配置驱动类 13 | driver-class-name: com.mysql.cj.jdbc.Driver 14 | # redis相关配置 15 | redis: 16 | # 配置主机 17 | host: 127.0.0.1 18 | # 配置使用的数据库 19 | database: 0 20 | # 指定端口 21 | port: 6379 22 | # 邮件配置 23 | mail: 24 | # smtp服务主机(163) QQ:smtp.qq.com 25 | host: smtp.qq.com 26 | # 服务协议 27 | protocol: smtp 28 | # 设置编码集 29 | default-encoding: UTF-8 30 | # 允许测试连接 31 | test-connection: true 32 | # 设置发件人 33 | username: 2300858713@qq.com 34 | # 授权码 35 | password: atrdavqvptfnebbe 36 | # 服务端口 37 | port: 465 38 | properties: 39 | mail: 40 | smtp: 41 | auth: true 42 | socketFactory: 43 | port: 465 44 | class: javax.net.ssl.SSLSocketFactory 45 | fallback: false 46 | starttls: 47 | enable: true 48 | required: true 49 | -------------------------------------------------------------------------------- /src/main/resources/application-prod.yml: -------------------------------------------------------------------------------- 1 | # 生产环境配置 2 | 3 | # 配置mysql数据源 4 | spring: 5 | datasource: 6 | # 用户名 7 | username: root 8 | # 密码 9 | password: 806823 10 | # mysql的连接路径 11 | url: jdbc:mysql://localhost:3306/health?useUnicode=true&characterEncoding=UTF-8&useSSL=false 12 | # 配置驱动类 13 | driver-class-name: com.mysql.cj.jdbc.Driver 14 | # redis相关配置 15 | redis: 16 | # 配置主机 17 | host: localhost 18 | # 配置使用的数据库 19 | database: 0 20 | # 指定端口 21 | port: 6379 22 | # 密码 23 | password: 24 | # 邮件配置 25 | mail: 26 | # smtp服务主机(163) QQ:smtp.qq.com 27 | host: smtp.qq.com 28 | # 服务协议 29 | protocol: smtp 30 | # 设置编码集 31 | default-encoding: UTF-8 32 | # 允许测试连接 33 | test-connection: true 34 | # 设置发件人 35 | username: 2300858713@qq.com 36 | # 授权码 37 | password: atrdavqvptfnebbe 38 | # 服务端口 39 | port: 465 40 | properties: 41 | mail: 42 | smtp: 43 | auth: true 44 | socketFactory: 45 | port: 465 46 | class: javax.net.ssl.SSLSocketFactory 47 | fallback: false 48 | starttls: 49 | enable: true 50 | required: true -------------------------------------------------------------------------------- /src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | # 端口信息 3 | port: 8000 4 | 5 | # 配置项目名称 6 | spring: 7 | author: 狂小腾 8 | application: 9 | name: personalHealth 10 | # 使用本地配置 11 | profiles: 12 | active: dev 13 | # 设置文件上传最大大小,默认1M 14 | servlet: 15 | multipart: 16 | max-file-size: 30MB 17 | # 日志输出彩色 18 | output: 19 | ansi: 20 | enabled: detect 21 | # AOP 配置 22 | aop: 23 | auto: true 24 | proxy-target-class: true 25 | 26 | # 配置MybatisPlus 27 | mybatis-plus: 28 | configuration: 29 | # 日志打印信息 30 | log-impl: org.apache.ibatis.logging.stdout.StdOutImpl 31 | # 开启驼峰命名 32 | map-underscore-to-camel-case: true 33 | # mapper接口找的xml文件 34 | mapper-locations: classpath:mapper/*.xml 35 | # 扫描的实体类 36 | type-aliases-package: com.lt.health.entity 37 | global-config: 38 | db-config: 39 | logic-delete-field: isDelete # 全局逻辑删除的实体字段名(since 3.3.0,配置后可以忽略不配置步骤2) 40 | logic-delete-value: 1 # 逻辑已删除值(默认为 1) 41 | logic-not-delete-value: 0 # 逻辑未删除值(默认为 0) 42 | 43 | # jwt配置 44 | jwt: 45 | # 请求头 46 | tokenHeader: Authorization 47 | # 签名加盐 48 | secret: iwqjhda8232bjgh432 49 | #JWT过期时间(60*60*24*7) 7天 50 | expiration: 604800 51 | # token头部 52 | tokenHead: 'Bearer ' 53 | 54 | # 配置七牛云 55 | qiniu: 56 | accessKey: 0z_mX9dvRAzBY7p2lLwOPHrgyiyzKx7fW6wJ7QYJ 57 | secretKey: cTnl5U3ZA1cIKzt3X4zpGnFWfdzPvMc9Q7e7fg1w 58 | bucket: mysport 59 | 60 | # 配置阿里云短信服务 61 | aliyun: 62 | # ak 63 | accessKey: 64 | # sk 65 | secretKey: 66 | # 签名 67 | signName: 68 | # 短信模板 69 | templateCode: 70 | 71 | # 微信小程序 72 | mini: 73 | # 密钥 74 | appid: wx764a8c18407bff62 75 | secret: 6b7173449d443d8299fd3ac5de837d60 76 | 77 | # 日志文件的配置 78 | logging: 79 | file: 80 | path: my.log 81 | 82 | # 项目相关配置 83 | lt: 84 | # 验证码配置 85 | captchaType: math 86 | -------------------------------------------------------------------------------- /src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////// 2 | // _ooOoo_ // 3 | // o8888888o // 4 | // 88" . "88 // 5 | // (| ^_^ |) // 6 | // O\ = /O // 7 | // ____/`---'\____ // 8 | // .' \\| |// `. // 9 | // / \\||| : |||// \ // 10 | // / _||||| -:- |||||- \ // 11 | // | | \\\ - /// | | // 12 | // | \_| ''\---/'' | | // 13 | // \ .-\__ `-` ___/-. / // 14 | // ___`. .' /--.--\ `. . ___ // 15 | // ."" '< `.___\_<|>_/___.' >'"". // 16 | // | | : `- \`.;`\ _ /`;.`/ - ` : | | // 17 | // \ \ `-. \_ __\ /__ _/ .-` / / // 18 | // ========`-.____`-.___\_____/___.-`____.-'======== // 19 | // `=---=' // 20 | // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ // 21 | // 佛祖保佑 永不宕机 永无BUG // 22 | //////////////////////////////////////////////////////////////////// 23 | spring-boot.version :: (${spring-boot.version}) author: (${spring.author}) -------------------------------------------------------------------------------- /src/main/resources/mapper/FoodMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | id,title,type_id, 40 | image_urls,nutrient,heat, 41 | protein,fat,carbon_water, 42 | dietary_fiber,vitamin_a,vitamin_c, 43 | vitamin_e,carrot,vitamin_b1, 44 | vitamin_b2,niacin,cholesterol, 45 | magnesium,iron,calcium, 46 | zinc,copper,manganese, 47 | potassium,phosphorus,sodium, 48 | selenium 49 | 50 | 51 | 52 | 53 | insert into sys_food values 54 | 55 | null,#{.title}, #{i.typeId}, #{i.imageUrls}, #{i.nutrient}, #{i.heat}, 56 | #{i.protein}, #{i.fat}, #{i.carbonWater}, #{i.dietaryFiber}, #{i.vitaminA}, 57 | #{i.vitaminC}, #{i.vitaminE}, #{i.carrot}, #{i.vitaminB1}, #{i.vitaminB2}, 58 | #{i.niacin}, #{i.cholesterol}, #{i.magnesium}, #{i.iron}, #{i.calcium}, 59 | #{i.zinc}, #{i.copper}, #{i.manganese}, #{i.potassium}, #{i.phosphorus}, 60 | #{i.sodium}, #{i.selenium} 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /src/main/resources/mapper/FoodTypeMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | id,title,icon 16 | 17 | 18 | 19 | 27 | 28 | 33 | 34 | -------------------------------------------------------------------------------- /src/main/resources/mapper/GoodsMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | id,name,price, 28 | number,create_time,create_user_id, 29 | image_url,model_type,control_mode, 30 | main_function,wifi_function,battery, 31 | characteristic,size,other, 32 | remark 33 | 34 | 35 | -------------------------------------------------------------------------------- /src/main/resources/mapper/LogMessageMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | id,user_name,content,remarks,table_name, 23 | date_time,result_value,ip, 24 | request_url,result,ex_string 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/main/resources/mapper/MenuMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | id,path,icon, 19 | title,component,parent_id, 20 | status 21 | 22 | 23 | 24 | 33 | 34 | 35 | 44 | 45 | 46 | 51 | 52 | 53 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /src/main/resources/mapper/MotionMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | id,name,applicable_age, 17 | beneficial_position,introduction 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/main/resources/mapper/PermissionMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | id,label,code, 16 | status 17 | 18 | 19 | 20 | 29 | 30 | 31 | 37 | 38 | -------------------------------------------------------------------------------- /src/main/resources/mapper/RoleMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | id,label,code, 17 | status,is_delete 18 | 19 | 20 | 21 | 29 | 30 | -------------------------------------------------------------------------------- /src/main/resources/mapper/RolesMenusMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | role_id,menu_id 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/main/resources/mapper/RolesPermissionsMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | role_id,permission_id 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/main/resources/mapper/SportMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | id,title,content, 20 | create_time,create_name,update_time, 21 | update_name,is_delete 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/main/resources/mapper/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | id,user_name,password, 27 | nick_name,sex,avatar_url, 28 | address,open_id,user_status, 29 | is_admin,phone_number,email, 30 | create_time,update_time,is_delete 31 | 32 | 33 | 34 | 35 | update sys_user 36 | 37 | 38 | nick_name = #{nickName}, 39 | 40 | 41 | sex = #{sex}, 42 | 43 | 44 | avatar_url = #{avatarUrl}, 45 | 46 | 47 | address = #{address}, 48 | 49 | 50 | phone_number = #{phoneNumber}, 51 | 52 | 53 | where open_id=#{openId} 54 | 55 | 56 | 57 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /src/main/resources/mapper/UserRolesMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | user_id,role_id 14 | 15 | 16 | 17 | 18 | insert into sys_user_roles 19 | values (#{userId}, #{roleId}) 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/main/resources/mapper/WxRunMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | openid,time,step 15 | 16 | 17 | 18 | 19 | insert into sys_wx_run values 20 | 21 | (#{wxRun.openid}, #{wxRun.time}, #{wxRun.step}) 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/test/java/com/lt/health/PersonalHealthApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.lt.health; 2 | 3 | import com.lt.health.entity.User; 4 | import com.lt.health.service.UserService; 5 | import org.junit.jupiter.api.Assertions; 6 | import org.junit.jupiter.api.Test; 7 | import org.springframework.boot.test.context.SpringBootTest; 8 | 9 | import javax.annotation.Resource; 10 | import java.util.List; 11 | 12 | @SpringBootTest 13 | class PersonalHealthApplicationTests { 14 | 15 | @Resource 16 | private UserService userService; 17 | 18 | @Test 19 | void contextLoads() { 20 | List list = userService.list(); 21 | int size = list.size(); 22 | Assertions.assertEquals(0, size); 23 | } 24 | 25 | 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/test/java/com/lt/health/mapper/MenuMapperTest.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.mapper; 2 | 3 | import com.lt.health.entity.Menu; 4 | import org.junit.jupiter.api.Test; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | 8 | import java.util.List; 9 | 10 | import static org.junit.jupiter.api.Assertions.*; 11 | 12 | /** 13 | * @description: 测试菜单sql 14 | * @author: 狂小腾 15 | * @date: 2022/3/27 17:05 16 | */ 17 | @SpringBootTest 18 | public class MenuMapperTest { 19 | 20 | @Autowired 21 | private MenuMapper menuMapper; 22 | 23 | @Test 24 | void findMenusByUserId() { 25 | List menus = menuMapper.findMenusByUserId(null); 26 | System.out.println(menus); 27 | } 28 | 29 | @Test 30 | void findChildrenMenuByPidAndUserId() { 31 | List childrenMenus = menuMapper.findChildrenMenuByPidAndUserId(1L, null); 32 | System.out.println(childrenMenus); 33 | 34 | } 35 | } -------------------------------------------------------------------------------- /src/test/java/com/lt/health/mapper/PermissionMapperTest.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.mapper; 2 | 3 | import com.lt.health.entity.Permission; 4 | import org.junit.jupiter.api.Test; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * @description: 测试数据权限sql 12 | * @author: 狂小腾 13 | * @date: 2022/3/27 17:01 14 | */ 15 | @SpringBootTest 16 | public class PermissionMapperTest { 17 | 18 | @Autowired 19 | private PermissionMapper permissionMapper; 20 | 21 | @Test 22 | public void findPermissionsByUserId() { 23 | List permissions = permissionMapper.findPermissionsByUserId(null); 24 | System.out.println(permissions); 25 | } 26 | } -------------------------------------------------------------------------------- /src/test/java/com/lt/health/mapper/RoleMapperTest.java: -------------------------------------------------------------------------------- 1 | package com.lt.health.mapper; 2 | 3 | import com.lt.health.entity.Role; 4 | import org.junit.jupiter.api.Test; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | 8 | import java.util.List; 9 | 10 | import static org.junit.jupiter.api.Assertions.*; 11 | 12 | /** 13 | * @description: 测试角色sql 14 | * @author: 狂小腾 15 | * @date: 2022/3/27 17:01 16 | */ 17 | @SpringBootTest 18 | public class RoleMapperTest { 19 | 20 | @Autowired 21 | private RoleMapper roleMapper; 22 | 23 | @Test 24 | void findRolesByUserId() { 25 | List roles = roleMapper.findRolesByUserId(null); 26 | System.out.println(roles); 27 | } 28 | } --------------------------------------------------------------------------------