| | |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_Core.Http; |
| | | using WIDESEAWCS_DTO.Stock; |
| | | using WIDESEAWCS_DTO.TaskInfo; |
| | | using WIDESEAWCS_ITaskInfoRepository; |
| | | using WIDESEAWCS_ITaskInfoService; |
| | | using WIDESEAWCS_Model.Models; |
| | |
| | | private readonly TcpSocketServer _TcpSocket; |
| | | private static readonly ConcurrentDictionary<string, RobotSocketState> _socketStates = new(); |
| | | private static int _eventSubscribedFlag; |
| | | private readonly IRobotTaskService _taskService; |
| | | |
| | | |
| | | private readonly ITaskService _taskService; |
| | | private readonly IRobotTaskService _robottaskService; |
| | | private readonly ITaskExecuteDetailService _taskExecuteDetailService; |
| | | private readonly ITaskRepository _taskRepository; |
| | | private readonly IRouterService _routerService; |
| | | |
| | | public RobotJob(TcpSocketServer TcpSocket, IRobotTaskService taskService) |
| | | public RobotJob(TcpSocketServer TcpSocket, IRobotTaskService RobottaskService, ITaskService TaskService) |
| | | { |
| | | _TcpSocket = TcpSocket; |
| | | _taskService = taskService; |
| | | _robottaskService = RobottaskService; |
| | | this._taskService = TaskService; |
| | | } |
| | | |
| | | public async Task Execute(IJobExecutionContext context) |
| | |
| | | /// <returns></returns> |
| | | private async Task<string?> _TcpSocket_MessageReceived(string message, bool isJson, TcpClient client, RobotSocketState state) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | string messageLower = message.ToLowerInvariant(); |
| | | |
| | | if (IsSimpleCommand(messageLower, state)) |
| | | if (await IsSimpleCommandAsync(messageLower, state)) |
| | | { |
| | | return null; |
| | | } |
| | |
| | | state.LastPickPositions = positions; |
| | | |
| | | var result = await HttpRequestHelper.HTTPPostAsync(nameof(Category.WMS), stockDTO.ToJsonString(), state.CurrentTask?.RobotTaskType == 2 ? nameof(ConfigKey.ChangePalletAsync) : nameof(ConfigKey.SplitPalletAsync)); |
| | | content = JsonConvert.DeserializeObject<WebResponseContent>(result); |
| | | |
| | | if (content.Status) |
| | | if (result.Status) |
| | | { |
| | | state.CurrentAction = "PickFinished"; |
| | | } |
| | |
| | | .ToList() |
| | | }; |
| | | var result = await HttpRequestHelper.HTTPPostAsync(nameof(Category.WMS), stockDTO.ToJsonString(), nameof(ConfigKey.GroupPalletAsync)); |
| | | content = JsonConvert.DeserializeObject<WebResponseContent>(result); |
| | | |
| | | if (content.Status) |
| | | if (result.Status) |
| | | { |
| | | state.CurrentAction = "PutFinished"; |
| | | } |
| | |
| | | /// <param name="message"></param> |
| | | /// <param name="state"></param> |
| | | /// <returns></returns> |
| | | private bool IsSimpleCommand(string message, RobotSocketState state) |
| | | private async Task<bool> IsSimpleCommandAsync(string message, RobotSocketState state) |
| | | { |
| | | switch (message) |
| | | { |
| | |
| | | |
| | | case "allpickfinished": |
| | | state.CurrentAction = "AllPickFinished"; |
| | | if(state.CurrentTask?.RobotTaskType == 2|| state.CurrentTask?.RobotTaskType == 3) |
| | | if (state.CurrentTask?.RobotTaskType == 2 || state.CurrentTask?.RobotTaskType == 3) |
| | | { |
| | | // TODO 机械手取货完成,判断是否换盘、拆盘任务,创建空托盘回库任务 |
| | | await HandleInboundTaskAsync(state, useSourceAddress: true); |
| | | } |
| | | return true; |
| | | |
| | | case "allputfinished": |
| | | state.CurrentAction = "AllPutFinished"; |
| | | if (state.CurrentTask?.RobotTaskType == 1 ) |
| | | if (state.CurrentTask?.RobotTaskType == 1) |
| | | { |
| | | // TODO 机械手取货完成,判断是否组盘任务,创建组盘入库任务 |
| | | await HandleInboundTaskAsync(state, useSourceAddress: false); |
| | | } |
| | | return true; |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | private async Task HandleInboundTaskAsync(RobotSocketState state, bool useSourceAddress) |
| | | { |
| | | var currentTask = state.CurrentTask; |
| | | if (currentTask == null) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | string roadway = currentTask.RobotRoadway == "1" ? "GWSC001" : currentTask.RobotRoadway == "2" ? "HCSC001" : "SC001"; |
| | | int warehouseId = currentTask.RobotRoadway == "1" ? 1 : currentTask.RobotRoadway == "2" ? 2 : 3; |
| | | |
| | | CreateTaskDto taskDto = new CreateTaskDto |
| | | { |
| | | PalletCode = currentTask.RobotTargetAddressPalletCode ?? string.Empty, |
| | | SourceAddress = currentTask.RobotTargetAddress ?? string.Empty, |
| | | TargetAddress = currentTask.RobotTargetAddress ?? string.Empty, |
| | | Roadway = roadway, |
| | | WarehouseId = warehouseId, |
| | | PalletType = 1, |
| | | TaskType = 4 |
| | | }; |
| | | |
| | | var result = await HttpRequestHelper.HTTPPostAsync(nameof(Category.WMS), taskDto.ToJsonString(), nameof(ConfigKey.CreateTaskInboundAsync)); |
| | | if (!result.Status) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | WMSTaskDTO taskDTO = JsonConvert.DeserializeObject<WMSTaskDTO>(result.Data.ToString() ?? string.Empty) ?? new WMSTaskDTO(); |
| | | var content = _taskService.ReceiveWMSTask(new List<WMSTaskDTO> { taskDTO }); |
| | | if (!content.Status) return; |
| | | |
| | | var taskInfo = _taskService.QueryByTaskNum(taskDTO.TaskNum); |
| | | |
| | | |
| | | string targetAddress = useSourceAddress ? taskDTO.SourceAddress : taskDTO.TargetAddress; |
| | | |
| | | IDevice? device = Storage.Devices.Where(x => x.DeviceProDTOs.Select(x => x.DeviceChildCode == taskDTO.SourceAddress).FirstOrDefault()).FirstOrDefault() ?? null; |
| | | device?.Communicator.Write(nameof(ConveyorLineDBNameNew.Target), taskInfo.NextAddress); |
| | | device?.Communicator.Write(nameof(ConveyorLineDBNameNew.TaskNo), taskDTO.TaskNum); |
| | | device?.Communicator.Write(nameof(ConveyorLineDBNameNew.WCS_STB), 1); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 机械手前缀命令处理 |
| | | /// </summary> |
| | |
| | | |
| | | private Dt_RobotTask? GetTask(RobotCraneDevice robotCrane) |
| | | { |
| | | return _taskService.QueryRobotCraneTask(robotCrane.DeviceCode); |
| | | return _robottaskService.QueryRobotCraneTask(robotCrane.DeviceCode); |
| | | } |
| | | } |
| | | |