| | |
| | | using Microsoft.AspNetCore.Components.Routing; |
| | | using Autofac.Core; |
| | | using AutoMapper; |
| | | using Microsoft.AspNetCore.Components.Routing; |
| | | using Newtonsoft.Json; |
| | | using Quartz; |
| | | using SqlSugar.Extensions; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Reflection; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Common; |
| | | using WIDESEAWCS_Common.TaskEnum; |
| | | using WIDESEAWCS_Communicator; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_Core.HttpContextUser; |
| | | using WIDESEAWCS_IBasicInfoRepository; |
| | | using WIDESEAWCS_ITaskInfoRepository; |
| | | using WIDESEAWCS_ITaskInfoService; |
| | |
| | | namespace WIDESEAWCS_Tasks |
| | | { |
| | | [DisallowConcurrentExecution] |
| | | public class ConveyorLineJob_YL2ndFloor : JobBase, IJob |
| | | public partial class ConveyorLineJob_YL2ndFloor : JobBase, IJob |
| | | { |
| | | private readonly ICacheService _cacheService; |
| | | private readonly ITaskService _taskService; |
| | | private readonly IMapper _mapper; |
| | | private readonly ITaskExecuteDetailService _taskExecuteDetailService; |
| | | private readonly ITaskRepository _taskRepository; |
| | | private readonly IStationMangerRepository _stationMangerRepository; |
| | | private readonly IRouterRepository _routerRepository; |
| | | private readonly IRouterService _routerService; |
| | | private readonly IRouterExtension _routerExtension; |
| | | private readonly List<Dt_WarehouseDevice> warehouseDevices; |
| | | private readonly IStationMangerRepository _stationMangerRepository; |
| | | |
| | | public ConveyorLineJob_YL2ndFloor(ICacheService cacheService, ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository, IRouterService routerService, IRouterExtension routerExtension) |
| | | public ConveyorLineJob_YL2ndFloor(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IStationMangerRepository stationMangerRepository,IMapper mapper, IRouterRepository routerRepository) |
| | | { |
| | | _cacheService = cacheService; |
| | | _taskService = taskService; |
| | | _taskExecuteDetailService = taskExecuteDetailService; |
| | | _taskRepository = taskRepository; |
| | | _stationMangerRepository = stationMangerRepository; |
| | | _mapper = mapper; |
| | | _routerRepository = routerRepository; |
| | | _routerService = routerService; |
| | | _routerExtension = routerExtension; |
| | | |
| | | string? warehouseDevicesStr = _cacheService.Get<string>(nameof(Dt_WarehouseDevice)); |
| | | if (!string.IsNullOrEmpty(warehouseDevicesStr)) |
| | | { |
| | | warehouseDevices = JsonConvert.DeserializeObject<List<Dt_WarehouseDevice>>(warehouseDevicesStr) ?? new List<Dt_WarehouseDevice>(); |
| | | } |
| | | else |
| | | { |
| | | warehouseDevices = new List<Dt_WarehouseDevice>(); |
| | | } |
| | | } |
| | | |
| | | public Task Execute(IJobExecutionContext context) |
| | | { |
| | | bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value); |
| | | if (flag && value != null) |
| | | try |
| | | { |
| | | OtherDevice device = (OtherDevice)value; |
| | | List<string> deviceStations = device.DeviceProDTOs.Select(x => x.DeviceChildCode).ToList(); |
| | | //è·åæåè®®çè¾é线-z |
| | | List<Dt_StationManger> stationMangers = _stationMangerRepository.QueryData(x => x.StationDeviceCode == device.DeviceCode); |
| | | //让æ¯ä¸ªè¾é线å¯å¨-z |
| | | foreach (var item in stationMangers.Where(x => deviceStations.Contains(x.StationCode))) |
| | | CommonConveyorLine conveyorLine = (CommonConveyorLine)context.JobDetail.JobDataMap.Get("JobParams"); |
| | | if (conveyorLine != null) |
| | | { |
| | | DeviceProDTO? deviceProRead = device.DeviceProDTOs.Where(x => x.DeviceChildCode == item.StationCode && x.DeviceProParamType == nameof(R_ConveyorLineCPDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); |
| | | DeviceProDTO? deviceProWrite = device.DeviceProDTOs.Where(x => x.DeviceChildCode == item.StationCode && x.DeviceProParamType == nameof(W_ConveyorLineCPDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); |
| | | if (deviceProRead != null) |
| | | #region ç«å°æ¹å¼ |
| | | |
| | | List<Dt_StationManger> stationManagers = _stationMangerRepository.QueryData(x => x.StationDeviceCode == conveyorLine.DeviceCode); |
| | | |
| | | foreach (var station in stationManagers) |
| | | { |
| | | |
| | | ConveyorLineTaskCommand command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(station.StationCode); |
| | | |
| | | DeviceProtocolDetailDTO? deviceProtocolDetails = conveyorLine.DeviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == nameof(ConveyorLineTaskCommand.InteractiveSignal) && x.ProtocalDetailValue == command.InteractiveSignal.ToString()); |
| | | if (deviceProtocolDetails != null) |
| | | { |
| | | MethodInfo? method = GetType().GetMethod(deviceProtocolDetails.ProtocolDetailType); |
| | | if (method != null) |
| | | { |
| | | method.Invoke(this, new object[] { conveyorLine, command, station }); |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | WriteError(item.StationName, $"æªæ¾å°è®¾å¤åç¼å·{item.StationCode}çå议信æ¯"); |
| | | } |
| | | #endregion ç«å°æ¹å¼ |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Console.Out.WriteLine(nameof(ConveyorLineJob_YL2ndFloor) + ":" + DateTime.Now + ":" + ex.ToString(), ex.StackTrace); |
| | | } |
| | | finally |
| | | { |
| | | } |
| | | return Task.CompletedTask; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è¾é线请æ±å
¥åº |
| | | /// </summary> |
| | | /// <param name="conveyorLine">è¾é线å®ä¾å¯¹è±¡</param> |
| | | /// <param name="command">读åç请æ±ä¿¡æ¯</param> |
| | | /// <param name="childDeviceCode">å设å¤ç¼å·</param> |
| | | /// <param name="ProtocalDetailValue">线ä½å½åbool读ååç§»å°å</param> |
| | | public void RequestInbound(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, Dt_StationManger stationManger) |
| | | { |
| | | try |
| | | { |
| | | |
| | | var task = _taskService.QueryLineExecuteTaskByBarcode(command.TaskNum, stationManger.StationCode); |
| | | var log = $"æ¶é´ï¼ã{DateTime.Now}ãã{conveyorLine.DeviceName}ãæçå·ï¼ã{command.Barcode}ãä»»å¡å·ï¼ã{command.TaskNum}ã设å¤ç¼ç ï¼ã{stationManger.StationCode}ã"; |
| | | ConsoleHelper.WriteSuccessLine(log); |
| | | |
| | | WriteInfo(conveyorLine.DeviceName, log); |
| | | |
| | | if(task != null) |
| | | { |
| | | ConveyorLineTaskCommandWrite taskCommand = _mapper.Map<ConveyorLineTaskCommandWrite>(task); |
| | | bool sendFlag = SendCommand(taskCommand, conveyorLine, stationManger.StationCode); |
| | | if (sendFlag) |
| | | { |
| | | _taskService.UpdateTaskStatusToNext(task, stationManger); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | HandleNewTask(conveyorLine, command, stationManger); |
| | | } |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Console.Out.WriteLine(ex.ToString()); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è¾é线å
¥åºå®æ |
| | | /// </summary> |
| | | /// <param name="conveyorLine">è¾é线å®ä¾å¯¹è±¡</param> |
| | | /// <param name="command">读åç请æ±ä¿¡æ¯</param> |
| | | /// <param name="childDeviceCode">å设å¤ç¼å·</param> |
| | | /// <param name="ProtocalDetailValue">线ä½å½åbool读ååç§»å°å</param> |
| | | public void ConveyorLineInFinish(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, Dt_StationManger stationManger) |
| | | { |
| | | var task = _taskService.QueryExecutingTaskByBarcode(command.TaskNum, stationManger.StationCode); |
| | | if (task != null && task.TaskState != (int)TaskStatusEnum.SC_Execute) |
| | | { |
| | | WebResponseContent content = _taskService.UpdateTaskStatusToNext(task, stationManger); |
| | | |
| | | if (content.Status) |
| | | { |
| | | conveyorLine.SetValue(ConveyorLineDBName.ResponState, 86, stationManger.StationCode); |
| | | } |
| | | Console.Out.WriteLine(content.Serialize()); |
| | | } |
| | | } |
| | | |
| | | public bool SendCommand(ConveyorLineTaskCommandWrite taskCommand, CommonConveyorLine conveyorLine, string childDeviceCode) |
| | | { |
| | | conveyorLine.SetValue(ConveyorLineDBName.TaskNum, taskCommand.TaskNum, childDeviceCode); |
| | | conveyorLine.SetValue(ConveyorLineDBName.TargetAddress, taskCommand.TargetAddress, childDeviceCode); |
| | | conveyorLine.SetValue(ConveyorLineDBName.Width, taskCommand.Width, childDeviceCode); |
| | | conveyorLine.SetValue(ConveyorLineDBName.Height, taskCommand.Height, childDeviceCode); |
| | | conveyorLine.SetValue(ConveyorLineDBName.Barcode, taskCommand.Barcode, childDeviceCode); |
| | | conveyorLine.SetValue(ConveyorLineDBName.ResponState, 86, childDeviceCode); |
| | | |
| | | return true; |
| | | |
| | | #region éè¦æ ¡éªèªå·±åæ¶æ³¨é |
| | | //for (int i = 0; i < 6; i++) |
| | | //{ |
| | | // ConveyorLineTaskCommand command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(childDeviceCode); |
| | | // if (command != null) |
| | | // { |
| | | // if (command.TaskNum == taskCommand.TaskNum && command.TargetAddress == taskCommand.TargetAddress && command.Height == taskCommand.Height && command.Width == taskCommand.Width && command.Barcode == taskCommand.Barcode) |
| | | // { |
| | | // WriteInfo(conveyorLine.DeviceName, $"æ¶é´ï¼ã{DateTime.Now}ãåå
¥ä»»å¡æååå
¥æ¬¡æ°{i}åå
¥ä»»å¡ã{JsonConvert.SerializeObject(taskCommand)}ã"); |
| | | // return true; |
| | | // } |
| | | // if (command.TaskNum != taskCommand.TaskNum) |
| | | // { |
| | | // conveyorLine.SetValue(ConveyorLineDBName.TaskNum, taskCommand.TaskNum, childDeviceCode); |
| | | // Thread.Sleep(100); |
| | | // } |
| | | // if (command.Barcode != taskCommand.Barcode) |
| | | // { |
| | | // conveyorLine.SetValue(ConveyorLineDBName.Barcode, taskCommand.Barcode, childDeviceCode); |
| | | // Thread.Sleep(100); |
| | | // } |
| | | // if (command.Height != taskCommand.Height) |
| | | // { |
| | | // conveyorLine.SetValue(ConveyorLineDBName.Height, taskCommand.Height, childDeviceCode); |
| | | // Thread.Sleep(100); |
| | | // } |
| | | // if (command.Width != taskCommand.Width) |
| | | // { |
| | | // conveyorLine.SetValue(ConveyorLineDBName.Width, taskCommand.Width, childDeviceCode); |
| | | // Thread.Sleep(100); |
| | | // } |
| | | // if (command.TargetAddress != taskCommand.TargetAddress) |
| | | // { |
| | | // conveyorLine.SetValue(ConveyorLineDBName.TargetAddress, taskCommand.TargetAddress, childDeviceCode); |
| | | // Thread.Sleep(100); |
| | | // } |
| | | // } |
| | | // conveyorLine.SetValue(ConveyorLineDBName.ResponState, 86, childDeviceCode); |
| | | //} |
| | | //WriteInfo(conveyorLine.DeviceName, $"æ¶é´ï¼ã{DateTime.Now}ãåå
¥ä»»å¡æåä»»å¡å·ã{taskCommand.TaskNum}ãæçå·ã{taskCommand.Barcode}ãç®æ å°åã{taskCommand.TargetAddress}ãå½åèç¹ã{childDeviceCode}ã"); |
| | | //return false; |
| | | #endregion |
| | | } |
| | | } |
| | | } |