| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Reflection.Metadata; |
| | | using System.Text; |
| | | using System.Text.Json; |
| | | using System.Threading.Tasks; |
| | | using WIDESEA_BasicService; |
| | | using WIDESEA_Common.CommonEnum; |
| | | using WIDESEA_Common.LocationEnum; |
| | | using WIDESEA_Common.OrderEnum; |
| | |
| | | using WIDESEA_IInboundService; |
| | | using WIDESEA_IOutboundService; |
| | | using WIDESEA_IStockService; |
| | | using WIDESEA_ITaskInfoService; |
| | | using WIDESEA_Model.Models; |
| | | using WIDESEA_Model.Models.Basic; |
| | | using WIDESEA_Model.Models.Check; |
| | | using WIDESEA_Model.Models.Outbound; |
| | | |
| | | namespace WIDESEA_OutboundService |
| | | { |
| | |
| | | private readonly IInboundOrderDetailService _inboundOrderDetailService; |
| | | private readonly IRepository<Dt_WarehouseArea> _warehouseAreaRepository; |
| | | private readonly IReCheckOrderService _reCheckOrderService; |
| | | private readonly ITask_HtyService _task_HtyService; |
| | | private readonly ILogger<OutboundPickingService> _logger; |
| | | private readonly IRepository<Dt_InterfaceLog> _interfaceLog; |
| | | |
| | | private Dictionary<string, string> stations = new Dictionary<string, string> |
| | | { |
| | |
| | | public OutboundPickingService(IRepository<Dt_PickingRecord> BaseDal, IUnitOfWorkManage unitOfWorkManage, IStockInfoService stockInfoService, IStockService stockService, |
| | | IOutStockLockInfoService outStockLockInfoService, IStockInfoDetailService stockInfoDetailService, ILocationInfoService locationInfoService, |
| | | IOutboundOrderDetailService outboundOrderDetailService, ISplitPackageService splitPackageService, IOutboundOrderService outboundOrderService, |
| | | IRepository<Dt_Task> taskRepository, IESSApiService eSSApiService, ILogger<OutboundPickingService> logger, IInvokeMESService invokeMESService, IDailySequenceService dailySequenceService, IAllocateService allocateService, IRepository<Dt_InboundOrder> inboundOrderRepository, IInboundOrderDetailService inboundOrderDetailService, IRepository<Dt_WarehouseArea> warehouseAreaRepository, IReCheckOrderService reCheckOrderService) : base(BaseDal) |
| | | IRepository<Dt_Task> taskRepository, IESSApiService eSSApiService, ILogger<OutboundPickingService> logger, IInvokeMESService invokeMESService, IDailySequenceService dailySequenceService, IAllocateService allocateService, IRepository<Dt_InboundOrder> inboundOrderRepository, IInboundOrderDetailService inboundOrderDetailService, IRepository<Dt_WarehouseArea> warehouseAreaRepository, IReCheckOrderService reCheckOrderService, ITask_HtyService task_HtyService, IRepository<Dt_InterfaceLog> interfaceLog) : base(BaseDal) |
| | | { |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | _stockInfoService = stockInfoService; |
| | |
| | | _inboundOrderDetailService = inboundOrderDetailService; |
| | | _warehouseAreaRepository = warehouseAreaRepository; |
| | | _reCheckOrderService = reCheckOrderService; |
| | | _task_HtyService = task_HtyService; |
| | | _interfaceLog = interfaceLog; |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | var statusAnalysis = await AnalyzePalletStatus(orderNo, palletCode, stockInfo.Id); |
| | | if (!statusAnalysis.HasItemsToReturn) |
| | | return await HandleNoReturnItems(orderNo, palletCode, task, stockInfo.Id); |
| | | { |
| | | try |
| | | { |
| | | var result = await HandleNoReturnItems(orderNo, palletCode, task, stockInfo.Id); |
| | | _unitOfWorkManage.CommitTran(); |
| | | if (result.Status) |
| | | { |
| | | task.PalletType = PalletTypeEnum.Empty.ObjToInt(); |
| | | await CreateReturnTaskAndHandleESS(orderNo, palletCode, task, TaskTypeEnum.InEmpty, PalletTypeEnum.Empty.ObjToInt()); |
| | | } |
| | | return result; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | _logger.LogError($"ReturnRemaining ååºç©ºç®±å¤±è´¥ - OrderNo: {orderNo}, PalletCode: {palletCode}, Error: {ex.Message}"); |
| | | return WebResponseContent.Instance.Error($"ååºç©ºç®±æä½å¤±è´¥: {ex.Message}"); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | // 4. æ£æ¥æ¯å¦æè¿è¡ä¸çä»»å¡ |
| | | if (statusAnalysis.HasActiveTasks) |
| | |
| | | { |
| | | // è·åææ°ç订åæç»æ°æ®ï¼å¸¦éï¼ |
| | | var currentOrderDetail = await _outboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>() |
| | | .With(SqlWith.RowLock) |
| | | //.With(SqlWith.RowLock) |
| | | .FirstAsync(x => x.Id == orderDetailId); |
| | | |
| | | decimal newOverOutQuantity = currentOrderDetail.OverOutQuantity - cancelQty; |
| | |
| | | _stockInfoService.AddMaterielGroup(emptystockInfo); |
| | | //空æçå¦ä½å¤ç è¿æä¸ä¸ªåºåºä»»å¡è¦å¤çã |
| | | originalTask.PalletType = PalletTypeEnum.Empty.ObjToInt(); |
| | | |
| | | await CreateReturnTaskAndHandleESS(orderNo, palletCode, originalTask, TaskTypeEnum.InEmpty, PalletTypeEnum.Empty.ObjToInt()); |
| | | |
| | | } |
| | | catch (Exception ex) |
| | |
| | | WarehouseId = originalTask.WarehouseId |
| | | |
| | | }; |
| | | // ä¿åååºä»»å¡ |
| | | await _taskRepository.Db.Insertable(returnTask).ExecuteCommandAsync(); |
| | | try |
| | | { |
| | | // ä¿åååºä»»å¡ |
| | | var insertcount = await _taskRepository.Db.Insertable(returnTask).ExecuteCommandAsync(); |
| | | if (insertcount <= 0) |
| | | { |
| | | throw new Exception("å建任å¡å¤±è´¥ï¼"); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _logger.LogInformation($"CreateReturnTaskAndHandleESS å建任å¡å¤±è´¥: {orderNo} ï¼ {palletCode}"); |
| | | throw new Exception("å建任å¡å¤±è´¥ï¼"); |
| | | } |
| | | var targetAddress = originalTask.TargetAddress; |
| | | |
| | | _logger.LogInformation($"CreateReturnTaskAndHandleESS å é¤åå²ä»»å¡: {orderNo} ï¼ {originalTask.TaskNum}"); |
| | | // å é¤åå§åºåºä»»å¡ |
| | | _taskRepository.DeleteAndMoveIntoHty(originalTask, OperateTypeEnum.èªå¨å®æ); |
| | | await _taskRepository.Db.Deleteable(originalTask).ExecuteCommandAsync(); |
| | | |
| | | |
| | | // _taskRepository.DeleteAndMoveIntoHty(originalTask, OperateTypeEnum.èªå¨å®æ); |
| | | var result = _task_HtyService.DeleteAndMoveIntoHty(originalTask, OperateTypeEnum.人工å é¤); |
| | | if (!result) |
| | | { |
| | | await _taskRepository.Db.Deleteable(originalTask).ExecuteCommandAsync(); |
| | | } |
| | | _logger.LogInformation($"CreateReturnTaskAndHandleESS å é¤åå²ä»»å¡: {orderNo} ï¼ {originalTask.TaskNum},å½±åè¡ {result}"); |
| | | |
| | | // ç» ESS åéæµå¨ä¿¡å·ååå»ºä»»å¡ |
| | | await SendESSCommands(palletCode, targetAddress, returnTask); |
| | |
| | | .Where(x => x.StockId == stockId && x.StockQuantity == 0) |
| | | .ExecuteCommandAsync(); |
| | | |
| | | await _stockInfoService.Db.Deleteable<Dt_StockInfo>() |
| | | .Where(x => x.Id == stockId).ExecuteCommandAsync(); |
| | | _stockInfoService.DeleteData(stockId); |
| | | |
| | | _logger.LogInformation($"æ¸
çé¶åºåæç»è®°å½ - StockId: {stockId}, å é¤è®°å½æ°: {deleteDetailCount}"); |
| | | |
| | |
| | | TaskNum = 0, |
| | | Status = (int)OutLockStockStatusEnum.æ£é宿, |
| | | Unit = outboundOrderDetail.Unit, |
| | | SupplyCode = outboundOrderDetail.SupplyCode?? "æ ", |
| | | SupplyCode = outboundOrderDetail.SupplyCode ?? "æ ", |
| | | OrderType = outboundOrder.OrderType, |
| | | CurrentBarcode = inboundOrderDetail.Barcode, |
| | | IsSplitted = 1, |
| | | Operator = App.User.UserName, |
| | | lineNo= outboundOrderDetail.lineNo, |
| | | lineNo = outboundOrderDetail.lineNo, |
| | | WarehouseCode = outboundOrderDetail.WarehouseCode ?? "æ ", |
| | | BarcodeQty=outboundOrderDetail.NoStockOutQty, |
| | | BarcodeUnit =outboundOrderDetail.BarcodeUnit, |
| | | BarcodeQty = outboundOrderDetail.NoStockOutQty, |
| | | BarcodeUnit = outboundOrderDetail.BarcodeUnit, |
| | | BatchNo = outboundOrderDetail.BatchNo |
| | | }; |
| | | _outStockLockInfoService.AddData(newLockInfo); |
| | |
| | | var result1 = await _invokeMESService.FeedbackInbound(infeedmodel); |
| | | if (result1 != null && result1.code == 200) |
| | | { |
| | | var orderIds = inboundOrderDetails.Select(x => x.Id).Distinct().ToList(); |
| | | _inboundOrderRepository.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(); |
| | | .Where(it => orderIds.Contains(it.Id)).ExecuteCommand(); |
| | | } |
| | | //åºåºåä¼ MES |
| | | |
| | | var documentNo = UniqueValueGenerator.Generate(); |
| | | |
| | | var outfeedmodel = 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 = App.User.UserName, |
| | | orderNo = outboundOrder.UpperOrderNo, |
| | | documentsNO = outboundOrder.OrderNo, |
| | | status = outboundOrder.OrderStatus, |
| | | details = new List<FeedbackOutboundDetailsModel>() |
| | | }; |
| | | foreach (var detail in outboundOrder.Details) |
| | | { |
| | | reqCode = Guid.NewGuid().ToString(), |
| | | reqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), |
| | | business_type = outboundOrder.BusinessType, |
| | | factoryArea = outboundOrder.FactoryArea, |
| | | operationType = 1, |
| | | Operator = App.User.UserName, |
| | | orderNo = outboundOrder.UpperOrderNo, |
| | | documentsNO = documentNo, |
| | | status = outboundOrder.OrderStatus, |
| | | details = new List<FeedbackOutboundDetailsModel>() |
| | | }; |
| | | foreach (var detail in outboundOrderDetails) |
| | | { |
| | | // è·å该æç»å¯¹åºçæ¡ç ä¿¡æ¯ï¼ä»éå®è®°å½ï¼ |
| | | var detailLocks = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>() |
| | |
| | | (x.Status == (int)OutLockStockStatusEnum.æ£é宿 || x.Status == (int)OutLockStockStatusEnum.å·²ååº)) |
| | | .ToListAsync(); |
| | | |
| | | var groupdata = detailLocks.GroupBy(item => new { item.MaterielCode, item.lineNo, item.BarcodeUnit, item.WarehouseCode }) |
| | | .Select(group => new FeedbackOutboundDetailsModel |
| | | { |
| | | var groupdata = detailLocks.GroupBy(item => new { item.MaterielCode, item.lineNo, item.BarcodeUnit, item.WarehouseCode }) |
| | | .Select(group => new FeedbackOutboundDetailsModel |
| | | { |
| | | |
| | | materialCode = group.Key.MaterielCode, |
| | | lineNo = group.Key.lineNo, |
| | | warehouseCode = group.Key.WarehouseCode, |
| | | qty = group.Sum(x => x.PickedQty), |
| | | currentDeliveryQty = group.Sum(x => x.PickedQty), |
| | | unit = group.Key.BarcodeUnit, |
| | | barcodes = group.Select(lockInfo => new WIDESEA_DTO.Outbound.BarcodesModel |
| | | { |
| | | barcode = lockInfo.CurrentBarcode, |
| | | supplyCode = lockInfo.SupplyCode, |
| | | batchNo = lockInfo.BatchNo, |
| | | unit = lockInfo.BarcodeUnit, |
| | | qty = lockInfo.PickedQty |
| | | }).ToList() |
| | | }).ToList(); |
| | | outfeedmodel.details.AddRange(groupdata); |
| | | } |
| | | var result = await _invokeMESService.FeedbackOutbound(outfeedmodel); |
| | | if (result != null && result.code == 200) |
| | | { |
| | | await _outboundOrderDetailService.Db.Updateable<Dt_OutboundOrderDetail>() |
| | | .SetColumns(x => x.ReturnToMESStatus == 1) |
| | | .Where(x => x.OrderId == outboundOrder.Id) |
| | | .ExecuteCommandAsync(); |
| | | materialCode = group.Key.MaterielCode, |
| | | lineNo = group.Key.lineNo, |
| | | warehouseCode = group.Key.WarehouseCode, |
| | | qty = group.Sum(x => x.PickedQty), |
| | | currentDeliveryQty = group.Sum(x => x.PickedQty), |
| | | unit = group.Key.BarcodeUnit, |
| | | barcodes = group.Select(lockInfo => new WIDESEA_DTO.Outbound.BarcodesModel |
| | | { |
| | | barcode = lockInfo.CurrentBarcode, |
| | | supplyCode = lockInfo.SupplyCode, |
| | | batchNo = lockInfo.BatchNo, |
| | | unit = lockInfo.BarcodeUnit, |
| | | qty = lockInfo.PickedQty |
| | | }).ToList() |
| | | }).ToList(); |
| | | outfeedmodel.details.AddRange(groupdata); |
| | | } |
| | | //åå¨åä¼ åæ°ï¼ä¿è¯å¼å¸¸æå¨åä¼ |
| | | Dt_InterfaceLog interfaceLog = new Dt_InterfaceLog |
| | | { |
| | | OrderNo = outboundOrder.UpperOrderNo, |
| | | DocumentNo = documentNo, |
| | | OrderType = "èæåºå
¥åº", |
| | | Content = outfeedmodel.ToJson(), |
| | | ReturnToMESStatus = 0, |
| | | IsDeleted = false |
| | | }; |
| | | _interfaceLog.AddData(interfaceLog); |
| | | |
| | | var result = await _invokeMESService.FeedbackOutbound(outfeedmodel); |
| | | if (result != null && result.code == 200) |
| | | { |
| | | var orderIds = outboundOrderDetails.Select(x => x.Id).Distinct().ToList(); |
| | | await _outboundOrderDetailService.Db.Updateable<Dt_OutboundOrderDetail>() |
| | | .SetColumns(x => x.ReturnToMESStatus == 1) |
| | | .Where(x => orderIds.Contains(x.Id)) |
| | | .ExecuteCommandAsync(); |
| | | |
| | | |
| | | await _outboundOrderService.Db.Updateable<Dt_OutboundOrder>() |
| | | .SetColumns(x => x.ReturnToMESStatus == 1) |
| | | .Where(x => x.Id == outboundOrder.Id) |
| | | .ExecuteCommandAsync(); |
| | | |
| | | await _interfaceLog.Db.Updateable<Dt_InterfaceLog>() |
| | | .SetColumns(x => x.ReturnToMESStatus == 1) |
| | | .Where(x => x.DocumentNo == documentNo) |
| | | .ExecuteCommandAsync(); |
| | | } |
| | | return WebResponseContent.Instance.OK(); |
| | |
| | | { |
| | | return content.Error("åªææ¿å°éæ£ç»ææè½å
¥åºï¼"); |
| | | } |
| | | else |
| | | { |
| | | return content.Error("æ²¡ææ¾å°éæ£åæ®æ°æ®ã"); |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | stockInfo.Details = new List<Dt_StockInfoDetail>(); |
| | | } |
| | | var inboindId = 0; Dt_InboundOrder dt_InboundOrder = null; |
| | | var dbinbound = _inboundOrderRepository.QueryData(x => x.InboundOrderNo == dbinboundOrderDetails.First().OrderNo).First(); |
| | | var orderno = dbinboundOrderDetails.First().OrderNo; |
| | | var dbinbound = _inboundOrderRepository.QueryData(x => x.InboundOrderNo == orderno).FirstOrDefault(); |
| | | if (dbinbound == null) |
| | | { |
| | | dt_InboundOrder = new Dt_InboundOrder |