| | |
| | | using AngleSharp.Dom; |
| | | using Dm; |
| | | using Mapster; |
| | | using Masuit.Tools; |
| | | using NewLife.Reflection; |
| | |
| | | using WIDESEA_Cache; |
| | | using WIDESEA_Common; |
| | | using WIDESEA_Core; |
| | | using WIDESEA_Core.Enums; |
| | | using WIDESEA_DTO; |
| | | using WIDESEA_DTO.Basic; |
| | | using WIDESEA_DTO.Stock; |
| | | using WIDESEA_DTO.WMS; |
| | | using WIDESEA_IOrderRepository; |
| | | using WIDESEA_Model.Models; |
| | | using WIDESEA_Model.Models.Order; |
| | | using WIDESEA_OrderRepository; |
| | | using WIDESEA_StorageTaskRepository; |
| | | |
| | | namespace WIDESEA_StorageBasicService; |
| | | |
| | |
| | | private readonly IUnitOfWorkManage _unitOfWorkManage; |
| | | private readonly IDt_OutboundOrderRepository _outorderRepository; |
| | | private readonly IDt_OutboundOrderDetailRepository _outorderdetailRepository; |
| | | private readonly IStockInfoDetailRepository _stockInfoDetailRepository; |
| | | private readonly IDt_TaskService _taskService; |
| | | private readonly ILocationInfoRepository _locationRepository; |
| | | private readonly IDt_TaskRepository _taskRepository; |
| | | |
| | | public StockInfoService(IStockInfoRepository BaseDal, |
| | | ILocationStatusChangeRecordRepository locationStatusChangeRecordRepository, |
| | | IDt_InboundOrderRepository inboundOrderRepository, |
| | | IUnitOfWorkManage unitOfWorkManage, |
| | | IDt_OutboundOrderRepository outorderRepository, |
| | | IDt_OutboundOrderDetailRepository outorderdetailRepository) : base(BaseDal) |
| | | IDt_OutboundOrderDetailRepository outorderdetailRepository, |
| | | IStockInfoDetailRepository stockInfoDetailRepository, |
| | | IDt_TaskService taskService, |
| | | ILocationInfoRepository locationRepository, |
| | | IDt_TaskRepository taskRepository) : base(BaseDal) |
| | | { |
| | | _locationStatusChangeRecordRepository = locationStatusChangeRecordRepository; |
| | | _inboundOrderRepository = inboundOrderRepository; |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | _outorderRepository = outorderRepository; |
| | | _outorderdetailRepository = outorderdetailRepository; |
| | | _stockInfoDetailRepository = stockInfoDetailRepository; |
| | | _taskService = taskService; |
| | | _locationRepository = locationRepository; |
| | | _taskRepository = taskRepository; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | return new PageGridData<DtStockInfo>(totalCount, data); |
| | | } |
| | | |
| | | |
| | | #region åºåè§å¾ |
| | | public List<StockSelectViewDTO> GetStockSelectViews(string materielCode) |
| | | { |
| | | var stock = 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); |
| | | .Where(x => x.StockInfoDetails.Any(d => d.MaterielCode == materielCode && d.Quantity > 0 && d.Quantity > d.OutboundQuantity)).ToList().OrderBy(x => x.CreateDate); |
| | | |
| | | var result = stock.Select(s => new StockSelectViewDTO |
| | | { |
| | |
| | | .FirstOrDefault(d => d.MaterielCode == materielCode)?.MaterielName ?? string.Empty, |
| | | |
| | | UseableQuantity = s.StockInfoDetails |
| | | .Where(d => d.MaterielCode == materielCode && d.Quantity > 0) |
| | | .Sum(d => (decimal?)d.Quantity) ?? 0, // å¤çç©ºå¼æ
åµ |
| | | .Where(d => d.MaterielCode == materielCode && d.Quantity > 0 && d.Quantity > d.OutboundQuantity) |
| | | .Sum(d => (decimal?)d.Quantity - d.OutboundQuantity) ?? 0, // å¤çç©ºå¼æ
åµ |
| | | |
| | | PalletCode = s.PalletCode ?? string.Empty, |
| | | LocationCode = s.LocationInfo?.LocationCode ?? string.Empty |
| | |
| | | return result; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region æ ¹æ®åæ®æç»çæåºåºä»»å¡ |
| | | |
| | | public WebResponseContent GenerateOutboundTask(GenerateOutTaskDto requestOut) |
| | | public async Task<WebResponseContent> GenerateOutboundTask(GenerateOutTaskDto requestOut) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | List<RequestTaskDto> taskDtos = new List<RequestTaskDto>(); |
| | | Dt_OutboundOrder outboundOrder = _outorderRepository.QueryFirst(x => x.Id == requestOut.orderId); |
| | | foreach (var orderId in requestOut.orderIds) |
| | | { |
| | | List<RequestTaskDto> taskDtos = new List<RequestTaskDto>(); |
| | | Dt_OutboundOrder outboundOrder = _outorderRepository.QueryFirst(x => x.Id == orderId); |
| | | |
| | | if (outboundOrder == null) |
| | | { |
| | | throw new Exception("æªæ¾å°åºåºåæç»ä¿¡æ¯!"); |
| | | } |
| | | List<DtStockInfo>? stockInfos = null; |
| | | Dt_OutboundOrderDetail? orderDetail = null; |
| | | List<DtLocationInfo>? locationInfos = null; |
| | | if (outboundOrder.OrderStatus != OrderStateEmun.已宿.ObjToInt()) |
| | | { |
| | | return content.Error("该åºåºåå·²å®æï¼æ æ³çæåºåºä»»å¡"); |
| | | } |
| | | else |
| | | { |
| | | if (requestOut.stockViews.Count == 0) |
| | | { |
| | | (bool, string) checkResult = CheckSelectStockDeital(outboundOrder, requestOut.stockViews, requestOut); |
| | | if (!checkResult.Item1) throw new Exception(checkResult.Item2); |
| | | |
| | | } |
| | | else |
| | | { |
| | | foreach (var item in requestOut.stockViews) |
| | | var result = AssignStockOutbound(outboundOrder, requestOut.stockViews); |
| | | |
| | | if (result.Item1.Count <= 0) |
| | | { |
| | | decimal availableQuantity = item.UseableQuantity; |
| | | if (availableQuantity <= 0) |
| | | { |
| | | continue; // æ å¯ç¨åºåï¼ç»§ç»ä¸ä¸ä¸ª |
| | | } |
| | | var stock = BaseDal.QueryFirst(x => x.LocationCode == item.LocationCode && x.PalletCode == item.PalletCode); |
| | | // åå»ºä»»å¡ |
| | | return content.Error("æªæ¾å°åºååé
ï¼è¯·ç¡®è®¤æ¯å¦åå¨åºåæåæ®æ°éå·²åºå®"); |
| | | } |
| | | |
| | | result.Item1.Distinct().ForEach(item => |
| | | { |
| | | RequestTaskDto task = new RequestTaskDto |
| | | { |
| | | TaskType = outboundOrder.OrderStatus, |
| | | TaskType = outboundOrder.OrderType, |
| | | OrderNo = outboundOrder.OrderNo, |
| | | MaterielCode = item.MaterielCode, |
| | | MaterielCode = outboundOrder.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.StockStatus = (int)StockStateEmun.åºåºéå®; |
| | | }); |
| | | List<Dt_Task> taskNews = new List<Dt_Task>(); |
| | | List<WMSTaskDTO> taskDTOs = new List<WMSTaskDTO>(); |
| | | foreach (var item in taskDtos) |
| | | { |
| | | taskNews.Add(await _taskService.RequestOutboundTaskAsync(item)); |
| | | |
| | | } |
| | | List<DtLocationStatusChangeRecord> locationStatusChangeRecords = new List<DtLocationStatusChangeRecord>(); |
| | | List<DtLocationInfo> locations = new List<DtLocationInfo>(); |
| | | foreach (var item in taskNews) |
| | | { |
| | | taskDTOs.Add(CreateTaskDTO(item)); |
| | | var result1 = _taskService.UpdateLocationStatus(item.SourceAddress, LocationEnum.InStockDisable, item.TaskNum.Value, (int)StatusChangeTypeEnum.AutomaticOutbound); |
| | | var result2 = _taskService.UpdateLocationStatus(item.TargetAddress, LocationEnum.Lock, item.TaskNum.Value, (int)StatusChangeTypeEnum.AutomaticOutbound); |
| | | locationStatusChangeRecords.AddRange(result1.Item1); |
| | | locationStatusChangeRecords.AddRange(result2.Item1); |
| | | locations.AddRange(result1.Item2); |
| | | locations.AddRange(result2.Item2); |
| | | } |
| | | |
| | | await _unitOfWorkManage.UseTranAsync(async () => |
| | | { |
| | | _taskRepository.AddData(taskNews); |
| | | BaseDal.UpdateDataNav(result.Item1); |
| | | await _locationStatusChangeRecordRepository.AddDataAsync(locationStatusChangeRecords); |
| | | await _locationRepository.UpdateDataAsync(locations); |
| | | _outorderRepository.UpdateData(result.Item2); |
| | | }); |
| | | content = await _taskService.SendWCSTask(taskDTOs); |
| | | } |
| | | } |
| | | return content.OK("åºåºä»»å¡çææå"); |
| | | return content; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | |
| | | } |
| | | |
| | | } |
| | | private WMSTaskDTO CreateTaskDTO(Dt_Task task) |
| | | { |
| | | return new WMSTaskDTO |
| | | { |
| | | TaskNum = task.TaskNum.Value, |
| | | Grade = task.Grade.Value, |
| | | PalletCode = task.PalletCode, |
| | | RoadWay = task.Roadway, |
| | | SourceAddress = task.SourceAddress, |
| | | TargetAddress = task.TargetAddress, |
| | | TaskState = task.TaskState, |
| | | Id = 0, |
| | | TaskType = task.TaskType, |
| | | AGVTaskNum = task.AGVTaskNum, |
| | | Remark = task.Remark |
| | | }; |
| | | } |
| | | public (List<DtStockInfo>, Dt_OutboundOrder) AssignStockOutbound(Dt_OutboundOrder outboundOrder, List<StockSelectViewDTO> stockSelectViews) |
| | | { |
| | | decimal originalNeedQuantity = outboundOrder.OrderQuantity - outboundOrder.OverOutQuantity; |
| | | |
| | | decimal needQuantity = originalNeedQuantity; |
| | | |
| | | List<DtStockInfo> outStocks = new List<DtStockInfo>(); |
| | | if (stockSelectViews != null && stockSelectViews.Count > 0) |
| | | { |
| | | outStocks = BaseDal.Db.Queryable<DtStockInfo>().Where(x => stockSelectViews.Select(x => x.PalletCode).ToList().Contains(x.PalletCode)).Includes(x => x.StockInfoDetails).ToList(); |
| | | } |
| | | else |
| | | { |
| | | outStocks = GetStockInfos(outboundOrder.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); |
| | | if (needQuantity <= 0) |
| | | { |
| | | continue; |
| | | } |
| | | foreach (var detail in stockDetail) |
| | | { |
| | | if (detail != null) |
| | | { |
| | | if (needQuantity >= detail.Quantity) |
| | | { |
| | | if (detail.Quantity <= detail.OutboundQuantity) |
| | | { |
| | | continue; |
| | | } |
| | | needQuantity -= detail.Quantity; |
| | | detail.OutboundQuantity = detail.Quantity; |
| | | } |
| | | else |
| | | { |
| | | if (detail.Quantity <= detail.OutboundQuantity) |
| | | { |
| | | continue; |
| | | } |
| | | detail.OutboundQuantity = needQuantity; |
| | | needQuantity = 0; |
| | | } |
| | | outStockNews.Add(item); |
| | | } |
| | | } |
| | | |
| | | } |
| | | outboundOrder.OverOutQuantity = outboundOrder.OrderQuantity - needQuantity; |
| | | outboundOrder.OrderStatus = (int)OrderStateEmun.å¼å§; |
| | | |
| | | return (outStockNews, outboundOrder); |
| | | } |
| | | |
| | | private (bool, string) CheckSelectStockDeital(Dt_OutboundOrder outboundOrder, List<StockSelectViewDTO> stockSelectViews, GenerateOutTaskDto requestOut) |
| | | { |
| | | if (outboundOrder == null) |
| | | { |
| | | return (false, "æªæ¾å°åºåºåä¿¡æ¯"); |
| | | } |
| | | if (outboundOrder.OrderStatus == (int)OrderStateEmun.已宿) |
| | | { |
| | | return (false, "该æç»ä¸å¯æä½"); |
| | | } |
| | | if (stockSelectViews != null && stockSelectViews.Sum(x => x.UseableQuantity) > outboundOrder.OrderQuantity - outboundOrder.OverOutQuantity) |
| | | { |
| | | return (false, "éæ©æ°éè¶
åºåæ®æ°é"); |
| | | } |
| | | if (outboundOrder.OrderQuantity <= outboundOrder.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>() |
| | | .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(); |
| | | } |
| | | #endregion æ ¹æ®åæ®æç»çæåºåºä»»å¡ |
| | | |
| | | |
| | | #region ç»ç |
| | | public async Task<WebResponseContent> AddGroupPlateAsync(GroupPlate groupPlate) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | |
| | | return content.Error(ex.Message); |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | #region è§£ç |
| | | public async Task<WebResponseContent> DeleteGroupPlateAsync(GroupPlate groupPlate) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | #endregion |
| | | } |