初始化

master
86199 2023-11-06 08:56:18 +08:00
commit 41da1dbff9
66 changed files with 2549 additions and 0 deletions

38
.gitignore vendored 100644
View File

@ -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

8
.idea/.gitignore vendored 100644
View File

@ -0,0 +1,8 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="2103a@165.154.161.166" uuid="508a55cd-7734-4d19-b1af-591941457cae">
<driver-ref>mysql.8</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
<jdbc-url>jdbc:mysql://165.154.161.166:3306/2103a</jdbc-url>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
</component>
</project>

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/../../../dve/maven_repository_1/org/springframework/boot/spring-boot-starter-parent/2.6.2/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/wzy-auth/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/wzy-auth/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/wzy-common/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/wzy-common/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/wzy-gateway/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/wzy-gateway/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/wzy-models/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/wzy-models/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/wzy-models/wzy-servers/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/wzy-models/wzy-servers/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/wzy-models/wzy-sms/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/wzy-models/wzy-user/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/wzy-models/wzy-user/src/main/resources" charset="UTF-8" />
</component>
</project>

14
.idea/misc.xml 100644
View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="SqlDialectMappings">
<file url="PROJECT" dialect="MySQL" />
</component>
</project>

6
.idea/vcs.xml 100644
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

64
pom.xml 100644
View File

@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.wzy</groupId>
<artifactId>wzy-11.1zk</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>wzy-common</module>
<module>wzy-auth</module>
<module>wzy-gateway</module>
<module>wzy-models</module>
</modules>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<!-- 规定SpringBoot版本 -->
<!-- 父级pom文件 主要用于规定项目依赖的各个版本,用于进行项目版本约束 -->
<parent>
<artifactId>spring-boot-starter-parent</artifactId>
<groupId>org.springframework.boot</groupId>
<version>2.6.2</version>
<relativePath/>
</parent>
<!-- 依赖声明 -->
<dependencyManagement>
<dependencies>
<!-- SpringCloud 微服务 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>2021.0.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- SpringCloud Alibaba 微服务 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2021.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- Alibaba Nacos 配置 -->
<dependency>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
<version>2.0.4</version>
</dependency>
<!-- 公共模块 -->
<dependency>
<groupId>com.wzy</groupId>
<artifactId>wzy-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>

38
wzy-auth/.gitignore vendored 100644
View File

@ -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

31
wzy-auth/pom.xml 100644
View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.wzy</groupId>
<artifactId>wzy-11.1zk</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>wzy-auth</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- 项目公共 依赖 -->
<dependency>
<groupId>com.wzy</groupId>
<artifactId>wzy-common</artifactId>
</dependency>
<!-- SpringBoot Web-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -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);
}
}

View File

@ -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<JwtResponse> login(@RequestBody LoginRequest loginRequest){
log.info("功能:登录,请求URI:{},请求方式:{},请求参数:{}",request.getRequestURI(),
request.getMethod(),loginRequest);
Result<JwtResponse> result = authService.login(loginRequest);
log.info("功能:登录,请求URI:{},请求方式:{},响应结果:{}",request.getRequestURI(),
request.getMethod(), JSONObject.toJSONString(result));
return result;
}
@GetMapping("/user/info")
public Result<User> userInfo(){
User user = authService.userInfo();
return Result.success(user);
}
@PostMapping("/logout")
public Result logout(){
authService.logout();
return Result.success();
}
}

View File

@ -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<User> login(@PathVariable String userName);
}

View File

@ -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<JwtResponse> login(LoginRequest loginRequest);
User userInfo();
void logout();
}

View File

@ -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<String,String> redisTemplate;
@Autowired
private HttpServletRequest request;
@Override
public Result<JwtResponse> login(LoginRequest loginRequest) {
Result<User> 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<String, Object> 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);
}
}

View File

@ -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}

38
wzy-common/.gitignore vendored 100644
View File

@ -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

116
wzy-common/pom.xml 100644
View File

