diff --git a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/Common/ITrainingFileScopeInput.cs b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/Common/ITrainingFileScopeInput.cs new file mode 100644 index 0000000..3e252a2 --- /dev/null +++ b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/Common/ITrainingFileScopeInput.cs @@ -0,0 +1,25 @@ +namespace FoodLabeling.Application.Contracts.Dtos.Common; + +/// +/// 培训文件创建/编辑入参中的 Company / Region / Location 适用范围字段。 +/// +public interface ITrainingFileScopeInput : ILabelEntityPartnerScopeInput +{ + /// 适用 Region:ALL / SPECIFIED + string? AppliedRegionType { get; } + + /// 适用 Region(fl_group.Id);与 合并;可含 ALL + List? RegionIds { get; } + + /// 与 相同;可含 ALL + List? GroupIds { get; } + + /// 适用 Location:ALL / SPECIFIED(与 二选一) + string? AvailabilityType { get; } + + /// 适用 Location:ALL / SPECIFIED( 别名) + string? AppliedLocationType { get; } + + /// 适用门店(location.Id);可含 ALL + List? LocationIds { get; } +} diff --git a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelAlertTimer/LabelAlertTimerCheckExpiredInputVo.cs b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelAlertTimer/LabelAlertTimerCheckExpiredInputVo.cs new file mode 100644 index 0000000..a8fdf22 --- /dev/null +++ b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelAlertTimer/LabelAlertTimerCheckExpiredInputVo.cs @@ -0,0 +1,13 @@ +namespace FoodLabeling.Application.Contracts.Dtos.LabelAlertTimer; + +/// +/// 检查告警计时器是否过期入参(至少提供一个标识) +/// +public class LabelAlertTimerCheckExpiredInputVo +{ + public string? TimerId { get; set; } + + public string? BatchId { get; set; } + + public string? PrintTaskId { get; set; } +} diff --git a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelAlertTimer/LabelAlertTimerCheckExpiredOutputDto.cs b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelAlertTimer/LabelAlertTimerCheckExpiredOutputDto.cs new file mode 100644 index 0000000..7496e71 --- /dev/null +++ b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelAlertTimer/LabelAlertTimerCheckExpiredOutputDto.cs @@ -0,0 +1,29 @@ +namespace FoodLabeling.Application.Contracts.Dtos.LabelAlertTimer; + +/// +/// 检查告警计时器是否过期出参 +/// +public class LabelAlertTimerCheckExpiredOutputDto +{ + /// 是否找到计时器记录 + public bool Found { get; set; } + + /// 是否已过期;无记录时为 false(允许继续打印) + public bool IsExpired { get; set; } + + public DateTime? ExpiresAt { get; set; } + + /// 剩余秒数(已过期为 0) + public int RemainingSeconds { get; set; } + + /// 状态:expired 或 running + public string? Status { get; set; } + + public string? Title { get; set; } + + public string? Subtitle { get; set; } + + public string? TimerId { get; set; } + + public string? BatchId { get; set; } +} diff --git a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelAlertTimer/LabelAlertTimerGetListInputVo.cs b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelAlertTimer/LabelAlertTimerGetListInputVo.cs new file mode 100644 index 0000000..c874a62 --- /dev/null +++ b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelAlertTimer/LabelAlertTimerGetListInputVo.cs @@ -0,0 +1,19 @@ +using Volo.Abp.Application.Dtos; + +namespace FoodLabeling.Application.Contracts.Dtos.LabelAlertTimer; + +/// +/// 告警计时器分页列表入参 +/// +public class LabelAlertTimerGetListInputVo : PagedAndSortedResultRequestDto +{ + /// + /// 当前门店 Id(location.Id,Guid 字符串,必填) + /// + public string? LocationId { get; set; } + + /// + /// 打印日期(yyyy-MM-dd);按 PrintedAt 筛选该日记录。 + /// + public string? DateDay { get; set; } +} diff --git a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelAlertTimer/LabelAlertTimerListItemDto.cs b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelAlertTimer/LabelAlertTimerListItemDto.cs new file mode 100644 index 0000000..f5a783a --- /dev/null +++ b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelAlertTimer/LabelAlertTimerListItemDto.cs @@ -0,0 +1,38 @@ +namespace FoodLabeling.Application.Contracts.Dtos.LabelAlertTimer; + +/// +/// 告警计时器列表项 +/// +public class LabelAlertTimerListItemDto +{ + public string Id { get; set; } = string.Empty; + + public string BatchId { get; set; } = string.Empty; + + public string PrintTaskId { get; set; } = string.Empty; + + public string LabelId { get; set; } = string.Empty; + + public string? LabelCode { get; set; } + + public string Title { get; set; } = string.Empty; + + public string Subtitle { get; set; } = string.Empty; + + /// 总时长(秒),同 DurationSeconds + public int TotalTime { get; set; } + + /// 剩余时长(秒) + public int RemainingTime { get; set; } + + /// 状态:expired 或 running + public string Status { get; set; } = string.Empty; + + public DateTime ExpiresAt { get; set; } + + public DateTime PrintedAt { get; set; } + + public string LocationId { get; set; } = string.Empty; + + public string? ProductName { get; set; } +} diff --git a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/IServices/ILabelAlertTimerAppService.cs b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/IServices/ILabelAlertTimerAppService.cs new file mode 100644 index 0000000..128e58c --- /dev/null +++ b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/IServices/ILabelAlertTimerAppService.cs @@ -0,0 +1,17 @@ +using FoodLabeling.Application.Contracts.Dtos.Common; +using FoodLabeling.Application.Contracts.Dtos.LabelAlertTimer; +using Volo.Abp.Application.Services; + +namespace FoodLabeling.Application.Contracts.IServices; + +/// +/// 标签告警计时器(App) +/// +public interface ILabelAlertTimerAppService : IApplicationService +{ + Task> GetListAsync(LabelAlertTimerGetListInputVo input); + + Task DeleteAsync(string id); + + Task CheckExpiredAsync(LabelAlertTimerCheckExpiredInputVo input); +} diff --git a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/LabelAlertTimerWriteHelper.cs b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/LabelAlertTimerWriteHelper.cs new file mode 100644 index 0000000..2c945b6 --- /dev/null +++ b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/LabelAlertTimerWriteHelper.cs @@ -0,0 +1,148 @@ +using System.Globalization; +using FoodLabeling.Application.Services.DbModels; +using FoodLabeling.Domain.Shared.Helpers; +using SqlSugar; + +namespace FoodLabeling.Application.Helpers; + +/// +/// 打印成功后写入告警计时器(按 BatchId 幂等,一条批次一条计时器)。 +/// +public static class LabelAlertTimerWriteHelper +{ + /// + /// 根据打印批次创建告警计时器;已存在未删除记录或无有效过期时刻时直接返回。 + /// + public static async Task TryCreateFromPrintBatchAsync( + ISqlSugarClient db, + string batchId, + string? createdBy, + CancellationToken ct = default) + { + var bid = batchId?.Trim(); + if (string.IsNullOrWhiteSpace(bid)) + { + return; + } + + ct.ThrowIfCancellationRequested(); + + // BatchId 有唯一索引:含软删记录也不再插入,避免幂等补写撞唯一约束 + var exists = await db.Queryable() + .AnyAsync(x => x.BatchId == bid); + if (exists) + { + return; + } + + var task = (await db.Queryable() + .Where(x => x.BatchId == bid) + .OrderBy(x => x.CopyIndex) + .Take(1) + .ToListAsync(ct)) + .FirstOrDefault(); + if (task is null) + { + return; + } + + var printedAt = task.PrintedAt ?? task.BaseTime ?? task.CreationTime; + if (!ReportsPrintLogExpiryHelper.TryResolveExpiryDateTime( + task.PrintInputJson, + task.RenderTemplateJson, + task.BaseTime, + printedAt, + out var expiresAt)) + { + return; + } + + var label = (await db.Queryable() + .Where(x => x.Id == task.LabelId) + .Select(x => new { x.LabelName, x.LabelCode }) + .Take(1) + .ToListAsync(ct)) + .FirstOrDefault(); + + var labelName = label?.LabelName?.Trim(); + if (string.IsNullOrWhiteSpace(labelName)) + { + labelName = FoodLabelingDisplayConsts.NotAvailable; + } + + string? productName = null; + if (!string.IsNullOrWhiteSpace(task.ProductId)) + { + productName = (await db.Queryable() + .Where(x => x.Id == task.ProductId && !x.IsDeleted) + .Select(x => x.ProductName) + .Take(1) + .ToListAsync(ct)) + .FirstOrDefault(); + } + + var durationSeconds = Math.Max(0, (int)(expiresAt - printedAt).TotalSeconds); + var title = BuildTitle(labelName, durationSeconds); + var subtitle = BuildSubtitle(durationSeconds, expiresAt); + var now = DateTime.Now; + + var entity = new FlLabelAlertTimerDbEntity + { + Id = YitIdHelper.NextId().ToString(), + BatchId = bid, + PrintTaskId = task.Id, + LabelId = task.LabelId, + LabelCode = label?.LabelCode?.Trim(), + LabelName = labelName, + ProductId = task.ProductId, + ProductName = string.IsNullOrWhiteSpace(productName) ? null : productName.Trim(), + LocationId = task.LocationId?.Trim() ?? string.Empty, + PrintedAt = printedAt, + BaseTime = task.BaseTime, + ExpiresAt = expiresAt, + DurationSeconds = durationSeconds, + Title = title, + Subtitle = subtitle, + IsDeleted = false, + DeletionTime = null, + CreatedBy = createdBy, + CreationTime = now + }; + + await db.Insertable(entity).ExecuteCommandAsync(); + } + + private static string BuildTitle(string labelName, int durationSeconds) + { + var hoursText = FormatDurationHoursLabel(durationSeconds); + return string.IsNullOrWhiteSpace(hoursText) ? labelName : $"{labelName} ({hoursText})"; + } + + private static string BuildSubtitle(int durationSeconds, DateTime expiresAt) + { + var hoursText = FormatDurationHoursLabel(durationSeconds); + var timeText = expiresAt.ToString("h:mm tt", CultureInfo.CurrentCulture); + return string.IsNullOrWhiteSpace(hoursText) + ? $"Completes at {timeText}" + : $"{hoursText} Completes at {timeText}"; + } + + private static string FormatDurationHoursLabel(int durationSeconds) + { + if (durationSeconds <= 0) + { + return string.Empty; + } + + var totalHours = durationSeconds / 3600.0; + if (totalHours >= 1) + { + var rounded = (int)Math.Round(totalHours, MidpointRounding.AwayFromZero); + rounded = Math.Max(1, rounded); + return rounded == 1 ? "1 hour" : $"{rounded} hours"; + } + + var minutes = Math.Max(1, (int)Math.Ceiling(durationSeconds / 60.0)); + return minutes == 1 ? "1 minute" : $"{minutes} minutes"; + } +} diff --git a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/LabelEntityPartnerScopeHelper.cs b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/LabelEntityPartnerScopeHelper.cs index e382df7..6483617 100644 --- a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/LabelEntityPartnerScopeHelper.cs +++ b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/LabelEntityPartnerScopeHelper.cs @@ -340,7 +340,14 @@ public static class LabelEntityPartnerScopeHelper else { var collapsed = await ScopeAllEchoHelper.CollapseScopeIdsToAllSentinelAsync( - db, pIds, null, null); + db, + pIds, + null, + null, + new ScopeAllEchoHelper.ScopeAllEchoOptions + { + AppliedPartnerType = partnerType + }); displayPartnerIds = collapsed.PartnerIds; } diff --git a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/ScopeAllEchoHelper.cs b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/ScopeAllEchoHelper.cs index 2ba7e48..6987934 100644 --- a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/ScopeAllEchoHelper.cs +++ b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/ScopeAllEchoHelper.cs @@ -14,6 +14,13 @@ public static class ScopeAllEchoHelper public bool IsRegionAll { get; init; } public bool IsLocationAll { get; init; } + + /// 落库维度为 SPECIFIED 时禁止再按「恰好全选」折叠为 ALL 哨兵。 + public string? AppliedPartnerType { get; init; } + + public string? AppliedRegionType { get; init; } + + public string? AppliedLocationType { get; init; } } /// @@ -36,7 +43,7 @@ public static class ScopeAllEchoHelper { partners = new List { AllScopeBindingHelper.ScopeAll }; } - else if (partners.Count > 0) + else if (!AllScopeBindingHelper.IsDeclaredSpecified(options.AppliedPartnerType) && partners.Count > 0) { var allPartners = await AllScopeBindingHelper.ResolveAllPartnerIdsAsync(db); if (allPartners.Count > 0 && AllScopeBindingHelper.IsFullIdSelection(partners, allPartners)) @@ -49,7 +56,7 @@ public static class ScopeAllEchoHelper { regions = new List { AllScopeBindingHelper.ScopeAll }; } - else if (regions.Count > 0) + else if (!AllScopeBindingHelper.IsDeclaredSpecified(options.AppliedRegionType) && regions.Count > 0) { regions = await CollapseRegionsIfFullAsync(db, partners, regions); } @@ -58,7 +65,7 @@ public static class ScopeAllEchoHelper { locations = new List { AllScopeBindingHelper.ScopeAll }; } - else if (locations.Count > 0) + else if (!AllScopeBindingHelper.IsDeclaredSpecified(options.AppliedLocationType) && locations.Count > 0) { locations = await CollapseLocationsIfFullAsync(db, partners, regions, locations); } @@ -79,7 +86,10 @@ public static class ScopeAllEchoHelper { IsPartnerAll = AllScopeBindingHelper.IsDeclaredAll(appliedPartnerType), IsRegionAll = AllScopeBindingHelper.IsDeclaredAll(appliedRegionType), - IsLocationAll = AllScopeBindingHelper.IsDeclaredAll(appliedLocationType) + IsLocationAll = AllScopeBindingHelper.IsDeclaredAll(appliedLocationType), + AppliedPartnerType = appliedPartnerType, + AppliedRegionType = appliedRegionType, + AppliedLocationType = appliedLocationType }; /// 标签类型/分类/多选项:Company + Region + Location 可用范围。 @@ -91,7 +101,10 @@ public static class ScopeAllEchoHelper { IsPartnerAll = AllScopeBindingHelper.IsDeclaredAll(appliedPartnerType), IsRegionAll = AllScopeBindingHelper.IsDeclaredAll(appliedRegionType), - IsLocationAll = AllScopeBindingHelper.IsDeclaredAll(availabilityType) + IsLocationAll = AllScopeBindingHelper.IsDeclaredAll(availabilityType), + AppliedPartnerType = appliedPartnerType, + AppliedRegionType = appliedRegionType, + AppliedLocationType = availabilityType }; /// 兼容旧调用:无 Region 类型时用 AvailabilityType 同时驱动 Region/Location。 @@ -106,10 +119,16 @@ public static class ScopeAllEchoHelper IReadOnlyList locationIds) { var isRegionAll = AllScopeBindingHelper.IsDeclaredAll(appliedRegionType); + var normalizedLocations = LocationScopeBindingHelper.NormalizeIds(locationIds); + var isLocationAll = isRegionAll && normalizedLocations.Count == 0; return new ScopeAllEchoOptions { IsRegionAll = isRegionAll, - IsLocationAll = isRegionAll && LocationScopeBindingHelper.NormalizeIds(locationIds).Count == 0 + IsLocationAll = isLocationAll, + AppliedRegionType = appliedRegionType, + AppliedLocationType = isLocationAll + ? AllScopeBindingHelper.ScopeAll + : AllScopeBindingHelper.ScopeSpecified }; } diff --git a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/DbModels/FlLabelAlertTimerDbEntity.cs b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/DbModels/FlLabelAlertTimerDbEntity.cs new file mode 100644 index 0000000..db8d7aa --- /dev/null +++ b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/DbModels/FlLabelAlertTimerDbEntity.cs @@ -0,0 +1,49 @@ +using SqlSugar; + +namespace FoodLabeling.Application.Services.DbModels; + +/// +/// 标签告警计时器(对应表:fl_label_alert_timer) +/// +[SugarTable("fl_label_alert_timer")] +public class FlLabelAlertTimerDbEntity +{ + [SugarColumn(IsPrimaryKey = true)] + public string Id { get; set; } = string.Empty; + + public string BatchId { get; set; } = string.Empty; + + public string PrintTaskId { get; set; } = string.Empty; + + public string LabelId { get; set; } = string.Empty; + + public string? LabelCode { get; set; } + + public string LabelName { get; set; } = string.Empty; + + public string? ProductId { get; set; } + + public string? ProductName { get; set; } + + public string LocationId { get; set; } = string.Empty; + + public DateTime PrintedAt { get; set; } + + public DateTime? BaseTime { get; set; } + + public DateTime ExpiresAt { get; set; } + + public int DurationSeconds { get; set; } + + public string Title { get; set; } = string.Empty; + + public string Subtitle { get; set; } = string.Empty; + + public bool IsDeleted { get; set; } + + public DateTime? DeletionTime { get; set; } + + public string? CreatedBy { get; set; } + + public DateTime CreationTime { get; set; } +} diff --git a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelAlertTimerAppService.cs b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelAlertTimerAppService.cs new file mode 100644 index 0000000..e72e38d --- /dev/null +++ b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelAlertTimerAppService.cs @@ -0,0 +1,320 @@ +using FoodLabeling.Application.Contracts.Dtos.Common; +using FoodLabeling.Application.Contracts.Dtos.LabelAlertTimer; +using FoodLabeling.Application.Contracts.IServices; +using FoodLabeling.Application.Helpers; +using FoodLabeling.Application.Services.DbModels; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using SqlSugar; +using Volo.Abp; +using Volo.Abp.Application.Services; +using Yi.Framework.SqlSugarCore.Abstractions; + +namespace FoodLabeling.Application.Services; + +/// +/// 标签告警计时器(App):按打印批次展示过期倒计时,过期时刻与 Print Log Expiration 同源。 +/// +public class LabelAlertTimerAppService : ApplicationService, ILabelAlertTimerAppService +{ + private const string StatusRunning = "running"; + private const string StatusExpired = "expired"; + + private readonly ISqlSugarDbContext _dbContext; + + public LabelAlertTimerAppService(ISqlSugarDbContext dbContext) + { + _dbContext = dbContext; + } + + /// + /// 分页查询当前门店告警计时器列表 + /// + /// + /// 过期时刻与 Print Log「Expiration」列同源(ReportsPrintLogExpiryHelper)。 + /// 同一打印批次(BatchId)无论打印多少张标签,仅一条计时器(取 CopyIndex 最小任务)。 + /// + /// 示例请求: + /// ```json + /// { + /// "locationId": "11111111-1111-1111-1111-111111111111", + /// "skipCount": 1, + /// "maxResultCount": 20, + /// "dateDay": "2026-08-07" + /// } + /// ``` + /// + /// 参数说明: + /// - locationId: 当前门店 Id(必填,须已绑定) + /// - skipCount: 页码(从 1 开始) + /// - maxResultCount: 每页条数 + /// - dateDay: 可选,按 PrintedAt 自然日筛选(yyyy-MM-dd) + /// + /// 分页查询入参 + /// 分页计时器列表 + /// 成功返回分页列表 + /// 参数错误或未登录/无门店权限 + /// 服务器错误 + [Authorize] + [HttpPost("label-alert-timer/list")] + public virtual async Task> GetListAsync( + LabelAlertTimerGetListInputVo input) + { + if (input is null) + { + throw new UserFriendlyException("入参不能为空"); + } + + if (!CurrentUser.Id.HasValue) + { + throw new UserFriendlyException("用户未登录"); + } + + var locationId = input.LocationId?.Trim(); + if (string.IsNullOrWhiteSpace(locationId)) + { + throw new UserFriendlyException("门店Id不能为空"); + } + + await UsAppPrintLogScopeHelper.EnsureUserCanAccessLocationAsync( + CurrentUser, _dbContext.SqlSugarClient, locationId); + + var db = _dbContext.SqlSugarClient; + RefAsync total = 0; + var query = db.Queryable() + .Where(x => !x.IsDeleted && x.LocationId == locationId); + + var (dayStart, dayEndExcl) = ResolveDateDayFilter(input.DateDay); + if (dayStart.HasValue && dayEndExcl.HasValue) + { + var start = dayStart.Value; + var endExcl = dayEndExcl.Value; + query = query.Where(x => x.PrintedAt >= start && x.PrintedAt < endExcl); + } + + var pageRows = await query + .OrderBy(x => x.ExpiresAt, OrderByType.Desc) + .OrderBy(x => x.PrintedAt, OrderByType.Desc) + .ToPageListAsync(input.SkipCount, input.MaxResultCount, total); + + var now = DateTime.Now; + var items = pageRows.Select(x => MapListItem(x, now)).ToList(); + + var pageSize = input.MaxResultCount <= 0 ? items.Count : input.MaxResultCount; + var pageIndex = pageSize <= 0 ? 1 : PagedQueryConvention.PageIndexFromSkipCount(input.SkipCount); + var totalCount = (long)total; + var totalPages = pageSize <= 0 ? 0 : (int)Math.Ceiling(totalCount / (double)pageSize); + + return new PagedResultWithPageDto + { + PageIndex = pageIndex, + PageSize = pageSize, + TotalCount = totalCount, + TotalPages = totalPages, + Items = items + }; + } + + /// + /// 软删除告警计时器 + /// + /// + /// 删除前校验当前用户可访问该计时器所属门店。 + /// + /// 计时器 Id + /// 删除成功 + /// 记录不存在或无门店权限 + /// 服务器错误 + [Authorize] + [HttpDelete("label-alert-timer/{id}")] + public virtual async Task DeleteAsync(string id) + { + var timerId = id?.Trim(); + if (string.IsNullOrWhiteSpace(timerId)) + { + throw new UserFriendlyException("计时器Id不能为空"); + } + + if (!CurrentUser.Id.HasValue) + { + throw new UserFriendlyException("用户未登录"); + } + + var db = _dbContext.SqlSugarClient; + var row = (await db.Queryable() + .Where(x => x.Id == timerId && !x.IsDeleted) + .Take(1) + .ToListAsync()) + .FirstOrDefault(); + if (row is null) + { + throw new UserFriendlyException("计时器不存在或已删除"); + } + + await UsAppPrintLogScopeHelper.EnsureUserCanAccessLocationAsync( + CurrentUser, db, row.LocationId); + + var now = DateTime.Now; + await db.Updateable() + .SetColumns(x => x.IsDeleted == true) + .SetColumns(x => x.DeletionTime == now) + .Where(x => x.Id == timerId && !x.IsDeleted) + .ExecuteCommandAsync(); + } + + /// + /// 检查告警计时器是否已过期 + /// + /// + /// 至少提供 timerId、batchId、printTaskId 之一。 + /// 无匹配记录时 found=false、isExpired=false(允许继续打印)。 + /// + /// 示例请求: + /// ```json + /// { + /// "batchId": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" + /// } + /// ``` + /// + /// 参数说明: + /// - timerId: 计时器 Id + /// - batchId: 打印批次 Id + /// - printTaskId: 打印任务 Id(同批次任意任务均可) + /// + /// 查询入参 + /// 过期检查结果 + /// 成功(含未找到记录的情况) + /// 未提供任何标识 + /// 服务器错误 + [Authorize] + [HttpPost("label-alert-timer/check-expired")] + public virtual async Task CheckExpiredAsync( + LabelAlertTimerCheckExpiredInputVo input) + { + if (input is null) + { + throw new UserFriendlyException("入参不能为空"); + } + + var timerId = input.TimerId?.Trim(); + var batchId = input.BatchId?.Trim(); + var printTaskId = input.PrintTaskId?.Trim(); + if (string.IsNullOrWhiteSpace(timerId) && + string.IsNullOrWhiteSpace(batchId) && + string.IsNullOrWhiteSpace(printTaskId)) + { + throw new UserFriendlyException("请至少提供 timerId、batchId 或 printTaskId 之一"); + } + + var db = _dbContext.SqlSugarClient; + FlLabelAlertTimerDbEntity? row = null; + + if (!string.IsNullOrWhiteSpace(timerId)) + { + row = (await db.Queryable() + .Where(x => x.Id == timerId && !x.IsDeleted) + .Take(1) + .ToListAsync()) + .FirstOrDefault(); + } + else if (!string.IsNullOrWhiteSpace(batchId)) + { + row = (await db.Queryable() + .Where(x => x.BatchId == batchId && !x.IsDeleted) + .Take(1) + .ToListAsync()) + .FirstOrDefault(); + } + else if (!string.IsNullOrWhiteSpace(printTaskId)) + { + var task = (await db.Queryable() + .Where(x => x.Id == printTaskId) + .Take(1) + .ToListAsync()) + .FirstOrDefault(); + if (task is not null && !string.IsNullOrWhiteSpace(task.BatchId)) + { + row = (await db.Queryable() + .Where(x => x.BatchId == task.BatchId && !x.IsDeleted) + .Take(1) + .ToListAsync()) + .FirstOrDefault(); + } + } + + if (row is null) + { + return new LabelAlertTimerCheckExpiredOutputDto + { + Found = false, + IsExpired = false, + RemainingSeconds = 0 + }; + } + + if (!CurrentUser.Id.HasValue) + { + throw new UserFriendlyException("用户未登录"); + } + + await UsAppPrintLogScopeHelper.EnsureUserCanAccessLocationAsync( + CurrentUser, db, row.LocationId); + + var now = DateTime.Now; + var remaining = Math.Max(0, (int)(row.ExpiresAt - now).TotalSeconds); + var isExpired = row.ExpiresAt <= now; + + return new LabelAlertTimerCheckExpiredOutputDto + { + Found = true, + IsExpired = isExpired, + ExpiresAt = row.ExpiresAt, + RemainingSeconds = remaining, + Status = isExpired ? StatusExpired : StatusRunning, + Title = row.Title, + Subtitle = row.Subtitle, + TimerId = row.Id, + BatchId = row.BatchId + }; + } + + private static LabelAlertTimerListItemDto MapListItem(FlLabelAlertTimerDbEntity row, DateTime now) + { + var remaining = Math.Max(0, (int)(row.ExpiresAt - now).TotalSeconds); + var isExpired = row.ExpiresAt <= now; + + return new LabelAlertTimerListItemDto + { + Id = row.Id, + BatchId = row.BatchId, + PrintTaskId = row.PrintTaskId, + LabelId = row.LabelId, + LabelCode = row.LabelCode, + Title = row.Title, + Subtitle = row.Subtitle, + TotalTime = row.DurationSeconds, + RemainingTime = remaining, + Status = isExpired ? StatusExpired : StatusRunning, + ExpiresAt = row.ExpiresAt, + PrintedAt = row.PrintedAt, + LocationId = row.LocationId, + ProductName = row.ProductName + }; + } + + private static (DateTime? DayStart, DateTime? DayEndExcl) ResolveDateDayFilter(string? dateDay) + { + if (string.IsNullOrWhiteSpace(dateDay)) + { + return (null, null); + } + + if (DateTime.TryParse(dateDay.Trim(), out var parsedDay)) + { + var day = parsedDay.Date; + return (day, day.AddDays(1)); + } + + return (null, null); + } +} diff --git a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelMultipleOptionAppService.cs b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelMultipleOptionAppService.cs index ef1587d..83ed804 100644 --- a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelMultipleOptionAppService.cs +++ b/泰额版/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 } var entities = await query.ToPageListAsync(input.SkipCount, input.MaxResultCount, total); - var scopeMap = await BuildMultipleOptionScopeMapAsync(entities); var partnerScopeMap = await LabelEntityPartnerScopeHelper.BuildPartnerScopeDisplayMapAsync( _dbContext.SqlSugarClient, LabelEntityPartnerScopeHelper.LabelEntityPartnerKind.MultipleOption, entities.Select(x => x.Id).ToList()); + var scopeMap = await BuildMultipleOptionScopeMapAsync(entities, partnerScopeMap); var items = entities.Select(x => { @@ -478,7 +478,8 @@ public class LabelMultipleOptionAppService : ApplicationService, ILabelMultipleO } private async Task> BuildMultipleOptionScopeMapAsync( - List entities) + List entities, + Dictionary partnerScopeMap) { var result = new Dictionary(StringComparer.Ordinal); if (entities.Count == 0) @@ -486,6 +487,8 @@ public class LabelMultipleOptionAppService : ApplicationService, ILabelMultipleO return result; } + var entityById = entities.ToDictionary(x => x.Id, StringComparer.Ordinal); + foreach (var e in entities.Where(x => !string.Equals(x.AvailabilityType, "SPECIFIED", StringComparison.OrdinalIgnoreCase))) { @@ -581,10 +584,28 @@ public class LabelMultipleOptionAppService : ApplicationService, ILabelMultipleO var regionIds = await LocationScopeBindingHelper.ResolveGroupIdsFromLocationIdsAsync( _dbContext.SqlSugarClient, locationIds); - var partnerIds = await LocationScopeBindingHelper.ResolvePartnerIdsFromLocationIdsAsync( - _dbContext.SqlSugarClient, locationIds); + + entityById.TryGetValue(optionId, out var entity); + partnerScopeMap.TryGetValue(optionId, out var partnerScope); + var partnerContext = entity is not null + && string.Equals( + entity.AppliedPartnerType, + LabelEntityPartnerScopeHelper.ScopeSpecified, + StringComparison.OrdinalIgnoreCase) + ? partnerScope?.PartnerIds + : null; + var collapsed = await ScopeAllEchoHelper.CollapseScopeIdsToAllSentinelAsync( - _dbContext.SqlSugarClient, partnerIds, regionIds, locationIds); + _dbContext.SqlSugarClient, + partnerContext, + regionIds, + locationIds, + entity is not null + ? ScopeAllEchoHelper.ForLabelEntityScope( + entity.AppliedPartnerType, + entity.AppliedRegionType, + entity.AvailabilityType) + : null); result[optionId] = new MultipleOptionScopeData { diff --git a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelTypeAppService.cs b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelTypeAppService.cs index d0dde3c..7fec0e1 100644 --- a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelTypeAppService.cs +++ b/泰额版/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 var ids = entities.Select(x => x.Id).ToList(); var countMap = await BuildTypeLabelStatsMapAsync(ids, scopedLocationIds); - var scopeMap = await BuildTypeConfiguredScopeMapAsync(entities); var partnerScopeMap = await LabelEntityPartnerScopeHelper.BuildPartnerScopeDisplayMapAsync( _dbContext.SqlSugarClient, LabelEntityPartnerScopeHelper.LabelEntityPartnerKind.Type, ids); + var scopeMap = await BuildTypeConfiguredScopeMapAsync(entities, partnerScopeMap); var items = entities.Select(x => { @@ -487,7 +487,8 @@ public class LabelTypeAppService : ApplicationService, ILabelTypeAppService } private async Task> BuildTypeConfiguredScopeMapAsync( - List entities) + List entities, + Dictionary partnerScopeMap) { var result = new Dictionary(StringComparer.Ordinal); if (entities.Count == 0) @@ -495,6 +496,8 @@ public class LabelTypeAppService : ApplicationService, ILabelTypeAppService return result; } + var entityById = entities.ToDictionary(x => x.Id, StringComparer.Ordinal); + foreach (var e in entities.Where(x => !string.Equals(x.AvailabilityType, "SPECIFIED", StringComparison.OrdinalIgnoreCase))) { @@ -590,10 +593,28 @@ public class LabelTypeAppService : ApplicationService, ILabelTypeAppService var regionIds = await LocationScopeBindingHelper.ResolveGroupIdsFromLocationIdsAsync( _dbContext.SqlSugarClient, locationIds); - var partnerIds = await LocationScopeBindingHelper.ResolvePartnerIdsFromLocationIdsAsync( - _dbContext.SqlSugarClient, locationIds); + + entityById.TryGetValue(typeId, out var entity); + partnerScopeMap.TryGetValue(typeId, out var partnerScope); + var partnerContext = entity is not null + && string.Equals( + entity.AppliedPartnerType, + LabelEntityPartnerScopeHelper.ScopeSpecified, + StringComparison.OrdinalIgnoreCase) + ? partnerScope?.PartnerIds + : null; + var collapsed = await ScopeAllEchoHelper.CollapseScopeIdsToAllSentinelAsync( - _dbContext.SqlSugarClient, partnerIds, regionIds, locationIds); + _dbContext.SqlSugarClient, + partnerContext, + regionIds, + locationIds, + entity is not null + ? ScopeAllEchoHelper.ForLabelEntityScope( + entity.AppliedPartnerType, + entity.AppliedRegionType, + entity.AvailabilityType) + : null); result[typeId] = new TypeScopeData { diff --git a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/scripts/fl_label_alert_timer.sql b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/scripts/fl_label_alert_timer.sql new file mode 100644 index 0000000..60dbfea --- /dev/null +++ b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/scripts/fl_label_alert_timer.sql @@ -0,0 +1,31 @@ +-- 标签告警计时器:按打印批次(BatchId)一条,过期时刻与 Print Log Expiration 同源解析 +-- 执行前请备份;可重复执行 + +SET @db := DATABASE(); + +CREATE TABLE IF NOT EXISTS `fl_label_alert_timer` ( + `Id` varchar(36) NOT NULL COMMENT '主键', + `BatchId` varchar(36) NOT NULL COMMENT '打印批次Id(fl_label_print_task.BatchId,唯一)', + `PrintTaskId` varchar(36) NOT NULL COMMENT '代表任务Id(CopyIndex 最小)', + `LabelId` varchar(36) NOT NULL COMMENT '标签Id', + `LabelCode` varchar(100) DEFAULT NULL COMMENT '标签编码', + `LabelName` varchar(200) NOT NULL COMMENT '标签名称', + `ProductId` varchar(36) DEFAULT NULL COMMENT '产品Id', + `ProductName` varchar(500) DEFAULT NULL COMMENT '产品名称', + `LocationId` varchar(36) NOT NULL COMMENT '门店Id', + `PrintedAt` datetime NOT NULL COMMENT '打印时刻(PrintedAt ?? BaseTime ?? CreationTime)', + `BaseTime` datetime DEFAULT NULL COMMENT '基准时间', + `ExpiresAt` datetime NOT NULL COMMENT '过期时刻', + `DurationSeconds` int NOT NULL DEFAULT 0 COMMENT '总时长(秒)', + `Title` varchar(500) NOT NULL COMMENT '标题', + `Subtitle` varchar(500) NOT NULL COMMENT '副标题', + `IsDeleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '软删', + `DeletionTime` datetime DEFAULT NULL COMMENT '删除时间', + `CreatedBy` varchar(36) DEFAULT NULL COMMENT '创建者', + `CreationTime` datetime NOT NULL COMMENT '创建时间', + PRIMARY KEY (`Id`), + UNIQUE KEY `uk_fl_label_alert_timer_batch` (`BatchId`), + KEY `idx_fl_label_alert_timer_location` (`LocationId`), + KEY `idx_fl_label_alert_timer_expires` (`ExpiresAt`), + KEY `idx_fl_label_alert_timer_printed` (`PrintedAt`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='标签告警计时器'; diff --git a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling/FoodLabeling.Th.Application/MultiTenancy/ThLoginTenantResolver.cs b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling/FoodLabeling.Th.Application/MultiTenancy/ThLoginTenantResolver.cs new file mode 100644 index 0000000..98fb4af --- /dev/null +++ b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling/FoodLabeling.Th.Application/MultiTenancy/ThLoginTenantResolver.cs @@ -0,0 +1,47 @@ +using Microsoft.Extensions.Logging; +using Yi.Framework.SqlSugarCore.Abstractions; + +namespace FoodLabeling.Th.Application.MultiTenancy; + +/// +/// 泰额 Web / App 登录共用:未选公司时按开通邮箱或租户业务库 user 反查公司租户。 +/// +internal static class ThLoginTenantResolver +{ + /// + /// 未选公司时:先查开通管理员凭据,再扫描各租户业务库 user(Team Member 等)。 + /// + internal static async Task TryResolveCompanyTenantIdByLoginAsync( + DbConnOptions dbConnOptions, + string? loginAccount, + ILogger? logger = null) + { + if (string.IsNullOrWhiteSpace(loginAccount)) + { + return null; + } + + try + { + if (ThWebPlatformLoginHelper.IsPlausiblePlatformEmail(loginAccount)) + { + var fromCredential = await ThTenantHostDataAccessor.FindActiveTenantIdByLoginAccountAsync( + dbConnOptions, + loginAccount); + if (fromCredential.HasValue) + { + return fromCredential; + } + } + + return await ThTenantHostDataAccessor.FindActiveTenantIdByBusinessUserLoginAsync( + dbConnOptions, + loginAccount); + } + catch (Exception ex) + { + logger?.LogError(ex, "按登录账号反查公司租户失败:{UserName}", loginAccount); + return null; + } + } +} diff --git a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling/FoodLabeling.Th.Application/Services/ThUsAppAuthAppService.cs b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling/FoodLabeling.Th.Application/Services/ThUsAppAuthAppService.cs new file mode 100644 index 0000000..12bd2b8 --- /dev/null +++ b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling/FoodLabeling.Th.Application/Services/ThUsAppAuthAppService.cs @@ -0,0 +1,85 @@ +using FoodLabeling.Application.Contracts; +using FoodLabeling.Application.Contracts.Dtos.UsAppAuth; +using FoodLabeling.Application.Contracts.IServices; +using FoodLabeling.Application.Services; +using FoodLabeling.Th.Application.Contracts.Dtos.Auth; +using FoodLabeling.Th.Application.Contracts.IServices; +using Lazy.Captcha.Core; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Caching.Distributed; +using Microsoft.Extensions.Options; +using Volo.Abp.DependencyInjection; +using Yi.Framework.Rbac.Application.Contracts.IServices; +using Yi.Framework.Rbac.Domain.Entities; +using Yi.Framework.Rbac.Domain.Managers; +using Yi.Framework.Rbac.Domain.Shared.Options; +using Yi.Framework.SqlSugarCore.Abstractions; + +namespace FoodLabeling.Th.Application.Services; + +/// +/// 泰额多租户:兼容 App 仍调用 us-app-auth/login,内部按邮箱反查公司并走租户库登录。 +/// +[Dependency(ReplaceServices = true)] +[ExposeServices(typeof(IUsAppAuthAppService), typeof(UsAppAuthAppService))] +public class ThUsAppAuthAppService : UsAppAuthAppService +{ + private readonly IThAppAuthAppService _thAppAuth; + private readonly DbConnOptions _saasDbConnOptions; + + public ThUsAppAuthAppService( + IAccountManager accountManager, + ISqlSugarRepository userRepository, + ISqlSugarDbContext dbContext, + IHttpContextAccessor httpContextAccessor, + ICaptcha captcha, + IOptions jwtOptions, + IOptions rbacOptions, + IForgotPasswordByEmailService forgotPasswordByEmailService, + IDistributedCache distributedCache, + IOptions dbConnOptions, + IThAppAuthAppService thAppAuth) + : base( + accountManager, + userRepository, + dbContext, + httpContextAccessor, + captcha, + jwtOptions, + rbacOptions, + forgotPasswordByEmailService, + distributedCache, + dbConnOptions) + { + _thAppAuth = thAppAuth; + _saasDbConnOptions = dbConnOptions.Value; + } + + /// + /// + /// SaaS 开启时转发至 th-app-auth/login 同等逻辑(邮箱反查租户 + JWT 含 TenantId), + /// 出参仍为 ,前端路径可不变。 + /// + public override async Task LoginAsync(UsAppLoginInputVo input) + { + if (!_saasDbConnOptions.EnabledSaasMultiTenancy) + { + return await base.LoginAsync(input); + } + + var thResult = await _thAppAuth.LoginAsync(new ThAppLoginInputVo + { + Email = input.Email, + Password = input.Password, + Uuid = input.Uuid, + Code = input.Code + }); + + return new UsAppLoginOutputDto + { + Token = thResult.Token, + RefreshToken = thResult.RefreshToken, + Locations = thResult.Locations + }; + } +} diff --git a/项目相关文档/2026-08-07告警接口文档.md b/项目相关文档/2026-08-07告警接口文档.md new file mode 100644 index 0000000..8b7ff9d --- /dev/null +++ b/项目相关文档/2026-08-07告警接口文档.md @@ -0,0 +1,188 @@ +# 告警计时器接口文档(泰额版) + +> 模块:标签告警计时器(Label Alert Timer) +> 范围:泰额版后端(租户业务库,非 `antis-foodlabeling-host`) +> 认证:`Authorization: Bearer {token}`;业务请求建议带 `__tenant: {tenantId}` +> JSON:camelCase +> Base URL 示例:`http://127.0.0.1:19002`(以实际部署为准) +> 更新日期:2026-08-07 + +--- + +## 1. 业务说明 + +| 概念 | 说明 | +|------|------| +| 过期时刻 | 与 Print Log「Expiration」列**同源**,由 `ReportsPrintLogExpiryHelper.TryResolveExpiryDateTime` 解析 | +| 批次维度 | 一次打印(同一 `BatchId`)无论打印多少张,**仅一条**计时器(取 `CopyIndex` 最小的 `fl_label_print_task`) | +| 无过期不上列表 | 模板无法解析过期时刻时,不写入计时器、不出现在列表 | +| 状态 | `running`(未过期)/ `expired`(已过期) | +| 软删 | 用户可删除计时器;删除后不再出现在列表 | + +### 写入时机 + +- `UsAppLabelingAppService.PrintAsync` / `ReprintAsync` 成功创建批次后自动写入 +- 幂等重试(相同 `clientRequestId`)返回前也会补写一次(Helper 内部按 `BatchId` 去重) + +### 建表 + +- 脚本:`module/food-labeling-us/scripts/fl_label_alert_timer.sql` +- 表名:`fl_label_alert_timer` +- 新租户开通时嵌入资源自动执行;**已有租户需用具备 CREATE 权限的账号**在业务库手动执行脚本(业务账号 `netteam` 通常无建表权限,可用运维高权限账号执行) + +--- + +## 2. 接口一览 + +| 功能 | 方法 | 路由 | +|------|------|------| +| 分页列表 | POST | `/api/app/label-alert-timer/list` | +| 软删除 | DELETE | `/api/app/label-alert-timer/{id}` | +| 检查是否过期 | POST | `/api/app/label-alert-timer/check-expired` | + +> 所有接口需登录;列表与删除需已绑定 `locationId` 对应门店。 + +--- + +## 3. 分页列表 + +**POST** `/api/app/label-alert-timer/list` + +### 请求 + +```json +{ + "locationId": "3a21220f-db37-3e32-7390-d55f64cd62a8", + "skipCount": 1, + "maxResultCount": 20, + "dateDay": "2026-08-07" +} +``` + +| 字段 | 必填 | 说明 | +|------|------|------| +| locationId | 是 | 当前门店 Id | +| skipCount | 是 | 页码(从 1 开始) | +| maxResultCount | 是 | 每页条数 | +| dateDay | 否 | `yyyy-MM-dd`,按 PrintedAt 自然日筛选 | + +### 响应示例 + +```json +{ + "pageIndex": 1, + "pageSize": 20, + "totalCount": 1, + "totalPages": 1, + "items": [ + { + "id": "1987654321000123456", + "batchId": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", + "printTaskId": "bbbbbbbb-cccc-dddd-eeee-ffffffffffff", + "labelId": "label-id-001", + "labelCode": "LB_001", + "title": "Chicken Prep (4 hours)", + "subtitle": "4 hours Completes at 2:30 PM", + "totalTime": 14400, + "remainingTime": 7200, + "status": "running", + "expiresAt": "2026-08-07T14:30:00", + "printedAt": "2026-08-07T10:30:00", + "locationId": "3a21220f-db37-3e32-7390-d55f64cd62a8", + "productName": "Grilled Chicken" + } + ] +} +``` + +| 出参字段 | 说明 | +|----------|------| +| totalTime | 总时长(秒),等于库中 DurationSeconds | +| remainingTime | 剩余秒数,`max(0, ExpiresAt - now)` | +| status | `running` 或 `expired` | + +--- + +## 4. 软删除 + +**DELETE** `/api/app/label-alert-timer/{id}` + +- 校验当前用户可访问该计时器所属门店 +- 设置 `IsDeleted=1`、`DeletionTime=now` + +--- + +## 5. 检查是否过期 + +**POST** `/api/app/label-alert-timer/check-expired` + +### 请求 + +至少提供 `timerId`、`batchId`、`printTaskId` 之一: + +```json +{ + "batchId": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" +} +``` + +### 响应(找到记录) + +```json +{ + "found": true, + "isExpired": false, + "expiresAt": "2026-08-07T14:30:00", + "remainingSeconds": 7200, + "status": "running", + "title": "Chicken Prep (4 hours)", + "subtitle": "4 hours Completes at 2:30 PM", + "timerId": "1987654321000123456", + "batchId": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" +} +``` + +### 响应(无记录) + +```json +{ + "found": false, + "isExpired": false, + "remainingSeconds": 0 +} +``` + +> **对接建议**:`found=false` 时视为无告警限制,**允许继续打印**;`found=true && isExpired=true` 时可提示用户标签已过期。 + +--- + +## 6. curl 示例 + +```bash +# 获取 Token 后替换 TOKEN、TENANT、LOCATION_ID + +curl -s -X POST "http://127.0.0.1:19002/api/app/label-alert-timer/list" \ + -H "Authorization: Bearer TOKEN" \ + -H "__tenant: TENANT" \ + -H "Content-Type: application/json" \ + -d '{"locationId":"LOCATION_ID","skipCount":1,"maxResultCount":20}' + +curl -s -X POST "http://127.0.0.1:19002/api/app/label-alert-timer/check-expired" \ + -H "Authorization: Bearer TOKEN" \ + -H "__tenant: TENANT" \ + -H "Content-Type: application/json" \ + -d '{"batchId":"YOUR_BATCH_ID"}' + +curl -s -X DELETE "http://127.0.0.1:19002/api/app/label-alert-timer/TIMER_ID" \ + -H "Authorization: Bearer TOKEN" \ + -H "__tenant: TENANT" +``` + +--- + +## 7. 前端对接建议 + +1. **列表页**:进入门店后拉取列表,用 `remainingTime` 做倒计时;`status=expired` 可高亮或置顶。 +2. **打印前校验**(可选):重打历史批次时调 `check-expired`,`isExpired=true` 时二次确认。 +3. **与 Print Log 一致**:展示过期时间时请与 Print Log Expiration 列对齐,避免两套算法。 +4. **删除**:用户左滑/长按删除时调 DELETE;删除仅隐藏计时器,不影响历史打印任务。