1.初始化
commit
4df18c8ef6
|
@ -0,0 +1,35 @@
|
|||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.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,42 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>h6-exam812</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>cloud-auth</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- 项目公共 依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common</artifactId>
|
||||
</dependency>
|
||||
<!-- SpringBoot Web-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>system-remote</artifactId>
|
||||
</dependency>
|
||||
<!-- Test-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,33 @@
|
|||
package com.muyu;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Data 2024/7/10
|
||||
* @注释
|
||||
*/
|
||||
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
|
||||
@EnableFeignClients("com.muyu.**.remote")
|
||||
public class AuthApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(AuthApplication.class,args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public BCryptPasswordEncoder bCryptPasswordEncoder(){
|
||||
BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
|
||||
return bCryptPasswordEncoder;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
package com.muyu.cloud.auth.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.muyu.cloud.auth.domain.request.UserReq;
|
||||
import com.muyu.cloud.auth.domain.response.TokenRes;
|
||||
import com.muyu.cloud.auth.service.AuthService;
|
||||
import com.muyu.cloud.system.domain.UserInfo;
|
||||
import com.muyu.common.result.Result;
|
||||
import com.mysql.cj.PreparedQuery;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/7/10
|
||||
* @注释
|
||||
*/
|
||||
@RestController
|
||||
@Log4j2
|
||||
public class AuthController {
|
||||
@Resource
|
||||
private AuthService authService;
|
||||
|
||||
@Resource
|
||||
private HttpServletRequest request;
|
||||
|
||||
@PostMapping("/loginUser")
|
||||
public Result<TokenRes> loginUser(@RequestBody UserReq userReq){
|
||||
//登录成功
|
||||
UserInfo userInfo = authService.loginUser(userReq);
|
||||
//生成token令牌
|
||||
TokenRes tokenRes = authService.getToken(userInfo);
|
||||
return Result.success(tokenRes);
|
||||
}
|
||||
|
||||
@GetMapping("/getInfo")
|
||||
public Result<UserInfo> getInfo(@RequestHeader("user_key") String user_key){
|
||||
log.info("功能:验证身份开始,请求路径:[{}],请求方法:[{}],请求参数:[{}]",request.getRequestURI(),request.getMethod(),user_key);
|
||||
UserInfo userInfo = authService.getInfo(user_key);
|
||||
log.info("功能:验证身份开始,请求路径:[{}],请求方法:[{}],响应值:[{}]",request.getRequestURI(),request.getMethod(), JSONObject.toJSONString(userInfo));
|
||||
|
||||
return Result.success(userInfo,"验证成功");
|
||||
}
|
||||
|
||||
@GetMapping("/logout")
|
||||
public Result<?> logout(@RequestHeader("user_key") String user_key){
|
||||
log.info("功能:注销开始,请求路径:[{}],请求方法:[{}],请求参数:[{}]",request.getRequestURI(),request.getMethod(),user_key);
|
||||
authService.logout(user_key);
|
||||
log.info("功能:注销结束,请求路径:[{}],请求方法:[{}]",request.getRequestURI(),request.getMethod());
|
||||
return Result.success(null,"注销成功");
|
||||
}
|
||||
|
||||
@GetMapping("/sendCode/{userTel}")
|
||||
public Result sendCode(@PathVariable("userTel") String userTel){
|
||||
authService.sendCode(userTel);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.muyu.cloud.auth.domain.request;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/7/10
|
||||
* @注释
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class UserReq {
|
||||
|
||||
@NotBlank(message = "手机号不能为空")
|
||||
private String userTel;
|
||||
private String code;
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package com.muyu.cloud.auth.domain.response;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/7/10
|
||||
* @注释
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class TokenRes {
|
||||
private String token;
|
||||
private long tokenDate;
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package com.muyu.cloud.auth.service;
|
||||
|
||||
import com.muyu.cloud.auth.domain.request.UserReq;
|
||||
import com.muyu.cloud.auth.domain.response.TokenRes;
|
||||
import com.muyu.cloud.system.domain.UserInfo;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/7/10
|
||||
* @注释
|
||||
*/
|
||||
public interface AuthService {
|
||||
UserInfo loginUser(UserReq userReq);
|
||||
|
||||
TokenRes getToken(UserInfo userInfo);
|
||||
|
||||
UserInfo getInfo(String userKey);
|
||||
|
||||
void logout(String userKey);
|
||||
|
||||
void sendCode(String userTel);
|
||||
}
|
|
@ -0,0 +1,137 @@
|
|||
package com.muyu.cloud.auth.service.impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.muyu.cloud.auth.domain.request.UserReq;
|
||||
import com.muyu.cloud.auth.domain.response.TokenRes;
|
||||
import com.muyu.cloud.auth.service.AuthService;
|
||||
import com.muyu.cloud.system.domain.UserInfo;
|
||||
import com.muyu.cloud.system.remote.RemoteUserInfoService;
|
||||
import com.muyu.common.constant.JwtConstants;
|
||||
import com.muyu.common.constant.MQQueueNameConstants;
|
||||
import com.muyu.common.constant.TokenConstants;
|
||||
import com.muyu.common.redis.service.RedisService;
|
||||
import com.muyu.common.result.Result;
|
||||
import com.muyu.common.utils.JwtUtils;
|
||||
import com.muyu.common.utils.TelSmsUtils;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.amqp.rabbit.annotation.Queue;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/7/10
|
||||
* @注释
|
||||
*/
|
||||
@Service
|
||||
@Log4j2
|
||||
public class AuthServiceImpl implements AuthService {
|
||||
@Resource
|
||||
private RemoteUserInfoService remoteUserInfoService;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Resource
|
||||
private RedisService redisService;
|
||||
|
||||
@Resource
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
|
||||
@Override
|
||||
public UserInfo loginUser(UserReq userReq) {
|
||||
//账号需要非空校验
|
||||
if(Objects.isNull(userReq)){
|
||||
log.info("账号[{}]为空,请重新输入", JSONObject.toJSONString(userReq));
|
||||
|
||||
throw new RuntimeException("账号[{"+JSONObject.toJSONString(userReq)+"}]为空,请重新输入");
|
||||
}
|
||||
//远调账号是否存在
|
||||
Result<UserInfo> login = remoteUserInfoService.login(userReq.getUserTel());
|
||||
UserInfo data = login.getData();
|
||||
if(Objects.isNull(data)){ //不存在
|
||||
log.info("账号[{}]尚未注册,请先注册",JSONObject.toJSONString(userReq));
|
||||
throw new RuntimeException("账号[{"+JSONObject.toJSONString(userReq)+"}]尚未注册,请先注册");
|
||||
}
|
||||
|
||||
//code验证
|
||||
String cacheUserTel = redisService.getCacheObject(JwtConstants.DETAILS_USERPHONE + userReq.getUserTel());
|
||||
if(!cacheUserTel.equals(userReq.getCode())){
|
||||
log.info("验证码[{}]输入错误请重新输入",userReq.getCode());
|
||||
throw new RuntimeException("验证码[{"+userReq.getCode()+"}]输入错误请重新输入");
|
||||
}
|
||||
|
||||
//登录成功
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public TokenRes getToken(UserInfo userInfo) {
|
||||
//账号需要非空校验
|
||||
if(Objects.isNull(userInfo)){
|
||||
log.info("账号[{}]为空,请重新输入", JSONObject.toJSONString(userInfo));
|
||||
|
||||
throw new RuntimeException("账号[{"+JSONObject.toJSONString(userInfo)+"}]为空,请重新输入");
|
||||
}
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
String userKey = UUID.randomUUID().toString().replace("-", "");
|
||||
//redis存储userInfo
|
||||
redisService.setCacheObject(JwtConstants.USER_KEY+userKey,userInfo);
|
||||
//生成token
|
||||
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);
|
||||
//redis存储token 登录成功后使用JWT生成token过期时间为15分钟,过期时间使用redis
|
||||
redisService.setCacheObject(TokenConstants.TOKEN+token,token,15L, TimeUnit.MINUTES);
|
||||
|
||||
return TokenRes.builder()
|
||||
.token(token)
|
||||
.tokenDate(15L)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserInfo getInfo(String userKey) {
|
||||
UserInfo cacheUserInfo = redisService.getCacheObject(JwtConstants.USER_KEY + userKey);
|
||||
return cacheUserInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logout(String userKey) {
|
||||
if(redisService.hasKey(userKey)){
|
||||
redisService.deleteObject(userKey);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendCode(String userTel) {
|
||||
/**
|
||||
* 发送短信验证码
|
||||
*/
|
||||
rabbitTemplate.convertAndSend(MQQueueNameConstants.SMS_QUEUE_NAME,userTel,message -> {
|
||||
message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
|
||||
return message;
|
||||
});
|
||||
}
|
||||
|
||||
//监听rabbitMQ
|
||||
@RabbitListener(queuesToDeclare = {@Queue (name = MQQueueNameConstants.SMS_QUEUE_NAME)})
|
||||
public void getMessage(String message){
|
||||
System.out.println("接收到的消息为:"+message);
|
||||
String code = String.valueOf(new Random().nextInt(9000)+1000);
|
||||
redisService.setCacheObject(JwtConstants.DETAILS_USERPHONE+message,code,5L,TimeUnit.MINUTES);
|
||||
System.out.println("验证码是:"+code);
|
||||
TelSmsUtils.sendSms(message,code);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
# Tomcat
|
||||
server:
|
||||
port: 8266
|
||||
|
||||
|
||||
# 配置nacos的地址
|
||||
nacos:
|
||||
server-addr: 1.94.37.42:8848
|
||||
|
||||
|
||||
# Spring
|
||||
spring:
|
||||
rabbitmq:
|
||||
host: 1.94.37.42
|
||||
port: 5672
|
||||
publisher-confirm-type: correlated #消息发送到交换机确认
|
||||
publisher-returns: true #允许发送到消息队列的确认
|
||||
username: user
|
||||
password: xyr070903
|
||||
application:
|
||||
# 应用名称
|
||||
name: cloud-auth
|
||||
profiles:
|
||||
# 环境配置
|
||||
active: dev
|
||||
main:
|
||||
# 允许使用循环引用
|
||||
allow-circular-references: true
|
||||
# 允许定义相同的bean对象 去覆盖原有的
|
||||
allow-bean-definition-overriding: true
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: ${nacos.server-addr}
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: ${nacos.server-addr}
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
shared-configs:
|
||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
# 程序Redis公共配置文件
|
||||
- redis-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
package com.muyu.test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/6/12 9:28
|
||||
* @注释
|
||||
*/
|
||||
@SpringBootTest
|
||||
public class BcryPassword {
|
||||
@Resource
|
||||
private BCryptPasswordEncoder bCryptPasswordEncoder;
|
||||
|
||||
@Test
|
||||
public void getPassword(){
|
||||
String encode = bCryptPasswordEncoder.encode("123456");
|
||||
System.out.println("密码123456加密后为:"+encode);
|
||||
System.out.println(bCryptPasswordEncoder.matches("123456",encode));
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,160 @@
|
|||
<?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.muyu</groupId>
|
||||
<artifactId>h6-exam812</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>cloud-common</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- bootstrap 启动器 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
||||
</dependency>
|
||||
<!-- SpringCloud Alibaba Nacos -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
<!-- SpringCloud Alibaba Nacos Config -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||
</dependency>
|
||||
<!-- SpringCloud Alibaba Sentinel -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
||||
</dependency>
|
||||
<!-- 负载均衡-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
|
||||
</dependency>
|
||||
<!-- SpringCloud Openfeign -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
</dependency>
|
||||
<!-- JWT -->
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt</artifactId>
|
||||
<version>0.9.1</version>
|
||||
</dependency>
|
||||
<!-- Alibaba Fastjson -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>1.2.80</version>
|
||||
</dependency>
|
||||
<!-- Alibaba Fastjson2 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2</artifactId>
|
||||
<version>2.0.50</version>
|
||||
</dependency>
|
||||
<!-- SpringBoot Boot Redis -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
</dependency>
|
||||
<!-- Druid -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
<version>1.2.8</version>
|
||||
</dependency>
|
||||
<!-- Mysql Connector -->
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
</dependency>
|
||||
<!-- Mybatis 依赖配置 -->
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>2.2.2</version>
|
||||
</dependency>
|
||||
<!-- Pagehelper -->
|
||||
<dependency>
|
||||
<groupId>com.github.pagehelper</groupId>
|
||||
<artifactId>pagehelper-spring-boot-starter</artifactId>
|
||||
<version>1.4.1</version>
|
||||
</dependency>
|
||||
<!-- 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>com.aliyun</groupId>
|
||||
<artifactId>dysmsapi20170525</artifactId>
|
||||
<version>2.0.1</version>
|
||||
</dependency>
|
||||
<!-- rabbitMQ依赖-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||
<version>3.2.6</version>
|
||||
</dependency>
|
||||
<!--fdfs上传图片-->
|
||||
<dependency>
|
||||
<groupId>com.github.tobato</groupId>
|
||||
<artifactId>fastdfs-client</artifactId>
|
||||
<version>1.26.5</version>
|
||||
</dependency>
|
||||
<!-- oss -->
|
||||
<dependency>
|
||||
<groupId>com.aliyun.oss</groupId>
|
||||
<artifactId>aliyun-sdk-oss</artifactId>
|
||||
<version>3.12.0</version>
|
||||
</dependency>
|
||||
<!-- swagger3 -->
|
||||
<dependency>
|
||||
<groupId>io.swagger.core.v3</groupId>
|
||||
<artifactId>swagger-annotations-jakarta</artifactId>
|
||||
<version>2.2.8</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
<!--锁依赖-->
|
||||
<dependency>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
<version>3.7.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.redisson</groupId>
|
||||
<artifactId>redisson</artifactId>
|
||||
<version>3.16.0</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
|
@ -0,0 +1,22 @@
|
|||
package com.muyu.common.config;
|
||||
|
||||
import com.muyu.common.result.Result;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
/**
|
||||
* @Author: xe ya ru
|
||||
* @Description: 异常处理器
|
||||
* @Data 2024/7/10
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Log4j2
|
||||
@RestControllerAdvice
|
||||
public class ExceptionHandler {
|
||||
|
||||
@org.springframework.web.bind.annotation.ExceptionHandler(value = RuntimeException.class)
|
||||
public Result<String> runtimeExceptionHandler(RuntimeException e) {
|
||||
log.error("程序请求异常:[{}]",e.getMessage(), e);
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package com.muyu.common.config;
|
||||
|
||||
import org.springframework.amqp.rabbit.connection.CorrelationData;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/7/10
|
||||
* @确认机制
|
||||
*/
|
||||
@Component
|
||||
public class MyConfirmCallback implements RabbitTemplate.ConfirmCallback {
|
||||
|
||||
@Autowired
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 回调确认
|
||||
* @param correlationData
|
||||
* @param ack
|
||||
* @param cause
|
||||
*/
|
||||
@Override
|
||||
public void confirm(CorrelationData correlationData, boolean ack, String cause) {
|
||||
if(ack){
|
||||
System.out.println("消息发送到broker成功");
|
||||
}else{
|
||||
System.out.println("消息发送到broker失败,原因是"+cause);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.muyu.common.config;
|
||||
|
||||
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
|
||||
import org.springframework.amqp.support.converter.MessageConverter;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/7/10
|
||||
* @注释
|
||||
*/
|
||||
@Configuration
|
||||
public class RabbitmqConfig {
|
||||
|
||||
|
||||
@Bean
|
||||
public MessageConverter jsonMessageConverter(){
|
||||
return new Jackson2JsonMessageConverter();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.muyu.common.config;
|
||||
|
||||
import org.springframework.amqp.core.ReturnedMessage;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/7/10
|
||||
* @回退机制
|
||||
*/
|
||||
@Component
|
||||
public class ReturnCallbackConfig implements RabbitTemplate.ReturnsCallback {
|
||||
|
||||
@Autowired
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
public void init() {
|
||||
rabbitTemplate.setReturnsCallback(this);
|
||||
}
|
||||
@Override
|
||||
public void returnedMessage(ReturnedMessage returnedMessage) {
|
||||
System.out.println("消息:"+returnedMessage.getMessage().toString()+"回退"+"被回退到交换机:"+returnedMessage.getExchange()+"拖回原因:"+returnedMessage.getReplyText());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.muyu.common.constant;
|
||||
|
||||
/**
|
||||
* @description: 系统常量
|
||||
* @author xie ya ru
|
||||
* @Data 2024/7/10
|
||||
*/
|
||||
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 = "操作异常";
|
||||
|
||||
/**
|
||||
* 自动识别json对象白名单配置(仅允许解析的包名,范围越小越安全)
|
||||
*/
|
||||
public static final String[] JSON_WHITELIST_STR = {"org.springframework", "com.muyu"};
|
||||
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.muyu.common.constant;
|
||||
|
||||
/**
|
||||
* @author xie ya ru
|
||||
* @description: Jwt常量
|
||||
* @Data 2024/7/10
|
||||
*/
|
||||
public class JwtConstants {
|
||||
/**
|
||||
* 用户ID字段
|
||||
*/
|
||||
public static final String DETAILS_USER_ID = "user_id";
|
||||
|
||||
/**
|
||||
* 用户名字段
|
||||
*/
|
||||
public static final String DETAILS_USERNAME = "username";
|
||||
|
||||
/*
|
||||
用户手机号
|
||||
*/
|
||||
public static final String DETAILS_USERPHONE ="userPhone";
|
||||
|
||||
/**
|
||||
* 用户标识
|
||||
*/
|
||||
public static final String USER_KEY = "user_key";
|
||||
|
||||
/**
|
||||
* 令牌秘钥
|
||||
*/
|
||||
public final static String SECRET = "abcdefghijklmnopqrstuvwxyz";
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.muyu.common.constant;
|
||||
|
||||
/**
|
||||
* @ClassName:
|
||||
* @Description: 消息队列名称常量
|
||||
* @Data 2024/7/10
|
||||
* @Author: xie ya ru
|
||||
*/
|
||||
public class MQQueueNameConstants {
|
||||
|
||||
/**
|
||||
* 短信队列名称
|
||||
*/
|
||||
public static final String SMS_QUEUE_NAME = "SEND_SMS_QUEUE";
|
||||
public static final String SMS_PHONE_NAME = "SEND_QQ_QUEUE";
|
||||
public static final String SMS_TEL_NAME = "SEND_TEL_QUEUE";
|
||||
public static final String SMS_SMS_NAME = "SEND_SMS_QUEUE";
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.muyu.common.constant;
|
||||
|
||||
/**
|
||||
* @Author: xie ya ru
|
||||
* @Description: 服务名称常量
|
||||
* @Data 2024/7/10
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class ServerNameConstants {
|
||||
|
||||
/**
|
||||
* 系统服务服务名称
|
||||
*/
|
||||
public final static String SYSTEM_NAME = "system-server";
|
||||
public final static String QUAN_NAME = "system-quan";
|
||||
public final static String ES_NAME = "system-es";
|
||||
|
||||
/**
|
||||
* 系统API远程调用前缀
|
||||
*/
|
||||
public static interface SystemApi {
|
||||
// 用户远程前缀
|
||||
String USER_INFO_API = "/user";
|
||||
String QUAN_INFO_API ="/coupons";
|
||||
String ES_INFO_API ="/couponsES";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.muyu.common.constant;
|
||||
|
||||
/**
|
||||
* @author xie ya ru
|
||||
* @description: 令牌常量
|
||||
* @Data 2024/7/10
|
||||
*/
|
||||
public class TokenConstants {
|
||||
/**
|
||||
* 缓存有效期,默认720(分钟)
|
||||
*/
|
||||
public final static long EXPIRATION = 720;
|
||||
/**
|
||||
* 缓存刷新时间,默认120(分钟)
|
||||
*/
|
||||
public final static long REFRESH_TIME = 120;
|
||||
/**
|
||||
* 权限缓存前缀
|
||||
*/
|
||||
public final static String LOGIN_TOKEN_KEY = "login_tokens:";
|
||||
/**
|
||||
* token标识
|
||||
*/
|
||||
public static final String TOKEN = "token";
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package com.muyu.common.redis.configure;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONReader;
|
||||
import com.alibaba.fastjson2.JSONWriter;
|
||||
import com.alibaba.fastjson2.filter.Filter;
|
||||
|
||||
import com.muyu.common.constant.Constants;
|
||||
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 xie ya ru
|
||||
* @Data 2024/7/10
|
||||
*/
|
||||
public class FastJson2JsonRedisSerializer<T> implements RedisSerializer<T> {
|
||||
|
||||
public static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
|
||||
|
||||
static final Filter AUTO_TYPE_FILTER = JSONReader.autoTypeFilter(Constants.JSON_WHITELIST_STR);
|
||||
|
||||
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,41 @@
|
|||
package com.muyu.common.redis.configure;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
|
||||
import org.springframework.cache.annotation.CachingConfigurerSupport;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
|
||||
/**
|
||||
* redis配置
|
||||
*
|
||||
* @author xie ya ru
|
||||
*/
|
||||
@Configuration
|
||||
@EnableCaching
|
||||
@AutoConfigureBefore(RedisAutoConfiguration.class)
|
||||
public class RedisConfig extends CachingConfigurerSupport {
|
||||
@Bean
|
||||
@SuppressWarnings(value = {"unchecked", "rawtypes"})
|
||||
public RedisTemplate<Object, Object> redisTemplate (RedisConnectionFactory connectionFactory) {
|
||||
RedisTemplate<Object, Object> template = new RedisTemplate<>();
|
||||
template.setConnectionFactory(connectionFactory);
|
||||
|
||||
FastJson2JsonRedisSerializer serializer = new FastJson2JsonRedisSerializer(Object.class);
|
||||
|
||||
// 使用StringRedisSerializer来序列化和反序列化redis的key值
|
||||
template.setKeySerializer(new StringRedisSerializer());
|
||||
template.setValueSerializer(serializer);
|
||||
|
||||
// Hash的key也采用StringRedisSerializer的序列化方式
|
||||
template.setHashKeySerializer(new StringRedisSerializer());
|
||||
template.setHashValueSerializer(serializer);
|
||||
|
||||
template.afterPropertiesSet();
|
||||
return template;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package com.muyu.common.redis.configure;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @BelongsPackage: com.bw.config
|
||||
* @Author: xie ya ru
|
||||
* @Data: 2021/7/10
|
||||
*/
|
||||
|
||||
@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://43.142.14.107:6379");
|
||||
return Redisson.create(config);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,268 @@
|
|||
package com.muyu.common.redis.service;
|
||||
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
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.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* spring redis 工具类
|
||||
*
|
||||
* @author xie ya ru
|
||||
**/
|
||||
@SuppressWarnings(value = {"unchecked", "rawtypes"})
|
||||
@Log4j2
|
||||
@Component
|
||||
public class RedisService {
|
||||
|
||||
@Scheduled(cron = "0/5 * * * * ?")
|
||||
public void scheduled() {
|
||||
this.setCacheObject("skip", System.currentTimeMillis());
|
||||
log.info("Redis心跳成功");
|
||||
}
|
||||
|
||||
@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 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);
|
||||
Iterator<T> it = dataSet.iterator();
|
||||
while (it.hasNext()) {
|
||||
setOperation.add(it.next());
|
||||
}
|
||||
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,34 @@
|
|||
package com.muyu.common.result;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author xie ya ru
|
||||
* @description: 列表返回结果集
|
||||
*/
|
||||
@Data
|
||||
public class PageResult<T> implements Serializable {
|
||||
/**
|
||||
* 总条数
|
||||
*/
|
||||
private long total;
|
||||
/**
|
||||
* 结果集合
|
||||
*/
|
||||
private List<T> list;
|
||||
public PageResult() {
|
||||
}
|
||||
public PageResult(long total, List<T> list) {
|
||||
this.total = total;
|
||||
this.list = list;
|
||||
}
|
||||
public static <T> PageResult<T> toPageResult(long total, List<T> list){
|
||||
return new PageResult(total , list);
|
||||
}
|
||||
public static <T> Result<PageResult<T>> toResult(long total, List<T> list){
|
||||
return Result.success(PageResult.toPageResult(total,list));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package com.muyu.common.result;
|
||||
|
||||
import com.muyu.common.constant.Constants;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @description: 响应信息主体
|
||||
* @author xie ya ru
|
||||
*/
|
||||
@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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
package com.muyu.common.utils;
|
||||
|
||||
import com.muyu.common.constant.JwtConstants;
|
||||
import io.jsonwebtoken.Claims;
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import io.jsonwebtoken.SignatureAlgorithm;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @description: Jwt工具类
|
||||
* @author xie ya ru
|
||||
*/
|
||||
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,162 @@
|
|||
package com.muyu.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;
|
||||
|
||||
/**
|
||||
* @Author: xie ya ru
|
||||
* @Description TODO Oss工具
|
||||
*/
|
||||
@Log4j2
|
||||
public class OssUtil {
|
||||
|
||||
/**
|
||||
* Endpoint 存储对象概述 阿里云主账号AccessKey,accessKeySecret拥有所有API的访问权限 访问路径前缀 存储对象概述
|
||||
*/
|
||||
private static String endPoint = "oss-cn-shanghai.aliyuncs.com";
|
||||
private static String accessKeyId = "LTAI5tDbRqXkC5i3SMrCSDcX";
|
||||
private static String accessKeySecret = "XUzMZoHPLsjNLafHsdQnMElBWZATsu";
|
||||
private static String accessPre = "https://mall-bw.oss-cn-shanghai.aliyuncs.com/";
|
||||
|
||||
/**
|
||||
* bucket名称
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private static String bucketName = "mall-bw";
|
||||
|
||||
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,68 @@
|
|||
package com.muyu.common.utils;
|
||||
|
||||
import org.springframework.util.AntPathMatcher;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author xie ya ru
|
||||
* 工具类
|
||||
*/
|
||||
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,125 @@
|
|||
package com.muyu.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.dysmsapi20170525.models.SendSmsResponseBody;
|
||||
import com.aliyun.teaopenapi.models.Config;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* 短信工具类
|
||||
*/
|
||||
@Log4j2
|
||||
public class TelSmsUtils {
|
||||
|
||||
/**
|
||||
* 阿里云主账号AccessKey,accessKeySecret拥有所有API的访问权限
|
||||
* <p>
|
||||
* LTAI5tN9vdDeBioiVbGG3UG3
|
||||
* gzhfYLb0UX0zH35DOki9yi1Q35ndgS
|
||||
*/
|
||||
private static final String accessKeyId = "LTAI5tN9vdDeBioiVbGG3UG3";
|
||||
|
||||
private static final String accessKeySecret = "gzhfYLb0UX0zH35DOki9yi1Q35ndgS";
|
||||
|
||||
/**
|
||||
* 短信访问域名
|
||||
*/
|
||||
private static final String endpoint = "dysmsapi.aliyuncs.com";
|
||||
|
||||
/**
|
||||
* 短信签名
|
||||
*/
|
||||
private static final String signName = "登录验证";
|
||||
|
||||
/**
|
||||
* 模板编号
|
||||
*/
|
||||
private static final String templateCode = "SMS_467560395";
|
||||
|
||||
/**
|
||||
* 实例化短信对象
|
||||
*/
|
||||
private static Client client;
|
||||
|
||||
static {
|
||||
log.info("初始化短信服务开始");
|
||||
long startTime = System.currentTimeMillis();
|
||||
try {
|
||||
client = initClient();
|
||||
log.info("初始化短信成功:{}", signName);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
log.info("初始化短信服务结束:耗时:{}MS", (System.currentTimeMillis() - startTime));
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化短信对象
|
||||
*
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
private static Client initClient() throws Exception {
|
||||
Config config = new Config()
|
||||
// 您的AccessKey ID
|
||||
.setAccessKeyId(accessKeyId)
|
||||
// 您的AccessKey Secret
|
||||
.setAccessKeySecret(accessKeySecret);
|
||||
// 访问的域名
|
||||
config.endpoint = endpoint;
|
||||
return new Client(config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送单条短信
|
||||
* @param tel 手机号
|
||||
* @param sendDataMap 验证码对象
|
||||
*/
|
||||
public static SendSmsResponseBody sendSms(String tel, 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 sendSmsResponse.getBody();
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送手机验证码
|
||||
* @param tel 手机号
|
||||
* @param code 验证码
|
||||
*/
|
||||
public static SendSmsResponseBody sendSms(String tel, String code) {
|
||||
|
||||
Map<String, String> map = new HashMap<>();
|
||||
|
||||
map.put("code",code);
|
||||
|
||||
return sendSms(tel, map);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
int code = new Random().nextInt(900000) + 100000;
|
||||
map.put("code", String.valueOf(code));
|
||||
sendSms("15335893491", map);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
com.muyu.common.redis.configure.RedisConfig
|
||||
com.muyu.common.redis.service.RedisService
|
||||
com.muyu.common.config.ExceptionHandler
|
||||
com.muyu.common.redis.configure.RedissonConfig
|
|
@ -0,0 +1,59 @@
|
|||
<?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.muyu</groupId>
|
||||
<artifactId>h6-exam812</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>cloud-gateway</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- 公共依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-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,22 @@
|
|||
package com.muyu;
|
||||
|
||||
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.scheduling.annotation.EnableScheduling;
|
||||
|
||||
/**
|
||||
* @Author: xie ya ru
|
||||
* @date: 2024/5/23
|
||||
* @Description: 云网关启动类
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, DruidDataSourceAutoConfigure.class})
|
||||
@EnableScheduling
|
||||
public class CloudGatewayApplication {
|
||||
|
||||
public static void main (String[] args) {
|
||||
SpringApplication.run(CloudGatewayApplication.class, args);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
package com.muyu.config;
|
||||
|
||||
import com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayFlowRule;
|
||||
import com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayRuleManager;
|
||||
import com.alibaba.csp.sentinel.adapter.gateway.sc.exception.SentinelGatewayBlockExceptionHandler;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.http.codec.ServerCodecConfigurer;
|
||||
import org.springframework.web.reactive.result.view.ViewResolver;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @deprecation: 网关限流控件
|
||||
* @author xie ya ru
|
||||
*/
|
||||
@Configuration
|
||||
public class GatewaySentinelConfig {
|
||||
/**
|
||||
* 查看解析器
|
||||
*/
|
||||
private final List<ViewResolver> viewResolvers;
|
||||
/**
|
||||
* 服务器编解码器配置
|
||||
*/
|
||||
private final ServerCodecConfigurer serverCodecConfigurer;
|
||||
public GatewaySentinelConfig(ObjectProvider<List<ViewResolver>> viewResolversProvider,
|
||||
ServerCodecConfigurer serverCodecConfigurer) {
|
||||
this.viewResolvers = viewResolversProvider.getIfAvailable(Collections::emptyList);
|
||||
this.serverCodecConfigurer = serverCodecConfigurer;
|
||||
}
|
||||
/**
|
||||
* Sentinel 网关块异常处理程序
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
@Order(Ordered.HIGHEST_PRECEDENCE)
|
||||
public SentinelGatewayBlockExceptionHandler sentinelGatewayBlockExceptionHandler() {
|
||||
// 给 Spring Cloud Gateway 注册块异常处理程序。
|
||||
return new SentinelGatewayBlockExceptionHandler(viewResolvers, serverCodecConfigurer);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化网关配置
|
||||
*/
|
||||
@PostConstruct
|
||||
public void doInit() {
|
||||
initGatewayRules();
|
||||
}
|
||||
/**
|
||||
* 配置限流规则
|
||||
*/
|
||||
private void initGatewayRules() {
|
||||
Set<GatewayFlowRule> rules = new HashSet<>();
|
||||
rules.add(new GatewayFlowRule("cloud-user")
|
||||
// 限流阈值
|
||||
.setCount(1)
|
||||
// 统计时间窗口,单位是秒,默认是 1 秒
|
||||
.setIntervalSec(5)
|
||||
);
|
||||
//添加到限流规则当中
|
||||
GatewayRuleManager.loadRules(rules);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package com.muyu.config;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.Data;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @description: 放行白名单配置
|
||||
* @author xie ya ru
|
||||
*/
|
||||
@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,97 @@
|
|||
package com.muyu.filter;
|
||||
|
||||
import com.muyu.common.constant.JwtConstants;
|
||||
import com.muyu.common.constant.TokenConstants;
|
||||
import com.muyu.common.redis.service.RedisService;
|
||||
import com.muyu.common.utils.JwtUtils;
|
||||
import com.muyu.common.utils.StringUtils;
|
||||
import com.muyu.config.IgnoreWhiteConfig;
|
||||
import com.muyu.utils.GatewayUtils;
|
||||
import io.jsonwebtoken.Claims;
|
||||
import lombok.AllArgsConstructor;
|
||||
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.server.RequestPath;
|
||||
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.io.UnsupportedEncodingException;
|
||||
import java.net.URI;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @Author: xie ya ru
|
||||
* @date: 2024/7/10
|
||||
* @Description: 权限过滤器
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class AuthFilter implements GlobalFilter, Ordered {
|
||||
|
||||
private final IgnoreWhiteConfig ignoreWhiteConfig;
|
||||
|
||||
private final RedisService redisService;
|
||||
|
||||
@Override
|
||||
public Mono<Void> filter (ServerWebExchange exchange, GatewayFilterChain chain) {
|
||||
|
||||
ServerHttpRequest request = exchange.getRequest();
|
||||
URI uri = request.getURI();
|
||||
String path = uri.getPath();
|
||||
if (StringUtils.matches(path, ignoreWhiteConfig.getWhites())){
|
||||
return chain.filter(exchange);
|
||||
}
|
||||
HttpHeaders requestHeaders = request.getHeaders();
|
||||
String token = requestHeaders.getFirst(TokenConstants.TOKEN);
|
||||
if (StringUtils.isEmpty(token)){
|
||||
return GatewayUtils.errorResponse(exchange, "token不合法");
|
||||
}
|
||||
Claims claims = JwtUtils.parseToken(token);
|
||||
if (claims == null){
|
||||
return GatewayUtils.errorResponse(exchange, "token不合法");
|
||||
}
|
||||
String userKey = JwtUtils.getUserKey(claims);
|
||||
if (!redisService.hasKey(JwtConstants.USER_KEY + userKey)){
|
||||
return GatewayUtils.errorResponse(exchange, "token已过期");
|
||||
}else{
|
||||
//每次访问后台gateway进行拦截10分钟内访问后台自动续期Token到15分钟
|
||||
long expire = redisService.getExpire(JwtConstants.USER_KEY + userKey);
|
||||
if(expire >5){
|
||||
redisService.expire(JwtConstants.USER_KEY+userKey,15L, TimeUnit.MINUTES);
|
||||
}
|
||||
}
|
||||
ServerHttpRequest.Builder mutate = request.mutate();
|
||||
GatewayUtils.addHeader(mutate, JwtConstants.USER_KEY, userKey);
|
||||
GatewayUtils.addHeader(mutate, JwtConstants.DETAILS_USER_ID, JwtUtils.getUserId(claims));
|
||||
String userName = JwtUtils.getUserName(claims);
|
||||
if (userName.matches(".*[\\u4E00-\\u9FA5]+.*")){
|
||||
userName = new String(userName.getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1);
|
||||
}
|
||||
GatewayUtils.addHeader(mutate, JwtConstants.DETAILS_USERNAME,userName );
|
||||
return chain.filter(exchange);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the order value of this object.
|
||||
* <p>Higher values are interpreted as lower priority. As a consequence,
|
||||
* the object with the lowest value has the highest priority (somewhat
|
||||
* analogous to Servlet {@code load-on-startup} values).
|
||||
* <p>Same order values will result in arbitrary sort positions for the
|
||||
* affected objects.
|
||||
*
|
||||
* @return the order value
|
||||
*
|
||||
* @see #HIGHEST_PRECEDENCE
|
||||
* @see #LOWEST_PRECEDENCE
|
||||
*/
|
||||
@Override
|
||||
public int getOrder () {
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
package com.muyu.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.muyu.common.result.Result;
|
||||
import com.muyu.common.utils.StringUtils;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.http.server.reactive.ServerHttpResponse;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* @author xie ya ru
|
||||
* @description: 网关处理工具类
|
||||
*/
|
||||
@Log4j2
|
||||
public class GatewayUtils {
|
||||
/**
|
||||
* 添加请求头参数
|
||||
* @param mutate 修改对象
|
||||
* @param key 键
|
||||
* @param value 值
|
||||
*/
|
||||
public static void addHeader(ServerHttpRequest.Builder mutate, String key, Object value) {
|
||||
if (StringUtils.isEmpty(key)){
|
||||
log.warn("添加请求头参数键不可以为空");
|
||||
return;
|
||||
}
|
||||
if (value == null) {
|
||||
log.warn("添加请求头参数:[{}]值为空",key);
|
||||
return;
|
||||
}
|
||||
String valueStr = value.toString();
|
||||
mutate.header(key, valueStr);
|
||||
log.info("添加请求头参数成功 - 键:[{}] , 值:[{}]", key , value);
|
||||
}
|
||||
/**
|
||||
* 删除请求头参数
|
||||
* @param mutate 修改对象
|
||||
* @param key 键
|
||||
*/
|
||||
public static void removeHeader(ServerHttpRequest.Builder mutate, String key) {
|
||||
if (StringUtils.isEmpty(key)){
|
||||
log.warn("删除请求头参数键不可以为空");
|
||||
return;
|
||||
}
|
||||
mutate.headers(httpHeaders -> httpHeaders.remove(key)).build();
|
||||
log.info("删除请求头参数 - 键:[{}]",key);
|
||||
}
|
||||
/**
|
||||
* 错误结果响应
|
||||
* @param exchange 响应上下文
|
||||
* @param msg 响应消息
|
||||
* @return
|
||||
*/
|
||||
public static Mono<Void> errorResponse(ServerWebExchange exchange, String msg) {
|
||||
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,32 @@
|
|||
# 指定项目启动的端口号
|
||||
server:
|
||||
port: 8081
|
||||
|
||||
# 配置nacos的地址
|
||||
nacos:
|
||||
server-addr: 1.94.37.42:8848
|
||||
|
||||
spring:
|
||||
application:
|
||||
# 配置项目的名称
|
||||
name: cloud-gateway
|
||||
profiles:
|
||||
# 指定项目启动使用的环境配置文件
|
||||
active: dev
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
# nacos 注册中心的地址
|
||||
server-addr: ${nacos.server-addr}
|
||||
config:
|
||||
# nacos 配置中心的地址
|
||||
server-addr: ${nacos.server-addr}
|
||||
# nacos 配置中心使用的文件后缀(格式)
|
||||
file-extension: yml
|
||||
# nacos 配置中心的共享配置文件
|
||||
shared-configs:
|
||||
# 程序公共配置文件
|
||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
# 程序Redis公共配置文件
|
||||
- redis-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
- cloud-gateway-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
|
@ -0,0 +1,38 @@
|
|||
<?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.muyu</groupId>
|
||||
<artifactId>cloud-system</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>cloud-quan</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.muyu</groupId>
|
||||
<artifactId>system-common</artifactId>
|
||||
</dependency>
|
||||
<!-- SpringBoot Web-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>system-remote</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,21 @@
|
|||
package com.muyu;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/8/12 10:44
|
||||
* @注释
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableFeignClients( basePackages = {"com.muyu.**"})
|
||||
@EnableScheduling
|
||||
public class QuanApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(QuanApplication.class,args);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
package com.muyu.quan.controller;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.muyu.cloud.system.domain.UserInfo;
|
||||
import com.muyu.cloud.system.domain.request.CouponsAddReq;
|
||||
import com.muyu.cloud.system.domain.request.CouponsReq;
|
||||
import com.muyu.cloud.system.domain.request.CouponsUpdReq;
|
||||
import com.muyu.cloud.system.domain.response.CouponsResp;
|
||||
import com.muyu.common.constant.JwtConstants;
|
||||
import com.muyu.common.redis.service.RedisService;
|
||||
import com.muyu.common.result.Result;
|
||||
import com.muyu.quan.service.CouponsService;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/8/12 11:13
|
||||
* @注释
|
||||
*/
|
||||
@Log4j2
|
||||
@RestController
|
||||
@RequestMapping("/coupons")
|
||||
public class CouponsController {
|
||||
@Resource
|
||||
private CouponsService couponsService;
|
||||
|
||||
@Resource
|
||||
private HttpServletRequest request;
|
||||
|
||||
@Resource
|
||||
private RedisService redisService;
|
||||
|
||||
@GetMapping("/selectAll")
|
||||
public Result<List<CouponsResp>> selectAll(){
|
||||
log.info("功能:查询优惠券列表开始,请求路径[{}],请求方法[{}]",request.getRequestURI(),request.getMethod());
|
||||
List<CouponsResp> couponsRespList = couponsService.showGop();
|
||||
log.info("功能:查询优惠券列表结束,请求路径[{}],请求方法[{}]",request.getRequestURI(),request.getMethod());
|
||||
return Result.success(couponsRespList);
|
||||
}
|
||||
@PostMapping("/selectAllC")
|
||||
public Result<List<CouponsResp>> selectAllC(@RequestBody CouponsReq couponsReq){
|
||||
log.info("功能:查询优惠券列表开始,请求路径[{}],请求方法[{}]",request.getRequestURI(),request.getMethod());
|
||||
List<CouponsResp> couponsRespList = couponsService.showGoup(couponsReq);
|
||||
log.info("功能:查询优惠券列表结束,请求路径[{}],请求方法[{}]",request.getRequestURI(),request.getMethod());
|
||||
return Result.success(couponsRespList);
|
||||
}
|
||||
|
||||
@PutMapping("/updCoupon")
|
||||
public Result updESCoupon(@RequestBody CouponsUpdReq couponsUpdReq){
|
||||
log.info("功能:更新修改优惠券开始,请求路径[{}],请求方法[{}],请求参数[{}]",request.getRequestURI(),request.getMethod(), JSONObject.toJSONString(couponsUpdReq));
|
||||
couponsService.updCouponUpdReq(couponsUpdReq);
|
||||
log.info("功能:更新修改优惠券开始,请求路径[{}],请求方法[{}]",request.getRequestURI(),request.getMethod());
|
||||
return Result.success(null,"操作成功");
|
||||
}
|
||||
|
||||
@PutMapping("/disable/{couponsId}")
|
||||
public Result disable(@PathVariable("couponsId") Long couponsId){
|
||||
log.info("功能:更新修改优惠券开始,请求路径[{}],请求方法[{}],请求参数[{}]",request.getRequestURI(),request.getMethod(), JSONObject.toJSONString(couponsId));
|
||||
couponsService.disable(couponsId);
|
||||
log.info("功能:更新修改优惠券开始,请求路径[{}],请求方法[{}]",request.getRequestURI(),request.getMethod());
|
||||
return Result.success(null,"操作成功");
|
||||
}
|
||||
|
||||
@PostMapping("/addCoupons")
|
||||
public Result addCoupons(@RequestBody CouponsAddReq couponsAddReq){
|
||||
log.info("功能:添加新的优惠券开始,请求路径[{}],请求方法[{}],请求参数[{}],",request.getRequestURI(),request.getMethod(),JSONObject.toJSONString(couponsAddReq));
|
||||
couponsService.addCouponsAddReq(couponsAddReq);
|
||||
log.info("功能:添加新的优惠券开始,请求路径[{}],请求方法[{}],",request.getRequestURI(),request.getMethod());
|
||||
return Result.success(null,"操作成功");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
package com.muyu.quan.controller;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.muyu.cloud.system.domain.UserInfo;
|
||||
import com.muyu.cloud.system.domain.request.OrderAddReq;
|
||||
import com.muyu.cloud.system.domain.request.OrderUpdReq;
|
||||
import com.muyu.cloud.system.domain.response.OrderResp;
|
||||
import com.muyu.common.constant.JwtConstants;
|
||||
import com.muyu.common.redis.service.RedisService;
|
||||
import com.muyu.common.result.Result;
|
||||
import com.muyu.quan.service.OrderService;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/8/12 19:00
|
||||
* @注释
|
||||
*/
|
||||
@Log4j2
|
||||
@RestController
|
||||
@RequestMapping("/order")
|
||||
public class OrderController {
|
||||
@Resource
|
||||
private OrderService orderService;
|
||||
|
||||
@Resource
|
||||
private HttpServletRequest request;
|
||||
|
||||
@Resource
|
||||
private RedisService redisService;
|
||||
|
||||
private UserInfo getUser(){
|
||||
String userKey = request.getHeader("user_key");
|
||||
UserInfo cacheUserInfo = redisService.getCacheObject(JwtConstants.USER_KEY + userKey);
|
||||
return cacheUserInfo;
|
||||
}
|
||||
|
||||
@PostMapping("/addOrders")
|
||||
public Result addOrders(@RequestBody OrderAddReq orderAddReq){
|
||||
log.info("功能:添加订单开始,请求路径[{}],请求方法[{}],请求参数[{}]",request.getRequestURI(),request.getMethod(), JSONObject.toJSONString(orderAddReq));
|
||||
orderAddReq.setCreateBy(getUser().getUsername());
|
||||
orderService.addOrder(orderAddReq);
|
||||
log.info("功能:添加订单结束,请求路径[{}],请求方法[{}],请求参数[{}]",request.getRequestURI(),request.getMethod(), JSONObject.toJSONString(orderAddReq));
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@PostMapping("/showByOne")
|
||||
public Result<List<OrderResp>> showByOne(){
|
||||
log.info("功能:添加订单开始,请求路径[{}],请求方法[{}]",request.getRequestURI(),request.getMethod());
|
||||
List<OrderResp> orderRespList = orderService.showByOne(getUser().getUsername());
|
||||
log.info("功能:添加订单结束,请求路径[{}],请求方法[{}]",request.getRequestURI(),request.getMethod());
|
||||
return Result.success(orderRespList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转让
|
||||
* @param orderUpdReq
|
||||
* @return
|
||||
*/
|
||||
@PutMapping("/updOrder")
|
||||
public Result updOrder(@RequestBody OrderUpdReq orderUpdReq){
|
||||
orderService.updOrder(orderUpdReq);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@PutMapping("/updateOrderStatus")
|
||||
public Result updateOrderStatus(@RequestBody OrderUpdReq orderUpdReq){
|
||||
orderService.updateOrderStatus(orderUpdReq);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Scheduled(cron = "* 0/5 * * * ?")
|
||||
public void getTime(){
|
||||
orderService.updateStatus();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.muyu.quan.mapper;
|
||||
|
||||
import com.muyu.cloud.system.domain.request.CouponsAddReq;
|
||||
import com.muyu.cloud.system.domain.request.CouponsReq;
|
||||
import com.muyu.cloud.system.domain.request.CouponsUpdReq;
|
||||
import com.muyu.cloud.system.domain.response.CouponsResp;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/8/12 11:05
|
||||
* @注释
|
||||
*/
|
||||
@Mapper
|
||||
public interface CouponsMapper {
|
||||
List<CouponsResp> showGop();
|
||||
|
||||
Integer addCoupons(CouponsAddReq couponsAddReq);
|
||||
|
||||
|
||||
Integer updCoupons(CouponsUpdReq couponsUpdReq);
|
||||
|
||||
|
||||
List<CouponsResp> showCoup(CouponsReq couponsReq);
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.muyu.quan.mapper;
|
||||
|
||||
import com.alibaba.nacos.shaded.org.checkerframework.checker.optional.qual.MaybePresent;
|
||||
import com.muyu.cloud.system.domain.request.OrderAddReq;
|
||||
import com.muyu.cloud.system.domain.request.OrderUpdReq;
|
||||
import com.muyu.cloud.system.domain.response.OrderResp;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/8/12 18:37
|
||||
* @注释
|
||||
*/
|
||||
@Mapper
|
||||
public interface OrderMapper {
|
||||
List<OrderResp> showByOne(String createBy);
|
||||
|
||||
void addOrder(OrderAddReq orderAddReq);
|
||||
|
||||
void updOrder(OrderUpdReq orderUpdReq);
|
||||
|
||||
void updateStatus();
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package com.muyu.quan.service;
|
||||
|
||||
import com.muyu.cloud.system.domain.request.CouponsAddReq;
|
||||
import com.muyu.cloud.system.domain.request.CouponsReq;
|
||||
import com.muyu.cloud.system.domain.request.CouponsUpdReq;
|
||||
import com.muyu.cloud.system.domain.response.CouponsResp;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/8/12 11:10
|
||||
* @注释
|
||||
*/
|
||||
public interface CouponsService {
|
||||
|
||||
/**
|
||||
* 查询所有 优惠券
|
||||
* @return List<CouponsResp>
|
||||
*/
|
||||
List<CouponsResp> showGop();
|
||||
|
||||
/**
|
||||
* 添加优惠券
|
||||
* @param couponsAddReq
|
||||
*/
|
||||
void addCouponsAddReq(CouponsAddReq couponsAddReq);
|
||||
|
||||
/**
|
||||
* 修改优惠券
|
||||
* @param couponsUpdReq
|
||||
*/
|
||||
void updCouponUpdReq(CouponsUpdReq couponsUpdReq);
|
||||
|
||||
/**
|
||||
* 禁用 优惠券
|
||||
* @param couponsId
|
||||
*/
|
||||
void disable(Long couponsId);
|
||||
|
||||
List<CouponsResp> showGoup(CouponsReq couponsReq);
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.muyu.quan.service;
|
||||
|
||||
import com.muyu.cloud.system.domain.request.OrderAddReq;
|
||||
import com.muyu.cloud.system.domain.request.OrderUpdReq;
|
||||
import com.muyu.cloud.system.domain.response.OrderResp;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/8/12 18:41
|
||||
* @注释
|
||||
*/
|
||||
public interface OrderService {
|
||||
|
||||
List<OrderResp> showByOne(String createBy);
|
||||
|
||||
void addOrder(OrderAddReq orderAddReq);
|
||||
|
||||
void updOrder(OrderUpdReq orderUpdReq);
|
||||
|
||||
void updateOrderStatus(OrderUpdReq orderUpdReq);
|
||||
|
||||
void updateStatus();
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
package com.muyu.quan.service.impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.muyu.cloud.system.domain.Coupons;
|
||||
import com.muyu.cloud.system.domain.request.CouponsAddReq;
|
||||
import com.muyu.cloud.system.domain.request.CouponsReq;
|
||||
import com.muyu.cloud.system.domain.request.CouponsUpdReq;
|
||||
import com.muyu.cloud.system.domain.response.CouponsResp;
|
||||
import com.muyu.cloud.system.remote.RemoteESCouponsService;
|
||||
import com.muyu.common.constant.MQQueueNameConstants;
|
||||
import com.muyu.quan.mapper.CouponsMapper;
|
||||
import com.muyu.quan.service.CouponsService;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.amqp.rabbit.annotation.Queue;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/8/12 11:10
|
||||
* @注释
|
||||
*/
|
||||
@Log4j2
|
||||
@Service
|
||||
public class CouponsServiceImpl implements CouponsService {
|
||||
@Resource
|
||||
private CouponsMapper couponsMapper;
|
||||
|
||||
@Resource
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
@Resource
|
||||
private RemoteESCouponsService remoteESCouponsService;
|
||||
|
||||
|
||||
@Override
|
||||
public List<CouponsResp> showGop() {
|
||||
return couponsMapper.showGop();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void addCouponsAddReq(CouponsAddReq couponsAddReq) {
|
||||
couponsMapper.addCoupons(couponsAddReq);
|
||||
rabbitTemplate.convertAndSend(MQQueueNameConstants.SMS_PHONE_NAME, JSONObject.toJSONString(couponsAddReq),message -> {
|
||||
message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
|
||||
return message;
|
||||
});
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void updCouponUpdReq(CouponsUpdReq couponsUpdReq) {
|
||||
couponsMapper.updCoupons(couponsUpdReq);
|
||||
rabbitTemplate.convertAndSend(MQQueueNameConstants.SMS_TEL_NAME, JSONObject.toJSONString(couponsUpdReq),message -> {
|
||||
message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
|
||||
return message;
|
||||
});
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void disable(Long couponsId) {
|
||||
Coupons coupons = new Coupons();
|
||||
CouponsUpdReq couponsUpdReq = coupons.bulidCouponsUpdReq(couponsId, 2);
|
||||
couponsMapper.updCoupons(couponsUpdReq);
|
||||
rabbitTemplate.convertAndSend(MQQueueNameConstants.SMS_TEL_NAME, JSONObject.toJSONString(couponsUpdReq),message -> {
|
||||
message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
|
||||
return message;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CouponsResp> showGoup(CouponsReq couponsReq) {
|
||||
return couponsMapper.showCoup(couponsReq);
|
||||
}
|
||||
|
||||
@RabbitListener(queuesToDeclare = {@Queue(name = MQQueueNameConstants.SMS_PHONE_NAME)})
|
||||
public void getSmsPhoneName(String message){
|
||||
CouponsAddReq couponsAddReq = JSONObject.parseObject(message, CouponsAddReq.class);
|
||||
remoteESCouponsService.addCoupons(couponsAddReq);
|
||||
|
||||
}
|
||||
@RabbitListener(queuesToDeclare = {@Queue(name = MQQueueNameConstants.SMS_TEL_NAME)})
|
||||
public void getSmsTelName(String message){
|
||||
CouponsUpdReq couponsUpdReq = JSONObject.parseObject(message, CouponsUpdReq.class);
|
||||
remoteESCouponsService.updESCoupon(couponsUpdReq);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
package com.muyu.quan.service.impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.muyu.cloud.system.domain.UserInfo;
|
||||
import com.muyu.cloud.system.domain.request.OrderAddReq;
|
||||
import com.muyu.cloud.system.domain.request.OrderUpdReq;
|
||||
import com.muyu.cloud.system.domain.response.OrderResp;
|
||||
import com.muyu.cloud.system.remote.RemoteUserInfoService;
|
||||
import com.muyu.common.constant.MQQueueNameConstants;
|
||||
import com.muyu.quan.mapper.OrderMapper;
|
||||
import com.muyu.quan.service.OrderService;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.amqp.rabbit.annotation.Queue;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/8/12 18:50
|
||||
* @注释
|
||||
*/
|
||||
@Log4j2
|
||||
@Service
|
||||
public class OrderServiceImpl implements OrderService {
|
||||
|
||||
@Resource
|
||||
private OrderMapper orderMapper;
|
||||
|
||||
@Resource
|
||||
private RemoteUserInfoService remoteUserInfoService;
|
||||
@Resource
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
@Override
|
||||
public List<OrderResp> showByOne(String createBy) {
|
||||
return orderMapper.showByOne(createBy);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void addOrder(OrderAddReq orderAddReq) {
|
||||
orderMapper.addOrder(orderAddReq);
|
||||
UserInfo userInfo = new UserInfo();
|
||||
userInfo.setUserMoney(orderAddReq.getOrderPrice());
|
||||
remoteUserInfoService.diffUserMoney(userInfo);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void updOrder(OrderUpdReq orderUpdReq) {
|
||||
orderMapper.updOrder(orderUpdReq);
|
||||
UserInfo userInfo = new UserInfo();
|
||||
userInfo.setUsername(orderUpdReq.getEndBy());
|
||||
userInfo.setUserMoney(orderUpdReq.getOrderPrice());
|
||||
remoteUserInfoService.updUserMoney(userInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateOrderStatus(OrderUpdReq orderUpdReq) {
|
||||
orderUpdReq.setOrderStatus(5);
|
||||
orderMapper.updOrder(orderUpdReq);
|
||||
UserInfo userInfo = new UserInfo();
|
||||
userInfo.setUsername(orderUpdReq.getEndBy());
|
||||
userInfo.setUserMoney(orderUpdReq.getOrderPrice());
|
||||
rabbitTemplate.convertAndSend(MQQueueNameConstants.SMS_SMS_NAME, JSONObject.toJSONString(userInfo),message -> {
|
||||
message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
|
||||
return message;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateStatus() {
|
||||
orderMapper.updateStatus();
|
||||
|
||||
}
|
||||
|
||||
@RabbitListener(queuesToDeclare = {@Queue(name = MQQueueNameConstants.SMS_SMS_NAME)})
|
||||
public void getUserInfo(String message){
|
||||
UserInfo userInfo = JSONObject.parseObject(message, UserInfo.class);
|
||||
remoteUserInfoService.diffUserMoney(userInfo);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
# Tomcat
|
||||
server:
|
||||
port: 9202
|
||||
|
||||
# 配置nacos的地址
|
||||
nacos:
|
||||
server-addr: 1.94.37.42:8848
|
||||
|
||||
# Spring
|
||||
spring:
|
||||
rabbitmq:
|
||||
host: 1.94.37.42
|
||||
port: 5672
|
||||
publisher-confirm-type: correlated #消息发送到交换机确认
|
||||
publisher-returns: true #允许发送到消息队列的确认
|
||||
username: user
|
||||
password: xyr070903
|
||||
main:
|
||||
allow-circular-references: true
|
||||
jackson:
|
||||
date-format: yyyy-MM-dd HH:mm:ss
|
||||
time-zone: GMT+8
|
||||
application:
|
||||
# 应用名称
|
||||
name: system-quan
|
||||
profiles:
|
||||
# 环境配置
|
||||
active: dev
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: ${nacos.server-addr}
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: ${nacos.server-addr}
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
shared-configs:
|
||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
# 程序Redis公共配置文件
|
||||
- redis-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
# 程序MySQL公共配置文件
|
||||
- mysql-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
|
||||
- system-server-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
|
||||
fdfs:
|
||||
so-timeout: 1500 # socket 连接时长
|
||||
connect-timeout: 600 # 连接 tracker 服务器超时时长
|
||||
# 这两个是你服务器的 IP 地址,注意 23000 端口也要打开,阿里云服务器记得配置安全组。tracker 要和 stroage 服务进行交流
|
||||
tracker-list: 1.94.37.42:22122
|
||||
web-server-url: 1.94.37.42:8888
|
||||
pool:
|
||||
jmx-enabled: false
|
||||
# 生成缩略图
|
||||
thumb-image:
|
||||
height: 500
|
||||
width: 500
|
|
@ -0,0 +1,36 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.muyu.quan.mapper.CouponsMapper">
|
||||
<insert id="addCoupons" useGeneratedKeys="true" keyProperty="coupons_id">
|
||||
INSERT INTO `h6-exam812`.`t_coupons` (`coupons_name`, `coupons_num`, `coupons_price`, `coupons_out_date`)
|
||||
VALUES
|
||||
( #{couponsName}, #{couponsNum}, #{couponsPrice}, #{couponsOutDate} )
|
||||
</insert>
|
||||
<update id="updCoupons">
|
||||
UPDATE `h6-exam812`.`t_coupons`
|
||||
SET `coupons_name` = #{couponsName},
|
||||
`coupons_num` = #{couponsNum},
|
||||
`coupons_price` = #{couponsPrice},
|
||||
`coupons_out_date` = #{couponsOutDate}
|
||||
WHERE
|
||||
`coupons_id` = #{couponsId}
|
||||
|
||||
</update>
|
||||
|
||||
|
||||
<select id="showGop" resultType="com.muyu.cloud.system.domain.response.CouponsResp">
|
||||
select * from t_coupons
|
||||
</select>
|
||||
<select id="showCoup" resultType="com.muyu.cloud.system.domain.response.CouponsResp">
|
||||
select * from t_coupons
|
||||
<where>
|
||||
and coupons_id >5
|
||||
<if test="couponsName != null and couponsName != ''">
|
||||
and instr(coupons_name,#{couponsName})
|
||||
</if>
|
||||
|
||||
</where>
|
||||
</select>
|
||||
</mapper>
|
|
@ -0,0 +1,37 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.muyu.quan.mapper.OrderMapper">
|
||||
<insert id="addOrder">
|
||||
INSERT INTO `h6-exam812`.`t_order` ( `coupons_id`, `order_start_date`, `order_end_date`, `create_by`, `end_by`,`order_price`,`order_num` )
|
||||
VALUES
|
||||
( #{couponsId}, NOW(), #{orderEndDate}, #{createBy}, #{endBy},#{orderPrice},#{orderNum} )
|
||||
|
||||
</insert>
|
||||
<update id="updOrder">
|
||||
|
||||
UPDATE `h6-exam812`.`t_order`
|
||||
SET `coupons_id` = #{couponsId},
|
||||
`order_status` = #{orderStatus},
|
||||
`order_start_date` = NOW(),
|
||||
`order_end_date` = #{orderEndDate},
|
||||
`end_by` = #{endBy},
|
||||
`order_num` =#{orderNum}
|
||||
WHERE
|
||||
`order_id` = #{orderId}
|
||||
</update>
|
||||
<update id="updateStatus">
|
||||
UPDATE `h6-exam812`.`t_order`
|
||||
SET
|
||||
`order_status`=5
|
||||
WHERE TIMEDIFF(now(),order_start_date) >2
|
||||
</update>
|
||||
|
||||
|
||||
<select id="showByOne" resultType="com.muyu.cloud.system.domain.response.OrderResp">
|
||||
select * from t_order
|
||||
left join `h6-exam812`.t_coupons tc on t_order.coupons_id = tc.coupons_id
|
||||
where create_by =#{cresteBy}
|
||||
</select>
|
||||
</mapper>
|
|
@ -0,0 +1,28 @@
|
|||
<?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.muyu</groupId>
|
||||
<artifactId>modules</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>cloud-system</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>system-common</module>
|
||||
<module>system-remote</module>
|
||||
<module>system-server</module>
|
||||
<module>system-es</module>
|
||||
<module>cloud-quan</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,28 @@
|
|||
<?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.muyu</groupId>
|
||||
<artifactId>cloud-system</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>system-common</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- 系统公共依赖包 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,63 @@
|
|||
package com.muyu.cloud.system.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.muyu.cloud.system.domain.request.CouponsUpdReq;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/8/12 10:48
|
||||
* @注释
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class Coupons {
|
||||
/**
|
||||
*ID
|
||||
*/
|
||||
private Long couponsId;
|
||||
/**
|
||||
*优惠券名称
|
||||
*/
|
||||
private String couponsName;
|
||||
/**
|
||||
*优惠券数量
|
||||
*/
|
||||
private String couponsNum;
|
||||
/**
|
||||
*优惠券价格
|
||||
*/
|
||||
private BigDecimal couponsPrice;
|
||||
|
||||
/**
|
||||
*优惠券过期时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date couponsOutDate;
|
||||
|
||||
/**
|
||||
* 优惠券状态(1:启用,2:禁用)
|
||||
*/
|
||||
private Integer couponsStatus;
|
||||
|
||||
|
||||
|
||||
|
||||
public CouponsUpdReq bulidCouponsUpdReq(Long couponsId, Integer couponsStatus) {
|
||||
return CouponsUpdReq.builder()
|
||||
.couponsId(couponsId)
|
||||
.couponsStatus(couponsStatus)
|
||||
.build();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.muyu.cloud.system.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/8/12 10:04
|
||||
* @注释
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class LogInfo {
|
||||
|
||||
private Long logId;
|
||||
private String logClassName;
|
||||
private String logMethodName;
|
||||
private String logRequestUri;
|
||||
private String logRequestArgs;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date logTime;
|
||||
private Long userId;
|
||||
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
package com.muyu.cloud.system.domain;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/8/12 10:58
|
||||
* @注释
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class Order {
|
||||
|
||||
private Long orderId;
|
||||
private Long couponsId;
|
||||
private Integer orderStatus;
|
||||
/**
|
||||
* 购买开始日期
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private String orderStartDate;
|
||||
/**
|
||||
* 有效时长
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private String orderEndDate;
|
||||
|
||||
/**
|
||||
* 购买人
|
||||
*/
|
||||
private String createBy;
|
||||
/**
|
||||
* 转让人
|
||||
*/
|
||||
private String endBy;
|
||||
/**
|
||||
* 订单总价
|
||||
*/
|
||||
private BigDecimal orderPrice;
|
||||
|
||||
/**
|
||||
* 订单个数
|
||||
*/
|
||||
private Integer orderNum;
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package com.muyu.cloud.system.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/8/12 10:56
|
||||
* @注释
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class Type {
|
||||
private Long typeId;
|
||||
private String typeName;
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.muyu.cloud.system.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/7/10 15:27
|
||||
* @注释
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class UserInfo {
|
||||
private Long id;
|
||||
private String username;
|
||||
private String password;
|
||||
private String userTel;
|
||||
private Integer role;
|
||||
private BigDecimal userMoney;
|
||||
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package com.muyu.cloud.system.domain.request;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/8/12 14:33
|
||||
* @注释
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class CouponsAddReq {
|
||||
|
||||
private Integer couponsId;
|
||||
/**
|
||||
*优惠券名称
|
||||
*/
|
||||
private String couponsName;
|
||||
/**
|
||||
*优惠券数量
|
||||
*/
|
||||
private String couponsNum;
|
||||
/**
|
||||
*优惠券价格
|
||||
*/
|
||||
private BigDecimal couponsPrice;
|
||||
/**
|
||||
*优惠券过期时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date couponsOutDate;
|
||||
/**
|
||||
* 优惠券状态(1:启用,2:禁用)
|
||||
*/
|
||||
private Integer couponsStatus;
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package com.muyu.cloud.system.domain.request;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/8/12 10:48
|
||||
* @注释
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class CouponsReq {
|
||||
|
||||
/**
|
||||
*优惠券名称
|
||||
*/
|
||||
private String couponsName;
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package com.muyu.cloud.system.domain.request;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/8/12 14:45
|
||||
* @注释
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class CouponsUpdReq {
|
||||
/**
|
||||
*ID
|
||||
*/
|
||||
private Long couponsId;
|
||||
/**
|
||||
*优惠券名称
|
||||
*/
|
||||
private String couponsName;
|
||||
/**
|
||||
*优惠券数量
|
||||
*/
|
||||
private String couponsNum;
|
||||
/**
|
||||
*优惠券价格
|
||||
*/
|
||||
private BigDecimal couponsPrice;
|
||||
|
||||
/**
|
||||
*优惠券过期时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date couponsOutDate;
|
||||
|
||||
/**
|
||||
* 优惠券状态(1:启用,2:禁用)
|
||||
*/
|
||||
private Integer couponsStatus;
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
package com.muyu.cloud.system.domain.request;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/8/12 19:03
|
||||
* @注释
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class OrderAddReq {
|
||||
|
||||
private Long orderId;
|
||||
private Long couponsId;
|
||||
private Integer orderStatus;
|
||||
/**
|
||||
* 购买开始日期
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private String orderStartDate;
|
||||
/**
|
||||
* 有效时长
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private String orderEndDate;
|
||||
|
||||
/**
|
||||
* 购买人
|
||||
*/
|
||||
private String createBy;
|
||||
/**
|
||||
* 转让人
|
||||
*/
|
||||
private String endBy;
|
||||
|
||||
/**
|
||||
* 订单总价
|
||||
*/
|
||||
private BigDecimal orderPrice;
|
||||
/**
|
||||
* 订单个数
|
||||
*/
|
||||
private Integer orderNum;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package com.muyu.cloud.system.domain.request;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/8/12 19:16
|
||||
* @注释
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class OrderUpdReq {
|
||||
private Long orderId;
|
||||
private Long couponsId;
|
||||
private Integer orderStatus;
|
||||
|
||||
private BigDecimal orderPrice;
|
||||
/**
|
||||
* 购买开始日期
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private String orderStartDate;
|
||||
/**
|
||||
* 有效时长
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private String orderEndDate;
|
||||
|
||||
/**
|
||||
* 购买人
|
||||
*/
|
||||
private String createBy;
|
||||
/**
|
||||
* 转让人
|
||||
*/
|
||||
private String endBy;
|
||||
/**
|
||||
* 订单个数
|
||||
*/
|
||||
private Integer orderNum;
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
package com.muyu.cloud.system.domain.response;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/8/12 10:48
|
||||
* @注释
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class CouponsResp {
|
||||
/**
|
||||
*ID
|
||||
*/
|
||||
private Long couponsId;
|
||||
/**
|
||||
*优惠券名称
|
||||
*/
|
||||
private String couponsName;
|
||||
/**
|
||||
*优惠券数量
|
||||
*/
|
||||
private String couponsNum;
|
||||
/**
|
||||
*优惠券价格
|
||||
*/
|
||||
private BigDecimal couponsPrice;
|
||||
|
||||
/**
|
||||
*优惠券过期时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date couponsOutDate;
|
||||
/**
|
||||
* 父级
|
||||
*/
|
||||
private Long couponsParentId;
|
||||
|
||||
/**
|
||||
* 优惠券状态(1:启用,2:禁用)
|
||||
*/
|
||||
private Integer couponsStatus;
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
package com.muyu.cloud.system.domain.response;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/8/12 10:58
|
||||
* @注释
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class OrderResp {
|
||||
|
||||
private Long orderId;
|
||||
private Long couponsId;
|
||||
private Integer orderStatus;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private String orderStartDate;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private String orderEndDate;
|
||||
|
||||
/**
|
||||
*优惠券名称
|
||||
*/
|
||||
private String couponsName;
|
||||
/**
|
||||
*优惠券数量
|
||||
*/
|
||||
private String couponsNum;
|
||||
/**
|
||||
*优惠券价格
|
||||
*/
|
||||
private BigDecimal couponsPrice;
|
||||
|
||||
|
||||
/**
|
||||
*优惠券过期时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date couponsOutDate;
|
||||
|
||||
/**
|
||||
* 购买人
|
||||
*/
|
||||
private String createBy;
|
||||
/**
|
||||
* 转让人
|
||||
*/
|
||||
private String endBy;
|
||||
|
||||
|
||||
}
|
|
@ -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.muyu</groupId>
|
||||
<artifactId>cloud-system</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>system-es</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>system-common</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<!-- es -->
|
||||
<dependency>
|
||||
<groupId>org.elasticsearch.client</groupId>
|
||||
<artifactId>elasticsearch-rest-high-level-client</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>system-remote</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,25 @@
|
|||
package com.muyu;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/7/10
|
||||
* @注释
|
||||
*/
|
||||
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
|
||||
@EnableFeignClients(basePackages = "com.muyu.**.remote")
|
||||
public class EsApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(EsApplication.class,args);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package com.muyu.es.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.elasticsearch.client.RestClient;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @ClassName:
|
||||
* @Description:
|
||||
* @Author: xie ya ru
|
||||
* @Date: 2024/7/10
|
||||
*/
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "es")
|
||||
@Data
|
||||
public class InitRestHighLevelClient {
|
||||
|
||||
private String hostname;
|
||||
|
||||
private int port;
|
||||
|
||||
private String scheme;
|
||||
|
||||
@Bean
|
||||
public RestHighLevelClient restHighLevelClient() {
|
||||
return new RestHighLevelClient(
|
||||
RestClient.builder(
|
||||
new HttpHost(hostname, port, scheme)));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package com.muyu.es.controller;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.muyu.cloud.system.domain.request.CouponsAddReq;
|
||||
import com.muyu.cloud.system.domain.request.CouponsReq;
|
||||
import com.muyu.cloud.system.domain.request.CouponsUpdReq;
|
||||
import com.muyu.cloud.system.domain.response.CouponsResp;
|
||||
import com.muyu.common.result.PageResult;
|
||||
import com.muyu.common.result.Result;
|
||||
import com.muyu.es.service.CouponsESService;
|
||||
import lombok.extern.java.Log;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
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;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/8/12 11:37
|
||||
* @注释
|
||||
*/
|
||||
@Log4j2
|
||||
@RestController
|
||||
@RequestMapping("couponsES")
|
||||
public class CouponsESController {
|
||||
@Resource
|
||||
private CouponsESService couponsESService;
|
||||
@Resource
|
||||
private HttpServletRequest request;
|
||||
|
||||
@PostMapping("/showCouponsES")
|
||||
public Result<PageResult<CouponsResp>> showCouponsES(@RequestBody CouponsReq couponsReq){
|
||||
log.info("功能:查询优惠信息列表开始,请求方式:[{}],请求路径:[{}],请求参数[{}]",request.getMethod(),request.getRequestURI(), JSONObject.toJSONString(couponsReq));
|
||||
PageResult<CouponsResp> couponsRespPageResult = couponsESService.showCoupons(couponsReq);
|
||||
log.info("功能:查询优惠信息列表结束,请求方式:[{}],请求路径:[{}],响应参数[{}]",request.getMethod(),request.getRequestURI(),JSONObject.toJSONString(couponsRespPageResult));
|
||||
return Result.success(couponsRespPageResult);
|
||||
}
|
||||
|
||||
@PostMapping("/updESCoupon")
|
||||
public Result updESCoupon(@RequestBody CouponsUpdReq couponsUpdReq){
|
||||
log.info("功能:更新修改优惠券开始,请求路径[{}],请求方法[{}],请求参数[{}]",request.getRequestURI(),request.getMethod(), JSONObject.toJSONString(couponsUpdReq));
|
||||
couponsESService.updESCoupons(couponsUpdReq);
|
||||
log.info("功能:更新修改优惠券开始,请求路径[{}],请求方法[{}]",request.getRequestURI(),request.getMethod());
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@PostMapping("/addESCoupons")
|
||||
public Result addCoupons(@RequestBody CouponsAddReq couponsAddReq){
|
||||
log.info("功能:添加新的优惠券开始,请求路径[{}],请求方法[{}],请求参数[{}],",request.getRequestURI(),request.getMethod(),JSONObject.toJSONString(couponsAddReq));
|
||||
couponsESService.addCouponsAddReq(couponsAddReq);
|
||||
log.info("功能:添加新的优惠券开始,请求路径[{}],请求方法[{}],",request.getRequestURI(),request.getMethod());
|
||||
return Result.success(null,"操作成功");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.muyu.es.service;
|
||||
|
||||
import com.muyu.cloud.system.domain.request.CouponsAddReq;
|
||||
import com.muyu.cloud.system.domain.request.CouponsReq;
|
||||
import com.muyu.cloud.system.domain.request.CouponsUpdReq;
|
||||
import com.muyu.cloud.system.domain.response.CouponsResp;
|
||||
import com.muyu.common.result.PageResult;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/8/12 11:38
|
||||
* @注释
|
||||
*/
|
||||
public interface CouponsESService {
|
||||
|
||||
PageResult<CouponsResp> showCoupons(CouponsReq couponsReq);
|
||||
|
||||
void delBath();
|
||||
|
||||
void addBath(List<CouponsResp> data);
|
||||
|
||||
void updESCoupons(CouponsUpdReq couponsUpdReq);
|
||||
|
||||
void addCouponsAddReq(CouponsAddReq couponsAddReq);
|
||||
}
|
|
@ -0,0 +1,150 @@
|
|||
package com.muyu.es.service.impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.muyu.cloud.system.domain.request.CouponsAddReq;
|
||||
import com.muyu.cloud.system.domain.request.CouponsReq;
|
||||
import com.muyu.cloud.system.domain.request.CouponsUpdReq;
|
||||
import com.muyu.cloud.system.domain.response.CouponsResp;
|
||||
import com.muyu.common.result.PageResult;
|
||||
import com.muyu.common.utils.StringUtils;
|
||||
import com.muyu.es.service.CouponsESService;
|
||||
import org.apache.lucene.search.SortField;
|
||||
import org.elasticsearch.action.bulk.BulkRequest;
|
||||
import org.elasticsearch.action.index.IndexRequest;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.update.UpdateRequest;
|
||||
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.QueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.index.reindex.BulkByScrollResponse;
|
||||
import org.elasticsearch.index.reindex.DeleteByQueryRequest;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.elasticsearch.search.SearchHits;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
|
||||
import org.elasticsearch.search.fetch.subphase.highlight.HighlightField;
|
||||
import org.elasticsearch.xcontent.XContentType;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/8/12 11:39
|
||||
* @注释
|
||||
*/
|
||||
@Service
|
||||
public class CouponsESServiceImpl implements CouponsESService {
|
||||
@Resource
|
||||
private RestHighLevelClient restHighLevelClient;
|
||||
|
||||
private static final String COUPONS_INDEX="my_coupons";
|
||||
|
||||
@Override
|
||||
public PageResult<CouponsResp> showCoupons(CouponsReq couponsReq) {
|
||||
Long total = 0L;
|
||||
ArrayList<CouponsResp> couponsRespArrayList = new ArrayList<>();
|
||||
|
||||
try {
|
||||
SearchRequest searchRequest = new SearchRequest();
|
||||
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
||||
BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();
|
||||
//查询优惠券名称信息
|
||||
if(StringUtils.isNotEmpty(couponsReq.getCouponsName())){
|
||||
boolQueryBuilder.must(QueryBuilders.matchQuery("couponsName",couponsReq.getCouponsName()));
|
||||
}
|
||||
searchSourceBuilder.query(boolQueryBuilder);
|
||||
//获取高亮
|
||||
searchSourceBuilder.highlighter(new HighlightBuilder().field("couponsName")
|
||||
.preTags("<span style='color:red'>")
|
||||
.postTags("</span>"));
|
||||
|
||||
searchRequest.source(searchSourceBuilder);
|
||||
SearchResponse search = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT);
|
||||
SearchHits hits = search.getHits();
|
||||
total = hits.getTotalHits().value;
|
||||
SearchHit[] hits1 = hits.getHits();
|
||||
for (SearchHit documentFields : hits1) {
|
||||
String sourceAsString = documentFields.getSourceAsString();
|
||||
CouponsResp couponsResp = JSONObject.parseObject(sourceAsString, CouponsResp.class);
|
||||
couponsResp.setCouponsId(Long.valueOf(documentFields.getId()));
|
||||
Map<String, HighlightField> highlightFields = documentFields.getHighlightFields();
|
||||
if(highlightFields != null && highlightFields.size() >0){
|
||||
HighlightField wzTitle = highlightFields.get(documentFields.getId());
|
||||
Text[] fragments = wzTitle.getFragments();
|
||||
String str="";
|
||||
for (Text fragment : fragments) {
|
||||
str += fragment;
|
||||
}
|
||||
couponsResp.setCouponsName(str);
|
||||
}
|
||||
couponsRespArrayList.add(couponsResp);
|
||||
}
|
||||
|
||||
return PageResult.toResult(total,couponsRespArrayList).getData();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("搜索是异常,异常信息为:"+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delBath() {
|
||||
try {
|
||||
DeleteByQueryRequest deleteByQueryRequest = new DeleteByQueryRequest(COUPONS_INDEX);
|
||||
deleteByQueryRequest.setQuery(QueryBuilders.matchAllQuery());
|
||||
restHighLevelClient.deleteByQuery(deleteByQueryRequest, RequestOptions.DEFAULT);
|
||||
} catch (IOException e) {
|
||||
|
||||
throw new RuntimeException("批量删除时的异常信息为"+e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addBath(List<CouponsResp> data) {
|
||||
try {
|
||||
BulkRequest bulkRequest = new BulkRequest();
|
||||
data.forEach(couponsResp -> {
|
||||
bulkRequest.add(new IndexRequest(COUPONS_INDEX).id(String.valueOf(couponsResp.getCouponsId()))
|
||||
.source(JSONObject.toJSONString(couponsResp), XContentType.JSON));
|
||||
});
|
||||
restHighLevelClient.bulk(bulkRequest,RequestOptions.DEFAULT);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("批量添加时的异常信息为"+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updESCoupons(CouponsUpdReq couponsUpdReq) {
|
||||
try {
|
||||
UpdateRequest updateRequest = new UpdateRequest();
|
||||
updateRequest
|
||||
.id(String.valueOf(couponsUpdReq.getCouponsId()))
|
||||
.doc(JSONObject.toJSONString(couponsUpdReq));
|
||||
restHighLevelClient.update(updateRequest,RequestOptions.DEFAULT);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("修改优惠券同步异常异常信息为:"+e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCouponsAddReq(CouponsAddReq couponsAddReq) {
|
||||
try {
|
||||
IndexRequest indexRequest = new IndexRequest();
|
||||
indexRequest.index(COUPONS_INDEX).source(JSONObject.toJSONString(couponsAddReq));
|
||||
restHighLevelClient.index(indexRequest,RequestOptions.DEFAULT);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("增加新的优惠券是异常,异常信息为:"+e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package com.muyu.es.sycn;
|
||||
|
||||
import com.muyu.cloud.system.domain.response.CouponsResp;
|
||||
import com.muyu.cloud.system.remote.RemoteCouponsService;
|
||||
import com.muyu.common.result.Result;
|
||||
import com.muyu.common.utils.StringUtils;
|
||||
import com.muyu.es.service.CouponsESService;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/8/12 11:28
|
||||
* @注释
|
||||
*/
|
||||
@Log4j2
|
||||
@Component
|
||||
public class SycnCoupons implements ApplicationRunner {
|
||||
|
||||
@Resource
|
||||
private RemoteCouponsService remoteCouponsService;
|
||||
|
||||
@Resource
|
||||
private CouponsESService couponsESService;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
|
||||
//1.先查询优惠券列表
|
||||
Result<List<CouponsResp>> listResult = remoteCouponsService.selectAll();
|
||||
List<CouponsResp> data = listResult.getData();
|
||||
if(StringUtils.isEmpty(data)){
|
||||
log.info("查询优惠券的数量为空");
|
||||
}
|
||||
//2.删除es的数据
|
||||
couponsESService.delBath();
|
||||
//3.添加数据库到ES数据中
|
||||
|
||||
couponsESService.addBath(data);
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
# Tomcat
|
||||
server:
|
||||
port: 9203
|
||||
# Spring
|
||||
spring:
|
||||
main:
|
||||
allow-circular-references: true
|
||||
jackson:
|
||||
date-format: yyyy-MM-dd HH:mm:ss
|
||||
time-zone: GMT+8
|
||||
application:
|
||||
# 应用名称
|
||||
name: system-es
|
||||
profiles:
|
||||
# 环境配置
|
||||
active: dev
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 1.94.37.42:8848
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 1.94.37.42:8848
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
shared-configs:
|
||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
# 程序Redis公共配置文件
|
||||
- redis-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
es:
|
||||
hostname: 1.94.37.42
|
||||
port: 9200
|
||||
scheme: http
|
|
@ -0,0 +1,27 @@
|
|||
<?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.muyu</groupId>
|
||||
<artifactId>cloud-system</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>system-remote</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- 系统服务公共依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>system-common</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,31 @@
|
|||
package com.muyu.cloud.system.factory;
|
||||
|
||||
import com.muyu.cloud.system.domain.response.CouponsResp;
|
||||
import com.muyu.cloud.system.remote.RemoteCouponsService;
|
||||
import com.muyu.common.constant.ServerNameConstants;
|
||||
import com.muyu.common.result.Result;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/8/12 11:23
|
||||
* @注释
|
||||
*/
|
||||
@Log4j2
|
||||
public class CouponsRemoteFactory implements FallbackFactory<RemoteCouponsService> {
|
||||
@Override
|
||||
public RemoteCouponsService create(Throwable cause) {
|
||||
return new RemoteCouponsService() {
|
||||
@Override
|
||||
public Result<List<CouponsResp>> selectAll() {
|
||||
log.error("服务[{}]调用接口发生异常:[{}]", ServerNameConstants.QUAN_NAME, cause.getMessage(), cause);
|
||||
return Result.error(cause.getMessage());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.muyu.cloud.system.factory;
|
||||
|
||||
import com.muyu.cloud.system.domain.request.CouponsAddReq;
|
||||
import com.muyu.cloud.system.domain.request.CouponsUpdReq;
|
||||
import com.muyu.cloud.system.remote.RemoteESCouponsService;
|
||||
import com.muyu.common.constant.ServerNameConstants;
|
||||
import com.muyu.common.result.Result;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/8/12 15:20
|
||||
* @注释
|
||||
*/
|
||||
@Log4j2
|
||||
public class ESCouponsRemoteFactory implements FallbackFactory<RemoteESCouponsService> {
|
||||
@Override
|
||||
public RemoteESCouponsService create(Throwable cause) {
|
||||
return new RemoteESCouponsService() {
|
||||
@Override
|
||||
public Result updESCoupon(CouponsUpdReq couponsUpdReq) {
|
||||
log.error("服务[{}]调用接口发生异常:[{}]", ServerNameConstants.ES_NAME, cause.getMessage(), cause);
|
||||
return Result.error(cause.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result addCoupons(CouponsAddReq couponsAddReq) {
|
||||
log.error("服务[{}]调用接口发生异常:[{}]", ServerNameConstants.ES_NAME, cause.getMessage(), cause);
|
||||
return Result.error(cause.getMessage());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package com.muyu.cloud.system.factory;
|
||||
|
||||
import com.muyu.cloud.system.domain.UserInfo;
|
||||
import com.muyu.cloud.system.remote.RemoteUserInfoService;
|
||||
import com.muyu.common.constant.ServerNameConstants;
|
||||
import com.muyu.common.result.Result;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
|
||||
/**
|
||||
* @Author: xie ya ru
|
||||
* @date: 2024/7/10
|
||||
* @Description: 用户远程调用熔断机制
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Log4j2
|
||||
public class UserInfoRemoteFactory implements FallbackFactory<RemoteUserInfoService> {
|
||||
@Override
|
||||
public RemoteUserInfoService create (Throwable cause) {
|
||||
return new RemoteUserInfoService() {
|
||||
@Override
|
||||
public Result updUserMoney(UserInfo userInfo) {
|
||||
log.error("服务[{}]调用接口发生异常:[{}]", ServerNameConstants.SYSTEM_NAME, cause.getMessage(), cause);
|
||||
return Result.error(cause.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result diffUserMoney(UserInfo userInfo) {
|
||||
log.error("服务[{}]调用接口发生异常:[{}]", ServerNameConstants.SYSTEM_NAME, cause.getMessage(), cause);
|
||||
return Result.error(cause.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过用户名称查询用户信息
|
||||
*
|
||||
* @param userTel 用户名称
|
||||
*
|
||||
* @return 用户信息
|
||||
*/
|
||||
@Override
|
||||
public Result<UserInfo> login (String userTel) {
|
||||
log.error("服务[{}]调用接口发生异常:[{}]", ServerNameConstants.SYSTEM_NAME, cause.getMessage(), cause);
|
||||
return Result.error(cause.getMessage());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package com.muyu.cloud.system.remote;
|
||||
|
||||
import com.muyu.cloud.system.domain.response.CouponsResp;
|
||||
import com.muyu.cloud.system.factory.CouponsRemoteFactory;
|
||||
import com.muyu.cloud.system.factory.UserInfoRemoteFactory;
|
||||
import com.muyu.common.constant.ServerNameConstants;
|
||||
import com.muyu.common.result.Result;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/8/12 11:19
|
||||
* @注释
|
||||
*/
|
||||
|
||||
@FeignClient(
|
||||
name = ServerNameConstants.QUAN_NAME,
|
||||
// "/user-info" -> controller(requestMapping)
|
||||
path = ServerNameConstants.SystemApi.QUAN_INFO_API,
|
||||
contextId = "remoteCouponsService",
|
||||
fallbackFactory = CouponsRemoteFactory.class
|
||||
)
|
||||
public interface RemoteCouponsService {
|
||||
|
||||
|
||||
@GetMapping("/selectAll")
|
||||
public Result<List<CouponsResp>> selectAll();
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package com.muyu.cloud.system.remote;
|
||||
|
||||
import com.muyu.cloud.system.domain.request.CouponsAddReq;
|
||||
import com.muyu.cloud.system.domain.request.CouponsUpdReq;
|
||||
import com.muyu.cloud.system.factory.CouponsRemoteFactory;
|
||||
import com.muyu.cloud.system.factory.ESCouponsRemoteFactory;
|
||||
import com.muyu.common.constant.ServerNameConstants;
|
||||
import com.muyu.common.result.Result;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/8/12 15:19
|
||||
* @注释
|
||||
*/
|
||||
@FeignClient(
|
||||
name = ServerNameConstants.ES_NAME,
|
||||
// "/user-info" -> controller(requestMapping)
|
||||
path = ServerNameConstants.SystemApi.ES_INFO_API,
|
||||
contextId = "remoteESCouponsService",
|
||||
fallbackFactory = ESCouponsRemoteFactory.class
|
||||
)
|
||||
public interface RemoteESCouponsService {
|
||||
|
||||
/**
|
||||
* 修改优惠券同步
|
||||
* @param couponsUpdReq
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/updESCoupon")
|
||||
public Result updESCoupon(@RequestBody CouponsUpdReq couponsUpdReq);
|
||||
|
||||
/**
|
||||
* 添加优惠券同步
|
||||
* @param couponsAddReq
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/addESCoupons")
|
||||
public Result addCoupons(@RequestBody CouponsAddReq couponsAddReq);
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.muyu.cloud.system.remote;
|
||||
|
||||
import com.muyu.cloud.system.domain.UserInfo;
|
||||
import com.muyu.cloud.system.factory.UserInfoRemoteFactory;
|
||||
import com.muyu.common.constant.ServerNameConstants;
|
||||
import com.muyu.common.result.Result;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* @Author: DongZeLiang
|
||||
* @date: 2024/5/24
|
||||
* @Description: 用户信息远程调用
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@FeignClient(
|
||||
name = ServerNameConstants.SYSTEM_NAME,
|
||||
// "/user-info" -> controller(requestMapping)
|
||||
path = ServerNameConstants.SystemApi.USER_INFO_API,
|
||||
contextId = "remoteUserInfoService",
|
||||
fallbackFactory = UserInfoRemoteFactory.class
|
||||
)
|
||||
public interface RemoteUserInfoService {
|
||||
|
||||
|
||||
/**
|
||||
* 通过用户名称查询用户信息
|
||||
* @param userTel 用户名称
|
||||
* @return 用户信息
|
||||
*/
|
||||
@PostMapping("/login/{userTel}")
|
||||
Result<UserInfo> login(@PathVariable("userTel") String userTel);
|
||||
|
||||
@PutMapping("/updUserMoney")
|
||||
public Result updUserMoney(@RequestBody UserInfo userInfo);
|
||||
|
||||
@PutMapping("/diffUserMoney")
|
||||
public Result diffUserMoney(@RequestBody UserInfo userInfo);
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
com.muyu.cloud.system.factory.UserInfoRemoteFactory
|
||||
com.muyu.cloud.system.factory.CouponsRemoteFactory
|
||||
com.muyu.cloud.system.factory.ESCouponsRemoteFactory
|
|
@ -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.muyu</groupId>
|
||||
<artifactId>cloud-system</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>system-server</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- 系统公共 依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>system-common</artifactId>
|
||||
</dependency>
|
||||
<!-- SpringBoot Web-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,21 @@
|
|||
package com.muyu.cloud.system;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
/**
|
||||
* @Author: xie ya ru
|
||||
* @date: 2024/7/10
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableFeignClients( basePackages = {"com.muyu.**"})
|
||||
@EnableScheduling
|
||||
public class CloudSystemApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(CloudSystemApplication.class, args);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package com.muyu.cloud.system.controller;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.muyu.cloud.system.domain.UserInfo;
|
||||
import com.muyu.cloud.system.service.UserService;
|
||||
import com.muyu.common.result.Result;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.apache.catalina.User;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/8/12 9:51
|
||||
* @注释
|
||||
*/
|
||||
@Log4j2
|
||||
@RestController
|
||||
@RequestMapping("/user")
|
||||
public class UserController {
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
@Resource
|
||||
private HttpServletRequest request;
|
||||
|
||||
@PostMapping("/login/{userTel}")
|
||||
Result<UserInfo> login(@PathVariable("userTel") String userTel){
|
||||
log.info("功能:开始查询登录数据,请求路径[{}],请求方法[{}],请求参数[{}]",request.getRequestURI(),request.getMethod(),userTel);
|
||||
UserInfo userInfo = userService.selectUser(userTel);
|
||||
log.info("功能:查询登录数据结束,请求路径[{}],请求方法[{}],请求参数[{}]",request.getRequestURI(),request.getMethod(), JSONObject.toJSONString(userInfo));
|
||||
return Result.success(userInfo);
|
||||
|
||||
}
|
||||
|
||||
@PutMapping("/updUserMoney")
|
||||
public Result updUserMoney(@RequestBody UserInfo userInfo){
|
||||
userService.updMoney(userInfo);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@PutMapping("/diffUserMoney")
|
||||
public Result diffUserMoney(@RequestBody UserInfo userInfo){
|
||||
userService.diffUserMoney(userInfo);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package com.muyu.cloud.system.mapper;
|
||||
|
||||
import com.muyu.cloud.system.domain.UserInfo;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/8/12 9:43
|
||||
* @注释
|
||||
*/
|
||||
@Mapper
|
||||
public interface UserMapper {
|
||||
|
||||
UserInfo login(@Param("userTel") String userTel);
|
||||
|
||||
void updMoney(UserInfo userInfo);
|
||||
|
||||
void diffUserMoney(UserInfo userInfo);
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.muyu.cloud.system.service;
|
||||
|
||||
import com.muyu.cloud.system.domain.UserInfo;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/8/12 9:46
|
||||
* @注释
|
||||
*/
|
||||
public interface UserService {
|
||||
UserInfo selectUser(String userTel);
|
||||
|
||||
void updMoney(UserInfo userInfo);
|
||||
|
||||
void diffUserMoney(UserInfo userInfo);
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package com.muyu.cloud.system.service.impl;
|
||||
|
||||
import com.muyu.cloud.system.domain.UserInfo;
|
||||
import com.muyu.cloud.system.mapper.UserMapper;
|
||||
import com.muyu.cloud.system.service.UserService;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.apache.http.impl.nio.reactor.IOSessionImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/8/12 9:47
|
||||
* @注释
|
||||
*/
|
||||
@Log4j2
|
||||
@Service
|
||||
public class UserServiceImpl implements UserService {
|
||||
@Resource
|
||||
private UserMapper userMapper;
|
||||
@Override
|
||||
public UserInfo selectUser(String userTel) {
|
||||
return userMapper.login(userTel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updMoney(UserInfo userInfo) {
|
||||
userMapper.updMoney(userInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void diffUserMoney(UserInfo userInfo) {
|
||||
userMapper.diffUserMoney(userInfo);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
# Tomcat
|
||||
server:
|
||||
port: 9201
|
||||
|
||||
# 配置nacos的地址
|
||||
nacos:
|
||||
server-addr: 1.94.37.42:8848
|
||||
|
||||
# Spring
|
||||
spring:
|
||||
main:
|
||||
allow-circular-references: true
|
||||
jackson:
|
||||
date-format: yyyy-MM-dd HH:mm:ss
|
||||
time-zone: GMT+8
|
||||
application:
|
||||
# 应用名称
|
||||
name: system-server
|
||||
profiles:
|
||||
# 环境配置
|
||||
active: dev
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: ${nacos.server-addr}
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: ${nacos.server-addr}
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
shared-configs:
|
||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
# 程序Redis公共配置文件
|
||||
- redis-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
# 程序MySQL公共配置文件
|
||||
- mysql-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
|
||||
- system-server-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
|
||||
fdfs:
|
||||
so-timeout: 1500 # socket 连接时长
|
||||
connect-timeout: 600 # 连接 tracker 服务器超时时长
|
||||
# 这两个是你服务器的 IP 地址,注意 23000 端口也要打开,阿里云服务器记得配置安全组。tracker 要和 stroage 服务进行交流
|
||||
tracker-list: 1.94.37.42:22122
|
||||
web-server-url: 1.94.37.42:8888
|
||||
pool:
|
||||
jmx-enabled: false
|
||||
# 生成缩略图
|
||||
thumb-image:
|
||||
height: 500
|
||||
width: 500
|
|
@ -0,0 +1,29 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.muyu.cloud.system.mapper.UserMapper">
|
||||
<update id="updMoney">
|
||||
|
||||
UPDATE `h6-exam812`.`t_user`
|
||||
SET
|
||||
`user_money` = `user_money`+ #{userMoney}
|
||||
WHERE
|
||||
|
||||
`username` = #{username}
|
||||
</update>
|
||||
<update id="diffUserMoney">
|
||||
UPDATE `h6-exam812`.`t_user`
|
||||
SET
|
||||
`user_money` = `user_money`- #{userMoney}
|
||||
WHERE
|
||||
|
||||
`username` = #{username}
|
||||
</update>
|
||||
<!-- 添加 -->
|
||||
|
||||
|
||||
<select id="login" resultType="com.muyu.cloud.system.domain.UserInfo">
|
||||
select * from t_user where user_tel =#{userTel}
|
||||
</select>
|
||||
</mapper>
|
|
@ -0,0 +1,24 @@
|
|||
<?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.muyu</groupId>
|
||||
<artifactId>h6-exam812</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>modules</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>cloud-system</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,80 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>h6-exam812</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>cloud-common</module>
|
||||
<module>cloud-auth</module>
|
||||
<module>cloud-gateway</module>
|
||||
<module>system-log</module>
|
||||
<module>modules</module>
|
||||
</modules>
|
||||
|
||||
<!-- 规定SpringBoot版本 -->
|
||||
<!-- 父级pom文件 主要用于规定项目依赖的各个版本,用于进行项目版本约束 -->
|
||||
<parent>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<version>2.7.15</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
|
||||
<!-- 依赖声明 -->
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<!-- SpringCloud 微服务 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-dependencies</artifactId>
|
||||
<version>2021.0.8</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<!-- SpringCloud Alibaba 微服务 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
|
||||
<version>2021.0.5.0</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<!-- Alibaba Nacos 配置 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-client</artifactId>
|
||||
<version>2.0.4</version>
|
||||
</dependency>
|
||||
<!-- 公共依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 系统服务公共依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>system-common</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
<!-- 系统服务远程调用依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>system-remote</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -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.muyu</groupId>
|
||||
<artifactId>cloud-system</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>system-log</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.muyu</groupId>
|
||||
<artifactId>system-common</artifactId>
|
||||
</dependency>
|
||||
<!-- SpringBoot Web-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,17 @@
|
|||
package com.muyu;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/7/11 14:43
|
||||
* @注释
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class LogInfoApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(LogInfoApplication.class,args);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.muyu.log.controller;
|
||||
|
||||
import com.muyu.log.service.LogInfoService;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/7/11 14:28
|
||||
* @注释
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/logInfo")
|
||||
public class LogInfoController {
|
||||
@Resource
|
||||
private LogInfoService logInfoService;
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package com.muyu.log.core;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.muyu.cloud.system.domain.LogInfo;
|
||||
import com.muyu.log.service.LogInfoService;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @Author: WangXin
|
||||
* @date: 2024/7/10
|
||||
* @Description: controller参数监测
|
||||
* @Version 1.0.0
|
||||
*/
|
||||
@Aspect
|
||||
@Component
|
||||
public class ControllerParameterMonitor {
|
||||
|
||||
@Resource
|
||||
private HttpServletRequest request;
|
||||
|
||||
@Resource
|
||||
private LogInfoService logInfoService;
|
||||
|
||||
@Around("execution(* com.muyu.*.controller.*.*(..))")
|
||||
public Object controllerMonitor(ProceedingJoinPoint pjp){
|
||||
try {
|
||||
Object target = pjp.getTarget();
|
||||
MethodSignature signature = (MethodSignature) pjp.getSignature();
|
||||
String methodName = signature.getName();
|
||||
String className = target.getClass().getName();
|
||||
String requestURI = request.getRequestURI();
|
||||
Object[] args = pjp.getArgs();
|
||||
//请求参数
|
||||
String jsonString = JSONObject.toJSONString(args);
|
||||
System.out.println(jsonString);
|
||||
Object proceed = pjp.proceed();
|
||||
LogInfo logInfo = new LogInfo();
|
||||
logInfo.setLogClassName(className);
|
||||
logInfo.setLogMethodName(methodName);
|
||||
logInfo.setLogRequestUri(requestURI);
|
||||
logInfo.setLogRequestArgs(jsonString);
|
||||
logInfoService.addLog(logInfo);
|
||||
return proceed;
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.muyu.log.mapper;
|
||||
|
||||
import com.muyu.cloud.system.domain.LogInfo;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/7/11 14:29
|
||||
* @注释
|
||||
*/
|
||||
@Mapper
|
||||
public interface LogInfoMapper {
|
||||
|
||||
|
||||
void addLog(LogInfo logInfo);
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.muyu.log.service;
|
||||
|
||||
|
||||
import com.muyu.cloud.system.domain.LogInfo;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/7/11 14:29
|
||||
* @注释
|
||||
*/
|
||||
public interface LogInfoService {
|
||||
void addLog(LogInfo logInfo);
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.muyu.log.service.impl;
|
||||
|
||||
import com.muyu.cloud.system.domain.LogInfo;
|
||||
import com.muyu.log.mapper.LogInfoMapper;
|
||||
import com.muyu.log.service.LogInfoService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author xie ya ru
|
||||
* @Date 2024/7/11 14:29
|
||||
* @注释
|
||||
*/
|
||||
@Service
|
||||
public class LogInfoServiceImpl implements LogInfoService {
|
||||
@Resource
|
||||
private LogInfoMapper logInfoMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public void addLog(LogInfo logInfo) {
|
||||
logInfoMapper.addLog(logInfo);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
# Tomcat
|
||||
server:
|
||||
port: 9205
|
||||
|
||||
# 配置nacos的地址
|
||||
nacos:
|
||||
server-addr: 1.94.37.42:8848
|
||||
|
||||
# Spring
|
||||
spring:
|
||||
main:
|
||||
allow-circular-references: true
|
||||
jackson:
|
||||
date-format: yyyy-MM-dd HH:mm:ss
|
||||
time-zone: GMT+8
|
||||
application:
|
||||
# 应用名称
|
||||
name: system-server
|
||||
profiles:
|
||||
# 环境配置
|
||||
active: dev
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: ${nacos.server-addr}
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: ${nacos.server-addr}
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
shared-configs:
|
||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
# 程序Redis公共配置文件
|
||||
- redis-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
# 程序MySQL公共配置文件
|
||||
- mysql-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
|
||||
- system-server-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.muyu.log.mapper.LogInfoMapper">
|
||||
<!-- 添加 -->
|
||||
|
||||
|
||||
<insert id="addLog">
|
||||
INSERT INTO `h5-moniexercise`.`t_log` ( `method_name`, `class_name`, `request_uri`, `request_args` )
|
||||
VALUES
|
||||
( #{methodName}, #{className}, #{requestUri}, #{requestArgs} )
|
||||
</insert>
|
||||
</mapper>
|
Loading…
Reference in New Issue