Commit ae1a26473f65dd114dbc9a5f901ac37c6062d72f

Authored by 杨鑫
2 parents b8e270d5 b1440da4

合并

美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/DashboardScopeHelper.cs
@@ -240,7 +240,87 @@ public static class DashboardScopeHelper @@ -240,7 +240,87 @@ public static class DashboardScopeHelper
240 } 240 }
241 241
242 /// <summary> 242 /// <summary>
243 - /// 统计范围内门店数。 243 + /// 统计门店数,口径与 Account Management Location 列表默认一致
  244 + ///(<see cref="LocationRegionScopeHelper.ResolveLocationListScopeAsync"/> + <see cref="LocationRegionScopeHelper.ApplyLocationListScope"/>)。
  245 + /// </summary>
  246 + public static async Task<int> CountLocationListScopedLocationsAsync(
  247 + ISqlSugarClient db,
  248 + ICurrentUser currentUser,
  249 + ISqlSugarDbContext dbContext,
  250 + DateTime? createdBefore)
  251 + {
  252 + var scope = await LocationRegionScopeHelper.ResolveLocationListScopeAsync(currentUser, dbContext);
  253 + var query = db.Queryable<LocationAggregateRoot>().Where(x => !x.IsDeleted);
  254 + query = LocationRegionScopeHelper.ApplyLocationListScope(query, scope);
  255 +
  256 + if (createdBefore.HasValue)
  257 + {
  258 + query = query.Where(x => x.CreationTime < createdBefore.Value);
  259 + }
  260 +
  261 + return await query.CountAsync();
  262 + }
  263 +
  264 + /// <summary>
  265 + /// 统计产品数:可见门店范围与 Location 列表一致,再经 <see cref="ProductListScopeHelper.ApplyProductLocationListFilter"/>
  266 + /// 过滤(含 AvailabilityType=ALL / AppliedRegionType=ALL)。
  267 + /// </summary>
  268 + public static async Task<int> CountLocationListScopedProductsAsync(
  269 + ISqlSugarClient db,
  270 + ICurrentUser currentUser,
  271 + ISqlSugarDbContext dbContext)
  272 + {
  273 + var scopedLocationIds = await ResolveLocationListScopedLocationIdsAsync(db, currentUser, dbContext);
  274 + var query = db.Queryable<FlProductDbEntity>().Where(x => !x.IsDeleted);
  275 +
  276 + if (scopedLocationIds is not null)
  277 + {
  278 + var hasAvailabilityColumn = await ProductScopeSchemaHelper.HasAvailabilityTypeColumnAsync(db);
  279 + var hasAppliedRegionColumn = await ProductScopeSchemaHelper.HasAppliedRegionTypeColumnAsync(db);
  280 + var hasPartnerIdColumn = await ProductScopeSchemaHelper.HasPartnerIdColumnAsync(db);
  281 + var filterPartner = await ProductListScopeHelper.ResolveFilterPartnerContextAsync(
  282 + db, null, null, scopedLocationIds);
  283 + var partnerOnly = !LabelEntityListScopeHelper.ShouldApplyLocationAvailabilityFilter(null, null, null);
  284 +
  285 + query = ProductListScopeHelper.ApplyProductLocationListFilter(
  286 + query,
  287 + scopedLocationIds,
  288 + filterPartner,
  289 + hasAvailabilityColumn,
  290 + hasAppliedRegionColumn,
  291 + hasPartnerIdColumn,
  292 + partnerOnly);
  293 + }
  294 +
  295 + return await query.CountAsync();
  296 + }
  297 +
  298 + /// <summary>
  299 + /// 解析与 Location 列表相同的可见门店 Id;<c>null</c> 表示不限制(系统管理员)。
  300 + /// </summary>
  301 + private static async Task<List<string>?> ResolveLocationListScopedLocationIdsAsync(
  302 + ISqlSugarClient db,
  303 + ICurrentUser currentUser,
  304 + ISqlSugarDbContext dbContext)
  305 + {
  306 + var scope = await LocationRegionScopeHelper.ResolveLocationListScopeAsync(currentUser, dbContext);
  307 + if (scope.IsUnrestricted)
  308 + {
  309 + return null;
  310 + }
  311 +
  312 + if (scope.RegionKeys.Count == 0)
  313 + {
  314 + return new List<string>();
  315 + }
  316 +
  317 + var query = db.Queryable<LocationAggregateRoot>().Where(x => !x.IsDeleted);
  318 + query = LocationRegionScopeHelper.ApplyLocationListScope(query, scope);
  319 + return await query.Select(x => SqlFunc.ToString(x.Id)).ToListAsync();
  320 + }
  321 +
  322 + /// <summary>
  323 + /// 统计范围内门店数(Team Member 公司全量门店口径,供非 Location 卡片使用)。
244 /// </summary> 324 /// </summary>
245 public static async Task<int> CountScopedLocationsAsync( 325 public static async Task<int> CountScopedLocationsAsync(
246 ISqlSugarClient db, 326 ISqlSugarClient db,
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/LabelBatchTemplateDefaultsHelper.cs
@@ -3,6 +3,7 @@ using System.Text.Json; @@ -3,6 +3,7 @@ using System.Text.Json;
3 using FoodLabeling.Application.Contracts.Dtos.Label; 3 using FoodLabeling.Application.Contracts.Dtos.Label;
4 using FoodLabeling.Application.Contracts.Dtos.LabelTemplate; 4 using FoodLabeling.Application.Contracts.Dtos.LabelTemplate;
5 using FoodLabeling.Application.Services.DbModels; 5 using FoodLabeling.Application.Services.DbModels;
  6 +using FoodLabeling.Domain.Shared;
6 using SqlSugar; 7 using SqlSugar;
7 using Volo.Abp; 8 using Volo.Abp;
8 using Volo.Abp.Guids; 9 using Volo.Abp.Guids;
@@ -76,10 +77,12 @@ public static class LabelBatchTemplateDefaultsHelper @@ -76,10 +77,12 @@ public static class LabelBatchTemplateDefaultsHelper
76 { 77 {
77 if (item.TemplateDefaultValues is { Count: > 0 }) 78 if (item.TemplateDefaultValues is { Count: > 0 })
78 { 79 {
79 - return item.TemplateDefaultValues.ToDictionary( 80 + var fromInput = item.TemplateDefaultValues.ToDictionary(
80 x => x.Key, 81 x => x.Key,
81 x => x.Value, 82 x => x.Value,
82 StringComparer.OrdinalIgnoreCase); 83 StringComparer.OrdinalIgnoreCase);
  84 + ScrubEmptyBarcodeQrDefaults(elements, fromInput);
  85 + return fromInput;
83 } 86 }
84 87
85 var textValues = item.TemplateDataValues ?? new Dictionary<string, string>(); 88 var textValues = item.TemplateDataValues ?? new Dictionary<string, string>();
@@ -108,7 +111,13 @@ public static class LabelBatchTemplateDefaultsHelper @@ -108,7 +111,13 @@ public static class LabelBatchTemplateDefaultsHelper
108 } 111 }
109 else 112 else
110 { 113 {
111 - outDict[id] = textValues.TryGetValue(id, out var tv) ? tv : ""; 114 + var tv = textValues.TryGetValue(id, out var raw) ? raw : "";
  115 + if (IsBarcodeOrQrElement(el) && FoodLabelingDisplayConsts.IsEmptyDisplay(tv))
  116 + {
  117 + continue;
  118 + }
  119 +
  120 + outDict[id] = tv;
112 } 121 }
113 } 122 }
114 123
@@ -125,7 +134,7 @@ public static class LabelBatchTemplateDefaultsHelper @@ -125,7 +134,7 @@ public static class LabelBatchTemplateDefaultsHelper
125 } 134 }
126 135
127 var codeValue = (productCodeValue ?? "").Trim(); 136 var codeValue = (productCodeValue ?? "").Trim();
128 - if (!string.IsNullOrWhiteSpace(codeValue)) 137 + if (!string.IsNullOrWhiteSpace(codeValue) && !FoodLabelingDisplayConsts.IsEmptyDisplay(codeValue))
129 { 138 {
130 foreach (var el in elements) 139 foreach (var el in elements)
131 { 140 {
@@ -160,9 +169,70 @@ public static class LabelBatchTemplateDefaultsHelper @@ -160,9 +169,70 @@ public static class LabelBatchTemplateDefaultsHelper
160 } 169 }
161 } 170 }
162 171
  172 + ScrubEmptyBarcodeQrDefaults(elements, outDict);
163 return outDict; 173 return outDict;
164 } 174 }
165 175
  176 + /// <summary>
  177 + /// Barcode/QR 的空展示占位(N/A、无)不应覆盖模板 FIXED config.data。
  178 + /// </summary>
  179 + public static bool IsScrubbableEmptyBarcodeQrDefault(LabelTemplateElementDto el, string? value) =>
  180 + IsBarcodeOrQrElement(el) && FoodLabelingDisplayConsts.IsEmptyDisplay(value);
  181 +
  182 + /// <summary>
  183 + /// 从 defaults 字典中移除 Barcode/QR 的空展示占位,避免落库或预览覆盖 FIXED 值。
  184 + /// </summary>
  185 + public static void ScrubEmptyBarcodeQrDefaults(
  186 + IReadOnlyList<LabelTemplateElementDto> elements,
  187 + Dictionary<string, object?> defaults)
  188 + {
  189 + if (defaults.Count == 0 || elements.Count == 0)
  190 + {
  191 + return;
  192 + }
  193 +
  194 + var barcodeQrKeys = CollectBarcodeQrDefaultKeys(elements);
  195 + if (barcodeQrKeys.Count == 0)
  196 + {
  197 + return;
  198 + }
  199 +
  200 + foreach (var key in defaults.Keys.ToList())
  201 + {
  202 + if (!barcodeQrKeys.Contains(key))
  203 + {
  204 + continue;
  205 + }
  206 +
  207 + if (FoodLabelingDisplayConsts.IsEmptyDisplay(DefaultValueToString(defaults[key])))
  208 + {
  209 + defaults.Remove(key);
  210 + }
  211 + }
  212 + }
  213 +
  214 + /// <summary>
  215 + /// 按 elementId / InputKey / ElementName 查找模板元素。
  216 + /// </summary>
  217 + public static bool TryFindElementByDefaultKey(
  218 + IReadOnlyList<LabelTemplateElementDto> elements,
  219 + string key,
  220 + out LabelTemplateElementDto? element)
  221 + {
  222 + element = null;
  223 + if (string.IsNullOrWhiteSpace(key))
  224 + {
  225 + return false;
  226 + }
  227 +
  228 + element = elements.FirstOrDefault(el =>
  229 + string.Equals(el.Id?.Trim(), key, StringComparison.OrdinalIgnoreCase)
  230 + || string.Equals(el.InputKey?.Trim(), key, StringComparison.OrdinalIgnoreCase)
  231 + || string.Equals(el.ElementName?.Trim(), key, StringComparison.OrdinalIgnoreCase));
  232 +
  233 + return element is not null;
  234 + }
  235 +
166 public static bool HasTemplateDataInput(LabelBatchCreateItemInputVo item) => 236 public static bool HasTemplateDataInput(LabelBatchCreateItemInputVo item) =>
167 item.TemplateDefaultValues is { Count: > 0 } 237 item.TemplateDefaultValues is { Count: > 0 }
168 || item.TemplateDataValues is { Count: > 0 } 238 || item.TemplateDataValues is { Count: > 0 }
@@ -353,15 +423,62 @@ public static class LabelBatchTemplateDefaultsHelper @@ -353,15 +423,62 @@ public static class LabelBatchTemplateDefaultsHelper
353 private static bool IsNutritionElement(LabelTemplateElementDto el) => 423 private static bool IsNutritionElement(LabelTemplateElementDto el) =>
354 CanonicalElementType(el.ElementType) == "NUTRITION"; 424 CanonicalElementType(el.ElementType) == "NUTRITION";
355 425
356 - private static bool IsTemplateSectionBarcodeOrQrElement(LabelTemplateElementDto el) 426 + private static bool IsBarcodeOrQrElement(LabelTemplateElementDto el)
  427 + {
  428 + var t = CanonicalElementType(el.ElementType);
  429 + return t is "BARCODE" or "QRCODE";
  430 + }
  431 +
  432 + private static bool IsTemplateSectionBarcodeOrQrElement(LabelTemplateElementDto el) =>
  433 + IsTemplateSectionPersistedType(el) && IsBarcodeOrQrElement(el);
  434 +
  435 + private static HashSet<string> CollectBarcodeQrDefaultKeys(IReadOnlyList<LabelTemplateElementDto> elements)
357 { 436 {
358 - if (!IsTemplateSectionPersistedType(el)) 437 + var keys = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
  438 + foreach (var el in elements)
359 { 439 {
360 - return false; 440 + if (!IsBarcodeOrQrElement(el))
  441 + {
  442 + continue;
  443 + }
  444 +
  445 + if (!string.IsNullOrWhiteSpace(el.Id))
  446 + {
  447 + keys.Add(el.Id.Trim());
  448 + }
  449 +
  450 + if (!string.IsNullOrWhiteSpace(el.InputKey))
  451 + {
  452 + keys.Add(el.InputKey.Trim());
  453 + }
  454 +
  455 + if (!string.IsNullOrWhiteSpace(el.ElementName))
  456 + {
  457 + keys.Add(el.ElementName.Trim());
  458 + }
361 } 459 }
362 460
363 - var t = CanonicalElementType(el.ElementType);  
364 - return t is "BARCODE" or "QRCODE"; 461 + return keys;
  462 + }
  463 +
  464 + private static string? DefaultValueToString(object? value)
  465 + {
  466 + if (value is null)
  467 + {
  468 + return null;
  469 + }
  470 +
  471 + if (value is string s)
  472 + {
  473 + return s;
  474 + }
  475 +
  476 + if (value is JsonElement je)
  477 + {
  478 + return je.ValueKind == JsonValueKind.String ? je.GetString() : je.ToString();
  479 + }
  480 +
  481 + return value.ToString();
365 } 482 }
366 483
367 private static bool IsTemplateLabelNameElement(LabelTemplateElementDto el) => 484 private static bool IsTemplateLabelNameElement(LabelTemplateElementDto el) =>
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/ReportsDateTimeDisplayHelper.cs
@@ -4,7 +4,8 @@ using FoodLabeling.Domain.Shared; @@ -4,7 +4,8 @@ using FoodLabeling.Domain.Shared;
4 namespace FoodLabeling.Application.Helpers; 4 namespace FoodLabeling.Application.Helpers;
5 5
6 /// <summary> 6 /// <summary>
7 -/// Reports Print Log 日期展示:Printed at / ExpiryDateText 均统一为 <c>MM/dd/yy HH:mm:ss</c>。 7 +/// Reports Print Log 日期展示:Printed at / Expiration 统一 <c>MM/dd/yy HH:mm:ss</c>
  8 +/// (Expiration 纯日期保留 <c>00:00:00</c>;Printed at 禁止用午夜占位冒充打印时间)。
8 /// </summary> 9 /// </summary>
9 public static class ReportsDateTimeDisplayHelper 10 public static class ReportsDateTimeDisplayHelper
10 { 11 {
@@ -217,7 +218,11 @@ public static class ReportsDateTimeDisplayHelper @@ -217,7 +218,11 @@ public static class ReportsDateTimeDisplayHelper
217 return false; 218 return false;
218 } 219 }
219 220
220 - /// <summary>将已解析的到期时刻格式化为 Print Log Expiration 列(始终含时分秒)。</summary> 221 + /// <summary>墙钟时分是否非午夜占位(H/M/S 至少一项非 0)。</summary>
  222 + public static bool HasMeaningfulWallClockTime(DateTime dt) =>
  223 + dt.Hour != 0 || dt.Minute != 0 || dt.Second != 0;
  224 +
  225 + /// <summary>将已解析的到期时刻格式化为 Print Log Expiration 列:统一 MM/dd/yy HH:mm:ss(纯日期为 00:00:00)。</summary>
221 public static string FormatExpiryDateTime(DateTime dt) 226 public static string FormatExpiryDateTime(DateTime dt)
222 { 227 {
223 if (dt == DateTime.MinValue) 228 if (dt == DateTime.MinValue)
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/ReportsPrintLogExpiryHelper.cs
@@ -6,7 +6,7 @@ using FoodLabeling.Domain.Shared; @@ -6,7 +6,7 @@ using FoodLabeling.Domain.Shared;
6 namespace FoodLabeling.Application.Helpers; 6 namespace FoodLabeling.Application.Helpers;
7 7
8 /// <summary> 8 /// <summary>
9 -/// Print Log「Expiry Date」:从打印任务 JSON 解析到期日期时间(优先已渲染的 __previewFormatted)。 9 +/// Print Log「Expiration」列:从打印快照 <c>elements</c> 收集全部到期相关日期候选,取最早的一个再格式化展示(优先 <c>__previewFormatted</c>)。
10 /// </summary> 10 /// </summary>
11 public static class ReportsPrintLogExpiryHelper 11 public static class ReportsPrintLogExpiryHelper
12 { 12 {
@@ -31,7 +31,7 @@ public static class ReportsPrintLogExpiryHelper @@ -31,7 +31,7 @@ public static class ReportsPrintLogExpiryHelper
31 }; 31 };
32 32
33 private static readonly Regex ExpiryNamePattern = new( 33 private static readonly Regex ExpiryNamePattern = new(
34 - @"(durationdate|duration_date|duration\s*date|expirydate|expiry_date|expiry\s*date|expirationdate|expiration_date|usebydate|use_by)", 34 + @"(durationdate|duration_date|duration\s*date|expirydate|expiry_date|expiry\s*date|expirationdate|expiration_date|expiration|usebydate|use_by|use.?by|best.?before|ready|discard)",
35 RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Compiled); 35 RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Compiled);
36 36
37 private static readonly Regex ExpiryTimeNamePattern = new( 37 private static readonly Regex ExpiryTimeNamePattern = new(
@@ -39,10 +39,10 @@ public static class ReportsPrintLogExpiryHelper @@ -39,10 +39,10 @@ public static class ReportsPrintLogExpiryHelper
39 RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Compiled); 39 RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Compiled);
40 40
41 private static readonly Regex ExcludeNamePattern = new( 41 private static readonly Regex ExcludeNamePattern = new(
42 - @"(currentdate|currenttime|prepped|prepdate|prepon|labelname|durationdate2|duration_date_2|durationdate_2|duration\s*date\s*2)", 42 + @"(currentdate|currenttime|prepped|prepdate|prepon|pulled|labelname|durationdate2|duration_date_2|durationdate_2|duration\s*date\s*2)",
43 RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Compiled); 43 RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Compiled);
44 44
45 - /// <summary>解析并格式化为 Print Log Expiration 列展示(含日期与时间)。</summary> 45 + /// <summary>解析全部到期候选并取最早时刻,格式化为 Print Log Expiration 列(含日期与时间)。</summary>
46 public static string ExtractFormattedExpiryText( 46 public static string ExtractFormattedExpiryText(
47 string? printInputJson, 47 string? printInputJson,
48 string? renderTemplateJson = null, 48 string? renderTemplateJson = null,
@@ -52,8 +52,7 @@ public static class ReportsPrintLogExpiryHelper @@ -52,8 +52,7 @@ public static class ReportsPrintLogExpiryHelper
52 var reference = NormalizeExpiryAnchor(baseTime ?? printedAt ?? DateTime.Now); 52 var reference = NormalizeExpiryAnchor(baseTime ?? printedAt ?? DateTime.Now);
53 if (TryResolveExpiryDateTime(printInputJson, renderTemplateJson, reference, out var resolved)) 53 if (TryResolveExpiryDateTime(printInputJson, renderTemplateJson, reference, out var resolved))
54 { 54 {
55 - resolved = ApplyPrintWallClockTimeIfNeeded(  
56 - resolved, printInputJson, renderTemplateJson, baseTime, printedAt); 55 + // 模板最早到期日为纯日期时保留 00:00:00,不补打印墙钟(如 Ready 早于 Discard)
57 return ReportsDateTimeDisplayHelper.FormatExpiryDateTime(resolved); 56 return ReportsDateTimeDisplayHelper.FormatExpiryDateTime(resolved);
58 } 57 }
59 58
@@ -66,53 +65,12 @@ public static class ReportsPrintLogExpiryHelper @@ -66,53 +65,12 @@ public static class ReportsPrintLogExpiryHelper
66 if (!FoodLabelingDisplayConsts.IsEmptyDisplay(raw) 65 if (!FoodLabelingDisplayConsts.IsEmptyDisplay(raw)
67 && ReportsDateTimeDisplayHelper.TryParseExpiryDateTime(raw.Trim(), reference, out var parsed)) 66 && ReportsDateTimeDisplayHelper.TryParseExpiryDateTime(raw.Trim(), reference, out var parsed))
68 { 67 {
69 - parsed = ApplyPrintWallClockTimeIfNeeded(  
70 - parsed, printInputJson, renderTemplateJson, baseTime, printedAt);  
71 return ReportsDateTimeDisplayHelper.FormatExpiryDateTime(parsed); 68 return ReportsDateTimeDisplayHelper.FormatExpiryDateTime(parsed);
72 } 69 }
73 70
74 return ReportsDateTimeDisplayHelper.FormatExpiryDisplay(raw, reference); 71 return ReportsDateTimeDisplayHelper.FormatExpiryDisplay(raw, reference);
75 } 72 }
76 73
77 - /// <summary>  
78 - /// Use By 为纯日期(00:00:00)时,用 Prepped On / BaseTime / PrintedAt 的墙钟时分秒补全。  
79 - /// </summary>  
80 - private static DateTime ApplyPrintWallClockTimeIfNeeded(  
81 - DateTime expiry,  
82 - string? printInputJson,  
83 - string? renderTemplateJson,  
84 - DateTime? baseTime,  
85 - DateTime? printedAt)  
86 - {  
87 - if (HasRealExpiryTime(expiry))  
88 - {  
89 - return expiry;  
90 - }  
91 -  
92 - DateTime printClock;  
93 - if (ReportsPrintLogPreppedHelper.TryResolvePreppedDateTime(  
94 - printInputJson, renderTemplateJson, baseTime, printedAt, out var prepped))  
95 - {  
96 - printClock = prepped;  
97 - }  
98 - else  
99 - {  
100 - printClock = NormalizeExpiryAnchor(baseTime ?? printedAt ?? DateTime.Now);  
101 - }  
102 -  
103 - return new DateTime(  
104 - expiry.Year,  
105 - expiry.Month,  
106 - expiry.Day,  
107 - printClock.Hour,  
108 - printClock.Minute,  
109 - printClock.Second,  
110 - expiry.Kind);  
111 - }  
112 -  
113 - private static bool HasRealExpiryTime(DateTime dt) =>  
114 - dt.Hour != 0 || dt.Minute != 0 || dt.Second != 0;  
115 -  
116 /// <summary>兼容旧调用:仅 PrintInputJson。</summary> 74 /// <summary>兼容旧调用:仅 PrintInputJson。</summary>
117 public static string ExtractFormattedExpiryText(string? printInputJson) => 75 public static string ExtractFormattedExpiryText(string? printInputJson) =>
118 ExtractFormattedExpiryText(printInputJson, null, null, null); 76 ExtractFormattedExpiryText(printInputJson, null, null, null);
@@ -157,66 +115,125 @@ public static class ReportsPrintLogExpiryHelper @@ -157,66 +115,125 @@ public static class ReportsPrintLogExpiryHelper
157 return false; 115 return false;
158 } 116 }
159 117
160 - if (!TryFindBestElement(elements, isDateElement: true, out var dateElement)) 118 + if (!TryCollectEarliestExpiryDateTime(elements, reference, out expiry))
161 { 119 {
162 return false; 120 return false;
163 } 121 }
164 122
165 - if (!TryResolveElementDateTimeValue(dateElement, reference, out var datePart)) 123 + return true;
  124 + }
  125 + catch
  126 + {
  127 + return false;
  128 + }
  129 + }
  130 +
  131 + /// <summary>遍历 elements 中全部到期日期候选,解析为 <see cref="DateTime"/> 后取最早(Min)。</summary>
  132 + private static bool TryCollectEarliestExpiryDateTime(
  133 + JsonElement elements,
  134 + DateTime reference,
  135 + out DateTime earliest)
  136 + {
  137 + earliest = default;
  138 + var candidates = new List<DateTime>();
  139 +
  140 + foreach (var el in elements.EnumerateArray())
  141 + {
  142 + if (el.ValueKind != JsonValueKind.Object)
166 { 143 {
167 - return false; 144 + continue;
168 } 145 }
169 146
170 - expiry = datePart;  
171 - if (HasMeaningfulTime(datePart)) 147 + if (ScoreExpiryDateElement(el) <= 0)
172 { 148 {
173 - return true; 149 + continue;
174 } 150 }
175 151
176 - // 日期字面量无时分时:仅合并「真实时间」元素;跳过 Duration Time=0 Days(会误用 BaseTime 小时)  
177 - if (TryFindBestElement(elements, isDateElement: false, out var timeElement) &&  
178 - TryResolveElementDateTimeValue(timeElement, reference, out var timePart) &&  
179 - HasMeaningfulTime(timePart) &&  
180 - !IsZeroDayDurationTimeElement(timeElement)) 152 + if (!TryResolveExpiryDateTimeForDateElement(elements, el, reference, out var resolved))
181 { 153 {
182 - // Time 偏移跨午夜时 timePart.Date 已是次日;不可只用 datePart.Day + timePart 时分。  
183 - if (timePart.Date > datePart.Date)  
184 - {  
185 - expiry = new DateTime(  
186 - timePart.Year,  
187 - timePart.Month,  
188 - timePart.Day,  
189 - timePart.Hour,  
190 - timePart.Minute,  
191 - 0);  
192 - }  
193 - else  
194 - {  
195 - expiry = new DateTime(  
196 - datePart.Year,  
197 - datePart.Month,  
198 - datePart.Day,  
199 - timePart.Hour,  
200 - timePart.Minute,  
201 - 0);  
202 - }  
203 - return true; 154 + continue;
204 } 155 }
205 156
206 - return true; 157 + candidates.Add(resolved);
207 } 158 }
208 - catch 159 +
  160 + if (candidates.Count == 0)
  161 + {
  162 + return false;
  163 + }
  164 +
  165 + earliest = candidates.Min();
  166 + return true;
  167 + }
  168 +
  169 + /// <summary>解析单个到期日期元素;无真实时分时尝试合并配对 durationtime(跳过 0 Days)。</summary>
  170 + private static bool TryResolveExpiryDateTimeForDateElement(
  171 + JsonElement elements,
  172 + JsonElement dateElement,
  173 + DateTime reference,
  174 + out DateTime resolved)
  175 + {
  176 + resolved = default;
  177 + if (!TryResolveElementDateTimeValue(dateElement, reference, out var datePart))
209 { 178 {
210 return false; 179 return false;
211 } 180 }
  181 +
  182 + resolved = datePart;
  183 + if (HasMeaningfulTime(datePart))
  184 + {
  185 + return true;
  186 + }
  187 +
  188 + if (TryFindPairedTimeElement(elements, dateElement, out var timeElement) &&
  189 + TryResolveElementDateTimeValue(timeElement, reference, out var timePart) &&
  190 + HasMeaningfulTime(timePart) &&
  191 + !IsZeroDayDurationTimeElement(timeElement))
  192 + {
  193 + resolved = new DateTime(
  194 + datePart.Year,
  195 + datePart.Month,
  196 + datePart.Day,
  197 + timePart.Hour,
  198 + timePart.Minute,
  199 + 0);
  200 + }
  201 +
  202 + return true;
212 } 203 }
213 204
214 - private static bool TryFindBestElement(JsonElement elements, bool isDateElement, out JsonElement bestElement) 205 + /// <summary>为到期日期元素查找配对时间元素(durationdate↔durationtime 或同名 time 后缀)。</summary>
  206 + private static bool TryFindPairedTimeElement(
  207 + JsonElement elements,
  208 + JsonElement dateElement,
  209 + out JsonElement timeElement)
215 { 210 {
216 - bestElement = default;  
217 - var bestScore = 0;  
218 - var bestOrder = int.MinValue;  
219 - var found = false; 211 + timeElement = default;
  212 + var dateName = GetStringProperty(dateElement, "elementName", "ElementName").Trim();
  213 + if (string.IsNullOrWhiteSpace(dateName))
  214 + {
  215 + return false;
  216 + }
  217 +
  218 + if (dateName.Equals("durationdate", StringComparison.OrdinalIgnoreCase))
  219 + {
  220 + foreach (var el in elements.EnumerateArray())
  221 + {
  222 + if (el.ValueKind != JsonValueKind.Object)
  223 + {
  224 + continue;
  225 + }
  226 +
  227 + var name = GetStringProperty(el, "elementName", "ElementName").Trim();
  228 + if (name.Equals("durationtime", StringComparison.OrdinalIgnoreCase))
  229 + {
  230 + timeElement = el;
  231 + return true;
  232 + }
  233 + }
  234 +
  235 + return false;
  236 + }
220 237
221 foreach (var el in elements.EnumerateArray()) 238 foreach (var el in elements.EnumerateArray())
222 { 239 {
@@ -225,28 +242,34 @@ public static class ReportsPrintLogExpiryHelper @@ -225,28 +242,34 @@ public static class ReportsPrintLogExpiryHelper
225 continue; 242 continue;
226 } 243 }
227 244
228 - var score = isDateElement ? ScoreExpiryDateElement(el) : ScoreExpiryTimeElement(el);  
229 - if (score <= 0) 245 + var name = GetStringProperty(el, "elementName", "ElementName").Trim();
  246 + if (string.IsNullOrWhiteSpace(name))
  247 + {
  248 + continue;
  249 + }
  250 +
  251 + if (ScoreExpiryTimeElement(el) <= 0 && !ExpiryTimeNamePattern.IsMatch(name))
230 { 252 {
231 continue; 253 continue;
232 } 254 }
233 255
234 - var order = TryGetIntProperty(el, "orderNum", "OrderNum") ?? 0;  
235 - if (score > bestScore || (score == bestScore && order > bestOrder)) 256 + if (name.Equals(dateName + "time", StringComparison.OrdinalIgnoreCase))
236 { 257 {
237 - bestScore = score;  
238 - bestOrder = order;  
239 - bestElement = el;  
240 - found = true; 258 + timeElement = el;
  259 + return true;
  260 + }
  261 +
  262 + if (dateName.EndsWith("date", StringComparison.OrdinalIgnoreCase) &&
  263 + name.Equals(dateName[..^4] + "time", StringComparison.OrdinalIgnoreCase))
  264 + {
  265 + timeElement = el;
  266 + return true;
241 } 267 }
242 } 268 }
243 269
244 - return found; 270 + return false;
245 } 271 }
246 272
247 - private static bool TryResolveElementDateTime(JsonElement el, DateTime reference, out DateTime result) =>  
248 - TryResolveElementDateTimeValue(el, reference, out result);  
249 -  
250 /// <summary> 273 /// <summary>
251 /// 从模板元素直接解析到期 <see cref="DateTime"/>,避免 DATE 预设格式(如 MM/DD/YY)剥掉锚点时分。 274 /// 从模板元素直接解析到期 <see cref="DateTime"/>,避免 DATE 预设格式(如 MM/DD/YY)剥掉锚点时分。
252 /// 优先使用打印快照已渲染的 <c>__previewFormatted</c> / 字面量,避免用 UTC BaseTime 重算偏移导致小时偏差。 275 /// 优先使用打印快照已渲染的 <c>__previewFormatted</c> / 字面量,避免用 UTC BaseTime 重算偏移导致小时偏差。
@@ -599,7 +622,7 @@ public static class ReportsPrintLogExpiryHelper @@ -599,7 +622,7 @@ public static class ReportsPrintLogExpiryHelper
599 } 622 }
600 623
601 private static bool HasMeaningfulTime(DateTime dt) => 624 private static bool HasMeaningfulTime(DateTime dt) =>
602 - dt.Hour != 0 || dt.Minute != 0; 625 + ReportsDateTimeDisplayHelper.HasMeaningfulWallClockTime(dt);
603 626
604 /// <summary> 627 /// <summary>
605 /// Duration Time 配置为 0 Days 时不应把 BaseTime 的时分并进 Expiration(标签 Use By 常为纯日期)。 628 /// Duration Time 配置为 0 Days 时不应把 BaseTime 的时分并进 Expiration(标签 Use By 常为纯日期)。
@@ -668,12 +691,7 @@ public static class ReportsPrintLogExpiryHelper @@ -668,12 +691,7 @@ public static class ReportsPrintLogExpiryHelper
668 691
669 if (TryGetProperty(root, "elements", out var elements) && elements.ValueKind == JsonValueKind.Array) 692 if (TryGetProperty(root, "elements", out var elements) && elements.ValueKind == JsonValueKind.Array)
670 { 693 {
671 - if (TryExtractNamedDurationExpiry(elements, anchor, out var fromNamed))  
672 - {  
673 - return fromNamed;  
674 - }  
675 -  
676 - if (TryExtractFromElements(elements, anchor, out var fromElements)) 694 + if (TryExtractEarliestFromElements(elements, anchor, out var fromElements))
677 { 695 {
678 return fromElements; 696 return fromElements;
679 } 697 }
@@ -756,48 +774,18 @@ public static class ReportsPrintLogExpiryHelper @@ -756,48 +774,18 @@ public static class ReportsPrintLogExpiryHelper
756 return false; 774 return false;
757 } 775 }
758 776
759 - /// <summary>优先按 elementName 合并 durationdate + durationtime(App 打印快照常见结构)。</summary>  
760 - private static bool TryExtractNamedDurationExpiry(JsonElement elements, DateTime anchor, out string text) 777 + /// <summary>从 elements 收集全部到期候选,解析后取最早再格式化为展示文本(与 DateTime 主路径一致)。</summary>
  778 + private static bool TryExtractEarliestFromElements(JsonElement elements, DateTime anchor, out string text)