@ -0,0 +1,116 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.wzy</groupId>
<artifactId>wzy-11.1zk</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>wzy-common</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- bootstrap 启动器 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
<!-- SpringCloud Alibaba Nacos -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!-- SpringCloud Alibaba Nacos Config -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<!-- SpringCloud Alibaba Sentinel -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<!-- 负载均衡-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>
<!-- SpringCloud Openfeign -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<!-- JWT -->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.9.1</version>
</dependency>
<!-- Alibaba Fastjson -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.80</version>
</dependency>
<!-- SpringBoot Boot Redis -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!-- Hibernate Validator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<!-- Apache Lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<!-- lombok依赖 -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<!-- hutool -->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.3</version>
</dependency>
<!-- 阿里大鱼 -->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>dysmsapi20170525</artifactId>
<version>2.0.1</version>
</dependency>
<!-- oss 图片上传 -->
<dependency>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId>
<version>3.12.0</version>
</dependency>
<!-- rabbitMQ -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<!-- &lt;!&ndash;mq 依赖&ndash;&gt;
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>-->
<dependency>
<groupId>com.github.tobato</groupId>
<artifactId>fastdfs-client</artifactId>
<version>1.26.5</version>
</dependency>
</dependencies>
</project>

View File

@ -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<String, Object> redisTemplate(RedisConnectionFactory factory) {
RedisTemplate<String, Object> 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;
}
}

View File

@ -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 = "操作异常";
}

View File

@ -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";
}

View File

@ -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";
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -0,0 +1,9 @@
package com.wzy.common.domain.request;
import lombok.Data;
@Data
public class LoginRequest {
private String userName;
private String userPwd;
}

View File

@ -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;
}

View File

@ -0,0 +1,9 @@
package com.wzy.common.domain.response;
import lombok.Data;
@Data
public class JwtResponse {
private String token;
private String expireTime;
}

View File

@ -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<T> implements Serializable {
/**
*
*/
private long total;
/**
*
*/
private List<T> list;
public PageResult() {
}
public PageResult(long total, List<T> list) {
this.total = total;
this.list = list;
}
public static <T> PageResult<T> toPageResult(long total, List<T> list){
return new PageResult(total , list);
}
public static <T> Result<PageResult<T>> toResult(long total, List<T> list){
return Result.success(PageResult.toPageResult(total,list));
}
}

View File

@ -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<T> 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 <T> Result<T> success() {
return restResult(null, SUCCESS, Constants.SUCCESS_MSG);
}
public static <T> Result<T> success(T data) {
return restResult(data, SUCCESS, Constants.SUCCESS_MSG);
}
public static <T> Result<T> success(T data, String msg) {
return restResult(data, SUCCESS, msg);
}
public static <T> Result<T> error() {
return restResult(null, FAIL, Constants.ERROR_MSG);
}
public static <T> Result<T> error(String msg) {
return restResult(null, FAIL, msg);
}
public static <T> Result<T> error(T data) {
return restResult(data, FAIL, Constants.ERROR_MSG);
}
public static <T> Result<T> error(T data, String msg) {
return restResult(data, FAIL, msg);
}
public static <T> Result<T> error(int code, String msg) {
return restResult(null, code, msg);
}
private static <T> Result<T> restResult(T data, int code, String msg) {
Result<T> apiResult = new Result<>();
apiResult.setCode(code);
apiResult.setData(data);
apiResult.setMsg(msg);
return apiResult;
}
}

View File

@ -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 "删除成功";
}
}

View File

@ -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<String, Object> 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();
}
}

View File

@ -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 ListSetQueue
*
* @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<String> 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);
}
}

View File

@ -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 {
/**
* AccessKeyaccessKeySecretAPI访
*/
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<String,String> 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());
}
}

View File

@ -0,0 +1,3 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration = \
com.wzy.common.config.RedisConfig,\
com.wzy.common.utils.FastUtil

38
wzy-gateway/.gitignore vendored 100644
View File

@ -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

View File

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.wzy</groupId>
<artifactId>wzy-11.1zk</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>wzy-gateway</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- 公共模块 -->
<dependency>
<groupId>com.wzy</groupId>
<artifactId>wzy-common</artifactId>
</dependency>
<!-- 网关依赖 -->
<!-- SpringCloud Gateway -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<!-- SpringCloud Alibaba Sentinel Gateway -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-sentinel-gateway</artifactId>
</dependency>
<!-- 引入阿里巴巴sentinel限流 依赖-->
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-spring-cloud-gateway-adapter</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -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);
}
}

View File

@ -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<String> whites = new ArrayList<>();
public void setWhites(List<String> whites) {
log.info("加载网关路径白名单:{}", JSONObject.toJSONString(whites));
this.whites = whites;
}
}

View File

@ -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<String,String> redisTemplate;
@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
List<String> 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;
}
}

View File

@ -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<Void> 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<Void> 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));
}
}

View File

@ -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}

38
wzy-models/.gitignore vendored 100644
View File

@ -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

26
wzy-models/pom.xml 100644
View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.wzy</groupId>
<artifactId>wzy-11.1zk</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>wzy-models</artifactId>
<packaging>pom</packaging>
<modules>
<module>wzy-user</module>
<module>wzy-servers</module>
<module>wzy-sms</module>
</modules>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

