fix: 格式化时间

This commit is contained in:
lifangliang 2025-08-29 15:18:19 +08:00
parent d00cf7a5c2
commit 93bef5c0ea
3 changed files with 38 additions and 7 deletions

View File

@ -16,6 +16,7 @@ import org.springframework.web.bind.annotation.*;
// 使用完全限定名称避免与自定义PrintService接口冲突 // 使用完全限定名称避免与自定义PrintService接口冲突
import java.awt.print.PrinterJob; import java.awt.print.PrinterJob;
import java.io.File; import java.io.File;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
@ -144,7 +145,13 @@ public class PrintController implements PrintService {
taskMap.put("fileName", extractFileName(task.getFileUrl())); taskMap.put("fileName", extractFileName(task.getFileUrl()));
taskMap.put("printer", task.getPrinter()); taskMap.put("printer", task.getPrinter());
taskMap.put("status", task.getStatus()); taskMap.put("status", task.getStatus());
taskMap.put("createTime", task.getQueuedTime()); // 格式化创建时间为 yyyy-MM-dd HH:mm:ss
if (task.getQueuedTime() != null) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
taskMap.put("createTime", task.getQueuedTime().format(formatter));
} else {
taskMap.put("createTime", "N/A");
}
taskMap.put("fileUrl", task.getFileUrl()); taskMap.put("fileUrl", task.getFileUrl());
return taskMap; return taskMap;
}) })

View File

@ -4,6 +4,7 @@ import com.goeing.printserver.main.domain.bo.PrintOption;
import lombok.Data; import lombok.Data;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -40,16 +41,27 @@ public class PrintTask {
*/ */
public Map<String, Object> toMap() { public Map<String, Object> toMap() {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
map.put("fileUrl", fileUrl); map.put("fileUrl", fileUrl);
map.put("printerName", printer); map.put("printerName", printer);
map.put("status", status); map.put("status", status);
map.put("queuedTime", queuedTime);
// 格式化时间字段
if (queuedTime != null) {
map.put("queuedTime", queuedTime.format(formatter));
} else {
map.put("queuedTime", "N/A");
}
if (startTime != null) { if (startTime != null) {
map.put("startTime", startTime); map.put("startTime", startTime.format(formatter));
} }
if (endTime != null) { if (endTime != null) {
map.put("endTime", endTime); map.put("endTime", endTime.format(formatter));
} }
return map; return map;
} }
} }

View File

@ -12,6 +12,7 @@ import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.io.IOException; import java.io.IOException;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -121,16 +122,27 @@ public class PrintQueueService {
public Map<String, Object> toMap() { public Map<String, Object> toMap() {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
map.put("fileUrl", printRequest.getFileUrl()); map.put("fileUrl", printRequest.getFileUrl());
map.put("printerName", printRequest.getPrinterName()); map.put("printerName", printRequest.getPrinterName());
map.put("status", status); map.put("status", status);
map.put("queuedTime", queuedTime);
// 格式化时间字段
if (queuedTime != null) {
map.put("queuedTime", queuedTime.format(formatter));
} else {
map.put("queuedTime", "N/A");
}
if (startTime != null) { if (startTime != null) {
map.put("startTime", startTime); map.put("startTime", startTime.format(formatter));
} }
if (endTime != null) { if (endTime != null) {
map.put("endTime", endTime); map.put("endTime", endTime.format(formatter));
} }
return map; return map;
} }
} }