From f4e01fb44b5428e61780e63d272df1d03f7281f3 Mon Sep 17 00:00:00 2001
From: hutongqing <hutongqing@hnkhzn.com>
Date: 星期六, 28 十二月 2024 13:49:32 +0800
Subject: [PATCH] Merge branch 'master' of http://115.159.85.185:8098/r/MeiRuiAn/HuaiAn

---
 代码管理/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundOrderService.cs |  152 ++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 120 insertions(+), 32 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 ceab71b..026f877 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"
@@ -1,6 +1,8 @@
 锘縰sing AutoMapper;
+using MailKit.Search;
 using Newtonsoft.Json;
 using Newtonsoft.Json.Serialization;
+using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -9,6 +11,7 @@
 using System.Threading.Tasks;
 using WIDESEA_Common.OrderEnum;
 using WIDESEA_Common.StockEnum;
+using WIDESEA_Common.WareHouseEnum;
 using WIDESEA_Core;
 using WIDESEA_Core.BaseRepository;
 using WIDESEA_Core.BaseServices;
@@ -18,6 +21,7 @@
 using WIDESEA_DTO.ERP;
 using WIDESEA_DTO.Inbound;
 using WIDESEA_DTO.Outbound;
+using WIDESEA_External.ERPService;
 using WIDESEA_External.Model;
 using WIDESEA_IBasicService;
 using WIDESEA_IOutboundRepository;
@@ -37,16 +41,20 @@
         private readonly IStockInfoService _stockInfoService;
         private readonly IStockInfoRepository _stockInfoRepository;
         public IOutboundOrderRepository Repository => BaseDal;
+        private readonly IInvokeERPService _invokeERPService;
+        private readonly IOutStockLockInfoService _outStockLockInfoService;
 
         public OutboundOrderService(IOutboundOrderRepository BaseDal, IMapper mapper,IUnitOfWorkManage unitOfWorkManage, IBasicService basicService, IOutboundOrderDetailRepository outboundOrderDetailRepository, IStockInfoService stockInfoService,
-          IStockInfoRepository stockInfoRepository) : base(BaseDal)
+          IStockInfoRepository stockInfoRepository, IInvokeERPService invokeERPService, IOutStockLockInfoService outStockLockInfoService) : base(BaseDal)
         {
             _mapper = mapper;
-            _unitOfWorkManage=unitOfWorkManage;
+            _unitOfWorkManage = unitOfWorkManage;
             _basicService = basicService;
             _outboundOrderDetailRepository = outboundOrderDetailRepository;
             _stockInfoService = stockInfoService;
-            _stockInfoRepository= stockInfoRepository;
+            _stockInfoRepository = stockInfoRepository;
+            _invokeERPService = invokeERPService;
+            _outStockLockInfoService = outStockLockInfoService;
         }
 
         public WebResponseContent ReceiveOutOrder(ErpOutOrderDTO model)
@@ -81,7 +89,6 @@
                         }
                         else
                         {
-                            Dt_StockInfo? stockInfo = null;
                             Dt_OutboundOrderDetail outboundOrderDetail = new Dt_OutboundOrderDetail()
                             {
                                 RowNo = Convert.ToInt32(model.RowNo),
@@ -92,20 +99,7 @@
                                 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
@@ -119,31 +113,19 @@
                             OrderDetailStatus = OrderDetailStatusEnum.New.ObjToInt(),
                             OrderQuantity = model.Qty,
                         };
-
                         Dt_OutboundOrder outboundOrder = new Dt_OutboundOrder()
                         {
+                            OrderNo=model.OrderNo,
                             UpperOrderNo = model.OrderNo,
                             OrderStatus = OutOrderStatusEnum.鏈紑濮�.ObjToInt(),
                             OrderType = OutOrderTypeEnum.Issue.ObjToInt(),
                             CreateType = OrderCreateTypeEnum.UpperSystemPush.ObjToInt(),
                             WarehouseId = warehouse.WarehouseId,
+                            DepartmentCode = model.DepartmentCode,
+                            DepartmentName = model.DepartmentName,
                             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)
@@ -189,7 +171,113 @@
                 return WebResponseContent.Instance.Error(ex.Message);
             }
         }
