Commit b1440da4e7c2ad5a5b4eaf667beeb0df5402a6e5

Authored by 李曜臣
1 parent 9b25efa4

2026-09-18代码优化

美国版/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 240 }
241 241  
242 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 324 /// </summary>
245 325 public static async Task<int> CountScopedLocationsAsync(
246 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 3 using FoodLabeling.Application.Contracts.Dtos.Label;
4 4 using FoodLabeling.Application.Contracts.Dtos.LabelTemplate;
5 5 using FoodLabeling.Application.Services.DbModels;
  6 +using FoodLabeling.Domain.Shared;
6 7 using SqlSugar;
7 8 using Volo.Abp;
8 9 using Volo.Abp.Guids;
... ... @@ -76,10 +77,12 @@ public static class LabelBatchTemplateDefaultsHelper
76 77 {
77 78 if (item.TemplateDefaultValues is { Count: > 0 })
78 79 {
79   - return item.TemplateDefaultValues.ToDictionary(
  80 + var fromInput = item.TemplateDefaultValues.ToDictionary(
80 81 x => x.Key,
81 82 x => x.Value,
82 83 StringComparer.OrdinalIgnoreCase);
  84 + ScrubEmptyBarcodeQrDefaults(elements, fromInput);
  85 + return fromInput;
83 86 }
84 87  
85 88 var textValues = item.TemplateDataValues ?? new Dictionary<string, string>();
... ... @@ -108,7 +111,13 @@ public static class LabelBatchTemplateDefaultsHelper
108 111 }
109 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 134 }
126 135  
127 136 var codeValue = (productCodeValue ?? "").Trim();
128   - if (!string.IsNullOrWhiteSpace(codeValue))
  137 + if (!string.IsNullOrWhiteSpace(codeValue) && !FoodLabelingDisplayConsts.IsEmptyDisplay(codeValue))
129 138 {
130 139 foreach (var el in elements)
131 140 {
... ... @@ -160,9 +169,70 @@ public static class LabelBatchTemplateDefaultsHelper
160 169 }
161 170 }
162 171  
  172 + ScrubEmptyBarcodeQrDefaults(elements, outDict);
163 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 236 public static bool HasTemplateDataInput(LabelBatchCreateItemInputVo item) =>
167 237 item.TemplateDefaultValues is { Count: > 0 }
168 238 || item.TemplateDataValues is { Count: > 0 }
... ... @@ -353,15 +423,62 @@ public static class LabelBatchTemplateDefaultsHelper
353 423 private static bool IsNutritionElement(LabelTemplateElementDto el) =>
354 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 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 4 namespace FoodLabeling.Application.Helpers;
5 5  
6 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 9 /// </summary>
9 10 public static class ReportsDateTimeDisplayHelper
10 11 {
... ... @@ -217,7 +218,11 @@ public static class ReportsDateTimeDisplayHelper
217 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 226 public static string FormatExpiryDateTime(DateTime dt)
222 227 {
223 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 6 namespace FoodLabeling.Application.Helpers;
7 7  
8 8 /// <summary>
9   -/// Print Log「Expiry Date」:从打印任务 JSON 解析到期日期时间(优先已渲染的 __previewFormatted)。
  9 +/// Print Log「Expiration」列:从打印快照 <c>elements</c> 收集全部到期相关日期候选,取最早的一个再格式化展示(优先 <c>__previewFormatted</c>)。
10 10 /// </summary>
11 11 public static class ReportsPrintLogExpiryHelper
12 12 {
... ... @@ -30,7 +30,7 @@ public static class ReportsPrintLogExpiryHelper
30 30 };
31 31  
32 32 private static readonly Regex ExpiryNamePattern = new(
33   - @"(durationdate|duration_date|duration\s*date|expirydate|expiry_date|expiry\s*date|expirationdate|expiration_date|usebydate|use_by)",
  33 + @"(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)",
34 34 RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Compiled);
35 35  
36 36 private static readonly Regex ExpiryTimeNamePattern = new(
... ... @@ -38,10 +38,10 @@ public static class ReportsPrintLogExpiryHelper
38 38 RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Compiled);
39 39  
40 40 private static readonly Regex ExcludeNamePattern = new(
41   - @"(currentdate|currenttime|prepped|prepdate|prepon|labelname|durationdate2|duration_date_2|durationdate_2|duration\s*date\s*2)",
  41 + @"(currentdate|currenttime|prepped|prepdate|prepon|pulled|labelname|durationdate2|duration_date_2|durationdate_2|duration\s*date\s*2)",
42 42 RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Compiled);
43 43  
44   - /// <summary>解析并格式化为 Print Log Expiration 列展示(含日期与时间)。</summary>
  44 + /// <summary>解析全部到期候选并取最早时刻,格式化为 Print Log Expiration 列(含日期与时间)。</summary>
45 45 public static string ExtractFormattedExpiryText(
46 46 string? printInputJson,
47 47 string? renderTemplateJson = null,
... ... @@ -51,8 +51,7 @@ public static class ReportsPrintLogExpiryHelper
51 51 var reference = NormalizeExpiryAnchor(baseTime ?? printedAt ?? DateTime.Now);
52 52 if (TryResolveExpiryDateTime(printInputJson, renderTemplateJson, reference, out var resolved))
53 53 {
54   - resolved = ApplyPrintWallClockTimeIfNeeded(
55   - resolved, printInputJson, renderTemplateJson, baseTime, printedAt);
  54 + // 模板最早到期日为纯日期时保留 00:00:00,不补打印墙钟(如 Ready 早于 Discard)
56 55 return ReportsDateTimeDisplayHelper.FormatExpiryDateTime(resolved);
57 56 }
58 57  
... ... @@ -65,53 +64,12 @@ public static class ReportsPrintLogExpiryHelper
65 64 if (!FoodLabelingDisplayConsts.IsEmptyDisplay(raw)
66 65 && ReportsDateTimeDisplayHelper.TryParseExpiryDateTime(raw.Trim(), reference, out var parsed))
67 66 {
68   - parsed = ApplyPrintWallClockTimeIfNeeded(
69   - parsed, printInputJson, renderTemplateJson, baseTime, printedAt);
70 67 return ReportsDateTimeDisplayHelper.FormatExpiryDateTime(parsed);
71 68 }
72 69  
73 70 return ReportsDateTimeDisplayHelper.FormatExpiryDisplay(raw, reference);
74 71 }
75 72  
76   - /// <summary>
77   - /// Use By 为纯日期(00:00:00)时,用 Prepped On / BaseTime / PrintedAt 的墙钟时分秒补全。
78   - /// </summary>
79   - private static DateTime ApplyPrintWallClockTimeIfNeeded(
80   - DateTime expiry,
81   - string? printInputJson,
82   - string? renderTemplateJson,
83   - DateTime? baseTime,
84   - DateTime? printedAt)
85   - {
86   - if (HasRealExpiryTime(expiry))
87   - {
88   - return expiry;
89   - }
90   -
91   - DateTime printClock;
92   - if (ReportsPrintLogPreppedHelper.TryResolvePreppedDateTime(
93   - printInputJson, renderTemplateJson, baseTime, printedAt, out var prepped))
94   - {
95   - printClock = prepped;
96   - }
97   - else
98   - {
99   - printClock = NormalizeExpiryAnchor(baseTime ?? printedAt ?? DateTime.Now);
100   - }
101   -
102   - return new DateTime(
103   - expiry.Year,
104   - expiry.Month,
105   - expiry.Day,
106   - printClock.Hour,
107   - printClock.Minute,
108   - printClock.Second,
109   - expiry.Kind);
110   - }
111   -
112   - private static bool HasRealExpiryTime(DateTime dt) =>
113   - dt.Hour != 0 || dt.Minute != 0 || dt.Second != 0;
114   -
115 73 /// <summary>兼容旧调用:仅 PrintInputJson。</summary>
116 74 public static string ExtractFormattedExpiryText(string? printInputJson) =>
117 75 ExtractFormattedExpiryText(printInputJson, null, null, null);
... ... @@ -156,52 +114,125 @@ public static class ReportsPrintLogExpiryHelper
156 114 return false;
157 115 }
158 116  
159   - if (!TryFindBestElement(elements, isDateElement: true, out var dateElement))
  117 + if (!TryCollectEarliestExpiryDateTime(elements, reference, out expiry))
160 118 {
161 119 return false;
162 120 }
163 121  
164   - if (!TryResolveElementDateTimeValue(dateElement, reference, out var datePart))
  122 + return true;
  123 + }
  124 + catch
  125 + {
  126 + return false;
  127 + }
  128 + }
  129 +
  130 + /// <summary>遍历 elements 中全部到期日期候选,解析为 <see cref="DateTime"/> 后取最早(Min)。</summary>
  131 + private static bool TryCollectEarliestExpiryDateTime(
  132 + JsonElement elements,
  133 + DateTime reference,
  134 + out DateTime earliest)
  135 + {
  136 + earliest = default;
  137 + var candidates = new List<DateTime>();
  138 +
  139 + foreach (var el in elements.EnumerateArray())
  140 + {
  141 + if (el.ValueKind != JsonValueKind.Object)
165 142 {
166   - return false;
  143 + continue;
167 144 }
168 145  
169   - expiry = datePart;
170   - if (HasMeaningfulTime(datePart))
  146 + if (ScoreExpiryDateElement(el) <= 0)
171 147 {
172   - return true;
  148 + continue;
173 149 }
174 150  
175   - // 日期字面量无时分时:仅合并「真实时间」元素;跳过 Duration Time=0 Days(会误用 BaseTime 小时)
176   - if (TryFindBestElement(elements, isDateElement: false, out var timeElement) &&
177   - TryResolveElementDateTimeValue(timeElement, reference, out var timePart) &&
178   - HasMeaningfulTime(timePart) &&
179   - !IsZeroDayDurationTimeElement(timeElement))
  151 + if (!TryResolveExpiryDateTimeForDateElement(elements, el, reference, out var resolved))
180 152 {
181   - expiry = new DateTime(
182   - datePart.Year,
183   - datePart.Month,
184   - datePart.Day,
185   - timePart.Hour,
186   - timePart.Minute,
187   - 0);
188   - return true;
  153 + continue;
189 154 }
190 155  
191   - return true;
  156 + candidates.Add(resolved);
192 157 }
193   - catch
  158 +
  159 + if (candidates.Count == 0)
194 160 {
195 161 return false;
196 162 }
  163 +
  164 + earliest = candidates.Min();
  165 + return true;
197 166 }
198 167  
199   - private static bool TryFindBestElement(JsonElement elements, bool isDateElement, out JsonElement bestElement)
  168 + /// <summary>解析单个到期日期元素;无真实时分时尝试合并配对 durationtime(跳过 0 Days)。</summary>
  169 + private static bool TryResolveExpiryDateTimeForDateElement(
  170 + JsonElement elements,
  171 + JsonElement dateElement,
  172 + DateTime reference,
  173 + out DateTime resolved)
