廖井涛
2025-05-27 084f17d969edbcc1a7dcf536a5555025372bae9c
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
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
package com.northglass.service.device;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
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.MachineType;
import com.northglass.constants.StateConstants.LoadMachineRackState;
import com.northglass.constants.StateConstants.PrintMachineState;
import com.northglass.constants.StateConstants.RackState;
import com.northglass.constants.StateConstants.ShelfHoistState;
import com.northglass.constants.StateConstants.ShelfRankState;
import com.northglass.constants.StateConstants.sendGlassState;
import com.northglass.entity.CountMachine;
import com.northglass.entity.CutMachine;
import com.northglass.entity.DummyFixRack;
import com.northglass.entity.FilmRemoveMachine;
import com.northglass.entity.GaoliweiMachine;
import com.northglass.entity.Glass;
import com.northglass.entity.GlassCommer;
import com.northglass.entity.GlassNumberColor;
import com.northglass.entity.LoadMachine;
import com.northglass.entity.LoadMachineRack;
import com.northglass.entity.MachineStatu;
import com.northglass.entity.PrintMachine;
import com.northglass.entity.PrintName;
import com.northglass.entity.PrintSize;
import com.northglass.entity.RawPackage;
import com.northglass.entity.RawPackageTxt;
import com.northglass.entity.Shelf;
import com.northglass.entity.ShelfHoist;
import com.northglass.entity.ShelfRank;
import com.northglass.entity.ShelfStatu;
import com.northglass.entity.TestOut;
import com.northglass.listener.GMMSPrinter;
import com.northglass.repository.CountMachineDao;
import com.northglass.repository.DummyFixRackDao;
import com.northglass.repository.GaoliweiMachineDao;
import com.northglass.repository.GlassCommerDao;
import com.northglass.repository.GlassDao;
import com.northglass.repository.GlassNumberColorDao;
import com.northglass.repository.LoadMachineRackDao;
import com.northglass.repository.MachineStatuDao;
import com.northglass.repository.PrintMachineDao;
import com.northglass.repository.PrintNameDao;
import com.northglass.repository.PrintSizeDao;
import com.northglass.repository.RawPackageTxtDao;
import com.northglass.repository.ShelfHoistDao;
import com.northglass.repository.ShelfRankDao;
import com.northglass.repository.ShelfStatuDao;
import com.northglass.repository.TestOutDao;
import com.northglass.service.arrangemachine.ArrangeMachineService;
import com.northglass.service.countmachine.CountMachineService;
import com.northglass.service.cutmachine.CutMachineService;
import com.northglass.service.edgemachine.EdgeMachineService;
import com.northglass.service.filmremovemachine.FilmRemoveMachineService;
import com.northglass.service.gaoliwei.GaoliweiMachineService;
import com.northglass.service.identifymachine.IdentifyMachineService;
import com.northglass.service.loadmachine.LoadMachineService;
import com.northglass.service.measuremachine.MeasureMachineService;
import com.northglass.service.shelf.ShelfService;
import com.northglass.service.tidy.TidyMachineService;
import com.northglass.service.washmachine.WashMachineService;
import com.northglass.web.gaoliwei.GaoliweiController;
 
@Component
@Transactional
public class DeviceService {
 
    private static final Logger LOGGER = LoggerFactory.getLogger(DeviceService.class);
 
    @Autowired
    private ShelfService shelfService;
 
    @Autowired
    private CutMachineService cutMachineService;
 
    @Autowired
    private LoadMachineService loadMachineService;
 
    @Autowired
    private FilmRemoveMachineService filmRemoveMachineService;
 
    @Autowired
    private ShelfRankDao shelfRankDao;
 
    @Autowired
    private GaoliweiMachineDao gaoliweiMachineDao;
 
    @Autowired
    private ShelfHoistDao shelfHoistDao;
 
    @Autowired
    private CountMachineDao countMachineDao;
 
    @Autowired
    private LoadMachineRackDao loadMachineRackDao;
 
