From ca2d4d7efb253c651b7eb6dc070ec8fae4d39a27 Mon Sep 17 00:00:00 2001
From: 647556386 <647556386@qq.com>
Date: 星期二, 03 二月 2026 19:11:06 +0800
Subject: [PATCH] 1

---
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundService.cs |  246 +++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 218 insertions(+), 28 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundService.cs"
index 99bb3e2..6cf7303 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundService.cs"
@@ -22,12 +22,14 @@
 using WIDESEA_DTO.Base;
 using WIDESEA_DTO.Basic;
 using WIDESEA_DTO.CalcOut;
+using WIDESEA_DTO.Outbound;
 using WIDESEA_DTO.ReturnMES;
 using WIDESEA_IBasicService;
 using WIDESEA_IOutboundService;
 using WIDESEA_IRecordService;
 using WIDESEA_IStockService;
 using WIDESEA_Model.Models;
+using WIDESEA_Model.Models.Check;
 using static HslCommunication.Profinet.Knx.KnxCode;
 
 namespace WIDESEA_OutboundService
@@ -61,6 +63,8 @@
         private readonly IESSApiService _eSSApiService;
         private readonly IRepository<Dt_AllocateOrder> _allocateOrderRepository;
         private readonly IRepository<Dt_AllocateMaterialInfo> _allocateMaterialInfoRepository;
+        public readonly IRepository<Dt_InboundOrderDetail> _inboundOrderDetailRepository;
+        public readonly IRepository<Dt_InboundOrder> _inboundOrderRepository;
 
         private Dictionary<string, string> stations = new Dictionary<string, string>
         {
@@ -74,7 +78,7 @@
             {"3-1","3-5" },
         };
 
-        public OutboundService(IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IRepository<Dt_OutboundOrderDetail> detailRepository, IRepository<Dt_OutboundOrder> outboundRepository, IRepository<Dt_OutStockLockInfo> outboundLockInfoRepository, IRepository<Dt_StockInfo> stockInfoRepository, IRepository<Dt_StockInfoDetail> stockDetailRepository, IRepository<Dt_StockQuantityChangeRecord> stockChangeRepository, IRepository<Dt_StockInfoDetail_Hty> stockDetailHistoryRepository, IBasicService basicService, IOutboundOrderDetailService outboundOrderDetailService, IOutboundOrderService outboundOrderService, IOutStockLockInfoService outboundStockLockInfoService, IFeedbackMesService feedbackMesService, IRepository<Dt_Task> taskRepository, ILocationInfoService locationInfoService, IESSApiService eSSApiService, IRepository<Dt_AllocateOrder> allocateOrderRepository, IRepository<Dt_AllocateMaterialInfo> allocateMaterialInfoRepository)
+        public OutboundService(IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IRepository<Dt_OutboundOrderDetail> detailRepository, IRepository<Dt_OutboundOrder> outboundRepository, IRepository<Dt_OutStockLockInfo> outboundLockInfoRepository, IRepository<Dt_StockInfo> stockInfoRepository, IRepository<Dt_StockInfoDetail> stockDetailRepository, IRepository<Dt_StockQuantityChangeRecord> stockChangeRepository, IRepository<Dt_StockInfoDetail_Hty> stockDetailHistoryRepository, IBasicService basicService, IOutboundOrderDetailService outboundOrderDetailService, IOutboundOrderService outboundOrderService, IOutStockLockInfoService outboundStockLockInfoService, IFeedbackMesService feedbackMesService, IRepository<Dt_Task> taskRepository, ILocationInfoService locationInfoService, IESSApiService eSSApiService, IRepository<Dt_AllocateOrder> allocateOrderRepository, IRepository<Dt_AllocateMaterialInfo> allocateMaterialInfoRepository, IRepository<Dt_InboundOrderDetail> inboundOrderDetailRepository, IRepository<Dt_InboundOrder> inboundOrderRepository)
         {
             _mapper = mapper;
             _unitOfWorkManage = unitOfWorkManage;
@@ -97,6 +101,35 @@
             _eSSApiService = eSSApiService;
             _allocateOrderRepository = allocateOrderRepository;
             _allocateMaterialInfoRepository = allocateMaterialInfoRepository;
+            _inboundOrderDetailRepository = inboundOrderDetailRepository;
+            _inboundOrderRepository = inboundOrderRepository;
+        }
+
+        public WebResponseContent PrintFromData (string barcode)
+        {
+            var detail = _inboundOrderDetailRepository.QueryFirst(x => x.Barcode == barcode);
+            if(detail == null)
+            {
+                return WebResponseContent.Instance.Error();
+            }
+
+            var inbound = _inboundOrderRepository.QueryFirst(x=>x.Id ==  detail.OrderId);
+            if(inbound == null)
+            {
+                return WebResponseContent.Instance.Error();
+            }
+            var printFormData = new PrintFromDataDTO { 
+                materialCode = detail.MaterielCode,
+                materialName = detail.MaterielName,
+                materialSpec = detail.Unit,
+                batchNo = detail.BatchNo,
+                pruchaseOrderNo = inbound.UpperOrderNo,
+                factoryArea = inbound.FactoryArea,
+                suplierCode = detail.SupplyCode,
+                quantity = detail.BarcodeQty
+            };
+
+            return WebResponseContent.Instance.OK(data:printFormData);
         }
 
         #region 鍑哄簱鍒嗛厤
