160 lines
5.3 KiB
Java
160 lines
5.3 KiB
Java
package com.muyu.web.service.impl;
|
|
|
|
import com.alibaba.fastjson2.JSONArray;
|
|
import com.muyu.vehicle.VehicleInstance;
|
|
import com.muyu.vehicle.core.LocalContainer;
|
|
import com.muyu.web.domain.PositionRouteInfo;
|
|
import com.muyu.web.domain.model.PositionModel;
|
|
import com.muyu.web.domain.model.TaskModel;
|
|
import com.muyu.web.domain.resp.UnifiedTaskResp;
|
|
import com.muyu.web.service.PositionRouteService;
|
|
import com.muyu.web.service.VehicleInstanceService;
|
|
import com.muyu.web.service.VehicleUnifiedService;
|
|
import lombok.extern.log4j.Log4j2;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import java.util.List;
|
|
import java.util.Random;
|
|
|
|
/**
|
|
* @author DongZeLiang
|
|
* @version 1.0
|
|
* @description 一键设置业务实现层
|
|
* @date 2023/12/6
|
|
*/
|
|
@Log4j2
|
|
@Service
|
|
public class VehicleUnifiedServiceImpl implements VehicleUnifiedService {
|
|
|
|
@Autowired
|
|
private VehicleInstanceService vehicleInstanceService;
|
|
|
|
@Autowired
|
|
private PositionRouteService positionRouteService;
|
|
|
|
|
|
/**
|
|
* 任务执行模型
|
|
*/
|
|
private final TaskModel taskModel = new TaskModel();
|
|
|
|
/**
|
|
* 一键上线
|
|
*/
|
|
@Override
|
|
public void unifiedOnline () {
|
|
// 获取离线车辆VIN
|
|
List<String> vinList = LocalContainer.getOfflineVehicleInstance()
|
|
.stream()
|
|
.map(VehicleInstance::getVin)
|
|
.toList();
|
|
taskModel.submit("一键上线", vinList, (vin) -> {
|
|
vehicleInstanceService.vehicleClientStart(vin);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 一键离线
|
|
*/
|
|
@Override
|
|
public void unifiedOffline () {
|
|
// 获取在线车辆VIN
|
|
List<String> vinList = LocalContainer.getOnlineVehicleVin();
|
|
taskModel.submit("一键离线", vinList, (vin) -> {
|
|
vehicleInstanceService.vehicleClientClose(vin);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 一键上报
|
|
*/
|
|
@Override
|
|
public void unifiedSend () {
|
|
// 获取在线车辆VIN
|
|
List<String> vinList = LocalContainer.getOnlineVehicleVin();
|
|
// 获取到所有路径
|
|
List<PositionRouteInfo> positionRouteInfoList = positionRouteService.list();
|
|
// 路径长度
|
|
int positionSize = positionRouteInfoList.size();
|
|
// 随机数
|
|
Random random = new Random();
|
|
|
|
taskModel.submit("一键上报", vinList, (vin) -> {
|
|
// 随机一个路径结果
|
|
int positionIndex = random.nextInt(0, positionSize);
|
|
PositionRouteInfo positionRouteInfo = positionRouteInfoList.get(positionIndex);
|
|
String positionCode = positionRouteInfo.getName();
|
|
List<PositionModel> positionModelList = JSONArray.parseArray(positionRouteInfo.getRouteData(), String.class)
|
|
.stream()
|
|
.map(PositionModel::strBuild)
|
|
.toList();
|
|
VehicleInstance vehicleInstance = LocalContainer.getVehicleInstance(vin);
|
|
// 设置车辆路径
|
|
vehicleInstance.settingPosition(positionModelList);
|
|
vehicleInstance.setPositionCode(positionCode);
|
|
// 设置车辆档位
|
|
vehicleInstance.setGear("D");
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 一键重置路径
|
|
*/
|
|
@Override
|
|
public void unifiedPosition () {
|
|
// 获取在线车辆VIN
|
|
List<String> vinList = LocalContainer.getOnlineVehicleVin();
|
|
// 获取到所有路径
|
|
List<PositionRouteInfo> positionRouteInfoList = positionRouteService.list();
|
|
// 路径长度
|
|
int positionSize = positionRouteInfoList.size();
|
|
// 随机数
|
|
Random random = new Random();
|
|
|
|
taskModel.submit("一键重置路径", vinList, (vin) -> {
|
|
// 随机一个路径结果
|
|
int positionIndex = random.nextInt(0, positionSize);
|
|
PositionRouteInfo positionRouteInfo = positionRouteInfoList.get(positionIndex);
|
|
String positionCode = positionRouteInfo.getName();
|
|
List<PositionModel> positionModelList = JSONArray.parseArray(positionRouteInfo.getRouteData(), String.class)
|
|
.stream()
|
|
.map(PositionModel::strBuild)
|
|
.toList();
|
|
VehicleInstance vehicleInstance = LocalContainer.getVehicleInstance(vin);
|
|
// 设置车辆路径
|
|
vehicleInstance.settingPosition(positionModelList);
|
|
vehicleInstance.setPositionCode(positionCode);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 一键取消上报
|
|
*/
|
|
@Override
|
|
public void unifiedStop () {
|
|
// 获取在线车辆VIN
|
|
List<String> vinList = LocalContainer.getOnlineVehicleVin();
|
|
taskModel.submit("一键取消上报", vinList, (vin) -> {
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 一键执行状态
|
|
*
|
|
* @return 一键执行状态
|
|
*/
|
|
@Override
|
|
public UnifiedTaskResp unifiedStatus() {
|
|
boolean unifiedStatus = this.taskModel.getUnifiedStatus().get();
|
|
return UnifiedTaskResp.builder()
|
|
.unifiedStatus(unifiedStatus)
|
|
.taskErrorSum(this.taskModel.getErrorSum())
|
|
.taskExecutionSum(this.taskModel.getTaskExecutionSum())
|
|
.taskSuccessSum(this.taskModel.getSuccessSum())
|
|
.taskName(this.taskModel.getTaskName())
|
|
.taskStartTime(System.currentTimeMillis() - this.taskModel.getTaskStartTime())
|
|
.build();
|
|
}
|
|
}
|