200 174 {
201   - bestElement = default;
202   - var bestScore = 0;
203   - var bestOrder = int.MinValue;
204   - var found = false;
  175 + resolved = default;
  176 + if (!TryResolveElementDateTimeValue(dateElement, reference, out var datePart))
  177 + {
  178 + return false;
  179 + }
  180 +
  181 + resolved = datePart;
  182 + if (HasMeaningfulTime(datePart))
  183 + {
  184 + return true;
  185 + }
  186 +
  187 + if (TryFindPairedTimeElement(elements, dateElement, out var timeElement) &&
  188 + TryResolveElementDateTimeValue(timeElement, reference, out var timePart) &&
  189 + HasMeaningfulTime(timePart) &&
  190 + !IsZeroDayDurationTimeElement(timeElement))
  191 + {
  192 + resolved = new DateTime(
  193 + datePart.Year,
  194 + datePart.Month,
  195 + datePart.Day,
  196 + timePart.Hour,
  197 + timePart.Minute,
  198 + 0);
  199 + }
  200 +
  201 + return true;
  202 + }
  203 +
  204 + /// <summary>为到期日期元素查找配对时间元素(durationdate↔durationtime 或同名 time 后缀)。</summary>
  205 + private static bool TryFindPairedTimeElement(
  206 + JsonElement elements,
  207 + JsonElement dateElement,
  208 + out JsonElement timeElement)
  209 + {
  210 + timeElement = default;
  211 + var dateName = GetStringProperty(dateElement, "elementName", "ElementName").Trim();
  212 + if (string.IsNullOrWhiteSpace(dateName))
  213 + {
  214 + return false;
  215 + }
  216 +
  217 + if (dateName.Equals("durationdate", StringComparison.OrdinalIgnoreCase))
  218 + {
  219 + foreach (var el in elements.EnumerateArray())
  220 + {
  221 + if (el.ValueKind != JsonValueKind.Object)
  222 + {
  223 + continue;
  224 + }
  225 +
  226 + var name = GetStringProperty(el, "elementName", "ElementName").Trim();
  227 + if (name.Equals("durationtime", StringComparison.OrdinalIgnoreCase))
  228 + {
  229 + timeElement = el;
  230 + return true;
  231 + }
  232 + }
  233 +
  234 + return false;
  235 + }
205 236  
206 237 foreach (var el in elements.EnumerateArray())
207 238 {
... ... @@ -210,28 +241,34 @@ public static class ReportsPrintLogExpiryHelper
210 241 continue;
211 242 }
212 243  
213   - var score = isDateElement ? ScoreExpiryDateElement(el) : ScoreExpiryTimeElement(el);
214   - if (score <= 0)
  244 + var name = GetStringProperty(el, "elementName", "ElementName").Trim();
  245 + if (string.IsNullOrWhiteSpace(name))
215 246 {
216 247 continue;
217 248 }
218 249  
219   - var order = TryGetIntProperty(el, "orderNum", "OrderNum") ?? 0;
220   - if (score > bestScore || (score == bestScore && order > bestOrder))
  250 + if (ScoreExpiryTimeElement(el) <= 0 && !ExpiryTimeNamePattern.IsMatch(name))
221 251 {
222   - bestScore = score;
223   - bestOrder = order;
224   - bestElement = el;
225   - found = true;
  252 + continue;
  253 + }
  254 +
  255 + if (name.Equals(dateName + "time", StringComparison.OrdinalIgnoreCase))
  256 + {
  257 + timeElement = el;
  258 + return true;
  259 + }
  260 +
  261 + if (dateName.EndsWith("date", StringComparison.OrdinalIgnoreCase) &&
  262 + name.Equals(dateName[..^4] + "time", StringComparison.OrdinalIgnoreCase))
  263 + {
  264 + timeElement = el;
  265 + return true;
226 266 }
227 267 }
228 268  
229   - return found;
  269 + return false;
