桌面端原材料入场记录完善

This commit is contained in:
2026-07-31 14:27:46 +08:00
parent 67f3acfd43
commit ef28b93909
13 changed files with 531 additions and 75 deletions

View File

@@ -57,11 +57,18 @@ public class PrintDotService : IPrintDotService
public async Task PrintAsync(string printerName, string pdfBase64, string jobName = "QH-MES", int copies = 1, CancellationToken ct = default)
{
if (string.IsNullOrWhiteSpace(printerName))
throw new InvalidOperationException("打印机名称不能为空");
if (string.IsNullOrWhiteSpace(pdfBase64))
throw new InvalidOperationException("打印内容为空PDF 生成失败");
// 去掉 data: 前缀
var content = pdfBase64.Trim();
var comma = content.IndexOf(',');
if (content.StartsWith("data:", StringComparison.OrdinalIgnoreCase) && comma >= 0)
content = content[(comma + 1)..];
if (string.IsNullOrWhiteSpace(content))
throw new InvalidOperationException("打印内容为空PDF 生成失败");
var payload = new
{
@@ -87,14 +94,46 @@ public class PrintDotService : IPrintDotService
{
var response = await ReceiveTextAsync(ws, cts.Token);
var resDoc = JsonNode.Parse(response);
var status = resDoc?["status"]?.GetValue<string>();
if (status == null) continue;
if (status == "success") return;
var rawMsg = resDoc?["message"]?.GetValue<string>() ?? "PrintDot 打印失败";
var status = TryReadJsonString(resDoc?["status"]);
if (string.IsNullOrWhiteSpace(status)) continue;
if (string.Equals(status, "success", StringComparison.OrdinalIgnoreCase)) return;
var rawMsg = TryReadJsonString(resDoc?["message"]) ?? "PrintDot 打印失败";
//update-begin---author:jiangxh ---date:20260731 for【PrintDot】队列未入队超时按软成功虚拟打印机-----------
if (IsPrintQueueAppearSoftSuccess(rawMsg))
{
return;
}
//update-end---author:jiangxh ---date:20260731 for【PrintDot】队列未入队超时按软成功虚拟打印机-----------
throw new InvalidOperationException(EnhanceErrorMessage(rawMsg));
}
}
private static string? TryReadJsonString(JsonNode? node)
{
if (node == null) return null;
try
{
if (node is JsonValue jv)
{
if (jv.TryGetValue<string>(out var s)) return s;
if (jv.TryGetValue<bool>(out var b)) return b ? "true" : "false";
return jv.ToJsonString().Trim('"');
}
return node.ToJsonString();
}
catch
{
return null;
}
}
/// <summary>PrintDot 队列入队超时:视为已提交(兼容旧版桥接器)。</summary>
private static bool IsPrintQueueAppearSoftSuccess(string? rawMsg)
{
if (string.IsNullOrWhiteSpace(rawMsg)) return false;
return rawMsg.Contains("print job not queued within", StringComparison.OrdinalIgnoreCase);
}
/// <summary>
/// 将 PrintDot 返回的部分英文错误转换为带本地处理步骤的中文提示。
/// 与 web 端 printDotBridge.ts::enhancePrintDotErrorMessage 行为一致,方便桌面端用户自助排查。