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