    @Autowired
    private CountMachineService countMachineService;
 
    @Autowired
    private GaoliweiMachineService gaoliweiMachineService;
    
    @Autowired
    private ArrangeMachineService arrangeMachineService;
    
    @Autowired
    private MeasureMachineService measureMachineService;
 
    @Autowired
    private TestOutDao testOutDao;
 
    @Autowired
    private GlassNumberColorDao colorDao;
 
    @Autowired
    private RawPackageTxtDao rawPackageTxtDao;
 
    @Autowired
    private GlassDao glassDao;
 
    @Autowired
    private PrintSizeDao printSizeDao;
 
    @Autowired
    private PrintNameDao printNameDao;
 
    @Autowired
    private PrintMachineDao printMachineDao;
 
    @Autowired
    private ShelfStatuDao shelfStatuDao;
    
    @Autowired
    private DummyFixRackDao dummyFixRackDao;
    
    @Autowired
    private GlassCommerDao glassCommerDao;
    
    @Autowired
    private IdentifyMachineService identifyMachineService;
    
    @Autowired
    private TidyMachineService tidyMachineService;
    
    @Autowired
    private EdgeMachineService edgeMachineService;
 
    @Autowired
    private WashMachineService washMachineService;
    public void resetState() {
        shelfService.resetState();
        cutMachineService.resetState();
        loadMachineService.resetState();
        gaoliweiMachineService.resetState();
        //identifyMachineService.resetState();
        // edgeMachineService.resetState();
        washMachineService.resetState();
        // filmRemoveMachineService.resetState();
        countMachineService.resetState();
        // grindEdgeMachineService.resetState();
        // grindEdgeMachineTwoService.resetState();
        arrangeMachineService.resetState();
        measureMachineService.resetState();
    }
 
    public void resetRankState() {
        List<ShelfRank> shelfRankList = shelfRankDao.findAll();
        for (ShelfRank rank : shelfRankList) {
            rank.setState(ShelfRankState.FREE);
        }
        shelfRankDao.save(shelfRankList);
 
        List<ShelfHoist> shelfHoistList = shelfHoistDao.findAll();
        for (ShelfHoist hoist : shelfHoistList) {
            hoist.setState(ShelfHoistState.FREE);
        }
        shelfHoistDao.save(shelfHoistList);
 
        List<LoadMachineRack> loadMachineRackList = loadMachineRackDao.findAll();
        for (LoadMachineRack rack : loadMachineRackList) {
            rack.setState(LoadMachineRackState.FREE);
        }
        loadMachineRackDao.save(loadMachineRackList);
    }
 
    public void connect() {
//        shelfService.connect();
//        measureMachineService.connect();
        /*loadMachineService.connect();
        cutMachineService.connect();
        identifyMachineService.connect();
        arrangeMachineService.connect();
        tidyMachineService.connect();
        gaoliweiMachineService.connect();
        edgeMachineService.connect();
        washMachineService.connect();
        countMachineService.connect();*/
    }
 
    public List<Device> deviceManage() {
        LOGGER.debug("> Start deviceManage");
 
        List<Device> deviceList = new ArrayList<Device>();
 
        Shelf shelf = shelfService.getDefaultShelf();
        if (shelf != null) {
            Device shelfDevice = new Device(shelf.getId(), "原片仓储" + shelf.getNumber(), shelf.getPort(),
                    MachineType.SHELF);
            deviceList.add(shelfDevice);
        }
 
        List<LoadMachine> loadMachines = loadMachineService.getAll();
        for (LoadMachine loadMachine : loadMachines) {
            Device loadMachineDevice = new Device(loadMachine.getId(), "上片机" + loadMachine.getNumber(),
                    loadMachine.getPort(), MachineType.LOAD_MACHINE);
            deviceList.add(loadMachineDevice);
        }
 
        List<GaoliweiMachine> gaoliweiMachines = gaoliweiMachineDao.findAll();
        for (GaoliweiMachine gaoliweiMachine : gaoliweiMachines) {
            Device loadMachineDevice = new Device(gaoliweiMachine.getId(), "高力威" + gaoliweiMachine.getNumber(),
                    gaoliweiMachine.getPort(), MachineType.LOAD_MACHINE);
            deviceList.add(loadMachineDevice);
        }
 
        List<CountMachine> countMachines = countMachineDao.findAll();
        for (CountMachine countMachine : countMachines) {
            Device loadMachineDevice = new Device(countMachine.getId(), "下片机" + countMachine.getNumber(),
                    countMachine.getPort(), MachineType.LOAD_MACHINE);
            deviceList.add(loadMachineDevice);
        }
        LOGGER.debug("> End deviceManage");
        return deviceList;
    }
 
