From b52018589bf6c7ec1d51ce8ad000a7aa993b0ab5 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期一, 13 四月 2026 16:06:15 +0800
Subject: [PATCH] 优化组盘表获取成品编号、流水号、供方代码

---
 代码管理/WIDESEAWCS_Server/WIDESEAWCS_Server/WIDESEAWCS_BasicInfoService/BoxingDetailService.cs |   89 ++++++++++++++++++++++++++++++++++----------
 1 files changed, 69 insertions(+), 20 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WIDESEAWCS_Server/WIDESEAWCS_Server/WIDESEAWCS_BasicInfoService/BoxingDetailService.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WIDESEAWCS_Server/WIDESEAWCS_Server/WIDESEAWCS_BasicInfoService/BoxingDetailService.cs"
index 03b6dce..8c3a935 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WIDESEAWCS_Server/WIDESEAWCS_Server/WIDESEAWCS_BasicInfoService/BoxingDetailService.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WIDESEAWCS_Server/WIDESEAWCS_Server/WIDESEAWCS_BasicInfoService/BoxingDetailService.cs"
@@ -3,6 +3,7 @@
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
+using System.Text.RegularExpressions;
 using System.Threading.Tasks;
 using WIDESEAWCS_Common;
 using WIDESEAWCS_Common.PLCEnum;
@@ -11,6 +12,7 @@
 using WIDESEAWCS_Core.BaseServices;
 using WIDESEAWCS_Core.Helper;
 using WIDESEAWCS_DTO.BasicInfo;
+using WIDESEAWCS_IBasicInfoService;
 using WIDESEAWCS_Model.Models;
 using WIDESEAWCS_QuartzJob;
 
@@ -22,6 +24,10 @@
         private readonly IBoxingService _boxingService;
         private readonly IFormulaService _formulaService;
         private readonly IFormulaDetailService _formulaDetailService;
+        private readonly IProcessInfoDetailService _processInfoDetailService;
+        private readonly IScanStationService _scanStationService;
+
+
         private readonly IUnitOfWorkManage _unitOfWorkManage;
 
         public BoxingDetailService(
@@ -29,13 +35,18 @@
             IFormulaService formulaService,
             IBoxingService boxingService,
             IFormulaDetailService formulaDetailService,
+            IProcessInfoDetailService processInfoDetailService,
+            IScanStationService scanStationService,
             IUnitOfWorkManage unitOfWorkManage
             ) : base(BaseDal)
         {
             _formulaService = formulaService;
             _boxingService = boxingService;
             _formulaDetailService = formulaDetailService;
+            _processInfoDetailService = processInfoDetailService;
+            _scanStationService = scanStationService;
             _unitOfWorkManage = unitOfWorkManage;
+
         }
 
         public IRepository<Dt_BoxingDetail> Repository => BaseDal;
