|  |  | 
 |  |  |  | 
 |  |  | #endregion << 版 本 注 释 >> | 
 |  |  |  | 
 |  |  | using Autofac.Core; | 
 |  |  | using AutoMapper; | 
 |  |  | using HslCommunication; | 
 |  |  | using Microsoft.CodeAnalysis; | 
 |  |  | using Newtonsoft.Json; | 
 |  |  | using OfficeOpenXml.FormulaParsing.Excel.Functions.Math; | 
 |  |  | using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup; | 
 |  |  | using Quartz; | 
 |  |  | using SqlSugar; | 
 |  |  | using System.Reflection; | 
 |  |  | 
 |  |  | using WIDESEAWCS_ITaskInfoService; | 
 |  |  | using WIDESEAWCS_Model.Models; | 
 |  |  | using WIDESEAWCS_QuartzJob; | 
 |  |  | using WIDESEAWCS_QuartzJob.DeviceBase; | 
 |  |  | using WIDESEAWCS_QuartzJob.DTO; | 
 |  |  | using WIDESEAWCS_QuartzJob.Repository; | 
 |  |  | using WIDESEAWCS_QuartzJob.Service; | 
 |  |  | using WIDESEAWCS_SignalR; | 
 |  |  | using WIDESEAWCS_Tasks.ConveyorLineJob; | 
 |  |  | using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database; | 
 |  |  | using ICacheService = WIDESEAWCS_Core.Caches.ICacheService; | 
 |  |  | using Platform = WIDESEAWCS_Model.Models.Platform; | 
 |  |  |  | 
 |  |  | 
 |  |  |                     foreach (string childDeviceCode in childDeviceCodes) | 
 |  |  |                     { | 
 |  |  |                         ConveyorLineTaskCommand_After command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand_After>(childDeviceCode); | 
 |  |  |  | 
 |  |  |                         if (command == null) continue; | 
 |  |  |                         if (command.ConveyorLineBarcode.Trim().Contains("\0")) command.ConveyorLineBarcode = ""; | 
 |  |  |  | 
 |  |  | 
 |  |  |                             } | 
 |  |  |                         } | 
 |  |  |  | 
 |  |  |                         if (childDeviceCode == "1670"||childDeviceCode=="1666"||childDeviceCode=="1548"||childDeviceCode=="1448") | 
 |  |  |                         if (childDeviceCode == "3464" || childDeviceCode == "3460" || childDeviceCode == "3456" ) | 
 |  |  |                         { | 
 |  |  |                             Platform platform = _platFormRepository.QueryFirst(x => x.PLCCode == conveyorLine.DeviceCode && x.PlatCode == childDeviceCode && x.Status == "Active"); | 
 |  |  |                             if (platform != null) | 
 |  |  | 
 |  |  |  | 
 |  |  |                 //ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true); | 
 |  |  |                 _taskService.UpdateTaskStatusToNext(task); | 
 |  |  |                 if (task.TaskType == (int)TaskOutboundTypeEnum.OutTray) | 
 |  |  |                 { | 
 |  |  |                     _taskService.UpdateTaskStatusToNext(task); | 
 |  |  |                 } | 
 |  |  |                 //if (task.TaskType == (int)TaskOutboundTypeEnum.OutTray) | 
 |  |  |                 //{ | 
 |  |  |                 //    _taskService.UpdateTaskStatusToNext(task); | 
 |  |  |                 //} | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  | 
 |  |  |         /// <param name="childDeviceCode">子设备编号</param> | 
 |  |  |         public void ConveyorLineOutFinish(CommonConveyorLine_GW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode) | 
 |  |  |         { | 
 |  |  |             var task = _taskService.QueryExecutingConveyorLineTask(command.ConveyorLineTaskNum, childDeviceCode); | 
 |  |  |             if (task != null) | 
 |  |  |             try | 
 |  |  |             { | 
 |  |  |                 WebResponseContent content = new WebResponseContent(); | 
 |  |  |                 ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(task); | 
 |  |  |                 taskCommand.InteractiveSignal = command.InteractiveSignal; | 
 |  |  |                 Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationPLC == conveyorLine.DeviceCode && x.stationChildCode == childDeviceCode); | 
 |  |  |                 if (task.PalletCode != command.ConveyorLineBarcode) | 
 |  |  |                 var task = _taskService.QueryExecutingConveyorLineTask(command.ConveyorLineTaskNum, childDeviceCode); | 
 |  |  |                 if (task != null) | 
 |  |  |                 { | 
 |  |  |                     //var NGAddress = _platFormRepository.QueryFirst(x => x.PlatCode == task.TargetAddress).Capacity; | 
 |  |  |                     //taskCommand.ConveyorLineTargetAddress = (short)NGAddress; | 
 |  |  |                     taskCommand.ConveyorLineTargetAddress = Convert.ToInt16(stationManager.stationNGChildCode); | 
 |  |  |                 } | 
 |  |  |                 else | 
 |  |  |                 { | 
 |  |  |                     //Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationPLC == conveyorLine.DeviceCode && x.stationChildCode == childDeviceCode); | 
 |  |  |                     taskCommand.ConveyorLineTargetAddress = Convert.ToInt16(stationManager.stationLocation); | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 if (stationManager.stationPLC == "1018" && stationManager.stationArea == "Cache")  //更新在途数据 | 
 |  |  |                 { | 
 |  |  |                     dt_needBarcode needBarcode = _needBarcodeRepository.QueryFirst(x => x.productLine == stationManager.productLine && x.toArea == stationManager.stationChildCode); | 
 |  |  |  | 
 |  |  |                     if (needBarcode != null) | 
 |  |  |                     WebResponseContent content = new WebResponseContent(); | 
 |  |  |                     ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(task); | 
 |  |  |                     taskCommand.InteractiveSignal = command.InteractiveSignal; | 
 |  |  |                     Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationPLC == conveyorLine.DeviceCode && x.stationChildCode == childDeviceCode); | 
 |  |  |                     if (task.PalletCode != command.ConveyorLineBarcode) | 
 |  |  |                     { | 
 |  |  |                         needBarcode.inLineNum--; | 
 |  |  |                         _needBarcodeRepository.UpdateData(needBarcode); | 
 |  |  |                         //var NGAddress = _platFormRepository.QueryFirst(x => x.PlatCode == task.TargetAddress).Capacity; | 
 |  |  |                         //taskCommand.ConveyorLineTargetAddress = (short)NGAddress; | 
 |  |  |                         taskCommand.ConveyorLineTargetAddress = Convert.ToInt16(stationManager.stationNGChildCode); | 
 |  |  |                     } | 
 |  |  |                     else | 
 |  |  |                     { | 
 |  |  |                         //Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationPLC == conveyorLine.DeviceCode && x.stationChildCode == childDeviceCode); | 
 |  |  |                         taskCommand.ConveyorLineTargetAddress = Convert.ToInt16(stationManager.stationLocation); | 
 |  |  |                     } | 
 |  |  |  | 
 |  |  |                     if (stationManager.stationPLC == "1007" && stationManager.stationArea == "Cache")  //更新在途数据 | 
 |  |  |                     { | 
 |  |  |                         dt_needBarcode needBarcode = _needBarcodeRepository.QueryFirst(x => x.productLine == stationManager.productLine && x.toArea == stationManager.stationChildCode); | 
 |  |  |  | 
 |  |  |                         if (needBarcode != null) | 
 |  |  |                         { | 
 |  |  |                             if (needBarcode.inLineNum == 0 || needBarcode.inLineNum > 0) | 
 |  |  |                             { | 
 |  |  |                                 needBarcode.inLineNum = 0; | 
 |  |  |                             } | 
 |  |  |                             else | 
 |  |  |                             { | 
 |  |  |                                 needBarcode.inLineNum--; | 
 |  |  |                             } | 
 |  |  |                             _needBarcodeRepository.UpdateData(needBarcode); | 
 |  |  |                         } | 
 |  |  |                     } | 
 |  |  |                     content = _taskService.UpdateTaskStatusToNext(task); | 
 |  |  |                     var proAddress = conveyorLine.DeviceProDTOs | 
 |  |  |                                     .FirstOrDefault(x => x.DeviceChildCode == childDeviceCode && x.DeviceProParamName == ConveyorLineDBName_After.InteractiveSignal.ToString()) | 
 |  |  |                                     ?.DeviceProAddress; | 
 |  |  |                     string address = proAddress.Contains(".0") ? proAddress : proAddress + ".0"; | 
 |  |  |                     conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTaskNum, taskCommand.ConveyorLineTaskNum, childDeviceCode); | 
 |  |  |                     conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTargetAddress, taskCommand.ConveyorLineTargetAddress, childDeviceCode); | 
 |  |  |                     conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineBarcode, taskCommand.ConveyorLineBarcode, childDeviceCode); | 
 |  |  |                     conveyorLine.Communicator.Write(address, 1); | 
 |  |  |                     //conveyorLine.SetValue(ConveyorLineDBName_After.InteractiveSignal, taskCommand.InteractiveSignal, childDeviceCode); | 
 |  |  |                     //conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, 1, childDeviceCode); | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 conveyorLine.SendCommand(taskCommand, childDeviceCode); | 
 |  |  |                 conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, 1, childDeviceCode); | 
 |  |  |                 //ConveyorLineSendFinish(conveyorLine, childDeviceCode, ProtocalDetailValue, true); | 
 |  |  |                 content = _taskService.UpdateTaskStatusToNext(task); | 
 |  |  |             } | 
 |  |  |             //else | 
 |  |  |             //{ | 
 |  |  |             //    Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationPLC == conveyorLine.DeviceCode && x.stationChildCode == childDeviceCode && x.stationArea == "Cache"); | 
 |  |  |             //    ////查询对应产线的在途数据 | 
 |  |  |             //    //dt_needBarcode needBarcode = _needBarcodeRepository.QueryFirst(x => x.productLine == station.productLine); | 
 |  |  |  | 
 |  |  |             //    //needBarcode.inLineNum = _taskRepository.QueryData(x => x.TargetAddress == station.stationChildCode).Count(); | 
 |  |  |  | 
 |  |  |             //    //若在途数量小于目标位置的缓存数量 则寻找对应常温库存中常温3工序的可出库数据 并建立出库任务 | 
 |  |  |             //    //if (needBarcode.inLineNum <= needBarcode.cacheNum) | 
 |  |  |             //    //{ | 
 |  |  |             //    //} | 
 |  |  |             //    //如果包装缓存站台存在 且有请求  则 | 
 |  |  |             //    if (stationManager != null) | 
 |  |  |             //    { | 
 |  |  |             //        _taskService.RequestOutTaskToBZAsync(stationManager); | 
 |  |  |             //    } | 
 |  |  |             //} | 
 |  |  |             catch (Exception ex) | 
 |  |  |             { | 
 |  |  |                 WriteInfo($"{conveyorLine.DeviceName}输送线出库完成", $"异常信息【{JsonConvert.SerializeObject(ex.Message)}】,子节点【{childDeviceCode}】托盘号:【{command.ConveyorLineBarcode}】"); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         /// <summary> | 
 |  |  | 
 |  |  |         /// <param name="command">读取的请求信息</param> | 
 |  |  |         /// <param name="childDeviceCode">子设备编号</param> | 
 |  |  |         /// <param name="index">线体当前bool读取偏移地址</param> | 
 |  |  |         public async void EmptyTrayReturn(CommonConveyorLine_GW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode, int index, WIDESEAWCS_Model.Models.Platform platform) | 
 |  |  |         public async void EmptyTrayReturn(CommonConveyorLine_GW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode, int index, Platform platform) | 
 |  |  |         { | 
 |  |  |             try | 
 |  |  |             { | 
 |  |  |                 //WriteInfo("出库", $"【{JsonConvert.SerializeObject(platform)}】"); | 
 |  |  |                 TaskOutboundTypeEnum taskOutboundTypeEnum; | 
 |  |  |                 if (platform.PlatformType.Contains("OutTray")) | 
 |  |  |                     taskOutboundTypeEnum = TaskOutboundTypeEnum.OutTray; | 
 |  |  | 
 |  |  |                     return; | 
 |  |  |  | 
 |  |  |                 taskDTO = JsonConvert.DeserializeObject<WMSTaskDTO>(content.Data.ToString()); | 
 |  |  |  | 
 |  |  |                 //WriteInfo("出库", $"【{JsonConvert.SerializeObject(taskDTO)}】"); | 
 |  |  |                 #endregion 调用WMS获取出库任务 | 
 |  |  |  | 
 |  |  |                 CreateAndSendTask(taskDTO); |