From 4dbdd03f0476e219b1593dda302f478c15860fa6 Mon Sep 17 00:00:00 2001
From: z8018 <1282578289@qq.com>
Date: 星期二, 16 十二月 2025 23:59:29 +0800
Subject: [PATCH] 回传

---
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundService.cs |  204 +++++++++++++++++++++++++++++++++------------------
 1 files changed, 132 insertions(+), 72 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 f2f1977..5f48f16 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"
@@ -1,12 +1,16 @@
-锘縰sing SqlSugar;
+锘縰sing Newtonsoft.Json;
+using Newtonsoft.Json.Serialization;
+using SqlSugar;
 using WIDESEA_Common.LocationEnum;
 using WIDESEA_Common.OrderEnum;
 using WIDESEA_Common.StockEnum;
 using WIDESEA_Common.TaskEnum;
 using WIDESEA_Core;
 using WIDESEA_Core.BaseRepository;
+using WIDESEA_Core.CodeConfigEnum;
 using WIDESEA_Core.Helper;
 using WIDESEA_DTO.CalcOut;
+using WIDESEA_DTO.ReturnMES;
 using WIDESEA_IBasicService;
 using WIDESEA_IOutboundService;
 using WIDESEA_IRecordService;
@@ -27,30 +31,34 @@
         public IOutStockLockInfoService OutboundStockLockInfoService { get; }
 
         private readonly ISqlSugarClient Db;
-        private readonly IOutboundOrderDetailService _detailService;
-        private readonly IOutboundOrderService _outboundOrderService;
-        private readonly IOutStockLockInfoService _outboundLockInfoService;
-        private readonly IStockInfoService _stockInfoService;
-        private readonly IStockInfoDetailService _stockDetailService;
-        private readonly ILocationInfoService _locationInfoService;
-        private readonly IStockQuantityChangeRecordService _stockChangeService;
-        private readonly IStockInfoDetail_HtyService _stockDetailHistoryService;
+        private readonly IBasicService _basicService;
 
-        public OutboundService(IUnitOfWorkManage unitOfWorkManage, IOutboundOrderDetailService outboundOrderDetailService, IOutboundOrderService outboundOrderService, IOutStockLockInfoService outboundStockLockInfoService, IStockInfoService stockInfoService, IStockInfoDetailService stockDetailService, ILocationInfoService locationInfoService, IStockQuantityChangeRecordService stockQuantityChangeRecordService, IStockInfoDetail_HtyService stockDetailHistoryService)
+
+        private readonly IRepository<Dt_OutboundOrderDetail> _detailRepository;
+        private readonly IRepository<Dt_OutboundOrder> _outboundRepository;
+        private readonly IRepository<Dt_OutStockLockInfo> _outboundLockInfoRepository;
+        private readonly IRepository<Dt_StockInfo> _stockInfoRepository;
+        private readonly IRepository<Dt_StockInfoDetail> _stockDetailRepository;
+        private readonly IRepository<Dt_LocationInfo> _locationInfoRepository;
+        private readonly IRepository<Dt_StockQuantityChangeRecord> _stockChangeRepository;
+        private readonly IRepository<Dt_StockInfoDetail_Hty> _stockDetailHistoryRepository;
+
+        public OutboundService(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)
         {
             _unitOfWorkManage = unitOfWorkManage;
             Db = _unitOfWorkManage.GetDbClient();
             OutboundOrderDetailService = outboundOrderDetailService;
             OutboundOrderService = outboundOrderService;
             OutboundStockLockInfoService = outboundStockLockInfoService;
-            _detailService = outboundOrderDetailService;
-            _outboundOrderService = outboundOrderService;
-            _outboundLockInfoService = outboundStockLockInfoService;
-            _stockInfoService = stockInfoService;
-            _stockDetailService = stockDetailService;
-            _locationInfoService = locationInfoService;
-            _stockChangeService = stockQuantityChangeRecordService;
-            _stockDetailHistoryService = stockDetailHistoryService;
+            _detailRepository = detailRepository;
+            _outboundRepository = outboundRepository;
+            _outboundLockInfoRepository = outboundLockInfoRepository;
+            _stockInfoRepository = stockInfoRepository;
+            _stockDetailRepository = stockDetailRepository;
+            _locationInfoRepository = basicService.LocationInfoService.Repository;
+            _stockChangeRepository = stockChangeRepository;
+            _stockDetailHistoryRepository = stockDetailHistoryRepository;
+            _basicService = basicService;
         }
 
         /// <summary>
