严智鑫
2025-11-13 945bc394f40d8af1072a53da9a94f24207124e6d
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
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
package com.northglass.service.identifymachine;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import javax.swing.text.html.HTML;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
 
import com.northglass.constants.StateConstants.ConnectState;
import com.northglass.constants.StateConstants.CountMachineTaskState;
import com.northglass.constants.StateConstants.GlassArrangeState;
import com.northglass.constants.StateConstants.GlassState;
import com.northglass.constants.StateConstants.sendGlassState;
import com.northglass.entity.CountMachineTask;
import com.northglass.entity.Glass;
import com.northglass.entity.GlassOrder;
import com.northglass.entity.GlassTest;
import com.northglass.entity.IdentifyFloor;
import com.northglass.entity.IdentifyMachine;
import com.northglass.entity.IdentifyPattern;
import com.northglass.entity.OptPattern;
import com.northglass.entity.PreprocessingGlass;
import com.northglass.entity.RawPackageTxt;
import com.northglass.entity.ShelfStatu;
import com.northglass.entity.SingalGlass;
import com.northglass.entity.TestOut;
import com.northglass.entity.TougheningGlass;
import com.northglass.listener.IdentifyMachineClientListener;
import com.northglass.repository.CountMachineDao;
import com.northglass.repository.CountMachineTaskDao;
import com.northglass.repository.GlassDao;
import com.northglass.repository.GlassOrderDao;
import com.northglass.repository.GlassTestDao;
import com.northglass.repository.IdentifyFloorDao;
import com.northglass.repository.IdentifyMachineDao;
import com.northglass.repository.IdentifyPatternDao;
import com.northglass.repository.PreprocessingGlassDao;
import com.northglass.repository.RawPackageTxtDao;
import com.northglass.repository.ShelfStatuDao;
import com.northglass.repository.SingalGlassDao;
import com.northglass.repository.TestOutDao;
import com.northglass.repository.TougheningGlassDao;
import com.northglass.service.message.IdentifyMachineMessageProcessor;
 
@Component
@Transactional
public class IdentifyMachineService {
 
    @Autowired
    private TestOutDao testOutDao;
 
    @Autowired
    private IdentifyMachineDao identifyMachineDao;
 
    @Autowired
    private IdentifyFloorDao identifyFloorDao;
 
    @Autowired
    private IdentifyMachineMessageProcessor processor;
 
    @Autowired
    private CountMachineTaskDao countMachineTaskDao;
 
    @Autowired
    private CountMachineDao countMachineDao;
 
    @Autowired
    private GlassDao glassDao;
 
    @Autowired
    private SingalGlassDao singalGlassDao;
 
    @Autowired
    private PreprocessingGlassDao preprocessingGlassDao;
 
    @Autowired
    private IdentifyPatternDao identifyPatternDao;
 
    @Autowired
    private RawPackageTxtDao rawPackageTxtDao;
    
    @Autowired
    private TougheningGlassDao tougheningGlassDao;
    
    @Autowired
    private ShelfStatuDao shelfStatuDao;
    
    @Autowired
    private GlassTestDao glassTestDao;
    
    @Autowired
    private GlassOrderDao glassOrderDao;
 
    private static final Logger LOGGER = LoggerFactory.getLogger(IdentifyMachineService.class);
 
    public void connect() {
        LOGGER.debug("> Start connect");
 
        List<IdentifyMachine> identifyMachineList = identifyMachineDao.findAll();
 
        // 若监听线程为空,则新建监听线程
        for (IdentifyMachine identifyMachine : identifyMachineList) {
            if (identifyMachine.getServerConnection().getThread() == null) {
                LOGGER.debug("创建新的测量台【" + identifyMachine.getNumber() + "】监听线程!");
                Thread thread = new Thread(new IdentifyMachineClientListener(identifyMachine, this));
                thread.start();
 
                setConnectState(identifyMachine, ConnectState.CONNECTING);
                identifyMachine.getServerConnection().setThread(thread);
            }
        }
 
        LOGGER.debug("> End connect");
    }
 
    public void setConnectState(IdentifyMachine identifyMachine, String connecting) {
        identifyMachine.setConnectState(connecting);
        identifyMachine.setModifyTime(new Date());
        identifyMachineDao.save(identifyMachine);
    }
 
