初始化 1.0.0
commit
525a40c2b0
|
@ -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
|
|
@ -0,0 +1,8 @@
|
||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectDictionaryState">
|
||||||
|
<dictionary name="Nian" />
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,20 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding" defaultCharsetForPropertiesFiles="UTF-8">
|
||||||
|
<file url="file://$PROJECT_DIR$/brook-auth/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/brook-common/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/brook-common/src/main/resources" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/brook-gatewat/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/brook-gateway/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/brook-modules/brook-brand/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/brook-modules/brook-cart/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/brook-modules/brook-es/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/brook-modules/brook-goods/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/brook-modules/brook-single/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/brook-modules/brook-system/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/brook-modules/src/main/java" 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="PROJECT" charset="UTF-8" />
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,19 @@
|
||||||
|
<?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>
|
||||||
|
<option name="ignoredFiles">
|
||||||
|
<set>
|
||||||
|
<option value="$PROJECT_DIR$/brook-gatewat/pom.xml" />
|
||||||
|
</set>
|
||||||
|
</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>
|
|
@ -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>
|
|
@ -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.brook</groupId>
|
||||||
|
<artifactId>brook_week3</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>brook-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.brook</groupId>
|
||||||
|
<artifactId>brook-common</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.brook.auth;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook.auth
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:AuthApplication
|
||||||
|
* @Date 2024/3/12:9:43
|
||||||
|
*/
|
||||||
|
@SpringBootApplication
|
||||||
|
@EnableFeignClients(basePackages = "com.brook.**")
|
||||||
|
public class AuthApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(AuthApplication.class,args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,67 @@
|
||||||
|
package com.brook.auth.controller;
|
||||||
|
|
||||||
|
import com.brook.auth.service.AuthService;
|
||||||
|
import com.brook.common.domain.UserInfo;
|
||||||
|
import com.brook.common.domain.request.auth.LoginAuth;
|
||||||
|
import com.brook.common.domain.response.auth.LoginAuthResp;
|
||||||
|
import com.brook.common.result.Result;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook.auth.controller
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:AuthController
|
||||||
|
* @Date 2024/3/12:9:26
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/auth")
|
||||||
|
public class AuthController {
|
||||||
|
|
||||||
|
private final AuthService authService;
|
||||||
|
|
||||||
|
public AuthController(AuthService authService) {
|
||||||
|
this.authService = authService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/sendCode")
|
||||||
|
public Result<String> sendCode(@RequestParam String phone){
|
||||||
|
|
||||||
|
if(phone==null || phone.equals("")){
|
||||||
|
return Result.error(
|
||||||
|
"手机号不能为空"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.success(
|
||||||
|
authService.sendCode(phone)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/login")
|
||||||
|
public Result<LoginAuthResp> login(@RequestBody LoginAuth loginAuth){
|
||||||
|
|
||||||
|
return Result.success(
|
||||||
|
authService.login(loginAuth)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/info")
|
||||||
|
public Result<UserInfo> getInfo(){
|
||||||
|
return authService.getInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.brook.auth.service;
|
||||||
|
|
||||||
|
import com.brook.common.domain.UserInfo;
|
||||||
|
import com.brook.common.domain.request.auth.LoginAuth;
|
||||||
|
import com.brook.common.domain.response.auth.LoginAuthResp;
|
||||||
|
import com.brook.common.result.Result;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook.auth.service
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:AuthService
|
||||||
|
* @Date 2024/3/12:9:26
|
||||||
|
*/
|
||||||
|
public interface AuthService {
|
||||||
|
String sendCode(String phone);
|
||||||
|
|
||||||
|
LoginAuthResp login(LoginAuth loginAuth);
|
||||||
|
|
||||||
|
Result<UserInfo> getInfo();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,119 @@
|
||||||
|
package com.brook.auth.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.RandomUtil;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.brook.auth.service.AuthService;
|
||||||
|
import com.brook.common.constants.JwtConstants;
|
||||||
|
import com.brook.common.constants.TokenConstants;
|
||||||
|
import com.brook.common.domain.UserInfo;
|
||||||
|
import com.brook.common.domain.request.auth.LoginAuth;
|
||||||
|
import com.brook.common.domain.response.auth.LoginAuthResp;
|
||||||
|
import com.brook.common.redis.RedisCache;
|
||||||
|
import com.brook.common.remote.RemoteUserInfoService;
|
||||||
|
import com.brook.common.result.Result;
|
||||||
|
import com.brook.common.utils.JwtUtils;
|
||||||
|
import io.jsonwebtoken.lang.Assert;
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook.auth.service.impl
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:AuthServiceImpl
|
||||||
|
* @Date 2024/3/12:9:26
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class AuthServiceImpl implements AuthService {
|
||||||
|
|
||||||
|
|
||||||
|
private final RemoteUserInfoService remoteUserInfoService;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private final HttpServletRequest request;
|
||||||
|
private final RedisCache redisCache;
|
||||||
|
|
||||||
|
public AuthServiceImpl(RemoteUserInfoService remoteUserInfoService, HttpServletRequest request, RedisCache redisCache) {
|
||||||
|
this.remoteUserInfoService = remoteUserInfoService;
|
||||||
|
|
||||||
|
this.request = request;
|
||||||
|
this.redisCache = redisCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String sendCode(String phone) {
|
||||||
|
|
||||||
|
Result<UserInfo> userInfoResult = remoteUserInfoService.findByPhone(phone);
|
||||||
|
|
||||||
|
UserInfo userInfo = userInfoResult.getData();
|
||||||
|
|
||||||
|
Assert.notNull(userInfo,"手机号不是系统用户");
|
||||||
|
|
||||||
|
String code = RandomUtil.randomNumbers(4);
|
||||||
|
|
||||||
|
System.out.println("验证码是:"+code);
|
||||||
|
|
||||||
|
|
||||||
|
redisCache.setCacheObject(phone,code,1L,TimeUnit.MINUTES);
|
||||||
|
|
||||||
|
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LoginAuthResp login(LoginAuth loginAuth) {
|
||||||
|
|
||||||
|
Result<UserInfo> userInfoResult = remoteUserInfoService.findByPhone(loginAuth.getPhone());
|
||||||
|
Assert.isTrue(userInfoResult.isSuccess(),"登陆失败");
|
||||||
|
UserInfo userInfo = userInfoResult.getData();
|
||||||
|
Assert.notNull(userInfo,"手机号不是系统用户");
|
||||||
|
|
||||||
|
Assert.isTrue(redisCache.hasKey(loginAuth.getPhone()),"验证码已经过期");
|
||||||
|
|
||||||
|
String code = (String) redisCache.getCacheObject(loginAuth.getPhone());
|
||||||
|
Assert.isTrue(
|
||||||
|
loginAuth.getCode().equals(code),
|
||||||
|
"验证码错误"
|
||||||
|
);
|
||||||
|
|
||||||
|
String userKey = UUID.randomUUID().toString().replace("_", "");
|
||||||
|
HashMap<String, Object> map = new HashMap<>();
|
||||||
|
map.put(JwtConstants.USER_KEY,userKey);
|
||||||
|
map.put(JwtConstants.DETAILS_USER_ID,userInfo.getId());
|
||||||
|
map.put(JwtConstants.DETAILS_USERNAME,userInfo.getUserName());
|
||||||
|
|
||||||
|
String token = JwtUtils.createToken(map);
|
||||||
|
|
||||||
|
redisCache.setCacheObject(
|
||||||
|
TokenConstants.LOGIN_TOKEN_KEY+userKey,
|
||||||
|
JSON.toJSONString(userInfo),
|
||||||
|
TokenConstants.EXPIRATION,
|
||||||
|
TimeUnit.MINUTES
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
return LoginAuthResp.builder()
|
||||||
|
.token(token)
|
||||||
|
.outTime(TokenConstants.EXPIRATION)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result<UserInfo> getInfo() {
|
||||||
|
|
||||||
|
String token = request.getHeader(JwtConstants.USER_KEY);
|
||||||
|
|
||||||
|
String userKey = redisCache.getCacheObject(TokenConstants.LOGIN_TOKEN_KEY + token);
|
||||||
|
|
||||||
|
UserInfo userInfo = JSON.parseObject(userKey, UserInfo.class);
|
||||||
|
|
||||||
|
return Result.success(userInfo);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
# Tomcat
|
||||||
|
server:
|
||||||
|
port: 9001
|
||||||
|
# Spring
|
||||||
|
spring:
|
||||||
|
main:
|
||||||
|
allow-circular-references: true
|
||||||
|
jackson:
|
||||||
|
date-format: yyyy-MM-dd HH:mm:ss
|
||||||
|
time-zone: GMT+8
|
||||||
|
application:
|
||||||
|
# 应用名称
|
||||||
|
name: brook-auth
|
||||||
|
profiles:
|
||||||
|
# 环境配置
|
||||||
|
active: dev
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
discovery:
|
||||||
|
# 服务注册地址
|
||||||
|
server-addr: 49.232.227.52:8848
|
||||||
|
namespace: 4cf48ba0-2ae3-4427-8892-ca501c8b740e
|
||||||
|
config:
|
||||||
|
# 配置中心地址
|
||||||
|
server-addr: 49.232.227.52:8848
|
||||||
|
# 配置文件格式
|
||||||
|
file-extension: yml
|
||||||
|
# 共享配置
|
||||||
|
shared-configs:
|
||||||
|
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||||
|
namespace: 4cf48ba0-2ae3-4427-8892-ca501c8b740e
|
|
@ -0,0 +1,170 @@
|
||||||
|
<?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.brook</groupId>
|
||||||
|
<artifactId>brook_week3</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>brook-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>
|
||||||
|
|
||||||
|
<!-- oss 图片上传 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.aliyun.oss</groupId>
|
||||||
|
<artifactId>aliyun-sdk-oss</artifactId>
|
||||||
|
<version>3.12.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.tobato</groupId>
|
||||||
|
<artifactId>fastdfs-client</artifactId>
|
||||||
|
<version>1.26.5</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--redisson最强分布式锁-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.redisson</groupId>
|
||||||
|
<artifactId>redisson</artifactId>
|
||||||
|
<version>3.16.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 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>
|
||||||
|
<!-- FastJson2 json工具 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.fastjson2</groupId>
|
||||||
|
<artifactId>fastjson2</artifactId>
|
||||||
|
<version>2.0.42</version>
|
||||||
|
</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>
|
||||||
|
<version>8.0.33</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- Mybatis-plus 配置 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||||
|
<version>3.5.4.1</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- Mybatis 依赖配置 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mybatis.spring.boot</groupId>
|
||||||
|
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||||
|
<version>2.2.2</version>
|
||||||
|
</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>
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.hutool</groupId>
|
||||||
|
<artifactId>hutool-all</artifactId>
|
||||||
|
<version>5.8.22</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- SpringBoot 测试框架 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--短信依赖 5条依赖-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
|
<artifactId>httpclient</artifactId>
|
||||||
|
<version>4.2.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
|
<artifactId>httpcore</artifactId>
|
||||||
|
<version>4.2.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-lang</groupId>
|
||||||
|
<artifactId>commons-lang</artifactId>
|
||||||
|
<version>2.6</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.eclipse.jetty</groupId>
|
||||||
|
<artifactId>jetty-util</artifactId>
|
||||||
|
<version>9.3.7.v20160115</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,30 @@
|
||||||
|
package com.brook.common.config;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.DbType;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DongZl
|
||||||
|
* @description: Mybatis-Plus配置
|
||||||
|
* @Date 2024-1-10 下午 05:12
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class MybatisPlusConfig {
|
||||||
|
|
||||||
|
public MybatisPlusConfig () {
|
||||||
|
System.out.println("初始化-----------");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加分页插件
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||||
|
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||||
|
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
|
||||||
|
return interceptor;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package com.brook.common.constants;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName Constants
|
||||||
|
* @Description 系统常量
|
||||||
|
* @Author ChenLong
|
||||||
|
* @Date 2023/2/23 16:04
|
||||||
|
* @Version 1.0
|
||||||
|
*/
|
||||||
|
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 = "操作异常";
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.brook.common.constants;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook.common.constants
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:GoodsConstants
|
||||||
|
* @Date 2024/3/12:10:09
|
||||||
|
*/
|
||||||
|
public class GoodsConstants {
|
||||||
|
|
||||||
|
public final static String GOODS_NAME = "brook-goods";
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
package com.brook.common.constants;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName JwtConstants
|
||||||
|
* @Description Jwt常量
|
||||||
|
* @Author ChenLong
|
||||||
|
* @Date 2023/2/23 16:07
|
||||||
|
* @Version 1.0
|
||||||
|
*/
|
||||||
|
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";
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package com.brook.common.constants;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName:
|
||||||
|
* @Description:
|
||||||
|
* @Author: zhuwenqiang
|
||||||
|
* @Date: 2023/10/25
|
||||||
|
*/
|
||||||
|
public class LoginConstants {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录成功
|
||||||
|
*/
|
||||||
|
public static final int LOGIN_SUCCESS = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录失败
|
||||||
|
*/
|
||||||
|
public static final int LOGIN_FAIL = 2;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
package com.brook.common.constants;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName:
|
||||||
|
* @Description:
|
||||||
|
* @Author: zhuwenqiang
|
||||||
|
* @Date: 2023/10/25
|
||||||
|
*/
|
||||||
|
public class MQQueueNameConstants {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录日志队列名称
|
||||||
|
*/
|
||||||
|
public static final String LOGIN_LOG_QUEUE_NAME = "login_log_queue_name";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加
|
||||||
|
*/
|
||||||
|
public static final String ADD_GOODS_ES_QUEUE_NAME = "add_goods_es_queue_name";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计网站每日访问人次
|
||||||
|
*/
|
||||||
|
public static final String WEBSITE_STATS_QUEUE = "website_stats_queue";
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
package com.brook.common.constants;
|
||||||
|
|
||||||
|
|
||||||
|
public class RabbitMqConstants {
|
||||||
|
public static final String SEND_CODE="send_code";
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package com.brook.common.constants;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName:
|
||||||
|
* @Description:
|
||||||
|
* @Author: zhuwenqiang
|
||||||
|
* @Date: 2023/10/18
|
||||||
|
*/
|
||||||
|
public class RoleConstants {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 管理员
|
||||||
|
*/
|
||||||
|
public static final int ADMIN = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 普通用户
|
||||||
|
*/
|
||||||
|
public static final int ORDINARY_USERS = 2;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
package com.brook.common.constants;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName TokenConstants
|
||||||
|
* @Description 令牌常量
|
||||||
|
* @Author ChenLong
|
||||||
|
* @Date 2023/2/23 16:08
|
||||||
|
* @Version 1.0
|
||||||
|
*/
|
||||||
|
public class TokenConstants {
|
||||||
|
/**
|
||||||
|
* 缓存有效期,默认720(分钟)
|
||||||
|
*/
|
||||||
|
public final static long EXPIRATION = 1800;
|
||||||
|
/**
|
||||||
|
* 缓存刷新时间,默认120(分钟)
|
||||||
|
*/
|
||||||
|
public final static long REFRESH_TIME = 120;
|
||||||
|
/**
|
||||||
|
* 权限缓存前缀
|
||||||
|
*/
|
||||||
|
public final static String LOGIN_TOKEN_KEY = "login_tokens:";
|
||||||
|
/**
|
||||||
|
* token标识
|
||||||
|
*/
|
||||||
|
public static final String TOKEN = "token";
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.brook.common.constants;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook.common.constants
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:UserInfoConstants
|
||||||
|
* @Date 2024/3/12:9:23
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class UserInfoConstants{
|
||||||
|
|
||||||
|
public static final String USER_INFO = "brook-system";
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
package com.brook.common.domain;
|
||||||
|
|
||||||
|
import com.alibaba.nacos.shaded.org.checkerframework.checker.initialization.qual.NotOnlyInitialized;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook.common.domain
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:Address
|
||||||
|
* @Date 2024/3/12:13:09
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class Address {
|
||||||
|
|
||||||
|
private Long addressId;
|
||||||
|
private Long userId;
|
||||||
|
private String addressName;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
package com.brook.common.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook.common.domain
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:Brand
|
||||||
|
* @Date 2024/3/12:11:43
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@TableName(value = "brand")
|
||||||
|
@Builder
|
||||||
|
public class Brand {
|
||||||
|
|
||||||
|
@TableField(value = "brand_id")
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
private Long brandId;
|
||||||
|
@TableField(value = "brand_name")
|
||||||
|
private String brandName;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
package com.brook.common.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook.common.domain
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:Cart
|
||||||
|
* @Date 2024/3/12:10:52
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
@TableName(value = "cart")
|
||||||
|
public class Cart {
|
||||||
|
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
@TableField(value = "cart_id")
|
||||||
|
private Long cartId;
|
||||||
|
|
||||||
|
@TableField(value = "goods_id")
|
||||||
|
private Long goodsId;
|
||||||
|
|
||||||
|
@TableField(value = "goods_name")
|
||||||
|
private String goodsName;
|
||||||
|
|
||||||
|
@TableField(value = "brand_name")
|
||||||
|
private String brandName;
|
||||||
|
@TableField(value = "goods_price")
|
||||||
|
private BigDecimal goodsPrice;
|
||||||
|
|
||||||
|
private Integer total;
|
||||||
|
|
||||||
|
@TableField(value = "total_price")
|
||||||
|
private BigDecimal totalPrice;
|
||||||
|
|
||||||
|
private Integer isTrue;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
package com.brook.common.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook.common.domain
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:Goods
|
||||||
|
* @Date 2024/3/12:10:02
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
@TableName(value = "goods")
|
||||||
|
public class Goods {
|
||||||
|
|
||||||
|
private Long goodsId;
|
||||||
|
|
||||||
|
private String goodsName;
|
||||||
|
|
||||||
|
private Integer brandId;
|
||||||
|
|
||||||
|
private String brandName;
|
||||||
|
|
||||||
|
private String goodsInfo;
|
||||||
|
|
||||||
|
private BigDecimal goodsPrice;
|
||||||
|
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT-8")
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
private Integer isTrue;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
package com.brook.common.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook.common.domain
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:Single
|
||||||
|
* @Date 2024/3/12:13:29
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
@TableName(value = "single")
|
||||||
|
public class Single {
|
||||||
|
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
@TableField(value = "single_id")
|
||||||
|
private Long singleId;
|
||||||
|
@TableField(value = "goods_id")
|
||||||
|
private Long goodsId;
|
||||||
|
private Integer total;
|
||||||
|
@TableField(value = "total_price")
|
||||||
|
private BigDecimal totalPrice;
|
||||||
|
@TableField(value = "user_id")
|
||||||
|
private Long userId;
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT-8")
|
||||||
|
@TableField(value = "create_time")
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
package com.brook.common.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook.common.domain
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:UserInfo
|
||||||
|
* @Date 2024/3/12:9:19
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
@TableName(value = "user_info")
|
||||||
|
public class UserInfo {
|
||||||
|
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private String phone;
|
||||||
|
|
||||||
|
@TableField(value = "user_name")
|
||||||
|
private String userName;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.brook.common.domain.request.address;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook.common.domain.request.address
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:AddressReq
|
||||||
|
* @Date 2024/3/12:13:46
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class AddressReq {
|
||||||
|
|
||||||
|
private Long userId;
|
||||||
|
private String addressName;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.brook.common.domain.request.auth;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook.common.domain.request.auth
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:LoginAuth
|
||||||
|
* @Date 2024/3/12:9:34
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class LoginAuth {
|
||||||
|
|
||||||
|
private String phone;
|
||||||
|
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
package com.brook.common.domain.request.cart;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook.common.domain.request.cart
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:CartAdd
|
||||||
|
* @Date 2024/3/12:12:21
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class CartAddReq {
|
||||||
|
|
||||||
|
private Long goodsId;
|
||||||
|
@TableField(value = "goods_name")
|
||||||
|
private String goodsName;
|
||||||
|
|
||||||
|
@TableField(value = "brand_name")
|
||||||
|
private String brandName;
|
||||||
|
@TableField(value = "goods_price")
|
||||||
|
private BigDecimal goodsPrice;
|
||||||
|
|
||||||
|
private Integer total;
|
||||||
|
|
||||||
|
@TableField(value = "total_price")
|
||||||
|
private BigDecimal totalPrice;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.brook.common.domain.request.es;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook.common.domain.request.es
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:GoodsRwq
|
||||||
|
* @Date 2024/3/12:10:13
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class GoodsReq {
|
||||||
|
|
||||||
|
private String goodsName;
|
||||||
|
private Integer brandId;
|
||||||
|
private Integer pageNum;
|
||||||
|
private Integer pageSize;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
package com.brook.common.domain.request.single;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook.common.domain.request.single
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:SingleReq
|
||||||
|
* @Date 2024/3/12:13:33
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class SingleReq {
|
||||||
|
|
||||||
|
@TableField(value = "goods_id")
|
||||||
|
private Long goodsId;
|
||||||
|
private Integer total;
|
||||||
|
@TableField(value = "total_price")
|
||||||
|
private BigDecimal totalPrice;
|
||||||
|
@TableField(value = "user_id")
|
||||||
|
private Long userId;
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT-8")
|
||||||
|
@TableField(value = "create_time")
|
||||||
|
private Date createTime;
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.brook.common.domain.response.auth;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook.common.domain.response.auth
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:LoginAuthResp
|
||||||
|
* @Date 2024/3/12:9:35
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class LoginAuthResp {
|
||||||
|
|
||||||
|
private String token;
|
||||||
|
private Long outTime;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
package com.brook.common.handler;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.brook.common.result.Result;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.validation.ObjectError;
|
||||||
|
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||||
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DongZl
|
||||||
|
* @description: 全局异常处理
|
||||||
|
* @Date 2024-1-10 下午 08:49
|
||||||
|
*/
|
||||||
|
@RestControllerAdvice
|
||||||
|
@Configuration
|
||||||
|
@Slf4j
|
||||||
|
public class GlobalExceptionHandler {
|
||||||
|
|
||||||
|
@ExceptionHandler(value = MethodArgumentNotValidException.class)
|
||||||
|
public Result<String> runtimeException (MethodArgumentNotValidException exception) {
|
||||||
|
return Result.error(
|
||||||
|
JSONObject.toJSONString(
|
||||||
|
exception.getBindingResult().getAllErrors()
|
||||||
|
.stream()
|
||||||
|
.map(ObjectError::getDefaultMessage)
|
||||||
|
.toList()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ExceptionHandler(value = IllegalArgumentException.class)
|
||||||
|
public Result<String> illegalArgumentExceptionHandler(IllegalArgumentException exception){
|
||||||
|
log.error("请求异常:[{}]", exception.getMessage(), exception);
|
||||||
|
return Result.error(exception.getMessage());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,260 @@
|
||||||
|
package com.brook.common.redis;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.redis.core.BoundSetOperations;
|
||||||
|
import org.springframework.data.redis.core.HashOperations;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.data.redis.core.ValueOperations;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* spring redis 工具类
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
**/
|
||||||
|
@SuppressWarnings(value = {"unchecked", "rawtypes"})
|
||||||
|
@Component
|
||||||
|
public class RedisCache {
|
||||||
|
@Autowired
|
||||||
|
public RedisTemplate redisTemplate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 缓存基本的对象,Integer、String、实体类等
|
||||||
|
*
|
||||||
|
* @param key 缓存的键值
|
||||||
|
* @param value 缓存的值
|
||||||
|
*/
|
||||||
|
public <T> void setCacheObject (final String key, final T value) {
|
||||||
|
redisTemplate.opsForValue().set(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 缓存基本的对象,Integer、String、实体类等
|
||||||
|
*
|
||||||
|
* @param key 缓存的键值
|
||||||
|
* @param value 缓存的值
|
||||||
|
* @param timeout 时间
|
||||||
|
* @param timeUnit 时间颗粒度
|
||||||
|
*/
|
||||||
|
public <T> void setCacheObject (final String key, final T value, final Long timeout, final TimeUnit timeUnit) {
|
||||||
|
redisTemplate.opsForValue().set(key, value, timeout, timeUnit);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置有效时间
|
||||||
|
*
|
||||||
|
* @param key Redis键
|
||||||
|
* @param timeout 超时时间
|
||||||
|
*
|
||||||
|
* @return true=设置成功;false=设置失败
|
||||||
|
*/
|
||||||
|
public boolean expire (final String key, final long timeout) {
|
||||||
|
return expire(key, timeout, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置有效时间
|
||||||
|
*
|
||||||
|
* @param key Redis键
|
||||||
|
* @param timeout 超时时间
|
||||||
|
* @param unit 时间单位
|
||||||
|
*
|
||||||
|
* @return true=设置成功;false=设置失败
|
||||||
|
*/
|
||||||
|
public boolean expire (final String key, final long timeout, final TimeUnit unit) {
|
||||||
|
return Boolean.TRUE.equals(redisTemplate.expire(key, timeout, unit));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取有效时间
|
||||||
|
*
|
||||||
|
* @param key Redis键
|
||||||
|
*
|
||||||
|
* @return 有效时间
|
||||||
|
*/
|
||||||
|
public long getExpire (final String key) {
|
||||||
|
return redisTemplate.getExpire(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断 key是否存在
|
||||||
|
*
|
||||||
|
* @param key 键
|
||||||
|
*
|
||||||
|
* @return true 存在 false不存在
|
||||||
|
*/
|
||||||
|
public Boolean hasKey (String key) {
|
||||||
|
return redisTemplate.hasKey(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得缓存的基本对象。
|
||||||
|
*
|
||||||
|
* @param key 缓存键值
|
||||||
|
*
|
||||||
|
* @return 缓存键值对应的数据
|
||||||
|
*/
|
||||||
|
public <T> T getCacheObject (final String key) {
|
||||||
|
ValueOperations<String, T> operation = redisTemplate.opsForValue();
|
||||||
|
return operation.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除单个对象
|
||||||
|
*
|
||||||
|
* @param key
|
||||||
|
*/
|
||||||
|
public boolean deleteObject (final String key) {
|
||||||
|
return redisTemplate.delete(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除集合对象
|
||||||
|
*
|
||||||
|
* @param collection 多个对象
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean deleteObject (final Collection collection) {
|
||||||
|
return redisTemplate.delete(collection) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 缓存List数据
|
||||||
|
*
|
||||||
|
* @param key 缓存的键值
|
||||||
|
* @param dataList 待缓存的List数据
|
||||||
|
*
|
||||||
|
* @return 缓存的对象
|
||||||
|
*/
|
||||||
|
public <T> long setCacheList (final String key, final List<T> dataList) {
|
||||||
|
Long count = redisTemplate.opsForList().rightPushAll(key, dataList);
|
||||||
|
return count == null ? 0 : count;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得缓存的list对象
|
||||||
|
*
|
||||||
|
* @param key 缓存的键值
|
||||||
|
*
|
||||||
|
* @return 缓存键值对应的数据
|
||||||
|
*/
|
||||||
|
public <T> List<T> getCacheList (final String key) {
|
||||||
|
return redisTemplate.opsForList().range(key, 0, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 缓存Set
|
||||||
|
*
|
||||||
|
* @param key 缓存键值
|
||||||
|
* @param dataSet 缓存的数据
|
||||||
|
*
|
||||||
|
* @return 缓存数据的对象
|
||||||
|
*/
|
||||||
|
public <T> BoundSetOperations<String, T> setCacheSet (final String key, final Set<T> dataSet) {
|
||||||
|
BoundSetOperations<String, T> setOperation = redisTemplate.boundSetOps(key);
|
||||||
|
for (T t : dataSet) {
|
||||||
|
setOperation.add(t);
|
||||||
|
}
|
||||||
|
return setOperation;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得缓存的set
|
||||||
|
*
|
||||||
|
* @param key
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public <T> Set<T> getCacheSet (final String key) {
|
||||||
|
return redisTemplate.opsForSet().members(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 缓存Map
|
||||||
|
*
|
||||||
|
* @param key
|
||||||
|
* @param dataMap
|
||||||
|
*/
|
||||||
|
public <T> void setCacheMap (final String key, final Map<String, T> dataMap) {
|
||||||
|
if (dataMap != null) {
|
||||||
|
redisTemplate.opsForHash().putAll(key, dataMap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得缓存的Map
|
||||||
|
*
|
||||||
|
* @param key
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public <T> Map<String, T> getCacheMap (final String key) {
|
||||||
|
return redisTemplate.opsForHash().entries(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 往Hash中存入数据
|
||||||
|
*
|
||||||
|
* @param key Redis键
|
||||||
|
* @param hKey Hash键
|
||||||
|
* @param value 值
|
||||||
|
*/
|
||||||
|
public <T> void setCacheMapValue (final String key, final String hKey, final T value) {
|
||||||
|
redisTemplate.opsForHash().put(key, hKey, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取Hash中的数据
|
||||||
|
*
|
||||||
|
* @param key Redis键
|
||||||
|
* @param hKey Hash键
|
||||||
|
*
|
||||||
|
* @return Hash中的对象
|
||||||
|
*/
|
||||||
|
public <T> T getCacheMapValue (final String key, final String hKey) {
|
||||||
|
HashOperations<String, String, T> opsForHash = redisTemplate.opsForHash();
|
||||||
|
return opsForHash.get(key, hKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取多个Hash中的数据
|
||||||
|
*
|
||||||
|
* @param key Redis键
|
||||||
|
* @param hKeys Hash键集合
|
||||||
|
*
|
||||||
|
* @return Hash对象集合
|
||||||
|
*/
|
||||||
|
public <T> List<T> getMultiCacheMapValue (final String key, final Collection<Object> hKeys) {
|
||||||
|
return redisTemplate.opsForHash().multiGet(key, hKeys);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除Hash中的某条数据
|
||||||
|
*
|
||||||
|
* @param key Redis键
|
||||||
|
* @param hKey Hash键
|
||||||
|
*
|
||||||
|
* @return 是否成功
|
||||||
|
*/
|
||||||
|
public boolean deleteCacheMapValue (final String key, final String hKey) {
|
||||||
|
return redisTemplate.opsForHash().delete(key, hKey) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得缓存的基本对象列表
|
||||||
|
*
|
||||||
|
* @param pattern 字符串前缀
|
||||||
|
*
|
||||||
|
* @return 对象列表
|
||||||
|
*/
|
||||||
|
public Collection<String> keys (final String pattern) {
|
||||||
|
return redisTemplate.keys(pattern);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.brook.common.remote;
|
||||||
|
|
||||||
|
import com.brook.common.constants.GoodsConstants;
|
||||||
|
import com.brook.common.domain.Goods;
|
||||||
|
import com.brook.common.remote.goods.RemoteGoodsFactory;
|
||||||
|
import com.brook.common.result.Result;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook.common.remote
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:RemoteGoodsService
|
||||||
|
* @Date 2024/3/12:10:10
|
||||||
|
*/
|
||||||
|
@FeignClient(
|
||||||
|
path = "/goods",
|
||||||
|
name = GoodsConstants.GOODS_NAME,
|
||||||
|
fallbackFactory = RemoteGoodsFactory.class
|
||||||
|
)
|
||||||
|
public interface RemoteGoodsService {
|
||||||
|
|
||||||
|
@GetMapping("/getGoodsList")
|
||||||
|
public Result<List<Goods>> goodsList();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.brook.common.remote;
|
||||||
|
|
||||||
|
import com.brook.common.constants.UserInfoConstants;
|
||||||
|
import com.brook.common.domain.UserInfo;
|
||||||
|
import com.brook.common.remote.system.RemoteUserInfoFactory;
|
||||||
|
import com.brook.common.result.Result;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook.common.remote
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:RemoteUserInfoService
|
||||||
|
* @Date 2024/3/12:9:23
|
||||||
|
*/
|
||||||
|
@FeignClient(
|
||||||
|
path = "/userInfo",
|
||||||
|
name = UserInfoConstants.USER_INFO,
|
||||||
|
fallbackFactory = RemoteUserInfoFactory.class
|
||||||
|
)
|
||||||
|
public interface RemoteUserInfoService {
|
||||||
|
|
||||||
|
@GetMapping("/findByPhone")
|
||||||
|
public Result<UserInfo> findByPhone(@RequestParam String phone);
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
package com.brook.common.remote.goods;
|
||||||
|
|
||||||
|
import com.brook.common.domain.Goods;
|
||||||
|
import com.brook.common.remote.RemoteGoodsService;
|
||||||
|
import com.brook.common.result.Result;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook.common.remote.goods
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:RemoteGoodsFactory
|
||||||
|
* @Date 2024/3/12:10:11
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class RemoteGoodsFactory implements FallbackFactory<RemoteGoodsService> {
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RemoteGoodsService create(Throwable cause) {
|
||||||
|
return new RemoteGoodsService() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result<List<Goods>> goodsList() {
|
||||||
|
log.info("远程调用商品列表失败",cause.getCause(),cause);
|
||||||
|
return Result.error();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
package com.brook.common.remote.system;
|
||||||
|
|
||||||
|
import com.brook.common.domain.UserInfo;
|
||||||
|
import com.brook.common.remote.RemoteUserInfoService;
|
||||||
|
import com.brook.common.result.Result;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook.common.remote.system
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:RemoteUserInfoFactory
|
||||||
|
* @Date 2024/3/12:9:24
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class RemoteUserInfoFactory implements FallbackFactory<RemoteUserInfoService> {
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RemoteUserInfoService create(Throwable cause) {
|
||||||
|
return new RemoteUserInfoService() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result<UserInfo> findByPhone(String phone) {
|
||||||
|
|
||||||
|
log.info("远程调用查询手机号是否是系统用户失败",phone,cause.getMessage(),cause);
|
||||||
|
|
||||||
|
return Result.error();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
package com.brook.common.result;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName PageResult
|
||||||
|
* @Description 列表返回结果集
|
||||||
|
* @Author ChenLong
|
||||||
|
* @Date 2023/2/23 16:09
|
||||||
|
* @Version 1.0
|
||||||
|
*/
|
||||||
|
@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));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,75 @@
|
||||||
|
package com.brook.common.result;
|
||||||
|
|
||||||
|
import com.brook.common.constants.Constants;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName Result
|
||||||
|
* @Description 响应信息主体
|
||||||
|
* @Author ChenLong
|
||||||
|
* @Date 2023/2/23 16:08
|
||||||
|
* @Version 1.0
|
||||||
|
*/
|
||||||
|
@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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSuccess(){
|
||||||
|
return this.code == SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isError(){
|
||||||
|
return !isSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,253 @@
|
||||||
|
package com.brook.common.utils;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.util.Base64Utils;
|
||||||
|
|
||||||
|
import javax.crypto.Cipher;
|
||||||
|
import javax.crypto.spec.IvParameterSpec;
|
||||||
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName AESUtils
|
||||||
|
* @Description 描述
|
||||||
|
* @Author WenSha.Wan
|
||||||
|
* @Date 2023/7/8 上午7:48
|
||||||
|
*/
|
||||||
|
public class AESUtils {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日志相关
|
||||||
|
*/
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(AESUtils.class);
|
||||||
|
/**
|
||||||
|
* 编码
|
||||||
|
*/
|
||||||
|
private static final String ENCODING = "UTF-8";
|
||||||
|
/**
|
||||||
|
* 算法定义
|
||||||
|
*/
|
||||||
|
private static final String AES_ALGORITHM = "AES";
|
||||||
|
/**
|
||||||
|
* 指定填充方式
|
||||||
|
*/
|
||||||
|
private static final String CIPHER_PADDING = "AES/ECB/PKCS5Padding";
|
||||||
|
private static final String CIPHER_CBC_PADDING = "AES/CBC/PKCS5Padding";
|
||||||
|
/**
|
||||||
|
* 偏移量(CBC中使用,增强加密算法强度)
|
||||||
|
*/
|
||||||
|
private static final String IV_SEED = "1234567812345678";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AES加密
|
||||||
|
* @param content 待加密内容
|
||||||
|
* @param aesKey 密码
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String encrypt(String content, String aesKey){
|
||||||
|
if(StringUtils.isBlank(content)){
|
||||||
|
LOGGER.info("AES encrypt: the content is null!");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
//判断秘钥是否为16位
|
||||||
|
if(StringUtils.isNotBlank(aesKey) && aesKey.length() == 16){
|
||||||
|
try {
|
||||||
|
//对密码进行编码
|
||||||
|
byte[] bytes = aesKey.getBytes(ENCODING);
|
||||||
|
//设置加密算法,生成秘钥
|
||||||
|
SecretKeySpec skeySpec = new SecretKeySpec(bytes, AES_ALGORITHM);
|
||||||
|
// "算法/模式/补码方式"
|
||||||
|
Cipher cipher = Cipher.getInstance(CIPHER_PADDING);
|
||||||
|
//选择加密
|
||||||
|
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
|
||||||
|
//根据待加密内容生成字节数组
|
||||||
|
byte[] encrypted = cipher.doFinal(content.getBytes(ENCODING));
|
||||||
|
//返回base64字符串
|
||||||
|
return Base64Utils.encodeToString(encrypted);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOGGER.info("AES encrypt exception:" + e.getMessage());
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}else {
|
||||||
|
LOGGER.info("AES encrypt: the aesKey is null or error!");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解密
|
||||||
|
*
|
||||||
|
* @param content 待解密内容
|
||||||
|
* @param aesKey 密码
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String decrypt(String content, String aesKey){
|
||||||
|
if(StringUtils.isBlank(content)){
|
||||||
|
LOGGER.info("AES decrypt: the content is null!");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
//判断秘钥是否为16位
|
||||||
|
if(StringUtils.isNotBlank(aesKey) && aesKey.length() == 16){
|
||||||
|
try {
|
||||||
|
//对密码进行编码
|
||||||
|
byte[] bytes = aesKey.getBytes(ENCODING);
|
||||||
|
//设置解密算法,生成秘钥
|
||||||
|
SecretKeySpec skeySpec = new SecretKeySpec(bytes, AES_ALGORITHM);
|
||||||
|
// "算法/模式/补码方式"
|
||||||
|
Cipher cipher = Cipher.getInstance(CIPHER_PADDING);
|
||||||
|
//选择解密
|
||||||
|
cipher.init(Cipher.DECRYPT_MODE, skeySpec);
|
||||||
|
|
||||||
|
//先进行Base64解码
|
||||||
|
byte[] decodeBase64 = Base64Utils.decodeFromString(content);
|
||||||
|
|
||||||
|
//根据待解密内容进行解密
|
||||||
|
byte[] decrypted = cipher.doFinal(decodeBase64);
|
||||||
|
//将字节数组转成字符串
|
||||||
|
return new String(decrypted, ENCODING);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOGGER.info("AES decrypt exception:" + e.getMessage());
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}else {
|
||||||
|
LOGGER.info("AES decrypt: the aesKey is null or error!");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AES_CBC加密
|
||||||
|
*
|
||||||
|
* @param content 待加密内容
|
||||||
|
* @param aesKey 密码
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String encryptCBC(String content, String aesKey){
|
||||||
|
if(StringUtils.isBlank(content)){
|
||||||
|
LOGGER.info("AES_CBC encrypt: the content is null!");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
//判断秘钥是否为16位
|
||||||
|
if(StringUtils.isNotBlank(aesKey) && aesKey.length() == 16){
|
||||||
|
try {
|
||||||
|
//对密码进行编码
|
||||||
|
byte[] bytes = aesKey.getBytes(ENCODING);
|
||||||
|
//设置加密算法,生成秘钥
|
||||||
|
SecretKeySpec skeySpec = new SecretKeySpec(bytes, AES_ALGORITHM);
|
||||||
|
// "算法/模式/补码方式"
|
||||||
|
Cipher cipher = Cipher.getInstance(CIPHER_CBC_PADDING);
|
||||||
|
//偏移
|
||||||
|
IvParameterSpec iv = new IvParameterSpec(IV_SEED.getBytes(ENCODING));
|
||||||
|
//选择加密
|
||||||
|
cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv);
|
||||||
|
//根据待加密内容生成字节数组
|
||||||
|
byte[] encrypted = cipher.doFinal(content.getBytes(ENCODING));
|
||||||
|
//返回base64字符串
|
||||||
|
return Base64Utils.encodeToString(encrypted);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOGGER.info("AES_CBC encrypt exception:" + e.getMessage());
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}else {
|
||||||
|
LOGGER.info("AES_CBC encrypt: the aesKey is null or error!");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AES_CBC解密
|
||||||
|
*
|
||||||
|
* @param content 待解密内容
|
||||||
|
* @param aesKey 密码
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String decryptCBC(String content, String aesKey){
|
||||||
|
if(StringUtils.isBlank(content)){
|
||||||
|
LOGGER.info("AES_CBC decrypt: the content is null!");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
//判断秘钥是否为16位
|
||||||
|
if(StringUtils.isNotBlank(aesKey) && aesKey.length() == 16){
|
||||||
|
try {
|
||||||
|
//对密码进行编码
|
||||||
|
byte[] bytes = aesKey.getBytes(ENCODING);
|
||||||
|
//设置解密算法,生成秘钥
|
||||||
|
SecretKeySpec skeySpec = new SecretKeySpec(bytes, AES_ALGORITHM);
|
||||||
|
//偏移
|
||||||
|
IvParameterSpec iv = new IvParameterSpec(IV_SEED.getBytes(ENCODING));
|
||||||
|
// "算法/模式/补码方式"
|
||||||
|
Cipher cipher = Cipher.getInstance(CIPHER_CBC_PADDING);
|
||||||
|
//选择解密
|
||||||
|
cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv);
|
||||||
|
|
||||||
|
//先进行Base64解码
|
||||||
|
byte[] decodeBase64 = Base64Utils.decodeFromString(content);
|
||||||
|
|
||||||
|
//根据待解密内容进行解密
|
||||||
|
byte[] decrypted = cipher.doFinal(decodeBase64);
|
||||||
|
//将字节数组转成字符串
|
||||||
|
return new String(decrypted, ENCODING);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOGGER.info("AES_CBC decrypt exception:" + e.getMessage());
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}else {
|
||||||
|
LOGGER.info("AES_CBC decrypt: the aesKey is null or error!");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// AES支持三种长度的密钥:128位、192位、256位。
|
||||||
|
// 代码中这种就是128位的加密密钥,16字节 * 8位/字节 = 128位。
|
||||||
|
// String random = RandomStringUtils.random(16, "abcdefghijklmnopqrstuvwxyz1234567890");
|
||||||
|
// String random = RandomStringUtils.random(16, "123456");
|
||||||
|
// System.out.println("随机key:" + random);
|
||||||
|
// System.out.println();
|
||||||
|
//
|
||||||
|
// System.out.println("---------加密---------");
|
||||||
|
// String aesResult = encrypt("测试AES加密12", random);
|
||||||
|
// System.out.println("aes加密结果:" + aesResult);
|
||||||
|
// System.out.println();
|
||||||
|
//
|
||||||
|
// System.out.println("---------解密---------");
|
||||||
|
// String decrypt = decrypt(aesResult, random);
|
||||||
|
// System.out.println("aes解密结果:" + decrypt);
|
||||||
|
// System.out.println();
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// System.out.println("--------AES_CBC加密解密---------");
|
||||||
|
// String cbcResult = encryptCBC("测试AES加密12456", random);
|
||||||
|
// System.out.println("aes_cbc加密结果:" + cbcResult);
|
||||||
|
// System.out.println();
|
||||||
|
//
|
||||||
|
// System.out.println("---------解密CBC---------");
|
||||||
|
// String cbcDecrypt = decryptCBC(cbcResult, random);
|
||||||
|
// System.out.println("aes解密结果:" + cbcDecrypt);
|
||||||
|
// System.out.println();
|
||||||
|
|
||||||
|
|
||||||
|
//加密
|
||||||
|
String encrypt1 = encrypt ("12345", "1234567890004422");
|
||||||
|
System.out.println ("12345加密后 1====================={"+encrypt1);
|
||||||
|
String encrypt2 = encrypt ("23456", "1234567890004422");
|
||||||
|
System.out.println ("23456加密后 1====================={"+encrypt2);
|
||||||
|
String encrypt3 = encrypt ("56789", "1234567890004422");
|
||||||
|
System.out.println ("56789加密后 1====================={"+encrypt3);
|
||||||
|
|
||||||
|
//解密
|
||||||
|
// decrypt ("/83VCGvDN+C5pvYN/19pBQ==")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,48 @@
|
||||||
|
package com.brook.common.utils;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSON;
|
||||||
|
import com.alibaba.fastjson2.JSONReader;
|
||||||
|
import com.alibaba.fastjson2.JSONWriter;
|
||||||
|
import com.alibaba.fastjson2.filter.Filter;
|
||||||
|
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||||
|
import org.springframework.data.redis.serializer.SerializationException;
|
||||||
|
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Redis使用FastJson序列化
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class FastJson2JsonRedisSerializer<T> implements RedisSerializer<T> {
|
||||||
|
public static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
|
||||||
|
|
||||||
|
static final Filter AUTO_TYPE_FILTER = JSONReader.autoTypeFilter(
|
||||||
|
"org.springframework", "com");
|
||||||
|
|
||||||
|
private Class<T> clazz;
|
||||||
|
|
||||||
|
public FastJson2JsonRedisSerializer(Class<T> clazz) {
|
||||||
|
super();
|
||||||
|
this.clazz = clazz;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] serialize (T t) throws SerializationException {
|
||||||
|
if (t == null) {
|
||||||
|
return new byte[0];
|
||||||
|
}
|
||||||
|
return JSON.toJSONString(t, JSONWriter.Feature.WriteClassName).getBytes(DEFAULT_CHARSET);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T deserialize (byte[] bytes) throws SerializationException {
|
||||||
|
if (bytes == null || bytes.length <= 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String str = new String(bytes, DEFAULT_CHARSET);
|
||||||
|
|
||||||
|
return JSON.parseObject(str, clazz, AUTO_TYPE_FILTER);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,312 @@
|
||||||
|
package com.brook.common.utils;
|
||||||
|
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.security.KeyManagementException;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.security.cert.X509Certificate;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.net.ssl.SSLContext;
|
||||||
|
import javax.net.ssl.TrustManager;
|
||||||
|
import javax.net.ssl.X509TrustManager;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
|
import org.apache.http.NameValuePair;
|
||||||
|
import org.apache.http.client.HttpClient;
|
||||||
|
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||||
|
import org.apache.http.client.methods.HttpDelete;
|
||||||
|
import org.apache.http.client.methods.HttpGet;
|
||||||
|
import org.apache.http.client.methods.HttpPost;
|
||||||
|
import org.apache.http.client.methods.HttpPut;
|
||||||
|
import org.apache.http.conn.ClientConnectionManager;
|
||||||
|
import org.apache.http.conn.scheme.Scheme;
|
||||||
|
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||||
|
import org.apache.http.conn.ssl.SSLSocketFactory;
|
||||||
|
import org.apache.http.entity.ByteArrayEntity;
|
||||||
|
import org.apache.http.entity.StringEntity;
|
||||||
|
import org.apache.http.impl.client.DefaultHttpClient;
|
||||||
|
import org.apache.http.message.BasicNameValuePair;
|
||||||
|
|
||||||
|
public class HttpUtils {
|
||||||
|
/**
|
||||||
|
* get
|
||||||
|
*
|
||||||
|
* @param host
|
||||||
|
* @param path
|
||||||
|
* @param method
|
||||||
|
* @param headers
|
||||||
|
* @param querys
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static HttpResponse doGet(String host, String path, String method,
|
||||||
|
Map<String, String> headers,
|
||||||
|
Map<String, String> querys)
|
||||||
|
throws Exception {
|
||||||
|
HttpClient httpClient = wrapClient(host);
|
||||||
|
|
||||||
|
HttpGet request = new HttpGet(buildUrl(host, path, querys));
|
||||||
|
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||||
|
request.addHeader(e.getKey(), e.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
return httpClient.execute(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* post form
|
||||||
|
*
|
||||||
|
* @param host
|
||||||
|
* @param path
|
||||||
|
* @param method
|
||||||
|
* @param headers
|
||||||
|
* @param querys
|
||||||
|
* @param bodys
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static HttpResponse doPost(String host, String path, String method,
|
||||||
|
Map<String, String> headers,
|
||||||
|
Map<String, String> querys,
|
||||||
|
Map<String, String> bodys)
|
||||||
|
throws Exception {
|
||||||
|
HttpClient httpClient = wrapClient(host);
|
||||||
|
|
||||||
|
HttpPost request = new HttpPost(buildUrl(host, path, querys));
|
||||||
|
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||||
|
request.addHeader(e.getKey(), e.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bodys != null) {
|
||||||
|
List<NameValuePair> nameValuePairList = new ArrayList<NameValuePair>();
|
||||||
|
|
||||||
|
for (String key : bodys.keySet()) {
|
||||||
|
nameValuePairList.add(new BasicNameValuePair(key, bodys.get(key)));
|
||||||
|
}
|
||||||
|
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, "utf-8");
|
||||||
|
formEntity.setContentType("application/x-www-form-urlencoded; charset=UTF-8");
|
||||||
|
request.setEntity(formEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
return httpClient.execute(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Post String
|
||||||
|
*
|
||||||
|
* @param host
|
||||||
|
* @param path
|
||||||
|
* @param method
|
||||||
|
* @param headers
|
||||||
|
* @param querys
|
||||||
|
* @param body
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static HttpResponse doPost(String host, String path, String method,
|
||||||
|
Map<String, String> headers,
|
||||||
|
Map<String, String> querys,
|
||||||
|
String body)
|
||||||
|
throws Exception {
|
||||||
|
HttpClient httpClient = wrapClient(host);
|
||||||
|
|
||||||
|
HttpPost request = new HttpPost(buildUrl(host, path, querys));
|
||||||
|
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||||
|
request.addHeader(e.getKey(), e.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isNotBlank(body)) {
|
||||||
|
request.setEntity(new StringEntity(body, "utf-8"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return httpClient.execute(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Post stream
|
||||||
|
*
|
||||||
|
* @param host
|
||||||
|
* @param path
|
||||||
|
* @param method
|
||||||
|
* @param headers
|
||||||
|
* @param querys
|
||||||
|
* @param body
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static HttpResponse doPost(String host, String path, String method,
|
||||||
|
Map<String, String> headers,
|
||||||
|
Map<String, String> querys,
|
||||||
|
byte[] body)
|
||||||
|
throws Exception {
|
||||||
|
HttpClient httpClient = wrapClient(host);
|
||||||
|
|
||||||
|
HttpPost request = new HttpPost(buildUrl(host, path, querys));
|
||||||
|
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||||
|
request.addHeader(e.getKey(), e.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (body != null) {
|
||||||
|
request.setEntity(new ByteArrayEntity(body));
|
||||||
|
}
|
||||||
|
|
||||||
|
return httpClient.execute(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Put String
|
||||||
|
* @param host
|
||||||
|
* @param path
|
||||||
|
* @param method
|
||||||
|
* @param headers
|
||||||
|
* @param querys
|
||||||
|
* @param body
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static HttpResponse doPut(String host, String path, String method,
|
||||||
|
Map<String, String> headers,
|
||||||
|
Map<String, String> querys,
|
||||||
|
String body)
|
||||||
|
throws Exception {
|
||||||
|
HttpClient httpClient = wrapClient(host);
|
||||||
|
|
||||||
|
HttpPut request = new HttpPut(buildUrl(host, path, querys));
|
||||||
|
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||||
|
request.addHeader(e.getKey(), e.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isNotBlank(body)) {
|
||||||
|
request.setEntity(new StringEntity(body, "utf-8"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return httpClient.execute(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Put stream
|
||||||
|
* @param host
|
||||||
|
* @param path
|
||||||
|
* @param method
|
||||||
|
* @param headers
|
||||||
|
* @param querys
|
||||||
|
* @param body
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static HttpResponse doPut(String host, String path, String method,
|
||||||
|
Map<String, String> headers,
|
||||||
|
Map<String, String> querys,
|
||||||
|
byte[] body)
|
||||||
|
throws Exception {
|
||||||
|
HttpClient httpClient = wrapClient(host);
|
||||||
|
|
||||||
|
HttpPut request = new HttpPut(buildUrl(host, path, querys));
|
||||||
|
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||||
|
request.addHeader(e.getKey(), e.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (body != null) {
|
||||||
|
request.setEntity(new ByteArrayEntity(body));
|
||||||
|
}
|
||||||
|
|
||||||
|
return httpClient.execute(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete
|
||||||
|
*
|
||||||
|
* @param host
|
||||||
|
* @param path
|
||||||
|
* @param method
|
||||||
|
* @param headers
|
||||||
|
* @param querys
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static HttpResponse doDelete(String host, String path, String method,
|
||||||
|
Map<String, String> headers,
|
||||||
|
Map<String, String> querys)
|
||||||
|
throws Exception {
|
||||||
|
HttpClient httpClient = wrapClient(host);
|
||||||
|
|
||||||
|
HttpDelete request = new HttpDelete(buildUrl(host, path, querys));
|
||||||
|
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||||
|
request.addHeader(e.getKey(), e.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
return httpClient.execute(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String buildUrl(String host, String path, Map<String, String> querys) throws UnsupportedEncodingException {
|
||||||
|
StringBuilder sbUrl = new StringBuilder();
|
||||||
|
sbUrl.append(host);
|
||||||
|
if (!StringUtils.isBlank(path)) {
|
||||||
|
sbUrl.append(path);
|
||||||
|
}
|
||||||
|
if (null != querys) {
|
||||||
|
StringBuilder sbQuery = new StringBuilder();
|
||||||
|
for (Map.Entry<String, String> query : querys.entrySet()) {
|
||||||
|
if (0 < sbQuery.length()) {
|
||||||
|
sbQuery.append("&");
|
||||||
|
}
|
||||||
|
if (StringUtils.isBlank(query.getKey()) && !StringUtils.isBlank(query.getValue())) {
|
||||||
|
sbQuery.append(query.getValue());
|
||||||
|
}
|
||||||
|
if (!StringUtils.isBlank(query.getKey())) {
|
||||||
|
sbQuery.append(query.getKey());
|
||||||
|
if (!StringUtils.isBlank(query.getValue())) {
|
||||||
|
sbQuery.append("=");
|
||||||
|
sbQuery.append(URLEncoder.encode(query.getValue(), "utf-8"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (0 < sbQuery.length()) {
|
||||||
|
sbUrl.append("?").append(sbQuery);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sbUrl.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static HttpClient wrapClient(String host) {
|
||||||
|
HttpClient httpClient = new DefaultHttpClient();
|
||||||
|
if (host.startsWith("https://")) {
|
||||||
|
sslClient(httpClient);
|
||||||
|
}
|
||||||
|
|
||||||
|
return httpClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void sslClient(HttpClient httpClient) {
|
||||||
|
try {
|
||||||
|
SSLContext ctx = SSLContext.getInstance("TLS");
|
||||||
|
X509TrustManager tm = new X509TrustManager() {
|
||||||
|
public X509Certificate[] getAcceptedIssuers() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public void checkClientTrusted(X509Certificate[] xcs, String str) {
|
||||||
|
|
||||||
|
}
|
||||||
|
public void checkServerTrusted(X509Certificate[] xcs, String str) {
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ctx.init(null, new TrustManager[] { tm }, null);
|
||||||
|
SSLSocketFactory ssf = new SSLSocketFactory(ctx);
|
||||||
|
ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
|
||||||
|
ClientConnectionManager ccm = httpClient.getConnectionManager();
|
||||||
|
SchemeRegistry registry = ccm.getSchemeRegistry();
|
||||||
|
registry.register(new Scheme("https", 443, ssf));
|
||||||
|
} catch (KeyManagementException ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
} catch (NoSuchAlgorithmException ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,106 @@
|
||||||
|
package com.brook.common.utils;
|
||||||
|
|
||||||
|
import com.brook.common.constants.JwtConstants;
|
||||||
|
import io.jsonwebtoken.Claims;
|
||||||
|
import io.jsonwebtoken.Jwts;
|
||||||
|
import io.jsonwebtoken.SignatureAlgorithm;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName JwtUtils
|
||||||
|
* @Description Jwt工具类
|
||||||
|
* @Author ChenLong
|
||||||
|
* @Date 2023/2/23 16:10
|
||||||
|
* @Version 1.0
|
||||||
|
*/
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,67 @@
|
||||||
|
package com.brook.common.utils;
|
||||||
|
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
|
import org.apache.http.util.EntityUtils;
|
||||||
|
import org.springframework.cache.annotation.CachePut;
|
||||||
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class MsgUtil {
|
||||||
|
//取code
|
||||||
|
// @Cacheable(key = "#phone",value = "bbb")
|
||||||
|
// public String getCacheCode(String phone){
|
||||||
|
//
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// //把当前注解的返回值装进去 //存code
|
||||||
|
// @CachePut(key = "#codeEntity.phone",value = "bbb")
|
||||||
|
// public String saveCacheCode(CodeEntity codeEntity){
|
||||||
|
//
|
||||||
|
// return codeEntity.getCode();
|
||||||
|
// }
|
||||||
|
|
||||||
|
public String sendMsg(String phone,String code){
|
||||||
|
String result = null;
|
||||||
|
String host = "https://gyytz.market.alicloudapi.com";
|
||||||
|
String path = "/sms/smsSend";
|
||||||
|
String method = "POST";
|
||||||
|
String appcode = "beautiful";
|
||||||
|
// 8b833b1c5501450584c6906c84b1839e
|
||||||
|
Map<String, String> headers = new HashMap<String, String>();
|
||||||
|
//最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
|
||||||
|
headers.put("Authorization", "APPCODE " + appcode);
|
||||||
|
Map<String, String> querys = new HashMap<String, String>();
|
||||||
|
querys.put("mobile", phone);
|
||||||
|
querys.put("param", "**code**:"+code+",**minute**:5");
|
||||||
|
|
||||||
|
//smsSignId(短信前缀)和templateId(短信模板),可登录国阳云控制台自助申请。参考文档:http://help.guoyangyun.com/Problem/Qm.html
|
||||||
|
|
||||||
|
querys.put("smsSignId", "2e65b1bb3d054466b82f0c9d125465e2");
|
||||||
|
querys.put("templateId", "908e94ccf08b4476ba6c876d13f084ad");
|
||||||
|
Map<String, String> bodys = new HashMap<String, String>();
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
/**
|
||||||
|
* 重要提示如下:
|
||||||
|
* HttpUtils请从\r\n\t \t* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java\r\n\t \t* 下载
|
||||||
|
*
|
||||||
|
* 相应的依赖请参照
|
||||||
|
* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
|
||||||
|
*/
|
||||||
|
HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
|
||||||
|
// System.out.println(response.toString());
|
||||||
|
//获取response的body
|
||||||
|
result = EntityUtils.toString(response.getEntity());
|
||||||
|
System.out.println(result);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,153 @@
|
||||||
|
package com.brook.common.utils;
|
||||||
|
|
||||||
|
import com.aliyun.oss.OSS;
|
||||||
|
import com.aliyun.oss.OSSClientBuilder;
|
||||||
|
import com.aliyun.oss.model.GetObjectRequest;
|
||||||
|
import com.aliyun.oss.model.PutObjectRequest;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Oss服务调用
|
||||||
|
*/
|
||||||
|
@Log4j2
|
||||||
|
public class OssUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Endpoint 存储对象概述 阿里云主账号AccessKey,accessKeySecret拥有所有API的访问权限 访问路径前缀 存储对象概述
|
||||||
|
*/
|
||||||
|
private static String endPoint = "oss-cn-shanghai.aliyuncs.com";
|
||||||
|
private static String accessKeyId = "LTAI5tPHcqEdn49yrDCNpLhb";
|
||||||
|
private static String accessKeySecret = "C29u7EmS0TFlgMBzVszvuPFUxsKJuW";
|
||||||
|
private static String accessPre = "https://liushiqian.oss-cn-shanghai.aliyuncs.com/";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bucket名称
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private static String bucketName = "liushiqian";
|
||||||
|
|
||||||
|
private static OSS ossClient ;
|
||||||
|
|
||||||
|
static {
|
||||||
|
ossClient = new OSSClientBuilder().build(
|
||||||
|
endPoint,
|
||||||
|
accessKeyId,
|
||||||
|
accessKeySecret);
|
||||||
|
log.info("oss服务连接成功!");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认路径上传本地文件
|
||||||
|
* @param filePath
|
||||||
|
*/
|
||||||
|
public static String uploadFile(String filePath){
|
||||||
|
return uploadFileForBucket(bucketName,getOssFilePath(filePath) ,filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认路径上传multipartFile文件
|
||||||
|
* @param multipartFile
|
||||||
|
*/
|
||||||
|
public static String uploadMultipartFile(MultipartFile multipartFile) {
|
||||||
|
return uploadMultipartFile(bucketName,getOssFilePath(multipartFile.getOriginalFilename()),multipartFile);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 上传 multipartFile 类型文件
|
||||||
|
* @param bucketName
|
||||||
|
* @param ossPath
|
||||||
|
* @param multipartFile
|
||||||
|
*/
|
||||||
|
public static String uploadMultipartFile(String bucketName , String ossPath , MultipartFile multipartFile){
|
||||||
|
InputStream inputStream = null;
|
||||||
|
try {
|
||||||
|
inputStream = multipartFile.getInputStream();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
uploadFileInputStreamForBucket(bucketName, ossPath, inputStream);
|
||||||
|
return accessPre+ossPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用File上传PutObject上传文件 ** 程序默认使用次方法上传
|
||||||
|
* @param bucketName 实例名称
|
||||||
|
* @param ossPath oss存储路径
|
||||||
|
* @param filePath 本地文件路径
|
||||||
|
*/
|
||||||
|
public static String uploadFileForBucket(String bucketName , String ossPath , String filePath) {
|
||||||
|
// 创建PutObjectRequest对象。
|
||||||
|
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, ossPath, new File(filePath));
|
||||||
|
|
||||||
|
// 上传
|
||||||
|
ossClient.putObject(putObjectRequest);
|
||||||
|
return accessPre+ossPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用文件流上传到指定的bucket实例
|
||||||
|
* @param bucketName 实例名称
|
||||||
|
* @param ossPath oss存储路径
|
||||||
|
* @param filePath 本地文件路径
|
||||||
|
*/
|
||||||
|
public static String uploadFileInputStreamForBucket(String bucketName , String ossPath , String filePath){
|
||||||
|
|
||||||
|
// 填写本地文件的完整路径。如果未指定本地路径,则默认从示例程序所属项目对应本地路径中上传文件流。
|
||||||
|
InputStream inputStream = null;
|
||||||
|
try {
|
||||||
|
inputStream = new FileInputStream(filePath);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
// 填写Bucket名称和Object完整路径。Object完整路径中不能包含Bucket名称。
|
||||||
|
uploadFileInputStreamForBucket(bucketName, ossPath, inputStream);
|
||||||
|
return accessPre+ossPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void uploadFileInputStreamForBucket(String bucketName , String ossPath , InputStream inputStream ){
|
||||||
|
ossClient.putObject(bucketName, ossPath, inputStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载
|
||||||
|
* @param ossFilePath
|
||||||
|
* @param filePath
|
||||||
|
*/
|
||||||
|
public static void downloadFile(String ossFilePath , String filePath ){
|
||||||
|
downloadFileForBucket(bucketName , ossFilePath , filePath);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 下载
|
||||||
|
* @param bucketName 实例名称
|
||||||
|
* @param ossFilePath oss存储路径
|
||||||
|
* @param filePath 本地文件路径
|
||||||
|
*/
|
||||||
|
public static void downloadFileForBucket(String bucketName , String ossFilePath , String filePath ){
|
||||||
|
ossClient.getObject(new GetObjectRequest(bucketName, ossFilePath), new File(filePath));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getOssDefaultPath(){
|
||||||
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
String url =
|
||||||
|
now.getYear()+"/"+
|
||||||
|
now.getMonth()+"/"+
|
||||||
|
now.getDayOfMonth()+"/"+
|
||||||
|
now.getHour()+"/"+
|
||||||
|
now.getMinute()+"/";
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getOssFilePath(String filePath){
|
||||||
|
String fileSuf = filePath.substring(filePath.indexOf(".") + 1);
|
||||||
|
return getOssDefaultPath() + UUID.randomUUID().toString() + "." + fileSuf;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.brook.common.utils;
|
||||||
|
|
||||||
|
public class RabbitMqSendCode {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送短信队列
|
||||||
|
*/
|
||||||
|
public final static String SEND_CODE="send_code_queue";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 记录日志队列
|
||||||
|
*/
|
||||||
|
public final static String NEW_LOG="new_log_queue_ju";
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
package com.brook.common.utils;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
//package com.brook.common.utils;
|
||||||
|
//
|
||||||
|
//import org.redisson.Redisson;
|
||||||
|
//import org.redisson.api.RedissonClient;
|
||||||
|
//import org.redisson.config.Config;
|
||||||
|
//import org.springframework.context.annotation.Bean;
|
||||||
|
//import org.springframework.context.annotation.Configuration;
|
||||||
|
//
|
||||||
|
//import java.io.IOException;
|
||||||
|
//
|
||||||
|
///**
|
||||||
|
// * @BelongsProject: demo02
|
||||||
|
// * @BelongsPackage: com.bw.config
|
||||||
|
// * @Author: zhupengfei
|
||||||
|
// * @CreateTime: 2022-12-24 09:26
|
||||||
|
// */
|
||||||
|
//
|
||||||
|
//@Configuration
|
||||||
|
//public class RedissonConfig {
|
||||||
|
//
|
||||||
|
// @Bean(destroyMethod="shutdown") // 服务停止后调用 shutdown 方法。
|
||||||
|
// public RedissonClient redisson() throws IOException {
|
||||||
|
// System.out.println("配置类初始加载......");
|
||||||
|
// // 1.创建配置
|
||||||
|
// Config config = new Config();
|
||||||
|
// // 集群模式
|
||||||
|
// // config.useClusterServers().addNodeAddress("127.0.0.1:6379", "127.0.0.1:6378");
|
||||||
|
// // 2.根据 Config 创建出 RedissonClient 实例。
|
||||||
|
// config.useSingleServer().setAddress("redis://49.232.227.52:6379");
|
||||||
|
// return Redisson.create(config);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//}
|
|
@ -0,0 +1,54 @@
|
||||||
|
package com.brook.common.utils;
|
||||||
|
|
||||||
|
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.util.Base64;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 安全服务工具类
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class SecurityUtils {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成BCryptPasswordEncoder密码
|
||||||
|
*
|
||||||
|
* @param password 密码
|
||||||
|
*
|
||||||
|
* @return 加密字符串
|
||||||
|
*/
|
||||||
|
public static String encryptPassword (String password, String salt) {
|
||||||
|
return encryptMD5(password, salt);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断密码是否相同
|
||||||
|
*
|
||||||
|
* @param rawPassword 真实密码
|
||||||
|
* @param encodedPassword 加密后字符
|
||||||
|
*
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public static boolean matchesPassword (String rawPassword, String salt, String encodedPassword) {
|
||||||
|
return encryptMD5(rawPassword, salt).equals(encodedPassword);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算字符串的MD5加密值,并返回Base64编码的字符串。
|
||||||
|
* @param password 要加密的字符串
|
||||||
|
* @return 加密后的Base64编码字符串
|
||||||
|
*/
|
||||||
|
public static String encryptMD5(String password, String salt) {
|
||||||
|
try {
|
||||||
|
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||||
|
md.update((password + salt).getBytes()); // 加盐处理
|
||||||
|
byte[] digest = md.digest();
|
||||||
|
return Base64.getEncoder().encodeToString(digest);
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,71 @@
|
||||||
|
package com.brook.common.utils;
|
||||||
|
|
||||||
|
import org.springframework.util.AntPathMatcher;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName StringUtils
|
||||||
|
* @Description 字符串处理工具类
|
||||||
|
* @Author ChenLong
|
||||||
|
* @Date 2023/2/23 16:11
|
||||||
|
* @Version 1.0
|
||||||
|
*/
|
||||||
|
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<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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,87 @@
|
||||||
|
package com.brook.common.utils;//package com.brook.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 = "b92797ea69f44d2faec2c9e45878a6fd";
|
||||||
|
// private static String accessKeySecret = "7uridodUyzCSxfxRytHcVgWiefB6I5U2";
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * 短信访问域名
|
||||||
|
// */
|
||||||
|
// 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());
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//}
|
|
@ -0,0 +1,5 @@
|
||||||
|
com.brook.common.handler.GlobalExceptionHandler
|
||||||
|
com.brook.common.redis.RedisCache
|
||||||
|
com.brook.common.remote.system.RemoteUserInfoFactory
|
||||||
|
com.brook.common.utils.RedisConfig
|
||||||
|
com.brook.common.remote.goods.RemoteGoodsFactory
|
|
@ -0,0 +1,63 @@
|
||||||
|
<?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.brook</groupId>
|
||||||
|
<artifactId>brook_week3</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>brook-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.brook</groupId>
|
||||||
|
<artifactId>brook-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>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<finalName>${project.artifactId}</finalName>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>repackage</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,29 @@
|
||||||
|
package com.brook.gateway;
|
||||||
|
|
||||||
|
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure;
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||||
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook.gateway
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:GateWayApplication
|
||||||
|
* @Date 2024/3/12:9:45
|
||||||
|
*/
|
||||||
|
@SpringBootApplication(exclude = {
|
||||||
|
DataSourceAutoConfiguration.class, DruidDataSourceAutoConfigure.class
|
||||||
|
})
|
||||||
|
@EnableDiscoveryClient
|
||||||
|
public class GateWayApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(GateWayApplication.class,args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.brook.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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName IgnoreWhiteConfig
|
||||||
|
* @Description 放行白名单配置
|
||||||
|
* @Author ChenLong
|
||||||
|
* @Date 2023/2/23 16:20
|
||||||
|
* @Version 1.0
|
||||||
|
*/
|
||||||
|
@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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,123 @@
|
||||||
|
package com.brook.gateway.filter;
|
||||||
|
|
||||||
|
import com.brook.common.constants.JwtConstants;
|
||||||
|
import com.brook.common.constants.TokenConstants;
|
||||||
|
import com.brook.common.redis.RedisCache;
|
||||||
|
import com.brook.common.utils.JwtUtils;
|
||||||
|
import com.brook.common.utils.StringUtils;
|
||||||
|
import com.brook.gateway.config.IgnoreWhiteConfig;
|
||||||
|
import com.brook.gateway.utils.GatewayUtils;
|
||||||
|
import io.jsonwebtoken.Claims;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
|
||||||
|
import org.springframework.cloud.gateway.filter.GlobalFilter;
|
||||||
|
import org.springframework.core.Ordered;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.HttpMethod;
|
||||||
|
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.bw.gateway.filter
|
||||||
|
* @Project: nacos-day4
|
||||||
|
* @name:LoginFilter
|
||||||
|
* @Date 2023/12/13:15:36
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class LoginFilter implements GlobalFilter, Ordered {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*@ClassName LoginFilter
|
||||||
|
*@Description 描述
|
||||||
|
*@Author ShuLing.Yan
|
||||||
|
*@Date 2023/12/13 :15:36
|
||||||
|
*/
|
||||||
|
|
||||||
|
private final IgnoreWhiteConfig ignoreWhiteConfig;
|
||||||
|
|
||||||
|
private final RedisCache redisCache;
|
||||||
|
|
||||||
|
public LoginFilter(IgnoreWhiteConfig ignoreWhiteConfig, RedisCache redisCache) {
|
||||||
|
this.ignoreWhiteConfig = ignoreWhiteConfig; //redis操作
|
||||||
|
this.redisCache = redisCache; //白名单
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
||||||
|
|
||||||
|
//请求作用域
|
||||||
|
ServerHttpRequest request = exchange.getRequest();
|
||||||
|
//请求头
|
||||||
|
HttpHeaders headers = request.getHeaders();
|
||||||
|
//请求方式
|
||||||
|
HttpMethod method = request.getMethod();
|
||||||
|
//header操作对象
|
||||||
|
ServerHttpRequest.Builder mutate = request.mutate();
|
||||||
|
|
||||||
|
String requestURI = request.getURI().getPath();
|
||||||
|
log.info("请求日志:url:[{}],请求方式:[{}]",requestURI,method);
|
||||||
|
|
||||||
|
List<String> whites = ignoreWhiteConfig.getWhites();
|
||||||
|
|
||||||
|
if(StringUtils.matches(requestURI,whites)){
|
||||||
|
return chain.filter(exchange);
|
||||||
|
}
|
||||||
|
|
||||||
|
String token = headers.getFirst("token");
|
||||||
|
|
||||||
|
if(StringUtils.isEmpty(token)){
|
||||||
|
return GatewayUtils.errorResponse(exchange,"令牌不能为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
Claims claims = JwtUtils.parseToken(token);
|
||||||
|
|
||||||
|
if(claims==null){
|
||||||
|
return GatewayUtils.errorResponse(exchange,"令牌已经过期");
|
||||||
|
}
|
||||||
|
|
||||||
|
String userKey = JwtUtils.getUserKey(claims);
|
||||||
|
|
||||||
|
Boolean isLogin = redisCache.hasKey(TokenConstants.LOGIN_TOKEN_KEY + userKey);
|
||||||
|
if(!isLogin){
|
||||||
|
return GatewayUtils.errorResponse(exchange,"登录已经过期");
|
||||||
|
}
|
||||||
|
|
||||||
|
long expire = redisCache.getExpire(TokenConstants.LOGIN_TOKEN_KEY + userKey);
|
||||||
|
|
||||||
|
long initExpire = 5*60*1000;
|
||||||
|
|
||||||
|
if(expire<(initExpire/2)){
|
||||||
|
redisCache.expire(TokenConstants.LOGIN_TOKEN_KEY+userKey,5,TimeUnit.MINUTES);
|
||||||
|
}
|
||||||
|
|
||||||
|
String userid = JwtUtils.getUserId(claims);
|
||||||
|
|
||||||
|
String username = JwtUtils.getUserName(claims);
|
||||||
|
// 设置用户信息到请求
|
||||||
|
GatewayUtils.addHeader(mutate, JwtConstants.USER_KEY, userKey);
|
||||||
|
|
||||||
|
GatewayUtils.addHeader(mutate, JwtConstants.DETAILS_USER_ID, userid);
|
||||||
|
|
||||||
|
GatewayUtils.addHeader(mutate, JwtConstants.DETAILS_USERNAME, username);
|
||||||
|
// 内部请求来源参数清除
|
||||||
|
GatewayUtils.removeHeader(mutate, TokenConstants.TOKEN);
|
||||||
|
|
||||||
|
|
||||||
|
return chain.filter(exchange.mutate().request(mutate.build()).build());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getOrder() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,78 @@
|
||||||
|
package com.brook.gateway.utils;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.brook.common.result.Result;
|
||||||
|
import com.brook.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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName GatewayUtils
|
||||||
|
* @Description 网关处理工具类
|
||||||
|
* @Author ChenLong
|
||||||
|
* @Date 2023/2/23 16:17
|
||||||
|
* @Version 1.0
|
||||||
|
*/
|
||||||
|
@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();
|
||||||
|
//String encode = URLEncoder.encode(valueStr, "utf-8");
|
||||||
|
// mutate.header(key, encode);
|
||||||
|
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) {
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
# Tomcat
|
||||||
|
server:
|
||||||
|
port: 18080
|
||||||
|
# Spring
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
# 应用名称
|
||||||
|
name: brook-gateway
|
||||||
|
profiles:
|
||||||
|
# 环境配置
|
||||||
|
active: dev
|
||||||
|
main:
|
||||||
|
# 允许使用循环引用
|
||||||
|
allow-circular-references: true
|
||||||
|
# 允许定义相同的bean对象 去覆盖原有的
|
||||||
|
allow-bean-definition-overriding: true
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
discovery:
|
||||||
|
# 服务注册地址
|
||||||
|
server-addr: 49.232.227.52:8848
|
||||||
|
namespace: 4cf48ba0-2ae3-4427-8892-ca501c8b740e
|
||||||
|
config:
|
||||||
|
# 配置中心地址
|
||||||
|
server-addr: 49.232.227.52:8848
|
||||||
|
# 配置文件格式
|
||||||
|
file-extension: yml
|
||||||
|
# 共享配置
|
||||||
|
shared-configs:
|
||||||
|
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||||
|
namespace: 4cf48ba0-2ae3-4427-8892-ca501c8b740e
|
|
@ -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.brook</groupId>
|
||||||
|
<artifactId>brook_week3</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>brook-brand</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.brook</groupId>
|
||||||
|
<artifactId>brook-common</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.brook;
|
||||||
|
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:BrandApplication
|
||||||
|
* @Date 2024/3/12:11:47
|
||||||
|
*/
|
||||||
|
@SpringBootApplication
|
||||||
|
@MapperScan("com.brook.mapper")
|
||||||
|
public class BrandApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(BrandApplication.class,args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
package com.brook.controller;
|
||||||
|
|
||||||
|
import com.brook.common.domain.Brand;
|
||||||
|
import com.brook.common.result.Result;
|
||||||
|
import com.brook.service.BrandService;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook.controller
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:BrandController
|
||||||
|
* @Date 2024/3/12:11:45
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/brand")
|
||||||
|
public class BrandController {
|
||||||
|
|
||||||
|
private final BrandService brandService;
|
||||||
|
|
||||||
|
public BrandController(BrandService brandService) {
|
||||||
|
this.brandService = brandService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/brandList")
|
||||||
|
public Result<List<Brand>> brandList(){
|
||||||
|
return Result.success(
|
||||||
|
brandService.list()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.brook.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.brook.common.domain.Brand;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook.mapper
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:BrandMapper
|
||||||
|
* @Date 2024/3/12:11:45
|
||||||
|
*/
|
||||||
|
public interface BrandMapper extends BaseMapper<Brand> {
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.brook.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.brook.common.domain.Brand;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook.service
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:BrandService
|
||||||
|
* @Date 2024/3/12:11:45
|
||||||
|
*/
|
||||||
|
public interface BrandService extends IService<Brand> {
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.brook.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.brook.common.domain.Brand;
|
||||||
|
import com.brook.mapper.BrandMapper;
|
||||||
|
import com.brook.service.BrandService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook.service.impl
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:BrandServiceImpl
|
||||||
|
* @Date 2024/3/12:11:45
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class BrandServiceImpl extends ServiceImpl<BrandMapper, Brand>
|
||||||
|
implements BrandService
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,62 @@
|
||||||
|
# Tomcat
|
||||||
|
server:
|
||||||
|
port: 9007
|
||||||
|
# Spring
|
||||||
|
spring:
|
||||||
|
main:
|
||||||
|
allow-circular-references: true
|
||||||
|
jackson:
|
||||||
|
date-format: yyyy-MM-dd HH:mm:ss
|
||||||
|
time-zone: GMT+8
|
||||||
|
application:
|
||||||
|
# 应用名称
|
||||||
|
name: brook-brand
|
||||||
|
profiles:
|
||||||
|
# 环境配置
|
||||||
|
active: dev
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
discovery:
|
||||||
|
# 服务注册地址
|
||||||
|
server-addr: 49.232.227.52:8848
|
||||||
|
namespace: 4cf48ba0-2ae3-4427-8892-ca501c8b740e
|
||||||
|
config:
|
||||||
|
# 配置中心地址
|
||||||
|
server-addr: 49.232.227.52:8848
|
||||||
|
# 配置文件格式
|
||||||
|
file-extension: yml
|
||||||
|
# 共享配置
|
||||||
|
shared-configs:
|
||||||
|
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||||
|
namespace: 4cf48ba0-2ae3-4427-8892-ca501c8b740e
|
||||||
|
rabbitmq:
|
||||||
|
host: 49.232.227.52
|
||||||
|
port: 5672
|
||||||
|
username: guest
|
||||||
|
password: guest
|
||||||
|
virtual-host: /
|
||||||
|
publisher-confirm-type: correlated #确认消息已发送到交换机(Exchange)
|
||||||
|
publisher-returns: true #确认消息已发送到队列(Queue)
|
||||||
|
listener:
|
||||||
|
simple:
|
||||||
|
prefetch: 1 # 每次只能获取一条,处理完成才能获取下一条
|
||||||
|
#acknowledge-mode: manual # 设置消费端手动ack确认
|
||||||
|
retry:
|
||||||
|
enabled: true # 是否支持重试
|
||||||
|
template:
|
||||||
|
# 只要消息抵达Queue,就会异步发送优先回调return firm
|
||||||
|
mandatory: true
|
||||||
|
redis:
|
||||||
|
host:49.232.227.52
|
||||||
|
fdfs:
|
||||||
|
so-timeout: 1500 # socket 连接时长
|
||||||
|
connect-timeout: 600 # 连接 tracker 服务器超时时长 upload
|
||||||
|
# 这两个是你服务器的 IP 地址,注意 23000 端口也要打开,阿里云服务器记得配置安全组。tracker 要和 stroage 服务进行交流
|
||||||
|
tracker-list: 49.232.227.52:22122
|
||||||
|
web-server-url: 49.232.227.52:8888
|
||||||
|
pool:
|
||||||
|
jmx-enabled: false
|
||||||
|
# 生成缩略图
|
||||||
|
thumb-image:
|
||||||
|
height: 500
|
||||||
|
width: 500
|
|
@ -0,0 +1,32 @@
|
||||||
|
<?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.brook</groupId>
|
||||||
|
<artifactId>brook_week3</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>brook-cart</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.brook</groupId>
|
||||||
|
<artifactId>brook-common</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.brook;
|
||||||
|
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:CartApplication
|
||||||
|
* @Date 2024/3/12:12:19
|
||||||
|
*/
|
||||||
|
@SpringBootApplication
|
||||||
|
@MapperScan("com.brook.mapper")
|
||||||
|
public class CartApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(CartApplication.class,args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,76 @@
|
||||||
|
package com.brook.controller;
|
||||||
|
|
||||||
|
import com.brook.common.domain.Cart;
|
||||||
|
import com.brook.common.domain.request.cart.CartAddReq;
|
||||||
|
import com.brook.common.result.Result;
|
||||||
|
import com.brook.service.CartService;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook.controller
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:CartController
|
||||||
|
* @Date 2024/3/12:12:16
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/cart")
|
||||||
|
public class CartController {
|
||||||
|
|
||||||
|
private final CartService cartService;
|
||||||
|
|
||||||
|
public CartController(CartService cartService) {
|
||||||
|
this.cartService = cartService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/cartList")
|
||||||
|
public Result<List<Cart>> cartList(){
|
||||||
|
return Result.success(
|
||||||
|
cartService.list()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/addCart")
|
||||||
|
public Result<String> addCart(@RequestBody CartAddReq cartAddReq){
|
||||||
|
|
||||||
|
if(cartAddReq.getTotal()<1){
|
||||||
|
return Result.error("商品数量不能小于1");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
cartService.save(
|
||||||
|
Cart.builder()
|
||||||
|
.goodsId(cartAddReq.getGoodsId())
|
||||||
|
.goodsName(cartAddReq.getGoodsName())
|
||||||
|
.brandName(cartAddReq.getBrandName())
|
||||||
|
.goodsPrice(cartAddReq.getGoodsPrice())
|
||||||
|
.total(cartAddReq.getTotal())
|
||||||
|
.totalPrice(cartAddReq.getTotalPrice())
|
||||||
|
.isTrue(0)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
|
||||||
|
return Result.success(
|
||||||
|
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.brook.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.brook.common.domain.Cart;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook.mapper
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:CartMapper
|
||||||
|
* @Date 2024/3/12:12:16
|
||||||
|
*/
|
||||||
|
public interface CartMapper extends BaseMapper<Cart> {
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.brook.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.brook.common.domain.Cart;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook.service
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:CartService
|
||||||
|
* @Date 2024/3/12:12:16
|
||||||
|
*/
|
||||||
|
public interface CartService extends IService<Cart> {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package com.brook.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.brook.common.domain.Cart;
|
||||||
|
import com.brook.mapper.CartMapper;
|
||||||
|
import com.brook.service.CartService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook.service.impl
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:CartServiceImpl
|
||||||
|
* @Date 2024/3/12:12:17
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class CartServiceImpl extends ServiceImpl<CartMapper, Cart>
|
||||||
|
implements CartService
|
||||||
|
{
|
||||||
|
|
||||||
|
private final CartMapper cartMapper;
|
||||||
|
|
||||||
|
|
||||||
|
public CartServiceImpl(CartMapper cartMapper) {
|
||||||
|
this.cartMapper = cartMapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,62 @@
|
||||||
|
# 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: brook-cart
|
||||||
|
profiles:
|
||||||
|
# 环境配置
|
||||||
|
active: dev
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
discovery:
|
||||||
|
# 服务注册地址
|
||||||
|
server-addr: 49.232.227.52:8848
|
||||||
|
namespace: 4cf48ba0-2ae3-4427-8892-ca501c8b740e
|
||||||
|
config:
|
||||||
|
# 配置中心地址
|
||||||
|
server-addr: 49.232.227.52:8848
|
||||||
|
# 配置文件格式
|
||||||
|
file-extension: yml
|
||||||
|
# 共享配置
|
||||||
|
shared-configs:
|
||||||
|
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||||
|
namespace: 4cf48ba0-2ae3-4427-8892-ca501c8b740e
|
||||||
|
rabbitmq:
|
||||||
|
host: 49.232.227.52
|
||||||
|
port: 5672
|
||||||
|
username: guest
|
||||||
|
password: guest
|
||||||
|
virtual-host: /
|
||||||
|
publisher-confirm-type: correlated #确认消息已发送到交换机(Exchange)
|
||||||
|
publisher-returns: true #确认消息已发送到队列(Queue)
|
||||||
|
listener:
|
||||||
|
simple:
|
||||||
|
prefetch: 1 # 每次只能获取一条,处理完成才能获取下一条
|
||||||
|
#acknowledge-mode: manual # 设置消费端手动ack确认
|
||||||
|
retry:
|
||||||
|
enabled: true # 是否支持重试
|
||||||
|
template:
|
||||||
|
# 只要消息抵达Queue,就会异步发送优先回调return firm
|
||||||
|
mandatory: true
|
||||||
|
redis:
|
||||||
|
host:49.232.227.52
|
||||||
|
fdfs:
|
||||||
|
so-timeout: 1500 # socket 连接时长
|
||||||
|
connect-timeout: 600 # 连接 tracker 服务器超时时长 upload
|
||||||
|
# 这两个是你服务器的 IP 地址,注意 23000 端口也要打开,阿里云服务器记得配置安全组。tracker 要和 stroage 服务进行交流
|
||||||
|
tracker-list: 49.232.227.52:22122
|
||||||
|
web-server-url: 49.232.227.52:8888
|
||||||
|
pool:
|
||||||
|
jmx-enabled: false
|
||||||
|
# 生成缩略图
|
||||||
|
thumb-image:
|
||||||
|
height: 500
|
||||||
|
width: 500
|
|
@ -0,0 +1,39 @@
|
||||||
|
<?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.brook</groupId>
|
||||||
|
<artifactId>brook_week3</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>brook-es</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.brook</groupId>
|
||||||
|
<artifactId>brook-common</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- SpringBoot Web-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.elasticsearch.client</groupId>
|
||||||
|
<artifactId>elasticsearch-rest-high-level-client</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,71 @@
|
||||||
|
package com.brook.es;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.brook.common.domain.Goods;
|
||||||
|
import com.brook.common.remote.RemoteGoodsService;
|
||||||
|
import org.elasticsearch.action.bulk.BulkRequest;
|
||||||
|
import org.elasticsearch.action.index.IndexRequest;
|
||||||
|
import org.elasticsearch.client.RequestOptions;
|
||||||
|
import org.elasticsearch.client.RestHighLevelClient;
|
||||||
|
import org.elasticsearch.index.query.MatchAllQueryBuilder;
|
||||||
|
import org.elasticsearch.index.query.QueryBuilders;
|
||||||
|
import org.elasticsearch.index.reindex.DeleteByQueryRequest;
|
||||||
|
import org.elasticsearch.xcontent.XContentType;
|
||||||
|
import org.springframework.boot.ApplicationArguments;
|
||||||
|
import org.springframework.boot.ApplicationRunner;
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook.es
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:EsApplication
|
||||||
|
* @Date 2024/3/12:10:44
|
||||||
|
*/
|
||||||
|
@SpringBootApplication
|
||||||
|
@EnableFeignClients(basePackages = "com.brook.**")
|
||||||
|
public class EsApplication implements ApplicationRunner {
|
||||||
|
|
||||||
|
|
||||||
|
private final RemoteGoodsService remoteGoodsService;
|
||||||
|
|
||||||
|
|
||||||
|
private final RestHighLevelClient client;
|
||||||
|
|
||||||
|
public EsApplication(RemoteGoodsService remoteGoodsService, RestHighLevelClient client) {
|
||||||
|
this.remoteGoodsService = remoteGoodsService;
|
||||||
|
this.client = client;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(ApplicationArguments args) throws Exception {
|
||||||
|
|
||||||
|
List<Goods> list = remoteGoodsService.goodsList().getData();
|
||||||
|
|
||||||
|
DeleteByQueryRequest deleteByQueryRequest = new DeleteByQueryRequest("goods");
|
||||||
|
MatchAllQueryBuilder matchAllQueryBuilder = QueryBuilders.matchAllQuery();
|
||||||
|
deleteByQueryRequest.setQuery(matchAllQueryBuilder);
|
||||||
|
|
||||||
|
client.deleteByQuery(deleteByQueryRequest, RequestOptions.DEFAULT);
|
||||||
|
|
||||||
|
BulkRequest bulkRequest = new BulkRequest("goods");
|
||||||
|
|
||||||
|
list.forEach(c->{
|
||||||
|
bulkRequest.add(new IndexRequest("goods").id(c.getGoodsId()+"").source(JSON.toJSONString(c), XContentType.JSON));
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
client.bulk(bulkRequest,RequestOptions.DEFAULT);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(EsApplication.class,args);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
package com.brook.es.config;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.apache.http.HttpHost;
|
||||||
|
import org.elasticsearch.client.RestClient;
|
||||||
|
import org.elasticsearch.client.RestHighLevelClient;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@ConfigurationProperties(prefix = "es")
|
||||||
|
@Data
|
||||||
|
@Log4j2
|
||||||
|
public class InitEsRestHighLevelClient {
|
||||||
|
private String host;
|
||||||
|
private Integer port;
|
||||||
|
private String scheme;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public RestHighLevelClient init() {
|
||||||
|
return new RestHighLevelClient(
|
||||||
|
RestClient.builder(new HttpHost(host,port,scheme))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
package com.brook.es.controller;
|
||||||
|
|
||||||
|
import com.brook.common.domain.Goods;
|
||||||
|
import com.brook.common.domain.request.es.GoodsReq;
|
||||||
|
import com.brook.common.result.PageResult;
|
||||||
|
import com.brook.common.result.Result;
|
||||||
|
import com.brook.es.service.EsService;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook.es.controller
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:EsController
|
||||||
|
* @Date 2024/3/12:10:36
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/es")
|
||||||
|
public class EsController {
|
||||||
|
|
||||||
|
private final EsService esService;
|
||||||
|
|
||||||
|
public EsController(EsService esService) {
|
||||||
|
this.esService = esService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/esList")
|
||||||
|
public Result<PageResult<Goods>> esList(@RequestBody GoodsReq goodsReq){
|
||||||
|
return Result.success(
|
||||||
|
esService.list(goodsReq)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.brook.es.service;
|
||||||
|
|
||||||
|
import com.brook.common.domain.Goods;
|
||||||
|
import com.brook.common.domain.request.es.GoodsReq;
|
||||||
|
import com.brook.common.result.PageResult;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook.es.service
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:EsService
|
||||||
|
* @Date 2024/3/12:10:36
|
||||||
|
*/
|
||||||
|
public interface EsService {
|
||||||
|
PageResult<Goods> list(GoodsReq goodsReq);
|
||||||
|
}
|
|
@ -0,0 +1,105 @@
|
||||||
|
package com.brook.es.service.impl;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.brook.common.domain.Goods;
|
||||||
|
import com.brook.common.domain.request.es.GoodsReq;
|
||||||
|
import com.brook.common.result.PageResult;
|
||||||
|
import com.brook.es.service.EsService;
|
||||||
|
import org.elasticsearch.action.search.SearchRequest;
|
||||||
|
import org.elasticsearch.action.search.SearchResponse;
|
||||||
|
import org.elasticsearch.client.RequestOptions;
|
||||||
|
import org.elasticsearch.client.RestHighLevelClient;
|
||||||
|
import org.elasticsearch.common.text.Text;
|
||||||
|
import org.elasticsearch.index.query.BoolQueryBuilder;
|
||||||
|
import org.elasticsearch.index.query.QueryBuilders;
|
||||||
|
import org.elasticsearch.search.SearchHit;
|
||||||
|
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||||
|
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
|
||||||
|
import org.elasticsearch.search.fetch.subphase.highlight.HighlightField;
|
||||||
|
import org.elasticsearch.search.sort.SortOrder;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook.es.service.impl
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:EsServiceImpl
|
||||||
|
* @Date 2024/3/12:10:36
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class EsServiceImpl implements EsService {
|
||||||
|
|
||||||
|
private final RestHighLevelClient client;
|
||||||
|
|
||||||
|
public EsServiceImpl(RestHighLevelClient client) {
|
||||||
|
this.client = client;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResult<Goods> list(GoodsReq goodsReq) {
|
||||||
|
|
||||||
|
long total = 0;
|
||||||
|
ArrayList<Goods> list = new ArrayList<>();
|
||||||
|
|
||||||
|
SearchRequest searchRequest = new SearchRequest("goods");
|
||||||
|
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
||||||
|
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
|
||||||
|
|
||||||
|
if(goodsReq.getGoodsName()!=null && !("").equals(goodsReq.getGoodsName())){
|
||||||
|
boolQueryBuilder.must(QueryBuilders.matchQuery("goodsName",goodsReq.getGoodsName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(goodsReq.getBrandId()!=null){
|
||||||
|
boolQueryBuilder.must(QueryBuilders.termQuery("brandId",goodsReq.getBrandId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
searchSourceBuilder.query(boolQueryBuilder);
|
||||||
|
searchSourceBuilder.sort("createTime", SortOrder.DESC);
|
||||||
|
searchSourceBuilder.from((goodsReq.getPageNum()-1)*goodsReq.getPageSize());
|
||||||
|
searchSourceBuilder.size(goodsReq.getPageSize());
|
||||||
|
|
||||||
|
HighlightBuilder highlightBuilder = new HighlightBuilder();
|
||||||
|
highlightBuilder.field("goodsName");
|
||||||
|
highlightBuilder.preTags("<span style=\"color: pink\">");
|
||||||
|
highlightBuilder.postTags("</span>");
|
||||||
|
|
||||||
|
searchSourceBuilder.highlighter(highlightBuilder);
|
||||||
|
|
||||||
|
searchRequest.source(searchSourceBuilder);
|
||||||
|
|
||||||
|
try {
|
||||||
|
SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT);
|
||||||
|
|
||||||
|
total = response.getHits().getTotalHits().value;
|
||||||
|
|
||||||
|
SearchHit[] hits = response.getHits().getHits();
|
||||||
|
for (SearchHit hit : hits) {
|
||||||
|
Goods goods = JSON.parseObject(hit.getSourceAsString(), Goods.class);
|
||||||
|
Map<String, HighlightField> highlightFields = hit.getHighlightFields();
|
||||||
|
HighlightField goodsName = highlightFields.get("goodsName");
|
||||||
|
if(goodsName!=null){
|
||||||
|
Text[] fragments = goodsName.fragments();
|
||||||
|
for (Text fragment : fragments) {
|
||||||
|
StringBuffer stringBuffer = new StringBuffer();
|
||||||
|
stringBuffer.append(fragment.toString());
|
||||||
|
goods.setGoodsName(stringBuffer.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
list.add(goods);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return PageResult.toPageResult(total,list);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
# Tomcat
|
||||||
|
server:
|
||||||
|
port: 9006
|
||||||
|
# Spring
|
||||||
|
spring:
|
||||||
|
main:
|
||||||
|
allow-circular-references: true
|
||||||
|
jackson:
|
||||||
|
date-format: yyyy-MM-dd HH:mm:ss
|
||||||
|
time-zone: GMT+8
|
||||||
|
application:
|
||||||
|
# 应用名称
|
||||||
|
name: brook-es
|
||||||
|
profiles:
|
||||||
|
# 环境配置
|
||||||
|
active: dev
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
discovery:
|
||||||
|
# 服务注册地址
|
||||||
|
server-addr: 49.232.227.52:8848
|
||||||
|
namespace: 4cf48ba0-2ae3-4427-8892-ca501c8b740e
|
||||||
|
config:
|
||||||
|
# 配置中心地址
|
||||||
|
server-addr: 49.232.227.52:8848
|
||||||
|
# 配置文件格式
|
||||||
|
file-extension: yml
|
||||||
|
# 共享配置
|
||||||
|
shared-configs:
|
||||||
|
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||||
|
namespace: 4cf48ba0-2ae3-4427-8892-ca501c8b740e
|
|
@ -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.brook</groupId>
|
||||||
|
<artifactId>brook_week3</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>brook-goods</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.brook</groupId>
|
||||||
|
<artifactId>brook-common</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.brook;
|
||||||
|
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:GoodsApplication
|
||||||
|
* @Date 2024/3/12:10:09
|
||||||
|
*/
|
||||||
|
@SpringBootApplication
|
||||||
|
@MapperScan("com.brook.mapper")
|
||||||
|
@EnableTransactionManagement
|
||||||
|
public class GoodsApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(GoodsApplication.class,args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,76 @@
|
||||||
|
package com.brook.controller;
|
||||||
|
|
||||||
|
import com.brook.common.domain.Address;
|
||||||
|
import com.brook.common.domain.Goods;
|
||||||
|
import com.brook.common.domain.request.address.AddressReq;
|
||||||
|
import com.brook.common.result.Result;
|
||||||
|
import com.brook.service.GoodsService;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook.controller
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:GoodsController
|
||||||
|
* @Date 2024/3/12:10:05
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/goods")
|
||||||
|
public class GoodsController {
|
||||||
|
|
||||||
|
private final GoodsService goodsService;
|
||||||
|
|
||||||
|
public GoodsController(GoodsService goodsService) {
|
||||||
|
this.goodsService = goodsService;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping("/getGoodsList")
|
||||||
|
public Result<List<Goods>> goodsList(){
|
||||||
|
return Result.success(
|
||||||
|
goodsService.getList()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping("/addressList")
|
||||||
|
public Result<List<Address>> addressList(){
|
||||||
|
return Result.success(
|
||||||
|
goodsService.addressList()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("/addressReq")
|
||||||
|
public Result<String> addressReq(@RequestBody AddressReq addressReq){
|
||||||
|
return Result.success(
|
||||||
|
goodsService.add(addressReq)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
package com.brook.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.brook.common.domain.Address;
|
||||||
|
import com.brook.common.domain.Goods;
|
||||||
|
import com.brook.common.domain.request.address.AddressReq;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook.mapper
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:GoodsMapper
|
||||||
|
* @Date 2024/3/12:10:05
|
||||||
|
*/
|
||||||
|
public interface GoodsMapper extends BaseMapper<Goods> {
|
||||||
|
List<Goods> getList();
|
||||||
|
|
||||||
|
|
||||||
|
List<Address> addressList(@Param("id") Long id);
|
||||||
|
|
||||||
|
String add(AddressReq addressReq);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
package com.brook.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.brook.common.domain.Address;
|
||||||
|
import com.brook.common.domain.Goods;
|
||||||
|
import com.brook.common.domain.request.address.AddressReq;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook.service
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:GoodsService
|
||||||
|
* @Date 2024/3/12:10:06
|
||||||
|
*/
|
||||||
|
public interface GoodsService extends IService<Goods> {
|
||||||
|
List<Goods> getList();
|
||||||
|
|
||||||
|
|
||||||
|
List<Address> addressList();
|
||||||
|
|
||||||
|
|
||||||
|
String add(AddressReq addressReq);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,67 @@
|
||||||
|
package com.brook.service.impl;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.brook.common.constants.JwtConstants;
|
||||||
|
import com.brook.common.constants.TokenConstants;
|
||||||
|
import com.brook.common.domain.Address;
|
||||||
|
import com.brook.common.domain.Goods;
|
||||||
|
import com.brook.common.domain.UserInfo;
|
||||||
|
import com.brook.common.domain.request.address.AddressReq;
|
||||||
|
import com.brook.common.redis.RedisCache;
|
||||||
|
import com.brook.mapper.GoodsMapper;
|
||||||
|
import com.brook.service.GoodsService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook.service.impl
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:GoodsServiceImpl
|
||||||
|
* @Date 2024/3/12:10:06
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods>
|
||||||
|
implements GoodsService
|
||||||
|
{
|
||||||
|
private final GoodsMapper goodsMapper;
|
||||||
|
|
||||||
|
private final RedisCache redisCache;
|
||||||
|
|
||||||
|
private final HttpServletRequest request;
|
||||||
|
|
||||||
|
public GoodsServiceImpl(GoodsMapper goodsMapper, RedisCache redisCache, HttpServletRequest request) {
|
||||||
|
this.goodsMapper = goodsMapper;
|
||||||
|
this.redisCache = redisCache;
|
||||||
|
this.request = request;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Goods> getList() {
|
||||||
|
return goodsMapper.getList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Address> addressList() {
|
||||||
|
|
||||||
|
String token = request.getHeader(JwtConstants.USER_KEY);
|
||||||
|
|
||||||
|
String userKey = redisCache.getCacheObject(TokenConstants.LOGIN_TOKEN_KEY + token);
|
||||||
|
|
||||||
|
UserInfo userInfo = JSON.parseObject(userKey, UserInfo.class);
|
||||||
|
|
||||||
|
List<Address> addressList = goodsMapper.addressList(userInfo.getId());
|
||||||
|
|
||||||
|
return addressList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String add(AddressReq addressReq) {
|
||||||
|
return goodsMapper.add(addressReq);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,62 @@
|
||||||
|
# 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: brook-goods
|
||||||
|
profiles:
|
||||||
|
# 环境配置
|
||||||
|
active: dev
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
discovery:
|
||||||
|
# 服务注册地址
|
||||||
|
server-addr: 49.232.227.52:8848
|
||||||
|
namespace: 4cf48ba0-2ae3-4427-8892-ca501c8b740e
|
||||||
|
config:
|
||||||
|
# 配置中心地址
|
||||||
|
server-addr: 49.232.227.52:8848
|
||||||
|
# 配置文件格式
|
||||||
|
file-extension: yml
|
||||||
|
# 共享配置
|
||||||
|
shared-configs:
|
||||||
|
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||||
|
namespace: 4cf48ba0-2ae3-4427-8892-ca501c8b740e
|
||||||
|
rabbitmq:
|
||||||
|
host: 49.232.227.52
|
||||||
|
port: 5672
|
||||||
|
username: guest
|
||||||
|
password: guest
|
||||||
|
virtual-host: /
|
||||||
|
publisher-confirm-type: correlated #确认消息已发送到交换机(Exchange)
|
||||||
|
publisher-returns: true #确认消息已发送到队列(Queue)
|
||||||
|
listener:
|
||||||
|
simple:
|
||||||
|
prefetch: 1 # 每次只能获取一条,处理完成才能获取下一条
|
||||||
|
#acknowledge-mode: manual # 设置消费端手动ack确认
|
||||||
|
retry:
|
||||||
|
enabled: true # 是否支持重试
|
||||||
|
template:
|
||||||
|
# 只要消息抵达Queue,就会异步发送优先回调return firm
|
||||||
|
mandatory: true
|
||||||
|
redis:
|
||||||
|
host:49.232.227.52
|
||||||
|
fdfs:
|
||||||
|
so-timeout: 1500 # socket 连接时长
|
||||||
|
connect-timeout: 600 # 连接 tracker 服务器超时时长 upload
|
||||||
|
# 这两个是你服务器的 IP 地址,注意 23000 端口也要打开,阿里云服务器记得配置安全组。tracker 要和 stroage 服务进行交流
|
||||||
|
tracker-list: 49.232.227.52:22122
|
||||||
|
web-server-url: 49.232.227.52:8888
|
||||||
|
pool:
|
||||||
|
jmx-enabled: false
|
||||||
|
# 生成缩略图
|
||||||
|
thumb-image:
|
||||||
|
height: 500
|
||||||
|
width: 500
|
|
@ -0,0 +1,27 @@
|
||||||
|
<?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">
|
||||||
|
<!--
|
||||||
|
1.在mybats的开发中namespace有特殊的意思,一定要是对应接口的全限定名
|
||||||
|
通过namespace可以简历mapper.xml和接口之间的关系(名字不重要,位置不重要)
|
||||||
|
-->
|
||||||
|
<mapper namespace="com.brook.mapper.GoodsMapper">
|
||||||
|
<insert id="add">
|
||||||
|
insert into address values(0,#{userId},#{addressName})
|
||||||
|
</insert>
|
||||||
|
<select id="addressList" resultType="com.brook.common.domain.Address">
|
||||||
|
select * from address where user_id = #{id}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
<select id="getList" resultType="com.brook.common.domain.Goods">
|
||||||
|
SELECT
|
||||||
|
g.*,
|
||||||
|
brand_name
|
||||||
|
FROM
|
||||||
|
goods g
|
||||||
|
LEFT JOIN brand b ON g.brand_id = b.brand_id
|
||||||
|
where is_meanwhile = 0 limit 1000
|
||||||
|
</select>
|
||||||
|
</mapper>
|
|
@ -0,0 +1,32 @@
|
||||||
|
<?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.brook</groupId>
|
||||||
|
<artifactId>brook_week3</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>brook-single</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.brook</groupId>
|
||||||
|
<artifactId>brook-common</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.brook;
|
||||||
|
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:SingleApplication
|
||||||
|
* @Date 2024/3/12:13:40
|
||||||
|
*/
|
||||||
|
@SpringBootApplication
|
||||||
|
@MapperScan("com.brook.mapper")
|
||||||
|
public class SingleApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(SingleApplication.class,args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,62 @@
|
||||||
|
package com.brook.controller;
|
||||||
|
|
||||||
|
import com.brook.common.domain.Single;
|
||||||
|
import com.brook.common.domain.request.single.SingleReq;
|
||||||
|
import com.brook.common.result.Result;
|
||||||
|
import com.brook.service.SingleService;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook.controller
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:SingleController
|
||||||
|
* @Date 2024/3/12:13:31
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/single")
|
||||||
|
public class SingleController {
|
||||||
|
|
||||||
|
private final SingleService singleService;
|
||||||
|
|
||||||
|
|
||||||
|
public SingleController(SingleService singleService) {
|
||||||
|
this.singleService = singleService;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("/addSingle")
|
||||||
|
public Result<String> single(@RequestBody SingleReq singleReq){
|
||||||
|
|
||||||
|
singleService.save(
|
||||||
|
Single.builder()
|
||||||
|
.goodsId(singleReq.getGoodsId())
|
||||||
|
.total(singleReq.getTotal())
|
||||||
|
.totalPrice(singleReq.getTotalPrice())
|
||||||
|
.userId(singleReq.getUserId())
|
||||||
|
.createTime(new Date())
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.brook.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.brook.common.domain.Single;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook.mapper
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:SingleMapper
|
||||||
|
* @Date 2024/3/12:13:31
|
||||||
|
*/
|
||||||
|
public interface SingleMapper extends BaseMapper<Single> {
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.brook.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.brook.common.domain.Single;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook.service
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:SingleService
|
||||||
|
* @Date 2024/3/12:13:32
|
||||||
|
*/
|
||||||
|
public interface SingleService extends IService<Single> {
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.brook.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.brook.common.domain.Single;
|
||||||
|
import com.brook.mapper.SingleMapper;
|
||||||
|
import com.brook.service.SingleService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook.service.impl
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:Single
|
||||||
|
* @Date 2024/3/12:13:32
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class SingleServiceImpl extends ServiceImpl<SingleMapper, Single>
|
||||||
|
implements SingleService
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
# Tomcat
|
||||||
|
server:
|
||||||
|
port: 9005
|
||||||
|
# Spring
|
||||||
|
spring:
|
||||||
|
main:
|
||||||
|
allow-circular-references: true
|
||||||
|
jackson:
|
||||||
|
date-format: yyyy-MM-dd HH:mm:ss
|
||||||
|
time-zone: GMT+8
|
||||||
|
application:
|
||||||
|
# 应用名称
|
||||||
|
name: brook-single
|
||||||
|
profiles:
|
||||||
|
# 环境配置
|
||||||
|
active: dev
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
discovery:
|
||||||
|
# 服务注册地址
|
||||||
|
server-addr: 49.232.227.52:8848
|
||||||
|
namespace: 4cf48ba0-2ae3-4427-8892-ca501c8b740e
|
||||||
|
config:
|
||||||
|
# 配置中心地址
|
||||||
|
server-addr: 49.232.227.52:8848
|
||||||
|
# 配置文件格式
|
||||||
|
file-extension: yml
|
||||||
|
# 共享配置
|
||||||
|
shared-configs:
|
||||||
|
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||||
|
namespace: 4cf48ba0-2ae3-4427-8892-ca501c8b740e
|
|
@ -0,0 +1,32 @@
|
||||||
|
<?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.brook</groupId>
|
||||||
|
<artifactId>brook_week3</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>brook-system</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.brook</groupId>
|
||||||
|
<artifactId>brook-common</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.brook;
|
||||||
|
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author YanShuLing
|
||||||
|
* @Package:com.brook
|
||||||
|
* @Project: brook_week3
|
||||||
|
* @Description TODO
|
||||||
|
* @name:UserInfoApplication
|
||||||
|
* @Date 2024/3/12:9:22
|
||||||
|
*/
|
||||||
|
@SpringBootApplication
|
||||||
|
@MapperScan("com.brook.mapper")
|
||||||
|
public class UserInfoApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(UserInfoApplication.class,args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue