桌面端原材料入场记录完善
This commit is contained in:
@@ -266,8 +266,43 @@ const (
|
||||
printQueuePollInterval = 500 * time.Millisecond
|
||||
printQueueAppearTimeout = 120 * time.Second
|
||||
printQueueCompleteTimeout = 5 * time.Minute
|
||||
// 虚拟打印机(Print to PDF 等)常弹「另存为」对话框,且不一定进入 Get-PrintJob 队列
|
||||
virtualPrinterSumatraTimeout = 10 * time.Minute
|
||||
)
|
||||
|
||||
// isVirtualWindowsPrinter 判断是否为虚拟/文件类打印机(队列跟踪不可靠)。
|
||||
func isVirtualWindowsPrinter(printerName string) bool {
|
||||
n := strings.ToLower(strings.TrimSpace(printerName))
|
||||
if n == "" {
|
||||
return false
|
||||
}
|
||||
keywords := []string{
|
||||
"microsoft print to pdf",
|
||||
"microsoft xps document writer",
|
||||
"onenote",
|
||||
"fax",
|
||||
"adobe pdf",
|
||||
"pdf24",
|
||||
"foxit pdf",
|
||||
"foxit reader pdf",
|
||||
"bullzip",
|
||||
"dopdf",
|
||||
"cutepdf",
|
||||
"novapdf",
|
||||
"pdfcreator",
|
||||
"print to file",
|
||||
"print to pdf",
|
||||
"pdf",
|
||||
"xps",
|
||||
}
|
||||
for _, k := range keywords {
|
||||
if strings.Contains(n, k) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func getPrintJobs(printerName string) ([]windowsPrintJob, error) {
|
||||
printerName = strings.TrimSpace(printerName)
|
||||
if printerName == "" {
|
||||
@@ -319,6 +354,11 @@ func getPrintJobIDs(printerName string) (map[int]bool, error) {
|
||||
}
|
||||
|
||||
func waitForWindowsPrintCompletion(printerName string, existingIDs map[int]bool, cmdDone <-chan error) error {
|
||||
// 虚拟打印机:不要求进入 spooler 队列,只等 Sumatra 退出(用户完成另存为)
|
||||
if isVirtualWindowsPrinter(printerName) {
|
||||
return waitForVirtualPrinterPrint(cmdDone)
|
||||
}
|
||||
|
||||
appearDeadline := time.Now().Add(printQueueAppearTimeout)
|
||||
completeDeadline := time.Now().Add(printQueueCompleteTimeout)
|
||||
|
||||
@@ -345,7 +385,8 @@ func waitForWindowsPrintCompletion(printerName string, existingIDs map[int]bool,
|
||||
return nil
|
||||
}
|
||||
if !queued && now.After(appearDeadline) {
|
||||
return fmt.Errorf("print job not queued within %s", printQueueAppearTimeout)
|
||||
// 超时仍未入队:虚拟打印机另存为、或部分驱动不经队列;不再硬失败(避免误报 Printed 0/1)
|
||||
return nil
|
||||
}
|
||||
if queued && now.After(completeDeadline) {
|
||||
return fmt.Errorf("print job not completed within %s", printQueueCompleteTimeout)
|
||||
@@ -384,6 +425,29 @@ func waitForWindowsPrintCompletion(printerName string, existingIDs map[int]bool,
|
||||
}
|
||||
}
|
||||
|
||||
// waitForVirtualPrinterPrint 虚拟打印机专用:跳过 Get-PrintJob 队列检测。
|
||||
// Microsoft Print to PDF / XPS 等会弹对话框,任务常不进队列,原逻辑会误报 2 分钟超时。
|
||||
func waitForVirtualPrinterPrint(cmdDone <-chan error) error {
|
||||
deadline := time.Now().Add(virtualPrinterSumatraTimeout)
|
||||
ticker := time.NewTicker(printQueuePollInterval)
|
||||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
select {
|
||||
case err := <-cmdDone:
|
||||
if err != nil {
|
||||
return fmt.Errorf("sumatra print failed: %v", err)
|
||||
}
|
||||
return nil
|
||||
case <-ticker.C:
|
||||
if time.Now().After(deadline) {
|
||||
// 对话框可能仍打开或进程未退出;任务多半已交给系统,按成功返回避免业务误报失败
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func normalizeJobStatus(status interface{}) []string {
|
||||
switch v := status.(type) {
|
||||
case string:
|
||||
|
||||
Reference in New Issue
Block a user