From 5cb146949546c7fe8383ce3e894e7e68d78bdfa4 Mon Sep 17 00:00:00 2001 From: 李曜臣 Date: Wed, 1 Apr 2026 17:55:25 +0800 Subject: [PATCH] 打印日志优化 --- 美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/UsAppLabeling/PrintLogItemDto.cs | 3 +++ 美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/UsAppLabelingAppService.cs | 2 ++ 项目相关文档/标签模块接口对接说明.md | 24 +++++++++++++++++++----- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/UsAppLabeling/PrintLogItemDto.cs b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/UsAppLabeling/PrintLogItemDto.cs index e69ab6f..85a1cf3 100644 --- a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/UsAppLabeling/PrintLogItemDto.cs +++ b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/UsAppLabeling/PrintLogItemDto.cs @@ -32,6 +32,9 @@ public class PrintLogItemDto /// 模板尺寸(来自 fl_label_template.Width/Height/Unit) public string? LabelSizeText { get; set; } + /// 本次任务落库的渲染模板 JSON(fl_label_print_task.RenderTemplateJson) + public string? RenderTemplateJson { get; set; } + /// /// 本次打印的内容快照(来自 fl_label_print_data,按 PrintTaskId 关联) /// diff --git a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/UsAppLabelingAppService.cs b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/UsAppLabelingAppService.cs index a979cb6..dd34e24 100644 --- a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/UsAppLabelingAppService.cs +++ b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/UsAppLabelingAppService.cs @@ -774,6 +774,7 @@ public class UsAppLabelingAppService : ApplicationService, IUsAppLabelingAppServ TemplateWidth = tpl.Width, TemplateHeight = tpl.Height, TemplateUnit = tpl.Unit, + t.RenderTemplateJson, t.PrintedAt, t.CreationTime }); @@ -826,6 +827,7 @@ public class UsAppLabelingAppService : ApplicationService, IUsAppLabelingAppServ ProductName = string.IsNullOrWhiteSpace(x.ProductName) ? "无" : x.ProductName.Trim(), TypeName = x.TypeName ?? string.Empty, LabelSizeText = FormatLabelSizeWithUnit(x.TemplateWidth, x.TemplateHeight, x.TemplateUnit), + RenderTemplateJson = x.RenderTemplateJson, PrintDataList = dataMap.TryGetValue(x.Id, out var list) ? list : new List(), PrintedAt = x.PrintedAt ?? x.CreationTime, OperatorName = operatorName, diff --git a/项目相关文档/标签模块接口对接说明.md b/项目相关文档/标签模块接口对接说明.md index b3000d6..cc13fe6 100644 --- a/项目相关文档/标签模块接口对接说明.md +++ b/项目相关文档/标签模块接口对接说明.md @@ -907,6 +907,7 @@ curl -X POST "http://localhost:19001/api/app/us-app-labeling/preview" \ | `labelCode` | string | 是 | 标签编码(`fl_label.LabelCode`) | | `productId` | string | 否 | 打印用产品Id;不传则默认取该标签绑定的第一个产品(用于模板解析) | | `printQuantity` | number | 否 | 打印份数;`<=0` 按 1 处理 | +| `clientRequestId` | string | 否 | 客户端幂等请求Id;同一个值重复调用会直接返回首次创建的 `batchId/taskIds`,避免重复写库 用法:前端/客户端每次点击 Print 生成一个稳定的 clientRequestId(比如 uuid) | | `baseTime` | string | 否 | 业务基准时间(用于 DATE/TIME 元素计算) | | `printInputJson` | object | 否 | 打印输入(用于模板 PRINT_INPUT 元素),key 建议与模板元素 `inputKey` 对齐 | | `printerId` | string | 否 | 打印机Id(可选,用于追踪) | @@ -916,11 +917,11 @@ curl -X POST "http://localhost:19001/api/app/us-app-labeling/preview" \ #### 数据落库说明 - **任务表**:`fl_label_print_task` - - 插入 1 条任务记录(`locationId / labelCode / productId / labelTypeId / templateCode / printQuantity / baseTime / printer...` 等)。 + - **一份打印 = 一条任务**:当 `printQuantity = N` 时,后端会插入 **N 条任务记录**(同一次点击 Print 共享一个 `BatchId`,并记录 `CopyIndex=1..N`)。 + - 任务表会保存:本次打印的输入、命中的模板默认值、以及整份 resolved 后的模板快照 JSON,便于追溯/重打。 - **明细表**:`fl_label_print_data` - - 按 `printQuantity` 插入 N 条明细记录(`copyIndex = 1..N`)。 - - `printInputJson`:保存本次打印的原始输入(JSON 字符串)。 - - `renderDataJson`:保存本次解析后的模板预览结构(`LabelTemplatePreviewDto`,包含 resolved 后的 `elements[].config`),供追溯/重打使用。 + - **按组件写快照**:每个任务会按模板 `elements[]` 逐个插入明细记录(`ElementId/ElementName/RenderValue/RenderConfigJson`)。 + - 适用于按组件维度审计/统计/追溯。 > 模板解析的数据源来自 `fl_label_template` + `fl_label_template_element`,与预览接口一致。 @@ -928,8 +929,11 @@ curl -X POST "http://localhost:19001/api/app/us-app-labeling/preview" \ | 字段 | 类型 | 说明 | |---|---|---| -| `taskId` | string | 打印任务Id(用于后续查询/重打/统计) | +| `taskId` | string | 第 1 份打印任务Id(兼容旧逻辑) | | `printQuantity` | number | 实际写入的份数 | +| `batchId` | string | 本次点击 Print 的批次Id | +| `taskIds` | string[] | 本次生成的所有任务Id(长度=printQuantity) | + #### 错误与边界 @@ -1017,10 +1021,20 @@ curl -X POST "http://localhost:19001/api/app/us-app-labeling/print" \ | `productName` | string | 产品名(来自 fl_product.ProductName;无则 “无”) | | `typeName` | string | 标签类型名称(来自 fl_label_type.TypeName) | | `labelSizeText` | string | 模板尺寸(宽高+单位,如 `2.00x2.00inch` / `6.00x4.00cm`) | +| `renderTemplateJson` | string | 本次任务落库的渲染模板 JSON(`fl_label_print_task.RenderTemplateJson`) | +| `printDataList` | PrintLogDataItemDto[] | 本次打印内容快照(来自 fl_label_print_data,按 taskId 关联) | | `printedAt` | string | 打印时间(PrintedAt ?? CreationTime) | | `operatorName` | string | 操作人姓名(当前登录账号 Name) | | `locationName` | string | 门店名称 | +`PrintLogDataItemDto`: + +| 字段 | 类型 | 说明 | +|---|---|---| +| `elementId` | string | 模板组件Id(fl_label_print_data.ElementId) | +| `renderValue` | string | 最终渲染值(fl_label_print_data.RenderValue) | +| `renderConfigJson` | object | 最终渲染配置(fl_label_print_data.RenderConfigJson 反序列化) | + #### curl ```bash -- libgit2 0.21.4