From 1deefc08464bcbaec7411192e399e47fd2b0403e Mon Sep 17 00:00:00 2001 From: jia <2744404105@qq.com> Date: Fri, 15 Dec 2023 19:44:58 +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 | 21 ++ .idea/inspectionProfiles/Project_Default.xml | 6 + .idea/misc.xml | 13 + .idea/uiDesigner.xml | 124 +++++++ .idea/vcs.xml | 6 + bwie-auth/pom.xml | 33 ++ .../src/main/java/com/bwie/auth/AuthApp.java | 13 + .../bwie/auth/controller/AuthController.java | 47 +++ .../java/com/bwie/auth/feign/AuthFeign.java | 12 + .../com/bwie/auth/service/AuthService.java | 8 + .../auth/service/impl/AuthServiceImpl.java | 60 ++++ bwie-auth/src/main/resources/bootstrap.yml | 31 ++ bwie-common/pom.xml | 102 ++++++ .../com/bwie/common/constants/Constants.java | 18 + .../bwie/common/constants/JwtConstants.java | 29 ++ .../common/constants/RabbitMQConstants.java | 11 + .../bwie/common/constants/TokenConstants.java | 24 ++ .../java/com/bwie/common/domain/Goods.java | 13 + .../main/java/com/bwie/common/domain/Opp.java | 10 + .../java/com/bwie/common/domain/SysUser.java | 11 + .../java/com/bwie/common/domain/Type.java | 9 + .../common/domain/request/GoodsRequest.java | 11 + .../common/domain/request/LoginRequest.java | 9 + .../common/domain/response/JwtResponse.java | 9 + .../com/bwie/common/result/PageResult.java | 34 ++ .../java/com/bwie/common/result/Result.java | 76 +++++ .../java/com/bwie/common/utils/JwtUtils.java | 109 ++++++ .../com/bwie/common/utils/StringUtils.java | 68 ++++ .../com/bwie/common/utils/TelSmsUtils.java | 89 +++++ bwie-gateway/pom.xml | 44 +++ .../java/com/bwie/gateway/GatewayApp.java | 11 + .../gateway/config/IgnoreWhiteConfig.java | 32 ++ .../com/bwie/gateway/filters/AuthFilter.java | 67 ++++ .../com/bwie/gateway/utils/GatewayUtils.java | 98 ++++++ bwie-gateway/src/main/resources/bootstrap.yml | 29 ++ bwie-modules/bwie-goods/pom.xml | 63 ++++ .../main/java/com/bwie/goods/GoodsApp.java | 13 + .../goods/controller/GoodsController.java | 46 +++ .../java/com/bwie/goods/feign/GoodsFeign.java | 12 + .../com/bwie/goods/mapper/GoodsMapper.java | 19 ++ .../com/bwie/goods/service/GoodsService.java | 12 + .../goods/service/impl/GoodsServiceImpl.java | 82 +++++ .../src/main/resources/bootstrap.yml | 30 ++ .../src/main/resources/mapper/GoodsMapper.xml | 26 ++ bwie-modules/bwie-mq/pom.xml | 68 ++++ .../bwie-mq/src/main/resources/bootstrap.yml | 30 ++ .../src/main/resources/mapper/MQMapper.xml | 10 + bwie-modules/bwie-opp/pom.xml | 91 +++++ .../src/main/java/com/bwie/opp/OppApp.java | 11 + .../bwie/opp/controller/OppController.java | 66 ++++ .../java/com/bwie/opp/mapper/OppMapper.java | 24 ++ .../java/com/bwie/opp/service/OppService.java | 16 + .../bwie/opp/service/impl/OppServiceImpl.java | 73 ++++ .../java/com/bwie/opp/util/HttpUtils.java | 319 ++++++++++++++++++ .../main/java/com/bwie/opp/util/MsgUtil.java | 80 +++++ .../bwie-opp/src/main/resources/bootstrap.yml | 30 ++ .../src/main/resources/mapper/OppMapper.xml | 24 ++ bwie-modules/bwie-system/pom.xml | 63 ++++ .../src/main/java/com/bwie/system/SysApp.java | 11 + .../bwie/system/controller/SysController.java | 35 ++ .../com/bwie/system/mapper/SysMapper.java | 10 + .../com/bwie/system/service/SysService.java | 9 + .../system/service/impl/SysServiceImpl.java | 22 ++ .../src/main/resources/bootstrap.yml | 30 ++ .../src/main/resources/mapper/SysMapper.xml | 10 + bwie-modules/pom.xml | 22 ++ pom.xml | 72 ++++ 69 files changed, 2762 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/encodings.xml create mode 100644 .idea/inspectionProfiles/Project_Default.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/feign/AuthFeign.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/constants/Constants.java create mode 100644 bwie-common/src/main/java/com/bwie/common/constants/JwtConstants.java create mode 100644 bwie-common/src/main/java/com/bwie/common/constants/RabbitMQConstants.java create mode 100644 bwie-common/src/main/java/com/bwie/common/constants/TokenConstants.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/Opp.java create mode 100644 bwie-common/src/main/java/com/bwie/common/domain/SysUser.java create mode 100644 bwie-common/src/main/java/com/bwie/common/domain/Type.java create mode 100644 bwie-common/src/main/java/com/bwie/common/domain/request/GoodsRequest.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/JwtResponse.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/JwtUtils.java create mode 100644 bwie-common/src/main/java/com/bwie/common/utils/StringUtils.java create mode 100644 bwie-common/src/main/java/com/bwie/common/utils/TelSmsUtils.java 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/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-goods/pom.xml create mode 100644 bwie-modules/bwie-goods/src/main/java/com/bwie/goods/GoodsApp.java create mode 100644 bwie-modules/bwie-goods/src/main/java/com/bwie/goods/controller/GoodsController.java create mode 100644 bwie-modules/bwie-goods/src/main/java/com/bwie/goods/feign/GoodsFeign.java create mode 100644 bwie-modules/bwie-goods/src/main/java/com/bwie/goods/mapper/GoodsMapper.java create mode 100644 bwie-modules/bwie-goods/src/main/java/com/bwie/goods/service/GoodsService.java create mode 100644 bwie-modules/bwie-goods/src/main/java/com/bwie/goods/service/impl/GoodsServiceImpl.java create mode 100644 bwie-modules/bwie-goods/src/main/resources/bootstrap.yml create mode 100644 bwie-modules/bwie-goods/src/main/resources/mapper/GoodsMapper.xml create mode 100644 bwie-modules/bwie-mq/pom.xml create mode 100644 bwie-modules/bwie-mq/src/main/resources/bootstrap.yml create mode 100644 bwie-modules/bwie-mq/src/main/resources/mapper/MQMapper.xml create mode 100644 bwie-modules/bwie-opp/pom.xml create mode 100644 bwie-modules/bwie-opp/src/main/java/com/bwie/opp/OppApp.java create mode 100644 bwie-modules/bwie-opp/src/main/java/com/bwie/opp/controller/OppController.java create mode 100644 bwie-modules/bwie-opp/src/main/java/com/bwie/opp/mapper/OppMapper.java create mode 100644 bwie-modules/bwie-opp/src/main/java/com/bwie/opp/service/OppService.java create mode 100644 bwie-modules/bwie-opp/src/main/java/com/bwie/opp/service/impl/OppServiceImpl.java create mode 100644 bwie-modules/bwie-opp/src/main/java/com/bwie/opp/util/HttpUtils.java create mode 100644 bwie-modules/bwie-opp/src/main/java/com/bwie/opp/util/MsgUtil.java create mode 100644 bwie-modules/bwie-opp/src/main/resources/bootstrap.yml create mode 100644 bwie-modules/bwie-opp/src/main/resources/mapper/OppMapper.xml 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/impl/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..fdaabdc --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..c32584c --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..6f5230a --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,13 @@ + + + + + + + + + \ 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..1daca0d --- /dev/null +++ b/bwie-auth/pom.xml @@ -0,0 +1,33 @@ + + + 4.0.0 + + com.bwie + test_week1 + 1.0-SNAPSHOT + + + bwie-auth + + + 8 + 8 + UTF-8 + + + + + + com.bwie + bwie-common + + + + org.springframework.boot + spring-boot-starter-web + + + + \ No newline at end of file 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..b1cac8b --- /dev/null +++ b/bwie-auth/src/main/java/com/bwie/auth/AuthApp.java @@ -0,0 +1,13 @@ +package com.bwie.auth; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.openfeign.EnableFeignClients; + +@SpringBootApplication +@EnableFeignClients +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..d2f71a8 --- /dev/null +++ b/bwie-auth/src/main/java/com/bwie/auth/controller/AuthController.java @@ -0,0 +1,47 @@ +package com.bwie.auth.controller; + +import com.alibaba.fastjson.JSONObject; +import com.alibaba.nacos.shaded.org.checkerframework.checker.units.qual.A; +import com.bwie.auth.service.AuthService; +import com.bwie.common.domain.request.LoginRequest; +import com.bwie.common.result.Result; +import lombok.Data; +import lombok.extern.log4j.Log4j2; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; + +@RestController +@Log4j2 +public class AuthController { + + @Autowired + private AuthService authService; + + @Autowired + private HttpServletRequest request; + + @PostMapping("login") + public Result login(@RequestBody LoginRequest loginRequest){ + log.info("功能名称:xxx,请求URI:{},请求方式:{},请求参数:{}", + request.getRequestURI(),request.getMethod(),JSONObject.toJSONString(loginRequest)); + Result result = authService.login(loginRequest); + log.info("功能名称:xxx,请求URI:{},请求方式:{},响应结果:{}", + request.getRequestURI(),request.getMethod(), JSONObject.toJSONString(result)); + return result; + } + + + + + + + + + + + +} diff --git a/bwie-auth/src/main/java/com/bwie/auth/feign/AuthFeign.java b/bwie-auth/src/main/java/com/bwie/auth/feign/AuthFeign.java new file mode 100644 index 0000000..e4d6691 --- /dev/null +++ b/bwie-auth/src/main/java/com/bwie/auth/feign/AuthFeign.java @@ -0,0 +1,12 @@ +package com.bwie.auth.feign; + +import com.bwie.common.domain.SysUser; +import com.bwie.common.result.Result; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestParam; +@FeignClient("bwie-system") +public interface AuthFeign { + @PostMapping("findphone") + public Result findphone(@RequestParam String userPhone); +} 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..ea0f9c7 --- /dev/null +++ b/bwie-auth/src/main/java/com/bwie/auth/service/AuthService.java @@ -0,0 +1,8 @@ +package com.bwie.auth.service; + +import com.bwie.common.domain.request.LoginRequest; +import com.bwie.common.result.Result; + +public interface AuthService { + Result login(LoginRequest loginRequest); +} 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..539f9dd --- /dev/null +++ b/bwie-auth/src/main/java/com/bwie/auth/service/impl/AuthServiceImpl.java @@ -0,0 +1,60 @@ +package com.bwie.auth.service.impl; + +import com.alibaba.fastjson.JSONObject; +import com.bwie.auth.feign.AuthFeign; +import com.bwie.auth.service.AuthService; +import com.bwie.common.constants.JwtConstants; +import com.bwie.common.constants.TokenConstants; +import com.bwie.common.domain.SysUser; +import com.bwie.common.domain.request.LoginRequest; +import com.bwie.common.domain.response.JwtResponse; +import com.bwie.common.result.Result; +import com.bwie.common.utils.JwtUtils; +import com.bwie.common.utils.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.stereotype.Service; + +import javax.servlet.http.HttpServletRequest; +import java.util.HashMap; +import java.util.UUID; +import java.util.concurrent.TimeUnit; + +@Service +public class AuthServiceImpl implements AuthService { + + @Autowired + private AuthFeign authFeign; + + @Autowired + private HttpServletRequest request; + + @Autowired + private StringRedisTemplate redisTemplate; + + @Override + public Result login(LoginRequest loginRequest) { + if(StringUtils.isAllBlank(loginRequest.getUserPhone(),loginRequest.getUserPwd())){ + return Result.error("不能为空"); + } + Result findphone = authFeign.findphone(loginRequest.getUserPhone()); + SysUser data = findphone.getData(); + if(null==data){ + return Result.error("手机号不存在"); + } + + if(!data.getUserPwd().equals(loginRequest.getUserPwd())){ + return Result.error("密码错误"); + } + String key = UUID.randomUUID().toString().replaceAll("-", ""); + HashMap map = new HashMap<>(); + map.put(JwtConstants.USER_KEY,key); + String token = JwtUtils.createToken(map); + redisTemplate.opsForValue().set(TokenConstants.LOGIN_TOKEN_KEY+key, JSONObject.toJSONString(data),15, TimeUnit.MINUTES); + JwtResponse jwtResponse = new JwtResponse(); + jwtResponse.setToken(token); + jwtResponse.setExpireTime("15MIN"); + + return Result.success(jwtResponse); + } +} 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..e0afe64 --- /dev/null +++ b/bwie-common/pom.xml @@ -0,0 +1,102 @@ + + + 4.0.0 + + com.bwie + test_week1 + 1.0-SNAPSHOT + + + bwie-common + + + 8 + 8 + 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 + + + + \ No newline at end of file diff --git a/bwie-common/src/main/java/com/bwie/common/constants/Constants.java b/bwie-common/src/main/java/com/bwie/common/constants/Constants.java new file mode 100644 index 0000000..2fdc9fe --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/constants/Constants.java @@ -0,0 +1,18 @@ +package com.bwie.common.constants; + +/** + * @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/constants/JwtConstants.java b/bwie-common/src/main/java/com/bwie/common/constants/JwtConstants.java new file mode 100644 index 0000000..03692c1 --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/constants/JwtConstants.java @@ -0,0 +1,29 @@ +package com.bwie.common.constants; + +/** + * @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/constants/RabbitMQConstants.java b/bwie-common/src/main/java/com/bwie/common/constants/RabbitMQConstants.java new file mode 100644 index 0000000..a99a980 --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/constants/RabbitMQConstants.java @@ -0,0 +1,11 @@ +package com.bwie.common.constants; + +/** + * @BelongsProject: Bob_Up_Like_A_Cork + * @BelongsPackage: com.bwie.common.constants + * @Author: zhangquan + * @CreateTime: 2023/8/1 20:11 + */ +public class RabbitMQConstants { + public static final String SEND_CODE="send_code"; +} diff --git a/bwie-common/src/main/java/com/bwie/common/constants/TokenConstants.java b/bwie-common/src/main/java/com/bwie/common/constants/TokenConstants.java new file mode 100644 index 0000000..1871fb7 --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/constants/TokenConstants.java @@ -0,0 +1,24 @@ +package com.bwie.common.constants; + +/** + * @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/Goods.java b/bwie-common/src/main/java/com/bwie/common/domain/Goods.java new file mode 100644 index 0000000..c0effc7 --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/domain/Goods.java @@ -0,0 +1,13 @@ +package com.bwie.common.domain; + +import lombok.Data; + +@Data +public class Goods { + private Integer goodsId; + private String goodsName; + private String goodsIntro; + private String goodsPrice; + private Integer typeId; + private String typeName; +} diff --git a/bwie-common/src/main/java/com/bwie/common/domain/Opp.java b/bwie-common/src/main/java/com/bwie/common/domain/Opp.java new file mode 100644 index 0000000..5f1c7f0 --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/domain/Opp.java @@ -0,0 +1,10 @@ +package com.bwie.common.domain; + +import lombok.Data; + +@Data +public class Opp { + private Integer oppId; + private Integer oppStatus; + private Integer userId; +} diff --git a/bwie-common/src/main/java/com/bwie/common/domain/SysUser.java b/bwie-common/src/main/java/com/bwie/common/domain/SysUser.java new file mode 100644 index 0000000..3ac5aba --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/domain/SysUser.java @@ -0,0 +1,11 @@ +package com.bwie.common.domain; + +import lombok.Data; + +@Data +public class SysUser { + private Integer userId; + private String userPhone; + private String userPwd; + private Integer userMoney; +} diff --git a/bwie-common/src/main/java/com/bwie/common/domain/Type.java b/bwie-common/src/main/java/com/bwie/common/domain/Type.java new file mode 100644 index 0000000..5ca5e0d --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/domain/Type.java @@ -0,0 +1,9 @@ +package com.bwie.common.domain; + +import lombok.Data; + +@Data +public class Type { + private Integer typeId; + private String typeName; +} diff --git a/bwie-common/src/main/java/com/bwie/common/domain/request/GoodsRequest.java b/bwie-common/src/main/java/com/bwie/common/domain/request/GoodsRequest.java new file mode 100644 index 0000000..f73b4e7 --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/domain/request/GoodsRequest.java @@ -0,0 +1,11 @@ +package com.bwie.common.domain.request; + +import lombok.Data; + +@Data +public class GoodsRequest { + private Integer pageNum=1; + private Integer pageSize=3; + private Integer typeId; + private String goodsName; +} 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..91c8379 --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/domain/request/LoginRequest.java @@ -0,0 +1,9 @@ +package com.bwie.common.domain.request; + +import lombok.Data; + +@Data +public class LoginRequest { + private String userPhone; + private String userPwd; +} 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..3c93121 --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/domain/response/JwtResponse.java @@ -0,0 +1,9 @@ +package com.bwie.common.domain.response; + +import lombok.Data; + +@Data +public class JwtResponse { + private String token; + private String expireTime; +} 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..30b1e73 --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/result/Result.java @@ -0,0 +1,76 @@ +package com.bwie.common.result; + +import com.bwie.common.constants.Constants; +import lombok.Data; + +import java.io.Serializable; + +/** + * @author DongZl + * @description: 响应信息主体 + */ +@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; + } +} 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..f560aa9 --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/utils/JwtUtils.java @@ -0,0 +1,109 @@ +package com.bwie.common.utils; + +import com.bwie.common.constants.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/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/java/com/bwie/common/utils/TelSmsUtils.java b/bwie-common/src/main/java/com/bwie/common/utils/TelSmsUtils.java new file mode 100644 index 0000000..b0a7322 --- /dev/null +++ b/bwie-common/src/main/java/com/bwie/common/utils/TelSmsUtils.java @@ -0,0 +1,89 @@ +package com.bwie.common.utils; + +import com.alibaba.fastjson.JSONObject; +import com.aliyun.dysmsapi20170525.Client; +import com.aliyun.dysmsapi20170525.models.SendSmsRequest; +import com.aliyun.dysmsapi20170525.models.SendSmsResponse; +import com.aliyun.teaopenapi.models.Config; +import lombok.extern.log4j.Log4j2; + +import java.util.Map; + +/** + * 短信工具类 + */ +@Log4j2 +public class TelSmsUtils { + + /** + * 阿里云主账号AccessKey,accessKeySecret拥有所有API的访问权限 + */ + private static String accessKeyId = "LTAI5tMRrNoxsBPgb6bYZWTW"; + private static String accessKeySecret = "r9LXZtt3ewEG2DHQ6DbAc65F0AFRA7"; + private static String templateCode = "SMS10001"; + /** + * 短信访问域名 + */ + private static String endpoint = "dysmsapi.aliyuncs.com"; + /** + * 短信签名 + */ + private static String signName = "登录验证"; + + /** + * 实例化短信对象 + */ + private static Client client; + + static { + log.info("初始化短信服务开始"); + long startTime = System.currentTimeMillis(); + try { + client = initClient(); + log.info("初始化短信成功:{}", signName); + } catch (Exception e) { + e.printStackTrace(); + } + log.info("初始化短信服务结束:耗时:{}MS", (System.currentTimeMillis() - startTime)); + } + + /** + * 初始化短信对象 + * + * @return + * @throws Exception + */ + private static Client initClient() throws Exception { + Config config = new Config() + // 您的AccessKey ID + .setAccessKeyId(accessKeyId) + // 您的AccessKey Secret + .setAccessKeySecret(accessKeySecret); + // 访问的域名 + config.endpoint = endpoint; + return new Client(config); + } + + /** + * 发送单条短信 + * + * @param tel + * @param sendDataMap + */ + public static String sendSms(String tel, Map sendDataMap) { + SendSmsRequest sendSmsRequest = new SendSmsRequest() + .setPhoneNumbers(tel) + .setSignName(signName) + .setTemplateCode(templateCode) + .setTemplateParam(JSONObject.toJSONString(sendDataMap)); + SendSmsResponse sendSmsResponse = null; + try { + log.info("发送短信验证码:消息内容是:【{}】", JSONObject.toJSONString(sendDataMap)); + sendSmsResponse = client.sendSms(sendSmsRequest); + } catch (Exception e) { + log.error("短信发送异常,手机号:【{}】,短信内容:【{}】,异常信息:【{}】", tel, sendDataMap, e); + } + return JSONObject.toJSONString(sendSmsResponse.getBody()); + } + +} diff --git a/bwie-gateway/pom.xml b/bwie-gateway/pom.xml new file mode 100644 index 0000000..6c36169 --- /dev/null +++ b/bwie-gateway/pom.xml @@ -0,0 +1,44 @@ + + + 4.0.0 + + com.bwie + test_week1 + 1.0-SNAPSHOT + + + bwie-gateway + + + 8 + 8 + 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 + + + + \ No newline at end of file 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..962bc29 --- /dev/null +++ b/bwie-gateway/src/main/java/com/bwie/gateway/GatewayApp.java @@ -0,0 +1,11 @@ +package com.bwie.gateway; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +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/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..6f1be22 --- /dev/null +++ b/bwie-gateway/src/main/java/com/bwie/gateway/filters/AuthFilter.java @@ -0,0 +1,67 @@ +package com.bwie.gateway.filters; + +import com.alibaba.fastjson.JSONObject; +import com.bwie.common.constants.TokenConstants; +import com.bwie.common.domain.SysUser; +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 org.springframework.beans.factory.annotation.Autowired; +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.data.redis.core.StringRedisTemplate; +import org.springframework.http.HttpStatus; +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 { + @Autowired + private StringRedisTemplate redisTemplate; + + @Autowired + private IgnoreWhiteConfig ignoreWhiteConfig; + + @Override + public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { + List whites = ignoreWhiteConfig.getWhites(); + String path = exchange.getRequest().getURI().getPath(); + System.out.println("path >>>>>>>>>>>>>>> = " + path); + if(StringUtils.matches(path,whites)){ + return chain.filter(exchange); + } + + String first = exchange.getRequest().getHeaders().getFirst(TokenConstants.TOKEN); + if(null==first){ + return GatewayUtils.errorResponse(exchange,"token不为空", HttpStatus.UNAUTHORIZED); + } + try { + JwtUtils.parseToken(first); + } catch (Exception e) { + return GatewayUtils.errorResponse(exchange,"token格式错误"); + } + + String userKey = JwtUtils.getUserKey(first); + if(!redisTemplate.hasKey(TokenConstants.LOGIN_TOKEN_KEY+userKey)){ + return GatewayUtils.errorResponse(exchange,"token过期"); + } + String s = redisTemplate.opsForValue().get(TokenConstants.LOGIN_TOKEN_KEY + userKey); + SysUser sysUser = JSONObject.parseObject(s, SysUser.class); + redisTemplate.opsForValue().set("present:",sysUser.getUserId()+""); + redisTemplate.expire(TokenConstants.LOGIN_TOKEN_KEY+userKey,15, TimeUnit.MINUTES); + + 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..7b789e5 --- /dev/null +++ b/bwie-gateway/src/main/java/com/bwie/gateway/utils/GatewayUtils.java @@ -0,0 +1,98 @@ +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; + +/** + * @author DongZl + * @description: 网关处理工具类 + */ +@Log4j2 +public class GatewayUtils { + /** + * 添加请求头参数 + * @param mutate 修改对象 + * @param key 键 + * @param value 值 + */ + public static void addHeader(ServerHttpRequest.Builder mutate, String key, Object value) { + if (StringUtils.isEmpty(key)){ + log.warn("添加请求头参数键不可以为空"); + return; + } + if (value == null) { + log.warn("添加请求头参数:[{}]值为空",key); + return; + } + String valueStr = value.toString(); + mutate.header(key, valueStr); + log.info("添加请求头参数成功 - 键:[{}] , 值:[{}]", key , value); + } + + /** + * 删除请求头参数 + * @param mutate 修改对象 + * @param key 键 + */ + 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); + } + + /** + * 错误结果响应 + * @param exchange 响应上下文 + * @param msg 响应消息 + * @return + */ + public static Mono errorResponse(ServerWebExchange exchange, String msg, HttpStatus httpStatus) { + ServerHttpResponse response = exchange.getResponse(); + //设置HTTP响应头状态 + response.setStatusCode(httpStatus); + //设置HTTP响应头文本格式 + response.getHeaders().add(HttpHeaders.CONTENT_TYPE, "application/json"); + //定义响应内容 + Result result = Result.error(msg); + String resultJson = JSONObject.toJSONString(result); + log.error("[鉴权异常处理]请求路径:[{}],异常信息:[{}],响应结果:[{}]", exchange.getRequest().getPath(), msg, resultJson); + DataBuffer dataBuffer = response.bufferFactory().wrap(resultJson.getBytes()); + //进行响应 + return response.writeWith(Mono.just(dataBuffer)); + } + + /** + * 错误结果响应 + * @param exchange 响应上下文 + * @param msg 响应消息 + * @return + */ + public static Mono errorResponse(ServerWebExchange exchange, String msg) { + ServerHttpResponse response = exchange.getResponse(); + //设置HTTP响应头状态 + response.setStatusCode(HttpStatus.OK); + //设置HTTP响应头文本格式 + response.getHeaders().add(HttpHeaders.CONTENT_TYPE, "application/json"); + //定义响应内容 + Result result = Result.error(msg); + String resultJson = JSONObject.toJSONString(result); + log.error("[鉴权异常处理]请求路径:[{}],异常信息:[{}],响应结果:[{}]", exchange.getRequest().getPath(), msg, resultJson); + DataBuffer dataBuffer = response.bufferFactory().wrap(resultJson.getBytes()); + //进行响应 + return response.writeWith(Mono.just(dataBuffer)); + } + + +} 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-goods/pom.xml b/bwie-modules/bwie-goods/pom.xml new file mode 100644 index 0000000..08ee29a --- /dev/null +++ b/bwie-modules/bwie-goods/pom.xml @@ -0,0 +1,63 @@ + + + 4.0.0 + + com.bwie + test_week1 + 1.0-SNAPSHOT + ../../pom.xml + + + bwie-goods + + + 8 + 8 + 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 + + + + \ No newline at end of file diff --git a/bwie-modules/bwie-goods/src/main/java/com/bwie/goods/GoodsApp.java b/bwie-modules/bwie-goods/src/main/java/com/bwie/goods/GoodsApp.java new file mode 100644 index 0000000..3f0a6c9 --- /dev/null +++ b/bwie-modules/bwie-goods/src/main/java/com/bwie/goods/GoodsApp.java @@ -0,0 +1,13 @@ +package com.bwie.goods; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.openfeign.EnableFeignClients; + +@SpringBootApplication +@EnableFeignClients +public class GoodsApp { + public static void main(String[] args) { + SpringApplication.run(GoodsApp.class); + } +} diff --git a/bwie-modules/bwie-goods/src/main/java/com/bwie/goods/controller/GoodsController.java b/bwie-modules/bwie-goods/src/main/java/com/bwie/goods/controller/GoodsController.java new file mode 100644 index 0000000..7656c8c --- /dev/null +++ b/bwie-modules/bwie-goods/src/main/java/com/bwie/goods/controller/GoodsController.java @@ -0,0 +1,46 @@ +package com.bwie.goods.controller; + +import com.alibaba.fastjson.JSONObject; +import com.bwie.common.domain.request.GoodsRequest; +import com.bwie.common.result.Result; +import com.bwie.goods.service.GoodsService; +import lombok.extern.log4j.Log4j2; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; + +@RestController +@Log4j2 +public class GoodsController { + @Autowired + private GoodsService goodsService; + + @Autowired + private HttpServletRequest request; + + @GetMapping("typeshow") + public Result typeshow(){ + log.info("功能名称:xxx,请求URI:{},请求方式:{}", + request.getRequestURI(),request.getMethod()); + Result result = goodsService.typeshow(); + log.info("功能名称:xxx,请求URI:{},请求方式:{},响应结果:{}", + request.getRequestURI(),request.getMethod(), JSONObject.toJSONString(result)); + return result; + } + + @PostMapping("show") + public Result show(@RequestBody GoodsRequest goodsRequest){ + log.info("功能名称:xxx,请求URI:{},请求方式:{},请求参数:{}", + request.getRequestURI(),request.getMethod(),goodsRequest); + Result result = goodsService.show(goodsRequest); + log.info("功能名称:xxx,请求URI:{},请求方式:{},响应结果:{}", + request.getRequestURI(),request.getMethod(), JSONObject.toJSONString(result)); + return result; + } + + +} diff --git a/bwie-modules/bwie-goods/src/main/java/com/bwie/goods/feign/GoodsFeign.java b/bwie-modules/bwie-goods/src/main/java/com/bwie/goods/feign/GoodsFeign.java new file mode 100644 index 0000000..c3d3c13 --- /dev/null +++ b/bwie-modules/bwie-goods/src/main/java/com/bwie/goods/feign/GoodsFeign.java @@ -0,0 +1,12 @@ +package com.bwie.goods.feign; + +import com.bwie.common.domain.Opp; +import com.bwie.common.result.Result; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; + +@FeignClient("bwie-opp") +public interface GoodsFeign { + @GetMapping("finduser") + public Result finduser(); +} diff --git a/bwie-modules/bwie-goods/src/main/java/com/bwie/goods/mapper/GoodsMapper.java b/bwie-modules/bwie-goods/src/main/java/com/bwie/goods/mapper/GoodsMapper.java new file mode 100644 index 0000000..6141ea0 --- /dev/null +++ b/bwie-modules/bwie-goods/src/main/java/com/bwie/goods/mapper/GoodsMapper.java @@ -0,0 +1,19 @@ +package com.bwie.goods.mapper; + +import com.bwie.common.domain.Goods; +import com.bwie.common.domain.Opp; +import com.bwie.common.domain.Type; +import com.bwie.common.domain.request.GoodsRequest; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; +@Mapper +public interface GoodsMapper { + List typelist(); + + List show(GoodsRequest goodsRequest); + + + + void addopp(Integer userId); +} diff --git a/bwie-modules/bwie-goods/src/main/java/com/bwie/goods/service/GoodsService.java b/bwie-modules/bwie-goods/src/main/java/com/bwie/goods/service/GoodsService.java new file mode 100644 index 0000000..457bc61 --- /dev/null +++ b/bwie-modules/bwie-goods/src/main/java/com/bwie/goods/service/GoodsService.java @@ -0,0 +1,12 @@ +package com.bwie.goods.service; + +import com.bwie.common.domain.Type; +import com.bwie.common.domain.request.GoodsRequest; +import com.bwie.common.result.Result; + +import java.util.List; + +public interface GoodsService { + Result typeshow(); + Result show(GoodsRequest goodsRequest); +} diff --git a/bwie-modules/bwie-goods/src/main/java/com/bwie/goods/service/impl/GoodsServiceImpl.java b/bwie-modules/bwie-goods/src/main/java/com/bwie/goods/service/impl/GoodsServiceImpl.java new file mode 100644 index 0000000..315ad37 --- /dev/null +++ b/bwie-modules/bwie-goods/src/main/java/com/bwie/goods/service/impl/GoodsServiceImpl.java @@ -0,0 +1,82 @@ +package com.bwie.goods.service.impl; + +import com.alibaba.fastjson.JSONObject; +import com.bwie.common.constants.TokenConstants; +import com.bwie.common.domain.Goods; +import com.bwie.common.domain.Opp; +import com.bwie.common.domain.SysUser; +import com.bwie.common.domain.Type; +import com.bwie.common.domain.request.GoodsRequest; +import com.bwie.common.result.PageResult; +import com.bwie.common.result.Result; +import com.bwie.common.utils.JwtUtils; +import com.bwie.goods.feign.GoodsFeign; +import com.bwie.goods.mapper.GoodsMapper; +import com.bwie.goods.service.GoodsService; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.stereotype.Service; + +import javax.servlet.http.HttpServletRequest; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +@Service +public class GoodsServiceImpl implements GoodsService { + @Autowired + private StringRedisTemplate redisTemplate; + + @Autowired + private HttpServletRequest request; + + @Autowired + private GoodsMapper goodsMapper; + + @Autowired + private GoodsFeign goodsFeign; + + @Override + public Result typeshow() { + if(!redisTemplate.hasKey("types")){ + List typelist = goodsMapper.typelist(); + for (Type type : typelist) { + redisTemplate.opsForSet().add("list", JSONObject.toJSONString(type)); + } + } + + Set list = redisTemplate.opsForSet().members("list"); + ArrayList types = new ArrayList<>(); + for (String s : list) { + Type type = JSONObject.parseObject(s, Type.class); + types.add(type); + } + + return Result.success(types); + } + + @Override + public Result show(GoodsRequest goodsRequest) { + + Result finduser = goodsFeign.finduser(); + Opp data = finduser.getData(); + if(null==data){ + goodsMapper.addopp(getInfo().getUserId()); + } + PageHelper.startPage(goodsRequest.getPageNum(),goodsRequest.getPageSize()); + List show = goodsMapper.show(goodsRequest); + PageInfo goodsPageInfo = new PageInfo<>(show); + return PageResult.toResult(goodsPageInfo.getTotal(),show); + } + + public SysUser getInfo() { + String header = request.getHeader(TokenConstants.TOKEN); + String userKey = JwtUtils.getUserKey(header); + String s = redisTemplate.opsForValue().get(TokenConstants.LOGIN_TOKEN_KEY + userKey); + return JSONObject.parseObject(s, SysUser.class); + } + + +} diff --git a/bwie-modules/bwie-goods/src/main/resources/bootstrap.yml b/bwie-modules/bwie-goods/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..21f45af --- /dev/null +++ b/bwie-modules/bwie-goods/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-goods + 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-goods/src/main/resources/mapper/GoodsMapper.xml b/bwie-modules/bwie-goods/src/main/resources/mapper/GoodsMapper.xml new file mode 100644 index 0000000..844dfb2 --- /dev/null +++ b/bwie-modules/bwie-goods/src/main/resources/mapper/GoodsMapper.xml @@ -0,0 +1,26 @@ + + + + + insert into opp (`opp_status`,`user_id`) + values (1,#{userId}) + + + + + + \ No newline at end of file diff --git a/bwie-modules/bwie-mq/pom.xml b/bwie-modules/bwie-mq/pom.xml new file mode 100644 index 0000000..c564687 --- /dev/null +++ b/bwie-modules/bwie-mq/pom.xml @@ -0,0 +1,68 @@ + + + 4.0.0 + + com.bwie + test_week1 + 1.0-SNAPSHOT + ../../pom.xml + + + bwie-mq + + + 8 + 8 + 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 + + + + + + \ No newline at end of file diff --git a/bwie-modules/bwie-mq/src/main/resources/bootstrap.yml b/bwie-modules/bwie-mq/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..6550be5 --- /dev/null +++ b/bwie-modules/bwie-mq/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-mq + 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-mq/src/main/resources/mapper/MQMapper.xml b/bwie-modules/bwie-mq/src/main/resources/mapper/MQMapper.xml new file mode 100644 index 0000000..6fc9735 --- /dev/null +++ b/bwie-modules/bwie-mq/src/main/resources/mapper/MQMapper.xml @@ -0,0 +1,10 @@ + + + + + + insert into rest + (`stu_id`,`rest_src`) + values (#{stuId},#{restSrc}) + + \ No newline at end of file diff --git a/bwie-modules/bwie-opp/pom.xml b/bwie-modules/bwie-opp/pom.xml new file mode 100644 index 0000000..9073725 --- /dev/null +++ b/bwie-modules/bwie-opp/pom.xml @@ -0,0 +1,91 @@ + + + 4.0.0 + + com.bwie + test_week1 + 1.0-SNAPSHOT + ../../pom.xml + + + bwie-opp + + + 8 + 8 + 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 + + + + + com.alibaba + fastjson + 1.2.15 + + + org.apache.httpcomponents + httpclient + 4.5.3 + + + org.apache.httpcomponents + httpcore + 4.4.15 + + + commons-lang + commons-lang + 2.6 + + + org.eclipse.jetty + jetty-util + 9.3.7.v20160115 + + + + \ No newline at end of file diff --git a/bwie-modules/bwie-opp/src/main/java/com/bwie/opp/OppApp.java b/bwie-modules/bwie-opp/src/main/java/com/bwie/opp/OppApp.java new file mode 100644 index 0000000..94cbdab --- /dev/null +++ b/bwie-modules/bwie-opp/src/main/java/com/bwie/opp/OppApp.java @@ -0,0 +1,11 @@ +package com.bwie.opp; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class OppApp { + public static void main(String[] args) { + SpringApplication.run(OppApp.class); + } +} diff --git a/bwie-modules/bwie-opp/src/main/java/com/bwie/opp/controller/OppController.java b/bwie-modules/bwie-opp/src/main/java/com/bwie/opp/controller/OppController.java new file mode 100644 index 0000000..5d524fd --- /dev/null +++ b/bwie-modules/bwie-opp/src/main/java/com/bwie/opp/controller/OppController.java @@ -0,0 +1,66 @@ +package com.bwie.opp.controller; + +import com.alibaba.fastjson.JSONObject; +import com.alibaba.nacos.shaded.org.checkerframework.checker.fenum.qual.AwtFlowLayout; +import com.bwie.common.domain.Opp; +import com.bwie.common.result.Result; +import com.bwie.opp.service.OppService; +import lombok.extern.log4j.Log4j2; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; + +@RestController +@Log4j2 +public class OppController { + + @Autowired + private HttpServletRequest request; + + @Autowired + private OppService oppService; + + + @GetMapping("finduser") + public Result finduser(){ + log.info("功能名称:xxx,请求URI:{},请求方式:{}", + request.getRequestURI(),request.getMethod()); + Result result= oppService.finduser(); + log.info("功能名称:xxx,请求URI:{},请求方式:{},响应结果:{}", + request.getRequestURI(),request.getMethod(), JSONObject.toJSONString(result)); + return result; + } + + @GetMapping("yue") + public Result yue(){ + log.info("功能名称:xxx,请求URI:{},请求方式:{}", + request.getRequestURI(),request.getMethod()); + Result result = oppService.yue(); + log.info("功能名称:xxx,请求URI:{},请求方式:{},响应结果:{}", + request.getRequestURI(),request.getMethod(), JSONObject.toJSONString(result)); + return result; + } + + @GetMapping("tui") + public Result tui(){ + log.info("功能名称:xxx,请求URI:{},请求方式:{}", + request.getRequestURI(),request.getMethod()); + Result result = oppService.tui(); + log.info("功能名称:xxx,请求URI:{},请求方式:{},响应结果:{}", + request.getRequestURI(),request.getMethod(), JSONObject.toJSONString(result)); + return result; + } + + @GetMapping("dui") + public Result dui(){ + log.info("功能名称:xxx,请求URI:{},请求方式:{}", + request.getRequestURI(),request.getMethod()); + Result result = oppService.dui(); + log.info("功能名称:xxx,请求URI:{},请求方式:{},响应结果:{}", + request.getRequestURI(),request.getMethod(), JSONObject.toJSONString(result)); + return result; + } +} diff --git a/bwie-modules/bwie-opp/src/main/java/com/bwie/opp/mapper/OppMapper.java b/bwie-modules/bwie-opp/src/main/java/com/bwie/opp/mapper/OppMapper.java new file mode 100644 index 0000000..cc80b4e --- /dev/null +++ b/bwie-modules/bwie-opp/src/main/java/com/bwie/opp/mapper/OppMapper.java @@ -0,0 +1,24 @@ +package com.bwie.opp.mapper; + +import com.bwie.common.domain.Opp; +import com.bwie.common.result.Result; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface OppMapper { + Opp findopp(Integer userId); + + void updmoney(Integer userId); + + void updyue(Integer userId); + + void tuimoney(Integer userId); + + void updtui(Integer userId); + + void upddui(Integer userId); + //查询用户状态 + //判断按钮 + + +} diff --git a/bwie-modules/bwie-opp/src/main/java/com/bwie/opp/service/OppService.java b/bwie-modules/bwie-opp/src/main/java/com/bwie/opp/service/OppService.java new file mode 100644 index 0000000..56f036f --- /dev/null +++ b/bwie-modules/bwie-opp/src/main/java/com/bwie/opp/service/OppService.java @@ -0,0 +1,16 @@ +package com.bwie.opp.service; + +import com.bwie.common.domain.Opp; +import com.bwie.common.result.Result; + +public interface OppService { + //判断按钮 + Result finduser(); + //预约 + Result yue(); + Result tui(); + + Result dui(); + + +} diff --git a/bwie-modules/bwie-opp/src/main/java/com/bwie/opp/service/impl/OppServiceImpl.java b/bwie-modules/bwie-opp/src/main/java/com/bwie/opp/service/impl/OppServiceImpl.java new file mode 100644 index 0000000..e9f393a --- /dev/null +++ b/bwie-modules/bwie-opp/src/main/java/com/bwie/opp/service/impl/OppServiceImpl.java @@ -0,0 +1,73 @@ +package com.bwie.opp.service.impl; + +import com.alibaba.fastjson.JSONObject; +import com.bwie.common.constants.TokenConstants; +import com.bwie.common.domain.Opp; +import com.bwie.common.domain.SysUser; +import com.bwie.common.result.Result; +import com.bwie.common.utils.JwtUtils; +import com.bwie.opp.mapper.OppMapper; +import com.bwie.opp.service.OppService; +import com.bwie.opp.util.MsgUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.stereotype.Service; + +import javax.servlet.http.HttpServletRequest; + +@Service +public class OppServiceImpl implements OppService { + + @Autowired + private MsgUtil msgUtil; + + @Autowired + private OppMapper oppMapper; + + @Autowired + private HttpServletRequest request;; + + @Autowired + private StringRedisTemplate redisTemplate; + + @Override + public Result finduser() { + String s = redisTemplate.opsForValue().get("present:"); + Integer i = JSONObject.parseObject(s, Integer.class); + Opp findopp = oppMapper.findopp(i); + return Result.success(findopp); + } + + @Override + public Result yue() { + //修改余额 + if(getInfo().getUserMoney()<30){ + return Result.error("余额不足"); + } + oppMapper.updmoney(getInfo().getUserId()); + //修改opp状态 + oppMapper.updyue(getInfo().getUserId()); + return Result.success("预约成功"); + } + + @Override + public Result tui() { + oppMapper.tuimoney(getInfo().getUserId()); + oppMapper.updtui(getInfo().getUserId()); + msgUtil.sendMsg(getInfo().getUserPhone(),"111"); + return Result.success("已退票"); + } + + @Override + public Result dui() { + oppMapper.upddui(getInfo().getUserId()); + return Result.success("已兑换"); + } + + public SysUser getInfo() { + String header = request.getHeader(TokenConstants.TOKEN); + String userKey = JwtUtils.getUserKey(header); + String s = redisTemplate.opsForValue().get(TokenConstants.LOGIN_TOKEN_KEY+userKey); + return JSONObject.parseObject(s, SysUser.class); + } +} diff --git a/bwie-modules/bwie-opp/src/main/java/com/bwie/opp/util/HttpUtils.java b/bwie-modules/bwie-opp/src/main/java/com/bwie/opp/util/HttpUtils.java new file mode 100644 index 0000000..c9e7406 --- /dev/null +++ b/bwie-modules/bwie-opp/src/main/java/com/bwie/opp/util/HttpUtils.java @@ -0,0 +1,319 @@ +package com.bwie.opp.util; + +import com.alibaba.fastjson.JSON; +import org.apache.commons.lang.StringUtils; +import org.apache.http.HttpResponse; +import org.apache.http.NameValuePair; +import org.apache.http.client.HttpClient; +import org.apache.http.client.entity.UrlEncodedFormEntity; +import org.apache.http.client.methods.HttpDelete; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.methods.HttpPut; +import org.apache.http.conn.ClientConnectionManager; +import org.apache.http.conn.scheme.Scheme; +import org.apache.http.conn.scheme.SchemeRegistry; +import org.apache.http.conn.ssl.SSLSocketFactory; +import org.apache.http.entity.ByteArrayEntity; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.message.BasicNameValuePair; +import org.apache.http.util.EntityUtils; + +import javax.net.ssl.SSLContext; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.X509Certificate; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class HttpUtils { + + /** + * get + * + * @param host + * @param path + * @param method + * @param headers + * @param querys + * @return + * @throws Exception + */ + public static List doGet(String host, String path, String method, + Map headers, + Map querys + ,Class clazz) + throws Exception { + HttpClient httpClient = wrapClient(host); + + HttpGet request = new HttpGet(buildUrl(host, path, querys)); + if(headers!=null){ + for (Map.Entry e : headers.entrySet()) { + request.addHeader(e.getKey(), e.getValue()); + } + + } + HttpResponse execute = httpClient.execute(request); + String s = EntityUtils.toString(execute.getEntity(),"UTF-8"); + List ts = JSON.parseArray(s, clazz); + return ts; + } + + /** + * post form + * + * @param host + * @param path + * @param method + * @param headers + * @param querys + * @param bodys + * @return + * @throws Exception + */ + public static HttpResponse doPost(String host, String path, String method, + Map headers, + Map querys, + Map bodys) + throws Exception { + HttpClient httpClient = wrapClient(host); + + HttpPost request = new HttpPost(buildUrl(host, path, querys)); + for (Map.Entry e : headers.entrySet()) { + request.addHeader(e.getKey(), e.getValue()); + } + + if (bodys != null) { + List nameValuePairList = new ArrayList(); + + for (String key : bodys.keySet()) { + nameValuePairList.add(new BasicNameValuePair(key, bodys.get(key))); + } + UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, "utf-8"); + formEntity.setContentType("application/x-www-form-urlencoded; charset=UTF-8"); + request.setEntity(formEntity); + } + + return httpClient.execute(request); + } + + /** + * Post String + * + * @param host + * @param path + * @param method + * @param headers + * @param querys + * @param body + * @return + * @throws Exception + */ + public static HttpResponse doPost(String host, String path, String method, + Map headers, + Map querys, + String body) + throws Exception { + HttpClient httpClient = wrapClient(host); + + HttpPost request = new HttpPost(buildUrl(host, path, querys)); + for (Map.Entry e : headers.entrySet()) { + request.addHeader(e.getKey(), e.getValue()); + } + + if (StringUtils.isNotBlank(body)) { + request.setEntity(new StringEntity(body, "utf-8")); + } + + return httpClient.execute(request); + } + + /** + * Post stream + * + * @param host + * @param path + * @param method + * @param headers + * @param querys + * @param body + * @return + * @throws Exception + */ + public static HttpResponse doPost(String host, String path, String method, + Map headers, + Map querys, + byte[] body) + throws Exception { + HttpClient httpClient = wrapClient(host); + + HttpPost request = new HttpPost(buildUrl(host, path, querys)); + for (Map.Entry e : headers.entrySet()) { + request.addHeader(e.getKey(), e.getValue()); + } + + if (body != null) { + request.setEntity(new ByteArrayEntity(body)); + } + + return httpClient.execute(request); + } + + /** + * Put String + * @param host + * @param path + * @param method + * @param headers + * @param querys + * @param body + * @return + * @throws Exception + */ + public static HttpResponse doPut(String host, String path, String method, + Map headers, + Map querys, + String body) + throws Exception { + HttpClient httpClient = wrapClient(host); + + HttpPut request = new HttpPut(buildUrl(host, path, querys)); + for (Map.Entry e : headers.entrySet()) { + request.addHeader(e.getKey(), e.getValue()); + } + + if (StringUtils.isNotBlank(body)) { + request.setEntity(new StringEntity(body, "utf-8")); + } + + return httpClient.execute(request); + } + + /** + * Put stream + * @param host + * @param path + * @param method + * @param headers + * @param querys + * @param body + * @return + * @throws Exception + */ + public static HttpResponse doPut(String host, String path, String method, + Map headers, + Map querys, + byte[] body) + throws Exception { + HttpClient httpClient = wrapClient(host); + + HttpPut request = new HttpPut(buildUrl(host, path, querys)); + for (Map.Entry e : headers.entrySet()) { + request.addHeader(e.getKey(), e.getValue()); + } + + if (body != null) { + request.setEntity(new ByteArrayEntity(body)); + } + + return httpClient.execute(request); + } + + /** + * Delete + * + * @param host + * @param path + * @param method + * @param headers + * @param querys + * @return + * @throws Exception + */ + public static HttpResponse doDelete(String host, String path, String method, + Map headers, + Map querys) + throws Exception { + HttpClient httpClient = wrapClient(host); + + HttpDelete request = new HttpDelete(buildUrl(host, path, querys)); + for (Map.Entry e : headers.entrySet()) { + request.addHeader(e.getKey(), e.getValue()); + } + + return httpClient.execute(request); + } + + private static String buildUrl(String host, String path, Map querys) throws UnsupportedEncodingException { + StringBuilder sbUrl = new StringBuilder(); + sbUrl.append(host); + if (!StringUtils.isBlank(path)) { + sbUrl.append(path); + } + if (null != querys) { + StringBuilder sbQuery = new StringBuilder(); + for (Map.Entry query : querys.entrySet()) { + if (0 < sbQuery.length()) { + sbQuery.append("&"); + } + if (StringUtils.isBlank(query.getKey()) && !StringUtils.isBlank(query.getValue())) { + sbQuery.append(query.getValue()); + } + if (!StringUtils.isBlank(query.getKey())) { + sbQuery.append(query.getKey()); + if (!StringUtils.isBlank(query.getValue())) { + sbQuery.append("="); + sbQuery.append(URLEncoder.encode(query.getValue(), "utf-8")); + } + } + } + if (0 < sbQuery.length()) { + sbUrl.append("?").append(sbQuery); + } + } + + return sbUrl.toString(); + } + + private static HttpClient wrapClient(String host) { + HttpClient httpClient = new DefaultHttpClient(); + if (host.startsWith("https://")) { + sslClient(httpClient); + } + + return httpClient; + } + + private static void sslClient(HttpClient httpClient) { + try { + SSLContext ctx = SSLContext.getInstance("TLS"); + X509TrustManager tm = new X509TrustManager() { + public X509Certificate[] getAcceptedIssuers() { + return null; + } + public void checkClientTrusted(X509Certificate[] xcs, String str) { + + } + public void checkServerTrusted(X509Certificate[] xcs, String str) { + + } + }; + ctx.init(null, new TrustManager[] { tm }, null); + SSLSocketFactory ssf = new SSLSocketFactory(ctx); + ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); + ClientConnectionManager ccm = httpClient.getConnectionManager(); + SchemeRegistry registry = ccm.getSchemeRegistry(); + registry.register(new Scheme("https", 443, ssf)); + } catch (KeyManagementException ex) { + throw new RuntimeException(ex); + } catch (NoSuchAlgorithmException ex) { + throw new RuntimeException(ex); + } + } +} \ No newline at end of file diff --git a/bwie-modules/bwie-opp/src/main/java/com/bwie/opp/util/MsgUtil.java b/bwie-modules/bwie-opp/src/main/java/com/bwie/opp/util/MsgUtil.java new file mode 100644 index 0000000..6c7a1fa --- /dev/null +++ b/bwie-modules/bwie-opp/src/main/java/com/bwie/opp/util/MsgUtil.java @@ -0,0 +1,80 @@ +package com.bwie.opp.util; + + +import org.apache.http.HttpResponse; +import org.apache.http.util.EntityUtils; +import org.springframework.cache.annotation.CachePut; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.stereotype.Component; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author + * @version 1.0.0 + * @ClassName MsgUtil.java + * @Description TODO + * @createTime 2022年05月26日 15:49:00 + */ +@Component +public class MsgUtil { + + +// //列表添加 +// //@CacheConfig(cacheNames = "aaa") +// //列表 +// //@Cacheable +// //实时更新 +// //@CacheEvict(allEntries = true) +// +// @Cacheable(key = "#phone",value = "bbb") +// public String getCacheCode(String phone){ +// +// return null; +// } +// +// @CachePut(key = "#codeEntity.phone",value = "bbb") +// public String saveCacheCode(CodeEntity codeEntity){ +// +// return codeEntity.getCode(); +// } + +// 858f87d76b7f4e618a5f7e1557f1d529 + + public void sendMsg(String phone,String code){ + String host = "https://gyytz.market.alicloudapi.com"; + String path = "/sms/smsSend"; + String method = "POST"; + String appcode = "13a8b5b781bc4c458ce2de65ed79be80"; + Map headers = new HashMap(); + //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105 + headers.put("Authorization", "APPCODE " + appcode); + Map querys = new HashMap(); + querys.put("mobile", phone); + querys.put("param", "**code**:"+code+",**minute**:5"); + +//smsSignId(短信前缀)和templateId(短信模板),可登录国阳云控制台自助申请。参考文档:http://help.guoyangyun.com/Problem/Qm.html + + querys.put("smsSignId", "2e65b1bb3d054466b82f0c9d125465e2"); + querys.put("templateId", "908e94ccf08b4476ba6c876d13f084ad"); + Map bodys = new HashMap(); + + + try { + /** + * 重要提示如下: + * HttpUtils请从\r\n\t \t* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java\r\n\t \t* 下载 + * + * 相应的依赖请参照 + * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml + */ + HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys); + System.out.println(response.toString()); + //获取response的body + System.out.println(EntityUtils.toString(response.getEntity())); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/bwie-modules/bwie-opp/src/main/resources/bootstrap.yml b/bwie-modules/bwie-opp/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..18e129c --- /dev/null +++ b/bwie-modules/bwie-opp/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-opp + 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-opp/src/main/resources/mapper/OppMapper.xml b/bwie-modules/bwie-opp/src/main/resources/mapper/OppMapper.xml new file mode 100644 index 0000000..d6d8e56 --- /dev/null +++ b/bwie-modules/bwie-opp/src/main/resources/mapper/OppMapper.xml @@ -0,0 +1,24 @@ + + + + + update user set user_money=user_money-30 where user_id=#{userId} + + + update opp set opp_status=2 where user_id =#{userId} + + + update user set user_money=user_money+30 where user_id=#{userId} + + + update opp set opp_status=3 where user_id =#{userId} + + + update opp set opp_status=4 where user_id =#{userId} + + + + \ No newline at end of file diff --git a/bwie-modules/bwie-system/pom.xml b/bwie-modules/bwie-system/pom.xml new file mode 100644 index 0000000..0913b38 --- /dev/null +++ b/bwie-modules/bwie-system/pom.xml @@ -0,0 +1,63 @@ + + + 4.0.0 + + com.bwie + test_week1 + 1.0-SNAPSHOT + ../../pom.xml + + + bwie-system + + + 8 + 8 + 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 + + + + \ No newline at end of file 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..3a309a4 --- /dev/null +++ b/bwie-modules/bwie-system/src/main/java/com/bwie/system/SysApp.java @@ -0,0 +1,11 @@ +package com.bwie.system; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +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..708087e --- /dev/null +++ b/bwie-modules/bwie-system/src/main/java/com/bwie/system/controller/SysController.java @@ -0,0 +1,35 @@ +package com.bwie.system.controller; + +import com.alibaba.fastjson.JSONObject; +import com.bwie.common.domain.SysUser; +import com.bwie.common.result.Result; +import com.bwie.system.service.SysService; +import lombok.extern.log4j.Log4j2; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; + +@RestController +@Log4j2 +public class SysController { + + @Autowired + private SysService sysService; + + @Autowired + private HttpServletRequest request; + + + @PostMapping("findphone") + public Result findphone(@RequestParam String userPhone){ + log.info("功能名称:xxx,请求URI:{},请求方式:{},请求参数:{}", + request.getRequestURI(),request.getMethod(),userPhone); + Result result = sysService.findname(userPhone); + log.info("功能名称:xxx,请求URI:{},请求方式:{},响应结果:{}", + request.getRequestURI(),request.getMethod(), JSONObject.toJSONString(result)); + return result; + } +} 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..dccaa72 --- /dev/null +++ b/bwie-modules/bwie-system/src/main/java/com/bwie/system/mapper/SysMapper.java @@ -0,0 +1,10 @@ +package com.bwie.system.mapper; + +import com.bwie.common.domain.SysUser; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; +@Mapper +public interface SysMapper { + SysUser findname(String userPhone); +} 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..73274ef --- /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.bwie.common.domain.SysUser; +import com.bwie.common.result.Result; + +public interface SysService { + + Result findname(String userPhone); +} diff --git a/bwie-modules/bwie-system/src/main/java/com/bwie/system/service/impl/SysServiceImpl.java b/bwie-modules/bwie-system/src/main/java/com/bwie/system/service/impl/SysServiceImpl.java new file mode 100644 index 0000000..dbe1e10 --- /dev/null +++ b/bwie-modules/bwie-system/src/main/java/com/bwie/system/service/impl/SysServiceImpl.java @@ -0,0 +1,22 @@ +package com.bwie.system.service.impl; + +import com.bwie.common.domain.SysUser; +import com.bwie.common.result.Result; +import com.bwie.system.mapper.SysMapper; +import com.bwie.system.service.SysService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class SysServiceImpl implements SysService { + + @Autowired + private SysMapper sysMapper; + @Override + public Result findname(String userPhone) { + SysUser findname = sysMapper.findname(userPhone); + return Result.success(findname); + } +} 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..ba0a82c --- /dev/null +++ b/bwie-modules/bwie-system/src/main/resources/mapper/SysMapper.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/bwie-modules/pom.xml b/bwie-modules/pom.xml new file mode 100644 index 0000000..a2f8bd9 --- /dev/null +++ b/bwie-modules/pom.xml @@ -0,0 +1,22 @@ + + + 4.0.0 + + com.bwie + test_week1 + 1.0-SNAPSHOT + + + bwie-modules + + + 8 + 8 + UTF-8 + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..33b075b --- /dev/null +++ b/pom.xml @@ -0,0 +1,72 @@ + + + 4.0.0 + + com.bwie + test_week1 + 1.0-SNAPSHOT + pom + + bwie-auth + bwie-common + bwie-gateway + bwie-modules + bwie-modules/bwie-system + bwie-modules/bwie-mq + bwie-modules/bwie-goods + bwie-modules/bwie-opp + + + + 8 + 8 + 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-SNAPSHOT + + + + + + \ No newline at end of file