From 41da1dbff9386afbe7f6b61bfc43b72f34efcd92 Mon Sep 17 00:00:00 2001 From: 86199 Date: Mon, 6 Nov 2023 08:56:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 38 ++++ .idea/.gitignore | 8 + .idea/dataSources.xml | 12 ++ .idea/encodings.xml | 21 +++ .idea/misc.xml | 14 ++ .idea/sqldialects.xml | 6 + .idea/vcs.xml | 6 + pom.xml | 64 +++++++ wzy-auth/.gitignore | 38 ++++ wzy-auth/pom.xml | 31 ++++ .../java/com/wzy/auth/AuthApplication.java | 13 ++ .../wzy/auth/controller/AuthController.java | 49 ++++++ .../com/wzy/auth/feign/UserFeignService.java | 14 ++ .../com/wzy/auth/service/AuthService.java | 14 ++ .../auth/service/impl/AuthServiceImpl.java | 77 ++++++++ wzy-auth/src/main/resources/bootstrap.yml | 30 ++++ wzy-common/.gitignore | 38 ++++ wzy-common/pom.xml | 116 ++++++++++++ .../com/wzy/common/config/RedisConfig.java | 40 +++++ .../com/wzy/common/constants/Constants.java | 18 ++ .../wzy/common/constants/JwtConstants.java | 29 +++ .../wzy/common/constants/TokenConstants.java | 24 +++ .../main/java/com/wzy/common/domain/Mine.java | 31 ++++ .../java/com/wzy/common/domain/Rebate.java | 26 +++ .../java/com/wzy/common/domain/Servers.java | 11 ++ .../main/java/com/wzy/common/domain/User.java | 22 +++ .../common/domain/request/LoginRequest.java | 9 + .../com/wzy/common/domain/request/Req.java | 17 ++ .../common/domain/response/JwtResponse.java | 9 + .../com/wzy/common/result/PageResult.java | 34 ++++ .../java/com/wzy/common/result/Result.java | 76 ++++++++ .../java/com/wzy/common/utils/FastUtil.java | 55 ++++++ .../java/com/wzy/common/utils/JwtUtils.java | 109 ++++++++++++ .../com/wzy/common/utils/StringUtils.java | 68 +++++++ .../com/wzy/common/utils/TelSmsUtils.java | 87 +++++++++ .../main/resources/META-INF/spring.factories | 3 + wzy-gateway/.gitignore | 38 ++++ wzy-gateway/pom.xml | 42 +++++ .../com/wzy/gateway/GatewayApplication.java | 11 ++ .../wzy/gateway/config/IgnoreWhiteConfig.java | 32 ++++ .../com/wzy/gateway/filters/AuthFilter.java | 62 +++++++ .../com/wzy/gateway/utils/GatewayUtils.java | 98 +++++++++++ wzy-gateway/src/main/resources/bootstrap.yml | 29 +++ wzy-models/.gitignore | 38 ++++ wzy-models/pom.xml | 26 +++ wzy-models/wzy-servers/.gitignore | 38 ++++ wzy-models/wzy-servers/pom.xml | 54 ++++++ .../com/wzy/servers/ServersApplication.java | 10 ++ .../servers/controller/ServersController.java | 106 +++++++++++ .../com/wzy/servers/mapper/ServersMapper.java | 34 ++++ .../wzy/servers/service/ServersService.java | 33 ++++ .../service/impl/ServersServiceImpl.java | 166 ++++++++++++++++++ .../src/main/resources/bootstrap.yml | 42 +++++ .../main/resources/mapper/ServersMapper.xml | 89 ++++++++++ wzy-models/wzy-sms/.gitignore | 38 ++++ wzy-models/wzy-sms/pom.xml | 37 ++++ .../wzy-sms/src/main/resources/bootstrap.yml | 47 +++++ wzy-models/wzy-user/.gitignore | 38 ++++ wzy-models/wzy-user/pom.xml | 54 ++++++ .../java/com/wzy/user/UserApplication.java | 11 ++ .../wzy/user/controller/UserController.java | 34 ++++ .../java/com/wzy/user/mapper/UserMapper.java | 9 + .../com/wzy/user/service/UserService.java | 6 + .../user/service/impl/UserServiceImpl.java | 19 ++ .../wzy-user/src/main/resources/bootstrap.yml | 42 +++++ .../src/main/resources/mapper/UserMapper.xml | 9 + 66 files changed, 2549 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/dataSources.xml create mode 100644 .idea/encodings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/sqldialects.xml create mode 100644 .idea/vcs.xml create mode 100644 pom.xml create mode 100644 wzy-auth/.gitignore create mode 100644 wzy-auth/pom.xml create mode 100644 wzy-auth/src/main/java/com/wzy/auth/AuthApplication.java create mode 100644 wzy-auth/src/main/java/com/wzy/auth/controller/AuthController.java create mode 100644 wzy-auth/src/main/java/com/wzy/auth/feign/UserFeignService.java create mode 100644 wzy-auth/src/main/java/com/wzy/auth/service/AuthService.java create mode 100644 wzy-auth/src/main/java/com/wzy/auth/service/impl/AuthServiceImpl.java create mode 100644 wzy-auth/src/main/resources/bootstrap.yml create mode 100644 wzy-common/.gitignore create mode 100644 wzy-common/pom.xml create mode 100644 wzy-common/src/main/java/com/wzy/common/config/RedisConfig.java create mode 100644 wzy-common/src/main/java/com/wzy/common/constants/Constants.java create mode 100644 wzy-common/src/main/java/com/wzy/common/constants/JwtConstants.java create mode 100644 wzy-common/src/main/java/com/wzy/common/constants/TokenConstants.java create mode 100644 wzy-common/src/main/java/com/wzy/common/domain/Mine.java create mode 100644 wzy-common/src/main/java/com/wzy/common/domain/Rebate.java create mode 100644 wzy-common/src/main/java/com/wzy/common/domain/Servers.java create mode 100644 wzy-common/src/main/java/com/wzy/common/domain/User.java create mode 100644 wzy-common/src/main/java/com/wzy/common/domain/request/LoginRequest.java create mode 100644 wzy-common/src/main/java/com/wzy/common/domain/request/Req.java create mode 100644 wzy-common/src/main/java/com/wzy/common/domain/response/JwtResponse.java create mode 100644 wzy-common/src/main/java/com/wzy/common/result/PageResult.java create mode 100644 wzy-common/src/main/java/com/wzy/common/result/Result.java create mode 100644 wzy-common/src/main/java/com/wzy/common/utils/FastUtil.java create mode 100644 wzy-common/src/main/java/com/wzy/common/utils/JwtUtils.java create mode 100644 wzy-common/src/main/java/com/wzy/common/utils/StringUtils.java create mode 100644 wzy-common/src/main/java/com/wzy/common/utils/TelSmsUtils.java create mode 100644 wzy-common/src/main/resources/META-INF/spring.factories create mode 100644 wzy-gateway/.gitignore create mode 100644 wzy-gateway/pom.xml create mode 100644 wzy-gateway/src/main/java/com/wzy/gateway/GatewayApplication.java create mode 100644 wzy-gateway/src/main/java/com/wzy/gateway/config/IgnoreWhiteConfig.java create mode 100644 wzy-gateway/src/main/java/com/wzy/gateway/filters/AuthFilter.java create mode 100644 wzy-gateway/src/main/java/com/wzy/gateway/utils/GatewayUtils.java create mode 100644 wzy-gateway/src/main/resources/bootstrap.yml create mode 100644 wzy-models/.gitignore create mode 100644 wzy-models/pom.xml create mode 100644 wzy-models/wzy-servers/.gitignore create mode 100644 wzy-models/wzy-servers/pom.xml create mode 100644 wzy-models/wzy-servers/src/main/java/com/wzy/servers/ServersApplication.java create mode 100644 wzy-models/wzy-servers/src/main/java/com/wzy/servers/controller/ServersController.java create mode 100644 wzy-models/wzy-servers/src/main/java/com/wzy/servers/mapper/ServersMapper.java create mode 100644 wzy-models/wzy-servers/src/main/java/com/wzy/servers/service/ServersService.java create mode 100644 wzy-models/wzy-servers/src/main/java/com/wzy/servers/service/impl/ServersServiceImpl.java create mode 100644 wzy-models/wzy-servers/src/main/resources/bootstrap.yml create mode 100644 wzy-models/wzy-servers/src/main/resources/mapper/ServersMapper.xml create mode 100644 wzy-models/wzy-sms/.gitignore create mode 100644 wzy-models/wzy-sms/pom.xml create mode 100644 wzy-models/wzy-sms/src/main/resources/bootstrap.yml create mode 100644 wzy-models/wzy-user/.gitignore create mode 100644 wzy-models/wzy-user/pom.xml create mode 100644 wzy-models/wzy-user/src/main/java/com/wzy/user/UserApplication.java create mode 100644 wzy-models/wzy-user/src/main/java/com/wzy/user/controller/UserController.java create mode 100644 wzy-models/wzy-user/src/main/java/com/wzy/user/mapper/UserMapper.java create mode 100644 wzy-models/wzy-user/src/main/java/com/wzy/user/service/UserService.java create mode 100644 wzy-models/wzy-user/src/main/java/com/wzy/user/service/impl/UserServiceImpl.java create mode 100644 wzy-models/wzy-user/src/main/resources/bootstrap.yml create mode 100644 wzy-models/wzy-user/src/main/resources/mapper/UserMapper.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..35410ca --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml +# 基于编辑器的 HTTP 客户端请求 +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 0000000..5306807 --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,12 @@ + + + + + mysql.8 + true + com.mysql.cj.jdbc.Driver + jdbc:mysql://165.154.161.166:3306/2103a + $ProjectFileDir$ + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..11295ce --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + \ 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/sqldialects.xml b/.idea/sqldialects.xml new file mode 100644 index 0000000..56782ca --- /dev/null +++ b/.idea/sqldialects.xml @@ -0,0 +1,6 @@ + + + + + + \ 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/pom.xml b/pom.xml new file mode 100644 index 0000000..692e0c4 --- /dev/null +++ b/pom.xml @@ -0,0 +1,64 @@ + + + 4.0.0 + + com.wzy + wzy-11.1zk + 1.0-SNAPSHOT + pom + + wzy-common + wzy-auth + wzy-gateway + wzy-models + + + + 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.wzy + wzy-common + 1.0-SNAPSHOT + + + + diff --git a/wzy-auth/.gitignore b/wzy-auth/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/wzy-auth/.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/wzy-auth/pom.xml b/wzy-auth/pom.xml new file mode 100644 index 0000000..e47e7aa --- /dev/null +++ b/wzy-auth/pom.xml @@ -0,0 +1,31 @@ + + + 4.0.0 + + com.wzy + wzy-11.1zk + 1.0-SNAPSHOT + + + wzy-auth + + + 17 + 17 + UTF-8 + + + + + com.wzy + wzy-common + + + + org.springframework.boot + spring-boot-starter-web + + + diff --git a/wzy-auth/src/main/java/com/wzy/auth/AuthApplication.java b/wzy-auth/src/main/java/com/wzy/auth/AuthApplication.java new file mode 100644 index 0000000..5936fc5 --- /dev/null +++ b/wzy-auth/src/main/java/com/wzy/auth/AuthApplication.java @@ -0,0 +1,13 @@ +package com.wzy.auth; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.openfeign.EnableFeignClients; + +@SpringBootApplication +@EnableFeignClients +public class AuthApplication { + public static void main(String[] args) { + SpringApplication.run(AuthApplication.class); + } +} diff --git a/wzy-auth/src/main/java/com/wzy/auth/controller/AuthController.java b/wzy-auth/src/main/java/com/wzy/auth/controller/AuthController.java new file mode 100644 index 0000000..42bf523 --- /dev/null +++ b/wzy-auth/src/main/java/com/wzy/auth/controller/AuthController.java @@ -0,0 +1,49 @@ +package com.wzy.auth.controller; + +import com.alibaba.fastjson.JSONObject; +import com.wzy.auth.service.AuthService; +import com.wzy.common.domain.User; +import com.wzy.common.domain.request.LoginRequest; +import com.wzy.common.domain.response.JwtResponse; +import com.wzy.common.result.Result; +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 AuthController { + + @Autowired + private AuthService authService; + + @Autowired + private HttpServletRequest request; + + @PostMapping("/login") + public Result login(@RequestBody LoginRequest loginRequest){ + log.info("功能:登录,请求URI:{},请求方式:{},请求参数:{}",request.getRequestURI(), + request.getMethod(),loginRequest); + Result result = authService.login(loginRequest); + log.info("功能:登录,请求URI:{},请求方式:{},响应结果:{}",request.getRequestURI(), + request.getMethod(), JSONObject.toJSONString(result)); + return result; + } + + @GetMapping("/user/info") + public Result userInfo(){ + User user = authService.userInfo(); + return Result.success(user); + } + + @PostMapping("/logout") + public Result logout(){ + authService.logout(); + return Result.success(); + } +} diff --git a/wzy-auth/src/main/java/com/wzy/auth/feign/UserFeignService.java b/wzy-auth/src/main/java/com/wzy/auth/feign/UserFeignService.java new file mode 100644 index 0000000..d6fa32d --- /dev/null +++ b/wzy-auth/src/main/java/com/wzy/auth/feign/UserFeignService.java @@ -0,0 +1,14 @@ +package com.wzy.auth.feign; + +import com.wzy.common.domain.User; +import com.wzy.common.result.Result; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; + +@FeignClient("wzy-user") +public interface UserFeignService { + + @PostMapping("/login/{userName}") + Result login(@PathVariable String userName); +} diff --git a/wzy-auth/src/main/java/com/wzy/auth/service/AuthService.java b/wzy-auth/src/main/java/com/wzy/auth/service/AuthService.java new file mode 100644 index 0000000..a9713e4 --- /dev/null +++ b/wzy-auth/src/main/java/com/wzy/auth/service/AuthService.java @@ -0,0 +1,14 @@ +package com.wzy.auth.service; + +import com.wzy.common.domain.User; +import com.wzy.common.domain.request.LoginRequest; +import com.wzy.common.domain.response.JwtResponse; +import com.wzy.common.result.Result; + +public interface AuthService { + Result login(LoginRequest loginRequest); + + User userInfo(); + + void logout(); +} diff --git a/wzy-auth/src/main/java/com/wzy/auth/service/impl/AuthServiceImpl.java b/wzy-auth/src/main/java/com/wzy/auth/service/impl/AuthServiceImpl.java new file mode 100644 index 0000000..9f3f099 --- /dev/null +++ b/wzy-auth/src/main/java/com/wzy/auth/service/impl/AuthServiceImpl.java @@ -0,0 +1,77 @@ +package com.wzy.auth.service.impl; + +import com.alibaba.fastjson.JSONObject; +import com.wzy.auth.feign.UserFeignService; +import com.wzy.auth.service.AuthService; +import com.wzy.common.constants.JwtConstants; +import com.wzy.common.constants.TokenConstants; +import com.wzy.common.domain.User; +import com.wzy.common.domain.request.LoginRequest; +import com.wzy.common.domain.response.JwtResponse; +import com.wzy.common.result.Result; +import com.wzy.common.utils.JwtUtils; +import com.wzy.common.utils.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +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 UserFeignService userFeignService; + + @Autowired + private RedisTemplate redisTemplate; + + @Autowired + private HttpServletRequest request; + @Override + public Result login(LoginRequest loginRequest) { + Result byUserName = userFeignService.login(loginRequest.getUserName()); + User data = byUserName.getData(); + + if (null == data){ + return Result.error("用户不存在"); + } + + if (StringUtils.isAllEmpty(loginRequest.getUserName(),loginRequest.getUserPwd())){ + return Result.error("用户或密码不能为空"); + } + + if (!loginRequest.getUserPwd().equals(data.getUserPwd())){ + return Result.error("密码错误"); + } + + String userKey = UUID.randomUUID().toString().replaceAll("-", ""); + HashMap map = new HashMap<>(); + map.put(JwtConstants.USER_KEY,userKey); + String token = JwtUtils.createToken(map); + redisTemplate.opsForValue().set(TokenConstants.LOGIN_TOKEN_KEY+userKey, JSONObject.toJSONString(data),50, TimeUnit.MINUTES); + + JwtResponse jwtResponse = new JwtResponse(); + jwtResponse.setExpireTime("50MIN"); + jwtResponse.setToken(token); + return Result.success(jwtResponse); + } + + @Override + public User userInfo() { + String token = request.getHeader(TokenConstants.TOKEN); + String userKey = JwtUtils.getUserKey(token); + String s = redisTemplate.opsForValue().get(TokenConstants.LOGIN_TOKEN_KEY + userKey); + return JSONObject.parseObject(s,User.class); + } + + @Override + public void logout() { + String token = request.getHeader(TokenConstants.TOKEN); + String userKey = JwtUtils.getUserKey(token); + redisTemplate.delete(TokenConstants.LOGIN_TOKEN_KEY + userKey); + } +} diff --git a/wzy-auth/src/main/resources/bootstrap.yml b/wzy-auth/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..bcbb870 --- /dev/null +++ b/wzy-auth/src/main/resources/bootstrap.yml @@ -0,0 +1,30 @@ +# Tomcat +server: + port: 9003 +# Spring +spring: + main: + allow-circular-references: true + jackson: + date-format: yyyy-MM-dd HH:mm:ss + time-zone: GMT+8 + application: + # 应用名称 + name: wzy-auth + profiles: + # 环境配置 + active: dev + cloud: + nacos: + discovery: + # 服务注册地址 + server-addr: 165.154.161.166:8848 + config: + # 配置中心地址 + server-addr: 165.154.161.166:8848 + # 配置文件格式 + file-extension: yml + # 共享配置 + shared-configs: + - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} + diff --git a/wzy-common/.gitignore b/wzy-common/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/wzy-common/.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/wzy-common/pom.xml b/wzy-common/pom.xml new file mode 100644 index 0000000..06b3be4 --- /dev/null +++ b/wzy-common/pom.xml @@ -0,0 +1,116 @@ + + + 4.0.0 + + com.wzy + wzy-11.1zk + 1.0-SNAPSHOT + + + wzy-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 + + + + com.aliyun.oss + aliyun-sdk-oss + 3.12.0 + + + + org.springframework.boot + spring-boot-starter-amqp + + + + com.github.tobato + fastdfs-client + 1.26.5 + + + diff --git a/wzy-common/src/main/java/com/wzy/common/config/RedisConfig.java b/wzy-common/src/main/java/com/wzy/common/config/RedisConfig.java new file mode 100644 index 0000000..02462ef --- /dev/null +++ b/wzy-common/src/main/java/com/wzy/common/config/RedisConfig.java @@ -0,0 +1,40 @@ +package com.wzy.common.config; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.PropertyAccessor; +import com.fasterxml.jackson.databind.ObjectMapper; +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.serializer.Jackson2JsonRedisSerializer; +import org.springframework.data.redis.serializer.StringRedisSerializer; + +@Configuration +public class RedisConfig { + + @Bean + public RedisTemplate redisTemplate(RedisConnectionFactory factory) { + RedisTemplate template = new RedisTemplate<>(); + template.setConnectionFactory(factory); + Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new + Jackson2JsonRedisSerializer(Object.class); + ObjectMapper om = new ObjectMapper(); + om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); + om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL); + jackson2JsonRedisSerializer.setObjectMapper(om); + + StringRedisSerializer stringRedisSerializer = new StringRedisSerializer(); + // key采用String的序列化方式 + template.setKeySerializer(stringRedisSerializer); + // hash的key也采用String的序列化方式 + template.setHashKeySerializer(stringRedisSerializer); + // value序列化方式采用jackson + template.setValueSerializer(jackson2JsonRedisSerializer); + // hash的value序列化方式采用jackson + template.setHashValueSerializer(jackson2JsonRedisSerializer); + template.afterPropertiesSet(); + + return template; + } +} diff --git a/wzy-common/src/main/java/com/wzy/common/constants/Constants.java b/wzy-common/src/main/java/com/wzy/common/constants/Constants.java new file mode 100644 index 0000000..41f728a --- /dev/null +++ b/wzy-common/src/main/java/com/wzy/common/constants/Constants.java @@ -0,0 +1,18 @@ +package com.wzy.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/wzy-common/src/main/java/com/wzy/common/constants/JwtConstants.java b/wzy-common/src/main/java/com/wzy/common/constants/JwtConstants.java new file mode 100644 index 0000000..b8d22af --- /dev/null +++ b/wzy-common/src/main/java/com/wzy/common/constants/JwtConstants.java @@ -0,0 +1,29 @@ +package com.wzy.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/wzy-common/src/main/java/com/wzy/common/constants/TokenConstants.java b/wzy-common/src/main/java/com/wzy/common/constants/TokenConstants.java new file mode 100644 index 0000000..51402e6 --- /dev/null +++ b/wzy-common/src/main/java/com/wzy/common/constants/TokenConstants.java @@ -0,0 +1,24 @@ +package com.wzy.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/wzy-common/src/main/java/com/wzy/common/domain/Mine.java b/wzy-common/src/main/java/com/wzy/common/domain/Mine.java new file mode 100644 index 0000000..7ec8e15 --- /dev/null +++ b/wzy-common/src/main/java/com/wzy/common/domain/Mine.java @@ -0,0 +1,31 @@ +package com.wzy.common.domain; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; + +import java.util.Date; + +@Data +public class Mine { + private Integer mineId; + @JsonFormat(pattern = "yyyy-MM-dd") + private Date mineDate; + private String serverName; + private String serverDesc; + private Integer serverPrice; + private String mineName; + private Integer start; + private Double rebateScale; + private Integer rebatePrice; + private String pic; + + private Integer userId; + private String userName; + private String userPwd; + private Integer userPrice; + private String userCode; + private Integer rebateNum; + private Integer points; + @JsonFormat(pattern = "yyyy-MM-dd") + private Date rebateDate; +} diff --git a/wzy-common/src/main/java/com/wzy/common/domain/Rebate.java b/wzy-common/src/main/java/com/wzy/common/domain/Rebate.java new file mode 100644 index 0000000..16271fa --- /dev/null +++ b/wzy-common/src/main/java/com/wzy/common/domain/Rebate.java @@ -0,0 +1,26 @@ +package com.wzy.common.domain; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; + +import java.util.Date; + +@Data +public class Rebate { + private Integer rebateId; + @JsonFormat(pattern = "yyyy-MM-dd") + private Date rebateDate; + private String serverName; + private Integer serverPrice; + private Double rebateScale; + private Integer rebatePrice; + private String remark; + + private Integer userId; + private String userName; + private String userPwd; + private Integer userPrice; + private String userCode; + private Integer rebateNum; + private Integer points; +} diff --git a/wzy-common/src/main/java/com/wzy/common/domain/Servers.java b/wzy-common/src/main/java/com/wzy/common/domain/Servers.java new file mode 100644 index 0000000..8825e3f --- /dev/null +++ b/wzy-common/src/main/java/com/wzy/common/domain/Servers.java @@ -0,0 +1,11 @@ +package com.wzy.common.domain; + +import lombok.Data; + +@Data +public class Servers { + private Integer serverId; + private String serverName; + private String serverDesc; + private Integer serverPrice; +} diff --git a/wzy-common/src/main/java/com/wzy/common/domain/User.java b/wzy-common/src/main/java/com/wzy/common/domain/User.java new file mode 100644 index 0000000..e5b34f4 --- /dev/null +++ b/wzy-common/src/main/java/com/wzy/common/domain/User.java @@ -0,0 +1,22 @@ +package com.wzy.common.domain; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; + +import java.util.Date; + +@Data +public class User { + private Integer userId; + private String userName; + private String userPwd; + private Integer userPrice; + private String userCode; + private Integer rebateNum; + private Integer rebatePrice; + private Integer points; + @JsonFormat(pattern = "yyyy-MM-dd") + private Date rebateDate; + private Integer roleId; + private Integer userNum; +} diff --git a/wzy-common/src/main/java/com/wzy/common/domain/request/LoginRequest.java b/wzy-common/src/main/java/com/wzy/common/domain/request/LoginRequest.java new file mode 100644 index 0000000..232fefd --- /dev/null +++ b/wzy-common/src/main/java/com/wzy/common/domain/request/LoginRequest.java @@ -0,0 +1,9 @@ +package com.wzy.common.domain.request; + +import lombok.Data; + +@Data +public class LoginRequest { + private String userName; + private String userPwd; +} diff --git a/wzy-common/src/main/java/com/wzy/common/domain/request/Req.java b/wzy-common/src/main/java/com/wzy/common/domain/request/Req.java new file mode 100644 index 0000000..930eccb --- /dev/null +++ b/wzy-common/src/main/java/com/wzy/common/domain/request/Req.java @@ -0,0 +1,17 @@ +package com.wzy.common.domain.request; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; + +import java.util.Date; + +@Data +public class Req { + @JsonFormat(pattern = "yyyy-MM-dd") + private Date start; + @JsonFormat(pattern = "yyyy-MM-dd") + private Date end; + private Integer roleId; + private Integer userId; + private Integer serverPrice; +} diff --git a/wzy-common/src/main/java/com/wzy/common/domain/response/JwtResponse.java b/wzy-common/src/main/java/com/wzy/common/domain/response/JwtResponse.java new file mode 100644 index 0000000..8c3bd78 --- /dev/null +++ b/wzy-common/src/main/java/com/wzy/common/domain/response/JwtResponse.java @@ -0,0 +1,9 @@ +package com.wzy.common.domain.response; + +import lombok.Data; + +@Data +public class JwtResponse { + private String token; + private String expireTime; +} diff --git a/wzy-common/src/main/java/com/wzy/common/result/PageResult.java b/wzy-common/src/main/java/com/wzy/common/result/PageResult.java new file mode 100644 index 0000000..9c7424a --- /dev/null +++ b/wzy-common/src/main/java/com/wzy/common/result/PageResult.java @@ -0,0 +1,34 @@ +package com.wzy.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/wzy-common/src/main/java/com/wzy/common/result/Result.java b/wzy-common/src/main/java/com/wzy/common/result/Result.java new file mode 100644 index 0000000..bbb8cb2 --- /dev/null +++ b/wzy-common/src/main/java/com/wzy/common/result/Result.java @@ -0,0 +1,76 @@ +package com.wzy.common.result; + +import com.wzy.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/wzy-common/src/main/java/com/wzy/common/utils/FastUtil.java b/wzy-common/src/main/java/com/wzy/common/utils/FastUtil.java new file mode 100644 index 0000000..a5b065e --- /dev/null +++ b/wzy-common/src/main/java/com/wzy/common/utils/FastUtil.java @@ -0,0 +1,55 @@ +package com.wzy.common.utils; + +import org.springframework.stereotype.Component; +import com.github.tobato.fastdfs.domain.fdfs.StorePath; +import com.github.tobato.fastdfs.service.FastFileStorageClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.util.StringUtils; +import org.springframework.web.multipart.MultipartFile; + +import javax.annotation.Resource; + +/** + * @BelongsProject: 0107day02 + * @BelongsPackage: com.bw.config + * @Author: zhupengfei + * @CreateTime: 2023-02-01 08:52 + */ +@Component +public class FastUtil { + private static final Logger log = LoggerFactory.getLogger(FastUtil.class); + + @Resource + private FastFileStorageClient storageClient ; + + /** + * 上传文件 + */ + public String upload(MultipartFile multipartFile) throws Exception{ + String originalFilename = multipartFile.getOriginalFilename(). + substring(multipartFile.getOriginalFilename(). + lastIndexOf(".") + 1); + StorePath storePath = this.storageClient.uploadImageAndCrtThumbImage( + multipartFile.getInputStream(), + multipartFile.getSize(),originalFilename , null); + return storePath.getFullPath() ; + } + /** + * 删除文件 + */ + public String deleteFile(String fileUrl) { + if (StringUtils.isEmpty(fileUrl)) { + log.info("fileUrl == >>文件路径为空..."); + return "文件路径不能为空"; + } + try { + StorePath storePath = StorePath.parseFromUrl(fileUrl); + storageClient.deleteFile(storePath.getGroup(), storePath.getPath()); + } catch (Exception e) { + log.error(e.getMessage()); + } + return "删除成功"; + } + +} diff --git a/wzy-common/src/main/java/com/wzy/common/utils/JwtUtils.java b/wzy-common/src/main/java/com/wzy/common/utils/JwtUtils.java new file mode 100644 index 0000000..5358ed5 --- /dev/null +++ b/wzy-common/src/main/java/com/wzy/common/utils/JwtUtils.java @@ -0,0 +1,109 @@ +package com.wzy.common.utils; + +import com.wzy.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/wzy-common/src/main/java/com/wzy/common/utils/StringUtils.java b/wzy-common/src/main/java/com/wzy/common/utils/StringUtils.java new file mode 100644 index 0000000..fbc3917 --- /dev/null +++ b/wzy-common/src/main/java/com/wzy/common/utils/StringUtils.java @@ -0,0 +1,68 @@ +package com.wzy.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/wzy-common/src/main/java/com/wzy/common/utils/TelSmsUtils.java b/wzy-common/src/main/java/com/wzy/common/utils/TelSmsUtils.java new file mode 100644 index 0000000..bb1a106 --- /dev/null +++ b/wzy-common/src/main/java/com/wzy/common/utils/TelSmsUtils.java @@ -0,0 +1,87 @@ +package com.wzy.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 = "LTAIEVXszCmcd1T5"; + private static String accessKeySecret = "2zHwciQXln8wExSEnkIYtRTSwLeRNd"; + + /** + * 短信访问域名 + */ + 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 templateCode SMS_153991546 + * @param sendDataMap + */ + public static String sendSms(String tel , String templateCode , 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/wzy-common/src/main/resources/META-INF/spring.factories b/wzy-common/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..1ace3ef --- /dev/null +++ b/wzy-common/src/main/resources/META-INF/spring.factories @@ -0,0 +1,3 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration = \ + com.wzy.common.config.RedisConfig,\ + com.wzy.common.utils.FastUtil diff --git a/wzy-gateway/.gitignore b/wzy-gateway/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/wzy-gateway/.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/wzy-gateway/pom.xml b/wzy-gateway/pom.xml new file mode 100644 index 0000000..a3b59a6 --- /dev/null +++ b/wzy-gateway/pom.xml @@ -0,0 +1,42 @@ + + + 4.0.0 + + com.wzy + wzy-11.1zk + 1.0-SNAPSHOT + + + wzy-gateway + + + 17 + 17 + UTF-8 + + + + + com.wzy + wzy-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/wzy-gateway/src/main/java/com/wzy/gateway/GatewayApplication.java b/wzy-gateway/src/main/java/com/wzy/gateway/GatewayApplication.java new file mode 100644 index 0000000..ffc34e9 --- /dev/null +++ b/wzy-gateway/src/main/java/com/wzy/gateway/GatewayApplication.java @@ -0,0 +1,11 @@ +package com.wzy.gateway; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class GatewayApplication { + public static void main(String[] args) { + SpringApplication.run(GatewayApplication.class); + } +} diff --git a/wzy-gateway/src/main/java/com/wzy/gateway/config/IgnoreWhiteConfig.java b/wzy-gateway/src/main/java/com/wzy/gateway/config/IgnoreWhiteConfig.java new file mode 100644 index 0000000..cff8f0b --- /dev/null +++ b/wzy-gateway/src/main/java/com/wzy/gateway/config/IgnoreWhiteConfig.java @@ -0,0 +1,32 @@ +package com.wzy.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/wzy-gateway/src/main/java/com/wzy/gateway/filters/AuthFilter.java b/wzy-gateway/src/main/java/com/wzy/gateway/filters/AuthFilter.java new file mode 100644 index 0000000..ee25396 --- /dev/null +++ b/wzy-gateway/src/main/java/com/wzy/gateway/filters/AuthFilter.java @@ -0,0 +1,62 @@ +package com.wzy.gateway.filters; + +import com.wzy.common.constants.TokenConstants; +import com.wzy.common.utils.JwtUtils; +import com.wzy.common.utils.StringUtils; +import com.wzy.gateway.config.IgnoreWhiteConfig; +import com.wzy.gateway.utils.GatewayUtils; +import org.springframework.beans.factory.annotation.Autowired; +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.RedisTemplate; +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; + +@Component +public class AuthFilter implements GlobalFilter, Ordered { + + @Autowired + private IgnoreWhiteConfig ignoreWhiteConfig; + + @Autowired + private RedisTemplate redisTemplate; + + @Override + public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { + List whites = ignoreWhiteConfig.getWhites(); + ServerHttpRequest request = exchange.getRequest(); + String path = request.getURI().getPath(); + if (StringUtils.matches(path,whites)) { + return chain.filter(exchange); + } + + String token = request.getHeaders().getFirst(TokenConstants.TOKEN); + if (StringUtils.isEmpty(token)) { + return GatewayUtils.errorResponse(exchange,"token不能为空"); + } + + try { + JwtUtils.parseToken(token); + } catch (Exception e) { + return GatewayUtils.errorResponse(exchange,"token不合法"); + } + + String userKey = JwtUtils.getUserKey(token); + Boolean hasKey = redisTemplate.hasKey(TokenConstants.LOGIN_TOKEN_KEY + userKey); + if (Boolean.FALSE.equals(hasKey)) { + return GatewayUtils.errorResponse(exchange,"token失效"); + } + + return chain.filter(exchange); + } + + @Override + public int getOrder() { + return 0; + } +} diff --git a/wzy-gateway/src/main/java/com/wzy/gateway/utils/GatewayUtils.java b/wzy-gateway/src/main/java/com/wzy/gateway/utils/GatewayUtils.java new file mode 100644 index 0000000..3ebb092 --- /dev/null +++ b/wzy-gateway/src/main/java/com/wzy/gateway/utils/GatewayUtils.java @@ -0,0 +1,98 @@ +package com.wzy.gateway.utils; + +import com.alibaba.fastjson.JSONObject; +import com.wzy.common.result.Result; +import com.wzy.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/wzy-gateway/src/main/resources/bootstrap.yml b/wzy-gateway/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..3435dc1 --- /dev/null +++ b/wzy-gateway/src/main/resources/bootstrap.yml @@ -0,0 +1,29 @@ +# Tomcat +server: + port: 18080 +# Spring +spring: + application: + # 应用名称 + name: wzy-gateway + profiles: + # 环境配置 + active: dev + main: + # 允许使用循环引用 + allow-circular-references: true + # 允许定义相同的bean对象 去覆盖原有的 + allow-bean-definition-overriding: true + cloud: + nacos: + discovery: + # 服务注册地址 + server-addr: 165.154.161.166:8848 + config: + # 配置中心地址 + server-addr: 165.154.161.166:8848 + # 配置文件格式 + file-extension: yml + # 共享配置 + shared-configs: + - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} diff --git a/wzy-models/.gitignore b/wzy-models/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/wzy-models/.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/wzy-models/pom.xml b/wzy-models/pom.xml new file mode 100644 index 0000000..a0636f5 --- /dev/null +++ b/wzy-models/pom.xml @@ -0,0 +1,26 @@ + + + 4.0.0 + + com.wzy + wzy-11.1zk + 1.0-SNAPSHOT + + + wzy-models + pom + + wzy-user + wzy-servers + wzy-sms + + + + 17 + 17 + UTF-8 + + + diff --git a/wzy-models/wzy-servers/.gitignore b/wzy-models/wzy-servers/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/wzy-models/wzy-servers/.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/wzy-models/wzy-servers/pom.xml b/wzy-models/wzy-servers/pom.xml new file mode 100644 index 0000000..023358d --- /dev/null +++ b/wzy-models/wzy-servers/pom.xml @@ -0,0 +1,54 @@ + + + 4.0.0 + + com.wzy + wzy-models + 1.0-SNAPSHOT + + + wzy-servers + + + 17 + 17 + UTF-8 + + + + + com.wzy + wzy-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 + + + diff --git a/wzy-models/wzy-servers/src/main/java/com/wzy/servers/ServersApplication.java b/wzy-models/wzy-servers/src/main/java/com/wzy/servers/ServersApplication.java new file mode 100644 index 0000000..74b09e4 --- /dev/null +++ b/wzy-models/wzy-servers/src/main/java/com/wzy/servers/ServersApplication.java @@ -0,0 +1,10 @@ +package com.wzy.servers; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class ServersApplication { + public static void main(String[] args) { + SpringApplication.run(ServersApplication.class); + } +} diff --git a/wzy-models/wzy-servers/src/main/java/com/wzy/servers/controller/ServersController.java b/wzy-models/wzy-servers/src/main/java/com/wzy/servers/controller/ServersController.java new file mode 100644 index 0000000..918e56b --- /dev/null +++ b/wzy-models/wzy-servers/src/main/java/com/wzy/servers/controller/ServersController.java @@ -0,0 +1,106 @@ +package com.wzy.servers.controller; + +import com.alibaba.fastjson.JSONObject; +import com.wzy.common.domain.Mine; +import com.wzy.common.domain.Rebate; +import com.wzy.common.domain.Servers; +import com.wzy.common.domain.User; +import com.wzy.common.domain.request.Req; +import com.wzy.common.result.Result; +import com.wzy.servers.service.ServersService; +import lombok.extern.log4j.Log4j2; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletRequest; +import java.util.List; + +@RestController +@Log4j2 +public class ServersController { + + private final ServersService serversService; + + private final HttpServletRequest request; + + public ServersController(ServersService serversService, HttpServletRequest request) { + this.serversService = serversService; + this.request = request; + } + + @PostMapping("/list") + public Result> list(@RequestBody Servers servers){ + return serversService.list(servers); + } + + @PostMapping("/shopServers") + public Result shopServers(@RequestBody Mine mine){ + log.info("功能:购买服务器,请求URI:{},请求方式:{},请求参数:{}",request.getRequestURI(), + request.getMethod(),mine); + Result result = serversService.shopServers(mine); + log.info("功能:购买服务器,请求URI:{},请求方式:{},响应结果:{}",request.getRequestURI(), + request.getMethod(), JSONObject.toJSONString(result)); + return result; + } + + @PostMapping("/updateUser") + public Result updateUser(@RequestBody User user){ + log.info("功能:更新用户信息,请求URI:{},请求方式:{},请求参数:{}",request.getRequestURI(), + request.getMethod(),user); + Result result = serversService.updateUser(user); + log.info("功能:更新用户信息,请求URI:{},请求方式:{},响应结果:{}",request.getRequestURI(), + request.getMethod(),JSONObject.toJSONString(result)); + return result; + } + + @PostMapping("/rebateAdd") + public Result rebateAdd(@RequestBody Rebate rebate){ + log.info("功能:返利记录,请求URI:{},请求方式:{},请求参数:{}",request.getRequestURI(), + request.getMethod(),rebate); + Result result = serversService.rebateAdd(rebate); + log.info("功能:返利记录,请求URI:{},请求方式:{},响应结果:{}",request.getRequestURI(), + request.getMethod(),JSONObject.toJSONString(result)); + return result; + } + + @PostMapping("/mineList") + public Result mineList(@RequestBody Req req){ + return serversService.mineList(req); + } + + @PostMapping("/updateStart") + public Result updateStart(@RequestBody Mine mine){ + return serversService.updateStart(mine); + } + + @PostMapping("/del/{mineId}") + public Result del(@PathVariable String mineId){ + return serversService.del(mineId); + } + + @PostMapping("/rebateAdd1") + public Result rebateAdd1(@RequestBody Rebate rebate){ + log.info("功能:返利记录,请求URI:{},请求方式:{},请求参数:{}",request.getRequestURI(), + request.getMethod(),rebate); + Result result = serversService.rebateAdd1(rebate); + log.info("功能:返利记录,请求URI:{},请求方式:{},响应结果:{}",request.getRequestURI(), + request.getMethod(),JSONObject.toJSONString(result)); + return result; + } + + @PostMapping("/updateUser1") + public Result updateUser1(@RequestBody User user){ + log.info("功能:更新用户信息,请求URI:{},请求方式:{},请求参数:{}",request.getRequestURI(), + request.getMethod(),user); + Result result = serversService.updateUser1(user); + log.info("功能:更新用户信息,请求URI:{},请求方式:{},响应结果:{}",request.getRequestURI(), + request.getMethod(),JSONObject.toJSONString(result)); + return result; + } + + @PostMapping("/upload") + public Result upload(@RequestParam("file")MultipartFile multipartFile){ + Result result = serversService.upload(multipartFile); + return result; + } +} diff --git a/wzy-models/wzy-servers/src/main/java/com/wzy/servers/mapper/ServersMapper.java b/wzy-models/wzy-servers/src/main/java/com/wzy/servers/mapper/ServersMapper.java new file mode 100644 index 0000000..ae587d3 --- /dev/null +++ b/wzy-models/wzy-servers/src/main/java/com/wzy/servers/mapper/ServersMapper.java @@ -0,0 +1,34 @@ +package com.wzy.servers.mapper; + +import com.wzy.common.domain.Mine; +import com.wzy.common.domain.Rebate; +import com.wzy.common.domain.Servers; +import com.wzy.common.domain.User; +import com.wzy.common.domain.request.Req; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +@Mapper +public interface ServersMapper { + List list(Servers servers); + + int shopServers(Mine mine); + + int updateUser(User user); + + int rebateAdd(Rebate rebate); + + List mineList(Req req); + + int updateStart(Mine mine); + + int del(String mineId); + + int rebateAdd1(Rebate rebate); + + int updateUser1(User user); + + List queryList(Req req); +} diff --git a/wzy-models/wzy-servers/src/main/java/com/wzy/servers/service/ServersService.java b/wzy-models/wzy-servers/src/main/java/com/wzy/servers/service/ServersService.java new file mode 100644 index 0000000..a4b98ac --- /dev/null +++ b/wzy-models/wzy-servers/src/main/java/com/wzy/servers/service/ServersService.java @@ -0,0 +1,33 @@ +package com.wzy.servers.service; + +import com.wzy.common.domain.Mine; +import com.wzy.common.domain.Rebate; +import com.wzy.common.domain.Servers; +import com.wzy.common.domain.User; +import com.wzy.common.domain.request.Req; +import com.wzy.common.result.Result; +import org.springframework.web.multipart.MultipartFile; + +import java.util.List; + +public interface ServersService { + Result> list(Servers servers); + + Result shopServers(Mine mine); + + Result updateUser(User user); + + Result rebateAdd(Rebate rebate); + + Result mineList(Req req); + + Result updateStart(Mine mine); + + Result del(String mineId); + + Result rebateAdd1(Rebate rebate); + + Result updateUser1(User user); + + Result upload(MultipartFile multipartFile); +} diff --git a/wzy-models/wzy-servers/src/main/java/com/wzy/servers/service/impl/ServersServiceImpl.java b/wzy-models/wzy-servers/src/main/java/com/wzy/servers/service/impl/ServersServiceImpl.java new file mode 100644 index 0000000..abceb89 --- /dev/null +++ b/wzy-models/wzy-servers/src/main/java/com/wzy/servers/service/impl/ServersServiceImpl.java @@ -0,0 +1,166 @@ +package com.wzy.servers.service.impl; + +import com.alibaba.fastjson.JSONObject; +import com.wzy.common.constants.TokenConstants; +import com.wzy.common.domain.Mine; +import com.wzy.common.domain.Rebate; +import com.wzy.common.domain.Servers; +import com.wzy.common.domain.User; +import com.wzy.common.domain.request.Req; +import com.wzy.common.result.Result; +import com.wzy.common.utils.FastUtil; +import com.wzy.common.utils.JwtUtils; +import com.wzy.servers.mapper.ServersMapper; +import com.wzy.servers.service.ServersService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletRequest; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +@Service +public class ServersServiceImpl implements ServersService { + + @Autowired + private ServersMapper serversMapper; + + @Autowired + private RedisTemplate redisTemplate; + + @Autowired + private HttpServletRequest request; + + @Autowired + private FastUtil fastUtil; + + @Override + public Result list(Servers servers) { + List list = serversMapper.list(servers); + return Result.success(list); + } + + @Override + public Result shopServers(Mine mine) { + User user = userInfo(); + if (!user.getUserName().equals(mine.getMineName())) { + if (user.getUserPrice()-mine.getServerPrice() >= 0) { + int i = serversMapper.shopServers(mine); + if (i > 0) { + return Result.success(i,"购买成功"); + } else { + return Result.error("请求失败"); + } + } else { + return Result.error("余额不足"); + } + } else { + return Result.error("自己不能推荐自己"); + } + } + + @Override + public Result updateUser(User user) { + int i = serversMapper.updateUser(user); + if (i > 0) { + return Result.success(i,"用户信息更新成功"); + } else { + return Result.error("请求失败"); + } + } + + @Override + public Result rebateAdd(Rebate rebate) { + int i = serversMapper.rebateAdd(rebate); + if (i > 0) { + return Result.success(i,"返利记录更新成功"); + } else { + return Result.error("请求失败"); + } + } + + @Override + public Result mineList(Req req) { + Set zset = redisTemplate.opsForZSet().reverseRange("hhh", 0, -1); + List list; + if (null == zset || zset.isEmpty()) { + list = serversMapper.queryList(req); + for (Mine mine : list) { + redisTemplate.opsForZSet().add("hhh",JSONObject.toJSONString(mine),mine.getServerPrice()); + } + zset = redisTemplate.opsForZSet().reverseRange("hhh",0,-1); + } else { + list = new ArrayList<>(); + for (String s : zset) { + list.add(JSONObject.parseObject(s,Mine.class)); + } + } + return Result.success(list); + } + + @Override + public Result updateStart(Mine mine) { + int i = serversMapper.updateStart(mine); + if (i > 0) { + return Result.success(i,"申请退款"); + } else { + return Result.error("请求失败"); + } + } + + @Override + public Result del(String mineId) { + int i = serversMapper.del(mineId); + if (i > 0) { + return Result.success(i,"退货成功"); + } else { + return Result.error("请求失败"); + } + } + + @Override + public Result rebateAdd1(Rebate rebate) { + int i = serversMapper.rebateAdd1(rebate); + if (i > 0) { + return Result.success(i,"返利记录更新成功"); + } else { + return Result.error("请求失败"); + } + } + + @Override + public Result updateUser1(User user) { + int i = serversMapper.updateUser1(user); + if (i > 0) { + return Result.success(i,"用户信息更新成功"); + } else { + return Result.error("请求失败"); + } + } + + @Override + public Result upload(MultipartFile multipartFile) { + String upload = null; + + try { + upload = fastUtil.upload(multipartFile); + if (null == upload) { + return Result.error("上传失败"); + } + } catch (Exception e) { + throw new RuntimeException(e); + } + return Result.success("http://165.154.161.166:8888/"+upload,"上传成功"); + } + + + public User userInfo() { + String token = request.getHeader(TokenConstants.TOKEN); + String userKey = JwtUtils.getUserKey(token); + String s = redisTemplate.opsForValue().get(TokenConstants.LOGIN_TOKEN_KEY + userKey); + return JSONObject.parseObject(s,User.class); + } +} diff --git a/wzy-models/wzy-servers/src/main/resources/bootstrap.yml b/wzy-models/wzy-servers/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..16a2e67 --- /dev/null +++ b/wzy-models/wzy-servers/src/main/resources/bootstrap.yml @@ -0,0 +1,42 @@ +# Tomcat +server: + port: 9002 +# Spring +spring: + main: + allow-circular-references: true + jackson: + date-format: yyyy-MM-dd HH:mm:ss + time-zone: GMT+8 + application: + # 应用名称 + name: wzy-servers + profiles: + # 环境配置 + active: dev + cloud: + nacos: + discovery: + # 服务注册地址 + server-addr: 165.154.161.166:8848 + config: + # 配置中心地址 + server-addr: 165.154.161.166:8848 + # 配置文件格式 + file-extension: yml + # 共享配置 + shared-configs: + - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} + +fdfs: + so-timeout: 1500 # socket 连接时长 + connect-timeout: 600 # 连接 tracker 服务器超时时长 + # 这两个是你服务器的 IP 地址,注意 23000 端口也要打开,阿里云服务器记得配置安全组。tracker 要和 stroage 服务进行交流 + tracker-list: 165.154.161.166:22122 + web-server-url: 165.154.161.166:8888 + pool: + jmx-enabled: false + # 生成缩略图 + thumb-image: + height: 500 + width: 500 diff --git a/wzy-models/wzy-servers/src/main/resources/mapper/ServersMapper.xml b/wzy-models/wzy-servers/src/main/resources/mapper/ServersMapper.xml new file mode 100644 index 0000000..81edda0 --- /dev/null +++ b/wzy-models/wzy-servers/src/main/resources/mapper/ServersMapper.xml @@ -0,0 +1,89 @@ + + + + + insert into a_mine (mine_date, server_name, server_desc, server_price, user_id, mine_name, start, rebate_scale, + rebate_price, pic) + values (now(), + #{serverName}, + #{serverDesc}, + #{serverPrice}, + #{userId}, + #{mineName}, + 1, + #{rebateScale}, + #{rebatePrice}, + #{pic}) + + + insert into a_rebate (rebate_date, server_name, server_price, user_id, rebate_scale, rebate_price, remark) + values ( + now(), + #{serverName}, + #{serverPrice}, + #{userId}, + #{rebateScale}, + #{rebatePrice}, + #{remark} + ); + + + insert into a_rebate( + rebate_date, + server_name, + server_price, + user_id, + rebate_scale, + rebate_price, + remark + ) + values ( + now(), + #{serverName}, + #{serverPrice}, + #{userId}, + #{rebateScale}, + #{rebatePrice}, + #{remark} + ) + + + update a_user set user_price=user_price-#{userPrice},rebate_num=rebate_num+1,rebate_price=rebate_price+#{rebatePrice},points=points+#{points},rebate_date=now() where user_id=#{userId} + + + update a_mine + set start = 2 + where mine_id=#{mineId} +# update a_mine set start=2 where mine_id=#{mineId} + + + update a_user set user_price=user_price+#{userPrice},rebate_num=rebate_num-1,rebate_price=rebate_price-#{rebatePrice},points=points-#{points},rebate_date=now() where user_id=#{userId} + + + delete from a_mine where mine_id=#{mineId} + + + + + + diff --git a/wzy-models/wzy-sms/.gitignore b/wzy-models/wzy-sms/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/wzy-models/wzy-sms/.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/wzy-models/wzy-sms/pom.xml b/wzy-models/wzy-sms/pom.xml new file mode 100644 index 0000000..996019a --- /dev/null +++ b/wzy-models/wzy-sms/pom.xml @@ -0,0 +1,37 @@ + + + 4.0.0 + + com.wzy + wzy-models + 1.0-SNAPSHOT + + + wzy-sms + + + 17 + 17 + UTF-8 + + + + + com.wzy + wzy-common + 1.0-SNAPSHOT + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-amqp + + + diff --git a/wzy-models/wzy-sms/src/main/resources/bootstrap.yml b/wzy-models/wzy-sms/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..605b11a --- /dev/null +++ b/wzy-models/wzy-sms/src/main/resources/bootstrap.yml @@ -0,0 +1,47 @@ +# Tomcat +server: + port: 9006 +# Spring +spring: + rabbitmq: + host: 165.154.161.166 + username: guest + password: guest + virtual-host: / + listener: + simple: + prefetch: 1 # 每次只能获取一条,处理完成才能获取下一条 + acknowledge-mode: manual # 设置消费端手动ack确认 + retry: + enabled: true # 是否支持重试 + # 生产者配置 + publisher-confirm-type: correlated #确认消息已发送到交换机(Exchange) + publisher-returns: true #确认消息已发送到队列(Queue) + redis: + host: 165.154.161.166 + port: 6379 + + main: + allow-circular-references: true + jackson: + date-format: yyyy-MM-dd HH:mm:ss + time-zone: GMT+8 + application: + # 应用名称 + name: wzy-sms + profiles: + # 环境配置 + active: dev + cloud: + nacos: + discovery: + # 服务注册地址 + server-addr: 165.154.161.166:8848 + config: + # 配置中心地址 + server-addr: 165.154.161.166:8848 + # 配置文件格式 + file-extension: yml + # 共享配置 + shared-configs: + - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} diff --git a/wzy-models/wzy-user/.gitignore b/wzy-models/wzy-user/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/wzy-models/wzy-user/.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/wzy-models/wzy-user/pom.xml b/wzy-models/wzy-user/pom.xml new file mode 100644 index 0000000..175bc7b --- /dev/null +++ b/wzy-models/wzy-user/pom.xml @@ -0,0 +1,54 @@ + + + 4.0.0 + + com.wzy + wzy-models + 1.0-SNAPSHOT + + + wzy-user + + + 17 + 17 + UTF-8 + + + + + com.wzy + wzy-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 + + + diff --git a/wzy-models/wzy-user/src/main/java/com/wzy/user/UserApplication.java b/wzy-models/wzy-user/src/main/java/com/wzy/user/UserApplication.java new file mode 100644 index 0000000..3c76be0 --- /dev/null +++ b/wzy-models/wzy-user/src/main/java/com/wzy/user/UserApplication.java @@ -0,0 +1,11 @@ +package com.wzy.user; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class UserApplication { + public static void main(String[] args) { + SpringApplication.run(UserApplication.class); + } +} diff --git a/wzy-models/wzy-user/src/main/java/com/wzy/user/controller/UserController.java b/wzy-models/wzy-user/src/main/java/com/wzy/user/controller/UserController.java new file mode 100644 index 0000000..9c63c52 --- /dev/null +++ b/wzy-models/wzy-user/src/main/java/com/wzy/user/controller/UserController.java @@ -0,0 +1,34 @@ +package com.wzy.user.controller; +import com.alibaba.fastjson.JSONObject; +import com.wzy.common.domain.User; +import com.wzy.common.result.Result; +import com.wzy.user.service.UserService; +import lombok.extern.log4j.Log4j2; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RestController; +import javax.servlet.http.HttpServletRequest; + +@RestController +@Log4j2 +public class UserController { + + @Autowired + private UserService userService; + + @Autowired + private HttpServletRequest request; + + @PostMapping("/login/{userName}") + public Result login(@PathVariable String userName){ + log.info("功能:登录,请求URI:{},请求方式:{},请求参数:{}",request.getRequestURI(), + request.getMethod(),userName); + User user = userService.login(userName); + Result result = Result.success(user); + log.info("功能:登录,请求URI:{},请求方式:{},响应结果:{}",request.getRequestURI(), + request.getMethod(), JSONObject.toJSONString(result)); + return result; + } + +} diff --git a/wzy-models/wzy-user/src/main/java/com/wzy/user/mapper/UserMapper.java b/wzy-models/wzy-user/src/main/java/com/wzy/user/mapper/UserMapper.java new file mode 100644 index 0000000..114040a --- /dev/null +++ b/wzy-models/wzy-user/src/main/java/com/wzy/user/mapper/UserMapper.java @@ -0,0 +1,9 @@ +package com.wzy.user.mapper; + +import com.wzy.common.domain.User; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface UserMapper { + User login(String userName); +} diff --git a/wzy-models/wzy-user/src/main/java/com/wzy/user/service/UserService.java b/wzy-models/wzy-user/src/main/java/com/wzy/user/service/UserService.java new file mode 100644 index 0000000..c410e78 --- /dev/null +++ b/wzy-models/wzy-user/src/main/java/com/wzy/user/service/UserService.java @@ -0,0 +1,6 @@ +package com.wzy.user.service; +import com.wzy.common.domain.User; + +public interface UserService { + User login(String userName); +} diff --git a/wzy-models/wzy-user/src/main/java/com/wzy/user/service/impl/UserServiceImpl.java b/wzy-models/wzy-user/src/main/java/com/wzy/user/service/impl/UserServiceImpl.java new file mode 100644 index 0000000..99b39a3 --- /dev/null +++ b/wzy-models/wzy-user/src/main/java/com/wzy/user/service/impl/UserServiceImpl.java @@ -0,0 +1,19 @@ +package com.wzy.user.service.impl; +import com.wzy.common.domain.User; +import com.wzy.user.mapper.UserMapper; +import com.wzy.user.service.UserService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class UserServiceImpl implements UserService { + + @Autowired + private UserMapper userMapper; + + @Override + public User login(String userName) { + return userMapper.login(userName); + } + +} diff --git a/wzy-models/wzy-user/src/main/resources/bootstrap.yml b/wzy-models/wzy-user/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..4c256c8 --- /dev/null +++ b/wzy-models/wzy-user/src/main/resources/bootstrap.yml @@ -0,0 +1,42 @@ +# Tomcat +server: + port: 9004 +# Spring +spring: + main: + allow-circular-references: true + jackson: + date-format: yyyy-MM-dd HH:mm:ss + time-zone: GMT+8 + application: + # 应用名称 + name: wzy-user + profiles: + # 环境配置 + active: dev + cloud: + nacos: + discovery: + # 服务注册地址 + server-addr: 165.154.161.166:8848 + config: + # 配置中心地址 + server-addr: 165.154.161.166:8848 + # 配置文件格式 + file-extension: yml + # 共享配置 + shared-configs: + - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} + +fdfs: + so-timeout: 1500 # socket 连接时长 + connect-timeout: 600 # 连接 tracker 服务器超时时长 + # 这两个是你服务器的 IP 地址,注意 23000 端口也要打开,阿里云服务器记得配置安全组。tracker 要和 stroage 服务进行交流 + tracker-list: 165.154.161.166:22122 + web-server-url: 165.154.161.166:8888 + pool: + jmx-enabled: false + # 生成缩略图 + thumb-image: + height: 500 + width: 500 diff --git a/wzy-models/wzy-user/src/main/resources/mapper/UserMapper.xml b/wzy-models/wzy-user/src/main/resources/mapper/UserMapper.xml new file mode 100644 index 0000000..a6087a7 --- /dev/null +++ b/wzy-models/wzy-user/src/main/resources/mapper/UserMapper.xml @@ -0,0 +1,9 @@ + + + + + +