diff --git a/cloud-modules/cloud-modules-enterprise/enterpise-common/src/main/java/com/muyu/domain/MessageTemplate.java b/cloud-modules/cloud-modules-enterprise/enterpise-common/src/main/java/com/muyu/domain/MessageTemplate.java index 46da1d1..7f9c810 100644 --- a/cloud-modules/cloud-modules-enterprise/enterpise-common/src/main/java/com/muyu/domain/MessageTemplate.java +++ b/cloud-modules/cloud-modules-enterprise/enterpise-common/src/main/java/com/muyu/domain/MessageTemplate.java @@ -3,6 +3,7 @@ package com.muyu.domain; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; +import com.muyu.domain.req.MessageTemplateAddReq; import com.muyu.common.core.web.domain.BaseEntity; import com.muyu.domain.req.MessageTemplateAddReq; import io.swagger.v3.oas.annotations.media.Schema; diff --git a/cloud-modules/cloud-modules-enterprise/enterpise-common/src/main/java/com/muyu/domain/SysCar.java b/cloud-modules/cloud-modules-enterprise/enterpise-common/src/main/java/com/muyu/domain/SysCar.java index 4a5017c..63b0a42 100644 --- a/cloud-modules/cloud-modules-enterprise/enterpise-common/src/main/java/com/muyu/domain/SysCar.java +++ b/cloud-modules/cloud-modules-enterprise/enterpise-common/src/main/java/com/muyu/domain/SysCar.java @@ -17,7 +17,7 @@ import org.apache.commons.lang3.builder.ToStringStyle; /** * 车辆基础信息对象 sys_car * - * @author Li HD + * @author LiHD * @date 2024-09-18 */ diff --git a/cloud-modules/cloud-modules-enterprise/enterpise-common/src/main/java/com/muyu/domain/SysCarType.java b/cloud-modules/cloud-modules-enterprise/enterpise-common/src/main/java/com/muyu/domain/SysCarType.java index c11eaa5..28e9c00 100644 --- a/cloud-modules/cloud-modules-enterprise/enterpise-common/src/main/java/com/muyu/domain/SysCarType.java +++ b/cloud-modules/cloud-modules-enterprise/enterpise-common/src/main/java/com/muyu/domain/SysCarType.java @@ -5,19 +5,18 @@ import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.muyu.common.core.web.domain.BaseEntity; import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.tags.Tag; import lombok.AllArgsConstructor; import lombok.Data; +import io.swagger.v3.oas.annotations.tags.Tag; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; /** - * 车辆类型实体类 - * *@ClassName SysCarType - * * @Description TODO - * * @Author Li HD - * * @Date 2024/9/22 15:48 + * @ClassName SysCarType + * @Description TODO + * @Author Li HD + * @Date 2024/9/22 15:48 */ @EqualsAndHashCode(callSuper = true) @Data diff --git a/cloud-modules/cloud-modules-enterprise/enterpise-common/src/main/java/com/muyu/domain/req/MessageTemplateAddReq.java b/cloud-modules/cloud-modules-enterprise/enterpise-common/src/main/java/com/muyu/domain/req/MessageTemplateAddReq.java index fb78dc3..f340141 100644 --- a/cloud-modules/cloud-modules-enterprise/enterpise-common/src/main/java/com/muyu/domain/req/MessageTemplateAddReq.java +++ b/cloud-modules/cloud-modules-enterprise/enterpise-common/src/main/java/com/muyu/domain/req/MessageTemplateAddReq.java @@ -11,7 +11,7 @@ import lombok.NoArgsConstructor; /** * @ClassName MessageTemplateAddReq * @Description TODO - * @Author Li HD + * @Author LiHD * @Date 2024/9/19 */ diff --git a/cloud-modules/cloud-modules-enterprise/enterpise-common/src/main/java/com/muyu/domain/req/MessageValueAddReq.java b/cloud-modules/cloud-modules-enterprise/enterpise-common/src/main/java/com/muyu/domain/req/MessageValueAddReq.java index 8d7917d..e23d47b 100644 --- a/cloud-modules/cloud-modules-enterprise/enterpise-common/src/main/java/com/muyu/domain/req/MessageValueAddReq.java +++ b/cloud-modules/cloud-modules-enterprise/enterpise-common/src/main/java/com/muyu/domain/req/MessageValueAddReq.java @@ -13,7 +13,7 @@ import lombok.NoArgsConstructor; /** * @ClassName MessageValueAddReq * @Description TODO - * @Author Li HD + * @Author LiHD * @Date 2024/9/19 */ diff --git a/cloud-modules/cloud-modules-enterprise/enterpise-common/src/main/java/com/muyu/domain/req/MessageValueReq.java b/cloud-modules/cloud-modules-enterprise/enterpise-common/src/main/java/com/muyu/domain/req/MessageValueReq.java index e51e0d9..51854dc 100644 --- a/cloud-modules/cloud-modules-enterprise/enterpise-common/src/main/java/com/muyu/domain/req/MessageValueReq.java +++ b/cloud-modules/cloud-modules-enterprise/enterpise-common/src/main/java/com/muyu/domain/req/MessageValueReq.java @@ -11,7 +11,7 @@ import lombok.NoArgsConstructor; /** * @ClassName MessageValueReq * @Description TODO - * @Author Li HD + * @Author LiHD * @Date 2024/9/19 */ diff --git a/cloud-modules/cloud-modules-enterprise/enterpise-common/src/main/java/com/muyu/domain/req/SysCar.java b/cloud-modules/cloud-modules-enterprise/enterpise-common/src/main/java/com/muyu/domain/req/SysCar.java index e15a912..142b116 100644 --- a/cloud-modules/cloud-modules-enterprise/enterpise-common/src/main/java/com/muyu/domain/req/SysCar.java +++ b/cloud-modules/cloud-modules-enterprise/enterpise-common/src/main/java/com/muyu/domain/req/SysCar.java @@ -17,7 +17,7 @@ import org.apache.commons.lang3.builder.ToStringStyle; /** * 车辆基础信息对象 sys_car * - * @author Li HD + * @author LiHD * @date 2024-09-18 */ diff --git a/cloud-modules/cloud-modules-enterprise/enterpise-common/src/main/java/com/muyu/domain/resp/MessageTemplateListResp.java b/cloud-modules/cloud-modules-enterprise/enterpise-common/src/main/java/com/muyu/domain/resp/MessageTemplateListResp.java index 388a58e..0145f2a 100644 --- a/cloud-modules/cloud-modules-enterprise/enterpise-common/src/main/java/com/muyu/domain/resp/MessageTemplateListResp.java +++ b/cloud-modules/cloud-modules-enterprise/enterpise-common/src/main/java/com/muyu/domain/resp/MessageTemplateListResp.java @@ -14,7 +14,7 @@ import lombok.NoArgsConstructor; /** * @ClassName MessageTemplateListResp * @Description TODO - * @Author Li HD + * @Author LiHD * @Date 2024/9/19 */ diff --git a/cloud-modules/cloud-modules-enterprise/enterpise-common/src/main/java/com/muyu/domain/resp/MessageValueListResp.java b/cloud-modules/cloud-modules-enterprise/enterpise-common/src/main/java/com/muyu/domain/resp/MessageValueListResp.java index a613905..ca09dc6 100644 --- a/cloud-modules/cloud-modules-enterprise/enterpise-common/src/main/java/com/muyu/domain/resp/MessageValueListResp.java +++ b/cloud-modules/cloud-modules-enterprise/enterpise-common/src/main/java/com/muyu/domain/resp/MessageValueListResp.java @@ -14,7 +14,7 @@ import lombok.NoArgsConstructor; /** * @ClassName MessageValueListResp * @Description TODO - * @Author Li HD + * @Author LiHD * @Date 2024/9/19 */ diff --git a/cloud-modules/cloud-modules-enterprise/enterpise-common/src/main/java/com/muyu/domain/resp/SysCarResp.java b/cloud-modules/cloud-modules-enterprise/enterpise-common/src/main/java/com/muyu/domain/resp/SysCarResp.java index 33f046f..19c61e5 100644 --- a/cloud-modules/cloud-modules-enterprise/enterpise-common/src/main/java/com/muyu/domain/resp/SysCarResp.java +++ b/cloud-modules/cloud-modules-enterprise/enterpise-common/src/main/java/com/muyu/domain/resp/SysCarResp.java @@ -13,7 +13,7 @@ import lombok.NoArgsConstructor; /** * @ClassName SysCarResp * @Description TODO - * @Author Li HD + * @Author LiHD * @Date 2024/9/25 20:14 */ diff --git a/cloud-modules/cloud-modules-enterprise/enterpise-service/src/main/java/com/muyu/controller/SysCarController.java b/cloud-modules/cloud-modules-enterprise/enterpise-service/src/main/java/com/muyu/controller/SysCarController.java index d6a7af7..3aba980 100644 --- a/cloud-modules/cloud-modules-enterprise/enterpise-service/src/main/java/com/muyu/controller/SysCarController.java +++ b/cloud-modules/cloud-modules-enterprise/enterpise-service/src/main/java/com/muyu/controller/SysCarController.java @@ -18,7 +18,7 @@ import java.util.List; /** * 车辆基础信息Controller - * @author Li HD + * @author LiHD * @date 2024-09-18 */ @RestController diff --git a/cloud-modules/cloud-modules-enterprise/enterpise-service/src/main/java/com/muyu/mapper/SysCarMapper.java b/cloud-modules/cloud-modules-enterprise/enterpise-service/src/main/java/com/muyu/mapper/SysCarMapper.java index a3a19b4..5d18dba 100644 --- a/cloud-modules/cloud-modules-enterprise/enterpise-service/src/main/java/com/muyu/mapper/SysCarMapper.java +++ b/cloud-modules/cloud-modules-enterprise/enterpise-service/src/main/java/com/muyu/mapper/SysCarMapper.java @@ -9,7 +9,7 @@ import java.util.List; /** * 车辆基础信息Mapper接口 - * @author Li HD + * @author LiHD * @date 2024-09-18 */ @Mapper diff --git a/cloud-modules/cloud-modules-enterprise/enterpise-service/src/main/java/com/muyu/service/SysCarService.java b/cloud-modules/cloud-modules-enterprise/enterpise-service/src/main/java/com/muyu/service/SysCarService.java index 3f331f3..4d012b9 100644 --- a/cloud-modules/cloud-modules-enterprise/enterpise-service/src/main/java/com/muyu/service/SysCarService.java +++ b/cloud-modules/cloud-modules-enterprise/enterpise-service/src/main/java/com/muyu/service/SysCarService.java @@ -8,7 +8,7 @@ import java.util.List; /** * 车辆基础信息Service接口 - * @author Li HD + * @author LiHD * @date 2024-09-18 */ public interface SysCarService extends IService { diff --git a/cloud-modules/cloud-modules-enterprise/enterpise-service/src/main/java/com/muyu/service/impl/SysCarServiceImpl.java b/cloud-modules/cloud-modules-enterprise/enterpise-service/src/main/java/com/muyu/service/impl/SysCarServiceImpl.java index 8f5cee4..c67bb8e 100644 --- a/cloud-modules/cloud-modules-enterprise/enterpise-service/src/main/java/com/muyu/service/impl/SysCarServiceImpl.java +++ b/cloud-modules/cloud-modules-enterprise/enterpise-service/src/main/java/com/muyu/service/impl/SysCarServiceImpl.java @@ -14,7 +14,7 @@ import java.util.List; /** * 车辆基础信息Service业务层处理 - * @author Li HD + * @author LiHD * @date 2024-09-18 */ @Service diff --git a/cloud-modules/cloud-modules-vehicleGateway/pom.xml b/cloud-modules/cloud-modules-vehicleGateway/pom.xml new file mode 100644 index 0000000..23c665e --- /dev/null +++ b/cloud-modules/cloud-modules-vehicleGateway/pom.xml @@ -0,0 +1,162 @@ + + + 4.0.0 + + com.muyu + cloud-modules + 3.6.3 + + + cloud-modules-vehicleGateway + + + cloud-modules-vehicleGateway车辆网关模块 + + + + 17 + 17 + UTF-8 + 1.2.5 + + + + + + + org.eclipse.paho + org.eclipse.paho.client.mqttv3 + ${mqtt.version} + + + + + com.aliyun + ecs20140526 + 5.1.8 + + + com.aliyun + tea-openapi + 0.3.2 + + + com.aliyun + tea-console + 0.0.1 + + + com.aliyun + tea-util + 0.2.21 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-config + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-sentinel + + + + + org.springframework.boot + spring-boot-starter-actuator + + + + + com.mysql + mysql-connector-j + + + + + com.muyu + cloud-common-datasource + + + + + com.muyu + cloud-common-datascope + + + + + com.muyu + cloud-common-log + + + + + com.muyu + cloud-common-api-doc + + + + + + ${project.artifactId} + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + + + + + + diff --git a/cloud-modules/cloud-modules-vehicleGateway/src/main/java/com/muyu/CloudVehicleGatewayApplication.java b/cloud-modules/cloud-modules-vehicleGateway/src/main/java/com/muyu/CloudVehicleGatewayApplication.java new file mode 100644 index 0000000..de05aa6 --- /dev/null +++ b/cloud-modules/cloud-modules-vehicleGateway/src/main/java/com/muyu/CloudVehicleGatewayApplication.java @@ -0,0 +1,22 @@ +package com.muyu; + +import com.muyu.common.security.annotation.EnableCustomConfig; +import com.muyu.common.security.annotation.EnableMyFeignClients; +import lombok.extern.log4j.Log4j2; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * 车辆网关启动程序 + * + * @author LiHD + */ +@Log4j2 +@EnableCustomConfig +@EnableMyFeignClients +@SpringBootApplication +public class CloudVehicleGatewayApplication { + public static void main(String[] args) { + SpringApplication.run(CloudVehicleGatewayApplication.class,args); + } +} diff --git a/cloud-modules/cloud-modules-vehicleGateway/src/main/java/com/muyu/vehicleGateway/ClearInstance.java b/cloud-modules/cloud-modules-vehicleGateway/src/main/java/com/muyu/vehicleGateway/ClearInstance.java new file mode 100644 index 0000000..11ac2cb --- /dev/null +++ b/cloud-modules/cloud-modules-vehicleGateway/src/main/java/com/muyu/vehicleGateway/ClearInstance.java @@ -0,0 +1,108 @@ +package com.muyu.vehicleGateway; + +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.teautil.models.RuntimeOptions; +import lombok.extern.log4j.Log4j2; +import org.springframework.beans.factory.DisposableBean; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; + +/** + * 清除阿里云ECS实例 + * @ClassName ClearInstance + * @author LiHD + * @Date 2024/9/28 22:29 + */ +@Component +@Log4j2 +public class ClearInstance implements DisposableBean { + + /** + * description : + *

使用AK&SK初始化账号Client

+ * @return Client + * + * @throws Exception + */ + public static com.aliyun.ecs20140526.Client createClient() throws Exception { + // 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。 + // 建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378657.html。 + com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config() + // 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。 + .setAccessKeyId("LTAI5tM4LSerzWQ9wUPXgybq") + // 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。 + .setAccessKeySecret("hkiPr0QwkKMZauhXucgg1SDriXUW0Q"); + // Endpoint 请参考 https://api.aliyun.com/product/Ecs + config.endpoint = "ecs.cn-beijing.aliyuncs.com"; + return new com.aliyun.ecs20140526.Client(config); + } + + public static void clearInstance() throws Exception { + + // 创建ECS客户端对象,用于后续调用ECS相关API + com.aliyun.ecs20140526.Client client = ClearInstance.createClient(); + + DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest() + .setRegionId("cn-beijing"); + + //创建运行时选择对象,用于配置运行时的选项参数 + RuntimeOptions runtimeOptions = new RuntimeOptions(); + + //获取实例列表 + DescribeInstancesResponse describeInstancesResponse = client.describeInstancesWithOptions(describeInstancesRequest, runtimeOptions); + + //提取实例ID集合 + ArrayList list = new ArrayList<>(); + DescribeInstancesResponseBody body = describeInstancesResponse.getBody(); + + for (DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance instance : body.getInstances().getInstance()) { + list.add(instance.getInstanceId()); + } + log.info("Instance IDs: " + list); + // 创建删除实例请求对象,并设置请求参数 + com.aliyun.ecs20140526.models.DeleteInstancesRequest deleteInstancesRequest = new com.aliyun.ecs20140526.models.DeleteInstancesRequest() + // 设置地域ID,指定删除实例的地域 + .setRegionId("cn-beijing") + // 设置DryRun为true,用于验证请求是否可以成功,但不实际执行删除操作 + .setDryRun(false) + // 设置Force为true,表示即使实例有正在运行的任务,也强制删除实例 + .setForce(true) + // 设置TerminateSubscription为true,表示删除按订阅付费的实例时终止订阅 + .setTerminateSubscription(true) + .setInstanceId(list); + + // 创建运行时选项对象,用于配置运行时的选项参数 + com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions(); + try { + // 复制代码运行请自行打印 API 的返回值 + client.deleteInstancesWithOptions(deleteInstancesRequest, runtime); + } catch (TeaException error) { + // 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。 + // 错误 message + System.out.println(error.getMessage()); + // 诊断地址 + System.out.println(error.getData().get("Recommend")); + com.aliyun.teautil.Common.assertAsString(error.message); + } catch (Exception _error) { + TeaException error = new TeaException(_error.getMessage(), _error); + // 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。 + // 错误 message + System.out.println(error.getMessage()); + // 诊断地址 + System.out.println(error.getData().get("Recommend")); + com.aliyun.teautil.Common.assertAsString(error.message); + } + } + + + @Override + public void destroy() throws Exception { + log.info("开始执行删除实例方法"); + clearInstance(); + log.info("删除实例方法执行完毕"); + } +} diff --git a/cloud-modules/cloud-modules-vehicleGateway/src/main/java/com/muyu/vehicleGateway/CreateInstance.java b/cloud-modules/cloud-modules-vehicleGateway/src/main/java/com/muyu/vehicleGateway/CreateInstance.java new file mode 100644 index 0000000..7d8860e --- /dev/null +++ b/cloud-modules/cloud-modules-vehicleGateway/src/main/java/com/muyu/vehicleGateway/CreateInstance.java @@ -0,0 +1,101 @@ +package com.muyu.vehicleGateway; + +import com.aliyun.tea.TeaException; +import lombok.extern.log4j.Log4j2; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.stereotype.Component; + +/** + * 创建阿里云ECS实例 + * @className Sample + * @author LiHD + * @date 2024/9/28 19:02 + */ +@Component +@Log4j2 +public class CreateInstance implements ApplicationRunner{ + + /** + * description : + *

使用AK&SK初始化账号Client

+ * @return Client + * + * @throws Exception + */ + public static com.aliyun.ecs20140526.Client createClient() throws Exception { + // 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。 + com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config() + // 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。 + .setAccessKeyId("LTAI5tM4LSerzWQ9wUPXgybq") + // 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。 + .setAccessKeySecret("hkiPr0QwkKMZauhXucgg1SDriXUW0Q"); + // Endpoint 请参考 https://api.aliyun.com/product/Ecs + config.endpoint = "ecs.cn-beijing.aliyuncs.com"; + return new com.aliyun.ecs20140526.Client(config); + } + + /** + * 本程序的入口点 + * 主要功能是创建阿里云ECS实例 + * + * @throws Exception 如果执行过程中发生错误则抛出异常 + */ + public static void sample() throws Exception { + + // 创建阿里云ECS客户端 + com.aliyun.ecs20140526.Client client = CreateInstance.createClient(); + + // 配置系统盘参数 + com.aliyun.ecs20140526.models.RunInstancesRequest.RunInstancesRequestSystemDisk systemDisk = new com.aliyun.ecs20140526.models.RunInstancesRequest.RunInstancesRequestSystemDisk() + .setSize("40") // 设置系统盘大小为40GB + .setCategory("cloud_essd"); // 设置系统盘类型为cloud_essd + + // 创建创建实例请求对象并设置参数 + com.aliyun.ecs20140526.models.RunInstancesRequest runInstancesRequest = new com.aliyun.ecs20140526.models.RunInstancesRequest() + .setRegionId("cn-beijing") // 设置地域ID + .setImageId("m-2ze801i45fclmf1qwes5") // 设置镜像ID + .setInstanceType("ecs.e-c1m1.large") // 设置实例类型 + .setSecurityGroupId("sg-2ze63acc0bas9vjm5gtv") // 设置安全组ID + .setVSwitchId("vsw-2ze028qk4xpwk3i0ggket") // 设置虚拟交换机ID + .setInstanceName("server-mqtt") // 设置实例名称 + .setInstanceChargeType("PostPaid") // 设置实例付费类型为后付费按量付费 + .setSystemDisk(systemDisk) // 设置系统盘配置 + .setHostName("root") // 设置主机名 + .setPassword("Lhd.123456") // 设置实例密码 + .setAmount(1) // 设置创建实例的数量 + .setInternetChargeType("PayByTraffic") // 设置互联网计费类型为按流量计费 + .setInternetMaxBandwidthOut(5); // 设置最大出带宽为5Mbps + + // 创建运行时选项对象 + com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions(); + + // 尝试执行创建实例请求 + try { + // 复制代码运行请自行打印 API 的返回值 + client.runInstancesWithOptions(runInstancesRequest, runtime); + } catch (TeaException error) { + // 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。 + // 错误 message + System.out.println(error.getMessage()); + // 诊断地址 + System.out.println(error.getData().get("Recommend")); + com.aliyun.teautil.Common.assertAsString(error.message); + } catch (Exception _error) { + TeaException error = new TeaException(_error.getMessage(), _error); + // 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。 + // 错误 message + System.out.println(error.getMessage()); + // 诊断地址 + System.out.println(error.getData().get("Recommend")); + com.aliyun.teautil.Common.assertAsString(error.message); + } + } + + @Override + public void run(ApplicationArguments args) throws Exception { + log.info("开始执行创建实例方法"); + sample(); + log.info("创建实例方法执行完毕"); + } +} diff --git a/cloud-modules/cloud-modules-vehicleGateway/src/main/java/com/muyu/vehicleGateway/MqttPublishSample.java b/cloud-modules/cloud-modules-vehicleGateway/src/main/java/com/muyu/vehicleGateway/MqttPublishSample.java new file mode 100644 index 0000000..f1b337a --- /dev/null +++ b/cloud-modules/cloud-modules-vehicleGateway/src/main/java/com/muyu/vehicleGateway/MqttPublishSample.java @@ -0,0 +1,56 @@ +package com.muyu.vehicleGateway; + +import lombok.extern.log4j.Log4j2; +import lombok.extern.slf4j.Slf4j; +import org.eclipse.paho.client.mqttv3.*; + +@Log4j2 +@Slf4j +public class MqttPublishSample { + + public static void main(String[] args) { + + // 定义一个用于MQTT消息发布的示例程序 + String topic = "vehicleGateway"; + String content = "Message from MqttPublishSample"; + int qos = 2; + String broker = "tcp://123.57.152.124:1883"; + String clientId = "JavaSample"; + + try { + // 创建MQTT客户端并连接到指定的broker + MqttClient sampleClient = new MqttClient(broker, clientId); + MqttConnectOptions connOpts = new MqttConnectOptions(); + connOpts.setCleanSession(true); + System.out.println("Connecting to broker: "+broker); + sampleClient.connect(connOpts); + sampleClient.subscribe(topic,0); + // 设置回调处理 + sampleClient.setCallback(new MqttCallback() { + @Override + public void connectionLost(Throwable throwable) { + // 连接丢失的处理 + } + + @Override + public void messageArrived(String s, MqttMessage mqttMessage) throws Exception { + // 消息到达的处理 + System.out.println(new String(mqttMessage.getPayload())); + } + + @Override + public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) { + // 消息发送完成的处理 + } + }); + } catch(MqttException me) { + // 处理MQTT异常 + System.out.println("reason "+me.getReasonCode()); + System.out.println("msg "+me.getMessage()); + System.out.println("loc "+me.getLocalizedMessage()); + System.out.println("cause "+me.getCause()); + System.out.println("excep "+me); + me.printStackTrace(); + } + } +} diff --git a/cloud-modules/cloud-modules-vehicleGateway/src/main/java/com/muyu/vehicleGateway/vehicle/VehicleInstance.java b/cloud-modules/cloud-modules-vehicleGateway/src/main/java/com/muyu/vehicleGateway/vehicle/VehicleInstance.java new file mode 100644 index 0000000..f0c8d8e --- /dev/null +++ b/cloud-modules/cloud-modules-vehicleGateway/src/main/java/com/muyu/vehicleGateway/vehicle/VehicleInstance.java @@ -0,0 +1,68 @@ +package com.muyu.vehicleGateway.vehicle; + +import com.muyu.vehicleGateway.vehicle.model.VehicleData; +import com.muyu.vehicleGateway.vehicle.thread.VehicleThread; +import com.muyu.vehicleGateway.web.domain.VehicleInfo; +import com.muyu.vehicleGateway.web.domain.model.PositionModel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.extern.log4j.Log4j2; + +import java.util.concurrent.LinkedBlockingQueue; + +/** + * 车辆实例 + * @className VehicleInstance + * @author LiHD + * @date 2024/9/27 20:37 + */ +@Data +@Log4j2 +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class VehicleInstance { + + /** + * 路线轨迹编码 + */ + private String postitionCode; + + /** + * 路径队列 + */ + @Builder.Default + private LinkedBlockingQueue positionQueue = new LinkedBlockingQueue<>(); + + /** + * 车辆 + */ + private VehicleInfo vehicleInfo; + + /** + * 实例数据 + */ + private VehicleData vehicleData; + + /** + * 上一次定位点 + */ + private PositionModel lastPosition; + + /** + * 车辆工作线程 + */ + private VehicleThread vehicleThread; + + /** + * 获取当前车辆VIN + * @return VIN + */ + public String getVin() { + return this.vehicleInfo.getVin(); + } + + +} diff --git a/cloud-modules/cloud-modules-vehicleGateway/src/main/java/com/muyu/vehicleGateway/vehicle/model/VehicleData.java b/cloud-modules/cloud-modules-vehicleGateway/src/main/java/com/muyu/vehicleGateway/vehicle/model/VehicleData.java new file mode 100644 index 0000000..d7cbaa9 --- /dev/null +++ b/cloud-modules/cloud-modules-vehicleGateway/src/main/java/com/muyu/vehicleGateway/vehicle/model/VehicleData.java @@ -0,0 +1,539 @@ +package com.muyu.vehicleGateway.vehicle.model; + +import com.muyu.vehicleGateway.web.domain.VehicleInfo; +import com.muyu.vehicleGateway.web.util.VehicleUtils; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; + +/** + * @ClassName VehicleData + * @Description 车辆模拟数据对象 + * @Author LiHD + * @Date 2024/9/27 22:11 + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class VehicleData { + + /** + * VIN + */ + private String vin; + + /** + * 行驶路线 + */ + private String drivingRoute; + + /** + * 经度 + */ + private String longitude; + + /** + * 维度 + */ + private String latitude; + + /** + * 速度 + */ + private String speed; + + /** + * 里程 + */ + private BigDecimal mileage; + + /** + * 总电压 + */ + private String voltage; + + /** + * 总电流 + */ + private String current; + + /** + * 绝缘电阻 + */ + private String resistance; + + /** + * 档位 + */ + @Builder.Default + private String gear = "P"; + + /** + * 加速踏板行程值 + */ + private String accelerationPedal; + + /** + * 制动踏板行程值 + */ + private String brakePedal; + + /** + * 燃料消耗率 + */ + private String fuelConsumptionRate; + + /** + * 电机控制器温度 + */ + private String motorControllerTemperature; + + /** + * 电机转速 + */ + private String motorSpeed; + + /** + * 电机转矩 + */ + private String motorTorque; + + /** + * 电机温度 + */ + private String motorTemperature; + + /** + * 电机电压 + */ + private String motorVoltage; + + /** + * 电机电流 + */ + private String motorCurrent; + + /** + * 动力电池剩余电量SOC + */ + private BigDecimal remainingBattery; + + /** + * 电池总容量 + */ + private BigDecimal batteryLevel; + + /** + * 当前状态允许的最大反馈功率 + */ + private String maximumFeedbackPower; + + /** + * 当前状态允许最大放电功率 + */ + private String maximumDischargePower; + + /** + * BMS自检计数器 + */ + private String selfCheckCounter; + + /** + * 动力电池充放电电流 + */ + private String totalBatteryCurrent; + + /** + * 动力电池负载端总电压V3 + */ + private String totalBatteryVoltage; + + /** + * 单次最大电压 + */ + private String singleBatteryMaxVoltage; + + /** + * 单体电池最低电压 + */ + private String singleBatteryMinVoltage; + + /** + * 单体电池最高温度 + */ + private String singleBatteryMaxTemperature; + + /** + * 单体电池最低温度 + */ + private String singleBatteryMinTemperature; + + /** + * 动力电池可用容量 + */ + private String availableBatteryCapacity; + + /** + * 车辆状态 + */ + @Builder.Default + private int vehicleStatus = 1; + + /** + * 充电状态 + */ + @Builder.Default + private int chargingStatus = 1; + + /** + * 运行状态 + */ + @Builder.Default + private int operatingStatus = 1; + + /** + * SOC + */ + @Builder.Default + private int socStatus = 1; + + /** + * 可充电储能装置工作状态 + */ + @Builder.Default + private int chargingEnergyStorageStatus = 1; + + /** + * 驱动电机状态 + */ + @Builder.Default + private int driveMotorStatus = 1; + + /** + * 定位是否有效 + */ + @Builder.Default + private int positionStatus = 1; + + /** + * EAS(汽车防盗系统)状态 + */ + @Builder.Default + private int easStatus = 1; + + /** + * PTC(电动加热器)状态 + */ + @Builder.Default + private int ptcStatus = 1; + + /** + * EPS(电动助力系统)状态 + */ + @Builder.Default + private int epsStatus = 1; + + /** + * ABS(防抱死)状态 + */ + @Builder.Default + private int absStatus = 1; + + /** + * MCU(电机/逆变器)状态 + */ + @Builder.Default + private int mcuStatus = 1; + + /** + * 动力电池加热状态 + */ + @Builder.Default + private int heatingStatus = 1; + + /** + * 动力电池当前状态 + */ + @Builder.Default + private int batteryStatus = 1; + + /** + * 动力电池保温状态 + */ + @Builder.Default + private int batteryInsulationStatus = 1; + + /** + * DCDC(电力交换系统)状态 + */ + @Builder.Default + private int dcdcStatus = 1; + + /** + * CHG(充电机)状态 + */ + @Builder.Default + private int chgStatus = 1; + + /** + * 车辆状态 报文 + */ + private String vehicleStatusMsg; + /** + * 智能硬件 报文 + */ + private String smartHardwareMsg; + /** + * 电池报文 + */ + private String batteryMsg; + + public String getMsg(){ + //第一位VIN + return vin + + // 当前时间戳 + System.currentTimeMillis() + + //第二位经度 longitude latitude + getValue(longitude, 11) + + //第三位维度 longitude latitude + getValue(latitude, 10) + + //车速 + getValue(speed, 6) + + //总里程 + getValue(mileage == null ? "" : mileage.toString(), 11) + + // 总电压 + getValue(voltage, 6) + + //总电流 + getValue(current, 5) + + //绝缘电阻 79 - 87 + getValue(resistance, 9) + + //档位 + (gear == null ? "D" : gear) + + // 加速踏板行程值 + getValue(accelerationPedal, 2) + + // 制动踏板行程值 + getValue(brakePedal, 2) + + // 燃料消耗率 + getValue(fuelConsumptionRate, 5) + + //电机控制器温度 + getValue(motorControllerTemperature, 6) + + //电机转速 + getValue(motorSpeed, 5) + + //点击转矩 + getValue(motorTorque, 4) + + //电机温度 + getValue(motorTemperature, 6) + + //电机电压 + getValue(motorVoltage, 5) + + //电机电流 + getValue(motorCurrent, 8) + + //动力电池剩余电量SOC + getValue(remainingBattery == null ? "" : remainingBattery.toString(), 6) + + //当前状态允许的最大反馈功率 + getValue(maximumFeedbackPower, 6) + + //当前状态允许最大放电功率 + getValue(maximumDischargePower, 6) + + //BMS自检计数器 + getValue(selfCheckCounter, 2) + + //动力电池充放电电流 + getValue(totalBatteryCurrent, 5) + + //动力电池负载端总电压V3 + getValue(totalBatteryVoltage, 6) + + //单次最大电压 + getValue(singleBatteryMaxVoltage, 4) + + //单体电池最低电压 + getValue(singleBatteryMinVoltage, 4) + + //单体电池最高温度 + getValue(singleBatteryMaxTemperature, 6) + + //单体电池最低温度 + getValue(singleBatteryMinTemperature, 6) + + //动力电池可用容量 + getValue(availableBatteryCapacity, 6) + + //车辆状态 + vehicleStatus + + //充电状态 + chargingStatus + + //运行状态 + operatingStatus + + //SOC + socStatus + + //可充电储能装置工作状态 + chargingEnergyStorageStatus + + //驱动电机状态 + driveMotorStatus + + //定位是否有效 + positionStatus + + //EAS + easStatus + + //PTC + ptcStatus + + //EPS + epsStatus + + //ABS + absStatus + + //MCU + mcuStatus + + //动力电池加热状态 + heatingStatus + + //动力电池当前状态 + batteryStatus + + //动力电池保温状态 + batteryInsulationStatus + + //DCDC + dcdcStatus + + //CHG + chgStatus; + } + + public String getValue(String val , int valLength){ + if(val == null){ + val = ""; + } + int length = val.length(); + if (length > valLength){ + return val.substring( 0 , valLength); + } + val = val + "0".repeat(valLength - length); + return val; + } + + /** + * 汽车对象构造企业VIN + * @param vehicleInfo 汽车对象 + * @return 汽车数据对象 + */ + public static VehicleData vehicleBuild (VehicleInfo vehicleInfo) { + return VehicleData.builder() + .vin(vehicleInfo.getVin()) + .gear("P") + .remainingBattery(vehicleInfo.getRemainingBattery()) + .batteryLevel(vehicleInfo.getBatteryLevel()) + .mileage(vehicleInfo.getTotalMileage()) + .vehicleStatus(1) + .chargingStatus(1) + .operatingStatus(1) + .socStatus(1) + .chargingEnergyStorageStatus(1) + .driveMotorStatus(1) + .positionStatus(1) + .easStatus(1) + .ptcStatus(1) + .epsStatus(1) + .absStatus(1) + .mcuStatus(1) + .heatingStatus(1) + .batteryStatus(1) + .batteryInsulationStatus(1) + .dcdcStatus(1) + .chgStatus(1) + .build(); + } + + /** + * 模拟基础项 + */ + public void imitateBase(){ + // 总电压 + this.voltage = VehicleUtils.genValue(110, 750); + // 总电流 + this.current = VehicleUtils.genValue(3, 50); + // 绝缘电阻 + this.resistance = VehicleUtils.genValue(0,30000); + // 加速踏板行程值 + this.accelerationPedal = VehicleUtils.genValue(0, 10); + // 制动踏板行程值 + this.brakePedal = VehicleUtils.genValue(0, 10); + } + + + /** + * 模拟电机数据 + */ + public void imitateMotor(){ + // 电机控制器温度 + this.motorControllerTemperature = VehicleUtils.genValue(0, 100); + // 电机转速 + this.motorSpeed = VehicleUtils.genValue(0, 99999); + // 电机转矩 + this.motorTorque = VehicleUtils.genValue(0, 1000); + // 电机温度 + this.motorTemperature = VehicleUtils.genValue(0, 150); + // 电机电压 + this.motorVoltage = VehicleUtils.genValue(110, 300); + // 电机电流 + this.motorCurrent = VehicleUtils.genValue(0, 15000); + } + + /** + * 模拟电池包数据 + */ + public void imitateBatteryPack(){ + // 当前状态允许的最大反馈功率 + this.maximumFeedbackPower = VehicleUtils.genValue(0, 100); + // 当前状态允许最大放电功率 + this.maximumDischargePower = VehicleUtils.genValue(0, 100); + // BMS自检计数器 + this.selfCheckCounter = VehicleUtils.genValue(0, 15); + // 动力电池充放电电流 + this.totalBatteryCurrent = VehicleUtils.genValue(0, 15); + // 动力电池负载端总电压V3 + this.totalBatteryVoltage = VehicleUtils.genValue(220, 750); + // 单体电池最高电压 + this.singleBatteryMaxVoltage = VehicleUtils.genValue(3, 5); + // 单体电池最低电压 + this.singleBatteryMinVoltage = VehicleUtils.genValue(3, 5); + // 单体电池最高温度 + this.singleBatteryMaxTemperature = VehicleUtils.genValue(0, 100); + // 单体电池最低温度 + this.singleBatteryMinTemperature = VehicleUtils.genValue(0, 100); + // 动力电池可用容量 + this.availableBatteryCapacity = VehicleUtils.genValue(0,100 ); + } + /** + 车辆状态 + vehicleStatus; + 充电状态 + chargingStatus; + 运行状态 + operatingStatus; + SOC + socStatus; + 可充电储能装置工作状态 + chargingEnergyStorageStatus; + 驱动电机状态 + driveMotorStatus; + 定位是否有效 + positionStatus; + */ + + /** + EAS(汽车防盗系统)状态 + easStatus; + PTC(电动加热器)状态 + ptcStatus; + EPS(电动助力系统)状态 + epsStatus; + ABS(防抱死)状态 + absStatus; + MCU(电机/逆变器)状态 + mcuStatus; + */ + + /** + 动力电池加热状态 + heatingStatus; + 动力电池当前状态 + batteryStatus; + 动力电池保温状态 + batteryInsulationStatus; + DCDC(电力交换系统)状态 + dcdcStatus; + CHG(充电机)状态 + chgStatus; + */ + +} diff --git a/cloud-modules/cloud-modules-vehicleGateway/src/main/java/com/muyu/vehicleGateway/vehicle/thread/VehicleThread.java b/cloud-modules/cloud-modules-vehicleGateway/src/main/java/com/muyu/vehicleGateway/vehicle/thread/VehicleThread.java new file mode 100644 index 0000000..6a74528 --- /dev/null +++ b/cloud-modules/cloud-modules-vehicleGateway/src/main/java/com/muyu/vehicleGateway/vehicle/thread/VehicleThread.java @@ -0,0 +1,45 @@ +package com.muyu.vehicleGateway.vehicle.thread; + +import com.muyu.vehicleGateway.vehicle.VehicleInstance; +import lombok.Data; +import lombok.extern.log4j.Log4j2; + +/** + * @ClassName VehicleThread + * @Description TODO + * @Author LiHD + * @Date 2024/9/27 22:44 + */ +@Data +@Log4j2 +public class VehicleThread implements Runnable { + + /** + * 是否停止线程 + */ + private volatile boolean isStop = false; + + /** + * 车辆实例对象 + */ + private VehicleInstance vehicleInstance; + + @Override + public void run() { + try { + if (!isStop){ + log.info("{} - 上报数据",this.vehicleInstance.getVin()); + + } + }catch (Throwable throwable){ + + } + } + + /** + * + */ + private void stop() { + this.isStop = true; + } +} diff --git a/cloud-modules/cloud-modules-vehicleGateway/src/main/java/com/muyu/vehicleGateway/web/domain/VehicleInfo.java b/cloud-modules/cloud-modules-vehicleGateway/src/main/java/com/muyu/vehicleGateway/web/domain/VehicleInfo.java new file mode 100644 index 0000000..6d5f335 --- /dev/null +++ b/cloud-modules/cloud-modules-vehicleGateway/src/main/java/com/muyu/vehicleGateway/web/domain/VehicleInfo.java @@ -0,0 +1,126 @@ +package com.muyu.vehicleGateway.web.domain; + +import com.baomidou.mybatisplus.annotation.*; +import com.muyu.vehicleGateway.vehicle.VehicleInstance; +import com.muyu.vehicleGateway.vehicle.model.VehicleData; +import com.muyu.vehicleGateway.web.util.VehicleUtils; +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; + +/** + * @ClassName VehicleInfo + * @Description 车辆信息 + * @Author LiHD + * @Date 2024/9/26 23:48 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@TableName("vehicle_info") +public class VehicleInfo { + + /** + * 主键id + */ + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + /** + * VIN + */ + private String vin; + + /** + * VIN + */ + @TableField(value = "tenant_id", fill = FieldFill.INSERT) + private String tenantId; + + /** + * 报文模板id + */ + @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; + + /** + * 生成车辆数据 + * + * @param messageTemplateId 报文ID + * @return 车辆数据 + */ + public static VehicleInfo gen(Supplier messageTemplateId) { + return VehicleInfo.create(VehicleUtils.genVin(), messageTemplateId); + } + + /** + * 生成车辆数据 + * + * @param vin + * @param messageTemplateId + * @return 车辆数据 + */ + public static VehicleInfo create(String vin, Supplier messageTemplateId) { + BigDecimal battery = VehicleUtils.genBattery(); + return VehicleInfo.builder() + .vin(vin) + .messageTemplateId(messageTemplateId.get()) + .createTime(new Date()) + .remainingBattery(battery) + .batteryLevel(battery) + .totalMileage(BigDecimal.ZERO) + .build(); + } + + public static VehicleInfo instanceBuild(VehicleInstance vehicleInstance) { + VehicleData vehicle = vehicleInstance.getVehicleData(); + return VehicleInfo.builder() + .vin(vehicleInstance.getVin()) + .remainingBattery(vehicle.getRemainingBattery()) + .totalMileage(vehicle.getMileage()) + .build(); + } + +} diff --git a/cloud-modules/cloud-modules-vehicleGateway/src/main/java/com/muyu/vehicleGateway/web/domain/model/PositionModel.java b/cloud-modules/cloud-modules-vehicleGateway/src/main/java/com/muyu/vehicleGateway/web/domain/model/PositionModel.java new file mode 100644 index 0000000..6e6a2e8 --- /dev/null +++ b/cloud-modules/cloud-modules-vehicleGateway/src/main/java/com/muyu/vehicleGateway/web/domain/model/PositionModel.java @@ -0,0 +1,37 @@ +package com.muyu.vehicleGateway.web.domain.model; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @ClassName PositionModel + * @Description 位置模型 + * @Author LiHD + * @Date 2024/9/27 20:59 + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +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(); + } +} diff --git a/cloud-modules/cloud-modules-vehicleGateway/src/main/java/com/muyu/vehicleGateway/web/mapper/VehicleInfoMapper.java b/cloud-modules/cloud-modules-vehicleGateway/src/main/java/com/muyu/vehicleGateway/web/mapper/VehicleInfoMapper.java new file mode 100644 index 0000000..963dc90 --- /dev/null +++ b/cloud-modules/cloud-modules-vehicleGateway/src/main/java/com/muyu/vehicleGateway/web/mapper/VehicleInfoMapper.java @@ -0,0 +1,15 @@ +package com.muyu.vehicleGateway.web.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.muyu.vehicleGateway.web.domain.VehicleInfo; +import org.apache.ibatis.annotations.Mapper; + +/** + * @ClassName VehicleInfoMapper + * @Description TODO + * @Author LiHD + * @Date 2024/9/26 23:47 + */ +@Mapper +public interface VehicleInfoMapper extends BaseMapper { +} diff --git a/cloud-modules/cloud-modules-vehicleGateway/src/main/java/com/muyu/vehicleGateway/web/service/impl/VechileInfoServiceImpl.java b/cloud-modules/cloud-modules-vehicleGateway/src/main/java/com/muyu/vehicleGateway/web/service/impl/VechileInfoServiceImpl.java new file mode 100644 index 0000000..a87b4ac --- /dev/null +++ b/cloud-modules/cloud-modules-vehicleGateway/src/main/java/com/muyu/vehicleGateway/web/service/impl/VechileInfoServiceImpl.java @@ -0,0 +1,24 @@ +package com.muyu.vehicleGateway.web.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.muyu.vehicleGateway.web.domain.VehicleInfo; +import com.muyu.vehicleGateway.web.mapper.VehicleInfoMapper; +import lombok.extern.log4j.Log4j2; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * @ClassName VechileInfoServiceImpl + * @Description TODO + * @Author LiHD + * @Date 2024/9/26 23:46 + */ +@Log4j2 +@Service +public class VechileInfoServiceImpl extends ServiceImpl { + + @Autowired + private VehicleInfoMapper vehicleInfoMapper; + + +} diff --git a/cloud-modules/cloud-modules-vehicleGateway/src/main/java/com/muyu/vehicleGateway/web/util/VehicleUtils.java b/cloud-modules/cloud-modules-vehicleGateway/src/main/java/com/muyu/vehicleGateway/web/util/VehicleUtils.java new file mode 100644 index 0000000..0f3034a --- /dev/null +++ b/cloud-modules/cloud-modules-vehicleGateway/src/main/java/com/muyu/vehicleGateway/web/util/VehicleUtils.java @@ -0,0 +1,99 @@ +package com.muyu.vehicleGateway.web.util; + +import com.muyu.vehicleGateway.web.domain.model.PositionModel; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.Random; + +/** + * @ClassName VehicleUtils + * @Description TODO + * @Author LiHD + * @Date 2024/9/27 21:21 + */ + +public class VehicleUtils { + + /** + * 生成VIN + * @return 返回结果对象 + */ + public static String genVin() { + String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + Random random = new Random(); + StringBuilder sb = new StringBuilder(17); + for (int i = 0; i < 17; i++) { + int index = (int) (random.nextFloat() * characters.length()); + sb.append(characters.charAt(index)); + } + return sb.toString(); + } + + private static Random random = new Random(); + + /** + * 生成电池额度 + * @return 电池额度 + */ + public static BigDecimal genBattery(){ + return BigDecimal.valueOf(random.nextInt(60, 80) * 1000L); + } + + + /** + * 两点之间的距离 + * @param startPositionModel 开始定位点 + * @param endPositionModel 结束定位点 + * @return + */ + public static BigDecimal distance(PositionModel startPositionModel, PositionModel endPositionModel){ + double lon1 = Double.parseDouble(startPositionModel.getLongitude()); + double lat1 = Double.parseDouble(startPositionModel.getLatitude()); + double lon2 = Double.parseDouble(endPositionModel.getLongitude()); + double lat2 = Double.parseDouble(endPositionModel.getLatitude()); + double lon1Rad = Math.toRadians(lon1); + double lat1Rad = Math.toRadians(lat1); + double lon2Rad = Math.toRadians(lon2); + double lat2Rad = Math.toRadians(lat2); + double earthRadius = 6371; // 地球半径(以公里为单位) + + double latDiff = lat2Rad - lat1Rad; + double lonDiff = lon2Rad - lon1Rad; + + double a = Math.sin(latDiff / 2) * Math.sin(latDiff / 2) + + Math.cos(lat1Rad) * Math.cos(lat2Rad) * + Math.sin(lonDiff / 2) * Math.sin(lonDiff / 2); + + double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); + + double distance = earthRadius * c; + return BigDecimal.valueOf(distance).setScale(2, RoundingMode.HALF_UP); + } + + /** + * 生成电池浮动 + * @return 电池浮动值 + */ + public static BigDecimal batteryFloat(){ + Random rand = new Random(); + // 生成0.00-0.31之间的随机数 + double num = rand.nextDouble() * 0.31; + // 加上0.90,得到0.90-1.21之间的随机数 + num += 0.90; + // 保留两位小数 + num = (double) Math.round(num * 100) / 100; + return BigDecimal.valueOf(num); + } + + /** + * 给予开始和结束的值生成数据 + * @param start 起始范围 + * @param end 截止范围 + * @return 返回结果 + */ + public static String genValue(int start, int end){ + Random rand = new Random(); + return String.valueOf(rand.nextInt(start, end)); + } +} diff --git a/cloud-modules/cloud-modules-vehicleGateway/src/main/resources/banner.txt b/cloud-modules/cloud-modules-vehicleGateway/src/main/resources/banner.txt new file mode 100644 index 0000000..0dd5eee --- /dev/null +++ b/cloud-modules/cloud-modules-vehicleGateway/src/main/resources/banner.txt @@ -0,0 +1,2 @@ +Spring Boot Version: ${spring-boot.version} +Spring Application Name: ${spring.application.name} diff --git a/cloud-modules/cloud-modules-vehicleGateway/src/main/resources/bootstrap.yml b/cloud-modules/cloud-modules-vehicleGateway/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..08feddf --- /dev/null +++ b/cloud-modules/cloud-modules-vehicleGateway/src/main/resources/bootstrap.yml @@ -0,0 +1,56 @@ +# Tomcat +server: + port: 9703 + +# nacos线上地址 +nacos: + addr: 123.57.152.124:8848 + user-name: nacos + password: nacos + namespace: lhd +# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all +# Spring +spring: + amqp: + deserialization: + trust: + all: true + main: + allow-bean-definition-overriding: true + application: + # 应用名称 + name: cloud-vehicleGateway + profiles: + # 环境配置 + active: dev + cloud: + nacos: + discovery: + # 服务注册地址 + server-addr: ${nacos.addr} + # nacos用户名 + username: ${nacos.user-name} + # nacos密码 + password: ${nacos.password} + # 命名空间 + namespace: ${nacos.namespace} + config: + # 服务注册地址 + server-addr: ${nacos.addr} + # nacos用户名 + username: ${nacos.user-name} + # nacos密码 + password: ${nacos.password} + # 命名空间 + namespace: ${nacos.namespace} + # 配置文件格式 + file-extension: yml + # 共享配置 + shared-configs: + # 系统共享配置 + - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} + # 系统环境Config共享配置 + - application-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} +logging: + level: + com.muyu.system.mapper: DEBUG diff --git a/cloud-modules/cloud-modules-vehicleGateway/src/main/resources/logback/dev.xml b/cloud-modules/cloud-modules-vehicleGateway/src/main/resources/logback/dev.xml new file mode 100644 index 0000000..03a6f37 --- /dev/null +++ b/cloud-modules/cloud-modules-vehicleGateway/src/main/resources/logback/dev.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + ${log.pattern} + + + + + + ${log.path}/info.log + + + + ${log.path}/info.%d{yyyy-MM-dd}.log + + 60 + + + ${log.pattern} + + + + INFO + + ACCEPT + + DENY + + + + + ${log.path}/error.log + + + + ${log.path}/error.%d{yyyy-MM-dd}.log + + 60 + + + ${log.pattern} + + + + ERROR + + ACCEPT + + DENY + + + + + + + + + + + + + + + + + + diff --git a/cloud-modules/cloud-modules-vehicleGateway/src/main/resources/logback/prod.xml b/cloud-modules/cloud-modules-vehicleGateway/src/main/resources/logback/prod.xml new file mode 100644 index 0000000..0d5066f --- /dev/null +++ b/cloud-modules/cloud-modules-vehicleGateway/src/main/resources/logback/prod.xml @@ -0,0 +1,81 @@ + + + + + + + + + + + + ${log.sky.pattern} + + + + + + ${log.path}/info.log + + + + ${log.path}/info.%d{yyyy-MM-dd}.log + + 60 + + + + + INFO + + ACCEPT + + DENY + + + + + ${log.path}/error.log + + + + ${log.path}/error.%d{yyyy-MM-dd}.log + + 60 + + + + + ERROR + + ACCEPT + + DENY + + + + + + + + ${log.sky.pattern} + + + + + + + + + + + + + + + + + + + + diff --git a/cloud-modules/cloud-modules-vehicleGateway/src/main/resources/logback/test.xml b/cloud-modules/cloud-modules-vehicleGateway/src/main/resources/logback/test.xml new file mode 100644 index 0000000..0d5066f --- /dev/null +++ b/cloud-modules/cloud-modules-vehicleGateway/src/main/resources/logback/test.xml @@ -0,0 +1,81 @@ + + + + + + + + + + + + ${log.sky.pattern} + + + + + + ${log.path}/info.log + + + + ${log.path}/info.%d{yyyy-MM-dd}.log + + 60 + + + + + INFO + + ACCEPT + + DENY + + + + + ${log.path}/error.log + + + + ${log.path}/error.%d{yyyy-MM-dd}.log + + 60 + + + + + ERROR + + ACCEPT + + DENY + + + + + + + + ${log.sky.pattern} + + + + + + + + + + + + + + + + + + + +