@@ -176,7 +209,7 @@
                     foreach (var detail in materielCalc.Details)
                     {
                         if (remainingToLock <= 0) break;
-                        decimal maxLockableQty = detail.OrderQuantity - detail.OverOutQuantity - detail.LockQuantity;
+                        decimal maxLockableQty = detail.OrderQuantity - detail.OverOutQuantity;
                         if (maxLockableQty <= 0) continue;
                         decimal currentLockQty = Math.Min(remainingToLock, maxLockableQty);
                         detail.LockQuantity += currentLockQty;
@@ -193,15 +226,27 @@
                     UpdateStockStatus(pickedDetails.Select(x => x.PalletCode).ToList(), StockStatusEmun.鍑哄簱閿佸畾.ObjToInt());
                     UpdateLocationStatus(pickedDetails.Select(x => x.LocationCode).ToList(), LocationStatusEnum.Lock.ObjToInt());
                 }
-                UpdateOutStockLockInfo(outStockLockInfos);
+                //閲嶆鍗曚笉鎷i�夛紝鍘绘帀閿佸畾璁板綍鍥炲簱锛屽啀娆$粍鐩樻椂鎵i櫎鍘熸潯鐮�
+                if (outboundOrder.OrderType != InOrderTypeEnum.ReCheck.ObjToInt())
+                {
+                    UpdateOutStockLockInfo(outStockLockInfos);
+                }
+                
                 if (tasks.Any()) _taskRepository.AddData(tasks);
 
-                _unitOfWorkManage.CommitTran();
+                
+                    _unitOfWorkManage.CommitTran();
 
                 // 4. 鏋勯�犲搷搴旓細鍖哄垎銆屽叏閮ㄥ垎閰嶃�嶅拰銆岄儴鍒嗗垎閰嶃��
                 string responseMsg = totalActualAllocate == totalNeedAllocate
                     ? "鍒嗘嫞浠诲姟鍒嗛厤鎴愬姛"
                     : $"鍒嗘嫞浠诲姟鍒嗛厤瀹屾垚锛堝疄闄呭垎閰峽totalActualAllocate}锛岄渶姹倇totalNeedAllocate}锛屽簱瀛樹笉瓒抽儴鍒嗘湭鍒嗛厤锛�";
+                Dt_OutboundOrder outboundOrder1 = _outboundRepository.Db.Queryable<Dt_OutboundOrder>().Where(x => x.OrderNo == request.OrderNo).Includes(x=>x.Details).First();
+                if(totalActualAllocate == 0 && !outboundOrder1.Details.Any(x=>x.LockQuantity >0))
+                {
+                    UpdateOutboundOrderStatus(request.OrderNo, (int)OutOrderStatusEnum.鏈紑濮�);
+                    return WebResponseContent.Instance.Error("鍒嗛厤搴撳瓨鏁伴噺涓�0锛屾棤娉曞嚭搴�");
+                }
                 response.Success = true;
                 response.Message = responseMsg;
                 response.Tasks = tasks;
@@ -484,7 +529,7 @@
                 x => request.StockDetailIds.Contains(x.Id)
                 && x.MaterielCode == materielCalc.MaterielCode
                 && x.StockQuantity > 0
-                && (x.Status == (int)StockStatusEmun.鍏ュ簱瀹屾垚 || x.Status == (int)StockStatusEmun.鎵嬪姩瑙i攣));
+                && (x.Status == (int)StockStatusEmun.鍏ュ簱瀹屾垚 || x.Status == (int)StockStatusEmun.鎵嬪姩鍐荤粨 || x.Status == (int)StockStatusEmun.鎵嬪姩瑙i攣 || x.Status == (int)StockStatusEmun.杩囨湡));
 
             if (!specifiedStockDetails.Any())
             {
@@ -593,7 +638,7 @@
 
             List<int> stockIds = stockDetailList.GroupBy(x => x.StockId).Select(x => x.Key).ToList();
             List<Dt_StockInfo> stockInfos = _stockInfoRepository.QueryData(x =>
-                stockIds.Contains(x.Id) && (x.StockStatus == StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt() || x.StockStatus == StockStatusEmun.鍑哄簱閿佸畾.ObjToInt())
+                stockIds.Contains(x.Id) && (x.StockStatus == StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt())
                 && !string.IsNullOrEmpty(x.LocationCode) && locationCodes.Contains(x.LocationCode));
 
             foreach (var stockInfo in stockInfos)
@@ -670,15 +715,13 @@
                     decimal totalAllocatedQuantity = CalcTotalAllocatedQuantity(lockInfos, stockInfo.Id, detail.MaterielCode);
                     lockInfo.AssignQuantity += actualAllocatedQuantity;
                     lockInfo.AllocatedQuantity = totalAllocatedQuantity;
-                    // 瀛橀噺閿佸畾璁板綍涔熸洿鏂癘riginalQuantity涓烘墭鐩樻�诲簱瀛橈紙鍙�夛紝淇濇寔鏁版嵁涓�鑷达級
                     if (palletMaterielTotalStock > 0)
                         lockInfo.OriginalQuantity = palletMaterielTotalStock;
                     lockInfoList.Add(lockInfo);
                 }
                 else
                 {
-                    // ===== 鏍稿績浼樺寲2锛歄riginalQuantity璧嬪�间负鎵樼洏鐗╂枡鎬诲簱瀛� =====
-                    decimal originalQuantity = palletMaterielTotalStock; // 鏇夸唬鍘熸湁灞�閮ㄦ槑缁嗘暟閲�
+                    decimal originalQuantity = palletMaterielTotalStock;
 
                     List<string> allDetailIds = outboundOrder.Details.Where(x =>
                         x.OrderId == outboundOrder.Id && x.MaterielCode == detail.MaterielCode
@@ -763,6 +806,10 @@
                 Dt_OutboundOrder outboundOrder = _outboundRepository.QueryFirst(x => x.OrderNo == orderNo);
                 if (outboundOrder == null) return false;
                 outboundOrder.OrderStatus = status;
+                if(outboundOrder.CreateType == OrderCreateTypeEnum.CreateInSystem.ObjToInt())
+                {
+                    outboundOrder.ReturnToMESStatus = 5;
+                }
                 _outboundRepository.UpdateData(outboundOrder);
                 return true;
             }
@@ -978,7 +1025,7 @@
                     // 鏁寸鍑哄簱鏃犻渶鎷嗗寘
                     PerformFullOutboundOperation(stockInfo, request, lockInfo.TaskNum.GetValueOrDefault());
 
-                    if (outboundOrder.OrderType != 0)
+                    if (outboundOrder.OrderType == InOrderTypeEnum.InternalAllocat.ObjToInt())
                     {
                         Dt_AllocateOrder allocateOrder = _allocateOrderRepository.QueryFirst(x => x.OrderNo == outboundOrder.OrderNo);
                         if (allocateOrder != null)
@@ -1004,6 +1051,29 @@
                             }
                             _allocateMaterialInfoRepository.AddData(allocateMaterialInfos);
                         }
+                    }
+                    else if(outboundOrder.OrderType == InOrderTypeEnum.ReCheck.ObjToInt())
+                    {
+                        List<Dt_AllocateMaterialInfo> allocateMaterialInfos = new List<Dt_AllocateMaterialInfo>();
+                        foreach (var item in stockInfo.Details)
+                        {
+                            Dt_AllocateMaterialInfo allocateMaterialInfo = new Dt_AllocateMaterialInfo()
+                            {
+                                Barcode = item.Barcode??"",
+                                BatchNo = item.BatchNo,
+                                FactoryArea = item.FactoryArea,
+                                MaterialCode = item.MaterielCode,
+                                MaterialName = item.MaterielName,
+                                OrderId = outboundOrder.Id,
+                                OrderNo = outboundOrder.OrderNo,
+                                Quantity = item.StockQuantity,
+                                SupplyCode = item.SupplyCode??"",
+                                Unit = item.Unit,
+                                WarehouseCode = item.WarehouseCode??""
+                            };
+                            allocateMaterialInfos.Add(allocateMaterialInfo);
+                        }
+                        _allocateMaterialInfoRepository.AddData(allocateMaterialInfos);
                     }
 
                     decimal allocatedQuantity = actualOutboundQuantity;
@@ -1081,8 +1151,15 @@
                         {
                             barcodeQuantity = item.LockQuantity - item.OverOutQuantity;
                             allocatedQuantity -= (item.LockQuantity - item.OverOutQuantity);
+                            if(item.ReturnToMESStatus == 0)
+                            {
+                                item.CurrentDeliveryQty = item.LockQuantity;
+                            }
+                            else
+                            {
+                                item.CurrentDeliveryQty = item.LockQuantity - item.OverOutQuantity;
+                            }
                             item.OverOutQuantity = item.LockQuantity;
-                            item.CurrentDeliveryQty = item.LockQuantity;
                         }
 
                         updateDetails.Add(item);
@@ -1098,6 +1175,11 @@
                             ContractResolver = new CamelCasePropertyNamesContractResolver()
                         };
                         item.ReturnJsonData = JsonConvert.SerializeObject(barcodesList, settings);
+                        //閲嶆嫞鍑哄簱涓嶉渶瑕佸洖浼�
+                        if (outboundOrder.OrderType == InOrderTypeEnum.ReCheck.ObjToInt())
+                        {
+                            item.ReturnJsonData = "";
+                        }
                     }
 
                     lockInfo.SortedQuantity = lockInfo.SortedQuantity + actualOutboundQuantity;
@@ -1125,12 +1207,27 @@
                     response.Message = "鍑哄簱瀹屾垚";
                     response.UpdatedDetails = updateDetails;
 
