qinchulong
2025-03-29 039a4a5433e7f80adc88b491b549e5d9486e4f9a
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using WIDESEA_Common;
using WIDESEA_Common.Tools;
using WIDESEA_Core.EFDbContext;
using WIDESEA_Core.Utilities;
using WIDESEA_Entity.DomainModels;
using WIDESEA_Services;
using WIDESEA_Services.IRepositories;
using WIDESEA_Services.Repositories;
using WIDESEA_Services.Services;
using WIDESEA_WCS.WCSClient;
 
namespace WIDESEA_WCS.Jobs
{
    public partial class EquipmentExecutor : SchedulerExecuteBase
    {
        private static int _readJROutBindSignalso = 0;
        /// <summary>
        /// 拆包站逻辑流程
        /// </summary>
        /// <param name="client"></param>
        /// <returns></returns>
        public static void JROutBind()
        {
            if (Interlocked.Exchange(ref _readJROutBindSignalso, 1) == 0)
            {
                try
                {
                    VOLContext Context = new VOLContext();
                    IJROutBindRepository jrRepository = new JROutBindRepository(Context);
                    Idt_agvtaskRepository agvRepository = new dt_agvtaskRepository(Context);
                    var task = agvRepository.Find(v => v.agv_toaddress.Contains("JR") && v.agv_taskstate == "WaitStockOut");
                    if (task != null)
                    {
                        var bind = jrRepository.Find(f => f.sum != 0);
                        if (bind != null)
                        {
                            for (int b = 0; b < bind.Count(); b++)
                            {
                                var tasks = agvRepository.Find(v => v.agv_materielid == bind[b].materialtype && v.agv_toaddress.Contains(bind[b].barcode.Substring(0, 2)) && v.agv_toaddress.Contains("JR") && v.agv_taskstate == "WaitStockOut");
                                if (tasks.Count() > 0)
                                {
                                    if (tasks.Count() >= bind[b].sum)
                                    {
                                        for (int i = 0; i < bind[b].sum; i++)
                                        {
                                            tasks[i].agv_fromaddress = bind[b].Devid;
                                            tasks[i].agv_taskstate = "Create";
                                            if (string.IsNullOrEmpty(bind[b].barcodes))
                                            {
                                                tasks[i].agv_materbarcode = bind[b].barcode;
                                            }
                                            else
                                            {
                                                tasks[i].agv_materbarcode = bind[b].barcodes.Split(',')[b];
                                            }
                                            #region
                                            //if (bind[b].Devid == "ZJXL-FBT001")
                                            //{
                                            //          if (BarcodesData.barcodes1.Count() == 0)
                                            //    {
                                            //        tasks[i].agv_materbarcode = bind[b].barcode;
                                            //    }
                                            //    else
                                            //    {
                                            //        tasks[i].agv_materbarcode = BarcodesData.barcodes1[b];
                                            //    }
                                            //}
                                            //else if (bind[b].Devid == "ZJXL-FBT002")
                                            //{
                                            //    if (BarcodesData.barcodes2.Count() == 0)
                                            //    {
                                            //        tasks[i].agv_materbarcode = bind[b].barcode;
                                            //    }
                                            //    else
                                            //    {
                                            //        tasks[i].agv_materbarcode = BarcodesData.barcodes2[b];
                                            //    }
                                            //}
                                            //else if (bind[b].Devid == "FJXL-FBT001")
                                            //{
                                            //    if (BarcodesData.barcodes3.Count() == 0)
                                            //    {
                                            //        tasks[i].agv_materbarcode = bind[b].barcode;
                                            //    }
                                            //    else
                                            //    {
                                            //        tasks[i].agv_materbarcode = BarcodesData.barcodes3[b];
                                            //    }
                                            //}
                                            //else if (bind[b].Devid == "FJXL-FBT002")
                                            //{
                                            //    if (BarcodesData.barcodes4.Count() == 0)
                                            //    {
                                            //        tasks[i].agv_materbarcode = bind[b].barcode;
                                            //    }
                                            //    else
                                            //    {
                                            //        tasks[i].agv_materbarcode = BarcodesData.barcodes4[b];
                                            //    }
                                            //}
                                            #endregion
                                            tasks[i].agv_materielid = bind[b].materialtype;
                                            if (i>0)
                                            {
                                                int size = int.Parse(tasks[i].size);
                                                //总宽度
                                                int zwigth = bind[b].sum * size;
                                                //已用宽度
                                                int nwigth = size * i;
                                                //剩余宽度
                                                int newwigth = zwigth - nwigth;
                                                tasks[i].JRunm = bind[b].sum - 1 + ";" + newwigth;
                                            }
 
                                            if (i == bind[b].sum - 1) { tasks[i].agv_remark = "true"; tasks[i].agv_qty = tasks.Count(); }
                                            agvRepository.Update(tasks[i], true);
                                        }
                                        bind[b].barcode = "";
                                        bind[b].materialtype = "";
                                        bind[b].sum = 0;
                                        bind[b].taskid = "";
                                        bind[b].barcodes = "";
                                        jrRepository.Update(bind[b], true);
                                        #region
                                        //if (bind[b].Devid == "ZJXL-FBT001")
                                        //{
                                        //   BarcodesData.barcodes1=null;
                                        //}
                                        //else if (bind[b].Devid == "ZJXL-FBT002")
                                        //{
                                        //    BarcodesData.barcodes2= null;
                                        //}
                                        //else if (bind[b].Devid == "FJXL-FBT001")
                                        //{
                                        //    BarcodesData.barcodes3 = null;
                                        //}
                                        //else if (bind[b].Devid == "FJXL-FBT002")
                                        //{
                                        //    BarcodesData.barcodes4= null;
                                        //}
                                        #endregion
                                    }
                                    else
                                    {
                                        for (int i = 0; i < tasks.Count(); i++)
                                        {
                                            tasks[i].agv_fromaddress = bind[b].Devid;
                                            tasks[i].agv_taskstate = "Create";
                                            if (string.IsNullOrEmpty( bind[b].barcodes))
                                            {
                                                tasks[i].agv_materbarcode = bind[b].barcode;
                                            }
                                            else
                                            {
                                                tasks[i].agv_materbarcode = bind[b].barcodes.Split(',')[b];
                                            }
                                            #region
                                            //if (bind[b].Devid == "ZJXL-FBT001")
                                            //{
                                            //    if (BarcodesData.barcodes1.Count() == 0)
                                            //    {
                                            //        tasks[i].agv_materbarcode = bind[b].barcode;
                                            //    }
                                            //    else
                                            //    {
                                            //        tasks[i].agv_materbarcode = BarcodesData.barcodes1[b];
                                            //    }
                                            //}
                                            //else if (bind[b].Devid == "ZJXL-FBT002")
                                            //{
                                            //    if (BarcodesData.barcodes2.Count() == 0)
                                            //    {
                                            //        tasks[i].agv_materbarcode = bind[b].barcode;
                                            //    }
                                            //    else
                                            //    {
                                            //        tasks[i].agv_materbarcode = BarcodesData.barcodes2[b];
                                            //    }
                                            //}
                                            //else if (bind[b].Devid == "FJXL-FBT001")
                                            //{
                                            //    if (BarcodesData.barcodes3.Count() == 0)
                                            //    {
                                            //        tasks[i].agv_materbarcode = bind[b].barcode;
                                            //    }
                                            //    else
                                            //    {
                                            //        tasks[i].agv_materbarcode = BarcodesData.barcodes3[b];
                                            //    }
                                            //}
                                            //else if (bind[b].Devid == "FJXL-FBT002")
                                            //{
                                            //    if (BarcodesData.barcodes4.Count() == 0)
                                            //    {
                                            //        tasks[i].agv_materbarcode = bind[b].barcode;
                                            //    }
                                            //    else
                                            //    {
                                            //        tasks[i].agv_materbarcode = BarcodesData.barcodes4[b];
                                            //    }
                                            //}
                                            #endregion
 
                                            if (i>0)
                                            {
                                                int size = int.Parse(tasks[i].size);
                                                //总宽度
                                                int zwigth = bind[b].sum * size;
                                                //已用宽度
                                                int nwigth = size * i;
                                                //剩余宽度
                                                int newwigth = zwigth - nwigth;
                                                tasks[i].JRunm = bind[b].sum - 1 + ";" + newwigth;
                                            }
 
                                            tasks[i].agv_materielid = bind[b].materialtype;
                                            if (i == tasks.Count() - 1) { tasks[i].agv_remark = "true"; tasks[i].agv_qty = tasks.Count(); }
                                            agvRepository.Update(tasks[i], true);
                                        }
                                        bind[b].barcode = "";
                                        bind[b].materialtype = "";
                                        bind[b].sum = 0;
                                        bind[b].taskid = "";
                                        bind[b].barcodes = "";
                                        jrRepository.Update(bind[b], true);
                                        #region
                                      //  List<string> newbarcodes = null;
                                        //if (bind[b].Devid == "ZJXL-FBT001")
                                        //{
                                        //    for (int j = tasks.Count(); j < BarcodesData.barcodes1.Count(); j++)
                                        //    {
                                        //        newbarcodes.Add(BarcodesData.barcodes1[j]);
                                        //        WriteLog.Info("剩余卷绕绑定条码").Write(bind[b].Devid+"卷绕绑定条码:" + BarcodesData.barcodes1[j] + DateTime.Now, "剩余卷绕绑定条码");
                                        //    }
                                        //    BarcodesData.barcodes1 = newbarcodes;
                                        //}
                                        //else if (bind[b].Devid == "ZJXL-FBT002")
                                        //{
                                        //    for (int j = tasks.Count(); j < BarcodesData.barcodes2.Count(); j++)
                                        //    {
                                        //        newbarcodes.Add(BarcodesData.barcodes2[j]);
                                        //        WriteLog.Info("剩余卷绕绑定条码").Write(bind[b].Devid + "卷绕绑定条码:" + BarcodesData.barcodes1[j] + DateTime.Now, "剩余卷绕绑定条码");
                                        //    }
                                        //    BarcodesData.barcodes2 = newbarcodes;
                                        //}
                                        //else if (bind[b].Devid == "FJXL-FBT001")
                                        //{
                                        //    for (int j = tasks.Count(); j < BarcodesData.barcodes3.Count(); j++)
                                        //    {
                                        //        newbarcodes.Add(BarcodesData.barcodes3[j]);
                                        //        WriteLog.Info("剩余卷绕绑定条码").Write(bind[b].Devid + "卷绕绑定条码:" + BarcodesData.barcodes1[j] + DateTime.Now, "剩余卷绕绑定条码");
                                        //    }
                                        //    BarcodesData.barcodes3 = newbarcodes;
                                        //}
                                        //else if (bind[b].Devid == "FJXL-FBT002")
                                        //{
                                        //    for (int j = tasks.Count(); j < BarcodesData.barcodes4.Count(); j++)
                                        //    {
                                        //        newbarcodes.Add(BarcodesData.barcodes4[j]);
                                        //        WriteLog.Info("剩余卷绕绑定条码").Write(bind[b].Devid + "卷绕绑定条码:" + BarcodesData.barcodes1[j] + DateTime.Now, "剩余卷绕绑定条码");
                                        //    }
                                        //    BarcodesData.barcodes4 = newbarcodes;
                                        //}
                                        #endregion
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception)
                {
 
                }
                finally
                {
                    Interlocked.Exchange(ref _readJROutBindSignalso, 0);
                }
            }
        }
    }
}