wangxinhui
2024-11-06 8f392cc88b0768b74efca3b68785cf5aa1c38e70
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
using Microsoft.CodeAnalysis;
using Microsoft.EntityFrameworkCore;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Logical;
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using WIDESEA_Common;
using WIDESEA_Common.DBHelper;
using WIDESEA_Common.Tools;
using WIDESEA_Core.EFDbContext;
using WIDESEA_Entity.DomainModels;
using WIDESEA_Services.IRepositories;
using WIDESEA_Services.Repositories;
 
namespace WIDESEA_WCS
{
    public partial class StackerExecutor
    {
        public static object requestFJBCK = new object();//requestFJJK
        private static int _readFBCKSignalsoZBCK = 0;//_readZTBUPSignalso
 
        /// <summary>
        /// 负极箔材库搬运工作逻辑
        /// </summary>
        /// <param name="client"></param>
        public static void F_BCK_Task()
        {
            if (Interlocked.Exchange(ref _readFBCKSignalsoZBCK, 1) == 0)
            {
                Task.Run(() =>
                {
                    try
                    {
                        FreeDB freeDB = new FreeDB();
                        VOLContext Context = new VOLContext();
                        Ibase_ware_locationRepository locRepository = new base_ware_locationRepository(Context);
                        Idt_agvtaskRepository agvRepository = new dt_agvtaskRepository(Context);
 
                        //34出口,供给辊分上料口
                        var location_34 = freeDB.Select<base_ware_location>().Where(t => t.upper_code == "FJ-BCHCJ34" && t.location_state == "LocationState_Empty" && t.status == 1 && t.task == 2 && t.tpgd == 0).First();
                        //36空架立即补料
                        //34空架立即补料
                        dt_agvtask dt_Agvtask34 = agvRepository.FindFirst(x=>x.agv_toaddress== "FJ-BCHCJ34");
                        if (dt_Agvtask34 != null && location_34.task==2)
                        {
                            location_34.update_time = DateTime.Now;
                            location_34.task = 1;
                            location_34.logic_col = 1;
                            var entrys = locRepository.DbContext.ChangeTracker.Entries<base_ware_location>().FirstOrDefault();
                            if (entrys != null)
                            {
                                entrys.State = EntityState.Detached;
                            }
                            int end = locRepository.Update(location_34, true);
                        }
                        if (location_34 != null && dt_Agvtask34==null)
                        {
 
                            var location_34_cp = freeDB.Select<base_ware_location>().Where(t => t.location_state == "LocationState_Stored" && t.logic_row.ToString() == "TBXL-BCK" && t.logic_col == 1/*正常料*/ && t.upper_code.Contains("FJ-BCHCJ") && t.light_color != "SB" && t.status == 1 && t.task == 2).OrderBy(t => t.update_time).First();
                            //dt_agvtask task_34 = agvRepository.Find(t => t.agv_fromaddress == "FJ-BCHCJ34" || t.agv_toaddress == "FJ-BCHCJ34").FirstOrDefault();
 
                            if (location_34_cp != null)//找到合适货位,生成补料搬运任务
                            {
                                //34货位补料任务
                                dt_agvtask agvtask = new dt_agvtask();
                                agvtask.agv_id = Guid.NewGuid();
                                agvtask.agv_tasknum = "KH-" + IdenxManager.GetTaskNo();
                                agvtask.agv_fromaddress = location_34_cp.upper_code;
                                agvtask.agv_toaddress = location_34.upper_code;
                                agvtask.agv_code = "负极AGV调度";
                                agvtask.agv_remark = "负极箔材库搬运(34补料)";
                                agvtask.agv_taskstate = AGVTaskStateEnum.Create.ToString();
                                agvtask.agv_tasktype = AGVTaskTypeEnum.TaskType_Outbound.ToString();
                                agvtask.agv_worktype = 1;//工作类型
                                agvtask.agv_materielid = "";
                                agvtask.agv_qty = 1;
                                agvtask.agv_createtime = DateTime.Now;
                                agvtask.agv_grade = 0;//任务优先级
                                agvtask.agv_userid = "WCS";
                                agvtask.agv_barcode = "";
 
                                location_34_cp.update_time = DateTime.Now;
                                location_34_cp.task = 1;
                                var entry = locRepository.DbContext.ChangeTracker.Entries<base_ware_location>().FirstOrDefault();
                                if (entry != null)
                                {
                                    entry.State = EntityState.Detached;
                                }
                                int begin = locRepository.Update(location_34_cp, d => new { d.update_time, d.task }, true);
 
                                location_34.update_time = DateTime.Now;
                                location_34.task = 1;
                                location_34.logic_col = 1;
                                var entrys = locRepository.DbContext.ChangeTracker.Entries<base_ware_location>().FirstOrDefault();
                                if (entrys != null)
                                {
                                    entrys.State = EntityState.Detached;
                                }
                                int end = locRepository.Update(location_34, d => new { d.update_time, d.task, d.logic_col }, true);
                                if (begin == 1 && end == 1)
                                {
                                    agvRepository.Add(agvtask, true);
                                }
 
                            }
 
                        }
 
                        //36出口,供给涂布上料口
                        var location_36 = freeDB.Select<base_ware_location>().Where(t => t.upper_code == "FJ-BCHCJ36" && t.location_state == "LocationState_Empty" && t.status == 1 && t.task == 2 && t.tpgd == 0).First();
                        //36空架立即补料
                        dt_agvtask dt_Agvtask36 = agvRepository.FindFirst(x => x.agv_toaddress == "FJ-BCHCJ36");
                        if (dt_Agvtask36 != null && location_36.task == 2)
                        {
                            location_36.update_time = DateTime.Now;
                            location_36.task = 1;
                            location_36.logic_col = 1;
                            var entrys = locRepository.DbContext.ChangeTracker.Entries<base_ware_location>().FirstOrDefault();
                            if (entrys != null)
                            {
                                entrys.State = EntityState.Detached;
                            }
                            int end = locRepository.Update(location_36, true);
                        }
                        if (location_36 != null && dt_Agvtask36 == null)
                        {
 
 
                            var location_36_cp = freeDB.Select<base_ware_location>().Where(t => t.location_state == "LocationState_Stored" && t.logic_row.ToString() == "TSJXL-BCK" && t.logic_col == 1 && t.upper_code.Contains("FJ-BCHCJ") && t.light_color != "SB" && t.status == 1 && t.task == 2).OrderBy(t => t.update_time).First();
                            //dt_agvtask task_36 = agvRepository.Find(t => t.agv_fromaddress == "FJ-BCHCJ36" || t.agv_toaddress == "FJ-BCHCJ36").FirstOrDefault();
 
                            if (location_36_cp != null)//找到合适货位,生成补料搬运任务
                            {
 
                                //36货位补料任务
                                dt_agvtask agvtask = new dt_agvtask();
                                agvtask.agv_id = Guid.NewGuid();
                                agvtask.agv_tasknum = "KH-" + IdenxManager.GetTaskNo();
                                agvtask.agv_fromaddress = location_36_cp.upper_code;
                                agvtask.agv_toaddress = location_36.upper_code;
                                agvtask.agv_code = "负极AGV调度";
                                agvtask.agv_remark = "负极箔材库搬运(36补料)";
                                agvtask.agv_taskstate = AGVTaskStateEnum.Create.ToString();
                                agvtask.agv_tasktype = AGVTaskTypeEnum.TaskType_Outbound.ToString();
                                agvtask.agv_worktype = 1;//工作类型
                                agvtask.agv_materielid = "";
                                agvtask.agv_qty = 1;
                                agvtask.agv_createtime = DateTime.Now;
                                agvtask.agv_grade = 0;//任务优先级
                                agvtask.agv_userid = "WCS";
                                agvtask.agv_barcode = "";
 
 
                                location_36_cp.update_time = DateTime.Now;
                                location_36_cp.task = 1;
                                var entrys = locRepository.DbContext.ChangeTracker.Entries<base_ware_location>().FirstOrDefault();
                                if (entrys != null)
                                {
                                    entrys.State = EntityState.Detached;
                                }
                                int begin = locRepository.Update(location_36_cp, d => new { d.update_time, d.task }, true);
 
                                location_36.update_time = DateTime.Now;
                                location_36.task = 1;
                                location_36.logic_col = 1;
                                var entry = locRepository.DbContext.ChangeTracker.Entries<base_ware_location>().FirstOrDefault();
                                if (entry != null)
                                {
                                    entry.State = EntityState.Detached;
                                }
                                int end = locRepository.Update(location_36, d => new { d.update_time, d.task, d.logic_col }, true);
 
                                if (begin == 1 && end == 1)
                                {
                                    agvRepository.Add(agvtask, true);
                                }
                            }
 
 
                        }
 
 
                        //35入口,供涂布下料
                        var location_35 = freeDB.Select<base_ware_location>().Where(t => t.upper_code == "FJ-BCHCJ35" && t.location_state == "LocationState_Stored" && t.status == 1 && t.task == 2 && t.tpgd == 1 && (t.logic_row == "TBXL-BCK" || t.logic_col == 1)).First();
                        //35有料立即搬走
                        if (location_35 != null)
                        {
 
                            int index = 0;
                            int b = 7;
                            DateTime time = DateTime.Now;
                            Double STAMP = 0;
                            do
                            {
                                DateTime time2 = DateTime.Now;
                                STAMP = (time2 - time).TotalSeconds;
                                base_ware_location ware_Location = locRepository.FindFirst(d => d.upper_code == location_35.upper_code
                    && d.location_state == "LocationState_Stored" && location_35.tpgd == 1 && d.status == 1 && (location_35.logic_row == "TBXL-BCK" || location_35.logic_col == 1));
                                if (ware_Location == null)
                                {
                                    index = 3;
                                    break;
                                }
 
                            } while (STAMP < b);
                            if (index != 3)
                            {
                                var location_35_cp = freeDB.Select<base_ware_location>().Where(t => t.location_state == "LocationState_Empty" && t.upper_code.Contains("FJ-BCHCJ") && t.light_color != "SB" && t.status == 1 && t.task == 2).First();
                                if (location_35_cp != null)//找到合适货位,生成搬运任务
                                {
                                    //35货位补料任务
                                    dt_agvtask agvtask = new dt_agvtask();
                                    agvtask.agv_id = Guid.NewGuid();
                                    agvtask.agv_tasknum = "KH-" + IdenxManager.GetTaskNo();
                                    agvtask.agv_fromaddress = location_35.upper_code;
                                    agvtask.agv_toaddress = location_35_cp.upper_code;
                                    agvtask.agv_code = "负极AGV调度";
                                    agvtask.agv_remark = "负极箔材库搬运(35)";
                                    agvtask.agv_taskstate = AGVTaskStateEnum.Create.ToString();
                                    agvtask.agv_tasktype = AGVTaskTypeEnum.TaskType_Outbound.ToString();
                                    agvtask.agv_worktype = 1;//工作类型
                                    agvtask.agv_materielid = "";
                                    agvtask.agv_qty = 1;
                                    agvtask.agv_createtime = DateTime.Now;
                                    agvtask.agv_grade = 0;//任务优先级
                                    agvtask.agv_userid = "WCS";
                                    agvtask.agv_barcode = "";
 
 
                                    location_35_cp.update_time = DateTime.Now;
                                    location_35_cp.task = 1;
                                    //location_35_cp.logic_row = "TBXL-BCK";
                                    var entry = locRepository.DbContext.ChangeTracker.Entries<base_ware_location>().FirstOrDefault();
                                    if (entry != null)
                                    {
                                        entry.State = EntityState.Detached;
                                    }
                                    int end = locRepository.Update(location_35_cp, d => new { d.update_time, d.task }, true);
 
                                    location_35.update_time = DateTime.Now;
                                    location_35.task = 1;
                                    var entrys = locRepository.DbContext.ChangeTracker.Entries<base_ware_location>().FirstOrDefault();
                                    if (entrys != null)
                                    {
                                        entrys.State = EntityState.Detached;
                                    }
                                    int begin = locRepository.Update(location_35, d => new { d.update_time, d.task }, true);
 
                                    if (begin == 1 && end == 1)
                                    {
                                        agvRepository.Add(agvtask, true);
                                    }
                                }
                            }
 
 
                        }
 
                        //37入口,供提升机下料
                        var location_37 = freeDB.Select<base_ware_location>().Where(t => t.upper_code == "FJ-BCHCJ37" && t.location_state == "LocationState_Stored" && t.status == 1 && t.task == 2 && t.tpgd == 1 && (t.logic_row == "TSJXL-BCK" || t.logic_col == 1)).First();
 
                        //37有料立即搬走
                        if (location_37 != null)
                        {
 
                            int index = 0;
                            int b = 7;
                            DateTime time = DateTime.Now;
                            Double STAMP = 0;
                            do
                            {
                                DateTime time2 = DateTime.Now;
                                STAMP = (time2 - time).TotalSeconds;
                                base_ware_location ware_Location = locRepository.FindFirst(d => d.upper_code == location_37.upper_code
                    && d.location_state == LocationStateEnum.LocationState_Stored.ToString() && location_37.tpgd == 1 && d.status == 1 && (location_37.logic_row == "TSJXL-BCK" || location_37.logic_col == 1));
                                if (ware_Location == null)
                                {
                                    index = 3;
                                    break;
                                }
 
                            } while (STAMP < b);
                            if (index != 3)
                            {
                                var location_37_cp = freeDB.Select<base_ware_location>().Where(t => t.location_state == "LocationState_Empty" && t.upper_code.Contains("FJ-BCHCJ") && t.light_color != "SB" && t.status == 1 && t.task == 2).First();
                                //dt_agvtask task_37 = agvRepository.Find(t => t.agv_fromaddress == "FJ-BCHCJ37" || t.agv_toaddress == "FJ-BCHCJ37").FirstOrDefault();
                                if (location_37_cp != null)//找到合适货位,生成搬运任务
                                {
                                    //37货位搬运任务
                                    dt_agvtask agvtask = new dt_agvtask();
                                    agvtask.agv_id = Guid.NewGuid();
                                    agvtask.agv_tasknum = "KH-" + IdenxManager.GetTaskNo();
                                    agvtask.agv_fromaddress = location_37.upper_code;
                                    agvtask.agv_toaddress = location_37_cp.upper_code;
                                    agvtask.agv_code = "负极AGV调度";
                                    agvtask.agv_remark = "负极箔材库搬运(37)";
                                    agvtask.agv_taskstate = AGVTaskStateEnum.Create.ToString();
                                    agvtask.agv_tasktype = AGVTaskTypeEnum.TaskType_Outbound.ToString();
                                    agvtask.agv_worktype = 1;//工作类型
                                    agvtask.agv_materielid = "";
                                    agvtask.agv_qty = 1;
                                    agvtask.agv_createtime = DateTime.Now;
                                    agvtask.agv_grade = 0;//任务优先级
                                    agvtask.agv_userid = "WCS";
                                    agvtask.agv_barcode = "";
 
                                    location_37_cp.update_time = DateTime.Now;
                                    location_37_cp.task = 1;
                                    //location_37_cp.logic_row = "TSJXL-BCK";
                                    var entry = locRepository.DbContext.ChangeTracker.Entries<base_ware_location>().FirstOrDefault();
                                    if (entry != null)
                                    {
                                        entry.State = EntityState.Detached;
                                    }
                                    int end = locRepository.Update(location_37_cp, d => new { d.task, d.update_time }, true);
 
                                    location_37.update_time = DateTime.Now;
                                    location_37.task = 1;
                                    var entrys = locRepository.DbContext.ChangeTracker.Entries<base_ware_location>().FirstOrDefault();
                                    if (entrys != null)
                                    {
                                        entrys.State = EntityState.Detached;
                                    }
                                    int begin = locRepository.Update(location_37, d => new { d.task, d.update_time }, true);
                                    if (begin == 1 && end == 1)
                                    {
                                        agvRepository.Add(agvtask, true);
                                    }
                                }
                            }
 
 
                        }
                    }
                    catch (Exception ex)
                    {
                        WriteLog.GetLog().Write($"负极泊材:{DateTime.Now} --------------{ex}", $"负极泊材调度");
                    }
                    finally
                    {
 
                        Interlocked.Exchange(ref _readFBCKSignalsoZBCK, 0);
                    }
                });
                
            }
        }
 
    }
}