+        //涓婃姤鍑哄簱瀹屾垚 娴嬭瘯鏋�
+        public WebResponseContent TestOutUpload(int id)
+        {
+            try
+            {
+                Dt_OutboundOrder outboundOrder = Db.Queryable<Dt_OutboundOrder>().Where(x=>x.Id==id).Includes(x=>x.Details).First();
+                Dt_Warehouse warehouse = _basicService.WarehouseService.Repository.QueryFirst(x => x.WarehouseId == outboundOrder.WarehouseId);
+                //娴嬭瘯鏋跺簱缁橢RP涓婃姤鍑哄簱瀹屾垚
+                ERPPickItemModel eRPOutPick = new ERPPickItemModel()
+                {
+                    Lotno = "20241227001",
+                    Qty = "1",
+                    Location = warehouse.WarehouseCode
+                };
+                ERPPickModel pickModel = new ERPPickModel()
+                {
+                    Rowindex = outboundOrder.Details[0].RowNo,
+                    Material = outboundOrder.Details[0].MaterielCode,
+                    Qty = (outboundOrder.Details[0].OrderQuantity.ObjToInt()).ToString(),
+                    Dataitem=new List<ERPPickItemModel> { eRPOutPick }
+                };
+                
+                ERPIssueItemModel issueItemModel = new ERPIssueItemModel()
+                {
+                    Pickcode = outboundOrder.UpperOrderNo,
+                    PickList = new List<ERPPickModel>() { pickModel }
+                };
+                ERPIssueModel issueModel = new ERPIssueModel()
+                {
+                    UniqueTag = id.ToString(),
+                    Code = "FL20241227001",//娴嬭瘯
+                    WarehouseCode = warehouse.WarehouseCode,
+                    Docremark = "",
+                    Deptno = outboundOrder.DepartmentCode,
+                    Deptname = outboundOrder.DepartmentName,
+                    Createtime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
+                    Createuser = "TC20082",
+                    Issitem = new List<ERPIssueItemModel>() { issueItemModel },
+                };
+                string response = _invokeERPService.InvokeOutStandardsApi(issueModel);
+                ErpRequestContent requestContent = response.DeserializeObject<ErpRequestContent>();
+                if (requestContent.res == 1)
+                {
 
+                    return WebResponseContent.Instance.OK(requestContent.Data);
+                }
+                else
+                {
+                    return WebResponseContent.Instance.Error(requestContent.Data);
+                }
+            }
+            catch (Exception ex)
+            {
+                return WebResponseContent.Instance.Error(ex.Message);
+            }
+        }
+        /// <summary>
+        /// 鏇存敼鍑哄簱鍗曞簱瀛樼姸鎬�
+        /// </summary>
+        /// <param name="warehouse"></param>
+        /// <param name="model"></param>
+        /// <returns></returns>
+        public WebResponseContent TestOutStocksUpdate(Dt_Warehouse warehouse, ErpOutOrderDTO model)
+        {
+            try
+            {
+                //鑾峰彇鍑哄簱鍗曞簱瀛�
+                List<Dt_StockInfo> stockInfos = _stockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.WarehouseId == warehouse.WarehouseId).Includes(x => x.Details).ToList();
+                if (model.Qty > stockInfos.Count)
+                {
+                    return WebResponseContent.Instance.Error($"鐗╂枡:{model.MCode}搴撳瓨涓嶈冻");
+                }
+                //鏇存敼鐘舵��
+                stockInfos.ForEach(x =>
+                {
+                    x.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
+                });
+                return WebResponseContent.Instance.OK("鎴愬姛", stockInfos);
+            }
+            catch (Exception ex)
+            {
+                return WebResponseContent.Instance.Error(ex.Message);
+            }
+        }
+        ///鎺ㄩ�佹祴璇曟灦鍑哄簱
+        //public WebResponseContent TestOutBack(int id,List<string> locationIds)
+        //{
+        //    try
+        //    {
+                
+        //        string response = _invokeERPService.InvokeOutStandardsApi(issueModel);
+        //        ErpRequestContent requestContent = response.DeserializeObject<ErpRequestContent>();
+        //        if (requestContent.res == 1)
+        //        {
+
+        //            return WebResponseContent.Instance.OK(requestContent.Data);
+        //        }
+        //        else
+        //        {
+        //            return WebResponseContent.Instance.Error(requestContent.Data);
+        //        }
+        //    }
+        //    catch (Exception ex)
+        //    {
+        //        return WebResponseContent.Instance.Error(ex.Message);
+        //    }
+        //}
 
         //public WebResponseContent FeedbackOutbondIssue(List<Dt_OutStockLockInfo> outStockLockInfos)
         //{

--
Gitblit v1.9.3