Commit 5cb146949546c7fe8383ce3e894e7e68d78bdfa4

Authored by 李曜臣
1 parent 76aa233f

打印日志优化

美国版/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 @@ -32,6 +32,9 @@ public class PrintLogItemDto
32 /// <summary>模板尺寸(来自 fl_label_template.Width/Height/Unit)</summary> 32 /// <summary>模板尺寸(来自 fl_label_template.Width/Height/Unit)</summary>
33 public string? LabelSizeText { get; set; } 33 public string? LabelSizeText { get; set; }
34 34
  35 + /// <summary>本次任务落库的渲染模板 JSON(fl_label_print_task.RenderTemplateJson)</summary>
  36 + public string? RenderTemplateJson { get; set; }
  37 +
35 /// <summary> 38 /// <summary>
36 /// 本次打印的内容快照(来自 fl_label_print_data,按 PrintTaskId 关联) 39 /// 本次打印的内容快照(来自 fl_label_print_data,按 PrintTaskId 关联)
37 /// </summary> 40 /// </summary>
美国版/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 @@ -774,6 +774,7 @@ public class UsAppLabelingAppService : ApplicationService, IUsAppLabelingAppServ
774 TemplateWidth = tpl.Width, 774 TemplateWidth = tpl.Width,
775 TemplateHeight = tpl.Height, 775 TemplateHeight = tpl.Height,
776 TemplateUnit = tpl.Unit, 776 TemplateUnit = tpl.Unit,
  777 + t.RenderTemplateJson,
777 t.PrintedAt, 778 t.PrintedAt,
778 t.CreationTime 779 t.CreationTime
779 }); 780 });
@@ -826,6 +827,7 @@ public class UsAppLabelingAppService : ApplicationService, IUsAppLabelingAppServ @@ -826,6 +827,7 @@ public class UsAppLabelingAppService : ApplicationService, IUsAppLabelingAppServ
826 ProductName = string.IsNullOrWhiteSpace(x.ProductName) ? "无" : x.ProductName.Trim(), 827 ProductName = string.IsNullOrWhiteSpace(x.ProductName) ? "无" : x.ProductName.Trim(),
827 TypeName = x.TypeName ?? string.Empty, 828 TypeName = x.TypeName ?? string.Empty,
828 LabelSizeText = FormatLabelSizeWithUnit(x.TemplateWidth, x.TemplateHeight, x.TemplateUnit), 829 LabelSizeText = FormatLabelSizeWithUnit(x.TemplateWidth, x.TemplateHeight, x.TemplateUnit),
  830 + RenderTemplateJson = x.RenderTemplateJson,
829 PrintDataList = dataMap.TryGetValue(x.Id, out var list) ? list : new List<PrintLogDataItemDto>(), 831 PrintDataList = dataMap.TryGetValue(x.Id, out var list) ? list : new List<PrintLogDataItemDto>(),
830 PrintedAt = x.PrintedAt ?? x.CreationTime, 832 PrintedAt = x.PrintedAt ?? x.CreationTime,
831 OperatorName = operatorName, 833 OperatorName = operatorName,
项目相关文档/标签模块接口对接说明.md
@@ -907,6 +907,7 @@ curl -X POST &quot;http://localhost:19001/api/app/us-app-labeling/preview&quot; \ @@ -907,6 +907,7 @@ curl -X POST &quot;http://localhost:19001/api/app/us-app-labeling/preview&quot; \
907 | `labelCode` | string | 是 | 标签编码(`fl_label.LabelCode`) | 907 | `labelCode` | string | 是 | 标签编码(`fl_label.LabelCode`) |
908 | `productId` | string | 否 | 打印用产品Id;不传则默认取该标签绑定的第一个产品(用于模板解析) | 908 | `productId` | string | 否 | 打印用产品Id;不传则默认取该标签绑定的第一个产品(用于模板解析) |
909 | `printQuantity` | number | 否 | 打印份数;`<=0` 按 1 处理 | 909 | `printQuantity` | number | 否 | 打印份数;`<=0` 按 1 处理 |
  910 +| `clientRequestId` | string | 否 | 客户端幂等请求Id;同一个值重复调用会直接返回首次创建的 `batchId/taskIds`,避免重复写库 用法:前端/客户端每次点击 Print 生成一个稳定的 clientRequestId(比如 uuid) |
