| | |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using System.Transactions; |
| | | using WIDESEA_Common.StockEnum; |
| | | using WIDESEA_Common.TaskEnum; |
| | | using WIDESEA_Core; |
| | | using WIDESEA_Core.BaseRepository; |
| | |
| | | using WIDESEA_ITaskInfoRepository; |
| | | using WIDESEA_ITaskInfoService; |
| | | using WIDESEA_Model.Models; |
| | | using WIDESEA_OutboundRepository; |
| | | using WIDESEA_TaskInfoRepository; |
| | | using WIDESEAWCS_DTO.WCSInfo; |
| | | |
| | |
| | | private readonly IInboundService _inboundService; |
| | | private readonly IRecordService _recordService; |
| | | private readonly IStockService _stockService; |
| | | private readonly IBasicRepository _basicRepository; |
| | | |
| | | public ITaskRepository Repository => BaseDal; |
| | | |
| | | public TaskService(ITaskRepository BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IBasicService basicService, IOutboundService outboundService, IInboundService inboundService, IRecordService recordService, IStockService stockService) : base(BaseDal) |
| | | public TaskService(ITaskRepository BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IBasicService basicService, IOutboundService outboundService, IInboundService inboundService, IRecordService recordService, IStockService stockService, IBasicRepository basicRepository) : base(BaseDal) |
| | | { |
| | | _mapper = mapper; |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | |
| | | _inboundService = inboundService; |
| | | _recordService = recordService; |
| | | _stockService = stockService; |
| | | _basicRepository = basicRepository; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å
¥åºä»»å¡å®æ |
| | | /// </summary> |
| | | /// <param name="task"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent InboundTaskCompleted(Dt_Task task) |
| | | { |
| | | Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode); |
| | |
| | | |
| | | return (true, "æå"); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// åºåºä»»å¡å®æ |
| | | /// </summary> |
| | | /// <param name="task"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent OutboundTaskCompleted(Dt_Task task) |
| | | { |
| | | Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode); |
| | |
| | | return OnOutboundTaskCompleted?.Invoke(task) ?? WebResponseContent.Instance.OK(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æçåºåºä»»å¡å®æ |
| | | /// </summary> |
| | | /// <param name="task"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent PalletOutboundTaskCompleted(Dt_Task task) |
| | | { |
| | | Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode); |
| | |
| | | { |
| | | Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == WMStask.TaskNum && x.TaskType == WMStask.TaskType); |
| | | if (task == null) return WebResponseContent.Instance.Error("æªæ¾å°ä»»å¡ä¿¡æ¯"); |
| | | if (task.TaskType == (int)TaskTypeEnum.Inbound) |
| | | if (TaskEnumHelper.GetTaskTypeGroup(task.TaskType) == TaskTypeGroup.InboundGroup) |
| | | { |
| | | int nextStatus = task.TaskState.GetNextNotCompletedStatus<TaskInStatusEnum>(); |
| | | if (WMStask.TaskState != nextStatus) return WebResponseContent.Instance.Error($"该任å¡ç¶ææè¯¯,ä»»å¡å·:ã{task.TaskNum}ã,ä»»å¡ç¶æ:ã{task.TaskState}ã"); |
| | | task.TaskState = nextStatus; |
| | | switch (nextStatus) |
| | | { |
| | | case (int)TaskInStatusEnum.SC_InFinish: |
| | | content = UpdateTaskStatusInFinish(task); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | //task.TaskState = nextStatus; |
| | | task.TaskState = TaskInStatusEnum.InFinish.ObjToInt(); |
| | | content = UpdateTaskStatusInFinish(task); |
| | | } |
| | | else if (task.TaskType == (int)TaskTypeEnum.Outbound) |
| | | { |
| | | int nextStatus = task.TaskState.GetNextNotCompletedStatus<TaskOutStatusEnum>(); |
| | | if (WMStask.TaskState != nextStatus) return WebResponseContent.Instance.Error($"该任å¡ç¶ææè¯¯,ä»»å¡å·:ã{task.TaskNum}ã,ä»»å¡ç¶æ:ã{task.TaskState}ã"); |
| | | task.TaskState = nextStatus; |
| | | switch (nextStatus) |
| | | //int nextStatus = task.TaskState.GetNextNotCompletedStatus<TaskOutStatusEnum>(); |
| | | //if (WMStask.TaskState != nextStatus) return WebResponseContent.Instance.Error($"该任å¡ç¶ææè¯¯,ä»»å¡å·:ã{task.TaskNum}ã,ä»»å¡ç¶æ:ã{task.TaskState}ã"); |
| | | //task.TaskState = nextStatus; |
| | | task.TaskState = WMStask.TaskState; |
| | | switch (task.TaskState) |
| | | { |
| | | case (int)TaskOutStatusEnum.SC_OutFinish: |
| | | case (int)TaskOutStatusEnum.SC_OutFinish://æ´æ°è´§ä½åºåä¿¡æ¯ |
| | | UpdateTaskStatusSC_OutFinish(task); |
| | | break; |
| | | //case (int)TaskOutStatusEnum.Line_OutFinish: |
| | | |
| | | //break; |
| | | case (int)TaskOutStatusEnum.OutFinish: |
| | | UpdateTaskStatusOutFinish(task); |
| | | break; |
| | | default: |
| | | UpdateData(task); |
| | | break; |
| | | } |
| | | } |
| | | else if (task.TaskType == (int)TaskTypeEnum.Relocation) |
| | | { |
| | | task.TaskState = WMStask.TaskState; |
| | | if (task.TaskState == (int)WIDESEA_Core.Enums.TaskRelocationStatusEnum.RelocationFinish) |
| | | content = UpdateTaskStatusRelocationCarFinish(task); |
| | | else |
| | | content = UpdateData(task); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | |
| | | return content; |
| | | } |
| | | /// <summary> |
| | | /// æ´æ°ä»»å¡ç¶æå®æ |
| | | /// ä¿®æ¹ä»»å¡ç¶æä¸ºå åæºåºåºå®æ |
| | | /// </summary> |
| | | /// <param name="task"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent UpdateTaskStatusSC_OutFinish(Dt_Task task) |
| | | { |
| | | try |
| | | { |
| | | Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode); |
| | | Dt_LocationInfo Sourcelocation = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.SourceAddress); |
| | | Dt_OutStockLockInfo outStockLockInfo = _outboundService.OutboundStockLockInfoService.Repository.QueryFirst(x => x.TaskNum == task.TaskNum); |
| | | Db.Ado.BeginTran(); |
| | | if (stockInfo != null) |
| | | { |
| | | _stockService.StockInfoService.Repository.DeleteAndMoveIntoHty(stockInfo, App.User.UserId == 0 ? OperateType.èªå¨å®æ : OperateType.äººå·¥å®æ); |
| | | _stockService.StockInfoDetailService.Repository.DeleteAndMoveIntoHty(stockInfo.Details, App.User.UserId == 0 ? OperateType.èªå¨å®æ : OperateType.äººå·¥å®æ); |
| | | } |
| | | if (Sourcelocation != null) |
| | | { |
| | | if (task.TaskType == TaskOutboundTypeEnum.Outbound.ObjToInt()) Sourcelocation.CurrentQty--; |
| | | if (Sourcelocation.CurrentQty == 0) |
| | | { |
| | | Sourcelocation.LocationStatus = LocationStatusEnum.Free.ObjToInt(); |
| | | Sourcelocation.EnableStatus = EnableStatusEnum.Normal.ObjToInt(); |
| | | } |
| | | if (Sourcelocation.Row == 1 && Sourcelocation.LocationStatus == LocationStatusEnum.Free.ObjToInt()) |
| | | { |
| | | Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.Row == 2 && x.Column == Sourcelocation.Column && x.Layer == Sourcelocation.Layer); |
| | | if (locationInfo.CurrentQty == 0 /*&& locationInfo.LocationStatus == LocationStatusEnum.Free.ObjToInt()*/) |
| | | { |
| | | locationInfo.LocationStatus = LocationStatusEnum.Free.ObjToInt(); |
| | | locationInfo.EnableStatus = EnableStatusEnum.Normal.ObjToInt(); |
| | | _basicService.LocationInfoService.Repository.UpdateData(locationInfo); |
| | | } |
| | | } |
| | | _basicService.LocationInfoService.Repository.UpdateData(Sourcelocation); |
| | | } |
| | | if (outStockLockInfo != null) |
| | | { |
| | | outStockLockInfo.Status = OutLockStockStatusEnum.åºåºä¸.ObjToInt(); |
| | | _outboundService.OutboundStockLockInfoService.Repository.UpdateData(outStockLockInfo); |
| | | } |
| | | UpdateData(task); |
| | | Db.Ado.CommitTran(); |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Db.Ado.RollbackTran(); |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// æ´æ°åºåºä»»å¡ç¶æå®æ |
| | | /// </summary> |
| | | /// <param name="task"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent UpdateTaskStatusOutFinish(Dt_Task task) |
| | | { |
| | | try |
| | | { |
| | | Dt_OutStockLockInfo? outStockLockInfo = _outboundService.OutboundStockLockInfoService.Repository.QueryFirst(x => x.TaskNum == task.TaskNum); |
| | | Dt_OutboundOrder? outboundOrder = null; |
| | | int overCount = 0; |
| | | if (outStockLockInfo != null) |
| | | { |
| | | Dt_OutboundOrderDetail outboundOrderDetail = _outboundService.OutboundOrderDetailService.Repository.QueryFirst(x => x.Id == outStockLockInfo.OrderDetailId); |
| | | if (outboundOrderDetail != null) |
| | | { |
| | | outboundOrder = Db.Queryable<Dt_OutboundOrder>().Where(x => x.Id == outboundOrderDetail.OrderId).Includes(x => x.Details).First(); |
| | | if (outboundOrder == null) throw new Exception("åºåºåä¸åå¨"); |
| | | outboundOrderDetail.OverOutQuantity++; |
| | | overCount = outboundOrder.Details.Where(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()).Count(); |
| | | if (outboundOrderDetail.OverOutQuantity == outboundOrderDetail.OrderQuantity) |
| | | { |
| | | outboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt(); |
| | | overCount++; |
| | | } |
| | | } |
| | | outStockLockInfo.Status = OutLockStockStatusEnum.åºåºå®æ.ObjToInt(); |
| | | } |
| | | Db.Ado.BeginTran(); |
| | | if (outboundOrder != null && outboundOrder.Details.Count == overCount) |
| | | { |
| | | outboundOrder.OrderStatus = OutboundStatusEnum.åºåºå®æ.ObjToInt(); |
| | | _outboundService.OutboundOrderService.Repository.DeleteAndMoveIntoHty(outboundOrder, App.User.UserId == 0 ? OperateType.èªå¨å®æ : OperateType.äººå·¥å®æ); |
| | | _outboundService.OutboundOrderDetailService.Repository.DeleteAndMoveIntoHty(outboundOrder.Details, App.User.UserId == 0 ? OperateType.èªå¨å®æ : OperateType.äººå·¥å®æ); |
| | | } |
| | | BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.èªå¨å®æ : OperateType.äººå·¥å®æ); |
| | | _outboundService.OutboundStockLockInfoService.Repository.UpdateData(outStockLockInfo); |
| | | Db.Ado.CommitTran(); |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Db.Ado.RollbackTran(); |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// æ´æ°ç§»åºä»»å¡ç¶æå®æ |
| | | /// </summary> |
| | | /// <param name="task"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent UpdateTaskStatusRelocationCarFinish(Dt_Task task) |
| | | { |
| | | try |
| | | { |
| | | Dt_LocationInfo Sourcelocation = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.SourceAddress);//èµ·å§è´§ä½ |
| | | Dt_LocationInfo Targetlocation = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress);//ç®æ è´§ä½ |
| | | Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode);//æçåºå |
| | | Sourcelocation.CurrentQty--; |
| | | Targetlocation.CurrentQty++; |
| | | stockInfo.LocationCode = Targetlocation.LocationCode; |
| | | stockInfo.SerialNumber = Targetlocation.CurrentQty; |
| | | if (Sourcelocation.CurrentQty == 0) Sourcelocation.LocationStatus = LocationStatusEnum.Free.ObjToInt(); |
| | | Dt_Task _Task = BaseDal.QueryFirst(x => x.TaskNum != task.TaskNum && x.TaskType == task.TaskType && x.SourceAddress == Sourcelocation.LocationCode && x.TargetAddress == Targetlocation.LocationCode); |
| | | if (_Task == null) |
| | | { |
| | | if (Targetlocation.CurrentQty == Targetlocation.MaxQty) Targetlocation.LocationStatus = LocationStatusEnum.Fullload.ObjToInt(); |
| | | else Targetlocation.LocationStatus = LocationStatusEnum.InStock.ObjToInt(); |
| | | if (Sourcelocation.CurrentQty == 0) Sourcelocation.LocationStatus = LocationStatusEnum.Free.ObjToInt(); |
| | | } |
| | | task.CurrentAddress = task.NextAddress; |
| | | task.NextAddress = string.Empty; |
| | | task.ModifyDate = DateTime.Now; |
| | | task.Modifier = "System"; |
| | | Db.Ado.BeginTran(); |
| | | _basicService.LocationInfoService.Repository.UpdateData(Sourcelocation); |
| | | _basicService.LocationInfoService.Repository.UpdateData(Targetlocation); |
| | | _stockService.StockInfoService.Repository.UpdateData(stockInfo); |
| | | //BaseDal.DeleteAndMoveIntoHty(task, OperateType.èªå¨å®æ); |
| | | BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.èªå¨å®æ : OperateType.äººå·¥å®æ); |
| | | Db.Ado.CommitTran(); |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Db.Ado.RollbackTran(); |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// æ´æ°å
¥åºä»»å¡ç¶æå®æ |
| | | /// </summary> |
| | | /// <param name="WMStask"></param> |
| | | /// <returns></returns> |
| | |
| | | WebResponseContent content = new WebResponseContent().OK(); |
| | | try |
| | | { |
| | | Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode); |
| | | Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress); |
| | | Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode);//ç»çåºå |
| | | Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress);//è´§ä½ |
| | | var result = CheckCompleted(stockInfo, locationInfo); |
| | | if (!result.Item1) throw new Exception(result.Item2); |
| | | |
| | | |
| | | if (stockInfo.StockStatus != StockStatusEmun.å
¥åºä¸.ObjToInt()) throw new Exception($"æç[{task.PalletCode}],该ç»çç¶æä¸å¯å
¥åº"); |
| | | stockInfo.StockStatus = StockStatusEmun.å·²å
¥åº.ObjToInt(); |
| | | locationInfo.CurrentQty++; |
| | | locationInfo.LocationStatus = locationInfo.MaxQty - locationInfo.CurrentQty == 0 ? LocationStatusEnum.Fullload.ObjToInt() : LocationStatusEnum.InStock.ObjToInt(); |
| | | using (TransactionScope scope = new TransactionScope()) |
| | | Dt_StockInfoDetail stockInfoDetail = stockInfo.Details.FirstOrDefault(x => x.StockId == stockInfo.Id); |
| | | if (task.TaskType == TaskTypeEnum.PalletInbound.ObjToInt()) |
| | | { |
| | | BaseDal.UpdateData(task); |
| | | stockInfo.SerialNumber = locationInfo.CurrentQty; |
| | | stockInfo.InDate = DateTime.Now; |
| | | stockInfo.StockStatus = StockStatusEmun.å·²å
¥åº.ObjToInt(); |
| | | stockInfoDetail.Status = StockStatusEmun.å·²å
¥åº.ObjToInt(); |
| | | locationInfo.LocationStatus = LocationStatusEnum.Pallet.ObjToInt(); |
| | | task.CurrentAddress = task.NextAddress; |
| | | task.NextAddress = string.Empty; |
| | | Db.Ado.BeginTran(); |
| | | BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.èªå¨å®æ : OperateType.äººå·¥å®æ); |
| | | _basicService.LocationInfoService.Repository.UpdateData(locationInfo); |
| | | _stockService.StockInfoService.Repository.UpdateData(stockInfo); |
| | | scope.Complete(); |
| | | _stockService.StockInfoDetailService.Repository.UpdateData(stockInfoDetail); |
| | | Db.Ado.CommitTran(); |
| | | return content; |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | /// <summary> |
| | | /// æ´æ°ä»»å¡ç¶ææ§è¡ |
| | | /// </summary> |
| | | /// <param name="WMStask"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent UpdateTaskStatusExecuting(Dt_Task task) |
| | | { |
| | | WebResponseContent content = new WebResponseContent().OK(); |
| | | try |
| | | { |
| | | #region å
¥åºå |
| | | Dt_InboundOrder inboundOrder = _inboundService.InbounOrderService.GetInboundOrder(stockInfoDetail.OrderNo); |
| | | if (inboundOrder == null || inboundOrder.Details == null) throw new Exception($"æªæ¾å°æç[{task.PalletCode}]çå
¥åºåæç»ä¿¡æ¯"); |
| | | Dt_InboundOrderDetail inboundOrderDetail = inboundOrder.Details.FirstOrDefault(x => x.BatchNo == stockInfoDetail.BatchNo && x.MaterielCode == stockInfoDetail.MaterielCode); |
| | | inboundOrderDetail.OverInQuantity++; |
| | | inboundOrderDetail.OrderDetailStatus = inboundOrderDetail.OverInQuantity == inboundOrderDetail.OrderQuantity ? OrderDetailStatusEnum.Over.ObjToInt() : OrderDetailStatusEnum.GroupAndInbound.ObjToInt(); |
| | | |
| | | if (inboundOrder.Details.FirstOrDefault(x => x.OrderDetailStatus != OrderDetailStatusEnum.Over.ObjToInt()) == null) |
| | | { |
| | | inboundOrder.OrderStatus = InboundStatusEnum.å
¥åºå®æ.ObjToInt(); |
| | | } |
| | | else if (inboundOrder.OrderStatus == InboundStatusEnum.æªå¼å§.ObjToInt()) |
| | | { |
| | | inboundOrder.OrderStatus = InboundStatusEnum.å
¥åºä¸.ObjToInt(); |
| | | } |
| | | #endregion |
| | | |
| | | List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.Repository.LocationCodesGetStockInfos(new List<string> { stockInfo.LocationCode }).Where(x => x.StockStatus == StockStatusEmun.å·²å
¥åº.ObjToInt()).ToList(); |
| | | stockInfo.SerialNumber = stockInfos.Count + 1; |
| | | stockInfo.InDate = DateTime.Now; |
| | | stockInfo.StockStatus = StockStatusEmun.å·²å
¥åº.ObjToInt(); |
| | | stockInfoDetail.Status = StockStatusEmun.å·²å
¥åº.ObjToInt(); |
| | | int beforeStatus = locationInfo.LocationStatus; |
| | | locationInfo.LocationStatus = locationInfo.MaxQty - locationInfo.CurrentQty == 0 ? LocationStatusEnum.Fullload.ObjToInt() : LocationStatusEnum.InStock.ObjToInt(); |
| | | task.CurrentAddress = task.NextAddress; |
| | | task.NextAddress = string.Empty; |
| | | Db.Ado.BeginTran(); |
| | | #region ä»»å¡åå
¥åºå |
| | | BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.èªå¨å®æ : OperateType.äººå·¥å®æ); |
| | | if (inboundOrder.OrderStatus != InboundStatusEnum.å
¥åºå®æ.ObjToInt()) |
| | | { |
| | | _inboundService.InbounOrderService.Repository.UpdateData(inboundOrder); |
| | | _inboundService.InboundOrderDetailService.Repository.UpdateData(inboundOrderDetail); |
| | | } |
| | | else |
| | | { |
| | | _inboundService.InbounOrderService.Repository.DeleteAndMoveIntoHty(inboundOrder, OperateType.èªå¨å®æ); |
| | | _inboundService.InboundOrderDetailService.Repository.DeleteAndMoveIntoHty(inboundOrder.Details, OperateType.èªå¨å®æ); |
| | | } |
| | | #endregion |
| | | _basicService.LocationInfoService.Repository.UpdateData(locationInfo); |
| | | _stockService.StockInfoService.Repository.UpdateData(stockInfo); |
| | | _stockService.StockInfoDetailService.Repository.UpdateData(stockInfoDetail); |
| | | //_recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Inbound.ObjToInt(), stockInfo.Details.FirstOrDefault()?.OrderNo ?? "", task.TaskNum); |
| | | Db.Ado.CommitTran(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Db.Ado.RollbackTran(); |
| | | content.Error(ex.Message); |
| | | } |
| | | return content; |