yanjinhui
2026-03-31 0128fce75a5e7cc9afc4bd89ce1966eb2231b69f
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
using Autofac.Core;
using HslCommunication;
using HslCommunication.Core;
using Microsoft.VisualBasic.FileIO;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Information;
using Quartz;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Common;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Communicator;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_IBasicInfoService;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.DeviceBase;
using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_QuartzJob.StackerCrane.Enum;
using WIDESEAWCS_TaskInfoService;
 
namespace WIDESEAWCS_Tasks
{
    [DisallowConcurrentExecution]
    public class TSJJob : JobBase, IJob
    {
        private readonly ITaskService _taskService;
        private readonly IStationMangerService _stationMangerService;
        public TSJJob(ITaskService taskService, IStationMangerService stationMangerService)
        {
            _taskService = taskService;//注入
            _stationMangerService = stationMangerService;
        }
 
        public Task Execute(IJobExecutionContext context)
        {
            bool flag = context.JobDetail.JobDataMap.TryGetValue("JobParams", out object? value);
            if (flag && value != null)
            {
                OtherDevice device = (OtherDevice)value;
                //Example
                //device.GetValue  读取
                //device.SetValue  写入
                // _taskService.Repository 仓储层,进行数据库访问
                try
                {
                    List<Dt_Task> Uptasks = new List<Dt_Task>();
                    //查询所有任务类型为3,4楼的入库任务类型且任务状态为AGV_WaitToExecute的任务 
                    var taskList = _taskService.Repository.QueryData(x => x.TaskState == TaskStatusEnum.AGV_WaitToExecute.ObjToInt());
                    //任务的目标地址对于站台号;
                    foreach (var task in taskList)
                    {
                        //先检查设备状态
                        if (device.GetValue<HoistEnum, short>(HoistEnum.EquipmentStatus, "TSJ") == 2)
                        {
                            if (task.ExceptionMessage == "提升机设备故障")
                            {
                                continue;
                            }
                            task.ExceptionMessage = "提升机设备故障";
                            Uptasks.Add(task);
                            continue;
                            //throw new Exception("设备故障");
                        }
                        if (task.TaskType == TaskTypeEnum.RK3F.ObjToInt() || task.TaskType == TaskTypeEnum.CHUKU1.ObjToInt() || task.TaskType == TaskTypeEnum.F04.ObjToInt())
                        {
                            if (task.TaskType == TaskTypeEnum.RK3F.ObjToInt())
                            {
                                //判断3楼入库箱号有无
                                if (device.GetValue<HoistEnum, short>(HoistEnum.OutboundInplace, task.TargetAddress) != 2)
                                {
                                    if (task.ExceptionMessage == "3楼入库箱号有货,请先处理")
                                    {
                                        continue;
                                    }
                                    task.ExceptionMessage = "3楼入库箱号有货,请先处理";
                                    Uptasks.Add(task);
                                    continue;
                                }
                            }
                            else
                            {
                                if (device.GetValue<HoistEnum, short>(HoistEnum.ReturnbinAvailable, task.TargetAddress) != 2)
                                {
                                    if (task.ExceptionMessage != "4F提升机入口有货")
                                    {
                                        task.ExceptionMessage = "4F提升机入口有货";
                                        Uptasks.Add(task);
                                    }
                                    continue;
                                }
                            }
 
 
                            //然后调用输送线接口,通知输送线有料箱需要入库,任务举行执行
                            var result = _taskService.Hikvisiontaskscontinue(task.WMSTaskNum);
                            if (result.Status == false)
                            {
                                if (task.ExceptionMessage != result.Message)
                                {
                                    task.ExceptionMessage = result.Message;
                                    Uptasks.Add(task);
                                }
                                continue;
                            }
                            task.TaskState = (int)TaskStatusEnum.AGV_ToExecute;
                            task.ExceptionMessage = "";
                            Uptasks.Add(task);
 
                            //这里任务变成了CheckPalletCodeing
 
                        }
                        else if (task.TaskType == TaskTypeEnum.CK3F.ObjToInt() || task.TaskType == TaskTypeEnum.Q1TSJ4.ObjToInt() || task.TaskType == TaskTypeEnum.F03.ObjToInt()) //出库
                        {
                            ////出库料箱缓存数量(这个是库区查询的时候要查一下,返给wms)
                            //if (device.GetValue<HoistEnum, short>(HoistEnum.Outboundmaterialbox, "TSJ") == 0) throw new Exception("没有出库料箱缓存数量为空");
 
                            if (task.TaskType == TaskTypeEnum.CK3F.ObjToInt())
                            {
                                //读取3楼出库料箱到位
                                if (device.GetValue<HoistEnum, short>(HoistEnum.SOutboundmaterialbox, task.SourceAddress) != 1)
                                {
                                    if (task.ExceptionMessage != "3楼提升机出口光电反馈无货")
                                    {
                                        task.ExceptionMessage = "3楼提升机出口光电反馈无货";
                                        Uptasks.Add(task);
                                    }
                                    continue;
                                }
                            }
                            else
                            {
                                if (device.GetValue<HoistEnum, short>(HoistEnum.FOutboundmaterialbox, task.SourceAddress) != 1)
                                {
                                    if (task.ExceptionMessage != "4楼提升机出口光电反馈无货")
                                    {
                                        task.ExceptionMessage = "4楼提升机出口光电反馈无货";
                                        Uptasks.Add(task);
                                    }
                                    continue;
                                }
                            }
                            //然后调用输送线接口,通知输送线有料箱需要入库,任务举行执行
                            var result = _taskService.Hikvisiontaskscontinue(task.WMSTaskNum);
                            if (result.Status == false)
                            {
                                if (task.ExceptionMessage != result.Message)
                                {
                                    task.ExceptionMessage = result.Message;
                                    Uptasks.Add(task);
                                }
                                continue;
                            }
                            task.TaskState = (int)TaskStatusEnum.AGV_ToExecute;
                            task.ExceptionMessage = "";
                            Uptasks.Add(task);
                        }
                      
 
                    }
 
                    #region 托盘号确认中
                    //查找三楼入库任务状态为CheckPalletCodeing的任务托盘号确认中
                    var RK3FTasks = _taskService.Repository.QueryFirst(x => x.TaskType == TaskTypeEnum.RK3F.ObjToInt() && x.TaskState == (int)TaskStatusEnum.CheckPalletCodeing);
                    if (RK3FTasks != null)
                    {
                        var Barcode = device.SetValue<HoistEnum, short>(HoistEnum.Codereadingtriggered, 1);
                        //检查3楼入库箱号是多少,然后传给wms
                        var BinNumber = device.GetValue<HoistEnum, string>(HoistEnum.Inboxnumber, RK3FTasks.TargetAddress);
                        //根据读到的箱号进行料箱检验,检验通过就触发读码器读取,如果不通过就抛出异常
                        //var Verification = _taskService.MaterialBoxInspection(RK3FTasks.WMSTaskNum, BinNumber.ToString());
                        //if (!Verification.Status)
                        //{
                        //    if (!(RK3FTasks.ExceptionMessage == Verification.Message))
                        //    {
                        //        RK3FTasks.ExceptionMessage = Verification.Message;
                        //        Uptasks.Add(RK3FTasks);
                        //    }
                        //    //料箱验证写好后,需要更改
                        //    RK3FTasks.TargetAddress = Verification.Data.ToString();
                        //}
 
                        //如果料箱检验成功就写入读码器的值
                        var result = _taskService.Hikvisiontaskscontinue(RK3FTasks.WMSTaskNum, RK3FTasks.TargetAddress);
                        if (result.Status == false)
                        {
                            if (RK3FTasks.ExceptionMessage != result.Message)
                            {
                                RK3FTasks.ExceptionMessage = result.Message;
                                Uptasks.Add(RK3FTasks);
                            }
                        }
                        RK3FTasks.TaskState = (int)TaskStatusEnum.CheckPalletCodeFinish;
                        Uptasks.Add(RK3FTasks);
                    }
                    #endregion
                    if (Uptasks.Count > 0)
                    {
                        _taskService.UpdateData(Uptasks);
                    }
                    WriteInfo(device.DeviceName, "infoLog");
 
                    WriteDebug(device.DeviceName, "debugLog");
                }
                catch (Exception ex)
                {
                    WriteError(device.DeviceName, "错误", ex);
                }
            }
            else
            {
                WriteError(nameof(TestJob), "参数错误,未传递设备参数或设备类型错误");
            }
 
 
            return Task.CompletedTask;
        }
    }
 
 
}