230 270 }
231 271  
232   - private static bool TryResolveElementDateTime(JsonElement el, DateTime reference, out DateTime result) =>
233   - TryResolveElementDateTimeValue(el, reference, out result);
234   -
235 272 /// <summary>
236 273 /// 从模板元素直接解析到期 <see cref="DateTime"/>,避免 DATE 预设格式(如 MM/DD/YY)剥掉锚点时分。
237 274 /// 优先使用打印快照已渲染的 <c>__previewFormatted</c> / 字面量,避免用 UTC BaseTime 重算偏移导致小时偏差。
... ... @@ -582,7 +619,7 @@ public static class ReportsPrintLogExpiryHelper
582 619 }
583 620  
584 621 private static bool HasMeaningfulTime(DateTime dt) =>
585   - dt.Hour != 0 || dt.Minute != 0;
  622 + ReportsDateTimeDisplayHelper.HasMeaningfulWallClockTime(dt);
586 623  
587 624 /// <summary>
588 625 /// Duration Time 配置为 0 Days 时不应把 BaseTime 的时分并进 Expiration(标签 Use By 常为纯日期)。
... ... @@ -651,12 +688,7 @@ public static class ReportsPrintLogExpiryHelper
651 688  
652 689 if (TryGetProperty(root, "elements", out var elements) && elements.ValueKind == JsonValueKind.Array)
653 690 {
654   - if (TryExtractNamedDurationExpiry(elements, anchor, out var fromNamed))
655   - {
656   - return fromNamed;
657   - }
658   -
659   - if (TryExtractFromElements(elements, anchor, out var fromElements))
  691 + if (TryExtractEarliestFromElements(elements, anchor, out var fromElements))
660 692 {
661 693 return fromElements;
662 694 }
... ... @@ -739,48 +771,18 @@ public static class ReportsPrintLogExpiryHelper
739 771 return false;
740 772 }
741 773  
742   - /// <summary>优先按 elementName 合并 durationdate + durationtime(App 打印快照常见结构)。</summary>
743   - private static bool TryExtractNamedDurationExpiry(JsonElement elements, DateTime anchor, out string text)
  774 + /// <summary>从 elements 收集全部到期候选,解析后取最早再格式化为展示文本(与 DateTime 主路径一致)。</summary>
  775 + private static bool TryExtractEarliestFromElements(JsonElement elements, DateTime anchor, out string text)
