From fb8169d1d8e4e8e4c2091cc128c05a8966cc5915 Mon Sep 17 00:00:00 2001
From: wankeda <Administrator@DESKTOP-HAU3ST3>
Date: 星期一, 19 一月 2026 15:51:07 +0800
Subject: [PATCH] 盘点流程

---
 WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/NewPartialTaskService_Outbound.cs |  240 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 229 insertions(+), 11 deletions(-)

diff --git a/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/NewPartialTaskService_Outbound.cs b/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/NewPartialTaskService_Outbound.cs
index 0f9506a..28bdeab 100644
--- a/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/NewPartialTaskService_Outbound.cs
+++ b/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/NewPartialTaskService_Outbound.cs
@@ -1,8 +1,12 @@
 锘縰sing System;
+using System.Collections;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using MailKit.Search;
+using WIDESEA_Common;
+using WIDESEA_Common.OrderEnum;
 using WIDESEA_Core;
 using WIDESEA_Core.Enums;
 using WIDESEA_Core.Helper;
@@ -12,6 +16,11 @@
 {
     public partial class TaskService
     {
+        /// <summary>
+        /// 鎴愬搧鍑哄簱
+        /// </summary>
+        /// <param name="keys"></param>
+        /// <returns></returns>
         public WebResponseContent WMSGenerateNewOutboundTask(int[] keys)
         {
             try
@@ -20,7 +29,7 @@
                 List<Dt_LocationInfo> locationInfos = new List<Dt_LocationInfo>();
                 List<Dt_OutStockLockInfo> outStockLockInfos = new List<Dt_OutStockLockInfo>();
 
-                List<Dt_NewOutboundOrderDetail> outboundOrderDetails = _outboundService.NewOutboundOrderDetailService.Repository.QueryData(x => keys.Contains(x.OrderId));
+                List<Dt_NewOutboundOrderDetail> outboundOrderDetails = _outboundService.NewOutboundOrderDetailService.Repository.QueryData(x => keys.Contains(x.Id));
                 if (outboundOrderDetails == null || outboundOrderDetails.Count == 0)
                 {
                     throw new Exception("鏈壘鍒板嚭搴撳崟鏄庣粏淇℃伅");
@@ -29,15 +38,38 @@
                 {
                     throw new Exception("鎵�閫夊嚭搴撳崟鏄庣粏瀛樺湪鍑哄簱涓垨宸插畬鎴�");
                 }
-                List<Dt_NewOutboundOrder> outboundOrders = _outboundService.NewOutboundOrderService.Repository.QueryData(x => keys.Contains(x.Id));
-                List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.Repository.QueryData(x => outboundOrderDetails.Select(s => s.LPNNo).Contains(x.PalletCode));
-                if (outboundOrderDetails == null || outboundOrderDetails.Count == 0)
+                var lpngroup = outboundOrderDetails.GroupBy(x => x.LPNNo);
+
+
+                List<Dt_NewOutboundOrderDetail> newOutboundOrderDetails = new List<Dt_NewOutboundOrderDetail>();
+                List<Dt_StockInfo> stockInfos = new List<Dt_StockInfo>();
+
+                foreach (var lpngroups in lpngroup)
+                {
+                    string lpn = lpngroups.Key;
+                    List<Dt_NewOutboundOrderDetail> detailsForThisLPN = _outboundService.NewOutboundOrderDetailService.Repository.QueryData(x => x.LPNNo == lpn && x.OrderDetailStatus == OrderDetailStatusEnum.New.ObjToInt());
+                    if (detailsForThisLPN.Count == 0) continue;
+                    newOutboundOrderDetails.AddRange(detailsForThisLPN);
+                    Dt_StockInfo? stockInfo = _stockService.StockInfoService.Repository.QueryFirst(x => x.PalletCode == lpn);
+                    if (stockInfo == null)
+                    {
+                        throw new Exception($"鏈壘鍒板簱瀛樹俊鎭紝鎵樼洏鍙穥lpn}");
+                    }
+                    stockInfos.Add(stockInfo);
+
+                }
+
+                if (stockInfos == null || stockInfos.Count == 0)
                 {
                     throw new Exception("鏈壘鍒板簱瀛樹俊鎭�");
                 }
+                List<int> orderId = newOutboundOrderDetails.Select(x => x.OrderId).Distinct().ToList();
+                List<Dt_NewOutboundOrder> outboundOrders = _outboundService.NewOutboundOrderService.Repository.QueryData(x => orderId.Contains(x.Id));
+                _unitOfWorkManage.BeginTran();
                 var Newtasks = GetTasks(stockInfos, TaskTypeEnum.OutProduct);
                 List<Dt_StockInfoDetail> stockInfoDetails = _stockService.StockInfoDetailService.Repository.QueryData(x => stockInfos.Select(x => x.Id).Contains(x.StockId));
-                foreach (var item in outboundOrderDetails)
+                List<string> palletcodelpn = new List<string>();
+                foreach (var item in newOutboundOrderDetails)
                 {
                     Dt_StockInfo? stockInfo = stockInfos.FirstOrDefault(x => x.PalletCode == item.LPNNo);
                     if (stockInfo == null) continue;
@@ -45,25 +77,39 @@
                     if (stockInfoDetail == null) continue;
                     stockInfoDetail.OutboundQuantity += item.OrderQuantity;
                     item.LockQuantity += item.OrderQuantity;
+                    item.OrderDetailStatus = OrderDetailStatusEnum.Outbound.ObjToInt();
                     var outboundOrder = outboundOrders.FirstOrDefault(x => x.Id == item.OrderId);
-                    Dt_OutStockLockInfo outStockLockInfo = _outboundService.OutboundStockLockInfoService.GetOutStockLockInfo(outboundOrder, item, stockInfo, item.OrderQuantity);
+                    Dt_OutStockLockInfo outStockLockInfo = _outboundService.OutboundStockLockInfoService.GetOutStockLockInfo(outboundOrder, item, stockInfo, stockInfoDetail, item.OrderQuantity);
                     outStockLockInfo.Status = OutStockStatus.鍑哄簱涓�.ObjToInt();
                     item.OrderDetailStatus = OrderDetailStatusEnum.Outbound.ObjToInt();
                     outboundOrder.OrderStatus = OutboundStatusEnum.鍑哄簱涓�.ObjToInt();
+                    stockInfo.StockStatus = StockStatusEmun.鍑哄簱閿佸畾.ObjToInt();
                     var task = Newtasks.FirstOrDefault(x => x.PalletCode == item.LPNNo);
-                    task.OrderNo = outboundOrder.OrderNo;
-                    tasks.Add(task);
+                    if (task != null && !palletcodelpn.Contains(item.LPNNo))
+                    {
+                        if (outboundOrder.OrderType == 1)
+                        {
+                            task.TaskType = TaskTypeEnum.OutProduct.ObjToInt();
+                        }
+                        else if (outboundOrder.OrderType == 2)
+                        {
+                            task.TaskType = TaskTypeEnum.OutAllocate.ObjToInt();
+                        }
+                        task.OrderNo = outboundOrder.OrderNo;
+                        tasks.Add(task);
+                        palletcodelpn.Add(task.PalletCode);
+                    }
                     outStockLockInfo.TaskNum = task.TaskNum;
                     outStockLockInfos.Add(outStockLockInfo);
                 }
                 locationInfos.AddRange(_basicService.LocationInfoService.Repository.GetLocationInfos(stockInfos.Select(x => x.LocationCode).ToList()));
 
-                _unitOfWorkManage.BeginTran();
+
 
                 BaseDal.AddData(tasks);
                 _stockService.StockInfoService.Repository.UpdateData(stockInfos);
                 _stockService.StockInfoDetailService.Repository.UpdateData(stockInfoDetails);
-                _outboundService.NewOutboundOrderDetailService.Repository.UpdateData(outboundOrderDetails);
+                _outboundService.NewOutboundOrderDetailService.Repository.UpdateData(newOutboundOrderDetails);
                 _outboundService.NewOutboundOrderService.Repository.UpdateData(outboundOrders);
                 _outboundService.OutboundStockLockInfoService.Repository.AddData(outStockLockInfos);
                 _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfos, LocationStatusEnum.Lock.ObjToInt(), StockChangeType.Outbound.ObjToInt(), "", tasks?.Select(x => x.TaskNum).ToList());
@@ -71,7 +117,7 @@
 
                 _unitOfWorkManage.CommitTran();
                 //灏嗕换鍔℃帹閫佸埌WCS
-                return PushTasksToWCS(tasks);
+                return PushTasksWCS(tasks);
             }
             catch (Exception ex)
             {
@@ -79,5 +125,177 @@
                 return WebResponseContent.Instance.Error(ex.Message);
             }
         }
+
+        /// <summary>
+        /// 鍚堟墭鍑哄簱
+        /// </summary>
+        /// <param name="keys"></param>
+        /// <returns></returns>
+        public WebResponseContent WMSGenerateSTOutboundTask(int[] keys)
+        {
+            try
+            {
+                List<Dt_Task> tasks = new List<Dt_Task>();
+                List<Dt_LocationInfo> locationInfos = new List<Dt_LocationInfo>();
+                List<Dt_OutStockLockInfo> outStockLockInfos = new List<Dt_OutStockLockInfo>();
+
+                List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.Repository.QueryData(x => keys.Contains(x.Id) && x.StockStatus == StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt());
+                if (stockInfos == null || stockInfos.Count == 0)
+                {
+                    throw new Exception("鏈壘鍒板簱瀛樹俊鎭�,鎴栧簱瀛樼姸鎬佷笉涓哄叆搴撳畬鎴�");
+                }
+                _unitOfWorkManage.BeginTran();
+                var Newtasks = GetTasks(stockInfos, TaskTypeEnum.OutSyncretism);
+                List<Dt_StockInfoDetail> stockInfoDetails = _stockService.StockInfoDetailService.Repository.QueryData(x => stockInfos.Select(x => x.Id).Contains(x.StockId));
+                foreach (var item in stockInfos)
+                {
+                    Dt_StockInfo? stockInfo = stockInfos.FirstOrDefault(x => x.PalletCode == item.PalletCode);
+                    if (stockInfo == null) continue;
+
+                    stockInfo.StockStatus = StockStatusEmun.鍑哄簱閿佸畾.ObjToInt();
+                    var task = Newtasks.FirstOrDefault(x => x.PalletCode == item.PalletCode);
+                    tasks.Add(task);
+                }
+                locationInfos.AddRange(_basicService.LocationInfoService.Repository.GetLocationInfos(stockInfos.Select(x => x.LocationCode).ToList()));
+
+
+
+                BaseDal.AddData(tasks);
+                _stockService.StockInfoService.Repository.UpdateData(stockInfos);
+                _stockService.StockInfoDetailService.Repository.UpdateData(stockInfoDetails);
+                _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfos, LocationStatusEnum.Lock.ObjToInt(), StockChangeType.Outbound.ObjToInt(), "", tasks?.Select(x => x.TaskNum).ToList());
+                _basicService.LocationInfoService.Repository.UpdateLocationStatus(locationInfos, LocationStatusEnum.Lock);
+
+                _unitOfWorkManage.CommitTran();
+                //灏嗕换鍔℃帹閫佸埌WCS
+                return PushTasksWCS(tasks);
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                return WebResponseContent.Instance.Error(ex.Message);
+            }
+        }
+
+        /// <summary>
+        /// SMOM鐩樼偣鍑哄簱
+        /// </summary>
+        /// <param name="keys"></param>
+        /// <returns></returns>
+        public WebResponseContent SMOMGenerateSTOutboundTask(int[] keys)
+        {
+            try
+            {
+                List<Dt_Task> tasks = new List<Dt_Task>();
+                List<Dt_LocationInfo> locationInfos = new List<Dt_LocationInfo>();
+                List<Dt_OutStockLockInfo> outStockLockInfos = new List<Dt_OutStockLockInfo>();
+
+                List<Dt_TakeStockOrderCP> takeStockOrderCPs = _takeStockOrderCPRepository.QueryData(x => keys.Contains(x.Id));
+                if (takeStockOrderCPs == null || takeStockOrderCPs.Count == 0)
+                {
+                    throw new Exception("鏈壘鍒板簱瀛樹俊鎭�,鎴栧簱瀛樼姸鎬佷笉涓哄叆搴撳畬鎴�");
+                }
+                if (takeStockOrderCPs.FirstOrDefault(x => x.TakeStockStatus > TakeStockDetailStatusEnum.鏈洏鐐�.ObjToInt()) != null)
+                {
+                    throw new Exception("鎵�閫夊嚭搴撳崟鏄庣粏瀛樺湪鍑哄簱涓垨宸插畬鎴�");
+                }
+                List<Dt_StockInfo> stockInfos = new List<Dt_StockInfo>();
+                _unitOfWorkManage.BeginTran();
+                foreach (var takeStock in takeStockOrderCPs)
+                {
+                    takeStock.TakeStockStatus = TakeStockStatusEnum.鐩樼偣涓�.ObjToInt();
+                    List<Dt_TakeStockOrderDetailCP> takeStockOrderDetailCPs = _takeStockOrderDetailCPRepository.QueryData(x => x.TakeStockId == takeStock.Id);
+                    foreach (var item in takeStockOrderDetailCPs)
+                    {
+                        item.TakeDetalStatus = TakeStockDetailStatusEnum.鐩樼偣鍑哄簱涓�.ObjToInt();
+                        _takeStockOrderDetailCPRepository.UpdateData(item);
+                    }
+                    var lpngroup = takeStockOrderDetailCPs.GroupBy(x => x.TakePalletCode);
+                    foreach (var lpngroups in lpngroup)
+                    {
+                        string lpn = lpngroups.Key;
+                        Dt_StockInfo? stockInfo = _stockService.StockInfoService.Repository.QueryFirst(x => x.PalletCode == lpn);
+                        if (stockInfo == null)
+                        {
+                            throw new Exception($"鏈壘鍒板簱瀛樹俊鎭紝鎵樼洏鍙穥lpn}");
+                        }
+                        stockInfos.Add(stockInfo);
+                    }
+                    if (stockInfos == null || stockInfos.Count == 0)
+                    {
+                        throw new Exception("鏈壘鍒板簱瀛樹俊鎭�");
+                    }
+                }
+
+                var Newtasks = GetTasks(stockInfos, TaskTypeEnum.OutInventory);
+                List<Dt_StockInfoDetail> stockInfoDetails = _stockService.StockInfoDetailService.Repository.QueryData(x => stockInfos.Select(x => x.Id).Contains(x.StockId));
+                foreach (var item in stockInfos)
+                {
+                    Dt_StockInfo? stockInfo = stockInfos.FirstOrDefault(x => x.PalletCode == item.PalletCode);
+                    if (stockInfo == null) continue;
+
+                    stockInfo.StockStatus = StockStatusEmun.鍑哄簱閿佸畾.ObjToInt();
+                    var task = Newtasks.FirstOrDefault(x => x.PalletCode == item.PalletCode);
+                    tasks.Add(task);
+                }
+                locationInfos.AddRange(_basicService.LocationInfoService.Repository.GetLocationInfos(stockInfos.Select(x => x.LocationCode).ToList()));
+
+
+
+                BaseDal.AddData(tasks);
+                _stockService.StockInfoService.Repository.UpdateData(stockInfos);
+                _stockService.StockInfoDetailService.Repository.UpdateData(stockInfoDetails);
+                _takeStockOrderCPRepository.UpdateData(takeStockOrderCPs);
+                _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfos, LocationStatusEnum.Lock.ObjToInt(), StockChangeType.Outbound.ObjToInt(), "", tasks?.Select(x => x.TaskNum).ToList());
+                _basicService.LocationInfoService.Repository.UpdateLocationStatus(locationInfos, LocationStatusEnum.Lock);
+
+                _unitOfWorkManage.CommitTran();
+                //灏嗕换鍔℃帹閫佸埌WCS
+                return PushTasksWCS(tasks);
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                return WebResponseContent.Instance.Error(ex.Message);
+            }
+        }
+
+        /// <summary>
+        /// SMOM鐩樼偣鍚庡簱瀛樿皟鏁�
+        /// </summary>
+        /// <param name="houseAdjustment"></param>
+        /// <returns></returns>
+        public WebResponseContent SMOMAdjustment(HouseAdjustment houseAdjustment)
+        {
+            WebResponseContent responseContent = new WebResponseContent();
+            try
+            {
+                if (houseAdjustment.DetailList.Count == 0)
+                {
+                    return WebResponseContent.Instance.Error("鏃犳槑缁嗕俊鎭�");
+                }
+                List<Dt_StockInfoDetail> stockdetail = new List<Dt_StockInfoDetail>();
+                foreach (var item in houseAdjustment.DetailList)
+                {
+                    var dt_StockInfo = BaseDal.Db.Queryable<Dt_StockInfoDetail>().LeftJoin<Dt_StockInfo>((stockdetail, stock) => stockdetail.StockId == stock.Id)
+                         .Where((stockdetail, stock) => stockdetail.MaterielCode == item.MaterielCode && stockdetail.BatchNo == item.BatchNo && stock.PalletCode == item.LPNNo).Select((stockdetail, stock) => stockdetail).First();
+                    if (dt_StockInfo != null)
+                    {
+                        dt_StockInfo.StockQuantity = item.OrderQuantity;
+                        stockdetail.Add(dt_StockInfo);
+                    }
+
+                }
+                _unitOfWorkManage.BeginTran();
+                _stockInfoDetailRepository.UpdateData(stockdetail);
+                _unitOfWorkManage.CommitTran();
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                return WebResponseContent.Instance.Error($"Error: {ex.Message}");
+            }
+            return WebResponseContent.Instance.OK();
+        }
     }
 }

--
Gitblit v1.9.3