| | |
| | | using SqlSugar; |
| | | using System.Reflection; |
| | | using System.Reflection.Emit; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using System.Xml.Linq; |
| | | using WIDESEA_BasicService; |
| | |
| | | private readonly IRepository<Dt_TakeStockOrder> _takeStockOrder; |
| | | public readonly IRepository<Dt_LocationType> _locationTypeRepository; |
| | | public readonly IRepository<Dt_WarehouseArea> _warehouseAreaRepository; |
| | | private readonly IRepository<Dt_OutStockLockInfo> _outboundLockInfoRepository; |
| | | public IRepository<Dt_Task> Repository => BaseDal; |
| | | |
| | | private Dictionary<string, SqlSugar.OrderByType> _taskOrderBy = new() |
| | |
| | | |
| | | 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, IAllocateService allocateService, IRepository<Dt_OutboundBatch> outboundBatchRepository, IRepository<Dt_ReCheckOrder> reCheckOrderRepository, IRepository<Dt_AllocateOrderDetail> allocateOrderDetailRepository, IRepository<Dt_AllocateOrder> allocateOrderRepository, IMaterialUnitService materialUnitService, ITask_HtyService task_HtyService, IRepository<Dt_AllocateMaterialInfo> allocateMaterialInfo, IRepository<Dt_AllocateMaterialInfo_Hty> allocateMaterialInfo_Hty, HttpClientHelper httpClientHelper, IBasicService basicService,IRepository<Dt_TakeStockOrder> takeStockOrder, IRepository<Dt_LocationType> locationTypeRepository, IRepository<Dt_WarehouseArea> warehouseAreaRepository) : 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, IRepository<Dt_AllocateOrderDetail> allocateOrderDetailRepository, IRepository<Dt_AllocateOrder> allocateOrderRepository, IMaterialUnitService materialUnitService, ITask_HtyService task_HtyService, IRepository<Dt_AllocateMaterialInfo> allocateMaterialInfo, IRepository<Dt_AllocateMaterialInfo_Hty> allocateMaterialInfo_Hty, HttpClientHelper httpClientHelper, IBasicService basicService,IRepository<Dt_TakeStockOrder> takeStockOrder, IRepository<Dt_LocationType> locationTypeRepository, IRepository<Dt_WarehouseArea> warehouseAreaRepository, IRepository<Dt_OutStockLockInfo> outboundLockInfoRepository) : base(BaseDal) |
| | | { |
| | | _mapper = mapper; |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | |
| | | _takeStockOrder = takeStockOrder; |
| | | _locationTypeRepository = locationTypeRepository; |
| | | _warehouseAreaRepository = warehouseAreaRepository; |
| | | _outboundLockInfoRepository = outboundLockInfoRepository; |
| | | } |
| | | |
| | | public async Task TaskStatusChange(string taskNum, TaskStatusEnum taskStatusEnum) |
| | |
| | | stockInfo.StockStatus = StockStatusEmun.å
¥åºå®æ.ObjToInt(); |
| | | stockInfo.Details.ForEach(x => |
| | | { |
| | | x.Status = StockStatusEmun.å
¥åºç¡®è®¤.ObjToInt(); |
| | | x.Status = inboundOrders.FirstOrDefault().CreateType == (int)OrderCreateTypeEnum.CreateInSystem ? StockStatusEmun.å
¥åºå®æ.ObjToInt():StockStatusEmun.å
¥åºç¡®è®¤.ObjToInt(); |
| | | }); |
| | | _stockService.StockInfoService.Repository.UpdateData(stockInfo); |
| | | _stockService.StockInfoDetailService.Repository.UpdateData(stockInfo.Details); |
| | |
| | | allocatefeedmodel.Details = groupedData; |
| | | |
| | | var response = responseModel(inboundOrder, 3, null, allocatefeedmodel); |
| | | if (response != null && response.IsSuccess) |
| | | if (response != null && response.IsSuccess && response.Data.Code =="200") |
| | | { |
| | | bool isAll = inboundOrder.Details.All(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()); |
| | | int isAllReturnToMESStatus = isAll ? 1 : 3; |
| | | _inboundOrderService.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = isAllReturnToMESStatus }) |
| | | .Where(it => it.Id == inboundOrder.Id ).ExecuteCommand(); |
| | | _inboundOrderDetailService.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = isAllReturnToMESStatus }) |
| | | .Where(it => it.OrderId == inboundOrder.Id).ExecuteCommand(); |
| | | var detailStatusList = _inboundOrderDetailService.Db.Queryable<Dt_InboundOrderDetail>() |
| | | .Where(it => it.OrderId == inboundOrder.Id) |
| | | .Select(it => it.OrderDetailStatus) |
| | | .ToList(); |
| | | |
| | | bool isAll = detailStatusList.Any() |
| | | ? detailStatusList.All(x => x == OrderDetailStatusEnum.Over.ObjToInt()) |
| | | : false; |
| | | |
| | | if (isAll) |
| | | { |
| | | _inboundOrderService.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 1, Remark = "" }) |
| | | .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 |
| | | { |
| | | _inboundOrderService.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 3, Remark = "" }) |
| | | .Where(it => it.Id == inboundOrder.Id).ExecuteCommand(); |
| | | _inboundOrderDetailService.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 3 }) |
| | | .Where(it => it.OrderId == inboundOrder.Id).ExecuteCommand(); |
| | | } |
| | | //åä¼ æååºåæå¯ç¨ |
| | | _stockRepository.Db.Updateable<Dt_StockInfoDetail>().SetColumns(it => new Dt_StockInfoDetail |
| | | { |
| | |
| | | } |
| | | else |
| | | { |
| | | bool isAll = inboundOrder.Details.All(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()); |
| | | int isAllReturnToMESStatus = isAll ? 2 : 4; |
| | | _inboundOrderService.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = isAllReturnToMESStatus, Remark = response.ErrorMessage }) |
| | | var detailStatusList = _inboundOrderDetailService.Db.Queryable<Dt_InboundOrderDetail>() |
| | | .Where(it => it.OrderId == inboundOrder.Id) |
| | | .Select(it => it.OrderDetailStatus) |
| | | .ToList(); |
| | | |
| | | bool isAll = detailStatusList.Any() |
| | | ? detailStatusList.All(x => x == OrderDetailStatusEnum.Over.ObjToInt()) |
| | | : false; |
| | | |
| | | if (isAll) |
| | | { |
| | | _inboundOrderService.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 2, Remark = "" }) |
| | | .Where(it => it.Id == inboundOrder.Id).ExecuteCommand(); |
| | | _inboundOrderDetailService.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = isAllReturnToMESStatus }) |
| | | .Where(it => it.OrderId == inboundOrder.Id).ExecuteCommand(); |
| | | _inboundOrderDetailService.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 2 }) |
| | | .Where(it => it.OrderId == inboundOrder.Id).ExecuteCommand(); |
| | | } |
| | | else |
| | | { |
| | | _inboundOrderService.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 4, Remark = "" }) |
| | | .Where(it => it.Id == inboundOrder.Id).ExecuteCommand(); |
| | | _inboundOrderDetailService.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 4 }) |
| | | .Where(it => it.OrderId == inboundOrder.Id).ExecuteCommand(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | else |
| | | { |
| | | if (inboundOrder != null && inboundOrder.OrderStatus == InOrderStatusEnum.å
¥åºå®æ.ObjToInt()) |
| | | if (inboundOrder != null && inboundOrder.OrderStatus == InOrderStatusEnum.å
¥åºå®æ.ObjToInt() && inboundOrder.CreateType == (int)OrderCreateTypeEnum.UpperSystemPush) |
| | | { |
| | | var feedmodel = new FeedbackInboundRequestModel |
| | | { |
| | |
| | | |
| | | var response= responseModel(inboundOrder,2, feedmodel); |
| | | |
| | | if (response != null && response.IsSuccess) |
| | | if (response != null && response.IsSuccess && response.Data.Code == "200") |
| | | { |
| | | bool isAll = inboundOrder.Details.All(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()); |
| | | int isAllReturnToMESStatus = isAll ? 1 : 3; |
| | | _inboundOrderService.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = isAllReturnToMESStatus, Remark = "" }) |
| | | var detailStatusList = _inboundOrderDetailService.Db.Queryable<Dt_InboundOrderDetail>() |
| | | .Where(it => it.OrderId == inboundOrder.Id) |
| | | .Select(it => it.OrderDetailStatus) |
| | | .ToList(); |
| | | |
| | | bool isAll = detailStatusList.Any() |
| | | ? detailStatusList.All(x => x == OrderDetailStatusEnum.Over.ObjToInt()) |
| | | : false; |
| | | |
| | | if (isAll) |
| | | { |
| | | _inboundOrderService.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 1, Remark = "" }) |
| | | .Where(it => it.Id == inboundOrder.Id).ExecuteCommand(); |
| | | _inboundOrderDetailService.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = isAllReturnToMESStatus }) |
| | | .Where(it => it.OrderId == inboundOrder.Id).ExecuteCommand(); |
| | | _inboundOrderDetailService.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 1 }) |
| | | .Where(it => it.OrderId == inboundOrder.Id).ExecuteCommand(); |
| | | } |
| | | else |
| | | { |
| | | _inboundOrderService.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 3, Remark = "" }) |
| | | .Where(it => it.Id == inboundOrder.Id).ExecuteCommand(); |
| | | _inboundOrderDetailService.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 3 }) |
| | | .Where(it => it.OrderId == inboundOrder.Id).ExecuteCommand(); |
| | | } |
| | | |
| | | //åä¼ æååºåæå¯ç¨ |
| | | _stockRepository.Db.Updateable<Dt_StockInfoDetail>().SetColumns(it => new Dt_StockInfoDetail |
| | | { |
| | |
| | | } |
| | | else |
| | | { |
| | | bool isAll = inboundOrder.Details.All(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()); |
| | | int isAllReturnToMESStatus = isAll ? 2 : 4; |
| | | _inboundOrderService.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = isAllReturnToMESStatus, Remark = response.ErrorMessage }) |
| | | var detailStatusList = _inboundOrderDetailService.Db.Queryable<Dt_InboundOrderDetail>() |
| | | .Where(it => it.OrderId == inboundOrder.Id) |
| | | .Select(it => it.OrderDetailStatus) |
| | | .ToList(); |
| | | |
| | | bool isAll = detailStatusList.Any() |
| | | ? detailStatusList.All(x => x == OrderDetailStatusEnum.Over.ObjToInt()) |
| | | : false; |
| | | |
| | | if (isAll) |
| | | { |
| | | _inboundOrderService.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 2, Remark = "" }) |
| | | .Where(it => it.Id == inboundOrder.Id).ExecuteCommand(); |
| | | _inboundOrderDetailService.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = isAllReturnToMESStatus }) |
| | | .Where(it => it.OrderId == inboundOrder.Id).ExecuteCommand(); |
| | | _inboundOrderDetailService.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 2 }) |
| | | .Where(it => it.OrderId == inboundOrder.Id).ExecuteCommand(); |
| | | } |
| | | else |
| | | { |
| | | _inboundOrderService.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 4, Remark = "" }) |
| | | .Where(it => it.Id == inboundOrder.Id).ExecuteCommand(); |
| | | _inboundOrderDetailService.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 4 }) |
| | | .Where(it => it.OrderId == inboundOrder.Id).ExecuteCommand(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | /// <summary> |
| | | /// çç¹åºåºå®æ |
| | | /// </summary> |
| | | public WebResponseContent OutInventoryTaskCompleted(Dt_Task task) |
| | | public async Task<WebResponseContent> OutInventoryTaskCompleted(Dt_Task task) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | content.Error(ex.Message); |
| | | return await Task.FromResult(WebResponseContent.Instance.Error(ex.Message)); |
| | | } |
| | | return content; |
| | | } |
| | |
| | | return await Task.FromResult(WebResponseContent.Instance.Error(ex.Message)); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ä»»å¡åæ¶ |
| | | /// </summary> |
| | | /// <param name="taskCodes"></param> |
| | | /// <returns></returns> |
| | | /// <summary> |
| | | public async Task<WebResponseContent> TaskCancel(List<int> taskCodes) |
| | | { |
| | | try |
| | | { |
| | | if (taskCodes == null || !taskCodes.Any()) |
| | | { |
| | | return WebResponseContent.Instance.Error("åæ¶çä»»å¡å·ä¸è½ä¸ºç©º"); |
| | | } |
| | | |
| | | //var taskCancelUrl = AppSettings.GetValue("TaskCancelUrl"); |
| | | //TaskCancelRequest taskc = new TaskCancelRequest(); |
| | | //taskc.TaskCodes = taskCodes.Select(x => x.ToString()).ToList(); |
| | | |
| | | //string json = JsonConvert.SerializeObject(taskc); |
| | | |
| | | //using var clientHttp = new HttpClient(); |
| | | //var content = new StringContent(json, Encoding.UTF8, "application/json"); |
| | | |
| | | //HttpResponseMessage response = await clientHttp.PostAsync(taskCancelUrl,content); |
| | | |
| | | //string responseJson = await response.Content.ReadAsStringAsync(); |
| | | //TaskCancelApiResponse apiResponse = JsonConvert.DeserializeObject<TaskCancelApiResponse>(responseJson); |
| | | |
| | | //if (apiResponse.Code != 0) |
| | | //{ |
| | | // return WebResponseContent.Instance.Error($"请æ±å¤±è´¥ï¼{apiResponse.Msg}"); |
| | | //} |
| | | _unitOfWorkManage.BeginTran(); |
| | | |
| | | var tasks = await Db.Queryable<Dt_Task>() |
| | | .Where(x => taskCodes.Contains(x.TaskNum)) |
| | | .ToListAsync(); |
| | | |
| | | if (!tasks.Any()) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return WebResponseContent.Instance.Error("æªæ¾å°å¯¹åºçä»»å¡ä¿¡æ¯"); |
| | | } |
| | | |
| | | int inPickType = TaskTypeEnum.InPick.ObjToInt(); |
| | | var inboundTypes = new List<int> |
| | | { |
| | | TaskTypeEnum.InAllocate.ObjToInt(), |
| | | TaskTypeEnum.InEmpty.ObjToInt(), |
| | | TaskTypeEnum.Inbound.ObjToInt(), |
| | | TaskTypeEnum.InInventory.ObjToInt(), |
| | | TaskTypeEnum.InQuality.ObjToInt() |
| | | }; |
| | | var outboundTypes = new List<int> |
| | | { |
| | | TaskTypeEnum.Outbound.ObjToInt(), |
| | | TaskTypeEnum.OutAllocate.ObjToInt() |
| | | }; |
| | | |
| | | foreach (var task in tasks) |
| | | { |
| | | if (task.TaskStatus == TaskStatusEnum.Cancel.ObjToInt()) |
| | | continue; |
| | | |
| | | var stock = await _stockRepository.QueryFirstAsync(x => x.PalletCode == task.PalletCode); |
| | | if (stock == null) |
| | | throw new Exception($"æç {task.PalletCode} æªæ¾å°åºåä¿¡æ¯"); |
| | | |
| | | if (task.TaskType == inPickType) |
| | | { |
| | | stock.StockStatus = StockStatusEmun.åºåºå®æ.ObjToInt(); |
| | | } |
| | | else if (inboundTypes.Contains(task.TaskType)) |
| | | { |
| | | stock.StockStatus = StockStatusEmun.ç»çæå.ObjToInt(); |
| | | } |
| | | else if (outboundTypes.Contains(task.TaskType)) |
| | | { |
| | | stock.StockStatus = StockStatusEmun.å
¥åºå®æ.ObjToInt(); |
| | | |
| | | var outStockLock = await _outStockLockInfoService.Db |
| | | .Queryable<Dt_OutStockLockInfo>() |
| | | .Where(x => x.PalletCode == task.PalletCode) |
| | | .FirstAsync(); |
| | | |
| | | if (outStockLock == null) |
| | | throw new Exception($"æç {task.PalletCode} æªæ¾å°åºåºéå®ä¿¡æ¯"); |
| | | |
| | | int detailId = outStockLock.OrderDetailIds.ObjToInt(); |
| | | var outboundDetail = await _outboundOrderDetailService.Db |
| | | .Queryable<Dt_OutboundOrderDetail>() |
| | | .Where(x => x.Id == detailId) |
| | | .FirstAsync(); |
| | | |
| | | if (outboundDetail == null) |
| | | throw new Exception($"åºåºæç»ID {detailId} ä¸åå¨"); |
| | | |
| | | if (outboundDetail.LockQuantity < outStockLock.AssignQuantity) |
| | | throw new Exception($"åºåºæç» {detailId} é宿°éä¸è¶³"); |
| | | |
| | | outboundDetail.LockQuantity -= outStockLock.AssignQuantity; |
| | | _outboundOrderDetailService.UpdateData(outboundDetail); |
| | | |
| | | _outboundLockInfoRepository.DeleteAndMoveIntoHty(outStockLock, OperateTypeEnum.人工å é¤); |
| | | } |
| | | |
| | | await _stockRepository.UpdateDataAsync(stock); |
| | | |
| | | task.TaskStatus = TaskStatusEnum.Cancel.ObjToInt(); |
| | | bool archiveSuccess = _task_HtyService.DeleteAndMoveIntoHty(task, OperateTypeEnum.人工å é¤); |
| | | |
| | | if (!archiveSuccess) |
| | | { |
| | | await Db.Deleteable(task).ExecuteCommandAsync(); |
| | | } |
| | | } |
| | | |
| | | _unitOfWorkManage.CommitTran(); |
| | | return WebResponseContent.Instance.OK("ä»»å¡åæ¶æå"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | _logger.LogError(ex, "ä»»å¡åæ¶å¼å¸¸"); |
| | | return WebResponseContent.Instance.Error($"ä»»å¡åæ¶å¤±è´¥ï¼{ex.Message}"); |
| | | } |
| | | } |
| | | |
| | | public async Task<WebResponseContent> AreaRelocationTaskCompleted(Dt_Task task) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | if (task == null || string.IsNullOrEmpty(task.PalletCode) || string.IsNullOrEmpty(task.TargetAddress)) |
| | | { |
| | | return WebResponseContent.Instance.Error("ç§»åºä»»å¡ä¿¡æ¯ä¸å®æ´ï¼æçå·/ç®æ è´§ä½ä¸ºç©ºï¼"); |
| | | } |
| | | |
| | | // 2. æ¥è¯¢æçåºåä¿¡æ¯ |
| | | Dt_StockInfo stockInfo = await _stockRepository.Db.Queryable<Dt_StockInfo>() |
| | | .Includes(x => x.Details) |
| | | .Where(x => x.PalletCode == task.PalletCode) |
| | | .FirstAsync(); |
| | | |
| | | if (stockInfo == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°æç[{task.PalletCode}]对åºçç»çä¿¡æ¯"); |
| | | } |
| | | |
| | | // é空æçå¿
é¡»ææç» |
| | | if (stockInfo.Details.Count == 0 && stockInfo.PalletType != PalletTypeEnum.Empty.ObjToInt()) |
| | | { |
| | | _logger.LogInformation($"TaskService RelocationTaskCompleted: æªæ¾å°è¯¥æçåºåæç»ä¿¡æ¯.{task.TaskNum}"); |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°è¯¥æç[{task.PalletCode}]åºåæç»ä¿¡æ¯"); |
| | | } |
| | | |
| | | // 3. æ¥è¯¢ç®æ è´§ä½+åè´§ä½ä¿¡æ¯ |
| | | Dt_LocationInfo targetLocationInfo = _locationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress); |
| | | if (targetLocationInfo == null) |
| | | { |
| | | return content.Error($"æªæ¾å°å¯¹åºçç»ç¹è´§ä½[{task.TargetAddress}]ä¿¡æ¯"); |
| | | } |
| | | |
| | | // åè´§ä½ä¿¡æ¯ |
| | | Dt_LocationInfo oldLocationInfo = null; |
| | | if (!string.IsNullOrEmpty(stockInfo.LocationCode)) |
| | | { |
| | | oldLocationInfo = _locationInfoService.Repository.QueryFirst(x => x.LocationCode == stockInfo.LocationCode); |
| | | if (oldLocationInfo == null) |
| | | { |
| | | return content.Error($"æªæ¾å°åè´§ä½[{stockInfo.LocationCode}]ä¿¡æ¯"); |
| | | } |
| | | } |
| | | |
| | | // 4. è´§ä½ç¶ææ ¡éª |
| | | if (targetLocationInfo.LocationStatus == LocationStatusEnum.InStock.ObjToInt()) |
| | | { |
| | | return WebResponseContent.Instance.Error($"ç®æ è´§ä½[{task.TargetAddress}]ç¶æä¸æ£ç¡®ï¼å½å为已å ç¨ï¼"); |
| | | } |
| | | |
| | | // 5. å¼å¯äºå¡å¤çæ ¸å¿é»è¾ |
| | | _unitOfWorkManage.BeginTran(); |
| | | |
| | | // 5.1 è®°å½ç®æ è´§ä½åç¶æï¼æ´æ°ä¸ºå ç¨ |
| | | var beforeTargetLocationStatus = targetLocationInfo.LocationStatus; |
| | | targetLocationInfo.LocationStatus = stockInfo.PalletType == PalletTypeEnum.Empty.ObjToInt() |
| | | ? LocationStatusEnum.Pallet.ObjToInt() |
| | | : LocationStatusEnum.InStock.ObjToInt(); |
| | | _locationInfoService.Repository.UpdateData(targetLocationInfo); |
| | | |
| | | // 5.2 éæ¾åè´§ä½ |
| | | int beforeOldLocationStatus = 0; |
| | | if (oldLocationInfo != null) |
| | | { |
| | | beforeOldLocationStatus = oldLocationInfo.LocationStatus; |
| | | // åè´§ä½æ¢å¤ä¸ºç©ºé² |
| | | oldLocationInfo.LocationStatus = LocationStatusEnum.Free.ObjToInt(); |
| | | _locationInfoService.Repository.UpdateData(oldLocationInfo); |
| | | } |
| | | // 5.4 æ´æ°åºå主信æ¯ï¼ç»å®æ°è´§ä½ï¼ |
| | | string oldLocationCode = stockInfo.LocationCode; // è®°å½åè´§ä½ |
| | | stockInfo.LocationCode = targetLocationInfo.LocationCode; // ç»å®ç®æ è´§ä½ |
| | | stockInfo.PalletCode = task.PalletCode; |
| | | stockInfo.StockStatus = StockStatusEmun.å
¥åºå®æ.ObjToInt(); |
| | | |
| | | _stockRepository.UpdateData(stockInfo); |
| | | |
| | | // 5.5 æ´æ°ä»»å¡ç¶æä¸ºå®æ |
| | | task.TaskStatus = TaskStatusEnum.Finish.ObjToInt(); |
| | | var result = _task_HtyService.DeleteAndMoveIntoHty(task, OperateTypeEnum.èªå¨å®æ); |
| | | |
| | | // æäº¤äºå¡ |
| | | _unitOfWorkManage.CommitTran(); |
| | | |
| | | // ä»»å¡å½æ¡£å¤±è´¥åç´æ¥å é¤ |
| | | if (!result) |
| | | { |
| | | await Db.Deleteable(task).ExecuteCommandAsync(); |
| | | } |
| | | try |
| | | { |
| | | // è®°å½ç®æ è´§ä½ç¶æåæ´ |
| | | _locationStatusChangeRecordService.AddLocationStatusChangeRecord( |
| | | targetLocationInfo, |
| | | beforeTargetLocationStatus, |
| | | StockChangeType.Inbound.ObjToInt(), |
| | | $"ç§»åºå
¥åºï¼åè´§ä½ï¼{oldLocationCode}ï¼", |
| | | task.TaskNum); |
| | | |
| | | // è®°å½åè´§ä½ç¶æåæ´ï¼è¥æï¼ |
| | | if (oldLocationInfo != null) |
| | | { |
| | | _locationStatusChangeRecordService.AddLocationStatusChangeRecord( |
| | | oldLocationInfo, |
| | | beforeOldLocationStatus, |
| | | StockChangeType.Outbound.ObjToInt(), |
| | | $"ç§»åºåºåºï¼ç®æ è´§ä½ï¼{targetLocationInfo.LocationCode}ï¼", |
| | | task.TaskNum); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _logger.LogInformation($"RelocationTaskCompleted AddLocationStatusChangeRecord : {ex.Message} "); |
| | | } |
| | | |
| | | return content.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | // äºå¡åæ» |
| | | _unitOfWorkManage.RollbackTran(); |
| | | _logger.LogError($"RelocationTaskCompleted å¤ç失败ï¼{ex.Message}", ex); |
| | | return await Task.FromResult(WebResponseContent.Instance.Error($"ç§»åºä»»å¡å¤ç失败ï¼{ex.Message}")); |
| | | } |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// è·¨åºåç§»åºä»»å¡å®æ |
| | | /// </summary> |
| | | /// <param name="task"></param> |
| | | /// <returns></returns> |
| | | public async Task<WebResponseContent> CrossAreaRelocationTaskCompleted(Dt_Task task) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | if (task == null || string.IsNullOrEmpty(task.PalletCode) || string.IsNullOrEmpty(task.TargetAddress)) |
| | | { |
| | | return WebResponseContent.Instance.Error("è·¨åºåç§»åºä»»å¡ä¿¡æ¯ä¸å®æ´ï¼æçå·/ç®æ è´§ä½ä¸ºç©ºï¼"); |
| | | } |
| | | |
| | | // 2. æ¥è¯¢æçåºåä¿¡æ¯ |
| | | Dt_StockInfo stockInfo = await _stockRepository.Db.Queryable<Dt_StockInfo>() |
| | | .Includes(x => x.Details) |
| | | .Where(x => x.PalletCode == task.PalletCode) |
| | | .FirstAsync(); |
| | | |
| | | if (stockInfo == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°æç[{task.PalletCode}]对åºçåºåä¿¡æ¯"); |
| | | } |
| | | |
| | | // é空æçå¿
é¡»ææç» |
| | | if (stockInfo.Details.Count == 0 && stockInfo.PalletType != PalletTypeEnum.Empty.ObjToInt()) |
| | | { |
| | | _logger.LogInformation($"CrossAreaRelocationTaskCompleted: æªæ¾å°è¯¥æçåºåæç»ä¿¡æ¯.{task.TaskNum}"); |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°è¯¥æç[{task.PalletCode}]åºåæç»ä¿¡æ¯"); |
| | | } |
| | | |
| | | // 3. æ¥è¯¢ç®æ è´§ä½ + åè´§ä½ä¿¡æ¯ |
| | | Dt_LocationInfo targetLocationInfo = _locationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress); |
| | | if (targetLocationInfo == null) |
| | | { |
| | | return content.Error($"æªæ¾å°å¯¹åºçç»ç¹è´§ä½[{task.TargetAddress}]ä¿¡æ¯"); |
| | | } |
| | | |
| | | // åè´§ä½ä¿¡æ¯ |
| | | Dt_LocationInfo oldLocationInfo = null; |
| | | if (!string.IsNullOrEmpty(stockInfo.LocationCode)) |
| | | { |
| | | oldLocationInfo = _locationInfoService.Repository.QueryFirst(x => x.LocationCode == stockInfo.LocationCode); |
| | | if (oldLocationInfo == null) |
| | | { |
| | | return content.Error($"æªæ¾å°åè´§ä½[{stockInfo.LocationCode}]ä¿¡æ¯"); |
| | | } |
| | | } |
| | | |
| | | // 4. è´§ä½ç¶ææ ¡éª |
| | | if (targetLocationInfo.LocationStatus == LocationStatusEnum.InStock.ObjToInt()) |
| | | { |
| | | return WebResponseContent.Instance.Error($"ç®æ è´§ä½[{task.TargetAddress}]ç¶æä¸æ£ç¡®ï¼å½å为已å ç¨ï¼"); |
| | | } |
| | | |
| | | // 5. å¼å¯äºå¡å¤çæ ¸å¿é»è¾ |
| | | _unitOfWorkManage.BeginTran(); |
| | | |
| | | // 5.1 ç®æ è´§ä½æ´æ°ä¸ºå ç¨ |
| | | var beforeTargetLocationStatus = targetLocationInfo.LocationStatus; |
| | | targetLocationInfo.LocationStatus = stockInfo.PalletType == PalletTypeEnum.Empty.ObjToInt() |
| | | ? LocationStatusEnum.Pallet.ObjToInt() |
| | | : LocationStatusEnum.InStock.ObjToInt(); |
| | | _locationInfoService.Repository.UpdateData(targetLocationInfo); |
| | | |
| | | // 5.2 åè´§ä½éæ¾ç©ºé² |
| | | int beforeOldLocationStatus = 0; |
| | | if (oldLocationInfo != null) |
| | | { |
| | | beforeOldLocationStatus = oldLocationInfo.LocationStatus; |
| | | oldLocationInfo.LocationStatus = LocationStatusEnum.Free.ObjToInt(); |
| | | _locationInfoService.Repository.UpdateData(oldLocationInfo); |
| | | } |
| | | |
| | | // 5.3 æ´æ°åºåï¼ç»å®æ°è´§ä½ + æ¢å¤æ£å¸¸ç¶æ |
| | | string oldLocationCode = stockInfo.LocationCode; |
| | | stockInfo.LocationCode = targetLocationInfo.LocationCode; |
| | | stockInfo.StockStatus = StockStatusEmun.å
¥åºå®æ.ObjToInt(); |
| | | stockInfo.LocationType = targetLocationInfo.LocationType; |
| | | _stockRepository.UpdateData(stockInfo); |
| | | |
| | | // 5.4 任塿 è®°ä¸ºå®æ |
| | | task.TaskStatus = TaskStatusEnum.Finish.ObjToInt(); |
| | | var result = _task_HtyService.DeleteAndMoveIntoHty(task, OperateTypeEnum.èªå¨å®æ); |
| | | |
| | | // æäº¤äºå¡ |
| | | _unitOfWorkManage.CommitTran(); |
| | | |
| | | // ä»»å¡å½æ¡£å¤±è´¥åå é¤ |
| | | if (!result) |
| | | { |
| | | await Db.Deleteable(task).ExecuteCommandAsync(); |
| | | } |
| | | |
| | | // è®°å½è´§ä½ç¶æåæ´æ¥å¿ |
| | | try |
| | | { |
| | | _locationStatusChangeRecordService.AddLocationStatusChangeRecord( |
| | | targetLocationInfo, |
| | | beforeTargetLocationStatus, |
| | | StockChangeType.Inbound.ObjToInt(), |
| | | $"è·¨åºåç§»åºå
¥åºï¼åè´§ä½ï¼{oldLocationCode}ï¼", |
| | | task.TaskNum); |
| | | |
| | | if (oldLocationInfo != null) |
| | | { |
| | | _locationStatusChangeRecordService.AddLocationStatusChangeRecord( |
| | | oldLocationInfo, |
| | | beforeOldLocationStatus, |
| | | StockChangeType.Outbound.ObjToInt(), |
| | | $"è·¨åºåç§»åºåºåºï¼ç®æ è´§ä½ï¼{targetLocationInfo.LocationCode}ï¼", |
| | | task.TaskNum); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _logger.LogInformation($"CrossAreaRelocationTaskCompleted è®°å½æ¥å¿å¼å¸¸ï¼{ex.Message}"); |
| | | } |
| | | |
| | | return content.OK("è·¨åºåç§»åºä»»å¡å®æ"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | _logger.LogError($"CrossAreaRelocationTaskCompleted å¤ç失败ï¼{ex.Message}", ex); |
| | | return await Task.FromResult(WebResponseContent.Instance.Error($"è·¨åºåç§»åºä»»å¡å¤ç失败ï¼{ex.Message}")); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |