| | |
| | | private readonly ILocationStatusChangeRecordRepository _locationStatusChangeRecordRepository; |
| | | private readonly IDt_InboundOrderRepository _inboundOrderRepository; |
| | | private readonly IUnitOfWorkManage _unitOfWorkManage; |
| | | private readonly IDt_OutboundOrderRepository _outorderRepository; |
| | | private readonly IDt_OutboundOrderDetailRepository _outorderdetailRepository; |
| | | private readonly IDt_OtherOutboundOrderRepository _OtheroutorderRepository; |
| | | private readonly IDt_OtherOutboundOrderDetailRepository _OtheroutorderdetailRepository; |
| | | private readonly IStockInfoDetailRepository _stockInfoDetailRepository; |
| | | private readonly IDt_TaskService _taskService; |
| | | private readonly ILocationInfoRepository _locationRepository; |
| | |
| | | ILocationStatusChangeRecordRepository locationStatusChangeRecordRepository, |
| | | IDt_InboundOrderRepository inboundOrderRepository, |
| | | IUnitOfWorkManage unitOfWorkManage, |
| | | IDt_OutboundOrderRepository outorderRepository, |
| | | IDt_OutboundOrderDetailRepository outorderdetailRepository, |
| | | IDt_OtherOutboundOrderRepository OtheroutorderRepository, |
| | | IDt_OtherOutboundOrderDetailRepository OtheroutorderdetailRepository, |
| | | IStockInfoDetailRepository stockInfoDetailRepository, |
| | | IDt_TaskService taskService, |
| | | ILocationInfoRepository locationRepository, |
| | |
| | | _locationStatusChangeRecordRepository = locationStatusChangeRecordRepository; |
| | | _inboundOrderRepository = inboundOrderRepository; |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | _outorderRepository = outorderRepository; |
| | | _outorderdetailRepository = outorderdetailRepository; |
| | | _OtheroutorderRepository = OtheroutorderRepository; |
| | | _OtheroutorderdetailRepository = OtheroutorderdetailRepository; |
| | | _stockInfoDetailRepository = stockInfoDetailRepository; |
| | | _taskService = taskService; |
| | | _locationRepository = locationRepository; |
| | |
| | | |
| | | |
| | | #region åºåè§å¾ |
| | | public List<StockSelectViewDTO> GetStockSelectViews(string materielCode) |
| | | public List<StockSelectViewDTO> GetStockSelectViews(GetStockSelectViewDto viewDto) |
| | | { |
| | | var stock = BaseDal.Db.Queryable<DtStockInfo>() |
| | | var stocks = BaseDal.Db.Queryable<DtStockInfo>() |
| | | .Includes(x => x.StockInfoDetails) |
| | | .Includes(x => x.LocationInfo) |
| | | .Where(x => x.LocationInfo.LocationStatus == (int)LocationEnum.InStock && x.LocationInfo.EnalbeStatus == (int)EnableEnum.Enable) |
| | | .Where(x => x.StockInfoDetails.Any(d => d.MaterielCode == materielCode && d.Quantity > 0 && d.Quantity > d.OutboundQuantity)).ToList().OrderBy(x => x.CreateDate); |
| | | .Where(x => x.StockInfoDetails.Any(d => d.MaterielCode == viewDto.materielCode && d.Quantity > 0 && d.Quantity > d.OutboundQuantity)).ToList().OrderBy(x => x.CreateDate); |
| | | |
| | | var result = stock.Select(s => new StockSelectViewDTO |
| | | List<DtLocationInfo> locationInfos = new List<DtLocationInfo>(); |
| | | List<DtStockInfo> stockNew = new List<DtStockInfo>(); |
| | | if (stocks != null || stocks.Count() > 0) |
| | | { |
| | | var locations = stocks.Select(s => s.LocationInfo).ToList(); |
| | | locationInfos = GetStockLocations(locations).Distinct().ToList(); |
| | | stockNew = stocks.Where(s => s.LocationInfo != null && locationInfos.Contains(s.LocationInfo)).ToList(); |
| | | } |
| | | |
| | | var result = stockNew.Select(s => new StockSelectViewDTO |
| | | { |
| | | MaterielCode = s.StockInfoDetails |
| | | .FirstOrDefault(d => d.MaterielCode == materielCode)?.MaterielCode ?? string.Empty, |
| | | .FirstOrDefault(d => d.MaterielCode == viewDto.materielCode)?.MaterielCode ?? string.Empty, |
| | | |
| | | MaterielName = s.StockInfoDetails |
| | | .FirstOrDefault(d => d.MaterielCode == materielCode)?.MaterielName ?? string.Empty, |
| | | .FirstOrDefault(d => d.MaterielCode == viewDto.materielCode)?.MaterielName ?? string.Empty, |
| | | |
| | | UseableQuantity = s.StockInfoDetails |
| | | .Where(d => d.MaterielCode == materielCode && d.Quantity > 0 && d.Quantity > d.OutboundQuantity) |
| | | .Where(d => d.MaterielCode == viewDto.materielCode && d.Quantity > 0 && d.Quantity > d.OutboundQuantity) |
| | | .Sum(d => (decimal?)d.Quantity - d.OutboundQuantity) ?? 0, // å¤çç©ºå¼æ
åµ |
| | | |
| | | PalletCode = s.PalletCode ?? string.Empty, |
| | |
| | | }).ToList(); |
| | | |
| | | return result; |
| | | } |
| | | |
| | | public List<DtLocationInfo> GetStockLocations(List<DtLocationInfo>? locations) |
| | | { |
| | | List<DtLocationInfo> locationsNew = new List<DtLocationInfo>(); |
| | | foreach (var item in locations) |
| | | { |
| | | if (item.AreaId == 1) |
| | | { |
| | | if (item.Depth == 2) |
| | | { |
| | | var locationLateral = _locationRepository.QueryFirst(x => x.Row == 1 && x.Column == item.Column && x.Layer == item.Layer); |
| | | |
| | | if (locationLateral.LocationStatus == (int)LocationEnum.Lock && locationLateral.EnalbeStatus == 1) |
| | | { |
| | | locationsNew.Remove(item); |
| | | continue; |
| | | } |
| | | locationsNew.Add(item); |
| | | } |
| | | } |
| | | else if (item.AreaId == 2) |
| | | { |
| | | var locationLateral = _locationRepository.QueryData(x => x.Row == item.Row && x.Column > item.Column && x.Remark == item.Remark); |
| | | |
| | | foreach (var Lateral in locationLateral) |
| | | { |
| | | if (Lateral.LocationStatus == (int)LocationEnum.Lock && Lateral.EnalbeStatus == 1) |
| | | { |
| | | locationsNew.Remove(item); |
| | | continue; |
| | | } |
| | | locationsNew.Add(item); |
| | | } |
| | | } |
| | | |
| | | else if (item.AreaId == 5 || item.AreaId == 6) |
| | | { |
| | | var locationLateral = _locationRepository.QueryData(x => x.Row == item.Row && x.Column < item.Column && x.Remark == item.Remark); |
| | | |
| | | foreach (var lateral in locationLateral) |
| | | { |
| | | if (lateral.LocationStatus == (int)LocationEnum.Lock && lateral.EnalbeStatus == 1) |
| | | { |
| | | locationsNew.Remove(item); |
| | | continue; |
| | | } |
| | | locationsNew.Add(item); |
| | | } |
| | | } |
| | | } |
| | | return locationsNew; |
| | | } |
| | | |
| | | #endregion |
| | |
| | | foreach (var orderId in requestOut.orderIds) |
| | | { |
| | | List<RequestTaskDto> taskDtos = new List<RequestTaskDto>(); |
| | | Dt_OutboundOrder outboundOrder = _outorderRepository.QueryFirst(x => x.Id == orderId); |
| | | Dt_OtherOutboundOrderDetail outboundOrderdetail = _OtheroutorderdetailRepository.QueryFirst(x => x.Id == orderId); |
| | | Dt_OtherOutboundOrder outboundOrder = _OtheroutorderRepository.QueryFirst(x => x.Id == outboundOrderdetail.OrderId); |
| | | |
| | | (bool, string) checkResult = CheckSelectStockDeital(outboundOrder, requestOut.stockViews, requestOut); |
| | | (bool, string) checkResult = CheckSelectStockDeital(outboundOrderdetail, requestOut.stockViews, requestOut); |
| | | if (!checkResult.Item1) throw new Exception(checkResult.Item2); |
| | | |
| | | else |
| | | { |
| | | var result = AssignStockOutbound(outboundOrder, requestOut.stockViews); |
| | | var result = AssignStockOutbound(outboundOrderdetail, requestOut.stockViews); |
| | | |
| | | if (result.Item1.Count <= 0) |
| | | { |
| | |
| | | { |
| | | TaskType = outboundOrder.OrderType, |
| | | OrderNo = outboundOrder.OrderNo, |
| | | MaterielCode = outboundOrder.MaterielCode, |
| | | MaterielCode = outboundOrderdetail.MaterielCode, |
| | | Position = item.LocationCode, |
| | | PalletCode = item.PalletCode, |
| | | AreaId = Convert.ToInt32(requestOut.AreaId), |
| | | }; |
| | | taskDtos.Add(task); |
| | | item.StockInfoDetails.Where(x => x.MaterielCode == outboundOrder.MaterielCode).FirstOrDefault().Status = (int)StockStateEmun.åºåºéå®; |
| | | item.StockInfoDetails.Where(x => x.MaterielCode == outboundOrderdetail.MaterielCode).FirstOrDefault().Status = (int)StockStateEmun.åºåºéå®; |
| | | item.StockStatus = (int)StockStateEmun.åºåºéå®; |
| | | }); |
| | | List<Dt_Task> taskNews = new List<Dt_Task>(); |
| | |
| | | BaseDal.UpdateDataNav(result.Item1); |
| | | await _locationStatusChangeRecordRepository.AddDataAsync(locationStatusChangeRecords); |
| | | await _locationRepository.UpdateDataAsync(locations); |
| | | _outorderRepository.UpdateData(result.Item2); |
| | | _OtheroutorderdetailRepository.UpdateData(result.Item2); |
| | | }); |
| | | content = await _taskService.SendWCSTask(taskDTOs); |
| | | } |
| | |
| | | Remark = task.Remark |
| | | }; |
| | | } |
| | | public (List<DtStockInfo>, Dt_OutboundOrder) AssignStockOutbound(Dt_OutboundOrder outboundOrder, List<StockSelectViewDTO> stockSelectViews) |
| | | public (List<DtStockInfo>, Dt_OtherOutboundOrderDetail) AssignStockOutbound(Dt_OtherOutboundOrderDetail outboundOrderdetail, List<StockSelectViewDTO> stockSelectViews) |
| | | { |
| | | decimal originalNeedQuantity = outboundOrder.OrderQuantity - outboundOrder.OverOutQuantity; |
| | | decimal originalNeedQuantity = outboundOrderdetail.OrderQuantity - outboundOrderdetail.OverOutQuantity; |
| | | |
| | | decimal needQuantity = originalNeedQuantity; |
| | | |
| | |
| | | } |
| | | else |
| | | { |
| | | outStocks = GetStockInfos(outboundOrder.MaterielCode); |
| | | outStocks = GetStockInfos(outboundOrderdetail.MaterielCode); |
| | | } |
| | | |
| | | List<DtStockInfo> outStockNews=new List<DtStockInfo>(); |
| | |
| | | foreach (var item in outStocks) |
| | | { |
| | | var stockDetail = item.StockInfoDetails |
| | | .Where(d => d.MaterielCode == outboundOrder.MaterielCode && d.Quantity > 0); |
| | | .Where(d => d.MaterielCode == outboundOrderdetail.MaterielCode && d.Quantity > 0); |
| | | if (needQuantity <= 0) |
| | | { |
| | | continue; |
| | |
| | | } |
| | | |
| | | } |
| | | outboundOrder.OverOutQuantity = outboundOrder.OrderQuantity - needQuantity; |
| | | outboundOrder.OrderStatus = (int)OrderStateEmun.å¼å§; |
| | | outboundOrderdetail.OverOutQuantity = outboundOrderdetail.OrderQuantity - needQuantity; |
| | | |
| | | return (outStockNews, outboundOrder); |
| | | if (outboundOrderdetail.OverOutQuantity != 0) |
| | | { |
| | | outboundOrderdetail.OrderDetailStatus = (int)OrderStateEmun.å¼å§; |
| | | } |
| | | return (outStockNews, outboundOrderdetail); |
| | | } |
| | | |
| | | private (bool, string) CheckSelectStockDeital(Dt_OutboundOrder outboundOrder, List<StockSelectViewDTO> stockSelectViews, GenerateOutTaskDto requestOut) |
| | | private (bool, string) CheckSelectStockDeital(Dt_OtherOutboundOrderDetail outboundOrderdetail, List<StockSelectViewDTO> stockSelectViews, GenerateOutTaskDto requestOut) |
| | | { |
| | | if (outboundOrder == null) |
| | | if (outboundOrderdetail == null) |
| | | { |
| | | return (false, "æªæ¾å°åºåºåä¿¡æ¯"); |
| | | } |
| | | if (outboundOrder.OrderStatus == (int)OrderStateEmun.已宿) |
| | | if (outboundOrderdetail.OrderDetailStatus == (int)OrderStateEmun.已宿) |
| | | { |
| | | return (false, "该æç»ä¸å¯æä½"); |
| | | } |
| | | if (stockSelectViews != null && stockSelectViews.Sum(x => x.UseableQuantity) > outboundOrder.OrderQuantity - outboundOrder.OverOutQuantity) |
| | | if (stockSelectViews != null && stockSelectViews.Sum(x => x.UseableQuantity) > outboundOrderdetail.OrderQuantity - outboundOrderdetail.OverOutQuantity) |
| | | { |
| | | return (false, "éæ©æ°éè¶
åºåæ®æ°é"); |
| | | } |
| | | if (outboundOrder.OrderQuantity <= outboundOrder.OverOutQuantity) |
| | | if (outboundOrderdetail.OrderQuantity <= outboundOrderdetail.OverOutQuantity) |
| | | { |
| | | return (false, "åæ®æ°éå·²åºåºå®æ"); |
| | | } |
| | | if (stockSelectViews != null && stockSelectViews.Count > 1 && requestOut.AreaId == null) |
| | | { |
| | | return (false, "åºåºåºå大äºä¸æ¡ä¸è½åºåºè³æå®åºä½!"); |
| | | } |
| | | if ( requestOut.TargetAddress == null && requestOut.AreaId == null) |
| | | { |
| | | return (false, "è¯·éæ©åºåºå°å"); |
| | | } |
| | | if (outboundOrder.OrderStatus == (int)OrderStateEmun.已宿) |
| | | { |
| | | return (false, "该åºåºåå·²å®æï¼æ æ³çæåºåºä»»å¡"); |
| | | } |
| | | return (true, "æå"); |
| | | } |
| | | |
| | | public List<DtStockInfo> GetStockInfos(string materielCode) |
| | | { |
| | | return BaseDal.Db.Queryable<DtStockInfo>() |
| | | var stocks = BaseDal.Db.Queryable<DtStockInfo>() |
| | | .Includes(x => x.StockInfoDetails) |
| | | .Includes(x => x.LocationInfo) |
| | | .Where(x => x.LocationInfo.LocationStatus == (int)LocationEnum.InStock && x.LocationInfo.EnalbeStatus == (int)EnableEnum.Enable) |
| | | .Where(x => x.StockInfoDetails.Any(d => d.MaterielCode == materielCode && d.Quantity > 0)).ToList().OrderBy(x => x.CreateDate).ToList(); |
| | | |
| | | if (stocks == null || stocks.Count() <= 0) |
| | | { |
| | | return stocks; |
| | | } |
| | | |
| | | var locations = stocks.Select(s => s.LocationInfo).ToList(); |
| | | List<DtLocationInfo> locationInfos = GetStockLocations(locations).Distinct().ToList(); |
| | | stocks = stocks.Where(s => s.LocationInfo != null && locationInfos.Contains(s.LocationInfo)).ToList(); |
| | | return stocks; |
| | | } |
| | | #endregion æ ¹æ®åæ®æç»çæåºåºä»»å¡ |
| | | |