Commit 816bc71f54477b1b47153da00beda7e78ad49395
1 parent
21737407
2026-10-22泰鄂版:告警
Showing
24 changed files
with
1009 additions
and
42 deletions
泰额版/Food Labeling Management App UniApp/src/services/usAppAlertTimer.ts
| @@ -84,3 +84,54 @@ export function deleteUsAppAlertTimer(id: string): Promise<void> { | @@ -84,3 +84,54 @@ export function deleteUsAppAlertTimer(id: string): Promise<void> { | ||
| 84 | auth: true, | 84 | auth: true, |
| 85 | }) | 85 | }) |
| 86 | } | 86 | } |
| 87 | + | ||
| 88 | +export interface UsAppAlertTemplateOption { | ||
| 89 | + id: string | ||
| 90 | + templateName: string | ||
| 91 | + durationUnit: string | ||
| 92 | + durationValue: number | ||
| 93 | +} | ||
| 94 | + | ||
| 95 | +function normalizeTemplateOption(raw: unknown): UsAppAlertTemplateOption | null { | ||
| 96 | + const o = (raw && typeof raw === 'object' ? raw : {}) as Record<string, unknown> | ||
| 97 | + const id = str(o, 'id', 'Id') | ||
| 98 | + if (!id) return null | ||
| 99 | + const unitRaw = o.durationUnit ?? o.DurationUnit | ||
| 100 | + const durationUnit = typeof unitRaw === 'string' && unitRaw.trim() | ||
| 101 | + ? unitRaw.trim() | ||
| 102 | + : String(unitRaw ?? 'Minute') | ||
| 103 | + return { | ||
| 104 | + id, | ||
| 105 | + templateName: str(o, 'templateName', 'TemplateName') || id, | ||
| 106 | + durationUnit, | ||
| 107 | + durationValue: Math.max(0, num(o, 'durationValue', 'DurationValue')), | ||
| 108 | + } | ||
| 109 | +} | ||
| 110 | + | ||
| 111 | +export async function fetchUsAppAlertTemplateOptions(): Promise<UsAppAlertTemplateOption[]> { | ||
| 112 | + const raw = await usAppApiRequest<unknown>({ | ||
| 113 | + path: '/api/app/alert-template/options', | ||
| 114 | + method: 'GET', | ||
| 115 | + auth: true, | ||
| 116 | + }) | ||
| 117 | + const o = (raw && typeof raw === 'object' ? raw : {}) as Record<string, unknown> | ||
| 118 | + const list = Array.isArray(raw) ? raw : asArr(o.items ?? o.Items) | ||
| 119 | + return list.map(normalizeTemplateOption).filter((x): x is UsAppAlertTemplateOption => !!x) | ||
| 120 | +} | ||
| 121 | + | ||
| 122 | +export async function createUsAppAlertTimer(input: { | ||
| 123 | + alertTemplateId: string | ||
| 124 | + locationId?: string | ||
| 125 | +}): Promise<UsAppAlertTimerDto> { | ||
| 126 | + const body: Record<string, unknown> = { | ||
| 127 | + alertTemplateId: input.alertTemplateId, | ||
| 128 | + } | ||
| 129 | + if (input.locationId) body.locationId = input.locationId | ||
| 130 | + const raw = await usAppApiRequest<unknown>({ | ||
| 131 | + path: `${PATH}/create`, | ||
| 132 | + method: 'POST', | ||
| 133 | + data: body, | ||
| 134 | + auth: true, | ||
| 135 | + }) | ||
| 136 | + return normalizeTimer(raw) | ||
| 137 | +} |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/AlertTemplate/AlertTemplateCreateInputVo.cs
| 1 | +using System.Text.Json.Serialization; | ||
| 2 | +using FoodLabeling.Application.Contracts.Json; | ||
| 3 | +using FoodLabeling.Domain.Shared.Enums; | ||
| 4 | + | ||
| 1 | namespace FoodLabeling.Application.Contracts.Dtos.AlertTemplate; | 5 | namespace FoodLabeling.Application.Contracts.Dtos.AlertTemplate; |
| 2 | 6 | ||
| 3 | /// <summary>告警模板新增/编辑入参</summary> | 7 | /// <summary>告警模板新增/编辑入参</summary> |
| @@ -5,7 +9,15 @@ public class AlertTemplateCreateInputVo | @@ -5,7 +9,15 @@ public class AlertTemplateCreateInputVo | ||
| 5 | { | 9 | { |
| 6 | public string TemplateName { get; set; } = string.Empty; | 10 | public string TemplateName { get; set; } = string.Empty; |
| 7 | 11 | ||
| 8 | - public string DateTimeFormat { get; set; } = string.Empty; | 12 | + /// <summary> |
| 13 | + /// 时长单位:Year/Month/Day/Hour/Minute/Second/Combined, | ||
| 14 | + /// 也可传 年/月/日/时/分/秒/组合时间。 | ||
| 15 | + /// </summary> | ||
| 16 | + [JsonConverter(typeof(AlertTemplateDurationUnitJsonConverter))] | ||
| 17 | + public AlertTemplateDurationUnit DurationUnit { get; set; } | ||
| 18 | + | ||
| 19 | + /// <summary>时长数字,与单位组合成 3年、3月、3日等;组合时间为总秒数。</summary> | ||
| 20 | + public int DurationValue { get; set; } | ||
| 9 | 21 | ||
| 10 | public bool State { get; set; } = true; | 22 | public bool State { get; set; } = true; |
| 11 | } | 23 | } |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/AlertTemplate/AlertTemplateDto.cs
| 1 | +using System.Text.Json.Serialization; | ||
| 2 | +using FoodLabeling.Application.Contracts.Json; | ||
| 3 | +using FoodLabeling.Domain.Shared.Enums; | ||
| 4 | + | ||
| 1 | namespace FoodLabeling.Application.Contracts.Dtos.AlertTemplate; | 5 | namespace FoodLabeling.Application.Contracts.Dtos.AlertTemplate; |
| 2 | 6 | ||
| 3 | /// <summary>告警模板详情/列表项</summary> | 7 | /// <summary>告警模板详情/列表项</summary> |
| @@ -7,7 +11,12 @@ public class AlertTemplateDto | @@ -7,7 +11,12 @@ public class AlertTemplateDto | ||
| 7 | 11 | ||
| 8 | public string TemplateName { get; set; } = string.Empty; | 12 | public string TemplateName { get; set; } = string.Empty; |
| 9 | 13 | ||
| 10 | - public string DateTimeFormat { get; set; } = string.Empty; | 14 | + /// <summary>时长单位</summary> |
| 15 | + [JsonConverter(typeof(AlertTemplateDurationUnitJsonConverter))] | ||
| 16 | + public AlertTemplateDurationUnit DurationUnit { get; set; } | ||
| 17 | + | ||
| 18 | + /// <summary>时长数字</summary> | ||
| 19 | + public int DurationValue { get; set; } | ||
| 11 | 20 | ||
| 12 | public bool State { get; set; } | 21 | public bool State { get; set; } |
| 13 | 22 |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/AlertTemplate/AlertTemplateOptionDto.cs
| 1 | +using System.Text.Json.Serialization; | ||
| 2 | +using FoodLabeling.Application.Contracts.Json; | ||
| 3 | +using FoodLabeling.Domain.Shared.Enums; | ||
| 4 | + | ||
| 1 | namespace FoodLabeling.Application.Contracts.Dtos.AlertTemplate; | 5 | namespace FoodLabeling.Application.Contracts.Dtos.AlertTemplate; |
| 2 | 6 | ||
| 3 | /// <summary>告警模板下拉项(仅启用)</summary> | 7 | /// <summary>告警模板下拉项(仅启用)</summary> |
| @@ -7,5 +11,8 @@ public class AlertTemplateOptionDto | @@ -7,5 +11,8 @@ public class AlertTemplateOptionDto | ||
| 7 | 11 | ||
| 8 | public string TemplateName { get; set; } = string.Empty; | 12 | public string TemplateName { get; set; } = string.Empty; |
| 9 | 13 | ||
| 10 | - public string DateTimeFormat { get; set; } = string.Empty; | 14 | + [JsonConverter(typeof(AlertTemplateDurationUnitJsonConverter))] |
| 15 | + public AlertTemplateDurationUnit DurationUnit { get; set; } | ||
| 16 | + | ||
| 17 | + public int DurationValue { get; set; } | ||
| 11 | } | 18 | } |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelAlertTimer/LabelAlertTimerCreateInputVo.cs
0 → 100644
| 1 | +namespace FoodLabeling.Application.Contracts.Dtos.LabelAlertTimer; | ||
| 2 | + | ||
| 3 | +/// <summary>按告警模板手动新增计时器入参</summary> | ||
| 4 | +public class LabelAlertTimerCreateInputVo | ||
| 5 | +{ | ||
| 6 | + /// <summary>告警模板 Id(取其 durationUnit + durationValue 作为倒计时)</summary> | ||
| 7 | + public string AlertTemplateId { get; set; } = string.Empty; | ||
| 8 | + | ||
| 9 | + /// <summary>门店 Id。Web 建议传入;App 可空(已选门店缓存)</summary> | ||
| 10 | + public string? LocationId { get; set; } | ||
| 11 | +} | ||
| 0 | \ No newline at end of file | 12 | \ No newline at end of file |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelAlertTimer/LabelAlertTimerListItemDto.cs
| @@ -49,6 +49,9 @@ public class LabelAlertTimerListItemDto | @@ -49,6 +49,9 @@ public class LabelAlertTimerListItemDto | ||
| 49 | 49 | ||
| 50 | public string? DateTimeFormat { get; set; } | 50 | public string? DateTimeFormat { get; set; } |
| 51 | 51 | ||
| 52 | + /// <summary>来源:printLog / manual</summary> | ||
| 53 | + public string Source { get; set; } = "printLog"; | ||
| 54 | + | ||
| 52 | public string? PrintedByUserId { get; set; } | 55 | public string? PrintedByUserId { get; set; } |
| 53 | 56 | ||
| 54 | public string? PrintedByUserName { get; set; } | 57 | public string? PrintedByUserName { get; set; } |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/Reports/ReportsPrintLogListItemDto.cs
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/IServices/IAlertTemplateAppService.cs
| @@ -4,7 +4,7 @@ using Volo.Abp.Application.Services; | @@ -4,7 +4,7 @@ using Volo.Abp.Application.Services; | ||
| 4 | 4 | ||
| 5 | namespace FoodLabeling.Application.Contracts.IServices; | 5 | namespace FoodLabeling.Application.Contracts.IServices; |
| 6 | 6 | ||
| 7 | -/// <summary>告警日期时间格式模板</summary> | 7 | +/// <summary>告警模板(倒计时秒数)</summary> |
| 8 | public interface IAlertTemplateAppService : IApplicationService | 8 | public interface IAlertTemplateAppService : IApplicationService |
| 9 | { | 9 | { |
| 10 | Task<PagedResultWithPageDto<AlertTemplateDto>> ListAsync(AlertTemplateGetListInputVo input); | 10 | Task<PagedResultWithPageDto<AlertTemplateDto>> ListAsync(AlertTemplateGetListInputVo input); |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/IServices/ILabelAlertTimerAppService.cs
| @@ -17,6 +17,18 @@ public interface ILabelAlertTimerAppService : IApplicationService | @@ -17,6 +17,18 @@ public interface ILabelAlertTimerAppService : IApplicationService | ||
| 17 | /// <remarks>方法名避免 Get 前缀,确保 ABP 约定为 POST(路径仍为 app-list)。</remarks> | 17 | /// <remarks>方法名避免 Get 前缀,确保 ABP 约定为 POST(路径仍为 app-list)。</remarks> |
| 18 | Task<PagedResultWithPageDto<LabelAlertTimerListItemDto>> AppListAsync(LabelAlertTimerGetListInputVo input); | 18 | Task<PagedResultWithPageDto<LabelAlertTimerListItemDto>> AppListAsync(LabelAlertTimerGetListInputVo input); |
| 19 | 19 | ||
| 20 | + /// <summary> | ||
| 21 | + /// Web/App:按告警模板倒计时手动新增计时器 | ||
| 22 | + /// </summary> | ||
| 23 | + Task<LabelAlertTimerListItemDto> CreateAsync(LabelAlertTimerCreateInputVo input); | ||
| 24 | + | ||
| 25 | + /// <summary> | ||
| 26 | + /// App:POST /label-alert-timer/{alertTemplateId} 兼容新增 | ||
| 27 | + /// </summary> | ||
| 28 | + Task<LabelAlertTimerListItemDto> CreateByTemplateIdAsync( | ||
| 29 | + string alertTemplateId, | ||
| 30 | + LabelAlertTimerCreateInputVo? input); | ||
| 31 | + | ||
| 20 | Task DeleteAsync(string id); | 32 | Task DeleteAsync(string id); |
| 21 | 33 | ||
| 22 | Task<LabelAlertTimerCheckExpiredOutputDto> CheckExpiredAsync(LabelAlertTimerCheckExpiredInputVo input); | 34 | Task<LabelAlertTimerCheckExpiredOutputDto> CheckExpiredAsync(LabelAlertTimerCheckExpiredInputVo input); |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Json/AlertTemplateDurationUnitJsonConverter.cs
0 → 100644
| 1 | +using System.Text.Json; | ||
| 2 | +using System.Text.Json.Serialization; | ||
| 3 | +using FoodLabeling.Domain.Shared.Enums; | ||
| 4 | + | ||
| 5 | +namespace FoodLabeling.Application.Contracts.Json; | ||
| 6 | + | ||
| 7 | +/// <summary> | ||
| 8 | +/// 时长单位:英文枚举名、数字、中文(年/月/日/时/分/秒/组合时间)均可。 | ||
| 9 | +/// </summary> | ||
| 10 | +public sealed class AlertTemplateDurationUnitJsonConverter : JsonConverter<AlertTemplateDurationUnit> | ||
| 11 | +{ | ||
| 12 | + public override AlertTemplateDurationUnit Read( | ||
| 13 | + ref Utf8JsonReader reader, | ||
| 14 | + Type typeToConvert, | ||
| 15 | + JsonSerializerOptions options) | ||
| 16 | + { | ||
| 17 | + if (reader.TokenType == JsonTokenType.Number && reader.TryGetInt32(out var num)) | ||
| 18 | + { | ||
| 19 | + if (Enum.IsDefined(typeof(AlertTemplateDurationUnit), num)) | ||
| 20 | + { | ||
| 21 | + return (AlertTemplateDurationUnit)num; | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + throw new JsonException("durationUnit is invalid."); | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + if (reader.TokenType != JsonTokenType.String) | ||
| 28 | + { | ||
| 29 | + throw new JsonException("durationUnit must be a string or number."); | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + if (!TryParse(reader.GetString(), out var unit)) | ||
| 33 | + { | ||
| 34 | + throw new JsonException("durationUnit is invalid."); | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + return unit; | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + public override void Write( | ||
| 41 | + Utf8JsonWriter writer, | ||
| 42 | + AlertTemplateDurationUnit value, | ||
| 43 | + JsonSerializerOptions options) | ||
| 44 | + { | ||
| 45 | + writer.WriteStringValue(value.ToString()); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + public static bool TryParse(string? raw, out AlertTemplateDurationUnit unit) | ||
| 49 | + { | ||
| 50 | + unit = default; | ||
| 51 | + var s = raw?.Trim(); | ||
| 52 | + if (string.IsNullOrWhiteSpace(s)) | ||
| 53 | + { | ||
| 54 | + return false; | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + if (int.TryParse(s, out var num) && Enum.IsDefined(typeof(AlertTemplateDurationUnit), num)) | ||
| 58 | + { | ||
| 59 | + unit = (AlertTemplateDurationUnit)num; | ||
| 60 | + return true; | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + if (Enum.TryParse(s, true, out unit) && Enum.IsDefined(unit)) | ||
| 64 | + { | ||
| 65 | + return true; | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + unit = s switch | ||
| 69 | + { | ||
| 70 | + "年" or "year" or "years" => AlertTemplateDurationUnit.Year, | ||
| 71 | + "月" or "month" or "months" => AlertTemplateDurationUnit.Month, | ||
| 72 | + "日" or "天" or "day" or "days" => AlertTemplateDurationUnit.Day, | ||
| 73 | + "时" or "小时" or "hour" or "hours" => AlertTemplateDurationUnit.Hour, | ||
| 74 | + "分" or "分钟" or "minute" or "minutes" => AlertTemplateDurationUnit.Minute, | ||
| 75 | + "秒" or "second" or "seconds" => AlertTemplateDurationUnit.Second, | ||
| 76 | + "组合时间" or "组合" or "combined" => AlertTemplateDurationUnit.Combined, | ||
| 77 | + _ => 0 | ||
| 78 | + }; | ||
| 79 | + return unit != 0; | ||
| 80 | + } | ||
| 81 | +} |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/FoodLabeling.Application.csproj
| @@ -42,6 +42,9 @@ | @@ -42,6 +42,9 @@ | ||
| 42 | <EmbeddedResource Include="..\scripts\fl_alert_template.sql"> | 42 | <EmbeddedResource Include="..\scripts\fl_alert_template.sql"> |
| 43 | <LogicalName>FoodLabeling.TenantMigrations.fl_alert_template.sql</LogicalName> | 43 | <LogicalName>FoodLabeling.TenantMigrations.fl_alert_template.sql</LogicalName> |
| 44 | </EmbeddedResource> | 44 | </EmbeddedResource> |
| 45 | + <EmbeddedResource Include="..\scripts\fl_alert_template_countdown.sql"> | ||
| 46 | + <LogicalName>FoodLabeling.TenantMigrations.fl_alert_template_countdown.sql</LogicalName> | ||
| 47 | + </EmbeddedResource> | ||
| 45 | <EmbeddedResource Include="..\scripts\fl_label_alert_timer_alert_template.sql"> | 48 | <EmbeddedResource Include="..\scripts\fl_label_alert_timer_alert_template.sql"> |
| 46 | <LogicalName>FoodLabeling.TenantMigrations.fl_label_alert_timer_alert_template.sql</LogicalName> | 49 | <LogicalName>FoodLabeling.TenantMigrations.fl_label_alert_timer_alert_template.sql</LogicalName> |
| 47 | </EmbeddedResource> | 50 | </EmbeddedResource> |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/AlertTemplateDurationHelper.cs
0 → 100644
| 1 | +using FoodLabeling.Application.Services.DbModels; | ||
| 2 | +using FoodLabeling.Domain.Shared.Enums; | ||
| 3 | +using Volo.Abp; | ||
| 4 | + | ||
| 5 | +namespace FoodLabeling.Application.Helpers; | ||
| 6 | + | ||
| 7 | +/// <summary>告警模板时长:单位 + 数字 → 到期时刻 / 秒数。</summary> | ||
| 8 | +public static class AlertTemplateDurationHelper | ||
| 9 | +{ | ||
| 10 | + public static DateTime AddTo(DateTime start, AlertTemplateDurationUnit unit, int value) | ||
| 11 | + { | ||
| 12 | + return unit switch | ||
| 13 | + { | ||
| 14 | + AlertTemplateDurationUnit.Year => start.AddYears(value), | ||
| 15 | + AlertTemplateDurationUnit.Month => start.AddMonths(value), | ||
| 16 | + AlertTemplateDurationUnit.Day => start.AddDays(value), | ||
| 17 | + AlertTemplateDurationUnit.Hour => start.AddHours(value), | ||
| 18 | + AlertTemplateDurationUnit.Minute => start.AddMinutes(value), | ||
| 19 | + AlertTemplateDurationUnit.Second => start.AddSeconds(value), | ||
| 20 | + AlertTemplateDurationUnit.Combined => start.AddSeconds(value), | ||
| 21 | + _ => throw new UserFriendlyException("durationUnit is invalid.") | ||
| 22 | + }; | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + public static int ToDurationSeconds(AlertTemplateDurationUnit unit, int value) | ||
| 26 | + { | ||
| 27 | + var now = DateTime.Now; | ||
| 28 | + var end = AddTo(now, unit, value); | ||
| 29 | + return Math.Max(1, (int)Math.Min(int.MaxValue, (end - now).TotalSeconds)); | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + public static int MaxValue(AlertTemplateDurationUnit unit) => | ||
| 33 | + unit switch | ||
| 34 | + { | ||
| 35 | + AlertTemplateDurationUnit.Year => 100, | ||
| 36 | + AlertTemplateDurationUnit.Month => 1200, | ||
| 37 | + AlertTemplateDurationUnit.Day => 3650, | ||
| 38 | + AlertTemplateDurationUnit.Hour => 87600, | ||
| 39 | + AlertTemplateDurationUnit.Minute => 5256000, | ||
| 40 | + AlertTemplateDurationUnit.Second => 365 * 24 * 3600, | ||
| 41 | + AlertTemplateDurationUnit.Combined => 365 * 24 * 3600, | ||
| 42 | + _ => 0 | ||
| 43 | + }; | ||
| 44 | + | ||
| 45 | + public static bool TryResolve( | ||
| 46 | + FlAlertTemplateDbEntity row, | ||
| 47 | + out AlertTemplateDurationUnit unit, | ||
| 48 | + out int value) | ||
| 49 | + { | ||
| 50 | + unit = default; | ||
| 51 | + value = 0; | ||
| 52 | + if (Enum.IsDefined(row.DurationUnit) && | ||
| 53 | + row.DurationUnit != 0 && | ||
| 54 | + row.DurationValue > 0) | ||
| 55 | + { | ||
| 56 | + unit = row.DurationUnit; | ||
| 57 | + value = row.DurationValue; | ||
| 58 | + return true; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + if (row.CountdownSeconds > 0) | ||
| 62 | + { | ||
| 63 | + unit = AlertTemplateDurationUnit.Second; | ||
| 64 | + value = row.CountdownSeconds; | ||
| 65 | + return true; | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + return false; | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + public static (AlertTemplateDurationUnit Unit, int Value) Resolve(FlAlertTemplateDbEntity row) | ||
| 72 | + { | ||
| 73 | + if (TryResolve(row, out var unit, out var value)) | ||
| 74 | + { | ||
| 75 | + return (unit, value); | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + throw new UserFriendlyException("Alert template duration is not configured."); | ||
| 79 | + } | ||
| 80 | +} |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/LabelAlertTimerWriteHelper.cs
| @@ -230,7 +230,7 @@ public static class LabelAlertTimerWriteHelper | @@ -230,7 +230,7 @@ public static class LabelAlertTimerWriteHelper | ||
| 230 | return elementName.Contains("到期提醒", StringComparison.Ordinal); | 230 | return elementName.Contains("到期提醒", StringComparison.Ordinal); |
| 231 | } | 231 | } |
| 232 | 232 | ||
| 233 | - private static async Task<string?> ResolveLocationNameAsync(ISqlSugarClient db, string locationId, CancellationToken ct) | 233 | + internal static async Task<string?> ResolveLocationNameAsync(ISqlSugarClient db, string locationId, CancellationToken ct) |
| 234 | { | 234 | { |
| 235 | if (string.IsNullOrWhiteSpace(locationId) || !Guid.TryParse(locationId, out var locGuid)) | 235 | if (string.IsNullOrWhiteSpace(locationId) || !Guid.TryParse(locationId, out var locGuid)) |
| 236 | { | 236 | { |
| @@ -300,13 +300,13 @@ public static class LabelAlertTimerWriteHelper | @@ -300,13 +300,13 @@ public static class LabelAlertTimerWriteHelper | ||
| 300 | return string.IsNullOrWhiteSpace(user.UserName) ? null : user.UserName.Trim(); | 300 | return string.IsNullOrWhiteSpace(user.UserName) ? null : user.UserName.Trim(); |
| 301 | } | 301 | } |
| 302 | 302 | ||
| 303 | - private static string BuildTitle(string labelName, int durationSeconds) | 303 | + internal static string BuildTitle(string labelName, int durationSeconds) |
| 304 | { | 304 | { |
| 305 | var hoursText = FormatDurationHoursLabel(durationSeconds); | 305 | var hoursText = FormatDurationHoursLabel(durationSeconds); |
| 306 | return string.IsNullOrWhiteSpace(hoursText) ? labelName : $"{labelName} ({hoursText})"; | 306 | return string.IsNullOrWhiteSpace(hoursText) ? labelName : $"{labelName} ({hoursText})"; |
| 307 | } | 307 | } |
| 308 | 308 | ||
| 309 | - private static string BuildSubtitle(int durationSeconds, DateTime expiresAt) | 309 | + internal static string BuildSubtitle(int durationSeconds, DateTime expiresAt) |
| 310 | { | 310 | { |
| 311 | var hoursText = FormatDurationHoursLabel(durationSeconds); | 311 | var hoursText = FormatDurationHoursLabel(durationSeconds); |
| 312 | var timeText = expiresAt.ToString("h:mm tt", CultureInfo.CurrentCulture); | 312 | var timeText = expiresAt.ToString("h:mm tt", CultureInfo.CurrentCulture); |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/MultiTenancy/FoodLabelingTenantMigrationScriptNames.cs
| @@ -28,6 +28,9 @@ public static class FoodLabelingTenantMigrationScriptNames | @@ -28,6 +28,9 @@ public static class FoodLabelingTenantMigrationScriptNames | ||
| 28 | 28 | ||
| 29 | public const string AlertTemplate = "FoodLabeling.TenantMigrations.fl_alert_template.sql"; | 29 | public const string AlertTemplate = "FoodLabeling.TenantMigrations.fl_alert_template.sql"; |
| 30 | 30 | ||
| 31 | + public const string AlertTemplateCountdown = | ||
| 32 | + "FoodLabeling.TenantMigrations.fl_alert_template_countdown.sql"; | ||
| 33 | + | ||
| 31 | public const string LabelAlertTimerAlertTemplate = | 34 | public const string LabelAlertTimerAlertTemplate = |
| 32 | "FoodLabeling.TenantMigrations.fl_label_alert_timer_alert_template.sql"; | 35 | "FoodLabeling.TenantMigrations.fl_label_alert_timer_alert_template.sql"; |
| 33 | 36 | ||
| @@ -48,6 +51,7 @@ public static class FoodLabelingTenantMigrationScriptNames | @@ -48,6 +51,7 @@ public static class FoodLabelingTenantMigrationScriptNames | ||
| 48 | LabelAlertTimer, | 51 | LabelAlertTimer, |
| 49 | BoundLabel, | 52 | BoundLabel, |
| 50 | AlertTemplate, | 53 | AlertTemplate, |
| 54 | + AlertTemplateCountdown, | ||
| 51 | LabelAlertTimerAlertTemplate, | 55 | LabelAlertTimerAlertTemplate, |
| 52 | MenuHidePlatformQrCodes | 56 | MenuHidePlatformQrCodes |
| 53 | ]; | 57 | ]; |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/MultiTenancy/TenantSqlScriptExecutor.cs
| 1 | -using System.Text; | 1 | +using System.Text; |
| 2 | using System.Text.RegularExpressions; | 2 | using System.Text.RegularExpressions; |
| 3 | using MySqlConnector; | 3 | using MySqlConnector; |
| 4 | using SqlSugar; | 4 | using SqlSugar; |
| @@ -45,6 +45,10 @@ public static class TenantSqlScriptExecutor | @@ -45,6 +45,10 @@ public static class TenantSqlScriptExecutor | ||
| 45 | { | 45 | { |
| 46 | await command.ExecuteNonQueryAsync(cancellationToken); | 46 | await command.ExecuteNonQueryAsync(cancellationToken); |
| 47 | } | 47 | } |
| 48 | + catch (MySqlException ex) when (ex.Number is 1060 or 1061) | ||
| 49 | + { | ||
| 50 | + // 1060 Duplicate column;1061 Duplicate key。幂等 ALTER 可忽略。 | ||
| 51 | + } | ||
| 48 | catch (MySqlException ex) | 52 | catch (MySqlException ex) |
| 49 | { | 53 | { |
| 50 | throw new InvalidOperationException( | 54 | throw new InvalidOperationException( |
| @@ -81,7 +85,8 @@ public static class TenantSqlScriptExecutor | @@ -81,7 +85,8 @@ public static class TenantSqlScriptExecutor | ||
| 81 | var trimmed = line.Trim(); | 85 | var trimmed = line.Trim(); |
| 82 | if (PrepareBlockEndRegex.IsMatch(trimmed) | 86 | if (PrepareBlockEndRegex.IsMatch(trimmed) |
| 83 | || CreateTableEndRegex.IsMatch(trimmed) | 87 | || CreateTableEndRegex.IsMatch(trimmed) |
| 84 | - || (trimmed.StartsWith("UPDATE ", StringComparison.OrdinalIgnoreCase) && trimmed.EndsWith(';'))) | 88 | + || (trimmed.StartsWith("UPDATE ", StringComparison.OrdinalIgnoreCase) && trimmed.EndsWith(';')) |
| 89 | + || (trimmed.StartsWith("ALTER ", StringComparison.OrdinalIgnoreCase) && trimmed.EndsWith(';'))) | ||
| 85 | { | 90 | { |
| 86 | var batch = current.ToString().Trim(); | 91 | var batch = current.ToString().Trim(); |
| 87 | if (!string.IsNullOrEmpty(batch)) | 92 | if (!string.IsNullOrEmpty(batch)) |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/AlertTemplateAppService.cs
| @@ -3,6 +3,7 @@ using FoodLabeling.Application.Contracts.Dtos.Common; | @@ -3,6 +3,7 @@ using FoodLabeling.Application.Contracts.Dtos.Common; | ||
| 3 | using FoodLabeling.Application.Contracts.IServices; | 3 | using FoodLabeling.Application.Contracts.IServices; |
| 4 | using FoodLabeling.Application.Helpers; | 4 | using FoodLabeling.Application.Helpers; |
| 5 | using FoodLabeling.Application.Services.DbModels; | 5 | using FoodLabeling.Application.Services.DbModels; |
| 6 | +using FoodLabeling.Domain.Shared.Enums; | ||
| 6 | using FoodLabeling.Domain.Shared.Helpers; | 7 | using FoodLabeling.Domain.Shared.Helpers; |
| 7 | using Microsoft.AspNetCore.Authorization; | 8 | using Microsoft.AspNetCore.Authorization; |
| 8 | using Microsoft.AspNetCore.Mvc; | 9 | using Microsoft.AspNetCore.Mvc; |
| @@ -14,7 +15,7 @@ using Yi.Framework.SqlSugarCore.Abstractions; | @@ -14,7 +15,7 @@ using Yi.Framework.SqlSugarCore.Abstractions; | ||
| 14 | namespace FoodLabeling.Application.Services; | 15 | namespace FoodLabeling.Application.Services; |
| 15 | 16 | ||
| 16 | /// <summary> | 17 | /// <summary> |
| 17 | -/// 告警日期时间格式模板(平台告警页 / 标签模板到期提醒下拉) | 18 | +/// 告警模板(倒计时秒数;平台告警页 / 手动新增计时器) |
| 18 | /// </summary> | 19 | /// </summary> |
| 19 | [Authorize] | 20 | [Authorize] |
| 20 | public class AlertTemplateAppService : ApplicationService, IAlertTemplateAppService | 21 | public class AlertTemplateAppService : ApplicationService, IAlertTemplateAppService |
| @@ -57,6 +58,7 @@ public class AlertTemplateAppService : ApplicationService, IAlertTemplateAppServ | @@ -57,6 +58,7 @@ public class AlertTemplateAppService : ApplicationService, IAlertTemplateAppServ | ||
| 57 | [Route("/api/app/alert-template/list")] | 58 | [Route("/api/app/alert-template/list")] |
| 58 | public async Task<PagedResultWithPageDto<AlertTemplateDto>> ListAsync(AlertTemplateGetListInputVo input) | 59 | public async Task<PagedResultWithPageDto<AlertTemplateDto>> ListAsync(AlertTemplateGetListInputVo input) |
| 59 | { | 60 | { |
| 61 | + await EnsureCountdownColumnAsync(_dbContext.SqlSugarClient); | ||
| 60 | input ??= new AlertTemplateGetListInputVo(); | 62 | input ??= new AlertTemplateGetListInputVo(); |
| 61 | var keyword = input.Keyword?.Trim(); | 63 | var keyword = input.Keyword?.Trim(); |
| 62 | RefAsync<int> total = 0; | 64 | RefAsync<int> total = 0; |
| @@ -97,6 +99,7 @@ public class AlertTemplateAppService : ApplicationService, IAlertTemplateAppServ | @@ -97,6 +99,7 @@ public class AlertTemplateAppService : ApplicationService, IAlertTemplateAppServ | ||
| 97 | [Route("/api/app/alert-template/{id}")] | 99 | [Route("/api/app/alert-template/{id}")] |
| 98 | public async Task<AlertTemplateDto> GetAsync(string id) | 100 | public async Task<AlertTemplateDto> GetAsync(string id) |
| 99 | { | 101 | { |
| 102 | + await EnsureCountdownColumnAsync(_dbContext.SqlSugarClient); | ||
| 100 | var entity = await FindActiveAsync(id); | 103 | var entity = await FindActiveAsync(id); |
| 101 | return MapDto(entity); | 104 | return MapDto(entity); |
| 102 | } | 105 | } |
| @@ -108,15 +111,17 @@ public class AlertTemplateAppService : ApplicationService, IAlertTemplateAppServ | @@ -108,15 +111,17 @@ public class AlertTemplateAppService : ApplicationService, IAlertTemplateAppServ | ||
| 108 | /// 示例请求: | 111 | /// 示例请求: |
| 109 | /// ```json | 112 | /// ```json |
| 110 | /// { | 113 | /// { |
| 111 | - /// "templateName": "US 过期展示", | ||
| 112 | - /// "dateTimeFormat": "MM/dd/yyyy h:mm tt", | 114 | + /// "templateName": "冷藏 3 日", |
| 115 | + /// "durationUnit": "Day", | ||
| 116 | + /// "durationValue": 3, | ||
| 113 | /// "state": true | 117 | /// "state": true |
| 114 | /// } | 118 | /// } |
| 115 | /// ``` | 119 | /// ``` |
| 116 | /// | 120 | /// |
| 117 | /// 参数说明: | 121 | /// 参数说明: |
| 118 | /// - templateName: 模板名称 | 122 | /// - templateName: 模板名称 |
| 119 | - /// - dateTimeFormat: 日期时间格式字符串(原样存储,用于 formattedExpiresAt) | 123 | + /// - durationUnit: 年/月/日/时/分/秒/组合时间(或 Year/Month/Day/Hour/Minute/Second/Combined) |
| 124 | + /// - durationValue: 数字,与单位组合成 3年、3月、3日;组合时间为总秒数 | ||
| 120 | /// - state: 是否启用 | 125 | /// - state: 是否启用 |
| 121 | /// </remarks> | 126 | /// </remarks> |
| 122 | /// <param name="input">模板字段</param> | 127 | /// <param name="input">模板字段</param> |
| @@ -128,13 +133,17 @@ public class AlertTemplateAppService : ApplicationService, IAlertTemplateAppServ | @@ -128,13 +133,17 @@ public class AlertTemplateAppService : ApplicationService, IAlertTemplateAppServ | ||
| 128 | [Route("/api/app/alert-template")] | 133 | [Route("/api/app/alert-template")] |
| 129 | public async Task<AlertTemplateDto> CreateAsync(AlertTemplateCreateInputVo input) | 134 | public async Task<AlertTemplateDto> CreateAsync(AlertTemplateCreateInputVo input) |
| 130 | { | 135 | { |
| 131 | - var (name, format) = ValidateInput(input); | 136 | + await EnsureCountdownColumnAsync(_dbContext.SqlSugarClient); |
| 137 | + var (name, unit, value, seconds) = ValidateInput(input); | ||
| 132 | var now = DateTime.Now; | 138 | var now = DateTime.Now; |
| 133 | var entity = new FlAlertTemplateDbEntity | 139 | var entity = new FlAlertTemplateDbEntity |
| 134 | { | 140 | { |
| 135 | Id = YitIdHelper.NextId().ToString(), | 141 | Id = YitIdHelper.NextId().ToString(), |
| 136 | TemplateName = name, | 142 | TemplateName = name, |
| 137 | - DateTimeFormat = format, | 143 | + DurationUnit = unit, |
| 144 | + DurationValue = value, | ||
| 145 | + CountdownSeconds = seconds, | ||
| 146 | + DateTimeFormat = seconds.ToString(), | ||
| 138 | State = input.State, | 147 | State = input.State, |
| 139 | IsDeleted = false, | 148 | IsDeleted = false, |
| 140 | CreatedBy = CurrentUser?.Id?.ToString(), | 149 | CreatedBy = CurrentUser?.Id?.ToString(), |
| @@ -161,10 +170,14 @@ public class AlertTemplateAppService : ApplicationService, IAlertTemplateAppServ | @@ -161,10 +170,14 @@ public class AlertTemplateAppService : ApplicationService, IAlertTemplateAppServ | ||
| 161 | [Route("/api/app/alert-template/{id}")] | 170 | [Route("/api/app/alert-template/{id}")] |
| 162 | public async Task<AlertTemplateDto> UpdateAsync(string id, AlertTemplateCreateInputVo input) | 171 | public async Task<AlertTemplateDto> UpdateAsync(string id, AlertTemplateCreateInputVo input) |
| 163 | { | 172 | { |
| 173 | + await EnsureCountdownColumnAsync(_dbContext.SqlSugarClient); | ||
| 164 | var entity = await FindActiveAsync(id); | 174 | var entity = await FindActiveAsync(id); |
| 165 | - var (name, format) = ValidateInput(input); | 175 | + var (name, unit, value, seconds) = ValidateInput(input); |
| 166 | entity.TemplateName = name; | 176 | entity.TemplateName = name; |
| 167 | - entity.DateTimeFormat = format; | 177 | + entity.DurationUnit = unit; |
| 178 | + entity.DurationValue = value; | ||
| 179 | + entity.CountdownSeconds = seconds; | ||
| 180 | + entity.DateTimeFormat = seconds.ToString(); | ||
| 168 | entity.State = input.State; | 181 | entity.State = input.State; |
| 169 | entity.LastModificationTime = DateTime.Now; | 182 | entity.LastModificationTime = DateTime.Now; |
| 170 | await _dbContext.SqlSugarClient.Updateable(entity).ExecuteCommandAsync(); | 183 | await _dbContext.SqlSugarClient.Updateable(entity).ExecuteCommandAsync(); |
| @@ -193,23 +206,29 @@ public class AlertTemplateAppService : ApplicationService, IAlertTemplateAppServ | @@ -193,23 +206,29 @@ public class AlertTemplateAppService : ApplicationService, IAlertTemplateAppServ | ||
| 193 | /// <summary> | 206 | /// <summary> |
| 194 | /// 启用中的告警模板下拉(标签模板编辑器到期提醒) | 207 | /// 启用中的告警模板下拉(标签模板编辑器到期提醒) |
| 195 | /// </summary> | 208 | /// </summary> |
| 196 | - /// <returns>id / templateName / dateTimeFormat</returns> | 209 | + /// <returns>id / templateName / durationUnit / durationValue</returns> |
| 197 | /// <response code="200">成功</response> | 210 | /// <response code="200">成功</response> |
| 198 | /// <response code="500">服务器错误</response> | 211 | /// <response code="500">服务器错误</response> |
| 199 | [HttpGet] | 212 | [HttpGet] |
| 200 | [Route("/api/app/alert-template/options")] | 213 | [Route("/api/app/alert-template/options")] |
| 201 | public async Task<List<AlertTemplateOptionDto>> GetOptionsAsync() | 214 | public async Task<List<AlertTemplateOptionDto>> GetOptionsAsync() |
| 202 | { | 215 | { |
| 216 | + await EnsureCountdownColumnAsync(_dbContext.SqlSugarClient); | ||
| 203 | var rows = await _dbContext.SqlSugarClient.Queryable<FlAlertTemplateDbEntity>() | 217 | var rows = await _dbContext.SqlSugarClient.Queryable<FlAlertTemplateDbEntity>() |
| 204 | .Where(x => !x.IsDeleted && x.State) | 218 | .Where(x => !x.IsDeleted && x.State) |
| 205 | .OrderByDescending(x => x.LastModificationTime) | 219 | .OrderByDescending(x => x.LastModificationTime) |
| 206 | .OrderByDescending(x => x.CreationTime) | 220 | .OrderByDescending(x => x.CreationTime) |
| 207 | .ToListAsync(); | 221 | .ToListAsync(); |
| 208 | - return rows.Select(x => new AlertTemplateOptionDto | 222 | + return rows.Select(x => |
| 209 | { | 223 | { |
| 210 | - Id = x.Id, | ||
| 211 | - TemplateName = x.TemplateName, | ||
| 212 | - DateTimeFormat = x.DateTimeFormat | 224 | + AlertTemplateDurationHelper.TryResolve(x, out var unit, out var value); |
| 225 | + return new AlertTemplateOptionDto | ||
| 226 | + { | ||
| 227 | + Id = x.Id, | ||
| 228 | + TemplateName = x.TemplateName, | ||
| 229 | + DurationUnit = unit, | ||
| 230 | + DurationValue = value | ||
| 231 | + }; | ||
| 213 | }).ToList(); | 232 | }).ToList(); |
| 214 | } | 233 | } |
| 215 | 234 | ||
| @@ -231,7 +250,50 @@ public class AlertTemplateAppService : ApplicationService, IAlertTemplateAppServ | @@ -231,7 +250,50 @@ public class AlertTemplateAppService : ApplicationService, IAlertTemplateAppServ | ||
| 231 | return entity; | 250 | return entity; |
| 232 | } | 251 | } |
| 233 | 252 | ||
| 234 | - private static (string Name, string Format) ValidateInput(AlertTemplateCreateInputVo? input) | 253 | + private static int _countdownColumnEnsured; |
| 254 | + | ||
| 255 | + internal static async Task EnsureCountdownColumnAsync(ISqlSugarClient db) | ||
| 256 | + { | ||
| 257 | + if (Volatile.Read(ref _countdownColumnEnsured) == 1) | ||
| 258 | + { | ||
| 259 | + return; | ||
| 260 | + } | ||
| 261 | + | ||
| 262 | + try | ||
| 263 | + { | ||
| 264 | + await db.Ado.ExecuteCommandAsync( | ||
| 265 | + "ALTER TABLE `fl_alert_template` ADD COLUMN `CountdownSeconds` int NOT NULL DEFAULT 0 COMMENT '倒计时秒数'"); | ||
| 266 | + } | ||
| 267 | + catch | ||
| 268 | + { | ||
| 269 | + // 列已存在 | ||
| 270 | + } | ||
| 271 | + | ||
| 272 | + try | ||
| 273 | + { | ||
| 274 | + await db.Ado.ExecuteCommandAsync( | ||
| 275 | + "ALTER TABLE `fl_alert_template` ADD COLUMN `DurationUnit` int NOT NULL DEFAULT 6 COMMENT '时长单位'"); | ||
| 276 | + } | ||
| 277 | + catch | ||
| 278 | + { | ||
| 279 | + // 列已存在 | ||
| 280 | + } | ||
| 281 | + | ||
| 282 | + try | ||
| 283 | + { | ||
| 284 | + await db.Ado.ExecuteCommandAsync( | ||
| 285 | + "ALTER TABLE `fl_alert_template` ADD COLUMN `DurationValue` int NOT NULL DEFAULT 0 COMMENT '时长数字'"); | ||
| 286 | + } | ||
| 287 | + catch | ||
| 288 | + { | ||
| 289 | + // 列已存在 | ||
| 290 | + } | ||
| 291 | + | ||
| 292 | + Volatile.Write(ref _countdownColumnEnsured, 1); | ||
| 293 | + } | ||
| 294 | + | ||
| 295 | + private static (string Name, AlertTemplateDurationUnit Unit, int Value, int Seconds) | ||
| 296 | + ValidateInput(AlertTemplateCreateInputVo? input) | ||
| 235 | { | 297 | { |
| 236 | if (input is null) | 298 | if (input is null) |
| 237 | { | 299 | { |
| @@ -244,23 +306,33 @@ public class AlertTemplateAppService : ApplicationService, IAlertTemplateAppServ | @@ -244,23 +306,33 @@ public class AlertTemplateAppService : ApplicationService, IAlertTemplateAppServ | ||
| 244 | throw new UserFriendlyException("Template name is required."); | 306 | throw new UserFriendlyException("Template name is required."); |
| 245 | } | 307 | } |
| 246 | 308 | ||
| 247 | - var format = input.DateTimeFormat?.Trim(); | ||
| 248 | - if (string.IsNullOrWhiteSpace(format)) | 309 | + if (!Enum.IsDefined(input.DurationUnit) || input.DurationUnit == 0) |
| 249 | { | 310 | { |
| 250 | - throw new UserFriendlyException("Date/time format is required."); | 311 | + throw new UserFriendlyException("durationUnit is required (Year/Month/Day/Hour/Minute/Second/Combined)."); |
| 251 | } | 312 | } |
| 252 | 313 | ||
| 253 | - return (name, format); | 314 | + var max = AlertTemplateDurationHelper.MaxValue(input.DurationUnit); |
| 315 | + if (input.DurationValue <= 0 || input.DurationValue > max) | ||
| 316 | + { | ||
| 317 | + throw new UserFriendlyException($"durationValue must be between 1 and {max}."); | ||
| 318 | + } | ||
| 319 | + | ||
| 320 | + var seconds = AlertTemplateDurationHelper.ToDurationSeconds(input.DurationUnit, input.DurationValue); | ||
| 321 | + return (name, input.DurationUnit, input.DurationValue, seconds); | ||
| 254 | } | 322 | } |
| 255 | 323 | ||
| 256 | - private static AlertTemplateDto MapDto(FlAlertTemplateDbEntity x) => | ||
| 257 | - new() | 324 | + private static AlertTemplateDto MapDto(FlAlertTemplateDbEntity x) |
| 325 | + { | ||
| 326 | + AlertTemplateDurationHelper.TryResolve(x, out var unit, out var value); | ||
| 327 | + return new AlertTemplateDto | ||
| 258 | { | 328 | { |
| 259 | Id = x.Id, | 329 | Id = x.Id, |
| 260 | TemplateName = x.TemplateName, | 330 | TemplateName = x.TemplateName, |
| 261 | - DateTimeFormat = x.DateTimeFormat, | 331 | + DurationUnit = unit, |
| 332 | + DurationValue = value, | ||
| 262 | State = x.State, | 333 | State = x.State, |
| 263 | CreationTime = x.CreationTime, | 334 | CreationTime = x.CreationTime, |
| 264 | LastModificationTime = x.LastModificationTime | 335 | LastModificationTime = x.LastModificationTime |
| 265 | }; | 336 | }; |
| 337 | + } | ||
| 266 | } | 338 | } |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/DbModels/FlAlertTemplateDbEntity.cs
| 1 | +using FoodLabeling.Domain.Shared.Enums; | ||
| 1 | using SqlSugar; | 2 | using SqlSugar; |
| 2 | 3 | ||
| 3 | namespace FoodLabeling.Application.Services.DbModels; | 4 | namespace FoodLabeling.Application.Services.DbModels; |
| 4 | 5 | ||
| 5 | -/// <summary>告警日期时间格式模板(<c>fl_alert_template</c>)</summary> | 6 | +/// <summary>告警模板(<c>fl_alert_template</c>):时长单位 + 数字</summary> |
| 6 | [SugarTable("fl_alert_template")] | 7 | [SugarTable("fl_alert_template")] |
| 7 | public class FlAlertTemplateDbEntity | 8 | public class FlAlertTemplateDbEntity |
| 8 | { | 9 | { |
| @@ -11,6 +12,16 @@ public class FlAlertTemplateDbEntity | @@ -11,6 +12,16 @@ public class FlAlertTemplateDbEntity | ||
| 11 | 12 | ||
| 12 | public string TemplateName { get; set; } = string.Empty; | 13 | public string TemplateName { get; set; } = string.Empty; |
| 13 | 14 | ||
| 15 | + /// <summary>时长单位,见 <see cref="AlertTemplateDurationUnit"/></summary> | ||
| 16 | + public AlertTemplateDurationUnit DurationUnit { get; set; } | ||
| 17 | + | ||
| 18 | + /// <summary>时长数字(与单位组合成 3年、3日等)</summary> | ||
| 19 | + public int DurationValue { get; set; } | ||
| 20 | + | ||
| 21 | + /// <summary>换算后的倒计时秒数(创建计时器展示用)</summary> | ||
| 22 | + public int CountdownSeconds { get; set; } | ||
| 23 | + | ||
| 24 | + /// <summary>历史列,保留兼容。</summary> | ||
| 14 | public string DateTimeFormat { get; set; } = string.Empty; | 25 | public string DateTimeFormat { get; set; } = string.Empty; |
| 15 | 26 | ||
| 16 | public bool State { get; set; } = true; | 27 | public bool State { get; set; } = true; |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelAlertTimerAppService.cs
| @@ -5,6 +5,8 @@ using FoodLabeling.Application.Helpers; | @@ -5,6 +5,8 @@ using FoodLabeling.Application.Helpers; | ||
| 5 | using FoodLabeling.Application.Services.DbModels; | 5 | using FoodLabeling.Application.Services.DbModels; |
| 6 | using FoodLabeling.Domain.Entities; | 6 | using FoodLabeling.Domain.Entities; |
| 7 | using FoodLabeling.Domain.Shared; | 7 | using FoodLabeling.Domain.Shared; |
| 8 | +using FoodLabeling.Domain.Shared.Enums; | ||
| 9 | +using FoodLabeling.Domain.Shared.Helpers; | ||
| 8 | using Microsoft.AspNetCore.Authorization; | 10 | using Microsoft.AspNetCore.Authorization; |
| 9 | using Microsoft.AspNetCore.Mvc; | 11 | using Microsoft.AspNetCore.Mvc; |
| 10 | using Microsoft.Extensions.Caching.Distributed; | 12 | using Microsoft.Extensions.Caching.Distributed; |
| @@ -58,7 +60,8 @@ public class LabelAlertTimerAppService : ApplicationService, ILabelAlertTimerApp | @@ -58,7 +60,8 @@ public class LabelAlertTimerAppService : ApplicationService, ILabelAlertTimerApp | ||
| 58 | /// <response code="400">参数错误或You are not signed in./无门店权限</response> | 60 | /// <response code="400">参数错误或You are not signed in./无门店权限</response> |
| 59 | /// <response code="500">服务器错误</response> | 61 | /// <response code="500">服务器错误</response> |
| 60 | [Authorize] | 62 | [Authorize] |
| 61 | - [HttpPost("label-alert-timer/list")] | 63 | + [HttpPost] |
| 64 | + [Route("/api/app/label-alert-timer/list")] | ||
| 62 | public virtual async Task<PagedResultWithPageDto<LabelAlertTimerListItemDto>> GetListAsync( | 65 | public virtual async Task<PagedResultWithPageDto<LabelAlertTimerListItemDto>> GetListAsync( |
| 63 | LabelAlertTimerGetListInputVo input) | 66 | LabelAlertTimerGetListInputVo input) |
| 64 | { | 67 | { |
| @@ -91,6 +94,152 @@ public class LabelAlertTimerAppService : ApplicationService, ILabelAlertTimerApp | @@ -91,6 +94,152 @@ public class LabelAlertTimerAppService : ApplicationService, ILabelAlertTimerApp | ||
| 91 | } | 94 | } |
| 92 | 95 | ||
| 93 | /// <summary> | 96 | /// <summary> |
| 97 | + /// 按告警模板手动新增计时器(Web / App 共用) | ||
| 98 | + /// </summary> | ||
| 99 | + /// <remarks> | ||
| 100 | + /// 读取模板时长(单位 + 数字,如 3 日),从当前时刻起倒计时,写入 <c>fl_label_alert_timer</c>(无需新表), | ||
| 101 | + /// 随后会出现在 list / app-list。 | ||
| 102 | + /// | ||
| 103 | + /// 示例请求: | ||
| 104 | + /// ```json | ||
| 105 | + /// { | ||
| 106 | + /// "alertTemplateId": "123456789", | ||
| 107 | + /// "locationId": "3a2473aa-98f1-e2ab-b50a-2efcb8bfdb54" | ||
| 108 | + /// } | ||
| 109 | + /// ``` | ||
| 110 | + /// | ||
| 111 | + /// 参数说明: | ||
| 112 | + /// - alertTemplateId: 启用中的告警模板 Id | ||
| 113 | + /// - locationId: 门店;空则取已选门店缓存 | ||
| 114 | + /// </remarks> | ||
| 115 | + /// <param name="input">模板与门店</param> | ||
| 116 | + /// <returns>新建计时器(含 remainingTime)</returns> | ||
| 117 | + /// <response code="200">成功</response> | ||
| 118 | + /// <response code="400">未登录、模板无效、未选门店</response> | ||
| 119 | + /// <response code="500">服务器错误</response> | ||
| 120 | + [Authorize] | ||
| 121 | + [HttpPost] | ||
| 122 | + [Route("/api/app/label-alert-timer/create")] | ||
| 123 | + [Route("/api/app/label-alert-timer")] | ||
| 124 | + public virtual async Task<LabelAlertTimerListItemDto> CreateAsync(LabelAlertTimerCreateInputVo input) | ||
| 125 | + { | ||
| 126 | + if (input is null) | ||
| 127 | + { | ||
| 128 | + throw new UserFriendlyException("Request body is required."); | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + if (!CurrentUser.Id.HasValue) | ||
| 132 | + { | ||
| 133 | + throw new UserFriendlyException("You are not signed in."); | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + var templateId = input.AlertTemplateId?.Trim(); | ||
| 137 | + if (string.IsNullOrWhiteSpace(templateId)) | ||
| 138 | + { | ||
| 139 | + throw new UserFriendlyException("Alert template Id is required."); | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | + var db = _dbContext.SqlSugarClient; | ||
| 143 | + await AlertTemplateAppService.EnsureCountdownColumnAsync(db); | ||
| 144 | + var template = (await db.Queryable<FlAlertTemplateDbEntity>() | ||
| 145 | + .Where(x => x.Id == templateId && !x.IsDeleted && x.State) | ||
| 146 | + .Take(1) | ||
| 147 | + .ToListAsync()) | ||
| 148 | + .FirstOrDefault(); | ||
| 149 | + if (template is null) | ||
| 150 | + { | ||
| 151 | + throw new UserFriendlyException("Alert template not found or disabled."); | ||
| 152 | + } | ||
| 153 | + | ||
| 154 | + var (unit, value) = AlertTemplateDurationHelper.Resolve(template); | ||
| 155 | + var now = DateTime.Now; | ||
| 156 | + var expiresAt = AlertTemplateDurationHelper.AddTo(now, unit, value); | ||
| 157 | + var countdown = Math.Max(1, (int)Math.Min(int.MaxValue, (expiresAt - now).TotalSeconds)); | ||
| 158 | + | ||
| 159 | + var locationId = input.LocationId?.Trim(); | ||
| 160 | + if (string.IsNullOrWhiteSpace(locationId)) | ||
| 161 | + { | ||
| 162 | + var cache = await UsAppAuthScopeHelper.GetAdminScopeCacheAsync( | ||
| 163 | + _distributedCache, | ||
| 164 | + CurrentUser.Id.Value); | ||
| 165 | + locationId = cache?.Location?.Id?.Trim(); | ||
| 166 | + } | ||
| 167 | + | ||
| 168 | + if (string.IsNullOrWhiteSpace(locationId)) | ||
| 169 | + { | ||
| 170 | + throw new UserFriendlyException("Select a location or pass locationId."); | ||
| 171 | + } | ||
| 172 | + | ||
| 173 | + await UsAppPrintLogScopeHelper.EnsureUserCanAccessLocationAsync( | ||
| 174 | + CurrentUser, db, locationId); | ||
| 175 | + | ||
| 176 | + var locationName = await LabelAlertTimerWriteHelper.ResolveLocationNameAsync( | ||
| 177 | + db, locationId, CancellationToken.None); | ||
| 178 | + var labelName = string.IsNullOrWhiteSpace(template.TemplateName) | ||
| 179 | + ? FoodLabelingDisplayConsts.NotAvailable | ||
| 180 | + : template.TemplateName.Trim(); | ||
| 181 | + var userId = CurrentUser.Id.Value.ToString(); | ||
| 182 | + var timerId = YitIdHelper.NextId().ToString(); | ||
| 183 | + var entity = new FlLabelAlertTimerDbEntity | ||
| 184 | + { | ||
| 185 | + Id = timerId, | ||
| 186 | + BatchId = timerId, | ||
| 187 | + PrintTaskId = string.Empty, | ||
| 188 | + LabelId = string.Empty, | ||
| 189 | + LabelName = labelName, | ||
| 190 | + LocationId = locationId, | ||
| 191 | + LocationName = locationName, | ||
| 192 | + PrintedAt = now, | ||
| 193 | + BaseTime = now, | ||
| 194 | + ExpiresAt = expiresAt, | ||
| 195 | + DurationSeconds = countdown, | ||
| 196 | + Title = LabelAlertTimerWriteHelper.BuildTitle(labelName, countdown), | ||
| 197 | + Subtitle = LabelAlertTimerWriteHelper.BuildSubtitle(countdown, expiresAt), | ||
| 198 | + AlertTemplateId = template.Id, | ||
| 199 | + AlertTemplateName = template.TemplateName, | ||
| 200 | + DateTimeFormat = ReportsDateTimeDisplayHelper.DateTimeDisplayFormat, | ||
| 201 | + PrintedByUserId = userId, | ||
| 202 | + PrintedByUserName = CurrentUser.UserName, | ||
| 203 | + IsDeleted = false, | ||
| 204 | + CreatedBy = userId, | ||
| 205 | + CreationTime = now | ||
| 206 | + }; | ||
| 207 | + await db.Insertable(entity).ExecuteCommandAsync(); | ||
| 208 | + var dto = MapListItem(entity, now); | ||
| 209 | + dto.Source = nameof(LabelAlertTimerSource.Manual).ToLowerInvariant(); | ||
| 210 | + return dto; | ||
| 211 | + } | ||
| 212 | + | ||
| 213 | + /// <summary> | ||
| 214 | + /// App:按模板 Id 路径新增计时器(兼容 POST /label-alert-timer/{templateId}) | ||
| 215 | + /// </summary> | ||
| 216 | + /// <remarks> | ||
| 217 | + /// 与 <c>/create</c> 相同逻辑;路径上的数字 Id 作为 <c>alertTemplateId</c>。 | ||
| 218 | + /// 避免该 POST 命中 DELETE <c>{id}</c> 后返回 405。 | ||
| 219 | + /// </remarks> | ||
| 220 | + /// <param name="alertTemplateId">告警模板 Id(YitId)</param> | ||
| 221 | + /// <param name="input">可选 body,可带 locationId</param> | ||
| 222 | + /// <returns>新建计时器</returns> | ||
| 223 | + /// <response code="200">成功</response> | ||
| 224 | + /// <response code="400">未登录、模板无效、未选门店</response> | ||
| 225 | + /// <response code="500">服务器错误</response> | ||
| 226 | + [Authorize] | ||
| 227 | + [HttpPost] | ||
| 228 | + [Route("/api/app/label-alert-timer/{alertTemplateId:regex(^\\d+$)}")] | ||
| 229 | + public virtual Task<LabelAlertTimerListItemDto> CreateByTemplateIdAsync( | ||
| 230 | + string alertTemplateId, | ||
| 231 | + [FromBody] LabelAlertTimerCreateInputVo? input) | ||
| 232 | + { | ||
| 233 | + input ??= new LabelAlertTimerCreateInputVo(); | ||
| 234 | + if (string.IsNullOrWhiteSpace(input.AlertTemplateId)) | ||
| 235 | + { | ||
| 236 | + input.AlertTemplateId = alertTemplateId; | ||
| 237 | + } | ||
| 238 | + | ||
| 239 | + return CreateAsync(input); | ||
| 240 | + } | ||
| 241 | + | ||
| 242 | + /// <summary> | ||
| 94 | /// App:告警列表(含倒计时;筛选项为当前门店/公司,过期时间默认当天及之后) | 243 | /// App:告警列表(含倒计时;筛选项为当前门店/公司,过期时间默认当天及之后) |
| 95 | /// </summary> | 244 | /// </summary> |
| 96 | /// <remarks> | 245 | /// <remarks> |
| @@ -126,7 +275,8 @@ public class LabelAlertTimerAppService : ApplicationService, ILabelAlertTimerApp | @@ -126,7 +275,8 @@ public class LabelAlertTimerAppService : ApplicationService, ILabelAlertTimerApp | ||
| 126 | /// <response code="400">Not signed in, no locations, or no permission</response> | 275 | /// <response code="400">Not signed in, no locations, or no permission</response> |
| 127 | /// <response code="500">服务器错误</response> | 276 | /// <response code="500">服务器错误</response> |
| 128 | [Authorize] | 277 | [Authorize] |
| 129 | - [HttpPost("label-alert-timer/app-list")] | 278 | + [HttpPost] |
| 279 | + [Route("/api/app/label-alert-timer/app-list")] | ||
| 130 | public virtual async Task<PagedResultWithPageDto<LabelAlertTimerListItemDto>> AppListAsync( | 280 | public virtual async Task<PagedResultWithPageDto<LabelAlertTimerListItemDto>> AppListAsync( |
| 131 | LabelAlertTimerGetListInputVo input) | 281 | LabelAlertTimerGetListInputVo input) |
| 132 | { | 282 | { |
| @@ -174,14 +324,15 @@ public class LabelAlertTimerAppService : ApplicationService, ILabelAlertTimerApp | @@ -174,14 +324,15 @@ public class LabelAlertTimerAppService : ApplicationService, ILabelAlertTimerApp | ||
| 174 | /// </summary> | 324 | /// </summary> |
| 175 | /// <remarks> | 325 | /// <remarks> |
| 176 | /// 删除前校验当前用户可访问该计时器所属门店。 | 326 | /// 删除前校验当前用户可访问该计时器所属门店。 |
| 177 | - /// id 路由约束为数字(YitId),避免 <c>app-list</c> 等字面路径被 <c>{id}</c> 匹配后对 POST 返回 405。 | 327 | + /// id 仅匹配数字(YitId),避免 <c>create</c> / <c>app-list</c> 被 <c>{id}</c> 吃掉后对 POST 返回 405。 |
| 178 | /// </remarks> | 328 | /// </remarks> |
| 179 | /// <param name="id">计时器 Id</param> | 329 | /// <param name="id">计时器 Id</param> |
| 180 | /// <response code="200">删除成功</response> | 330 | /// <response code="200">删除成功</response> |
| 181 | /// <response code="400">记录不存在或无门店权限</response> | 331 | /// <response code="400">记录不存在或无门店权限</response> |
| 182 | /// <response code="500">服务器错误</response> | 332 | /// <response code="500">服务器错误</response> |
| 183 | [Authorize] | 333 | [Authorize] |
| 184 | - [HttpDelete("label-alert-timer/{id}")] | 334 | + [HttpDelete] |
| 335 | + [Route("/api/app/label-alert-timer/{id:regex(^\\d+$)}")] | ||
| 185 | public virtual async Task DeleteAsync(string id) | 336 | public virtual async Task DeleteAsync(string id) |
| 186 | { | 337 | { |
| 187 | var timerId = id?.Trim(); | 338 | var timerId = id?.Trim(); |
| @@ -269,7 +420,8 @@ public class LabelAlertTimerAppService : ApplicationService, ILabelAlertTimerApp | @@ -269,7 +420,8 @@ public class LabelAlertTimerAppService : ApplicationService, ILabelAlertTimerApp | ||
| 269 | /// <response code="400">未提供任何标识</response> | 420 | /// <response code="400">未提供任何标识</response> |
| 270 | /// <response code="500">服务器错误</response> | 421 | /// <response code="500">服务器错误</response> |
| 271 | [Authorize] | 422 | [Authorize] |
| 272 | - [HttpPost("label-alert-timer/check-expired")] | 423 | + [HttpPost] |
| 424 | + [Route("/api/app/label-alert-timer/check-expired")] | ||
| 273 | public virtual async Task<LabelAlertTimerCheckExpiredOutputDto> CheckExpiredAsync( | 425 | public virtual async Task<LabelAlertTimerCheckExpiredOutputDto> CheckExpiredAsync( |
| 274 | LabelAlertTimerCheckExpiredInputVo input) | 426 | LabelAlertTimerCheckExpiredInputVo input) |
| 275 | { | 427 | { |
| @@ -497,6 +649,29 @@ public class LabelAlertTimerAppService : ApplicationService, ILabelAlertTimerApp | @@ -497,6 +649,29 @@ public class LabelAlertTimerAppService : ApplicationService, ILabelAlertTimerApp | ||
| 497 | now)); | 649 | now)); |
| 498 | } | 650 | } |
| 499 | 651 | ||
| 652 | + foreach (var row in liveTimers.Where(x => string.IsNullOrWhiteSpace(x.PrintTaskId))) | ||
| 653 | + { | ||
| 654 | + if (locationIds is not null && | ||
| 655 | + (string.IsNullOrWhiteSpace(row.LocationId) || | ||
| 656 | + !locationIds.Contains(row.LocationId, StringComparer.OrdinalIgnoreCase))) | ||
| 657 | + { | ||
| 658 | + continue; | ||
| 659 | + } | ||
| 660 | + | ||
| 661 | + if (fromToday.HasValue && row.ExpiresAt < fromToday.Value) | ||
| 662 | + { | ||
| 663 | + continue; | ||
| 664 | + } | ||
| 665 | + | ||
| 666 | + if (dayStart.HasValue && dayEndExcl.HasValue && | ||
| 667 | + (row.ExpiresAt < dayStart.Value || row.ExpiresAt >= dayEndExcl.Value)) | ||
| 668 | + { | ||
| 669 | + continue; | ||
| 670 | + } | ||
| 671 | + | ||
| 672 | + mapped.Add(MapListItem(row, now)); | ||
| 673 | + } | ||
| 674 | + | ||
| 500 | mapped = mapped | 675 | mapped = mapped |
| 501 | .OrderByDescending(x => x.ExpiresAt) | 676 | .OrderByDescending(x => x.ExpiresAt) |
| 502 | .ThenByDescending(x => x.PrintedAt) | 677 | .ThenByDescending(x => x.PrintedAt) |
| @@ -546,6 +721,9 @@ public class LabelAlertTimerAppService : ApplicationService, ILabelAlertTimerApp | @@ -546,6 +721,9 @@ public class LabelAlertTimerAppService : ApplicationService, ILabelAlertTimerApp | ||
| 546 | DateTimeFormat = row.DateTimeFormat, | 721 | DateTimeFormat = row.DateTimeFormat, |
| 547 | PrintedByUserId = row.PrintedByUserId, | 722 | PrintedByUserId = row.PrintedByUserId, |
| 548 | PrintedByUserName = row.PrintedByUserName, | 723 | PrintedByUserName = row.PrintedByUserName, |
| 724 | + Source = string.IsNullOrWhiteSpace(row.PrintTaskId) | ||
| 725 | + ? nameof(LabelAlertTimerSource.Manual).ToLowerInvariant() | ||
| 726 | + : nameof(LabelAlertTimerSource.PrintLog).ToLowerInvariant(), | ||
| 549 | ExpiredMessageTemplate = LabelAlertTimerDisplayHelper.ExpiredMessageTemplate | 727 | ExpiredMessageTemplate = LabelAlertTimerDisplayHelper.ExpiredMessageTemplate |
| 550 | }; | 728 | }; |
| 551 | } | 729 | } |
| @@ -623,6 +801,7 @@ public class LabelAlertTimerAppService : ApplicationService, ILabelAlertTimerApp | @@ -623,6 +801,7 @@ public class LabelAlertTimerAppService : ApplicationService, ILabelAlertTimerApp | ||
| 623 | DateTimeFormat = format, | 801 | DateTimeFormat = format, |
| 624 | PrintedByUserId = task.CreatedBy ?? timer?.PrintedByUserId, | 802 | PrintedByUserId = task.CreatedBy ?? timer?.PrintedByUserId, |
| 625 | PrintedByUserName = timer?.PrintedByUserName, | 803 | PrintedByUserName = timer?.PrintedByUserName, |
| 804 | + Source = nameof(LabelAlertTimerSource.PrintLog).ToLowerInvariant(), | ||
| 626 | ExpiredMessageTemplate = LabelAlertTimerDisplayHelper.ExpiredMessageTemplate | 805 | ExpiredMessageTemplate = LabelAlertTimerDisplayHelper.ExpiredMessageTemplate |
| 627 | }; | 806 | }; |
| 628 | } | 807 | } |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Domain.Shared/Enums/AlertTemplateDurationUnit.cs
0 → 100644
| 1 | +namespace FoodLabeling.Domain.Shared.Enums; | ||
| 2 | + | ||
| 3 | +/// <summary> | ||
| 4 | +/// 告警模板时长单位:与 <c>durationValue</c> 组合成「3年 / 3月 / 3日」等。 | ||
| 5 | +/// </summary> | ||
| 6 | +public enum AlertTemplateDurationUnit | ||
| 7 | +{ | ||
| 8 | + /// <summary>年</summary> | ||
| 9 | + Year = 1, | ||
| 10 | + | ||
| 11 | + /// <summary>月</summary> | ||
| 12 | + Month = 2, | ||
| 13 | + | ||
| 14 | + /// <summary>日</summary> | ||
| 15 | + Day = 3, | ||
| 16 | + | ||
| 17 | + /// <summary>时</summary> | ||
| 18 | + Hour = 4, | ||
| 19 | + | ||
| 20 | + /// <summary>分</summary> | ||
| 21 | + Minute = 5, | ||
| 22 | + | ||
| 23 | + /// <summary>秒</summary> | ||
| 24 | + Second = 6, | ||
| 25 | + | ||
| 26 | + /// <summary>组合时间(durationValue 为总秒数,如 1 小时 30 分 = 5400)</summary> | ||
| 27 | + Combined = 7 | ||
| 28 | +} |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Domain.Shared/Enums/LabelAlertTimerSource.cs
0 → 100644
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/scripts/fl_alert_template.sql
| 1 | --- 告警日期时间格式模板(租户业务库) | 1 | +-- 告警模板(租户业务库):倒计时秒数 |
| 2 | -- 执行前请备份;可重复执行 | 2 | -- 执行前请备份;可重复执行 |
| 3 | 3 | ||
| 4 | SET @db := DATABASE(); | 4 | SET @db := DATABASE(); |
| @@ -6,7 +6,10 @@ SET @db := DATABASE(); | @@ -6,7 +6,10 @@ SET @db := DATABASE(); | ||
| 6 | CREATE TABLE IF NOT EXISTS `fl_alert_template` ( | 6 | CREATE TABLE IF NOT EXISTS `fl_alert_template` ( |
| 7 | `Id` varchar(36) NOT NULL COMMENT '主键(YitId)', | 7 | `Id` varchar(36) NOT NULL COMMENT '主键(YitId)', |
| 8 | `TemplateName` varchar(200) NOT NULL COMMENT '模板名称', | 8 | `TemplateName` varchar(200) NOT NULL COMMENT '模板名称', |
| 9 | - `DateTimeFormat` varchar(100) NOT NULL COMMENT '日期时间格式(如 MM/dd/yyyy h:mm tt)', | 9 | + `DurationUnit` int NOT NULL DEFAULT 6 COMMENT '1年 2月 3日 4时 5分 6秒 7组合时间', |
| 10 | + `DurationValue` int NOT NULL DEFAULT 0 COMMENT '时长数字', | ||
| 11 | + `CountdownSeconds` int NOT NULL DEFAULT 0 COMMENT '换算后的倒计时秒数', | ||
| 12 | + `DateTimeFormat` varchar(100) NOT NULL COMMENT '兼容旧列', | ||
| 10 | `State` tinyint(1) NOT NULL DEFAULT 1 COMMENT '启用状态', | 13 | `State` tinyint(1) NOT NULL DEFAULT 1 COMMENT '启用状态', |
| 11 | `IsDeleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '软删', | 14 | `IsDeleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '软删', |
| 12 | `DeletionTime` datetime DEFAULT NULL, | 15 | `DeletionTime` datetime DEFAULT NULL, |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/scripts/fl_alert_template_countdown.sql
0 → 100644
| 1 | +-- 告警模板补列:倒计时秒数 + 单位 + 数字(列已存在时忽略 1060) | ||
| 2 | + | ||
| 3 | +ALTER TABLE `fl_alert_template` | ||
| 4 | + ADD COLUMN `CountdownSeconds` int NOT NULL DEFAULT 0 COMMENT '倒计时秒数' AFTER `TemplateName`; | ||
| 5 | + | ||
| 6 | +ALTER TABLE `fl_alert_template` | ||
| 7 | + ADD COLUMN `DurationUnit` int NOT NULL DEFAULT 6 COMMENT '1年 2月 3日 4时 5分 6秒 7组合时间' AFTER `TemplateName`; | ||
| 8 | + | ||
| 9 | +ALTER TABLE `fl_alert_template` | ||
| 10 | + ADD COLUMN `DurationValue` int NOT NULL DEFAULT 0 COMMENT '时长数字' AFTER `DurationUnit`; |
项目相关文档/2026-10-22告警接口文档.md
0 → 100644
| 1 | +# 2026-10-22 告警接口文档 | ||
| 2 | + | ||
| 3 | +范围:泰额 **告警模板** CRUD / 下拉,以及 **按模板新增计时器**。不含登录、门店。 | ||
| 4 | +统一包装:成功时业务数据在 `data`(camelCase)。 | ||
| 5 | +鉴权:请求头 `Authorization` 使用公司登录返回的 token(已含 `Bearer ` 则原样带上)。 | ||
| 6 | +须已解析业务租户,且该公司主库初始化状态为 1。 | ||
| 7 | + | ||
| 8 | +**时长字段**:两个字段组合,例如 3 年、3 月、3 日。 | ||
| 9 | + | ||
| 10 | +| 字段 | 说明 | | ||
| 11 | +|------|------| | ||
| 12 | +| durationUnit | 类型:年 / 月 / 日 / 时 / 分 / 秒 / 组合时间 | | ||
| 13 | +| durationValue | 数字,与类型组合 | | ||
| 14 | + | ||
| 15 | +分页约定:`skipCount` 为**页码(从 1 开始)**,`maxResultCount` 为每页条数。 | ||
| 16 | + | ||
| 17 | +--- | ||
| 18 | + | ||
| 19 | +## 0. durationUnit 取值 | ||
| 20 | + | ||
| 21 | +接口 JSON 推荐英文枚举名,也接受中文或数字。 | ||
| 22 | + | ||
| 23 | +| 值(推荐) | 中文别名 | 数字 | 与 durationValue 的含义 | | ||
| 24 | +|------------|----------|------|-------------------------| | ||
| 25 | +| Year | 年 | 1 | 3 → 3 年 | | ||
| 26 | +| Month | 月 | 2 | 3 → 3 月 | | ||
| 27 | +| Day | 日 / 天 | 3 | 3 → 3 日 | | ||
| 28 | +| Hour | 时 / 小时 | 4 | 3 → 3 小时 | | ||
| 29 | +| Minute | 分 / 分钟 | 5 | 30 → 30 分钟 | | ||
| 30 | +| Second | 秒 | 6 | 90 → 90 秒 | | ||
| 31 | +| Combined | 组合时间 | 7 | **总秒数**,如 1 小时 30 分 = 5400 | | ||
| 32 | + | ||
| 33 | +`durationValue` 必须 ≥ 1。上限:年 100、月 1200、日 3650、时 87600、分 5256000、秒/组合时间 31536000。 | ||
| 34 | + | ||
| 35 | +--- | ||
| 36 | + | ||
| 37 | +## 1. 分页列表 | ||
| 38 | + | ||
| 39 | +**POST** `/api/app/alert-template/list` | ||
| 40 | + | ||
| 41 | +```json | ||
| 42 | +{ | ||
| 43 | + "keyword": "冷藏", | ||
| 44 | + "state": true, | ||
| 45 | + "skipCount": 1, | ||
| 46 | + "maxResultCount": 20 | ||
| 47 | +} | ||
| 48 | +``` | ||
| 49 | + | ||
| 50 | +| 字段 | 类型 | 必填 | 说明 | | ||
| 51 | +|------|------|------|------| | ||
| 52 | +| keyword | string | 否 | 模板名称模糊匹配 | | ||
| 53 | +| state | bool / null | 否 | 启用状态;不传=全部 | | ||
| 54 | +| skipCount | int | 否 | 页码,从 1 开始 | | ||
| 55 | +| maxResultCount | int | 否 | 每页条数;≤0 时按 10 | | ||
| 56 | + | ||
| 57 | +### data | ||
| 58 | + | ||
| 59 | +| 字段 | 类型 | 说明 | | ||
| 60 | +|------|------|------| | ||
| 61 | +| pageIndex | int | 当前页 | | ||
| 62 | +| pageSize | int | 每页条数 | | ||
| 63 | +| totalCount | long | 总条数 | | ||
| 64 | +| totalPages | int | 总页数 | | ||
| 65 | +| items | array | 见第 6 节 | | ||
| 66 | + | ||
| 67 | +--- | ||
| 68 | + | ||
| 69 | +## 2. 详情 | ||
| 70 | + | ||
| 71 | +**GET** `/api/app/alert-template/{id}` | ||
| 72 | + | ||
| 73 | +| 字段 | 位置 | 说明 | | ||
| 74 | +|------|------|------| | ||
| 75 | +| id | path | 模板主键(YitId) | | ||
| 76 | + | ||
| 77 | +`data` 见第 6 节。 | ||
| 78 | + | ||
| 79 | +--- | ||
| 80 | + | ||
| 81 | +## 3. 新增 | ||
| 82 | + | ||
| 83 | +**POST** `/api/app/alert-template` | ||
| 84 | + | ||
| 85 | +```json | ||
| 86 | +{ | ||
| 87 | + "templateName": "冷藏 3 日", | ||
| 88 | + "durationUnit": "Day", | ||
| 89 | + "durationValue": 3, | ||
| 90 | + "state": true | ||
| 91 | +} | ||
| 92 | +``` | ||
| 93 | + | ||
| 94 | +中文单位也可以: | ||
| 95 | + | ||
| 96 | +```json | ||
| 97 | +{ | ||
| 98 | + "templateName": "保质 3 年", | ||
| 99 | + "durationUnit": "年", | ||
| 100 | + "durationValue": 3, | ||
| 101 | + "state": true | ||
| 102 | +} | ||
| 103 | +``` | ||
| 104 | + | ||
| 105 | +组合时间(总秒数): | ||
| 106 | + | ||
| 107 | +```json | ||
| 108 | +{ | ||
| 109 | + "templateName": "1小时30分", | ||
| 110 | + "durationUnit": "组合时间", | ||
| 111 | + "durationValue": 5400, | ||
| 112 | + "state": true | ||
| 113 | +} | ||
| 114 | +``` | ||
| 115 | + | ||
| 116 | +| 字段 | 类型 | 必填 | 说明 | | ||
| 117 | +|------|------|------|------| | ||
| 118 | +| templateName | string | 是 | 模板名称 | | ||
| 119 | +| durationUnit | string / int | 是 | 见第 0 节 | | ||
| 120 | +| durationValue | int | 是 | 时长数字 | | ||
| 121 | +| state | bool | 否 | 是否启用,默认 true | | ||
| 122 | + | ||
| 123 | +`data` 为新建后的模板对象(含 `id`)。 | ||
| 124 | + | ||
| 125 | +--- | ||
| 126 | + | ||
| 127 | +## 4. 编辑 | ||
| 128 | + | ||
| 129 | +**PUT** `/api/app/alert-template/{id}` | ||
| 130 | + | ||
| 131 | +body 与新增相同。 | ||
| 132 | + | ||
| 133 | +--- | ||
| 134 | + | ||
| 135 | +## 5. 软删除 | ||
| 136 | + | ||
| 137 | +**DELETE** `/api/app/alert-template/{id}` | ||
| 138 | + | ||
| 139 | +成功:HTTP 200。列表不再出现。 | ||
| 140 | + | ||
| 141 | +--- | ||
| 142 | + | ||
| 143 | +## 6. 模板对象(列表 / 详情 / 新增 / 编辑出参) | ||
| 144 | + | ||
| 145 | +| 字段 | 类型 | 说明 | | ||
| 146 | +|------|------|------| | ||
| 147 | +| id | string | 主键(YitId) | | ||
| 148 | +| templateName | string | 模板名称 | | ||
| 149 | +| durationUnit | string | `Year` / `Month` / `Day` / `Hour` / `Minute` / `Second` / `Combined` | | ||
| 150 | +| durationValue | int | 时长数字 | | ||
| 151 | +| state | bool | 是否启用 | | ||
| 152 | +| creationTime | datetime | 创建时间 | | ||
| 153 | +| lastModificationTime | datetime / null | 最后修改时间 | | ||
| 154 | + | ||
| 155 | +```json | ||
| 156 | +{ | ||
| 157 | + "id": "1234567890123456789", | ||
| 158 | + "templateName": "冷藏 3 日", | ||
| 159 | + "durationUnit": "Day", | ||
| 160 | + "durationValue": 3, | ||
| 161 | + "state": true, | ||
| 162 | + "creationTime": "2026-10-22T17:00:00", | ||
| 163 | + "lastModificationTime": "2026-10-22T17:00:00" | ||
| 164 | +} | ||
| 165 | +``` | ||
| 166 | + | ||
| 167 | +--- | ||
| 168 | + | ||
| 169 | +## 7. 启用中下拉 | ||
| 170 | + | ||
| 171 | +**GET** `/api/app/alert-template/options` | ||
| 172 | + | ||
| 173 | +仅未删除且 `state=true`。 | ||
| 174 | + | ||
| 175 | +| 字段 | 类型 | 说明 | | ||
| 176 | +|------|------|------| | ||
| 177 | +| id | string | 模板 Id | | ||
| 178 | +| templateName | string | 名称 | | ||
| 179 | +| durationUnit | string | 单位 | | ||
| 180 | +| durationValue | int | 数字 | | ||
| 181 | + | ||
| 182 | +--- | ||
| 183 | + | ||
| 184 | +## 8. 错误码 | ||
| 185 | + | ||
| 186 | +| HTTP | 场景 | | ||
| 187 | +|------|------| | ||
| 188 | +| 200 | 成功 | | ||
| 189 | +| 400 | 参数无效、模板不存在、未初始化完成 | | ||
| 190 | +| 401 | 未登录 | | ||
| 191 | +| 405 | POST 打到了只允许 DELETE 的 `{id}`;请用 `/create` | | ||
| 192 | +| 500 | 服务器错误 | | ||
| 193 | + | ||
| 194 | +| 错误信息 | 原因 | | ||
| 195 | +|----------|------| | ||
| 196 | +| Request body is required. | body 为空 | | ||
| 197 | +| Template name is required. | 未填名称 | | ||
| 198 | +| durationUnit is required (Year/Month/Day/Hour/Minute/Second/Combined). | 未传或非法单位 | | ||
| 199 | +| durationValue must be between 1 and {max}. | 数字越界 | | ||
| 200 | +| Template Id is required. | 路径 id 为空 | | ||
| 201 | +| Alert template not found. | 不存在或已删除 | | ||
| 202 | +| Alert template not found or disabled. | 新增计时器时模板不存在或未启用 | | ||
| 203 | +| Alert template duration is not configured. | 模板未配置单位+数字 | | ||
| 204 | +| Select a location or pass locationId. | 新增计时器未选门店 | | ||
| 205 | + | ||
| 206 | +--- | ||
| 207 | + | ||
| 208 | +## 9. 库表 | ||
| 209 | + | ||
| 210 | +`fl_alert_template`(租户业务库) | ||
| 211 | + | ||
| 212 | +| 列 | 说明 | | ||
| 213 | +|----|------| | ||
| 214 | +| DurationUnit | 1年 2月 3日 4时 5分 6秒 7组合时间 | | ||
| 215 | +| DurationValue | 时长数字 | | ||
| 216 | +| CountdownSeconds | 创建时换算的秒数(内部用) | | ||
| 217 | + | ||
| 218 | +首次调接口会自动补列。 | ||
| 219 | + | ||
| 220 | +--- | ||
| 221 | + | ||
| 222 | +## 10. curl | ||
| 223 | + | ||
| 224 | +```bash | ||
| 225 | +# 新增:3 日 | ||
| 226 | +curl -s -X POST "https://flusapi-tetest.3flabeling.com/api/app/alert-template" \ | ||
| 227 | + -H "Authorization: <TOKEN>" \ | ||
| 228 | + -H "Content-Type: application/json" \ | ||
| 229 | + -d "{\"templateName\":\"冷藏3日\",\"durationUnit\":\"Day\",\"durationValue\":3,\"state\":true}" | ||
| 230 | + | ||
| 231 | +# 新增:3 年(中文单位) | ||
| 232 | +curl -s -X POST "https://flusapi-tetest.3flabeling.com/api/app/alert-template" \ | ||
| 233 | + -H "Authorization: <TOKEN>" \ | ||
| 234 | + -H "Content-Type: application/json" \ | ||
| 235 | + -d "{\"templateName\":\"保质3年\",\"durationUnit\":\"年\",\"durationValue\":3,\"state\":true}" | ||
| 236 | + | ||
| 237 | +# 列表 | ||
| 238 | +curl -s -X POST "https://flusapi-tetest.3flabeling.com/api/app/alert-template/list" \ | ||
| 239 | + -H "Authorization: <TOKEN>" \ | ||
| 240 | + -H "Content-Type: application/json" \ | ||
| 241 | + -d "{\"keyword\":\"\",\"skipCount\":1,\"maxResultCount\":20}" | ||
| 242 | + | ||
| 243 | +# 下拉 | ||
| 244 | +curl -s "https://flusapi-tetest.3flabeling.com/api/app/alert-template/options" \ | ||
| 245 | + -H "Authorization: <TOKEN>" | ||
| 246 | + | ||
| 247 | +# 编辑 | ||
| 248 | +curl -s -X PUT "https://flusapi-tetest.3flabeling.com/api/app/alert-template/<ID>" \ | ||
| 249 | + -H "Authorization: <TOKEN>" \ | ||
| 250 | + -H "Content-Type: application/json" \ | ||
| 251 | + -d "{\"templateName\":\"冷藏3日\",\"durationUnit\":\"日\",\"durationValue\":3,\"state\":true}" | ||
| 252 | + | ||
| 253 | +# 删除模板 | ||
| 254 | +curl -s -X DELETE "https://flusapi-tetest.3flabeling.com/api/app/alert-template/<ID>" \ | ||
| 255 | + -H "Authorization: <TOKEN>" | ||
| 256 | + | ||
| 257 | +# 按模板新增计时器(App 推荐) | ||
| 258 | +curl -s -X POST "https://flusapi-tetest.3flabeling.com/api/app/label-alert-timer/create" \ | ||
| 259 | + -H "Authorization: <TOKEN>" \ | ||
| 260 | + -H "Content-Type: application/json" \ | ||
| 261 | + -d "{\"alertTemplateId\":\"<TEMPLATE_ID>\",\"locationId\":\"<LOCATION_ID>\"}" | ||
| 262 | + | ||
| 263 | +# 兼容:路径带模板数字 Id | ||
| 264 | +curl -s -X POST "https://flusapi-tetest.3flabeling.com/api/app/label-alert-timer/<TEMPLATE_ID>" \ | ||
| 265 | + -H "Authorization: <TOKEN>" \ | ||
| 266 | + -H "Content-Type: application/json" \ | ||
| 267 | + -d "{\"locationId\":\"<LOCATION_ID>\"}" | ||
| 268 | +``` | ||
| 269 | + | ||
| 270 | +--- | ||
| 271 | + | ||
| 272 | +## 11. 按模板新增计时器(Web / App) | ||
| 273 | + | ||
| 274 | +从启用中的模板读 `durationUnit` + `durationValue`,从当前时刻倒计时,写入已有表 `fl_label_alert_timer`(`printTaskId` 空)。随后出现在 `list` / `app-list`。 | ||
| 275 | + | ||
| 276 | +| 方法 | 路径 | 说明 | | ||
| 277 | +|------|------|------| | ||
| 278 | +| POST | `/api/app/label-alert-timer/create` | **推荐**;App Confirm 走这条 | | ||
| 279 | +| POST | `/api/app/label-alert-timer` | 兼容根路径 | | ||
| 280 | +| POST | `/api/app/label-alert-timer/{alertTemplateId}` | 路径数字 Id = 模板 Id | | ||
| 281 | +| DELETE | `/api/app/label-alert-timer/{id}` | 软删;`id` 仅数字(YitId) | | ||
| 282 | + | ||
| 283 | +`create` / `list` / `app-list` / `check-expired` 是固定路径。`{id}` 只匹配数字,避免 POST `/create` 被当成删除接口而 **405**。 | ||
| 284 | + | ||
| 285 | +```json | ||
| 286 | +{ | ||
| 287 | + "alertTemplateId": "123456789", | ||
| 288 | + "locationId": "3a2473aa-98f1-e2ab-b50a-2efcb8bfdb54" | ||
| 289 | +} | ||
| 290 | +``` | ||
| 291 | + | ||
| 292 | +| 字段 | 类型 | 必填 | 说明 | | ||
| 293 | +|------|------|------|------| | ||
| 294 | +| alertTemplateId | string | 是(路径版可省略) | 启用中的模板 Id | | ||
| 295 | +| locationId | string | 否 | 门店;空则已选门店缓存;仍空 400 | | ||
| 296 | + | ||
| 297 | +成功 `data` 含 `id`、`remainingTime`、`expiresAt`、`source=manual`。 |
项目相关文档/2026-10-22接口文档.md
| @@ -251,7 +251,32 @@ Authorization: <公司 Token> | @@ -251,7 +251,32 @@ Authorization: <公司 Token> | ||
| 251 | 251 | ||
| 252 | --- | 252 | --- |
| 253 | 253 | ||
| 254 | -## 7. 告警计时器(打印日志过期时间列表) | 254 | +## 6.1 告警模板(单位 + 数字) |
| 255 | + | ||
| 256 | +公司业务 Token。完整说明见 `2026-10-22告警接口文档.md`。 | ||
| 257 | + | ||
| 258 | +两个字段组合:`durationUnit`(年/月/日/时/分/秒/组合时间)+ `durationValue`(数字)→ 3年、3月、3日。 | ||
| 259 | +组合时间时 `durationValue` 为总秒数。 | ||
| 260 | + | ||
| 261 | +### 新增 | ||
| 262 | + | ||
| 263 | +**POST** `/api/app/alert-template` | ||
| 264 | + | ||
| 265 | +```json | ||
| 266 | +{ | ||
| 267 | + "templateName": "冷藏 3 日", | ||
| 268 | + "durationUnit": "Day", | ||
| 269 | + "durationValue": 3, | ||
| 270 | + "state": true | ||
| 271 | +} | ||
| 272 | +``` | ||
| 273 | + | ||
| 274 | +列表 **POST** `/api/app/alert-template/list`;编辑 **PUT** `/api/app/alert-template/{id}`;下拉 **GET** `/api/app/alert-template/options`。 | ||
| 275 | +App 按模板新增计时器见 **7.3.1**(`POST /api/app/label-alert-timer/create`)。 | ||
| 276 | + | ||
| 277 | +--- | ||
| 278 | + | ||
| 279 | +## 7. 告警计时器(打印日志过期 + 手动模板计时器) | ||
| 255 | 280 | ||
| 256 | 公司业务 Token。列表按**打印日志实时解析过期时间**(与 Print Log「Expiration」同源,优先打印快照),不要求 `fl_label_alert_timer` 已有行;改过期时间后立刻能查到。 | 281 | 公司业务 Token。列表按**打印日志实时解析过期时间**(与 Print Log「Expiration」同源,优先打印快照),不要求 `fl_label_alert_timer` 已有行;改过期时间后立刻能查到。 |
| 257 | **仅展示倒计时,绝不用于拦截打印。** | 282 | **仅展示倒计时,绝不用于拦截打印。** |
| @@ -339,18 +364,46 @@ App 只有一个筛选项:当前门店/公司。 | @@ -339,18 +364,46 @@ App 只有一个筛选项:当前门店/公司。 | ||
| 339 | | productName | string / null | 产品名 | | 364 | | productName | string / null | 产品名 | |
| 340 | | alertTemplateId / alertTemplateName | string / null | 告警模板(可空) | | 365 | | alertTemplateId / alertTemplateName | string / null | 告警模板(可空) | |
| 341 | | dateTimeFormat | string / null | 时间格式 | | 366 | | dateTimeFormat | string / null | 时间格式 | |
| 367 | +| source | string | `printLog` 打印日志;`manual` 按模板手动新增 | | ||
| 342 | | printedByUserId / printedByUserName | string / null | 打印人 | | 368 | | printedByUserId / printedByUserName | string / null | 打印人 | |
| 343 | | expiredMessageTemplate | string | `Hi {userName}, your {labelName} label has expired. Please take action.` | | 369 | | expiredMessageTemplate | string | `Hi {userName}, your {labelName} label has expired. Please take action.` | |
| 344 | 370 | ||
| 345 | 排序:先 `expiresAt` 降序,再 `printedAt` 降序。 | 371 | 排序:先 `expiresAt` 降序,再 `printedAt` 降序。 |
| 346 | 372 | ||
| 347 | -写入规则:打印成功且能解析过期时刻会写入/更新 `fl_label_alert_timer`。列表本身不依赖该表,直接读打印日志过期时间。 | 373 | +**不需要新表。** 手动计时器写入已有 `fl_label_alert_timer`(`printTaskId` 为空)。列表 = 打印日志过期记录 ∪ 手动计时器。 |
| 374 | + | ||
| 375 | +### 7.3.1 按模板新增计时器(Web / App) | ||
| 376 | + | ||
| 377 | +从启用中的告警模板读取 `durationUnit` + `durationValue`,从当前时刻开始倒计时。三条路径等价,推荐第一条。 | ||
| 378 | + | ||
| 379 | +| 方法 | 路径 | 说明 | | ||
| 380 | +|------|------|------| | ||
| 381 | +| POST | `/api/app/label-alert-timer/create` | **推荐**;App 当前用这条 | | ||
| 382 | +| POST | `/api/app/label-alert-timer` | 兼容 ABP 约定根路径 | | ||
| 383 | +| POST | `/api/app/label-alert-timer/{alertTemplateId}` | 路径上的数字 Id 当作模板 Id;body 可只带 `locationId` | | ||
| 384 | + | ||
| 385 | +`alertTemplateId`、删除用的 `{id}` **必须是数字(YitId)**。`create` / `list` / `app-list` / `check-expired` 不会被 `{id}` 吃掉;否则 POST 会 405。 | ||
| 386 | + | ||
| 387 | +```json | ||
| 388 | +{ | ||
| 389 | + "alertTemplateId": "123456789", | ||
| 390 | + "locationId": "3a2473aa-98f1-e2ab-b50a-2efcb8bfdb54" | ||
| 391 | +} | ||
| 392 | +``` | ||
| 393 | + | ||
| 394 | +| 字段 | 类型 | 必填 | 说明 | | ||
| 395 | +|------|------|------|------| | ||
| 396 | +| alertTemplateId | string | 是(路径版可省略) | 启用中的告警模板 Id | | ||
| 397 | +| locationId | string | 否 | 门店;空则已选门店缓存;仍空则 400 | | ||
| 398 | + | ||
| 399 | +成功 data 结构同列表 `items[]`,`source=manual`。随后会出现在 list / app-list。 | ||
| 348 | 400 | ||
| 349 | ### 7.4 软删除 | 401 | ### 7.4 软删除 |
| 350 | 402 | ||
| 351 | **DELETE** `/api/app/label-alert-timer/{id}` | 403 | **DELETE** `/api/app/label-alert-timer/{id}` |
| 352 | 404 | ||
| 353 | -`id` 必须是数字(YitId)。删除前校验当前用户可访问该计时器所属门店。 | 405 | +`id` 必须是数字(YitId)。删除前校验当前用户可访问该计时器所属门店。 |
| 406 | +对 `create` 等非数字路径发 DELETE / POST 不要当删除用。 | ||
| 354 | 407 | ||
| 355 | ### 7.5 查询是否过期(展示用) | 408 | ### 7.5 查询是否过期(展示用) |
| 356 | 409 | ||
| @@ -370,6 +423,10 @@ App 只有一个筛选项:当前门店/公司。 | @@ -370,6 +423,10 @@ App 只有一个筛选项:当前门店/公司。 | ||
| 370 | |----------|------| | 423 | |----------|------| |
| 371 | | Request body is required. | body 为空 | | 424 | | Request body is required. | body 为空 | |
| 372 | | You are not signed in. | 未登录 | | 425 | | You are not signed in. | 未登录 | |
| 426 | +| Alert template Id is required. | 未传模板 Id | | ||
| 427 | +| Alert template not found or disabled. | 模板不存在或未启用 | | ||
| 428 | +| Alert template duration is not configured. | 模板未配置单位+数字 | | ||
| 429 | +| Select a location or pass locationId. | 未选门店 | | ||
| 373 | | Timer Id is required. | 删除未传 id | | 430 | | Timer Id is required. | 删除未传 id | |
| 374 | | Timer not found or removed. | 记录不存在或已删 | | 431 | | Timer not found or removed. | 记录不存在或已删 | |
| 375 | | Provide at least one of timerId, batchId, or printTaskId. | check-expired 三个标识都空 | | 432 | | Provide at least one of timerId, batchId, or printTaskId. | check-expired 三个标识都空 | |
| @@ -384,6 +441,7 @@ App 只有一个筛选项:当前门店/公司。 | @@ -384,6 +441,7 @@ App 只有一个筛选项:当前门店/公司。 | ||
| 384 | | 200 | 成功 | | 441 | | 200 | 成功 | |
| 385 | | 400 | 未初始化完成、过期、账号密码错误、门店不可见、计时器参数错误 | | 442 | | 400 | 未初始化完成、过期、账号密码错误、门店不可见、计时器参数错误 | |
| 386 | | 401 | 未登录 | | 443 | | 401 | 未登录 | |
| 444 | +| 405 | 方法不匹配(例如 POST 打到了只允许 DELETE 的 `{id}`;请用 `/create`) | | ||
| 387 | | 500 | 服务器错误 | | 445 | | 500 | 服务器错误 | |
| 388 | 446 | ||
| 389 | --- | 447 | --- |
| @@ -427,4 +485,22 @@ curl -s -X POST "https://flusapi-tetest.3flabeling.com/api/app/label-alert-timer | @@ -427,4 +485,22 @@ curl -s -X POST "https://flusapi-tetest.3flabeling.com/api/app/label-alert-timer | ||
| 427 | -H "Authorization: <COMPANY_TOKEN>" \ | 485 | -H "Authorization: <COMPANY_TOKEN>" \ |
| 428 | -H "Content-Type: application/json" \ | 486 | -H "Content-Type: application/json" \ |
| 429 | -d "{\"locationId\":\"3a2473aa-98f1-e2ab-b50a-2efcb8bfdb54\",\"skipCount\":1,\"maxResultCount\":50}" | 487 | -d "{\"locationId\":\"3a2473aa-98f1-e2ab-b50a-2efcb8bfdb54\",\"skipCount\":1,\"maxResultCount\":50}" |
| 488 | + | ||
| 489 | +# 告警模板新增(单位 + 数字,如 3 日) | ||
| 490 | +curl -s -X POST "https://flusapi-tetest.3flabeling.com/api/app/alert-template" \ | ||
| 491 | + -H "Authorization: <COMPANY_TOKEN>" \ | ||
| 492 | + -H "Content-Type: application/json" \ | ||
| 493 | + -d "{\"templateName\":\"冷藏3日\",\"durationUnit\":\"Day\",\"durationValue\":3,\"state\":true}" | ||
| 494 | + | ||
| 495 | +# App/Web:按模板新增计时器(推荐) | ||
| 496 | +curl -s -X POST "https://flusapi-tetest.3flabeling.com/api/app/label-alert-timer/create" \ | ||
| 497 | + -H "Authorization: <COMPANY_TOKEN>" \ | ||
| 498 | + -H "Content-Type: application/json" \ | ||
| 499 | + -d "{\"alertTemplateId\":\"<TEMPLATE_ID>\",\"locationId\":\"3a2473aa-98f1-e2ab-b50a-2efcb8bfdb54\"}" | ||
| 500 | + | ||
| 501 | +# 兼容:路径带模板数字 Id | ||
| 502 | +curl -s -X POST "https://flusapi-tetest.3flabeling.com/api/app/label-alert-timer/<TEMPLATE_ID>" \ | ||
| 503 | + -H "Authorization: <COMPANY_TOKEN>" \ | ||
| 504 | + -H "Content-Type: application/json" \ | ||
| 505 | + -d "{\"locationId\":\"3a2473aa-98f1-e2ab-b50a-2efcb8bfdb54\"}" | ||
| 430 | ``` | 506 | ``` |