wu
2024-11-19 b092806a662b99310cdb050292de2721ba06acd9
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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
package com.example.springboot.service;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import com.example.springboot.common.Result;
import com.example.springboot.component.PLCAutoMes;
import com.example.springboot.component.Plchome;
import com.example.springboot.component.S7control;
import com.example.springboot.entity.Flowcard;
import com.example.springboot.entity.GlassInfo;
import com.example.springboot.entity.MeasureSetting;
import com.example.springboot.entity.Queue;
import com.example.springboot.entity.StorageCage;
import com.example.springboot.entity.StorageTask;
import com.example.springboot.entity.device.PlcParameterObject;
import com.example.springboot.mapper.AlbaniaMapper;
import com.example.springboot.mapper.GlassInfoMapper;
import com.example.springboot.mapper.HomeMapper;
import com.example.springboot.mapper.QueueMapper;
import com.fasterxml.jackson.databind.ObjectMapper;
 
@Service
public class StorageCageService {
    @Autowired
    private HomeMapper homeMapper;
 
    @Autowired
    private OutSliceServive outSliceServive;
 
    @Autowired
    private QueueMapper QueueMapper;
 
    @Autowired
    private SpianService spianService;
    @Autowired
    private AlbaniaMapper albaniaMapper;
    @Autowired
    private GlassInfoMapper glassInfoMapper;
 
    public void EndTask(int types) {
        String A01glassid1 = spianService.queGlassid("DB103.128", 14).toString();
        String A01glassid2 = spianService.queGlassid("DB103.142", 14).toString();
        String A02glassid1 = spianService.queGlassid("DB103.156", 14).toString();
        String B01glassid = spianService.queGlassid("DB103.184", 14).toString();
        String B02glassid = spianService.queGlassid("DB103.212", 14).toString();
        List<Short> DeviceList = S7control.getinstance().ReadWord("DB103.0", 10);
        if (types == 0) {// 终止进片任务
            List<StorageTask> cageList = homeMapper.SelectTaskByState(types);
            for (StorageTask storageTask : cageList) {
                // 判断出片任务位置并清除对应玻璃id
                if ((storageTask.getGlassId().equals(A01glassid1) || storageTask.getGlassId().equals(A01glassid2))
                        && DeviceList.get(4) == 0) {
                    outSliceServive.StopTask(storageTask.getGlassId(), types);
                    ClearGlassId("DB101.10.0");
                }
                if (storageTask.getGlassId().equals(B01glassid) && DeviceList.get(2) == 0) {
                    outSliceServive.StopTask(storageTask.getGlassId(), types);
                    ClearGlassId("DB101.10.2");
                }
                if (storageTask.getGlassId().equals(B02glassid) && DeviceList.get(3) == 0) {
                    ClearGlassId("DB101.10.3");
                    outSliceServive.StopTask(storageTask.getGlassId(), types);
                }
            }
            // 发送终止进片任务信号
        } else {// 终止出片任务
            List<StorageTask> cageLists = homeMapper.SelectTaskByState(types);
            List<StorageTask> cageList2 = homeMapper.SelectTaskByState(2);
            if (cageList2.size() > 0) {
                cageLists.add(cageList2.get(0));
            }
            for (StorageTask cageList : cageLists) {
                if (cageList.getTaskType().equals("1")) {
                    System.out.println(DeviceList.get(5));
                    if (cageList.getGlassId().equals(A02glassid1) && DeviceList.get(5) == 0) {
                        outSliceServive.StopTask(cageList.getGlassId(), types);
                        ClearGlassId("DB101.10.1");
                    }
                    if (cageList.getGlassId().equals(B01glassid) && DeviceList.get(2) == 0) {
                        outSliceServive.StopTask(cageList.getGlassId(), types);
                        ClearGlassId("DB101.10.2");
                    }
                    if (cageList.getGlassId().equals(B02glassid) && DeviceList.get(3) == 0) {
                        outSliceServive.StopTask(cageList.getGlassId(), types);
                        ClearGlassId("DB101.10.3");
                    }
                } else if (cageList.getTaskType().equals("2")) {
                    if (cageList.getGlassId().equals(A02glassid1) && DeviceList.get(5) == 0) {
                        outSliceServive.StopTask(cageList.getGlassId(), 2);
                        ClearGlassId("DB101.10.1");
                    }
                    if (cageList.getGlassId().equals(B01glassid) && DeviceList.get(2) == 0) {
                        outSliceServive.StopTask(cageList.getGlassId(), 2);
                        ClearGlassId("DB101.10.2");
                    }
                    if (cageList.getGlassId().equals(B02glassid) && DeviceList.get(3) == 0) {
                        outSliceServive.StopTask(cageList.getGlassId(), 2);
                        ClearGlassId("DB101.10.3");
                    }
                }
            }
 
            // List<StorageCage> storageCages = homeMapper.selectinout(3);
            // for (StorageCage storageCage : storageCages) {
            // List<StorageCage> storageCagess =
            // homeMapper.SelectStoragesGlassById(storageCage.getGlassId());
 
            // for (StorageCage storageCagez : storageCagess) {
 
            // if (storageCagez.getState().equals("2")) {// 调拨进片
            // outSliceServive.StopTask(storageCagez.getGlassId(), 0);
            // } else {// 出片
            // outSliceServive.StopTask(storageCagez.getGlassId(), types);
            // }
 
            // // 判断出片任务位置并清除对应玻璃id
            // if (storageCagez.getGlassId() == A02glassid1&&DeviceList.get(5)==0) {
            // outSliceServive.StopTask(storageCagez.getGlassId(), types);
            // ClearGlassId("DB101.10.1");
            // } else if (storageCagez.getGlassId() == B01glassid&&DeviceList.get(2)==0) {
            // outSliceServive.StopTask(storageCagez.getGlassId(), types);
            // ClearGlassId("DB101.10.2");
            // } else if (storageCagez.getGlassId() == B02glassid&&DeviceList.get(3)==0) {
            // ClearGlassId("DB101.10.3");
            // outSliceServive.StopTask(storageCagez.getGlassId(), types);
            // }
            // }
            // }
        }
    }
 
    // 手动完成任务
    public void UpdateTask(Integer types, Integer shelfrack, String glassid) {
        if (types == 0) {// 完成进片
            spianService.overtask(glassid);
        } else if (types == 1) {// 完成出片
            spianService.overtask(glassid);
        }
        // else if (types == 2) {// 终止进片任务
        // outSliceServive.StopTask(glassid, 0);
        // // 发送终止进片任务信号
        // } else {// 终止出片任务
        // outSliceServive.StopTask(glassid, 1);
        // }
    }
 
    // 判断任务类型后清除对应玻璃id
    public Result ClearGlassId(String position, String glassid) {
        Map<String, Object> map = new HashMap<>();
        if (S7control.getinstance().CheckConnected() == true) {
            // 判断进出还是出片任务
            Short type = homeMapper.SelectTaskByGlassId(glassid);
            if (type != null) {
                if (type == 0) {
                    // 进片
                    outSliceServive.StopTask(glassid, 0);
                } else if (type == 1) {
                    // 出片
                    outSliceServive.StopTask(glassid, 1);
                } else {
                    // 调拨
                    outSliceServive.StopTask(glassid, 0);
                    outSliceServive.StopTask(glassid, 1);
                }
            }
            ClearGlassId(position);
            map.put("message", "200");
        } else {
            map.put("message", "300");
        }
        return Result.success(map);
    }
 