744 776 {
745 777 text = FoodLabelingDisplayConsts.NotAvailable;
746   - string? datePart = null;
747   - string? timePart = null;
748   -
749   - foreach (var el in elements.EnumerateArray())
  778 + if (TryCollectEarliestExpiryDateTime(elements, anchor, out var earliest))
750 779 {
751   - if (el.ValueKind != JsonValueKind.Object)
752   - {
753   - continue;
754   - }
755   -
756   - var name = GetStringProperty(el, "elementName", "ElementName").Trim();
757   - if (name.Equals("durationdate", StringComparison.OrdinalIgnoreCase))
758   - {
759   - datePart = GetElementConfigDisplayText(el, anchor);
760   - }
761   - else if (name.Equals("durationtime", StringComparison.OrdinalIgnoreCase))
762   - {
763   - timePart = GetElementConfigDisplayText(el, anchor);
764   - }
765   - }
766   -
767   - if (string.IsNullOrWhiteSpace(datePart) || IsMissingExpiry(datePart))
768   - {
769   - return false;
  780 + text = ReportsDateTimeDisplayHelper.FormatExpiryDateTime(earliest);
  781 + return true;
770 782 }
771 783  
772   - text = string.IsNullOrWhiteSpace(timePart) || IsMissingExpiry(timePart)
773   - ? datePart.Trim()
774   - : ReportsDateTimeDisplayHelper.MergeDateAndTimeParts(datePart.Trim(), timePart.Trim(), anchor);
775   - return true;
776   - }
777   -
778   - private static bool TryExtractFromElements(JsonElement elements, DateTime anchor, out string text)
779   - {
780   - text = FoodLabelingDisplayConsts.NotAvailable;
781   - var bestScore = 0;
782   - string? bestText = null;
783   - var bestOrder = int.MinValue;
  784 + DateTime? earliestParsed = null;
  785 + string? earliestRaw = null;
784 786  
785 787 foreach (var el in elements.EnumerateArray())
786 788 {
... ... @@ -789,33 +791,44 @@ public static class ReportsPrintLogExpiryHelper
789 791 continue;
790 792 }
791 793  
792   - var score = ScoreExpiryDateElement(el);
793   - if (score <= 0)
  794 + if (ScoreExpiryDateElement(el) <= 0)
794 795 {
795 796 continue;
796 797 }
797 798  
798 799 var display = GetElementConfigDisplayText(el, anchor);
799   - if (string.IsNullOrWhiteSpace(display))
  800 + if (string.IsNullOrWhiteSpace(display) || IsMissingExpiry(display))
800 801 {
801 802 continue;
802 803 }
803 804  
804   - var order = TryGetIntProperty(el, "orderNum", "OrderNum") ?? 0;
805   - if (score > bestScore || (score == bestScore && order > bestOrder))
  805 + var trimmed = display.Trim();
  806 + if (ReportsDateTimeDisplayHelper.TryParseExpiryDateTime(trimmed, anchor, out var parsed))
  807 + {
  808 + if (!earliestParsed.HasValue || parsed < earliestParsed.Value)
  809 + {
  810 + earliestParsed = parsed;
  811 + earliestRaw = trimmed;
  812 + }
  813 + }
  814 + else if (!earliestParsed.HasValue && earliestRaw is null)
806 815 {
807   - bestScore = score;
808   - bestOrder = order;
809   - bestText = display.Trim();
  816 + earliestRaw = trimmed;
810 817 }
811 818 }
812 819  
813   - if (string.IsNullOrWhiteSpace(bestText))
  820 + if (earliestParsed.HasValue)
  821 + {
  822 + text = ReportsDateTimeDisplayHelper.FormatExpiryDateTime(earliestParsed.Value);
  823 + return true;
  824 + }
  825 +
  826 + if (string.IsNullOrWhiteSpace(earliestRaw))
