wangxinhui
2025-01-10 4bc0e18b94a2bf17c1b7277910d63ef82fbe616a
´úÂë¹ÜÀí/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundOrderService.cs
@@ -43,9 +43,11 @@
        public IOutboundOrderRepository Repository => BaseDal;
        private readonly IInvokeERPService _invokeERPService;
        private readonly IOutStockLockInfoService _outStockLockInfoService;
        private readonly IOutboundOrderRepository _outboundOrderRepository;
        public OutboundOrderService(IOutboundOrderRepository BaseDal, IMapper mapper,IUnitOfWorkManage unitOfWorkManage, IBasicService basicService, IOutboundOrderDetailRepository outboundOrderDetailRepository, IStockInfoService stockInfoService,
          IStockInfoRepository stockInfoRepository, IInvokeERPService invokeERPService, IOutStockLockInfoService outStockLockInfoService) : base(BaseDal)
          IStockInfoRepository stockInfoRepository, IInvokeERPService invokeERPService, IOutStockLockInfoService outStockLockInfoService,
          IOutboundOrderRepository outboundOrderRepository) : base(BaseDal)
        {
            _mapper = mapper;
            _unitOfWorkManage = unitOfWorkManage;
@@ -55,8 +57,21 @@
            _stockInfoRepository = stockInfoRepository;
            _invokeERPService = invokeERPService;
            _outStockLockInfoService = outStockLockInfoService;
            _outboundOrderRepository = outboundOrderRepository;
        }
        public override WebResponseContent AddData(SaveModel saveModel)
        {
            if (saveModel.MainData.TryGetValue(nameof(Dt_OutboundOrder.UpperOrderNo).FirstLetterToLower(), out object? upperOrderNo) && upperOrderNo != null && !string.IsNullOrEmpty(upperOrderNo.ToString()))
            {
                Dt_OutboundOrder outboundOrder = BaseDal.QueryFirst(x => x.UpperOrderNo == upperOrderNo.ToString() && x.WarehouseId == Convert.ToInt32(saveModel.MainData[nameof(Dt_OutboundOrder.WarehouseId).FirstLetterToLower()]));
                if (outboundOrder != null)
                {
                    return WebResponseContent.Instance.Error($"{upperOrderNo}领料单号已存在");
                }
            }
            saveModel.DetailData[0].Add("orderDetailStatus", OrderDetailStatusEnum.New.ObjToInt());
            return base.AddData(saveModel);
        }
        public WebResponseContent ReceiveOutOrder(ErpOutOrderDTO model)
        {
            try
@@ -112,6 +127,7 @@
                            MaterielName = materielInfo.MaterielName,
                            OrderDetailStatus = OrderDetailStatusEnum.New.ObjToInt(),
                            OrderQuantity = model.Qty,
                            Unit=materielInfo.MaterielUnit
                        };
                        Dt_OutboundOrder outboundOrder = new Dt_OutboundOrder()
                        {
@@ -172,7 +188,7 @@
            }
        }
        //上报出库完成
        public WebResponseContent TestOutUpload(int id,Dt_StockInfo stockInfo)
        public WebResponseContent TestOutUpload(int id,List<Dt_OutStockLockInfo>? outStockLockInfos)
        {
            try
            {
@@ -180,8 +196,23 @@
                Dt_Warehouse warehouse = _basicService.WarehouseService.Repository.QueryFirst(x => x.WarehouseId == outboundOrder.WarehouseId);
                ERPIssueModel issueModel = new ERPIssueModel();
                List<Dt_StockInfo> stockInfos = new List<Dt_StockInfo>();
                List<Dt_OutStockLockInfo> _OutStockLockInfos=new List<Dt_OutStockLockInfo>();
                int overCount = outboundOrder.Details.Where(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()).Count();
                if (outboundOrder.Details.Count == overCount)
                {
                    outboundOrder.OrderStatus = OutOrderStatusEnum.出库完成.ObjToInt();
                    _outboundOrderRepository.UpdateData(outboundOrder);
                }
                if (outboundOrder==null)
                {
                    return WebResponseContent.Instance.Error("出库单不存在");
                }
                if (outboundOrder.CreateType == OrderCreateTypeEnum.CreateInSystem.ObjToInt())
                {
                    return WebResponseContent.Instance.OK();
                }
                //测试架库给ERP上报出库完成
                if (stockInfo==null)
                if (warehouse.WarehouseCode==WarehouseEnum.HA64.ToString())
                {
                    stockInfos = TestOutStocksUpdate(warehouse).Data as List<Dt_StockInfo> ?? new List<Dt_StockInfo>();
                    List<ERPPickItemModel> eRPOutPick =new List<ERPPickItemModel>();
@@ -224,25 +255,37 @@
                }
                else
                {
                    Dt_OutboundOrderDetail orderDetail = outboundOrder.Details.FirstOrDefault(x => x.MaterielCode == stockInfo.Details[0].MaterielCode);
                    List<ERPPickModel> eRPPickModels= new List<ERPPickModel>();
                    
                    ERPPickItemModel pickItemModel = new ERPPickItemModel()
                    //获取出库详情单
                    foreach (var item in outStockLockInfos)
                    {
                        Lotno = stockInfo.Details[0].BatchNo,
                        Qty = stockInfo.Details[0].StockQuantity.ObjToInt().ToString(),
                        Location = stockInfo.LocationCode
                    };
                    ERPPickModel pickModel = new ERPPickModel()
                    {
                        Rowindex = outboundOrder.Details[0].RowNo,
                        Material = outboundOrder.Details[0].MaterielCode,
                        Qty = (outboundOrder.Details[0].OrderQuantity.ObjToInt()).ToString(),
                        Dataitem = new List<ERPPickItemModel> { pickItemModel }
                    };
                        ERPPickItemModel pickItemModel = new ERPPickItemModel()
                        {
                            Lotno = item.BatchNo,
                            Qty = item.AssignQuantity.ObjToInt().ToString(),
                            Location = item.LocationCode
                        };
                        //获取出库单明细
                        Dt_OutboundOrderDetail outboundOrderDetail = outboundOrder.Details.FirstOrDefault(x => x.Id == item.OrderDetailId);
                        ERPPickModel pickModel = new ERPPickModel()
                        {
                            Rowindex = outboundOrderDetail.RowNo,
                            Material = outboundOrderDetail.MaterielCode,
                            Qty = pickItemModel.Qty,
                            Dataitem = new List<ERPPickItemModel> { pickItemModel }
                        };
                        if (item.OrderQuantity==item.AssignQuantity)
                        {
                            item.Status = OutLockStockStatusEnum.出库完成.ObjToInt();
                        }
                        eRPPickModels.Add(pickModel);
                        _OutStockLockInfos.Add(item);
                    }
                    ERPIssueItemModel issueItemModel = new ERPIssueItemModel()
                    {
                        Pickcode = outboundOrder.UpperOrderNo,
                        PickList = new List<ERPPickModel>() { pickModel }
                        PickList = eRPPickModels
                    };
                    issueModel = new ERPIssueModel()
                    {
@@ -258,20 +301,17 @@
                    };
                }
                
                string response = _invokeERPService.InvokeOutStandardsApi(issueModel);
                ErpRequestContent requestContent = response.DeserializeObject<ErpRequestContent>();
                if (requestContent.res == 1)
                if (stockInfos.Count > 0)
                {
                    if (stockInfos.Count>0)
                    {
                        _stockInfoRepository.UpdateData(stockInfos);
                    }
                    return WebResponseContent.Instance.OK(requestContent.Data);
                    _stockInfoRepository.UpdateData(stockInfos);
                }
                else
                {
                    return WebResponseContent.Instance.Error(requestContent.Data);
                    _outStockLockInfoService.Repository.UpdateData(_OutStockLockInfos);
                }
                //出库完成上报ERP æµ‹è¯•注释
                _invokeERPService.InvokeOutStandardsApi(issueModel);
                return WebResponseContent.Instance.OK();
            }
            catch (Exception ex)
            {