| | |
| | | using Serilog.Core; |
| | | using System.Diagnostics.CodeAnalysis; |
| | | using WIDESEAWCS_Common.TaskEnum; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.Enums; |
| | | using WIDESEAWCS_DTO; |
| | | using WIDESEAWCS_DTO.TaskInfo; |
| | | using WIDESEAWCS_Model.Models; |
| | | using WIDESEAWCS_QuartzJob; |
| | | using WIDESEAWCS_QuartzJob.Models; |
| | | using WIDESEAWCS_QuartzJob.Service; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.Enums; |
| | | using WIDESEAWCS_Model.Models; |
| | | using WIDESEAWCS_QuartzJob; |
| | | using WIDESEAWCS_QuartzJob.Models; |
| | | using WIDESEAWCS_QuartzJob.Service; |
| | | using WIDESEAWCS_Tasks; |
| | | |
| | | namespace WIDESEAWCS_TaskInfoService; |
| | | |
| | |
| | | /// <returns></returns> |
| | | public WebResponseContent UpdateTaskStatusToNext([NotNull] Dt_Task task) |
| | | { |
| | | int oldState = task.TaskStatus; |
| | | |
| | | var result = task.TaskType.GetTaskTypeGroup() switch |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | TaskTypeGroup.OutbondGroup => _outboundTaskFlowService.MoveToNextStatus(task), |
| | | TaskTypeGroup.InboundGroup => _inboundTaskFlowService.MoveToNextStatus(task), |
| | | TaskTypeGroup.RelocationGroup => _relocationTaskFlowService.MoveToNextStatus(task), |
| | | TaskTypeGroup.OtherGroup => _robotTaskFlowService.MoveToNextStatus(task), |
| | | _ => WebResponseContent.Instance.Error($"任务类型错误,未找到该任务类型,任务号:【{task.TaskNum}】,任务类型:【{task.TaskType}】") |
| | | }; |
| | | int oldState = task.TaskStatus; |
| | | |
| | | if (!result.Status) |
| | | return result; |
| | | var result = task.TaskType.GetTaskTypeGroup() switch |
| | | { |
| | | TaskTypeGroup.OutbondGroup => _outboundTaskFlowService.MoveToNextStatus(task), |
| | | TaskTypeGroup.InboundGroup => _inboundTaskFlowService.MoveToNextStatus(task), |
| | | TaskTypeGroup.RelocationGroup => _relocationTaskFlowService.MoveToNextStatus(task), |
| | | TaskTypeGroup.OtherGroup => _robotTaskFlowService.MoveToNextStatus(task), |
| | | _ => content.Error($"任务类型错误,未找到该任务类型,任务号:【{task.TaskNum}】,任务类型:【{task.TaskType}】") |
| | | }; |
| | | |
| | | // 出库完成线体节点时,可能需要接收入库新任务。 |
| | | if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup |
| | | && result.Data is List<WMSTaskDTO> wmsTasks |
| | | && wmsTasks.Count > 0) |
| | | { |
| | | WebResponseContent content = ReceiveWMSTask(wmsTasks); |
| | | if (!content.Status) |
| | | return content; |
| | | if (!result.Status) |
| | | return result; |
| | | |
| | | // 出库完成线体节点时,可能需要接收入库新任务。 |
| | | if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup |
| | | && result.Data is List<WMSTaskDTO> wmsTasks |
| | | && wmsTasks.Count > 0) |
| | | { |
| | | content = ReceiveWMSTask(wmsTasks); |
| | | if (!content.Status) |
| | | return content; |
| | | } |
| | | |
| | | // 更新任务数据 |
| | | task.ModifyDate = DateTime.Now; |
| | | task.Modifier = "System"; |
| | | if (task.TaskStatus == (int)TaskOutStatusEnum.Line_OutFinish) |
| | | { |
| | | BaseDal.DeleteAndMoveIntoHty(task, OperateTypeEnum.自动完成); |
| | | } |
| | | else |
| | | { |
| | | BaseDal.UpdateData(task); |
| | | } |
| | | |
| | | // 记录任务执行详情 |
| | | string logMessage = App.User.UserId > 0 |
| | | ? $"人工手动将任务状态从【{oldState}】跳转到【{task.TaskStatus}】" |
| | | : $"系统自动流程,任务状态从【{oldState}】转到【{task.TaskStatus}】"; |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, logMessage); |
| | | |
| | | return content.OK(); |
| | | } |
| | | |
| | | // 更新任务数据 |
| | | task.ModifyDate = DateTime.Now; |
| | | task.Modifier = "System"; |
| | | if (task.TaskStatus == (int)TaskOutStatusEnum.Line_OutFinish) |
| | | catch (Exception ex) |
| | | { |
| | | BaseDal.DeleteAndMoveIntoHty(task, OperateTypeEnum.自动完成); |
| | | QuartzLogHelper.LogError(Logger.None, $"UpdateTaskStatusToNext 更新将任务状态修改为下一个状态失败,任务号:【{task.TaskNum}】,错误信息:【{ex.Message}】", "UpdateTaskStatusToNext"); |
| | | return content.Error(ex.Message); |
| | | } |
| | | else |
| | | { |
| | | BaseDal.UpdateData(task); |
| | | } |
| | | |
| | | // 记录任务执行详情 |
| | | string logMessage = App.User.UserId > 0 |
| | | ? $"人工手动将任务状态从【{oldState}】跳转到【{task.TaskStatus}】" |
| | | : $"系统自动流程,任务状态从【{oldState}】转到【{task.TaskStatus}】"; |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, logMessage); |
| | | |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | string oldCurrentPos = task.CurrentAddress; |
| | | string oldNextPos = task.NextAddress; |
| | | |
| | | |
| | | Dt_Router routers = _routerService.QueryNextRoute(oldNextPos, task.TargetAddress); |
| | | if (routers == null) throw new Exception($"未找到设备路由信息"); |
| | | |
| | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Console.WriteLine($"UpdatePosition 更新任务位置失败,任务号:【{taskNum}】,错误信息:【{ex.Message}】"); |
| | | QuartzLogHelper.LogError(Logger.None, $"UpdatePosition 更新任务位置失败,任务号:【{taskNum}】,错误信息:【{ex.Message}】", "UpdatePosition"); |
| | | //Console.WriteLine($"UpdatePosition 更新任务位置失败,任务号:【{taskNum}】,错误信息:【{ex.Message}】"); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据任务号、当前地址更新任务位置信息 |
| | | /// </summary> |
| | | /// <param name="taskNum">任务号</param> |
| | | /// <param name="currentAddress">当前地址</param> |
| | | /// <param name="nextAddress">下一地址</param> |
| | | /// <returns></returns> |
| | | public Dt_Task? UpdatePosition(int taskNum, string currentAddress, string nextAddress) |
| | | { |
| | | try |
| | | { |
| | | if (string.IsNullOrEmpty(currentAddress)) |
| | | throw new ArgumentNullException(nameof(currentAddress), "当前地址不能为空"); |
| | | |
| | | Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum && x.CurrentAddress == currentAddress); |
| | | if (task == null) throw new Exception($"未找到该任务信息,任务号:【{taskNum}】"); |
| | | |
| | | string oldCurrentPos = task.CurrentAddress; |
| | | string oldNextPos = task.NextAddress; |
| | | |
| | | task.CurrentAddress = task.NextAddress; |
| | | task.NextAddress = nextAddress; |
| | | |
| | | task.ModifyDate = DateTime.Now; |
| | | task.Modifier = "System"; |
| | | BaseDal.UpdateData(task); |
| | | |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, $"系统自动流程,更新当前位置【{oldCurrentPos} ----> {task.CurrentAddress}】和下一位置【{oldNextPos} ----> {task.NextAddress}】"); |
| | | return task; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | QuartzLogHelper.LogError(Logger.None, $"UpdatePosition 更新任务位置失败,任务号:【{taskNum}】,错误信息:【{ex.Message}】", "UpdatePosition"); |
| | | } |
| | | return null; |
| | | } |