duyongjia
2025-02-25 a205d879fb21a8b60348bf465a970c07b0784945
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
using Autofac.Core;
using HslCommunication;
using HslCommunication.Core;
using HslCommunication.WebSocket;
using Microsoft.Extensions.Hosting;
using Microsoft.VisualBasic.FileIO;
using Newtonsoft.Json;
using Quartz;
using SixLabors.ImageSharp.PixelFormats;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Communicator;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.DeviceBase;
using WIDESEAWCS_QuartzJob.StackerCrane.Enum;
using WIDESEAWCS_Tasks.OHT;
 
namespace WIDESEAWCS_Tasks
{
    [DisallowConcurrentExecution]
    public class GZJJob : JobBase, IJob
    {
        private readonly ITaskService _taskService;
        WebSocketServer _webSocketServer;
        public GZJJob(ITaskService taskService, WebSocketServer webSocketServer)
        {
            _taskService = taskService;//注入
            _webSocketServer = webSocketServer;
        }
 
        public Task Execute(IJobExecutionContext context)
        {
           
            bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value);
            if (flag && value != null)
            {
                OtherDevice device = (OtherDevice)value;
                try
                {
                    //Example
                    //device.GetValue  读取
                    //device.SetValue  写入
                    //_taskService.Repository; //仓储层,进行数据库访问
                    OHTReadData oHTReadData = new OHTReadData();
                    //todo:读取设备数据,
 
 
                    //todo:设备状态数据发送给前端
                  
 
                    
                    //WriteInfo(device.DeviceName, "infoLog");
 
                    //WriteDebug(device.DeviceName, "debugLog");
                }
                catch (Exception ex)
                {
                    WriteError(device.DeviceName, "错误", ex);
                }
            }
 
 
            return Task.CompletedTask;
        }
 
 
        /// <summary>
        /// 任务实体转换成命令Model
        /// </summary>
        /// <param name="task">任务实体</param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        public OHTTaskCommand? ConvertToOHTTaskCommand([NotNull] Dt_Task task)
        {
            OHTTaskCommand oHtTaskCommand = new OHTTaskCommand();
 
            oHtTaskCommand.W_Task_Type = 1;
            oHtTaskCommand.W_Load_Layer = 0;
            oHtTaskCommand.W_Pick_Line = 1;
           
            string[] SourceCodes = task.SourceAddress.Split("-");
            if (SourceCodes.Length == 3)
            {
                oHtTaskCommand.W_Pick_Line = Convert.ToInt16(SourceCodes[1]);
                oHtTaskCommand.W_Put_Column = Convert.ToInt16(SourceCodes[2]);
                oHtTaskCommand.W_Put_Layer = Convert.ToInt16(SourceCodes[3]);
            }
            else
            {
                //数据配置错误
                _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"任务源地址配置错误!");
                return null;
            }
            string[] targetCodes = task.TargetAddress.Split("-");
            if (targetCodes.Length == 3)
            {
                oHtTaskCommand.W_Put_Line = Convert.ToInt16(targetCodes[1]);
                oHtTaskCommand.W_Put_Column = Convert.ToInt16(targetCodes[2]);
                oHtTaskCommand.W_Put_Layer = Convert.ToInt16(targetCodes[3]);
            }
            else
            {
                //数据配置错误
                _taskService.UpdateTaskExceptionMessage(task.TaskNum, $"任务目标地址配置错误");
                return null;
            }
            return oHtTaskCommand;
        }
 
 
        /// <summary>
        /// 获取任务
        /// </summary>
        /// <returns></returns>
        private Dt_Task? GetTask()
        {
            Dt_Task task;
            task = _taskService.QueryStackerCraneTask("R01");
            return task;
        }
 
 
    }
 
 
}