    public String processMessage(String message, IdentifyMachine machineClient) {
        return processor.generateReturnMessage(message, machineClient);
    }
 
    public void getendtime(String name) {
        List<TestOut> testOuts = testOutDao.findByName(name);
        if (testOuts.size() > 0) {
            TestOut testOut = testOuts.get(testOuts.size() - 1);
            if (testOut.getEnd_time() != null && !testOut.getEnd_time().equals("")) {
                TestOut test = new TestOut(name);
                test.setStart_time(new Date());
                testOutDao.save(test);
            } else {
                testOut.setEnd_time(new Date());
                testOutDao.save(testOut);
            }
        } else {
            TestOut testOut = new TestOut(name + "start");
            testOut.setStart_time(new Date());
            testOutDao.save(testOut);
        }
    }
 
    public void getright(String name) {
        TestOut testOut = new TestOut(name);
        testOut.setStart_time(new Date());
        testOutDao.save(testOut);
    }
    //findToIdentifyGlass
    public List<Glass> getGlass() {
        List<Glass> glass=new ArrayList<Glass>();
        glass=glassDao.findToIdentifyGlass();
        return glass;
    }
    public Glass getOnlyGlass(IdentifyMachine machineClient, List<Glass> glasses, double length, double width) {
        IdentifyFloor idf = identifyFloorDao.findOne(1L);
        List<Glass> glasses2 = new ArrayList<Glass>();
        // 产生匹配详情
        PreprocessingGlass preprocessingGlass = preprocessingGlassDao.findOne(1L);
        preprocessingGlass.setActualLength(length);
        preprocessingGlass.setActualWidth(width);
        preprocessingGlass.setStatu("匹配失败");
        if (glasses.size() > 0) {
            for (Glass glass : glasses) {
                //误差范围内的匹配
                if ((glass.getStartlength() - idf.getCeiling()< length
                        && glass.getStartlength() + idf.getFloor()  > length
                        && glass.getStartwidth() - idf.getCeiling() < width
                        && glass.getStartwidth() + idf.getFloor() > width)
                        || (glass.getStartlength() - idf.getCeiling() < width
                                && glass.getStartlength() + idf.getFloor() > width
                                && glass.getStartwidth() - idf.getCeiling() < length
                                && glass.getStartwidth() + idf.getFloor() > length)) {
                    glasses2.add(glass);
                    break;
                }
            }
            if (glasses2.size() == 1) {
                Glass g = glasses2.get(0);
                TougheningGlass tougheningGlass = new TougheningGlass();
                tougheningGlass.setActualLength(length);
                tougheningGlass.setActualWidth(width);
                tougheningGlass.setGlass(g);
                tougheningGlass.setState("等待中");
                
                GlassTest test = new GlassTest(length,width,new Date());
                test.setLength(g.getStartlength());
                test.setWidth(g.getStartwidth());
                
                preprocessingGlass.setLength(g.getStartlength());
                preprocessingGlass.setWidth(g.getStartwidth());
                preprocessingGlass.setThickness(g.getThickness());
                preprocessingGlass.setTxtname(g.getRawPackageTxt().getTxt_name());
                preprocessingGlass.setStatu("匹配成功");
                preprocessingGlass.setColor(g.getColor());
                preprocessingGlass.setGlass(g);
 
                //此类玻璃   完成达到完成片数    修改状态为已完成   修改 完成片数+1
                if (g.getPieces() == g.getCompletePieces()+1) {
                    g.setState(GlassState.TO_COMPLETE);
                }
                g.setCompletePieces(g.getCompletePieces() + 1);
                glassDao.save(g);
                glassTestDao.save(test);
                tougheningGlassDao.save(tougheningGlass);
                preprocessingGlassDao.save(preprocessingGlass);
                return g;
            }
        }else {
            preprocessingGlass.setLength(0);
            preprocessingGlass.setWidth(0);
            preprocessingGlass.setThickness(0);
            preprocessingGlass.setTxtname("");
            preprocessingGlass.setStatu("无玻璃信息对比");
            preprocessingGlassDao.save(preprocessingGlass);
            LOGGER.debug("没有玻璃信息对比,请查明原因");
            return null;
        }
        return null;
    }
 
    /**
     * 
     * 功能:测量台用于对比数据(弃用)
     * 
     **/
    public SingalGlass getOnlySingalGlass(IdentifyMachine machineClient, List<SingalGlass> glasses, double length,
            double width) {
        IdentifyFloor idf = identifyFloorDao.findOne(1L);
        List<SingalGlass> glasses2 = new ArrayList<SingalGlass>();
        for (SingalGlass glass : glasses) {
            if ((glass.getLength() - idf.getCeiling() + glass.getArrangePieces() < length
                    && glass.getLength() + idf.getFloor() + glass.getArrangePieces() > length
                    && glass.getWidth() - idf.getCeiling() + glass.getArrangePieces() < width
                    && glass.getWidth() + idf.getFloor() + glass.getArrangePieces() > width)
                    || (glass.getLength() - idf.getCeiling() + glass.getArrangePieces() < width
                            && glass.getLength() + idf.getFloor() + glass.getArrangePieces() > width
                            && glass.getWidth() - idf.getCeiling() + glass.getArrangePieces() < length
                            && glass.getWidth() + idf.getFloor() + glass.getArrangePieces() > length)) {
                // for (SingalGlass gla :glasses2) {
                // if
                // (!(glass.getLength()==gla.getLength()&&glass.getWidth()==gla.getWidth())||!(glass.getLength()==gla.getWidth()&&glass.getWidth()==gla.getLength()))
                // {
                glasses2.add(glass);
                // }
                // }
 
            }
        }
        if (glasses2.size() == 1) {
            SingalGlass g = glasses2.get(0);
            if (g.getLength() - idf.getCeiling() + g.getArrangePieces() < width
                    && g.getLength() + idf.getFloor() + g.getArrangePieces() > width
                    && g.getWidth() - idf.getCeiling() + g.getArrangePieces() < length
                    && g.getWidth() + idf.getFloor() + g.getArrangePieces() > length) {
                CountMachineTask task = new CountMachineTask();
                countMachineTaskDao.save(task);
            } else {
                CountMachineTask task = new CountMachineTask();
                countMachineTaskDao.save(task);
            }
            return glasses2.get(0);
        }
        return null;
    }
 
    public Glass gerMatchGlass(IdentifyMachine machineClient, RawPackageTxt rawPackageTxt, double length,
            double width) {
//        // IdentifyFloor idf = identifyFloorDao.findOne(1L);
//        List<Glass> glasses = glassDao.findByRaw(rawPackageTxt.getId());
//        if (glasses.size() > 0) {
//            return getOnlyGlass(machineClient, glasses, length, width);
//        } else {
//            // 把singalglass里面的数据精简放到glass里面去
//            List<Glass> glasses2 = singalToGlass(rawPackageTxt);
//            if (glasses2.size() > 0) {
//                return getOnlyGlass(machineClient, glasses2, length, width);
//            }
//        }
        return null;
    }
 
//    private List<Glass> singalToGlass(RawPackageTxt rawPackageTxt) {
//        // 得到singalglass数据
//        List<Glass> glasses = new ArrayList<Glass>();
//        List<SingalGlass> singalGlasses = singalGlassDao.findByRaw(rawPackageTxt.getId());
//        if (singalGlasses.size() > 0) {
//            for (SingalGlass singalGlass : singalGlasses) {
//                OptPattern optPattern = singalGlass.getOptPattern();
//                if (glasses.size() > 0) {
//                    for (int i = 0; i <= glasses.size() - 1; i++) {
//                        Glass glass = glasses.get(i);
//                        if ((glass.getWidth() == singalGlass.getWidth())
//                                && (glass.getLength() == singalGlass.getLength())
//                                && (glass.getApart_id().equals(singalGlass.getApart_id()))) {
//                            glass.setPieces(glass.getPieces() + optPattern.getPieces());
//                            glassDao.save(glass);
//                            break;
//                        }
//                        if (i == glasses.size() - 1) {
//                            Glass gl = new Glass(GlassArrangeState.MEASURE, 0, singalGlass.getLength(),
//                                    singalGlass.getWidth(), singalGlass.getThickness(), singalGlass.getColor(),
//                                    singalGlass.getCustomer(), GlassArrangeState.MEASURE, "", singalGlass.getApart_id(),
//                                    singalGlass.getManufacture_batch(),
//                                    singalGlass.getPieces() * optPattern.getPieces(), 0, 0,
//                                    singalGlass.getApplication(), singalGlass.getProduction(),
//                                    singalGlass.getFloor_number(), singalGlass.getOrder_number(),
//                                    singalGlass.getPiece_sign(), singalGlass.getRemark(), sendGlassState.NOTSEND,
//                                    sendGlassState.NOTSEND);
//                            gl.setRawPackageTxt(rawPackageTxt);
//                            gl.setStartlength(singalGlass.getStartlength());
//                            gl.setStartwidth(singalGlass.getStartwidth());
//                            glassDao.save(gl);
//                            glasses.add(gl);
//                            break;
//                        }
//
//                    }
//                } else {
//                    Glass glass = new Glass(GlassArrangeState.MEASURE, 0, singalGlass.getLength(),
//                            singalGlass.getWidth(), singalGlass.getThickness(), singalGlass.getColor(),
//                            singalGlass.getCustomer(), GlassArrangeState.MEASURE, "", singalGlass.getApart_id(),
//                            singalGlass.getManufacture_batch(), singalGlass.getPieces() * optPattern.getPieces(), 0, 0,
//                            singalGlass.getApplication(), singalGlass.getProduction(), singalGlass.getFloor_number(),
//                            singalGlass.getOrder_number(), singalGlass.getPiece_sign(), singalGlass.getRemark(),
//                            sendGlassState.NOTSEND, sendGlassState.NOTSEND);
//                    glass.setRawPackageTxt(rawPackageTxt);
//                    glass.setStartlength(singalGlass.getStartlength());
//                    glass.setStartwidth(singalGlass.getStartwidth());
//                    glassDao.save(glass);
//                    glasses.add(glass);
//                }
//            }
//        }
//        return glasses;
//    }
 
