Compare commits
8 Commits
ddf4ede829
...
6ba71a95d4
Author | SHA1 | Date |
---|---|---|
|
6ba71a95d4 | |
|
8de7f88912 | |
|
83ab8a27a7 | |
|
d38d77b331 | |
|
bc3053d834 | |
|
4ecdbe3881 | |
|
d586c26468 | |
|
7b36e4b359 |
|
@ -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);
|
||||
|
||||
}
|
|
@ -22,6 +22,7 @@
|
|||
<module>cloud-common-rabbit</module>
|
||||
<module>cloud-common-saas</module>
|
||||
<module>cloud-common-swagger</module>
|
||||
<module>cloud-common-cache</module>
|
||||
</modules>
|
||||
|
||||
<artifactId>cloud-common</artifactId>
|
||||
|
|
|
@ -131,7 +131,18 @@
|
|||
<version>4.2.0</version><!-- 请根据实际情况使用最新的版本 -->
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu.server</groupId>
|
||||
<artifactId>saas-server</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Forest HTTP Client -->
|
||||
<dependency>
|
||||
<groupId>com.dtflys.forest</groupId>
|
||||
<artifactId>forest-spring-boot-starter</artifactId>
|
||||
<version>1.5.36</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -6,6 +6,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||
|
||||
@SpringBootApplication
|
||||
@EnableMyFeignClients
|
||||
|
||||
public class VehicleGatewayApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(VehicleGatewayApplication.class,args);
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
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.common.redis.service.RedisService;
|
||||
import com.muyu.vehicle.config.SelectInstance;
|
||||
import com.muyu.vehicle.domain.InstanceInfo;
|
||||
import com.muyu.vehicle.service.OpenInstance;
|
||||
import com.muyu.vehicle.service.SelectInstance;
|
||||
import com.muyu.vehicle.utils.CreateClient;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
|
@ -19,155 +20,113 @@ import org.springframework.stereotype.Component;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Component
|
||||
@Log4j2
|
||||
/**
|
||||
* 项目启动创建实例
|
||||
*/
|
||||
public class ManageInstance implements ApplicationRunner {
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
/**
|
||||
* ACCESS_KEY_ID
|
||||
*/
|
||||
public static final String ALIBABA_CLOUD_ACCESS_KEY_ID="LTAI5tGabdxedjfCh2uXHNrw";
|
||||
/**
|
||||
* 镜像ID
|
||||
*/
|
||||
public static final String IMAGE_ID = "m-uf6ffgkry85fwu4znr6s";
|
||||
|
||||
/**
|
||||
*ACCESS_KEY_SECRET
|
||||
*/
|
||||
public static final String ACCESS_KEY_SECRET="NHb7wHVpesLW6Axc0bFBs6ThhuNR10";
|
||||
/**
|
||||
* 实例类型
|
||||
*/
|
||||
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";
|
||||
|
||||
|
||||
/**
|
||||
* 镜像ID
|
||||
*/
|
||||
public static final String IMAGE_ID="m-uf6agr9i6g27gj23om34";
|
||||
/**
|
||||
* 实例付费类型
|
||||
*/
|
||||
public static final String INSTANCE_CHARGE_TY = "PostPaid";
|
||||
|
||||
/**
|
||||
* 实例类型
|
||||
*/
|
||||
public static final String INSTANCE_TYPE="ecs.e-c1m1.large";
|
||||
public static List<String> generateInstance() throws Exception {
|
||||
// 创建阿里云ECS客户端
|
||||
// 创建ECS客户端对象,用于后续调用ECS相关API
|
||||
Client client = CreateClient.createClient();
|
||||
// 配置系统盘参数
|
||||
RunInstancesRequest.RunInstancesRequestSystemDisk systemDisk =
|
||||
new RunInstancesRequest.RunInstancesRequestSystemDisk()
|
||||
.setSize("40")
|
||||
.setCategory("cloud_essd");
|
||||
|
||||
/**
|
||||
* 安全组ID
|
||||
*/
|
||||
public static final String SECURITY_GROUP_ID="sg-uf6glo8c4k17szhxu7sk";
|
||||
// 创建创建实例请求对象并设置参数
|
||||
|
||||
/**
|
||||
*交换机ID
|
||||
*/
|
||||
public static final String V_SWITCH_ID="vsw-uf6xy4rbt9ggcz93t6oib";
|
||||
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);
|
||||
|
||||
|
||||
/**
|
||||
* 实例付费类型
|
||||
*/
|
||||
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);
|
||||
//创建运行时选择对象
|
||||
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);
|
||||
return 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());
|
||||
}
|
||||
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());
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
List<String> list = generateInstance();
|
||||
log.info("创建实例成功");
|
||||
log.info("正在加载实例");
|
||||
Thread.sleep(30000);
|
||||
List<InstanceInfo> instanceInfos = SelectInstance.selectInstance(list);
|
||||
log.info("实例信息加载成功");
|
||||
for (InstanceInfo instanceInfo : instanceInfos) {
|
||||
redisService.getCacheObject(instanceInfo.getInstanceId());
|
||||
} log.info("实例信息:{}",instanceInfos);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
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,6 +1,4 @@
|
|||
package com.muyu.vehicle.service;
|
||||
|
||||
|
||||
package com.muyu.vehicle.config;
|
||||
import com.aliyun.ecs20140526.Client;
|
||||
import com.aliyun.ecs20140526.models.DeleteInstancesRequest;
|
||||
import com.aliyun.ecs20140526.models.DescribeInstancesRequest;
|
||||
|
@ -10,42 +8,31 @@ 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.utils.CreateClient;
|
||||
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";
|
||||
public class CloseInstance implements DisposableBean{
|
||||
|
||||
/**
|
||||
*ACCESS_KEY_SECRET
|
||||
* <b>description</b> :
|
||||
* <p>使用AK&SK初始化账号Client</p>
|
||||
* @return Client
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
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();
|
||||
Client client = CreateClient.createClient();
|
||||
|
||||
DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest()
|
||||
.setRegionId("cn-shanghai");
|
||||
|
@ -61,7 +48,7 @@ public class CloseInstance implements DisposableBean {
|
|||
DescribeInstancesResponseBody body = describeInstancesResponse.getBody();
|
||||
|
||||
for (DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance instance : body.getInstances().getInstance()) {
|
||||
if (!instance.getInstanceId().equals("i-uf68jwsbbqq4b4xc893s")){
|
||||
if (!instance.getInstanceId().equals("i-uf68jwsbbqq4b4xc893s")) {
|
||||
list.add(instance.getInstanceId());
|
||||
}
|
||||
}
|
||||
|
@ -79,7 +66,7 @@ public class CloseInstance implements DisposableBean {
|
|||
.setInstanceId(list);
|
||||
|
||||
// 创建运行时选项对象,用于配置运行时的选项参数
|
||||
RuntimeOptions runtime = new RuntimeOptions();
|
||||
RuntimeOptions runtime = new RuntimeOptions();
|
||||
try {
|
||||
// 复制代码运行请自行打印 API 的返回值
|
||||
client.deleteInstancesWithOptions(deleteInstancesRequest, runtime);
|
||||
|
@ -108,3 +95,5 @@ public class CloseInstance implements DisposableBean {
|
|||
delInstance();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package com.muyu.vehicle.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.client.ClientHttpRequestFactory;
|
||||
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
@Configuration
|
||||
public class RestTemplateConfig {
|
||||
|
||||
|
||||
|
||||
@Bean
|
||||
public RestTemplate restTemplate(ClientHttpRequestFactory factory){
|
||||
return new RestTemplate(factory);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Bean
|
||||
public ClientHttpRequestFactory simpleClientHttpRequestFactory() {
|
||||
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
|
||||
//超时设置
|
||||
factory.setReadTimeout(5000);//ms
|
||||
factory.setConnectTimeout(15000);//ms
|
||||
return factory;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package com.muyu.vehicle.config;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
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.teautil.Common;
|
||||
import com.aliyun.teautil.models.RuntimeOptions;
|
||||
import com.muyu.vehicle.domain.InstanceInfo;
|
||||
import com.muyu.vehicle.utils.CreateClient;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 查询实例信息
|
||||
*/
|
||||
|
||||
@Log4j2
|
||||
public class SelectInstance {
|
||||
public static List<InstanceInfo> selectInstance(List<String> instanceIds) throws Exception {
|
||||
// 创建ECS客户端对象,用于后续调用ECS相关API
|
||||
Client client = CreateClient.createClient();
|
||||
ArrayList<InstanceInfo> instanceInfos = new ArrayList<>();// 实例基础信息
|
||||
com.aliyun.ecs20140526.models.DescribeInstancesRequest describeInstancesRequest = new com.aliyun.ecs20140526.models.DescribeInstancesRequest()
|
||||
.setInstanceIds(JSON.toJSONString(instanceIds))
|
||||
.setRegionId("cn-shanghai");
|
||||
// 创建运行时选项对象
|
||||
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();
|
||||
|
||||
ArrayList<InstanceInfo> exampleInformations = new ArrayList<>();
|
||||
for (DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance instance : body.getInstances().getInstance()){
|
||||
InstanceInfo instanceInfo = new InstanceInfo();
|
||||
instanceInfo.setInstanceId(instance.getInstanceId());
|
||||
log.info("实例ID:{}",instanceInfo.getInstanceId());
|
||||
instanceInfo.setStatus(instance.getStatus());
|
||||
log.info("实例状态:{}",instanceInfo.getStatus());
|
||||
instanceInfo.setIpAddress(String.valueOf(instance.getPublicIpAddress().getIpAddress()));
|
||||
log.info("实例IP:{}",instanceInfo.getIpAddress());
|
||||
exampleInformations.add(instanceInfo);
|
||||
}
|
||||
log.info("实例信息:{}",instanceInfos);
|
||||
return instanceInfos;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.muyu.vehicle.controller;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.vehicle.domain.req.VehicleConnectionReq;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@Log4j2
|
||||
public class CarInstanceController {
|
||||
|
||||
|
||||
|
||||
@PostMapping("/receiveMsg/connect")
|
||||
public Result receiveMsg(@RequestBody VehicleConnectionReq vehicleConnectionReq){
|
||||
log.info("=======>"+vehicleConnectionReq);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package com.muyu.vehicle.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* fluxMq配置
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class FluxMqProperties {
|
||||
|
||||
|
||||
/**
|
||||
* 节点
|
||||
*/
|
||||
private String broker;
|
||||
|
||||
/**
|
||||
* 主题
|
||||
*/
|
||||
private String topic;
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 节点ID
|
||||
*/
|
||||
private String clientId;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -4,6 +4,9 @@ import lombok.AllArgsConstructor;
|
|||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 网关实例信息
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package com.muyu.vehicle.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* Mqtt服务器模型
|
||||
* @author YunFei.Du
|
||||
* @date 22:08 2024/5/29
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class MqttServerModel {
|
||||
|
||||
/**
|
||||
* MQTT服务节点
|
||||
*/
|
||||
private String broker;
|
||||
|
||||
/**
|
||||
* MQTT订阅主题
|
||||
*/
|
||||
private String topic;
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package com.muyu.vehicle.domain.req;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 车辆连接信息
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class VehicleConnectionReq {
|
||||
|
||||
private String vehicleVin;
|
||||
|
||||
/**
|
||||
* 时间戳
|
||||
*/
|
||||
|
||||
private String timestamp;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 随机字符串
|
||||
*/
|
||||
private String nonce;
|
||||
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.muyu.vehicle.service;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.vehicle.domain.MqttServerModel;
|
||||
import com.muyu.vehicle.domain.req.VehicleConnectionReq;
|
||||
|
||||
/**
|
||||
* 车辆业务层
|
||||
*/
|
||||
public interface CarInstanceService {
|
||||
|
||||
Result<MqttServerModel> getConnect(VehicleConnectionReq carConnectionReq);
|
||||
|
||||
/**
|
||||
* 车辆初始化
|
||||
*/
|
||||
void carClientStart(String vin);
|
||||
|
||||
}
|
|
@ -1,129 +0,0 @@
|
|||
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());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
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));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.muyu.vehicle.service.impl;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.utils.uuid.UUID;
|
||||
import com.muyu.vehicle.config.RestTemplateConfig;
|
||||
import com.muyu.vehicle.domain.MqttServerModel;
|
||||
import com.muyu.vehicle.domain.req.VehicleConnectionReq;
|
||||
import com.muyu.vehicle.service.CarInstanceService;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 车辆业务实现层
|
||||
*/
|
||||
@Service
|
||||
@Log4j2
|
||||
public class CarInstanceServiceImpl implements CarInstanceService {
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Result<MqttServerModel> getConnect(VehicleConnectionReq carConnectionReq) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void carClientStart(String vin) {
|
||||
String timestamp = String.valueOf(System.currentTimeMillis());
|
||||
VehicleConnectionReq carConnectionReq = VehicleConnectionReq.builder()
|
||||
.vehicleVin(vin)
|
||||
.timestamp(timestamp)
|
||||
.username(vin + timestamp)
|
||||
.nonce(UUID.fastUUID().toString().replaceAll("-", ""))
|
||||
.build();
|
||||
|
||||
//获取网关节点信息
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package com.muyu.vehicle.utils;
|
||||
|
||||
import com.aliyun.ecs20140526.Client;
|
||||
import com.aliyun.teaopenapi.models.Config;
|
||||
|
||||
/**
|
||||
* 创建ECS客户端对象
|
||||
*/
|
||||
public class CreateClient {
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
|
@ -7,10 +7,12 @@ nacos:
|
|||
addr: 47.101.53.251:8848
|
||||
user-name: nacos
|
||||
password: nacos
|
||||
namespace: four
|
||||
namespace: sx
|
||||
|
||||
# Spring
|
||||
spring:
|
||||
main:
|
||||
allow-bean-definition-overriding: true
|
||||
application:
|
||||
# 应用名称
|
||||
name: cloud-vehicleGateway
|
||||
|
|
|
@ -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>
|
|
@ -0,0 +1,32 @@
|
|||
package com.muyu.cache;
|
||||
|
||||
import com.muyu.common.domain.database.ElectronicFence;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @Author YuPing
|
||||
* @Description 电子围栏缓存
|
||||
* @Version 1.0
|
||||
* @Data 2024-09-29 20:53:46
|
||||
*/
|
||||
@Component
|
||||
public class ElectronicFenceCacheService extends CacheAbsBasic<String, ElectronicFence>{
|
||||
/**
|
||||
* key前缀
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String keyPre() {
|
||||
return "electronicFence";
|
||||
}
|
||||
|
||||
/**
|
||||
* 解码
|
||||
* @param key 编码key
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String decode(String key) {
|
||||
return key.replace(keyPre(), "");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package com.muyu.cache;
|
||||
|
||||
import com.muyu.common.domain.database.ElectronicFenceGroup;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @Author YuPing
|
||||
* @Description 围栏组缓存
|
||||
* @Version 1.0
|
||||
* @Data 2024-09-29 20:57:46
|
||||
*/
|
||||
@Component
|
||||
public class ElectronicFenceGroupCacheService extends CacheAbsBasic<String, ElectronicFenceGroup>{
|
||||
/**
|
||||
* key前缀
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String keyPre() {
|
||||
return "electronicFenceGroup";
|
||||
}
|
||||
|
||||
/**
|
||||
* 解码
|
||||
* @param key 编码key
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String decode(String key) {
|
||||
return key.replace(keyPre(), "");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package com.muyu.cache;
|
||||
|
||||
import com.muyu.common.domain.Enterprise;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author yuping
|
||||
* @package com.muyu.cache
|
||||
* @name EnterpriseCacheService
|
||||
* @date 2024/9/29 20:21 企业缓存
|
||||
*/
|
||||
@Component
|
||||
public class EnterpriseCacheService extends CacheAbsBasic<String, Enterprise>{
|
||||
/**
|
||||
* 缓存前缀
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String keyPre() {
|
||||
return "enterprise:info:";
|
||||
}
|
||||
|
||||
/**
|
||||
* 解码
|
||||
* @param key 编码key
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String decode(String key) {
|
||||
return key.replace(keyPre(), "");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package com.muyu.cache;
|
||||
|
||||
import com.muyu.common.domain.SysCarFault;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @Author YuPing
|
||||
* @Description 故障缓存
|
||||
* @Version 1.0
|
||||
* @Data 2024-09-29 21:10:31
|
||||
*/
|
||||
@Component
|
||||
public class SysCarFaultCacheService extends CacheAbsBasic<String, SysCarFault>{
|
||||
/**
|
||||
* 缓存前缀
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String keyPre() {
|
||||
return "sysCarFault";
|
||||
}
|
||||
|
||||
/**
|
||||
* 解码
|
||||
* @param key 编码key
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String decode(String key) {
|
||||
return key.replace(keyPre(), "");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package com.muyu.cache;
|
||||
|
||||
import com.muyu.common.domain.SysCarFaultMessage;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @Author YuPing
|
||||
* @Description 站内信缓存
|
||||
* @Version 1.0
|
||||
* @Data 2024-09-29 21:13:19
|
||||
*/
|
||||
@Component
|
||||
public class SysCarFaultMessageCacheService extends CacheAbsBasic<String, SysCarFaultMessage>{
|
||||
@Override
|
||||
public String keyPre() {
|
||||
return "sysCarFaultMessage";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String decode(String key) {
|
||||
return key.replace(keyPre(), "");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
com.muyu.cache.ElectronicFenceCacheService
|
||||
com.muyu.cache.ElectronicFenceGroupCacheService
|
||||
com.muyu.cache.EnterpriseCacheService
|
||||
com.muyu.cache.SysCarFaultCacheService
|
||||
com.muyu.cache.SysCarFaultMessageCacheService
|
|
@ -29,10 +29,10 @@ public class DataType implements Serializable{
|
|||
* 数据类型ID
|
||||
*/
|
||||
@TableId(value = "data_type_id",type = IdType.AUTO)
|
||||
private Integer DataTypeId;
|
||||
private Integer dataTypeId;
|
||||
/**
|
||||
* 数据类型名称
|
||||
*/
|
||||
private String DataTypeName;
|
||||
private String dataTypeName;
|
||||
|
||||
}
|
||||
|
|
|
@ -24,6 +24,12 @@
|
|||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>saas-cache</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu.common</groupId>
|
||||
<artifactId>saas-common</artifactId>
|
||||
|
|
|
@ -14,6 +14,4 @@ import org.apache.ibatis.annotations.Mapper;
|
|||
@Mapper
|
||||
public interface MessageTemplateTypeMapper extends BaseMapper<MessageTemplateType> {
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.muyu.server.service.impl;
|
|||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.cache.ElectronicFenceGroupCacheService;
|
||||
import com.muyu.common.core.utils.StringUtils;
|
||||
import com.muyu.common.domain.database.ElectronicFenceGroup;
|
||||
import com.muyu.common.domain.database.FenceGroupMid;
|
||||
|
@ -38,6 +39,9 @@ public class ElectronicFenceGroupServiceImpl extends ServiceImpl<ElectronicFence
|
|||
@Autowired
|
||||
private FenceGroupMidService fenceGroupMidService;
|
||||
|
||||
@Autowired
|
||||
private ElectronicFenceGroupCacheService electronicFenceGroupCacheService;
|
||||
|
||||
@Override
|
||||
public List<ElectronicFenceGroup> selectGroupList(ElectronicFenceGroupListReq req) {
|
||||
|
||||
|
@ -55,6 +59,10 @@ public class ElectronicFenceGroupServiceImpl extends ServiceImpl<ElectronicFence
|
|||
);
|
||||
List<ElectronicFenceGroup> list = this.list(queryWrapper);
|
||||
|
||||
list.forEach(electronicFenceGroup -> {
|
||||
electronicFenceGroupCacheService.put(electronicFenceGroup.getId().toString(),electronicFenceGroup);
|
||||
});
|
||||
|
||||
return list;
|
||||
|
||||
}
|
||||
|
@ -77,6 +85,8 @@ public class ElectronicFenceGroupServiceImpl extends ServiceImpl<ElectronicFence
|
|||
electronicFenceGroupResp.setElectronicFenceRespList(electronicFenceRespList);
|
||||
}
|
||||
|
||||
electronicFenceGroupCacheService.put(electronicFenceGroup.getId().toString(),electronicFenceGroup);
|
||||
|
||||
|
||||
return electronicFenceGroupResp;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.cache.ElectronicFenceCacheService;
|
||||
import com.muyu.common.core.utils.StringUtils;
|
||||
import com.muyu.common.domain.database.ElectronicFence;
|
||||
import com.muyu.common.domain.req.ElectroicFenceAddReq;
|
||||
|
@ -31,6 +32,9 @@ public class ElectronicFenceServiceImpl extends ServiceImpl<ElectronicFenceMappe
|
|||
@Autowired
|
||||
private ElectronicFenceMapper electronicFenceMapper;
|
||||
|
||||
@Autowired
|
||||
private ElectronicFenceCacheService electronicFenceCacheService;
|
||||
|
||||
|
||||
@Override
|
||||
public List<ElectronicFenceResp> fenceselectList(ElectroicFenceListReq electroicFenceListReq) {
|
||||
|
@ -38,40 +42,44 @@ public class ElectronicFenceServiceImpl extends ServiceImpl<ElectronicFenceMappe
|
|||
LambdaQueryWrapper<ElectronicFence> queryWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
queryWrapper.like(
|
||||
StringUtils.isNotNull(electroicFenceListReq.getName()),ElectronicFence::getName, electroicFenceListReq.getName()
|
||||
StringUtils.isNotEmpty(electroicFenceListReq.getName()),ElectronicFence::getName, electroicFenceListReq.getName()
|
||||
);
|
||||
queryWrapper.eq(
|
||||
StringUtils.isNotEmpty(electroicFenceListReq.getFenceType()),ElectronicFence::getFenceType, electroicFenceListReq.getFenceType()
|
||||
);
|
||||
queryWrapper.eq(
|
||||
StringUtils.isNotEmpty(electroicFenceListReq.getFenceType()),ElectronicFence::getFenceType, electroicFenceListReq.getFenceType()
|
||||
);
|
||||
queryWrapper.eq(
|
||||
StringUtils.isNotEmpty(electroicFenceListReq.getStatus()),ElectronicFence::getStatus, electroicFenceListReq.getStatus()
|
||||
);
|
||||
List<ElectronicFence> list = this.list(queryWrapper);
|
||||
|
||||
list.forEach(electronicFence -> {
|
||||
electronicFenceCacheService.put(electronicFence.getId().toString(),electronicFence);
|
||||
});
|
||||
|
||||
return list.stream().map(ElectronicFence::bullerResp).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void AddFence(ElectroicFenceAddReq electroicFenceAddReq) {
|
||||
|
||||
|
||||
|
||||
electronicFenceMapper.insert(ElectronicFence.buildElectroicAdd(electroicFenceAddReq));
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElectronicFence findElectronicByid(Long id) {
|
||||
|
||||
ElectronicFence electronicFence = electronicFenceMapper.selectById(id);
|
||||
|
||||
electronicFenceCacheService.put(id.toString(),electronicFence);
|
||||
|
||||
return electronicFence;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delElectronById(Long id) {
|
||||
|
||||
electronicFenceCacheService.remove(id.toString());
|
||||
|
||||
electronicFenceMapper.deleteById(id);
|
||||
}
|
||||
|
||||
|
@ -118,6 +126,10 @@ public class ElectronicFenceServiceImpl extends ServiceImpl<ElectronicFenceMappe
|
|||
|
||||
List<ElectronicFence> list = this.list(wrapper);
|
||||
|
||||
list.forEach(electronicFence -> {
|
||||
electronicFenceCacheService.put(electronicFence.getId().toString(),electronicFence);
|
||||
});
|
||||
|
||||
return list.stream().map(ElectronicFence::bullerResp).toList();
|
||||
}
|
||||
|
||||
|
@ -129,6 +141,8 @@ public class ElectronicFenceServiceImpl extends ServiceImpl<ElectronicFenceMappe
|
|||
|
||||
List<ElectronicFence> fenceList = this.list(queryWrapper);
|
||||
|
||||
electronicFenceCacheService.remove(name);
|
||||
|
||||
if (fenceList.size()>0){
|
||||
throw new RuntimeException("电子围栏名不能重复");
|
||||
}
|
||||
|
@ -141,6 +155,9 @@ public class ElectronicFenceServiceImpl extends ServiceImpl<ElectronicFenceMappe
|
|||
|
||||
List<ElectronicFence> electronicFenceList = this.list(Wrappers.<ElectronicFence>lambdaQuery().in(ElectronicFence::getId, ids));
|
||||
|
||||
electronicFenceList.forEach(electronicFence -> {
|
||||
electronicFenceCacheService.put(electronicFence.getId().toString(),electronicFence);
|
||||
});
|
||||
|
||||
return electronicFenceList.stream().map(ElectronicFence::bullerResp).toList();
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.muyu.server.service.impl;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import com.muyu.cache.EnterpriseCacheService;
|
||||
import com.muyu.common.domain.Enterprise;
|
||||
import com.muyu.common.util.PageUtils;
|
||||
import com.muyu.server.mapper.EnterpriseDao;
|
||||
|
@ -22,6 +23,9 @@ public class EnterpriseServiceImpl implements EnterpriseService {
|
|||
@Autowired
|
||||
private EnterpriseDao enterpriseDao;
|
||||
|
||||
@Autowired
|
||||
private EnterpriseCacheService enterpriseCacheService;
|
||||
|
||||
/**
|
||||
* 分页查询企业运营信息
|
||||
* @param param
|
||||
|
@ -49,6 +53,9 @@ public class EnterpriseServiceImpl implements EnterpriseService {
|
|||
@Override
|
||||
public int insert(Enterprise enterprise) {
|
||||
int rows = enterpriseDao.insert(enterprise);
|
||||
if (rows > 0){
|
||||
enterpriseCacheService.put(String.valueOf(enterprise.getEnterpriseId()), enterprise);
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
|
@ -61,6 +68,12 @@ public class EnterpriseServiceImpl implements EnterpriseService {
|
|||
@Override
|
||||
public HashMap searchById(int enterpriseId) {
|
||||
HashMap map = enterpriseDao.searchById(enterpriseId);
|
||||
if (map != null){
|
||||
Enterprise enterprise = enterpriseCacheService.get(String.valueOf(enterpriseId));
|
||||
if (enterprise != null){
|
||||
map.put("enterprise", enterprise);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
|
@ -73,6 +86,9 @@ public class EnterpriseServiceImpl implements EnterpriseService {
|
|||
@Override
|
||||
public int updateEnterprise(Enterprise enterprise) {
|
||||
int rows = enterpriseDao.updateEnterprise(enterprise);
|
||||
if (rows > 0){
|
||||
enterpriseCacheService.put(String.valueOf(enterprise.getEnterpriseId()), enterprise);
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
|
@ -90,6 +106,7 @@ public class EnterpriseServiceImpl implements EnterpriseService {
|
|||
|
||||
Integer[] idList = Arrays.asList(ids).toArray(new Integer[0]);
|
||||
int rows = enterpriseDao.deleteByIds(idList);
|
||||
enterpriseCacheService.remove(String.valueOf(idList));
|
||||
return rows;
|
||||
|
||||
}
|
||||
|
|
|
@ -3,9 +3,11 @@ package com.muyu.server.service.impl;
|
|||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.cache.SysCarFaultMessageCacheService;
|
||||
import com.muyu.common.domain.SysCarFaultMessage;
|
||||
import com.muyu.server.mapper.SysCarFaultMessageMapper;
|
||||
import com.muyu.server.service.SysCarFaultMessageService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -20,6 +22,11 @@ import java.util.List;
|
|||
@Service
|
||||
public class SysCarFaultMessageServiceImpl extends ServiceImpl<SysCarFaultMessageMapper, SysCarFaultMessage> implements SysCarFaultMessageService {
|
||||
|
||||
|
||||
@Autowired
|
||||
private SysCarFaultMessageCacheService sysCarFaultMessageCacheService;
|
||||
|
||||
|
||||
/**
|
||||
* 查询故障消息列表
|
||||
* @param sysCarFaultMessage
|
||||
|
@ -28,7 +35,14 @@ public class SysCarFaultMessageServiceImpl extends ServiceImpl<SysCarFaultMessag
|
|||
@Override
|
||||
public List<SysCarFaultMessage> selectSysCarFaultMessageList(SysCarFaultMessage sysCarFaultMessage) {
|
||||
LambdaQueryWrapper<SysCarFaultMessage> wrapper = new LambdaQueryWrapper<>();
|
||||
return baseMapper.selectList(wrapper);
|
||||
|
||||
List<SysCarFaultMessage> list = baseMapper.selectList(wrapper);
|
||||
|
||||
list.forEach(item->{
|
||||
sysCarFaultMessageCacheService.put(item.getContent(),item);
|
||||
});
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -37,7 +51,14 @@ public class SysCarFaultMessageServiceImpl extends ServiceImpl<SysCarFaultMessag
|
|||
*/
|
||||
@Override
|
||||
public List<SysCarFaultMessage> listStatusOnt( ) {
|
||||
return baseMapper.listStatusOnt();
|
||||
|
||||
List<SysCarFaultMessage> list = baseMapper.listStatusOnt();
|
||||
|
||||
list.forEach(item->{
|
||||
sysCarFaultMessageCacheService.put(item.getContent(),item);
|
||||
});
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -46,6 +67,13 @@ public class SysCarFaultMessageServiceImpl extends ServiceImpl<SysCarFaultMessag
|
|||
*/
|
||||
@Override
|
||||
public List<SysCarFaultMessage> listStatusTwo( ) {
|
||||
return baseMapper.listStatusTwo();
|
||||
|
||||
List<SysCarFaultMessage> list = baseMapper.listStatusTwo();
|
||||
|
||||
list.forEach(item->{
|
||||
sysCarFaultMessageCacheService.put(item.getContent(),item);
|
||||
});
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.muyu.server.service.impl;
|
|||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.cache.SysCarFaultCacheService;
|
||||
import com.muyu.common.core.utils.StringUtils;
|
||||
import com.muyu.common.domain.SysCarFault;
|
||||
import com.muyu.server.mapper.SysCarFaultMapper;
|
||||
|
@ -27,6 +28,9 @@ public class SysCarFaultServiceImpl
|
|||
@Autowired
|
||||
private SysCarFaultMapper mapper;
|
||||
|
||||
@Autowired
|
||||
private SysCarFaultCacheService sysCarFaultCacheService;
|
||||
|
||||
/**
|
||||
* 精确查询车辆故障管理
|
||||
*
|
||||
|
@ -39,6 +43,9 @@ public class SysCarFaultServiceImpl
|
|||
LambdaQueryWrapper<SysCarFault> queryWrapper = new LambdaQueryWrapper<>();
|
||||
Assert.notNull(id, "id不可为空");
|
||||
queryWrapper.eq(SysCarFault::getId, id);
|
||||
|
||||
sysCarFaultCacheService.put(id.toString(),this.getOne(queryWrapper));
|
||||
|
||||
return this.getOne(queryWrapper);
|
||||
}
|
||||
|
||||
|
@ -70,7 +77,14 @@ public class SysCarFaultServiceImpl
|
|||
if (sysCarFault.getCarTypeId()!=null){
|
||||
queryWrapper.eq(SysCarFault::getCarTypeId,sysCarFault.getTypeId());
|
||||
}
|
||||
return this.list(queryWrapper);
|
||||
|
||||
List<SysCarFault> list = this.list(queryWrapper);
|
||||
|
||||
list.forEach(sysCarFault1 -> {
|
||||
sysCarFaultCacheService.put(sysCarFault1.getId().toString(),sysCarFault1);
|
||||
});
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
|
@ -83,6 +97,9 @@ public class SysCarFaultServiceImpl
|
|||
|
||||
@Override
|
||||
public SysCarFault selectFaultByFaultCode(String faultCode) {
|
||||
|
||||
sysCarFaultCacheService.put(faultCode,mapper.selectFaultByFaultCode(faultCode));
|
||||
|
||||
return mapper.selectFaultByFaultCode(faultCode);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue