From 95e39ae7aecd6e1016c71cf5ae70a680d8f569bb Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期二, 29 四月 2025 10:48:30 +0800
Subject: [PATCH] 上传最新代码

---
 代码管理/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/MesProductService.cs |  198 +++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 175 insertions(+), 23 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/MesProductService.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/MesProductService.cs"
index 99b1724..a2e1a4c 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/MesProductService.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/MesProductService.cs"
@@ -15,6 +15,11 @@
 using Newtonsoft.Json.Serialization;
 using Newtonsoft.Json;
 using WIDESEA_Common.APIEnum;
+using System.Reflection.Metadata;
+using Microsoft.Extensions.FileSystemGlobbing.Internal;
+using System.Text.RegularExpressions;
+using WIDESEA_Common.CommonEnum;
+using WIDESEA_Core.CodeConfigEnum;
 
 namespace WIDESEA_TaskInfoService
 {
@@ -34,12 +39,12 @@
                 {
                     return content.Error("鏈壘鍒颁粨搴撲俊鎭�");
                 }
-                //闄愬埗浠诲姟
-                Dt_Task task = BaseDal.QueryFirst(x => x.SourceAddress == bagInfoModel.WorkCenter && (x.TaskStatus == TaskStatusEnum.New.ObjToInt() || x.TaskStatus == TaskStatusEnum.Line_Execute.ObjToInt() || x.TaskStatus == TaskStatusEnum.Line_Executing.ObjToInt()));
-                if (task!=null)
-                {
-                    return content.Error($"绾夸綋瀛樺湪浠诲姟鎴栨墽琛屼腑,鑳舵鍙穥task.PalletCode}");
-                }
+                ////闄愬埗浠诲姟
+                //Dt_Task task = BaseDal.QueryFirst(x => x.SourceAddress == bagInfoModel.WorkCenter && (x.TaskStatus == TaskStatusEnum.New.ObjToInt() || x.TaskStatus == TaskStatusEnum.Line_Execute.ObjToInt() || x.TaskStatus == TaskStatusEnum.Line_Executing.ObjToInt()));
+                //if (task!=null)
+                //{
+                //    return content.Error($"绾夸綋瀛樺湪浠诲姟鎴栨墽琛屼腑,鑳舵鍙穥task.PalletCode}");
+                //}
                 Dt_Warehouse warehouseLocation = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA71.ToString());
                 Dt_LocationInfo locationInfo = _basicRepository.LocationInfoRepository.QueryFirst(x => x.WarehouseId == warehouseLocation.WarehouseId);
                 if (locationInfo == null)
@@ -60,6 +65,25 @@
                 List<string> proDetailsExists = _stockRepository.ProStockInfoDetailRepository.QueryData().Select(x=>x.BagNo).ToList();
                 //鍐呭寘淇℃伅缁勭洏
                 List<Dt_MesProInOrderDetail> mesProInOrderDetails = new List<Dt_MesProInOrderDetail>();