    public Map<String, Object> getCeliangManageData(String groups) {
 
        // Long machineId = Long.valueOf(groups);
        PreprocessingGlass preprocessingGlass = preprocessingGlassDao.findOne(1L);
        Map<String, Object> param = new HashMap<String, Object>();
 
        param.put("actuallength", preprocessingGlass.getActualLength());
        param.put("actualwidth", preprocessingGlass.getActualWidth());
        param.put("color", preprocessingGlass.getColor());
        param.put("txtname", preprocessingGlass.getTxtname());
        param.put("thickness", preprocessingGlass.getThickness());
        param.put("status", preprocessingGlass.getStatu());
        if (preprocessingGlass.getGlass() != null) {
            param.put("width", preprocessingGlass.getWidth());
            param.put("length", preprocessingGlass.getLength());
            param.put("glassid", preprocessingGlass.getGlass().getId());
        }
        if (preprocessingGlass.getStatu().equals("匹配失败") ||preprocessingGlass.getStatu().equals("多数据匹配")) {
            param.put("img", "quxiao.png");
        } else {
            param.put("img", "zhengque.png");
        }
        int totalPieces = 0;
        int completePieces = 0;
        if (preprocessingGlass.getRawPackageTxt()!=null) {
            List<Glass> glasses = glassDao.findByRaw(preprocessingGlass.getRawPackageTxt().getId());
            if (glasses.size()>0) {
                for (Glass glass : glasses) {
                    completePieces = completePieces + glass.getCompletePieces();
                    totalPieces = totalPieces + glass.getPieces();
                }
            }
        }
        
        param.put("totalPieces", totalPieces);
        param.put("completePieces", completePieces);
        param.put("leftPieces", totalPieces - completePieces);
        param.put("progress", ((double) completePieces / (double) totalPieces * 100) + "%");
 
        // 测量结果显示。
        // - 若找到匹配玻璃,则显示结果为匹配成功,不需要人工处理,自动执行送片;
        // - 若没有找到识别玻璃,则显示两个按钮
        // - 一个是重新匹配,允许用户校正并重新测量;
        // - 另一个是匹配失败,需要用户自己将玻璃移除,并确认;
        StringBuffer html = new StringBuffer();
        param.put("identifyResultHtml", html.toString());
 
        return param;
 
    }
 
    public IdentifyPattern getpatern(String groups) {
        LOGGER.debug("group:" + groups);
        return identifyPatternDao.findById(1L);
    }
 
    public IdentifyFloor getfloor(String groups) {
        LOGGER.debug("group:" + groups);
        return identifyFloorDao.findOne(1L);
    }
 
