From 816bc71f54477b1b47153da00beda7e78ad49395 Mon Sep 17 00:00:00 2001
From: 李曜臣
Date: Thu, 22 Oct 2026 17:56:27 +0800
Subject: [PATCH] 2026-10-22泰鄂版:告警
---
泰额版/Food Labeling Management App UniApp/src/services/usAppAlertTimer.ts | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/AlertTemplate/AlertTemplateCreateInputVo.cs | 14 +++++++++++++-
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/AlertTemplate/AlertTemplateDto.cs | 11 ++++++++++-
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/AlertTemplate/AlertTemplateOptionDto.cs | 9 ++++++++-
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelAlertTimer/LabelAlertTimerCreateInputVo.cs | 11 +++++++++++
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelAlertTimer/LabelAlertTimerListItemDto.cs | 3 +++
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/Reports/ReportsPrintLogListItemDto.cs | 2 +-
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/IServices/IAlertTemplateAppService.cs | 2 +-
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/IServices/ILabelAlertTimerAppService.cs | 12 ++++++++++++
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Json/AlertTemplateDurationUnitJsonConverter.cs | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/FoodLabeling.Application.csproj | 3 +++
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/AlertTemplateDurationHelper.cs | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/LabelAlertTimerWriteHelper.cs | 6 +++---
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/MultiTenancy/FoodLabelingTenantMigrationScriptNames.cs | 4 ++++
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/MultiTenancy/TenantSqlScriptExecutor.cs | 9 +++++++--
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/AlertTemplateAppService.cs | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/DbModels/FlAlertTemplateDbEntity.cs | 13 ++++++++++++-
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelAlertTimerAppService.cs | 189 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Domain.Shared/Enums/AlertTemplateDurationUnit.cs | 28 ++++++++++++++++++++++++++++
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Domain.Shared/Enums/LabelAlertTimerSource.cs | 13 +++++++++++++
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/scripts/fl_alert_template.sql | 7 +++++--
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/scripts/fl_alert_template_countdown.sql | 10 ++++++++++
项目相关文档/2026-10-22告警接口文档.md | 297 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
项目相关文档/2026-10-22接口文档.md | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
24 files changed, 1009 insertions(+), 42 deletions(-)
create mode 100644 泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelAlertTimer/LabelAlertTimerCreateInputVo.cs
create mode 100644 泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Json/AlertTemplateDurationUnitJsonConverter.cs
create mode 100644 泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/AlertTemplateDurationHelper.cs
create mode 100644 泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Domain.Shared/Enums/AlertTemplateDurationUnit.cs
create mode 100644 泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Domain.Shared/Enums/LabelAlertTimerSource.cs
create mode 100644 泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/scripts/fl_alert_template_countdown.sql
create mode 100644 项目相关文档/2026-10-22告警接口文档.md
diff --git a/泰额版/Food Labeling Management App UniApp/src/services/usAppAlertTimer.ts b/泰额版/Food Labeling Management App UniApp/src/services/usAppAlertTimer.ts
index b8e4cba..16d9f62 100644
--- a/泰额版/Food Labeling Management App UniApp/src/services/usAppAlertTimer.ts
+++ b/泰额版/Food Labeling Management App UniApp/src/services/usAppAlertTimer.ts
@@ -84,3 +84,54 @@ export function deleteUsAppAlertTimer(id: string): Promise {
auth: true,
})
}
+
+export interface UsAppAlertTemplateOption {
+ id: string
+ templateName: string
+ durationUnit: string
+ durationValue: number
+}
+
+function normalizeTemplateOption(raw: unknown): UsAppAlertTemplateOption | null {
+ const o = (raw && typeof raw === 'object' ? raw : {}) as Record
+ const id = str(o, 'id', 'Id')
+ if (!id) return null
+ const unitRaw = o.durationUnit ?? o.DurationUnit
+ const durationUnit = typeof unitRaw === 'string' && unitRaw.trim()
+ ? unitRaw.trim()
+ : String(unitRaw ?? 'Minute')
+ return {
+ id,
+ templateName: str(o, 'templateName', 'TemplateName') || id,
+ durationUnit,
+ durationValue: Math.max(0, num(o, 'durationValue', 'DurationValue')),
+ }
+}
+
+export async function fetchUsAppAlertTemplateOptions(): Promise {
+ const raw = await usAppApiRequest({
+ path: '/api/app/alert-template/options',
+ method: 'GET',
+ auth: true,
+ })
+ const o = (raw && typeof raw === 'object' ? raw : {}) as Record
+ const list = Array.isArray(raw) ? raw : asArr(o.items ?? o.Items)
+ return list.map(normalizeTemplateOption).filter((x): x is UsAppAlertTemplateOption => !!x)
+}
+
+export async function createUsAppAlertTimer(input: {
+ alertTemplateId: string
+ locationId?: string
+}): Promise {
+ const body: Record = {
+ alertTemplateId: input.alertTemplateId,
+ }
+ if (input.locationId) body.locationId = input.locationId
+ const raw = await usAppApiRequest({
+ path: `${PATH}/create`,
+ method: 'POST',
+ data: body,
+ auth: true,
+ })
+ return normalizeTimer(raw)
+}
diff --git a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/AlertTemplate/AlertTemplateCreateInputVo.cs b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/AlertTemplate/AlertTemplateCreateInputVo.cs
index 69fc897..dde7e0e 100644
--- a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/AlertTemplate/AlertTemplateCreateInputVo.cs
+++ b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/AlertTemplate/AlertTemplateCreateInputVo.cs
@@ -1,3 +1,7 @@
+using System.Text.Json.Serialization;
+using FoodLabeling.Application.Contracts.Json;
+using FoodLabeling.Domain.Shared.Enums;
+
namespace FoodLabeling.Application.Contracts.Dtos.AlertTemplate;
/// 告警模板新增/编辑入参
@@ -5,7 +9,15 @@ public class AlertTemplateCreateInputVo
{
public string TemplateName { get; set; } = string.Empty;
- public string DateTimeFormat { get; set; } = string.Empty;
+ ///
+ /// 时长单位:Year/Month/Day/Hour/Minute/Second/Combined,
+ /// 也可传 年/月/日/时/分/秒/组合时间。
+ ///
+ [JsonConverter(typeof(AlertTemplateDurationUnitJsonConverter))]
+ public AlertTemplateDurationUnit DurationUnit { get; set; }
+
+ /// 时长数字,与单位组合成 3年、3月、3日等;组合时间为总秒数。
+ public int DurationValue { get; set; }
public bool State { get; set; } = true;
}
diff --git a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/AlertTemplate/AlertTemplateDto.cs b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/AlertTemplate/AlertTemplateDto.cs
index c09253d..d92edb8 100644
--- a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/AlertTemplate/AlertTemplateDto.cs
+++ b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/AlertTemplate/AlertTemplateDto.cs
@@ -1,3 +1,7 @@
+using System.Text.Json.Serialization;
+using FoodLabeling.Application.Contracts.Json;
+using FoodLabeling.Domain.Shared.Enums;
+
namespace FoodLabeling.Application.Contracts.Dtos.AlertTemplate;
/// 告警模板详情/列表项
@@ -7,7 +11,12 @@ public class AlertTemplateDto
public string TemplateName { get; set; } = string.Empty;
- public string DateTimeFormat { get; set; } = string.Empty;
+ /// 时长单位
+ [JsonConverter(typeof(AlertTemplateDurationUnitJsonConverter))]
+ public AlertTemplateDurationUnit DurationUnit { get; set; }
+
+ /// 时长数字
+ public int DurationValue { get; set; }
public bool State { get; set; }
diff --git a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/AlertTemplate/AlertTemplateOptionDto.cs b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/AlertTemplate/AlertTemplateOptionDto.cs
index 80c27cc..29b6323 100644
--- a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/AlertTemplate/AlertTemplateOptionDto.cs
+++ b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/AlertTemplate/AlertTemplateOptionDto.cs
@@ -1,3 +1,7 @@
+using System.Text.Json.Serialization;
+using FoodLabeling.Application.Contracts.Json;
+using FoodLabeling.Domain.Shared.Enums;
+
namespace FoodLabeling.Application.Contracts.Dtos.AlertTemplate;
/// 告警模板下拉项(仅启用)
@@ -7,5 +11,8 @@ public class AlertTemplateOptionDto
public string TemplateName { get; set; } = string.Empty;
- public string DateTimeFormat { get; set; } = string.Empty;
+ [JsonConverter(typeof(AlertTemplateDurationUnitJsonConverter))]
+ public AlertTemplateDurationUnit DurationUnit { get; set; }
+
+ public int DurationValue { get; set; }
}
diff --git a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelAlertTimer/LabelAlertTimerCreateInputVo.cs b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelAlertTimer/LabelAlertTimerCreateInputVo.cs
new file mode 100644
index 0000000..a0b8e53
--- /dev/null
+++ b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelAlertTimer/LabelAlertTimerCreateInputVo.cs
@@ -0,0 +1,11 @@
+namespace FoodLabeling.Application.Contracts.Dtos.LabelAlertTimer;
+
+/// 按告警模板手动新增计时器入参
+public class LabelAlertTimerCreateInputVo
+{
+ /// 告警模板 Id(取其 durationUnit + durationValue 作为倒计时)
+ public string AlertTemplateId { get; set; } = string.Empty;
+
+ /// 门店 Id。Web 建议传入;App 可空(已选门店缓存)
+ public string? LocationId { get; set; }
+}
\ No newline at end of file
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
index d5940f3..ad9f96c 100644
--- 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
@@ -49,6 +49,9 @@ public class LabelAlertTimerListItemDto
public string? DateTimeFormat { get; set; }
+ /// 来源:printLog / manual
+ public string Source { get; set; } = "printLog";
+
public string? PrintedByUserId { get; set; }
public string? PrintedByUserName { get; set; }
diff --git a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/Reports/ReportsPrintLogListItemDto.cs b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/Reports/ReportsPrintLogListItemDto.cs
index f4633fd..c5f077f 100644
--- a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/Reports/ReportsPrintLogListItemDto.cs
+++ b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/Reports/ReportsPrintLogListItemDto.cs
@@ -1,4 +1,4 @@
-namespace FoodLabeling.Application.Contracts.Dtos.Reports;
+namespace FoodLabeling.Application.Contracts.Dtos.Reports;
///
/// Print Log 列表行(Reports 管理端)
diff --git a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/IServices/IAlertTemplateAppService.cs b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/IServices/IAlertTemplateAppService.cs
index c8b3b80..0663d9d 100644
--- a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/IServices/IAlertTemplateAppService.cs
+++ b/泰额版/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;
namespace FoodLabeling.Application.Contracts.IServices;
-/// 告警日期时间格式模板
+/// 告警模板(倒计时秒数)
public interface IAlertTemplateAppService : IApplicationService
{
Task> ListAsync(AlertTemplateGetListInputVo input);
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
index 4e9edf6..aa2fd34 100644
--- 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
@@ -17,6 +17,18 @@ public interface ILabelAlertTimerAppService : IApplicationService
/// 方法名避免 Get 前缀,确保 ABP 约定为 POST(路径仍为 app-list)。
Task> AppListAsync(LabelAlertTimerGetListInputVo input);
+ ///
+ /// Web/App:按告警模板倒计时手动新增计时器
+ ///
+ Task CreateAsync(LabelAlertTimerCreateInputVo input);
+
+ ///
+ /// App:POST /label-alert-timer/{alertTemplateId} 兼容新增
+ ///
+ Task CreateByTemplateIdAsync(
+ string alertTemplateId,
+ LabelAlertTimerCreateInputVo? 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.Contracts/Json/AlertTemplateDurationUnitJsonConverter.cs b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Json/AlertTemplateDurationUnitJsonConverter.cs
new file mode 100644
index 0000000..bfb59de
--- /dev/null
+++ b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Json/AlertTemplateDurationUnitJsonConverter.cs
@@ -0,0 +1,81 @@
+using System.Text.Json;
+using System.Text.Json.Serialization;
+using FoodLabeling.Domain.Shared.Enums;
+
+namespace FoodLabeling.Application.Contracts.Json;
+
+///
+/// 时长单位:英文枚举名、数字、中文(年/月/日/时/分/秒/组合时间)均可。
+///
+public sealed class AlertTemplateDurationUnitJsonConverter : JsonConverter
+{
+ public override AlertTemplateDurationUnit Read(
+ ref Utf8JsonReader reader,
+ Type typeToConvert,
+ JsonSerializerOptions options)
+ {
+ if (reader.TokenType == JsonTokenType.Number && reader.TryGetInt32(out var num))
+ {
+ if (Enum.IsDefined(typeof(AlertTemplateDurationUnit), num))
+ {
+ return (AlertTemplateDurationUnit)num;
+ }
+
+ throw new JsonException("durationUnit is invalid.");
+ }
+
+ if (reader.TokenType != JsonTokenType.String)
+ {
+ throw new JsonException("durationUnit must be a string or number.");
+ }
+
+ if (!TryParse(reader.GetString(), out var unit))
+ {
+ throw new JsonException("durationUnit is invalid.");
+ }
+
+ return unit;
+ }
+
+ public override void Write(
+ Utf8JsonWriter writer,
+ AlertTemplateDurationUnit value,
+ JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.ToString());
+ }
+
+ public static bool TryParse(string? raw, out AlertTemplateDurationUnit unit)
+ {
+ unit = default;
+ var s = raw?.Trim();
+ if (string.IsNullOrWhiteSpace(s))
+ {
+ return false;
+ }
+
+ if (int.TryParse(s, out var num) && Enum.IsDefined(typeof(AlertTemplateDurationUnit), num))
+ {
+ unit = (AlertTemplateDurationUnit)num;
+ return true;
+ }
+
+ if (Enum.TryParse(s, true, out unit) && Enum.IsDefined(unit))
+ {
+ return true;
+ }
+
+ unit = s switch
+ {
+ "年" or "year" or "years" => AlertTemplateDurationUnit.Year,
+ "月" or "month" or "months" => AlertTemplateDurationUnit.Month,
+ "日" or "天" or "day" or "days" => AlertTemplateDurationUnit.Day,
+ "时" or "小时" or "hour" or "hours" => AlertTemplateDurationUnit.Hour,
+ "分" or "分钟" or "minute" or "minutes" => AlertTemplateDurationUnit.Minute,
+ "秒" or "second" or "seconds" => AlertTemplateDurationUnit.Second,
+ "组合时间" or "组合" or "combined" => AlertTemplateDurationUnit.Combined,
+ _ => 0
+ };
+ return unit != 0;
+ }
+}
diff --git a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/FoodLabeling.Application.csproj b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/FoodLabeling.Application.csproj
index 5560f89..6b512e3 100644
--- a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/FoodLabeling.Application.csproj
+++ b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/FoodLabeling.Application.csproj
@@ -42,6 +42,9 @@
FoodLabeling.TenantMigrations.fl_alert_template.sql
+
+ FoodLabeling.TenantMigrations.fl_alert_template_countdown.sql
+
FoodLabeling.TenantMigrations.fl_label_alert_timer_alert_template.sql
diff --git a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/AlertTemplateDurationHelper.cs b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/AlertTemplateDurationHelper.cs
new file mode 100644
index 0000000..12d6797
--- /dev/null
+++ b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/AlertTemplateDurationHelper.cs
@@ -0,0 +1,80 @@
+using FoodLabeling.Application.Services.DbModels;
+using FoodLabeling.Domain.Shared.Enums;
+using Volo.Abp;
+
+namespace FoodLabeling.Application.Helpers;
+
+/// 告警模板时长:单位 + 数字 → 到期时刻 / 秒数。
+public static class AlertTemplateDurationHelper
+{
+ public static DateTime AddTo(DateTime start, AlertTemplateDurationUnit unit, int value)
+ {
+ return unit switch
+ {
+ AlertTemplateDurationUnit.Year => start.AddYears(value),
+ AlertTemplateDurationUnit.Month => start.AddMonths(value),
+ AlertTemplateDurationUnit.Day => start.AddDays(value),
+ AlertTemplateDurationUnit.Hour => start.AddHours(value),
+ AlertTemplateDurationUnit.Minute => start.AddMinutes(value),
+ AlertTemplateDurationUnit.Second => start.AddSeconds(value),
+ AlertTemplateDurationUnit.Combined => start.AddSeconds(value),
+ _ => throw new UserFriendlyException("durationUnit is invalid.")
+ };
+ }
+
+ public static int ToDurationSeconds(AlertTemplateDurationUnit unit, int value)
+ {
+ var now = DateTime.Now;
+ var end = AddTo(now, unit, value);
+ return Math.Max(1, (int)Math.Min(int.MaxValue, (end - now).TotalSeconds));
+ }
+
+ public static int MaxValue(AlertTemplateDurationUnit unit) =>
+ unit switch
+ {
+ AlertTemplateDurationUnit.Year => 100,
+ AlertTemplateDurationUnit.Month => 1200,
+ AlertTemplateDurationUnit.Day => 3650,
+ AlertTemplateDurationUnit.Hour => 87600,
+ AlertTemplateDurationUnit.Minute => 5256000,
+ AlertTemplateDurationUnit.Second => 365 * 24 * 3600,
+ AlertTemplateDurationUnit.Combined => 365 * 24 * 3600,
+ _ => 0
+ };
+
+ public static bool TryResolve(
+ FlAlertTemplateDbEntity row,
+ out AlertTemplateDurationUnit unit,
+ out int value)
+ {
+ unit = default;
+ value = 0;
+ if (Enum.IsDefined(row.DurationUnit) &&
+ row.DurationUnit != 0 &&
+ row.DurationValue > 0)
+ {
+ unit = row.DurationUnit;
+ value = row.DurationValue;
+ return true;
+ }
+
+ if (row.CountdownSeconds > 0)
+ {
+ unit = AlertTemplateDurationUnit.Second;
+ value = row.CountdownSeconds;
+ return true;
+ }
+
+ return false;
+ }
+
+ public static (AlertTemplateDurationUnit Unit, int Value) Resolve(FlAlertTemplateDbEntity row)
+ {
+ if (TryResolve(row, out var unit, out var value))
+ {
+ return (unit, value);
+ }
+
+ throw new UserFriendlyException("Alert template duration is not configured.");
+ }
+}
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
index 000c5cb..8cffc95 100644
--- 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
@@ -230,7 +230,7 @@ public static class LabelAlertTimerWriteHelper
return elementName.Contains("到期提醒", StringComparison.Ordinal);
}
- private static async Task ResolveLocationNameAsync(ISqlSugarClient db, string locationId, CancellationToken ct)
+ internal static async Task ResolveLocationNameAsync(ISqlSugarClient db, string locationId, CancellationToken ct)
{
if (string.IsNullOrWhiteSpace(locationId) || !Guid.TryParse(locationId, out var locGuid))
{
@@ -300,13 +300,13 @@ public static class LabelAlertTimerWriteHelper
return string.IsNullOrWhiteSpace(user.UserName) ? null : user.UserName.Trim();
}
- private static string BuildTitle(string labelName, int durationSeconds)
+ internal 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)
+ internal static string BuildSubtitle(int durationSeconds, DateTime expiresAt)
{
var hoursText = FormatDurationHoursLabel(durationSeconds);
var timeText = expiresAt.ToString("h:mm tt", CultureInfo.CurrentCulture);
diff --git a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/MultiTenancy/FoodLabelingTenantMigrationScriptNames.cs b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/MultiTenancy/FoodLabelingTenantMigrationScriptNames.cs
index a062c76..8dc69bb 100644
--- a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/MultiTenancy/FoodLabelingTenantMigrationScriptNames.cs
+++ b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/MultiTenancy/FoodLabelingTenantMigrationScriptNames.cs
@@ -28,6 +28,9 @@ public static class FoodLabelingTenantMigrationScriptNames
public const string AlertTemplate = "FoodLabeling.TenantMigrations.fl_alert_template.sql";
+ public const string AlertTemplateCountdown =
+ "FoodLabeling.TenantMigrations.fl_alert_template_countdown.sql";
+
public const string LabelAlertTimerAlertTemplate =
"FoodLabeling.TenantMigrations.fl_label_alert_timer_alert_template.sql";
@@ -48,6 +51,7 @@ public static class FoodLabelingTenantMigrationScriptNames
LabelAlertTimer,
BoundLabel,
AlertTemplate,
+ AlertTemplateCountdown,
LabelAlertTimerAlertTemplate,
MenuHidePlatformQrCodes
];
diff --git a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/MultiTenancy/TenantSqlScriptExecutor.cs b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/MultiTenancy/TenantSqlScriptExecutor.cs
index 8bbf6e4..2eb902c 100644
--- a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/MultiTenancy/TenantSqlScriptExecutor.cs
+++ b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/MultiTenancy/TenantSqlScriptExecutor.cs
@@ -1,4 +1,4 @@
-using System.Text;
+using System.Text;
using System.Text.RegularExpressions;
using MySqlConnector;
using SqlSugar;
@@ -45,6 +45,10 @@ public static class TenantSqlScriptExecutor
{
await command.ExecuteNonQueryAsync(cancellationToken);
}
+ catch (MySqlException ex) when (ex.Number is 1060 or 1061)
+ {
+ // 1060 Duplicate column;1061 Duplicate key。幂等 ALTER 可忽略。
+ }
catch (MySqlException ex)
{
throw new InvalidOperationException(
@@ -81,7 +85,8 @@ public static class TenantSqlScriptExecutor
var trimmed = line.Trim();
if (PrepareBlockEndRegex.IsMatch(trimmed)
|| CreateTableEndRegex.IsMatch(trimmed)
- || (trimmed.StartsWith("UPDATE ", StringComparison.OrdinalIgnoreCase) && trimmed.EndsWith(';')))
+ || (trimmed.StartsWith("UPDATE ", StringComparison.OrdinalIgnoreCase) && trimmed.EndsWith(';'))
+ || (trimmed.StartsWith("ALTER ", StringComparison.OrdinalIgnoreCase) && trimmed.EndsWith(';')))
{
var batch = current.ToString().Trim();
if (!string.IsNullOrEmpty(batch))
diff --git a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/AlertTemplateAppService.cs b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/AlertTemplateAppService.cs
index b1e3b4c..b268c90 100644
--- a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/AlertTemplateAppService.cs
+++ b/泰额版/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;
using FoodLabeling.Application.Contracts.IServices;
using FoodLabeling.Application.Helpers;
using FoodLabeling.Application.Services.DbModels;
+using FoodLabeling.Domain.Shared.Enums;
using FoodLabeling.Domain.Shared.Helpers;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
@@ -14,7 +15,7 @@ using Yi.Framework.SqlSugarCore.Abstractions;
namespace FoodLabeling.Application.Services;
///
-/// 告警日期时间格式模板(平台告警页 / 标签模板到期提醒下拉)
+/// 告警模板(倒计时秒数;平台告警页 / 手动新增计时器)
///
[Authorize]
public class AlertTemplateAppService : ApplicationService, IAlertTemplateAppService
@@ -57,6 +58,7 @@ public class AlertTemplateAppService : ApplicationService, IAlertTemplateAppServ
[Route("/api/app/alert-template/list")]
public async Task> ListAsync(AlertTemplateGetListInputVo input)
{
+ await EnsureCountdownColumnAsync(_dbContext.SqlSugarClient);
input ??= new AlertTemplateGetListInputVo();
var keyword = input.Keyword?.Trim();
RefAsync total = 0;
@@ -97,6 +99,7 @@ public class AlertTemplateAppService : ApplicationService, IAlertTemplateAppServ
[Route("/api/app/alert-template/{id}")]
public async Task GetAsync(string id)
{
+ await EnsureCountdownColumnAsync(_dbContext.SqlSugarClient);
var entity = await FindActiveAsync(id);
return MapDto(entity);
}
@@ -108,15 +111,17 @@ public class AlertTemplateAppService : ApplicationService, IAlertTemplateAppServ
/// 示例请求:
/// ```json
/// {
- /// "templateName": "US 过期展示",
- /// "dateTimeFormat": "MM/dd/yyyy h:mm tt",
+ /// "templateName": "冷藏 3 日",
+ /// "durationUnit": "Day",
+ /// "durationValue": 3,
/// "state": true
/// }
/// ```
///
/// 参数说明:
/// - templateName: 模板名称
- /// - dateTimeFormat: 日期时间格式字符串(原样存储,用于 formattedExpiresAt)
+ /// - durationUnit: 年/月/日/时/分/秒/组合时间(或 Year/Month/Day/Hour/Minute/Second/Combined)
+ /// - durationValue: 数字,与单位组合成 3年、3月、3日;组合时间为总秒数
/// - state: 是否启用
///
/// 模板字段
@@ -128,13 +133,17 @@ public class AlertTemplateAppService : ApplicationService, IAlertTemplateAppServ
[Route("/api/app/alert-template")]
public async Task CreateAsync(AlertTemplateCreateInputVo input)
{
- var (name, format) = ValidateInput(input);
+ await EnsureCountdownColumnAsync(_dbContext.SqlSugarClient);
+ var (name, unit, value, seconds) = ValidateInput(input);
var now = DateTime.Now;
var entity = new FlAlertTemplateDbEntity
{
Id = YitIdHelper.NextId().ToString(),
TemplateName = name,
- DateTimeFormat = format,
+ DurationUnit = unit,
+ DurationValue = value,
+ CountdownSeconds = seconds,
+ DateTimeFormat = seconds.ToString(),
State = input.State,
IsDeleted = false,
CreatedBy = CurrentUser?.Id?.ToString(),
@@ -161,10 +170,14 @@ public class AlertTemplateAppService : ApplicationService, IAlertTemplateAppServ
[Route("/api/app/alert-template/{id}")]
public async Task UpdateAsync(string id, AlertTemplateCreateInputVo input)
{
+ await EnsureCountdownColumnAsync(_dbContext.SqlSugarClient);
var entity = await FindActiveAsync(id);
- var (name, format) = ValidateInput(input);
+ var (name, unit, value, seconds) = ValidateInput(input);
entity.TemplateName = name;
- entity.DateTimeFormat = format;
+ entity.DurationUnit = unit;
+ entity.DurationValue = value;
+ entity.CountdownSeconds = seconds;
+ entity.DateTimeFormat = seconds.ToString();
entity.State = input.State;
entity.LastModificationTime = DateTime.Now;
await _dbContext.SqlSugarClient.Updateable(entity).ExecuteCommandAsync();
@@ -193,23 +206,29 @@ public class AlertTemplateAppService : ApplicationService, IAlertTemplateAppServ
///
/// 启用中的告警模板下拉(标签模板编辑器到期提醒)
///
- /// id / templateName / dateTimeFormat
+ /// id / templateName / durationUnit / durationValue
/// 成功
/// 服务器错误
[HttpGet]
[Route("/api/app/alert-template/options")]
public async Task> GetOptionsAsync()
{
+ await EnsureCountdownColumnAsync(_dbContext.SqlSugarClient);
var rows = await _dbContext.SqlSugarClient.Queryable()
.Where(x => !x.IsDeleted && x.State)
.OrderByDescending(x => x.LastModificationTime)
.OrderByDescending(x => x.CreationTime)
.ToListAsync();
- return rows.Select(x => new AlertTemplateOptionDto
+ return rows.Select(x =>
{
- Id = x.Id,
- TemplateName = x.TemplateName,
- DateTimeFormat = x.DateTimeFormat
+ AlertTemplateDurationHelper.TryResolve(x, out var unit, out var value);
+ return new AlertTemplateOptionDto
+ {
+ Id = x.Id,
+ TemplateName = x.TemplateName,
+ DurationUnit = unit,
+ DurationValue = value
+ };
}).ToList();
}
@@ -231,7 +250,50 @@ public class AlertTemplateAppService : ApplicationService, IAlertTemplateAppServ
return entity;
}
- private static (string Name, string Format) ValidateInput(AlertTemplateCreateInputVo? input)
+ private static int _countdownColumnEnsured;
+
+ internal static async Task EnsureCountdownColumnAsync(ISqlSugarClient db)
+ {
+ if (Volatile.Read(ref _countdownColumnEnsured) == 1)
+ {
+ return;
+ }
+
+ try
+ {
+ await db.Ado.ExecuteCommandAsync(
+ "ALTER TABLE `fl_alert_template` ADD COLUMN `CountdownSeconds` int NOT NULL DEFAULT 0 COMMENT '倒计时秒数'");
+ }
+ catch
+ {
+ // 列已存在
+ }
+
+ try
+ {
+ await db.Ado.ExecuteCommandAsync(
+ "ALTER TABLE `fl_alert_template` ADD COLUMN `DurationUnit` int NOT NULL DEFAULT 6 COMMENT '时长单位'");
+ }
+ catch
+ {
+ // 列已存在
+ }
+
+ try
+ {
+ await db.Ado.ExecuteCommandAsync(
+ "ALTER TABLE `fl_alert_template` ADD COLUMN `DurationValue` int NOT NULL DEFAULT 0 COMMENT '时长数字'");
+ }
+ catch
+ {
+ // 列已存在
+ }
+
+ Volatile.Write(ref _countdownColumnEnsured, 1);
+ }
+
+ private static (string Name, AlertTemplateDurationUnit Unit, int Value, int Seconds)
+ ValidateInput(AlertTemplateCreateInputVo? input)
{
if (input is null)
{
@@ -244,23 +306,33 @@ public class AlertTemplateAppService : ApplicationService, IAlertTemplateAppServ
throw new UserFriendlyException("Template name is required.");
}
- var format = input.DateTimeFormat?.Trim();
- if (string.IsNullOrWhiteSpace(format))
+ if (!Enum.IsDefined(input.DurationUnit) || input.DurationUnit == 0)
{
- throw new UserFriendlyException("Date/time format is required.");
+ throw new UserFriendlyException("durationUnit is required (Year/Month/Day/Hour/Minute/Second/Combined).");
}
- return (name, format);
+ var max = AlertTemplateDurationHelper.MaxValue(input.DurationUnit);
+ if (input.DurationValue <= 0 || input.DurationValue > max)
+ {
+ throw new UserFriendlyException($"durationValue must be between 1 and {max}.");
+ }
+
+ var seconds = AlertTemplateDurationHelper.ToDurationSeconds(input.DurationUnit, input.DurationValue);
+ return (name, input.DurationUnit, input.DurationValue, seconds);
}
- private static AlertTemplateDto MapDto(FlAlertTemplateDbEntity x) =>
- new()
+ private static AlertTemplateDto MapDto(FlAlertTemplateDbEntity x)
+ {
+ AlertTemplateDurationHelper.TryResolve(x, out var unit, out var value);
+ return new AlertTemplateDto
{
Id = x.Id,
TemplateName = x.TemplateName,
- DateTimeFormat = x.DateTimeFormat,
+ DurationUnit = unit,
+ DurationValue = value,
State = x.State,
CreationTime = x.CreationTime,
LastModificationTime = x.LastModificationTime
};
+ }
}
diff --git a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/DbModels/FlAlertTemplateDbEntity.cs b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/DbModels/FlAlertTemplateDbEntity.cs
index 9065ccc..5084e1c 100644
--- a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/DbModels/FlAlertTemplateDbEntity.cs
+++ b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/DbModels/FlAlertTemplateDbEntity.cs
@@ -1,8 +1,9 @@
+using FoodLabeling.Domain.Shared.Enums;
using SqlSugar;
namespace FoodLabeling.Application.Services.DbModels;
-/// 告警日期时间格式模板(fl_alert_template)
+/// 告警模板(fl_alert_template):时长单位 + 数字
[SugarTable("fl_alert_template")]
public class FlAlertTemplateDbEntity
{
@@ -11,6 +12,16 @@ public class FlAlertTemplateDbEntity
public string TemplateName { get; set; } = string.Empty;
+ /// 时长单位,见
+ public AlertTemplateDurationUnit DurationUnit { get; set; }
+
+ /// 时长数字(与单位组合成 3年、3日等)
+ public int DurationValue { get; set; }
+
+ /// 换算后的倒计时秒数(创建计时器展示用)
+ public int CountdownSeconds { get; set; }
+
+ /// 历史列,保留兼容。
public string DateTimeFormat { get; set; } = string.Empty;
public bool State { get; set; } = true;
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
index 9ac1e21..900a350 100644
--- 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
@@ -5,6 +5,8 @@ using FoodLabeling.Application.Helpers;
using FoodLabeling.Application.Services.DbModels;
using FoodLabeling.Domain.Entities;
using FoodLabeling.Domain.Shared;
+using FoodLabeling.Domain.Shared.Enums;
+using FoodLabeling.Domain.Shared.Helpers;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Distributed;
@@ -58,7 +60,8 @@ public class LabelAlertTimerAppService : ApplicationService, ILabelAlertTimerApp
/// 参数错误或You are not signed in./无门店权限
/// 服务器错误
[Authorize]
- [HttpPost("label-alert-timer/list")]
+ [HttpPost]
+ [Route("/api/app/label-alert-timer/list")]
public virtual async Task> GetListAsync(
LabelAlertTimerGetListInputVo input)
{
@@ -91,6 +94,152 @@ public class LabelAlertTimerAppService : ApplicationService, ILabelAlertTimerApp
}
///
+ /// 按告警模板手动新增计时器(Web / App 共用)
+ ///
+ ///
+ /// 读取模板时长(单位 + 数字,如 3 日),从当前时刻起倒计时,写入 fl_label_alert_timer(无需新表),
+ /// 随后会出现在 list / app-list。
+ ///
+ /// 示例请求:
+ /// ```json
+ /// {
+ /// "alertTemplateId": "123456789",
+ /// "locationId": "3a2473aa-98f1-e2ab-b50a-2efcb8bfdb54"
+ /// }
+ /// ```
+ ///
+ /// 参数说明:
+ /// - alertTemplateId: 启用中的告警模板 Id
+ /// - locationId: 门店;空则取已选门店缓存
+ ///
+ /// 模板与门店
+ /// 新建计时器(含 remainingTime)
+ /// 成功
+ /// 未登录、模板无效、未选门店
+ /// 服务器错误
+ [Authorize]
+ [HttpPost]
+ [Route("/api/app/label-alert-timer/create")]
+ [Route("/api/app/label-alert-timer")]
+ public virtual async Task CreateAsync(LabelAlertTimerCreateInputVo input)
+ {
+ if (input is null)
+ {
+ throw new UserFriendlyException("Request body is required.");
+ }
+
+ if (!CurrentUser.Id.HasValue)
+ {
+ throw new UserFriendlyException("You are not signed in.");
+ }
+
+ var templateId = input.AlertTemplateId?.Trim();
+ if (string.IsNullOrWhiteSpace(templateId))
+ {
+ throw new UserFriendlyException("Alert template Id is required.");
+ }
+
+ var db = _dbContext.SqlSugarClient;
+ await AlertTemplateAppService.EnsureCountdownColumnAsync(db);
+ var template = (await db.Queryable()
+ .Where(x => x.Id == templateId && !x.IsDeleted && x.State)
+ .Take(1)
+ .ToListAsync())
+ .FirstOrDefault();
+ if (template is null)
+ {
+ throw new UserFriendlyException("Alert template not found or disabled.");
+ }
+
+ var (unit, value) = AlertTemplateDurationHelper.Resolve(template);
+ var now = DateTime.Now;
+ var expiresAt = AlertTemplateDurationHelper.AddTo(now, unit, value);
+ var countdown = Math.Max(1, (int)Math.Min(int.MaxValue, (expiresAt - now).TotalSeconds));
+
+ var locationId = input.LocationId?.Trim();
+ if (string.IsNullOrWhiteSpace(locationId))
+ {
+ var cache = await UsAppAuthScopeHelper.GetAdminScopeCacheAsync(
+ _distributedCache,
+ CurrentUser.Id.Value);
+ locationId = cache?.Location?.Id?.Trim();
+ }
+
+ if (string.IsNullOrWhiteSpace(locationId))
+ {
+ throw new UserFriendlyException("Select a location or pass locationId.");
+ }
+
+ await UsAppPrintLogScopeHelper.EnsureUserCanAccessLocationAsync(
+ CurrentUser, db, locationId);
+
+ var locationName = await LabelAlertTimerWriteHelper.ResolveLocationNameAsync(
+ db, locationId, CancellationToken.None);
+ var labelName = string.IsNullOrWhiteSpace(template.TemplateName)
+ ? FoodLabelingDisplayConsts.NotAvailable
+ : template.TemplateName.Trim();
+ var userId = CurrentUser.Id.Value.ToString();
+ var timerId = YitIdHelper.NextId().ToString();
+ var entity = new FlLabelAlertTimerDbEntity
+ {
+ Id = timerId,
+ BatchId = timerId,
+ PrintTaskId = string.Empty,
+ LabelId = string.Empty,
+ LabelName = labelName,
+ LocationId = locationId,
+ LocationName = locationName,
+ PrintedAt = now,
+ BaseTime = now,
+ ExpiresAt = expiresAt,
+ DurationSeconds = countdown,
+ Title = LabelAlertTimerWriteHelper.BuildTitle(labelName, countdown),
+ Subtitle = LabelAlertTimerWriteHelper.BuildSubtitle(countdown, expiresAt),
+ AlertTemplateId = template.Id,
+ AlertTemplateName = template.TemplateName,
+ DateTimeFormat = ReportsDateTimeDisplayHelper.DateTimeDisplayFormat,
+ PrintedByUserId = userId,
+ PrintedByUserName = CurrentUser.UserName,
+ IsDeleted = false,
+ CreatedBy = userId,
+ CreationTime = now
+ };
+ await db.Insertable(entity).ExecuteCommandAsync();
+ var dto = MapListItem(entity, now);
+ dto.Source = nameof(LabelAlertTimerSource.Manual).ToLowerInvariant();
+ return dto;
+ }
+
+ ///
+ /// App:按模板 Id 路径新增计时器(兼容 POST /label-alert-timer/{templateId})
+ ///
+ ///
+ /// 与 /create 相同逻辑;路径上的数字 Id 作为 alertTemplateId。
+ /// 避免该 POST 命中 DELETE {id} 后返回 405。
+ ///
+ /// 告警模板 Id(YitId)
+ /// 可选 body,可带 locationId
+ /// 新建计时器
+ /// 成功
+ /// 未登录、模板无效、未选门店
+ /// 服务器错误
+ [Authorize]
+ [HttpPost]
+ [Route("/api/app/label-alert-timer/{alertTemplateId:regex(^\\d+$)}")]
+ public virtual Task CreateByTemplateIdAsync(
+ string alertTemplateId,
+ [FromBody] LabelAlertTimerCreateInputVo? input)
+ {
+ input ??= new LabelAlertTimerCreateInputVo();
+ if (string.IsNullOrWhiteSpace(input.AlertTemplateId))
+ {
+ input.AlertTemplateId = alertTemplateId;
+ }
+
+ return CreateAsync(input);
+ }
+
+ ///
/// App:告警列表(含倒计时;筛选项为当前门店/公司,过期时间默认当天及之后)
///
///
@@ -126,7 +275,8 @@ public class LabelAlertTimerAppService : ApplicationService, ILabelAlertTimerApp
/// Not signed in, no locations, or no permission
/// 服务器错误
[Authorize]
- [HttpPost("label-alert-timer/app-list")]
+ [HttpPost]
+ [Route("/api/app/label-alert-timer/app-list")]
public virtual async Task> AppListAsync(
LabelAlertTimerGetListInputVo input)
{
@@ -174,14 +324,15 @@ public class LabelAlertTimerAppService : ApplicationService, ILabelAlertTimerApp
///
///
/// 删除前校验当前用户可访问该计时器所属门店。
- /// id 路由约束为数字(YitId),避免 app-list 等字面路径被 {id} 匹配后对 POST 返回 405。
+ /// id 仅匹配数字(YitId),避免 create / app-list 被 {id} 吃掉后对 POST 返回 405。
///
/// 计时器 Id
/// 删除成功
/// 记录不存在或无门店权限
/// 服务器错误
[Authorize]
- [HttpDelete("label-alert-timer/{id}")]
+ [HttpDelete]
+ [Route("/api/app/label-alert-timer/{id:regex(^\\d+$)}")]
public virtual async Task DeleteAsync(string id)
{
var timerId = id?.Trim();
@@ -269,7 +420,8 @@ public class LabelAlertTimerAppService : ApplicationService, ILabelAlertTimerApp
/// 未提供任何标识
/// 服务器错误
[Authorize]
- [HttpPost("label-alert-timer/check-expired")]
+ [HttpPost]
+ [Route("/api/app/label-alert-timer/check-expired")]
public virtual async Task CheckExpiredAsync(
LabelAlertTimerCheckExpiredInputVo input)
{
@@ -497,6 +649,29 @@ public class LabelAlertTimerAppService : ApplicationService, ILabelAlertTimerApp
now));
}
+ foreach (var row in liveTimers.Where(x => string.IsNullOrWhiteSpace(x.PrintTaskId)))
+ {
+ if (locationIds is not null &&
+ (string.IsNullOrWhiteSpace(row.LocationId) ||
+ !locationIds.Contains(row.LocationId, StringComparer.OrdinalIgnoreCase)))
+ {
+ continue;
+ }
+
+ if (fromToday.HasValue && row.ExpiresAt < fromToday.Value)
+ {
+ continue;
+ }
+
+ if (dayStart.HasValue && dayEndExcl.HasValue &&
+ (row.ExpiresAt < dayStart.Value || row.ExpiresAt >= dayEndExcl.Value))
+ {
+ continue;
+ }
+
+ mapped.Add(MapListItem(row, now));
+ }
+
mapped = mapped
.OrderByDescending(x => x.ExpiresAt)
.ThenByDescending(x => x.PrintedAt)
@@ -546,6 +721,9 @@ public class LabelAlertTimerAppService : ApplicationService, ILabelAlertTimerApp
DateTimeFormat = row.DateTimeFormat,
PrintedByUserId = row.PrintedByUserId,
PrintedByUserName = row.PrintedByUserName,
+ Source = string.IsNullOrWhiteSpace(row.PrintTaskId)
+ ? nameof(LabelAlertTimerSource.Manual).ToLowerInvariant()
+ : nameof(LabelAlertTimerSource.PrintLog).ToLowerInvariant(),
ExpiredMessageTemplate = LabelAlertTimerDisplayHelper.ExpiredMessageTemplate
};
}
@@ -623,6 +801,7 @@ public class LabelAlertTimerAppService : ApplicationService, ILabelAlertTimerApp
DateTimeFormat = format,
PrintedByUserId = task.CreatedBy ?? timer?.PrintedByUserId,
PrintedByUserName = timer?.PrintedByUserName,
+ Source = nameof(LabelAlertTimerSource.PrintLog).ToLowerInvariant(),
ExpiredMessageTemplate = LabelAlertTimerDisplayHelper.ExpiredMessageTemplate
};
}
diff --git a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Domain.Shared/Enums/AlertTemplateDurationUnit.cs b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Domain.Shared/Enums/AlertTemplateDurationUnit.cs
new file mode 100644
index 0000000..3f87bac
--- /dev/null
+++ b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Domain.Shared/Enums/AlertTemplateDurationUnit.cs
@@ -0,0 +1,28 @@
+namespace FoodLabeling.Domain.Shared.Enums;
+
+///
+/// 告警模板时长单位:与 durationValue 组合成「3年 / 3月 / 3日」等。
+///
+public enum AlertTemplateDurationUnit
+{
+ /// 年
+ Year = 1,
+
+ /// 月
+ Month = 2,
+
+ /// 日
+ Day = 3,
+
+ /// 时
+ Hour = 4,
+
+ /// 分
+ Minute = 5,
+
+ /// 秒
+ Second = 6,
+
+ /// 组合时间(durationValue 为总秒数,如 1 小时 30 分 = 5400)
+ Combined = 7
+}
diff --git a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Domain.Shared/Enums/LabelAlertTimerSource.cs b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Domain.Shared/Enums/LabelAlertTimerSource.cs
new file mode 100644
index 0000000..1c6bb4a
--- /dev/null
+++ b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Domain.Shared/Enums/LabelAlertTimerSource.cs
@@ -0,0 +1,13 @@
+namespace FoodLabeling.Domain.Shared.Enums;
+
+///
+/// 告警计时器来源。
+///
+public enum LabelAlertTimerSource
+{
+ /// 打印日志过期时间
+ PrintLog = 0,
+
+ /// 按告警模板手动新增
+ Manual = 1
+}
diff --git a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/scripts/fl_alert_template.sql b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/scripts/fl_alert_template.sql
index 6ed8a8e..6f89ea4 100644
--- a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/scripts/fl_alert_template.sql
+++ b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/scripts/fl_alert_template.sql
@@ -1,4 +1,4 @@
--- 告警日期时间格式模板(租户业务库)
+-- 告警模板(租户业务库):倒计时秒数
-- 执行前请备份;可重复执行
SET @db := DATABASE();
@@ -6,7 +6,10 @@ SET @db := DATABASE();
CREATE TABLE IF NOT EXISTS `fl_alert_template` (
`Id` varchar(36) NOT NULL COMMENT '主键(YitId)',
`TemplateName` varchar(200) NOT NULL COMMENT '模板名称',
- `DateTimeFormat` varchar(100) NOT NULL COMMENT '日期时间格式(如 MM/dd/yyyy h:mm tt)',
+ `DurationUnit` int NOT NULL DEFAULT 6 COMMENT '1年 2月 3日 4时 5分 6秒 7组合时间',
+ `DurationValue` int NOT NULL DEFAULT 0 COMMENT '时长数字',
+ `CountdownSeconds` int NOT NULL DEFAULT 0 COMMENT '换算后的倒计时秒数',
+ `DateTimeFormat` varchar(100) NOT NULL COMMENT '兼容旧列',
`State` tinyint(1) NOT NULL DEFAULT 1 COMMENT '启用状态',
`IsDeleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '软删',
`DeletionTime` datetime DEFAULT NULL,
diff --git a/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/scripts/fl_alert_template_countdown.sql b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/scripts/fl_alert_template_countdown.sql
new file mode 100644
index 0000000..d9788fc
--- /dev/null
+++ b/泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/scripts/fl_alert_template_countdown.sql
@@ -0,0 +1,10 @@
+-- 告警模板补列:倒计时秒数 + 单位 + 数字(列已存在时忽略 1060)
+
+ALTER TABLE `fl_alert_template`
+ ADD COLUMN `CountdownSeconds` int NOT NULL DEFAULT 0 COMMENT '倒计时秒数' AFTER `TemplateName`;
+
+ALTER TABLE `fl_alert_template`
+ ADD COLUMN `DurationUnit` int NOT NULL DEFAULT 6 COMMENT '1年 2月 3日 4时 5分 6秒 7组合时间' AFTER `TemplateName`;
+
+ALTER TABLE `fl_alert_template`
+ ADD COLUMN `DurationValue` int NOT NULL DEFAULT 0 COMMENT '时长数字' AFTER `DurationUnit`;
diff --git a/项目相关文档/2026-10-22告警接口文档.md b/项目相关文档/2026-10-22告警接口文档.md
new file mode 100644
index 0000000..7fbb72d
--- /dev/null
+++ b/项目相关文档/2026-10-22告警接口文档.md
@@ -0,0 +1,297 @@
+# 2026-10-22 告警接口文档
+
+范围:泰额 **告警模板** CRUD / 下拉,以及 **按模板新增计时器**。不含登录、门店。
+统一包装:成功时业务数据在 `data`(camelCase)。
+鉴权:请求头 `Authorization` 使用公司登录返回的 token(已含 `Bearer ` 则原样带上)。
+须已解析业务租户,且该公司主库初始化状态为 1。
+
+**时长字段**:两个字段组合,例如 3 年、3 月、3 日。
+
+| 字段 | 说明 |
+|------|------|
+| durationUnit | 类型:年 / 月 / 日 / 时 / 分 / 秒 / 组合时间 |
+| durationValue | 数字,与类型组合 |
+
+分页约定:`skipCount` 为**页码(从 1 开始)**,`maxResultCount` 为每页条数。
+
+---
+
+## 0. durationUnit 取值
+
+接口 JSON 推荐英文枚举名,也接受中文或数字。
+
+| 值(推荐) | 中文别名 | 数字 | 与 durationValue 的含义 |
+|------------|----------|------|-------------------------|
+| Year | 年 | 1 | 3 → 3 年 |
+| Month | 月 | 2 | 3 → 3 月 |
+| Day | 日 / 天 | 3 | 3 → 3 日 |
+| Hour | 时 / 小时 | 4 | 3 → 3 小时 |
+| Minute | 分 / 分钟 | 5 | 30 → 30 分钟 |
+| Second | 秒 | 6 | 90 → 90 秒 |
+| Combined | 组合时间 | 7 | **总秒数**,如 1 小时 30 分 = 5400 |
+
+`durationValue` 必须 ≥ 1。上限:年 100、月 1200、日 3650、时 87600、分 5256000、秒/组合时间 31536000。
+
+---
+
+## 1. 分页列表
+
+**POST** `/api/app/alert-template/list`
+
+```json
+{
+ "keyword": "冷藏",
+ "state": true,
+ "skipCount": 1,
+ "maxResultCount": 20
+}
+```
+
+| 字段 | 类型 | 必填 | 说明 |
+|------|------|------|------|
+| keyword | string | 否 | 模板名称模糊匹配 |
+| state | bool / null | 否 | 启用状态;不传=全部 |
+| skipCount | int | 否 | 页码,从 1 开始 |
+| maxResultCount | int | 否 | 每页条数;≤0 时按 10 |
+
+### data
+
+| 字段 | 类型 | 说明 |
+|------|------|------|
+| pageIndex | int | 当前页 |
+| pageSize | int | 每页条数 |
+| totalCount | long | 总条数 |
+| totalPages | int | 总页数 |
+| items | array | 见第 6 节 |
+
+---
+
+## 2. 详情
+
+**GET** `/api/app/alert-template/{id}`
+
+| 字段 | 位置 | 说明 |
+|------|------|------|
+| id | path | 模板主键(YitId) |
+
+`data` 见第 6 节。
+
+---
+
+## 3. 新增
+
+**POST** `/api/app/alert-template`
+
+```json
+{
+ "templateName": "冷藏 3 日",
+ "durationUnit": "Day",
+ "durationValue": 3,
+ "state": true
+}
+```
+
+中文单位也可以:
+
+```json
+{
+ "templateName": "保质 3 年",
+ "durationUnit": "年",
+ "durationValue": 3,
+ "state": true
+}
+```
+
+组合时间(总秒数):
+
+```json
+{
+ "templateName": "1小时30分",
+ "durationUnit": "组合时间",
+ "durationValue": 5400,
+ "state": true
+}
+```
+
+| 字段 | 类型 | 必填 | 说明 |
+|------|------|------|------|
+| templateName | string | 是 | 模板名称 |
+| durationUnit | string / int | 是 | 见第 0 节 |
+| durationValue | int | 是 | 时长数字 |
+| state | bool | 否 | 是否启用,默认 true |
+
+`data` 为新建后的模板对象(含 `id`)。
+
+---
+
+## 4. 编辑
+
+**PUT** `/api/app/alert-template/{id}`
+
+body 与新增相同。
+
+---
+
+## 5. 软删除
+
+**DELETE** `/api/app/alert-template/{id}`
+
+成功:HTTP 200。列表不再出现。
+
+---
+
+## 6. 模板对象(列表 / 详情 / 新增 / 编辑出参)
+
+| 字段 | 类型 | 说明 |
+|------|------|------|
+| id | string | 主键(YitId) |
+| templateName | string | 模板名称 |
+| durationUnit | string | `Year` / `Month` / `Day` / `Hour` / `Minute` / `Second` / `Combined` |
+| durationValue | int | 时长数字 |
+| state | bool | 是否启用 |
+| creationTime | datetime | 创建时间 |
+| lastModificationTime | datetime / null | 最后修改时间 |
+
+```json
+{
+ "id": "1234567890123456789",
+ "templateName": "冷藏 3 日",
+ "durationUnit": "Day",
+ "durationValue": 3,
+ "state": true,
+ "creationTime": "2026-10-22T17:00:00",
+ "lastModificationTime": "2026-10-22T17:00:00"
+}
+```
+
+---
+
+## 7. 启用中下拉
+
+**GET** `/api/app/alert-template/options`
+
+仅未删除且 `state=true`。
+
+| 字段 | 类型 | 说明 |
+|------|------|------|
+| id | string | 模板 Id |
+| templateName | string | 名称 |
+| durationUnit | string | 单位 |
+| durationValue | int | 数字 |
+
+---
+
+## 8. 错误码
+
+| HTTP | 场景 |
+|------|------|
+| 200 | 成功 |
+| 400 | 参数无效、模板不存在、未初始化完成 |
+| 401 | 未登录 |
+| 405 | POST 打到了只允许 DELETE 的 `{id}`;请用 `/create` |
+| 500 | 服务器错误 |
+
+| 错误信息 | 原因 |
+|----------|------|
+| Request body is required. | body 为空 |
+| Template name is required. | 未填名称 |
+| durationUnit is required (Year/Month/Day/Hour/Minute/Second/Combined). | 未传或非法单位 |
+| durationValue must be between 1 and {max}. | 数字越界 |
+| Template Id is required. | 路径 id 为空 |
+| Alert template not found. | 不存在或已删除 |
+| Alert template not found or disabled. | 新增计时器时模板不存在或未启用 |
+| Alert template duration is not configured. | 模板未配置单位+数字 |
+| Select a location or pass locationId. | 新增计时器未选门店 |
+
+---
+
+## 9. 库表
+
+`fl_alert_template`(租户业务库)
+
+| 列 | 说明 |
+|----|------|
+| DurationUnit | 1年 2月 3日 4时 5分 6秒 7组合时间 |
+| DurationValue | 时长数字 |
+| CountdownSeconds | 创建时换算的秒数(内部用) |
+
+首次调接口会自动补列。
+
+---
+
+## 10. curl
+
+```bash
+# 新增:3 日
+curl -s -X POST "https://flusapi-tetest.3flabeling.com/api/app/alert-template" \
+ -H "Authorization: " \
+ -H "Content-Type: application/json" \
+ -d "{\"templateName\":\"冷藏3日\",\"durationUnit\":\"Day\",\"durationValue\":3,\"state\":true}"
+
+# 新增:3 年(中文单位)
+curl -s -X POST "https://flusapi-tetest.3flabeling.com/api/app/alert-template" \
+ -H "Authorization: " \
+ -H "Content-Type: application/json" \
+ -d "{\"templateName\":\"保质3年\",\"durationUnit\":\"年\",\"durationValue\":3,\"state\":true}"
+
+# 列表
+curl -s -X POST "https://flusapi-tetest.3flabeling.com/api/app/alert-template/list" \
+ -H "Authorization: " \
+ -H "Content-Type: application/json" \
+ -d "{\"keyword\":\"\",\"skipCount\":1,\"maxResultCount\":20}"
+
+# 下拉
+curl -s "https://flusapi-tetest.3flabeling.com/api/app/alert-template/options" \
+ -H "Authorization: "
+
+# 编辑
+curl -s -X PUT "https://flusapi-tetest.3flabeling.com/api/app/alert-template/" \
+ -H "Authorization: " \
+ -H "Content-Type: application/json" \
+ -d "{\"templateName\":\"冷藏3日\",\"durationUnit\":\"日\",\"durationValue\":3,\"state\":true}"
+
+# 删除模板
+curl -s -X DELETE "https://flusapi-tetest.3flabeling.com/api/app/alert-template/" \
+ -H "Authorization: "
+
+# 按模板新增计时器(App 推荐)
+curl -s -X POST "https://flusapi-tetest.3flabeling.com/api/app/label-alert-timer/create" \
+ -H "Authorization: " \
+ -H "Content-Type: application/json" \
+ -d "{\"alertTemplateId\":\"\",\"locationId\":\"\"}"
+
+# 兼容:路径带模板数字 Id
+curl -s -X POST "https://flusapi-tetest.3flabeling.com/api/app/label-alert-timer/" \
+ -H "Authorization: " \
+ -H "Content-Type: application/json" \
+ -d "{\"locationId\":\"\"}"
+```
+
+---
+
+## 11. 按模板新增计时器(Web / App)
+
+从启用中的模板读 `durationUnit` + `durationValue`,从当前时刻倒计时,写入已有表 `fl_label_alert_timer`(`printTaskId` 空)。随后出现在 `list` / `app-list`。
+
+| 方法 | 路径 | 说明 |
+|------|------|------|
+| POST | `/api/app/label-alert-timer/create` | **推荐**;App Confirm 走这条 |
+| POST | `/api/app/label-alert-timer` | 兼容根路径 |
+| POST | `/api/app/label-alert-timer/{alertTemplateId}` | 路径数字 Id = 模板 Id |
+| DELETE | `/api/app/label-alert-timer/{id}` | 软删;`id` 仅数字(YitId) |
+
+`create` / `list` / `app-list` / `check-expired` 是固定路径。`{id}` 只匹配数字,避免 POST `/create` 被当成删除接口而 **405**。
+
+```json
+{
+ "alertTemplateId": "123456789",
+ "locationId": "3a2473aa-98f1-e2ab-b50a-2efcb8bfdb54"
+}
+```
+
+| 字段 | 类型 | 必填 | 说明 |
+|------|------|------|------|
+| alertTemplateId | string | 是(路径版可省略) | 启用中的模板 Id |
+| locationId | string | 否 | 门店;空则已选门店缓存;仍空 400 |
+
+成功 `data` 含 `id`、`remainingTime`、`expiresAt`、`source=manual`。
diff --git a/项目相关文档/2026-10-22接口文档.md b/项目相关文档/2026-10-22接口文档.md
index 3b8a07f..883c067 100644
--- a/项目相关文档/2026-10-22接口文档.md
+++ b/项目相关文档/2026-10-22接口文档.md
@@ -251,7 +251,32 @@ Authorization: <公司 Token>
---
-## 7. 告警计时器(打印日志过期时间列表)
+## 6.1 告警模板(单位 + 数字)
+
+公司业务 Token。完整说明见 `2026-10-22告警接口文档.md`。
+
+两个字段组合:`durationUnit`(年/月/日/时/分/秒/组合时间)+ `durationValue`(数字)→ 3年、3月、3日。
+组合时间时 `durationValue` 为总秒数。
+
+### 新增
+
+**POST** `/api/app/alert-template`
+
+```json
+{
+ "templateName": "冷藏 3 日",
+ "durationUnit": "Day",
+ "durationValue": 3,
+ "state": true
+}
+```
+
+列表 **POST** `/api/app/alert-template/list`;编辑 **PUT** `/api/app/alert-template/{id}`;下拉 **GET** `/api/app/alert-template/options`。
+App 按模板新增计时器见 **7.3.1**(`POST /api/app/label-alert-timer/create`)。
+
+---
+
+## 7. 告警计时器(打印日志过期 + 手动模板计时器)
公司业务 Token。列表按**打印日志实时解析过期时间**(与 Print Log「Expiration」同源,优先打印快照),不要求 `fl_label_alert_timer` 已有行;改过期时间后立刻能查到。
**仅展示倒计时,绝不用于拦截打印。**
@@ -339,18 +364,46 @@ App 只有一个筛选项:当前门店/公司。
| productName | string / null | 产品名 |
| alertTemplateId / alertTemplateName | string / null | 告警模板(可空) |
| dateTimeFormat | string / null | 时间格式 |
+| source | string | `printLog` 打印日志;`manual` 按模板手动新增 |
| printedByUserId / printedByUserName | string / null | 打印人 |
| expiredMessageTemplate | string | `Hi {userName}, your {labelName} label has expired. Please take action.` |
排序:先 `expiresAt` 降序,再 `printedAt` 降序。
-写入规则:打印成功且能解析过期时刻会写入/更新 `fl_label_alert_timer`。列表本身不依赖该表,直接读打印日志过期时间。
+**不需要新表。** 手动计时器写入已有 `fl_label_alert_timer`(`printTaskId` 为空)。列表 = 打印日志过期记录 ∪ 手动计时器。
+
+### 7.3.1 按模板新增计时器(Web / App)
+
+从启用中的告警模板读取 `durationUnit` + `durationValue`,从当前时刻开始倒计时。三条路径等价,推荐第一条。
+
+| 方法 | 路径 | 说明 |
+|------|------|------|
+| POST | `/api/app/label-alert-timer/create` | **推荐**;App 当前用这条 |
+| POST | `/api/app/label-alert-timer` | 兼容 ABP 约定根路径 |
+| POST | `/api/app/label-alert-timer/{alertTemplateId}` | 路径上的数字 Id 当作模板 Id;body 可只带 `locationId` |
+
+`alertTemplateId`、删除用的 `{id}` **必须是数字(YitId)**。`create` / `list` / `app-list` / `check-expired` 不会被 `{id}` 吃掉;否则 POST 会 405。
+
+```json
+{
+ "alertTemplateId": "123456789",
+ "locationId": "3a2473aa-98f1-e2ab-b50a-2efcb8bfdb54"
+}
+```
+
+| 字段 | 类型 | 必填 | 说明 |
+|------|------|------|------|
+| alertTemplateId | string | 是(路径版可省略) | 启用中的告警模板 Id |
+| locationId | string | 否 | 门店;空则已选门店缓存;仍空则 400 |
+
+成功 data 结构同列表 `items[]`,`source=manual`。随后会出现在 list / app-list。
### 7.4 软删除
**DELETE** `/api/app/label-alert-timer/{id}`
-`id` 必须是数字(YitId)。删除前校验当前用户可访问该计时器所属门店。
+`id` 必须是数字(YitId)。删除前校验当前用户可访问该计时器所属门店。
+对 `create` 等非数字路径发 DELETE / POST 不要当删除用。
### 7.5 查询是否过期(展示用)
@@ -370,6 +423,10 @@ App 只有一个筛选项:当前门店/公司。
|----------|------|
| Request body is required. | body 为空 |
| You are not signed in. | 未登录 |
+| Alert template Id is required. | 未传模板 Id |
+| Alert template not found or disabled. | 模板不存在或未启用 |
+| Alert template duration is not configured. | 模板未配置单位+数字 |
+| Select a location or pass locationId. | 未选门店 |
| Timer Id is required. | 删除未传 id |
| Timer not found or removed. | 记录不存在或已删 |
| Provide at least one of timerId, batchId, or printTaskId. | check-expired 三个标识都空 |
@@ -384,6 +441,7 @@ App 只有一个筛选项:当前门店/公司。
| 200 | 成功 |
| 400 | 未初始化完成、过期、账号密码错误、门店不可见、计时器参数错误 |
| 401 | 未登录 |
+| 405 | 方法不匹配(例如 POST 打到了只允许 DELETE 的 `{id}`;请用 `/create`) |
| 500 | 服务器错误 |
---
@@ -427,4 +485,22 @@ curl -s -X POST "https://flusapi-tetest.3flabeling.com/api/app/label-alert-timer
-H "Authorization: " \
-H "Content-Type: application/json" \
-d "{\"locationId\":\"3a2473aa-98f1-e2ab-b50a-2efcb8bfdb54\",\"skipCount\":1,\"maxResultCount\":50}"
+
+# 告警模板新增(单位 + 数字,如 3 日)
+curl -s -X POST "https://flusapi-tetest.3flabeling.com/api/app/alert-template" \
+ -H "Authorization: " \
+ -H "Content-Type: application/json" \
+ -d "{\"templateName\":\"冷藏3日\",\"durationUnit\":\"Day\",\"durationValue\":3,\"state\":true}"
+
+# App/Web:按模板新增计时器(推荐)
+curl -s -X POST "https://flusapi-tetest.3flabeling.com/api/app/label-alert-timer/create" \
+ -H "Authorization: " \
+ -H "Content-Type: application/json" \
+ -d "{\"alertTemplateId\":\"\",\"locationId\":\"3a2473aa-98f1-e2ab-b50a-2efcb8bfdb54\"}"
+
+# 兼容:路径带模板数字 Id
+curl -s -X POST "https://flusapi-tetest.3flabeling.com/api/app/label-alert-timer/" \
+ -H "Authorization: " \
+ -H "Content-Type: application/json" \
+ -d "{\"locationId\":\"3a2473aa-98f1-e2ab-b50a-2efcb8bfdb54\"}"
```
--
libgit2 0.21.4