| | |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEA_Common.LocationEnum; |
| | | using WIDESEA_Common.MaterielEnum; |
| | | using WIDESEA_Core; |
| | | using WIDESEA_Core.BaseServices; |
| | |
| | | using WIDESEA_IRecordService; |
| | | using WIDESEA_IStockService; |
| | | using WIDESEA_Model.Models; |
| | | using WIDESEA_OutboundRepository; |
| | | |
| | | namespace WIDESEA_OutboundService |
| | | { |
| | |
| | | private IOutStockLockInfoService _outStockLockInfoService; |
| | | private IBasicService _basicService; |
| | | private ILocationStatusChangeRecordService _locationStatusChangeRecordService; |
| | | private IOutboundRepository _outboundRepository; |
| | | private readonly IMapper _mapper; |
| | | |
| | | public OutMESOrderService(IOutMESOrderRepository BaseDal,IBasicRepository basicRepository, IStockService stockService, IOutStockLockInfoService outStockLockInfoService, IBasicService basicService, ILocationStatusChangeRecordService locationStatusChangeRecordService,IMapper mapper) : base(BaseDal) |
| | | public OutMESOrderService(IOutMESOrderRepository BaseDal,IBasicRepository basicRepository, IStockService stockService, IOutStockLockInfoService outStockLockInfoService, IBasicService basicService, ILocationStatusChangeRecordService locationStatusChangeRecordService,IMapper mapper, IOutboundRepository outboundRepository) : base(BaseDal) |
| | | { |
| | | _basicRepository = basicRepository; |
| | | _stockService = stockService; |
| | | _outStockLockInfoService = outStockLockInfoService; |
| | | _basicService = basicService; |
| | | _locationStatusChangeRecordService = locationStatusChangeRecordService; |
| | | _outboundRepository = outboundRepository; |
| | | _mapper = mapper; |
| | | } |
| | | List<string> GradeCodes = new List<string> |
| | | { |
| | | "001" |
| | | }; |
| | | /// <summary> |
| | | /// æ¥æ¶MESé¢æè®¡å |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public WebResponseContent ReceiveOutBound(OutMESOrderDTO outMESOrderDTO) |
| | | public WebResponseContent ReceiveOutBound(List<OutMESOrderDTO> outMESOrderDTOs) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | if (outMESOrderDTO==null) |
| | | if (outMESOrderDTOs==null || outMESOrderDTOs.Count <= 0) |
| | | { |
| | | return content.Error("é¢æè®¡åä¼ å
¥ä¿¡æ¯ä¸ºç©º"); |
| | | } |
| | | if (outMESOrderDTO.OutDetailId <= 0) |
| | | outMESOrderDTOs.Select(x => x.OutDetailId); |
| | | List<Dt_Warehouse> warehouses = _basicRepository.WarehouseRepository.QueryData(); |
| | | OutMESOrderDTO? CheckGradeCode = outMESOrderDTOs.FirstOrDefault(x => !GradeCodes.Contains(x.GradeCode)); |
| | | if (CheckGradeCode != null) |
| | | { |
| | | return content.Error($"é¢æè®¡å{nameof(OutMESOrderDTO.OutDetailId)}:{outMESOrderDTO.OutDetailId}éè¦å¤§äº0"); |
| | | return content.Error($"é¢æè®¡ååºåº{nameof(OutMESOrderDTO.GradeCode)}:{CheckGradeCode.GradeCode}ä¸åå¨"); |
| | | } |
| | | if (outMESOrderDTO.ReqQuantity <= 0) |
| | | OutMESOrderDTO? CheckOutDetailId = outMESOrderDTOs.FirstOrDefault(x => x.OutDetailId <= 0); |
| | | if (CheckOutDetailId != null) |
| | | { |
| | | return content.Error($"é¢æè®¡å{nameof(OutMESOrderDTO.ReqQuantity)}:{outMESOrderDTO.ReqQuantity}éè¦å¤§äº0"); |
| | | return content.Error($"é¢æè®¡å{nameof(OutMESOrderDTO.OutDetailId)}:{CheckOutDetailId.ProductOrderNo}éè¦å¤§äº0"); |
| | | } |
| | | OutMESOrderDTO? CheckReqQuantity = outMESOrderDTOs.FirstOrDefault(x => x.ReqQuantity <= 0); |
| | | if (CheckReqQuantity != null) |
| | | { |
| | | return content.Error($"é¢æè®¡å{nameof(OutMESOrderDTO.ReqQuantity)}:{CheckReqQuantity.ProductOrderNo}éè¦å¤§äº0"); |
| | | } |
| | | //è·åææç©æä¿¡æ¯ |
| | | List<Dt_MaterielInfo> materielInfos = _basicRepository.MaterielInfoRepository.QueryData(x=>x.MaterielInvOrgId==MaterielInvOrgEnum.æ°å.ObjToInt()); |
| | | //è·åææä¸´æè®¡å |
| | | //è·åææé¢æè®¡å |
| | | List<Dt_OutMESOrder> outMESOrders = BaseDal.QueryData(); |
| | | Dt_MaterielInfo? ExistmaterielInfo = materielInfos.FirstOrDefault(x=>x.MaterielCode== outMESOrderDTO.MaterialCode); |
| | | if (ExistmaterielInfo == null) |
| | | OutMESOrderDTO? CheckMaterialCode = outMESOrderDTOs.FirstOrDefault(x=> !materielInfos.Select(x=>x.MaterielCode).Contains(x.MaterialCode)); |
| | | if (CheckMaterialCode != null) |
| | | { |
| | | return content.Error($"ç©æç¼ç {nameof(OutMESOrderDTO.MaterialCode)}:{outMESOrderDTO.MaterialCode}ä¿¡æ¯ä¸åå¨"); |
| | | return content.Error($"ç©æç¼ç {nameof(OutMESOrderDTO.MaterialCode)}:{CheckMaterialCode.MaterialCode}ä¿¡æ¯ä¸åå¨"); |
| | | } |
| | | Dt_OutMESOrder? OldoutMESOrder = outMESOrders.FirstOrDefault(x=>x.OutDetailId==outMESOrderDTO.OutDetailId); |
| | | Dt_OutMESOrder? OldoutMESOrder = outMESOrders.FirstOrDefault(x=> outMESOrderDTOs.Select(x=>x.OutDetailId).Contains(x.OutDetailId)); |
| | | if (OldoutMESOrder!=null) |
| | | { |
| | | return content.Error($"é¢æè®¡å{nameof(OutMESOrderDTO.OutDetailId)}:{outMESOrderDTO.OutDetailId}ä¿¡æ¯å·²åå¨"); |
| | | return content.Error($"é¢æè®¡å{nameof(OutMESOrderDTO.OutDetailId)}:{OldoutMESOrder.OutDetailId}ä¿¡æ¯å·²åå¨"); |
| | | } |
| | | return content.Error($"é¢æè®¡å{nameof(OutMESOrderDTO.ProductOrderNo)}:{outMESOrderDTO.ProductOrderNo},ç©æ{outMESOrderDTO.MaterialCode}æ å¯åé
åºå"); |
| | | |
| | | Dt_OutMESOrder outMESOrder = _mapper.Map<Dt_OutMESOrder>(outMESOrderDTO); |
| | | List<Dt_OutMESOrder> outMESOrder = outMESOrderDTOs.Select(x=> _mapper.Map<Dt_OutMESOrder>(x)).ToList(); |
| | | foreach (var item in outMESOrder) |
| | | { |
| | | Dt_MaterielInfo materielInfo = materielInfos.FirstOrDefault(x=>x.MaterielCode==item.MaterialCode); |
| | | item.WarehouseId = materielInfo.WarehouseId; |
| | | } |
| | | BaseDal.AddData(outMESOrder); |
| | | return content.OK("æ¥æ¶æå"); |
| | | } |
| | |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// åºåºåºååé
åï¼æ´æ°æ°æ®åºæ°æ® |
| | | /// </summary> |
| | | public WebResponseContent LockOutboundStockDataUpdate(List<Dt_StockInfo> stockInfos, List<Dt_OutMESOrder> outboundOrderDetails, List<Dt_OutStockLockInfo> outStockLockInfos, List<Dt_LocationInfo> locationInfos, LocationStatusEnum locationStatus = LocationStatusEnum.Lock, List<Dt_Task>? tasks = null) |
| | | { |
| | | try |
| | | { |
| | | _stockService.StockInfoService.Repository.UpdateData(stockInfos); |
| | | BaseDal.UpdateData(outboundOrderDetails); |
| | | |
| | | List<Dt_OutStockLockInfo> addOutStockLockInfos = outStockLockInfos.Where(x => x.Id == 0).ToList(); |
| | | if (addOutStockLockInfos != null && addOutStockLockInfos.Any()) |
| | | { |
| | | if (tasks != null) |
| | | { |
| | | addOutStockLockInfos.ForEach(x => |
| | | { |
| | | x.TaskNum = tasks.FirstOrDefault(v => v.PalletCode == x.PalletCode)?.TaskNum; |
| | | }); |
| | | } |
| | | |
| | | _outStockLockInfoService.Repository.AddData(addOutStockLockInfos); |
| | | } |
| | | List<Dt_OutStockLockInfo> updateOutStockLockInfos = outStockLockInfos.Where(x => x.Id > 0).ToList(); |
| | | if (updateOutStockLockInfos != null && updateOutStockLockInfos.Any()) |
| | | { |
| | | _outStockLockInfoService.Repository.UpdateData(updateOutStockLockInfos); |
| | | } |
| | | //æ·»å è´§ä½ç¶æ |
| | | _locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfos, locationStatus, LocationChangeType.OutboundAssignLocation, "", tasks?.Select(x => x.TaskNum).ToList()); |
| | | //æ¹éæ´æ°è´§ä½ç¶æ |
| | | _basicService.LocationInfoService.Repository.UpdateLocationStatus(locationInfos, locationStatus); |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// åé
åºå |
| | | /// </summary> |
| | | public (List<Dt_StockInfo>, List<Dt_OutMESOrder>, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) AssignStockOutbound(List<Dt_OutMESOrder> outboundOrders) |
| | | { |
| | | if (!outboundOrders.Any()) |
| | | { |
| | | throw new Exception($"æªæ¾å°åºåºåæç»ä¿¡æ¯"); |
| | | } |
| | | |
| | | List<Dt_StockInfo> outStocks = new List<Dt_StockInfo>(); |
| | | |
| | | //åºåºè¯¦æ
|
| | | List<Dt_OutStockLockInfo> outStockLockInfos = new List<Dt_OutStockLockInfo>(); |
| | | //è´§ä½åå¨ |
| | | List<Dt_LocationInfo> locationInfos = new List<Dt_LocationInfo>(); |
| | | |
| | | foreach (var item in outboundOrders) |
| | | { |
| | | decimal needQuantity = item.ReqQuantity; |
| | | //è·åå¯ç¨åºå |
| | | List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.GetUseableStocks(item.MaterialCode, item.WarehouseId).Where(x => !outStocks.Select(x => x.PalletCode).Contains(x.PalletCode)).ToList(); |
| | | if (!stockInfos.Any()) |
| | | { |
| | | throw new Exception($"æªæ¾å°å¯åé
åºå"); |
| | | } |
| | | //åé
å®é
åºå |
| | | List<Dt_StockInfo> autoAssignStocks = _stockService.StockInfoService.GetOutboundStocks(stockInfos, needQuantity).OrderBy(x => x.StockLength).ToList(); |
| | | //æ·»å åºååé
|
| | | outStocks.AddRange(autoAssignStocks); |
| | | |
| | | //è®¢åæ°é |
| | | decimal orderQuantity = item.ReqQuantity; |
| | | bool assignStop = true; |
| | | while (assignStop) |
| | | { |
| | | //åºåºè®¢åæç»å·²åé
æ°é |
| | | decimal detailAssignQuantity = outStockLockInfos.Where(x => x.OrderDetailId == item.OutDetailId).Sum(x => x.AssignQuantity); |
| | | |
| | | decimal orderDetailNeedQuantity = item.ReqQuantity - detailAssignQuantity; |
| | | |
| | | decimal useStockLength = autoAssignStocks[0].StockLength - autoAssignStocks[0].StockOutLength; |
| | | if (orderDetailNeedQuantity > useStockLength) |
| | | { |
| | | |
| | | //çæè¯¦æ
|
| | | Dt_OutStockLockInfo outStockLockInfo = _outStockLockInfoService.GetOutStockLockInfo(item, autoAssignStocks[0], useStockLength); |
| | | outStockLockInfos.Add(outStockLockInfo); |
| | | item.AssignTotalUsage += useStockLength; |
| | | autoAssignStocks.Remove(autoAssignStocks[0]); |
| | | |
| | | } |
| | | else |
| | | { |
| | | //çæè¯¦æ
|
| | | Dt_OutStockLockInfo outStockLockInfo = _outStockLockInfoService.GetOutStockLockInfo(item, autoAssignStocks[0], orderDetailNeedQuantity); |
| | | outStockLockInfos.Add(outStockLockInfo); |
| | | item.AssignTotalUsage = orderQuantity; |
| | | autoAssignStocks[0].StockOutLength += orderDetailNeedQuantity; |
| | | if (autoAssignStocks[0].StockOutLength == autoAssignStocks[0].StockLength) |
| | | { |
| | | autoAssignStocks.Remove(autoAssignStocks[0]); |
| | | } |
| | | assignStop = false; |
| | | } |
| | | } |
| | | |
| | | locationInfos.AddRange(_basicRepository.LocationInfoRepository.GetLocationInfos(outStocks.Select(x => x.LocationCode).ToList())); |
| | | } |
| | | |
| | | return (outStocks, outboundOrders, outStockLockInfos, locationInfos); |
| | | } |
| | | } |
| | | } |