From 225d11e2ddaa55d1d482201cb4d89c9486cdba69 Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期五, 20 六月 2025 12:27:52 +0800
Subject: [PATCH] 更新代码

---
 代码管理/WMS/WIDESEA_WMSServer/WIDESEA_InboundService/InboundOrderService.cs |  269 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 261 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 cf79150..3613253 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"
@@ -3,6 +3,8 @@
 using Microsoft.AspNetCore.Mvc.RazorPages;
 using Newtonsoft.Json;
 using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
+using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
+using Org.BouncyCastle.Asn1.Ocsp;
 using SqlSugar;
 using System;
 using System.Collections;
@@ -863,11 +865,17 @@
 
                     stockInfoDetails.Add(stockInfoDetail);
 
-                    notGroupDetail.ReceiptQuantity += model.Quantity;
-                    if (notGroupDetail.ReceiptQuantity>notGroupDetail.OrderQuantity)
+                    decimal decimalReceiptQuantity = Convert.ToDecimal(notGroupDetail.ReceiptQuantity);
+                    decimal decimalModelQuantity = Convert.ToDecimal(model.Quantity);
+                    decimal decimalOrderQuantity = Convert.ToDecimal(notGroupDetail.OrderQuantity);
+                    decimalReceiptQuantity += decimalModelQuantity;
+                    // 妫�鏌ユ槸鍚﹁秴鍑鸿鍗曟暟閲�
+                    if (decimalReceiptQuantity > decimalOrderQuantity)
                     {
-                        return WebResponseContent.Instance.Error($"缁勭洏鏁伴噺婧㈠嚭{notGroupDetail.ReceiptQuantity - notGroupDetail.OrderQuantity}");
+                        return WebResponseContent.Instance.Error($"缁勭洏鏁伴噺婧㈠嚭{decimalReceiptQuantity - decimalOrderQuantity}");
                     }
+                    // 杞洖float绫诲瀷瀛樺偍锛屼絾姣旇緝鍜岃绠楅兘浣跨敤decimal瀹屾垚
+                    notGroupDetail.ReceiptQuantity = Convert.ToSingle(decimalReceiptQuantity);
                     if (notGroupDetail.OrderDetailStatus == OrderDetailStatusEnum.New.ObjToInt())
                     {
                         notGroupDetail.OrderDetailStatus = OrderDetailStatusEnum.GroupAndInbound.ObjToInt();
@@ -899,6 +907,232 @@
                 content.Error(ex.Message);
             }
             return content;
+        }
+        public WebResponseContent MaterielPPorGM(string materielBoxCode = "")
+        {
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                string SerNum = "";
+                if (materielBoxCode.LastIndexOf("SC:")<0)
+                {
+                    SerNum = materielBoxCode;
+                }
+                else
+                {
+                    SerNum = materielBoxCode.Substring(0, materielBoxCode.LastIndexOf("SC:") - 1);
+                }
+                MatSerNumAnalysisModel model = CodeAnalysisHelper.CodeAnalysis<MatSerNumAnalysisModel>(AnalysisCodeEnum.MatSerNumAnalysis, SerNum);
+                //楠岃瘉鍒ゆ柇鏃堕棿鏍煎紡
+                WebResponseContent IsValidContent = IsValidMCDates(new List<MatSerNumAnalysisModel>() { model });
+                if (!IsValidContent.Status)
+                {
+                    return content.Error(IsValidContent.Message);
+                }
+                string result = "";
+                if (materielBoxCode.LastIndexOf("SC:") > 0)
+                {
+                    result = materielBoxCode.Substring(materielBoxCode.LastIndexOf("SC:") + 3);
+                }
+                //鑾峰彇鍏ュ簱鍗曟槑缁�
+                Dt_InboundOrderDetail inboundOrderDetail = _inboundRepository.InboundOrderDetailRepository.QueryFirst(x=>x.BatchNo== model.LotNo && x.MaterielCode== model.MaterielCode);
+                if (inboundOrderDetail == null)
+                {
+                    return InOtherGMOrPP(model, result);
+                }
+                Dt_InboundOrder inboundOrder = BaseDal.Db.Queryable<Dt_InboundOrder>().First(x => x.Id == inboundOrderDetail.OrderId);
+
+                if (inboundOrder == null)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒板叆搴撳崟淇℃伅");
+                }
+                Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseId == inboundOrder.WarehouseId);
+                //闄ら噰璐叆搴撳崟浠ュ鍏朵粬鍏ュ簱鍗曠粍鐩樻暟鎹鐞�
+                if (inboundOrder.OrderType != InOrderTypeEnum.Purchase.ObjToInt())
+                {
+                    return OtherInGroup(inboundOrder, model.LotNo, 0, warehouse, new List<MatSerNumAnalysisModel>() { model });
+                }
+                Dt_ReceiveOrder receiveOrder = _inboundRepository.ReceiveOrderRepository.Db.Queryable<Dt_ReceiveOrder>().Where(x => x.ReceiveOrderNo == inboundOrder.UpperOrderNo).Includes(x => x.Details).First();
+                if (receiveOrder == null)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒板搴旂殑鏀惰揣鍗�");
+                }
+                if (receiveOrder.Details == null || receiveOrder.Details.Count <= 0)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒板搴旂殑鏀惰揣鍗曟槑缁�");
+                }
+
+                List<string> purchaseOrderNos = receiveOrder.Details.Select(x => x.PurchaseOrderNo).ToList();
+
+                string materielCode = model?.MaterielCode ?? "";
+                Dt_MaterielInfo materielInfo = _basicRepository.MaterielInfoRepository.QueryFirst(x => x.MaterielCode == materielCode);
+                if (materielInfo == null)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒拌鐗╂枡鐨勪俊鎭�");
+                }
+
+                float beforeQuantity = 0;
+                
+                Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletCode == model.LotNo).Includes(x => x.Details).First();
+                if (stockInfo == null)
+                {
+                    stockInfo = new Dt_StockInfo()
+                    {
+                        PalletCode = model.LotNo,
+                        StockStatus = StockStatusEmun.缁勭洏鏆傚瓨.ObjToInt(),
+                        WarehouseId = inboundOrder.WarehouseId,
+                        PalletType = GetPalletTypeGMOrPP(warehouse, result.IsNullOrEmpty() ? "" : result.Split("*")[0]),
+                        StockLength = result.IsNullOrEmpty() ? 0 : result.Split("*")[0].ObjToInt(),
+                        Details = new List<Dt_StockInfoDetail>()
+                    };
+                }
+                else
+                {
+                    if (stockInfo.StockStatus != StockStatusEmun.缁勭洏鏆傚瓨.ObjToInt())
+                    {
+                        return WebResponseContent.Instance.Error($"鎵樼洏鍙烽噸澶�");
+                    }
+                }
+                if (stockInfo.PalletType==-1)
+                {
+                    return WebResponseContent.Instance.Error($"鎵樼洏绫诲瀷涓嶅瓨鍦�");
+                }
+                List<Dt_StockInfoDetail> stockInfoDetails = new List<Dt_StockInfoDetail>();
+                if (purchaseOrderNos.FirstOrDefault(x => x == model.PurchaseOrderNo) == null)
+                {
+                    return WebResponseContent.Instance.Error($"鏈湪鏀惰揣鏄庣粏涓壘鍒拌閲囪喘鍗�");
+                }
+
+                if (inboundOrderDetail.OrderDetailStatus > OrderDetailStatusEnum.Inbounding.ObjToInt() || inboundOrderDetail.OrderQuantity == inboundOrderDetail.ReceiptQuantity)
+                {
+                    return WebResponseContent.Instance.Error($"璇ョ墿鏂欏湪璇ュ叆搴撳崟涓凡鍏ㄩ儴缁勭洏瀹屾垚");
+                }
+                Dt_StockInfoDetail stockInfoDetail = new Dt_StockInfoDetail()
+                {
+                    BatchNo = model.LotNo,
+                    MaterielCode = materielInfo.MaterielCode,
+                    MaterielName = materielInfo.MaterielName,
+                    MaterielSpec = materielInfo.MaterielSpec,
+                    OrderNo = inboundOrder.InboundOrderNo,
+                    SerialNumber = model.SerialNumber,
+                    StockQuantity = model.Quantity,
+                    OutboundQuantity = 0,
+                    Unit = materielInfo.MaterielUnit,
+                    Status = StockStatusEmun.缁勭洏鏆傚瓨.ObjToInt(),
+                    ProductionDate = model.ProductionDate,
+                    EffectiveDate = model.EffectiveDate,
+                    InboundOrderRowNo = inboundOrderDetail.RowNo,
+                };
+
+                stockInfo.Details.Add(stockInfoDetail);
+
+                stockInfoDetails.Add(stockInfoDetail);
+
+                inboundOrderDetail.ReceiptQuantity += model.Quantity;
+                if (inboundOrderDetail.ReceiptQuantity > inboundOrderDetail.OrderQuantity)
+                {
+                    return WebResponseContent.Instance.Error($"缁勭洏鏁伴噺婧㈠嚭{inboundOrderDetail.ReceiptQuantity - inboundOrderDetail.OrderQuantity}");
+                }
+                if (inboundOrderDetail.OrderDetailStatus == OrderDetailStatusEnum.New.ObjToInt())
+                {
+                    inboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.GroupAndInbound.ObjToInt();
+                }
+                float totalQuantity = stockInfo.Details.Sum(x => x.StockQuantity);
+                if (inboundOrder.OrderStatus == InOrderStatusEnum.鏈紑濮�.ObjToInt())
+                {
+                    inboundOrder.OrderStatus = InOrderStatusEnum.鍏ュ簱涓�.ObjToInt();
+                }
+                _inboundRepository.InboundOrderDetailRepository.UpdateData(inboundOrderDetail);
+                _inboundRepository.InboundOrderRepository.UpdateData(inboundOrder);
+                _recordService.StockQuantityChangeRecordService.AddStockChangeRecord(stockInfo, stockInfoDetails, beforeQuantity, totalQuantity, StockChangeTypeEnum.MaterielGroup);
+                content.OK(data: stockInfo);
+            }
+            catch (Exception ex)
+            {
+                content.Error(ex.Message);
+            }
+            return content;
+        }
+        public WebResponseContent InOtherGMOrPP(MatSerNumAnalysisModel model,string request = "")
+        {
+            string materielCode = model?.MaterielCode ?? "";
+            Dt_MaterielInfo materielInfo = _basicRepository.MaterielInfoRepository.QueryFirst(x => x.MaterielCode == materielCode);
+            if (materielInfo == null)
+            {
+                return WebResponseContent.Instance.Error($"鏈壘鍒拌鐗╂枡鐨勪俊鎭�");
+            }
+            float beforeQuantity = 0;
+            Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseId == materielInfo.WarehouseId);
+            Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletCode == model.LotNo).Includes(x => x.Details).First();
+            if (stockInfo == null)
+            {
+                stockInfo = new Dt_StockInfo()
+                {
+                    PalletCode = model.LotNo,
+                    StockStatus = StockStatusEmun.缁勭洏鏆傚瓨.ObjToInt(),
+                    WarehouseId = warehouse.WarehouseId,
+                    PalletType = GetPalletTypeGMOrPP(warehouse, request.IsNullOrEmpty() ?"":request.Split("*")[0]),
+                    StockLength = request.IsNullOrEmpty()?0:request.Split("*")[0].ObjToInt(),
+                    Details = new List<Dt_StockInfoDetail>()
+                };
+            }
+            else
+            {
+                if (stockInfo.StockStatus != StockStatusEmun.缁勭洏鏆傚瓨.ObjToInt())
+                {
+                    return WebResponseContent.Instance.Error($"鎵樼洏鍙烽噸澶�");
+                }
+            }
+            if (stockInfo.PalletType == -1)
+            {
+                return WebResponseContent.Instance.Error($"鎵樼洏绫诲瀷涓嶅瓨鍦�");
+            }
+            List<Dt_StockInfoDetail> stockInfoDetails = new List<Dt_StockInfoDetail>();
+            Dt_StockInfoDetail stockInfoDetail = new Dt_StockInfoDetail()
+            {
+                BatchNo = model.LotNo,
+                MaterielCode = materielInfo.MaterielCode,
+                MaterielName = materielInfo.MaterielName,
+                MaterielSpec = materielInfo.MaterielSpec,
+                OrderNo = "",
+                SerialNumber = model.SerialNumber,
+                StockQuantity = model.Quantity,
+                OutboundQuantity = 0,
+                Unit = materielInfo.MaterielUnit,
+                Status = StockStatusEmun.缁勭洏鏆傚瓨.ObjToInt(),
+                ProductionDate = model.ProductionDate,
+                EffectiveDate = model.EffectiveDate,
+                InboundOrderRowNo = 0,
+            };
+
+            stockInfo.Details.Add(stockInfoDetail);
+
+            stockInfoDetails.Add(stockInfoDetail);
+            float totalQuantity = stockInfo.Details.Sum(x => x.StockQuantity);
+            _recordService.StockQuantityChangeRecordService.AddStockChangeRecord(stockInfo, stockInfoDetails, beforeQuantity, totalQuantity, StockChangeTypeEnum.MaterielGroup);
+            return WebResponseContent.Instance.OK(data: stockInfo);
+        }
+        public int GetPalletTypeGMOrPP(Dt_Warehouse warehouse, string boxWidth)
+        {
+            if (warehouse.WarehouseCode == WarehouseEnum.HA152.ToString())
+            {
+
+                if (boxWidth.ObjToInt() <= 690 && boxWidth.ObjToInt()>=520)
+                {
+                    return 15;
+                }
+                else if (boxWidth.ObjToInt() > 690 && boxWidth.ObjToInt() <= 1400)
+                {
+                    return 16;
+                }
+
+            }
+            else if (warehouse.WarehouseCode == WarehouseEnum.HA58.ToString())
+            {
+                Dt_PalletTypeInfo palletTypeInfo = _palletTypeInfoRepository.QueryFirst(x => x.WarehouseId == warehouse.WarehouseId);
+                return palletTypeInfo.PalletType;
+            }
+            return -1;
         }
         public WebResponseContent OtherInGroup(Dt_InboundOrder inboundOrder,string? palletCode,int Initiallife,Dt_Warehouse warehouse,List<MatSerNumAnalysisModel> models)
         {
@@ -1331,6 +1565,8 @@
             try
             {
                 List<ERPProItemsItem> proItemsItems = new List<ERPProItemsItem>();
+                Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x=>x.WarehouseId==mesProInOrder.WarehouseId);
+                string batchNoRemark = "";
                 foreach (var item in mesProInOrder.Details)
                 {
                     ERPProItemsItem proItemsItem = new ERPProItemsItem()
@@ -1338,7 +1574,7 @@
                         PartNum = item.ProductCode,
                         Rev=item.ProductVersion,
                         DateCode=item.DateCode,
-                        BatchNumber= item.BagNo,
+                        BatchNumber= item.ProductCode,
                         XLocation=item.XSite,
                         Xqty=item.XQty,
                         QtySet=item.SETQty,
@@ -1354,6 +1590,7 @@
                             }
                         }
                     };
+                    batchNoRemark += item.BagNo + ",";
                     proItemsItems.Add(proItemsItem);
                 }
                 ERPProInboundModel proInboundModel = new ERPProInboundModel()
@@ -1363,13 +1600,20 @@
                     CreatorCode = "GSWMS",
                     CompanyCode = "HATC",
                     FactoryCode = "HA02",
-                    WarehouseCode = "HA71",
-                    LocationCode = "HA71",
+                    WarehouseCode = warehouse.WarehouseCode,
+                    LocationCode = warehouse.WarehouseCode,
                     StockDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                     StockFormType= "Production",
-                    StockFormItems= proItemsItems
+                    StockFormItems= proItemsItems,
+                    Remark=batchNoRemark
                 };
-                _invokeERPService.InvokeProInApi(proInboundModel);
+                string response = _invokeERPService.InvokeProInApi(proInboundModel);
+                ErpRequestContent requestContent = response.DeserializeObject<ErpRequestContent>();
+                if (requestContent.res != 1)
+                {
+                    return content.Error($"{requestContent.Data}");
+                }
+                content.OK();
             }
             catch (Exception ex)
             {
@@ -1560,6 +1804,15 @@
                 }
                 return palletTypeInfo.PalletType;
             }
+            else if (warehouse.WarehouseCode == WarehouseEnum.HA58.ObjToString())
+            {
+                Dt_PalletTypeInfo palletTypeInfo = _palletTypeInfoRepository.QueryFirst(x => x.CodeStartStr == palletCode.Substring(0, 2));
+                if (palletTypeInfo == null)
+                {
+                    throw new Exception($"鎵樼洏鍙烽敊璇�");
+                }
+                return palletTypeInfo.PalletType;
+            }
             return -1;
         }
         /// <summary>

--
Gitblit v1.9.3