@@ -129,9 +137,17 @@
                     foreach (var detail in materielCalc.Details)
                     {
                         decimal lockQuantity = (detail.OrderQuantity - detail.OverOutQuantity);
-                        detail.LockQuantity += lockQuantity; // 澧炲姞閿佸畾鏁伴噺 涓嶆洿鏂� OverOutQuantity 鍜� OrderDetailStatus锛屽洜涓鸿繕娌℃湁瀹為檯鍑哄簱
-
-                        outboundOrderDetails.Add(detail);
+                        if (lockQuantity < materielCalc.UnallocatedQuantity)
+                        {
+                            detail.LockQuantity += lockQuantity; // 澧炲姞閿佸畾鏁伴噺 涓嶆洿鏂� OverOutQuantity 鍜� OrderDetailStatus锛屽洜涓鸿繕娌℃湁瀹為檯鍑哄簱
+                            outboundOrderDetails.Add(detail);
+                        }
+                        else
+                        {
+                            detail.LockQuantity += materielCalc.UnallocatedQuantity;
+                            outboundOrderDetails.Add(detail);
+                            break;
+                        }
                     }
                 }
 
@@ -139,7 +155,7 @@
                 UpdateOutboundOrderStatus(request.OrderNo, (int)OutOrderStatusEnum.鍑哄簱涓�);
 
                 // 4. 鏇存柊鍑哄簱鍗曟槑缁嗛攣瀹氭暟閲�
-                _detailService.Repository.UpdateData(outboundOrderDetails);
+                _detailRepository.UpdateData(outboundOrderDetails);
 
                 // 5. 鏇存柊搴撳瓨鐘舵��
                 UpdateStockStatus(pickedDetails.Select(x => x.PalletCode).ToList(), StockStatusEmun.鍑哄簱閿佸畾.ObjToInt());