814 827 {
815 828 return false;
816 829 }
817 830  
818   - text = bestText;
  831 + text = earliestRaw;
819 832 return true;
820 833 }
821 834  
... ...
美国版/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 5 namespace FoodLabeling.Application.Helpers;
6 6  
7 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 10 /// </summary>
10 11 public static class ReportsPrintLogPreppedHelper
11 12 {
... ... @@ -38,7 +39,7 @@ public static class ReportsPrintLogPreppedHelper
38 39 }
39 40  
40 41 /// <summary>
41   - /// 解析标签 Prepped On 并格式化为 Printed at 列;无法解析时回退 <paramref name="printedAtFallback"/>。
  42 + /// 格式化 Printed at 列:库内有真实时分的打印时刻优先;禁止在存在真实时分来源时输出 <c>00:00:00</c>。
42 43 /// </summary>
43 44 public static string ExtractFormattedPrintedAt(
44 45 string? printInputJson,
... ... @@ -46,12 +47,128 @@ public static class ReportsPrintLogPreppedHelper
46 47 DateTime? baseTime = null,
47 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 174 private static bool TryResolvePreppedDateTimeFromSources(
... ... @@ -126,8 +243,8 @@ public static class ReportsPrintLogPreppedHelper
126 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 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 82 var regionsPrevWeek = await DashboardScopeHelper.CountScopedRegionsAsync(
83 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 90 var people = await DashboardScopeHelper.CountScopedRegisteredUsersAsync(
90 91 db, scopeLocationIds, activeOnly: false, createdBefore: null);
... ... @@ -96,23 +97,8 @@ public class DashboardAppService : ApplicationService, IDashboardAppService
96 97 var labelsPrevWeek = await DashboardScopeHelper.CountScopedLabelsAsync(
97 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 102 // fl_product 当前实体未映射 CreationTime,无法按时间切分对比,先回退为同口径总量对比
117 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 102 t.PrintInputJson,
103 103 t.RenderTemplateJson,
104 104 t.BaseTime,
105   - PrintedAt = SqlFunc.IsNull(t.PrintedAt, t.CreationTime),
  105 + t.PrintedAt,
  106 + t.CreationTime,
106 107 t.CreatedBy,
107 108 t.LocationId,
108 109 LocName = loc.LocationName,
... ... @@ -118,7 +119,7 @@ public class ReportsAppService : ApplicationService, IReportsAppService
118 119 pageRows.Select(x => new ReportsPrintLogDailyLabelIdHelper.PrintTaskScopeKey(
119 120 x.Id,
120 121 x.LocationId,
121   - x.PrintedAt ?? DateTime.MinValue)).ToList());
  122 + ResolveStoredPrintInstant(x.PrintedAt, x.CreationTime, x.BaseTime))).ToList());
