fix: 打印任务不显示的问题
This commit is contained in:
parent
93bef5c0ea
commit
41ad507f68
@ -107,6 +107,22 @@ public class PrintController implements PrintService {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空打印队列
|
||||
*
|
||||
* @return 清空结果
|
||||
*/
|
||||
@DeleteMapping("queue/clear")
|
||||
public Map<String, Object> clearQueue() {
|
||||
int clearedCount = printQueueService.clearQueue();
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("success", true);
|
||||
result.put("clearedCount", clearedCount);
|
||||
result.put("message", "队列已清空,共清空 " + clearedCount + " 个任务");
|
||||
result.put("timestamp", System.currentTimeMillis());
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索打印任务
|
||||
*
|
||||
|
||||
@ -64,6 +64,7 @@ public class PrintQueueService {
|
||||
* 打印任务内部类,封装打印请求和WebSocket会话
|
||||
*/
|
||||
private static class PrintTask {
|
||||
private final String id;
|
||||
private final PrintRequest printRequest;
|
||||
private final WebSocketMessageDTO messageDTO;
|
||||
private final Session session;
|
||||
@ -73,12 +74,17 @@ public class PrintQueueService {
|
||||
private String status; // queued, processing, completed, failed
|
||||
|
||||
public PrintTask(PrintRequest printRequest, WebSocketMessageDTO messageDTO, Session session) {
|
||||
this.id = "TASK_" + System.currentTimeMillis() + "_" + (int)(Math.random() * 1000);
|
||||
this.printRequest = printRequest;
|
||||
this.messageDTO = messageDTO;
|
||||
this.session = session;
|
||||
this.queuedTime = LocalDateTime.now();
|
||||
this.status = "queued";
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public PrintRequest getPrintRequest() {
|
||||
return printRequest;
|
||||
@ -124,6 +130,7 @@ public class PrintQueueService {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
map.put("id", id);
|
||||
map.put("fileUrl", printRequest.getFileUrl());
|
||||
map.put("printerName", printRequest.getPrinterName());
|
||||
map.put("status", status);
|
||||
@ -224,6 +231,7 @@ public class PrintQueueService {
|
||||
|
||||
try {
|
||||
// 执行打印
|
||||
Thread.sleep(20000L);
|
||||
printService.print(printRequest);
|
||||
log.info("打印任务完成: {}", printRequest.getFileUrl());
|
||||
|
||||
@ -362,6 +370,19 @@ public class PrintQueueService {
|
||||
return maxQueueSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空打印队列
|
||||
* 注意:此操作不会影响当前正在处理的任务
|
||||
*
|
||||
* @return 清空的任务数量
|
||||
*/
|
||||
public int clearQueue() {
|
||||
int clearedCount = printQueue.size();
|
||||
printQueue.clear();
|
||||
log.info("打印队列已清空,共清空 {} 个任务", clearedCount);
|
||||
return clearedCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取历史服务实例
|
||||
*
|
||||
|
||||
Loading…
Reference in New Issue
Block a user