From 934e15d2f454a251d796e263dfc6cf68e8fc3589 Mon Sep 17 00:00:00 2001 From: jia <2744404105@qq.com> Date: Wed, 28 Feb 2024 13:43:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=91=A8=E8=80=831?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 38 +++ .idea/.gitignore | 8 + .idea/encodings.xml | 15 + .idea/misc.xml | 14 + .idea/uiDesigner.xml | 124 +++++++++ .idea/vcs.xml | 6 + bwie-auth/pom.xml | 33 +++ .../src/main/java/com/bwie/auth/AuthApp.java | 16 ++ .../bwie/auth/controller/AuthController.java | 38 +++ .../com/bwie/auth/service/AuthService.java | 10 + .../auth/service/impl/AuthServiceImpl.java | 59 ++++ bwie-auth/src/main/resources/bootstrap.yml | 31 +++ bwie-common/pom.xml | 116 ++++++++ .../config/FastJson2JsonRedisSerializer.java | 48 ++++ .../bwie/common/config/MybatisPlusConfig.java | 30 ++ .../com/bwie/common/config/RedisConfig.java | 65 +++++ .../com/bwie/common/constant/Constants.java | 18 ++ .../bwie/common/constant/JwtConstants.java | 27 ++ .../common/constant/ServerNameConstants.java | 6 + .../bwie/common/constant/TokenConstants.java | 24 ++ .../main/java/com/bwie/common/domain/Car.java | 30 ++ .../java/com/bwie/common/domain/Goods.java | 51 ++++ .../main/java/com/bwie/common/domain/Ord.java | 29 ++ .../java/com/bwie/common/domain/User.java | 33 +++ .../bwie/common/domain/request/GoodsReq.java | 16 ++ .../common/domain/request/LoginRequest.java | 16 ++ .../bwie/common/domain/response/CarShow.java | 23 ++ .../common/domain/response/JwtResponse.java | 18 ++ .../common/handler/GlobalExceptionHandle.java | 56 ++++ .../com/bwie/common/redis/RedisCache.java | 260 ++++++++++++++++++ .../common/remote/user/UserRemoteService.java | 22 ++ .../user/factory/UserRemoteFactory.java | 23 ++ .../com/bwie/common/result/PageResult.java | 34 +++ .../java/com/bwie/common/result/Result.java | 63 +++++ .../java/com/bwie/common/utils/IdUtils.java | 19 ++ .../java/com/bwie/common/utils/JwtUtils.java | 105 +++++++ .../com/bwie/common/utils/SecurityUtils.java | 54 ++++ .../com/bwie/common/utils/StringUtils.java | 68 +++++ .../main/resources/META-INF/spring.factories | 6 + bwie-gateway/pom.xml | 44 +++ .../java/com/bwie/gateway/GatewayApp.java | 14 + .../gateway/config/GatewaySentinelConfig.java | 71 +++++ .../gateway/config/IgnoreWhiteConfig.java | 32 +++ .../com/bwie/gateway/filters/AuthFilter.java | 76 +++++ .../com/bwie/gateway/utils/GatewayUtils.java | 67 +++++ bwie-gateway/src/main/resources/bootstrap.yml | 29 ++ bwie-modules/bwie-car/pom.xml | 63 +++++ .../src/main/java/com/bwie/car/CarApp.java | 15 + .../bwie/car/controller/CarController.java | 74 +++++ .../java/com/bwie/car/mapper/CarMapper.java | 18 ++ .../java/com/bwie/car/service/CarService.java | 18 ++ .../com/bwie/car/service/CarServiceImpl.java | 62 +++++ .../bwie-car/src/main/resources/bootstrap.yml | 30 ++ .../src/main/resources/mapper/CarMapper.xml | 18 ++ bwie-modules/bwie-es/pom.xml | 69 +++++ .../src/main/java/com/bwie/es/EsApp.java | 34 +++ .../java/com/bwie/es/config/InitEsRes.java | 25 ++ .../com/bwie/es/controller/EsController.java | 44 +++ .../java/com/bwie/es/mapper/EsMapper.java | 7 + .../java/com/bwie/es/service/EsService.java | 13 + .../bwie/es/service/impl/EsServiceImpl.java | 128 +++++++++ .../main/java/com/bwie/es/sync/MyTask.java | 31 +++ .../bwie-es/src/main/resources/bootstrap.yml | 40 +++ .../src/main/resources/mapper/EsMapper.xml | 5 + bwie-modules/bwie-ord/pom.xml | 63 +++++ .../bwie/ord/controller/OrdController.java | 4 + .../java/com/bwie/ord/mapper/OrdMapper.java | 4 + .../java/com/bwie/ord/service/OrdService.java | 4 + .../com/bwie/ord/service/OrdServiceImpl.java | 4 + .../bwie-ord/src/main/resources/bootstrap.yml | 30 ++ bwie-modules/bwie-system/pom.xml | 64 +++++ .../src/main/java/com/bwie/system/SysApp.java | 15 + .../bwie/system/controller/SysController.java | 25 ++ .../com/bwie/system/mapper/SysMapper.java | 8 + .../com/bwie/system/service/SysService.java | 9 + .../bwie/system/service/SysServiceImpl.java | 24 ++ .../src/main/resources/bootstrap.yml | 30 ++ .../src/main/resources/mapper/SysMapper.xml | 5 + bwie-modules/pom.xml | 20 ++ pom.xml | 70 +++++ 80 files changed, 3058 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/encodings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/uiDesigner.xml create mode 100644 .idea/vcs.xml create mode 100644 bwie-auth/pom.xml create mode 100644 bwie-auth/src/main/java/com/bwie/auth/AuthApp.java create mode 100644 bwie-auth/src/main/java/com/bwie/auth/controller/AuthController.java create mode 100644 bwie-auth/src/main/java/com/bwie/auth/service/AuthService.java create mode 100644 bwie-auth/src/main/java/com/bwie/auth/service/impl/AuthServiceImpl.java create mode 100644 bwie-auth/src/main/resources/bootstrap.yml create mode 100644 bwie-common/pom.xml create mode 100644 bwie-common/src/main/java/com/bwie/common/config/FastJson2JsonRedisSerializer.java create mode 100644 bwie-common/src/main/java/com/bwie/common/config/MybatisPlusConfig.java create mode 100644 bwie-common/src/main/java/com/bwie/common/config/RedisConfig.java create mode 100644 bwie-common/src/main/java/com/bwie/common/constant/Constants.java create mode 100644 bwie-common/src/main/java/com/bwie/common/constant/JwtConstants.java create mode 100644 bwie-common/src/main/java/com/bwie/common/constant/ServerNameConstants.java create mode 100644 bwie-common/src/main/java/com/bwie/common/constant/TokenConstants.java create mode 100644 bwie-common/src/main/java/com/bwie/common/domain/Car.java create mode 100644 bwie-common/src/main/java/com/bwie/common/domain/Goods.java create mode 100644 bwie-common/src/main/java/com/bwie/common/domain/Ord.java create mode 100644 bwie-common/src/main/java/com/bwie/common/domain/User.java create mode 100644 bwie-common/src/main/java/com/bwie/common/domain/request/GoodsReq.java create mode 100644 bwie-common/src/main/java/com/bwie/common/domain/request/LoginRequest.java create mode 100644 bwie-common/src/main/java/com/bwie/common/domain/response/CarShow.java create mode 100644 bwie-common/src/main/java/com/bwie/common/domain/response/JwtResponse.java create mode 100644 bwie-common/src/main/java/com/bwie/common/handler/GlobalExceptionHandle.java create mode 100644 bwie-common/src/main/java/com/bwie/common/redis/RedisCache.java create mode 100644 bwie-common/src/main/java/com/bwie/common/remote/user/UserRemoteService.java create mode 100644 bwie-common/src/main/java/com/bwie/common/remote/user/factory/UserRemoteFactory.java create mode 100644 bwie-common/src/main/java/com/bwie/common/result/PageResult.java create mode 100644 bwie-common/src/main/java/com/bwie/common/result/Result.java create mode 100644 bwie-common/src/main/java/com/bwie/common/utils/IdUtils.java create mode 100644 bwie-common/src/main/java/com/bwie/common/utils/JwtUtils.java create mode 100644 bwie-common/src/main/java/com/bwie/common/utils/SecurityUtils.java create mode 100644 bwie-common/src/main/java/com/bwie/common/utils/StringUtils.java create mode 100644 bwie-common/src/main/resources/META-INF/spring.factories create mode 100644 bwie-gateway/pom.xml create mode 100644 bwie-gateway/src/main/java/com/bwie/gateway/GatewayApp.java create mode 100644 bwie-gateway/src/main/java/com/bwie/gateway/config/GatewaySentinelConfig.java create mode 100644 bwie-gateway/src/main/java/com/bwie/gateway/config/IgnoreWhiteConfig.java create mode 100644 bwie-gateway/src/main/java/com/bwie/gateway/filters/AuthFilter.java create mode 100644 bwie-gateway/src/main/java/com/bwie/gateway/utils/GatewayUtils.java create mode 100644 bwie-gateway/src/main/resources/bootstrap.yml create mode 100644 bwie-modules/bwie-car/pom.xml create mode 100644 bwie-modules/bwie-car/src/main/java/com/bwie/car/CarApp.java create mode 100644 bwie-modules/bwie-car/src/main/java/com/bwie/car/controller/CarController.java create mode 100644 bwie-modules/bwie-car/src/main/java/com/bwie/car/mapper/CarMapper.java create mode 100644 bwie-modules/bwie-car/src/main/java/com/bwie/car/service/CarService.java create mode 100644 bwie-modules/bwie-car/src/main/java/com/bwie/car/service/CarServiceImpl.java create mode 100644 bwie-modules/bwie-car/src/main/resources/bootstrap.yml create mode 100644 bwie-modules/bwie-car/src/main/resources/mapper/CarMapper.xml create mode 100644 bwie-modules/bwie-es/pom.xml create mode 100644 bwie-modules/bwie-es/src/main/java/com/bwie/es/EsApp.java create mode 100644 bwie-modules/bwie-es/src/main/java/com/bwie/es/config/InitEsRes.java create mode 100644 bwie-modules/bwie-es/src/main/java/com/bwie/es/controller/EsController.java create mode 100644 bwie-modules/bwie-es/src/main/java/com/bwie/es/mapper/EsMapper.java create mode 100644 bwie-modules/bwie-es/src/main/java/com/bwie/es/service/EsService.java create mode 100644 bwie-modules/bwie-es/src/main/java/com/bwie/es/service/impl/EsServiceImpl.java create mode 100644 bwie-modules/bwie-es/src/main/java/com/bwie/es/sync/MyTask.java create mode 100644 bwie-modules/bwie-es/src/main/resources/bootstrap.yml create mode 100644 bwie-modules/bwie-es/src/main/resources/mapper/EsMapper.xml create mode 100644 bwie-modules/bwie-ord/pom.xml create mode 100644 bwie-modules/bwie-ord/src/main/java/com/bwie/ord/controller/OrdController.java create mode 100644 bwie-modules/bwie-ord/src/main/java/com/bwie/ord/mapper/OrdMapper.java create mode 100644 bwie-modules/bwie-ord/src/main/java/com/bwie/ord/service/OrdService.java create mode 100644 bwie-modules/bwie-ord/src/main/java/com/bwie/ord/service/OrdServiceImpl.java create mode 100644 bwie-modules/bwie-ord/src/main/resources/bootstrap.yml create mode 100644 bwie-modules/bwie-system/pom.xml create mode 100644 bwie-modules/bwie-system/src/main/java/com/bwie/system/SysApp.java create mode 100644 bwie-modules/bwie-system/src/main/java/com/bwie/system/controller/SysController.java create mode 100644 bwie-modules/bwie-system/src/main/java/com/bwie/system/mapper/SysMapper.java create mode 100644 bwie-modules/bwie-system/src/main/java/com/bwie/system/service/SysService.java create mode 100644 bwie-modules/bwie-system/src/main/java/com/bwie/system/service/SysServiceImpl.java create mode 100644 bwie-modules/bwie-system/src/main/resources/bootstrap.yml create mode 100644 bwie-modules/bwie-system/src/main/resources/mapper/SysMapper.xml create mode 100644 bwie-modules/pom.xml create mode 100644 pom.xml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..a0c84c9 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..82dbec8 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/bwie-auth/pom.xml b/bwie-auth/pom.xml new file mode 100644 index 0000000..15bb2fb --- /dev/null +++ b/bwie-auth/pom.xml @@ -0,0 +1,33 @@ + + + 4.0.0 + + com.bwie + test_week1 + 1.0.0 + + + bwie-auth + + + 17 + 17 + UTF-8 + + + + + + + com.bwie + bwie-common + + + + org.springframework.boot + spring-boot-starter-web + + + diff --git a/bwie-auth/src/main/java/com/bwie/auth/AuthApp.java b/bwie-auth/src/main/java/com/bwie/auth/AuthApp.java new file mode 100644 index 0000000..b32381f --- /dev/null +++ b/bwie-auth/src/main/java/com/bwie/auth/AuthApp.java @@ -0,0 +1,16 @@ +package com.bwie.auth; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.openfeign.EnableFeignClients; + +@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) +@EnableDiscoveryClient +@EnableFeignClients(basePackages = "com.bwie.**") +public class AuthApp { + public static void main(String[] args) { + SpringApplication.run(AuthApp.class); + } +} diff --git a/bwie-auth/src/main/java/com/bwie/auth/controller/AuthController.java b/bwie-auth/src/main/java/com/bwie/auth/controller/AuthController.java new file mode 100644 index 0000000..c79cbf9 --- /dev/null +++ b/bwie-auth/src/main/java/com/bwie/auth/controller/AuthController.java @@ -0,0 +1,38 @@ +package com.bwie.auth.controller; + +import com.bwie.auth.service.AuthService; +import com.bwie.common.domain.User; +import com.bwie.common.domain.request.LoginRequest; +import com.bwie.common.domain.response.JwtResponse; +import com.bwie.common.result.Result; +import org.springframework.web.bind.annotation.*; + +@RestController +@ResponseBody +public class AuthController { + + private final AuthService authService; + + public AuthController(AuthService authService) { + this.authService = authService; + + } + + @PostMapping("login") + public Result login(@RequestBody LoginRequest loginRequest){ + JwtResponse login = authService.login(loginRequest); + return Result.success(login); + } + + @GetMapping("info") + public User info(){ + return authService.info(); + } + + + + + + + +} diff --git a/bwie-auth/src/main/java/com/bwie/auth/service/AuthService.java b/bwie-auth/src/main/java/com/bwie/auth/service/AuthService.java new file mode 100644 index 0000000..942d712 --- /dev/null +++ b/bwie-auth/src/main/java/com/bwie/auth/service/AuthService.java @@ -0,0 +1,10 @@ +package com.bwie.auth.service; + +import com.bwie.common.domain.User; +import com.bwie.common.domain.request.LoginRequest; +import com.bwie.common.domain.response.JwtResponse; + +public interface AuthService { + JwtResponse login(LoginRequest loginRequest); + User info(); +} diff --git a/bwie-auth/src/main/java/com/bwie/auth/service/impl/AuthServiceImpl.java b/bwie-auth/src/main/java/com/bwie/auth/service/impl/AuthServiceImpl.java new file mode 100644 index 0000000..555c6a0 --- /dev/null +++ b/bwie-auth/src/main/java/com/bwie/auth/service/impl/AuthServiceImpl.java @@ -0,0 +1,59 @@ +package com.bwie.auth.service.impl; + +import com.baomidou.mybatisplus.core.toolkit.Assert; +import com.bwie.auth.service.AuthService; +import com.bwie.common.constant.JwtConstants; +import com.bwie.common.constant.TokenConstants; +import com.bwie.common.domain.User; +import com.bwie.common.domain.request.LoginRequest; +import com.bwie.common.domain.response.JwtResponse; +import com.bwie.common.redis.RedisCache; +import com.bwie.common.remote.user.UserRemoteService; +import com.bwie.common.result.Result; +import com.bwie.common.utils.IdUtils; +import com.bwie.common.utils.JwtUtils; +import org.springframework.stereotype.Service; + +import javax.servlet.http.HttpServletRequest; +import java.util.HashMap; +import java.util.concurrent.TimeUnit; + +@Service +public class AuthServiceImpl implements AuthService { + private final RedisCache redisCache; + private final HttpServletRequest request; + private final UserRemoteService userRemoteService; + + public AuthServiceImpl(RedisCache redisCache, HttpServletRequest request, UserRemoteService userRemoteService) { + this.redisCache = redisCache; + this.request = request; + this.userRemoteService = userRemoteService; + } + @Override + public JwtResponse login(LoginRequest loginRequest) { + Result findtel = userRemoteService.findtel(loginRequest.getUserTel()); + Assert.isTrue(findtel.isSuccess(),"登陆失败"); + User data = findtel.getData(); + Assert.notNull(data,"电话不存在"); + Assert.isTrue(data.getUserPwd().equals(loginRequest.getUserPwd()),"密码错误"); + HashMap map = new HashMap<>(); + String key = IdUtils.genId(); + map.put(JwtConstants.USER_KEY,key); + String token = JwtUtils.createToken(map); + redisCache.setCacheObject(TokenConstants.LOGIN_TOKEN_KEY+key,data,TokenConstants.EXPIRATION, TimeUnit.SECONDS); + + + return JwtResponse.builder() + .token(token) + .expirTime(TokenConstants.EXPIRATION) + .build(); + } + + @Override + public User info() { + String header = request.getHeader(TokenConstants.TOKEN); + String userKey = JwtUtils.getUserKey(header); + User cacheObject = redisCache.getCacheObject(TokenConstants.LOGIN_TOKEN_KEY + userKey); + return cacheObject; + } +} diff --git a/bwie-auth/src/main/resources/bootstrap.yml b/bwie-auth/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..770cce2 --- /dev/null +++ b/bwie-auth/src/main/resources/bootstrap.yml @@ -0,0 +1,31 @@ +# Tomcat +server: + port: 9001 +# Spring +spring: + main: + allow-circular-references: true + allow-bean-definition-overriding: true + jackson: + date-format: yyyy-MM-dd HH:mm:ss + time-zone: GMT+8 + application: + # 应用名称 + name: bwie-auth + profiles: + # 环境配置 + active: dev + cloud: + nacos: + discovery: + # 服务注册地址 + server-addr: 124.221.177.197:8848 + config: + # 配置中心地址 + server-addr: 124.221.177.197:8848 + # 配置文件格式 + file-extension: yml + # 共享配置 + shared-configs: + - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} + diff --git a/bwie-common/pom.xml b/bwie-common/pom.xml new file mode 100644 index 0000000..0e0e8ad --- /dev/null +++ b/bwie-common/pom.xml @@ -0,0 +1,116 @@ + + + 4.0.0 + + com.bwie + test_week1 + 1.0.0 + + + bwie-common + + + 17 + 17 + UTF-8 + + + + + + org.springframework.cloud + spring-cloud-starter-bootstrap + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-config + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-sentinel + + + + org.springframework.cloud + spring-cloud-starter-loadbalancer + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + + io.jsonwebtoken + jjwt + 0.9.1 + + + + com.alibaba + fastjson + 1.2.80 + + + + org.springframework.boot + spring-boot-starter-data-redis + + + + org.springframework.boot + spring-boot-starter-validation + + + + org.apache.commons + commons-lang3 + + + + org.projectlombok + lombok + + + + cn.hutool + hutool-all + 5.8.3 + + + + com.aliyun + dysmsapi20170525 + 2.0.1 + + + + org.springframework.boot + spring-boot-starter-amqp + + + + + com.baomidou + mybatis-plus-boot-starter + 3.5.4.1 + + + + + com.alibaba.fastjson2 + fastjson2 + 2.0.42 + + + + diff --git a/bwie-common/src/main/java/com/bwie/common/config/FastJson2JsonRedisSerializer.java b/bwie-common/src/main/java/com/bwie/common/config/FastJson2JsonRedisSerializer.java new file mode 100644 index 0000000..584566b --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/config/FastJson2JsonRedisSerializer.java @@ -0,0 +1,48 @@ +package com.bwie.common.config; + +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONReader; +import com.alibaba.fastjson2.JSONWriter; +import com.alibaba.fastjson2.filter.Filter; +import org.springframework.data.redis.serializer.RedisSerializer; +import org.springframework.data.redis.serializer.SerializationException; + +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; + +/** + * Redis使用FastJson序列化 + * + * @author ruoyi + */ +public class FastJson2JsonRedisSerializer implements RedisSerializer { + public static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8; + + static final Filter AUTO_TYPE_FILTER = JSONReader.autoTypeFilter( + "org.springframework", "com"); + + private Class clazz; + + public FastJson2JsonRedisSerializer(Class clazz) { + super(); + this.clazz = clazz; + } + + @Override + public byte[] serialize (T t) throws SerializationException { + if (t == null) { + return new byte[0]; + } + return JSON.toJSONString(t, JSONWriter.Feature.WriteClassName).getBytes(DEFAULT_CHARSET); + } + + @Override + public T deserialize (byte[] bytes) throws SerializationException { + if (bytes == null || bytes.length <= 0) { + return null; + } + String str = new String(bytes, DEFAULT_CHARSET); + + return JSON.parseObject(str, clazz, AUTO_TYPE_FILTER); + } +} diff --git a/bwie-common/src/main/java/com/bwie/common/config/MybatisPlusConfig.java b/bwie-common/src/main/java/com/bwie/common/config/MybatisPlusConfig.java new file mode 100644 index 0000000..1983b7e --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/config/MybatisPlusConfig.java @@ -0,0 +1,30 @@ +package com.bwie.common.config; + +import com.baomidou.mybatisplus.annotation.DbType; +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * @author DongZl + * @description: Mybatis-Plus配置 + * @Date 2024-1-10 下午 05:12 + */ +@Configuration +public class MybatisPlusConfig { + + public MybatisPlusConfig () { + System.out.println("初始化-----------"); + } + + /** + * 添加分页插件 + */ + @Bean + public MybatisPlusInterceptor mybatisPlusInterceptor() { + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); + interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); + return interceptor; + } +} diff --git a/bwie-common/src/main/java/com/bwie/common/config/RedisConfig.java b/bwie-common/src/main/java/com/bwie/common/config/RedisConfig.java new file mode 100644 index 0000000..5d3ecc0 --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/config/RedisConfig.java @@ -0,0 +1,65 @@ +package com.bwie.common.config; + +import org.springframework.cache.annotation.CachingConfigurerSupport; +import org.springframework.cache.annotation.EnableCaching; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.script.DefaultRedisScript; +import org.springframework.data.redis.serializer.StringRedisSerializer; + +/** + * redis配置 + * + * @author ruoyi + */ +@Configuration +@EnableCaching +public class RedisConfig extends CachingConfigurerSupport { + @Bean + @SuppressWarnings(value = {"unchecked", "rawtypes"}) + public RedisTemplate redisTemplate (RedisConnectionFactory connectionFactory) { + RedisTemplate template = new RedisTemplate<>(); + template.setConnectionFactory(connectionFactory); + + FastJson2JsonRedisSerializer serializer = new FastJson2JsonRedisSerializer(Object.class); + + // 使用StringRedisSerializer来序列化和反序列化redis的key值 + template.setKeySerializer(new StringRedisSerializer()); + template.setValueSerializer(serializer); + + // Hash的key也采用StringRedisSerializer的序列化方式 + template.setHashKeySerializer(new StringRedisSerializer()); + template.setHashValueSerializer(serializer); + + template.afterPropertiesSet(); + return template; + } + + @Bean + public DefaultRedisScript limitScript () { + DefaultRedisScript redisScript = new DefaultRedisScript<>(); + redisScript.setScriptText(limitScriptText()); + redisScript.setResultType(Long.class); + return redisScript; + } + + /** + * 限流脚本 + */ + private String limitScriptText () { + return "local key = KEYS[1]\n" + + "local count = tonumber(ARGV[1])\n" + + "local time = tonumber(ARGV[2])\n" + + "local current = redis.call('get', key);\n" + + "if current and tonumber(current) > count then\n" + + " return tonumber(current);\n" + + "end\n" + + "current = redis.call('incr', key)\n" + + "if tonumber(current) == 1 then\n" + + " redis.call('expire', key, time)\n" + + "end\n" + + "return tonumber(current);"; + } +} diff --git a/bwie-common/src/main/java/com/bwie/common/constant/Constants.java b/bwie-common/src/main/java/com/bwie/common/constant/Constants.java new file mode 100644 index 0000000..9dd5a4e --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/constant/Constants.java @@ -0,0 +1,18 @@ +package com.bwie.common.constant; + +/** + * @description: 系统常量 + * @author DongZl + */ +public class Constants { + /** + * 成功标记 + */ + public static final Integer SUCCESS = 200; + public static final String SUCCESS_MSG = "操作成功"; + /** + * 失败标记 + */ + public static final Integer ERROR = 500; + public static final String ERROR_MSG = "操作异常"; +} diff --git a/bwie-common/src/main/java/com/bwie/common/constant/JwtConstants.java b/bwie-common/src/main/java/com/bwie/common/constant/JwtConstants.java new file mode 100644 index 0000000..9def83c --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/constant/JwtConstants.java @@ -0,0 +1,27 @@ +package com.bwie.common.constant; + +/** + * @author DongZl + * @description: Jwt常量 + */ +public class JwtConstants { + /** + * 用户ID字段 + */ + public static final String DETAILS_USER_ID = "user_id"; + + /** + * 用户名字段 + */ + public static final String DETAILS_USERNAME = "username"; + + /** + * 用户标识 + */ + public static final String USER_KEY = "user_key"; + + /** + * 令牌秘钥 + */ + public final static String SECRET = "abcdefghijklmnopqrstuvwxyz"; +} diff --git a/bwie-common/src/main/java/com/bwie/common/constant/ServerNameConstants.java b/bwie-common/src/main/java/com/bwie/common/constant/ServerNameConstants.java new file mode 100644 index 0000000..a555782 --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/constant/ServerNameConstants.java @@ -0,0 +1,6 @@ +package com.bwie.common.constant; + +public class ServerNameConstants { + + public final static String SYSTEM_NAME="bwie-system"; +} diff --git a/bwie-common/src/main/java/com/bwie/common/constant/TokenConstants.java b/bwie-common/src/main/java/com/bwie/common/constant/TokenConstants.java new file mode 100644 index 0000000..7e81bda --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/constant/TokenConstants.java @@ -0,0 +1,24 @@ +package com.bwie.common.constant; + +/** + * @author DongZl + * @description: 令牌常量 + */ +public class TokenConstants { + /** + * 缓存有效期,默认720(分钟) + */ + public final static long EXPIRATION = 720; + /** + * 缓存刷新时间,默认120(分钟) + */ + public final static long REFRESH_TIME = 120; + /** + * 权限缓存前缀 + */ + public final static String LOGIN_TOKEN_KEY = "login_tokens:"; + /** + * token标识 + */ + public static final String TOKEN = "token"; +} diff --git a/bwie-common/src/main/java/com/bwie/common/domain/Car.java b/bwie-common/src/main/java/com/bwie/common/domain/Car.java new file mode 100644 index 0000000..65ea6d5 --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/domain/Car.java @@ -0,0 +1,30 @@ +package com.bwie.common.domain; + +import com.alibaba.nacos.shaded.org.checkerframework.checker.units.qual.A; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +@TableName("car") +public class Car { + @TableId(value = "car_id",type = IdType.AUTO) + private Long carId; + @TableField(value = "goods_id") + private Long goodsId; + @TableField(value = "user_id") + private Long userId; + @TableField(value = "goods_num") + private Integer goodsNum; + + + +} diff --git a/bwie-common/src/main/java/com/bwie/common/domain/Goods.java b/bwie-common/src/main/java/com/bwie/common/domain/Goods.java new file mode 100644 index 0000000..6323a5c --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/domain/Goods.java @@ -0,0 +1,51 @@ +package com.bwie.common.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +@TableName("goods") +public class Goods { + /** + * 主键id + */ + @TableId(value = "goods_id",type = IdType.AUTO) + private Long goodsId; + //商品编码 + @TableField(value = "goods_hao") + private String goodsHao; + @TableField(value = "goods_name") + private String goodsName; + @TableField(value = "goods_brand") + private String goodsBrand; + @TableField(value = "goods_intr") + private String goodsIntr; + @TableField(value = "goods_price") + private Integer goodsPrice; + @TableField(value = "goods_xin") + private Integer goodsXin; + @TableField(value = "goods_bao") + private Integer goodsBao; + @TableField(value = "goods_sync") + private Integer goodsSync; + + + + + + + + + + + +} diff --git a/bwie-common/src/main/java/com/bwie/common/domain/Ord.java b/bwie-common/src/main/java/com/bwie/common/domain/Ord.java new file mode 100644 index 0000000..0550d02 --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/domain/Ord.java @@ -0,0 +1,29 @@ +package com.bwie.common.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; + +import java.util.Date; + +@Data +public class Ord { + private Long carId; + private Long goodsId; + private String goodsHao; + private String goodsName; + private String goodsBrand; + private Integer ordMoney; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm") + private Date ordTime; + + + + + + + + +} diff --git a/bwie-common/src/main/java/com/bwie/common/domain/User.java b/bwie-common/src/main/java/com/bwie/common/domain/User.java new file mode 100644 index 0000000..16b1e29 --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/domain/User.java @@ -0,0 +1,33 @@ +package com.bwie.common.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +@TableName("user") +public class User { + @TableId(value = "user_id",type = IdType.AUTO) + private Long userId; + @TableField(value = "user_tel") + private String userTel; + @TableField(value = "user_pwd") + private String userPwd; + @TableField(value = "user_yu") + private Integer userYu; + + + + + + + +} diff --git a/bwie-common/src/main/java/com/bwie/common/domain/request/GoodsReq.java b/bwie-common/src/main/java/com/bwie/common/domain/request/GoodsReq.java new file mode 100644 index 0000000..4da5297 --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/domain/request/GoodsReq.java @@ -0,0 +1,16 @@ +package com.bwie.common.domain.request; + +import com.baomidou.mybatisplus.annotation.TableField; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class GoodsReq { + private String goodsName; + private String goodsBrand; +} diff --git a/bwie-common/src/main/java/com/bwie/common/domain/request/LoginRequest.java b/bwie-common/src/main/java/com/bwie/common/domain/request/LoginRequest.java new file mode 100644 index 0000000..f02c848 --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/domain/request/LoginRequest.java @@ -0,0 +1,16 @@ +package com.bwie.common.domain.request; + +import com.baomidou.mybatisplus.annotation.TableField; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class LoginRequest { + private String userTel; + private String userPwd; +} diff --git a/bwie-common/src/main/java/com/bwie/common/domain/response/CarShow.java b/bwie-common/src/main/java/com/bwie/common/domain/response/CarShow.java new file mode 100644 index 0000000..c7e10f4 --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/domain/response/CarShow.java @@ -0,0 +1,23 @@ +package com.bwie.common.domain.response; + +import com.baomidou.mybatisplus.annotation.TableField; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class CarShow { + + private Long carId; + private Long goodsId; + private Long userId; + private Integer goodsNum; + + private String goodsHao; + private String goodsName; + private Integer goodsPrice; +} diff --git a/bwie-common/src/main/java/com/bwie/common/domain/response/JwtResponse.java b/bwie-common/src/main/java/com/bwie/common/domain/response/JwtResponse.java new file mode 100644 index 0000000..a136655 --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/domain/response/JwtResponse.java @@ -0,0 +1,18 @@ +package com.bwie.common.domain.response; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class JwtResponse { + private String token; + private Long expirTime; + + + +} diff --git a/bwie-common/src/main/java/com/bwie/common/handler/GlobalExceptionHandle.java b/bwie-common/src/main/java/com/bwie/common/handler/GlobalExceptionHandle.java new file mode 100644 index 0000000..533cab2 --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/handler/GlobalExceptionHandle.java @@ -0,0 +1,56 @@ +package com.bwie.common.handler; + +import com.alibaba.fastjson.JSONObject; +import com.bwie.common.result.Result; +import lombok.extern.log4j.Log4j2; +import org.springframework.context.annotation.Configuration; +import org.springframework.validation.ObjectError; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +import java.util.stream.Collectors; + +@RestControllerAdvice +@Log4j2 +@Configuration +public class GlobalExceptionHandle { + + @ExceptionHandler(value = MethodArgumentNotValidException.class) + public Result runtimeException(MethodArgumentNotValidException exception){ + log.error("请求异常:[{}]",exception.getMessage(),exception); + return Result.error( + JSONObject.toJSONString( + exception.getBindingResult().getAllErrors() + .stream() + .map(ObjectError::getDefaultMessage) + .toArray() + ) + ); +// return Result.error( +// exception.getBindingResult().getAllErrors() +// .stream() +// .map(ObjectError::getDefaultMessage) +// .collect(Collectors.joining())); + } + + + @ExceptionHandler(value = IllegalArgumentException.class) + public Result illegalArgumentExceptionHandle(IllegalArgumentException exception){ + log.error("请求异常[{}]",exception.getMessage(),exception); + return Result.error(exception.getMessage()); + } + + + + + + + + + + + + +} diff --git a/bwie-common/src/main/java/com/bwie/common/redis/RedisCache.java b/bwie-common/src/main/java/com/bwie/common/redis/RedisCache.java new file mode 100644 index 0000000..d1e4f79 --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/redis/RedisCache.java @@ -0,0 +1,260 @@ +package com.bwie.common.redis; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.BoundSetOperations; +import org.springframework.data.redis.core.HashOperations; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.ValueOperations; +import org.springframework.stereotype.Component; + +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +/** + * spring redis 工具类 + * + * @author ruoyi + **/ +@SuppressWarnings(value = {"unchecked", "rawtypes"}) +@Component +public class RedisCache { + @Autowired + public RedisTemplate redisTemplate; + + /** + * 缓存基本的对象,Integer、String、实体类等 + * + * @param key 缓存的键值 + * @param value 缓存的值 + */ + public void setCacheObject (final String key, final T value) { + redisTemplate.opsForValue().set(key, value); + } + + /** + * 缓存基本的对象,Integer、String、实体类等 + * + * @param key 缓存的键值 + * @param value 缓存的值 + * @param timeout 时间 + * @param timeUnit 时间颗粒度 + */ + public void setCacheObject (final String key, final T value, final Long timeout, final TimeUnit timeUnit) { + redisTemplate.opsForValue().set(key, value, timeout, timeUnit); + } + + /** + * 设置有效时间 + * + * @param key Redis键 + * @param timeout 超时时间 + * + * @return true=设置成功;false=设置失败 + */ + public boolean expire (final String key, final long timeout) { + return expire(key, timeout, TimeUnit.SECONDS); + } + + /** + * 设置有效时间 + * + * @param key Redis键 + * @param timeout 超时时间 + * @param unit 时间单位 + * + * @return true=设置成功;false=设置失败 + */ + public boolean expire (final String key, final long timeout, final TimeUnit unit) { + return Boolean.TRUE.equals(redisTemplate.expire(key, timeout, unit)); + } + + /** + * 获取有效时间 + * + * @param key Redis键 + * + * @return 有效时间 + */ + public long getExpire (final String key) { + return redisTemplate.getExpire(key); + } + + /** + * 判断 key是否存在 + * + * @param key 键 + * + * @return true 存在 false不存在 + */ + public Boolean hasKey (String key) { + return redisTemplate.hasKey(key); + } + + /** + * 获得缓存的基本对象。 + * + * @param key 缓存键值 + * + * @return 缓存键值对应的数据 + */ + public T getCacheObject (final String key) { + ValueOperations operation = redisTemplate.opsForValue(); + return operation.get(key); + } + + /** + * 删除单个对象 + * + * @param key + */ + public boolean deleteObject (final String key) { + return redisTemplate.delete(key); + } + + /** + * 删除集合对象 + * + * @param collection 多个对象 + * + * @return + */ + public boolean deleteObject (final Collection collection) { + return redisTemplate.delete(collection) > 0; + } + + /** + * 缓存List数据 + * + * @param key 缓存的键值 + * @param dataList 待缓存的List数据 + * + * @return 缓存的对象 + */ + public long setCacheList (final String key, final List dataList) { + Long count = redisTemplate.opsForList().rightPushAll(key, dataList); + return count == null ? 0 : count; + } + + /** + * 获得缓存的list对象 + * + * @param key 缓存的键值 + * + * @return 缓存键值对应的数据 + */ + public List getCacheList (final String key) { + return redisTemplate.opsForList().range(key, 0, -1); + } + + /** + * 缓存Set + * + * @param key 缓存键值 + * @param dataSet 缓存的数据 + * + * @return 缓存数据的对象 + */ + public BoundSetOperations setCacheSet (final String key, final Set dataSet) { + BoundSetOperations setOperation = redisTemplate.boundSetOps(key); + for (T t : dataSet) { + setOperation.add(t); + } + return setOperation; + } + + /** + * 获得缓存的set + * + * @param key + * + * @return + */ + public Set getCacheSet (final String key) { + return redisTemplate.opsForSet().members(key); + } + + /** + * 缓存Map + * + * @param key + * @param dataMap + */ + public void setCacheMap (final String key, final Map dataMap) { + if (dataMap != null) { + redisTemplate.opsForHash().putAll(key, dataMap); + } + } + + /** + * 获得缓存的Map + * + * @param key + * + * @return + */ + public Map getCacheMap (final String key) { + return redisTemplate.opsForHash().entries(key); + } + + /** + * 往Hash中存入数据 + * + * @param key Redis键 + * @param hKey Hash键 + * @param value 值 + */ + public void setCacheMapValue (final String key, final String hKey, final T value) { + redisTemplate.opsForHash().put(key, hKey, value); + } + + /** + * 获取Hash中的数据 + * + * @param key Redis键 + * @param hKey Hash键 + * + * @return Hash中的对象 + */ + public T getCacheMapValue (final String key, final String hKey) { + HashOperations opsForHash = redisTemplate.opsForHash(); + return opsForHash.get(key, hKey); + } + + /** + * 获取多个Hash中的数据 + * + * @param key Redis键 + * @param hKeys Hash键集合 + * + * @return Hash对象集合 + */ + public List getMultiCacheMapValue (final String key, final Collection hKeys) { + return redisTemplate.opsForHash().multiGet(key, hKeys); + } + + /** + * 删除Hash中的某条数据 + * + * @param key Redis键 + * @param hKey Hash键 + * + * @return 是否成功 + */ + public boolean deleteCacheMapValue (final String key, final String hKey) { + return redisTemplate.opsForHash().delete(key, hKey) > 0; + } + + /** + * 获得缓存的基本对象列表 + * + * @param pattern 字符串前缀 + * + * @return 对象列表 + */ + public Collection keys (final String pattern) { + return redisTemplate.keys(pattern); + } +} diff --git a/bwie-common/src/main/java/com/bwie/common/remote/user/UserRemoteService.java b/bwie-common/src/main/java/com/bwie/common/remote/user/UserRemoteService.java new file mode 100644 index 0000000..989328f --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/remote/user/UserRemoteService.java @@ -0,0 +1,22 @@ +package com.bwie.common.remote.user; + +import com.bwie.common.constant.ServerNameConstants; +import com.bwie.common.domain.User; +import com.bwie.common.remote.user.factory.UserRemoteFactory; +import com.bwie.common.result.Result; +import org.springframework.amqp.rabbit.core.RabbitTemplate; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestParam; + +@FeignClient( + name = ServerNameConstants.SYSTEM_NAME, + fallbackFactory = UserRemoteFactory.class +) +public interface UserRemoteService { + + @PostMapping("findtel") + public Result findtel(@RequestParam String userTel); + + +} diff --git a/bwie-common/src/main/java/com/bwie/common/remote/user/factory/UserRemoteFactory.java b/bwie-common/src/main/java/com/bwie/common/remote/user/factory/UserRemoteFactory.java new file mode 100644 index 0000000..141b9d2 --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/remote/user/factory/UserRemoteFactory.java @@ -0,0 +1,23 @@ +package com.bwie.common.remote.user.factory; + +import com.bwie.common.domain.User; +import com.bwie.common.remote.user.UserRemoteService; +import com.bwie.common.result.Result; +import lombok.extern.log4j.Log4j2; +import org.springframework.cloud.openfeign.FallbackFactory; +import org.springframework.stereotype.Component; + +@Component +@Log4j2 +public class UserRemoteFactory implements FallbackFactory { + @Override + public UserRemoteService create(Throwable cause) { + return new UserRemoteService() { + @Override + public Result findtel(String userTel) { + log.error("[{}-{}]查找电话远程调用错误",userTel,cause.getMessage(),cause); + return Result.error(); + } + }; + } +} diff --git a/bwie-common/src/main/java/com/bwie/common/result/PageResult.java b/bwie-common/src/main/java/com/bwie/common/result/PageResult.java new file mode 100644 index 0000000..85ecdda --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/result/PageResult.java @@ -0,0 +1,34 @@ +package com.bwie.common.result; + +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +/** + * @author DongZl + * @description: 列表返回结果集 + */ +@Data +public class PageResult implements Serializable { + /** + * 总条数 + */ + private long total; + /** + * 结果集合 + */ + private List list; + public PageResult() { + } + public PageResult(long total, List list) { + this.total = total; + this.list = list; + } + public static PageResult toPageResult(long total, List list){ + return new PageResult(total , list); + } + public static Result> toResult(long total, List list){ + return Result.success(PageResult.toPageResult(total,list)); + } +} diff --git a/bwie-common/src/main/java/com/bwie/common/result/Result.java b/bwie-common/src/main/java/com/bwie/common/result/Result.java new file mode 100644 index 0000000..148e0fa --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/result/Result.java @@ -0,0 +1,63 @@ +package com.bwie.common.result; + + +import com.bwie.common.constant.Constants; +import lombok.Data; + +import java.io.Serializable; + +/** + * @description: 响应信息主体 + * @author DongZl + */ +@Data +public class Result implements Serializable { + private static final long serialVersionUID = 1L; + /** 成功 */ + public static final int SUCCESS = Constants.SUCCESS; + /** 失败 */ + public static final int FAIL = Constants.ERROR; + private int code; + private String msg; + private T data; + public static Result success() { + return restResult(null, SUCCESS, Constants.SUCCESS_MSG); + } + public static Result success(T data) { + return restResult(data, SUCCESS, Constants.SUCCESS_MSG); + } + public static Result success(T data, String msg) { + return restResult(data, SUCCESS, msg); + } + public static Result error() { + return restResult(null, FAIL, Constants.ERROR_MSG); + } + public static Result error(String msg) { + return restResult(null, FAIL, msg); + } + public static Result error(T data) { + return restResult(data, FAIL, Constants.ERROR_MSG); + } + public static Result error(T data, String msg) { + return restResult(data, FAIL, msg); + } + public static Result error(int code, String msg) { + return restResult(null, code, msg); + } + private static Result restResult(T data, int code, String msg) { + Result apiResult = new Result<>(); + apiResult.setCode(code); + apiResult.setData(data); + apiResult.setMsg(msg); + return apiResult; + } + + public boolean isSuccess(){ + return this.code==SUCCESS; + } + public boolean isError(){ + return !isSuccess(); + } + + +} diff --git a/bwie-common/src/main/java/com/bwie/common/utils/IdUtils.java b/bwie-common/src/main/java/com/bwie/common/utils/IdUtils.java new file mode 100644 index 0000000..b013ae8 --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/utils/IdUtils.java @@ -0,0 +1,19 @@ +package com.bwie.common.utils; + +import java.util.UUID; + +/** + * @author DongZl + * @description: ID生成工具类 + * @Date 2024-1-10 下午 08:26 + */ +public class IdUtils { + + /** + * 生成UUID + * @return UUID + */ + public static String genId(){ + return UUID.randomUUID().toString().replace("-", ""); + } +} diff --git a/bwie-common/src/main/java/com/bwie/common/utils/JwtUtils.java b/bwie-common/src/main/java/com/bwie/common/utils/JwtUtils.java new file mode 100644 index 0000000..79ab70f --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/utils/JwtUtils.java @@ -0,0 +1,105 @@ +package com.bwie.common.utils; + + +import com.bwie.common.constant.JwtConstants; +import io.jsonwebtoken.Claims; +import io.jsonwebtoken.Jwts; +import io.jsonwebtoken.SignatureAlgorithm; + +import java.util.Map; + +/** + * @description: Jwt工具类 + * @author DongZl + */ +public class JwtUtils { + + public static String secret = JwtConstants.SECRET; + /** + * 从数据声明生成令牌 + * + * @param claims 数据声明 + * @return 令牌 + */ + public static String createToken(Map claims){ + String token = Jwts.builder().setClaims(claims).signWith(SignatureAlgorithm.HS512, secret).compact(); + return token; + } + /** + * 从令牌中获取数据声明 + * + * @param token 令牌 + * @return 数据声明 + */ + public static Claims parseToken(String token){ + return Jwts.parser().setSigningKey(secret).parseClaimsJws(token).getBody(); + } + /** + * 根据令牌获取用户标识 + * + * @param token 令牌 + * @return 用户ID + */ + public static String getUserKey(String token){ + Claims claims = parseToken(token); + return getValue(claims, JwtConstants.USER_KEY); + } + /** + * 根据令牌获取用户标识 + * + * @param claims 身份信息 + * @return 用户ID + */ + public static String getUserKey(Claims claims){ + return getValue(claims, JwtConstants.USER_KEY); + } + /** + * 根据令牌获取用户ID + * + * @param token 令牌 + * @return 用户ID + */ + public static String getUserId(String token){ + Claims claims = parseToken(token); + return getValue(claims, JwtConstants.DETAILS_USER_ID); + } + /** + * 根据身份信息获取用户ID + * + * @param claims 身份信息 + * @return 用户ID + */ + public static String getUserId(Claims claims){ + return getValue(claims, JwtConstants.DETAILS_USER_ID); + } + /** + * 根据令牌获取用户名 + * + * @param token 令牌 + * @return 用户名 + */ + public static String getUserName(String token){ + Claims claims = parseToken(token); + return getValue(claims, JwtConstants.DETAILS_USERNAME); + } + /** + * 根据身份信息获取用户名 + * + * @param claims 身份信息 + * @return 用户名 + */ + public static String getUserName(Claims claims){ + return getValue(claims, JwtConstants.DETAILS_USERNAME); + } + /** + * 根据身份信息获取键值 + * + * @param claims 身份信息 + * @param key 键 + * @return 值 + */ + public static String getValue(Claims claims, String key){ + Object obj = claims.get(key); + return obj == null ? "" : obj.toString(); + } +} diff --git a/bwie-common/src/main/java/com/bwie/common/utils/SecurityUtils.java b/bwie-common/src/main/java/com/bwie/common/utils/SecurityUtils.java new file mode 100644 index 0000000..c2ed35f --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/utils/SecurityUtils.java @@ -0,0 +1,54 @@ +package com.bwie.common.utils; + + +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Base64; + +/** + * 安全服务工具类 + * + * @author ruoyi + */ +public class SecurityUtils { + + + /** + * 生成BCryptPasswordEncoder密码 + * + * @param password 密码 + * + * @return 加密字符串 + */ + public static String encryptPassword (String password, String salt) { + return encryptMD5(password, salt); + } + + /** + * 判断密码是否相同 + * + * @param rawPassword 真实密码 + * @param encodedPassword 加密后字符 + * + * @return 结果 + */ + public static boolean matchesPassword (String rawPassword, String salt, String encodedPassword) { + return encryptMD5(rawPassword, salt).equals(encodedPassword); + } + + /** + * 计算字符串的MD5加密值,并返回Base64编码的字符串。 + * @param password 要加密的字符串 + * @return 加密后的Base64编码字符串 + */ + public static String encryptMD5(String password, String salt) { + try { + MessageDigest md = MessageDigest.getInstance("MD5"); + md.update((password + salt).getBytes()); // 加盐处理 + byte[] digest = md.digest(); + return Base64.getEncoder().encodeToString(digest); + } catch (NoSuchAlgorithmException e) { + throw new RuntimeException(e); + } + } +} diff --git a/bwie-common/src/main/java/com/bwie/common/utils/StringUtils.java b/bwie-common/src/main/java/com/bwie/common/utils/StringUtils.java new file mode 100644 index 0000000..93c47fd --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/utils/StringUtils.java @@ -0,0 +1,68 @@ +package com.bwie.common.utils; + +import org.springframework.util.AntPathMatcher; + +import java.util.Collection; +import java.util.List; + +/** + * @author DongZl + * @description: 字符串处理工具类 + */ +public class StringUtils extends org.apache.commons.lang3.StringUtils { + + /** + * * 判断一个对象是否为空 + * + * @param object Object + * @return true:为空 false:非空 + */ + public static boolean isNull(Object object) { + return object == null; + } + + /** + * * 判断一个Collection是否为空, 包含List,Set,Queue + * + * @param coll 要判断的Collection + * @return true:为空 false:非空 + */ + public static boolean isEmpty(Collection coll) { + return isNull(coll) || coll.isEmpty(); + } + + /** + * 查找指定字符串是否匹配指定字符串列表中的任意一个字符串 + * + * @param str 指定字符串 + * @param strs 需要检查的字符串数组 + * @return 是否匹配 + */ + public static boolean matches(String str, List strs) { + if (isEmpty(str) || isEmpty(strs)) { + return false; + } + for (String pattern : strs) { + if (isMatch(pattern, str)) + { + return true; + } + } + return false; + } + + /** + * 判断url是否与规则配置: + * ? 表示单个字符; + * * 表示一层路径内的任意字符串,不可跨层级; + * ** 表示任意层路径; + * + * @param pattern 匹配规则 + * @param url 需要匹配的url + * @return + */ + public static boolean isMatch(String pattern, String url) { + AntPathMatcher matcher = new AntPathMatcher(); + return matcher.match(pattern, url); + } +} diff --git a/bwie-common/src/main/resources/META-INF/spring.factories b/bwie-common/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..b83ea18 --- /dev/null +++ b/bwie-common/src/main/resources/META-INF/spring.factories @@ -0,0 +1,6 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ + com.bwie.common.config.MybatisPlusConfig,\ + com.bwie.common.handler.GlobalExceptionHandle,\ + com.bwie.common.config.RedisConfig,\ + com.bwie.common.redis.RedisCache,\ + com.bwie.common.remote.user.factory.UserRemoteFactory diff --git a/bwie-gateway/pom.xml b/bwie-gateway/pom.xml new file mode 100644 index 0000000..90cc001 --- /dev/null +++ b/bwie-gateway/pom.xml @@ -0,0 +1,44 @@ + + + 4.0.0 + + com.bwie + test_week1 + 1.0.0 + + + bwie-gateway + + + 17 + 17 + UTF-8 + + + + + + com.bwie + bwie-common + + + + + org.springframework.cloud + spring-cloud-starter-gateway + + + + com.alibaba.cloud + spring-cloud-alibaba-sentinel-gateway + + + + com.alibaba.csp + sentinel-spring-cloud-gateway-adapter + + + + diff --git a/bwie-gateway/src/main/java/com/bwie/gateway/GatewayApp.java b/bwie-gateway/src/main/java/com/bwie/gateway/GatewayApp.java new file mode 100644 index 0000000..156356c --- /dev/null +++ b/bwie-gateway/src/main/java/com/bwie/gateway/GatewayApp.java @@ -0,0 +1,14 @@ +package com.bwie.gateway; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; + +@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) +@EnableDiscoveryClient +public class GatewayApp { + public static void main(String[] args) { + SpringApplication.run(GatewayApp.class); + } +} diff --git a/bwie-gateway/src/main/java/com/bwie/gateway/config/GatewaySentinelConfig.java b/bwie-gateway/src/main/java/com/bwie/gateway/config/GatewaySentinelConfig.java new file mode 100644 index 0000000..1ad8ba8 --- /dev/null +++ b/bwie-gateway/src/main/java/com/bwie/gateway/config/GatewaySentinelConfig.java @@ -0,0 +1,71 @@ +package com.bwie.gateway.config; + +import com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayFlowRule; +import com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayRuleManager; +import com.alibaba.csp.sentinel.adapter.gateway.sc.exception.SentinelGatewayBlockExceptionHandler; +import org.springframework.beans.factory.ObjectProvider; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.Ordered; +import org.springframework.core.annotation.Order; +import org.springframework.http.codec.ServerCodecConfigurer; +import org.springframework.web.reactive.result.view.ViewResolver; + +import javax.annotation.PostConstruct; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +/** + * @deprecation: 网关限流控件 + * @author DongZl + */ +@Configuration +public class GatewaySentinelConfig { + /** + * 查看解析器 + */ + private final List viewResolvers; + /** + * 服务器编解码器配置 + */ + private final ServerCodecConfigurer serverCodecConfigurer; + public GatewaySentinelConfig(ObjectProvider> viewResolversProvider, + ServerCodecConfigurer serverCodecConfigurer) { + this.viewResolvers = viewResolversProvider.getIfAvailable(Collections::emptyList); + this.serverCodecConfigurer = serverCodecConfigurer; + } + /** + * Sentinel 网关块异常处理程序 + * @return + */ + @Bean + @Order(Ordered.HIGHEST_PRECEDENCE) + public SentinelGatewayBlockExceptionHandler sentinelGatewayBlockExceptionHandler() { + // 给 Spring Cloud GatewayApp 注册块异常处理程序。 + return new SentinelGatewayBlockExceptionHandler(viewResolvers, serverCodecConfigurer); + } + + /** + * 初始化网关配置 + */ + @PostConstruct + public void doInit() { + initGatewayRules(); + } + /** + * 配置限流规则 + */ + private void initGatewayRules() { + Set rules = new HashSet<>(); + rules.add(new GatewayFlowRule("cloud-user") + // 限流阈值 + .setCount(1) + // 统计时间窗口,单位是秒,默认是 1 秒 + .setIntervalSec(5) + ); + //添加到限流规则当中 + GatewayRuleManager.loadRules(rules); + } +} diff --git a/bwie-gateway/src/main/java/com/bwie/gateway/config/IgnoreWhiteConfig.java b/bwie-gateway/src/main/java/com/bwie/gateway/config/IgnoreWhiteConfig.java new file mode 100644 index 0000000..5705d6f --- /dev/null +++ b/bwie-gateway/src/main/java/com/bwie/gateway/config/IgnoreWhiteConfig.java @@ -0,0 +1,32 @@ +package com.bwie.gateway.config; + +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import lombok.extern.log4j.Log4j2; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.cloud.context.config.annotation.RefreshScope; +import org.springframework.context.annotation.Configuration; + +import java.util.ArrayList; +import java.util.List; + +/** + * @description: 放行白名单配置 + * @author DongZl + */ +@Configuration +@RefreshScope +@ConfigurationProperties(prefix = "ignore") +@Data +@Log4j2 +public class IgnoreWhiteConfig { + /** + * 放行白名单配置,网关不校验此处的白名单 + */ + private List whites = new ArrayList<>(); + + public void setWhites(List whites) { + log.info("加载网关路径白名单:{}", JSONObject.toJSONString(whites)); + this.whites = whites; + } +} diff --git a/bwie-gateway/src/main/java/com/bwie/gateway/filters/AuthFilter.java b/bwie-gateway/src/main/java/com/bwie/gateway/filters/AuthFilter.java new file mode 100644 index 0000000..f9e7e4d --- /dev/null +++ b/bwie-gateway/src/main/java/com/bwie/gateway/filters/AuthFilter.java @@ -0,0 +1,76 @@ +package com.bwie.gateway.filters; + +import com.bwie.common.constant.JwtConstants; +import com.bwie.common.constant.TokenConstants; +import com.bwie.common.redis.RedisCache; +import com.bwie.common.utils.JwtUtils; +import com.bwie.common.utils.StringUtils; +import com.bwie.gateway.config.IgnoreWhiteConfig; +import com.bwie.gateway.utils.GatewayUtils; +import io.jsonwebtoken.Claims; +import org.springframework.cloud.gateway.filter.GatewayFilter; +import org.springframework.cloud.gateway.filter.GatewayFilterChain; +import org.springframework.cloud.gateway.filter.GlobalFilter; +import org.springframework.core.Ordered; +import org.springframework.http.HttpMethod; +import org.springframework.http.server.reactive.ServerHttpRequest; +import org.springframework.stereotype.Component; +import org.springframework.web.server.ServerWebExchange; +import reactor.core.publisher.Mono; + +import java.util.List; +import java.util.concurrent.TimeUnit; + +@Component +public class AuthFilter implements GlobalFilter, Ordered { + private final RedisCache redisCache; + private final IgnoreWhiteConfig ignoreWhiteConfig; + + public AuthFilter(RedisCache redisCache, IgnoreWhiteConfig ignoreWhiteConfig) { + this.redisCache = redisCache; + this.ignoreWhiteConfig = ignoreWhiteConfig; + } + + @Override + public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { + ServerHttpRequest request = exchange.getRequest(); + String path = request.getURI().getPath(); + System.out.println("path = " + path); + HttpMethod method = request.getMethod(); + System.out.println("method = " + method); + + ServerHttpRequest.Builder mutate = request.mutate(); + List whites = ignoreWhiteConfig.getWhites(); + if(StringUtils.matches(path,whites)){ + return chain.filter(exchange); + } + + String first = request.getHeaders().getFirst(TokenConstants.TOKEN); + if(null==first){ + return GatewayUtils.errorResponse(exchange,"token不为空"); + } + + Claims claims = JwtUtils.parseToken(first); + if(null==claims){ + return GatewayUtils.errorResponse(exchange,"token格式不正确"); + } + String userKey = JwtUtils.getUserKey(claims); + if(!redisCache.hasKey(TokenConstants.LOGIN_TOKEN_KEY+userKey)){ + return GatewayUtils.errorResponse(exchange,"token过期"); + } + + redisCache.expire(TokenConstants.LOGIN_TOKEN_KEY+userKey,30, TimeUnit.MINUTES); + +// String userId = JwtUtils.getUserId(claims); +// GatewayUtils.addHander(mutate, JwtConstants.USER_KEY,userKey); +// GatewayUtils.addHander(mutate,JwtConstants.DETAILS_USER_ID,userId); +// GatewayUtils.removeHeader(mutate,TokenConstants.TOKEN); + + return chain.filter(exchange); + } + + @Override + public int getOrder() { + return 0; + } +} diff --git a/bwie-gateway/src/main/java/com/bwie/gateway/utils/GatewayUtils.java b/bwie-gateway/src/main/java/com/bwie/gateway/utils/GatewayUtils.java new file mode 100644 index 0000000..cc033bf --- /dev/null +++ b/bwie-gateway/src/main/java/com/bwie/gateway/utils/GatewayUtils.java @@ -0,0 +1,67 @@ +package com.bwie.gateway.utils; + +import com.alibaba.fastjson.JSONObject; +import com.bwie.common.result.Result; +import com.bwie.common.utils.StringUtils; +import lombok.extern.log4j.Log4j2; +import org.springframework.core.io.buffer.DataBuffer; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.server.reactive.ServerHttpRequest; +import org.springframework.http.server.reactive.ServerHttpResponse; +import org.springframework.web.server.ServerWebExchange; +import reactor.core.publisher.Mono; + +@Log4j2 +public class GatewayUtils { + public static void addHander(ServerHttpRequest.Builder mutate,String key,Object value) { + if(StringUtils.isEmpty(key)){ + log.warn("添加请求头参数键不可以为空"); + return; + } + if(value==null){ + log.warn("添加请求头参数:[{}]值为空",key); + return; + } + String string = value.toString(); + mutate.header(key,string); + log.info("添加请求头参数成功 - 键:{[]},值:{[]}",key,value); + } + + public static void removeHeader(ServerHttpRequest.Builder mutate, String key) { + if (StringUtils.isEmpty(key)){ + log.warn("删除请求头参数键不可以为空"); + return; + } + mutate.headers(httpHeaders -> httpHeaders.remove(key)).build(); + log.info("删除请求头参数 - 键:[{}]",key); + } + + public static Mono errorResponse(ServerWebExchange exchange,String msg){ + ServerHttpResponse response = exchange.getResponse(); + response.setStatusCode(HttpStatus.OK); + response.getHeaders().add(HttpHeaders.CONTENT_TYPE,"application/json"); + Result error = Result.error(msg); + String jsonString = JSONObject.toJSONString(error); + log.error("[鉴权异常处理]请求路径:[{}],异常信息:[{}],响应结果:[{}]", + exchange.getRequest().getPath(),msg,jsonString); + DataBuffer wrap = response.bufferFactory().wrap(jsonString.getBytes()); + return response.writeWith(Mono.just(wrap)); + + + } + + + + + + + + + + + + + + +} diff --git a/bwie-gateway/src/main/resources/bootstrap.yml b/bwie-gateway/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..231e2a0 --- /dev/null +++ b/bwie-gateway/src/main/resources/bootstrap.yml @@ -0,0 +1,29 @@ +# Tomcat +server: + port: 18080 +# Spring +spring: + application: + # 应用名称 + name: bwie-gateway + profiles: + # 环境配置 + active: dev + main: + # 允许使用循环引用 + allow-circular-references: true + # 允许定义相同的bean对象 去覆盖原有的 + allow-bean-definition-overriding: true + cloud: + nacos: + discovery: + # 服务注册地址 + server-addr: 124.221.177.197:8848 + config: + # 配置中心地址 + server-addr: 124.221.177.197:8848 + # 配置文件格式 + file-extension: yml + # 共享配置 + shared-configs: + - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} diff --git a/bwie-modules/bwie-car/pom.xml b/bwie-modules/bwie-car/pom.xml new file mode 100644 index 0000000..32af86a --- /dev/null +++ b/bwie-modules/bwie-car/pom.xml @@ -0,0 +1,63 @@ + + + 4.0.0 + + com.bwie + test_week1 + 1.0.0 + ../../pom.xml + + + bwie-car + + + 17 + 17 + UTF-8 + + + + + com.bwie + bwie-common + + + + org.springframework.boot + spring-boot-starter-web + + + + + com.alibaba + druid-spring-boot-starter + 1.2.8 + + + + mysql + mysql-connector-java + + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 2.2.2 + + + + + com.github.pagehelper + pagehelper-spring-boot-starter + 1.4.1 + + + + org.springframework.boot + spring-boot-starter-test + test + + + diff --git a/bwie-modules/bwie-car/src/main/java/com/bwie/car/CarApp.java b/bwie-modules/bwie-car/src/main/java/com/bwie/car/CarApp.java new file mode 100644 index 0000000..a4db90a --- /dev/null +++ b/bwie-modules/bwie-car/src/main/java/com/bwie/car/CarApp.java @@ -0,0 +1,15 @@ +package com.bwie.car; + +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; + +@SpringBootApplication +@EnableDiscoveryClient +@MapperScan("com.bwie.car.mapper") +public class CarApp { + public static void main(String[] args) { + SpringApplication.run(CarApp.class); + } +} diff --git a/bwie-modules/bwie-car/src/main/java/com/bwie/car/controller/CarController.java b/bwie-modules/bwie-car/src/main/java/com/bwie/car/controller/CarController.java new file mode 100644 index 0000000..19d7e46 --- /dev/null +++ b/bwie-modules/bwie-car/src/main/java/com/bwie/car/controller/CarController.java @@ -0,0 +1,74 @@ +package com.bwie.car.controller; + +import com.bwie.car.mapper.CarMapper; +import com.bwie.car.service.CarService; +import com.bwie.common.constant.TokenConstants; +import com.bwie.common.domain.Car; +import com.bwie.common.domain.Ord; +import com.bwie.common.domain.User; +import com.bwie.common.domain.response.CarShow; +import com.bwie.common.redis.RedisCache; +import com.bwie.common.result.Result; +import com.bwie.common.utils.JwtUtils; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import java.util.List; + +@RestController +@ResponseBody +public class CarController { + private final CarService carService; + private final RedisCache redisCache; + private final CarMapper carMapper; + private final HttpServletRequest request; + + public CarController(CarService carService, RedisCache redisCache, CarMapper carMapper, HttpServletRequest request) { + this.carService = carService; + this.redisCache = redisCache; + this.carMapper = carMapper; + this.request = request; + } + + @PostMapping("addcar") + public Result addcar(@RequestParam Long goodsId){ + Car findgoods = carService.findgoods(goodsId, info().getUserId()); + if(findgoods==null){ + Car build = Car.builder() + .userId(info().getUserId()) + .goodsId(goodsId) + .goodsNum(1) + .build(); + carService.save(build); + }else { + findgoods.setGoodsNum(findgoods.getGoodsNum()+1); + carMapper.updateById(findgoods); + } + return Result.success(); + } + + @GetMapping("show") + public Result show(){ + List show = carService.show(); + return Result.success(show); + } + + @PostMapping("delcar") + public Result delcar(@RequestParam Long carId){ + carService.delcar(carId); + return Result.success(); + } + + public User info() { + String header = request.getHeader(TokenConstants.TOKEN); + String userKey = JwtUtils.getUserKey(header); + User cacheObject = redisCache.getCacheObject(TokenConstants.LOGIN_TOKEN_KEY + userKey); + return cacheObject; + } + + @GetMapping("showord") + public Result showord(){ + List show = carService.showord(); + return Result.success(show); + } +} diff --git a/bwie-modules/bwie-car/src/main/java/com/bwie/car/mapper/CarMapper.java b/bwie-modules/bwie-car/src/main/java/com/bwie/car/mapper/CarMapper.java new file mode 100644 index 0000000..17871e0 --- /dev/null +++ b/bwie-modules/bwie-car/src/main/java/com/bwie/car/mapper/CarMapper.java @@ -0,0 +1,18 @@ +package com.bwie.car.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.bwie.car.CarApp; +import com.bwie.common.domain.Car; +import com.bwie.common.domain.Ord; +import com.bwie.common.domain.response.CarShow; + +import java.util.List; + +public interface CarMapper extends BaseMapper { + + List show(Long userId); + + List showord(Long userId); + + +} diff --git a/bwie-modules/bwie-car/src/main/java/com/bwie/car/service/CarService.java b/bwie-modules/bwie-car/src/main/java/com/bwie/car/service/CarService.java new file mode 100644 index 0000000..91f4f7f --- /dev/null +++ b/bwie-modules/bwie-car/src/main/java/com/bwie/car/service/CarService.java @@ -0,0 +1,18 @@ +package com.bwie.car.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.bwie.common.domain.Car; +import com.bwie.common.domain.Goods; +import com.bwie.common.domain.Ord; +import com.bwie.common.domain.response.CarShow; + +import java.util.List; + +public interface CarService extends IService { + + Car findgoods(Long goodsId, Long userId); + + List show(); + void delcar(Long carId); + List showord(); +} diff --git a/bwie-modules/bwie-car/src/main/java/com/bwie/car/service/CarServiceImpl.java b/bwie-modules/bwie-car/src/main/java/com/bwie/car/service/CarServiceImpl.java new file mode 100644 index 0000000..aeb21c6 --- /dev/null +++ b/bwie-modules/bwie-car/src/main/java/com/bwie/car/service/CarServiceImpl.java @@ -0,0 +1,62 @@ +package com.bwie.car.service; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.bwie.car.mapper.CarMapper; +import com.bwie.common.constant.TokenConstants; +import com.bwie.common.domain.Car; +import com.bwie.common.domain.Ord; +import com.bwie.common.domain.User; +import com.bwie.common.domain.response.CarShow; +import com.bwie.common.redis.RedisCache; +import com.bwie.common.utils.JwtUtils; +import org.springframework.stereotype.Service; + +import javax.servlet.http.HttpServletRequest; +import java.util.List; + +@Service +public class CarServiceImpl extends ServiceImpl implements CarService { + + private final RedisCache redisCache; + private final CarMapper carMapper; + private final HttpServletRequest request; + + public CarServiceImpl(RedisCache redisCache, CarMapper carMapper, HttpServletRequest request) { + this.redisCache = redisCache; + this.carMapper = carMapper; + this.request = request; + } + + @Override + public Car findgoods(Long goodsId, Long userId) { + LambdaQueryWrapper carLambdaQueryWrapper = new LambdaQueryWrapper<>(); + carLambdaQueryWrapper.eq(Car::getGoodsId, goodsId); + carLambdaQueryWrapper.eq(Car::getUserId,userId); + Car car = carMapper.selectOne(carLambdaQueryWrapper); + return car; + } + + @Override + public List show() { + List show = carMapper.show(info().getUserId()); + return show; + } + + @Override + public void delcar(Long carId) { + carMapper.deleteById(carId); + } + + @Override + public List showord() { + return carMapper.showord(info().getUserId()); + } + + public User info() { + String header = request.getHeader(TokenConstants.TOKEN); + String userKey = JwtUtils.getUserKey(header); + User cacheObject = redisCache.getCacheObject(TokenConstants.LOGIN_TOKEN_KEY + userKey); + return cacheObject; + } +} diff --git a/bwie-modules/bwie-car/src/main/resources/bootstrap.yml b/bwie-modules/bwie-car/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..476f800 --- /dev/null +++ b/bwie-modules/bwie-car/src/main/resources/bootstrap.yml @@ -0,0 +1,30 @@ +# Tomcat +server: + port: 9003 +# Spring +spring: + main: + allow-circular-references: true + allow-bean-definition-overriding: true + jackson: + date-format: yyyy-MM-dd HH:mm:ss + time-zone: GMT+8 + application: + # 应用名称 + name: bwie-car + profiles: + # 环境配置 + active: dev + cloud: + nacos: + discovery: + # 服务注册地址 + server-addr: 124.221.177.197:8848 + config: + # 配置中心地址 + server-addr: 124.221.177.197:8848 + # 配置文件格式 + file-extension: yml + # 共享配置 + shared-configs: + - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} diff --git a/bwie-modules/bwie-car/src/main/resources/mapper/CarMapper.xml b/bwie-modules/bwie-car/src/main/resources/mapper/CarMapper.xml new file mode 100644 index 0000000..ddf7ac9 --- /dev/null +++ b/bwie-modules/bwie-car/src/main/resources/mapper/CarMapper.xml @@ -0,0 +1,18 @@ + + + + + + + diff --git a/bwie-modules/bwie-es/pom.xml b/bwie-modules/bwie-es/pom.xml new file mode 100644 index 0000000..b47eb6b --- /dev/null +++ b/bwie-modules/bwie-es/pom.xml @@ -0,0 +1,69 @@ + + + 4.0.0 + + com.bwie + test_week1 + 1.0.0 + ../../pom.xml + + + + bwie-es + + + 17 + 17 + UTF-8 + 7.17.0 + + + + + com.bwie + bwie-common + + + org.springframework.boot + spring-boot-starter-web + + + org.elasticsearch.client + elasticsearch-rest-high-level-client + 7.17.0 + + + + + + com.alibaba + druid-spring-boot-starter + 1.2.8 + + + + mysql + mysql-connector-java + + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 2.2.2 + + + + com.github.pagehelper + pagehelper-spring-boot-starter + 1.4.1 + + + + org.springframework.boot + spring-boot-starter-test + test + + + diff --git a/bwie-modules/bwie-es/src/main/java/com/bwie/es/EsApp.java b/bwie-modules/bwie-es/src/main/java/com/bwie/es/EsApp.java new file mode 100644 index 0000000..27a2602 --- /dev/null +++ b/bwie-modules/bwie-es/src/main/java/com/bwie/es/EsApp.java @@ -0,0 +1,34 @@ +package com.bwie.es; + +import com.bwie.common.domain.Goods; +import com.bwie.es.service.EsService; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.scheduling.annotation.EnableScheduling; + +import javax.annotation.PostConstruct; +import java.util.List; + +@SpringBootApplication +@EnableDiscoveryClient +@MapperScan("com.bwie.es.mapper") +@EnableScheduling +public class EsApp { + private final EsService esService; + + public EsApp(EsService esService) { + this.esService = esService; + } + + public static void main(String[] args) { + SpringApplication.run(EsApp.class); + } + + @PostConstruct + public void Sync(){ + List findall = esService.findall(); + esService.BatchAdd(findall); + } +} diff --git a/bwie-modules/bwie-es/src/main/java/com/bwie/es/config/InitEsRes.java b/bwie-modules/bwie-es/src/main/java/com/bwie/es/config/InitEsRes.java new file mode 100644 index 0000000..c94caa7 --- /dev/null +++ b/bwie-modules/bwie-es/src/main/java/com/bwie/es/config/InitEsRes.java @@ -0,0 +1,25 @@ +package com.bwie.es.config; + +import lombok.Data; +import org.apache.http.HttpHost; +import org.elasticsearch.client.RestClient; +import org.elasticsearch.client.RestHighLevelClient; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +@ConfigurationProperties(prefix = "es") +@Data +public class InitEsRes { + private String host; + private int port; + private String scheme; + + @Bean + public RestHighLevelClient restHighLevelClient(){ + return new RestHighLevelClient( + RestClient.builder(new HttpHost(host,port,scheme)) + ); + } +} diff --git a/bwie-modules/bwie-es/src/main/java/com/bwie/es/controller/EsController.java b/bwie-modules/bwie-es/src/main/java/com/bwie/es/controller/EsController.java new file mode 100644 index 0000000..b0449a1 --- /dev/null +++ b/bwie-modules/bwie-es/src/main/java/com/bwie/es/controller/EsController.java @@ -0,0 +1,44 @@ +package com.bwie.es.controller; + +import cn.hutool.core.util.RandomUtil; +import com.bwie.common.domain.Goods; +import com.bwie.common.domain.request.GoodsReq; +import com.bwie.common.result.Result; +import com.bwie.es.service.EsService; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.PostConstruct; +import java.util.ArrayList; +import java.util.List; + +@RestController +@ResponseBody +public class EsController { + private final EsService esService; + + public EsController(EsService esService) { + this.esService = esService; + } + + + @PostMapping("addgoods") + public Result addgoods(@RequestBody Goods gg){ + String s = RandomUtil.randomNumbers(7); + gg.setGoodsHao(s); + gg.setGoodsSync(2); + esService.save(gg); + ArrayList goods = new ArrayList<>(); + goods.add(gg); + esService.BatchAdd(goods); + return Result.success(); + } + + @PostMapping("show") + public Result show(@RequestBody GoodsReq req){ + List show = esService.show(req); + return Result.success(show); + } +} diff --git a/bwie-modules/bwie-es/src/main/java/com/bwie/es/mapper/EsMapper.java b/bwie-modules/bwie-es/src/main/java/com/bwie/es/mapper/EsMapper.java new file mode 100644 index 0000000..fe8883e --- /dev/null +++ b/bwie-modules/bwie-es/src/main/java/com/bwie/es/mapper/EsMapper.java @@ -0,0 +1,7 @@ +package com.bwie.es.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.bwie.common.domain.Goods; + +public interface EsMapper extends BaseMapper { +} diff --git a/bwie-modules/bwie-es/src/main/java/com/bwie/es/service/EsService.java b/bwie-modules/bwie-es/src/main/java/com/bwie/es/service/EsService.java new file mode 100644 index 0000000..ed1aef5 --- /dev/null +++ b/bwie-modules/bwie-es/src/main/java/com/bwie/es/service/EsService.java @@ -0,0 +1,13 @@ +package com.bwie.es.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.bwie.common.domain.Goods; +import com.bwie.common.domain.request.GoodsReq; + +import java.util.List; + +public interface EsService extends IService { + List findall(); + void BatchAdd(List gg); + List show(GoodsReq goodsReq); +} diff --git a/bwie-modules/bwie-es/src/main/java/com/bwie/es/service/impl/EsServiceImpl.java b/bwie-modules/bwie-es/src/main/java/com/bwie/es/service/impl/EsServiceImpl.java new file mode 100644 index 0000000..8e8fd44 --- /dev/null +++ b/bwie-modules/bwie-es/src/main/java/com/bwie/es/service/impl/EsServiceImpl.java @@ -0,0 +1,128 @@ +package com.bwie.es.service.impl; + +import cn.hutool.core.util.RandomUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.nacos.common.utils.RandomUtils; +import com.alibaba.nacos.common.utils.UuidUtils; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Assert; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.bwie.common.domain.Goods; +import com.bwie.common.domain.request.GoodsReq; +import com.bwie.es.mapper.EsMapper; +import com.bwie.es.service.EsService; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.elasticsearch.action.bulk.BulkRequest; +import org.elasticsearch.action.bulk.BulkResponse; +import org.elasticsearch.action.index.IndexRequest; +import org.elasticsearch.action.search.SearchRequest; +import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.client.RequestOptions; +import org.elasticsearch.client.RestHighLevelClient; +import org.elasticsearch.common.text.Text; +import org.elasticsearch.common.unit.Fuzziness; + +import org.elasticsearch.index.query.BoolQueryBuilder; +import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.search.SearchHit; +import org.elasticsearch.search.builder.SearchSourceBuilder; +import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder; +import org.elasticsearch.search.fetch.subphase.highlight.HighlightField; +import org.elasticsearch.xcontent.XContentType; +import org.springframework.stereotype.Service; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +@Service +public class EsServiceImpl extends ServiceImpl implements EsService { + private final EsMapper esMapper; + private final RestHighLevelClient client; + + public EsServiceImpl(EsMapper esMapper, RestHighLevelClient client) { + this.esMapper = esMapper; + this.client = client; + } + + @Override + public List findall() { + LambdaQueryWrapper goodsLambdaQueryWrapper = new LambdaQueryWrapper<>(); + List goods = esMapper.selectList(goodsLambdaQueryWrapper); + return goods; + } + + @Override + public void BatchAdd(List gg) { + BulkRequest bulkRequest = new BulkRequest(); + for (Goods goods : gg) { + bulkRequest.add(new IndexRequest("goods").id(goods.getGoodsId().toString()) + .source(JSON.toJSONString(goods), XContentType.JSON)); + } + try { + BulkResponse bulk = client.bulk(bulkRequest, RequestOptions.DEFAULT); + Assert.isTrue(!bulk.hasFailures(),"同步失败"); + for (Goods goods : gg) { + goods.setGoodsSync(1); + esMapper.updateById(goods); + } + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Override + public List show(GoodsReq goodsReq) { + SearchRequest searchRequest = new SearchRequest("goods"); + SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); + BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder(); + + if(goodsReq.getGoodsName()!=null&&!goodsReq.getGoodsName().equals("")){ + boolQueryBuilder.must(QueryBuilders.matchQuery("goodsName",goodsReq.getGoodsName()).fuzziness(Fuzziness.AUTO)); + } + if(goodsReq.getGoodsBrand()!=null&&!goodsReq.getGoodsBrand().equals("")){ + boolQueryBuilder.must(QueryBuilders.matchQuery("goodsBrand",goodsReq.getGoodsBrand()).fuzziness(Fuzziness.AUTO)); + } + searchSourceBuilder.query(boolQueryBuilder); + + + HighlightBuilder highlightBuilder = new HighlightBuilder(); + highlightBuilder.field("goodsName"); + highlightBuilder.preTags(""); + highlightBuilder.postTags(""); + searchSourceBuilder.highlighter(highlightBuilder); + searchRequest.source(searchSourceBuilder); + + ArrayList goods = new ArrayList<>(); + try { + SearchResponse search = client.search(searchRequest, RequestOptions.DEFAULT); + for (SearchHit hit : search.getHits()) { + Map highlightFields = hit.getHighlightFields(); + HighlightField name = highlightFields.get("goodsName"); + StringBuffer stringBuffer = new StringBuffer(); + if(name!=null){ + Text[] fragments = name.getFragments(); + for (Text fragment : fragments) { + stringBuffer.append(fragment.toString()); + } + } + + String sourceAsString = hit.getSourceAsString(); + Goods goods1 = JSON.parseObject(sourceAsString, Goods.class); + if(name!=null){ + goods1.setGoodsName(stringBuffer.toString()); + } + goods.add(goods1); + } + + + } catch (IOException e) { + throw new RuntimeException(e); + } + return goods; + + } + + +} diff --git a/bwie-modules/bwie-es/src/main/java/com/bwie/es/sync/MyTask.java b/bwie-modules/bwie-es/src/main/java/com/bwie/es/sync/MyTask.java new file mode 100644 index 0000000..495a10b --- /dev/null +++ b/bwie-modules/bwie-es/src/main/java/com/bwie/es/sync/MyTask.java @@ -0,0 +1,31 @@ +package com.bwie.es.sync; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.bwie.common.domain.Goods; +import com.bwie.es.mapper.EsMapper; +import com.bwie.es.service.EsService; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Component +public class MyTask { + private final EsMapper esMapper; + private final EsService esService; + + public MyTask(EsMapper esMapper, EsService esService) { + this.esMapper = esMapper; + this.esService = esService; + } + + @Scheduled(cron = "0/30 * * * * *") + public void checkSync(){ + LambdaQueryWrapper goodsLambdaQueryWrapper = new LambdaQueryWrapper<>(); + goodsLambdaQueryWrapper.eq(Goods::getGoodsSync,2); + List goods = esMapper.selectList(goodsLambdaQueryWrapper); + if(goods.size()>0){ + esService.BatchAdd(goods); + } + } +} diff --git a/bwie-modules/bwie-es/src/main/resources/bootstrap.yml b/bwie-modules/bwie-es/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..bc86b38 --- /dev/null +++ b/bwie-modules/bwie-es/src/main/resources/bootstrap.yml @@ -0,0 +1,40 @@ +es: + host: 124.221.177.197 + port: 9200 + scheme: http + +# Tomcat +server: + port: 9005 +# Spring +spring: + main: + allow-circular-references: true + allow-bean-definition-overriding: true + jackson: + date-format: yyyy-MM-dd HH:mm:ss + time-zone: GMT+8 + application: + # 应用名称 + name: bwie-es + profiles: + # 环境配置 + active: dev + cloud: + nacos: + discovery: + # 服务注册地址 + server-addr: 124.221.177.197:8848 + config: + # 配置中心地址 + server-addr: 124.221.177.197:8848 + # 配置文件格式 + file-extension: yml + # 共享配置 + shared-configs: + - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} + +# 将mapper接口所在包的日志级别改成debug,可以在控制台打印es +logging: + level: + org.apache.http: trace diff --git a/bwie-modules/bwie-es/src/main/resources/mapper/EsMapper.xml b/bwie-modules/bwie-es/src/main/resources/mapper/EsMapper.xml new file mode 100644 index 0000000..dd8764c --- /dev/null +++ b/bwie-modules/bwie-es/src/main/resources/mapper/EsMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/bwie-modules/bwie-ord/pom.xml b/bwie-modules/bwie-ord/pom.xml new file mode 100644 index 0000000..85c7949 --- /dev/null +++ b/bwie-modules/bwie-ord/pom.xml @@ -0,0 +1,63 @@ + + + 4.0.0 + + com.bwie + test_week1 + 1.0.0 + ../../pom.xml + + + bwie-ord + + + 17 + 17 + UTF-8 + + + + + com.bwie + bwie-common + + + + org.springframework.boot + spring-boot-starter-web + + + + + com.alibaba + druid-spring-boot-starter + 1.2.8 + + + + mysql + mysql-connector-java + + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 2.2.2 + + + + + com.github.pagehelper + pagehelper-spring-boot-starter + 1.4.1 + + + + org.springframework.boot + spring-boot-starter-test + test + + + diff --git a/bwie-modules/bwie-ord/src/main/java/com/bwie/ord/controller/OrdController.java b/bwie-modules/bwie-ord/src/main/java/com/bwie/ord/controller/OrdController.java new file mode 100644 index 0000000..ac23131 --- /dev/null +++ b/bwie-modules/bwie-ord/src/main/java/com/bwie/ord/controller/OrdController.java @@ -0,0 +1,4 @@ +package com.bwie.ord.controller; + +public class OrdController { +} diff --git a/bwie-modules/bwie-ord/src/main/java/com/bwie/ord/mapper/OrdMapper.java b/bwie-modules/bwie-ord/src/main/java/com/bwie/ord/mapper/OrdMapper.java new file mode 100644 index 0000000..5f12053 --- /dev/null +++ b/bwie-modules/bwie-ord/src/main/java/com/bwie/ord/mapper/OrdMapper.java @@ -0,0 +1,4 @@ +package com.bwie.ord.mapper; + +public interface OrdMapper { +} diff --git a/bwie-modules/bwie-ord/src/main/java/com/bwie/ord/service/OrdService.java b/bwie-modules/bwie-ord/src/main/java/com/bwie/ord/service/OrdService.java new file mode 100644 index 0000000..edd6c3e --- /dev/null +++ b/bwie-modules/bwie-ord/src/main/java/com/bwie/ord/service/OrdService.java @@ -0,0 +1,4 @@ +package com.bwie.ord.service; + +public interface OrdService { +} diff --git a/bwie-modules/bwie-ord/src/main/java/com/bwie/ord/service/OrdServiceImpl.java b/bwie-modules/bwie-ord/src/main/java/com/bwie/ord/service/OrdServiceImpl.java new file mode 100644 index 0000000..9e1d6cc --- /dev/null +++ b/bwie-modules/bwie-ord/src/main/java/com/bwie/ord/service/OrdServiceImpl.java @@ -0,0 +1,4 @@ +package com.bwie.ord.service; + +public class OrdServiceImpl { +} diff --git a/bwie-modules/bwie-ord/src/main/resources/bootstrap.yml b/bwie-modules/bwie-ord/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..507da86 --- /dev/null +++ b/bwie-modules/bwie-ord/src/main/resources/bootstrap.yml @@ -0,0 +1,30 @@ +# Tomcat +server: + port: 9004 +# Spring +spring: + main: + allow-circular-references: true + allow-bean-definition-overriding: true + jackson: + date-format: yyyy-MM-dd HH:mm:ss + time-zone: GMT+8 + application: + # 应用名称 + name: bwie-ord + profiles: + # 环境配置 + active: dev + cloud: + nacos: + discovery: + # 服务注册地址 + server-addr: 124.221.177.197:8848 + config: + # 配置中心地址 + server-addr: 124.221.177.197:8848 + # 配置文件格式 + file-extension: yml + # 共享配置 + shared-configs: + - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} diff --git a/bwie-modules/bwie-system/pom.xml b/bwie-modules/bwie-system/pom.xml new file mode 100644 index 0000000..4ce8b7a --- /dev/null +++ b/bwie-modules/bwie-system/pom.xml @@ -0,0 +1,64 @@ + + + 4.0.0 + + com.bwie + test_week1 + 1.0.0 + ../../pom.xml + + + bwie-system + + + 17 + 17 + UTF-8 + + + + + + com.bwie + bwie-common + + + + org.springframework.boot + spring-boot-starter-web + + + + + com.alibaba + druid-spring-boot-starter + 1.2.8 + + + + mysql + mysql-connector-java + + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 2.2.2 + + + + + com.github.pagehelper + pagehelper-spring-boot-starter + 1.4.1 + + + + org.springframework.boot + spring-boot-starter-test + test + + + diff --git a/bwie-modules/bwie-system/src/main/java/com/bwie/system/SysApp.java b/bwie-modules/bwie-system/src/main/java/com/bwie/system/SysApp.java new file mode 100644 index 0000000..8c3a57f --- /dev/null +++ b/bwie-modules/bwie-system/src/main/java/com/bwie/system/SysApp.java @@ -0,0 +1,15 @@ +package com.bwie.system; + +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; + +@SpringBootApplication +@EnableDiscoveryClient +@MapperScan("com.bwie.system.mapper") +public class SysApp { + public static void main(String[] args) { + SpringApplication.run(SysApp.class); + } +} diff --git a/bwie-modules/bwie-system/src/main/java/com/bwie/system/controller/SysController.java b/bwie-modules/bwie-system/src/main/java/com/bwie/system/controller/SysController.java new file mode 100644 index 0000000..2e77e6a --- /dev/null +++ b/bwie-modules/bwie-system/src/main/java/com/bwie/system/controller/SysController.java @@ -0,0 +1,25 @@ +package com.bwie.system.controller; + +import com.bwie.common.domain.User; +import com.bwie.common.result.Result; +import com.bwie.system.service.SysService; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@ResponseBody +public class SysController { + private final SysService service; + + public SysController(SysService service) { + this.service = service; + } + + @PostMapping("findtel") + public Result findtel(@RequestParam String userTel){ + User findtel = service.findtel(userTel); + return Result.success(findtel); + } +} diff --git a/bwie-modules/bwie-system/src/main/java/com/bwie/system/mapper/SysMapper.java b/bwie-modules/bwie-system/src/main/java/com/bwie/system/mapper/SysMapper.java new file mode 100644 index 0000000..ab52245 --- /dev/null +++ b/bwie-modules/bwie-system/src/main/java/com/bwie/system/mapper/SysMapper.java @@ -0,0 +1,8 @@ +package com.bwie.system.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.bwie.common.domain.User; +import com.bwie.common.remote.user.UserRemoteService; + +public interface SysMapper extends BaseMapper { +} diff --git a/bwie-modules/bwie-system/src/main/java/com/bwie/system/service/SysService.java b/bwie-modules/bwie-system/src/main/java/com/bwie/system/service/SysService.java new file mode 100644 index 0000000..738b726 --- /dev/null +++ b/bwie-modules/bwie-system/src/main/java/com/bwie/system/service/SysService.java @@ -0,0 +1,9 @@ +package com.bwie.system.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.bwie.common.domain.User; +import com.bwie.common.remote.user.UserRemoteService; + +public interface SysService extends IService { + User findtel(String userTel); +} diff --git a/bwie-modules/bwie-system/src/main/java/com/bwie/system/service/SysServiceImpl.java b/bwie-modules/bwie-system/src/main/java/com/bwie/system/service/SysServiceImpl.java new file mode 100644 index 0000000..190a7c5 --- /dev/null +++ b/bwie-modules/bwie-system/src/main/java/com/bwie/system/service/SysServiceImpl.java @@ -0,0 +1,24 @@ +package com.bwie.system.service; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.bwie.common.domain.User; +import com.bwie.system.mapper.SysMapper; +import org.springframework.stereotype.Service; + +@Service +public class SysServiceImpl extends ServiceImpl implements SysService{ + private final SysMapper sysMapper; + + public SysServiceImpl(SysMapper sysMapper) { + this.sysMapper = sysMapper; + } + + @Override + public User findtel(String userTel) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(User::getUserTel,userTel); + User user = sysMapper.selectOne(queryWrapper); + return user; + } +} diff --git a/bwie-modules/bwie-system/src/main/resources/bootstrap.yml b/bwie-modules/bwie-system/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..51939cf --- /dev/null +++ b/bwie-modules/bwie-system/src/main/resources/bootstrap.yml @@ -0,0 +1,30 @@ +# Tomcat +server: + port: 9002 +# Spring +spring: + main: + allow-circular-references: true + allow-bean-definition-overriding: true + jackson: + date-format: yyyy-MM-dd HH:mm:ss + time-zone: GMT+8 + application: + # 应用名称 + name: bwie-system + profiles: + # 环境配置 + active: dev + cloud: + nacos: + discovery: + # 服务注册地址 + server-addr: 124.221.177.197:8848 + config: + # 配置中心地址 + server-addr: 124.221.177.197:8848 + # 配置文件格式 + file-extension: yml + # 共享配置 + shared-configs: + - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} diff --git a/bwie-modules/bwie-system/src/main/resources/mapper/SysMapper.xml b/bwie-modules/bwie-system/src/main/resources/mapper/SysMapper.xml new file mode 100644 index 0000000..d8da7bb --- /dev/null +++ b/bwie-modules/bwie-system/src/main/resources/mapper/SysMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/bwie-modules/pom.xml b/bwie-modules/pom.xml new file mode 100644 index 0000000..11f2c16 --- /dev/null +++ b/bwie-modules/pom.xml @@ -0,0 +1,20 @@ + + + 4.0.0 + + com.bwie + test_week1 + 1.0.0 + + + bwie-modules + + + 17 + 17 + UTF-8 + + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..d0baeda --- /dev/null +++ b/pom.xml @@ -0,0 +1,70 @@ + + + 4.0.0 + + com.bwie + test_week1 + 1.0.0 + pom + + bwie-common + bwie-auth + bwie-gateway + bwie-modules + bwie-modules/bwie-system + bwie-modules/bwie-es + bwie-modules/bwie-car + bwie-modules/bwie-ord + + + + 17 + 17 + UTF-8 + + + + + spring-boot-starter-parent + org.springframework.boot + 2.6.2 + + + + + + + + org.springframework.cloud + spring-cloud-dependencies + 2021.0.0 + pom + import + + + + com.alibaba.cloud + spring-cloud-alibaba-dependencies + 2021.1 + pom + import + + + + com.alibaba.nacos + nacos-client + 2.0.4 + + + + + com.bwie + bwie-common + 1.0.0 + + + + +