| | |
| | | using MapsterMapper; |
| | | using Masuit.Tools; |
| | | using Microsoft.Extensions.Configuration; |
| | | using Microsoft.Extensions.Logging; |
| | | using Newtonsoft.Json; |
| | | using Quartz; |
| | | using Serilog; |
| | | using SqlSugar; |
| | | using WIDESEA_Core; |
| | | using WIDESEAWCS_Common.TaskEnum; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_Core.LogHelper; |
| | | using WIDESEAWCS_DTO.TaskInfo; |
| | | using WIDESEAWCS_ITaskInfoService; |
| | | using WIDESEAWCS_Model.Models; |
| | |
| | | /// 任务服务 |
| | | /// </summary> |
| | | private readonly ITaskService _taskService; |
| | | |
| | | |
| | | /// <summary> |
| | | /// 机器人任务服务 |
| | |
| | | /// <summary> |
| | | /// 日志记录器 |
| | | /// </summary> |
| | | private readonly ILogger<CommonConveyorLineNewJob> _logger; |
| | | private readonly ILogger _logger; |
| | | |
| | | /// <summary> |
| | | /// 目标地址到设备类型的映射 |
| | |
| | | /// <remarks> |
| | | /// </remarks> |
| | | private static List<string> AddressToDeviceType = new List<string> { "11020", "11028" }; |
| | | |
| | | /// <summary> |
| | | /// 托盘检查位置的最近执行时间(用于30秒间隔限制) |
| | | /// </summary> |
| | | private static readonly Dictionary<string, DateTime> _lastPalletCheckTime = new(); |
| | | |
| | | /// <summary> |
| | | /// 构造函数 |
| | |
| | | /// <param name="mapper">对象映射器</param> |
| | | /// <param name="httpClientHelper">HTTP 客户端帮助类</param> |
| | | /// <param name="logger">日志记录器</param> |
| | | public CommonConveyorLineNewJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IMapper mapper, HttpClientHelper httpClientHelper, ILogger<CommonConveyorLineNewJob> logger, IRobotTaskService robotTaskService) |
| | | public CommonConveyorLineNewJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IMapper mapper, HttpClientHelper httpClientHelper, ILogger logger, IRobotTaskService robotTaskService) |
| | | { |
| | | _taskService = taskService; |
| | | _taskExecuteDetailService = taskExecuteDetailService; |
| | |
| | | // 如果当前设备在检查列表中 |
| | | if (checkPalletPositions.Any(x => x.Code == childDeviceCode)) |
| | | { |
| | | // 30秒间隔限制 |
| | | if (_lastPalletCheckTime.TryGetValue(childDeviceCode, out var lastTime) && |
| | | (DateTime.Now - lastTime).TotalSeconds < 30) |
| | | { |
| | | continue; |
| | | } |
| | | |
| | | // 检查输送线状态(是否有托盘) |
| | | if (command.CV_State == 2) |
| | | { |
| | |
| | | { |
| | | // 没有任务,向 WMS 请求出库托盘任务 |
| | | var position = checkPalletPositions.FirstOrDefault(x => x.Code == childDeviceCode); |
| | | QuartzLogHelper.LogInfo(_logger, "Execute:检查托盘位置 {ChildDeviceCode},请求WMS出库托盘任务", $"检查托盘位置 {childDeviceCode},请求WMS出库托盘任务", conveyorLine.DeviceCode, childDeviceCode); |
| | | |
| | | var responseResult = _httpClientHelper.Post<WebResponseContent>("GetOutBoundTrayTaskAsync", new CreateTaskDto() |
| | | string configKey = "GetOutBoundTrayTaskAsync"; |
| | | string requestParam = new CreateTaskDto() |
| | | { |
| | | WarehouseId = position.WarehouseId, |
| | | TargetAddress = childDeviceCode |
| | | }.Serialize()); |
| | | }.Serialize(); |
| | | DateTime startTime = DateTime.Now; |
| | | |
| | | var responseResult = _httpClientHelper.Post<WebResponseContent>(configKey, requestParam); |
| | | |
| | | _lastPalletCheckTime[childDeviceCode] = DateTime.Now; |
| | | |
| | | // 如果请求成功,接收 WMS 返回的任务 |
| | | if (responseResult.IsSuccess && responseResult.Data.Status) |
| | | { |
| | | QuartzLogHelper.LogInfo(_logger, $"调用WMS接口成功,接口:【{configKey}】,请求参数:【{requestParam}】,响应数据:【{responseResult.Data?.Data}】,耗时:{(DateTime.Now - startTime).TotalMilliseconds}ms", conveyorLine.DeviceCode); |
| | | var wmsTask = JsonConvert.DeserializeObject<WMSTaskDTO>(responseResult.Data.Data.ToString()); |
| | | List<WMSTaskDTO> taskDTOs = new List<WMSTaskDTO> { wmsTask }; |
| | | if (wmsTask != null) |
| | | _taskService.ReceiveWMSTask(taskDTOs); |
| | | } |
| | | else |
| | | { |
| | | QuartzLogHelper.LogError(_logger, $"调用WMS接口失败,接口:【{configKey}】,请求参数:【{requestParam}】,错误信息:【{responseResult.Data?.Message}】", conveyorLine.DeviceCode); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | #endregion 检测是否需要空托盘 |
| | | |
| | | // ========== 检查 PLC_STB 标志 ========== |
| | | // 只有当 PLC_STB 为 1 时才处理任务 |
| | |
| | | var task = _taskService.QueryManualInboundTask(childDeviceCode); |
| | | if (task != null) |
| | | { |
| | | var handler = new ManualInboundTaskHandler(_taskService); |
| | | var handler = new ManualInboundTaskHandler(_taskService, _logger); |
| | | handler.WriteTaskToPlc(conveyorLine, childDeviceCode, task); |
| | | } |
| | | } |
| | |
| | | RobotTargetAddressLineCode = childDeviceCode, |
| | | RobotTaskNum = num, // 生成任务号 |
| | | RobotDispatchertime = DateTime.Now, |
| | | |
| | | }; |
| | | if (_robotTaskService.AddData(robotTask).Status) |
| | | { |