Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/ConveyorLine/CommonConveyorLine_CW.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_CW/CWTask/RequestInbound.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_CW/CommonConveyorLine_CWJob.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_QuartzJob/ConveyorLine/CommonConveyorLine_CW.cs
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,342 @@ #region << ç æ¬ 注 é >> /*---------------------------------------------------------------- * å½å空é´ï¼WIDESEAWCS_QuartzJob * å建è ï¼è¡ç«¥åº * å建æ¶é´ï¼2024/8/2 16:13:36 * çæ¬ï¼V1.0.0 * æè¿°ï¼ä¸è¬è¾é线å®ç°ç±» * * ---------------------------------------------------------------- * ä¿®æ¹äººï¼ * ä¿®æ¹æ¶é´ï¼ * çæ¬ï¼V1.0.1 * ä¿®æ¹è¯´æï¼ * *----------------------------------------------------------------*/ #endregion << ç æ¬ 注 é >> using HslCommunication; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; using WIDESEAWCS_Communicator; using WIDESEAWCS_QuartzJob.ConveyorLine.Enum; using WIDESEAWCS_QuartzJob.DeviceBase; using WIDESEAWCS_QuartzJob.DTO; using WIDESEAWCS_QuartzJob.StackerCrane.Enum; namespace WIDESEAWCS_QuartzJob { [Description("è¾é线")] public class CommonConveyorLine_CW : IConveyorLine { #region Private Member /// <summary> /// å åæºé讯对象 /// </summary> private readonly BaseCommunicator _communicator; /// <summary> /// å åæºåè®®ä¿¡æ¯ /// </summary> private readonly List<DeviceProDTO> _deviceProDTOs; /// <summary> /// å åæºåè®®æç»ä¿¡æ¯ /// </summary> private readonly List<DeviceProtocolDetailDTO> _deviceProtocolDetailDTOs; /// <summary> /// 设å¤ç¼å· /// </summary> public readonly string _deviceCode; /// <summary> /// 设å¤åç§° /// </summary> public readonly string _deviceName; private bool _heartStatr = true; private bool _isConnected = true; #endregion #region Public Member /// <summary> /// è¾é线é讯对象 /// </summary> public BaseCommunicator Communicator => _communicator; /// <summary> /// è¾é线åè®®ä¿¡æ¯ /// </summary> public List<DeviceProDTO> DeviceProDTOs => _deviceProDTOs; /// <summary> /// è¾é线åè®®æç»ä¿¡æ¯ /// </summary> public List<DeviceProtocolDetailDTO> DeviceProtocolDetailDTOs => _deviceProtocolDetailDTOs; /// <summary> /// 设å¤ç¼å· /// </summary> public string DeviceCode => _deviceCode; /// <summary> /// 设å¤åç§° /// </summary> public string DeviceName => _deviceName; /// <summary> /// æ¯å¦ææ é /// </summary> public bool IsFault => false; /// <summary> /// é讯æ¯å¦å·²è¿æ¥ /// </summary> public bool IsConnected => Communicator.IsConnected && _isConnected; /// <summary> /// 设å¤ç¶æ /// </summary> public DeviceStatus Status => DeviceStatus.Offline; #endregion #region Constructor Function /// <summary> /// æé 彿° /// </summary> /// <param name="communicator">å åæºé讯对象</param> /// <param name="deviceProDTOs">å åæºå议信æ¯</param> /// <param name="deviceProtocolDetailDTOs">å åæºåè®®æç»ä¿¡æ¯</param> /// <param name="deviceCode">设å¤ç¼å·</param> /// <param name="deviceName">设å¤åç§°</param> public CommonConveyorLine_CW(BaseCommunicator communicator, List<DeviceProDTO> deviceProDTOs, List<DeviceProtocolDetailDTO> deviceProtocolDetailDTOs, string deviceCode, string deviceName) { _communicator = communicator; _deviceProDTOs = deviceProDTOs; _deviceProtocolDetailDTOs = deviceProtocolDetailDTOs; _deviceCode = deviceCode; _deviceName = deviceName; CheckConnect(); } #endregion #region Private Method private void CheckConnect() { Task.Run(() => { while (_heartStatr) { try { DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(); if (devicePro == null) _isConnected = false; else Communicator.ReadAsObj(devicePro.DeviceProAddress, devicePro.DeviceDataType); _isConnected = true; } catch (Exception ex) { _isConnected = false; } Thread.Sleep(500); } }); } #endregion #region Public Method /// <summary> /// 读åPLCåè®®å°åçæ°æ® /// </summary> /// <typeparam name="TEnum">å议信æ¯çæä¸¾å¯¹è±¡ä¿¡æ¯ã</typeparam> /// <typeparam name="TRsult">è¯»åæ°æ®çç±»å对象信æ¯ã</typeparam> /// <param name="value">æä¸¾å¼</param> /// <param name="deviceChildCode">设å¤åç¼å·</param> /// <returns>读åå°çæ°æ®</returns> public TRsult GetValue<TEnum, TRsult>(TEnum value, string deviceChildCode) where TEnum : Enum { if (!IsConnected) throw new Exception($"éè®¯è¿æ¥é误ï¼è¯·æ£æ¥ç½ç»"); DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == value.ToString() && x.DeviceChildCode == deviceChildCode); return devicePro == null ? throw new Exception() : (TRsult)Communicator.ReadAsObj(devicePro.DeviceProAddress, devicePro.DeviceDataType); } /// <summary> /// ä¸è®¾å¤çå¿è·³ /// </summary> public void Heartbeat() { throw new NotImplementedException(); } /// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="command"></param> /// <param name="deviceChildCode"></param> /// <returns></returns> /// <exception cref="Exception"></exception> public bool SendCommand<T>(T command, string deviceChildCode) where T : IDataTransfer, new() { if (!IsConnected) throw new Exception($"éè®¯è¿æ¥é误ï¼è¯·æ£æ¥ç½ç»"); DeviceProDTO? devicePro = _deviceProDTOs.Where(x => x.DeviceProParamType == nameof(DeviceCommand) && x.DeviceChildCode == deviceChildCode).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); if (devicePro == null) { return false; } if (Communicator.WriteCustomer(devicePro.DeviceProAddress, command)) { return true; } return false; } /// <summary> /// 读åPLCæ°æ®ï¼è¿åèªå®ä¹å¯¹è±¡ /// </summary> /// <typeparam name="T">æ³å</typeparam> /// <param name="deviceChildCode">å设å¤ç¼å·</param> /// <returns>è¿åèªå®ä¹å¯¹è±¡ææåºå¼å¸¸</returns> /// <exception cref="Exception"></exception> public T ReadCustomer<T>(string deviceChildCode) where T : IDataTransfer, new() { if (!IsConnected) throw new Exception($"éè®¯è¿æ¥é误ï¼è¯·æ£æ¥ç½ç»"); DeviceProDTO? devicePro = _deviceProDTOs.Where(x => x.DeviceProParamType == "DeviceCommand" && x.DeviceChildCode == deviceChildCode).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); if (devicePro == null) { throw new Exception($"ã{_deviceCode}ã--æªæ¾å°ã{deviceChildCode}ãå议信æ¯"); } else { return Communicator.ReadCustomer<T>(devicePro.DeviceProAddress); } } /// <summary> /// 读åPLCæ°æ®ï¼è¿åèªå®ä¹å¯¹è±¡ /// </summary> /// <typeparam name="T">æ³å</typeparam> /// <param name="deviceChildCode">å设å¤ç¼å·</param> /// <param name="deviceProParamType">åæ°ç±»å</param> /// <returns>è¿åèªå®ä¹å¯¹è±¡ææåºå¼å¸¸</returns> /// <exception cref="Exception"></exception> public T ReadCustomer<T>(string deviceChildCode, string deviceProParamType) where T : IDataTransfer, new() { if (!IsConnected) throw new Exception($"éè®¯è¿æ¥é误ï¼è¯·æ£æ¥ç½ç»"); DeviceProDTO? devicePro = _deviceProDTOs.Where(x => x.DeviceProParamType == deviceProParamType && x.DeviceChildCode == deviceChildCode).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); if (devicePro == null) { throw new Exception($"æªæ¾å°ã{deviceChildCode}ãå议信æ¯"); } else { return Communicator.ReadCustomer<T>(devicePro.DeviceProAddress); } } /// <summary> /// æ ¹æ®åæ°åç§°ã设å¤åç¼å·åå ¥å¯¹åºçæ°æ®ã /// </summary> /// <typeparam name="TEnum">åæ°åç§°æä¸¾ç±»åã</typeparam> /// <typeparam name="TValue">è¦åå ¥çæ°æ®ç±»åã</typeparam> /// <param name="enum">åæ°åç§°ã</param> /// <param name="value">è¦åå ¥çæ°æ®ã</param> /// <param name="deviceChildCode">设å¤åç¼å·å</param> /// <returns>è¿ååå ¥æåæå¤±è´¥</returns> public bool SetValue<TEnum, TValue>(TEnum @enum, TValue value, string deviceChildCode) where TEnum : Enum where TValue : notnull { if (!IsConnected) throw new Exception($"éè®¯è¿æ¥é误ï¼è¯·æ£æ¥ç½ç»"); DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == @enum.ToString() && x.DeviceChildCode == deviceChildCode); return devicePro == null ? throw new Exception() : Communicator.WriteObj(devicePro.DeviceProAddress, devicePro.DeviceDataType, value); } /// <summary> /// æ ¹æ®åæ°åç§°ã设å¤åç¼å·è¯»å对åºçæ°æ®ã /// </summary> /// <typeparam name="TEnum">åæ°åç§°æä¸¾ç±»åã</typeparam> /// <param name="enum">åæ°åç§°ã</param> /// <param name="deviceChildCode">设å¤åç¼å·å</param> /// <returns>è¿ååå ¥æåæå¤±è´¥</returns> public object ReadValue<TEnum>(TEnum @enum, string deviceChildCode) where TEnum : Enum { if (!IsConnected) throw new Exception($"éè®¯è¿æ¥é误ï¼è¯·æ£æ¥ç½ç»"); DeviceProDTO? devicePro = _deviceProDTOs.FirstOrDefault(x => x.DeviceProParamName == @enum.ToString() && x.DeviceChildCode == deviceChildCode); return devicePro == null ? throw new Exception() : Communicator.ReadAsObj(devicePro.DeviceProAddress, devicePro.DeviceDataType); } //public bool IsOccupied(string deviceChildCode) //{ // if (Communicator.IsConnected) // { // } //} /// <summary> /// /// </summary> /// <param name="deviceChildCode"></param> /// <returns></returns> /// <exception cref="Exception"></exception> public bool IsOccupied(string deviceChildCode) { if (Communicator.IsConnected) { List<DeviceProDTO> devicePros = _deviceProDTOs.Where(x => x.DeviceChildCode == deviceChildCode && x.DeviceProParamName == "InteractiveSignal").ToList(); if (devicePros.Count == 0) { //todo åè®®ä¿¡æ¯æªè·åå°æ¶æåºå¼å¸¸ throw new Exception(); } for (int i = 0; i < devicePros.Count; i++) { object readStatus = Communicator.ReadAsObj(devicePros[i].DeviceProAddress, devicePros[i].DeviceDataType); //todo åè®®æç»ä¿¡æ¯æªè·åå°æ¶æåºå¼å¸¸ DeviceProtocolDetailDTO? deviceProtocolDetail = _deviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == devicePros[i].DeviceProParamName) ?? throw new Exception(); deviceProtocolDetail = _deviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == "InteractiveSignal" && x.ProtocalDetailValue.Equals(readStatus.ToString())); if (deviceProtocolDetail != null) { return true; } return false; } } //todo é讯æªè¿æ¥æ¶æåºå¼å¸¸ return false; } public void Dispose() { _heartStatr = false; _communicator.Dispose(); GC.SuppressFinalize(this); } #endregion } } Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_CW/CWTask/RequestInbound.cs
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,420 @@ using Mapster; using Masuit.Tools; using Newtonsoft.Json; using System.Threading.Tasks; using WIDESEAWCS_Common; using WIDESEAWCS_Common.TaskEnum; using WIDESEAWCS_Core; using WIDESEAWCS_Core.Helper; using WIDESEAWCS_DTO.TaskInfo; using WIDESEAWCS_DTO.WMS; using WIDESEAWCS_Model.Models; using WIDESEAWCS_QuartzJob; using WIDESEAWCS_Tasks.ConveyorLineJob; using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database; namespace WIDESEAWCS_Tasks { public partial class CommonConveyorLine_CWJob { /// <summary> /// å¤çåºåºä»»å¡ /// </summary> private void HandleTaskOut(CommonConveyorLine_CW conveyorLine, ConveyorLineTaskCommand_After 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) { CompleteWmsTask(taskOut, command, conveyorLine, childDeviceCode, ProtocalDetailValue); } } /// <summary> /// å¤çæ°ä»»å¡ /// </summary> private void HandleNewTask(CommonConveyorLine_CW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode) { Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationPLC == conveyorLine.DeviceCode && x.stationChildCode == childDeviceCode); if (stationManager == null) { // Handle the case where stationManager is not found, if necessary Console.WriteLine($"æªæ¾å°{childDeviceCode}ç«å°"); return; } // æ ¹æ®ç«ç±»åæ§è¡ç¸åºçæ¹æ³ switch (stationManager.stationType) { case 8: case 9: case 11: case 12: var task = _taskService.QueryExecutingTaskByBarcode(command.ConveyorLineBarcode, childDeviceCode); if (task != null) { ExecuteStationAction(stationManager, conveyorLine, command, childDeviceCode); } break; case 1: case 6: case 10: ExecuteStationAction(stationManager, conveyorLine, command, childDeviceCode); break; //case 16: // ExecuteStationAction(stationManager, conveyorLine, command, childDeviceCode); // break; } #region //Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationPLC == conveyorLine.DeviceCode && x.stationChildCode == childDeviceCode); //if (stationManager.stationType == 8) //{ // var task = _taskService.QueryExecutingConveyorLineTask(command.ConveyorLineTaskNum, childDeviceCode); // if (task != null) // { // RequestInNextAddress(conveyorLine, command, childDeviceCode); // } //} //else if (stationManager.stationType == 9) //{ // var task = _taskService.QueryExecutingConveyorLineTask(command.ConveyorLineTaskNum, childDeviceCode); // if (task != null) // { // ConveyorLineInFinish(conveyorLine, command, childDeviceCode); // } //} //else if (stationManager.stationType == 1) //{ // if (stationManager.stationArea.Contains("GW")) // { // var taskGW = _taskRepository.QueryFirst(x => x.TargetAddress == childDeviceCode && x.TaskState == (int)TaskOutStatusEnum.OutFinish); // if (taskGW != null) // { // command.ConveyorLineBarcode = taskGW.PalletCode; // } // } // RequestWmsTask(conveyorLine, command, childDeviceCode); //} //else if (stationManager.stationType == 10) //{ // var task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode); // if (task != null) // { // RequestOutbound(conveyorLine, command, childDeviceCode); // } //} //else if (stationManager.stationType == 11) //{ // var task = _taskService.QueryExecutingConveyorLineTask(command.ConveyorLineTaskNum, childDeviceCode); // if (task != null) // { // RequestOutNextAddress(conveyorLine, command, childDeviceCode); // } //} //else if (stationManager.stationType == 12) //{ // var task = _taskService.QueryExecutingConveyorLineTask(command.ConveyorLineTaskNum, childDeviceCode); // if (task != null) // { // ConveyorLineOutFinish(conveyorLine, command, childDeviceCode); // } //} #endregion } private void ExecuteStationAction(Dt_StationManager stationManager, CommonConveyorLine_CW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode) { switch (stationManager.stationType) { case 8: RequestInNextAddress(conveyorLine, command, childDeviceCode); break; case 9: ConveyorLineInFinish(conveyorLine, command, childDeviceCode); break; case 10: RequestOutbound(conveyorLine, command, childDeviceCode); break; case 11: RequestOutNextAddress(conveyorLine, command, childDeviceCode); break; case 12: ConveyorLineOutFinish(conveyorLine, command, childDeviceCode); break; case 6: CreateAndSendEmptyTrayTask(conveyorLine, command, childDeviceCode); break; case 16: AbNormalStationBZTask(conveyorLine, command, childDeviceCode); break; case 1: //if (stationManager.stationArea.Contains("GW")) //{ //var taskGW = _taskRepository.QueryFirst(x => x.TargetAddress == childDeviceCode && (x.TaskState == (int)TaskOutStatusEnum.OutFinish || x.TaskState == (int)TaskOutStatusEnum.OutPending)); //if (taskGW != null) //{ // command.ConveyorLineBarcode = taskGW.PalletCode; //} //} //å¦é«æ¸©åºåºå任塿 è®°NGå¼å¸¸åå°ä»»å¡æ´æ°ä¸ºå¼å¸¸æåºä»»å¡ --å å®åæ¶è¶ æ¶æ£æµå æçè¶ æ¶ä¸å¨åºåºè³å¼å¸¸å£ //Dt_Task NGtask = _taskRepository.QueryFirst(x => x.Remark == "NG" && x.Roadway == stationManager.Roadway && x.Roadway.Contains("GW")); //if (NGtask != null) //{ // CreateAbNormalOutbound(conveyorLine, command, childDeviceCode, NGtask); // break; //} RequestWmsTask(conveyorLine, command, childDeviceCode, stationManager); break; } } /// <summary> /// æ å°ä»»å¡å½ä»¤ /// </summary> private ConveyorLineTaskCommand_After MapTaskCommand(Dt_Task task, ConveyorLineTaskCommand_After command) { var comm = _mapper.Map<ConveyorLineTaskCommand_After>(task); comm.InteractiveSignal = command.InteractiveSignal; return comm; } /// <summary> /// 宿WMSä»»å¡ /// </summary> private void CompleteWmsTask(Dt_Task taskOut, ConveyorLineTaskCommand_After command, CommonConveyorLine_CW conveyorLine, string childDeviceCode, int ProtocalDetailValue) { if (command.ConveyorLineBarcode == "NoRead") { var NGAddress = _platFormRepository.QueryFirst(x => x.PlatCode == taskOut.TargetAddress).Capacity; taskOut.TargetAddress = NGAddress.ToString(); } var keys = new Dictionary<string, object>() { {"taskNum", taskOut.TaskNum} }; var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress); var wmsBase = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.WMSIP_BASE)?.ConfigValue; var completeTask = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.CompleteTask)?.ConfigValue; if (wmsBase == null || completeTask == null) { throw new InvalidOperationException("WMS IP æªé ç½®"); } var wmsIpAddress = wmsBase + completeTask; var result = HttpHelper.GetAsync(wmsIpAddress, 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_CW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode) { if (command.ConveyorLineBarcode != "NoRead") { var taskDTO = CreateEmptyTrayTaskDto(command.ConveyorLineBarcode, childDeviceCode); if (_taskRepository.QueryFirst(x => x.PalletCode == command.ConveyorLineBarcode) != null) { List<string> strings = new List<string>() { "1743", "1739", "1837", "1841" }; var taskExecuting = _taskRepository.QueryFirst(x => x.PalletCode == command.ConveyorLineBarcode && x.TaskState == (int)TaskOutStatusEnum.Line_OutExecuting && strings.Contains(x.TargetAddress)); if (taskExecuting != null) { taskExecuting.ExceptionMessage = "æªæ¥æ¶å°çº¿ä½å®æä¿¡å·ç³»ç»å é¨èªå¨å®æ"; _taskService.Delete(taskExecuting); } ConsoleHelper.WriteErrorLine($"å½åæçåå¨ä»»å¡ï¼ã{command.ConveyorLineBarcode}ã"); WriteInfo(conveyorLine.DeviceName, $"å½åæçåå¨ä»»å¡{command.ConveyorLineBarcode}"); } var content = CreateAndSendTask(taskDTO); if (content.Status) { var task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode, command.ConveyorLineBarcode); if (task != null) { var taskCommand = MapTaskCommand(task, command); bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode); if (sendFlag) { _taskService.UpdateTaskStatusToNext(task); } } } } } /// <summary> /// å建空æçä»»å¡DTO /// </summary> private WMSTaskDTO CreateEmptyTrayTaskDto(string barcode, string childDeviceCode) { var request = new RequestTaskDto() { Position = childDeviceCode, PalletCode = barcode, }; var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress); var wmsBase = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.WMSIP_BASE)?.ConfigValue; var requestTrayInTask = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.RequestTrayInTask)?.ConfigValue; if (wmsBase == null || requestTrayInTask == null) { throw new InvalidOperationException("WMS IP æªé ç½®"); } var wmsIpAddrss = wmsBase + requestTrayInTask; var result = HttpHelper.PostAsync(wmsIpAddrss, request.ToJsonString()).Result; if (result == null) return new WMSTaskDTO(); WebResponseContent content = JsonConvert.DeserializeObject<WebResponseContent>(result); if (!content.Status) return new WMSTaskDTO(); return JsonConvert.DeserializeObject<WMSTaskDTO>(content.Data.ToString()); } /// <summary> /// 请æ±WMSä»»å¡ /// </summary> private async void RequestWmsTask(CommonConveyorLine_CW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode, Dt_StationManager stationManager) { try { if (command.ConveyorLineBarcode.IsNullOrEmpty()) return; var content = await _taskService.RequestWMSTask(command.ConveyorLineBarcode, childDeviceCode); if (content.Status) { var task = _taskService.QueryBarCodeConveyorLineTask(command.ConveyorLineBarcode, childDeviceCode); if (task != null) { if (childDeviceCode == "1039") { var GWTask = _taskRepository.QueryData(x => x.Roadway.Contains("GWSC2") && x.SourceAddress == "1039" && (x.TaskState == (int)TaskInStatusEnum.Line_InExecuting || x.TaskState == (int)TaskInStatusEnum.Line_InFinish)).ToList(); if (GWTask.Count >= 2 && childDeviceCode == "1039" && task.Roadway.Contains("GWSC2")) { ConsoleHelper.WriteErrorLine($"æçå·ï¼ã{command.ConveyorLineBarcode}ã髿¸©äºå·²åå¨ã{GWTask.Count}ã个任å¡å¤§äº2个任å¡ä¸å¯ä¸å"); return; } } ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(task); //conveyorLine.SendCommand(taskCommand, childDeviceCode); bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode); if (sendFlag) { conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode); _taskService.UpdateTaskStatusToNext(task); } } } else { if (content.Message != "请æ±è¿äºé¢ç¹ï¼è¯·ç¨ååè¯" && content.Message != "æ æ³è·åç®æ å°å") { WriteInfo(conveyorLine.DeviceName, content.Message); conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTargetAddress, stationManager.stationNGChildCode, childDeviceCode); conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode); ConsoleHelper.WriteErrorLine($"ã{conveyorLine.DeviceName}ãæçå·ï¼ã{command.ConveyorLineBarcode}ã请æ±ç¹ä½ï¼ã{childDeviceCode}ãå¼å¸¸ä¿¡æ¯ã{content.Message}ã"); WriteInfo(conveyorLine.DeviceName, $"ã{conveyorLine.DeviceName}ãæçå·ï¼ã{command.ConveyorLineBarcode}ã请æ±ç¹ä½ï¼ã{childDeviceCode}ãå¼å¸¸ä¿¡æ¯ã{content.Message}ã"); } ConsoleHelper.WriteErrorLine($"ã{conveyorLine.DeviceName}ãæçå·ï¼ã{command.ConveyorLineBarcode}ã请æ±ç¹ä½ï¼ã{childDeviceCode}ãå¼å¸¸ä¿¡æ¯ã{content.Message}ã"); } } catch (Exception ex) { WriteInfo(conveyorLine.DeviceName, $"ã{conveyorLine.DeviceName}ãæçå·ï¼ã{command.ConveyorLineBarcode}ã请æ±ç¹ä½ï¼ã{childDeviceCode}ãå¼å¸¸ä¿¡æ¯ã{ex.Message}ãå¼å¸¸è¡ã{ex.StackTrace}ã"); } } /// <summary> /// 髿¸©åºåºåä»»å¡å®æ 妿任塿 è¯NGåå°ä»»å¡æ¹ä¸ºå¼å¸¸æåºä»»å¡ /// </summary> /// <param name="conveyorLine"></param> /// <param name="command"></param> /// <param name="childDeviceCode"></param> /// <param name="task"></param> /// <exception cref="Exception"></exception> private void CreateAbNormalOutbound(CommonConveyorLine_CW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode, Dt_Task task) { Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == childDeviceCode); if (stationManager == null || string.IsNullOrWhiteSpace(stationManager.stationNGChildCode) || string.IsNullOrWhiteSpace(stationManager.stationNGLocation)) { throw new Exception("æªé ç½®ç«å°ç对åºNGå£ä¿¡æ¯"); } task.SourceAddress = task.TargetAddress; task.TargetAddress = stationManager.stationNGLocation; task.TaskState = (int)TaskOutStatusEnum.OutNew; task.TaskType = (int)TaskOutboundTypeEnum.InToOut; task.Grade = 10; //æ¤å¤ åºåºè³å¼å¸¸æåºå£çä»»å¡åºé¤ç«è¦å¤æä¼å æ§è¡ _taskRepository.UpdateData(task); //Dt_Task task= _taskRepository.QueryFirst(x=>) //_taskRepository.QueryFirst() } /// <summary> /// å è£ å¼å¸¸æåºå£é»è¾ /// </summary> /// <param name="conveyorLine"></param> /// <param name="command"></param> /// <param name="childDeviceCode"></param> private void AbNormalStationBZTask(CommonConveyorLine_CW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode) { Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationChildCode == childDeviceCode && x.stationPLC == conveyorLine.DeviceCode); if (command.ConveyorLineBarcode.IsNullOrEmpty()) { conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode); return; } if (conveyorLine.ReadValue(ConveyorLineDBName_After.InteractiveSignal, childDeviceCode).ObjToInt() == 0) //æçæ£åä¿¡å· { } ; conveyorLine.ReadValue(ConveyorLineDBName_After.InteractiveSignal, childDeviceCode); //æçææ çµè¯ä¿¡å· } } } Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob_CW/CommonConveyorLine_CWJob.cs
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,632 @@ #region MyRegion #region << ç æ¬ 注 é >> /*---------------------------------------------------------------- * å½å空é´ï¼WIDESEAWCS_Tasks.ConveyorLineJob * å建è ï¼è¡ç«¥åº * å建æ¶é´ï¼2024/8/2 16:13:36 * çæ¬ï¼V1.0.0 * æè¿°ï¼ * * ---------------------------------------------------------------- * ä¿®æ¹äººï¼ * ä¿®æ¹æ¶é´ï¼ * çæ¬ï¼V1.0.1 * ä¿®æ¹è¯´æï¼ * *----------------------------------------------------------------*/ #endregion << ç æ¬ 注 é >> using AutoMapper; using HslCommunication; using Masuit.Tools; using Microsoft.CodeAnalysis; using Newtonsoft.Json; using Quartz; using SqlSugar; using System.ComponentModel.Design; using System.Reflection; using WIDESEAWCS_BasicInfoRepository; using WIDESEAWCS_Common; using WIDESEAWCS_Common.TaskEnum; using WIDESEAWCS_Core; using WIDESEAWCS_Core.Helper; using WIDESEAWCS_Core.HttpContextUser; using WIDESEAWCS_DTO.MOM; using WIDESEAWCS_DTO.TaskInfo; using WIDESEAWCS_IProcessRepository; using WIDESEAWCS_ISystemServices; using WIDESEAWCS_ITaskInfoRepository; using WIDESEAWCS_ITaskInfoService; using WIDESEAWCS_Model.Models; using WIDESEAWCS_QuartzJob; using WIDESEAWCS_QuartzJob.DTO; using WIDESEAWCS_QuartzJob.Repository; using WIDESEAWCS_QuartzJob.Service; using WIDESEAWCS_SignalR; using WIDESEAWCS_Tasks.ConveyorLineJob; using ICacheService = WIDESEAWCS_Core.Caches.ICacheService; using Platform = WIDESEAWCS_Model.Models.Platform; namespace WIDESEAWCS_Tasks { [DisallowConcurrentExecution] public partial class CommonConveyorLine_CWJob : JobBase, IJob { public readonly ITaskService _taskService; private readonly ITaskRepository _taskRepository; private readonly ITaskExecuteDetailService _taskExecuteDetailService; private readonly IRouterService _routerService; private readonly IPlatFormRepository _platFormRepository; private readonly ISys_ConfigService _sys_ConfigService; private readonly IMapper _mapper; private readonly IDt_StationManagerRepository _stationManagerRepository; private readonly ICacheService _cacheService; private readonly INoticeService _noticeService; private readonly IDt_needBarcodeRepository _needBarcodeRepository; private readonly IDeviceInfoRepository _deviceInfoRepository; private static List<string>? userTokenIds; private static List<int>? userIds; private static List<string> childCodeList = new List<string>(); public CommonConveyorLine_CWJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IMapper mapper, ITaskRepository taskRepository, IPlatFormRepository platFormRepository, ISys_ConfigService sys_ConfigService, IDt_StationManagerRepository stationManagerRepository, ICacheService cacheService, INoticeService noticeService, IDt_needBarcodeRepository needBarcodeRepository, IDeviceInfoRepository deviceInfoRepository) { _taskService = taskService; _taskExecuteDetailService = taskExecuteDetailService; _routerService = routerService; _mapper = mapper; _taskRepository = taskRepository; _platFormRepository = platFormRepository; _sys_ConfigService = sys_ConfigService; _stationManagerRepository = stationManagerRepository; _cacheService = cacheService; _noticeService = noticeService; _needBarcodeRepository = needBarcodeRepository; _deviceInfoRepository = deviceInfoRepository; } public Task Execute(IJobExecutionContext context) { try { CommonConveyorLine_CW conveyorLine = (CommonConveyorLine_CW)context.JobDetail.JobDataMap.Get("JobParams"); if (conveyorLine != null) { #region ç«å°æ¹å¼ //List<Dt_StationManager> stationManagers = _stationManagerService.GetAllStationByDeviceCode(conveyorLine.DeviceCode); //foreach (var station in stationManagers) //{ // ConveyorLineTaskCommand_After command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand_After>(station.stationChildCode); // DeviceProtocolDetailDTO? deviceProtocolDetails = conveyorLine.DeviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == nameof(ConveyorLineTaskCommand_After.InteractiveSignal) && x.ProtocalDetailValue == command.InteractiveSignal.ToString()); // if (deviceProtocolDetails != null) // { // MethodInfo? method = GetType().GetMethod(deviceProtocolDetails.ProtocolDetailType); // if (method != null) // { // method.Invoke(this, new object[] { conveyorLine, command, station }); // } // } //} #endregion ç«å°æ¹å¼ #region è·¯ç±æ¹å¼ List<string> childDeviceCodes = _routerService.QueryAllPositions(conveyorLine.DeviceCode); DateTime dateTime = DateTime.Now; Console.WriteLine($"循ç¯å¼å§æ¶é´{dateTime}"); foreach (string childDeviceCode in childDeviceCodes) { //Thread.Sleep(1000); //if (childCodeList.Contains(childDeviceCode)) //{ // Console.WriteLine($"å½å{childDeviceCode}æ§è¡ä¸ï¼å·²è·³è¿"); // continue; //} //childCodeList.Add(childDeviceCode); //Console.WriteLine(childDeviceCode); ConveyorLineTaskCommand_After command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand_After>(childDeviceCode); if (command == null) continue; //if (command.InteractiveSignal == 0 && command.HasPallet != 1) continue; if (command.ConveyorLineBarcode.Trim().Contains("\0")) command.ConveyorLineBarcode = ""; DeviceProtocolDetailDTO? deviceProtocolDetails = conveyorLine.DeviceProtocolDetailDTOs.FirstOrDefault(x => x.DeviceProParamName == nameof(ConveyorLineTaskCommand_After.InteractiveSignal) && x.ProtocalDetailValue == command.InteractiveSignal.ToString()); if (deviceProtocolDetails != null) { MethodInfo? method = GetType().GetMethod(deviceProtocolDetails.ProtocolDetailType); if (method != null) { method.Invoke(this, new object[] { conveyorLine, command, childDeviceCode }); } } if (childDeviceCode == "1670" || childDeviceCode == "1666" || childDeviceCode == "1548" || childDeviceCode == "1448") { Platform platform = _platFormRepository.QueryFirst(x => x.DeviceCode == conveyorLine.DeviceCode && x.PlatCode == childDeviceCode && x.Status == "Active"); if (platform != null) { if (command.HasPallet != 1) { MethodInfo? method = GetType().GetMethod(platform.ExecutionMethod); if (method != null) { //var strings = platform.Location.Split(',').ToList(); int count = 1; method.Invoke(this, new object[] { conveyorLine, command, childDeviceCode, count, platform }); } } } } //childCodeList.Remove(childDeviceCode); #region è°ç¨äºä»¶æ»çº¿éç¥å端 var tokenInfos = _cacheService.Get<List<UserInfo>>("Cache_UserToken"); if (tokenInfos == null || !tokenInfos.Any()) { //throw new Exception(conveyorLine.DeviceName + "ç¼å䏿ªæ¾å°Tokenç¼å"); continue; } var userTokenIds = tokenInfos?.Select(x => x.Token_ID).ToList(); var userIds = tokenInfos?.Select(x => x.UserId).ToList(); object obj = new { childDeviceCode, commandAfter = command, }; _noticeService.LineData(userIds?.FirstOrDefault(), userTokenIds, new { conveyorLine.DeviceName, data = obj }); #endregion è°ç¨äºä»¶æ»çº¿éç¥å端 } DateTime ENDdateTime = DateTime.Now; Console.WriteLine($"循ç¯ç»ææ¶é´{ENDdateTime}"); #endregion è·¯ç±æ¹å¼ } } catch (Exception ex) { Console.Out.WriteLine(nameof(CommonConveyorLine_CWJob) + ":" + DateTime.Now + ":" + ex.ToString()); } finally { //WriteDebug("CommonConveyorLineJob", "test"); //Console.Out.WriteLine(DateTime.Now); } return Task.CompletedTask; } /// <summary> /// è¾é线请æ±å ¥åº /// </summary> /// <param name="conveyorLine">è¾é线å®ä¾å¯¹è±¡</param> /// <param name="command">读åç请æ±ä¿¡æ¯</param> /// <param name="childDeviceCode">å设å¤ç¼å·</param> /// <param name="ProtocalDetailValue">线ä½å½åbool读ååç§»å°å</param> public void RequestInbound(CommonConveyorLine_CW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode) { try { var task = _taskService.QueryBarCodeConveyorLineTask(command.ConveyorLineBarcode, childDeviceCode); var log = $"æ¶é´ï¼ã{DateTime.Now}ãã{conveyorLine.DeviceName}ãæçå·ï¼ã{command.ConveyorLineBarcode}ãä»»å¡å·ï¼ã{command.ConveyorLineTaskNum}ã设å¤ç¼ç ï¼ã{childDeviceCode}ã"; ConsoleHelper.WriteSuccessLine(log); //_noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" }); WriteInfo(conveyorLine.DeviceName, log); if (task == null) { HandleNewTask(conveyorLine, command, childDeviceCode); } else { if (childDeviceCode == "1039") { var GWTask = _taskRepository.QueryData(x => x.Roadway.Contains("GWSC2") && x.SourceAddress == "1039" && (x.TaskState == (int)TaskInStatusEnum.Line_InExecuting || x.TaskState == (int)TaskInStatusEnum.Line_InFinish)).ToList(); if (GWTask.Count >= 2 && childDeviceCode == "1039" && task.Roadway.Contains("GWSC2")) { ConsoleHelper.WriteErrorLine($"æ¶é´ï¼ã{DateTime.Now}ãæçå·ï¼ã{command.ConveyorLineBarcode}ã髿¸©äºå·²åå¨ã{GWTask.Count}ã个任å¡å¤§äº2个任å¡ä¸å¯ä¸å"); return; } } ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(task); bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode); if (sendFlag) { conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode); _taskService.UpdateTaskStatusToNext(task); } } } catch (Exception ex) { Console.Out.WriteLine(ex.ToString()); } } /// <summary> /// è¾é线请æ±å ¥åºä¸ä¸å°å /// </summary> /// <param name="conveyorLine">è¾é线å®ä¾å¯¹è±¡</param> /// <param name="command">读åç请æ±ä¿¡æ¯</param> /// <param name="childDeviceCode">å设å¤ç¼å·</param> public void RequestInNextAddress(CommonConveyorLine_CW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode) { Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.ConveyorLineTaskNum, childDeviceCode, command.ConveyorLineBarcode); if (task != null) { if (command.ConveyorLineBarcode != task.PalletCode) { conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode); return; } Dt_Task? newTask = _taskService.UpdatePosition(task.TaskNum, task.CurrentAddress); if (newTask != null) { ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(newTask); //conveyorLine.SendCommand(taskCommand, childDeviceCode); bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode); if (sendFlag) { conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode); _taskService.UpdateData(newTask); } } } //else //{ // //å½åå°åè¯·æ± å¯»æ¾å½åå°åçæçå· ä»»å¡å·çä»»å¡ï¼å¦åå¨ä»»å¡å鿰忬¡åå ¥æ°ç®æ å°å // Dt_Task currentTask = _taskService.QueryExecutingCurrentConveyorLineTask(command.ConveyorLineTaskNum, childDeviceCode, command.ConveyorLineBarcode); // if (currentTask != null) // { // conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTargetAddress, Convert.ToInt16(currentTask.TargetAddress), childDeviceCode); // } //} } /// <summary> /// è¾éçº¿å ¥åºå®æ /// </summary> /// <param name="conveyorLine">è¾é线å®ä¾å¯¹è±¡</param> /// <param name="command">读åç请æ±ä¿¡æ¯</param> /// <param name="childDeviceCode">å设å¤ç¼å·</param> /// <param name="ProtocalDetailValue">线ä½å½åbool读ååç§»å°å</param> public void ConveyorLineInFinish(CommonConveyorLine_CW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode) { var task = _taskService.QueryExecutingTaskByBarcode(command.ConveyorLineBarcode, childDeviceCode); if (task != null && task.TaskState != (int)TaskInStatusEnum.Line_InFinish) { WebResponseContent content = _taskService.UpdateTaskStatusToNext(task); if (content.Status) { conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode); } Console.Out.WriteLine(content.Serialize()); } } /// <summary> /// è¾é线请æ±åºä¿¡æ¯ /// </summary> /// <param name="conveyorLine">è¾é线å®ä¾å¯¹è±¡</param> /// <param name="command">读åç请æ±ä¿¡æ¯</param> /// <param name="childDeviceCode">å设å¤ç¼å·</param> /// <param name="ProtocalDetailValue">线ä½å½åbool读ååç§»å°å</param> public void RequestOutbound(CommonConveyorLine_CW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode) { var task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode); if (task != null) { ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(task); //conveyorLine.SendCommand(taskCommand, childDeviceCode); bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode); if (sendFlag) { conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode); _taskService.UpdateTaskStatusToNext(task); if (task.TaskType == (int)TaskOutboundTypeEnum.OutTray) { _taskService.UpdateTaskStatusToNext(task); } } } } /// <summary> /// è¾é线请æ±åºåºä¸ä¸å°å /// </summary> /// <param name="conveyorLine">è¾é线å®ä¾å¯¹è±¡</param> /// <param name="command">读åç请æ±ä¿¡æ¯</param> /// <param name="childDeviceCode">å设å¤ç¼å·</param> public void RequestOutNextAddress(CommonConveyorLine_CW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode) { Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.ConveyorLineTaskNum, childDeviceCode, command.ConveyorLineBarcode); if (task != null) { var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress); var wmsBase = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.MOMIP_BASE)?.ConfigValue; var ipAddress = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.TrayCellsStatus)?.ConfigValue; if (wmsBase == null || ipAddress == null) { throw new InvalidOperationException("MOM IP æªé ç½®"); } Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationPLC == conveyorLine.DeviceCode && x.stationChildCode == childDeviceCode); TrayCellsStatusDto trayCells = new TrayCellsStatusDto() { Software = "WMS", TrayBarcode = command.ConveyorLineBarcode, EquipmentCode = stationManager.stationEquipMOM, SessionId = Guid.NewGuid().ToString(), EmployeeNo = "MITest", SceneType = "1", RequestTime = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).ToString("yyyy-MM-ddTHH:mm:ss.fffZ") }; var MOMIpAddress = wmsBase + ipAddress; var result = HttpHelper.PostAsync(MOMIpAddress, trayCells.Serialize()).Result; WriteInfo("å ¥ç«æ ¡éª", $"ã{childDeviceCode}ãå ¥ç«æ ¡éªè¯·æ±åæ°ã{trayCells.Serialize()}ã"); WriteInfo("å ¥ç«æ ¡éª", ""); WriteInfo("å ¥ç«æ ¡éª", $"ã{childDeviceCode}ãå ¥ç«æ ¡éªè¿ååæ°ã{result}ã"); ResultTrayCellsStatus result1 = JsonConvert.DeserializeObject<ResultTrayCellsStatus>(result); if (result1.Success || task.Remark != "NG") { Dt_Task? newTask = _taskService.UpdatePosition(task.TaskNum, task.CurrentAddress); if (newTask != null) { ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(newTask); //conveyorLine.SendCommand(taskCommand, childDeviceCode); bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode); if (sendFlag) { conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode); _taskService.UpdateData(newTask); } } } else { ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(task); taskCommand.ConveyorLineTargetAddress = Convert.ToInt16(stationManager.stationNGChildCode); //conveyorLine.SendCommand(taskCommand, childDeviceCode); bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode); if (sendFlag) { conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode); _taskService.UpdateTaskStatusToNext(task); } } } } /// <summary> /// è¾é线åºåºå®æ /// </summary> /// <param name="conveyorLine">è¾é线å®ä¾å¯¹è±¡</param> /// <param name="command">读åç请æ±ä¿¡æ¯</param> /// <param name="childDeviceCode">å设å¤ç¼å·</param> public void ConveyorLineOutFinish(CommonConveyorLine_CW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode) { var log = $"æ¶é´ï¼ã{DateTime.Now}ãã{conveyorLine.DeviceName}ãæçå·ï¼ã{command.ConveyorLineBarcode}ãä»»å¡å·ï¼ã{command.ConveyorLineTaskNum}ã设å¤ç¼ç ï¼ã{childDeviceCode}ã"; ConsoleHelper.WriteSuccessLine(log); //_noticeService.Logs(userTokenIds, new { conveyorLine.DeviceName, log = log, time = DateTime.Now.ToString("G"), color = "red" }); WriteInfo(conveyorLine.DeviceName, log); var task = _taskService.QueryExecutingConveyorLineTask(command.ConveyorLineTaskNum, childDeviceCode, command.ConveyorLineBarcode); if (task != 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) { taskCommand.ConveyorLineTargetAddress = Convert.ToInt16(stationManager.stationNGChildCode); } else { 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) { needBarcode.inLineNum--; _needBarcodeRepository.UpdateData(needBarcode); } } //conveyorLine.SendCommand(taskCommand, childDeviceCode); bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode); if (sendFlag) { conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode); content = _taskService.UpdateTaskStatusToNext(task); } } else { var taskNext = _taskService.QueryExecutingConveyorLineTask(childDeviceCode, command.ConveyorLineBarcode); if (taskNext != null) { WebResponseContent content = new WebResponseContent(); ConveyorLineTaskCommand_After taskCommand = _mapper.Map<ConveyorLineTaskCommand_After>(taskNext); taskCommand.InteractiveSignal = command.InteractiveSignal; Dt_StationManager stationManager = _stationManagerRepository.QueryFirst(x => x.stationPLC == conveyorLine.DeviceCode && x.stationChildCode == childDeviceCode); if (taskNext.PalletCode != command.ConveyorLineBarcode) { taskCommand.ConveyorLineTargetAddress = Convert.ToInt16(stationManager.stationNGChildCode); } else { 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) { needBarcode.inLineNum--; _needBarcodeRepository.UpdateData(needBarcode); } } //conveyorLine.SendCommand(taskCommand, childDeviceCode); bool sendFlag = SendCommand(taskCommand, conveyorLine, childDeviceCode); if (sendFlag) { conveyorLine.SetValue(ConveyorLineDBName_After.ResponState, Convert.ToInt16(1), childDeviceCode); taskNext.ExceptionMessage = log; content = _taskService.UpdateTaskStatusToNext(taskNext); } } } } /// <summary> /// çæµç©ºæçå®çåºåº /// </summary> /// <param name="conveyorLine">è¾é线å®ä¾å¯¹è±¡</param> /// <param name="command">读åç请æ±ä¿¡æ¯</param> /// <param name="childDeviceCode">å设å¤ç¼å·</param> /// <param name="index">线ä½å½åbool读ååç§»å°å</param> public async void EmptyTrayReturn(CommonConveyorLine_CW conveyorLine, ConveyorLineTaskCommand_After command, string childDeviceCode, int index, WIDESEAWCS_Model.Models.Platform platform) { try { TaskOutboundTypeEnum taskOutboundTypeEnum; if (platform.PlatformType.Contains("OutTray")) taskOutboundTypeEnum = TaskOutboundTypeEnum.OutTray; else taskOutboundTypeEnum = TaskOutboundTypeEnum.Outbound; await CheckAndCreateTask(taskOutboundTypeEnum, childDeviceCode, index, platform); } catch (Exception) { } } /// <summary> /// æ£æ¥ä»»å¡å¹¶å建æ°ä»»å¡ /// </summary> private async Task CheckAndCreateTask(TaskOutboundTypeEnum taskType, string childDeviceCode, int index, Platform platform) { var tasks = _taskRepository.QueryData(x => x.TaskType == (int)taskType && x.TargetAddress == childDeviceCode); if (tasks.Count < platform.Capacity) { #region è°ç¨WMSè·ååºåºä»»å¡ WMSTaskDTO taskDTO = new WMSTaskDTO(); // è·åWMSipå°å var config = _sys_ConfigService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_IPAddress); var wmsBase = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.WMSIP_BASE)?.ConfigValue; var requestTrayOutTask = config.FirstOrDefault(x => x.ConfigKey == SysConfigKeyConst.RequestTrayOutTask)?.ConfigValue; if (wmsBase == null || requestTrayOutTask == null) { throw new InvalidOperationException("WMS IP æªé ç½®"); } var wmsIpAddress = wmsBase + requestTrayOutTask; //var device = _deviceInfoRepository.QueryData(x => x.DeviceStatus == "1" && x.DeviceRemark == platform.Id.ToString()); //var deviceCode = device.Select(x => x.DeviceCode).ToList(); List<string> strings = platform.Location.Split(',').ToList(); var result = await HttpHelper.PostAsync(wmsIpAddress, new { Position = childDeviceCode, Tag = (int)taskType, AreaCdoe = platform.Stacker, AreaCdoes = strings, platform.ProductionLine }.Serialize()); //var result = await HttpHelper.PostAsync("http://localhost:5000/api/Task/RequestTrayOutTaskAsync", dynamic.ToJsonString()); WebResponseContent content = JsonConvert.DeserializeObject<WebResponseContent>(result); // æ£æ¥ç¶æå¹¶è¿å if (!content.Status) return; taskDTO = JsonConvert.DeserializeObject<WMSTaskDTO>(content.Data.ToString()); #endregion è°ç¨WMSè·ååºåºä»»å¡ CreateAndSendTask(taskDTO); } } /// <summary> /// åå»ºä»»å¡ /// </summary> public WebResponseContent CreateAndSendTask(WMSTaskDTO taskDTO) { var content = _taskService.ReceiveWMSTask(new List<WMSTaskDTO> { taskDTO }); if (content.Status) { Console.WriteLine($"{taskDTO.TaskType}å¼å«æå"); } return content; } public bool SendCommand(ConveyorLineTaskCommand_After taskCommand, CommonConveyorLine_CW conveyorLine, string childDeviceCode) { conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTargetAddress, Convert.ToInt16(taskCommand.ConveyorLineTargetAddress), childDeviceCode); Thread.Sleep(100); conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineBarcode, taskCommand.ConveyorLineBarcode, childDeviceCode); Thread.Sleep(100); conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTaskNum, taskCommand.ConveyorLineTaskNum, childDeviceCode); for (int i = 0; i < 6; i++) { ConveyorLineTaskCommand_After command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand_After>(childDeviceCode); if (command != null) { if (command.ConveyorLineBarcode == taskCommand.ConveyorLineBarcode && command.ConveyorLineTaskNum == taskCommand.ConveyorLineTaskNum && command.ConveyorLineTargetAddress == taskCommand.ConveyorLineTargetAddress) { WriteInfo(conveyorLine.DeviceName, $"æ¶é´ï¼ã{DateTime.Now}ãåå ¥ä»»å¡æååå ¥æ¬¡æ°{i}åå ¥ä»»å¡ã{JsonConvert.SerializeObject(taskCommand)}ã"); return true; } if (command.ConveyorLineTargetAddress != taskCommand.ConveyorLineTargetAddress) { conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTargetAddress, Convert.ToInt16(taskCommand.ConveyorLineTargetAddress), childDeviceCode); Thread.Sleep(100); } if (command.ConveyorLineBarcode != taskCommand.ConveyorLineBarcode) { conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineBarcode, taskCommand.ConveyorLineBarcode, childDeviceCode); Thread.Sleep(100); } if (command.ConveyorLineTaskNum != taskCommand.ConveyorLineTaskNum) { conveyorLine.SetValue(ConveyorLineDBName_After.ConveyorLineTaskNum, taskCommand.ConveyorLineTaskNum, childDeviceCode); Thread.Sleep(100); } } } WriteInfo(conveyorLine.DeviceName, $"æ¶é´ï¼ã{DateTime.Now}ãåå ¥ä»»å¡å¤±è´¥ä»»å¡å·ã{taskCommand.ConveyorLineTaskNum}ãæçå·ã{taskCommand.ConveyorLineBarcode}ãç®æ å°åã{taskCommand.ConveyorLineTargetAddress}ãå½åèç¹ã{childDeviceCode}ã"); return false; } } } #endregion