Merge remote-tracking branch 'origin/dev' into dev
commit
2695602972
|
@ -11,6 +11,9 @@
|
|||
|
||||
<artifactId>cloud-common-rabbit</artifactId>
|
||||
|
||||
<description>
|
||||
cloud-common-rabbit 模块,提供RabbitMq消息队列的相关配置
|
||||
</description>
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
|
|
|
@ -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<String, MessageValueListResp> {
|
||||
public class AllMessageValueCacheService extends CacheAbsBacis<String, List<MessageValueListResp>> {
|
||||
|
||||
|
||||
@Override
|
||||
|
|
|
@ -48,9 +48,9 @@ public class MessageValueController {
|
|||
@Operation(summary = "报文数据列表", description = "根据报文类别, 报文模版筛选报文数据")
|
||||
public Result<List<MessageValueListResp>> findAll(@RequestBody MessageValueReq messageValueReq) {
|
||||
List<MessageValueListResp> 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>) messageValueListResp);
|
||||
// }
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
|
@ -102,6 +102,7 @@ public class MessageValueController {
|
|||
@Operation(summary = "根据报文模版id查询报文数据", description = "根据报文模版id查询报文数据")
|
||||
public Result<List<MessageValueListResp>> findByTemplateId(@PathVariable("templateId") Long templateId) {
|
||||
List<MessageValueListResp> list = messageValueService.findByTemplateId(templateId);
|
||||
allMessageValueCacheService.put(String.valueOf(templateId), list);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
|
|
|
@ -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<TableDataInfo<VehicleManageResp>> getVehicleList(@RequestBody VehicleManageReq vehicleManageReq) {
|
||||
startPage();
|
||||
List<VehicleManageResp> list = vehicleService.getVehicleList(vehicleManageReq);
|
||||
//将车辆信息存到Redis
|
||||
// 将车辆信息存到Redis
|
||||
// for (VehicleManageResp resp : list) {
|
||||
// allVehicleCacheService.put(resp.getVehicleVin(), resp);
|
||||
// }
|
||||
List<Vehicle> vehicleList = vehicleService.list();
|
||||
vehicleList.forEach(vehicle -> {
|
||||
vehicleCacheService.put(vehicle.getVehicleVin(), vehicle);
|
||||
|
|
|
@ -48,14 +48,17 @@ public class VehicleTypeController {
|
|||
* 查询所有车辆类型
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(path = "/", method = RequestMethod.POST)
|
||||
@RequestMapping(path = "/findAll", method = RequestMethod.POST)
|
||||
@Operation(summary = "车辆类型列表",description = "车辆类型列表")
|
||||
public Result<List<VehicleType>> findAll(){
|
||||
List<VehicleType> 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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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<Vehicle> {
|
|||
})
|
||||
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<FenceGroup> showBoundFenceGroup(@Param("fenceGroupId") Long fenceGroupId);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -30,11 +30,6 @@ public interface ElectService extends IService<Fence> {
|
|||
*/
|
||||
List<Fence> mapShow(@Param("fenceId") Long fenceId);
|
||||
|
||||
// /**
|
||||
// * 根据id查询车辆
|
||||
// */
|
||||
// Fence boundFence(@Param("fenceId") Long fenceId);
|
||||
|
||||
/**
|
||||
* 查询电子围栏(终版)
|
||||
*/
|
||||
|
|
|
@ -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<Vehicle> {
|
|||
*/
|
||||
void boundFenceGroup(BoundFenceGroupReq boundFenceGroupReq);
|
||||
|
||||
/**
|
||||
* 查询绑定围栏组信息
|
||||
* @param fenceGroupId
|
||||
* @return
|
||||
*/
|
||||
List<FenceGroup> showBoundFenceGroup(@Param("fenceGroupId") Long fenceGroupId);
|
||||
|
||||
}
|
||||
|
|
|
@ -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<MessageValueListResp> 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<String, Object> stringObjectEntry : jsonObject) {
|
||||
// log.info(stringObjectEntry.getKey() + ":" + stringObjectEntry.getValue());
|
||||
// }
|
||||
// return jsonObject;
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -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<FenceGroup> showBoundFenceGroup(Long fenceGroupId) {
|
||||
List<FenceGroup> fenceGroups = vehicleMapper.showBoundFenceGroup(fenceGroupId);
|
||||
return fenceGroups;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -126,8 +126,8 @@ public class DelInstance implements ApplicationListener<ContextClosedEvent> {
|
|||
try{
|
||||
log.info("=======>删除实例");
|
||||
delInstance();
|
||||
redisTemplate.delete("instanceIds");
|
||||
redisTemplate.delete("instanceList");
|
||||
// redisTemplate.delete("instanceIds");
|
||||
// redisTemplate.delete("instanceList");
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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<String,String> redisTemplate(RedisConnectionFactory redisConnectionFactory){
|
||||
RedisTemplate<String, String> redisTemplate = new RedisTemplate<>();
|
||||
redisTemplate.setConnectionFactory(redisConnectionFactory);
|
||||
|
||||
redisTemplate.setKeySerializer(new StringRedisSerializer());
|
||||
redisTemplate.setValueSerializer(new Jackson2JsonRedisSerializer<Object>(Object.class));
|
||||
|
||||
redisTemplate.setHashKeySerializer(new StringRedisSerializer());
|
||||
redisTemplate.setHashValueSerializer(new StringRedisSerializer());
|
||||
return redisTemplate;
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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:
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.muyu.cloud.vehicle.gateway.aliyun.mapper.VehicleConnectionMapper">
|
||||
|
||||
|
||||
<insert id="addConnect">
|
||||
insert into car_one_click_operation
|
||||
(vehicle_vin,user_name,password)
|
||||
values
|
||||
(#{vehicleVin},#{username},#{password})
|
||||
</insert>
|
||||
</mapper>
|
Loading…
Reference in New Issue