| | |
| | | #region << 版 本 注 释 >> |
| | | |
| | | /*---------------------------------------------------------------- |
| | | * 命名空间:WIDESEAWCS_TaskInfoService |
| | | * 创建者:胡童庆 |
| | | * 创建时间:2024/8/2 16:13:36 |
| | | * 版本:V1.0.0 |
| | | * 描述: |
| | | * |
| | | * ---------------------------------------------------------------- |
| | | * 修改人: |
| | | * 修改时间: |
| | | * 版本:V1.0.1 |
| | | * 修改说明: |
| | | * |
| | | *----------------------------------------------------------------*/ |
| | | |
| | | #endregion << 版 本 注 释 >> |
| | | |
| | | using AutoMapper; |
| | | using MapsterMapper; |
| | | using SqlSugar; |
| | | using System.Diagnostics.CodeAnalysis; |
| | | using System.Text.Json; |
| | | using WIDESEA_Core; |
| | | using WIDESEAWCS_Common.HttpEnum; |
| | | using WIDESEAWCS_Common.TaskEnum; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.BaseServices; |
| | | using WIDESEAWCS_Core.Enums; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_Core.Http; |
| | | using WIDESEAWCS_DTO; |
| | | using WIDESEAWCS_DTO.Stock; |
| | | using WIDESEAWCS_DTO.TaskInfo; |
| | | using WIDESEAWCS_ITaskInfoRepository; |
| | | using WIDESEAWCS_ITaskInfoService; |
| | | using WIDESEAWCS_Model.Models; |
| | | using WIDESEAWCS_QuartzJob; |
| | | using WIDESEAWCS_QuartzJob.DeviceBase; |
| | | using WIDESEAWCS_QuartzJob.DTO; |
| | | using WIDESEAWCS_QuartzJob.Models; |
| | | using WIDESEAWCS_QuartzJob.Service; |
| | | |
| | | namespace WIDESEAWCS_TaskInfoService |
| | | namespace WIDESEAWCS_TaskInfoService; |
| | | |
| | | /// <summary> |
| | | /// 任务服务 - 核心业务逻辑 |
| | | /// </summary> |
| | | public partial class TaskService : ServiceBase<Dt_Task, ITaskRepository>, ITaskService |
| | | { |
| | | public class TaskService : ServiceBase<Dt_Task, ITaskRepository>, ITaskService |
| | | private readonly IRouterService _routerService; |
| | | private readonly ITaskExecuteDetailService _taskExecuteDetailService; |
| | | private readonly ITaskExecuteDetailRepository _taskExecuteDetailRepository; |
| | | private readonly IMapper _mapper; |
| | | private readonly IOutboundTaskFlowService _outboundTaskFlowService; |
| | | private readonly IInboundTaskFlowService _inboundTaskFlowService; |
| | | private readonly IRelocationTaskFlowService _relocationTaskFlowService; |
| | | private readonly IRobotTaskFlowService _robotTaskFlowService; |
| | | |
| | | private Dictionary<string, OrderByType> _taskOrderBy = new() |
| | | { |
| | | private readonly IRouterService _routerService; |
| | | private readonly ITaskExecuteDetailService _taskExecuteDetailService; |
| | | private readonly ITaskExecuteDetailRepository _taskExecuteDetailRepository; |
| | | private readonly IMapper _mapper; |
| | | private readonly HttpClientHelper _httpClientHelper; |
| | | {nameof(Dt_Task.Grade),OrderByType.Desc }, |
| | | {nameof(Dt_Task.CreateDate),OrderByType.Asc}, |
| | | }; |
| | | |
| | | private Dictionary<string, OrderByType> _taskOrderBy = new() |
| | | { |
| | | {nameof(Dt_Task.Grade),OrderByType.Desc }, |
| | | {nameof(Dt_Task.CreateDate),OrderByType.Asc}, |
| | | }; |
| | | public Dictionary<string, OrderByType> TaskOrderBy |
| | | { get { return _taskOrderBy; } set { _taskOrderBy = value; } } |
| | | |
| | | public Dictionary<string, OrderByType> TaskOrderBy |
| | | { get { return _taskOrderBy; } set { _taskOrderBy = value; } } |
| | | public List<int> TaskInboundTypes => typeof(TaskInboundTypeEnum).GetEnumIndexList(); |
| | | |
| | | public List<int> TaskInboundTypes => typeof(TaskInboundTypeEnum).GetEnumIndexList(); |
| | | public List<int> TaskOutboundTypes => typeof(TaskOutboundTypeEnum).GetEnumIndexList(); |
| | | |
| | | public List<int> TaskOutboundTypes => typeof(TaskOutboundTypeEnum).GetEnumIndexList(); |
| | | public List<int> TaskRelocationTypes => typeof(TaskRelocationTypeEnum).GetEnumIndexList(); |
| | | |
| | | public List<int> TaskRobotTypes => typeof(TaskOtherTypeEnum).GetEnumIndexList(); |
| | | public List<int> TaskRobotTypes => typeof(TaskOtherTypeEnum).GetEnumIndexList(); |
| | | |
| | | public TaskService(ITaskRepository BaseDal, IRouterService routerService, ITaskExecuteDetailService taskExecuteDetailService, ITaskExecuteDetailRepository taskExecuteDetailRepository, IMapper mapper, HttpClientHelper httpClientHelper) : base(BaseDal) |
| | | { |
| | | _routerService = routerService; |
| | | _taskExecuteDetailService = taskExecuteDetailService; |
| | | _taskExecuteDetailRepository = taskExecuteDetailRepository; |
| | | _mapper = mapper; |
| | | _httpClientHelper = httpClientHelper; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 接收WMS任务信息 |
| | | /// </summary> |
| | | /// <param name="taskDTOs">WMS任务对象集合</param> |
| | | /// <returns>返回处理结果</returns> |
| | | public WebResponseContent ReceiveWMSTask([NotNull] List<WMSTaskDTO> taskDTOs) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | List<Dt_Task> tasks = new List<Dt_Task>(); |
| | | foreach (var item in taskDTOs) |
| | | { |
| | | if (BaseDal.QueryFirst(x => x.TaskNum == item.TaskNum || x.PalletCode == item.PalletCode) != null) |
| | | { |
| | | continue; |
| | | } |
| | | Dt_Task task = _mapper.Map<Dt_Task>(item); |
| | | task.Creater = "WMS"; |
| | | if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup) |
| | | { |
| | | List<Dt_Router> routers = _routerService.QueryNextRoutes(item.RoadWay, item.TargetAddress); |
| | | //暂不考虑多路径 |
| | | if (routers.Count > 0) |
| | | { |
| | | task.TaskState = (int)TaskOutStatusEnum.OutNew; |
| | | task.CurrentAddress = item.SourceAddress; |
| | | task.NextAddress = routers.FirstOrDefault().ChildPosi; |
| | | } |
| | | } |
| | | else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup) |
| | | { |
| | | List<Dt_Router> routers = _routerService.QueryNextRoutes(item.SourceAddress, item.TargetAddress); |
| | | //暂不考虑多路径 |
| | | if (routers.Count > 0) |
| | | { |
| | | task.TaskState = (int)TaskInStatusEnum.InNew; |
| | | task.CurrentAddress = item.SourceAddress; |
| | | task.NextAddress = routers.FirstOrDefault().ChildPosi; |
| | | } |
| | | } |
| | | tasks.Add(task); |
| | | } |
| | | BaseDal.AddData(tasks); |
| | | |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(tasks.Select(x => x.TaskNum).ToList(), "接收WMS任务"); |
| | | |
| | | content = WebResponseContent.Instance.OK("成功"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error($"任务接收错误,错误信息:{ex.Message}"); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据托盘号、起始地址向WMS请求任务 |
| | | /// </summary> |
| | | /// <param name="palletCode">托盘号</param> |
| | | /// <param name="sourceAddress">起始地址</param> |
| | | /// <returns></returns> |
| | | public WebResponseContent RequestWMSTask(string palletCode, string sourceAddress) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | WMSTaskDTO taskDTO = new WMSTaskDTO() |
| | | { |
| | | TaskNum = Convert.ToInt32(DateTime.Now.ToString("HHmmss")), |
| | | Grade = 1, |
| | | PalletCode = palletCode, |
| | | RoadWay = "SC01", |
| | | SourceAddress = sourceAddress, |
| | | TargetAddress = "SC01", |
| | | TaskState = (int)TaskInStatusEnum.InNew, |
| | | Id = 0, |
| | | TaskType = (int)TaskInboundTypeEnum.Inbound |
| | | }; |
| | | |
| | | content = ReceiveWMSTask(new List<WMSTaskDTO> { taskDTO }); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据设备编号、当前地址查询输送线未执行的任务 |
| | | /// </summary> |
| | | /// <param name="deviceNo">设备编号</param> |
| | | /// <param name="currentAddress">当前地址</param> |
| | | /// <returns></returns> |
| | | public Dt_Task QueryConveyorLineTask(string deviceNo, string currentAddress) |
| | | { |
| | | return BaseDal.QueryFirst(x => (TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskInStatusEnum.InNew || TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.SC_OutFinish) && x.CurrentAddress == currentAddress, TaskOrderBy); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据任务号、下一地址查询输送线执行中的任务 |
| | | /// </summary> |
| | | /// <param name="taskNum">任务号</param> |
| | | /// <param name="nextAddress">下一地址</param> |
| | | /// <returns></returns> |
| | | public Dt_Task QueryExecutingConveyorLineTask(int taskNum, string nextAddress) |
| | | { |
| | | if (string.IsNullOrEmpty(nextAddress)) |
| | | throw new ArgumentNullException(nameof(nextAddress), "下一地址不能为空"); |
| | | |
| | | return BaseDal.QueryFirst(x => x.TaskNum == taskNum && x.NextAddress == nextAddress && (x.TaskState == (int)TaskInStatusEnum.Line_InExecuting || x.TaskState == (int)TaskOutStatusEnum.Line_OutExecuting), TaskOrderBy); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据任务号、当前地址查询输送线完成的任务 |
| | | /// </summary> |
| | | /// <param name="taskNum">任务号</param> |
| | | /// <param name="currentAddress">当前地址</param> |
| | | /// <returns></returns> |
| | | public Dt_Task QueryCompletedConveyorLineTask(int taskNum, string currentAddress) |
| | | { |
| | | if (string.IsNullOrEmpty(currentAddress)) |
| | | throw new ArgumentNullException(nameof(currentAddress), "当前地址不能为空"); |
| | | |
| | | return BaseDal.QueryFirst(x => x.TaskNum == taskNum && x.CurrentAddress == currentAddress && (x.TaskState == (int)TaskInStatusEnum.Line_InFinish || x.TaskState == (int)TaskOutStatusEnum.Line_OutFinish), TaskOrderBy); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据设备编号、任务类型分组(可选)按照优先级以及创建时间排序查询任务池新增的任务 |
| | | /// </summary> |
| | | /// <param name="deviceNo">设备编号</param> |
| | | /// <param name="taskTypeGroup">任务类型分组(可选)</param> |
| | | /// <returns></returns> |
| | | public Dt_Task? QuertStackerCraneTask(string deviceNo, TaskTypeGroup? taskTypeGroup = null) |
| | | { |
| | | if (taskTypeGroup == null) |
| | | return BaseDal.QueryFirst(x => x.Roadway == deviceNo && (TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskInStatusEnum.Line_InFinish || TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.OutNew), TaskOrderBy); |
| | | if (taskTypeGroup.Value == TaskTypeGroup.InboundGroup) |
| | | return BaseDal.QueryFirst(x => x.Roadway == deviceNo && TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskInStatusEnum.Line_InFinish, TaskOrderBy); |
| | | if (taskTypeGroup.Value == TaskTypeGroup.OutbondGroup) |
| | | return BaseDal.QueryFirst(x => x.Roadway == deviceNo && TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.OutNew, TaskOrderBy); |
| | | return null; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据设备编号、当前地址按照优先级以及创建时间排序查询任务池新增的任务 |
| | | /// </summary> |
| | | /// <param name="deviceNo">设备编号</param> |
| | | /// <param name="currentAddress">当前地址</param> |
| | | /// <returns>返回任务实体对象,可能为null</returns> |
| | | public Dt_Task QueryStackerCraneTask(string deviceNo, string currentAddress = "") |
| | | { |
| | | if (string.IsNullOrEmpty(currentAddress)) |
| | | return BaseDal.QueryFirst(x => x.Roadway == deviceNo && (TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskInStatusEnum.Line_InFinish || TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.OutNew), TaskOrderBy); |
| | | else |
| | | return BaseDal.QueryFirst(x => x.Roadway == deviceNo && x.CurrentAddress == currentAddress && (TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskInStatusEnum.Line_InFinish || TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.OutNew), TaskOrderBy); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据设备编号、当前地址按照优先级以及创建时间排序查询任务池入库类型的新增的任务 |
| | | /// </summary> |
| | | /// <param name="deviceNo">设备编号</param> |
| | | /// <param name="currentAddress">当前地址</param> |
| | | /// <returns>返回任务实体对象,可能为null</returns> |
| | | public Dt_Task QueryStackerCraneInTask(string deviceNo, string currentAddress = "") |
| | | { |
| | | if (string.IsNullOrEmpty(currentAddress)) |
| | | return BaseDal.QueryFirst(x => x.Roadway == deviceNo && TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskInStatusEnum.Line_InFinish, TaskOrderBy); |
| | | else |
| | | return BaseDal.QueryFirst(x => x.Roadway == deviceNo && TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskInStatusEnum.Line_InFinish && x.CurrentAddress == currentAddress, TaskOrderBy); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据设备编号、当前地址按照优先级以及创建时间排序查询任务池出库类型的新增的任务 |
| | | /// </summary> |
| | | /// <param name="deviceNo">设备编号</param> |
| | | /// <param name="currentAddress">当前地址</param> |
| | | /// <returns>返回任务实体对象,可能为null</returns> |
| | | public Dt_Task QueryStackerCraneOutTask(string deviceNo, string currentAddress = "") |
| | | { |
| | | if (string.IsNullOrEmpty(currentAddress)) |
| | | return BaseDal.QueryFirst(x => x.Roadway == deviceNo && TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.OutNew, TaskOrderBy); |
| | | else |
| | | return BaseDal.QueryFirst(x => x.Roadway == deviceNo && TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.OutNew && x.CurrentAddress == currentAddress, TaskOrderBy); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据设备编号、当前地址按照优先级以及创建时间排序查询任务池出库类型的新增的任务 |
| | | /// </summary> |
| | | /// <param name="deviceNo">设备编号</param> |
| | | /// <param name="currentAddress">当前地址</param> |
| | | /// <returns>返回任务实体对象集合,可能为null</returns> |
| | | public List<Dt_Task> QueryStackerCraneOutTasks(string deviceNo, List<string> outStationCodes) |
| | | { |
| | | return BaseDal.QueryData(x => x.Roadway == deviceNo && TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.OutNew && outStationCodes.Contains(x.CurrentAddress), TaskOrderBy); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 更新任务异常信息显示 |
| | | /// </summary> |
| | | /// <param name="taskNum">任务号</param> |
| | | /// <param name="message">异常信息</param> |
| | | public WebResponseContent UpdateTaskExceptionMessage(int taskNum, string message) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | if (string.IsNullOrEmpty(message)) |
| | | throw new ArgumentNullException(nameof(message), "异常信息不能为空"); |
| | | |
| | | Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum); |
| | | if (task == null) return WebResponseContent.Instance.Error($"未找到该任务信息,任务号:【{taskNum}】"); |
| | | if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup) |
| | | { |
| | | task.TaskState = (int)TaskOutStatusEnum.OutPending; |
| | | } |
| | | else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup) |
| | | { |
| | | task.TaskState = (int)TaskInStatusEnum.InPending; |
| | | } |
| | | task.ExceptionMessage = message; |
| | | task.ModifyDate = DateTime.Now; |
| | | BaseDal.UpdateData(task); |
| | | |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, task.ExceptionMessage); |
| | | |
| | | content = WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 更新任务状态信息,并同步至WMS |
| | | /// </summary> |
| | | /// <param name="taskNum">任务号</param> |
| | | /// <param name="status">任务状态</param> |
| | | public void UpdateTaskStatus(int taskNum, int status) |
| | | { |
| | | Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum); |
| | | if (task == null) return; |
| | | task.TaskState = status; |
| | | task.ModifyDate = DateTime.Now; |
| | | BaseDal.UpdateData(task); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 将任务状态修改为下一个状态 |
| | | /// </summary> |
| | | /// <param name="taskNum">任务号</param> |
| | | public WebResponseContent UpdateTaskStatusToNext(int taskNum) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum); |
| | | if (task == null) return WebResponseContent.Instance.Error($"未找到该任务信息,任务号:【{taskNum}】"); |
| | | return UpdateTaskStatusToNext(task); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 将任务状态修改为下一个状态 |
| | | /// </summary> |
| | | /// <param name="task">任务实体对象</param> |
| | | /// <returns></returns> |
| | | public WebResponseContent UpdateTaskStatusToNext([NotNull] Dt_Task task) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | int oldState = task.TaskState; |
| | | if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup) |
| | | { |
| | | if (task.TaskState >= (int)TaskOutStatusEnum.OutFinish) |
| | | { |
| | | return content = WebResponseContent.Instance.Error($"该任务状态不可跳转到下一步,任务号:【{task.TaskNum}】,任务状态:【{task.TaskState}】"); |
| | | } |
| | | |
| | | int nextStatus = task.TaskState.GetNextNotCompletedStatus<TaskOutStatusEnum>(); |
| | | |
| | | task.TaskState = nextStatus; |
| | | } |
| | | else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup) |
| | | { |
| | | if (task.TaskState >= (int)TaskInStatusEnum.InFinish) |
| | | { |
| | | return content = WebResponseContent.Instance.Error($"该任务状态不可跳转到下一步,任务号:【{task.TaskNum}】,任务状态:【{task.TaskState}】"); |
| | | } |
| | | |
| | | int nextStatus = task.TaskState.GetNextNotCompletedStatus<TaskInStatusEnum>(); |
| | | task.TaskState = nextStatus; |
| | | |
| | | if (task.TaskState == (int)TaskInStatusEnum.Line_InFinish) |
| | | { |
| | | // 调用WMS系统接口,获取最终目标地址 |
| | | CreateTaskDto taskDto = new CreateTaskDto() |
| | | { |
| | | PalletCode = task.PalletCode, |
| | | }; |
| | | |
| | | var result = _httpClientHelper.Post<WebResponseContent>(nameof(ConfigKey.GetTasksLocation), taskDto.ToJson(), nameof(ConfigKey.GetTasksLocation)); |
| | | if (!result.IsSuccess && !result.Data.Status) |
| | | { |
| | | return WebResponseContent.Instance.Error($"调用WMS接口获取任务目标地址失败,任务号:【{task.TaskNum}】,错误信息:【{content.Message}】"); |
| | | } |
| | | |
| | | string wmsTargetAddress = result.Data.Data?.ToString() ?? string.Empty; |
| | | if (string.IsNullOrEmpty(wmsTargetAddress)) |
| | | { |
| | | return WebResponseContent.Instance.Error($"调用WMS接口获取任务目标地址失败,任务号:【{task.TaskNum}】,错误信息:【未获取到有效的目标地址】"); |
| | | } |
| | | |
| | | task.NextAddress = wmsTargetAddress; |
| | | task.TargetAddress = wmsTargetAddress; |
| | | task.CurrentAddress = task.NextAddress; |
| | | } |
| | | } |
| | | else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OtherGroup) |
| | | { |
| | | if (task.TaskState >= (int)TaskRobotStatusEnum.RobotNew) |
| | | { |
| | | return content = WebResponseContent.Instance.Error($"该任务状态不可跳转到下一步,任务号:【{task.TaskNum}】,任务状态:【{task.TaskState}】"); |
| | | } |
| | | |
| | | int nextStatus = task.TaskState.GetNextNotCompletedStatus<TaskRobotStatusEnum>(); |
| | | |
| | | task.TaskState = nextStatus; |
| | | } |
| | | else |
| | | { |
| | | throw new Exception($"任务类型错误,未找到该任务类型,任务号:【{task.TaskNum}】,任务类型:【{task.TaskType}】"); |
| | | } |
| | | |
| | | if (task.TaskState <= 0) |
| | | { |
| | | return content = WebResponseContent.Instance.Error($"该任务状态不可跳转到下一步,任务号:【{task.TaskNum}】,任务状态:【{task.TaskState}】"); |
| | | } |
| | | |
| | | task.ModifyDate = DateTime.Now; |
| | | task.Modifier = "System"; |
| | | BaseDal.UpdateData(task); |
| | | |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, App.User.UserId > 0 ? $"人工手动将任务状态从【{oldState}】跳转到【{task.TaskState}】" : $"系统自动流程,任务状态从【{oldState}】转到【{task.TaskState}】"); |
| | | |
| | | content = WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据任务号、当前地址更新任务位置信息 |
| | | /// </summary> |
| | | /// <param name="taskNum">任务号</param> |
| | | /// <param name="currentAddress">当前地址</param> |
| | | /// <returns></returns> |
| | | public Dt_Task? UpdatePosition(int taskNum, string currentAddress) |
| | | { |
| | | 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; |
| | | |
| | | Dt_Router routers = _routerService.QueryNextRoute(task.CurrentAddress); |
| | | if (routers == null) throw new Exception($"未找到设备路由信息"); |
| | | |
| | | task.CurrentAddress = task.NextAddress; |
| | | task.NextAddress = routers.ChildPosi; |
| | | |
| | | 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) |
| | | { |
| | | Console.WriteLine($"UpdatePosition 更新任务位置失败,任务号:【{taskNum}】,错误信息:【{ex.Message}】"); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 任务完成 |
| | | /// </summary> |
| | | /// <param name="taskNum">任务编号</param> |
| | | /// <returns>返回处理结果</returns> |
| | | public WebResponseContent StackCraneTaskCompleted(int taskNum) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum); |
| | | if (task == null) return WebResponseContent.Instance.Error($"未找到该任务信息,任务号:【{taskNum}】"); |
| | | |
| | | if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup && task.TaskState == (int)TaskOutStatusEnum.SC_OutExecuting) |
| | | { |
| | | List<Dt_Router> routers = _routerService.QueryNextRoutes(task.NextAddress, task.TargetAddress); |
| | | if (!routers.Any()) return WebResponseContent.Instance.Error($"未找到设备路由信息"); |
| | | |
| | | int nextStatus = task.TaskState.GetNextNotCompletedStatus<TaskOutStatusEnum>(); |
| | | task.TaskState = nextStatus; |
| | | task.CurrentAddress = task.NextAddress; |
| | | task.NextAddress = routers.FirstOrDefault().ChildPosi; |
| | | task.ModifyDate = DateTime.Now; |
| | | task.Modifier = "System"; |
| | | BaseDal.UpdateData(task); |
| | | |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, $"堆垛机出库完成"); |
| | | |
| | | var result = _httpClientHelper.Post<WebResponseContent>(nameof(ConfigKey.OutboundFinishTaskAsync), (new StockInfoDTO() { PalletCode = task.PalletCode, TaskNum = task.TaskNum }).ToJson()); |
| | | if (result.IsSuccess && result.Data.Status) |
| | | { |
| | | return content.Error($"通知WMS系统堆垛机出库完成成功,任务号:【{task.TaskNum}】,托盘号:【{task.PalletCode}】"); |
| | | |
| | | } |
| | | else |
| | | { |
| | | return content.Error($"通知WMS系统堆垛机出库完成失败,任务号:【{task.TaskNum}】,托盘号:【{task.PalletCode}】,错误信息:【{result.Data.Message}】"); |
| | | } |
| | | } |
| | | else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup && task.TaskState == (int)TaskInStatusEnum.SC_InExecuting) |
| | | { |
| | | int nextStatus = task.TaskState.GetNextNotCompletedStatus<TaskInStatusEnum>(); |
| | | task.TaskState = nextStatus; |
| | | task.ModifyDate = DateTime.Now; |
| | | task.Modifier = "System"; |
| | | BaseDal.UpdateData(task); |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, $"堆垛机入库完成"); |
| | | |
| | | |
| | | var result = _httpClientHelper.Post<WebResponseContent>(nameof(ConfigKey.InboundFinishTaskAsync), (new CreateTaskDto() |
| | | { |
| | | PalletCode = task.PalletCode, |
| | | }).ToJson()); |
| | | |
| | | if (result.IsSuccess && result.Data.Status) |
| | | { |
| | | return content.Error($"通知WMS系统堆垛机入库完成成功,任务号:【{task.TaskNum}】,托盘号:【{task.PalletCode}】"); |
| | | } |
| | | else |
| | | { |
| | | return content.Error($"通知WMS系统堆垛机入库完成失败,任务号:【{task.TaskNum}】,托盘号:【{task.PalletCode}】,错误信息:【{result.Data.Message}】"); |
| | | } |
| | | } |
| | | else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.RelocationGroup) |
| | | { |
| | | //todo 调用WMS移库完成 |
| | | } |
| | | else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OtherGroup) |
| | | { |
| | | } |
| | | else |
| | | { |
| | | throw new Exception($"任务类型错误,未找到该任务类型,任务号:【{taskNum}】,任务类型:【{task.TaskType}】"); |
| | | } |
| | | content = WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error($"任务完成异常,任务号:【{taskNum}】"); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 恢复挂起任务 |
| | | /// </summary> |
| | | /// <param name="taskNum">任务号</param> |
| | | /// <returns>返回处理结果</returns> |
| | | public WebResponseContent TaskStatusRecovery(int taskNum) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum); |
| | | if (task == null) return WebResponseContent.Instance.Error($"未找到该任务信息,任务号:【{taskNum}】"); |
| | | if (task.TaskState != (int)TaskInStatusEnum.InPending && task.TaskState != (int)TaskOutStatusEnum.OutPending) |
| | | { |
| | | return content = WebResponseContent.Instance.Error($"该任务状态不可恢复,任务号:【{taskNum}】,任务状态:【{task.TaskState}】"); |
| | | } |
| | | |
| | | Dt_TaskExecuteDetail taskExecuteDetail = _taskExecuteDetailRepository.QueryFirst(x => x.TaskId == task.TaskId && x.IsNormal, new Dictionary<string, OrderByType> { { nameof(Dt_TaskExecuteDetail.TaskDetailId), OrderByType.Desc } }); |
| | | if (taskExecuteDetail != null) |
| | | { |
| | | task.TaskState = taskExecuteDetail.TaskState; |
| | | } |
| | | else |
| | | { |
| | | if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup) |
| | | { |
| | | task.TaskState = (int)TaskOutStatusEnum.OutNew; |
| | | } |
| | | else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup) |
| | | { |
| | | task.TaskState = (int)TaskInStatusEnum.InNew; |
| | | } |
| | | //todo |
| | | } |
| | | |
| | | task.ExceptionMessage = string.Empty; |
| | | |
| | | BaseDal.UpdateData(task); |
| | | |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, $"人工恢复挂起任务,恢复挂起时任务状态【{task.TaskState}】"); |
| | | |
| | | content = WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 回滚任务状态 |
| | | /// </summary> |
| | | /// <param name="taskNum">任务号</param> |
| | | /// <returns>返回处理结果</returns> |
| | | public WebResponseContent RollbackTaskStatusToLast(int taskNum) |
| | | { |
| | | WebResponseContent content = new(); |
| | | try |
| | | { |
| | | Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum); |
| | | if (task == null) return WebResponseContent.Instance.Error($"未找到该任务信息,任务号:【{taskNum}】"); |
| | | |
| | | int oldState = task.TaskState; |
| | | Dt_TaskExecuteDetail taskExecuteDetail = _taskExecuteDetailRepository.QueryFirst(x => x.TaskId == task.TaskId && x.TaskState < task.TaskState && x.TaskState > 0, new Dictionary<string, OrderByType> { { nameof(Dt_TaskExecuteDetail.TaskDetailId), OrderByType.Desc } }); |
| | | if (taskExecuteDetail != null) |
| | | { |
| | | task.TaskState = taskExecuteDetail.TaskState; |
| | | task.CurrentAddress = taskExecuteDetail.CurrentAddress; |
| | | task.NextAddress = taskExecuteDetail.NextAddress; |
| | | } |
| | | else |
| | | { |
| | | return content = WebResponseContent.Instance.Error($"未找到任务明细信息,该任务状态不可回滚到上一步,任务号:【{taskNum}】,任务状态:【{task.TaskState}】"); |
| | | } |
| | | |
| | | task.ExceptionMessage = string.Empty; |
| | | |
| | | BaseDal.UpdateData(task); |
| | | |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, $"人工将任务状态从【{oldState}】回滚到【{task.TaskState}】"); |
| | | |
| | | content = WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | public override WebResponseContent DeleteData(object[] keys) |
| | | { |
| | | List<int> taskKeys = new List<int>(); |
| | | for (int i = 0; i < keys.Length; i++) |
| | | { |
| | | taskKeys.Add(Convert.ToInt32(keys[i])); |
| | | } |
| | | List<Dt_Task> tasks = BaseDal.QueryData(x => taskKeys.Contains(x.TaskId)); |
| | | BaseDal.DeleteAndMoveIntoHty(tasks, OperateTypeEnum.人工删除); |
| | | return WebResponseContent.Instance.OK($"成功删除{tasks.Count}条数据"); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据设备编号、当前地址按照优先级以及创建时间排序查询任务池新增的任务 |
| | | /// </summary> |
| | | /// <param name="deviceNo">设备编号</param> |
| | | /// <param name="currentAddress">当前地址</param> |
| | | /// <returns>返回任务实体对象,可能为null</returns> |
| | | public Dt_Task QueryRobotCraneTask(string deviceNo, string currentAddress = "") |
| | | { |
| | | if (string.IsNullOrEmpty(currentAddress)) |
| | | return BaseDal.QueryFirst(x => x.Roadway == deviceNo && (TaskRobotTypes.Contains(x.TaskType) && x.TaskState <= (int)TaskRobotStatusEnum.RobotExecuting), TaskOrderBy); |
| | | else |
| | | return BaseDal.QueryFirst(x => x.Roadway == deviceNo && TaskRobotTypes.Contains(x.TaskType) && x.CurrentAddress == currentAddress && x.TaskState <= (int)TaskRobotStatusEnum.RobotExecuting, TaskOrderBy); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取与指定任务编号关联的任务。 |
| | | /// </summary> |
| | | /// <param name="taskNum">要获取的任务的唯一标识符。</param> |
| | | /// <returns>表示指定编号任务的<see cref="Dt_Task"/>对象,如果不存在该任务则返回<c>null</c>。</returns> |
| | | public Dt_Task QueryByTaskNum(int taskNum) |
| | | { |
| | | return BaseDal.QueryFirst(x => x.TaskNum == taskNum); |
| | | } |
| | | public TaskService( |
| | | ITaskRepository BaseDal, |
| | | IRouterService routerService, |
| | | ITaskExecuteDetailService taskExecuteDetailService, |
| | | ITaskExecuteDetailRepository taskExecuteDetailRepository, |
| | | IMapper mapper, |
| | | IOutboundTaskFlowService outboundTaskFlowService, |
| | | IInboundTaskFlowService inboundTaskFlowService, |
| | | IRelocationTaskFlowService relocationTaskFlowService, |
| | | IRobotTaskFlowService robotTaskFlowService) : base(BaseDal) |
| | | { |
| | | _routerService = routerService; |
| | | _taskExecuteDetailService = taskExecuteDetailService; |
| | | _taskExecuteDetailRepository = taskExecuteDetailRepository; |
| | | _mapper = mapper; |
| | | _outboundTaskFlowService = outboundTaskFlowService; |
| | | _inboundTaskFlowService = inboundTaskFlowService; |
| | | _relocationTaskFlowService = relocationTaskFlowService; |
| | | _robotTaskFlowService = robotTaskFlowService; |
| | | } |
| | | } |