diff --git a/cloud-common/cloud-common-rabbit/pom.xml b/cloud-common/cloud-common-rabbit/pom.xml index fa6d383..6f64264 100644 --- a/cloud-common/cloud-common-rabbit/pom.xml +++ b/cloud-common/cloud-common-rabbit/pom.xml @@ -11,6 +11,9 @@ cloud-common-rabbit + + cloud-common-rabbit 模块,提供RabbitMq消息队列的相关配置 + 17 17 @@ -32,4 +35,4 @@ - \ No newline at end of file + diff --git a/cloud-common/cloud-common-rabbit/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/cloud-common/cloud-common-rabbit/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index 189ea2c..3e6824a 100644 --- a/cloud-common/cloud-common-rabbit/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/cloud-common/cloud-common-rabbit/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -1 +1 @@ -com.muyu.common.rabbit.RabbitListenerConfigurer \ No newline at end of file +com.muyu.common.rabbit.RabbitListenerConfigurer diff --git a/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-cache/src/main/java/com/muyu/enterprise/cache/AllMessageValueCacheService.java b/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-cache/src/main/java/com/muyu/enterprise/cache/AllMessageValueCacheService.java index 4d80094..97f3e3c 100644 --- a/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-cache/src/main/java/com/muyu/enterprise/cache/AllMessageValueCacheService.java +++ b/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-cache/src/main/java/com/muyu/enterprise/cache/AllMessageValueCacheService.java @@ -6,10 +6,12 @@ import com.muyu.domain.MessageValue; import com.muyu.domain.req.MessageValueReq; import com.muyu.domain.resp.MessageValueListResp; +import java.util.List; + /** * 报文模版缓存 */ -public class AllMessageValueCacheService extends CacheAbsBacis { +public class AllMessageValueCacheService extends CacheAbsBacis> { @Override diff --git a/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/enterprise/controller/MessageValueController.java b/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/enterprise/controller/MessageValueController.java index bf394ca..f262f49 100644 --- a/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/enterprise/controller/MessageValueController.java +++ b/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/enterprise/controller/MessageValueController.java @@ -48,9 +48,9 @@ public class MessageValueController { @Operation(summary = "报文数据列表", description = "根据报文类别, 报文模版筛选报文数据") public Result> findAll(@RequestBody MessageValueReq messageValueReq) { List list = messageValueService.findAll(messageValueReq); - for (MessageValueListResp messageValueListResp : list) { - allMessageValueCacheService.put(String.valueOf(messageValueListResp.getMessageTemplateId()), messageValueListResp); - } +// for (MessageValueListResp messageValueListResp : list) { +// allMessageValueCacheService.put(String.valueOf(messageValueListResp.getMessageTemplateId()), (List) messageValueListResp); +// } return Result.success(list); } @@ -102,6 +102,7 @@ public class MessageValueController { @Operation(summary = "根据报文模版id查询报文数据", description = "根据报文模版id查询报文数据") public Result> findByTemplateId(@PathVariable("templateId") Long templateId) { List list = messageValueService.findByTemplateId(templateId); + allMessageValueCacheService.put(String.valueOf(templateId), list); return Result.success(list); } diff --git a/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/enterprise/controller/VehicleController.java b/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/enterprise/controller/VehicleController.java index e466edf..125aaed 100644 --- a/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/enterprise/controller/VehicleController.java +++ b/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/enterprise/controller/VehicleController.java @@ -48,6 +48,10 @@ public class VehicleController extends BaseController { //添加车辆缓存 @Autowired private VehicleCacheService vehicleCacheService; + //车辆信息 + @Autowired + private AllVehicleCacheService allVehicleCacheService; + /** * 查询车辆管理列表 @@ -59,7 +63,10 @@ public class VehicleController extends BaseController { public Result> getVehicleList(@RequestBody VehicleManageReq vehicleManageReq) { startPage(); List list = vehicleService.getVehicleList(vehicleManageReq); - //将车辆信息存到Redis +// 将车辆信息存到Redis +// for (VehicleManageResp resp : list) { +// allVehicleCacheService.put(resp.getVehicleVin(), resp); +// } List vehicleList = vehicleService.list(); vehicleList.forEach(vehicle -> { vehicleCacheService.put(vehicle.getVehicleVin(), vehicle); diff --git a/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/enterprise/controller/VehicleTypeController.java b/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/enterprise/controller/VehicleTypeController.java index 3518600..068cd45 100644 --- a/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/enterprise/controller/VehicleTypeController.java +++ b/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/enterprise/controller/VehicleTypeController.java @@ -48,14 +48,17 @@ public class VehicleTypeController { * 查询所有车辆类型 * @return */ - @RequestMapping(path = "/", method = RequestMethod.POST) + @RequestMapping(path = "/findAll", method = RequestMethod.POST) @Operation(summary = "车辆类型列表",description = "车辆类型列表") public Result> findAll(){ List list = vehicleTypeService.list(); - for (VehicleType vehicleType : list) { - allVehicleTypeCacheService.put(String.valueOf(vehicleType.getVehicleTypeId()),vehicleType); - } - return Result.success(); +// for (VehicleType vehicleType : list) { +// allVehicleTypeCacheService.put(String.valueOf(vehicleType.getVehicleTypeId()),vehicleType); +// } + list.forEach(vehicleType -> { + vehicleTypeCacheService.put(String.valueOf(vehicleType.getVehicleTypeId()), vehicleType); + }); + return Result.success(list); } /** diff --git a/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/enterprise/mapper/VehicleMapper.java b/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/enterprise/mapper/VehicleMapper.java index 95cc6f1..1fcbaa5 100644 --- a/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/enterprise/mapper/VehicleMapper.java +++ b/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/enterprise/mapper/VehicleMapper.java @@ -1,6 +1,7 @@ package com.muyu.enterprise.mapper; import com.github.yulichang.base.MPJBaseMapper; +import com.muyu.domain.FenceGroup; import com.muyu.domain.Vehicle; import com.muyu.domain.req.BoundFenceGroupReq; import com.muyu.domain.req.VehicleManageReq; @@ -49,4 +50,8 @@ public interface VehicleMapper extends MPJBaseMapper { }) void boundFenceGroup(BoundFenceGroupReq boundFenceGroupReq); + @Select("SELECT * FROM bound_middle bm LEFT JOIN vehicle v ON bm.vehicle_id=v.vehicle_id WHERE bm.fence_group_id = #{fenceGroupId}") + List showBoundFenceGroup(@Param("fenceGroupId") Long fenceGroupId); + + } diff --git a/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/enterprise/service/ElectService.java b/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/enterprise/service/ElectService.java index d0b2896..d9006f7 100644 --- a/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/enterprise/service/ElectService.java +++ b/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/enterprise/service/ElectService.java @@ -30,11 +30,6 @@ public interface ElectService extends IService { */ List mapShow(@Param("fenceId") Long fenceId); -// /** -// * 根据id查询车辆 -// */ -// Fence boundFence(@Param("fenceId") Long fenceId); - /** * 查询电子围栏(终版) */ diff --git a/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/enterprise/service/VehicleService.java b/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/enterprise/service/VehicleService.java index e34cc29..940aeda 100644 --- a/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/enterprise/service/VehicleService.java +++ b/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/enterprise/service/VehicleService.java @@ -1,6 +1,7 @@ package com.muyu.enterprise.service; import com.baomidou.mybatisplus.extension.service.IService; +import com.muyu.domain.FenceGroup; import com.muyu.domain.Vehicle; import com.muyu.domain.req.BoundFenceGroupReq; import com.muyu.domain.req.VehicleManageReq; @@ -39,4 +40,11 @@ public interface VehicleService extends IService { */ void boundFenceGroup(BoundFenceGroupReq boundFenceGroupReq); + /** + * 查询绑定围栏组信息 + * @param fenceGroupId + * @return + */ + List showBoundFenceGroup(@Param("fenceGroupId") Long fenceGroupId); + } diff --git a/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/enterprise/service/impl/MessageValueServiceImpl.java b/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/enterprise/service/impl/MessageValueServiceImpl.java index 7d12c08..3dbbb15 100644 --- a/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/enterprise/service/impl/MessageValueServiceImpl.java +++ b/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/enterprise/service/impl/MessageValueServiceImpl.java @@ -72,48 +72,7 @@ public class MessageValueServiceImpl messageValue ) ).collect(Collectors.toList()); - allMessageValueCacheService.put(String.valueOf(templateId), collect); +// allMessageValueCacheService.put(String.valueOf(templateId), collect); return collect; } - - -// @Override -// public JSONObject analysis(String testStr) { -// -// if (testStr.length() < 18){ -// throw new RuntimeException("报文格式不正确"); -// } -// //根据空格切割数据 -// String[] hexArray = testStr.split(" "); -// StringBuilder result = new StringBuilder(); -// for (String hex : hexArray) { -// int decimal = Integer.parseInt(hex, 16); -// result.append((char) decimal); -// } -// log.info(result); -// //取出车辆VIN码 -// String vehicleVin = result.substring(1, 18); -// log.info("车辆VIN:" + vehicleVin); -// //根据车辆VIN码, 查找到报文模版id -// Long templateId = messageValueMapper.getTemplateId(vehicleVin); -// log.info("模版id:" + templateId); -// //获取到报文模版的列表 -// List templateList = messageValueMapper.getTemplateList(templateId); -// //存储报文模板解析后数据 -// JSONObject jsonObject = new JSONObject(); -// for (MessageValueListResp messageValue : templateList) { -// //起始位下标 -// Integer startIndex = messageValue.getMessageStartIndex() - 1; -// //截止位下标 -// Integer endIndex = messageValue.getMessageEndIndex(); -// //根据报文模版截取数据 -// String value = result.substring(startIndex, endIndex); -// //存入数据 -// jsonObject.put(messageValue.getMessageLabel(), value); -// } -// for (Map.Entry stringObjectEntry : jsonObject) { -// log.info(stringObjectEntry.getKey() + ":" + stringObjectEntry.getValue()); -// } -// return jsonObject; -// } } diff --git a/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/enterprise/service/impl/VehicleServiceImpl.java b/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/enterprise/service/impl/VehicleServiceImpl.java index 142377d..321f207 100644 --- a/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/enterprise/service/impl/VehicleServiceImpl.java +++ b/cloud-modules/cloud-modules-enterprise/cloud-modules-enterprise-server/src/main/java/com/muyu/enterprise/service/impl/VehicleServiceImpl.java @@ -3,6 +3,7 @@ package com.muyu.enterprise.service.impl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.github.yulichang.wrapper.MPJLambdaWrapper; import com.muyu.common.core.utils.StringUtils; +import com.muyu.domain.FenceGroup; import com.muyu.domain.Vehicle; import com.muyu.domain.VehicleType; import com.muyu.domain.req.BoundFenceGroupReq; @@ -14,6 +15,7 @@ import com.muyu.enterprise.service.VehicleService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.Collections; import java.util.List; /** @@ -76,5 +78,11 @@ public class VehicleServiceImpl vehicleMapper.boundFenceGroup(boundFenceGroupReq); } + @Override + public List showBoundFenceGroup(Long fenceGroupId) { + List fenceGroups = vehicleMapper.showBoundFenceGroup(fenceGroupId); + return fenceGroups; + } + } diff --git a/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/aliyun/controller/VehicleConnectionController.java b/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/aliyun/controller/VehicleConnectionController.java new file mode 100644 index 0000000..54e828b --- /dev/null +++ b/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/aliyun/controller/VehicleConnectionController.java @@ -0,0 +1,40 @@ +package com.muyu.cloud.vehicle.gateway.aliyun.controller; + + +import com.alibaba.nacos.api.model.v2.Result; +import com.muyu.cloud.vehicle.gateway.aliyun.domain.req.VehicleConnectionReq; +import com.muyu.cloud.vehicle.gateway.aliyun.service.VehicleConnectionService; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.extern.log4j.Log4j2; +import org.springframework.beans.factory.annotation.Autowired; +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; + +/** + * + * 车辆连接控制器 + */ +@Log4j2 +@RestController +@RequestMapping("/vehicleGateway") +@Tag(name = "连接车辆控制层") +public class VehicleConnectionController { + + @Autowired + private VehicleConnectionService vehicleConnectionService; + + + /** + * 获取http连接的参数 + * @param vehicleConnectionReq + * @return + */ + @PostMapping("/receiveMsg/connect") + public Result receiveMsg(@RequestBody VehicleConnectionReq vehicleConnectionReq){ + log.info("=======>"+vehicleConnectionReq); + vehicleConnectionService.getConnect(vehicleConnectionReq); + return Result.success(); + } +} diff --git a/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/aliyun/domain/AliInstance.java b/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/aliyun/domain/AliInstance.java new file mode 100644 index 0000000..10ebe57 --- /dev/null +++ b/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/aliyun/domain/AliInstance.java @@ -0,0 +1,23 @@ +package com.muyu.cloud.vehicle.gateway.aliyun.domain; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class AliInstance { + /** + * 实例ID + */ + private String instanceId; + /** + * 实例IP + */ + private String ipAddress; + /** + * 实例状态 + */ + private String status; +} diff --git a/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/aliyun/domain/AliServerConfig.java b/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/aliyun/domain/AliServerConfig.java new file mode 100644 index 0000000..e337c9a --- /dev/null +++ b/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/aliyun/domain/AliServerConfig.java @@ -0,0 +1,42 @@ +package com.muyu.cloud.vehicle.gateway.aliyun.domain; + + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 创建实例的数量 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class AliServerConfig { + + /** + * 主键 + */ + private Long id; + /** + * 地域ID + */ + private String regionId; + /** + * 镜像ID + */ + private String imageId; + /** + * 实例规格 + */ + private String instanceType; + /** + * 安全组ID + */ + private String securityGroupId; + /** + * 虚拟交换机ID + */ + private String vSwitchId; +} diff --git a/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/aliyun/domain/ConnectWeight.java b/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/aliyun/domain/ConnectWeight.java new file mode 100644 index 0000000..32710bd --- /dev/null +++ b/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/aliyun/domain/ConnectWeight.java @@ -0,0 +1,23 @@ +package com.muyu.cloud.vehicle.gateway.aliyun.domain; + + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 车辆服务器 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class ConnectWeight { + /** + * 车辆服务器ID + */ + private String carServerId; + /** + * 权重值 + */ + private Integer weightValue; +} diff --git a/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/aliyun/domain/HttpStatus.java b/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/aliyun/domain/HttpStatus.java new file mode 100644 index 0000000..748ed18 --- /dev/null +++ b/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/aliyun/domain/HttpStatus.java @@ -0,0 +1,93 @@ +package com.muyu.cloud.vehicle.gateway.aliyun.domain; + +/** + * 返回状态码 + */ +public class HttpStatus { + /** + * 操作成功 + */ + private static final int SUCCESS = 200; + + /** + * 对象创建成功 + */ + public static final int CREATED = 201; + + /** + * 请求已经被接受 + */ + public static final int ACCEPTED = 202; + + /** + * 操作已经执行成功 + */ + public static final int NO_CONTENT = 204; + + /** + * 资源已被修改 + */ + public static final int MOVED_PERM = 301; + + /** + * 重定向 + */ + public static final int SEE_OTHER = 303; + + /** + * 资源没有被修改 + */ + public static final int NOT_MODIFIED = 304; + + /** + * 参数列表错误(缺少,格式不匹配) + */ + public static final int BAD_REQUEST = 400; + + /** + * 未授权 + */ + public static final int UNAUTHORIZED = 401; + + /** + * 访问受限,授权过期 + */ + public static final int FORBIDDEN = 403; + + /** + * 资源,服务未找到 + */ + public static final int NOT_FOUND = 404; + + /** + * 不允许的http方法 + */ + public static final int BAD_METHOD = 405; + + /** + * 资源冲突,或者资源被锁 + */ + public static final int CONFLICT = 409; + + /** + * 不支持的数据,媒体类型 + */ + public static final int UNSUPPORTED_TYPE = 415; + + /** + * 系统内部错误 + */ + public static final int ERROR = 500; + + /** + * 接口未实现 + */ + public static final int NOT_IMPLEMENTED = 501; + + /** + * 系统警告消息 + */ + public static final int WARN = 601; + + +} diff --git a/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/aliyun/domain/ServerConfig.java b/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/aliyun/domain/ServerConfig.java new file mode 100644 index 0000000..0235433 --- /dev/null +++ b/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/aliyun/domain/ServerConfig.java @@ -0,0 +1,51 @@ +package com.muyu.cloud.vehicle.gateway.aliyun.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +@TableName(value = "server_config") +public class ServerConfig { + + /** + * 主键 + */ + @TableId(value = "id",type = IdType.AUTO) + private Long id; + /** + * 租户id + */ + private String tenantId; + /** + * 主机地址 + */ + private String host; + /** + * 端口 + */ + private String port; + /** + * 负载的地址 + */ + private String url; + /** + * 默认MQTT地址 + */ + private String defaultMqttAddr; + /** + * 默认MQTT主题 + */ + private String defaultMqttTopic; + /** + * 默认MQTT QOS + */ + private Integer defaultMqttQos; +} diff --git a/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/aliyun/domain/VehicleConnection.java b/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/aliyun/domain/VehicleConnection.java new file mode 100644 index 0000000..ca6d48a --- /dev/null +++ b/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/aliyun/domain/VehicleConnection.java @@ -0,0 +1,34 @@ +package com.muyu.cloud.vehicle.gateway.aliyun.domain; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 车辆鉴权的参数 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class VehicleConnection { + /** + * 车辆VIN + */ + private String vehicleVin; + /** + * 时间戳 + */ + private String timestamp; + /** + * 用户名 + */ + private String username; + /** + * 随机数 + */ + private String nonce; + /** + * 密码 + */ + private String password; +} diff --git a/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/aliyun/domain/VinIp.java b/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/aliyun/domain/VinIp.java new file mode 100644 index 0000000..2960f8e --- /dev/null +++ b/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/aliyun/domain/VinIp.java @@ -0,0 +1,23 @@ +package com.muyu.cloud.vehicle.gateway.aliyun.domain; + + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 车辆VIN + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class VinIp { + /** + * 车辆的vin + */ + String vin; + /** + * 车辆的ip + */ + String ip; +} diff --git a/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/aliyun/domain/req/VehicleConnectionReq.java b/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/aliyun/domain/req/VehicleConnectionReq.java new file mode 100644 index 0000000..cdcaf65 --- /dev/null +++ b/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/aliyun/domain/req/VehicleConnectionReq.java @@ -0,0 +1,37 @@ +package com.muyu.cloud.vehicle.gateway.aliyun.domain.req; + + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 车辆获取链接地址 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class VehicleConnectionReq { + + /** + * 车辆vin + */ + private String vehicleVin; + + /** + * 时间戳 + */ + private String timestamp; + + /** + * 用户名 + */ + private String username; + + /** + * 随机数 + */ + private String nonce; +} diff --git a/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/aliyun/ecs/DelInstance.java b/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/aliyun/ecs/DelInstance.java index c9268c5..1b40738 100644 --- a/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/aliyun/ecs/DelInstance.java +++ b/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/aliyun/ecs/DelInstance.java @@ -126,8 +126,8 @@ public class DelInstance implements ApplicationListener { try{ log.info("=======>删除实例"); delInstance(); - redisTemplate.delete("instanceIds"); - redisTemplate.delete("instanceList"); +// redisTemplate.delete("instanceIds"); +// redisTemplate.delete("instanceList"); } catch (Exception e) { throw new RuntimeException(e); } diff --git a/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/aliyun/ecs/Sample.java b/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/aliyun/ecs/Sample.java index 750ddbb..50c547e 100644 --- a/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/aliyun/ecs/Sample.java +++ b/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/aliyun/ecs/Sample.java @@ -27,9 +27,6 @@ import java.util.List; @Component public class Sample implements ApplicationRunner { - @Autowired - private StringRedisTemplate redisTemplate; - /** @@ -64,7 +61,7 @@ public class Sample implements ApplicationRunner { // 创建创建实例请求对象并设置参数 RunInstancesRequest runInstancesRequest = new RunInstancesRequest() .setRegionId("cn-shanghai") // 设置地域ID - .setImageId("m-uf63dnbv4od71jlezdne")// 设置镜像ID + .setImageId("m-uf66taa8r57ky0pg3e7s")// 设置镜像ID .setInstanceType("ecs.e-c1m1.large")// 设置实例类型 .setSecurityGroupId("sg-uf6hyictocodexptlgiv")// 设置安全组ID .setVSwitchId("vsw-uf6ags5luz17qd6ckn2tb")// 设置虚拟交换机ID diff --git a/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/aliyun/mapper/VehicleConnectionMapper.java b/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/aliyun/mapper/VehicleConnectionMapper.java new file mode 100644 index 0000000..b573aa1 --- /dev/null +++ b/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/aliyun/mapper/VehicleConnectionMapper.java @@ -0,0 +1,10 @@ +package com.muyu.cloud.vehicle.gateway.aliyun.mapper; + +import com.muyu.cloud.vehicle.gateway.aliyun.domain.VehicleConnection; +import com.muyu.cloud.vehicle.gateway.aliyun.domain.req.VehicleConnectionReq; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface VehicleConnectionMapper { + void addConnect(VehicleConnection vehicleConnection); +} diff --git a/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/aliyun/service/VehicleConnectionService.java b/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/aliyun/service/VehicleConnectionService.java new file mode 100644 index 0000000..dfbf7cb --- /dev/null +++ b/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/aliyun/service/VehicleConnectionService.java @@ -0,0 +1,12 @@ +package com.muyu.cloud.vehicle.gateway.aliyun.service; + +import com.muyu.cloud.vehicle.gateway.aliyun.domain.req.VehicleConnectionReq; + +public interface VehicleConnectionService { + /** + * 获取连接 + * @param vehicleConnectionReq + */ + void getConnect(VehicleConnectionReq vehicleConnectionReq); + +} diff --git a/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/aliyun/service/impl/VehicleConnectionServiceImpl.java b/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/aliyun/service/impl/VehicleConnectionServiceImpl.java new file mode 100644 index 0000000..71cca36 --- /dev/null +++ b/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/aliyun/service/impl/VehicleConnectionServiceImpl.java @@ -0,0 +1,35 @@ +package com.muyu.cloud.vehicle.gateway.aliyun.service.impl; + +import com.muyu.cloud.vehicle.gateway.aliyun.domain.VehicleConnection; +import com.muyu.cloud.vehicle.gateway.aliyun.domain.req.VehicleConnectionReq; +import com.muyu.cloud.vehicle.gateway.aliyun.mapper.VehicleConnectionMapper; +import com.muyu.cloud.vehicle.gateway.aliyun.service.VehicleConnectionService; +import lombok.extern.log4j.Log4j2; +import org.springframework.amqp.rabbit.core.RabbitTemplate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Log4j2 +@Service +public class VehicleConnectionServiceImpl implements VehicleConnectionService { + + @Autowired + private RabbitTemplate rabbitTemplate; + + @Autowired + private VehicleConnectionMapper vehicleConnectionMapper; + + @Override + public void getConnect(VehicleConnectionReq vehicleConnectionReq) { + log.info("车辆连接请求:{}",vehicleConnectionReq.toString()); + + //发送消息 + rabbitTemplate.convertAndSend("exchange_topics_inform","",vehicleConnectionReq.getVehicleVin()); + + VehicleConnection vehicleConnection = new VehicleConnection(); + vehicleConnection.setVehicleVin(vehicleConnectionReq.getVehicleVin()); + vehicleConnection.setUsername(vehicleConnectionReq.getUsername()); + vehicleConnection.setPassword(vehicleConnectionReq.getVehicleVin()+vehicleConnectionReq.getTimestamp()+vehicleConnectionReq.getNonce()); + vehicleConnectionMapper.addConnect(vehicleConnection); + } +} diff --git a/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/config/RabbitmqConfig.java b/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/config/RabbitmqConfig.java new file mode 100644 index 0000000..b8e2048 --- /dev/null +++ b/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/config/RabbitmqConfig.java @@ -0,0 +1,104 @@ +package com.muyu.cloud.vehicle.gateway.config; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.amqp.core.*; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.concurrent.Exchanger; + +/** + * rabbitmq配置类 + */ +@Configuration +public class RabbitmqConfig { + /** + * 日志 + */ + private static final Logger logger = LoggerFactory.getLogger(RabbitmqConfig.class); + /** + * 队列 + */ + private static final String QUEUE_INFORM_EMAIL = "queue_inform_email"; + /** + * 队列 + */ + private static final String QUEUE_INFORM_SMS = "queue_inform_sms"; + /** + * 交换机 + */ + private static final String EXCHANGE_TOPICS_INFORM = "exchange_topics_inform"; + /** + * 路由key + */ + private static final String ROUTINGKEY_EMAIL = "inform.#.email.#"; + /** + * 路由key + */ + private static final String ROUTINGKEY_SMS = "inform.#.sms.#"; + + /** + * 声明交换机,做持久化 + */ + @Bean(EXCHANGE_TOPICS_INFORM) + public Exchange exchangeTopicsInform() { + try{ + Exchange exchange = ExchangeBuilder.topicExchange(EXCHANGE_TOPICS_INFORM).durable(true).build(); + logger.info("创建的交换机为:{}",EXCHANGE_TOPICS_INFORM); + return exchange; + } catch (Exception e) { + logger.error("创建该:{} 交换机失败",EXCHANGE_TOPICS_INFORM,e); + throw e; + } + } + + /** + * 声明QUEUE_INFORM_EMAIL队列 + */ + @Bean(QUEUE_INFORM_EMAIL) + public Queue queueInformEmail() { + try{ + Queue queue = new Queue(QUEUE_INFORM_EMAIL); + logger.info("创建的队列为:{}",QUEUE_INFORM_EMAIL); + return queue; + } catch (Exception e) { + logger.error("创建该:{} 队列失败",QUEUE_INFORM_EMAIL,e); + throw e; + } + } + + /** + * 声明QUEUE_INFORM_SMS队列 + */ + @Bean(QUEUE_INFORM_SMS) + public Queue queueInformSms() { + try{ + Queue queue = new Queue(QUEUE_INFORM_SMS); + logger.info("创建的队列为:{}",QUEUE_INFORM_SMS); + return queue; + } catch (Exception e) { + logger.error("创建该:{} 队列失败",QUEUE_INFORM_SMS,e); + throw e; + } + } + + /** + * ROUTINGKEY_EMAIL队列绑定交换机,指定routingKey + */ + @Bean + public Binding bindingExchangeInformEmail(@Qualifier(QUEUE_INFORM_EMAIL)Queue queue, + @Qualifier(EXCHANGE_TOPICS_INFORM)Exchange exchange) { + return BindingBuilder.bind(queue).to(exchange).with(ROUTINGKEY_EMAIL).noargs(); + } + + /** + * ROUTINGKEY_SMS队列绑定交换机,指定routingKey + */ + @Bean + public Binding bindingExchangeInformSms(@Qualifier(QUEUE_INFORM_SMS)Queue queue, + @Qualifier(EXCHANGE_TOPICS_INFORM)Exchange exchange) { + return BindingBuilder.bind(queue).to(exchange).with(ROUTINGKEY_SMS).noargs(); + } +} diff --git a/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/config/RedisConfig.java b/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/config/RedisConfig.java new file mode 100644 index 0000000..5531036 --- /dev/null +++ b/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/config/RedisConfig.java @@ -0,0 +1,28 @@ +package com.muyu.cloud.vehicle.gateway.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; +import org.springframework.data.redis.serializer.StringRedisSerializer; + +/** + * Redis配置类 + */ +@Configuration +public class RedisConfig { + + @Bean + public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory){ + RedisTemplate redisTemplate = new RedisTemplate<>(); + redisTemplate.setConnectionFactory(redisConnectionFactory); + + redisTemplate.setKeySerializer(new StringRedisSerializer()); + redisTemplate.setValueSerializer(new Jackson2JsonRedisSerializer(Object.class)); + + redisTemplate.setHashKeySerializer(new StringRedisSerializer()); + redisTemplate.setHashValueSerializer(new StringRedisSerializer()); + return redisTemplate; + } +} diff --git a/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/config/RestTemplateConfig.java b/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/config/RestTemplateConfig.java new file mode 100644 index 0000000..1d89c16 --- /dev/null +++ b/cloud-modules/cloud-modules-vehicle-gateway/src/main/java/com/muyu/cloud/vehicle/gateway/config/RestTemplateConfig.java @@ -0,0 +1,43 @@ +package com.muyu.cloud.vehicle.gateway.config; + +import lombok.extern.log4j.Log4j2; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.client.ClientHttpRequestFactory; +import org.springframework.http.client.SimpleClientHttpRequestFactory; +import org.springframework.web.client.RestTemplate; + +/** + * rest配置类 + */ +@Log4j2 +@Configuration +public class RestTemplateConfig { + @Bean + public RestTemplate restTemplate(ClientHttpRequestFactory factory){ + return new RestTemplate(factory); + } + + /** + * 创建并配置客户端HTTP请求工厂实例。 + * 注意:这里设置了连接和读取数据的超时时间,分别设为15秒和5秒。 + * 这些值可以根据实际网络状况和应用需求进行调整。 + * + * @return 配置好的客户端请求工厂对象 + */ + @Bean + public ClientHttpRequestFactory simpleClientHttpRequestFactory(){ + try{ + SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory(); + //设置读取超时时间为5秒 + factory.setReadTimeout(5000); + //设置连接超时时间为15秒 + factory.setConnectTimeout(15000); + return factory; + } catch (Exception e) { + //处理创建工厂或设置超时时间可能出现的异常 + log.info("创建工厂失败:" + e.getMessage()); + throw new RuntimeException("初始化HTTP请求失败",e); + } + } +} diff --git a/cloud-modules/cloud-modules-vehicle-gateway/src/main/resources/bootstrap.yml b/cloud-modules/cloud-modules-vehicle-gateway/src/main/resources/bootstrap.yml index 73addd9..303ca8a 100644 --- a/cloud-modules/cloud-modules-vehicle-gateway/src/main/resources/bootstrap.yml +++ b/cloud-modules/cloud-modules-vehicle-gateway/src/main/resources/bootstrap.yml @@ -7,7 +7,7 @@ nacos: addr: 47.101.49.53:8848 user-name: nacos password: nacos - namespace: warn + namespace: seven # SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all # Spring spring: diff --git a/cloud-modules/cloud-modules-vehicle-gateway/src/main/resources/mapper/VehicleConnectionMapper.xml b/cloud-modules/cloud-modules-vehicle-gateway/src/main/resources/mapper/VehicleConnectionMapper.xml new file mode 100644 index 0000000..8ca5630 --- /dev/null +++ b/cloud-modules/cloud-modules-vehicle-gateway/src/main/resources/mapper/VehicleConnectionMapper.xml @@ -0,0 +1,14 @@ + + + + + + + insert into car_one_click_operation + (vehicle_vin,user_name,password) + values + (#{vehicleVin},#{username},#{password}) + +