| | |
| | | using System.Reflection.Emit; |
| | | using System.Threading.Tasks; |
| | | using System.Xml.Linq; |
| | | using WIDESEA_Common.AllocateEnum; |
| | | using WIDESEA_Common.CommonEnum; |
| | | using WIDESEA_Common.LocationEnum; |
| | | using WIDESEA_Common.OrderEnum; |
| | |
| | | using WIDESEA_Core.BaseServices; |
| | | using WIDESEA_Core.Enums; |
| | | using WIDESEA_Core.Helper; |
| | | using WIDESEA_DTO.Allocate; |
| | | using WIDESEA_DTO.Basic; |
| | | using WIDESEA_DTO.Inbound; |
| | | using WIDESEA_DTO.Outbound; |
| | | using WIDESEA_DTO.Task; |
| | | using WIDESEA_IAllocateService; |
| | | using WIDESEA_IBasicService; |
| | | using WIDESEA_IInboundService; |
| | | using WIDESEA_IOutboundService; |
| | |
| | | using WIDESEA_IStockService; |
| | | using WIDESEA_ITaskInfoService; |
| | | using WIDESEA_Model.Models; |
| | | using WIDESEA_Model.Models.Check; |
| | | using WIDESEA_Model.Models.Outbound; |
| | | |
| | | namespace WIDESEA_TaskInfoService |
| | | { |
| | |
| | | private readonly IInboundOrderService _inboundOrderService; |
| | | private readonly IInboundOrderDetailService _inboundOrderDetailService; |
| | | |
| | | private readonly IRepository<Dt_ReCheckOrder> _reCheckOrderRepository; |
| | | private readonly IRepository<Dt_OutboundBatch> _OutboundBatchRepository; |
| | | private readonly IOutboundOrderService _outboundOrderService; |
| | | private readonly IOutboundOrderDetailService _outboundOrderDetailService; |
| | | private readonly IOutStockLockInfoService _outStockLockInfoService; |
| | |
| | | private readonly IESSApiService _eSSApiService; |
| | | private readonly IStockService _stockService; |
| | | private readonly IRecordService _recordService; |
| | | |
| | | private readonly IAllocateService _allocateService; |
| | | private readonly IInvokeMESService _invokeMESService; |
| | | public IRepository<Dt_Task> Repository => BaseDal; |
| | | |
| | |
| | | |
| | | public List<int> TaskOutboundTypes => typeof(TaskTypeEnum).GetEnumIndexList(); |
| | | |
| | | public TaskService(IRepository<Dt_Task> BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IRepository<Dt_StockInfo> stockRepository, ILocationInfoService locationInfoService, IInboundOrderService inboundOrderService, ILocationStatusChangeRecordService locationStatusChangeRecordService, IESSApiService eSSApiService, ILogger<TaskService> logger, IStockService stockService, IRecordService recordService, IInboundOrderDetailService inboundOrderDetailService, IOutboundOrderService outboundOrderService, IOutboundOrderDetailService outboundOrderDetailService, IInvokeMESService invokeMESService, IOutStockLockInfoService outStockLockInfoService) : base(BaseDal) |
| | | public TaskService(IRepository<Dt_Task> BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IRepository<Dt_StockInfo> stockRepository, ILocationInfoService locationInfoService, IInboundOrderService inboundOrderService, ILocationStatusChangeRecordService locationStatusChangeRecordService, IESSApiService eSSApiService, ILogger<TaskService> logger, IStockService stockService, IRecordService recordService, IInboundOrderDetailService inboundOrderDetailService, IOutboundOrderService outboundOrderService, IOutboundOrderDetailService outboundOrderDetailService, IInvokeMESService invokeMESService, IOutStockLockInfoService outStockLockInfoService, IAllocateService allocateService, IRepository<Dt_OutboundBatch> outboundBatchRepository,IRepository<Dt_ReCheckOrder> reCheckOrderRepository) : base(BaseDal) |
| | | { |
| | | _mapper = mapper; |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | |
| | | _outboundOrderDetailService = outboundOrderDetailService; |
| | | _invokeMESService = invokeMESService; |
| | | _outStockLockInfoService = outStockLockInfoService; |
| | | _allocateService = allocateService; |
| | | _OutboundBatchRepository = outboundBatchRepository; |
| | | _reCheckOrderRepository = reCheckOrderRepository; |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | if (int.TryParse(taskNum, out var newTaskNum)) |
| | | { |
| | | task = BaseDal.QueryFirst(x => x.TaskNum == newTaskNum); |
| | | task = await BaseDal.QueryFirstAsync(x => x.TaskNum == newTaskNum); |
| | | if (task == null) |
| | | { |
| | | return WebResponseContent.Instance.Error("æªæ¾å°ä»»å¡ä¿¡æ¯"); |
| | |
| | | MethodInfo? methodInfo = GetType().GetMethod(((TaskTypeEnum)task.TaskType) + "TaskCompleted"); |
| | | if (methodInfo != null) |
| | | { |
| | | WebResponseContent? responseContent = (WebResponseContent?)methodInfo.Invoke(this, new object[] { task }); |
| | | if (responseContent != null) |
| | | object? taskResult = methodInfo.Invoke(this, new object[] { task }); |
| | | if (taskResult is Task<WebResponseContent> asyncTask) |
| | | { |
| | | return responseContent; |
| | | try |
| | | { |
| | | // 3. 弿¥çå¾
Task 宿ï¼èªå¨è§£æåº WebResponseContent |
| | | WebResponseContent responseContent = await asyncTask; |
| | | if (responseContent != null) |
| | | { |
| | | return responseContent; |
| | | } |
| | | } |
| | | catch (AggregateException ex) |
| | | { |
| | | _logger.LogError($"TaskService TaskCompleted taskResult: {ex.Message} "); |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _logger.LogError(ex, $"Unexpected error in {task.TaskType}"); |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | } |
| | | return WebResponseContent.Instance.Error("æªæ¾å°ä»»å¡ç±»å对åºä¸å¡å¤çé»è¾"); |
| | |
| | | { |
| | | foreach (var inboundOrder in inboundOrders) |
| | | { |
| | | if (inboundOrder.OrderType == InOrderTypeEnum.Allocat.ObjToInt())//è°æ¨å
¥åº |
| | | if (inboundOrder.OrderType == InOrderTypeEnum.AllocatInbound.ObjToInt())//è°æ¨å
¥åº |
| | | { |
| | | if (inboundOrder != null && inboundOrder.OrderStatus == InOrderStatusEnum.å
¥åºå®æ.ObjToInt()) |
| | | { |
| | | var allocate = _allocateService.Repository.QueryData(x => x.OrderNo == inboundOrder.InboundOrderNo).First(); |
| | | var allocatefeedmodel = new AllocateDto |
| | | { |
| | | ReqCode = Guid.NewGuid().ToString(), |
| | | ReqTime = DateTime.Now.ToString(), |
| | | BusinessType = BusinessTypeEnum.å¤é¨ä»åºè°æºä».ObjToInt().ToString(), |
| | | FactoryArea = inboundOrder.FactoryArea, |
| | | OperationType = 1, |
| | | Operator = inboundOrder.Operator, |
| | | OrderNo = inboundOrder.UpperOrderNo, |
| | | fromWarehouse = allocate?.FromWarehouse ?? "", |
| | | toWarehouse = allocate?.ToWarehouse ?? "", |
| | | Details = new List<AllocateDtoDetail>() |
| | | |
| | | }; |
| | | |
| | | var groupedData = inboundOrder.Details.GroupBy(item => new { item.MaterielCode, item.lineNo, item.BarcodeUnit, item.WarehouseCode }) |
| | | .Select(group => new AllocateDtoDetail |
| | | { |
| | | MaterialCode = group.Key.MaterielCode, |
| | | LineNo = group.Key.lineNo, |
| | | WarehouseCode = group.Key.WarehouseCode, |
| | | Qty = group.Sum(x => x.BarcodeQty), |
| | | // warehouseCode= "1072", |
| | | Unit = group.Key.BarcodeUnit, |
| | | Barcodes = group.Select(row => new BarcodeInfo |
| | | { |
| | | Barcode = row.Barcode, |
| | | Qty = row.BarcodeQty, |
| | | BatchNo = row.BatchNo, |
| | | SupplyCode = row.SupplyCode, |
| | | Unit = row.BarcodeUnit |
| | | }).ToList() |
| | | }).ToList(); |
| | | allocatefeedmodel.Details = groupedData; |
| | | |
| | | var result = await _invokeMESService.FeedbackAllocate(allocatefeedmodel); |
| | | if (result != null && result.code == 200) |
| | | { |
| | | _inboundOrderService.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 1 }) |
| | | .Where(it => it.Id == inboundOrder.Id).ExecuteCommand(); |
| | | _inboundOrderDetailService.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 1 }) |
| | | .Where(it => it.OrderId == inboundOrder.Id).ExecuteCommand(); |
| | | } |
| | | } |
| | | } |
| | | else if (inboundOrder.OrderType == InOrderTypeEnum.ReCheck.ObjToInt()) //鿣å
¥åº |
| | | { |
| | | //ä¸éè¦åä¼ ãå ä¸ä¸ªä½ç½®ã |
| | | } |
| | | else if (inboundOrder.OrderType == InOrderTypeEnum.InternalAllocat.ObjToInt()) //æºä»è°æºä» |
| | | { |
| | | _logger.LogInformation($"InboundTaskCompleted ååMES : {inboundOrder.InboundOrderNo } ,ordertype: {InOrderTypeEnum.InternalAllocat.ObjToInt()} " ); |
| | | // BusinessTypeEnum.æºä»è°æºä» |
| | | if (inboundOrder != null && inboundOrder.OrderStatus == InOrderStatusEnum.å
¥åºå®æ.ObjToInt()) |
| | | { |
| | | var allocate = _allocateService.Repository.QueryData(x => x.OrderNo == inboundOrder.InboundOrderNo).First(); |
| | | var allocatefeedmodel = new AllocateDto |
| | | { |
| | | ReqCode = Guid.NewGuid().ToString(), |
| | | ReqTime = DateTime.Now.ToString(), |
| | | BusinessType = BusinessTypeEnum.æºä»è°æºä».ObjToInt().ToString(), |
| | | FactoryArea = inboundOrder.FactoryArea, |
| | | OperationType = 1, |
| | | Operator = inboundOrder.Operator, |
| | | OrderNo = inboundOrder.UpperOrderNo, |
| | | fromWarehouse = allocate?.FromWarehouse ?? "", |
| | | toWarehouse = allocate?.ToWarehouse ?? "", |
| | | Details = new List<AllocateDtoDetail>() |
| | | |
| | | }; |
| | | |
| | | var groupedData = inboundOrder.Details.GroupBy(item => new { item.MaterielCode, item.lineNo, item.BarcodeUnit, item.WarehouseCode }) |
| | | .Select(group => new AllocateDtoDetail |
| | | { |
| | | MaterialCode = group.Key.MaterielCode, |
| | | LineNo = group.Key.lineNo, |
| | | WarehouseCode = group.Key.WarehouseCode, |
| | | Qty = group.Sum(x => x.BarcodeQty), |
| | | // warehouseCode= "1072", |
| | | Unit = group.Key.BarcodeUnit, |
| | | Barcodes = group.Select(row => new BarcodeInfo |
| | | { |
| | | Barcode = row.Barcode, |
| | | Qty = row.BarcodeQty, |
| | | BatchNo = row.BatchNo, |
| | | SupplyCode = row.SupplyCode, |
| | | Unit = row.BarcodeUnit |
| | | }).ToList() |
| | | }).ToList(); |
| | | allocatefeedmodel.Details = groupedData; |
| | | |
| | | var result = await _invokeMESService.FeedbackAllocate(allocatefeedmodel); |
| | | if (result != null && result.code == 200) |
| | | { |
| | | _inboundOrderService.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 1 }) |
| | | .Where(it => it.Id == inboundOrder.Id).ExecuteCommand(); |
| | | _inboundOrderDetailService.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 1 }) |
| | | .Where(it => it.OrderId == inboundOrder.Id).ExecuteCommand(); |
| | | } |
| | | } |
| | | |
| | | } |
| | | else |
| | |
| | | }).ToList(); |
| | | feedmodel.details = groupedData; |
| | | |
| | | var result= await _invokeMESService.FeedbackInbound(feedmodel); |
| | | var result = await _invokeMESService.FeedbackInbound(feedmodel); |
| | | if (result != null && result.code == 200) |
| | | { |
| | | _inboundOrderService.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 1 }) |
| | | .Where(it => it.Id== inboundOrder.Id).ExecuteCommand(); |
| | | .Where(it => it.Id == inboundOrder.Id).ExecuteCommand(); |
| | | _inboundOrderDetailService.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 1 }) |
| | | .Where(it => it.OrderId == inboundOrder.Id).ExecuteCommand(); |
| | | } |
| | |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | |
| | | public WebResponseContent OutboundTaskCompleted(Dt_Task task) |
| | | |
| | | public async Task<WebResponseContent> OutAllocateTaskCompleted(Dt_Task task) |
| | | { |
| | | _logger.LogInformation($"TaskService OutAllocateTaskCompleted: {task.TaskNum}"); |
| | | |
| | | return await OutboundTaskCompleted(task); |
| | | } |
| | | public async Task<WebResponseContent> OutboundTaskCompleted(Dt_Task task) |
| | | { |
| | | _logger.LogInformation($"TaskService OutboundTaskCompleted: {task.TaskNum}"); |
| | | //æ¥è´§ä½ |
| | |
| | | locationInfo.LocationStatus = LocationStatusEnum.Free.ObjToInt(); |
| | | _locationInfoService.Repository.UpdateData(locationInfo); |
| | | |
| | | var outloks = _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>().Where(x => x.TaskNum == task.TaskNum).ToList(); |
| | | var outloks = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>().Where(x => x.TaskNum == task.TaskNum).ToListAsync(); |
| | | |
| | | var stockids = outloks.Select(x => x.StockId).ToList(); |
| | | |
| | | |
| | | _stockService.StockInfoService.Db.Updateable<Dt_StockInfo>() |
| | | .SetColumns(it => new Dt_StockInfo |
| | | { |
| | |
| | | { |
| | | Status = StockStatusEmun.åºåºéå®.ObjToInt() |
| | | }) |
| | | .Where(it => stockids.Contains( it.StockId)) |
| | | .Where(it => stockids.Contains(it.StockId)) |
| | | .ExecuteCommand(); |
| | | |
| | | |
| | | |
| | | |
| | | return WebResponseContent.Instance.OK(); |
| | |
| | | stockInfo.StockStatus = StockStatusEmun.å
¥åºå®æ.ObjToInt(); |
| | | _stockRepository.UpdateData(stockInfo); |
| | | |
| | | var outboundOrder = _outboundOrderService.Db.Queryable<Dt_OutboundOrder>().First(x => x.OrderNo == task.OrderNo); |
| | | |
| | | task.TaskStatus = TaskStatusEnum.Finish.ObjToInt(); |
| | | BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? WIDESEA_Core.Enums.OperateTypeEnum.èªå¨å®æ : OperateTypeEnum.äººå·¥å®æ); |
| | | |
| | | _locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfo, beforelocationStatus, StockChangeType.Inbound.ObjToInt(), "", task.TaskNum); |
| | | |
| | | |
| | | if (outboundOrder != null) |
| | | { |
| | | await HandleOutboundOrderToMESCompletion(outboundOrder, outboundOrder.OrderNo); |
| | | } |
| | | else |
| | | { |
| | | _logger.LogInformation($"TaskService InEmptyTaskCompleted: {task.TaskNum} ,æªæ¾å°åºåºåã "); |
| | | } |
| | | |
| | | return content; |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | public WebResponseContent InPickTaskCompleted(Dt_Task task) |
| | | public async Task<WebResponseContent> InPickTaskCompleted(Dt_Task task) |
| | | { |
| | | _logger.LogInformation($"TaskService InPickTaskCompleted: {task.TaskNum}"); |
| | | //æ¥åºå |
| | | Dt_StockInfo stockInfo = _stockRepository.Db.Queryable<Dt_StockInfo>().Includes(x => x.Details).Where(x => x.PalletCode == task.PalletCode).First(); |
| | | if (stockInfo == null) |
| | | try |
| | | { |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°æç对åºçç»çä¿¡æ¯"); |
| | | } |
| | | if (stockInfo.Details.Count == 0 && stockInfo.PalletType != PalletTypeEnum.Empty.ObjToInt()) |
| | | { |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°è¯¥æçåºåæç»ä¿¡æ¯"); |
| | | } |
| | | //æ¥åºå |
| | | Dt_StockInfo stockInfo = await _stockRepository.Db.Queryable<Dt_StockInfo>().Includes(x => x.Details).Where(x => x.PalletCode == task.PalletCode).FirstAsync(); |
| | | if (stockInfo == null) |
| | | { |
| | | _logger.LogInformation($"TaskService InPickTaskCompleted: æªæ¾å°æç对åºçç»çä¿¡æ¯.{task.TaskNum}"); |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°æç对åºçç»çä¿¡æ¯"); |
| | | } |
| | | if (stockInfo.Details.Count == 0 && stockInfo.PalletType != PalletTypeEnum.Empty.ObjToInt()) |
| | | { |
| | | _logger.LogInformation($"TaskService InPickTaskCompleted: æªæ¾å°è¯¥æçåºåæç»ä¿¡æ¯.{task.TaskNum}"); |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°è¯¥æçåºåæç»ä¿¡æ¯"); |
| | | } |
| | | //æ¥è´§ä½ |
| | | Dt_LocationInfo locationInfo = _locationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress); |
| | | if (locationInfo == null) |
| | | { |
| | | _logger.LogInformation($"TaskService InPickTaskCompleted: æªæ¾å°å¯¹åºçç»ç¹è´§ä½ä¿¡æ¯ {task.TaskNum}."); |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°å¯¹åºçç»ç¹è´§ä½ä¿¡æ¯"); |
| | | } |
| | | |
| | | //æ¥è´§ä½ |
| | | Dt_LocationInfo locationInfo = _locationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress); |
| | | if (locationInfo == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°å¯¹åºçç»ç¹è´§ä½ä¿¡æ¯"); |
| | | var beforelocationStatus = locationInfo.LocationStatus; |
| | | // è·åææååºä¸çåºåºéå®è®°å½ |
| | | var returnLocks = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>() |
| | | .Where(it => it.OrderNo == task.OrderNo && it.PalletCode == task.PalletCode && it.Status == (int)OutLockStockStatusEnum.ååºä¸) |
| | | .ToListAsync(); |
| | | // æ´æ°åºåºéå®è®°å½ç¶æä¸ºååºå®æ |
| | | foreach (var lockInfo in returnLocks) |
| | | { |
| | | lockInfo.Status = (int)OutLockStockStatusEnum.å·²ååº; |
| | | } |
| | | _outStockLockInfoService.Db.Updateable(returnLocks).ExecuteCommand(); |
| | | |
| | | stockInfo.LocationCode = task.TargetAddress; |
| | | stockInfo.StockStatus = StockStatusEmun.å
¥åºå®æ.ObjToInt(); |
| | | if (stockInfo.Details != null && stockInfo.Details.Any()) |
| | | { |
| | | stockInfo.Details.ForEach(x => |
| | | { |
| | | x.Status = StockStatusEmun.å
¥åºå®æ.ObjToInt(); |
| | | }); |
| | | _stockService.StockInfoDetailService.Repository.UpdateData(stockInfo.Details); |
| | | } |
| | | |
| | | _stockService.StockInfoService.Repository.UpdateData(stockInfo); |
| | | |
| | | await ProcessStockDetailsForReturn(task, stockInfo.Id); |
| | | |
| | | await DeleteZeroQuantityStockDetails(stockInfo.Id); |
| | | |
| | | if (stockInfo.PalletType == PalletTypeEnum.Empty.ObjToInt()) |
| | | { |
| | | locationInfo.LocationStatus = LocationStatusEnum.Pallet.ObjToInt(); |
| | | } |
| | | else |
| | | { |
| | | locationInfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt(); |
| | | } |
| | | _locationInfoService.Repository.UpdateData(locationInfo); |
| | | var outboundOrder = _outboundOrderService.Db.Queryable<Dt_OutboundOrder>().First(x => x.OrderNo == task.OrderNo); |
| | | task.TaskStatus = TaskStatusEnum.Finish.ObjToInt(); |
| | | |
| | | BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateTypeEnum.èªå¨å®æ : OperateTypeEnum.äººå·¥å®æ); |
| | | BaseDal.DeleteData(task); |
| | | _locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfo, beforelocationStatus, StockChangeType.Inbound.ObjToInt(), "", task.TaskNum); |
| | | |
| | | if (outboundOrder != null) |
| | | { |
| | | await HandleOutboundOrderToMESCompletion(outboundOrder, outboundOrder.OrderNo); |
| | | } |
| | | else |
| | | { |
| | | _logger.LogInformation($"TaskService InPickTaskCompleted: {task.TaskNum} ,æªæ¾å°åºåºåã "); |
| | | } |
| | | } |
| | | stockInfo.LocationCode = task.TargetAddress; |
| | | stockInfo.StockStatus = StockStatusEmun.å
¥åºå®æ.ObjToInt(); |
| | | stockInfo.Details.ForEach(x => |
| | | catch (Exception ex) |
| | | { |
| | | x.Status = StockStatusEmun.å
¥åºå®æ.ObjToInt(); |
| | | }); |
| | | _stockService.StockInfoService.Repository.UpdateData(stockInfo); |
| | | _stockService.StockInfoDetailService.Repository.UpdateData(stockInfo.Details); |
| | | |
| | | if (stockInfo.PalletType == PalletTypeEnum.Empty.ObjToInt()) |
| | | { |
| | | locationInfo.LocationStatus = LocationStatusEnum.Pallet.ObjToInt(); |
| | | _logger.LogInformation($"TaskService InPickTaskCompleted: {task.TaskNum} , {ex.Message}"); |
| | | } |
| | | else |
| | | { |
| | | locationInfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt(); |
| | | } |
| | | _locationInfoService.Repository.UpdateData(locationInfo); |
| | | |
| | | task.TaskStatus = TaskStatusEnum.Finish.ObjToInt(); |
| | | |
| | | BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateTypeEnum.èªå¨å®æ : OperateTypeEnum.äººå·¥å®æ); |
| | | |
| | | return WebResponseContent.Instance.OK(); |
| | | return await Task.FromResult(WebResponseContent.Instance.OK()); |
| | | } |
| | | |
| | | |
| | | private async Task HandleOutboundOrderToMESCompletion(Dt_OutboundOrder outboundOrder, string orderNo) |
| | | { |
| | | try |
| | | { |
| | | var orderDetails = await _outboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>() |
| | | .LeftJoin<Dt_OutboundOrder>((o, item) => o.OrderId == item.Id) |
| | | .Where((o, item) => item.OrderNo == orderNo) |
| | | .Select((o, item) => o) |
| | | .ToListAsync(); |
| | | |
| | | bool allCompleted = true; |
| | | foreach (var detail in orderDetails) |
| | | { |
| | | _logger.LogInformation($"TaskService HandleOutboundOrderToMESCompletion: {outboundOrder.OrderNo} , {detail.NeedOutQuantity}"); |
| | | if (detail.OverOutQuantity < detail.NeedOutQuantity) |
| | | { |
| | | allCompleted = false; |
| | | break; |
| | | } |
| | | } |
| | | _logger.LogInformation($"TaskService HandleOutboundOrderToMESCompletion: {outboundOrder.OrderNo} , {allCompleted}"); |
| | | int newStatus = allCompleted ? (int)OutOrderStatusEnum.åºåºå®æ : (int)OutOrderStatusEnum.åºåºä¸; |
| | | |
| | | if (outboundOrder.OrderStatus != newStatus) |
| | | { |
| | | await _outboundOrderService.Db.Updateable<Dt_OutboundOrder>() |
| | | .SetColumns(x => x.OrderStatus == newStatus) |
| | | .Where(x => x.OrderNo == orderNo) |
| | | .ExecuteCommandAsync(); |
| | | |
| | | } |
| | | //åªææ£å¸¸åæ£å®ææ¶æåMESåé¦ |
| | | if (allCompleted && newStatus == (int)OutOrderStatusEnum.åºåºå®æ) |
| | | { |
| | | |
| | | if (outboundOrder.OrderType == OutOrderTypeEnum.Allocate.ObjToInt()) |
| | | { |
| | | var allocate = _allocateService.Repository.QueryData(x => x.UpperOrderNo == outboundOrder.UpperOrderNo).First(); |
| | | var allocatefeedmodel = new AllocateDto |
| | | { |
| | | ReqCode = Guid.NewGuid().ToString(), |
| | | ReqTime = DateTime.Now.ToString(), |
| | | BusinessType = "2", |
| | | FactoryArea = outboundOrder.FactoryArea, |
| | | OperationType = 1, |
| | | Operator = outboundOrder.Operator, |
| | | OrderNo = outboundOrder.UpperOrderNo, |
| | | // documentsNO = outboundOrder.OrderNo, |
| | | // status = outboundOrder.OrderStatus, |
| | | fromWarehouse = allocate?.FromWarehouse ?? "", |
| | | toWarehouse = allocate?.ToWarehouse ?? "", |
| | | Details = new List<AllocateDtoDetail>() |
| | | |
| | | }; |
| | | foreach (var detail in orderDetails) |
| | | { |
| | | // è·å该æç»å¯¹åºçæ¡ç ä¿¡æ¯ï¼ä»éå®è®°å½ï¼ |
| | | var detailLocks = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>() |
| | | .Where(x => x.OrderNo == orderNo && |
| | | x.OrderDetailId == detail.Id && |
| | | x.Status == (int)OutLockStockStatusEnum.æ£é宿) |
| | | .ToListAsync(); |
| | | |
| | | var detailModel = new AllocateDtoDetail |
| | | { |
| | | MaterialCode = detail.MaterielCode, |
| | | LineNo = detail.lineNo, |
| | | WarehouseCode = detail.WarehouseCode, |
| | | Qty = detailLocks.Sum(x=>x.BarcodeQty), |
| | | Unit = detail.Unit, |
| | | Barcodes = detailLocks.Select(lockInfo => new BarcodeInfo |
| | | { |
| | | Barcode = lockInfo.CurrentBarcode, |
| | | SupplyCode = lockInfo.SupplyCode, |
| | | BatchNo = lockInfo.BatchNo, |
| | | Unit = lockInfo.BarcodeUnit, |
| | | Qty = lockInfo.BarcodeQty // æ¡ç 级å«çæ°éä»ç¨éå®è®°å½ |
| | | }).ToList() |
| | | }; |
| | | |
| | | allocatefeedmodel.Details.Add(detailModel); |
| | | } |
| | | |
| | | var result = await _invokeMESService.FeedbackAllocate(allocatefeedmodel); |
| | | if (result != null && result.code == 200) |
| | | { |
| | | await _outboundOrderDetailService.Db.Updateable<Dt_OutboundOrderDetail>() |
| | | .SetColumns(x => x.ReturnToMESStatus == 1) |
| | | .Where(x => x.OrderId == outboundOrder.Id).ExecuteCommandAsync(); |
| | | |
| | | await _outboundOrderService.Db.Updateable<Dt_OutboundOrder>() |
| | | .SetColumns(x => new Dt_OutboundOrder |
| | | { |
| | | ReturnToMESStatus = 1, |
| | | Operator = App.User.UserName, |
| | | }).Where(x => x.OrderNo == orderNo).ExecuteCommandAsync(); |
| | | } |
| | | } |
| | | else if (outboundOrder.OrderType == OutOrderTypeEnum.ReCheck.ObjToInt()) |
| | | { |
| | | //ä¸ç¨åä¼ |
| | | } |
| | | else |
| | | { |
| | | var feedmodel = new FeedbackOutboundRequestModel |
| | | { |
| | | reqCode = Guid.NewGuid().ToString(), |
| | | reqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), |
| | | business_type = outboundOrder.BusinessType, |
| | | factoryArea = outboundOrder.FactoryArea, |
| | | operationType = 1, |
| | | Operator = outboundOrder.Operator, |
| | | orderNo = outboundOrder.UpperOrderNo, |
| | | documentsNO = outboundOrder.OrderNo, |
| | | status = outboundOrder.OrderStatus, |
| | | details = new List<FeedbackOutboundDetailsModel>() |
| | | }; |
| | | |
| | | |
| | | foreach (var detail in orderDetails) |
| | | { |
| | | // è·å该æç»å¯¹åºçæ¡ç ä¿¡æ¯ï¼ä»éå®è®°å½ï¼ |
| | | var detailLocks = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>() |
| | | .Where(x => x.OrderNo == orderNo && |
| | | x.OrderDetailId == detail.Id && |
| | | x.Status == (int)OutLockStockStatusEnum.æ£é宿) |
| | | .ToListAsync(); |
| | | |
| | | var detailModel = new FeedbackOutboundDetailsModel |
| | | { |
| | | materialCode = detail.MaterielCode, |
| | | lineNo = detail.lineNo, // 注æï¼è¿éå¯è½éè¦è°æ´å段å |
| | | warehouseCode = detail.WarehouseCode, |
| | | qty = detail.BarcodeQty, |
| | | currentDeliveryQty = detail.BarcodeQty, |
| | | unit = detail.Unit, |
| | | barcodes = detailLocks.Select(lockInfo => new WIDESEA_DTO.Outbound.BarcodesModel |
| | | { |
| | | barcode = lockInfo.CurrentBarcode, |
| | | supplyCode = lockInfo.SupplyCode, |
| | | batchNo = lockInfo.BatchNo, |
| | | unit = lockInfo.BarcodeUnit, |
| | | qty = lockInfo.BarcodeQty // æ¡ç 级å«çæ°éä»ç¨éå®è®°å½ |
| | | }).ToList() |
| | | }; |
| | | |
| | | feedmodel.details.Add(detailModel); |
| | | } |
| | | var result = await _invokeMESService.FeedbackOutbound(feedmodel); |
| | | if (result != null && result.code == 200) |
| | | { |
| | | await _outboundOrderDetailService.Db.Updateable<Dt_OutboundOrderDetail>() |
| | | .SetColumns(x => x.ReturnToMESStatus == 1) |
| | | .Where(x => x.OrderId == outboundOrder.Id) |
| | | .ExecuteCommandAsync(); |
| | | |
| | | await _outboundOrderService.Db.Updateable<Dt_OutboundOrder>() |
| | | .SetColumns(x => x.ReturnToMESStatus == 1) |
| | | .Where(x => x.OrderNo == orderNo) |
| | | .ExecuteCommandAsync(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _logger.LogError($"CheckAndUpdateOrderStatus失败 - OrderNo: {orderNo}, Error: {ex.Message}"); |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å é¤åºåæ°ä¸º0çåºåæç»è®°å½ |
| | | /// </summary> |
| | | private async Task DeleteZeroQuantityStockDetails(int stockId) |
| | | { |
| | | try |
| | | { |
| | | // å é¤åºåæ°é为0çè®°å½ |
| | | var deleteCount = await _stockService.StockInfoDetailService.Db.Deleteable<Dt_StockInfoDetail>() |
| | | .Where(x => x.StockId == stockId && |
| | | x.StockQuantity == 0 && |
| | | (x.Status == StockStatusEmun.åºåºå®æ.ObjToInt() || x.Status == |
| | | StockStatusEmun.å
¥åºå®æ.ObjToInt())) // åªå é¤å·²å®æç¶æçé¶åºå |
| | | .ExecuteCommandAsync(); |
| | | |
| | | if (deleteCount > 0) |
| | | { |
| | | _logger.LogInformation($"å é¤{deleteCount}æ¡é¶åºåæç»è®°å½ - StockId: {stockId}"); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _logger.LogWarning($"å é¤é¶åºåè®°å½å¤±è´¥ - StockId: {stockId}, Error: {ex.Message}"); |
| | | // 注æï¼å é¤å¤±è´¥ä¸åºè¯¥å½±å主æµç¨ï¼è®°å½æ¥å¿åç»§ç» |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// å¤çååºç¸å
³çææåºåæç»ç¶æåæ´ |
| | | /// </summary> |
| | | private async Task ProcessStockDetailsForReturn(Dt_Task returnTask, int stockId) |
| | | { |
| | | // è·å该æç䏿æéè¦ååºçåºåæç» |
| | | var stockDetails = await _stockService.StockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>() |
| | | .Where(x => x.StockId == stockId && |
| | | x.StockQuantity > 0 && |
| | | (x.Status == StockStatusEmun.åºåºéå®.ObjToInt() || x.Status == |
| | | StockStatusEmun.å
¥åºç¡®è®¤.ObjToInt())) // å
æ¬åºåºéå®åå
¥åºç¡®è®¤ç |
| | | .ToListAsync(); |
| | | |
| | | foreach (var detail in stockDetails) |
| | | { |
| | | |
| | | detail.Status = StockStatusEmun.å
¥åºå®æ.ObjToInt(); |
| | | detail.OutboundQuantity = 0; // æ¸
空åºåºæ°é |
| | | |
| | | _logger.LogInformation($"æ´æ°åºåæç»ç¶æ - æ¡ç : {detail.Barcode}, æ°é: {detail.StockQuantity}"); |
| | | } |
| | | |
| | | if (stockDetails.Any()) |
| | | { |
| | | await _stockService.StockInfoDetailService.Db.Updateable(stockDetails).ExecuteCommandAsync(); |
| | | _logger.LogInformation($"å
±æ´æ°{stockDetails.Count}个åºåæç»ç¶æä¸ºå
¥åºå®æ"); |
| | | } |
| | | } |
| | | public async Task<WebResponseContent> OutEmptyTaskCompleted(Dt_Task task) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | |
| | | task.TaskStatus = TaskStatusEnum.Finish.ObjToInt(); |
| | | BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateTypeEnum.èªå¨å®æ : OperateTypeEnum.äººå·¥å®æ); |
| | | _stockService.StockInfoService.Repository.DeleteAndMoveIntoHty(stockInfo, App.User.UserId == 0 ? OperateTypeEnum.èªå¨å®æ : OperateTypeEnum.äººå·¥å®æ); |
| | | _stockRepository.Db.Deleteable(stockInfo).ExecuteCommand(); |
| | | |
| | | //_stockRepository.Db.Deleteable(stockInfo).ExecuteCommand(); |
| | | _stockService.StockInfoService.DeleteData(stockInfo); |
| | | _locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Outbound.ObjToInt(), stockInfo.Details.FirstOrDefault()?.OrderNo ?? "", task.TaskNum); |
| | | |
| | | return WebResponseContent.Instance.OK(); |
| | | return await Task.FromResult(WebResponseContent.Instance.OK()); |
| | | |
| | | } |
| | | catch (Exception ex) |