Commit 0519811fa27d5d680ac7a3e97236bc8a02d76365
1 parent
455610a7
2026-10-15 自动更新功能
Showing
76 changed files
with
3776 additions
and
110 deletions
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/AlertTemplate/AlertTemplateCreateInputVo.cs
0 → 100644
| 1 | +namespace FoodLabeling.Application.Contracts.Dtos.AlertTemplate; | |
| 2 | + | |
| 3 | +/// <summary>告警模板新增/编辑入参</summary> | |
| 4 | +public class AlertTemplateCreateInputVo | |
| 5 | +{ | |
| 6 | + public string TemplateName { get; set; } = string.Empty; | |
| 7 | + | |
| 8 | + public string DateTimeFormat { get; set; } = string.Empty; | |
| 9 | + | |
| 10 | + public bool State { get; set; } = true; | |
| 11 | +} | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/AlertTemplate/AlertTemplateDto.cs
0 → 100644
| 1 | +namespace FoodLabeling.Application.Contracts.Dtos.AlertTemplate; | |
| 2 | + | |
| 3 | +/// <summary>告警模板详情/列表项</summary> | |
| 4 | +public class AlertTemplateDto | |
| 5 | +{ | |
| 6 | + public string Id { get; set; } = string.Empty; | |
| 7 | + | |
| 8 | + public string TemplateName { get; set; } = string.Empty; | |
| 9 | + | |
| 10 | + public string DateTimeFormat { get; set; } = string.Empty; | |
| 11 | + | |
| 12 | + public bool State { get; set; } | |
| 13 | + | |
| 14 | + public DateTime CreationTime { get; set; } | |
| 15 | + | |
| 16 | + public DateTime? LastModificationTime { get; set; } | |
| 17 | +} | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/AlertTemplate/AlertTemplateGetListInputVo.cs
0 → 100644
| 1 | +using Volo.Abp.Application.Dtos; | |
| 2 | + | |
| 3 | +namespace FoodLabeling.Application.Contracts.Dtos.AlertTemplate; | |
| 4 | + | |
| 5 | +/// <summary>告警模板分页列表入参</summary> | |
| 6 | +public class AlertTemplateGetListInputVo : PagedAndSortedResultRequestDto | |
| 7 | +{ | |
| 8 | + public string? Keyword { get; set; } | |
| 9 | + | |
| 10 | + public bool? State { get; set; } | |
| 11 | +} | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/AlertTemplate/AlertTemplateOptionDto.cs
0 → 100644
| 1 | +namespace FoodLabeling.Application.Contracts.Dtos.AlertTemplate; | |
| 2 | + | |
| 3 | +/// <summary>告警模板下拉项(仅启用)</summary> | |
| 4 | +public class AlertTemplateOptionDto | |
| 5 | +{ | |
| 6 | + public string Id { get; set; } = string.Empty; | |
| 7 | + | |
| 8 | + public string TemplateName { get; set; } = string.Empty; | |
| 9 | + | |
| 10 | + public string DateTimeFormat { get; set; } = string.Empty; | |
| 11 | +} | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/AppUpdate/AppUpdateDto.cs
0 → 100644
| 1 | +namespace FoodLabeling.Application.Contracts.Dtos.AppUpdate; | |
| 2 | + | |
| 3 | +/// <summary>App 版本检查出参(对齐锁控面板 <c>/api/app/update</c>)。</summary> | |
| 4 | +public class AppUpdateDto | |
| 5 | +{ | |
| 6 | + public string PackageName { get; set; } = string.Empty; | |
| 7 | + | |
| 8 | + public int VersionCode { get; set; } | |
| 9 | + | |
| 10 | + public string VersionName { get; set; } = string.Empty; | |
| 11 | + | |
| 12 | + public bool ForceUpdate { get; set; } | |
| 13 | + | |
| 14 | + public string Changelog { get; set; } = string.Empty; | |
| 15 | + | |
| 16 | + /// <summary>完整 APK 下载地址</summary> | |
| 17 | + public string ApkUrl { get; set; } = string.Empty; | |
| 18 | + | |
| 19 | + public bool ApkReady { get; set; } | |
| 20 | + | |
| 21 | + /// <summary>服务端实际解析到的 APK 路径(排查 apkReady=false;前端可忽略)</summary> | |
| 22 | + public string? ApkResolvedPath { get; set; } | |
| 23 | + | |
| 24 | + /// <summary> | |
| 25 | + /// 入参带了本地 <c>versionCode</c> 时:远程更大且 apkReady 则为 true; | |
| 26 | + /// 未传本地版本时为 null,由前端自行比较。 | |
| 27 | + /// </summary> | |
| 28 | + public bool? HasUpdate { get; set; } | |
| 29 | +} | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/Label/LabelBatchCreateItemInputVo.cs
| ... | ... | @@ -32,6 +32,9 @@ public class LabelBatchCreateItemInputVo |
| 32 | 32 | |
| 33 | 33 | public List<string> ProductIds { get; set; } = new(); |
| 34 | 34 | |
| 35 | + /// <summary>绑定培训文件 Id(<c>fl_training_file.Id</c>);可空</summary> | |
| 36 | + public List<string>? BoundTrainingFileIds { get; set; } | |
| 37 | + | |
| 35 | 38 | /// <summary>标签级模板数据(落库 <c>fl_label.LabelInfoJson</c>);通常批量导入走模板 ProductDefaults</summary> |
| 36 | 39 | public object? LabelInfoJson { get; set; } |
| 37 | 40 | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/Label/LabelCreateInputVo.cs
| ... | ... | @@ -57,6 +57,9 @@ public class LabelCreateInputVo |
| 57 | 57 | |
| 58 | 58 | public List<string> ProductIds { get; set; } = new(); |
| 59 | 59 | |
| 60 | + /// <summary>绑定培训文件 Id(<c>fl_training_file.Id</c>);可空</summary> | |
| 61 | + public List<string>? BoundTrainingFileIds { get; set; } | |
| 62 | + | |
| 60 | 63 | public object? LabelInfoJson { get; set; } |
| 61 | 64 | |
| 62 | 65 | public bool State { get; set; } = true; | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/Label/LabelGetListOutputDto.cs
| ... | ... | @@ -32,6 +32,12 @@ public class LabelGetListOutputDto |
| 32 | 32 | /// </summary> |
| 33 | 33 | public string Products { get; set; } = string.Empty; |
| 34 | 34 | |
| 35 | + /// <summary>绑定的培训文件 Id</summary> | |
| 36 | + public List<string> BoundTrainingFileIds { get; set; } = new(); | |
| 37 | + | |
| 38 | + /// <summary>绑定培训文件名称,逗号拼接</summary> | |
| 39 | + public string BoundTrainingFiles { get; set; } = string.Empty; | |
| 40 | + | |
| 35 | 41 | public string TemplateName { get; set; } = string.Empty; |
| 36 | 42 | |
| 37 | 43 | /// <summary> | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/Label/LabelGetOutputDto.cs
| ... | ... | @@ -54,5 +54,11 @@ public class LabelGetOutputDto |
| 54 | 54 | public object? LabelInfoJson { get; set; } |
| 55 | 55 | |
| 56 | 56 | public List<string> ProductIds { get; set; } = new(); |
| 57 | + | |
| 58 | + /// <summary>绑定的培训文件 Id</summary> | |
| 59 | + public List<string> BoundTrainingFileIds { get; set; } = new(); | |
| 60 | + | |
| 61 | + /// <summary>绑定培训文件名称,逗号拼接</summary> | |
| 62 | + public string BoundTrainingFiles { get; set; } = string.Empty; | |
| 57 | 63 | } |
| 58 | 64 | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/Label/LabelUpdateInputVo.cs
| ... | ... | @@ -42,6 +42,9 @@ public class LabelUpdateInputVo |
| 42 | 42 | |
| 43 | 43 | public List<string> ProductIds { get; set; } = new(); |
| 44 | 44 | |
| 45 | + /// <summary>绑定培训文件 Id;null 表示不改动,空数组表示清空</summary> | |
| 46 | + public List<string>? BoundTrainingFileIds { get; set; } | |
| 47 | + | |
| 45 | 48 | public object? LabelInfoJson { get; set; } |
| 46 | 49 | |
| 47 | 50 | public bool State { get; set; } = true; | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelAlertTimer/LabelAlertTimerCheckExpiredOutputDto.cs
| ... | ... | @@ -26,4 +26,11 @@ public class LabelAlertTimerCheckExpiredOutputDto |
| 26 | 26 | public string? TimerId { get; set; } |
| 27 | 27 | |
| 28 | 28 | public string? BatchId { get; set; } |
| 29 | + | |
| 30 | + public string? LabelName { get; set; } | |
| 31 | + | |
| 32 | + public string? FormattedExpiresAt { get; set; } | |
| 33 | + | |
| 34 | + /// <summary>固定文案:亲爱的{userName},您的{labelName}标签已过期,请及时处理</summary> | |
| 35 | + public string? ExpiredMessageTemplate { get; set; } | |
| 29 | 36 | } | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelAlertTimer/LabelAlertTimerGetListInputVo.cs
| ... | ... | @@ -9,7 +9,8 @@ public class LabelAlertTimerGetListInputVo : PagedAndSortedResultRequestDto |
| 9 | 9 | { |
| 10 | 10 | /// <summary> |
| 11 | 11 | /// 当前门店 Id(location.Id,Guid 字符串)。 |
| 12 | - /// <c>list</c> 必填;<c>app-list</c> 可空(空则取已选门店缓存)。 | |
| 12 | + /// <c>list</c>(平台)可空:空=权限范围内全部门店;有值则仅该门店。 | |
| 13 | + /// <c>app-list</c> 必须落到一个门店(空则取已选门店缓存)。 | |
| 13 | 14 | /// </summary> |
| 14 | 15 | public string? LocationId { get; set; } |
| 15 | 16 | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelAlertTimer/LabelAlertTimerListItemDto.cs
| ... | ... | @@ -15,6 +15,8 @@ public class LabelAlertTimerListItemDto |
| 15 | 15 | |
| 16 | 16 | public string? LabelCode { get; set; } |
| 17 | 17 | |
| 18 | + public string LabelName { get; set; } = string.Empty; | |
| 19 | + | |
| 18 | 20 | public string Title { get; set; } = string.Empty; |
| 19 | 21 | |
| 20 | 22 | public string Subtitle { get; set; } = string.Empty; |
| ... | ... | @@ -30,9 +32,27 @@ public class LabelAlertTimerListItemDto |
| 30 | 32 | |
| 31 | 33 | public DateTime ExpiresAt { get; set; } |
| 32 | 34 | |
| 35 | + /// <summary>按告警模板 DateTimeFormat 格式化后的过期时刻</summary> | |
| 36 | + public string FormattedExpiresAt { get; set; } = string.Empty; | |
| 37 | + | |
| 33 | 38 | public DateTime PrintedAt { get; set; } |
| 34 | 39 | |
| 35 | 40 | public string LocationId { get; set; } = string.Empty; |
| 36 | 41 | |
| 42 | + public string? LocationName { get; set; } | |
| 43 | + | |
| 37 | 44 | public string? ProductName { get; set; } |
| 45 | + | |
| 46 | + public string? AlertTemplateId { get; set; } | |
| 47 | + | |
| 48 | + public string? AlertTemplateName { get; set; } | |
| 49 | + | |
| 50 | + public string? DateTimeFormat { get; set; } | |
| 51 | + | |
| 52 | + public string? PrintedByUserId { get; set; } | |
| 53 | + | |
| 54 | + public string? PrintedByUserName { get; set; } | |
| 55 | + | |
| 56 | + /// <summary>固定文案:亲爱的{userName},您的{labelName}标签已过期,请及时处理</summary> | |
| 57 | + public string ExpiredMessageTemplate { get; set; } = string.Empty; | |
| 38 | 58 | } | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/Training/TrainingCategoryTreeInputVo.cs
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/Training/TrainingFileDto.cs
| ... | ... | @@ -44,6 +44,12 @@ public class TrainingFileDto |
| 44 | 44 | |
| 45 | 45 | public List<string> LocationIds { get; set; } = new(); |
| 46 | 46 | |
| 47 | + /// <summary>绑定标签 Id(与标签列表 <c>id</c> 一致,为 LabelCode)</summary> | |
| 48 | + public List<string> BoundLabelIds { get; set; } = new(); | |
| 49 | + | |
| 50 | + /// <summary>绑定标签名称,逗号拼接</summary> | |
| 51 | + public string BoundLabels { get; set; } = string.Empty; | |
| 52 | + | |
| 47 | 53 | public DateTime CreationTime { get; set; } |
| 48 | 54 | |
| 49 | 55 | public DateTime? LastModificationTime { get; set; } | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/Training/TrainingFileUpdateInputVo.cs
| ... | ... | @@ -34,4 +34,7 @@ public class TrainingFileUpdateInputVo : ITrainingFileScopeInput |
| 34 | 34 | |
| 35 | 35 | /// <summary>适用门店(<c>location.Id</c>);可含 <c>ALL</c></summary> |
| 36 | 36 | public List<string>? LocationIds { get; set; } |
| 37 | + | |
| 38 | + /// <summary>绑定标签 Id(LabelCode 或内部 Id);null 不改动,空数组清空</summary> | |
| 39 | + public List<string>? BoundLabelIds { get; set; } | |
| 37 | 40 | } | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/Training/TrainingFileUploadInputVo.cs
| ... | ... | @@ -50,4 +50,8 @@ public class TrainingFileUploadInputVo : ITrainingFileScopeInput |
| 50 | 50 | /// <summary>适用门店(<c>location.Id</c>);可含 <c>ALL</c></summary> |
| 51 | 51 | [FromForm(Name = "locationIds")] |
| 52 | 52 | public List<string>? LocationIds { get; set; } |
| 53 | + | |
| 54 | + /// <summary>绑定标签 Id(<c>fl_label.LabelCode</c> 或内部 Id)</summary> | |
| 55 | + [FromForm(Name = "boundLabelIds")] | |
| 56 | + public List<string>? BoundLabelIds { get; set; } | |
| 53 | 57 | } | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/Training/UsAppTrainingTreeInputVo.cs
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/IServices/IAlertTemplateAppService.cs
0 → 100644
| 1 | +using FoodLabeling.Application.Contracts.Dtos.AlertTemplate; | |
| 2 | +using FoodLabeling.Application.Contracts.Dtos.Common; | |
| 3 | +using Volo.Abp.Application.Services; | |
| 4 | + | |
| 5 | +namespace FoodLabeling.Application.Contracts.IServices; | |
| 6 | + | |
| 7 | +/// <summary>告警日期时间格式模板</summary> | |
| 8 | +public interface IAlertTemplateAppService : IApplicationService | |
| 9 | +{ | |
| 10 | + Task<PagedResultWithPageDto<AlertTemplateDto>> ListAsync(AlertTemplateGetListInputVo input); | |
| 11 | + | |
| 12 | + Task<AlertTemplateDto> GetAsync(string id); | |
| 13 | + | |
| 14 | + Task<AlertTemplateDto> CreateAsync(AlertTemplateCreateInputVo input); | |
| 15 | + | |
| 16 | + Task<AlertTemplateDto> UpdateAsync(string id, AlertTemplateCreateInputVo input); | |
| 17 | + | |
| 18 | + Task DeleteAsync(string id); | |
| 19 | + | |
| 20 | + Task<List<AlertTemplateOptionDto>> GetOptionsAsync(); | |
| 21 | +} | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/IServices/IAppUpdateAppService.cs
0 → 100644
| 1 | +using FoodLabeling.Application.Contracts.Dtos.AppUpdate; | |
| 2 | +using Microsoft.AspNetCore.Mvc; | |
| 3 | +using Volo.Abp.Application.Services; | |
| 4 | + | |
| 5 | +namespace FoodLabeling.Application.Contracts.IServices; | |
| 6 | + | |
| 7 | +/// <summary>App 版本检查与 APK 下载</summary> | |
| 8 | +public interface IAppUpdateAppService : IApplicationService | |
| 9 | +{ | |
| 10 | + Task<AppUpdateDto> GetInfoAsync(int? versionCode); | |
| 11 | + | |
| 12 | + IActionResult DownloadApk(); | |
| 13 | +} | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/IServices/ILabelAlertTimerAppService.cs
| ... | ... | @@ -5,7 +5,7 @@ using Volo.Abp.Application.Services; |
| 5 | 5 | namespace FoodLabeling.Application.Contracts.IServices; |
| 6 | 6 | |
| 7 | 7 | /// <summary> |
| 8 | -/// 标签告警计时器(App) | |
| 8 | +/// 标签告警计时器(平台 list 可全店;App app-list 仅本店) | |
| 9 | 9 | /// </summary> |
| 10 | 10 | public interface ILabelAlertTimerAppService : IApplicationService |
| 11 | 11 | { | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/IServices/ILabelAppService.cs
| ... | ... | @@ -11,18 +11,19 @@ namespace FoodLabeling.Application.Contracts.IServices; |
| 11 | 11 | public interface ILabelAppService : IApplicationService |
| 12 | 12 | { |
| 13 | 13 | /// <summary> |
| 14 | - /// 按产品分页列表(一个产品展示多个标签)。支持 <c>GroupId</c> / <c>LocationId</c> 筛选(命中 <c>fl_label_region</c>、<c>fl_label_location</c> 或 <c>AppliedRegionType=ALL</c>);<c>labelTypeId</c> 为可选筛选;出参含 <c>locationIds</c>、<c>region</c>、<c>regionIds</c>、<c>appliedRegionType</c>。 | |
| 14 | + /// 按产品分页列表(一个产品展示多个标签)。支持 <c>GroupId</c> / <c>LocationId</c> 筛选(命中 <c>fl_label_region</c>、<c>fl_label_location</c> 或 <c>AppliedRegionType=ALL</c>);<c>labelTypeId</c> 为可选筛选;出参含 <c>locationIds</c>、<c>region</c>、<c>regionIds</c>、<c>appliedRegionType</c>、<c>boundTrainingFileIds</c>、<c>boundTrainingFiles</c>。 | |
| 15 | 15 | /// </summary> |
| 16 | 16 | Task<PagedResultWithPageDto<LabelGetListOutputDto>> GetListAsync(LabelGetListInputVo input); |
| 17 | 17 | |
| 18 | 18 | /// <summary> |
| 19 | - /// 标签详情(id=LabelCode)。出参含 <c>locationIds</c>、<c>location</c>、<c>appliedRegionType</c>、<c>region</c>、<c>regionIds</c>、<c>groupIds</c>;<c>locationId</c> 为 <c>locationIds</c> 首项兼容字段。 | |
| 19 | + /// 标签详情(id=LabelCode)。出参含 <c>locationIds</c>、<c>location</c>、<c>appliedRegionType</c>、<c>region</c>、<c>regionIds</c>、<c>groupIds</c>、<c>boundTrainingFileIds</c>、<c>boundTrainingFiles</c>;<c>locationId</c> 为 <c>locationIds</c> 首项兼容字段。 | |
| 20 | 20 | /// </summary> |
| 21 | 21 | Task<LabelGetOutputDto> GetAsync(string id); |
| 22 | 22 | |
| 23 | 23 | /// <summary> |
| 24 | 24 | /// 新增标签。Body 支持 <c>appliedRegionType</c>(ALL/SPECIFIED)、 |
| 25 | - /// <c>regionIds</c> / <c>groupIds</c> / <c>locationIds</c>(可含哨兵 <c>ALL</c>,归档为 AppliedRegionType=ALL)。 | |
| 25 | + /// <c>regionIds</c> / <c>groupIds</c> / <c>locationIds</c>(可含哨兵 <c>ALL</c>,归档为 AppliedRegionType=ALL), | |
| 26 | + /// 以及 <c>boundTrainingFileIds</c>(绑定培训文件 Id)。 | |
| 26 | 27 | /// </summary> |
| 27 | 28 | Task<LabelGetOutputDto> CreateAsync(LabelCreateInputVo input); |
| 28 | 29 | |
| ... | ... | @@ -33,6 +34,7 @@ public interface ILabelAppService : IApplicationService |
| 33 | 34 | |
| 34 | 35 | /// <summary> |
| 35 | 36 | /// 编辑标签(id=LabelCode)。范围传参与 <see cref="CreateAsync"/> 一致,支持 Id 数组传 <c>ALL</c>。 |
| 37 | + /// <c>boundTrainingFileIds</c> 为 null 时不改绑定;空数组清空绑定。 | |
| 36 | 38 | /// </summary> |
| 37 | 39 | Task<LabelGetOutputDto> UpdateAsync(string id, LabelUpdateInputVo input); |
| 38 | 40 | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/FoodLabeling.Application.csproj
| ... | ... | @@ -36,6 +36,18 @@ |
| 36 | 36 | <EmbeddedResource Include="..\scripts\fl_label_alert_timer.sql"> |
| 37 | 37 | <LogicalName>FoodLabeling.TenantMigrations.fl_label_alert_timer.sql</LogicalName> |
| 38 | 38 | </EmbeddedResource> |
| 39 | + <EmbeddedResource Include="..\scripts\fl_bound_label.sql"> | |
| 40 | + <LogicalName>FoodLabeling.TenantMigrations.fl_bound_label.sql</LogicalName> | |
| 41 | + </EmbeddedResource> | |
| 42 | + <EmbeddedResource Include="..\scripts\fl_alert_template.sql"> | |
| 43 | + <LogicalName>FoodLabeling.TenantMigrations.fl_alert_template.sql</LogicalName> | |
| 44 | + </EmbeddedResource> | |
| 45 | + <EmbeddedResource Include="..\scripts\fl_label_alert_timer_alert_template.sql"> | |
| 46 | + <LogicalName>FoodLabeling.TenantMigrations.fl_label_alert_timer_alert_template.sql</LogicalName> | |
| 47 | + </EmbeddedResource> | |
| 48 | + <EmbeddedResource Include="..\scripts\fl_menu_hide_platform_qr_codes.sql"> | |
| 49 | + <LogicalName>FoodLabeling.TenantMigrations.fl_menu_hide_platform_qr_codes.sql</LogicalName> | |
| 50 | + </EmbeddedResource> | |
| 39 | 51 | </ItemGroup> |
| 40 | 52 | |
| 41 | 53 | <ItemGroup> | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/FoodLabelingApplicationModule.cs
| ... | ... | @@ -23,6 +23,8 @@ public class FoodLabelingApplicationModule : AbpModule |
| 23 | 23 | { |
| 24 | 24 | Configure<FoodLabelingBatchImportOptions>( |
| 25 | 25 | context.Services.GetConfiguration().GetSection(FoodLabelingBatchImportOptions.SectionName)); |
| 26 | + Configure<FoodLabelingAppUpdateOptions>( | |
| 27 | + context.Services.GetConfiguration().GetSection(FoodLabelingAppUpdateOptions.SectionName)); | |
| 26 | 28 | |
| 27 | 29 | // 任意业务写接口成功后刷新系统编辑时间戳,供 my-menus.lastUpdated 使用 |
| 28 | 30 | Configure<MvcOptions>(options => | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/AppUpdatePathHelper.cs
0 → 100644
| 1 | +using FoodLabeling.Application.Options; | |
| 2 | + | |
| 3 | +namespace FoodLabeling.Application.Helpers; | |
| 4 | + | |
| 5 | +/// <summary>相对路径按进程工作目录解析;<c>ApkPath</c> 可为 APK 文件或目录。</summary> | |
| 6 | +public static class AppUpdatePathHelper | |
| 7 | +{ | |
| 8 | + public const string DefaultDirectory = "/www/wwwroot/FoodLabelingManagementUs/wwwroot/app-update"; | |
| 9 | + | |
| 10 | + public const string DefaultFileName = "app-release.apk"; | |
| 11 | + | |
| 12 | + public static FileInfo? ResolveApk(FoodLabelingAppUpdateOptions cfg) | |
| 13 | + { | |
| 14 | + if (cfg is null || string.IsNullOrWhiteSpace(cfg.ApkPath)) | |
| 15 | + { | |
| 16 | + return null; | |
| 17 | + } | |
| 18 | + | |
| 19 | + var configured = cfg.ApkPath.Trim().TrimEnd('/', '\\'); | |
| 20 | + var tried = new HashSet<string>(StringComparer.OrdinalIgnoreCase); | |
| 21 | + var candidates = new List<FileInfo>(); | |
| 22 | + | |
| 23 | + void AddFile(string path) | |
| 24 | + { | |
| 25 | + if (string.IsNullOrWhiteSpace(path) || !tried.Add(path)) | |
| 26 | + { | |
| 27 | + return; | |
| 28 | + } | |
| 29 | + | |
| 30 | + candidates.Add(new FileInfo(path)); | |
| 31 | + } | |
| 32 | + | |
| 33 | + void AddPath(string path) | |
| 34 | + { | |
| 35 | + if (string.IsNullOrWhiteSpace(path)) | |
| 36 | + { | |
| 37 | + return; | |
| 38 | + } | |
| 39 | + | |
| 40 | + if (Directory.Exists(path)) | |
| 41 | + { | |
| 42 | + var preferred = Path.Combine(path, DefaultFileName); | |
| 43 | + AddFile(preferred); | |
| 44 | + foreach (var apk in Directory.EnumerateFiles(path, "*.apk") | |
| 45 | + .OrderByDescending(File.GetLastWriteTimeUtc)) | |
| 46 | + { | |
| 47 | + AddFile(apk); | |
| 48 | + } | |
| 49 | + | |
| 50 | + return; | |
| 51 | + } | |
| 52 | + | |
| 53 | + AddFile(path); | |
| 54 | + if (!Path.HasExtension(path)) | |
| 55 | + { | |
| 56 | + AddFile(Path.Combine(path, DefaultFileName)); | |
| 57 | + } | |
| 58 | + } | |
| 59 | + | |
| 60 | + AddPath(configured); | |
| 61 | + if (!Path.IsPathRooted(configured)) | |
| 62 | + { | |
| 63 | + var stripped = configured.StartsWith("./", StringComparison.Ordinal) | |
| 64 | + ? configured[2..] | |
| 65 | + : configured; | |
| 66 | + AddPath(Path.Combine(Environment.CurrentDirectory, stripped)); | |
| 67 | + } | |
| 68 | + | |
| 69 | + AddPath(DefaultDirectory); | |
| 70 | + AddFile(Path.Combine(DefaultDirectory, DefaultFileName)); | |
| 71 | + | |
| 72 | + foreach (var file in candidates) | |
| 73 | + { | |
| 74 | + if (file.Exists && file.Length > 0) | |
| 75 | + { | |
| 76 | + return file; | |
| 77 | + } | |
| 78 | + } | |
| 79 | + | |
| 80 | + return candidates.Count == 0 ? null : candidates[0]; | |
| 81 | + } | |
| 82 | +} | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/AppUpdateVersionResolver.cs
0 → 100644
| 1 | +using System.Collections.Concurrent; | |
| 2 | +using System.IO.Compression; | |
| 3 | +using System.Text.Json; | |
| 4 | +using FoodLabeling.Application.Options; | |
| 5 | + | |
| 6 | +namespace FoodLabeling.Application.Helpers; | |
| 7 | + | |
| 8 | +/// <summary> | |
| 9 | +/// 版本号以已上传 APK 为准:日常后端发版不改版本;只有目录里换了新包才变。 | |
| 10 | +/// 优先读 APK 内 UniApp <c>manifest.json</c>,其次同目录 <c>version.json</c>,最后才用 appsettings 兜底。 | |
| 11 | +/// </summary> | |
| 12 | +public static class AppUpdateVersionResolver | |
| 13 | +{ | |
| 14 | + private static readonly ConcurrentDictionary<string, (long Length, long Ticks, int Code, string Name)> ApkCache = | |
| 15 | + new(StringComparer.OrdinalIgnoreCase); | |
| 16 | + | |
| 17 | + public static (int VersionCode, string VersionName) Resolve(FileInfo? apk, FoodLabelingAppUpdateOptions options) | |
| 18 | + { | |
| 19 | + var fallbackCode = options.VersionCode; | |
| 20 | + var fallbackName = options.VersionName ?? string.Empty; | |
| 21 | + | |
| 22 | + if (apk is not { Exists: true, Length: > 0 }) | |
| 23 | + { | |
| 24 | + return (fallbackCode, fallbackName); | |
| 25 | + } | |
| 26 | + | |
| 27 | + if (TryReadFromApk(apk, out var apkCode, out var apkName)) | |
| 28 | + { | |
| 29 | + return (apkCode, string.IsNullOrWhiteSpace(apkName) ? fallbackName : apkName); | |
| 30 | + } | |
| 31 | + | |
| 32 | + if (TryReadSidecar(apk.DirectoryName, out var fileCode, out var fileName)) | |
| 33 | + { | |
| 34 | + return (fileCode, string.IsNullOrWhiteSpace(fileName) ? fallbackName : fileName); | |
| 35 | + } | |
| 36 | + | |
| 37 | + return (fallbackCode, fallbackName); | |
| 38 | + } | |
| 39 | + | |
| 40 | + private static bool TryReadFromApk(FileInfo apk, out int versionCode, out string versionName) | |
| 41 | + { | |
| 42 | + versionCode = 0; | |
| 43 | + versionName = string.Empty; | |
| 44 | + var cacheKey = apk.FullName; | |
| 45 | + var ticks = apk.LastWriteTimeUtc.Ticks; | |
| 46 | + if (ApkCache.TryGetValue(cacheKey, out var cached) | |
| 47 | + && cached.Length == apk.Length | |
| 48 | + && cached.Ticks == ticks) | |
| 49 | + { | |
| 50 | + versionCode = cached.Code; | |
| 51 | + versionName = cached.Name; | |
| 52 | + return versionCode > 0; | |
| 53 | + } | |
| 54 | + | |
| 55 | + try | |
| 56 | + { | |
| 57 | + using var zip = ZipFile.OpenRead(apk.FullName); | |
| 58 | + foreach (var entry in zip.Entries) | |
| 59 | + { | |
| 60 | + if (!entry.FullName.EndsWith("manifest.json", StringComparison.OrdinalIgnoreCase)) | |
| 61 | + { | |
| 62 | + continue; | |
| 63 | + } | |
| 64 | + | |
| 65 | + var path = entry.FullName.Replace('\\', '/'); | |
| 66 | + if (path.Contains("/node_modules/", StringComparison.OrdinalIgnoreCase) | |
| 67 | + || path.Contains("/unpackage/", StringComparison.OrdinalIgnoreCase)) | |
| 68 | + { | |
| 69 | + continue; | |
| 70 | + } | |
| 71 | + | |
| 72 | + using var stream = entry.Open(); | |
| 73 | + using var doc = JsonDocument.Parse(stream); | |
| 74 | + if (!TryReadManifest(doc.RootElement, out versionCode, out versionName) || versionCode <= 0) | |
| 75 | + { | |
| 76 | + continue; | |
| 77 | + } | |
| 78 | + | |
| 79 | + ApkCache[cacheKey] = (apk.Length, ticks, versionCode, versionName); | |
| 80 | + return true; | |
| 81 | + } | |
| 82 | + } | |
| 83 | + catch (Exception) | |
| 84 | + { | |
| 85 | + return false; | |
| 86 | + } | |
| 87 | + | |
| 88 | + return false; | |
| 89 | + } | |
| 90 | + | |
| 91 | + private static bool TryReadSidecar(string? directory, out int versionCode, out string versionName) | |
| 92 | + { | |
| 93 | + versionCode = 0; | |
| 94 | + versionName = string.Empty; | |
| 95 | + if (string.IsNullOrWhiteSpace(directory)) | |
| 96 | + { | |
| 97 | + return false; | |
| 98 | + } | |
| 99 | + | |
| 100 | + var sidecar = Path.Combine(directory, "version.json"); | |
| 101 | + if (!File.Exists(sidecar)) | |
| 102 | + { | |
| 103 | + return false; | |
| 104 | + } | |
| 105 | + | |
| 106 | + try | |
| 107 | + { | |
| 108 | + using var doc = JsonDocument.Parse(File.ReadAllText(sidecar)); | |
| 109 | + return TryReadManifest(doc.RootElement, out versionCode, out versionName) && versionCode > 0; | |
| 110 | + } | |
| 111 | + catch (Exception) | |
| 112 | + { | |
| 113 | + return false; | |
| 114 | + } | |
| 115 | + } | |
| 116 | + | |
| 117 | + private static bool TryReadManifest(JsonElement root, out int versionCode, out string versionName) | |
| 118 | + { | |
| 119 | + versionCode = 0; | |
| 120 | + versionName = string.Empty; | |
| 121 | + if (root.ValueKind != JsonValueKind.Object) | |
| 122 | + { | |
| 123 | + return false; | |
| 124 | + } | |
| 125 | + | |
| 126 | + versionName = ReadString(root, "versionName") ?? string.Empty; | |
| 127 | + var codeEl = GetProperty(root, "versionCode"); | |
| 128 | + if (codeEl.ValueKind == JsonValueKind.Number && codeEl.TryGetInt32(out var n)) | |
| 129 | + { | |
| 130 | + versionCode = n; | |
| 131 | + return true; | |
| 132 | + } | |
| 133 | + | |
| 134 | + if (codeEl.ValueKind == JsonValueKind.String | |
| 135 | + && int.TryParse(codeEl.GetString(), out var fromText) | |
| 136 | + && fromText > 0) | |
| 137 | + { | |
| 138 | + versionCode = fromText; | |
| 139 | + return true; | |
| 140 | + } | |
| 141 | + | |
| 142 | + return false; | |
| 143 | + } | |
| 144 | + | |
| 145 | + private static string? ReadString(JsonElement root, string name) | |
| 146 | + { | |
| 147 | + var el = GetProperty(root, name); | |
| 148 | + return el.ValueKind == JsonValueKind.String ? el.GetString() : null; | |
| 149 | + } | |
| 150 | + | |
| 151 | + private static JsonElement GetProperty(JsonElement root, string name) | |
| 152 | + { | |
| 153 | + if (root.TryGetProperty(name, out var el)) | |
| 154 | + { | |
| 155 | + return el; | |
| 156 | + } | |
| 157 | + | |
| 158 | + foreach (var p in root.EnumerateObject()) | |
| 159 | + { | |
| 160 | + if (string.Equals(p.Name, name, StringComparison.OrdinalIgnoreCase)) | |
| 161 | + { | |
| 162 | + return p.Value; | |
| 163 | + } | |
| 164 | + } | |
| 165 | + | |
| 166 | + return default; | |
| 167 | + } | |
| 168 | +} | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/BoundLabelBindingHelper.cs
0 → 100644
| 1 | +using FoodLabeling.Application.Services.DbModels; | |
| 2 | +using FoodLabeling.Domain.Shared; | |
| 3 | +using FoodLabeling.Domain.Shared.Helpers; | |
| 4 | +using SqlSugar; | |
| 5 | +using Volo.Abp; | |
| 6 | + | |
| 7 | +namespace FoodLabeling.Application.Helpers; | |
| 8 | + | |
| 9 | +/// <summary> | |
| 10 | +/// 标签 ↔ 培训文件多对多(<c>fl_training_file_label</c>)。 | |
| 11 | +/// 标签侧绑定培训文件 Id;培训文件侧绑定标签 Id/LabelCode。 | |
| 12 | +/// </summary> | |
| 13 | +public static class BoundLabelBindingHelper | |
| 14 | +{ | |
| 15 | + public sealed class BoundLabelDisplay | |
| 16 | + { | |
| 17 | + public List<string> BoundLabelIds { get; init; } = new(); | |
| 18 | + | |
| 19 | + public string BoundLabels { get; init; } = FoodLabelingDisplayConsts.NotAvailable; | |
| 20 | + } | |
| 21 | + | |
| 22 | + public sealed class BoundTrainingFileDisplay | |
| 23 | + { | |
| 24 | + public List<string> BoundTrainingFileIds { get; init; } = new(); | |
| 25 | + | |
| 26 | + public string BoundTrainingFiles { get; init; } = FoodLabelingDisplayConsts.NotAvailable; | |
| 27 | + } | |
| 28 | + | |
| 29 | + public static BoundLabelDisplay EmptyDisplay { get; } = new(); | |
| 30 | + | |
| 31 | + public static BoundTrainingFileDisplay EmptyTrainingFileDisplay { get; } = new(); | |
| 32 | + | |
| 33 | + private static int _schemaReady; | |
| 34 | + | |
| 35 | + private const string CreateTrainingFileLabelTableSql = """ | |
| 36 | + CREATE TABLE IF NOT EXISTS `fl_training_file_label` ( | |
| 37 | + `Id` varchar(36) NOT NULL, | |
| 38 | + `TrainingFileId` varchar(36) NOT NULL, | |
| 39 | + `LabelId` varchar(36) NOT NULL, | |
| 40 | + PRIMARY KEY (`Id`), | |
| 41 | + UNIQUE KEY `uk_fl_training_file_label` (`TrainingFileId`, `LabelId`), | |
| 42 | + KEY `idx_fl_tflabel_file` (`TrainingFileId`), | |
| 43 | + KEY `idx_fl_tflabel_label` (`LabelId`) | |
| 44 | + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci | |
| 45 | + """; | |
| 46 | + | |
| 47 | + private static async Task EnsureSchemaAsync(ISqlSugarClient db, bool throwIfMissing) | |
| 48 | + { | |
| 49 | + if (Volatile.Read(ref _schemaReady) == 1) | |
| 50 | + { | |
| 51 | + return; | |
| 52 | + } | |
| 53 | + | |
| 54 | + if (await TablesExistAsync(db)) | |
| 55 | + { | |
| 56 | + Volatile.Write(ref _schemaReady, 1); | |
| 57 | + return; | |
| 58 | + } | |
| 59 | + | |
| 60 | + try | |
| 61 | + { | |
| 62 | + await db.Ado.ExecuteCommandAsync(CreateTrainingFileLabelTableSql); | |
| 63 | + } | |
| 64 | + catch (Exception ex) when (throwIfMissing) | |
| 65 | + { | |
| 66 | + throw new UserFriendlyException($"绑定标签表未初始化,请执行 fl_bound_label.sql:{ex.Message}"); | |
| 67 | + } | |
| 68 | + catch | |
| 69 | + { | |
| 70 | + return; | |
| 71 | + } | |
| 72 | + | |
| 73 | + if (await TablesExistAsync(db)) | |
| 74 | + { | |
| 75 | + Volatile.Write(ref _schemaReady, 1); | |
| 76 | + return; | |
| 77 | + } | |
| 78 | + | |
| 79 | + if (throwIfMissing) | |
| 80 | + { | |
| 81 | + throw new UserFriendlyException("绑定标签表未初始化,请执行 fl_bound_label.sql"); | |
| 82 | + } | |
| 83 | + } | |
| 84 | + | |
| 85 | + private static async Task<bool> TablesExistAsync(ISqlSugarClient db) | |
| 86 | + { | |
| 87 | + var count = await db.Ado.GetIntAsync( | |
| 88 | + """ | |
| 89 | + SELECT COUNT(*) | |
| 90 | + FROM information_schema.TABLES | |
| 91 | + WHERE TABLE_SCHEMA = DATABASE() | |
| 92 | + AND TABLE_NAME = 'fl_training_file_label' | |
| 93 | + """); | |
| 94 | + return count >= 1; | |
| 95 | + } | |
| 96 | + | |
| 97 | + /// <summary> | |
| 98 | + /// 保存标签绑定的培训文件。编辑时 <paramref name="inputIds"/> 为 null 表示不改动。 | |
| 99 | + /// </summary> | |
| 100 | + public static async Task SaveForLabelAsync( | |
| 101 | + ISqlSugarClient db, | |
| 102 | + string labelId, | |
| 103 | + IEnumerable<string>? inputIds, | |
| 104 | + bool replaceWhenNull) | |
| 105 | + { | |
| 106 | + if (inputIds is null && !replaceWhenNull) | |
| 107 | + { | |
| 108 | + return; | |
| 109 | + } | |
| 110 | + | |
| 111 | + await EnsureSchemaAsync(db, throwIfMissing: true); | |
| 112 | + var fileIds = await ResolveTrainingFileIdsAsync(db, inputIds, throwIfMissing: true); | |
| 113 | + | |
| 114 | + await db.Deleteable<FlTrainingFileLabelDbEntity>() | |
| 115 | + .Where(x => x.LabelId == labelId) | |
| 116 | + .ExecuteCommandAsync(); | |
| 117 | + | |
| 118 | + if (fileIds.Count == 0) | |
| 119 | + { | |
| 120 | + return; | |
| 121 | + } | |
| 122 | + | |
| 123 | + var rows = fileIds.Select(id => new FlTrainingFileLabelDbEntity | |
| 124 | + { | |
| 125 | + Id = YitIdHelper.NextId().ToString(), | |
| 126 | + TrainingFileId = id, | |
| 127 | + LabelId = labelId | |
| 128 | + }).ToList(); | |
| 129 | + await db.Insertable(rows).ExecuteCommandAsync(); | |
| 130 | + } | |
| 131 | + | |
| 132 | + /// <summary> | |
| 133 | + /// 保存培训文件绑定的标签。编辑时 <paramref name="inputIds"/> 为 null 表示不改动。 | |
| 134 | + /// </summary> | |
| 135 | + public static async Task SaveForTrainingFileAsync( | |
| 136 | + ISqlSugarClient db, | |
| 137 | + string trainingFileId, | |
| 138 | + IEnumerable<string>? inputIds, | |
| 139 | + bool replaceWhenNull) | |
| 140 | + { | |
| 141 | + if (inputIds is null && !replaceWhenNull) | |
| 142 | + { | |
| 143 | + return; | |
| 144 | + } | |
| 145 | + | |
| 146 | + await EnsureSchemaAsync(db, throwIfMissing: true); | |
| 147 | + var boundIds = await ResolveInternalLabelIdsAsync(db, inputIds, throwIfMissing: true); | |
| 148 | + | |
| 149 | + await db.Deleteable<FlTrainingFileLabelDbEntity>() | |
| 150 | + .Where(x => x.TrainingFileId == trainingFileId) | |
| 151 | + .ExecuteCommandAsync(); | |
| 152 | + | |
| 153 | + if (boundIds.Count == 0) | |
| 154 | + { | |
| 155 | + return; | |
| 156 | + } | |
| 157 | + | |
| 158 | + var rows = boundIds.Select(id => new FlTrainingFileLabelDbEntity | |
| 159 | + { | |
| 160 | + Id = YitIdHelper.NextId().ToString(), | |
| 161 | + TrainingFileId = trainingFileId, | |
| 162 | + LabelId = id | |
| 163 | + }).ToList(); | |
| 164 | + await db.Insertable(rows).ExecuteCommandAsync(); | |
| 165 | + } | |
| 166 | + | |
| 167 | + public static async Task DeleteForLabelAsync(ISqlSugarClient db, string labelId) | |
| 168 | + { | |
| 169 | + await EnsureSchemaAsync(db, throwIfMissing: false); | |
| 170 | + if (Volatile.Read(ref _schemaReady) != 1) | |
| 171 | + { | |
| 172 | + return; | |
| 173 | + } | |
| 174 | + await db.Deleteable<FlTrainingFileLabelDbEntity>() | |
| 175 | + .Where(x => x.LabelId == labelId) | |
| 176 | + .ExecuteCommandAsync(); | |
| 177 | + } | |
| 178 | + | |
| 179 | + public static async Task DeleteForTrainingFileAsync(ISqlSugarClient db, string trainingFileId) | |
| 180 | + { | |
| 181 | + await EnsureSchemaAsync(db, throwIfMissing: false); | |
| 182 | + if (Volatile.Read(ref _schemaReady) != 1) | |
| 183 | + { | |
| 184 | + return; | |
| 185 | + } | |
| 186 | + await db.Deleteable<FlTrainingFileLabelDbEntity>() | |
| 187 | + .Where(x => x.TrainingFileId == trainingFileId) | |
| 188 | + .ExecuteCommandAsync(); | |
| 189 | + } | |
| 190 | + | |
| 191 | + public static async Task<Dictionary<string, BoundTrainingFileDisplay>> LoadForLabelsAsync( | |
| 192 | + ISqlSugarClient db, | |
| 193 | + IEnumerable<string> labelIds) | |
| 194 | + { | |
| 195 | + var ids = labelIds.Where(x => !string.IsNullOrWhiteSpace(x)).Distinct(StringComparer.Ordinal).ToList(); | |
| 196 | + if (ids.Count == 0) | |
| 197 | + { | |
| 198 | + return new Dictionary<string, BoundTrainingFileDisplay>(StringComparer.Ordinal); | |
| 199 | + } | |
| 200 | + | |
| 201 | + await EnsureSchemaAsync(db, throwIfMissing: false); | |
| 202 | + if (Volatile.Read(ref _schemaReady) != 1) | |
| 203 | + { | |
| 204 | + return new Dictionary<string, BoundTrainingFileDisplay>(StringComparer.Ordinal); | |
| 205 | + } | |
| 206 | + | |
| 207 | + var rows = await db.Queryable<FlTrainingFileLabelDbEntity>() | |
| 208 | + .InnerJoin<FlTrainingFileDbEntity>((b, f) => b.TrainingFileId == f.Id) | |
| 209 | + .Where((b, f) => ids.Contains(b.LabelId) && !f.IsDeleted) | |
| 210 | + .Select((b, f) => new BoundFileRow | |
| 211 | + { | |
| 212 | + OwnerId = b.LabelId, | |
| 213 | + TrainingFileId = f.Id, | |
| 214 | + FileName = f.FileName | |
| 215 | + }) | |
| 216 | + .ToListAsync(); | |
| 217 | + | |
| 218 | + return rows | |
| 219 | + .GroupBy(x => x.OwnerId, StringComparer.Ordinal) | |
| 220 | + .ToDictionary( | |
| 221 | + g => g.Key, | |
| 222 | + g => | |
| 223 | + { | |
| 224 | + var fileIds = g.Select(x => x.TrainingFileId).Where(x => !string.IsNullOrWhiteSpace(x)).Distinct().ToList(); | |
| 225 | + var names = g.Select(x => x.FileName?.Trim()) | |
| 226 | + .Where(x => !string.IsNullOrWhiteSpace(x)) | |
| 227 | + .Distinct() | |
| 228 | + .ToList(); | |
| 229 | + return new BoundTrainingFileDisplay | |
| 230 | + { | |
| 231 | + BoundTrainingFileIds = fileIds, | |
| 232 | + BoundTrainingFiles = names.Count == 0 | |
| 233 | + ? FoodLabelingDisplayConsts.NotAvailable | |
| 234 | + : string.Join(",", names) | |
| 235 | + }; | |
| 236 | + }, | |
| 237 | + StringComparer.Ordinal); | |
| 238 | + } | |
| 239 | + | |
| 240 | + public static async Task<Dictionary<string, BoundLabelDisplay>> LoadForTrainingFilesAsync( | |
| 241 | + ISqlSugarClient db, | |
| 242 | + IEnumerable<string> trainingFileIds) | |
| 243 | + { | |
| 244 | + var ids = trainingFileIds.Where(x => !string.IsNullOrWhiteSpace(x)).Distinct(StringComparer.Ordinal).ToList(); | |
| 245 | + if (ids.Count == 0) | |
| 246 | + { | |
| 247 | + return new Dictionary<string, BoundLabelDisplay>(StringComparer.Ordinal); | |
| 248 | + } | |
| 249 | + | |
| 250 | + await EnsureSchemaAsync(db, throwIfMissing: false); | |
| 251 | + if (Volatile.Read(ref _schemaReady) != 1) | |
| 252 | + { | |
| 253 | + return new Dictionary<string, BoundLabelDisplay>(StringComparer.Ordinal); | |
| 254 | + } | |
| 255 | + var rows = await db.Queryable<FlTrainingFileLabelDbEntity>() | |
| 256 | + .InnerJoin<FlLabelDbEntity>((b, l) => b.LabelId == l.Id) | |
| 257 | + .Where((b, l) => ids.Contains(b.TrainingFileId) && !l.IsDeleted) | |
| 258 | + .Select((b, l) => new BoundRow | |
| 259 | + { | |
| 260 | + OwnerId = b.TrainingFileId, | |
| 261 | + LabelCode = l.LabelCode, | |
| 262 | + LabelId = l.Id, | |
| 263 | + LabelName = l.LabelName | |
| 264 | + }) | |
| 265 | + .ToListAsync(); | |
| 266 | + | |
| 267 | + return ToDisplayMap(rows); | |
| 268 | + } | |
| 269 | + | |
| 270 | + public static async Task<BoundTrainingFileDisplay> LoadForLabelAsync(ISqlSugarClient db, string labelId) | |
| 271 | + { | |
| 272 | + var map = await LoadForLabelsAsync(db, new[] { labelId }); | |
| 273 | + return map.TryGetValue(labelId, out var display) ? display : EmptyTrainingFileDisplay; | |
| 274 | + } | |
| 275 | + | |
| 276 | + /// <summary>解析单个标签 Id 或 LabelCode;不存在返回 null,不抛异常。</summary> | |
| 277 | + public static async Task<string?> TryResolveInternalLabelIdAsync(ISqlSugarClient db, string? token) | |
| 278 | + { | |
| 279 | + if (string.IsNullOrWhiteSpace(token)) | |
| 280 | + { | |
| 281 | + return null; | |
| 282 | + } | |
| 283 | + | |
| 284 | + var ids = await ResolveInternalLabelIdsAsync(db, new[] { token.Trim() }, throwIfMissing: false); | |
| 285 | + return ids.Count > 0 ? ids[0] : null; | |
| 286 | + } | |
| 287 | + | |
| 288 | + public static async Task<bool> TryEnsureSchemaAsync(ISqlSugarClient db) | |
| 289 | + { | |
| 290 | + await EnsureSchemaAsync(db, throwIfMissing: false); | |
| 291 | + return Volatile.Read(ref _schemaReady) == 1; | |
| 292 | + } | |
| 293 | + | |
| 294 | + public static async Task<BoundLabelDisplay> LoadForTrainingFileAsync(ISqlSugarClient db, string trainingFileId) | |
| 295 | + { | |
| 296 | + var map = await LoadForTrainingFilesAsync(db, new[] { trainingFileId }); | |
| 297 | + return map.TryGetValue(trainingFileId, out var display) ? display : EmptyDisplay; | |
| 298 | + } | |
| 299 | + | |
| 300 | + private static async Task<List<string>> ResolveInternalLabelIdsAsync( | |
| 301 | + ISqlSugarClient db, | |
| 302 | + IEnumerable<string>? inputIds, | |
| 303 | + bool throwIfMissing) | |
| 304 | + { | |
| 305 | + var tokens = (inputIds ?? Enumerable.Empty<string>()) | |
| 306 | + .Where(x => !string.IsNullOrWhiteSpace(x)) | |
| 307 | + .Select(x => x.Trim()) | |
| 308 | + .Distinct(StringComparer.Ordinal) | |
| 309 | + .ToList(); | |
| 310 | + if (tokens.Count == 0) | |
| 311 | + { | |
| 312 | + return new List<string>(); | |
| 313 | + } | |
| 314 | + | |
| 315 | + var found = await db.Queryable<FlLabelDbEntity>() | |
| 316 | + .Where(x => !x.IsDeleted && (tokens.Contains(x.Id) || tokens.Contains(x.LabelCode))) | |
| 317 | + .Select(x => new { x.Id, x.LabelCode }) | |
| 318 | + .ToListAsync(); | |
| 319 | + | |
| 320 | + var byId = found.ToDictionary(x => x.Id, x => x.Id, StringComparer.Ordinal); | |
| 321 | + var byCode = found | |
| 322 | + .Where(x => !string.IsNullOrWhiteSpace(x.LabelCode)) | |
| 323 | + .GroupBy(x => x.LabelCode!, StringComparer.Ordinal) | |
| 324 | + .ToDictionary(g => g.Key, g => g.First().Id, StringComparer.Ordinal); | |
| 325 | + | |
| 326 | + var resolved = new List<string>(); | |
| 327 | + var seen = new HashSet<string>(StringComparer.Ordinal); | |
| 328 | + foreach (var token in tokens) | |
| 329 | + { | |
| 330 | + if (!byId.TryGetValue(token, out var internalId) && !byCode.TryGetValue(token, out internalId)) | |
| 331 | + { | |
| 332 | + if (throwIfMissing) | |
| 333 | + { | |
| 334 | + throw new UserFriendlyException($"绑定标签不存在:{token}"); | |
| 335 | + } | |
| 336 | + | |
| 337 | + continue; | |
| 338 | + } | |
| 339 | + | |
| 340 | + if (seen.Add(internalId)) | |
| 341 | + { | |
| 342 | + resolved.Add(internalId); | |
| 343 | + } | |
| 344 | + } | |
| 345 | + | |
| 346 | + return resolved; | |
| 347 | + } | |
| 348 | + | |
| 349 | + private static async Task<List<string>> ResolveTrainingFileIdsAsync( | |
| 350 | + ISqlSugarClient db, | |
| 351 | + IEnumerable<string>? inputIds, | |
| 352 | + bool throwIfMissing) | |
| 353 | + { | |
| 354 | + var tokens = (inputIds ?? Enumerable.Empty<string>()) | |
| 355 | + .Where(x => !string.IsNullOrWhiteSpace(x)) | |
| 356 | + .Select(x => x.Trim()) | |
| 357 | + .Distinct(StringComparer.Ordinal) | |
| 358 | + .ToList(); | |
| 359 | + if (tokens.Count == 0) | |
| 360 | + { | |
| 361 | + return new List<string>(); | |
| 362 | + } | |
| 363 | + | |
| 364 | + var found = await db.Queryable<FlTrainingFileDbEntity>() | |
| 365 | + .Where(x => !x.IsDeleted && tokens.Contains(x.Id)) | |
| 366 | + .Select(x => x.Id) | |
| 367 | + .ToListAsync(); | |
| 368 | + var foundSet = found.ToHashSet(StringComparer.Ordinal); | |
| 369 | + | |
| 370 | + var resolved = new List<string>(); | |
| 371 | + foreach (var token in tokens) | |
| 372 | + { | |
| 373 | + if (!foundSet.Contains(token)) | |
| 374 | + { | |
| 375 | + if (throwIfMissing) | |
| 376 | + { | |
| 377 | + throw new UserFriendlyException($"绑定培训文件不存在:{token}"); | |
| 378 | + } | |
| 379 | + | |
| 380 | + continue; | |
| 381 | + } | |
| 382 | + | |
| 383 | + resolved.Add(token); | |
| 384 | + } | |
| 385 | + | |
| 386 | + return resolved; | |
| 387 | + } | |
| 388 | + | |
| 389 | + private static Dictionary<string, BoundLabelDisplay> ToDisplayMap(List<BoundRow> rows) | |
| 390 | + { | |
| 391 | + return rows | |
| 392 | + .GroupBy(x => x.OwnerId, StringComparer.Ordinal) | |
| 393 | + .ToDictionary( | |
| 394 | + g => g.Key, | |
| 395 | + g => | |
| 396 | + { | |
| 397 | + var ids = g.Select(ToApiId).Where(x => !string.IsNullOrWhiteSpace(x)).Distinct().ToList(); | |
| 398 | + var names = g.Select(x => x.LabelName?.Trim()) | |
| 399 | + .Where(x => !string.IsNullOrWhiteSpace(x)) | |
| 400 | + .Distinct() | |
| 401 | + .ToList(); | |
| 402 | + return new BoundLabelDisplay | |
| 403 | + { | |
| 404 | + BoundLabelIds = ids, | |
| 405 | + BoundLabels = names.Count == 0 | |
| 406 | + ? FoodLabelingDisplayConsts.NotAvailable | |
| 407 | + : string.Join(",", names) | |
| 408 | + }; | |
| 409 | + }, | |
| 410 | + StringComparer.Ordinal); | |
| 411 | + } | |
| 412 | + | |
| 413 | + private static string ToApiId(BoundRow row) => | |
| 414 | + string.IsNullOrWhiteSpace(row.LabelCode) ? row.LabelId : row.LabelCode!; | |
| 415 | + | |
| 416 | + private sealed class BoundRow | |
| 417 | + { | |
| 418 | + public string OwnerId { get; set; } = string.Empty; | |
| 419 | + | |
| 420 | + public string? LabelCode { get; set; } | |
| 421 | + | |
| 422 | + public string LabelId { get; set; } = string.Empty; | |
| 423 | + | |
| 424 | + public string? LabelName { get; set; } | |
| 425 | + } | |
| 426 | + | |
| 427 | + private sealed class BoundFileRow | |
| 428 | + { | |
| 429 | + public string OwnerId { get; set; } = string.Empty; | |
| 430 | + | |
| 431 | + public string TrainingFileId { get; set; } = string.Empty; | |
| 432 | + | |
| 433 | + public string? FileName { get; set; } | |
| 434 | + } | |
| 435 | +} | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/LabelAlertTimerDisplayHelper.cs
0 → 100644
| 1 | +using System.Globalization; | |
| 2 | +using FoodLabeling.Domain.Shared.Enums; | |
| 3 | + | |
| 4 | +namespace FoodLabeling.Application.Helpers; | |
| 5 | + | |
| 6 | +/// <summary>告警计时器展示字段(格式化过期时刻、弹窗文案、状态)</summary> | |
| 7 | +public static class LabelAlertTimerDisplayHelper | |
| 8 | +{ | |
| 9 | + public const string ExpiredMessageTemplate = "亲爱的{userName},您的{labelName}标签已过期,请及时处理"; | |
| 10 | + | |
| 11 | + public const string StatusRunning = "running"; | |
| 12 | + | |
| 13 | + public const string StatusExpired = "expired"; | |
| 14 | + | |
| 15 | + public static string ToStatusString(DateTime expiresAt, DateTime now) => | |
| 16 | + expiresAt <= now ? StatusExpired : StatusRunning; | |
| 17 | + | |
| 18 | + public static LabelAlertTimerStatus ToStatus(DateTime expiresAt, DateTime now) => | |
| 19 | + expiresAt <= now ? LabelAlertTimerStatus.Expired : LabelAlertTimerStatus.Running; | |
| 20 | + | |
| 21 | + public static string FormatExpiresAt(DateTime expiresAt, string? dateTimeFormat) | |
| 22 | + { | |
| 23 | + var format = dateTimeFormat?.Trim(); | |
| 24 | + if (string.IsNullOrWhiteSpace(format)) | |
| 25 | + { | |
| 26 | + return expiresAt.ToString("yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture); | |
| 27 | + } | |
| 28 | + | |
| 29 | + try | |
| 30 | + { | |
| 31 | + return expiresAt.ToString(format, CultureInfo.GetCultureInfo("en-US")); | |
| 32 | + } | |
| 33 | + catch (FormatException) | |
| 34 | + { | |
| 35 | + return expiresAt.ToString("yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture); | |
| 36 | + } | |
| 37 | + } | |
| 38 | +} | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/LabelAlertTimerWriteHelper.cs
| 1 | 1 | using System.Globalization; |
| 2 | +using System.Text.Json; | |
| 2 | 3 | using FoodLabeling.Application.Services.DbModels; |
| 4 | +using FoodLabeling.Domain.Entities; | |
| 3 | 5 | using FoodLabeling.Domain.Shared.Helpers; |
| 4 | 6 | using SqlSugar; |
| 7 | +using Yi.Framework.Rbac.Domain.Entities; | |
| 5 | 8 | |
| 6 | 9 | namespace FoodLabeling.Application.Helpers; |
| 7 | 10 | |
| 8 | 11 | /// <summary> |
| 9 | -/// 打印成功后写入告警计时器(按 BatchId 幂等,一条批次一条计时器)。 | |
| 12 | +/// 打印成功后写入告警计时器(按 BatchId 幂等;须有到期提醒控件 + 启用模板 + 可解析过期时刻)。 | |
| 10 | 13 | /// </summary> |
| 11 | 14 | public static class LabelAlertTimerWriteHelper |
| 12 | 15 | { |
| 13 | 16 | /// <summary> |
| 14 | - /// 根据打印批次创建告警计时器;已存在未删除记录或无有效过期时刻时直接返回。 | |
| 17 | + /// 根据打印批次创建告警计时器;条件不满足或已存在记录时直接返回。 | |
| 15 | 18 | /// </summary> |
| 16 | 19 | public static async Task TryCreateFromPrintBatchAsync( |
| 17 | 20 | ISqlSugarClient db, |
| 18 | 21 | string batchId, |
| 19 | 22 | string? createdBy, |
| 23 | + string? printedByUserName = null, | |
| 20 | 24 | CancellationToken ct = default) |
| 21 | 25 | { |
| 22 | 26 | var bid = batchId?.Trim(); |
| ... | ... | @@ -27,7 +31,6 @@ public static class LabelAlertTimerWriteHelper |
| 27 | 31 | |
| 28 | 32 | ct.ThrowIfCancellationRequested(); |
| 29 | 33 | |
| 30 | - // BatchId 有唯一索引:含软删记录也不再插入,避免幂等补写撞唯一约束 | |
| 31 | 34 | var exists = await db.Queryable<FlLabelAlertTimerDbEntity>() |
| 32 | 35 | .AnyAsync(x => x.BatchId == bid); |
| 33 | 36 | if (exists) |
| ... | ... | @@ -46,6 +49,21 @@ public static class LabelAlertTimerWriteHelper |
| 46 | 49 | return; |
| 47 | 50 | } |
| 48 | 51 | |
| 52 | + if (!TryFindExpirationAlertTemplateId(task.RenderTemplateJson, out var alertTemplateId)) | |
| 53 | + { | |
| 54 | + return; | |
| 55 | + } | |
| 56 | + | |
| 57 | + var template = (await db.Queryable<FlAlertTemplateDbEntity>() | |
| 58 | + .Where(x => x.Id == alertTemplateId && !x.IsDeleted && x.State) | |
| 59 | + .Take(1) | |
| 60 | + .ToListAsync(ct)) | |
| 61 | + .FirstOrDefault(); | |
| 62 | + if (template is null) | |
| 63 | + { | |
| 64 | + return; | |
| 65 | + } | |
| 66 | + | |
| 49 | 67 | var printedAt = task.PrintedAt ?? task.BaseTime ?? task.CreationTime; |
| 50 | 68 | if (!ReportsPrintLogExpiryHelper.TryResolveExpiryDateTime( |
| 51 | 69 | task.PrintInputJson, |
| ... | ... | @@ -81,6 +99,14 @@ public static class LabelAlertTimerWriteHelper |
| 81 | 99 | .FirstOrDefault(); |
| 82 | 100 | } |
| 83 | 101 | |
| 102 | + var locationId = task.LocationId?.Trim() ?? string.Empty; | |
| 103 | + var locationName = await ResolveLocationNameAsync(db, locationId, ct); | |
| 104 | + var printerName = printedByUserName?.Trim(); | |
| 105 | + if (string.IsNullOrWhiteSpace(printerName)) | |
| 106 | + { | |
| 107 | + printerName = await ResolveUserDisplayNameAsync(db, createdBy, ct); | |
| 108 | + } | |
| 109 | + | |
| 84 | 110 | var durationSeconds = Math.Max(0, (int)(expiresAt - printedAt).TotalSeconds); |
| 85 | 111 | var title = BuildTitle(labelName, durationSeconds); |
| 86 | 112 | var subtitle = BuildSubtitle(durationSeconds, expiresAt); |
| ... | ... | @@ -96,13 +122,19 @@ public static class LabelAlertTimerWriteHelper |
| 96 | 122 | LabelName = labelName, |
| 97 | 123 | ProductId = task.ProductId, |
| 98 | 124 | ProductName = string.IsNullOrWhiteSpace(productName) ? null : productName.Trim(), |
| 99 | - LocationId = task.LocationId?.Trim() ?? string.Empty, | |
| 125 | + LocationId = locationId, | |
| 126 | + LocationName = locationName, | |
| 100 | 127 | PrintedAt = printedAt, |
| 101 | 128 | BaseTime = task.BaseTime, |
| 102 | 129 | ExpiresAt = expiresAt, |
| 103 | 130 | DurationSeconds = durationSeconds, |
| 104 | 131 | Title = title, |
| 105 | 132 | Subtitle = subtitle, |
| 133 | + AlertTemplateId = template.Id, | |
| 134 | + AlertTemplateName = template.TemplateName, | |
| 135 | + DateTimeFormat = template.DateTimeFormat, | |
| 136 | + PrintedByUserId = createdBy, | |
| 137 | + PrintedByUserName = printerName, | |
| 106 | 138 | IsDeleted = false, |
| 107 | 139 | DeletionTime = null, |
| 108 | 140 | CreatedBy = createdBy, |
| ... | ... | @@ -112,6 +144,124 @@ public static class LabelAlertTimerWriteHelper |
| 112 | 144 | await db.Insertable(entity).ExecuteCommandAsync(); |
| 113 | 145 | } |
| 114 | 146 | |
| 147 | + internal static bool TryFindExpirationAlertTemplateId(string? renderTemplateJson, out string templateId) | |
| 148 | + { | |
| 149 | + templateId = string.Empty; | |
| 150 | + if (string.IsNullOrWhiteSpace(renderTemplateJson)) | |
| 151 | + { | |
| 152 | + return false; | |
| 153 | + } | |
| 154 | + | |
| 155 | + try | |
| 156 | + { | |
| 157 | + using var doc = JsonDocument.Parse(renderTemplateJson); | |
| 158 | + if (doc.RootElement.ValueKind != JsonValueKind.Object) | |
| 159 | + { | |
| 160 | + return false; | |
| 161 | + } | |
| 162 | + | |
| 163 | + if (!TryGetProperty(doc.RootElement, "elements", out var elements) || | |
| 164 | + elements.ValueKind != JsonValueKind.Array) | |
| 165 | + { | |
| 166 | + return false; | |
| 167 | + } | |
| 168 | + | |
| 169 | + foreach (var el in elements.EnumerateArray()) | |
| 170 | + { | |
| 171 | + if (el.ValueKind != JsonValueKind.Object || !IsExpirationAlertElement(el)) | |
| 172 | + { | |
| 173 | + continue; | |
| 174 | + } | |
| 175 | + | |
| 176 | + if (!TryGetProperty(el, "config", out var cfg) || cfg.ValueKind != JsonValueKind.Object) | |
| 177 | + { | |
| 178 | + continue; | |
| 179 | + } | |
| 180 | + | |
| 181 | + var id = GetStringProperty(cfg, "alertTemplateId", "AlertTemplateId").Trim(); | |
| 182 | + if (string.IsNullOrWhiteSpace(id)) | |
| 183 | + { | |
| 184 | + continue; | |
| 185 | + } | |
| 186 | + | |
| 187 | + templateId = id; | |
| 188 | + return true; | |
| 189 | + } | |
| 190 | + } | |
| 191 | + catch | |
| 192 | + { | |
| 193 | + return false; | |
| 194 | + } | |
| 195 | + | |
| 196 | + return false; | |
| 197 | + } | |
| 198 | + | |
| 199 | + private static bool IsExpirationAlertElement(JsonElement el) | |
| 200 | + { | |
| 201 | + var typeAdd = GetStringProperty(el, "typeAdd", "TypeAdd"); | |
| 202 | + var elementName = GetStringProperty(el, "elementName", "ElementName"); | |
| 203 | + var typeAddNorm = typeAdd.Trim().ToLowerInvariant().Replace(" ", "", StringComparison.Ordinal); | |
| 204 | + var nameLower = elementName.Trim().ToLowerInvariant(); | |
| 205 | + if (typeAddNorm.Contains("expirationalert", StringComparison.Ordinal)) | |
| 206 | + { | |
| 207 | + return true; | |
| 208 | + } | |
| 209 | + | |
| 210 | + if (nameLower.Contains("expiration alert", StringComparison.Ordinal)) | |
| 211 | + { | |
| 212 | + return true; | |
| 213 | + } | |
| 214 | + | |
| 215 | + return elementName.Contains("到期提醒", StringComparison.Ordinal); | |
| 216 | + } | |
| 217 | + | |
| 218 | + private static async Task<string?> ResolveLocationNameAsync(ISqlSugarClient db, string locationId, CancellationToken ct) | |
| 219 | + { | |
| 220 | + if (string.IsNullOrWhiteSpace(locationId) || !Guid.TryParse(locationId, out var locGuid)) | |
| 221 | + { | |
| 222 | + return null; | |
| 223 | + } | |
| 224 | + | |
| 225 | + var name = (await db.Queryable<LocationAggregateRoot>() | |
| 226 | + .Where(x => x.Id == locGuid) | |
| 227 | + .Select(x => x.LocationName) | |
| 228 | + .Take(1) | |
| 229 | + .ToListAsync(ct)) | |
| 230 | + .FirstOrDefault(); | |
| 231 | + return string.IsNullOrWhiteSpace(name) ? null : name.Trim(); | |
| 232 | + } | |
| 233 | + | |
| 234 | + private static async Task<string?> ResolveUserDisplayNameAsync(ISqlSugarClient db, string? userId, CancellationToken ct) | |
| 235 | + { | |
| 236 | + if (string.IsNullOrWhiteSpace(userId) || !Guid.TryParse(userId, out var uid)) | |
| 237 | + { | |
| 238 | + return null; | |
| 239 | + } | |
| 240 | + | |
| 241 | + var user = (await db.Queryable<UserAggregateRoot>() | |
| 242 | + .Where(x => x.Id == uid) | |
| 243 | + .Select(x => new { x.Name, x.Nick, x.UserName }) | |
| 244 | + .Take(1) | |
| 245 | + .ToListAsync(ct)) | |
| 246 | + .FirstOrDefault(); | |
| 247 | + if (user is null) | |
| 248 | + { | |
| 249 | + return null; | |
| 250 | + } | |
| 251 | + | |
| 252 | + if (!string.IsNullOrWhiteSpace(user.Name)) | |
| 253 | + { | |
| 254 | + return user.Name.Trim(); | |
| 255 | + } | |
| 256 | + | |
| 257 | + if (!string.IsNullOrWhiteSpace(user.Nick)) | |
| 258 | + { | |
| 259 | + return user.Nick.Trim(); | |
| 260 | + } | |
| 261 | + | |
| 262 | + return string.IsNullOrWhiteSpace(user.UserName) ? null : user.UserName.Trim(); | |
| 263 | + } | |
| 264 | + | |
| 115 | 265 | private static string BuildTitle(string labelName, int durationSeconds) |
| 116 | 266 | { |
| 117 | 267 | var hoursText = FormatDurationHoursLabel(durationSeconds); |
| ... | ... | @@ -145,4 +295,37 @@ public static class LabelAlertTimerWriteHelper |
| 145 | 295 | var minutes = Math.Max(1, (int)Math.Ceiling(durationSeconds / 60.0)); |
| 146 | 296 | return minutes == 1 ? "1 minute" : $"{minutes} minutes"; |
| 147 | 297 | } |
| 298 | + | |
| 299 | + private static bool TryGetProperty(JsonElement obj, string name, out JsonElement value) | |
| 300 | + { | |
| 301 | + if (obj.TryGetProperty(name, out value)) | |
| 302 | + { | |
| 303 | + return true; | |
| 304 | + } | |
| 305 | + | |
| 306 | + if (name.Length > 0) | |
| 307 | + { | |
| 308 | + var pascal = char.ToUpperInvariant(name[0]) + name[1..]; | |
| 309 | + if (obj.TryGetProperty(pascal, out value)) | |
| 310 | + { | |
| 311 | + return true; | |
| 312 | + } | |
| 313 | + } | |
| 314 | + | |
| 315 | + value = default; | |
| 316 | + return false; | |
| 317 | + } | |
| 318 | + | |
| 319 | + private static string GetStringProperty(JsonElement obj, params string[] names) | |
| 320 | + { | |
| 321 | + foreach (var name in names) | |
| 322 | + { | |
| 323 | + if (TryGetProperty(obj, name, out var v) && v.ValueKind == JsonValueKind.String) | |
| 324 | + { | |
| 325 | + return v.GetString() ?? string.Empty; | |
| 326 | + } | |
| 327 | + } | |
| 328 | + | |
| 329 | + return string.Empty; | |
| 330 | + } | |
| 148 | 331 | } | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/PagedQueryConvention.cs
| ... | ... | @@ -7,4 +7,19 @@ namespace FoodLabeling.Application.Helpers; |
| 7 | 7 | public static class PagedQueryConvention |
| 8 | 8 | { |
| 9 | 9 | public static int PageIndexFromSkipCount(int skipCount) => skipCount <= 0 ? 1 : skipCount; |
| 10 | + | |
| 11 | + /// <summary> | |
| 12 | + /// 将 ABP 风格 offset(<c>SkipCount=(currentPage-1)*pageSize</c>)转为 SqlSugar 页码(从 1 起)。 | |
| 13 | + /// 例:skipCount=40, maxResultCount=10 → 第 5 页。 | |
| 14 | + /// </summary> | |
| 15 | + public static int PageIndexFromOffset(int skipCount, int maxResultCount) | |
| 16 | + { | |
| 17 | + var pageSize = maxResultCount <= 0 ? 10 : maxResultCount; | |
| 18 | + if (skipCount <= 0) | |
| 19 | + { | |
| 20 | + return 1; | |
| 21 | + } | |
| 22 | + | |
| 23 | + return skipCount / pageSize + 1; | |
| 24 | + } | |
| 10 | 25 | } | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/PlatformMenuHelper.cs
| ... | ... | @@ -17,6 +17,11 @@ public static class PlatformMenuHelper |
| 17 | 17 | return true; |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | + if (IsQrCodeMenu(menu.Id, menu.PermissionCode, menu.Router)) | |
| 21 | + { | |
| 22 | + return true; | |
| 23 | + } | |
| 24 | + | |
| 20 | 25 | var code = menu.PermissionCode?.Trim() ?? string.Empty; |
| 21 | 26 | if (code.StartsWith("menu.platform", StringComparison.OrdinalIgnoreCase)) |
| 22 | 27 | { |
| ... | ... | @@ -27,6 +32,26 @@ public static class PlatformMenuHelper |
| 27 | 32 | return router.StartsWith("/platform", StringComparison.OrdinalIgnoreCase); |
| 28 | 33 | } |
| 29 | 34 | |
| 35 | + /// <summary>二维码已改为仅平台;含历史 management 权限码 / 旧路由。</summary> | |
| 36 | + public static bool IsQrCodeMenu(string? menuId, string? permissionCode, string? router) | |
| 37 | + { | |
| 38 | + if (string.Equals(menuId?.Trim(), "f0010037-0001-4000-8000-000000000037", StringComparison.OrdinalIgnoreCase)) | |
| 39 | + { | |
| 40 | + return true; | |
| 41 | + } | |
| 42 | + | |
| 43 | + var code = permissionCode?.Trim() ?? string.Empty; | |
| 44 | + if (code.Equals("menu.management.qr-codes", StringComparison.OrdinalIgnoreCase) | |
| 45 | + || code.Equals("menu.platform.qr-codes", StringComparison.OrdinalIgnoreCase)) | |
| 46 | + { | |
| 47 | + return true; | |
| 48 | + } | |
| 49 | + | |
| 50 | + var path = router?.Trim() ?? string.Empty; | |
| 51 | + return path.Equals("/qr-codes", StringComparison.OrdinalIgnoreCase) | |
| 52 | + || path.Equals("/platform/qr-codes", StringComparison.OrdinalIgnoreCase); | |
| 53 | + } | |
| 54 | + | |
| 30 | 55 | /// <summary> |
| 31 | 56 | /// 从全量菜单中保留平台菜单及其祖先节点,以便组装菜单树 |
| 32 | 57 | /// </summary> | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/MultiTenancy/FoodLabelingTenantMigrationScriptNames.cs
| ... | ... | @@ -24,6 +24,16 @@ public static class FoodLabelingTenantMigrationScriptNames |
| 24 | 24 | |
| 25 | 25 | public const string LabelAlertTimer = "FoodLabeling.TenantMigrations.fl_label_alert_timer.sql"; |
| 26 | 26 | |
| 27 | + public const string BoundLabel = "FoodLabeling.TenantMigrations.fl_bound_label.sql"; | |
| 28 | + | |
| 29 | + public const string AlertTemplate = "FoodLabeling.TenantMigrations.fl_alert_template.sql"; | |
| 30 | + | |
| 31 | + public const string LabelAlertTimerAlertTemplate = | |
| 32 | + "FoodLabeling.TenantMigrations.fl_label_alert_timer_alert_template.sql"; | |
| 33 | + | |
| 34 | + public const string MenuHidePlatformQrCodes = | |
| 35 | + "FoodLabeling.TenantMigrations.fl_menu_hide_platform_qr_codes.sql"; | |
| 36 | + | |
| 27 | 37 | /// <summary>CodeFirst 之后按序执行的脚本资源名。</summary> |
| 28 | 38 | public static readonly IReadOnlyList<string> TenantInitializationOrder = |
| 29 | 39 | [ |
| ... | ... | @@ -35,6 +45,10 @@ public static class FoodLabelingTenantMigrationScriptNames |
| 35 | 45 | TeamMemberScope, |
| 36 | 46 | TeamMemberRegion, |
| 37 | 47 | Training, |
| 38 | - LabelAlertTimer | |
| 48 | + LabelAlertTimer, | |
| 49 | + BoundLabel, | |
| 50 | + AlertTemplate, | |
| 51 | + LabelAlertTimerAlertTemplate, | |
| 52 | + MenuHidePlatformQrCodes | |
| 39 | 53 | ]; |
| 40 | 54 | } | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Options/FoodLabelingAppUpdateOptions.cs
0 → 100644
| 1 | +namespace FoodLabeling.Application.Options; | |
| 2 | + | |
| 3 | +/// <summary> | |
| 4 | +/// App 热更新(查版本 + 下载 APK)。发布时把新包放到 <see cref="ApkPath"/> 并提高 <see cref="VersionCode"/>。 | |
| 5 | +/// </summary> | |
| 6 | +public class FoodLabelingAppUpdateOptions | |
| 7 | +{ | |
| 8 | + public const string SectionName = "FoodLabeling:AppUpdate"; | |
| 9 | + | |
| 10 | + public bool Enabled { get; set; } = true; | |
| 11 | + | |
| 12 | + public string PackageName { get; set; } = "com.3flabeling.usapp"; | |
| 13 | + | |
| 14 | + /// <summary>整型版本号,须大于 App 本地 <c>versionCode</c> 才会提示更新。</summary> | |
| 15 | + public int VersionCode { get; set; } = 106; | |
| 16 | + | |
| 17 | + public string VersionName { get; set; } = "1.0.6"; | |
| 18 | + | |
| 19 | + public bool ForceUpdate { get; set; } | |
| 20 | + | |
| 21 | + public string Changelog { get; set; } = string.Empty; | |
| 22 | + | |
| 23 | + /// <summary>服务器本地 APK 路径(建议绝对路径)。</summary> | |
| 24 | + public string ApkPath { get; set; } = | |
| 25 | + "/www/wwwroot/FoodLabelingManagementUs/wwwroot/app-update/app-release.apk"; | |
| 26 | +} | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/AlertTemplateAppService.cs
0 → 100644
| 1 | +using FoodLabeling.Application.Contracts.Dtos.AlertTemplate; | |
| 2 | +using FoodLabeling.Application.Contracts.Dtos.Common; | |
| 3 | +using FoodLabeling.Application.Contracts.IServices; | |
| 4 | +using FoodLabeling.Application.Helpers; | |
| 5 | +using FoodLabeling.Application.Services.DbModels; | |
| 6 | +using FoodLabeling.Domain.Shared.Helpers; | |
| 7 | +using Microsoft.AspNetCore.Authorization; | |
| 8 | +using Microsoft.AspNetCore.Mvc; | |
| 9 | +using SqlSugar; | |
| 10 | +using Volo.Abp; | |
| 11 | +using Volo.Abp.Application.Services; | |
| 12 | +using Yi.Framework.SqlSugarCore.Abstractions; | |
| 13 | + | |
| 14 | +namespace FoodLabeling.Application.Services; | |
| 15 | + | |
| 16 | +/// <summary> | |
| 17 | +/// 告警日期时间格式模板(平台告警页 / 标签模板到期提醒下拉) | |
| 18 | +/// </summary> | |
| 19 | +[Authorize] | |
| 20 | +public class AlertTemplateAppService : ApplicationService, IAlertTemplateAppService | |
| 21 | +{ | |
| 22 | + private readonly ISqlSugarDbContext _dbContext; | |
| 23 | + | |
| 24 | + public AlertTemplateAppService(ISqlSugarDbContext dbContext) | |
| 25 | + { | |
| 26 | + _dbContext = dbContext; | |
| 27 | + } | |
| 28 | + | |
| 29 | + /// <summary> | |
| 30 | + /// 分页查询告警模板 | |
| 31 | + /// </summary> | |
| 32 | + /// <remarks> | |
| 33 | + /// 查询当前租户 <c>fl_alert_template</c> 未删除记录。 | |
| 34 | + /// | |
| 35 | + /// 示例请求: | |
| 36 | + /// ```json | |
| 37 | + /// { | |
| 38 | + /// "keyword": "冷藏", | |
| 39 | + /// "state": true, | |
| 40 | + /// "skipCount": 1, | |
| 41 | + /// "maxResultCount": 20 | |
| 42 | + /// } | |
| 43 | + /// ``` | |
| 44 | + /// | |
| 45 | + /// 参数说明: | |
| 46 | + /// - keyword: 模板名称模糊匹配 | |
| 47 | + /// - state: 启用状态 | |
| 48 | + /// - skipCount: 页码(从 1 开始) | |
| 49 | + /// - maxResultCount: 每页条数 | |
| 50 | + /// </remarks> | |
| 51 | + /// <param name="input">分页与筛选</param> | |
| 52 | + /// <returns>分页模板列表</returns> | |
| 53 | + /// <response code="200">成功</response> | |
| 54 | + /// <response code="400">参数无效</response> | |
| 55 | + /// <response code="500">服务器错误</response> | |
| 56 | + [HttpPost] | |
| 57 | + [Route("/api/app/alert-template/list")] | |
| 58 | + public async Task<PagedResultWithPageDto<AlertTemplateDto>> ListAsync(AlertTemplateGetListInputVo input) | |
| 59 | + { | |
| 60 | + input ??= new AlertTemplateGetListInputVo(); | |
| 61 | + var keyword = input.Keyword?.Trim(); | |
| 62 | + RefAsync<int> total = 0; | |
| 63 | + var query = _dbContext.SqlSugarClient.Queryable<FlAlertTemplateDbEntity>() | |
| 64 | + .Where(x => !x.IsDeleted) | |
| 65 | + .WhereIF(!string.IsNullOrWhiteSpace(keyword), x => x.TemplateName.Contains(keyword!)) | |
| 66 | + .WhereIF(input.State is not null, x => x.State == input.State); | |
| 67 | + | |
| 68 | + var pageIndex = PagedQueryConvention.PageIndexFromSkipCount(input.SkipCount); | |
| 69 | + var pageSize = input.MaxResultCount <= 0 ? 10 : input.MaxResultCount; | |
| 70 | + var entities = await query | |
| 71 | + .OrderByDescending(x => x.LastModificationTime) | |
| 72 | + .OrderByDescending(x => x.CreationTime) | |
| 73 | + .ToPageListAsync(pageIndex, pageSize, total); | |
| 74 | + | |
| 75 | + var items = entities.Select(MapDto).ToList(); | |
| 76 | + var totalCount = (long)total; | |
| 77 | + var totalPages = pageSize <= 0 ? 0 : (int)Math.Ceiling(totalCount / (double)pageSize); | |
| 78 | + return new PagedResultWithPageDto<AlertTemplateDto> | |
| 79 | + { | |
| 80 | + PageIndex = pageIndex, | |
| 81 | + PageSize = pageSize, | |
| 82 | + TotalCount = totalCount, | |
| 83 | + TotalPages = totalPages, | |
| 84 | + Items = items | |
| 85 | + }; | |
| 86 | + } | |
| 87 | + | |
| 88 | + /// <summary> | |
| 89 | + /// 告警模板详情 | |
| 90 | + /// </summary> | |
| 91 | + /// <param name="id">模板 Id</param> | |
| 92 | + /// <returns>模板</returns> | |
| 93 | + /// <response code="200">成功</response> | |
| 94 | + /// <response code="400">不存在</response> | |
| 95 | + /// <response code="500">服务器错误</response> | |
| 96 | + [HttpGet] | |
| 97 | + [Route("/api/app/alert-template/{id}")] | |
| 98 | + public async Task<AlertTemplateDto> GetAsync(string id) | |
| 99 | + { | |
| 100 | + var entity = await FindActiveAsync(id); | |
| 101 | + return MapDto(entity); | |
| 102 | + } | |
| 103 | + | |
| 104 | + /// <summary> | |
| 105 | + /// 新增告警模板 | |
| 106 | + /// </summary> | |
| 107 | + /// <remarks> | |
| 108 | + /// 示例请求: | |
| 109 | + /// ```json | |
| 110 | + /// { | |
| 111 | + /// "templateName": "US 过期展示", | |
| 112 | + /// "dateTimeFormat": "MM/dd/yyyy h:mm tt", | |
| 113 | + /// "state": true | |
| 114 | + /// } | |
| 115 | + /// ``` | |
| 116 | + /// | |
| 117 | + /// 参数说明: | |
| 118 | + /// - templateName: 模板名称 | |
| 119 | + /// - dateTimeFormat: 日期时间格式字符串(原样存储,用于 formattedExpiresAt) | |
| 120 | + /// - state: 是否启用 | |
| 121 | + /// </remarks> | |
| 122 | + /// <param name="input">模板字段</param> | |
| 123 | + /// <returns>新建模板</returns> | |
| 124 | + /// <response code="200">成功</response> | |
| 125 | + /// <response code="400">参数无效</response> | |
| 126 | + /// <response code="500">服务器错误</response> | |
| 127 | + [HttpPost] | |
| 128 | + [Route("/api/app/alert-template")] | |
| 129 | + public async Task<AlertTemplateDto> CreateAsync(AlertTemplateCreateInputVo input) | |
| 130 | + { | |
| 131 | + var (name, format) = ValidateInput(input); | |
| 132 | + var now = DateTime.Now; | |
| 133 | + var entity = new FlAlertTemplateDbEntity | |
| 134 | + { | |
| 135 | + Id = YitIdHelper.NextId().ToString(), | |
| 136 | + TemplateName = name, | |
| 137 | + DateTimeFormat = format, | |
| 138 | + State = input.State, | |
| 139 | + IsDeleted = false, | |
| 140 | + CreatedBy = CurrentUser?.Id?.ToString(), | |
| 141 | + CreationTime = now, | |
| 142 | + LastModificationTime = now | |
| 143 | + }; | |
| 144 | + await _dbContext.SqlSugarClient.Insertable(entity).ExecuteCommandAsync(); | |
| 145 | + return MapDto(entity); | |
| 146 | + } | |
| 147 | + | |
| 148 | + /// <summary> | |
| 149 | + /// 编辑告警模板 | |
| 150 | + /// </summary> | |
| 151 | + /// <remarks> | |
| 152 | + /// 示例请求同新增。 | |
| 153 | + /// </remarks> | |
| 154 | + /// <param name="id">模板 Id</param> | |
| 155 | + /// <param name="input">模板字段</param> | |
| 156 | + /// <returns>更新后的模板</returns> | |
| 157 | + /// <response code="200">成功</response> | |
| 158 | + /// <response code="400">不存在或参数无效</response> | |
| 159 | + /// <response code="500">服务器错误</response> | |
| 160 | + [HttpPut] | |
| 161 | + [Route("/api/app/alert-template/{id}")] | |
| 162 | + public async Task<AlertTemplateDto> UpdateAsync(string id, AlertTemplateCreateInputVo input) | |
| 163 | + { | |
| 164 | + var entity = await FindActiveAsync(id); | |
| 165 | + var (name, format) = ValidateInput(input); | |
| 166 | + entity.TemplateName = name; | |
| 167 | + entity.DateTimeFormat = format; | |
| 168 | + entity.State = input.State; | |
| 169 | + entity.LastModificationTime = DateTime.Now; | |
| 170 | + await _dbContext.SqlSugarClient.Updateable(entity).ExecuteCommandAsync(); | |
| 171 | + return MapDto(entity); | |
| 172 | + } | |
| 173 | + | |
| 174 | + /// <summary> | |
| 175 | + /// 软删除告警模板 | |
| 176 | + /// </summary> | |
| 177 | + /// <param name="id">模板 Id</param> | |
| 178 | + /// <response code="200">成功</response> | |
| 179 | + /// <response code="400">不存在</response> | |
| 180 | + /// <response code="500">服务器错误</response> | |
| 181 | + [HttpDelete] | |
| 182 | + [Route("/api/app/alert-template/{id}")] | |
| 183 | + public async Task DeleteAsync(string id) | |
| 184 | + { | |
| 185 | + var entity = await FindActiveAsync(id); | |
| 186 | + var now = DateTime.Now; | |
| 187 | + entity.IsDeleted = true; | |
| 188 | + entity.DeletionTime = now; | |
| 189 | + entity.LastModificationTime = now; | |
| 190 | + await _dbContext.SqlSugarClient.Updateable(entity).ExecuteCommandAsync(); | |
| 191 | + } | |
| 192 | + | |
| 193 | + /// <summary> | |
| 194 | + /// 启用中的告警模板下拉(标签模板编辑器到期提醒) | |
| 195 | + /// </summary> | |
| 196 | + /// <returns>id / templateName / dateTimeFormat</returns> | |
| 197 | + /// <response code="200">成功</response> | |
| 198 | + /// <response code="500">服务器错误</response> | |
| 199 | + [HttpGet] | |
| 200 | + [Route("/api/app/alert-template/options")] | |
| 201 | + public async Task<List<AlertTemplateOptionDto>> GetOptionsAsync() | |
| 202 | + { | |
| 203 | + var rows = await _dbContext.SqlSugarClient.Queryable<FlAlertTemplateDbEntity>() | |
| 204 | + .Where(x => !x.IsDeleted && x.State) | |
| 205 | + .OrderByDescending(x => x.LastModificationTime) | |
| 206 | + .OrderByDescending(x => x.CreationTime) | |
| 207 | + .ToListAsync(); | |
| 208 | + return rows.Select(x => new AlertTemplateOptionDto | |
| 209 | + { | |
| 210 | + Id = x.Id, | |
| 211 | + TemplateName = x.TemplateName, | |
| 212 | + DateTimeFormat = x.DateTimeFormat | |
| 213 | + }).ToList(); | |
| 214 | + } | |
| 215 | + | |
| 216 | + private async Task<FlAlertTemplateDbEntity> FindActiveAsync(string id) | |
| 217 | + { | |
| 218 | + var tid = id?.Trim(); | |
| 219 | + if (string.IsNullOrWhiteSpace(tid)) | |
| 220 | + { | |
| 221 | + throw new UserFriendlyException("模板Id不能为空"); | |
| 222 | + } | |
| 223 | + | |
| 224 | + var entity = await _dbContext.SqlSugarClient.Queryable<FlAlertTemplateDbEntity>() | |
| 225 | + .FirstAsync(x => x.Id == tid && !x.IsDeleted); | |
| 226 | + if (entity is null) | |
| 227 | + { | |
| 228 | + throw new UserFriendlyException("告警模板不存在"); | |
| 229 | + } | |
| 230 | + | |
| 231 | + return entity; | |
| 232 | + } | |
| 233 | + | |
| 234 | + private static (string Name, string Format) ValidateInput(AlertTemplateCreateInputVo? input) | |
| 235 | + { | |
| 236 | + if (input is null) | |
| 237 | + { | |
| 238 | + throw new UserFriendlyException("入参不能为空"); | |
| 239 | + } | |
| 240 | + | |
| 241 | + var name = input.TemplateName?.Trim(); | |
| 242 | + if (string.IsNullOrWhiteSpace(name)) | |
| 243 | + { | |
| 244 | + throw new UserFriendlyException("模板名称不能为空"); | |
| 245 | + } | |
| 246 | + | |
| 247 | + var format = input.DateTimeFormat?.Trim(); | |
| 248 | + if (string.IsNullOrWhiteSpace(format)) | |
| 249 | + { | |
| 250 | + throw new UserFriendlyException("日期时间格式不能为空"); | |
| 251 | + } | |
| 252 | + | |
| 253 | + return (name, format); | |
| 254 | + } | |
| 255 | + | |
| 256 | + private static AlertTemplateDto MapDto(FlAlertTemplateDbEntity x) => | |
| 257 | + new() | |
| 258 | + { | |
| 259 | + Id = x.Id, | |
| 260 | + TemplateName = x.TemplateName, | |
| 261 | + DateTimeFormat = x.DateTimeFormat, | |
| 262 | + State = x.State, | |
| 263 | + CreationTime = x.CreationTime, | |
| 264 | + LastModificationTime = x.LastModificationTime | |
| 265 | + }; | |
| 266 | +} | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/AppUpdateAppService.cs
0 → 100644
| 1 | +using FoodLabeling.Application.Contracts.Dtos.AppUpdate; | |
| 2 | +using FoodLabeling.Application.Contracts.IServices; | |
| 3 | +using FoodLabeling.Application.Helpers; | |
| 4 | +using FoodLabeling.Application.Options; | |
| 5 | +using Microsoft.AspNetCore.Authorization; | |
| 6 | +using Microsoft.AspNetCore.Http; | |
| 7 | +using Microsoft.AspNetCore.Mvc; | |
| 8 | +using Microsoft.Extensions.Logging; | |
| 9 | +using Microsoft.Extensions.Options; | |
| 10 | +using Volo.Abp; | |
| 11 | +using Volo.Abp.Application.Services; | |
| 12 | + | |
| 13 | +namespace FoodLabeling.Application.Services; | |
| 14 | + | |
| 15 | +/// <summary> | |
| 16 | +/// App 版本检查与 APK 下载(对齐锁控面板;供手动「检查更新」)。 | |
| 17 | +/// </summary> | |
| 18 | +[AllowAnonymous] | |
| 19 | +public class AppUpdateAppService : ApplicationService, IAppUpdateAppService | |
| 20 | +{ | |
| 21 | + private readonly FoodLabelingAppUpdateOptions _options; | |
| 22 | + private readonly IHttpContextAccessor _httpContextAccessor; | |
| 23 | + private readonly ILogger<AppUpdateAppService> _logger; | |
| 24 | + | |
| 25 | + public AppUpdateAppService( | |
| 26 | + IOptions<FoodLabelingAppUpdateOptions> options, | |
| 27 | + IHttpContextAccessor httpContextAccessor, | |
| 28 | + ILogger<AppUpdateAppService> logger) | |
| 29 | + { | |
| 30 | + _options = options.Value; | |
| 31 | + _httpContextAccessor = httpContextAccessor; | |
| 32 | + _logger = logger; | |
| 33 | + } | |
| 34 | + | |
| 35 | + /// <summary> | |
| 36 | + /// 查询服务端最新 App 版本 | |
| 37 | + /// </summary> | |
| 38 | + /// <remarks> | |
| 39 | + /// 无需登录。前端用本地 <c>versionCode</c> 与返回的 <c>versionCode</c> 比较: | |
| 40 | + /// 远程更大且 <c>apkReady=true</c> 时再下载 <c>apkUrl</c> 并调起安装。 | |
| 41 | + /// | |
| 42 | + /// 示例请求: | |
| 43 | + /// ```json | |
| 44 | + /// GET /api/app/update?versionCode=106 | |
| 45 | + /// ``` | |
| 46 | + /// | |
| 47 | + /// 参数说明: | |
| 48 | + /// - versionCode: 可选,当前 App 本地整型版本号;传入时出参带 hasUpdate | |
| 49 | + /// </remarks> | |
| 50 | + /// <param name="versionCode">当前 App 本地 versionCode</param> | |
| 51 | + /// <returns>最新版本信息与 APK 地址</returns> | |
| 52 | + /// <response code="200">成功</response> | |
| 53 | + /// <response code="400">更新未启用</response> | |
| 54 | + /// <response code="500">服务器错误</response> | |
| 55 | + [HttpGet] | |
| 56 | + [Route("/api/app/update")] | |
| 57 | + public Task<AppUpdateDto> GetInfoAsync([FromQuery] int? versionCode) | |
| 58 | + { | |
| 59 | + EnsureEnabled(); | |
| 60 | + var apk = AppUpdatePathHelper.ResolveApk(_options); | |
| 61 | + var ready = apk is { Exists: true, Length: > 0 }; | |
| 62 | + if (!ready) | |
| 63 | + { | |
| 64 | + _logger.LogWarning( | |
| 65 | + "App 更新 APK 未就绪,配置路径={Configured},已解析={Resolved},user.dir={UserDir}", | |
| 66 | + _options.ApkPath, | |
| 67 | + apk?.FullName, | |
| 68 | + Environment.CurrentDirectory); | |
| 69 | + } | |
| 70 | + | |
| 71 | + var (remoteCode, remoteName) = AppUpdateVersionResolver.Resolve(apk, _options); | |
| 72 | + bool? hasUpdate = null; | |
| 73 | + if (versionCode.HasValue) | |
| 74 | + { | |
| 75 | + hasUpdate = ready && remoteCode > versionCode.Value; | |
| 76 | + } | |
| 77 | + | |
| 78 | + return Task.FromResult(new AppUpdateDto | |
| 79 | + { | |
| 80 | + PackageName = _options.PackageName ?? string.Empty, | |
| 81 | + VersionCode = remoteCode, | |
| 82 | + VersionName = remoteName, | |
| 83 | + ForceUpdate = _options.ForceUpdate, | |
| 84 | + Changelog = _options.Changelog ?? string.Empty, | |
| 85 | + ApkReady = ready, | |
| 86 | + ApkResolvedPath = apk?.FullName, | |
| 87 | + ApkUrl = BuildApkUrl(), | |
| 88 | + HasUpdate = hasUpdate | |
| 89 | + }); | |
| 90 | + } | |
| 91 | + | |
| 92 | + /// <summary> | |
| 93 | + /// 下载最新 APK(二进制,不走 JSON 包装) | |
| 94 | + /// </summary> | |
| 95 | + /// <remarks> | |
| 96 | + /// 无需登录。Content-Type 为 <c>application/vnd.android.package-archive</c>。 | |
| 97 | + /// </remarks> | |
| 98 | + /// <returns>APK 文件流</returns> | |
| 99 | + /// <response code="200">成功返回文件</response> | |
| 100 | + /// <response code="400">更新未启用或文件不存在</response> | |
| 101 | + /// <response code="500">服务器错误</response> | |
| 102 | + [HttpGet] | |
| 103 | + [Route("/api/app/update/apk")] | |
| 104 | + public IActionResult DownloadApk() | |
| 105 | + { | |
| 106 | + EnsureEnabled(); | |
| 107 | + var apk = AppUpdatePathHelper.ResolveApk(_options); | |
| 108 | + if (apk is not { Exists: true, Length: > 0 }) | |
| 109 | + { | |
| 110 | + throw new UserFriendlyException( | |
| 111 | + "APK 文件不存在,请放到: " + _options.ApkPath | |
| 112 | + + "(当前工作目录=" + Environment.CurrentDirectory + ")"); | |
| 113 | + } | |
| 114 | + | |
| 115 | + var (_, remoteName) = AppUpdateVersionResolver.Resolve(apk, _options); | |
| 116 | + var downloadName = "food-labeling-" + (string.IsNullOrWhiteSpace(remoteName) ? "app" : remoteName) + ".apk"; | |
| 117 | + return new PhysicalFileResult(apk.FullName, "application/vnd.android.package-archive") | |
| 118 | + { | |
| 119 | + FileDownloadName = downloadName | |
| 120 | + }; | |
| 121 | + } | |
| 122 | + | |
| 123 | + private void EnsureEnabled() | |
| 124 | + { | |
| 125 | + if (!_options.Enabled) | |
| 126 | + { | |
| 127 | + throw new UserFriendlyException("App 更新未启用"); | |
| 128 | + } | |
| 129 | + } | |
| 130 | + | |
| 131 | + private string BuildApkUrl() | |
| 132 | + { | |
| 133 | + var request = _httpContextAccessor.HttpContext?.Request; | |
| 134 | + if (request is null) | |
| 135 | + { | |
| 136 | + return "/api/app/update/apk"; | |
| 137 | + } | |
| 138 | + | |
| 139 | + return $"{request.Scheme}://{request.Host}{request.PathBase}/api/app/update/apk"; | |
| 140 | + } | |
| 141 | +} | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/DbModels/FlAlertTemplateDbEntity.cs
0 → 100644
| 1 | +using SqlSugar; | |
| 2 | + | |
| 3 | +namespace FoodLabeling.Application.Services.DbModels; | |
| 4 | + | |
| 5 | +/// <summary>告警日期时间格式模板(<c>fl_alert_template</c>)</summary> | |
| 6 | +[SugarTable("fl_alert_template")] | |
| 7 | +public class FlAlertTemplateDbEntity | |
| 8 | +{ | |
| 9 | + [SugarColumn(IsPrimaryKey = true)] | |
| 10 | + public string Id { get; set; } = string.Empty; | |
| 11 | + | |
| 12 | + public string TemplateName { get; set; } = string.Empty; | |
| 13 | + | |
| 14 | + public string DateTimeFormat { get; set; } = string.Empty; | |
| 15 | + | |
| 16 | + public bool State { get; set; } = true; | |
| 17 | + | |
| 18 | + public bool IsDeleted { get; set; } | |
| 19 | + | |
| 20 | + public DateTime? DeletionTime { get; set; } | |
| 21 | + | |
| 22 | + public string? CreatedBy { get; set; } | |
| 23 | + | |
| 24 | + public DateTime CreationTime { get; set; } | |
| 25 | + | |
| 26 | + public DateTime? LastModificationTime { get; set; } | |
| 27 | +} | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/DbModels/FlLabelAlertTimerDbEntity.cs
| ... | ... | @@ -27,6 +27,8 @@ public class FlLabelAlertTimerDbEntity |
| 27 | 27 | |
| 28 | 28 | public string LocationId { get; set; } = string.Empty; |
| 29 | 29 | |
| 30 | + public string? LocationName { get; set; } | |
| 31 | + | |
| 30 | 32 | public DateTime PrintedAt { get; set; } |
| 31 | 33 | |
| 32 | 34 | public DateTime? BaseTime { get; set; } |
| ... | ... | @@ -39,6 +41,16 @@ public class FlLabelAlertTimerDbEntity |
| 39 | 41 | |
| 40 | 42 | public string Subtitle { get; set; } = string.Empty; |
| 41 | 43 | |
| 44 | + public string? AlertTemplateId { get; set; } | |
| 45 | + | |
| 46 | + public string? AlertTemplateName { get; set; } | |
| 47 | + | |
| 48 | + public string? DateTimeFormat { get; set; } | |
| 49 | + | |
| 50 | + public string? PrintedByUserId { get; set; } | |
| 51 | + | |
| 52 | + public string? PrintedByUserName { get; set; } | |
| 53 | + | |
| 42 | 54 | public bool IsDeleted { get; set; } |
| 43 | 55 | |
| 44 | 56 | public DateTime? DeletionTime { get; set; } | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/DbModels/FlLabelBoundLabelDbEntity.cs
0 → 100644
| 1 | +using SqlSugar; | |
| 2 | + | |
| 3 | +namespace FoodLabeling.Application.Services.DbModels; | |
| 4 | + | |
| 5 | +/// <summary>标签绑定其他标签(<c>fl_label</c> → <c>fl_label</c>)</summary> | |
| 6 | +[SugarTable("fl_label_bound_label")] | |
| 7 | +public class FlLabelBoundLabelDbEntity | |
| 8 | +{ | |
| 9 | + [SugarColumn(IsPrimaryKey = true)] | |
| 10 | + public string Id { get; set; } = string.Empty; | |
| 11 | + | |
| 12 | + public string LabelId { get; set; } = string.Empty; | |
| 13 | + | |
| 14 | + public string BoundLabelId { get; set; } = string.Empty; | |
| 15 | +} | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/DbModels/FlTrainingFileLabelDbEntity.cs
0 → 100644
| 1 | +using SqlSugar; | |
| 2 | + | |
| 3 | +namespace FoodLabeling.Application.Services.DbModels; | |
| 4 | + | |
| 5 | +/// <summary>培训文件绑定标签</summary> | |
| 6 | +[SugarTable("fl_training_file_label")] | |
| 7 | +public class FlTrainingFileLabelDbEntity | |
| 8 | +{ | |
| 9 | + [SugarColumn(IsPrimaryKey = true)] | |
| 10 | + public string Id { get; set; } = string.Empty; | |
| 11 | + | |
| 12 | + public string TrainingFileId { get; set; } = string.Empty; | |
| 13 | + | |
| 14 | + public string LabelId { get; set; } = string.Empty; | |
| 15 | +} | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelAlertTimerAppService.cs
| ... | ... | @@ -18,9 +18,6 @@ namespace FoodLabeling.Application.Services; |
| 18 | 18 | /// </summary> |
| 19 | 19 | public class LabelAlertTimerAppService : ApplicationService, ILabelAlertTimerAppService |
| 20 | 20 | { |
| 21 | - private const string StatusRunning = "running"; | |
| 22 | - private const string StatusExpired = "expired"; | |
| 23 | - | |
| 24 | 21 | private readonly ISqlSugarDbContext _dbContext; |
| 25 | 22 | private readonly IDistributedCache _distributedCache; |
| 26 | 23 | |
| ... | ... | @@ -31,25 +28,24 @@ public class LabelAlertTimerAppService : ApplicationService, ILabelAlertTimerApp |
| 31 | 28 | } |
| 32 | 29 | |
| 33 | 30 | /// <summary> |
| 34 | - /// 分页查询当前门店告警计时器列表(含倒计时) | |
| 31 | + /// 平台:分页查询告警计时器(locationId 可选,空=权限内全店) | |
| 35 | 32 | /// </summary> |
| 36 | 33 | /// <remarks> |
| 37 | 34 | /// 仅展示已打印标签的过期倒计时,<b>不</b>用于判断能否打印。 |
| 38 | - /// 过期时刻与 Print Log「Expiration」列同源(<c>ReportsPrintLogExpiryHelper</c>)。 | |
| 39 | - /// 同一打印批次(<c>BatchId</c>)无论打印多少张标签,仅一条计时器(取 CopyIndex 最小任务)。 | |
| 35 | + /// 过期时刻与 Print Log「Expiration」列同源。 | |
| 40 | 36 | /// |
| 41 | 37 | /// 示例请求: |
| 42 | 38 | /// ```json |
| 43 | 39 | /// { |
| 44 | - /// "locationId": "11111111-1111-1111-1111-111111111111", | |
| 40 | + /// "locationId": "", | |
| 45 | 41 | /// "skipCount": 1, |
| 46 | 42 | /// "maxResultCount": 20, |
| 47 | - /// "dateDay": "2026-08-07" | |
| 43 | + /// "dateDay": "2026-10-13" | |
| 48 | 44 | /// } |
| 49 | 45 | /// ``` |
| 50 | 46 | /// |
| 51 | 47 | /// 参数说明: |
| 52 | - /// - locationId: 当前门店 Id(必填,须已绑定) | |
| 48 | + /// - locationId: 可选;空=当前用户权限范围内全部门店;有值则仅该门店(须可访问) | |
| 53 | 49 | /// - skipCount: 页码(从 1 开始) |
| 54 | 50 | /// - maxResultCount: 每页条数 |
| 55 | 51 | /// - dateDay: 可选,按 PrintedAt 自然日筛选(yyyy-MM-dd) |
| ... | ... | @@ -75,12 +71,21 @@ public class LabelAlertTimerAppService : ApplicationService, ILabelAlertTimerApp |
| 75 | 71 | } |
| 76 | 72 | |
| 77 | 73 | var locationId = input.LocationId?.Trim(); |
| 78 | - if (string.IsNullOrWhiteSpace(locationId)) | |
| 74 | + if (!string.IsNullOrWhiteSpace(locationId)) | |
| 75 | + { | |
| 76 | + await UsAppPrintLogScopeHelper.EnsureUserCanAccessLocationAsync( | |
| 77 | + CurrentUser, _dbContext.SqlSugarClient, locationId); | |
| 78 | + return await QueryListAsync(input, new List<string> { locationId }); | |
| 79 | + } | |
| 80 | + | |
| 81 | + var scopeIds = await ReportsLocationScopeHelper.ResolveReportLocationIdsAsync( | |
| 82 | + CurrentUser, _dbContext.SqlSugarClient, null, null, null); | |
| 83 | + if (scopeIds is { Count: 0 }) | |
| 79 | 84 | { |
| 80 | - throw new UserFriendlyException("门店Id不能为空"); | |
| 85 | + return EmptyPage(input); | |
| 81 | 86 | } |
| 82 | 87 | |
| 83 | - return await QueryListByLocationAsync(locationId, input); | |
| 88 | + return await QueryListAsync(input, scopeIds); | |
| 84 | 89 | } |
| 85 | 90 | |
| 86 | 91 | /// <summary> |
| ... | ... | @@ -101,7 +106,7 @@ public class LabelAlertTimerAppService : ApplicationService, ILabelAlertTimerApp |
| 101 | 106 | /// ``` |
| 102 | 107 | /// |
| 103 | 108 | /// 参数说明: |
| 104 | - /// - locationId: 当前门店 Id(可选;空则取已选门店缓存) | |
| 109 | + /// - locationId: 必须落到一个门店(可选;空则取已选门店缓存);禁止全店 | |
| 105 | 110 | /// - skipCount: 页码(从 1 开始) |
| 106 | 111 | /// - maxResultCount: 每页条数 |
| 107 | 112 | /// - dateDay: 可选,按 PrintedAt 自然日筛选(yyyy-MM-dd) |
| ... | ... | @@ -146,7 +151,9 @@ public class LabelAlertTimerAppService : ApplicationService, ILabelAlertTimerApp |
| 146 | 151 | throw new UserFriendlyException("请先选择门店或传入 locationId"); |
| 147 | 152 | } |
| 148 | 153 | |
| 149 | - return await QueryListByLocationAsync(locationId, input); | |
| 154 | + await UsAppPrintLogScopeHelper.EnsureUserCanAccessLocationAsync( | |
| 155 | + CurrentUser, _dbContext.SqlSugarClient, locationId); | |
| 156 | + return await QueryListAsync(input, new List<string> { locationId }); | |
| 150 | 157 | } |
| 151 | 158 | |
| 152 | 159 | /// <summary> |
| ... | ... | @@ -306,25 +313,26 @@ public class LabelAlertTimerAppService : ApplicationService, ILabelAlertTimerApp |
| 306 | 313 | IsExpired = isExpired, |
| 307 | 314 | ExpiresAt = row.ExpiresAt, |
| 308 | 315 | RemainingSeconds = remaining, |
| 309 | - Status = isExpired ? StatusExpired : StatusRunning, | |
| 316 | + Status = LabelAlertTimerDisplayHelper.ToStatusString(row.ExpiresAt, now), | |
| 310 | 317 | Title = row.Title, |
| 311 | 318 | Subtitle = row.Subtitle, |
| 312 | 319 | TimerId = row.Id, |
| 313 | - BatchId = row.BatchId | |
| 320 | + BatchId = row.BatchId, | |
| 321 | + LabelName = row.LabelName, | |
| 322 | + FormattedExpiresAt = LabelAlertTimerDisplayHelper.FormatExpiresAt(row.ExpiresAt, row.DateTimeFormat), | |
| 323 | + ExpiredMessageTemplate = LabelAlertTimerDisplayHelper.ExpiredMessageTemplate | |
| 314 | 324 | }; |
| 315 | 325 | } |
| 316 | 326 | |
| 317 | - private async Task<PagedResultWithPageDto<LabelAlertTimerListItemDto>> QueryListByLocationAsync( | |
| 318 | - string locationId, | |
| 319 | - LabelAlertTimerGetListInputVo input) | |
| 327 | + private async Task<PagedResultWithPageDto<LabelAlertTimerListItemDto>> QueryListAsync( | |
| 328 | + LabelAlertTimerGetListInputVo input, | |
| 329 | + List<string>? locationIds) | |
| 320 | 330 | { |
| 321 | - await UsAppPrintLogScopeHelper.EnsureUserCanAccessLocationAsync( | |
| 322 | - CurrentUser, _dbContext.SqlSugarClient, locationId); | |
| 323 | - | |
| 324 | 331 | var db = _dbContext.SqlSugarClient; |
| 325 | 332 | RefAsync<int> total = 0; |
| 326 | 333 | var query = db.Queryable<FlLabelAlertTimerDbEntity>() |
| 327 | - .Where(x => !x.IsDeleted && x.LocationId == locationId); | |
| 334 | + .Where(x => !x.IsDeleted) | |
| 335 | + .WhereIF(locationIds is not null, x => locationIds!.Contains(x.LocationId)); | |
| 328 | 336 | |
| 329 | 337 | var (dayStart, dayEndExcl) = ResolveDateDayFilter(input.DateDay); |
| 330 | 338 | if (dayStart.HasValue && dayEndExcl.HasValue) |
| ... | ... | @@ -360,7 +368,6 @@ public class LabelAlertTimerAppService : ApplicationService, ILabelAlertTimerApp |
| 360 | 368 | private static LabelAlertTimerListItemDto MapListItem(FlLabelAlertTimerDbEntity row, DateTime now) |
| 361 | 369 | { |
| 362 | 370 | var remaining = Math.Max(0, (int)(row.ExpiresAt - now).TotalSeconds); |
| 363 | - var isExpired = row.ExpiresAt <= now; | |
| 364 | 371 | |
| 365 | 372 | return new LabelAlertTimerListItemDto |
| 366 | 373 | { |
| ... | ... | @@ -369,15 +376,38 @@ public class LabelAlertTimerAppService : ApplicationService, ILabelAlertTimerApp |
| 369 | 376 | PrintTaskId = row.PrintTaskId, |
| 370 | 377 | LabelId = row.LabelId, |
| 371 | 378 | LabelCode = row.LabelCode, |
| 379 | + LabelName = row.LabelName, | |
| 372 | 380 | Title = row.Title, |
| 373 | 381 | Subtitle = row.Subtitle, |
| 374 | 382 | TotalTime = row.DurationSeconds, |
| 375 | 383 | RemainingTime = remaining, |
| 376 | - Status = isExpired ? StatusExpired : StatusRunning, | |
| 384 | + Status = LabelAlertTimerDisplayHelper.ToStatusString(row.ExpiresAt, now), | |
| 377 | 385 | ExpiresAt = row.ExpiresAt, |
| 386 | + FormattedExpiresAt = LabelAlertTimerDisplayHelper.FormatExpiresAt(row.ExpiresAt, row.DateTimeFormat), | |
| 378 | 387 | PrintedAt = row.PrintedAt, |
| 379 | 388 | LocationId = row.LocationId, |
| 380 | - ProductName = row.ProductName | |
| 389 | + LocationName = row.LocationName, | |
| 390 | + ProductName = row.ProductName, | |
| 391 | + AlertTemplateId = row.AlertTemplateId, | |
| 392 | + AlertTemplateName = row.AlertTemplateName, | |
| 393 | + DateTimeFormat = row.DateTimeFormat, | |
| 394 | + PrintedByUserId = row.PrintedByUserId, | |
| 395 | + PrintedByUserName = row.PrintedByUserName, | |
| 396 | + ExpiredMessageTemplate = LabelAlertTimerDisplayHelper.ExpiredMessageTemplate | |
| 397 | + }; | |
| 398 | + } | |
| 399 | + | |
| 400 | + private static PagedResultWithPageDto<LabelAlertTimerListItemDto> EmptyPage(LabelAlertTimerGetListInputVo input) | |
| 401 | + { | |
| 402 | + var pageSize = input.MaxResultCount <= 0 ? 10 : input.MaxResultCount; | |
| 403 | + var pageIndex = PagedQueryConvention.PageIndexFromSkipCount(input.SkipCount); | |
| 404 | + return new PagedResultWithPageDto<LabelAlertTimerListItemDto> | |
| 405 | + { | |
| 406 | + PageIndex = pageIndex, | |
| 407 | + PageSize = pageSize, | |
| 408 | + TotalCount = 0, | |
| 409 | + TotalPages = 0, | |
| 410 | + Items = new List<LabelAlertTimerListItemDto>() | |
| 381 | 411 | }; |
| 382 | 412 | } |
| 383 | 413 | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelAppService.cs
| ... | ... | @@ -252,6 +252,8 @@ public class LabelAppService : ApplicationService, ILabelAppService |
| 252 | 252 | ProductCategoryName = string.Join(",", g.Select(x => x.ProductCategoryName ?? string.Empty).Select(x => x.Trim()).Where(x => !string.IsNullOrWhiteSpace(x)).Distinct()) |
| 253 | 253 | }); |
| 254 | 254 | |
| 255 | + var boundMap = await BoundLabelBindingHelper.LoadForLabelsAsync(db, pageLabelIds); | |
| 256 | + | |
| 255 | 257 | var items = orderedLabels.Select(x => |
| 256 | 258 | { |
| 257 | 259 | var products = productsMap.TryGetValue(x.Id, out var prod) ? prod.Products : string.Empty; |
| ... | ... | @@ -260,6 +262,7 @@ public class LabelAppService : ApplicationService, ILabelAppService |
| 260 | 262 | locationScopeMap.TryGetValue(x.Id, out var locationScope); |
| 261 | 263 | locationIdsMap.TryGetValue(x.Id, out var locIds); |
| 262 | 264 | appliedRegionTypeMap.TryGetValue(x.Id, out var appliedRegionType); |
| 265 | + boundMap.TryGetValue(x.Id, out var bound); | |
| 263 | 266 | return new LabelGetListOutputDto |
| 264 | 267 | { |
| 265 | 268 | Id = x.LabelCode ?? string.Empty, |
| ... | ... | @@ -275,6 +278,8 @@ public class LabelAppService : ApplicationService, ILabelAppService |
| 275 | 278 | LabelCategoryName = x.LabelCategoryName ?? string.Empty, |
| 276 | 279 | ProductCategoryName = string.IsNullOrWhiteSpace(productCategoryNameValue) ? FoodLabelingDisplayConsts.NotAvailable : productCategoryNameValue, |
| 277 | 280 | Products = products, |
| 281 | + BoundTrainingFileIds = bound?.BoundTrainingFileIds ?? new List<string>(), | |
| 282 | + BoundTrainingFiles = bound?.BoundTrainingFiles ?? FoodLabelingDisplayConsts.NotAvailable, | |
| 278 | 283 | TemplateName = x.TemplateName ?? string.Empty, |
| 279 | 284 | TemplateCode = x.TemplateCode ?? string.Empty, |
| 280 | 285 | LabelTypeName = string.IsNullOrWhiteSpace(x.LabelTypeName) ? FoodLabelingDisplayConsts.NotAvailable : x.LabelTypeName, |
| ... | ... | @@ -404,6 +409,8 @@ public class LabelAppService : ApplicationService, ILabelAppService |
| 404 | 409 | ? new List<string> { partnerIds[0] } |
| 405 | 410 | : partnerIds.Where(x => !AllScopeBindingHelper.IsDeclaredAll(x)).ToList(); |
| 406 | 411 | |
| 412 | + var bound = await BoundLabelBindingHelper.LoadForLabelAsync(db, label.Id); | |
| 413 | + | |
| 407 | 414 | return new LabelGetOutputDto |
| 408 | 415 | { |
| 409 | 416 | Id = label.LabelCode ?? string.Empty, |
| ... | ... | @@ -427,7 +434,9 @@ public class LabelAppService : ApplicationService, ILabelAppService |
| 427 | 434 | TemplateName = template?.TemplateName ?? string.Empty, |
| 428 | 435 | State = label.State, |
| 429 | 436 | LabelInfoJson = labelInfo, |
| 430 | - ProductIds = productIds | |
| 437 | + ProductIds = productIds, | |
| 438 | + BoundTrainingFileIds = bound.BoundTrainingFileIds, | |
| 439 | + BoundTrainingFiles = bound.BoundTrainingFiles | |
| 431 | 440 | }; |
| 432 | 441 | } |
| 433 | 442 | |
| ... | ... | @@ -541,6 +550,8 @@ public class LabelAppService : ApplicationService, ILabelAppService |
| 541 | 550 | ProductId = pid |
| 542 | 551 | }).ToList(); |
| 543 | 552 | await _dbContext.SqlSugarClient.Insertable(rows).ExecuteCommandAsync(); |
| 553 | + await BoundLabelBindingHelper.SaveForLabelAsync( | |
| 554 | + _dbContext.SqlSugarClient, labelId, input.BoundTrainingFileIds, replaceWhenNull: true); | |
| 544 | 555 | |
| 545 | 556 | await LabelCategoryAppService.TouchLabelCategoryLastEditedAsync( |
| 546 | 557 | _dbContext, labelEntity.LabelCategoryId, CurrentUser?.Id?.ToString()); |
| ... | ... | @@ -739,6 +750,7 @@ public class LabelAppService : ApplicationService, ILabelAppService |
| 739 | 750 | LabelCategoryId = item.LabelCategoryId, |
| 740 | 751 | LabelTypeId = item.LabelTypeId, |
| 741 | 752 | ProductIds = item.ProductIds ?? new List<string>(), |
| 753 | + BoundTrainingFileIds = item.BoundTrainingFileIds, | |
| 742 | 754 | LabelInfoJson = item.LabelInfoJson, |
| 743 | 755 | State = item.State |
| 744 | 756 | }; |
| ... | ... | @@ -841,6 +853,8 @@ public class LabelAppService : ApplicationService, ILabelAppService |
| 841 | 853 | ProductId = pid |
| 842 | 854 | }).ToList(); |
| 843 | 855 | await _dbContext.SqlSugarClient.Insertable(rows).ExecuteCommandAsync(); |
| 856 | + await BoundLabelBindingHelper.SaveForLabelAsync( | |
| 857 | + _dbContext.SqlSugarClient, label.Id, input.BoundTrainingFileIds, replaceWhenNull: false); | |
| 844 | 858 | |
| 845 | 859 | var newCategoryId = label.LabelCategoryId; |
| 846 | 860 | await LabelCategoryAppService.TouchLabelCategoryLastEditedAsync( |
| ... | ... | @@ -895,6 +909,7 @@ public class LabelAppService : ApplicationService, ILabelAppService |
| 895 | 909 | await _dbContext.SqlSugarClient.Deleteable<FlLabelProductDbEntity>() |
| 896 | 910 | .Where(x => x.LabelId == label.Id) |
| 897 | 911 | .ExecuteCommandAsync(); |
| 912 | + await BoundLabelBindingHelper.DeleteForLabelAsync(_dbContext.SqlSugarClient, label.Id); | |
| 898 | 913 | |
| 899 | 914 | await LabelCategoryAppService.TouchLabelCategoryLastEditedAsync( |
| 900 | 915 | _dbContext, label.LabelCategoryId, CurrentUser?.Id?.ToString()); | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/TrainingAppService.cs
| ... | ... | @@ -73,7 +73,8 @@ public class TrainingAppService : ApplicationService, ITrainingAppService |
| 73 | 73 | /// 参数说明: |
| 74 | 74 | /// - keyword: 匹配分类名或文件名 |
| 75 | 75 | /// - locationId: 按门店权限过滤可见文件 |
| 76 | - /// - includeFiles: 是否返回文件列表 | |
| 76 | + /// - includeFiles: 是否返回文件列表;文件出参含 boundLabelIds / boundLabels | |
| 77 | + /// - labelId: 可选,按绑定标签(LabelCode 或 Id)过滤文件 | |
| 77 | 78 | /// </remarks> |
| 78 | 79 | /// <param name="input">查询条件</param> |
| 79 | 80 | /// <returns>分类树</returns> |
| ... | ... | @@ -83,6 +84,18 @@ public class TrainingAppService : ApplicationService, ITrainingAppService |
| 83 | 84 | public async Task<List<TrainingCategoryTreeNodeDto>> GetCategoryTreeAsync([FromQuery] TrainingCategoryTreeInputVo input) |
| 84 | 85 | { |
| 85 | 86 | var keyword = input.Keyword?.Trim(); |
| 87 | + var labelToken = input.LabelId?.Trim(); | |
| 88 | + string? boundLabelInternalId = null; | |
| 89 | + if (!string.IsNullOrWhiteSpace(labelToken)) | |
| 90 | + { | |
| 91 | + boundLabelInternalId = await BoundLabelBindingHelper.TryResolveInternalLabelIdAsync( | |
| 92 | + _dbContext.SqlSugarClient, labelToken); | |
| 93 | + if (boundLabelInternalId is null) | |
| 94 | + { | |
| 95 | + return new List<TrainingCategoryTreeNodeDto>(); | |
| 96 | + } | |
| 97 | + } | |
| 98 | + | |
| 86 | 99 | TrainingFileScopeHelper.LocationScopeContext? scopeContext = null; |
| 87 | 100 | if (!string.IsNullOrWhiteSpace(input.LocationId)) |
| 88 | 101 | { |
| ... | ... | @@ -115,6 +128,19 @@ public class TrainingAppService : ApplicationService, ITrainingAppService |
| 115 | 128 | fileQuery = fileQuery.Where(x => x.FileName.Contains(keyword!)); |
| 116 | 129 | } |
| 117 | 130 | |
| 131 | + if (!string.IsNullOrWhiteSpace(boundLabelInternalId) | |
| 132 | + && await BoundLabelBindingHelper.TryEnsureSchemaAsync(_dbContext.SqlSugarClient)) | |
| 133 | + { | |
| 134 | + var labelKey = boundLabelInternalId; | |
| 135 | + fileQuery = fileQuery.Where(x => SqlFunc.Subqueryable<FlTrainingFileLabelDbEntity>() | |
| 136 | + .Where(b => b.TrainingFileId == x.Id && b.LabelId == labelKey) | |
| 137 | + .Any()); | |
| 138 | + } | |
| 139 | + else if (!string.IsNullOrWhiteSpace(boundLabelInternalId)) | |
| 140 | + { | |
| 141 | + fileQuery = fileQuery.Where(x => false); | |
| 142 | + } | |
| 143 | + | |
| 118 | 144 | var files = await fileQuery |
| 119 | 145 | .OrderByDescending(x => x.OrderNum) |
| 120 | 146 | .OrderByDescending(x => x.CreationTime) |
| ... | ... | @@ -130,6 +156,9 @@ public class TrainingAppService : ApplicationService, ITrainingAppService |
| 130 | 156 | var scopeDisplayMap = await TrainingFileScopeHelper.BuildScopeDisplayMapAsync( |
| 131 | 157 | _dbContext.SqlSugarClient, |
| 132 | 158 | allFileEntities); |
| 159 | + var boundMap = await BoundLabelBindingHelper.LoadForTrainingFilesAsync( | |
| 160 | + _dbContext.SqlSugarClient, | |
| 161 | + allFileEntities.Select(x => x.Id)); | |
| 133 | 162 | |
| 134 | 163 | var level1 = categories.Where(x => string.IsNullOrWhiteSpace(x.ParentId)).ToList(); |
| 135 | 164 | var level2Map = categories |
| ... | ... | @@ -163,7 +192,12 @@ public class TrainingAppService : ApplicationService, ITrainingAppService |
| 163 | 192 | continue; |
| 164 | 193 | } |
| 165 | 194 | |
| 166 | - childNodes.Add(MapCategoryNode(l2, fileRows, scopeDisplayMap)); | |
| 195 | + if (!string.IsNullOrWhiteSpace(boundLabelInternalId) && fileRows.Count == 0) | |
| 196 | + { | |
| 197 | + continue; | |
| 198 | + } | |
| 199 | + | |
| 200 | + childNodes.Add(MapCategoryNode(l2, fileRows, scopeDisplayMap, boundMap)); | |
| 167 | 201 | } |
| 168 | 202 | |
| 169 | 203 | var l1NameMatch = string.IsNullOrWhiteSpace(keyword) |
| ... | ... | @@ -178,6 +212,11 @@ public class TrainingAppService : ApplicationService, ITrainingAppService |
| 178 | 212 | continue; |
| 179 | 213 | } |
| 180 | 214 | |
| 215 | + if (!string.IsNullOrWhiteSpace(boundLabelInternalId) && childNodes.Count == 0) | |
| 216 | + { | |
| 217 | + continue; | |
| 218 | + } | |
| 219 | + | |
| 181 | 220 | result.Add(new TrainingCategoryTreeNodeDto |
| 182 | 221 | { |
| 183 | 222 | Id = l1.Id, |
| ... | ... | @@ -359,6 +398,7 @@ public class TrainingAppService : ApplicationService, ITrainingAppService |
| 359 | 398 | /// - regionIds / groupIds: 可含 ALL |
| 360 | 399 | /// - availabilityType 或 appliedLocationType: ALL / SPECIFIED |
| 361 | 400 | /// - locationIds: 可含 ALL |
| 401 | + /// - boundLabelIds: 绑定标签 LabelCode 或 Id,可重复传值 | |
| 362 | 402 | /// </remarks> |
| 363 | 403 | /// <param name="input">上传表单</param> |
| 364 | 404 | /// <returns>文件信息</returns> |
| ... | ... | @@ -456,8 +496,12 @@ public class TrainingAppService : ApplicationService, ITrainingAppService |
| 456 | 496 | now); |
| 457 | 497 | } |
| 458 | 498 | |
| 499 | + await BoundLabelBindingHelper.SaveForTrainingFileAsync( | |
| 500 | + _dbContext.SqlSugarClient, entity.Id, input.BoundLabelIds, replaceWhenNull: true); | |
| 501 | + | |
| 459 | 502 | var display = await TrainingFileScopeHelper.BuildScopeDisplayAsync(_dbContext.SqlSugarClient, entity); |
| 460 | - return MapFileDto(entity, display); | |
| 503 | + var bound = await BoundLabelBindingHelper.LoadForTrainingFileAsync(_dbContext.SqlSugarClient, entity.Id); | |
| 504 | + return MapFileDto(entity, display, bound); | |
| 461 | 505 | } |
| 462 | 506 | |
| 463 | 507 | /// <summary> |
| ... | ... | @@ -473,7 +517,8 @@ public class TrainingAppService : ApplicationService, ITrainingAppService |
| 473 | 517 | /// "partnerIds": ["p1"], |
| 474 | 518 | /// "appliedRegionType": "ALL", |
| 475 | 519 | /// "availabilityType": "SPECIFIED", |
| 476 | - /// "locationIds": ["loc1"] | |
| 520 | + /// "locationIds": ["loc1"], | |
| 521 | + /// "boundLabelIds": ["LB_1001"] | |
| 477 | 522 | /// } |
| 478 | 523 | /// ``` |
| 479 | 524 | /// |
| ... | ... | @@ -482,6 +527,7 @@ public class TrainingAppService : ApplicationService, ITrainingAppService |
| 482 | 527 | /// - appliedPartnerType / partnerIds / companyIds: Company 范围,Id 可含 ALL |
| 483 | 528 | /// - appliedRegionType / regionIds / groupIds: Region 范围,Id 可含 ALL |
| 484 | 529 | /// - availabilityType 或 appliedLocationType / locationIds: Location 范围,Id 可含 ALL |
| 530 | + /// - boundLabelIds: 绑定标签;null 不改动,空数组清空 | |
| 485 | 531 | /// </remarks> |
| 486 | 532 | /// <param name="id">文件Id</param> |
| 487 | 533 | /// <param name="input">文件元数据</param> |
| ... | ... | @@ -510,8 +556,12 @@ public class TrainingAppService : ApplicationService, ITrainingAppService |
| 510 | 556 | entity = await ApplyFileScopeAsync(entity, input); |
| 511 | 557 | } |
| 512 | 558 | |
| 559 | + await BoundLabelBindingHelper.SaveForTrainingFileAsync( | |
| 560 | + _dbContext.SqlSugarClient, entity.Id, input.BoundLabelIds, replaceWhenNull: false); | |
| 561 | + | |
| 513 | 562 | var display = await TrainingFileScopeHelper.BuildScopeDisplayAsync(_dbContext.SqlSugarClient, entity); |
| 514 | - return MapFileDto(entity, display); | |
| 563 | + var bound = await BoundLabelBindingHelper.LoadForTrainingFileAsync(_dbContext.SqlSugarClient, entity.Id); | |
| 564 | + return MapFileDto(entity, display, bound); | |
| 515 | 565 | } |
| 516 | 566 | |
| 517 | 567 | /// <summary> |
| ... | ... | @@ -525,6 +575,7 @@ public class TrainingAppService : ApplicationService, ITrainingAppService |
| 525 | 575 | { |
| 526 | 576 | var entity = await GetFileOrThrowAsync(id); |
| 527 | 577 | await TrainingFileScopeHelper.DeleteScopeRowsAsync(_dbContext.SqlSugarClient, entity.Id); |
| 578 | + await BoundLabelBindingHelper.DeleteForTrainingFileAsync(_dbContext.SqlSugarClient, entity.Id); | |
| 528 | 579 | |
| 529 | 580 | entity.IsDeleted = true; |
| 530 | 581 | entity.LastModificationTime = DateTime.Now; |
| ... | ... | @@ -722,7 +773,8 @@ public class TrainingAppService : ApplicationService, ITrainingAppService |
| 722 | 773 | private static TrainingCategoryTreeNodeDto MapCategoryNode( |
| 723 | 774 | FlTrainingCategoryDbEntity entity, |
| 724 | 775 | List<FlTrainingFileDbEntity> files, |
| 725 | - IReadOnlyDictionary<string, TrainingFileScopeHelper.TrainingFileScopeDisplay> scopeDisplayMap) => | |
| 776 | + IReadOnlyDictionary<string, TrainingFileScopeHelper.TrainingFileScopeDisplay> scopeDisplayMap, | |
| 777 | + IReadOnlyDictionary<string, BoundLabelBindingHelper.BoundLabelDisplay> boundMap) => | |
| 726 | 778 | new() |
| 727 | 779 | { |
| 728 | 780 | Id = entity.Id, |
| ... | ... | @@ -733,13 +785,15 @@ public class TrainingAppService : ApplicationService, ITrainingAppService |
| 733 | 785 | Files = files.Select(file => |
| 734 | 786 | { |
| 735 | 787 | scopeDisplayMap.TryGetValue(file.Id, out var display); |
| 736 | - return MapFileDto(file, display); | |
| 788 | + boundMap.TryGetValue(file.Id, out var bound); | |
| 789 | + return MapFileDto(file, display, bound); | |
| 737 | 790 | }).ToList() |
| 738 | 791 | }; |
| 739 | 792 | |
| 740 | 793 | private static TrainingFileDto MapFileDto( |
| 741 | 794 | FlTrainingFileDbEntity entity, |
| 742 | - TrainingFileScopeHelper.TrainingFileScopeDisplay? display = null) => | |
| 795 | + TrainingFileScopeHelper.TrainingFileScopeDisplay? display = null, | |
| 796 | + BoundLabelBindingHelper.BoundLabelDisplay? bound = null) => | |
| 743 | 797 | new() |
| 744 | 798 | { |
| 745 | 799 | Id = entity.Id, |
| ... | ... | @@ -760,6 +814,8 @@ public class TrainingAppService : ApplicationService, ITrainingAppService |
| 760 | 814 | AvailabilityType = display?.AvailabilityType ?? entity.AvailabilityType, |
| 761 | 815 | Location = display?.Location ?? string.Empty, |
| 762 | 816 | LocationIds = display?.LocationIds ?? new List<string>(), |
| 817 | + BoundLabelIds = bound?.BoundLabelIds ?? new List<string>(), | |
| 818 | + BoundLabels = bound?.BoundLabels ?? FoodLabelingDisplayConsts.NotAvailable, | |
| 763 | 819 | CreationTime = entity.CreationTime, |
| 764 | 820 | LastModificationTime = entity.LastModificationTime |
| 765 | 821 | }; | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/UsAppLabelingAppService.cs
| ... | ... | @@ -544,7 +544,8 @@ public class UsAppLabelingAppService : ApplicationService, IUsAppLabelingAppServ |
| 544 | 544 | await LabelAlertTimerWriteHelper.TryCreateFromPrintBatchAsync( |
| 545 | 545 | _dbContext.SqlSugarClient, |
| 546 | 546 | existedBatchId ?? string.Empty, |
| 547 | - CurrentUser?.Id?.ToString()); | |
| 547 | + CurrentUser?.Id?.ToString(), | |
| 548 | + await ResolveCurrentUserDisplayNameAsync()); | |
| 548 | 549 | return new UsAppLabelPrintOutputDto |
| 549 | 550 | { |
| 550 | 551 | TaskId = existedTaskIds.FirstOrDefault() ?? string.Empty, |
| ... | ... | @@ -696,7 +697,8 @@ public class UsAppLabelingAppService : ApplicationService, IUsAppLabelingAppServ |
| 696 | 697 | await LabelAlertTimerWriteHelper.TryCreateFromPrintBatchAsync( |
| 697 | 698 | _dbContext.SqlSugarClient, |
| 698 | 699 | batchId, |
| 699 | - currentUserId); | |
| 700 | + currentUserId, | |
| 701 | + await ResolveCurrentUserDisplayNameAsync()); | |
| 700 | 702 | |
| 701 | 703 | return new UsAppLabelPrintOutputDto |
| 702 | 704 | { |
| ... | ... | @@ -748,7 +750,8 @@ public class UsAppLabelingAppService : ApplicationService, IUsAppLabelingAppServ |
| 748 | 750 | await LabelAlertTimerWriteHelper.TryCreateFromPrintBatchAsync( |
| 749 | 751 | _dbContext.SqlSugarClient, |
| 750 | 752 | existedBatchId ?? string.Empty, |
| 751 | - CurrentUser?.Id?.ToString()); | |
| 753 | + CurrentUser?.Id?.ToString(), | |
| 754 | + await ResolveCurrentUserDisplayNameAsync()); | |
| 752 | 755 | return new UsAppLabelPrintOutputDto |
| 753 | 756 | { |
| 754 | 757 | TaskId = existedTaskIds.FirstOrDefault() ?? string.Empty, |
| ... | ... | @@ -862,7 +865,8 @@ public class UsAppLabelingAppService : ApplicationService, IUsAppLabelingAppServ |
| 862 | 865 | await LabelAlertTimerWriteHelper.TryCreateFromPrintBatchAsync( |
| 863 | 866 | _dbContext.SqlSugarClient, |
| 864 | 867 | batchId, |
| 865 | - currentUserId); | |
| 868 | + currentUserId, | |
| 869 | + await ResolveCurrentUserDisplayNameAsync()); | |
| 866 | 870 | |
| 867 | 871 | return new UsAppLabelPrintOutputDto |
| 868 | 872 | { |
| ... | ... | @@ -1649,6 +1653,32 @@ public class UsAppLabelingAppService : ApplicationService, IUsAppLabelingAppServ |
| 1649 | 1653 | : $"{ws}x{hs}{u}"; |
| 1650 | 1654 | } |
| 1651 | 1655 | |
| 1656 | + private async Task<string?> ResolveCurrentUserDisplayNameAsync() | |
| 1657 | + { | |
| 1658 | + if (!CurrentUser.Id.HasValue) | |
| 1659 | + { | |
| 1660 | + return CurrentUser.UserName; | |
| 1661 | + } | |
| 1662 | + | |
| 1663 | + var user = await _userRepository.GetFirstAsync(x => x.Id == CurrentUser.Id.Value); | |
| 1664 | + if (user is null) | |
| 1665 | + { | |
| 1666 | + return CurrentUser.UserName; | |
| 1667 | + } | |
| 1668 | + | |
| 1669 | + if (!string.IsNullOrWhiteSpace(user.Name)) | |
| 1670 | + { | |
| 1671 | + return user.Name.Trim(); | |
| 1672 | + } | |
| 1673 | + | |
| 1674 | + if (!string.IsNullOrWhiteSpace(user.Nick)) | |
| 1675 | + { | |
| 1676 | + return user.Nick.Trim(); | |
| 1677 | + } | |
| 1678 | + | |
| 1679 | + return string.IsNullOrWhiteSpace(user.UserName) ? CurrentUser.UserName : user.UserName.Trim(); | |
| 1680 | + } | |
| 1681 | + | |
| 1652 | 1682 | private static string? FormatLabelSizeWithUnit(decimal w, decimal h, string unit) |
| 1653 | 1683 | { |
| 1654 | 1684 | var u = (unit ?? "inch").Trim().ToLowerInvariant(); | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/UsAppTrainingAppService.cs
| ... | ... | @@ -33,13 +33,15 @@ public class UsAppTrainingAppService : ApplicationService, IUsAppTrainingAppServ |
| 33 | 33 | /// ```json |
| 34 | 34 | /// { |
| 35 | 35 | /// "locationId": "3fa85f64-5717-4562-b3fc-2c963f66afa6", |
| 36 | - /// "keyword": "安全" | |
| 36 | + /// "keyword": "安全", | |
| 37 | + /// "labelId": "LB_1001" | |
| 37 | 38 | /// } |
| 38 | 39 | /// ``` |
| 39 | 40 | /// |
| 40 | 41 | /// 参数说明: |
| 41 | 42 | /// - locationId: 当前门店 Id(必填) |
| 42 | 43 | /// - keyword: 可选,匹配分类名或文件名 |
| 44 | + /// - labelId: 可选,标签 LabelCode 或内部 Id,只返回绑定该标签的培训文件 | |
| 43 | 45 | /// </remarks> |
| 44 | 46 | /// <param name="input">查询条件</param> |
| 45 | 47 | /// <returns>分类树(含可见文件)</returns> |
| ... | ... | @@ -64,6 +66,7 @@ public class UsAppTrainingAppService : ApplicationService, IUsAppTrainingAppServ |
| 64 | 66 | { |
| 65 | 67 | Keyword = input.Keyword, |
| 66 | 68 | LocationId = locationId, |
| 69 | + LabelId = input.LabelId, | |
| 67 | 70 | IncludeFiles = true |
| 68 | 71 | }); |
| 69 | 72 | } | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Domain.Shared/Enums/LabelAlertTimerStatus.cs
0 → 100644
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/scripts/2026-10-12代码优化.md
0 → 100644
| 1 | +# 2026-10-12 代码优化接口文档 | |
| 2 | + | |
| 3 | +鉴权:请求头 `Authorization` 填登录返回的 `data.token`(已含 `Bearer `)。 | |
| 4 | +统一包装:`{ "code": 200, "data": {}, "message": "" }` | |
| 5 | +下文示例均为 `data` 内层,字段 camelCase。 | |
| 6 | + | |
| 7 | +标签 ↔ 培训文件为多对多,租户库表 `fl_training_file_label`(`TrainingFileId` + `LabelId`)。 | |
| 8 | + | |
| 9 | +--- | |
| 10 | + | |
| 11 | +## 1. 标签 `/api/app/label` | |
| 12 | + | |
| 13 | +路径参数 `id` = **LabelCode**。 | |
| 14 | +`SkipCount` 为 **页码(从 1 起)**,不是 offset。 | |
| 15 | + | |
| 16 | +本次:原「绑定标签」改为 **绑定培训文件 Id**(`boundTrainingFileIds`)。编辑不传该字段不改绑定,传 `[]` 清空。 | |
| 17 | + | |
| 18 | +### 1.1 分页列表 | |
| 19 | + | |
| 20 | +**GET** `/api/app/label?SkipCount=1&MaxResultCount=10` | |
| 21 | + | |
| 22 | +| Query | 类型 | 说明 | | |
| 23 | +|---|---|---| | |
| 24 | +| SkipCount | int | 页码,从 1 开始 | | |
| 25 | +| MaxResultCount | int | 每页条数 | | |
| 26 | +| Keyword / PartnerId / GroupId / LocationId / ProductId / LabelCategoryId / LabelTypeId / TemplateCode / State | | 筛选,均可选 | | |
| 27 | + | |
| 28 | +列表项相对原接口新增: | |
| 29 | + | |
| 30 | +| 字段 | 类型 | 说明 | | |
| 31 | +|---|---|---| | |
| 32 | +| boundTrainingFileIds | string[] | 绑定的培训文件 Id | | |
| 33 | +| boundTrainingFiles | string | 文件名逗号拼接,无则为 `N/A` | | |
| 34 | + | |
| 35 | +```json | |
| 36 | +{ | |
| 37 | + "pageIndex": 1, | |
| 38 | + "pageSize": 10, | |
| 39 | + "totalCount": 100, | |
| 40 | + "totalPages": 10, | |
| 41 | + "items": [ | |
| 42 | + { | |
| 43 | + "id": "LB_1001", | |
| 44 | + "labelName": "Chicken Salad", | |
| 45 | + "boundTrainingFileIds": ["file-id-1"], | |
| 46 | + "boundTrainingFiles": "手册.pdf", | |
| 47 | + "state": true | |
| 48 | + } | |
| 49 | + ] | |
| 50 | +} | |
| 51 | +``` | |
| 52 | + | |
| 53 | +(其余列表字段:locationName、locationIds、region、regionIds、groupIds、appliedRegionType、labelCategoryName、productCategoryName、products、templateName、templateCode、labelTypeName、lastEdited、hasError 与原来一致。) | |
| 54 | + | |
| 55 | +### 1.2 详情 | |
| 56 | + | |
| 57 | +**GET** `/api/app/label/{id}` | |
| 58 | + | |
| 59 | +出参在原有字段上增加 `boundTrainingFileIds`、`boundTrainingFiles`。 | |
| 60 | + | |
| 61 | +### 1.3 新增 | |
| 62 | + | |
| 63 | +**POST** `/api/app/label` | |
| 64 | + | |
| 65 | +| 字段 | 必填 | 说明 | | |
| 66 | +|---|---|---| | |
| 67 | +| labelName / templateCode / labelCategoryId | 是 | | | |
| 68 | +| productIds | 是 | 至少 1 个 | | |
| 69 | +| boundTrainingFileIds | 否 | 培训文件 Id 数组 | | |
| 70 | +| 其余范围字段 | 否 | partnerId、appliedRegionType、regionIds、locationIds 等与原来一致 | | |
| 71 | + | |
| 72 | +```json | |
| 73 | +{ | |
| 74 | + "labelName": "Chicken Salad", | |
| 75 | + "templateCode": "TPL_NUTRITION_3X6", | |
| 76 | + "labelCategoryId": "cat-id", | |
| 77 | + "productIds": ["product-id"], | |
| 78 | + "boundTrainingFileIds": ["file-id-1", "file-id-2"], | |
| 79 | + "state": true | |
| 80 | +} | |
| 81 | +``` | |
| 82 | + | |
| 83 | +成功返回详情。非法文件 Id:`绑定培训文件不存在:xxx`。 | |
| 84 | + | |
| 85 | +### 1.4 编辑 | |
| 86 | + | |
| 87 | +**PUT** `/api/app/label/{id}` | |
| 88 | + | |
| 89 | +Body 与新增类似(无 labelCode)。 | |
| 90 | +`boundTrainingFileIds`:省略不改;`[]` 清空;有值全量覆盖。 | |
| 91 | + | |
| 92 | +--- | |
| 93 | + | |
| 94 | +## 2. 培训 `/api/app/training` | |
| 95 | + | |
| 96 | +查询树:**GET** `/api/app/training/category-tree?includeFiles=true` | |
| 97 | +新增/编辑绑定标签走 **文件** 上传与编辑(分类本身不绑标签)。 | |
| 98 | + | |
| 99 | +本次:文件新增/编辑增加 **绑定标签 Id** `boundLabelIds`(LabelCode 或内部 Id)。查询树文件节点带回该字段。 | |
| 100 | + | |
| 101 | +### 2.1 分类树(含文件) | |
| 102 | + | |
| 103 | +**GET** `/api/app/training/category-tree?includeFiles=true` | |
| 104 | + | |
| 105 | +| Query | 类型 | 必填 | 说明 | | |
| 106 | +|---|---|---|---| | |
| 107 | +| includeFiles | bool | 否 | 默认 true,是否带文件 | | |
| 108 | +| keyword | string | 否 | 分类名或文件名 | | |
| 109 | +| locationId | string | 否 | 按门店过滤可见文件 | | |
| 110 | +| labelId | string | 否 | 只返回绑定了该标签的文件 | | |
| 111 | + | |
| 112 | +文件节点新增: | |
| 113 | + | |
| 114 | +| 字段 | 类型 | 说明 | | |
| 115 | +|---|---|---| | |
| 116 | +| boundLabelIds | string[] | 绑定标签 Id(LabelCode) | | |
| 117 | +| boundLabels | string | 标签名称逗号拼接,无则为 `N/A` | | |
| 118 | + | |
| 119 | +```json | |
| 120 | +[ | |
| 121 | + { | |
| 122 | + "id": "cat-l1", | |
| 123 | + "categoryName": "Safety", | |
| 124 | + "parentId": null, | |
| 125 | + "orderNum": 100, | |
| 126 | + "children": [ | |
| 127 | + { | |
| 128 | + "id": "cat-l2", | |
| 129 | + "categoryName": "Prep", | |
| 130 | + "parentId": "cat-l1", | |
| 131 | + "orderNum": 90, | |
| 132 | + "children": [], | |
| 133 | + "files": [ | |
| 134 | + { | |
| 135 | + "id": "file-id-1", | |
| 136 | + "categoryId": "cat-l2", | |
| 137 | + "fileName": "手册.pdf", | |
| 138 | + "fileUrl": "/training/....pdf", | |
| 139 | + "fileType": "doc", | |
| 140 | + "fileSize": 1024, | |
| 141 | + "orderNum": 100, | |
| 142 | + "boundLabelIds": ["LB_1001"], | |
| 143 | + "boundLabels": "Chicken Salad" | |
| 144 | + } | |
| 145 | + ] | |
| 146 | + } | |
| 147 | + ], | |
| 148 | + "files": [] | |
| 149 | + } | |
| 150 | +] | |
| 151 | +``` | |
| 152 | + | |
| 153 | +### 2.2 上传文件(新增) | |
| 154 | + | |
| 155 | +**POST** `/api/app/training/file/upload` | |
| 156 | +`multipart/form-data` | |
| 157 | + | |
| 158 | +| 字段 | 必填 | 说明 | | |
| 159 | +|---|---|---| | |
| 160 | +| file | 是 | 文件,最大 20MB | | |
| 161 | +| categoryId | 是 | 二级分类 Id | | |
| 162 | +| orderNum | 否 | 排序 | | |
| 163 | +| boundLabelIds | 否 | 可重复,标签 LabelCode 或 Id | | |
| 164 | +| 范围字段 | 否 | appliedPartnerType、partnerIds、appliedRegionType、regionIds、availabilityType、locationIds 等 | | |
| 165 | + | |
| 166 | +```bash | |
| 167 | +curl -X POST "https://{host}/api/app/training/file/upload" \ | |
| 168 | + -H "Authorization: {token}" \ | |
| 169 | + -F "file=@手册.pdf" \ | |
| 170 | + -F "categoryId=cat-l2" \ | |
| 171 | + -F "boundLabelIds=LB_1001" | |
| 172 | +``` | |
| 173 | + | |
| 174 | +返回 `TrainingFileDto`(含 `boundLabelIds`)。 | |
| 175 | + | |
| 176 | +### 2.3 编辑文件 | |
| 177 | + | |
| 178 | +**PUT** `/api/app/training/{id}/file` | |
| 179 | + | |
| 180 | +```json | |
| 181 | +{ | |
| 182 | + "fileName": "操作手册.pdf", | |
| 183 | + "orderNum": 100, | |
| 184 | + "boundLabelIds": ["LB_1001", "LB_1002"] | |
| 185 | +} | |
| 186 | +``` | |
| 187 | + | |
| 188 | +`boundLabelIds`:省略不改;`[]` 清空。非法标签:`绑定标签不存在:xxx`。 | |
| 189 | + | |
| 190 | +--- | |
| 191 | + | |
| 192 | +## 3. 系统菜单分页(同日修复) | |
| 193 | + | |
| 194 | +**GET** `/api/app/th-rbac-menu/list?maxResultCount=10&skipCount=40` | |
| 195 | + | |
| 196 | +`skipCount` 为 **offset**:`(currentPage-1)*maxResultCount`。上例为第 5 页。 | |
| 197 | +出参 `totalCount` + `items`(含 routeUrl、isShow 等)。 | |
| 198 | + | |
| 199 | +--- | |
| 200 | + | |
| 201 | +## 4. App 培训树(同日) | |
| 202 | + | |
| 203 | +**GET** `/api/app/us-app-training/tree?locationId={门店Id}&labelId={标签Id}` | |
| 204 | + | |
| 205 | +`locationId` 必填;`labelId` 可选,按绑定标签筛文件。 | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/scripts/2026-10-15代码.md
0 → 100644
| 1 | +# 2026-10-15 App 手动更新(前端对接) | |
| 2 | + | |
| 3 | +鉴权:本接口**无需登录**(可不带 `Authorization`)。 | |
| 4 | +统一包装:`GET /api/app/update` 返回 `{ "code": 200, "data": {}, "message": "" }`。 | |
| 5 | +`GET /api/app/update/apk` 为**二进制 APK**,不要当 JSON 解析。 | |
| 6 | + | |
| 7 | +对齐锁控面板:查版本 → 弹窗确认 → 下载 APK → 调起系统安装页。 | |
| 8 | +后端只提供接口;前端(UniApp 打印端)在「Support / 关于」增加**手动检查更新**即可,不要改后端路由。 | |
| 9 | + | |
| 10 | +--- | |
| 11 | + | |
| 12 | +## 1. 查询最新版本 | |
| 13 | + | |
| 14 | +**GET** `/api/app/update` | |
| 15 | + | |
| 16 | +| Query | 类型 | 必填 | 说明 | | |
| 17 | +|---|---|---|---| | |
| 18 | +| versionCode | int | 否 | 当前 App 本地整型版本(`manifest.versionCode` / `plus.runtime.versionCode`)。传入时 `data.hasUpdate` 有值 | | |
| 19 | + | |
| 20 | +### data 字段 | |
| 21 | + | |
| 22 | +| 字段 | 类型 | 说明 | | |
| 23 | +|---|---|---| | |
| 24 | +| packageName | string | 包名,仅展示/校验,可不强制匹配 | | |
| 25 | +| versionCode | int | 服务端最新整型版本 | | |
| 26 | +| versionName | string | 展示用,如 `1.0.7` | | |
| 27 | +| forceUpdate | bool | `true` 时弹窗不可取消,必须更新 | | |
| 28 | +| changelog | string | 更新说明,可空 | | |
| 29 | +| apkUrl | string | APK 完整下载地址(即 `/api/app/update/apk`) | | |
| 30 | +| apkReady | bool | 服务端是否已放好 APK 文件 | | |
| 31 | +| apkResolvedPath | string | 服务端本地路径,仅排查用,界面不要展示 | | |
| 32 | +| hasUpdate | bool / null | 只有请求带了 `versionCode` 才有:远程更大且 `apkReady` 为 true | | |
| 33 | + | |
| 34 | +### 判断是否有更新(与锁控一致) | |
| 35 | + | |
| 36 | +``` | |
| 37 | +本地 versionCode < data.versionCode 且 data.apkReady === true 且 data.apkUrl 非空 | |
| 38 | +``` | |
| 39 | + | |
| 40 | +也可直接用 `data.hasUpdate === true`(须在请求里带本地 `versionCode`)。 | |
| 41 | + | |
| 42 | +`apkReady=false`:提示「服务器尚未上传安装包」,不要去下载。 | |
| 43 | + | |
| 44 | +已是最新:Toast「已是最新版本 v{本地 versionName}」。 | |
| 45 | + | |
| 46 | +--- | |
| 47 | + | |
| 48 | +## 2. 下载 APK | |
| 49 | + | |
| 50 | +**GET** `/api/app/update/apk` | |
| 51 | + | |
| 52 | +- 响应:`application/vnd.android.package-archive` | |
| 53 | +- 用 `uni.downloadFile({ url: data.apkUrl })`,成功后再 `plus.runtime.install(tempFilePath, { force: false })` | |
| 54 | +- Android 需「允许安装未知应用」权限(API 26+:`REQUEST_INSTALL_PACKAGES`) | |
| 55 | + | |
| 56 | +--- | |
| 57 | + | |
| 58 | +## 3. 建议交互(Support 页) | |
| 59 | + | |
| 60 | +当前 Support 已展示 App Version / Build Number,建议在版本卡片下加按钮 **Check for updates / 检查更新**: | |
| 61 | + | |
| 62 | +1. 取本地 `versionCode`(与 Build Number 同源) | |
| 63 | +2. `GET /api/app/update?versionCode={本地}` | |
| 64 | +3. 无更新 → Toast | |
| 65 | +4. 有更新 → 弹窗标题「应用更新」,正文:`发现新版本 {versionName}\n{changelog}` | |
| 66 | + - `forceUpdate=false`:立即更新 / 稍后 | |
| 67 | + - `forceUpdate=true`:仅「立即更新」,不可关闭 | |
| 68 | +5. 立即更新 → 下载进度 → 调起安装页,用户点一次「安装」 | |
| 69 | + | |
| 70 | +不要做静默安装。不要在启动时强制自动弹窗(需求为**手动更新**);若以后要自动检查,仍调同一接口即可。 | |
| 71 | + | |
| 72 | +--- | |
| 73 | + | |
| 74 | +## 4. 请求示例 | |
| 75 | + | |
| 76 | +```http | |
| 77 | +GET /api/app/update?versionCode=106 | |
| 78 | +``` | |
| 79 | + | |
| 80 | +`data` 示例: | |
| 81 | + | |
| 82 | +```json | |
| 83 | +{ | |
| 84 | + "packageName": "com.3flabeling.usapp", | |
| 85 | + "versionCode": 107, | |
| 86 | + "versionName": "1.0.7", | |
| 87 | + "forceUpdate": false, | |
| 88 | + "changelog": "修复打印连接", | |
| 89 | + "apkUrl": "https://flusapi-tetest.3flabeling.com/api/app/update/apk", | |
| 90 | + "apkReady": true, | |
| 91 | + "apkResolvedPath": "/www/wwwroot/FoodLabelingManagementUs/wwwroot/app-update/app-release.apk", | |
| 92 | + "hasUpdate": true | |
| 93 | +} | |
| 94 | +``` | |
| 95 | + | |
| 96 | +--- | |
| 97 | + | |
| 98 | +## 5. 发布约定(给联调) | |
| 99 | + | |
| 100 | +**接口里的 versionCode / versionName 跟 APK 走,不跟后端日常发版走。** | |
| 101 | + | |
| 102 | +- 只修后端 bug、重新部署 API:不换 APK → 检查更新仍是旧号,App 不会被提示更新。 | |
| 103 | +- 前端要发新包:把新 APK(`manifest.json` 里 versionCode 已 +1)放到 | |
| 104 | + `/www/wwwroot/FoodLabelingManagementTeUsTest/wwwroot/app-update/app-release.apk` | |
| 105 | + 后端会从包内 `manifest.json` 读出版本。读不到时可在同目录放 `version.json`: | |
| 106 | + `{"versionCode":107,"versionName":"1.0.7"}` | |
| 107 | +- `appsettings.json` 的 `FoodLabeling:AppUpdate.VersionCode` 只是**没有 APK 时的兜底**,日常修 bug 不用改。 | |
| 108 | +- `ForceUpdate` / `Changelog` 仍在 | |
| 109 | + `美国版/Food Labeling Management Code/Yi.Abp.Net8/src/Yi.Abp.Web/appsettings.json` | |
| 110 | + 的 `FoodLabeling.AppUpdate` 里手动改。 | |
| 111 | + | |
| 112 | +无新数据库表,主库/租户库都不用改。 | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/scripts/fl_alert_template.sql
0 → 100644
| 1 | +-- 告警日期时间格式模板(租户业务库) | |
| 2 | +-- 执行前请备份;可重复执行 | |
| 3 | + | |
| 4 | +SET @db := DATABASE(); | |
| 5 | + | |
| 6 | +CREATE TABLE IF NOT EXISTS `fl_alert_template` ( | |
| 7 | + `Id` varchar(36) NOT NULL COMMENT '主键(YitId)', | |
| 8 | + `TemplateName` varchar(200) NOT NULL COMMENT '模板名称', | |
| 9 | + `DateTimeFormat` varchar(100) NOT NULL COMMENT '日期时间格式(如 MM/dd/yyyy h:mm tt)', | |
| 10 | + `State` tinyint(1) NOT NULL DEFAULT 1 COMMENT '启用状态', | |
| 11 | + `IsDeleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '软删', | |
| 12 | + `DeletionTime` datetime DEFAULT NULL, | |
| 13 | + `CreatedBy` varchar(36) DEFAULT NULL, | |
| 14 | + `CreationTime` datetime NOT NULL, | |
| 15 | + `LastModificationTime` datetime DEFAULT NULL, | |
| 16 | + PRIMARY KEY (`Id`), | |
| 17 | + KEY `idx_fl_alert_template_state` (`State`), | |
| 18 | + KEY `idx_fl_alert_template_name` (`TemplateName`) | |
| 19 | +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='告警日期时间格式模板'; | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/scripts/fl_bound_label.sql
0 → 100644
| 1 | +-- 标签 / 培训文件「绑定标签」关联表 | |
| 2 | +-- 执行前请备份;可重复执行 | |
| 3 | + | |
| 4 | +SET @db := DATABASE(); | |
| 5 | + | |
| 6 | +CREATE TABLE IF NOT EXISTS `fl_label_bound_label` ( | |
| 7 | + `Id` varchar(36) NOT NULL COMMENT '主键', | |
| 8 | + `LabelId` varchar(36) NOT NULL COMMENT '主标签 fl_label.Id', | |
| 9 | + `BoundLabelId` varchar(36) NOT NULL COMMENT '被绑定标签 fl_label.Id', | |
| 10 | + PRIMARY KEY (`Id`), | |
| 11 | + UNIQUE KEY `uk_fl_label_bound_label` (`LabelId`, `BoundLabelId`), | |
| 12 | + KEY `idx_fl_label_bound_owner` (`LabelId`), | |
| 13 | + KEY `idx_fl_label_bound_target` (`BoundLabelId`) | |
| 14 | +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='标签绑定其他标签'; | |
| 15 | + | |
| 16 | +CREATE TABLE IF NOT EXISTS `fl_training_file_label` ( | |
| 17 | + `Id` varchar(36) NOT NULL COMMENT '主键', | |
| 18 | + `TrainingFileId` varchar(36) NOT NULL COMMENT 'fl_training_file.Id', | |
| 19 | + `LabelId` varchar(36) NOT NULL COMMENT 'fl_label.Id', | |
| 20 | + PRIMARY KEY (`Id`), | |
| 21 | + UNIQUE KEY `uk_fl_training_file_label` (`TrainingFileId`, `LabelId`), | |
| 22 | + KEY `idx_fl_tflabel_file` (`TrainingFileId`), | |
| 23 | + KEY `idx_fl_tflabel_label` (`LabelId`) | |
| 24 | +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='培训文件绑定标签'; | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/scripts/fl_label_alert_timer.sql
| ... | ... | @@ -13,12 +13,18 @@ CREATE TABLE IF NOT EXISTS `fl_label_alert_timer` ( |
| 13 | 13 | `ProductId` varchar(36) DEFAULT NULL COMMENT '产品Id', |
| 14 | 14 | `ProductName` varchar(500) DEFAULT NULL COMMENT '产品名称', |
| 15 | 15 | `LocationId` varchar(36) NOT NULL COMMENT '门店Id', |
| 16 | + `LocationName` varchar(200) DEFAULT NULL COMMENT '门店名冗余', | |
| 16 | 17 | `PrintedAt` datetime NOT NULL COMMENT '打印时刻(PrintedAt ?? BaseTime ?? CreationTime)', |
| 17 | 18 | `BaseTime` datetime DEFAULT NULL COMMENT '基准时间', |
| 18 | 19 | `ExpiresAt` datetime NOT NULL COMMENT '过期时刻', |
| 19 | 20 | `DurationSeconds` int NOT NULL DEFAULT 0 COMMENT '总时长(秒)', |
| 20 | 21 | `Title` varchar(500) NOT NULL COMMENT '标题', |
| 21 | 22 | `Subtitle` varchar(500) NOT NULL COMMENT '副标题', |
| 23 | + `AlertTemplateId` varchar(36) DEFAULT NULL COMMENT '告警模板Id', | |
| 24 | + `AlertTemplateName` varchar(200) DEFAULT NULL COMMENT '告警模板名称', | |
| 25 | + `DateTimeFormat` varchar(100) DEFAULT NULL COMMENT '过期时刻展示格式', | |
| 26 | + `PrintedByUserId` varchar(36) DEFAULT NULL COMMENT '打印人Id', | |
| 27 | + `PrintedByUserName` varchar(200) DEFAULT NULL COMMENT '打印人姓名', | |
| 22 | 28 | `IsDeleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '软删', |
| 23 | 29 | `DeletionTime` datetime DEFAULT NULL COMMENT '删除时间', |
| 24 | 30 | `CreatedBy` varchar(36) DEFAULT NULL COMMENT '创建者', | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/scripts/fl_label_alert_timer_alert_template.sql
0 → 100644
| 1 | +-- 告警计时器扩展:模板冗余、打印人、门店名(租户业务库) | |
| 2 | +-- 执行前请备份;可重复执行 | |
| 3 | + | |
| 4 | +SET @db := DATABASE(); | |
| 5 | + | |
| 6 | +SET @c := ( | |
| 7 | + SELECT COUNT(*) FROM information_schema.COLUMNS | |
| 8 | + WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'fl_label_alert_timer' AND COLUMN_NAME = 'AlertTemplateId' | |
| 9 | +); | |
| 10 | +SET @ddl := IF( | |
| 11 | + @c = 0, | |
| 12 | + 'ALTER TABLE `fl_label_alert_timer` ADD COLUMN `AlertTemplateId` varchar(36) NULL DEFAULT NULL COMMENT ''告警模板Id'' AFTER `Subtitle`', | |
| 13 | + 'SELECT 1' | |
| 14 | +); | |
| 15 | +PREPARE s FROM @ddl; EXECUTE s; DEALLOCATE PREPARE s; | |
| 16 | + | |
| 17 | +SET @c := ( | |
| 18 | + SELECT COUNT(*) FROM information_schema.COLUMNS | |
| 19 | + WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'fl_label_alert_timer' AND COLUMN_NAME = 'AlertTemplateName' | |
| 20 | +); | |
| 21 | +SET @ddl := IF( | |
| 22 | + @c = 0, | |
| 23 | + 'ALTER TABLE `fl_label_alert_timer` ADD COLUMN `AlertTemplateName` varchar(200) NULL DEFAULT NULL COMMENT ''告警模板名称'' AFTER `AlertTemplateId`', | |
| 24 | + 'SELECT 1' | |
| 25 | +); | |
| 26 | +PREPARE s FROM @ddl; EXECUTE s; DEALLOCATE PREPARE s; | |
| 27 | + | |
| 28 | +SET @c := ( | |
| 29 | + SELECT COUNT(*) FROM information_schema.COLUMNS | |
| 30 | + WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'fl_label_alert_timer' AND COLUMN_NAME = 'DateTimeFormat' | |
| 31 | +); | |
| 32 | +SET @ddl := IF( | |
| 33 | + @c = 0, | |
| 34 | + 'ALTER TABLE `fl_label_alert_timer` ADD COLUMN `DateTimeFormat` varchar(100) NULL DEFAULT NULL COMMENT ''过期时刻展示格式'' AFTER `AlertTemplateName`', | |
| 35 | + 'SELECT 1' | |
| 36 | +); | |
| 37 | +PREPARE s FROM @ddl; EXECUTE s; DEALLOCATE PREPARE s; | |
| 38 | + | |
| 39 | +SET @c := ( | |
| 40 | + SELECT COUNT(*) FROM information_schema.COLUMNS | |
| 41 | + WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'fl_label_alert_timer' AND COLUMN_NAME = 'PrintedByUserId' | |
| 42 | +); | |
| 43 | +SET @ddl := IF( | |
| 44 | + @c = 0, | |
| 45 | + 'ALTER TABLE `fl_label_alert_timer` ADD COLUMN `PrintedByUserId` varchar(36) NULL DEFAULT NULL COMMENT ''打印人Id'' AFTER `DateTimeFormat`', | |
| 46 | + 'SELECT 1' | |
| 47 | +); | |
| 48 | +PREPARE s FROM @ddl; EXECUTE s; DEALLOCATE PREPARE s; | |
| 49 | + | |
| 50 | +SET @c := ( | |
| 51 | + SELECT COUNT(*) FROM information_schema.COLUMNS | |
| 52 | + WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'fl_label_alert_timer' AND COLUMN_NAME = 'PrintedByUserName' | |
| 53 | +); | |
| 54 | +SET @ddl := IF( | |
| 55 | + @c = 0, | |
| 56 | + 'ALTER TABLE `fl_label_alert_timer` ADD COLUMN `PrintedByUserName` varchar(200) NULL DEFAULT NULL COMMENT ''打印人姓名'' AFTER `PrintedByUserId`', | |
| 57 | + 'SELECT 1' | |
| 58 | +); | |
| 59 | +PREPARE s FROM @ddl; EXECUTE s; DEALLOCATE PREPARE s; | |
| 60 | + | |
| 61 | +SET @c := ( | |
| 62 | + SELECT COUNT(*) FROM information_schema.COLUMNS | |
| 63 | + WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'fl_label_alert_timer' AND COLUMN_NAME = 'LocationName' | |
| 64 | +); | |
| 65 | +SET @ddl := IF( | |
| 66 | + @c = 0, | |
| 67 | + 'ALTER TABLE `fl_label_alert_timer` ADD COLUMN `LocationName` varchar(200) NULL DEFAULT NULL COMMENT ''门店名冗余'' AFTER `LocationId`', | |
| 68 | + 'SELECT 1' | |
| 69 | +); | |
| 70 | +PREPARE s FROM @ddl; EXECUTE s; DEALLOCATE PREPARE s; | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/scripts/fl_menu_hide_platform_qr_codes.sql
0 → 100644
| 1 | +-- 企业端(租户业务库)去掉「二维码」菜单:软删 + 解除角色绑定 | |
| 2 | +-- 新租户初始化会自动执行;已有租户请手工执行 | |
| 3 | +-- 可重复执行。禁止在主库 Host 执行(主库二维码要保留在「平台管理」下) | |
| 4 | + | |
| 5 | +SET NAMES utf8mb4; | |
| 6 | + | |
| 7 | +UPDATE `menu` | |
| 8 | +SET `IsDeleted` = 1, | |
| 9 | + `LastModificationTime` = NOW() | |
| 10 | +WHERE (`IsDeleted` = 0 OR `IsDeleted` IS NULL) | |
| 11 | + AND ( | |
| 12 | + `Id` = 'f0010037-0001-4000-8000-000000000037' | |
| 13 | + OR `Router` IN ('/qr-codes', '/platform/qr-codes') | |
| 14 | + OR `PermissionCode` IN ('menu.management.qr-codes', 'menu.platform.qr-codes') | |
| 15 | + ); | |
| 16 | + | |
| 17 | +DELETE `rm` | |
| 18 | +FROM `rolemenu` `rm` | |
| 19 | +INNER JOIN `menu` `m` ON `m`.`Id` = `rm`.`MenuId` | |
| 20 | +WHERE `m`.`Id` = 'f0010037-0001-4000-8000-000000000037' | |
| 21 | + OR `m`.`Router` IN ('/qr-codes', '/platform/qr-codes') | |
| 22 | + OR `m`.`PermissionCode` IN ('menu.management.qr-codes', 'menu.platform.qr-codes'); | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/scripts/label-training-绑定标签接口文档.md
0 → 100644
| 1 | +# 泰鄂版 Label / Training 接口文档(绑定标签) | |
| 2 | + | |
| 3 | +适用范围:泰鄂版后端 `LabelAppService`、`TrainingAppService`。 | |
| 4 | +鉴权:请求头 `Authorization` 填登录返回的 `data.token`(已含 `Bearer ` 前缀)。 | |
| 5 | +租户:业务数据在**当前租户库**;`boundLabelIds` 落库 `fl_label_bound_label` / `fl_training_file_label`。 | |
| 6 | + | |
| 7 | +统一响应(Yi 包装): | |
| 8 | + | |
| 9 | +```json | |
| 10 | +{ | |
| 11 | + "code": 200, | |
| 12 | + "data": {}, | |
| 13 | + "message": "" | |
| 14 | +} | |
| 15 | +``` | |
| 16 | + | |
| 17 | +下文示例均为 `data` 内层。JSON 字段均为 camelCase。 | |
| 18 | + | |
| 19 | +--- | |
| 20 | + | |
| 21 | +## 公共约定:绑定标签 `boundLabelIds` | |
| 22 | + | |
| 23 | +| 项 | 说明 | | |
| 24 | +|---|---| | |
| 25 | +| 入参 | `string[]`,元素为标签 **LabelCode** 或内部 `fl_label.Id` | | |
| 26 | +| 出参 `boundLabelIds` | 统一为 **LabelCode**(与标签列表 `id` 相同) | | |
| 27 | +| 出参 `boundLabels` | 绑定标签名称,逗号拼接;无绑定时为 `N/A` | | |
| 28 | +| 新增未传 / 空数组 | 不绑定 | | |
| 29 | +| **编辑未传(null)** | **不改动**已有绑定(兼容旧前端) | | |
| 30 | +| 编辑传 `[]` | 清空绑定 | | |
| 31 | +| 非法 Id | 400,提示 `绑定标签不存在:xxx` | | |
| 32 | +| 标签绑自己 | 自动忽略 | | |
| 33 | + | |
| 34 | +--- | |
| 35 | + | |
| 36 | +## 一、标签 `/api/app/label` | |
| 37 | + | |
| 38 | +路由前缀:`/api/app/label`。路径参数 `id` = **LabelCode**(不是内部主键)。 | |
| 39 | + | |
| 40 | +### 1.1 分页列表 | |
| 41 | + | |
| 42 | +- **GET** `/api/app/label` | |
| 43 | +- Query(本项目分页:`SkipCount` 为页码,从 1 开始) | |
| 44 | + | |
| 45 | +| 参数 | 类型 | 必填 | 说明 | | |
| 46 | +|---|---|---|---| | |
| 47 | +| SkipCount | int | 否 | 页码,从 1 开始。例:`1` | | |
| 48 | +| MaxResultCount | int | 否 | 每页条数。例:`10` | | |
| 49 | +| Keyword | string | 否 | 关键字 | | |
| 50 | +| PartnerId | string | 否 | Company Id | | |
| 51 | +| GroupId | string | 否 | Region / `fl_group.Id` | | |
| 52 | +| LocationId | string | 否 | 门店 Id | | |
| 53 | +| ProductId | string | 否 | 按产品筛标签 | | |
| 54 | +| LabelCategoryId | string | 否 | 标签分类 | | |
| 55 | +| LabelTypeId | string | 否 | 标签类型 | | |
| 56 | +| TemplateCode | string | 否 | 模板编码 | | |
| 57 | +| State | bool | 否 | 启用状态 | | |
| 58 | + | |
| 59 | +示例:`GET /api/app/label?SkipCount=1&MaxResultCount=10` | |
| 60 | + | |
| 61 | +`data`: | |
| 62 | + | |
| 63 | +```json | |
| 64 | +{ | |
| 65 | + "pageIndex": 1, | |
| 66 | + "pageSize": 10, | |
| 67 | + "totalCount": 100, | |
| 68 | + "totalPages": 10, | |
| 69 | + "items": [ | |
| 70 | + { | |
| 71 | + "id": "LB_1001", | |
| 72 | + "labelName": "Chicken Salad", | |
| 73 | + "locationName": "Store A", | |
| 74 | + "locationIds": ["loc-1"], | |
| 75 | + "region": "Group A", | |
| 76 | + "regionIds": ["g-1"], | |
| 77 | + "groupIds": ["g-1"], | |
| 78 | + "appliedRegionType": "SPECIFIED", | |
| 79 | + "labelCategoryName": "Prepared", | |
| 80 | + "productCategoryName": "Salad", | |
| 81 | + "products": "Chicken Salad", | |
| 82 | + "boundLabelIds": ["LB_2002"], | |
| 83 | + "boundLabels": "Allergen Warning", | |
| 84 | + "templateName": "Nutrition 3x6", | |
| 85 | + "templateCode": "TPL_NUTRITION_3X6", | |
| 86 | + "labelTypeName": "Prep", | |
| 87 | + "state": true, | |
| 88 | + "lastEdited": "2026-10-12T10:00:00", | |
| 89 | + "hasError": false | |
| 90 | + } | |
| 91 | + ] | |
| 92 | +} | |
| 93 | +``` | |
| 94 | + | |
| 95 | +### 1.2 详情 | |
| 96 | + | |
| 97 | +- **GET** `/api/app/label/{id}` | |
| 98 | +- `id`:LabelCode | |
| 99 | + | |
| 100 | +`data` 主要字段: | |
| 101 | + | |
| 102 | +| 字段 | 类型 | 说明 | | |
| 103 | +|---|---|---| | |
| 104 | +| id | string | LabelCode | | |
| 105 | +| labelName | string | 名称 | | |
| 106 | +| locationId / locationIds / location / locationName | | 门店 | | |
| 107 | +| partnerId / partnerIds / companyIds | | Company | | |
| 108 | +| appliedRegionType | string | `ALL` / `SPECIFIED` | | |
| 109 | +| region / regionIds / groupIds | | Region | | |
| 110 | +| labelCategoryId / labelCategoryName | | 分类 | | |
| 111 | +| labelTypeId / labelTypeName | | 类型 | | |
| 112 | +| templateCode / templateName | | 模板 | | |
| 113 | +| state | bool | 启用 | | |
| 114 | +| labelInfoJson | object | 模板数据 | | |
| 115 | +| productIds | string[] | 绑定产品 Id | | |
| 116 | +| boundLabelIds | string[] | 绑定标签 LabelCode | | |
| 117 | +| boundLabels | string | 绑定标签名称 | | |
| 118 | + | |
| 119 | +### 1.3 新增 | |
| 120 | + | |
| 121 | +- **POST** `/api/app/label` | |
| 122 | +- Header:`Content-Type: application/json` | |
| 123 | + | |
| 124 | +| 字段 | 类型 | 必填 | 说明 | | |
| 125 | +|---|---|---|---| | |
| 126 | +| labelName | string | 是 | 名称 | | |
| 127 | +| templateCode | string | 是 | 模板编码 | | |
| 128 | +| labelCategoryId | string | 是 | 分类 Id | | |
| 129 | +| productIds | string[] | 是 | 至少 1 个产品 | | |
| 130 | +| labelCode | string | 否 | 不传则后端生成 | | |
| 131 | +| partnerId / partnerIds / companyIds | | 否 | Company,单选 | | |
| 132 | +| appliedRegionType | string | 否 | `ALL` / `SPECIFIED` | | |
| 133 | +| regionIds / groupIds | string[] | 否 | Region,可含 `"ALL"` | | |
| 134 | +| locationIds / locationId | | 否 | 门店,可含 `"ALL"` | | |
| 135 | +| labelTypeId | string | 否 | 类型 | | |
| 136 | +| boundLabelIds | string[] | 否 | 绑定其他标签 | | |
| 137 | +| labelInfoJson | object | 否 | 模板数据 | | |
| 138 | +| state | bool | 否 | 默认 true | | |
| 139 | + | |
| 140 | +请求示例: | |
| 141 | + | |
| 142 | +```json | |
| 143 | +{ | |
| 144 | + "labelName": "Chicken Salad", | |
| 145 | + "templateCode": "TPL_NUTRITION_3X6", | |
| 146 | + "labelCategoryId": "cat-id", | |
| 147 | + "productIds": ["product-id"], | |
| 148 | + "appliedRegionType": "SPECIFIED", | |
| 149 | + "regionIds": ["group-id"], | |
| 150 | + "locationIds": ["location-id"], | |
| 151 | + "boundLabelIds": ["LB_2002"], | |
| 152 | + "state": true | |
| 153 | +} | |
| 154 | +``` | |
| 155 | + | |
| 156 | +成功返回同 **1.2 详情**。 | |
| 157 | + | |
| 158 | +### 1.4 编辑 | |
| 159 | + | |
| 160 | +- **PUT** `/api/app/label/{id}` | |
| 161 | +- `id`:LabelCode | |
| 162 | +- Body 与新增基本相同(无 `labelCode`) | |
| 163 | +- `boundLabelIds`:**省略则不改绑定**;`[]` 清空;有值则全量覆盖 | |
| 164 | + | |
| 165 | +```json | |
| 166 | +{ | |
| 167 | + "labelName": "Chicken Salad", | |
| 168 | + "templateCode": "TPL_NUTRITION_3X6", | |
| 169 | + "labelCategoryId": "cat-id", | |
| 170 | + "productIds": ["product-id"], | |
| 171 | + "boundLabelIds": ["LB_2002", "LB_2003"], | |
| 172 | + "state": true | |
| 173 | +} | |
| 174 | +``` | |
| 175 | + | |
| 176 | +成功返回同 **1.2 详情**。 | |
| 177 | + | |
| 178 | +--- | |
| 179 | + | |
| 180 | +## 二、培训 `/api/app/training` | |
| 181 | + | |
| 182 | +查询树:`GET /api/app/training/category-tree`(管理端实际调用此路径,不是裸 `/api/app/training`)。 | |
| 183 | + | |
| 184 | +### 2.1 分类树(含文件) | |
| 185 | + | |
| 186 | +- **GET** `/api/app/training/category-tree` | |
| 187 | + | |
| 188 | +| 参数 | 类型 | 必填 | 说明 | | |
| 189 | +|---|---|---|---| | |
| 190 | +| keyword | string | 否 | 匹配分类名或文件名 | | |
| 191 | +| locationId | string | 否 | 按门店过滤可见文件 | | |
| 192 | +| includeFiles | bool | 否 | 是否带文件,默认 true | | |
| 193 | + | |
| 194 | +`data`:一级分类数组,`children` 为二级;文件只挂在二级 `files`。 | |
| 195 | + | |
| 196 | +```json | |
| 197 | +[ | |
| 198 | + { | |
| 199 | + "id": "cat-l1", | |
| 200 | + "categoryName": "Safety", | |
| 201 | + "parentId": null, | |
| 202 | + "orderNum": 100, | |
| 203 | + "children": [ | |
| 204 | + { | |
| 205 | + "id": "cat-l2", | |
| 206 | + "categoryName": "Prep", | |
| 207 | + "parentId": "cat-l1", | |
| 208 | + "orderNum": 90, | |
| 209 | + "children": [], | |
| 210 | + "files": [ | |
| 211 | + { | |
| 212 | + "id": "file-id", | |
| 213 | + "categoryId": "cat-l2", | |
| 214 | + "fileName": "手册.pdf", | |
| 215 | + "fileUrl": "/training/....pdf", | |
| 216 | + "fileType": "doc", | |
| 217 | + "fileSize": 1024, | |
| 218 | + "orderNum": 100, | |
| 219 | + "appliedPartnerType": "ALL", | |
| 220 | + "company": "All Companies", | |
| 221 | + "partnerIds": [], | |
| 222 | + "companyIds": [], | |
| 223 | + "appliedRegionType": "ALL", | |
| 224 | + "region": "", | |
| 225 | + "regionIds": [], | |
| 226 | + "groupIds": [], | |
| 227 | + "availabilityType": "ALL", | |
| 228 | + "location": "", | |
| 229 | + "locationIds": [], | |
| 230 | + "boundLabelIds": ["LB_1001"], | |
| 231 | + "boundLabels": "Chicken Salad", | |
| 232 | + "creationTime": "2026-10-12T10:00:00", | |
| 233 | + "lastModificationTime": "2026-10-12T10:00:00" | |
| 234 | + } | |
| 235 | + ] | |
| 236 | + } | |
| 237 | + ], | |
| 238 | + "files": [] | |
| 239 | + } | |
| 240 | +] | |
| 241 | +``` | |
| 242 | + | |
| 243 | +### 2.2 上传文件(新增) | |
| 244 | + | |
| 245 | +- **POST** `/api/app/training/file/upload` | |
| 246 | +- `multipart/form-data`,单文件最大 20MB | |
| 247 | + | |
| 248 | +| 字段 | 类型 | 必填 | 说明 | | |
| 249 | +|---|---|---|---| | |
| 250 | +| file | file | 是 | 文件 | | |
| 251 | +| categoryId | string | 是 | **二级**分类 Id | | |
| 252 | +| orderNum | int | 否 | 排序 | | |
| 253 | +| appliedPartnerType | string | 否 | Company:`ALL` / `SPECIFIED` | | |
| 254 | +| partnerIds / companyIds | string | 否 | 可重复;可含 `ALL` | | |
| 255 | +| appliedRegionType | string | 否 | Region:`ALL` / `SPECIFIED` | | |
| 256 | +| regionIds / groupIds | string | 否 | 可重复;可含 `ALL` | | |
| 257 | +| availabilityType / appliedLocationType | string | 否 | Location:`ALL` / `SPECIFIED` | | |
| 258 | +| locationIds | string | 否 | 可重复;可含 `ALL` | | |
| 259 | +| boundLabelIds | string | 否 | 可重复,LabelCode 或 Id | | |
| 260 | + | |
| 261 | +curl 示例: | |
| 262 | + | |
| 263 | +```bash | |
| 264 | +curl -X POST "https://{host}/api/app/training/file/upload" \ | |
| 265 | + -H "Authorization: {token}" \ | |
| 266 | + -F "file=@手册.pdf" \ | |
| 267 | + -F "categoryId=cat-l2" \ | |
| 268 | + -F "orderNum=100" \ | |
| 269 | + -F "boundLabelIds=LB_1001" \ | |
| 270 | + -F "boundLabelIds=LB_1002" | |
| 271 | +``` | |
| 272 | + | |
| 273 | +成功返回 `TrainingFileDto`(结构同树节点 `files[]`)。 | |
| 274 | + | |
| 275 | +### 2.3 编辑文件 | |
| 276 | + | |
| 277 | +- **PUT** `/api/app/training/{id}/file` | |
| 278 | +- `id`:文件 Id | |
| 279 | +- `Content-Type: application/json` | |
| 280 | + | |
| 281 | +| 字段 | 类型 | 必填 | 说明 | | |
| 282 | +|---|---|---|---| | |
| 283 | +| fileName | string | 是 | 展示文件名 | | |
| 284 | +| orderNum | int | 否 | 排序 | | |
| 285 | +| appliedPartnerType / partnerIds / companyIds | | 否 | 有传才改 Company 范围 | | |
| 286 | +| appliedRegionType / regionIds / groupIds | | 否 | 有传才改 Region | | |
| 287 | +| availabilityType / appliedLocationType / locationIds | | 否 | 有传才改 Location | | |
| 288 | +| boundLabelIds | string[] | 否 | 省略不改;`[]` 清空 | | |
| 289 | + | |
| 290 | +```json | |
| 291 | +{ | |
| 292 | + "fileName": "操作手册.pdf", | |
| 293 | + "orderNum": 100, | |
| 294 | + "appliedPartnerType": "SPECIFIED", | |
| 295 | + "partnerIds": ["p1"], | |
| 296 | + "appliedRegionType": "ALL", | |
| 297 | + "availabilityType": "SPECIFIED", | |
| 298 | + "locationIds": ["loc1"], | |
| 299 | + "boundLabelIds": ["LB_1001"] | |
| 300 | +} | |
| 301 | +``` | |
| 302 | + | |
| 303 | +成功返回 `TrainingFileDto`。 | |
| 304 | + | |
| 305 | +--- | |
| 306 | + | |
| 307 | +## 三、相关表(租户库) | |
| 308 | + | |
| 309 | +| 表 | 含义 | | |
| 310 | +|---|---| | |
| 311 | +| `fl_label_bound_label` | 标签绑定其他标签:`LabelId` → `BoundLabelId` | | |
| 312 | +| `fl_training_file_label` | 培训文件绑定标签:`TrainingFileId` → `LabelId` | | |
| 313 | + | |
| 314 | +脚本:同目录 `fl_bound_label.sql`。 | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/scripts/seed_host_platform_menus.sql
| 1 | 1 | -- 泰额版平台级菜单:清空 antis-foodlabeling-host.menu 后按前端路由表重录 |
| 2 | 2 | -- 使用稳定 Id(f001*),保证 rolemenu 等引用不失效 |
| 3 | 3 | -- MenuSource=0(Ruoyi),平台目录 MenuType=0,页面 MenuType=1 |
| 4 | +-- 仅在【主库 Host】执行,禁止在租户业务库执行(会清空租户 menu) | |
| 4 | 5 | |
| 5 | 6 | SET NAMES utf8mb4; |
| 6 | 7 | START TRANSACTION; |
| ... | ... | @@ -24,6 +25,9 @@ INSERT INTO menu ( |
| 24 | 25 | ('f0010003-0001-4000-8000-000000000003', 0, NOW(), NULL, NULL, NULL, |
| 25 | 26 | 6, 1, 'SAAS 公司', 'FoodLabelingPlatformTenants', 1, 'menu.platform.tenants', 'f0010002-0001-4000-8000-000000000002', |
| 26 | 27 | 'lucide:building', '/platform/tenants', 0, 0, 1, NULL, '/food-labeling/platform/tenants/index', 0, NULL, ''), |
| 28 | +('f0010037-0001-4000-8000-000000000037', 0, NOW(), NULL, NULL, NULL, | |
| 29 | + 7, 1, '二维码', 'FoodLabelingQrCodes', 1, 'menu.platform.qr-codes', 'f0010002-0001-4000-8000-000000000002', | |
| 30 | + 'lucide:qr-code', '/platform/qr-codes', 0, 0, 1, NULL, '/food-labeling/modules/qr-codes/index', 0, NULL, ''), | |
| 27 | 31 | |
| 28 | 32 | -- 标签管理 |
| 29 | 33 | ('f0010010-0001-4000-8000-000000000010', 0, NOW(), NULL, NULL, NULL, |
| ... | ... | @@ -45,59 +49,53 @@ INSERT INTO menu ( |
| 45 | 49 | 15, 1, '多选选项集', 'FoodLabelingMultipleOptions', 1, 'menu.labeling.multiple-options', 'f0010010-0001-4000-8000-000000000010', |
| 46 | 50 | 'lucide:list-checks', '/multiple-options', 0, 0, 1, NULL, '/food-labeling/labeling/multiple-options/index', 0, NULL, ''), |
| 47 | 51 | |
| 48 | --- 业务模块 | |
| 49 | -('f0010020-0001-4000-8000-000000000020', 0, NOW(), NULL, NULL, NULL, | |
| 50 | - 15, 1, '业务模块', 'FoodLabelingModules', 0, 'menu.modules', '0', | |
| 51 | - 'lucide:boxes', '/modules', 0, 0, 1, NULL, NULL, 0, NULL, ''), | |
| 52 | +-- 原「业务模块」子项:提升为一级菜单(ParentId=0),不再保留「业务模块」目录 | |
| 52 | 53 | ('f0010021-0001-4000-8000-000000000021', 0, NOW(), NULL, NULL, NULL, |
| 53 | - 16, 1, '培训', 'FoodLabelingTraining', 1, 'menu.modules.training', 'f0010020-0001-4000-8000-000000000020', | |
| 54 | + 15, 1, '培训', 'FoodLabelingTraining', 1, 'menu.modules.training', '0', | |
| 54 | 55 | 'lucide:graduation-cap', '/training', 0, 0, 1, NULL, '/food-labeling/modules/training/index', 0, NULL, ''), |
| 55 | 56 | ('f0010022-0001-4000-8000-000000000022', 0, NOW(), NULL, NULL, NULL, |
| 56 | - 17, 1, '告警', 'FoodLabelingAlerts', 1, 'menu.modules.alerts', 'f0010020-0001-4000-8000-000000000020', | |
| 57 | + 16, 1, '告警', 'FoodLabelingAlerts', 1, 'menu.modules.alerts', '0', | |
| 57 | 58 | 'lucide:bell', '/alerts', 0, 0, 1, NULL, '/food-labeling/modules/alerts/index', 0, NULL, ''), |
| 58 | 59 | ('f0010023-0001-4000-8000-000000000023', 0, NOW(), NULL, NULL, NULL, |
| 59 | - 18, 1, '任务', 'FoodLabelingTasks', 1, 'menu.modules.tasks', 'f0010020-0001-4000-8000-000000000020', | |
| 60 | + 17, 1, '任务', 'FoodLabelingTasks', 1, 'menu.modules.tasks', '0', | |
| 60 | 61 | 'lucide:list-todo', '/tasks', 0, 0, 1, NULL, '/food-labeling/modules/tasks/index', 0, NULL, ''), |
| 61 | 62 | ('f0010024-0001-4000-8000-000000000024', 0, NOW(), NULL, NULL, NULL, |
| 62 | - 19, 1, '传感器', 'FoodLabelingSensors', 1, 'menu.modules.sensors', 'f0010020-0001-4000-8000-000000000020', | |
| 63 | + 18, 1, '传感器', 'FoodLabelingSensors', 1, 'menu.modules.sensors', '0', | |
| 63 | 64 | 'lucide:activity', '/sensors', 0, 0, 1, NULL, '/food-labeling/modules/sensors/index', 0, NULL, ''), |
| 64 | 65 | ('f0010025-0001-4000-8000-000000000025', 0, NOW(), NULL, NULL, NULL, |
| 65 | - 20, 1, '食物浪费', 'FoodLabelingFoodWaste', 1, 'menu.modules.food-waste', 'f0010020-0001-4000-8000-000000000020', | |
| 66 | + 19, 1, '食物浪费', 'FoodLabelingFoodWaste', 1, 'menu.modules.food-waste', '0', | |
| 66 | 67 | 'lucide:apple', '/food-waste', 0, 0, 1, NULL, '/food-labeling/modules/food-waste/index', 0, NULL, ''), |
| 67 | 68 | ('f0010026-0001-4000-8000-000000000026', 0, NOW(), NULL, NULL, NULL, |
| 68 | - 21, 1, '电子标签', 'FoodLabelingELabelModule', 1, 'menu.modules.e-label', 'f0010020-0001-4000-8000-000000000020', | |
| 69 | + 20, 1, '电子标签', 'FoodLabelingELabelModule', 1, 'menu.modules.e-label', '0', | |
| 69 | 70 | 'lucide:file-digit', '/e-label-module', 0, 0, 1, NULL, '/food-labeling/modules/e-label/index', 0, NULL, ''), |
| 70 | 71 | |
| 71 | 72 | -- 管理 |
| 72 | 73 | ('f0010030-0001-4000-8000-000000000030', 0, NOW(), NULL, NULL, NULL, |
| 73 | - 20, 1, '管理', 'FoodLabelingManagement', 0, 'menu.management', '0', | |
| 74 | + 30, 1, '管理', 'FoodLabelingManagement', 0, 'menu.management', '0', | |
| 74 | 75 | 'lucide:building-2', '/management', 0, 0, 1, NULL, NULL, 0, NULL, ''), |
| 75 | 76 | ('f0010031-0001-4000-8000-000000000031', 0, NOW(), NULL, NULL, NULL, |
| 76 | - 21, 1, '账户管理', 'FoodLabelingAccountManagement', 1, 'menu.management.account', 'f0010030-0001-4000-8000-000000000030', | |
| 77 | + 31, 1, '账户管理', 'FoodLabelingAccountManagement', 1, 'menu.management.account', 'f0010030-0001-4000-8000-000000000030', | |
| 77 | 78 | 'lucide:users', '/account-management', 0, 0, 1, NULL, '/food-labeling/management/account-management/index', 0, NULL, ''), |
| 78 | 79 | ('f0010032-0001-4000-8000-000000000032', 0, NOW(), NULL, NULL, NULL, |
| 79 | - 22, 1, '系统菜单', 'FoodLabelingSystemMenu', 1, 'menu.management.system-menu', 'f0010030-0001-4000-8000-000000000030', | |
| 80 | + 32, 1, '系统菜单', 'FoodLabelingSystemMenu', 1, 'menu.management.system-menu', 'f0010030-0001-4000-8000-000000000030', | |
| 80 | 81 | 'lucide:menu-square', '/system-menu', 0, 0, 1, NULL, '/food-labeling/management/system-menu/index', 0, NULL, ''), |
| 81 | 82 | ('f0010033-0001-4000-8000-000000000033', 0, NOW(), NULL, NULL, NULL, |
| 82 | - 23, 1, '菜单管理', 'FoodLabelingMenuManagement', 1, 'menu.management.menu', 'f0010030-0001-4000-8000-000000000030', | |
| 83 | + 33, 1, '菜单管理', 'FoodLabelingMenuManagement', 1, 'menu.management.menu', 'f0010030-0001-4000-8000-000000000030', | |
| 83 | 84 | 'lucide:utensils', '/menu-management', 0, 0, 1, NULL, '/food-labeling/management/menu-management/index', 0, NULL, ''), |
| 84 | 85 | ('f0010034-0001-4000-8000-000000000034', 0, NOW(), NULL, NULL, NULL, |
| 85 | - 24, 1, '设备', 'FoodLabelingDevices', 1, 'menu.management.devices', 'f0010030-0001-4000-8000-000000000030', | |
| 86 | + 34, 1, '设备', 'FoodLabelingDevices', 1, 'menu.management.devices', 'f0010030-0001-4000-8000-000000000030', | |
| 86 | 87 | 'lucide:smartphone', '/devices', 0, 0, 1, NULL, '/food-labeling/modules/devices/index', 0, NULL, ''), |
| 87 | 88 | ('f0010035-0001-4000-8000-000000000035', 0, NOW(), NULL, NULL, NULL, |
| 88 | - 25, 1, '报表', 'FoodLabelingReports', 1, 'menu.management.reports', 'f0010030-0001-4000-8000-000000000030', | |
| 89 | + 35, 1, '报表', 'FoodLabelingReports', 1, 'menu.management.reports', 'f0010030-0001-4000-8000-000000000030', | |
| 89 | 90 | 'lucide:file-bar-chart', '/reports', 0, 0, 1, NULL, '/food-labeling/management/reports/index', 0, NULL, ''), |
| 90 | 91 | ('f0010036-0001-4000-8000-000000000036', 0, NOW(), NULL, NULL, NULL, |
| 91 | - 26, 1, '发票', 'FoodLabelingInvoices', 1, 'menu.management.invoices', 'f0010030-0001-4000-8000-000000000030', | |
| 92 | + 36, 1, '发票', 'FoodLabelingInvoices', 1, 'menu.management.invoices', 'f0010030-0001-4000-8000-000000000030', | |
| 92 | 93 | 'lucide:receipt', '/invoices', 0, 0, 1, NULL, '/food-labeling/modules/invoices/index', 0, NULL, ''), |
| 93 | -('f0010037-0001-4000-8000-000000000037', 0, NOW(), NULL, NULL, NULL, | |
| 94 | - 27, 1, '二维码', 'FoodLabelingQrCodes', 1, 'menu.management.qr-codes', 'f0010030-0001-4000-8000-000000000030', | |
| 95 | - 'lucide:qr-code', '/qr-codes', 0, 0, 1, NULL, '/food-labeling/modules/qr-codes/index', 0, NULL, ''), | |
| 96 | 94 | ('f0010038-0001-4000-8000-000000000038', 0, NOW(), NULL, NULL, NULL, |
| 97 | - 28, 1, '支持', 'FoodLabelingSupport', 1, 'menu.management.support', 'f0010030-0001-4000-8000-000000000030', | |
| 95 | + 37, 1, '支持', 'FoodLabelingSupport', 1, 'menu.management.support', 'f0010030-0001-4000-8000-000000000030', | |
| 98 | 96 | 'lucide:life-buoy', '/support', 0, 0, 1, NULL, '/food-labeling/management/support/index', 0, NULL, ''), |
| 99 | 97 | ('f0010039-0001-4000-8000-000000000039', 0, NOW(), NULL, NULL, NULL, |
| 100 | - 29, 1, 'API', 'FoodLabelingApi', 1, 'menu.management.api', 'f0010030-0001-4000-8000-000000000030', | |
| 98 | + 38, 1, 'API', 'FoodLabelingApi', 1, 'menu.management.api', 'f0010030-0001-4000-8000-000000000030', | |
| 101 | 99 | 'lucide:code-2', '/api-settings', 0, 0, 1, NULL, '/food-labeling/modules/api/index', 0, NULL, ''); |
| 102 | 100 | |
| 103 | 101 | COMMIT; | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling/FoodLabeling.Th.Application.Contracts/Dtos/RbacMenu/ThRbacMenuGetListInputVo.cs
| ... | ... | @@ -14,6 +14,11 @@ public class ThRbacMenuGetListInputVo : PagedAndSortedResultRequestDto |
| 14 | 14 | public string? MenuName { get; set; } |
| 15 | 15 | |
| 16 | 16 | /// <summary> |
| 17 | + /// 关键字(与 <see cref="MenuName"/> 相同,兼容前端 Keyword) | |
| 18 | + /// </summary> | |
| 19 | + public string? Keyword { get; set; } | |
| 20 | + | |
| 21 | + /// <summary> | |
| 17 | 22 | /// 启用状态 |
| 18 | 23 | /// </summary> |
| 19 | 24 | public bool? State { get; set; } | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling/FoodLabeling.Th.Application.Contracts/Dtos/RbacMenu/ThRbacMenuGetListOutputDto.cs
| ... | ... | @@ -17,6 +17,25 @@ public class ThRbacMenuGetListOutputDto |
| 17 | 17 | |
| 18 | 18 | public string? Router { get; set; } |
| 19 | 19 | |
| 20 | + /// <summary>与 <see cref="Router"/> 相同,兼容前端 routeUrl</summary> | |
| 21 | + public string? RouteUrl { get; set; } | |
| 22 | + | |
| 23 | + public string? MenuIcon { get; set; } | |
| 24 | + | |
| 25 | + public bool IsLink { get; set; } | |
| 26 | + | |
| 27 | + public bool IsCache { get; set; } | |
| 28 | + | |
| 29 | + public bool IsShow { get; set; } | |
| 30 | + | |
| 31 | + public string? Remark { get; set; } | |
| 32 | + | |
| 33 | + public string? Component { get; set; } | |
| 34 | + | |
| 35 | + public string? Query { get; set; } | |
| 36 | + | |
| 37 | + public string? ConcurrencyStamp { get; set; } | |
| 38 | + | |
| 20 | 39 | public string? PermissionCode { get; set; } |
| 21 | 40 | |
| 22 | 41 | public MenuTypeEnum MenuType { get; set; } | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling/FoodLabeling.Th.Application/Filters/FoodLabelingBusinessTenantActionFilter.cs
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling/FoodLabeling.Th.Application/MultiTenancy/TenantCompanyMenuSyncService.cs
| ... | ... | @@ -87,6 +87,7 @@ public class TenantCompanyMenuSyncService : ITenantCompanyMenuSyncService, ITran |
| 87 | 87 | var hostMenus = await ThTenantHostDataAccessor.LoadHostMenusAsync(_dbConnOptions); |
| 88 | 88 | var menusToUpsert = CollectMenusWithAncestors(hostMenus, menuIds); |
| 89 | 89 | await UpsertTenantMenusAsync(tenantDb, menusToUpsert, cancellationToken); |
| 90 | + await HidePlatformQrMenusAsync(tenantDb, cancellationToken); | |
| 90 | 91 | await ReplaceAdminRoleMenusAsync(tenantDb, adminRole.Id, menusToUpsert.Select(m => m.Id).ToList(), cancellationToken); |
| 91 | 92 | |
| 92 | 93 | _logger.LogInformation( |
| ... | ... | @@ -127,6 +128,11 @@ public class TenantCompanyMenuSyncService : ITenantCompanyMenuSyncService, ITran |
| 127 | 128 | var currentId = menuId; |
| 128 | 129 | while (currentId != Guid.Empty && byId.TryGetValue(currentId, out var menu)) |
| 129 | 130 | { |
| 131 | + if (ThSaasMenuPermissionCatalog.IsPlatformOnlyMenu(menu)) | |
| 132 | + { | |
| 133 | + break; | |
| 134 | + } | |
| 135 | + | |
| 130 | 136 | if (!collected.Add(currentId)) |
| 131 | 137 | { |
| 132 | 138 | break; |
| ... | ... | @@ -161,6 +167,36 @@ public class TenantCompanyMenuSyncService : ITenantCompanyMenuSyncService, ITran |
| 161 | 167 | return adminRoles.FirstOrDefault(); |
| 162 | 168 | } |
| 163 | 169 | |
| 170 | + private static async Task HidePlatformQrMenusAsync( | |
| 171 | + ISqlSugarClient tenantDb, | |
| 172 | + CancellationToken cancellationToken) | |
| 173 | + { | |
| 174 | + var qrMenuId = Guid.Parse("f0010037-0001-4000-8000-000000000037"); | |
| 175 | + var qrIds = await tenantDb.Queryable<MenuAggregateRoot>() | |
| 176 | + .Where(m => !m.IsDeleted) | |
| 177 | + .Where(m => m.Id == qrMenuId | |
| 178 | + || m.Router == "/qr-codes" | |
| 179 | + || m.Router == "/platform/qr-codes" | |
| 180 | + || m.PermissionCode == "menu.management.qr-codes" | |
| 181 | + || m.PermissionCode == "menu.platform.qr-codes") | |
| 182 | + .Select(m => m.Id) | |
| 183 | + .ToListAsync(cancellationToken); | |
| 184 | + if (qrIds.Count == 0) | |
| 185 | + { | |
| 186 | + return; | |
| 187 | + } | |
| 188 | + | |
| 189 | + await tenantDb.Updateable<MenuAggregateRoot>() | |
| 190 | + .SetColumns(m => m.IsDeleted == true) | |
| 191 | + .SetColumns(m => m.LastModificationTime == DateTime.Now) | |
| 192 | + .Where(m => qrIds.Contains(m.Id)) | |
| 193 | + .ExecuteCommandAsync(cancellationToken); | |
| 194 | + | |
| 195 | + await tenantDb.Deleteable<RoleMenuEntity>() | |
| 196 | + .Where(x => qrIds.Contains(x.MenuId)) | |
| 197 | + .ExecuteCommandAsync(cancellationToken); | |
| 198 | + } | |
| 199 | + | |
| 164 | 200 | private static async Task UpsertTenantMenusAsync( |
| 165 | 201 | ISqlSugarClient tenantDb, |
| 166 | 202 | IReadOnlyList<MenuAggregateRoot> hostMenus, | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling/FoodLabeling.Th.Application/MultiTenancy/ThSaasMenuPermissionCatalog.cs
| ... | ... | @@ -37,6 +37,7 @@ public static class ThSaasMenuPermissionCatalog |
| 37 | 37 | ["management:reports"] = "f0010035-0001-4000-8000-000000000035", |
| 38 | 38 | ["management:invoices"] = "f0010036-0001-4000-8000-000000000036", |
| 39 | 39 | ["management:qr-codes"] = "f0010037-0001-4000-8000-000000000037", |
| 40 | + ["platform:qr-codes"] = "f0010037-0001-4000-8000-000000000037", | |
| 40 | 41 | ["management:support"] = "f0010038-0001-4000-8000-000000000038", |
| 41 | 42 | ["management:api"] = "f0010039-0001-4000-8000-000000000039", |
| 42 | 43 | }; |
| ... | ... | @@ -51,6 +52,11 @@ public static class ThSaasMenuPermissionCatalog |
| 51 | 52 | return true; |
| 52 | 53 | } |
| 53 | 54 | |
| 55 | + if (IsQrCodeMenu(menu.Id.ToString(), menu.PermissionCode, menu.Router)) | |
| 56 | + { | |
| 57 | + return true; | |
| 58 | + } | |
| 59 | + | |
| 54 | 60 | var code = menu.PermissionCode?.Trim() ?? string.Empty; |
| 55 | 61 | if (code.StartsWith("menu.platform", StringComparison.OrdinalIgnoreCase)) |
| 56 | 62 | { |
| ... | ... | @@ -61,6 +67,26 @@ public static class ThSaasMenuPermissionCatalog |
| 61 | 67 | return router.StartsWith("/platform", StringComparison.OrdinalIgnoreCase); |
| 62 | 68 | } |
| 63 | 69 | |
| 70 | + /// <summary>二维码已改为仅平台;含历史 management 权限码 / 旧路由。</summary> | |
| 71 | + public static bool IsQrCodeMenu(string? menuId, string? permissionCode, string? router) | |
| 72 | + { | |
| 73 | + if (string.Equals(menuId?.Trim(), "f0010037-0001-4000-8000-000000000037", StringComparison.OrdinalIgnoreCase)) | |
| 74 | + { | |
| 75 | + return true; | |
| 76 | + } | |
| 77 | + | |
| 78 | + var code = permissionCode?.Trim() ?? string.Empty; | |
| 79 | + if (code.Equals("menu.management.qr-codes", StringComparison.OrdinalIgnoreCase) | |
| 80 | + || code.Equals("menu.platform.qr-codes", StringComparison.OrdinalIgnoreCase)) | |
| 81 | + { | |
| 82 | + return true; | |
| 83 | + } | |
| 84 | + | |
| 85 | + var path = router?.Trim() ?? string.Empty; | |
| 86 | + return path.Equals("/qr-codes", StringComparison.OrdinalIgnoreCase) | |
| 87 | + || path.Equals("/platform/qr-codes", StringComparison.OrdinalIgnoreCase); | |
| 88 | + } | |
| 89 | + | |
| 64 | 90 | /// <summary> |
| 65 | 91 | /// 将历史 SaaS Key / PermissionCode / 菜单 Id 统一为菜单 Id 字符串 |
| 66 | 92 | /// </summary> | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling/FoodLabeling.Th.Application/Services/ThRbacMenuAppService.cs
| ... | ... | @@ -55,9 +55,9 @@ public class ThRbacMenuAppService : ApplicationService, IThRbacMenuAppService |
| 55 | 55 | /// ``` |
| 56 | 56 | /// |
| 57 | 57 | /// 参数说明: |
| 58 | - /// - skipCount: 跳过条数 | |
| 58 | + /// - skipCount: ABP offset,公式 (currentPage-1)*maxResultCount;第 5 页每页 10 条应传 40,不是页码 40 | |
| 59 | 59 | /// - maxResultCount: 每页条数 |
| 60 | - /// - menuName: 菜单名称模糊匹配 | |
| 60 | + /// - menuName / keyword: 菜单名称模糊匹配 | |
| 61 | 61 | /// - state: 启用状态 |
| 62 | 62 | /// - menuSource: 菜单来源(MenuSourceEnum) |
| 63 | 63 | /// - menuType: 菜单类型(MenuTypeEnum) |
| ... | ... | @@ -71,10 +71,12 @@ public class ThRbacMenuAppService : ApplicationService, IThRbacMenuAppService |
| 71 | 71 | public virtual async Task<PagedResultDto<ThRbacMenuGetListOutputDto>> GetListAsync([FromQuery] ThRbacMenuGetListInputVo input) |
| 72 | 72 | { |
| 73 | 73 | RefAsync<int> total = 0; |
| 74 | + var pageSize = input.MaxResultCount <= 0 ? 10 : input.MaxResultCount; | |
| 75 | + var pageIndex = PagedQueryConvention.PageIndexFromOffset(input.SkipCount, pageSize); | |
| 74 | 76 | var query = BuildFilteredQuery(input) |
| 75 | 77 | .OrderBy(x => x.OrderNum, OrderByType.Desc); |
| 76 | 78 | |
| 77 | - var entities = await query.ToPageListAsync(input.SkipCount, input.MaxResultCount, total); | |
| 79 | + var entities = await query.ToPageListAsync(pageIndex, pageSize, total); | |
| 78 | 80 | var items = entities.Select(MapToListDto).ToList(); |
| 79 | 81 | return new PagedResultDto<ThRbacMenuGetListOutputDto>(total, items); |
| 80 | 82 | } |
| ... | ... | @@ -397,9 +399,10 @@ public class ThRbacMenuAppService : ApplicationService, IThRbacMenuAppService |
| 397 | 399 | |
| 398 | 400 | private ISugarQueryable<MenuDbEntity> BuildFilteredQuery(ThRbacMenuGetListInputVo input) |
| 399 | 401 | { |
| 402 | + var name = !string.IsNullOrWhiteSpace(input.MenuName) ? input.MenuName!.Trim() : input.Keyword?.Trim(); | |
| 400 | 403 | return _dbContext.SqlSugarClient.Queryable<MenuDbEntity>() |
| 401 | 404 | .Where(x => x.IsDeleted == false) |
| 402 | - .WhereIF(!string.IsNullOrWhiteSpace(input.MenuName), x => x.MenuName.Contains(input.MenuName!.Trim())) | |
| 405 | + .WhereIF(!string.IsNullOrWhiteSpace(name), x => x.MenuName.Contains(name!)) | |
| 403 | 406 | .WhereIF(input.State is not null, x => x.State == input.State) |
| 404 | 407 | .WhereIF(input.MenuSource is not null, x => x.MenuSource == (int)input.MenuSource!.Value) |
| 405 | 408 | .WhereIF(input.MenuType is not null, x => x.MenuType == (int)input.MenuType!.Value); |
| ... | ... | @@ -465,6 +468,15 @@ public class ThRbacMenuAppService : ApplicationService, IThRbacMenuAppService |
| 465 | 468 | MenuName = x.MenuName ?? string.Empty, |
| 466 | 469 | RouterName = x.RouterName, |
| 467 | 470 | Router = x.Router, |
| 471 | + RouteUrl = x.Router, | |
| 472 | + MenuIcon = x.MenuIcon, | |
| 473 | + IsLink = x.IsLink, | |
| 474 | + IsCache = x.IsCache, | |
| 475 | + IsShow = x.IsShow, | |
| 476 | + Remark = x.Remark, | |
| 477 | + Component = x.Component, | |
| 478 | + Query = x.Query, | |
| 479 | + ConcurrencyStamp = x.ConcurrencyStamp, | |
| 468 | 480 | PermissionCode = x.PermissionCode, |
| 469 | 481 | MenuType = (MenuTypeEnum)x.MenuType, |
| 470 | 482 | MenuSource = (MenuSourceEnum)x.MenuSource, | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/src/Yi.Abp.Web/appsettings.json
| ... | ... | @@ -20,7 +20,7 @@ |
| 20 | 20 | }, |
| 21 | 21 | //应用启动:SelfUrl 供 Program.cs UseUrls 绑定;用 0.0.0.0 避免写成固定局域网 IP 在本机无该网卡时启动失败(WinError 10049) |
| 22 | 22 | "App": { |
| 23 | - "SelfUrl": "http://192.168.31.87:19002", | |
| 23 | + "SelfUrl": "http://192.168.31.88:19002", | |
| 24 | 24 | "CorsOrigins": "http://localhost:19002;http://localhost:18000;http://localhost:5666;http://localhost:5173;http://localhost:5174;http://localhost:3000;http://127.0.0.1:19002;http://flus-tetest.3flabeling.com;https://flus-tetest.3flabeling.com;http://flusapi-tetest.3flabeling.com;https://flusapi-tetest.3flabeling.com" |
| 25 | 25 | }, |
| 26 | 26 | //配置 |
| ... | ... | @@ -60,6 +60,15 @@ |
| 60 | 60 | }, |
| 61 | 61 | "TenantSelectCrypto": { |
| 62 | 62 | "SecretKey": "FoodLabelingThTenantSelect2026Key!" |
| 63 | + }, | |
| 64 | + "AppUpdate": { | |
| 65 | + "Enabled": true, | |
| 66 | + "PackageName": "com.3flabeling.usapp", | |
| 67 | + "VersionCode": 106, | |
| 68 | + "VersionName": "1.0.6", | |
| 69 | + "ForceUpdate": false, | |
| 70 | + "Changelog": "", | |
| 71 | + "ApkPath": "/www/wwwroot/FoodLabelingManagementUs/wwwroot/app-update/app-release.apk" | |
| 63 | 72 | } |
| 64 | 73 | }, |
| 65 | 74 | ... | ... |
泰额版/Food Labeling Management Code/Yi.Abp.Net8/src/Yi.Abp.Web/wwwroot/FoodLabelingManagementSAAS/training/20261012140249_23897803234742272.jpg
0 → 100644
54.3 KB
泰额版/Food Labeling Management Code/Yi.Vben5.Vue3/apps/web-antd/src/api/request.ts
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/AppUpdate/AppUpdateDto.cs
0 → 100644
| 1 | +namespace FoodLabeling.Application.Contracts.Dtos.AppUpdate; | |
| 2 | + | |
| 3 | +/// <summary>App 版本检查出参(对齐锁控面板 <c>/api/app/update</c>)。</summary> | |
| 4 | +public class AppUpdateDto | |
| 5 | +{ | |
| 6 | + public string PackageName { get; set; } = string.Empty; | |
| 7 | + | |
| 8 | + /// <summary>服务端当前可安装包的版本号(来自 APK / version.json,不是每次后端发版)</summary> | |
| 9 | + public int VersionCode { get; set; } | |
| 10 | + | |
| 11 | + public string VersionName { get; set; } = string.Empty; | |
| 12 | + | |
| 13 | + public bool ForceUpdate { get; set; } | |
| 14 | + | |
| 15 | + public string Changelog { get; set; } = string.Empty; | |
| 16 | + | |
| 17 | + /// <summary>完整 APK 下载地址</summary> | |
| 18 | + public string ApkUrl { get; set; } = string.Empty; | |
| 19 | + | |
| 20 | + public bool ApkReady { get; set; } | |
| 21 | + | |
| 22 | + /// <summary>服务端实际解析到的 APK 路径(排查 apkReady=false;前端可忽略)</summary> | |
| 23 | + public string? ApkResolvedPath { get; set; } | |
| 24 | + | |
| 25 | + /// <summary> | |
| 26 | + /// 入参带了本地 <c>versionCode</c> 时:远程更大且 apkReady 则为 true; | |
| 27 | + /// 未传本地版本时为 null,由前端自行比较。 | |
| 28 | + /// </summary> | |
| 29 | + public bool? HasUpdate { get; set; } | |
| 30 | +} | ... | ... |
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/IServices/IAppUpdateAppService.cs
0 → 100644
| 1 | +using FoodLabeling.Application.Contracts.Dtos.AppUpdate; | |
| 2 | +using Microsoft.AspNetCore.Mvc; | |
| 3 | +using Volo.Abp.Application.Services; | |
| 4 | + | |
| 5 | +namespace FoodLabeling.Application.Contracts.IServices; | |
| 6 | + | |
| 7 | +/// <summary>App 版本检查与 APK 下载</summary> | |
| 8 | +public interface IAppUpdateAppService : IApplicationService | |
| 9 | +{ | |
| 10 | + Task<AppUpdateDto> GetInfoAsync(int? versionCode); | |
| 11 | + | |
| 12 | + IActionResult DownloadApk(); | |
| 13 | +} | ... | ... |
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/FoodLabelingApplicationModule.cs
| ... | ... | @@ -23,6 +23,8 @@ public class FoodLabelingApplicationModule : AbpModule |
| 23 | 23 | { |
| 24 | 24 | Configure<FoodLabelingBatchImportOptions>( |
| 25 | 25 | context.Services.GetConfiguration().GetSection(FoodLabelingBatchImportOptions.SectionName)); |
| 26 | + Configure<FoodLabelingAppUpdateOptions>( | |
| 27 | + context.Services.GetConfiguration().GetSection(FoodLabelingAppUpdateOptions.SectionName)); | |
| 26 | 28 | |
| 27 | 29 | // 任意业务写接口成功后刷新系统编辑时间戳,供 my-menus.lastUpdated 使用 |
| 28 | 30 | Configure<MvcOptions>(options => | ... | ... |
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/AppUpdatePathHelper.cs
0 → 100644
| 1 | +using FoodLabeling.Application.Options; | |
| 2 | + | |
| 3 | +namespace FoodLabeling.Application.Helpers; | |
| 4 | + | |
| 5 | +/// <summary>相对路径按进程工作目录解析;<c>ApkPath</c> 可为 APK 文件或目录。</summary> | |
| 6 | +public static class AppUpdatePathHelper | |
| 7 | +{ | |
| 8 | + public const string DefaultFileName = "app-release.apk"; | |
| 9 | + | |
| 10 | + private static readonly string[] FallbackDirectories = | |
| 11 | + [ | |
| 12 | + "/www/wwwroot/FoodLabelingManagementTeUsTest/wwwroot/app-update", | |
| 13 | + "/www/wwwroot/FoodLabelingManagementUs/wwwroot/app-update" | |
| 14 | + ]; | |
| 15 | + | |
| 16 | + public static FileInfo? ResolveApk(FoodLabelingAppUpdateOptions cfg) | |
| 17 | + { | |
| 18 | + if (cfg is null || string.IsNullOrWhiteSpace(cfg.ApkPath)) | |
| 19 | + { | |
| 20 | + return null; | |
| 21 | + } | |
| 22 | + | |
| 23 | + var configured = cfg.ApkPath.Trim().TrimEnd('/', '\\'); | |
| 24 | + var tried = new HashSet<string>(StringComparer.OrdinalIgnoreCase); | |
| 25 | + var candidates = new List<FileInfo>(); | |
| 26 | + | |
| 27 | + void AddFile(string path) | |
| 28 | + { | |
| 29 | + if (string.IsNullOrWhiteSpace(path) || !tried.Add(path)) | |
| 30 | + { | |
| 31 | + return; | |
| 32 | + } | |
| 33 | + | |
| 34 | + candidates.Add(new FileInfo(path)); | |
| 35 | + } | |
| 36 | + | |
| 37 | + void AddPath(string path) | |
| 38 | + { | |
| 39 | + if (string.IsNullOrWhiteSpace(path)) | |
| 40 | + { | |
| 41 | + return; | |
| 42 | + } | |
| 43 | + | |
| 44 | + if (Directory.Exists(path)) | |
| 45 | + { | |
| 46 | + AddFile(Path.Combine(path, DefaultFileName)); | |
| 47 | + foreach (var apk in Directory.EnumerateFiles(path, "*.apk") | |
| 48 | + .OrderByDescending(File.GetLastWriteTimeUtc)) | |
| 49 | + { | |
| 50 | + AddFile(apk); | |
| 51 | + } | |
| 52 | + | |
| 53 | + return; | |
| 54 | + } | |
| 55 | + | |
| 56 | + AddFile(path); | |
| 57 | + if (!Path.HasExtension(path)) | |
| 58 | + { | |
| 59 | + AddFile(Path.Combine(path, DefaultFileName)); | |
| 60 | + } | |
| 61 | + } | |
| 62 | + | |
| 63 | + AddPath(configured); | |
| 64 | + if (!Path.IsPathRooted(configured)) | |
| 65 | + { | |
| 66 | + var stripped = configured.StartsWith("./", StringComparison.Ordinal) | |
| 67 | + ? configured[2..] | |
| 68 | + : configured; | |
| 69 | + AddPath(Path.Combine(Environment.CurrentDirectory, stripped)); | |
| 70 | + } | |
| 71 | + | |
| 72 | + foreach (var dir in FallbackDirectories) | |
| 73 | + { | |
| 74 | + AddPath(dir); | |
| 75 | + } | |
| 76 | + | |
| 77 | + foreach (var file in candidates) | |
| 78 | + { | |
| 79 | + if (file.Exists && file.Length > 0) | |
| 80 | + { | |
| 81 | + return file; | |
| 82 | + } | |
| 83 | + } | |
| 84 | + | |
| 85 | + return candidates.Count == 0 ? null : candidates[0]; | |
| 86 | + } | |
| 87 | +} | ... | ... |
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Helpers/AppUpdateVersionResolver.cs
0 → 100644
| 1 | +using System.Collections.Concurrent; | |
| 2 | +using System.IO.Compression; | |
| 3 | +using System.Text.Json; | |
| 4 | +using FoodLabeling.Application.Options; | |
| 5 | + | |
| 6 | +namespace FoodLabeling.Application.Helpers; | |
| 7 | + | |
| 8 | +/// <summary> | |
| 9 | +/// 版本号以已上传 APK 为准:日常后端发版不改版本;只有目录里换了新包才变。 | |
| 10 | +/// 优先读 APK 内 UniApp <c>manifest.json</c>,其次同目录 <c>version.json</c>,最后才用 appsettings 兜底。 | |
| 11 | +/// </summary> | |
| 12 | +public static class AppUpdateVersionResolver | |
| 13 | +{ | |
| 14 | + private static readonly ConcurrentDictionary<string, (long Length, long Ticks, int Code, string Name)> ApkCache = | |
| 15 | + new(StringComparer.OrdinalIgnoreCase); | |
| 16 | + | |
| 17 | + public static (int VersionCode, string VersionName) Resolve(FileInfo? apk, FoodLabelingAppUpdateOptions options) | |
| 18 | + { | |
| 19 | + var fallbackCode = options.VersionCode; | |
| 20 | + var fallbackName = options.VersionName ?? string.Empty; | |
| 21 | + | |
| 22 | + if (apk is not { Exists: true, Length: > 0 }) | |
| 23 | + { | |
| 24 | + return (fallbackCode, fallbackName); | |
| 25 | + } | |
| 26 | + | |
| 27 | + if (TryReadFromApk(apk, out var apkCode, out var apkName)) | |
| 28 | + { | |
| 29 | + return (apkCode, string.IsNullOrWhiteSpace(apkName) ? fallbackName : apkName); | |
| 30 | + } | |
| 31 | + | |
| 32 | + if (TryReadSidecar(apk.DirectoryName, out var fileCode, out var fileName)) | |
| 33 | + { | |
| 34 | + return (fileCode, string.IsNullOrWhiteSpace(fileName) ? fallbackName : fileName); | |
| 35 | + } | |
| 36 | + | |
| 37 | + return (fallbackCode, fallbackName); | |
| 38 | + } | |
| 39 | + | |
| 40 | + private static bool TryReadFromApk(FileInfo apk, out int versionCode, out string versionName) | |
| 41 | + { | |
| 42 | + versionCode = 0; | |
| 43 | + versionName = string.Empty; | |
| 44 | + var cacheKey = apk.FullName; | |
| 45 | + var ticks = apk.LastWriteTimeUtc.Ticks; | |
| 46 | + if (ApkCache.TryGetValue(cacheKey, out var cached) | |
| 47 | + && cached.Length == apk.Length | |
| 48 | + && cached.Ticks == ticks) | |
| 49 | + { | |
| 50 | + versionCode = cached.Code; | |
| 51 | + versionName = cached.Name; | |
| 52 | + return versionCode > 0; | |
| 53 | + } | |
| 54 | + | |
| 55 | + try | |
| 56 | + { | |
| 57 | + using var zip = ZipFile.OpenRead(apk.FullName); | |
| 58 | + foreach (var entry in zip.Entries) | |
| 59 | + { | |
| 60 | + if (!entry.FullName.EndsWith("manifest.json", StringComparison.OrdinalIgnoreCase)) | |
| 61 | + { | |
| 62 | + continue; | |
| 63 | + } | |
| 64 | + | |
| 65 | + var path = entry.FullName.Replace('\\', '/'); | |
| 66 | + if (path.Contains("/node_modules/", StringComparison.OrdinalIgnoreCase) | |
| 67 | + || path.Contains("/unpackage/", StringComparison.OrdinalIgnoreCase)) | |
| 68 | + { | |
| 69 | + continue; | |
| 70 | + } | |
| 71 | + | |
| 72 | + using var stream = entry.Open(); | |
| 73 | + using var doc = JsonDocument.Parse(stream); | |
| 74 | + if (!TryReadManifest(doc.RootElement, out versionCode, out versionName) || versionCode <= 0) | |
| 75 | + { | |
| 76 | + continue; | |
| 77 | + } | |
| 78 | + | |
| 79 | + ApkCache[cacheKey] = (apk.Length, ticks, versionCode, versionName); | |
| 80 | + return true; | |
| 81 | + } | |
| 82 | + } | |
| 83 | + catch (Exception) | |
| 84 | + { | |
| 85 | + return false; | |
| 86 | + } | |
| 87 | + | |
| 88 | + return false; | |
| 89 | + } | |
| 90 | + | |
| 91 | + private static bool TryReadSidecar(string? directory, out int versionCode, out string versionName) | |
| 92 | + { | |
| 93 | + versionCode = 0; | |
| 94 | + versionName = string.Empty; | |
| 95 | + if (string.IsNullOrWhiteSpace(directory)) | |
| 96 | + { | |
| 97 | + return false; | |
| 98 | + } | |
| 99 | + | |
| 100 | + var sidecar = Path.Combine(directory, "version.json"); | |
| 101 | + if (!File.Exists(sidecar)) | |
| 102 | + { | |
| 103 | + return false; | |
| 104 | + } | |
| 105 | + | |
| 106 | + try | |
| 107 | + { | |
| 108 | + using var doc = JsonDocument.Parse(File.ReadAllText(sidecar)); | |
| 109 | + return TryReadManifest(doc.RootElement, out versionCode, out versionName) && versionCode > 0; | |
| 110 | + } | |
| 111 | + catch (Exception) | |
| 112 | + { | |
| 113 | + return false; | |
| 114 | + } | |
| 115 | + } | |
| 116 | + | |
| 117 | + private static bool TryReadManifest(JsonElement root, out int versionCode, out string versionName) | |
| 118 | + { | |
| 119 | + versionCode = 0; | |
| 120 | + versionName = string.Empty; | |
| 121 | + if (root.ValueKind != JsonValueKind.Object) | |
| 122 | + { | |
| 123 | + return false; | |
| 124 | + } | |
| 125 | + | |
| 126 | + versionName = ReadString(root, "versionName") ?? string.Empty; | |
| 127 | + var codeEl = GetProperty(root, "versionCode"); | |
| 128 | + if (codeEl.ValueKind == JsonValueKind.Number && codeEl.TryGetInt32(out var n)) | |
| 129 | + { | |
| 130 | + versionCode = n; | |
| 131 | + return true; | |
| 132 | + } | |
| 133 | + | |
| 134 | + if (codeEl.ValueKind == JsonValueKind.String | |
| 135 | + && int.TryParse(codeEl.GetString(), out var fromText) | |
| 136 | + && fromText > 0) | |
| 137 | + { | |
| 138 | + versionCode = fromText; | |
| 139 | + return true; | |
| 140 | + } | |
| 141 | + | |
| 142 | + return false; | |
| 143 | + } | |
| 144 | + | |
| 145 | + private static string? ReadString(JsonElement root, string name) | |
| 146 | + { | |
| 147 | + var el = GetProperty(root, name); | |
| 148 | + return el.ValueKind == JsonValueKind.String ? el.GetString() : null; | |
| 149 | + } | |
| 150 | + | |
| 151 | + private static JsonElement GetProperty(JsonElement root, string name) | |
| 152 | + { | |
| 153 | + if (root.TryGetProperty(name, out var el)) | |
| 154 | + { | |
| 155 | + return el; | |
| 156 | + } | |
| 157 | + | |
| 158 | + foreach (var p in root.EnumerateObject()) | |
| 159 | + { | |
| 160 | + if (string.Equals(p.Name, name, StringComparison.OrdinalIgnoreCase)) | |
| 161 | + { | |
| 162 | + return p.Value; | |
| 163 | + } | |
| 164 | + } | |
| 165 | + | |
| 166 | + return default; | |
| 167 | + } | |
| 168 | +} | ... | ... |
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Options/FoodLabelingAppUpdateOptions.cs
0 → 100644
| 1 | +namespace FoodLabeling.Application.Options; | |
| 2 | + | |
| 3 | +/// <summary> | |
| 4 | +/// App 热更新。接口展示的版本号优先来自已上传 APK;appsettings 仅作无包时的兜底。 | |
| 5 | +/// </summary> | |
| 6 | +public class FoodLabelingAppUpdateOptions | |
| 7 | +{ | |
| 8 | + public const string SectionName = "FoodLabeling:AppUpdate"; | |
| 9 | + | |
| 10 | + public bool Enabled { get; set; } = true; | |
| 11 | + | |
| 12 | + public string PackageName { get; set; } = "com.3flabeling.usapp"; | |
| 13 | + | |
| 14 | + /// <summary>整型版本号,须大于 App 本地 versionCode 才会提示更新。</summary> | |
| 15 | + public int VersionCode { get; set; } = 106; | |
| 16 | + | |
| 17 | + public string VersionName { get; set; } = "1.0.6"; | |
| 18 | + | |
| 19 | + public bool ForceUpdate { get; set; } | |
| 20 | + | |
| 21 | + public string Changelog { get; set; } = string.Empty; | |
| 22 | + | |
| 23 | + /// <summary>APK 文件或目录。部署脚本会改成对应环境的 wwwroot/app-update 路径。</summary> | |
| 24 | + public string ApkPath { get; set; } = | |
| 25 | + "/www/wwwroot/FoodLabelingManagementTeUsTest/wwwroot/app-update/app-release.apk"; | |
| 26 | +} | ... | ... |
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/AppUpdateAppService.cs
0 → 100644
| 1 | +using FoodLabeling.Application.Contracts.Dtos.AppUpdate; | |
| 2 | +using FoodLabeling.Application.Contracts.IServices; | |
| 3 | +using FoodLabeling.Application.Helpers; | |
| 4 | +using FoodLabeling.Application.Options; | |
| 5 | +using Microsoft.AspNetCore.Authorization; | |
| 6 | +using Microsoft.AspNetCore.Http; | |
| 7 | +using Microsoft.AspNetCore.Mvc; | |
| 8 | +using Microsoft.Extensions.Logging; | |
| 9 | +using Microsoft.Extensions.Options; | |
| 10 | +using Volo.Abp; | |
| 11 | +using Volo.Abp.Application.Services; | |
| 12 | + | |
| 13 | +namespace FoodLabeling.Application.Services; | |
| 14 | + | |
| 15 | +/// <summary> | |
| 16 | +/// App 版本检查与 APK 下载(对齐锁控面板;供手动「检查更新」)。 | |
| 17 | +/// </summary> | |
| 18 | +[AllowAnonymous] | |
| 19 | +public class AppUpdateAppService : ApplicationService, IAppUpdateAppService | |
| 20 | +{ | |
| 21 | + private readonly FoodLabelingAppUpdateOptions _options; | |
| 22 | + private readonly IHttpContextAccessor _httpContextAccessor; | |
| 23 | + private readonly ILogger<AppUpdateAppService> _logger; | |
| 24 | + | |
| 25 | + public AppUpdateAppService( | |
| 26 | + IOptions<FoodLabelingAppUpdateOptions> options, | |
| 27 | + IHttpContextAccessor httpContextAccessor, | |
| 28 | + ILogger<AppUpdateAppService> logger) | |
| 29 | + { | |
| 30 | + _options = options.Value; | |
| 31 | + _httpContextAccessor = httpContextAccessor; | |
| 32 | + _logger = logger; | |
| 33 | + } | |
| 34 | + | |
| 35 | + /// <summary> | |
| 36 | + /// 查询服务端最新 App 版本 | |
| 37 | + /// </summary> | |
| 38 | + /// <remarks> | |
| 39 | + /// 无需登录。前端用本地 <c>versionCode</c> 与返回的 <c>versionCode</c> 比较。 | |
| 40 | + /// | |
| 41 | + /// 示例请求: | |
| 42 | + /// ```json | |
| 43 | + /// GET /api/app/update?versionCode=106 | |
| 44 | + /// ``` | |
| 45 | + /// | |
| 46 | + /// 参数说明: | |
| 47 | + /// - versionCode: 可选,当前 App 本地整型版本号;传入时出参带 hasUpdate | |
| 48 | + /// </remarks> | |
| 49 | + /// <param name="versionCode">当前 App 本地 versionCode</param> | |
| 50 | + /// <returns>最新版本信息与 APK 地址</returns> | |
| 51 | + /// <response code="200">成功</response> | |
| 52 | + /// <response code="400">更新未启用</response> | |
| 53 | + /// <response code="500">服务器错误</response> | |
| 54 | + [HttpGet] | |
| 55 | + [Route("/api/app/update")] | |
| 56 | + public Task<AppUpdateDto> GetInfoAsync([FromQuery] int? versionCode) | |
| 57 | + { | |
| 58 | + EnsureEnabled(); | |
| 59 | + var apk = AppUpdatePathHelper.ResolveApk(_options); | |
| 60 | + var ready = apk is { Exists: true, Length: > 0 }; | |
| 61 | + if (!ready) | |
| 62 | + { | |
| 63 | + _logger.LogWarning( | |
| 64 | + "App 更新 APK 未就绪,配置路径={Configured},已解析={Resolved},user.dir={UserDir}", | |
| 65 | + _options.ApkPath, | |
| 66 | + apk?.FullName, | |
| 67 | + Environment.CurrentDirectory); | |
| 68 | + } | |
| 69 | + | |
| 70 | + var (remoteCode, remoteName) = AppUpdateVersionResolver.Resolve(apk, _options); | |
| 71 | + bool? hasUpdate = null; | |
| 72 | + if (versionCode.HasValue) | |
| 73 | + { | |
| 74 | + hasUpdate = ready && remoteCode > versionCode.Value; | |
| 75 | + } | |
| 76 | + | |
| 77 | + return Task.FromResult(new AppUpdateDto | |
| 78 | + { | |
| 79 | + PackageName = _options.PackageName ?? string.Empty, | |
| 80 | + VersionCode = remoteCode, | |
| 81 | + VersionName = remoteName, | |
| 82 | + ForceUpdate = _options.ForceUpdate, | |
| 83 | + Changelog = _options.Changelog ?? string.Empty, | |
| 84 | + ApkReady = ready, | |
| 85 | + ApkResolvedPath = apk?.FullName, | |
| 86 | + ApkUrl = BuildApkUrl(), | |
| 87 | + HasUpdate = hasUpdate | |
| 88 | + }); | |
| 89 | + } | |
| 90 | + | |
| 91 | + /// <summary> | |
| 92 | + /// 下载最新 APK(二进制,不走 JSON 包装) | |
| 93 | + /// </summary> | |
| 94 | + /// <remarks>无需登录。Content-Type 为 application/vnd.android.package-archive。</remarks> | |
| 95 | + /// <returns>APK 文件流</returns> | |
| 96 | + /// <response code="200">成功返回文件</response> | |
| 97 | + /// <response code="400">更新未启用或文件不存在</response> | |
| 98 | + /// <response code="500">服务器错误</response> | |
| 99 | + [HttpGet] | |
| 100 | + [Route("/api/app/update/apk")] | |
| 101 | + public IActionResult DownloadApk() | |
| 102 | + { | |
| 103 | + EnsureEnabled(); | |
| 104 | + var apk = AppUpdatePathHelper.ResolveApk(_options); | |
| 105 | + if (apk is not { Exists: true, Length: > 0 }) | |
| 106 | + { | |
| 107 | + throw new UserFriendlyException( | |
| 108 | + "APK 文件不存在,请放到: " + _options.ApkPath | |
| 109 | + + "(当前工作目录=" + Environment.CurrentDirectory + ")"); | |
| 110 | + } | |
| 111 | + | |
| 112 | + var (_, remoteName) = AppUpdateVersionResolver.Resolve(apk, _options); | |
| 113 | + var downloadName = "food-labeling-" + (string.IsNullOrWhiteSpace(remoteName) ? "app" : remoteName) + ".apk"; | |
| 114 | + return new PhysicalFileResult(apk.FullName, "application/vnd.android.package-archive") | |
| 115 | + { | |
| 116 | + FileDownloadName = downloadName | |
| 117 | + }; | |
| 118 | + } | |
| 119 | + | |
| 120 | + private void EnsureEnabled() | |
| 121 | + { | |
| 122 | + if (!_options.Enabled) | |
| 123 | + { | |
| 124 | + throw new UserFriendlyException("App 更新未启用"); | |
| 125 | + } | |
| 126 | + } | |
| 127 | + | |
| 128 | + private string BuildApkUrl() | |
| 129 | + { | |
| 130 | + var request = _httpContextAccessor.HttpContext?.Request; | |
| 131 | + if (request is null) | |
| 132 | + { | |
| 133 | + return "/api/app/update/apk"; | |
| 134 | + } | |
| 135 | + | |
| 136 | + return $"{request.Scheme}://{request.Host}{request.PathBase}/api/app/update/apk"; | |
| 137 | + } | |
| 138 | +} | ... | ... |
美国版/Food Labeling Management Code/Yi.Abp.Net8/src/Yi.Abp.Web/appsettings.json
| ... | ... | @@ -128,6 +128,15 @@ |
| 128 | 128 | }, |
| 129 | 129 | |
| 130 | 130 | "FoodLabeling": { |
| 131 | + "AppUpdate": { | |
| 132 | + "Enabled": true, | |
| 133 | + "PackageName": "com.3flabeling.usapp", | |
| 134 | + "VersionCode": 108, | |
| 135 | + "VersionName": "1.0.8", | |
| 136 | + "ForceUpdate": false, | |
| 137 | + "Changelog": "", | |
| 138 | + "ApkPath": "/www/wwwroot/FoodLabelingManagementTeUsTest/wwwroot/app-update/app-release.apk" | |
| 139 | + }, | |
| 131 | 140 | "BatchImport": { |
| 132 | 141 | "TemplateDirectory": "/www/wwwroot/FoodLabelingManagementUs/batchImportOfFiles", |
| 133 | 142 | "LocationTemplateFileName": "Location-Manager-批量导入模板.xlsx", | ... | ... |
美国版/scripts/泰鄂测试版部署.ps1
美国版/scripts/泰鄂美国测试版部署.ps1
| 1 | 1 | #Requires -Version 5.1 |
| 2 | 2 | <# |
| 3 | 3 | .SYNOPSIS |
| 4 | - 泰鄂美国测试版 API 一键部署 | |
| 4 | + Te US test API deploy | |
| 5 | 5 | .DESCRIPTION |
| 6 | - 发布 Yi.Abp.Web,上传到 47.253.11.59,重启 Kestrel 19004,健康检查 https://flusapi-teustest.3flabeling.com | |
| 6 | + Publish Yi.Abp.Web to 47.253.11.59, restart Kestrel 19004. | |
| 7 | + https://flusapi-teustest.3flabeling.com | |
| 8 | + Script only rewrites ApkPath to wwwroot/app-update and keeps uploaded APK. | |
| 9 | + VersionCode is NOT auto-incremented. Edit manually: | |
| 10 | + 美国版/Food Labeling Management Code/Yi.Abp.Net8/src/Yi.Abp.Web/appsettings.json | |
| 11 | + FoodLabeling.AppUpdate.VersionCode / VersionName / Changelog / ForceUpdate | |
| 7 | 12 | #> |
| 8 | 13 | param( |
| 9 | 14 | [switch]$SkipBuild |
| ... | ... | @@ -34,17 +39,17 @@ $PublishDir = Join-Path $RepoRoot "美国版\Food Labeling Management Code\Yi.Ab |
| 34 | 39 | Initialize-DeploySsh |
| 35 | 40 | $SshOpts = $global:SshOpts |
| 36 | 41 | |
| 37 | -Write-Host "== 泰鄂美国测试版部署 ==" -ForegroundColor Cyan | |
| 38 | -Write-Host "目标: $HostName $RemoteDir" | |
| 39 | -Write-Host "域名: $HealthUrl" | |
| 40 | -Write-Host "数据库: $TestDbName @ $DbHost" | |
| 42 | +Write-Host "== Te US test deploy ==" -ForegroundColor Cyan | |
| 43 | +Write-Host "target: $HostName $RemoteDir" | |
| 44 | +Write-Host "url: $HealthUrl" | |
| 45 | +Write-Host "db: $TestDbName @ $DbHost" | |
| 41 | 46 | |
| 42 | 47 | if (-not $SkipBuild) { |
| 43 | - if (-not (Test-Path $WebCsproj)) { throw "找不到工程: $WebCsproj" } | |
| 44 | - Write-Host "== 发布 Yi.Abp.Web ==" -ForegroundColor Cyan | |
| 48 | + if (-not (Test-Path $WebCsproj)) { throw "csproj not found: $WebCsproj" } | |
| 49 | + Write-Host "== dotnet publish ==" -ForegroundColor Cyan | |
| 45 | 50 | if (Test-Path $PublishDir) { Remove-Item $PublishDir -Recurse -Force } |
| 46 | 51 | & dotnet publish $WebCsproj -c Release -o $PublishDir --nologo |
| 47 | - if ($LASTEXITCODE -ne 0) { throw "dotnet publish 失败" } | |
| 52 | + if ($LASTEXITCODE -ne 0) { throw "dotnet publish failed" } | |
| 48 | 53 | |
| 49 | 54 | $appsettings = Join-Path $PublishDir "appsettings.json" |
| 50 | 55 | if (Test-Path $appsettings) { |
| ... | ... | @@ -55,44 +60,53 @@ if (-not $SkipBuild) { |
| 55 | 60 | $json = [regex]::Replace($json, 'uid=[^;]+', "uid=$DbUser") |
| 56 | 61 | $json = [regex]::Replace($json, 'pwd=[^;]+', "pwd=$DbPassword") |
| 57 | 62 | $json = [regex]::Replace($json, 'database=antis-foodlabeling-[^;]+', "database=$TestDbName") |
| 63 | + $apkPath = "$RemoteDir/wwwroot/app-update/app-release.apk" | |
| 64 | + if ($json -notmatch '"AppUpdate"') { | |
| 65 | + throw "appsettings.json missing FoodLabeling:AppUpdate" | |
| 66 | + } | |
| 67 | + $json = [regex]::Replace($json, '"ApkPath"\s*:\s*"[^"]*"', '"ApkPath": "' + $apkPath + '"') | |
| 68 | + Write-Host "AppUpdate.ApkPath => $apkPath (VersionCode unchanged)" | |
| 58 | 69 | Set-Content -Path $appsettings -Value $json -Encoding UTF8 |
| 59 | 70 | } |
| 60 | 71 | } |
| 61 | 72 | |
| 62 | 73 | if (-not (Test-Path (Join-Path $PublishDir "Yi.Abp.Web.dll"))) { |
| 63 | - throw "发布目录缺少 Yi.Abp.Web.dll: $PublishDir" | |
| 74 | + throw "missing Yi.Abp.Web.dll: $PublishDir" | |
| 64 | 75 | } |
| 65 | 76 | |
| 66 | -Write-Host "== 停止远程进程 ==" -ForegroundColor Cyan | |
| 67 | -Invoke-Remote @' | |
| 77 | +Write-Host "== stop remote process ==" -ForegroundColor Cyan | |
| 78 | +$stopRemote = @" | |
| 68 | 79 | set -e |
| 69 | -if [ -f "/var/tmp/net_project/食品标签泰鄂美国测试版.pid" ]; then | |
| 70 | - pid=$(cat "/var/tmp/net_project/食品标签泰鄂美国测试版.pid" || true) | |
| 71 | - if [ -n "$pid" ]; then kill "$pid" 2>/dev/null || true; fi | |
| 80 | +PIDFILE=/var/tmp/net_project/食品标签泰鄂美国测试版.pid | |
| 81 | +if test -f "`$PIDFILE"; then | |
| 82 | + pid=`$(cat "`$PIDFILE" || true) | |
| 83 | + if test -n "`$pid"; then kill `$pid 2>/dev/null || true; fi | |
| 72 | 84 | fi |
| 73 | 85 | pkill -f "/www/wwwroot/FoodLabelingManagementTeUsTest/Yi.Abp.Web.dll" 2>/dev/null || true |
| 74 | 86 | sleep 1 |
| 75 | 87 | echo stopped |
| 76 | -'@ | |
| 88 | +"@ | |
| 89 | +Invoke-Remote $stopRemote | |
| 77 | 90 | |
| 78 | -Write-Host "== 上传发布包 ==" -ForegroundColor Cyan | |
| 91 | +Write-Host "== upload publish package ==" -ForegroundColor Cyan | |
| 79 | 92 | $tar = Join-Path $env:TEMP "flus-teustest-publish.tgz" |
| 80 | 93 | if (Test-Path $tar) { Remove-Item $tar -Force } |
| 81 | 94 | Push-Location $PublishDir |
| 82 | 95 | try { |
| 83 | 96 | & tar -czf $tar --exclude=logs --exclude=startup.log * |
| 84 | - if ($LASTEXITCODE -ne 0) { throw "打包失败" } | |
| 97 | + if ($LASTEXITCODE -ne 0) { throw "tar failed" } | |
| 85 | 98 | } finally { |
| 86 | 99 | Pop-Location |
| 87 | 100 | } |
| 88 | 101 | |
| 89 | 102 | & scp @SshOpts $tar "${UserName}@${HostName}:/tmp/flus-teustest-publish.tgz" |
| 90 | -if ($LASTEXITCODE -ne 0) { throw "scp 失败" } | |
| 103 | +if ($LASTEXITCODE -ne 0) { throw "scp failed" } | |
| 91 | 104 | |
| 92 | -Invoke-Remote @" | |
| 105 | +$uploadRemote = @" | |
| 93 | 106 | set -e |
| 94 | 107 | mkdir -p '$RemoteDir' |
| 95 | 108 | cd '$RemoteDir' |
| 109 | +test -d wwwroot/app-update && mv wwwroot/app-update /tmp/teustest-app-update-keep || true | |
| 96 | 110 | for x in *; do |
| 97 | 111 | case "`$x" in |
| 98 | 112 | logs|*.log) ;; |
| ... | ... | @@ -101,23 +115,29 @@ for x in *; do |
| 101 | 115 | done |
| 102 | 116 | tar --overwrite -xzf /tmp/flus-teustest-publish.tgz -C '$RemoteDir' |
| 103 | 117 | rm -f /tmp/flus-teustest-publish.tgz |
| 118 | +mkdir -p '$RemoteDir/wwwroot/app-update' | |
| 119 | +test -d /tmp/teustest-app-update-keep && cp -a /tmp/teustest-app-update-keep/. '$RemoteDir/wwwroot/app-update/' || true | |
| 120 | +rm -rf /tmp/teustest-app-update-keep | |
| 104 | 121 | chmod -R a+rX '$RemoteDir' |
| 105 | 122 | ls -l '$RemoteDir/Yi.Abp.Web.dll' |
| 123 | +ls -l '$RemoteDir/wwwroot/app-update' || true | |
| 106 | 124 | echo uploaded_to=$RemoteDir |
| 107 | 125 | "@ |
| 126 | +Invoke-Remote $uploadRemote | |
| 108 | 127 | |
| 109 | -Write-Host "== 登记宝塔 Net 项目 ==" -ForegroundColor Cyan | |
| 128 | +Write-Host "== register BT net project ==" -ForegroundColor Cyan | |
| 110 | 129 | $btPyLocal = Join-Path $ScriptDir "bt-register-net-project.py" |
| 111 | 130 | & scp @SshOpts $btPyLocal "${UserName}@${HostName}:/tmp/bt-register-net-project.py" |
| 112 | -if ($LASTEXITCODE -ne 0) { throw "上传宝塔登记脚本失败" } | |
| 113 | -Invoke-Remote @" | |
| 131 | +if ($LASTEXITCODE -ne 0) { throw "upload bt python failed" } | |
| 132 | +$btRemote = @" | |
| 114 | 133 | set -e |
| 115 | 134 | sed -i 's/\r`$//' /tmp/bt-register-net-project.py |
| 116 | 135 | python3 /tmp/bt-register-net-project.py name='$BtName' path='$RemoteDir' port='19004' ps='$BtName' domain='$BtDomain' cmd='$BtCmd' run_user='root' dotnet_version='8.0.100' |
| 117 | 136 | "@ |
| 137 | +Invoke-Remote $btRemote | |
| 118 | 138 | |
| 119 | -Write-Host "== 启动 API ==" -ForegroundColor Cyan | |
| 120 | -Invoke-Remote -AllowFail @" | |
| 139 | +Write-Host "== start API ==" -ForegroundColor Cyan | |
| 140 | +$startRemote = @" | |
| 121 | 141 | mkdir -p /www/wwwlogs/net /var/tmp/net_project |
| 122 | 142 | cd '$RemoteDir' |
| 123 | 143 | nohup $Dotnet '$AppDll' --urls=$ListenUrl >> /www/wwwlogs/net/食品标签泰鄂美国测试版.log 2>&1 & |
| ... | ... | @@ -127,24 +147,47 @@ ss -lntp | grep 19004 || true |
| 127 | 147 | curl -s -o /dev/null -w 'local=%{http_code}\n' --max-time 15 http://127.0.0.1:19004/swagger/index.html || true |
| 128 | 148 | tail -n 20 /www/wwwlogs/net/食品标签泰鄂美国测试版.log || true |
| 129 | 149 | "@ |
| 150 | +Invoke-Remote -AllowFail $startRemote | |
| 130 | 151 | |
| 131 | -Write-Host "== 健康检查 ==" -ForegroundColor Cyan | |
| 152 | +Write-Host "== health check ==" -ForegroundColor Cyan | |
| 132 | 153 | $ok = $false |
| 133 | 154 | for ($i = 1; $i -le 8; $i++) { |
| 134 | 155 | try { |
| 135 | 156 | $resp = Invoke-WebRequest -Uri $HealthUrl -UseBasicParsing -TimeoutSec 15 |
| 136 | 157 | if ($resp.StatusCode -eq 200) { |
| 137 | - Write-Host "访问成功: $HealthUrl HTTP $($resp.StatusCode)" -ForegroundColor Green | |
| 158 | + Write-Host "OK: $HealthUrl HTTP $($resp.StatusCode)" -ForegroundColor Green | |
| 138 | 159 | $ok = $true |
| 139 | 160 | break |
| 140 | 161 | } |
| 141 | 162 | } catch { |
| 142 | - Write-Host "等待服务就绪 ($i/8)..." | |
| 163 | + Write-Host "wait ($i/8)..." | |
| 143 | 164 | Start-Sleep -Seconds 3 |
| 144 | 165 | } |
| 145 | 166 | } |
| 146 | 167 | |
| 147 | -if (-not $ok) { throw "部署后健康检查失败: $HealthUrl" } | |
| 148 | -Write-Host "完成。API: https://flusapi-teustest.3flabeling.com" -ForegroundColor Green | |
| 168 | +if (-not $ok) { throw "health check failed: $HealthUrl" } | |
| 169 | + | |
| 170 | +$updateUrl = "https://flusapi-teustest.3flabeling.com/api/app/update" | |
| 171 | +Write-Host "== current App version ==" -ForegroundColor Cyan | |
| 172 | +try { | |
| 173 | + $updateResp = Invoke-WebRequest -Uri $updateUrl -UseBasicParsing -TimeoutSec 20 | |
| 174 | + $updateJson = $updateResp.Content | ConvertFrom-Json | |
| 175 | + $data = $updateJson.data | |
| 176 | + if (-not $data) { $data = $updateJson } | |
| 177 | + $code = $data.versionCode | |
| 178 | + $name = $data.versionName | |
| 179 | + $ready = $data.apkReady | |
| 180 | + Write-Host ("VERSION_CODE={0}" -f $code) -ForegroundColor Green | |
| 181 | + Write-Host ("VERSION_NAME={0}" -f $name) -ForegroundColor Green | |
| 182 | + Write-Host ("APK_READY={0}" -f $ready) | |
| 183 | + if ($data.apkResolvedPath) { | |
| 184 | + Write-Host ("APK_PATH={0}" -f $data.apkResolvedPath) | |
| 185 | + } | |
| 186 | + Write-Host "check: GET $updateUrl" | |
| 187 | +} catch { | |
| 188 | + Write-Host "failed to read /api/app/update: $($_.Exception.Message)" -ForegroundColor Yellow | |
| 189 | +} | |
| 190 | + | |
| 191 | +Write-Host "done. API: https://flusapi-teustest.3flabeling.com" -ForegroundColor Green | |
| 149 | 192 | Write-Host "Swagger: $HealthUrl" |
| 150 | -Write-Host "登录: POST https://flusapi-teustest.3flabeling.com/api/app/account/login" | |
| 193 | +Write-Host "login: POST https://flusapi-teustest.3flabeling.com/api/app/account/login" | ... | ... |
项目相关文档/seed_host_platform_menus(1).sql
0 → 100644
| 1 | +-- 泰额版平台级菜单:清空 antis-foodlabeling-host.menu 后按前端路由表重录 | |
| 2 | +-- 使用稳定 Id(f001*),保证 rolemenu 等引用不失效 | |
| 3 | +-- MenuSource=0(Ruoyi),平台目录 MenuType=0,页面 MenuType=1 | |
| 4 | + | |
| 5 | +SET NAMES utf8mb4; | |
| 6 | +START TRANSACTION; | |
| 7 | + | |
| 8 | +DELETE FROM menu; | |
| 9 | + | |
| 10 | +INSERT INTO menu ( | |
| 11 | + Id, IsDeleted, CreationTime, CreatorId, LastModifierId, LastModificationTime, | |
| 12 | + OrderNum, State, MenuName, RouterName, MenuType, PermissionCode, ParentId, | |
| 13 | + MenuIcon, Router, IsLink, IsCache, IsShow, Remark, Component, MenuSource, Query, ConcurrencyStamp | |
| 14 | +) VALUES | |
| 15 | +-- 首页概览 | |
| 16 | +('f0010001-0001-4000-8000-000000000001', 0, NOW(), NULL, NULL, NULL, | |
| 17 | + -1, 1, '首页概览', 'FoodLabelingDashboard', 1, 'menu.dashboard.analytics', '0', | |
| 18 | + 'lucide:layout-dashboard', '/analytics', 0, 0, 1, NULL, '/food-labeling/dashboard/index', 0, NULL, ''), | |
| 19 | + | |
| 20 | +-- 平台管理 | |
| 21 | +('f0010002-0001-4000-8000-000000000002', 0, NOW(), NULL, NULL, NULL, | |
| 22 | + 5, 1, '平台管理', 'FoodLabelingPlatform', 0, 'menu.platform', '0', | |
| 23 | + 'lucide:cloud-cog', '/platform', 0, 0, 1, NULL, NULL, 0, NULL, ''), | |
| 24 | +('f0010003-0001-4000-8000-000000000003', 0, NOW(), NULL, NULL, NULL, | |
| 25 | + 6, 1, 'SAAS 公司', 'FoodLabelingPlatformTenants', 1, 'menu.platform.tenants', 'f0010002-0001-4000-8000-000000000002', | |
| 26 | + 'lucide:building', '/platform/tenants', 0, 0, 1, NULL, '/food-labeling/platform/tenants/index', 0, NULL, ''), | |
| 27 | +('f0010037-0001-4000-8000-000000000037', 0, NOW(), NULL, NULL, NULL, | |
| 28 | + 7, 1, '二维码', 'FoodLabelingQrCodes', 1, 'menu.platform.qr-codes', 'f0010002-0001-4000-8000-000000000002', | |
| 29 | + 'lucide:qr-code', '/platform/qr-codes', 0, 0, 1, NULL, '/food-labeling/modules/qr-codes/index', 0, NULL, ''), | |
| 30 | + | |
| 31 | +-- 标签管理 | |
| 32 | +('f0010010-0001-4000-8000-000000000010', 0, NOW(), NULL, NULL, NULL, | |
| 33 | + 10, 1, '标签管理', 'FoodLabelingLabeling', 0, 'menu.labeling', '0', | |
| 34 | + 'lucide:tags', '/labeling', 0, 0, 1, NULL, NULL, 0, NULL, ''), | |
| 35 | +('f0010011-0001-4000-8000-000000000011', 0, NOW(), NULL, NULL, NULL, | |
| 36 | + 11, 1, '标签', 'FoodLabelingLabels', 1, 'menu.labeling.labels', 'f0010010-0001-4000-8000-000000000010', | |
| 37 | + 'lucide:tag', '/labels', 0, 0, 1, NULL, '/food-labeling/labeling/labels/index', 0, NULL, ''), | |
| 38 | +('f0010012-0001-4000-8000-000000000012', 0, NOW(), NULL, NULL, NULL, | |
| 39 | + 12, 1, '标签分类', 'FoodLabelingLabelCategories', 1, 'menu.labeling.categories', 'f0010010-0001-4000-8000-000000000010', | |
| 40 | + 'lucide:folder-tree', '/label-categories', 0, 0, 1, NULL, '/food-labeling/labeling/label-categories/index', 0, NULL, ''), | |
| 41 | +('f0010013-0001-4000-8000-000000000013', 0, NOW(), NULL, NULL, NULL, | |
| 42 | + 13, 1, '标签类型', 'FoodLabelingLabelTypes', 1, 'menu.labeling.types', 'f0010010-0001-4000-8000-000000000010', | |
| 43 | + 'lucide:layers', '/label-types', 0, 0, 1, NULL, '/food-labeling/labeling/label-types/index', 0, NULL, ''), | |
| 44 | +('f0010014-0001-4000-8000-000000000014', 0, NOW(), NULL, NULL, NULL, | |
| 45 | + 14, 1, '标签模板', 'FoodLabelingLabelTemplates', 1, 'menu.labeling.templates', 'f0010010-0001-4000-8000-000000000010', | |
| 46 | + 'lucide:layout-template', '/label-templates', 0, 0, 1, NULL, '/food-labeling/labeling/label-templates/index', 0, NULL, ''), | |
| 47 | +('f0010015-0001-4000-8000-000000000015', 0, NOW(), NULL, NULL, NULL, | |
| 48 | + 15, 1, '多选选项集', 'FoodLabelingMultipleOptions', 1, 'menu.labeling.multiple-options', 'f0010010-0001-4000-8000-000000000010', | |
| 49 | + 'lucide:list-checks', '/multiple-options', 0, 0, 1, NULL, '/food-labeling/labeling/multiple-options/index', 0, NULL, ''), | |
| 50 | + | |
| 51 | +-- 原「业务模块」子项:提升为一级菜单(ParentId=0),不再保留「业务模块」目录 | |
| 52 | +('f0010021-0001-4000-8000-000000000021', 0, NOW(), NULL, NULL, NULL, | |
| 53 | + 15, 1, '培训', 'FoodLabelingTraining', 1, 'menu.modules.training', '0', | |
| 54 | + 'lucide:graduation-cap', '/training', 0, 0, 1, NULL, '/food-labeling/modules/training/index', 0, NULL, ''), | |
| 55 | +('f0010022-0001-4000-8000-000000000022', 0, NOW(), NULL, NULL, NULL, | |
| 56 | + 16, 1, '告警', 'FoodLabelingAlerts', 1, 'menu.modules.alerts', '0', | |
| 57 | + 'lucide:bell', '/alerts', 0, 0, 1, NULL, '/food-labeling/modules/alerts/index', 0, NULL, ''), | |
| 58 | +('f0010023-0001-4000-8000-000000000023', 0, NOW(), NULL, NULL, NULL, | |
| 59 | + 17, 1, '任务', 'FoodLabelingTasks', 1, 'menu.modules.tasks', '0', | |
| 60 | + 'lucide:list-todo', '/tasks', 0, 0, 1, NULL, '/food-labeling/modules/tasks/index', 0, NULL, ''), | |
| 61 | +('f0010024-0001-4000-8000-000000000024', 0, NOW(), NULL, NULL, NULL, | |
| 62 | + 18, 1, '传感器', 'FoodLabelingSensors', 1, 'menu.modules.sensors', '0', | |
| 63 | + 'lucide:activity', '/sensors', 0, 0, 1, NULL, '/food-labeling/modules/sensors/index', 0, NULL, ''), | |
| 64 | +('f0010025-0001-4000-8000-000000000025', 0, NOW(), NULL, NULL, NULL, | |
| 65 | + 19, 1, '食物浪费', 'FoodLabelingFoodWaste', 1, 'menu.modules.food-waste', '0', | |
| 66 | + 'lucide:apple', '/food-waste', 0, 0, 1, NULL, '/food-labeling/modules/food-waste/index', 0, NULL, ''), | |
| 67 | +('f0010026-0001-4000-8000-000000000026', 0, NOW(), NULL, NULL, NULL, | |
| 68 | + 20, 1, '电子标签', 'FoodLabelingELabelModule', 1, 'menu.modules.e-label', '0', | |
| 69 | + 'lucide:file-digit', '/e-label-module', 0, 0, 1, NULL, '/food-labeling/modules/e-label/index', 0, NULL, ''), | |
| 70 | + | |
| 71 | +-- 管理 | |
| 72 | +('f0010030-0001-4000-8000-000000000030', 0, NOW(), NULL, NULL, NULL, | |
| 73 | + 30, 1, '管理', 'FoodLabelingManagement', 0, 'menu.management', '0', | |
| 74 | + 'lucide:building-2', '/management', 0, 0, 1, NULL, NULL, 0, NULL, ''), | |
| 75 | +('f0010031-0001-4000-8000-000000000031', 0, NOW(), NULL, NULL, NULL, | |
| 76 | + 31, 1, '账户管理', 'FoodLabelingAccountManagement', 1, 'menu.management.account', 'f0010030-0001-4000-8000-000000000030', | |
| 77 | + 'lucide:users', '/account-management', 0, 0, 1, NULL, '/food-labeling/management/account-management/index', 0, NULL, ''), | |
| 78 | +('f0010032-0001-4000-8000-000000000032', 0, NOW(), NULL, NULL, NULL, | |
| 79 | + 32, 1, '系统菜单', 'FoodLabelingSystemMenu', 1, 'menu.management.system-menu', 'f0010030-0001-4000-8000-000000000030', | |
| 80 | + 'lucide:menu-square', '/system-menu', 0, 0, 1, NULL, '/food-labeling/management/system-menu/index', 0, NULL, ''), | |
| 81 | +('f0010033-0001-4000-8000-000000000033', 0, NOW(), NULL, NULL, NULL, | |
| 82 | + 33, 1, '菜单管理', 'FoodLabelingMenuManagement', 1, 'menu.management.menu', 'f0010030-0001-4000-8000-000000000030', | |
| 83 | + 'lucide:utensils', '/menu-management', 0, 0, 1, NULL, '/food-labeling/management/menu-management/index', 0, NULL, ''), | |
| 84 | +('f0010034-0001-4000-8000-000000000034', 0, NOW(), NULL, NULL, NULL, | |
| 85 | + 34, 1, '设备', 'FoodLabelingDevices', 1, 'menu.management.devices', 'f0010030-0001-4000-8000-000000000030', | |
| 86 | + 'lucide:smartphone', '/devices', 0, 0, 1, NULL, '/food-labeling/modules/devices/index', 0, NULL, ''), | |
| 87 | +('f0010035-0001-4000-8000-000000000035', 0, NOW(), NULL, NULL, NULL, | |
| 88 | + 35, 1, '报表', 'FoodLabelingReports', 1, 'menu.management.reports', 'f0010030-0001-4000-8000-000000000030', | |
| 89 | + 'lucide:file-bar-chart', '/reports', 0, 0, 1, NULL, '/food-labeling/management/reports/index', 0, NULL, ''), | |
| 90 | +('f0010036-0001-4000-8000-000000000036', 0, NOW(), NULL, NULL, NULL, | |
| 91 | + 36, 1, '发票', 'FoodLabelingInvoices', 1, 'menu.management.invoices', 'f0010030-0001-4000-8000-000000000030', | |
| 92 | + 'lucide:receipt', '/invoices', 0, 0, 1, NULL, '/food-labeling/modules/invoices/index', 0, NULL, ''), | |
| 93 | +('f0010038-0001-4000-8000-000000000038', 0, NOW(), NULL, NULL, NULL, | |
| 94 | + 37, 1, '支持', 'FoodLabelingSupport', 1, 'menu.management.support', 'f0010030-0001-4000-8000-000000000030', | |
| 95 | + 'lucide:life-buoy', '/support', 0, 0, 1, NULL, '/food-labeling/management/support/index', 0, NULL, ''), | |
| 96 | +('f0010039-0001-4000-8000-000000000039', 0, NOW(), NULL, NULL, NULL, | |
| 97 | + 38, 1, 'API', 'FoodLabelingApi', 1, 'menu.management.api', 'f0010030-0001-4000-8000-000000000030', | |
| 98 | + 'lucide:code-2', '/api-settings', 0, 0, 1, NULL, '/food-labeling/modules/api/index', 0, NULL, ''); | |
| 99 | + | |
| 100 | +COMMIT; | ... | ... |
项目相关文档/二维码菜单改为平台级-说明(1).md
0 → 100644
| 1 | +# 二维码菜单改为平台级 | |
| 2 | + | |
| 3 | +> 日期:2026-10-13 | |
| 4 | +> 说明:前端路由已挪到「平台管理」;**已有环境的 host / 租户库菜单需执行下方 SQL**(不自动改后端代码逻辑)。 | |
| 5 | + | |
| 6 | +## 目标 | |
| 7 | + | |
| 8 | +- **平台端**(图:平台管理):「二维码」挂在「平台管理」下,与「SAAS 公司」同级。 | |
| 9 | +- **企业端**(租户):「管理」下**不再**出现「二维码」。 | |
| 10 | +- 权限码改为 `menu.platform.qr-codes`(`IsPlatformOnlyMenu` 会按 `menu.platform*` 判定为仅平台,不可分配给公司)。 | |
| 11 | + | |
| 12 | +## 前端(已改) | |
| 13 | + | |
| 14 | +- `Yi.Vben5.Vue3/.../router/routes/local.ts` | |
| 15 | + - 路径:`/platform/qr-codes` | |
| 16 | + - 父级:`FoodLabelingPlatform`(平台管理) | |
| 17 | + | |
| 18 | +## 种子脚本(已改,供重建 host 菜单) | |
| 19 | + | |
| 20 | +- `Yi.Abp.Net8/.../scripts/seed_host_platform_menus.sql` | |
| 21 | + - 二维码 `ParentId` → 平台管理目录 | |
| 22 | + - `PermissionCode` → `menu.platform.qr-codes` | |
| 23 | + - `Router` → `/platform/qr-codes` | |
| 24 | + | |
| 25 | +## 已有库补丁 SQL(需运维执行) | |
| 26 | + | |
| 27 | +### 1)Host 库(如 `antis-foodlabeling-host`) | |
| 28 | + | |
| 29 | +```sql | |
| 30 | +-- 二维码挪到「平台管理」下 | |
| 31 | +UPDATE menu | |
| 32 | +SET | |
| 33 | + ParentId = 'f0010002-0001-4000-8000-000000000002', | |
| 34 | + PermissionCode = 'menu.platform.qr-codes', | |
| 35 | + Router = '/platform/qr-codes', | |
| 36 | + Component = '/food-labeling/modules/qr-codes/index', | |
| 37 | + OrderNum = 7, | |
| 38 | + IsShow = 1, | |
| 39 | + IsDeleted = 0 | |
| 40 | +WHERE Id = 'f0010037-0001-4000-8000-000000000037'; | |
| 41 | +``` | |
| 42 | + | |
| 43 | +### 2)各租户库(企业端去掉二维码) | |
| 44 | + | |
| 45 | +对每个公司库执行其一即可: | |
| 46 | + | |
| 47 | +```sql | |
| 48 | +-- 推荐:软删,企业端菜单不再展示 | |
| 49 | +UPDATE menu | |
| 50 | +SET IsDeleted = 1, DeletionTime = NOW() | |
| 51 | +WHERE Id = 'f0010037-0001-4000-8000-000000000037' | |
| 52 | + OR Router IN ('/qr-codes', '/platform/qr-codes') | |
| 53 | + OR PermissionCode IN ('menu.management.qr-codes', 'menu.platform.qr-codes'); | |
| 54 | +``` | |
| 55 | + | |
| 56 | +或仅隐藏: | |
| 57 | + | |
| 58 | +```sql | |
| 59 | +UPDATE menu SET IsShow = 0 | |
| 60 | +WHERE Id = 'f0010037-0001-4000-8000-000000000037' | |
| 61 | + OR Router IN ('/qr-codes', '/platform/qr-codes'); | |
| 62 | +``` | |
| 63 | + | |
| 64 | +### 3)可选:权限目录兼容(后端 C#,若要用新 SaaS Key) | |
| 65 | + | |
| 66 | +文件:`FoodLabeling.Th.Application/MultiTenancy/ThSaasMenuPermissionCatalog.cs` | |
| 67 | +在 `LegacyKeyToMenuId` 增加: | |
| 68 | + | |
| 69 | +```csharp | |
| 70 | +["platform:qr-codes"] = "f0010037-0001-4000-8000-000000000037", | |
| 71 | +``` | |
| 72 | + | |
| 73 | +保留 `["management:qr-codes"] = ...` 兼容历史数据。 | |
| 74 | +(`menu.platform.qr-codes` 本身已会被 `IsPlatformOnlyMenu` 识别,可不改代码也能达到「不可分配给公司」。) | |
| 75 | + | |
| 76 | +## 验证 | |
| 77 | + | |
| 78 | +1. 平台管理员登录 → 「平台管理」下可见「二维码」,打开 `/platform/qr-codes`。 | |
| 79 | +2. 企业管理员登录 → 「管理」下无「二维码」。 | |
| 80 | +3. 开通公司时的菜单树中不应再勾选到可分配的「二维码」(平台 only)。 | ... | ... |
项目相关文档/告警计时器后端改造方案(1).md
0 → 100644
| 1 | +# 告警计时器后端改造方案 | |
| 2 | + | |
| 3 | +> 文档日期:2026-10-13 | |
| 4 | +> 适用范围:泰额版 `Yi.Abp.Net8` / `food-labeling-us` | |
| 5 | +> 说明:本文档为**后端改造规格**,供后端单独实现;前端(平台告警页、标签模板「到期提醒」)按本文约定对接。 | |
| 6 | + | |
| 7 | +--- | |
| 8 | + | |
| 9 | +## 1. 已确认业务规则 | |
| 10 | + | |
| 11 | +| # | 规则 | | |
| 12 | +|---|---| | |
| 13 | +| 1 | **过期时刻 `ExpiresAt`**:从标签打印数据解析(与 Print Log Expiration 同源,`ReportsPrintLogExpiryHelper.TryResolveExpiryDateTime`)。**告警模板的 `DateTimeFormat` 仅用于展示**该过期时刻(出参 `formattedExpiresAt`)。 | | |
| 14 | +| 2 | **无「到期提醒」控件的旧模板**:打印成功后**不写**计时器。 | | |
| 15 | +| 3 | **到期弹窗文案**:`亲爱的{userName},您的{labelName}标签已过期,请及时处理`。`{userName}` 由 **App 当前登录人**替换;后端可返回带占位符的 `expiredMessageTemplate`。 | | |
| 16 | +| 4 | **平台**可查权限范围内**所有门店**计时器;**App**仅查**当前门店**。 | | |
| 17 | + | |
| 18 | +--- | |
| 19 | + | |
| 20 | +## 2. 现状 vs 目标 | |
| 21 | + | |
| 22 | +| 项 | 现状 | 目标 | | |
| 23 | +|---|---|---| | |
| 24 | +| 告警模板 | 无 | 表 `fl_alert_template` + CRUD + options | | |
| 25 | +| 到期提醒控件 | 前端可选模板;写库逻辑需后端识别 | 打印时检测 Expiration Alert + 有效 `alertTemplateId` 才写计时器 | | |
| 26 | +| 写计时器 | 有过期时刻即可能写入 | 必须:有到期提醒控件 + 启用模板 + 能解析过期时刻 | | |
| 27 | +| 平台 list | 强制 `locationId` | `locationId` 可选;空 = 权限内全店 | | |
| 28 | +| App list | 本店 | 保持本店 | | |
| 29 | +| 展示格式 | 无 | 按模板 `DateTimeFormat` 输出 `formattedExpiresAt` | | |
| 30 | +| 弹窗文案 | 无标准字段 | 出参 `expiredMessageTemplate` | | |
| 31 | + | |
| 32 | +--- | |
| 33 | + | |
| 34 | +## 3. 数据库 | |
| 35 | + | |
| 36 | +### 3.1 新表 `fl_alert_template` | |
| 37 | + | |
| 38 | +```sql | |
| 39 | +CREATE TABLE IF NOT EXISTS `fl_alert_template` ( | |
| 40 | + `Id` varchar(36) NOT NULL COMMENT '主键(YitId)', | |
| 41 | + `TemplateName` varchar(200) NOT NULL COMMENT '模板名称', | |
| 42 | + `DateTimeFormat` varchar(100) NOT NULL COMMENT '日期时间格式(如 MM/dd/yyyy h:mm tt)', | |
| 43 | + `State` tinyint(1) NOT NULL DEFAULT 1 COMMENT '启用状态', | |
| 44 | + `IsDeleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '软删', | |
| 45 | + `DeletionTime` datetime DEFAULT NULL, | |
| 46 | + `CreatedBy` varchar(36) DEFAULT NULL, | |
| 47 | + `CreationTime` datetime NOT NULL, | |
| 48 | + `LastModificationTime` datetime DEFAULT NULL, | |
| 49 | + PRIMARY KEY (`Id`), | |
| 50 | + KEY `idx_fl_alert_template_state` (`State`), | |
| 51 | + KEY `idx_fl_alert_template_name` (`TemplateName`) | |
| 52 | +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='告警日期时间格式模板'; | |
| 53 | +``` | |
| 54 | + | |
| 55 | +**DateTimeFormat 建议预设(前端下拉,后端原样存储字符串):** | |
| 56 | + | |
| 57 | +- `MM/dd/yyyy h:mm tt` | |
| 58 | +- `yyyy-MM-dd HH:mm` | |
| 59 | +- `dd/MM/yyyy HH:mm` | |
| 60 | + | |
| 61 | +### 3.2 扩展 `fl_label_alert_timer` | |
| 62 | + | |
| 63 | +在现有表上增加: | |
| 64 | + | |
| 65 | +| 列 | 类型 | 说明 | | |
| 66 | +|---|---|---| | |
| 67 | +| `AlertTemplateId` | varchar(36) NULL | 告警模板 Id | | |
| 68 | +| `AlertTemplateName` | varchar(200) NULL | 名称冗余 | | |
| 69 | +| `DateTimeFormat` | varchar(100) NULL | 格式冗余(列表展示不依赖再查模板) | | |
| 70 | +| `PrintedByUserId` | varchar(36) NULL | 打印人 Id | | |
| 71 | +| `PrintedByUserName` | varchar(200) NULL | 打印人姓名 | | |
| 72 | +| `LocationName` | varchar(200) NULL | 门店名冗余 | | |
| 73 | + | |
| 74 | +> 保留:`BatchId` 唯一、软删、`ExpiresAt`、`DurationSeconds`、`Title`、`Subtitle` 等。 | |
| 75 | + | |
| 76 | +租户迁移:新 SQL 挂到 `FoodLabelingTenantMigrationScriptNames`;已有租户执行一次扩展脚本。 | |
| 77 | + | |
| 78 | +**ID 规范:** 所有新实体主键使用 `YitIdHelper.NextId().ToString()`,禁止 `Guid.NewGuid()`。 | |
| 79 | + | |
| 80 | +--- | |
| 81 | + | |
| 82 | +## 4. 接口设计 | |
| 83 | + | |
| 84 | +统一包装:`{ "code": 200, "data": {}, "message": "" }` | |
| 85 | +鉴权:`Authorization: Bearer …` | |
| 86 | +分页约定(本模块):`skipCount` = **页码从 1 起**(与现有 label-alert-timer 一致)。 | |
| 87 | + | |
| 88 | +### 4.1 告警模板 `/api/app/alert-template` | |
| 89 | + | |
| 90 | +| 方法 | 路径 | 说明 | | |
| 91 | +|---|---|---| | |
| 92 | +| POST | `/api/app/alert-template/list` | 分页列表 | | |
| 93 | +| GET | `/api/app/alert-template/{id}` | 详情 | | |
| 94 | +| POST | `/api/app/alert-template` | 新增 | | |
| 95 | +| PUT | `/api/app/alert-template/{id}` | 编辑 | | |
| 96 | +| DELETE | `/api/app/alert-template/{id}` | 软删 | | |
| 97 | +| GET | `/api/app/alert-template/options` | 启用项下拉(标签模板编辑器用) | | |
| 98 | + | |
| 99 | +#### list 入参 | |
| 100 | + | |
| 101 | +```json | |
| 102 | +{ | |
| 103 | + "keyword": "冷藏", | |
| 104 | + "state": true, | |
| 105 | + "skipCount": 1, | |
| 106 | + "maxResultCount": 20 | |
| 107 | +} | |
| 108 | +``` | |
| 109 | + | |
| 110 | +#### 新增/编辑 body | |
| 111 | + | |
| 112 | +```json | |
| 113 | +{ | |
| 114 | + "templateName": "US 过期展示", | |
| 115 | + "dateTimeFormat": "MM/dd/yyyy h:mm tt", | |
| 116 | + "state": true | |
| 117 | +} | |
| 118 | +``` | |
| 119 | + | |
| 120 | +#### options 出参(data 数组元素) | |
| 121 | + | |
| 122 | +```json | |
| 123 | +{ | |
| 124 | + "id": "…", | |
| 125 | + "templateName": "US 过期展示", | |
| 126 | + "dateTimeFormat": "MM/dd/yyyy h:mm tt" | |
| 127 | +} | |
| 128 | +``` | |
| 129 | + | |
| 130 | +仅返回 `State=true` 且未删除。 | |
| 131 | + | |
| 132 | +--- | |
| 133 | + | |
| 134 | +### 4.2 计时器 `/api/app/label-alert-timer`(改造现有) | |
| 135 | + | |
| 136 | +| 方法 | 路径 | 说明 | | |
| 137 | +|---|---|---| | |
| 138 | +| POST | `/api/app/label-alert-timer/list` | **平台**:`locationId` 可选 | | |
| 139 | +| POST | `/api/app/label-alert-timer/app-list` | **App**:强制当前门店 | | |
| 140 | +| POST | `/api/app/label-alert-timer/check-expired` | 状态查询;补弹窗字段 | | |
| 141 | +| DELETE | `/api/app/label-alert-timer/{id}` | 软删(保持门店权限校验) | | |
| 142 | + | |
| 143 | +#### 平台 list | |
| 144 | + | |
| 145 | +```json | |
| 146 | +{ | |
| 147 | + "locationId": "", | |
| 148 | + "skipCount": 1, | |
| 149 | + "maxResultCount": 20, | |
| 150 | + "dateDay": "2026-10-13" | |
| 151 | +} | |
| 152 | +``` | |
| 153 | + | |
| 154 | +- `locationId` **空或省略**:当前用户权限范围内全部门店(参考 `ReportsLocationScopeHelper` / Print Log 全店范围)。 | |
| 155 | +- `locationId` **有值**:仅该门店,并校验可访问。 | |
| 156 | +- `dateDay`:按 `PrintedAt` 自然日筛选(可选)。 | |
| 157 | + | |
| 158 | +#### App app-list | |
| 159 | + | |
| 160 | +- 必须落到**一个**门店:入参 `locationId` 或已选门店缓存;否则友好错误。 | |
| 161 | +- **禁止**全店查询。 | |
| 162 | + | |
| 163 | +#### 列表项建议出参(data.items[]) | |
| 164 | + | |
| 165 | +| 字段 | 说明 | | |
| 166 | +|---|---| | |
| 167 | +| id / batchId / printTaskId / labelId / labelCode | 原有 | | |
| 168 | +| labelName | 标签名称 | | |
| 169 | +| title / subtitle | 原有展示标题 | | |
| 170 | +| totalTime / remainingTime | 秒 | | |
| 171 | +| status | `running` \| `expired` | | |
| 172 | +| expiresAt | 过期时刻 | | |
| 173 | +| **formattedExpiresAt** | 按 `DateTimeFormat` 格式化后的字符串 | | |
| 174 | +| printedAt | 打印时刻 | | |
| 175 | +| locationId / **locationName** | 门店 | | |
| 176 | +| productName | 产品名 | | |
| 177 | +| **alertTemplateId / alertTemplateName / dateTimeFormat** | 模板冗余 | | |
| 178 | +| printedByUserId / printedByUserName | 打印人 | | |
| 179 | +| **expiredMessageTemplate** | 固定:`亲爱的{userName},您的{labelName}标签已过期,请及时处理` | | |
| 180 | + | |
| 181 | +App 弹窗:用当前登录人姓名替换 `{userName}`,用该项 `labelName` 替换 `{labelName}`。 | |
| 182 | + | |
| 183 | +#### check-expired | |
| 184 | + | |
| 185 | +入参至少提供 `timerId` / `batchId` / `printTaskId` 之一。 | |
| 186 | +出参增加:`labelName`、`formattedExpiresAt`、`expiredMessageTemplate`(及原有 isExpired、remainingSeconds 等)。 | |
| 187 | +**注意:** 本接口仅展示倒计时,**不得**用于拦截打印。 | |
| 188 | + | |
| 189 | +--- | |
| 190 | + | |
| 191 | +## 5. 打印写计时器逻辑 | |
| 192 | + | |
| 193 | +入口:打印成功后(现有 `UsAppLabelingAppService` 等调用点)→ `LabelAlertTimerWriteHelper.TryCreateFromPrintBatchAsync`。 | |
| 194 | + | |
| 195 | +### 5.1 写入条件(全部满足才插入) | |
| 196 | + | |
| 197 | +1. `BatchId` 有效;该 `BatchId` **尚无**计时器记录(含软删也不再插,避免唯一索引冲突)。 | |
| 198 | +2. 从打印任务 `RenderTemplateJson`(或等价快照)的 `elements` 中找到 **Expiration Alert / 到期提醒** 控件。 | |
| 199 | + 识别建议(与前端一致): | |
| 200 | + - `typeAdd` 含 `expiration alert` / `expirationalert`,或 | |
| 201 | + - `elementName` 含 `expiration alert` / `到期提醒` | |
| 202 | +3. 该元素 `config.alertTemplateId` 非空,且对应 `fl_alert_template` 存在、`!IsDeleted`、`State=true`。 | |
| 203 | +4. `ReportsPrintLogExpiryHelper.TryResolveExpiryDateTime(printInputJson, renderTemplateJson, …)` 成功得到 `ExpiresAt`。 | |
| 204 | + | |
| 205 | +任一不满足 → **直接 return,不写计时器**(含:旧模板无到期提醒控件)。 | |
| 206 | + | |
| 207 | +### 5.2 写入字段 | |
| 208 | + | |
| 209 | +- 原有:BatchId、PrintTaskId、Label*、Product*、LocationId、PrintedAt、BaseTime、ExpiresAt、DurationSeconds、Title、Subtitle… | |
| 210 | +- 新增:AlertTemplateId/Name、DateTimeFormat(从模板拷贝)、PrintedByUserId/Name(打印成功时传入当前用户)、LocationName(可查门店表冗余) | |
| 211 | + | |
| 212 | +### 5.3 标签模板前端约定(供后端解析) | |
| 213 | + | |
| 214 | +到期提醒元素写入 JSON 示例: | |
| 215 | + | |
| 216 | +```json | |
| 217 | +{ | |
| 218 | + "type": "TEXT_STATIC", | |
| 219 | + "typeAdd": "label_Expiration Alert", | |
| 220 | + "elementName": "Expiration Alert", | |
| 221 | + "config": { | |
| 222 | + "alertTemplateId": "模板Id", | |
| 223 | + "alertTemplateName": "US 过期展示", | |
| 224 | + "dateTimeFormat": "MM/dd/yyyy h:mm tt", | |
| 225 | + "text": "…" | |
| 226 | + } | |
| 227 | +} | |
| 228 | +``` | |
| 229 | + | |
| 230 | +--- | |
| 231 | + | |
| 232 | +## 6. 平台 / App 权限差异 | |
| 233 | + | |
| 234 | +| | 平台 `list` | App `app-list` | | |
| 235 | +|---|---|---| | |
| 236 | +| 门店范围 | 可选;空=权限内全店 | 仅当前门店 | | |
| 237 | +| 用途 | 管理端告警页「计时器」Tab(时钟卡片) | App 告警页 + 到期弹窗 | | |
| 238 | +| 删除 | 校验该计时器所属门店权限 | 同左 | | |
| 239 | + | |
| 240 | +--- | |
| 241 | + | |
| 242 | +## 7. 前端已按本文对接的能力(供联调) | |
| 243 | + | |
| 244 | +> 以下为平台/编辑器侧约定;**不要求本文作者改后端代码**,仅便于联调对照。 | |
| 245 | + | |
| 246 | +1. 告警页两个 Tab:告警模板 CRUD;计时器全店时钟卡片(`locationId` 可空)。 | |
| 247 | +2. 标签模板编辑器开放「到期提醒」,属性绑定 `alert-template/options`。 | |
| 248 | +3. 弹窗文案占位:`{userName}` / `{labelName}`。 | |
| 249 | + | |
| 250 | +若后端尚未实现上述接口,前端会调不通,需按本文实现后再联调。 | |
| 251 | + | |
| 252 | +--- | |
| 253 | + | |
| 254 | +## 8. 实现检查清单(后端) | |
| 255 | + | |
| 256 | +- [ ] `fl_alert_template` 建表 + 租户迁移 | |
| 257 | +- [ ] `fl_label_alert_timer` 扩展列 + 迁移 | |
| 258 | +- [ ] AlertTemplate AppService:list / get / create / update / delete / options | |
| 259 | +- [ ] LabelAlertTimerWriteHelper:按 §5 条件写入;旧模板不写 | |
| 260 | +- [ ] 平台 list:`locationId` 可选 + 全店范围 | |
| 261 | +- [ ] App list:强制本店 | |
| 262 | +- [ ] list / check-expired:`formattedExpiresAt`、`expiredMessageTemplate`、`labelName`、`locationName` 等 | |
| 263 | +- [ ] 打印入口传入打印人 Id/Name | |
| 264 | +- [ ] XML 注释、枚举、WhereIF、YitId 规范 | |
| 265 | +- [ ] 接口自测 + 查库验证:有/无到期提醒控件各打一次,确认写库与否 | |
| 266 | + | |
| 267 | +--- | |
| 268 | + | |
| 269 | +## 9. 相关现有代码位置(实现时参考) | |
| 270 | + | |
| 271 | +| 说明 | 路径(泰额版 Yi.Abp.Net8) | | |
| 272 | +|---|---| | |
| 273 | +| 写计时器 Helper | `module/food-labeling-us/.../Helpers/LabelAlertTimerWriteHelper.cs` | | |
| 274 | +| 计时器 Service | `.../Services/LabelAlertTimerAppService.cs` | | |
| 275 | +| 过期时刻解析 | `.../Helpers/ReportsPrintLogExpiryHelper.cs` | | |
| 276 | +| 计时器表脚本 | `.../scripts/fl_label_alert_timer.sql` | | |
| 277 | +| 打印成功调用点 | `.../Services/UsAppLabelingAppService.cs` | | |
| 278 | + | |
| 279 | +--- | |
| 280 | + | |
| 281 | +## 10. 修订记录 | |
| 282 | + | |
| 283 | +| 日期 | 说明 | | |
| 284 | +|---|---| | |
| 285 | +| 2026-10-13 | 初版:按产品确认(格式展示、无控件不写、弹窗当前登录人、平台全店)整理后端规格 | | ... | ... |