From a4baaa73a80394707b9437478b205c4ed87de901 Mon Sep 17 00:00:00 2001
From: 李曜臣
Date: Mon, 30 Mar 2026 14:57:58 +0800
Subject: [PATCH] 模板与产品关联实现
---
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelTemplate/LabelTemplateCreateInputVo.cs | 6 ++++++
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelTemplate/LabelTemplateElementDto.cs | 3 +++
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelTemplate/LabelTemplateGetOutputDto.cs | 2 ++
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelTemplate/LabelTemplateProductDefaultDto.cs | 25 +++++++++++++++++++++++++
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/UsAppLabeling/UsAppLabelPreviewDto.cs | 12 ++++++++++++
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/DbModels/FlLabelTemplateElementDbEntity.cs | 3 +++
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/DbModels/FlLabelTemplateProductDefaultDbEntity.cs | 24 ++++++++++++++++++++++++
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelAppService.cs | 1 +
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelTemplateAppService.cs | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/UsAppLabelingAppService.cs | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----
项目相关文档/标签模块接口对接说明.md | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
11 files changed, 324 insertions(+), 14 deletions(-)
create mode 100644 美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelTemplate/LabelTemplateProductDefaultDto.cs
create mode 100644 美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/DbModels/FlLabelTemplateProductDefaultDbEntity.cs
diff --git a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelTemplate/LabelTemplateCreateInputVo.cs b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelTemplate/LabelTemplateCreateInputVo.cs
index 1a98451..cc34717 100644
--- a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelTemplate/LabelTemplateCreateInputVo.cs
+++ b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelTemplate/LabelTemplateCreateInputVo.cs
@@ -57,5 +57,11 @@ public class LabelTemplateCreateInputVo
///
[JsonPropertyName("appliedLocationIds")]
public List AppliedLocationIds { get; set; } = new();
+
+ ///
+ /// 模板与产品/标签类型绑定默认值
+ ///
+ [JsonPropertyName("templateProductDefaults")]
+ public List? TemplateProductDefaults { get; set; }
}
diff --git a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelTemplate/LabelTemplateElementDto.cs b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelTemplate/LabelTemplateElementDto.cs
index b1a8bf3..4e24238 100644
--- a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelTemplate/LabelTemplateElementDto.cs
+++ b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelTemplate/LabelTemplateElementDto.cs
@@ -13,6 +13,9 @@ public class LabelTemplateElementDto
[JsonPropertyName("type")]
public string ElementType { get; set; } = string.Empty;
+ [JsonPropertyName("elementName")]
+ public string ElementName { get; set; } = string.Empty;
+
[JsonPropertyName("x")]
public decimal PosX { get; set; }
diff --git a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelTemplate/LabelTemplateGetOutputDto.cs b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelTemplate/LabelTemplateGetOutputDto.cs
index 1187b11..b72cd37 100644
--- a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelTemplate/LabelTemplateGetOutputDto.cs
+++ b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelTemplate/LabelTemplateGetOutputDto.cs
@@ -29,5 +29,7 @@ public class LabelTemplateGetOutputDto
public List Elements { get; set; } = new();
public List AppliedLocationIds { get; set; } = new();
+
+ public List TemplateProductDefaults { get; set; } = new();
}
diff --git a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelTemplate/LabelTemplateProductDefaultDto.cs b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelTemplate/LabelTemplateProductDefaultDto.cs
new file mode 100644
index 0000000..1f4322b
--- /dev/null
+++ b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/LabelTemplate/LabelTemplateProductDefaultDto.cs
@@ -0,0 +1,25 @@
+using System.Text.Json.Serialization;
+
+namespace FoodLabeling.Application.Contracts.Dtos.LabelTemplate;
+
+///
+/// 模板与产品/标签类型绑定后的默认值行
+///
+public class LabelTemplateProductDefaultDto
+{
+ [JsonPropertyName("productId")]
+ public string ProductId { get; set; } = string.Empty;
+
+ [JsonPropertyName("labelTypeId")]
+ public string LabelTypeId { get; set; } = string.Empty;
+
+ ///
+ /// 默认值JSON(建议结构:{ "el-xxx": "默认值" })
+ ///
+ [JsonPropertyName("defaultValues")]
+ public object? DefaultValues { get; set; }
+
+ [JsonPropertyName("orderNum")]
+ public int OrderNum { get; set; }
+}
+
diff --git a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/UsAppLabeling/UsAppLabelPreviewDto.cs b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/UsAppLabeling/UsAppLabelPreviewDto.cs
index b9206a5..12a4f26 100644
--- a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/UsAppLabeling/UsAppLabelPreviewDto.cs
+++ b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application.Contracts/Dtos/UsAppLabeling/UsAppLabelPreviewDto.cs
@@ -1,3 +1,5 @@
+using System;
+using System.Collections.Generic;
using FoodLabeling.Application.Contracts.Dtos.Label;
namespace FoodLabeling.Application.Contracts.Dtos.UsAppLabeling;
@@ -7,6 +9,8 @@ namespace FoodLabeling.Application.Contracts.Dtos.UsAppLabeling;
///
public class UsAppLabelPreviewDto
{
+ public string LabelId { get; set; } = string.Empty;
+
public string LocationId { get; set; } = string.Empty;
public string LabelCode { get; set; } = string.Empty;
@@ -23,6 +27,8 @@ public class UsAppLabelPreviewDto
public string? LabelCategoryName { get; set; }
+ public DateTime? LabelLastEdited { get; set; }
+
///
/// 预览图(base64 png,可空;若为空,客户端可用 Template 自行渲染)
///
@@ -32,5 +38,11 @@ public class UsAppLabelPreviewDto
/// 预览模板结构(与 LabelCanvas/LabelPreviewOnly 结构尽量一致)
///
public LabelTemplatePreviewDto Template { get; set; } = new();
+
+ ///
+ /// 当前预览上下文(模板+产品+标签类型)命中的默认值配置。
+ /// 数据来源:fl_label_template_product_default.DefaultValuesJson
+ ///
+ public Dictionary? TemplateProductDefaultValues { get; set; }
}
diff --git a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/DbModels/FlLabelTemplateElementDbEntity.cs b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/DbModels/FlLabelTemplateElementDbEntity.cs
index f727092..c9f2f8f 100644
--- a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/DbModels/FlLabelTemplateElementDbEntity.cs
+++ b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/DbModels/FlLabelTemplateElementDbEntity.cs
@@ -14,6 +14,9 @@ public class FlLabelTemplateElementDbEntity
public string ElementType { get; set; } = string.Empty;
+ [SugarColumn(ColumnName = "ElementName")]
+ public string ElementName { get; set; } = string.Empty;
+
public decimal PosX { get; set; }
public decimal PosY { get; set; }
diff --git a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/DbModels/FlLabelTemplateProductDefaultDbEntity.cs b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/DbModels/FlLabelTemplateProductDefaultDbEntity.cs
new file mode 100644
index 0000000..9da371e
--- /dev/null
+++ b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/DbModels/FlLabelTemplateProductDefaultDbEntity.cs
@@ -0,0 +1,24 @@
+using SqlSugar;
+
+namespace FoodLabeling.Application.Services.DbModels;
+
+[SugarTable("fl_label_template_product_default")]
+public class FlLabelTemplateProductDefaultDbEntity
+{
+ [SugarColumn(IsPrimaryKey = true)]
+ public string Id { get; set; } = string.Empty;
+
+ public string TemplateId { get; set; } = string.Empty;
+
+ public string ProductId { get; set; } = string.Empty;
+
+ public string LabelTypeId { get; set; } = string.Empty;
+
+ ///
+ /// 默认值JSON(字符串保存)
+ ///
+ public string? DefaultValuesJson { get; set; }
+
+ public int OrderNum { get; set; }
+}
+
diff --git a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelAppService.cs b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelAppService.cs
index 178285c..74b1434 100644
--- a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelAppService.cs
+++ b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelAppService.cs
@@ -695,6 +695,7 @@ public class LabelAppService : ApplicationService, ILabelAppService
{
Id = el.ElementKey,
ElementType = el.ElementType,
+ ElementName = el.ElementName,
PosX = el.PosX,
PosY = el.PosY,
Width = el.Width,
diff --git a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelTemplateAppService.cs b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelTemplateAppService.cs
index 79e1e60..d713d61 100644
--- a/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelTemplateAppService.cs
+++ b/美国版/Food Labeling Management Code/Yi.Abp.Net8/module/food-labeling-us/FoodLabeling.Application/Services/LabelTemplateAppService.cs
@@ -157,6 +157,7 @@ public class LabelTemplateAppService : ApplicationService, ILabelTemplateAppServ
{
Id = e.ElementKey,
ElementType = e.ElementType,
+ ElementName = e.ElementName,
PosX = e.PosX,
PosY = e.PosY,
Width = e.Width,
@@ -180,6 +181,28 @@ public class LabelTemplateAppService : ApplicationService, ILabelTemplateAppServ
.Select(x => x.LocationId)
.ToListAsync();
+ var defaultRows = await _dbContext.SqlSugarClient.Queryable()
+ .Where(x => x.TemplateId == template.Id)
+ .OrderBy(x => x.OrderNum)
+ .ToListAsync();
+
+ var productDefaults = defaultRows.Select(x =>
+ {
+ object? defaults = null;
+ if (!string.IsNullOrWhiteSpace(x.DefaultValuesJson))
+ {
+ defaults = JsonSerializer.Deserialize