@@ -179,7 +195,7 @@
 
             try
             {
-                Dt_OutboundOrder outboundOrder = _outboundOrderService.Repository.QueryFirst(x => x.OrderNo == request.OrderNo);
+                Dt_OutboundOrder outboundOrder = _outboundRepository.QueryFirst(x => x.OrderNo == request.OrderNo);
                 if (outboundOrder == null)
                 {
                     result.CanOutbound = false;
@@ -188,10 +204,15 @@
                 }
 
                 result.FactoryArea = outboundOrder.FactoryArea;
-                result.IsMultiDetail = request.IsMultiDetail;
 
                 // 鑾峰彇閫夋嫨鐨勫嚭搴撴槑缁�
-                List<Dt_OutboundOrderDetail> selectedDetails = _detailService.Repository.QueryData(x => x.OrderId == outboundOrder.Id && request.DetailIds.Contains(x.Id));
+                List<Dt_OutboundOrderDetail> selectedDetails = _detailRepository.QueryData(x => x.OrderId == outboundOrder.Id && request.DetailIds.Contains(x.Id));
+
+                if (outboundOrder.IsBatch == 1)
+                {
+                    selectedDetails = _detailRepository.QueryData(x => x.WarehouseCode == selectedDetails.First().WarehouseCode && x.MaterielCode == selectedDetails.First().MaterielCode && x.BatchNo == selectedDetails.First().BatchNo && x.SupplyCode == selectedDetails.First().SupplyCode);
+                }
+
 
                 if (!selectedDetails.Any())
                 {
@@ -199,7 +220,6 @@
                     result.ErrorMessage = $"鏈壘鍒伴�夋嫨鐨勫嚭搴撴槑缁嗕俊鎭�";
                     return result;
                 }
-
                 if (selectedDetails.Any(x => x.LockQuantity > x.OrderQuantity - x.MoveQty || x.OverOutQuantity > x.OrderQuantity - x.MoveQty))
                 {
                     List<int> selectDetailIds = selectedDetails.Where(x => x.LockQuantity > x.OrderQuantity - x.MoveQty || x.OverOutQuantity > x.OrderQuantity - x.MoveQty).Select(x => x.Id).ToList();
@@ -212,7 +232,7 @@
                 result.OutboundOrder = outboundOrder;
                 result.SelectedDetails = selectedDetails;
 
-                if (request.IsMultiDetail)
+                if (outboundOrder.IsBatch == 0)
                 {
                     // 澶氭槑缁嗗嚭搴擄細鎸夌墿鏂欏垎缁勫鐞�
                     result.MaterielCalculations = CalcMaterielOutboundQuantities(outboundOrder, selectedDetails.ToList());
@@ -227,15 +247,21 @@
                         return result;
                     }
 
+                    decimal lockQuantity = selectedDetails.Sum(x => x.LockQuantity);
+                    decimal orderQuantity = selectedDetails.Sum(x => x.OrderQuantity);
+                    decimal moveQuantity = selectedDetails.Sum(x => x.MoveQty);
+                    decimal overQuantity = selectedDetails.Sum(x => x.OverOutQuantity);
+
                     Dt_OutboundOrderDetail? singleDetail = selectedDetails.First();
 
                     //鍒ゆ柇鍙嚭搴撴暟閲�
-                    if (singleDetail.OrderQuantity - singleDetail.LockQuantity - singleDetail.MoveQty <= 0)
+                    if (orderQuantity - lockQuantity - moveQuantity < request.OutboundQuantity.Value || orderQuantity - overQuantity - moveQuantity < request.OutboundQuantity.Value)
                     {
                         result.CanOutbound = false;
-                        result.ErrorMessage = $"鏈鍑哄簱鏁伴噺 {request.OutboundQuantity.Value} 瓒呰繃鍙嚭搴撴暟閲� {singleDetail.OrderQuantity - singleDetail.LockQuantity - singleDetail.MoveQty}";
+                        result.ErrorMessage = $"鏈鍑哄簱鏁伴噺 {request.OutboundQuantity.Value} 瓒呰繃鍙嚭搴撴暟閲� {orderQuantity - lockQuantity - moveQuantity}";
                         return result;
                     }
+
                     result.MaterielCalculations = new List<MaterielOutboundCalculationDTO>()
                     {
                         new MaterielOutboundCalculationDTO
@@ -245,12 +271,12 @@
                             BatchNo = singleDetail.BatchNo,
                             SupplyCode = singleDetail.SupplyCode,
                             WarehouseCode = singleDetail.WarehouseCode,
-                            TotalOrderQuantity = singleDetail.OrderQuantity - singleDetail.MoveQty,
-                            TotalOverOutQuantity = singleDetail.OverOutQuantity,
-                            AssignedQuantity = singleDetail.LockQuantity,
-                            UnallocatedQuantity = singleDetail.OrderQuantity - singleDetail.LockQuantity - singleDetail.MoveQty,
-                            MovedQuantity = singleDetail.MoveQty,
-                            Details = new List<Dt_OutboundOrderDetail>() { singleDetail }
+                            TotalOrderQuantity = orderQuantity - moveQuantity,
+                            TotalOverOutQuantity = overQuantity,
+                            AssignedQuantity = lockQuantity,
+                            UnallocatedQuantity = request.OutboundQuantity.Value,
+                            MovedQuantity = moveQuantity,
+                            Details = selectedDetails
                         }
                     };
                 }
@@ -297,7 +323,7 @@
                     UnallocatedQuantity = g.Sum(x => x.OrderQuantity - x.LockQuantity - x.MoveQty),
                     MovedQuantity = g.Sum(x => x.MoveQty),
                     Details = g.ToList(),