+                string palletCode = @"^C\d{5}$";  // 姝e垯琛ㄨ揪寮�
+                bool isValid = Regex.IsMatch(bagInfoModel.BatchNo, palletCode);
+                if (!isValid && bagInfoModel.BatchNo.Substring(0,3).ToUpper()!= "CPK")
+                {
+                    return content.Error($"妗嗙爜鏍煎紡閿欒{bagInfoModel.BatchNo}");
+                }
+                if (bagInfoModel.BatchNo.Substring(0, 3).ToUpper() == "CPK")
+                {
+                    WebResponseContent inProRespone = InPKProStock(bagInfoModel, proDetailsExists, warehouse);
+                    if (!inProRespone.Status)
+                    {
+                        return content.Error(inProRespone.Message);
+                    }
+                    return content.OK(inProRespone.Message);
+                }
+                else if (isValid)
+                {
+
+                }
                 foreach (var item in bagInfoModel.BagDetails)
                 {
                     if (proDetailsExists.Contains(item.BagNo))
@@ -96,6 +120,7 @@
                 Dt_MesProInOrder mesProInOrder = new Dt_MesProInOrder()
                 {
                     WarehouseId = warehouse.WarehouseId,
+                    ProInOrderNo = _outboundService.OutboundOrderService.CreateCodeByRule(nameof(RuleCodeEnum.ProInCodeRule)),
                     BatchNo = bagInfoModel.BatchNo,
                     WorkCenter = bagInfoModel.WorkCenter,
                     MesProStatus = InOrderStatusEnum.鍏ュ簱涓�.ObjToInt(),
@@ -144,8 +169,20 @@
                 _unitOfWorkManage.BeginTran();
                 int taskId = BaseDal.AddData(newTask);
                 newTask.TaskId = taskId;
-                Db.InsertNav(mesProInOrder).Include(x => x.Details).ExecuteCommand();
                 Db.InsertNav(proStockInfo).Include(x => x.proStockInfoDetails).ExecuteCommand();
+                
+                //涓婁紶ERP
+                WebResponseContent responseContent = _inboundOrderService.FeedbackProIn(mesProInOrder);
+                if (!responseContent.Status)
+                {
+                    mesProInOrder.UpErpStatus = WhetherEnum.False.ObjToInt();
+                    mesProInOrder.Remark = responseContent.Message;
+                }
+                else
+                {
+                    mesProInOrder.UpErpStatus = WhetherEnum.True.ObjToInt();
+                }
+                Db.InsertNav(mesProInOrder).Include(x => x.Details).ExecuteCommand();
                 _unitOfWorkManage.CommitTran();
                 //鎺ㄩ�佷换鍔�
                 PushTasksToWCS(new List<Dt_Task> { newTask });
@@ -157,6 +194,107 @@
                 content.Error(ex.Message);
             }
             return content;
+        }
+        public WebResponseContent InPKProStock(MesBagInfoModel bagInfoModel, List<string> proDetailsExists,Dt_Warehouse wareSource)
+        {
+            Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x=>x.WarehouseCode==WarehouseEnum.HA101.ToString());
+            if (warehouse==null)
+            {
+                return WebResponseContent.Instance.Error("鏈壘鍒板钩搴撲粨搴撲俊鎭�");
+            }
+            //鍐呭寘淇℃伅缁勭洏
+            List<Dt_MesProInOrderDetail> mesProInOrderDetails = new List<Dt_MesProInOrderDetail>();
+            foreach (var item in bagInfoModel.BagDetails)
+            {
+                if (proDetailsExists.Contains(item.BagNo))
+                {
+                    return WebResponseContent.Instance.Error($"鍐呭寘{item.BagNo}宸插瓨鍦�");
+                }
+                foreach (var child in item.BagItems)
+                {
+                    Dt_MesProInOrderDetail mesProInOrderDetail = new Dt_MesProInOrderDetail()
+                    {
+                        BagNo = item.BagNo,
+                        ProductCode = item.ProductCode,
+                        ProductVersion = item.ProductVersion,
+                        SETQty = child.SETQty,
+                        OKPCSQTY = child.OKPCSQTY,
+                        DateCode = item.DateCode,
+                        XQty = child.XQty,
+                        XSite = child.XSite,
+                        Weight = item.Weight,
+                        PackingDate = item.PackingDate,
+                        LotNumber = child.LotNumber,
+                        ERPOrder = child.ERPOrder,
+                        SaleOrder = child.SaleOrder,
+                        MoNumber = child.MoNumber,
+                        OverInQuantity= child.OKPCSQTY
+                    };
+                    mesProInOrderDetails.Add(mesProInOrderDetail);
+                }
+            }
+            List<Dt_ProStockInfoDetail> proStockInfoDetails = new List<Dt_ProStockInfoDetail>();
+            foreach (var item in mesProInOrderDetails)
+            {
+                proStockInfoDetails.Add(_mapper.Map<Dt_ProStockInfoDetail>(item));
+            }
+            Dt_MesProInOrder mesProInOrder = new Dt_MesProInOrder()
+            {
+                WarehouseId = warehouse.WarehouseId,
+                ProInOrderNo = _outboundService.OutboundOrderService.CreateCodeByRule(nameof(RuleCodeEnum.ProInCodeRule)),
+                BatchNo = bagInfoModel.BatchNo,
+                WorkCenter = bagInfoModel.WorkCenter,
+                MesProStatus = InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt(),
+                UnPackStock = bagInfoModel.UnPackStock,
+                CreateType = OrderCreateTypeEnum.UpperSystemPush.ObjToInt(),
+                Details = mesProInOrderDetails
+            };
+            ProStockAttributeEnum attributeEnum = new ProStockAttributeEnum();
+            switch (wareSource.WarehouseCode)
+            {
+                case "HA71":
+                    attributeEnum = ProStockAttributeEnum.鎴愬搧;
+                    break;
+                case "HA72":
+                    attributeEnum = ProStockAttributeEnum.灏炬暟;
+                    break;
+                case "HA73":
+                    attributeEnum = ProStockAttributeEnum.鐮斿彂;
+                    break;
+                default:
+                    throw new Exception("鏈壘鍒拌搴撳瓨灞炴��");
+            }
+            proStockInfoDetails.ForEach(x =>
+            {
+                x.ProOutDetailStatus = StockStatusEmun.骞冲簱鍏ュ簱瀹屾垚.ObjToInt();
+            });
+            Dt_ProStockInfo proStockInfo = new Dt_ProStockInfo()
+            {
+                PalletCode = bagInfoModel.BatchNo,
+                PalletType = 1,
+                LocationCode= "鎴愬搧寰呭彂璐у尯",
+                ProStockAttribute = attributeEnum.ObjToInt(),
+                WarehouseId = warehouse.WarehouseId,
+                StockStatus = StockStatusEmun.骞冲簱鍏ュ簱瀹屾垚.ObjToInt(),
+                proStockInfoDetails = proStockInfoDetails
+            };
+            
+            _unitOfWorkManage.BeginTran();
+            Db.InsertNav(proStockInfo).Include(x => x.proStockInfoDetails).ExecuteCommand();
+            //涓婁紶ERP
+            WebResponseContent responseContent = _inboundOrderService.FeedbackProIn(mesProInOrder);
+            if (!responseContent.Status)
+            {
+                mesProInOrder.UpErpStatus = WhetherEnum.False.ObjToInt();
+                mesProInOrder.Remark = responseContent.Message;
+            }
+            else
+            {
+                mesProInOrder.UpErpStatus = WhetherEnum.True.ObjToInt();
+            }
+            Db.InsertNav(mesProInOrder).Include(x => x.Details).ExecuteCommand();
+            _unitOfWorkManage.CommitTran();
+            return WebResponseContent.Instance.OK("鎺ユ敹鎴愬姛");
         }
         /// <summary>
         /// 澶栧寘淇℃伅鎺ユ敹
