| | |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEA_BasicService; |
| | | using WIDESEA_Common.CommonEnum; |
| | | using WIDESEA_Common.LocationEnum; |
| | | using WIDESEA_Common.OrderEnum; |
| | |
| | | using WIDESEA_DTO.Basic; |
| | | using WIDESEA_DTO.Stock; |
| | | using WIDESEA_Model.Models; |
| | | using WIDESEA_Model.Models.Basic; |
| | | using WIDESEA_Model.Models.Outbound; |
| | | |
| | | namespace WIDESEA_TaskInfoService |
| | | { |
| | |
| | | { |
| | | throw new Exception("æªæ¾å°åºåºåæç»ä¿¡æ¯"); |
| | | } |
| | | if (outboundOrderDetails.FirstOrDefault(x => x.OrderDetailStatus > OrderDetailStatusEnum.New.ObjToInt() && x.OrderDetailStatus != OrderDetailStatusEnum.AssignOverPartial.ObjToInt()) != null) |
| | | //if (outboundOrderDetails.FirstOrDefault(x => x.OrderDetailStatus > OrderDetailStatusEnum.New.ObjToInt() && x.OrderDetailStatus != OrderDetailStatusEnum.AssignOverPartial.ObjToInt()) != null) |
| | | //{ |
| | | // throw new Exception("æéåºåºåæç»åå¨åºåºä¸æå·²å®æ"); |
| | | //} |
| | | |
| | | if (outboundOrderDetails.FirstOrDefault(x => x.OrderDetailStatus > OrderDetailStatusEnum.Outbound.ObjToInt() && x.OrderDetailStatus != OrderDetailStatusEnum.AssignOverPartial.ObjToInt()) != null) |
| | | { |
| | | throw new Exception("æéåºåºåæç»åå¨åºåºä¸æå·²å®æ"); |
| | | throw new Exception("æéåºåºåæç»åå¨å·²å®æç¶æï¼æ æ³éæ°åé
"); |
| | | } |
| | | |
| | | List<Dt_StockInfo>? stockInfos = null; |
| | | List<Dt_OutboundOrderDetail>? orderDetails = null; |
| | | List<Dt_OutStockLockInfo>? outStockLockInfos = null; |
| | | List<Dt_LocationInfo>? locationInfos = null; |
| | | |
| | | CleanupPreviousInvalidLocks(outboundOrderDetails); |
| | | |
| | | (List<Dt_StockInfo>, List<Dt_OutboundOrderDetail>, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) result = _outboundOrderDetailService.AssignStockOutbound(outboundOrderDetails); |
| | | if (result.Item1 != null && result.Item1.Count > 0) |
| | |
| | | else |
| | | { |
| | | throw new Exception("æ åºå"); |
| | | } |
| | | } |
| | | return (tasks, stockInfos, orderDetails, outStockLockInfos, locationInfos); |
| | | } |
| | | /// <summary> |
| | | /// æ¸
çä¹åçæ æéå®è®°å½ |
| | | /// </summary> |
| | | private void CleanupPreviousInvalidLocks(List<Dt_OutboundOrderDetail> orderDetails) |
| | | { |
| | | var orderIds = orderDetails.Select(x => x.OrderId).Distinct().ToList(); |
| | | var orderNos = _outboundOrderService.Db.Queryable<Dt_OutboundOrder>() |
| | | .Where(x => orderIds.Contains(x.Id)) |
| | | .Select(x => x.OrderNo) |
| | | .ToList(); |
| | | |
| | | // æ¸
çç¶æä¸º"已鿾"æ"ååºä¸"çæ§éå®è®°å½ |
| | | foreach (var orderNo in orderNos) |
| | | { |
| | | _outStockLockInfoService.Db.Updateable<Dt_OutStockLockInfo>() |
| | | .SetColumns(x => new Dt_OutStockLockInfo |
| | | { |
| | | Status = (int)OutLockStockStatusEnum.已鿾 |
| | | }) |
| | | .Where(x => x.OrderNo == orderNo && |
| | | (x.Status == (int)OutLockStockStatusEnum.ååºä¸ || |
| | | x.Status == (int)OutLockStockStatusEnum.已鿾)) |
| | | .ExecuteCommand(); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// çæåºåºä»»å¡åæ°æ®æ´æ°å°æ°æ®åº |
| | |
| | | { |
| | | _outboundOrderService.Repository.UpdateData(outboundOrder); |
| | | } |
| | | else |
| | | { |
| | | outboundOrder.OrderStatus = OutOrderStatusEnum.åºåºä¸.ObjToInt(); |
| | | } |
| | | outboundOrder.Operator = App.User.UserName; |
| | | _outboundOrderService.Repository.UpdateData(outboundOrder); |
| | | WebResponseContent content = _outboundOrderDetailService.LockOutboundStockDataUpdate(stockInfos, outboundOrderDetails, outStockLockInfos, locationInfos, tasks: tasks); |
| | | |
| | | if (!content.Status) |
| | |
| | | { |
| | | _outboundOrderService.Repository.UpdateData(outboundOrder); |
| | | } |
| | | else |
| | | { |
| | | outboundOrder.OrderStatus = OutOrderStatusEnum.åºåºä¸.ObjToInt(); |
| | | } |
| | | outboundOrder.Operator = App.User.UserName; |
| | | _outboundOrderService.Repository.UpdateData(outboundOrder); |
| | | _outboundOrderDetailService.Repository.UpdateData(outboundOrderDetails); |
| | | } |
| | | _unitOfWorkManage.CommitTran(); |
| | |
| | | throw new Exception("æªæ¾å°åºåºåæç»ä¿¡æ¯"); |
| | | } |
| | | |
| | | if (stockSelectViews.Sum(x => x.UseableQuantity) > outboundOrderDetail.OrderQuantity - outboundOrderDetail.LockQuantity) |
| | | { |
| | | throw new Exception("éæ©æ°éè¶
åºåæ®æ°é"); |
| | | } |
| | | //if (stockSelectViews.Sum(x => x.UseableQuantity) > outboundOrderDetail.OrderQuantity - outboundOrderDetail.LockQuantity) |
| | | //{ |
| | | // throw new Exception("éæ©æ°éè¶
åºåæ®æ°é"); |
| | | //} |
| | | List<Dt_StockInfo>? stockInfos = null; |
| | | Dt_OutboundOrderDetail? orderDetail = null; |
| | | List<Dt_OutStockLockInfo>? outStockLockInfos = null; |
| | |
| | | (List<Dt_StockInfo>, Dt_OutboundOrderDetail, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) result = _outboundOrderDetailService.AssignStockOutbound(outboundOrderDetail, stockSelectViews); |
| | | if (result.Item1 != null && result.Item1.Count > 0) |
| | | { |
| | | Dt_OutboundOrder outboundOrder = _outboundOrderService .Repository.QueryFirst(x => x.Id == outboundOrderDetail.OrderId); |
| | | Dt_OutboundOrder outboundOrder = _outboundOrderService.Repository.QueryFirst(x => x.Id == outboundOrderDetail.OrderId); |
| | | TaskTypeEnum typeEnum = outboundOrder.OrderType switch |
| | | { |
| | | (int)OutOrderTypeEnum.Issue => TaskTypeEnum.Outbound, |
| | |
| | | |
| | | } |
| | | |
| | | |
| | | #region åæ¹åé
åºå |
| | | |
| | | /// <summary> |
| | | /// åæ¹åé
åºå |
| | | /// </summary> |
| | | public async Task<WebResponseContent> BatchAllocateStock(string orderNo, int orderDetailId, decimal batchQuantity, string outStation) |
| | | { |
| | | try |
| | | { |
| | | List<Dt_Task> tasks = new List<Dt_Task>(); |
| | | List<Dt_StockInfo> stockInfos = new List<Dt_StockInfo>(); |
| | | List<Dt_OutboundOrderDetail> outboundOrderDetails = new List<Dt_OutboundOrderDetail>(); |
| | | List<Dt_OutStockLockInfo> outStockLockInfos = new List<Dt_OutStockLockInfo>(); |
| | | List<Dt_LocationInfo> locationInfos = new List<Dt_LocationInfo>(); |
| | | |
| | | (List<Dt_Task>, List<Dt_StockInfo>?, List<Dt_OutboundOrderDetail>?, List<Dt_OutStockLockInfo>?, List<Dt_LocationInfo>?) result = await BatchAllocateStockDataHandle(orderNo, orderDetailId, batchQuantity, outStation); |
| | | |
| | | if (result.Item2 != null && result.Item2.Count > 0) |
| | | { |
| | | stockInfos.AddRange(result.Item2); |
| | | } |
| | | if (result.Item3 != null && result.Item3.Count > 0) |
| | | { |
| | | outboundOrderDetails.AddRange(result.Item3); |
| | | } |
| | | if (result.Item4 != null && result.Item4.Count > 0) |
| | | { |
| | | outStockLockInfos.AddRange(result.Item4); |
| | | } |
| | | if (result.Item5 != null && result.Item5.Count > 0) |
| | | { |
| | | locationInfos.AddRange(result.Item5); |
| | | } |
| | | if (result.Item1 != null && result.Item1.Count > 0) |
| | | { |
| | | tasks.AddRange(result.Item1); |
| | | } |
| | | |
| | | WebResponseContent content = await GenerateOutboundTaskDataUpdateAsync(tasks, stockInfos, outboundOrderDetails, outStockLockInfos, locationInfos); |
| | | return content; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | _logger.LogError($"åæ¹åé
åºå失败 - OrderNo: {orderNo}, OrderDetailId: {orderDetailId}, Quantity: {batchQuantity}, Error: {ex.Message}"); |
| | | return WebResponseContent.Instance.Error($"åæ¹åé
失败ï¼{ex.Message}"); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// åæ¹åé
åºåæ°æ®å¤ç |
| | | /// </summary> |
| | | public async Task<(List<Dt_Task>, List<Dt_StockInfo>?, List<Dt_OutboundOrderDetail>?, List<Dt_OutStockLockInfo>?, List<Dt_LocationInfo>?)> |
| | | BatchAllocateStockDataHandle(string orderNo, int orderDetailId, decimal batchQuantity, string outStation) |
| | | { |
| | | List<Dt_Task> tasks = new List<Dt_Task>(); |
| | | |
| | | // è·å订åæç» |
| | | var outboundOrderDetail = await _outboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>() |
| | | .FirstAsync(x => x.Id == orderDetailId ); |
| | | |
| | | if (outboundOrderDetail == null) |
| | | { |
| | | throw new Exception("æªæ¾å°åºåºåæç»ä¿¡æ¯"); |
| | | } |
| | | |
| | | // éªè¯è®¢åæç»ç¶æ |
| | | if (outboundOrderDetail.OrderDetailStatus > OrderDetailStatusEnum.New.ObjToInt() && |
| | | outboundOrderDetail.OrderDetailStatus != OrderDetailStatusEnum.AssignOverPartial.ObjToInt()) |
| | | { |
| | | throw new Exception("æéåºåºåæç»åå¨åºåºä¸æå·²å®æ"); |
| | | } |
| | | |
| | | // éªè¯åé
æ°é |
| | | decimal allocatedQty = outboundOrderDetail.AllocatedQuantity; |
| | | decimal overOutQty = outboundOrderDetail.OverOutQuantity; |
| | | decimal needOutQty = outboundOrderDetail.NeedOutQuantity; |
| | | decimal availableQty = needOutQty - allocatedQty - overOutQty; |
| | | |
| | | if (availableQty <= 0) |
| | | throw new Exception("æ å¯åé
æ°é"); |
| | | |
| | | if (batchQuantity > availableQty) |
| | | throw new Exception($"åé
æ°éä¸è½è¶
è¿å¯åé
æ°é{availableQty}"); |
| | | |
| | | List<Dt_StockInfo>? stockInfos = null; |
| | | List<Dt_OutboundOrderDetail>? orderDetails = null; |
| | | List<Dt_OutStockLockInfo>? outStockLockInfos = null; |
| | | List<Dt_LocationInfo>? locationInfos = null; |
| | | |
| | | // çææ¹æ¬¡å· |
| | | string batchNo = await GenerateBatchNo(); |
| | | |
| | | // åé
åºå |
| | | (List<Dt_StockInfo>, List<Dt_OutboundOrderDetail>, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) allocateResult = |
| | | await _outboundOrderDetailService.AssignStockForBatch(outboundOrderDetail, batchQuantity, batchNo); |
| | | |
| | | if (allocateResult.Item1 != null && allocateResult.Item1.Count > 0) |
| | | { |
| | | // åå»ºåæ¹è®°å½ |
| | | await CreateBatchRecord(orderNo, orderDetailId, batchQuantity, batchNo); |
| | | |
| | | Dt_OutboundOrder outboundOrder = await _outboundOrderService.Repository.QueryFirstAsync(x => x.Id == outboundOrderDetail.OrderId); |
| | | TaskTypeEnum typeEnum = outboundOrder.OrderType switch |
| | | { |
| | | (int)OutOrderTypeEnum.Issue => TaskTypeEnum.Outbound, |
| | | (int)OutOrderTypeEnum.Allocate => TaskTypeEnum.OutAllocate, |
| | | (int)OutOrderTypeEnum.Quality => TaskTypeEnum.OutQuality, |
| | | _ => TaskTypeEnum.Outbound |
| | | }; |
| | | |
| | | tasks = GetTasks(allocateResult.Item1, typeEnum, outStation); |
| | | tasks.ForEach(x => |
| | | { |
| | | x.OrderNo = outboundOrder.OrderNo; |
| | | }); |
| | | |
| | | allocateResult.Item2.ForEach(x => |
| | | { |
| | | x.OrderDetailStatus = OrderDetailStatusEnum.Outbound.ObjToInt(); |
| | | }); |
| | | |
| | | allocateResult.Item3.ForEach(x => |
| | | { |
| | | x.Status = OutLockStockStatusEnum.åºåºä¸.ObjToInt(); |
| | | }); |
| | | |
| | | stockInfos = allocateResult.Item1; |
| | | orderDetails = allocateResult.Item2; |
| | | outStockLockInfos = allocateResult.Item3; |
| | | locationInfos = allocateResult.Item4; |
| | | } |
| | | else |
| | | { |
| | | throw new Exception("æ åºå"); |
| | | } |
| | | |
| | | return (tasks, stockInfos, orderDetails, outStockLockInfos, locationInfos); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// æ´æ°è®¢åæç»ç¶æ |
| | | /// </summary> |
| | | private void UpdateOrderDetailStatus(List<Dt_OutboundOrderDetail> details, decimal allocatedQuantity, decimal needQuantity) |
| | | { |
| | | foreach (var detail in details) |
| | | { |
| | | // æ ¹æ®åé
æ
嵿´æ°ç¶æ |
| | | if (allocatedQuantity >= needQuantity) |
| | | { |
| | | detail.OrderDetailStatus = OrderDetailStatusEnum.Outbound.ObjToInt(); |
| | | } |
| | | else |
| | | { |
| | | detail.OrderDetailStatus = OrderDetailStatusEnum.AssignOverPartial.ObjToInt(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | private async Task<string> GenerateBatchNo() |
| | | { |
| | | var batchNo = UniqueValueGenerator.Generate(); |
| | | |
| | | return $"Out{batchNo} "; |
| | | } |
| | | |
| | | private async Task<Dt_OutboundBatch> CreateBatchRecord(string orderNo, int orderDetailId, decimal batchQuantity, string batchNo) |
| | | { |
| | | var batchRecord = new Dt_OutboundBatch |
| | | { |
| | | BatchNo = batchNo, |
| | | OrderNo = orderNo, |
| | | OrderDetailId = orderDetailId, |
| | | BatchQuantity = batchQuantity, |
| | | BatchStatus = (int)BatchStatusEnum.åé
ä¸, |
| | | Operator = App.User.UserName |
| | | }; |
| | | |
| | | await _OutboundBatchRepository.Db.Insertable(batchRecord).ExecuteCommandAsync(); |
| | | return batchRecord; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | |
| | | } |
| | | } |