| | |
| | | _locationInfoService = locationInfoService; |
| | | _taskService=taskService; |
| | | } |
| | | |
| | | private static readonly object _taskProcessLock = new object(); |
| | | private const int TASK_PROCESS_TIMEOUT = 3000; // 3ç§è¶
æ¶ |
| | | |
| | | public Task StartAsync(CancellationToken cancellationToken) |
| | | { |
| | |
| | | } |
| | | private void DoWorkWheel(object state) |
| | | { |
| | | // å®ä¹ç¶æå¸¸éï¼é¿å
éæ³æ°å |
| | | const int PLC_IN_FINISH = (int)InTaskStatusEnum.PLC_InFinish; |
| | | const int OUT_NEW = (int)OutTaskStatusEnum.OutNew; |
| | | const int SC_OUT_FINISH = (int)OutTaskStatusEnum.SC_OutFinish; |
| | | const int SC_IN_EXECUTING = (int)InTaskStatusEnum.SC_IntExecuting; |
| | | const int SC_OUT_EXECUTING = (int)OutTaskStatusEnum.SC_OutExecuting; |
| | | const int RELOCATION_EXECUTING = (int)RelocationTaskStatusEnum.RelocationExecuting; |
| | | const int PLC_OUT_EXECUTING = (int)OutTaskStatusEnum.PLC_OutExecuting; |
| | | if (!Monitor.TryEnter(_taskProcessLock, TASK_PROCESS_TIMEOUT)) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | // è·åå½å任塿°æ® |
| | | List<Dt_Task> allTasks = _taskService.Repository.QueryData(); |
| | | try |
| | | { |
| | | // å®ä¹ç¶æå¸¸éï¼é¿å
éæ³æ°å |
| | | const int PLC_IN_FINISH = (int)InTaskStatusEnum.PLC_InFinish; |
| | | const int OUT_NEW = (int)OutTaskStatusEnum.OutNew; |
| | | const int SC_OUT_FINISH = (int)OutTaskStatusEnum.SC_OutFinish; |
| | | const int SC_IN_EXECUTING = (int)InTaskStatusEnum.SC_IntExecuting; |
| | | const int SC_OUT_EXECUTING = (int)OutTaskStatusEnum.SC_OutExecuting; |
| | | const int RELOCATION_EXECUTING = (int)RelocationTaskStatusEnum.RelocationExecuting; |
| | | const int PLC_OUT_EXECUTING = (int)OutTaskStatusEnum.PLC_OutExecuting; |
| | | |
| | | // è·åå··éè¶
è¿3个任å¡ç路段 |
| | | HashSet<string> excludedRoadways = allTasks |
| | | .Where(x => x.NumberSsuances > 3) |
| | | .Select(x => x.Roadway) |
| | | .Distinct() |
| | | .ToHashSet(); |
| | | // è·åå½å任塿°æ® |
| | | List<Dt_Task> allTasks = _taskService.Repository.QueryData(); |
| | | |
| | | // è¿æ»¤éè¦å¤ççä»»å¡ |
| | | List<Dt_Task> tasksToProcess = allTasks |
| | | .Where(x => |
| | | (x.TaskStatus == PLC_IN_FINISH || |
| | | x.TaskStatus == OUT_NEW || |
| | | x.TaskStatus == SC_OUT_FINISH) && |
| | | !excludedRoadways.Contains(x.Roadway)) |
| | | .ToList(); |
| | | // è·åå··éè¶
è¿3个任å¡ç路段 |
| | | HashSet<string> excludedRoadways = allTasks |
| | | .Where(x => x.NumberSsuances > 3) |
| | | .Select(x => x.Roadway) |
| | | .Distinct() |
| | | .ToHashSet(); |
| | | |
| | | // æç¶æåç»å¤çï¼åå°é夿¥è¯¢ |
| | | ProcessInAndNewTasks(tasksToProcess, allTasks, excludedRoadways); //ä¸åå åæº |
| | | ProcessOutFinishTasks(tasksToProcess, allTasks); //ä¸åè¾éçº¿ä»»å¡ |
| | | // è¿æ»¤éè¦å¤ççä»»å¡ |
| | | List<Dt_Task> tasksToProcess = allTasks |
| | | .Where(x => |
| | | (x.TaskStatus == PLC_IN_FINISH || |
| | | x.TaskStatus == OUT_NEW || |
| | | x.TaskStatus == SC_OUT_FINISH) && |
| | | !excludedRoadways.Contains(x.Roadway)) |
| | | .ToList(); |
| | | |
| | | // æç¶æåç»å¤çï¼åå°é夿¥è¯¢ |
| | | ProcessInAndNewTasks(tasksToProcess, allTasks, excludedRoadways); //ä¸åå åæº |
| | | ProcessOutFinishTasks(tasksToProcess, allTasks); //ä¸åè¾éçº¿ä»»å¡ |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Console.WriteLine($"ä»»å¡å¤çå¼å¸¸ï¼{ex.Message}"); |
| | | } |
| | | finally |
| | | { |
| | | // å¿
须鿾éï¼å¦åä¼å¯¼è´æ»é |
| | | Monitor.Exit(_taskProcessLock); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | private void ProcessInAndNewTasks(List<Dt_Task> tasksToProcess, List<Dt_Task> allTasks, HashSet<string> excludedRoadways) |
| | |
| | | x.Roadway == task.Roadway && |
| | | (x.TaskStatus == SC_IN_EXECUTING || |
| | | x.TaskStatus == SC_OUT_EXECUTING || |
| | | x.TaskStatus == RELOCATION_EXECUTING)); |
| | | x.TaskStatus == RELOCATION_EXECUTING || x.TaskStatus == RELOCCATION_NEW)); |
| | | |
| | | if (hasExecutingTask) |
| | | continue; |
| | | |
| | | if(task.TaskStatus == OUT_NEW) |
| | | { |
| | | bool SCNewTasks = allTasks.Any(x => x.TaskStatus != OUT_NEW && x.TargetAddress == task.TargetAddress); |
| | | if (SCNewTasks) |
| | | continue; |
| | | } |
| | | |
| | | //夿æ¯å¦éè¦ç§»åº |
| | | WebResponseContent webResponse=JudgmentIsRelocations(task); |
| | |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | string Locationcodeadd = dt_Task.TaskType == (int)TaskTypeEnum.Inbound ? dt_Task.NextAddress : dt_Task.CurrentAddress; |
| | | string Locationcodeadd = dt_Task.TaskType == (int)TaskTypeEnum.Inbound ? dt_Task.NextAddress: dt_Task.CurrentAddress ; |
| | | |
| | | Dt_LocationInfo dt_Location = _locationInfoService.Repository.QueryData(x => x.LocationCode == Locationcodeadd).FirstOrDefault(); |
| | | if (dt_Location.Depth == 1 || dt_Location.RoadwayNo == "5") return content.OK(); |
| | |
| | | _taskService.AddData(task); |
| | | _locationInfoService.UpdateData(dt_Locations); |
| | | _stockInfoService.UpdateData(dt_StockInfo); |
| | | //_stockInfoService.Repository.AddData(dt_StockInfo); |
| | | _unitOfWorkManage.CommitTran(); |
| | | |
| | | //è¿è¡ä¸åç»å åæºä»»å¡ |