fix():重新构建结构
parent
6dde202353
commit
9ba5f8e14a
|
@ -15,6 +15,10 @@ public class LoginBody {
|
|||
* 用户密码
|
||||
*/
|
||||
private String password;
|
||||
/**
|
||||
* 公司数据信息id
|
||||
*/
|
||||
private Long firmId;
|
||||
|
||||
public String getUsername () {
|
||||
return username;
|
||||
|
|
|
@ -7,9 +7,17 @@ package com.muyu.common.rabbit.constants;
|
|||
* @Description: rabbit常量
|
||||
* @Version 1.0.0
|
||||
*/
|
||||
public class RabbitConstants {
|
||||
|
||||
public final static String GO_ONLINE_QUEUE= "GoOnline";
|
||||
|
||||
public final static String DOWNLINE_QUEUE= "Downline";
|
||||
public interface RabbitConstants {
|
||||
/**
|
||||
* 上线队列
|
||||
*/
|
||||
String GO_ONLINE_QUEUE= "GoOnline";
|
||||
/**
|
||||
* 下线队列
|
||||
*/
|
||||
String DOWN_LINE_QUEUE= "DownLine";
|
||||
/**
|
||||
* 交换机
|
||||
*/
|
||||
String ONLINE_EXCHANGE = "online_exchange";
|
||||
}
|
||||
|
|
|
@ -17,6 +17,10 @@
|
|||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<description>
|
||||
cloud-common-saas saas公共模块
|
||||
</description>
|
||||
|
||||
<dependencies>
|
||||
<!-- 多数据源依赖 -->
|
||||
<dependency>
|
||||
|
|
|
@ -14,6 +14,7 @@ import com.muyu.common.core.constant.UserConstants;
|
|||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.utils.SpringUtils;
|
||||
import com.muyu.common.system.domain.SysDept;
|
||||
import com.muyu.common.system.domain.SysFirmDatasource;
|
||||
import com.muyu.common.system.domain.SysUser;
|
||||
import com.muyu.common.system.remote.RemoteUserService;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
@ -23,10 +24,7 @@ import org.springframework.boot.autoconfigure.AutoConfiguration;
|
|||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @Author: DongZeLiang
|
||||
|
@ -42,26 +40,28 @@ public class ManyDataSource implements ApplicationRunner {
|
|||
|
||||
private List<EntInfo> dataSourceInfoList(){
|
||||
RemoteUserService RemoteUserService = SpringUtils.getBean(RemoteUserService.class);
|
||||
Result<List<String>> listResult = RemoteUserService.selectFirmDatabaseList(SecurityConstants.INNER);
|
||||
Result<List<SysFirmDatasource>> listResult = RemoteUserService.selectFirmDatabaseList(SecurityConstants.INNER);
|
||||
if (listResult==null){
|
||||
throw new SaaSException("saas远调数据源错误");
|
||||
}
|
||||
List<String> data = listResult.getData();
|
||||
List<SysFirmDatasource> data = listResult.getData();
|
||||
if (listResult.getCode() ==Result.SUCCESS && data !=null){
|
||||
List<EntInfo> list = new ArrayList<>();
|
||||
for (String row : data) {
|
||||
for (SysFirmDatasource row : data) {
|
||||
list.add(
|
||||
EntInfo.builder()
|
||||
.entCode(row)
|
||||
.ip(DatasourceContent.IP)
|
||||
.port(DatasourceContent.PORT)
|
||||
.entCode(row.getDatabaseName())
|
||||
.ip(row.getIp())
|
||||
.port(row.getPort())
|
||||
.userName(row.getUsername())
|
||||
.password(row.getPassword())
|
||||
.build()
|
||||
);
|
||||
}
|
||||
return list;
|
||||
}else {
|
||||
log.error("远调数据源错误,远调数据为:{}", JSON.toJSONString(data));
|
||||
throw new RuntimeException("远调数据源错误,远调--》 companyList ");
|
||||
throw new RuntimeException("远调数据源错误,远调--》 firmList ");
|
||||
}
|
||||
}
|
||||
// private List<EntInfo> dataPrimarySourceInfoList(){
|
||||
|
@ -82,9 +82,16 @@ public class ManyDataSource implements ApplicationRunner {
|
|||
Map<Object, Object> dataSourceMap = new HashMap<>();
|
||||
dataSourceInfoList()
|
||||
.stream()
|
||||
.map(entInfo -> DataSourceInfo.hostAndPortBuild(entInfo.getEntCode(), entInfo.getIp(), entInfo.getPort()))
|
||||
.forEach(dataSourceInfo -> {
|
||||
dataSourceMap.put(dataSourceInfo.getKey(), druidDataSourceFactory.create(dataSourceInfo));
|
||||
.map(entInfo -> DataSourceInfo.hostAndPortBuild(
|
||||
entInfo.getEntCode(),
|
||||
entInfo.getIp(),
|
||||
entInfo.getPort(),
|
||||
entInfo.getUserName(),
|
||||
entInfo.getPassword()))
|
||||
.map(DruidDataSourceFactory::create)
|
||||
.filter(Objects::nonNull)
|
||||
.forEach(druidDataSource -> {
|
||||
dataSourceMap.put(druidDataSource.getName(), druidDataSource);
|
||||
});
|
||||
//设置动态数据源
|
||||
DynamicDataSource dynamicDataSource = new DynamicDataSource();
|
||||
|
@ -101,7 +108,7 @@ public class ManyDataSource implements ApplicationRunner {
|
|||
DynamicDataSource dynamicDataSource = SpringUtils.getBean(DynamicDataSource.class);
|
||||
for (EntInfo entInfo : dataSourceInfoList()) {
|
||||
DataSourceInfo dataSourceInfo = DataSourceInfo.hostAndPortBuild(
|
||||
entInfo.getEntCode(), entInfo.getIp(), entInfo.getPort()
|
||||
entInfo.getEntCode(), entInfo.getIp(), entInfo.getPort(),entInfo.getUserName(), entInfo.getPassword()
|
||||
);
|
||||
DruidDataSource druidDataSource = druidDataSourceFactory.create(dataSourceInfo);
|
||||
dynamicDataSource.put(dataSourceInfo.getKey(), druidDataSource);
|
||||
|
|
|
@ -9,11 +9,4 @@ public class DatasourceContent {
|
|||
|
||||
public final static String DATASOURCE_URL = "jdbc:mysql://{}:{}/{}?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8";
|
||||
|
||||
public final static String USER_NAME = "root";
|
||||
|
||||
public final static String PASSWORD = "wx0713101x";
|
||||
|
||||
public final static String IP = "127.0.0.1";
|
||||
|
||||
public final static Integer PORT = 3307;
|
||||
}
|
||||
|
|
|
@ -39,12 +39,12 @@ public class DataSourceInfo {
|
|||
private String password;
|
||||
|
||||
|
||||
public static DataSourceInfo hostAndPortBuild(String key, String host, Integer port) {
|
||||
public static DataSourceInfo hostAndPortBuild(String key, String host, Integer port,String userName,String password) {
|
||||
return DataSourceInfo.builder()
|
||||
.key(key)
|
||||
.url(StringUtils.format(DatasourceContent.DATASOURCE_URL, host, port, key))
|
||||
.password(DatasourceContent.PASSWORD)
|
||||
.userName(DatasourceContent.USER_NAME)
|
||||
.password(userName)
|
||||
.userName(password)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,8 +20,9 @@ public class DruidDataSourceFactory {
|
|||
/**
|
||||
* @Description: 根据传递的数据源信息测试数据库连接
|
||||
*/
|
||||
public DruidDataSource create(DataSourceInfo dataSourceInfo) {
|
||||
public static DruidDataSource create(DataSourceInfo dataSourceInfo) {
|
||||
DruidDataSource druidDataSource = new DruidDataSource();
|
||||
druidDataSource.setName(dataSourceInfo.getKey());
|
||||
druidDataSource.setUrl(dataSourceInfo.getUrl());
|
||||
druidDataSource.setUsername(dataSourceInfo.getUserName());
|
||||
druidDataSource.setPassword(dataSourceInfo.getPassword());
|
||||
|
|
|
@ -22,4 +22,8 @@ public class EntInfo {
|
|||
private String ip;
|
||||
|
||||
private Integer port;
|
||||
|
||||
private String userName;
|
||||
|
||||
private String password;
|
||||
}
|
||||
|
|
|
@ -79,6 +79,11 @@ public class SysDept extends BaseEntity {
|
|||
*/
|
||||
private String parentName;
|
||||
|
||||
/**
|
||||
* 公司Id
|
||||
*/
|
||||
private Long firmId;
|
||||
|
||||
/**
|
||||
* 子部门
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
package com.muyu.common.system.domain;
|
||||
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 公司下拉响应对象
|
||||
* @Author WangXin
|
||||
* @Data 2024/10/8
|
||||
* @Version 1.0.0
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Tag(name = "公司下拉响应对象",description = "登录公司下拉框数据")
|
||||
public class SysFirmResp {
|
||||
|
||||
private String name;
|
||||
|
||||
private String firmId;
|
||||
}
|
|
@ -3,6 +3,7 @@ package com.muyu.common.system.remote;
|
|||
import com.muyu.common.core.constant.SecurityConstants;
|
||||
import com.muyu.common.core.constant.ServiceNameConstants;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.system.domain.SysFirmDatasource;
|
||||
import com.muyu.common.system.domain.SysUser;
|
||||
import com.muyu.common.system.remote.factory.RemoteUserFallbackFactory;
|
||||
import com.muyu.common.system.domain.LoginUser;
|
||||
|
@ -40,6 +41,11 @@ public interface RemoteUserService {
|
|||
@PostMapping("/user/register")
|
||||
public Result<Boolean> registerUserInfo (@RequestBody SysUser sysUser, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
|
||||
@GetMapping("/")
|
||||
Result<List<String>> selectFirmDatabaseList(@RequestHeader(SecurityConstants.FROM_SOURCE) String inner);
|
||||
/**
|
||||
* 公司数据源
|
||||
* @param inner
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/firmDatasource/firmDatasourceList")
|
||||
Result<List<SysFirmDatasource>> selectFirmDatabaseList(@RequestHeader(SecurityConstants.FROM_SOURCE) String inner);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.muyu.common.system.remote.factory;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.system.domain.SysFirmDatasource;
|
||||
import com.muyu.common.system.remote.RemoteUserService;
|
||||
import com.muyu.common.system.domain.SysUser;
|
||||
import com.muyu.common.system.domain.LoginUser;
|
||||
|
@ -35,7 +36,7 @@ public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserServ
|
|||
}
|
||||
|
||||
@Override
|
||||
public Result<List<String>> selectFirmDatabaseList(String inner) {
|
||||
public Result<List<SysFirmDatasource>> selectFirmDatabaseList(String inner) {
|
||||
return Result.error("注册用户失败:" + throwable.getMessage());
|
||||
}
|
||||
};
|
||||
|
|
|
@ -70,7 +70,7 @@ public class TestController {
|
|||
|
||||
@GetMapping("/testRabbit/Downline")
|
||||
public void testRabbitDownline(@RequestParam("msg") String msg) {
|
||||
rabbitTemplate.convertAndSend(RabbitConstants.DOWNLINE_QUEUE, msg, message -> {
|
||||
rabbitTemplate.convertAndSend(RabbitConstants.DOWN_LINE_QUEUE, msg, message -> {
|
||||
message.getMessageProperties().setMessageId(UUID.randomUUID().toString().replace("-",""));
|
||||
return message;
|
||||
});
|
||||
|
|
|
@ -31,12 +31,12 @@ public class DownlineRabbitConsumer {
|
|||
@Resource
|
||||
private CacheManager cacheManager;
|
||||
|
||||
@RabbitListener(queuesToDeclare = {@Queue(RabbitConstants.DOWNLINE_QUEUE)})
|
||||
@RabbitListener(queuesToDeclare = {@Queue(RabbitConstants.DOWN_LINE_QUEUE)})
|
||||
public void downline(String vin, Message message, Channel channel) {
|
||||
log.info("车辆 {} 下线, 配置信息准备中。。。",vin);
|
||||
try {
|
||||
// 重复性校验
|
||||
Long add = redisTemplate.opsForSet().add(RabbitConstants.DOWNLINE_QUEUE, message.getMessageProperties().getMessageId());
|
||||
Long add = redisTemplate.opsForSet().add(RabbitConstants.DOWN_LINE_QUEUE, message.getMessageProperties().getMessageId());
|
||||
if (add>0) {
|
||||
deleteCarCache(vin);
|
||||
log.info("车辆 {} 下线, 消息已确认。。。",vin);
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
package com.muyu;
|
||||
|
||||
import com.alibaba.druid.spring.boot3.autoconfigure.DruidDataSourceAutoConfigure;
|
||||
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceAutoConfiguration;
|
||||
import com.muyu.common.security.annotation.EnableCustomConfig;
|
||||
import com.muyu.common.security.annotation.EnableMyFeignClients;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
|
@ -14,7 +18,11 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||
@EnableCustomConfig
|
||||
//@EnableCustomSwagger2
|
||||
@EnableMyFeignClients
|
||||
@SpringBootApplication
|
||||
@SpringBootApplication(exclude = {
|
||||
DataSourceAutoConfiguration.class,
|
||||
DruidDataSourceAutoConfigure.class,
|
||||
DynamicDataSourceAutoConfiguration.class
|
||||
})
|
||||
public class CloudEnterpiseApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(CloudEnterpiseApplication.class, args);
|
||||
|
|
|
@ -4,10 +4,10 @@ server:
|
|||
|
||||
# nacos线上地址
|
||||
nacos:
|
||||
addr: 123.57.152.124:8848
|
||||
addr: 127.0.0.1:8848
|
||||
user-name: nacos
|
||||
password: nacos
|
||||
namespace: xyr
|
||||
namespace: wx
|
||||
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
|
||||
# Spring
|
||||
spring:
|
||||
|
@ -19,7 +19,7 @@ spring:
|
|||
allow-bean-definition-overriding: true
|
||||
application:
|
||||
# 应用名称
|
||||
name: cloud-saas
|
||||
name: cloud-enterprise
|
||||
profiles:
|
||||
# 环境配置
|
||||
active: dev
|
||||
|
|
|
@ -9,11 +9,8 @@ import com.muyu.enterpise.cache.MessageValueCacheService;
|
|||
import com.muyu.enterpise.cache.SysCarCacheService;
|
||||
import com.muyu.enterpise.cache.SysCarTypeCacheService;
|
||||
import com.muyu.parse.uitl.DataParseUtil;
|
||||
import com.muyu.remote.RemoteMessageValueService;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.apache.kafka.clients.producer.Callback;
|
||||
import org.apache.kafka.clients.producer.ProducerRecord;
|
||||
import org.apache.kafka.clients.producer.RecordMetadata;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
|
|
@ -4,10 +4,10 @@ server:
|
|||
|
||||
# nacos线上地址
|
||||
nacos:
|
||||
addr: 123.57.152.124:8848
|
||||
addr: 127.0.0.1:8848
|
||||
user-name: nacos
|
||||
password: nacos
|
||||
namespace: xyr
|
||||
namespace: wx
|
||||
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
|
||||
# Spring
|
||||
spring:
|
||||
|
|
|
@ -3,21 +3,22 @@ package com.muyu.system.controller;
|
|||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.web.controller.BaseController;
|
||||
import com.muyu.common.core.web.domain.BaseEntity;
|
||||
import com.muyu.common.security.annotation.InnerAuth;
|
||||
import com.muyu.common.system.domain.SysFirmDatasource;
|
||||
import com.muyu.common.system.domain.SysFirmResp;
|
||||
import com.muyu.system.service.SysFirmDatasourceService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据源信息控制层
|
||||
* @Author WangXin
|
||||
* @Data 2024/10/2
|
||||
* @Description 数据源信息控制层
|
||||
* @Description 公司数据源信息控制层
|
||||
* @Version 1.0.0
|
||||
*/
|
||||
@RestController
|
||||
|
@ -28,6 +29,25 @@ public class SysFirmDatasourceController extends BaseController<BaseEntity> {
|
|||
@Resource
|
||||
private SysFirmDatasourceService sysFirmDatasourceService;
|
||||
|
||||
/**
|
||||
* 登录公司下拉框
|
||||
* @return 公司数据下拉框
|
||||
*/
|
||||
@GetMapping("/firmList")
|
||||
public Result<List<SysFirmResp>> firmList(){
|
||||
return success(sysFirmDatasourceService.firmList());
|
||||
}
|
||||
|
||||
/**
|
||||
* saas数据源
|
||||
* @return 公司数据源
|
||||
*/
|
||||
@GetMapping("/firmDatasourceList")
|
||||
@InnerAuth
|
||||
public Result<List<SysFirmDatasource>> firmDatasourceList(){
|
||||
return success(sysFirmDatasourceService.firmDatasourceList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id查询数据源信息
|
||||
* @param id 数据源id
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.muyu.system.mapper;
|
|||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.muyu.common.system.domain.SysDept;
|
||||
import com.muyu.common.system.domain.SysFirmResp;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
|
@ -129,4 +130,11 @@ public interface SysDeptMapper extends BaseMapper<SysDept> {
|
|||
* @return 结果
|
||||
*/
|
||||
public int deleteDeptById (Long deptId);
|
||||
|
||||
/**
|
||||
* 查询公司下拉框
|
||||
* @return 登录公司下拉框数据
|
||||
*/
|
||||
List<SysFirmResp> firmList();
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.muyu.system.service;
|
|||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.muyu.common.system.domain.SysDept;
|
||||
import com.muyu.common.system.domain.SysFirmResp;
|
||||
import com.muyu.system.domain.vo.TreeSelect;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -135,4 +136,12 @@ public interface SysDeptService extends IService<SysDept> {
|
|||
* @return 结果
|
||||
*/
|
||||
public int deleteDeptById (Long deptId);
|
||||
|
||||
/**
|
||||
* 公司下拉框数据
|
||||
* @return
|
||||
*/
|
||||
List<SysFirmResp> firmList();
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,9 @@ package com.muyu.system.service;
|
|||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.muyu.common.system.domain.SysFirmDatasource;
|
||||
import com.muyu.common.system.domain.SysFirmResp;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author WangXin
|
||||
|
@ -10,4 +13,17 @@ import com.muyu.common.system.domain.SysFirmDatasource;
|
|||
* @Version 1.0.0
|
||||
*/
|
||||
public interface SysFirmDatasourceService extends IService<SysFirmDatasource> {
|
||||
|
||||
/**
|
||||
* 公司下拉框
|
||||
* @return 公司下拉框数据
|
||||
*/
|
||||
List<SysFirmResp> firmList();
|
||||
|
||||
/**
|
||||
* saas数据源
|
||||
* @return 公司数据源
|
||||
*/
|
||||
List<SysFirmDatasource> firmDatasourceList();
|
||||
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import com.muyu.common.core.utils.StringUtils;
|
|||
import com.muyu.common.datascope.annotation.DataScope;
|
||||
import com.muyu.common.security.utils.SecurityUtils;
|
||||
import com.muyu.common.system.domain.SysDept;
|
||||
import com.muyu.common.system.domain.SysFirmResp;
|
||||
import com.muyu.common.system.domain.SysRole;
|
||||
import com.muyu.common.system.domain.SysUser;
|
||||
import com.muyu.system.domain.vo.TreeSelect;
|
||||
|
@ -280,6 +281,15 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|||
return deptMapper.deleteDeptById(deptId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录公司下拉框
|
||||
* @return 公司数据下拉框
|
||||
*/
|
||||
@Override
|
||||
public List<SysFirmResp> firmList() {
|
||||
return deptMapper.firmList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归列表
|
||||
*/
|
||||
|
|
|
@ -1,11 +1,17 @@
|
|||
package com.muyu.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.common.system.domain.SysFirmDatasource;
|
||||
import com.muyu.common.system.domain.SysFirmResp;
|
||||
import com.muyu.system.mapper.SysFirmDatasourceMapper;
|
||||
import com.muyu.system.service.SysDeptService;
|
||||
import com.muyu.system.service.SysFirmDatasourceService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author WangXin
|
||||
* @Data 2024/10/2
|
||||
|
@ -17,5 +23,26 @@ public class SysFirmDatasourceServiceImpl
|
|||
extends ServiceImpl<SysFirmDatasourceMapper, SysFirmDatasource>
|
||||
implements SysFirmDatasourceService {
|
||||
|
||||
@Resource
|
||||
private SysDeptService sysDeptService;
|
||||
|
||||
/**
|
||||
* 登录公司下拉框
|
||||
* @return 公司数据下拉框
|
||||
*/
|
||||
@Override
|
||||
public List<SysFirmResp> firmList() {
|
||||
return sysDeptService.firmList();
|
||||
}
|
||||
|
||||
/**
|
||||
* saas数据源
|
||||
* @return 公司数据源
|
||||
*/
|
||||
@Override
|
||||
public List<SysFirmDatasource> firmDatasourceList() {
|
||||
LambdaQueryWrapper<SysFirmDatasource> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.ne(SysFirmDatasource::getDatabaseName,"-");
|
||||
return this.list(lambdaQueryWrapper);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,12 @@
|
|||
<result property="createTime" column="create_time"/>
|
||||
<result property="updateBy" column="update_by"/>
|
||||
<result property="updateTime" column="update_time"/>
|
||||
<result property="firmId" column="firm_id"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="SysFirmRespResult" type="com.muyu.common.system.domain.SysFirmResp">
|
||||
<result property="name" column="dept_name"/>
|
||||
<result property="firmId" column="firm_id"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectDeptVo">
|
||||
|
@ -34,7 +40,15 @@
|
|||
d.status,
|
||||
d.del_flag,
|
||||
d.create_by,
|
||||
d.create_time
|
||||
d.create_time,
|
||||
d.firm_id
|
||||
from sys_dept d
|
||||
</sql>
|
||||
|
||||
<sql id="selectFirmResp">
|
||||
select
|
||||
d.dept_name,
|
||||
d.firm_id
|
||||
from sys_dept d
|
||||
</sql>
|
||||
|
||||
|
@ -108,6 +122,13 @@
|
|||
<include refid="selectDeptVo"/>
|
||||
where dept_name=#{deptName} and parent_id = #{parentId} and del_flag = '0' limit 1
|
||||
</select>
|
||||
<select id="firmList" resultMap="SysFirmRespResult">
|
||||
<include refid="selectFirmResp" />
|
||||
where
|
||||
parent_id = 100
|
||||
and
|
||||
del_flag = '0'
|
||||
</select>
|
||||
|
||||
<insert id="insertDept" parameterType="com.muyu.common.system.domain.SysDept">
|
||||
insert into sys_dept(
|
||||
|
|
|
@ -12,47 +12,77 @@
|
|||
<artifactId>cloud-modules-vehicle-gateway</artifactId>
|
||||
|
||||
<description>
|
||||
cloud-modules-vehicleGateway 车辆网关模块
|
||||
cloud-modules-vehicle-gateway 车辆网关模块
|
||||
</description>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<mqtt.version>1.2.5</mqtt.version>
|
||||
<mybatisplus.version>3.5.7</mybatisplus.version>
|
||||
<forest.version>1.5.36</forest.version>
|
||||
<jjwt.version>0.12.5</jjwt.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- MQTT -->
|
||||
<!-- 阿里云开启多重服务器依赖-->
|
||||
<dependency>
|
||||
<groupId>org.eclipse.paho</groupId>
|
||||
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
|
||||
<version>${mqtt.version}</version>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>credentials-java</artifactId>
|
||||
<version>LATEST</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>tea</artifactId>
|
||||
<version>LATEST</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 阿里云 -->
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>ecs20140526</artifactId>
|
||||
<version>5.1.8</version>
|
||||
<version>5.1.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>tea-openapi</artifactId>
|
||||
<version>0.3.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>tea-console</artifactId>
|
||||
<version>0.0.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>tea-util</artifactId>
|
||||
<version>0.2.21</version>
|
||||
</dependency>
|
||||
|
||||
<!-- http调用框架 -->
|
||||
<dependency>
|
||||
<groupId>com.dtflys.forest</groupId>
|
||||
<artifactId>forest-spring-boot3-starter</artifactId>
|
||||
<version>${forest.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- JWT -->
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt</artifactId>
|
||||
<version>${jjwt.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- mqtt3 -->
|
||||
<dependency>
|
||||
<groupId>org.eclipse.paho</groupId>
|
||||
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
|
||||
<version>1.2.5</version>
|
||||
</dependency>
|
||||
|
||||
<!-- SpringCloud Alibaba Nacos -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
|
@ -107,6 +137,16 @@
|
|||
<artifactId>cloud-common-api-doc</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- XllJob定时任务 -->
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-xxl</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-rabbit</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -1,108 +0,0 @@
|
|||
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 {
|
||||
|
||||
/**
|
||||
* <b>description</b> :
|
||||
* <p>使用AK&SK初始化账号Client</p>
|
||||
* @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<String> 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("删除实例方法执行完毕");
|
||||
}
|
||||
}
|
|
@ -1,101 +0,0 @@
|
|||
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{
|
||||
|
||||
/**
|
||||
* <b>description</b> :
|
||||
* <p>使用AK&SK初始化账号Client</p>
|
||||
* @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("创建实例方法执行完毕");
|
||||
}
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
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<PositionModel> 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();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,539 +0,0 @@
|
|||
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;
|
||||
*/
|
||||
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
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;
|
||||
}
|
||||
}
|
|
@ -1,126 +0,0 @@
|
|||
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<Long> messageTemplateId) {
|
||||
return VehicleInfo.create(VehicleUtils.genVin(), messageTemplateId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成车辆数据
|
||||
*
|
||||
* @param vin
|
||||
* @param messageTemplateId
|
||||
* @return 车辆数据
|
||||
*/
|
||||
public static VehicleInfo create(String vin, Supplier<Long> 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();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
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();
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
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<VehicleInfo> {
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
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<VehicleInfoMapper, VehicleInfo> {
|
||||
|
||||
@Autowired
|
||||
private VehicleInfoMapper vehicleInfoMapper;
|
||||
|
||||
|
||||
}
|
|
@ -1,99 +0,0 @@
|
|||
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));
|
||||
}
|
||||
}
|
|
@ -1,22 +1,21 @@
|
|||
package com.muyu;
|
||||
package com.muyu.vehiclegateway;
|
||||
|
||||
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
|
||||
* @Author: WangXin
|
||||
* @name:VehicleGatewayApplication
|
||||
* @Date:2024/9/25 21:14
|
||||
*/
|
||||
@Log4j2
|
||||
@EnableCustomConfig
|
||||
@EnableMyFeignClients
|
||||
@EnableCustomConfig
|
||||
@SpringBootApplication
|
||||
public class CloudVehicleGatewayApplication {
|
||||
public class VehicleGatewayApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(CloudVehicleGatewayApplication.class,args);
|
||||
SpringApplication.run(VehicleGatewayApplication.class);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.muyu.vehiclegateway.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @Author: LiHongDao
|
||||
* @name:AuthCarController
|
||||
* @Date:2024/10/4 20:42
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/authCar")
|
||||
public class AuthCarController {
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package com.muyu.vehiclegateway.controller;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.utils.uuid.UUID;
|
||||
import com.muyu.vehiclegateway.domain.Instance;
|
||||
|
||||
import com.muyu.vehiclegateway.domain.MqttServerModel;
|
||||
import com.muyu.vehiclegateway.domain.req.VehicleConnectionReq;
|
||||
import com.muyu.vehiclegateway.service.VehicleGatewayService;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.eclipse.paho.client.mqttv3.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.ListOperations;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: WangXin
|
||||
* @name:VehicleGatewayController
|
||||
* @Date:2024/9/25 21:05
|
||||
*/
|
||||
@Log4j2
|
||||
@RestController
|
||||
@RequestMapping("/vehicleGateway")
|
||||
public class VehicleGatewayController {
|
||||
|
||||
@Autowired
|
||||
private VehicleGatewayService vehicleGatewayService;
|
||||
|
||||
@PostMapping("/receiveMsg/connect")
|
||||
public Result receiveMsg(@RequestBody VehicleConnectionReq vehicleConnectionReq){
|
||||
log.info("=======>"+vehicleConnectionReq);
|
||||
MqttServerModel mqttServerModel = vehicleGatewayService.receiveMsg(vehicleConnectionReq);
|
||||
|
||||
|
||||
return Result.success(mqttServerModel);
|
||||
}
|
||||
|
||||
// @PostMapping("/testConnect")
|
||||
// public void testConnect() {
|
||||
// vehicleGatewayService.testConnect();
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.muyu.vehiclegateway.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @Author: LiHongDao
|
||||
* @name:AuthCar
|
||||
* @Date:2024/10/4 20:40
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class AuthCar {
|
||||
private Integer id;
|
||||
private String vin;
|
||||
|
||||
private String userName;
|
||||
|
||||
private String password;
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.muyu.vehiclegateway.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @Author: LiHongDao
|
||||
* @name:Instance
|
||||
* @Date:2024/9/29 16:05
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Instance {
|
||||
|
||||
|
||||
/**
|
||||
* 实例ID
|
||||
*/
|
||||
private String instanceId;
|
||||
|
||||
/**
|
||||
* IP地址
|
||||
*/
|
||||
private String ipAddress;
|
||||
|
||||
|
||||
/**
|
||||
* 实例状态
|
||||
*/
|
||||
private String status;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.muyu.vehiclegateway.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @Author: LiHongDao
|
||||
* @name:MqttServerModel
|
||||
* @Date:2024/10/4 15:17
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class MqttServerModel {
|
||||
|
||||
/**
|
||||
* MQTT服务节点
|
||||
*/
|
||||
private String broker;
|
||||
|
||||
|
||||
/**
|
||||
* MQTT订阅主题
|
||||
*/
|
||||
private String topic;
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package com.muyu.vehiclegateway.domain.req;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @Author: LiHongDao
|
||||
* @name:VehicleConnectionReq
|
||||
* @Date:2024/10/4 9:37
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class VehicleConnectionReq {
|
||||
/**
|
||||
* vin
|
||||
*/
|
||||
|
||||
|
||||
private String vehicleVin;
|
||||
|
||||
/**
|
||||
* 时间戳
|
||||
*/
|
||||
|
||||
private String timestamp;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 随机字符串
|
||||
*/
|
||||
private String nonce;
|
||||
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
// This file is auto-generated, don't edit it. Thanks.
|
||||
package com.muyu.vehiclegateway.instance;
|
||||
|
||||
import com.aliyun.ecs20140526.Client;
|
||||
import com.aliyun.ecs20140526.models.DeleteInstancesRequest;
|
||||
import com.aliyun.tea.TeaException;
|
||||
import com.aliyun.teautil.Common;
|
||||
import com.aliyun.teautil.models.RuntimeOptions;
|
||||
import com.muyu.common.redis.service.RedisService;
|
||||
import com.muyu.vehiclegateway.utils.InstanceUtil;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.event.ContextClosedEvent;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Log4j2
|
||||
@Component
|
||||
public class DelInstance implements ApplicationListener<ContextClosedEvent> {
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
private InstanceUtil instanceUtil;
|
||||
|
||||
|
||||
public void delInstance() throws Exception {
|
||||
|
||||
// 创建ECS客户端对象,用于后续调用ECS相关API
|
||||
Client client = instanceUtil.createClient();
|
||||
|
||||
List<String> list = redisService.getCacheList("instanceIds");
|
||||
|
||||
|
||||
|
||||
// 创建删除实例请求对象,并设置请求参数
|
||||
DeleteInstancesRequest deleteInstancesRequest = new DeleteInstancesRequest()
|
||||
// 设置地域ID,指定删除实例的地域
|
||||
.setRegionId("cn-shanghai")
|
||||
// 设置DryRun为true,用于验证请求是否可以成功,但不实际执行删除操作
|
||||
.setDryRun(false)
|
||||
// 设置Force为true,表示即使实例有正在运行的任务,也强制删除实例
|
||||
.setForce(true)
|
||||
// 设置TerminateSubscription为true,表示删除按订阅付费的实例时终止订阅
|
||||
.setTerminateSubscription(true)
|
||||
.setInstanceId(list);
|
||||
|
||||
// 创建运行时选项对象,用于配置运行时的选项参数
|
||||
RuntimeOptions runtime = new RuntimeOptions();
|
||||
try {
|
||||
// 复制代码运行请自行打印 API 的返回值
|
||||
client.deleteInstancesWithOptions(deleteInstancesRequest, runtime);
|
||||
} catch (TeaException error) {
|
||||
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
||||
// 错误 message
|
||||
log.error(error.getMessage());
|
||||
// 诊断地址
|
||||
log.error(error.getData().get("Recommend"));
|
||||
Common.assertAsString(error.message);
|
||||
} catch (Exception _error) {
|
||||
TeaException error = new TeaException(_error.getMessage(), _error);
|
||||
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
||||
// 错误 message
|
||||
log.error(error.getMessage());
|
||||
// 诊断地址
|
||||
log.error(error.getData().get("Recommend"));
|
||||
Common.assertAsString(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ContextClosedEvent event) {
|
||||
try {
|
||||
log.info("====>删除实例");
|
||||
delInstance();
|
||||
redisService.deleteObject("instanceIds");
|
||||
redisService.deleteObject("instanceList");
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,171 @@
|
|||
// This file is auto-generated, don't edit it. Thanks.
|
||||
package com.muyu.vehiclegateway.instance;
|
||||
|
||||
import com.aliyun.ecs20140526.Client;
|
||||
import com.aliyun.ecs20140526.models.*;
|
||||
import com.aliyun.tea.TeaException;
|
||||
import com.aliyun.teautil.Common;
|
||||
import com.aliyun.teautil.models.RuntimeOptions;
|
||||
import com.muyu.common.redis.service.RedisService;
|
||||
import com.muyu.vehiclegateway.domain.Instance;
|
||||
import com.muyu.vehiclegateway.utils.InstanceUtil;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Log4j2
|
||||
@Component
|
||||
public class GenerateInstance implements ApplicationRunner {
|
||||
|
||||
|
||||
@Autowired
|
||||
private RedisService redisTemplate;
|
||||
|
||||
@Autowired
|
||||
private InstanceUtil instanceUtil;
|
||||
|
||||
/**
|
||||
* 本程序的入口点
|
||||
* 主要功能是创建阿里云ECS实例
|
||||
*
|
||||
* @throws Exception 如果执行过程中发生错误则抛出异常
|
||||
*/
|
||||
public void generateInstance() throws Exception {
|
||||
|
||||
// 创建阿里云ECS客户端
|
||||
Client client = instanceUtil.createClient();
|
||||
// 配置系统盘参数
|
||||
RunInstancesRequest.RunInstancesRequestSystemDisk systemDisk = new RunInstancesRequest.RunInstancesRequestSystemDisk()
|
||||
.setSize("20") // 设置系统盘大小为40GB
|
||||
.setCategory("cloud_essd"); // 设置系统盘类型为cloud_essd
|
||||
// 创建创建实例请求对象并设置参数
|
||||
RunInstancesRequest runInstancesRequest = new RunInstancesRequest()
|
||||
.setRegionId("cn-shanghai") // 设置地域ID
|
||||
.setImageId("m-uf65fhjzbd3nq22twh8j") // 设置镜像ID
|
||||
.setInstanceType("ecs.t6-c1m1.large") // 设置实例类型
|
||||
.setSecurityGroupId("sg-uf68j9psn6catmhhgda9") // 设置安全组ID
|
||||
.setVSwitchId("vsw-uf609yqm5q5j15nvpfmjs") // 设置虚拟交换机ID
|
||||
.setInstanceName("server-mqtt") // 设置实例名称
|
||||
.setInstanceChargeType("PostPaid") // 设置实例付费类型为后付费按量付费
|
||||
.setSystemDisk(systemDisk) // 设置系统盘配置
|
||||
.setHostName("root") // 设置主机名
|
||||
.setPassword("TwoGroup123.") // 设置实例密码
|
||||
.setAmount(2) // 设置创建实例的数量
|
||||
// 设置互联网计费类型为按流量计费
|
||||
.setInternetChargeType("PayByTraffic")
|
||||
// 设置互联网最大出带宽为1 Mbps
|
||||
.setInternetMaxBandwidthOut(1);
|
||||
|
||||
|
||||
|
||||
// 创建运行时选项对象
|
||||
RuntimeOptions runtime = new RuntimeOptions();
|
||||
|
||||
// 尝试执行创建实例请求
|
||||
try {
|
||||
|
||||
RunInstancesResponse runInstancesResponse = client.runInstancesWithOptions(runInstancesRequest, runtime);
|
||||
RunInstancesResponseBody body = runInstancesResponse.getBody();
|
||||
RunInstancesResponseBody.RunInstancesResponseBodyInstanceIdSets instanceIdSets = body.getInstanceIdSets();
|
||||
|
||||
List<Instance> instanceList = new ArrayList<>();
|
||||
List<String> instanceIds = new ArrayList<>();
|
||||
|
||||
for (String instanceId : instanceIdSets.instanceIdSet) {
|
||||
instanceIds.add(instanceId);
|
||||
}
|
||||
|
||||
Thread.sleep(20000);
|
||||
|
||||
DescribeInstancesResponse describeInstancesResponse = queryInstanceDetails(client);
|
||||
log.info("====>创建的实例id:"+instanceIds);
|
||||
// 获取实例的ID、公网IP和状态
|
||||
|
||||
List<DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance> bodyInstancesInstances = describeInstancesResponse.getBody().getInstances().getInstance();
|
||||
for (DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance instance : bodyInstancesInstances) {
|
||||
String id = instance.getInstanceId();
|
||||
String ipAddress = instance.getPublicIpAddress().getIpAddress().toString();
|
||||
String status = instance.getStatus();
|
||||
Instance instance1 = new Instance(id,ipAddress,status);
|
||||
instanceList.add(instance1);
|
||||
}
|
||||
|
||||
|
||||
log.info("====>创建的实例集合:"+instanceList);
|
||||
|
||||
|
||||
|
||||
redisTemplate.setCacheList("instanceList",instanceList);
|
||||
redisTemplate.setCacheList("instanceIds",instanceIds);
|
||||
|
||||
// List<ConnectWeight> weightArrayList = new ArrayList<>();
|
||||
//
|
||||
// for (String instanceId : instanceIds) {
|
||||
// processIp(instanceId,weightArrayList)
|
||||
// }
|
||||
|
||||
|
||||
|
||||
} catch (TeaException error) {
|
||||
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
||||
// 错误 message
|
||||
log.error(error.getMessage());
|
||||
// 诊断地址
|
||||
log.error(error.getData().get("Recommend"));
|
||||
Common.assertAsString(error.message);
|
||||
} catch (Exception _error) {
|
||||
TeaException error = new TeaException(_error.getMessage(), _error);
|
||||
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
||||
// 错误 message
|
||||
log.error(error.getMessage());
|
||||
// 诊断地址
|
||||
log.error(error.getData().get("Recommend"));
|
||||
Common.assertAsString(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static DescribeInstancesResponse queryInstanceDetails(Client client) {
|
||||
|
||||
// 创建查询实例请求对象并设置参数
|
||||
DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest()
|
||||
.setInstanceName("server-mqtt")
|
||||
.setRegionId("cn-shanghai"); // 设置地域ID // 设置实例ID
|
||||
// 创建运行时选项对象
|
||||
RuntimeOptions runtime = new RuntimeOptions();
|
||||
|
||||
// 尝试执行查询实例请求
|
||||
try {
|
||||
return client.describeInstancesWithOptions(describeInstancesRequest, runtime);
|
||||
} catch (TeaException e) {
|
||||
// 捕获特定的TeaException并打印详细信息
|
||||
log.info("TeaException occurred: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
// 捕获其他所有异常
|
||||
log.info("An error occurred: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
log.info("===============>开始执行创建实例方法");
|
||||
|
||||
generateInstance();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.muyu.vehiclegateway.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.muyu.vehiclegateway.domain.AuthCar;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* @Author: LiHongDao
|
||||
* @name:AuthCarMapper
|
||||
* @Date:2024/10/4 20:42
|
||||
*/
|
||||
@Mapper
|
||||
public interface AuthCarMapper extends BaseMapper<AuthCar> {
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.muyu.vehiclegateway.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* @Author: WangXin
|
||||
* @name:VehicleGatewayControllerMapper
|
||||
* @Date:2024/9/25 21:14
|
||||
*/
|
||||
@Mapper
|
||||
public interface VehicleGatewayControllerMapper {
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package com.muyu.vehiclegateway.mq;
|
||||
|
||||
import com.muyu.common.rabbit.constants.RabbitConstants;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.amqp.core.*;
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @Author: WangXin
|
||||
* @name:CreateExchange
|
||||
* @Date:2024/10/7 11:46
|
||||
*/
|
||||
@Log4j2
|
||||
@Component
|
||||
public class CreateExchange implements ApplicationRunner {
|
||||
|
||||
@Autowired
|
||||
private ConnectionFactory connectionFactory;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
log.info("=====>开始创建交换机");
|
||||
|
||||
RabbitAdmin rabbitAdmin = new RabbitAdmin(connectionFactory);
|
||||
|
||||
// 创建Fanout类型的交换机
|
||||
FanoutExchange exchange = new FanoutExchange(RabbitConstants.ONLINE_EXCHANGE, true, false);
|
||||
|
||||
rabbitAdmin.declareExchange(exchange);
|
||||
|
||||
// 创建队列
|
||||
Queue queue = new Queue(RabbitConstants.GO_ONLINE_QUEUE, true, false, false);
|
||||
|
||||
rabbitAdmin.declareQueue(queue);
|
||||
|
||||
// Fanout交换机绑定
|
||||
rabbitAdmin.declareBinding(BindingBuilder.bind(queue).to(exchange));
|
||||
|
||||
log.info("=====>交换机创建成功");
|
||||
log.info("=====>队列创建成功并绑定到交换机");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.muyu.vehiclegateway.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.muyu.vehiclegateway.domain.AuthCar;
|
||||
|
||||
/**
|
||||
* @Author: LiHongDao
|
||||
* @name:AuthCarService
|
||||
* @Date:2024/10/4 20:41
|
||||
*/
|
||||
public interface AuthCarService extends IService<AuthCar> {
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.muyu.vehiclegateway.service.Impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.vehiclegateway.domain.AuthCar;
|
||||
import com.muyu.vehiclegateway.mapper.AuthCarMapper;
|
||||
import com.muyu.vehiclegateway.service.AuthCarService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @Author: LiHongDao
|
||||
* @name:AuthCarServiceImpl
|
||||
* @Date:2024/10/4 20:41
|
||||
*/
|
||||
@Service
|
||||
public class AuthCarServiceImpl extends ServiceImpl<AuthCarMapper,AuthCar> implements AuthCarService {
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
package com.muyu.vehiclegateway.service.Impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.muyu.common.core.utils.uuid.UUID;
|
||||
import com.muyu.common.redis.service.RedisService;
|
||||
import com.muyu.vehiclegateway.domain.AuthCar;
|
||||
import com.muyu.vehiclegateway.domain.Instance;
|
||||
import com.muyu.vehiclegateway.domain.MqttServerModel;
|
||||
import com.muyu.vehiclegateway.domain.req.VehicleConnectionReq;
|
||||
import com.muyu.vehiclegateway.mapper.AuthCarMapper;
|
||||
import com.muyu.vehiclegateway.service.AuthCarService;
|
||||
import com.muyu.vehiclegateway.service.VehicleGatewayService;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.eclipse.paho.client.mqttv3.*;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: WangXin
|
||||
* @name:VehicleGatewayControllerServiceImpl
|
||||
* @Date:2024/9/25 21:07
|
||||
*/
|
||||
@Log4j2
|
||||
@Service
|
||||
public class VehicleGatewayServiceImpl implements VehicleGatewayService {
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
private StringRedisTemplate redisTemplate;
|
||||
|
||||
@Autowired
|
||||
private AuthCarService authCarService;
|
||||
|
||||
@Autowired
|
||||
private AuthCarMapper authCarMapper;
|
||||
|
||||
@Autowired
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
public static int currentIndex = 0;
|
||||
|
||||
@Override
|
||||
public MqttServerModel receiveMsg(VehicleConnectionReq vehicleConnectionReq) {
|
||||
|
||||
List<Instance> instanceList = redisService.getCacheList("instanceList");
|
||||
String username = vehicleConnectionReq.getUsername();
|
||||
String password = vehicleConnectionReq.getVehicleVin() + vehicleConnectionReq.getTimestamp() + vehicleConnectionReq.getNonce();
|
||||
String vin = vehicleConnectionReq.getVehicleVin();
|
||||
|
||||
AuthCar authCar = AuthCar.builder()
|
||||
.vin(vin)
|
||||
.userName(username)
|
||||
.password(password).build();
|
||||
authCarService.save(authCar);
|
||||
|
||||
currentIndex = currentIndex % instanceList.size();
|
||||
|
||||
for (int i = 0; i < instanceList.size(); i++) {
|
||||
Instance instance = instanceList.get((currentIndex + i) % instanceList.size());
|
||||
String status = instance.getStatus();
|
||||
|
||||
if (status.equals("Running")) {
|
||||
MqttServerModel model = MqttServerModel.builder()
|
||||
.broker(instance.getIpAddress().replace("[", "").replace("]", ""))
|
||||
.topic("car")
|
||||
.build();
|
||||
|
||||
// 更新当前索引
|
||||
currentIndex = (currentIndex + i + 1) % instanceList.size();
|
||||
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.muyu.vehiclegateway.service;
|
||||
|
||||
import com.muyu.vehiclegateway.domain.MqttServerModel;
|
||||
import com.muyu.vehiclegateway.domain.req.VehicleConnectionReq;
|
||||
|
||||
/**
|
||||
* @Author: WangXin
|
||||
* @name:VehicleGatewayControllerService
|
||||
* @Date:2024/9/25 21:07
|
||||
*/
|
||||
public interface VehicleGatewayService {
|
||||
|
||||
// void testConnect();
|
||||
|
||||
MqttServerModel receiveMsg(VehicleConnectionReq vehicleConnectionReq);
|
||||
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
package com.muyu.vehiclegateway.utils;
|
||||
|
||||
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.models.RuntimeOptions;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: LiHongDao
|
||||
* @name:InstanceUtil
|
||||
* @Date:2024/9/28 22:25
|
||||
*/
|
||||
@Component
|
||||
public class InstanceUtil {
|
||||
|
||||
|
||||
/**
|
||||
* <b>description</b> :
|
||||
* <p>使用AK&SK初始化账号Client</p>
|
||||
* @return Client
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public Client createClient() throws Exception {
|
||||
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
|
||||
Config config = new Config()
|
||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
|
||||
.setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
|
||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
|
||||
.setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
|
||||
// Endpoint 请参考 https://api.aliyun.com/product/Ecs
|
||||
config.endpoint = "ecs-cn-hangzhou.aliyuncs.com";
|
||||
return new Client(config);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询所有的实例ID
|
||||
* @return
|
||||
*/
|
||||
public List<String> selectAllInstancesId() {
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
|
||||
try {
|
||||
Client client = createClient();
|
||||
|
||||
//创建运行时选择对象,用于配置运行时的选项参数
|
||||
RuntimeOptions runtimeOptions = new RuntimeOptions();
|
||||
|
||||
DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest()
|
||||
.setRegionId("cn-shanghai");
|
||||
//获取实例列表
|
||||
DescribeInstancesResponse describeInstancesResponse = client.describeInstancesWithOptions(describeInstancesRequest, runtimeOptions);
|
||||
|
||||
//提取实例ID集合
|
||||
|
||||
DescribeInstancesResponseBody body = describeInstancesResponse.getBody();
|
||||
|
||||
for (DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance instance : body.getInstances().getInstance()) {
|
||||
list.add(instance.getInstanceId());
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return list;
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
package com.muyu.vehiclegateway.utils;
|
||||
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.SecureRandom;
|
||||
|
||||
@Log4j2
|
||||
public class MD5Util {
|
||||
|
||||
private static final Integer SALT_LENGTH = 12;
|
||||
|
||||
/**
|
||||
* 将指定byte数组转换成16进制字符串
|
||||
* @param b 字节数组
|
||||
* @return 返回结果字符串
|
||||
*/
|
||||
public static String byteToHexString(byte[] b) {
|
||||
StringBuilder hexString = new StringBuilder();
|
||||
for (byte value : b) {
|
||||
String hex = Integer.toHexString(value & 0xFF);
|
||||
if (hex.length() == 1) {
|
||||
hex = '0' + hex;
|
||||
}
|
||||
hexString.append(hex.toUpperCase());
|
||||
}
|
||||
return hexString.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得加密后的口令
|
||||
* @param str 需要加密的字符串
|
||||
* @return 加密后的字符串
|
||||
*/
|
||||
public static String encrypted (String str) {
|
||||
try {
|
||||
// 声明加密后的口令数组变量
|
||||
byte[] pwd = null;
|
||||
// 随机数生成器
|
||||
SecureRandom random = new SecureRandom();
|
||||
// 声明盐数组变量
|
||||
byte[] salt = new byte[SALT_LENGTH];
|
||||
// 将随机数放入盐变量中
|
||||
random.nextBytes(salt);
|
||||
|
||||
// 声明消息摘要对象
|
||||
MessageDigest md = null;
|
||||
// 创建消息摘要
|
||||
md = MessageDigest.getInstance("MD5");
|
||||
// 将盐数据传入消息摘要对象
|
||||
md.update(salt);
|
||||
// 将口令的数据传给消息摘要对象
|
||||
md.update(str.getBytes(StandardCharsets.UTF_8));
|
||||
// 获得消息摘要的字节数组
|
||||
byte[] digest = md.digest();
|
||||
|
||||
// 因为要在口令的字节数组中存放盐,所以加上盐的字节长度
|
||||
pwd = new byte[digest.length + SALT_LENGTH];
|
||||
// 将盐的字节拷贝到生成的加密口令字节数组的前12个字节,以便在验证口令时取出盐
|
||||
System.arraycopy(salt, 0, pwd, 0, SALT_LENGTH);
|
||||
// 将消息摘要拷贝到加密口令字节数组从第13个字节开始的字节
|
||||
System.arraycopy(digest, 0, pwd, SALT_LENGTH, digest.length);
|
||||
// 将字节数组格式加密后的口令转化为16进制字符串格式的口令
|
||||
return byteToHexString(pwd);
|
||||
}catch (Exception exception){
|
||||
log.info("md5加密失败:[{}]", str, exception);
|
||||
return str;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,13 +1,13 @@
|
|||
# Tomcat
|
||||
#server:
|
||||
# port: 9703
|
||||
server:
|
||||
port: 9902
|
||||
|
||||
# nacos线上地址
|
||||
nacos:
|
||||
addr: 123.57.152.124:8848
|
||||
addr: 150.158.33.234:8848
|
||||
user-name: nacos
|
||||
password: nacos
|
||||
namespace: lhd
|
||||
namespace: dev
|
||||
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
|
||||
# Spring
|
||||
spring:
|
||||
|
@ -51,6 +51,10 @@ spring:
|
|||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
# 系统环境Config共享配置
|
||||
- application-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
# xxl-job 配置文件
|
||||
- application-xxl-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
# rabbit 配置文件
|
||||
- application-rabbit-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
logging:
|
||||
level:
|
||||
com.muyu.system.mapper: DEBUG
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||
<!-- 日志存放路径 -->
|
||||
<property name="log.path" value="logs/cloud-vehicleGateway"/>
|
||||
<property name="log.path" value="logs/cloud-system"/>
|
||||
<!-- 日志输出格式 -->
|
||||
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||
<!-- 日志存放路径 -->
|
||||
<property name="log.path" value="logs/cloud-vehicleGateway"/>
|
||||
<property name="log.path" value="logs/cloud-system"/>
|
||||
<!-- 日志输出格式 -->
|
||||
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||
<property name="log.sky.pattern" value="%d{HH:mm:ss.SSS} %yellow([%tid]) [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||
<!-- 日志存放路径 -->
|
||||
<property name="log.path" value="logs/cloud-vehicleGateway"/>
|
||||
<property name="log.path" value="logs/cloud-system"/>
|
||||
<!-- 日志输出格式 -->
|
||||
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||
<property name="log.sky.pattern" value="%d{HH:mm:ss.SSS} %yellow([%tid]) [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
|
||||
|
@ -43,7 +43,7 @@
|
|||
<!-- 日志最大的历史 60天 -->
|
||||
<maxHistory>60</maxHistory>
|
||||
</rollingPolicy>
|
||||
|
||||
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||
<!-- 过滤的级别 -->
|
||||
<level>ERROR</level>
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
<module>cloud-vx</module>
|
||||
<module>cloud-modules-parse</module>
|
||||
<module>cloud-modules-enterprise</module>
|
||||
<!-- <module>cloud-modules-vehicle-gateway</module>-->
|
||||
<module>cloud-modules-vehicle-gateway</module>
|
||||
<module>cloud-modules-data-process</module>
|
||||
</modules>
|
||||
|
||||
|
|
Loading…
Reference in New Issue