From 2a978847c0dfef510349b097ef8202afe5647997 Mon Sep 17 00:00:00 2001
From: yangpeixing <yangpeixing@hnkhzn.com>
Date: 星期四, 22 一月 2026 15:47:27 +0800
Subject: [PATCH] 1

---
 WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/NewPartialTaskService_Outbound.cs |  310 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 305 insertions(+), 5 deletions(-)

diff --git a/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/NewPartialTaskService_Outbound.cs b/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/NewPartialTaskService_Outbound.cs
index 1ab57a2..9f43953 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
@@ -41,7 +50,7 @@
                     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);
+                    Dt_StockInfo? stockInfo = _stockService.StockInfoService.Repository.QueryFirst(x => x.PalletCode == lpn && x.LocationCode != null);
                     if (stockInfo == null)
                     {
                         throw new Exception($"鏈壘鍒板簱瀛樹俊鎭紝鎵樼洏鍙穥lpn}");
@@ -56,6 +65,7 @@
                 }
                 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));
                 List<string> palletcodelpn = new List<string>();
@@ -94,7 +104,7 @@
                 }
                 locationInfos.AddRange(_basicService.LocationInfoService.Repository.GetLocationInfos(stockInfos.Select(x => x.LocationCode).ToList()));
 
-                _unitOfWorkManage.BeginTran();
+
 
                 BaseDal.AddData(tasks);
                 _stockService.StockInfoService.Repository.UpdateData(stockInfos);
@@ -116,7 +126,11 @@
             }
         }
 
-        //鍚堟墭鍑哄簱
+        /// <summary>
+        /// 鍚堟墭鍑哄簱
+        /// </summary>
+        /// <param name="keys"></param>
+        /// <returns></returns>
         public WebResponseContent WMSGenerateSTOutboundTask(int[] keys)
         {
             try
@@ -130,7 +144,7 @@
                 {
                     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)
@@ -144,7 +158,7 @@
                 }
                 locationInfos.AddRange(_basicService.LocationInfoService.Repository.GetLocationInfos(stockInfos.Select(x => x.LocationCode).ToList()));
 
-                _unitOfWorkManage.BeginTran();
+
 
                 BaseDal.AddData(tasks);
                 _stockService.StockInfoService.Repository.UpdateData(stockInfos);
@@ -162,5 +176,291 @@
                 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("鏈壘鍒板簱瀛樹俊鎭�");
+                    }
+                }
+                string orderNo = takeStockOrderCPs.FirstOrDefault().OrderNo;
+                var Newtasks = GetTask(stockInfos, TaskTypeEnum.OutInventory, orderNo);
+                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)
+                {
+                    Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.QueryFirst(x => x.PalletCode == item.LPNNo);
+                    if (stockInfo == null)
+                    {
+                        return WebResponseContent.Instance.Error("鏈壘鍒版鎵樼洏搴撳瓨");
+                    }
+                    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);
+                    }
+                    else
+                    {
+                        Dt_StockInfoDetail stockInfoDetail = new Dt_StockInfoDetail()
+                        {
+                            StockId = stockInfo.Id,
+                            MaterielCode = item.MaterielCode,
+                            MaterielName = item.MaterielName,
+                            OrderNo = dt_StockInfo.OrderNo,
+                            BatchNo = item.BatchNo,
+                            SupplierBatch = dt_StockInfo.SupplierBatch,
+                            LinId = item.LinId,
+                            StockQuantity = item.OrderQuantity,
+                            Status = (int)StockStatusEmun.缁勭洏鏆傚瓨,
+                            Creater = "WMS",
+                            CreateDate = DateTime.Now,
+                            Id = item.LinId.ObjToInt(),
+                            MaterieSpec = dt_StockInfo.MaterieSpec,
+                            OrinalLocation = dt_StockInfo.OrinalLocation
+                        };
+                        stockdetail.Add(stockInfoDetail);
+                    }
+
+                }
+                _unitOfWorkManage.BeginTran();
+                _stockInfoDetailRepository.UpdateData(stockdetail);
+                _unitOfWorkManage.CommitTran();
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                return WebResponseContent.Instance.Error($"Error: {ex.Message}");
+            }
+            return WebResponseContent.Instance.OK();
+        }
+
+        /// <summary>
+        /// SMOM鍙戣揣鍚庢垚鍝佺搴撳瓨璋冩暣
+        /// </summary>
+        /// <param name="houseStockDetail"></param>
+        /// <returns></returns>
+        public WebResponseContent SMOMStock(HouseStockDetail houseStockDetail)
+        {
+            WebResponseContent responseContent = new WebResponseContent();
+            try
+            {
+                if (houseStockDetail.DetailList.Count == 0)
+                {
+                    return WebResponseContent.Instance.Error("鏃犳槑缁嗕俊鎭�");
+                }
+                List<Dt_StockInfoDetail> stockdetail = new List<Dt_StockInfoDetail>();
+                var allBoxCodes = new List<string>();
+                _unitOfWorkManage.BeginTran();
+                foreach (var item in houseStockDetail.DetailList)
+                {
+                    // 妫�鏌ユ槑缁嗗垪琛ㄦ槸鍚﹀瓨鍦ㄤ笖鏈夋晥
+                    if (item.LabelList == null || item.LabelList.Count == 0)
+                    {
+                        return WebResponseContent.Instance.Error($"鎵樼洏{item.LPNNo}鏃犵鐮佹槑缁嗕俊鎭�");
+                    }
+                    allBoxCodes.AddRange(item.LabelList);
+
+                    Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.QueryFirst(x => x.PalletCode == item.LPNNo);
+                    if (stockInfo == null)
+                    {
+                        return WebResponseContent.Instance.Error("鏈壘鍒版鎵樼洏搴撳瓨");
+                    }
+
+                    var stockdetailbox = BaseDal.Db.Queryable<Dt_StockInfo>().LeftJoin<Dt_StockInfoDetail>((s, d) => s.Id == d.StockId).LeftJoin<Dt_StockInfoDetailCP>((s, d, cp) => d.Id == cp.StockDetailId).Where((s, d, cp) => allBoxCodes.Contains(cp.BoxCode)).Select((s, d, cp) => cp.BoxCode)
+                .Distinct()
+                .ToList();
+
+                    var stockInfoDetailCPList = _stockInfoDetailCPRepository.QueryData(x => stockdetailbox.Contains(x.BoxCode)).ToList();
+                    if (stockInfoDetailCPList != null)
+                    {
+                        _stockInfoDetailCPRepository.DeleteAndMoveIntoHty(stockInfoDetailCPList, App.User.UserId == 0 ? OperateType.鑷姩瀹屾垚 : OperateType.浜哄伐瀹屾垚);
+                    }
+                }
+                _unitOfWorkManage.CommitTran();
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                return WebResponseContent.Instance.Error($"Error: {ex.Message}");
+            }
+            return WebResponseContent.Instance.OK();
+        }
+
+        public List<Dt_Task> GetTask(List<Dt_StockInfo> stockInfos, TaskTypeEnum taskType, string orderNo)
+        {
+            List<Dt_Task> tasks = new List<Dt_Task>();
+            for (int i = 0; i < stockInfos.Count; i++)
+            {
+                Dt_StockInfo stockInfo = stockInfos[i];
+
+                if (stockInfo != null)
+                {
+                    Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == stockInfo.LocationCode);
+                    if (locationInfo == null)
+                    {
+                        throw new Exception("鏈壘鍒板嚭搴撳簱浣�");
+                    }
+                    Dt_Task dt_Task = BaseDal.QueryFirst(x => x.SourceAddress == locationInfo.LocationCode || x.TargetAddress == locationInfo.LocationCode);
+                    if (dt_Task != null)
+                    {
+                        throw new Exception("璇ヨ揣浣嶅凡瀛樺湪璧风偣浠诲姟鎴栫粓鐐逛换鍔�");
+                    }
+                    Dt_Task dt_Task1 = BaseDal.QueryFirst(x => x.PalletCode == stockInfo.PalletCode);
+                    if (dt_Task1 != null)
+                    {
+                        throw new Exception("璇ユ墭鐩樺凡瀛樺湪浠诲姟");
+                    }
+                    Dt_RoadwayInfo roadwayInfo = _basicService.RoadwayInfoService.Repository.QueryFirst(x => x.RoadwayNo == locationInfo.RoadwayNo);
+                    Dt_StockInfoDetail stockInfoDetail = _stockService.StockInfoDetailService.Repository.QueryFirst(x => x.StockId == stockInfo.Id);
+                    if (roadwayInfo != null)
+                    {
+                        if (roadwayInfo.RoadwayNo.Contains("CP"))
+                        {
+                            Dt_Task task = new()
+                            {
+                                PalletType = stockInfo.PalletType,
+                                OrderNo = orderNo,
+                                CurrentAddress = locationInfo.LocationCode,
+                                Grade = 0,
+                                Creater = "WMS",
+                                PalletCode = stockInfo.PalletCode,
+                                NextAddress = roadwayInfo.OutSCStationCode,
+                                Roadway = locationInfo.RoadwayNo,
+                                SourceAddress = locationInfo.LocationCode,
+                                TargetAddress = "",
+                                TaskStatus = OutTaskStatusEnum.OutNew.ObjToInt(),
+                                TaskType = taskType.ObjToInt(),
+                                Depth = locationInfo.Depth,
+                                WarehouseId = stockInfo.WarehouseId,
+                                TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
+                                MaterielCode = stockInfoDetail.MaterielCode,
+                                Quantity = (float)stockInfoDetail.StockQuantity
+                            };
+                            tasks.Add(task);
+                        }
+                        else
+                        {
+                            Dt_Task task = new()
+                            {
+                                PalletType = stockInfo.PalletType,
+                                OrderNo = stockInfoDetail.OrderNo,
+                                CurrentAddress = locationInfo.LocationCode,
+                                Grade = 0,
+                                Creater = "WMS",
+                                PalletCode = stockInfo.PalletCode,
+                                NextAddress = roadwayInfo.OutSCStationCode,
+                                Roadway = locationInfo.RoadwayNo,
+                                SourceAddress = locationInfo.LocationCode,
+                                TargetAddress = "",
+                                TaskStatus = OutTaskStatusEnum.OutNew.ObjToInt(),
+                                TaskType = taskType.ObjToInt(),
+                                Depth = locationInfo.Depth,
+                                WarehouseId = stockInfo.WarehouseId,
+                                TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum))
+                            };
+                            if (taskType != TaskTypeEnum.OutEmpty)
+                            {
+                                task.MaterielCode = stockInfo.Details?.Where(x => x.StockId == stockInfo.Id).FirstOrDefault()?.MaterielCode;
+                                task.Quantity = (float)stockInfo.Details?.Where(x => x.StockId == stockInfo.Id).Sum(x => x.StockQuantity);
+                            }
+                            tasks.Add(task);
+                        }
+
+                    }
+                }
+
+            }
+            return tasks;
+        }
     }
 }

--
Gitblit v1.9.3