From cb3907de90eef531df10a078149b29c55ff86401 Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期四, 17 七月 2025 16:20:06 +0800
Subject: [PATCH] 1

---
 代码管理/WMS/WIDESEA_WMSServer/WIDESEA_DTO/MES/RworkTaskModel.cs                         |   16 ++++
 代码管理/WMS/WIDESEA_WMSServer/WIDESEA_Model/Models/Outbound/Dt_MesRworkOutboundOrder.cs |    7 ++
 代码管理/WMS/WIDESEA_WMSServer/WIDESEA_StockService/ProStockInfoService.cs               |   27 ++++++---
 代码管理/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/MesProductService.cs              |   71 +++++++++++++++++++----
 代码管理/WMS/WIDESEA_WMSServer/WIDESEA_StockRepository/ProStockInfoRepository.cs         |    3 
 5 files changed, 98 insertions(+), 26 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_DTO/MES/RworkTaskModel.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_DTO/MES/RworkTaskModel.cs"
index 813b7d3..dc9ecfa 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_DTO/MES/RworkTaskModel.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_DTO/MES/RworkTaskModel.cs"
@@ -39,14 +39,26 @@
         [PropertyValidate("鍛ㄦ湡", NotNullAndEmpty = true)]
         public string DateCode { get; set; }
         /// <summary>
-        /// 闇�姹傛暟閲�
+        /// 闇�姹侾CS鏁伴噺
         /// </summary>
         [PropertyValidate("闇�姹傛暟閲�", NotNullAndEmpty = true)]
         public float RequiredQuantity { get; set; }
         /// <summary>
+        /// 闇�姹係ET鏁伴噺
+        /// </summary>
+        public float RequiredSetCount { get; set; }
+        /// <summary>
+        /// 浠撳簱
+        /// </summary>
+        public string WarehouseCode { get; set; }
+        /// <summary>
         /// 宸ュ巶
         /// </summary>
-        public string FactoryCode { get; set; }
+        public string FactoryCode { get; set; } = "HA02";
+        /// <summary>
+        /// 鎺ユ敹
+        /// </summary>
+        public int ReceiveDown { get; set; }
         /// <summary>
         /// 閿�鍞鍗�
         /// </summary>
diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_Model/Models/Outbound/Dt_MesRworkOutboundOrder.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_Model/Models/Outbound/Dt_MesRworkOutboundOrder.cs"
index 86e7760..6467471 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_Model/Models/Outbound/Dt_MesRworkOutboundOrder.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_Model/Models/Outbound/Dt_MesRworkOutboundOrder.cs"
@@ -93,11 +93,16 @@
         [SugarColumn(IsNullable = false, Length = 50, ColumnDescription = "鍛ㄦ湡")]
         public string DateCode { get; set; }
         /// <summary>
-        /// 闇�姹傛暟閲�
+        /// 闇�姹侾CS鏁伴噺
         /// </summary>
         [SugarColumn(IsNullable = false, ColumnDescription = "闇�姹傛暟閲�", DefaultValue = "0")]
         public float RequiredQuantity { get; set; }
         /// <summary>
+        /// 闇�姹係ET鏁伴噺
+        /// </summary>
+        [SugarColumn(IsNullable = false, ColumnDescription = "闇�姹傛暟閲�", DefaultValue = "0")]
+        public float RequiredSetCount { get; set; }
+        /// <summary>
         /// 宸ュ巶
         /// </summary>
         [SugarColumn(IsNullable = false, Length = 50, ColumnDescription = "宸ュ巶")]
diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_StockRepository/ProStockInfoRepository.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_StockRepository/ProStockInfoRepository.cs"
index 0f2a144..7449017 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_StockRepository/ProStockInfoRepository.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_StockRepository/ProStockInfoRepository.cs"
@@ -77,8 +77,7 @@
             proStockInfos = Db.Queryable<Dt_ProStockInfo>().Where(x => locationInfos.Contains(x.LocationCode))
                 .Includes(x => x.proStockInfoDetails)
                 .Where(x => x.proStockInfoDetails
-                .Any(v => v.SaleOrder == mesRworkOutboundOrder.SaleOrder
-                && v.ProductCode == mesRworkOutboundOrder.ProductCode
+                .Any(v => v.ProductCode == mesRworkOutboundOrder.ProductCode
                 && v.ProductVersion == mesRworkOutboundOrder.ProductVersion
                 && (isCanDate ? isCanDate : v.DateCode == mesRworkOutboundOrder.DateCode)
                 ))
diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_StockService/ProStockInfoService.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_StockService/ProStockInfoService.cs"
index 07c8b06..72285eb 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_StockService/ProStockInfoService.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_StockService/ProStockInfoService.cs"
@@ -109,7 +109,7 @@
         public List<Dt_ProStockInfo> GetUseableStocks(Dt_MesRworkOutboundOrder mesRworkOutboundOrder)
         {
             //杞崲鎴� 鎴愬搧浠撲粨搴撲俊鎭幏鍙栧熬鏁板睘鎬х殑璐т綅
-            Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x=>x.WarehouseCode==WarehouseEnum.HA71.ToString());
+            Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x=>x.WarehouseId== mesRworkOutboundOrder.WarehouseId);
             List<string> locationCodes = _basicRepository.LocationInfoRepository.GetCanOutLocationCodes(warehouse.WarehouseId);
             return BaseDal.GetProStocks(mesRworkOutboundOrder, locationCodes);
         }