@@ -228,24 +366,29 @@
                     x.ProOutDetailStatus = StockStatusEmun.骞冲簱鍏ュ簱瀹屾垚.ObjToInt();
                 });
 
-                Dt_ProStockInfo proStockInfo = new Dt_ProStockInfo()
-                {
-                    PalletCode = boxInfoModel.BoxNo,
-                    PalletType = 0,
-                    LocationCode="鎴愬搧寰呭彂璐у尯",
-                    WarehouseId = warehouse.WarehouseId,
-                    ShipmentOrder = shipmentOrder,
-                    StockStatus = StockStatusEmun.骞冲簱鍏ュ簱瀹屾垚.ObjToInt(),
-                    proStockInfoDetails = proStockInfoDetails
-                };
+                
                 _unitOfWorkManage.BeginTran();
-                //鏍规嵁澶栧寘淇℃伅瑙g粦鍐呭寘涓庤兌妗嗗簱瀛樺叧绯�
                 WebResponseContent UnBindContent = _stockService.ProStockInfoService.UnBindStock(proStockInfoDetails);
                 if (!UnBindContent.Status)
                 {
                     throw new Exception(UnBindContent.Message);
                 }
-                Db.InsertNav(proStockInfo).Include(x => x.proStockInfoDetails).ExecuteCommand();
+                if (UnBindContent.Data!=null)
+                {
+                    Dt_ProStockInfo proStockInfo = new Dt_ProStockInfo()
+                    {
+                        PalletCode = boxInfoModel.BoxNo,
+                        PalletType = 0,
+                        LocationCode = "鎴愬搧寰呭彂璐у尯",
+                        WarehouseId = warehouse.WarehouseId,
+                        ShipmentOrder = shipmentOrder,
+                        StockStatus = StockStatusEmun.骞冲簱鍏ュ簱瀹屾垚.ObjToInt(),
+                        proStockInfoDetails = UnBindContent.Data as List<Dt_ProStockInfoDetail>,
+                        ProStockAttribute = ProStockAttributeEnum.鎴愬搧.ObjToInt()
+                    };
+                    //鏍规嵁澶栧寘淇℃伅瑙g粦鍐呭寘涓庤兌妗嗗簱瀛樺叧绯�
+                    Db.InsertNav(proStockInfo).Include(x => x.proStockInfoDetails).ExecuteCommand();
+                }
                 _unitOfWorkManage.CommitTran();
                 return content.OK("澶栧寘鎺ユ敹鎴愬姛");
             }
@@ -264,25 +407,34 @@
             //鑾峰彇鍑哄簱鍗�
             Dt_ProOutOrder proOutOrder = _outboundService.ProOutOrderService.Repository.QueryFirst(x => x.Id == proOutOrderDetail.ProOrderId);
             //鑾峰彇瀹㈡埛
-            Dt_CustomerInfo customerInfo = _basicRepository.CustomerInfoRepository.QueryFirst(x => x.Code == proOutOrderDetail.Customer);
+            Dt_CustomerInfo customerInfo = _basicRepository.CustomerInfoRepository.QueryFirst(x => x.Code == proOutOrderDetail.EndCustomer);
             List<string> outBags = proStockInfoDetails.Where(x => x.OutboundQuantity > 0).Select(x => x.BagNo).ToList();
+            outBags.ForEach(x =>
+            {
+                x = string.Format($"{0},{1},{2},0,{3}",x,outProStockInfo.PCode,outProStockInfo.DateCode,outProStockInfo.AssignQuantity.ObjToInt());
+            });
             MesShipOrderDetail orderDetail = new MesShipOrderDetail()
             {
                 ProductCode = proOutOrderDetail.PCode,
                 ProductVersion = proOutOrderDetail.PVer,
                 Qty = outProStockInfo.AssignQuantity,
-                DateCode= outProStockInfo.DateCode,
+                DateCode = outProStockInfo.DateCode,
                 SaleOrder = proOutOrderDetail.SaleOrder,
                 Sequence = outProStockInfo.Id,
                 WorkCenter = "SPCK_OUTER-001",
-                PlasticBox=new List<PlasticBox> { new PlasticBox() { PlasticBoxNumber= outProStockInfo.PalletCode,Insourcings=outBags } }
+                PlasticBox = new List<PlasticBox> { new PlasticBox()
+                    {
+                        PlasticBoxNumber= outProStockInfo.PalletCode,
+                        Insourcings = outBags
+                    } 
+                }
             };
             mesShipOrderDetails.Add(orderDetail);
             MesShipmentOrderSync shipmentOrderSync = new MesShipmentOrderSync()
             {
                 ShipmentOrder = proOutOrder.ProOutOrderNo+"-"+ outProStockInfo.TaskNum,
                 PlantShipDate = proOutOrder.PlantShipDate.ToString("yyyy-MM-dd HH:mm:ss"),
-                Customer = proOutOrderDetail.Customer,
+                Customer = proOutOrderDetail.EndCustomer,
                 FactoryCode = proOutOrderDetail.FactoryCode,
                 ShipName = customerInfo.Name,
                 ShippingAddress = customerInfo.NickName,

--
Gitblit v1.9.3