| | |
| | | using Microsoft.AspNetCore.Components.Routing; |
| | | using Autofac.Core; |
| | | using Microsoft.AspNetCore.Components.Routing; |
| | | using Newtonsoft.Json; |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime; |
| | | using Org.BouncyCastle.Asn1.Ocsp; |
| | | using Org.BouncyCastle.Tls; |
| | | using Quartz; |
| | | using System; |
| | |
| | | using System.Drawing; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Channels; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Common; |
| | | using WIDESEAWCS_Common.TaskEnum; |
| | |
| | | using WIDESEAWCS_QuartzJob.Models; |
| | | using WIDESEAWCS_QuartzJob.Repository; |
| | | using WIDESEAWCS_QuartzJob.Service; |
| | | using WIDESEAWCS_TaskInfoRepository; |
| | | using WIDESEAWCS_Tasks.ConveyorLineJob; |
| | | using ICacheService = WIDESEAWCS_Core.Caches.ICacheService; |
| | | |
| | |
| | | private readonly IRouterService _routerService; |
| | | private readonly IRouterExtension _routerExtension; |
| | | private readonly List<Dt_WarehouseDevice> warehouseDevices; |
| | | private readonly IPackaxisTaskRepository _packaxisTaskRepository; |
| | | private readonly IPackaxisTaskService _packaxisTaskService; |
| | | private static object lockObj = 0;// |
| | | private static List<string> strings = new List<string>(); |
| | | |
| | | public ConveyorLineJob_CPH(ICacheService cacheService, ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository, IRouterService routerService, IRouterExtension routerExtension) |
| | | public ConveyorLineJob_CPH(ICacheService cacheService, ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, ITaskRepository taskRepository, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository, IRouterService routerService, IRouterExtension routerExtension, IPackaxisTaskRepository packaxisTaskRepository, IPackaxisTaskService packaxisTaskService) |
| | | { |
| | | _cacheService = cacheService; |
| | | _taskService = taskService; |
| | |
| | | _routerRepository = routerRepository; |
| | | _routerService = routerService; |
| | | _routerExtension = routerExtension; |
| | | //string boxCodes = AppSettings.Get("BoxCodes"); |
| | | //if (!string.IsNullOrEmpty(boxCodes) && strings.Count<=0) |
| | | //{ |
| | | // foreach (string s in boxCodes.Split(",")) |
| | | // { |
| | | // strings.Add(s); |
| | | // } |
| | | //} |
| | | string? warehouseDevicesStr = _cacheService.Get<string>(nameof(Dt_WarehouseDevice)); |
| | | if (!string.IsNullOrEmpty(warehouseDevicesStr)) |
| | | { |
| | |
| | | { |
| | | warehouseDevices = new List<Dt_WarehouseDevice>(); |
| | | } |
| | | _packaxisTaskRepository = packaxisTaskRepository; |
| | | _packaxisTaskService = packaxisTaskService; |
| | | } |
| | | |
| | | public Task Execute(IJobExecutionContext context) |
| | |
| | | if (lockObj.ToString()=="0") |
| | | { |
| | | lockObj = 1; |
| | | Task task = Task.Run(() => |
| | | bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value); |
| | | if (flag && value != null) |
| | | { |
| | | try |
| | | { |
| | | while (true) |
| | | //è·åå½åè®¾å¤ |
| | | OtherDevice device = (OtherDevice)value; |
| | | List<Dt_StationManger> stationMangers = _stationMangerRepository.QueryData(x => x.StationDeviceCode == device.DeviceCode); |
| | | Task.Run(() => |
| | | { |
| | | bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value); |
| | | if (flag && value != null) |
| | | { |
| | | //è·åå½åè®¾å¤ |
| | | OtherDevice device = (OtherDevice)value; |
| | | List<Dt_StationManger> stationMangers = _stationMangerRepository.QueryData(x => x.StationDeviceCode == device.DeviceCode); |
| | | Dt_StationManger? RequestIn = stationMangers.FirstOrDefault(x => x.StationType == StationTypeEnum.StationType_OnlyInbound.ObjToInt()); |
| | | if (RequestIn != null) |
| | | { |
| | | DeviceProDTO? deviceProRead = device.DeviceProDTOs.Where(x => x.DeviceChildCode == RequestIn.StationCode && x.DeviceProParamType == nameof(R_CLineCPHDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); |
| | | DeviceProDTO? deviceProWrite = device.DeviceProDTOs.Where(x => x.DeviceChildCode == RequestIn.StationCode && x.DeviceProParamType == nameof(W_CLineCPHDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); |
| | | if (deviceProRead != null && deviceProWrite != null) |
| | | { |
| | | R_CLineCPHInfo conveyorLineInfoRead = device.Communicator.ReadCustomer<R_CLineCPHInfo>(deviceProRead.DeviceProAddress); |
| | | //ç åç¯çº¿è¯·æ±ä»»å¡ |
| | | if (conveyorLineInfoRead != null && (conveyorLineInfoRead.R_State == 2 || conveyorLineInfoRead.R_State == 3) && conveyorLineInfoRead.R_TaskNo <= 0 && !string.IsNullOrEmpty(conveyorLineInfoRead.R_BoxCode) && conveyorLineInfoRead.R_Request == 1) |
| | | { |
| | | //WebResponseContent content = _taskService.MESBoxCodeNotice(conveyorLineInfoRead.R_BoxCode); |
| | | ////åWMS请æ±ä»»å¡ |
| | | //if (true) |
| | | //{ |
| | | bool shouldRestart = true; |
| | | |
| | | //} |
| | | //string[] strings = conveyorLineInfoRead.R_BoxCode.Split("-"); |
| | | //if (strings.Length==2) |
| | | //{ |
| | | #region todo:临æ¶é»è¾ |
| | | ////åå
¥æ§è¡æ°æ® |
| | | //if (strings.FirstOrDefault(x=>x == conveyorLineInfoRead.R_BoxCode)!=null) |
| | | //{ |
| | | device.SetValue(W_CLineCPHDB.W_TaskNo, 100 + 5, RequestIn.StationCode); |
| | | device.SetValue(W_CLineCPHDB.W_Channel, 14, RequestIn.StationCode); |
| | | device.SetValue(W_CLineCPHDB.W_Long, 465, RequestIn.StationCode); |
| | | device.SetValue(W_CLineCPHDB.W_Wide, 375, RequestIn.StationCode); |
| | | device.SetValue(W_CLineCPHDB.W_High, 690, RequestIn.StationCode); |
| | | device.SetValue(W_CLineCPHDB.W_TMID, conveyorLineInfoRead.R_BoxCode, RequestIn.StationCode); |
| | | device.SetValue(W_CLineCPHDB.W_Request, 1, RequestIn.StationCode); |
| | | // WebResponseContent content = _taskService.MESBoxCodeNotice(conveyorLineInfoRead.R_BoxCode); |
| | | // if (content.Message.Contains("true")) |
| | | // { |
| | | // strings.Remove(conveyorLineInfoRead.R_BoxCode); |
| | | // WriteInfo(RequestIn.StationName, content.Message); |
| | | // } |
| | | // else |
| | | // { |
| | | // WriteError(RequestIn.StationName, content.Message); |
| | | // } |
| | | //} |
| | | //else |
| | | //{ |
| | | // WriteError(RequestIn.StationName, $"æªæ¾å°æ¡ç {conveyorLineInfoRead.R_BoxCode}æ°æ®"); |
| | | //} |
| | | #endregion |
| | | //} |
| | | //else |
| | | //{ |
| | | // WriteError(RequestIn.StationName, $"æ°æ®æªåé误ï¼{strings}"); |
| | | //} |
| | | } |
| | | } |
| | | else |
| | | { |
| | | WriteError(RequestIn.StationName, $"æªæ¾å°è®¾å¤åç¼å·{RequestIn.StationCode}çå议信æ¯"); |
| | | } |
| | | } |
| | | foreach (var item in stationMangers.Where(x=>x.StationType==StationTypeEnum.StationType_OnlyOutbound.ObjToInt())) |
| | | while (shouldRestart) |
| | | { |
| | | try |
| | | { |
| | | DeviceProDTO? deviceProRead = device.DeviceProDTOs.Where(x => x.DeviceChildCode == item.StationCode && x.DeviceProParamType == nameof(R_CLineCPHDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); |
| | | if (deviceProRead != null) |
| | | shouldRestart = false; |
| | | Dt_StationManger? RequestIn = stationMangers.FirstOrDefault(x => x.StationDeviceCode == device.DeviceCode && x.StationType == StationTypeEnum.StationType_OnlyInbound.ObjToInt()); |
| | | WriteInfo($"çº¿ç¨ {Thread.CurrentThread.ManagedThreadId}ååå£","å¼å§æ§è¡"); |
| | | while (true) |
| | | { |
| | | R_CLineCPHInfo conveyorLineInfoRead = device.Communicator.ReadCustomer<R_CLineCPHInfo>(deviceProRead.DeviceProAddress); |
| | | //è·åç åå£ä»»å¡æ´æ°ä»»å¡ç¶æ |
| | | if (conveyorLineInfoRead != null && (conveyorLineInfoRead.R_State == 2 || conveyorLineInfoRead.R_State == 3) && conveyorLineInfoRead.R_TaskNo > 0) |
| | | //WriteInfo($"ååå£è¿è¡æ¶é´" , $"å¼å§æ¶é´:" + DateTime.Now.ToString("HH:mm:ss.fff")); |
| | | if (RequestIn != null) |
| | | { |
| | | Dt_Task task = _taskRepository.QueryFirst(x => x.TaskNum == conveyorLineInfoRead.R_TaskNo && x.NextAddress == item.StationCode && x.TaskState == TaskStatusEnum.Line_Executing.ObjToInt()); |
| | | if (task != null) |
| | | DeviceProDTO? deviceProRead = device.DeviceProDTOs.Where(x => x.DeviceChildCode == RequestIn.StationCode && x.DeviceProParamType == nameof(R_CLineCPHDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); |
| | | DeviceProDTO? deviceProWrite = device.DeviceProDTOs.Where(x => x.DeviceChildCode == RequestIn.StationCode && x.DeviceProParamType == nameof(W_CLineCPHDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); |
| | | if (deviceProRead != null && deviceProWrite != null) |
| | | { |
| | | task.CurrentAddress = item.StationCode; |
| | | task.NextAddress = task.TargetAddress; |
| | | task.DeviceCode = item.StackerCraneCode; |
| | | _taskService.UpdateTask(task, TaskStatusEnum.MD_Executing); |
| | | R_CLineCPHInfo conveyorLineInfoRead = device.Communicator.ReadCustomer<R_CLineCPHInfo>(deviceProRead.DeviceProAddress); |
| | | //ç åç¯çº¿è¯·æ±ä»»å¡ |
| | | if (conveyorLineInfoRead != null && (conveyorLineInfoRead.R_State == 2 || conveyorLineInfoRead.R_State == 3) && conveyorLineInfoRead.R_TaskNo <= 0 && !string.IsNullOrEmpty(conveyorLineInfoRead.R_BoxCode) && conveyorLineInfoRead.R_Request == 1) |
| | | { |
| | | //WriteInfo($"ååå£è¿è¡æ¶é´", $"{conveyorLineInfoRead.R_BoxCode}请æ±" + DateTime.Now.ToString("HH:mm:ss.fff")); |
| | | //夿æ¯å¦ä»»å¡å·²ç»åå¨ |
| | | Dt_PackaxisTask packaxisTask = _packaxisTaskRepository.Db.Queryable<Dt_PackaxisTask>().Where(x => x.BarCode == conveyorLineInfoRead.R_BoxCode.Trim() && x.TaskState == TaskStatusEnum.Line_Executing.ObjToInt()).First(); |
| | | if (packaxisTask != null) |
| | | { |
| | | //åå
¥æ§è¡æ°æ® |
| | | device.SetValue(W_CLineCPHDB.W_TaskNo, packaxisTask.PackTaskNum, RequestIn.StationCode); |
| | | device.SetValue(W_CLineCPHDB.W_Channel, packaxisTask.NextAddress, RequestIn.StationCode); |
| | | device.SetValue(W_CLineCPHDB.W_Long, packaxisTask.PackLength, RequestIn.StationCode); |
| | | device.SetValue(W_CLineCPHDB.W_Wide, packaxisTask.PackWidth, RequestIn.StationCode); |
| | | device.SetValue(W_CLineCPHDB.W_High, packaxisTask.PackHeight, RequestIn.StationCode); |
| | | device.SetValue(W_CLineCPHDB.W_TMID, conveyorLineInfoRead.R_BoxCode.Trim(), RequestIn.StationCode); |
| | | device.SetValue(W_CLineCPHDB.W_Request, 1, RequestIn.StationCode); |
| | | //WriteInfo($"ååå£è¿è¡æ¶é´", $"{conveyorLineInfoRead.R_BoxCode}请æ±å®æ" + DateTime.Now.ToString("HH:mm:ss.fff")); |
| | | } |
| | | else |
| | | { |
| | | #region |
| | | WebResponseContent webResponse = _packaxisTaskService.ReqPackTask(conveyorLineInfoRead.R_BoxCode.Trim(), RequestIn.StationDeviceCode); |
| | | if (webResponse.Status) |
| | | { |
| | | Dt_PackaxisTask _PackaxisTask = webResponse.Data as Dt_PackaxisTask; |
| | | //åå
¥æ§è¡æ°æ® |
| | | device.SetValue(W_CLineCPHDB.W_TaskNo, _PackaxisTask.PackTaskNum, RequestIn.StationCode); |
| | | device.SetValue(W_CLineCPHDB.W_Channel, _PackaxisTask.NextAddress.ObjToInt(), RequestIn.StationCode); |
| | | device.SetValue(W_CLineCPHDB.W_Long, _PackaxisTask.PackLength, RequestIn.StationCode); |
| | | device.SetValue(W_CLineCPHDB.W_Wide, _PackaxisTask.PackWidth, RequestIn.StationCode); |
| | | device.SetValue(W_CLineCPHDB.W_High, _PackaxisTask.PackHeight, RequestIn.StationCode); |
| | | device.SetValue(W_CLineCPHDB.W_TMID, conveyorLineInfoRead.R_BoxCode.Trim(), RequestIn.StationCode); |
| | | device.SetValue(W_CLineCPHDB.W_Request, 1, RequestIn.StationCode); |
| | | //WriteInfo($"ååå£è¿è¡æ¶é´", $"{conveyorLineInfoRead.R_BoxCode}请æ±å®æ" + DateTime.Now.ToString("HH:mm:ss.fff")); |
| | | WebResponseContent content = _taskService.MESBoxCodeNotice(conveyorLineInfoRead.R_BoxCode.Trim()); |
| | | if (content.Status) |
| | | { |
| | | WriteInfo(RequestIn.StationName, content.Message); |
| | | } |
| | | else |
| | | { |
| | | WriteError(RequestIn.StationName, content.Message); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | WriteError(RequestIn.StationName, webResponse.Message); |
| | | } |
| | | #endregion |
| | | } |
| | | Thread.Sleep(200); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | WriteError(RequestIn.StationName, $"æªæ¾å°è®¾å¤åç¼å·{RequestIn.StationCode}çå议信æ¯"); |
| | | } |
| | | } |
| | | //WriteInfo($"ååå£è¿è¡æ¶é´", $"ç»ææ¶é´:" + DateTime.Now.ToString("HH:mm:ss.fff")); |
| | | } |
| | | } |
| | | Thread.Sleep(100); |
| | | catch (Exception ex) |
| | | { |
| | | WriteInfo($"çº¿ç¨ {Thread.CurrentThread.ManagedThreadId}ååå£", $"å¼å¸¸:{ex.Message}"); |
| | | Thread.Sleep(3000); |
| | | shouldRestart = true; |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | Task.Run(() => |
| | | { |
| | | bool shouldRestart = true; |
| | | |
| | | while (shouldRestart) |
| | | { |
| | | try |
| | | { |
| | | shouldRestart = false; |
| | | //è·åææç åå£ |
| | | List<Dt_StationManger> stationMangersMD = stationMangers.Where(x => x.StationDeviceCode == device.DeviceCode && x.StationType == StationTypeEnum.StationType_OnlyOutbound.ObjToInt()).ToList(); |
| | | WriteInfo($"çº¿ç¨ {Thread.CurrentThread.ManagedThreadId}ç åå£", "å¼å§æ§è¡"); |
| | | while (true) |
| | | { |
| | | if (stationMangersMD.Count > 0) |
| | | { |
| | | foreach (var item in stationMangersMD) |
| | | { |
| | | DeviceProDTO? deviceProRead = device.DeviceProDTOs.Where(x => x.DeviceChildCode == item.StationCode && x.DeviceProParamType == nameof(R_CLineCPHDB)).OrderBy(x => x.DeviceProOffset).FirstOrDefault(); |
| | | if (deviceProRead != null) |
| | | { |
| | | R_CLineCPHChannelInfo conveyorLineInfoRead = device.Communicator.ReadCustomer<R_CLineCPHChannelInfo>(deviceProRead.DeviceProAddress); |
| | | //è·åç åå£ä»»å¡æ´æ°ä»»å¡ç¶æ |
| | | if (conveyorLineInfoRead != null && conveyorLineInfoRead.R_State == 5 && conveyorLineInfoRead.R_TaskNo > 0) |
| | | { |
| | | Dt_PackaxisTask packaxisTask = _packaxisTaskRepository.QueryFirst(x => x.PackTaskNum == conveyorLineInfoRead.R_TaskNo && x.NextAddress == item.StationCode && x.TaskState == TaskStatusEnum.Line_Executing.ObjToInt() && x.DeviceCode == item.StationDeviceCode); |
| | | if (packaxisTask != null) |
| | | { |
| | | Dt_PackaxisTask packaxisTaskOld = _packaxisTaskRepository.QueryFirst(x => x.TaskState == TaskStatusEnum.MD_Executing.ObjToInt() && x.DeviceCode == item.StackerCraneCode); |
| | | if (packaxisTaskOld != null) |
| | | { |
| | | WriteError(item.StationName, $"ç å{item.StackerCraneCode}æ£æ§è¡ä»»å¡{packaxisTaskOld.PackTaskNum},æ æ³ç»§ç»ä¸å"); |
| | | } |
| | | else |
| | | { |
| | | packaxisTask.CurrentAddress = item.StationCode; |
| | | packaxisTask.NextAddress = packaxisTask.TargetAddress; |
| | | packaxisTask.DeviceCode = item.StackerCraneCode; |
| | | packaxisTask.TaskState = TaskStatusEnum.MD_Executing.ObjToInt(); |
| | | _packaxisTaskRepository.UpdateData(packaxisTask); |
| | | device.SetValue(W_CLineCPHDB.W_Request, 1, item.StationCode); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | WriteError(item.StationName, $"æªæ¾å°ä»»å¡{conveyorLineInfoRead.R_TaskNo}ä¿¡æ¯"); |
| | | } |
| | | Thread.Sleep(2000); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | WriteError(nameof(ConveyorLineJob_CPH), $"é误信æ¯ï¼æªæ¾å°ç åå£ä¿¡æ¯"); |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | WriteInfo($"çº¿ç¨ {Thread.CurrentThread.ManagedThreadId}ç åå£", $"å¼å¸¸:{ex.Message}"); |
| | | Thread.Sleep(3000); |
| | | shouldRestart = true; |
| | | } |
| | | } |
| | | }); |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | |
| | | lockObj = 0; |
| | | WriteError(nameof(ConveyorLineJob_CPH), $"é误信æ¯ï¼{ex.Message}"); |
| | | } |
| | | |
| | | }); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | return Task.CompletedTask; |
| | | } |
| | | } |