feat():获取ip连接
parent
525a4eeb5a
commit
6d462b5228
|
@ -65,19 +65,18 @@ public class VehicleInstanceServiceImpl implements VehicleInstanceService {
|
||||||
* 车辆结果对象
|
* 车辆结果对象
|
||||||
*
|
*
|
||||||
* @param vehicleInstanceListReq 车辆查询
|
* @param vehicleInstanceListReq 车辆查询
|
||||||
*
|
|
||||||
* @return 车辆对象
|
* @return 车辆对象
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public PageList<VehicleInstanceResp> queryList (VehicleInstanceListReq vehicleInstanceListReq) {
|
public PageList<VehicleInstanceResp> queryList(VehicleInstanceListReq vehicleInstanceListReq) {
|
||||||
Stream<VehicleInstance> stream = LocalContainer.vehicleDataMap.values()
|
Stream<VehicleInstance> stream = LocalContainer.vehicleDataMap.values()
|
||||||
.stream();
|
.stream();
|
||||||
if (StringUtils.isNotBlank(vehicleInstanceListReq.getVin())){
|
if (StringUtils.isNotBlank(vehicleInstanceListReq.getVin())) {
|
||||||
stream = stream.filter(vehicleInstance ->
|
stream = stream.filter(vehicleInstance ->
|
||||||
vehicleInstance.getVin().contains(vehicleInstanceListReq.getVin()));
|
vehicleInstance.getVin().contains(vehicleInstanceListReq.getVin()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vehicleInstanceListReq.isOnline()){
|
if (vehicleInstanceListReq.isOnline()) {
|
||||||
stream = stream.sorted(Comparator.comparingInt(o -> (o.isOnline() ? 0 : 1)));
|
stream = stream.sorted(Comparator.comparingInt(o -> (o.isOnline() ? 0 : 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,27 +98,31 @@ public class VehicleInstanceServiceImpl implements VehicleInstanceService {
|
||||||
* @param vin vin
|
* @param vin vin
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void vehicleClientInit (String vin) {
|
public void vehicleClientInit(String vin) {
|
||||||
log.info("vin[{}],开始上线", vin);
|
log.info("vin[{}],开始上线", vin);
|
||||||
VehicleInstance vehicleInstance = LocalContainer.getVehicleInstance(vin);
|
VehicleInstance vehicleInstance = LocalContainer.getVehicleInstance(vin);
|
||||||
if (vehicleInstance == null){
|
if (vehicleInstance == null) {
|
||||||
throw new RuntimeException("没有【"+vin+"】车辆");
|
throw new RuntimeException("没有【" + vin + "】车辆");
|
||||||
}
|
}
|
||||||
String timestamp = String.valueOf(System.currentTimeMillis());
|
String timestamp = String.valueOf(System.currentTimeMillis());
|
||||||
VehicleConnectionReq connectionReq = VehicleConnectionReq.builder()
|
VehicleConnectionReq connectionReq = VehicleConnectionReq.builder()
|
||||||
.vin(vin)
|
.vin(vin)
|
||||||
.timestamp(timestamp)
|
.timestamp(timestamp)
|
||||||
.userName(MD5Util.encrypted(vin+timestamp))
|
.userName(MD5Util.encrypted(vin + timestamp))
|
||||||
.nonce(MD5Util.encrypted(UUID.randomUUID().toString().replace("-", "")))
|
.nonce(MD5Util.encrypted(UUID.randomUUID().toString().replace("-", "")))
|
||||||
.build();
|
.build();
|
||||||
Result<MqttServerModel> result = clientAdmin.vehicleConnection(connectionReq);
|
Result<MqttServerModel> result = clientAdmin.vehicleConnection(connectionReq);
|
||||||
if (result.getCode() != 200){
|
log.info(result);
|
||||||
|
// Result<MqttServerModel> result = clientAdmin.getIp(connectionReq);
|
||||||
|
if (result.getCode() != 200) {
|
||||||
log.error("车辆:[{}],申请上线异常:[{}]", vin, result.getMsg());
|
log.error("车辆:[{}],申请上线异常:[{}]", vin, result.getMsg());
|
||||||
throw new RuntimeException("远程服务器没有【"+vin+"】车辆");
|
throw new RuntimeException("远程服务器没有【" + vin + "】车辆");
|
||||||
}
|
}
|
||||||
MqttServerModel mqttServerModel = result.getData();
|
MqttServerModel mqttServerModel = result.getData();
|
||||||
|
// broker:39.98.38.57 topic:0
|
||||||
|
// broker:39.98.50.223 topic:1
|
||||||
MqttProperties mqttProperties = MqttProperties.builder()
|
MqttProperties mqttProperties = MqttProperties.builder()
|
||||||
.broker(mqttServerModel.getBroker())
|
.broker("tcp://"+mqttServerModel.getBroker()+":1883")
|
||||||
.topic(mqttServerModel.getTopic())
|
.topic(mqttServerModel.getTopic())
|
||||||
.clientId(vin)
|
.clientId(vin)
|
||||||
.username(connectionReq.getUserName())
|
.username(connectionReq.getUserName())
|
||||||
|
@ -127,16 +130,16 @@ public class VehicleInstanceServiceImpl implements VehicleInstanceService {
|
||||||
.build();
|
.build();
|
||||||
vehicleInstance.setMqttProperties(mqttProperties);
|
vehicleInstance.setMqttProperties(mqttProperties);
|
||||||
vehicleInstance.initClient();
|
vehicleInstance.initClient();
|
||||||
|
|
||||||
log.info("vin[{}],上线成功", vin);
|
log.info("vin[{}],上线成功", vin);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 车辆客户端关闭
|
* 车辆客户端关闭
|
||||||
|
*
|
||||||
* @param vin vin
|
* @param vin vin
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void vehicleClientClose (String vin) {
|
public void vehicleClientClose(String vin) {
|
||||||
VehicleInstance vehicleInstance = LocalContainer.getVehicleInstance(vin);
|
VehicleInstance vehicleInstance = LocalContainer.getVehicleInstance(vin);
|
||||||
vehicleInstance.closeClient();
|
vehicleInstance.closeClient();
|
||||||
}
|
}
|
||||||
|
@ -147,7 +150,7 @@ public class VehicleInstanceServiceImpl implements VehicleInstanceService {
|
||||||
* @param checkPositionReq 切换轨迹
|
* @param checkPositionReq 切换轨迹
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void checkPosition (CheckPositionReq checkPositionReq) {
|
public void checkPosition(CheckPositionReq checkPositionReq) {
|
||||||
VehicleInstance vehicleInstance = LocalContainer.getVehicleInstance(checkPositionReq.getVin());
|
VehicleInstance vehicleInstance = LocalContainer.getVehicleInstance(checkPositionReq.getVin());
|
||||||
List<PositionModel> positionModelList =
|
List<PositionModel> positionModelList =
|
||||||
this.positionRouteService.getPositionModelByRouteName(checkPositionReq.getPositionCode());
|
this.positionRouteService.getPositionModelByRouteName(checkPositionReq.getPositionCode());
|
||||||
|
@ -161,11 +164,11 @@ public class VehicleInstanceServiceImpl implements VehicleInstanceService {
|
||||||
* @param msgReq
|
* @param msgReq
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void msg (MsgReq msgReq) {
|
public void msg(MsgReq msgReq) {
|
||||||
VehicleInstance vehicleInstance = LocalContainer.getVehicleInstance(msgReq.getVin());
|
VehicleInstance vehicleInstance = LocalContainer.getVehicleInstance(msgReq.getVin());
|
||||||
switch (msgReq.getMsgCode()){
|
switch (msgReq.getMsgCode()) {
|
||||||
case "上报" -> {
|
case "上报" -> {
|
||||||
if(vehicleInstance.getVehicleThread() == null){
|
if (vehicleInstance.getVehicleThread() == null) {
|
||||||
vehicleInstance.initVehicleThread();
|
vehicleInstance.initVehicleThread();
|
||||||
}
|
}
|
||||||
vehicleInstance.startSend();
|
vehicleInstance.startSend();
|
||||||
|
@ -182,7 +185,7 @@ public class VehicleInstanceServiceImpl implements VehicleInstanceService {
|
||||||
* @param gearReq
|
* @param gearReq
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void gear (GearReq gearReq) {
|
public void gear(GearReq gearReq) {
|
||||||
VehicleInstance vehicleInstance = LocalContainer.getVehicleInstance(gearReq.getVin());
|
VehicleInstance vehicleInstance = LocalContainer.getVehicleInstance(gearReq.getVin());
|
||||||
vehicleInstance.setGear(gearReq.getGear());
|
vehicleInstance.setGear(gearReq.getGear());
|
||||||
}
|
}
|
||||||
|
@ -195,7 +198,7 @@ public class VehicleInstanceServiceImpl implements VehicleInstanceService {
|
||||||
* @param statusValue 状态值
|
* @param statusValue 状态值
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void editStatus (String vin, String statusKey, Integer statusValue) {
|
public void editStatus(String vin, String statusKey, Integer statusValue) {
|
||||||
VehicleInstance vehicleInstance = LocalContainer.getVehicleInstance(vin);
|
VehicleInstance vehicleInstance = LocalContainer.getVehicleInstance(vin);
|
||||||
VehicleData vehicleData = vehicleInstance.getVehicleData();
|
VehicleData vehicleData = vehicleInstance.getVehicleData();
|
||||||
ReflectUtils.invokeSetter(vehicleData, statusKey, statusValue);
|
ReflectUtils.invokeSetter(vehicleData, statusKey, statusValue);
|
||||||
|
|
|
@ -12,13 +12,16 @@ import com.muyu.vehicle.api.req.VehicleConnectionReq;
|
||||||
* @description: 客户端的管理
|
* @description: 客户端的管理
|
||||||
* @Date 2023-11-28 上午 10:20
|
* @Date 2023-11-28 上午 10:20
|
||||||
*/
|
*/
|
||||||
@BaseRequest(baseURL = "${adminHost}")
|
@BaseRequest(
|
||||||
|
baseURL = "${adminHost}"
|
||||||
|
)
|
||||||
public interface ClientAdmin {
|
public interface ClientAdmin {
|
||||||
|
|
||||||
@Post("${adminTopicUri}")
|
@Post("${adminTopicUri}")
|
||||||
public Result<MqttServerModel> vehicleConnection(@JSONBody VehicleConnectionReq vehicleConnectionReq);
|
public Result<MqttServerModel> vehicleConnection(@JSONBody VehicleConnectionReq vehicleConnectionReq);
|
||||||
//
|
//
|
||||||
// @Post("/fluxmq/getIp")
|
|
||||||
// public String getIp();
|
// @Post(url = "${adminTopicUri}", headers = "Content-Type=application/json")
|
||||||
|
// public Result<MqttServerModel> getIp(@JSONBody VehicleConnectionReq vehicleConnectionReq);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,8 +76,8 @@ logging:
|
||||||
# http调用框架
|
# http调用框架
|
||||||
forest:
|
forest:
|
||||||
max-connections: 1000 # 连接池最大连接数
|
max-connections: 1000 # 连接池最大连接数
|
||||||
connect-timeout: 3000 # 连接超时时间,单位为毫秒
|
connect-timeout: 30000 # 连接超时时间,单位为毫秒
|
||||||
read-timeout: 3000 # 数据读取超时时间,单位为毫秒
|
read-timeout: 30000 # 数据读取超时时间,单位为毫秒
|
||||||
variables:
|
variables:
|
||||||
adminHost: ${mqtt.admin.host}
|
adminHost: ${mqtt.admin.host}
|
||||||
adminTopicUri: ${mqtt.admin.topic-uri}
|
adminTopicUri: ${mqtt.admin.topic-uri}
|
||||||
|
@ -87,8 +87,8 @@ forest:
|
||||||
mqtt:
|
mqtt:
|
||||||
server:
|
server:
|
||||||
host: tcp://39.98.45.160:1883
|
host: tcp://39.98.45.160:1883
|
||||||
topic: test1
|
topic: topic1
|
||||||
admin:
|
admin:
|
||||||
host: http://127.0.0.1:8081
|
host: http://127.0.0.1:8081/
|
||||||
topic-uri: /fluxmq/getIp
|
topic-uri: fluxmq/getIp
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue