打印机状态
This commit is contained in:
parent
8a43ac80cf
commit
b55b4e87a6
@ -197,6 +197,65 @@ public class PrintController implements PrintService {
|
|||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取打印机连接状态
|
||||||
|
*
|
||||||
|
* @return 包含各种连接状态的详细信息
|
||||||
|
*/
|
||||||
|
@GetMapping("printers/status")
|
||||||
|
public Map<String, Object> getPrintersStatus() {
|
||||||
|
Map<String, Object> status = new HashMap<>();
|
||||||
|
|
||||||
|
// Java后端服务状态
|
||||||
|
Map<String, Object> backendStatus = new HashMap<>();
|
||||||
|
backendStatus.put("status", "connected");
|
||||||
|
backendStatus.put("uptime", getUptime());
|
||||||
|
backendStatus.put("timestamp", System.currentTimeMillis());
|
||||||
|
status.put("backend", backendStatus);
|
||||||
|
|
||||||
|
// WebSocket连接状态
|
||||||
|
Map<String, Object> websocketStatus = new HashMap<>();
|
||||||
|
boolean isWebSocketConnected = printerClient.isConnected();
|
||||||
|
websocketStatus.put("status", isWebSocketConnected ? "connected" : "disconnected");
|
||||||
|
websocketStatus.put("url", config.getWebsocketUrl());
|
||||||
|
websocketStatus.put("printerId", config.getPrinterId());
|
||||||
|
if (isWebSocketConnected) {
|
||||||
|
websocketStatus.put("connectionUrl", printerClient.getCurrentConnectionUrl());
|
||||||
|
}
|
||||||
|
websocketStatus.put("timestamp", System.currentTimeMillis());
|
||||||
|
status.put("websocket", websocketStatus);
|
||||||
|
|
||||||
|
// 本地打印机状态
|
||||||
|
Map<String, Object> printersStatus = new HashMap<>();
|
||||||
|
javax.print.PrintService[] printServices = PrinterJob.lookupPrintServices();
|
||||||
|
List<Map<String, Object>> printerList = Arrays.stream(printServices)
|
||||||
|
.map(service -> {
|
||||||
|
Map<String, Object> printer = new HashMap<>();
|
||||||
|
printer.put("name", service.getName());
|
||||||
|
printer.put("status", "available"); // 简化处理,假设所有检测到的打印机都可用
|
||||||
|
printer.put("isDefault", service.getName().equals(config.getDefaultPrinter()));
|
||||||
|
return printer;
|
||||||
|
})
|
||||||
|
.sorted((a, b) -> ((String) a.get("name")).compareTo((String) b.get("name")))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
printersStatus.put("count", printerList.size());
|
||||||
|
printersStatus.put("printers", printerList);
|
||||||
|
printersStatus.put("defaultPrinter", config.getDefaultPrinter());
|
||||||
|
printersStatus.put("timestamp", System.currentTimeMillis());
|
||||||
|
status.put("localPrinters", printersStatus);
|
||||||
|
|
||||||
|
// 打印队列状态
|
||||||
|
Map<String, Object> queueStatus = new HashMap<>();
|
||||||
|
queueStatus.put("queueSize", printQueueService.getQueueSize());
|
||||||
|
queueStatus.put("maxQueueSize", printQueueService.getMaxQueueSize());
|
||||||
|
queueStatus.put("currentTask", printQueueService.getCurrentTaskInfo());
|
||||||
|
queueStatus.put("timestamp", System.currentTimeMillis());
|
||||||
|
status.put("queue", queueStatus);
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存系统设置
|
* 保存系统设置
|
||||||
*
|
*
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user