wcs
huanghongfeng
2025-01-16 b701e82fd920e401658b72a5b1c53feaf9ae5b77
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
#region << 版 本 注 释 >>
/*----------------------------------------------------------------
 * 命名空间:WIDESEAWCS_Tasks.ConveyorLineJob
 * 创建者:胡童庆
 * 创建时间:2024/8/2 16:13:36
 * 版本:V1.0.0
 * 描述:
 *
 * ----------------------------------------------------------------
 * 修改人:
 * 修改时间:
 * 版本:V1.0.1
 * 修改说明:
 * 
 *----------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
 
using AutoMapper;
using Quartz;
using WIDESEA_Common.Log;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_DTO.Enum;
using WIDESEAWCS_ISystemServices;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_Model.Models.System;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.Service;
using WIDESEAWCS_Tasks.ConveyorLineJob;
 
namespace WIDESEAWCS_Tasks
{
    [DisallowConcurrentExecution]
    public class CommonConveyorLineJob : IJob
    {
        private readonly ITaskService _taskService;
        private readonly ITaskExecuteDetailService _taskExecuteDetailService;
        private readonly IRouterService _routerService;
        private readonly IAgvStationService _agvStationService;
        private readonly IMapper _mapper;
 
        public CommonConveyorLineJob(ITaskService taskService, ITaskExecuteDetailService taskExecuteDetailService, IRouterService routerService, IAgvStationService agvStation, IMapper mapper)
        {
            _taskService = taskService;
            _taskExecuteDetailService = taskExecuteDetailService;
            _routerService = routerService;
            _agvStationService = agvStation;
            _mapper = mapper;
        }
 
        public Task Execute(IJobExecutionContext context)
        {
            try
            {
                wcsWriteLog("LineJob", "运行状态", $"开始时间:{DateTime.Now}");
                CommonConveyorLine conveyorLine = (CommonConveyorLine)context.JobDetail.JobDataMap.Get("JobParams");
                if (conveyorLine != null)
                {
                    //生成取货任务,放至上料位
                    RequestInbound(conveyorLine);
                    //根据agv下料任务,把料放至上料口或缓存位
                    RequestOutbound(conveyorLine);  //上料口需要找任务,找缓存区
                }
 
            }
            catch (Exception ex)
            {
                //Console.Out.WriteLine(nameof(CommonConveyorLineJob) + ":" + ex.ToString());
                wcsWriteLog("LineJob错误信息", "异常信息", ex.ToString());
            }
            wcsWriteLog("LineJob", "运行状态", $"结束时间:{DateTime.Now}");
            return Task.CompletedTask;
        }
 
        /// <summary>
        /// 输送线请求入库
        /// </summary>
        /// <param name="conveyorLine">输送线实例对象</param>
        /// <param name="command">读取的请求信息</param>Request outbound
        /// <param name="childDeviceCode">子设备编号</param>
        public void RequestInbound(CommonConveyorLine conveyorLine)
        {
            List<string> _Task = _taskService.QueryConveyorLineTaskSourceAddress();
            List<AGVStation> childDeviceCodes = _agvStationService.QuerypLatform(conveyorLine.DeviceCode, _Task);  //对应每个ip找全部的下料站点与垫板回收点站台点
            foreach (var childDeviceCode in childDeviceCodes)
            {
                ConveyorLineCommand command = conveyorLine.ReadCustomer<ConveyorLineCommand>(childDeviceCode.Station_name);
                if (command != null)
                {
                    if (command.R_Releasespermitted == 1)
                    {
                        if (childDeviceCode.Station_material==(int)AgvStationEnum.PadRecycle)
                        {
                            RequestHcdbst(conveyorLine, childDeviceCode.Station_Area, childDeviceCode.Station_name, childDeviceCode.Station_remark);
                        }
                        else
                        {
                            Dt_Task taskDTO = new Dt_Task()
                            {
                                TaskNum = Convert.ToInt32(DateTime.Now.ToString("HHmmss")) + childDeviceCode.Station_code,
                                Grade = 1,
                                Roadway = childDeviceCode.Station_Area.ToString(),
                                SourceAddress = childDeviceCode.Station_name,
                                CurrentAddress = childDeviceCode.Station_name,
                                TaskState = (int)TaskInStatusEnum.InNew,
                                TaskType = (int)childDeviceCode.Station_material,
                            };
                            _taskService.ReceiveWMSTask(taskDTO);
                        }
                    }
                    else
                    {
                        wcsWriteLog(childDeviceCode.Station_name, "读取信息", $"未找到该读取模块");
                    }
                }
                else
                {
                    wcsWriteLog(childDeviceCode.Station_name, "读取信息", $"通讯连接错误,未找到读取模块地址");
                }
            }
        }
 
        /// <summary>
        /// 输送线请求出站
        /// </summary>
        /// <param name="conveyorLine">输送线实例对象</param>
        /// <param name="command">读取的请求信息</param>
        /// <param name="childDeviceCode">子设备编号</param>
        public void RequestOutbound(CommonConveyorLine conveyorLine)
        {
            List<AGVStation> AGVStationListdata = _agvStationService.QuerypLatformarer(conveyorLine.DeviceCode);
            foreach (var AGVStationitem in AGVStationListdata)
            {
                ConveyorLineCommand command = conveyorLine.ReadCustomer<ConveyorLineCommand>(AGVStationitem.Station_name);
                if (command != null)
                {
                    if (command.R_Pickuppermitted == 1)
                    {
                        if (AGVStationitem.Station_material == (int)AgvStationEnum.BoardLoad)
                        {
                            Dt_Task agvstack= _taskService.QueryConveyorLineTaskRoadway(AGVStationitem.Station_Area);
                            if(agvstack != null)
                            {
                                _taskService.UpdateTargetAddress(agvstack.TaskId, AGVStationitem.Station_name);
                            }
                            else
                            {
                                //去找缓存区库存
                                RequestHcst(conveyorLine, AGVStationitem.Station_Area, AGVStationitem.Station_name, AGVStationitem.Station_remark);
                            }
                        }
                    }
                    else
                    {
                        wcsWriteLog(AGVStationitem.Station_name, "读取信息", $"通讯连接错误,未找到读取模块地址");
                    }
                }
            }
        }
 
        public void RequestHcst(CommonConveyorLine conveyorLine,int Station_Area,string Station_names,string Station_remark)
        {
            List<AGVStation> AGVStationListdata = _agvStationService.QuerypLatformmaterial(Station_Area);   //查出缓存位
            if (Station_remark != null)   //找寻对应的放货站台
            {
                AGVStationListdata = _agvStationService.QuerypStation_Area2(Station_remark);
            }
            foreach (var AGVStationitem in AGVStationListdata)
            {
                ConveyorLineCommand command = conveyorLine.ReadCustomer<ConveyorLineCommand>(AGVStationitem.Station_name);
                if (command != null)
                {
                    if (command.R_Releasespermitted == 1)
                    {
                        if (_taskService.QueryConveyorLinetaeersuadd(AGVStationitem.Station_name))
                        {
                            Dt_Task taskDTO = new Dt_Task()
                            {
                                TaskNum = Convert.ToInt32(DateTime.Now.ToString("HHmmss")) + AGVStationitem.Station_code,
                                Grade = 1,
                                Roadway = AGVStationitem.Station_Area.ToString(),
                                SourceAddress = AGVStationitem.Station_name,
                                CurrentAddress = AGVStationitem.Station_name,
                                TaskState = (int)TaskInStatusEnum.InNew,
                                TaskType = (int)AGVStationitem.Station_material,
                                TargetAddress = Station_names,
                                NextAddress = Station_names,
                            };
                            _taskService.ReceiveWMSTask(taskDTO);
                        }
                    }
                    else
                    {
                        wcsWriteLog(AGVStationitem.Station_name, "读取信息", $"通讯连接错误,未找到读取模块地址");
                    }
                }
            }
        }
 
        public void RequestHcdbst(CommonConveyorLine conveyorLine, int Station_Area, string Station_names,string Station_remark)
        {
            List<AGVStation> AGVStationListdata = _agvStationService.QuerypStation_Area(Station_Area);   //查出缓存位
            if(Station_remark !=null)   //找寻对应的放货站台
            {
                AGVStationListdata= _agvStationService.QuerypStation_Area2(Station_remark);
            }
            
            foreach (var AGVStationitem in AGVStationListdata)
            {
                ConveyorLineCommand command = conveyorLine.ReadCustomer<ConveyorLineCommand>(AGVStationitem.Station_name);
                if (command != null)
                {
                    if (command.R_Releasespermitted == 1)
                    {
                        if (_taskService.QueryConveyorLinetaeersuadd(AGVStationitem.Station_name))
                        {
                            Dt_Task taskDTO = new Dt_Task()
                            {
                                TaskNum = Convert.ToInt32(DateTime.Now.ToString("HHmmss")) + AGVStationitem.Station_code,
                                Grade = 1,
                                Roadway = AGVStationitem.Station_Area.ToString(),
                                SourceAddress = Station_names,
                                CurrentAddress = Station_names,
                                TaskState = (int)TaskInStatusEnum.InNew,
                                TaskType = (int)AGVStationitem.Station_material,
                                TargetAddress = AGVStationitem.Station_name,
                                NextAddress = AGVStationitem.Station_name,
                            };
                            _taskService.ReceiveWMSTask(taskDTO);
                        }
                    }
                    else
                    {
                        wcsWriteLog(AGVStationitem.Station_name, "读取信息", $"读取放货信号为:{command.R_Releasespermitted}");
                    }
                }
            }
        }
 
 
 
        /// <summary>
        /// 读取信息记录
        /// </summary>
        /// <param name="SCLLinStack"></param>
        /// <param name="Logtype"></param>
        /// <param name="Magessadd"></param>
        public void wcsWriteLog(string SCLLinStack,string Logtype,string Magessadd)
        {
            WriteLog.Write_Log("站台读取信息记录", SCLLinStack+"站台", Logtype, new{信息 = Magessadd });
        }
 
    }
}