Compare commits
No commits in common. "217af96abc879461287ae0ca6a747e9e4876126b" and "370a91773eda7d0398fe5abca301082dcbad7026" have entirely different histories.
217af96abc
...
370a91773e
|
@ -57,10 +57,6 @@
|
||||||
<groupId>com.muyu</groupId>
|
<groupId>com.muyu</groupId>
|
||||||
<artifactId>cloud-common-api-doc</artifactId>
|
<artifactId>cloud-common-api-doc</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>com.mysql</groupId>
|
|
||||||
<artifactId>mysql-connector-j</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
package com.muyu.auth.controller;
|
package com.muyu.auth.controller;
|
||||||
|
|
||||||
import com.muyu.auth.form.EnterpriseSettlement;
|
|
||||||
import com.muyu.auth.form.Firm;
|
|
||||||
import com.muyu.auth.form.LoginBody;
|
import com.muyu.auth.form.LoginBody;
|
||||||
import com.muyu.auth.form.RegisterBody;
|
import com.muyu.auth.form.RegisterBody;
|
||||||
import com.muyu.auth.service.SysFirmService;
|
|
||||||
import com.muyu.auth.service.SysLoginService;
|
import com.muyu.auth.service.SysLoginService;
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
import com.muyu.common.core.utils.JwtUtils;
|
import com.muyu.common.core.utils.JwtUtils;
|
||||||
|
@ -34,16 +31,8 @@ public class TokenController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private SysLoginService sysLoginService;
|
private SysLoginService sysLoginService;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private SysFirmService sysFirmService;
|
|
||||||
|
|
||||||
@PostMapping("login")
|
@PostMapping("login")
|
||||||
public Result<?> login (@RequestBody LoginBody form) {
|
public Result<?> login (@RequestBody LoginBody form) {
|
||||||
//查询企业是否存在
|
|
||||||
Firm firm = sysFirmService.findFirmByName(form.getFirmName());
|
|
||||||
if (firm.getDatabaseName() == null){
|
|
||||||
return Result.error(null,"企业不存在");
|
|
||||||
}
|
|
||||||
// 用户登录
|
// 用户登录
|
||||||
LoginUser userInfo = sysLoginService.login(form.getUsername(), form.getPassword());
|
LoginUser userInfo = sysLoginService.login(form.getUsername(), form.getPassword());
|
||||||
// 获取登录token
|
// 获取登录token
|
||||||
|
@ -80,10 +69,4 @@ public class TokenController {
|
||||||
sysLoginService.register(registerBody.getUsername(), registerBody.getPassword());
|
sysLoginService.register(registerBody.getUsername(), registerBody.getPassword());
|
||||||
return Result.success();
|
return Result.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/enterprise")
|
|
||||||
public Result<?> enterprise( @RequestBody EnterpriseSettlement settlement){
|
|
||||||
sysLoginService.enterprise(settlement.getDatabaseName(),settlement.getFirmName());
|
|
||||||
return Result.success();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
package com.muyu.auth.form;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 企业入驻
|
|
||||||
* @author 袁子龙
|
|
||||||
* @package com.muyu.auth.form
|
|
||||||
* @name EnterpriseSettlement
|
|
||||||
* @date 2024/9/30 11:25
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class EnterpriseSettlement {
|
|
||||||
/**
|
|
||||||
* 企业名称
|
|
||||||
*/
|
|
||||||
private String firmName;
|
|
||||||
/**
|
|
||||||
* 数据库名称
|
|
||||||
*/
|
|
||||||
private String databaseName;
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,28 +0,0 @@
|
||||||
package com.muyu.auth.form;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 企业登录对象
|
|
||||||
* @author 袁子龙
|
|
||||||
* @package com.muyu.auth.form
|
|
||||||
* @name Enterprise
|
|
||||||
* @date 2024/9/30 10:30
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
public class Firm {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 企业id
|
|
||||||
*/
|
|
||||||
private Integer id;
|
|
||||||
/**
|
|
||||||
* 企业名称
|
|
||||||
*/
|
|
||||||
private String firmName;
|
|
||||||
/**
|
|
||||||
* 数据库名称
|
|
||||||
*/
|
|
||||||
private String databaseName;
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,14 +1,10 @@
|
||||||
package com.muyu.auth.form;
|
package com.muyu.auth.form;
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户登录对象
|
* 用户登录对象
|
||||||
*
|
*
|
||||||
* @author muyu
|
* @author muyu
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Data
|
|
||||||
public class LoginBody {
|
public class LoginBody {
|
||||||
/**
|
/**
|
||||||
* 用户名
|
* 用户名
|
||||||
|
@ -20,11 +16,20 @@ public class LoginBody {
|
||||||
*/
|
*/
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
/**
|
|
||||||
* 企业名称
|
|
||||||
*/
|
|
||||||
private String firmName;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public String getUsername () {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUsername (String username) {
|
||||||
|
this.username = username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword () {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword (String password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,57 +0,0 @@
|
||||||
package com.muyu.auth.service;
|
|
||||||
|
|
||||||
import com.muyu.auth.form.Firm;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
|
||||||
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.Statement;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 数据源
|
|
||||||
* @author 袁子龙
|
|
||||||
* @package com.muyu.auth.service
|
|
||||||
* @name SysFirmService
|
|
||||||
* @date 2024/9/30 11:05
|
|
||||||
*/
|
|
||||||
@Component
|
|
||||||
public class SysFirmService {
|
|
||||||
//数据库账号
|
|
||||||
static final String USER="root";
|
|
||||||
//数据库密码
|
|
||||||
static final String PASSWORD="Lw030106";
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private RedisTemplate redisTemplate;
|
|
||||||
public Firm findFirmByName(String firmName){
|
|
||||||
Firm firm = new Firm();
|
|
||||||
try {
|
|
||||||
DriverManager.registerDriver(new com.mysql.cj.jdbc.Driver());
|
|
||||||
Connection connection= DriverManager.getConnection("jdbc:mysql://47.101.53.251:3306/datasource?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT&useSSL=false",USER,PASSWORD);
|
|
||||||
String sql="select * from `datasource` where firm_name = '"+firmName+"'";
|
|
||||||
|
|
||||||
Statement stmt = connection.createStatement();
|
|
||||||
ResultSet rs = stmt.executeQuery(sql);
|
|
||||||
|
|
||||||
|
|
||||||
while (rs.next()){
|
|
||||||
firm.setId(rs.getInt("id"));
|
|
||||||
firm.setFirmName(rs.getString("firm_name"));
|
|
||||||
firm.setDatabaseName(rs.getString("database_name"));
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
//数据源不为空
|
|
||||||
if (firm!=null){
|
|
||||||
redisTemplate.opsForValue().set("datasource",firm.getDatabaseName());
|
|
||||||
}
|
|
||||||
return firm;
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.muyu.auth.service;
|
package com.muyu.auth.service;
|
||||||
|
|
||||||
import com.muyu.auth.form.EnterpriseSettlement;
|
|
||||||
import com.muyu.common.core.constant.CacheConstants;
|
import com.muyu.common.core.constant.CacheConstants;
|
||||||
import com.muyu.common.core.constant.Constants;
|
import com.muyu.common.core.constant.Constants;
|
||||||
import com.muyu.common.core.constant.SecurityConstants;
|
import com.muyu.common.core.constant.SecurityConstants;
|
||||||
|
@ -13,7 +12,6 @@ import com.muyu.common.core.utils.StringUtils;
|
||||||
import com.muyu.common.core.utils.ip.IpUtils;
|
import com.muyu.common.core.utils.ip.IpUtils;
|
||||||
import com.muyu.common.redis.service.RedisService;
|
import com.muyu.common.redis.service.RedisService;
|
||||||
import com.muyu.common.security.utils.SecurityUtils;
|
import com.muyu.common.security.utils.SecurityUtils;
|
||||||
import com.muyu.common.system.domain.Enterprise;
|
|
||||||
import com.muyu.common.system.remote.RemoteUserService;
|
import com.muyu.common.system.remote.RemoteUserService;
|
||||||
import com.muyu.common.system.domain.SysUser;
|
import com.muyu.common.system.domain.SysUser;
|
||||||
import com.muyu.common.system.domain.LoginUser;
|
import com.muyu.common.system.domain.LoginUser;
|
||||||
|
@ -126,29 +124,4 @@ public class SysLoginService {
|
||||||
}
|
}
|
||||||
recordLogService.recordLogininfor(username, Constants.REGISTER, "注册成功");
|
recordLogService.recordLogininfor(username, Constants.REGISTER, "注册成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 企业入驻
|
|
||||||
* @param databaseName
|
|
||||||
* @param fileName
|
|
||||||
*/
|
|
||||||
public void enterprise (String databaseName,String fileName) {
|
|
||||||
// 参数校验 数据库名或企业名称不能为空
|
|
||||||
if (StringUtils.isAnyBlank(databaseName, fileName)) {
|
|
||||||
throw new ServiceException("数据库名或企业名称不能为空");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (databaseName.length() < UserConstants.PASSWORD_MIN_LENGTH || databaseName.length() > UserConstants.PASSWORD_MAX_LENGTH) {
|
|
||||||
throw new ServiceException("数据库名长度必须在5到20个字符之间");
|
|
||||||
}
|
|
||||||
if (fileName.length() < UserConstants.Firm_NAME_MIN_LENGTH || fileName.length() > UserConstants.Firm_NAME_MAX_LENGTH) {
|
|
||||||
throw new ServiceException("企业名称长度必须在2到20个字符之间");
|
|
||||||
}
|
|
||||||
Enterprise settlement = new Enterprise();
|
|
||||||
settlement.setDatabaseName(databaseName);
|
|
||||||
settlement.setFirmName(fileName);
|
|
||||||
|
|
||||||
remoteUserService.settlementEnterpriseInfo(settlement, SecurityConstants.INNER);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ nacos:
|
||||||
addr: 47.101.53.251:8848
|
addr: 47.101.53.251:8848
|
||||||
user-name: nacos
|
user-name: nacos
|
||||||
password: nacos
|
password: nacos
|
||||||
namespace: yzl
|
namespace: lgy
|
||||||
# Spring
|
# Spring
|
||||||
spring:
|
spring:
|
||||||
application:
|
application:
|
||||||
|
|
|
@ -1,49 +0,0 @@
|
||||||
package com.muyu.common.core.constant;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* kafka常量信息
|
|
||||||
* @program: cloud-server
|
|
||||||
* @author: cuiyongxing
|
|
||||||
* @create: 2024-09-28 12:18
|
|
||||||
**/
|
|
||||||
public class KafkaConstant {
|
|
||||||
|
|
||||||
public static final String BOOTSTRAP_SERVERS = "bootstrap.servers";
|
|
||||||
|
|
||||||
public static final String RETRIES = "retries";
|
|
||||||
|
|
||||||
public static final String ACKS = "acks";
|
|
||||||
|
|
||||||
public static final String BATCH_SIZE = "batch.size";
|
|
||||||
|
|
||||||
public static final String BUFFER_MEMORY = "buffer-memory";
|
|
||||||
|
|
||||||
public static final String KEY_SERIALIZER = "key.serializer";
|
|
||||||
|
|
||||||
public static final String VALUE_SERIALIZER = "value.serializer";
|
|
||||||
|
|
||||||
public static final String ENABLE_AUTO_COMMIT = "enable.auto.commit";
|
|
||||||
|
|
||||||
public static final String AUTO_COMMIT_INTERVAL = "auto.commit.interval.ms";
|
|
||||||
|
|
||||||
public static final String AUTO_OFFSET_RESET = "auto.offset.reset";
|
|
||||||
|
|
||||||
public static final String FETCH_MAX_WAIT = "fetch.max.wait";
|
|
||||||
|
|
||||||
public static final String FETCH_MIN_SIZE = "fetch.min.size";
|
|
||||||
|
|
||||||
public static final String HEARTBEAT_INTERVAL = "heartbeat.interval";
|
|
||||||
|
|
||||||
public static final String MAX_POLL_RECORDS = "max.poll.records";
|
|
||||||
|
|
||||||
public static final String KEY_DESERIALIZER = "key.deserializer";
|
|
||||||
|
|
||||||
public static final String VALUE_DESERIALIZER = "value.deserializer";
|
|
||||||
|
|
||||||
public static final String TOPIC = "topic";
|
|
||||||
|
|
||||||
public static final String GROUP_ID = "group.id";
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -110,16 +110,4 @@ public class UserConstants {
|
||||||
public static final int PASSWORD_MIN_LENGTH = 5;
|
public static final int PASSWORD_MIN_LENGTH = 5;
|
||||||
|
|
||||||
public static final int PASSWORD_MAX_LENGTH = 20;
|
public static final int PASSWORD_MAX_LENGTH = 20;
|
||||||
|
|
||||||
/**
|
|
||||||
* 企业名称长度限制
|
|
||||||
*/
|
|
||||||
public static final int Firm_NAME_MIN_LENGTH = 2;
|
|
||||||
public static final int Firm_NAME_MAX_LENGTH = 20;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 数据库名称长度限制
|
|
||||||
*/
|
|
||||||
public static final int DATABASE_NAME_MIN_LENGTH = 2;
|
|
||||||
public static final int DATABASE_NAME_MAX_LENGTH = 20;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,40 +0,0 @@
|
||||||
<?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-common</artifactId>
|
|
||||||
<version>3.6.3</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>cloud-common-kafka</artifactId>
|
|
||||||
<description>
|
|
||||||
cloud-common-kafka消息队列
|
|
||||||
</description>
|
|
||||||
<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>org.apache.kafka</groupId>
|
|
||||||
<artifactId>kafka-clients</artifactId>
|
|
||||||
<version>3.0.0</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.muyu</groupId>
|
|
||||||
<artifactId>cloud-common-core</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.kafka</groupId>
|
|
||||||
<artifactId>kafka-clients</artifactId>
|
|
||||||
<version>2.8.0</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
|
|
||||||
</dependencies>
|
|
||||||
</project>
|
|
|
@ -1,96 +0,0 @@
|
||||||
package com.muyu.common.kafka.config;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import com.muyu.common.core.constant.KafkaConstant;
|
|
||||||
import org.apache.kafka.clients.consumer.KafkaConsumer;
|
|
||||||
import org.apache.kafka.common.serialization.StringDeserializer;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* kafka消费者配置类
|
|
||||||
* @program: cloud-server
|
|
||||||
* @author: cuiyongxing
|
|
||||||
* @create: 2024-09-28 14:28
|
|
||||||
**/
|
|
||||||
@Configuration
|
|
||||||
public class KafkaConsumerConfig {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 服务端id+端口号
|
|
||||||
*/
|
|
||||||
@Value("${spring.kafka.consumer.bootstrap-servers}")
|
|
||||||
private String bootstrapServers;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 偏移量
|
|
||||||
*/
|
|
||||||
@Value("${spring.kafka.consumer.enable-auto-commit}")
|
|
||||||
private Boolean enableAutoCommit;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 自动提交时间间隔
|
|
||||||
*/
|
|
||||||
@Value("${spring.kafka.consumer.auto-commit-interval}")
|
|
||||||
private Integer autoCommitInterval;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 偏移量配置
|
|
||||||
*/
|
|
||||||
@Value("${spring.kafka.consumer.auto-offset-reset}")
|
|
||||||
private String autoOffsetReset;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 阻塞最大时间
|
|
||||||
*/
|
|
||||||
@Value("${spring.kafka.consumer.fetch-max-wait}")
|
|
||||||
private Integer fetchMaxWait;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 请求最小字节
|
|
||||||
*/
|
|
||||||
@Value("${spring.kafka.consumer.fetch-min-size}")
|
|
||||||
private Integer fetchMinSize;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 心跳间隔时间
|
|
||||||
*/
|
|
||||||
@Value("${spring.kafka.consumer.heartbeat-interval}")
|
|
||||||
private Integer heartbeatInterval;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 最大记录条数
|
|
||||||
*/
|
|
||||||
@Value("${spring.kafka.consumer.max-poll-records}")
|
|
||||||
private Integer maxPollRecords;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 消费组
|
|
||||||
*/
|
|
||||||
@Value("${spring.kafka.consumer.group-id}")
|
|
||||||
private String groupId;
|
|
||||||
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public KafkaConsumer kafkaConsumer(){
|
|
||||||
Map<String,Object> configs = new HashMap<>();
|
|
||||||
configs.put(KafkaConstant.BOOTSTRAP_SERVERS, bootstrapServers);
|
|
||||||
configs.put(KafkaConstant.ENABLE_AUTO_COMMIT, enableAutoCommit);
|
|
||||||
configs.put(KafkaConstant.AUTO_COMMIT_INTERVAL, autoCommitInterval);
|
|
||||||
configs.put(KafkaConstant.AUTO_OFFSET_RESET, autoOffsetReset);
|
|
||||||
configs.put(KafkaConstant.FETCH_MAX_WAIT, fetchMaxWait);
|
|
||||||
configs.put(KafkaConstant.FETCH_MIN_SIZE, fetchMinSize);
|
|
||||||
configs.put(KafkaConstant.HEARTBEAT_INTERVAL, heartbeatInterval);
|
|
||||||
configs.put(KafkaConstant.MAX_POLL_RECORDS, maxPollRecords);
|
|
||||||
configs.put(KafkaConstant.GROUP_ID, groupId);
|
|
||||||
StringDeserializer keyDeserializer = new StringDeserializer();
|
|
||||||
StringDeserializer valueDeserializer = new StringDeserializer();
|
|
||||||
return new KafkaConsumer(configs, keyDeserializer, valueDeserializer);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,68 +0,0 @@
|
||||||
package com.muyu.common.kafka.config;
|
|
||||||
|
|
||||||
import com.muyu.common.core.constant.KafkaConstant;
|
|
||||||
import org.apache.kafka.clients.producer.KafkaProducer;
|
|
||||||
import org.apache.kafka.common.serialization.StringSerializer;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* kafka生产者配置信息
|
|
||||||
* @program: cloud-server
|
|
||||||
* @author: cuiyongxing
|
|
||||||
* @create: 2024-09-28 12:03
|
|
||||||
**/
|
|
||||||
@Configuration
|
|
||||||
public class KafkaProducerConfig {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 服务端ip+端口号
|
|
||||||
*/
|
|
||||||
@Value("${spring.kafka.producer.bootstrap-servers}")
|
|
||||||
private String bootstrapServers;
|
|
||||||
/**
|
|
||||||
* 重试次数
|
|
||||||
*/
|
|
||||||
@Value("${spring.kafka.producer.retries}")
|
|
||||||
private Integer retries;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 默认批量大小
|
|
||||||
*/
|
|
||||||
@Value("${spring.kafka.producer.batch-size}")
|
|
||||||
private Integer batchSize;
|
|
||||||
/**
|
|
||||||
* 总内存字节数
|
|
||||||
*/
|
|
||||||
@Value("${spring.kafka.producer.buffer-memory}")
|
|
||||||
private Integer bufferMemory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 偏移量
|
|
||||||
*/
|
|
||||||
@Value("${spring.kafka.producer.acks}")
|
|
||||||
private String acks;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public KafkaProducer kafkaProducer() {
|
|
||||||
Map<String, Object> configs = new HashMap<>();
|
|
||||||
configs.put(KafkaConstant.BOOTSTRAP_SERVERS, bootstrapServers);
|
|
||||||
configs.put(KafkaConstant.RETRIES, retries);
|
|
||||||
configs.put(KafkaConstant.BATCH_SIZE, batchSize);
|
|
||||||
configs.put(KafkaConstant.BUFFER_MEMORY, bufferMemory);
|
|
||||||
configs.put(KafkaConstant.ACKS, acks);
|
|
||||||
StringSerializer keySerializer = new StringSerializer();
|
|
||||||
StringSerializer valueSerializer = new StringSerializer();
|
|
||||||
KafkaProducer kafkaProducer = new KafkaProducer<>(configs, keySerializer, valueSerializer);
|
|
||||||
return kafkaProducer;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,2 +0,0 @@
|
||||||
com.muyu.common.kafka.config.KafkaConsumerConfig
|
|
||||||
com.muyu.common.kafka.config.KafkaProducerConfig
|
|
|
@ -17,10 +17,6 @@
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<description>
|
|
||||||
cloud-common-rabbit 消息队列服务
|
|
||||||
</description>
|
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<!-- rabbitMq 消息队列 -->
|
<!-- rabbitMq 消息队列 -->
|
||||||
|
@ -32,7 +28,7 @@
|
||||||
<!-- 项目公共核心 -->
|
<!-- 项目公共核心 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.muyu</groupId>
|
<groupId>com.muyu</groupId>
|
||||||
<artifactId>cloud-common-redis</artifactId>
|
<artifactId>cloud-common-core</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
package com.muyu.common.rabbit;
|
||||||
|
|
||||||
|
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||||
|
import org.springframework.amqp.rabbit.listener.RabbitListenerEndpointRegistrar;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.messaging.converter.MappingJackson2MessageConverter;
|
||||||
|
import org.springframework.messaging.handler.annotation.support.DefaultMessageHandlerMethodFactory;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class RabbitListenerConfigurer implements org.springframework.amqp.rabbit.annotation.RabbitListenerConfigurer {
|
||||||
|
|
||||||
|
static {
|
||||||
|
System.setProperty("spring.amqp.deserialization.trust.all", "true");
|
||||||
|
}
|
||||||
|
|
||||||
|
//以下配置RabbitMQ消息服务
|
||||||
|
@Autowired
|
||||||
|
public ConnectionFactory connectionFactory;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理器方法工厂
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public DefaultMessageHandlerMethodFactory handlerMethodFactory() {
|
||||||
|
DefaultMessageHandlerMethodFactory factory = new DefaultMessageHandlerMethodFactory();
|
||||||
|
// 这里的转换器设置实现了 通过 @Payload 注解 自动反序列化message body
|
||||||
|
factory.setMessageConverter(new MappingJackson2MessageConverter());
|
||||||
|
return factory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void configureRabbitListeners(RabbitListenerEndpointRegistrar rabbitListenerEndpointRegistrar) {
|
||||||
|
rabbitListenerEndpointRegistrar.setMessageHandlerMethodFactory(handlerMethodFactory());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -1,83 +0,0 @@
|
||||||
package com.muyu.common.rabbit.config;
|
|
||||||
|
|
||||||
|
|
||||||
import com.muyu.common.rabbit.constants.RabbitmqConstants;
|
|
||||||
import org.springframework.amqp.core.*;
|
|
||||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ClassName: DelayedQueueConfig
|
|
||||||
* @Description: 延迟队列配置类
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
public class DelayedQueueConfig {
|
|
||||||
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private RabbitAdmin rabbitAdmin;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 声明队列
|
|
||||||
* @return 返回队列
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public Queue delayedQueue() {
|
|
||||||
Queue queue = new Queue(RabbitmqConstants.DELAYED_QUEUE_NAME);
|
|
||||||
rabbitAdmin.declareQueue(queue);
|
|
||||||
return queue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 声明交换机
|
|
||||||
* @return 返回交换机
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public Exchange delayedExchange() {
|
|
||||||
HashMap<String, Object> arguments = new HashMap<>(3);
|
|
||||||
|
|
||||||
arguments.put("x-delayed-type", "direct");
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 声明自定义交换机
|
|
||||||
* 第一个参数:交换机的名称
|
|
||||||
* 第二个参数:交换机的类型
|
|
||||||
* 第三个参数:是否需要持久化
|
|
||||||
* 第四个参数:是否自动删除
|
|
||||||
* 第五个参数:其他参数
|
|
||||||
*/
|
|
||||||
CustomExchange customExchange = new CustomExchange(
|
|
||||||
RabbitmqConstants.DELAYED_EXCHANGE_NAME,
|
|
||||||
"x-delayed-message",
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
arguments);
|
|
||||||
rabbitAdmin.declareExchange(customExchange);
|
|
||||||
return customExchange;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 绑定交换机
|
|
||||||
* @param delayedQueue 队列对象
|
|
||||||
* @param delayedExchange 交换机对象
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public Binding delayedQueueBindingDelayedExchange(
|
|
||||||
@Qualifier("delayedQueue") Queue delayedQueue,
|
|
||||||
@Qualifier("delayedExchange") Exchange delayedExchange) {
|
|
||||||
|
|
||||||
Binding noargs = BindingBuilder.bind(delayedQueue)
|
|
||||||
.to(delayedExchange)
|
|
||||||
.with(RabbitmqConstants.DELAYED_ROUTING_KEY)
|
|
||||||
.noargs();
|
|
||||||
rabbitAdmin.declareBinding(noargs);
|
|
||||||
return noargs;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,47 +0,0 @@
|
||||||
package com.muyu.common.rabbit.config;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import org.springframework.amqp.rabbit.connection.CorrelationData;
|
|
||||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ClassName:
|
|
||||||
* @Description: 消息发送到 交换机的确认 回调方法
|
|
||||||
*/
|
|
||||||
@Component
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class MyConfirmCallback implements RabbitTemplate.ConfirmCallback {
|
|
||||||
|
|
||||||
|
|
||||||
private RabbitTemplate rabbitTemplate;
|
|
||||||
|
|
||||||
// public MyConfirmCallback(RabbitTemplate rabbitTemplate) {
|
|
||||||
// this.rabbitTemplate = rabbitTemplate;
|
|
||||||
// // 设置 消息发送到交换机成功 的回调
|
|
||||||
// this.rabbitTemplate.setConfirmCallback(this);
|
|
||||||
// }
|
|
||||||
|
|
||||||
@PostConstruct
|
|
||||||
public void init() {
|
|
||||||
this.rabbitTemplate.setConfirmCallback(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 发送消息到交换机的回调方法 消息发送成功或者失败都会执行
|
|
||||||
*
|
|
||||||
* @param correlationData correlation data for the callback. 消息的元数据
|
|
||||||
* @param ack true for ack, false for nack
|
|
||||||
* @param cause An optional cause, for nack, when available, otherwise null.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void confirm(CorrelationData correlationData, boolean ack, String cause) {
|
|
||||||
if (ack) {
|
|
||||||
System.out.println("消息发送到交换机成功~");
|
|
||||||
} else {
|
|
||||||
System.out.println("消息发送到交换机失败,失败的原因:" + cause);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,49 +0,0 @@
|
||||||
package com.muyu.common.rabbit.config;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
|
||||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
|
||||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ClassName: RabbitAdminConfig
|
|
||||||
* @Description: RabbitAdmin配置类
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
public class RabbitAdminConfig {
|
|
||||||
@Value("${spring.rabbitmq.host}")
|
|
||||||
private String host;
|
|
||||||
@Value("${spring.rabbitmq.username}")
|
|
||||||
private String username;
|
|
||||||
@Value("${spring.rabbitmq.password}")
|
|
||||||
private String password;
|
|
||||||
@Value("${spring.rabbitmq.virtualhost}")
|
|
||||||
private String virtualHost;
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public ConnectionFactory connectionFactory() {
|
|
||||||
CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory();
|
|
||||||
cachingConnectionFactory.setHost(host);
|
|
||||||
cachingConnectionFactory.setUsername(username);
|
|
||||||
cachingConnectionFactory.setPassword(password);
|
|
||||||
cachingConnectionFactory.setVirtualHost(virtualHost);
|
|
||||||
return cachingConnectionFactory;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public RabbitAdmin rabbitAdmin(ConnectionFactory connectionFactory) {
|
|
||||||
RabbitAdmin rabbitAdmin = new RabbitAdmin(connectionFactory);
|
|
||||||
rabbitAdmin.setAutoStartup(true);
|
|
||||||
return rabbitAdmin;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
package com.muyu.common.rabbit.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;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* JSON 消息转换器 自动将发送的消息转换成 json 字符串 并且 消费者接收到消息的时候自动反序列化 成需要的对象
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
public class RabbitmqConfig {
|
|
||||||
|
|
||||||
|
|
||||||
// 消息转换配置
|
|
||||||
@Bean
|
|
||||||
public MessageConverter jsonMessageConverter() {
|
|
||||||
return new Jackson2JsonMessageConverter();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,37 +0,0 @@
|
||||||
package com.muyu.common.rabbit.config;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import org.springframework.amqp.core.ReturnedMessage;
|
|
||||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 消息发送到 队列的确认
|
|
||||||
*/
|
|
||||||
@Component
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class ReturnCallbackConfig implements RabbitTemplate.ReturnsCallback {
|
|
||||||
|
|
||||||
|
|
||||||
private final RabbitTemplate rabbitTemplate;
|
|
||||||
|
|
||||||
@PostConstruct // @PostContruct是spring框架的注解,在⽅法上加该注解会在项⽬启动的时候执⾏该⽅法,也可以理解为在spring容器初始化的时候执
|
|
||||||
public void init() {
|
|
||||||
rabbitTemplate.setReturnsCallback(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 消息发送到 队列失败的时候执行
|
|
||||||
*
|
|
||||||
* @param returnedMessage the returned message and metadata.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void returnedMessage(ReturnedMessage returnedMessage) {
|
|
||||||
System.out.println("消息" + returnedMessage.getMessage().toString() +
|
|
||||||
"被交换机" + returnedMessage.getExchange() + "回退!"
|
|
||||||
+ "退回原因为:" + returnedMessage.getReplyText());
|
|
||||||
// 回退了所有的信息,可做补偿机制 记录发送的日志
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,75 +0,0 @@
|
||||||
package com.muyu.common.rabbit.config;
|
|
||||||
|
|
||||||
import org.springframework.amqp.core.*;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author: WangXin
|
|
||||||
* @Time: 2024/4/22 11:55
|
|
||||||
* @Description: 主题模式配置
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
public class TopicConfig {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 主题模式交换机
|
|
||||||
* @return exchange
|
|
||||||
*/
|
|
||||||
@Bean(name = "topicExchange")
|
|
||||||
public Exchange getTopicExchange(){
|
|
||||||
return ExchangeBuilder
|
|
||||||
.topicExchange("exchange_topic")
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 主题队列 01
|
|
||||||
* @return queue
|
|
||||||
*/
|
|
||||||
@Bean(name = "topicQueue01")
|
|
||||||
public Queue getTopicQueue01(){
|
|
||||||
return QueueBuilder
|
|
||||||
.durable("queue_topic_01")
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 主题队列 02
|
|
||||||
* @return queue
|
|
||||||
*/
|
|
||||||
@Bean(name = "topicQueue02")
|
|
||||||
public Queue getTopicQueue02(){
|
|
||||||
return QueueBuilder
|
|
||||||
.durable("queue_topic_02")
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 绑定队列 01
|
|
||||||
* @return binding
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public Binding getTopicBinding01(){
|
|
||||||
return BindingBuilder
|
|
||||||
.bind(getTopicQueue01())
|
|
||||||
.to(getTopicExchange())
|
|
||||||
//路由键 队列1接收debug级别的消息
|
|
||||||
.with("front.#")
|
|
||||||
.noargs();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 绑定队列 02
|
|
||||||
* @return binding
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public Binding getTopicBinding02(){
|
|
||||||
return BindingBuilder
|
|
||||||
.bind(getTopicQueue02())
|
|
||||||
.to(getTopicExchange())
|
|
||||||
// 路由键 队列2接收info级别的消息
|
|
||||||
.with("back.order.*")
|
|
||||||
.noargs();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,35 +0,0 @@
|
||||||
package com.muyu.common.rabbit.constants;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author: 刘武
|
|
||||||
* @date: 2024/7/10
|
|
||||||
* @Description: rabbitmq常量
|
|
||||||
* @Version 1.0.0
|
|
||||||
*/
|
|
||||||
public interface RabbitmqConstants {
|
|
||||||
|
|
||||||
//普通队列
|
|
||||||
String BASIC_QUEUE_NAME = "BASIC_QUEUE_NAME";
|
|
||||||
|
|
||||||
String lOG_QUEUE_NAME = "LOG_QUEUE_NAME";
|
|
||||||
//延迟队列
|
|
||||||
//队列名称
|
|
||||||
String DELAYED_QUEUE_NAME = "delayed_queue";
|
|
||||||
//交换机名称
|
|
||||||
String DELAYED_EXCHANGE_NAME = "DELAYED_EXCHANGE";
|
|
||||||
//交换机
|
|
||||||
String DELAYED_ROUTING_KEY = "delayed";
|
|
||||||
/**
|
|
||||||
* 上下线监听交换机
|
|
||||||
*/
|
|
||||||
String TOP_BOTTOM_STITCHING = "top_bottom_stitching";
|
|
||||||
/**
|
|
||||||
* 上线规则
|
|
||||||
*/
|
|
||||||
String TOP_RULE = "car.top.data";
|
|
||||||
/**
|
|
||||||
* 车辆下线规则
|
|
||||||
*/
|
|
||||||
String BOTTOM_RULE = "car.bottom.data";
|
|
||||||
}
|
|
|
@ -1,140 +0,0 @@
|
||||||
package com.muyu.common.rabbit.consumer;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
|
||||||
import com.muyu.common.redis.service.RedisService;
|
|
||||||
import com.rabbitmq.client.Channel;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.extern.log4j.Log4j2;
|
|
||||||
import org.springframework.amqp.core.Message;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ClassName: RabbitMQConsumerUtil
|
|
||||||
* @Description: rabbitmq消费者
|
|
||||||
*/
|
|
||||||
@Component
|
|
||||||
@Log4j2
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class RabbitMQConsumerUtil {
|
|
||||||
|
|
||||||
private final RedisService redisService;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 普通消费者
|
|
||||||
* @param data 数据类型
|
|
||||||
* @param message
|
|
||||||
* @param channel
|
|
||||||
*/
|
|
||||||
public void rabbitMQBasicConsumer(Object data ,Message message , Channel channel) {
|
|
||||||
log.info("当前时间:{} :RabbitMQConsumerUtil : {}", new Date(), message);
|
|
||||||
try {
|
|
||||||
// 获取到消息 开始消费
|
|
||||||
log.info("消息消费者接收到消息,消息内容:{}", JSONObject.toJSONString(data));
|
|
||||||
|
|
||||||
|
|
||||||
Long add = redisService.redisTemplate.opsForSet().add(data, message.getMessageProperties().getMessageId());
|
|
||||||
|
|
||||||
if (add != 1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* -----------------------------------以下为异步业务操作----------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ------------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
// 消费消息成功之后需要确认
|
|
||||||
// long deliveryTag 消息投递序号 自增的数字 在整个队列中唯一 拿到这个序号就相当于拿到这条消息
|
|
||||||
// boolean multiple 是否批量确认 true 批量 确认小于等于当前投递序号的消息 false 单个确认
|
|
||||||
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
|
|
||||||
log.info("xxx消费者接收到消息,消息内容:{},消费成功...", message);
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("xxx消费者接收到消息,消息内容:{},消费消息异常,异常信息:{}", message, e);
|
|
||||||
// 消息回退 拒绝消费消息
|
|
||||||
// long deliveryTag 消息投递序号 自增的数字 在整个队列中唯一 拿到这个序号就相当于拿到这条消息
|
|
||||||
// boolean requeue 是否回到原来的队列
|
|
||||||
try {
|
|
||||||
channel.basicReject(message.getMessageProperties().getDeliveryTag(), true);
|
|
||||||
// channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, true);
|
|
||||||
} catch (IOException ex) {
|
|
||||||
log.error("xxx消费者接收到消息,消息内容:{},回退消息异常,异常信息:{}", message, ex);
|
|
||||||
}
|
|
||||||
}finally {
|
|
||||||
try {
|
|
||||||
channel.close();
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("xxx消费者关闭Channel异常,消息内容:{},异常信息:{}", message, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 普通消费者
|
|
||||||
* @param data 数据类型
|
|
||||||
* @param message
|
|
||||||
* @param channel
|
|
||||||
*/
|
|
||||||
public void carUpConsumer(String data,Message message , Channel channel) {
|
|
||||||
log.info("当前时间:{} :RabbitMQConsumerUtil : {}", new Date(), message);
|
|
||||||
try {
|
|
||||||
// 获取到消息 开始消费
|
|
||||||
log.info("消息消费者接收到消息,消息内容:{}", JSONObject.toJSONString(data));
|
|
||||||
|
|
||||||
|
|
||||||
Long add = redisService.redisTemplate.opsForSet().add(data, message.getMessageProperties().getMessageId());
|
|
||||||
|
|
||||||
if (add != 1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* -----------------------------------以下为异步业务操作----------------------------
|
|
||||||
*/
|
|
||||||
log.info("[ 根据vin拿到缓存 ] vin为 --》 {}",data);
|
|
||||||
log.info("[ 存入本地缓存 ] 数据为 --》 {}",data);
|
|
||||||
log.info("[ 存入本地缓存 ] 数据为 --》 {}",data);
|
|
||||||
/**
|
|
||||||
* ------------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
// 消费消息成功之后需要确认
|
|
||||||
// long deliveryTag 消息投递序号 自增的数字 在整个队列中唯一 拿到这个序号就相当于拿到这条消息
|
|
||||||
// boolean multiple 是否批量确认 true 批量 确认小于等于当前投递序号的消息 false 单个确认
|
|
||||||
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
|
|
||||||
log.info("xxx消费者接收到消息,消息内容:{},消费成功...", message);
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("xxx消费者接收到消息,消息内容:{},消费消息异常,异常信息:{}", message, e);
|
|
||||||
// 消息回退 拒绝消费消息
|
|
||||||
// long deliveryTag 消息投递序号 自增的数字 在整个队列中唯一 拿到这个序号就相当于拿到这条消息
|
|
||||||
// boolean requeue 是否回到原来的队列
|
|
||||||
try {
|
|
||||||
channel.basicReject(message.getMessageProperties().getDeliveryTag(), true);
|
|
||||||
// channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, true);
|
|
||||||
} catch (IOException ex) {
|
|
||||||
log.error("xxx消费者接收到消息,消息内容:{},回退消息异常,异常信息:{}", message, ex);
|
|
||||||
}
|
|
||||||
}finally {
|
|
||||||
try {
|
|
||||||
channel.close();
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("xxx消费者关闭Channel异常,消息内容:{},异常信息:{}", message, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,174 +0,0 @@
|
||||||
package com.muyu.common.rabbit.producer;
|
|
||||||
|
|
||||||
import com.muyu.common.core.domain.Result;
|
|
||||||
import com.muyu.common.rabbit.constants.RabbitmqConstants;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.extern.log4j.Log4j2;
|
|
||||||
import org.springframework.amqp.core.MessageProperties;
|
|
||||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ClassName: RabbitMQProducer
|
|
||||||
* @Description: rabbitmq生产者
|
|
||||||
*/
|
|
||||||
@Component
|
|
||||||
@AllArgsConstructor
|
|
||||||
@Log4j2
|
|
||||||
public class RabbitMQProducerUtil {
|
|
||||||
//redis工具类对象
|
|
||||||
|
|
||||||
//rabbit
|
|
||||||
private final RabbitTemplate rabbitTemplate;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 简单模型
|
|
||||||
*
|
|
||||||
* @param param 传递的消息 (如果是对象需要序列化)
|
|
||||||
* @return 结果集
|
|
||||||
* 一对一消费,只有一个消费者能接收到
|
|
||||||
*/
|
|
||||||
public Result<?> basicSendMessage(String queueName, Object param, String msg) {
|
|
||||||
|
|
||||||
log.info("【简单模型mq】 : method: 【 basicSendMessage 】 - ages: 【 String : {}, Object : {}, String : {} 】 ---> 【 消息发送中。。。 】", RabbitmqConstants.BASIC_QUEUE_NAME, param, msg);
|
|
||||||
// 发送简单模型消息
|
|
||||||
// 第一个参数: 绑定规则 相当于 队列名称
|
|
||||||
// 第二个参数:消息内容
|
|
||||||
rabbitTemplate.convertAndSend(queueName, param, message -> {
|
|
||||||
message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
|
|
||||||
return message;
|
|
||||||
} );
|
|
||||||
|
|
||||||
log.info("【简单模型mq】 : method: 【 basicSendMessage 】- queue: 【 {} 】 ---> 【 消息发送成功 】", RabbitmqConstants.BASIC_QUEUE_NAME);
|
|
||||||
|
|
||||||
return Result.success(msg!=null?msg:"消息发送成功");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Work queue 工作模型
|
|
||||||
*
|
|
||||||
* @param obj 传递的消息 (如果是对象需要序列化)
|
|
||||||
* @return 结果集
|
|
||||||
* 多个消费者,你一个我一个分配消费消息,有预取机制,默认公平消费,可配置 能者多劳模式(),谁完成的快,谁多做一点
|
|
||||||
*/
|
|
||||||
public Result<?> workSendMessage(String queueName, Object obj, String msg) {
|
|
||||||
|
|
||||||
log.info("【工作模型mq】 : method: 【 workSendMessage 】 - ages: 【 String : {}, Object : {}, String : {} 】 ---> 【 消息发送中。。。 】", queueName, obj, msg);
|
|
||||||
// 发送简单模型消息
|
|
||||||
// 第一个参数: 绑定规则 相当于 队列名称
|
|
||||||
// 第二个参数:消息内容
|
|
||||||
rabbitTemplate.convertAndSend(queueName, obj, message -> {
|
|
||||||
message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
|
|
||||||
return message;
|
|
||||||
} );
|
|
||||||
|
|
||||||
log.info("【工作模型mq】 : method: 【 workSendMessage 】- queue: 【 {} 】 ---> 【 消息发送成功 】", queueName);
|
|
||||||
|
|
||||||
return Result.success("消息发送成功");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Publish/Subscribe 发布订阅者模型
|
|
||||||
* 多个消费者,多个消费者可以同时接收到消息 有交换机 类型 fanout
|
|
||||||
*
|
|
||||||
* @param exchange 交换机名称
|
|
||||||
* @param obj 发送的消息Object
|
|
||||||
* @param msg 响应的内容
|
|
||||||
* @return 结果集
|
|
||||||
*/
|
|
||||||
public Result<?> publishSubscribeSendMessage(String exchange, Object obj, String msg) {
|
|
||||||
|
|
||||||
log.info("【订阅模型mq】 : method: 【 workSendMessage 】 - ages: 【 String : {}, Object : {}, String : {} 】 ---> 【 消息发送中。。。 】", exchange, obj, msg);
|
|
||||||
// 发送简单模型消息
|
|
||||||
// 第一个参数: exchange 交换机的名称
|
|
||||||
// 第二个参数: 绑定规则 发布订阅者模型 不写 默认 "" 只要绑定就行 不需要规则
|
|
||||||
// 第三个参数:消息内容
|
|
||||||
rabbitTemplate.convertAndSend(exchange, "", obj, message -> {
|
|
||||||
message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
|
|
||||||
return message;
|
|
||||||
} );
|
|
||||||
|
|
||||||
log.info("【订阅模型mq】 : method: 【 workSendMessage 】- exchange: 【 {} 】 ---> 【 消息发送成功 】", exchange);
|
|
||||||
|
|
||||||
return Result.success("消息发送成功");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Routing路由模型
|
|
||||||
* 使用的是 Direct 类型的交换机,会将接收到的消息根据 规则 路由到指定的Queue(队列),因此称为路由模式
|
|
||||||
*
|
|
||||||
* @param exchange 交换机名称
|
|
||||||
* @param rule 绑定规则 一个字符串即可
|
|
||||||
* @param obj 发送的消息Object
|
|
||||||
* @param msg 响应的内容
|
|
||||||
* @return 结果集
|
|
||||||
*/
|
|
||||||
public Result<?> routingSendMessage(String exchange, String rule, Object obj, String msg) {
|
|
||||||
|
|
||||||
log.info("【路由模型mq】 : method: 【 workSendMessage 】 - ages: 【 String : {}, Object : {}, String : {} 】 ---> 【 消息发送中。。。 】", exchange, obj, msg);
|
|
||||||
// 发送简单模型消息
|
|
||||||
// 第一个参数: 绑定规则 相当于 队列名称
|
|
||||||
// 第二个参数:消息内容
|
|
||||||
rabbitTemplate.convertAndSend(exchange, rule, obj, message -> {
|
|
||||||
message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
|
|
||||||
return message;
|
|
||||||
} );
|
|
||||||
|
|
||||||
log.info("【路由模型mq】 : method: 【 workSendMessage 】- exchange: 【 {} 】 ---> 【 消息发送成功 】", exchange);
|
|
||||||
|
|
||||||
return Result.success("消息发送成功");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Topic主题模型模型
|
|
||||||
* 使用的是 topic 类型的交换机
|
|
||||||
*
|
|
||||||
* @param exchange 交换机名称
|
|
||||||
* @param rule 绑定规则 可以绑定多个单词以 . 拼接 也可以使用 #(匹配 零个 一个 或 多个 单词) 或 *(匹配 一个 单词) 通配符(例如:name.msg, *.msg, age.# )
|
|
||||||
* @param obj 发送的消息Object
|
|
||||||
* @param msg 响应的内容
|
|
||||||
* @return 结果集
|
|
||||||
*/
|
|
||||||
public Result<?> topicSendMessage(String exchange, String rule, Object obj) {
|
|
||||||
|
|
||||||
log.info("【主题模型mq】 : method: 【 workSendMessage 】 - ages: 【 String : {}, Object : {} 】 ---> 【 消息发送中。。。 】", exchange, obj);
|
|
||||||
// 发送简单模型消息
|
|
||||||
// 第一个参数: 绑定规则 相当于 队列名称
|
|
||||||
// 第二个参数:消息内容
|
|
||||||
rabbitTemplate.convertAndSend(exchange, rule, obj, message -> {
|
|
||||||
message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
|
|
||||||
return message;
|
|
||||||
} );
|
|
||||||
|
|
||||||
log.info("【主题模型mq】 : method: 【 workSendMessage 】- exchange: 【 {} 】 ---> 【 消息发送成功 】", exchange);
|
|
||||||
|
|
||||||
return Result.success(obj,"消息发送成功");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 延迟队列模型
|
|
||||||
* @param param 传输内容
|
|
||||||
* @param delayTime 延迟时间
|
|
||||||
* @return 结果集
|
|
||||||
*/
|
|
||||||
public Result<?> delayedSendMessage(Long delayTime, Object param) {
|
|
||||||
log.info("【延迟队列模型】 : method: 【 delayedSendMessage 】 消息内容:{}---> 【 消息发送中。。。 】",param);
|
|
||||||
|
|
||||||
rabbitTemplate.convertAndSend(RabbitmqConstants.DELAYED_EXCHANGE_NAME, RabbitmqConstants.DELAYED_ROUTING_KEY,param, message -> {
|
|
||||||
MessageProperties messageProperties = message.getMessageProperties();
|
|
||||||
messageProperties.setMessageId(UUID.randomUUID().toString());
|
|
||||||
messageProperties.setDelayLong(delayTime);
|
|
||||||
return message;
|
|
||||||
});
|
|
||||||
log.info("【延迟队列模型】 : method: 【 delayedSendMessage 】 消息内容:{}---> 【 消息发送成功 】",param);
|
|
||||||
|
|
||||||
return Result.success(param,"消息发送成功");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,7 +1 @@
|
||||||
com.muyu.rabbitmq.producer.RabbitMQProducerUtil
|
com.muyu.common.rabbit.RabbitListenerConfigurer
|
||||||
com.muyu.rabbitmq.consumer.RabbitMQConsumerUtil
|
|
||||||
com.muyu.rabbitmq.config.RabbitmqConfig
|
|
||||||
com.muyu.rabbitmq.config.MyConfirmCallback
|
|
||||||
com.muyu.rabbitmq.config.DelayedQueueConfig
|
|
||||||
com.muyu.rabbitmq.config.RabbitAdminConfig
|
|
||||||
com.muyu.rabbitmq.config.ReturnCallbackConfig
|
|
|
@ -1,26 +1,23 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
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>
|
<parent>
|
||||||
<groupId>com.muyu</groupId>
|
<groupId>com.muyu</groupId>
|
||||||
<artifactId>cloud-common</artifactId>
|
<artifactId>cloud-common</artifactId>
|
||||||
<version>3.6.3</version>
|
<version>3.6.3</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<groupId>com.bwie</groupId>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<artifactId>cloud-common-swagger</artifactId>
|
<artifactId>cloud-common-swagger</artifactId>
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
cloud-common-swagger系统接口
|
cloud-common-swagger swagger2文档聚合
|
||||||
</description>
|
</description>
|
||||||
<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>
|
<dependencies>
|
||||||
|
|
||||||
<!-- SpringBoot Web -->
|
<!-- SpringBoot Web -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
|
|
@ -1,21 +1,10 @@
|
||||||
package com.muyu.common.swagger.annotation;
|
package com.muyu.common.swagger.annotation;
|
||||||
|
|
||||||
import com.muyu.common.swagger.config.SwaggerAutoConfiguration;
|
|
||||||
import org.springframework.context.annotation.Import;
|
|
||||||
|
|
||||||
import java.lang.annotation.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author 袁子龙
|
* @author 袁子龙
|
||||||
* @package:com.muyu.common.swagger.annotation
|
* @package:com.muyu.common.swagger.annotation
|
||||||
* @name:EnableCustomSwagger2
|
* @name:EnableCustomSwagger2
|
||||||
* @date:2024/9/29 10:01
|
* @date:2024/9/29 10:01
|
||||||
*/
|
*/
|
||||||
@Target({ElementType.TYPE})
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@Documented
|
|
||||||
@Inherited
|
|
||||||
@Import({SwaggerAutoConfiguration.class})
|
|
||||||
public @interface EnableCustomSwagger2 {
|
public @interface EnableCustomSwagger2 {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,6 @@ import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 在 springboot 2.6.x 不兼容问题的处理
|
|
||||||
* @author 袁子龙
|
* @author 袁子龙
|
||||||
* @package:com.muyu.common.swagger.config
|
* @package:com.muyu.common.swagger.config
|
||||||
* @name:SwaggerBeanPostProcessor
|
* @name:SwaggerBeanPostProcessor
|
||||||
|
|
|
@ -300,3 +300,4 @@ public class SwaggerProperties {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,42 +0,0 @@
|
||||||
package com.muyu.common.system.domain;
|
|
||||||
|
|
||||||
import com.muyu.common.core.annotation.Excel;
|
|
||||||
import com.muyu.common.core.annotation.Excel.ColumnType;
|
|
||||||
import com.muyu.common.core.web.domain.BaseEntity;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import lombok.experimental.SuperBuilder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 企业对象
|
|
||||||
* @author 袁子龙
|
|
||||||
* @package com.muyu.common.system.domain
|
|
||||||
* @name Enterprise
|
|
||||||
* @date 2024/9/30 12:05
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@SuperBuilder
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
public class Enterprise extends BaseEntity {
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 企业Id
|
|
||||||
*/
|
|
||||||
@Excel(name = "企业序号",cellType = ColumnType.NUMERIC, prompt = "企业编号")
|
|
||||||
private Integer id;
|
|
||||||
/**
|
|
||||||
* 企业名称
|
|
||||||
*/
|
|
||||||
@Excel(name = "企业名称")
|
|
||||||
private String firmName;
|
|
||||||
/**
|
|
||||||
* 数据库名称
|
|
||||||
*/
|
|
||||||
@Excel(name = "数据库名称")
|
|
||||||
private String databaseName;
|
|
||||||
}
|
|
|
@ -4,7 +4,6 @@ import com.muyu.common.core.constant.SecurityConstants;
|
||||||
import com.muyu.common.core.constant.ServiceNameConstants;
|
import com.muyu.common.core.constant.ServiceNameConstants;
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
import com.muyu.common.core.web.page.TableDataInfo;
|
import com.muyu.common.core.web.page.TableDataInfo;
|
||||||
import com.muyu.common.system.domain.Enterprise;
|
|
||||||
import com.muyu.common.system.domain.SysFirmUser;
|
import com.muyu.common.system.domain.SysFirmUser;
|
||||||
import com.muyu.common.system.domain.SysUser;
|
import com.muyu.common.system.domain.SysUser;
|
||||||
import com.muyu.common.system.remote.factory.RemoteUserFallbackFactory;
|
import com.muyu.common.system.remote.factory.RemoteUserFallbackFactory;
|
||||||
|
@ -45,13 +44,4 @@ public interface RemoteUserService {
|
||||||
|
|
||||||
@GetMapping("/user/companyList")
|
@GetMapping("/user/companyList")
|
||||||
Result<List<SysUser>> companyList();
|
Result<List<SysUser>> companyList();
|
||||||
|
|
||||||
/**
|
|
||||||
* 入驻企业信息
|
|
||||||
* @param enterprise
|
|
||||||
* @param source
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@PostMapping("/user/settlement")
|
|
||||||
Result<Boolean>settlementEnterpriseInfo(@RequestBody Enterprise enterprise, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package com.muyu.common.system.remote.factory;
|
||||||
|
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
import com.muyu.common.core.web.page.TableDataInfo;
|
import com.muyu.common.core.web.page.TableDataInfo;
|
||||||
import com.muyu.common.system.domain.Enterprise;
|
|
||||||
import com.muyu.common.system.domain.SysFirmUser;
|
import com.muyu.common.system.domain.SysFirmUser;
|
||||||
import com.muyu.common.system.remote.RemoteUserService;
|
import com.muyu.common.system.remote.RemoteUserService;
|
||||||
import com.muyu.common.system.domain.SysUser;
|
import com.muyu.common.system.domain.SysUser;
|
||||||
|
@ -42,11 +41,6 @@ public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserServ
|
||||||
return Result.error("获取企业列表失败:" + throwable.getMessage());
|
return Result.error("获取企业列表失败:" + throwable.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Result<Boolean> settlementEnterpriseInfo(Enterprise enterprise, String source) {
|
|
||||||
return Result.error("入驻企业失败");
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
<module>cloud-common-saas</module>
|
<module>cloud-common-saas</module>
|
||||||
<module>cloud-common-swagger</module>
|
<module>cloud-common-swagger</module>
|
||||||
<module>cloud-common-cache</module>
|
<module>cloud-common-cache</module>
|
||||||
<module>cloud-common-kafka</module>
|
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<artifactId>cloud-common</artifactId>
|
<artifactId>cloud-common</artifactId>
|
||||||
|
|
|
@ -7,7 +7,7 @@ nacos:
|
||||||
addr: 47.101.53.251:8848
|
addr: 47.101.53.251:8848
|
||||||
user-name: nacos
|
user-name: nacos
|
||||||
password: nacos
|
password: nacos
|
||||||
namespace: yzl
|
namespace: lgy
|
||||||
|
|
||||||
# Spring
|
# Spring
|
||||||
spring:
|
spring:
|
||||||
|
|
|
@ -54,6 +54,13 @@
|
||||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.kafka</groupId>
|
||||||
|
<artifactId>spring-kafka</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<!-- Mysql Connector -->
|
<!-- Mysql Connector -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.mysql</groupId>
|
<groupId>com.mysql</groupId>
|
||||||
|
@ -103,17 +110,11 @@
|
||||||
<artifactId>node-commons</artifactId>
|
<artifactId>node-commons</artifactId>
|
||||||
<version>1.3.2</version>
|
<version>1.3.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.muyu</groupId>
|
<groupId>org.springframework.kafka</groupId>
|
||||||
<artifactId>cloud-common-kafka</artifactId>
|
<artifactId>spring-kafka</artifactId>
|
||||||
<version>3.6.3</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.muyu</groupId>
|
|
||||||
<artifactId>cloud-common-rabbit</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
package com.muyu.event.basic;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
|
||||||
import org.springframework.context.ApplicationEvent;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 事件类型
|
|
||||||
* @author 刘武
|
|
||||||
* @package:com.muyu.event.Basic
|
|
||||||
* @name:EventCustom
|
|
||||||
* @date:2024/9/29 21:17
|
|
||||||
*/
|
|
||||||
public class EventCustom extends ApplicationEvent {
|
|
||||||
|
|
||||||
private JSONObject data;
|
|
||||||
|
|
||||||
public EventCustom(Object source,JSONObject data) {
|
|
||||||
super(source);
|
|
||||||
this.data=data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public JSONObject getData(){
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
package com.muyu.event.basic;
|
|
||||||
|
|
||||||
|
|
||||||
import org.springframework.context.ApplicationListener;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 事件监听接口
|
|
||||||
* @author 刘武
|
|
||||||
* @package:com.muyu.event.basic
|
|
||||||
* @name:EventListener
|
|
||||||
* @date:2024/9/29 21:21
|
|
||||||
*/
|
|
||||||
public interface EventListener extends ApplicationListener<EventCustom> {
|
|
||||||
|
|
||||||
void onEvent(EventCustom event);
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,33 +0,0 @@
|
||||||
package com.muyu.event.basic;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSONB;
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
|
||||||
import org.springframework.context.ApplicationEventPublisher;
|
|
||||||
import org.springframework.context.ApplicationEventPublisherAware;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 策略发送事件
|
|
||||||
* @author 刘武
|
|
||||||
* @package:com.muyu.event.basic
|
|
||||||
* @name:EventPublisher
|
|
||||||
* @date:2024/9/29 22:01
|
|
||||||
*/
|
|
||||||
@Component
|
|
||||||
public class EventPublisher implements ApplicationEventPublisherAware {
|
|
||||||
|
|
||||||
private ApplicationEventPublisher publisher;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
|
|
||||||
this.publisher=applicationEventPublisher;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void publishEvent(JSONObject jsonObject){
|
|
||||||
EventCustom event = new EventCustom(this, jsonObject);
|
|
||||||
publisher.publishEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.muyu.event.basics;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 刘武
|
||||||
|
* @package:
|
||||||
|
* @name:EventHandler
|
||||||
|
* @date:2024/9/29
|
||||||
|
*/
|
||||||
|
public class EventHandler {
|
||||||
|
|
||||||
|
private static final ThreadLocal<EventQueueConfig> EVENT_THREAD = new ThreadLocal<>();
|
||||||
|
|
||||||
|
public static void set(final EventQueueConfig handler) {
|
||||||
|
EVENT_THREAD.set(handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static EventQueueConfig get() {
|
||||||
|
return EVENT_THREAD.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void remove(){
|
||||||
|
EVENT_THREAD.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.muyu.event.basics;
|
||||||
|
|
||||||
|
|
||||||
|
public abstract class EventProcessBasics {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下一个事件对象
|
||||||
|
*/
|
||||||
|
protected EventProcessBasics nextEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下一个事件
|
||||||
|
* @param nextHandler 下一个事件处理
|
||||||
|
*/
|
||||||
|
public void setNextHandler(EventProcessBasics nextHandler) {
|
||||||
|
this.nextEvent = nextHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 事件处理抽象类
|
||||||
|
* @param eventKey 事件唯一key
|
||||||
|
*/
|
||||||
|
public abstract void handleEvent(String eventKey);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
package com.muyu.event.basics;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.concurrent.LinkedBlockingDeque;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 刘武
|
||||||
|
* @package:
|
||||||
|
* @name:EventQueueConfig
|
||||||
|
* @date:2024/9/29
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class EventQueueConfig {
|
||||||
|
|
||||||
|
private LinkedBlockingDeque<EventProcessBasics> taskNodeQueue = new LinkedBlockingDeque<>();
|
||||||
|
|
||||||
|
public void addEvent(EventProcessBasics obj){
|
||||||
|
this.taskNodeQueue.add(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hashEventNext(){
|
||||||
|
return !taskNodeQueue.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
private EventProcessBasics nextTaskNode(){
|
||||||
|
return taskNodeQueue.poll();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.muyu.event.basics;
|
||||||
|
|
||||||
|
|
||||||
|
import com.muyu.event.domian.EventActuate;
|
||||||
|
import org.springframework.context.ApplicationEvent;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 刘武
|
||||||
|
* @package:
|
||||||
|
* @name:StartEvent
|
||||||
|
* @date:2024/9/29
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class StartEvent extends ApplicationEvent {
|
||||||
|
|
||||||
|
private EventActuate eventActuate;
|
||||||
|
|
||||||
|
public StartEvent(EventActuate source) {
|
||||||
|
super(source);
|
||||||
|
this.eventActuate = source;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EventActuate getEventActuate() {
|
||||||
|
return eventActuate;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,23 +0,0 @@
|
||||||
package com.muyu.event.config;
|
|
||||||
|
|
||||||
|
|
||||||
import com.muyu.event.listener.AddDatabaseListener;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author 刘武
|
|
||||||
* @package:com.muyu.event.config
|
|
||||||
* @name:EventConfig
|
|
||||||
* @date:2024/9/29 21:13
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
public class EventConfig {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public AddDatabaseListener addDatabaseListener() {
|
|
||||||
return new AddDatabaseListener();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,129 @@
|
||||||
|
package com.muyu.event.config;
|
||||||
|
|
||||||
|
|
||||||
|
import org.apache.kafka.clients.consumer.ConsumerConfig;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.boot.SpringBootConfiguration;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
|
||||||
|
import org.springframework.kafka.config.KafkaListenerContainerFactory;
|
||||||
|
import org.springframework.kafka.core.ConsumerFactory;
|
||||||
|
import org.springframework.kafka.core.DefaultKafkaConsumerFactory;
|
||||||
|
import org.springframework.kafka.listener.ConcurrentMessageListenerContainer;
|
||||||
|
import org.springframework.kafka.listener.ContainerProperties;
|
||||||
|
import org.springframework.kafka.support.serializer.JsonDeserializer;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 徐一杰
|
||||||
|
* @date 2022/10/31 18:05
|
||||||
|
* kafka配置,也可以写在yml,这个文件会覆盖yml
|
||||||
|
*/
|
||||||
|
@SpringBootConfiguration
|
||||||
|
public class KafkaConsumerConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置 Kafka的 主机地址
|
||||||
|
*/
|
||||||
|
@Value("${spring.kafka.consumer.bootstrap-servers}")
|
||||||
|
private String bootstrapServers;
|
||||||
|
/**
|
||||||
|
* 配置分分组
|
||||||
|
*/
|
||||||
|
@Value("${spring.kafka.consumer.group-id}")
|
||||||
|
private String groupId;
|
||||||
|
/**
|
||||||
|
* 是否自动提交 偏移量
|
||||||
|
*/
|
||||||
|
@Value("${spring.kafka.consumer.enable-auto-commit}")
|
||||||
|
private boolean enableAutoCommit;
|
||||||
|
/**
|
||||||
|
* 消费者与Kafka的心跳续约的会话超时时间
|
||||||
|
*/
|
||||||
|
@Value("${spring.kafka.properties.session.timeout.ms}")
|
||||||
|
private String sessionTimeout;
|
||||||
|
/**
|
||||||
|
* 两次poll之间的最大间隔,默认值为5分钟。如果超过这个间隔会触发reBalance
|
||||||
|
*/
|
||||||
|
@Value("${spring.kafka.properties.max.poll.interval.ms}")
|
||||||
|
private String maxPollIntervalTime;
|
||||||
|
|
||||||
|
@Value("${spring.kafka.consumer.max-poll-records}")
|
||||||
|
private String maxPollRecords;
|
||||||
|
|
||||||
|
@Value("${spring.kafka.consumer.auto-offset-reset}")
|
||||||
|
private String autoOffsetReset;
|
||||||
|
|
||||||
|
@Value("${spring.kafka.listener.concurrency}")
|
||||||
|
private Integer concurrency;
|
||||||
|
|
||||||
|
@Value("${spring.kafka.listener.missing-topics-fatal}")
|
||||||
|
private boolean missingTopicsFatal;
|
||||||
|
|
||||||
|
@Value("${spring.kafka.listener.poll-timeout}")
|
||||||
|
private long pollTimeout;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Map<String, Object> consumerConfigs() {
|
||||||
|
Map<String, Object> propsMap = new HashMap<>(16);
|
||||||
|
propsMap.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
|
||||||
|
propsMap.put(ConsumerConfig.GROUP_ID_CONFIG, groupId);
|
||||||
|
//是否自动提交偏移量,默认值是true,为了避免出现重复数据和数据丢失,可以把它设置为false,然后手动提交偏移量
|
||||||
|
propsMap.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, enableAutoCommit);
|
||||||
|
//自动提交的时间间隔,自动提交开启时生效
|
||||||
|
propsMap.put(ConsumerConfig.AUTO_COMMIT_INTERVAL_MS_CONFIG, "2000");
|
||||||
|
//该属性指定了消费者在读取一个没有偏移量的分区或者偏移量无效的情况下该作何处理:
|
||||||
|
//earliest:当各分区下有已提交的offset时,从提交的offset开始消费;无提交的offset时,从头开始消费分区的记录
|
||||||
|
//latest:当各分区下有已提交的offset时,从提交的offset开始消费;无提交的offset时,消费新产生的该分区下的数据(在消费者启动之后生成的记录)
|
||||||
|
//none:当各分区都存在已提交的offset时,从提交的offset开始消费;只要有一个分区不存在已提交的offset,则抛出异常
|
||||||
|
propsMap.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, autoOffsetReset);
|
||||||
|
//两次poll之间的最大间隔,默认值为5分钟。如果超过这个间隔会触发reBalance
|
||||||
|
propsMap.put(ConsumerConfig.MAX_POLL_INTERVAL_MS_CONFIG, maxPollIntervalTime);
|
||||||
|
//这个参数定义了poll方法最多可以拉取多少条消息,默认值为500。如果在拉取消息的时候新消息不足500条,那有多少返回多少;如果超过500条,每次只返回500。
|
||||||
|
//这个默认值在有些场景下太大,有些场景很难保证能够在5min内处理完500条消息,
|
||||||
|
//如果消费者无法在5分钟内处理完500条消息的话就会触发reBalance,
|
||||||
|
//然后这批消息会被分配到另一个消费者中,还是会处理不完,这样这批消息就永远也处理不完。
|
||||||
|
//要避免出现上述问题,提前评估好处理一条消息最长需要多少时间,然后覆盖默认的max.poll.records参数
|
||||||
|
//注:需要开启BatchListener批量监听才会生效,如果不开启BatchListener则不会出现reBalance情况
|
||||||
|
propsMap.put(ConsumerConfig.MAX_POLL_RECORDS_CONFIG, maxPollRecords);
|
||||||
|
//当broker多久没有收到consumer的心跳请求后就触发reBalance,默认值是10s
|
||||||
|
propsMap.put(ConsumerConfig.SESSION_TIMEOUT_MS_CONFIG, sessionTimeout);
|
||||||
|
//序列化(建议使用Json,这种序列化方式可以无需额外配置传输实体类)
|
||||||
|
propsMap.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, JsonDeserializer.class);
|
||||||
|
propsMap.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, JsonDeserializer.class);
|
||||||
|
return propsMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ConsumerFactory<Object, Object> consumerFactory() {
|
||||||
|
// 配置消费者的 Json 反序列化的可信赖包,反序列化实体类需要
|
||||||
|
try (JsonDeserializer<Object> deserializer = new JsonDeserializer<>()) {
|
||||||
|
deserializer.trustedPackages("*");
|
||||||
|
return new DefaultKafkaConsumerFactory<>(consumerConfigs(), new JsonDeserializer<>(), deserializer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* kafka监听容器工厂 负责 从 Kafka的主题中 取出消息进行消费 可以设置消费者的配置
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<Object, Object>> kafkaListenerContainerFactory() {
|
||||||
|
ConcurrentKafkaListenerContainerFactory<Object, Object> factory = new ConcurrentKafkaListenerContainerFactory<>();
|
||||||
|
factory.setConsumerFactory(consumerFactory());
|
||||||
|
//在侦听器容器中运行的线程数,一般设置为 机器数*分区数
|
||||||
|
factory.setConcurrency(concurrency);
|
||||||
|
// 消费监听接口监听的主题不存在时,默认会报错,所以设置为false忽略错误
|
||||||
|
factory.setMissingTopicsFatal(missingTopicsFatal);
|
||||||
|
// 自动提交关闭,需要设置手动消息确认
|
||||||
|
factory.getContainerProperties().setAckMode(ContainerProperties.AckMode.MANUAL_IMMEDIATE);
|
||||||
|
factory.getContainerProperties().setPollTimeout(pollTimeout);
|
||||||
|
// 设置为批量监听,需要用List接收
|
||||||
|
// factory.setBatchListener(true);
|
||||||
|
return factory;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,127 @@
|
||||||
|
package com.muyu.event.config;
|
||||||
|
|
||||||
|
import org.apache.kafka.clients.producer.ProducerConfig;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.kafka.core.DefaultKafkaProducerFactory;
|
||||||
|
import org.springframework.kafka.core.KafkaTemplate;
|
||||||
|
import org.springframework.kafka.core.ProducerFactory;
|
||||||
|
import org.springframework.kafka.transaction.KafkaTransactionManager;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主题生产者的配置类
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class KafkaProviderConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* kafka 的主机地址
|
||||||
|
*/
|
||||||
|
@Value("${spring.kafka.producer.bootstrap-servers}")
|
||||||
|
private String bootstrapServers;
|
||||||
|
/**
|
||||||
|
* 配置 Kafka的事务
|
||||||
|
*/
|
||||||
|
@Value("${spring.kafka.producer.transaction-id-prefix}")
|
||||||
|
private String transactionIdPrefix;
|
||||||
|
/**
|
||||||
|
* 发送确认机制
|
||||||
|
*/
|
||||||
|
@Value("${spring.kafka.producer.acks}")
|
||||||
|
private String acks;
|
||||||
|
/**
|
||||||
|
* 发送重试
|
||||||
|
*/
|
||||||
|
@Value("${spring.kafka.producer.retries}")
|
||||||
|
private String retries;
|
||||||
|
/**
|
||||||
|
* 发送消息的批次大小
|
||||||
|
*/
|
||||||
|
@Value("${spring.kafka.producer.batch-size}")
|
||||||
|
private String batchSize;
|
||||||
|
/**
|
||||||
|
* 消息的缓冲区内存大小
|
||||||
|
*/
|
||||||
|
@Value("${spring.kafka.producer.buffer-memory}")
|
||||||
|
private String bufferMemory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置 健的序列化方式
|
||||||
|
*/
|
||||||
|
@Value("${spring.kafka.producer.key-serializer}")
|
||||||
|
private String keySerializer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置 值的序列化方式
|
||||||
|
*/
|
||||||
|
@Value("${spring.kafka.producer.value-serializer}")
|
||||||
|
private String valueSerializer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建 map 配置消息生产者对象的配置
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public Map<String, Object> producerConfigs() {
|
||||||
|
Map<String, Object> props = new HashMap<>(16);
|
||||||
|
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
|
||||||
|
//acks=0 : 生产者在成功写入消息之前不会等待任何来自服务器的响应。
|
||||||
|
//acks=1 : 只要集群的首领节点收到消息,生产者就会收到一个来自服务器成功响应。
|
||||||
|
//acks=all :只有当所有参与复制的节点全部收到消息时,生产者才会收到一个来自服务器的成功响应。
|
||||||
|
//开启事务必须设为all
|
||||||
|
props.put(ProducerConfig.ACKS_CONFIG, acks);
|
||||||
|
//发生错误后,消息重发的次数,开启事务必须大于0
|
||||||
|
props.put(ProducerConfig.RETRIES_CONFIG, retries);
|
||||||
|
//当多个消息发送到相同分区时,生产者会将消息打包到一起,以减少请求交互. 而不是一条条发送
|
||||||
|
//批次的大小可以通过batch.size 参数设置.默认是16KB
|
||||||
|
//较小的批次大小有可能降低吞吐量(批次大小为0则完全禁用批处理)。
|
||||||
|
//比如说,kafka里的消息5秒钟Batch才凑满了16KB,才能发送出去。那这些消息的延迟就是5秒钟
|
||||||
|
//实测batchSize这个参数没有用
|
||||||
|
props.put(ProducerConfig.BATCH_SIZE_CONFIG, batchSize);
|
||||||
|
//有的时刻消息比较少,过了很久,比如5min也没有凑够16KB,这样延时就很大,所以需要一个参数. 再设置一个时间,到了这个时间,
|
||||||
|
//即使数据没达到16KB,也将这个批次发送出去
|
||||||
|
props.put(ProducerConfig.LINGER_MS_CONFIG, "5000");
|
||||||
|
//生产者内存缓冲区的大小
|
||||||
|
props.put(ProducerConfig.BUFFER_MEMORY_CONFIG, bufferMemory);
|
||||||
|
//反序列化,和生产者的序列化方式对应
|
||||||
|
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, keySerializer);
|
||||||
|
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, valueSerializer);
|
||||||
|
return props;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建 主题生产者工厂
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public ProducerFactory<Object, Object> producerFactory() {
|
||||||
|
DefaultKafkaProducerFactory<Object, Object> factory = new DefaultKafkaProducerFactory<>(producerConfigs());
|
||||||
|
//开启事务,会导致 LINGER_MS_CONFIG 配置失效
|
||||||
|
factory.setTransactionIdPrefix(transactionIdPrefix);
|
||||||
|
return factory;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置 Kafka的事务管理器
|
||||||
|
* @param producerFactory
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public KafkaTransactionManager<Object, Object> kafkaTransactionManager(ProducerFactory<Object, Object> producerFactory) {
|
||||||
|
return new KafkaTransactionManager<>(producerFactory);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建 KafkaTemplate
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public KafkaTemplate<Object, Object> kafkaTemplate() {
|
||||||
|
return new KafkaTemplate<>(producerFactory());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,65 @@
|
||||||
|
package com.muyu.event.config;
|
||||||
|
|
||||||
|
import jakarta.annotation.Nullable;
|
||||||
|
import org.apache.kafka.clients.producer.ProducerRecord;
|
||||||
|
import org.apache.kafka.clients.producer.RecordMetadata;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.kafka.core.KafkaTemplate;
|
||||||
|
import org.springframework.kafka.support.ProducerListener;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class KafkaSendResultHandler implements ProducerListener<Object,Object> {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private KafkaTemplate<Object,Object> kafkaTemplate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bean 初始化方法
|
||||||
|
*/
|
||||||
|
@PostConstruct
|
||||||
|
public void init(){
|
||||||
|
this.kafkaTemplate.setProducerListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息发送到Kafka成功的回调
|
||||||
|
* @param producerRecord
|
||||||
|
* @param recordMetadata
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onSuccess(ProducerRecord producerRecord, RecordMetadata recordMetadata){
|
||||||
|
System.out.println("信息发送成功:"+ producerRecord.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 息发送到 Kafka 失败的回调
|
||||||
|
* @param producerRecord the failed record
|
||||||
|
* @param recordMetadata The metadata for the record that was sent (i.e. the partition
|
||||||
|
* and offset). If an error occurred, metadata will contain only valid topic and maybe
|
||||||
|
* the partition. If the partition is not provided in the ProducerRecord and an error
|
||||||
|
* occurs before partition is assigned, then the partition will be set to
|
||||||
|
* RecordMetadata.UNKNOWN_PARTITION.
|
||||||
|
* @param exception the exception thrown
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onError(ProducerRecord producerRecord, @Nullable RecordMetadata recordMetadata,
|
||||||
|
Exception exception){
|
||||||
|
System.out.println("消息发送失败: "+ producerRecord.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.muyu.event.config;
|
||||||
|
|
||||||
|
|
||||||
|
import lombok.NonNull;
|
||||||
|
import org.apache.kafka.clients.consumer.Consumer;
|
||||||
|
import org.springframework.kafka.listener.KafkaListenerErrorHandler;
|
||||||
|
import org.springframework.kafka.listener.ListenerExecutionFailedException;
|
||||||
|
import org.springframework.messaging.Message;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class MyKafkaListenerErrorHandler implements KafkaListenerErrorHandler {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NonNull
|
||||||
|
public Object handleError(@NonNull Message<?> message,
|
||||||
|
ListenerExecutionFailedException exception) {
|
||||||
|
return new Object();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NonNull
|
||||||
|
public Object handleError(@NonNull Message<?> message,
|
||||||
|
@NonNull ListenerExecutionFailedException exception,
|
||||||
|
Consumer<?, ?> consumer) {
|
||||||
|
System.out.println("消息详情:"+ message);
|
||||||
|
System.out.println("异常信息:"+ exception);
|
||||||
|
System.out.println("消费者详情:" +consumer.groupMetadata());
|
||||||
|
System.out.println("监听主题:"+ consumer.listTopics());
|
||||||
|
return KafkaListenerErrorHandler.super.handleError(message, exception, consumer);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.muyu.event.constant;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 事件常量
|
||||||
|
* @author 刘武
|
||||||
|
* @package:com.muyu.event.constant
|
||||||
|
* @name:EventConstant
|
||||||
|
* @date:2024/9/28 19:25
|
||||||
|
*/
|
||||||
|
|
||||||
|
public interface EventConstant {
|
||||||
|
|
||||||
|
String STORAGE_EVENT = "storageEvent";
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package com.muyu.event.consumer;
|
||||||
|
|
||||||
|
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
||||||
|
import org.springframework.kafka.annotation.KafkaListener;
|
||||||
|
import org.springframework.kafka.support.Acknowledgment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* kafka监听
|
||||||
|
* @author 刘武
|
||||||
|
* @package:com.muyu.event.consumer
|
||||||
|
* @name:KafkaConsumer
|
||||||
|
* @date:2024/9/28 23:34
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class KafkaConsumer {
|
||||||
|
|
||||||
|
|
||||||
|
@KafkaListener(topics = "data")
|
||||||
|
public void dataKafkaConsumer(ConsumerRecord<Object,Object> consumerRecord, Acknowledgment acknowledgment){
|
||||||
|
Object key = consumerRecord.key();
|
||||||
|
Object value = consumerRecord.value();
|
||||||
|
|
||||||
|
//事件调用
|
||||||
|
|
||||||
|
|
||||||
|
//消息确认消费
|
||||||
|
acknowledgment.acknowledge();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -1,57 +0,0 @@
|
||||||
package com.muyu.event.consumer;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
|
||||||
import com.muyu.event.basic.EventPublisher;
|
|
||||||
import lombok.extern.log4j.Log4j2;
|
|
||||||
import org.apache.kafka.clients.consumer.ConsumerRecords;
|
|
||||||
import org.apache.kafka.clients.consumer.KafkaConsumer;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.ApplicationArguments;
|
|
||||||
import org.springframework.boot.ApplicationRunner;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.time.Duration;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static org.bouncycastle.asn1.x500.style.RFC4519Style.l;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* kafka监听
|
|
||||||
* @author 刘武
|
|
||||||
* @package:com.muyu.event.consumer
|
|
||||||
* @name:KafkaConsumer
|
|
||||||
* @date:2024/9/28 23:34
|
|
||||||
*/
|
|
||||||
@Component
|
|
||||||
@Log4j2
|
|
||||||
public class MessageConsumer implements ApplicationRunner {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public KafkaConsumer consumer;
|
|
||||||
@Autowired
|
|
||||||
private EventPublisher eventPublisher;
|
|
||||||
|
|
||||||
private final String topic="four_car";
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run(ApplicationArguments args) throws Exception {
|
|
||||||
List<String> list = Collections.singletonList(topic);
|
|
||||||
consumer.subscribe(list);
|
|
||||||
|
|
||||||
while (true){
|
|
||||||
ConsumerRecords<String,String> consumerRecords = consumer.poll(Duration.ofMillis(100));
|
|
||||||
consumerRecords.forEach(record -> {
|
|
||||||
String value = record.value();
|
|
||||||
JSONObject jsonObject = JSONObject.parseObject(value);
|
|
||||||
log.info("value:{}",value);
|
|
||||||
// eventPublisher.publishEvent(jsonObject);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
package com.muyu.event.consumer;
|
|
||||||
|
|
||||||
import lombok.extern.log4j.Log4j2;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 车辆上线监听
|
|
||||||
* @author 刘武
|
|
||||||
* @package:com.muyu.event.consumer
|
|
||||||
* @name:OnlineConsumer
|
|
||||||
* @date:2024/9/30 11:40
|
|
||||||
*/
|
|
||||||
@Component
|
|
||||||
@Log4j2
|
|
||||||
public class OnlineConsumer {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
package com.muyu.event.controller;
|
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author 刘武
|
|
||||||
* @package:com.muyu.event.controller
|
|
||||||
* @name:DataController
|
|
||||||
* @date:2024/9/29 20:16
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("data")
|
|
||||||
public class DataController {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,63 +0,0 @@
|
||||||
package com.muyu.event.controller;
|
|
||||||
|
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
|
||||||
import com.muyu.event.service.TestService;
|
|
||||||
import org.apache.kafka.clients.producer.KafkaProducer;
|
|
||||||
import org.apache.kafka.clients.producer.ProducerRecord;
|
|
||||||
import org.springframework.amqp.core.AmqpTemplate;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author 刘武
|
|
||||||
* @package:com.muyu.event.controller
|
|
||||||
* @name:TestController
|
|
||||||
* @date:2024/9/29 20:58
|
|
||||||
*/
|
|
||||||
@RestController("test")
|
|
||||||
public class TestController {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private KafkaProducer kafkaProducer;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private static final String topic="four_car";
|
|
||||||
|
|
||||||
@GetMapping("send")
|
|
||||||
public String sendKafka(){
|
|
||||||
|
|
||||||
String message="发送一条信息";
|
|
||||||
JSONObject jsonObject = new JSONObject();
|
|
||||||
jsonObject.put("cj","sb");
|
|
||||||
|
|
||||||
|
|
||||||
ProducerRecord<String, String> producerRecord = new ProducerRecord<String, String>(topic,jsonObject.toJSONString());
|
|
||||||
kafkaProducer.send(producerRecord);
|
|
||||||
|
|
||||||
return "success";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.muyu.event.domian;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 事件驱动对象
|
||||||
|
* @Author 刘武
|
||||||
|
* @Data 2024/9/29
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@SuperBuilder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class EventActuate {
|
||||||
|
/**
|
||||||
|
* json数据
|
||||||
|
*/
|
||||||
|
private String jsonData;
|
||||||
|
/**
|
||||||
|
* 事件驱动key集合
|
||||||
|
*/
|
||||||
|
private List<String> eventKeys;
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.muyu.event.eventDispose;
|
||||||
|
|
||||||
|
|
||||||
|
import com.muyu.event.basics.StartEvent;
|
||||||
|
import com.muyu.event.domian.EventActuate;
|
||||||
|
import org.springframework.context.ApplicationListener;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 刘武
|
||||||
|
* @package:
|
||||||
|
* @name:AutoStartupEventListener
|
||||||
|
* @date:2024/9/29
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class AutoStartupEventListener implements ApplicationListener<StartEvent> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onApplicationEvent(StartEvent event) {
|
||||||
|
|
||||||
|
EventActuate eventActuate = event.getEventActuate();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
package com.muyu.event.eventDispose;
|
||||||
|
|
||||||
|
|
||||||
|
import com.muyu.event.basics.EventProcessBasics;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 刘武
|
||||||
|
* @package:
|
||||||
|
* @name:StorageEvent
|
||||||
|
* @date:2024/9/29
|
||||||
|
*/
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Log4j2
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class StorageEvent extends EventProcessBasics {
|
||||||
|
/**
|
||||||
|
* 事件名称
|
||||||
|
*/
|
||||||
|
private String eventName;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleEvent(String eventKey) {
|
||||||
|
if (eventKey.equals(eventName)){
|
||||||
|
log.info("开始执行 [{}] 事件", eventKey);
|
||||||
|
|
||||||
|
}else if (nextEvent != null){
|
||||||
|
nextEvent.handleEvent(eventKey);
|
||||||
|
}else {
|
||||||
|
log.info("处理结束,最后处理的事件为 [{}]", eventKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,37 +0,0 @@
|
||||||
package com.muyu.event.listener;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
|
||||||
import com.muyu.event.basic.EventCustom;
|
|
||||||
import com.muyu.event.basic.EventListener;
|
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 添加数据库事件
|
|
||||||
* @program: cloud-server
|
|
||||||
* @author: cuiyongxing
|
|
||||||
* @create: 2024-09-29 17:34
|
|
||||||
**/
|
|
||||||
public class AddDatabaseListener implements EventListener {
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onEvent(EventCustom event) {
|
|
||||||
|
|
||||||
JSONObject jsonObject = event.getData();
|
|
||||||
List<String> keys = new ArrayList<>();
|
|
||||||
List<String> values = new ArrayList<>();
|
|
||||||
|
|
||||||
jsonObject.forEach((key, value) -> {
|
|
||||||
keys.add(key);
|
|
||||||
values.add((String) value);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onApplicationEvent(EventCustom event) {
|
|
||||||
onEvent(event);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
package com.muyu.event.service;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author 刘武
|
|
||||||
* @package:com.muyu.event.service.impl
|
|
||||||
* @name:DataService
|
|
||||||
* @date:2024/9/29 20:23
|
|
||||||
*/
|
|
||||||
public interface DataService {
|
|
||||||
|
|
||||||
void warnData(String data);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,10 +0,0 @@
|
||||||
package com.muyu.event.service;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author 刘武
|
|
||||||
* @package:com.muyu.event.service
|
|
||||||
* @name:TestService
|
|
||||||
* @date:2024/9/29 20:59
|
|
||||||
*/
|
|
||||||
public interface TestService {
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
package com.muyu.event.service.impl;
|
|
||||||
|
|
||||||
import com.muyu.event.service.DataService;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author 刘武
|
|
||||||
* @package:com.muyu.event.service.impl
|
|
||||||
* @name:DataServiceImpl
|
|
||||||
* @date:2024/9/29 20:24
|
|
||||||
*/
|
|
||||||
@Service
|
|
||||||
public class DataServiceImpl implements DataService {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void warnData(String data) {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,20 +0,0 @@
|
||||||
package com.muyu.event.service.impl;
|
|
||||||
|
|
||||||
import com.muyu.event.service.TestService;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author 刘武
|
|
||||||
* @package:com.muyu.event.service.impl
|
|
||||||
* @name:TestServiceImpl
|
|
||||||
* @date:2024/9/29 21:00
|
|
||||||
*/
|
|
||||||
@Service
|
|
||||||
public class TestServiceImpl implements TestService {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,37 +0,0 @@
|
||||||
package com.muyu.event.util;
|
|
||||||
|
|
||||||
import com.github.benmanes.caffeine.cache.Cache;
|
|
||||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 缓存工具类
|
|
||||||
*
|
|
||||||
* @program: cloud-server
|
|
||||||
* @author: 刘武
|
|
||||||
* @create: 2024-09-30 10:08
|
|
||||||
**/
|
|
||||||
@Component
|
|
||||||
public class CacheUtil<T> {
|
|
||||||
|
|
||||||
private final Cache<String, T> cache;
|
|
||||||
|
|
||||||
public CacheUtil() {
|
|
||||||
this.cache = Caffeine.newBuilder()
|
|
||||||
.maximumSize(500L)
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
public T get(String key) {
|
|
||||||
return cache.getIfPresent(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void put(String key, T value) {
|
|
||||||
cache.put(key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void remove(String key) {
|
|
||||||
cache.invalidate(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,16 +1,14 @@
|
||||||
# Tomcat
|
# Tomcat
|
||||||
server:
|
server:
|
||||||
port: 10009
|
port: 10009
|
||||||
|
|
||||||
# nacos线上地址
|
# nacos线上地址
|
||||||
nacos:
|
nacos:
|
||||||
addr: 47.101.53.251:8848
|
addr: 47.101.53.251:8848
|
||||||
user-name: nacos
|
user-name: nacos
|
||||||
password: nacos
|
password: nacos
|
||||||
namespace: yzl
|
namespace: lgy
|
||||||
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
|
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
|
||||||
# Spring
|
# Spring
|
||||||
spring:
|
|
||||||
amqp:
|
amqp:
|
||||||
deserialization:
|
deserialization:
|
||||||
trust:
|
trust:
|
||||||
|
@ -53,8 +51,9 @@ spring:
|
||||||
- application-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
- application-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||||
# xxl-job 配置文件
|
# xxl-job 配置文件
|
||||||
- application-xxl-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
- application-xxl-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||||
|
# rabbit 配置文件
|
||||||
|
- application-rabbit-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||||
logging:
|
logging:
|
||||||
level:
|
level:
|
||||||
com.muyu.system.mapper: DEBUG
|
com.muyu.fence.mapper: DEBUG
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ nacos:
|
||||||
addr: 47.101.53.251:8848
|
addr: 47.101.53.251:8848
|
||||||
user-name: nacos
|
user-name: nacos
|
||||||
password: nacos
|
password: nacos
|
||||||
namespace: yzl
|
namespace: lgy
|
||||||
|
|
||||||
# Spring
|
# Spring
|
||||||
spring:
|
spring:
|
||||||
|
|
|
@ -9,7 +9,7 @@ import org.springframework.stereotype.Service;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 业务字段 业务逻辑层实现
|
* 业务字段 服务层实现
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -40,7 +40,7 @@ import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 业务 业务逻辑层实现
|
* 业务 服务层实现
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -7,7 +7,7 @@ nacos:
|
||||||
addr: 47.101.53.251:8848
|
addr: 47.101.53.251:8848
|
||||||
user-name: nacos
|
user-name: nacos
|
||||||
password: nacos
|
password: nacos
|
||||||
namespace: yzl
|
namespace: lgy
|
||||||
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
|
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
|
||||||
# Spring
|
# Spring
|
||||||
spring:
|
spring:
|
||||||
|
|
|
@ -10,7 +10,10 @@ import com.muyu.common.log.enums.BusinessType;
|
||||||
import com.muyu.common.security.annotation.InnerAuth;
|
import com.muyu.common.security.annotation.InnerAuth;
|
||||||
import com.muyu.common.security.annotation.RequiresPermissions;
|
import com.muyu.common.security.annotation.RequiresPermissions;
|
||||||
import com.muyu.common.security.utils.SecurityUtils;
|
import com.muyu.common.security.utils.SecurityUtils;
|
||||||
import com.muyu.common.system.domain.*;
|
import com.muyu.common.system.domain.SysDept;
|
||||||
|
import com.muyu.common.system.domain.SysRole;
|
||||||
|
import com.muyu.common.system.domain.SysUser;
|
||||||
|
import com.muyu.common.system.domain.LoginUser;
|
||||||
import com.muyu.system.domain.resp.AuthRoleResp;
|
import com.muyu.system.domain.resp.AuthRoleResp;
|
||||||
import com.muyu.system.domain.resp.UserDetailInfoResp;
|
import com.muyu.system.domain.resp.UserDetailInfoResp;
|
||||||
import com.muyu.system.domain.resp.UserInfoResp;
|
import com.muyu.system.domain.resp.UserInfoResp;
|
||||||
|
@ -133,15 +136,6 @@ public class SysUserController extends BaseController {
|
||||||
return Result.success(userService.registerUser(sysUser));
|
return Result.success(userService.registerUser(sysUser));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 入驻企业信息
|
|
||||||
*/
|
|
||||||
@InnerAuth
|
|
||||||
@PostMapping("/enterprise")
|
|
||||||
public Result<Boolean> enterprise (@RequestBody Enterprise enterprise){
|
|
||||||
|
|
||||||
return Result.success(userService.enterprise(enterprise));
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* 获取用户信息
|
* 获取用户信息
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package com.muyu.system.mapper;
|
package com.muyu.system.mapper;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.muyu.common.system.domain.Enterprise;
|
|
||||||
import com.muyu.common.system.domain.SysUser;
|
import com.muyu.common.system.domain.SysUser;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
@ -67,8 +66,6 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
|
||||||
*/
|
*/
|
||||||
int insertUser(SysUser user);
|
int insertUser(SysUser user);
|
||||||
|
|
||||||
int enterprise(Enterprise enterprise);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改用户信息
|
* 修改用户信息
|
||||||
*
|
*
|
||||||
|
@ -145,6 +142,4 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
|
||||||
|
|
||||||
List<SysUser> selectCompanyList();
|
List<SysUser> selectCompanyList();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import com.muyu.system.domain.vo.TreeSelect;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 部门管理 业务逻辑层
|
* 部门管理 服务层
|
||||||
*
|
*
|
||||||
* @author muyu
|
* @author muyu
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package com.muyu.system.service;
|
package com.muyu.system.service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.muyu.common.system.domain.Enterprise;
|
|
||||||
import com.muyu.common.system.domain.SysUser;
|
import com.muyu.common.system.domain.SysUser;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -134,7 +133,6 @@ public interface SysUserService extends IService<SysUser> {
|
||||||
*/
|
*/
|
||||||
boolean registerUser(SysUser user);
|
boolean registerUser(SysUser user);
|
||||||
|
|
||||||
boolean enterprise(Enterprise enterprise);
|
|
||||||
/**
|
/**
|
||||||
* 修改用户信息
|
* 修改用户信息
|
||||||
*
|
*
|
||||||
|
@ -230,5 +228,4 @@ public interface SysUserService extends IService<SysUser> {
|
||||||
|
|
||||||
List<SysUser> selectCompanyList();
|
List<SysUser> selectCompanyList();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ import com.muyu.common.core.utils.StringUtils;
|
||||||
import com.muyu.common.core.utils.bean.BeanValidators;
|
import com.muyu.common.core.utils.bean.BeanValidators;
|
||||||
import com.muyu.common.datascope.annotation.DataScope;
|
import com.muyu.common.datascope.annotation.DataScope;
|
||||||
import com.muyu.common.security.utils.SecurityUtils;
|
import com.muyu.common.security.utils.SecurityUtils;
|
||||||
import com.muyu.common.system.domain.Enterprise;
|
|
||||||
import com.muyu.common.system.domain.SysRole;
|
import com.muyu.common.system.domain.SysRole;
|
||||||
import com.muyu.common.system.domain.SysUser;
|
import com.muyu.common.system.domain.SysUser;
|
||||||
import com.muyu.system.domain.SysPost;
|
import com.muyu.system.domain.SysPost;
|
||||||
|
@ -258,11 +257,6 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||||
return userMapper.insertUser(user) > 0;
|
return userMapper.insertUser(user) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean enterprise(Enterprise enterprise){
|
|
||||||
return userMapper.enterprise(enterprise) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改保存用户信息
|
* 修改保存用户信息
|
||||||
*
|
*
|
||||||
|
|
|
@ -7,7 +7,7 @@ nacos:
|
||||||
addr: 47.101.53.251:8848
|
addr: 47.101.53.251:8848
|
||||||
user-name: nacos
|
user-name: nacos
|
||||||
password: nacos
|
password: nacos
|
||||||
namespace: yzl
|
namespace: lgy
|
||||||
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
|
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
|
||||||
# Spring
|
# Spring
|
||||||
spring:
|
spring:
|
||||||
|
|
|
@ -221,9 +221,6 @@
|
||||||
sysdate()
|
sysdate()
|
||||||
)
|
)
|
||||||
</insert>
|
</insert>
|
||||||
<insert id="enterprise">
|
|
||||||
INSERT INTO `datasource`.`datasource` (`id`, `firm_name`, `database_name`) VALUES (NULL, #{firmName}, #{databaseName});
|
|
||||||
</insert>
|
|
||||||
|
|
||||||
<update id="updateUser" parameterType="com.muyu.common.system.domain.SysUser">
|
<update id="updateUser" parameterType="com.muyu.common.system.domain.SysUser">
|
||||||
update sys_user
|
update sys_user
|
||||||
|
|
|
@ -1,99 +0,0 @@
|
||||||
<?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-modules</artifactId>
|
|
||||||
<version>3.6.3</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>cloud-modules-template</artifactId>
|
|
||||||
|
|
||||||
<description>
|
|
||||||
cloud-modules-template 协议解析模块
|
|
||||||
</description>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.muyu</groupId>
|
|
||||||
<artifactId>cloud-common-kafka</artifactId>
|
|
||||||
<version>3.6.3</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.muyu.server</groupId>
|
|
||||||
<artifactId>saas-server</artifactId>
|
|
||||||
<version>3.6.3</version>
|
|
||||||
</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>
|
|
||||||
|
|
||||||
<!-- SpringBoot Actuator -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Mysql Connector -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.mysql</groupId>
|
|
||||||
<artifactId>mysql-connector-j</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- MuYu Common DataSource -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.muyu</groupId>
|
|
||||||
<artifactId>cloud-common-datasource</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- MuYu Common DataScope -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.muyu</groupId>
|
|
||||||
<artifactId>cloud-common-datascope</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- MuYu Common Log -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.muyu</groupId>
|
|
||||||
<artifactId>cloud-common-log</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- 接口模块 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.muyu</groupId>
|
|
||||||
<artifactId>cloud-common-api-doc</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- XllJob定时任务 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.muyu</groupId>
|
|
||||||
<artifactId>cloud-common-xxl</artifactId>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<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>
|
|
|
@ -1,23 +0,0 @@
|
||||||
package com.muyu.template;
|
|
||||||
import com.muyu.common.security.annotation.EnableCustomConfig;
|
|
||||||
import com.muyu.common.security.annotation.EnableMyFeignClients;
|
|
||||||
import org.springframework.boot.SpringApplication;
|
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
||||||
/**
|
|
||||||
* @author liuxinyue
|
|
||||||
* @Package:com.muyu.template
|
|
||||||
* @name:CloudTemplateApplication
|
|
||||||
* @Date:2024/9/30 10:36
|
|
||||||
*/
|
|
||||||
@EnableCustomConfig
|
|
||||||
@EnableMyFeignClients
|
|
||||||
@SpringBootApplication
|
|
||||||
public class CloudTemplateApplication {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
|
|
||||||
SpringApplication.run(CloudTemplateApplication.class, args);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,150 +0,0 @@
|
||||||
package com.muyu.template.config;
|
|
||||||
import cn.hutool.json.JSONObject;
|
|
||||||
import com.alibaba.fastjson2.JSON;
|
|
||||||
import com.muyu.common.domain.MessageTemplateType;
|
|
||||||
import com.muyu.common.domain.SysCar;
|
|
||||||
import com.muyu.common.redis.service.RedisService;
|
|
||||||
import com.muyu.server.service.MessageTemplateTypeService;
|
|
||||||
import com.muyu.server.service.SysCarService;
|
|
||||||
import com.muyu.server.service.impl.SysCarServiceImpl;
|
|
||||||
import lombok.extern.log4j.Log4j2;
|
|
||||||
import org.eclipse.paho.client.mqttv3.*;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import javax.annotation.PostConstruct;
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.util.List;
|
|
||||||
/**
|
|
||||||
* @author liuxinyue
|
|
||||||
* @Package:com.muyu.mqtt.configure
|
|
||||||
* @Project:cloud-server
|
|
||||||
* @name:MqttConfigure
|
|
||||||
* @Date:2024/9/28 16:10
|
|
||||||
*/
|
|
||||||
@Log4j2
|
|
||||||
@Component
|
|
||||||
public class MqttConfigure {
|
|
||||||
@Autowired
|
|
||||||
private RedisService redisService;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private SysCarService sysCarService;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private SysCarServiceImpl service;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private MessageTemplateTypeService messageTemplateTypeService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private RedisTemplate redisTemplate;
|
|
||||||
|
|
||||||
@PostConstruct
|
|
||||||
public void MQTTMonitoring(){
|
|
||||||
|
|
||||||
String topic = "vehicle";
|
|
||||||
int qos = 2;
|
|
||||||
String broker = "tcp://47.101.53.251:1883";
|
|
||||||
String clientId = "测试mqtt";
|
|
||||||
try {
|
|
||||||
MqttClient sampleClient = new MqttClient(broker, clientId);
|
|
||||||
MqttConnectOptions connOpts = new MqttConnectOptions();
|
|
||||||
//是否清空session
|
|
||||||
connOpts.setCleanSession(true);
|
|
||||||
log.info("Connecting to broker: " + broker);
|
|
||||||
//连接
|
|
||||||
sampleClient.connect(connOpts);
|
|
||||||
sampleClient.subscribe(topic,qos);
|
|
||||||
sampleClient.setCallback(new MqttCallback() {
|
|
||||||
//连接丢失(报错)
|
|
||||||
@Override
|
|
||||||
public void connectionLost(Throwable throwable) {
|
|
||||||
log.error("error:"+throwable.getMessage());
|
|
||||||
}
|
|
||||||
//消息已经接收到
|
|
||||||
@Override
|
|
||||||
public void messageArrived(String s, MqttMessage mqttMessage) throws Exception {
|
|
||||||
// 将MQTT消息转换为字符串
|
|
||||||
String messageContent = new String(mqttMessage.getPayload());
|
|
||||||
// 解析JSON字符串
|
|
||||||
JSONObject jsonObject = new JSONObject(messageContent);
|
|
||||||
// 从JSON对象中获取"msg"字段的值
|
|
||||||
String msgValue = jsonObject.getStr("msg");
|
|
||||||
messageParsing(msgValue);
|
|
||||||
log.info("接收到的值为:"+msgValue);
|
|
||||||
}
|
|
||||||
//交付完成
|
|
||||||
@Override
|
|
||||||
public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch(MqttException me) {
|
|
||||||
System.out.println("reason "+me.getReasonCode());
|
|
||||||
System.out.println("msg "+me.getMessage());
|
|
||||||
System.out.println("loc "+me.getLocalizedMessage());
|
|
||||||
System.out.println("cause "+me.getCause());
|
|
||||||
System.out.println("excep "+me);
|
|
||||||
me.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public JSONObject messageParsing(String templateMessage) {
|
|
||||||
//给一个JSON对象
|
|
||||||
JSONObject jsonObject = new JSONObject();
|
|
||||||
//先截取出VIN码 然后根据VIN码查询这个车属于什么类型
|
|
||||||
if (templateMessage.length() < 18) {
|
|
||||||
throw new RuntimeException("The vehicle message is incorrect");
|
|
||||||
}
|
|
||||||
//将报文进行切割
|
|
||||||
String[] hexArray = templateMessage.split(" ");
|
|
||||||
StringBuilder result = new StringBuilder();
|
|
||||||
for (String hex : hexArray) {
|
|
||||||
int decimal = Integer.parseInt(hex, 16);
|
|
||||||
result.append((char) decimal);
|
|
||||||
}
|
|
||||||
//取出VIN码
|
|
||||||
String carVin = result.substring(0, 18 - 1);
|
|
||||||
log.info("carVin码为:" + carVin);
|
|
||||||
//根据VIN码获取车辆信息
|
|
||||||
SysCar carByVin = service.findCarByVin(carVin);
|
|
||||||
log.info("车辆信息为:" + carByVin);
|
|
||||||
//对应车辆所对应的报文模版
|
|
||||||
Integer templateId = carByVin.getTemplateId();
|
|
||||||
List<MessageTemplateType> templateTypeList;
|
|
||||||
//key
|
|
||||||
String redisKey = "messageTemplateType" + templateId;
|
|
||||||
//key存在
|
|
||||||
if (redisTemplate.hasKey(redisKey)) {
|
|
||||||
|
|
||||||
List list = redisTemplate.opsForList().range(redisKey, 0, -1);
|
|
||||||
|
|
||||||
templateTypeList = list.stream().map(o -> JSON.parseObject(o.toString(), MessageTemplateType.class))
|
|
||||||
.toList();
|
|
||||||
} else {
|
|
||||||
List<MessageTemplateType> templateTypeList1 = messageTemplateTypeService.findTemplateById(templateId);
|
|
||||||
templateTypeList = templateTypeList1;
|
|
||||||
templateTypeList.forEach(
|
|
||||||
templateType ->
|
|
||||||
redisTemplate.opsForList().rightPush(
|
|
||||||
redisKey, com.alibaba.fastjson.JSON.toJSONString(templateType)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
//将模版里面有的配置进行循环
|
|
||||||
for (MessageTemplateType messageTemplateType : templateTypeList) {
|
|
||||||
//开始位置
|
|
||||||
Integer startIndex = messageTemplateType.getStartIndex() - 1;
|
|
||||||
//结束位置
|
|
||||||
Integer endIndex = messageTemplateType.getEndIndex();
|
|
||||||
//将每个解析后的字段都存入到JSON对象中
|
|
||||||
jsonObject.put(messageTemplateType.getMessageField(), result.substring(startIndex, endIndex));
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println("哈哈哈红红火火恍恍惚惚");
|
|
||||||
log.info("解析后的报文是:" + jsonObject);
|
|
||||||
|
|
||||||
return jsonObject;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,2 +0,0 @@
|
||||||
Spring Boot Version: ${spring-boot.version}
|
|
||||||
Spring Application Name: ${spring.application.name}
|
|
|
@ -1,74 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
|
||||||
<!-- 日志存放路径 -->
|
|
||||||
<property name="log.path" value="logs/cloud-saas"/>
|
|
||||||
<!-- 日志输出格式 -->
|
|
||||||
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
|
||||||
|
|
||||||
<!-- 控制台输出 -->
|
|
||||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
|
||||||
<encoder>
|
|
||||||
<pattern>${log.pattern}</pattern>
|
|
||||||
</encoder>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<!-- 系统日志输出 -->
|
|
||||||
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
|
||||||
<file>${log.path}/info.log</file>
|
|
||||||
<!-- 循环政策:基于时间创建日志文件 -->
|
|
||||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
|
||||||
<!-- 日志文件名格式 -->
|
|
||||||
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
|
|
||||||
<!-- 日志最大的历史 60天 -->
|
|
||||||
<maxHistory>60</maxHistory>
|
|
||||||
</rollingPolicy>
|
|
||||||
<encoder>
|
|
||||||
<pattern>${log.pattern}</pattern>
|
|
||||||
</encoder>
|
|
||||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
|
||||||
<!-- 过滤的级别 -->
|
|
||||||
<level>INFO</level>
|
|
||||||
<!-- 匹配时的操作:接收(记录) -->
|
|
||||||
<onMatch>ACCEPT</onMatch>
|
|
||||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
|
||||||
<onMismatch>DENY</onMismatch>
|
|
||||||
</filter>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
|
||||||
<file>${log.path}/error.log</file>
|
|
||||||
<!-- 循环政策:基于时间创建日志文件 -->
|
|
||||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
|
||||||
<!-- 日志文件名格式 -->
|
|
||||||
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
|
|
||||||
<!-- 日志最大的历史 60天 -->
|
|
||||||
<maxHistory>60</maxHistory>
|
|
||||||
</rollingPolicy>
|
|
||||||
<encoder>
|
|
||||||
<pattern>${log.pattern}</pattern>
|
|
||||||
</encoder>
|
|
||||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
|
||||||
<!-- 过滤的级别 -->
|
|
||||||
<level>ERROR</level>
|
|
||||||
<!-- 匹配时的操作:接收(记录) -->
|
|
||||||
<onMatch>ACCEPT</onMatch>
|
|
||||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
|
||||||
<onMismatch>DENY</onMismatch>
|
|
||||||
</filter>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<!-- 系统模块日志级别控制 -->
|
|
||||||
<logger name="com.muyu" level="info"/>
|
|
||||||
<!-- Spring日志级别控制 -->
|
|
||||||
<logger name="org.springframework" level="warn"/>
|
|
||||||
|
|
||||||
<root level="info">
|
|
||||||
<appender-ref ref="console"/>
|
|
||||||
</root>
|
|
||||||
|
|
||||||
<!--系统操作日志-->
|
|
||||||
<root level="info">
|
|
||||||
<appender-ref ref="file_info"/>
|
|
||||||
<appender-ref ref="file_error"/>
|
|
||||||
</root>
|
|
||||||
</configuration>
|
|
|
@ -1,81 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
|
||||||
<!-- 日志存放路径 -->
|
|
||||||
<property name="log.path" value="logs/cloud-saas"/>
|
|
||||||
<!-- 日志输出格式 -->
|
|
||||||
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
|
||||||
<property name="log.sky.pattern" value="%d{HH:mm:ss.SSS} %yellow([%tid]) [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
|
||||||
|
|
||||||
<!-- 控制台输出 -->
|
|
||||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
|
||||||
<encoder>
|
|
||||||
<pattern>${log.sky.pattern}</pattern>
|
|
||||||
</encoder>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<!-- 系统日志输出 -->
|
|
||||||
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
|
||||||
<file>${log.path}/info.log</file>
|
|
||||||
<!-- 循环政策:基于时间创建日志文件 -->
|
|
||||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
|
||||||
<!-- 日志文件名格式 -->
|
|
||||||
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
|
|
||||||
<!-- 日志最大的历史 60天 -->
|
|
||||||
<maxHistory>60</maxHistory>
|
|
||||||
</rollingPolicy>
|
|
||||||
|
|
||||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
|
||||||
<!-- 过滤的级别 -->
|
|
||||||
<level>INFO</level>
|
|
||||||
<!-- 匹配时的操作:接收(记录) -->
|
|
||||||
<onMatch>ACCEPT</onMatch>
|
|
||||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
|
||||||
<onMismatch>DENY</onMismatch>
|
|
||||||
</filter>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
|
||||||
<file>${log.path}/error.log</file>
|
|
||||||
<!-- 循环政策:基于时间创建日志文件 -->
|
|
||||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
|
||||||
<!-- 日志文件名格式 -->
|
|
||||||
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
|
|
||||||
<!-- 日志最大的历史 60天 -->
|
|
||||||
<maxHistory>60</maxHistory>
|
|
||||||
</rollingPolicy>
|
|
||||||
|
|
||||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
|
||||||
<!-- 过滤的级别 -->
|
|
||||||
<level>ERROR</level>
|
|
||||||
<!-- 匹配时的操作:接收(记录) -->
|
|
||||||
<onMatch>ACCEPT</onMatch>
|
|
||||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
|
||||||
<onMismatch>DENY</onMismatch>
|
|
||||||
</filter>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<!-- 使用gRpc将日志发送到skywalking服务端 -->
|
|
||||||
<appender name="GRPC_LOG" class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.log.GRPCLogClientAppender">
|
|
||||||
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
|
|
||||||
<layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
|
|
||||||
<Pattern>${log.sky.pattern}</Pattern>
|
|
||||||
</layout>
|
|
||||||
</encoder>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<!-- 系统模块日志级别控制 -->
|
|
||||||
<logger name="com.muyu" level="info"/>
|
|
||||||
<!-- Spring日志级别控制 -->
|
|
||||||
<logger name="org.springframework" level="warn"/>
|
|
||||||
|
|
||||||
<root level="info">
|
|
||||||
<appender-ref ref="GRPC_LOG"/>
|
|
||||||
<appender-ref ref="console"/>
|
|
||||||
</root>
|
|
||||||
|
|
||||||
<!--系统操作日志-->
|
|
||||||
<root level="info">
|
|
||||||
<appender-ref ref="file_info"/>
|
|
||||||
<appender-ref ref="file_error"/>
|
|
||||||
</root>
|
|
||||||
</configuration>
|
|
|
@ -1,81 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
|
||||||
<!-- 日志存放路径 -->
|
|
||||||
<property name="log.path" value="logs/cloud-saas"/>
|
|
||||||
<!-- 日志输出格式 -->
|
|
||||||
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
|
||||||
<property name="log.sky.pattern" value="%d{HH:mm:ss.SSS} %yellow([%tid]) [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
|
||||||
|
|
||||||
<!-- 控制台输出 -->
|
|
||||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
|
||||||
<encoder>
|
|
||||||
<pattern>${log.sky.pattern}</pattern>
|
|
||||||
</encoder>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<!-- 系统日志输出 -->
|
|
||||||
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
|
||||||
<file>${log.path}/info.log</file>
|
|
||||||
<!-- 循环政策:基于时间创建日志文件 -->
|
|
||||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
|
||||||
<!-- 日志文件名格式 -->
|
|
||||||
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
|
|
||||||
<!-- 日志最大的历史 60天 -->
|
|
||||||
<maxHistory>60</maxHistory>
|
|
||||||
</rollingPolicy>
|
|
||||||
|
|
||||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
|
||||||
<!-- 过滤的级别 -->
|
|
||||||
<level>INFO</level>
|
|
||||||
<!-- 匹配时的操作:接收(记录) -->
|
|
||||||
<onMatch>ACCEPT</onMatch>
|
|
||||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
|
||||||
<onMismatch>DENY</onMismatch>
|
|
||||||
</filter>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
|
||||||
<file>${log.path}/error.log</file>
|
|
||||||
<!-- 循环政策:基于时间创建日志文件 -->
|
|
||||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
|
||||||
<!-- 日志文件名格式 -->
|
|
||||||
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
|
|
||||||
<!-- 日志最大的历史 60天 -->
|
|
||||||
<maxHistory>60</maxHistory>
|
|
||||||
</rollingPolicy>
|
|
||||||
|
|
||||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
|
||||||
<!-- 过滤的级别 -->
|
|
||||||
<level>ERROR</level>
|
|
||||||
<!-- 匹配时的操作:接收(记录) -->
|
|
||||||
<onMatch>ACCEPT</onMatch>
|
|
||||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
|
||||||
<onMismatch>DENY</onMismatch>
|
|
||||||
</filter>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<!-- 使用gRpc将日志发送到skywalking服务端 -->
|
|
||||||
<appender name="GRPC_LOG" class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.log.GRPCLogClientAppender">
|
|
||||||
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
|
|
||||||
<layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
|
|
||||||
<Pattern>${log.sky.pattern}</Pattern>
|
|
||||||
</layout>
|
|
||||||
</encoder>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<!-- 系统模块日志级别控制 -->
|
|
||||||
<logger name="com.muyu" level="info"/>
|
|
||||||
<!-- Spring日志级别控制 -->
|
|
||||||
<logger name="org.springframework" level="warn"/>
|
|
||||||
|
|
||||||
<root level="info">
|
|
||||||
<appender-ref ref="GRPC_LOG"/>
|
|
||||||
<appender-ref ref="console"/>
|
|
||||||
</root>
|
|
||||||
|
|
||||||
<!--系统操作日志-->
|
|
||||||
<root level="info">
|
|
||||||
<appender-ref ref="file_info"/>
|
|
||||||
<appender-ref ref="file_error"/>
|
|
||||||
</root>
|
|
||||||
</configuration>
|
|
|
@ -7,7 +7,7 @@ nacos:
|
||||||
addr: 47.101.53.251:8848
|
addr: 47.101.53.251:8848
|
||||||
user-name: nacos
|
user-name: nacos
|
||||||
password: nacos
|
password: nacos
|
||||||
namespace: yzl
|
namespace: four
|
||||||
|
|
||||||
# Spring
|
# Spring
|
||||||
spring:
|
spring:
|
||||||
|
|
|
@ -24,10 +24,8 @@
|
||||||
<module>saas</module>
|
<module>saas</module>
|
||||||
<module>cloud-modules-vehiclegateway</module>
|
<module>cloud-modules-vehiclegateway</module>
|
||||||
<module>cloud-event</module>
|
<module>cloud-event</module>
|
||||||
<module>cloud-modules-template</module>
|
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
|
|
||||||
<artifactId>cloud-modules</artifactId>
|
<artifactId>cloud-modules</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
|
|
|
@ -7,11 +7,12 @@ import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 车辆类型
|
* 车辆类型对象
|
||||||
* @author sx
|
* @Author:liuxinyue
|
||||||
* @package com.muyu.common.domain
|
* @Package:com.sheep.message.domain
|
||||||
* @name CarType
|
* @Project:cloud-server-c
|
||||||
* @date 2024/9/22 14:36
|
* @name:MessageTemplateType
|
||||||
|
* @Date:2024/9/18 21:01
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
|
|
@ -10,8 +10,8 @@ import lombok.NoArgsConstructor;
|
||||||
import lombok.experimental.SuperBuilder;
|
import lombok.experimental.SuperBuilder;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
/**
|
/**
|
||||||
* 数据类型表
|
* 数据类型对象
|
||||||
* @author liuxinyue
|
* @Author:liuxinyue
|
||||||
* @Package:com.sheep.message.domain
|
* @Package:com.sheep.message.domain
|
||||||
* @Project:cloud-server-c
|
* @Project:cloud-server-c
|
||||||
* @name:DataType
|
* @name:DataType
|
||||||
|
@ -29,10 +29,10 @@ public class DataType implements Serializable{
|
||||||
* 数据类型ID
|
* 数据类型ID
|
||||||
*/
|
*/
|
||||||
@TableId(value = "data_type_id",type = IdType.AUTO)
|
@TableId(value = "data_type_id",type = IdType.AUTO)
|
||||||
private Integer DataTypeId;
|
private Integer dataTypeId;
|
||||||
/**
|
/**
|
||||||
* 数据类型名称
|
* 数据类型名称
|
||||||
*/
|
*/
|
||||||
private String DataTypeName;
|
private String dataTypeName;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
package com.muyu.common.domain;
|
package com.muyu.common.domain;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 企业运营实体类
|
* @Author YuPing
|
||||||
* @author yuping
|
|
||||||
* @Description 企业运营实体类
|
* @Description 企业运营实体类
|
||||||
* @Version 1.0
|
* @Version 1.0
|
||||||
* @Data 2024-09-26 20:22:04
|
* @Data 2024-09-26 20:22:04
|
||||||
|
@ -15,7 +13,6 @@ import lombok.NoArgsConstructor;
|
||||||
@Data
|
@Data
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@TableName("enterprise")
|
|
||||||
public class Enterprise {
|
public class Enterprise {
|
||||||
/**
|
/**
|
||||||
* 企业编号
|
* 企业编号
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.muyu.common.domain;
|
package com.muyu.common.domain;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
@ -10,8 +9,8 @@ import lombok.experimental.SuperBuilder;
|
||||||
import java.sql.Date;
|
import java.sql.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 报文模版
|
* 新能源车模版
|
||||||
* @author liuxinyue
|
* @Author:liuxinyue
|
||||||
* @Package:com.template.domain
|
* @Package:com.template.domain
|
||||||
* @Project:cloud-server
|
* @Project:cloud-server
|
||||||
* @name:MessageTemplate
|
* @name:MessageTemplate
|
||||||
|
@ -22,7 +21,6 @@ import java.sql.Date;
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@SuperBuilder
|
@SuperBuilder
|
||||||
@Tag(name = "报文")
|
@Tag(name = "报文")
|
||||||
@TableName("message_template")
|
|
||||||
public class MessageTemplate {
|
public class MessageTemplate {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.muyu.common.domain;
|
package com.muyu.common.domain;
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
@ -7,10 +8,9 @@ import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.experimental.SuperBuilder;
|
import lombok.experimental.SuperBuilder;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* 模版对应的配置
|
||||||
* @Author:liuxinyue
|
* @Author:liuxinyue
|
||||||
* @Package:com.sheep.message.domain
|
* @Package:com.sheep.message.domain
|
||||||
* @Project:cloud-server-c
|
* @Project:cloud-server-c
|
||||||
|
@ -24,7 +24,6 @@ import java.io.Serializable;
|
||||||
@Tag(name = "报文模版表")
|
@Tag(name = "报文模版表")
|
||||||
@TableName(value = "message_template_type",autoResultMap = true)
|
@TableName(value = "message_template_type",autoResultMap = true)
|
||||||
public class MessageTemplateType implements Serializable {
|
public class MessageTemplateType implements Serializable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 主键
|
* 主键
|
||||||
*/
|
*/
|
||||||
|
@ -57,6 +56,7 @@ public class MessageTemplateType implements Serializable {
|
||||||
/**
|
/**
|
||||||
* 数据类型名称
|
* 数据类型名称
|
||||||
*/
|
*/
|
||||||
|
@TableField(exist = false)
|
||||||
private String dataTypeName;
|
private String dataTypeName;
|
||||||
/**
|
/**
|
||||||
*最小值
|
*最小值
|
||||||
|
|
|
@ -10,11 +10,12 @@ import lombok.EqualsAndHashCode;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 车辆管理表
|
* 车辆对象
|
||||||
* @author sx
|
* @Author:liuxinyue
|
||||||
* @package com.muyu.common.domain
|
* @Package:com.sheep.message.domain
|
||||||
* @name SysCar
|
* @Project:cloud-server-c
|
||||||
* @date 2024-09-29 14:39:33
|
* @name:MessageTemplateType
|
||||||
|
* @Date:2024/9/18 21:01
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@ -22,6 +23,7 @@ import lombok.NoArgsConstructor;
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@TableName(value = "sys_car",autoResultMap = true)
|
@TableName(value = "sys_car",autoResultMap = true)
|
||||||
public class SysCar extends BaseEntity {
|
public class SysCar extends BaseEntity {
|
||||||
|
|
||||||
@TableId(value = "id",type = IdType.AUTO)
|
@TableId(value = "id",type = IdType.AUTO)
|
||||||
private Long id;
|
private Long id;
|
||||||
private String carVin;
|
private String carVin;
|
||||||
|
|
|
@ -11,11 +11,12 @@ import lombok.NoArgsConstructor;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 车辆上下线记录表
|
* 车辆记录对象
|
||||||
* @author sx
|
* @Author:liuxinyue
|
||||||
* @package com.muyu.common.domain
|
* @Package:com.sheep.message.domain
|
||||||
* @name SysCarLog
|
* @Project:cloud-server-c
|
||||||
* @date 2024-09-29 14:34:15
|
* @name:MessageTemplateType
|
||||||
|
* @Date:2024/9/18 21:01
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
|
|
@ -3,25 +3,22 @@ package com.muyu.common.domain;
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.experimental.SuperBuilder;
|
import lombok.experimental.SuperBuilder;
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 报文模版
|
* 报文模版对象
|
||||||
* @author liuxinyue
|
* @Author:liuxinyue
|
||||||
* @Package:com.template.domain
|
* @Package:com.template.domain
|
||||||
* @Project:cloud-server-c
|
* @Project:cloud-server-c
|
||||||
* @name:Template
|
* @name:Template
|
||||||
* @Date:2024/9/20 12:04
|
* @Date:2024/9/20 12:04
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
|
@ -50,7 +47,5 @@ public class Template {
|
||||||
/**
|
/**
|
||||||
* 创建时间
|
* 创建时间
|
||||||
*/
|
*/
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
|
||||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
|
||||||
private Date createTime;
|
private Date createTime;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ import java.util.Date;
|
||||||
/**
|
/**
|
||||||
* 预警日志对象 warn_logs
|
* 预警日志对象 warn_logs
|
||||||
*
|
*
|
||||||
* @author sx
|
* @author muyu
|
||||||
* @date 2024-09-20
|
* @date 2024-09-20
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ import lombok.NoArgsConstructor;
|
||||||
/**
|
/**
|
||||||
* 预警规则对象 warn_rule
|
* 预警规则对象 warn_rule
|
||||||
*
|
*
|
||||||
* @author sx
|
* @author muyu
|
||||||
* @date 2024-09-20
|
* @date 2024-09-20
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ import lombok.NoArgsConstructor;
|
||||||
/**
|
/**
|
||||||
* 预警策略对象 warn_strategy
|
* 预警策略对象 warn_strategy
|
||||||
*
|
*
|
||||||
* @author sx
|
* @author muyu
|
||||||
* @date 2024-09-20
|
* @date 2024-09-20
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,7 @@ import lombok.experimental.SuperBuilder;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 电子围栏表
|
* @Author:yuping
|
||||||
* @author yuping
|
|
||||||
* @Package:com.muyu.fence.domain
|
* @Package:com.muyu.fence.domain
|
||||||
* @Project:cloud-server
|
* @Project:cloud-server
|
||||||
* @name:ElectronicFence
|
* @name:ElectronicFence
|
||||||
|
|
|
@ -16,8 +16,7 @@ import lombok.experimental.SuperBuilder;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 围栏组
|
* @Author:yuping
|
||||||
* @author yuping
|
|
||||||
* @Package:com.muyu.fence.domain
|
* @Package:com.muyu.fence.domain
|
||||||
* @Project:cloud-server
|
* @Project:cloud-server
|
||||||
* @name:ElectronicFenceGroup
|
* @name:ElectronicFenceGroup
|
||||||
|
|
|
@ -9,8 +9,7 @@ import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 围栏组连接表
|
* @Author:yuping
|
||||||
* @author yuping
|
|
||||||
* @Package:com.muyu.fence.domain
|
* @Package:com.muyu.fence.domain
|
||||||
* @Project:cloud-server
|
* @Project:cloud-server
|
||||||
* @name:FenceGroupMid
|
* @name:FenceGroupMid
|
||||||
|
|
|
@ -10,8 +10,7 @@ import lombok.NoArgsConstructor;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 电动围栏添加请求参数
|
* @Author:yuping
|
||||||
* @author yuping
|
|
||||||
* @Package:com.muyu.fence.domain.req
|
* @Package:com.muyu.fence.domain.req
|
||||||
* @Project:cloud-server
|
* @Project:cloud-server
|
||||||
* @name:ElectroicAdd
|
* @name:ElectroicAdd
|
||||||
|
|
|
@ -8,8 +8,7 @@ import lombok.NoArgsConstructor;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 电子围栏列表请求参数
|
* @Author:yuping
|
||||||
* @author yuping
|
|
||||||
* @Package:com.muyu.fence.domain.req
|
* @Package:com.muyu.fence.domain.req
|
||||||
* @Project:cloud-server
|
* @Project:cloud-server
|
||||||
* @name:ElectroicFenceReq
|
* @name:ElectroicFenceReq
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue