add:第一版测试版本。

This commit is contained in:
2025-12-15 10:42:02 +08:00
parent 98e0bbcaa6
commit cd483c81d1
84 changed files with 3714 additions and 26 deletions

View File

@@ -0,0 +1,31 @@
package org.nl.schedule.core.util;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
/**
* @author dsh
* 2025/12/2
*/
public class ScheduleUtil {
/**
* 获得之后num个天的时间
*
* @param num
* @return
*/
public static String getNextDay(int num) {
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DAY_OF_MONTH, num);
Date date = calendar.getTime();
TimeZone tz = TimeZone.getTimeZone("Asia/Shanghai");
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
df.setTimeZone(tz);
String nowAsISO = df.format(date);
return nowAsISO;
}
}

View File

@@ -0,0 +1,153 @@
package org.nl.schedule.core.websocket;
import cn.hutool.core.map.MapUtil;
import com.alibaba.fastjson.JSON;
import jakarta.websocket.*;
import jakarta.websocket.server.PathParam;
import jakarta.websocket.server.ServerEndpoint;
import lombok.Data;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArraySet;
/**
* @author dsh
* 2025/11/26
*/
@Slf4j
@Getter
@Component
@ServerEndpoint("/WebSocket/VehicleInfo/{sid}")
public class WebSocketVehicleInfoServer {
/**
* concurrent包的线程安全Set用来存放每个客户端对应的MyWebSocket对象。
*/
private static CopyOnWriteArraySet<WebSocketVehicleInfoServer> webSocketSet = new CopyOnWriteArraySet<>();
/**
* 静态变量,用来记录当前在线连接数。应该把它设计成线程安全的。
*/
private static int onlineCount = 0;
/**
* 与某个客户端的连接会话,需要通过它来给客户端发送数据
*/
private Session session;
/**
* 接收userId
*/
private String sid = "";
/**
* 默认语言
*/
private String lang = "zh";
/**
* 连接建立成功调用的方法
*/
@OnOpen
public void onOpen(Session session, @PathParam("sid") String sid) {
this.session = session;
// 获取查询参数中的语言设置
String queryString = session.getRequestURI().getQuery();
if (queryString != null) {
String[] params = queryString.split("&");
for (String param : params) {
if (param.startsWith("lang=")) {
// 获取lang参数值
this.lang = param.substring(5);
break;
}
}
}
//如果存在就先删除一个,防止重复推送消息
webSocketSet.removeIf(webSocket -> webSocket.sid.equals(sid));
webSocketSet.add(this);
//在线数加1
addOnlineCount();
log.info("VehicleWS:sid{}连接成功,当前在线人数为{}", sid, getOnlineCount());
this.sid = sid;
}
/**
* 连接关闭调用的方法
*/
@OnClose
public void onClose() {
webSocketSet.remove(this);
//在线数减1
subOnlineCount();
log.info("VehicleWS:sid{}关闭连接!当前在线人数为{}", sid, getOnlineCount());
}
/**
* 收到客户端消息后调用的方法
*
* @param message 客户端发送过来的消息
*/
@OnMessage
public void onMessage(String message, Session session) {
//System.out.println(webSocketSet.size() + "_接收到消息_" + session.getId());
}
@OnError
public void onError(Session session, Throwable error) {
//log.error("发生错误");
webSocketSet.remove(session);
error.printStackTrace();
}
public Session getSession() {
return session;
}
// 获取语言的方法
public String getLang() {
return lang;
}
// 推送方法
public void sendMessage(String message) throws IOException {
this.session.getBasicRemote().sendText(message);
}
public void sendDataToClient(Map<String, Object> data) {
try {
if (this.session != null&& MapUtil.isNotEmpty(data)) {
this.session.getBasicRemote().sendText(JSON.toJSONString(data));
}
} catch (IOException e) {
log.error("发送消息给客户端失败", e);
}
}
public static synchronized int getOnlineCount() {
return onlineCount;
}
public static CopyOnWriteArraySet<WebSocketVehicleInfoServer> getWebSocketSet() {
return webSocketSet;
}
public void setSession(Session session) {
this.session = session;
}
public static synchronized void addOnlineCount() {
WebSocketVehicleInfoServer.onlineCount++;
}
public static synchronized void subOnlineCount() {
WebSocketVehicleInfoServer.onlineCount--;
}
}

View File

@@ -0,0 +1,33 @@
package org.nl.schedule.modular.map.provider;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.nl.api.schedule.map.api.ScheduleMapAPI;
import org.nl.exception.BadRequestException;
import org.springframework.stereotype.Service;
/**
* @author dsh
* 2025/12/13
*/
@Slf4j
@Service
public class ScheduleMapAPIProvider implements ScheduleMapAPI {
@Override
public HttpResponse queryCurrentMapPointInfo() {
log.info("获取当前地图中的所有POI");
HttpResponse result = null;
try {
result = HttpRequest.get("http://127.0.0.1:8011/api/core/artifact/v1/pois")
.execute();
log.info("获取当前地图中的所有POI响应结果:{}",result.body());
}catch (Exception e){
log.info("获取当前地图中的所有POI失败");
}
return result;
}
}

View File

@@ -0,0 +1,57 @@
package org.nl.schedule.modular.setting.provider;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.nl.api.schedule.setting.api.ScheduleSettingAPI;
import org.nl.api.schedule.setting.core.ScheduleAPISettingChargeParam;
import org.nl.api.schedule.setting.core.ScheduleAPISettingSpeedParam;
import org.nl.exception.BadRequestException;
import org.springframework.stereotype.Service;
/**
* @author dsh
* 2025/12/8
*/
@Slf4j
@Service
public class ScheduleSettingAPIProvider implements ScheduleSettingAPI {
@Override
public HttpResponse settingSpeed(ScheduleAPISettingSpeedParam scheduleAPISettingSpeedParam) {
if (ObjectUtil.isEmpty(scheduleAPISettingSpeedParam)){
throw new BadRequestException("调度设置配送速度参数不能为空");
}
log.info("设置调度配送速度参数:{}", scheduleAPISettingSpeedParam);
HttpResponse result = null;
try {
result = HttpRequest.put("http://127.0.0.1:8011/system/motion/speed")
.body(String.valueOf(JSONObject.toJSON(scheduleAPISettingSpeedParam)))
.execute();
log.info("设置调度配送速度响应结果:{}",result.body());
}catch (Exception e){
log.info("调度设置配送速度失败");
}
return result;
}
@Override
public HttpResponse settingCharge(ScheduleAPISettingChargeParam scheduleAPISettingChargeParam) {
if (ObjectUtil.isEmpty(scheduleAPISettingChargeParam)){
throw new BadRequestException("调度设置充电参数不能为空");
}
log.info("设置调度充电参数:{}", scheduleAPISettingChargeParam);
HttpResponse result = null;
try {
result = HttpRequest.put("http://127.0.0.1:8011/system/charging/auto-threshold")
.body(String.valueOf(JSONObject.toJSON(scheduleAPISettingChargeParam)))
.execute();
log.info("设置调度充电响应结果:{}",result.body());
}catch (Exception e){
log.info("设置调度充电参数失败");
}
return result;
}
}

View File

@@ -0,0 +1,28 @@
package org.nl.schedule.modular.task.controller;
import jakarta.annotation.Resource;
import org.nl.schedule.modular.task.param.ScheduleTaskArrivedReportParam;
import org.nl.schedule.modular.task.service.ScheduleTaskService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
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;
/**
* @author dsh
* 2025/12/8
*/
@RestController
@RequestMapping("/api/scheduleTask")
public class ScheduleTaskRequestReportController {
@Resource
private ScheduleTaskService scheduleTaskService;
@PostMapping("/arrivedReport")
public ResponseEntity<Object> arrivedReport(@RequestBody ScheduleTaskArrivedReportParam scheduleTaskArrivedReportParam){
return new ResponseEntity<>(scheduleTaskService.taskArrivedReport(scheduleTaskArrivedReportParam), HttpStatus.OK);
}
}

View File

@@ -0,0 +1,30 @@
package org.nl.schedule.modular.task.param;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
/**
* @author dsh
* 2025/12/11
*/
@Data
public class ScheduleTaskArrivedReportParam {
/**
* 点位
*/
@NotBlank(message = "点位不能为空")
private String location;
/**
* 车号
*/
@NotBlank(message = "车号不能为空")
private String vehicle_number;
/**
* 任务号
*/
@NotBlank(message = "任务号不能为空")
private String task_code;
}

View File

@@ -0,0 +1,182 @@
package org.nl.schedule.modular.task.provider;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.nl.api.schedule.task.api.ScheduleTaskAPI;
import org.nl.api.schedule.task.core.ScheduleAPICreateOneClickTaskParam;
import org.nl.api.schedule.task.core.ScheduleAPICreateTaskParam;
import org.nl.exception.BadRequestException;
import org.nl.schedule.core.util.ScheduleUtil;
import org.springframework.stereotype.Service;
/**
* @author dsh
* 2025/12/1
*/
@Slf4j
@Service
public class ScheduleTaskAPIProvider implements ScheduleTaskAPI {
@Override
public HttpResponse createTask(ScheduleAPICreateTaskParam scheduleAPICreateTaskParam) {
String task_code = scheduleAPICreateTaskParam.getTask_code();
String destinations = scheduleAPICreateTaskParam.getDestinations();
String type = scheduleAPICreateTaskParam.getType();
if (StrUtil.isBlank(task_code)){
throw new BadRequestException("任务号不能为空");
}
if (StrUtil.isBlank(destinations)){
throw new BadRequestException("目标点不能为空");
}
if (StrUtil.isBlank(type)){
throw new BadRequestException("任务操作类型不能为空");
}
JSONObject request_body = new JSONObject();
request_body.put("deadline", ScheduleUtil.getNextDay(1));
if (StrUtil.isNotBlank(scheduleAPICreateTaskParam.getVehicle_number())){
request_body.put("intendedVehicle", scheduleAPICreateTaskParam.getVehicle_number());
}
JSONArray body_destinations = new JSONArray();
JSONObject body_destination = new JSONObject();
body_destination.put("locationName", destinations);
body_destination.put("operation", type);
body_destinations.add(body_destination);
request_body.put("destinations", body_destinations);
if (StrUtil.isNotBlank(scheduleAPICreateTaskParam.getPriority())){
request_body.put("priority", Integer.parseInt(scheduleAPICreateTaskParam.getPriority()));
}
log.info("下发调度任务参数:{}", request_body);
HttpResponse result = null;
try {
result = HttpRequest
.post("http://127.0.0.1:8011/tasks/"+scheduleAPICreateTaskParam.getTask_code())
.body(String.valueOf(request_body))
.execute();
log.info("下发调度任务响应结果:{}",result.body());
}catch (Exception e){
log.error("下发调度任务失败:{}",e.getMessage());
}
return result;
}
@Override
public HttpResponse cancelTask(String taskId) {
if (StrUtil.isBlank(taskId)){
throw new BadRequestException("任务号不能为空");
}
log.info("取消调度任务参数:{}", taskId);
HttpResponse result = null;
try {
result = HttpRequest
.post("http://127.0.0.1:8011/tasks/"+taskId+"/withdrawl")
.body(String.valueOf(new JSONObject()))
.execute();
log.info("取消调度任务响应结果:{}",result.body());
}catch (Exception e){
log.error("取消调度任务失败:{}",e.getMessage());
}
return result;
}
@Override
public HttpResponse queryTaskStatusByTaskId(String taskId) {
if (StrUtil.isBlank(taskId)){
throw new BadRequestException("任务号不能为空");
}
log.info("查询调度任务状态参数:{}", taskId);
HttpResponse result = null;
try {
result = HttpRequest
.get("http://127.0.0.1:8011/tasks/"+taskId)
.execute();
log.info("查询调度任务状态响应结果:{}",result.body());
}catch (Exception e){
log.error("查询调度任务状态失败:{}",e.getMessage());
}
return result;
}
@Override
public HttpResponse pauseTask(String taskId) {
if (StrUtil.isBlank(taskId)){
throw new BadRequestException("任务号不能为空");
}
log.info("暂停调度任务参数:{}", taskId);
HttpResponse result = null;
try {
result = HttpRequest
.post("http://127.0.0.1:8011/tasks/"+taskId+"/pause")
.body(String.valueOf(new JSONObject()))
.execute();
log.info("暂停调度任务响应结果:{}",result.body());
}catch (Exception e){
log.error("暂停调度任务失败:{}",e.getMessage());
}
return result;
}
@Override
public HttpResponse resumeTask(String taskId) {
if (StrUtil.isBlank(taskId)){
throw new BadRequestException("任务号不能为空");
}
log.info("恢复调度任务参数:{}", taskId);
HttpResponse result = null;
try {
result = HttpRequest
.post("http://127.0.0.1:8011/tasks/"+taskId+"/resume")
.body(String.valueOf(new JSONObject()))
.execute();
log.info("恢复调度任务响应结果:{}",result.body());
}catch (Exception e){
log.error("恢复调度任务失败:{}",e.getMessage());
}
return result;
}
@Override
public HttpResponse oneClickOperationTask(ScheduleAPICreateOneClickTaskParam scheduleAPICreateOneClickTaskParam) {
String task_code = scheduleAPICreateOneClickTaskParam.getTask_code();
String type = scheduleAPICreateOneClickTaskParam.getType();
String vehicleNumber = scheduleAPICreateOneClickTaskParam.getVehicle_number();
if (StrUtil.isBlank(task_code)){
throw new BadRequestException("任务号不能为空");
}
if (StrUtil.isBlank(type)){
throw new BadRequestException("任务操作类型不能为空");
}
if (StrUtil.isBlank(vehicleNumber)){
throw new BadRequestException("车号不能为空");
}
JSONObject request_body = new JSONObject();
request_body.put("vehicleNumber", vehicleNumber);
request_body.put("taskId",task_code);
request_body.put("taskType",type);
log.info("下发调度一键任务参数:{}", request_body);
HttpResponse result = null;
try {
result = HttpRequest
.post("http://127.0.0.1:8011/tasks/quick-create")
.body(String.valueOf(request_body))
.execute();
log.info("下发调度一键任务响应结果:{}",result.body());
}catch (Exception e){
log.error("下发调度一键任务失败:{}",e.getMessage());
}
return result;
}
}

View File

@@ -0,0 +1,13 @@
package org.nl.schedule.modular.task.service;
import org.nl.response.WebResponse;
import org.nl.schedule.modular.task.param.ScheduleTaskArrivedReportParam;
/**
* @author dsh
* 2025/12/2
*/
public interface ScheduleTaskService {
WebResponse taskArrivedReport(ScheduleTaskArrivedReportParam scheduleTaskArrivedReportParam);
}

View File

@@ -0,0 +1,88 @@
package org.nl.schedule.modular.task.service.impl;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.nl.api.setting.api.SettingAPI;
import org.nl.api.task.api.TaskAPI;
import org.nl.enums.YesOrNoEnum;
import org.nl.exception.BadRequestException;
import org.nl.response.WebResponse;
import org.nl.enums.ScheduleTaskReportStatusEnum;
import org.nl.schedule.modular.task.param.ScheduleTaskArrivedReportParam;
import org.nl.schedule.modular.task.service.ScheduleTaskService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
* @author dsh
* 2025/12/2
*/
@Slf4j
@Service
public class ScheduleTaskServiceImpl implements ScheduleTaskService {
@Resource
private TaskAPI taskAPI;
@Resource
private SettingAPI settingAPI;
@Override
public WebResponse taskArrivedReport(ScheduleTaskArrivedReportParam scheduleTaskArrivedReportParam) {
String location = scheduleTaskArrivedReportParam.getLocation();
String vehicle_number = scheduleTaskArrivedReportParam.getVehicle_number();
String task_code = scheduleTaskArrivedReportParam.getTask_code();
if (StrUtil.isBlank(location)) {
throw new BadRequestException("上报点位不能为空");
}
if (StrUtil.isBlank(vehicle_number)) {
throw new BadRequestException("上报车号不能为空");
}
if (StrUtil.isBlank(task_code)) {
throw new BadRequestException("上报任务号不能为空");
}
log.info("调度上报到达,参数:{}",scheduleTaskArrivedReportParam);
String status = taskAPI.taskOperationConfirm(task_code,vehicle_number);
if (StrUtil.isBlank(status)){
throw new BadRequestException("未找到该上报阶段");
}
ScheduleTaskReportStatusEnum scheduleTaskReportStatusEnum = ScheduleTaskReportStatusEnum.getByCode(status);
if (scheduleTaskReportStatusEnum == null) {
throw new BadRequestException("未找到该上报类型");
}
boolean flag = false;
// 到达时等待设置参数
JSONObject jsonObject = settingAPI.querySttingParamIsActiveByCode("call_arrival_waiting_time").getJSONObject("data");
String is_active = jsonObject.getString("is_active");
String arrive_waiting_time = jsonObject.getString("value");
if (StrUtil.isNotBlank(is_active) && YesOrNoEnum.YES.getCode().equals(is_active)){
switch (scheduleTaskReportStatusEnum){
case NOT_REPORTED:
boolean result = taskAPI.updateTaskReportStatusByCode(task_code, ScheduleTaskReportStatusEnum.REPORTED.getCode(),arrive_waiting_time);
if (!result) {
log.info("更新调度上报状态失败");
}
break;
case REPORTED:
log.info("已接收上报,但未确认操作");
break;
case FINISH_REPORTED:
flag = true;
log.info("确认操作");
break;
}
}else {
// 如果没有启用 到达时等待,则直接反馈调度成功。
flag = true;
}
if (flag) {
return WebResponse.requestOk();
}
throw new BadRequestException("未确认操作");
}
}

View File

@@ -0,0 +1,32 @@
package org.nl.schedule.modular.vehicle.controller;
import jakarta.validation.constraints.NotBlank;
import org.nl.schedule.modular.vehicle.service.VehicleService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author dsh
* 2025/11/25
*/
@RestController
@RequestMapping("/schedule/vehicle")
@Validated
public class VehicleController {
private final VehicleService vehicleService;
public VehicleController(VehicleService vehicleService) {
this.vehicleService = vehicleService;
}
@GetMapping("/getVehicleInfoByNumber/{vehicleNumber}")
public ResponseEntity<Object> getVehicleInfoByNumber(@PathVariable @NotBlank String vehicleNumber) {
return new ResponseEntity<>(vehicleService.getVehicleInfoByNumber(vehicleNumber), HttpStatus.OK);
}
}

View File

@@ -0,0 +1,70 @@
package org.nl.schedule.modular.vehicle.dto;
import lombok.Data;
import org.nl.schedule.modular.vehicle.entity.Location;
import java.io.Serializable;
import java.util.List;
/**
* @author dsh
* 2025/11/25
*/
@Data
public class VehicleInfoDto{
/**
* 车辆ID
*/
private String vehicleId;
/**
* 车辆编号
*/
private String vehicleNumber;
/**
* 车辆IP
*/
private String ip;
/**
* 电量
*/
private int batteryLevel;
/**
* 冰容量
*/
private int iceCapacity;
/**
* 水容量
*/
private int waterCapacity;
/**
* 信号类型
*/
private String signalType;
/**
* 信号强度
*/
private int signalStrength;
/**
* 异常信息集合
*/
private List<String> exceptions;
/**
* 当前位置
*/
private Location currentLocation;
/**
* 最后更新时间
*/
private String lastUpdated;
}

View File

@@ -0,0 +1,21 @@
package org.nl.schedule.modular.vehicle.entity;
import lombok.Data;
/**
* @author dsh
* 2025/11/25
*/
@Data
public class Location {
/**
* 楼层
*/
private String floor;
/**
* 房间
*/
private String room;
}

View File

@@ -0,0 +1,24 @@
package org.nl.schedule.modular.vehicle.service;
import org.nl.response.WebResponse;
import org.nl.schedule.modular.vehicle.dto.VehicleInfoDto;
import java.util.List;
/**
* @author dsh
* 2025/11/25
*/
public interface VehicleService {
List<VehicleInfoDto> getAllVehicles();
/**
* 根据车号获取车辆信息
* @param vehicleNumber
* @return VehicleInfoDto
*/
VehicleInfoDto getVehicleInfoByNumber(String vehicleNumber);
}

View File

@@ -0,0 +1,103 @@
package org.nl.schedule.modular.vehicle.service.impl;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.nl.api.task.api.TaskAPI;
import org.nl.response.WebResponse;
import org.nl.schedule.core.websocket.WebSocketVehicleInfoServer;
import org.nl.schedule.modular.vehicle.dto.VehicleInfoDto;
import org.nl.schedule.modular.vehicle.service.VehicleService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet;
/**
* @author dsh
* 2025/11/25
*/
@Slf4j
@Service
public class VehicleServiceImpl implements VehicleService {
private final ConcurrentHashMap<String, VehicleInfoDto> vehicleCache = new ConcurrentHashMap<>();
@Resource
private TaskAPI taskAPI;
/**
* 定时更新车辆信息(每秒执行)
*/
@Scheduled(fixedRate = 1000) // 每秒执行一次
public void updateVehicleInfo() {
try {
List<VehicleInfoDto> vehicles = getAllVehicles();
if (ObjectUtil.isNotEmpty(vehicles)) {
// 清空旧数据
vehicleCache.clear();
// 更新缓存
for (VehicleInfoDto vehicle : vehicles) {
vehicleCache.put(vehicle.getVehicleNumber(), vehicle);
}
log.debug("成功更新 {} 辆车辆信息", vehicles.size());
}
} catch (Exception e) {
log.error("更新车辆信息失败: {}", e.getMessage());
}
}
@Scheduled(fixedRate = 1000)
public void pushVehicleInfo(){
CopyOnWriteArraySet<WebSocketVehicleInfoServer> webSocketSet =
WebSocketVehicleInfoServer.getWebSocketSet();
if (webSocketSet.size() > 0) {
webSocketSet.forEach(c -> {
Map<String, Object> vehicleInfoMap = new HashMap<>();
vehicleInfoMap.put("vehicleInfo", getVehicleInfoByNumber(c.getSid()));
vehicleInfoMap.put("currentTask", taskAPI.queryCurrentTaskByVehicleNumber(c.getSid()));
c.sendDataToClient(vehicleInfoMap);
});
}
}
@Override
public List<VehicleInfoDto> getAllVehicles() {
String url = "http://127.0.0.1:8011/schedule/vehicles";
List<VehicleInfoDto> vehicles = new ArrayList<>();
try {
try (HttpResponse response = HttpRequest.get("http://127.0.0.1:8011/schedule/vehicles")
.setConnectionTimeout(10000)
.setReadTimeout(10000)
.execute()) {
if (response.isOk() && response.body() != null) {
// 获取响应体内容
String body = response.body();
vehicles = JSON.parseArray(body, VehicleInfoDto.class);
log.info(vehicles.toString());
}
}
}catch (Exception e) {
log.error("获取调度车辆信息失败:{}",e.getMessage());
}
return vehicles;
}
@Override
public VehicleInfoDto getVehicleInfoByNumber(String vehicleNumber) {
// 直接从缓存中获取
return vehicleCache.get(vehicleNumber);
}
}