122 123  
123 124 var items = pageRows.Select(x =>
124 125 {
... ... @@ -127,7 +128,7 @@ public class ReportsAppService : ApplicationService, IReportsAppService
127 128 : (string.IsNullOrWhiteSpace(x.LabelCategoryName) ? FoodLabelingDisplayConsts.NotAvailable : x.LabelCategoryName.Trim());
128 129 var templateText = FormatTemplateDisplay(x.Width, x.Height, x.Unit, x.TemplateName);
129 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 132 var labelDisplayId = dailyLabelIdMap.TryGetValue(x.Id, out var dailyId) ? dailyId : FoodLabelingDisplayConsts.NotAvailable;
132 133 return new ReportsPrintLogListItemDto
133 134 {
... ... @@ -219,7 +220,8 @@ public class ReportsAppService : ApplicationService, IReportsAppService
219 220 t.PrintInputJson,
220 221 t.RenderTemplateJson,
221 222 t.BaseTime,
222   - PrintedAt = SqlFunc.IsNull(t.PrintedAt, t.CreationTime),
  223 + t.PrintedAt,
  224 + t.CreationTime,
223 225 t.CreatedBy,
224 226 t.LocationId,
225 227 LocName = loc.LocationName,
... ... @@ -235,7 +237,7 @@ public class ReportsAppService : ApplicationService, IReportsAppService
235 237 rows.Select(x => new ReportsPrintLogDailyLabelIdHelper.PrintTaskScopeKey(
236 238 x.Id,
237 239 x.LocationId,
238   - x.PrintedAt ?? DateTime.MinValue)).ToList());
  240 + ResolveStoredPrintInstant(x.PrintedAt, x.CreationTime, x.BaseTime))).ToList());
239 241  
240 242 var fileName = $"print-log_{Clock.Now:yyyy-MM-dd_HH-mm-ss}.pdf";
241 243 var document = Document.Create(container =>
... ... @@ -282,7 +284,7 @@ public class ReportsAppService : ApplicationService, IReportsAppService
282 284 table.Cell().BorderBottom(0.5f).BorderColor(Colors.Grey.Lighten2).Padding(3).Text(cat);
283 285 table.Cell().BorderBottom(0.5f).BorderColor(Colors.Grey.Lighten2).Padding(3)
284 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 288 table.Cell().BorderBottom(0.5f).BorderColor(Colors.Grey.Lighten2).Padding(3)
287 289 .Text(ReportsPrintLogPreppedHelper.ExtractFormattedPrintedAt(
288 290 x.PrintInputJson,
... ... @@ -381,7 +383,8 @@ public class ReportsAppService : ApplicationService, IReportsAppService
381 383 PrintInputJson = t.PrintInputJson,
382 384 RenderTemplateJson = t.RenderTemplateJson,
383 385 BaseTime = t.BaseTime,
384   - PrintedAt = SqlFunc.IsNull(t.PrintedAt, t.CreationTime),
  386 + PrintedAt = t.PrintedAt,
  387 + CreationTime = t.CreationTime,
385 388 CreatedBy = t.CreatedBy,
386 389 LocationId = t.LocationId,
387 390 LocName = loc.LocationName,
... ... @@ -397,7 +400,7 @@ public class ReportsAppService : ApplicationService, IReportsAppService
397 400 pageRows.Select(x => new ReportsPrintLogDailyLabelIdHelper.PrintTaskScopeKey(
398 401 x.Id,
399 402 x.LocationId,
400   - x.PrintedAt ?? DateTime.MinValue)).ToList());
  403 + ResolveStoredPrintInstant(x.PrintedAt, x.CreationTime, x.BaseTime))).ToList());
401 404  
402 405 var items = pageRows.Select(x => MapPrintLogExportRowToListItem(x, userMap, dailyLabelIdMap)).ToList();
403 406  
... ... @@ -956,6 +959,8 @@ public class ReportsAppService : ApplicationService, IReportsAppService
956 959  
957 960 public DateTime? PrintedAt { get; set; }
958 961  
  962 + public DateTime CreationTime { get; set; }
  963 +
959 964 public string? CreatedBy { get; set; }
960 965  
961 966 public string? LocationId { get; set; }
... ... @@ -975,7 +980,7 @@ public class ReportsAppService : ApplicationService, IReportsAppService
975 980 : (string.IsNullOrWhiteSpace(x.LabelCategoryName) ? FoodLabelingDisplayConsts.NotAvailable : x.LabelCategoryName.Trim());
976 981 var templateText = FormatTemplateDisplay(x.Width, x.Height, x.Unit, x.TemplateName);
977 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 984 var labelDisplayId = dailyLabelIdMap.TryGetValue(x.Id, out var dailyId) ? dailyId : FoodLabelingDisplayConsts.NotAvailable;
980 985 return new ReportsPrintLogListItemDto
981 986 {
... ... @@ -1005,4 +1010,29 @@ public class ReportsAppService : ApplicationService, IReportsAppService
1005 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 478 templateProductDefaultValues ??= new Dictionary<string, object?>();
479 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 488 templateProductDefaultValues[key] = value;
482 489 }
483 490 }
... ... @@ -506,6 +513,9 @@ public class UsAppLabelingAppService : ApplicationService, IUsAppLabelingAppServ
506 513  
507 514 if (templateProductDefaultValues is { Count: > 0 })
508 515 {
  516 + LabelBatchTemplateDefaultsHelper.ScrubEmptyBarcodeQrDefaults(
  517 + template.Elements,
  518 + templateProductDefaultValues);
509 519 ApplyTemplateProductDefaultValuesToPreviewElements(template.Elements, templateProductDefaultValues);
510 520 }
511 521  
... ... @@ -1329,6 +1339,11 @@ public class UsAppLabelingAppService : ApplicationService, IUsAppLabelingAppServ
1329 1339 continue;
1330 1340 }
1331 1341  
  1342 + if (LabelBatchTemplateDefaultsHelper.IsScrubbableEmptyBarcodeQrDefault(el, stored))
  1343 + {
  1344 + continue;
  1345 + }
  1346 +
1332 1347 var cfg = ParsePreviewElementConfig(el.ConfigJson);
1333 1348 var type = (el.ElementType ?? string.Empty).Trim().ToUpperInvariant();
1334 1349  
... ...