    public void modifyPort(String type, Long id, int port) {
        LOGGER.debug("> 开始定义");
        LOGGER.debug("type: " + type);
        LOGGER.debug("id: " + id);
        LOGGER.debug("port: " + port);
 
        if (type.equalsIgnoreCase(MachineType.SHELF)) {
            Shelf shelf = shelfService.getDefaultShelf();
            shelf.setPort(port);
            shelfService.save(shelf);
        } else if (type.equalsIgnoreCase(MachineType.LOAD_MACHINE)) {
            LoadMachine loadMachine = loadMachineService.getById(id);
            loadMachine.setPort(port);
            loadMachineService.saveLoadMachine(loadMachine);
        } else if (type.equalsIgnoreCase(MachineType.CUT_MACHINE)) {
            CutMachine cutMachine = cutMachineService.getById(id);
            cutMachine.setPort(port);
            cutMachineService.save(cutMachine);
        } else if (type.equalsIgnoreCase("filmremovemachine")) {
            FilmRemoveMachine filmRemoveMachine = filmRemoveMachineService.getById(id);
            filmRemoveMachine.setPort(port);
            filmRemoveMachineService.save(filmRemoveMachine);
        } else if (type.equalsIgnoreCase(MachineType.COUNT_MACHINE)) {
            CountMachine countMachine = countMachineService.getById(id);
            countMachine.setPort(port);
            countMachineService.saveCountMachine(countMachine);
        }
 
        LOGGER.debug("> End modifyPort");
    }
 
    public Map<String, Object> getdropped() {
        Map<String, Object> param = new HashMap<String, Object>();
        List<TestOut> shelf = testOutDao.findByName("shelf");
        List<TestOut> loadMachine01 = testOutDao.findByName("loadMachine01");
        List<TestOut> loadMachine02 = testOutDao.findByName("loadMachine02");
        List<TestOut> countMachine01 = testOutDao.findByName("countMachine01");
        List<TestOut> countMachine02 = testOutDao.findByName("countMachine02");
        List<TestOut> gaoliweiMachine01 = testOutDao.findByName("gaoliweiMachine01");
        List<TestOut> gaoliweiMachine02 = testOutDao.findByName("gaoliweiMachine02");
        param.put("shelf", shelf.size());
        param.put("loadMachine01", loadMachine01.size());
        param.put("loadMachine02", loadMachine02.size());
        param.put("gaoliweiMachine01", gaoliweiMachine01.size());
        param.put("gaoliweiMachine02", gaoliweiMachine02.size());
        param.put("countMachine01", countMachine01.size());
        param.put("countMachine02", countMachine02.size());
        return param;
    }
 
    public void deletedrop() {
        testOutDao.deleteAll();
    }
 
    public String findColorHtml() {
        StringBuffer html = new StringBuffer();
        List<GlassNumberColor> colors = colorDao.findAll();
        for (int i = 0; i < colors.size(); i++) {
            GlassNumberColor color = colors.get(i);
            html.append("<tr><td>").append(color.getId()).append("</td><td>");
            html.append("<span class='label label-success'>").append(color.getGlassId());
            html.append("</span></td><td><a href='/gmms2/device/deletecolor/").append(color.getId())
                    .append("' class='btn btn-danger'>删除</a></td></tr>");
        }
        return html.toString();
    }
 
    public void addcolor(GlassNumberColor color) {
        color.setFlag("0");
        colorDao.save(color);
    }
 
    public void deletecolor(String id) {
        GlassNumberColor color = colorDao.findOne(Long.parseLong(id));
        colorDao.delete(Long.parseLong(id));
        LOGGER.debug("删除膜系" + color.getGlassId());
    }
 
    public void finish() {
        GaoliweiController.setButton("1");
        GaoliweiController.setButton1("1");
    }
 
    public void prints(String s) {
        PrintMachine printMachin = printMachineDao.findByLine(s);
        GMMSPrinter printer = new GMMSPrinter("罗兰测试1", "0100000463", "5mmXTY270镀膜不印标(异形)钢化",
                "5-9 1816289-2 固玻 关埠 按图开介,图-1", "1L", 888, 666, "20181014.02A", "A", "12345", s, 1, (long) 123,
                printMachin.getName(), printMachin.getStatu(), "4","归来出");
        if (!s.equals("1")) {
            printer = new GMMSPrinter("罗兰测试2", "0100000464", "5mmXTY270镀膜不印标(异形)钢化", "5-9 1816289-2 固玻 关埠 按图开介,图-1",
                    "1L", 1000, 800, "20181024.01A", "B", "33333", s, 1, (long) 123, printMachin.getName(),
                    printMachin.getStatu(), "4","归来去");
        }
 
        // 开始打印
        printer.doPrint();
    }
 
    public void finishmo(String id) {
        if (id.equals("1")) {
            GaoliweiController.setButton("1");
            LOGGER.debug("发送一号线清空指令");
        } else {
            GaoliweiController.setButton1("1");
            LOGGER.debug("发送二号线清空指令");
        }
    }
 
    public void again(String id) {
        RawPackageTxt rawPackageTxt = rawPackageTxtDao.findAcceptedByGroup("1");
        if (rawPackageTxt == null) {
            LOGGER.debug("没有任务,不处理信息");
        } else {
            String txtName = rawPackageTxt.getTxt_name();
            List<Glass> allGlasses = glassDao.findByBatch(txtName);
            if (allGlasses.size() > 0) {
                if (id.equals("1")) {
                    for (Glass glass : allGlasses) {
                        glass.setSendState(sendGlassState.NOTSEND);
                        glassDao.save(glass);
                    }
                } else if (id.equals("2")) {
                    for (Glass glass : allGlasses) {
                        glass.setSendStates(sendGlassState.NOTSEND);
                        glassDao.save(glass);
                    }
                }
            }
        }
 
    }
 
    public void nosend(String id) {
        RawPackageTxt rawPackageTxt = rawPackageTxtDao.findAcceptedByGroup("1");
        if (rawPackageTxt == null) {
            LOGGER.debug("没有任务,不处理信息");
        } else {
            String txtName = rawPackageTxt.getTxt_name();
            List<Glass> allGlasses = glassDao.findByBatch(txtName);
            if (allGlasses.size() > 0) {
                if (id.equals("1")) {
                    for (Glass glass : allGlasses) {
                        glass.setSendState(sendGlassState.NOTUSE);
                        glassDao.save(glass);
                    }
                } else if (id.equals("2")) {
                    for (Glass glass : allGlasses) {
                        glass.setSendStates(sendGlassState.NOTUSE);
                        glassDao.save(glass);
                    }
                }
            }
        }
    }
 
    public PrintSize findPrintSize() {
        return printSizeDao.findOne(1L);
    }
 
    public PrintName findPrintName(Long s) {
        return printNameDao.findOne(s);
    }
 
    public String getPrintHtml(long l) {
        StringBuffer html = new StringBuffer();
        List<PrintMachine> printMachines = printMachineDao.findAll();
        if (printMachines.size() > 0) {
            for (PrintMachine printMachine : printMachines) {
                html.append("<tr><td>打印机").append(printMachine.getLine()).append("</td>");
                html.append("<td>");
                if (printMachine.getPattern().equals(PrintMachineState.PATTERN_SINGLE)) {
                    html.append("单片打印");
                } else if (printMachine.getPattern().equals(PrintMachineState.PATTERN_ALL)) {
                    html.append("全部打印");
                } else {
                    html.append("不打印");
                }
                html.append("</td>");
                html.append("<td>").append(printMachine.getStatu()).append("</td>");
                html.append("<td><a class='btn btn-large btn-success' onclick='modifypattern(")
                        .append(printMachine.getId()).append(")'>修改打印类型</a>");
                html.append("<a class='btn btn-large btn-success' onclick='modifystatu(").append(printMachine.getId())
                        .append(")'>修改打印属性</a>");
                html.append("<a class='btn btn-large btn-success' href='/gmms2/device/print/")
                        .append(printMachine.getId()).append("'>打印测试</a>");
                html.append("</td></tr>");
            }
        }
        html.append("</tr>");
        return html.toString();
    }
 
    public void modifyPattern(PrintMachine printMachine) {
        // String line = printMachine.getLine();
 
        String s = "";
        PrintMachine print = printMachineDao.findByLine(printMachine.getLine());
        if (printMachine.getPattern().equals("单片打印")) {
            s = PrintMachineState.PATTERN_SINGLE;
        } else if (printMachine.getPattern().equals("全部打印")) {
            s = PrintMachineState.PATTERN_ALL;
        } else {
            s = PrintMachineState.PATTERN_NOT;
        }
        print.setPattern(s);
        printMachineDao.save(print);
    }
 
    public void modifyStatu(PrintMachine printMachine) {
        PrintMachine print = printMachineDao.findByLine(printMachine.getLine());
        print.setStatu(printMachine.getStatu());
        printMachineDao.save(print);
    }
 
    public String getstatu() {
        StringBuffer html = new StringBuffer();
 
        return html.toString();
    }
 
    /**
     * 仓储信息
     * 
     * @author 司家旺
     * 
     **/
    public String getshelfstatu() {
        StringBuffer html = new StringBuffer();
        List<ShelfStatu> status = shelfStatuDao.findAll();
        if (status.size() > 0) {
            for (ShelfStatu statu : status) {
                html.append("<tr style='color:red'><td>").append(statu.getId()).append("</td>");
                html.append("<td>").append(statu.getAutostate()).append("</td>");
                html.append("<td>").append(statu.getErrorstate()).append("</td>");
                html.append("<td>").append(statu.getPlcid()).append("</td>");
                html.append("<td>").append(statu.getMesid()).append("</td>");
                html.append("<td>").append(statu.getSetTime()).append("</td></tr>");
            }
        }
        return html.toString();
    }
 
    public String getloadstatu() {
        StringBuffer html = new StringBuffer();
        ShelfStatu statu = shelfStatuDao.findByMachine("load");
        if (statu != null) {
                html.append("<tr style='color:red'><td>").append(statu.getId()).append("</td>");
                html.append("<td>").append(statu.getAutostate()).append("</td>");
                html.append("<td>").append(statu.getErrorstate()).append("</td>");
                html.append("<td>").append(statu.getLoadfinish()).append("</td>");
                html.append("<td>").append(statu.getPlcid()).append("</td>");
                html.append("<td>").append(statu.getMesid()).append("</td>");
                html.append("<td>").append(statu.getSetTime()).append("</td></tr>");
        }
        return html.toString();
    }
 
    public String getgaoliweistatu() {
        StringBuffer html = new StringBuffer();
        ShelfStatu statu = shelfStatuDao.findByMachine("gaoliwei");
        if (statu != null) {
                html.append("<tr style='color:red;'><td>").append(statu.getId()).append("</td>");
                html.append("<td>").append(statu.getAutostate()).append("</td>");
                html.append("<td>").append(statu.getLoadfinish()).append("</td>");
                html.append("<td>").append(statu.getPlcid()).append("</td>");
                html.append("<td>").append(statu.getMesid()).append("</td>");
                html.append("<td>").append(statu.getSetTime()).append("</td></tr>");
        }
        return html.toString();
    }
 
