| | |
| | | using SqlSugar; |
| | | 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_Common.TaskEnum; |
| | | using WIDESEA_Core; |
| | | 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; |
| | | using WIDESEA_IOutboundService; |
| | | using WIDESEA_IRecordService; |
| | |
| | | { |
| | | public partial class OutboundService : IOutboundService |
| | | { |
| | | |
| | | private readonly IMapper _mapper; |
| | | public IUnitOfWorkManage _unitOfWorkManage { get; } |
| | | |
| | | public IOutboundOrderDetailService OutboundOrderDetailService { get; } |
| | |
| | | public IOutStockLockInfoService OutboundStockLockInfoService { get; } |
| | | |
| | | private readonly ISqlSugarClient Db; |
| | | private readonly IOutboundOrderDetailService _detailService; |
| | | private readonly IOutboundOrderService _outboundOrderService; |
| | | private readonly IOutStockLockInfoService _outboundLockInfoService; |
| | | private readonly IStockInfoService _stockInfoService; |
| | | private readonly IStockInfoDetailService _stockDetailService; |
| | | private readonly ILocationInfoService _locationInfoService; |
| | | private readonly IStockQuantityChangeRecordService _stockChangeService; |
| | | private readonly IStockInfoDetail_HtyService _stockDetailHistoryService; |
| | | private readonly IBasicService _basicService; |
| | | |
| | | public OutboundService(IUnitOfWorkManage unitOfWorkManage, IOutboundOrderDetailService outboundOrderDetailService, IOutboundOrderService outboundOrderService, IOutStockLockInfoService outboundStockLockInfoService, IStockInfoService stockInfoService, IStockInfoDetailService stockDetailService, ILocationInfoService locationInfoService, IStockQuantityChangeRecordService stockQuantityChangeRecordService, IStockInfoDetail_HtyService stockDetailHistoryService) |
| | | |
| | | private readonly IRepository<Dt_OutboundOrderDetail> _detailRepository; |
| | | private readonly IRepository<Dt_OutboundOrder> _outboundRepository; |
| | | private readonly IRepository<Dt_OutStockLockInfo> _outboundLockInfoRepository; |
| | | private readonly IRepository<Dt_StockInfo> _stockInfoRepository; |
| | | private readonly IRepository<Dt_StockInfoDetail> _stockDetailRepository; |
| | | 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; |
| | | |
| | | 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; |
| | | OutboundOrderService = outboundOrderService; |
| | | OutboundStockLockInfoService = outboundStockLockInfoService; |
| | | _detailService = outboundOrderDetailService; |
| | | _outboundOrderService = outboundOrderService; |
| | | _outboundLockInfoService = outboundStockLockInfoService; |
| | | _stockInfoService = stockInfoService; |
| | | _stockDetailService = stockDetailService; |
| | | _detailRepository = detailRepository; |
| | | _outboundRepository = outboundRepository; |
| | | _outboundLockInfoRepository = outboundLockInfoRepository; |
| | | _stockInfoRepository = stockInfoRepository; |
| | | _stockDetailRepository = stockDetailRepository; |
| | | _locationInfoRepository = basicService.LocationInfoService.Repository; |
| | | _stockChangeRepository = stockChangeRepository; |
| | | _stockDetailHistoryRepository = stockDetailHistoryRepository; |
| | | _basicService = basicService; |
| | | _feedbackMesService = feedbackMesService; |
| | | _taskRepository = taskRepository; |
| | | _locationInfoService = locationInfoService; |
| | | _stockChangeService = stockQuantityChangeRecordService; |
| | | _stockDetailHistoryService = stockDetailHistoryService; |
| | | _eSSApiService = eSSApiService; |
| | | } |
| | | |
| | | #region åºåºåé
|
| | | /// <summary> |
| | | /// 忣åºåºæä½ |
| | | /// </summary> |
| | |
| | | |
| | | pickedDetails.AddRange(materielPickedDetails.PickedDetails); |
| | | |
| | | decimal allallocatedQuantity = materielCalc.UnallocatedQuantity; |
| | | // æ´æ°åºåºåæç»ï¼å¢å é宿°éï¼ä¸å¢å å·²åºæ°éï¼ |
| | | foreach (var detail in materielCalc.Details) |
| | | { |
| | | decimal lockQuantity = (detail.OrderQuantity - detail.OverOutQuantity); |
| | | detail.LockQuantity += lockQuantity; // å¢å é宿°é 䏿´æ° OverOutQuantity å OrderDetailStatusï¼å ä¸ºè¿æ²¡æå®é
åºåº |
| | | if (allallocatedQuantity <= 0) break; |
| | | |
| | | outboundOrderDetails.Add(detail); |
| | | decimal lockQuantity = (detail.OrderQuantity - detail.OverOutQuantity); |
| | | if (lockQuantity < materielCalc.UnallocatedQuantity) |
| | | { |
| | | detail.LockQuantity += lockQuantity; // å¢å é宿°é 䏿´æ° OverOutQuantity å OrderDetailStatusï¼å ä¸ºè¿æ²¡æå®é
åºåº |
| | | outboundOrderDetails.Add(detail); |
| | | materielCalc.UnallocatedQuantity -= lockQuantity; |
| | | } |
| | | else |
| | | { |
| | | detail.LockQuantity += materielCalc.UnallocatedQuantity; |
| | | outboundOrderDetails.Add(detail); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | UpdateOutboundOrderStatus(request.OrderNo, (int)OutOrderStatusEnum.åºåºä¸); |
| | | |
| | | // 4. æ´æ°åºåºåæç»é宿°é |
| | | _detailService.Repository.UpdateData(outboundOrderDetails); |
| | | _detailRepository.UpdateData(outboundOrderDetails); |
| | | |
| | | // 5. æ´æ°åºåç¶æ |
| | | UpdateStockStatus(pickedDetails.Select(x => x.PalletCode).ToList(), StockStatusEmun.åºåºéå®.ObjToInt()); |
| | |
| | | |
| | | // 7. æ´æ°åºå详æ
|
| | | UpdateOutStockLockInfo(outStockLockInfos); |
| | | |
| | | // 8. æ·»å 任塿°æ® |
| | | _taskRepository.AddData(tasks); |
| | | |
| | | _unitOfWorkManage.CommitTran(); |
| | | |
| | |
| | | |
| | | try |
| | | { |
| | | Dt_OutboundOrder outboundOrder = _outboundOrderService.Repository.QueryFirst(x => x.OrderNo == request.OrderNo); |
| | | Dt_OutboundOrder outboundOrder = _outboundRepository.QueryFirst(x => x.OrderNo == request.OrderNo); |
| | | if (outboundOrder == null) |
| | | { |
| | | result.CanOutbound = false; |
| | |
| | | } |
| | | |
| | | result.FactoryArea = outboundOrder.FactoryArea; |
| | | result.IsMultiDetail = request.IsMultiDetail; |
| | | |
| | | // è·åéæ©çåºåºæç» |
| | | List<Dt_OutboundOrderDetail> selectedDetails = _detailService.Repository.QueryData(x => x.OrderId == outboundOrder.Id && request.DetailIds.Contains(x.Id)); |
| | | List<Dt_OutboundOrderDetail> selectedDetails = _detailRepository.QueryData(x => x.OrderId == outboundOrder.Id && request.DetailIds.Contains(x.Id)); |
| | | |
| | | if (outboundOrder.IsBatch == 1) |
| | | { |
| | | 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); |
| | | } |
| | | |
| | | |
| | | if (!selectedDetails.Any()) |
| | | { |
| | |
| | | result.ErrorMessage = $"æªæ¾å°éæ©çåºåºæç»ä¿¡æ¯"; |
| | | return result; |
| | | } |
| | | |
| | | if (selectedDetails.Any(x => x.LockQuantity > x.OrderQuantity - x.MoveQty || x.OverOutQuantity > x.OrderQuantity - x.MoveQty)) |
| | | { |
| | | List<int> selectDetailIds = selectedDetails.Where(x => x.LockQuantity > x.OrderQuantity - x.MoveQty || x.OverOutQuantity > x.OrderQuantity - x.MoveQty).Select(x => x.Id).ToList(); |
| | |
| | | result.OutboundOrder = outboundOrder; |
| | | result.SelectedDetails = selectedDetails; |
| | | |
| | | if (request.IsMultiDetail) |
| | | if (outboundOrder.IsBatch == 0) |
| | | { |
| | | // 夿ç»åºåºï¼æç©æåç»å¤ç |
| | | result.MaterielCalculations = CalcMaterielOutboundQuantities(outboundOrder, selectedDetails.ToList()); |
| | |
| | | return result; |
| | | } |
| | | |
| | | decimal lockQuantity = selectedDetails.Sum(x => x.LockQuantity); |
| | | decimal orderQuantity = selectedDetails.Sum(x => x.OrderQuantity); |
| | | decimal moveQuantity = selectedDetails.Sum(x => x.MoveQty); |
| | | decimal overQuantity = selectedDetails.Sum(x => x.OverOutQuantity); |
| | | |
| | | Dt_OutboundOrderDetail? singleDetail = selectedDetails.First(); |
| | | |
| | | //夿å¯åºåºæ°é |
| | | if (singleDetail.OrderQuantity - singleDetail.LockQuantity - singleDetail.MoveQty <= 0) |
| | | if (orderQuantity - lockQuantity - moveQuantity < request.OutboundQuantity.Value || orderQuantity - overQuantity - moveQuantity < request.OutboundQuantity.Value) |
| | | { |
| | | result.CanOutbound = false; |
| | | result.ErrorMessage = $"æ¬æ¬¡åºåºæ°é {request.OutboundQuantity.Value} è¶
è¿å¯åºåºæ°é {singleDetail.OrderQuantity - singleDetail.LockQuantity - singleDetail.MoveQty}"; |
| | | result.ErrorMessage = $"æ¬æ¬¡åºåºæ°é {request.OutboundQuantity.Value} è¶
è¿å¯åºåºæ°é {orderQuantity - lockQuantity - moveQuantity}"; |
| | | 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 |
| | |
| | | BatchNo = singleDetail.BatchNo, |
| | | SupplyCode = singleDetail.SupplyCode, |
| | | WarehouseCode = singleDetail.WarehouseCode, |
| | | TotalOrderQuantity = singleDetail.OrderQuantity - singleDetail.MoveQty, |
| | | TotalOverOutQuantity = singleDetail.OverOutQuantity, |
| | | AssignedQuantity = singleDetail.LockQuantity, |
| | | UnallocatedQuantity = singleDetail.OrderQuantity - singleDetail.LockQuantity - singleDetail.MoveQty, |
| | | MovedQuantity = singleDetail.MoveQty, |
| | | Details = new List<Dt_OutboundOrderDetail>() { singleDetail } |
| | | TotalOrderQuantity = orderQuantity - moveQuantity, |
| | | TotalOverOutQuantity = overQuantity, |
| | | AssignedQuantity = lockQuantity, |
| | | UnallocatedQuantity = request.OutboundQuantity.Value, |
| | | MovedQuantity = moveQuantity, |
| | | Details = outboundOrderDetails |
| | | } |
| | | }; |
| | | |
| | | outboundOrder.Details = outboundOrderDetails; |
| | | } |
| | | |
| | | result.CanOutbound = true; |
| | |
| | | UnallocatedQuantity = g.Sum(x => x.OrderQuantity - x.LockQuantity - x.MoveQty), |
| | | MovedQuantity = g.Sum(x => x.MoveQty), |
| | | Details = g.ToList(), |
| | | OutStockLockInfos = _outboundLockInfoService.Repository.QueryData(x => x.MaterielCode == g.Key.MaterielCode && x.BatchNo == g.Key.BatchNo && x.OrderType == (int)outboundOrder.OrderType && x.OrderNo == outboundOrder.OrderNo) |
| | | OutStockLockInfos = _outboundLockInfoRepository.QueryData(x => x.MaterielCode == g.Key.MaterielCode && x.BatchNo == g.Key.BatchNo && x.OrderType == (int)outboundOrder.OrderType && x.OrderNo == outboundOrder.OrderNo) |
| | | }) |
| | | .ToList(); |
| | | |
| | |
| | | private List<Dt_StockInfo> BuildStockQueryWithInfo(MaterielOutboundCalculationDTO materielCalc, string factoryArea) |
| | | { |
| | | // åºç¡æ¥è¯¢æ¡ä»¶ï¼ç©æç¼å·ãæ¹æ¬¡å·ï¼å¦ææä¾ï¼ãåºåæ°é>0 |
| | | ISugarQueryable<Dt_StockInfoDetail> stockDetails = _stockDetailService.Repository.Db.Queryable<Dt_StockInfoDetail>().Where(x => x.MaterielCode == materielCalc.MaterielCode && x.StockQuantity > 0); |
| | | ISugarQueryable<Dt_StockInfoDetail> stockDetails = _stockDetailRepository.Db.Queryable<Dt_StockInfoDetail>().Where(x => x.MaterielCode == materielCalc.MaterielCode && x.StockQuantity > 0); |
| | | |
| | | // æ ¹æ®æ¡ä»¶æ·»å ä¾åºåç¼å·å¹é
ï¼ä¸ä¸ºç©ºæ¶æéè¦å¹é
ï¼ |
| | | if (!string.IsNullOrEmpty(materielCalc.SupplyCode)) |
| | |
| | | List<Dt_StockInfoDetail> stockDetailList = stockDetails.ToList(); |
| | | |
| | | // è·åå¯ç¨è´§ä½ç¼å· |
| | | List<string> locationCodes = _locationInfoService.Repository.QueryData(x => (x.LocationStatus == LocationStatusEnum.InStock.ObjToInt() /*|| x.LocationStatus == LocationStatusEnum.Lock.ObjToInt()*/) && x.EnableStatus == EnableStatusEnum.Normal.ObjToInt()).Select(x => x.LocationCode).ToList(); |
| | | List<string> locationCodes = _locationInfoRepository.QueryData(x => (x.LocationStatus == LocationStatusEnum.InStock.ObjToInt() /*|| x.LocationStatus == LocationStatusEnum.Lock.ObjToInt()*/) && x.EnableStatus == EnableStatusEnum.Normal.ObjToInt()).Select(x => x.LocationCode).ToList(); |
| | | |
| | | // è·åææç¸å
³çåºåä¿¡æ¯ |
| | | List<int> stockIds = stockDetailList.GroupBy(x => x.StockId).Select(x => x.Key).ToList(); |
| | | List<Dt_StockInfo> stockInfos = _stockInfoService.Repository.QueryData(x => stockIds.Contains(x.Id) && (x.StockStatus == StockStatusEmun.å
¥åºå®æ.ObjToInt() /*|| x.StockStatus == StockStatusEmun.åºåºéå®.ObjToInt()*/) && !string.IsNullOrEmpty(x.LocationCode) && locationCodes.Contains(x.LocationCode)); |
| | | List<Dt_StockInfo> stockInfos = _stockInfoRepository.QueryData(x => stockIds.Contains(x.Id) && (x.StockStatus == StockStatusEmun.å
¥åºå®æ.ObjToInt() /*|| x.StockStatus == StockStatusEmun.åºåºéå®.ObjToInt()*/) && !string.IsNullOrEmpty(x.LocationCode) && locationCodes.Contains(x.LocationCode)); |
| | | |
| | | // å¨å
åä¸å
³èæ°æ® |
| | | foreach (var stockInfo in stockInfos) |
| | |
| | | private decimal CalcTotalAllocatedQuantity(List<Dt_OutStockLockInfo> lockInfos, int stockId, string materielCode) |
| | | { |
| | | // æ¥è¯¢è¯¥æçè¯¥ç©æå¨ææéå®è®°å½ä¸çæå¤§å·²åé
æ°é |
| | | List<Dt_OutStockLockInfo> lockRecords = _outboundLockInfoService.Repository.QueryData(x => |
| | | List<Dt_OutStockLockInfo> lockRecords = _outboundLockInfoRepository.QueryData(x => |
| | | x.StockId == stockId && |
| | | x.MaterielCode == materielCode); |
| | | |
| | |
| | | { |
| | | try |
| | | { |
| | | Dt_OutboundOrder outboundOrder = _outboundOrderService.Repository.QueryFirst(x => x.OrderNo == orderNo); |
| | | Dt_OutboundOrder outboundOrder = _outboundRepository.QueryFirst(x => x.OrderNo == orderNo); |
| | | if (outboundOrder == null) return false; |
| | | |
| | | outboundOrder.OrderStatus = status; |
| | | _outboundOrderService.Repository.UpdateData(outboundOrder); |
| | | _outboundRepository.UpdateData(outboundOrder); |
| | | return true; |
| | | } |
| | | catch |
| | |
| | | { |
| | | try |
| | | { |
| | | List<Dt_StockInfo> stockInfos = _stockInfoService.Repository.QueryData(x => palletCodes.Contains(x.PalletCode)); |
| | | List<Dt_StockInfo> stockInfos = _stockInfoRepository.QueryData(x => palletCodes.Contains(x.PalletCode)); |
| | | stockInfos.ForEach(stockInfo => |
| | | { |
| | | stockInfo.StockStatus = status; |
| | | }); |
| | | |
| | | _stockInfoService.Repository.UpdateData(stockInfos); |
| | | _stockInfoRepository.UpdateData(stockInfos); |
| | | return true; |
| | | } |
| | | catch |
| | |
| | | { |
| | | try |
| | | { |
| | | List<Dt_LocationInfo> locationInfos = _locationInfoService.Repository.QueryData(x => locationCodes.Contains(x.LocationCode)); |
| | | List<Dt_LocationInfo> locationInfos = _locationInfoRepository.QueryData(x => locationCodes.Contains(x.LocationCode)); |
| | | locationInfos.ForEach(x => |
| | | { |
| | | x.LocationStatus = status; |
| | | }); |
| | | |
| | | _locationInfoService.Repository.UpdateData(locationInfos); |
| | | _locationInfoRepository.UpdateData(locationInfos); |
| | | return true; |
| | | } |
| | | catch |
| | |
| | | try |
| | | { |
| | | List<Dt_OutStockLockInfo> updateData = outStockLockInfos.Where(x => x.Id > 0).ToList(); |
| | | _outboundLockInfoService.Repository.UpdateData(updateData); |
| | | _outboundLockInfoRepository.UpdateData(updateData); |
| | | |
| | | List<Dt_OutStockLockInfo> addData = outStockLockInfos.Where(x => x.Id <= 0).ToList(); |
| | | _outboundLockInfoService.Repository.AddData(addData); |
| | | _outboundLockInfoRepository.AddData(addData); |
| | | |
| | | return 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> |
| | |
| | | try |
| | | { |
| | | // 1. æ ¹æ®æçå·æ¥æ¾åºåä¿¡æ¯ |
| | | Dt_StockInfo stockInfo = _stockInfoService.Repository.QueryFirst(x => x.PalletCode == request.PalletCode); |
| | | Dt_StockInfo stockInfo = _stockInfoRepository.QueryFirst(x => x.PalletCode == request.PalletCode); |
| | | if (stockInfo == null) |
| | | { |
| | | response.Success = false; |
| | |
| | | } |
| | | |
| | | // 2. æ ¹æ®æ¡ç æ¥æ¾åºåæç» |
| | | Dt_StockInfoDetail stockDetail = _stockDetailService.Repository.QueryFirst(x => x.Barcode == request.Barcode); |
| | | Dt_StockInfoDetail stockDetail = _stockDetailRepository.QueryFirst(x => x.Barcode == request.Barcode); |
| | | if (stockDetail == null) |
| | | { |
| | | response.Success = false; |
| | |
| | | } |
| | | |
| | | // 4. æ¥æ¾åºåºåä¿¡æ¯ |
| | | Dt_OutboundOrder outboundOrder = _outboundOrderService.Repository.QueryFirst(o => o.OrderNo == request.OrderNo); |
| | | Dt_OutboundOrder outboundOrder = _outboundRepository.QueryFirst(o => o.OrderNo == request.OrderNo); |
| | | if (outboundOrder == null) |
| | | { |
| | | response.Success = false; |
| | |
| | | } |
| | | |
| | | // 5. æ¥æ¾éå®è®°å½ |
| | | Dt_OutStockLockInfo lockInfo = _outboundLockInfoService.Repository.QueryFirst(x => |
| | | Dt_OutStockLockInfo lockInfo = _outboundLockInfoRepository.QueryFirst(x => |
| | | x.OrderNo == request.OrderNo && |
| | | x.StockId == stockInfo.Id && |
| | | x.MaterielCode == stockDetail.MaterielCode && |
| | |
| | | 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 |
| | | { |
| | |
| | | { |
| | | if (allocatedQuantity <= 0) break; |
| | | |
| | | if (item.OrderQuantity - item.MoveQty - item.OverOutQuantity >= allocatedQuantity) |
| | | |
| | | //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; |
| | | //} |
| | | |
| | | decimal barcodeQuantity = allocatedQuantity; |
| | | |
| | | if (item.LockQuantity - item.OverOutQuantity >= allocatedQuantity) |
| | | { |
| | | item.OverOutQuantity += allocatedQuantity; |
| | | item.CurrentDeliveryQty += allocatedQuantity; |
| | | allocatedQuantity = 0; |
| | | } |
| | | else |
| | | { |
| | | allocatedQuantity -= (item.OrderQuantity - item.MoveQty - item.OverOutQuantity); |
| | | item.OverOutQuantity = item.OrderQuantity - item.MoveQty; |
| | | barcodeQuantity = item.LockQuantity - item.OverOutQuantity; |
| | | allocatedQuantity -= (item.LockQuantity - item.OverOutQuantity); |
| | | item.OverOutQuantity = item.LockQuantity; |
| | | item.CurrentDeliveryQty = item.LockQuantity; |
| | | } |
| | | |
| | | updateDetails.Add(item); |
| | | |
| | | List<Barcodes> barcodesList = new List<Barcodes>(); |
| | | Barcodes barcodes = new Barcodes |
| | | { |
| | | Barcode = request.Barcode, |
| | | Qty = barcodeQuantity, |
| | | SupplyCode = stockDetail?.SupplyCode ?? "", |
| | | BatchNo = stockDetail?.BatchNo ?? "", |
| | | Unit = stockDetail?.Unit ?? "" |
| | | }; |
| | | if (!string.IsNullOrEmpty(item.ReturnJsonData)) |
| | | { |
| | | barcodesList = JsonConvert.DeserializeObject<List<Barcodes>>(item.ReturnJsonData) ?? new List<Barcodes>(); |
| | | } |
| | | barcodesList.Add(barcodes); |
| | | JsonSerializerSettings settings = new JsonSerializerSettings |
| | | { |
| | | ContractResolver = new CamelCasePropertyNamesContractResolver() |
| | | }; |
| | | item.ReturnJsonData = JsonConvert.SerializeObject(barcodesList, settings); |
| | | } |
| | | |
| | | lockInfo.SortedQuantity = lockInfo.SortedQuantity + actualOutboundQuantity; |
| | | |
| | | if (lockInfo.SortedQuantity == lockInfo.AssignQuantity) |
| | | { |
| | | _outboundLockInfoService.Repository.DeleteAndMoveIntoHty(lockInfo, WIDESEA_Core.Enums.OperateTypeEnum.èªå¨å®æ); |
| | | _outboundLockInfoRepository.DeleteAndMoveIntoHty(lockInfo, WIDESEA_Core.Enums.OperateTypeEnum.èªå¨å®æ); |
| | | } |
| | | else |
| | | { |
| | | // æ´æ°éå®è®°å½ |
| | | _outboundLockInfoService.Repository.UpdateData(lockInfo); |
| | | _outboundLockInfoRepository.UpdateData(lockInfo); |
| | | } |
| | | |
| | | // æ´æ°åºåºåæç»çå·²åºåºæ°é |
| | | _detailService.Repository.UpdateData(updateDetails); |
| | | _detailRepository.UpdateData(updateDetails); |
| | | |
| | | // æ´æ°éå®è®°å½ç累计已åºåºæ°éï¼éè¦æ´æ°è¯¥æçè¯¥ç©æçææç¸å
³è®°å½ï¼ |
| | | //UpdateLockInfoAllocatedQuantity(stockInfo.Id, stockDetail.MaterielCode, stockDetail.BatchNo, actualOutboundQuantity); |
| | |
| | | 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 |
| | | } |
| | |
| | | /// <returns></returns> |
| | | private List<Dt_OutboundOrderDetail> FindMatchingOutboundDetails(int orderId, Dt_StockInfoDetail stockDetail, List<int> detailIds) |
| | | { |
| | | List<Dt_OutboundOrderDetail> details = _detailService.Repository.QueryData(x => |
| | | List<Dt_OutboundOrderDetail> details = _detailRepository.QueryData(x => |
| | | x.OrderId == orderId && |
| | | x.MaterielCode == stockDetail.MaterielCode && x.OrderQuantity - x.MoveQty > x.OverOutQuantity && detailIds.Contains(x.Id)); |
| | | |
| | |
| | | stockDetail.StockQuantity); |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// æ§è¡æå
æä½ |
| | | /// </summary> |
| | |
| | | /// <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 |
| | |
| | | WarehouseCode = stockDetail.WarehouseCode, |
| | | Remark = $"æå
ååå§è®°å½ï¼åæ¡ç ï¼{request.Barcode}ï¼åæ°éï¼{stockDetail.StockQuantity}ï¼åºåºæ°éï¼{actualOutboundQuantity}ï¼æä½è
ï¼{request.Operator}" |
| | | }; |
| | | _stockDetailHistoryService.Repository.AddData(originalHistoryRecord); |
| | | _stockDetailHistoryRepository.AddData(originalHistoryRecord); |
| | | |
| | | // ä¿åå©ä½é¨åå°åå²è®°å½ |
| | | decimal remainingQuantity = stockDetail.StockQuantity - actualOutboundQuantity; |
| | |
| | | stockDetail.StockQuantity = remainingQuantity; |
| | | //stockDetail.Barcode = newBarcode; |
| | | stockDetail.Remark = $"æå
åæ´æ°ï¼åæ¡ç ï¼{request.Barcode}ï¼æ°æ°éï¼{remainingQuantity}ï¼æä½è
ï¼{request.Operator}"; |
| | | _stockDetailService.Repository.UpdateData(stockDetail); |
| | | _stockDetailRepository.UpdateData(stockDetail); |
| | | } |
| | | |
| | | // è®°å½æå
åå¨ |
| | |
| | | WarehouseCode = stockDetail.WarehouseCode, |
| | | Remark = $"æå
åºåºï¼åæ¡ç ï¼{request.Barcode}ï¼æ°æ¡ç ï¼{newBarcode}ï¼åºåºæ°éï¼{actualOutboundQuantity}ï¼å©ä½ï¼{remainingQuantity}ï¼æä½è
ï¼{request.Operator}" |
| | | }; |
| | | _stockChangeService.Repository.AddData(unpackChangeRecord); |
| | | _stockChangeRepository.AddData(unpackChangeRecord); |
| | | |
| | | return newBarcode; |
| | | return returnDTOs; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | WarehouseCode = stockDetail.WarehouseCode, |
| | | Remark = $"åºåºå®æå é¤ï¼æ¡ç ï¼{request.Barcode}ï¼åæ°éï¼{stockDetail.StockQuantity}ï¼åºåºæ°éï¼{actualOutboundQuantity}ï¼æä½è
ï¼{request.Operator}" |
| | | }; |
| | | _stockDetailHistoryService.Repository.AddData(historyRecord); |
| | | _stockDetailHistoryRepository.AddData(historyRecord); |
| | | |
| | | // å é¤åºåæç»è®°å½ |
| | | _stockDetailService.Repository.DeleteData(stockDetail); |
| | | _stockDetailRepository.DeleteData(stockDetail); |
| | | |
| | | // è®°å½åºååå¨ |
| | | Dt_StockQuantityChangeRecord changeRecord = new Dt_StockQuantityChangeRecord |
| | |
| | | WarehouseCode = stockDetail.WarehouseCode, |
| | | Remark = $"åºåºå®æå é¤åºåæç»ï¼æ¡ç ï¼{request.Barcode}ï¼åºåºæ°éï¼{actualOutboundQuantity}ï¼æä½è
ï¼{request.Operator}" |
| | | }; |
| | | _stockChangeService.Repository.AddData(changeRecord); |
| | | _stockChangeRepository.AddData(changeRecord); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | // ä½¿ç¨æ¶é´æ³åéæºæ°çæå¯ä¸æ¡ç |
| | | string newBarcode = string.Empty; |
| | | |
| | | //todo éæ°çææ¡ç é»è¾ |
| | | newBarcode = _basicService.CreateCodeByRule(RuleCodeEnum.NewBarcodeRule.ToString()); |
| | | |
| | | return newBarcode; |
| | | } |
| | | |
| | | /// <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> |
| | |
| | | private void UpdateLockInfoAllocatedQuantity(int stockId, string materielCode, string batchNo, decimal actualOutboundQuantity) |
| | | { |
| | | // æ¥è¯¢è¯¥æçè¯¥ç©æçææéå®è®°å½ |
| | | List<Dt_OutStockLockInfo> lockRecords = _outboundLockInfoService.Repository.QueryData(x => |
| | | List<Dt_OutStockLockInfo> lockRecords = _outboundLockInfoRepository.QueryData(x => |
| | | x.StockId == stockId && |
| | | x.MaterielCode == materielCode && |
| | | x.BatchNo == batchNo); |
| | |
| | | } |
| | | |
| | | // æ¹éæ´æ° |
| | | _outboundLockInfoService.Repository.UpdateData(lockRecords); |
| | | _outboundLockInfoRepository.UpdateData(lockRecords); |
| | | } |
| | | } |
| | | |
| | |
| | | /// </summary> |
| | | public bool CheckOutboundOrderCompleted(string orderNo) |
| | | { |
| | | Dt_OutboundOrder outboundOrder = _outboundOrderService.Repository.QueryFirst(x => x.OrderNo == orderNo); |
| | | Dt_OutboundOrder outboundOrder = _outboundRepository.QueryFirst(x => x.OrderNo == orderNo); |
| | | if (outboundOrder == null) return false; |
| | | |
| | | List<Dt_OutboundOrderDetail> details = _detailService.Repository.QueryData(x => x.OrderId == outboundOrder.Id); |
| | | List<Dt_OutboundOrderDetail> details = _detailRepository.QueryData(x => x.OrderId == outboundOrder.Id); |
| | | |
| | | // æ£æ¥æææç»çå·²åºæ°éæ¯å¦é½çäºåæ®æ°é |
| | | return details.All(x => x.OverOutQuantity >= x.OrderQuantity); |
| | | 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 |
| | | } |
| | | } |