From 0fb0f17319ecf71d66b96a6acfd07f754be9443e Mon Sep 17 00:00:00 2001 From: dengjunjie <dengjunjie@hnkhzn.com> Date: 星期四, 24 十月 2024 13:44:38 +0800 Subject: [PATCH] WCS添加穿梭车信息表,修改任务信息表 --- 项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ShuttleCarJob/ShuttleCarJob.cs | 244 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 240 insertions(+), 4 deletions(-) diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ShuttleCarJob/ShuttleCarJob.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ShuttleCarJob/ShuttleCarJob.cs" index e229c15..8351b96 100644 --- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ShuttleCarJob/ShuttleCarJob.cs" +++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ShuttleCarJob/ShuttleCarJob.cs" @@ -1,28 +1,43 @@ 锘縰sing AutoMapper; +using Newtonsoft.Json; +using OfficeOpenXml.Drawing.Chart; using Quartz; using System; using System.Collections.Generic; using System.Linq; using System.Text; 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_IShuttleCar; using WIDESEAWCS_ITaskInfoService; +using WIDESEAWCS_Model.Models; using WIDESEAWCS_QuartzJob; using WIDESEAWCS_QuartzJob.Service; using WIDESEAWCS_QuartzJob.StackerCrane.Enum; +using WIDESEAWCS_TaskInfoService; +using WIDESEAWCS_Tasks.ConveyorLineJob; +using WIDESEAWCS_Tasks.ShuttleCarJob; +using WIDESEAWCS_Tasks.StackerCraneJob; namespace WIDESEAWCS_Tasks { [DisallowConcurrentExecution] - public class ShuttleCarJob : IJob + public class CommonShuttleCarJob : IJob { private readonly ITaskService _taskService; + private readonly IShuttleCarService _shuttleCarService; private readonly ITaskExecuteDetailService _taskExecuteDetailService; private readonly IRouterService _routerService; private readonly IMapper _mapper; - public ShuttleCarJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IMapper mapper) + public CommonShuttleCarJob(ITaskService taskService, IShuttleCarService shuttleCarService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IMapper mapper) { _taskService = taskService; + _shuttleCarService = shuttleCarService; _taskExecuteDetailService = taskExecuteDetailService; _routerService = routerService; _mapper = mapper; @@ -35,12 +50,131 @@ ShuttleCar shuttleCar = (ShuttleCar)context.JobDetail.JobDataMap.Get("JobParams"); if (shuttleCar != null) { - + ShuttleCarTaskCommandR command = shuttleCar.ReadCustomer<ShuttleCarTaskCommandR>(shuttleCar.DeviceCode);//璇诲彇绌挎杞︿俊鎭� + if (command != null && command.JoinStatus == 1) + { + #region 绌挎杞︿换鍔″畬鎴� + if (command.TaskTypeComplete > (short)ShuttleCarTaskComplete.Standby) + { + //鏌ユ壘浠诲姟锛屽垽鏂换鍔$姸鎬佸仛瀵瑰簲澶勭悊锛侊紒锛侊紒锛侊紒锛侊紒锛侊紒锛侊紒锛侊紒锛侊紒锛侊紒锛侊紒锛侊紒锛侊紒锛� + var Status = _taskService.StackCraneTaskCompleted(command.number).Status;//闇�浼樺寲!!! + shuttleCar.SetValue(ShuttleCarDBName.ConfirmComplete, Status, 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()); + } + #endregion + + #region 绌挎杞︾Щ搴撲换鍔� + + #region 鑾峰彇鍫嗗灈鏈虹Щ杞﹀畬鎴愪换鍔� + Dt_Task dt_Task = GetTask((int)TaskCarStatusEnum.SC_CarFinish, (int)TaskOtherTypeEnum.RelocationCar); + if (dt_Task != null) + { + var ShuttleCar = QueryCode(dt_Task.ShuttleCarCode); + ShuttleCar.ShuttleCarPosition = dt_Task.TargetAddress; + _shuttleCarService.UpdateData(ShuttleCar); + if (string.IsNullOrEmpty(dt_Task.Remark))//瀹屾垚绉诲簱浠诲姟 + { + //绉诲叆鍘嗗彶浠诲姟锛侊紒锛侊紒锛侊紒锛侊紒锛侊紒锛侊紒锛侊紒锛侊紒锛侊紒锛侊紒锛侊紒锛侊紒锛侊紒锛侊紒锛侊紒锛� + //鍒犻櫎褰撳墠浠诲姟 + } + 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) + { + 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 鍚慦MS鐢宠 + 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) + { + dt_Task.TargetAddress = content.Message; + dt_Task.NextAddress = dt_Task.TargetAddress; + _taskService.UpdateData(dt_Task); + } + } + #endregion + } + //绌挎杞︾Щ搴撲换鍔′笅鍙� + if (!string.IsNullOrEmpty(dt_Task.SourceAddress) && !string.IsNullOrEmpty(dt_Task.TargetAddress) && !string.IsNullOrEmpty(dt_Task.ShuttleCarCode)) + { + SendTask(dt_Task); + } + } + #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 + } + } + } + #endregion + } } } catch (Exception ex) { - + Console.Out.WriteLine(nameof(CommonShuttleCarJob) + ":" + ex.ToString()); } finally { @@ -48,5 +182,107 @@ } 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; + } } } -- Gitblit v1.9.3