+                    if (CheckOutboundOrderDetailCompletedByMatCode(request.OrderNo, lockInfo.MaterielCode, outboundOrderDetails))
+                    {
+                        Func<Dt_OutStockLockInfo, bool> supWhere = x => string.IsNullOrEmpty(outboundOrderDetails.First().SupplyCode) ? true : x.SupplyCode == outboundOrderDetails.First().SupplyCode;
+
+                        Func<Dt_OutStockLockInfo, bool> wareWhere = x => string.IsNullOrEmpty(outboundOrderDetails.First().WarehouseCode) ? true : x.WarehouseCode == outboundOrderDetails.First().WarehouseCode;
+
+                        List<Dt_OutStockLockInfo> stockLockInfos = _outboundLockInfoRepository.QueryData(x =>
+                                x.OrderNo == request.OrderNo &&
+                                x.MaterielCode == stockInfoDetail.MaterielCode).Where(supWhere).Where(wareWhere).ToList();
+                        if (stockLockInfos != null && stockLockInfos.Any())
+                        {
+                            _outboundLockInfoRepository.DeleteAndMoveIntoHty(stockLockInfos, WIDESEA_Core.Enums.OperateTypeEnum.鑷姩鍒犻櫎);
+                        }
+                    }
+
                     // 妫�鏌ュ嚭搴撳崟鏄惁瀹屾垚
                     if (CheckOutboundOrderCompleted(request.OrderNo))
                     {
                         UpdateOutboundOrderStatus(request.OrderNo, OutOrderStatusEnum.鍑哄簱瀹屾垚.ObjToInt());
 
-                        if (outboundOrder.OrderType != OutOrderTypeEnum.InternalAllocat.ObjToInt())
+                        if (outboundOrder.OrderType != OutOrderTypeEnum.InternalAllocat.ObjToInt()&& outboundOrder.OrderType!= InOrderTypeEnum.ReCheck.ObjToInt())
                         {
                             _feedbackMesService.OutboundFeedback(outboundOrder.OrderNo);
                         }
@@ -1359,7 +1456,7 @@
 
                         MaterialCodeReturnDTO returnDTO = returnDTOs.First(x => x.Barcode == newBarcode);
 
-                        if (outboundOrder.OrderType != 0)
+                        if (outboundOrder.OrderType == InOrderTypeEnum.ReCheck.ObjToInt()||outboundOrder.OrderType == InOrderTypeEnum.InternalAllocat.ObjToInt())
                         {
                             allocateMaterialInfo = new Dt_AllocateMaterialInfo()
                             {
@@ -1381,7 +1478,7 @@
                     {
                         PerformFullOutboundOperation(stockDetail, stockInfo, actualOutboundQuantity, request, beforeQuantity, lockInfo.TaskNum.GetValueOrDefault());
 
-                        if (outboundOrder.OrderType != 0)
+                        if (outboundOrder.OrderType == InOrderTypeEnum.ReCheck.ObjToInt() || outboundOrder.OrderType == InOrderTypeEnum.InternalAllocat.ObjToInt())
                         {
                             allocateMaterialInfo = new Dt_AllocateMaterialInfo()
                             {
@@ -1400,8 +1497,8 @@
 
                     }
 
-                    // 鍒ゆ柇鏄惁鏄皟鎷ㄥ崟
-                    if (outboundOrder.OrderType != 0)
+                    // 鍒ゆ柇鏄惁鏄櫤浠撹皟鏅轰粨鍗�
+                    if ( outboundOrder.OrderType == InOrderTypeEnum.InternalAllocat.ObjToInt())
                     {
                         Dt_AllocateOrder allocateOrder = _allocateOrderRepository.QueryFirst(x => x.OrderNo == outboundOrder.OrderNo);
                         if (allocateOrder != null)
@@ -1441,8 +1538,15 @@
                         {
                             barcodeQuantity = item.LockQuantity - item.OverOutQuantity;
                             allocatedQuantity -= (item.LockQuantity - item.OverOutQuantity);
+                            if (item.ReturnToMESStatus == 0)
+                            {
+                                item.CurrentDeliveryQty = item.LockQuantity;
+                            }
+                            else
+                            {
+                                item.CurrentDeliveryQty += item.LockQuantity - item.OverOutQuantity;
+                            }
                             item.OverOutQuantity = item.LockQuantity;
-                            item.CurrentDeliveryQty = item.LockQuantity;
                         }
 
                         updateDetails.Add(item);
@@ -1518,8 +1622,7 @@
                         _feedbackMesService.BarcodeFeedback(newBarcode);
                     }
 
-                    // 鍒犻櫎閿佸畾璁板綍锛堝鏋滃嚭搴撴槑缁嗗叏閮ㄥ畬鎴愶級 涓嶤alculateActualOutboundQuantity鏂规硶閲岄潰娉ㄩ噴浠g爜2閫�1浣跨敤
-                    if (CheckOutboundOrderDetailCompletedByMatCode(request.OrderNo, lockInfo.MaterielCode, outboundOrderDetails.First()))
+                    if (CheckOutboundOrderDetailCompletedByMatCode(request.OrderNo, lockInfo.MaterielCode, outboundOrderDetails))
                     {
                         Func<Dt_OutStockLockInfo, bool> supWhere = x => string.IsNullOrEmpty(outboundOrderDetails.First().SupplyCode) ? true : x.SupplyCode == outboundOrderDetails.First().SupplyCode;
 
@@ -1533,18 +1636,18 @@
                             _outboundLockInfoRepository.DeleteAndMoveIntoHty(stockLockInfos, WIDESEA_Core.Enums.OperateTypeEnum.鑷姩鍒犻櫎);
                         }
                     }
+                    
 
                     // 妫�鏌ュ嚭搴撳崟鏄惁瀹屾垚
                     if (CheckOutboundOrderCompleted(request.OrderNo))
                     {
                         UpdateOutboundOrderStatus(request.OrderNo, OutOrderStatusEnum.鍑哄簱瀹屾垚.ObjToInt());
 
-                        if (outboundOrder.OrderType != OutOrderTypeEnum.InternalAllocat.ObjToInt())
+                        if (outboundOrder.OrderType != OutOrderTypeEnum.InternalAllocat.ObjToInt() && outboundOrder.CreateType!=OrderCreateTypeEnum.CreateInSystem.ObjToInt())
                         {
                             _feedbackMesService.OutboundFeedback(outboundOrder.OrderNo);
                         }
                     }
-
                 }
                 catch (Exception ex)
                 {
@@ -1873,14 +1976,30 @@
         /// <summary>
         /// 妫�鏌ュ嚭搴撳崟鏄庣粏鏄惁瀹屾垚
         /// </summary>
-        public bool CheckOutboundOrderDetailCompletedByMatCode(string orderNo, string materialCode, Dt_OutboundOrderDetail outboundOrderDetail)
+        public bool CheckOutboundOrderDetailCompletedByMatCode(string orderNo, string materialCode, List<Dt_OutboundOrderDetail> outboundOrderDetails)
         {
+            if (string.IsNullOrEmpty(orderNo) || string.IsNullOrEmpty(materialCode) || outboundOrderDetails == null || !outboundOrderDetails.Any())
+                return false;
+
+            // 鏌ヨ涓昏鍗曪紝涓嶅瓨鍦ㄧ洿鎺ヨ繑鍥瀎alse
             Dt_OutboundOrder outboundOrder = _outboundRepository.QueryFirst(x => x.OrderNo == orderNo);
             if (outboundOrder == null) return false;
 
-            List<Dt_OutboundOrderDetail> details = _detailRepository.QueryData(x => x.OrderId == outboundOrder.Id && x.MaterielCode == materialCode && (string.IsNullOrEmpty(outboundOrderDetail.SupplyCode) || x.SupplyCode == outboundOrderDetail.SupplyCode) && (string.IsNullOrEmpty(outboundOrderDetail.WarehouseCode) || x.WarehouseCode == outboundOrderDetail.WarehouseCode));
+            var firstDetail = outboundOrderDetails.FirstOrDefault();
+            string supplyCode = firstDetail.SupplyCode;
+            string warehouseCode = firstDetail.WarehouseCode;
+            List<int> ids = outboundOrderDetails.Select(x => x.Id).ToList();
 
-            // 妫�鏌ユ墍鏈夋槑缁嗙殑宸插嚭鏁伴噺鏄惁閮界瓑浜庡崟鎹暟閲�
+            List<Dt_OutboundOrderDetail> details = _detailRepository.QueryData(x =>
+                x.OrderId == outboundOrder.Id
+                && x.MaterielCode == materialCode
+                && ids.Contains(x.Id)
+                && (string.IsNullOrEmpty(supplyCode) || x.SupplyCode == supplyCode)
+                && (string.IsNullOrEmpty(warehouseCode) || x.WarehouseCode == warehouseCode)
+            );
+
+            if (!details.Any()) return false;
+
             return details.All(x => x.OverOutQuantity >= x.OrderQuantity - x.MoveQty);
         }
 
@@ -1893,6 +2012,12 @@
             try
             {
                 var stock = await _stockInfoRepository.Db.Queryable<Dt_StockInfo>().Includes(x => x.Details).Where(x => x.PalletCode == palletCode).FirstAsync();
+
+                Dt_Task task = _taskRepository.QueryFirst(x => x.PalletCode == palletCode);
+                if (task != null)
+                {
+                    return WebResponseContent.Instance.Error("浠诲姟淇℃伅鍒楄〃瀛樺湪璇ユ墭鐩樼殑浠诲姟淇℃伅锛屼笉鍙彇璧扮┖绠憋紝璇锋鏌ヤ换鍔℃槸鍚﹀畬鎴�");
+                }
 
                 if (stock == null)
                 {
@@ -1938,21 +2063,20 @@
                 if (stock.Details.Count <= 0)
                 {
                     stock.PalletType = (int)PalletTypeEnum.Empty;
-                    stock.StockStatus = (int)StockStatusEmun.缁勭洏鏆傚瓨;
+                    stock.StockStatus = (int)StockStatusEmun.鍏ュ簱纭;
                     stock.LocationCode = "";
                 }
                 else if (stock.Details.Count > 0)
                 {
                     Dt_OutStockLockInfo lockInfo = _outboundLockInfoRepository.QueryFirst(x =>
-                       x.OrderNo == OrderNo &&
                        x.StockId == stock.Id &&
                        x.PalletCode == palletCode);
 
                     if (lockInfo != null && lockInfo.SortedQuantity != lockInfo.AssignQuantity)
                     {
-                        return content.Error($"鎵樼洏{palletCode}搴撳瓨鏈嫞閫夊畬涓嶅厑璁稿洖搴�");
+                        return content.Error($"鎵樼洏{palletCode}搴撳瓨锛屽湪鍗曟嵁{lockInfo.OrderNo}閲岄潰杩樻湭鎷i�夊畬鎴愶紝涓嶅厑璁稿洖搴�");
                     }
-                    stock.StockStatus = (int)StockStatusEmun.缁勭洏鏆傚瓨;
+                    stock.StockStatus = (int)StockStatusEmun.鍏ュ簱纭;
                     stock.LocationCode = "";
                 }
 
@@ -1967,6 +2091,11 @@
 
                 // 鍒嗛厤鏂拌揣浣�
                 var newLocation = _locationInfoService.AssignLocation(stock.LocationType);
+
+                if(newLocation == null)
+                {
+                    return WebResponseContent.Instance.Error("娌℃湁绌洪棽搴撲綅鍙洖搴�");
+                }
 
                 var newTask = new Dt_Task()
                 {
@@ -2000,6 +2129,67 @@
             }
         }
 
+        public WebResponseContent RecheckPicking(RecheckPickingDTO pickingDTO)
+        {
+            try
+            {
+                Dt_ReCheckOrder reCheckOrder = _outboundRepository.Db.Queryable<Dt_ReCheckOrder>().Where(x => x.OrderNo == pickingDTO.orderNo && x.Result == 0).First();
+                if(reCheckOrder == null)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒拌寰呴噸鎷g殑鍗曟嵁{pickingDTO.orderNo}");
+                }
+                Dt_StockInfoDetail stockInfoDetail = _stockDetailRepository.QueryFirst(x=>x.Barcode == pickingDTO.barCode && x.Status == StockStatusEmun.鎵嬪姩鍐荤粨.ObjToInt() );
+                if(stockInfoDetail == null)
+                {
+                    return WebResponseContent.Instance.Error($"鏈湪搴撳瓨涓壘鍒拌鍐荤粨/闅旂鏉$爜 {pickingDTO.barCode}");
+                }
+                if (stockInfoDetail.MaterielCode != reCheckOrder.MaterielCode || stockInfoDetail.BatchNo != reCheckOrder.BatchNo)
+                {
+                    return WebResponseContent.Instance.Error("璇ユ潯鐮佺殑鐗╂枡缂栫爜鍜屾壒娆″拰璇ラ噸妫�鍗曚笉绗�");
+                }
+                stockInfoDetail.OrderNo = pickingDTO.orderNo;
+                stockInfoDetail.Status = StockStatusEmun.閲嶆涓�.ObjToInt();
+                var currentRemark = _outboundRepository.Db.Queryable<Dt_OutboundOrder>()
+                .Where(x => x.OrderNo == pickingDTO.orderNo)
+                .Select(x => x.Remark)
+                .First();
+
+                string newRemark;
+                if (string.IsNullOrWhiteSpace(currentRemark))
+                {
+                    newRemark = pickingDTO.barCode;
+                }
+                else
+                {
+                    var existingCodes = currentRemark.Split(',', StringSplitOptions.RemoveEmptyEntries)
+                        .Select(s => s.Trim())
+                        .ToList();
+
+                    if (!existingCodes.Contains(pickingDTO.barCode))
+                    {
+                        existingCodes.Add(pickingDTO.barCode);
+                        newRemark = string.Join(",", existingCodes);
+                    }
+                    else
+                    {
+                        newRemark = currentRemark;
+                    }
+                }
+                _outboundRepository.Db.Updateable<Dt_OutboundOrder>()
+                    .SetColumns(x => x.Remark == newRemark)
+                    .SetColumns(x=>x.OrderStatus == (int)OutOrderStatusEnum.鍑哄簱瀹屾垚)
+                    .Where(x => x.OrderNo == pickingDTO.orderNo)
+                    .ExecuteCommand();
+                _stockDetailRepository.UpdateData(stockInfoDetail);
+
+                return WebResponseContent.Instance.OK();
+            }
+            catch(Exception ex)
+            {
+                return WebResponseContent.Instance.Error(ex.Message);
+            }
+        }
+
         #endregion
     }
 }

--
Gitblit v1.9.3