From 994dced313b956180f1b95e68760290c5ed931ba Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期三, 15 一月 2025 19:12:47 +0800
Subject: [PATCH] Merge branch 'master' of http://115.159.85.185:8098/r/MeiRuiAn/HuaiAn

---
 代码管理/WMS/WIDESEA_WMSServer/WIDESEA_InboundService/InboundOrderService.cs |  153 ++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 145 insertions(+), 8 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_InboundService/InboundOrderService.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_InboundService/InboundOrderService.cs"
index 8a57f20..bcf23c8 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_InboundService/InboundOrderService.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_InboundService/InboundOrderService.cs"
@@ -18,8 +18,10 @@
 using WIDESEA_Core.BaseRepository;
 using WIDESEA_Core.BaseServices;
 using WIDESEA_Core.CodeConfigEnum;
+using WIDESEA_Core.DB;
 using WIDESEA_Core.Enums;
 using WIDESEA_Core.Helper;
+using WIDESEA_Core.Seed;
 using WIDESEA_Core.Utilities;
 using WIDESEA_DTO;
 using WIDESEA_DTO.Basic;
@@ -340,6 +342,7 @@
 
                 List<Dt_StockInfoDetail> stockInfoDetails = new List<Dt_StockInfoDetail>();
                 List<int> detailKeys = new List<int>();
+                int newCount = 0;
                 foreach (var model in models)
                 {
                     if (purchaseOrderNos.FirstOrDefault(x => x == model.PurchaseOrderNo) == null)
@@ -370,6 +373,7 @@
                         EffectiveDate = model.EffectiveDate,
                         InboundOrderRowNo = notGroupDetail.RowNo,
                     };
+                    newCount++;
 
                     if (stockInfo.Id > 0)
                     {
@@ -385,7 +389,7 @@
                 }
 
                 //鍏ュ簱鏄庣粏鏂板瀹屾垚鏁伴噺
-                int newCount = inboundOrderDetails.Where(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()).ToList().Count;
+                //int newCount = inboundOrderDetails.Where(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()).ToList().Count;
                 if (inboundOrder.Details.Count == (newCount + oldCount))
                 {
                     inboundOrder.OrderStatus = InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt();
@@ -428,7 +432,7 @@
                 }
                 ERPInboundModel eRPInboundModel = new ERPInboundModel()
                 {
-                    Code = inboundOrder.InboundOrderNo,
+                    Code = CreateCodeByRule(nameof(RuleCodeEnum.RLCodeRule)),
                     CreatorCode = inboundOrder.Creater,
                     EntDate = inboundOrder.CreateDate.ToString("yyyy-MM-dd HH:mm:ss"),
                     StockDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
@@ -509,7 +513,7 @@
                     return WebResponseContent.Instance.Error($"鏈壘鍒拌鐗╂枡鐨勪俊鎭�");
                 }
 
-                List<Dt_InboundOrderDetail> inboundOrderDetails = inboundOrder.Details.Where(x => x.MaterielCode == materielCode).ToList();
+                List<Dt_InboundOrderDetail> inboundOrderDetails = inboundOrder.Details.Where(x => x.MaterielCode == materielCode && x.BatchNo==(models.FirstOrDefault()?.LotNo ?? "")).ToList();
 
                 if (inboundOrderDetails == null || inboundOrderDetails.Count <= 0)
                 {
@@ -530,7 +534,7 @@
                         PalletCode = palletCode,
                         StockStatus = StockStatusEmun.缁勭洏鏆傚瓨.ObjToInt(),
                         WarehouseId = inboundOrder.WarehouseId,
-                        PalletType = GetPalletType(warehouse, palletCode, materielInfo),
+                        PalletType = GetPalletType(warehouse, palletCode),
                         Details = new List<Dt_StockInfoDetail>()
                     };
                 }
@@ -674,7 +678,7 @@
                         PalletCode = palletCode,
                         StockStatus = StockStatusEmun.鎵嬪姩缁勭洏鏆傚瓨.ObjToInt(),
                         WarehouseId = warehouse.WarehouseId,
-                        PalletType = GetPalletType(warehouse, palletCode, materielInfo),
+                        PalletType = GetPalletType(warehouse, palletCode),
                         Details = new List<Dt_StockInfoDetail>()
                     };
                 }
@@ -762,9 +766,10 @@
             return content;
         }
         /// <summary>
-        /// 鍏ュ簱瀹屾垚涓婃姤ERP
+        /// 鍏ュ簱瀹屾垚涓婃姤ERP 寮冪敤
         /// </summary>
         /// <returns></returns>
+        #region 寮冪敤
         public WebResponseContent FeedbackInboundOrder(Dt_StockInfo stockInfo, Dt_InboundOrder inboundOrder, List<ERPInboundDetailModel> detailModels)
         {
             WebResponseContent content = new WebResponseContent();
@@ -786,7 +791,7 @@
 
                 ERPInboundModel model = new ERPInboundModel()
                 {
-                    Code = inboundOrder.InboundOrderNo,
+                    Code = CreateCodeByRule(nameof(RuleCodeEnum.RLCodeRule)),
                     CreatorCode = inboundOrder.Creater,//娴嬭瘯
                     EntDate = inboundOrder.CreateDate.ToString("yyyy-MM-dd HH:mm:ss"),
                     StockDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
@@ -807,6 +812,138 @@
                 content.Error(ex.Message);
             }
             return content;
+        }
+        #endregion
+        /// <summary>
+        /// 鍏ュ簱瀹屾垚涓婃姤ERP
+        /// </summary>
+        /// <returns></returns>
+        public WebResponseContent FeedbackInboundOrder(Dt_InboundOrder inboundOrder, List<Dt_StockInfoDetail> stockInfoDetails)
+        {
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                if (inboundOrder.Details.Count == 0)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒板叆搴撳崟鏄庣粏淇℃伅");
+                }
+                if (stockInfoDetails.Count==0)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒板簱瀛樻槑缁嗕俊鎭�");
+                }
+                Dt_Warehouse warehouse = _warehouseService.Repository.QueryFirst(x => x.WarehouseId == inboundOrder.WarehouseId);
+                if (warehouse == null)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒颁粨搴撲俊鎭�");
+                }
+                List<ERPInboundDetailModel>? detailModels = null;
+                foreach (var item in stockInfoDetails)
+                {
+                    Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.QueryFirst(x => x.Id == item.StockId);
+                    if (detailModels!=null && detailModels.FirstOrDefault(x=>x.Rack==stockInfo.LocationCode)!=null)
+                    {
+                        var detailModel = detailModels.FirstOrDefault(x => x.Rack == stockInfo.LocationCode);
+                        detailModel.Quantity = (Convert.ToDouble(detailModel.Quantity) + item.StockQuantity).ToString();
+                    }
+                    else
+                    {
+                        ERPInboundDetailModel detailModel = new ERPInboundDetailModel()
+                        {
+                            ExpiryDate = item.EffectiveDate ?? "",
+                            LocationCode = warehouse.WarehouseCode,
+                            MaterialsCode = item.MaterielCode,
+                            MfgDate = item.ProductionDate ?? "",
+                            QtyCustoms = "0",
+                            Quantity = item.StockQuantity.ToString(),
+                            Rack = stockInfo.LocationCode,
+                            ReceiptCode = inboundOrder.UpperOrderNo,
+                            ReceiptSerNo = item.InboundOrderRowNo.ToString()
+                        };
+                        detailModels.Add(detailModel);
+                    }
+                }
+                ERPInboundModel model = new ERPInboundModel()
+                {
+                    Code = CreateCodeByRule(nameof(RuleCodeEnum.RLCodeRule)),
+                    CreatorCode = inboundOrder.Creater,//娴嬭瘯
+                    EntDate = inboundOrder.CreateDate.ToString("yyyy-MM-dd HH:mm:ss"),
+                    StockDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
+                    SuppliersId = inboundOrder.SupplierId,
+                    Type = "S",
+                    UniqueTag = inboundOrder.Id.ToString(),
+                    WarehouseCode = warehouse.WarehouseCode,
+                    Way = 1,
+                    Details = detailModels
+                };
+                //鎺ㄩ�丒RP 娴嬭瘯娉ㄩ噴
+                _invokeERPService.InvokeInboundOrderApi(model);
+                return WebResponseContent.Instance.OK();
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                content.Error(ex.Message);
+            }
+            return content;
+        }
+        static object lock_code = new object();
+        public string CreateCodeByRule(string ruleCode)
+        {
+            lock (lock_code)
+            {
+
+                string code = string.Empty;
+                DateTime dateTime = DateTime.Now;
+                DateTime now = DateTime.Now;
+                try
+                {
+                    if (string.IsNullOrEmpty(ruleCode))
+                        throw new ArgumentNullException(nameof(ruleCode));
+                    SqlSugarClient sugarClient = new SqlSugarClient(new ConnectionConfig
+                    {
+                        IsAutoCloseConnection = false,
+                        DbType = DbType.SqlServer,
+                        ConnectionString = DBContext.ConnectionString
+                    });
+                    Dt_CodeRuleConfig codeRuleConfig = sugarClient.Queryable<Dt_CodeRuleConfig>().Where(x => x.RuleCode == ruleCode).First();
+                    if (codeRuleConfig == null)
+                        throw new ArgumentNullException(nameof(codeRuleConfig));
+                    if (codeRuleConfig.ModifyDate != null)
+                    {
+                        dateTime = Convert.ToDateTime(codeRuleConfig.ModifyDate);
+                    }
+                    else
+                    {
+                        dateTime = Convert.ToDateTime(codeRuleConfig.CreateDate);
+                    }
+
+                    if (now.Year == dateTime.Year && now.Month == dateTime.Month && now.Day == dateTime.Day)
+                    {
+                        now = dateTime;
+                        codeRuleConfig.CurrentVal = Convert.ToInt32(codeRuleConfig.CurrentVal) + 1;
+                    }
+                    else
+                    {
+                        codeRuleConfig.CurrentVal = 1;
+                    }
+                    codeRuleConfig.ModifyDate = DateTime.Now;
+                    code = codeRuleConfig.Format;
+                    code = code.Replace($"[{CodeFormatTypeEnum.YYYY}]", now.Year.ToString().PadLeft(4, '0'));
+                    code = code.Replace($"[{CodeFormatTypeEnum.MM}]", now.Month.ToString().PadLeft(2, '0'));
+                    code = code.Replace($"[{CodeFormatTypeEnum.DD}]", now.Day.ToString().PadLeft(2, '0'));
+                    code = code.Replace($"[{CodeFormatTypeEnum.ST}]", codeRuleConfig.StartStr?.ToString() ?? "");
+                    code = code.Replace($"[{CodeFormatTypeEnum.NUM}]", codeRuleConfig.CurrentVal.ToString().PadLeft(codeRuleConfig.Length, '0'));
+                    Dictionary<string, object> keyValuePairs = new Dictionary<string, object>() { { nameof(codeRuleConfig.CurrentVal), codeRuleConfig.CurrentVal }, { nameof(codeRuleConfig.Id), codeRuleConfig.Id }, { nameof(codeRuleConfig.ModifyDate), DateTime.Now } };
+                    sugarClient.Updateable(keyValuePairs).AS(MainDb.CodeRuleConfig).WhereColumns(nameof(codeRuleConfig.Id)).ExecuteCommand();
+                    sugarClient.Updateable(codeRuleConfig);
+
+                }
+                catch (Exception ex)
+                {
+
+                }
+                return code;
+            }
         }
 
         /// <summary>
@@ -892,7 +1029,7 @@
         //    }
         //}
 
-        public int GetPalletType(Dt_Warehouse warehouse, string palletCode, Dt_MaterielInfo materielInfo)
+        public int GetPalletType(Dt_Warehouse warehouse, string palletCode)
         {
             if (warehouse.WarehouseCode == WarehouseEnum.HA64.ToString())
             {

--
Gitblit v1.9.3