    public void modifyGlass(String txtid, String ids) {
        // 把原先的尺寸全部删除
        // 把新的尺寸都给算进去
        RawPackageTxt txt = rawPackageTxtDao.findByTxtName(ids);
        LOGGER.debug(txtid);
//        List<Glass> glasses = glassDao.findByRaw(Long.parseLong(txtid));
        PreprocessingGlass ga=preprocessingGlassDao.findOne(1L);
        ga.setGlass(null);
        preprocessingGlassDao.save(ga);
//        List<CountMachineTask> countMachineTaskes = countMachineTaskDao.findByRaw(txt.getId());
//        if (countMachineTaskes.size()>0) {
//            for (CountMachineTask ctask : countMachineTaskes) {
//                countMachineTaskDao.delete(ctask);
//            }
//        }
//        if (glasses.size() > 0) {
//            for (Glass glass : glasses) {
//                List<CountMachineTask> countMachineTaskes = countMachineTaskDao.findByGlass(glass.getId());
//                if (countMachineTaskes.size()>0) {
//                    for (CountMachineTask ctask : countMachineTaskes) {
//                        countMachineTaskDao.delete(ctask);
//                    }
//                }
//                glassDao.delete(glass);
//            }
//        }
        
    
        if (txt != null) {
//            singalToGlass(txt);
            // 修改identifyPattern
            IdentifyPattern pattern = identifyPatternDao.findOne(1L);
            pattern.setRawPackageTxt(txt);
        }
    }
 
    public String getbatch(String groups) {
        IdentifyPattern identifyPattern = identifyPatternDao.findById(1L);
        return identifyPattern.getRawPackageTxt().getTxt_name();
    }
/****
 * 
 * 
 * 功能:玻璃尺寸非常接近时,找出可对应的单号
 * 
 * 
 * 
 * **/
    public List<Glass> getglassList(String groups) {
//        IdentifyPattern identifyPattern = identifyPatternDao.findById(1L);
        PreprocessingGlass preprocessingGlass = preprocessingGlassDao.findOne(1L);
//        RawPackageTxt txt = identifyPattern.getRawPackageTxt();
        if (preprocessingGlass.getRawPackageTxt() ==null) {
            return null;
        }
        List<Glass> glasses = glassDao.findByRawAndState(preprocessingGlass.getRawPackageTxt().getId());
        IdentifyFloor idf = identifyFloorDao.findOne(1L);
        List<Glass> glasses2 = new ArrayList<Glass>();
        // 产生匹配详情
    
        double length = preprocessingGlass.getActualLength();
        double width = preprocessingGlass.getActualWidth();
        // 匹配对比
        if (preprocessingGlass.getStatu().equals("匹配失败")|| preprocessingGlass.getStatu().equals("多数据匹配")) {
            for (Glass glass : glasses) {
                if ((glass.getStartlength() - idf.getCeiling() < length
                        && glass.getStartlength() + idf.getFloor()> length
                        && glass.getStartwidth() - idf.getCeiling() < width
                        && glass.getStartwidth() + idf.getFloor() > width)
                        || (glass.getStartlength() - idf.getCeiling() < width
                                && glass.getStartlength() + idf.getFloor() > width
                                && glass.getStartwidth() - idf.getCeiling() < length
                                && glass.getStartwidth() + idf.getFloor() > length)) {
                    if (glasses2.size() > 0) {
                        for (Glass gla : glasses2) {
                            if (!(glass.getLength() == gla.getLength() && glass.getWidth() == gla.getWidth())
                                    || !(glass.getLength() == gla.getWidth() && glass.getWidth() == gla.getLength())) {
                                glasses2.add(glass);
                                break;
                            }
                        }
                    }else {
                        glasses2.add(glass);
                    }
                }
            }
        }
        return glasses2;
    }
    public void Deleteglalls(String groups, String glassid) {
        //破损
        PreprocessingGlass gs = preprocessingGlassDao.findOne(1L);
        if(gs.getFlag()==0){
            Glass glass=glassDao.findOne(Integer.valueOf(glassid).longValue());
            glass.setCompletePieces(glass.getCompletePieces()+1);
            glass.setDamagePieces(glass.getDamagePieces()+1);
            gs.setFlag(3);
            preprocessingGlassDao.save(gs);
        }
    }
    public void modify(String groups, String glassid) {
        PreprocessingGlass preprocessingGlass = preprocessingGlassDao.findOne(Long.parseLong(groups));
        //找出当前的玻璃,并修改指认
        if(preprocessingGlass.getFlag()==0){
            Glass glass = glassDao.findOne(Long.parseLong(glassid));
            preprocessingGlass.setTxtname(glass.getRawPackageTxt().getTxt_name());
            preprocessingGlass.setGlass(glass);
            preprocessingGlass.setStatu("匹配成功");
            preprocessingGlass.setFlag(1);
            preprocessingGlass.setLength(glass.getStartlength());
            preprocessingGlass.setWidth(glass.getStartwidth());
            preprocessingGlass.setColor(glass.getColor());
            preprocessingGlass.setThickness(glass.getThickness());
            
            GlassTest test = new GlassTest(glass.getLength(),glass.getWidth(),preprocessingGlass.getActualLength(),preprocessingGlass.getActualWidth(),new Date());
            test.setLength(glass.getLength());
            test.setWidth(glass.getWidth());
            
            TougheningGlass tougheningGlass = new TougheningGlass();
            tougheningGlass.setGlass(glass);    
            tougheningGlass.setActualLength(glass.getLength());
            tougheningGlass.setActualWidth(glass.getWidth());
            tougheningGlass.setState("等待中");
            if (glass.getPieces() == glass.getCompletePieces()+1) {
                glass.setState(GlassState.TO_COMPLETE);
            }
            glass.setCompletePieces(glass.getCompletePieces()+1);
            glassDao.save(glass);
            glassTestDao.save(test);
            tougheningGlassDao.save(tougheningGlass);
            preprocessingGlassDao.save(preprocessingGlass);
        }
        
    }
 
    public void modifyErrorRange(String groups, String floor, String ceiling) {
        IdentifyFloor identifyFloor = identifyFloorDao.findOne(1L);
        if (identifyFloor != null) {
            identifyFloor.setCeiling(Double.parseDouble(ceiling));
            identifyFloor.setFloor(Double.parseDouble(floor));
            identifyFloorDao.save(identifyFloor);
        }
    }
 
    public void pattern(String groups, String patterns) {
        IdentifyPattern pattern = identifyPatternDao.findOne(1L);
        LOGGER.debug("对应的id:"+pattern);
        if (patterns.equals("old")) {
            pattern.setPattern("切割匹配");
        }else if (patterns.equals("now")) {
            pattern.setPattern("不匹配");
        }else{
            pattern.setPattern("订单匹配");
        }
        identifyPatternDao.save(pattern);
    }
 
    public void deleteData() {
        
    }
 
    public void posun() {
        PreprocessingGlass preprocessingGlass = preprocessingGlassDao.findOne(1L);
        if (preprocessingGlass.getStatu().equals("匹配失败") ||preprocessingGlass.getStatu().equals("多数据匹配")) {
            preprocessingGlass.setFlag(2);
            preprocessingGlass.setStatu("匹配失败");
            preprocessingGlassDao.save(preprocessingGlass);
        }
    }
 
    public String selectData() {
        StringBuffer html = new StringBuffer();
        List<TougheningGlass> tougheningGlasses = tougheningGlassDao.findInWork();
        if (tougheningGlasses.size()>0) {
            for (TougheningGlass tougheningGlass:tougheningGlasses) {
                html.append("<td>").append(tougheningGlass.getActualLength());
                html.append("</td>");
            }
        }
        return html.toString();
    }
 
    public String damage() {
        StringBuffer html = new StringBuffer();
        RawPackageTxt txt = rawPackageTxtDao.findAcceptedByGroup("1");
        List<Glass> glasses = glassDao.findGlassByBatchs(txt.getTxt_name());
        if (glasses.size()>0) {
            for(Glass glass : glasses){
                html.append("<tr><td>").append(glass.getId()).append("</td>");
                html.append("<td>").append(glass.getManufacture_batch()).append("</td>");
                html.append("<td>").append(glass.getWidth()).append("</td>");
                html.append("<td>").append(glass.getLength()).append("</td>");
                html.append("<td>").append(glass.getThickness()).append("</td>");
                html.append("<td>").append(glass.getColor()).append("</td>");
                html.append("<td>").append(glass.getPieces()).append("</td>");
                html.append("<td>").append(glass.getCompletePieces()).append("</td>");
                html.append("<td>").append(glass.getDamagePieces()).append("</td>");
                html.append("<td><a class='btn btn-danger' onclick='print("+glass.getId()+")'> ").append("破损").append("</a></td>");
                html.append("</tr>");
            }
        }
        return html.toString();
    }
    
