From 0bbfa0ba324412eac0871e8c8c3f4972f5c43d44 Mon Sep 17 00:00:00 2001 From: zpc Date: Sun, 16 Nov 2025 17:25:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=BC=E5=AE=B9=E7=89=B9=E6=AE=8A=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Business/OdfPortsController.cs | 83 ++++++++++++++++++- ZR.Admin.WebApi/appsettings.json | 10 +-- 2 files changed, 87 insertions(+), 6 deletions(-) diff --git a/ZR.Admin.WebApi/Controllers/Business/OdfPortsController.cs b/ZR.Admin.WebApi/Controllers/Business/OdfPortsController.cs index 01a8f11..0bfc7db 100644 --- a/ZR.Admin.WebApi/Controllers/Business/OdfPortsController.cs +++ b/ZR.Admin.WebApi/Controllers/Business/OdfPortsController.cs @@ -762,7 +762,8 @@ namespace ZR.Admin.WebApi.Controllers.Business /// /// 原始字符串 /// 日期+原因集合 - private List<(DateTime Date, string Reason)> ParseHistory(string historyRemarks) + [Obsolete] + private List<(DateTime Date, string Reason)> ParseHistoryf(string historyRemarks) { var result = new List<(DateTime, string)>(); @@ -801,6 +802,86 @@ namespace ZR.Admin.WebApi.Controllers.Business return result; } + /// + /// 超强健壮型历史备注解析器,支持以下所有日期格式: + /// - 英文:2022/5/3, 2022-10 24, 2022-10-24, 2021/ 12/2 + /// - 中文:2022年5月3日, 2022年5月3号 9:20 + /// - 时间:支持无秒,如 8:20、8:5、8:5:1、自动补零 + /// - 自动修复多余空格 + /// + /// 最终统一输出 yyyy-MM-dd HH:mm:ss + /// + private List<(DateTime Date, string Reason)> ParseHistory(string historyRemarks) + { + var list = new List<(DateTime, string)>(); + + if (string.IsNullOrWhiteSpace(historyRemarks)) + return list; + + // 支持: + // - yyyy/MM/dd + // - yyyy- MM dd + // - yyyy年M月d日 + // - yyyy年M月d号 + // - 时间可为 HH:mm 或 HH:mm:ss + var regex = new Regex( + @"(?\d{4})\s*(?:[-/年]\s*)?(?\d{1,2})\s*(?:[-/月]\s*)?(?\d{1,2})\s*(?:日|号)?\s+(?