From 6f2f412a3ddf11af03d0efc1c002e2f261207fca Mon Sep 17 00:00:00 2001
From: kyy <3283105747@qq.com>
Date: 星期五, 29 八月 2025 12:03:38 +0800
Subject: [PATCH] 1、新增srm条码接收删除接口

---
 MES.Service/Dto/webApi/DeleteByDeliveryItemRequest.cs             |   22 +
 MES.Service/Modes/DeliveryBarcodeInformation.cs                   |  196 ++++++++++++++
 MES.Service/service/BasicData/DeliveryBarcodeManager.cs           |  291 ++++++++++++++++++++
 MES.Service/Dto/webApi/DeliveryBarcodeInfo.cs                     |   59 ++++
 MESApplication/Controllers/BasicData/DeliveryBarcodeController.cs |  256 ++++++++++++++++++
 MES.Service/Dto/webApi/DeleteByDeliveryNoRequest.cs               |   15 +
 6 files changed, 839 insertions(+), 0 deletions(-)

diff --git a/MES.Service/Dto/webApi/DeleteByDeliveryItemRequest.cs b/MES.Service/Dto/webApi/DeleteByDeliveryItemRequest.cs
new file mode 100644
index 0000000..ecb4e85
--- /dev/null
+++ b/MES.Service/Dto/webApi/DeleteByDeliveryItemRequest.cs
@@ -0,0 +1,22 @@
+锘縰sing System.ComponentModel.DataAnnotations;
+using MES.Service.Dto.webApi;
+
+namespace MES.Service.Dto.webApi;
+
+/// <summary>
+/// 鎸夐�佽揣鍗曞彿+琛屽唴鐮佸垹闄ゆ潯鐮佺殑璇锋眰妯″瀷
+/// </summary>
+public class DeleteByDeliveryItemRequest
+{
+    /// <summary>
+    /// 閫佽揣鍗曞彿锛堝繀濉紝涓嶈兘涓虹┖/绌哄瓧绗︿覆锛�
+    /// </summary>
+    [Required(ErrorMessage = "閫佽揣鍗曞彿 DeliveryNo 涓嶈兘涓虹┖")]
+    public string DeliveryNo { get; set; }
+
+    /// <summary>
+    /// 閫佽揣鍗曡鍐呯爜锛堝繀濉紝涓嶈兘涓虹┖/绌哄瓧绗︿覆锛�
+    /// </summary>
+    [Required(ErrorMessage = "閫佽揣鍗曡鍐呯爜 LineNo 涓嶈兘涓虹┖")]
+    public string LineNo { get; set; }
+}
\ No newline at end of file
diff --git a/MES.Service/Dto/webApi/DeleteByDeliveryNoRequest.cs b/MES.Service/Dto/webApi/DeleteByDeliveryNoRequest.cs
new file mode 100644
index 0000000..4c6a00a
--- /dev/null
+++ b/MES.Service/Dto/webApi/DeleteByDeliveryNoRequest.cs
@@ -0,0 +1,15 @@
+锘縰sing System.ComponentModel.DataAnnotations;
+
+namespace MES.Service.Dto.webApi;
+
+/// <summary>
+/// 鏍规嵁閫佽揣鍗曞彿鍒犻櫎鏉$爜鐨勮姹傛ā鍨�
+/// </summary>
+public class DeleteByDeliveryNoRequest
+{
+    /// <summary>
+    /// 閫佽揣鍗曞彿锛堝繀濉紝涓嶈兘涓虹┖/绌哄瓧绗︿覆锛�
+    /// </summary>
+    [Required(ErrorMessage = "閫佽揣鍗曞彿 DeliveryNo 涓嶈兘涓虹┖")]
+    public string DeliveryNo { get; set; }
+}
\ No newline at end of file
diff --git a/MES.Service/Dto/webApi/DeliveryBarcodeInfo.cs b/MES.Service/Dto/webApi/DeliveryBarcodeInfo.cs
new file mode 100644
index 0000000..852c235
--- /dev/null
+++ b/MES.Service/Dto/webApi/DeliveryBarcodeInfo.cs
@@ -0,0 +1,59 @@
+锘縩amespace MES.Service.Dto.webApi;
+
+public class DeliveryBarcodeInfo
+{
+    /// <summary>
+    /// 閫佽揣鍗曞彿
+    /// </summary>
+    public string? DeliveryNo { get; set; }
+    
+    /// <summary>
+    /// 閫佽揣鍗曡鍐呯爜
+    /// </summary>
+    public string? LineNo { get; set; }
+    
+    /// <summary>
+    /// 鐗╂枡鏉$爜
+    /// </summary>
+    public string? SmallBarcode { get; set; }
+    
+    /// <summary>
+    /// 鐗╂枡鍐呯爜
+    /// </summary>
+    public string? ProductCode { get; set; }
+    
+    /// <summary>
+    /// 鏉$爜鏁伴噺
+    /// </summary>
+    public decimal? IncludeQty { get; set; }
+    
+    /// <summary>
+    /// 绠辨潯鐮�
+    /// </summary>
+    public string? OuterBarcode { get; set; }
+    
+    /// <summary>
+    /// 鏉$爜绫诲瀷
+    /// </summary>
+    public string? BarcodeType { get; set; }
+    
+    /// <summary>
+    /// 鏄惁鍚堝苟
+    /// </summary>
+    public bool? IsMerge { get; set; }
+    
+    /// <summary>
+    /// 鎺ュ彛绫诲瀷
+    /// </summary>
+    public string? Type { get; set; }
+    
+    /// <summary>
+    /// 鏄惁灏剧
+    /// </summary>
+    public bool? IsLast { get; set; }
+    
+    /// <summary>
+    /// 绠辫鏁�
+    /// </summary>
+    public int? PackingQty { get; set; }
+}
\ No newline at end of file
diff --git a/MES.Service/Modes/DeliveryBarcodeInformation.cs b/MES.Service/Modes/DeliveryBarcodeInformation.cs
new file mode 100644
index 0000000..d76aeca
--- /dev/null
+++ b/MES.Service/Modes/DeliveryBarcodeInformation.cs
@@ -0,0 +1,196 @@
+锘縰sing SqlSugar;
+
+namespace MES.Service.Modes;
+
+/// <summary>
+///     鎼哄浜戞潯鐮佷俊鎭〃
+/// </summary>
+[SugarTable("TBL_BARCODE_INFORMATION")]
+public class BarcodeInformation
+{
+    /// <summary>
+    ///     SEQ_XKY
+    /// </summary>
+    [SugarColumn(ColumnName = "id", IsPrimaryKey = true)]
+    public Guid Id { get; set; }
+
+    /// <summary>
+    ///     浜у搧缂栫爜
+    /// </summary>
+    [SugarColumn(ColumnName = "product_code")]
+    public string? ProductCode { get; set; }
+
+    /// <summary>
+    ///     灏忓寘鏉$爜
+    /// </summary>
+    [SugarColumn(ColumnName = "small_barcode")]
+    public string? SmallBarcode { get; set; }
+
+    /// <summary>
+    ///     澶у寘鏉$爜
+    /// </summary>
+    [SugarColumn(ColumnName = "big_barcode")]
+    public string? BigBarcode { get; set; }
+
+    /// <summary>
+    ///     澶栫鏉$爜
+    /// </summary>
+    [SugarColumn(ColumnName = "outer_barcode")]
+    public string? OuterBarcode { get; set; }
+
+    /// <summary>
+    ///     褰撳墠灏忓寘鏉$爜鍖呭惈鐨勬暟閲�
+    /// </summary>
+    [SugarColumn(ColumnName = "include_qty")]
+    public decimal? IncludeQty { get; set; }
+
+    /// <summary>
+    ///     灏忓寘鏉$爜-闀�
+    /// </summary>
+    [SugarColumn(ColumnName = "small_package_length")]
+    public string? SmallPackageLength { get; set; }
+
+    /// <summary>
+    ///     灏忓寘鏉$爜-瀹�
+    /// </summary>
+    [SugarColumn(ColumnName = "small_package_width")]
+    public string? SmallPackageWidth { get; set; }
+
+    /// <summary>
+    ///     灏忓寘鏉$爜-楂�
+    /// </summary>
+    [SugarColumn(ColumnName = "small_package_height")]
+    public string? SmallPackageHeight { get; set; }
+
+    /// <summary>
+    ///     澶у寘鏉$爜-闀�
+    /// </summary>
+    [SugarColumn(ColumnName = "big_package_length")]
+    public string? BigPackageLength { get; set; }
+
+    /// <summary>
+    ///     澶у寘鏉$爜-瀹�
+    /// </summary>
+    [SugarColumn(ColumnName = "big_package_width")]
+    public string? BigPackageWidth { get; set; }
+
+    /// <summary>
+    ///     澶у寘鏉$爜-楂�
+    /// </summary>
+    [SugarColumn(ColumnName = "big_package_height")]
+    public string? BigPackageHeight { get; set; }
+
+    /// <summary>
+    ///     澶栫鏉$爜-闀�
+    /// </summary>
+    [SugarColumn(ColumnName = "outer_package_length")]
+    public string? OuterPackageLength { get; set; }
+
+    /// <summary>
+    ///     澶栫鏉$爜-瀹�
+    /// </summary>
+    [SugarColumn(ColumnName = "outer_package_width")]
+    public string? OuterPackageWidth { get; set; }
+
+    /// <summary>
+    ///     澶栫鏉$爜-楂�
+    /// </summary>
+    [SugarColumn(ColumnName = "outer_package_height")]
+    public string? OuterPackageHeight { get; set; }
+
+    /// <summary>
+    ///     褰撳墠灏忓寘鏉$爜鐨勬祦姘寸爜
+    /// </summary>
+    [SugarColumn(ColumnName = "small_package_sn")]
+    public string? SmallPackageSn { get; set; }
+
+    /// <summary>
+    ///     褰撳墠澶у寘鏉$爜鐨勬祦姘寸爜
+    /// </summary>
+    [SugarColumn(ColumnName = "big_package_sn")]
+    public string? BigPackageSn { get; set; }
+
+    /// <summary>
+    ///     褰撳墠澶栫鏉$爜鐨勬祦姘寸爜
+    /// </summary>
+    [SugarColumn(ColumnName = "out_package_sn")]
+    public string? OutPackageSn { get; set; }
+
+    /// <summary>
+    ///     鏉$爜瑙勫垯涓搴旂殑鍔ㄦ�佸瓧娈电殑鍊�
+    /// </summary>
+    [SugarColumn(ColumnName = "dynamic_data")]
+    public string? DynamicData { get; set; }
+
+    /// <summary>
+    ///     鍖呰灞傜骇
+    /// </summary>
+    [SugarColumn(ColumnName = "pack_level")]
+    public string? PackLevel { get; set; }
+
+    /// <summary>
+    ///     鍒涘缓鏃堕棿
+    /// </summary>
+    [SugarColumn(ColumnName = "create_time")]
+    public DateTime? CreateTime { get; set; }
+
+    /// <summary>
+    ///     鏇存柊鏃堕棿
+    /// </summary>
+    [SugarColumn(ColumnName = "update_time")]
+    public DateTime? UpdateTime { get; set; }
+
+    /// <summary>
+    ///     閫佽揣鍗曞彿
+    /// </summary>
+    [SugarColumn(ColumnName = "delivery_no")]
+    public string? DeliveryNo { get; set; }
+
+    /// <summary>
+    ///     閲囪喘鍗曞彿
+    /// </summary>
+    [SugarColumn(ColumnName = "po_erp_no")]
+    public string? PoErpNo { get; set; }
+
+    /// <summary>
+    ///     閫佽揣鍗曢」娆�
+    /// </summary>
+    [SugarColumn(ColumnName = "dnLines")]
+    public string? DnLines { get; set; }
+
+    /// <summary>
+    ///     璁㈠崟椤规(ERP)
+    /// </summary>
+    [SugarColumn(ColumnName = "po_line_no")]
+    public string? PoLineNo { get; set; }
+
+    /// <summary>
+    ///     渚涘簲鍟嗙紪鐮�
+    /// </summary>
+    [SugarColumn(ColumnName = "inner_vendor_code")]
+    public string? InnerVendorCode { get; set; }
+
+    /// <summary>
+    ///     X
+    /// </summary>
+    [SugarColumn(ColumnName = "customize1")]
+    public string? Customize1 { get; set; }
+
+    /// <summary>
+    ///     鍚屾鏃堕棿
+    /// </summary>
+    [SugarColumn(ColumnName = "SYNCHRONOUS_DATE")]
+    public DateTime? SynchronousDate { get; set; }
+
+    /// <summary>
+    ///     鐢熶骇鏃ユ湡
+    /// </summary>
+    [SugarColumn(ColumnName = "customize2")]
+    public string? Customize2 { get; set; }
+
+    /// <summary>
+    ///     鏈夋晥鏈�
+    /// </summary>
+    [SugarColumn(ColumnName = "customize3")]
+    public string? Customize3 { get; set; }
+}
\ No newline at end of file
diff --git a/MES.Service/service/BasicData/DeliveryBarcodeManager.cs b/MES.Service/service/BasicData/DeliveryBarcodeManager.cs
new file mode 100644
index 0000000..515e5fb
--- /dev/null
+++ b/MES.Service/service/BasicData/DeliveryBarcodeManager.cs
@@ -0,0 +1,291 @@
+锘縰sing MES.Service.DB;
+using MES.Service.Dto.webApi;
+using MES.Service.Modes;
+using System.Linq;
+
+namespace MES.Service.service.BasicData;
+
+/// <summary>
+/// 閫佽揣鍗曟潯鐮佷笟鍔$鐞嗗櫒锛堝搴擳BL_BARCODE_INFORMATION琛ㄦ搷浣滐級
+/// </summary>
+public class DeliveryBarcodeManager : Repository<BarcodeInformation>
+{
+    /// <summary>
+    /// 鍗曚釜閫佽揣鍗曟潯鐮佷俊鎭繚瀛橈紙鏀寔鏂板/鍒犻櫎锛屾寜Type鍖哄垎鎿嶄綔绫诲瀷锛�
+    /// </summary>
+    /// <param name="barcodeDto">閫佽揣鍗曟潯鐮丏TO锛堝惈鎿嶄綔绫诲瀷Type锛�</param>
+    /// <returns>鎿嶄綔鏄惁鎴愬姛</returns>
+    public bool Save(DeliveryBarcodeInfo barcodeDto)
+    {
+        if (barcodeDto == null)
+            throw new ArgumentNullException(nameof(barcodeDto), "鏉$爜DTO涓嶈兘涓虹┖");
+
+        // DTO杞疄浣擄紙鏄犲皠瀛楁鍏崇郴锛�
+        var barcodeEntity = ConvertDtoToEntity(barcodeDto);
+
+        try
+        {
+            // 鎸塗ype鍖哄垎鎿嶄綔绫诲瀷锛�0=鏂板锛�1=鍒犻櫎锛�
+            switch (barcodeDto.Type)
+            {
+                case "0":
+                    return InsertBarcode(barcodeEntity);
+                case "1":
+                    return DeleteBarcode(barcodeEntity.Id);
+                default:
+                    throw new ArgumentOutOfRangeException(
+                        nameof(barcodeDto.Type), 
+                        barcodeDto.Type, 
+                        "鏉$爜鎿嶄綔绫诲瀷閿欒锛氫粎鏀寔 0锛堟柊澧烇級銆�1锛堝垹闄わ級");
+            }
+        }
+        catch (Exception ex)
+        {
+            throw new ApplicationException($"鍗曚釜鏉$爜鎿嶄綔澶辫触锛堥�佽揣鍗曞彿锛歿barcodeDto.DeliveryNo}锛夛細{ex.Message}", ex);
+        }
+    }
+
+    /// <summary>
+    /// 鎵归噺閫佽揣鍗曟潯鐮佷俊鎭繚瀛橈紙鎸塗ype鍒嗙粍澶勭悊锛岀粺涓�寮傚父鎹曡幏锛�
+    /// </summary>
+    /// <param name="barcodeDtoList">閫佽揣鍗曟潯鐮丏TO鍒楄〃</param>
+    /// <returns>鎵归噺鎿嶄綔鏄惁鍏ㄩ儴鎴愬姛</returns>
+    public bool SaveList(List<DeliveryBarcodeInfo> barcodeDtoList)
+    {
+        if (barcodeDtoList == null || !barcodeDtoList.Any())
+        {
+            throw new ArgumentException("鎵归噺鎿嶄綔鐨勬潯鐮佸垪琛ㄤ笉鑳戒负绌�");
+        }
+
+        try
+        {
+            // 1. 鍒涘缓寮虹被鍨嬬殑瀹炰綋涓庣被鍨嬬粍鍚堝垪琛紙瑙e喅dynamic杞崲闂锛�
+            var entityTypePairs = new List<EntityTypePair>();
+            foreach (var dto in barcodeDtoList)
+            {
+                entityTypePairs.Add(new EntityTypePair
+                {
+                    Entity = ConvertDtoToEntity(dto),
+                    Type = dto.Type
+                });
+            }
+
+            // 2. 鎸夋搷浣滅被鍨婽ype鍒嗙粍锛堜娇鐢ㄥ己绫诲瀷閬垮厤绫诲瀷鎺ㄦ柇闂锛�
+            var typeGroupDict = entityTypePairs
+                .GroupBy(pair => pair.Type)
+                .ToDictionary(
+                    group => group.Key, 
+                    group => group.Select(pair => pair.Entity).ToList()
+                );
+
+            // 3. 瀛樺偍鍚勭粍鎿嶄綔缁撴灉
+            var groupResultList = new List<bool>();
+
+            foreach (var (type, entityGroup) in typeGroupDict)
+            {
+                switch (type)
+                {
+                    case "0":
+                        groupResultList.Add(InsertBarcodeBatch(entityGroup));
+                        break;
+                    case "1":
+                        groupResultList.Add(DeleteBarcodeBatch(entityGroup.Select(e => e.Id).ToArray()));
+                        break;
+                    default:
+                        throw new ArgumentOutOfRangeException(
+                            nameof(type), 
+                            type, 
+                            "鎵归噺鎿嶄綔涓瓨鍦ㄩ潪娉昑ype锛氫粎鏀寔 0锛堟柊澧烇級銆�1锛堝垹闄わ級");
+                }
+            }
+
+            // 4. 鎵�鏈夊垎缁勬搷浣滃潎鎴愬姛鎵嶇畻鎵归噺鎴愬姛
+            if (groupResultList.All(result => result))
+            {
+                return true;
+            }
+
+            throw new NotImplementedException("鎵归噺鏉$爜鎿嶄綔閮ㄥ垎澶辫触锛屽叿浣撹鏌ョ湅鏃ュ織");
+        }
+        catch (Exception ex)
+        {
+            throw new ApplicationException($"鎵归噺鏉$爜鎿嶄綔澶辫触锛堟�绘潯鏁帮細{barcodeDtoList.Count}锛夛細{ex.Message}", ex);
+        }
+    }
+    
+    /// <summary>
+    /// 鏍规嵁閫佽揣鍗曞彿鍒犻櫎鏉$爜鏁版嵁
+    /// </summary>
+    /// <param name="deliveryNo">閫佽揣鍗曞彿锛堜笉鑳戒负绌�/绌哄瓧绗︿覆锛�</param>
+    /// <returns>鏄惁鍒犻櫎鎴愬姛锛坱rue=鑷冲皯鍒犻櫎1鏉★紝false=鏈壘鍒板搴旀暟鎹級</returns>
+    public bool DeleteByDeliveryNo(string deliveryNo)
+    {
+        // 1. 鏍¢獙鍙傛暟锛氶�佽揣鍗曞彿涓嶈兘涓虹┖
+        if (string.IsNullOrWhiteSpace(deliveryNo))
+            throw new ArgumentException("閫佽揣鍗曞彿 DeliveryNo 涓嶈兘涓虹┖鎴栫┖鏍�", nameof(deliveryNo));
+
+        try
+        {
+            // 2. 鎵ц鍒犻櫎锛氭牴鎹� DeliveryNo 鍖归厤琛ㄤ腑鏁版嵁锛堝搴斿疄浣撶殑 DeliveryNo 瀛楁锛�
+            int deletedCount = Db.Deleteable<BarcodeInformation>()
+                .Where(barcode => barcode.DeliveryNo == deliveryNo) // 琛ㄥ瓧娈典笌閫佽揣鍗曞彿鍖归厤
+                .ExecuteCommand(); // 杩斿洖鍙楀奖鍝嶇殑琛屾暟
+
+            // 3. 鍒ゆ柇缁撴灉锛氳嚦灏戝垹闄�1鏉″垯瑙嗕负鎴愬姛锛屽惁鍒欐姏鍑衡�滄湭鎵惧埌鏁版嵁鈥濆紓甯�
+            if (deletedCount > 0)
+                return true;
+
+            throw new KeyNotFoundException($"鏈壘鍒伴�佽揣鍗曞彿涓恒�寋deliveryNo}銆嶇殑鏉$爜鏁版嵁锛屽垹闄ゆ搷浣滄湭鎵ц");
+        }
+        catch (Exception ex)
+        {
+            // 4. 鍖呰涓氬姟寮傚父锛岃ˉ鍏呬笂涓嬫枃淇℃伅
+            throw new ApplicationException($"鏍规嵁閫佽揣鍗曞彿鍒犻櫎鏉$爜鏁版嵁澶辫触锛圖eliveryNo锛歿deliveryNo}锛夛細{ex.Message}", ex);
+        }
+    }
+    
+    /// <summary>
+    /// 鎸夐�佽揣鍗曞彿+琛屽唴鐮佽仈鍚堝垹闄ゆ潯鐮佹暟鎹�
+    /// </summary>
+    /// <param name="deliveryNo">閫佽揣鍗曞彿</param>
+    /// <param name="lineNo">閫佽揣鍗曡鍐呯爜</param>
+    /// <returns>鏄惁鍒犻櫎鎴愬姛锛坱rue=鑷冲皯鍒犻櫎1鏉★紝false=鏈壘鍒板搴旀暟鎹級</returns>
+    public bool DeleteByDeliveryItem(string deliveryNo, string lineNo)
+    {
+        // 1. 鍙屽弬鏁版牎楠岋細閬垮厤绌哄��/绌哄瓧绗︿覆
+        if (string.IsNullOrWhiteSpace(deliveryNo))
+            throw new ArgumentException("閫佽揣鍗曞彿 DeliveryNo 涓嶈兘涓虹┖鎴栫┖鏍�", nameof(deliveryNo));
+        if (string.IsNullOrWhiteSpace(lineNo))
+            throw new ArgumentException("閫佽揣鍗曡鍐呯爜 LineNo 涓嶈兘涓虹┖鎴栫┖鏍�", nameof(lineNo));
+
+        try
+        {
+            // 2. 鑱斿悎鏉′欢鍒犻櫎锛氬尮閰� DeliveryNo锛堥�佽揣鍗曞彿锛夊拰 DnLines锛堣鍐呯爜锛屽疄浣撳瓧娈靛搴旇〃鐨� dnLines 鍒楋級
+            int deletedCount = Db.Deleteable<BarcodeInformation>()
+                .Where(barcode => 
+                        barcode.DeliveryNo == deliveryNo // 鍖归厤閫佽揣鍗曞彿
+                        && barcode.DnLines == lineNo     // 鍖归厤琛屽唴鐮侊紙瀹炰綋 DnLines 瀵瑰簲琛� dnLines 瀛楁锛�
+                )
+                .ExecuteCommand(); // 杩斿洖鍙楀奖鍝嶇殑琛屾暟
+
+            // 3. 缁撴灉鍒ゆ柇锛氭湁鏁版嵁琚垹闄ゅ垯鎴愬姛锛屽惁鍒欐姏鈥滄湭鎵惧埌鏁版嵁鈥濆紓甯�
+            if (deletedCount > 0)
+                return true;
+
+            throw new KeyNotFoundException(
+                $"鏈壘鍒伴�佽揣鍗曞彿銆寋deliveryNo}銆嶄笖琛屽唴鐮併�寋lineNo}銆嶅搴旂殑鏉$爜鏁版嵁锛屽垹闄ゆ搷浣滄湭鎵ц");
+        }
+        catch (Exception ex)
+        {
+            // 4. 鍖呰寮傚父锛氳ˉ鍏呰仈鍚堟潯浠朵笂涓嬫枃锛屼究浜庡畾浣嶉棶棰�
+            throw new ApplicationException(
+                $"鎸夐�佽揣鍗曞彿+琛屽唴鐮佸垹闄ゆ潯鐮佹暟鎹け璐ワ紙DeliveryNo锛歿deliveryNo}锛孡ineNo锛歿lineNo}锛夛細{ex.Message}", 
+                ex);
+        }
+    }
+    #region 绉佹湁杈呭姪鏂规硶鍜屽唴閮ㄧ被
+    /// <summary>
+    /// 鍐呴儴杈呭姪绫伙細鐢ㄤ簬鍏宠仈瀹炰綋鍜屾搷浣滅被鍨嬶紙瑙e喅dynamic绫诲瀷杞崲闂锛�
+    /// </summary>
+    private class EntityTypePair
+    {
+        public BarcodeInformation Entity { get; set; }
+        public string Type { get; set; }
+    }
+
+    /// <summary>
+    /// DTO杞疄浣擄細鏄犲皠DeliveryBarcodeInfo鍒癇arcodeInformation瀛楁
+    /// </summary>
+    private BarcodeInformation ConvertDtoToEntity(DeliveryBarcodeInfo dto)
+    {
+        var entityId = dto.Type == "0" 
+            ? Guid.NewGuid() 
+            : (string.IsNullOrEmpty(dto.SmallBarcode) ? Guid.Empty : Guid.Parse(dto.SmallBarcode));
+
+        return new BarcodeInformation
+        {
+            Id = entityId,
+            ProductCode = dto.ProductCode,
+            SmallBarcode = dto.SmallBarcode,
+            OuterBarcode = dto.OuterBarcode,
+            IncludeQty = dto.IncludeQty.HasValue ? Convert.ToDecimal(dto.IncludeQty) : 0,
+            DeliveryNo = dto.DeliveryNo,
+            DnLines = dto.LineNo,
+            PackLevel = dto.BarcodeType,
+            CreateTime = dto.Type == "0" ? DateTime.Now : (DateTime?)null,
+            UpdateTime = DateTime.Now,
+            
+            // 鎵╁睍瀛楁璧嬮粯璁ゅ��
+            BigBarcode = null,
+            SmallPackageLength = null,
+            SmallPackageWidth = null,
+            SmallPackageHeight = null,
+            BigPackageLength = null,
+            BigPackageWidth = null,
+            BigPackageHeight = null,
+            OuterPackageLength = null,
+            OuterPackageWidth = null,
+            OuterPackageHeight = null,
+            SmallPackageSn = null,
+            BigPackageSn = null,
+            OutPackageSn = null,
+            DynamicData = null,
+            PoErpNo = null,
+            PoLineNo = null,
+            InnerVendorCode = null,
+            Customize1 = null,
+            SynchronousDate = null,
+            Customize2 = null,
+            Customize3 = null
+        };
+    }
+
+    /// <summary>
+    /// 鍗曚釜鏉$爜鏂板
+    /// </summary>
+    private bool InsertBarcode(BarcodeInformation entity)
+    {
+        var isInsertSuccess = base.Insert(entity);
+        return isInsertSuccess ? true : throw new NotImplementedException("鏉$爜鏂板澶辫触锛氭暟鎹簱鎻掑叆鎿嶄綔鏈墽琛屾垚鍔�");
+    }
+
+    /// <summary>
+    /// 鍗曚釜鏉$爜鍒犻櫎锛堟寜涓婚敭Id锛�
+    /// </summary>
+    private bool DeleteBarcode(Guid id)
+    {
+        if (id == Guid.Empty)
+            throw new ArgumentException("鍒犻櫎鎿嶄綔鐨勬潯鐮両d涓嶈兘涓虹┖");
+
+        var deleteRowCount = Db.Deleteable<BarcodeInformation>()
+            .Where(entity => entity.Id == id)
+            .ExecuteCommand();
+
+        return deleteRowCount > 0 ? true : throw new NotImplementedException($"鏉$爜鍒犻櫎澶辫触锛氭湭鎵惧埌Id涓恒�寋id}銆嶇殑鏉$爜璁板綍");
+    }
+
+    /// <summary>
+    /// 鎵归噺鏉$爜鏂板
+    /// </summary>
+    private bool InsertBarcodeBatch(List<BarcodeInformation> entityList)
+    {
+        var isBatchInsertSuccess = base.InsertRange(entityList);
+        return isBatchInsertSuccess ? true : throw new NotImplementedException($"鎵归噺鏉$爜鏂板澶辫触锛氬叡{entityList.Count}鏉¤褰�");
+    }
+
+    /// <summary>
+    /// 鎵归噺鏉$爜鍒犻櫎锛堟寜涓婚敭Id鏁扮粍锛�
+    /// </summary>
+    private bool DeleteBarcodeBatch(Guid[] ids)
+    {
+        if (ids == null || ids.Length == 0)
+            throw new ArgumentException("鎵归噺鍒犻櫎鐨勬潯鐮両d鏁扮粍涓嶈兘涓虹┖");
+
+        var deleteRowCount = Db.Deleteable<BarcodeInformation>()
+            .Where(entity => ids.Contains(entity.Id))
+            .ExecuteCommand();
+
+        return deleteRowCount > 0 ? true : throw new NotImplementedException($"鎵归噺鏉$爜鍒犻櫎澶辫触锛氬叡{ids.Length}涓狪d");
+    }
+    #endregion
+}
diff --git a/MESApplication/Controllers/BasicData/DeliveryBarcodeController.cs b/MESApplication/Controllers/BasicData/DeliveryBarcodeController.cs
new file mode 100644
index 0000000..e7a0768
--- /dev/null
+++ b/MESApplication/Controllers/BasicData/DeliveryBarcodeController.cs
@@ -0,0 +1,256 @@
+锘縰sing System.Dynamic;
+using MES.Service.Dto.webApi;
+using MES.Service.Modes;
+using MES.Service.service;
+using MES.Service.service.BasicData; // 鍋囪DeliveryBarcodeManager鍦ㄨ鍛藉悕绌洪棿涓嬶紝鍙牴鎹疄闄呰皟鏁�
+using MES.Service.util;
+using Microsoft.AspNetCore.Mvc;
+using Newtonsoft.Json;
+
+namespace MESApplication.Controllers.BasicData;
+
+/// <summary>
+/// 閫佽揣鍗曟潯鐮佹帶鍒跺櫒锛堝搴旀惡瀹簯鏉$爜淇℃伅琛ㄦ搷浣滐級
+/// </summary>
+[ApiController]
+[Route("api/[controller]")]
+public class DeliveryBarcodeController : ControllerBase
+{
+    // 娑堟伅涓績绠$悊鍣紙澶嶇敤鍘熼�昏緫锛�
+    private readonly MessageCenterManager _messageCenterManager = new();
+
+    // 閫佽揣鍗曟潯鐮佷笟鍔¢�昏緫绠$悊鍣紙瀵瑰簲涓氬姟灞傦紝闇�纭繚瀹為檯椤圭洰涓瓨鍦ㄨ绫伙級
+    private readonly DeliveryBarcodeManager _deliveryBarcodeManager = new();
+
+    // 鎺ュ彛璇锋眰鏂规硶锛堝浐瀹歅OST锛屼笌鍘熸帶鍒跺櫒涓�鑷达級
+    private readonly string REQUEST_METHOD = "POST";
+
+    // 瀵瑰簲鏁版嵁搴撹〃鍚嶏紙鎼哄浜戞潯鐮佷俊鎭〃锛屼笌涔嬪墠瀹氫箟鐨勫疄浣撶被琛ㄥ悕涓�鑷达級
+    private readonly string TARGET_TABLE = "TBL_BARCODE_INFORMATION";
+
+    // 鍩虹鎺ュ彛URL锛堟牴鎹帶鍒跺櫒鍚嶅畾涔夛紝淇濇寔REST椋庢牸锛�
+    private readonly string BASE_API_URL = "http://localhost:10054/api/DeliveryBarcode/";
+
+    /// <summary>
+    /// 鍗曚釜閫佽揣鍗曟潯鐮佷俊鎭繚瀛樻帴鍙�
+    /// </summary>
+    /// <param name="barcodeInfo">閫佽揣鍗曟潯鐮丏TO锛堝崟涓級</param>
+    /// <returns>缁熶竴鍝嶅簲缁撴灉</returns>
+    [HttpPost("Save")]
+    public ResponseResult Save(DeliveryBarcodeInfo barcodeInfo)
+    {
+        // 1. 鍒濆鍖栨秷鎭腑蹇冨疄浣擄紙鐢ㄤ簬鏃ュ織/娑堟伅璁板綍锛�
+        var messageEntity = new MessageCenter
+        {
+            TableName = TARGET_TABLE,
+            Url = BASE_API_URL + "Save", // 鎷兼帴瀹屾暣鎺ュ彛URL
+            Method = REQUEST_METHOD,
+            Data = JsonConvert.SerializeObject(barcodeInfo), // 搴忓垪鍖朌TO涓篔SON
+            Status = 1, // 鐘舵�佹爣璇嗭紙1=寰呭鐞�/澶勭悊涓紝涓庡師閫昏緫涓�鑷达級
+            CreateBy = "PL017", // 鍒涘缓浜猴紙澶嶇敤鍘熼厤缃紝鍙牴鎹疄闄呰皟鏁翠负鍔ㄦ�佽幏鍙栵級
+            Route = barcodeInfo.DeliveryNo ?? "鏈煡閫佽揣鍗曞彿", // 璺敱鏍囪瘑锛堢敤閫佽揣鍗曞彿鍖哄垎锛屾棤鍒欏~榛樿鍊硷級
+            DealWith = 0 // 鍒濆澶勭悊鐘舵�侊紙0=鏈鐞嗭級
+        };
+
+        try
+        {
+            // 2. 涓氬姟閫昏緫澶勭悊锛氳皟鐢ㄤ笟鍔″眰淇濆瓨鍗曚釜鏉$爜淇℃伅
+            dynamic resultData = new ExpandoObject();
+            bool saveSuccess = _deliveryBarcodeManager.Save(barcodeInfo);
+            resultData.tbBillList = saveSuccess; // 瀛樺偍淇濆瓨缁撴灉锛堜笌鍘熻繑鍥炴牸寮忎竴鑷达級
+
+            // 3. 鏇存柊娑堟伅涓績瀹炰綋鐘舵��
+            messageEntity.Result = saveSuccess ? 1 : 0; // 1=鎴愬姛锛�0=澶辫触
+            messageEntity.DealWith = 1; // 1=宸插鐞�
+            _messageCenterManager.save(messageEntity); // 淇濆瓨娑堟伅璁板綍
+
+            // 4. 杩斿洖鎴愬姛鍝嶅簲锛堢粺涓�鍝嶅簲鏍煎紡锛�
+            return new ResponseResult
+            {
+                status = 0, // 0=鎴愬姛鐘舵�佺爜锛堜笌鍘熼�昏緫涓�鑷达級
+                message = "鍗曚釜閫佽揣鍗曟潯鐮佷俊鎭繚瀛樻垚鍔�",
+                data = resultData
+            };
+        }
+        catch (Exception ex)
+        {
+            // 5. 寮傚父澶勭悊锛氭崟鑾峰紓甯稿苟鏇存柊娑堟伅涓績
+            messageEntity.Result = 0; // 澶辫触鏍囪瘑
+            messageEntity.DealWith = 0; // 鏈鐞嗘爣璇�
+            messageEntity.ResultData = ex.Message; // 寮傚父淇℃伅璁板綍
+            _messageCenterManager.save(messageEntity); // 淇濆瓨寮傚父娑堟伅
+
+            // 6. 杩斿洖寮傚父鍝嶅簲锛堝鐢ㄥ伐鍏风被鐨勭粺涓�寮傚父鍝嶅簲鏂规硶锛�
+            return ResponseResult.ResponseError(ex);
+        }
+    }
+
+    /// <summary>
+    /// 鎵归噺閫佽揣鍗曟潯鐮佷俊鎭繚瀛樻帴鍙�
+    /// </summary>
+    /// <param name="barcodeInfoList">閫佽揣鍗曟潯鐮丏TO鍒楄〃锛堟壒閲忥級</param>
+    /// <returns>缁熶竴鍝嶅簲缁撴灉</returns>
+    [HttpPost("SaveList")]
+    public ResponseResult SaveList(List<DeliveryBarcodeInfo> barcodeInfoList)
+    {
+        // 1. 鍒濆鍖栨秷鎭腑蹇冨疄浣擄紙鎵归噺鍦烘櫙涓撶敤锛�
+        var messageEntity = new MessageCenter
+        {
+            TableName = TARGET_TABLE,
+            Url = BASE_API_URL + "SaveList", // 鎷兼帴鎵归噺鎺ュ彛URL
+            Method = REQUEST_METHOD,
+            Data = JsonConvert.SerializeObject(barcodeInfoList), // 搴忓垪鍖朌TO鍒楄〃涓篔SON
+            Status = 1,
+            CreateBy = "PL017",
+            Route = barcodeInfoList.Any() ? $"鎵归噺_{barcodeInfoList.First().DeliveryNo ?? "鏈煡"}" : "绌烘壒閲忚姹�",
+            DealWith = 0
+        };
+
+        try
+        {
+            // 2. 涓氬姟閫昏緫澶勭悊锛氳皟鐢ㄤ笟鍔″眰鎵归噺淇濆瓨
+            dynamic resultData = new ExpandoObject();
+            bool batchSaveSuccess = _deliveryBarcodeManager.SaveList(barcodeInfoList);
+            resultData.tbBillList = batchSaveSuccess; // 淇濇寔涓庡崟涓繚瀛樹竴鑷寸殑杩斿洖瀛楁
+
+            // 3. 鏇存柊娑堟伅涓績鐘舵��
+            messageEntity.Result = batchSaveSuccess ? 1 : 0;
+            messageEntity.DealWith = 1;
+            _messageCenterManager.save(messageEntity);
+
+            // 4. 杩斿洖鎴愬姛鍝嶅簲
+            return new ResponseResult
+            {
+                status = 0,
+                message = $"鎵归噺淇濆瓨鎴愬姛锛屽叡澶勭悊{barcodeInfoList.Count}鏉℃潯鐮佷俊鎭�",
+                data = resultData
+            };
+        }
+        catch (Exception ex)
+        {
+            // 5. 寮傚父澶勭悊锛氳褰曞紓甯稿苟杩斿洖閿欒
+            messageEntity.Result = 0;
+            messageEntity.DealWith = 0;
+            messageEntity.ResultData = $"鎵归噺淇濆瓨寮傚父锛歿ex.Message}";
+            _messageCenterManager.save(messageEntity);
+
+            return ResponseResult.ResponseError(ex);
+        }
+    }
+    
+    /// <summary>
+    /// 鏍规嵁閫佽揣鍗曞彿鍒犻櫎鏉$爜鏁版嵁
+    /// </summary>
+    /// <param name="request">鍖呭惈閫佽揣鍗曞彿鐨勮姹傛ā鍨�</param>
+    /// <returns>缁熶竴鍝嶅簲缁撴灉</returns>
+    [HttpPost("DeleteByNo")] // 鑻ラ」鐩敮鎸� RESTful锛屽彲鏀逛负 [HttpDelete("DeleteByNo")]
+    public ResponseResult DeleteByNo([FromBody] DeleteByDeliveryNoRequest request)
+    {
+        // 1. 鍒濆鍖栨秷鎭腑蹇冨疄浣擄紙璁板綍鍒犻櫎鎿嶄綔鏃ュ織锛�
+        var messageEntity = new MessageCenter
+        {
+            TableName = TARGET_TABLE,
+            Url = BASE_API_URL + "DeleteByNo", // 鎺ュ彛URL
+            Method = REQUEST_METHOD,
+            Data = JsonConvert.SerializeObject(request), // 搴忓垪鍖栬姹傚弬鏁�
+            Status = 1, // 1=澶勭悊涓�
+            CreateBy = "PL017", // 涓庡師鏈夋帴鍙d竴鑷寸殑鍒涘缓浜�
+            Route = request.DeliveryNo, // 璺敱鏍囪瘑=閫佽揣鍗曞彿锛屼究浜庡畾浣嶆棩蹇�
+            DealWith = 0 // 鍒濆=鏈鐞�
+        };
+
+        try
+        {
+            // 2. 璋冪敤涓氬姟灞傛柟娉曟墽琛屽垹闄�
+            dynamic resultData = new ExpandoObject();
+            bool deleteSuccess = _deliveryBarcodeManager.DeleteByDeliveryNo(request.DeliveryNo);
+            resultData.deletedDeliveryNo = request.DeliveryNo; // 杩斿洖鍒犻櫎鐨勯�佽揣鍗曞彿
+            resultData.isSuccess = deleteSuccess;
+
+            // 3. 鏇存柊娑堟伅涓績鐘舵�侊紙鎴愬姛锛�
+            messageEntity.Result = 1; // 1=鎴愬姛
+            messageEntity.DealWith = 1; // 1=宸插鐞�
+            _messageCenterManager.save(messageEntity);
+
+            // 4. 杩斿洖鎴愬姛鍝嶅簲
+            return new ResponseResult
+            {
+                status = 0,
+                message = $"鎴愬姛鍒犻櫎閫佽揣鍗曞彿銆寋request.DeliveryNo}銆嶅搴旂殑鏉$爜鏁版嵁",
+                data = resultData
+            };
+        }
+        catch (Exception ex)
+        {
+            // 5. 寮傚父澶勭悊锛氭洿鏂版秷鎭腑蹇冩棩蹇楋紙澶辫触锛�
+            messageEntity.Result = 0; // 0=澶辫触
+            messageEntity.DealWith = 0; // 0=鏈鐞�
+            messageEntity.ResultData = ex.Message; // 璁板綍寮傚父淇℃伅
+            _messageCenterManager.save(messageEntity);
+
+            // 6. 杩斿洖缁熶竴寮傚父鍝嶅簲
+            return ResponseResult.ResponseError(ex);
+        }
+    }
+    
+    /// <summary>
+    /// 鎸夐�佽揣鍗曞彿+琛屽唴鐮佽仈鍚堝垹闄ゆ潯鐮佹暟鎹�
+    /// </summary>
+    /// <param name="request">鍖呭惈閫佽揣鍗曞彿鍜岃鍐呯爜鐨勮姹傛ā鍨�</param>
+    /// <returns>缁熶竴鍝嶅簲缁撴灉</returns>
+    [HttpPost("DeleteByItem")] // 鑻ョ敤 RESTful 瑙勮寖锛屽彲鏀逛负 [HttpDelete("DeleteByItem")]
+    public ResponseResult DeleteByItem([FromBody] DeleteByDeliveryItemRequest request)
+    {
+        // 1. 鍒濆鍖栨秷鎭腑蹇冨疄浣擄細璁板綍鍒犻櫎鎿嶄綔鏃ュ織
+        var messageEntity = new MessageCenter
+        {
+            TableName = TARGET_TABLE,
+            Url = BASE_API_URL + "DeleteByItem", // 鎺ュ彛URL
+            Method = REQUEST_METHOD,
+            Data = JsonConvert.SerializeObject(request), // 搴忓垪鍖栬姹傚弬鏁帮紙鍚弻鏉′欢锛�
+            Status = 1, // 1=澶勭悊涓�
+            CreateBy = "PL017", // 涓庡師鏈夋帴鍙d竴鑷寸殑鍒涘缓浜�
+            Route = $"{request.DeliveryNo}_{request.LineNo}", // 璺敱鏍囪瘑=鈥滃崟鍙穇琛屽唴鐮佲�濓紝渚夸簬鏃ュ織瀹氫綅
+            DealWith = 0 // 鍒濆=鏈鐞�
+        };
+
+        try
+        {
+            // 2. 璋冪敤涓氬姟灞傝仈鍚堝垹闄ゆ柟娉�
+            dynamic resultData = new ExpandoObject();
+            bool deleteSuccess = _deliveryBarcodeManager.DeleteByDeliveryItem(
+                request.DeliveryNo, 
+                request.LineNo
+            );
+            // 鍝嶅簲涓繑鍥炲叧閿潯浠讹紝渚夸簬鍓嶇纭鍒犻櫎鑼冨洿
+            resultData.deletedDeliveryNo = request.DeliveryNo;
+            resultData.deletedLineNo = request.LineNo;
+            resultData.isSuccess = deleteSuccess;
+
+            // 3. 鏇存柊娑堟伅涓績鐘舵�侊紙鎴愬姛锛�
+            messageEntity.Result = 1; // 1=鎴愬姛
+            messageEntity.DealWith = 1; // 1=宸插鐞�
+            _messageCenterManager.save(messageEntity);
+
+            // 4. 杩斿洖鎴愬姛鍝嶅簲
+            return new ResponseResult
+            {
+                status = 0,
+                message = $"鎴愬姛鍒犻櫎閫佽揣鍗曞彿銆寋request.DeliveryNo}銆�-琛屽唴鐮併�寋request.LineNo}銆嶅搴旂殑鏉$爜鏁版嵁",
+                data = resultData
+            };
+        }
+        catch (Exception ex)
+        {
+            // 5. 寮傚父澶勭悊锛氳褰曟秷鎭腑蹇冩棩蹇楋紙澶辫触锛�
+            messageEntity.Result = 0; // 0=澶辫触
+            messageEntity.DealWith = 0; // 0=鏈鐞�
+            messageEntity.ResultData = ex.Message; // 瀛樺偍寮傚父淇℃伅
+            _messageCenterManager.save(messageEntity);
+
+            // 6. 杩斿洖缁熶竴寮傚父鍝嶅簲
+            return ResponseResult.ResponseError(ex);
+        }
+    } 
+}
+

--
Gitblit v1.9.3