@@ -125,10 +125,14 @@
         public List<Dt_ProStockInfo> GetOutboundStocks(List<Dt_ProStockInfo> stockInfos, Dt_ProOutOrderDetail outOrderDetail, float needQuantity, out float residueQuantity)
         {
             List<Dt_ProStockInfo> assignOutStocks =new List<Dt_ProStockInfo>();
-            float stockTotalQuantity = stockInfos.Select(x => x.proStockInfoDetails.Sum(v => v.StockPcsQty - v.OutboundQuantity)).Sum(x => x);
-            //stockInfos = stockInfos.OrderBy(x => x.Id).ToList();
             bool isCanLot = string.IsNullOrEmpty(outOrderDetail.PLot);
             bool isCanDate = string.IsNullOrEmpty(outOrderDetail.DateCode);
+            float stockTotalQuantity = stockInfos.Select(x => x.proStockInfoDetails.Where(x => x.ProductCode == outOrderDetail.PCode && x.ProductVersion.StartsWith(outOrderDetail.PVer.Substring(0, 1))
+                            && (isCanLot ? isCanLot : x.BagNo == outOrderDetail.PLot)
+                            && (isCanDate ? isCanDate : x.DateCode == outOrderDetail.DateCode))
+                        .Sum(v => v.StockPcsQty - v.OutboundQuantity)).Sum(x => x);
+            //stockInfos = stockInfos.OrderBy(x => x.Id).ToList();
+            
             if (stockTotalQuantity >= needQuantity)//搴撳瓨澶�
             {
                 int index = 0;
@@ -233,7 +237,10 @@
         public List<Dt_ProStockInfo> GetOutboundStocks(List<Dt_ProStockInfo> stockInfos, Dt_ErpProScrapSheetDetail outOrderDetail, float needQuantity, out float residueQuantity)
         {
             List<Dt_ProStockInfo> assignOutStocks = new List<Dt_ProStockInfo>();
-            float stockTotalQuantity = stockInfos.Select(x => x.proStockInfoDetails.Sum(v => v.StockPcsQty - v.OutboundQuantity)).Sum(x => x);
+            float stockTotalQuantity = stockInfos.Select(x => x.proStockInfoDetails.Where(x =>
+                            x.ProductCode == outOrderDetail.ScrapProCode
+                            && x.ProductVersion == outOrderDetail.ScrapProVersion
+                            && x.LotNumber == outOrderDetail.ScrapProLotNo).Sum(v => v.StockPcsQty - v.OutboundQuantity)).Sum(x => x);
             //stockInfos = stockInfos.OrderBy(x => x.Id).ToList();
             if (stockTotalQuantity >= needQuantity)//搴撳瓨澶�
             {
@@ -293,9 +300,12 @@
         public List<Dt_ProStockInfo> GetOutboundStocks(List<Dt_ProStockInfo> stockInfos, Dt_MesRworkOutboundOrder mesRworkOutboundOrder, float needQuantity, out float residueQuantity)
         {
             List<Dt_ProStockInfo> assignOutStocks = new List<Dt_ProStockInfo>();
-            float stockTotalQuantity = stockInfos.Select(x => x.proStockInfoDetails.Sum(v => v.StockPcsQty - v.OutboundQuantity)).Sum(x => x);
-            //stockInfos = stockInfos.OrderBy(x => x.Id).ToList();
             bool isCanDate = string.IsNullOrEmpty(mesRworkOutboundOrder.DateCode);
+            float stockTotalQuantity = stockInfos.Select(x => x.proStockInfoDetails.Where(x => x.ProductCode == mesRworkOutboundOrder.ProductCode
+                            && x.ProductVersion == mesRworkOutboundOrder.ProductVersion
+                            && (isCanDate ? isCanDate : x.DateCode == mesRworkOutboundOrder.DateCode))
+                        .Sum(v => v.StockPcsQty - v.OutboundQuantity)).Sum(x => x);
+            //stockInfos = stockInfos.OrderBy(x => x.Id).ToList();
             if (stockTotalQuantity >= needQuantity)//搴撳瓨澶�
             {
                 int index = 0;
@@ -303,8 +313,7 @@
                 {
                     Dt_ProStockInfo stockInfo = stockInfos[index];
                     float useableStockQuantity = stockInfo.proStockInfoDetails
-                        .Where(x => x.SaleOrder == mesRworkOutboundOrder.SaleOrder 
-                            && x.ProductCode == mesRworkOutboundOrder.ProductCode 
+                        .Where(x => x.ProductCode == mesRworkOutboundOrder.ProductCode 
                             && x.ProductVersion == mesRworkOutboundOrder.ProductVersion
                             && (isCanDate? isCanDate: x.DateCode == mesRworkOutboundOrder.DateCode))
                         .Sum(x => x.StockPcsQty - x.OutboundQuantity);
@@ -317,7 +326,7 @@
                     {
                         stockInfo.proStockInfoDetails.ForEach(x =>
                         {
-                            if ((x.StockPcsQty > x.OutboundQuantity) && x.SaleOrder == mesRworkOutboundOrder.SaleOrder 
+                            if ((x.StockPcsQty > x.OutboundQuantity) 
                                 && x.ProductCode == mesRworkOutboundOrder.ProductCode 
                                 && x.ProductVersion == mesRworkOutboundOrder.ProductVersion
                                 && (isCanDate ? isCanDate : x.DateCode == mesRworkOutboundOrder.DateCode))
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 d56e520..d96efaa 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"
@@ -531,7 +531,7 @@
             MesResponseContent content = new MesResponseContent();
             try
             {
-                Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA72.ToString());
+                Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == model.WarehouseCode);
                 if (warehouse == null)
                 {
                     return content.Error($"灏炬暟浠撲俊鎭湭閰嶇疆");
@@ -546,17 +546,58 @@
                 {
                     WarehouseId = warehouse.WarehouseId,
                     TaskNo = model.TaskNo,
-                    OrderStatus = OutOrderStatusEnum.鏈紑濮�.ObjToInt(),
+                    OrderStatus = OutOrderStatusEnum.鍑哄簱涓�.ObjToInt(),
                     CreateType = OrderCreateTypeEnum.UpperSystemPush.ObjToInt(),
                     ProductCode = model.ProductCode,
-                    ProductName = model.ProductName,
+                    ProductName = model.ProductCode,
                     ProductVersion = model.ProductVersion,
                     DateCode = model.DateCode,
                     RequiredQuantity = model.RequiredQuantity,
+                    RequiredSetCount=model.RequiredSetCount,
                     FactoryCode = model.FactoryCode,
-                    SaleOrder = model.SaleOrder,
+                    SaleOrder = model.SaleOrder ?? "",
                     OrderType = model.InventoryType
                 };
+                if (model.DateCode.IndexOf("骞冲簱")>0 || warehouse.WarehouseCode==WarehouseEnum.HA101.ToString())
+                {
+                    Dt_Warehouse warehousePing = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA101.ToString());
+                    mesRworkOutboundOrder.WarehouseId = warehousePing.WarehouseId;
+                    mesRworkOutboundOrder.OrderStatus = OutOrderStatusEnum.鍑哄簱瀹屾垚.ObjToInt();
+                    _unitOfWorkManage.BeginTran();
+                    _outboundService.RworkOutboundOrderService.Repository.AddData(mesRworkOutboundOrder);
+                    MesInventoryInfo mesInventoryInfo = new MesInventoryInfo()
+                    {
+                        Warhouseno = warehousePing.WarehouseCode,
+                        InternalPackageNumber = model.ProductCode,
+                        SetCount = (int)model.RequiredSetCount,
+                        EligiblePcsCount = (int)model.RequiredQuantity
+                    };
+
+                    MesProductOutBound mesProductOutBound = new MesProductOutBound()
+                    {
+                        TaskNo = mesRworkOutboundOrder.TaskNo,
+                        ProductCode = mesRworkOutboundOrder.ProductCode,
+                        ProductVersion = mesRworkOutboundOrder.ProductVersion,
+                        DateCode = mesRworkOutboundOrder.DateCode,
+                        SaleOrder = mesRworkOutboundOrder.SaleOrder,
+                        InventoryInfo = new List<MesInventoryInfo> { mesInventoryInfo  }
+                    };
+                    if (model.ReceiveDown==EnableEnum.Enable.ObjToInt())
+                    {
+                        _unitOfWorkManage.RollbackTran();
+                    }
+                    else
+                    {
+                        //MES鎴愬搧搴撳瓨鏉垮嚭搴撳悓姝�
+                        WebResponseContent responseContentPing = _outboundService.RworkOutboundOrderService.ProductOutBoundSync(mesProductOutBound);
+                        if (!responseContentPing.Status)
+                        {
+                            throw new Exception("鍚屾MES搴撳瓨鏉垮嚭搴撳け璐�,閿欒:" + responseContentPing.Message);
+                        }
+                        _unitOfWorkManage.CommitTran();
+                    }
+                    return content.OK($"鎻愪緵杩斿簱鍗曟帴鏀舵垚鍔�,ReceiveDown:{model.ReceiveDown}");
+                }
                 List<Dt_Task> tasks = new List<Dt_Task>();
                 List<Dt_ProStockInfo>? proStockInfos = null;
                 List<Dt_OutProStockInfo>? outProStockInfos = null;
@@ -605,19 +646,25 @@
 
                     if (!updateContent.Status)
                     {
-                        _unitOfWorkManage.RollbackTran();
-                        return content.Error(updateContent.Message);
+                        throw new Exception(updateContent.Message);
                     }
                 }
                 _outboundService.RworkOutboundOrderService.Repository.AddData(mesRworkOutboundOrder);
-                //MES鎴愬搧搴撳瓨鏉垮嚭搴撳悓姝�
-                WebResponseContent responseContent = _outboundService.RworkOutboundOrderService.ProductOutBoundSync(_outboundService.RworkOutboundOrderService.MesProOutBound(mesRworkOutboundOrder, proStockInfoDetails));
-                if (!responseContent.Status)
+                if (model.ReceiveDown == EnableEnum.Enable.ObjToInt())
                 {
-                    throw new Exception("鍚屾MES搴撳瓨鏉垮嚭搴撳け璐�,閿欒:" + responseContent.Message);
+                    _unitOfWorkManage.RollbackTran();
                 }
-                _unitOfWorkManage.CommitTran();
-                return content.OK("鎻愪緵杩斿簱鍗曟帴鏀舵垚鍔�");
+                else
+                {
+                    //MES鎴愬搧搴撳瓨鏉垮嚭搴撳悓姝�
+                    WebResponseContent responseContent = _outboundService.RworkOutboundOrderService.ProductOutBoundSync(_outboundService.RworkOutboundOrderService.MesProOutBound(mesRworkOutboundOrder, proStockInfoDetails));
+                    if (!responseContent.Status)
+                    {
+                        throw new Exception("鍚屾MES搴撳瓨鏉垮嚭搴撳け璐�,閿欒:" + responseContent.Message);
+                    }
+                    _unitOfWorkManage.CommitTran();
+                }
+                return content.OK($"鎻愪緵杩斿簱鍗曟帴鏀舵垚鍔�,ReceiveDown:{model.ReceiveDown}");
             }
             catch (Exception ex)
             {

--
Gitblit v1.9.3