From b7c6607e6937df8f60d99a076178f3173213af1e Mon Sep 17 00:00:00 2001
From: kyy <3283105747@qq.com>
Date: 星期三, 17 九月 2025 15:59:20 +0800
Subject: [PATCH] 1、送货条码操作类型修改

---
 MES.Service/service/BasicData/DeliveryBarcodeManager.cs |  117 +++++++++++++++++++++-------------------------------------
 1 files changed, 43 insertions(+), 74 deletions(-)

diff --git a/MES.Service/service/BasicData/DeliveryBarcodeManager.cs b/MES.Service/service/BasicData/DeliveryBarcodeManager.cs
index 6352d5f..c5a82a5 100644
--- a/MES.Service/service/BasicData/DeliveryBarcodeManager.cs
+++ b/MES.Service/service/BasicData/DeliveryBarcodeManager.cs
@@ -29,15 +29,12 @@
             // 鎸塗ype鍖哄垎鎿嶄綔绫诲瀷锛�0=鏂板锛�1=鍒犻櫎锛�
             switch (barcodeDto.Type)
             {
-                case "0":
-                    return InsertBarcode(barcodeEntity);
                 case "1":
+                    return InsertBarcode(barcodeEntity);
+                case "2":
                     return DeleteBarcode(barcodeEntity.Id);
                 default:
-                    throw new ArgumentOutOfRangeException(
-                        nameof(barcodeDto.Type),
-                        barcodeDto.Type,
-                        "鏉$爜鎿嶄綔绫诲瀷閿欒锛氫粎鏀寔 0锛堟柊澧烇級銆�1锛堝垹闄わ級");
+                    throw new ArgumentOutOfRangeException( nameof(barcodeDto.Type), barcodeDto.Type, "鏉$爜鎿嶄綔绫诲瀷閿欒锛氫粎鏀寔 0锛堟柊澧烇級銆�1锛堝垹闄わ級");
             }
         }
         catch (Exception ex)
@@ -72,12 +69,7 @@
             }
 
             // 2. 鎸夋搷浣滅被鍨婽ype鍒嗙粍锛堜娇鐢ㄥ己绫诲瀷閬垮厤绫诲瀷鎺ㄦ柇闂锛�
-            var typeGroupDict = entityTypePairs
-                .GroupBy(pair => pair.Type)
-                .ToDictionary(
-                    group => group.Key,
-                    group => group.Select(pair => pair.Entity).ToList()
-                );
+            var typeGroupDict = entityTypePairs.GroupBy(pair => pair.Type).ToDictionary(group => group.Key,group => group.Select(pair => pair.Entity).ToList());
 
             // 3. 瀛樺偍鍚勭粍鎿嶄綔缁撴灉
             var groupResultList = new List<bool>();
@@ -86,17 +78,14 @@
             {
                 switch (type)
                 {
-                    case "0":
+                    case "1":
                         groupResultList.Add(InsertBarcodeBatch(entityGroup));
                         break;
-                    case "1":
+                    case "2":
                         groupResultList.Add(DeleteBarcodeBatch(entityGroup.Select(e => e.Id).ToArray()));
                         break;
                     default:
-                        throw new ArgumentOutOfRangeException(
-                            nameof(type),
-                            type,
-                            "鎵归噺鎿嶄綔涓瓨鍦ㄩ潪娉昑ype锛氫粎鏀寔 0锛堟柊澧烇級銆�1锛堝垹闄わ級");
+                        throw new ArgumentOutOfRangeException(nameof(type),type,"鎵归噺鎿嶄綔涓瓨鍦ㄩ潪娉昑ype锛氫粎鏀寔 1锛堟柊澧烇級銆�2锛堝垹闄わ級");
                 }
             }
 
@@ -123,8 +112,9 @@
     {
         // 1. 鏍¢獙鍙傛暟锛氶�佽揣鍗曞彿涓嶈兘涓虹┖
         if (string.IsNullOrWhiteSpace(deliveryNo))
+        {
             throw new ArgumentException("閫佽揣鍗曞彿 DeliveryNo 涓嶈兘涓虹┖鎴栫┖鏍�", nameof(deliveryNo));
-
+        }
         try
         {
             // 2. 鎵ц鍒犻櫎锛氭牴鎹� DeliveryNo 鍖归厤琛ㄤ腑鏁版嵁锛堝搴斿疄浣撶殑 DeliveryNo 瀛楁锛�
@@ -134,8 +124,9 @@
 
             // 3. 鍒ゆ柇缁撴灉锛氳嚦灏戝垹闄�1鏉″垯瑙嗕负鎴愬姛锛屽惁鍒欐姏鍑衡�滄湭鎵惧埌鏁版嵁鈥濆紓甯�
             if (deletedCount > 0)
+            {
                 return true;
-
+            }
             throw new KeyNotFoundException($"鏈壘鍒伴�佽揣鍗曞彿涓恒�寋deliveryNo}銆嶇殑鏉$爜鏁版嵁锛屽垹闄ゆ搷浣滄湭鎵ц");
         }
         catch (Exception ex)
@@ -154,8 +145,9 @@
     {
         // 1. 鍙傛暟鏍¢獙涓庡鐞嗭紙浠庢帶鍒跺櫒绉昏繃鏉ョ殑閫昏緫锛�
         if (deliveryNoItems == null || !deliveryNoItems.Any())
+        {
             throw new ArgumentException("閫佽揣鍗曞彿鍒楄〃涓嶈兘涓虹┖", nameof(deliveryNoItems));
-
+        }
         // 鎻愬彇骞堕獙璇侀�佽揣鍗曞彿鍒楄〃
         var deliveryNoList = deliveryNoItems
             .Select(item => item.DeliveryNo) // 浠庡璞′腑鎻愬彇DeliveryNo瀛楁
@@ -165,21 +157,16 @@
 
         // 鍒ゆ柇鏄惁鏈夋湁鏁堝崟鍙�
         if (!deliveryNoList.Any())
+        {
             throw new ArgumentException("璇锋眰涓病鏈夋湁鏁堢殑閫佽揣鍗曞彿锛堝潎涓虹┖鎴栫┖鏍硷級");
-
+        }
         try
         {
             // 2. 鏌ヨ鏁版嵁搴撲腑瀛樺湪鐨勯�佽揣鍗曞彿
-            var existingNos = Db.Queryable<BarcodeInformation>()
-                .Where(barcode => deliveryNoList.Contains(barcode.DeliveryNo))
-                .Select(barcode => barcode.DeliveryNo)
-                .Distinct()
-                .ToList();
+            var existingNos = Db.Queryable<BarcodeInformation>().Where(barcode => deliveryNoList.Contains(barcode.DeliveryNo)).Select(barcode => barcode.DeliveryNo).Distinct().ToList();
 
             // 3. 鎵ц鎵归噺鍒犻櫎
-            int totalDeleted = Db.Deleteable<BarcodeInformation>()
-                .Where(barcode => deliveryNoList.Contains(barcode.DeliveryNo))
-                .ExecuteCommand();
+            int totalDeleted = Db.Deleteable<BarcodeInformation>().Where(barcode => deliveryNoList.Contains(barcode.DeliveryNo)).ExecuteCommand();
 
             // 4. 杩斿洖缁撴灉
             return new BatchDeleteResult
@@ -192,9 +179,7 @@
         }
         catch (Exception ex)
         {
-            throw new ApplicationException(
-                $"鎵归噺鍒犻櫎澶辫触锛堝叡{deliveryNoList.Count}涓崟鍙凤級锛歿ex.Message}",
-                ex);
+            throw new ApplicationException($"鎵归噺鍒犻櫎澶辫触锛堝叡{deliveryNoList.Count}涓崟鍙凤級锛歿ex.Message}",ex);
         }
     }
 
@@ -208,33 +193,31 @@
     {
         // 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 瀛楁锛�
-                )
+            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}銆嶅搴旂殑鏉$爜鏁版嵁锛屽垹闄ゆ搷浣滄湭鎵ц");
+            }
+            throw new KeyNotFoundException($"鏈壘鍒伴�佽揣鍗曞彿銆寋deliveryNo}銆嶄笖琛屽唴鐮併�寋lineNo}銆嶅搴旂殑鏉$爜鏁版嵁锛屽垹闄ゆ搷浣滄湭鎵ц");
         }
         catch (Exception ex)
         {
             // 4. 鍖呰寮傚父锛氳ˉ鍏呰仈鍚堟潯浠朵笂涓嬫枃锛屼究浜庡畾浣嶉棶棰�
-            throw new ApplicationException(
-                $"鎸夐�佽揣鍗曞彿+琛屽唴鐮佸垹闄ゆ潯鐮佹暟鎹け璐ワ紙DeliveryNo锛歿deliveryNo}锛孡ineNo锛歿lineNo}锛夛細{ex.Message}",
-                ex);
+            throw new ApplicationException($"鎸夐�佽揣鍗曞彿+琛屽唴鐮佸垹闄ゆ潯鐮佹暟鎹け璐ワ紙DeliveryNo锛歿deliveryNo}锛孡ineNo锛歿lineNo}锛夛細{ex.Message}",ex);
         }
     }
 
@@ -247,25 +230,21 @@
     {
         // 1. 鍙傛暟鏍¢獙涓庡鐞�
         if (deliveryItems == null || !deliveryItems.Any())
+        {
             throw new ArgumentException("閫佽揣鍗曡鍒楄〃涓嶈兘涓虹┖", nameof(deliveryItems));
-
+        }
         // 鎻愬彇骞堕獙璇侀�佽揣鍗曞彿+琛屽唴鐮佺粍鍚�
-        var validItems = deliveryItems
-            .Where(item =>
-                !string.IsNullOrWhiteSpace(item.DeliveryNo) &&
-                !string.IsNullOrWhiteSpace(item.LineNo)
-            )
+        var validItems = deliveryItems.Where(item =>!string.IsNullOrWhiteSpace(item.DeliveryNo) &&!string.IsNullOrWhiteSpace(item.LineNo))
             .Select(item => new
             {
                 DeliveryNo = item.DeliveryNo,
                 LineNo = item.LineNo
-            })
-            .Distinct() // 鍘婚噸鐩稿悓鐨勭粍鍚�
-            .ToList();
+            }).Distinct().ToList();
 
         if (!validItems.Any())
+        {
             throw new ArgumentException("璇锋眰涓病鏈夋湁鏁堢殑鏁堢殑閫佽揣鍗曡鏁版嵁锛堝潎涓虹┖鎴栫┖鏍硷級");
-
+        }
         try
         {
             // 2. 鎵ц鎵归噺鍒犻櫎锛堟寜DeliveryNo+LineNo缁勫悎鏉′欢锛�
@@ -277,16 +256,12 @@
             foreach (var item in validItems)
             {
                 // 妫�鏌ュ綋鍓嶇粍鍚堟槸鍚﹀瓨鍦�
-                var exists = Db.Queryable<BarcodeInformation>()
-                    .Any(b => b.DeliveryNo == item.DeliveryNo && b.DnLines == item.LineNo);
+                var exists = Db.Queryable<BarcodeInformation>().Any(b => b.DeliveryNo == item.DeliveryNo && b.DnLines == item.LineNo);
 
                 if (exists)
                 {
                     // 鎵ц鍒犻櫎
-                    var deleted = Db.Deleteable<BarcodeInformation>()
-                        .Where(b => b.DeliveryNo == item.DeliveryNo && b.DnLines == item.LineNo)
-                        .ExecuteCommand();
-
+                    var deleted = Db.Deleteable<BarcodeInformation>().Where(b => b.DeliveryNo == item.DeliveryNo && b.DnLines == item.LineNo).ExecuteCommand();
                     totalDeleted += deleted;
                     deletedItems.Add($"{item.DeliveryNo}_{item.LineNo}");
                 }
@@ -329,9 +304,7 @@
     /// </summary>
     private BarcodeInformation ConvertDtoToEntity(DeliveryBarcodeInfo dto)
     {
-        var entityId = dto.Type == "0"
-            ? Guid.NewGuid()
-            : (string.IsNullOrEmpty(dto.SmallBarcode) ? Guid.Empty : Guid.Parse(dto.SmallBarcode));
+        var entityId = dto.Type == "1" ? Guid.NewGuid() : (string.IsNullOrEmpty(dto.SmallBarcode) ? Guid.Empty : Guid.NewGuid());
 
         return new BarcodeInformation
         {
@@ -343,9 +316,8 @@
             DeliveryNo = dto.DeliveryNo,
             DnLines = dto.LineNo,
             PackLevel = dto.BarcodeType,
-            CreateTime = dto.Type == "0" ? DateTime.Now : (DateTime?)null,
+            CreateTime = dto.Type == "1" ? DateTime.Now : (DateTime?)null,
             UpdateTime = DateTime.Now,
-
             // 鎵╁睍瀛楁璧嬮粯璁ゅ��
             BigBarcode = null,
             SmallPackageLength = null,
@@ -379,18 +351,16 @@
         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();
+        }
+        var deleteRowCount = Db.Deleteable<BarcodeInformation>().Where(entity => entity.Id == id).ExecuteCommand();
 
         return deleteRowCount > 0 ? true : throw new NotImplementedException($"鏉$爜鍒犻櫎澶辫触锛氭湭鎵惧埌Id涓恒�寋id}銆嶇殑鏉$爜璁板綍");
     }
@@ -410,11 +380,10 @@
     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();
+        }
+        var deleteRowCount = Db.Deleteable<BarcodeInformation>().Where(entity => ids.Contains(entity.Id)).ExecuteCommand();
 
         return deleteRowCount > 0 ? true : throw new NotImplementedException($"鎵归噺鏉$爜鍒犻櫎澶辫触锛氬叡{ids.Length}涓狪d");
     }

--
Gitblit v1.9.3