fix: 格式化时间
This commit is contained in:
parent
d00cf7a5c2
commit
93bef5c0ea
@ -16,6 +16,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
// 使用完全限定名称避免与自定义PrintService接口冲突
|
||||
import java.awt.print.PrinterJob;
|
||||
import java.io.File;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@ -144,7 +145,13 @@ public class PrintController implements PrintService {
|
||||
taskMap.put("fileName", extractFileName(task.getFileUrl()));
|
||||
taskMap.put("printer", task.getPrinter());
|
||||
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());
|
||||
return taskMap;
|
||||
})
|
||||
|
||||
@ -4,6 +4,7 @@ import com.goeing.printserver.main.domain.bo.PrintOption;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@ -40,16 +41,27 @@ public class PrintTask {
|
||||
*/
|
||||
public Map<String, Object> toMap() {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
map.put("fileUrl", fileUrl);
|
||||
map.put("printerName", printer);
|
||||
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) {
|
||||
map.put("startTime", startTime);
|
||||
map.put("startTime", startTime.format(formatter));
|
||||
}
|
||||
|
||||
if (endTime != null) {
|
||||
map.put("endTime", endTime);
|
||||
map.put("endTime", endTime.format(formatter));
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
}
|
||||
@ -12,6 +12,7 @@ import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -121,16 +122,27 @@ public class PrintQueueService {
|
||||
|
||||
public Map<String, Object> toMap() {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
map.put("fileUrl", printRequest.getFileUrl());
|
||||
map.put("printerName", printRequest.getPrinterName());
|
||||
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) {
|
||||
map.put("startTime", startTime);
|
||||
map.put("startTime", startTime.format(formatter));
|
||||
}
|
||||
|
||||
if (endTime != null) {
|
||||
map.put("endTime", endTime);
|
||||
map.put("endTime", endTime.format(formatter));
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user