761 { 779 {
762 text = FoodLabelingDisplayConsts.NotAvailable; 780 text = FoodLabelingDisplayConsts.NotAvailable;
763 - string? datePart = null;  
764 - string? timePart = null;  
765 -  
766 - foreach (var el in elements.EnumerateArray())  
767 - {  
768 - if (el.ValueKind != JsonValueKind.Object)  
769 - {  
770 - continue;  
771 - }  
772 -  
773 - var name = GetStringProperty(el, "elementName", "ElementName").Trim();  
774 - if (name.Equals("durationdate", StringComparison.OrdinalIgnoreCase))  
775 - {  
776 - datePart = GetElementConfigDisplayText(el, anchor);  
777 - }  
778 - else if (name.Equals("durationtime", StringComparison.OrdinalIgnoreCase))  
779 - {  
780 - timePart = GetElementConfigDisplayText(el, anchor);  
781 - }  
782 - }  
783 -  
784 - if (string.IsNullOrWhiteSpace(datePart) || IsMissingExpiry(datePart)) 781 + if (TryCollectEarliestExpiryDateTime(elements, anchor, out var earliest))
785 { 782 {
786 - return false; 783 + text = ReportsDateTimeDisplayHelper.FormatExpiryDateTime(earliest);
  784 + return true;
787 } 785 }
788 786
789 - text = string.IsNullOrWhiteSpace(timePart) || IsMissingExpiry(timePart)  
790 - ? datePart.Trim()  
791 - : ReportsDateTimeDisplayHelper.MergeDateAndTimeParts(datePart.Trim(), timePart.Trim(), anchor);  
792 - return true;  
793 - }  
794 -  
795 - private static bool TryExtractFromElements(JsonElement elements, DateTime anchor, out string text)  
796 - {  
797 - text = FoodLabelingDisplayConsts.NotAvailable;  
798 - var bestScore = 0;  
799 - string? bestText = null;  
800 - var bestOrder = int.MinValue; 787 + DateTime? earliestParsed = null;
  788 + string? earliestRaw = null;
801 789
802 foreach (var el in elements.EnumerateArray()) 790 foreach (var el in elements.EnumerateArray())
803 { 791 {
@@ -806,33 +794,44 @@ public static class ReportsPrintLogExpiryHelper @@ -806,33 +794,44 @@ public static class ReportsPrintLogExpiryHelper
806 continue; 794 continue;
807 } 795 }
808 796
809 - var score = ScoreExpiryDateElement(el);  
810 - if (score <= 0) 797 + if (ScoreExpiryDateElement(el) <= 0)
811 { 798 {
812 continue; 799 continue;
813 } 800 }
814 801
815 var display = GetElementConfigDisplayText(el, anchor); 802 var display = GetElementConfigDisplayText(el, anchor);
816 - if (string.IsNullOrWhiteSpace(display)) 803 + if (string.IsNullOrWhiteSpace(display) || IsMissingExpiry(display))
817 { 804 {
818 continue; 805 continue;
819 } 806 }
820 807
821 - var order = TryGetIntProperty(el, "orderNum", "OrderNum") ?? 0;  
822 - if (score > bestScore || (score == bestScore && order > bestOrder)) 808 + var trimmed = display.Trim();
  809 + if (ReportsDateTimeDisplayHelper.TryParseExpiryDateTime(trimmed, anchor, out var parsed))
823 { 810 {
824 - bestScore = score;  
825 - bestOrder = order;  
826 - bestText = display.Trim(); 811 + if (!earliestParsed.HasValue || parsed < earliestParsed.Value)
  812 + {
  813 + earliestParsed = parsed;
  814 + earliestRaw = trimmed;
  815 + }
  816 + }
  817 + else if (!earliestParsed.HasValue && earliestRaw is null)
  818 + {
  819 + earliestRaw = trimmed;
827 } 820 }
828 } 821 }
829 822
830 - if (string.IsNullOrWhiteSpace(bestText)) 823 + if (earliestParsed.HasValue)
  824 + {
  825 + text = ReportsDateTimeDisplayHelper.FormatExpiryDateTime(earliestParsed.Value);
  826 + return true;
  827 + }
  828 +
  829 + if (string.IsNullOrWhiteSpace(earliestRaw))
831 { 830 {
832 return false; 831 return false;
833 } 832 }
834 833
835 - text = bestText; 834 + text = earliestRaw;
836 return true; 835 return true;
837 } 836 }
838 837
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/ReportsPrintLogPreppedHelper.cs
@@ -5,7 +5,8 @@ using FoodLabeling.Domain.Shared; @@ -5,7 +5,8 @@ using FoodLabeling.Domain.Shared;
5 namespace FoodLabeling.Application.Helpers; 5 namespace FoodLabeling.Application.Helpers;
6 6
7 /// <summary> 7 /// <summary>
8 -/// Print Log「Printed at」:从打印快照 JSON 提取标签 Prepped On 展示时间(优先 <c>__previewFormatted</c>)。 8 +/// Print Log「Printed at」:优先库内真实打印时刻(PrintedAt / CreationTime / BaseTime),
  9 +/// 仅当库值为午夜占位时再尝试快照 Prepped/currenttime 补全墙钟。
