| | |
| | | using Newtonsoft.Json; |
| | | using AutoMapper; |
| | | using Dm.filter; |
| | | using MailKit.Search; |
| | | using Mapster; |
| | | using Newtonsoft.Json; |
| | | using Newtonsoft.Json.Serialization; |
| | | using Org.BouncyCastle.Asn1.Ocsp; |
| | | using Org.BouncyCastle.Crypto; |
| | | using SqlSugar; |
| | | using System.Reflection.Emit; |
| | | using WIDESEA_BasicService; |
| | | using WIDESEA_Common.CommonEnum; |
| | | using WIDESEA_Common.LocationEnum; |
| | | using WIDESEA_Common.OrderEnum; |
| | | using WIDESEA_Common.StockEnum; |
| | |
| | | using WIDESEA_Core.BaseRepository; |
| | | using WIDESEA_Core.CodeConfigEnum; |
| | | using WIDESEA_Core.Helper; |
| | | using WIDESEA_DTO.Basic; |
| | | using WIDESEA_DTO.CalcOut; |
| | | using WIDESEA_DTO.ReturnMES; |
| | | using WIDESEA_IBasicService; |
| | |
| | | { |
| | | public partial class OutboundService : IOutboundService |
| | | { |
| | | |
| | | private readonly IMapper _mapper; |
| | | public IUnitOfWorkManage _unitOfWorkManage { get; } |
| | | |
| | | public IOutboundOrderDetailService OutboundOrderDetailService { get; } |
| | |
| | | private readonly IRepository<Dt_LocationInfo> _locationInfoRepository; |
| | | private readonly IRepository<Dt_StockQuantityChangeRecord> _stockChangeRepository; |
| | | private readonly IRepository<Dt_StockInfoDetail_Hty> _stockDetailHistoryRepository; |
| | | private readonly IFeedbackMesService _feedbackMesService; |
| | | private readonly IRepository<Dt_Task> _taskRepository; |
| | | private readonly ILocationInfoService _locationInfoService; |
| | | private readonly IESSApiService _eSSApiService; |
| | | |
| | | public OutboundService(IUnitOfWorkManage unitOfWorkManage, IRepository<Dt_OutboundOrderDetail> detailRepository, IRepository<Dt_OutboundOrder> outboundRepository, IRepository<Dt_OutStockLockInfo> outboundLockInfoRepository, IRepository<Dt_StockInfo> stockInfoRepository, IRepository<Dt_StockInfoDetail> stockDetailRepository, IRepository<Dt_StockQuantityChangeRecord> stockChangeRepository, IRepository<Dt_StockInfoDetail_Hty> stockDetailHistoryRepository, IBasicService basicService, IOutboundOrderDetailService outboundOrderDetailService, IOutboundOrderService outboundOrderService, IOutStockLockInfoService outboundStockLockInfoService) |
| | | private Dictionary<string, string> stations = new Dictionary<string, string> |
| | | { |
| | | {"2-1","2-9" }, |
| | | {"3-1","3-9" }, |
| | | }; |
| | | |
| | | private Dictionary<string, string> movestations = new Dictionary<string, string> |
| | | { |
| | | {"2-1","2-5" }, |
| | | {"3-1","3-5" }, |
| | | }; |
| | | |
| | | public OutboundService(IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IRepository<Dt_OutboundOrderDetail> detailRepository, IRepository<Dt_OutboundOrder> outboundRepository, IRepository<Dt_OutStockLockInfo> outboundLockInfoRepository, IRepository<Dt_StockInfo> stockInfoRepository, IRepository<Dt_StockInfoDetail> stockDetailRepository, IRepository<Dt_StockQuantityChangeRecord> stockChangeRepository, IRepository<Dt_StockInfoDetail_Hty> stockDetailHistoryRepository, IBasicService basicService, IOutboundOrderDetailService outboundOrderDetailService, IOutboundOrderService outboundOrderService, IOutStockLockInfoService outboundStockLockInfoService, IFeedbackMesService feedbackMesService, IRepository<Dt_Task> taskRepository, ILocationInfoService locationInfoService, IESSApiService eSSApiService) |
| | | { |
| | | _mapper = mapper; |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | Db = _unitOfWorkManage.GetDbClient(); |
| | | OutboundOrderDetailService = outboundOrderDetailService; |
| | |
| | | _stockChangeRepository = stockChangeRepository; |
| | | _stockDetailHistoryRepository = stockDetailHistoryRepository; |
| | | _basicService = basicService; |
| | | _feedbackMesService = feedbackMesService; |
| | | _taskRepository = taskRepository; |
| | | _locationInfoService = locationInfoService; |
| | | _eSSApiService = eSSApiService; |
| | | } |
| | | |
| | | #region åºåºåé
|
| | | /// <summary> |
| | | /// 忣åºåºæä½ |
| | | /// </summary> |
| | |
| | | |
| | | pickedDetails.AddRange(materielPickedDetails.PickedDetails); |
| | | |
| | | decimal allallocatedQuantity = materielCalc.UnallocatedQuantity; |
| | | // æ´æ°åºåºåæç»ï¼å¢å é宿°éï¼ä¸å¢å å·²åºæ°éï¼ |
| | | foreach (var detail in materielCalc.Details) |
| | | { |
| | | if (allallocatedQuantity <= 0) break; |
| | | |
| | | decimal lockQuantity = (detail.OrderQuantity - detail.OverOutQuantity); |
| | | if (lockQuantity < materielCalc.UnallocatedQuantity) |
| | | { |
| | | detail.LockQuantity += lockQuantity; // å¢å é宿°é 䏿´æ° OverOutQuantity å OrderDetailStatusï¼å ä¸ºè¿æ²¡æå®é
åºåº |
| | | outboundOrderDetails.Add(detail); |
| | | materielCalc.UnallocatedQuantity -= lockQuantity; |
| | | } |
| | | else |
| | | { |
| | |
| | | |
| | | // 7. æ´æ°åºå详æ
|
| | | UpdateOutStockLockInfo(outStockLockInfos); |
| | | |
| | | // 8. æ·»å 任塿°æ® |
| | | _taskRepository.AddData(tasks); |
| | | |
| | | _unitOfWorkManage.CommitTran(); |
| | | |
| | |
| | | |
| | | if (outboundOrder.IsBatch == 1) |
| | | { |
| | | selectedDetails = _detailRepository.QueryData(x => x.WarehouseCode == selectedDetails.First().WarehouseCode && x.MaterielCode == selectedDetails.First().MaterielCode && x.BatchNo == selectedDetails.First().BatchNo && x.SupplyCode == selectedDetails.First().SupplyCode); |
| | | selectedDetails = _detailRepository.QueryData(x => x.OrderId == selectedDetails.First().OrderId && x.WarehouseCode == selectedDetails.First().WarehouseCode && x.MaterielCode == selectedDetails.First().MaterielCode && x.BatchNo == selectedDetails.First().BatchNo && x.SupplyCode == selectedDetails.First().SupplyCode); |
| | | } |
| | | |
| | | |
| | |
| | | return result; |
| | | } |
| | | |
| | | decimal inputQuantity = request.OutboundQuantity.Value; |
| | | List<Dt_OutboundOrderDetail> outboundOrderDetails = new List<Dt_OutboundOrderDetail>(); |
| | | foreach (var item in selectedDetails) |
| | | { |
| | | inputQuantity -= (item.OrderQuantity - item.MoveQty - item.LockQuantity); |
| | | outboundOrderDetails.Add(item); |
| | | if (inputQuantity <= 0) |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | |
| | | result.MaterielCalculations = new List<MaterielOutboundCalculationDTO>() |
| | | { |
| | | new MaterielOutboundCalculationDTO |
| | |
| | | AssignedQuantity = lockQuantity, |
| | | UnallocatedQuantity = request.OutboundQuantity.Value, |
| | | MovedQuantity = moveQuantity, |
| | | Details = selectedDetails |
| | | Details = outboundOrderDetails |
| | | } |
| | | }; |
| | | |
| | | outboundOrder.Details = outboundOrderDetails; |
| | | } |
| | | |
| | | result.CanOutbound = true; |
| | |
| | | return false; |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | |
| | | |
| | | public WebResponseContent CompleteOutboundWithPallet(OutboundCompletePalletRequestDTO request) |
| | | { |
| | | WebResponseContent content = WebResponseContent.Instance; |
| | | |
| | | OutboundCompleteResponseDTO response = new(); |
| | | try |
| | | { |
| | | // 1. æ ¹æ®æçå·æ¥æ¾åºåä¿¡æ¯ |
| | | Dt_StockInfo stockInfo = _stockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletCode == request.PalletCode).Includes(x => x.Details).First(); |
| | | if (stockInfo == null) |
| | | { |
| | | response.Success = false; |
| | | response.Message = $"æçå· {request.PalletCode} 对åºçåºåä¸åå¨"; |
| | | return WebResponseContent.Instance.Error(response.Message); |
| | | } |
| | | |
| | | if (!stockInfo.Details.Any()) |
| | | { |
| | | response.Success = false; |
| | | response.Message = $"æç {request.PalletCode} 对åºçåºåæç»ä¸åå¨"; |
| | | return WebResponseContent.Instance.Error(response.Message); |
| | | } |
| | | |
| | | bool isMatMixed = stockInfo.Details.GroupBy(x => new |
| | | { |
| | | x.MaterielCode, |
| | | x.MaterielName, |
| | | x.BatchNo, |
| | | x.SupplyCode, |
| | | x.WarehouseCode |
| | | }).Count() > 1; |
| | | |
| | | if (isMatMixed) |
| | | { |
| | | response.Success = false; |
| | | response.Message = $"æ··ææç {request.PalletCode} ä¸è½æ´ç®±åºåº"; |
| | | return WebResponseContent.Instance.Error(response.Message); |
| | | } |
| | | |
| | | // 2. æ¥æ¾åºåºåä¿¡æ¯ |
| | | Dt_OutboundOrder outboundOrder = _outboundRepository.QueryFirst(o => o.OrderNo == request.OrderNo); |
| | | if (outboundOrder == null) |
| | | { |
| | | response.Success = false; |
| | | response.Message = $"åºåºå {request.OrderNo} ä¸åå¨"; |
| | | return WebResponseContent.Instance.Error(response.Message); |
| | | } |
| | | |
| | | Dt_StockInfoDetail stockInfoDetail = stockInfo.Details.First(); |
| | | |
| | | // 3. æ¥æ¾éå®è®°å½ |
| | | Dt_OutStockLockInfo lockInfo = _outboundLockInfoRepository.QueryFirst(x => |
| | | x.OrderNo == request.OrderNo && |
| | | x.StockId == stockInfo.Id && |
| | | x.MaterielCode == stockInfoDetail.MaterielCode && |
| | | x.PalletCode == stockInfo.PalletCode); |
| | | |
| | | if (lockInfo == null || lockInfo.AssignQuantity <= 0) |
| | | { |
| | | response.Success = false; |
| | | response.Message = $"该åºå没æåé
åºåºéï¼æçå·ï¼{request.PalletCode}"; |
| | | return WebResponseContent.Instance.Error(response.Message); |
| | | } |
| | | |
| | | // æ¾åºå·²åé
ç订åæç»Id |
| | | List<int> detailIds = new List<int>(); |
| | | string[] ids = lockInfo.OrderDetailIds.Split(","); |
| | | foreach (string id in ids) |
| | | { |
| | | if (int.TryParse(id, out int detailId)) |
| | | { |
| | | detailIds.Add(detailId); |
| | | } |
| | | } |
| | | // 4. æ¥æ¾åºåºåæç»ä¿¡æ¯ |
| | | List<Dt_OutboundOrderDetail> outboundOrderDetails = FindMatchingOutboundDetails(outboundOrder.Id, stockInfoDetail, detailIds); |
| | | if (!outboundOrderDetails.Any()) |
| | | { |
| | | response.Success = false; |
| | | response.Message = $"æªæ¾å°å¹é
çåºåºåæç»ï¼ç©æï¼{stockInfoDetail.MaterielCode}ï¼æ¹æ¬¡ï¼{stockInfoDetail.BatchNo}"; |
| | | return WebResponseContent.Instance.Error(response.Message); |
| | | } |
| | | |
| | | decimal totalStockQuantity = stockInfo.Details.Sum(x => x.StockQuantity); |
| | | |
| | | // 5. 计ç®å®é
åºåºé |
| | | decimal actualOutboundQuantity = CalculateActualOutboundQuantity(stockInfo.Details, outboundOrderDetails, lockInfo);// éåºåºé |
| | | |
| | | if (actualOutboundQuantity <= 0) |
| | | { |
| | | decimal totalAllocatedQuantity = lockInfo.AllocatedQuantity; |
| | | decimal availableOutboundQuantity = lockInfo.AssignQuantity - totalAllocatedQuantity; |
| | | decimal detailRemainingQuantity = outboundOrderDetails.Sum(x => x.OrderQuantity - x.OverOutQuantity - x.MoveQty); |
| | | |
| | | response.Success = false; |
| | | response.Message = $"æ æ³åºåºï¼æçå·ï¼{request.PalletCode}ï¼åºåéï¼{totalStockQuantity}ï¼å·²åºåºï¼{totalAllocatedQuantity}ï¼åé
éï¼{lockInfo.AssignQuantity}ï¼æç»å©ä½ï¼{detailRemainingQuantity}"; |
| | | return WebResponseContent.Instance.Error(response.Message); |
| | | } |
| | | |
| | | if (lockInfo.AssignQuantity != totalStockQuantity) |
| | | { |
| | | response.Success = false; |
| | | response.Message = $"æ æ³åºåºï¼æçå·ï¼{request.PalletCode}ï¼åºåéï¼{totalStockQuantity}ï¼åé
éï¼{lockInfo.AssignQuantity}"; |
| | | return WebResponseContent.Instance.Error(response.Message); |
| | | } |
| | | |
| | | // 6. å¼å¯äºå¡ |
| | | _unitOfWorkManage.BeginTran(); |
| | | try |
| | | { |
| | | // æ´ç®±åºåºæ éæå
|
| | | PerformFullOutboundOperation(stockInfo, request, lockInfo.TaskNum.GetValueOrDefault()); |
| | | |
| | | |
| | | decimal allocatedQuantity = actualOutboundQuantity; |
| | | List<Dt_OutboundOrderDetail> updateDetails = new(); |
| | | foreach (var item in outboundOrderDetails) |
| | | { |
| | | if (allocatedQuantity <= 0) break; |
| | | |
| | | |
| | | //if (item.OrderQuantity - item.MoveQty - item.OverOutQuantity >= allocatedQuantity) |
| | | //{ |
| | | // item.OverOutQuantity += allocatedQuantity; |
| | | // allocatedQuantity = 0; |
| | | //} |
| | | //else |
| | | //{ |
| | | // allocatedQuantity -= (item.OrderQuantity - item.MoveQty - item.OverOutQuantity); |
| | | // item.OverOutQuantity = item.OrderQuantity - item.MoveQty; |
| | | //} |
| | | List<Barcodes> barcodesList = new List<Barcodes>(); |
| | | List<Dt_StockInfoDetail> stockInfoDetails = stockInfo.Details.Where((x => x.StockQuantity > x.OutboundQuantity)).ToList(); |
| | | foreach (var stockDetail in stockInfoDetails) |
| | | { |
| | | if (item.LockQuantity - item.OverOutQuantity >= stockDetail.StockQuantity - stockInfoDetail.OutboundQuantity) |
| | | { |
| | | Barcodes barcodes = new Barcodes |
| | | { |
| | | Barcode = stockDetail.Barcode, |
| | | Qty = stockDetail.StockQuantity - stockInfoDetail.OutboundQuantity, |
| | | SupplyCode = stockDetail?.SupplyCode ?? "", |
| | | BatchNo = stockDetail?.BatchNo ?? "", |
| | | Unit = stockDetail?.Unit ?? "" |
| | | }; |
| | | |
| | | stockDetail.StockQuantity = stockInfoDetail.OutboundQuantity; |
| | | barcodesList.Add(barcodes); |
| | | } |
| | | else |
| | | { |
| | | Barcodes barcodes = new Barcodes |
| | | { |
| | | Barcode = stockDetail.Barcode, |
| | | Qty = item.LockQuantity - item.OverOutQuantity, |
| | | SupplyCode = stockDetail?.SupplyCode ?? "", |
| | | BatchNo = stockDetail?.BatchNo ?? "", |
| | | Unit = stockDetail?.Unit ?? "" |
| | | }; |
| | | stockInfoDetail.OutboundQuantity += item.LockQuantity - item.OverOutQuantity; |
| | | barcodesList.Add(barcodes); |
| | | } |
| | | } |
| | | |
| | | decimal barcodeQuantity = allocatedQuantity; |
| | | |
| | | if (item.LockQuantity - item.OverOutQuantity >= allocatedQuantity) |
| | | { |
| | | item.OverOutQuantity += allocatedQuantity; |
| | | item.CurrentDeliveryQty += allocatedQuantity; |
| | | allocatedQuantity = 0; |
| | | } |
| | | else |
| | | { |
| | | barcodeQuantity = item.LockQuantity - item.OverOutQuantity; |
| | | allocatedQuantity -= (item.LockQuantity - item.OverOutQuantity); |
| | | item.OverOutQuantity = item.LockQuantity; |
| | | item.CurrentDeliveryQty = item.LockQuantity; |
| | | } |
| | | |
| | | updateDetails.Add(item); |
| | | |
| | | |
| | | if (!string.IsNullOrEmpty(item.ReturnJsonData)) |
| | | { |
| | | barcodesList.AddRange(JsonConvert.DeserializeObject<List<Barcodes>>(item.ReturnJsonData) ?? new List<Barcodes>()); |
| | | } |
| | | |
| | | JsonSerializerSettings settings = new JsonSerializerSettings |
| | | { |
| | | ContractResolver = new CamelCasePropertyNamesContractResolver() |
| | | }; |
| | | item.ReturnJsonData = JsonConvert.SerializeObject(barcodesList, settings); |
| | | } |
| | | |
| | | lockInfo.SortedQuantity = lockInfo.SortedQuantity + actualOutboundQuantity; |
| | | |
| | | if (lockInfo.SortedQuantity == lockInfo.AssignQuantity) |
| | | { |
| | | _outboundLockInfoRepository.DeleteAndMoveIntoHty(lockInfo, WIDESEA_Core.Enums.OperateTypeEnum.èªå¨å®æ); |
| | | } |
| | | else |
| | | { |
| | | // æ´æ°éå®è®°å½ |
| | | _outboundLockInfoRepository.UpdateData(lockInfo); |
| | | } |
| | | |
| | | // æ´æ°åºåºåæç»çå·²åºåºæ°é |
| | | _detailRepository.UpdateData(updateDetails); |
| | | |
| | | // æ´æ°éå®è®°å½ç累计已åºåºæ°éï¼éè¦æ´æ°è¯¥æçè¯¥ç©æçææç¸å
³è®°å½ï¼ |
| | | //UpdateLockInfoAllocatedQuantity(stockInfo.Id, stockDetail.MaterielCode, stockDetail.BatchNo, actualOutboundQuantity); |
| | | |
| | | // æäº¤äºå¡ |
| | | _unitOfWorkManage.CommitTran(); |
| | | |
| | | response.Success = true; |
| | | response.Message = "åºåºå®æ"; |
| | | response.UpdatedDetails = updateDetails; |
| | | |
| | | // æ£æ¥åºåºåæ¯å¦å®æ |
| | | if (CheckOutboundOrderCompleted(request.OrderNo)) |
| | | { |
| | | UpdateOutboundOrderStatus(request.OrderNo, OutOrderStatusEnum.åºåºå®æ.ObjToInt()); |
| | | |
| | | |
| | | //todo: åä¼ MES |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | response.Success = false; |
| | | response.Message = $"åºåºå¤ç失败ï¼{ex.Message}"; |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | |
| | | content = WebResponseContent.Instance.OK(data: response); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error("å¤çåºåºå®æå¤±è´¥ï¼" + ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 计ç®å®é
åºåºæ°é |
| | | /// </summary> |
| | | private decimal CalculateActualOutboundQuantity(List<Dt_StockInfoDetail> stockDetails, List<Dt_OutboundOrderDetail> outboundDetails, Dt_OutStockLockInfo lockInfo) |
| | | { |
| | | decimal availableOutboundQuantity = lockInfo.AssignQuantity; |
| | | decimal detailRemainingQuantity = outboundDetails.Sum(x => x.OrderQuantity - x.OverOutQuantity - x.MoveQty);//outboundDetail.OrderQuantity - outboundDetail.OverOutQuantity; |
| | | |
| | | return Math.Min( |
| | | Math.Min(availableOutboundQuantity, detailRemainingQuantity), |
| | | stockDetails.Sum(x => x.StockQuantity)); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ§è¡å®æ´åºåºæä½ï¼ä¸æå
ï¼ |
| | | /// </summary> |
| | | private void PerformFullOutboundOperation(Dt_StockInfo stockInfo, OutboundCompletePalletRequestDTO request, int taskNum) |
| | | { |
| | | List<Dt_StockInfoDetail_Hty> historyRecords = new List<Dt_StockInfoDetail_Hty>(); |
| | | List<Dt_StockQuantityChangeRecord> changeRecords = new List<Dt_StockQuantityChangeRecord>(); |
| | | foreach (var item in stockInfo.Details) |
| | | { |
| | | // ä¿ååºåæç»å°åå²è®°å½ |
| | | Dt_StockInfoDetail_Hty historyRecord = new Dt_StockInfoDetail_Hty |
| | | { |
| | | SourceId = item.Id, |
| | | OperateType = "åºåºå®æ", |
| | | InsertTime = DateTime.Now, |
| | | StockId = item.StockId, |
| | | MaterielCode = item.MaterielCode, |
| | | MaterielName = item.MaterielName, |
| | | OrderNo = item.OrderNo, |
| | | BatchNo = item.BatchNo, |
| | | ProductionDate = item.ProductionDate, |
| | | EffectiveDate = item.EffectiveDate, |
| | | SerialNumber = item.SerialNumber, |
| | | StockQuantity = item.StockQuantity, |
| | | OutboundQuantity = item.StockQuantity, |
| | | Status = item.Status, |
| | | Unit = item.Unit, |
| | | InboundOrderRowNo = item.InboundOrderRowNo, |
| | | SupplyCode = item.SupplyCode, |
| | | FactoryArea = item.FactoryArea, |
| | | WarehouseCode = item.WarehouseCode, |
| | | Barcode = item.Barcode, |
| | | Remark = $"æ´ç®±åºåºå®æå é¤ï¼æ¡ç ï¼{request.PalletCode}ï¼åæ°éï¼{item.StockQuantity}ï¼åºåºæ°éï¼{item.StockQuantity}ï¼æä½è
ï¼{request.Operator}" |
| | | }; |
| | | historyRecords.Add(historyRecord); |
| | | |
| | | // è®°å½åºååå¨ |
| | | Dt_StockQuantityChangeRecord changeRecord = new Dt_StockQuantityChangeRecord |
| | | { |
| | | StockDetailId = item.Id, |
| | | PalleCode = stockInfo.PalletCode, |
| | | MaterielCode = item.MaterielCode, |
| | | MaterielName = item.MaterielName, |
| | | BatchNo = item.BatchNo, |
| | | OriginalSerilNumber = item.Barcode, |
| | | NewSerilNumber = "", |
| | | OrderNo = request.OrderNo, |
| | | TaskNum = taskNum, |
| | | ChangeType = (int)StockChangeTypeEnum.Outbound, |
| | | ChangeQuantity = -item.StockQuantity, |
| | | BeforeQuantity = item.StockQuantity, |
| | | AfterQuantity = 0, |
| | | SupplyCode = item.SupplyCode, |
| | | WarehouseCode = item.WarehouseCode, |
| | | Remark = $"æ´ç®±åºåºå®æå é¤åºåæç»ï¼æ¡ç ï¼{request.PalletCode}ï¼åºåºæ°éï¼{item.StockQuantity}ï¼æä½è
ï¼{request.Operator}" |
| | | }; |
| | | changeRecords.Add(changeRecord); |
| | | } |
| | | _stockDetailHistoryRepository.AddData(historyRecords); |
| | | |
| | | // å é¤åºåæç»è®°å½ |
| | | _stockDetailRepository.DeleteData(stockInfo.Details); |
| | | _stockChangeRepository.AddData(changeRecords); |
| | | } |
| | | |
| | | #region æ£é |
| | | /// <summary> |
| | | /// åºåºå®æå¤çï¼æ«ææ¡ç æ£ååºåï¼ |
| | | /// </summary> |
| | |
| | | return WebResponseContent.Instance.Error($"æ æ³åºåºï¼æ¡ç ï¼{request.Barcode}ï¼åºåï¼{stockDetail.StockQuantity}ï¼å·²åºåºï¼{totalAllocatedQuantity}ï¼åé
éï¼{lockInfo.AssignQuantity}ï¼æç»å©ä½ï¼{detailRemainingQuantity}"); |
| | | } |
| | | |
| | | if (actualOutboundQuantity + lockInfo.SortedQuantity > lockInfo.AssignQuantity) |
| | | { |
| | | response.Success = false; |
| | | response.Message = $"æ æ³åºåºï¼æ¡ç ï¼{request.Barcode}ï¼åºåï¼{stockDetail.StockQuantity}ï¼åºåºé{actualOutboundQuantity + lockInfo.SortedQuantity}大äºåé
é{lockInfo.AssignQuantity}"; |
| | | return WebResponseContent.Instance.Error($"æ æ³åºåºï¼æ¡ç ï¼{request.Barcode}ï¼åºåï¼{stockDetail.StockQuantity}ï¼åºåºé{actualOutboundQuantity + lockInfo.SortedQuantity}大äºåé
é{lockInfo.AssignQuantity}"); |
| | | } |
| | | //if (actualOutboundQuantity + lockInfo.SortedQuantity > lockInfo.AssignQuantity) |
| | | //{ |
| | | // response.Success = false; |
| | | // response.Message = $"æ æ³åºåºï¼æ¡ç ï¼{request.Barcode}ï¼åºåï¼{stockDetail.StockQuantity}ï¼åºåºé{actualOutboundQuantity + lockInfo.SortedQuantity}大äºåé
é{lockInfo.AssignQuantity}"; |
| | | // return WebResponseContent.Instance.Error($"æ æ³åºåºï¼æ¡ç ï¼{request.Barcode}ï¼åºåï¼{stockDetail.StockQuantity}ï¼åºåºé{actualOutboundQuantity + lockInfo.SortedQuantity}大äºåé
é{lockInfo.AssignQuantity}"); |
| | | //} |
| | | |
| | | // 8. 夿æ¯å¦éè¦æå
ï¼å½åºåºæ°éå°äºåºåæ°éæ¶éè¦æå
ï¼ |
| | | bool isUnpacked = actualOutboundQuantity < stockDetail.StockQuantity; |
| | | string newBarcode = string.Empty; |
| | | List<MaterialCodeReturnDTO> returnDTOs = new List<MaterialCodeReturnDTO>(); |
| | | |
| | | // 9. å¼å¯äºå¡ |
| | | _unitOfWorkManage.BeginTran(); |
| | |
| | | // æ ¹æ®æ¯å¦æå
æ§è¡ä¸åçæä½ |
| | | if (isUnpacked) |
| | | { |
| | | newBarcode = PerformUnpackOperation(stockDetail, stockInfo, actualOutboundQuantity, request, beforeQuantity, lockInfo.TaskNum.GetValueOrDefault()); |
| | | returnDTOs = PerformUnpackOperation(stockDetail, stockInfo, actualOutboundQuantity, request, beforeQuantity, lockInfo.TaskNum.GetValueOrDefault()); |
| | | } |
| | | else |
| | | { |
| | |
| | | // item.OverOutQuantity = item.OrderQuantity - item.MoveQty; |
| | | //} |
| | | |
| | | decimal barcodeQuantity = allocatedQuantity; |
| | | |
| | | if (item.LockQuantity - item.OverOutQuantity >= allocatedQuantity) |
| | | { |
| | | item.OverOutQuantity += allocatedQuantity; |
| | |
| | | } |
| | | else |
| | | { |
| | | barcodeQuantity = item.LockQuantity - item.OverOutQuantity; |
| | | allocatedQuantity -= (item.LockQuantity - item.OverOutQuantity); |
| | | item.OverOutQuantity = item.LockQuantity; |
| | | item.CurrentDeliveryQty = item.LockQuantity; |
| | |
| | | Barcodes barcodes = new Barcodes |
| | | { |
| | | Barcode = request.Barcode, |
| | | Qty = actualOutboundQuantity, |
| | | Qty = barcodeQuantity, |
| | | SupplyCode = stockDetail?.SupplyCode ?? "", |
| | | BatchNo = stockDetail?.BatchNo ?? "", |
| | | Unit = stockDetail?.Unit ?? "" |
| | |
| | | BeforeQuantity = beforeQuantity, |
| | | AfterQuantity = isUnpacked ? actualOutboundQuantity : 0, |
| | | ChangeQuantity = -actualOutboundQuantity, |
| | | IsUnpacked = isUnpacked |
| | | IsUnpacked = isUnpacked, |
| | | MaterialCodes = returnDTOs |
| | | }; |
| | | |
| | | response.Success = true; |
| | | response.Message = isUnpacked ? $"æå
åºåºå®æï¼å·²çææ°æ¡ç ï¼{newBarcode}" : "åºåºå®æ"; |
| | | response.Message = "åºåºå®æ"; |
| | | response.ScannedDetail = scannedDetail; |
| | | response.UpdatedDetails = updateDetails; |
| | | response.NewBarcode = newBarcode; |
| | | |
| | | // æ£æ¥åºåºåæ¯å¦å®æ |
| | | if (CheckOutboundOrderCompleted(request.OrderNo)) |
| | | { |
| | | UpdateOutboundOrderStatus(request.OrderNo, OutOrderStatusEnum.åºåºå®æ.ObjToInt()); |
| | | |
| | | |
| | | //todo: åä¼ MES |
| | | } |
| | |
| | | /// <param name="beforeQuantity"></param> |
| | | /// <param name="taskNum"></param> |
| | | /// <returns></returns> |
| | | private string PerformUnpackOperation(Dt_StockInfoDetail stockDetail, Dt_StockInfo stockInfo, |
| | | private List<MaterialCodeReturnDTO> PerformUnpackOperation(Dt_StockInfoDetail stockDetail, Dt_StockInfo stockInfo, |
| | | decimal actualOutboundQuantity, OutboundCompleteRequestDTO request, decimal beforeQuantity, int taskNum) |
| | | { |
| | | string newBarcode = GenerateNewBarcode(); |
| | | |
| | | string remark = $"æå
è®°å½ï¼åæ¡ç ï¼{request.Barcode}ï¼åæ°éï¼{stockDetail.StockQuantity}ï¼åºåºæ¡ç ï¼{newBarcode}ï¼ åºåºæ°éï¼{actualOutboundQuantity}ï¼ååºæ¡ç ï¼{request.Barcode}ï¼ååºæ°éï¼{stockDetail.StockQuantity - actualOutboundQuantity},æä½è
ï¼{request.Operator}"; |
| | | |
| | | List<Dt_MaterialCodeInfo> materialCodeInfos = CreateMaterialCodeInfos(stockDetail, newBarcode, actualOutboundQuantity, remark); |
| | | |
| | | List<MaterialCodeReturnDTO> returnDTOs = _mapper.Map<List<MaterialCodeReturnDTO>>(materialCodeInfos); |
| | | |
| | | // ä¿ååå§åºåæç»å°åå²è®°å½ |
| | | Dt_StockInfoDetail_Hty originalHistoryRecord = new Dt_StockInfoDetail_Hty |
| | |
| | | }; |
| | | _stockChangeRepository.AddData(unpackChangeRecord); |
| | | |
| | | return newBarcode; |
| | | return returnDTOs; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <param name="stockDetail"></param> |
| | | /// <param name="newBarcode"></param> |
| | | /// <param name="splitQuantity"></param> |
| | | /// <param name="afterQuantity"></param> |
| | | /// <param name="remark"></param> |
| | | /// <returns></returns> |
| | | private List<Dt_MaterialCodeInfo> CreateMaterialCodeInfos(Dt_StockInfoDetail stockDetail, string newBarcode, decimal splitQuantity, string remark) |
| | | { |
| | | List<Dt_MaterialCodeInfo> materialCodeInfos = new List<Dt_MaterialCodeInfo>(); |
| | | |
| | | Dt_MaterielInfo? materielInfo = _basicService.MaterielInfoService.Repository.QueryFirst(x => x.MaterielCode == stockDetail.MaterielCode); |
| | | |
| | | Dt_MaterialCodeInfo outMaterialCodeInfo = new Dt_MaterialCodeInfo() |
| | | { |
| | | AfterQuantity = splitQuantity, |
| | | BatchNo = stockDetail.BatchNo, |
| | | FactoryArea = stockDetail.FactoryArea, |
| | | MaterialName = materielInfo?.MaterielName ?? stockDetail.MaterielName, |
| | | MaterialSpec = materielInfo?.MaterielSpec ?? "", |
| | | MaterialCode = stockDetail.MaterielCode, |
| | | NewBarcode = newBarcode, |
| | | OldBarcode = stockDetail.Barcode, |
| | | OriginalQuantity = stockDetail.StockQuantity, |
| | | PruchaseOrderNo = stockDetail.OrderNo, |
| | | SuplierCode = stockDetail.SupplyCode, |
| | | Unit = stockDetail.Unit, |
| | | Date = DateTime.Now.ToString("yyyy-MM-dd"), |
| | | Remark = remark |
| | | }; |
| | | materialCodeInfos.Add(outMaterialCodeInfo); |
| | | |
| | | Dt_MaterialCodeInfo returnMaterialCodeInfo = new Dt_MaterialCodeInfo() |
| | | { |
| | | AfterQuantity = stockDetail.StockQuantity - splitQuantity, |
| | | BatchNo = stockDetail.BatchNo, |
| | | FactoryArea = stockDetail.FactoryArea, |
| | | MaterialName = materielInfo?.MaterielName ?? stockDetail.MaterielName, |
| | | MaterialSpec = materielInfo?.MaterielSpec ?? "", |
| | | MaterialCode = stockDetail.MaterielCode, |
| | | NewBarcode = stockDetail.Barcode, |
| | | OldBarcode = stockDetail.Barcode, |
| | | OriginalQuantity = stockDetail.StockQuantity, |
| | | PruchaseOrderNo = stockDetail.OrderNo, |
| | | SuplierCode = stockDetail.SupplyCode, |
| | | Unit = stockDetail.Unit, |
| | | Date = DateTime.Now.ToString("yyyy-MM-dd"), |
| | | Remark = remark |
| | | }; |
| | | |
| | | materialCodeInfos.Add(returnMaterialCodeInfo); |
| | | |
| | | _basicService.MaterielCodeInfoService.Repository.AddData(materialCodeInfos); |
| | | return materialCodeInfos; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ´æ°è¯¥æçè¯¥ç©æçææéå®è®°å½ç累计已åºåºæ°é |
| | | /// </summary> |
| | | /// <param name="stockId">åºåID</param> |
| | |
| | | // æ£æ¥æææç»çå·²åºæ°éæ¯å¦é½çäºåæ®æ°é |
| | | return details.All(x => x.OverOutQuantity >= x.OrderQuantity - x.MoveQty); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region å空箱 |
| | | public async Task<WebResponseContent> EmptyBox(string palletCode) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var stock = await _stockInfoRepository.Db.Queryable<Dt_StockInfo>().Includes(x=>x.Details).Where(x => x.PalletCode == palletCode).FirstAsync(); |
| | | |
| | | if (stock == null) |
| | | { |
| | | return content.Error($"æªæ¾å°æç{palletCode}åºåä¿¡æ¯"); |
| | | } |
| | | if (stock.Details.Count > 0) |
| | | { |
| | | return content.Error($"æç{palletCode}è¿åå¨åºåä¿¡æ¯ä¸å
许åèµ°"); |
| | | } |
| | | Dt_StockInfo_Hty stockInfo_Hty = stock.Adapt<Dt_StockInfo_Hty>(); |
| | | stockInfo_Hty.SourceId = stock.Id; |
| | | stockInfo_Hty.OperateType = "å空箱"; |
| | | stockInfo_Hty.InsertTime = DateTime.Now; |
| | | |
| | | _unitOfWorkManage.BeginTran(); |
| | | await _outboundRepository.Db.InsertNav(stockInfo_Hty).IncludesAllFirstLayer().ExecuteCommandAsync(); |
| | | await _stockInfoRepository.DeleteDataByIdAsync(stock.Id); |
| | | _unitOfWorkManage.CommitTran(); |
| | | return content.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region |
| | | public async Task<WebResponseContent> ReturnToWarehouse(string palletCode, string OrderNo, string station) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var stock = await _stockInfoRepository.Db.Queryable<Dt_StockInfo>().Includes(x => x.Details).Where(x => x.PalletCode == palletCode).FirstAsync(); |
| | | |
| | | if (stock == null) |
| | | { |
| | | return content.Error($"æªæ¾å°æç{palletCode}åºåä¿¡æ¯ä¸å
许ååº"); |
| | | } |
| | | |
| | | if (stock.Details.Count <= 0) |
| | | { |
| | | stock.PalletType = (int)PalletTypeEnum.Empty; |
| | | stock.StockStatus = (int)StockStatusEmun.ç»çæå; |
| | | stock.LocationCode = ""; |
| | | } |
| | | else if (stock.Details.Count > 0) |
| | | { |
| | | Dt_OutStockLockInfo lockInfo = _outboundLockInfoRepository.QueryFirst(x => |
| | | x.OrderNo == OrderNo && |
| | | x.StockId == stock.Id && |
| | | x.PalletCode == palletCode); |
| | | |
| | | if (lockInfo != null && lockInfo.SortedQuantity != lockInfo.AssignQuantity) |
| | | { |
| | | return content.Error($"æç{palletCode}åºåæªæ£éå®ä¸å
许ååº"); |
| | | } |
| | | stock.StockStatus = (int)StockStatusEmun.ç»çæå; |
| | | stock.LocationCode = ""; |
| | | } |
| | | |
| | | var task = await _taskRepository.Db.Queryable<Dt_Task>() |
| | | .Where(x => x.PalletCode == palletCode) |
| | | .FirstAsync(); |
| | | |
| | | if (task != null) |
| | | { |
| | | return content.Error($"æç{palletCode}åå¨ä»»å¡ååºå¤±è´¥!"); |
| | | } |
| | | |
| | | // åé
æ°è´§ä½ |
| | | var newLocation = _locationInfoService.AssignLocation(stock.LocationType); |
| | | |
| | | var newTask = new Dt_Task() |
| | | { |
| | | CurrentAddress = stations[station], |
| | | Grade = 0, |
| | | PalletCode = palletCode, |
| | | NextAddress = "", |
| | | OrderNo = OrderNo, |
| | | Roadway = newLocation.RoadwayNo, |
| | | SourceAddress = stations[station], |
| | | TargetAddress = newLocation.LocationCode, |
| | | TaskStatus = (int)TaskStatusEnum.New, |
| | | TaskType = stock.Details.Count > 0 ? (int)TaskTypeEnum.InPick : (int)TaskTypeEnum.InEmpty, |
| | | PalletType = stock.PalletType, |
| | | WarehouseId = stock.WarehouseId |
| | | }; |
| | | _stockInfoRepository.UpdateData(stock); |
| | | _taskRepository.AddData(newTask); |
| | | |
| | | //var moveResult = await _eSSApiService.MoveContainerAsync(new MoveContainerRequest |
| | | //{ |
| | | // slotCode = movestations[station], |
| | | // containerCode = palletCode |
| | | //}); |
| | | return content.OK(); |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | } |
| | | } |