1
dengjunjie
2025-03-18 9f225bb1f1e26d25c1652d3e1ec2a8f239f69615
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Common.ConveyorLineEnum;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_DTO.WMSInfo;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_QuartzJob.Models;
using WIDESEAWCS_Tasks.ConveyorLineJob;
 
namespace WIDESEAWCS_Tasks
{
    public partial class CommonConveyorLineJob
    {
        /// <summary>
        /// 输送线
        /// </summary>
        /// <param name="conveyorLine"></param>
        /// <returns></returns>
        public List<Task> ConveyorLineExtend(CommonConveyorLine conveyorLine)
        {
            List<string> childDeviceCodes = _routerService.QueryAllPositions(conveyorLine.DeviceCode);
            List<Task> tasks = new List<Task>();
            foreach (string childDeviceCode in childDeviceCodes)
            {
                try
                {
                    ConveyorLineTaskCommandR command = conveyorLine.ReadCustomer<ConveyorLineTaskCommandR>(childDeviceCode);
                    if (command != null)
                    {
                        if (childDeviceCode == "1002" && command.Status == (ushort)ConveyorStatus.Wait)
                        {
                            RequestInbound(conveyorLine, command, childDeviceCode);
                        }
                        else if (childDeviceCode == "1004" && command.Status == (ushort)ConveyorStatus.Stored)
                        {
                            ConveyorLineInFinish(conveyorLine, command, childDeviceCode);
                        }
                        //else if (childDeviceCode == "1005" && command.Status == (ushort)ConveyorStatus.Stored)
                        //{
                        //    Dt_Task task = _taskService.QueryConveyorLineTaskNum(conveyorLine.DeviceCode, childDeviceCode, command.TaskNum);
                        //    if (task != null)
                        //    {
                        //        task.TaskState = TaskOutStatusEnum.Line_OutExecuting.ObjToInt();
                        //        _taskService.UpdateData(task);
                        //        ConveyorLineTaskCommandW taskCommand = _mapper.Map<ConveyorLineTaskCommandW>(task);
                        //        taskCommand.WriterTrue = (short)command.inRead;
                        //        conveyorLine.SendCommand(taskCommand, childDeviceCode);
                        //    }
                        //}
                        else if (childDeviceCode == "1008" && command.Status == (ushort)ConveyorStatus.Stored)
                        {
                            Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode);
                            if (task != null)
                            {
                                List<Dt_Router> routers = _routerRepository.QueryData(x => x.StartPosi == task.NextAddress && x.ChildPosiDeviceCode == "AGV" && x.Remark == "未占用");
                                if (routers.Count > 0)
                                {
 
                                }
                                task.TaskState = TaskOutStatusEnum.Line_OutFinish.ObjToInt();
                                _taskService.UpdateData(task);
                            }
                        }
                    }
                    #region MyRegion
 
                    //if (command != null && command.Status == (ushort)ConveyorStatus.Stored)//添加输送线状态ConveyorLineStatus enum
                    //{
                    //    switch (childDeviceCode)
                    //    {
                    //        case "1002":
                    //            {
                    //                RequestInbound(conveyorLine, command, childDeviceCode);
                    //            }
                    //            break;
                    //        case "1004":
                    //            ConveyorLineInFinish(conveyorLine, command, childDeviceCode);
                    //            break;
                    //        //case "105":
                    //        //    RequestOutbound(conveyorLine, command, childDeviceCode);
                    //        //    break;
                    //        case "1008":
                    //            ConveyorLineOutFinish(conveyorLine, command, childDeviceCode);
                    //            break;
                    //            //default:
                    //            //    RequestInNextAddress(conveyorLine, command, childDeviceCode);
                    //            //    RequestOutNextAddress(conveyorLine, command, childDeviceCode);
                    //            //    break;
                    //    }
                    //}
                    #endregion
                }
                catch (Exception ex)
                {
                    continue;
                }
            }
            return tasks;
        }
 
 
        /// <summary>
        /// 输送线请求入库
        /// </summary>
        /// <param name="conveyorLine">输送线实例对象</param>
        /// <param name="command">读取的请求信息</param>
        /// <param name="childDeviceCode">子设备编号</param>
        public void RequestInbound(CommonConveyorLine conveyorLine, ConveyorLineTaskCommandR command, string childDeviceCode)
        {
            Dt_Task task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode, command.Barcode);
            //Dt_Task task = _taskService.QueryConveyorLineTaskNum(conveyorLine.DeviceCode, childDeviceCode, command.TaskNum);
            if (task != null)
            {
                if (command.Spec > 0)
                {
                    DeviceProtocolDetailDTO? deviceProtocolDetail = conveyorLine.DeviceProtocolDetailDTOs.FirstOrDefault(x => x.ProtocalDetailValue == command.Spec.ToString() && x.DeviceProParamName == nameof(ConveyorLineTaskCommandR.Spec));
                    string? Des = deviceProtocolDetail?.ProtocolDetailDes;
                    if (Des != task.ExceptionMessage)
                    {
                        task.ExceptionMessage = deviceProtocolDetail?.ProtocolDetailDes;
                        _taskService.UpdateData(task);
                    }
                    return;
                }
                ConveyorLineDTO lineDTO = new ConveyorLineDTO()
                {
                    TaskNum = task.TaskNum,
                    stationCode = childDeviceCode,
                    Barcode = command.Barcode,
                    Spec = command.Spec,
                    Weight = command.Weight,
                };
                var content = _taskService.RequestWMSTask(lineDTO);
                if (!content.Status)
                {
                    task.ExceptionMessage = content?.Message;
                    _taskService.UpdateData(task);
                    return;
                }
                //if (content.Status)
                //{
                task.CurrentAddress = childDeviceCode;
                List<Dt_Router> routers = _routerService.QueryNextRoutes(task.CurrentAddress, task.TargetAddress);
                if (routers.Count > 0)
                {
                    task.NextAddress = routers.FirstOrDefault().ChildPosi;
                }
                //task.NextAddress = AppSettings.Configuration["OKAddress"];
                task.ExceptionMessage = null;
                ConveyorLineTaskCommandW taskCommand = _mapper.Map<ConveyorLineTaskCommandW>(task);
                taskCommand.WriterTrue = (short)command.inRead;
 
                if (conveyorLine.SendCommand(taskCommand, childDeviceCode))
                    _taskService.UpdateTaskStatusToNext(task);
                //}
                //else
                //{
                //    //if (content.Code == 404)//修改终点地址
                //    //{
                //    task.CurrentAddress = childDeviceCode;
                //    task.NextAddress = AppSettings.Configuration["NGAddress"];
                //    task.ExceptionMessage = content.Message;
                //    task.TaskState = (int)TaskInStatusEnum.InException;
                //    ConveyorLineTaskCommandW taskCommand = _mapper.Map<ConveyorLineTaskCommandW>(task);
                //    taskCommand.WriterTrue = 1;
                //    if (conveyorLine.SendCommand(taskCommand, childDeviceCode)) _taskService.UpdateData(task);
                //    //}
                //}
            }
        }
 
        /// <summary>
        /// 输送线请求入库下一地址
        /// </summary>
        /// <param name="conveyorLine">输送线实例对象</param>
        /// <param name="command">读取的请求信息</param>
        /// <param name="childDeviceCode">子设备编号</param>
        public void RequestInNextAddress(CommonConveyorLine conveyorLine, ConveyorLineTaskCommandR command, string childDeviceCode)
        {
            Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode);
            if (task != null)
            {
                Dt_Task? newTask = _taskService.UpdatePosition(task.TaskNum, task.CurrentAddress);
                //if (newTask != null)
                //{
                //    ConveyorLineTaskCommandW taskCommand = _mapper.Map<ConveyorLineTaskCommandW>(newTask);
 
                //    conveyorLine.SendCommand(taskCommand, childDeviceCode);
                //}
            }
        }
        /// <summary>
        /// 输送线入库完成
        /// </summary>
        /// <param name="conveyorLine">输送线实例对象</param>
        /// <param name="command">读取的请求信息</param>
        /// <param name="childDeviceCode">子设备编号</param>
        public void ConveyorLineInFinish(CommonConveyorLine conveyorLine, ConveyorLineTaskCommandR command, string childDeviceCode)
        {
            //Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode);
            Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.Barcode, childDeviceCode);
            if (task != null) _taskService.UpdateTaskStatusToNext(task);
 
            task = _taskService.QueryCompletedConveyorLineTask(command.Barcode, childDeviceCode);
            if (task != null && string.IsNullOrEmpty(task.TargetAddress))
            {
                _taskService.StackerCraneRequestInbound(task);
            }
            //if (task != null)
            //{
            //    //conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal, 0, childDeviceCode);
            //    //向WMS更新任务状态,WMS返回入库任务终点
            //    WebResponseContent content = _taskService.UpdateTaskStatusToNext(task);
            //    //Console.Out.WriteLine(content.Serialize());
            //}
        }
 
        /// <summary>
        /// 输送线请求出信息
        /// </summary>
        /// <param name="conveyorLine">输送线实例对象</param>
        /// <param name="command">读取的请求信息</param>
        /// <param name="childDeviceCode">子设备编号</param>
        public void RequestOutbound(CommonConveyorLine conveyorLine, ConveyorLineTaskCommandR command, string childDeviceCode)
        {
            Dt_Task task = _taskService.QueryConveyorLineTask(conveyorLine.DeviceCode, childDeviceCode, command.Barcode);
            if (task != null)
            {
                ConveyorLineTaskCommandW taskCommand = _mapper.Map<ConveyorLineTaskCommandW>(task);
 
                conveyorLine.SendCommand(taskCommand, childDeviceCode);
 
                _taskService.UpdateTaskStatusToNext(task);
            }
        }
 
        /// <summary>
        /// 输送线请求出库下一地址
        /// </summary>
        /// <param name="conveyorLine">输送线实例对象</param>
        /// <param name="command">读取的请求信息</param>
        /// <param name="childDeviceCode">子设备编号</param>
        public void RequestOutNextAddress(CommonConveyorLine conveyorLine, ConveyorLineTaskCommandR command, string childDeviceCode)
        {
            Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode);
            if (task != null)
            {
                Dt_Task? newTask = _taskService.UpdatePosition(task.TaskNum, task.CurrentAddress);
                //if (newTask != null)
                //{
                //    ConveyorLineTaskCommandW taskCommand = _mapper.Map<ConveyorLineTaskCommandW>(newTask);
 
                //    conveyorLine.SendCommand(taskCommand, childDeviceCode);
                //}
            }
        }
 
        /// <summary>
        /// 输送线出库完成
        /// </summary>
        /// <param name="conveyorLine">输送线实例对象</param>
        /// <param name="command">读取的请求信息</param>
        /// <param name="childDeviceCode">子设备编号</param>
        public void ConveyorLineOutFinish(CommonConveyorLine conveyorLine, ConveyorLineTaskCommandR command, string childDeviceCode)
        {
            Dt_Task task = _taskService.QueryExecutingConveyorLineTask(command.TaskNum, childDeviceCode);
            if (task != null)
            {
                //conveyorLine.SetValue(ConveyorLineDBName.WriteInteractiveSignal, 0, childDeviceCode);
                WebResponseContent content = _taskService.UpdateTaskStatusToNext(task);
                //Console.Out.WriteLine(content.Serialize());
            }
        }
    }
}