1
huanghongfeng
2024-11-11 3ecd03b3a0a30a57153468beaed3199bfe906772
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
#region << 版 本 注 释 >>
/*----------------------------------------------------------------
 * 命名空间:WIDESEAWCS_Tasks.ConveyorLineJob
 * 创建者:胡童庆
 * 创建时间:2024/8/2 16:13:36
 * 版本:V1.0.0
 * 描述:
 *
 * ----------------------------------------------------------------
 * 修改人:
 * 修改时间:
 * 版本:V1.0.1
 * 修改说明:
 * 
 *----------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
 
using AutoMapper;
using Newtonsoft.Json;
using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using Quartz;
using StackExchange.Profiling.Internal;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Common.Log;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Communicator;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.DeviceBase;
using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_QuartzJob.Models;
using WIDESEAWCS_QuartzJob.Service;
using WIDESEAWCS_Tasks.ConveyorLineJob;
using WIDESEAWCS_Tasks.StackerCraneJob;
using static Microsoft.IO.RecyclableMemoryStreamManager;
 
namespace WIDESEAWCS_Tasks
{
    [DisallowConcurrentExecution]
    public class CommonConveyorLineJob : IJob
    {
        private readonly ITaskService _taskService;
        private readonly ITaskExecuteDetailService _taskExecuteDetailService;
        private readonly IRouterService _routerService;
        private readonly IMapper _mapper;
 
        public CommonConveyorLineJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IMapper mapper)
        {
            _taskService = taskService;
            _taskExecuteDetailService = taskExecuteDetailService;
            _routerService = routerService;
            _mapper = mapper;
        }
 
        public Task Execute(IJobExecutionContext context)
        {
            try
            {
                CommonConveyorLine conveyorLine = (CommonConveyorLine)context.JobDetail.JobDataMap.Get("JobParams");
 
                if( conveyorLine != null )
                {
                    RequestInbound(conveyorLine);   //判断巷道去哪个巷道
                }
                //RequestInNextAddress(conveyorLine);
 
 
            }
            catch (Exception ex)
            {
                //Console.Out.WriteLine(nameof(CommonConveyorLineJob) + ":" + ex.ToString());
            }
            finally
            {
                //Console.Out.WriteLine(DateTime.Now);
            }
            return Task.CompletedTask;
        }
 
        /// <summary>
        /// 输送线请求入库到哪个巷道
        /// </summary>
        /// <param name="conveyorLine">输送线实例对象</param>
        /// <param name="command">读取的请求信息</param>
        /// <param name="childDeviceCode">子设备编号</param>
        public void RequestInbound(CommonConveyorLine conveyorLine)
        {
            //1楼输送线判断
            HandleEvent(conveyorLine, "PLC_WCS_B._03_PLC_EVENT", "PLC_WCS_B._03_PLC_LPN", "WCS_PLC_B._03_WCS_TO");  //判断巷道
            HandleEvent(conveyorLine, "PLC_WCS_C._02_PLC_EVENT", "PLC_WCS_C._02_PLC_LPN", "WCS_PLC_C._02_WCS_TO");  //判断巷道
            CheckForEmptyPallet(conveyorLine, "PLC_WCS_B._01_PLC_EVENT"); //判断是否取空托
            CheckForEmptyPallet(conveyorLine, "PLC_WCS_C._01_PLC_EVENT"); //判断是否取空托
            ProcessConveyorEvent(conveyorLine, "PLC_WCS_B._01_PLC_EVENT", "PLC_WCS_B._01_PLC_LPN", "R02-003-027-001-01");// 处理 B 站台事件 //判断输送线到达信号
            ProcessConveyorEvent(conveyorLine, "PLC_WCS_C._03_PLC_EVENT", "PLC_WCS_C._03_PLC_LPN", "R01-003-041-001-01");// 处理 C 站台事件 //判断输送线到达信号
        }
 
        
 
        /// <summary>
        /// 判断出库站台是否需要空托
        /// </summary>
        /// <param name="conveyorLine">输送线实例对象</param>
        /// <param name="command">读取的请求信息</param>
        /// <param name="childDeviceCode">子设备编号</param>
        public void ConveyorLineInFinish(CommonConveyorLine conveyorLine)
        {
            
        }
 
 
        /// <summary>
        /// 用于入库判断巷道
        /// </summary>
        /// <param name="conveyorLine"></param>
        /// <param name="eventTag"></param>
        /// <param name="barcodeTag"></param>
        /// <param name="writeTag"></param>
        private void HandleEvent(CommonConveyorLine conveyorLine,string eventTag, string barcodeTag, string writeTag)
        {
            try
            {
                byte events = conveyorLine.Communicator.Read<byte>(eventTag); // 读取事件
                if (events == 1)
                {
                    string barcode = conveyorLine.Communicator.Read<string>(barcodeTag); // 读取条码
                    if ((_taskService.ToPlatform(barcode)).Status)
                    {
                        // 写入去向1号堆垛机
                        bool result = conveyorLine.Communicator.Write(writeTag, 1);
                        if (result)
                        {
                            WriteLog.GetLog("PLC日志").Write("写入去向:1", "去向");
                        }
                    }
                    /*else
                    {
                        // 写入去向2号堆垛机
                        *//*bool result = conveyorLine.Communicator.Write(writeTag, 2);
                        if (result)
                        {
                            WriteLog.GetLog("PLC日志").Write("写入去向:2", "去向");
                        }*//*
 
                        WriteLog.GetLog("PLC日志").Write("入库失败", "入库组盘");
                    }*/
                }
            }
            catch (Exception ex)
            {
 
                throw;
            }
        }
 
        //用于判断是否补空托
        private void CheckForEmptyPallet(CommonConveyorLine conveyorLine,string eventTag)
        {
 
            Byte events = conveyorLine.Communicator.Read<Byte>(eventTag);  // 读取事件
            if (events == 0)
            {
                WriteLog.GetLog("PLC日志").Write($"读取到出库口补空托信号:{events}", "需要空托");
                // 生成堆垛机取空托任务
                if ((_taskService.RequestWMSTask2(conveyorLine.DeviceCode)).Status)
                {
                    WriteLog.GetLog("PLC日志").Write($"已生成空托出库任务:{events}", "需要空托");
                }
                else
                {
                    WriteLog.GetLog("PLC日志").Write($"未生成空托出库任务:{events}", "需要空托");
                }
            }
        }
 
        //用于判断入库站台
        private void ProcessConveyorEvent(CommonConveyorLine conveyorLine, string eventTag, string barcodeTag, string taskCode)
        {
            byte eventStatus = conveyorLine.Communicator.Read<byte>(eventTag);
            if (eventStatus == 1)
            {
                string barcode = conveyorLine.Communicator.Read<string>(barcodeTag);
                if (barcode != null)
                {
                    // 拿取托盘条码申请入库信息
                    WebResponseContent content = _taskService.RequestWMSTask(barcode, taskCode); // 申请入库,生成堆垛机任务
                    if (content !=null)
                    {
                        if (content.Status)
                        {
                            WriteLog.GetLog("PLC入库站台日志").Write($"申请入库成功,站台编号为:{taskCode}", "站台信息");
                        }
                        else
                        {
                            WriteLog.GetLog("PLC入库站台日志").Write($"申请入库失败,站台编号为:{taskCode}", "站台信息");
                        }
                    }
                }
                else
                {
                    WriteLog.GetLog("PLC入库站台日志").Write($"读取到输送线信息为空,站台编号为:{taskCode}", "站台信息");
                }
            }
        }
    }
}