From 65b5b0ced6d04f773002908cb8c0720540f34907 Mon Sep 17 00:00:00 2001 From: wanshenmean <cathay_xy@163.com> Date: 星期四, 10 四月 2025 09:20:17 +0800 Subject: [PATCH] 1 --- 代码管理/NEWCode/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs | 109 +++++++++++++++++++++++++++++++++++------------------- 1 files changed, 71 insertions(+), 38 deletions(-) diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/NEWCode/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/NEWCode/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs" index f82ab1f..7ee7a24 100644 --- "a/\344\273\243\347\240\201\347\256\241\347\220\206/NEWCode/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs" +++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/NEWCode/WIDESEAWCS_Server/WIDESEAWCS_Tasks/ConveyorLineJob/CommonConveyorLineJob.cs" @@ -24,8 +24,10 @@ using System.Reflection; using System.Text; using System.Threading.Tasks; +using WIDESEAWCS_Common.TaskEnum; using WIDESEAWCS_Core; using WIDESEAWCS_Core.Helper; +using WIDESEAWCS_ITaskInfoRepository; using WIDESEAWCS_ITaskInfoService; using WIDESEAWCS_Model.Models; using WIDESEAWCS_QuartzJob; @@ -39,74 +41,105 @@ public class CommonConveyorLineJob : JobBase, IJob, IDisposable { private readonly ITaskService _taskService; + private readonly ITaskRepository _taskRepository; + private readonly ITaskCZRepository _taskCZRepository; private readonly ITaskExecuteDetailService _taskExecuteDetailService; private readonly IRouterService _routerService; private readonly IMapper _mapper; - public CommonConveyorLineJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IMapper mapper) + public CommonConveyorLineJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IMapper mapper, ITaskRepository taskRepository, ITaskCZRepository taskCZRepository) { _taskService = taskService; _taskExecuteDetailService = taskExecuteDetailService; _routerService = routerService; _mapper = mapper; + _taskRepository = taskRepository; + _taskCZRepository = taskCZRepository; } public Task Execute(IJobExecutionContext context) { - //Console.Out.WriteLine(DateTime.Now); try { + // 浠庝笂涓嬫枃涓幏鍙� JobParams 骞惰浆鎹负 CommonConveyorLine 绫诲瀷 CommonConveyorLine conveyorLine = (CommonConveyorLine)context.JobDetail.JobDataMap.Get("JobParams"); - if (conveyorLine != null) + if (conveyorLine == null) { - short[] values = conveyorLine.Communicator.Read<short>("DB2.0", 20); - - //bool result = conveyorLine.Communicator.Write("DB1.0", "AAABBB"); - //string testVal = conveyorLine.Communicator.Read<string>("DB1.0"); - - List<string> childDeviceCodes = _routerService.QueryAllPositions(conveyorLine.DeviceCode); - List<Task> tasks = new List<Task>(); - foreach (string childDeviceCode in childDeviceCodes) - { - //Task task = Task.Run(() => - //{ - ConveyorLineTaskCommand command = conveyorLine.ReadCustomer<ConveyorLineTaskCommand>(childDeviceCode); - if (command != null) - { - DeviceProtocolDetailDTO? deviceProtocolDetail = conveyorLine.DeviceProtocolDetailDTOs.FirstOrDefault(x => x.ProtocalDetailValue == command.InteractiveSignal.ToString() && x.DeviceProParamName == nameof(ConveyorLineTaskCommand.InteractiveSignal)); - if (deviceProtocolDetail != null) - { - MethodInfo? method = GetType().GetMethod(deviceProtocolDetail.ProtocolDetailType); - if (method != null) - { - method.Invoke(this, new object[] { conveyorLine, command, childDeviceCode }); - } - else - { - //todo 鏈壘鍒版柟娉曟椂 - } - } - } - //}); - //tasks.Add(task); - } - - Task.WaitAll(tasks.ToArray()); + throw new Exception("JobParams 涓嶅寘鍚� CommonConveyorLine 绫诲瀷鍙傛暟"); } + // 瀹氫箟绾夸綋瀹炵洏鍏ュ簱璇锋眰鐨勫湴鍧�鍜屼换鍔$被鍨� + var requests = new Dictionary<string, string> + { + { "DB1002.293.0", "ZJXL-WLX002" }, + { "DB1002.1493.0", "FJXL-WLX002" } + }; + + foreach (var request in requests) + { + var isDownRequest = conveyorLine.Communicator.Read<bool>(request.Key); + if (!isDownRequest) + { + continue; + } + + string fromAdd = request.Value; + string taskType = request.Value.Contains("ZJXL") ? "姝f瀬" : "璐熸瀬"; + + // 鏌ヨ鏄惁瀛樺湪宸茬敓鎴愮殑鏂颁换鍔� + var task = _taskRepository.QueryFirst(x => x.SourceAddress == fromAdd && x.TaskState == (int)TaskInStatusEnum.InNew); + if (task != null) + { + ConsoleHelper.WriteInfoLine($"{nameof(CommonConveyorLineJob)}: {taskType}涓嬬嚎璇锋眰鍏ュ簱,浠诲姟宸茬敓鎴愬瓨鍦紝绋嶅悗閲嶈瘯......"); + continue; + } + + // 鏌ヨ浠诲姟绫诲瀷瀵瑰簲鐨刢zTask + DtCZTask czTask = _taskCZRepository.QueryFirst(x => x.TaskType == taskType); + if (czTask == null) + { + ConsoleHelper.WriteInfoLine($"{nameof(CommonConveyorLineJob)}: {taskType}涓嬬嚎璇锋眰鍏ュ簱,{taskType}浠诲姟涓嶅瓨鍦紝绋嶅悗閲嶈瘯......"); + continue; + } + + // 鍒涘缓鏂扮殑浠诲姟骞舵坊鍔犲埌浠诲姟浠撳簱 + task = new Dt_Task() + { + TaskNum = _taskService.GetTaskNum(), + CreateDate = DateTime.Now, + Creater = "system", + CurrentAddress = fromAdd, + SourceAddress = fromAdd, + TaskState = (int)TaskInStatusEnum.InNew, + TaskType = (int)TaskInboundTypeEnum.Inbound, + Grade = 1, + PalletCode = czTask.TaskProductCode, + TargetAddress = czTask.TaskEndAddress, + Roadway = $"{taskType}AGV", + WMSId = czTask.Id, + Remark = czTask.TaskOrderNo + }; + _taskRepository.AddData(task); + ConsoleHelper.WriteInfoLine($"{nameof(CommonConveyorLineJob)}: {taskType}涓嬬嚎璇锋眰鍏ュ簱,浠诲姟宸茬敓鎴愶紝绛夊緟鎵ц......"); + } } catch (Exception ex) { - //Console.Out.WriteLine(nameof(CommonConveyorLineJob) + ":" + ex.ToString()); + // 璁板綍寮傚父淇℃伅 + // Console.Out.WriteLine(nameof(CommonConveyorLineJob) + ":" + ex.ToString()); + ConsoleHelper.WriteErrorLine($"{nameof(CommonConveyorLineJob)}: 鍙戠敓寮傚父 - {ex.Message}"); } finally { + // 鍐欒皟璇曚俊鎭� WriteDebug("CommonConveyorLineJob", "test"); - //Console.Out.WriteLine(DateTime.Now); + // Console.Out.WriteLine(DateTime.Now); } + return Task.CompletedTask; } + /// <summary> /// 杈撻�佺嚎璇锋眰鍏ュ簱 /// </summary> -- Gitblit v1.9.3