Commit 76aa233fb282e4fec5fa70e2e227847235c13909

Authored by 李曜臣
1 parent ca114eb9

打印日志接口优化

美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/UsAppLabeling/PrintLogItemDto.cs
... ... @@ -32,6 +32,11 @@ public class PrintLogItemDto
32 32 /// <summary>模板尺寸(来自 fl_label_template.Width/Height/Unit)</summary>
33 33 public string? LabelSizeText { get; set; }
34 34  
  35 + /// <summary>
  36 + /// 本次打印的内容快照(来自 fl_label_print_data,按 PrintTaskId 关联)
  37 + /// </summary>
  38 + public List<PrintLogDataItemDto> PrintDataList { get; set; } = new();
  39 +
35 40 /// <summary>打印时间(PrintedAt ?? CreationTime)</summary>
36 41 public DateTime PrintedAt { get; set; }
37 42  
... ... @@ -42,3 +47,15 @@ public class PrintLogItemDto
42 47 public string LocationName { get; set; } = "无";
43 48 }
44 49  
  50 +/// <summary>
  51 +/// 打印内容快照项(fl_label_print_data)
  52 +/// </summary>
  53 +public class PrintLogDataItemDto
  54 +{
  55 + public string ElementId { get; set; } = string.Empty;
  56 +
  57 + public string? RenderValue { get; set; }
  58 +
  59 + public object? RenderConfigJson { get; set; }
  60 +}
  61 +
... ...
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/UsAppLabelingAppService.cs
... ... @@ -780,6 +780,41 @@ public class UsAppLabelingAppService : ApplicationService, IUsAppLabelingAppServ
780 780  
781 781 var pageRows = await query.ToPageListAsync(input.SkipCount, input.MaxResultCount, total);
782 782  
  783 + var taskIds = pageRows.Select(x => x.Id).Where(x => !string.IsNullOrWhiteSpace(x)).Distinct().ToList();
  784 +
  785 + var dataRows = taskIds.Count == 0
  786 + ? new List<FlLabelPrintDataDbEntity>()
  787 + : await _dbContext.SqlSugarClient.Queryable<FlLabelPrintDataDbEntity>()
  788 + .Where(x => taskIds.Contains(x.PrintTaskId))
  789 + .ToListAsync();
  790 +
  791 + var dataMap = dataRows
  792 + .GroupBy(x => x.PrintTaskId)
  793 + .ToDictionary(
  794 + g => g.Key,
  795 + g => g.Select(d =>
  796 + {
  797 + object? cfg = null;
  798 + if (!string.IsNullOrWhiteSpace(d.RenderConfigJson))
  799 + {
  800 + try
  801 + {
  802 + cfg = JsonSerializer.Deserialize<object>(d.RenderConfigJson);
  803 + }
  804 + catch
  805 + {
  806 + cfg = null;
  807 + }
  808 + }
  809 +
  810 + return new PrintLogDataItemDto
  811 + {
  812 + ElementId = d.ElementId,
  813 + RenderValue = d.RenderValue,
  814 + RenderConfigJson = cfg
  815 + };
  816 + }).ToList());
  817 +
783 818 var items = pageRows.Select(x => new PrintLogItemDto
784 819 {
785 820 TaskId = x.Id,
... ... @@ -791,6 +826,7 @@ public class UsAppLabelingAppService : ApplicationService, IUsAppLabelingAppServ
791 826 ProductName = string.IsNullOrWhiteSpace(x.ProductName) ? "无" : x.ProductName.Trim(),
792 827 TypeName = x.TypeName ?? string.Empty,
793 828 LabelSizeText = FormatLabelSizeWithUnit(x.TemplateWidth, x.TemplateHeight, x.TemplateUnit),
  829 + PrintDataList = dataMap.TryGetValue(x.Id, out var list) ? list : new List<PrintLogDataItemDto>(),
794 830 PrintedAt = x.PrintedAt ?? x.CreationTime,
795 831 OperatorName = operatorName,
796 832 LocationName = locationName
... ...