910 | `baseTime` | string | 否 | 业务基准时间(用于 DATE/TIME 元素计算) | 911 | `baseTime` | string | 否 | 业务基准时间(用于 DATE/TIME 元素计算) |
911 | `printInputJson` | object | 否 | 打印输入(用于模板 PRINT_INPUT 元素),key 建议与模板元素 `inputKey` 对齐 | 912 | `printInputJson` | object | 否 | 打印输入(用于模板 PRINT_INPUT 元素),key 建议与模板元素 `inputKey` 对齐 |
912 | `printerId` | string | 否 | 打印机Id(可选,用于追踪) | 913 | `printerId` | string | 否 | 打印机Id(可选,用于追踪) |
@@ -916,11 +917,11 @@ curl -X POST &quot;http://localhost:19001/api/app/us-app-labeling/preview&quot; \ @@ -916,11 +917,11 @@ curl -X POST &quot;http://localhost:19001/api/app/us-app-labeling/preview&quot; \
916 #### 数据落库说明 917 #### 数据落库说明
917 918
918 - **任务表**:`fl_label_print_task` 919 - **任务表**:`fl_label_print_task`
919 - - 插入 1 条任务记录(`locationId / labelCode / productId / labelTypeId / templateCode / printQuantity / baseTime / printer...` 等)。 920 + - **一份打印 = 一条任务**:当 `printQuantity = N` 时,后端会插入 **N 条任务记录**(同一次点击 Print 共享一个 `BatchId`,并记录 `CopyIndex=1..N`)。
  921 + - 任务表会保存:本次打印的输入、命中的模板默认值、以及整份 resolved 后的模板快照 JSON,便于追溯/重打。
920 - **明细表**:`fl_label_print_data` 922 - **明细表**:`fl_label_print_data`
921 - - 按 `printQuantity` 插入 N 条明细记录(`copyIndex = 1..N`)。  
922 - - `printInputJson`:保存本次打印的原始输入(JSON 字符串)。  
923 - - `renderDataJson`:保存本次解析后的模板预览结构(`LabelTemplatePreviewDto`,包含 resolved 后的 `elements[].config`),供追溯/重打使用。 923 + - **按组件写快照**:每个任务会按模板 `elements[]` 逐个插入明细记录(`ElementId/ElementName/RenderValue/RenderConfigJson`)。
  924 + - 适用于按组件维度审计/统计/追溯。
924 925
925 > 模板解析的数据源来自 `fl_label_template` + `fl_label_template_element`,与预览接口一致。 926 > 模板解析的数据源来自 `fl_label_template` + `fl_label_template_element`,与预览接口一致。
926 927
@@ -928,8 +929,11 @@ curl -X POST &quot;http://localhost:19001/api/app/us-app-labeling/preview&quot; \ @@ -928,8 +929,11 @@ curl -X POST &quot;http://localhost:19001/api/app/us-app-labeling/preview&quot; \
928 929
929 | 字段 | 类型 | 说明 | 930 | 字段 | 类型 | 说明 |
930 |---|---|---| 931 |---|---|---|
931 -| `taskId` | string | 打印任务Id(用于后续查询/重打/统计) | 932 +| `taskId` | string | 第 1 份打印任务Id(兼容旧逻辑) |
932 | `printQuantity` | number | 实际写入的份数 | 933 | `printQuantity` | number | 实际写入的份数 |
  934 +| `batchId` | string | 本次点击 Print 的批次Id |
  935 +| `taskIds` | string[] | 本次生成的所有任务Id(长度=printQuantity) |
  936 +
933 937
934 #### 错误与边界 938 #### 错误与边界
935 939
@@ -1017,10 +1021,20 @@ curl -X POST &quot;http://localhost:19001/api/app/us-app-labeling/print&quot; \ @@ -1017,10 +1021,20 @@ curl -X POST &quot;http://localhost:19001/api/app/us-app-labeling/print&quot; \
1017 | `productName` | string | 产品名(来自 fl_product.ProductName;无则 “无”) | 1021 | `productName` | string | 产品名(来自 fl_product.ProductName;无则 “无”) |
1018 | `typeName` | string | 标签类型名称(来自 fl_label_type.TypeName) | 1022 | `typeName` | string | 标签类型名称(来自 fl_label_type.TypeName) |
1019 | `labelSizeText` | string | 模板尺寸(宽高+单位,如 `2.00x2.00inch` / `6.00x4.00cm`) | 1023 | `labelSizeText` | string | 模板尺寸(宽高+单位,如 `2.00x2.00inch` / `6.00x4.00cm`) |
  1024 +| `renderTemplateJson` | string | 本次任务落库的渲染模板 JSON(`fl_label_print_task.RenderTemplateJson`) |
  1025 +| `printDataList` | PrintLogDataItemDto[] | 本次打印内容快照(来自 fl_label_print_data,按 taskId 关联) |
1020 | `printedAt` | string | 打印时间(PrintedAt ?? CreationTime) | 1026 | `printedAt` | string | 打印时间(PrintedAt ?? CreationTime) |
1021 | `operatorName` | string | 操作人姓名(当前登录账号 Name) | 1027 | `operatorName` | string | 操作人姓名(当前登录账号 Name) |
1022 | `locationName` | string | 门店名称 | 1028 | `locationName` | string | 门店名称 |
1023 1029
  1030 +`PrintLogDataItemDto`:
  1031 +
  1032 +| 字段 | 类型 | 说明 |
  1033 +|---|---|---|
  1034 +| `elementId` | string | 模板组件Id(fl_label_print_data.ElementId) |
  1035 +| `renderValue` | string | 最终渲染值(fl_label_print_data.RenderValue) |
  1036 +| `renderConfigJson` | object | 最终渲染配置(fl_label_print_data.RenderConfigJson 反序列化) |
  1037 +
1024 #### curl 1038 #### curl
1025 1039
1026 ```bash 1040 ```bash