    public String serchglass(String name) {
        StringBuffer html = new StringBuffer();
        LOGGER.debug("name:" + name);
        List<Glass> glasses = glassDao.findByBatch(name);
        LOGGER.debug("glasses:" + glasses.size());
        if (glasses.size() > 0) {
            for (Glass glass : glasses) {
                if (glass.getPieces() == glass.getCompletePieces()) {
                    html.append("<tr>");
                } else {
                    html.append("<tr style='color:red'>");
                }
                html.append("<td>").append(glass.getId()).append("</td>");
                html.append("<td>").append(glass.getManufacture_batch()).append("</td>");
                html.append("<td>").append(glass.getLength()).append("</td>");
                html.append("<td>").append(glass.getWidth()).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>")
                        .append("<a type='button' class='btn btn-large btn-success' href='/gmms2/device/printglass/")
                        .append(glass.getId());
                html.append(
                        "/1'>打印1</a><a type='button' class='btn btn-large btn-success' href='/gmms2/device/printglass/")
                        .append(glass.getId());
                html.append("/2'>打印2</a>");
                html.append("</td></tr>");
            }
        }
        return html.toString();
    }
 
    public String workglass() {
        StringBuffer html = new StringBuffer();
        RawPackageTxt txt = rawPackageTxtDao.findCutFinishByGroup("1");
        if (txt == null) {
            txt = rawPackageTxtDao.findAcceptedByGroup("1");
        }
        if (txt != null) {
            List<Glass> glasses = glassDao.findByBatch(txt.getTxt_name());
 
            if (glasses.size() > 0) {
                for (Glass glass : glasses) {
                    if (glass.getPieces() == glass.getCompletePieces()) {
                        html.append("<tr>");
                    } else {
                        html.append("<tr style='color:red'>");
                    }
                    html.append("<td>").append(glass.getId()).append("</td>");
                    html.append("<td>").append(glass.getManufacture_batch()).append("</td>");
                    html.append("<td>").append(glass.getLength()).append("</td>");
                    html.append("<td>").append(glass.getWidth()).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>")
                            .append("<a type='button' class='btn btn-large btn-success' href='/gmms2/device/printglass/")
                            .append(glass.getId());
                    html.append(
                            "/1'>打印1</a><a type='button' class='btn btn-large btn-success' href='/gmms2/device/printglass/")
                            .append(glass.getId());
                    html.append("/2'>打印2</a></td>");*/
                    html.append("</tr>");
                }
            }
        }
        return html.toString();
    }
 
    public void printglass(String id, String line) {
        Glass glass = glassDao.findOne(Long.valueOf(id));
        PrintMachine printMachin = printMachineDao.findByLine(line);
        if (glass != null) {
            new GMMSPrinter(glass.getCustomer(), glass.getApplication(), glass.getProduction(), glass.getFloor_number(),
                    glass.getOrder_number(), glass.getLength(), glass.getWidth(), glass.getApart_id(),
                    glass.getPiece_sign(), glass.getRemark(), line, glass.getPieces(), 1L, printMachin.getName(),
                    printMachin.getStatu(), glass.getArrangeStatu(),glass.getThingsout()).doPrint();
        }
    }
 
    public void otherprint(String id) {
 
        PrintMachine printMachin = printMachineDao.findByLine(id);
        RawPackageTxt txt = rawPackageTxtDao.findCutFinishByGroup("1");
        if (txt == null) {
            txt = rawPackageTxtDao.findAcceptedByGroup("1");
        }
        LOGGER.debug("打印剩余的玻璃标签!");
        if (txt != null) {
            List<Glass> glasses = glassDao.findByBatch(txt.getTxt_name());
            if (glasses.size() > 0) {
                for (Glass glass : glasses) {
                    if (glass.getPieces() > glass.getCompletePieces()) {
                        for (int i = 0; i < glass.getPieces() - glass.getCompletePieces(); i++) {
                            new GMMSPrinter(glass.getCustomer(), glass.getApplication(), glass.getProduction(),
                                    glass.getFloor_number(), glass.getOrder_number(), glass.getLength(),
                                    glass.getWidth(), glass.getApart_id(), glass.getPiece_sign(), glass.getRemark(),
                                    id, glass.getPieces(), 1L, printMachin.getName(), printMachin.getStatu(),
                                    glass.getArrangeStatu(),glass.getThingsout()).doPrint();
                        }
                        glass.setCompletePieces(glass.getPieces());
                        glassDao.save(glass);
                    }
 
                }
            }
        }
 
    }
 
