¶Ô±ÈÐÂÎļþ |
| | |
| | | using Newtonsoft.Json; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Common.TaskEnum; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_DTO.TaskInfo; |
| | | using WIDESEAWCS_Model.Models; |
| | | using WIDESEAWCS_QuartzJob; |
| | | using WIDESEAWCS_Tasks.ConveyorLineJob; |
| | | using HslCommunication; |
| | | using OfficeOpenXml.ConditionalFormatting; |
| | | using WIDESEAWCS_DTO.WMS; |
| | | |
| | | namespace WIDESEAWCS_Tasks |
| | | { |
| | | public partial class CommonConveyorLineJob |
| | | { |
| | | /// <summary> |
| | | /// å¤çåºåºä»»å¡ |
| | | /// </summary> |
| | | private void HandleTaskOut(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, int ProtocalDetailValue, Dt_Task taskOut) |
| | | { |
| | | // å¦ææ²¡æä»»å¡ï¼ç´æ¥è¿å |
| | | if (taskOut == null) return; |
| | | |
| | | // æ å°ä»»å¡å½ä»¤ |
| | | var taskCommand = MapTaskCommand(taskOut, command); |
| | | |
| | | // æ ¹æ®ä¸åçä»»å¡ç±»ååç¶ææ§è¡ä¸åçé»è¾ |
| | | bool isOutTray = taskOut.TaskType == (int)TaskOutboundTypeEnum.OutTray; |
| | | bool isOutboundAndOutFinish = taskOut.TaskType == (int)TaskOutboundTypeEnum.Outbound && taskOut.TaskState == (int)TaskOutStatusEnum.SC_OutFinish; |
| | | bool isOutboundAndLineOutExecuting = taskOut.TaskType == (int)TaskOutboundTypeEnum.Outbound && taskOut.TaskState == (int)TaskOutStatusEnum.Line_OutExecuting; |
| | | |
| | | if (isOutTray || isOutboundAndOutFinish || isOutboundAndLineOutExecuting) |
| | | { |
| | | // åéå½ä»¤å°è¾é线 |
| | | conveyorLine.SendCommand(taskCommand, childDeviceCode); |
| | | // æ è®°åé宿 |
| | | ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true); |
| | | // æ´æ°ä»»å¡ç¶æ |
| | | _taskService.UpdateTaskStatusToNext(taskOut); |
| | | } |
| | | else if (taskOut.TaskType == (int)TaskOutboundTypeEnum.OutTray && taskOut.TaskState == (int)TaskOutStatusEnum.Line_OutExecuting) |
| | | { |
| | | // 宿WMSä»»å¡ |
| | | CompleteWmsTask(taskOut, command, conveyorLine, childDeviceCode, ProtocalDetailValue); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å¤çæ°ä»»å¡ |
| | | /// </summary> |
| | | private void HandleNewTask(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, int ProtocalDetailValue) |
| | | { |
| | | // ç¹å®æ¡ä»¶ä¸å建并åé空æçå
¥åºä»»å¡ |
| | | if ((conveyorLine.DeviceCode == "1003" && childDeviceCode == "1016") || (conveyorLine.DeviceCode == "1005" && childDeviceCode == "1048")) |
| | | { |
| | | // 请æ±WMS空æçä»»å¡ |
| | | CreateAndSendEmptyTrayTask(conveyorLine, command, childDeviceCode, ProtocalDetailValue); |
| | | } |
| | | else if ((conveyorLine.DeviceCode == "1001" && childDeviceCode == "1088") || (conveyorLine.DeviceCode == "1004" && childDeviceCode == "1339")) |
| | | { |
| | | // 请æ±WMSå
¥åºä»»å¡ |
| | | RequestWmsTask(conveyorLine, command, childDeviceCode, ProtocalDetailValue); |
| | | } |
| | | else if ((conveyorLine.DeviceCode == "1001" && childDeviceCode == "1073") || (conveyorLine.DeviceCode == "1003" && childDeviceCode == "1002")) |
| | | { |
| | | //TODO åéç´æ¥å»NGå£ä»»å¡ |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ å°ä»»å¡å½ä»¤ |
| | | /// </summary> |
| | | private ConveyorLineTaskCommand MapTaskCommand(Dt_Task task, ConveyorLineTaskCommand command) |
| | | { |
| | | // 使ç¨mapperæ å°ä»»å¡å½ä»¤ |
| | | var comm = _mapper.Map<ConveyorLineTaskCommand>(task); |
| | | comm.InteractiveSignal = command.InteractiveSignal; |
| | | return comm; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 宿WMSä»»å¡ |
| | | /// </summary> |
| | | private void CompleteWmsTask(Dt_Task taskOut, ConveyorLineTaskCommand command, CommonConveyorLine conveyorLine, string childDeviceCode, int ProtocalDetailValue) |
| | | { |
| | | // å¦ææ²¡ææ¡ç ä¿¡æ¯ï¼åè®¾ç½®ç®æ å°å为NGå°å |
| | | if (command.Barcode == "NoRead") |
| | | { |
| | | var NGAddress = _platFormRepository.QueryFirst(x => x.PlatCode == taskOut.TargetAddress).Capacity; |
| | | taskOut.TargetAddress = NGAddress.ToString(); |
| | | } |
| | | |
| | | // TODOè°ç¨WMSä»»å¡å®ææ¥å£ |
| | | var keys = new Dictionary<string, object>() |
| | | { |
| | | {"taskNum", taskOut.TaskNum} |
| | | }; |
| | | var result = HttpHelper.GetAsync($"http://127.0.0.1:5000/api/Task/CompleteTaskAsync", keys).Result; |
| | | WebResponseContent content = JsonConvert.DeserializeObject<WebResponseContent>(result); |
| | | if (content.Status) |
| | | { |
| | | // æ è®°åé宿 |
| | | ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true); |
| | | // æ´æ°ä»»å¡ç¶æ |
| | | _taskService.UpdateTaskStatusToNext(taskOut); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å建并åé空æçä»»å¡ |
| | | /// </summary> |
| | | public void CreateAndSendEmptyTrayTask(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, int ProtocalDetailValue) |
| | | { |
| | | if (command.Barcode != "NoRead") |
| | | { |
| | | // å建空æçä»»å¡DTO |
| | | WMSTaskDTO taskDTO = CreateEmptyTrayTaskDto(command.Barcode, childDeviceCode); |
| | | // å建并åéä»»å¡ |
| | | WebResponseContent content = CreateAndSendTask(taskDTO); |
| | | if (content.Status) |
| | | { |
| | | // æ¥è¯¢ä»»å¡ |
| | | Dt_Task task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode); |
| | | if (task != null) |
| | | { |
| | | // æ å°ä»»å¡å½ä»¤ |
| | | ConveyorLineTaskCommand taskCommand = MapTaskCommand(task, command); |
| | | // åéå½ä»¤å°è¾é线 |
| | | conveyorLine.SendCommand(taskCommand, childDeviceCode); |
| | | // æ è®°åé宿 |
| | | ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true); |
| | | // æ´æ°ä»»å¡ç¶æ |
| | | _taskService.UpdateTaskStatusToNext(task); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å建空æçä»»å¡DTO |
| | | /// </summary> |
| | | private WMSTaskDTO CreateEmptyTrayTaskDto(string barcode, string childDeviceCode) |
| | | { |
| | | #region åWMS请æ±ç©ºæçä»»å¡ |
| | | WMSTaskDTO wMSTaskDTO = new WMSTaskDTO(); |
| | | RequestTaskDto request = new RequestTaskDto() |
| | | { |
| | | Position = childDeviceCode, |
| | | PalletCode = barcode, |
| | | }; |
| | | var result = HttpHelper.PostAsync("http://127.0.0.1:5000/api/Task/RequestTrayInTaskAsync", request.ToJsonString()).Result; |
| | | if (result == null) |
| | | return wMSTaskDTO; |
| | | |
| | | WebResponseContent content = JsonConvert.DeserializeObject<WebResponseContent>(result); |
| | | // æ£æ¥ç¶æå¹¶è¿å |
| | | if (!content.Status) |
| | | return wMSTaskDTO; |
| | | |
| | | return JsonConvert.DeserializeObject<WMSTaskDTO>(content.Data.ToString()); |
| | | |
| | | #endregion åWMS请æ±ç©ºæçä»»å¡ |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 请æ±WMSä»»å¡ |
| | | /// </summary> |
| | | private void RequestWmsTask(CommonConveyorLine conveyorLine, ConveyorLineTaskCommand command, string childDeviceCode, int ProtocalDetailValue) |
| | | { |
| | | // 请æ±WMSä»»å¡ |
| | | if (_taskService.RequestWMSTask(command.Barcode, childDeviceCode).Status) |
| | | { |
| | | // æ¥è¯¢ä»»å¡ |
| | | Dt_Task task = _taskService.QueryBarCodeConveyorLineTask(command.Barcode, childDeviceCode); |
| | | if (task != null) |
| | | { |
| | | // æ å°ä»»å¡å½ä»¤ |
| | | ConveyorLineTaskCommand taskCommand = MapTaskCommand(task, command); |
| | | // åéå½ä»¤å°è¾é线 |
| | | conveyorLine.SendCommand(taskCommand, childDeviceCode); |
| | | // æ è®°åé宿 |
| | | ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true); |
| | | // æ´æ°ä»»å¡ç¶æ |
| | | _taskService.UpdateTaskStatusToNext(task); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |