| | |
| | | using WIDESEA_Core.BaseServices; |
| | | using WIDESEA_Core.Enums; |
| | | using WIDESEA_Core.Helper; |
| | | using WIDESEA_DTO.ERP; |
| | | using WIDESEA_DTO.Stock; |
| | | using WIDESEA_IBasicRepository; |
| | | using WIDESEA_IBasicService; |
| | |
| | | |
| | | namespace WIDESEA_OutboundService |
| | | { |
| | | |
| | | |
| | | public partial class OutboundOrderDetailService : ServiceBase<Dt_OutboundOrderDetail, IOutboundOrderDetailRepository>, IOutboundOrderDetailService |
| | | { |
| | | |
| | | public WebResponseContent LockOutboundStock(int orderDetailId) |
| | | { |
| | | Dt_OutboundOrderDetail outboundOrderDetail = BaseDal.QueryFirst(x => x.Id == orderDetailId); |
| | |
| | | } |
| | | Dt_OutboundOrder outboundOrder = _outboundRepository.OutboundOrderRepository.QueryFirst(x => x.Id == outboundOrderDetails.FirstOrDefault().OrderId); |
| | | List<Dt_StockInfo> outStocks = new List<Dt_StockInfo>(); |
| | | List<Dt_OutboundOrderDetail> groupDetails = outboundOrderDetails.GroupBy(x => new { x.MaterielCode, x.BatchNo }).Select(x => new Dt_OutboundOrderDetail { OrderQuantity = x.Sum(v => v.OrderQuantity) - x.Sum(v => v.LockQuantity), MaterielCode = x.Key.MaterielCode, BatchNo = x.Key.BatchNo }).ToList(); |
| | | List<Dt_Warehouse> warehouse = _basicService.WarehouseService.Repository.QueryData(x => x.WarehouseDes == outboundOrder.OutWareHouse); |
| | | List<Dt_OutboundOrderDetail> groupDetails = outboundOrderDetails.GroupBy(x => new { x.MaterielCode, x.BatchNo , x.LocationName}).Select(x => new Dt_OutboundOrderDetail { OrderQuantity = x.Sum(v => v.OrderQuantity) - x.Sum(v => v.LockQuantity), MaterielCode = x.Key.MaterielCode, BatchNo = x.Key.BatchNo,LocationName = x.Key.LocationName}).ToList(); |
| | | List<Dt_Warehouse> warehouse = new List<Dt_Warehouse>(); |
| | | if (outboundOrder.OutWareHouse == "SC01_BC") |
| | | { |
| | | warehouse = _basicService.WarehouseService.Repository.QueryData(x => x.WarehouseDes == outboundOrder.OutWareHouse || x.WarehouseDes =="SC02_BC"); |
| | | } |
| | | else |
| | | { |
| | | warehouse = _basicService.WarehouseService.Repository.QueryData(x => x.WarehouseDes == outboundOrder.OutWareHouse); |
| | | } |
| | | List<Dt_OutStockLockInfo> outStockLockInfos = new List<Dt_OutStockLockInfo>(); |
| | | List<Dt_LocationInfo> locationInfos = new List<Dt_LocationInfo>(); |
| | | foreach (var item in groupDetails) |
| | |
| | | |
| | | decimal needQuantity = originalNeedQuantity; |
| | | |
| | | List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.GetUseableStocks(item.MaterielCode, item.BatchNo, warehouse); |
| | | List<Dt_StockInfo> stockInfos = new List<Dt_StockInfo>(); |
| | | ///出库指定库位出库判断 |
| | | if (item.LocationName != null && item.LocationName != "") |
| | | { |
| | | stockInfos = _stockService.StockInfoService.GetUseableStocks(item.MaterielCode, item.BatchNo, warehouse).Where(x=>x.LocationCode == item.LocationName).ToList(); |
| | | } |
| | | else |
| | | { |
| | | stockInfos = _stockService.StockInfoService.GetUseableStocks(item.MaterielCode, item.BatchNo, warehouse); |
| | | } |
| | | |
| | | if (!stockInfos.Any()) |
| | | { |
| | | throw new Exception($"未找到可分配库存"); |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | locationInfos.AddRange(_basicService.LocationInfoService.Repository.GetLocationInfos(outStocks.Select(x => x.LocationCode).ToList())); |
| | | } |
| | |
| | | } |
| | | return (true, "成功"); |
| | | } |
| | | |
| | | |
| | | public string ToCancelOutFeedbackERP = WIDESEA_Core.Helper.AppSettings.Configuration["CancelOutFeedbackERP"]; |
| | | public WebResponseContent CancelOutFeedbackERP(int[] keys) |
| | | { |
| | | List<Dt_OutboundOrderDetail> outboundOrderDetails = _outboundRepository.OutboundOrderDetailRepository.QueryData(x => keys.Contains(x.Id)); |
| | | |
| | | if (outboundOrderDetails == null || outboundOrderDetails.Count == 0) |
| | | { |
| | | return WebResponseContent.Instance.Error("未找到出库单明细信息"); |
| | | } |
| | | if (outboundOrderDetails.FirstOrDefault(x => x.OrderDetailStatus > OrderDetailStatusEnum.New.ObjToInt() && x.OrderDetailStatus != OrderDetailStatusEnum.AssignOverPartial.ObjToInt()) != null) |
| | | { |
| | | return WebResponseContent.Instance.Error("所选出库单明细存在出库中或已完成"); |
| | | } |
| | | Dt_OutboundOrder outboundOrder = _outboundRepository.OutboundOrderRepository.QueryFirst(x => x.Id == outboundOrderDetails[0].OrderId); |
| | | if(outboundOrder == null) |
| | | { |
| | | return WebResponseContent.Instance.Error("未通过该明细找到出库单信息"); |
| | | } |
| | | if (!outboundOrder.System.Equals("ERP")) |
| | | { |
| | | return WebResponseContent.Instance.Error("该出库单据非ERP推送,无法取消"); |
| | | } |
| | | string ids =""; |
| | | foreach (var item in outboundOrderDetails) |
| | | { |
| | | ids = item.LinId; |
| | | var postContent = new MultipartFormDataContent(); |
| | | postContent.Headers.Add("ContentType", $"multipart/form-data"); |
| | | postContent.Add(new StringContent(ids), "ids"); |
| | | string result = string.Empty; |
| | | HttpClient client = null; |
| | | try |
| | | { |
| | | using (client = new HttpClient()) |
| | | { |
| | | HttpResponseMessage response = client.PostAsync(ToCancelOutFeedbackERP, postContent) |
| | | .ConfigureAwait(false).GetAwaiter().GetResult(); |
| | | |
| | | // 确保响应成功 |
| | | response.EnsureSuccessStatusCode(); |
| | | result = response.Content.ReadAsStringAsync() |
| | | .ConfigureAwait(false).GetAwaiter().GetResult(); |
| | | } |
| | | _unitOfWorkManage.BeginTran(); |
| | | _outboundRepository.OutboundOrderDetailRepository.DeleteAndMoveIntoHty(outboundOrderDetails, OperateType.人工取消); |
| | | |
| | | //检查该主订单是否还有剩余明细 |
| | | int remainingDetailsCount = _outboundRepository.OutboundOrderDetailRepository |
| | | .Db.Queryable<Dt_OutboundOrderDetail>() |
| | | .Where(d => d.OrderId == outboundOrder.Id) |
| | | .Count(); |
| | | |
| | | // 如果没有剩余明细,再删除主订单 |
| | | if (remainingDetailsCount == 0) |
| | | { |
| | | _outboundRepository.OutboundOrderRepository.DeleteAndMoveIntoHty(outboundOrder, OperateType.人工取消); |
| | | } |
| | | _unitOfWorkManage.CommitTran(); |
| | | // 假设ERP返回成功时返回成功响应 |
| | | return WebResponseContent.Instance.OK(result); |
| | | |
| | | } |
| | | catch (HttpRequestException ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | // 处理HTTP请求相关异常 |
| | | return WebResponseContent.Instance.Error($"HTTP请求错误: {ex.Message}"); |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | // 处理其他异常 |
| | | return WebResponseContent.Instance.Error($"处理失败: {ex.Message}"); |
| | | } |
| | | |
| | | } |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | |
| | | } |
| | | } |