    public String review() {
        StringBuffer html = new StringBuffer();
        List<TougheningGlass> tougheningGlasses = tougheningGlassDao.findWaitingGlass();
        if (tougheningGlasses.size()>0) {
            for(TougheningGlass tougheningGlass : tougheningGlasses){
                Glass glass = tougheningGlass.getGlass();
                html.append("<tr><td>").append(glass.getId()).append("</td>");
                html.append("<td>").append(glass.getManufacture_batch()).append("</td>");
                html.append("<td>").append(glass.getWidth()).append("</td>");
                html.append("<td>").append(glass.getLength()).append("</td>");
                html.append("<td>").append(glass.getThickness()).append("</td>");
                html.append("<td>").append(glass.getColor()).append("</td>");
                html.append("<td>").append(glass.getPieces()).append("</td>");
                html.append("<td>").append(glass.getCompletePieces()).append("</td>");
                html.append("<td>").append(glass.getDamagePieces()).append("</td>");
                html.append("<td><a class='btn btn-danger' onclick='print("+tougheningGlass.getId()+")'> ").append("退回").append("</a></td>");
                html.append("</tr>");
            }
        }
        return html.toString();
    }
 
 
    public String checkEnd(String id) {
        Glass glass = glassDao.findOne(Long.parseLong(id));
        if (glass != null) {
            glass.setDamagePieces(glass.getDamagePieces()+1);
            if (glass.getCompletePieces()+glass.getDamagePieces() == glass.getPieces()) {
                glass.setState("已识别");
            }
            glassDao.save(glass);
            ps(glass);//玻璃破损
            return "ok";
        }else {
            return "noglass";
        }
    }
    //进片前破损
    public void ps(Glass glass){
        List<GlassOrder> orderes = glassOrderDao.findByLengthAndWidth(glass.getRawPackageTxt().getTxt_name(), glass.getApart_id(),glass.getLength(),glass.getWidth());
        if (orderes.size()>0) {
            GlassOrder order = orderes.get(0);
            order.setDamagePieces(order.getDamagePieces()+1);
            glassOrderDao.save(order);
        }else {
            List<GlassOrder> ors = glassOrderDao.findByLength(glass.getRawPackageTxt().getTxt_name(), glass.getLength(), glass.getWidth());
            if (ors.size()>0) {
                GlassOrder or = ors.get(0);
                or.setDamagePieces(or.getDamagePieces()+1);
                glassOrderDao.save(or);
            }
        }
    }
    
    //进片后破损
        public void moreps(Glass glass){
            List<GlassOrder> orderes = glassOrderDao.findByLengthAndWidth(glass.getRawPackageTxt().getTxt_name(), glass.getApart_id(),glass.getLength(),glass.getWidth());
            if (orderes.size()>0) {
                GlassOrder order = orderes.get(0);
                order.setDamagePieces(order.getDamagePieces()+1);
                glassOrderDao.save(order);
            }else {
                List<GlassOrder> ors = glassOrderDao.findByLength(glass.getRawPackageTxt().getTxt_name(), glass.getLength(), glass.getWidth());
                if (ors.size()>0) {
                    GlassOrder or = ors.get(0);
                    or.setDamagePieces(or.getDamagePieces()+1);
                    glassOrderDao.save(or);
                }
            }
        }
    
    public String reviewglass(String id) {
        TougheningGlass tougheningGlass = tougheningGlassDao.findOne(Long.parseLong(id));
        if (tougheningGlass !=null) {
            Glass glass = tougheningGlass.getGlass();
            if (glass != null) {
                glass.setCompletePieces(glass.getCompletePieces()-1);;
                if (glass.getState().equals("已识别")) {
                    glass.setState("待识别");
                }
                glassDao.save(glass);
//                tougheningGlass.setState("退回");
//                tougheningGlassDao.save(tougheningGlass);
                tougheningGlassDao.delete(tougheningGlass);
                return "ok";
            }else {
                return "noglass";
            }
        }else {
            return "noglass";
        }
    }
 
}