    /**
     * 
     * @author northglass
     * 功能:获得虚拟料架的专属列表
     * 2019年3月18日
     * 
     * **/
    public String getdummyhtml() {
        StringBuffer html = new StringBuffer();
        List<DummyFixRack> dummyFixRacks = dummyFixRackDao.findAll();
        if (dummyFixRacks.size()>0) {
            for (DummyFixRack dummyFixRack :dummyFixRacks) {
                html.append("<tr><td>").append(dummyFixRack.getNumber()).append("</td><td>");
                if (dummyFixRack.getState().equals(RackState.FREE)) {
                    html.append(dummyFixRack.getState()).append("</td><td>");
                    html.append("<button class=\"btn btn-large btn-success\" onclick=\"addrack(").append(dummyFixRack.getId()).append(")\">添加原片</button>");
                }else {
                    html.append("【").append(dummyFixRack.getThickness()).append("mm").append(dummyFixRack.getWidth());
                    html.append("*"+dummyFixRack.getHeight() + " mm " +dummyFixRack.getColor()+ "】");
                    html.append(dummyFixRack.getLeftPieces()+"/"+dummyFixRack.getPieces()).append("</td><td>");
                    html.append("<button class=\"btn btn-large btn-warning\" onclick=\"modifyrack(").append(dummyFixRack.getId()).append(")\">修改原片</button>&nbsp;&nbsp;&nbsp;&nbsp;");
                    html.append("<a class=\"btn btn-large btn-danger\" href=\"/gmms2/device/deleteDummyRack/").append(dummyFixRack.getId()).append("\">删除原片</a>");
                }
                html.append("</td></tr>");
            }
        }
        return html.toString();
    }
 
    /***
     * 
     * @author northglass
     * 2019年3月18日
     * 功能:删除虚拟料架上面的数据
     * 
     * **/
    public void deleteDummyRack(String id) {
        DummyFixRack dummyFixRack = dummyFixRackDao.findOne(Long.parseLong(id));
        if (dummyFixRack != null) {
            dummyFixRack.setColor(null);
            dummyFixRack.setHeight(0);
            dummyFixRack.setThickness(0);
            dummyFixRack.setWidth(0);
            dummyFixRack.setLeftPieces(0);
            dummyFixRack.setPieces(0);
            dummyFixRack.setState(RackState.FREE);
            dummyFixRackDao.save(dummyFixRack);
        }
    }
 
    /***
     * 
     * @author northglass
     * 2019年3月18日
     * 功能:修改虚拟料架里面的片数
     * 
     * **/
    public void modifyRack(String pieces, String ids) {
        DummyFixRack dummyFixRack = dummyFixRackDao.findOne(Long.parseLong(ids));
        int pic = Integer.parseInt(pieces);
        if (pic == 0) {
            dummyFixRack.setColor(null);
            dummyFixRack.setHeight(0);
            dummyFixRack.setThickness(0);
            dummyFixRack.setWidth(0);
            dummyFixRack.setLeftPieces(0);
            dummyFixRack.setPieces(0);
            dummyFixRack.setState(RackState.FREE);
        }else {
            dummyFixRack.setLeftPieces(pic);
        }
        dummyFixRackDao.save(dummyFixRack);
    }
 
