From 0a4224dbd27287ee2c79f832149e5222914d7ad4 Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期日, 22 十二月 2024 13:35:06 +0800
Subject: [PATCH] 更新代码

---
 代码管理/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundOrderService.cs |   79 +++++++++++++++++++++++++++++++++++++--
 1 files changed, 74 insertions(+), 5 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundOrderService.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundOrderService.cs"
index fa29aa5..26ac858 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundOrderService.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundOrderService.cs"
@@ -8,7 +8,9 @@
 using System.Text;
 using System.Threading.Tasks;
 using WIDESEA_Common.OrderEnum;
+using WIDESEA_Common.StockEnum;
 using WIDESEA_Core;
+using WIDESEA_Core.BaseRepository;
 using WIDESEA_Core.BaseServices;
 using WIDESEA_Core.Enums;
 using WIDESEA_Core.Helper;
@@ -19,6 +21,7 @@
 using WIDESEA_IBasicService;
 using WIDESEA_IOutboundRepository;
 using WIDESEA_IOutboundService;
+using WIDESEA_IStockRepository;
 using WIDESEA_IStockService;
 using WIDESEA_Model.Models;
 
@@ -27,16 +30,22 @@
     public class OutboundOrderService : ServiceBase<Dt_OutboundOrder, IOutboundOrderRepository>, IOutboundOrderService
     {
         private readonly IMapper _mapper;
+        private readonly IUnitOfWorkManage _unitOfWorkManage;
         private readonly IBasicService _basicService;
         private readonly IOutboundOrderDetailRepository _outboundOrderDetailRepository;
-
+        private readonly IStockInfoService _stockInfoService;
+        private readonly IStockInfoRepository _stockInfoRepository;
         public IOutboundOrderRepository Repository => BaseDal;
 
-        public OutboundOrderService(IOutboundOrderRepository BaseDal, IMapper mapper, IBasicService basicService, IOutboundOrderDetailRepository outboundOrderDetailRepository) : base(BaseDal)
+        public OutboundOrderService(IOutboundOrderRepository BaseDal, IMapper mapper,IUnitOfWorkManage unitOfWorkManage, IBasicService basicService, IOutboundOrderDetailRepository outboundOrderDetailRepository, IStockInfoService stockInfoService,
+          IStockInfoRepository stockInfoRepository) : base(BaseDal)
         {
             _mapper = mapper;
+            _unitOfWorkManage=unitOfWorkManage;
             _basicService = basicService;
             _outboundOrderDetailRepository = outboundOrderDetailRepository;
+            _stockInfoService = stockInfoService;
+            _stockInfoRepository= stockInfoRepository;
         }
 
         public WebResponseContent ReceiveOutOrder(ErpOutOrderDTO model)
@@ -71,6 +80,7 @@
                         }
                         else
                         {
+                            Dt_StockInfo? stockInfo = null;
                             Dt_OutboundOrderDetail outboundOrderDetail = new Dt_OutboundOrderDetail()
                             {
                                 RowNo = Convert.ToInt32(model.RowNo),
@@ -81,8 +91,20 @@
                                 OrderQuantity = model.Qty,
                                 OrderId = oldOutboundOrder.Id
                             };
-
+                            //ERP涓婁紶娴嬭瘯浠撻鏂欏崟鏇存柊瀵瑰簲搴撳瓨鐘舵��
+                            if (warehouse.WarehouseId == 1)
+                            {
+                                //鑾峰彇鍑哄簱鍗曞簱瀛�
+                                stockInfo = _stockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.WarehouseId == warehouse.WarehouseId).Includes(x => x.Details).Where(x => x.Details.Any(x => x.MaterielCode == model.MCode && x.BatchNo == model.MLot && x.InboundOrderRowNo == Convert.ToInt32(model.RowNo))).First();
+                                stockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
+                            }
+                            _unitOfWorkManage.BeginTran();
+                            if (stockInfo != null)
+                            {
+                                _stockInfoRepository.UpdateData(stockInfo);
+                            }
                             _outboundOrderDetailRepository.AddData(outboundOrderDetail);
+                            _unitOfWorkManage.CommitTran();
                         }
                     }
                     else
@@ -106,8 +128,21 @@
                             WarehouseId = warehouse.WarehouseId,
                             Details = new List<Dt_OutboundOrderDetail> { outboundOrderDetail }
                         };
-
+                        Dt_StockInfo? stockInfo = null;
+                        //ERP涓婁紶娴嬭瘯浠撻鏂欏崟鏇存柊瀵瑰簲搴撳瓨鐘舵�� 
+                        if (warehouse.WarehouseId==1)
+                        {
+                            //鑾峰彇鍑哄簱鍗曞簱瀛�
+                            stockInfo = _stockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.WarehouseId == warehouse.WarehouseId).Includes(x => x.Details).Where(x => x.Details.Any(x => x.MaterielCode == model.MCode && x.BatchNo == model.MLot && x.InboundOrderRowNo == Convert.ToInt32(model.RowNo))).First();
+                            stockInfo.StockStatus=StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
+                        }
+                        _unitOfWorkManage.BeginTran();
+                        if (stockInfo!=null)
+                        {
+                            _stockInfoRepository.UpdateData(stockInfo);
+                        }
                         Db.InsertNav(outboundOrder).Include(x => x.Details).ExecuteCommand();
+                        _unitOfWorkManage.CommitTran();
                     }
                 }
                 else if (model.Way == 2)
@@ -121,7 +156,7 @@
                     {
                         return WebResponseContent.Instance.Error($"鏈壘鍒拌鏄庣粏琛屽彿淇℃伅");
                     }
-                    if(outboundOrderDetail.OrderDetailStatus != OrderDetailStatusEnum.New.ObjToInt())
+                    if (outboundOrderDetail.OrderDetailStatus != OrderDetailStatusEnum.New.ObjToInt())
                     {
                         return WebResponseContent.Instance.Error($"璇ユ槑缁嗕笉鍙慨鏀�");
                     }
@@ -137,6 +172,40 @@
 
                     _outboundOrderDetailRepository.UpdateData(outboundOrderDetail);
                 }
+                else if (model.Way == 3)
+                {
+                    if (oldOutboundOrder == null)
+                    {
+                        return WebResponseContent.Instance.Error($"鏈壘鍒拌鍑哄簱鍗�");
+                    }
+                }
+
+                return WebResponseContent.Instance.OK();
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                return WebResponseContent.Instance.Error(ex.Message);
+            }
+        }
+
+        public WebResponseContent ReleaseOutOrder(int id)
+        {
+            try
+            {
+                Dt_OutboundOrder outboundOrder = Db.Queryable<Dt_OutboundOrder>().Where(x => x.Id == id).Includes(x => x.Details).First();
+                if (outboundOrder == null)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒拌鍑哄簱鍗�");
+                }
+                if(outboundOrder.Details == null || outboundOrder.Details.Count == 0)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒版槑缁嗕俊鎭�");
+                }
+
+                foreach (var item in outboundOrder.Details)
+                {
+                }
 
                 return WebResponseContent.Instance.OK();
             }

--
Gitblit v1.9.3