Commit 79c9b19fd05fa677dd2e8769f89acdf5528b3e56
1 parent
177fe12d
2026-08-07代码优化
Showing
17 changed files
with
1094 additions
and
17 deletions
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/Common/ITrainingFileScopeInput.cs
0 → 100644
| 1 | +namespace FoodLabeling.Application.Contracts.Dtos.Common; | ||
| 2 | + | ||
| 3 | +/// <summary> | ||
| 4 | +/// 培训文件创建/编辑入参中的 Company / Region / Location 适用范围字段。 | ||
| 5 | +/// </summary> | ||
| 6 | +public interface ITrainingFileScopeInput : ILabelEntityPartnerScopeInput | ||
| 7 | +{ | ||
| 8 | + /// <summary>适用 Region:ALL / SPECIFIED</summary> | ||
| 9 | + string? AppliedRegionType { get; } | ||
| 10 | + | ||
| 11 | + /// <summary>适用 Region(<c>fl_group.Id</c>);与 <see cref="GroupIds"/> 合并;可含 <c>ALL</c></summary> | ||
| 12 | + List<string>? RegionIds { get; } | ||
| 13 | + | ||
| 14 | + /// <summary>与 <see cref="RegionIds"/> 相同;可含 <c>ALL</c></summary> | ||
| 15 | + List<string>? GroupIds { get; } | ||
| 16 | + | ||
| 17 | + /// <summary>适用 Location:ALL / SPECIFIED(与 <see cref="AppliedLocationType"/> 二选一)</summary> | ||
| 18 | + string? AvailabilityType { get; } | ||
| 19 | + | ||
| 20 | + /// <summary>适用 Location:ALL / SPECIFIED(<see cref="AvailabilityType"/> 别名)</summary> | ||
| 21 | + string? AppliedLocationType { get; } | ||
| 22 | + | ||
| 23 | + /// <summary>适用门店(<c>location.Id</c>);可含 <c>ALL</c></summary> | ||
| 24 | + List<string>? LocationIds { get; } | ||
| 25 | +} |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelAlertTimer/LabelAlertTimerCheckExpiredInputVo.cs
0 → 100644
| 1 | +namespace FoodLabeling.Application.Contracts.Dtos.LabelAlertTimer; | ||
| 2 | + | ||
| 3 | +/// <summary> | ||
| 4 | +/// 检查告警计时器是否过期入参(至少提供一个标识) | ||
| 5 | +/// </summary> | ||
| 6 | +public class LabelAlertTimerCheckExpiredInputVo | ||
| 7 | +{ | ||
| 8 | + public string? TimerId { get; set; } | ||
| 9 | + | ||
| 10 | + public string? BatchId { get; set; } | ||
| 11 | + | ||
| 12 | + public string? PrintTaskId { get; set; } | ||
| 13 | +} |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelAlertTimer/LabelAlertTimerCheckExpiredOutputDto.cs
0 → 100644
| 1 | +namespace FoodLabeling.Application.Contracts.Dtos.LabelAlertTimer; | ||
| 2 | + | ||
| 3 | +/// <summary> | ||
| 4 | +/// 检查告警计时器是否过期出参 | ||
| 5 | +/// </summary> | ||
| 6 | +public class LabelAlertTimerCheckExpiredOutputDto | ||
| 7 | +{ | ||
| 8 | + /// <summary>是否找到计时器记录</summary> | ||
| 9 | + public bool Found { get; set; } | ||
| 10 | + | ||
| 11 | + /// <summary>是否已过期;无记录时为 false(允许继续打印)</summary> | ||
| 12 | + public bool IsExpired { get; set; } | ||
| 13 | + | ||
| 14 | + public DateTime? ExpiresAt { get; set; } | ||
| 15 | + | ||
| 16 | + /// <summary>剩余秒数(已过期为 0)</summary> | ||
| 17 | + public int RemainingSeconds { get; set; } | ||
| 18 | + | ||
| 19 | + /// <summary>状态:<c>expired</c> 或 <c>running</c></summary> | ||
| 20 | + public string? Status { get; set; } | ||
| 21 | + | ||
| 22 | + public string? Title { get; set; } | ||
| 23 | + | ||
| 24 | + public string? Subtitle { get; set; } | ||
| 25 | + | ||
| 26 | + public string? TimerId { get; set; } | ||
| 27 | + | ||
| 28 | + public string? BatchId { get; set; } | ||
| 29 | +} |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelAlertTimer/LabelAlertTimerGetListInputVo.cs
0 → 100644
| 1 | +using Volo.Abp.Application.Dtos; | ||
| 2 | + | ||
| 3 | +namespace FoodLabeling.Application.Contracts.Dtos.LabelAlertTimer; | ||
| 4 | + | ||
| 5 | +/// <summary> | ||
| 6 | +/// 告警计时器分页列表入参 | ||
| 7 | +/// </summary> | ||
| 8 | +public class LabelAlertTimerGetListInputVo : PagedAndSortedResultRequestDto | ||
| 9 | +{ | ||
| 10 | + /// <summary> | ||
| 11 | + /// 当前门店 Id(location.Id,Guid 字符串,必填) | ||
| 12 | + /// </summary> | ||
| 13 | + public string? LocationId { get; set; } | ||
| 14 | + | ||
| 15 | + /// <summary> | ||
| 16 | + /// 打印日期(<c>yyyy-MM-dd</c>);按 PrintedAt 筛选该日记录。 | ||
| 17 | + /// </summary> | ||
| 18 | + public string? DateDay { get; set; } | ||
| 19 | +} |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelAlertTimer/LabelAlertTimerListItemDto.cs
0 → 100644
| 1 | +namespace FoodLabeling.Application.Contracts.Dtos.LabelAlertTimer; | ||
| 2 | + | ||
| 3 | +/// <summary> | ||
| 4 | +/// 告警计时器列表项 | ||
| 5 | +/// </summary> | ||
| 6 | +public class LabelAlertTimerListItemDto | ||
| 7 | +{ | ||
| 8 | + public string Id { get; set; } = string.Empty; | ||
| 9 | + | ||
| 10 | + public string BatchId { get; set; } = string.Empty; | ||
| 11 | + | ||
| 12 | + public string PrintTaskId { get; set; } = string.Empty; | ||
| 13 | + | ||
| 14 | + public string LabelId { get; set; } = string.Empty; | ||
| 15 | + | ||
| 16 | + public string? LabelCode { get; set; } | ||
| 17 | + | ||
| 18 | + public string Title { get; set; } = string.Empty; | ||
| 19 | + | ||
| 20 | + public string Subtitle { get; set; } = string.Empty; | ||
| 21 | + | ||
| 22 | + /// <summary>总时长(秒),同 DurationSeconds</summary> | ||
| 23 | + public int TotalTime { get; set; } | ||
| 24 | + | ||
| 25 | + /// <summary>剩余时长(秒)</summary> | ||
| 26 | + public int RemainingTime { get; set; } | ||
| 27 | + | ||
| 28 | + /// <summary>状态:<c>expired</c> 或 <c>running</c></summary> | ||
| 29 | + public string Status { get; set; } = string.Empty; | ||
| 30 | + | ||
| 31 | + public DateTime ExpiresAt { get; set; } | ||
| 32 | + | ||
| 33 | + public DateTime PrintedAt { get; set; } | ||
| 34 | + | ||
| 35 | + public string LocationId { get; set; } = string.Empty; | ||
| 36 | + | ||
| 37 | + public string? ProductName { get; set; } | ||
| 38 | +} |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/IServices/ILabelAlertTimerAppService.cs
0 → 100644
| 1 | +using FoodLabeling.Application.Contracts.Dtos.Common; | ||
| 2 | +using FoodLabeling.Application.Contracts.Dtos.LabelAlertTimer; | ||
| 3 | +using Volo.Abp.Application.Services; | ||
| 4 | + | ||
| 5 | +namespace FoodLabeling.Application.Contracts.IServices; | ||
| 6 | + | ||
| 7 | +/// <summary> | ||
| 8 | +/// 标签告警计时器(App) | ||
| 9 | +/// </summary> | ||
| 10 | +public interface ILabelAlertTimerAppService : IApplicationService | ||
| 11 | +{ | ||
| 12 | + Task<PagedResultWithPageDto<LabelAlertTimerListItemDto>> GetListAsync(LabelAlertTimerGetListInputVo input); | ||
| 13 | + | ||
| 14 | + Task DeleteAsync(string id); | ||
| 15 | + | ||
| 16 | + Task<LabelAlertTimerCheckExpiredOutputDto> CheckExpiredAsync(LabelAlertTimerCheckExpiredInputVo input); | ||
| 17 | +} |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/LabelAlertTimerWriteHelper.cs
0 → 100644
| 1 | +using System.Globalization; | ||
| 2 | +using FoodLabeling.Application.Services.DbModels; | ||
| 3 | +using FoodLabeling.Domain.Shared.Helpers; | ||
| 4 | +using SqlSugar; | ||
| 5 | + | ||
| 6 | +namespace FoodLabeling.Application.Helpers; | ||
| 7 | + | ||
| 8 | +/// <summary> | ||
| 9 | +/// 打印成功后写入告警计时器(按 BatchId 幂等,一条批次一条计时器)。 | ||
| 10 | +/// </summary> | ||
| 11 | +public static class LabelAlertTimerWriteHelper | ||
| 12 | +{ | ||
| 13 | + /// <summary> | ||
| 14 | + /// 根据打印批次创建告警计时器;已存在未删除记录或无有效过期时刻时直接返回。 | ||
| 15 | + /// </summary> | ||
| 16 | + public static async Task TryCreateFromPrintBatchAsync( | ||
| 17 | + ISqlSugarClient db, | ||
| 18 | + string batchId, | ||
| 19 | + string? createdBy, | ||
| 20 | + CancellationToken ct = default) | ||
| 21 | + { | ||
| 22 | + var bid = batchId?.Trim(); | ||
| 23 | + if (string.IsNullOrWhiteSpace(bid)) | ||
| 24 | + { | ||
| 25 | + return; | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + ct.ThrowIfCancellationRequested(); | ||
| 29 | + | ||
| 30 | + // BatchId 有唯一索引:含软删记录也不再插入,避免幂等补写撞唯一约束 | ||
| 31 | + var exists = await db.Queryable<FlLabelAlertTimerDbEntity>() | ||
| 32 | + .AnyAsync(x => x.BatchId == bid); | ||
| 33 | + if (exists) | ||
| 34 | + { | ||
| 35 | + return; | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + var task = (await db.Queryable<FlLabelPrintTaskDbEntity>() | ||
| 39 | + .Where(x => x.BatchId == bid) | ||
| 40 | + .OrderBy(x => x.CopyIndex) | ||
| 41 | + .Take(1) | ||
| 42 | + .ToListAsync(ct)) | ||
| 43 | + .FirstOrDefault(); | ||
| 44 | + if (task is null) | ||
| 45 | + { | ||
| 46 | + return; | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + var printedAt = task.PrintedAt ?? task.BaseTime ?? task.CreationTime; | ||
| 50 | + if (!ReportsPrintLogExpiryHelper.TryResolveExpiryDateTime( | ||
| 51 | + task.PrintInputJson, | ||
| 52 | + task.RenderTemplateJson, | ||
| 53 | + task.BaseTime, | ||
| 54 | + printedAt, | ||
| 55 | + out var expiresAt)) | ||
| 56 | + { | ||
| 57 | + return; | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + var label = (await db.Queryable<FlLabelDbEntity>() | ||
| 61 | + .Where(x => x.Id == task.LabelId) | ||
| 62 | + .Select(x => new { x.LabelName, x.LabelCode }) | ||
| 63 | + .Take(1) | ||
| 64 | + .ToListAsync(ct)) | ||
| 65 | + .FirstOrDefault(); | ||
| 66 | + | ||
| 67 | + var labelName = label?.LabelName?.Trim(); | ||
| 68 | + if (string.IsNullOrWhiteSpace(labelName)) | ||
| 69 | + { | ||
| 70 | + labelName = FoodLabelingDisplayConsts.NotAvailable; | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + string? productName = null; | ||
| 74 | + if (!string.IsNullOrWhiteSpace(task.ProductId)) | ||
| 75 | + { | ||
| 76 | + productName = (await db.Queryable<FlProductDbEntity>() | ||
| 77 | + .Where(x => x.Id == task.ProductId && !x.IsDeleted) | ||
| 78 | + .Select(x => x.ProductName) | ||
| 79 | + .Take(1) | ||
| 80 | + .ToListAsync(ct)) | ||
| 81 | + .FirstOrDefault(); | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + var durationSeconds = Math.Max(0, (int)(expiresAt - printedAt).TotalSeconds); | ||
| 85 | + var title = BuildTitle(labelName, durationSeconds); | ||
| 86 | + var subtitle = BuildSubtitle(durationSeconds, expiresAt); | ||
| 87 | + var now = DateTime.Now; | ||
| 88 | + | ||
| 89 | + var entity = new FlLabelAlertTimerDbEntity | ||
| 90 | + { | ||
| 91 | + Id = YitIdHelper.NextId().ToString(), | ||
| 92 | + BatchId = bid, | ||
| 93 | + PrintTaskId = task.Id, | ||
| 94 | + LabelId = task.LabelId, | ||
| 95 | + LabelCode = label?.LabelCode?.Trim(), | ||
| 96 | + LabelName = labelName, | ||
| 97 | + ProductId = task.ProductId, | ||
| 98 | + ProductName = string.IsNullOrWhiteSpace(productName) ? null : productName.Trim(), | ||
| 99 | + LocationId = task.LocationId?.Trim() ?? string.Empty, | ||
| 100 | + PrintedAt = printedAt, | ||
| 101 | + BaseTime = task.BaseTime, | ||
| 102 | + ExpiresAt = expiresAt, | ||
| 103 | + DurationSeconds = durationSeconds, | ||
| 104 | + Title = title, | ||
| 105 | + Subtitle = subtitle, | ||
| 106 | + IsDeleted = false, | ||
| 107 | + DeletionTime = null, | ||
| 108 | + CreatedBy = createdBy, | ||
| 109 | + CreationTime = now | ||
| 110 | + }; | ||
| 111 | + | ||
| 112 | + await db.Insertable(entity).ExecuteCommandAsync(); | ||
| 113 | + } | ||
| 114 | + | ||
| 115 | + private static string BuildTitle(string labelName, int durationSeconds) | ||
| 116 | + { | ||
| 117 | + var hoursText = FormatDurationHoursLabel(durationSeconds); | ||
| 118 | + return string.IsNullOrWhiteSpace(hoursText) ? labelName : $"{labelName} ({hoursText})"; | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + private static string BuildSubtitle(int durationSeconds, DateTime expiresAt) | ||
| 122 | + { | ||
| 123 | + var hoursText = FormatDurationHoursLabel(durationSeconds); | ||
| 124 | + var timeText = expiresAt.ToString("h:mm tt", CultureInfo.CurrentCulture); | ||
| 125 | + return string.IsNullOrWhiteSpace(hoursText) | ||
| 126 | + ? $"Completes at {timeText}" | ||
| 127 | + : $"{hoursText} Completes at {timeText}"; | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + private static string FormatDurationHoursLabel(int durationSeconds) | ||
| 131 | + { | ||
| 132 | + if (durationSeconds <= 0) | ||
| 133 | + { | ||
| 134 | + return string.Empty; | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + var totalHours = durationSeconds / 3600.0; | ||
| 138 | + if (totalHours >= 1) | ||
| 139 | + { | ||
| 140 | + var rounded = (int)Math.Round(totalHours, MidpointRounding.AwayFromZero); | ||
| 141 | + rounded = Math.Max(1, rounded); | ||
| 142 | + return rounded == 1 ? "1 hour" : $"{rounded} hours"; | ||
| 143 | + } | ||
| 144 | + | ||
| 145 | + var minutes = Math.Max(1, (int)Math.Ceiling(durationSeconds / 60.0)); | ||
| 146 | + return minutes == 1 ? "1 minute" : $"{minutes} minutes"; | ||
| 147 | + } | ||
| 148 | +} |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/LabelEntityPartnerScopeHelper.cs
| @@ -340,7 +340,14 @@ public static class LabelEntityPartnerScopeHelper | @@ -340,7 +340,14 @@ public static class LabelEntityPartnerScopeHelper | ||
| 340 | else | 340 | else |
| 341 | { | 341 | { |
| 342 | var collapsed = await ScopeAllEchoHelper.CollapseScopeIdsToAllSentinelAsync( | 342 | var collapsed = await ScopeAllEchoHelper.CollapseScopeIdsToAllSentinelAsync( |
| 343 | - db, pIds, null, null); | 343 | + db, |
| 344 | + pIds, | ||
| 345 | + null, | ||
| 346 | + null, | ||
| 347 | + new ScopeAllEchoHelper.ScopeAllEchoOptions | ||
| 348 | + { | ||
| 349 | + AppliedPartnerType = partnerType | ||
| 350 | + }); | ||
| 344 | displayPartnerIds = collapsed.PartnerIds; | 351 | displayPartnerIds = collapsed.PartnerIds; |
| 345 | } | 352 | } |
| 346 | 353 |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/ScopeAllEchoHelper.cs
| @@ -14,6 +14,13 @@ public static class ScopeAllEchoHelper | @@ -14,6 +14,13 @@ public static class ScopeAllEchoHelper | ||
| 14 | public bool IsRegionAll { get; init; } | 14 | public bool IsRegionAll { get; init; } |
| 15 | 15 | ||
| 16 | public bool IsLocationAll { get; init; } | 16 | public bool IsLocationAll { get; init; } |
| 17 | + | ||
| 18 | + /// <summary>落库维度为 SPECIFIED 时禁止再按「恰好全选」折叠为 ALL 哨兵。</summary> | ||
| 19 | + public string? AppliedPartnerType { get; init; } | ||
| 20 | + | ||
| 21 | + public string? AppliedRegionType { get; init; } | ||
| 22 | + | ||
| 23 | + public string? AppliedLocationType { get; init; } | ||
| 17 | } | 24 | } |
| 18 | 25 | ||
| 19 | /// <summary> | 26 | /// <summary> |
| @@ -36,7 +43,7 @@ public static class ScopeAllEchoHelper | @@ -36,7 +43,7 @@ public static class ScopeAllEchoHelper | ||
| 36 | { | 43 | { |
| 37 | partners = new List<string> { AllScopeBindingHelper.ScopeAll }; | 44 | partners = new List<string> { AllScopeBindingHelper.ScopeAll }; |
| 38 | } | 45 | } |
| 39 | - else if (partners.Count > 0) | 46 | + else if (!AllScopeBindingHelper.IsDeclaredSpecified(options.AppliedPartnerType) && partners.Count > 0) |
| 40 | { | 47 | { |
| 41 | var allPartners = await AllScopeBindingHelper.ResolveAllPartnerIdsAsync(db); | 48 | var allPartners = await AllScopeBindingHelper.ResolveAllPartnerIdsAsync(db); |
| 42 | if (allPartners.Count > 0 && AllScopeBindingHelper.IsFullIdSelection(partners, allPartners)) | 49 | if (allPartners.Count > 0 && AllScopeBindingHelper.IsFullIdSelection(partners, allPartners)) |
| @@ -49,7 +56,7 @@ public static class ScopeAllEchoHelper | @@ -49,7 +56,7 @@ public static class ScopeAllEchoHelper | ||
| 49 | { | 56 | { |
| 50 | regions = new List<string> { AllScopeBindingHelper.ScopeAll }; | 57 | regions = new List<string> { AllScopeBindingHelper.ScopeAll }; |
| 51 | } | 58 | } |
| 52 | - else if (regions.Count > 0) | 59 | + else if (!AllScopeBindingHelper.IsDeclaredSpecified(options.AppliedRegionType) && regions.Count > 0) |
| 53 | { | 60 | { |
| 54 | regions = await CollapseRegionsIfFullAsync(db, partners, regions); | 61 | regions = await CollapseRegionsIfFullAsync(db, partners, regions); |
| 55 | } | 62 | } |
| @@ -58,7 +65,7 @@ public static class ScopeAllEchoHelper | @@ -58,7 +65,7 @@ public static class ScopeAllEchoHelper | ||
| 58 | { | 65 | { |
| 59 | locations = new List<string> { AllScopeBindingHelper.ScopeAll }; | 66 | locations = new List<string> { AllScopeBindingHelper.ScopeAll }; |
| 60 | } | 67 | } |
| 61 | - else if (locations.Count > 0) | 68 | + else if (!AllScopeBindingHelper.IsDeclaredSpecified(options.AppliedLocationType) && locations.Count > 0) |
| 62 | { | 69 | { |
| 63 | locations = await CollapseLocationsIfFullAsync(db, partners, regions, locations); | 70 | locations = await CollapseLocationsIfFullAsync(db, partners, regions, locations); |
| 64 | } | 71 | } |
| @@ -79,7 +86,10 @@ public static class ScopeAllEchoHelper | @@ -79,7 +86,10 @@ public static class ScopeAllEchoHelper | ||
| 79 | { | 86 | { |
| 80 | IsPartnerAll = AllScopeBindingHelper.IsDeclaredAll(appliedPartnerType), | 87 | IsPartnerAll = AllScopeBindingHelper.IsDeclaredAll(appliedPartnerType), |
| 81 | IsRegionAll = AllScopeBindingHelper.IsDeclaredAll(appliedRegionType), | 88 | IsRegionAll = AllScopeBindingHelper.IsDeclaredAll(appliedRegionType), |
| 82 | - IsLocationAll = AllScopeBindingHelper.IsDeclaredAll(appliedLocationType) | 89 | + IsLocationAll = AllScopeBindingHelper.IsDeclaredAll(appliedLocationType), |
| 90 | + AppliedPartnerType = appliedPartnerType, | ||
| 91 | + AppliedRegionType = appliedRegionType, | ||
| 92 | + AppliedLocationType = appliedLocationType | ||
| 83 | }; | 93 | }; |
| 84 | 94 | ||
| 85 | /// <summary>标签类型/分类/多选项:Company + Region + Location 可用范围。</summary> | 95 | /// <summary>标签类型/分类/多选项:Company + Region + Location 可用范围。</summary> |
| @@ -91,7 +101,10 @@ public static class ScopeAllEchoHelper | @@ -91,7 +101,10 @@ public static class ScopeAllEchoHelper | ||
| 91 | { | 101 | { |
| 92 | IsPartnerAll = AllScopeBindingHelper.IsDeclaredAll(appliedPartnerType), | 102 | IsPartnerAll = AllScopeBindingHelper.IsDeclaredAll(appliedPartnerType), |
| 93 | IsRegionAll = AllScopeBindingHelper.IsDeclaredAll(appliedRegionType), | 103 | IsRegionAll = AllScopeBindingHelper.IsDeclaredAll(appliedRegionType), |
| 94 | - IsLocationAll = AllScopeBindingHelper.IsDeclaredAll(availabilityType) | 104 | + IsLocationAll = AllScopeBindingHelper.IsDeclaredAll(availabilityType), |
| 105 | + AppliedPartnerType = appliedPartnerType, | ||
| 106 | + AppliedRegionType = appliedRegionType, | ||
| 107 | + AppliedLocationType = availabilityType | ||
| 95 | }; | 108 | }; |
| 96 | 109 | ||
| 97 | /// <summary>兼容旧调用:无 Region 类型时用 AvailabilityType 同时驱动 Region/Location。</summary> | 110 | /// <summary>兼容旧调用:无 Region 类型时用 AvailabilityType 同时驱动 Region/Location。</summary> |
| @@ -106,10 +119,16 @@ public static class ScopeAllEchoHelper | @@ -106,10 +119,16 @@ public static class ScopeAllEchoHelper | ||
| 106 | IReadOnlyList<string> locationIds) | 119 | IReadOnlyList<string> locationIds) |
| 107 | { | 120 | { |
| 108 | var isRegionAll = AllScopeBindingHelper.IsDeclaredAll(appliedRegionType); | 121 | var isRegionAll = AllScopeBindingHelper.IsDeclaredAll(appliedRegionType); |
| 122 | + var normalizedLocations = LocationScopeBindingHelper.NormalizeIds(locationIds); | ||
| 123 | + var isLocationAll = isRegionAll && normalizedLocations.Count == 0; | ||
| 109 | return new ScopeAllEchoOptions | 124 | return new ScopeAllEchoOptions |
| 110 | { | 125 | { |
| 111 | IsRegionAll = isRegionAll, | 126 | IsRegionAll = isRegionAll, |
| 112 | - IsLocationAll = isRegionAll && LocationScopeBindingHelper.NormalizeIds(locationIds).Count == 0 | 127 | + IsLocationAll = isLocationAll, |
| 128 | + AppliedRegionType = appliedRegionType, | ||
| 129 | + AppliedLocationType = isLocationAll | ||
| 130 | + ? AllScopeBindingHelper.ScopeAll | ||
| 131 | + : AllScopeBindingHelper.ScopeSpecified | ||
| 113 | }; | 132 | }; |
| 114 | } | 133 | } |
| 115 | 134 |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/DbModels/FlLabelAlertTimerDbEntity.cs
0 → 100644
| 1 | +using SqlSugar; | ||
| 2 | + | ||
| 3 | +namespace FoodLabeling.Application.Services.DbModels; | ||
| 4 | + | ||
| 5 | +/// <summary> | ||
| 6 | +/// 标签告警计时器(对应表:fl_label_alert_timer) | ||
| 7 | +/// </summary> | ||
| 8 | +[SugarTable("fl_label_alert_timer")] | ||
| 9 | +public class FlLabelAlertTimerDbEntity | ||
| 10 | +{ | ||
| 11 | + [SugarColumn(IsPrimaryKey = true)] | ||
| 12 | + public string Id { get; set; } = string.Empty; | ||
| 13 | + | ||
| 14 | + public string BatchId { get; set; } = string.Empty; | ||
| 15 | + | ||
| 16 | + public string PrintTaskId { get; set; } = string.Empty; | ||
| 17 | + | ||
| 18 | + public string LabelId { get; set; } = string.Empty; | ||
| 19 | + | ||
| 20 | + public string? LabelCode { get; set; } | ||
| 21 | + | ||
| 22 | + public string LabelName { get; set; } = string.Empty; | ||
| 23 | + | ||
| 24 | + public string? ProductId { get; set; } | ||
| 25 | + | ||
| 26 | + public string? ProductName { get; set; } | ||
| 27 | + | ||
| 28 | + public string LocationId { get; set; } = string.Empty; | ||
| 29 | + | ||
| 30 | + public DateTime PrintedAt { get; set; } | ||
| 31 | + | ||
| 32 | + public DateTime? BaseTime { get; set; } | ||
| 33 | + | ||
| 34 | + public DateTime ExpiresAt { get; set; } | ||
| 35 | + | ||
| 36 | + public int DurationSeconds { get; set; } | ||
| 37 | + | ||
| 38 | + public string Title { get; set; } = string.Empty; | ||
| 39 | + | ||
| 40 | + public string Subtitle { get; set; } = string.Empty; | ||
| 41 | + | ||
| 42 | + public bool IsDeleted { get; set; } | ||
| 43 | + | ||
| 44 | + public DateTime? DeletionTime { get; set; } | ||
| 45 | + | ||
| 46 | + public string? CreatedBy { get; set; } | ||
| 47 | + | ||
| 48 | + public DateTime CreationTime { get; set; } | ||
| 49 | +} |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelAlertTimerAppService.cs
0 → 100644
| 1 | +using FoodLabeling.Application.Contracts.Dtos.Common; | ||
| 2 | +using FoodLabeling.Application.Contracts.Dtos.LabelAlertTimer; | ||
| 3 | +using FoodLabeling.Application.Contracts.IServices; | ||
| 4 | +using FoodLabeling.Application.Helpers; | ||
| 5 | +using FoodLabeling.Application.Services.DbModels; | ||
| 6 | +using Microsoft.AspNetCore.Authorization; | ||
| 7 | +using Microsoft.AspNetCore.Mvc; | ||
| 8 | +using SqlSugar; | ||
| 9 | +using Volo.Abp; | ||
| 10 | +using Volo.Abp.Application.Services; | ||
| 11 | +using Yi.Framework.SqlSugarCore.Abstractions; | ||
| 12 | + | ||
| 13 | +namespace FoodLabeling.Application.Services; | ||
| 14 | + | ||
| 15 | +/// <summary> | ||
| 16 | +/// 标签告警计时器(App):按打印批次展示过期倒计时,过期时刻与 Print Log Expiration 同源。 | ||
| 17 | +/// </summary> | ||
| 18 | +public class LabelAlertTimerAppService : ApplicationService, ILabelAlertTimerAppService | ||
| 19 | +{ | ||
| 20 | + private const string StatusRunning = "running"; | ||
| 21 | + private const string StatusExpired = "expired"; | ||
| 22 | + | ||
| 23 | + private readonly ISqlSugarDbContext _dbContext; | ||
| 24 | + | ||
| 25 | + public LabelAlertTimerAppService(ISqlSugarDbContext dbContext) | ||
| 26 | + { | ||
| 27 | + _dbContext = dbContext; | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + /// <summary> | ||
| 31 | + /// 分页查询当前门店告警计时器列表 | ||
| 32 | + /// </summary> | ||
| 33 | + /// <remarks> | ||
| 34 | + /// 过期时刻与 Print Log「Expiration」列同源(<c>ReportsPrintLogExpiryHelper</c>)。 | ||
| 35 | + /// 同一打印批次(<c>BatchId</c>)无论打印多少张标签,仅一条计时器(取 CopyIndex 最小任务)。 | ||
| 36 | + /// | ||
| 37 | + /// 示例请求: | ||
| 38 | + /// ```json | ||
| 39 | + /// { | ||
| 40 | + /// "locationId": "11111111-1111-1111-1111-111111111111", | ||
| 41 | + /// "skipCount": 1, | ||
| 42 | + /// "maxResultCount": 20, | ||
| 43 | + /// "dateDay": "2026-08-07" | ||
| 44 | + /// } | ||
| 45 | + /// ``` | ||
| 46 | + /// | ||
| 47 | + /// 参数说明: | ||
| 48 | + /// - locationId: 当前门店 Id(必填,须已绑定) | ||
| 49 | + /// - skipCount: 页码(从 1 开始) | ||
| 50 | + /// - maxResultCount: 每页条数 | ||
| 51 | + /// - dateDay: 可选,按 PrintedAt 自然日筛选(yyyy-MM-dd) | ||
| 52 | + /// </remarks> | ||
| 53 | + /// <param name="input">分页查询入参</param> | ||
| 54 | + /// <returns>分页计时器列表</returns> | ||
| 55 | + /// <response code="200">成功返回分页列表</response> | ||
| 56 | + /// <response code="400">参数错误或未登录/无门店权限</response> | ||
| 57 | + /// <response code="500">服务器错误</response> | ||
| 58 | + [Authorize] | ||
| 59 | + [HttpPost("label-alert-timer/list")] | ||
| 60 | + public virtual async Task<PagedResultWithPageDto<LabelAlertTimerListItemDto>> GetListAsync( | ||
| 61 | + LabelAlertTimerGetListInputVo input) | ||
| 62 | + { | ||
| 63 | + if (input is null) | ||
| 64 | + { | ||
| 65 | + throw new UserFriendlyException("入参不能为空"); | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + if (!CurrentUser.Id.HasValue) | ||
| 69 | + { | ||
| 70 | + throw new UserFriendlyException("用户未登录"); | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + var locationId = input.LocationId?.Trim(); | ||
| 74 | + if (string.IsNullOrWhiteSpace(locationId)) | ||
| 75 | + { | ||
| 76 | + throw new UserFriendlyException("门店Id不能为空"); | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + await UsAppPrintLogScopeHelper.EnsureUserCanAccessLocationAsync( | ||
| 80 | + CurrentUser, _dbContext.SqlSugarClient, locationId); | ||
| 81 | + | ||
| 82 | + var db = _dbContext.SqlSugarClient; | ||
| 83 | + RefAsync<int> total = 0; | ||
| 84 | + var query = db.Queryable<FlLabelAlertTimerDbEntity>() | ||
| 85 | + .Where(x => !x.IsDeleted && x.LocationId == locationId); | ||
| 86 | + | ||
| 87 | + var (dayStart, dayEndExcl) = ResolveDateDayFilter(input.DateDay); | ||
| 88 | + if (dayStart.HasValue && dayEndExcl.HasValue) | ||
| 89 | + { | ||
| 90 | + var start = dayStart.Value; | ||
| 91 | + var endExcl = dayEndExcl.Value; | ||
| 92 | + query = query.Where(x => x.PrintedAt >= start && x.PrintedAt < endExcl); | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + var pageRows = await query | ||
| 96 | + .OrderBy(x => x.ExpiresAt, OrderByType.Desc) | ||
| 97 | + .OrderBy(x => x.PrintedAt, OrderByType.Desc) | ||
| 98 | + .ToPageListAsync(input.SkipCount, input.MaxResultCount, total); | ||
| 99 | + | ||
| 100 | + var now = DateTime.Now; | ||
| 101 | + var items = pageRows.Select(x => MapListItem(x, now)).ToList(); | ||
| 102 | + | ||
| 103 | + var pageSize = input.MaxResultCount <= 0 ? items.Count : input.MaxResultCount; | ||
| 104 | + var pageIndex = pageSize <= 0 ? 1 : PagedQueryConvention.PageIndexFromSkipCount(input.SkipCount); | ||
| 105 | + var totalCount = (long)total; | ||
| 106 | + var totalPages = pageSize <= 0 ? 0 : (int)Math.Ceiling(totalCount / (double)pageSize); | ||
| 107 | + | ||
| 108 | + return new PagedResultWithPageDto<LabelAlertTimerListItemDto> | ||
| 109 | + { | ||
| 110 | + PageIndex = pageIndex, | ||
| 111 | + PageSize = pageSize, | ||
| 112 | + TotalCount = totalCount, | ||
| 113 | + TotalPages = totalPages, | ||
| 114 | + Items = items | ||
| 115 | + }; | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + /// <summary> | ||
| 119 | + /// 软删除告警计时器 | ||
| 120 | + /// </summary> | ||
| 121 | + /// <remarks> | ||
| 122 | + /// 删除前校验当前用户可访问该计时器所属门店。 | ||
| 123 | + /// </remarks> | ||
| 124 | + /// <param name="id">计时器 Id</param> | ||
| 125 | + /// <response code="200">删除成功</response> | ||
| 126 | + /// <response code="400">记录不存在或无门店权限</response> | ||
| 127 | + /// <response code="500">服务器错误</response> | ||
| 128 | + [Authorize] | ||
| 129 | + [HttpDelete("label-alert-timer/{id}")] | ||
| 130 | + public virtual async Task DeleteAsync(string id) | ||
| 131 | + { | ||
| 132 | + var timerId = id?.Trim(); | ||
| 133 | + if (string.IsNullOrWhiteSpace(timerId)) | ||
| 134 | + { | ||
| 135 | + throw new UserFriendlyException("计时器Id不能为空"); | ||
| 136 | + } | ||
| 137 | + | ||
| 138 | + if (!CurrentUser.Id.HasValue) | ||
| 139 | + { | ||
| 140 | + throw new UserFriendlyException("用户未登录"); | ||
| 141 | + } | ||
| 142 | + | ||
| 143 | + var db = _dbContext.SqlSugarClient; | ||
| 144 | + var row = (await db.Queryable<FlLabelAlertTimerDbEntity>() | ||
| 145 | + .Where(x => x.Id == timerId && !x.IsDeleted) | ||
| 146 | + .Take(1) | ||
| 147 | + .ToListAsync()) | ||
| 148 | + .FirstOrDefault(); | ||
| 149 | + if (row is null) | ||
| 150 | + { | ||
| 151 | + throw new UserFriendlyException("计时器不存在或已删除"); | ||
| 152 | + } | ||
| 153 | + | ||
| 154 | + await UsAppPrintLogScopeHelper.EnsureUserCanAccessLocationAsync( | ||
| 155 | + CurrentUser, db, row.LocationId); | ||
| 156 | + | ||
| 157 | + var now = DateTime.Now; | ||
| 158 | + await db.Updateable<FlLabelAlertTimerDbEntity>() | ||
| 159 | + .SetColumns(x => x.IsDeleted == true) | ||
| 160 | + .SetColumns(x => x.DeletionTime == now) | ||
| 161 | + .Where(x => x.Id == timerId && !x.IsDeleted) | ||
| 162 | + .ExecuteCommandAsync(); | ||
| 163 | + } | ||
| 164 | + | ||
| 165 | + /// <summary> | ||
| 166 | + /// 检查告警计时器是否已过期 | ||
| 167 | + /// </summary> | ||
| 168 | + /// <remarks> | ||
| 169 | + /// 至少提供 <c>timerId</c>、<c>batchId</c>、<c>printTaskId</c> 之一。 | ||
| 170 | + /// 无匹配记录时 <c>found=false</c>、<c>isExpired=false</c>(允许继续打印)。 | ||
| 171 | + /// | ||
| 172 | + /// 示例请求: | ||
| 173 | + /// ```json | ||
| 174 | + /// { | ||
| 175 | + /// "batchId": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" | ||
| 176 | + /// } | ||
| 177 | + /// ``` | ||
| 178 | + /// | ||
| 179 | + /// 参数说明: | ||
| 180 | + /// - timerId: 计时器 Id | ||
| 181 | + /// - batchId: 打印批次 Id | ||
| 182 | + /// - printTaskId: 打印任务 Id(同批次任意任务均可) | ||
| 183 | + /// </remarks> | ||
| 184 | + /// <param name="input">查询入参</param> | ||
| 185 | + /// <returns>过期检查结果</returns> | ||
| 186 | + /// <response code="200">成功(含未找到记录的情况)</response> | ||
| 187 | + /// <response code="400">未提供任何标识</response> | ||
| 188 | + /// <response code="500">服务器错误</response> | ||
| 189 | + [Authorize] | ||
| 190 | + [HttpPost("label-alert-timer/check-expired")] | ||
| 191 | + public virtual async Task<LabelAlertTimerCheckExpiredOutputDto> CheckExpiredAsync( | ||
| 192 | + LabelAlertTimerCheckExpiredInputVo input) | ||
| 193 | + { | ||
| 194 | + if (input is null) | ||
| 195 | + { | ||
| 196 | + throw new UserFriendlyException("入参不能为空"); | ||
| 197 | + } | ||
| 198 | + | ||
| 199 | + var timerId = input.TimerId?.Trim(); | ||
| 200 | + var batchId = input.BatchId?.Trim(); | ||
| 201 | + var printTaskId = input.PrintTaskId?.Trim(); | ||
| 202 | + if (string.IsNullOrWhiteSpace(timerId) && | ||
| 203 | + string.IsNullOrWhiteSpace(batchId) && | ||
| 204 | + string.IsNullOrWhiteSpace(printTaskId)) | ||
| 205 | + { | ||
| 206 | + throw new UserFriendlyException("请至少提供 timerId、batchId 或 printTaskId 之一"); | ||
| 207 | + } | ||
| 208 | + | ||
| 209 | + var db = _dbContext.SqlSugarClient; | ||
| 210 | + FlLabelAlertTimerDbEntity? row = null; | ||
| 211 | + | ||
| 212 | + if (!string.IsNullOrWhiteSpace(timerId)) | ||
| 213 | + { | ||
| 214 | + row = (await db.Queryable<FlLabelAlertTimerDbEntity>() | ||
| 215 | + .Where(x => x.Id == timerId && !x.IsDeleted) | ||
| 216 | + .Take(1) | ||
| 217 | + .ToListAsync()) | ||
| 218 | + .FirstOrDefault(); | ||
| 219 | + } | ||
| 220 | + else if (!string.IsNullOrWhiteSpace(batchId)) | ||
| 221 | + { | ||
| 222 | + row = (await db.Queryable<FlLabelAlertTimerDbEntity>() | ||
| 223 | + .Where(x => x.BatchId == batchId && !x.IsDeleted) | ||
| 224 | + .Take(1) | ||
| 225 | + .ToListAsync()) | ||
| 226 | + .FirstOrDefault(); | ||
| 227 | + } | ||
| 228 | + else if (!string.IsNullOrWhiteSpace(printTaskId)) | ||
| 229 | + { | ||
| 230 | + var task = (await db.Queryable<FlLabelPrintTaskDbEntity>() | ||
| 231 | + .Where(x => x.Id == printTaskId) | ||
| 232 | + .Take(1) | ||
| 233 | + .ToListAsync()) | ||
| 234 | + .FirstOrDefault(); | ||
| 235 | + if (task is not null && !string.IsNullOrWhiteSpace(task.BatchId)) | ||
| 236 | + { | ||
| 237 | + row = (await db.Queryable<FlLabelAlertTimerDbEntity>() | ||
| 238 | + .Where(x => x.BatchId == task.BatchId && !x.IsDeleted) | ||
| 239 | + .Take(1) | ||
| 240 | + .ToListAsync()) | ||
| 241 | + .FirstOrDefault(); | ||
| 242 | + } | ||
| 243 | + } | ||
| 244 | + | ||
| 245 | + if (row is null) | ||
| 246 | + { | ||
| 247 | + return new LabelAlertTimerCheckExpiredOutputDto | ||
| 248 | + { | ||
| 249 | + Found = false, | ||
| 250 | + IsExpired = false, | ||
| 251 | + RemainingSeconds = 0 | ||
| 252 | + }; | ||
| 253 | + } | ||
| 254 | + | ||
| 255 | + if (!CurrentUser.Id.HasValue) | ||
| 256 | + { | ||
| 257 | + throw new UserFriendlyException("用户未登录"); | ||
| 258 | + } | ||
| 259 | + | ||
| 260 | + await UsAppPrintLogScopeHelper.EnsureUserCanAccessLocationAsync( | ||
| 261 | + CurrentUser, db, row.LocationId); | ||
| 262 | + | ||
| 263 | + var now = DateTime.Now; | ||
| 264 | + var remaining = Math.Max(0, (int)(row.ExpiresAt - now).TotalSeconds); | ||
| 265 | + var isExpired = row.ExpiresAt <= now; | ||
| 266 | + | ||
| 267 | + return new LabelAlertTimerCheckExpiredOutputDto | ||
| 268 | + { | ||
| 269 | + Found = true, | ||
| 270 | + IsExpired = isExpired, | ||
| 271 | + ExpiresAt = row.ExpiresAt, | ||
| 272 | + RemainingSeconds = remaining, | ||
| 273 | + Status = isExpired ? StatusExpired : StatusRunning, | ||
| 274 | + Title = row.Title, | ||
| 275 | + Subtitle = row.Subtitle, | ||
| 276 | + TimerId = row.Id, | ||
| 277 | + BatchId = row.BatchId | ||
| 278 | + }; | ||
| 279 | + } | ||
| 280 | + | ||
| 281 | + private static LabelAlertTimerListItemDto MapListItem(FlLabelAlertTimerDbEntity row, DateTime now) | ||
| 282 | + { | ||
| 283 | + var remaining = Math.Max(0, (int)(row.ExpiresAt - now).TotalSeconds); | ||
| 284 | + var isExpired = row.ExpiresAt <= now; | ||
| 285 | + | ||
| 286 | + return new LabelAlertTimerListItemDto | ||
| 287 | + { | ||
| 288 | + Id = row.Id, | ||
| 289 | + BatchId = row.BatchId, | ||
| 290 | + PrintTaskId = row.PrintTaskId, | ||
| 291 | + LabelId = row.LabelId, | ||
| 292 | + LabelCode = row.LabelCode, | ||
| 293 | + Title = row.Title, | ||
| 294 | + Subtitle = row.Subtitle, | ||
| 295 | + TotalTime = row.DurationSeconds, | ||
| 296 | + RemainingTime = remaining, | ||
| 297 | + Status = isExpired ? StatusExpired : StatusRunning, | ||
| 298 | + ExpiresAt = row.ExpiresAt, | ||
| 299 | + PrintedAt = row.PrintedAt, | ||
| 300 | + LocationId = row.LocationId, | ||
| 301 | + ProductName = row.ProductName | ||
| 302 | + }; | ||
| 303 | + } | ||
| 304 | + | ||
| 305 | + private static (DateTime? DayStart, DateTime? DayEndExcl) ResolveDateDayFilter(string? dateDay) | ||
| 306 | + { | ||
| 307 | + if (string.IsNullOrWhiteSpace(dateDay)) | ||
| 308 | + { | ||
| 309 | + return (null, null); | ||
| 310 | + } | ||
| 311 | + | ||
| 312 | + if (DateTime.TryParse(dateDay.Trim(), out var parsedDay)) | ||
| 313 | + { | ||
| 314 | + var day = parsedDay.Date; | ||
| 315 | + return (day, day.AddDays(1)); | ||
| 316 | + } | ||
| 317 | + | ||
| 318 | + return (null, null); | ||
| 319 | + } | ||
| 320 | +} |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelMultipleOptionAppService.cs
| @@ -61,11 +61,11 @@ public class LabelMultipleOptionAppService : ApplicationService, ILabelMultipleO | @@ -61,11 +61,11 @@ public class LabelMultipleOptionAppService : ApplicationService, ILabelMultipleO | ||
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | var entities = await query.ToPageListAsync(input.SkipCount, input.MaxResultCount, total); | 63 | var entities = await query.ToPageListAsync(input.SkipCount, input.MaxResultCount, total); |
| 64 | - var scopeMap = await BuildMultipleOptionScopeMapAsync(entities); | ||
| 65 | var partnerScopeMap = await LabelEntityPartnerScopeHelper.BuildPartnerScopeDisplayMapAsync( | 64 | var partnerScopeMap = await LabelEntityPartnerScopeHelper.BuildPartnerScopeDisplayMapAsync( |
| 66 | _dbContext.SqlSugarClient, | 65 | _dbContext.SqlSugarClient, |
| 67 | LabelEntityPartnerScopeHelper.LabelEntityPartnerKind.MultipleOption, | 66 | LabelEntityPartnerScopeHelper.LabelEntityPartnerKind.MultipleOption, |
| 68 | entities.Select(x => x.Id).ToList()); | 67 | entities.Select(x => x.Id).ToList()); |
| 68 | + var scopeMap = await BuildMultipleOptionScopeMapAsync(entities, partnerScopeMap); | ||
| 69 | 69 | ||
| 70 | var items = entities.Select(x => | 70 | var items = entities.Select(x => |
| 71 | { | 71 | { |
| @@ -478,7 +478,8 @@ public class LabelMultipleOptionAppService : ApplicationService, ILabelMultipleO | @@ -478,7 +478,8 @@ public class LabelMultipleOptionAppService : ApplicationService, ILabelMultipleO | ||
| 478 | } | 478 | } |
| 479 | 479 | ||
| 480 | private async Task<Dictionary<string, MultipleOptionScopeData>> BuildMultipleOptionScopeMapAsync( | 480 | private async Task<Dictionary<string, MultipleOptionScopeData>> BuildMultipleOptionScopeMapAsync( |
| 481 | - List<FlLabelMultipleOptionDbEntity> entities) | 481 | + List<FlLabelMultipleOptionDbEntity> entities, |
| 482 | + Dictionary<string, LabelEntityPartnerScopeHelper.LabelEntityPartnerScopeDisplay> partnerScopeMap) | ||
| 482 | { | 483 | { |
| 483 | var result = new Dictionary<string, MultipleOptionScopeData>(StringComparer.Ordinal); | 484 | var result = new Dictionary<string, MultipleOptionScopeData>(StringComparer.Ordinal); |
| 484 | if (entities.Count == 0) | 485 | if (entities.Count == 0) |
| @@ -486,6 +487,8 @@ public class LabelMultipleOptionAppService : ApplicationService, ILabelMultipleO | @@ -486,6 +487,8 @@ public class LabelMultipleOptionAppService : ApplicationService, ILabelMultipleO | ||
| 486 | return result; | 487 | return result; |
| 487 | } | 488 | } |
| 488 | 489 | ||
| 490 | + var entityById = entities.ToDictionary(x => x.Id, StringComparer.Ordinal); | ||
| 491 | + | ||
| 489 | foreach (var e in entities.Where(x => | 492 | foreach (var e in entities.Where(x => |
| 490 | !string.Equals(x.AvailabilityType, "SPECIFIED", StringComparison.OrdinalIgnoreCase))) | 493 | !string.Equals(x.AvailabilityType, "SPECIFIED", StringComparison.OrdinalIgnoreCase))) |
| 491 | { | 494 | { |
| @@ -581,10 +584,28 @@ public class LabelMultipleOptionAppService : ApplicationService, ILabelMultipleO | @@ -581,10 +584,28 @@ public class LabelMultipleOptionAppService : ApplicationService, ILabelMultipleO | ||
| 581 | 584 | ||
| 582 | var regionIds = await LocationScopeBindingHelper.ResolveGroupIdsFromLocationIdsAsync( | 585 | var regionIds = await LocationScopeBindingHelper.ResolveGroupIdsFromLocationIdsAsync( |
| 583 | _dbContext.SqlSugarClient, locationIds); | 586 | _dbContext.SqlSugarClient, locationIds); |
| 584 | - var partnerIds = await LocationScopeBindingHelper.ResolvePartnerIdsFromLocationIdsAsync( | ||
| 585 | - _dbContext.SqlSugarClient, locationIds); | 587 | + |
| 588 | + entityById.TryGetValue(optionId, out var entity); | ||
| 589 | + partnerScopeMap.TryGetValue(optionId, out var partnerScope); | ||
| 590 | + var partnerContext = entity is not null | ||
| 591 | + && string.Equals( | ||
| 592 | + entity.AppliedPartnerType, | ||
| 593 | + LabelEntityPartnerScopeHelper.ScopeSpecified, | ||
| 594 | + StringComparison.OrdinalIgnoreCase) | ||
| 595 | + ? partnerScope?.PartnerIds | ||
| 596 | + : null; | ||
| 597 | + | ||
| 586 | var collapsed = await ScopeAllEchoHelper.CollapseScopeIdsToAllSentinelAsync( | 598 | var collapsed = await ScopeAllEchoHelper.CollapseScopeIdsToAllSentinelAsync( |
| 587 | - _dbContext.SqlSugarClient, partnerIds, regionIds, locationIds); | 599 | + _dbContext.SqlSugarClient, |
| 600 | + partnerContext, | ||
| 601 | + regionIds, | ||
| 602 | + locationIds, | ||
| 603 | + entity is not null | ||
| 604 | + ? ScopeAllEchoHelper.ForLabelEntityScope( | ||
| 605 | + entity.AppliedPartnerType, | ||
| 606 | + entity.AppliedRegionType, | ||
| 607 | + entity.AvailabilityType) | ||
| 608 | + : null); | ||
| 588 | 609 | ||
| 589 | result[optionId] = new MultipleOptionScopeData | 610 | result[optionId] = new MultipleOptionScopeData |
| 590 | { | 611 | { |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelTypeAppService.cs
| @@ -63,11 +63,11 @@ public class LabelTypeAppService : ApplicationService, ILabelTypeAppService | @@ -63,11 +63,11 @@ public class LabelTypeAppService : ApplicationService, ILabelTypeAppService | ||
| 63 | var ids = entities.Select(x => x.Id).ToList(); | 63 | var ids = entities.Select(x => x.Id).ToList(); |
| 64 | 64 | ||
| 65 | var countMap = await BuildTypeLabelStatsMapAsync(ids, scopedLocationIds); | 65 | var countMap = await BuildTypeLabelStatsMapAsync(ids, scopedLocationIds); |
| 66 | - var scopeMap = await BuildTypeConfiguredScopeMapAsync(entities); | ||
| 67 | var partnerScopeMap = await LabelEntityPartnerScopeHelper.BuildPartnerScopeDisplayMapAsync( | 66 | var partnerScopeMap = await LabelEntityPartnerScopeHelper.BuildPartnerScopeDisplayMapAsync( |
| 68 | _dbContext.SqlSugarClient, | 67 | _dbContext.SqlSugarClient, |
| 69 | LabelEntityPartnerScopeHelper.LabelEntityPartnerKind.Type, | 68 | LabelEntityPartnerScopeHelper.LabelEntityPartnerKind.Type, |
| 70 | ids); | 69 | ids); |
| 70 | + var scopeMap = await BuildTypeConfiguredScopeMapAsync(entities, partnerScopeMap); | ||
| 71 | 71 | ||
| 72 | var items = entities.Select(x => | 72 | var items = entities.Select(x => |
| 73 | { | 73 | { |
| @@ -487,7 +487,8 @@ public class LabelTypeAppService : ApplicationService, ILabelTypeAppService | @@ -487,7 +487,8 @@ public class LabelTypeAppService : ApplicationService, ILabelTypeAppService | ||
| 487 | } | 487 | } |
| 488 | 488 | ||
| 489 | private async Task<Dictionary<string, TypeScopeData>> BuildTypeConfiguredScopeMapAsync( | 489 | private async Task<Dictionary<string, TypeScopeData>> BuildTypeConfiguredScopeMapAsync( |
| 490 | - List<FlLabelTypeDbEntity> entities) | 490 | + List<FlLabelTypeDbEntity> entities, |
| 491 | + Dictionary<string, LabelEntityPartnerScopeHelper.LabelEntityPartnerScopeDisplay> partnerScopeMap) | ||
| 491 | { | 492 | { |
| 492 | var result = new Dictionary<string, TypeScopeData>(StringComparer.Ordinal); | 493 | var result = new Dictionary<string, TypeScopeData>(StringComparer.Ordinal); |
| 493 | if (entities.Count == 0) | 494 | if (entities.Count == 0) |
| @@ -495,6 +496,8 @@ public class LabelTypeAppService : ApplicationService, ILabelTypeAppService | @@ -495,6 +496,8 @@ public class LabelTypeAppService : ApplicationService, ILabelTypeAppService | ||
| 495 | return result; | 496 | return result; |
| 496 | } | 497 | } |
| 497 | 498 | ||
| 499 | + var entityById = entities.ToDictionary(x => x.Id, StringComparer.Ordinal); | ||
| 500 | + | ||
| 498 | foreach (var e in entities.Where(x => | 501 | foreach (var e in entities.Where(x => |
| 499 | !string.Equals(x.AvailabilityType, "SPECIFIED", StringComparison.OrdinalIgnoreCase))) | 502 | !string.Equals(x.AvailabilityType, "SPECIFIED", StringComparison.OrdinalIgnoreCase))) |
| 500 | { | 503 | { |
| @@ -590,10 +593,28 @@ public class LabelTypeAppService : ApplicationService, ILabelTypeAppService | @@ -590,10 +593,28 @@ public class LabelTypeAppService : ApplicationService, ILabelTypeAppService | ||
| 590 | 593 | ||
| 591 | var regionIds = await LocationScopeBindingHelper.ResolveGroupIdsFromLocationIdsAsync( | 594 | var regionIds = await LocationScopeBindingHelper.ResolveGroupIdsFromLocationIdsAsync( |
| 592 | _dbContext.SqlSugarClient, locationIds); | 595 | _dbContext.SqlSugarClient, locationIds); |
| 593 | - var partnerIds = await LocationScopeBindingHelper.ResolvePartnerIdsFromLocationIdsAsync( | ||
| 594 | - _dbContext.SqlSugarClient, locationIds); | 596 | + |
| 597 | + entityById.TryGetValue(typeId, out var entity); | ||
| 598 | + partnerScopeMap.TryGetValue(typeId, out var partnerScope); | ||
| 599 | + var partnerContext = entity is not null | ||
| 600 | + && string.Equals( | ||
| 601 | + entity.AppliedPartnerType, | ||
| 602 | + LabelEntityPartnerScopeHelper.ScopeSpecified, | ||
| 603 | + StringComparison.OrdinalIgnoreCase) | ||
| 604 | + ? partnerScope?.PartnerIds | ||
| 605 | + : null; | ||
| 606 | + | ||
| 595 | var collapsed = await ScopeAllEchoHelper.CollapseScopeIdsToAllSentinelAsync( | 607 | var collapsed = await ScopeAllEchoHelper.CollapseScopeIdsToAllSentinelAsync( |
| 596 | - _dbContext.SqlSugarClient, partnerIds, regionIds, locationIds); | 608 | + _dbContext.SqlSugarClient, |
| 609 | + partnerContext, | ||
| 610 | + regionIds, | ||
| 611 | + locationIds, | ||
| 612 | + entity is not null | ||
| 613 | + ? ScopeAllEchoHelper.ForLabelEntityScope( | ||
| 614 | + entity.AppliedPartnerType, | ||
| 615 | + entity.AppliedRegionType, | ||
| 616 | + entity.AvailabilityType) | ||
| 617 | + : null); | ||
| 597 | 618 | ||
| 598 | result[typeId] = new TypeScopeData | 619 | result[typeId] = new TypeScopeData |
| 599 | { | 620 | { |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/scripts/fl_label_alert_timer.sql
0 → 100644
| 1 | +-- 标签告警计时器:按打印批次(BatchId)一条,过期时刻与 Print Log Expiration 同源解析 | ||
| 2 | +-- 执行前请备份;可重复执行 | ||
| 3 | + | ||
| 4 | +SET @db := DATABASE(); | ||
| 5 | + | ||
| 6 | +CREATE TABLE IF NOT EXISTS `fl_label_alert_timer` ( | ||
| 7 | + `Id` varchar(36) NOT NULL COMMENT '主键', | ||
| 8 | + `BatchId` varchar(36) NOT NULL COMMENT '打印批次Id(fl_label_print_task.BatchId,唯一)', | ||
| 9 | + `PrintTaskId` varchar(36) NOT NULL COMMENT '代表任务Id(CopyIndex 最小)', | ||
| 10 | + `LabelId` varchar(36) NOT NULL COMMENT '标签Id', | ||
| 11 | + `LabelCode` varchar(100) DEFAULT NULL COMMENT '标签编码', | ||
| 12 | + `LabelName` varchar(200) NOT NULL COMMENT '标签名称', | ||
| 13 | + `ProductId` varchar(36) DEFAULT NULL COMMENT '产品Id', | ||
| 14 | + `ProductName` varchar(500) DEFAULT NULL COMMENT '产品名称', | ||
| 15 | + `LocationId` varchar(36) NOT NULL COMMENT '门店Id', | ||
| 16 | + `PrintedAt` datetime NOT NULL COMMENT '打印时刻(PrintedAt ?? BaseTime ?? CreationTime)', | ||
| 17 | + `BaseTime` datetime DEFAULT NULL COMMENT '基准时间', | ||
| 18 | + `ExpiresAt` datetime NOT NULL COMMENT '过期时刻', | ||
| 19 | + `DurationSeconds` int NOT NULL DEFAULT 0 COMMENT '总时长(秒)', | ||
| 20 | + `Title` varchar(500) NOT NULL COMMENT '标题', | ||
| 21 | + `Subtitle` varchar(500) NOT NULL COMMENT '副标题', | ||
| 22 | + `IsDeleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '软删', | ||
| 23 | + `DeletionTime` datetime DEFAULT NULL COMMENT '删除时间', | ||
| 24 | + `CreatedBy` varchar(36) DEFAULT NULL COMMENT '创建者', | ||
| 25 | + `CreationTime` datetime NOT NULL COMMENT '创建时间', | ||
| 26 | + PRIMARY KEY (`Id`), | ||
| 27 | + UNIQUE KEY `uk_fl_label_alert_timer_batch` (`BatchId`), | ||
| 28 | + KEY `idx_fl_label_alert_timer_location` (`LocationId`), | ||
| 29 | + KEY `idx_fl_label_alert_timer_expires` (`ExpiresAt`), | ||
| 30 | + KEY `idx_fl_label_alert_timer_printed` (`PrintedAt`) | ||
| 31 | +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='标签告警计时器'; |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling/FoodLabeling.Th.Application/MultiTenancy/ThLoginTenantResolver.cs
0 → 100644
| 1 | +using Microsoft.Extensions.Logging; | ||
| 2 | +using Yi.Framework.SqlSugarCore.Abstractions; | ||
| 3 | + | ||
| 4 | +namespace FoodLabeling.Th.Application.MultiTenancy; | ||
| 5 | + | ||
| 6 | +/// <summary> | ||
| 7 | +/// 泰额 Web / App 登录共用:未选公司时按开通邮箱或租户业务库 user 反查公司租户。 | ||
| 8 | +/// </summary> | ||
| 9 | +internal static class ThLoginTenantResolver | ||
| 10 | +{ | ||
| 11 | + /// <summary> | ||
| 12 | + /// 未选公司时:先查开通管理员凭据,再扫描各租户业务库 user(Team Member 等)。 | ||
| 13 | + /// </summary> | ||
| 14 | + internal static async Task<Guid?> TryResolveCompanyTenantIdByLoginAsync( | ||
| 15 | + DbConnOptions dbConnOptions, | ||
| 16 | + string? loginAccount, | ||
| 17 | + ILogger? logger = null) | ||
| 18 | + { | ||
| 19 | + if (string.IsNullOrWhiteSpace(loginAccount)) | ||
| 20 | + { | ||
| 21 | + return null; | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + try | ||
| 25 | + { | ||
| 26 | + if (ThWebPlatformLoginHelper.IsPlausiblePlatformEmail(loginAccount)) | ||
| 27 | + { | ||
| 28 | + var fromCredential = await ThTenantHostDataAccessor.FindActiveTenantIdByLoginAccountAsync( | ||
| 29 | + dbConnOptions, | ||
| 30 | + loginAccount); | ||
| 31 | + if (fromCredential.HasValue) | ||
| 32 | + { | ||
| 33 | + return fromCredential; | ||
| 34 | + } | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + return await ThTenantHostDataAccessor.FindActiveTenantIdByBusinessUserLoginAsync( | ||
| 38 | + dbConnOptions, | ||
| 39 | + loginAccount); | ||
| 40 | + } | ||
| 41 | + catch (Exception ex) | ||
| 42 | + { | ||
| 43 | + logger?.LogError(ex, "按登录账号反查公司租户失败:{UserName}", loginAccount); | ||
| 44 | + return null; | ||
| 45 | + } | ||
| 46 | + } | ||
| 47 | +} |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling/FoodLabeling.Th.Application/Services/ThUsAppAuthAppService.cs
0 → 100644
| 1 | +using FoodLabeling.Application.Contracts; | ||
| 2 | +using FoodLabeling.Application.Contracts.Dtos.UsAppAuth; | ||
| 3 | +using FoodLabeling.Application.Contracts.IServices; | ||
| 4 | +using FoodLabeling.Application.Services; | ||
| 5 | +using FoodLabeling.Th.Application.Contracts.Dtos.Auth; | ||
| 6 | +using FoodLabeling.Th.Application.Contracts.IServices; | ||
| 7 | +using Lazy.Captcha.Core; | ||
| 8 | +using Microsoft.AspNetCore.Http; | ||
| 9 | +using Microsoft.Extensions.Caching.Distributed; | ||
| 10 | +using Microsoft.Extensions.Options; | ||
| 11 | +using Volo.Abp.DependencyInjection; | ||
| 12 | +using Yi.Framework.Rbac.Application.Contracts.IServices; | ||
| 13 | +using Yi.Framework.Rbac.Domain.Entities; | ||
| 14 | +using Yi.Framework.Rbac.Domain.Managers; | ||
| 15 | +using Yi.Framework.Rbac.Domain.Shared.Options; | ||
| 16 | +using Yi.Framework.SqlSugarCore.Abstractions; | ||
| 17 | + | ||
| 18 | +namespace FoodLabeling.Th.Application.Services; | ||
| 19 | + | ||
| 20 | +/// <summary> | ||
| 21 | +/// 泰额多租户:兼容 App 仍调用 <c>us-app-auth/login</c>,内部按邮箱反查公司并走租户库登录。 | ||
| 22 | +/// </summary> | ||
| 23 | +[Dependency(ReplaceServices = true)] | ||
| 24 | +[ExposeServices(typeof(IUsAppAuthAppService), typeof(UsAppAuthAppService))] | ||
| 25 | +public class ThUsAppAuthAppService : UsAppAuthAppService | ||
| 26 | +{ | ||
| 27 | + private readonly IThAppAuthAppService _thAppAuth; | ||
| 28 | + private readonly DbConnOptions _saasDbConnOptions; | ||
| 29 | + | ||
| 30 | + public ThUsAppAuthAppService( | ||
| 31 | + IAccountManager accountManager, | ||
| 32 | + ISqlSugarRepository<UserAggregateRoot, Guid> userRepository, | ||
| 33 | + ISqlSugarDbContext dbContext, | ||
| 34 | + IHttpContextAccessor httpContextAccessor, | ||
| 35 | + ICaptcha captcha, | ||
| 36 | + IOptions<JwtOptions> jwtOptions, | ||
| 37 | + IOptions<RbacOptions> rbacOptions, | ||
| 38 | + IForgotPasswordByEmailService forgotPasswordByEmailService, | ||
| 39 | + IDistributedCache distributedCache, | ||
| 40 | + IOptions<DbConnOptions> dbConnOptions, | ||
| 41 | + IThAppAuthAppService thAppAuth) | ||
| 42 | + : base( | ||
| 43 | + accountManager, | ||
| 44 | + userRepository, | ||
| 45 | + dbContext, | ||
| 46 | + httpContextAccessor, | ||
| 47 | + captcha, | ||
| 48 | + jwtOptions, | ||
| 49 | + rbacOptions, | ||
| 50 | + forgotPasswordByEmailService, | ||
| 51 | + distributedCache, | ||
| 52 | + dbConnOptions) | ||
| 53 | + { | ||
| 54 | + _thAppAuth = thAppAuth; | ||
| 55 | + _saasDbConnOptions = dbConnOptions.Value; | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + /// <inheritdoc /> | ||
| 59 | + /// <remarks> | ||
| 60 | + /// SaaS 开启时转发至 <c>th-app-auth/login</c> 同等逻辑(邮箱反查租户 + JWT 含 TenantId), | ||
| 61 | + /// 出参仍为 <see cref="UsAppLoginOutputDto"/>,前端路径可不变。 | ||
| 62 | + /// </remarks> | ||
| 63 | + public override async Task<UsAppLoginOutputDto> LoginAsync(UsAppLoginInputVo input) | ||
| 64 | + { | ||
| 65 | + if (!_saasDbConnOptions.EnabledSaasMultiTenancy) | ||
| 66 | + { | ||
| 67 | + return await base.LoginAsync(input); | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + var thResult = await _thAppAuth.LoginAsync(new ThAppLoginInputVo | ||
| 71 | + { | ||
| 72 | + Email = input.Email, | ||
| 73 | + Password = input.Password, | ||
| 74 | + Uuid = input.Uuid, | ||
| 75 | + Code = input.Code | ||
| 76 | + }); | ||
| 77 | + | ||
| 78 | + return new UsAppLoginOutputDto | ||
| 79 | + { | ||
| 80 | + Token = thResult.Token, | ||
| 81 | + RefreshToken = thResult.RefreshToken, | ||
| 82 | + Locations = thResult.Locations | ||
| 83 | + }; | ||
| 84 | + } | ||
| 85 | +} |
项目相关文档/2026-08-07告警接口文档.md
0 → 100644
| 1 | +# 告警计时器接口文档(泰额版) | ||
| 2 | + | ||
| 3 | +> 模块:标签告警计时器(Label Alert Timer) | ||
| 4 | +> 范围:泰额版后端(租户业务库,非 `antis-foodlabeling-host`) | ||
| 5 | +> 认证:`Authorization: Bearer {token}`;业务请求建议带 `__tenant: {tenantId}` | ||
| 6 | +> JSON:camelCase | ||
| 7 | +> Base URL 示例:`http://127.0.0.1:19002`(以实际部署为准) | ||
| 8 | +> 更新日期:2026-08-07 | ||
| 9 | + | ||
| 10 | +--- | ||
| 11 | + | ||
| 12 | +## 1. 业务说明 | ||
| 13 | + | ||
| 14 | +| 概念 | 说明 | | ||
| 15 | +|------|------| | ||
| 16 | +| 过期时刻 | 与 Print Log「Expiration」列**同源**,由 `ReportsPrintLogExpiryHelper.TryResolveExpiryDateTime` 解析 | | ||
| 17 | +| 批次维度 | 一次打印(同一 `BatchId`)无论打印多少张,**仅一条**计时器(取 `CopyIndex` 最小的 `fl_label_print_task`) | | ||
| 18 | +| 无过期不上列表 | 模板无法解析过期时刻时,不写入计时器、不出现在列表 | | ||
| 19 | +| 状态 | `running`(未过期)/ `expired`(已过期) | | ||
| 20 | +| 软删 | 用户可删除计时器;删除后不再出现在列表 | | ||
| 21 | + | ||
| 22 | +### 写入时机 | ||
| 23 | + | ||
| 24 | +- `UsAppLabelingAppService.PrintAsync` / `ReprintAsync` 成功创建批次后自动写入 | ||
| 25 | +- 幂等重试(相同 `clientRequestId`)返回前也会补写一次(Helper 内部按 `BatchId` 去重) | ||
| 26 | + | ||
| 27 | +### 建表 | ||
| 28 | + | ||
| 29 | +- 脚本:`module/food-labeling-us/scripts/fl_label_alert_timer.sql` | ||
| 30 | +- 表名:`fl_label_alert_timer` | ||
| 31 | +- 新租户开通时嵌入资源自动执行;**已有租户需用具备 CREATE 权限的账号**在业务库手动执行脚本(业务账号 `netteam` 通常无建表权限,可用运维高权限账号执行) | ||
| 32 | + | ||
| 33 | +--- | ||
| 34 | + | ||
| 35 | +## 2. 接口一览 | ||
| 36 | + | ||
| 37 | +| 功能 | 方法 | 路由 | | ||
| 38 | +|------|------|------| | ||
| 39 | +| 分页列表 | POST | `/api/app/label-alert-timer/list` | | ||
| 40 | +| 软删除 | DELETE | `/api/app/label-alert-timer/{id}` | | ||
| 41 | +| 检查是否过期 | POST | `/api/app/label-alert-timer/check-expired` | | ||
| 42 | + | ||
| 43 | +> 所有接口需登录;列表与删除需已绑定 `locationId` 对应门店。 | ||
| 44 | + | ||
| 45 | +--- | ||
| 46 | + | ||
| 47 | +## 3. 分页列表 | ||
| 48 | + | ||
| 49 | +**POST** `/api/app/label-alert-timer/list` | ||
| 50 | + | ||
| 51 | +### 请求 | ||
| 52 | + | ||
| 53 | +```json | ||
| 54 | +{ | ||
| 55 | + "locationId": "3a21220f-db37-3e32-7390-d55f64cd62a8", | ||
| 56 | + "skipCount": 1, | ||
| 57 | + "maxResultCount": 20, | ||
| 58 | + "dateDay": "2026-08-07" | ||
| 59 | +} | ||
| 60 | +``` | ||
| 61 | + | ||
| 62 | +| 字段 | 必填 | 说明 | | ||
| 63 | +|------|------|------| | ||
| 64 | +| locationId | 是 | 当前门店 Id | | ||
| 65 | +| skipCount | 是 | 页码(从 1 开始) | | ||
| 66 | +| maxResultCount | 是 | 每页条数 | | ||
| 67 | +| dateDay | 否 | `yyyy-MM-dd`,按 PrintedAt 自然日筛选 | | ||
| 68 | + | ||
| 69 | +### 响应示例 | ||
| 70 | + | ||
| 71 | +```json | ||
| 72 | +{ | ||
| 73 | + "pageIndex": 1, | ||
| 74 | + "pageSize": 20, | ||
| 75 | + "totalCount": 1, | ||
| 76 | + "totalPages": 1, | ||
| 77 | + "items": [ | ||
| 78 | + { | ||
| 79 | + "id": "1987654321000123456", | ||
| 80 | + "batchId": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", | ||
| 81 | + "printTaskId": "bbbbbbbb-cccc-dddd-eeee-ffffffffffff", | ||
| 82 | + "labelId": "label-id-001", | ||
| 83 | + "labelCode": "LB_001", | ||
| 84 | + "title": "Chicken Prep (4 hours)", | ||
| 85 | + "subtitle": "4 hours Completes at 2:30 PM", | ||
| 86 | + "totalTime": 14400, | ||
| 87 | + "remainingTime": 7200, | ||
| 88 | + "status": "running", | ||
| 89 | + "expiresAt": "2026-08-07T14:30:00", | ||
| 90 | + "printedAt": "2026-08-07T10:30:00", | ||
| 91 | + "locationId": "3a21220f-db37-3e32-7390-d55f64cd62a8", | ||
| 92 | + "productName": "Grilled Chicken" | ||
| 93 | + } | ||
| 94 | + ] | ||
| 95 | +} | ||
| 96 | +``` | ||
| 97 | + | ||
| 98 | +| 出参字段 | 说明 | | ||
| 99 | +|----------|------| | ||
| 100 | +| totalTime | 总时长(秒),等于库中 DurationSeconds | | ||
| 101 | +| remainingTime | 剩余秒数,`max(0, ExpiresAt - now)` | | ||
| 102 | +| status | `running` 或 `expired` | | ||
| 103 | + | ||
| 104 | +--- | ||
| 105 | + | ||
| 106 | +## 4. 软删除 | ||
| 107 | + | ||
| 108 | +**DELETE** `/api/app/label-alert-timer/{id}` | ||
| 109 | + | ||
| 110 | +- 校验当前用户可访问该计时器所属门店 | ||
| 111 | +- 设置 `IsDeleted=1`、`DeletionTime=now` | ||
| 112 | + | ||
| 113 | +--- | ||
| 114 | + | ||
| 115 | +## 5. 检查是否过期 | ||
| 116 | + | ||
| 117 | +**POST** `/api/app/label-alert-timer/check-expired` | ||
| 118 | + | ||
| 119 | +### 请求 | ||
| 120 | + | ||
| 121 | +至少提供 `timerId`、`batchId`、`printTaskId` 之一: | ||
| 122 | + | ||
| 123 | +```json | ||
| 124 | +{ | ||
| 125 | + "batchId": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" | ||
| 126 | +} | ||
| 127 | +``` | ||
| 128 | + | ||
| 129 | +### 响应(找到记录) | ||
| 130 | + | ||
| 131 | +```json | ||
| 132 | +{ | ||
| 133 | + "found": true, | ||
| 134 | + "isExpired": false, | ||
| 135 | + "expiresAt": "2026-08-07T14:30:00", | ||
| 136 | + "remainingSeconds": 7200, | ||
| 137 | + "status": "running", | ||
| 138 | + "title": "Chicken Prep (4 hours)", | ||
| 139 | + "subtitle": "4 hours Completes at 2:30 PM", | ||
| 140 | + "timerId": "1987654321000123456", | ||
| 141 | + "batchId": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" | ||
| 142 | +} | ||
| 143 | +``` | ||
| 144 | + | ||
| 145 | +### 响应(无记录) | ||
| 146 | + | ||
| 147 | +```json | ||
| 148 | +{ | ||
| 149 | + "found": false, | ||
| 150 | + "isExpired": false, | ||
| 151 | + "remainingSeconds": 0 | ||
| 152 | +} | ||
| 153 | +``` | ||
| 154 | + | ||
| 155 | +> **对接建议**:`found=false` 时视为无告警限制,**允许继续打印**;`found=true && isExpired=true` 时可提示用户标签已过期。 | ||
| 156 | + | ||
| 157 | +--- | ||
| 158 | + | ||
| 159 | +## 6. curl 示例 | ||
| 160 | + | ||
| 161 | +```bash | ||
| 162 | +# 获取 Token 后替换 TOKEN、TENANT、LOCATION_ID | ||
| 163 | + | ||
| 164 | +curl -s -X POST "http://127.0.0.1:19002/api/app/label-alert-timer/list" \ | ||
| 165 | + -H "Authorization: Bearer TOKEN" \ | ||
| 166 | + -H "__tenant: TENANT" \ | ||
| 167 | + -H "Content-Type: application/json" \ | ||
| 168 | + -d '{"locationId":"LOCATION_ID","skipCount":1,"maxResultCount":20}' | ||
| 169 | + | ||
| 170 | +curl -s -X POST "http://127.0.0.1:19002/api/app/label-alert-timer/check-expired" \ | ||
| 171 | + -H "Authorization: Bearer TOKEN" \ | ||
| 172 | + -H "__tenant: TENANT" \ | ||
| 173 | + -H "Content-Type: application/json" \ | ||
| 174 | + -d '{"batchId":"YOUR_BATCH_ID"}' | ||
| 175 | + | ||
| 176 | +curl -s -X DELETE "http://127.0.0.1:19002/api/app/label-alert-timer/TIMER_ID" \ | ||
| 177 | + -H "Authorization: Bearer TOKEN" \ | ||
| 178 | + -H "__tenant: TENANT" | ||
| 179 | +``` | ||
| 180 | + | ||
| 181 | +--- | ||
| 182 | + | ||
| 183 | +## 7. 前端对接建议 | ||
| 184 | + | ||
| 185 | +1. **列表页**:进入门店后拉取列表,用 `remainingTime` 做倒计时;`status=expired` 可高亮或置顶。 | ||
| 186 | +2. **打印前校验**(可选):重打历史批次时调 `check-expired`,`isExpired=true` 时二次确认。 | ||
| 187 | +3. **与 Print Log 一致**:展示过期时间时请与 Print Log Expiration 列对齐,避免两套算法。 | ||
| 188 | +4. **删除**:用户左滑/长按删除时调 DELETE;删除仅隐藏计时器,不影响历史打印任务。 |