    /***
     * 
     * @author northglass
     * 2019年3月18日
     * 功能:添加虚拟料架上面的信息
     * 
     * **/
    public void addRack(RawPackage rawPackage, String shelfRankNumber, String ids) {
        DummyFixRack dummyFixRack = dummyFixRackDao.findOne(Long.parseLong(ids));
        if (dummyFixRack !=null ) {
            dummyFixRack.setColor(rawPackage.getColor());
            dummyFixRack.setHeight(rawPackage.getHeight());
            dummyFixRack.setWidth(rawPackage.getWidth());
            dummyFixRack.setThickness(rawPackage.getThickness());
            dummyFixRack.setPieces(rawPackage.getPieces());
            dummyFixRack.setLeftPieces(dummyFixRack.getPieces());
            dummyFixRack.setState(RackState.IN_WORK);
            dummyFixRack.setCreateTime(new Date());
            dummyFixRackDao.save(dummyFixRack);
        }
    }
 
    /**
     * 
     * @author northglass
     * 功能:获得查询虚拟料架的专属列表
     * 2019年3月19日
     * 
     * **/
    
    public String getserachdummyhtml(String color, String glassThickness) {
        StringBuffer html = new StringBuffer();
        List<DummyFixRack> dummyFixRacks = dummyFixRackDao.findbyColorAndThickness(color,Double.parseDouble(glassThickness));
        if (dummyFixRacks.size()>0) {
            for (DummyFixRack dummyFixRack :dummyFixRacks) {
                html.append("<tr><td>").append(dummyFixRack.getNumber()).append("</td><td>");
                if (dummyFixRack.getState().equals(RackState.FREE)) {
                    html.append(dummyFixRack.getState()).append("</td><td>");
                    html.append("<button class=\"btn btn-large btn-success\" onclick=\"addrack(").append(dummyFixRack.getId()).append(")\">添加原片</button>");
                }else {
                    html.append("【").append(dummyFixRack.getThickness()).append("mm").append(dummyFixRack.getWidth());
                    html.append("*"+dummyFixRack.getHeight() + " mm " +dummyFixRack.getColor()+ "】");
                    html.append(dummyFixRack.getLeftPieces()+"/"+dummyFixRack.getPieces()).append("</td><td>");
                    html.append("<button class=\"btn btn-large btn-warning\" onclick=\"modifyrack(").append(dummyFixRack.getId()).append(")\">修改原片</button>&nbsp;&nbsp;&nbsp;&nbsp;");
                    html.append("<a class=\"btn btn-large btn-danger\" href=\"/gmms2/device/deleteDummyRack/").append(dummyFixRack.getId()).append("\">删除原片</a>");
                }
                html.append("</td></tr>");
            }
        }
        return html.toString();
    }
 
    public String findglasscumtorHtml() {
        StringBuffer html = new StringBuffer();
        List<GlassCommer> glassCommers = glassCommerDao.findAll();
        for (int i = 0; i < glassCommers.size(); i++) {
            GlassCommer glassCommer = glassCommers.get(i);
            html.append("<tr><td>").append(glassCommer.getId()).append("</td><td>");
            html.append("<span class='label label-success'>").append(glassCommer.getName());
            html.append("</span></td><td><a href='/gmms2/device/deletecumtor/").append(glassCommer.getId())
                    .append("' class='btn btn-danger'>删除</a></td></tr>");
        }
        return html.toString();
    }
    
    public void addcommer(GlassCommer glassCommer) {
        glassCommerDao.save(glassCommer);
    }
 
    public void deletecumtor(String id) {
        GlassCommer glassCommer = glassCommerDao.findOne(Long.parseLong(id));
        glassCommerDao.delete(Long.parseLong(id));
        LOGGER.debug("删除膜系" + glassCommer.getName());
        
    }
 
    public Map<String, Object> getCeliangManageData(String groups) {
 
//        Long machineId = Long.valueOf(groups);
        Map<String, Object> param = new HashMap<String, Object>();
 
    
        int totalPieces = 0;
        int completePieces = 0;
        
        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;
    
    }
}