From e83c793bebdb1b9ecdcd79fab8d83fd167baa817 Mon Sep 17 00:00:00 2001
From: wankeda <Administrator@DESKTOP-HAU3ST3>
Date: 星期一, 19 一月 2026 15:51:56 +0800
Subject: [PATCH] 盘点流程

---
 WMS/WIDESEA_WMSServer/WIDESEA_InboundService/Base/InboundOrderService.cs | 1752 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 1,666 insertions(+), 86 deletions(-)

diff --git a/WMS/WIDESEA_WMSServer/WIDESEA_InboundService/Base/InboundOrderService.cs b/WMS/WIDESEA_WMSServer/WIDESEA_InboundService/Base/InboundOrderService.cs
index c4ff7db..cf22938 100644
--- a/WMS/WIDESEA_WMSServer/WIDESEA_InboundService/Base/InboundOrderService.cs
+++ b/WMS/WIDESEA_WMSServer/WIDESEA_InboundService/Base/InboundOrderService.cs
@@ -1,29 +1,45 @@
 锘縰sing AutoMapper;
 using MailKit.Search;
+using Newtonsoft.Json;
 using SqlSugar;
 using System;
 using System.Collections.Generic;
+using System.Data;
+using System.Globalization;
 using System.Linq;
 using System.Reflection.Metadata;
 using System.Text;
 using System.Threading.Tasks;
+using WIDESEA_BasicRepository;
 using WIDESEA_Common;
+using WIDESEA_Common.OrderEnum;
+using WIDESEA_Common.TaskEnum;
 using WIDESEA_Core;
 using WIDESEA_Core.BaseRepository;
 using WIDESEA_Core.BaseServices;
+using WIDESEA_Core.CodeConfigEnum;
 using WIDESEA_Core.Enums;
 using WIDESEA_Core.Helper;
 using WIDESEA_Core.Utilities;
 using WIDESEA_DTO;
+using WIDESEA_DTO.Basic;
+using WIDESEA_DTO.ERP;
 using WIDESEA_DTO.Inbound;
 using WIDESEA_DTO.Outbound;
+using WIDESEA_IBasicRepository;
 using WIDESEA_IBasicService;
 using WIDESEA_IInboundRepository;
 using WIDESEA_IInboundService;
+using WIDESEA_InboundRepository;
+using WIDESEA_IStockRepository;
 using WIDESEA_IStockService;
 using WIDESEA_ITaskInfoRepository;
 using WIDESEA_Model.Models;
+using WIDESEA_Model.Models.Inbound;
 using static WIDESEA_Common.HouseInventoryIn;
+using static WIDESEA_Common.HouseSyncretism;
+using static WIDESEA_Common.InventoryAllocate;
+using Parameter = WIDESEA_Common.Parameter;
 
 namespace WIDESEA_InboundService
 {
@@ -32,58 +48,294 @@
         private readonly IMapper _mapper;
         private readonly IUnitOfWorkManage _unitOfWorkManage;
         private readonly ITaskRepository _taskRepository;
-
+        private readonly IInboundRepository _inboundRepository;
+        private readonly IBasicRepository _basicRepository;
         private IBasicService _basicService;
         private IStockService _stockService;
         private IInboundOrderDetailService _inboundOrderDetailService;
         private IInboundOrder_HtyService _inboundOrderHtyService;
         private IInboundOrderDetail_HtyService _inboundOrderDetail_HtyService;
+        private IWarehouseService _warehouseService;
+        private readonly IStockRepository _stockRepository;
+        private IPalletTypeInfoRepository _palletTypeInfoRepository;
+        private readonly IReturnOrderRepository _returnOrderRepository;
+        private readonly ICPInboundOrderDetailRepository _cPInboundOrderDetailRepository;
+
 
         public IInboundOrderRepository Repository => BaseDal;
 
-        public InboundOrderService(IInboundOrderRepository BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, ITaskRepository taskRepository, IBasicService basicService, IStockService stockService, IInboundOrderDetailService inboundOrderDetailService, IInboundOrder_HtyService inboundOrderHtyService, IInboundOrderDetail_HtyService inboundOrderDetail_HtyService) : base(BaseDal)
+        public InboundOrderService(IInboundOrderRepository BaseDal, IMapper mapper, IBasicService basicService, IBasicRepository basicRepository, IInboundRepository inboundRepository, IUnitOfWorkManage unitOfWorkManage, ITaskRepository taskRepository, IStockService stockService, IInboundOrderDetailService inboundOrderDetailService, IInboundOrder_HtyService inboundOrderHtyService, IInboundOrderDetail_HtyService inboundOrderDetail_HtyService, IWarehouseService warehouseService, IStockRepository stockRepository, IPalletTypeInfoRepository palletTypeInfoRepository, IReturnOrderRepository returnOrderRepository, ICPInboundOrderDetailRepository cPInboundOrderDetailRepository) : base(BaseDal)
         {
             _mapper = mapper;
             _unitOfWorkManage = unitOfWorkManage;
             _taskRepository = taskRepository;
-            _basicService = basicService;
             _stockService = stockService;
+            _inboundRepository = inboundRepository;
+            _basicRepository = basicRepository;
             _inboundOrderDetailService = inboundOrderDetailService;
             _inboundOrderHtyService = inboundOrderHtyService;
             _inboundOrderDetail_HtyService = inboundOrderDetail_HtyService;
+            _basicService = basicService;
+            _warehouseService = warehouseService;
+            _stockRepository = stockRepository;
+            _palletTypeInfoRepository = palletTypeInfoRepository;
+            _returnOrderRepository = returnOrderRepository;
+            _cPInboundOrderDetailRepository = cPInboundOrderDetailRepository;
         }
 
         /// <summary>
-        /// 娣诲姞鍗曟嵁
+        /// PDA鎵爜缁勭洏
         /// </summary>
-        /// <param name="saveModel"></param>
+        /// <param name="materielGroupDTO"></param>
         /// <returns></returns>
-        public override WebResponseContent AddData(SaveModel saveModel)
+        public WebResponseContent MaterielGroup(SaveModel saveModel)
         {
-            InboundOrderAddDTO orderAddDTO = saveModel.MainData.DicToModel<InboundOrderAddDTO>();
-            orderAddDTO.Details = saveModel.DetailData.DicToIEnumerable<InboundOrderDetailAddDTO>();
-            return AddInboundOrder(orderAddDTO);
-        }
-
-        /// <summary>
-        /// 娣诲姞鍗曟嵁
-        /// </summary>
-        /// <param name="orderAddDTO">鍗曟嵁娣诲姞DTO</param>
-        /// <returns></returns>
-        public WebResponseContent AddInboundOrder(InboundOrderAddDTO orderAddDTO)
-        {
-            WebResponseContent content = new();
+            WebResponseContent content = new WebResponseContent();
             try
             {
-                #region 楠岃瘉鏁版嵁
-                (bool, string, object?) result = CheckInboundOrderAddData(orderAddDTO);
-                if (!result.Item1) return content = WebResponseContent.Instance.Error(result.Item2);
-                #endregion
 
-                Dt_InboundOrder inboundOrder = _mapper.Map<Dt_InboundOrder>(orderAddDTO);
-                inboundOrder.OrderStatus = InboundStatusEnum.鏈紑濮�.ObjToInt();
-                bool a = BaseDal.Db.InsertNav(inboundOrder).Include(x => x.Details).ExecuteCommand();
-                content = WebResponseContent.Instance.OK();
+                var orderNo = saveModel.MainData["orderNo"].ToString();
+                var palletCode = saveModel.MainData["palletCode"].ToString();
+                var warehouseId = saveModel.MainData["warehouseId"].ObjToInt();
+                var Initiallife = saveModel.MainData["initiallife"].ObjToInt();
+                List<string> serialNumbers = new List<string>();
+                List<decimal> quantitys = new List<decimal>();
+                foreach (var item in saveModel.DelKeys)
+                {
+                    string json = JsonConvert.SerializeObject(item);
+                    Dictionary<string, object> delKeyDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
+
+
+                    if (delKeyDict.TryGetValue("serialNumber", out object serialNumberObj))
+                    {
+                        string serialNumber = serialNumberObj?.ToString();
+                        if (!string.IsNullOrEmpty(serialNumber))
+                        {
+                            serialNumbers.Add(serialNumber);
+                        }
+                        else
+                        {
+                            return WebResponseContent.Instance.Error("serialNumber鐨勫�间负绌�");
+                        }
+                    }
+                    if (delKeyDict.TryGetValue("quantity", out object quantityObj))
+                    {
+                        if (quantityObj == null)
+                        {
+                            return WebResponseContent.Instance.Error("鐗╂枡鏁伴噺鐨勫�间负绌�");
+                        }
+                        decimal quantity;
+                        try
+                        {
+                            quantity = Convert.ToDecimal(quantityObj);
+                        }
+                        catch
+                        {
+                            return WebResponseContent.Instance.Error($"鐗╂枡鏁伴噺{quantityObj}鏃犳硶杞崲涓烘暟瀛�");
+                        }
+                        if (quantity <= 0)
+                        {
+                            return WebResponseContent.Instance.Error("鐗╂枡鏁伴噺蹇呴』澶т簬0");
+                        }
+
+                        quantitys.Add(quantity);
+                    }
+                    else
+                    {
+                        return WebResponseContent.Instance.Error("缂哄皯鐗╂枡鏁伴噺瀛楁");
+                    }
+                }
+                Dt_Warehouse warehouse = _warehouseService.Repository.QueryFirst(x => x.WarehouseId == warehouseId);
+                if (warehouse == null)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒拌浠撳簱淇℃伅");
+                }
+
+                Dt_InboundOrder inboundOrder = BaseDal.Db.Queryable<Dt_InboundOrder>().Where(x => x.OrderNo == orderNo && x.WarehouseId == warehouse.WarehouseId).Includes(x => x.Details).First();
+                if (inboundOrder == null)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒板叆搴撳崟淇℃伅");
+                }
+                if (inboundOrder.Details == null || inboundOrder.Details.Count <= 0)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒板叆搴撳崟鏄庣粏淇℃伅");
+                }
+                List<MatSerNumAnalysisModel> models = CodeAnalysisHelper.CodeAnalysis<MatSerNumAnalysisModel>(AnalysisCodeEnum.MatSerNumAnalysis, serialNumbers);
+                //楠岃瘉鍒ゆ柇鏃堕棿鏍煎紡
+                WebResponseContent IsValidContent = IsValidMCDates(models);
+                if (!IsValidContent.Status)
+                {
+                    return content.Error(IsValidContent.Message);
+                }
+
+                string materielCode = models.FirstOrDefault()?.MaterielCode ?? "";
+                Dt_MaterielInfo materielInfo = _basicRepository.MaterielInfoRepository.QueryFirst(x => x.MaterielCode == materielCode);
+                if (materielInfo == null)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒拌鐗╂枡鐨勪俊鎭�");
+                }
+                List<Dt_InboundOrderDetail> inboundOrderDetails = new List<Dt_InboundOrderDetail>();
+                ///鎵炬暟閲忓尮閰嶇殑
+                if (warehouse.WarehouseCode.Contains("BC"))
+                {
+                    inboundOrderDetails = inboundOrder.Details.Where(x => x.MaterielCode == materielCode && x.SupplierBatch == (models.FirstOrDefault()?.LotNo ?? "") && x.OrderQuantity > x.ReceiptQuantity && x.OrderQuantity == (quantitys.FirstOrDefault())).ToList();
+                }
+                else
+                {
+                    inboundOrderDetails = inboundOrder.Details.Where(x => x.MaterielCode == materielCode && x.BatchNo == (models.FirstOrDefault()?.LotNo ?? "")).ToList();
+                }
+
+
+                if (inboundOrderDetails == null || inboundOrderDetails.Count <= 0)
+                {
+                    return WebResponseContent.Instance.Error($"鏈湪鍏ュ簱鍗曟槑缁嗕腑鎵惧埌璇ョ墿鏂欎俊鎭垨鏁伴噺涓嶅尮閰�");
+                }
+                var inboundOrderDet = inboundOrderDetails.FirstOrDefault();
+
+                //Dt_StockInfo? stockInfo = _stockService.StockInfoService.GetStockByPalletCode(palletCode);
+
+                decimal beforeQuantity = 0;
+
+                Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletCode == palletCode).Includes(x => x.Details).First();
+                if (stockInfo == null)
+                {
+                    stockInfo = new Dt_StockInfo()
+                    {
+                        BatchNo = inboundOrderDet.BatchNo,
+                        PalletCode = palletCode,
+                        PalletType = GetPalletType(warehouse, palletCode),//GetPalletType(warehouse, palletCode)
+                        IsFull = true,
+                        StockStatus = (int)StockStatusEmun.缁勭洏鏆傚瓨,
+                        Creater = "WMS",
+                        CreateDate = DateTime.Now,
+                        MaterialType = (int)InventoryMaterialType.鍘熸潗鏂�,
+                        Materialweight = 0,
+                        Wlstatus = (int)InventoryMaterialStatus.鍚堟牸,
+                        Mgeneratetime = DateTime.Now,
+                        WarehouseId = warehouse.WarehouseId,
+                        System = inboundOrder.System,
+                        Details = new List<Dt_StockInfoDetail>()
+                    };
+                }
+                else
+                {
+                    //if (stockInfo.StockStatus != StockStatusEmun.缁勭洏鏆傚瓨.ObjToInt())
+                    //{
+                    return WebResponseContent.Instance.Error($"鎵樼洏鍙烽噸澶�,璇ユ墭鐩樺凡缁勮繃鐗╂枡");
+                    //}
+                    //beforeQuantity = stockInfo.Details.Sum(x => x.StockQuantity);
+                }
+
+                if (warehouse.WarehouseCode == WarehouseEnum.SC01_BC.ToString())
+                {
+                    stockInfo.Remark = Initiallife.ToString();
+                    string batchNo = models.FirstOrDefault()?.LotNo ?? "";
+                    //Dt_StockInfoDetail existDetail = _stockRepository.StockInfoDetailRepository.QueryFirst(x => x.BatchNo == batchNo);
+                    //if (existDetail != null)
+                    //{
+                    //    return WebResponseContent.Instance.Error($"{batchNo}娴嬭瘯鏋跺凡瀛樺湪");
+                    //}
+                    if (models.Count >= 2)
+                    {
+                        return WebResponseContent.Instance.Error($"缁勭洏鏄庣粏涓嶅敮涓�");
+                    }
+                    //if (palletCode.Substring(0, 1) == "6")
+                    //{
+                    //    stockInfo.PalletType = PalletTypeEnum.MediumPallet.ObjToInt();
+                    //}
+                    //else
+                    //{
+                    //    stockInfo.PalletType = PalletTypeEnum.LargestPallet.ObjToInt();
+                    //}
+                }
+                else if (warehouse.WarehouseCode == WarehouseEnum.SC01_BC.ToString())
+                {
+                    if (models.Count >= 2)
+                    {
+                        return WebResponseContent.Instance.Error($"缁勭洏鏄庣粏涓嶅敮涓�");
+                    }
+                }
+
+                List<Dt_StockInfoDetail> stockInfoDetails = new List<Dt_StockInfoDetail>();
+                foreach (var model in models)
+                {
+
+                    Dt_InboundOrderDetail notGroupDetail = new Dt_InboundOrderDetail();
+                    ///鎵炬暟閲忓尮閰嶇殑
+                    if (warehouse.WarehouseCode.Contains("BC"))
+                    {
+                        notGroupDetail = inboundOrderDetails.Where(x => x.OrderDetailStatus <= OrderDetailStatusEnum.Inbounding.ObjToInt() && x.MaterielCode == model.MaterielCode && x.SupplierBatch == model.LotNo && x.OrderQuantity > x.ReceiptQuantity).FirstOrDefault();
+                    }
+                    else
+                    {
+                        notGroupDetail = inboundOrderDetails.Where(x => x.OrderDetailStatus <= OrderDetailStatusEnum.Inbounding.ObjToInt() && x.MaterielCode == model.MaterielCode && x.BatchNo == model.LotNo && x.OrderQuantity > x.ReceiptQuantity).FirstOrDefault();
+                    }
+
+
+                    if (notGroupDetail == null)
+                    {
+                        return WebResponseContent.Instance.Error($"璇ョ墿鏂欏湪璇ュ叆搴撳崟涓凡鍏ㄩ儴缁勭洏瀹屾垚");
+                    }
+                    Dt_StockInfoDetail stockInfoDetail = new Dt_StockInfoDetail()
+                    {
+                        MaterielCode = inboundOrderDet.MaterielCode,
+                        MaterielName = inboundOrderDet.MaterielName,
+                        OrderNo = inboundOrder.OrderNo,
+                        BatchNo = inboundOrderDet.BatchNo,
+                        LinId = inboundOrderDet.LinId,
+                        StockQuantity = (quantitys.FirstOrDefault()),
+                        Status = (int)StockStatusEmun.缁勭洏鏆傚瓨,
+                        Creater = "WMS",
+                        CreateDate = DateTime.Now,
+                        Id = inboundOrderDet.LinId.ObjToInt(),
+                        DeliveryNote = model.DeliveryNote,
+                        SupplierBatch = inboundOrderDet.SupplierBatch,
+                        MaterieSpec = inboundOrderDet.MaterieSpec,
+                        OrinalLocation = inboundOrderDet.OrinalLocation
+                    };
+
+                    if (stockInfo.Id > 0)
+                    {
+                        stockInfoDetail.StockId = stockInfo.Id;
+                    }
+                    stockInfo.Details.Add(stockInfoDetail);
+
+                    stockInfoDetails.Add(stockInfoDetail);
+
+                    decimal decimalReceiptQuantity = Convert.ToDecimal(notGroupDetail.ReceiptQuantity);
+                    decimal decimalModelQuantity = Convert.ToDecimal((quantitys.FirstOrDefault()));
+                    decimal decimalOrderQuantity = Convert.ToDecimal(notGroupDetail.OrderQuantity);
+                    decimalReceiptQuantity += decimalModelQuantity;
+                    // 妫�鏌ユ槸鍚﹁秴鍑鸿鍗曟暟閲�
+                    if (decimalReceiptQuantity > decimalOrderQuantity)
+                    {
+                        return WebResponseContent.Instance.Error($"缁勭洏鏁伴噺婧㈠嚭{decimalReceiptQuantity - decimalOrderQuantity}");
+                    }
+                    // 杞洖float绫诲瀷瀛樺偍锛屼絾姣旇緝鍜岃绠楅兘浣跨敤decimal瀹屾垚
+                    notGroupDetail.ReceiptQuantity = Convert.ToDecimal(decimalReceiptQuantity);
+                    if (notGroupDetail.OrderDetailStatus == OrderDetailStatusEnum.New.ObjToInt())
+                    {
+                        notGroupDetail.OrderDetailStatus = OrderDetailStatusEnum.GroupAndInbound.ObjToInt();
+                    }
+                }
+
+                decimal totalQuantity = stockInfo.Details.Sum(x => x.StockQuantity);
+
+                inboundOrder.OrderStatus = InOrderStatusEnum.鍏ュ簱涓�.ObjToInt();
+
+                _unitOfWorkManage.BeginTran();
+                if (stockInfo.Id == 0)
+                {
+                    _stockRepository.StockInfoRepository.Db.InsertNav(stockInfo).Include(x => x.Details).ExecuteCommand();
+                }
+                else
+                {
+                    _stockRepository.StockInfoRepository.Db.UpdateNav(stockInfo).Include(x => x.Details, new UpdateNavOptions() { OneToManyInsertOrUpdate = true }).ExecuteCommand();
+                }
+                _inboundRepository.InboundOrderDetailRepository.UpdateData(inboundOrderDetails);
+                _inboundRepository.InboundOrderRepository.UpdateData(inboundOrder);
+                _unitOfWorkManage.CommitTran();
+                content.OK();
             }
             catch (Exception ex)
             {
@@ -95,39 +347,1039 @@
             }
             return content;
         }
+
+        //鑽按锛屼綆娓╀粨缁勭洏
+        public WebResponseContent NewMaterielGroup(SaveModel saveModel)
+        {
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+
+                var orderNo = saveModel.MainData["orderNo"].ToString();
+                var palletCode = saveModel.MainData["palletCode"].ToString();
+                var warehouseId = saveModel.MainData["warehouseId"].ObjToInt();
+                var Initiallife = saveModel.MainData["initiallife"].ObjToInt();
+                List<string> serialNumbers = new List<string>();
+                List<decimal> quantitys = new List<decimal>();
+                foreach (var item in saveModel.DelKeys)
+                {
+                    string json = JsonConvert.SerializeObject(item);
+                    Dictionary<string, object> delKeyDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
+
+
+                    if (delKeyDict.TryGetValue("serialNumber", out object serialNumberObj))
+                    {
+                        string serialNumber = serialNumberObj?.ToString();
+                        if (!string.IsNullOrEmpty(serialNumber))
+                        {
+                            serialNumbers.Add(serialNumber);
+                        }
+                        else
+                        {
+                            return WebResponseContent.Instance.Error("serialNumber鐨勫�间负绌�");
+                        }
+                    }
+                    if (delKeyDict.TryGetValue("quantity", out object quantityObj))
+                    {
+                        if (quantityObj == null)
+                        {
+                            return WebResponseContent.Instance.Error("鐗╂枡鏁伴噺鐨勫�间负绌�");
+                        }
+                        decimal quantity;
+                        try
+                        {
+                            quantity = Convert.ToDecimal(quantityObj);
+                        }
+                        catch
+                        {
+                            return WebResponseContent.Instance.Error($"鐗╂枡鏁伴噺{quantityObj}鏃犳硶杞崲涓烘暟瀛�");
+                        }
+                        if (quantity <= 0)
+                        {
+                            return WebResponseContent.Instance.Error("鐗╂枡鏁伴噺蹇呴』澶т簬0");
+                        }
+
+                        quantitys.Add(quantity);
+                    }
+                    else
+                    {
+                        return WebResponseContent.Instance.Error("缂哄皯鐗╂枡鏁伴噺瀛楁");
+                    }
+                }
+                Dt_Warehouse warehouse = _warehouseService.Repository.QueryFirst(x => x.WarehouseId == warehouseId);
+                if (warehouse == null)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒拌浠撳簱淇℃伅");
+                }
+
+                Dt_InboundOrder inboundOrder = BaseDal.Db.Queryable<Dt_InboundOrder>().Where(x => x.OrderNo == orderNo && x.WarehouseId == warehouse.WarehouseId).Includes(x => x.Details).First();
+                if (inboundOrder == null)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒板叆搴撳崟淇℃伅");
+                }
+                if (inboundOrder.Details == null || inboundOrder.Details.Count <= 0)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒板叆搴撳崟鏄庣粏淇℃伅");
+                }
+                List<MatSerNumAnalysisModel> models = CodeAnalysisHelper.CodeAnalysis<MatSerNumAnalysisModel>(AnalysisCodeEnum.MatSerNumAnalysis, serialNumbers);
+                //楠岃瘉鍒ゆ柇鏃堕棿鏍煎紡
+                WebResponseContent IsValidContent = IsValidMCDates(models);
+                if (!IsValidContent.Status)
+                {
+                    return content.Error(IsValidContent.Message);
+                }
+
+                string materielCode = models.FirstOrDefault()?.MaterielCode ?? "";
+                Dt_MaterielInfo materielInfo = _basicRepository.MaterielInfoRepository.QueryFirst(x => x.MaterielCode == materielCode);
+                if (materielInfo == null)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒拌鐗╂枡鐨勪俊鎭�");
+                }
+
+                decimal beforeQuantity = 0;
+
+                Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletCode == palletCode).Includes(x => x.Details).First();
+                if (stockInfo == null)
+                {
+                    stockInfo = new Dt_StockInfo()
+                    {
+                        BatchNo ="",
+                        PalletCode = palletCode,
+                        PalletType = GetPalletType(warehouse, palletCode),//GetPalletType(warehouse, palletCode)
+                        IsFull = true,
+                        StockStatus = (int)StockStatusEmun.缁勭洏鏆傚瓨,
+                        Creater = "WMS",
+                        CreateDate = DateTime.Now,
+                        MaterialType = (int)InventoryMaterialType.鍘熸潗鏂�,
+                        Materialweight = 0,
+                        Wlstatus = (int)InventoryMaterialStatus.鍚堟牸,
+                        Mgeneratetime = DateTime.Now,
+                        WarehouseId = warehouse.WarehouseId,
+                        System = inboundOrder.System,
+                        Details = new List<Dt_StockInfoDetail>()
+                    };
+                }
+                else
+                {
+                    return WebResponseContent.Instance.Error($"鎵樼洏鍙烽噸澶�,璇ユ墭鐩樺凡缁勮繃鐗╂枡");
+                }
+                List<Dt_StockInfoDetail> stockInfoDetails = new List<Dt_StockInfoDetail>();
+                foreach (var model in models)
+                {
+
+                    Dt_InboundOrderDetail notGroupDetail = new Dt_InboundOrderDetail();
+
+                    notGroupDetail = inboundOrder.Details.Where(x => x.OrderDetailStatus <= OrderDetailStatusEnum.Inbounding.ObjToInt() && x.MaterielCode == model.MaterielCode && x.BatchNo == model.LotNo).FirstOrDefault();
+
+                    if (notGroupDetail == null)
+                    {
+                        return WebResponseContent.Instance.Error($"璇ョ墿鏂欏湪璇ュ叆搴撳崟涓凡鍏ㄩ儴缁勭洏瀹屾垚");
+                    }
+                    Dt_StockInfoDetail stockInfoDetail = new Dt_StockInfoDetail()
+                    {
+                        MaterielCode = notGroupDetail.MaterielCode,
+                        MaterielName = notGroupDetail.MaterielName,
+                        OrderNo = inboundOrder.OrderNo,
+                        BatchNo = notGroupDetail.BatchNo,
+                        LinId = notGroupDetail.LinId,
+                        StockQuantity = model.Quantity,
+                        Status = (int)StockStatusEmun.缁勭洏鏆傚瓨,
+                        Creater = "WMS",
+                        CreateDate = DateTime.Now,
+                        Id = notGroupDetail.LinId.ObjToInt(),
+                        DeliveryNote = model.DeliveryNote,
+                        SupplierBatch = notGroupDetail.SupplierBatch,
+                        MaterieSpec = notGroupDetail.MaterieSpec,
+                        OrinalLocation = notGroupDetail.OrinalLocation
+                    };
+
+                    if (stockInfo.Id > 0)
+                    {
+                        stockInfoDetail.StockId = stockInfo.Id;
+                    }
+                    stockInfo.Details.Add(stockInfoDetail);
+
+                    stockInfoDetails.Add(stockInfoDetail);
+
+                    decimal decimalReceiptQuantity = Convert.ToDecimal(notGroupDetail.ReceiptQuantity);
+                    decimal decimalModelQuantity = Convert.ToDecimal(notGroupDetail.OrderQuantity);
+                    decimal decimalOrderQuantity = Convert.ToDecimal(notGroupDetail.OrderQuantity);
+                    decimalReceiptQuantity += model.Quantity;
+                    // 妫�鏌ユ槸鍚﹁秴鍑鸿鍗曟暟閲�
+                    if (decimalReceiptQuantity > decimalOrderQuantity)
+                    {
+                        return WebResponseContent.Instance.Error($"缁勭洏鏁伴噺婧㈠嚭{decimalReceiptQuantity - decimalOrderQuantity}");
+                    }
+                    // 杞洖float绫诲瀷瀛樺偍锛屼絾姣旇緝鍜岃绠楅兘浣跨敤decimal瀹屾垚
+                    notGroupDetail.ReceiptQuantity = Convert.ToDecimal(decimalReceiptQuantity);
+                    if (notGroupDetail.OrderDetailStatus == OrderDetailStatusEnum.New.ObjToInt())
+                    {
+                        notGroupDetail.OrderDetailStatus = OrderDetailStatusEnum.GroupAndInbound.ObjToInt();
+                    }
+                }
+
+                decimal totalQuantity = stockInfo.Details.Sum(x => x.StockQuantity);
+
+                inboundOrder.OrderStatus = InOrderStatusEnum.鍏ュ簱涓�.ObjToInt();
+
+                _unitOfWorkManage.BeginTran();
+                if (stockInfo.Id == 0)
+                {
+                    _stockRepository.StockInfoRepository.Db.InsertNav(stockInfo).Include(x => x.Details).ExecuteCommand();
+                }
+                else
+                {
+                    _stockRepository.StockInfoRepository.Db.UpdateNav(stockInfo).Include(x => x.Details, new UpdateNavOptions() { OneToManyInsertOrUpdate = true }).ExecuteCommand();
+                }
+                _inboundRepository.InboundOrderDetailRepository.UpdateData(inboundOrder.Details);
+                _inboundRepository.InboundOrderRepository.UpdateData(inboundOrder);
+                _unitOfWorkManage.CommitTran();
+                content.OK();
+            }
+            catch (Exception ex)
+            {
+                content = WebResponseContent.Instance.Error(ex.Message);
+            }
+            finally
+            {
+
+            }
+            return content;
+        }
+
+        /// <summary>
+        /// 鎴愬搧缁勭洏
+        /// </summary>
+        /// <param name="materielGroupDTO"></param>
+        /// <returns></returns>
+        public WebResponseContent CPMaterielGroup(SaveModel saveModel)
+        {
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                var orderNo = saveModel.MainData["orderNo"].ToString();
+                var palletCode = saveModel.MainData["palletCode"].ToString();
+                var warehouseId = saveModel.MainData["warehouseId"].ObjToInt();
+                var serialNumbers = new List<string>();
+                var quantities = new List<decimal>();
+                var lotNos = new List<string>();
+                var materielCodes = new List<string>();
+
+                foreach (var item in saveModel.DelKeys)
+                {
+                    var delKeyDict = item as IDictionary<string, object>;
+                    if (delKeyDict == null)
+                    {
+                        string json = JsonConvert.SerializeObject(item);
+                        delKeyDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
+                    }
+
+                    // 澶勭悊搴忓垪鍙�
+                    if (!delKeyDict.TryGetValue("serialNumber", out object serialNumberObj) || serialNumberObj == null)
+                    {
+                        return WebResponseContent.Instance.Error("缂哄皯serialNumber瀛楁鎴栧�间负绌�");
+                    }
+
+                    string serialNumber = serialNumberObj.ToString();
+                    if (string.IsNullOrWhiteSpace(serialNumber))
+                    {
+                        return WebResponseContent.Instance.Error("serialNumber鐨勫�间负绌�");
+                    }
+                    serialNumbers.Add(serialNumber);
+                }
+                // 鑾峰彇浠撳簱淇℃伅
+                Dt_Warehouse warehouse = _warehouseService.Repository.QueryFirst(x => x.WarehouseId == warehouseId);
+                if (warehouse == null)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒拌浠撳簱淇℃伅");
+                }
+
+                // 鑾峰彇鍏ュ簱鍗曚俊鎭�
+                Dt_InboundOrder inboundOrder = BaseDal.Db.Queryable<Dt_InboundOrder>()
+                    .Where(x => x.OrderNo == orderNo && x.WarehouseId == warehouse.WarehouseId)
+                    .Includes(x => x.Details)
+                    .First();
+
+                if (inboundOrder == null || inboundOrder.Details == null || inboundOrder.Details.Count <= 0)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒板叆搴撳崟淇℃伅");
+                }
+
+                // 鎵归噺鏌ヨ鎵�鏈夌浉鍏崇鍙风殑CP鍏ュ簱鍗曟槑缁�
+                List<Dt_CPInboundOrderDetail> CPinboundOrderDetails = BaseDal.Db.Queryable<Dt_CPInboundOrderDetail>()
+                    .LeftJoin<Dt_InboundOrderDetail>((cp, d) => cp.OrderDetailId == d.Id)
+                    .LeftJoin<Dt_InboundOrder>((cp, d, o) => d.OrderId == o.Id)
+                    .Where((cp, d, o) =>
+                        o.OrderNo == orderNo &&
+                        o.WarehouseId == warehouse.WarehouseId &&
+                        serialNumbers.Contains(cp.BoxCode)
+                    )
+                    .Select((cp, d, o) => cp)
+                    .ToList();
+
+                //float totalQty = CPinboundOrderDetails.Sum(x => x.QtyOfpcs);
+
+
+                // 楠岃瘉鏌ヨ鍒扮殑鏁版嵁鏁伴噺鏄惁鍖归厤
+                if (CPinboundOrderDetails.Count < serialNumbers.Count)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒版墍鏈夊搴旂殑绠卞彿淇℃伅锛屾壘鍒皗CPinboundOrderDetails.Count}鏉★紝鏈熸湜{serialNumbers.Count}鏉�");
+                }
+
+                // 鎸夌収绠卞彿鍒嗙粍锛岀敤浜庡悗缁鐞�
+                var cpDetailsByBoxCode = CPinboundOrderDetails
+                    .GroupBy(x => x.BoxCode)
+                    .ToDictionary(g => g.Key, g => g.ToList());
+
+
+                var existingStockBoxCodes = _stockRepository.StockInfoRepository.Db
+                .Queryable<Dt_StockInfo>()
+                .LeftJoin<Dt_StockInfoDetail>((s, d) => s.Id == d.StockId)
+                .LeftJoin<Dt_StockInfoDetailCP>((s, d, cp) => d.Id == cp.StockDetailId)
+                .Where((s, d, cp) =>
+                    serialNumbers.Contains(cp.BoxCode))
+                .Select((s, d, cp) => cp.BoxCode)
+                .Distinct()
+                .ToList();
+
+                if (existingStockBoxCodes.Any())
+                {
+                    return WebResponseContent.Instance.Error($"浠ヤ笅绠卞彿宸插湪搴撳瓨涓細{string.Join(",", existingStockBoxCodes)}");
+                }
+
+                // 鑾峰彇鎵�鏈夌浉鍏崇殑鍏ュ簱鍗曟槑缁咺D
+                var orderDetailIds = CPinboundOrderDetails.Select(x => x.OrderDetailId).Distinct().ToList();
+
+                // 鏌ヨ瀵瑰簲鐨勫叆搴撳崟鏄庣粏
+                List<Dt_InboundOrderDetail> inboundOrderDetails = BaseDal.Db.Queryable<Dt_InboundOrderDetail>()
+                    .Where(x => orderDetailIds.Contains(x.Id))
+                    .ToList();
+
+                if (inboundOrderDetails.Sum(x => x.OrderQuantity) <= inboundOrderDetails.Sum(x => x.ReceiptQuantity))
+                {
+                    return WebResponseContent.Instance.Error($"姝ゅ崟鎹凡鍏ㄩ儴缁勭洏瀹屾垚");
+                }
+
+                // 鎸夎鍗曟槑缁咺D鍒嗙粍锛屾鏌ユ瘡涓槑缁嗙殑鎵�鏈夌鍙锋槸鍚﹂兘鎵弿浜�
+                var detailsByOrderDetailId = CPinboundOrderDetails
+                    .GroupBy(x => x.OrderDetailId)
+                    .ToDictionary(g => g.Key, g => g.ToList());
+
+                // 鑾峰彇鐩稿叧鐨勮鍗曟槑缁�
+                List<Dt_InboundOrderDetail> orderDetails = new List<Dt_InboundOrderDetail>();
+                List<Dt_InboundOrderDetail> detailsToUpdate = new List<Dt_InboundOrderDetail>();
+
+                // 妫�鏌ユ瘡涓鍗曟槑缁嗘槸鍚﹀畬鎴愪簡鎵�鏈夌鍙风殑鎵弿
+                foreach (var kvp in detailsByOrderDetailId)
+                {
+                    int orderDetailId = kvp.Key;
+                    var cpDetails = kvp.Value;
+
+                    // 鑾峰彇璁㈠崟鏄庣粏
+                    var orderDetail = inboundOrder.Details.FirstOrDefault(x => x.Id == orderDetailId);
+                    if (orderDetail == null)
+                    {
+                        orderDetail = BaseDal.Db.Queryable<Dt_InboundOrderDetail>()
+                            .First(x => x.Id == orderDetailId);
+                    }
+
+                    if (orderDetail == null)
+                    {
+                        return WebResponseContent.Instance.Error($"鏈壘鍒拌鍗曟槑缁咺D锛歿orderDetailId}");
+                    }
+
+                    orderDetails.Add(orderDetail);
+
+                    // 鏍囪璇ユ槑缁嗕负宸插畬鎴愮粍鐩�
+                    orderDetail.OrderDetailStatus = OrderDetailStatusEnum.GroupAndInbound.ObjToInt();
+                    var recqty = orderDetail.ReceiptQuantity;
+                    float totalQty = cpDetails.Sum(item => item.QtyOfpcs);
+                    orderDetail.ReceiptQuantity = (decimal)totalQty + recqty; // 鏀惰揣鏁伴噺绛変簬璁㈠崟鏁伴噺
+
+                    detailsToUpdate.Add(orderDetail);
+                }
+
+
+
+                // 妫�鏌ユ墭鐩樻槸鍚﹀凡瀛樺湪
+                Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db
+                    .Queryable<Dt_StockInfo>()
+                    .Where(x => x.PalletCode == palletCode)
+                    .First();
+
+                if (stockInfo == null)
+                {
+                    // 鍒涘缓鏂版墭鐩�
+                    stockInfo = new Dt_StockInfo()
+                    {
+                        BatchNo = "", // 浣跨敤鍏ュ簱鍗曟壒娆″彿
+                        PalletCode = palletCode,
+                        PalletType = GetPalletType(warehouse, palletCode),
+                        IsFull = true,
+                        StockStatus = (int)StockStatusEmun.缁勭洏鏆傚瓨,
+                        Creater = "WMS",
+                        CreateDate = DateTime.Now,
+                        MaterialType = (int)InventoryMaterialType.鍘熸潗鏂�,
+                        Materialweight = 0,
+                        Wlstatus = (int)InventoryMaterialStatus.鍚堟牸,
+                        Mgeneratetime = DateTime.Now,
+                        WarehouseId = warehouse.WarehouseId,
+                        System = inboundOrder.System,
+                        Details = new List<Dt_StockInfoDetail>()
+                    };
+                }
+                else
+                {
+                    // 濡傛灉鎵樼洏宸插瓨鍦紝妫�鏌ユ槸鍚﹀凡缁忔槸缁勭洏鏆傚瓨鐘舵��
+                    if (stockInfo.StockStatus != (int)StockStatusEmun.缁勭洏鏆傚瓨)
+                    {
+                        return WebResponseContent.Instance.Error($"鎵樼洏鍙烽噸澶�,璇ユ墭鐩樺凡缁勮繃鐗╂枡");
+                    }
+                }
+
+                List<Dt_CPInboundOrderDetail> cPInboundOrderDetail = new List<Dt_CPInboundOrderDetail>();
+                // 鍒涘缓搴撳瓨鏄庣粏 - 鎸夎鍗曟槑缁嗗垱寤�
+                foreach (var orderDetail in orderDetails)
+                {
+                    // 鑾峰彇璇ユ槑缁嗗搴旂殑鎵�鏈夌鍙�
+                    var detailBoxCodes = detailsByOrderDetailId[orderDetail.Id]
+                        .Select(x => x.BoxCode)
+                        .ToList();
+
+                    cPInboundOrderDetail = BaseDal.Db.Queryable<Dt_CPInboundOrderDetail>().Where(x => detailBoxCodes.Contains(x.BoxCode)).ToList();
+
+                    List<Dt_StockInfoDetailCP> stockInfoDetailCP = new List<Dt_StockInfoDetailCP>();
+                    foreach (var item in cPInboundOrderDetail)
+                    {
+                        Dt_StockInfoDetailCP stockInfoDetailCP1 = new Dt_StockInfoDetailCP()
+                        {
+                            BoxId = item.BoxId,
+                            BoxCode = item.BoxCode,
+                            DateCode = item.DateCode,
+                            JobId = item.JobId,
+                            PartNum = item.PartNum,
+                            QtyOfpcs = item.QtyOfpcs,
+                            QtyOfxout = item.QtyOfxout,
+                            CPStockDetailStatus = (int)StockStatusEmun.缁勭洏鏆傚瓨,
+                            Creater = "涓婃父WMS",
+                        };
+                        stockInfoDetailCP.Add(stockInfoDetailCP1);
+
+                        item.CPOrderDetailStatus = InOrderStatusEnum.鍏ュ簱涓�.ObjToInt();
+                    }
+
+                    // 鍒涘缓搴撳瓨鏄庣粏
+                    Dt_StockInfoDetail stockInfoDetail = new Dt_StockInfoDetail()
+                    {
+                        MaterielCode = orderDetail.MaterielCode,
+                        MaterielName = orderDetail.MaterielName,
+                        OrderNo = inboundOrder.OrderNo,
+                        BatchNo = orderDetail.BatchNo,
+                        SupplierBatch = orderDetail.SupplierBatch,
+                        LinId = orderDetail.LinId,
+                        StockQuantity = (decimal)cPInboundOrderDetail.Sum(item => item.QtyOfpcs),
+                        Status = (int)StockStatusEmun.缁勭洏鏆傚瓨,
+                        Creater = "WMS",
+                        CreateDate = DateTime.Now,
+                        Id = orderDetail.LinId.ObjToInt(),
+                        //DeliveryNote = orderDetail.DeliveryNote,
+                        MaterieSpec = orderDetail.MaterieSpec,
+                        StockDetails = stockInfoDetailCP,
+                        OrinalLocation = orderDetail.OrinalLocation
+                    };
+
+                    if (stockInfo.Id > 0)
+                    {
+                        stockInfoDetail.StockId = stockInfo.Id;
+                    }
+                    stockInfo.Details.Add(stockInfoDetail);
+                }
+
+                // 妫�鏌ュ叆搴撳崟鏄惁鎵�鏈夋槑缁嗛兘宸插畬鎴愮粍鐩�
+                bool allDetailsCompleted = inboundOrder.Details.All(x =>
+                    detailsToUpdate.Any(d => d.Id == x.Id) ||
+                    x.OrderDetailStatus == OrderDetailStatusEnum.GroupAndInbound.ObjToInt());
+
+
+
+                // 浜嬪姟澶勭悊
+                _unitOfWorkManage.BeginTran();
+                try
+                {
+                    if (stockInfo.Id == 0)
+                    {
+                        _stockRepository.StockInfoRepository.Db.InsertNav(stockInfo)
+                            .Include(x => x.Details).ThenInclude(x => x.StockDetails)
+                            .ExecuteCommand();
+                    }
+                    else
+                    {
+                        _stockRepository.StockInfoRepository.Db.UpdateNav(stockInfo)
+                            .Include(x => x.Details, new UpdateNavOptions()
+                            {
+                                OneToManyInsertOrUpdate = true
+                            }).ThenInclude(x => x.StockDetails)
+                            .ExecuteCommand();
+                    }
+
+                    // 鏇存柊璁㈠崟鏄庣粏
+                    if (detailsToUpdate.Count > 0)
+                    {
+                        _inboundRepository.InboundOrderDetailRepository.UpdateData(detailsToUpdate);
+                    }
+
+                    // 鏇存柊璁㈠崟
+                    _inboundRepository.InboundOrderRepository.UpdateData(inboundOrder);
+
+                    _cPInboundOrderDetailRepository.UpdateData(cPInboundOrderDetail);
+
+                    _unitOfWorkManage.CommitTran();
+
+                    content = WebResponseContent.Instance.OK("缁勭洏鎴愬姛");
+                }
+                catch (Exception ex)
+                {
+                    _unitOfWorkManage.RollbackTran();
+                    throw new Exception($"缁勭洏浜嬪姟澶勭悊澶辫触锛歿ex.Message}", ex);
+                }
+            }
+            catch (Exception ex)
+            {
+                content = WebResponseContent.Instance.Error($"缁勭洏澶辫触锛歿ex.Message}");
+            }
+
+            return content;
+        }
+        public string ReceiveWMSTaskin = WIDESEA_Core.Helper.AppSettings.Configuration["ReceiveWMSTaskin"];
+        /// <summary>
+        /// 缁勭洏鍚堟墭
+        /// </summary>
+        /// <param name="saveModel"></param>
+        /// <returns></returns>
+        public WebResponseContent SYMaterielGroup(SaveModel saveModel)
+        {
+
+            WebResponseContent webResponseContent = new WebResponseContent();
+            try
+            {
+                var soussAddress = saveModel.MainData["soussAddress"];
+                var targetAddress = saveModel.MainData["targetAddress"];
+
+                Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Includes(x => x.Details).Where(x => x.PalletCode == soussAddress).First();
+                Dt_StockInfo targetstockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Includes(x => x.Details).Where(x => x.PalletCode == targetAddress).First();
+                Dt_Warehouse warehouse = _warehouseService.Repository.QueryFirst(x => x.WarehouseId == targetstockInfo.WarehouseId);
+                if (stockInfo == null || targetstockInfo == null)
+                {
+                    throw new Exception("搴撳瓨鏈壘鍒版墭鐩樺彿");
+                }
+
+                var sameItems = from sourceItem in stockInfo.Details
+                                join targetItem in targetstockInfo.Details
+                                on new
+                                {
+                                    sourceItem.BatchNo,
+                                    sourceItem.MaterielName,
+                                    sourceItem.MaterielCode
+                                }
+                                equals new
+                                {
+                                    targetItem.BatchNo,
+                                    targetItem.MaterielName,
+                                    targetItem.MaterielCode
+                                }
+                                select new
+                                {
+                                    SourceItem = sourceItem,
+                                    TargetItem = targetItem,
+                                    BatchNo = sourceItem.BatchNo,
+                                    MaterialCode = sourceItem.MaterielCode,
+                                    MaterialType = sourceItem.MaterielName
+                                };
+
+                var matchedSourceItemIds = sameItems.Select(x => x.SourceItem.Id).ToList();
+
+                foreach (var item in stockInfo.Details)
+                {
+                    if (!matchedSourceItemIds.Contains(item.Id))
+                    {
+                        item.StockId = targetstockInfo.Id;
+                    }
+                }
+                var differentItems = stockInfo.Details
+      .Where(x => !matchedSourceItemIds.Contains(x.Id))
+      .ToList();
+                targetstockInfo.Details = targetstockInfo.Details
+      .Where(x => !matchedSourceItemIds.Contains(x.Id))
+      .Concat(differentItems)
+      .ToList();
+                if (warehouse.WarehouseCode == "SC02_CP")
+                {
+                    warehouse.WarehouseCode = "SC01_CP";
+                }
+                if (warehouse.WarehouseCode == "SC02_BC")
+                {
+                    warehouse.WarehouseCode = "SC01_BC";
+                }
+                var houseSyncretism = new HouseSyncretism
+                {
+                    ApiType = "InventoryMoveController",
+                    Method = "AsrsSubmitMoveDatas",
+
+                    Parameters = new List<HouseSyncretism.Parame>
+                    {
+                        new HouseSyncretism.Parame {
+                            Value =  stockInfo.Details.Select(g => new Parame.Syncretism
+                        {
+                            Lpn = stockInfo.PalletCode,
+                            MoveType = 0,
+                            WareHouseCode = warehouse.WarehouseCode,
+                            ItemCode = g.MaterielCode,
+                            MoveNumber = g.StockQuantity,
+                            LotNo = g.BatchNo,
+                            WipBatch = g.BatchNo,
+                            LocationName = stockInfo.LocationCode,
+                            TargetLocName = targetstockInfo.LocationCode,
+                            TargetLpn = targetstockInfo.PalletCode,
+
+                        }).ToList()
+                            }
+                    }
+                };
+                var authResult = AuthenticateWithWMS();
+                if (authResult.IsSuccess)
+                {
+                    houseSyncretism.Context = new Dictionary<string, string>
+                                            {
+                                                { "Ticket", authResult.Ticket },
+                                                { "InvOrgId", authResult.InvOrgId }
+
+                                            };
+
+                    var response = HttpHelper.Post<MomRequestContent>(ReceiveWMSTaskin, houseSyncretism, "绔嬪簱鍏ュ簱鏁伴噺鍥炰紶WMS");
+                    if (!response.Success)
+                    {
+                        throw new Exception($"鎿嶄綔澶辫触: {response.Message ?? "鏈彁渚涢敊璇俊鎭�"}");
+                    }
+
+                }
+                _unitOfWorkManage.BeginTran();
+                foreach (var sameItem in sameItems)
+                {
+                    sameItem.TargetItem.StockQuantity += sameItem.SourceItem.StockQuantity;
+                    _stockRepository.StockInfoDetailRepository.UpdateData(sameItem.TargetItem);
+                    _stockRepository.StockInfoDetailRepository.DeleteData(sameItem.SourceItem);
+                }
+                _stockRepository.StockInfoRepository.UpdateData(targetstockInfo);
+                _stockRepository.StockInfoDetailRepository.UpdateData(targetstockInfo.Details);
+                _stockRepository.StockInfoRepository.DeleteData(stockInfo);
+
+                _unitOfWorkManage.CommitTran();
+                webResponseContent = WebResponseContent.Instance.OK("鍚堟墭鎴愬姛");
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                webResponseContent = WebResponseContent.Instance.Error($"缁勭洏澶辫触锛歿ex.Message}");
+            }
+            return webResponseContent;
+        }
+
+        private (bool IsSuccess, string Ticket, string InvOrgId) AuthenticateWithWMS()
+        {
+            var authentication = new Authentication
+            {
+                ApiType = "AuthenticationController",
+                Parameters = new List<Parameter>
+        {
+            new Parameter { Value = "LK-Admin" },
+            new Parameter { Value = "LK-Admin" }
+        },
+                Method = "Login",
+            };
+
+            var response = HttpHelper.Post<WebResponseContent>(ReceiveWMSTaskin, authentication, "鐧诲綍WMS璐﹀彿");
+
+            if (response.Context != null)
+            {
+                return (true, response.Context["Ticket"].ToString(), response.Context["InvOrgId"].ToString());
+            }
+
+            return (false, null, null);
+        }
+
+
+        public int GetPalletType(Dt_Warehouse warehouse, string palletCode)
+        {
+
+            if (warehouse.WarehouseCode == WarehouseEnum.SC01_BC.ObjToString())
+            {
+                Dt_PalletTypeInfo palletTypeInfo = _palletTypeInfoRepository.QueryFirst(x => x.CodeStartStr == palletCode.Substring(0, 3));
+                if (palletTypeInfo == null)
+                {
+                    throw new Exception($"鎵樼洏鍙烽敊璇�");
+                }
+                return palletTypeInfo.PalletType;
+            }
+            //else if (warehouse.WarehouseCode == WarehouseEnum.HA152.ObjToString())
+            //{
+            //    Dt_PalletTypeInfo palletTypeInfo = _palletTypeInfoRepository.QueryFirst(x => x.CodeStartStr == palletCode.Substring(0, 2));
+            //    if (palletTypeInfo == null)
+            //    {
+            //        throw new Exception($"鎵樼洏鍙烽敊璇�");
+            //    }
+            //    return palletTypeInfo.PalletType;
+            //}
+            //else if (warehouse.WarehouseCode == WarehouseEnum.HA57.ObjToString())
+            //{
+            //    Dt_PalletTypeInfo palletTypeInfo = _palletTypeInfoRepository.QueryFirst(x => x.CodeStartStr == palletCode.Substring(0, 3));
+            //    if (palletTypeInfo == null)
+            //    {
+            //        throw new Exception($"鎵樼洏鍙烽敊璇�");
+            //    }
+            //    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>
+        /// 鍒ゆ柇姝g‘鏃堕棿鏍煎紡
+        /// </summary>
+        public WebResponseContent IsValidMCDates(List<MatSerNumAnalysisModel> analysisModels)
+        {
+            string[] effDates = analysisModels.Select(x => x.EffectiveDate).Distinct().ToArray();
+            string[] ProDates = analysisModels.Select(x => x.ProductionDate).Distinct().ToArray();
+            foreach (string effDate in effDates)
+            {
+                string format = "yyyy-MM-dd"; // 鐩爣鏍煎紡
+                DateTime parsedDate;
+                // 瑙f瀽骞堕獙璇佹牸寮�
+                bool isValid = DateTime.TryParseExact(
+                    effDate,
+                    format,
+                    CultureInfo.InvariantCulture,
+                    DateTimeStyles.None,
+                    out parsedDate
+                );
+
+                if (!isValid)
+                {
+                    return WebResponseContent.Instance.Error("鏍煎紡鏃犳晥鎴栨棩鏈熶笉鍚堟硶");
+                }
+            }
+            foreach (string ProDate in ProDates)
+            {
+                string format = "yyyy-MM-dd"; // 鐩爣鏍煎紡
+                DateTime parsedDate;
+                // 瑙f瀽骞堕獙璇佹牸寮�
+                bool isValid = DateTime.TryParseExact(
+                    ProDate,
+                    format,
+                    CultureInfo.InvariantCulture,
+                    DateTimeStyles.None,
+                    out parsedDate
+                );
+
+                if (!isValid)
+                {
+                    return WebResponseContent.Instance.Error("鏍煎紡鏃犳晥鎴栨棩鏈熶笉鍚堟硶");
+                }
+            }
+            return WebResponseContent.Instance.OK();
+        }
+
         /// <summary>
         /// 鍏ュ簱鍗曟嵁涓嬪彂
         /// </summary>
         /// <param name="orderAddDTO"></param>
         /// <returns></returns>
-        public WebResponseContent AddInboundOrders(HouseInbound orderAddDTO)
+        public WebResponseContent AddInboundOrders(HouseInbound model)
         {
-            WebResponseContent content = new();
+            WebResponseContent content = new WebResponseContent();
             try
             {
-                InboundOrderAddDTO orderAddDTO1 = new InboundOrderAddDTO();
-                orderAddDTO1.OrderNo = orderAddDTO.AsnNo;
-                orderAddDTO1.UpperOrderNo = orderAddDTO.AsnNo;
-                orderAddDTO1.OutWareHouse = orderAddDTO.InWarehouse;
-                orderAddDTO1.TransactionCode = orderAddDTO.TransactionCode;
-                orderAddDTO1.InoutType = orderAddDTO.OrderType;
-                orderAddDTO1.OrderType = orderAddDTO.InoutType.ObjToInt();
-                orderAddDTO1.Details = orderAddDTO.DetailList.DicToIEnumerable<InboundOrderDetailAddDTO>();
-                #region 楠岃瘉鏁版嵁
-                (bool, string, object?) result = CheckInboundOrderAddData(orderAddDTO1);
-                if (!result.Item1) return content = WebResponseContent.Instance.Error(result.Item2);
-                #endregion
+                _unitOfWorkManage.BeginTran();
+                foreach (var item in model.DetailList)
+                {
+                    //鑾峰彇鐗╂枡淇℃伅
+                    Dt_MaterielInfo materielInfo = _basicRepository.MaterielInfoRepository.QueryFirst(x => x.MaterielCode == item.MaterielCode);
+                    if (materielInfo == null)
+                    {
+                        return content.Error($"鐗╂枡{item.MaterielCode}涓嶅瓨鍦�!");
+                    }
+                    Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == model.InWarehouse);
+                    if (warehouse == null)
+                    {
+                        return content.Error($"鏈壘鍒颁粨搴撲俊鎭�");
+                    }
+                    if (warehouse.WarehouseCode.Contains("CP"))
+                    {
+                        if (item.SupplierBatch == null)
+                        {
+                            return content.Error("渚涘簲鍟嗘壒娆′笉鍙负绌�");
+                        }
+                        Dt_InboundOrder inboundOrderOld = BaseDal.Db.Queryable<Dt_InboundOrder>().Where(x => x.UpperOrderNo == model.AsnNo).Includes(x => x.Details).First();
 
-                Dt_InboundOrder inboundOrder = _mapper.Map<Dt_InboundOrder>(orderAddDTO1);
-                inboundOrder.OrderStatus = InboundStatusEnum.鏈紑濮�.ObjToInt();
-                inboundOrder.Creater = "WMS";
-                inboundOrder.CreateDate = DateTime.Now;
-                bool a = BaseDal.Db.InsertNav(inboundOrder).Include(x => x.Details).ExecuteCommand();
+                        if (inboundOrderOld != null)
+                        {
+                            if (inboundOrderOld.OrderStatus == InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt())
+                            {
+                                inboundOrderOld.OrderStatus = InOrderStatusEnum.鍏ュ簱涓�.ObjToInt();
+                                _inboundRepository.InboundOrderRepository.UpdateData(inboundOrderOld);
+                            }
+                            Dt_InboundOrderDetail orderDetail1 = BaseDal.Db.Queryable<Dt_InboundOrderDetail>().Where(x => x.OrderId == inboundOrderOld.Id).First();
+                            Dt_InboundOrderDetail? inboundOrderDetailOld = inboundOrderOld.Details?.FirstOrDefault(x => x.LinId == item.LinId && x.MaterielCode == item.MaterielCode);
+                            if (inboundOrderDetailOld != null)
+                            {
+                                inboundOrderDetailOld.OrderQuantity += item.OrderQuantity;
+                                _inboundRepository.InboundOrderDetailRepository.UpdateData(inboundOrderDetailOld);
+                            }
+                            else
+                            {
+                                List<Dt_CPInboundOrderDetail> cPInboundOrderDetail = new List<Dt_CPInboundOrderDetail>();
+                                foreach (var list in item.BoxList)
+                                {
+                                    Dt_CPInboundOrderDetail cPInboundOrderDetail1 = new Dt_CPInboundOrderDetail()
+                                    {
+                                        BoxId = (float)list.BoxId,
+                                        BoxCode = list.BoxCode,
+                                        DateCode = list.DateCode,
+                                        JobId = (float)list.JobId,
+                                        PartNum = list.PartNum,
+                                        QtyOfpcs = (float)list.QtyOfpcs,
+                                        QtyOfxout = (float)list.QtyOfxout,
+                                        CPOrderDetailStatus = OrderDetailStatusEnum.New.ObjToInt(),
+                                        Creater = "涓婃父WMS",
+                                    };
+                                    cPInboundOrderDetail.Add(cPInboundOrderDetail1);
+                                }
+
+                                Dt_InboundOrderDetail orderDetail = new Dt_InboundOrderDetail()
+                                {
+                                    OrderId = orderDetail1.OrderId,
+                                    MaterielCode = item.MaterielCode,
+                                    BatchNo = item.BatchNo,
+                                    OrderQuantity = item.OrderQuantity,
+                                    ReceiptQuantity = 0,
+                                    OverInQuantity = 0,
+                                    OrderDetailStatus = OrderDetailStatusEnum.New.ObjToInt(),
+                                    LinId = item.LinId,
+                                    LPNNo = item.LPNNo,
+                                    MaterielName = item.MaterielName,
+                                    MaterieSpec = item.MaterieSpec,
+                                    Creater = "涓婃父WMS",
+                                    SupplierBatch = item.SupplierBatch,
+                                    OrinalLocation = item.OrinalLocation,
+                                    CPDetails = cPInboundOrderDetail
+                                };
+                                //_inboundRepository.InboundOrderDetailRepository.AddData(orderDetail);
+                                Db.InsertNav(orderDetail).Include(x => x.CPDetails).ExecuteCommand();
+                            }
+                        }
+                        else
+                        {
+                            List<Dt_CPInboundOrderDetail> cPInboundOrderDetail = new List<Dt_CPInboundOrderDetail>();
+                            foreach (var list in item.BoxList)
+                            {
+                                Dt_CPInboundOrderDetail cPInboundOrderDetail1 = new Dt_CPInboundOrderDetail()
+                                {
+                                    BoxId = (float)list.BoxId,
+                                    BoxCode = list.BoxCode,
+                                    DateCode = list.DateCode,
+                                    JobId = (float)list.JobId,
+                                    PartNum = list.PartNum,
+                                    QtyOfpcs = (float)list.QtyOfpcs,
+                                    QtyOfxout = (float)list.QtyOfxout,
+                                    CPOrderDetailStatus = OrderDetailStatusEnum.New.ObjToInt(),
+                                    Creater = "涓婃父WMS",
+                                };
+                                cPInboundOrderDetail.Add(cPInboundOrderDetail1);
+                            }
+
+                            Dt_InboundOrderDetail orderDetail = new Dt_InboundOrderDetail()
+                            {
+                                MaterielCode = item.MaterielCode,
+                                BatchNo = item.BatchNo,
+                                OrderQuantity = item.OrderQuantity,
+                                ReceiptQuantity = 0,
+                                OverInQuantity = 0,
+                                OrderDetailStatus = OrderDetailStatusEnum.New.ObjToInt(),
+                                LinId = item.LinId,
+                                LPNNo = item.LPNNo,
+                                MaterielName = item.MaterielName,
+                                MaterieSpec = item.MaterieSpec,
+                                Creater = "涓婃父WMS",
+                                SupplierBatch = item.SupplierBatch,
+                                OrinalLocation = item.OrinalLocation,
+                                CPDetails = cPInboundOrderDetail
+                            };
+
+                            Dt_InboundOrder inboundOrder = new Dt_InboundOrder()
+                            {
+                                OrderNo = model.AsnNo,
+                                UpperOrderNo = model.AsnNo,
+                                WarehouseId = warehouse.WarehouseId,
+                                //SupplierId = "",
+                                OrderStatus = InboundStatusEnum.鏈紑濮�.ObjToInt(),
+                                CreateType = CreateType.UpperSystemPush.ObjToInt(),
+                                Remark = "",
+                                TransactionCode = model.TransactionCode,
+                                InoutType = model.OrderType,
+                                OrderType = model.InoutType.ObjToInt(),
+                                Creater = "涓婃父WMS",
+                                System = model.System,
+                                Details = new List<Dt_InboundOrderDetail> { orderDetail }
+                            };
+                            //switch (model.OrderType)//鍗曟嵁绫诲瀷
+                            //{
+                            //    case 1:
+                            //        inboundOrder.OrderType = InOrderTypeEnum.Allocat.ObjToInt();
+                            //        break;
+                            //    case 3:
+                            //        inboundOrder.OrderType = InOrderTypeEnum.CustomerRecovery.ObjToInt();
+                            //        break;
+                            //    case 6:
+                            //        inboundOrder.OrderType = InOrderTypeEnum.SaleReturn.ObjToInt();
+                            //        break;
+                            //    default:
+                            //        break;
+                            //};
+
+
+                            Db.InsertNav(inboundOrder).Include(x => x.Details).ThenInclude(x => x.CPDetails).ExecuteCommand();
+                        }
+                    }
+                    else
+                    {
+                        if (item.SupplierBatch == null)
+                        {
+                            return content.Error("渚涘簲鍟嗘壒娆′笉鍙负绌�");
+                        }
+                        Dt_InboundOrder inboundOrderOld = BaseDal.Db.Queryable<Dt_InboundOrder>().Where(x => x.UpperOrderNo == model.AsnNo).Includes(x => x.Details).First();
+
+                        if (inboundOrderOld != null)
+                        {
+                            if (inboundOrderOld.OrderStatus == InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt())
+                            {
+                                inboundOrderOld.OrderStatus = InOrderStatusEnum.鍏ュ簱涓�.ObjToInt();
+                                _inboundRepository.InboundOrderRepository.UpdateData(inboundOrderOld);
+                            }
+                            Dt_InboundOrderDetail orderDetail1 = BaseDal.Db.Queryable<Dt_InboundOrderDetail>().Where(x => x.OrderId == inboundOrderOld.Id).First();
+                            Dt_InboundOrderDetail? inboundOrderDetailOld = inboundOrderOld.Details?.FirstOrDefault(x => x.LinId == item.LinId && x.MaterielCode == item.MaterielCode);
+                            if (inboundOrderDetailOld != null)
+                            {
+                                inboundOrderDetailOld.OrderQuantity += item.OrderQuantity;
+                                inboundOrderDetailOld.OrderDetailStatus = OrderDetailStatusEnum.Inbounding.ObjToInt();
+                                _inboundRepository.InboundOrderDetailRepository.UpdateData(inboundOrderDetailOld);
+                            }
+                            else
+                            {
+                                Dt_InboundOrderDetail orderDetail = new Dt_InboundOrderDetail()
+                                {
+                                    OrderId = orderDetail1.OrderId,
+                                    MaterielCode = item.MaterielCode,
+                                    BatchNo = item.BatchNo,
+                                    OrderQuantity = item.OrderQuantity,
+                                    ReceiptQuantity = 0,
+                                    OverInQuantity = 0,
+                                    OrderDetailStatus = OrderDetailStatusEnum.New.ObjToInt(),
+                                    LinId = item.LinId,
+                                    LPNNo = item.LPNNo,
+                                    MaterielName = item.MaterielName,
+                                    MaterieSpec = item.MaterieSpec,
+                                    Creater = "涓婃父WMS",
+                                    SupplierBatch = item.SupplierBatch
+                                };
+                                _inboundRepository.InboundOrderDetailRepository.AddData(orderDetail);
+                            }
+                        }
+                        else
+                        {
+                            Dt_InboundOrderDetail orderDetail = new Dt_InboundOrderDetail()
+                            {
+                                MaterielCode = item.MaterielCode,
+                                BatchNo = item.BatchNo,
+                                OrderQuantity = item.OrderQuantity,
+                                ReceiptQuantity = 0,
+                                OverInQuantity = 0,
+                                OrderDetailStatus = OrderDetailStatusEnum.New.ObjToInt(),
+                                LinId = item.LinId,
+                                LPNNo = item.LPNNo,
+                                MaterielName = item.MaterielName,
+                                MaterieSpec = item.MaterieSpec,
+                                Creater = "涓婃父WMS",
+                                SupplierBatch = item.SupplierBatch
+                            };
+
+                            Dt_InboundOrder inboundOrder = new Dt_InboundOrder()
+                            {
+                                OrderNo = model.AsnNo,
+                                UpperOrderNo = model.AsnNo,
+                                WarehouseId = warehouse.WarehouseId,
+                                //SupplierId = "",
+                                OrderStatus = InboundStatusEnum.鏈紑濮�.ObjToInt(),
+                                CreateType = CreateType.UpperSystemPush.ObjToInt(),
+                                Remark = "",
+                                TransactionCode = model.TransactionCode,
+                                InoutType = model.OrderType,
+                                OrderType = model.InoutType.ObjToInt(),
+                                Creater = "涓婃父WMS",
+                                System = model.System,
+                                Details = new List<Dt_InboundOrderDetail> { orderDetail }
+                            };
+                            //switch (model.OrderType)//鍗曟嵁绫诲瀷
+                            //{
+                            //    case 1:
+                            //        inboundOrder.OrderType = InOrderTypeEnum.Allocat.ObjToInt();
+                            //        break;
+                            //    case 3:
+                            //        inboundOrder.OrderType = InOrderTypeEnum.CustomerRecovery.ObjToInt();
+                            //        break;
+                            //    case 6:
+                            //        inboundOrder.OrderType = InOrderTypeEnum.SaleReturn.ObjToInt();
+                            //        break;
+                            //    default:
+                            //        break;
+                            //};
+                            Db.InsertNav(inboundOrder).Include(x => x.Details).ExecuteCommand();
+
+                        }
+                    }
+                }
+                _unitOfWorkManage.CommitTran();
                 content = WebResponseContent.Instance.OK();
+                //InboundOrderAddDTO orderAddDTO1 = new InboundOrderAddDTO();
+                //orderAddDTO1.OrderNo = orderAddDTO.AsnNo;
+                //orderAddDTO1.UpperOrderNo = orderAddDTO.AsnNo;
+                //orderAddDTO1.OutWareHouse = orderAddDTO.InWarehouse;
+                //orderAddDTO1.TransactionCode = orderAddDTO.TransactionCode;
+                //orderAddDTO1.InoutType = orderAddDTO.OrderType;
+                //orderAddDTO1.OrderType = orderAddDTO.InoutType.ObjToInt();
+                //orderAddDTO1.Details = orderAddDTO.DetailList.DicToIEnumerable<InboundOrderDetailAddDTO>();
+                //#region 楠岃瘉鏁版嵁
+                //(bool, string, object?) result = CheckInboundOrderAddData(orderAddDTO1);
+                //if (!result.Item1) return content = WebResponseContent.Instance.Error(result.Item2);
+                //#endregion
+
+                //Dt_InboundOrder inboundOrder = _mapper.Map<Dt_InboundOrder>(orderAddDTO1);
+                //inboundOrder.OrderStatus = InboundStatusEnum.鏈紑濮�.ObjToInt();
+                //inboundOrder.Creater = "WMS";
+                //inboundOrder.CreateDate = DateTime.Now;
+                //bool a = BaseDal.Db.InsertNav(inboundOrder).Include(x => x.Details).ExecuteCommand();
+
             }
             catch (Exception ex)
             {
+                _unitOfWorkManage.RollbackTran();
                 content = WebResponseContent.Instance.Error(ex.Message);
+
             }
             finally
             {
@@ -182,7 +1434,7 @@
             return content;
         }
         /// <summary>
-        /// 鍏ュ簱鍙栨秷
+        /// 鍏ュ簱鍗曟嵁鍙栨秷
         /// </summary>
         /// <param name="houseInventoryIn"></param>
         /// <returns></returns>
@@ -194,7 +1446,7 @@
                 InboundOrderAddDTO orderAddDTO1 = new InboundOrderAddDTO();
                 orderAddDTO1.OrderNo = houseCancelIn.AsnNo;
                 orderAddDTO1.Details = houseCancelIn.DetailList.DicToIEnumerable<InboundOrderDetailAddDTO>();
-                Dt_InboundOrder oldOutboundOrder = BaseDal.Db.Queryable<Dt_InboundOrder>().Where(x => x.OrderNo == orderAddDTO1.OrderNo).Includes(x => x.Details).First();
+                Dt_InboundOrder oldOutboundOrder = BaseDal.Db.Queryable<Dt_InboundOrder>().Where(x => x.UpperOrderNo == orderAddDTO1.OrderNo).Includes(x => x.Details).First();
                 Dt_InboundOrderDetail dt_InboundOrderDetail = BaseDal.Db.Queryable<Dt_InboundOrderDetail>().Where(x => x.OrderId == oldOutboundOrder.Id).First();
                 if (oldOutboundOrder.OrderStatus != InboundStatusEnum.鏈紑濮�.ObjToInt())
                 {
@@ -209,8 +1461,8 @@
                     CreateType = oldOutboundOrder.CreateType,
                     //SourceId = oldOutboundOrder.SourceId,
                     UpperOrderNo = oldOutboundOrder.UpperOrderNo,
-                    OrderNo = oldOutboundOrder.OrderNo,
-                    OutWareHouse = oldOutboundOrder.OutWareHouse,
+                    //OrderNo = oldOutboundOrder.OrderNo,
+                    //OutWareHouse = oldOutboundOrder.OutWareHouse,
                     TransactionCode = oldOutboundOrder.TransactionCode,
                     InoutType = oldOutboundOrder.InoutType,
                     OrderType = oldOutboundOrder.OrderType,
@@ -237,19 +1489,6 @@
                     _inboundOrderDetailService.DeleteData(item);
                 }
                 BaseDal.DeleteData(oldOutboundOrder);
-
-                //inboundOrder_Hty.Details = oldOutboundOrder.Details;
-
-                //#region 楠岃瘉鏁版嵁
-                //(bool, string, object?) result = CheckInboundOrderAddData(orderAddDTO1);
-                //#endregion
-
-                //Dt_InboundOrder inboundOrder = _mapper.Map<Dt_InboundOrder>(orderAddDTO1);
-                //inboundOrder.OrderStatus = InboundStatusEnum.鏈紑濮�.ObjToInt();
-                //inboundOrder.OrderType = OutOrderTypeEnum.OutInventory.ObjToInt();
-                //inboundOrder.Creater = "WMS";
-                //inboundOrder.CreateDate = DateTime.Now;
-                //bool a = BaseDal.Db.InsertNav(inboundOrder).Include(x => x.Details).ExecuteCommand();
                 content = WebResponseContent.Instance.OK();
             }
             catch (Exception ex)
@@ -263,37 +1502,378 @@
             return content;
         }
 
+        public WebResponseContent GetInboundOrders(SaveModel saveModel)
+        {
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                int pageNo = saveModel.MainData["pageNo"].ObjToInt();
+                string? orderNo = saveModel.MainData["orderNo"].ToString();
+                int warehouseId = saveModel.MainData["warehouseId"].ObjToInt();
+                List<Dt_InboundOrder> dt_ReceiveOrders = new List<Dt_InboundOrder>();
+                if (string.IsNullOrEmpty(orderNo))
+                {
+                    dt_ReceiveOrders = Db.Queryable<Dt_InboundOrder>().Where(x => x.OrderStatus < InboundStatusEnum.鍏ュ簱瀹屾垚.ObjToInt() && x.WarehouseId == warehouseId).Includes(x => x.Details).OrderByDescending(x => x.CreateDate).ToPageList(pageNo, 10);
+                }
+                else
+                {
+                    dt_ReceiveOrders = Db.Queryable<Dt_InboundOrder>().Where(x => (x.OrderNo.Contains(orderNo)) && x.OrderStatus < InboundStatusEnum.鍏ュ簱瀹屾垚.ObjToInt() && x.WarehouseId == warehouseId).Includes(x => x.Details).OrderByDescending(x => x.CreateDate).ToPageList(pageNo, 10);
+                }
+
+                content.OK(data: dt_ReceiveOrders);
+            }
+            catch (Exception ex)
+            {
+                content.Error(ex.Message);
+            }
+            return content;
+        }
+        /// <summary>
+        /// erp鍗曟嵁涓嬪彂
+        /// </summary>
+        /// <param name="addInboundOrder"></param>
+        /// <returns></returns>
+        public WebResponseContent Save(AddInboundOrderModel addInboundOrder)
+        {
+            try
+            {
+                List<Dt_InboundOrderDetail> inboundOrderDetails = new List<Dt_InboundOrderDetail>();
+                Random random = new Random();
+                if (addInboundOrder.Details != null)
+                {
+                    foreach (var model in addInboundOrder.Details)
+                    {
+                        // 鐢熸垚3浣嶉殢鏈烘暟锛�1-999涔嬮棿锛�
+                        int randomNum = random.Next(1, 1000);
+
+                        // 鏍煎紡鍖栧綋鍓嶆棩鏈熶负骞存湀鏃ワ紙渚嬪锛�20230820锛�
+                        string datePart = DateTime.Now.ToString("yyyyMMdd");
+                        Dt_InboundOrderDetail inboundOrderDetail = new Dt_InboundOrderDetail()
+                        {
+                            MaterielCode = model.MaterielCode,
+                            MaterielName = model.MaterielName,
+                            SupplierBatch = model.SupplierBatch,
+                            OrderQuantity = model.OrderQuantity,
+                            BatchNo = "PC" + $"{datePart}{randomNum}",
+                            OrderDetailStatus = InOrderStatusEnum.鏈紑濮�.ObjToInt(),
+                            Creater = "WMS",
+                            CreateDate = DateTime.Now,
+
+                        };
+                        inboundOrderDetails.Add(inboundOrderDetail);
+                    }
+                }
+                int randomNum2 = random.Next(1, 1000);
+                string datePart2 = DateTime.Now.ToString("yyyyMMdd");
+                Dt_InboundOrder erpProScrapSheet = new Dt_InboundOrder()
+                {
+                    OrderNo = "WMSIN" + $"{datePart2}{randomNum2}",
+                    UpperOrderNo = "WMSIN" + $"{datePart2}{randomNum2}",
+                    WarehouseId = addInboundOrder.WarehouseId,
+                    OrderType = OrderTypeEnum.鐢熶骇鍏ュ簱鍗�.ObjToInt(),
+                    InoutType = InoutTypeEnum.OtherIn.ToString(),
+                    OrderStatus = InOrderStatusEnum.鏈紑濮�.ObjToInt(),
+                    CreateType = OrderCreateTypeEnum.CreateInSystem.ObjToInt(),
+                    System = "WMS",
+                    Details = inboundOrderDetails,
+                    Creater = "WMS",
+                    CreateDate = DateTime.Now,
+                };
+                _unitOfWorkManage.BeginTran();
+                Db.InsertNav(erpProScrapSheet).Include(x => x.Details).ExecuteCommand();
+                _unitOfWorkManage.CommitTran();
+                return WebResponseContent.Instance.OK();
+
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                return WebResponseContent.Instance.Error(ex.Message);
+            }
+
+        }
+
+        public string CancelInMaterialWarehousing = WIDESEA_Core.Helper.AppSettings.Configuration["CancelInMaterialWarehousing"];
+        /// <summary>
+        /// 鍏ュ簱鍗曟嵁鍙栨秷鎺ㄩ�丒RP
+        /// </summary>
+        /// <param name="orderNo"></param>
+        /// <returns></returns>
+        public WebResponseContent FeedbackInboundCanceERP(int[] keys)
+        {
+            try
+            {
+                List<Dt_InboundOrderDetail> inboundOrderDetails = _inboundRepository.InboundOrderDetailRepository.QueryData(x => keys.Contains(x.Id));
+
+                if (inboundOrderDetails == null || inboundOrderDetails.Count == 0)
+                {
+                    return WebResponseContent.Instance.Error("鏈壘鍒板叆搴撳崟鏄庣粏淇℃伅");
+                }
+                if (inboundOrderDetails.FirstOrDefault(x => x.OrderDetailStatus > OrderDetailStatusEnum.New.ObjToInt() && x.OrderDetailStatus != OrderDetailStatusEnum.AssignOverPartial.ObjToInt()) != null)
+                {
+                    return WebResponseContent.Instance.Error("鎵�閫夊叆搴撳崟鏄庣粏瀛樺湪鍏ュ簱涓垨宸插畬鎴�");
+                }
+                Dt_InboundOrder inboundOrder = _inboundRepository.InboundOrderRepository.QueryFirst(x => x.Id == inboundOrderDetails[0].OrderId);
+                if (inboundOrder == null)
+                {
+                    return WebResponseContent.Instance.Error("鏈�氳繃璇ユ槑缁嗘壘鍒板叆搴撳崟淇℃伅");
+                }
+                if (!inboundOrder.System.Equals("ERP"))
+                {
+                    return WebResponseContent.Instance.Error("璇ュ叆搴撳崟鎹潪ERP鎺ㄩ�侊紝鏃犳硶鍙栨秷");
+                }
+                List<FeedbackInboundOrderERP> feedbackInboundOrders = new List<FeedbackInboundOrderERP>();
+                foreach (var item in inboundOrderDetails)
+                {
+                    FeedbackInboundOrderERP feedbackInbound = new FeedbackInboundOrderERP()
+                    {
+                        code = inboundOrder.UpperOrderNo,
+                        itemId = item.LinId,
+                    };
+                    feedbackInboundOrders.Add(feedbackInbound);
+                }
+
+                var response = HttpHelper.Post<WebResponseContent>(CancelInMaterialWarehousing, feedbackInboundOrders, "鍏ュ簱鏄庣粏鍙栨秷鍥炰紶ERP");
+                _unitOfWorkManage.BeginTran();
+                if (response.Code == 0)
+                {
+                    _inboundRepository.InboundOrderDetailRepository.DeleteAndMoveIntoHty(inboundOrderDetails, OperateType.浜哄伐鍙栨秷);
+
+                    //妫�鏌ヨ涓昏鍗曟槸鍚﹁繕鏈夊墿浣欐槑缁�
+                    int remainingDetailsCount = _inboundRepository.InboundOrderDetailRepository
+                        .Db.Queryable<Dt_InboundOrderDetail>()
+                        .Where(d => d.OrderId == inboundOrder.Id)
+                        .Count();
+                    //妫�鏌ユ槑缁嗗畬鎴愮殑涓暟
+                    int overCount = _inboundRepository.InboundOrderDetailRepository
+                        .Db.Queryable<Dt_InboundOrderDetail>()
+                        .Where(d => d.OrderId == inboundOrder.Id && d.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt())
+                        .Count();
+                    // 濡傛灉娌℃湁鍓╀綑鏄庣粏锛屽啀鍒犻櫎涓昏鍗�
+                    if (remainingDetailsCount == 0)
+                    {
+                        _inboundRepository.InboundOrderRepository.DeleteAndMoveIntoHty(inboundOrder, OperateType.浜哄伐鍙栨秷);
+                    }
+                    //濡傛灉鍙栨秷浠ュ悗鏄庣粏宸茬粡鍏ㄩ儴瀹屾垚
+                    if (remainingDetailsCount == overCount)
+                    {
+                        inboundOrder.OrderStatus = InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt();
+                        _inboundRepository.InboundOrderRepository.UpdateData(inboundOrder);
+                    }
+
+
+                    _unitOfWorkManage.CommitTran();
+                    return WebResponseContent.Instance.OK();
+                }
+                else
+                {
+                    throw new Exception($"鎿嶄綔澶辫触: {response.Message ?? "鏈彁渚涢敊璇俊鎭�"}");
+
+                }
+
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                return WebResponseContent.Instance.Error(ex.Message);
+            }
+        }
+        //鍙嶆嫞鍥炲簱鍗�
+        public WebResponseContent ReceiveReturnOrder(List<HouseReturnOrder> houseReturnOrder)
+        {
+            try
+            {
+                Random random = new Random();
+                List<Dt_ReturnOrder> returnOrders = new List<Dt_ReturnOrder>();
+                _unitOfWorkManage.BeginTran();
+                foreach (var item in houseReturnOrder)
+                {
+                    int randomNum = random.Next(1, 1000);
+                    string datePart = DateTime.Now.ToString("yyyyMMdd");
+                    Dt_ReturnOrder returnOrder = _returnOrderRepository.QueryFirst(x => x.LPNNo == item.LPNNo && x.OrderStatus == InOrderStatusEnum.鏈紑濮�.ObjToInt());
+                    if (returnOrder == null)
+                    {
+                        Dt_ReturnOrder newReturnOrder = new Dt_ReturnOrder
+                        {
+                            OrderType = OrderTypeEnum.鍙嶆嫞鍥炲簱鍗�.ObjToInt(),
+                            MaterielCode = item.MaterielCode,
+                            MaterielName = item.MaterielName,
+                            MaterieSpec = item.MaterieSpec,
+                            BatchNo = item.BatchNo,
+                            OrderQuantity = item.OrderQuantity,
+                            Remark = item.Remark,
+                            LinId = item.LinId,
+                            LPNNo = item.LPNNo,
+                            LocationCode = item.LocationCode,
+                            WarehouseCode = item.WarehouseCode,
+                            System = item.System,
+                            OrderStatus = InOrderStatusEnum.鏈紑濮�.ObjToInt(),
+                            Creater = "SMOM",
+                            CreateDate = DateTime.Now
+                        };
+                        _returnOrderRepository.AddData(newReturnOrder);
+                        Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo, Dt_StockInfoDetail>((stock, detail) => stock.Id == detail.StockId).Where((stock, detail) => stock.PalletCode == item.LPNNo && stock.LocationCode == item.LocationCode).First();
+                        Dt_OutboundOrderDetail outboundOrderDetail = new Dt_OutboundOrderDetail();
+                        Dt_OutboundOrder outboundOrder = new Dt_OutboundOrder();
+                        if (stockInfo == null)
+                        {
+                            Dt_Warehouse warehouse = _warehouseService.Repository.QueryData(x => x.WarehouseCode == item.WarehouseCode).FirstOrDefault();
+                            if (warehouse == null)
+                            {
+                                return WebResponseContent.Instance.Error($"璇ヤ粨搴撶紪鍙穥item.WarehouseCode}鏈厤缃�");
+                            }
+                            Dt_StockInfoDetail stockInfoDetail = new Dt_StockInfoDetail
+                            {
+                                MaterielCode = item.MaterielCode,
+                                MaterielName = item.MaterielName,
+                                MaterieSpec = item.MaterieSpec,
+                                BatchNo = item.BatchNo,
+                                LinId = item.LinId,
+                                Status = StockStatusEmun.缁勭洏鏆傚瓨.ObjToInt(),
+                                Creater = "SMOM",
+                                CreateDate = DateTime.Now,
+                                OrderNo = newReturnOrder.OrderNo,
+                                StockQuantity = item.OrderQuantity,
+                            };
+                            Dt_StockInfo stockInfo1 = new Dt_StockInfo
+                            {
+                                PalletCode = item.LPNNo,
+                                WarehouseId = warehouse.WarehouseId,
+                                BatchNo = item.BatchNo,
+                                PalletType = GetPalletType(warehouse, item.LPNNo),
+                                IsFull = true,
+                                StockStatus = (int)StockStatusEmun.鍙嶆嫞鍏ュ簱,
+                                Creater = "WMS",
+                                CreateDate = DateTime.Now,
+                                MaterialType = (int)InventoryMaterialType.鍘熸潗鏂�,
+                                Materialweight = 0,
+                                Wlstatus = (int)InventoryMaterialStatus.鍚堟牸,
+                                Mgeneratetime = DateTime.Now,
+                                Details = new List<Dt_StockInfoDetail> { stockInfoDetail }
+                            };
+                            Db.InsertNav(stockInfo1).Include(x => x.Details).ExecuteCommand();
+                        }
+                        else
+                        {
+                            outboundOrderDetail = new Dt_OutboundOrderDetail
+                            {
+                                MaterielCode = item.MaterielCode,
+                                MaterielName = item.MaterielName,
+                                MaterieSpec = item.MaterieSpec,
+                                BatchNo = item.BatchNo,
+                                OrderQuantity = stockInfo.Details.Sum(x => x.StockQuantity),
+                                Remark = item.Remark,
+                                LinId = item.LinId,
+                                LPNNo = item.LPNNo,
+                                Creater = "SMOM",
+                                CreateDate = DateTime.Now,
+                                LocationName = item.LocationCode
+                            };
+                            outboundOrder = new Dt_OutboundOrder
+                            {
+                                OrderNo = "FJCK" + $"{datePart}{randomNum}",
+                                UpperOrderNo = "WMSFJCK" + $"{datePart}{randomNum}",
+                                OrderStatus = OutOrderStatusEnum.鏈紑濮�.ObjToInt(),
+                                OrderType = OrderTypeEnum.鍙嶆嫞鍑哄簱鍗�.ObjToInt(),
+                                InoutType = InoutTypeEnum.OtherOut.ToString(),
+                                System = item.System,
+                                Creater = "SMOM",
+                                CreateDate = DateTime.Now,
+                                CreateType = OrderCreateTypeEnum.UpperSystemPush.ObjToInt(),
+                                Details = new List<Dt_OutboundOrderDetail> { outboundOrderDetail }
+                            };
+                            Db.InsertNav(outboundOrder).Include(x => x.Details).ExecuteCommand();
+                        }
+
+                    }
+                    else
+                    {
+                        Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo, Dt_StockInfoDetail>((stock, detail) => stock.Id == detail.StockId).Where((stock, detail) => stock.PalletCode == item.LPNNo && stock.StockStatus == StockStatusEmun.浣欐枡閫�搴�.ObjToInt()).First();
+                        stockInfo.StockStatus = StockStatusEmun.鍙嶆嫞鍏ュ簱.ObjToInt();
+                        returnOrder.LinId = item.LinId;
+                        returnOrder.System = item.System;
+                        returnOrder.WarehouseCode = item.WarehouseCode;
+                        returnOrder.LocationCode = item.LocationCode;
+                        returnOrder.OrderType = OrderTypeEnum.鍙嶆嫞鍥炲簱鍗�.ObjToInt();
+                        returnOrder.OrderQuantity += item.OrderQuantity;
+                        returnOrder.ReceiptQuantity += item.OrderQuantity;
+                        _returnOrderRepository.UpdateData(returnOrder);
+                        _stockRepository.StockInfoRepository.UpdateData(stockInfo);
+
+                    }
+                }
+                _unitOfWorkManage.CommitTran();
+                return WebResponseContent.Instance.OK();
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                return WebResponseContent.Instance.Error(ex.Message);
+            }
+        }
+
+        public WebResponseContent GetMaterielCode(int warehouseId)
+        {
+            try
+            {
+                List<Dt_MaterielInfo> materielInfos = _basicRepository.MaterielInfoRepository.QueryData(x => x.WarehouseId == warehouseId).ToList();
+                List<string> materielCodes = materielInfos.Select(x => x.MaterielCode).Distinct().ToList();
+                return WebResponseContent.Instance.OK("鎴愬姛", data: materielCodes);
+            }
+            catch (Exception ex)
+            {
+                return WebResponseContent.Instance.Error(ex.Message);
+            }
+        }
+
+        public WebResponseContent GetMaterielName(int warehouseId, string materielCode)
+        {
+            try
+            {
+                List<Dt_MaterielInfo> materielInfos = _basicRepository.MaterielInfoRepository.QueryData(x => x.WarehouseId == warehouseId && x.MaterielCode == materielCode).ToList();
+                List<string> materielNames = materielInfos.Select(x => x.MaterielName).Distinct().ToList();
+                return WebResponseContent.Instance.OK("鎴愬姛", data: materielNames);
+            }
+            catch (Exception ex)
+            {
+                return WebResponseContent.Instance.Error(ex.Message);
+            }
+        }
         /// <summary>
         /// 楠岃瘉鍗曟嵁娣诲姞DTO瀵硅薄
         /// </summary>
         /// <param name="inboundOrderAddDTO">鍗曟嵁娣诲姞DTO</param>
         /// <returns></returns>
-        private (bool, string, object?) CheckInboundOrderAddData(InboundOrderAddDTO inboundOrderAddDTO)
-        {
-            (bool, string, object?) result1 = ModelValidate.ValidateModelData(inboundOrderAddDTO);
-            if (!result1.Item1) return result1;
+        //private (bool, string, object?) CheckInboundOrderAddData(InboundOrderAddDTO inboundOrderAddDTO)
+        //{
+        //    (bool, string, object?) result1 = ModelValidate.ValidateModelData(inboundOrderAddDTO);
+        //    if (!result1.Item1) return result1;
 
-            (bool, string, object?) result2 = ModelValidate.ValidateModelData(inboundOrderAddDTO.Details);
-            if (!result2.Item1) return result2;
+        //    (bool, string, object?) result2 = ModelValidate.ValidateModelData(inboundOrderAddDTO.Details);
+        //    if (!result2.Item1) return result2;
 
-            //IEnumerable<int> inOrderTypes = Enum.GetValues<OrderTypeEmun>().Cast<int>();
-            //if (!inOrderTypes.Contains(inboundOrderAddDTO.OrderType))
-            //{
-            //    return (false, "鏈壘鍒拌鍗曟嵁绫诲瀷", inboundOrderAddDTO);
-            //}
+        //    IEnumerable<int> inOrderTypes = Enum.GetValues<OrderTypeEmun>().Cast<int>();
+        //    if (!inOrderTypes.Contains(inboundOrderAddDTO.OrderType))
+        //    {
+        //        return (false, "鏈壘鍒拌鍗曟嵁绫诲瀷", inboundOrderAddDTO);
+        //    }
 
-            //List<string> materielCodes = inboundOrderAddDTO.Details.Select(x => x.MaterielCode).ToList();
-            //if (!_basicService.MaterielInfoService.ExsitMateriels(materielCodes))
-            //{
-            //    return (false, "鏈夌墿鏂欎俊鎭湭褰曞叆锛岃褰曞叆鐗╂枡淇℃伅", inboundOrderAddDTO);
-            //}
-
-            if (BaseDal.QueryFirst(x => x.OrderName == inboundOrderAddDTO.orderName && !string.IsNullOrEmpty(x.OrderName)) != null)
-            {
-                return (false, "鍗曟嵁宸插瓨鍦�", inboundOrderAddDTO);
-            }
-            return (true, "鎴愬姛", inboundOrderAddDTO);
-        }
+        //    List<string> materielCodes = inboundOrderAddDTO.Details.Select(x => x.MaterielCode).ToList();
+        //    if (!_basicService.MaterielInfoService.ExsitMateriels(materielCodes))
+        //    {
+        //        return (false, "鏈夌墿鏂欎俊鎭湭褰曞叆锛岃褰曞叆鐗╂枡淇℃伅", inboundOrderAddDTO);
+        //    }
+        //    Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == inboundOrderAddDTO.OutWareHouse);
+        //    if (warehouse == null)
+        //    {
+        //        return (false, "鏈壘鍒颁粨搴撲俊鎭�", inboundOrderAddDTO);
+        //    }
+        //    if (BaseDal.QueryFirst(x => x.OrderName == inboundOrderAddDTO.orderName && !string.IsNullOrEmpty(x.OrderName)) != null)
+        //    {
+        //        return (false, "鍗曟嵁宸插瓨鍦�", inboundOrderAddDTO);
+        //    }
+        //    return (true, "鎴愬姛", inboundOrderAddDTO);
+        //}
 
 
     }

--
Gitblit v1.9.3