View File

@ -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

View File

@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.wzy</groupId>
<artifactId>wzy-models</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>wzy-servers</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- 系统公共 依赖 -->
<dependency>
<groupId>com.wzy</groupId>
<artifactId>wzy-common</artifactId>
</dependency>
<!-- SpringBoot Web-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Druid -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.2.8</version>
</dependency>
<!-- Mysql Connector -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- Mybatis 依赖配置 -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.2</version>
</dependency>
<!-- Pagehelper -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.4.1</version>
</dependency>
</dependencies>
</project>

View File

@ -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);
}
}

View File

@ -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<Servers>> 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;
}
}

View File

@ -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<Servers> list(Servers servers);
int shopServers(Mine mine);
int updateUser(User user);
int rebateAdd(Rebate rebate);
List<Mine> mineList(Req req);
int updateStart(Mine mine);
int del(String mineId);
int rebateAdd1(Rebate rebate);
int updateUser1(User user);
List<Mine> queryList(Req req);
}

View File

@ -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>> 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);
}

View File

@ -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<String,String> redisTemplate;
@Autowired
private HttpServletRequest request;
@Autowired
private FastUtil fastUtil;
@Override
public Result list(Servers servers) {
List<Servers> 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<String> zset = redisTemplate.opsForZSet().reverseRange("hhh", 0, -1);
List<Mine> 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);
}
}

View File

@ -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

View File

@ -0,0 +1,89 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.wzy.servers.mapper.ServersMapper">
<insert id="shopServers">
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>
<insert id="rebateAdd">
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>
<insert id="rebateAdd1">
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>
<update id="updateUser">
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>
<update id="updateStart">
update a_mine
set start = 2
where mine_id=#{mineId}
# update a_mine set start=2 where mine_id=#{mineId}
</update>
<update id="updateUser1">
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>
<delete id="del">
delete from a_mine where mine_id=#{mineId}
</delete>
<select id="list" resultType="com.wzy.common.domain.Servers">
select *
from a_server
</select>
<select id="mineList" resultType="com.wzy.common.domain.Mine">
select m.*,u.user_name,u.role_id
from a_mine m left join a_user u on m.user_id=u.user_id
<where>
<if test="null!=start">
and mine_date >= #{start}
</if>
<if test="null!=end">
and mine_date &lt;= #{end}
</if>
<if test="roleId==1">
and u.user_id=#{userId}
</if>
</where>
</select>
<select id="queryList" resultType="com.wzy.common.domain.Mine">
select m.*,u.user_name,u.role_id
from a_mine m left join a_user u on m.user_id=u.user_id
</select>
</mapper>

38
wzy-models/wzy-sms/.gitignore vendored 100644
View File

@ -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

View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.wzy</groupId>
<artifactId>wzy-models</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>wzy-sms</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- 系统公共 依赖 -->
<dependency>
<groupId>com.wzy</groupId>
<artifactId>wzy-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- SpringBoot Web-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- mq -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -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}

38
wzy-models/wzy-user/.gitignore vendored 100644
View File

@ -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

View File

@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.wzy</groupId>
<artifactId>wzy-models</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>wzy-user</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- 系统公共 依赖 -->
<dependency>
<groupId>com.wzy</groupId>
<artifactId>wzy-common</artifactId>
</dependency>
<!-- SpringBoot Web-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Druid -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.2.8</version>
</dependency>
<!-- Mysql Connector -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- Mybatis 依赖配置 -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.2</version>
</dependency>
<!-- Pagehelper -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.4.1</version>
</dependency>
</dependencies>
</project>

View File

@ -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);
}
}

View File

@ -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<User> login(@PathVariable String userName){
log.info("功能:登录,请求URI:{},请求方式:{},请求参数:{}",request.getRequestURI(),
request.getMethod(),userName);
User user = userService.login(userName);
Result<User> result = Result.success(user);
log.info("功能:登录,请求URI:{},请求方式:{},响应结果:{}",request.getRequestURI(),
request.getMethod(), JSONObject.toJSONString(result));
return result;
}
}

View File

@ -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);
}

View File

@ -0,0 +1,6 @@
package com.wzy.user.service;
import com.wzy.common.domain.User;
public interface UserService {
User login(String userName);
}

View File

@ -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);
}
}

View File

@ -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

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.wzy.user.mapper.UserMapper">
<select id="login" resultType="com.wzy.common.domain.User">
select *
from a_user where user_name=#{userName}
</select>
</mapper>