    // 清除玻璃id
    public Result ClearGlassId(String position) {
        Map<String, Object> map = new HashMap<>();
        if (S7control.getinstance().CheckConnected() == true) {
            S7control.getinstance().WriteBit(position, true);
            try {
                TimeUnit.MILLISECONDS.sleep(300);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            S7control.getinstance().WriteBit(position, false);
            map.put("message", "200");
        } else {
            map.put("message", "300");
        }
        return Result.success(map);
    }
 
    public Result InsertQueueGlassId(Short id, Queue queue) {
        Map<String, Object> map = new HashMap<>();
 
        Short zhi = 200;
        short result = homeMapper.SelectStorageByGlassId(queue.getglassId());
        if (result > 0) {
            map.put("message", "300");
        } else {
            if (id == 1) {
                // 调用伍存储过程
                System.out.println("调用上片函数");
                zhi = spianService.selectAll(queue.getglassId());
                if (zhi == 200) {
                    homeMapper.InsertQueueGlassId(queue, id);
                }
            }
            map.put("message", zhi);
        }
        if (zhi != 200) {
            Plchome.FeedState = true;
        }
        return Result.success(map);
    }
 
    public List<StorageCage> SelectStorageCageInfo() {
        return homeMapper.SelectStorageCageInfo();
    }
 
    // 增加/减少理片笼玻璃数
    public Result UpdateStroageCageByCell(Integer cell, Integer num) {
        if (num == 0) {
            homeMapper.DeleteStroageCageByCell(cell);
        } else {
            homeMapper.updateStroageCageByCell(cell, num);
            homeMapper.UpdateStroageCageWidthByCell(cell);// 修改笼子宽度
        }
        Map<String, Object> map = new HashMap<>();
        map.put("message", "200");
        return Result.success(map);
    }
 
    // 指定格子出片
    public Result AddOutGlass(Integer cell, Integer glasstype) {
        GlassInfo glass = albaniaMapper.SelectGlassInfo(glasstype);
        Map<String, Object> map = new HashMap<>();
        if (glass != null) {
            albaniaMapper.AddFinishNumber(glass.getFlowcard(), glass.getMateid(), glass.getTier());
            UpdateStroageCageByCell(cell, -1);// 玻璃数量-1
            // 增加出片队列的任务
            albaniaMapper.InsertOutTask(1, 0, cell, 2001, glass.getGlassid(),
                    glass.getGlasstype(), glass.getFlowcard(), glass.getMateid(), glass.getTier());
            map.put("message", "200");
        } else {
            map.put("message", "300");
        }
        return Result.success(map);
    }
 
    // 查询进/出片任务
    public List<StorageTask> SelectStorageTask(int task_type) {
        List<StorageTask> storageTasks = new ArrayList<>();
        String loadrack = "0";
        if (task_type == 0) {
            storageTasks = homeMapper.SelectStorageTask(task_type);
        } else {
            storageTasks = homeMapper.SelectStorageTask(task_type);
        }
        for (StorageTask storageTask : storageTasks) {
            if (task_type == 0) {
                loadrack = storageTask.getLoadrack();
            } else {
                loadrack = storageTask.getShelfRack();
            }
            // storageTask.setstorageCage(homeMapper.SelectStorageByCell(loadrack));
            storageTask.setstorageCage(homeMapper.SelectStorageByCellGlass(storageTask.getId()));
 
        }
        return storageTasks;
    }
 
    // 查询出片队列
    public List<Map> SelectOutTask() {
        return homeMapper.SelectOutTask();
    }
 
    // 查询出片队列
    public List<Map> SelectOutLog() {
        return homeMapper.SelectOutLog();
    }
 
    // 查询进/出片任务
    public List<GlassInfo> SelectMeasure() {
        return homeMapper.SelectMeasure();
    }
 
    // 查询当前膜系厚度
    public MeasureSetting SelectSetting() {
        return homeMapper.SelectMeasureSetting();
    }
 
    // 查询测量宽高厚膜系
    public Map StorageCageForm() {
        return homeMapper.SelectMeasureWidthHeight();
    }
 
    // 手动结束任务
    public Result TerminateTask(int id) {
        for (int i = 1; i < 7; i++) {
            int taskcont = albaniaMapper.SelectTaskcount(); // 正在进行的任务数量
            System.out.println("任务数量:" + taskcont);
            if (taskcont == 0) {
                break;
            }
            StorageTask storageTask = homeMapper.SelectStorageTaskById();// 获取任务信息
            if (storageTask.getTaskType().equals("0")) {
                System.out.println("结束进片任务:" + storageTask.getId());
                homeMapper.FinishTask(storageTask.getId(), 2);// 完成任务
                homeMapper.DeletequeueByGlassid(storageTask.getGlasstype().toString());
                glassInfoMapper.updateGlassNumber(storageTask.getGlasstype());// 减少扫描次数
            } else {
                System.out.println("结束出片任务:" + storageTask.getId());
                homeMapper.FinishTask(storageTask.getId(), 2);// 完成任务
                UpdateStroageCageByCell(Integer.parseInt(storageTask.getShelfRack()), 1);// 玻璃数量+1
                homeMapper.OutGlassNo(storageTask.getGlasstype());// 还原出片完成数量
            }
        }
        Map<String, Object> map = new HashMap<>();
        return Result.success(map);
    }
 
    // 手动完成任务
    public Result FinishTask() {
        for (int i = 1; i < 7; i++) {
            int taskcont = albaniaMapper.SelectTaskcount(); // 正在进行的任务数量
            System.out.println("任务数量:" + taskcont);
            if (taskcont == 0) {
                break;
            }
            StorageTask storageTask = homeMapper.SelectStorageTaskById();// 获取任务信息
            if (storageTask.getTaskType().equals("0")) {
                System.out.println("完成进片任务:" + storageTask.getId());
                homeMapper.FinishTask(storageTask.getId(), 1);// 完成任务
                UpdateStroageCageByCell(Integer.parseInt(storageTask.getLoadrack()), 1);// 玻璃数量+1
                homeMapper.DeletequeueByGlassid(storageTask.getGlasstype().toString());
            } else {
                System.out.println("完成出片任务:" + storageTask.getId());
                homeMapper.FinishTask(storageTask.getId(), 1);// 完成任务
                StorageCage storageCage = homeMapper.SelectStorageByCell(storageTask.getShelfRack());
                if (storageCage.getNumber() == null || storageCage.getNumber() == 0) {
                    UpdateStroageCageByCell(Integer.parseInt(storageTask.getShelfRack()), 0);// 清除格内信息
                }
                // homeMapper.AddGlassNo(storageTask.getFlowcard(), storageTask.getMateid(),
                // storageTask.geTier());// 添加出片完成数量
 
            }
        }
        Map<String, Object> map = new HashMap<>();
        map.put("message", "200");
        return Result.success(map);
    }
 
    // 自动完成任务
    public Result LoseTask() {
        for (int i = 1; i < 7; i++) {
            int taskcont = albaniaMapper.SelectTaskcount(); // 正在进行的任务数量
            System.out.println("任务数量:" + taskcont);
            if (taskcont == 0) {
                break;
            }
            StorageTask storageTask = homeMapper.SelectStorageTaskById();// 获取任务信息
            if (storageTask.getTaskType().equals("0")) {
                System.out.println("完成进片任务:" + storageTask.getId());
                homeMapper.FinishTask(storageTask.getId(), 1);// 完成任务
                UpdateStroageCageByCell(Integer.parseInt(storageTask.getLoadrack()), 1);// 玻璃数量+1
                homeMapper.DeletequeueByGlassid(storageTask.getGlasstype().toString());
            } else {
                System.out.println("完成出片任务:" + storageTask.getId());
                homeMapper.FinishTask(storageTask.getId(), 1);// 完成任务
                StorageCage storageCage = homeMapper.SelectStorageByCell(storageTask.getShelfRack());
                if (storageCage.getNumber() > 1) {
                    UpdateStroageCageByCell(Integer.parseInt(storageTask.getShelfRack()), -1);// 玻璃数量-1
                } else {
                    UpdateStroageCageByCell(Integer.parseInt(storageTask.getShelfRack()), 0);// 清除格内信息
                }
                homeMapper.AddGlassNo(storageTask.getFlowcard(), storageTask.getMateid(), storageTask.geTier());// 添加出片完成数量
 
            }
        }
        Map<String, Object> map = new HashMap<>();
        map.put("message", "200");
        return Result.success(map);
    }
 
    // 查询玻璃信息
    public Result SelectGlassInfo(String width, String height, String thickness, String films) {
        List<GlassInfo> glassInfoList = homeMapper.SelectGlassInfo(width, height, thickness, films);
        Map<String, Object> map = new HashMap<>();
        map.put("StorageCageAddInfo", glassInfoList);
        return Result.success(map);
    }
 
    // 添加玻璃到格子内
    public Result StorageCageAddGlass(String cell, GlassInfo glassInfo) {
        homeMapper.StorageCageAddGlass(cell, glassInfo);
        UpdateStroageCageByCell(Integer.parseInt(cell), 1);
        Map<String, Object> map = new HashMap<>();
        map.put("message", "200");
        return Result.success(map);
    }
 
    // 查询订单任务
    public List<Flowcard> SelectOrderTask() {
        List<Flowcard> OrderTask = homeMapper.SelectOrderTask();
        for (Flowcard flowcard : OrderTask) {
            flowcard.setglassinfo(homeMapper.SelectOrderView(flowcard.getFlowcard()));
        }
        return OrderTask;
    }
 
    // 开始出片
    public Result ClaimTasks(String flowcard, Integer state, Integer line) {
        int count = homeMapper.SelectTaskCount(flowcard, line);
        Map<String, Object> map = new HashMap<>();
        if (count == 0) {
            if (state == 1) {
                homeMapper.ClaimTasks(flowcard, 0, line);
            } else {
                homeMapper.ClaimTasks(flowcard, 1, line);
            }
            map.put("message", "200");
        } else {
            map.put("message", "300");
        }
 
        return Result.success(map);
    }
 
    // 任务模式修改
    public Result ModeChange(String flowcard, Integer method) {
        if (method == 1) {
            homeMapper.ModeChange(flowcard, 0);
        } else {
            homeMapper.ModeChange(flowcard, 1);
        }
        Map<String, Object> map = new HashMap<>();
        map.put("message", "200");
        return Result.success(map);
    }
 
    // 人工匹配修改测量信息
    public Result UpdateQueue(GlassInfo glassInfo) {
        // 删除数据
        Map<String, Object> map = new HashMap<>();
        QueueMapper.DeleteQueue();
        System.out.println("人工匹配ID:" + glassInfo.getMateid() + "膜系:" + glassInfo.getFilms());
        // int count = homeMapper.SelectQueue();
        // if (count > 0) {
            // homeMapper.UpdateQueue(glassInfo.getFlowcard(), glassInfo.getWidth(), glassInfo.getHeight(),
            //         glassInfo.getGlasstype(), glassInfo.getThickness(), glassInfo.getTier(), glassInfo.getMateid());
            homeMapper.AddQueue(glassInfo.getFlowcard(), glassInfo.getWidth(), glassInfo.getHeight(),
                    glassInfo.getGlasstype(), glassInfo.getThickness(), glassInfo.getTier(), glassInfo.getMateid());
            PlcParameterObject plcmes = PLCAutoMes.PlcMesObject;
            S7control.getinstance().WriteWord(plcmes.getPlcParameter("MESToGaStatus").getAddress(), (short) 1);
            map.put("message", "200");
        // } else {
        //     map.put("message", "300");
        // }
        return Result.success(map);
    }
 
    public List<StorageCage> SelectStorageCageByCage(int cage) {
        return homeMapper.SelectStorageCageByCage(cage);
    }
 
    // 人工拿走
    public Result ManualTake(String glassInfo) {
        // 读取DB105区文件
        PlcParameterObject plcmes = PLCAutoMes.PlcMesObject;
        // 移除
        S7control.getinstance().WriteWord(plcmes.getPlcParameter("MESToGaStatus").getAddress(), (short) 3);
        // 删除数据
        QueueMapper.DeleteErrorQueue();
 
        // plcmes.getPlcParameter("GaToMES").setValue("3");
        Map<String, Object> map = new HashMap<>();
        map.put("message", "200");
        return Result.success(map);
    }
 
    // 开始上片
    public Result StartChange(String flowcard, int orderstate) {
        homeMapper.StartChange(flowcard, orderstate);
        Map<String, Object> map = new HashMap<>();
        int state = homeMapper.selectStartChange(flowcard);
        map.put("message", "200");
        return Result.success(map);
    }
 
    // 开始/暂停出片队列
    public Result UpdateOutTask(Integer id, Integer state) {
        homeMapper.UpdateOutTask(id, state);
        Map<String, Object> map = new HashMap<>();
        map.put("message", "200");
        return Result.success(map);
    }
 
    // 删除出片队列
    public Result DeleteOutTask(Integer id) {
        homeMapper.DeleteOutTask(id);
        Map<String, Object> map = new HashMap<>();
        map.put("message", "200");
        return Result.success(map);
    }
 
    // 删除工程
    public Result deleteTasks(Map num) {
        String flowcard = (String) num.get("num");
        int aa = homeMapper.deleteFlowcard(flowcard.trim());
        homeMapper.deleteGlassinfo(flowcard.trim());
        System.out.println(flowcard);
        Map<String, Object> map = new HashMap<>();
        map.put("message", flowcard.trim());
        return Result.success(map);
    }
 
    // 保存测量设置
    public Result SaveMeasure(String films, Integer thickness) {
        int Measure = homeMapper.SaveMeasure(films, thickness);
        Map<String, Object> map = new HashMap<>();
        map.put("message", Measure);
        return Result.success(map);
    }
 
    // 重新测量
    public Result AnewMeasure(String glassInfo) {
        // 读取DB105区文件
        PlcParameterObject plcmes = PLCAutoMes.PlcMesObject;
        // 重新测量
        S7control.getinstance().WriteWord(plcmes.getPlcParameter("MESToGaStatus").getAddress(), (short) 2);
        // 删除数据
        QueueMapper.DeleteErrorQueue();
        // plcmes.getPlcParameter("GaToMES").setValue("2");
        Map<String, Object> map = new HashMap<>();
        map.put("message", "200");
        return Result.success(map);
    }
 
    // 添加小片信息
    public Result AddGlassinfo(List<Map> IportDataStr) {
 
        // 筛选处理数据 1.去除无用数据 2.计算配片ID 3.计算ID 4. 计算总层数
        List<Map> TypeDatas = homeMapper.SelectType();
        Map<String, String> TypeData = new HashMap<String, String>();// 得到处理完后所有的类型
        Map<String, Integer> groupby = new HashMap<String, Integer>(); // 得到处理完后所有总层数;
        Map<String, Integer> OrderFinishedProduct = new HashMap<String, Integer>(); // 得到处理完后订单成品总数量;
        // "order zong 0 1 10 2 10"
        List<Map> RemoveErrorData = IportDataStr.stream()
                .filter(item -> (item.get("order") != null && item.get("tier") != null
                        &&
                        item.get("films") != null && item.get("base") != null && item.get("height") != null
                        && item.get("thickness") != null && item.get("quantity") != null
                        && item.get("matching") != null))
                .collect(Collectors.toList());
 
        TypeDatas.forEach(item -> {
            TypeData.put(item.get("type").toString(), item.get("glasstype").toString());
        });
 
        RemoveErrorData.forEach(item -> {
            String key = item.get("order").toString() + "_" + item.get("matching").toString();
            String keyCount = item.get("order").toString() + "_" + item.get("matching").toString() + "_"
                    + item.get("tier").toString();
            String keyCountSum = item.get("order").toString() + "_" + item.get("matching").toString() + "_Sum";// 订单总数
            if (OrderFinishedProduct.get(keyCount) != null) {
                Integer count = OrderFinishedProduct.get(keyCount) + 1;
                Integer sumcount = OrderFinishedProduct.get(keyCountSum)
                        + Integer.parseInt(item.get("quantity").toString());
                OrderFinishedProduct.put(keyCount, count);
                OrderFinishedProduct.put(keyCountSum, sumcount);
            } else if (OrderFinishedProduct.get(keyCount) == null && groupby.get(key) == null) {
                OrderFinishedProduct.put(keyCount, 1);
                OrderFinishedProduct.put(keyCountSum, Integer.parseInt(item.get("quantity").toString()));
            }
            if (groupby.get(key) != null) {
                Integer Tiers = groupby.get(key) + 1;
                groupby.put(key, Tiers);
            } else {
                groupby.put(key, 1);
            }
        });
 
        System.out.println(RemoveErrorData.size());
        // 处理完成 添加数据库
        int count = 1;
        for (Map map : RemoveErrorData) {
            String key = map.get("base").toString() + "_" + map.get("height").toString() + "_"
                    + map.get("thickness").toString() + "_" + map.get("films").toString() + "_"
                    + map.get("order").toString() + "_" + map.get("matching").toString();
 
            String tierkey = map.get("order").toString() + "_" + map.get("matching").toString();
 
            String value = TypeData.get(key);
            Integer glasstype;
            System.out.println(key + ":" + TypeData.get(key));
            if (TypeData.get(key) == null) {
 
                glasstype = homeMapper.SelectMaxTypes(key);
                if (glasstype == null) {
                    glasstype = homeMapper.SelectMaxType();
                }
                if (glasstype == null) {
                    glasstype = 1;
                }
            } else {
                glasstype = Integer.valueOf(value);
            }
            //
            homeMapper.AddGlassinfo(map.get("order").toString(), glasstype,
                    Integer.parseInt(map.get("matching").toString()) // 需要计算 配片ID
                    , map.get("order").toString() + "-" + count + "" // 需要计算 玻璃ID
                    , Integer.parseInt(map.get("tier").toString()), map.get("films").toString(),
                    Double.parseDouble(map.get("base").toString()), Double.parseDouble(map.get("height").toString()),
                    Double.parseDouble(map.get("thickness").toString()),
                    Integer.parseInt(map.get("quantity").toString()), groupby.get(tierkey),
                    map.get("Customer").toString());// 需要计算总层数
            // 订单内总层数
            homeMapper.InsertFlowcard(map.get("order").toString(), OrderFinishedProduct.get(tierkey + "_Sum"),
                    map.get("Customer").toString());
            count++;
        }
        Map<String, Object> ResultCode = new HashMap<>();
        ResultCode.put("message", "200");
        return Result.success(ResultCode);
    }
 
}