| | |
| | | using AutoMapper; |
| | | using HslCommunication; |
| | | using Newtonsoft.Json; |
| | | using OfficeOpenXml.Drawing.Chart; |
| | | using Quartz; |
| | |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Common.ShuttleCarEnum; |
| | | using WIDESEAWCS_Common.TaskEnum; |
| | | using WIDESEAWCS_Common.WMSInfo; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_DTO.WMSInfo; |
| | | using WIDESEAWCS_IShuttleCar; |
| | | using WIDESEAWCS_ITaskInfoRepository; |
| | | using WIDESEAWCS_ITaskInfoService; |
| | | using WIDESEAWCS_Model.Models; |
| | | using WIDESEAWCS_QuartzJob; |
| | | using WIDESEAWCS_QuartzJob.DTO; |
| | | using WIDESEAWCS_QuartzJob.Service; |
| | | using WIDESEAWCS_QuartzJob.StackerCrane.Enum; |
| | | using WIDESEAWCS_TaskInfoService; |
| | |
| | | namespace WIDESEAWCS_Tasks |
| | | { |
| | | [DisallowConcurrentExecution] |
| | | public class CommonShuttleCarJob : IJob |
| | | partial class CommonShuttleCarJob : JobBase, IJob |
| | | { |
| | | private readonly ITaskService _taskService; |
| | | private readonly ITaskRepository _taskRepository; |
| | | private readonly ITaskHtyService _taskHtyService; |
| | | private readonly IShuttleCarService _shuttleCarService; |
| | | private readonly ITaskExecuteDetailService _taskExecuteDetailService; |
| | | private readonly IRouterService _routerService; |
| | | private readonly IMapper _mapper; |
| | | |
| | | public CommonShuttleCarJob(ITaskService taskService, IShuttleCarService shuttleCarService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IMapper mapper) |
| | | public CommonShuttleCarJob(ITaskService taskService, ITaskRepository taskRepository, ITaskHtyService taskHtyService, IShuttleCarService shuttleCarService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IMapper mapper) |
| | | { |
| | | _taskService = taskService; |
| | | _taskRepository = taskRepository; |
| | | _taskHtyService = taskHtyService; |
| | | _shuttleCarService = shuttleCarService; |
| | | _taskExecuteDetailService = taskExecuteDetailService; |
| | | _routerService = routerService; |
| | |
| | | ShuttleCar shuttleCar = (ShuttleCar)context.JobDetail.JobDataMap.Get("JobParams"); |
| | | if (shuttleCar != null) |
| | | { |
| | | ShuttleCarTaskCommandR command = shuttleCar.ReadCustomer<ShuttleCarTaskCommandR>(shuttleCar.DeviceCode);//读åç©¿æ¢è½¦ä¿¡æ¯ |
| | | shuttleCar.Communicator.IsReadAfterWrite = false; |
| | | ShuttleCarTaskCommandR command = ReadCustomer<ShuttleCarTaskCommandR>(shuttleCar, shuttleCar.DeviceCode);//读åç©¿æ¢è½¦ä¿¡æ¯ |
| | | if (command != null && command.JoinStatus == 1) |
| | | { |
| | | #region ç©¿æ¢è½¦ä»»å¡å®æ |
| | | if (command.TaskTypeComplete > (short)ShuttleCarTaskComplete.Standby) |
| | | var complete = shuttleCar.GetValue<ShuttleCarDBName, bool>(ShuttleCarDBName.TaskComplete); |
| | | if (complete && command.TaskTypeComplete > (short)ShuttleCarTaskComplete.Standby && command.Status == command.TaskTypeComplete) |
| | | { |
| | | //æ¥æ¾ä»»å¡ï¼å¤æä»»å¡ç¶æå对åºå¤çï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ |
| | | var Status = _taskService.StackCraneTaskCompleted(command.number).Status;//éä¼å!!! |
| | | shuttleCar.SetValue(ShuttleCarDBName.ConfirmComplete, Status, shuttleCar.DeviceCode); |
| | | _taskService.ShuttleCarTaskCompleted(command.number, command.TaskTypeComplete); |
| | | shuttleCar.SetValue(ShuttleCarDBName.ConfirmComplete, true, shuttleCar.DeviceCode); |
| | | } |
| | | #endregion |
| | | |
| | | #region ç§»åºå
çµä»»å¡ |
| | | if (command.Err_Status == (short)ShuttleCarErr.LowBattery || command.ElectricQuantity == (short)ShuttleCarErr.LowBattery) |
| | | { |
| | | //çæå åæºç§»è½¦ä»»å¡&ç©¿æ¢è½¦å
çµä»»å¡ |
| | | var ShuttleCar = QueryCode(shuttleCar.DeviceCode); |
| | | _taskService.AddRelocationCarTask(ShuttleCar.ShuttleCarPosition, "", ShuttleCar.ShuttleCarCode, ShuttleCarTaskType.Charging.ToString()); |
| | | } |
| | | #region è·åå åæºç§»è½¦/ç§»åºå®æä»»å¡ |
| | | GetSC_CarFinish(); |
| | | #endregion |
| | | |
| | | #region ç©¿æ¢è½¦ç§»åºä»»å¡ |
| | | |
| | | #region è·åå åæºç§»è½¦å®æä»»å¡ |
| | | Dt_Task dt_Task = GetTask((int)TaskCarStatusEnum.SC_CarFinish, (int)TaskOtherTypeEnum.RelocationCar); |
| | | if (dt_Task != null) |
| | | #region å建移车å
çµä»»å¡ |
| | | if (command.Err_Status == (short)ShuttleCarErr.LowBattery || command.ElectricQuantity <= (short)ShuttleCarErr.LowBattery) |
| | | { |
| | | var ShuttleCar = QueryCode(dt_Task.ShuttleCarCode); |
| | | ShuttleCar.ShuttleCarPosition = dt_Task.TargetAddress; |
| | | _shuttleCarService.UpdateData(ShuttleCar); |
| | | if (string.IsNullOrEmpty(dt_Task.Remark))//å®æç§»åºä»»å¡ |
| | | //çæå åæºç§»è½¦ä»»å¡&ç©¿æ¢è½¦å
çµä»»å¡,夿æ¯å¦æç©¿æ¢è½¦å¨å
çµ |
| | | Dt_Task _Task = _taskRepository.QueryFirst(x => x.TaskType == TaskOtherTypeEnum.RelocationCarCharging.ObjToInt()); |
| | | if (_Task != null) |
| | | { |
| | | //ç§»å
¥åå²ä»»å¡ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ |
| | | //å é¤å½åä»»å¡ |
| | | } |
| | | else//ä¸åå
çµä»»å¡ |
| | | { |
| | | SendTask(dt_Task); |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | dt_Task = GetTask((int)TaskCarStatusEnum.CarNew, (int)TaskOtherTypeEnum.RelocationCar);//è·åæ°å»ºç§»è½¦ä»»å¡ |
| | | if (dt_Task != null) |
| | | { |
| | | if (string.IsNullOrEmpty(dt_Task.SourceAddress)) |
| | | { |
| | | if (command.Status == (short)ShuttleCarStatus.Standby && command.TaskTypeComplete == (short)ShuttleCarTaskComplete.Standby && command.Err_Status == (short)ShuttleCarErr.Normal) |
| | | if (_Task.ShuttleCarCode != shuttleCar.DeviceCode) |
| | | { |
| | | dt_Task.SourceAddress = QueryCode(shuttleCar._deviceCode).ShuttleCarPosition; |
| | | dt_Task.CurrentAddress = dt_Task.SourceAddress; |
| | | dt_Task.ShuttleCarCode = shuttleCar._deviceCode; |
| | | _taskService.UpdateData(dt_Task); |
| | | } |
| | | } |
| | | else if (string.IsNullOrEmpty(dt_Task.TargetAddress)) |
| | | { |
| | | #region åWMSç³è¯· |
| | | WebResponseContent content = new WebResponseContent(); |
| | | var ResultData = HttpHelper.PostAsync(WMSIP.GetPosition + $"?position={dt_Task.SourceAddress}", "", headers: new Dictionary<string, string>()); |
| | | if (ResultData.Result != null) |
| | | { |
| | | content = JsonConvert.DeserializeObject<WebResponseContent>(ResultData.Result); |
| | | if (content != null && content.Status) |
| | | 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) |
| | | { |
| | | dt_Task.TargetAddress = content.Message; |
| | | dt_Task.NextAddress = dt_Task.TargetAddress; |
| | | _taskService.UpdateData(dt_Task); |
| | | if (command1.Status == (short)ShuttleCarStatus.Charging && command1.ElectricQuantity >= 50) |
| | | { |
| | | var ShuttleCar = QueryCode(shuttleCar1.DeviceCode); |
| | | _taskService.AddRelocationCarTask(ShuttleCar.ShuttleCarPosition, "", ShuttleCar.ShuttleCarCode); |
| | | shuttleCar1.SetValue(ShuttleCarDBName.TaskType, (short)ShuttleCarStatus.QuitCharging); |
| | | } |
| | | } |
| | | } |
| | | #endregion |
| | | } |
| | | //ç©¿æ¢è½¦ç§»åºä»»å¡ä¸å |
| | | if (!string.IsNullOrEmpty(dt_Task.SourceAddress) && !string.IsNullOrEmpty(dt_Task.TargetAddress) && !string.IsNullOrEmpty(dt_Task.ShuttleCarCode)) |
| | | else |
| | | { |
| | | SendTask(dt_Task); |
| | | var ShuttleCar = QueryCode(shuttleCar.DeviceCode); |
| | | _taskService.AddRelocationCarTask(ShuttleCar.ShuttleCarPosition, "003-002-001", ShuttleCar.ShuttleCarCode, ShuttleCarTaskType.Charging.ToString()); |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | #region ç©¿æ¢è½¦åºå
¥åºä»»å¡ |
| | | else |
| | | { |
| | | var task = _taskService.QueryShuttleCarTask(shuttleCar.DeviceCode); |
| | | if (task != null) |
| | | { |
| | | if (task.TaskType == (int)TaskOutboundTypeEnum.Outbound && !task.IsPickPlace) |
| | | { |
| | | var ShuttleCar = _shuttleCarService.QueryShuttleCar(task.SourceAddress);//åºåºä»»å¡å¤ææ¯å¦åå¨ç©¿æ¢è½¦ |
| | | if (ShuttleCar != null) |
| | | { |
| | | SendTask(task); |
| | | } |
| | | else |
| | | { |
| | | _taskService.AddRelocationCarTask("", task.SourceAddress); |
| | | } |
| | | #region å建å åæºç§»è½¦ä»»å¡ |
| | | //dt_Task = new Dt_Task() |
| | | //{ |
| | | // TaskNum = Convert.ToInt32(DateTime.Now.ToString("HHmmss")), |
| | | // Grade = 2, |
| | | // Roadway = "SC01", |
| | | // TaskType = (int)TaskOtherTypeEnum.RelocationCar, |
| | | // SourceAddress = "", |
| | | // TargetAddress = task.SourceAddress, |
| | | // CurrentAddress = "", |
| | | // NextAddress = task.SourceAddress, |
| | | // CreateDate = DateTime.Now, |
| | | // Creater = "WCS", |
| | | // TaskState = (int)TaskCarStatusEnum.CarNew, |
| | | // WMSId = 0, |
| | | //}; |
| | | //_taskService.AddData(dt_Task); |
| | | #endregion |
| | | } |
| | | } |
| | | } |
| | | #region è·å移车/åºå
¥åºä»»å¡ |
| | | Get_CarTask(shuttleCar, command); |
| | | #endregion |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Console.Out.WriteLine(nameof(CommonShuttleCarJob) + ":" + ex.ToString()); |
| | | } |
| | | finally |
| | | { |
| | | |
| | | //Console.Out.WriteLine(nameof(CommonShuttleCarJob) + ":" + ex.ToString()); |
| | | } |
| | | return Task.CompletedTask; |
| | | } |
| | | private void SendTask(Dt_Task task) |
| | | { |
| | | ShuttleCar shuttleCar = Storage.Devices.FirstOrDefault(x => x.DeviceCode == task.ShuttleCarCode) as ShuttleCar; |
| | | if (shuttleCar != null) |
| | | { |
| | | ShuttleCarTaskCommandR command = shuttleCar.ReadCustomer<ShuttleCarTaskCommandR>(shuttleCar.DeviceCode);//读åç©¿æ¢è½¦ä¿¡æ¯ |
| | | if (command != null && command.Status == (short)ShuttleCarStatus.Standby && command.TaskTypeComplete == (short)ShuttleCarTaskComplete.Standby && command.Err_Status == (short)ShuttleCarErr.Normal) |
| | | { |
| | | //ä»»å¡è½¬æ¢ |
| | | ShuttleCarTaskCommandW shuttleCarTaskCommand = new ShuttleCarTaskCommandW(); |
| | | shuttleCarTaskCommand.Direction = command.Position; |
| | | shuttleCarTaskCommand.TaskNum = task.TaskNum; |
| | | if (task.TaskType == (int)TaskOtherTypeEnum.RelocationCar)//移车 |
| | | { |
| | | if (task.TaskState == (int)TaskCarStatusEnum.CarNew) |
| | | { |
| | | if (task.Remark == ShuttleCarTaskType.ExitCharge.ToString()) shuttleCarTaskCommand.TaskType = (short)GetCarTaskType(task.Remark); |
| | | else shuttleCarTaskCommand.TaskType = (short)GetCarTaskType(task.TaskType, shuttleCarTaskCommand.Direction); |
| | | } |
| | | else if (task.TaskState == (int)TaskCarStatusEnum.SC_CarFinish) |
| | | { |
| | | if (task.Remark == ShuttleCarTaskType.Charging.ToString()) shuttleCarTaskCommand.TaskType = (short)GetCarTaskType(task.Remark); |
| | | else shuttleCarTaskCommand.TaskType = (short)GetCarTaskType(task.TaskType, shuttleCarTaskCommand.Direction); |
| | | } |
| | | } |
| | | else |
| | | shuttleCarTaskCommand.TaskType = (short)GetCarTaskType(task.TaskType, shuttleCarTaskCommand.Direction); |
| | | //shuttleCarTaskCommand.TaskType = string.IsNullOrEmpty(task.Remark) ? (short)GetCarTaskType(task.TaskType, shuttleCarTaskCommand.Direction) : (short)GetCarTaskType(task.Remark); |
| | | //ä»»å¡ä¸å |
| | | if (shuttleCarTaskCommand.TaskType != null)//0 |
| | | { |
| | | if (shuttleCar.SendCommand(shuttleCarTaskCommand, shuttleCar.DeviceCode)) |
| | | { |
| | | if (!string.IsNullOrEmpty(task.Remark)) task.Remark = task.Remark + "å·²ä¸å"; |
| | | task.TaskState = GetTaskState(task.TaskType); |
| | | _taskService.UpdateData(task); |
| | | } |
| | | } |
| | | } |
| | | |
| | | ///éåºå
çµä»»å¡ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ |
| | | if (command.ElectricQuantity > 50) |
| | | { |
| | | |
| | | } |
| | | } |
| | | } |
| | | private Dt_Task GetTask(int TaskState, int TaskType) |
| | | { |
| | | return _taskService.GetTaskState(TaskState, TaskType); |
| | | } |
| | | |
| | | public Dt_ShuttleCar QueryCode(string ShuttleCarCode) |
| | | { |
| | | return _shuttleCarService.QueryCode(ShuttleCarCode); |
| | | } |
| | | |
| | | ShuttleCarTaskType GetCarTaskType(string remark) => remark switch |
| | | { |
| | | "Charging" => ShuttleCarTaskType.Charging, |
| | | "ExitCharge" => ShuttleCarTaskType.ExitCharge, |
| | | }; |
| | | |
| | | ShuttleCarTaskType GetCarTaskType(int TaskType, short Direction) |
| | | { |
| | | ShuttleCarTaskType taskType = new ShuttleCarTaskType(); |
| | | switch (TaskType) |
| | | { |
| | | case (int)TaskInboundTypeEnum.Inbound: |
| | | taskType = ShuttleCarTaskType.In; |
| | | break; |
| | | case (int)TaskOutboundTypeEnum.Outbound: |
| | | taskType = ShuttleCarTaskType.Out; |
| | | break; |
| | | case (int)TaskOtherTypeEnum.RelocationCar: |
| | | taskType = Direction == 1 ? ShuttleCarTaskType.ZeroA : ShuttleCarTaskType.ZeroB; |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | return taskType; |
| | | } |
| | | |
| | | int GetTaskState(int TaskType) |
| | | { |
| | | int state = 0; |
| | | switch (TaskType) |
| | | { |
| | | case (int)TaskInboundTypeEnum.Inbound: |
| | | state = (int)TaskInStatusEnum.Car_InExecuting; |
| | | break; |
| | | case (int)TaskOutboundTypeEnum.Outbound: |
| | | state = (int)TaskOutStatusEnum.Car_OutExecuting; |
| | | break; |
| | | case (int)TaskOtherTypeEnum.RelocationCar: |
| | | state = (int)TaskCarStatusEnum.ShuttleCar_Executing; |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | return state; |
| | | } |
| | | } |
| | | } |