9 /// </summary> 10 /// </summary>
10 public static class ReportsPrintLogPreppedHelper 11 public static class ReportsPrintLogPreppedHelper
11 { 12 {
@@ -38,7 +39,7 @@ public static class ReportsPrintLogPreppedHelper @@ -38,7 +39,7 @@ public static class ReportsPrintLogPreppedHelper
38 } 39 }
39 40
40 /// <summary> 41 /// <summary>
41 - /// 解析标签 Prepped On 并格式化为 Printed at 列;无法解析时回退 <paramref name="printedAtFallback"/>。 42 + /// 格式化 Printed at 列:库内有真实时分的打印时刻优先;禁止在存在真实时分来源时输出 <c>00:00:00</c>。
42 /// </summary> 43 /// </summary>
43 public static string ExtractFormattedPrintedAt( 44 public static string ExtractFormattedPrintedAt(
44 string? printInputJson, 45 string? printInputJson,
@@ -46,12 +47,128 @@ public static class ReportsPrintLogPreppedHelper @@ -46,12 +47,128 @@ public static class ReportsPrintLogPreppedHelper
46 DateTime? baseTime = null, 47 DateTime? baseTime = null,
47 DateTime? printedAtFallback = null) 48 DateTime? printedAtFallback = null)
48 { 49 {
49 - if (TryResolvePreppedDateTime(printInputJson, renderTemplateJson, baseTime, printedAtFallback, out var resolved)) 50 + if (TryPickMeaningfulStoredPrintInstant(printedAtFallback, baseTime, out var stored))
50 { 51 {
51 - return ReportsDateTimeDisplayHelper.FormatPrintedAt(resolved); 52 + return ReportsDateTimeDisplayHelper.FormatPrintedAt(stored);
52 } 53 }
53 54
54 - return ReportsDateTimeDisplayHelper.FormatPrintedAt(printedAtFallback ?? DateTime.MinValue); 55 + if (TryResolvePreppedDateTime(printInputJson, renderTemplateJson, baseTime, printedAtFallback, out var prepped)
  56 + && HasMeaningfulTime(prepped))
  57 + {
  58 + return ReportsDateTimeDisplayHelper.FormatPrintedAt(prepped);
  59 + }
  60 +
  61 + if (TryEnrichMidnightWithTemplateClock(
  62 + printInputJson, renderTemplateJson, baseTime, printedAtFallback, out var enriched))
  63 + {
  64 + return ReportsDateTimeDisplayHelper.FormatPrintedAt(enriched);
  65 + }
  66 +
  67 + // 仍无真实墙钟:返回 N/A,避免把午夜占位当成打印时间
  68 + return ReportsDateTimeDisplayHelper.FormatPrintedAt(DateTime.MinValue);
  69 + }
  70 +
  71 + /// <summary>
  72 + /// 在 PrintedAt / CreationTime(已 coalesce 到 printedAtFallback)与 BaseTime 中选取含真实时分的打印时刻。
  73 + /// </summary>
  74 + public static bool TryPickMeaningfulStoredPrintInstant(
  75 + DateTime? printedAtOrCreationTime,
  76 + DateTime? baseTime,
  77 + out DateTime resolved)
  78 + {
  79 + resolved = default;
  80 + foreach (var candidate in new[] { printedAtOrCreationTime, baseTime })
  81 + {
  82 + if (!candidate.HasValue || candidate.Value == DateTime.MinValue)
  83 + {
  84 + continue;
  85 + }
  86 +
  87 + var normalized = NormalizePreppedAnchor(candidate.Value);
  88 + if (HasMeaningfulTime(normalized))
  89 + {
  90 + resolved = normalized;
  91 + return true;
  92 + }
  93 + }
  94 +
  95 + return false;
  96 + }
  97 +
  98 + /// <summary>库值为午夜时,用快照 TIME/currenttime 墙钟合并日期。</summary>
  99 + private static bool TryEnrichMidnightWithTemplateClock(
  100 + string? printInputJson,
  101 + string? renderTemplateJson,
  102 + DateTime? baseTime,
  103 + DateTime? printedAtFallback,
  104 + out DateTime resolved)
  105 + {
  106 + resolved = default;
  107 + DateTime? dateSource = null;
  108 + foreach (var candidate in new[] { printedAtFallback, baseTime })
  109 + {
  110 + if (candidate.HasValue && candidate.Value != DateTime.MinValue)
  111 + {
  112 + dateSource = NormalizePreppedAnchor(candidate.Value);
  113 + break;
  114 + }
  115 + }
  116 +
  117 + if (!dateSource.HasValue)
  118 + {
  119 + return false;
  120 + }
  121 +
  122 + foreach (var json in new[] { printInputJson, renderTemplateJson })
  123 + {
  124 + if (string.IsNullOrWhiteSpace(json))
  125 + {
  126 + continue;
  127 + }
  128 +
  129 + try
  130 + {
  131 + using var doc = JsonDocument.Parse(json);
  132 + if (doc.RootElement.ValueKind != JsonValueKind.Object)
  133 + {
  134 + continue;
  135 + }
  136 +
  137 + if (!TryGetProperty(doc.RootElement, "elements", out var elements)
  138 + || elements.ValueKind != JsonValueKind.Array)
  139 + {
  140 + continue;
  141 + }
  142 +
  143 + if (!TryFindBestPreppedTimeElement(elements, out var timeElement))
  144 + {
  145 + continue;
  146 + }
  147 +
  148 + var anchor = dateSource.Value;
  149 + if (!TryResolvePreppedElementDateTime(timeElement, anchor, out var timePart)
  150 + || !HasMeaningfulTime(timePart))
  151 + {
  152 + continue;
  153 + }
  154 +
  155 + resolved = new DateTime(
  156 + dateSource.Value.Year,
  157 + dateSource.Value.Month,
  158 + dateSource.Value.Day,
  159 + timePart.Hour,
  160 + timePart.Minute,
  161 + timePart.Second,
  162 + dateSource.Value.Kind);
  163 + return true;
  164 + }
  165 + catch
  166 + {
  167 + // ignore malformed snapshot
  168 + }
  169 + }
  170 +
  171 + return false;
55 } 172 }
56 173
57 private static bool TryResolvePreppedDateTimeFromSources( 174 private static bool TryResolvePreppedDateTimeFromSources(
@@ -126,8 +243,8 @@ public static class ReportsPrintLogPreppedHelper @@ -126,8 +243,8 @@ public static class ReportsPrintLogPreppedHelper
126 return true; 243 return true;
127 } 244 }
128 245
129 - result = datePart;  
130 - return true; 246 + // 快照 Prepped 仅含日期(无真实时分)时,回退 PrintedAt / BaseTime,避免 FormatPrintedAt 输出 00:00:00
  247 + return false;
131 } 248 }
132 catch 249 catch
133 { 250 {
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/DashboardAppService.cs
@@ -82,9 +82,10 @@ public class DashboardAppService : ApplicationService, IDashboardAppService @@ -82,9 +82,10 @@ public class DashboardAppService : ApplicationService, IDashboardAppService
82 var regionsPrevWeek = await DashboardScopeHelper.CountScopedRegionsAsync( 82 var regionsPrevWeek = await DashboardScopeHelper.CountScopedRegionsAsync(
83 db, groupScope, weekStart); 83 db, groupScope, weekStart);
84 84
85 - var locations = await DashboardScopeHelper.CountScopedLocationsAsync(db, scopeLocationIds, null);  
86 - var locationsPrevWeek = await DashboardScopeHelper.CountScopedLocationsAsync(  
87 - db, scopeLocationIds, weekStart); 85 + var locations = await DashboardScopeHelper.CountLocationListScopedLocationsAsync(
  86 + db, CurrentUser, _dbContext, null);
  87 + var locationsPrevWeek = await DashboardScopeHelper.CountLocationListScopedLocationsAsync(
  88 + db, CurrentUser, _dbContext, weekStart);
88 89
89 var people = await DashboardScopeHelper.CountScopedRegisteredUsersAsync( 90 var people = await DashboardScopeHelper.CountScopedRegisteredUsersAsync(
90 db, scopeLocationIds, activeOnly: false, createdBefore: null); 91 db, scopeLocationIds, activeOnly: false, createdBefore: null);
@@ -96,23 +97,8 @@ public class DashboardAppService : ApplicationService, IDashboardAppService @@ -96,23 +97,8 @@ public class DashboardAppService : ApplicationService, IDashboardAppService
96 var labelsPrevWeek = await DashboardScopeHelper.CountScopedLabelsAsync( 97 var labelsPrevWeek = await DashboardScopeHelper.CountScopedLabelsAsync(
97 db, _dbContext, CurrentUser, createdBefore: weekStart); 98 db, _dbContext, CurrentUser, createdBefore: weekStart);
98 99
99 - var productQuery = db.Queryable<FlProductDbEntity>().Where(x => !x.IsDeleted);  
100 - if (scopeLocationIds is not null)  
101 - {  
102 - if (scopeLocationIds.Count == 0)  
103 - {  
104 - productQuery = productQuery.Where(_ => false);  
105 - }  
106 - else  
107 - {  
108 - productQuery = productQuery.Where(p =>  
109 - SqlFunc.Subqueryable<FlLocationProductDbEntity>()  
110 - .Where(lp => lp.ProductId == p.Id && scopeLocationIds.Contains(lp.LocationId))  
111 - .Any());  
112 - }  
113 - }  
114 -  
115 - var products = await productQuery.CountAsync(); 100 + var products = await DashboardScopeHelper.CountLocationListScopedProductsAsync(
  101 + db, CurrentUser, _dbContext);
116 // fl_product 当前实体未映射 CreationTime,无法按时间切分对比,先回退为同口径总量对比 102 // fl_product 当前实体未映射 CreationTime,无法按时间切分对比,先回退为同口径总量对比
117 var productsPrevWeek = products; 103 var productsPrevWeek = products;
118 104
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/ReportsAppService.cs
@@ -102,7 +102,8 @@ public class ReportsAppService : ApplicationService, IReportsAppService @@ -102,7 +102,8 @@ public class ReportsAppService : ApplicationService, IReportsAppService
102 t.PrintInputJson, 102 t.PrintInputJson,
103 t.RenderTemplateJson, 103 t.RenderTemplateJson,
104 t.BaseTime, 104 t.BaseTime,
105 - PrintedAt = SqlFunc.IsNull(t.PrintedAt, t.CreationTime), 105 + t.PrintedAt,
  106 + t.CreationTime,
106 t.CreatedBy, 107 t.CreatedBy,
107 t.LocationId, 108 t.LocationId,
108 LocName = loc.LocationName, 109 LocName = loc.LocationName,
@@ -118,7 +119,7 @@ public class ReportsAppService : ApplicationService, IReportsAppService @@ -118,7 +119,7 @@ public class ReportsAppService : ApplicationService, IReportsAppService
118 pageRows.Select(x => new ReportsPrintLogDailyLabelIdHelper.PrintTaskScopeKey( 119 pageRows.Select(x => new ReportsPrintLogDailyLabelIdHelper.PrintTaskScopeKey(
119 x.Id, 120 x.Id,
120 x.LocationId, 121 x.LocationId,
121 - x.PrintedAt ?? DateTime.MinValue)).ToList()); 122 + ResolveStoredPrintInstant(x.PrintedAt, x.CreationTime, x.BaseTime))).ToList());
122 123
123 var items = pageRows.Select(x => 124 var items = pageRows.Select(x =>
124 { 125 {
@@ -127,7 +128,7 @@ public class ReportsAppService : ApplicationService, IReportsAppService @@ -127,7 +128,7 @@ public class ReportsAppService : ApplicationService, IReportsAppService
127 : (string.IsNullOrWhiteSpace(x.LabelCategoryName) ? FoodLabelingDisplayConsts.NotAvailable : x.LabelCategoryName.Trim()); 128 : (string.IsNullOrWhiteSpace(x.LabelCategoryName) ? FoodLabelingDisplayConsts.NotAvailable : x.LabelCategoryName.Trim());
128 var templateText = FormatTemplateDisplay(x.Width, x.Height, x.Unit, x.TemplateName); 129 var templateText = FormatTemplateDisplay(x.Width, x.Height, x.Unit, x.TemplateName);
129 var locText = FormatLocationText(x.LocName, x.LocCode); 130 var locText = FormatLocationText(x.LocName, x.LocCode);
130 - var printedAt = x.PrintedAt ?? DateTime.MinValue; 131 + var printedAt = ResolveStoredPrintInstant(x.PrintedAt, x.CreationTime, x.BaseTime);
131 var labelDisplayId = dailyLabelIdMap.TryGetValue(x.Id, out var dailyId) ? dailyId : FoodLabelingDisplayConsts.NotAvailable; 132 var labelDisplayId = dailyLabelIdMap.TryGetValue(x.Id, out var dailyId) ? dailyId : FoodLabelingDisplayConsts.NotAvailable;
132 return new ReportsPrintLogListItemDto 133 return new ReportsPrintLogListItemDto
133 { 134 {
@@ -219,7 +220,8 @@ public class ReportsAppService : ApplicationService, IReportsAppService @@ -219,7 +220,8 @@ public class ReportsAppService : ApplicationService, IReportsAppService
219 t.PrintInputJson, 220 t.PrintInputJson,
220 t.RenderTemplateJson, 221 t.RenderTemplateJson,
221 t.BaseTime, 222 t.BaseTime,
222 - PrintedAt = SqlFunc.IsNull(t.PrintedAt, t.CreationTime), 223 + t.PrintedAt,
  224 + t.CreationTime,
223 t.CreatedBy, 225 t.CreatedBy,
224 t.LocationId, 226 t.LocationId,
225 LocName = loc.LocationName, 227 LocName = loc.LocationName,
@@ -235,7 +237,7 @@ public class ReportsAppService : ApplicationService, IReportsAppService @@ -235,7 +237,7 @@ public class ReportsAppService : ApplicationService, IReportsAppService
235 rows.Select(x => new ReportsPrintLogDailyLabelIdHelper.PrintTaskScopeKey( 237 rows.Select(x => new ReportsPrintLogDailyLabelIdHelper.PrintTaskScopeKey(
236 x.Id, 238 x.Id,
237 x.LocationId, 239 x.LocationId,
238 - x.PrintedAt ?? DateTime.MinValue)).ToList()); 240 + ResolveStoredPrintInstant(x.PrintedAt, x.CreationTime, x.BaseTime))).ToList());
239 241
240 var fileName = $"print-log_{Clock.Now:yyyy-MM-dd_HH-mm-ss}.pdf"; 242 var fileName = $"print-log_{Clock.Now:yyyy-MM-dd_HH-mm-ss}.pdf";
241 var document = Document.Create(container => 243 var document = Document.Create(container =>
@@ -282,7 +284,7 @@ public class ReportsAppService : ApplicationService, IReportsAppService @@ -282,7 +284,7 @@ public class ReportsAppService : ApplicationService, IReportsAppService
282 table.Cell().BorderBottom(0.5f).BorderColor(Colors.Grey.Lighten2).Padding(3).Text(cat); 284 table.Cell().BorderBottom(0.5f).BorderColor(Colors.Grey.Lighten2).Padding(3).Text(cat);
283 table.Cell().BorderBottom(0.5f).BorderColor(Colors.Grey.Lighten2).Padding(3) 285 table.Cell().BorderBottom(0.5f).BorderColor(Colors.Grey.Lighten2).Padding(3)
284 .Text(FormatTemplateDisplay(x.Width, x.Height, x.Unit, x.TemplateName)); 286 .Text(FormatTemplateDisplay(x.Width, x.Height, x.Unit, x.TemplateName));
285 - var printedAt = x.PrintedAt ?? DateTime.MinValue; 287 + var printedAt = ResolveStoredPrintInstant(x.PrintedAt, x.CreationTime, x.BaseTime);
286 table.Cell().BorderBottom(0.5f).BorderColor(Colors.Grey.Lighten2).Padding(3) 288 table.Cell().BorderBottom(0.5f).BorderColor(Colors.Grey.Lighten2).Padding(3)
287 .Text(ReportsPrintLogPreppedHelper.ExtractFormattedPrintedAt( 289 .Text(ReportsPrintLogPreppedHelper.ExtractFormattedPrintedAt(
288 x.PrintInputJson, 290 x.PrintInputJson,
@@ -381,7 +383,8 @@ public class ReportsAppService : ApplicationService, IReportsAppService @@ -381,7 +383,8 @@ public class ReportsAppService : ApplicationService, IReportsAppService
381 PrintInputJson = t.PrintInputJson, 383 PrintInputJson = t.PrintInputJson,
382 RenderTemplateJson = t.RenderTemplateJson, 384 RenderTemplateJson = t.RenderTemplateJson,
383 BaseTime = t.BaseTime, 385 BaseTime = t.BaseTime,
384 - PrintedAt = SqlFunc.IsNull(t.PrintedAt, t.CreationTime), 386 + PrintedAt = t.PrintedAt,
  387 + CreationTime = t.CreationTime,
385 CreatedBy = t.CreatedBy, 388 CreatedBy = t.CreatedBy,
386 LocationId = t.LocationId, 389 LocationId = t.LocationId,
387 LocName = loc.LocationName, 390 LocName = loc.LocationName,
@@ -397,7 +400,7 @@ public class ReportsAppService : ApplicationService, IReportsAppService @@ -397,7 +400,7 @@ public class ReportsAppService : ApplicationService, IReportsAppService
397 pageRows.Select(x => new ReportsPrintLogDailyLabelIdHelper.PrintTaskScopeKey( 400 pageRows.Select(x => new ReportsPrintLogDailyLabelIdHelper.PrintTaskScopeKey(
398 x.Id, 401 x.Id,
399 x.LocationId, 402 x.LocationId,
400 - x.PrintedAt ?? DateTime.MinValue)).ToList()); 403 + ResolveStoredPrintInstant(x.PrintedAt, x.CreationTime, x.BaseTime))).ToList());
401 404
402 var items = pageRows.Select(x => MapPrintLogExportRowToListItem(x, userMap, dailyLabelIdMap)).ToList(); 405 var items = pageRows.Select(x => MapPrintLogExportRowToListItem(x, userMap, dailyLabelIdMap)).ToList();
403 406
@@ -956,6 +959,8 @@ public class ReportsAppService : ApplicationService, IReportsAppService @@ -956,6 +959,8 @@ public class ReportsAppService : ApplicationService, IReportsAppService
956 959
957 public DateTime? PrintedAt { get; set; } 960 public DateTime? PrintedAt { get; set; }
958 961
  962 + public DateTime CreationTime { get; set; }
  963 +
959 public string? CreatedBy { get; set; } 964 public string? CreatedBy { get; set; }
960 965
961 public string? LocationId { get; set; } 966 public string? LocationId { get; set; }
@@ -975,7 +980,7 @@ public class ReportsAppService : ApplicationService, IReportsAppService @@ -975,7 +980,7 @@ public class ReportsAppService : ApplicationService, IReportsAppService
975 : (string.IsNullOrWhiteSpace(x.LabelCategoryName) ? FoodLabelingDisplayConsts.NotAvailable : x.LabelCategoryName.Trim()); 980 : (string.IsNullOrWhiteSpace(x.LabelCategoryName) ? FoodLabelingDisplayConsts.NotAvailable : x.LabelCategoryName.Trim());
976 var templateText = FormatTemplateDisplay(x.Width, x.Height, x.Unit, x.TemplateName); 981 var templateText = FormatTemplateDisplay(x.Width, x.Height, x.Unit, x.TemplateName);
977 var locText = FormatLocationText(x.LocName, x.LocCode); 982 var locText = FormatLocationText(x.LocName, x.LocCode);
978 - var printedAt = x.PrintedAt ?? DateTime.MinValue; 983 + var printedAt = ResolveStoredPrintInstant(x.PrintedAt, x.CreationTime, x.BaseTime);
979 var labelDisplayId = dailyLabelIdMap.TryGetValue(x.Id, out var dailyId) ? dailyId : FoodLabelingDisplayConsts.NotAvailable; 984 var labelDisplayId = dailyLabelIdMap.TryGetValue(x.Id, out var dailyId) ? dailyId : FoodLabelingDisplayConsts.NotAvailable;
980 return new ReportsPrintLogListItemDto 985 return new ReportsPrintLogListItemDto
981 { 986 {
@@ -1005,4 +1010,29 @@ public class ReportsAppService : ApplicationService, IReportsAppService @@ -1005,4 +1010,29 @@ public class ReportsAppService : ApplicationService, IReportsAppService
1005 printedAt) 1010 printedAt)
1006 }; 1011 };
1007 } 1012 }
  1013 +
  1014 + /// <summary>
  1015 + /// 打印时刻:有真实时分的 PrintedAt → CreationTime → BaseTime;否则 coalesce 非空值(供排序/日序号)。
  1016 + /// </summary>
  1017 + private static DateTime ResolveStoredPrintInstant(DateTime? printedAt, DateTime creationTime, DateTime? baseTime)
  1018 + {
  1019 + if (ReportsPrintLogPreppedHelper.TryPickMeaningfulStoredPrintInstant(printedAt, null, out var fromPrinted)
  1020 + || ReportsPrintLogPreppedHelper.TryPickMeaningfulStoredPrintInstant(creationTime, null, out fromPrinted)
  1021 + || ReportsPrintLogPreppedHelper.TryPickMeaningfulStoredPrintInstant(null, baseTime, out fromPrinted))
  1022 + {
  1023 + return fromPrinted;
  1024 + }
  1025 +
  1026 + if (printedAt.HasValue && printedAt.Value != DateTime.MinValue)
  1027 + {
  1028 + return printedAt.Value;
  1029 + }
  1030 +
  1031 + if (creationTime != DateTime.MinValue)
  1032 + {
  1033 + return creationTime;
  1034 + }
  1035 +
  1036 + return baseTime is { } bt && bt != DateTime.MinValue ? bt : DateTime.MinValue;
  1037 + }
1008 } 1038 }
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/UsAppLabelingAppService.cs
@@ -478,6 +478,13 @@ public class UsAppLabelingAppService : ApplicationService, IUsAppLabelingAppServ @@ -478,6 +478,13 @@ public class UsAppLabelingAppService : ApplicationService, IUsAppLabelingAppServ
478 templateProductDefaultValues ??= new Dictionary<string, object?>(); 478 templateProductDefaultValues ??= new Dictionary<string, object?>();
479 foreach (var (key, value) in labelTemplateInputValues) 479 foreach (var (key, value) in labelTemplateInputValues)
480 { 480 {
  481 + var stored = TemplateProductDefaultValueToStoredString(value);
  482 + if (LabelBatchTemplateDefaultsHelper.TryFindElementByDefaultKey(template.Elements, key, out var el)
  483 + && LabelBatchTemplateDefaultsHelper.IsScrubbableEmptyBarcodeQrDefault(el!, stored))
  484 + {
  485 + continue;
  486 + }
  487 +
481 templateProductDefaultValues[key] = value; 488 templateProductDefaultValues[key] = value;
482 } 489 }
483 } 490 }
@@ -506,6 +513,9 @@ public class UsAppLabelingAppService : ApplicationService, IUsAppLabelingAppServ @@ -506,6 +513,9 @@ public class UsAppLabelingAppService : ApplicationService, IUsAppLabelingAppServ
506 513
507 if (templateProductDefaultValues is { Count: > 0 }) 514 if (templateProductDefaultValues is { Count: > 0 })
508 { 515 {
  516 + LabelBatchTemplateDefaultsHelper.ScrubEmptyBarcodeQrDefaults(
  517 + template.Elements,
  518 + templateProductDefaultValues);
509 ApplyTemplateProductDefaultValuesToPreviewElements(template.Elements, templateProductDefaultValues); 519 ApplyTemplateProductDefaultValuesToPreviewElements(template.Elements, templateProductDefaultValues);
510 } 520 }
511 521
@@ -1329,6 +1339,11 @@ public class UsAppLabelingAppService : ApplicationService, IUsAppLabelingAppServ @@ -1329,6 +1339,11 @@ public class UsAppLabelingAppService : ApplicationService, IUsAppLabelingAppServ
1329 continue; 1339 continue;
1330 } 1340 }
1331 1341
  1342 + if (LabelBatchTemplateDefaultsHelper.IsScrubbableEmptyBarcodeQrDefault(el, stored))
  1343 + {
  1344 + continue;
  1345 + }
  1346 +
1332 var cfg = ParsePreviewElementConfig(el.ConfigJson); 1347 var cfg = ParsePreviewElementConfig(el.ConfigJson);
1333 var type = (el.ElementType ?? string.Empty).Trim().ToUpperInvariant(); 1348 var type = (el.ElementType ?? string.Empty).Trim().ToUpperInvariant();
1334 1349