@@ -103,6 +114,7 @@
         /// <returns></returns>
         public string IsComponentCodesEqual(List<string> boxingDetails, List<string> formulaDetails)
         {
+
             // 澶勭悊null闆嗗悎锛岃閬跨┖鎸囬拡寮傚父
             var boxList = boxingDetails ?? new List<string>();
             var formulaList = formulaDetails ?? new List<string>();
@@ -141,30 +153,51 @@
                     {
                         return WebResponseContent.Instance.Error("鎻愪氦鍙傛暟涓嶈兘涓虹┖");
                     }
-                    string productCode = toolingBoardSubmitDto.FinishedProductCode?.Trim();
+                    string productCode = toolingBoardSubmitDto.FinishedProductCode.Trim();
+
+                    string proCode = string.Empty;
+                    string proOther = string.Empty;
+                    string supplierCode = string.Empty;
+
                     if (!string.IsNullOrWhiteSpace(productCode))
                     {
-                        string proCode = string.Empty;
-                        string proOther = string.Empty;
+                        string[] parts = productCode.Split(new char[] { ' ', '|' }, StringSplitOptions.RemoveEmptyEntries);
+                        if (parts.Length < 3) return WebResponseContent.Instance.Error("缂栫爜瑙勫垯鏈夎锛�");
+                        proCode = parts[0];
+                        proOther = parts[1];
+                        supplierCode = parts[2];
 
-                        var proCodeMatch = System.Text.RegularExpressions.Regex.Match(productCode, @"TX(\d+)(?=\s|\||$)", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
-                        if (proCodeMatch.Success)
-                        {
-                            proCode = $"TX{proCodeMatch.Groups[1].Value.Trim()}"; // 鎷兼帴TX+鏁板瓧锛屼繚鎸佹牸寮忕粺涓�
-                        }
+                        #region 鑾峰彇鎴愬搧缂栧彿銆佹祦姘村彿銆佷緵鏂逛唬鐮�
+                        //var proCodeMatch = Regex.Match(productCode, @"TX(\d+)(?=\s|\||$)", RegexOptions.IgnoreCase);
+                        //if (proCodeMatch.Success)
+                        //{
+                        //    proCode = $"TX{proCodeMatch.Groups[1].Value.Trim()}";
+                        //}
 
-                        // 姝e垯2锛氬尮閰嶈繛缁殑10浣嶇函鏁板瓧锛堝叏灞�鍖归厤锛屽彇绗竴涓鍚堢殑鍗冲彲锛�
-                        var proOtherMatch = System.Text.RegularExpressions.Regex.Match(productCode, @"\d{10}");
-                        if (proOtherMatch.Success)
-                        {
-                            proOther = proOtherMatch.Value.Trim();
-                        }
+                        //// 姝e垯2锛氬尮閰嶈繛缁殑10浣嶇函鏁板瓧锛堝叏灞�鍖归厤锛屽彇绗竴涓鍚堢殑鍗冲彲锛�
+                        //var proOtherMatch = Regex.Match(productCode, @"\d{10}");
+                        //if (proOtherMatch.Success)
+                        //{
+                        //    proOther = proOtherMatch.Value.Trim();
+                        //}
+                        //var supplierCodeMatch = Regex.Match(productCode, @"[A-Z]+$", RegexOptions.IgnoreCase);
+                        //if (supplierCodeMatch.Success)
+                        //{
+                        //    supplierCode = supplierCodeMatch.Value.Trim();
+                        //} 
+                        #endregion
                         toolingBoardSubmitDto.PartsList = toolingBoardSubmitDto.PartsList.Where(code => !string.IsNullOrEmpty(code)).ToList();
                         // 2. 鏌ヨ鎴愬搧閰嶆柟淇℃伅
                         Dt_Formula formulaModel = _formulaService.Repository.QueryFirst(x => x.ProductCode == proCode);
                         if (formulaModel == null)
                         {
                             return WebResponseContent.Instance.Error("鏃犳垚鍝侀厤鏂癸紝璇锋牳瀵规垚鍝佺紪鐮�");
+                        }
+
+                        Dt_ScanStation dt_ScanStation = _scanStationService.Repository.QueryFirst(x => x.StationCode == "001");
+                        if (dt_ScanStation.StationEndProduct != proCode)
+                        {
+                            return WebResponseContent.Instance.Error("鎴愬搧缂栧彿閿欒");
                         }
 
                         List<Dt_FormulaDetail> dt_FormulaDetails = _formulaDetailService.Repository.QueryData(x => x.FormulaId == formulaModel.Id && x.IsScanned == 1);
@@ -175,10 +208,10 @@
                             return WebResponseContent.Instance.Error($"鐗╂枡銆恵IsCode}銆戦敊璇紝璇锋牳瀵圭墿鏂欑紪鍙�");
                         }
 
-                        
-                        
+
+
                         //Dt_Boxing existBoxinModel = _boxingService.Repository.QueryFirst(x => x.PalletCode == PalletCode);
-                        
+
                         //if (existBoxinModel == null)
                         //{
                         //    return WebResponseContent.Instance.Error($"鎵樼洏鏈坊鍔狅紝璇风◢鍚庨噸璇�");
@@ -194,10 +227,17 @@
                         {
                             throw new InvalidOperationException("鎵樼洏鐮佹湭鎵埌锛岃閲嶈瘯");
                         }
+                        Dt_Boxing dt_Boxing = _boxingService.Repository.QueryFirst(x => x.PalletCode == PalletCode);
+                        if (dt_Boxing != null)
+                        {
+                            throw new InvalidOperationException("鎵樼洏鐮侀噸澶嶆壂鎻�");
+                        }
                         Dt_Boxing existBoxinModel = new Dt_Boxing();
                         existBoxinModel.PalletCode = PalletCode;
                         existBoxinModel.ProductCode = proCode;
+                        existBoxinModel.ProductName = formulaModel.ProductName;
                         existBoxinModel.BoxingNo = proOther;
+                        existBoxinModel.SupplierCode = supplierCode;
 
                         int id = _boxingService.Repository.AddData(existBoxinModel);
 
@@ -216,7 +256,7 @@
                         uow.Commit();
                     }
 
-                    
+
 
                     OtherDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceName == "涓绘帶PLC") as OtherDevice;
                     if (device == null) throw new Exception("鏈壘鍒颁富鎺LC璁惧淇℃伅");
@@ -326,9 +366,18 @@
                     //    #endregion
                     //}
                     //uow.Commit();
-                    //string msg = existBoxinModel == null ? "缁勭洏淇℃伅鏂板鎴愬姛锛�" : "缁勭洏淇℃伅淇敼鎴愬姛锛�";
+                    string msg = null;
+                    List<Dt_ProcessInfoDetail> dt_ProcessInfoDetail = _processInfoDetailService.Repository
+                            .QueryData(x => x.ProductSn == proOther && x.ProductCode == proCode).ToList();
 
-                    return WebResponseContent.Instance.OK();
+                    // 3. 鍒ゆ柇鏌ヨ缁撴灉锛屽瓨鍦ㄥ垯璧嬪�兼彁绀轰俊鎭�
+                    if (dt_ProcessInfoDetail.Count <= 3 && dt_ProcessInfoDetail.Count != 0)
+                    {
+                        msg = "宸叉湁娴佹按鍙�";
+                    }
+
+                    // 4. 杩斿洖鍝嶅簲锛堝瓨鍦ㄩ噸澶嶅垯msg鏄�"宸叉湁娴佹按鍙�"锛屼笉瀛樺湪鍒檓sg涓簄ull锛�
+                    return WebResponseContent.Instance.OK(msg);
                 }
                 catch (Exception ex)
                 {

--
Gitblit v1.9.3