| | |
| | | using HslCommunication; |
| | | using Newtonsoft.Json; |
| | | using OfficeOpenXml.Drawing.Chart; |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; |
| | | using Quartz; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.ComponentModel; |
| | | using System.Linq; |
| | | using System.Reflection; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Common.ShuttleCarEnum; |
| | | using WIDESEAWCS_Common.TaskEnum; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.Caches; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_DTO.System; |
| | | using WIDESEAWCS_DTO.TaskInfo; |
| | | using WIDESEAWCS_DTO.WMSInfo; |
| | | using WIDESEAWCS_IShuttleCar; |
| | | using WIDESEAWCS_ITaskInfoRepository; |
| | |
| | | private readonly IShuttleCarService _shuttleCarService; |
| | | private readonly ITaskExecuteDetailService _taskExecuteDetailService; |
| | | private readonly IRouterService _routerService; |
| | | private readonly ICacheService _cacheService; |
| | | private readonly IMapper _mapper; |
| | | |
| | | public CommonShuttleCarJob(ITaskService taskService, ITaskRepository taskRepository, ITaskHtyService taskHtyService, IShuttleCarService shuttleCarService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IMapper mapper) |
| | | public CommonShuttleCarJob(ITaskService taskService, ITaskRepository taskRepository, ITaskHtyService taskHtyService, IShuttleCarService shuttleCarService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, ICacheService cacheService, IMapper mapper) |
| | | { |
| | | _taskService = taskService; |
| | | _taskRepository = taskRepository; |
| | |
| | | _shuttleCarService = shuttleCarService; |
| | | _taskExecuteDetailService = taskExecuteDetailService; |
| | | _routerService = routerService; |
| | | _cacheService = cacheService; |
| | | _mapper = mapper; |
| | | } |
| | | |
| | |
| | | { |
| | | shuttleCar.Communicator.IsReadAfterWrite = false; |
| | | ShuttleCarTaskCommandR command = ReadCustomer<ShuttleCarTaskCommandR>(shuttleCar, shuttleCar.DeviceCode);//读åç©¿æ¢è½¦ä¿¡æ¯ |
| | | _cacheService.AddOrUpdate(shuttleCar.DeviceCode, command); |
| | | if (command != null && command.JoinStatus == 1) |
| | | { |
| | | #region ç©¿æ¢è½¦ä»»å¡å®æ |
| | | var complete = shuttleCar.GetValue<ShuttleCarDBName, bool>(ShuttleCarDBName.TaskComplete); |
| | | if (complete && command.TaskTypeComplete > (short)ShuttleCarTaskComplete.Standby && command.Status == command.TaskTypeComplete) |
| | | if (complete && command.TaskTypeComplete > (short)ShuttleCarTaskComplete.Standby) |
| | | { |
| | | #region æ¥å¿è®°å½ |
| | | FieldInfo? fieldInfo = typeof(ShuttleCarTaskComplete).GetField(((ShuttleCarTaskComplete)command.TaskTypeComplete).ToString()); |
| | | DescriptionAttribute? description = fieldInfo.GetCustomAttribute<DescriptionAttribute>(); |
| | | var type = description?.Description ?? ((ShuttleCarTaskComplete)command.TaskTypeComplete).ToString(); |
| | | WriteDebug($"{shuttleCar.DeviceName}ä»»å¡å®æ", $"ä»»å¡å·ã{command.number}ã,å®æç±»åã{type}ã"); |
| | | #endregion |
| | | _taskService.ShuttleCarTaskCompleted(command.number, command.TaskTypeComplete); |
| | | shuttleCar.SetValue(ShuttleCarDBName.ConfirmComplete, true, shuttleCar.DeviceCode); |
| | | } |
| | |
| | | #region å建移车å
çµä»»å¡ |
| | | if (command.Err_Status == (short)ShuttleCarErr.LowBattery || command.ElectricQuantity <= (short)ShuttleCarErr.LowBattery) |
| | | { |
| | | //çæå åæºç§»è½¦ä»»å¡&ç©¿æ¢è½¦å
çµä»»å¡,夿æ¯å¦æç©¿æ¢è½¦å¨å
çµ |
| | | Dt_Task _Task = _taskRepository.QueryFirst(x => x.TaskType == TaskOtherTypeEnum.RelocationCarCharging.ObjToInt()); |
| | | if (_Task != null) |
| | | var ShuttleCar = QueryCode(shuttleCar.DeviceCode); |
| | | #region å¤æç©¿æ¢è½¦å½åä½ç½®æ¯å¦æä»»å¡ |
| | | if (_taskRepository.QueryFirst(x => x.SourceAddress == ShuttleCar.ShuttleCarPosition || x.TargetAddress == ShuttleCar.ShuttleCarPosition) == null) |
| | | { |
| | | if (_Task.ShuttleCarCode != shuttleCar.DeviceCode) |
| | | Dt_Task _Task = _taskRepository.QueryFirst(x => x.TaskType == TaskOtherTypeEnum.RelocationCarCharging.ObjToInt()); |
| | | if (_Task != null) |
| | | { |
| | | ShuttleCar shuttleCar1 = Storage.Devices.Where(x => x.DeviceCode.Equals(_Task.ShuttleCarCode)).FirstOrDefault() as ShuttleCar; |
| | | ShuttleCarTaskCommandR command1 = ReadCustomer<ShuttleCarTaskCommandR>(shuttleCar1, shuttleCar1.DeviceCode);//读åç©¿æ¢è½¦ä¿¡æ¯ |
| | | if (command1 != null && command1.JoinStatus == 1) |
| | | if (_Task.ShuttleCarCode != shuttleCar.DeviceCode) |
| | | { |
| | | if (command1.Status == (short)ShuttleCarStatus.Charging && command1.ElectricQuantity >= 50) |
| | | ShuttleCar shuttleCar1 = Storage.Devices.Where(x => x.DeviceCode.Equals(_Task.ShuttleCarCode)).FirstOrDefault() as ShuttleCar; |
| | | ShuttleCarTaskCommandR command1 = ReadCustomer<ShuttleCarTaskCommandR>(shuttleCar1, shuttleCar1.DeviceCode);//读åç©¿æ¢è½¦ä¿¡æ¯ |
| | | if (command1 != null && command1.JoinStatus == 1) |
| | | { |
| | | var ShuttleCar = QueryCode(shuttleCar1.DeviceCode); |
| | | _taskService.AddRelocationCarTask(ShuttleCar.ShuttleCarPosition, "", ShuttleCar.ShuttleCarCode); |
| | | shuttleCar1.SetValue(ShuttleCarDBName.TaskType, (short)ShuttleCarStatus.QuitCharging); |
| | | if (command1.Status == (short)ShuttleCarStatus.Charging && command1.ElectricQuantity /*> command.ElectricQuantity*/ >= 50) |
| | | { |
| | | shuttleCar1.SetValue(ShuttleCarDBName.TaskType, (short)ShuttleCarStatus.QuitCharging); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | string CarChargingStation = AppSettings.Configuration[nameof(CarChargingStation)];//å
çµä½ |
| | | //夿å
çµä½æ¯å¦æè½¦ |
| | | var ShuttleCar1 = _shuttleCarService.QueryShuttleCar(CarChargingStation); |
| | | if (ShuttleCar1 != null && ShuttleCar1.ShuttleCarCode != shuttleCar.DeviceCode) |
| | | { |
| | | if (_taskRepository.QueryFirst(x => x.ShuttleCarCode == ShuttleCar1.ShuttleCarCode) == null) |
| | | _taskService.AddRelocationCarTask(ShuttleCar1.ShuttleCarPosition, "", ShuttleCar1.ShuttleCarCode); |
| | | } |
| | | else |
| | | { |
| | | _taskService.AddRelocationCarTask(ShuttleCar.ShuttleCarPosition, CarChargingStation, ShuttleCar.ShuttleCarCode, ShuttleCarTaskType.Charging.ToString()); |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | var ShuttleCar = QueryCode(shuttleCar.DeviceCode); |
| | | _taskService.AddRelocationCarTask(ShuttleCar.ShuttleCarPosition, "003-002-001", ShuttleCar.ShuttleCarCode, ShuttleCarTaskType.Charging.ToString()); |
| | | } |
| | | #endregion |
| | | } |
| | | #endregion |
| | | |
| | | #region è·å移车/åºå
¥åºä»»å¡ |
| | | Get_CarTask(shuttleCar, command); |
| | | if (command != null && |
| | | (command.Status == (short)ShuttleCarStatus.Standby || |
| | | command.Status == (short)ShuttleCarStatus.Charging) && |
| | | command.TaskTypeComplete == (short)ShuttleCarTaskComplete.Standby && |
| | | (command.Err_Status == (short)ShuttleCarErr.Normal || |
| | | command.Err_Status == (short)ShuttleCarErr.LowBattery) |
| | | ) |
| | | { |
| | | var dt_Task = GetTask(TaskRelocationStatusEnum.SC_RelocationFinish.ObjToInt(), TaskRelocationTypeEnum.Relocation.ObjToInt());//ç§»åºä»»å¡ |
| | | if (dt_Task != null && shuttleCar.DeviceCode == dt_Task.ShuttleCarCode) |
| | | SendTask(dt_Task); |
| | | else |
| | | Get_CarTask(shuttleCar, command); |
| | | } |
| | | #endregion |
| | | } |
| | | } |