Compare commits
42 Commits
f46db057b5
...
87d104cf9b
Author | SHA1 | Date |
---|---|---|
|
87d104cf9b | |
|
fe90a341ff | |
|
d99edc16d1 | |
|
50a655d888 | |
|
e8bc92c658 | |
|
76440e1c98 | |
|
b879a1768d | |
|
370fdd9fd5 | |
|
82ec79ccaf | |
|
551f5f5496 | |
|
8e0e492555 | |
|
6545fc79ef | |
|
78747b7d03 | |
|
d6ff8ad340 | |
|
8bc54f4662 | |
|
e6639bc7f9 | |
|
a0ddc45e67 | |
|
051fe490d6 | |
|
31df6d32db | |
|
798f509dec | |
|
f93af8b4a6 | |
|
1272d0e0b7 | |
|
1f072d4ca2 | |
|
8de7f88912 | |
|
ddf4ede829 | |
|
83ab8a27a7 | |
|
d38d77b331 | |
|
bc3053d834 | |
|
4ecdbe3881 | |
|
d586c26468 | |
|
7b36e4b359 | |
|
29cb1ffadb | |
|
2488248967 | |
|
dea0f07c90 | |
|
7d7950e925 | |
|
e3f65e7f1e | |
|
f4faf4d828 | |
|
a0994c3e7a | |
|
0228051467 | |
|
dfacea67f6 | |
|
688154709d | |
|
3f9a930c95 |
|
@ -57,6 +57,10 @@
|
|||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-api-doc</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
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.RegisterBody;
|
||||
import com.muyu.auth.service.SysFirmService;
|
||||
import com.muyu.auth.service.SysLoginService;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.utils.JwtUtils;
|
||||
|
@ -31,8 +34,16 @@ public class TokenController {
|
|||
@Autowired
|
||||
private SysLoginService sysLoginService;
|
||||
|
||||
@Autowired
|
||||
private SysFirmService sysFirmService;
|
||||
|
||||
@PostMapping("login")
|
||||
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());
|
||||
// 获取登录token
|
||||
|
@ -69,4 +80,10 @@ public class TokenController {
|
|||
sysLoginService.register(registerBody.getUsername(), registerBody.getPassword());
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@PostMapping("/enterprise")
|
||||
public Result<?> enterprise( @RequestBody EnterpriseSettlement settlement){
|
||||
sysLoginService.enterprise(settlement.getDatabaseName(),settlement.getFirmName());
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
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;
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
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,10 +1,14 @@
|
|||
package com.muyu.auth.form;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 用户登录对象
|
||||
*
|
||||
* @author muyu
|
||||
*/
|
||||
|
||||
@Data
|
||||
public class LoginBody {
|
||||
/**
|
||||
* 用户名
|
||||
|
@ -16,20 +20,11 @@ public class LoginBody {
|
|||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
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,5 +1,6 @@
|
|||
package com.muyu.auth.service;
|
||||
|
||||
import com.muyu.auth.form.EnterpriseSettlement;
|
||||
import com.muyu.common.core.constant.CacheConstants;
|
||||
import com.muyu.common.core.constant.Constants;
|
||||
import com.muyu.common.core.constant.SecurityConstants;
|
||||
|
@ -12,6 +13,7 @@ import com.muyu.common.core.utils.StringUtils;
|
|||
import com.muyu.common.core.utils.ip.IpUtils;
|
||||
import com.muyu.common.redis.service.RedisService;
|
||||
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.domain.SysUser;
|
||||
import com.muyu.common.system.domain.LoginUser;
|
||||
|
@ -124,4 +126,29 @@ public class SysLoginService {
|
|||
}
|
||||
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
|
||||
user-name: nacos
|
||||
password: nacos
|
||||
namespace: four
|
||||
namespace: yzl
|
||||
# Spring
|
||||
spring:
|
||||
application:
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</parent>
|
||||
|
||||
<groupId>com.muyu.cache</groupId>
|
||||
<artifactId>cloud-common-cache</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-redis</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,38 @@
|
|||
package com.muyu.cache;/**
|
||||
* @author yuping
|
||||
* @package com.muyu.cache
|
||||
* @name CacheAbsBasic
|
||||
* @date 2024/9/29 20:10 抽象缓存层
|
||||
*/
|
||||
|
||||
import com.muyu.common.redis.service.RedisService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import static cn.hutool.core.lang.ansi.AnsiEncoder.encode;
|
||||
|
||||
/**
|
||||
* @Author YuPing
|
||||
* @Description
|
||||
* @Version 1.0
|
||||
* @Data 2024-09-29 20:10:09
|
||||
*/
|
||||
public abstract class CacheAbsBasic<K,V> implements CacheBasic<K,V>{
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService; // spring redis 工具类
|
||||
|
||||
@Override
|
||||
public void put(K key, V value) {
|
||||
redisService.setCacheObject(encodeKey(key), value); // 编码 --> 缓存基础的对象 Integer String 实体类等
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get(K key) {
|
||||
return redisService.getCacheObject(encode(key)); // 获取缓存的基本对象 编码
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(K key) {
|
||||
redisService.deleteObject(encode(key));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.muyu.cache;
|
||||
|
||||
/**
|
||||
* @author yuping
|
||||
* @package com.muyu.cache
|
||||
* @name CacheBasic
|
||||
* @date 2024/9/29 20:08 缓存基础
|
||||
*/
|
||||
public interface CacheBasic <K,V> extends PrimaryKeyBasic<K>{
|
||||
|
||||
void put(K key, V value);
|
||||
|
||||
V get(K key);
|
||||
|
||||
void remove(K key);
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package com.muyu.cache;
|
||||
|
||||
/**
|
||||
* @author yuping
|
||||
* @package com.muyu.cache
|
||||
* @name PrimaryKeyBasic
|
||||
* @date 2024/9/29 20:03 主键基础
|
||||
*/
|
||||
public interface PrimaryKeyBasic <K> {
|
||||
|
||||
/**
|
||||
* key 前缀
|
||||
* @return key前缀
|
||||
*/
|
||||
public String keyPre();
|
||||
|
||||
|
||||
/**
|
||||
* key 编码
|
||||
* @param key 缓存键
|
||||
* @return 封装键
|
||||
*/
|
||||
public default String encodeKey(K key) {
|
||||
return keyPre() + key.toString(); //key 前缀
|
||||
}
|
||||
|
||||
/**
|
||||
* 解码 key
|
||||
* @param key 编码key
|
||||
* @return 解码后的key
|
||||
*/
|
||||
public K decode(String key);
|
||||
|
||||
}
|
|
@ -138,10 +138,10 @@
|
|||
</dependency>
|
||||
|
||||
<!-- Java Specification Requests 标准库-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>javax.annotation</groupId>-->
|
||||
<!-- <artifactId>jsr250-api</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>javax.annotation</groupId>-->
|
||||
<!-- <artifactId>jsr250-api</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.annotation</groupId>
|
||||
|
|
|
@ -110,4 +110,16 @@ public class UserConstants {
|
|||
public static final int PASSWORD_MIN_LENGTH = 5;
|
||||
|
||||
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,7 +1,5 @@
|
|||
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;
|
||||
|
|
|
@ -49,8 +49,6 @@ public class KafkaProducerConfig {
|
|||
private String acks;
|
||||
|
||||
|
||||
|
||||
|
||||
@Bean
|
||||
public KafkaProducer kafkaProducer() {
|
||||
Map<String, Object> configs = new HashMap<>();
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-redis</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -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,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,4 +1,4 @@
|
|||
package com.muyu.common.rabbit.config;
|
||||
package com.muyu.rabbitmq.config;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.amqp.rabbit.connection.CorrelationData;
|
|
@ -1,4 +1,4 @@
|
|||
package com.muyu.common.rabbit.config;
|
||||
package com.muyu.rabbitmq.config;
|
||||
|
||||
|
||||
|
||||
|
@ -21,16 +21,16 @@ public class RabbitAdminConfig {
|
|||
private String username;
|
||||
@Value("${spring.rabbitmq.password}")
|
||||
private String password;
|
||||
@Value("${spring.rabbitmq.virtualhost}")
|
||||
private String virtualHost;
|
||||
@Value("${spring.rabbitmq.port}")
|
||||
private Integer port;
|
||||
|
||||
@Bean
|
||||
public ConnectionFactory connectionFactory() {
|
||||
CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory();
|
||||
cachingConnectionFactory.setHost(host);
|
||||
cachingConnectionFactory.setPort(port);
|
||||
cachingConnectionFactory.setUsername(username);
|
||||
cachingConnectionFactory.setPassword(password);
|
||||
cachingConnectionFactory.setVirtualHost(virtualHost);
|
||||
return cachingConnectionFactory;
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.muyu.common.rabbit.config;
|
||||
package com.muyu.rabbitmq.config;
|
||||
|
||||
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
|
||||
import org.springframework.amqp.support.converter.MessageConverter;
|
|
@ -1,4 +1,4 @@
|
|||
package com.muyu.common.rabbit.config;
|
||||
package com.muyu.rabbitmq.config;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.amqp.core.ReturnedMessage;
|
|
@ -1,4 +1,4 @@
|
|||
package com.muyu.common.rabbit.constants;
|
||||
package com.muyu.rabbitmq.constants;
|
||||
|
||||
/**
|
||||
*
|
|
@ -1,11 +1,15 @@
|
|||
package com.muyu.common.rabbit.consumer;
|
||||
package com.muyu.rabbitmq.consumer;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.muyu.common.redis.service.RedisService;
|
||||
import com.muyu.rabbitmq.util.CacheUtil;
|
||||
import com.rabbitmq.client.Channel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.rabbit.annotation.Queue;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -22,6 +26,9 @@ public class RabbitMQConsumerUtil {
|
|||
|
||||
private final RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
private CacheUtil cacheUtil;
|
||||
|
||||
|
||||
/**
|
||||
* 普通消费者
|
||||
|
@ -29,7 +36,8 @@ public class RabbitMQConsumerUtil {
|
|||
* @param message
|
||||
* @param channel
|
||||
*/
|
||||
public void rabbitMQBasicConsumer(Object data ,Message message , Channel channel) {
|
||||
@RabbitListener(queuesToDeclare = @Queue(name = "basic"))
|
||||
public void rabbitMQBasicConsumer(String data ,Message message , Channel channel) {
|
||||
log.info("当前时间:{} :RabbitMQConsumerUtil : {}", new Date(), message);
|
||||
try {
|
||||
// 获取到消息 开始消费
|
||||
|
@ -42,10 +50,12 @@ public class RabbitMQConsumerUtil {
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* -----------------------------------以下为异步业务操作----------------------------
|
||||
*/
|
||||
String carList = (String) redisService.redisTemplate.opsForValue().get("carList");
|
||||
cacheUtil.put("carList",carList);
|
||||
|
||||
|
||||
/**
|
||||
* ------------------------------------------------------------------------------
|
|
@ -1,7 +1,7 @@
|
|||
package com.muyu.common.rabbit.producer;
|
||||
package com.muyu.rabbitmq.producer;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.rabbit.constants.RabbitmqConstants;
|
||||
import com.muyu.rabbitmq.constants.RabbitmqConstants;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.amqp.core.MessageProperties;
|
||||
|
@ -31,9 +31,9 @@ public class RabbitMQProducerUtil {
|
|||
* @return 结果集
|
||||
* 一对一消费,只有一个消费者能接收到
|
||||
*/
|
||||
public Result<?> basicSendMessage(String queueName, Object param, String msg) {
|
||||
public void basicSendMessage(String queueName, String param) {
|
||||
|
||||
log.info("【简单模型mq】 : method: 【 basicSendMessage 】 - ages: 【 String : {}, Object : {}, String : {} 】 ---> 【 消息发送中。。。 】", RabbitmqConstants.BASIC_QUEUE_NAME, param, msg);
|
||||
log.info("【简单模型mq】 : method: 【 basicSendMessage 】 - ages: 【 String : {}, Object : {}】 ---> 【 消息发送中。。。 】", RabbitmqConstants.BASIC_QUEUE_NAME, param);
|
||||
// 发送简单模型消息
|
||||
// 第一个参数: 绑定规则 相当于 队列名称
|
||||
// 第二个参数:消息内容
|
||||
|
@ -44,7 +44,7 @@ public class RabbitMQProducerUtil {
|
|||
|
||||
log.info("【简单模型mq】 : method: 【 basicSendMessage 】- queue: 【 {} 】 ---> 【 消息发送成功 】", RabbitmqConstants.BASIC_QUEUE_NAME);
|
||||
|
||||
return Result.success(msg!=null?msg:"消息发送成功");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -156,19 +156,19 @@ public class RabbitMQProducerUtil {
|
|||
* @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,"消息发送成功");
|
||||
|
||||
}
|
||||
// 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,"消息发送成功");
|
||||
//
|
||||
// }
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package com.muyu.rabbitmq.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);
|
||||
}
|
||||
|
||||
}
|
|
@ -2,6 +2,5 @@ com.muyu.rabbitmq.producer.RabbitMQProducerUtil
|
|||
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
|
||||
|
|
|
@ -40,7 +40,7 @@ import java.util.Map;
|
|||
public class ManyDataSource implements ApplicationRunner{
|
||||
private List<EntInfo> dataSourceInfoList(){
|
||||
RemoteSaaSService remoteSaaSService = SpringUtils.getBean(RemoteSaaSService.class);
|
||||
Result<List<Datasource>> tableDataInfoResult = remoteSaaSService.findDatabaseList();
|
||||
Result<List<Datasource>> tableDataInfoResult = remoteSaaSService.findDatabaseList();
|
||||
if (tableDataInfoResult==null){
|
||||
throw new SaaSException("saas远调数据源错误");
|
||||
}
|
||||
|
|
|
@ -1,23 +1,26 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
<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>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.bwie</groupId>
|
||||
<artifactId>cloud-common-swagger</artifactId>
|
||||
|
||||
<description>
|
||||
cloud-common-swagger swagger2文档聚合
|
||||
cloud-common-swagger系统接口
|
||||
</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>
|
||||
|
||||
<!-- SpringBoot Web -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
|
|
@ -1,10 +1,21 @@
|
|||
package com.muyu.common.swagger.annotation;
|
||||
|
||||
import com.muyu.common.swagger.config.SwaggerAutoConfiguration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* @author 袁子龙
|
||||
* @package:com.muyu.common.swagger.annotation
|
||||
* @name:EnableCustomSwagger2
|
||||
* @date:2024/9/29 10:01
|
||||
*/
|
||||
@Target({ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Inherited
|
||||
@Import({SwaggerAutoConfiguration.class})
|
||||
public @interface EnableCustomSwagger2 {
|
||||
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import java.util.List;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 在 springboot 2.6.x 不兼容问题的处理
|
||||
* @author 袁子龙
|
||||
* @package:com.muyu.common.swagger.config
|
||||
* @name:SwaggerBeanPostProcessor
|
||||
|
|
|
@ -300,4 +300,3 @@ public class SwaggerProperties {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
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,6 +4,7 @@ import com.muyu.common.core.constant.SecurityConstants;
|
|||
import com.muyu.common.core.constant.ServiceNameConstants;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
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.SysUser;
|
||||
import com.muyu.common.system.remote.factory.RemoteUserFallbackFactory;
|
||||
|
@ -44,4 +45,13 @@ public interface RemoteUserService {
|
|||
|
||||
@GetMapping("/user/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,6 +2,7 @@ package com.muyu.common.system.remote.factory;
|
|||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
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.remote.RemoteUserService;
|
||||
import com.muyu.common.system.domain.SysUser;
|
||||
|
@ -41,6 +42,11 @@ public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserServ
|
|||
return Result.error("获取企业列表失败:" + throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<Boolean> settlementEnterpriseInfo(Enterprise enterprise, String source) {
|
||||
return Result.error("入驻企业失败");
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
<module>cloud-common-rabbit</module>
|
||||
<module>cloud-common-saas</module>
|
||||
<module>cloud-common-swagger</module>
|
||||
<module>cloud-common-cache</module>
|
||||
<module>cloud-common-kafka</module>
|
||||
</modules>
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ nacos:
|
|||
addr: 47.101.53.251:8848
|
||||
user-name: nacos
|
||||
password: nacos
|
||||
namespace: four
|
||||
namespace: yzl
|
||||
|
||||
# Spring
|
||||
spring:
|
||||
|
|
|
@ -66,9 +66,7 @@ public class IoTDBConfig {
|
|||
measurements.add("car_vin");
|
||||
measurements.add("information");
|
||||
|
||||
|
||||
session.insertRecord(TABLENAME,System.currentTimeMillis(),measurements,list);
|
||||
|
||||
//关闭连接
|
||||
session.close();
|
||||
} catch (IoTDBConnectionException e) {
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.muyu.event.consumer;
|
||||
|
||||
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.muyu.event.basic.EventPublisher;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
@ -36,7 +34,6 @@ public class MessageConsumer implements ApplicationRunner {
|
|||
|
||||
private final String topic="four_car";
|
||||
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
List<String> list = Collections.singletonList(topic);
|
||||
|
@ -48,10 +45,8 @@ public class MessageConsumer implements ApplicationRunner {
|
|||
String value = record.value();
|
||||
JSONObject jsonObject = JSONObject.parseObject(value);
|
||||
log.info("value:{}",value);
|
||||
// eventPublisher.publishEvent(jsonObject);
|
||||
eventPublisher.publishEvent(jsonObject);
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package com.muyu.event.consumer;
|
||||
|
||||
import com.muyu.rabbitmq.consumer.RabbitMQConsumerUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* rabbitmq 监听器
|
||||
* @author 刘武
|
||||
* @package:com.muyu.event.consumer
|
||||
* @name:MqConsumer
|
||||
* @date:2024/10/2 14:17
|
||||
*/
|
||||
|
||||
@Component
|
||||
public class MqConsumer {
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -18,4 +18,6 @@ public class OnlineConsumer {
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 数据处理
|
||||
* @author 刘武
|
||||
* @package:com.muyu.event.controller
|
||||
* @name:DataController
|
||||
|
|
|
@ -19,13 +19,12 @@ import java.util.List;
|
|||
* @name:ItodbController
|
||||
* @date:2024/9/28 19:17
|
||||
*/
|
||||
@RestController()
|
||||
@RestController
|
||||
public class IoTDBController {
|
||||
|
||||
@Autowired
|
||||
private IoTDBService tdbService;
|
||||
|
||||
|
||||
/**
|
||||
* 查询实时车辆信息列表
|
||||
* @return list
|
||||
|
@ -47,7 +46,6 @@ public class IoTDBController {
|
|||
return Result.success(carInformation);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* 车辆添加
|
||||
* @param addCarInformation
|
||||
|
@ -71,4 +69,6 @@ public class IoTDBController {
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -2,20 +2,17 @@ package com.muyu.event.controller;
|
|||
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.muyu.event.service.TestService;
|
||||
import com.muyu.rabbitmq.producer.RabbitMQProducerUtil;
|
||||
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
|
||||
|
@ -26,25 +23,33 @@ public class TestController {
|
|||
|
||||
@Resource
|
||||
private KafkaProducer kafkaProducer;
|
||||
|
||||
@Resource
|
||||
private RabbitMQProducerUtil rabbitMQProducerUtil;
|
||||
|
||||
|
||||
private static final String topic="four_car";
|
||||
|
||||
@GetMapping("send")
|
||||
@GetMapping("sendKafka")
|
||||
public String sendKafka(){
|
||||
|
||||
String message="发送一条信息";
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("cj","sb");
|
||||
|
||||
|
||||
ProducerRecord<String, String> producerRecord = new ProducerRecord<String, String>(topic,jsonObject.toJSONString());
|
||||
jsonObject.put("cj","hh");
|
||||
ProducerRecord<String, String> producerRecord = new ProducerRecord<String, String>(topic,jsonObject.toString());
|
||||
kafkaProducer.send(producerRecord);
|
||||
|
||||
return "success";
|
||||
}
|
||||
|
||||
@GetMapping("sendMq")
|
||||
public String sendMq(){
|
||||
String message="发送一条信息-mq";
|
||||
rabbitMQProducerUtil.basicSendMessage("basic",message);
|
||||
return "success-mq";
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -13,7 +13,13 @@ import org.springframework.format.annotation.DateTimeFormat;
|
|||
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
/**
|
||||
* 事件实体类
|
||||
* @author 刘武
|
||||
* @package:com.muyu.event.domain
|
||||
* @name:Event
|
||||
* @date:2024/9/28 23:10
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
|
|
|
@ -7,7 +7,7 @@ nacos:
|
|||
addr: 47.101.53.251:8848
|
||||
user-name: nacos
|
||||
password: nacos
|
||||
namespace: four
|
||||
namespace: yzl
|
||||
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
|
||||
# Spring
|
||||
spring:
|
||||
|
|
|
@ -7,7 +7,7 @@ nacos:
|
|||
addr: 47.101.53.251:8848
|
||||
user-name: nacos
|
||||
password: nacos
|
||||
namespace: four
|
||||
namespace: yzl
|
||||
|
||||
# Spring
|
||||
spring:
|
||||
|
|
|
@ -9,7 +9,7 @@ import org.springframework.stereotype.Service;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 业务字段 服务层实现
|
||||
* 业务字段 业务逻辑层实现
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
|
|
|
@ -40,7 +40,7 @@ import java.util.zip.ZipEntry;
|
|||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
/**
|
||||
* 业务 服务层实现
|
||||
* 业务 业务逻辑层实现
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
|
|
|
@ -7,7 +7,7 @@ nacos:
|
|||
addr: 47.101.53.251:8848
|
||||
user-name: nacos
|
||||
password: nacos
|
||||
namespace: four
|
||||
namespace: yzl
|
||||
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
|
||||
# Spring
|
||||
spring:
|
||||
|
|
|
@ -10,10 +10,7 @@ import com.muyu.common.log.enums.BusinessType;
|
|||
import com.muyu.common.security.annotation.InnerAuth;
|
||||
import com.muyu.common.security.annotation.RequiresPermissions;
|
||||
import com.muyu.common.security.utils.SecurityUtils;
|
||||
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.common.system.domain.*;
|
||||
import com.muyu.system.domain.resp.AuthRoleResp;
|
||||
import com.muyu.system.domain.resp.UserDetailInfoResp;
|
||||
import com.muyu.system.domain.resp.UserInfoResp;
|
||||
|
@ -136,6 +133,15 @@ public class SysUserController extends BaseController {
|
|||
return Result.success(userService.registerUser(sysUser));
|
||||
}
|
||||
|
||||
/**
|
||||
* 入驻企业信息
|
||||
*/
|
||||
@InnerAuth
|
||||
@PostMapping("/enterprise")
|
||||
public Result<Boolean> enterprise (@RequestBody Enterprise enterprise){
|
||||
|
||||
return Result.success(userService.enterprise(enterprise));
|
||||
}
|
||||
/**
|
||||
* 获取用户信息
|
||||
*
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.muyu.system.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.muyu.common.system.domain.Enterprise;
|
||||
import com.muyu.common.system.domain.SysUser;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
|
@ -66,6 +67,8 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
|
|||
*/
|
||||
int insertUser(SysUser user);
|
||||
|
||||
int enterprise(Enterprise enterprise);
|
||||
|
||||
/**
|
||||
* 修改用户信息
|
||||
*
|
||||
|
@ -142,4 +145,6 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
|
|||
|
||||
List<SysUser> selectCompanyList();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import com.muyu.system.domain.vo.TreeSelect;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 部门管理 服务层
|
||||
* 部门管理 业务逻辑层
|
||||
*
|
||||
* @author muyu
|
||||
*/
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.muyu.system.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.muyu.common.system.domain.Enterprise;
|
||||
import com.muyu.common.system.domain.SysUser;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -133,6 +134,7 @@ public interface SysUserService extends IService<SysUser> {
|
|||
*/
|
||||
boolean registerUser(SysUser user);
|
||||
|
||||
boolean enterprise(Enterprise enterprise);
|
||||
/**
|
||||
* 修改用户信息
|
||||
*
|
||||
|
@ -228,4 +230,5 @@ public interface SysUserService extends IService<SysUser> {
|
|||
|
||||
List<SysUser> selectCompanyList();
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import com.muyu.common.core.utils.StringUtils;
|
|||
import com.muyu.common.core.utils.bean.BeanValidators;
|
||||
import com.muyu.common.datascope.annotation.DataScope;
|
||||
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.SysUser;
|
||||
import com.muyu.system.domain.SysPost;
|
||||
|
@ -257,6 +258,11 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||
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
|
||||
user-name: nacos
|
||||
password: nacos
|
||||
namespace: four
|
||||
namespace: yzl
|
||||
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
|
||||
# Spring
|
||||
spring:
|
||||
|
|
|
@ -221,6 +221,9 @@
|
|||
sysdate()
|
||||
)
|
||||
</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 sys_user
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
<?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>
|
||||
|
||||
|
||||
<!-- 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>
|
|
@ -0,0 +1,27 @@
|
|||
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
|
||||
//@EnableCustomSwagger2
|
||||
@EnableMyFeignClients
|
||||
@SpringBootApplication
|
||||
public class CloudTemplateApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
SpringApplication.run(CloudTemplateApplication.class, args);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package com.muyu.template.service;
|
||||
|
||||
/**
|
||||
* @author liuxinyue
|
||||
* @Package:com.muyu.template.service
|
||||
* @name:TemplateService
|
||||
* @Date:2024/9/30 10:57
|
||||
*/
|
||||
public interface TemplateService {
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.muyu.template.service.impl;
|
||||
|
||||
import com.muyu.template.service.TemplateService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author liuxinyue
|
||||
* @Package:com.muyu.template.service.impl
|
||||
* @name:TemplateServiceImpl
|
||||
* @Date:2024/9/30 10:57
|
||||
*/
|
||||
@Service
|
||||
public class TemplateServiceImpl implements TemplateService {
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
Spring Boot Version: ${spring-boot.version}
|
||||
Spring Application Name: ${spring.application.name}
|
|
@ -0,0 +1,74 @@
|
|||
<?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>
|
|
@ -0,0 +1,81 @@
|
|||
<?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>
|
|
@ -0,0 +1,81 @@
|
|||
<?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>
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.muyu.server.mapper.CarTypeMapper">
|
||||
|
||||
|
||||
|
||||
</mapper>
|
|
@ -0,0 +1,67 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<!--
|
||||
1.在mybats的开发中namespace有特殊的意思,一定要是对应接口的全限定名
|
||||
通过namespace可以简历mapper.xml和接口之间的关系(名字不重要,位置不重要)
|
||||
-->
|
||||
<mapper namespace="com.muyu.server.mapper.EnterpriseDao">
|
||||
|
||||
<!--查询企业信息-->
|
||||
<select id="selectEnterprise" resultType="HashMap" parameterType="Map">
|
||||
select *
|
||||
from tb_enterprise
|
||||
<where>
|
||||
<if test="enterpriseName != null">
|
||||
and enterprise_name like concat('%',#{enterpriseName},'%')
|
||||
</if>
|
||||
</where>
|
||||
limit #{start},#{length}
|
||||
</select>
|
||||
|
||||
<!--查询企业记录总数-->
|
||||
<select id="selectEnterpriseCount" resultType="Long">
|
||||
select count(enterprise_id)
|
||||
from tb_enterprise
|
||||
</select>
|
||||
|
||||
<!--新增企业信息-->
|
||||
<insert id="insert" parameterType="com.muyu.server.mapper.EnterpriseDao">
|
||||
insert into tb_enterprise
|
||||
set enterprise_name = #{enterpriseName},
|
||||
enterprise_car_count = #{enterpriseCarCount},
|
||||
enterprise_fence_count = #{enterpriseFenceCount}
|
||||
</insert>
|
||||
|
||||
|
||||
|
||||
<!--根据编号查询企业信息-->
|
||||
<select id="searchById" resultType="java.util.HashMap">
|
||||
select enterprise_id,enterprise_name,enterprise_car_count,enterprise_fence_count
|
||||
from tb_enterprise
|
||||
where enterprise_id = #{enterpriseId}
|
||||
</select>
|
||||
<!--修改企业信息-->
|
||||
<update id="updateEnterprise" parameterType="com.muyu.common.domain.Enterprise">
|
||||
update tb_enterprise
|
||||
set enterprise_name = #{enterpriseName},
|
||||
enterprise_car_count = #{enterpriseCarCount},
|
||||
enterprise_fence_count = #{enterpriseFenceCount}
|
||||
where enterprise_id = #{enterpriseId} and enterprise_id != 0
|
||||
</update>
|
||||
|
||||
|
||||
|
||||
<!--删除企业信息-->
|
||||
<delete id="deleteByIds">
|
||||
delete from tb_enterprise
|
||||
where enterprise_id in
|
||||
<foreach collection="ids" open="(" separator="," close=")" item="one">
|
||||
#{one}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
|
||||
|
||||
</mapper>
|
|
@ -0,0 +1,83 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.muyu.server.mapper.SysCarMapper">
|
||||
<insert id="addSysCar">
|
||||
INSERT INTO `four`.`sys_car`
|
||||
( `car_vin`, `car_type_id`, `state`, `car_motor_manufacturer`, `car_motor_model`,
|
||||
`car_battery_manufacturer`, `car_battery_model`, `strategy_id`,`group_id`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`,)
|
||||
VALUES (#{carVin}, #{carTypeId}, '1', #{carMotorManufacturer}, #{carMotorModel},
|
||||
#{carBatteryManufacturer}, #{carBatteryModel}, #{strategyId},#{groupId},#{createBy}, #{createTime}, #{updateBy}, #{updateTime}, #{remark})
|
||||
</insert>
|
||||
<update id="updSysCarById">
|
||||
UPDATE `four`.`sys_car`
|
||||
SET `car_vin` = #{carVin},
|
||||
`car_type_id` = #{carTypeId},
|
||||
`state` = #{state},
|
||||
`car_motor_manufacturer` = #{carMotorManufacturer},
|
||||
`car_motor_model` = #{carMotorModel},
|
||||
`car_battery_manufacturer` = #{carBatteryManufacturer},
|
||||
`car_battery_model` = #{carBatteryModel},
|
||||
`strategy_id` = #{strategyId},
|
||||
`group_id`=#{groupId}
|
||||
`create_by` = #{createBy},
|
||||
`create_time` = #{createTime},
|
||||
`update_by` = #{updateBy},
|
||||
`update_time` = #{updateTime},
|
||||
`remark` = #{remark} WHERE `id` = #{id}
|
||||
</update>
|
||||
<select id="selectSysCarVoList" resultType="com.muyu.common.domain.resp.SysCarVo">
|
||||
SELECT * ,car_type.type_name,warn_strategy.strategy_name,electronic_fence_group.group_name
|
||||
FROM `sys_car`
|
||||
LEFT JOIN car_type ON sys_car.car_type_id=car_type.id
|
||||
LEFT JOIN warn_strategy ON sys_car.strategy_id=warn_strategy.id
|
||||
LEFT JOIN electronic_fence_group ON sys_car.group_id=electronic_fence_group.id
|
||||
<where>
|
||||
<if test="carVin!=null and carVin!=''">
|
||||
sys_car.car_vin=#{carVin}
|
||||
</if>
|
||||
<if test="state!=null and state!=''">
|
||||
and sys_car.state=#{state}
|
||||
</if>
|
||||
<if test="carMotorManufacturer!=null and carMotorManufacturer!=''">
|
||||
and sys_car.car_motor_manufacturer=#{carMotorManufacturer}
|
||||
</if>
|
||||
<if test="carBatteryManufacturer!=null and carBatteryManufacturer!=''">
|
||||
and sys_car.car_battery_manufacturer=#{carBatteryManufacturer}
|
||||
</if>
|
||||
<if test="carMotorModel!=null and carMotorModel!=''">
|
||||
and sys_car.car_motor_model=#{carMotorModel}
|
||||
</if>
|
||||
<if test="carBatteryModel!=null and carBatteryModel!=''">
|
||||
and sys_car.car_battery_model=#{carBatteryModel}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectSysCarVoById" resultType="com.muyu.common.domain.resp.SysCarVo">
|
||||
SELECT * ,car_type.type_name,warn_strategy.strategy_name,electronic_fence_group.group_name
|
||||
FROM `sys_car`
|
||||
LEFT JOIN car_type ON sys_car.car_type_id=car_type.id
|
||||
LEFT JOIN warn_strategy ON sys_car.strategy_id=warn_strategy.id
|
||||
LEFT JOIN electronic_fence_group ON sys_car.group_id=electronic_fence_group.id
|
||||
where sys_car.id=#{id}
|
||||
</select>
|
||||
<select id="findFenceByCarVin" resultType="com.muyu.common.domain.resp.SysCarFaultLogVo">
|
||||
SELECT
|
||||
sys_car_fault_log.*,
|
||||
sys_car_fault.*
|
||||
FROM
|
||||
sys_car_fault_log
|
||||
LEFT JOIN sys_car_fault ON sys_car_fault_log.sys_car_fault_id = sys_car_fault.id
|
||||
WHERE
|
||||
sys_car_fault_log.vin = #{carVin};
|
||||
</select>
|
||||
<select id="findCarByVin" resultType="com.muyu.common.domain.SysCar">
|
||||
select * from sys_car where car_vin=#{carVin}
|
||||
</select>
|
||||
<select id="selectByCarVin" resultType="com.muyu.common.domain.SysCar">
|
||||
select * from sys_car where car_cin=#{carVin}
|
||||
</select>
|
||||
</mapper>
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.muyu.server.mapper.TemplateNeedMapper">
|
||||
|
||||
<select id="selectByTemplateId" resultType="com.muyu.common.domain.MessageTemplateType">
|
||||
SELECT * FROM `message_template_type` WHERE template_id=#{templateId}
|
||||
</select>
|
||||
</mapper>
|
|
@ -0,0 +1,31 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.muyu.server.mapper.WarnLogsMapper">
|
||||
<insert id="addWarnLog">
|
||||
INSERT INTO warn_logs VALUES
|
||||
<foreach collection="list" item="warnLogs" index="index" separator=",">
|
||||
(#{warnLogs.id})
|
||||
</foreach>
|
||||
</insert>
|
||||
<select id="selectWarnLogsList" resultType="com.muyu.common.domain.resp.WarnLogsResp">
|
||||
SELECT
|
||||
*,
|
||||
warn_rule.rule_name
|
||||
FROM
|
||||
warn_logs
|
||||
LEFT JOIN warn_rule
|
||||
ON warn_logs.warn_rule_id = warn_rule.id
|
||||
</select>
|
||||
<select id="selectWarnLogs" resultType="com.muyu.common.domain.resp.WarnLogsResp">
|
||||
SELECT
|
||||
*,
|
||||
warn_rule.rule_name
|
||||
FROM
|
||||
warn_logs
|
||||
LEFT JOIN warn_rule
|
||||
ON warn_logs.warn_rule_id = warn_rule.id
|
||||
where warn_rule.id=#{id}
|
||||
</select>
|
||||
</mapper>
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.muyu.server.mapper.WarnRuleMapper">
|
||||
|
||||
<select id="selectListByStrategyId" resultType="com.muyu.common.domain.resp.WarnRuleResp">
|
||||
SELECT * ,warn_strategy.strategy_name,
|
||||
message_template_type.message_field
|
||||
FROM `warn_rule`
|
||||
LEFT JOIN warn_strategy ON warn_rule.strategy_id=warn_strategy.id
|
||||
LEFT JOIN message_template_type ON warn_rule.msg_type_id=message_template_type.message_template_type_id
|
||||
WHERE warn_rule.strategy_id=#{strategyId}
|
||||
</select>
|
||||
<select id="selectWarnRuleRespList" resultType="com.muyu.common.domain.resp.WarnRuleResp">
|
||||
SELECT * ,warn_strategy.strategy_name,
|
||||
message_template_type.message_field
|
||||
FROM `warn_rule`
|
||||
LEFT JOIN warn_strategy ON warn_rule.strategy_id=warn_strategy.id
|
||||
LEFT JOIN message_template_type ON warn_rule.msg_type_id=message_template_type.message_template_type_id
|
||||
</select>
|
||||
</mapper>
|
|
@ -0,0 +1,35 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.muyu.server.mapper.WarnStrategyMapper">
|
||||
<select id="selectWarnStrategyList" resultType="com.muyu.common.domain.resp.WarnStrategyResp">
|
||||
SELECT *,
|
||||
car_type.type_name,
|
||||
t_template.template_name
|
||||
FROM `warn_strategy`
|
||||
LEFT JOIN car_type ON warn_strategy.car_type_id=car_type.id
|
||||
LEFT JOIN t_template ON warn_strategy.template_id=t_template.template_id
|
||||
<where>
|
||||
<if test="carTypeId!=null and carTypeId!=''">
|
||||
car_type.id=#{carTypeId}
|
||||
</if>
|
||||
<if test="strategyName!=null and strategyName!=''">
|
||||
and warn_strategy.strategy_name=#{strategyName}
|
||||
</if>
|
||||
<if test="templateId!=null and templateId!=''">
|
||||
and t_template.template_id=#{templateId}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
<select id="selectListByCarType" resultType="com.muyu.common.domain.resp.WarnStrategyResp">
|
||||
SELECT *,
|
||||
car_type.type_name,
|
||||
t_template.template_name
|
||||
FROM `warn_strategy`
|
||||
LEFT JOIN car_type ON warn_strategy.car_type_id=car_type.id
|
||||
LEFT JOIN t_template ON warn_strategy.template_id=t_template.template_id
|
||||
where warn_strategy.car_type_id=#{carTypeId}
|
||||
</select>
|
||||
</mapper>
|
|
@ -102,6 +102,36 @@
|
|||
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
|
||||
<version>1.2.5</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>ecs20140526</artifactId>
|
||||
<version>5.1.8</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>tea-openapi</artifactId>
|
||||
<version>0.3.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>tea-console</artifactId>
|
||||
<version>0.0.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>tea-util</artifactId>
|
||||
<version>0.2.21</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>aliyun-java-sdk-ecs</artifactId>
|
||||
<version>4.2.0</version><!-- 请根据实际情况使用最新的版本 -->
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -0,0 +1,173 @@
|
|||
package com.muyu.vehicle;
|
||||
|
||||
|
||||
import com.aliyun.ecs20140526.Client;
|
||||
import com.aliyun.ecs20140526.models.*;
|
||||
import com.aliyun.tea.TeaException;
|
||||
import com.aliyun.teaopenapi.models.Config;
|
||||
import com.aliyun.teautil.Common;
|
||||
import com.aliyun.teautil.models.RuntimeOptions;
|
||||
import com.muyu.vehicle.domain.InstanceInfo;
|
||||
import com.muyu.vehicle.service.OpenInstance;
|
||||
import com.muyu.vehicle.service.SelectInstance;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@Log4j2
|
||||
public class ManageInstance implements ApplicationRunner {
|
||||
|
||||
/**
|
||||
* ACCESS_KEY_ID
|
||||
*/
|
||||
public static final String ALIBABA_CLOUD_ACCESS_KEY_ID="LTAI5tGabdxedjfCh2uXHNrw";
|
||||
|
||||
/**
|
||||
*ACCESS_KEY_SECRET
|
||||
*/
|
||||
public static final String ACCESS_KEY_SECRET="NHb7wHVpesLW6Axc0bFBs6ThhuNR10";
|
||||
|
||||
|
||||
/**
|
||||
* 镜像ID
|
||||
*/
|
||||
public static final String IMAGE_ID="m-uf6agr9i6g27gj23om34";
|
||||
|
||||
/**
|
||||
* 实例类型
|
||||
*/
|
||||
public static final String INSTANCE_TYPE="ecs.e-c1m1.large";
|
||||
|
||||
/**
|
||||
* 安全组ID
|
||||
*/
|
||||
public static final String SECURITY_GROUP_ID="sg-uf6glo8c4k17szhxu7sk";
|
||||
|
||||
/**
|
||||
*交换机ID
|
||||
*/
|
||||
public static final String V_SWITCH_ID="vsw-uf6xy4rbt9ggcz93t6oib";
|
||||
|
||||
|
||||
/**
|
||||
* 实例付费类型
|
||||
*/
|
||||
public static final String INSTANCE_CHARGE_TY="PostPaid";
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 使用AK&SK初始化账号Client
|
||||
* @return Client
|
||||
* @throws Exception
|
||||
*/
|
||||
|
||||
public static Client createClient() throws Exception {
|
||||
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
|
||||
Config config = new Config()
|
||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
|
||||
.setAccessKeyId(ALIBABA_CLOUD_ACCESS_KEY_ID)
|
||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
|
||||
.setAccessKeySecret(ACCESS_KEY_SECRET);
|
||||
// Endpoint 请参考 https://api.aliyun.com/product/Ecs
|
||||
config.endpoint = "ecs-cn-hangzhou.aliyuncs.com";
|
||||
return new com.aliyun.ecs20140526.Client(config);
|
||||
}
|
||||
|
||||
|
||||
public static void generateInstance() throws Exception {
|
||||
// 创建阿里云ECS客户端
|
||||
Client client = ManageInstance.createClient();
|
||||
// 配置系统盘参数
|
||||
RunInstancesRequest.RunInstancesRequestSystemDisk systemDisk=
|
||||
new RunInstancesRequest.RunInstancesRequestSystemDisk()
|
||||
.setSize("40")
|
||||
.setCategory("cloud_essd");
|
||||
|
||||
// 创建创建实例请求对象并设置参数
|
||||
|
||||
RunInstancesRequest runInstancesRequest = new RunInstancesRequest()
|
||||
.setRegionId("cn-shanghai") // 设置地域ID
|
||||
.setImageId(IMAGE_ID) // 设置镜像ID
|
||||
.setInstanceType(INSTANCE_TYPE) // 设置实例类型
|
||||
.setSecurityGroupId(SECURITY_GROUP_ID) // 设置安全组ID
|
||||
.setVSwitchId(V_SWITCH_ID) // 设置虚拟交换机ID
|
||||
.setInstanceName("cloud-MQTT") // 设置实例名称
|
||||
.setInstanceChargeType(INSTANCE_CHARGE_TY) // 设置实例付费类型为后付费按量付费
|
||||
.setSystemDisk(systemDisk) // 设置系统盘配置
|
||||
.setHostName("root") // 设置主机名
|
||||
.setPassword("2112A-four") // 设置实例密码
|
||||
.setAmount(2) // 设置创建实例的数量
|
||||
.setInternetChargeType("PayByTraffic")
|
||||
.setInternetMaxBandwidthOut(1);
|
||||
|
||||
|
||||
//创建运行时选择对象
|
||||
RuntimeOptions runTime=
|
||||
new RuntimeOptions();
|
||||
// 尝试执行创建实例请求
|
||||
try {
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
// 复制代码运行请自行打印 API 的返回值
|
||||
RunInstancesResponse runInstancesResponse = client.runInstancesWithOptions(runInstancesRequest, runTime);
|
||||
RunInstancesResponseBody body = runInstancesResponse.getBody();
|
||||
for (String instance : body.getInstanceIdSets().getInstanceIdSet()) {
|
||||
list.add(instance);
|
||||
}
|
||||
log.info("ESC创建成功,实例ID为:" + list);
|
||||
} catch (TeaException error) {
|
||||
// 错误 message
|
||||
log.info(error.getMessage());
|
||||
// 诊断地址
|
||||
log.info(error.getData().get("Recommend"));
|
||||
Common.assertAsString(error.message);
|
||||
} catch (Exception _error) {
|
||||
TeaException error = new TeaException(_error.getMessage(), _error);
|
||||
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
||||
// 错误 message
|
||||
log.info("实例创建失败:"+error.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static List<InstanceInfo> selectInstance() throws Exception {
|
||||
Client client = ManageInstance.createClient();
|
||||
ArrayList<InstanceInfo> instanceInfos = new ArrayList<>();// 实例基础信息
|
||||
DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest()
|
||||
.setRegionId("cn-shanghai")
|
||||
.setInternetChargeType("PayByTraffic")
|
||||
.setInstanceChargeType("PostPaid")
|
||||
.setInstanceName("cloud-MQTT") // 设置实例名称
|
||||
;
|
||||
// 创建运行时选项对象
|
||||
RuntimeOptions runtime = new RuntimeOptions();
|
||||
//实例ID Instances.Instance.InstanceId
|
||||
//实例IP Instances.Instance.PublicIpAddress.IpAddress
|
||||
//状态 Instances.Instance.Status
|
||||
DescribeInstancesResponse resp =client.describeInstancesWithOptions(describeInstancesRequest, runtime);
|
||||
DescribeInstancesResponseBody body = resp.getBody();
|
||||
|
||||
for (DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance instance : body.getInstances().getInstance()){
|
||||
InstanceInfo instanceInfo = new InstanceInfo();
|
||||
instanceInfo.setInstanceId(instance.getInstanceId());
|
||||
instanceInfo.setIpAddress(String.valueOf(instance.getPublicIpAddress().getIpAddress()));
|
||||
instanceInfo.setStatus(instance.getStatus());
|
||||
instanceInfos.add(instanceInfo);
|
||||
|
||||
}
|
||||
log.info("实例信息为:"+Common.toJSONString(instanceInfos));
|
||||
return instanceInfos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
generateInstance();
|
||||
selectInstance();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,132 +0,0 @@
|
|||
package com.muyu.vehicle;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.muyu.web.common.ScheduledThreadPool;
|
||||
import com.muyu.web.domain.MqttProperties;
|
||||
import com.muyu.web.domain.VehicleInfo;
|
||||
import com.muyu.web.domain.model.PositionModel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.eclipse.paho.client.mqttv3.MqttClient;
|
||||
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
|
||||
import org.eclipse.paho.client.mqttv3.MqttException;
|
||||
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@Log4j2
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class VehicleInstance {
|
||||
/**
|
||||
* 路线轨迹编码
|
||||
*/
|
||||
private String positionCode;
|
||||
|
||||
/**
|
||||
* 路径队列
|
||||
*/
|
||||
private LinkedBlockingQueue<PositionModel> positionQueue=new LinkedBlockingQueue<>();
|
||||
|
||||
/**
|
||||
* 车辆
|
||||
*/
|
||||
private VehicleInfo vehicleInfo;
|
||||
|
||||
/**
|
||||
* 车辆工作线程
|
||||
*/
|
||||
private VehicleThread vehicleThread;
|
||||
|
||||
/**
|
||||
* MQTT配置
|
||||
*/
|
||||
private MqttProperties mqttProperties;
|
||||
|
||||
/**
|
||||
* 线程提交回调
|
||||
*/
|
||||
private ScheduledFuture<?>scheduledFuture;
|
||||
|
||||
/**
|
||||
* 连接上报
|
||||
*/
|
||||
private MqttClient client;
|
||||
|
||||
|
||||
/**
|
||||
* 获取当前车辆VIN
|
||||
*/
|
||||
public String getVin(){
|
||||
return this.vehicleInfo.getVin();
|
||||
}
|
||||
/**
|
||||
* 获取车辆租户信息
|
||||
*/
|
||||
public String getTenantId(){
|
||||
return this.vehicleInfo.getTenantId();
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送消息
|
||||
*/
|
||||
public void sengMsg(String msg){
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 初始化客户端
|
||||
*/
|
||||
public void initClient(){
|
||||
try {
|
||||
client = new MqttClient(mqttProperties.getBroker(), mqttProperties.getClientId(), new MemoryPersistence());
|
||||
MqttConnectOptions options = new MqttConnectOptions();
|
||||
//设置用户名和密码
|
||||
if (Objects.nonNull(mqttProperties.getUserName())&&Objects.nonNull(mqttProperties.getPassword())){
|
||||
options.setUserName(mqttProperties.getUserName());
|
||||
options.setPassword(mqttProperties.getPassword().toCharArray());
|
||||
}
|
||||
options.setConnectionTimeout(1);
|
||||
options.setKeepAliveInterval(20);
|
||||
//连接
|
||||
client.connect(options);
|
||||
log.debug("车辆:[{}]客户端初始化成功连接配置:{}",getVin(),
|
||||
JSONObject.toJSONString(this.mqttProperties)
|
||||
);
|
||||
VehicleThread vehicleThread = new VehicleThread();
|
||||
vehicleThread.setVehicleInstance(this);
|
||||
this.setVehicleThread(vehicleThread);
|
||||
ScheduledFuture<?> submit = ScheduledThreadPool.submit(vehicleThread);
|
||||
this.setScheduledFuture(submit);
|
||||
log.info("初始化车辆上报模拟线程开始:[{}]", this.getVin());
|
||||
} catch (MqttException e) {
|
||||
log.error("车辆:[{}] 客户端初始化异常", getVin(), e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否连接在线
|
||||
*/
|
||||
public boolean isOnline(){
|
||||
if (this.client==null){
|
||||
return false;
|
||||
}
|
||||
return this.client.isConnected();
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否建立车辆模拟线程
|
||||
*/
|
||||
public boolean isSend(){
|
||||
return this.vehicleThread!=null;
|
||||
}
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
package com.muyu.vehicle;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
||||
@Data
|
||||
@Log4j2
|
||||
public class VehicleThread implements Runnable{
|
||||
/**
|
||||
* 是否停止线程
|
||||
*/
|
||||
private volatile boolean isStop;
|
||||
|
||||
/**
|
||||
* 车辆实例对象
|
||||
*/
|
||||
private VehicleInstance vehicleInstance;
|
||||
@Override
|
||||
public void run() {
|
||||
if (!isStop){
|
||||
log.info("{}-上报数据",this.vehicleInstance.getVin());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
package com.muyu.vehicle.api;
|
||||
|
||||
/**
|
||||
* 客户端管理
|
||||
*/
|
||||
public interface ClientAdmin {
|
||||
/**
|
||||
* 获取车辆负载地址
|
||||
*/
|
||||
|
||||
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
package com.muyu.vehicle.core;
|
||||
|
||||
import com.muyu.vehicle.VehicleInstance;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class LocalContainer {
|
||||
private static final Map<String,Map<String, VehicleInstance>> tenantVehicleDataMap
|
||||
=new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* 获取租户ID下车辆
|
||||
*/
|
||||
public static Map<String,VehicleInstance>getVehicleDataMap(String tenantId){
|
||||
return tenantVehicleDataMap.computeIfAbsent(tenantId,k->new ConcurrentHashMap<>());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package com.muyu.vehicle.core;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Log4j2
|
||||
@Configuration
|
||||
@AllArgsConstructor
|
||||
public class VehicleConfiguration {
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.muyu.vehicle.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class InstanceInfo {
|
||||
|
||||
//实例ID
|
||||
private String InstanceId;
|
||||
|
||||
private String IpAddress;
|
||||
|
||||
private String status;
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
package com.muyu.vehicle.service;
|
||||
|
||||
|
||||
import com.aliyun.ecs20140526.Client;
|
||||
import com.aliyun.ecs20140526.models.DeleteInstancesRequest;
|
||||
import com.aliyun.ecs20140526.models.DescribeInstancesRequest;
|
||||
import com.aliyun.ecs20140526.models.DescribeInstancesResponse;
|
||||
import com.aliyun.ecs20140526.models.DescribeInstancesResponseBody;
|
||||
import com.aliyun.tea.TeaException;
|
||||
import com.aliyun.teaopenapi.models.Config;
|
||||
import com.aliyun.teautil.Common;
|
||||
import com.aliyun.teautil.models.RuntimeOptions;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
@Component
|
||||
@Log4j2
|
||||
public class CloseInstance implements DisposableBean {
|
||||
/**
|
||||
* ACCESS_KEY_ID
|
||||
*/
|
||||
public static final String ALIBABA_CLOUD_ACCESS_KEY_ID="LTAI5tGabdxedjfCh2uXHNrw";
|
||||
|
||||
/**
|
||||
*ACCESS_KEY_SECRET
|
||||
*/
|
||||
public static final String ACCESS_KEY_SECRET="NHb7wHVpesLW6Axc0bFBs6ThhuNR10";
|
||||
public static Client createClient() throws Exception {
|
||||
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
|
||||
// 建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378657.html。
|
||||
Config config = new Config()
|
||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
|
||||
.setAccessKeyId(ALIBABA_CLOUD_ACCESS_KEY_ID)
|
||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
|
||||
.setAccessKeySecret(ACCESS_KEY_SECRET);
|
||||
// Endpoint 请参考 https://api.aliyun.com/product/Ecs
|
||||
config.endpoint = "ecs.cn-shanghai.aliyuncs.com";
|
||||
return new Client(config);
|
||||
}
|
||||
|
||||
public static void delInstance() throws Exception {
|
||||
|
||||
// 创建ECS客户端对象,用于后续调用ECS相关API
|
||||
Client client = CloseInstance.createClient();
|
||||
|
||||
DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest()
|
||||
.setRegionId("cn-shanghai");
|
||||
|
||||
//创建运行时选择对象,用于配置运行时的选项参数
|
||||
RuntimeOptions runtimeOptions = new RuntimeOptions();
|
||||
|
||||
//获取实例列表
|
||||
DescribeInstancesResponse describeInstancesResponse = client.describeInstancesWithOptions(describeInstancesRequest, runtimeOptions);
|
||||
|
||||
//提取实例ID集合
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
DescribeInstancesResponseBody body = describeInstancesResponse.getBody();
|
||||
|
||||
for (DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance instance : body.getInstances().getInstance()) {
|
||||
if (!instance.getInstanceId().equals("i-uf68jwsbbqq4b4xc893s")){
|
||||
list.add(instance.getInstanceId());
|
||||
}
|
||||
}
|
||||
log.info("搜索到实例Instance IDs: " + list);
|
||||
// 创建删除实例请求对象,并设置请求参数
|
||||
DeleteInstancesRequest deleteInstancesRequest = new DeleteInstancesRequest()
|
||||
// 设置地域ID,指定删除实例的地域
|
||||
.setRegionId("cn-shanghai")
|
||||
// 设置DryRun为true,用于验证请求是否可以成功,但不实际执行删除操作
|
||||
.setDryRun(false)
|
||||
// 设置Force为true,表示即使实例有正在运行的任务,也强制删除实例
|
||||
.setForce(true)
|
||||
// 设置TerminateSubscription为true,表示删除按订阅付费的实例时终止订阅
|
||||
.setTerminateSubscription(true)
|
||||
.setInstanceId(list);
|
||||
|
||||
// 创建运行时选项对象,用于配置运行时的选项参数
|
||||
RuntimeOptions runtime = new RuntimeOptions();
|
||||
try {
|
||||
// 复制代码运行请自行打印 API 的返回值
|
||||
client.deleteInstancesWithOptions(deleteInstancesRequest, runtime);
|
||||
} catch (TeaException error) {
|
||||
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
||||
// 错误 message
|
||||
log.info(error.getMessage());
|
||||
// 诊断地址
|
||||
log.info(error.getData().get("Recommend"));
|
||||
Common.assertAsString(error.message);
|
||||
} catch (Exception _error) {
|
||||
TeaException error = new TeaException(_error.getMessage(), _error);
|
||||
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
||||
// 错误 message
|
||||
System.out.println(error.getMessage());
|
||||
// 诊断地址
|
||||
log.info(error.getData().get("Recommend"));
|
||||
Common.assertAsString(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void destroy() throws Exception {
|
||||
log.info("开始删除实例");
|
||||
delInstance();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,129 @@
|
|||
package com.muyu.vehicle.service;
|
||||
|
||||
import com.aliyun.ecs20140526.Client;
|
||||
import com.aliyun.ecs20140526.models.RunInstancesRequest;
|
||||
import com.aliyun.ecs20140526.models.RunInstancesResponse;
|
||||
import com.aliyun.ecs20140526.models.RunInstancesResponseBody;
|
||||
import com.aliyun.tea.TeaException;
|
||||
import com.aliyun.teaopenapi.models.Config;
|
||||
import com.aliyun.teautil.Common;
|
||||
import com.aliyun.teautil.models.RuntimeOptions;
|
||||
import com.muyu.vehicle.ManageInstance;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@Log4j2
|
||||
public class OpenInstance {
|
||||
/**
|
||||
* ACCESS_KEY_ID
|
||||
*/
|
||||
public static final String ALIBABA_CLOUD_ACCESS_KEY_ID="LTAI5tGabdxedjfCh2uXHNrw";
|
||||
|
||||
/**
|
||||
*ACCESS_KEY_SECRET
|
||||
*/
|
||||
public static final String ACCESS_KEY_SECRET="NHb7wHVpesLW6Axc0bFBs6ThhuNR10";
|
||||
|
||||
|
||||
/**
|
||||
* 镜像ID
|
||||
*/
|
||||
public static final String IMAGE_ID="m-uf6agr9i6g27gj23om34";
|
||||
|
||||
/**
|
||||
* 实例类型
|
||||
*/
|
||||
public static final String INSTANCE_TYPE="ecs.e-c1m1.large";
|
||||
|
||||
/**
|
||||
* 安全组ID
|
||||
*/
|
||||
public static final String SECURITY_GROUP_ID="sg-uf6glo8c4k17szhxu7sk";
|
||||
|
||||
/**
|
||||
*交换机ID
|
||||
*/
|
||||
public static final String V_SWITCH_ID="vsw-uf6xy4rbt9ggcz93t6oib";
|
||||
|
||||
|
||||
/**
|
||||
* 实例付费类型
|
||||
*/
|
||||
public static final String INSTANCE_CHARGE_TY="PostPaid";
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 使用AK&SK初始化账号Client
|
||||
* @return Client
|
||||
* @throws Exception
|
||||
*/
|
||||
|
||||
public static Client createClient() throws Exception {
|
||||
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
|
||||
Config config = new Config()
|
||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
|
||||
.setAccessKeyId(ALIBABA_CLOUD_ACCESS_KEY_ID)
|
||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
|
||||
.setAccessKeySecret(ACCESS_KEY_SECRET);
|
||||
// Endpoint 请参考 https://api.aliyun.com/product/Ecs
|
||||
config.endpoint = "ecs-cn-hangzhou.aliyuncs.com";
|
||||
return new com.aliyun.ecs20140526.Client(config);
|
||||
}
|
||||
|
||||
|
||||
public static void generateInstance() throws Exception {
|
||||
// 创建阿里云ECS客户端
|
||||
Client client = OpenInstance.createClient();
|
||||
// 配置系统盘参数
|
||||
RunInstancesRequest.RunInstancesRequestSystemDisk systemDisk=
|
||||
new RunInstancesRequest.RunInstancesRequestSystemDisk()
|
||||
.setSize("40")
|
||||
.setCategory("cloud_essd");
|
||||
|
||||
// 创建创建实例请求对象并设置参数
|
||||
|
||||
RunInstancesRequest runInstancesRequest = new RunInstancesRequest()
|
||||
.setRegionId("cn-shanghai") // 设置地域ID
|
||||
.setImageId(IMAGE_ID) // 设置镜像ID
|
||||
.setInstanceType(INSTANCE_TYPE) // 设置实例类型
|
||||
.setSecurityGroupId(SECURITY_GROUP_ID) // 设置安全组ID
|
||||
.setVSwitchId(V_SWITCH_ID) // 设置虚拟交换机ID
|
||||
.setInstanceName("cloud-MQTT") // 设置实例名称
|
||||
.setInstanceChargeType(INSTANCE_CHARGE_TY) // 设置实例付费类型为后付费按量付费
|
||||
.setSystemDisk(systemDisk) // 设置系统盘配置
|
||||
.setHostName("root") // 设置主机名
|
||||
.setPassword("2112A-four") // 设置实例密码
|
||||
.setAmount(2) // 设置创建实例的数量
|
||||
.setInternetChargeType("PayByTraffic")
|
||||
.setInternetMaxBandwidthOut(1);
|
||||
|
||||
|
||||
//创建运行时选择对象
|
||||
RuntimeOptions runTime=
|
||||
new RuntimeOptions();
|
||||
// 尝试执行创建实例请求
|
||||
try {
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
// 复制代码运行请自行打印 API 的返回值
|
||||
RunInstancesResponse runInstancesResponse = client.runInstancesWithOptions(runInstancesRequest, runTime);
|
||||
RunInstancesResponseBody body = runInstancesResponse.getBody();
|
||||
for (String instance : body.getInstanceIdSets().getInstanceIdSet()) {
|
||||
list.add(instance);
|
||||
log.info("ESC创建成功,实例ID为:" + list);
|
||||
}
|
||||
} catch (TeaException error) {
|
||||
// 错误 message
|
||||
log.info(error.getMessage());
|
||||
// 诊断地址
|
||||
log.info(error.getData().get("Recommend"));
|
||||
Common.assertAsString(error.message);
|
||||
} catch (Exception _error) {
|
||||
TeaException error = new TeaException(_error.getMessage(), _error);
|
||||
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
||||
// 错误 message
|
||||
log.info("实例创建失败:"+error.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
package com.muyu.vehicle.service;
|
||||
|
||||
import com.aliyun.ecs20140526.Client;
|
||||
import com.aliyun.ecs20140526.models.DescribeInstancesRequest;
|
||||
import com.aliyun.ecs20140526.models.DescribeInstancesResponse;
|
||||
import com.aliyun.ecs20140526.models.DescribeInstancesResponseBody;
|
||||
import com.aliyun.teaopenapi.models.Config;
|
||||
import com.aliyun.teautil.Common;
|
||||
import com.aliyun.teautil.models.RuntimeOptions;
|
||||
import com.muyu.vehicle.domain.InstanceInfo;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@Log4j2
|
||||
public class SelectInstance {
|
||||
/**
|
||||
* ACCESS_KEY_ID
|
||||
*/
|
||||
public static final String ALIBABA_CLOUD_ACCESS_KEY_ID="LTAI5tGabdxedjfCh2uXHNrw";
|
||||
|
||||
/**
|
||||
*ACCESS_KEY_SECRET
|
||||
*/
|
||||
public static final String ACCESS_KEY_SECRET="NHb7wHVpesLW6Axc0bFBs6ThhuNR10";
|
||||
|
||||
public static Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
|
||||
Config config = new com.aliyun.teaopenapi.models.Config()
|
||||
// 必填,您的 AccessKey ID
|
||||
.setAccessKeyId(ALIBABA_CLOUD_ACCESS_KEY_ID)
|
||||
// 必填,您的 AccessKey Secret
|
||||
.setAccessKeySecret(ACCESS_KEY_SECRET);
|
||||
// 访问的域名
|
||||
config.endpoint = "ecs-cn-hangzhou.aliyuncs.com";
|
||||
return new Client(config);
|
||||
}
|
||||
|
||||
public static void main(String[] args_) throws Exception {
|
||||
java.util.List<String> args = java.util.Arrays.asList(args_);
|
||||
// 请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID 和 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
|
||||
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考,建议使用更安全的 STS 方式
|
||||
Client client = SelectInstance.createClient(ALIBABA_CLOUD_ACCESS_KEY_ID, ACCESS_KEY_SECRET);
|
||||
DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest()
|
||||
.setRegionId("cn-shanghai")
|
||||
.setInternetChargeType("PayByTraffic")
|
||||
.setInstanceChargeType("PostPaid")
|
||||
.setInstanceName("cloud-MQTT") // 设置实例名称
|
||||
;
|
||||
//实例ID Instances.Instance.InstanceId
|
||||
//实例IP Instances.Instance.PublicIpAddress.IpAddress
|
||||
//状态 Instances.Instance.Status
|
||||
RuntimeOptions runtime = new RuntimeOptions();
|
||||
DescribeInstancesResponse resp = client.describeInstancesWithOptions(describeInstancesRequest, runtime);
|
||||
DescribeInstancesResponseBody body = resp.getBody();
|
||||
ArrayList<InstanceInfo> instanceInfos = new ArrayList<>();// 实例基础信息
|
||||
for (DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance instance : body.getInstances().getInstance()){
|
||||
|
||||
InstanceInfo instanceInfo = new InstanceInfo();
|
||||
instanceInfo.setInstanceId(instance.getInstanceId());
|
||||
instanceInfo.setIpAddress(String.valueOf(instance.getPublicIpAddress().getIpAddress()));
|
||||
instanceInfo.setStatus(instance.getStatus());
|
||||
instanceInfos.add(instanceInfo);
|
||||
}
|
||||
log.info(Common.toJSONString(instanceInfos));
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
package com.muyu.web.common;
|
||||
|
||||
import net.sf.jsqlparser.statement.select.KSQLWindow;
|
||||
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class ScheduledThreadPool {
|
||||
/**
|
||||
* 周期线程数 CPU*2+1
|
||||
*/
|
||||
private static final ScheduledExecutorService scheduledThreadPool= Executors.newScheduledThreadPool(
|
||||
Runtime.getRuntime().availableProcessors()*2+1
|
||||
);
|
||||
|
||||
public static ScheduledFuture<?>submit(Runnable thread){
|
||||
// 参数分别是: 任务, 多久后开始执行, 每隔多久执行一次(周期),时间单位
|
||||
return submit(thread, 1);
|
||||
}
|
||||
|
||||
public static ScheduledFuture<?>submit(Runnable thread,long period){
|
||||
return scheduledThreadPool.scheduleAtFixedRate(thread,0,period, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭线程池
|
||||
*/
|
||||
public static void shutdown(){
|
||||
scheduledThreadPool.shutdown();
|
||||
}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
package com.muyu.web.controller;
|
||||
|
||||
import com.muyu.common.core.utils.uuid.UUID;
|
||||
import org.eclipse.paho.client.mqttv3.*;
|
||||
|
||||
public class testController {
|
||||
public static void main(String[] args) {
|
||||
String broker = "tcp://47.101.53.251:1883";
|
||||
String clientId = "SX-"+ UUID.randomUUID().toString();
|
||||
MqttClient client;
|
||||
|
||||
try {
|
||||
client = new MqttClient(broker, clientId);
|
||||
MqttConnectOptions connectOptions = new MqttConnectOptions();
|
||||
connectOptions.setCleanSession(true);
|
||||
System.out.println("Connect to broker:"+broker);
|
||||
client.connect(connectOptions);
|
||||
System.out.println("Connected");
|
||||
client.setCallback(new MqttCallback() {
|
||||
@Override
|
||||
public void connectionLost(Throwable throwable) {
|
||||
System.out.println("连接丢失");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void messageArrived(String topic, MqttMessage mqttMessage) throws Exception {
|
||||
System.out.println("消息到达:"+new String(mqttMessage.getPayload())+topic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
|
||||
|
||||
}
|
||||
});
|
||||
} catch (MqttException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
package com.muyu.web.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* mqtt配置类
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class MqttProperties {
|
||||
/**
|
||||
* 节点
|
||||
*/
|
||||
private String broker;
|
||||
|
||||
/**
|
||||
* 主题
|
||||
*/
|
||||
private String topic;
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 节点ID
|
||||
*/
|
||||
private String clientId;
|
||||
/**
|
||||
* 上报级别
|
||||
*/
|
||||
private int qos=0;
|
||||
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
package com.muyu.web.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.muyu.web.domain.model.ServerConfigModel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* 服务器配置类
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TableName(value = "server_config")
|
||||
public class ServerConfig {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(value = "id",type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
|
||||
/**
|
||||
* 主机地址
|
||||
*/
|
||||
private String host;
|
||||
|
||||
/**
|
||||
* 端口号
|
||||
*/
|
||||
private String port;
|
||||
|
||||
/**
|
||||
* 负载地址
|
||||
*/
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* 默认MOTT地址
|
||||
*/
|
||||
private String defaultMqttAddr;
|
||||
|
||||
/**
|
||||
* 默认MQTT主题
|
||||
*/
|
||||
private String defaultMqttTopic;
|
||||
|
||||
/**
|
||||
* 默认MOTT交付级别
|
||||
*/
|
||||
private Integer defaultMqttQos;
|
||||
|
||||
|
||||
public static ServerConfig modeBuild(ServerConfigModel serverConfigModel, Supplier<Long> idKey){
|
||||
return builder()
|
||||
.id(idKey.get())
|
||||
.host(serverConfigModel.getHost())
|
||||
.port(serverConfigModel.getPort())
|
||||
.url(serverConfigModel.getUrl())
|
||||
.defaultMqttAddr(serverConfigModel.getDefaultMqttAddr())
|
||||
.defaultMqttTopic(serverConfigModel.getDefaultMqttTopic())
|
||||
.defaultMqttQos(serverConfigModel.getDefaultMqttQos())
|
||||
.build();
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
package com.muyu.web.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
@TableName("vehicle_info")
|
||||
public class VehicleInfo {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(
|
||||
value = "id",
|
||||
type = IdType.AUTO
|
||||
)
|
||||
private Long id;
|
||||
/**
|
||||
* VIN
|
||||
*/
|
||||
private String vin;
|
||||
/**
|
||||
* VIN
|
||||
*/
|
||||
@TableField(value = "tenant_id", fill = FieldFill.INSERT)
|
||||
private String tenantId;
|
||||
|
||||
/**
|
||||
* 报文模板
|
||||
*/
|
||||
@TableField("message_template_id")
|
||||
private Long messageTemplateId;
|
||||
|
||||
/**
|
||||
* 电池剩余电量
|
||||
*/
|
||||
@TableField("remaining_battery")
|
||||
private BigDecimal remainingBattery;
|
||||
|
||||
/**
|
||||
* 电池电量
|
||||
*/
|
||||
@TableField("battery_level")
|
||||
private BigDecimal batteryLevel;
|
||||
|
||||
/**
|
||||
* 上一次经度
|
||||
*/
|
||||
@TableField("last_longitude")
|
||||
private String lastLongitude;
|
||||
|
||||
/**
|
||||
* 上一次维度
|
||||
*/
|
||||
@TableField("last_latitude")
|
||||
private String lastLatitude;
|
||||
|
||||
/**
|
||||
* 总里程
|
||||
*/
|
||||
@TableField("total_mileage")
|
||||
private BigDecimal totalMileage;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||
private Date createTime;
|
||||
|
||||
|
||||
public static VehicleInfo create(String vin, Supplier<Long>messageTemplateId){
|
||||
return VehicleInfo.builder()
|
||||
.vin(vin)
|
||||
.messageTemplateId(messageTemplateId.get())
|
||||
.createTime(new Date())
|
||||
.totalMileage(BigDecimal.ZERO)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
package com.muyu.web.domain.model;
|
||||
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
Mqtt服务器模型
|
||||
*/
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class MqttServerModel {
|
||||
private static final Logger log=LoggerFactory.getLogger(MqttServerModel.class);
|
||||
|
||||
/**
|
||||
* MQTT服务节点
|
||||
*/
|
||||
private String broker;
|
||||
|
||||
/**
|
||||
* MQTT订阅主题
|
||||
*/
|
||||
private String topic;
|
||||
|
||||
public String getBroker(){
|
||||
log.info("broker:{}",broker);
|
||||
return broker.contains("tcp://")?broker:"tcp://"+broker+":1883";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
package com.muyu.web.domain.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @description: 位置模型
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class PositionModel {
|
||||
/**
|
||||
* 经度
|
||||
*/
|
||||
private String longitude;
|
||||
|
||||
/**
|
||||
* 维度
|
||||
*/
|
||||
private String latitude;
|
||||
|
||||
public static PositionModel strBuild (String positionStr) {
|
||||
String[] split = positionStr.split(",");
|
||||
return PositionModel.builder()
|
||||
.longitude(split[0])
|
||||
.latitude(split[1])
|
||||
.build();
|
||||
}
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
package com.muyu.web.domain.model;
|
||||
|
||||
import com.muyu.web.domain.ServerConfig;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ServerConfigModel {
|
||||
/**
|
||||
* 主机地址
|
||||
*/
|
||||
private String host;
|
||||
|
||||
/**
|
||||
* 端口号
|
||||
*/
|
||||
private String port;
|
||||
/**
|
||||
* 负载地址
|
||||
*/
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* 默认MOTT地址
|
||||
*/
|
||||
private String defaultMqttAddr;
|
||||
|
||||
/**
|
||||
* 默认MQTT主题
|
||||
*/
|
||||
private String defaultMqttTopic;
|
||||
|
||||
/**
|
||||
* 默认MOTT交付级别
|
||||
*/
|
||||
private Integer defaultMqttQos;
|
||||
|
||||
public static ServerConfigModel serverConfigModelBuild(ServerConfig serverConfig){
|
||||
return builder()
|
||||
.host(serverConfig.getHost().trim())
|
||||
.port(serverConfig.getPort())
|
||||
.url(serverConfig.getUrl().trim())
|
||||
.defaultMqttAddr(serverConfig.getDefaultMqttAddr().trim())
|
||||
.defaultMqttTopic(serverConfig.getDefaultMqttTopic().trim())
|
||||
.defaultMqttQos(serverConfig.getDefaultMqttQos())
|
||||
.build();
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
package com.muyu.web.domain.req;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class VehicleConnectionReq {
|
||||
|
||||
@JSONField(name = "vin")
|
||||
private String vin;
|
||||
|
||||
/**
|
||||
* 时间戳
|
||||
*/
|
||||
private String timestamp;
|
||||
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
@JSONField(name = "username")
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 随机字符串
|
||||
*/
|
||||
private String nonce;
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
package com.muyu.web.service;
|
||||
|
||||
public interface VehicleInstanceService {
|
||||
|
||||
|
||||
/**
|
||||
* 车辆客户端初始化
|
||||
*/
|
||||
void vehicleClientStart(String vin);
|
||||
|
||||
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
package com.muyu.web.service.impl;
|
||||
|
||||
import com.muyu.common.core.utils.uuid.UUID;
|
||||
import com.muyu.web.domain.req.VehicleConnectionReq;
|
||||
import com.muyu.web.service.VehicleInstanceService;
|
||||
import com.muyu.web.utils.MD5Util;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Log4j2
|
||||
@Service
|
||||
public class VehicleInstanceServiceImpl implements VehicleInstanceService {
|
||||
@Override
|
||||
public void vehicleClientStart(String vin) {
|
||||
log.info("车辆{},开始上线",vin);
|
||||
String timestamp = String.valueOf(System.currentTimeMillis());
|
||||
VehicleConnectionReq.builder()
|
||||
.vin(vin)
|
||||
.timestamp(timestamp)
|
||||
.userName(MD5Util.encrypted(vin+timestamp))
|
||||
.nonce(MD5Util.encrypted(UUID.randomUUID().toString().replace("-","")))
|
||||
.build();
|
||||
//
|
||||
}
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
package com.muyu.web.utils;
|
||||
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
|
||||
@Log4j2
|
||||
public class MD5Util {
|
||||
private static final Integer SALT_LENGTH = 12;
|
||||
|
||||
/**
|
||||
* 指定数组转化为16进制字符串
|
||||
*/
|
||||
public static String byteToHexString(byte[]b){
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (byte value : b) {
|
||||
String hex = Integer.toHexString(value & 0xFF);
|
||||
if (hex.length()==1){
|
||||
hex='0'+hex;
|
||||
}
|
||||
stringBuilder.append(hex.toUpperCase());
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得加密后的口令
|
||||
*/
|
||||
public static String encrypted(String str){
|
||||
try {
|
||||
byte[]pwd=null;
|
||||
SecureRandom random = new SecureRandom();
|
||||
byte[] salt = new byte[SALT_LENGTH];
|
||||
random.nextBytes(salt);
|
||||
MessageDigest md=null;
|
||||
md = MessageDigest.getInstance("MD5");
|
||||
md.update(salt);
|
||||
md.update(str.getBytes(StandardCharsets.UTF_8));
|
||||
byte[] digest = md.digest();
|
||||
pwd=new byte[digest.length+SALT_LENGTH];
|
||||
System.arraycopy(salt,0,pwd,0,SALT_LENGTH);
|
||||
System.arraycopy(digest,0,pwd,SALT_LENGTH,digest.length);
|
||||
return byteToHexString(pwd);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -7,7 +7,7 @@ nacos:
|
|||
addr: 47.101.53.251:8848
|
||||
user-name: nacos
|
||||
password: nacos
|
||||
namespace: four
|
||||
namespace: yzl
|
||||
|
||||
# Spring
|
||||
spring:
|
||||
|
@ -54,3 +54,5 @@ logging:
|
|||
level:
|
||||
com.muyu.system.mapper: DEBUG
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
<module>saas</module>
|
||||
<module>cloud-modules-vehiclegateway</module>
|
||||
<module>cloud-event</module>
|
||||
<module>cloud-modules-template</module>
|
||||
</modules>
|
||||
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
<modules>
|
||||
<module>saas-common</module>
|
||||
<module>saas-server</module>
|
||||
<module>saas-cache</module>
|
||||
</modules>
|
||||
|
||||
<description>
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
<?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>saas</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>saas-cache</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<description>
|
||||
saas-cache缓存模块
|
||||
</description>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu.common</groupId>
|
||||
<artifactId>saas-common</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu.cache</groupId>
|
||||
<artifactId>cloud-common-cache</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue