From 225d11e2ddaa55d1d482201cb4d89c9486cdba69 Mon Sep 17 00:00:00 2001 From: wangxinhui <wangxinhui@hnkhzn.com> Date: 星期五, 20 六月 2025 12:27:52 +0800 Subject: [PATCH] 更新代码 --- 代码管理/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/ProOutOrderService.cs | 134 ++++++++++++++++++++++++++++++++------------ 1 files changed, 96 insertions(+), 38 deletions(-) diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/ProOutOrderService.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/ProOutOrderService.cs" index 94e8e3b..d591f56 100644 --- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/ProOutOrderService.cs" +++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_OutboundService/ProOutOrderService.cs" @@ -53,7 +53,7 @@ _invokeERPService = invokeERPService; } /// <summary> - /// 鎺ユ敹ERP鎴愬搧鍑哄簱鍗� + /// 鎺ユ敹ERP鎴愬搧鍑哄簱鍗曚俊鎭�(璁㈠崟鍑哄簱/瀵勫敭鍑哄簱) /// </summary> /// <returns></returns> public async Task<WebResponseContent> ProductDeliveryOrder(ErpProOutOrderDTO outOrderDTO) @@ -131,6 +131,7 @@ keyValuePairs.Add(item.SaleOrder, responseContent.Data[0].Endcustomer); } } + proOutOrderDetail.QtyPcs += proOutOrderDetail.SpareQty; proOutOrderDetails.Add(proOutOrderDetail); } Dt_ProOutOrder proOutOrder= new Dt_ProOutOrder() @@ -199,6 +200,69 @@ content.Error(ex.Message); } return content; + } + /// <summary> + /// 閿�鍞寚娲� + /// </summary> + /// <returns></returns> + public async Task<WebResponseContent> ProductSpecifyVer(ErpProductSpecifyVerDTO erpProductSpecifyVerDTO) + { + WebResponseContent content = new WebResponseContent(); + try + { + Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x=>x.WarehouseCode==erpProductSpecifyVerDTO.WaType); + if (warehouse == null) + return await Task.FromResult(content.Error($"鏈壘鍒皗erpProductSpecifyVerDTO.WaType}浠撳簱淇℃伅")); + //鏌ヨ鍙寚娲惧簱瀛� + List<Dt_ProStockInfo> proStockInfos = Db.Queryable<Dt_ProStockInfo>().Where(x => x.ProStockAttribute == ProStockAttributeEnum.鎴愬搧.ObjToInt()) + .Includes(x => x.proStockInfoDetails) + .Where(x => x.proStockInfoDetails + .Any(v => + v.SaleOrder == erpProductSpecifyVerDTO.OrderNo + && v.ProductCode == erpProductSpecifyVerDTO.PCode + && v.ProductVersion == erpProductSpecifyVerDTO.PVer + && v.LotNumber == erpProductSpecifyVerDTO.PLot + && v.DateCode == erpProductSpecifyVerDTO.DateCode + && (v.SpecifyVer==null||v.SpecifyVer=="") + )) + .ToList(); + List<Dt_ProStockInfoDetail> proStockInfoDetails = new List<Dt_ProStockInfoDetail>(); + List<Dt_ProStockInfoDetail> specifyVerDetails = new List<Dt_ProStockInfoDetail>(); + if (proStockInfos==null) + return await Task.FromResult(content.Error("鍙寚娲惧簱瀛樹笉瀛樺湪")); + proStockInfos = proStockInfos.OrderBy(x => x.proStockInfoDetails.FirstOrDefault()?.DateCode).ThenBy(x => x.CreateDate).ThenBy(x => x.proStockInfoDetails.Sum(x => x.StockPcsQty)).ToList(); + foreach (var item in proStockInfos) + { + proStockInfoDetails.AddRange(item.proStockInfoDetails); + } + if (proStockInfoDetails.Sum(x=>x.StockPcsQty)< erpProductSpecifyVerDTO.QtyPcs) + return await Task.FromResult(content.Error($"鍙寚娲惧簱瀛樻暟閲忎笉瓒�,鍙敤:{proStockInfoDetails.Sum(x => x.StockPcsQty)}")); + float overQty = 0; + foreach (var item in proStockInfoDetails) + { + specifyVerDetails.Add(item); + overQty += item.StockPcsQty; + //宸叉弧瓒宠幏鍙栨暟閲忎笉鍐嶆洿鏀� + if (overQty>= erpProductSpecifyVerDTO.QtyPcs) + { + break; + } + } + specifyVerDetails.ForEach(x => + { + x.SpecifyVer = erpProductSpecifyVerDTO.Ver; + }); + _unitOfWorkManage.BeginTran(); + _stockRepository.ProStockInfoDetailRepository.UpdateData(specifyVerDetails); + _unitOfWorkManage.CommitTran(); + content.OK("鎸囨淳鎴愬姛"); + } + catch (Exception ex) + { + _unitOfWorkManage.RollbackTran(); + content.Error(ex.Message); + } + return await Task.FromResult(content); } /// <summary> /// 鎴愬搧鍑哄緟鍙戣揣鍖�(骞冲簱)+鍚屾ERP鍑哄簱(缁戝畾浜嗗嚭搴撳崟搴撳瓨) @@ -654,7 +718,7 @@ /// <summary> /// 鏌ヨERP璁㈠崟鎵i櫎搴撳瓨鏁伴噺 /// </summary> - public async Task<WebResponseContent> OutProErpSync(string outProOrderNo) + public WebResponseContent OutProErpSync(string outProOrderNo) { WebResponseContent content = new WebResponseContent(); try @@ -663,52 +727,54 @@ Dt_ProOutOrder proOutOrder = BaseDal.Db.Queryable<Dt_ProOutOrder>().Where(x=>x.ProOutOrderNo== outProOrderNo).Includes(x => x.Details).First(); if (proOutOrder==null) { - return await Task.FromResult(content.Error($"鏈壘鍒版垚鍝佸嚭搴撹鍗晎outProOrderNo}")); + return content.Error($"鏈壘鍒版垚鍝佸嚭搴撹鍗晎outProOrderNo}"); } if (proOutOrder.ProOrderStatus>=OutOrderStatusEnum.鍑哄簱瀹屾垚.ObjToInt()) { - return await Task.FromResult(content.Error($"鍑哄簱璁㈠崟宸插畬鎴愭垨鍏抽棴")); + return content.Error($"鍑哄簱璁㈠崟宸插畬鎴愭垨鍏抽棴"); } //璋冪敤erp鍑哄簱璁㈠崟搴撳瓨鏌ヨ鎺ュ彛 string response = _invokeERPService.InvokeOutProErpSync(outProOrderNo); ErpOutProSyncResponseContent erpOutProSyncResponse= response.DeserializeObject<ErpOutProSyncResponseContent>(); if (erpOutProSyncResponse.Code!=200) { - return await Task.FromResult(content.Error($"ERP鍑哄簱璁㈠崟鏌ヨ鎺ュ彛璋冪敤澶辫触,閿欒淇℃伅:{erpOutProSyncResponse.Msg}")); + return content.Error($"ERP鍑哄簱璁㈠崟鏌ヨ鎺ュ彛璋冪敤澶辫触,閿欒淇℃伅:{erpOutProSyncResponse.Msg}"); } List<OutProStock> outProStocks = erpOutProSyncResponse.Data; if (outProStocks.Count<=0 || outProStocks==null) { - return await Task.FromResult(content.Error($"鎴愬搧鍑哄簱璁㈠崟{outProOrderNo}ERP褰撳墠鏈湁鍑哄簱搴撳瓨淇℃伅")); + return content.Error($"鎴愬搧鍑哄簱璁㈠崟{outProOrderNo}ERP褰撳墠鏈湁鍑哄簱搴撳瓨淇℃伅"); + } + // 楠岃瘉鎵�鏈夊嚭搴撳崟鍙锋槸鍚︿竴鑷� + OutProStock? outExist = outProStocks.FirstOrDefault(x => x.ShippingNumber != outProOrderNo); + if (outExist != null) + { + return content.Error($"ERP杩斿洖浜嗗嚭搴撹鍗晎outExist.ShippingNumber}搴撳瓨淇℃伅"); } //鑾峰彇骞冲簱搴撳尯 Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA101.ToString()); if (warehouse==null) { - return await Task.FromResult(content.Error("鏈壘鍒板簱鍖轰俊鎭�")); + return content.Error("鏈壘鍒板簱鍖轰俊鎭�"); } + var productCodes = outProStocks.Select(x => x.Partnum).Distinct().ToList(); //鑾峰彇鎵�鏈夊钩搴撳簱瀛� - List<Dt_ProStockInfo> proStockInfos = _stockRepository.ProStockInfoRepository.Db.Queryable<Dt_ProStockInfo>().Where(x => x.WarehouseId == warehouse.WarehouseId).Includes(x => x.proStockInfoDetails).ToList(); - List<Dt_ProStockInfoDetail> proStockInfoDetails= new List<Dt_ProStockInfoDetail>(); - foreach (var item in proStockInfos) - { - proStockInfoDetails.AddRange(item.proStockInfoDetails); - } - proStockInfoDetails = proStockInfoDetails.OrderBy(x => x.DateCode).ThenBy(x => x.CreateDate).ToList() ; + List<Dt_ProStockInfoDetail> proStockInfoDetails = _stockRepository.ProStockInfoRepository.Db.Queryable<Dt_ProStockInfo, Dt_ProStockInfoDetail>((master, detail) => master.Id == detail.ProStockId) + .Where((master, detail) => master.WarehouseId == warehouse.WarehouseId && productCodes.Contains(detail.ProductCode)) + .Select((master, detail) => detail) + .ToList(); + proStockInfoDetails = proStockInfoDetails.OrderBy(x => x.DateCode).ThenBy(x => x.CreateDate).ToList(); + List<Dt_ProStockInfo> delProStockInfos = new List<Dt_ProStockInfo>(); List<Dt_ProStockInfoDetail> delStockInfoDetails = new List<Dt_ProStockInfoDetail>(); foreach (var item in outProStocks) { - //鏌ヨ搴撳瓨璁板綍 - if (item.ShippingNumber != outProOrderNo) - { - return await Task.FromResult(content.Error($"ERP杩斿洖浜嗗嚭搴撹鍗晎item.ShippingNumber}搴撳瓨淇℃伅")); - } + //鑾峰彇搴撳瓨 List<Dt_ProStockInfoDetail> outStocks = proStockInfoDetails.Where(x=>x.ProductCode==item.Partnum).ToList(); if (outStocks.Count==0 || outStocks==null) { - return await Task.FromResult(content.Error($"{item.Partnum}浜у搧鍨嬪彿搴撳瓨涓嶅瓨鍦�")); + return content.Error($"{item.Partnum}浜у搧鍨嬪彿搴撳瓨涓嶅瓨鍦�"); } foreach (var itemOut in outStocks) { @@ -716,13 +782,9 @@ { break; } + Dt_ProOutOrderDetail? proOutOrderDetail = proOutOrder.Details.FirstOrDefault(x => x.SaleOrder == item.SoNumber && x.PCode == item.Partnum) ?? throw new Exception($"鍑哄簱鍗晎proOutOrder.ProOutOrderNo}鏈壘鍒伴攢鍞鍗晎item.SoNumber}鏄庣粏,璇锋鏌�"); if (item.Quantity >= itemOut.StockPcsQty) { - Dt_ProOutOrderDetail? proOutOrderDetail = proOutOrder.Details.FirstOrDefault(x => x.SaleOrder == item.SoNumber && x.PCode == item.Partnum); - if (proOutOrderDetail == null) - { - return await Task.FromResult(content.Error($"鍑哄簱鍗晎proOutOrder.ProOutOrderNo}鏈壘鍒伴攢鍞鍗晎item.SoNumber}鏄庣粏,璇锋鏌�")); - } //鏇存柊鍑哄簱鏄庣粏鍗曟暟閲� proOutOrderDetail.OverQtyPcs += itemOut.StockPcsQty; item.Quantity -= (int)itemOut.StockPcsQty; @@ -730,7 +792,7 @@ proStockInfoDetails.Remove(itemOut); if (proOutOrderDetail.OverQtyPcs > proOutOrderDetail.QtyPcs) { - return await Task.FromResult(content.Error($"鍑哄簱鍗晎proOutOrder.ProOutOrderNo}閿�鍞鍗晎item.SoNumber}鏁伴噺婧㈠嚭{proOutOrderDetail.OverQtyPcs - proOutOrderDetail.QtyPcs}")); + return content.Error($"鍑哄簱鍗晎proOutOrder.ProOutOrderNo}閿�鍞鍗晎item.SoNumber}鏁伴噺婧㈠嚭{proOutOrderDetail.OverQtyPcs - proOutOrderDetail.QtyPcs}"); } if (proOutOrderDetail.ProOrderDetailStatus == OrderDetailStatusEnum.New.ObjToInt()) { @@ -743,11 +805,7 @@ } else if (item.Quantity < itemOut.StockPcsQty) { - Dt_ProOutOrderDetail? proOutOrderDetail = proOutOrder.Details.FirstOrDefault(x => x.SaleOrder == item.SoNumber && x.PCode == item.Partnum); - if (proOutOrderDetail == null) - { - return await Task.FromResult(content.Error($"鍑哄簱鍗晎proOutOrder.ProOutOrderNo}鏈壘鍒伴攢鍞鍗晎item.SoNumber}鏄庣粏,璇锋鏌�")); - } + //鏇存柊鍑哄簱鏄庣粏鍗曟暟閲� proOutOrderDetail.OverQtyPcs += item.Quantity; item.Quantity -= item.Quantity; @@ -756,7 +814,7 @@ itemOut.StockPcsQty -= item.Quantity; if (proOutOrderDetail.OverQtyPcs > proOutOrderDetail.QtyPcs) { - return await Task.FromResult(content.Error($"鍑哄簱鍗晎proOutOrder.ProOutOrderNo}閿�鍞鍗晎item.SoNumber}鏁伴噺婧㈠嚭{proOutOrderDetail.OverQtyPcs - proOutOrderDetail.QtyPcs}")); + return content.Error($"鍑哄簱鍗晎proOutOrder.ProOutOrderNo}閿�鍞鍗晎item.SoNumber}鏁伴噺婧㈠嚭{proOutOrderDetail.OverQtyPcs - proOutOrderDetail.QtyPcs}"); } if (proOutOrderDetail.ProOrderDetailStatus == OrderDetailStatusEnum.New.ObjToInt()) { @@ -776,7 +834,7 @@ else { Dt_ProOutOrderDetail? proOutOrderDetail = proOutOrder.Details.FirstOrDefault(x => x.ProOrderDetailStatus <= OrderDetailStatusEnum.Over.ObjToInt()); - return await Task.FromResult(content.Error($"{proOutOrderDetail?.SaleOrder}閿�鍞鍗曟暟閲忛渶鍑簕proOutOrderDetail?.QtyPcs},鍙嚭{proOutOrderDetail?.OverQtyPcs}")); + return content.Error($"{proOutOrderDetail?.SaleOrder}閿�鍞鍗曟暟閲忛渶鍑簕proOutOrderDetail?.QtyPcs},鍙嚭{proOutOrderDetail?.OverQtyPcs}"); } //鏇存柊鏁版嵁 _unitOfWorkManage.BeginTran(); @@ -784,16 +842,16 @@ { _stockRepository.ProStockInfoDetailRepository.DeleteAndMoveIntoHty(delStockInfoDetails, OperateTypeEnum.鑷姩鍒犻櫎); } - await _stockRepository.ProStockInfoDetailRepository.UpdateDataAsync(proStockInfoDetails); - await BaseDal.UpdateDataAsync(proOutOrder); - await _outboundRepository.ProOutOrderDetailRepository.UpdateDataAsync(proOutOrder.Details); + _stockRepository.ProStockInfoDetailRepository.UpdateData(proStockInfoDetails); + BaseDal.UpdateData(proOutOrder); + _outboundRepository.ProOutOrderDetailRepository.UpdateData(proOutOrder.Details); _unitOfWorkManage.CommitTran(); - return await Task.FromResult(content.OK()); + return content.OK(); } catch (Exception ex) { _unitOfWorkManage.RollbackTran(); - return await Task.FromResult(content.Error(ex.Message)); + return content.Error(ex.Message); } } /// <summary> -- Gitblit v1.9.3