-                    OutStockLockInfos = _outboundLockInfoService.Repository.QueryData(x => x.MaterielCode == g.Key.MaterielCode && x.BatchNo == g.Key.BatchNo && x.OrderType == (int)outboundOrder.OrderType && x.OrderNo == outboundOrder.OrderNo)
+                    OutStockLockInfos = _outboundLockInfoRepository.QueryData(x => x.MaterielCode == g.Key.MaterielCode && x.BatchNo == g.Key.BatchNo && x.OrderType == (int)outboundOrder.OrderType && x.OrderNo == outboundOrder.OrderNo)
                 })
                 .ToList();
 
@@ -454,7 +480,7 @@
         private List<Dt_StockInfo> BuildStockQueryWithInfo(MaterielOutboundCalculationDTO materielCalc, string factoryArea)
         {
             // 鍩虹鏌ヨ鏉′欢锛氱墿鏂欑紪鍙枫�佹壒娆″彿锛堝鏋滄彁渚涳級銆佸簱瀛樻暟閲�>0
-            ISugarQueryable<Dt_StockInfoDetail> stockDetails = _stockDetailService.Repository.Db.Queryable<Dt_StockInfoDetail>().Where(x => x.MaterielCode == materielCalc.MaterielCode && x.StockQuantity > 0);
+            ISugarQueryable<Dt_StockInfoDetail> stockDetails = _stockDetailRepository.Db.Queryable<Dt_StockInfoDetail>().Where(x => x.MaterielCode == materielCalc.MaterielCode && x.StockQuantity > 0);
 
             // 鏍规嵁鏉′欢娣诲姞渚涘簲鍟嗙紪鍙峰尮閰嶏紙涓嶄负绌烘椂鎵嶉渶瑕佸尮閰嶏級
             if (!string.IsNullOrEmpty(materielCalc.SupplyCode))
@@ -483,11 +509,11 @@
             List<Dt_StockInfoDetail> stockDetailList = stockDetails.ToList();
 
             // 鑾峰彇鍙敤璐т綅缂栧彿
-            List<string> locationCodes = _locationInfoService.Repository.QueryData(x => (x.LocationStatus == LocationStatusEnum.InStock.ObjToInt() /*|| x.LocationStatus == LocationStatusEnum.Lock.ObjToInt()*/) && x.EnableStatus == EnableStatusEnum.Normal.ObjToInt()).Select(x => x.LocationCode).ToList();
+            List<string> locationCodes = _locationInfoRepository.QueryData(x => (x.LocationStatus == LocationStatusEnum.InStock.ObjToInt() /*|| x.LocationStatus == LocationStatusEnum.Lock.ObjToInt()*/) && x.EnableStatus == EnableStatusEnum.Normal.ObjToInt()).Select(x => x.LocationCode).ToList();
 
             // 鑾峰彇鎵�鏈夌浉鍏崇殑搴撳瓨淇℃伅
             List<int> stockIds = stockDetailList.GroupBy(x => x.StockId).Select(x => x.Key).ToList();
-            List<Dt_StockInfo> stockInfos = _stockInfoService.Repository.QueryData(x => stockIds.Contains(x.Id) && (x.StockStatus == StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt() /*|| x.StockStatus == StockStatusEmun.鍑哄簱閿佸畾.ObjToInt()*/) && !string.IsNullOrEmpty(x.LocationCode) && locationCodes.Contains(x.LocationCode));
+            List<Dt_StockInfo> stockInfos = _stockInfoRepository.QueryData(x => stockIds.Contains(x.Id) && (x.StockStatus == StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt() /*|| x.StockStatus == StockStatusEmun.鍑哄簱閿佸畾.ObjToInt()*/) && !string.IsNullOrEmpty(x.LocationCode) && locationCodes.Contains(x.LocationCode));
 
             // 鍦ㄥ唴瀛樹腑鍏宠仈鏁版嵁
             foreach (var stockInfo in stockInfos)
@@ -652,7 +678,7 @@
         private decimal CalcTotalAllocatedQuantity(List<Dt_OutStockLockInfo> lockInfos, int stockId, string materielCode)
         {
             // 鏌ヨ璇ユ墭鐩樿鐗╂枡鍦ㄦ墍鏈夐攣瀹氳褰曚腑鐨勬渶澶у凡鍒嗛厤鏁伴噺
-            List<Dt_OutStockLockInfo> lockRecords = _outboundLockInfoService.Repository.QueryData(x =>
+            List<Dt_OutStockLockInfo> lockRecords = _outboundLockInfoRepository.QueryData(x =>
                 x.StockId == stockId &&
                 x.MaterielCode == materielCode);
 
@@ -672,11 +698,11 @@
         {
             try
             {
-                Dt_OutboundOrder outboundOrder = _outboundOrderService.Repository.QueryFirst(x => x.OrderNo == orderNo);
+                Dt_OutboundOrder outboundOrder = _outboundRepository.QueryFirst(x => x.OrderNo == orderNo);
                 if (outboundOrder == null) return false;
 
                 outboundOrder.OrderStatus = status;
-                _outboundOrderService.Repository.UpdateData(outboundOrder);
+                _outboundRepository.UpdateData(outboundOrder);
                 return true;
             }
             catch
@@ -695,13 +721,13 @@
         {
             try
             {
-                List<Dt_StockInfo> stockInfos = _stockInfoService.Repository.QueryData(x => palletCodes.Contains(x.PalletCode));
+                List<Dt_StockInfo> stockInfos = _stockInfoRepository.QueryData(x => palletCodes.Contains(x.PalletCode));
                 stockInfos.ForEach(stockInfo =>
                 {
                     stockInfo.StockStatus = status;
                 });
 
-                _stockInfoService.Repository.UpdateData(stockInfos);
+                _stockInfoRepository.UpdateData(stockInfos);
                 return true;
             }
             catch
@@ -720,13 +746,13 @@
         {
             try
             {
-                List<Dt_LocationInfo> locationInfos = _locationInfoService.Repository.QueryData(x => locationCodes.Contains(x.LocationCode));
+                List<Dt_LocationInfo> locationInfos = _locationInfoRepository.QueryData(x => locationCodes.Contains(x.LocationCode));
                 locationInfos.ForEach(x =>
                 {
                     x.LocationStatus = status;
                 });
 
-                _locationInfoService.Repository.UpdateData(locationInfos);
+                _locationInfoRepository.UpdateData(locationInfos);
                 return true;
             }
             catch
@@ -745,10 +771,10 @@
             try
             {
                 List<Dt_OutStockLockInfo> updateData = outStockLockInfos.Where(x => x.Id > 0).ToList();
-                _outboundLockInfoService.Repository.UpdateData(updateData);
+                _outboundLockInfoRepository.UpdateData(updateData);
 
                 List<Dt_OutStockLockInfo> addData = outStockLockInfos.Where(x => x.Id <= 0).ToList();
-                _outboundLockInfoService.Repository.AddData(addData);
+                _outboundLockInfoRepository.AddData(addData);
 
                 return true;
             }
@@ -772,7 +798,7 @@
             try
             {
                 // 1. 鏍规嵁鎵樼洏鍙锋煡鎵惧簱瀛樹俊鎭�
-                Dt_StockInfo stockInfo = _stockInfoService.Repository.QueryFirst(x => x.PalletCode == request.PalletCode);
+                Dt_StockInfo stockInfo = _stockInfoRepository.QueryFirst(x => x.PalletCode == request.PalletCode);
                 if (stockInfo == null)
                 {
                     response.Success = false;
@@ -781,7 +807,7 @@
                 }
 
                 // 2. 鏍规嵁鏉$爜鏌ユ壘搴撳瓨鏄庣粏
-                Dt_StockInfoDetail stockDetail = _stockDetailService.Repository.QueryFirst(x => x.Barcode == request.Barcode);
+                Dt_StockInfoDetail stockDetail = _stockDetailRepository.QueryFirst(x => x.Barcode == request.Barcode);
                 if (stockDetail == null)
                 {
                     response.Success = false;
@@ -798,7 +824,7 @@
                 }
 
                 // 4. 鏌ユ壘鍑哄簱鍗曚俊鎭�
-                Dt_OutboundOrder outboundOrder = _outboundOrderService.Repository.QueryFirst(o => o.OrderNo == request.OrderNo);
+                Dt_OutboundOrder outboundOrder = _outboundRepository.QueryFirst(o => o.OrderNo == request.OrderNo);
                 if (outboundOrder == null)
                 {
                     response.Success = false;
@@ -807,7 +833,7 @@
                 }
 
                 // 5. 鏌ユ壘閿佸畾璁板綍
-                Dt_OutStockLockInfo lockInfo = _outboundLockInfoService.Repository.QueryFirst(x =>
+                Dt_OutStockLockInfo lockInfo = _outboundLockInfoRepository.QueryFirst(x =>
                     x.OrderNo == request.OrderNo &&
                     x.StockId == stockInfo.Id &&
                     x.MaterielCode == stockDetail.MaterielCode &&
@@ -886,33 +912,68 @@
                     {
                         if (allocatedQuantity <= 0) break;
 
-                        if (item.OrderQuantity - item.MoveQty - item.OverOutQuantity >= allocatedQuantity)
+
+                        //if (item.OrderQuantity - item.MoveQty - item.OverOutQuantity >= allocatedQuantity)
+                        //{
+                        //    item.OverOutQuantity += allocatedQuantity;
+                        //    allocatedQuantity = 0;
+                        //}
+                        //else
+                        //{
+                        //    allocatedQuantity -= (item.OrderQuantity - item.MoveQty - item.OverOutQuantity);
+                        //    item.OverOutQuantity = item.OrderQuantity - item.MoveQty;
+                        //}
+
+                        if (item.LockQuantity - item.OverOutQuantity >= allocatedQuantity)
                         {
                             item.OverOutQuantity += allocatedQuantity;
+                            item.CurrentDeliveryQty += allocatedQuantity;
                             allocatedQuantity = 0;
                         }
                         else
                         {
-                            allocatedQuantity -= (item.OrderQuantity - item.MoveQty - item.OverOutQuantity);
-                            item.OverOutQuantity = item.OrderQuantity - item.MoveQty;
+                            allocatedQuantity -= (item.LockQuantity - item.OverOutQuantity);
+                            item.OverOutQuantity = item.LockQuantity;
+                            item.CurrentDeliveryQty = item.LockQuantity;
                         }
+
                         updateDetails.Add(item);
+
+                        List<Barcodes> barcodesList = new List<Barcodes>();
+                        Barcodes barcodes = new Barcodes
+                        {
+                            Barcode = request.Barcode,
+                            Qty = actualOutboundQuantity,
+                            SupplyCode = stockDetail?.SupplyCode ?? "",
+                            BatchNo = stockDetail?.BatchNo ?? "",
+                            Unit = stockDetail?.Unit ?? ""
+                        };
+                        if (!string.IsNullOrEmpty(item.ReturnJsonData))
+                        {
+                            barcodesList = JsonConvert.DeserializeObject<List<Barcodes>>(item.ReturnJsonData) ?? new List<Barcodes>();
+                        }
+                        barcodesList.Add(barcodes);
+                        JsonSerializerSettings settings = new JsonSerializerSettings
+                        {
+                            ContractResolver = new CamelCasePropertyNamesContractResolver()
+                        };
+                        item.ReturnJsonData = JsonConvert.SerializeObject(barcodesList, settings);
                     }
 
                     lockInfo.SortedQuantity = lockInfo.SortedQuantity + actualOutboundQuantity;
 
                     if (lockInfo.SortedQuantity == lockInfo.AssignQuantity)
                     {
-                        _outboundLockInfoService.Repository.DeleteAndMoveIntoHty(lockInfo, WIDESEA_Core.Enums.OperateTypeEnum.鑷姩瀹屾垚);
+                        _outboundLockInfoRepository.DeleteAndMoveIntoHty(lockInfo, WIDESEA_Core.Enums.OperateTypeEnum.鑷姩瀹屾垚);
                     }
                     else
                     {
                         // 鏇存柊閿佸畾璁板綍
-                        _outboundLockInfoService.Repository.UpdateData(lockInfo);
+                        _outboundLockInfoRepository.UpdateData(lockInfo);
                     }
 
                     // 鏇存柊鍑哄簱鍗曟槑缁嗙殑宸插嚭搴撴暟閲�
-                    _detailService.Repository.UpdateData(updateDetails);
+                    _detailRepository.UpdateData(updateDetails);
 
                     // 鏇存柊閿佸畾璁板綍鐨勭疮璁″凡鍑哄簱鏁伴噺锛堥渶瑕佹洿鏂拌鎵樼洏璇ョ墿鏂欑殑鎵�鏈夌浉鍏宠褰曪級
                     //UpdateLockInfoAllocatedQuantity(stockInfo.Id, stockDetail.MaterielCode, stockDetail.BatchNo, actualOutboundQuantity);
@@ -974,7 +1035,7 @@
         /// <returns></returns>
         private List<Dt_OutboundOrderDetail> FindMatchingOutboundDetails(int orderId, Dt_StockInfoDetail stockDetail, List<int> detailIds)
         {
-            List<Dt_OutboundOrderDetail> details = _detailService.Repository.QueryData(x =>
+            List<Dt_OutboundOrderDetail> details = _detailRepository.QueryData(x =>
                 x.OrderId == orderId &&
                 x.MaterielCode == stockDetail.MaterielCode && x.OrderQuantity - x.MoveQty > x.OverOutQuantity && detailIds.Contains(x.Id));
 
@@ -1002,7 +1063,6 @@
                 Math.Min(availableOutboundQuantity, detailRemainingQuantity),
                 stockDetail.StockQuantity);
         }
-
 
         /// <summary>
         /// 鎵ц鎷嗗寘鎿嶄綔
@@ -1043,7 +1103,7 @@
                 WarehouseCode = stockDetail.WarehouseCode,
                 Remark = $"鎷嗗寘鍓嶅師濮嬭褰曪紝鍘熸潯鐮侊細{request.Barcode}锛屽師鏁伴噺锛歿stockDetail.StockQuantity}锛屽嚭搴撴暟閲忥細{actualOutboundQuantity}锛屾搷浣滆�咃細{request.Operator}"
             };
-            _stockDetailHistoryService.Repository.AddData(originalHistoryRecord);
+            _stockDetailHistoryRepository.AddData(originalHistoryRecord);
 
             // 淇濆瓨鍓╀綑閮ㄥ垎鍒板巻鍙茶褰�
             decimal remainingQuantity = stockDetail.StockQuantity - actualOutboundQuantity;
@@ -1053,7 +1113,7 @@
                 stockDetail.StockQuantity = remainingQuantity;
                 //stockDetail.Barcode = newBarcode;
                 stockDetail.Remark = $"鎷嗗寘鍚庢洿鏂帮紝鍘熸潯鐮侊細{request.Barcode}锛屾柊鏁伴噺锛歿remainingQuantity}锛屾搷浣滆�咃細{request.Operator}";
-                _stockDetailService.Repository.UpdateData(stockDetail);
+                _stockDetailRepository.UpdateData(stockDetail);
             }
 
             // 璁板綍鎷嗗寘鍙樺姩
@@ -1076,7 +1136,7 @@
                 WarehouseCode = stockDetail.WarehouseCode,
                 Remark = $"鎷嗗寘鍑哄簱锛屽師鏉$爜锛歿request.Barcode}锛屾柊鏉$爜锛歿newBarcode}锛屽嚭搴撴暟閲忥細{actualOutboundQuantity}锛屽墿浣欙細{remainingQuantity}锛屾搷浣滆�咃細{request.Operator}"
             };
-            _stockChangeService.Repository.AddData(unpackChangeRecord);
+            _stockChangeRepository.AddData(unpackChangeRecord);
 
             return newBarcode;
         }
@@ -1111,10 +1171,10 @@
                 WarehouseCode = stockDetail.WarehouseCode,
                 Remark = $"鍑哄簱瀹屾垚鍒犻櫎锛屾潯鐮侊細{request.Barcode}锛屽師鏁伴噺锛歿stockDetail.StockQuantity}锛屽嚭搴撴暟閲忥細{actualOutboundQuantity}锛屾搷浣滆�咃細{request.Operator}"
             };
-            _stockDetailHistoryService.Repository.AddData(historyRecord);
+            _stockDetailHistoryRepository.AddData(historyRecord);
 
             // 鍒犻櫎搴撳瓨鏄庣粏璁板綍
-            _stockDetailService.Repository.DeleteData(stockDetail);
+            _stockDetailRepository.DeleteData(stockDetail);
 
             // 璁板綍搴撳瓨鍙樺姩
             Dt_StockQuantityChangeRecord changeRecord = new Dt_StockQuantityChangeRecord
@@ -1136,7 +1196,7 @@
                 WarehouseCode = stockDetail.WarehouseCode,
                 Remark = $"鍑哄簱瀹屾垚鍒犻櫎搴撳瓨鏄庣粏锛屾潯鐮侊細{request.Barcode}锛屽嚭搴撴暟閲忥細{actualOutboundQuantity}锛屾搷浣滆�咃細{request.Operator}"
             };
-            _stockChangeService.Repository.AddData(changeRecord);
+            _stockChangeRepository.AddData(changeRecord);
         }
 
         /// <summary>
@@ -1148,7 +1208,7 @@
             // 浣跨敤鏃堕棿鎴冲拰闅忔満鏁扮敓鎴愬敮涓�鏉$爜
             string newBarcode = string.Empty;
 
-            //todo 閲嶆柊鐢熸垚鏉$爜閫昏緫
+            newBarcode = _basicService.CreateCodeByRule(RuleCodeEnum.NewBarcodeRule.ToString());
 
             return newBarcode;
         }
@@ -1164,7 +1224,7 @@
         private void UpdateLockInfoAllocatedQuantity(int stockId, string materielCode, string batchNo, decimal actualOutboundQuantity)
         {
             // 鏌ヨ璇ユ墭鐩樿鐗╂枡鐨勬墍鏈夐攣瀹氳褰�
-            List<Dt_OutStockLockInfo> lockRecords = _outboundLockInfoService.Repository.QueryData(x =>
+            List<Dt_OutStockLockInfo> lockRecords = _outboundLockInfoRepository.QueryData(x =>
                 x.StockId == stockId &&
                 x.MaterielCode == materielCode &&
                 x.BatchNo == batchNo);
@@ -1178,7 +1238,7 @@
                 }
 
                 // 鎵归噺鏇存柊
-                _outboundLockInfoService.Repository.UpdateData(lockRecords);
+                _outboundLockInfoRepository.UpdateData(lockRecords);
             }
         }
 
@@ -1187,13 +1247,13 @@
         /// </summary>
         public bool CheckOutboundOrderCompleted(string orderNo)
         {
-            Dt_OutboundOrder outboundOrder = _outboundOrderService.Repository.QueryFirst(x => x.OrderNo == orderNo);
+            Dt_OutboundOrder outboundOrder = _outboundRepository.QueryFirst(x => x.OrderNo == orderNo);
             if (outboundOrder == null) return false;
 
-            List<Dt_OutboundOrderDetail> details = _detailService.Repository.QueryData(x => x.OrderId == outboundOrder.Id);
+            List<Dt_OutboundOrderDetail> details = _detailRepository.QueryData(x => x.OrderId == outboundOrder.Id);
 
             // 妫�鏌ユ墍鏈夋槑缁嗙殑宸插嚭鏁伴噺鏄惁閮界瓑浜庡崟鎹暟閲�
-            return details.All(x => x.OverOutQuantity >= x.OrderQuantity);
+            return details.All(x => x.OverOutQuantity >= x.OrderQuantity - x.MoveQty);
         }
     }
 }

--
Gitblit v1.9.3