廖井涛
2025-05-27 d687ff755f0f3022dcd1f57a03104b0e91536ab3
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
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486
9487
9488
9489
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9534
9535
9536
9537
9538
9539
9540
9541
9542
9543
9544
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573
9574
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727
9728
9729
9730
9731
9732
9733
9734
9735
9736
9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774
9775
9776
9777
9778
9779
9780
9781
9782
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
9821
9822
9823
9824
9825
9826
9827
9828
9829
9830
9831
9832
9833
9834
9835
9836
9837
9838
9839
9840
9841
9842
9843
9844
9845
9846
9847
9848
9849
9850
9851
9852
9853
9854
9855
9856
9857
9858
9859
9860
9861
9862
9863
9864
9865
9866
9867
9868
9869
9870
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933
9934
9935
9936
9937
9938
9939
9940
9941
9942
9943
9944
9945
9946
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
9974
9975
9976
9977
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046
10047
10048
10049
10050
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162
10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176
10177
10178
10179
10180
10181
10182
10183
10184
10185
10186
10187
10188
10189
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10212
10213
10214
10215
10216
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10232
10233
10234
10235
10236
10237
10238
10239
10240
10241
10242
10243
10244
10245
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
10273
10274
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10288
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10307
10308
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350
10351
10352
10353
10354
10355
10356
10357
10358
10359
10360
10361
10362
10363
10364
10365
10366
10367
10368
10369
10370
10371
10372
10373
10374
10375
10376
10377
10378
10379
10380
10381
10382
10383
10384
10385
10386
10387
10388
10389
10390
10391
10392
10393
10394
10395
10396
10397
10398
10399
10400
10401
10402
10403
10404
10405
10406
10407
10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
10428
10429
10430
10431
10432
10433
10434
10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463
10464
10465
10466
10467
10468
10469
10470
10471
10472
10473
10474
10475
10476
10477
10478
10479
10480
10481
10482
10483
10484
10485
10486
10487
10488
10489
10490
10491
10492
10493
10494
10495
10496
10497
10498
10499
10500
10501
10502
10503
10504
10505
10506
10507
10508
10509
10510
10511
10512
10513
10514
10515
10516
10517
10518
10519
10520
10521
10522
10523
10524
10525
10526
10527
10528
10529
10530
10531
10532
10533
10534
10535
10536
10537
10538
10539
10540
10541
10542
10543
10544
10545
10546
10547
10548
10549
10550
10551
10552
10553
10554
10555
10556
10557
10558
10559
10560
10561
10562
10563
10564
10565
10566
10567
10568
10569
10570
10571
10572
10573
10574
10575
10576
10577
10578
10579
10580
10581
10582
10583
10584
10585
10586
10587
10588
10589
10590
10591
10592
10593
10594
10595
10596
10597
10598
10599
10600
10601
10602
10603
10604
10605
10606
10607
10608
10609
10610
10611
10612
10613
10614
10615
10616
10617
10618
10619
10620
10621
10622
10623
10624
10625
10626
10627
10628
10629
10630
10631
10632
10633
10634
10635
10636
10637
10638
10639
10640
10641
10642
10643
10644
10645
10646
10647
10648
10649
10650
10651
10652
10653
10654
10655
10656
10657
10658
10659
10660
10661
10662
10663
10664
10665
10666
10667
10668
10669
10670
10671
10672
10673
10674
10675
10676
10677
10678
10679
10680
10681
10682
10683
10684
10685
10686
10687
10688
10689
10690
10691
10692
10693
10694
10695
10696
10697
10698
10699
10700
10701
10702
10703
10704
10705
10706
10707
10708
10709
10710
10711
10712
10713
10714
10715
10716
10717
10718
10719
10720
10721
10722
10723
10724
10725
10726
10727
10728
10729
10730
10731
10732
10733
10734
10735
10736
10737
10738
10739
10740
10741
10742
10743
10744
10745
10746
10747
10748
10749
10750
10751
10752
10753
10754
10755
10756
10757
10758
10759
10760
10761
10762
10763
10764
10765
10766
10767
10768
10769
10770
10771
10772
10773
10774
10775
10776
10777
10778
10779
10780
10781
10782
10783
10784
10785
10786
10787
10788
10789
10790
10791
10792
10793
10794
10795
10796
10797
10798
10799
10800
10801
10802
10803
10804
10805
10806
10807
10808
10809
10810
10811
10812
10813
10814
10815
10816
10817
10818
10819
10820
10821
10822
10823
10824
10825
10826
10827
10828
10829
10830
10831
10832
10833
10834
10835
10836
10837
10838
10839
10840
10841
10842
10843
10844
10845
10846
10847
10848
10849
10850
10851
10852
10853
10854
10855
10856
10857
10858
10859
10860
10861
10862
10863
10864
10865
10866
10867
10868
10869
10870
10871
10872
10873
10874
10875
10876
10877
10878
10879
10880
10881
10882
10883
10884
10885
10886
10887
10888
10889
10890
10891
10892
10893
10894
10895
10896
10897
10898
10899
10900
10901
10902
10903
10904
10905
10906
10907
10908
10909
10910
10911
10912
10913
10914
10915
10916
10917
10918
10919
10920
10921
10922
10923
10924
10925
10926
10927
10928
10929
10930
10931
10932
10933
10934
10935
10936
10937
10938
10939
10940
10941
10942
10943
10944
10945
10946
10947
10948
10949
10950
10951
10952
10953
10954
10955
10956
10957
10958
10959
10960
10961
10962
10963
10964
10965
10966
10967
10968
10969
10970
10971
10972
10973
10974
10975
10976
10977
10978
10979
10980
10981
10982
10983
10984
10985
10986
10987
10988
10989
10990
10991
10992
10993
10994
10995
10996
10997
10998
10999
11000
11001
11002
11003
11004
11005
11006
11007
11008
11009
11010
11011
11012
11013
11014
11015
11016
11017
11018
11019
11020
11021
11022
11023
11024
11025
11026
11027
11028
11029
11030
11031
11032
11033
11034
11035
11036
11037
11038
11039
11040
11041
11042
11043
11044
11045
11046
11047
11048
11049
11050
11051
11052
11053
11054
11055
11056
11057
11058
11059
11060
11061
11062
11063
11064
11065
11066
11067
11068
11069
11070
11071
11072
11073
11074
11075
11076
11077
11078
11079
11080
11081
11082
11083
11084
11085
11086
11087
11088
11089
11090
11091
11092
11093
11094
11095
11096
11097
11098
11099
11100
11101
11102
11103
11104
11105
11106
11107
11108
11109
11110
11111
11112
11113
11114
11115
11116
11117
11118
11119
11120
11121
11122
11123
11124
11125
11126
11127
11128
11129
11130
11131
11132
11133
11134
11135
11136
11137
11138
11139
11140
11141
11142
11143
11144
11145
11146
11147
11148
11149
11150
11151
11152
11153
11154
11155
11156
11157
11158
11159
11160
11161
11162
11163
11164
11165
11166
11167
11168
11169
11170
11171
11172
11173
11174
11175
11176
11177
11178
11179
11180
11181
11182
11183
11184
11185
11186
11187
11188
11189
11190
11191
11192
11193
11194
11195
11196
11197
11198
11199
11200
11201
11202
11203
11204
11205
11206
11207
11208
11209
11210
11211
11212
11213
11214
11215
11216
11217
11218
11219
11220
11221
11222
11223
11224
11225
11226
11227
11228
11229
11230
11231
11232
11233
11234
11235
11236
11237
11238
11239
11240
11241
11242
11243
11244
11245
11246
11247
11248
11249
11250
11251
11252
11253
11254
11255
11256
11257
11258
11259
11260
11261
11262
11263
11264
11265
11266
11267
11268
11269
11270
11271
11272
11273
11274
11275
11276
11277
11278
11279
11280
11281
11282
11283
11284
11285
11286
11287
11288
11289
11290
11291
11292
11293
11294
11295
11296
11297
11298
11299
11300
11301
11302
11303
11304
11305
11306
11307
11308
11309
11310
11311
11312
11313
11314
11315
11316
11317
11318
11319
11320
11321
11322
11323
11324
11325
11326
11327
11328
11329
11330
11331
11332
11333
11334
11335
11336
11337
11338
11339
11340
11341
11342
11343
11344
11345
11346
11347
11348
11349
11350
11351
11352
11353
11354
11355
11356
11357
11358
11359
11360
11361
11362
11363
11364
11365
11366
11367
11368
11369
11370
11371
11372
11373
11374
11375
11376
11377
11378
11379
11380
11381
11382
11383
11384
11385
11386
11387
11388
11389
11390
11391
11392
11393
11394
11395
11396
11397
11398
11399
11400
11401
11402
11403
11404
11405
11406
11407
11408
11409
11410
11411
11412
11413
11414
11415
11416
11417
11418
11419
11420
11421
11422
11423
11424
11425
11426
11427
11428
11429
11430
11431
11432
11433
11434
11435
11436
11437
11438
11439
11440
11441
11442
11443
11444
11445
11446
11447
11448
11449
11450
11451
11452
11453
11454
11455
11456
11457
11458
11459
11460
11461
11462
11463
11464
11465
11466
11467
11468
11469
11470
11471
11472
11473
11474
11475
11476
11477
11478
11479
11480
11481
11482
11483
11484
11485
11486
11487
11488
11489
11490
11491
11492
11493
11494
11495
11496
11497
11498
11499
11500
11501
11502
11503
11504
11505
11506
11507
11508
11509
11510
11511
11512
11513
11514
11515
11516
11517
11518
11519
11520
11521
11522
11523
11524
11525
11526
11527
11528
11529
11530
11531
11532
11533
11534
11535
11536
11537
11538
11539
11540
11541
11542
11543
11544
11545
11546
11547
11548
11549
11550
11551
11552
11553
11554
11555
11556
11557
11558
11559
11560
11561
11562
11563
11564
11565
11566
11567
11568
11569
11570
11571
11572
11573
11574
11575
11576
11577
11578
11579
11580
11581
11582
11583
11584
11585
11586
11587
11588
11589
11590
11591
11592
11593
11594
11595
11596
11597
11598
11599
11600
11601
11602
11603
11604
11605
11606
11607
11608
11609
11610
11611
11612
11613
11614
11615
11616
11617
11618
11619
11620
11621
11622
11623
11624
11625
11626
11627
11628
11629
11630
11631
11632
11633
11634
11635
11636
11637
11638
11639
11640
11641
11642
11643
11644
11645
11646
11647
11648
11649
11650
11651
11652
11653
11654
11655
11656
11657
11658
11659
11660
11661
11662
11663
11664
11665
11666
11667
11668
11669
11670
11671
11672
11673
11674
11675
11676
11677
11678
11679
11680
11681
11682
11683
11684
11685
11686
11687
11688
11689
11690
11691
11692
11693
11694
11695
11696
11697
11698
11699
11700
11701
11702
11703
11704
11705
11706
11707
11708
11709
11710
11711
11712
11713
11714
11715
11716
11717
11718
11719
11720
11721
11722
11723
11724
11725
11726
11727
11728
11729
11730
11731
11732
11733
11734
11735
11736
11737
11738
11739
11740
11741
11742
11743
11744
11745
11746
11747
11748
11749
11750
11751
11752
11753
11754
11755
11756
11757
11758
11759
11760
11761
11762
11763
11764
11765
11766
11767
11768
11769
11770
11771
11772
11773
11774
11775
11776
11777
11778
11779
11780
11781
11782
11783
11784
11785
11786
11787
11788
11789
11790
11791
11792
11793
11794
11795
11796
11797
11798
11799
11800
11801
11802
11803
11804
11805
11806
11807
11808
11809
11810
11811
11812
11813
11814
11815
11816
11817
11818
11819
11820
11821
11822
11823
11824
11825
11826
11827
11828
11829
11830
11831
11832
11833
11834
11835
11836
11837
11838
11839
11840
11841
11842
11843
11844
11845
11846
11847
11848
11849
11850
11851
11852
11853
11854
11855
11856
11857
11858
11859
11860
11861
11862
11863
11864
11865
11866
11867
11868
11869
11870
11871
11872
11873
11874
11875
11876
11877
11878
11879
11880
11881
11882
11883
11884
11885
11886
11887
11888
11889
11890
11891
11892
11893
11894
11895
11896
11897
11898
11899
11900
11901
11902
11903
11904
11905
11906
11907
11908
11909
11910
11911
11912
11913
11914
11915
11916
11917
11918
11919
11920
11921
11922
11923
11924
11925
11926
11927
11928
11929
11930
11931
11932
11933
11934
11935
11936
11937
11938
11939
11940
11941
11942
11943
11944
11945
11946
11947
11948
11949
11950
11951
11952
11953
11954
11955
11956
11957
11958
11959
11960
11961
11962
11963
11964
11965
11966
11967
11968
11969
11970
11971
11972
11973
11974
11975
11976
11977
11978
11979
11980
11981
11982
11983
11984
11985
11986
11987
11988
11989
11990
11991
11992
11993
11994
11995
11996
11997
11998
11999
12000
12001
12002
12003
12004
12005
12006
12007
12008
12009
12010
12011
12012
12013
12014
12015
12016
12017
12018
12019
12020
12021
12022
12023
12024
12025
12026
12027
12028
12029
12030
12031
12032
12033
12034
12035
12036
12037
12038
12039
12040
12041
12042
12043
12044
12045
12046
12047
12048
12049
12050
12051
12052
12053
12054
12055
12056
12057
12058
12059
12060
12061
12062
12063
12064
12065
12066
12067
12068
12069
12070
12071
12072
12073
12074
12075
12076
12077
12078
12079
12080
12081
12082
12083
12084
12085
12086
12087
12088
12089
12090
12091
12092
12093
12094
12095
12096
12097
12098
12099
12100
12101
12102
12103
12104
12105
12106
12107
12108
12109
12110
12111
12112
12113
12114
12115
12116
12117
12118
12119
12120
12121
12122
12123
12124
12125
12126
12127
12128
12129
12130
12131
12132
12133
12134
12135
12136
12137
12138
12139
12140
12141
12142
12143
12144
12145
12146
12147
12148
12149
12150
12151
12152
12153
12154
12155
12156
12157
12158
12159
12160
12161
12162
12163
12164
12165
12166
12167
12168
12169
12170
12171
12172
12173
12174
12175
12176
12177
12178
12179
12180
12181
12182
12183
12184
12185
12186
12187
12188
12189
12190
12191
12192
12193
12194
12195
12196
12197
12198
12199
12200
12201
12202
12203
12204
12205
12206
12207
12208
12209
12210
12211
12212
12213
12214
12215
12216
12217
12218
12219
12220
12221
12222
12223
12224
12225
12226
12227
12228
12229
12230
12231
12232
12233
12234
12235
12236
12237
12238
12239
12240
12241
12242
12243
12244
12245
12246
12247
12248
12249
12250
12251
12252
12253
12254
12255
12256
12257
12258
12259
12260
12261
12262
12263
12264
12265
12266
12267
12268
12269
12270
12271
12272
12273
12274
12275
12276
12277
12278
12279
12280
12281
12282
12283
12284
12285
12286
12287
12288
12289
12290
12291
12292
12293
12294
12295
12296
12297
12298
12299
12300
12301
12302
12303
12304
12305
12306
12307
12308
12309
12310
12311
12312
12313
12314
12315
12316
12317
12318
12319
12320
12321
12322
12323
12324
12325
12326
12327
12328
12329
12330
12331
12332
12333
12334
12335
12336
12337
12338
12339
12340
12341
12342
12343
12344
12345
12346
12347
12348
12349
12350
12351
12352
12353
12354
12355
12356
12357
12358
12359
12360
12361
12362
12363
12364
12365
12366
12367
12368
12369
12370
12371
12372
12373
12374
12375
12376
12377
12378
12379
12380
12381
12382
12383
12384
12385
12386
12387
12388
12389
12390
12391
12392
12393
12394
12395
12396
12397
12398
12399
12400
12401
12402
12403
12404
12405
12406
12407
12408
12409
12410
12411
12412
12413
12414
12415
12416
12417
12418
12419
12420
12421
12422
12423
12424
12425
12426
12427
12428
12429
12430
12431
12432
12433
12434
12435
12436
12437
12438
12439
12440
12441
12442
12443
12444
12445
12446
12447
12448
12449
12450
12451
12452
12453
12454
12455
12456
12457
12458
12459
12460
12461
12462
12463
12464
12465
12466
12467
12468
12469
12470
12471
12472
12473
12474
12475
12476
12477
12478
12479
12480
12481
12482
12483
12484
12485
12486
12487
12488
12489
12490
12491
12492
12493
12494
12495
12496
12497
12498
12499
12500
12501
12502
12503
12504
12505
12506
12507
12508
12509
12510
12511
12512
12513
12514
12515
12516
12517
12518
12519
12520
12521
12522
12523
12524
12525
12526
12527
12528
12529
12530
12531
12532
12533
12534
12535
12536
12537
12538
12539
12540
12541
12542
12543
12544
12545
12546
12547
12548
12549
12550
12551
12552
12553
12554
12555
12556
12557
12558
12559
12560
12561
12562
12563
12564
12565
12566
12567
12568
12569
12570
12571
12572
12573
12574
12575
12576
12577
12578
12579
12580
12581
12582
12583
12584
12585
12586
12587
12588
12589
12590
12591
12592
12593
12594
12595
12596
12597
12598
12599
12600
12601
12602
12603
12604
12605
12606
12607
12608
12609
12610
12611
12612
12613
12614
12615
12616
12617
12618
12619
12620
12621
12622
12623
12624
12625
12626
12627
12628
12629
12630
12631
12632
12633
12634
12635
12636
12637
12638
12639
12640
12641
12642
12643
12644
12645
12646
12647
12648
12649
12650
12651
12652
12653
12654
12655
12656
12657
12658
12659
12660
12661
12662
12663
12664
12665
12666
12667
12668
12669
12670
12671
12672
12673
12674
12675
12676
12677
12678
12679
12680
12681
12682
12683
12684
12685
12686
12687
12688
12689
12690
12691
12692
12693
12694
12695
12696
12697
12698
12699
12700
12701
12702
12703
12704
12705
12706
12707
12708
12709
12710
12711
12712
12713
12714
12715
12716
12717
12718
12719
12720
12721
12722
12723
12724
12725
12726
12727
12728
12729
12730
12731
12732
12733
12734
12735
12736
12737
12738
12739
12740
12741
12742
12743
12744
12745
12746
12747
12748
12749
12750
12751
12752
12753
12754
12755
12756
12757
12758
12759
12760
12761
12762
12763
12764
12765
12766
12767
12768
12769
12770
12771
12772
12773
12774
12775
12776
12777
12778
12779
12780
12781
12782
12783
12784
12785
12786
12787
12788
12789
12790
12791
12792
12793
12794
12795
12796
12797
12798
12799
12800
12801
12802
12803
12804
12805
12806
12807
12808
12809
12810
12811
12812
12813
12814
12815
12816
12817
12818
12819
12820
12821
12822
12823
12824
12825
12826
12827
12828
12829
12830
12831
12832
12833
12834
12835
12836
12837
12838
12839
12840
12841
12842
12843
12844
12845
12846
12847
12848
12849
12850
12851
12852
12853
12854
12855
12856
12857
12858
12859
12860
12861
12862
12863
12864
12865
12866
12867
12868
12869
12870
12871
12872
12873
12874
12875
12876
12877
12878
12879
12880
12881
12882
12883
12884
12885
12886
12887
12888
12889
12890
12891
12892
12893
12894
12895
12896
12897
12898
12899
12900
12901
12902
12903
12904
12905
12906
12907
12908
12909
12910
12911
12912
12913
12914
12915
12916
12917
12918
12919
12920
12921
12922
12923
12924
12925
12926
12927
12928
12929
12930
12931
12932
12933
12934
12935
12936
12937
12938
12939
12940
12941
12942
12943
12944
12945
12946
12947
12948
12949
12950
12951
12952
12953
12954
12955
12956
12957
12958
12959
12960
12961
12962
12963
12964
12965
12966
12967
12968
12969
12970
12971
12972
12973
12974
12975
12976
12977
12978
12979
12980
12981
12982
12983
12984
12985
12986
12987
12988
12989
12990
12991
12992
12993
12994
12995
12996
12997
12998
12999
13000
13001
13002
13003
13004
13005
13006
13007
13008
13009
13010
13011
13012
13013
13014
13015
13016
13017
13018
13019
13020
13021
13022
13023
13024
13025
13026
13027
13028
13029
13030
13031
13032
13033
13034
13035
13036
13037
13038
13039
13040
13041
13042
13043
13044
13045
13046
13047
13048
13049
13050
13051
13052
13053
13054
13055
13056
13057
13058
13059
13060
13061
13062
13063
13064
13065
13066
13067
13068
13069
13070
13071
13072
13073
13074
13075
13076
13077
13078
13079
13080
13081
13082
13083
13084
13085
13086
13087
13088
13089
13090
13091
13092
13093
13094
13095
13096
13097
13098
13099
13100
13101
13102
13103
13104
13105
13106
13107
13108
13109
13110
13111
13112
13113
13114
13115
13116
13117
13118
13119
13120
13121
13122
13123
13124
13125
13126
13127
13128
13129
13130
13131
13132
13133
13134
13135
13136
13137
13138
13139
13140
13141
13142
13143
13144
13145
13146
13147
13148
13149
13150
13151
13152
13153
13154
13155
13156
13157
13158
13159
13160
13161
13162
13163
13164
13165
13166
13167
13168
13169
13170
13171
13172
13173
13174
13175
13176
13177
13178
13179
13180
13181
13182
13183
13184
13185
13186
13187
13188
13189
13190
13191
13192
13193
13194
13195
13196
13197
13198
13199
13200
13201
13202
13203
13204
13205
13206
13207
13208
13209
13210
13211
13212
13213
13214
13215
13216
13217
13218
13219
13220
13221
13222
13223
13224
13225
13226
13227
13228
13229
13230
13231
13232
13233
13234
13235
13236
13237
13238
13239
13240
13241
13242
13243
13244
13245
13246
13247
13248
13249
13250
13251
13252
13253
13254
13255
13256
13257
13258
13259
13260
13261
13262
13263
13264
13265
13266
13267
13268
13269
13270
13271
13272
13273
13274
13275
13276
13277
13278
13279
13280
13281
13282
13283
13284
13285
13286
13287
13288
13289
13290
13291
13292
13293
13294
13295
13296
13297
13298
13299
13300
13301
13302
13303
13304
13305
13306
13307
13308
13309
13310
13311
13312
13313
13314
13315
13316
13317
13318
13319
13320
13321
13322
13323
13324
13325
13326
13327
13328
13329
13330
13331
13332
13333
13334
13335
13336
13337
13338
13339
13340
13341
13342
13343
13344
13345
13346
13347
13348
13349
13350
13351
13352
13353
13354
13355
13356
13357
13358
13359
13360
13361
13362
13363
13364
13365
13366
13367
13368
13369
13370
13371
13372
13373
13374
13375
13376
13377
13378
13379
13380
13381
13382
13383
13384
13385
13386
13387
13388
13389
13390
13391
13392
13393
13394
13395
13396
13397
13398
13399
13400
13401
13402
13403
13404
13405
13406
13407
13408
13409
13410
13411
13412
13413
13414
13415
13416
13417
13418
13419
13420
13421
13422
13423
13424
13425
13426
13427
13428
13429
13430
13431
13432
13433
13434
13435
13436
13437
13438
13439
13440
13441
13442
13443
13444
13445
13446
13447
13448
13449
13450
13451
13452
13453
13454
13455
13456
13457
13458
13459
13460
13461
13462
13463
13464
13465
13466
13467
13468
13469
13470
13471
13472
13473
13474
13475
13476
13477
13478
13479
13480
13481
13482
13483
13484
13485
13486
13487
13488
13489
13490
13491
13492
13493
13494
13495
13496
13497
13498
13499
13500
13501
13502
13503
13504
13505
13506
13507
13508
13509
13510
13511
13512
13513
13514
13515
13516
13517
13518
13519
13520
13521
13522
13523
13524
13525
13526
13527
13528
13529
13530
13531
13532
13533
13534
13535
13536
13537
13538
13539
13540
13541
13542
13543
13544
13545
13546
13547
13548
13549
13550
13551
13552
13553
13554
13555
13556
13557
13558
13559
13560
13561
13562
13563
13564
13565
13566
13567
13568
13569
13570
13571
13572
13573
13574
13575
13576
13577
13578
13579
13580
13581
13582
13583
13584
13585
13586
13587
13588
13589
13590
13591
13592
13593
13594
13595
13596
13597
13598
13599
13600
13601
13602
13603
13604
13605
13606
13607
13608
13609
13610
13611
13612
13613
13614
13615
13616
13617
13618
13619
13620
13621
13622
13623
13624
13625
13626
13627
13628
13629
13630
13631
13632
13633
13634
13635
13636
13637
13638
13639
13640
13641
13642
13643
13644
13645
13646
13647
13648
13649
13650
13651
13652
13653
13654
13655
13656
13657
13658
13659
13660
13661
13662
13663
13664
13665
13666
13667
13668
13669
13670
13671
13672
13673
13674
13675
13676
13677
13678
13679
13680
13681
13682
13683
13684
13685
13686
13687
13688
13689
13690
13691
13692
13693
13694
13695
13696
13697
13698
13699
13700
13701
13702
13703
13704
13705
13706
13707
13708
13709
13710
13711
13712
13713
13714
13715
13716
13717
13718
13719
13720
13721
13722
13723
13724
13725
13726
13727
13728
13729
13730
13731
13732
13733
13734
13735
13736
13737
13738
13739
13740
13741
13742
13743
13744
13745
13746
13747
13748
13749
13750
13751
13752
13753
13754
13755
13756
13757
13758
13759
13760
13761
13762
13763
13764
13765
13766
13767
13768
13769
13770
13771
13772
13773
13774
13775
13776
13777
13778
13779
13780
13781
13782
13783
13784
13785
13786
13787
13788
13789
13790
13791
13792
13793
13794
13795
13796
13797
13798
13799
13800
13801
13802
13803
13804
13805
13806
13807
13808
13809
13810
13811
13812
13813
13814
13815
13816
13817
13818
13819
13820
13821
13822
13823
13824
13825
13826
13827
13828
13829
13830
13831
13832
13833
13834
13835
13836
13837
13838
13839
13840
13841
13842
13843
13844
13845
13846
13847
13848
13849
13850
13851
13852
13853
13854
13855
13856
13857
13858
13859
13860
13861
13862
13863
13864
13865
13866
13867
13868
13869
13870
13871
13872
13873
13874
13875
13876
13877
13878
13879
13880
13881
13882
13883
13884
13885
13886
13887
13888
13889
13890
13891
13892
13893
13894
13895
13896
13897
13898
13899
13900
13901
13902
13903
13904
13905
13906
13907
13908
13909
13910
13911
13912
13913
13914
13915
13916
13917
13918
13919
13920
13921
13922
13923
13924
13925
13926
13927
13928
13929
13930
13931
13932
13933
13934
13935
13936
13937
13938
13939
13940
13941
13942
13943
13944
13945
13946
13947
13948
13949
13950
13951
13952
13953
13954
13955
13956
13957
13958
13959
13960
13961
13962
13963
13964
13965
13966
13967
13968
13969
13970
13971
13972
13973
13974
13975
13976
13977
13978
13979
13980
13981
13982
13983
13984
13985
13986
13987
13988
13989
13990
13991
13992
13993
13994
13995
13996
13997
13998
13999
14000
14001
14002
14003
14004
14005
14006
14007
14008
14009
14010
14011
14012
14013
14014
14015
14016
14017
14018
14019
14020
14021
14022
14023
14024
14025
14026
14027
14028
14029
14030
14031
14032
14033
14034
14035
14036
14037
14038
14039
14040
14041
14042
14043
14044
14045
14046
14047
14048
14049
14050
14051
14052
14053
14054
14055
14056
14057
14058
14059
14060
14061
14062
14063
14064
14065
14066
14067
14068
14069
14070
14071
14072
14073
14074
14075
14076
14077
14078
14079
14080
14081
14082
14083
14084
14085
14086
14087
14088
14089
14090
14091
14092
14093
14094
14095
14096
14097
14098
14099
14100
14101
14102
14103
14104
14105
14106
14107
14108
14109
14110
14111
14112
14113
14114
14115
14116
14117
14118
14119
14120
14121
14122
14123
14124
14125
14126
14127
14128
14129
14130
14131
14132
14133
14134
14135
14136
14137
14138
14139
14140
14141
14142
14143
14144
14145
14146
14147
14148
14149
14150
14151
14152
14153
14154
14155
14156
14157
14158
14159
14160
14161
14162
14163
14164
14165
14166
14167
14168
14169
14170
14171
14172
14173
14174
14175
14176
14177
14178
14179
14180
14181
14182
14183
14184
14185
14186
14187
14188
14189
14190
14191
14192
14193
14194
14195
14196
14197
14198
14199
14200
14201
14202
14203
14204
14205
14206
14207
14208
14209
14210
14211
14212
14213
14214
14215
14216
14217
14218
14219
14220
14221
14222
14223
14224
14225
14226
14227
14228
14229
14230
14231
14232
14233
14234
14235
14236
14237
14238
14239
14240
14241
14242
14243
14244
14245
14246
14247
14248
14249
14250
14251
14252
14253
14254
14255
14256
14257
14258
14259
14260
14261
14262
14263
14264
14265
14266
14267
14268
14269
14270
14271
14272
14273
14274
14275
14276
14277
14278
14279
14280
14281
14282
14283
14284
14285
14286
14287
14288
14289
14290
14291
14292
14293
14294
14295
14296
14297
14298
14299
14300
14301
14302
14303
14304
14305
14306
14307
14308
14309
14310
14311
14312
14313
14314
14315
14316
14317
14318
14319
14320
14321
14322
14323
14324
14325
14326
14327
14328
14329
14330
14331
14332
14333
14334
14335
14336
14337
14338
14339
14340
14341
14342
14343
14344
14345
14346
14347
14348
14349
14350
14351
14352
14353
14354
14355
14356
14357
14358
14359
14360
14361
14362
14363
14364
14365
14366
14367
14368
14369
14370
14371
14372
14373
14374
14375
14376
14377
14378
14379
14380
14381
14382
14383
14384
14385
14386
14387
14388
14389
14390
14391
14392
14393
14394
14395
14396
14397
14398
14399
14400
14401
14402
14403
14404
14405
14406
14407
14408
14409
14410
14411
14412
14413
14414
14415
14416
14417
14418
14419
14420
14421
14422
14423
14424
14425
14426
14427
14428
14429
14430
14431
14432
14433
14434
14435
14436
14437
14438
14439
14440
14441
14442
14443
14444
14445
14446
14447
14448
14449
14450
14451
14452
14453
14454
14455
14456
14457
14458
14459
14460
14461
14462
14463
14464
14465
14466
14467
14468
14469
14470
14471
14472
14473
14474
14475
14476
14477
14478
14479
14480
14481
14482
14483
14484
14485
14486
14487
14488
14489
14490
14491
14492
14493
14494
14495
14496
14497
14498
14499
14500
14501
14502
14503
14504
14505
14506
14507
14508
14509
14510
14511
14512
14513
14514
14515
14516
14517
14518
14519
14520
14521
14522
14523
14524
14525
14526
14527
14528
14529
14530
14531
14532
14533
14534
14535
14536
14537
14538
14539
14540
14541
14542
14543
14544
14545
14546
14547
14548
14549
14550
14551
14552
14553
14554
14555
14556
14557
14558
14559
14560
14561
14562
14563
14564
14565
14566
14567
14568
14569
14570
14571
14572
14573
14574
14575
14576
14577
14578
14579
14580
14581
14582
14583
14584
14585
14586
14587
14588
14589
14590
14591
14592
14593
14594
14595
14596
14597
14598
14599
14600
14601
14602
14603
14604
14605
14606
14607
14608
14609
14610
14611
14612
14613
14614
14615
14616
14617
14618
14619
14620
14621
14622
14623
14624
14625
14626
14627
14628
14629
14630
14631
14632
14633
14634
14635
14636
14637
14638
14639
14640
14641
14642
14643
14644
14645
14646
14647
14648
14649
14650
14651
14652
14653
14654
14655
14656
14657
14658
14659
14660
14661
14662
14663
14664
14665
14666
14667
14668
14669
14670
14671
14672
14673
14674
14675
14676
14677
14678
14679
14680
14681
14682
14683
14684
14685
14686
14687
14688
14689
14690
14691
14692
14693
14694
14695
14696
14697
14698
14699
14700
14701
14702
14703
14704
14705
14706
14707
14708
14709
14710
14711
14712
14713
14714
14715
14716
14717
14718
14719
14720
14721
14722
14723
14724
14725
14726
14727
14728
14729
14730
14731
14732
14733
14734
14735
14736
14737
14738
14739
14740
14741
14742
14743
14744
14745
14746
14747
14748
14749
14750
14751
14752
14753
14754
14755
14756
14757
14758
14759
14760
14761
14762
14763
14764
14765
14766
14767
14768
14769
14770
14771
14772
14773
14774
14775
14776
14777
14778
14779
14780
14781
14782
14783
14784
14785
14786
14787
14788
14789
14790
14791
14792
14793
14794
14795
14796
14797
14798
14799
14800
14801
14802
14803
14804
14805
14806
14807
14808
14809
14810
14811
14812
14813
14814
14815
14816
14817
14818
14819
14820
14821
14822
14823
14824
14825
14826
14827
14828
14829
14830
14831
14832
14833
14834
14835
14836
14837
14838
14839
14840
14841
14842
14843
14844
14845
14846
14847
14848
14849
14850
14851
14852
14853
14854
14855
14856
14857
14858
14859
14860
14861
14862
14863
14864
14865
14866
14867
14868
14869
14870
14871
14872
14873
14874
14875
14876
14877
14878
14879
14880
14881
14882
14883
14884
14885
14886
14887
14888
14889
14890
14891
14892
14893
14894
14895
14896
14897
14898
14899
14900
14901
14902
14903
14904
14905
14906
14907
14908
14909
14910
14911
14912
14913
14914
14915
14916
14917
14918
14919
14920
14921
14922
14923
14924
14925
14926
14927
14928
14929
14930
14931
14932
14933
14934
14935
14936
14937
14938
14939
14940
14941
14942
14943
14944
14945
14946
14947
14948
14949
14950
14951
14952
14953
14954
14955
14956
14957
14958
14959
14960
14961
14962
14963
14964
14965
14966
14967
14968
14969
14970
14971
14972
14973
14974
14975
14976
14977
14978
14979
14980
14981
14982
14983
14984
14985
14986
14987
14988
14989
14990
14991
14992
14993
14994
14995
14996
14997
14998
14999
15000
15001
15002
15003
15004
15005
15006
15007
15008
15009
15010
15011
15012
15013
15014
15015
15016
15017
15018
15019
15020
15021
15022
15023
15024
15025
15026
15027
15028
15029
15030
15031
15032
15033
15034
15035
15036
15037
15038
15039
15040
15041
15042
15043
15044
15045
15046
15047
15048
15049
15050
15051
15052
15053
15054
15055
15056
15057
15058
15059
15060
15061
15062
15063
15064
15065
15066
15067
15068
15069
15070
15071
15072
15073
15074
15075
15076
15077
15078
15079
15080
15081
15082
15083
15084
15085
15086
15087
15088
15089
15090
15091
15092
15093
15094
15095
15096
15097
15098
15099
15100
15101
15102
15103
15104
15105
15106
15107
15108
15109
15110
15111
15112
15113
15114
15115
15116
15117
15118
15119
15120
15121
15122
15123
15124
15125
15126
15127
15128
15129
15130
15131
15132
15133
15134
15135
15136
15137
15138
15139
15140
15141
15142
15143
15144
15145
15146
15147
15148
15149
15150
15151
15152
15153
15154
15155
15156
15157
15158
15159
15160
15161
15162
15163
15164
15165
15166
15167
15168
15169
15170
15171
15172
15173
15174
15175
15176
15177
15178
15179
15180
15181
15182
15183
15184
15185
15186
15187
15188
15189
15190
15191
15192
15193
15194
15195
15196
15197
15198
15199
15200
15201
15202
15203
15204
15205
15206
15207
15208
15209
15210
15211
15212
15213
15214
15215
15216
15217
15218
15219
15220
15221
15222
15223
15224
15225
15226
15227
15228
15229
15230
15231
15232
15233
15234
15235
15236
15237
15238
15239
15240
15241
15242
15243
15244
15245
15246
15247
15248
15249
15250
15251
15252
15253
15254
15255
15256
15257
15258
15259
15260
15261
15262
15263
15264
15265
15266
15267
15268
15269
15270
15271
15272
15273
15274
15275
15276
15277
15278
15279
15280
15281
15282
15283
15284
15285
15286
15287
15288
15289
15290
15291
15292
15293
15294
15295
15296
15297
15298
15299
15300
15301
15302
15303
15304
15305
15306
15307
15308
15309
15310
15311
15312
15313
15314
15315
15316
15317
15318
15319
15320
15321
15322
15323
15324
15325
15326
15327
15328
15329
15330
15331
15332
15333
15334
15335
15336
15337
15338
15339
15340
15341
15342
15343
15344
15345
15346
15347
15348
15349
15350
15351
15352
15353
15354
15355
15356
15357
15358
15359
15360
15361
15362
15363
15364
15365
15366
15367
15368
15369
15370
15371
15372
15373
15374
15375
15376
15377
15378
15379
15380
15381
15382
15383
15384
15385
15386
15387
15388
15389
15390
15391
15392
15393
15394
15395
15396
15397
15398
15399
15400
15401
15402
15403
15404
15405
15406
15407
15408
15409
15410
15411
15412
15413
15414
15415
15416
15417
15418
15419
15420
15421
15422
15423
15424
15425
15426
15427
15428
15429
15430
15431
15432
15433
15434
15435
15436
15437
15438
15439
15440
15441
15442
15443
15444
15445
15446
15447
15448
15449
15450
15451
15452
15453
15454
15455
15456
15457
15458
15459
15460
15461
15462
15463
15464
15465
15466
15467
15468
15469
15470
15471
15472
15473
15474
15475
15476
15477
15478
15479
15480
15481
15482
15483
15484
15485
15486
15487
15488
15489
15490
15491
15492
15493
15494
15495
15496
15497
15498
15499
15500
15501
15502
15503
15504
15505
15506
15507
15508
15509
15510
15511
15512
15513
15514
15515
15516
15517
15518
15519
15520
15521
15522
15523
15524
15525
15526
15527
15528
15529
15530
15531
15532
15533
15534
15535
15536
15537
15538
15539
15540
15541
15542
15543
15544
15545
15546
15547
15548
15549
15550
15551
15552
15553
15554
15555
15556
15557
15558
15559
15560
15561
15562
15563
15564
15565
15566
15567
15568
15569
15570
15571
15572
15573
15574
15575
15576
15577
15578
15579
15580
15581
15582
15583
15584
15585
15586
15587
15588
15589
15590
15591
15592
15593
15594
15595
15596
15597
15598
15599
15600
15601
15602
15603
15604
15605
15606
15607
15608
15609
15610
15611
15612
15613
15614
15615
15616
15617
15618
15619
15620
15621
15622
15623
15624
15625
15626
15627
15628
15629
15630
15631
15632
15633
15634
15635
15636
15637
15638
15639
15640
15641
15642
15643
15644
15645
15646
15647
15648
15649
15650
15651
15652
15653
15654
15655
15656
15657
15658
15659
15660
15661
15662
15663
15664
15665
15666
15667
15668
15669
15670
15671
15672
15673
15674
15675
15676
15677
15678
15679
15680
15681
15682
15683
15684
15685
15686
15687
15688
15689
15690
15691
15692
15693
15694
15695
15696
15697
15698
15699
15700
15701
15702
15703
15704
15705
15706
15707
15708
15709
15710
15711
15712
15713
15714
15715
15716
15717
15718
15719
15720
15721
15722
15723
15724
15725
15726
15727
15728
15729
15730
15731
15732
15733
15734
15735
15736
15737
15738
15739
15740
15741
15742
15743
15744
15745
15746
15747
15748
15749
15750
15751
15752
15753
15754
15755
15756
15757
15758
15759
15760
15761
15762
15763
15764
15765
15766
15767
15768
15769
15770
15771
15772
15773
15774
15775
15776
15777
15778
15779
15780
15781
15782
15783
15784
15785
15786
15787
15788
15789
15790
15791
15792
15793
15794
15795
15796
15797
15798
15799
15800
15801
15802
15803
15804
15805
15806
15807
15808
15809
15810
15811
15812
15813
15814
15815
15816
15817
15818
15819
15820
15821
15822
15823
15824
15825
15826
15827
15828
15829
15830
15831
15832
15833
15834
15835
15836
15837
15838
15839
15840
15841
15842
15843
15844
15845
15846
15847
15848
15849
15850
15851
15852
15853
15854
15855
15856
15857
15858
15859
15860
15861
15862
15863
15864
15865
15866
15867
15868
15869
15870
15871
15872
15873
15874
15875
15876
15877
15878
15879
15880
15881
15882
15883
15884
15885
15886
15887
15888
15889
15890
15891
15892
15893
15894
15895
15896
15897
15898
15899
15900
15901
15902
15903
15904
15905
15906
15907
15908
15909
15910
15911
15912
15913
15914
15915
15916
15917
15918
15919
15920
15921
15922
15923
15924
15925
15926
15927
15928
15929
15930
15931
15932
15933
15934
15935
15936
15937
15938
15939
15940
15941
15942
15943
15944
15945
15946
15947
15948
15949
15950
15951
15952
15953
15954
15955
15956
15957
15958
15959
15960
15961
15962
15963
15964
15965
15966
15967
15968
15969
15970
15971
15972
15973
15974
15975
15976
15977
15978
15979
15980
15981
15982
15983
15984
15985
15986
15987
15988
15989
15990
15991
15992
15993
15994
15995
15996
15997
15998
15999
16000
16001
16002
16003
16004
16005
16006
16007
16008
16009
16010
16011
16012
16013
16014
16015
16016
16017
16018
16019
16020
16021
16022
16023
16024
16025
16026
16027
16028
16029
16030
16031
16032
16033
16034
16035
16036
16037
16038
16039
16040
16041
16042
16043
16044
16045
16046
16047
16048
16049
16050
16051
16052
16053
16054
16055
16056
16057
16058
16059
16060
16061
16062
16063
16064
16065
16066
16067
16068
16069
16070
16071
16072
16073
16074
16075
16076
16077
16078
16079
16080
16081
16082
16083
16084
16085
16086
16087
16088
16089
16090
16091
16092
16093
16094
16095
16096
16097
16098
16099
16100
16101
16102
16103
16104
16105
16106
16107
16108
16109
16110
16111
16112
16113
16114
16115
16116
16117
16118
16119
16120
16121
16122
16123
16124
16125
16126
16127
16128
16129
16130
16131
16132
16133
16134
16135
16136
16137
16138
16139
16140
16141
16142
16143
16144
16145
16146
16147
16148
16149
16150
16151
16152
16153
16154
16155
16156
16157
16158
16159
16160
16161
16162
16163
16164
16165
16166
16167
16168
16169
16170
16171
16172
16173
16174
16175
16176
16177
16178
16179
16180
16181
16182
16183
16184
16185
16186
16187
16188
16189
16190
16191
16192
16193
16194
16195
16196
16197
16198
16199
16200
16201
16202
16203
16204
16205
16206
16207
16208
16209
16210
16211
16212
16213
16214
16215
16216
16217
16218
16219
16220
16221
16222
16223
16224
16225
16226
16227
16228
16229
16230
16231
16232
16233
16234
16235
16236
16237
16238
16239
16240
16241
16242
16243
16244
16245
16246
16247
16248
16249
16250
16251
16252
16253
16254
16255
16256
16257
16258
16259
16260
16261
16262
16263
16264
16265
16266
16267
16268
16269
16270
16271
16272
16273
16274
16275
16276
16277
16278
16279
16280
16281
16282
16283
16284
16285
16286
16287
16288
16289
16290
16291
16292
16293
16294
16295
16296
16297
16298
16299
16300
16301
16302
16303
16304
16305
16306
16307
16308
16309
16310
16311
16312
16313
16314
16315
16316
16317
16318
16319
16320
16321
16322
16323
16324
16325
16326
16327
16328
16329
16330
16331
16332
16333
16334
16335
16336
16337
16338
16339
16340
16341
16342
16343
16344
16345
16346
16347
16348
16349
16350
16351
16352
16353
16354
16355
16356
16357
16358
16359
16360
16361
16362
16363
16364
16365
16366
16367
16368
16369
16370
16371
16372
16373
16374
16375
16376
16377
16378
16379
16380
16381
16382
16383
16384
16385
16386
16387
16388
16389
16390
16391
16392
16393
16394
16395
16396
16397
16398
16399
16400
16401
16402
16403
16404
16405
16406
16407
16408
16409
16410
16411
16412
16413
16414
16415
16416
16417
16418
16419
16420
16421
16422
16423
16424
16425
16426
16427
16428
16429
16430
16431
16432
16433
16434
16435
16436
16437
16438
16439
16440
16441
16442
16443
16444
16445
16446
16447
16448
16449
16450
16451
16452
16453
16454
16455
16456
16457
16458
16459
16460
16461
16462
16463
16464
16465
16466
16467
16468
16469
16470
16471
16472
16473
16474
16475
16476
16477
16478
16479
16480
16481
16482
16483
16484
16485
16486
16487
16488
16489
16490
16491
16492
16493
16494
16495
16496
16497
16498
16499
16500
16501
16502
16503
16504
16505
16506
16507
16508
16509
16510
16511
16512
16513
16514
16515
16516
16517
16518
16519
16520
16521
16522
16523
16524
16525
16526
16527
16528
16529
16530
16531
16532
16533
16534
16535
16536
16537
16538
16539
16540
16541
16542
16543
16544
16545
16546
16547
16548
16549
16550
16551
16552
16553
16554
16555
16556
16557
16558
16559
16560
16561
16562
16563
16564
16565
16566
16567
16568
16569
16570
16571
16572
16573
16574
16575
16576
16577
16578
16579
16580
16581
16582
16583
16584
16585
16586
16587
16588
16589
16590
16591
16592
16593
16594
16595
16596
16597
16598
16599
16600
16601
16602
16603
16604
16605
16606
16607
16608
16609
16610
16611
16612
16613
16614
16615
16616
16617
16618
16619
16620
16621
16622
16623
16624
16625
16626
16627
16628
16629
16630
16631
16632
16633
16634
16635
16636
16637
16638
16639
16640
16641
16642
16643
16644
16645
16646
16647
16648
16649
16650
16651
16652
16653
16654
16655
16656
16657
16658
16659
16660
16661
16662
16663
16664
16665
16666
16667
16668
16669
16670
16671
16672
16673
16674
16675
16676
16677
16678
16679
16680
16681
16682
16683
16684
16685
16686
16687
16688
16689
16690
16691
16692
16693
16694
16695
16696
16697
16698
16699
16700
16701
16702
16703
16704
16705
16706
16707
16708
16709
16710
16711
16712
16713
16714
16715
16716
16717
16718
16719
16720
16721
16722
16723
16724
16725
16726
16727
16728
16729
16730
16731
16732
16733
16734
16735
16736
16737
16738
16739
16740
16741
16742
16743
16744
16745
16746
16747
16748
16749
16750
16751
16752
16753
16754
16755
16756
16757
16758
16759
16760
16761
16762
16763
16764
16765
16766
16767
16768
16769
16770
16771
16772
16773
16774
16775
16776
16777
16778
16779
16780
16781
16782
16783
16784
16785
16786
16787
16788
16789
16790
16791
16792
16793
16794
16795
16796
16797
16798
16799
16800
16801
16802
16803
16804
16805
16806
16807
16808
16809
16810
16811
16812
16813
16814
16815
16816
16817
16818
16819
16820
16821
16822
16823
16824
16825
16826
16827
16828
16829
16830
16831
16832
16833
16834
16835
16836
16837
16838
16839
16840
16841
16842
16843
16844
16845
16846
16847
16848
16849
16850
16851
16852
16853
16854
16855
16856
16857
16858
16859
16860
16861
16862
16863
16864
16865
16866
16867
16868
16869
16870
16871
16872
16873
16874
16875
16876
16877
16878
16879
16880
16881
16882
16883
16884
16885
16886
16887
16888
16889
16890
16891
16892
16893
16894
16895
16896
16897
16898
16899
16900
16901
16902
16903
16904
16905
16906
16907
16908
16909
16910
16911
16912
16913
16914
16915
16916
16917
16918
16919
16920
16921
16922
16923
16924
16925
16926
16927
16928
16929
16930
16931
16932
16933
16934
16935
16936
16937
16938
16939
16940
16941
16942
16943
16944
16945
16946
16947
16948
16949
16950
16951
16952
16953
16954
16955
16956
16957
16958
16959
16960
16961
16962
16963
16964
16965
16966
16967
16968
16969
16970
16971
16972
16973
16974
16975
16976
16977
16978
16979
16980
16981
16982
16983
16984
16985
16986
16987
16988
16989
16990
16991
16992
16993
16994
16995
16996
16997
16998
16999
17000
17001
17002
17003
17004
17005
17006
17007
17008
17009
17010
17011
17012
17013
17014
17015
17016
17017
17018
17019
17020
17021
17022
17023
17024
17025
17026
17027
17028
17029
17030
17031
17032
17033
17034
17035
17036
17037
17038
17039
17040
17041
17042
17043
17044
17045
17046
17047
17048
17049
17050
17051
17052
17053
17054
17055
17056
17057
17058
17059
17060
17061
17062
17063
17064
17065
17066
17067
17068
17069
17070
17071
17072
17073
17074
17075
17076
17077
17078
17079
17080
17081
17082
17083
17084
17085
17086
17087
17088
17089
17090
17091
17092
17093
17094
17095
17096
17097
17098
17099
17100
17101
17102
17103
17104
17105
17106
17107
17108
17109
17110
17111
17112
17113
17114
17115
17116
17117
17118
17119
17120
17121
17122
17123
17124
17125
17126
17127
17128
17129
17130
17131
17132
17133
17134
17135
17136
17137
17138
17139
17140
17141
17142
17143
17144
17145
17146
17147
17148
17149
17150
17151
17152
17153
17154
17155
17156
17157
17158
17159
17160
17161
17162
17163
17164
17165
17166
17167
17168
17169
17170
17171
17172
17173
17174
17175
17176
17177
17178
17179
17180
17181
17182
17183
17184
17185
17186
17187
17188
17189
17190
17191
17192
17193
17194
17195
17196
17197
17198
17199
17200
17201
17202
17203
17204
17205
17206
17207
17208
17209
17210
17211
17212
17213
17214
17215
17216
17217
17218
17219
17220
17221
17222
17223
17224
17225
17226
17227
17228
17229
17230
17231
17232
17233
17234
17235
17236
17237
17238
17239
17240
17241
17242
17243
17244
17245
17246
17247
17248
17249
17250
17251
17252
17253
17254
17255
17256
17257
17258
17259
17260
17261
17262
17263
17264
17265
17266
17267
17268
17269
17270
17271
17272
17273
17274
17275
17276
17277
17278
17279
17280
17281
17282
17283
17284
17285
17286
17287
17288
17289
17290
17291
17292
17293
17294
17295
17296
17297
17298
17299
17300
17301
17302
17303
17304
17305
17306
17307
17308
17309
17310
17311
17312
17313
17314
17315
17316
17317
17318
17319
17320
17321
17322
17323
17324
17325
17326
17327
17328
17329
17330
17331
17332
17333
17334
17335
17336
17337
17338
17339
17340
17341
17342
17343
17344
17345
17346
17347
17348
17349
17350
17351
17352
17353
17354
17355
17356
17357
17358
17359
17360
17361
17362
17363
17364
17365
17366
17367
17368
17369
17370
17371
17372
17373
17374
17375
17376
17377
17378
17379
17380
17381
17382
17383
17384
17385
17386
17387
17388
17389
17390
17391
17392
17393
17394
17395
17396
17397
17398
17399
17400
17401
17402
17403
17404
17405
17406
17407
17408
17409
17410
17411
17412
17413
17414
17415
17416
17417
17418
17419
17420
17421
17422
17423
17424
17425
17426
17427
17428
17429
17430
17431
17432
17433
17434
17435
17436
17437
17438
17439
17440
17441
17442
17443
17444
17445
17446
17447
17448
17449
17450
17451
17452
17453
17454
17455
17456
17457
17458
17459
17460
17461
17462
17463
17464
17465
17466
17467
17468
17469
17470
17471
17472
17473
17474
17475
17476
17477
17478
17479
17480
17481
17482
17483
17484
17485
17486
17487
17488
17489
17490
17491
17492
17493
17494
17495
17496
17497
17498
17499
17500
17501
17502
17503
17504
17505
17506
17507
17508
17509
17510
17511
17512
17513
17514
17515
17516
17517
17518
17519
17520
17521
17522
17523
17524
17525
17526
17527
17528
17529
17530
17531
17532
17533
17534
17535
17536
17537
17538
17539
17540
17541
17542
17543
17544
17545
17546
17547
17548
17549
17550
17551
17552
17553
17554
17555
17556
17557
17558
17559
17560
17561
17562
17563
17564
17565
17566
17567
17568
17569
17570
17571
17572
17573
17574
17575
17576
17577
17578
17579
17580
17581
17582
17583
17584
17585
17586
17587
17588
17589
17590
17591
17592
17593
17594
17595
17596
17597
17598
17599
17600
17601
17602
17603
17604
17605
17606
17607
17608
17609
17610
17611
17612
17613
17614
17615
17616
17617
17618
17619
17620
17621
17622
17623
17624
17625
17626
17627
17628
17629
17630
17631
17632
17633
17634
17635
17636
17637
17638
17639
17640
17641
17642
17643
17644
17645
17646
17647
17648
17649
17650
17651
17652
17653
17654
17655
17656
17657
17658
17659
17660
17661
17662
17663
17664
17665
17666
17667
17668
17669
17670
17671
17672
17673
17674
17675
17676
17677
17678
17679
17680
17681
17682
17683
17684
17685
17686
17687
17688
17689
17690
17691
17692
17693
17694
17695
17696
17697
17698
17699
17700
17701
17702
17703
17704
17705
17706
17707
17708
17709
17710
17711
17712
17713
17714
17715
17716
17717
17718
17719
17720
17721
17722
17723
17724
17725
17726
17727
17728
17729
17730
17731
17732
17733
17734
17735
17736
17737
17738
17739
17740
17741
17742
17743
17744
17745
17746
17747
17748
17749
17750
17751
17752
17753
17754
17755
17756
17757
17758
17759
17760
17761
17762
17763
17764
17765
17766
17767
17768
17769
17770
17771
17772
17773
17774
17775
17776
17777
17778
17779
17780
17781
17782
17783
17784
17785
17786
17787
17788
17789
17790
17791
17792
17793
17794
17795
17796
17797
17798
17799
17800
17801
17802
17803
17804
17805
17806
17807
17808
17809
17810
17811
17812
17813
17814
17815
17816
17817
17818
17819
17820
17821
17822
17823
17824
17825
17826
17827
17828
17829
17830
17831
17832
17833
17834
17835
17836
17837
17838
17839
17840
17841
17842
17843
17844
17845
17846
17847
17848
17849
17850
17851
17852
17853
17854
17855
17856
17857
17858
17859
17860
17861
17862
17863
17864
17865
17866
17867
17868
17869
17870
17871
17872
17873
17874
17875
17876
17877
17878
17879
17880
17881
17882
17883
17884
17885
17886
17887
17888
17889
17890
17891
17892
17893
17894
17895
17896
17897
17898
17899
17900
17901
17902
17903
17904
17905
17906
17907
17908
17909
17910
17911
17912
17913
17914
17915
17916
17917
17918
17919
17920
17921
17922
17923
17924
17925
17926
17927
17928
17929
17930
17931
17932
17933
17934
17935
17936
17937
17938
17939
17940
17941
17942
17943
17944
17945
17946
17947
17948
17949
17950
17951
17952
17953
17954
17955
17956
17957
17958
17959
17960
17961
17962
17963
17964
17965
17966
17967
17968
17969
17970
17971
17972
17973
17974
17975
17976
17977
17978
17979
17980
17981
17982
17983
17984
17985
17986
17987
17988
17989
17990
17991
17992
17993
17994
17995
17996
17997
17998
17999
18000
18001
18002
18003
18004
18005
18006
18007
18008
18009
18010
18011
18012
18013
18014
18015
18016
18017
18018
18019
18020
18021
18022
18023
18024
18025
18026
18027
18028
18029
18030
18031
18032
18033
18034
18035
18036
18037
18038
18039
18040
18041
18042
18043
18044
18045
18046
18047
18048
18049
18050
18051
18052
18053
18054
18055
18056
18057
18058
18059
18060
18061
18062
18063
18064
18065
18066
18067
18068
18069
18070
18071
18072
18073
18074
18075
18076
18077
18078
18079
18080
18081
18082
18083
18084
18085
18086
18087
18088
18089
18090
18091
18092
18093
18094
18095
18096
18097
18098
18099
18100
18101
18102
18103
18104
18105
18106
18107
18108
18109
18110
18111
18112
18113
18114
18115
18116
18117
18118
18119
18120
18121
18122
18123
18124
18125
18126
18127
18128
18129
18130
18131
18132
18133
18134
18135
18136
18137
18138
18139
18140
18141
18142
18143
18144
18145
18146
18147
18148
18149
18150
18151
18152
18153
18154
18155
18156
18157
18158
18159
18160
18161
18162
18163
18164
18165
18166
18167
18168
18169
18170
18171
18172
18173
18174
18175
18176
18177
18178
18179
18180
18181
18182
18183
18184
18185
18186
18187
18188
18189
18190
18191
18192
18193
18194
18195
18196
18197
18198
18199
18200
18201
18202
18203
18204
18205
18206
18207
18208
18209
18210
18211
18212
18213
18214
18215
18216
18217
18218
18219
18220
18221
18222
18223
18224
18225
18226
18227
18228
18229
18230
18231
18232
18233
18234
18235
18236
18237
18238
18239
18240
18241
18242
18243
18244
18245
18246
18247
18248
18249
18250
18251
18252
18253
18254
18255
18256
18257
18258
18259
18260
18261
18262
18263
18264
18265
18266
18267
18268
18269
18270
18271
18272
18273
18274
18275
18276
18277
18278
18279
18280
18281
18282
18283
18284
18285
18286
18287
18288
18289
18290
18291
18292
18293
18294
18295
18296
18297
18298
18299
18300
18301
18302
18303
18304
18305
18306
18307
18308
18309
18310
18311
18312
18313
18314
18315
18316
18317
18318
18319
18320
18321
18322
18323
18324
18325
18326
18327
18328
18329
18330
18331
18332
18333
18334
18335
18336
18337
18338
18339
18340
18341
18342
18343
18344
18345
18346
18347
18348
18349
18350
18351
18352
18353
18354
18355
18356
18357
18358
18359
18360
18361
18362
18363
18364
18365
18366
18367
18368
18369
18370
18371
18372
18373
18374
18375
18376
18377
18378
18379
18380
18381
18382
18383
18384
18385
18386
18387
18388
18389
18390
18391
18392
18393
18394
18395
18396
18397
18398
18399
18400
18401
18402
18403
18404
18405
18406
18407
18408
18409
18410
18411
18412
18413
18414
18415
18416
18417
18418
18419
18420
18421
18422
18423
18424
18425
18426
18427
18428
18429
18430
18431
18432
18433
18434
18435
18436
18437
18438
18439
18440
18441
18442
18443
18444
18445
18446
18447
18448
18449
18450
18451
18452
18453
18454
18455
18456
18457
18458
18459
18460
18461
18462
18463
18464
18465
18466
18467
18468
18469
18470
18471
18472
18473
18474
18475
18476
18477
18478
18479
18480
18481
18482
18483
18484
18485
18486
18487
18488
18489
18490
18491
18492
18493
18494
18495
18496
18497
18498
18499
18500
18501
18502
18503
18504
18505
18506
18507
18508
18509
18510
18511
18512
18513
18514
18515
18516
18517
18518
18519
18520
18521
18522
18523
18524
18525
18526
18527
18528
18529
18530
18531
18532
18533
18534
18535
18536
18537
18538
18539
18540
18541
18542
18543
18544
18545
18546
18547
18548
18549
18550
18551
18552
18553
18554
18555
18556
18557
18558
18559
18560
18561
18562
18563
18564
18565
18566
18567
18568
18569
18570
18571
18572
18573
18574
18575
18576
18577
18578
18579
18580
18581
18582
18583
18584
18585
18586
18587
18588
18589
18590
18591
18592
18593
18594
18595
18596
18597
18598
18599
18600
18601
18602
18603
18604
18605
18606
18607
18608
18609
18610
18611
18612
18613
18614
18615
18616
18617
18618
18619
18620
18621
18622
18623
18624
18625
18626
18627
18628
18629
18630
18631
18632
18633
18634
18635
18636
18637
18638
18639
18640
18641
18642
18643
18644
18645
18646
18647
18648
18649
18650
18651
18652
18653
18654
18655
18656
18657
18658
18659
18660
18661
18662
18663
18664
18665
18666
18667
18668
18669
18670
18671
18672
18673
18674
18675
18676
18677
18678
18679
18680
18681
18682
18683
18684
18685
18686
18687
18688
18689
18690
18691
18692
18693
18694
18695
18696
18697
18698
18699
18700
18701
18702
18703
18704
18705
18706
18707
18708
18709
18710
18711
18712
18713
18714
18715
18716
18717
18718
18719
18720
18721
18722
18723
18724
18725
18726
18727
18728
18729
18730
18731
18732
18733
18734
18735
18736
18737
18738
18739
18740
18741
18742
18743
18744
18745
18746
18747
18748
18749
18750
18751
18752
18753
18754
18755
18756
18757
18758
18759
18760
18761
18762
18763
18764
18765
18766
18767
18768
18769
18770
18771
18772
18773
18774
18775
18776
18777
18778
18779
18780
18781
18782
18783
18784
18785
18786
18787
18788
18789
18790
18791
18792
18793
18794
18795
18796
18797
18798
18799
18800
18801
18802
18803
18804
18805
18806
18807
18808
18809
18810
18811
18812
18813
18814
18815
18816
18817
18818
18819
18820
18821
18822
18823
18824
18825
18826
18827
18828
18829
18830
18831
18832
18833
18834
18835
18836
18837
18838
18839
18840
18841
18842
18843
18844
18845
18846
18847
18848
18849
18850
18851
18852
18853
18854
18855
18856
18857
18858
18859
18860
18861
18862
18863
18864
18865
18866
18867
18868
18869
18870
18871
18872
18873
18874
18875
18876
18877
18878
18879
18880
18881
18882
18883
18884
18885
18886
18887
18888
18889
18890
18891
18892
18893
18894
18895
18896
18897
18898
18899
18900
18901
18902
18903
18904
18905
18906
18907
18908
18909
18910
18911
18912
18913
18914
18915
18916
18917
18918
18919
18920
18921
18922
18923
18924
18925
18926
18927
18928
18929
18930
18931
18932
18933
18934
18935
18936
18937
18938
18939
18940
18941
18942
18943
18944
18945
18946
18947
18948
18949
18950
18951
18952
18953
18954
18955
18956
18957
18958
18959
18960
18961
18962
18963
18964
18965
18966
18967
18968
18969
18970
18971
18972
18973
18974
18975
18976
18977
18978
18979
18980
18981
18982
18983
18984
18985
18986
18987
18988
18989
18990
18991
18992
18993
18994
18995
18996
18997
18998
18999
19000
19001
19002
19003
19004
19005
19006
19007
19008
19009
19010
19011
19012
19013
19014
19015
19016
19017
19018
19019
19020
19021
19022
19023
19024
19025
19026
19027
19028
19029
19030
19031
19032
19033
19034
19035
19036
19037
19038
19039
19040
19041
19042
19043
19044
19045
19046
19047
19048
19049
19050
19051
19052
19053
19054
19055
19056
19057
19058
19059
19060
19061
19062
19063
19064
19065
19066
19067
19068
19069
19070
19071
19072
19073
19074
19075
19076
19077
19078
19079
19080
19081
19082
19083
19084
19085
19086
19087
19088
19089
19090
19091
19092
19093
19094
19095
19096
19097
19098
19099
19100
19101
19102
19103
19104
19105
19106
19107
19108
19109
19110
19111
19112
19113
19114
19115
19116
19117
19118
19119
19120
19121
19122
19123
19124
19125
19126
19127
19128
19129
19130
19131
19132
19133
19134
19135
19136
19137
19138
19139
19140
19141
19142
19143
19144
19145
19146
19147
19148
19149
19150
19151
19152
19153
19154
19155
19156
19157
19158
19159
19160
19161
19162
19163
19164
19165
19166
19167
19168
19169
19170
19171
19172
19173
19174
19175
19176
19177
19178
19179
19180
19181
19182
19183
19184
19185
19186
19187
19188
19189
19190
19191
19192
19193
19194
19195
19196
19197
19198
19199
19200
19201
19202
19203
19204
19205
19206
19207
19208
19209
19210
19211
19212
19213
19214
19215
19216
19217
19218
19219
19220
19221
19222
19223
19224
19225
19226
19227
19228
19229
19230
19231
19232
19233
19234
19235
19236
19237
19238
19239
19240
19241
19242
19243
19244
19245
19246
19247
19248
19249
19250
19251
19252
19253
19254
19255
19256
19257
19258
19259
19260
19261
19262
19263
19264
19265
19266
19267
19268
19269
19270
19271
19272
19273
19274
19275
19276
19277
19278
19279
19280
19281
19282
19283
19284
19285
19286
19287
19288
19289
19290
19291
19292
19293
19294
19295
19296
19297
19298
19299
19300
19301
19302
19303
19304
19305
19306
19307
19308
19309
19310
19311
19312
19313
19314
19315
19316
19317
19318
19319
19320
19321
19322
19323
19324
19325
19326
19327
19328
19329
19330
19331
19332
19333
19334
19335
19336
19337
19338
19339
19340
19341
19342
19343
19344
19345
19346
19347
19348
19349
19350
19351
19352
19353
19354
19355
19356
19357
19358
19359
19360
19361
19362
19363
19364
19365
19366
19367
19368
19369
19370
19371
19372
19373
19374
19375
19376
19377
19378
19379
19380
19381
19382
19383
19384
19385
19386
19387
19388
19389
19390
19391
19392
19393
19394
19395
19396
19397
19398
19399
19400
19401
19402
19403
19404
19405
19406
19407
19408
19409
19410
19411
19412
19413
19414
19415
19416
19417
19418
19419
19420
19421
19422
19423
19424
19425
19426
19427
19428
19429
19430
19431
19432
19433
19434
19435
19436
19437
19438
19439
19440
19441
19442
19443
19444
19445
19446
19447
19448
19449
19450
19451
19452
19453
19454
19455
19456
19457
19458
19459
19460
19461
19462
19463
19464
19465
19466
19467
19468
19469
19470
19471
19472
19473
19474
19475
19476
19477
19478
19479
19480
19481
19482
19483
19484
19485
19486
19487
19488
19489
19490
19491
19492
19493
19494
19495
19496
19497
19498
19499
19500
19501
19502
19503
19504
19505
19506
19507
19508
19509
19510
19511
19512
19513
19514
19515
19516
19517
19518
19519
19520
19521
19522
19523
19524
19525
19526
19527
19528
19529
19530
19531
19532
19533
19534
19535
19536
19537
19538
19539
19540
19541
19542
19543
19544
19545
19546
19547
19548
19549
19550
19551
19552
19553
19554
19555
19556
19557
19558
19559
19560
19561
19562
19563
19564
19565
19566
19567
19568
19569
19570
19571
19572
19573
19574
19575
19576
19577
19578
19579
19580
19581
19582
19583
19584
19585
19586
19587
19588
19589
19590
19591
19592
19593
19594
19595
19596
19597
19598
19599
19600
19601
19602
19603
19604
19605
19606
19607
19608
19609
19610
19611
19612
19613
19614
19615
19616
19617
19618
19619
19620
19621
19622
19623
19624
19625
19626
19627
19628
19629
19630
19631
19632
19633
19634
19635
19636
19637
19638
19639
19640
19641
19642
19643
19644
19645
19646
19647
19648
19649
19650
19651
19652
19653
19654
19655
19656
19657
19658
19659
19660
19661
19662
19663
19664
19665
19666
19667
19668
19669
19670
19671
19672
19673
19674
19675
19676
19677
19678
19679
19680
19681
19682
19683
19684
19685
19686
19687
19688
19689
19690
19691
19692
19693
19694
19695
19696
19697
19698
19699
19700
19701
19702
19703
19704
19705
19706
19707
19708
19709
19710
19711
19712
19713
19714
19715
19716
19717
19718
19719
19720
19721
19722
19723
19724
19725
19726
19727
19728
19729
19730
19731
19732
19733
19734
19735
19736
19737
19738
19739
19740
19741
19742
19743
19744
19745
19746
19747
19748
19749
19750
19751
19752
19753
19754
19755
19756
19757
19758
19759
19760
19761
19762
19763
19764
19765
19766
19767
19768
19769
19770
19771
19772
19773
19774
19775
19776
19777
19778
19779
19780
19781
19782
19783
19784
19785
19786
19787
19788
19789
19790
19791
19792
19793
19794
19795
19796
19797
19798
19799
19800
19801
19802
19803
19804
19805
19806
19807
19808
19809
19810
19811
19812
19813
19814
19815
19816
19817
19818
19819
19820
19821
19822
19823
19824
19825
19826
19827
19828
19829
19830
19831
19832
19833
19834
19835
19836
19837
19838
19839
19840
19841
19842
19843
19844
19845
19846
19847
19848
19849
19850
19851
19852
19853
19854
19855
19856
19857
19858
19859
19860
19861
19862
19863
19864
19865
19866
19867
19868
19869
19870
19871
19872
19873
19874
19875
19876
19877
19878
19879
19880
19881
19882
19883
19884
19885
19886
19887
19888
19889
19890
19891
19892
19893
19894
19895
19896
19897
19898
19899
19900
19901
19902
19903
19904
19905
19906
19907
19908
19909
19910
19911
19912
19913
19914
19915
19916
19917
19918
19919
19920
19921
19922
19923
19924
19925
19926
19927
19928
19929
19930
19931
19932
19933
19934
19935
19936
19937
19938
19939
19940
19941
19942
19943
19944
19945
19946
19947
19948
19949
19950
19951
19952
19953
19954
19955
19956
19957
19958
19959
19960
19961
19962
19963
19964
19965
19966
19967
19968
19969
19970
19971
19972
19973
19974
19975
19976
19977
19978
19979
19980
19981
19982
19983
19984
19985
19986
19987
19988
19989
19990
19991
19992
19993
19994
19995
19996
19997
19998
19999
20000
20001
20002
20003
20004
20005
20006
20007
20008
20009
20010
20011
20012
20013
20014
20015
20016
20017
20018
20019
20020
20021
20022
20023
20024
20025
20026
20027
20028
20029
20030
20031
20032
20033
20034
20035
20036
20037
20038
20039
20040
20041
20042
20043
20044
20045
20046
20047
20048
20049
20050
20051
20052
20053
20054
20055
20056
20057
20058
20059
20060
20061
20062
20063
20064
20065
20066
20067
20068
20069
20070
20071
20072
20073
20074
20075
20076
20077
20078
20079
20080
20081
20082
20083
20084
20085
20086
20087
20088
20089
20090
20091
20092
20093
20094
20095
20096
20097
20098
20099
20100
20101
20102
20103
20104
20105
20106
20107
20108
20109
20110
20111
20112
20113
20114
20115
20116
20117
20118
20119
20120
20121
20122
20123
20124
20125
20126
20127
20128
20129
20130
20131
20132
20133
20134
20135
20136
20137
20138
20139
20140
20141
20142
20143
20144
20145
20146
20147
20148
20149
20150
20151
20152
20153
20154
20155
20156
20157
20158
20159
20160
20161
20162
20163
20164
20165
20166
20167
20168
20169
20170
20171
20172
20173
20174
20175
20176
20177
20178
20179
20180
20181
20182
20183
20184
20185
20186
20187
20188
20189
20190
20191
20192
20193
20194
20195
20196
20197
20198
20199
20200
20201
20202
20203
20204
20205
20206
20207
20208
20209
20210
20211
20212
20213
20214
20215
20216
20217
20218
20219
20220
20221
20222
20223
20224
20225
20226
20227
20228
20229
20230
20231
20232
20233
20234
20235
20236
20237
20238
20239
20240
20241
20242
20243
20244
20245
20246
20247
20248
20249
20250
20251
20252
20253
20254
20255
20256
20257
20258
20259
20260
20261
20262
20263
20264
20265
20266
20267
20268
20269
20270
20271
20272
20273
20274
20275
20276
20277
20278
20279
20280
20281
20282
20283
20284
20285
20286
20287
20288
20289
20290
20291
20292
20293
20294
20295
20296
20297
20298
20299
20300
20301
20302
20303
20304
20305
20306
20307
20308
20309
20310
20311
20312
20313
20314
20315
20316
20317
20318
20319
20320
20321
20322
20323
20324
20325
20326
20327
20328
20329
20330
20331
20332
20333
20334
20335
20336
20337
20338
20339
20340
20341
20342
20343
20344
20345
20346
20347
20348
20349
20350
20351
20352
20353
20354
20355
20356
20357
20358
20359
20360
20361
20362
20363
20364
20365
20366
20367
20368
20369
20370
20371
20372
20373
20374
20375
20376
20377
20378
20379
20380
20381
20382
20383
20384
20385
20386
20387
20388
20389
20390
20391
20392
20393
20394
20395
20396
20397
20398
20399
20400
20401
20402
20403
20404
20405
20406
20407
20408
20409
20410
20411
20412
20413
20414
20415
20416
20417
20418
20419
20420
20421
20422
20423
20424
20425
20426
20427
20428
20429
20430
20431
20432
20433
20434
20435
20436
20437
20438
20439
20440
20441
20442
20443
20444
20445
20446
20447
20448
20449
20450
20451
20452
20453
20454
20455
20456
20457
20458
20459
20460
20461
20462
20463
20464
20465
20466
20467
20468
20469
20470
20471
20472
20473
20474
20475
20476
20477
20478
20479
20480
20481
20482
20483
20484
20485
20486
20487
20488
20489
20490
20491
20492
20493
20494
20495
20496
20497
20498
20499
20500
20501
20502
20503
20504
20505
20506
20507
20508
20509
20510
20511
20512
20513
20514
20515
20516
20517
20518
20519
20520
20521
20522
20523
20524
20525
20526
20527
20528
20529
20530
20531
20532
20533
20534
20535
20536
20537
20538
20539
20540
20541
20542
20543
20544
20545
20546
20547
20548
20549
20550
20551
20552
20553
20554
20555
20556
20557
20558
20559
20560
20561
20562
20563
20564
20565
20566
20567
20568
20569
20570
20571
20572
20573
20574
20575
20576
20577
20578
20579
20580
20581
20582
20583
20584
20585
20586
20587
20588
20589
20590
20591
20592
20593
20594
20595
20596
20597
20598
20599
20600
20601
20602
20603
20604
20605
20606
20607
20608
20609
20610
20611
20612
20613
20614
20615
20616
20617
20618
20619
20620
20621
20622
20623
20624
20625
20626
20627
20628
20629
20630
20631
20632
20633
20634
20635
20636
20637
20638
20639
20640
20641
20642
20643
20644
20645
20646
20647
20648
20649
20650
20651
20652
20653
20654
20655
20656
20657
20658
20659
20660
20661
20662
20663
20664
20665
20666
20667
20668
20669
20670
20671
20672
20673
20674
20675
20676
20677
20678
20679
20680
20681
20682
20683
20684
20685
20686
20687
20688
20689
20690
20691
20692
20693
20694
20695
20696
20697
20698
20699
20700
20701
20702
20703
20704
20705
20706
20707
20708
20709
20710
20711
20712
20713
20714
20715
20716
20717
20718
20719
20720
20721
20722
20723
20724
20725
20726
20727
20728
20729
20730
20731
20732
20733
20734
20735
20736
20737
20738
20739
20740
20741
20742
20743
20744
20745
20746
20747
20748
20749
20750
20751
20752
20753
20754
20755
20756
20757
20758
20759
20760
20761
20762
20763
20764
20765
20766
20767
20768
20769
20770
20771
20772
20773
20774
20775
20776
20777
20778
20779
20780
20781
20782
20783
20784
20785
20786
20787
20788
20789
20790
20791
20792
20793
20794
20795
20796
20797
20798
20799
20800
20801
20802
20803
20804
20805
20806
20807
20808
20809
20810
20811
20812
20813
20814
20815
20816
20817
20818
20819
20820
20821
20822
20823
20824
20825
20826
20827
20828
20829
20830
20831
20832
20833
20834
20835
20836
20837
20838
20839
20840
20841
20842
20843
20844
20845
20846
20847
20848
20849
20850
20851
20852
20853
20854
20855
20856
20857
20858
20859
20860
20861
20862
20863
20864
20865
20866
20867
20868
20869
20870
20871
20872
20873
20874
20875
20876
20877
20878
20879
20880
20881
20882
20883
20884
20885
20886
20887
20888
20889
20890
20891
20892
20893
20894
20895
20896
20897
20898
20899
20900
20901
20902
20903
20904
20905
20906
20907
20908
20909
20910
20911
20912
20913
20914
20915
20916
20917
20918
20919
20920
20921
20922
20923
20924
20925
20926
20927
20928
20929
20930
20931
20932
20933
20934
20935
20936
20937
20938
20939
20940
20941
20942
20943
20944
20945
20946
20947
20948
20949
20950
20951
20952
20953
20954
20955
20956
20957
20958
20959
20960
20961
20962
20963
20964
20965
20966
20967
20968
20969
20970
20971
20972
20973
20974
20975
20976
20977
20978
20979
20980
20981
20982
20983
20984
20985
20986
20987
20988
20989
20990
20991
20992
20993
20994
20995
20996
20997
20998
20999
21000
21001
21002
21003
21004
21005
21006
21007
21008
21009
21010
21011
21012
21013
21014
21015
21016
21017
21018
21019
21020
21021
21022
21023
21024
21025
21026
21027
21028
21029
21030
21031
21032
21033
21034
21035
21036
21037
21038
21039
21040
21041
21042
21043
21044
21045
21046
21047
21048
21049
21050
21051
21052
21053
21054
21055
21056
21057
21058
21059
21060
21061
21062
21063
21064
21065
21066
21067
21068
21069
21070
21071
21072
21073
21074
21075
21076
21077
21078
21079
21080
21081
21082
21083
21084
21085
21086
21087
21088
21089
21090
21091
21092
21093
21094
21095
21096
21097
21098
21099
21100
21101
21102
21103
21104
21105
21106
21107
21108
21109
21110
21111
21112
21113
21114
21115
21116
21117
21118
21119
21120
21121
21122
21123
21124
21125
21126
21127
21128
21129
21130
21131
21132
21133
21134
21135
21136
21137
21138
21139
21140
21141
21142
21143
21144
21145
21146
21147
21148
21149
21150
21151
21152
21153
21154
21155
21156
21157
21158
21159
21160
21161
21162
21163
21164
21165
21166
21167
21168
21169
21170
21171
21172
21173
21174
21175
21176
21177
21178
21179
21180
21181
21182
21183
21184
21185
21186
21187
21188
21189
21190
21191
21192
21193
21194
21195
21196
21197
21198
21199
21200
21201
21202
21203
21204
21205
21206
21207
21208
21209
21210
21211
21212
21213
21214
21215
21216
21217
21218
21219
21220
21221
21222
21223
21224
21225
21226
21227
21228
21229
21230
21231
21232
21233
21234
21235
21236
21237
21238
21239
21240
21241
21242
21243
21244
21245
21246
21247
21248
21249
21250
21251
21252
21253
21254
21255
21256
21257
21258
21259
21260
21261
21262
21263
21264
21265
21266
21267
21268
21269
21270
21271
21272
21273
21274
21275
21276
21277
21278
21279
21280
21281
21282
21283
21284
21285
21286
21287
21288
21289
21290
21291
21292
21293
21294
21295
21296
21297
21298
21299
21300
21301
21302
21303
21304
21305
21306
21307
21308
21309
21310
21311
21312
21313
21314
21315
21316
21317
21318
21319
21320
21321
21322
21323
21324
21325
21326
21327
21328
21329
21330
21331
21332
21333
21334
21335
21336
21337
21338
21339
21340
21341
21342
21343
21344
21345
21346
21347
21348
21349
21350
21351
21352
21353
21354
21355
21356
21357
21358
21359
21360
21361
21362
21363
21364
21365
21366
21367
21368
21369
21370
21371
21372
21373
21374
21375
21376
21377
21378
21379
21380
21381
21382
21383
21384
21385
21386
21387
21388
21389
21390
21391
21392
21393
21394
21395
21396
21397
21398
21399
21400
21401
21402
21403
21404
21405
21406
21407
21408
21409
21410
21411
21412
21413
21414
21415
21416
21417
21418
21419
21420
21421
21422
21423
21424
21425
21426
21427
21428
21429
21430
21431
21432
21433
21434
21435
21436
21437
21438
21439
21440
21441
21442
21443
21444
21445
21446
21447
21448
21449
21450
21451
21452
21453
21454
21455
21456
21457
21458
21459
21460
21461
21462
21463
21464
21465
21466
21467
21468
21469
21470
21471
21472
21473
21474
21475
21476
21477
21478
21479
21480
21481
21482
21483
21484
21485
21486
21487
21488
21489
21490
21491
21492
21493
21494
21495
21496
21497
21498
21499
21500
21501
21502
21503
21504
21505
21506
21507
21508
21509
21510
21511
21512
21513
21514
21515
21516
21517
21518
21519
21520
21521
21522
21523
21524
21525
21526
21527
21528
21529
21530
21531
21532
21533
21534
21535
21536
21537
21538
21539
21540
21541
21542
21543
21544
21545
21546
21547
21548
21549
21550
21551
21552
21553
21554
21555
21556
21557
21558
21559
21560
21561
21562
21563
21564
21565
21566
21567
21568
21569
21570
21571
21572
21573
21574
21575
21576
21577
21578
21579
21580
21581
21582
21583
21584
21585
21586
21587
21588
21589
21590
21591
21592
21593
21594
21595
21596
21597
21598
21599
21600
21601
21602
21603
21604
21605
21606
21607
21608
21609
21610
21611
21612
21613
21614
21615
21616
21617
21618
21619
21620
21621
21622
21623
21624
21625
21626
21627
21628
21629
21630
21631
21632
21633
21634
21635
21636
21637
21638
21639
21640
21641
21642
21643
21644
21645
21646
21647
21648
21649
21650
21651
21652
21653
21654
21655
21656
21657
21658
21659
21660
21661
21662
21663
21664
21665
21666
21667
21668
21669
21670
21671
21672
21673
21674
21675
21676
21677
21678
21679
21680
21681
21682
21683
21684
21685
21686
21687
21688
21689
21690
21691
21692
21693
21694
21695
21696
21697
21698
21699
21700
21701
21702
21703
21704
21705
21706
21707
21708
21709
21710
21711
21712
21713
21714
21715
21716
21717
21718
21719
21720
21721
21722
21723
21724
21725
21726
21727
21728
21729
21730
21731
21732
21733
21734
21735
21736
21737
21738
21739
21740
21741
21742
21743
21744
21745
21746
21747
21748
21749
21750
21751
21752
21753
21754
21755
21756
21757
21758
21759
21760
21761
21762
21763
21764
21765
21766
21767
21768
21769
21770
21771
21772
21773
21774
21775
21776
21777
/*
 Navicat MySQL Data Transfer
 
 Source Server         : aaa
 Source Server Type    : MySQL
 Source Server Version : 50528
 Source Host           : localhost:3306
 Source Schema         : gmms
 
 Target Server Type    : MySQL
 Target Server Version : 50528
 File Encoding         : 65001
 
 Date: 13/05/2024 13:12:34
*/
 
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
 
-- ----------------------------
-- Table structure for ATAB
-- ----------------------------
DROP TABLE IF EXISTS `ATAB`;
CREATE TABLE `ATAB`  (
  `gg` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for A_JiXieHand
-- ----------------------------
DROP TABLE IF EXISTS `A_JiXieHand`;
CREATE TABLE `A_JiXieHand`  (
  `begin_time` datetime NULL DEFAULT NULL COMMENT '接收时间',
  `end_time` datetime NULL DEFAULT NULL COMMENT '响应时间',
  `content` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '内容'
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for A_LengLipian
-- ----------------------------
DROP TABLE IF EXISTS `A_LengLipian`;
CREATE TABLE `A_LengLipian`  (
  `create_time` datetime NULL DEFAULT NULL COMMENT '进入时间',
  `end_time` datetime NULL DEFAULT NULL COMMENT '结束时间',
  `content` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '内容'
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for A_LengLipian_copy1
-- ----------------------------
DROP TABLE IF EXISTS `A_LengLipian_copy1`;
CREATE TABLE `A_LengLipian_copy1`  (
  `create_time` datetime NULL DEFAULT NULL COMMENT '进入时间',
  `end_time` datetime NULL DEFAULT NULL COMMENT '结束时间',
  `content` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '内容'
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for A_Robotlog
-- ----------------------------
DROP TABLE IF EXISTS `A_Robotlog`;
CREATE TABLE `A_Robotlog`  (
  `groups` bigint(20) NULL DEFAULT NULL,
  `glassid` bigint(20) NULL DEFAULT NULL,
  `beigntime` datetime NULL DEFAULT NULL,
  `endtime` datetime NULL DEFAULT NULL,
  `state` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `processcard_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for A_youhua
-- ----------------------------
DROP TABLE IF EXISTS `A_youhua`;
CREATE TABLE `A_youhua`  (
  `processcard_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '优化流程卡',
  `count` int(11) NULL DEFAULT NULL COMMENT '优化数量',
  `youhuashijian` datetime NULL DEFAULT NULL COMMENT '优化时间'
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for Cold_Work_Stock
-- ----------------------------
DROP TABLE IF EXISTS `Cold_Work_Stock`;
CREATE TABLE `Cold_Work_Stock`  (
  `processcard_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '流程卡号',
  `state` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '出库/入库',
  `in_stock_time` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '入库时间',
  `out_stock_time` datetime NULL DEFAULT NULL COMMENT '出库时间',
  PRIMARY KEY (`processcard_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for GanghuaTuiJian
-- ----------------------------
DROP TABLE IF EXISTS `GanghuaTuiJian`;
CREATE TABLE `GanghuaTuiJian`  (
  `liuchengka` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `baogongbianhao` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `gyqrxh` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for SemiFinishedProductsCold
-- ----------------------------
DROP TABLE IF EXISTS `SemiFinishedProductsCold`;
CREATE TABLE `SemiFinishedProductsCold`  (
  `id` bigint(20) NOT NULL,
  `LocationNum` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '库位',
  `LocationArea` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '库区',
  `CarNumber` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '流程卡号',
  `State` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '状态',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for TemperingFinsh
-- ----------------------------
DROP TABLE IF EXISTS `TemperingFinsh`;
CREATE TABLE `TemperingFinsh`  (
  `machineid` bigint(20) NULL DEFAULT 0,
  `glassid` bigint(20) NULL DEFAULT NULL,
  `Finshtime` datetime NULL DEFAULT NULL,
  `stoprank` bigint(20) NULL DEFAULT NULL,
  `shelfrankid` bigint(20) NULL DEFAULT NULL,
  `processcard` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for Y_Edg_Statistics
-- ----------------------------
DROP TABLE IF EXISTS `Y_Edg_Statistics`;
CREATE TABLE `Y_Edg_Statistics`  (
  `Glassid` bigint(20) NOT NULL COMMENT '玻璃ID',
  `SendTime` datetime NULL DEFAULT NULL COMMENT '发送时间',
  `Width` double NULL DEFAULT NULL COMMENT '宽',
  `Height` double NULL DEFAULT NULL COMMENT '高',
  `Thickess` double NULL DEFAULT NULL COMMENT '厚',
  `SizeText` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '尺寸字符串',
  `SendText` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '发送内容',
  `Recordsid` bigint(20) NULL DEFAULT NULL COMMENT '记录ID',
  `Line` int(11) NULL DEFAULT NULL COMMENT '线路',
  `RecordsidW` double NULL DEFAULT NULL COMMENT '记录ID宽',
  `RecordsidH` double NULL DEFAULT NULL COMMENT '记录ID高',
  `banzu` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '班组',
  `report_time` date NULL DEFAULT NULL COMMENT '报工日期'
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for aaaa
-- ----------------------------
DROP TABLE IF EXISTS `aaaa`;
CREATE TABLE `aaaa`  (
  `MachineName` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `groups` int(11) NULL DEFAULT NULL,
  `data1` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `Content` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '内容',
  `id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '任务id',
  `Sendtext` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for app_glassType
-- ----------------------------
DROP TABLE IF EXISTS `app_glassType`;
CREATE TABLE `app_glassType`  (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '膜系中文变化成英文',
  `old_glassType` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `new_glassType` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `creat_time` datetime NOT NULL,
  `update_time` datetime NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 30 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for app_yuanpianpandian
-- ----------------------------
DROP TABLE IF EXISTS `app_yuanpianpandian`;
CREATE TABLE `app_yuanpianpandian`  (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '原片盘点',
  `shelf_id` int(11) NULL DEFAULT NULL,
  `dateshijian` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `glass` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `width_height` varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `kucunshuliang` int(11) NULL DEFAULT NULL,
  `pandianshuliang` int(11) NULL DEFAULT NULL,
  `shenheshuliang` int(11) NOT NULL,
  `jianlitime` datetime NOT NULL,
  `xiugaitime` datetime NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 72 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for banzu
-- ----------------------------
DROP TABLE IF EXISTS `banzu`;
CREATE TABLE `banzu`  (
  `banzubianhao` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `banzumingcheng` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `gongxu` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `shebeibianhao` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `shebei` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `gongyi` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `shenhezhuangtai` int(11) NULL DEFAULT NULL,
  `shenherengonghao` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `shenheren` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `jianlitime` datetime NULL DEFAULT NULL,
  `xiugaitime` datetime NULL DEFAULT NULL
) ENGINE = FEDERATED CHARACTER SET = utf8 COLLATE = utf8_general_ci CONNECTION = 'mysql://root1:beibo.123@10.12.0.104:3306/sappp/banzu' ROW_FORMAT = Dynamic;
 
-- ----------------------------
-- Table structure for cipoleixing
-- ----------------------------
DROP TABLE IF EXISTS `cipoleixing`;
CREATE TABLE `cipoleixing`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `cipoleixing` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `shenhezhuangtai` int(11) NULL DEFAULT NULL,
  `shenherengonghao` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `shenheren` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `jianlitime` datetime NULL DEFAULT NULL,
  `xiugaitime` datetime NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING REMOTE
) ENGINE = FEDERATED CHARACTER SET = utf8 COLLATE = utf8_general_ci CONNECTION = 'mysql://root1:beibo.123@10.12.0.104:3306/sappp/cipoleixing' ROW_FORMAT = Dynamic;
 
-- ----------------------------
-- Table structure for cipoyuanyin
-- ----------------------------
DROP TABLE IF EXISTS `cipoyuanyin`;
CREATE TABLE `cipoyuanyin`  (
  `xuhao` int(11) NOT NULL AUTO_INCREMENT,
  `cipoyuanyin` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `shenhezhuangtai` int(11) NULL DEFAULT NULL,
  `shenherengonghao` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `shenheren` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `cipoleixing` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `cipofenxi` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `jianlitime` datetime NULL DEFAULT NULL,
  `xiugaitime` datetime NULL DEFAULT NULL,
  PRIMARY KEY (`xuhao`) USING REMOTE
) ENGINE = FEDERATED CHARACTER SET = utf8 COLLATE = utf8_general_ci CONNECTION = 'mysql://root1:beibo.123@10.12.0.104:3306/sappp/cipoyuanyin' ROW_FORMAT = Dynamic;
 
-- ----------------------------
-- Table structure for e_pierceds
-- ----------------------------
DROP TABLE IF EXISTS `e_pierceds`;
CREATE TABLE `e_pierceds`  (
  `processcard_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '流程卡',
  `type_num` bigint(20) NULL DEFAULT NULL COMMENT '玻璃类型',
  `pieces` bigint(20) NULL DEFAULT NULL COMMENT '数量',
  `pierced_type` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '次破类型',
  `pierced_cause` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '次破原因',
  `is_report` bigint(20) NULL DEFAULT 0 COMMENT '是否报工(0:未报工;1:可报工;2:准备报工;3:已报工;4:人工拿走)',
  `glass_id` bigint(20) NULL DEFAULT NULL COMMENT '玻璃id',
  `create_time` datetime NULL DEFAULT NULL COMMENT '次破时间',
  `process` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工序',
  `line` bigint(20) NULL DEFAULT NULL COMMENT '线路',
  `gc_number` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工程号',
  `cs_number` int(11) NULL DEFAULT NULL COMMENT '原因次数',
  `team_name` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '班组名称',
  `report_time` date NULL DEFAULT NULL COMMENT '报工时间',
  INDEX `create_time`(`create_time`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for e_record_hollow
-- ----------------------------
DROP TABLE IF EXISTS `e_record_hollow`;
CREATE TABLE `e_record_hollow`  (
  `processcard_id` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '流程卡',
  `glass_id` bigint(20) NULL DEFAULT NULL COMMENT '玻璃id',
  `width` double(20, 2) NULL DEFAULT NULL COMMENT '宽度',
  `height` double(20, 2) NULL DEFAULT NULL COMMENT '高度',
  `thinkess` double(20, 2) NULL DEFAULT NULL COMMENT '厚度',
  `color` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '颜色',
  `sequence` bigint(20) NULL DEFAULT NULL COMMENT '架上顺序',
  `create_time` datetime NULL DEFAULT NULL COMMENT '中空完成时间',
  `line` bigint(20) NULL DEFAULT NULL COMMENT '线路',
  `team_name` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '班组名称',
  `type_num` int(11) NULL DEFAULT NULL COMMENT '玻璃类型',
  `is_report` int(11) NULL DEFAULT NULL COMMENT '是否报工(0:未报工;1:可报工;2:准备报工;3:已报工)',
  `report_time` date NULL DEFAULT NULL COMMENT '报工时间',
  INDEX `create_time`(`create_time`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for e_record_stock
-- ----------------------------
DROP TABLE IF EXISTS `e_record_stock`;
CREATE TABLE `e_record_stock`  (
  `processcard_id` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '流程卡',
  `glass_id` bigint(20) NULL DEFAULT NULL COMMENT '玻璃id',
  `width` double(20, 2) NULL DEFAULT NULL COMMENT '宽度',
  `height` double(20, 2) NULL DEFAULT NULL COMMENT '高度',
  `thinkess` double(20, 2) NULL DEFAULT NULL COMMENT '厚度',
  `color` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '颜色',
  `sequence` bigint(20) NULL DEFAULT NULL COMMENT '架上顺序',
  `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '钢化完成时间',
  `line` bigint(20) NULL DEFAULT NULL COMMENT '线路',
  `team_name` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '班组名称',
  `type_num` int(11) NULL DEFAULT NULL COMMENT '玻璃类型',
  `is_report` int(11) NULL DEFAULT NULL COMMENT '是否报工(0:未报工;1:可报工;2:准备报工;3:已报工)',
  `rank` int(11) NULL DEFAULT NULL COMMENT '架子号',
  `report_time` date NULL DEFAULT NULL COMMENT '报工时间',
  INDEX `create_time`(`create_time`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for e_record_tempering
-- ----------------------------
DROP TABLE IF EXISTS `e_record_tempering`;
CREATE TABLE `e_record_tempering`  (
  `processcard_id` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '流程卡',
  `glass_id` bigint(20) NULL DEFAULT NULL COMMENT '玻璃id',
  `width` double(20, 2) NULL DEFAULT NULL COMMENT '宽度',
  `height` double(20, 2) NULL DEFAULT NULL COMMENT '高度',
  `thinkess` double(20, 2) NULL DEFAULT NULL COMMENT '厚度',
  `color` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '颜色',
  `sequence` bigint(20) NULL DEFAULT NULL COMMENT '架上顺序',
  `create_time` datetime NULL DEFAULT NULL COMMENT '钢化完成时间',
  `line` bigint(20) NULL DEFAULT NULL COMMENT '线路',
  `team_name` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '班组名称',
  `type_num` int(11) NULL DEFAULT NULL COMMENT '玻璃类型',
  `is_report` int(11) NULL DEFAULT NULL COMMENT '是否报工(0:未报工;1:可报工;2:准备报工;3:已报工)',
  `rank` int(11) NULL DEFAULT NULL COMMENT '架子号',
  `report_time` date NULL DEFAULT NULL COMMENT '报工时间',
  `furnace` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '炉子号',
  INDEX `create_time`(`create_time`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for event_tab
-- ----------------------------
DROP TABLE IF EXISTS `event_tab`;
CREATE TABLE `event_tab`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `time_stamp` datetime NULL DEFAULT NULL,
  `eventname` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `eventid` int(11) NULL DEFAULT NULL,
  `machineid` int(11) NULL DEFAULT NULL,
  `oldmsg` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `newmsg` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `flag` int(11) NULL DEFAULT NULL,
  `iswrite` int(11) NULL DEFAULT NULL,
  `invoke` int(11) NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 7 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for galss_C
-- ----------------------------
DROP TABLE IF EXISTS `galss_C`;
CREATE TABLE `galss_C`  (
  `id` bigint(20) NOT NULL,
  `color` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '颜色  (白玻)',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_biao_table
-- ----------------------------
DROP TABLE IF EXISTS `gmms_biao_table`;
CREATE TABLE `gmms_biao_table`  (
  `id` int(11) NOT NULL,
  `dongzuo_id` int(11) NULL DEFAULT NULL,
  `da_biao_mo_ban` int(11) NULL DEFAULT NULL,
  `note` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `biao_type` int(11) NULL DEFAULT NULL,
  `color_type` int(11) NULL DEFAULT NULL,
  `fangxiang_type` int(11) NULL DEFAULT NULL,
  `line` int(11) NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_cutmanage
-- ----------------------------
DROP TABLE IF EXISTS `gmms_cutmanage`;
CREATE TABLE `gmms_cutmanage`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `width` double NULL DEFAULT NULL COMMENT '宽度',
  `height` double NULL DEFAULT NULL COMMENT '高度',
  `thickness` double NULL DEFAULT NULL COMMENT '厚度',
  `color` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '颜色',
  `pieces` int(11) NULL DEFAULT NULL COMMENT '数量',
  `groups` bigint(20) NULL DEFAULT NULL COMMENT '线路',
  `statrtime` datetime NULL DEFAULT NULL COMMENT '时间',
  `engineering_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工程号',
  `production_time` datetime NULL DEFAULT NULL COMMENT '生产日期',
  `batch_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '批次号',
  `warehousing_time` datetime NULL DEFAULT NULL COMMENT '进仓日期',
  `dengluname` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '切割班组',
  `BgTime` datetime NULL DEFAULT NULL COMMENT '报工时间',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 167574 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_device_state
-- ----------------------------
DROP TABLE IF EXISTS `gmms_device_state`;
CREATE TABLE `gmms_device_state`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `device_id` bigint(20) NULL DEFAULT NULL COMMENT '设备ID',
  `enable` bit(1) NULL DEFAULT NULL COMMENT '总使能',
  `line` int(11) NULL DEFAULT NULL,
  `device_name` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 7 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_dongzuo
-- ----------------------------
DROP TABLE IF EXISTS `gmms_dongzuo`;
CREATE TABLE `gmms_dongzuo`  (
  `number` int(11) NOT NULL,
  `mode` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `note` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `da_biao_mo_ban` int(11) NOT NULL,
  `qing_xi_hou_zhua` int(11) NOT NULL,
  `gang_qian_zhua` int(11) NOT NULL,
  `gang_qian_bu_zhuan` int(11) NOT NULL,
  `gang_qian_zhuan` int(11) NOT NULL,
  `gang_hou_bu_zhuan` int(11) NOT NULL,
  `gang_hou_zhuan` int(11) NOT NULL,
  `gang_hou_zhua` int(11) NOT NULL,
  `zhong_kong_fang` int(11) NOT NULL,
  PRIMARY KEY (`number`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_dongzuo_111
-- ----------------------------
DROP TABLE IF EXISTS `gmms_dongzuo_111`;
CREATE TABLE `gmms_dongzuo_111`  (
  `number` int(11) NOT NULL,
  `mode` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `bo_li_fan_mian` int(11) NOT NULL,
  `da_biao_mo_ban` int(11) NOT NULL,
  `qing_xi_hou_zhua` int(11) NOT NULL,
  `gang_qian_zhua` int(11) NOT NULL,
  `gang_qian_bu_zhuan` int(11) NOT NULL,
  `gang_qian_zhuan` int(11) NOT NULL,
  `gang_hou_bu_zhuan` int(11) NOT NULL,
  `gang_hou_zhuan` int(11) NOT NULL,
  `gang_hou_zhua` int(11) NOT NULL,
  `zhong_kong_fang` int(11) NOT NULL,
  PRIMARY KEY (`number`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_dongzuo_table_copy1
-- ----------------------------
DROP TABLE IF EXISTS `gmms_dongzuo_table_copy1`;
CREATE TABLE `gmms_dongzuo_table_copy1`  (
  `number` int(11) NOT NULL,
  `mode` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `bo_li_fan_mian` int(11) NOT NULL,
  `da_biao_mo_ban` int(11) NOT NULL,
  `qing_xi_hou_zhua` int(11) NOT NULL,
  `gang_qian_zhua` int(11) NOT NULL,
  `gang_qian_bu_zhuan` int(11) NOT NULL,
  `gang_qian_zhuan` int(11) NOT NULL,
  `gang_hou_bu_zhuan` int(11) NOT NULL,
  `gang_hou_zhuan` int(11) NOT NULL,
  `gang_hou_zhua` int(11) NOT NULL,
  `zhong_kong_fang` int(11) NOT NULL,
  PRIMARY KEY (`number`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_drop_frame
-- ----------------------------
DROP TABLE IF EXISTS `gmms_drop_frame`;
CREATE TABLE `gmms_drop_frame`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `drop_frame` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '架号',
  `processcard_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '流程卡号',
  `engineering_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工程号',
  `state` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '0 无架  1 空架 2 非空架  3 半完成(多流程卡有一个完成) 4 完成架',
  `processcard_count` int(11) NOT NULL COMMENT '总流程卡数',
  `finsh_count` int(11) NOT NULL COMMENT '完成数量',
  `groups` bigint(20) NULL DEFAULT NULL,
  `stops` int(11) NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 16 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_drop_frame_2
-- ----------------------------
DROP TABLE IF EXISTS `gmms_drop_frame_2`;
CREATE TABLE `gmms_drop_frame_2`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `drop_frame` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '架号',
  `processcard_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '流程卡号',
  `engineering_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工程号',
  `state` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '0 无架  1 空架 2 非空架  3 半完成(多流程卡有一个完成) 4 完成架',
  `processcard_count` int(11) NOT NULL COMMENT '总流程卡数',
  `surplus_count` int(11) NOT NULL COMMENT '剩余数量',
  `groups` bigint(20) NULL DEFAULT NULL COMMENT '线路',
  `stops` int(11) NULL DEFAULT NULL COMMENT '位置',
  `noodles` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'A/B面',
  `flag` int(11) NOT NULL COMMENT '标记',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 15 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_drop_frame_3
-- ----------------------------
DROP TABLE IF EXISTS `gmms_drop_frame_3`;
CREATE TABLE `gmms_drop_frame_3`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `drop_frame` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '架号',
  `processcard_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '流程卡号',
  `engineering_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工程号',
  `state` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '0 无架  1 空架 2 非空架  3 半完成(多流程卡有一个完成) 4 完成架',
  `processcard_count` int(11) NOT NULL COMMENT '总流程卡数',
  `finsh_count` int(11) NOT NULL COMMENT '完成数量',
  `groups` bigint(20) NULL DEFAULT NULL,
  `stops` int(11) NULL DEFAULT NULL,
  `rank` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '架子',
  `orientation` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '朝向',
  `stop_rank` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '位置',
  `flag` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '状态',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 9 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_drop_frame_4
-- ----------------------------
DROP TABLE IF EXISTS `gmms_drop_frame_4`;
CREATE TABLE `gmms_drop_frame_4`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `drop_frame` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '架号',
  `processcard_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '流程卡号',
  `engineering_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工程号',
  `state` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '0 无架  1 空架 2 非空架  3 半完成(多流程卡有一个完成) 4 完成架',
  `processcard_count` int(11) NOT NULL COMMENT '总流程卡数',
  `finsh_count` int(11) NOT NULL COMMENT '完成数量',
  `groups` bigint(20) NULL DEFAULT NULL,
  `stops` int(11) NULL DEFAULT NULL,
  `rank` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '架子',
  `orientation` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '朝向',
  `stop_rank` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '位置',
  `flag` int(11) NOT NULL COMMENT '状态',
  `sign` int(11) NOT NULL COMMENT '标记',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 100 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_drop_frame_5
-- ----------------------------
DROP TABLE IF EXISTS `gmms_drop_frame_5`;
CREATE TABLE `gmms_drop_frame_5`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `groups_` bigint(20) NULL DEFAULT NULL COMMENT '线路 : 钢化后1/理片2/中空3/旋转4',
  `drop_type` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工位类型:钢化后/理片/中空/旋转',
  `drop_groups` bigint(20) NULL DEFAULT NULL COMMENT '工位线路',
  `stops` int(11) NULL DEFAULT NULL COMMENT '工位序号',
  `stop_rank` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工位编号',
  `orientation` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '朝向',
  `rank` bigint(255) NULL DEFAULT NULL COMMENT '架子ID',
  `sign` int(11) NOT NULL COMMENT '1进   2正在进  3进完成  4 出  5正在出  6出完成      0需要任务  7不需要任务   ',
  `flag` int(11) NOT NULL COMMENT '状态  :  启用1 /禁用0',
  `all_groups` bigint(20) NULL DEFAULT NULL COMMENT '任务优先级(\r\n吊装移库400,\r\n中空旋转(旋转退库)300,\r\n中空移库200,\r\n移库100\r\n)',
  `position` double(20, 2) NULL DEFAULT NULL COMMENT '所在位置',
  `rankposition` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '料架出库前的工位',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1042 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_edg_perimeter
-- ----------------------------
DROP TABLE IF EXISTS `gmms_edg_perimeter`;
CREATE TABLE `gmms_edg_perimeter`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `width` decimal(6, 1) NULL DEFAULT NULL COMMENT '宽度',
  `height` decimal(6, 1) NULL DEFAULT NULL COMMENT '高度',
  `start_time` datetime NULL DEFAULT NULL COMMENT '建立时间',
  `groups` bigint(20) NULL DEFAULT NULL COMMENT '线路',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1550998 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_edg_speed
-- ----------------------------
DROP TABLE IF EXISTS `gmms_edg_speed`;
CREATE TABLE `gmms_edg_speed`  (
  `id` int(11) NOT NULL,
  `speed1` int(11) NULL DEFAULT NULL COMMENT '磨边机速度',
  `speed2` int(11) NULL DEFAULT NULL COMMENT '清洗机速度',
  `groups` int(255) NULL DEFAULT NULL COMMENT '线路',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_fragments
-- ----------------------------
DROP TABLE IF EXISTS `gmms_fragments`;
CREATE TABLE `gmms_fragments`  (
  `id` int(11) NOT NULL,
  `state` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `fragments_rank` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `width` double NULL DEFAULT NULL,
  `height` double NULL DEFAULT NULL,
  `thickness` double NULL DEFAULT NULL,
  `flag` int(11) NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_furnace
-- ----------------------------
DROP TABLE IF EXISTS `gmms_furnace`;
CREATE TABLE `gmms_furnace`  (
  `id` int(11) NOT NULL,
  `width` int(11) NOT NULL,
  `length` int(11) NOT NULL,
  `xinterval` int(11) NOT NULL,
  `yinterval` int(11) NOT NULL,
  `maxLoadingRate` int(3) NOT NULL COMMENT '单炉最大装载率',
  `maxTolerance` int(3) NOT NULL COMMENT '单炉最大尺寸比例',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_furnace_config
-- ----------------------------
DROP TABLE IF EXISTS `gmms_furnace_config`;
CREATE TABLE `gmms_furnace_config`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `width` int(11) NOT NULL COMMENT '宽',
  `length` int(11) NOT NULL COMMENT '长',
  `xinterval` int(11) NOT NULL COMMENT 'x轴间隔',
  `yinterval` int(11) NOT NULL COMMENT 'y轴间隔',
  `description` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '配置描述',
  `line` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '产线',
  `IntRemark` int(255) NULL DEFAULT NULL,
  `StrRemark` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 28 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_galss_task
-- ----------------------------
DROP TABLE IF EXISTS `gmms_galss_task`;
CREATE TABLE `gmms_galss_task`  (
  `id` bigint(20) NOT NULL,
  `rank` bigint(20) NULL DEFAULT 0 COMMENT '测量队列',
  `type_id` bigint(20) NULL DEFAULT NULL COMMENT '类型编号',
  `galss_id` bigint(20) NOT NULL COMMENT '玻璃编号',
  `pattern_id` bigint(20) NULL DEFAULT NULL COMMENT '版面编号',
  `width` double(6, 1) NULL DEFAULT NULL COMMENT '宽度',
  `height` double(6, 1) NULL DEFAULT NULL COMMENT '高度',
  `thickness` double(6, 1) NULL DEFAULT NULL COMMENT '厚度',
  `color` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '颜色',
  `edg_width` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '磨边宽度',
  `edg_height` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '磨边高度',
  `chamfer_size` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '倒角大小',
  `galss_type` int(11) NULL DEFAULT NULL COMMENT '玻璃类型 散单/整单',
  `edg_speed1` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '磨边速度',
  `edg_speed2` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '速度',
  `fine_throwing` int(11) NULL DEFAULT NULL COMMENT '精抛/粗磨',
  `work_state` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工作状态',
  `work_procedure` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工序',
  `slicecage_rank` bigint(20) NULL DEFAULT 0 COMMENT '理片笼架子',
  `drop_frame` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '落架',
  `slicecage_flag` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '0' COMMENT '理片笼标志(备用)',
  `out_rank` bigint(20) NOT NULL COMMENT '出理片笼序号',
  `start_time` datetime NOT NULL COMMENT '创建时间',
  `finsh_time` datetime NULL DEFAULT NULL COMMENT '完成时间',
  `stop_position` int(11) NOT NULL COMMENT '下片位置',
  `processcard_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '流程卡号',
  `engineering_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工程号',
  `broken_state` int(11) NOT NULL COMMENT '破片标记,非0破片',
  `stop_rank` int(11) NOT NULL COMMENT '片序',
  `work_procedure_number` int(11) NULL DEFAULT NULL COMMENT '工序标记',
  `gc_number` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '没用',
  `gc_width` double NULL DEFAULT NULL COMMENT '没用',
  `gc_height` double NULL DEFAULT NULL COMMENT '没用',
  `gc_stockid` int(11) NULL DEFAULT NULL COMMENT '没用',
  `marking_flag` int(11) NOT NULL COMMENT '打标',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `pattern_id`(`pattern_id`) USING BTREE,
  INDEX `galss_id`(`galss_id`) USING BTREE,
  INDEX `type_id`(`type_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_galss_task_2
-- ----------------------------
DROP TABLE IF EXISTS `gmms_galss_task_2`;
CREATE TABLE `gmms_galss_task_2`  (
  `id` bigint(20) NOT NULL,
  `rank` bigint(20) NULL DEFAULT 0,
  `type_id` bigint(20) NULL DEFAULT NULL,
  `galss_id` bigint(20) NOT NULL,
  `pattern_id` bigint(20) NULL DEFAULT NULL,
  `width` double(6, 1) NULL DEFAULT NULL,
  `height` double(6, 1) NULL DEFAULT NULL,
  `thickness` double(6, 1) NULL DEFAULT NULL,
  `color` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `edg_width` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `edg_height` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `chamfer_size` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '倒角大小',
  `galss_type` int(11) NULL DEFAULT NULL COMMENT '玻璃类型 散单/整单',
  `edg_speed1` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '磨边速度',
  `edg_speed2` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `fine_throwing` int(11) NULL DEFAULT NULL COMMENT '精抛/粗磨',
  `work_state` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `slicecage_rank` bigint(20) NULL DEFAULT 0 COMMENT '理片笼架子',
  `work_procedure` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `drop_frame` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '落架',
  `slicecage_flag` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '0' COMMENT '理片笼标志(备用)',
  `out_rank` bigint(20) NOT NULL COMMENT '出理片笼序号',
  `start_time` datetime NOT NULL,
  `finsh_time` datetime NULL DEFAULT NULL,
  `stop_position` int(11) NOT NULL COMMENT '下片位置',
  `processcard_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '流程卡号',
  `engineering_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工程号',
  `broken_state` int(11) NOT NULL COMMENT '破片标记,非0破片',
  `stop_rank` int(11) NOT NULL,
  `work_procedure_number` int(11) NULL DEFAULT NULL,
  `gc_number` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `gc_width` double NULL DEFAULT NULL,
  `gc_height` double NULL DEFAULT NULL,
  `gc_stockid` int(11) NULL DEFAULT NULL,
  `marking_flag` int(11) NOT NULL COMMENT '打标',
  `orders` int(11) NULL DEFAULT NULL COMMENT '顺序',
  `grouporder` int(11) NULL DEFAULT NULL COMMENT '组',
  `furnace` int(11) NULL DEFAULT NULL COMMENT '炉',
  `angle` int(11) NULL DEFAULT NULL COMMENT '旋转角度  0.0度 1.90度 2.-90度 3.180度 4.-180度',
  `distance` int(11) NULL DEFAULT NULL COMMENT '距离  /mm',
  `groups` bigint(20) NULL DEFAULT 0 COMMENT '线路',
  `pendulum_piece` int(255) NULL DEFAULT NULL COMMENT '1.传送完后等待  2.传送完后传送至钢化片台 3.传送完后传送至钢化摆片台并启动钢化摆片台',
  `banzu` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '班组',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `pattern_id`(`pattern_id`) USING BTREE,
  INDEX `galss_id`(`galss_id`) USING BTREE,
  INDEX `type_id`(`type_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_galss_task_2_copy1
-- ----------------------------
DROP TABLE IF EXISTS `gmms_galss_task_2_copy1`;
CREATE TABLE `gmms_galss_task_2_copy1`  (
  `id` bigint(20) NOT NULL,
  `rank` bigint(20) NULL DEFAULT 0,
  `type_id` bigint(20) NULL DEFAULT NULL,
  `galss_id` bigint(20) NOT NULL,
  `pattern_id` bigint(20) NULL DEFAULT NULL,
  `width` double(6, 1) NULL DEFAULT NULL,
  `height` double(6, 1) NULL DEFAULT NULL,
  `thickness` double(6, 1) NULL DEFAULT NULL,
  `color` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `edg_width` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `edg_height` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `chamfer_size` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '倒角大小',
  `galss_type` int(11) NULL DEFAULT NULL COMMENT '玻璃类型 散单/整单',
  `edg_speed1` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '磨边速度',
  `edg_speed2` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `fine_throwing` int(11) NULL DEFAULT NULL COMMENT '精抛/粗磨',
  `work_state` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `slicecage_rank` bigint(20) NULL DEFAULT 0 COMMENT '理片笼架子',
  `work_procedure` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `drop_frame` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '落架',
  `slicecage_flag` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '0' COMMENT '理片笼标志(备用)',
  `out_rank` bigint(20) NOT NULL COMMENT '出理片笼序号',
  `start_time` datetime NOT NULL,
  `finsh_time` datetime NULL DEFAULT NULL,
  `stop_position` int(11) NOT NULL COMMENT '下片位置',
  `processcard_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '流程卡号',
  `engineering_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工程号',
  `broken_state` int(11) NOT NULL COMMENT '破片标记,非0破片',
  `stop_rank` int(11) NOT NULL,
  `work_procedure_number` int(11) NULL DEFAULT NULL,
  `gc_number` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `gc_width` double NULL DEFAULT NULL,
  `gc_height` double NULL DEFAULT NULL,
  `gc_stockid` int(11) NULL DEFAULT NULL,
  `marking_flag` int(11) NOT NULL COMMENT '打标',
  `orders` int(11) NULL DEFAULT NULL COMMENT '顺序',
  `grouporder` int(11) NULL DEFAULT NULL COMMENT '组',
  `furnace` int(11) NULL DEFAULT NULL COMMENT '炉',
  `angle` int(11) NULL DEFAULT NULL COMMENT '旋转角度  0.0度 1.90度 2.-90度 3.180度 4.-180度',
  `distance` int(11) NULL DEFAULT NULL COMMENT '距离  /mm',
  `groups` bigint(20) NULL DEFAULT 0 COMMENT '线路',
  `pendulum_piece` int(255) NULL DEFAULT NULL COMMENT '1.传送完后等待  2.传送完后传送至钢化片台 3.传送完后传送至钢化摆片台并启动钢化摆片台',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `pattern_id`(`pattern_id`) USING BTREE,
  INDEX `galss_id`(`galss_id`) USING BTREE,
  INDEX `type_id`(`type_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_galss_task_buffer
-- ----------------------------
DROP TABLE IF EXISTS `gmms_galss_task_buffer`;
CREATE TABLE `gmms_galss_task_buffer`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `rank` bigint(20) NULL DEFAULT 0,
  `type_id` bigint(20) NULL DEFAULT NULL,
  `galss_id` bigint(20) NOT NULL,
  `pattern_id` bigint(20) NULL DEFAULT NULL,
  `width` double NULL DEFAULT NULL COMMENT '切割的宽',
  `height` double NULL DEFAULT NULL,
  `thickness` double NULL DEFAULT NULL,
  `color` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `edg_width` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '磨后的宽',
  `edg_height` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `chamfer_size` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '倒角大小',
  `galss_type` int(11) NULL DEFAULT NULL COMMENT '玻璃类型 散单/整单',
  `edg_speed1` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '磨边速度',
  `edg_speed2` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `fine_throwing` int(11) NULL DEFAULT NULL COMMENT '精抛/粗磨',
  `work_state` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `work_procedure` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `slicecage_rank` bigint(20) NULL DEFAULT 0 COMMENT '理片笼架子',
  `drop_frame` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '落架',
  `slicecage_flag` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '0' COMMENT '理片笼标志(备用)',
  `out_rank` bigint(20) NOT NULL COMMENT '出理片笼序号',
  `start_time` datetime NOT NULL,
  `finsh_time` datetime NULL DEFAULT NULL,
  `stop_position` int(11) NULL DEFAULT NULL COMMENT '下片位置',
  `processcard_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '流程卡号',
  `engineering_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工程号',
  `broken_state` int(11) NOT NULL COMMENT '破片标记,非0破片',
  `stop_rank` int(11) NOT NULL COMMENT '落架顺序',
  `work_procedure_number` int(11) NULL DEFAULT NULL,
  `gc_number` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `gc_width` double NULL DEFAULT NULL,
  `gc_height` double NULL DEFAULT NULL,
  `gc_stockid` int(11) NULL DEFAULT NULL,
  `marking_flag` int(11) NOT NULL COMMENT '打标,(0不钢化横标1不钢化竖标2钢化横标3钢化竖标)',
  `w` double(11, 0) NOT NULL DEFAULT 0,
  `h` double(11, 0) NOT NULL DEFAULT 0,
  `loucengbianhao` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '楼层编号',
  `marking_flag_ex` int(11) NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `pattern_id`(`pattern_id`) USING BTREE,
  INDEX `galss_id`(`galss_id`) USING BTREE,
  INDEX `type_id`(`type_id`) USING BTREE,
  INDEX `gc`(`engineering_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1779094 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_galss_task_details
-- ----------------------------
DROP TABLE IF EXISTS `gmms_galss_task_details`;
CREATE TABLE `gmms_galss_task_details`  (
  `id` bigint(20) NOT NULL,
  `rank` bigint(20) NULL DEFAULT 0 COMMENT '测量队列',
  `type_id` bigint(20) NULL DEFAULT NULL COMMENT '类型编号',
  `galss_id` bigint(20) NOT NULL COMMENT '玻璃编号',
  `pattern_id` bigint(20) NULL DEFAULT NULL COMMENT '版面编号',
  `width` double(6, 1) NULL DEFAULT NULL COMMENT '宽度',
  `height` double(6, 1) NULL DEFAULT NULL COMMENT '高度',
  `thickness` double(6, 1) NULL DEFAULT NULL COMMENT '厚度',
  `color` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '颜色',
  `edg_width` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '磨边宽度',
  `edg_height` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '磨边高度',
  `chamfer_size` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '倒角大小',
  `galss_type` int(11) NULL DEFAULT NULL COMMENT '玻璃类型 散单/整单',
  `edg_speed1` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '磨边速度',
  `edg_speed2` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '速度',
  `fine_throwing` int(11) NULL DEFAULT NULL COMMENT '精抛/粗磨',
  `work_state` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工作状态',
  `work_procedure` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工序',
  `slicecage_rank` bigint(20) NULL DEFAULT 0 COMMENT '理片笼架子',
  `drop_frame` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '落架',
  `slicecage_flag` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '0' COMMENT '理片笼标志(备用)',
  `out_rank` bigint(20) NOT NULL COMMENT '出理片笼序号',
  `start_time` datetime NOT NULL COMMENT '创建时间',
  `finsh_time` datetime NULL DEFAULT NULL COMMENT '完成时间',
  `stop_position` int(11) NOT NULL COMMENT '下片位置',
  `processcard_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '流程卡号',
  `engineering_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工程号',
  `broken_state` int(11) NOT NULL COMMENT '破片标记,非0破片',
  `stop_rank` int(11) NOT NULL COMMENT '片序',
  `work_procedure_number` int(11) NULL DEFAULT NULL COMMENT '工序标记',
  `gc_number` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '没用',
  `gc_width` double NULL DEFAULT NULL COMMENT '没用',
  `gc_height` double NULL DEFAULT NULL COMMENT '没用',
  `gc_stockid` int(11) NULL DEFAULT NULL COMMENT '没用',
  `marking_flag` int(11) NOT NULL COMMENT '打标',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `pattern_id`(`pattern_id`) USING BTREE,
  INDEX `galss_id`(`galss_id`) USING BTREE,
  INDEX `type_id`(`type_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_galss_task_hollow
-- ----------------------------
DROP TABLE IF EXISTS `gmms_galss_task_hollow`;
CREATE TABLE `gmms_galss_task_hollow`  (
  `id` bigint(20) NOT NULL,
  `rank` bigint(20) NULL DEFAULT 0 COMMENT '测量队列',
  `type_id` bigint(20) NULL DEFAULT NULL COMMENT '类型编号',
  `galss_id` bigint(20) NOT NULL COMMENT '玻璃编号',
  `pattern_id` bigint(20) NULL DEFAULT NULL COMMENT '版面编号',
  `width` double(6, 1) NULL DEFAULT NULL COMMENT '宽度',
  `height` double(6, 1) NULL DEFAULT NULL COMMENT '高度',
  `thickness` double(6, 1) NULL DEFAULT NULL COMMENT '厚度',
  `color` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '颜色',
  `edg_width` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '磨边宽度',
  `edg_height` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '磨边高度',
  `chamfer_size` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '倒角大小',
  `galss_type` int(11) NULL DEFAULT NULL COMMENT '玻璃类型 散单/整单',
  `edg_speed1` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '磨边速度',
  `edg_speed2` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '速度',
  `fine_throwing` int(11) NULL DEFAULT NULL COMMENT '精抛/粗磨',
  `work_state` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工作状态',
  `work_procedure` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工序',
  `slicecage_rank` bigint(20) NULL DEFAULT 0 COMMENT '理片笼架子',
  `drop_frame` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '落架',
  `slicecage_flag` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '0' COMMENT '理片笼标志(备用)',
  `out_rank` bigint(20) NOT NULL COMMENT '出理片笼序号',
  `start_time` datetime NOT NULL COMMENT '创建时间',
  `finsh_time` datetime NULL DEFAULT NULL COMMENT '完成时间',
  `stop_position` int(11) NOT NULL COMMENT '下片位置',
  `processcard_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '流程卡号',
  `engineering_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工程号',
  `broken_state` int(11) NOT NULL COMMENT '破片标记,非0破片',
  `stop_rank` int(11) NOT NULL COMMENT '片序',
  `work_procedure_number` int(11) NULL DEFAULT NULL COMMENT '工序标记',
  `gc_number` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '没用',
  `gc_width` double NULL DEFAULT NULL COMMENT '没用',
  `gc_height` double NULL DEFAULT NULL COMMENT '没用',
  `gc_stockid` int(11) NULL DEFAULT NULL COMMENT '没用',
  `marking_flag` int(11) NOT NULL COMMENT '打标',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `pattern_id`(`pattern_id`) USING BTREE,
  INDEX `galss_id`(`galss_id`) USING BTREE,
  INDEX `type_id`(`type_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_galss_task_interrupt
-- ----------------------------
DROP TABLE IF EXISTS `gmms_galss_task_interrupt`;
CREATE TABLE `gmms_galss_task_interrupt`  (
  `id` bigint(20) NOT NULL,
  `rank` bigint(20) NULL DEFAULT 0 COMMENT '测量队列',
  `type_id` bigint(20) NULL DEFAULT NULL COMMENT '类型编号',
  `galss_id` bigint(20) NOT NULL COMMENT '玻璃编号',
  `pattern_id` bigint(20) NULL DEFAULT NULL COMMENT '版面编号',
  `width` double(6, 1) NULL DEFAULT NULL COMMENT '宽度',
  `height` double(6, 1) NULL DEFAULT NULL COMMENT '高度',
  `thickness` double(6, 1) NULL DEFAULT NULL COMMENT '厚度',
  `color` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '颜色',
  `edg_width` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '磨边宽度',
  `edg_height` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '磨边高度',
  `chamfer_size` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '倒角大小',
  `galss_type` int(11) NULL DEFAULT NULL COMMENT '玻璃类型 散单/整单',
  `edg_speed1` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '磨边速度',
  `edg_speed2` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '速度',
  `fine_throwing` int(11) NULL DEFAULT NULL COMMENT '精抛/粗磨',
  `work_state` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工作状态',
  `work_procedure` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工序',
  `slicecage_rank` bigint(20) NULL DEFAULT 0 COMMENT '理片笼架子',
  `drop_frame` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '落架',
  `slicecage_flag` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '0' COMMENT '理片笼标志(备用)',
  `out_rank` bigint(20) NOT NULL COMMENT '出理片笼序号',
  `start_time` datetime NOT NULL COMMENT '创建时间',
  `finsh_time` datetime NULL DEFAULT NULL COMMENT '完成时间',
  `stop_position` int(11) NOT NULL COMMENT '下片位置',
  `processcard_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '流程卡号',
  `engineering_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工程号',
  `broken_state` int(11) NOT NULL COMMENT '破片标记,非0破片',
  `stop_rank` int(11) NOT NULL COMMENT '片序',
  `work_procedure_number` int(11) NULL DEFAULT NULL COMMENT '工序标记',
  `gc_number` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '没用',
  `gc_width` double NULL DEFAULT NULL COMMENT '没用',
  `gc_height` double NULL DEFAULT NULL COMMENT '没用',
  `gc_stockid` int(11) NULL DEFAULT NULL COMMENT '没用',
  `marking_flag` int(11) NOT NULL COMMENT '打标',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `pattern_id`(`pattern_id`) USING BTREE,
  INDEX `galss_id`(`galss_id`) USING BTREE,
  INDEX `type_id`(`type_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_galss_task_shelf
-- ----------------------------
DROP TABLE IF EXISTS `gmms_galss_task_shelf`;
CREATE TABLE `gmms_galss_task_shelf`  (
  `id` bigint(20) NOT NULL,
  `rank` bigint(20) NULL DEFAULT 0,
  `type_id` bigint(20) NULL DEFAULT NULL,
  `galss_id` bigint(20) NOT NULL,
  `pattern_id` bigint(20) NULL DEFAULT NULL,
  `width` double(6, 1) NULL DEFAULT NULL,
  `height` double(6, 1) NULL DEFAULT NULL,
  `thickness` double(6, 1) NULL DEFAULT NULL,
  `color` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `edg_width` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `edg_height` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `chamfer_size` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '倒角大小',
  `galss_type` int(11) NULL DEFAULT NULL COMMENT '玻璃类型 散单/整单',
  `edg_speed1` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '磨边速度',
  `edg_speed2` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `fine_throwing` int(11) NULL DEFAULT NULL COMMENT '精抛/粗磨',
  `work_state` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `work_procedure` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `slicecage_rank` bigint(20) NULL DEFAULT 0 COMMENT '理片笼架子',
  `drop_frame` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '落架',
  `slicecage_flag` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '0' COMMENT '理片笼标志(备用)',
  `out_rank` bigint(20) NOT NULL COMMENT '出理片笼序号',
  `start_time` datetime NOT NULL,
  `finsh_time` datetime NULL DEFAULT NULL,
  `stop_position` int(11) NOT NULL COMMENT '下片位置',
  `processcard_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '流程卡号',
  `engineering_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工程号',
  `broken_state` int(11) NOT NULL COMMENT '破片标记,非0破片',
  `stop_rank` int(11) NOT NULL,
  `work_procedure_number` int(11) NULL DEFAULT NULL,
  `gc_number` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `gc_width` double NULL DEFAULT NULL,
  `gc_height` double NULL DEFAULT NULL,
  `gc_stockid` int(11) NULL DEFAULT NULL,
  `marking_flag` int(11) NOT NULL COMMENT '打标',
  `groupsss` int(11) NULL DEFAULT NULL COMMENT '线路',
  `banzu` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '班组',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `pattern_id`(`pattern_id`) USING BTREE,
  INDEX `galss_id`(`galss_id`) USING BTREE,
  INDEX `type_id`(`type_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_galss_task_shelf_copy1
-- ----------------------------
DROP TABLE IF EXISTS `gmms_galss_task_shelf_copy1`;
CREATE TABLE `gmms_galss_task_shelf_copy1`  (
  `id` bigint(20) NOT NULL,
  `rank` bigint(20) NULL DEFAULT 0,
  `type_id` bigint(20) NULL DEFAULT NULL,
  `galss_id` bigint(20) NOT NULL,
  `pattern_id` bigint(20) NULL DEFAULT NULL,
  `width` double(6, 1) NULL DEFAULT NULL,
  `height` double(6, 1) NULL DEFAULT NULL,
  `thickness` double(6, 1) NULL DEFAULT NULL,
  `color` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `edg_width` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `edg_height` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `chamfer_size` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '倒角大小',
  `galss_type` int(11) NULL DEFAULT NULL COMMENT '玻璃类型 散单/整单',
  `edg_speed1` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '磨边速度',
  `edg_speed2` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `fine_throwing` int(11) NULL DEFAULT NULL COMMENT '精抛/粗磨',
  `work_state` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `work_procedure` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `slicecage_rank` bigint(20) NULL DEFAULT 0 COMMENT '理片笼架子',
  `drop_frame` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '落架',
  `slicecage_flag` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '0' COMMENT '理片笼标志(备用)',
  `out_rank` bigint(20) NOT NULL COMMENT '出理片笼序号',
  `start_time` datetime NOT NULL,
  `finsh_time` datetime NULL DEFAULT NULL,
  `stop_position` int(11) NOT NULL COMMENT '下片位置',
  `processcard_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '流程卡号',
  `engineering_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工程号',
  `broken_state` int(11) NOT NULL COMMENT '破片标记,非0破片',
  `stop_rank` int(11) NOT NULL,
  `work_procedure_number` int(11) NULL DEFAULT NULL,
  `gc_number` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `gc_width` double NULL DEFAULT NULL,
  `gc_height` double NULL DEFAULT NULL,
  `gc_stockid` int(11) NULL DEFAULT NULL,
  `marking_flag` int(11) NOT NULL COMMENT '打标',
  `youhuashijian` datetime NULL DEFAULT NULL,
  `youhua` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `pattern_id`(`pattern_id`) USING BTREE,
  INDEX `galss_id`(`galss_id`) USING BTREE,
  INDEX `type_id`(`type_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_galss_task_shelf_copy2
-- ----------------------------
DROP TABLE IF EXISTS `gmms_galss_task_shelf_copy2`;
CREATE TABLE `gmms_galss_task_shelf_copy2`  (
  `id` bigint(20) NOT NULL,
  `rank` bigint(20) NULL DEFAULT 0,
  `type_id` bigint(20) NULL DEFAULT NULL,
  `galss_id` bigint(20) NOT NULL,
  `pattern_id` bigint(20) NULL DEFAULT NULL,
  `width` double(6, 1) NULL DEFAULT NULL,
  `height` double(6, 1) NULL DEFAULT NULL,
  `thickness` double(6, 1) NULL DEFAULT NULL,
  `color` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `edg_width` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `edg_height` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `chamfer_size` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '倒角大小',
  `galss_type` int(11) NULL DEFAULT NULL COMMENT '玻璃类型 散单/整单',
  `edg_speed1` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '磨边速度',
  `edg_speed2` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `fine_throwing` int(11) NULL DEFAULT NULL COMMENT '精抛/粗磨',
  `work_state` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `work_procedure` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `slicecage_rank` bigint(20) NULL DEFAULT 0 COMMENT '理片笼架子',
  `drop_frame` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '落架',
  `slicecage_flag` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '0' COMMENT '理片笼标志(备用)',
  `out_rank` bigint(20) NOT NULL COMMENT '出理片笼序号',
  `start_time` datetime NOT NULL,
  `finsh_time` datetime NULL DEFAULT NULL,
  `stop_position` int(11) NOT NULL COMMENT '下片位置',
  `processcard_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '流程卡号',
  `engineering_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工程号',
  `broken_state` int(11) NOT NULL COMMENT '破片标记,非0破片',
  `stop_rank` int(11) NOT NULL,
  `work_procedure_number` int(11) NULL DEFAULT NULL,
  `gc_number` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `gc_width` double NULL DEFAULT NULL,
  `gc_height` double NULL DEFAULT NULL,
  `gc_stockid` int(11) NULL DEFAULT NULL,
  `marking_flag` int(11) NOT NULL COMMENT '打标',
  `groupsss` int(11) NULL DEFAULT NULL COMMENT '线路',
  `banzu` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '班组',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `pattern_id`(`pattern_id`) USING BTREE,
  INDEX `galss_id`(`galss_id`) USING BTREE,
  INDEX `type_id`(`type_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_galss_task_shelf_copy3
-- ----------------------------
DROP TABLE IF EXISTS `gmms_galss_task_shelf_copy3`;
CREATE TABLE `gmms_galss_task_shelf_copy3`  (
  `id` bigint(20) NOT NULL,
  `rank` bigint(20) NULL DEFAULT 0,
  `type_id` bigint(20) NULL DEFAULT NULL,
  `galss_id` bigint(20) NOT NULL,
  `pattern_id` bigint(20) NULL DEFAULT NULL,
  `width` double(6, 1) NULL DEFAULT NULL,
  `height` double(6, 1) NULL DEFAULT NULL,
  `thickness` double(6, 1) NULL DEFAULT NULL,
  `color` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `edg_width` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `edg_height` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `chamfer_size` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '倒角大小',
  `galss_type` int(11) NULL DEFAULT NULL COMMENT '玻璃类型 散单/整单',
  `edg_speed1` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '磨边速度',
  `edg_speed2` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `fine_throwing` int(11) NULL DEFAULT NULL COMMENT '精抛/粗磨',
  `work_state` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `work_procedure` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `slicecage_rank` bigint(20) NULL DEFAULT 0 COMMENT '理片笼架子',
  `drop_frame` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '落架',
  `slicecage_flag` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '0' COMMENT '理片笼标志(备用)',
  `out_rank` bigint(20) NOT NULL COMMENT '出理片笼序号',
  `start_time` datetime NOT NULL,
  `finsh_time` datetime NULL DEFAULT NULL,
  `stop_position` int(11) NOT NULL COMMENT '下片位置',
  `processcard_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '流程卡号',
  `engineering_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工程号',
  `broken_state` int(11) NOT NULL COMMENT '破片标记,非0破片',
  `stop_rank` int(11) NOT NULL,
  `work_procedure_number` int(11) NULL DEFAULT NULL,
  `gc_number` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `gc_width` double NULL DEFAULT NULL,
  `gc_height` double NULL DEFAULT NULL,
  `gc_stockid` int(11) NULL DEFAULT NULL,
  `marking_flag` int(11) NOT NULL COMMENT '打标',
  `groupsss` int(11) NULL DEFAULT NULL COMMENT '线路',
  `banzu` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '班组',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `pattern_id`(`pattern_id`) USING BTREE,
  INDEX `galss_id`(`galss_id`) USING BTREE,
  INDEX `type_id`(`type_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_galss_task_shelf_log
-- ----------------------------
DROP TABLE IF EXISTS `gmms_galss_task_shelf_log`;
CREATE TABLE `gmms_galss_task_shelf_log`  (
  `id` bigint(20) NOT NULL,
  `rank` bigint(20) NULL DEFAULT 0,
  `type_id` bigint(20) NULL DEFAULT NULL,
  `galss_id` bigint(20) NOT NULL,
  `pattern_id` bigint(20) NULL DEFAULT NULL,
  `width` double(6, 1) NULL DEFAULT NULL,
  `height` double(6, 1) NULL DEFAULT NULL,
  `thickness` double(6, 1) NULL DEFAULT NULL,
  `color` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `edg_width` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `edg_height` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `chamfer_size` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '倒角大小',
  `galss_type` int(11) NULL DEFAULT NULL COMMENT '玻璃类型 散单/整单',
  `edg_speed1` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '磨边速度',
  `edg_speed2` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `fine_throwing` int(11) NULL DEFAULT NULL COMMENT '精抛/粗磨',
  `work_state` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `work_procedure` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `slicecage_rank` bigint(20) NULL DEFAULT 0 COMMENT '理片笼架子',
  `drop_frame` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '落架',
  `slicecage_flag` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '0' COMMENT '理片笼标志(备用)',
  `out_rank` bigint(20) NOT NULL COMMENT '出理片笼序号',
  `start_time` datetime NOT NULL,
  `finsh_time` datetime NULL DEFAULT NULL,
  `stop_position` int(11) NOT NULL COMMENT '下片位置',
  `processcard_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '流程卡号',
  `engineering_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工程号',
  `broken_state` int(11) NOT NULL COMMENT '破片标记,非0破片',
  `stop_rank` int(11) NOT NULL,
  `work_procedure_number` int(11) NULL DEFAULT NULL,
  `gc_number` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `gc_width` double NULL DEFAULT NULL,
  `gc_height` double NULL DEFAULT NULL,
  `gc_stockid` int(11) NULL DEFAULT NULL,
  `marking_flag` int(11) NOT NULL COMMENT '打标',
  `groupsss` int(11) NULL DEFAULT NULL COMMENT '线路',
  `banzu` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '班组',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `pattern_id`(`pattern_id`) USING BTREE,
  INDEX `galss_id`(`galss_id`) USING BTREE,
  INDEX `type_id`(`type_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_galss_task_slicecage
-- ----------------------------
DROP TABLE IF EXISTS `gmms_galss_task_slicecage`;
CREATE TABLE `gmms_galss_task_slicecage`  (
  `id` bigint(20) NOT NULL,
  `rank` bigint(20) NULL DEFAULT 0 COMMENT '测量队列',
  `type_id` bigint(20) NULL DEFAULT NULL COMMENT '类型编号',
  `galss_id` bigint(20) NOT NULL COMMENT '玻璃编号',
  `pattern_id` bigint(20) NULL DEFAULT NULL COMMENT '版面编号',
  `width` double(6, 1) NULL DEFAULT NULL COMMENT '宽度',
  `height` double(6, 1) NULL DEFAULT NULL COMMENT '高度',
  `thickness` double(6, 1) NULL DEFAULT NULL COMMENT '厚度',
  `color` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '颜色',
  `edg_width` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '磨边宽度',
  `edg_height` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '磨边高度',
  `chamfer_size` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '倒角大小',
  `galss_type` int(11) NULL DEFAULT NULL COMMENT '玻璃类型 散单/整单',
  `edg_speed1` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '磨边速度',
  `edg_speed2` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '速度',
  `fine_throwing` int(11) NULL DEFAULT NULL COMMENT '精抛/粗磨',
  `work_state` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工作状态',
  `work_procedure` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工序',
  `slicecage_rank` bigint(20) NULL DEFAULT 0 COMMENT '理片笼架子',
  `drop_frame` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '落架',
  `slicecage_flag` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '0' COMMENT '理片笼标志(备用)',
  `out_rank` bigint(20) NOT NULL COMMENT '出理片笼序号',
  `start_time` datetime NOT NULL COMMENT '创建时间',
  `finsh_time` datetime NULL DEFAULT NULL COMMENT '完成时间',
  `stop_position` int(11) NOT NULL COMMENT '下片位置',
  `processcard_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '流程卡号',
  `engineering_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工程号',
  `broken_state` int(11) NOT NULL COMMENT '破片标记,非0破片',
  `stop_rank` int(11) NOT NULL COMMENT '片序',
  `work_procedure_number` int(11) NULL DEFAULT NULL COMMENT '工序标记',
  `gc_number` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '没用',
  `gc_width` double NULL DEFAULT NULL COMMENT '没用',
  `gc_height` double NULL DEFAULT NULL COMMENT '没用',
  `gc_stockid` int(11) NULL DEFAULT NULL COMMENT '没用',
  `marking_flag` int(11) NOT NULL COMMENT '打标',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `pattern_id`(`pattern_id`) USING BTREE,
  INDEX `galss_id`(`galss_id`) USING BTREE,
  INDEX `type_id`(`type_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_galss_task_stock
-- ----------------------------
DROP TABLE IF EXISTS `gmms_galss_task_stock`;
CREATE TABLE `gmms_galss_task_stock`  (
  `id` bigint(20) NOT NULL,
  `rank` bigint(20) NULL DEFAULT 0 COMMENT '测量队列',
  `type_id` bigint(20) NULL DEFAULT NULL COMMENT '类型编号',
  `galss_id` bigint(20) NOT NULL COMMENT '玻璃编号',
  `pattern_id` bigint(20) NULL DEFAULT NULL COMMENT '版面编号',
  `width` double(6, 1) NULL DEFAULT NULL COMMENT '宽度',
  `height` double(6, 1) NULL DEFAULT NULL COMMENT '高度',
  `thickness` double(6, 1) NULL DEFAULT NULL COMMENT '厚度',
  `color` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '颜色',
  `edg_width` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '磨边宽度',
  `edg_height` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '磨边高度',
  `chamfer_size` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '倒角大小',
  `galss_type` int(11) NULL DEFAULT NULL COMMENT '玻璃类型 散单/整单',
  `edg_speed1` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '磨边速度',
  `edg_speed2` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '速度',
  `fine_throwing` int(11) NULL DEFAULT NULL COMMENT '精抛/粗磨',
  `work_state` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工作状态',
  `work_procedure` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工序',
  `slicecage_rank` bigint(20) NULL DEFAULT 0 COMMENT '理片笼架子',
  `drop_frame` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '落架',
  `slicecage_flag` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '0' COMMENT '理片笼标志(备用)',
  `out_rank` bigint(20) NOT NULL COMMENT '出理片笼序号',
  `start_time` datetime NOT NULL COMMENT '创建时间',
  `finsh_time` datetime NULL DEFAULT NULL COMMENT '完成时间',
  `stop_position` int(11) NOT NULL COMMENT '下片位置',
  `processcard_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '流程卡号',
  `engineering_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工程号',
  `broken_state` int(11) NOT NULL COMMENT '破片标记,非0破片',
  `stop_rank` int(11) NOT NULL COMMENT '片序',
  `work_procedure_number` int(11) NULL DEFAULT NULL COMMENT '工序标记',
  `gc_number` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '没用',
  `gc_width` double NULL DEFAULT NULL COMMENT '没用',
  `gc_height` double NULL DEFAULT NULL COMMENT '没用',
  `gc_stockid` int(11) NULL DEFAULT NULL COMMENT '没用',
  `marking_flag` int(11) NOT NULL COMMENT '打标',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `pattern_id`(`pattern_id`) USING BTREE,
  INDEX `galss_id`(`galss_id`) USING BTREE,
  INDEX `type_id`(`type_id`) USING BTREE,
  INDEX `finsh_time`(`finsh_time`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_galss_task_stock1
-- ----------------------------
DROP TABLE IF EXISTS `gmms_galss_task_stock1`;
CREATE TABLE `gmms_galss_task_stock1`  (
  `id` bigint(20) NOT NULL,
  `rank` bigint(20) NULL DEFAULT 0,
  `type_id` bigint(20) NULL DEFAULT NULL,
  `galss_id` bigint(20) NOT NULL,
  `pattern_id` bigint(20) NULL DEFAULT NULL,
  `width` double(6, 1) NULL DEFAULT NULL,
  `height` double(6, 1) NULL DEFAULT NULL,
  `thickness` double(6, 1) NULL DEFAULT NULL,
  `color` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `edg_width` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `edg_height` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `chamfer_size` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '倒角大小',
  `galss_type` int(11) NULL DEFAULT NULL COMMENT '玻璃类型 散单/整单',
  `edg_speed1` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '磨边速度',
  `edg_speed2` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `fine_throwing` int(11) NULL DEFAULT NULL COMMENT '精抛/粗磨',
  `work_state` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `work_procedure` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `slicecage_rank` bigint(20) NULL DEFAULT 0 COMMENT '理片笼架子',
  `drop_frame` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '落架',
  `slicecage_flag` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '0' COMMENT '理片笼标志(备用)',
  `out_rank` bigint(20) NOT NULL COMMENT '出理片笼序号',
  `start_time` datetime NOT NULL,
  `finsh_time` datetime NULL DEFAULT NULL,
  `stop_position` int(11) NOT NULL COMMENT '下片位置',
  `processcard_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '流程卡号',
  `engineering_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工程号',
  `broken_state` int(11) NOT NULL COMMENT '破片标记,非0破片',
  `stop_rank` int(11) NOT NULL,
  `work_procedure_number` int(11) NULL DEFAULT NULL,
  `gc_number` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `gc_width` double NULL DEFAULT NULL,
  `gc_height` double NULL DEFAULT NULL,
  `gc_stockid` int(11) NULL DEFAULT NULL,
  `marking_flag` int(11) NOT NULL COMMENT '打标',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `pattern_id`(`pattern_id`) USING BTREE,
  INDEX `galss_id`(`galss_id`) USING BTREE,
  INDEX `type_id`(`type_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_ganghuatuijian_log
-- ----------------------------
DROP TABLE IF EXISTS `gmms_ganghuatuijian_log`;
CREATE TABLE `gmms_ganghuatuijian_log`  (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Parameter` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '参数',
  `Result` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '结果',
  `Result_Detail` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL,
  `StrRemark` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `IntRemark` int(255) NULL DEFAULT NULL,
  `CreateTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  PRIMARY KEY (`Id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 35 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_glass_log
-- ----------------------------
DROP TABLE IF EXISTS `gmms_glass_log`;
CREATE TABLE `gmms_glass_log`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `main_id` bigint(20) NULL DEFAULT NULL,
  `glass_id` bigint(20) NULL DEFAULT NULL COMMENT '玻璃ID',
  `segment_name` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `work_name` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `line` int(11) NULL DEFAULT NULL COMMENT '所在线',
  `begin_time` datetime NULL DEFAULT NULL COMMENT '开始时间',
  `end_time` datetime NULL DEFAULT NULL COMMENT '结束时间',
  `status` int(11) NULL DEFAULT NULL COMMENT '状态标志',
  `parent_id` bigint(20) NULL DEFAULT NULL,
  `area` decimal(20, 7) NULL DEFAULT NULL COMMENT '面积',
  `freeze` bit(1) NULL DEFAULT b'0' COMMENT '冻结,不可改',
  `time_out` bit(1) NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `end_time_idx`(`end_time`) USING BTREE,
  INDEX `gid`(`glass_id`) USING BTREE,
  CONSTRAINT `g_id_f` FOREIGN KEY (`glass_id`) REFERENCES `gmms_galss_task_buffer` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE = InnoDB AUTO_INCREMENT = 3949683 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_glass_log_config
-- ----------------------------
DROP TABLE IF EXISTS `gmms_glass_log_config`;
CREATE TABLE `gmms_glass_log_config`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `work_name` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '记录名',
  `status` int(11) NULL DEFAULT NULL COMMENT '1   第一道   2  中间工序   3 最后一道  ',
  `work_proc` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'mes 工作名',
  `work_status` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'mes 工作状态',
  `line` int(11) NULL DEFAULT NULL COMMENT '配置所属线号',
  `segment` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '配置所属工艺段',
  `segment_number` int(11) NULL DEFAULT NULL COMMENT '分段编号   相同代表相同工艺  数字大的在后面',
  `work_number` int(11) NULL DEFAULT NULL COMMENT '工艺序号   在本工艺分段中的编号,大的在后',
  `segment_status` tinyint(4) NULL DEFAULT NULL COMMENT ' 0  开始    1  中间   2  完成   3 破损(破损暂时不用)',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 89 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_glass_log_main
-- ----------------------------
DROP TABLE IF EXISTS `gmms_glass_log_main`;
CREATE TABLE `gmms_glass_log_main`  (
  `id` bigint(11) NOT NULL AUTO_INCREMENT,
  `segment` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `gongchenghao` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `create_time` datetime NULL DEFAULT NULL,
  `line` int(11) NULL DEFAULT NULL,
  `state` int(11) NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 377 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_glass_number_color
-- ----------------------------
DROP TABLE IF EXISTS `gmms_glass_number_color`;
CREATE TABLE `gmms_glass_number_color`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `glass_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '玻璃类型',
  `flag` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '标记',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 94 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_glass_yuliao
-- ----------------------------
DROP TABLE IF EXISTS `gmms_glass_yuliao`;
CREATE TABLE `gmms_glass_yuliao`  (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `gongchenghao` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工程号',
  `wuliaodaima` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '物料代码',
  `bantuxuhao` int(255) NULL DEFAULT NULL COMMENT '版图序号',
  `moxi` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '膜系',
  `houdu` int(255) NULL DEFAULT NULL COMMENT '厚度',
  `kuan` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '宽',
  `gao` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '高',
  `shuliang` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '数量',
  `mianji` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '面积',
  `ruku` int(255) NULL DEFAULT 0 COMMENT '是否入库:0否1是,默认0',
  `shiyong` int(255) NULL DEFAULT 0 COMMENT '是否使用:0否1是,默认0',
  `shanchu` int(255) NULL DEFAULT 0 COMMENT '是否删除:0否1是,默认0',
  `IntRemark` int(255) NULL DEFAULT NULL COMMENT '预留列,占用时注明用途',
  `StrRemark` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '预留列,占用是注明用途',
  `UpdateTime` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `CreateTime` datetime NULL DEFAULT NULL COMMENT '创建时间',
  PRIMARY KEY (`Id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 341468 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_globel_var
-- ----------------------------
DROP TABLE IF EXISTS `gmms_globel_var`;
CREATE TABLE `gmms_globel_var`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `line` int(255) NULL DEFAULT NULL,
  `var_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `int_value` int(255) NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_horizontal
-- ----------------------------
DROP TABLE IF EXISTS `gmms_horizontal`;
CREATE TABLE `gmms_horizontal`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `slicecage_rank` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '架号',
  `state` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '状态',
  `type_id` bigint(20) NOT NULL COMMENT '类型编号',
  `count` int(11) NOT NULL DEFAULT 0 COMMENT '数量',
  `flag` int(20) NOT NULL DEFAULT 0 COMMENT '0/1',
  `gourp` bigint(20) NULL DEFAULT NULL COMMENT '线路',
  `processcard_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '流程卡号',
  `Update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `glass_id`(`type_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 101 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_identify_error
-- ----------------------------
DROP TABLE IF EXISTS `gmms_identify_error`;
CREATE TABLE `gmms_identify_error`  (
  `id` int(11) NOT NULL,
  `widtherror` double(4, 1) NULL DEFAULT NULL COMMENT '宽度误差',
  `heigtherror` double(4, 1) NULL DEFAULT NULL COMMENT '高度误差',
  `groups` int(11) NULL DEFAULT NULL COMMENT '线路',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_identify_error_details
-- ----------------------------
DROP TABLE IF EXISTS `gmms_identify_error_details`;
CREATE TABLE `gmms_identify_error_details`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `galssid` bigint(20) NULL DEFAULT NULL COMMENT '玻璃编号',
  `width` double(6, 1) NULL DEFAULT NULL COMMENT '宽度',
  `heigth` double(6, 1) NULL DEFAULT NULL COMMENT '高度',
  `error_width` double(6, 1) NULL DEFAULT NULL COMMENT '测量宽度',
  `error_heigth` double(6, 1) NULL DEFAULT NULL COMMENT '测量高度',
  `groups` bigint(20) NULL DEFAULT NULL COMMENT '线路',
  `times` datetime NULL DEFAULT NULL COMMENT '时间',
  `flag` int(11) NOT NULL,
  `content` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '匹配内容',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 2588657 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_identify_mark
-- ----------------------------
DROP TABLE IF EXISTS `gmms_identify_mark`;
CREATE TABLE `gmms_identify_mark`  (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `Line` tinyint(11) NULL DEFAULT NULL COMMENT '生产线',
  `GHMark` tinyint(1) NULL DEFAULT NULL COMMENT '钢化是否打标:0不打标1打标',
  `DBMark` tinyint(1) NULL DEFAULT NULL COMMENT '不钢化是否打标:0不大标1打标',
  `IntRemark` int(11) NULL DEFAULT NULL COMMENT '预留列',
  `StrRemark` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '预留列',
  `Update_Time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  PRIMARY KEY (`ID`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 11 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_identify_mark_update
-- ----------------------------
DROP TABLE IF EXISTS `gmms_identify_mark_update`;
CREATE TABLE `gmms_identify_mark_update`  (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `gongchenghao` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `DBMark` tinyint(255) NULL DEFAULT 0 COMMENT '记录非钢化打标类型,1打标0不打标',
  `GHMark` tinyint(255) NULL DEFAULT 0 COMMENT '记录钢化打标类型,0不打标1打标',
  `line` tinyint(4) NULL DEFAULT NULL COMMENT '生产线',
  `IntRemark` int(255) NULL DEFAULT NULL COMMENT '预留列',
  `StrRemark` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '预留列',
  `Create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间',
  PRIMARY KEY (`ID`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 39 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_journal
-- ----------------------------
DROP TABLE IF EXISTS `gmms_journal`;
CREATE TABLE `gmms_journal`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `rank` bigint(20) NULL DEFAULT 0,
  `type_id` bigint(20) NULL DEFAULT NULL,
  `galss_id` bigint(20) NOT NULL,
  `pattern_id` bigint(20) NULL DEFAULT NULL,
  `width` double NULL DEFAULT NULL,
  `height` double NULL DEFAULT NULL,
  `thickness` double NULL DEFAULT NULL,
  `color` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `edg_width` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `edg_height` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `chamfer_size` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '倒角大小',
  `galss_type` int(11) NULL DEFAULT NULL COMMENT '玻璃类型 散单/整单',
  `edg_speed1` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '磨边速度',
  `edg_speed2` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `fine_throwing` int(11) NULL DEFAULT NULL COMMENT '精抛/粗磨',
  `work_state` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `work_procedure` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `slicecage_rank` bigint(20) NULL DEFAULT 0 COMMENT '理片笼架子',
  `drop_frame` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '落架',
  `slicecage_flag` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '0' COMMENT '理片笼标志',
  `out_rank` bigint(20) NOT NULL COMMENT '出理片笼序号',
  `start_time` datetime NOT NULL,
  `finsh_time` datetime NULL DEFAULT NULL,
  `stop_position` int(11) NULL DEFAULT NULL COMMENT '下片位置',
  `processcard_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '流程卡号',
  `engineering_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工程号',
  `broken_state` int(11) NOT NULL COMMENT '破片标记,非0破片',
  `work_procedure_number` int(11) NULL DEFAULT NULL,
  `message` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '报文',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `pattern_id`(`pattern_id`) USING BTREE,
  INDEX `galss_id`(`galss_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_liuchengka
-- ----------------------------
DROP TABLE IF EXISTS `gmms_liuchengka`;
CREATE TABLE `gmms_liuchengka`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `liuchengka` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '流程卡',
  `gongchenghao` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '对应工程号(单片才有)',
  `parent_liuchengka` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '父流程卡',
  `main_liuchengka` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `is_single` bit(1) NULL DEFAULT NULL COMMENT '是单片',
  `child_count` tinyint(4) NULL DEFAULT NULL COMMENT '合片层数',
  `current_status` varchar(11) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '未开始   开始    结束   撤销\r\n',
  `current_work_position` varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '当前工作位置',
  `current_frame` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '当前所属架',
  `last_changed_time` datetime NULL DEFAULT NULL,
  `piece_count` int(11) NULL DEFAULT NULL COMMENT '小片数',
  `gy_gang` bit(1) NOT NULL DEFAULT b'0',
  `gy_jiajiao` bit(1) NOT NULL DEFAULT b'0',
  `gy_zhongkong` bit(1) NOT NULL DEFAULT b'0',
  `gongyi` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '\0',
  `Occupied` int(11) NULL DEFAULT 0 COMMENT '占用,0初始 其他数字表示架子位//12.06新增',
  `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间,自动记录,//12.06新增',
  `getdatatime` datetime NULL DEFAULT NULL COMMENT '领取时间',
  `getgroups` bigint(20) NULL DEFAULT NULL COMMENT '领取线路',
  `isyou` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '是否在优化',
  `Suction_sheet_mode` int(11) NULL DEFAULT 0 COMMENT '吸片模式,0初始 其他数字表示反吸//6.19新增',
  `ischu` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '是否出库',
  `xiapianbiaoji` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `isgang` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '',
  `minArea` double NULL DEFAULT NULL COMMENT '最小面积',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `main_liuchengka_idx`(`main_liuchengka`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 78834 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_liuchengka_buffer
-- ----------------------------
DROP TABLE IF EXISTS `gmms_liuchengka_buffer`;
CREATE TABLE `gmms_liuchengka_buffer`  (
  `ID` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID',
  `liuchengkahao` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '流程卡号',
  `liuchengkahaoceng` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '流程卡号/层',
  `gongyiliucheng` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工程流程',
  `loucengbianhao` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '楼层编号',
  `mianji` decimal(7, 2) NULL DEFAULT NULL COMMENT '总面积',
  `shuliang` int(50) NULL DEFAULT NULL COMMENT '总数量',
  `ceng` int(10) NULL DEFAULT NULL COMMENT '层',
  `moxi` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '膜系',
  `houdu` int(20) NULL DEFAULT NULL COMMENT '厚度',
  `hepianshunxu` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '合片顺序',
  `lowe` int(255) NULL DEFAULT NULL COMMENT '是否lowe',
  `suoshudingdan` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '所属订单',
  `gongchenghao` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工程号',
  `IntRemark` int(255) NULL DEFAULT NULL COMMENT '预留列,占用时请标明',
  `StrRemark` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '预留列,占用时请标明',
  `Create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  PRIMARY KEY (`ID`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 61757 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_liuchengka_copy1
-- ----------------------------
DROP TABLE IF EXISTS `gmms_liuchengka_copy1`;
CREATE TABLE `gmms_liuchengka_copy1`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `liuchengka` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '流程卡',
  `gongchenghao` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '对应工程号(单片才有)',
  `parent_liuchengka` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '父流程卡',
  `main_liuchengka` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `is_single` bit(1) NULL DEFAULT NULL COMMENT '是单片',
  `child_count` tinyint(4) NULL DEFAULT NULL COMMENT '合片层数',
  `current_status` varchar(11) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '未开始   开始    结束   撤销\r\n',
  `current_work_position` varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '当前工作位置',
  `current_frame` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '当前所属架',
  `last_changed_time` datetime NULL DEFAULT NULL,
  `piece_count` int(11) NULL DEFAULT NULL COMMENT '小片数',
  `gy_gang` bit(1) NOT NULL DEFAULT b'0',
  `gy_jiajiao` bit(1) NOT NULL DEFAULT b'0',
  `gy_zhongkong` bit(1) NOT NULL DEFAULT b'0',
  `gongyi` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '\0',
  `Occupied` int(11) NULL DEFAULT 0 COMMENT '占用,0初始 其他数字表示架子位//12.06新增',
  `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间,自动记录,//12.06新增',
  `getdatatime` datetime NULL DEFAULT NULL COMMENT '领取时间',
  `getgroups` bigint(20) NULL DEFAULT NULL COMMENT '领取线路',
  `isyou` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '是否在优化',
  `Suction_sheet_mode` int(11) NULL DEFAULT 0 COMMENT '吸片模式,0初始 其他数字表示反吸//6.19新增',
  `ischu` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '是否出库',
  `xiapianbiaoji` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `isgang` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `main_liuchengka_idx`(`main_liuchengka`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 45084 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_liuchengka_copy2
-- ----------------------------
DROP TABLE IF EXISTS `gmms_liuchengka_copy2`;
CREATE TABLE `gmms_liuchengka_copy2`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `liuchengka` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '流程卡',
  `gongchenghao` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '对应工程号(单片才有)',
  `parent_liuchengka` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '父流程卡',
  `main_liuchengka` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `is_single` bit(1) NULL DEFAULT NULL COMMENT '是单片',
  `child_count` tinyint(4) NULL DEFAULT NULL COMMENT '合片层数',
  `current_status` varchar(11) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '未开始   开始    结束   撤销\r\n',
  `current_work_position` varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '当前工作位置',
  `current_frame` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '当前所属架',
  `last_changed_time` datetime NULL DEFAULT NULL,
  `piece_count` int(11) NULL DEFAULT NULL COMMENT '小片数',
  `gy_gang` bit(1) NOT NULL DEFAULT b'0',
  `gy_jiajiao` bit(1) NOT NULL DEFAULT b'0',
  `gy_zhongkong` bit(1) NOT NULL DEFAULT b'0',
  `gongyi` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '\0',
  `Occupied` int(11) NULL DEFAULT 0 COMMENT '占用,0初始 其他数字表示架子位//12.06新增',
  `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间,自动记录,//12.06新增',
  `getdatatime` datetime NULL DEFAULT NULL COMMENT '领取时间',
  `getgroups` bigint(20) NULL DEFAULT NULL COMMENT '领取线路',
  `isyou` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '是否在优化',
  `Suction_sheet_mode` int(11) NULL DEFAULT 0 COMMENT '吸片模式,0初始 其他数字表示反吸//6.19新增',
  `ischu` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '是否出库',
  `xiapianbiaoji` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `isgang` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `main_liuchengka_idx`(`main_liuchengka`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 45592 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_liuchengka_dayin_buffer
-- ----------------------------
DROP TABLE IF EXISTS `gmms_liuchengka_dayin_buffer`;
CREATE TABLE `gmms_liuchengka_dayin_buffer`  (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `baozhuangfangshi` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '包装方式',
  `liuchengkahao` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '流程卡号',
  `ceng` int(11) NULL DEFAULT NULL COMMENT '层',
  `kehumingcheng` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '客户名称',
  `xiangmumingcheng` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '项目名称',
  `gongyiliucheng` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工艺流程',
  `danpianmingcheng` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '单片名称',
  `chanpinmingcheng` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '产品名称',
  `jiagongyaoqiu` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '加工要求',
  `pici` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '批次',
  `houdu` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '厚度',
  `qiepian` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '切片类型',
  `mobian` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '磨边类型',
  `yinbiao` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '印标类型',
  `jiajiao` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '夹胶类型',
  `zhongkong` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '中空类型',
  `baozhuang` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '包装类型',
  `tianfenID` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '天分',
  `saleID` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `zongpianshu` int(255) NULL DEFAULT NULL COMMENT '总片数',
  `zongliuchengshu` int(255) NULL DEFAULT NULL COMMENT '销售单总流程数',
  `gongchenghao` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工程号',
  `Create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `IntRemark` int(255) NULL DEFAULT NULL COMMENT '预留列,使用需注明',
  `StrRemark` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '预留列,使用需注明',
  PRIMARY KEY (`ID`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 53854 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_load_rack
-- ----------------------------
DROP TABLE IF EXISTS `gmms_load_rack`;
CREATE TABLE `gmms_load_rack`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `number` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '架子编号',
  `machine_id` bigint(20) NULL DEFAULT NULL COMMENT '机器编号',
  `falg` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '启用标记',
  `state` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工作状态',
  `shelf_task_id` bigint(20) NULL DEFAULT NULL COMMENT '仓储任务编号',
  `falg_shelf` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '标记是否有玻璃',
  `type_falg` int(11) NOT NULL DEFAULT 0 COMMENT '上片位类型',
  `groups` bigint(20) NOT NULL COMMENT '线路',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `machine_id`(`machine_id`) USING BTREE,
  INDEX `shelf_task_id`(`shelf_task_id`) USING BTREE,
  CONSTRAINT `gmms_load_rack_ibfk_1` FOREIGN KEY (`machine_id`) REFERENCES `gmms_machine` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  CONSTRAINT `gmms_load_rack_ibfk_2` FOREIGN KEY (`shelf_task_id`) REFERENCES `gmms_shelf_task` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB AUTO_INCREMENT = 11 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_log_glass
-- ----------------------------
DROP TABLE IF EXISTS `gmms_log_glass`;
CREATE TABLE `gmms_log_glass`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `glass_id` bigint(20) NULL DEFAULT NULL COMMENT '玻璃ID',
  `segment` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工艺段(冷加工,钢化,中空)',
  `work_name` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '(小工艺段)',
  `line` int(11) NULL DEFAULT NULL COMMENT '所属线号',
  `begin_time` datetime NULL DEFAULT NULL COMMENT '开始时间',
  `end_time` datetime NULL DEFAULT NULL COMMENT '结束时间',
  `liuchengka` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '所属流程卡',
  `broken` bit(1) NULL DEFAULT NULL COMMENT '破损',
  `time_out` bit(1) NULL DEFAULT NULL COMMENT '过时_无效记录(返工重做,会将之前日志无效掉)',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_machine
-- ----------------------------
DROP TABLE IF EXISTS `gmms_machine`;
CREATE TABLE `gmms_machine`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `machine_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '机器名字',
  `machine_type_id` bigint(20) NOT NULL COMMENT '类型编号',
  `ip_address` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'IP地址',
  `port` int(11) NULL DEFAULT NULL COMMENT '端口',
  `state` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '机器状态',
  `connect_state` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '连接状态',
  `work_state` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工作状态',
  `work_id` bigint(20) NULL DEFAULT NULL COMMENT '线路',
  `flag` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '启用标记',
  `remarks` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '备注',
  `software_connect` int(11) NOT NULL,
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `machine_type_id`(`machine_type_id`) USING BTREE,
  CONSTRAINT `gmms_machine_ibfk_1` FOREIGN KEY (`machine_type_id`) REFERENCES `gmms_machine_type` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB AUTO_INCREMENT = 76 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_machine_copy1
-- ----------------------------
DROP TABLE IF EXISTS `gmms_machine_copy1`;
CREATE TABLE `gmms_machine_copy1`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `machine_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `machine_type_id` bigint(20) NOT NULL,
  `ip_address` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `port` int(11) NULL DEFAULT NULL,
  `state` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `connect_state` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `work_state` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `work_id` bigint(20) NULL DEFAULT NULL,
  `flag` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `remarks` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `machine_type_id`(`machine_type_id`) USING BTREE,
  CONSTRAINT `gmms_machine_copy1_ibfk_1` FOREIGN KEY (`machine_type_id`) REFERENCES `gmms_machine_type` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB AUTO_INCREMENT = 20 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_machine_dispose
-- ----------------------------
DROP TABLE IF EXISTS `gmms_machine_dispose`;
CREATE TABLE `gmms_machine_dispose`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `machine_type_id` bigint(20) NULL DEFAULT NULL COMMENT '机器类型编号',
  `plc_font_type` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'plc字类型',
  `plc_font_value` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'plc字内容',
  `mes_font_type` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'mes字类型',
  `mes_font_value` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'mes字内容',
  `return_value` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '返回值',
  `logic` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '对应操作步骤',
  `remarks` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '备注',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `machine_type_id`(`machine_type_id`) USING BTREE,
  CONSTRAINT `gmms_machine_dispose_ibfk_1` FOREIGN KEY (`machine_type_id`) REFERENCES `gmms_machine_type` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB AUTO_INCREMENT = 101 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_machine_font
-- ----------------------------
DROP TABLE IF EXISTS `gmms_machine_font`;
CREATE TABLE `gmms_machine_font`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `machine_type_id` bigint(20) NULL DEFAULT NULL COMMENT '机器类型编号',
  `flag` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '位置标记',
  `font_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '字类型',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `machine_type_id`(`machine_type_id`) USING BTREE,
  CONSTRAINT `gmms_machine_font_ibfk_1` FOREIGN KEY (`machine_type_id`) REFERENCES `gmms_machine_type` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB AUTO_INCREMENT = 84 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_machine_message
-- ----------------------------
DROP TABLE IF EXISTS `gmms_machine_message`;
CREATE TABLE `gmms_machine_message`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `machine_id` bigint(20) NULL DEFAULT NULL COMMENT '机器编号',
  `message` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000' COMMENT '通讯内容',
  `mod_time` datetime NULL DEFAULT NULL COMMENT '修改时间',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `machine_id`(`machine_id`) USING BTREE,
  CONSTRAINT `gmms_machine_message_ibfk_1` FOREIGN KEY (`machine_id`) REFERENCES `gmms_machine` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB AUTO_INCREMENT = 76 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_machine_state
-- ----------------------------
DROP TABLE IF EXISTS `gmms_machine_state`;
CREATE TABLE `gmms_machine_state`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `device_id` bigint(50) NOT NULL,
  `tick` bigint(20) NOT NULL,
  `time_stamp` datetime NULL DEFAULT NULL,
  `var_name` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `var_value` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 6 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_machine_type
-- ----------------------------
DROP TABLE IF EXISTS `gmms_machine_type`;
CREATE TABLE `gmms_machine_type`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `type` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '机器类型名称',
  `type_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '机器类型名称',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 24 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_password
-- ----------------------------
DROP TABLE IF EXISTS `gmms_password`;
CREATE TABLE `gmms_password`  (
  `id` int(11) NOT NULL,
  `password` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '密码',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_pattern_task
-- ----------------------------
DROP TABLE IF EXISTS `gmms_pattern_task`;
CREATE TABLE `gmms_pattern_task`  (
  `id` bigint(20) NOT NULL,
  `rank` bigint(20) NULL DEFAULT NULL COMMENT '顺序',
  `raw_type` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '玻璃类型厚度',
  `raw_width` double NULL DEFAULT NULL COMMENT '宽度',
  `raw_height` double NULL DEFAULT NULL COMMENT '高度',
  `raw_thickness` double NULL DEFAULT NULL COMMENT '厚度',
  `work_state` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工作状态',
  `color` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '颜色',
  `content` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '没用',
  `task_id` bigint(20) NULL DEFAULT NULL COMMENT '没用',
  `raw_id` bigint(20) NULL DEFAULT NULL COMMENT '任务编号',
  `finsh_time` datetime NULL DEFAULT NULL COMMENT '完成时间',
  `flag` int(11) NOT NULL COMMENT '标记',
  `groups` bigint(20) NOT NULL COMMENT '线路',
  `Update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `task_id`(`task_id`) USING BTREE,
  INDEX `raw_id`(`raw_id`) USING BTREE,
  CONSTRAINT `gmms_pattern_task_ibfk_2` FOREIGN KEY (`raw_id`) REFERENCES `gmms_raw_file` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_pattern_task_buffer
-- ----------------------------
DROP TABLE IF EXISTS `gmms_pattern_task_buffer`;
CREATE TABLE `gmms_pattern_task_buffer`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `rank` bigint(20) NULL DEFAULT NULL,
  `raw_type` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `raw_width` double NULL DEFAULT NULL,
  `raw_height` double NULL DEFAULT NULL,
  `raw_thickness` double NULL DEFAULT NULL,
  `work_state` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `color` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `content` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `task_id` bigint(20) NULL DEFAULT NULL,
  `finsh_time` datetime NULL DEFAULT NULL,
  `flag` int(11) NOT NULL,
  `engineering_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `groups` bigint(20) NOT NULL,
  `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `task_id`(`task_id`) USING BTREE,
  INDEX `engineering_id`(`engineering_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 190667 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_pattern_task_interrupt
-- ----------------------------
DROP TABLE IF EXISTS `gmms_pattern_task_interrupt`;
CREATE TABLE `gmms_pattern_task_interrupt`  (
  `id` bigint(20) NOT NULL,
  `rank` bigint(20) NULL DEFAULT NULL COMMENT '顺序',
  `raw_type` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '玻璃类型厚度',
  `raw_width` double NULL DEFAULT NULL COMMENT '宽度',
  `raw_height` double NULL DEFAULT NULL COMMENT '高度',
  `raw_thickness` double NULL DEFAULT NULL COMMENT '厚度',
  `work_state` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工作状态',
  `color` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '颜色',
  `content` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '没用',
  `task_id` bigint(20) NULL DEFAULT NULL COMMENT '没用',
  `raw_id` bigint(20) NULL DEFAULT NULL COMMENT '任务编号',
  `finsh_time` datetime NULL DEFAULT NULL COMMENT '完成时间',
  `flag` int(11) NOT NULL COMMENT '标记',
  `groups` bigint(20) NOT NULL COMMENT '线路',
  `Update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `task_id`(`task_id`) USING BTREE,
  INDEX `raw_id`(`raw_id`) USING BTREE,
  CONSTRAINT `gmms_pattern_task_interrupt_ibfk_1` FOREIGN KEY (`raw_id`) REFERENCES `gmms_raw_file` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_peak_value
-- ----------------------------
DROP TABLE IF EXISTS `gmms_peak_value`;
CREATE TABLE `gmms_peak_value`  (
  `id` int(11) NOT NULL,
  `peak_value` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '峰值',
  `groups` int(11) NULL DEFAULT NULL COMMENT '线路',
  `type` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '类型',
  `work_procedure` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工序',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_preprocessing_glass
-- ----------------------------
DROP TABLE IF EXISTS `gmms_preprocessing_glass`;
CREATE TABLE `gmms_preprocessing_glass`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `glass_id` bigint(20) NOT NULL COMMENT '玻璃编号',
  `actual_length` double(20, 1) NULL DEFAULT NULL COMMENT '测量长度',
  `actual_width` double(20, 1) NULL DEFAULT NULL COMMENT '测量宽度',
  `length` double(10, 1) NOT NULL COMMENT '实际长度',
  `width` double(10, 1) NOT NULL COMMENT '实际宽度',
  `statu` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '状态',
  `color` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '颜色',
  `thickness` double(20, 0) NULL DEFAULT NULL COMMENT '厚度',
  `flag` bigint(20) NULL DEFAULT NULL COMMENT '标记',
  `groups` int(11) NULL DEFAULT NULL COMMENT '线路',
  `marking` int(11) NULL DEFAULT NULL COMMENT '打标模式',
  `minwidths` double(10, 1) NULL DEFAULT NULL,
  `tk` int(11) NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `glass_id`(`glass_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_print_log
-- ----------------------------
DROP TABLE IF EXISTS `gmms_print_log`;
CREATE TABLE `gmms_print_log`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `liuchengka` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `time_stamp` datetime NULL DEFAULT NULL,
  `piece_count` int(255) NULL DEFAULT NULL,
  `piece_area` double NULL DEFAULT NULL,
  `line` int(11) NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_prod_line_state
-- ----------------------------
DROP TABLE IF EXISTS `gmms_prod_line_state`;
CREATE TABLE `gmms_prod_line_state`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `line` int(11) NULL DEFAULT NULL COMMENT '线路',
  `state` tinyint(1) NULL DEFAULT NULL COMMENT '生产状态',
  `standalonestate` tinyint(1) NULL DEFAULT NULL COMMENT '单机状态',
  `gongwei_mode` int(11) NULL DEFAULT NULL COMMENT '切割工位模式:1单工位/2双工位',
  `lipianlong_mode` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '理片笼模式:1单片/2双片模式',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_rank
-- ----------------------------
DROP TABLE IF EXISTS `gmms_rank`;
CREATE TABLE `gmms_rank`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `glass_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '玻璃编号',
  `pieces` int(11) NULL DEFAULT NULL COMMENT '片数',
  `width` double NULL DEFAULT NULL COMMENT '宽度',
  `height` double NULL DEFAULT NULL COMMENT '高度',
  `thickness` double NULL DEFAULT NULL COMMENT '厚度',
  `color` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '颜色',
  `endtime` timestamp NULL DEFAULT NULL COMMENT '结束时间',
  `manufacturer` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '没用',
  `type` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '类型',
  `createtime` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间',
  `flag` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '标记',
  `shelf_rack_id` bigint(20) NULL DEFAULT NULL COMMENT '仓储架子',
  `batch_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '批次号',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `shelf_rank_id`(`shelf_rack_id`) USING BTREE,
  CONSTRAINT `gmms_rank_ibfk_1` FOREIGN KEY (`shelf_rack_id`) REFERENCES `gmms_shelf_rack` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB AUTO_INCREMENT = 5834 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_rank_2
-- ----------------------------
DROP TABLE IF EXISTS `gmms_rank_2`;
CREATE TABLE `gmms_rank_2`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `glass_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '玻璃编号',
  `pieces` int(11) NULL DEFAULT NULL COMMENT '片数',
  `width` double NULL DEFAULT NULL COMMENT '宽度',
  `height` double NULL DEFAULT NULL COMMENT '高度',
  `thickness` double NULL DEFAULT NULL COMMENT '厚度',
  `color` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '颜色',
  `endtime` timestamp NULL DEFAULT NULL COMMENT '结束时间',
  `manufacturer` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '没用',
  `type` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '类型',
  `createtime` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `flag` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '标记',
  `shelf_rack_id` bigint(20) NULL DEFAULT NULL COMMENT '仓储架子',
  `batch_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '批次号',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `shelf_rank_id`(`shelf_rack_id`) USING BTREE,
  CONSTRAINT `gmms_rank_2_ibfk_1` FOREIGN KEY (`shelf_rack_id`) REFERENCES `gmms_shelf_rack` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_raw_file
-- ----------------------------
DROP TABLE IF EXISTS `gmms_raw_file`;
CREATE TABLE `gmms_raw_file`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `file_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工程号',
  `file_url` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '没用',
  `state` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '状态',
  `operator` bigint(20) NULL DEFAULT NULL COMMENT '线路',
  `width` double NOT NULL COMMENT '宽度',
  `height` double NOT NULL COMMENT '高度',
  `thickness` double NOT NULL COMMENT '厚度',
  `count` int(11) NOT NULL COMMENT '数量',
  `create_time` datetime NULL DEFAULT NULL COMMENT '创建时间',
  `receive_time` datetime NULL DEFAULT NULL COMMENT '完成时间',
  `galssmeasure` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '0' COMMENT '小片面积',
  `patternmeasure` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '0' COMMENT '原片面积',
  `cutting_rate` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '0' COMMENT '切裁率',
  `Update_time` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `file_name`(`file_name`) USING BTREE,
  INDEX `create_time`(`create_time`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 10540 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_raw_file_2
-- ----------------------------
DROP TABLE IF EXISTS `gmms_raw_file_2`;
CREATE TABLE `gmms_raw_file_2`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `file_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工程号',
  `state` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '状态',
  `operator` bigint(20) NULL DEFAULT NULL COMMENT '线路',
  `create_time` datetime NULL DEFAULT NULL COMMENT '创建时间',
  `receive_time` datetime NULL DEFAULT NULL COMMENT '完成时间',
  `jiakong` int(11) NOT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 815 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_raw_package
-- ----------------------------
DROP TABLE IF EXISTS `gmms_raw_package`;
CREATE TABLE `gmms_raw_package`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `raw_type` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '玻璃类型',
  `raw_width` double NULL DEFAULT NULL COMMENT '宽度',
  `raw_height` double NULL DEFAULT NULL COMMENT '高度',
  `raw_thickness` double NULL DEFAULT NULL COMMENT '厚度',
  `state` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '状态',
  `color` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '颜色',
  `pieces` int(11) NULL DEFAULT NULL COMMENT '总数量',
  `left_pieces` int(11) NULL DEFAULT NULL COMMENT '剩余数量',
  `qrcode` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '物料编码',
  `create_time` datetime NULL DEFAULT NULL COMMENT '创建时间',
  `production_time` datetime NULL DEFAULT NULL COMMENT '生产日期',
  `batch_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '批次号',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 7264 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_shelf_rack
-- ----------------------------
DROP TABLE IF EXISTS `gmms_shelf_rack`;
CREATE TABLE `gmms_shelf_rack`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `number` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '架子编号',
  `state` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '状态',
  `raw_package_id1` bigint(20) NULL DEFAULT NULL COMMENT '包号编号',
  `create_time` datetime NULL DEFAULT NULL COMMENT '创建时间',
  `mod_time` datetime NULL DEFAULT NULL COMMENT '修改时间',
  `falg` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '禁用启用',
  `color_falg` int(11) NOT NULL COMMENT '翻片标记',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `raw_package_id1`(`raw_package_id1`) USING BTREE,
  CONSTRAINT `gmms_shelf_rack_ibfk_1` FOREIGN KEY (`raw_package_id1`) REFERENCES `gmms_raw_package` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB AUTO_INCREMENT = 72 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_shelf_rack_2
-- ----------------------------
DROP TABLE IF EXISTS `gmms_shelf_rack_2`;
CREATE TABLE `gmms_shelf_rack_2`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `number` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `state` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `processcard_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `create_time` datetime NULL DEFAULT NULL,
  `mod_time` datetime NULL DEFAULT NULL,
  `falg` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `orientation` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `sign` int(11) NOT NULL,
  `jiakong` int(11) NOT NULL,
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `raw_package_id1`(`processcard_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 72 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_shelf_task
-- ----------------------------
DROP TABLE IF EXISTS `gmms_shelf_task`;
CREATE TABLE `gmms_shelf_task`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `task_id` bigint(20) NULL DEFAULT 0 COMMENT '任务编号',
  `task_type` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '任务类型',
  `task_state` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工作状态',
  `shelf_rack_id` bigint(20) NOT NULL COMMENT '仓储架号',
  `load_rack` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '上片位编号',
  `file_id` bigint(20) NULL DEFAULT NULL COMMENT '没用',
  `groups` bigint(20) NULL DEFAULT NULL COMMENT '线路',
  `start_time` datetime NULL DEFAULT NULL COMMENT '创建时间',
  `finsh_time` datetime NULL DEFAULT NULL COMMENT '完成时间',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `file_id`(`file_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 95108 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_shelf_task_2
-- ----------------------------
DROP TABLE IF EXISTS `gmms_shelf_task_2`;
CREATE TABLE `gmms_shelf_task_2`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `task_type` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `task_state` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `shelf_rack_id` bigint(20) NULL DEFAULT NULL,
  `load_rack` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `groups` bigint(20) NULL DEFAULT NULL,
  `start_time` datetime NULL DEFAULT NULL,
  `finsh_time` datetime NULL DEFAULT NULL,
  `line` bigint(20) NOT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 130995 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_shelf_tasks2
-- ----------------------------
DROP TABLE IF EXISTS `gmms_shelf_tasks2`;
CREATE TABLE `gmms_shelf_tasks2`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `groups` bigint(20) NULL DEFAULT NULL COMMENT '线路',
  `tasktype` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '任务类型',
  `taskphase` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工作阶段',
  `taskstatus` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '任务状态',
  `starttime` datetime NULL DEFAULT NULL COMMENT '生成时间',
  `endtime` datetime NULL DEFAULT NULL COMMENT '结束时间',
  `updatetime` datetime NULL DEFAULT NULL COMMENT '修改时间',
  `beginaddress` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '起始地',
  `endaddress` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '目的地',
  `cardlocation` bigint(20) NULL DEFAULT NULL COMMENT '小车上的位置',
  `rackid` bigint(20) NULL DEFAULT NULL COMMENT '工位id',
  `endgroups` bigint(20) NULL DEFAULT NULL COMMENT '任务优先级(\r\n吊装移库400,\r\n中空旋转(旋转退库)300,\r\n中空移库200,\r\n移库100\r\n)',
  `isrepeal` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '正常' COMMENT '任务标记(撤销,正常,暂停)',
  `isout` bigint(20) NULL DEFAULT 0 COMMENT '是否下车,0上车1下车',
  `finshtype1` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '上车完成手动或自动',
  `finshtype2` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '下车完成手动或自动',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 71643 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_slicecage
-- ----------------------------
DROP TABLE IF EXISTS `gmms_slicecage`;
CREATE TABLE `gmms_slicecage`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `slicecage_rank` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '架号',
  `state` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '状态',
  `type_id` bigint(20) NOT NULL COMMENT '类型编号',
  `count` int(11) NOT NULL DEFAULT 0 COMMENT '数量',
  `flag` int(20) NOT NULL DEFAULT 0 COMMENT '0/1',
  `gourp` bigint(20) NULL DEFAULT NULL COMMENT '线路',
  `processcard_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '流程卡号',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `glass_id`(`type_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 161 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_slicecage_details
-- ----------------------------
DROP TABLE IF EXISTS `gmms_slicecage_details`;
CREATE TABLE `gmms_slicecage_details`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `processcard_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `groups` int(11) NULL DEFAULT NULL,
  `time` datetime NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 41 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_slicecage_house_full
-- ----------------------------
DROP TABLE IF EXISTS `gmms_slicecage_house_full`;
CREATE TABLE `gmms_slicecage_house_full`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `processcard_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `groups` bigint(20) NULL DEFAULT NULL,
  `time` datetime NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 3 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_slicecage_pattern
-- ----------------------------
DROP TABLE IF EXISTS `gmms_slicecage_pattern`;
CREATE TABLE `gmms_slicecage_pattern`  (
  `id` int(11) NOT NULL,
  `var` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '笼子状态(进出存)',
  `groups` int(11) NULL DEFAULT NULL COMMENT '线路',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_slicecage_tempering
-- ----------------------------
DROP TABLE IF EXISTS `gmms_slicecage_tempering`;
CREATE TABLE `gmms_slicecage_tempering`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `slicecage_rank` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '架号',
  `state` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '状态',
  `type_id` bigint(20) NOT NULL COMMENT '类型编号',
  `count` int(11) NOT NULL DEFAULT 0 COMMENT '数量',
  `flag` int(20) NOT NULL DEFAULT 0 COMMENT '0/1',
  `gourp` bigint(20) NULL DEFAULT NULL COMMENT '线路',
  `processcard_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '流程卡号',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `glass_id`(`type_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 81 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_task
-- ----------------------------
DROP TABLE IF EXISTS `gmms_task`;
CREATE TABLE `gmms_task`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `description` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `user_id` bigint(20) NOT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 6 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_tempere_layout
-- ----------------------------
DROP TABLE IF EXISTS `gmms_tempere_layout`;
CREATE TABLE `gmms_tempere_layout`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `work_id` int(11) NOT NULL COMMENT '所属钢化炉编号',
  `layout_number` int(11) NOT NULL COMMENT '炉号',
  `insert_time` datetime NOT NULL,
  `layout_rate` double NULL DEFAULT NULL COMMENT '装载率',
  `glass_number` int(11) NULL DEFAULT NULL COMMENT '从1 开始',
  `x` int(11) NULL DEFAULT NULL,
  `y` int(11) NULL DEFAULT NULL,
  `width` int(11) NULL DEFAULT NULL,
  `height` int(11) NULL DEFAULT NULL,
  `rotate` bit(1) NULL DEFAULT NULL,
  `row` int(11) NULL DEFAULT NULL,
  `column` int(11) NULL DEFAULT NULL,
  `glass_id` bigint(20) NULL DEFAULT NULL,
  `erp_glass_id` bigint(20) NULL DEFAULT NULL,
  `head_info` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '附加信息头 一般只有第一片玻璃有该字段',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 236561 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_timer
-- ----------------------------
DROP TABLE IF EXISTS `gmms_timer`;
CREATE TABLE `gmms_timer`  (
  `timer_name` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `time_stamp` datetime NULL DEFAULT NULL,
  `time_out` datetime NULL DEFAULT NULL,
  PRIMARY KEY (`timer_name`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_user
-- ----------------------------
DROP TABLE IF EXISTS `gmms_user`;
CREATE TABLE `gmms_user`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `login_name` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '登录名',
  `name` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '用户名',
  `password` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '密码',
  `salt` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '编译文',
  `roles` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '角色',
  `groups` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '线路',
  `register_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '修改时间',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `login_name`(`login_name`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 43 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_user_current
-- ----------------------------
DROP TABLE IF EXISTS `gmms_user_current`;
CREATE TABLE `gmms_user_current`  (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `gongyi` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工艺',
  `chanxian` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '产线',
  `banzu` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '班组',
  `intRemark` int(11) NULL DEFAULT NULL COMMENT '预留列,使用请标明用途',
  `strRemark` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '预留列,使用请标明用途',
  `isPaused` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '是否暂停设备(用于切换班组)',
  PRIMARY KEY (`Id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 12 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_user_details
-- ----------------------------
DROP TABLE IF EXISTS `gmms_user_details`;
CREATE TABLE `gmms_user_details`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `groups` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_var
-- ----------------------------
DROP TABLE IF EXISTS `gmms_var`;
CREATE TABLE `gmms_var`  (
  `id` int(11) NOT NULL,
  `varname` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '理片笼保存的类型',
  `value` int(11) NULL DEFAULT NULL COMMENT '保存的数据',
  `groups` int(11) NULL DEFAULT NULL COMMENT '线路',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_var_table
-- ----------------------------
DROP TABLE IF EXISTS `gmms_var_table`;
CREATE TABLE `gmms_var_table`  (
  `ID` int(11) NOT NULL,
  `var_name` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `var_value` decimal(10, 0) NULL DEFAULT 0,
  PRIMARY KEY (`ID`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_workmanship
-- ----------------------------
DROP TABLE IF EXISTS `gmms_workmanship`;
CREATE TABLE `gmms_workmanship`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `processcard_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '流程卡',
  `specifications` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '规格',
  `cuttingcount` int(11) NULL DEFAULT NULL COMMENT '切割',
  `edgingcount` int(11) NULL DEFAULT NULL COMMENT '磨边',
  `temperingcount` int(11) NULL DEFAULT NULL COMMENT '钢化',
  `hollowcount` int(11) NULL DEFAULT NULL COMMENT '中空',
  `processcard_count` int(11) NULL DEFAULT NULL COMMENT '总数',
  `starttime` datetime NULL DEFAULT NULL COMMENT '创建时间',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 120850 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for gmms_yuliao_slicecage
-- ----------------------------
DROP TABLE IF EXISTS `gmms_yuliao_slicecage`;
CREATE TABLE `gmms_yuliao_slicecage`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `slicecage_number` int(11) NULL DEFAULT NULL,
  `slicecage_group` int(11) NULL DEFAULT NULL,
  `slicecage_status` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `ban` int(11) NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 203 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gmms_yuliao_task
-- ----------------------------
DROP TABLE IF EXISTS `gmms_yuliao_task`;
CREATE TABLE `gmms_yuliao_task`  (
  `yuliao_id` bigint(20) NOT NULL,
  `pattern_task_id` bigint(11) NULL DEFAULT NULL,
  `state` int(255) NULL DEFAULT NULL,
  `lib_id` bigint(20) NULL DEFAULT NULL,
  `chanxian` int(11) NULL DEFAULT NULL,
  PRIMARY KEY (`yuliao_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for gongcheng_raw
-- ----------------------------
DROP TABLE IF EXISTS `gongcheng_raw`;
CREATE TABLE `gongcheng_raw`  (
  `gc_name` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `order_index` int(11) NOT NULL,
  `color` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `thickness` double(11, 0) NOT NULL,
  `width` int(11) NOT NULL,
  `height` int(11) NOT NULL,
  `count` int(11) NOT NULL,
  `state` int(11) NOT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 43 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for hn_user
-- ----------------------------
DROP TABLE IF EXISTS `hn_user`;
CREATE TABLE `hn_user`  (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `name` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `phone` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `idcard` varchar(18) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `update_time` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `add_time` bigint(13) NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 49702 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for io_log
-- ----------------------------
DROP TABLE IF EXISTS `io_log`;
CREATE TABLE `io_log`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `device_id` int(11) NULL DEFAULT NULL,
  `begin_time` datetime NULL DEFAULT NULL,
  `end_time` datetime NULL DEFAULT NULL,
  `read_message` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `send_message` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 479352 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for liuchengka_output
-- ----------------------------
DROP TABLE IF EXISTS `liuchengka_output`;
CREATE TABLE `liuchengka_output`  (
  `liuchengka` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `guige` int(11) NULL DEFAULT NULL,
  `state` int(11) NULL DEFAULT NULL,
  `gongcheng` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `maxxuhao` int(11) NULL DEFAULT NULL,
  `currentxuhao` int(11) NULL DEFAULT NULL,
  `width` double NULL DEFAULT NULL,
  `height` double NULL DEFAULT NULL,
  `suo` int(11) NULL DEFAULT NULL,
  PRIMARY KEY (`liuchengka`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for log_debug
-- ----------------------------
DROP TABLE IF EXISTS `log_debug`;
CREATE TABLE `log_debug`  (
  `id` bigint(20) NOT NULL,
  `txt` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL,
  `dt` datetime NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for memory_var_table
-- ----------------------------
DROP TABLE IF EXISTS `memory_var_table`;
CREATE TABLE `memory_var_table`  (
  `var_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `update_time` datetime NULL DEFAULT NULL,
  `var_value` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL,
  PRIMARY KEY (`var_name`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT STORAGE MEMORY;
 
-- ----------------------------
-- Table structure for names5
-- ----------------------------
DROP TABLE IF EXISTS `names5`;
CREATE TABLE `names5`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name1` datetime NULL DEFAULT NULL,
  `name2` datetime NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 638603 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for namess
-- ----------------------------
DROP TABLE IF EXISTS `namess`;
CREATE TABLE `namess`  (
  `id` int(11) NOT NULL,
  `name1` int(11) NULL DEFAULT NULL COMMENT '出片条件数量',
  `name2` int(11) NULL DEFAULT NULL,
  `groups` int(11) NULL DEFAULT NULL COMMENT '线路',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for run_view
-- ----------------------------
DROP TABLE IF EXISTS `run_view`;
CREATE TABLE `run_view`  (
  `ID` int(11) NOT NULL,
  `t` datetime NULL DEFAULT NULL,
  `tms` int(255) NULL DEFAULT NULL,
  `msg` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `name` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  PRIMARY KEY (`ID`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for supplement_liuchengkafua
-- ----------------------------
DROP TABLE IF EXISTS `supplement_liuchengkafua`;
CREATE TABLE `supplement_liuchengkafua`  (
  `id` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
  `liuchengkahao` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `xuhao` int(11) NOT NULL,
  `luojiashunxu` int(11) NOT NULL,
  `loucengbianhao` varchar(40) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `danpianmingcheng` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `pianbiaoji` varchar(5) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `gongyiliucheng` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `mobiandengji` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `qiepian` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `mobianleixing` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `ganghua` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `jiajiao` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `zhongkong` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `baozhuang` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `mobianbiaoji` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `kuan` decimal(7, 2) NOT NULL,
  `gao` decimal(7, 2) NOT NULL,
  `shuliang` decimal(9, 6) NOT NULL,
  `mianji` decimal(12, 6) NULL DEFAULT NULL,
  `xingzhuang` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `beizhu` varchar(600) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `gyqrxh` int(11) NULL DEFAULT NULL,
  `houdu` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `yanse` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `qiangdu` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `weizhi` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `lowe` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `pbzt` int(11) NULL DEFAULT NULL,
  `bpsl` int(11) NULL DEFAULT NULL,
  `jianlitime` datetime NULL DEFAULT NULL,
  `xiugaitime` datetime NULL DEFAULT NULL,
  `yiyouhuashuliang` decimal(9, 6) NULL DEFAULT 0.000000,
  `chanpinbianhao` varchar(16) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `chanpinmingcheng` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `kucunshuliang` int(11) NULL DEFAULT NULL,
  `danjuzhuangtai` int(11) NULL DEFAULT NULL,
  `yirushuliang` int(11) NULL DEFAULT NULL,
  `bupianbianhao` varchar(15) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `tianFenID` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `yipian` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `wanmian` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `dakong` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `waque` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `qiejiao` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `zixu` int(11) NULL DEFAULT NULL,
  `ordrID2` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `jiahao` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '架号',
  `state` varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '未领取',
  `gongcheng_id` bigint(20) NULL DEFAULT NULL,
  `xiaoshoudanhao` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '销售单号',
  `posungongxu` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '破损工序',
  `liuchengkahaos` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for supplement_liuchengkazhu
-- ----------------------------
DROP TABLE IF EXISTS `supplement_liuchengkazhu`;
CREATE TABLE `supplement_liuchengkazhu`  (
  `id` bigint(20) NOT NULL,
  `xiaoshoudanhao` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `shengchandingdanhao` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `liuchengkahao` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `kehubianma` varchar(15) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `kehumingcheng` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `xiangmumingcheng` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `chanpinbianhao` varchar(16) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `chanpinmingcheng` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `pianbiaoji` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `fenjiayuangonghao` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `fenjiayuan` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `fenjiashijian` datetime NOT NULL,
  `gyqrxh` int(11) NULL DEFAULT NULL,
  `beizhu` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `baozhuangfangshi` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `banjin` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `danpian` varchar(255) CHARACTER SET utf32 COLLATE utf32_general_ci NULL DEFAULT NULL,
  `jiangewu` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `kuaisuchaxun` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `pbzt` int(11) NULL DEFAULT NULL,
  `jianlitime` datetime NULL DEFAULT NULL,
  `xiugaitime` datetime NULL DEFAULT NULL,
  `youhuazhuangtai` int(11) NULL DEFAULT NULL,
  `jiagongyaoqiu` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `gylc` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `qiejiao` int(11) NULL DEFAULT NULL,
  `yipian` int(11) NULL DEFAULT NULL,
  `tianFenID` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `shengchanID` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `projectNo` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工程编号',
  `projectID` int(11) NULL DEFAULT NULL COMMENT '工程ID',
  `No` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `dyzt` int(11) NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = COMPACT;
 
-- ----------------------------
-- Table structure for y_Len_CeLiang
-- ----------------------------
DROP TABLE IF EXISTS `y_Len_CeLiang`;
CREATE TABLE `y_Len_CeLiang`  (
  `rank` int(11) NULL DEFAULT NULL COMMENT '序号',
  `Fx_Content` varchar(2000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '冷加工测量台执行内容',
  `minpattern` varchar(2000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '第几张版图',
  `Mode_State` int(255) NULL DEFAULT NULL COMMENT '0,关闭  1 选择    只能有一个是1  多个1时默认为第一个',
  `groups` int(11) NULL DEFAULT NULL COMMENT '线路'
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for y_mode_type
-- ----------------------------
DROP TABLE IF EXISTS `y_mode_type`;
CREATE TABLE `y_mode_type`  (
  `groups` bigint(20) NULL DEFAULT NULL COMMENT '线路',
  `mode_type` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '模式类型',
  `machine_type` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '设备类型',
  `number` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '编号'
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- Table structure for y_pro_timer
-- ----------------------------
DROP TABLE IF EXISTS `y_pro_timer`;
CREATE TABLE `y_pro_timer`  (
  `id` int(11) NOT NULL,
  `pro_timer` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '定时器名称',
  `is_enable` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '是否开启',
  `is_run` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '是否在运行   runing',
  `run_begin_time` datetime NULL DEFAULT NULL COMMENT '上次运行开始时间',
  `run_end_time` datetime NULL DEFAULT NULL COMMENT '上次运行结束时间',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
 
-- ----------------------------
-- View structure for chanliang
-- ----------------------------
DROP VIEW IF EXISTS `chanliang`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `chanliang` AS select sum(`gmms_glass_log`.`area`) AS `area`,`gmms_glass_log`.`work_name` AS `work_name`,`gmms_glass_log`.`line` AS `line`,count(0) AS `total`,count((case when (`gmms_glass_log`.`status` = 100) then 1 else NULL end)) AS `ok_count`,count((case when (`gmms_glass_log`.`status` = 101) then 1 else NULL end)) AS `broken_count`,sum((case when (`gmms_glass_log`.`status` = 100) then `gmms_glass_log`.`area` else 0 end)) AS `ok_area`,sum((case when (`gmms_glass_log`.`status` = 101) then `gmms_glass_log`.`area` else 0 end)) AS `broken_area` from `gmms_glass_log` group by `gmms_glass_log`.`work_name`,`gmms_glass_log`.`line`;
 
-- ----------------------------
-- View structure for gmms_dongzuo_table
-- ----------------------------
DROP VIEW IF EXISTS `gmms_dongzuo_table`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `gmms_dongzuo_table` AS select `a`.`id` AS `id`,`a`.`id` AS `number`,`b`.`mode` AS `mode`,`a`.`note` AS `note`,`a`.`da_biao_mo_ban` AS `da_biao_mo_ban`,`b`.`qing_xi_hou_zhua` AS `qing_xi_hou_zhua`,`b`.`gang_qian_zhua` AS `gang_qian_zhua`,`b`.`gang_qian_bu_zhuan` AS `gang_qian_bu_zhuan`,`b`.`gang_qian_zhuan` AS `gang_qian_zhuan`,`b`.`gang_hou_bu_zhuan` AS `gang_hou_bu_zhuan`,`b`.`gang_hou_zhuan` AS `gang_hou_zhuan`,`b`.`gang_hou_zhua` AS `gang_hou_zhua`,`b`.`zhong_kong_fang` AS `zhong_kong_fang` from (`gmms_biao_table` `a` left join `gmms_dongzuo` `b` on((`a`.`dongzuo_id` = `b`.`number`)));
 
-- ----------------------------
-- View structure for horizontal
-- ----------------------------
DROP VIEW IF EXISTS `horizontal`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `horizontal` AS select `kgt`.`processcard_id` AS `processcard_id`,count(0) AS `count1` from ((`gmms_raw_file` `krf` left join `gmms_galss_task` `kgt` on(((`krf`.`file_name` = `kgt`.`engineering_id`) and (`krf`.`state` = '已领取') and (`krf`.`operator` = 1)))) left join `gmms_horizontal` `kghl` on((`kgt`.`slicecage_rank` = `kghl`.`id`))) where ((`kgt`.`work_state` = '已进库') and (`kgt`.`work_procedure` = '理片') and (`kghl`.`flag` = 0)) group by `kgt`.`processcard_id`;
 
-- ----------------------------
-- View structure for online_glass_view
-- ----------------------------
DROP VIEW IF EXISTS `online_glass_view`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `online_glass_view` AS select `gmms_galss_task`.`id` AS `id`,`gmms_galss_task`.`edg_width` AS `edg_width`,`gmms_galss_task`.`edg_height` AS `edg_height`,`gmms_galss_task`.`thickness` AS `thickness`,`gmms_galss_task`.`color` AS `color`,`gmms_galss_task`.`processcard_id` AS `processcard_id`,`gmms_galss_task`.`work_procedure` AS `work_procedure`,`gmms_galss_task`.`work_state` AS `work_state`,`gmms_galss_task`.`out_rank` AS `out_rank`,`gmms_galss_task`.`rank` AS `rank`,`gmms_galss_task`.`stop_position` AS `stop_position` from `gmms_galss_task` where ((((`gmms_galss_task`.`work_procedure` = '理片') and (`gmms_galss_task`.`work_state` = '已出库')) or (`gmms_galss_task`.`work_procedure` = '复合') or (`gmms_galss_task`.`work_procedure` = '磨边') or ((`gmms_galss_task`.`work_procedure` = '下片') and (`gmms_galss_task`.`work_state` <> '已完成'))) and (`gmms_galss_task`.`work_state` <> '破损')) order by `gmms_galss_task`.`out_rank` desc;
 
-- ----------------------------
-- View structure for processcard
-- ----------------------------
DROP VIEW IF EXISTS `processcard`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `processcard` AS select `rf`.`file_name` AS `工程号`,`rf`.`operator` AS `线路`,`gt`.`processcard_id` AS `流程卡`,`gt`.`drop_frame` AS `架号`,count(0) AS `总数`,count(0) AS `切割数`,(select count(0) from `gmms_galss_task` where ((`gmms_galss_task`.`processcard_id` = `gt`.`processcard_id`) and (`gmms_galss_task`.`work_state` = '已完成') and (`gmms_galss_task`.`work_procedure` = '下片'))) AS `下架数`,if((`rf`.`operator` = 1),ifnull(`gr1`.`count1`,0),ifnull(`gr2`.`count2`,0)) AS `库内数` from (((`gmms_raw_file` `rf` left join `gmms_galss_task` `gt` on(((`rf`.`file_name` = `gt`.`engineering_id`) and (`rf`.`state` = '已领取')))) left join `horizontal` `gr1` on((`gt`.`processcard_id` = `gr1`.`processcard_id`))) left join `slicecage` `gr2` on((`gt`.`processcard_id` = `gr2`.`processcard_id`))) where (`gt`.`engineering_id` is not null) group by `gt`.`processcard_id`;
 
-- ----------------------------
-- View structure for processcard1
-- ----------------------------
DROP VIEW IF EXISTS `processcard1`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `processcard1` AS select `gmms_galss_task`.`processcard_id` AS `流程卡`,`gmms_galss_task`.`engineering_id` AS `工程号`,count(`gmms_galss_task`.`id`) AS `总数`,count((case when (`gmms_galss_task`.`work_procedure_number` >= 100) then 1 end)) AS `切割数`,count((case when (`gmms_galss_task`.`work_procedure_number` = 500) then 1 end)) AS `下架数`,count((case when ((`gmms_galss_task`.`slicecage_rank` is not null) and (`gmms_galss_task`.`work_state` = '已进库') and (`gmms_galss_task`.`slicecage_rank` > 0)) then 1 end)) AS `库内数`,`gmms_galss_task`.`drop_frame` AS `架号` from (`gmms_galss_task` join `gmms_horizontal` on((`gmms_galss_task`.`slicecage_rank` = `gmms_horizontal`.`id`))) group by `gmms_galss_task`.`processcard_id`,`gmms_galss_task`.`engineering_id`;
 
-- ----------------------------
-- View structure for processcard_ex
-- ----------------------------
DROP VIEW IF EXISTS `processcard_ex`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `processcard_ex` AS select `a`.`流程卡` AS `流程卡`,`a`.`工程号` AS `工程号`,`a`.`架号` AS `架号`,`a`.`总数` AS `总数`,`a`.`切割数` AS `切割数`,`a`.`下架数` AS `下架数`,`a`.`库内数` AS `库内数`,`b`.`id` AS `下片位置` from (`processcard` `a` left join `gmms_drop_frame` `b` on((`a`.`流程卡` = `b`.`processcard_id`)));
 
-- ----------------------------
-- View structure for processcard_ex1
-- ----------------------------
DROP VIEW IF EXISTS `processcard_ex1`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `processcard_ex1` AS select `a`.`流程卡` AS `流程卡`,`a`.`工程号` AS `工程号`,`a`.`架号` AS `架号`,`a`.`总数` AS `总数`,`a`.`切割数` AS `切割数`,`a`.`下架数` AS `下架数`,`a`.`库内数` AS `库内数`,`b`.`id` AS `下片位置` from (`processcard1` `a` left join `gmms_drop_frame` `b` on((`a`.`流程卡` = `b`.`processcard_id`)));
 
-- ----------------------------
-- View structure for rf_qiecailv_lck
-- ----------------------------
DROP VIEW IF EXISTS `rf_qiecailv_lck`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `rf_qiecailv_lck` AS select NULL AS `序号`,`g`.`engineering_id` AS `工程号`,`g`.`processcard_id` AS `流程卡号`,`g`.`thickness` AS `厚度`,`g`.`color` AS `膜系`,round((sum((`g`.`width` * `g`.`height`)) / 1000000),6) AS `面积`,count(`g`.`id`) AS `数量`,`f`.`cutting_rate` AS `切裁率`,`g`.`start_time` AS `开始时间` from (`gmms_galss_task_buffer` `g` left join `gmms_raw_file` `f` on((`g`.`engineering_id` = `f`.`file_name`))) where (`f`.`create_time` > (curdate() - interval 1 year)) group by `g`.`processcard_id` order by `g`.`engineering_id` desc,`g`.`processcard_id`;
 
-- ----------------------------
-- View structure for select
-- ----------------------------
DROP VIEW IF EXISTS `select`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `select` AS select `gmms_galss_task`.`processcard_id` AS `流程卡`,`gmms_galss_task`.`engineering_id` AS `工程号`,count(`gmms_galss_task`.`id`) AS `总数`,count((case when (`gmms_galss_task`.`work_procedure_number` >= 100) then 1 end)) AS `切割数`,count((case when (`gmms_galss_task`.`work_procedure_number` = 500) then 1 end)) AS `下架数`,count((case when ((`gmms_galss_task`.`slicecage_rank` is not null) and (`gmms_galss_task`.`work_state` = '已进库')) then 1 end)) AS `库内数`,`gmms_galss_task`.`drop_frame` AS `架号` from `gmms_galss_task` group by `gmms_galss_task`.`processcard_id`,`gmms_galss_task`.`engineering_id`;
 
-- ----------------------------
-- View structure for slicecage
-- ----------------------------
DROP VIEW IF EXISTS `slicecage`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `slicecage` AS select `kgt`.`processcard_id` AS `processcard_id`,count(0) AS `count2` from ((`gmms_raw_file` `krf` left join `gmms_galss_task` `kgt` on(((`krf`.`file_name` = `kgt`.`engineering_id`) and (`krf`.`state` = '已领取') and ((`krf`.`operator` = 2) or (`krf`.`operator` = 3))))) left join `gmms_slicecage` `kgs` on((`kgt`.`slicecage_rank` = `kgs`.`slicecage_rank`))) where ((`kgt`.`work_state` = '已进库') and (`kgt`.`work_procedure` = '理片') and (`kgs`.`gourp` = `krf`.`operator`) and (`kgs`.`flag` = 0)) group by `kgt`.`processcard_id`;
 
-- ----------------------------
-- View structure for slicecage_content
-- ----------------------------
DROP VIEW IF EXISTS `slicecage_content`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `slicecage_content` AS select `b`.`id` AS `格子`,`b`.`state` AS `格子状态`,`b`.`type_id` AS `玻璃类型ID`,`a`.`processcard_id` AS `流程卡`,`a`.`drop_frame` AS `架号`,`a`.`width` AS `宽度`,`a`.`height` AS `高度`,`a`.`work_procedure` AS `工序`,`a`.`work_state` AS `工序状态` from (`gmms_galss_task` `a` join `gmms_slicecage` `b` on((`a`.`slicecage_rank` = `b`.`id`))) order by `b`.`id`,`a`.`rank`;
 
-- ----------------------------
-- View structure for slicecage_view
-- ----------------------------
DROP VIEW IF EXISTS `slicecage_view`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `slicecage_view` AS select `b`.`slicecage_rank` AS `格子`,`b`.`state` AS `格子状态`,`b`.`type_id` AS `玻璃类型ID`,`b`.`count` AS `count`,`a`.`processcard_id` AS `流程卡`,`a`.`drop_frame` AS `架号`,`a`.`width` AS `宽度`,`a`.`height` AS `高度`,`a`.`work_procedure` AS `工序`,`a`.`work_state` AS `工序状态`,`b`.`gourp` AS `groups` from (`gmms_galss_task` `a` join `gmms_slicecage` `b` on(((`a`.`slicecage_rank` = `b`.`slicecage_rank`) and (`a`.`processcard_id` = `b`.`processcard_id`)))) order by `b`.`id`,`a`.`rank`;
 
-- ----------------------------
-- View structure for spq111
-- ----------------------------
DROP VIEW IF EXISTS `spq111`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `spq111` AS select `dr`.`id` AS `id`,`dr`.`stops` AS `stops`,`dr`.`processcard_id` AS `processcard_id`,`dr`.`state` AS `state`,(select count(0) from `gmms_galss_task_2` where (`gmms_galss_task_2`.`processcard_id` = `dr`.`processcard_id`)) AS `zongshu`,(select count(0) from `gmms_galss_task_2` where ((`gmms_galss_task_2`.`processcard_id` = `dr`.`processcard_id`) and (`gmms_galss_task_2`.`work_state` = '破损'))) AS `posunshu`,(select count(0) from `gmms_galss_task_2` where ((`gmms_galss_task_2`.`processcard_id` = `dr`.`processcard_id`) and (`gmms_galss_task_2`.`work_state` <> '未优化'))) AS `yiyouhua`,(select count(0) from `gmms_galss_task_2` where ((`gmms_galss_task_2`.`processcard_id` = `dr`.`processcard_id`) and (`gmms_galss_task_2`.`work_procedure` <> '钢化上片') and (`gmms_galss_task_2`.`work_state` <> '破损'))) AS `wanchengshu`,((select count(0) from `gmms_galss_task_2` where (`gmms_galss_task_2`.`processcard_id` = `dr`.`processcard_id`)) - (select count(0) from `gmms_galss_task_2` where ((`gmms_galss_task_2`.`processcard_id` = `dr`.`processcard_id`) and (`gmms_galss_task_2`.`work_procedure` <> '钢化上片') and (`gmms_galss_task_2`.`work_state` <> '破损')))) AS `shengyushu`,`dr`.`surplus_count` AS `shangpianshengyushu`,`dr`.`noodles` AS `noodles`,`dr`.`flag` AS `flag`,`dr`.`groups` AS `groups`,(select `gmms_liuchengka`.`Occupied` from `gmms_liuchengka` where (`gmms_liuchengka`.`liuchengka` = `dr`.`processcard_id`)) AS `weizhi` from `gmms_drop_frame_2` `dr`;
 
-- ----------------------------
-- View structure for tempereworkgalsss1
-- ----------------------------
DROP VIEW IF EXISTS `tempereworkgalsss1`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `tempereworkgalsss1` AS select `temperelayout`.`id` AS `id`,`temperelayout`.`work_id` AS `work_id`,`temperelayout`.`layout_number` AS `layout_number`,`temperelayout`.`insert_time` AS `insert_time`,`temperelayout`.`layout_rate` AS `layout_rate`,`temperelayout`.`glass_number` AS `glass_number`,`temperelayout`.`x` AS `x`,`temperelayout`.`y` AS `y`,`temperelayout`.`width` AS `width`,`temperelayout`.`height` AS `height`,`temperelayout`.`rotate` AS `rotate`,`temperelayout`.`row` AS `row`,`temperelayout`.`column` AS `column`,`temperelayout`.`glass_id` AS `glass_id`,`temperelayout`.`erp_glass_id` AS `erp_glass_id`,`temperelayout`.`head_info` AS `head_info`,`glasstask`.`work_procedure` AS `work_procedure`,`glasstask`.`work_state` AS `work_state` from (`gmms_galss_task_2` `glasstask` join `gmms_tempere_layout` `temperelayout` on((`glasstask`.`id` = `temperelayout`.`glass_id`))) where (`glasstask`.`furnace` = (select `gmms_galss_task_2`.`furnace` from `gmms_galss_task_2` where ((`gmms_galss_task_2`.`work_state` = '已完成') and (`gmms_galss_task_2`.`work_procedure` = '钢化') and (`gmms_galss_task_2`.`groups` = 1)) order by `gmms_galss_task_2`.`furnace` limit 1));
 
-- ----------------------------
-- View structure for tempereworkgalsss2
-- ----------------------------
DROP VIEW IF EXISTS `tempereworkgalsss2`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `tempereworkgalsss2` AS select `temperelayout`.`id` AS `id`,`temperelayout`.`work_id` AS `work_id`,`temperelayout`.`layout_number` AS `layout_number`,`temperelayout`.`insert_time` AS `insert_time`,`temperelayout`.`layout_rate` AS `layout_rate`,`temperelayout`.`glass_number` AS `glass_number`,`temperelayout`.`x` AS `x`,`temperelayout`.`y` AS `y`,`temperelayout`.`width` AS `width`,`temperelayout`.`height` AS `height`,`temperelayout`.`rotate` AS `rotate`,`temperelayout`.`row` AS `row`,`temperelayout`.`column` AS `column`,`temperelayout`.`glass_id` AS `glass_id`,`temperelayout`.`erp_glass_id` AS `erp_glass_id`,`temperelayout`.`head_info` AS `head_info`,`glasstask`.`work_procedure` AS `work_procedure`,`glasstask`.`work_state` AS `work_state` from (`gmms_galss_task_2` `glasstask` join `gmms_tempere_layout` `temperelayout` on((`glasstask`.`id` = `temperelayout`.`glass_id`))) where (`glasstask`.`furnace` = (select `gmms_galss_task_2`.`furnace` from `gmms_galss_task_2` where (((`gmms_galss_task_2`.`work_state` = '已完成') or (`gmms_galss_task_2`.`work_state` = '正在工作')) and (`gmms_galss_task_2`.`work_procedure` = '钢化') and (`gmms_galss_task_2`.`groups` = 2)) order by `gmms_galss_task_2`.`furnace` limit 1));
 
-- ----------------------------
-- View structure for tempere_task_glass
-- ----------------------------
DROP VIEW IF EXISTS `tempere_task_glass`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `tempere_task_glass` AS select `a`.`id` AS `id`,`a`.`processcard_id` AS `processcard`,`b`.`stops` AS `position`,`b`.`flag` AS `front`,`a`.`width` AS `width`,`a`.`height` AS `height`,`a`.`stop_rank` AS `glass_idx`,`a`.`thickness` AS `thickness`,`a`.`color` AS `color`,`b`.`groups` AS `work_id`,0 AS `layout_mode`,(select `gmms_galss_task_buffer`.`w` from `gmms_galss_task_buffer` where (`gmms_galss_task_buffer`.`id` = `a`.`id`)) AS `w`,(select `gmms_galss_task_buffer`.`h` from `gmms_galss_task_buffer` where (`gmms_galss_task_buffer`.`id` = `a`.`id`)) AS `h` from (`gmms_galss_task_2` `a` join `gmms_drop_frame_2` `b` on((`a`.`processcard_id` = `b`.`processcard_id`))) where ((`a`.`work_procedure` = '钢化上片') and (`a`.`work_state` = '未优化') and (`b`.`flag` = 1));
 
-- ----------------------------
-- View structure for tempere_task_glass_copy1
-- ----------------------------
DROP VIEW IF EXISTS `tempere_task_glass_copy1`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `tempere_task_glass_copy1` AS select `a`.`id` AS `id`,`a`.`processcard_id` AS `processcard`,`b`.`stops` AS `position`,`b`.`flag` AS `front`,`c`.`w` AS `width`,`c`.`h` AS `height`,`a`.`stop_rank` AS `glass_idx`,`a`.`thickness` AS `thickness`,`a`.`color` AS `color`,`b`.`groups` AS `work_id`,0 AS `layout_mode` from ((`gmms_galss_task_2` `a` join `gmms_drop_frame_2` `b` on((`a`.`processcard_id` = `b`.`processcard_id`))) join `gmms_galss_task_buffer` `c` on((`a`.`id` = `c`.`id`))) where ((`a`.`work_procedure` = '钢化上片') and (`a`.`work_state` = '未优化') and (`b`.`flag` = 1));
 
-- ----------------------------
-- View structure for tempere_task_glass_copy2
-- ----------------------------
DROP VIEW IF EXISTS `tempere_task_glass_copy2`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `tempere_task_glass_copy2` AS select `a`.`id` AS `id`,`a`.`processcard_id` AS `processcard`,`b`.`stops` AS `position`,`b`.`flag` AS `front`,`a`.`width` AS `width`,`a`.`height` AS `height`,`a`.`stop_rank` AS `glass_idx`,`a`.`thickness` AS `thickness`,`a`.`color` AS `color`,`b`.`groups` AS `work_id`,0 AS `layout_mode`,`a`.`height` AS `h`,`a`.`width` AS `w` from (`gmms_galss_task_2` `a` join `gmms_drop_frame_2` `b` on((`a`.`processcard_id` = `b`.`processcard_id`))) where ((`a`.`work_procedure` = '钢化上片') and (`a`.`work_state` = '未优化') and (`b`.`flag` = 1));
 
-- ----------------------------
-- View structure for tempere_task_glass_copy3
-- ----------------------------
DROP VIEW IF EXISTS `tempere_task_glass_copy3`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `tempere_task_glass_copy3` AS select `a`.`id` AS `id`,`a`.`processcard_id` AS `processcard`,`b`.`stops` AS `position`,`b`.`flag` AS `front`,`c`.`w` AS `width`,`c`.`h` AS `height`,`a`.`stop_rank` AS `glass_idx`,`a`.`thickness` AS `thickness`,`a`.`color` AS `color`,`b`.`groups` AS `work_id`,0 AS `layout_mode`,`c`.`h` AS `h`,`c`.`w` AS `w` from ((`gmms_galss_task_2` `a` join `gmms_drop_frame_2` `b` on((`a`.`processcard_id` = `b`.`processcard_id`))) join `gmms_galss_task_buffer` `c` on((`a`.`id` = `c`.`id`))) where ((`a`.`work_procedure` = '钢化上片') and (`a`.`work_state` = '未优化') and (`b`.`flag` = 1));
 
-- ----------------------------
-- View structure for tempere_task_glass_copy4
-- ----------------------------
DROP VIEW IF EXISTS `tempere_task_glass_copy4`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `tempere_task_glass_copy4` AS select `a`.`id` AS `id`,`a`.`processcard_id` AS `processcard`,`b`.`stops` AS `position`,`b`.`flag` AS `front`,`a`.`width` AS `width`,`a`.`height` AS `height`,`a`.`stop_rank` AS `glass_idx`,`a`.`thickness` AS `thickness`,`a`.`color` AS `color`,`b`.`groups` AS `work_id`,0 AS `layout_mode`,`a`.`height` AS `w`,`a`.`width` AS `h` from (`gmms_galss_task_2` `a` join `gmms_drop_frame_2` `b` on((`a`.`processcard_id` = `b`.`processcard_id`))) where ((`a`.`work_procedure` = '钢化上片') and (`a`.`work_state` = '未优化') and (`b`.`flag` = 1));
 
-- ----------------------------
-- View structure for v_cc_cpinfo
-- ----------------------------
DROP VIEW IF EXISTS `v_cc_cpinfo`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `v_cc_cpinfo` AS select NULL AS `序号`,`lk`.`parent_liuchengka` AS `中空流程卡号`,NULL AS `总数/库内数`,(select group_concat(`gmms_liuchengka`.`liuchengka` separator ',') from `gmms_liuchengka` where ((`gmms_liuchengka`.`parent_liuchengka` = `lk`.`parent_liuchengka`) and `gmms_liuchengka`.`liuchengka` in (select `gmms_shelf_rack_2`.`processcard_id` from `gmms_shelf_rack_2`))) AS `库内的流程卡`,NULL AS `未到位流程卡`,(select group_concat(`gmms_liuchengka`.`liuchengka` separator ',') from `gmms_liuchengka` where (`gmms_liuchengka`.`parent_liuchengka` = `lk`.`parent_liuchengka`)) AS `包含的流程卡` from (`gmms_liuchengka` `lk` left join `gmms_shelf_rack_2` `sr` on((`lk`.`liuchengka` = `sr`.`processcard_id`))) where (`sr`.`processcard_id` is not null) group by `lk`.`parent_liuchengka`;
 
-- ----------------------------
-- View structure for v_cc_liaojia
-- ----------------------------
DROP VIEW IF EXISTS `v_cc_liaojia`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `v_cc_liaojia` AS select `sr`.`id` AS `id`,`sr`.`state` AS `state`,`sr`.`processcard_id` AS `processcard_id`,`sr`.`orientation` AS `orientation`,`sr`.`falg` AS `falg` from `gmms_shelf_rack_2` `sr` where ((`sr`.`id` < 42) and (not(`sr`.`id` in (select `gmms_drop_frame_5`.`rank` from `gmms_drop_frame_5` where ((`gmms_drop_frame_5`.`groups_` <> 100) and (`gmms_drop_frame_5`.`rank` is not null))))));
 
-- ----------------------------
-- View structure for v_cipo
-- ----------------------------
DROP VIEW IF EXISTS `v_cipo`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `v_cipo` AS select NULL AS `xh`,`ep`.`glass_id` AS `glass_id`,`ep`.`processcard_id` AS `processcard_id`,`gtb`.`edg_width` AS `width`,`gtb`.`edg_height` AS `height`,concat(`gtb`.`thickness`,'  ',`gtb`.`color`) AS `moxi`,1 AS `shuliang`,ifnull(`gs`.`work_procedure`,' ') AS `work_procedure`,`ep`.`pierced_type` AS `pierced_type`,`ep`.`pierced_cause` AS `pierced_cause`,`ep`.`process` AS `process`,`ep`.`team_name` AS `team_name`,`ep`.`create_time` AS `create_time`,`ep`.`is_report` AS `is_report` from ((`e_pierceds` `ep` left join `gmms_galss_task_2` `gs` on((`ep`.`glass_id` = `gs`.`id`))) left join `gmms_galss_task_buffer` `gtb` on((`gtb`.`id` = `ep`.`glass_id`)));
 
-- ----------------------------
-- View structure for v_completedtasks
-- ----------------------------
DROP VIEW IF EXISTS `v_completedtasks`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `v_completedtasks` AS select `gmms_raw_file`.`id` AS `id`,`gmms_raw_file`.`file_name` AS `file_name`,`gmms_raw_file`.`file_url` AS `file_url`,`gmms_raw_file`.`state` AS `state`,`gmms_raw_file`.`operator` AS `operator`,`gmms_raw_file`.`width` AS `width`,`gmms_raw_file`.`height` AS `height`,`gmms_raw_file`.`thickness` AS `thickness`,`gmms_raw_file`.`count` AS `count`,`gmms_raw_file`.`create_time` AS `create_time`,`gmms_raw_file`.`receive_time` AS `receive_time`,`gmms_raw_file`.`galssmeasure` AS `galssmeasure`,`gmms_raw_file`.`patternmeasure` AS `patternmeasure`,`gmms_raw_file`.`cutting_rate` AS `cutting_rate`,`gmms_raw_file`.`Update_time` AS `Update_time` from `gmms_raw_file` where ((`gmms_raw_file`.`state` like '%完成%') and (`gmms_raw_file`.`receive_time` > (curdate() - interval 7 day))) order by `gmms_raw_file`.`receive_time` desc,`gmms_raw_file`.`id` desc;
 
-- ----------------------------
-- View structure for v_ghh_online_glass
-- ----------------------------
DROP VIEW IF EXISTS `v_ghh_online_glass`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `v_ghh_online_glass` AS select NULL AS `NULL`,`ggt`.`galss_id` AS `galss_id`,`ggt`.`edg_width` AS `edg_width`,`ggt`.`edg_height` AS `edg_height`,concat(`ggt`.`thickness`,'mm ',`ggt`.`color`) AS `moxi`,`ggt`.`processcard_id` AS `processcard_id`,`ggt`.`work_procedure` AS `work_procedure`,`ggt`.`work_state` AS `work_state`,`ggt`.`drop_frame` AS `drop_frame`,`ggt`.`orders` AS `orders`,`ggt`.`grouporder` AS `grouporder`,`ggt`.`furnace` AS `furnace`,`ggt`.`groups` AS `groups`,`ggt`.`fine_throwing` AS `fine_throwing`,`ggt`.`id` AS `id` from `gmms_galss_task_2` `ggt` where ((`ggt`.`orders` is not null) and (((`ggt`.`work_procedure` = '钢化') and (`ggt`.`work_state` <> '等待中')) or (`ggt`.`work_procedure` = '钢化后摆片') or (`ggt`.`work_procedure` = '钢化后复合') or ((`ggt`.`work_procedure` = '钢化后下片') and (`ggt`.`work_state` <> '已完成'))) and (`ggt`.`work_state` <> '破损')) order by `ggt`.`furnace`,`ggt`.`grouporder`,`ggt`.`orders`;
 
-- ----------------------------
-- View structure for v_ghq_liuchengka
-- ----------------------------
DROP VIEW IF EXISTS `v_ghq_liuchengka`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `v_ghq_liuchengka` AS select NULL AS `NULL`,`l`.`liuchengka` AS `liuchengka`,`b`.`ceng` AS `ceng`,`b`.`houdu` AS `houdu`,`b`.`moxi` AS `moxi`,`b`.`mianji` AS `mianji`,`b`.`shuliang` AS `shuliang`,`b`.`Create_time` AS `Create_time` from (`gmms_liuchengka` `l` left join `gmms_liuchengka_buffer` `b` on((`l`.`liuchengka` = `b`.`liuchengkahaoceng`))) where ((`l`.`current_status` = '已完成') and (`l`.`current_work_position` = '创建') and (`l`.`gy_gang` = 1) and (`l`.`piece_count` > 10) and (`l`.`minArea` > 0.7) and (`l`.`isgang` = '冷加工下片完成')) group by `l`.`liuchengka` order by `b`.`Create_time`;
 
-- ----------------------------
-- View structure for v_ghq_online_glass
-- ----------------------------
DROP VIEW IF EXISTS `v_ghq_online_glass`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `v_ghq_online_glass` AS select NULL AS `NULL`,`gh`.`galss_id` AS `galss_id`,`gh`.`edg_width` AS `edg_width`,`gh`.`edg_height` AS `edg_height`,concat(`gh`.`thickness`,'mm ',`gh`.`color`) AS `moxi`,`gh`.`processcard_id` AS `processcard_id`,`gh`.`work_procedure` AS `work_procedure`,`gh`.`work_state` AS `work_state`,`gh`.`drop_frame` AS `drop_frame`,`gh`.`orders` AS `orders`,`gh`.`grouporder` AS `grouporder`,`gh`.`furnace` AS `furnace`,`gh`.`groups` AS `groups`,`gh`.`fine_throwing` AS `fine_throwing`,`gh`.`id` AS `id` from `gmms_galss_task_2` `gh` where ((`gh`.`orders` is not null) and ((`gh`.`work_procedure` = '钢化上片') or (`gh`.`work_procedure` = '钢化前复合') or (`gh`.`work_procedure` = '钢化前摆片') or (`gh`.`work_procedure` = '钢化')) and (`gh`.`work_state` <> '破损')) order by `gh`.`furnace`,`gh`.`orders`;
 
-- ----------------------------
-- View structure for v_gh_shangpianwei
-- ----------------------------
DROP VIEW IF EXISTS `v_gh_shangpianwei`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `v_gh_shangpianwei` AS select `f`.`id` AS `id`,`f`.`stops` AS `stops`,`f`.`processcard_id` AS `processcard_id`,`f`.`state` AS `state`,`f`.`processcard_count` AS `zongshu`,(select count(1) from `gmms_galss_task_2` `t2` where ((`t2`.`work_state` = '破损') and (`t2`.`processcard_id` = `f`.`processcard_id`))) AS `posunshu`,(select count(1) from `gmms_galss_task_2` `t2` where ((`t2`.`work_state` = '已优化') and (`t2`.`processcard_id` = `f`.`processcard_id`))) AS `yiyouhua`,NULL AS `wanchengshu`,(select count(1) from `gmms_galss_task_2` `t3` where ((`t3`.`work_state` <> '破损') and (`t3`.`work_procedure` = '钢化上片') and (`t3`.`processcard_id` = `f`.`processcard_id`))) AS `shengyushu`,`f`.`surplus_count` AS `shangpianshengyushu`,`f`.`noodles` AS `noodles`,`f`.`flag` AS `flag`,`f`.`groups` AS `groups`,(select `l`.`Occupied` from `gmms_liuchengka` `l` where (`l`.`liuchengka` = `f`.`processcard_id`)) AS `weizhi` from `gmms_drop_frame_2` `f` group by `f`.`id`,`f`.`stops`,`f`.`processcard_id`,`f`.`state`,`f`.`noodles`,`f`.`flag`,`f`.`groups`;
 
-- ----------------------------
-- View structure for v_gh_shangpianwei_copy1
-- ----------------------------
DROP VIEW IF EXISTS `v_gh_shangpianwei_copy1`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `v_gh_shangpianwei_copy1` AS select `f`.`id` AS `id`,`f`.`stops` AS `stops`,`f`.`processcard_id` AS `processcard_id`,`f`.`state` AS `state`,(select count(1) from `gmms_galss_task_2` `t2` where (`t2`.`processcard_id` = `f`.`processcard_id`)) AS `zongshu`,(select count(1) from `gmms_galss_task_2` `t2` where ((`t2`.`work_state` = '破损') and (`t2`.`processcard_id` = `f`.`processcard_id`))) AS `posunshu`,(select count(1) from `gmms_galss_task_2` `t2` where ((`t2`.`work_state` = '已优化') and (`t2`.`processcard_id` = `f`.`processcard_id`))) AS `yiyouhua`,(select count(1) from `gmms_galss_task_2` `t2` where ((`t2`.`work_state` = '已完成') and (`t2`.`processcard_id` = `f`.`processcard_id`))) AS `wanchengshu`,NULL AS `shengyushu`,`f`.`noodles` AS `noodles`,`f`.`flag` AS `flag`,`f`.`groups` AS `groups` from (`gmms_drop_frame_2` `f` left join `gmms_galss_task_2` `t` on(((`f`.`processcard_id` = `t`.`processcard_id`) and (`f`.`engineering_id` = `t`.`engineering_id`))));
 
-- ----------------------------
-- View structure for v_gh_shangpianwei_copy2
-- ----------------------------
DROP VIEW IF EXISTS `v_gh_shangpianwei_copy2`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `v_gh_shangpianwei_copy2` AS select `f`.`id` AS `id`,`f`.`stops` AS `stops`,`f`.`processcard_id` AS `processcard_id`,`f`.`state` AS `state`,(select count(1) from `gmms_galss_task_2` `t2` where (`t2`.`processcard_id` = `f`.`processcard_id`)) AS `zongshu`,(select count(1) from `gmms_galss_task_2` `t2` where ((`t2`.`work_state` = '破损') and (`t2`.`processcard_id` = `f`.`processcard_id`))) AS `posunshu`,(select count(1) from `gmms_galss_task_2` `t2` where ((`t2`.`work_state` = '已优化') and (`t2`.`processcard_id` = `f`.`processcard_id`))) AS `yiyouhua`,(select count(1) from `gmms_galss_task_2` `t2` where ((`t2`.`work_state` = '已完成') and (`t2`.`processcard_id` = `f`.`processcard_id`))) AS `wanchengshu`,NULL AS `shengyushu`,`f`.`noodles` AS `noodles`,`f`.`flag` AS `flag`,`f`.`groups` AS `groups` from (`gmms_drop_frame_2` `f` left join `gmms_galss_task_2` `t` on((`f`.`processcard_id` = `t`.`processcard_id`))) group by `f`.`id`,`f`.`stops`,`f`.`processcard_id`,`f`.`state`,`f`.`noodles`,`f`.`flag`,`f`.`groups`;
 
-- ----------------------------
-- View structure for v_gh_shangpianwei_copy3
-- ----------------------------
DROP VIEW IF EXISTS `v_gh_shangpianwei_copy3`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `v_gh_shangpianwei_copy3` AS select `f`.`id` AS `id`,`f`.`stops` AS `stops`,`f`.`processcard_id` AS `processcard_id`,`f`.`state` AS `state`,`f`.`processcard_count` AS `zongshu`,(select count(1) from `gmms_galss_task_2` `t2` where ((`t2`.`work_state` = '破损') and (`t2`.`processcard_id` = `f`.`processcard_id`))) AS `posunshu`,(select count(1) from `gmms_galss_task_2` `t2` where ((`t2`.`work_state` = '已优化') and (`t2`.`processcard_id` = `f`.`processcard_id`))) AS `yiyouhua`,(select count(1) from `gmms_galss_task_2` `t2` where ((`t2`.`work_state` = '已完成') and (`t2`.`processcard_id` = `f`.`processcard_id`))) AS `wanchengshu`,NULL AS `shengyushu`,`f`.`surplus_count` AS `shangpianshengyushu`,`f`.`noodles` AS `noodles`,`f`.`flag` AS `flag`,`f`.`groups` AS `groups`,(select `l`.`Occupied` from `gmms_liuchengka` `l` where (`l`.`liuchengka` = `f`.`processcard_id`)) AS `weizhi` from (`gmms_drop_frame_2` `f` left join `gmms_galss_task_2` `t` on((`f`.`processcard_id` = `t`.`processcard_id`))) group by `f`.`id`,`f`.`stops`,`f`.`processcard_id`,`f`.`state`,`f`.`noodles`,`f`.`flag`,`f`.`groups`;
 
-- ----------------------------
-- View structure for v_gh_shangpianwei_copy4_12
-- ----------------------------
DROP VIEW IF EXISTS `v_gh_shangpianwei_copy4_12`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `v_gh_shangpianwei_copy4_12` AS select `f`.`id` AS `id`,`f`.`stops` AS `stops`,`f`.`processcard_id` AS `processcard_id`,`f`.`state` AS `state`,`f`.`processcard_count` AS `zongshu`,(select count(1) from `gmms_galss_task_2` `t2` where ((`t2`.`work_state` = '破损') and (`t2`.`processcard_id` = `f`.`processcard_id`))) AS `posunshu`,(select count(1) from `gmms_galss_task_2` `t2` where ((`t2`.`work_state` = '已优化') and (`t2`.`processcard_id` = `f`.`processcard_id`))) AS `yiyouhua`,NULL AS `wanchengshu`,(select count(1) from `gmms_galss_task_2` `t3` where ((`t3`.`work_state` <> '已完成') and (`t3`.`work_procedure` = '钢化上片') and (`t3`.`processcard_id` = `f`.`processcard_id`))) AS `shengyushu`,`f`.`surplus_count` AS `shangpianshengyushu`,`f`.`noodles` AS `noodles`,`f`.`flag` AS `flag`,`f`.`groups` AS `groups`,(select `l`.`Occupied` from `gmms_liuchengka` `l` where (`l`.`liuchengka` = `f`.`processcard_id`)) AS `weizhi` from (`gmms_drop_frame_2` `f` left join `gmms_galss_task_2` `t` on((`f`.`processcard_id` = `t`.`processcard_id`))) group by `f`.`id`,`f`.`stops`,`f`.`processcard_id`,`f`.`state`,`f`.`noodles`,`f`.`flag`,`f`.`groups`;
 
-- ----------------------------
-- View structure for v_gh_xiapianwei
-- ----------------------------
DROP VIEW IF EXISTS `v_gh_xiapianwei`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `v_gh_xiapianwei` AS select `d`.`id` AS `Id`,`d`.`drop_groups` AS `groups`,`d`.`stops` AS `stops`,`d`.`rank` AS `rank`,`s`.`id` AS `rId`,`s`.`state` AS `state`,(select distinct `g`.`gc_number` from `gmms_galss_task_2` `g` where (`g`.`processcard_id` = `s`.`processcard_id`)) AS `gongchenghao`,`s`.`processcard_id` AS `processcard_id`,(select count(`g`.`id`) from `gmms_galss_task_2` `g` where ((`g`.`processcard_id` = `s`.`processcard_id`) and (`g`.`work_procedure` = '钢化后下片') and (`g`.`work_state` = '已完成'))) AS `wanchengshu`,(select count(`g`.`id`) from `gmms_galss_task_2` `g` where ((`g`.`processcard_id` = `s`.`processcard_id`) and (`g`.`work_state` = '破损'))) AS `posunshu`,(select count(`g`.`id`) from `gmms_galss_task_2` `g` where (`g`.`processcard_id` = `s`.`processcard_id`)) AS `zongshu`,NULL AS `weiwanchegnshu`,`d`.`orientation` AS `orientation`,`d`.`stop_rank` AS `stop_rank`,`d`.`sign` AS `sign`,`d`.`flag` AS `flag`,`d`.`groups_` AS `groups_` from (`gmms_drop_frame_5` `d` left join `gmms_shelf_rack_2` `s` on((`d`.`rank` = `s`.`id`))) where (`d`.`groups_` = 1);
 
-- ----------------------------
-- View structure for v_liuchengkareportform
-- ----------------------------
DROP VIEW IF EXISTS `v_liuchengkareportform`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `v_liuchengkareportform` AS select `g`.`id` AS `id`,`g`.`engineering_id` AS `gongchenghao`,`g`.`processcard_id` AS `liuchengkahao`,`g`.`thickness` AS `thinckness`,`g`.`color` AS `color`,sum((`g`.`width` * `g`.`height`)) AS `mianji`,count(`g`.`id`) AS `shuliang`,`g`.`start_time` AS `start_time` from `gmms_galss_task_buffer` `g` group by `g`.`processcard_id` order by `g`.`engineering_id` desc,`g`.`processcard_id`;
 
-- ----------------------------
-- View structure for v_rf_qiecailv
-- ----------------------------
DROP VIEW IF EXISTS `v_rf_qiecailv`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `v_rf_qiecailv` AS select NULL AS `序号`,`f`.`file_name` AS `工程号`,`f`.`state` AS `状态`,`f`.`operator` AS `产线`,(select `gmms_galss_task_buffer`.`color` from `gmms_galss_task_buffer` where (`gmms_galss_task_buffer`.`engineering_id` = `f`.`file_name`) limit 0,1) AS `膜系`,(select `gmms_galss_task_buffer`.`thickness` from `gmms_galss_task_buffer` where (`gmms_galss_task_buffer`.`engineering_id` = `f`.`file_name`) limit 0,1) AS `厚度`,(select count(1) from `gmms_galss_task_buffer` `b` where ((`b`.`id` > 500000) and (`b`.`engineering_id` = `f`.`file_name`))) AS `小片数量`,`f`.`galssmeasure` AS `小片面积`,`f`.`patternmeasure` AS `原片面积`,`f`.`cutting_rate` AS `切裁率`,`f`.`create_time` AS `创建时间`,`f`.`receive_time` AS `完成时间` from `gmms_raw_file` `f` where ((`f`.`state` like '%完成') and (`f`.`file_name` like 'P%') and (`f`.`create_time` > '2022-10-01')) order by `f`.`receive_time` desc;
 
-- ----------------------------
-- View structure for v_rf_qiecailv_lck
-- ----------------------------
DROP VIEW IF EXISTS `v_rf_qiecailv_lck`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `v_rf_qiecailv_lck` AS select NULL AS `序号`,`g`.`engineering_id` AS `工程号`,`g`.`processcard_id` AS `流程卡号`,`g`.`thickness` AS `厚度`,`g`.`color` AS `膜系`,round((sum((`g`.`width` * `g`.`height`)) / 1000000),6) AS `面积`,count(`g`.`id`) AS `数量`,`f`.`cutting_rate` AS `切裁率`,`g`.`start_time` AS `开始时间` from (`gmms_galss_task_buffer` `g` left join `gmms_raw_file` `f` on((`g`.`engineering_id` = `f`.`file_name`))) where (`g`.`start_time` > (curdate() - interval 1 year)) group by `g`.`processcard_id` order by `g`.`engineering_id` desc,`g`.`processcard_id`;
 
-- ----------------------------
-- View structure for v_zklp_shangpianwei
-- ----------------------------
DROP VIEW IF EXISTS `v_zklp_shangpianwei`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `v_zklp_shangpianwei` AS select `d`.`id` AS `Id`,`d`.`drop_groups` AS `groups`,`d`.`stops` AS `stops`,`d`.`rank` AS `rank`,`d`.`flag` AS `flag`,`d`.`sign` AS `sign`,`s`.`processcard_id` AS `processcard_id`,(select `t`.`piece_count` from `y_shelfrackcardinfo` `t` where (`t`.`liuchengka` = `s`.`processcard_id`)) AS `zongshu`,(select count(`g`.`id`) from `gmms_galss_task_shelf` `g` where (`g`.`processcard_id` = `s`.`processcard_id`)) AS `kuneishu`,(select count(`g`.`id`) from `gmms_galss_task_shelf` `g` where ((`g`.`processcard_id` = `s`.`processcard_id`) and (`g`.`work_state` = '破损'))) AS `posunshu`,NULL AS `quepianshu`,NULL AS `yishangpian`,(select count(`g`.`id`) from `gmms_galss_task_shelf` `g` where ((`g`.`processcard_id` = `s`.`processcard_id`) and (`g`.`work_procedure` = '钢化后下片') and (`g`.`work_state` = '已完成'))) AS `jiazishengyushu`,`d`.`orientation` AS `orientation`,`d`.`stop_rank` AS `stop_rank` from (`gmms_drop_frame_5` `d` left join `gmms_shelf_rack_2` `s` on((`d`.`rank` = `s`.`id`))) where (`d`.`groups_` = 3);
 
-- ----------------------------
-- View structure for v_zk_shangpianwei
-- ----------------------------
DROP VIEW IF EXISTS `v_zk_shangpianwei`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `v_zk_shangpianwei` AS select `d`.`id` AS `Id`,`d`.`drop_groups` AS `groups`,`d`.`stops` AS `stops`,`d`.`rank` AS `rank`,`d`.`flag` AS `flag`,`d`.`sign` AS `sign`,`s`.`processcard_id` AS `processcard_id`,(select `t`.`piece_count` from `y_shelfrackcardinfo` `t` where (`t`.`liuchengka` = `s`.`processcard_id`)) AS `zongshu`,(select count(`g`.`id`) from `gmms_galss_task_shelf` `g` where ((`g`.`processcard_id` = `s`.`processcard_id`) and (`g`.`stop_position` > 0))) AS `kuneishu`,((select `t`.`piece_count` from `y_shelfrackcardinfo` `t` where (`t`.`liuchengka` = `s`.`processcard_id`)) - (select count(`g`.`id`) from `gmms_galss_task_shelf` `g` where ((`g`.`processcard_id` = `s`.`processcard_id`) and (`g`.`stop_position` > 0)))) AS `quepianshu`,(select count(`g`.`id`) from `gmms_galss_task_shelf` `g` where ((`g`.`processcard_id` = `s`.`processcard_id`) and (`g`.`work_procedure` = '中空上片') and (`g`.`work_state` = '已完成'))) AS `wanchengshu`,NULL AS `shengyushu`,`d`.`orientation` AS `orientation`,`d`.`stop_rank` AS `stop_rank` from (`gmms_drop_frame_5` `d` left join `gmms_shelf_rack_2` `s` on((`d`.`rank` = `s`.`id`))) where (`d`.`groups_` = 4);
 
-- ----------------------------
-- View structure for y_howllorslicetasks
-- ----------------------------
DROP VIEW IF EXISTS `y_howllorslicetasks`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `y_howllorslicetasks` AS select `y_howllowgroupby`.`main_liuchengka` AS `main_liuchengka`,sum(`y_howllowgroupby`.`piececount`) AS `sumpiececount`,sum(`y_howllowgroupby`.`storagecounts`) AS `sumstoragecount`,(sum(`y_howllowgroupby`.`piececount`) = sum(`y_howllowgroupby`.`storagecounts`)) AS `isprice`,count(0) AS `ishowllorslice` from `y_howllowgroupby` group by `y_howllowgroupby`.`main_liuchengka` having (sum(`y_howllowgroupby`.`piececount`) = sum(`y_howllowgroupby`.`storagecounts`));
 
-- ----------------------------
-- View structure for y_howllowgroupby
-- ----------------------------
DROP VIEW IF EXISTS `y_howllowgroupby`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `y_howllowgroupby` AS select `y_shelfrackcardinfo`.`id` AS `id`,`y_shelfrackcardinfo`.`orientation` AS `orientation`,`y_shelfrackcardinfo`.`falg` AS `falg`,`y_shelfrackcardinfo`.`state` AS `state`,`y_shelfrackcardinfo`.`liuchengka` AS `liuchengka`,`y_shelfrackcardinfo`.`main_liuchengka` AS `main_liuchengka`,`y_shelfrackcardinfo`.`cardrank` AS `cardrank`,count(`y_shelfrackcardinfo`.`liuchengka`) AS `cardcount`,sum(`y_shelfrackcardinfo`.`piece_count`) AS `piececount`,sum(`y_shelfrackcardinfo`.`storagecount`) AS `storagecounts` from `y_shelfrackcardinfo` group by `y_shelfrackcardinfo`.`main_liuchengka`,`y_shelfrackcardinfo`.`groupwidth`,`y_shelfrackcardinfo`.`groupheight`;
 
-- ----------------------------
-- View structure for y_liuchengka
-- ----------------------------
DROP VIEW IF EXISTS `y_liuchengka`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `y_liuchengka` AS select `lk`.`parent_liuchengka` AS `parent_liuchengka`,`lk`.`liuchengka` AS `liuchengka`,`ypl`.`zongshu` AS `zongshu`,`lk`.`piece_count` AS `piece_count`,`sr`.`id` AS `id`,`sr`.`state` AS `state`,`sr`.`falg` AS `falg`,`sr`.`orientation` AS `orientation` from ((`y_parent_liuchengka` `ypl` left join `gmms_liuchengka` `lk` on((`ypl`.`zkliuchengka` = `lk`.`parent_liuchengka`))) left join `gmms_shelf_rack_2` `sr` on((`lk`.`liuchengka` = `sr`.`processcard_id`))) where (`lk`.`parent_liuchengka` is not null);
 
-- ----------------------------
-- View structure for y_liuchengka_copy1
-- ----------------------------
DROP VIEW IF EXISTS `y_liuchengka_copy1`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `y_liuchengka_copy1` AS select `lk`.`parent_liuchengka` AS `parent_liuchengka`,`lk`.`liuchengka` AS `liuchengka`,`lk`.`piece_count` AS `piece_count` from (`gmms_liuchengka` `lk` left join `gmms_shelf_rack_2` `sr` on((`lk`.`liuchengka` = `sr`.`processcard_id`))) where (`sr`.`processcard_id` is not null);
 
-- ----------------------------
-- View structure for y_parent_liuchengka
-- ----------------------------
DROP VIEW IF EXISTS `y_parent_liuchengka`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `y_parent_liuchengka` AS select NULL AS `xuhao`,`lk`.`parent_liuchengka` AS `zkliuchengka`,(select group_concat(`gmms_liuchengka`.`liuchengka` separator ',') from `gmms_liuchengka` where (`gmms_liuchengka`.`parent_liuchengka` = `lk`.`parent_liuchengka`)) AS `liuchengkas`,(select sum(`gmms_liuchengka`.`piece_count`) from `gmms_liuchengka` where (`gmms_liuchengka`.`parent_liuchengka` = `lk`.`parent_liuchengka`)) AS `zongshu`,(select count(`gmms_galss_task_shelf`.`id`) from `gmms_galss_task_shelf` where ((`gmms_galss_task_shelf`.`gc_number` = `lk`.`parent_liuchengka`) and (`gmms_galss_task_shelf`.`work_procedure` = '钢化后下片') and (`gmms_galss_task_shelf`.`work_state` = '已完成'))) AS `kuneishu` from (`gmms_liuchengka` `lk` left join `gmms_shelf_rack_2` `sr` on((`lk`.`liuchengka` = `sr`.`processcard_id`))) where (`sr`.`processcard_id` is not null) group by `lk`.`parent_liuchengka`;
 
-- ----------------------------
-- View structure for y_parent_liuchengka_copy1
-- ----------------------------
DROP VIEW IF EXISTS `y_parent_liuchengka_copy1`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `y_parent_liuchengka_copy1` AS select `lk`.`parent_liuchengka` AS `parent_liuchengka`,sum(`lk`.`piece_count`) AS `parent_count` from (`gmms_liuchengka` `lk` left join `gmms_shelf_rack_2` `sr` on((`lk`.`liuchengka` = `sr`.`processcard_id`))) where (`sr`.`processcard_id` is not null) group by `lk`.`parent_liuchengka`;
 
-- ----------------------------
-- View structure for y_shelfgalsss
-- ----------------------------
DROP VIEW IF EXISTS `y_shelfgalsss`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `y_shelfgalsss` AS select NULL AS `xuhao`,`yl`.`parent_liuchengka` AS `parent_liuchengka`,`yl`.`liuchengka` AS `liuchengka`,`yl`.`zongshu` AS `zongshu`,`yl`.`piece_count` AS `piece_count`,`yl`.`id` AS `id`,`yl`.`state` AS `state`,`yl`.`falg` AS `falg`,`yl`.`orientation` AS `orientation`,`gb`.`id` AS `taskid`,`gs`.`id` AS `shelftaskid`,`gs`.`stop_rank` AS `stop_rank`,`gs`.`stop_position` AS `stop_position`,`gb`.`width` AS `width`,`gb`.`height` AS `height`,`gb`.`thickness` AS `thickness`,`gb`.`color` AS `color`,`gs`.`work_state` AS `work_state`,`gs`.`work_procedure` AS `work_procedure` from ((`y_liuchengka` `yl` left join `gmms_galss_task_buffer` `gb` on((`yl`.`liuchengka` = `gb`.`processcard_id`))) left join `gmms_galss_task_shelf` `gs` on((`gb`.`id` = `gs`.`id`))) where (`gb`.`processcard_id` is not null);
 
-- ----------------------------
-- View structure for y_shelfprocesscard
-- ----------------------------
DROP VIEW IF EXISTS `y_shelfprocesscard`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `y_shelfprocesscard` AS select `y_shelfrack`.`processcard` AS `processcard` from `y_shelfrack` where (`y_shelfrack`.`processcard` is not null) group by `y_shelfrack`.`processcard`;
 
-- ----------------------------
-- View structure for y_shelfrack
-- ----------------------------
DROP VIEW IF EXISTS `y_shelfrack`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `y_shelfrack` AS select `sr`.`id` AS `id`,`sr`.`state` AS `state`,left(`sr`.`processcard_id`,(locate('/',`sr`.`processcard_id`) - 1)) AS `processcard`,substr(`sr`.`processcard_id`,(locate('/',`sr`.`processcard_id`) + 1)) AS `cardrank`,`gt`.`processcard_id` AS `processcard_id`,group_concat(`gt`.`edg_speed2` order by `gt`.`stop_rank` ASC separator ',') AS `grouprank`,group_concat(`gt`.`width` order by `gt`.`stop_rank` ASC separator ',') AS `groupwidth`,group_concat(`gt`.`height` order by `gt`.`stop_rank` ASC separator ',') AS `groupheight`,`sr`.`orientation` AS `orientation`,`sr`.`sign` AS `sign`,`sr`.`falg` AS `falg`,count(0) AS `storagecount` from (`gmms_shelf_rack_2` `sr` join `gmms_galss_task_shelf` `gt` on((`sr`.`processcard_id` = `gt`.`processcard_id`))) group by `gt`.`processcard_id`;
 
-- ----------------------------
-- View structure for y_shelfrackcardinfo
-- ----------------------------
DROP VIEW IF EXISTS `y_shelfrackcardinfo`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `y_shelfrackcardinfo` AS select `gl`.`liuchengka` AS `liuchengka`,`gl`.`main_liuchengka` AS `main_liuchengka`,`ysr`.`id` AS `id`,`ysr`.`state` AS `state`,`ysr`.`processcard` AS `processcard`,`ysr`.`cardrank` AS `cardrank`,`ysr`.`processcard_id` AS `processcard_id`,`ysr`.`grouprank` AS `grouprank`,`ysr`.`groupwidth` AS `groupwidth`,`ysr`.`groupheight` AS `groupheight`,`ysr`.`orientation` AS `orientation`,`ysr`.`sign` AS `sign`,`ysr`.`falg` AS `falg`,`ysr`.`storagecount` AS `storagecount`,`gl`.`gy_gang` AS `gy_gang`,`gl`.`gy_jiajiao` AS `gy_jiajiao`,`gl`.`gy_zhongkong` AS `gy_zhongkong`,`gl`.`piece_count` AS `piece_count`,`gliu`.`child_count` AS `child_count` from (((`gmms_liuchengka` `gl` join `y_shelfprocesscard` `ysp` on((`gl`.`main_liuchengka` = `ysp`.`processcard`))) left join `y_shelfrack` `ysr` on((`gl`.`liuchengka` = `ysr`.`processcard_id`))) left join `gmms_liuchengka` `gliu` on((`gl`.`main_liuchengka` = `gliu`.`main_liuchengka`))) where ((`gl`.`is_single` <> 0) and (`gliu`.`is_single` = 0));
 
-- ----------------------------
-- View structure for y_slicetasks
-- ----------------------------
DROP VIEW IF EXISTS `y_slicetasks`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `y_slicetasks` AS select `yhg`.`id` AS `id`,`yhg`.`orientation` AS `orientation`,`yhg`.`falg` AS `falg`,`yhg`.`state` AS `state`,`yhg`.`liuchengka` AS `liuchengka`,`yhg`.`main_liuchengka` AS `main_liuchengka`,`yhg`.`cardrank` AS `cardrank`,`yhg`.`cardcount` AS `cardcount`,`yhg`.`piececount` AS `piececount`,`yhg`.`storagecounts` AS `storagecounts`,`yh`.`sumpiececount` AS `sumpiececount`,`yh`.`sumstoragecount` AS `sumstoragecount`,`yh`.`isprice` AS `isprice`,`yh`.`ishowllorslice` AS `ishowllorslice` from (`y_howllorslicetasks` `yh` join `y_howllowgroupby` `yhg` on((`yh`.`main_liuchengka` = `yhg`.`main_liuchengka`))) where ((`yh`.`ishowllorslice` > 1) and (`yhg`.`cardcount` = 1)) order by `yhg`.`main_liuchengka`,`yhg`.`cardcount`,`yhg`.`cardrank` desc;
 
-- ----------------------------
-- View structure for y_slicetasks_copy1
-- ----------------------------
DROP VIEW IF EXISTS `y_slicetasks_copy1`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `y_slicetasks_copy1` AS select `yhg`.`id` AS `id`,`yhg`.`orientation` AS `orientation`,`yhg`.`falg` AS `falg`,`yhg`.`state` AS `state`,`yhg`.`liuchengka` AS `liuchengka`,`yhg`.`main_liuchengka` AS `main_liuchengka`,`yhg`.`cardrank` AS `cardrank`,`yhg`.`cardcount` AS `cardcount`,`yhg`.`piececount` AS `piececount`,`yhg`.`storagecounts` AS `storagecounts`,`yh`.`sumpiececount` AS `sumpiececount`,`yh`.`sumstoragecount` AS `sumstoragecount`,`yh`.`isprice` AS `isprice`,`yh`.`ishowllorslice` AS `ishowllorslice` from (`y_howllorslicetasks` `yh` join `y_howllowgroupby` `yhg` on((`yh`.`main_liuchengka` = `yhg`.`main_liuchengka`))) where (`yh`.`ishowllorslice` > 1) order by `yhg`.`main_liuchengka`,`yhg`.`cardcount`,`yhg`.`cardrank` desc;
 
-- ----------------------------
-- View structure for y_station_shelf
-- ----------------------------
DROP VIEW IF EXISTS `y_station_shelf`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `y_station_shelf` AS select `dr`.`id` AS `id`,`dr`.`groups_` AS `groups_`,`dr`.`drop_type` AS `drop_type`,`dr`.`drop_groups` AS `drop_groups`,`dr`.`stops` AS `stops`,`dr`.`stop_rank` AS `stop_rank`,`dr`.`orientation` AS `orientation`,`dr`.`rank` AS `rank`,`dr`.`sign` AS `sign`,`dr`.`flag` AS `flag`,`dr`.`all_groups` AS `all_groups`,`dr`.`position` AS `position`,`dr`.`rankposition` AS `rankposition`,`sr`.`processcard_id` AS `processcard_id`,`sr`.`orientation` AS `RankOrientation`,`lk`.`current_work_position` AS `current_work_position`,`lk`.`current_status` AS `current_status`,`lk`.`getdatatime` AS `getdatatime`,`lk`.`getgroups` AS `getgroups`,(select count(`gmms_galss_task_shelf`.`id`) from `gmms_galss_task_shelf` where ((`gmms_galss_task_shelf`.`processcard_id` = `sr`.`processcard_id`) and (`gmms_galss_task_shelf`.`work_state` <> '破损') and ((`gmms_galss_task_shelf`.`work_procedure` <> '中空上片') or (`gmms_galss_task_shelf`.`work_state` <> '已完成')))) AS `processcardcount` from ((`gmms_drop_frame_5` `dr` left join `gmms_shelf_rack_2` `sr` on((`dr`.`rank` = `sr`.`id`))) left join `gmms_liuchengka` `lk` on((`sr`.`processcard_id` = `lk`.`liuchengka`))) where (`dr`.`groups_` = 100);
 
-- ----------------------------
-- View structure for 冷加工产量时间
-- ----------------------------
DROP VIEW IF EXISTS `冷加工产量时间`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `冷加工产量时间` AS select `rf`.`file_name` AS `工程号`,`rf`.`state` AS `状态`,`rf`.`operator` AS `线路`,min(`gs`.`finsh_time`) AS `第一片落架时间`,max(`gs`.`finsh_time`) AS `最后一片落架时间`,timediff(max(`gs`.`finsh_time`),min(`gs`.`finsh_time`)) AS `总用时`,(select count(0) from `gmms_galss_task_buffer` where (`gmms_galss_task_buffer`.`engineering_id` = `rf`.`file_name`)) AS `总数` from (`gmms_raw_file` `rf` left join `gmms_galss_task_stock` `gs` on((`rf`.`file_name` = `gs`.`engineering_id`))) where ((`gs`.`engineering_id` is not null) and (`rf`.`state` = '已完成') and (`rf`.`create_time` > (now() - interval 14 day))) group by `gs`.`engineering_id`;
 
-- ----------------------------
-- Procedure structure for 111
-- ----------------------------
DROP PROCEDURE IF EXISTS `111`;
delimiter ;;
CREATE PROCEDURE `111`()
BEGIN
DECLARE t_error INTEGER DEFAULT 0;
DECLARE c INTEGER DEFAULT 0;
DECLARE y int DEFAULT 0;
DECLARE processcardid2 varchar(255);
    DECLARE    CONTINUE HANDLER FOR SQLEXCEPTION SET t_error = 1;
    
 
--  DECLARE _rank int;
--  DECLARE  _id bigint;
--  DECLARE  done int ;
--  DECLARE  g  varchar(30);
--  declare cur CURSOR for   
--     select rank,id,engineering_id from gmms_pattern_task_buffer;
--   # 游标中的内容执行完后将done设置为1  
--   DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1;  
--       open cur;
--       a: LOOP
--               
--                      IF done=1 THEN    
--                          LEAVE a;  
--                         END IF;
--                   FETCH cur into  _rank ,_id,g;
--                                      UPDATE gmms_galss_task_buffer set pattern_id=_id where gc_stockid=_rank and engineering_id=g;
--                     
--                      
--           END LOOP a;    
--          close cur;
 
 
--     select GROUP_CONCAT(gtf.edg_speed2)  from (select edg_speed2 from gmms_galss_task_shelf where processcard_id='NG22091607A10/3' and stop_rank<=20 order by stop_rank) as gtf;
--     select GROUP_CONCAT(gtf.edg_speed2)  from (select edg_speed2 from gmms_galss_task_shelf where processcard_id='NG22091607A10/2' and stop_rank<=20 order by stop_rank) as gtf;        
--                         
--                 if  position("P" in 'm23022416')>0 then
--                     select 1;
--                 else
--                     select 2;
--                 end if;        
 
if 1=1 then
select 1;
end if;
--                         
-- #中空任务
-- select  count(*) into @count1 from 
-- (select count(*) as ccc,a.parent_liuchengka,b.child_count from gmms_liuchengka  a inner join gmms_liuchengka b on a.parent_liuchengka=b.liuchengka inner join  gmms_shelf_rack_2 c on 
-- a.liuchengka=c.processcard_id where c.sign=2 and b.gongyi='中空' group by a.parent_liuchengka ,b.child_count) aa
-- where aa.child_count=aa.ccc;
-- while c<@count1 do
--     select  aa.parent_liuchengka into @parent_liuchengka from 
-- (select count(*) as ccc,a.parent_liuchengka,b.child_count from gmms_liuchengka  a inner join gmms_liuchengka b on a.parent_liuchengka=b.liuchengka inner join  gmms_shelf_rack_2 c on 
-- a.liuchengka=c.processcard_id where c.sign=2 and b.gongyi='中空' group by a.parent_liuchengka ,b.child_count) aa
-- where aa.child_count=aa.ccc limit c,1;
--     if @parent_liuchengka is not null then
--         select count(*) into @count2 from gmms_raw_file_2 where file_name=@parent_liuchengka;
--         if @count2=0 then
--             select count(*) into @count8 from gmms_shelf_rack_2 where processcard_id like CONCAT('%',@parent_liuchengka,'%') and orientation='A';
--             select count(*) into @count9 from gmms_shelf_rack_2 where processcard_id like CONCAT('%',@parent_liuchengka,'%') and orientation='B';
--             if @count8!=3 or @count9!=3 then
--                 insert into gmms_raw_file_2 (file_name,state,operator,create_time) values(@parent_liuchengka,'未领取',0,NOW());
--             else
--                 select number into @number from gmms_shelf_rack_2 where processcard_id like CONCAT('%',@parent_liuchengka,'%') order by number limit 0,1;
--                 select noodles into @noodles from gmms_drop_frame_2 where groups=20 and flag=1;
--                 select count(*) into @count10 from gmms_shelf_task_2 where shelf_rack_id=@number and load_rack=@noodles and task_type='从仓位到旋转位' and groups=0 and line=3 and (task_state='正在工作' or task_state='等待中');
--                 if @count10=0 and @number is not null then
--                     insert into gmms_shelf_task_2 (task_type,task_state,shelf_rack_id,load_rack,groups,start_time,line) values('从仓位到旋转位','等待中',@number,@noodles,0,now(),3);
--                 end if;
--             end if;
--             
--         end if;
--     end if;
--     
-- set c=c+1;
-- end while;
 
 
-- #钢化后的完成
-- insert into E_record_hollow  
-- select gs.processcard_id,gs.id,gs.edg_width,gs.edg_height,gs.thickness,gs.color,gs.stop_rank,gs.finsh_time,'工序','线路' from gmms_galss_task_shelf as gs left join E_Pierceds as ep on gs.id=gs.id
-- where ep.id is null;
-- 
-- #钢化后的破损
-- insert into E_Pierceds  
-- select gs.processcard_id,'玻璃类型',1,'刺破类型','刺破原因','是否报工',gs.id,NOW(),'工序','线路' from gmms_galss_task_shelf as gs left join E_Pierceds as ep on gs.id=gs.id
-- where ep.id is null;
-- 
-- #钢化破损
-- insert into E_Pierceds  
-- select gs.processcard_id,'玻璃类型',1,'刺破类型','刺破原因','是否报工',gs.id,NOW(),'工序','线路' from gmms_galss_task_2 as gs left join E_Pierceds as ep on gs.id=gs.id
-- where ep.id is null;
 
 
 
 
 
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for aaaaqqq
-- ----------------------------
DROP PROCEDURE IF EXISTS `aaaaqqq`;
delimiter ;;
CREATE PROCEDURE `aaaaqqq`()
BEGIN
    #Routine body goes here...
        set @count=(select count(*) from gmms_shelf_task_2 
        where task_state='已下车' and shelf_rack_id=10);
        select @count;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for Accelerate
-- ----------------------------
DROP PROCEDURE IF EXISTS `Accelerate`;
delimiter ;;
CREATE PROCEDURE `Accelerate`(in sendMessageHex varchar(255),in machineids BIGINT,out messagedate varchar(255))
BEGIN
    #加速台存储过程
    #找到当前机器标志位
    #查询机器逻辑表中对应的逻辑进行对应的步骤
    DECLARE machinedisposeids int DEFAULT 0;
    DECLARE dates varchar(255);
    DECLARE taskplc varchar(255);
    DECLARE taskmes varchar(255);
    DECLARE messagedates varchar(255) DEFAULT '';
    set messagedate=messagedates;
    
    select machine_type_id,work_id into @mtid,@work_groups from gmms_machine where id=machineids;
    
    select speed2 into @speed2 from gmms_edg_speed where groups=@work_groups;
    
    
    select mf.flag into @请求标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='请求字';
    
    select mf.flag into @发送标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='发送字';
    
    set taskplc = substring(sendMessageHex,(cast(@请求标志位 as UNSIGNED INTEGER)*4)+19,4);
    set taskmes = substring(sendMessageHex,(cast(@发送标志位 as UNSIGNED INTEGER)*4)+19,4);
    
    select taskplc;
    select taskmes;
    
    #请求逻辑查询
    select count(*),md.id into @请求数量,@请求逻辑编号 from gmms_machine_dispose md join gmms_machine_type mt on md.machine_type_id=mt.id where md.machine_type_id=@mtid  and md.plc_font_type='请求字' and md.mes_font_type='发送字' and md.plc_font_value=taskplc and md.mes_font_value=taskmes; 
    #判断逻辑是否存在
    if  @请求数量=1 then
        
        #判断请求逻辑是否为空
        if @请求逻辑编号!=0 then
            set machinedisposeids=@请求逻辑编号;
            
        end if;
        
        #查询当前执行逻辑进行判断
        select logic,return_value,mes_font_value into @ExecutionLogic,@returnvalue,@mes_font_value from gmms_machine_dispose where id=machinedisposeids;
        if @ExecutionLogic='任务请求' then
                call AccelerateSend(sendMessageHex,machineids,@returnvalue,@messagedate);
                set messagedate=@messagedate;
         elseif @ExecutionLogic='任务清空' then
                set dates=CONCAT(@returnvalue,"00000000000000000000");
                select dates;
                call message(dates,'000a',@date);
                set messagedate=@date;
        
        end if;
        else
                call intTo2ByteHex10_16_4(@speed2,@speed2s);
                call message(@speed2s,'0011',@messagedate);
                set messagedate=@messagedate;
    end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for AccelerateSend
-- ----------------------------
DROP PROCEDURE IF EXISTS `AccelerateSend`;
delimiter ;;
CREATE PROCEDURE `AccelerateSend`(in sendMessageHex varchar(255),in machineids BIGINT,in returnvalue varchar(255),out messagedate varchar(255))
BEGIN
    #加速台请求存储过程
    #找到当前对应的工序的玻璃信息
    #序号,高度,宽度,厚度发送给plc
    DECLARE number int DEFAULT 0;
    DECLARE out_ranks int;
    DECLARE widths int;
    DECLARE heigths int;
    DECLARE thicknesss int;
    DECLARE drop_frames int;
    DECLARE dates varchar(255);
    DECLARE messagedates varchar(255) DEFAULT '';
    set messagedate=messagedates;
    
    select machine_type_id,work_id into @mtid,@work_groups from gmms_machine where id=machineids;
    
    select file_name into @engineering_id from gmms_raw_file where operator=@work_groups and state='已领取';
    
    select speed2 into @speed2 from gmms_edg_speed where groups=@work_groups;
    
    select @work_groups;
    select count(*) into @count from gmms_galss_task where work_procedure='复合' and work_state='待复合' and engineering_id=@engineering_id;
 
    if @count>0 then
--         select count(*) into @number from gmms_galss_task where work_procedure='复合' and work_state='已复合' and drop_frame=@drop_frame;
        select out_rank,width,height,thickness,drop_frame,processcard_id into @out_rank,@width,@heigth,@thickness,@drop_frame,@processcard_id from gmms_galss_task where work_procedure='复合' and work_state='待复合' and engineering_id=@engineering_id  order by out_rank limit 1;
 
        select finsh_count into @counts from gmms_drop_frame where drop_frame=@drop_frame and processcard_id=@processcard_id and groups=@work_groups;
                    select @count;
        update gmms_galss_task set work_state='正在工作' where out_rank=@out_rank and work_procedure='复合' and engineering_id=@engineering_id;
         set number=@counts+1;
        set out_ranks=cast(@out_rank as UNSIGNED INTEGER);
        set widths=cast(@width as UNSIGNED INTEGER);
        set heigths=cast(@heigth as UNSIGNED INTEGER);
        set thicknesss=cast(@thickness as UNSIGNED INTEGER);
         set drop_frames=cast(number as UNSIGNED INTEGER);
--         select ranks;
--         select heigths;
--         select widths;
--         select thicknesss;
--         select drop_frames;
        call intTo2ByteHex10_16_4(@speed2,@speed2s);
        call intTo2ByteHex10_16_4(out_ranks,@out_ranks);
        call intTo2ByteHex10_16_4(heigths,@heigth);
        call intTo2ByteHex10_16_4(widths,@width);
        call intTo2ByteHex10_16_4(thicknesss,@thickness);
         call intTo2ByteHex10_16_4(drop_frames,@drop_frame);
        select @out_ranks;
        select @heigth;
        select @width;
        select @thickness;
        select @drop_frame;
        if machineids=32 then
        set dates=CONCAT(returnvalue,@out_ranks,@width,@heigth,@thickness,'0001','0000',@speed2s);
        else
        set dates=CONCAT(returnvalue,@out_ranks,@heigth,@width,@thickness,'00000000',@speed2s);
        end if;
        
        select dates;
        call message(dates,'000a',@date);
        set messagedate=@date;
    end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for ceshi
-- ----------------------------
DROP PROCEDURE IF EXISTS `ceshi`;
delimiter ;;
CREATE PROCEDURE `ceshi`()
BEGIN
    #Routine body goes here...
    #1.查找是否掉线
    #2.查找请求交互
    #3.查找完成交互
    #4.查找正在工作的ID 信息
    DECLARE values1 varchar(255) DEFAULT '';
    DECLARE groups int DEFAULT 1;#线路
    DECLARE flags int DEFAULT 1;#冷加工(1),热加工(2),中空(3)
    DECLARE work_pro varchar(255) DEFAULT '复合';#工作阶段
    DECLARE work_st varchar(255)  DEFAULT '正在工作';#工作状态
    DECLARE messages varchar(255) DEFAULT '';
    set groups=1;
    set flags=1; 
    set work_pro='待测量';
    set work_st='正在工作';
    select id,galss_id,work_procedure,work_state,width,height,thickness,stop_rank,orders,marking_flag,distance from gmms_galss_task_2 where processcard_id='NG22102603A04/2' and work_state!='未优化' order by orders;
    select message into messages from gmms_machine_message where machine_id=22;#6.19.28.29.30
    select substring(messages,1+18,4) as 请求,
           substring(messages,41+18,4) as 发送,
                 substring(messages,21+18,4) as 完成,
                 substring(messages,81+18,4) as 确认; 
  if flags=1 then
        select * from gmms_galss_task where engineering_id=(select file_name from gmms_raw_file where operator=groups and state='已领取') and work_state=work_st; 
        select * from gmms_galss_task where engineering_id=(select file_name from gmms_raw_file where operator=groups and state='已领取') and work_procedure=                work_pro and     work_state=work_st;
        select * from gmms_galss_task where engineering_id=(select file_name from gmms_raw_file where operator=groups and state='已领取') and work_procedure=                work_pro and     work_state='等待中';
    elseif flags=2 then
        select * from gmms_galss_task_2 where work_state=work_st;
        select * from gmms_galss_task_2 where work_procedure=work_pro and work_state=work_st;
    else
        select * from gmms_raw_file_2 where work_state=work_st;
    end if;
  
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for ceshi_copy1
-- ----------------------------
DROP PROCEDURE IF EXISTS `ceshi_copy1`;
delimiter ;;
CREATE PROCEDURE `ceshi_copy1`()
BEGIN
    #ATAB 对此表的  单子删除重新添加
    DECLARE deletenum int DEFAULT 0;#删除数
    
    DECLARE count int DEFAULT 0;#删除数
    
    DECLARE tkcount int DEFAULT 0;#删除数
    DECLARE lckh varchar(255) DEFAULT '';
    
    select count(*) into deletenum from ATAB;
  if deletenum>0 then
        
        WHILE deletenum>count DO
            select gg into lckh from ATAB limit count,1;
            #是否已经开始任务
            select count(*) into tkcount from gmms_liuchengka where current_work_position!='创建' and main_liuchengka=lckh and is_single=1;
            if tkcount=0 then
                delete from gmms_liuchengka where main_liuchengka=lckh;
                call liuchengka_load_rel(lckh);
            end if;
            
      
            set count=count+1;
            set tkcount=0;
            set lckh='';
        END WHILE;
 
        
    end if;
    
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for Compound
-- ----------------------------
DROP PROCEDURE IF EXISTS `Compound`;
delimiter ;;
CREATE PROCEDURE `Compound`(in sendMessageHex varchar(255),in machineids BIGINT,out messagedate varchar(255))
BEGIN
    #复合台存储过程
    #找到当前机器标志位
    #查询机器逻辑表中对应的逻辑进行对应的步骤
    DECLARE machinedisposeids int DEFAULT 0;
    DECLARE dates varchar(255);
    DECLARE taskplc varchar(255);
    DECLARE taskmes varchar(255);
    DECLARE taskplc1 varchar(255);
    DECLARE taskmes1 varchar(255);
    DECLARE send_rankid BIGINT;
    DECLARE rankids varchar(255);
    DECLARE messagedates varchar(255) DEFAULT '';
    set messagedate=messagedates;
    
    select machine_type_id,work_id into @mtid,@work_groups from gmms_machine where id=machineids;
    
    
    select mf.flag into @请求标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='请求字';
    
    select mf.flag into @发送标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='发送字';
    
    set send_rankid = cast(@请求标志位 as UNSIGNED INTEGER)+1;
    set taskplc = substring(sendMessageHex,(cast(@请求标志位 as UNSIGNED INTEGER)*4)+19,4);
    set taskmes = substring(sendMessageHex,(cast(@发送标志位 as UNSIGNED INTEGER)*4)+19,4);
    set taskplc1 = substring(sendMessageHex,(cast(4 as UNSIGNED INTEGER)*4)+19,4);
    set taskmes1 = substring(sendMessageHex,(cast(20 as UNSIGNED INTEGER)*4)+19,4);
--      if machineids=67 then
--                     insert into aaaa(ddd) VALUES(99);
--              end if;
    
    set rankids = conv(substring(sendMessageHex,(cast(send_rankid as UNSIGNED INTEGER)*4)+19,4),16,10);
    SELECT rankids;
    select taskplc;
    select taskmes;
    select taskplc1;
    select taskmes1;
    
    #请求逻辑查询
    select count(*),md.id into @请求数量,@请求逻辑编号 from gmms_machine_dispose md join gmms_machine_type mt on md.machine_type_id=mt.id where md.machine_type_id=@mtid  and md.plc_font_type='请求字' and md.mes_font_type='发送字' and md.plc_font_value=taskplc and md.mes_font_value=taskmes;
    select @mtid; 
    select taskplc;
    select taskmes;
    #判断逻辑是否存在
    if  @请求数量=1 then
        
    select 1;
        #判断请求逻辑是否为空
        if @请求逻辑编号!=0 then
            set machinedisposeids=@请求逻辑编号;
            
        end if;
        
        #查询当前执行逻辑进行判断
        select logic,return_value,mes_font_value into @ExecutionLogic,@returnvalue,@mes_font_value from gmms_machine_dispose where id=machinedisposeids;
        select @ExecutionLogic;
        if @ExecutionLogic='任务请求' and rankids>0 then
                call CompoundSend(sendMessageHex,machineids,1,rankids,@returnvalue,@messagedate);
                set messagedate=@messagedate;
        elseif @ExecutionLogic='匹配失败' and rankids>0 then
                call CompoundSend(sendMessageHex,machineids,2,rankids,@returnvalue,@messagedate);
                set messagedate=@messagedate;
         elseif @ExecutionLogic='任务清空' then
                set dates=CONCAT(@returnvalue,"0000000000000000");
                select dates;
                call message(dates,'000a',@date);
                set messagedate=@date;
        else
                set messagedate='';
        end if;
        
    elseif taskplc1='0001' and taskmes1='0000' then
            set @Fhcount=null;
            select count(*) into @Fhcount from gmms_galss_task_2 where  work_procedure='钢化后复合'  and (work_state='正在工作' or work_state='复合失败') and groups=@work_groups;
            if (machineids=43 or machineids=67) and @Fhcount=0 then
            select machineids;
            select rankids;
            select @work_groups;
                select count(*),edg_width,edg_height,thickness,angle,marking_flag 
                into @counts,@width,@height,@thickness,@angle,@marking_flag from gmms_galss_task_2 
                where galss_id=rankids and work_state='待复合' and work_procedure='钢化后复合' and groups=@work_groups;
                select @counts;
                if @counts=1 then
                    #此处修改                    
                    if @angle=1 then 
                            select gang_hou_zhuan into @z_angle from gmms_dongzuo_table where gmms_dongzuo_table.number=@marking_flag;
                    else
                            select gang_hou_bu_zhuan into @z_angle from gmms_dongzuo_table where gmms_dongzuo_table.number=@marking_flag;
                    end if;
    
                    call intTo2ByteHex10_16_4(@width,@widths);
                    call intTo2ByteHex10_16_4(@height,@heights);
                    call intTo2ByteHex10_16_4(@thickness,@thicknesss);
                    call intTo2ByteHex10_16_4(@z_angle,@angles);
                    
                    if @heights is not null and @heights!='' and 
                         @widths is not null and @widths!='' and
                         @thicknesss is not null and @thicknesss!='' and
                         @angles is not null and @angles!=''     
                    then
                         if @angle=1 or @angle=3 then
                                set dates=CONCAT(@heights,@widths,@thicknesss,@angles,'000000000001');
                         else
                                set dates=CONCAT(@widths,@heights,@thicknesss,@angles,'000000000001');
                         end if;
                                call message(dates,'000e',@date);
                                set messagedate=@date;    
                                update gmms_galss_task_2 set work_state='正在工作' 
                                where  galss_id=rankids and work_state='待复合' and work_procedure='钢化后复合' and groups=@work_groups;
                              insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,@work_groups,NOW(),'发送任务',rankids,messagedate);    
                    end if;    
                    
                        -- 原程序开始
--                     update gmms_galss_task_2 set work_state='正在工作' where  galss_id=rankids and work_state='待复合' and work_procedure='钢化后复合' and groups=@work_groups;
--                     call intTo2ByteHex10_16_4(@width,@widths);
--                     call intTo2ByteHex10_16_4(@height,@heights);
--                     call intTo2ByteHex10_16_4(@thickness,@thicknesss);
--                     
--                     #此处修改
--                     
--                     if @angle=1 then 
--                         select gang_hou_zhuan into @z_angle from gmms_dongzuo_table where gmms_dongzuo_table.number=@marking_flag;
--                   else
--                             select gang_hou_bu_zhuan into @z_angle from gmms_dongzuo_table where gmms_dongzuo_table.number=@marking_flag;
--                     end if;
--                     
--                     #########
--                     
--                     call intTo2ByteHex10_16_4(@z_angle,@angles);
--                     if @angle=1 or @angle=3 then
--                         set dates=CONCAT(@heights,@widths,@thicknesss,@angles,'000000000001');
--                     else
--                         set dates=CONCAT(@widths,@heights,@thicknesss,@angles,'000000000001');
--                     end if;
--                     
--                     call message(dates,'000e',@date);
--                     set messagedate=@date;
--          原程序结束
                end if;
            end if;
        elseif taskplc1='0000' and taskmes1='0001' then
                set dates=CONCAT("0000000000000000000000000000");
                call message(dates,'000e',@date);
                set messagedate=@date;
    end if;
    if (machineids=64 or machineids=39) and (messagedate is null or messagedate='') then
        set @fuheid=null;
        select gt.id into @fuheid from gmms_machine as gm LEFT JOIN gmms_galss_task_2 as gt on gm.remarks=gt.id
        where gm.id=machineids and gt.id is not null and gt.work_state='复合失败';
        if @fuheid is not null then
            set dates=CONCAT('0000',"0000000000000000");
            call message(dates,'000a',@date);
            set messagedate=@date;
        else
            update gmms_machine set remarks=null    where id=machineids;
        end if;
    end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for Compoundmanual
-- ----------------------------
DROP PROCEDURE IF EXISTS `Compoundmanual`;
delimiter ;;
CREATE PROCEDURE `Compoundmanual`(in machineids BIGINT,in returnvalue varchar(255),out messagedate varchar(255))
BEGIN
    #手动复合存储过程(备用)
    DECLARE number int DEFAULT 0;
    DECLARE dates varchar(255);
    DECLARE messagedates varchar(255) DEFAULT '';
    set messagedate=messagedates;
    
    select machine_type_id,work_id into @mtid,@work_groups from gmms_machine where id=machineids;
    
    select file_name into @engineering_id from gmms_raw_file where operator=@work_groups and state='已领取';
    
    select flag into @flag from gmms_preprocessing_glass where groups=@work_groups;
    select @flag;
    
    if @flag>0 then
    
        select width,height,galss_id,thickness,drop_frame into @width,@heigth,@galss_id,@thickness,@drop_frame from gmms_galss_task where id=@flag and engineering_id=@engineering_id;
        select finsh_count into @counts from gmms_drop_frame where drop_frame=@drop_frame and groups=@work_groups;
        
        set number=@counts+1;    
        update gmms_galss_task set work_state='等待中',work_procedure='下片' where id=@flag and engineering_id=@engineering_id;
        
        update gmms_preprocessing_glass set statu='复合成功',glass_id=@galss_id,length=@width,width=@heigth,flag=0 where groups=@work_groups;
        
        select rank into @rank from gmms_galss_task where id=@flag and engineering_id=@engineering_id;
        
        select @rank;
        
        call intTo2ByteHex10_16_4(@rank,@ranks);
        call intTo2ByteHex10_16_4(@width,@widths);
        call intTo2ByteHex10_16_4(@heigth,@heigths);
        call intTo2ByteHex10_16_4(@thickness,@thicknesss);
        call intTo2ByteHex10_16_4(number,@number);
        select @ranks;
        set dates=CONCAT(returnvalue,@ranks,@widths,@heigths,@thicknesss,@number);
        select dates;
        call message(dates,'0014',@date);
        set messagedate=@date;
--     elseif     @flag=2 then
--         update gmms_preprocessing_glass set statu='匹配失败',flag=0 where id=1;
    end if;
                
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for Compounds
-- ----------------------------
DROP PROCEDURE IF EXISTS `Compounds`;
delimiter ;;
CREATE PROCEDURE `Compounds`()
BEGIN
    #Routine body goes here...
    #复合台程序
    
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for CompoundSend
-- ----------------------------
DROP PROCEDURE IF EXISTS `CompoundSend`;
delimiter ;;
CREATE PROCEDURE `CompoundSend`(in sendMessageHex varchar(255),in machineids BIGINT,in flags int,in rankid BIGINT,in returnvalue varchar(255),out messagedate varchar(255))
BEGIN
    #复合台请求存储过程
    #flag=1为复合成功,flag=2为复合失败
    #复合失败后界面上点击匹配成功,找到复合台机器表的备注字段绑定的玻璃编号
    #大于零则为绑定了玻璃编号,-1则为失败手动拿走,varchar的-1转换为int并不是-1
    DECLARE number int DEFAULT 0;
    DECLARE remarkss int;
    DECLARE ranks int;
    DECLARE widths int;
    DECLARE heigths int;
    DECLARE thicknesss int;
    DECLARE drop_frames int;
    DECLARE dates varchar(255);
    DECLARE messagedates varchar(255) DEFAULT '';
    
    DECLARE maxw int DEFAULT 0;
    DECLARE maxh int DEFAULT 0;
    DECLARE minw int DEFAULT 0;
    DECLARE minh int DEFAULT 0;
    DECLARE kaobian int DEFAULT 0;
    set messagedate=messagedates;
    
    select machine_type_id,work_id into @mtid,@work_groups from gmms_machine where id=machineids;
 
    
 
    if  (machineids=11 or machineids=21 or machineids=33) then
        select file_name into @engineering_id from gmms_raw_file where operator=@work_groups and state='已领取';
    
        select count(*) into @count from gmms_galss_task where work_procedure='复合' and (work_state='正在工作' or work_state='复合失败' ) and engineering_id=@engineering_id;
        set @count=1;
        if @count>0 then
        
        if flags=1 then
            
            if machineids=33 then
                #  一号线的特殊处理 33 
                select out_rank,width,height,thickness,drop_frame,processcard_id,stop_position into @rank,@width,@heigth,@thickness,@drop_frame,@processcard_id,kaobian from gmms_galss_task 
                where work_procedure='复合' and work_state='正在工作' and engineering_id=@engineering_id order by out_rank limit 1;
                #得到最小的 和最大的玻璃数据  判断往哪里靠边
                #select xiapianbiaoji into kaobian from gmms_liuchengka where liuchengka=@processcard_id;
                if kaobian<13 and kaobian>0 then
                    update gmms_galss_task set work_state='等待中',work_procedure='下片' where out_rank=rankid and engineering_id=@engineering_id;
                    set returnvalue=CONCAT(returnvalue,"0000");
                    call message(returnvalue,'000a',@date);
                    set messagedate=@date;
                    insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,"",NOW(),'发送复合确认任务0',IFNULL(kaobian,0),messagedate);
                elseif kaobian>12 and kaobian>0 then
                    update gmms_galss_task set work_state='等待中',work_procedure='下片' where out_rank=rankid and engineering_id=@engineering_id;
                    set returnvalue=CONCAT(returnvalue,"0001");
                    call message(returnvalue,'000a',@date);
                    set messagedate=@date;
                    insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,"",NOW(),'发送复合确认任务1',IFNULL(kaobian,0),messagedate);
                end if;
            else
                select out_rank,width,height,thickness,drop_frame,processcard_id into @rank,@width,@heigth,@thickness,@drop_frame,@processcard_id from gmms_galss_task where work_procedure='复合' and work_state='正在工作' and engineering_id=@engineering_id order by out_rank limit 1;
                select @rank;
                
                update gmms_galss_task set work_state='等待中',work_procedure='下片' where out_rank=rankid and engineering_id=@engineering_id;
                call message(returnvalue,'000a',@date);
                set messagedate=@date;
            end if;
        
    #复合失败    
        elseif flags=2 then
            set @flags=null;
            update gmms_galss_task set work_state='复合失败' where out_rank=rankid and work_procedure='复合' and engineering_id=@engineering_id;
            select remarks into @flags from gmms_machine where id=machineids;
            set remarkss=cast(@flags as UNSIGNED INTEGER);
            select remarkss;
            #手动匹配,判断是否绑定玻璃信息
            if remarkss>0 and remarkss<100000000 then
                if machineids=333 then
                    select width,height,galss_id,thickness,drop_frame into @width,@heigth,@galss_id,@thickness,@drop_frame from gmms_galss_task where id=remarkss and engineering_id=@engineering_id;
                    select finsh_count into @counts from gmms_drop_frame where drop_frame=@drop_frame and processcard_id=@processcard_id and groups=@work_groups;
        
                    set number=@counts+1;    
                    update gmms_galss_task set work_state='已完成',work_procedure='下片',finsh_time=now(),work_procedure_number=500,stop_rank=number where id=remarkss and engineering_id=@engineering_id;
                    update gmms_machine set remarks=null where id=machineids;
                else
                    select stop_position into kaobian from gmms_galss_task 
                    where work_procedure='复合' and id=remarkss order by out_rank limit 1;
                    update gmms_galss_task set work_state='等待中',work_procedure='下片' where id=remarkss and engineering_id=@engineering_id;
                    update gmms_machine set remarks=null where id=machineids;
                end if;
                
        
        
--                 select rank into @rank from gmms_galss_task where id=remarkss;
--         
--                 call intTo2ByteHex10_16_4(@rank,@ranks);
--                 call intTo2ByteHex10_16_4(@width,@widths);
--                 call intTo2ByteHex10_16_4(@heigth,@heigths);
--                 call intTo2ByteHex10_16_4(@thickness,@thicknesss);
--                 call intTo2ByteHex10_16_4(number,@number);
--                 select @ranks;
--                 set dates=CONCAT(returnvalue,@ranks,@widths,@heigths,@thicknesss,@number);
--                 select dates;
                
                    if kaobian<13 and kaobian>0 then
                        set returnvalue=CONCAT(returnvalue,"0000");
                        call message(returnvalue,'000a',@date);
                        set messagedate=@date;
                        insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,"",NOW(),'发送复合手动确认任务0',IFNULL(kaobian,0),messagedate);
                    elseif kaobian>12 and kaobian>0 then
                        set returnvalue=CONCAT(returnvalue,"0001");
                        call message(returnvalue,'000a',@date);
                        set messagedate=@date;
                        insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,"",NOW(),'发送复合手动确认任务1',IFNULL(kaobian,0),messagedate);
                    end if;
            #人工拿走
            elseif remarkss>100000000 then
                update gmms_galss_task set work_state='破损' where work_state='复合失败' and engineering_id=@engineering_id;
                update gmms_machine set remarks='' where id=machineids;
                call message('0002','000a',@date);
                set messagedate=@date;
            else
                set messagedate='';
            end if;
        end if;    
        end if;
    
    #钢化前复合台
    #select count(*) into @a from gmms_galss_task_2 where work_procedure='钢化前复合' and (work_state='正在工作' or work_state='复合失败' ) and groups=@work_groups;
    elseif machineids=39 or machineids=43 or machineids=64 or machineids=67 then
        if machineids=39 or machineids=64 then
            if flags=1 then
                update gmms_galss_task_2 set work_state='等待中',work_procedure='钢化前摆片' where  work_state='正在工作' and work_procedure='钢化前复合' and groups=@work_groups and galss_id=rankid;
                    
                    call intTo2ByteHex10_16_4(rankid,@ranks);
                    set dates=CONCAT(@returnvalue,@ranks);
                    call message(dates,'000a',@date);
                    set messagedate=@date;
                
                    insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,@work_groups,NOW(),'复合成功',rankid,messagedate);
            #复合失败    
            elseif flags=2 then
                if (select id from aaaa where MachineName=machineids order by data1 desc limit 1)=rankid then
                    insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,@work_groups,NOW(),'复合失败',rankid,messagedate);
                end if;            
                set @flags=null;
                select rankid;
                update gmms_galss_task_2 set work_state='复合失败' where  work_procedure='钢化前复合' and groups=@work_groups and galss_id=rankid;
                select remarks into @flags from gmms_machine where id=machineids;
                set remarkss=cast(@flags as UNSIGNED INTEGER);
                select remarkss;
                #手动匹配,判断是否绑定玻璃信息
                
                if remarkss>0 and remarkss<100000000 then
                    select width,height,galss_id,thickness,drop_frame into @width,@heigth,@galss_id,@thickness,@drop_frame from gmms_galss_task_2 where id=remarkss ;
                    #11.17修改 加 and work_state='复合失败' and work_procedure='钢化前复合'
                    update gmms_galss_task_2 set work_state='等待中',work_procedure='钢化前摆片' 
                    where id=remarkss and work_state='复合失败' and work_procedure='钢化前复合' and groups=@work_groups;
                    update gmms_machine set remarks=null    where id=machineids;
                    
                    call intTo2ByteHex10_16_4(rankid,@ranks);
                    set dates=CONCAT(@returnvalue,@ranks);
                    call message(dates,'000a',@date);
                    set messagedate=@date;
                #人工拿走
                elseif remarkss>100000000 then
                    #11.17修改 加 and work_procedure='钢化前复合'
                    update gmms_galss_task_2 set work_state='破损' where work_state='复合失败' and galss_id=rankid and groups=@work_groups and work_procedure='钢化前复合';
                    update gmms_machine set remarks='' where id=machineids;
                    call intTo2ByteHex10_16_4(rankid,@ranks);
                    set dates=CONCAT('0002',@ranks);
                    call message(dates,'000a',@date);
                    set messagedate=@date;
                else
                    set messagedate='';
                end if;
            end if;    
        
        
        #钢化后复合台
        elseif machineids=43 or machineids=67 then
            if flags=1 then                    
--     原程序update gmms_galss_task_2 set work_state='等待中',work_procedure='钢化后下片' where  work_state='正在工作' and work_procedure='钢化后复合' and groups=@work_groups ORDER BY fine_throwing limit 1;
                    if rankid is not null then
                        update gmms_galss_task_2 set work_state='等待中',work_procedure='钢化后下片' 
                        where  work_state='正在工作' and work_procedure='钢化后复合' and groups=@work_groups and galss_id=rankid ORDER BY fine_throwing limit 1;
                    end if;
--                     if rankid is not null then
--                         update gmms_galss_task_2 set work_state='等待中',work_procedure='钢化后下片' where  work_state='正在工作' and work_procedure='钢化后复合' and groups=@work_groups  ORDER BY fine_throwing limit 1;
--                     else
--                         update gmms_galss_task_2 set work_state='等待中',work_procedure='钢化后下片' where  work_state='正在工作' and work_procedure='钢化后复合' and groups=@work_groups and galss_id=rankid ORDER BY fine_throwing limit 1;
--                     end if;
                    
                    call intTo2ByteHex10_16_4(rankid,@ranks);
                    set dates=CONCAT(@returnvalue,@ranks);
                    call message(dates,'000a',@date);
                    set messagedate=@date;
                  insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,@work_groups,NOW(),'复合成功',rankid,messagedate);    
 
            #复合失败    
            elseif flags=2 then
                set @flags=null;
                select rankid;
                select count(*) into @shibai2 from gmms_galss_task_2 
                where work_state='复合失败' and  work_procedure='钢化后复合' and groups=@work_groups and galss_id=rankid;
                select remarks into @flags from gmms_machine where id=machineids;
                if @shibai2<1 then
                #添加线路区分修改  
                    update gmms_galss_task_2 set work_state='复合失败' where work_state='正在工作' and  work_procedure='钢化后复合' and groups=@work_groups and galss_id=rankid;
                  
                  insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,@work_groups,NOW(),'复合失败',rankid,messagedate);
                end if;
                
                set remarkss=cast(@flags as UNSIGNED INTEGER);
                select remarkss;
                #手动匹配,判断是否绑定玻璃信息
                if remarkss>0 and remarkss<100000000 then
                    select width,height,galss_id,thickness,drop_frame into @width,@heigth,@galss_id,@thickness,@drop_frame from gmms_galss_task_2 where id=remarkss ;
                    update gmms_machine set remarks=null    where id=machineids;
                    #11.17添加  and work_state='正在工作' and  work_procedure='钢化后复合'
                    update gmms_galss_task_2 set work_state='等待中',work_procedure='钢化后下片' where id=remarkss and work_state='复合失败' and  work_procedure='钢化后复合';
                                
                    call intTo2ByteHex10_16_4(rankid,@ranks);
                    set dates=CONCAT(@returnvalue,@ranks);
                    call message(dates,'000a',@date);
                    set messagedate=@date;
                    insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,@work_groups,NOW(),'手动匹配',rankid,messagedate);
                #人工拿走
                elseif remarkss>100000000 then
                #11.17添加  and work_state='正在工作' and  work_procedure='钢化后复合'
                    update gmms_galss_task_2 set work_state='破损' where work_state='复合失败' and galss_id=rankid and groups=@work_groups  and  work_procedure='钢化后复合';
                    update gmms_machine set remarks='' where id=machineids;
                    call intTo2ByteHex10_16_4(rankid,@ranks);
                    set dates=CONCAT('0002',@ranks);
                    call message(dates,'000a',@date);
                    set messagedate=@date;
                    insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,@work_groups,NOW(),'拿走破损',rankid,messagedate);
                else
                    set messagedate='';
                end if;
            end if;    
            end if;
    end if;
    
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for create_empty_raw_file
-- ----------------------------
DROP PROCEDURE IF EXISTS `create_empty_raw_file`;
delimiter ;;
CREATE PROCEDURE `create_empty_raw_file`(in type varchar(30),out id bigint,out gongcheng varchar(30))
BEGIN
    #Routine body goes here...
    DECLARE  gc varchar(30);
  DECLARE last varchar(30);
    DECLARE tmp int;
      set gc=concat("MB",DATE_FORMAT(now(),"%y%m%d"),'%');
         set last=null;
        SELECT file_name into last from  gmms_raw_file where file_name like gc order by file_name DESC LIMIT 1; 
            
         if last is not null then 
              set @c=    substring(last,9);
                set tmp=cast(@c as UNSIGNED);
              set tmp=tmp+1;
                set @ch=cast(tmp as char);
                set @chl=length(@ch);
                select @chl,@ch,tmp,@c;
                if @chl=1 then
                  set gc=concat("MB",DATE_FORMAT(now(),"%y%m%d"),'00',@ch);
                end if;
                if @chl=2 then  
                  set gc=concat("MB",DATE_FORMAT(now(),"%y%m%d"),'0',@ch);
                end if;
                if @chl=3 then
                  set gc=concat("MB",DATE_FORMAT(now(),"%y%m%d"),@ch);
                end if;
                
         else 
           set gc=concat("MB",DATE_FORMAT(now(),"%y%m%d"),'001');
 
         end if;
         insert into gmms_raw_file (file_name,state,operator,create_time) 
            values (gc,'已下发',0,now());
         set gongcheng=gc;
         SET id=LAST_INSERT_ID();
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for create_gongchengorder
-- ----------------------------
DROP PROCEDURE IF EXISTS `create_gongchengorder`;
delimiter ;;
CREATE PROCEDURE `create_gongchengorder`(in gongcheng varchar(50))
BEGIN
    #Routine body goes here...
         INSERT into gmms_raw_file(thickness,color,width,height,count)   (SELECT thickness,color,width,height,count from gongcheng_raw where gc_name=gongcheng and state=0);
         UPDATE gongcheng_raw SET state=1 where gc_name=gongcheng;
        
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for create_log_records
-- ----------------------------
DROP PROCEDURE IF EXISTS `create_log_records`;
delimiter ;;
CREATE PROCEDURE `create_log_records`(in gongcheng varchar(50),in line int)
BEGIN
--      call    create_log_records_pattern(gongcheng,line);
--          call    create_log_records_segment(gongcheng,line,"切磨线");
--          call    create_log_records_segment(gongcheng,null,"钢化线");
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for create_log_records_pattern
-- ----------------------------
DROP PROCEDURE IF EXISTS `create_log_records_pattern`;
delimiter ;;
CREATE PROCEDURE `create_log_records_pattern`(in gongcheng varchar(50),in _line int)
BEGIN
    #Routine body goes here...
        declare done int default 0;
    declare w double;
    declare h double;
    DECLARE gid BIGINT;
    declare _work_segment varchar(50);
    DECLARE cr_work_name varchar(50);
  declare cur cursor for
              SELECT id,raw_width,raw_height from gmms_pattern_task_buffer where engineering_id=gongcheng;
    declare cur1 cursor for
              SELECT work_name from gmms_glass_log_config where segment=_work_segment group by work_name;
 
                DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1;
    set _work_segment="原片仓储";
    set  @zid=null;
    SELECT id into @zid  from gmms_glass_log_main  where gongchenghao=gongcheng;
   if @zid is null then 
         INSERT INTO gmms_glass_log_main (
                segment
                ,gongchenghao
                ,create_time
                ,line
                ,state
                ) values (_work_segment,gongcheng,now(),_line,0);
            SET @zid=LAST_INSERT_ID();
     end if;
     
     SET @tmp=0;
     select count(*) into @tmp from gmms_glass_log where main_id=@zid and segment_name=_work_segment;
     set done=0;
    if @tmp=0 then 
            
                open cur;
              loop1:loop 
                    FETCH cur into gid,w,h;
                    if done=1 then 
                                    set @cccc=@cccc+1000;
                       LEAVE loop1;
                     end if;
                 set @tmp=w*h/1000/1000;
                 
                 INSERT INTO gmms_glass_log (
main_id
,glass_id
,segment_name
,work_name
,line
,begin_time
,end_time
,`status`
,parent_id
,area
)
values (@zid,gid, _work_segment,null,_line,null,null,0,null,@tmp);
                end loop loop1;
                close cur;
    set done=0;
    open cur1;
    
     loop2:loop 
                    FETCH cur1 into cr_work_name;
                    if done=1 then 
                       LEAVE loop2;
                     end if;
                        set @crw=cr_work_name;
                        set @csg=_work_segment;
                 INSERT INTO gmms_glass_log (
main_id
,glass_id
,segment_name
,work_name
,line
,begin_time
,end_time
,`status`
,parent_id
,area)
select 
main_id
,glass_id
,@csg
,@crw
,line
,null
,null
,0
,id
,area
 from  gmms_glass_log where main_id=@zid and parent_id is null and segment_name=_work_segment;
    end loop loop2;
    close cur1;
    end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for create_log_records_segment
-- ----------------------------
DROP PROCEDURE IF EXISTS `create_log_records_segment`;
delimiter ;;
CREATE PROCEDURE `create_log_records_segment`(in gongcheng varchar(50),in _line int,in _work_segment varchar(50))
BEGIN
    #Routine body goes here...
    declare done int default 0;
    declare w double;
    declare h double;
    DECLARE gid BIGINT;
    DECLARE cr_work_name varchar(50);
  declare cur cursor for
              SELECT id,edg_width,edg_height from gmms_galss_task_buffer where engineering_id=gongcheng;
    declare cur1 cursor for
              SELECT work_name from gmms_glass_log_config where segment=_work_segment group by work_name;
 
                DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1;
            
    set  @zid=null;
    SELECT id into @zid  from gmms_glass_log_main  where gongchenghao=gongcheng;
   if @zid is null then 
         INSERT INTO gmms_glass_log_main (
                segment
                ,gongchenghao
                ,create_time
                ,line
                ,state
                ) values (_work_segment,gongcheng,now(),_line,0);
            SET @zid=LAST_INSERT_ID();
     end if;
     
     SET @tmp=0;
     select count(*) into @tmp from gmms_glass_log where main_id=@zid and segment_name=_work_segment;
     set done=0;
    if @tmp=0 then 
            
                open cur;
              loop1:loop 
                    FETCH cur into gid,w,h;
                    if done=1 then 
                                    set @cccc=@cccc+1000;
                       LEAVE loop1;
                     end if;
                 set @tmp=w*h/1000/1000;
                                
                 INSERT INTO gmms_glass_log (
main_id
,glass_id
,segment_name
,work_name
,line
,begin_time
,end_time
,`status`
,parent_id
,area
)
values (@zid,gid, _work_segment,null,_line,null,null,0,null,@tmp);
                end loop loop1;
                close cur;
    set done=0;
    open cur1;
    
     loop2:loop 
                    FETCH cur1 into cr_work_name;
                    if done=1 then 
                       LEAVE loop2;
                     end if;
                        set @crw=cr_work_name;
                        set @csg=_work_segment;
                 INSERT INTO gmms_glass_log (
main_id
,glass_id
,segment_name
,work_name
,line
,begin_time
,end_time
,`status`
,parent_id
,area)
select 
main_id
,glass_id
,@csg
,@crw
,line
,null
,null
,0
,id
,area
 from  gmms_glass_log where main_id=@zid and parent_id is null and segment_name=_work_segment;
    end loop loop2;
    close cur1;
    end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for deleteshujujilu
-- ----------------------------
DROP PROCEDURE IF EXISTS `deleteshujujilu`;
delimiter ;;
CREATE PROCEDURE `deleteshujujilu`()
BEGIN
 
delete from gmms_identify_error_details where  times<now() - interval 14 day;
 
delete from gmms_edg_perimeter where start_time<now() - interval 90 day;
 
delete from gmms_shelf_task where task_state='已完成' and finsh_time<now() - interval 14 day;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for DoEvent
-- ----------------------------
DROP PROCEDURE IF EXISTS `DoEvent`;
delimiter ;;
CREATE PROCEDURE `DoEvent`(in iswrite int,in id int,in msg varchar(255))
BEGIN
--  SELECT 'DDDD',id;
    #Routine body goes here...
        if id=10 then 
          if iswrite=0 then
                    call record_event("加速台请求",1,msg,id,0,0,false);
             else 
                    call record_event("加速台回复",101,msg,id,10,0,true);
             end if;
        end if;
        if id=11 then 
            if iswrite=0 then
                    call record_event("复核台请求",1,1msg,id,0,0,false);
             else 
                    call record_event("复合台回复",101,msg,id,10,0,true);
             end if;
        end if;
 
        if id=17 then 
        
            if iswrite=0 then
                SELECT 17;
                    call record_event("下片台请求",1,msg,17,0,0,false);
                    call record_event("下片台请求",2,msg,17,6,6,false);
             else 
                    call record_event("下片台汇报",101,msg,17,10,0,true);
                    call record_event("下片台确认",102,msg,17,24,0,true);
             end if;
        end if;
        
        
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for dongzuo_get_number
-- ----------------------------
DROP PROCEDURE IF EXISTS `dongzuo_get_number`;
delimiter ;;
CREATE PROCEDURE `dongzuo_get_number`(glass_id bigint,line int,out _number int)
BEGIN
    #Routine body goes here...
    #Routine body goes here...
        declare m_f   int DEFAULT NULL;
        declare cl  varchar(50) default null;
        declare md varchar(10) default null;
        set _number=null;
        SELECT color,marking_flag into cl ,m_f from gmms_galss_task_buffer where id=glass_id;
    
        #SELECT m_f,cl;
        set md="";
        if m_f is not null then 
            if cl='白玻' or cl='超白' or cl='C' then 
              set  md="0";
             else
              set  md="1";
            end if;
        
          if line=1 then 
               set md=concat(md,"1");
                 
            else 
             set md=concat(md,"0");
            end if;
        
        if m_f=1 then 
             set md=CONCAT(md,"1");
             else         
             if m_f<>0 then 
               set md=CONCAT(md,"2");
             end if;
         end if;
     
         
             
             
             
            # select md;
             select number into _number from gmms_dongzuo_table where `mode`=md;
             
                 if      m_f=0 then 
 
            set _number= 15;
        end if;
             
             if m_f>=10 then 
        
            set _number=m_f;
            end if;
        end if;
        
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for dongzuo_get_number_copy1
-- ----------------------------
DROP PROCEDURE IF EXISTS `dongzuo_get_number_copy1`;
delimiter ;;
CREATE PROCEDURE `dongzuo_get_number_copy1`(cl varchar(50),m_f int ,_line int,out _number int)
BEGIN
    #Routine body goes here...
    #Routine body goes here...
     
        declare db int;
        declare shu int;
        declare biao int;
        declare le int;
        set db=0;
        set shu=0;
        set biao=0;
        set le=0;
        set _number=null;
        
        if _line<>1 then 
           set _line=0;
        end if;
            if cl='白玻' or cl='超白' or cl='C' or cl='c' or cl='C(DB)'  then 
              set  le=0;
             else
              set  le=1;
              set    _line=0;
            end if;
        
        
        set @bit1=m_f mod 2;
        set @bit2=(m_f div 2) mod 2;
        set @bit3=(m_f div 4) mod 2;
        if @bit3=1 then 
             set db=1;
                 set shu=@bit1;
         else 
             if @bit2=1 then 
                    set db=2;
                        set shu=@bit1;
                    else    
                            #不打标
                            set _line=0;
                            set shu=0;
                            set db=0;
                 end if;
        end if;
 
        
        if le=0 then 
                if db=2 then 
                   set db=3;
                end if;
        else
             if db=1 then 
                 set db=2;
             else 
                 set db=0;
             end if;
        end if;
        
        if db=0 then 
           set _line=0;
             set shu=0;
             set db=0;
        end if;
        
        
     if m_f>20 then 
            set _number=m_f;
    else
        if (m_f is null or m_f<0 or m_f>7) AND false  then 
        set _number=16;     
      else
           #low-e不钢化
          if le=1 and @bit3=0 then 
                set _number=31;
            else
                select id into _number from gmms_biao_table where biao_type=db and fangxiang_type=shu and line=_line and color_type=le  and id<33;
                 end if;
       end if;
     end if;
        
        #select * from gmms_dongzuo_table_1 where number=_number;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for dongzuo_get_number_ex
-- ----------------------------
DROP PROCEDURE IF EXISTS `dongzuo_get_number_ex`;
delimiter ;;
CREATE PROCEDURE `dongzuo_get_number_ex`(cl varchar(50),m_f int,line int,out _number int)
BEGIN
    #Routine body goes here...
    #Routine body goes here...
    
        declare md varchar(10) default null;
        set _number=null;
 
        #SELECT m_f,cl;
        set md="";
    
        if m_f is not null then 
            if cl='白玻' or cl='超白' or cl='C' then 
              set  md="0";
             else
              set  md="1";
            end if;
    
          if line=1 then 
               set md=concat(md,"1");
                 
            else 
             set md=concat(md,"0");
            end if;
            
        if m_f=1 then 
             set md=CONCAT(md,"1");
             else         
             if m_f<>0 then 
               set md=CONCAT(md,"2");
             end if;
         end if;
     
         
    
             
 
             select number into _number from gmms_dongzuo_table where `mode`=md;
             
                 if      m_f=0 then 
 
            set _number= 15;
        end if;
             
             if m_f>=10 then 
        
            set _number=m_f;
            end if;
        end if;
        
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for dongzuo_update_marking_flag
-- ----------------------------
DROP PROCEDURE IF EXISTS `dongzuo_update_marking_flag`;
delimiter ;;
CREATE PROCEDURE `dongzuo_update_marking_flag`(gc varchar(50),in _line int)
BEGIN
  # 用于更新动作标记
    #Routine body goes here...
    DECLARE cid long ;
    declare cmk int;
    DECLARE done1 int;
    DECLARE cl varchar(100);
    DECLARE cur CURSOR FOR
 
    SELECT id,marking_flag,color FROM gmms_galss_task_buffer where  engineering_id=gc;
    DECLARE CONTINUE HANDLER FOR NOT FOUND SET done1=1;
    set done1=0;
    open cur;
    set @kkk=0;
    loop1 :loop
      set cmk=null;
        FETCH cur into cid,cmk,cl;
        if done1=1 then 
         LEAVE loop1;
     end if;
     
 
        IF cmk is null then 
                update gmms_galss_task set marking_flag=15 where id=cid;
                update gmms_galss_task_buffer set marking_flag_ex=15 where id=cid;
        elseif cmk >32 then -- 打标混排新增-2023.07.07
                update gmms_galss_task set marking_flag=cmk where id=cid;
                update gmms_galss_task_buffer set marking_flag_ex=cmk where id=cid;
        else
          call dongzuo_get_number_copy1(cl,cmk,_line,@kkkk);
            #call dongzuo_get_number_ex(cl,cmk,_line,@kkkk);
            if @kkkk is null then 
            set @kkkk=15;
            end if;
            update gmms_galss_task set marking_flag=@kkkk where id=cid;
          update gmms_galss_task_buffer set marking_flag_ex=@kkkk where id=cid;
        end if;
    end loop loop1;
    close cur;
    
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for d_dapingxianshi1
-- ----------------------------
DROP PROCEDURE IF EXISTS `d_dapingxianshi1`;
delimiter ;;
CREATE PROCEDURE `d_dapingxianshi1`()
BEGIN
    #Routine body goes here...
 
    #原片仓储,半成品仓储架子
 
    select count(*) into @shelf_rack1 from gmms_shelf_rack where state='空闲';
    select count(*) into @shelf_rack2 from gmms_shelf_rack where state='使用中' or state='正在使用';
    
    select count(*) into @shelf_rack3 from gmms_shelf_rack_2 where processcard_id is null;
    select count(*) into @shelf_rack4 from gmms_shelf_rack_2 where processcard_id is not null;
 
select @shelf_rack2,@shelf_rack1,@shelf_rack4,@shelf_rack3;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for d_dapingxianshi13
-- ----------------------------
DROP PROCEDURE IF EXISTS `d_dapingxianshi13`;
delimiter ;;
CREATE PROCEDURE `d_dapingxianshi13`()
BEGIN
    #Routine body goes here...
    DECLARE i int DEFAULT 0;
    DECLARE shijian1 varchar(255);
    DECLARE shijian2 varchar(255);
    DECLARE shijian3 varchar(255);
 
drop table if EXISTS  tabletmp_table1;
 
create temporary table tabletmp_table1 (riqi VARCHAR(255) NOT NULL);
while i<14 do
    set shijian2= subdate(date_format( now(), '%Y-%m-%d' ),i);
    insert into tabletmp_table1(riqi) values(shijian2);
    set shijian1=CONCAT('%',@shijian,'%');
 
    set i=i+1;
end while;
set shijian3=subdate(date_format( now(), '%Y-%m-%d' ),14);
 
 
-- select ifnull(max(tag5)-min(tag5),0),ifnull(max(tag6)-min(tag6),0),ifnull(max(tag7)-min(tag7),0),ifnull(max(tag4)-min(tag4),0),ifnull(max(tag9)-min(tag9),0),ifnull(max(tag20)-min(tag20),0),ifnull(max(tag19)-min(tag19),0),ifnull(max(tag13)-min(tag13),0) from tabletmp_table1 tt left join  gmms_data.dianliang_view dl  on tt.riqi=date(dl.mydatetime) and dl.mydatetime>shijian3 group by tt.riqi;
select max(tag5)-min(tag5),max(tag6)-min(tag6),max(tag7)-min(tag7),max(tag4)-min(tag4),max(tag9)-min(tag9),max(tag20)-min(tag20),max(tag19)-min(tag19),max(tag13)-min(tag13) from tabletmp_table1 tt left join  gmms_data.dianliang_view dl  on tt.riqi=date(dl.mydatetime) and dl.mydatetime>shijian3 group by tt.riqi;
 
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for d_dapingxianshi14
-- ----------------------------
DROP PROCEDURE IF EXISTS `d_dapingxianshi14`;
delimiter ;;
CREATE PROCEDURE `d_dapingxianshi14`()
BEGIN
    #Routine body goes here...
    #半圆
    DECLARE i int DEFAULT 0;
    DECLARE shijian1 varchar(255);
    DECLARE shijian2 varchar(255);
    DECLARE shijian3 varchar(255);
    DECLARE posunfengzhi varchar(255);
    DECLARE posunshiji varchar(255);
    
    DECLARE dainhaofengzhi varchar(255);
    DECLARE dainhaoshiji varchar(255);
    
    DECLARE chanliangfengzhi varchar(255);
    DECLARE chanliangshiji varchar(255);
 
set shijian1= date_format( now(), '%Y-%m-%d' );
set shijian2= subdate(date_format( now(), '%Y-%m-%d' ),14);
 
 
select sum(peak_value*14) into posunfengzhi from gmms_peak_value where type='破损';
 
select sum(peak_value*14) into dainhaofengzhi from gmms_peak_value where type='电耗';
 
select sum(peak_value*14) into chanliangfengzhi from gmms_peak_value where type='产量';
 
 
select ifnull(round(sum(gt.width*gt.height/1000000),2),0) into posunshiji from e_pierceds ep left join gmms_galss_task_buffer gt on ep.glass_id=gt.id  where  create_time>=shijian2 and create_time<shijian1;
 
 
select ifnull(max(tag5+tag6+tag7+tag4+tag9+tag20+tag2+tag13)-min(tag5+tag6+tag7+tag4+tag9+tag20+tag2+tag13),0) into dainhaoshiji from gmms_data.dianliang_view dl where dl.mydatetime >=shijian2 and dl.mydatetime<shijian1;
 
select ifnull(round(sum((width*height)/1000000),2),0) into @chanliangshiji1 from gmms_galss_task_stock where finsh_time>=shijian2 and finsh_time<shijian1;
select ifnull(round(sum((width*height)/1000000),2),0) into @chanliangshiji2 from E_record_tempering where create_time>=shijian2 and create_time<shijian1;
select ifnull(round(sum((width*height)/1000000),2),0) into @chanliangshiji3 from E_record_hollow where create_time>=shijian2 and create_time<shijian1;
 
set @zongchangliang =@chanliangshiji1+@chanliangshiji2+@chanliangshiji3;
 
 
select posunfengzhi,posunshiji,dainhaofengzhi,dainhaoshiji,chanliangfengzhi,@zongchangliang;
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for d_dapingxianshi15
-- ----------------------------
DROP PROCEDURE IF EXISTS `d_dapingxianshi15`;
delimiter ;;
CREATE PROCEDURE `d_dapingxianshi15`()
BEGIN
    #Routine body goes here...
    #Routine body goes here...
        #冷加工总产量图
 
#Routine body goes here...
    DECLARE i int DEFAULT 0;
    DECLARE shijian1 varchar(255);
    DECLARE shijian2 varchar(255);
    DECLARE shijian3 varchar(255);
 
 
drop table if EXISTS  tabletmp_table2;
create temporary table tabletmp_table2 (riqi VARCHAR(255) NOT NULL);
while i<14 do
    set shijian2= subdate(date_format( now(), '%Y-%m-%d' ),i);
    insert into tabletmp_table2(riqi) values(shijian2);
    set shijian1=CONCAT('%',@shijian,'%');
 
    set i=i+1;
end while;
set shijian3=subdate(date_format( now(), '%Y-%m-%d' ),14);
 
 
select sum(ifnull((round(gc.width*gc.height/1000000,2)*gc.pieces),0)) as qiege from 
(select ss.mobian,ss.ganghua,ss.riqi,sum(ifnull(round(erh.width*erh.height/1000000,2),0)) as zhongkong from
(select aa.riqi,c as mobian,sum(ifnull(round(ert.width*ert.height/1000000,2),0)) as ganghua  from
(select riqi,sum(ifnull(round(gr.width*gr.height/1000000,2),0)) as c
from tabletmp_table2 tt 
left join gmms_galss_task_stock gr on tt.riqi=date(gr.finsh_time) and gr.finsh_time>shijian3 left join gmms_raw_file rf on rf.file_name=gr.engineering_id and rf.create_time>shijian3 group by tt.riqi) as aa 
left join E_record_tempering ert on aa.riqi=date(ert.create_time) and ert.create_time>shijian3 group by aa.riqi) ss 
left join E_record_hollow erh on ss.riqi=date(erh.create_time) and erh.create_time>shijian3 group by ss.riqi) jj
left join gmms_cutmanage gc on jj.riqi=date(gc.statrtime) and gc.statrtime>shijian3 group by jj.riqi;
 
 
 
 
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for d_dapingxianshi15_1
-- ----------------------------
DROP PROCEDURE IF EXISTS `d_dapingxianshi15_1`;
delimiter ;;
CREATE PROCEDURE `d_dapingxianshi15_1`()
BEGIN
    #Routine body goes here...
    #Routine body goes here...
        #冷加工总产量图
 
#Routine body goes here...
    DECLARE i int DEFAULT 0;
    DECLARE shijian1 varchar(255);
    DECLARE shijian2 varchar(255);
    DECLARE shijian3 varchar(255);
 
 
drop table if EXISTS  tabletmp_table2;
create temporary table tabletmp_table2 (riqi VARCHAR(255) NOT NULL);
while i<14 do
    set shijian2= subdate(date_format( now(), '%Y-%m-%d' ),i);
    insert into tabletmp_table2(riqi) values(shijian2);
    set shijian1=CONCAT('%',@shijian,'%');
 
    set i=i+1;
end while;
set shijian3=subdate(date_format( now(), '%Y-%m-%d' ),14);
 
 
select sum(ifnull(gc.pieces,0)) as qiege from 
(select ss.mobian,ss.ganghua,ss.riqi,if(erh.glass_id is null,0,count(*)) as zhongkong from
(select aa.riqi,c as mobian,if(ert.glass_id is null,0,count(*)) as ganghua  from
(select riqi,if(gr.id is null,0,count(*)) as c
from tabletmp_table2 tt 
left join gmms_galss_task_stock gr on tt.riqi=date(gr.finsh_time) and gr.finsh_time>shijian3 left join gmms_raw_file rf on rf.file_name=gr.engineering_id and rf.create_time>shijian3 group by tt.riqi) as aa 
left join E_record_tempering ert on aa.riqi=date(ert.create_time) and ert.create_time>shijian3 group by aa.riqi) ss 
left join E_record_hollow erh on ss.riqi=date(erh.create_time) and erh.create_time>shijian3 group by ss.riqi) jj
left join gmms_cutmanage gc on jj.riqi=date(gc.statrtime) and gc.statrtime>shijian3 group by jj.riqi;
 
 
 
 
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for d_dapingxianshi2
-- ----------------------------
DROP PROCEDURE IF EXISTS `d_dapingxianshi2`;
delimiter ;;
CREATE PROCEDURE `d_dapingxianshi2`()
BEGIN
    #Routine body goes here...
    #原片仓储调拨记录
    DECLARE i int DEFAULT 0;
    DECLARE shijian1 varchar(255);
    DECLARE shijian2 varchar(255);
 
drop table if EXISTS  tabletmp_table;
 
create temporary table tabletmp_table (riqi VARCHAR(255) NOT NULL);
while i<14 do
    set shijian2= subdate(date_format( now(), '%Y-%m-%d' ),i);
    insert into tabletmp_table(riqi) values(shijian2);
    set shijian1=CONCAT('%',@shijian,'%');
 
    set i=i+1;
end while;
select sum(case when type="进库" then round((width*height)/1000000,2) else 0 end),round(concat('-',sum(case when type="退库" then width*height/1000000  else 0 end)),2) from tabletmp_table tt left join gmms_rank gr on tt.riqi=date(gr.createtime) group by tt.riqi;
 
 
-- select sum(case when type="进库" then 1 else 0 end),round(concat('-',sum(case when type="退库" then 1 else 0 end)),2) from tabletmp_table tt left join gmms_rank gr on tt.riqi=date(gr.createtime) group by tt.riqi;
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for d_dapingxianshi3
-- ----------------------------
DROP PROCEDURE IF EXISTS `d_dapingxianshi3`;
delimiter ;;
CREATE PROCEDURE `d_dapingxianshi3`()
BEGIN
    #Routine body goes here...
    #破损数据
    
        #Routine body goes here...
    #破损数据
    DECLARE shijian1 varchar(255);
    DECLARE shijian2 varchar(255);
    
    set shijian1=CONCAT('%',date_format( now(), '%Y-%m-%d' ),'%');
 
select CAST(sum(galssmeasure) as UNSIGNED) into @daijiagong1 from gmms_raw_file where state='已下发' and file_name like '%P%';
-- select ifnull(CAST(sum(galssmeasure) as UNSIGNED),0) into @yijiagong1 from  gmms_raw_file where state='已完成' and operator=1 and file_name like '%P%' and receive_time like shijian1; 
-- select ifnull(CAST(sum(galssmeasure) as UNSIGNED),0) into @yijiagong2 from  gmms_raw_file where state='已完成' and operator=2 and file_name like '%P%' and receive_time like shijian1; 
-- select ifnull(CAST(sum(galssmeasure) as UNSIGNED),0) into @yijiagong3 from  gmms_raw_file where state='已完成' and operator=3 and file_name like '%P%' and receive_time like shijian1; 
 
select ifnull(round(sum(case when operator=1 then (gt.width*gt.height)/1000000  else 0 end),2),0),ifnull(round(sum(case when operator=2 then (gt.width*gt.height)/1000000 else 0 end),2),0),ifnull(round(sum(case when operator=3 then (gt.width*gt.height)/1000000 else 0 end),2),0) into @yijiagong1,@yijiagong2,@yijiagong3 from gmms_galss_task_stock gt inner join gmms_raw_file rf on gt.engineering_id=rf.file_name and gt.finsh_time like shijian1;
 
select ifnull(CAST(sum((gt.edg_width*gt.edg_height)/1000000) as UNSIGNED),0) into @qiegeposun1 from e_pierceds ep left join gmms_galss_task_buffer gt on ep.glass_id=gt.id where line=1 and create_time like shijian1 and (process='切割' or process='磨边');
select ifnull(CAST(sum((gt.edg_width*gt.edg_height)/1000000) as UNSIGNED),0)  into @qiegeposun2 from e_pierceds ep left join gmms_galss_task_buffer gt on ep.glass_id=gt.id where line=2 and create_time like shijian1 and (process='切割' or process='磨边');
select ifnull(CAST(sum((gt.edg_width*gt.edg_height)/1000000) as UNSIGNED),0)  into @qiegeposun3 from e_pierceds ep left join gmms_galss_task_buffer gt on ep.glass_id=gt.id where line=3 and create_time like shijian1 and (process='切割' or process='磨边');
select ifnull(CAST(sum((gt.edg_width*gt.edg_height)/1000000) as UNSIGNED),0)  into @ganghuaposun1 from e_pierceds ep left join gmms_galss_task_buffer gt on ep.glass_id=gt.id where line=1 and create_time like shijian1 and process='钢化';
select ifnull(CAST(sum((gt.edg_width*gt.edg_height)/1000000) as UNSIGNED),0)  into @ganghuaposun2 from e_pierceds ep left join gmms_galss_task_buffer gt on ep.glass_id=gt.id where line=2 and create_time like shijian1 and process='钢化';
select ifnull(CAST(sum((gt.edg_width*gt.edg_height)/1000000) as UNSIGNED),0)  into @zhongkongposun1 from e_pierceds ep left join gmms_galss_task_buffer gt on ep.glass_id=gt.id where line=1 and create_time like shijian1 and process='中空';
select ifnull(CAST(sum((gt.edg_width*gt.edg_height)/1000000) as UNSIGNED),0)  into @zhongkongposun2 from e_pierceds ep left join gmms_galss_task_buffer gt on ep.glass_id=gt.id where line=2 and create_time like shijian1 and process='中空';
select ifnull(CAST(sum((gt.edg_width*gt.edg_height)/1000000) as UNSIGNED),0)  into @zhongkongposun3 from e_pierceds ep left join gmms_galss_task_buffer gt on ep.glass_id=gt.id where line=3 and create_time like shijian1 and process='中空';
select ifnull(CAST(sum((edg_width*edg_height)/1000000) as UNSIGNED),0) into @daijiagong2 from gmms_galss_task_stock where fine_throwing=0 and marking_flag in('11','12','13','14','15','16','17','18');
 
select CAST(sum((edg_width*edg_height)/1000000) as UNSIGNED) into @daijiagong3 from gmms_galss_task_shelf where work_procedure='钢化后下片';
 
select ifnull(round(sum((width*height)/1000000),2),0) into @yijiagong4 from E_record_tempering where line=1 and create_time like shijian1;
select ifnull(round(sum((width*height)/1000000),2),0) into @yijiagong5 from  E_record_tempering where line=2 and create_time like shijian1;
select ifnull(round(sum((width*height)/1000000),2),0)  into @yijiagong6 from  E_record_hollow where line=1 and create_time like shijian1;
select ifnull(round(sum((width*height)/1000000),2),0) into @yijiagong7 from  E_record_hollow where line=2 and create_time like shijian1;
select ifnull(round(sum((width*height)/1000000),2),0) into @yijiagong8 from  E_record_hollow where line=3 and create_time like shijian1;
 
 
select ifnull(sum(case when operator=1 then 1 else 0 end),0),ifnull(sum(case when operator=2 then 1 else 0 end),0),ifnull(sum(case when operator=3 then 1 else 0 end),0) into @jiagongshu1,@jiagongshu2,@jiagongshu3 from gmms_galss_task_stock gt inner join gmms_raw_file rf on gt.engineering_id=rf.file_name and gt.finsh_time like shijian1;
 
select ifnull(sum(case when line=1 then 1 else 0 end),0),ifnull(sum(case when line=2 then 1 else 0 end),0) into @jiagongshu4,@jiagongshu5 from E_record_tempering where create_time like shijian1;
 
select ifnull(sum(case when line=1 then 1 else 0 end),0),ifnull(sum(case when line=2 then 1 else 0 end),0),ifnull(sum(case when line=3 then 1 else 0 end),0) into @jiagongshu6,@jiagongshu7,@jiagongshu8 from E_record_hollow where create_time like shijian1;
 
 
-- select sum(tag5),sum(tag6),sum(tag7),sum(tag4),sum(tag9),sum(tag20),sum(tag19),sum(tag13) into @haodian1,@haodian2,@haodian3,@haodian4,@haodian5,@haodian6,@haodian7,@haodian8 from   gmms_data.dianliang_view dl order by myid desc limit 0,1;
 
 
select ifnull(max(tag5)-min(tag5),0),ifnull(max(tag6)-min(tag6),0),ifnull(max(tag7)-min(tag7),0),ifnull(max(tag4)-min(tag4),0),ifnull(max(tag9)-min(tag9),0),ifnull(max(tag20)-min(tag20),0),ifnull(max(tag19)-min(tag19),0),ifnull(max(tag13)-min(tag13),0) into @haodian1,@haodian2,@haodian3,@haodian4,@haodian5,@haodian6,@haodian7,@haodian8 from   gmms_data.dianliang_view dl where mydatetime like shijian1  ;
 
 
 
select @daijiagong1,@yijiagong1,@yijiagong2,@yijiagong3,@qiegeposun1,@qiegeposun2,@qiegeposun3,@ganghuaposun1,@ganghuaposun2,@zhongkongposun1,@zhongkongposun2,@zhongkongposun3,@daijiagong2,@daijiagong3,@yijiagong4,@yijiagong5,@yijiagong6,@yijiagong7,@yijiagong8,@haodian1,@haodian2,@haodian3,@haodian4,@haodian5,@haodian6,@haodian7,@haodian8,@jiagongshu1,
@jiagongshu2,@jiagongshu3,@jiagongshu4,@jiagongshu5,@jiagongshu6,@jiagongshu7,@jiagongshu8,ifnull(round(@haodian1/@yijiagong1,2),0),ifnull(round(@haodian2/@yijiagong2,2),0),ifnull(round(@haodian3/@yijiagong3,2),0),ifnull(round(@haodian4/@yijiagong4,2),0),ifnull(round(@haodian5/@yijiagong5,2),0),ifnull(round(@haodian6/@yijiagong6,2),0),ifnull(round(@haodian7/@yijiagong7,2),0),ifnull(round(@haodian8/@yijiagong8,2),0);
 
 
-- select CAST(sum(galssmeasure) as UNSIGNED) into @daijiagong1 from gmms_raw_file where state='已下发' and file_name like '%P%';
-- select CAST(sum(galssmeasure) as UNSIGNED) into @yijiagong1 from  gmms_raw_file where state='已完成' and operator=1 and file_name like '%P%'; 
-- select CAST(sum(galssmeasure) as UNSIGNED) into @yijiagong2 from  gmms_raw_file where state='已完成' and operator=2 and file_name like '%P%'; 
-- select CAST(sum(galssmeasure) as UNSIGNED) into @yijiagong3 from  gmms_raw_file where state='已完成' and operator=3 and file_name like '%P%'; 
-- select ifnull(CAST(sum((gt.edg_width*gt.edg_height)/1000000) as UNSIGNED),0) into @qiegeposun1 from e_pierceds ep left join gmms_galss_task_buffer gt on ep.glass_id=gt.id where line=1 and (process='切割' or process='磨边');
-- select ifnull(CAST(sum((gt.edg_width*gt.edg_height)/1000000) as UNSIGNED),0)  into @qiegeposun2 from e_pierceds ep left join gmms_galss_task_buffer gt on ep.glass_id=gt.id where line=2 and (process='切割' or process='磨边');
-- select ifnull(CAST(sum((gt.edg_width*gt.edg_height)/1000000) as UNSIGNED),0)  into @qiegeposun3 from e_pierceds ep left join gmms_galss_task_buffer gt on ep.glass_id=gt.id where line=3 and (process='切割' or process='磨边');
-- select ifnull(CAST(sum((gt.edg_width*gt.edg_height)/1000000) as UNSIGNED),0)  into @ganghuaposun1 from e_pierceds ep left join gmms_galss_task_buffer gt on ep.glass_id=gt.id where line=1 and process='钢化';
-- select ifnull(CAST(sum((gt.edg_width*gt.edg_height)/1000000) as UNSIGNED),0)  into @ganghuaposun2 from e_pierceds ep left join gmms_galss_task_buffer gt on ep.glass_id=gt.id where line=2 and process='钢化';
-- select ifnull(CAST(sum((gt.edg_width*gt.edg_height)/1000000) as UNSIGNED),0)  into @zhongkongposun1 from e_pierceds ep left join gmms_galss_task_buffer gt on ep.glass_id=gt.id where line=1 and process='中空';
-- select ifnull(CAST(sum((gt.edg_width*gt.edg_height)/1000000) as UNSIGNED),0)  into @zhongkongposun2 from e_pierceds ep left join gmms_galss_task_buffer gt on ep.glass_id=gt.id where line=2 and process='中空';
-- select ifnull(CAST(sum((gt.edg_width*gt.edg_height)/1000000) as UNSIGNED),0)  into @zhongkongposun3 from e_pierceds ep left join gmms_galss_task_buffer gt on ep.glass_id=gt.id where line=3 and process='中空';
-- select ifnull(CAST(sum((edg_width*edg_height)/1000000) as UNSIGNED),0) into @daijiagong2 from gmms_galss_task_stock where fine_throwing=0 and marking_flag in('11','12','13','14','15','16','17','18');
-- 
-- select ifnull(CAST(sum((edg_width*edg_height)/1000000) as UNSIGNED),0) into @daijiagong3 from gmms_galss_task_shelf where work_procedure='钢化后下片';
-- 
-- select ifnull(round(sum((width*height)/1000000),2),0) into @yijiagong4 from E_record_tempering where line=1;
-- select ifnull(round(sum((width*height)/1000000),2),0) into @yijiagong5 from  E_record_tempering where line=2;
-- select ifnull(round(sum((width*height)/1000000),2),0)  into @yijiagong6 from  E_record_hollow where line=1;
-- select ifnull(round(sum((width*height)/1000000),2),0) into @yijiagong7 from  E_record_hollow where line=2;
-- select ifnull(round(sum((width*height)/1000000),2),0) into @yijiagong8 from  E_record_hollow where line=3;
-- 
-- select round(sum(tag5)),round(sum(tag6)),round(sum(tag7)),round(sum(tag4)),round(sum(tag9)),round(sum(tag20)),round(sum(tag19)),round(sum(tag13)) into @haodian1,@haodian2,@haodian3,@haodian4,@haodian5,@haodian6,@haodian7,@haodian8 from   gmms_data.dianliang_view dl ;
-- 
-- select @daijiagong1,@yijiagong1,@yijiagong2,@yijiagong3,@qiegeposun1,@qiegeposun2,@qiegeposun3,@ganghuaposun1,@ganghuaposun2,@zhongkongposun1,@zhongkongposun2,@zhongkongposun3,@daijiagong2,@daijiagong3,@yijiagong4,@yijiagong5,@yijiagong6,@yijiagong7,@yijiagong8,@haodian1,@haodian2,@haodian3,@haodian4,@haodian5,@haodian6,@haodian7,@haodian8;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for d_dapingxianshi4
-- ----------------------------
DROP PROCEDURE IF EXISTS `d_dapingxianshi4`;
delimiter ;;
CREATE PROCEDURE `d_dapingxianshi4`()
BEGIN
    #Routine body goes here...
    #生产线冷加工完工折线图
    DECLARE i int DEFAULT 10;
    DECLARE shijian1 varchar(255);
    DECLARE shijian2 varchar(255);
    DECLARE shijian3 varchar(255);
 
drop table if EXISTS  tabletmp_table1;
drop table if EXISTS  tabletmp_table2;
 
create temporary table tabletmp_table1 (riqi VARCHAR(255) NOT NULL);
create temporary table tabletmp_table2 (riqi VARCHAR(255) NOT NULL);
while i<=60 do
    set shijian2= DATE_ADD(now(), INTERVAL -i MINUTE);
    insert into tabletmp_table1(riqi) values(shijian2);
    insert into tabletmp_table2(riqi) values(shijian2);
    set shijian1=CONCAT('%',@shijian,'%');
 
    set i=i+10;
end while;
 
set shijian3=DATE_ADD(now(), INTERVAL -70 MINUTE);
 
-- select sum(case when operator=1 then round((gr.width*gr.height)/1000000,2) else 0 end) as bbb,
-- sum(case when operator=2 then round((gr.width*gr.height)/1000000,2) else 0 end) as sss,
-- sum(case when operator=3 then round((gr.width*gr.height)/1000000,2) else 0 end) as aaa
-- from tabletmp_table1 tt left join  gmms_galss_task_stock   gr on finsh_time>shijian3 and left(tt.riqi,15)=left(gr.finsh_time,15) 
-- left join gmms_raw_file grf on gr.engineering_id=grf.file_name group by left(tt.riqi,15);
 
 
select qiege1,qiege2,qiege3,ganghua1,ganghua2,sum(case when ert.line=1 then round((ert.width*ert.height)/1000000 ,2) else 0 end) as zhongkong1,sum(case when ert.line=2 then round((ert.width*ert.height)/1000000 ,2) else 0 end) as zhongkong2,sum(case when ert.line=3 then round((ert.width*ert.height)/1000000 ,2) else 0 end) as zhongkong3 from
(select ss.riqi,bbb as qiege1,sss as qiege2,aaa as qiege3,
sum(case when erp.line=1 then round((erp.width*erp.height)/1000000,2)  else 0 end) as ganghua1,
sum(case when erp.line=2 then round((erp.width*erp.height)/1000000,2)  else 0 end) as ganghua2  from 
(select riqi,sum(case when operator=1 then round((gr.width*gr.height)/1000000,2) else 0 end) as bbb,
sum(case when operator=2 then round((gr.width*gr.height)/1000000,2) else 0 end) as sss,
sum(case when operator=3 then round((gr.width*gr.height)/1000000,2) else 0 end) as aaa
 
 
from tabletmp_table1 tt left join  gmms_galss_task_stock   gr on left(tt.riqi,15)=left(gr.finsh_time,15) and finsh_time>shijian3
 
left join gmms_raw_file grf on gr.engineering_id=grf.file_name group by left(tt.riqi,15)) as ss left join E_record_tempering erp on left(ss.riqi,15)=left(erp.create_time,15) and create_time>shijian3
group by left(ss.riqi,15)) as gg left join E_record_hollow ert on left(gg.riqi,15)=left(ert.create_time,15) and create_time>shijian3 group by left(gg.riqi,15);
-- 
-- 
-- 
-- 
-- 
-- select qiege1,qiege2,qiege3,ganghua1,ganghua2,sum(case when ert.line=1 then 1 else 0 end) as zhongkong1,sum(case when ert.line=2 then 1 else 0 end) as zhongkong2,sum(case when ert.line=3 then 1 else 0 end) as zhongkong3 from
-- (select ss.riqi,bbb as qiege1,sss as qiege2,aaa as qiege3,
-- sum(case when erp.line=1 then 1  else 0 end) as ganghua1,
-- sum(case when erp.line=2 then 1  else 0 end) as ganghua2  from 
-- (select riqi,sum(case when operator=1 then 1 else 0 end) as bbb,
-- sum(case when operator=2 then 1 else 0 end) as sss,
-- sum(case when operator=3 then 1 else 0 end) as aaa
-- 
-- 
-- from tabletmp_table1 tt left join  gmms_galss_task_stock   gr on left(tt.riqi,15)=left(gr.finsh_time,15) and finsh_time>shijian3
-- 
-- left join gmms_raw_file grf on gr.engineering_id=grf.file_name group by left(tt.riqi,15)) as ss left join E_record_tempering erp on left(ss.riqi,15)=left(erp.create_time,15) and create_time>shijian3
-- group by left(ss.riqi,15)) as gg left join E_record_hollow ert on left(gg.riqi,15)=left(ert.create_time,15) and create_time>shijian3 group by left(gg.riqi,15);
 
 
 
 
 
 
 
 
 
 
 
-- select riqi,sum(case when ert.line=3 then round((ert.width*ert.width)/1000000,2)  else 0 end)
-- 
-- 
-- from tabletmp_table1 tt left join E_record_hollow ert on left(tt.riqi,15)=left(ert.create_time,15) and create_time>@shijian2 group by left(tt.riqi,15);
 
 
-- select riqi,sum(case when operator=1 then 1 else 0 end),
-- sum(case when operator=2 then 1 else 0 end) ,
-- sum(case when operator=3 then 1 else 0 end) 
-- 
-- 
-- from tabletmp_table1 tt left join  gmms_galss_task_stock   gr on left(tt.riqi,15)=left(gr.finsh_time,15) and finsh_time>DATE_ADD('2023-04-10 10:49:48', INTERVAL -70 MINUTE)
-- 
-- left join gmms_raw_file grf on gr.engineering_id=grf.file_name group by left(tt.riqi,15);
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for d_dapingxianshi5
-- ----------------------------
DROP PROCEDURE IF EXISTS `d_dapingxianshi5`;
delimiter ;;
CREATE PROCEDURE `d_dapingxianshi5`()
BEGIN
    #Routine body goes here...
        #冷加工总产量图
 
#Routine body goes here...
    DECLARE i int DEFAULT 0;
    DECLARE shijian1 varchar(255);
    DECLARE shijian2 varchar(255);
    DECLARE shijian3 varchar(255);
 
 
drop table if EXISTS  tabletmp_table2;
create temporary table tabletmp_table2 (riqi VARCHAR(255) NOT NULL);
while i<14 do
    set shijian2= subdate(date_format( now(), '%Y-%m-%d' ),i);
    insert into tabletmp_table2(riqi) values(shijian2);
    set shijian1=CONCAT('%',@shijian,'%');
 
    set i=i+1;
end while;
set shijian3=subdate(date_format( now(), '%Y-%m-%d' ),14);
 
 
 
select qiege1,qiege2,qiege3,ganghua1,ganghua2,sum(case when erh.line=1 then round(erh.width*erh.height/1000000,2) else 0 end) as zhongkong1,sum(case when erh.line=2 then round(erh.width*erh.height/1000000,2) else 0 end) as zhongkong2,sum(case when erh.line=3 then round(erh.width*erh.height/1000000,2) else 0 end) as zhongkong3 from
(select aa.riqi,a as qiege1,b as qiege2,c as qiege3,sum(case when ert.line=1 then round(ert.width*ert.height/1000000,2) else 0 end) as ganghua1,sum(case when ert.line=2 then round(ert.width*ert.height/1000000,2) else 0 end) as ganghua2  from
(select riqi,sum(case when operator=1 then round(gr.width*gr.height/1000000,2) else 0 end) as a,sum(case when operator=2 then round(gr.width*gr.height/1000000,2) else 0 end) as b,sum(case when operator=3 then round(gr.width*gr.height/1000000,2) else 0 end) as c
from tabletmp_table2 tt left join gmms_galss_task_stock gr on tt.riqi=date(gr.finsh_time) and gr.finsh_time>shijian3 left join gmms_raw_file rf on rf.file_name=gr.engineering_id and rf.create_time>shijian3 group by tt.riqi) as aa 
left join E_record_tempering ert on aa.riqi=date(ert.create_time) and ert.create_time>shijian3 group by aa.riqi) ss 
left join E_record_hollow erh on ss.riqi=date(erh.create_time) and erh.create_time>shijian3 group by ss.riqi;
 
 
 
-- select qiege1,qiege2,qiege3,ganghua1,ganghua2,sum(case when erh.line=1 then 1 else 0 end) as zhongkong1,sum(case when erh.line=2 then 1 else 0 end) as zhongkong2,sum(case when erh.line=3 then 1 else 0 end) as zhongkong3 from
-- (select aa.riqi,a as qiege1,b as qiege2,c as qiege3,sum(case when ert.line=1 then 1 else 0 end) as ganghua1,sum(case when ert.line=2 then 1 else 0 end) as ganghua2  from
-- (select riqi,sum(case when operator=1 then 1 else 0 end) as a,sum(case when operator=2 then 1 else 0 end) as b,sum(case when operator=3 then 1 else 0 end) as c
-- from tabletmp_table2 tt left join gmms_galss_task_stock gr on tt.riqi=date(gr.finsh_time) and gr.finsh_time>shijian3 left join gmms_raw_file rf on rf.file_name=gr.engineering_id and rf.create_time>shijian3 group by tt.riqi) as aa 
-- left join E_record_tempering ert on aa.riqi=date(ert.create_time) and ert.create_time>shijian3 group by aa.riqi) ss 
-- left join E_record_hollow erh on ss.riqi=date(erh.create_time) and erh.create_time>shijian3 group by ss.riqi;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for d_dapingxianshi5_1
-- ----------------------------
DROP PROCEDURE IF EXISTS `d_dapingxianshi5_1`;
delimiter ;;
CREATE PROCEDURE `d_dapingxianshi5_1`()
BEGIN
    #    #冷加工总产量图
 
#Routine body goes here...
    DECLARE i int DEFAULT 0;
    DECLARE shijian1 varchar(255);
    DECLARE shijian2 varchar(255);
    DECLARE shijian3 varchar(255);
 
 
drop table if EXISTS  tabletmp_table2;
create temporary table tabletmp_table2 (riqi VARCHAR(255) NOT NULL);
while i<=14 do
    set shijian2= subdate(date_format( now(), '%Y-%m-%d' ),i);
    insert into tabletmp_table2(riqi) values(shijian2);
    set shijian1=CONCAT('%',@shijian,'%');
 
    set i=i+1;
end while;
set shijian3=subdate(date_format( now(), '%Y-%m-%d' ),14);
 
 
-- select qiege1,qiege2,qiege3,ganghua1,ganghua2,sum(case when erh.line=1 then round(erh.width*erh.height/1000000,2) else 0 end) as zhongkong1,sum(case when erh.line=2 then round(erh.width*erh.height/1000000,2) else 0 end) as zhongkong2,sum(case when erh.line=3 then round(erh.width*erh.height/1000000,2) else 0 end) as zhongkong3 from
-- (select aa.riqi,a as qiege1,b as qiege2,c as qiege3,sum(case when ert.line=1 then round(ert.width*ert.height/1000000,2) else 0 end) as ganghua1,sum(case when ert.line=2 then round(ert.width*ert.height/1000000,2) else 0 end) as ganghua2  from
-- (select riqi,sum(case when operator=1 then round(gr.width*gr.height/1000000,2) else 0 end) as a,sum(case when operator=2 then round(gr.width*gr.height/1000000,2) else 0 end) as b,sum(case when operator=3 then round(gr.width*gr.height/1000000,2) else 0 end) as c
-- from tabletmp_table2 tt left join gmms_galss_task_stock gr on tt.riqi=date(gr.finsh_time) and gr.finsh_time>shijian3 left join gmms_raw_file rf on rf.file_name=gr.engineering_id and rf.create_time>@shijian3 group by tt.riqi) as aa 
-- left join E_record_tempering ert on aa.riqi=date(ert.create_time) and ert.create_time>shijian3 group by aa.riqi) ss 
-- left join E_record_hollow erh on ss.riqi=date(erh.create_time) and erh.create_time>shijian3 group by ss.riqi;
 
 
 
 
 
select qiege1,qiege2,qiege3,ganghua1,ganghua2,sum(case when erh.line=1 then 1 else 0 end) as zhongkong1,sum(case when erh.line=2 then 1 else 0 end) as zhongkong2,sum(case when erh.line=3 then 1 else 0 end) as zhongkong3 from
(select aa.riqi,a as qiege1,b as qiege2,c as qiege3,sum(case when ert.line=1 then 1 else 0 end) as ganghua1,sum(case when ert.line=2 then 1 else 0 end) as ganghua2  from
(select riqi,sum(case when operator=1 then 1 else 0 end) as a,sum(case when operator=2 then 1 else 0 end) as b,sum(case when operator=3 then 1 else 0 end) as c
from tabletmp_table2 tt left join gmms_galss_task_stock gr on tt.riqi=date(gr.finsh_time) and gr.finsh_time>shijian3 left join gmms_raw_file rf on rf.file_name=gr.engineering_id and rf.create_time>shijian3 group by tt.riqi) as aa 
left join E_record_tempering ert on aa.riqi=date(ert.create_time) and ert.create_time>shijian3 group by aa.riqi) ss 
left join E_record_hollow erh on ss.riqi=date(erh.create_time) and erh.create_time>shijian3 group by ss.riqi;
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for d_dapingxianshi6
-- ----------------------------
DROP PROCEDURE IF EXISTS `d_dapingxianshi6`;
delimiter ;;
CREATE PROCEDURE `d_dapingxianshi6`()
BEGIN
    #Routine body goes here...
    #总破损统计图
 
#Routine body goes here...
    DECLARE i int DEFAULT 0;
    DECLARE shijian1 varchar(255);
    DECLARE shijian2 varchar(255);
    DECLARE shijian3 varchar(255);
 
drop table if EXISTS  tabletmp_table3;
 
create temporary table tabletmp_table3 (riqi VARCHAR(255) NOT NULL);
while i<14 do
    set shijian2= subdate(date_format( now(), '%Y-%m-%d' ),i);
    insert into tabletmp_table3(riqi) values(shijian2);
    set shijian1=CONCAT('%',@shijian,'%');
 
    set i=i+1;
end while;
set shijian3=subdate(date_format( now(), '%Y-%m-%d' ),14);
 
select sum(case when line=1 and (process='切割' or process='磨边') then round(gt.width*gt.height/1000000,2) else 0 end)
,sum(case when line=2 and (process='切割' or process='磨边') then round(gt.width*gt.height/1000000,2) else 0 end)
,sum(case when line=3 and (process='切割' or process='磨边') then round(gt.width*gt.height/1000000,2) else 0 end)
,sum(case when line=1 and process='钢化'  then round(gt.width*gt.height/1000000,2) else 0 end)
,sum(case when line=2 and process='钢化'  then round(gt.width*gt.height/1000000,2) else 0 end)
,sum(case when line=1 and process='中空'  then round(gt.width*gt.height/1000000,2) else 0 end)
,sum(case when line=2 and process='中空'  then round(gt.width*gt.height/1000000,2) else 0 end)
,sum(case when line=3 and process='中空'  then round(gt.width*gt.height/1000000,2) else 0 end)
from tabletmp_table3 tt left join e_pierceds gr on tt.riqi=date(gr.create_time) and gr.create_time>shijian3 left join gmms_galss_task_buffer gt on gr.glass_id=gt.id  group by tt.riqi;
 
-- select sum(case when line=1 and (process='切割' or process='磨边') then 1 else 0 end)
-- ,sum(case when line=2 and (process='切割' or process='磨边') then 1 else 0 end)
-- ,sum(case when line=3 and (process='切割' or process='磨边') then 1 else 0 end)
-- ,sum(case when line=1 and process='钢化'  then 1 else 0 end)
-- ,sum(case when line=2 and process='钢化'  then 1 else 0 end)
-- ,sum(case when line=1 and process='中空'  then 1 else 0 end)
-- ,sum(case when line=2 and process='中空'  then 1 else 0 end)
-- ,sum(case when line=3 and process='中空'  then 1 else 0 end)
-- from tabletmp_table3 tt left join e_pierceds gr on tt.riqi=date(gr.create_time) and gr.create_time>shijian3  group by tt.riqi;
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for d_dapingxianshi6_1
-- ----------------------------
DROP PROCEDURE IF EXISTS `d_dapingxianshi6_1`;
delimiter ;;
CREATE PROCEDURE `d_dapingxianshi6_1`()
BEGIN
        #总破损统计图
 
#Routine body goes here...
    DECLARE i int DEFAULT 0;
    DECLARE shijian1 varchar(255);
    DECLARE shijian2 varchar(255);
    DECLARE shijian3 varchar(255);
 
drop table if EXISTS  tabletmp_table3;
 
create temporary table tabletmp_table3 (riqi VARCHAR(255) NOT NULL);
while i<=14 do
    set shijian2= subdate(date_format(now(), '%Y-%m-%d' ),i);
    insert into tabletmp_table3(riqi) values(shijian2);
    set shijian1=CONCAT('%',@shijian,'%');
 
    set i=i+1;
end while;
set shijian3=subdate(date_format( now(), '%Y-%m-%d' ),14);
 
-- select sum(case when line=1 and (process='切割' or process='磨边') then round(gt.width*gt.height/1000000,2) else 0 end)
-- ,sum(case when line=2 and (process='切割' or process='磨边') then round(gt.width*gt.height/1000000,2) else 0 end)
-- ,sum(case when line=3 and (process='切割' or process='磨边') then round(gt.width*gt.height/1000000,2) else 0 end)
-- ,sum(case when line=1 and process='钢化'  then round(gt.width*gt.height/1000000,2) else 0 end)
-- ,sum(case when line=2 and process='钢化'  then round(gt.width*gt.height/1000000,2) else 0 end)
-- ,sum(case when line=1 and process='中空'  then round(gt.width*gt.height/1000000,2) else 0 end)
-- ,sum(case when line=2 and process='中空'  then round(gt.width*gt.height/1000000,2) else 0 end)
-- ,sum(case when line=3 and process='中空'  then round(gt.width*gt.height/1000000,2) else 0 end)
-- from tabletmp_table3 tt left join e_pierceds gr on tt.riqi=date(gr.create_time) and gr.create_time>shijian3 left join gmms_galss_task_buffer gt on gr.glass_id=gt.id  group by tt.riqi;
 
select sum(case when line=1 and (process='切割' or process='磨边') then 1 else 0 end)
,sum(case when line=2 and (process='切割' or process='磨边') then 1 else 0 end)
,sum(case when line=3 and (process='切割' or process='磨边') then 1 else 0 end)
,sum(case when line=1 and process='钢化'  then 1 else 0 end)
,sum(case when line=2 and process='钢化'  then 1 else 0 end)
,sum(case when line=1 and process='中空'  then 1 else 0 end)
,sum(case when line=2 and process='中空'  then 1 else 0 end)
,sum(case when line=3 and process='中空'  then 1 else 0 end)
from tabletmp_table3 tt left join e_pierceds gr on tt.riqi=date(gr.create_time) and gr.create_time>shijian3  group by tt.riqi;
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for d_dapingxianshi7
-- ----------------------------
DROP PROCEDURE IF EXISTS `d_dapingxianshi7`;
delimiter ;;
CREATE PROCEDURE `d_dapingxianshi7`()
BEGIN
    #Routine body goes here...
    #Routine body goes here...
    #生产线破损折线图
    DECLARE i int DEFAULT 10;
    DECLARE shijian1 varchar(255);
    DECLARE shijian2 varchar(255);
    DECLARE shijian3 varchar(255);
 
drop table if EXISTS  tabletmp_table4;
 
create temporary table tabletmp_table4 (riqi VARCHAR(255) NOT NULL);
while i<=60 do
    set shijian2= DATE_ADD(now(), INTERVAL -i MINUTE);
    insert into tabletmp_table4(riqi) values(shijian2);
    set shijian1=CONCAT('%',@shijian,'%');
 
    set i=i+10;
end while;
set shijian3=DATE_ADD(now(), INTERVAL -70 MINUTE);
 
select sum(case when line=1 and (process='切割' or process='磨边') then round(gt.width*gt.height/1000000,2) else 0 end)
,sum(case when line=2 and (process='切割' or process='磨边') then round(gt.width*gt.height/1000000,2) else 0 end)
,sum(case when line=3 and (process='切割' or process='磨边') then round(gt.width*gt.height/1000000,2) else 0 end)
,sum(case when line=1 and process='钢化'  then round(gt.width*gt.height/1000000,2) else 0 end)
,sum(case when line=2 and process='钢化'  then round(gt.width*gt.height/1000000,2) else 0 end)
,sum(case when line=1 and process='中空'  then round(gt.width*gt.height/1000000,2) else 0 end)
,sum(case when line=2 and process='中空'  then round(gt.width*gt.height/1000000,2) else 0 end)
,sum(case when line=3 and process='中空'  then round(gt.width*gt.height/1000000,2) else 0 end)
from tabletmp_table4 tt left join e_pierceds gr on left(tt.riqi,15)=left(gr.create_time,15) and gr.create_time>shijian3 left join gmms_galss_task_buffer gt on gr.glass_id=gt.id
 
group by left(tt.riqi,15);
 
 
-- select sum(case when line=1 and (process='切割' or process='磨边') then 1 else 0 end)
-- ,sum(case when line=2 and (process='切割' or process='磨边') then 1 else 0 end)
-- ,sum(case when line=3 and (process='切割' or process='磨边') then 1 else 0 end)
-- ,sum(case when line=1 and process='钢化'  then 1 else 0 end)
-- ,sum(case when line=2 and process='钢化'  then 1 else 0 end)
-- ,sum(case when line=1 and process='中空'  then 1 else 0 end)
-- ,sum(case when line=2 and process='中空'  then 1 else 0 end)
-- ,sum(case when line=3 and process='中空'  then 1 else 0 end)
-- from tabletmp_table4 tt left join e_pierceds gr on left(tt.riqi,15)=left(gr.create_time,15) and gr.create_time>shijian3
-- 
-- group by left(tt.riqi,15);
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for d_dapingxianshi8
-- ----------------------------
DROP PROCEDURE IF EXISTS `d_dapingxianshi8`;
delimiter ;;
CREATE PROCEDURE `d_dapingxianshi8`()
BEGIN
    #Routine body goes here...
    #生产线冷加工完工折线图
    DECLARE i int DEFAULT 0;
    DECLARE shijian1 varchar(255);
    DECLARE shijian2 varchar(255);
    DECLARE shijian3 varchar(255);
 
drop table if EXISTS  tabletmp_table1;
drop table if EXISTS  tabletmp_table2;
 
create temporary table tabletmp_table1 (riqi VARCHAR(255) NOT NULL);
create temporary table tabletmp_table2 (riqi VARCHAR(255) NOT NULL);
while i<14 do
    set shijian2= subdate(date_format( now(), '%Y-%m-%d' ),i);
    insert into tabletmp_table1(riqi) values(shijian2);
    insert into tabletmp_table2(riqi) values(shijian2);
    set shijian1=CONCAT('%',@shijian,'%');
 
    set i=i+1;
end while;
set shijian3=subdate(date_format( now(), '%Y-%m-%d' ),14);
 
 
select biao1.aaa+biao2.bbb,if(biao1.bbb+biao2.aaa!=0,concat('-',biao1.bbb+biao2.aaa),biao1.bbb+biao2.aaa) from
(select riqi,aaa,ifnull(sum(round(erh.width*erh.height/1000000,2)),0)  as bbb from 
(select riqi,ifnull(sum(round(ert.width*ert.height/1000000,2)),0)  as aaa
 
 
from tabletmp_table1 tt left join  E_record_tempering   ert on tt.riqi=date(ert.create_time) and ert.create_time>shijian3 group by tt.riqi) as gg 
left join E_record_hollow erh on gg.riqi=date(erh.create_time) and erh.create_time>shijian3 group by gg.riqi) as biao1
 
 
inner join 
 
 
(select riqi,sum(case when type='进库' then round(gr.width*gr.height/1000000,2) else 0 end) as bbb ,sum(case when type='退库' then round(gr.width*gr.height/1000000,2) else 0 end) as aaa
 
 
from tabletmp_table2 tt left join  gmms_rank_2   gr on tt.riqi=date(gr.createtime) and createtime>shijian3 group by tt.riqi) as biao2
on biao1.riqi=biao2.riqi;
 
 
 
-- select biao1.riqi,biao1.bbb+biao2.bbb,biao1.aaa+biao2.aaa from
-- (select riqi,aaa,sum(case when groups is not null then 1 else 0 end) as bbb from 
-- (select riqi,sum(case when groups is not null then 1 else 0 end)  as aaa
-- 
-- 
-- from tabletmp_table1 tt left join  E_record_tempering   ert on tt.riqi=date(ert.create_time) and ert.create_time>@shijian2 group by tt.riqi) as gg 
-- left join E_record_hollow erh on gg.riqi=date(erh.create_time) and erh.create_time>shijian3 group by gg.riqi) as biao1
-- 
-- 
-- inner join 
-- 
-- 
-- (select riqi,sum(case when type='进库' then 1 else 0 end) as bbb ,sum(case when type='退库' then 1 else 0 end) as aaa
-- 
-- 
-- from tabletmp_table2 tt left join  gmms_rank_2   gr on tt.riqi=date(gr.createtime) and createtime>shijian3 group by tt.riqi) as biao2
-- on biao1.riqi=biao2.riqi;
 
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for d_dapingxianshi9
-- ----------------------------
DROP PROCEDURE IF EXISTS `d_dapingxianshi9`;
delimiter ;;
CREATE PROCEDURE `d_dapingxianshi9`()
BEGIN
    #Routine body goes here...
    #右上角
    DECLARE i int DEFAULT 0;
    DECLARE shijian1 varchar(255);
    DECLARE shijian2 varchar(255);
    DECLARE shijian3 varchar(255);
    DECLARE shijian4 varchar(255);
 
 
 
drop table if EXISTS  tabletmp_table4;
create temporary table tabletmp_table4 (riqi VARCHAR(255) NOT NULL);
insert into tabletmp_table4(riqi) values('切割一线'),('切割二线'),('切割三线'),('钢化一线'),('钢化二线'),('中空一线'),('中空二线'),('中空三线');
 
 
set shijian4=DATE_ADD(curdate(), INTERVAL -1 HOUR);
 
 
set @db='select tt.riqi,qqq.* from tabletmp_table4 tt left join (select if(rf.operator!=1 and rf.operator!=2,"切割三线",if(rf.operator!=1,"切割二线","切割一线")) as aaa';
set @db1='select if(ert.line!=2,"钢化一线","钢化二线") as aaa';
set @db2='select if(erh.line!=1 and erh.line!=2,"中空三线",if(erh.line!=1,"中空二线","中空一线")) as aaa' ;
 
 
 while i<1440 do
    set shijian2= DATE_ADD(curdate(), INTERVAL +i MINUTE);
    
    set shijian3=DATE_ADD(shijian2, INTERVAL +20 MINUTE);
 
    set @db=concat(@db,',ifnull(if(round(sum(case when left(gtc.finsh_time,16)<"',left(shijian3,16),'" and left(gtc.finsh_time,16)>="',left(shijian2,16),'"   then 1 else 0 end)/20*100,2)>100,100,round(sum(case when left(gtc.finsh_time,16)<"',left(shijian3,16),'" and left(gtc.finsh_time,16)>="',left(shijian2,16),'"   then 1 else 0 end)/20*100,2)),0)');
    
    set @db1=concat(@db1,',ifnull(if(round(sum(case when left(ert.create_time,16)<"',left(shijian2,16),'" and left(ert.create_time,13)>="',left(shijian2,16),'"   then 1 else 0 end)/20*100,2)>100,100,round(sum(case when left(ert.create_time,16)<"',left(shijian3,16),'" and left(ert.create_time,16)>="',left(shijian2,16),'"   then 1 else 0 end)/20*100,2)),0)');
    
    set @db2=concat(@db2,',if(round(sum(case when left(erh.create_time,16)<"',left(shijian2,16),'" and left(erh.create_time,16)>="',left(shijian2,16),'"   then 1 else 0 end)/20*100,2)>100,100,round(sum(case when left(erh.create_time,16)<"',left(shijian3,16),'" and left(erh.create_time,16)>="',left(shijian2,16),'"   then 1 else 0 end)/20*100,2))');
    set i=i+20;
 end while;
 
 
set @db=concat(@db,'from gmms_galss_task_stock gtc left join gmms_raw_file rf on rf.file_name=gtc.engineering_id and finsh_time>"',shijian4,'"   where gtc.finsh_time>"',shijian4,'"and  rf.operator is not null group by rf.operator');
set @db1=concat(@db1,'from E_record_tempering ert  where ert.create_time>"',shijian4,'"and  ert.line is not null group by ert.line ');
set @db2=concat(@db2,'from E_record_hollow erh  where erh.create_time>"',shijian4,'"and  erh.line is not null group by erh.line ) as qqq on tt.riqi=qqq.aaa ');
 
 
 
 
set @dbmax=concat(@db,' union all ',@db1,' union all ',@db2);
 
 
 
prepare danp from @dbmax;
EXECUTE danp;
DEALLOCATE PREPARE danp;
 
 
    
    
    
    
    
    
--     DECLARE i int DEFAULT 336;
--     DECLARE shijian1 varchar(255);
--     DECLARE shijian2 varchar(255);
--     DECLARE shijian3 varchar(255);
--     DECLARE shijian4 varchar(255);
-- 
-- drop table if EXISTS  tabletmp_table4;
-- create temporary table tabletmp_table4 (riqi VARCHAR(255) NOT NULL);
-- insert into tabletmp_table4(riqi) values('切割一线'),('切割二线'),('切割三线'),('钢化一线'),('钢化二线'),('中空一线'),('中空二线'),('中空三线');
-- 
-- 
-- set shijian4=DATE_ADD(now(), INTERVAL -337 HOUR);
--  
-- set @db='select tt.riqi,qqq.* from tabletmp_table4 tt left join (select if(rf.operator!=1 and rf.operator!=2,"切割三线",if(rf.operator!=1,"切割二线","切割一线")) as aaa';
-- set @db1='select if(ert.line!=2,"钢化一线","钢化二线") as aaa';
-- set @db2='select if(erh.line!=1 and erh.line!=2,"中空三线",if(erh.line!=1,"中空二线","中空一线")) as aaa' ;
--  
--  
--  while i>=0 do
--     set shijian2= DATE_ADD(now(), INTERVAL -i HOUR);
--     
--     set shijian3=DATE_ADD(shijian2, INTERVAL -4 HOUR);
--     set @db=concat(@db,',ifnull(if(round(sum(case when left(gtc.finsh_time,13)<"',left(shijian2,13),'" and left(gtc.finsh_time,13)>="',left(shijian3,13),'"   then 1 else 0 end)/200*100,2)>100,100,round(sum(case when left(gtc.finsh_time,13)<"',left(shijian2,13),'" and left(gtc.finsh_time,13)>="',left(shijian3,13),'"   then 1 else 0 end)/200*100,2)),0)');
--     
--     set @db1=concat(@db1,',ifnull(if(round(sum(case when left(ert.create_time,13)<"',left(shijian2,13),'" and left(ert.create_time,13)>="',left(shijian3,13),'"   then 1 else 0 end)/200*100,2)>100,100,round(sum(case when left(ert.create_time,13)<"',left(shijian2,13),'" and left(ert.create_time,13)>="',left(shijian3,13),'"   then 1 else 0 end)/200*100,2)),0)');
--     
--     set @db2=concat(@db2,',if(round(sum(case when left(erh.create_time,13)<"',left(shijian2,13),'" and left(erh.create_time,13)>="',left(shijian3,13),'"   then 1 else 0 end)/200*100,2)>100,100,round(sum(case when left(erh.create_time,13)<"',left(shijian2,13),'" and left(erh.create_time,13)>="',left(shijian3,13),'"   then 1 else 0 end)/200*100,2))');
--     set i=i-4;
--  end while;
--  
--  
-- set @db=concat(@db,'from gmms_galss_task_stock gtc left join gmms_raw_file rf on rf.file_name=gtc.engineering_id and finsh_time>"',shijian4,'"   where gtc.finsh_time>"',shijian4,'"and  rf.operator is not null group by rf.operator');
-- set @db1=concat(@db1,'from E_record_tempering ert  where ert.create_time>"',shijian4,'"and  ert.line is not null group by ert.line ');
-- set @db2=concat(@db2,'from E_record_hollow erh  where erh.create_time>"',shijian4,'"and  erh.line is not null group by erh.line ) as qqq on tt.riqi=qqq.aaa ');
-- 
-- 
-- 
-- 
-- set @dbmax=concat(@db,' union all ',@db1,' union all ',@db2);
-- 
-- 
-- 
-- prepare danp from @dbmax;
-- EXECUTE danp;
-- DEALLOCATE PREPARE danp;
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for d_dapingxianshi9_copy1
-- ----------------------------
DROP PROCEDURE IF EXISTS `d_dapingxianshi9_copy1`;
delimiter ;;
CREATE PROCEDURE `d_dapingxianshi9_copy1`()
BEGIN
    #Routine body goes here...
    #右上角
    DECLARE i int DEFAULT 1440;
    DECLARE shijian1 varchar(255);
    DECLARE shijian2 varchar(255);
    DECLARE shijian3 varchar(255);
    DECLARE shijian4 varchar(255);
 
drop table if EXISTS  tabletmp_table4;
create temporary table tabletmp_table4 (riqi VARCHAR(255) NOT NULL);
insert into tabletmp_table4(riqi) values('切割一线'),('切割二线'),('切割三线'),('钢化一线'),('钢化二线'),('中空一线'),('中空二线'),('中空三线');
 
 
set shijian4=DATE_ADD('2023-06-19 11:10:18', INTERVAL -25 HOUR);
 
set @db='select tt.riqi,qqq.* from tabletmp_table4 tt left join (select if(rf.operator!=1 and rf.operator!=2,"切割三线",if(rf.operator!=1,"切割二线","切割一线")) as aaa';
set @db1='select if(ert.line!=2,"钢化一线","钢化二线") as aaa';
set @db2='select if(erh.line!=1 and erh.line!=2,"中空三线",if(erh.line!=1,"中空二线","中空一线")) as aaa' ;
 
 
 while i>0 do
    set shijian2= DATE_ADD('2023-06-19 11:10:18', INTERVAL -i MINUTE);
    
    set shijian3=DATE_ADD(shijian2, INTERVAL -20 MINUTE);
 
    set @db=concat(@db,',ifnull(if(round(sum(case when left(gtc.finsh_time,13)<"',left(shijian2,16),'" and left(gtc.finsh_time,13)>="',left(shijian3,16),'"   then 1 else 0 end)/20*100,2)>100,100,round(sum(case when left(gtc.finsh_time,13)<"',left(shijian2,16),'" and left(gtc.finsh_time,13)>="',left(shijian3,16),'"   then 1 else 0 end)/20*100,2)),0)');
    
    set @db1=concat(@db1,',ifnull(if(round(sum(case when left(ert.create_time,13)<"',left(shijian2,16),'" and left(ert.create_time,13)>="',left(shijian3,16),'"   then 1 else 0 end)/20*100,2)>100,100,round(sum(case when left(ert.create_time,13)<"',left(shijian2,16),'" and left(ert.create_time,13)>="',left(shijian3,16),'"   then 1 else 0 end)/20*100,2)),0)');
    
    set @db2=concat(@db2,',if(round(sum(case when left(erh.create_time,13)<"',left(shijian2,16),'" and left(erh.create_time,13)>="',left(shijian3,16),'"   then 1 else 0 end)/20*100,2)>100,100,round(sum(case when left(erh.create_time,13)<"',left(shijian2,16),'" and left(erh.create_time,13)>="',left(shijian3,16),'"   then 1 else 0 end)/20*100,2))');
    set i=i-20;
 end while;
 
 
set @db=concat(@db,'from gmms_galss_task_stock gtc left join gmms_raw_file rf on rf.file_name=gtc.engineering_id and finsh_time>"',shijian4,'"   where gtc.finsh_time>"',shijian4,'"and  rf.operator is not null group by rf.operator');
set @db1=concat(@db1,'from E_record_tempering ert  where ert.create_time>"',shijian4,'"and  ert.line is not null group by ert.line ');
set @db2=concat(@db2,'from E_record_hollow erh  where erh.create_time>"',shijian4,'"and  erh.line is not null group by erh.line ) as qqq on tt.riqi=qqq.aaa ');
 
 
 
 
set @dbmax=concat(@db,' union all ',@db1,' union all ',@db2);
 
 
 
prepare danp from @dbmax;
EXECUTE danp;
DEALLOCATE PREPARE danp;
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for Edg
-- ----------------------------
DROP PROCEDURE IF EXISTS `Edg`;
delimiter ;;
CREATE PROCEDURE `Edg`(in sendMessageHex varchar(255),in machineids BIGINT,out messagedate varchar(255))
BEGIN
    #磨边机存储过程
    #找到当前机器标志位
    #查询机器逻辑表中对应的逻辑进行对应的步骤
    DECLARE machinedisposeids int DEFAULT 0;
    DECLARE dates varchar(255);
    DECLARE findplc varchar(255);
    DECLARE findmes varchar(255);
    DECLARE taskplc varchar(255);
    DECLARE taskmes varchar(255);
    DECLARE posunplc varchar(255);
    DECLARE posunmes varchar(255);
    DECLARE speed1s int;
    DECLARE speed2s int;
    DECLARE messagedates varchar(255) DEFAULT '';
    set messagedate=messagedates;
    
    select machine_type_id into @mtid from gmms_machine where id=machineids;
    
    select machine_type_id,work_id into @mtid,@work_groups from gmms_machine where id=machineids;
    
    
    
    select mf.flag into @完成标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='完成字';
    
    select mf.flag into @请求标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='请求字';
    
    select mf.flag into @发送标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='发送字';
    
    select mf.flag into @完成确认标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='完成确认字';
    
    select mf.flag into @破损标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='破损字';
    
    select mf.flag into @破损确认标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='破损确认字';
    
    set findplc = substring(sendMessageHex,(cast(@完成标志位 as UNSIGNED INTEGER)*4)+19,4);
    set taskplc = substring(sendMessageHex,(cast(@请求标志位 as UNSIGNED INTEGER)*4)+19,4);
    set taskmes = substring(sendMessageHex,(cast(@发送标志位 as UNSIGNED INTEGER)*4)+19,4);
    set findmes = substring(sendMessageHex,(cast(@完成确认标志位 as UNSIGNED INTEGER)*4)+19,4);
    set posunplc = substring(sendMessageHex,(cast(@破损标志位 as UNSIGNED INTEGER)*4)+19,4);
    set posunmes = substring(sendMessageHex,(cast(@破损确认标志位 as UNSIGNED INTEGER)*4)+19,4);
    set speed1s = conv(substring(sendMessageHex,(cast(45 as UNSIGNED INTEGER)*4)+19,4),16,10);
    set speed2s = conv(substring(sendMessageHex,(cast(48 as UNSIGNED INTEGER)*4)+19,4),16,10);
    select taskplc;
    select taskmes;
    select findplc;
    select findmes;
    select posunplc;
    select posunmes;
    select @mtid;
    
    if machineids=28 then
        update gmms_edg_speed set speed1=speed1s,speed2=speed2s where groups=@work_groups;
    elseif machineids=6 or machineids=29 then
        update gmms_edg_speed set speed1=speed1s where groups=@work_groups;
 elseif machineids=30 or machineids=19 then
        update gmms_edg_speed set speed2=speed1s where groups=@work_groups;
    end if;
    
    #完成逻辑查询
    select count(*),md.id into @完成数量,@完成逻辑编号 from gmms_machine_dispose md join gmms_machine_type mt on md.machine_type_id=mt.id where md.machine_type_id=@mtid  and md.plc_font_type='完成字' and md.mes_font_type='完成确认字' and md.plc_font_value=findplc and md.mes_font_value=findmes;
    
    #请求逻辑查询
    select count(*),md.id into @请求数量,@请求逻辑编号 from gmms_machine_dispose md join gmms_machine_type mt on md.machine_type_id=mt.id where md.machine_type_id=@mtid  and md.plc_font_type='请求字' and md.mes_font_type='发送字' and md.plc_font_value=taskplc and md.mes_font_value=taskmes;
    
    #破损逻辑查询
    select count(*),md.id into @破损数量,@破损逻辑编号 from gmms_machine_dispose md join gmms_machine_type mt on md.machine_type_id=mt.id where md.machine_type_id=@mtid  and md.plc_font_type='破损字' and md.mes_font_type='破损确认字' and md.plc_font_value=posunplc and md.mes_font_value=posunmes;
    
    #判断逻辑是否存在
    select @完成数量;
    select @请求数量;
    select @完成逻辑编号;
    select machineids;
    if @完成数量=1 or @请求数量=1 or @破损数量=1 then
        if machineids = 6 or machineids = 29 or machineids = 28 then
            if @请求逻辑编号!=0 then
                set machinedisposeids=@请求逻辑编号;
            elseif @完成逻辑编号!=0 then
                set machinedisposeids=@完成逻辑编号;
            elseif @破损逻辑编号!=0 then
                set machinedisposeids=@破损逻辑编号;
            end if;
        elseif machineids = 19 or machineids = 30  then
            if (@完成逻辑编号!=0 && machineids=19) or (@完成逻辑编号!=0 && machineids=30)  then
                set machinedisposeids=@完成逻辑编号;
            
--         #判断破损逻辑是否为空
         elseif @破损逻辑编号!=0 then
             set machinedisposeids=@破损逻辑编号;
            
        #判断请求逻辑是否为空
            elseif @请求逻辑编号!=0 then
                set machinedisposeids=@请求逻辑编号;
            
            end if;
        end if;
    select machinedisposeids;
        
        #查询当前执行逻辑进行判断
        select logic,return_value into @ExecutionLogic,@returnvalue from gmms_machine_dispose where id=machinedisposeids;
        select @ExecutionLogic;
        if @ExecutionLogic='任务完成' then
                call     EdgFinsh(sendMessageHex,machineids,machinedisposeids,1,@messagedate);
                set messagedate=@messagedate;
         elseif @ExecutionLogic='完成破损' then
                call EdgFinsh(sendMessageHex,machineids,machinedisposeids,2,@messagedate);
                set messagedate=@messagedate;
         elseif @ExecutionLogic='完成清空' then        
                if machineids=28 then
                    call message(@returnvalue,'0014',@date);
                    set messagedate=@date;
                else
                    call message(@returnvalue,'1784',@date);
                    set messagedate=@date;
                end if;
                
        elseif @ExecutionLogic='破损清空' then        
                if machineids=28 then
                    call message(@returnvalue,'0016',@date);
                    set messagedate=@date;
                else
                    call message(@returnvalue,'1786',@date);
                    set messagedate=@date;
                end if;
        elseif @ExecutionLogic='任务请求' then
            if machineids=6 or  machineids=29 or  machineids=28 then
                call EdgSend(machineids,machinedisposeids,@messagedate);
                set messagedate=@messagedate;
            end if;
         elseif @ExecutionLogic='任务清空' then
                if machineids=28 then
                    set dates=CONCAT(@returnvalue,"0000000000000000");
                    call message(dates,'000a',@date);
                    set messagedate=@date;
                else
                    set dates=CONCAT(@returnvalue,"0000000000000000");
                    call message(dates,'177a',@date);
                    set messagedate=@date;
                end if;
                
        end if;
    end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for EdgFinsh
-- ----------------------------
DROP PROCEDURE IF EXISTS `EdgFinsh`;
delimiter ;;
CREATE PROCEDURE `EdgFinsh`(in sendMessageHex varchar(255),in machineids BIGINT,in machinedisposeids BIGINT,in flag int,out messagedate varchar(255))
BEGIN
    #磨边机完成存储过程
    #任务完成以及任务破损,flag=1为完成,flag=2为破损
    DECLARE rank3 int ;
    DECLARE rank4 varchar(255);
    DECLARE dates varchar(255);
    DECLARE messagedates varchar(255) DEFAULT '';
    set messagedate=messagedates;
    
    select machine_type_id,work_id into @mtid,@work_groups from gmms_machine where id=machineids;
    
    select file_name into @engineering_id from gmms_raw_file where operator=@work_groups and state='已领取';
    
    select return_value into @returnvalue from gmms_machine_dispose where id=machinedisposeids;
    
    
    select mf.flag into @完成标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='完成字';
    
    select mf.flag into @破损标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='破损字';
    
    #完成
if machineids=6 or machineids=29 then
select flag;
    if flag=1 then 
        call message('0001','1784',@date);
        set messagedate=@date;
        
    #破损
    elseif flag=2 then
        set rank4 = substring(sendMessageHex,(cast(@破损标志位+1 as UNSIGNED INTEGER)*4)+19,4);
        select rank4;
        set rank3=conv(rank4,16,10);
        select rank3;
        
        update gmms_galss_task set work_state='破损' where galss_id=rank3 and work_state='正在工作' and engineering_id=@engineering_id;
        
        call message(@returnvalue,'1786',@date);
        set messagedate=@date;
    end if;
        
elseif machineids=19 or machineids=30 then
    if flag=1 then 
--      if machineids=19 then
--         insert into aaaa set ddd="111222";
--         end if;
        set rank4 = substring(sendMessageHex,(cast(@完成标志位+1 as UNSIGNED INTEGER)*4)+19,4);
        
        set rank3=conv(rank4,16,10);
        
        select width,height into @width,@height from gmms_galss_task where galss_id=rank3 and work_state='正在工作' and engineering_id=@engineering_id;
        insert into gmms_edg_perimeter set width=@width,height=@height,start_time=NOW(),groups=@work_groups;
        
        update gmms_galss_task set work_state='待复合',work_procedure='复合' where galss_id=rank3 and work_state='正在工作' and engineering_id=@engineering_id;
 
        call message(@returnvalue,'1784',@date);
        set messagedate=@date;
        
    #破损
    elseif flag=2 then
    
        set rank4 = substring(sendMessageHex,(cast(@破损标志位+1 as UNSIGNED INTEGER)*4)+19,4);
        select rank4;
        set rank3=conv(rank4,16,10);
        
        update gmms_galss_task set work_state='破损' where galss_id=rank3 and work_state='正在工作' and work_procedure='磨边' and engineering_id=@engineering_id;
        
        call message(@returnvalue,'1786',@date);
        set messagedate=@date;
    
    end if;
elseif machineids=28 then
    if flag=1 then 
        
        set rank4 = substring(sendMessageHex,(cast(@完成标志位+1 as UNSIGNED INTEGER)*4)+19,4);
        
        set rank3=conv(rank4,16,10);
        
        select width,height into @width,@height from gmms_galss_task where galss_id=rank3 and work_state='正在工作' and engineering_id=@engineering_id;
        insert into gmms_edg_perimeter set width=@width,height=@height,start_time=NOW(),groups=@work_groups;
        
        update gmms_galss_task set work_state='待复合',work_procedure='复合' where galss_id=rank3 and work_state='正在工作' and engineering_id=@engineering_id;
 
        call message(@returnvalue,'0014',@date);
        set messagedate=@date;
        
    #破损
    elseif flag=2 then
    
        set rank4 = substring(sendMessageHex,(cast(@破损标志位+1 as UNSIGNED INTEGER)*4)+19,4);
        select rank4;
        set rank3=conv(rank4,16,10);
        
        update gmms_galss_task set work_state='破损' where galss_id=rank3 and work_state='正在工作' and work_procedure='磨边' and engineering_id=@engineering_id;
        
        call message(@returnvalue,'0016',@date);
        set messagedate=@date;
    
    end if;
end if;
    
    
    
    
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for EdgSend
-- ----------------------------
DROP PROCEDURE IF EXISTS `EdgSend`;
delimiter ;;
CREATE PROCEDURE `EdgSend`(in machineids BIGINT,in machinedisposeids BIGINT,out messagedate varchar(255))
BEGIN
    #磨边机请求存储过程
    #找到当前的一条玻璃信息,把需要的数据发送过去
    #发送数据:序号,宽度,高度,厚度,类型,磨边速度,磨边大小
    DECLARE width1 int;
    DECLARE heigth1 int;
    DECLARE rank1 int;
    DECLARE thickness1 int;
    DECLARE chamfer_size1 int;
    DECLARE galss_type1 int;
    DECLARE fine_throwing1 int;
    DECLARE edg_speed11 int;
    DECLARE edg_speed21 int;
    DECLARE dates varchar(255);
    DECLARE booldate varchar(255);
    DECLARE booldate1 varchar(255);
    DECLARE booldate2 varchar(255);
    DECLARE messagedates varchar(255) DEFAULT '';
    
    DECLARE jiID BIGINT DEFAULT 0;
    DECLARE thistype varchar(255);
    DECLARE lasttype varchar(255) DEFAULT '';
    DECLARE lastRecordsid BIGINT DEFAULT 0;
    DECLARE lastRecordsidW BIGINT DEFAULT 0;
    DECLARE lastRecordsidH BIGINT DEFAULT 0;
    DECLARE lastW int DEFAULT 0;
    DECLARE lastH int DEFAULT 0;
    
    
    set messagedate=messagedates;
    
    select machine_type_id,work_id into @mtid,@work_groups from gmms_machine where id=machineids;
    
    select file_name into @engineering_id from gmms_raw_file where operator=@work_groups and state='已领取';
    
    select return_value into @returnvalue from gmms_machine_dispose where id=machinedisposeids;
    
    select id,galss_id,edg_width,edg_height,thickness,chamfer_size,galss_type,fine_throwing,edg_speed1,edg_speed2 into jiID,@rank,@width,@heigth,@thickness,@chamfer_size,@galss_type,@fine_throwing,@edg_speed1,@edg_speed2 from gmms_galss_task where work_state='等待中' and work_procedure='磨边' and engineering_id=@engineering_id order by out_rank limit 1;
    
    
    select @rank;
    if @rank is not null then
    
     update gmms_galss_task set work_state='正在工作' where galss_id=@rank and engineering_id=@engineering_id;
    #update gmms_galss_task set work_state='待复合',work_procedure='复合' where galss_id=@rank;
      
    set thistype=CONCAT(IFNULL(@width,''),'*',IFNULL(@heigth,''));
    select SizeText,Recordsid,Width,Height,RecordsidW,RecordsidH into lasttype,lastRecordsid,lastW,lastH,lastRecordsidW,lastRecordsidH from Y_Edg_Statistics 
    where Line=@work_groups order by Recordsid desc limit 1;
    if lasttype is null then
        set lastRecordsid=1;
        set lastRecordsidW=1;
        set lastRecordsidH=1;
    else
        if lasttype!=thistype then
            set lastRecordsid=lastRecordsid+1;
        end if;
        if lastW!=@width then
            set lastRecordsidW=lastRecordsidW+1;
        end if;
        if lastH!=@heigth then
            set lastRecordsidH=lastRecordsidH+1;
        end if;
    end if;
    
    
    
    set rank1=cast(@rank as UNSIGNED INTEGER);
    select rank1;
    set width1=cast(@width as UNSIGNED INTEGER)*10;
    set heigth1=cast(@heigth as UNSIGNED INTEGER)*10;
    set thickness1=cast(@thickness as UNSIGNED INTEGER)*10;
--     set chamfer_size1=cast(@chamfer_size as UNSIGNED INTEGER);
--     set galss_type1=@galss_type;
--     set fine_throwing1=@fine_throwing;
--     set edg_speed11=cast(@edg_speed1 as UNSIGNED INTEGER);
--     set edg_speed21=cast(@edg_speed2 as UNSIGNED INTEGER);
--     
--     set booldate1=CONCAT(galss_type1,'11',fine_throwing1,'0000');
--     set booldate2=CONCAT("00000000");
    
    #转换进制
    call intTo2ByteHex10_16_4(rank1,@ranks);
    call intTo2ByteHex10_16_4(width1,@widths);
    call intTo2ByteHex10_16_4(heigth1,@heigths);
    call intTo2ByteHex10_16_4(thickness1,@thicknesss);
    select @ranks;
    select @widths;
    select @heigths;
    select @thicknesss;
--     call intTo2ByteHex2_16(booldate1,@booldate1);
--     call intTo2ByteHex2_16(booldate2,@booldate2);
--     call intTo2ByteHex10_16_4(chamfer_size1,@chamfer_sizes);
--     call intTo2ByteHex10_16_4(edg_speed11,@edg_speed1s);
--     call intTo2ByteHex10_16_4(edg_speed21,@edg_speed2s);
--     
--     set booldate=CONCAT(@booldate2,@booldate1);
 
 
    
    
    INSERT INTO `gmms`.`Y_Edg_Statistics`(`Glassid`, `SendTime`, `Width`, `Height`, `Thickess`, `SizeText`, `SendText`, `Recordsid`, `Line`,RecordsidW,RecordsidH) 
    select id,NOW(),edg_width,edg_height,thickness,CONCAT(IFNULL(edg_width,''),'*',IFNULL(edg_height,'')),CONCAT(@returnvalue,@ranks,@heigths,@widths,@thicknesss),lastRecordsid,@work_groups,lastRecordsidW,lastRecordsidH from gmms_galss_task 
    where id=jiID;
 
    if machineids=28 then
        set dates=CONCAT(@returnvalue,@ranks,@heigths,@widths,@thicknesss);
        select dates;
        call message(dates,'000a',@date); 
        set messagedate=@date;
    elseif machineids=29 then
        set dates=CONCAT(@returnvalue,@ranks,@heigths,@widths,@thicknesss);
        select dates;
        call message(dates,'177a',@date); 
        set messagedate=@date;
    else
        set dates=CONCAT(@returnvalue,@ranks,@widths,@heigths,@thicknesss);
        select dates;
        call message(dates,'177a',@date); 
        set messagedate=@date;
    end if;
    end if;
    
    
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for GalssTask
-- ----------------------------
DROP PROCEDURE IF EXISTS `GalssTask`;
delimiter ;;
CREATE PROCEDURE `GalssTask`(in rawFileid BIGINT,in line BIGINT,out dates int)
BEGIN
    #Routine body goes here...
    declare t_err int default 0;
  DECLARE t_step int;
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION,SQLWARNING,NOT FOUND set t_err=1;
    
    set dates=0;
    set t_step=0;
    set t_err=0;
    set @file_name=null;
    select rawFileid;
    select id,file_name,state into @id,@file_name,@z_state from gmms_raw_file where id=rawFileid;
    select @z_state;
    if @z_state<>'已下发' and @z_state<>'中断' then
            set t_err=2;
    elseif @z_state='中断' then
            set t_err=10;
  else 
        START TRANSACTION;
    end if;
    
    
    if t_err=0 then 
    select @file_name;
        set t_step=1;
 
        insert into gmms_pattern_task (id,rank,raw_type,raw_height,raw_width,raw_thickness,work_state,color,content,task_id,raw_id,flag,groups) select ptf.id,ptf.rank,ptf.raw_type,ptf.raw_height,ptf.raw_width,ptf.raw_thickness,ptf.work_state,ptf.color,ptf.content,ptf.task_id,rf.id,ptf.flag,rf.operator from gmms_pattern_task_buffer ptf join gmms_raw_file rf on ptf.engineering_id=rf.file_name where engineering_id=@file_name;
 
        
    elseif t_err=10 then
        
        select count(*) into @count1 from gmms_galss_task where engineering_id=@file_name;
        select count(*) into @count2 from gmms_pattern_task where raw_id=@id and groups=line;
        select @count1,@count2;
        if @count1<>0 or @count2<>0 then
            delete from gmms_galss_task where engineering_id=@file_name;
            delete from gmms_pattern_task where raw_id=@id and groups=line;
        end if;
        
        insert into gmms_galss_task select * from gmms_galss_task_interrupt where engineering_id=@file_name;
        select count(*) from gmms_pattern_task_interrupt where raw_id=@id and groups=line;
        insert into gmms_pattern_task select * from gmms_pattern_task_interrupt where raw_id=@id and groups=line;
        set dates=100;
    end if;
 
    
    if t_err=0 then 
    set t_step=2;
     #insert into gmms_galss_task select * from gmms_galss_task_buffer where engineering_id=@file_name;
    select @file_name;
    insert into gmms_galss_task (id,rank,type_id,galss_id,pattern_id,width,height,thickness,color,edg_width,edg_height,chamfer_size,galss_type,edg_speed1,edg_speed2,fine_throwing,work_state,work_procedure,slicecage_rank,drop_frame,slicecage_flag,out_rank,start_time,finsh_time,stop_position,processcard_id,engineering_id,broken_state,stop_rank,work_procedure_number,gc_number,gc_width,gc_height,gc_stockid,marking_flag) select id,rank,type_id,MOD(galss_id,10000),pattern_id,width,height,thickness,color,edg_width,edg_height,chamfer_size,galss_type,edg_speed1,edg_speed2,fine_throwing,work_state,work_procedure,slicecage_rank,drop_frame,slicecage_flag,out_rank,start_time,finsh_time,stop_position,processcard_id,engineering_id,broken_state,stop_rank,work_procedure_number,gc_number,gc_width,gc_height,gc_stockid,marking_flag from gmms_galss_task_buffer where engineering_id=@file_name;
    
    select t_err,t_step,0;
    call output_create(@file_name);
    select t_err,t_step,1;
    end if;
    if t_err=0 then 
                set t_step=3;
           call dongzuo_update_marking_flag(@file_name,line);
    end if;
    if t_err=0 then     
            set t_step=4;
           update gmms_raw_file set `state`='已领取',operator=line,create_time=now() where id= rawFileid;             
    end if;
    if t_err=0 then             
            set dates=100;
            COMMIT; 
    end if;
    
    if t_err=1 then
       ROLLBACK;
    end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for GalssTaskAdd
-- ----------------------------
DROP PROCEDURE IF EXISTS `GalssTaskAdd`;
delimiter ;;
CREATE PROCEDURE `GalssTaskAdd`(in width1 double,in height1 double,in thickness1 double,in pices int,in groups1 BIGINT,in dropframe varchar(255),in grinding double,in processcardid varchar(255),in engineeringid varchar(255),in marking varchar(255),out dates int)
BEGIN
    #Routine body goes here...   1622   978  6   3   3   35 A2 1.4 NG2023920933    MD2023920933
    DECLARE s int DEFAULT 1;
    DECLARE begins int DEFAULT 0;
    select count(*),id into @count,@id from gmms_raw_file where file_name=engineeringid and state='已领取';
    select count(*) into @count2 from gmms_raw_file where operator=groups1 and state='已领取';
    select number into @markings from gmms_dongzuo_table where note=marking;
    
    set begins=(groups1-1)*5000;
    set s=begins+1;
    if @count>0 then
        select id into @id1 from gmms_pattern_task where groups=groups1 limit 0,1;
        select max(type_id),max(id) into @type_id,@maxid from gmms_galss_task where engineering_id=engineeringid;
        set s=@maxid+1;
        while s<=(pices+@maxid) do
            insert into gmms_galss_task (id,rank,type_id,galss_id,pattern_id,width,height,thickness,color,edg_width,edg_height,galss_type,work_state,work_procedure,drop_frame,start_time,processcard_id,engineering_id,work_procedure_number,gc_height,gc_width,gc_number,fine_throwing,gc_stockid,marking_flag) values (s,0,@type_id+1,s,@id1,width1+(grinding/2),height1+(grinding/2),thickness1,'白玻',width1,height1,1,'待识别','测量',dropframe,now(),processcardid,engineeringid,100,0,0,0,0,0,@markings);
        set s=s+1;
        end while;
        set dates=1;
    else
        if @count2=0 then
            insert into gmms_raw_file (file_name,state,operator,create_time) values (engineeringid,'已领取',groups1,NOW());
            select id into @ids from gmms_raw_file where file_name=engineeringid and state='已领取';
            select max(id) into @maxid from gmms_pattern_task;
            insert into gmms_pattern_task (id,rank,raw_type,raw_width,raw_height,raw_thickness,work_state,color,task_id,raw_id,finsh_time,flag,groups) values (groups1,0,0,0,0,0,'已完成','0',0,@ids,NOW(),0,groups1);
            
            select id into @id1 from gmms_pattern_task where groups=groups1 limit 0,1;
            while s<=(pices+begins) do
                insert into gmms_galss_task (id,rank,type_id,galss_id,pattern_id,width,height,thickness,color,edg_width,edg_height,galss_type,work_state,work_procedure,drop_frame,start_time,processcard_id,engineering_id,work_procedure_number,gc_height,gc_width,gc_number,fine_throwing,gc_stockid,marking_flag) values (s,0,1,s,@id1,width1+(grinding/2),height1+(grinding/2),thickness1,'白玻',width1,height1,1,'待识别','测量',dropframe,now(),processcardid,engineeringid,100,0,0,0,0,0,@markings);
            set s=s+1;
            end while;
            set dates=1;
        end if;
    end if;
    
    
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for GalssTaskHollow
-- ----------------------------
DROP PROCEDURE IF EXISTS `GalssTaskHollow`;
delimiter ;;
CREATE PROCEDURE `GalssTaskHollow`(in rawFileid BIGINT,in line BIGINT,out dates int)
BEGIN
    #Routine body goes here...
    DECLARE g int DEFAULT 0;
    DECLARE counts int DEFAULT 1;
    
select file_name into @liuchengka from gmms_raw_file_2 where id=rawFileid;
 
select count(*) into counts from gmms_raw_file_2 where id=rawFileid and state='已领取';
 
if counts=0 then
 
 
select count(count1) into @count2 from (select count(*) as count1 from gmms_galss_task_shelf where  processcard_id like CONCAT('%',@liuchengka,'%') group by processcard_id ) aa;
select @count2;
while g<@count2 do
    select g;
    select processcard_id into @processcard_id from gmms_galss_task_shelf where  processcard_id like CONCAT('%',@liuchengka,'%')  group by  processcard_id  limit g,1;
    select @processcard_id;
    select dr.id,sr.number,dr.stop_rank into @id,@number,@stop_rank from gmms_shelf_rack_2 sr join gmms_drop_frame_4 dr on sr.orientation=dr.orientation where dr.groups=line and flag=0 and dr.state='空闲' and sr.processcard_id=@processcard_id order by dr.id limit 0,1;
    select @number;
    if @number is not null then
        select count(*) into @count3 from gmms_shelf_task_2 where shelf_rack_id=@number and load_rack=@stop_rank and task_state!='已下车';
        if @count3=0 then
            insert into gmms_shelf_task_2 (task_type,task_state,shelf_rack_id,load_rack,groups,start_time,line) values('从仓位到中空位','等待上车',@number,@stop_rank,1,now(),1);
        end if;
    end if;
    set g=g+1;
end while;
set dates=1;
update gmms_raw_file_2 set state='已领取',operator=line where id=rawFileid;
 
end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for GalssTaskHollowJia
-- ----------------------------
DROP PROCEDURE IF EXISTS `GalssTaskHollowJia`;
delimiter ;;
CREATE PROCEDURE `GalssTaskHollowJia`(in rawFileid BIGINT,out dates int)
BEGIN
    #Routine body goes here...
    DECLARE g int DEFAULT 0;
    
select file_name into @liuchengka from gmms_raw_file_2 where id=rawFileid;
 
select count(*) into @count from gmms_raw_file_2 where id=rawFileid and state='已领取';
select @count;
if @count=0 then
 
select liuchengka into @liuchengka1 from gmms_liuchengka_copy2 where parent_liuchengka=@liuchengka limit 0,1;
 
select liuchengka into @liuchengka2 from gmms_liuchengka_copy2 where parent_liuchengka=@liuchengka limit 1,1;
 
select number into @number1 from gmms_shelf_rack_2 where processcard_id=@liuchengka1;
select number into @number2 from gmms_shelf_rack_2 where processcard_id=@liuchengka2;
select @liuchengka;
select @number1;
    if @number1 is not null and @number2 is not null then
--             insert into gmms_shelf_task_2 (task_type,task_state,shelf_rack_id,load_rack,groups,start_time) values('从仓位到吊装位','等待中',@number1,99,0,now());
--             insert into gmms_shelf_task_2 (task_type,task_state,shelf_rack_id,load_rack,groups,start_time) values('从吊装位到仓位','等待中',@number1,99,0,now());
--             insert into gmms_shelf_task_2 (task_type,task_state,shelf_rack_id,load_rack,groups,start_time) values('从仓位到吊装位','等待中',@number2,99,0,now());
--             insert into gmms_shelf_task_2 (task_type,task_state,shelf_rack_id,load_rack,groups,start_time) values('从吊装位到仓位','等待中',@number2,99,0,now());
            update gmms_raw_file_2 set state='已领取' where id=rawFileid;
    end if;
 
set dates=1;
 
end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for GalssTaskShelfAdd
-- ----------------------------
DROP PROCEDURE IF EXISTS `GalssTaskShelfAdd`;
delimiter ;;
CREATE PROCEDURE `GalssTaskShelfAdd`(in processcardid VARCHAR(254),out dates int)
BEGIN
    #Routine body goes here...
 
    insert into gmms_galss_task_shelf select * from gmms_galss_task_details where processcard_id=processcardid;
    update gmms_galss_task_shelf set work_procedure='钢化后下片' where processcard_id=processcardid;
 
set dates=1;
 
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for GalssTaskStock
-- ----------------------------
DROP PROCEDURE IF EXISTS `GalssTaskStock`;
delimiter ;;
CREATE PROCEDURE `GalssTaskStock`(in processcardid VARCHAR(255),in groups1 BIGINT,out dates int)
BEGIN
    
    
    #Routine body goes here...
    #update aaaa set data1= now(),data2=null where ddd='1';
--      insert into gmms_galss_task_2 (id,rank,type_id,galss_id,pattern_id,width,height,thickness,color,edg_width,edg_height,chamfer_size,    galss_type,edg_speed1,edg_speed2,fine_throwing,work_state,work_procedure,slicecage_rank,drop_frame,slicecage_flag,out_rank,start_time,finsh_time,stop_position,processcard_id,engineering_id,broken_state,stop_rank,work_procedure_number,gc_number,gc_width,gc_height,gc_stockid,marking_flag) select * from gmms_galss_task_stock where processcard_id=processcardid;
--     
--     update gmms_galss_task_2 set groups=groups1,work_state='等待中',work_procedure='钢化上片',galss_id=0 where processcard_id=processcardid;
-- set dates=1;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for getId
-- ----------------------------
DROP PROCEDURE IF EXISTS `getId`;
delimiter ;;
CREATE PROCEDURE `getId`(in str text,in idx int,out backid varchar(30))
BEGIN
    #Routine body goes here...
     set @str1=SUBSTRING_INDEX(str,',',idx+1);
     set    @str2=SUBSTRING_INDEX(str,',',idx);
      if length(@str1)=length(@str2) then 
         set    backid=null;
        else
          set backid=SUBSTRING_INDEX(@str1,',',-1);
        end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for get_baobiao_chanliang
-- ----------------------------
DROP PROCEDURE IF EXISTS `get_baobiao_chanliang`;
delimiter ;;
CREATE PROCEDURE `get_baobiao_chanliang`()
BEGIN
    #Routine body goes here...
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for get_device_status
-- ----------------------------
DROP PROCEDURE IF EXISTS `get_device_status`;
delimiter ;;
CREATE PROCEDURE `get_device_status`(in  dev_id int,in flag int,out _work_name varchar(50),out _work_status varchar(50),out _islast bit)
BEGIN
    #dev_id      设备的ID号
  #flag                    获取的状态标志 0  获取上一个工艺段的完成状态。  1 获取当前工艺段的开始状态    2  获取当前工艺段的完成状态
    #_work_name    获取到的工序名
    #_work_status   获取到的状态名
    #_islast        如果当前状态是最后一个工艺段的完成状态,这里会返回true 1
 
    #Routine body goes here...
        DECLARE idx int default(null);
        DECLARE _name varchar(50) default(null);
        set _islast=false;
        set _work_name=null;
        set _work_status=null;
        if flag= 1 then 
    
                SELECT work_name,begin_status into _work_name,_work_status from gmms_device where id=dev_id;
            end if;
            
            if flag= 2 then 
    
                SELECT work_name,end_status,is_last into _work_name,_work_status,_islast from gmms_device where id=dev_id;
            end if;
            
        if flag=0 then 
            SELECT device_index,line_name into idx,_name from gmms_device where id=dev_id;
            if idx>1 then 
                    SELECT work_name,end_status into _work_name,_work_status from gmms_device where device_index=idx-1 and line_name=_name;
            end if;
            
            if idx=0 then     
                            SELECT work_name,begin_status into _work_name,_work_status from gmms_device where id=dev_id;
            end if;
        
        end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for get_next_tempere_number
-- ----------------------------
DROP PROCEDURE IF EXISTS `get_next_tempere_number`;
delimiter ;;
CREATE PROCEDURE `get_next_tempere_number`(in _work_id int,out _number int)
BEGIN
    #Routine body goes here...
   SET _number=0;
     SELECT layout_number into _number from gmms_tempere_layout where work_id=_work_id order by layout_number desc LIMIT 1;
     set  _number=_number+1;
END
;;
delimiter ;
 
-- ----------------------------
-- Function structure for get_str
-- ----------------------------
DROP FUNCTION IF EXISTS `get_str`;
delimiter ;;
CREATE FUNCTION `get_str`(_data text,_idx int)
 RETURNS varchar(200) CHARSET utf8
BEGIN
    #Routine body goes here...
  declare pos int;
    declare pos1 int;
    set pos=1;
    
    while _idx>-1 do 
        set pos1=LOCATE(',',_data,pos);
        if pos1>0 then 
            if _idx=0  then
                RETURN SUBSTR(_data FROM pos FOR (pos1-pos));
            else
                set pos=pos1+1;
            end if;
        else
            if _idx=0 then
                RETURN SUBSTR(_data FROM pos FOR (LENGTH(_data)-pos+1));
            else
              return null;
            end if;
        end if;
            set _idx=_idx-1;    
    end while;
    
    RETURN null;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for get_view_ping_chanliang
-- ----------------------------
DROP PROCEDURE IF EXISTS `get_view_ping_chanliang`;
delimiter ;;
CREATE PROCEDURE `get_view_ping_chanliang`(seg varchar(50),    
_line int,            
_from datetime, 
_to  datetime,   
out result int,
out msg varchar(50))
BEGIN
set result=0;
set @a=TIMESTAMPDIFF(MINUTE,_from,_to);
    #Routine body goes here...
select a.work_name,(case when b.b is null then '0/0' else b.b end) as bb ,
(case when b.d is null then '0/0' else b.d end) as dd,
(case when b.c is null then 0 else b.c end) as cc
  from 
(SELECT work_name from gmms_glass_log_config where segment=seg group by work_name order by work_number) 
a
LEFT JOIN
(
SELECT work_name,CONVERT(concat(count(*),'/', round(sum(area),2)),CHAR) as b, '0/0' as d, round(count(*)/TIMESTAMPDIFF(MINUTE,min(end_time),max(end_time)),1) as  c   FROM gmms_glass_log where end_time>=_from and end_time<=_to and `status`=100 and segment_name=seg  and line=_line and parent_id is not null and freeze=false group by work_name 
) b on a.work_name=b.work_name;
set result=200;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for get_view_ping_kucun
-- ----------------------------
DROP PROCEDURE IF EXISTS `get_view_ping_kucun`;
delimiter ;;
CREATE PROCEDURE `get_view_ping_kucun`(in flag int,out result int,out msg varchar(50))
BEGIN
    #Routine body goes here...
    if flag=0 or flag=1 then
                select  b.number,a.color,a.raw_width,a.raw_height,a.left_pieces,CAST(a.create_time as date) as create_time from gmms_raw_package a RIGHT join gmms_shelf_rack b on b.raw_package_id1=a.id order by convert(b.number,DECIMAL(10,0));
    end if;
    
 
if flag=0 or  flag=2 then 
                    SELECT a.liuchengka,b.color
    ,count(a.liuchengka) as count 
    from gmms_liuchengka a inner join gmms_galss_task_details b on a.liuchengka=b.processcard_id 
    where a.current_work_position='切磨线'  and a.current_status='下架'
    group by a.liuchengka,b.color;
end if;
 
 
if flag=0 or flag=3 then 
                    SELECT a.liuchengka,b.color
    ,count(a.liuchengka) as count 
    from gmms_liuchengka a inner join gmms_galss_task_details b on a.liuchengka=b.processcard_id 
    where a.current_work_position='钢化后'  and a.current_status='下架'
    group by a.liuchengka,b.color;
end if;
end
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for GlassTask_furnace
-- ----------------------------
DROP PROCEDURE IF EXISTS `GlassTask_furnace`;
delimiter ;;
CREATE PROCEDURE `GlassTask_furnace`(in RId BIGINT,in line int,out back_Num int,out back_Msg varchar(255))
BEGIN
    #逻辑流程:
    #1.查询规则
    #2.更新规则
 
    #生成钢化前玻璃上片规则
 
    Declare w varchar(255);#最大宽
    Declare l int;#最大高
    Declare x int;#x轴间隔
    Declare y int;#y轴间隔
    Declare r int;#记录受影响行数
 
    select width into w from gmms_furnace_config where Id = RId;
    select length into l from gmms_furnace_config where Id = RId;
    select xinterval into x from gmms_furnace_config where Id = RId;
    select yinterval into y from gmms_furnace_config where Id = RId;
    set back_num = 0;
    set back_Msg = "查询失败";
    
    update gmms_furnace_config set line = null where line = line;
    update gmms_furnace_config set line = line where Id = RId;
    set back_num = 2;
    set back_Msg = "规则表更新失败";
    
    update gmms_furnace set width = w,length = l,xinterval = x,yinterval = y where Id = line;
    set r =  FOUND_ROWS();
    if r=1 
        then
        set back_num = 1;
        set back_Msg = "成功";
    else 
        set back_num = 3;
        set back_Msg = "更新失败";
    end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for GlassTask_ganghuaqian
-- ----------------------------
DROP PROCEDURE IF EXISTS `GlassTask_ganghuaqian`;
delimiter ;;
CREATE PROCEDURE `GlassTask_ganghuaqian`(in pro_line BIGINT,out back_Num int,out back_Msg varchar(255))
BEGIN
    #生成钢化前玻璃上片任务
    Declare lck_num varchar(255);#记录流程卡号
    DECLARE sum_count int default 0;#记录累加的记录数
    DECLARE mlck_sum int default 0;#某流程卡数据总数
    DECLARE drop_num int default 0;#有流程卡的架位数量
    declare ks_time DateTime default now();#存储过程调用时间
    #定义游标
    Declare lck_cursor cursor for select processcard_id from gmms_drop_frame_2 where groups = pro_line and processcard_id is not null and processcard_id <>'' order by Id desc;
    
    select count(*) into drop_num from gmms_drop_frame_2 where groups = pro_line and processcard_id is not null and processcard_id <>'' order by Id desc;
    select drop_num;
    set back_Num = 0;#记录
    #打开游标
    Open lck_cursor;
    set back_Num = 6;#记录
    #重复
    REPEAT
    set back_Num = 7;#记录
        #使用游标---从游标中获取数据
        FETCH lck_cursor INTO lck_num;
        
        Update gmms_liuchengka set Occupied = 1000,isgang='已钢化' where liuchengka = lck_num;
        
        set back_Num = 2;
        #流程卡玻璃任务总数
        Select count(*) into mlck_sum from gmms_galss_task_2 where processcard_id = lck_num;
        if mlck_sum =0
            then
                SET sum_count = sum_count + 1;
                set back_Num = 3;
                #插入玻璃任务数据
                insert into gmms_galss_task_2 (id,rank,type_id,galss_id,pattern_id,width,height,thickness,color,edg_width,edg_height,chamfer_size,galss_type,edg_speed1,edg_speed2,fine_throwing,work_state,work_procedure,slicecage_rank,drop_frame,slicecage_flag,out_rank,start_time,finsh_time,stop_position,processcard_id,engineering_id,broken_state,stop_rank,work_procedure_number,gc_number,gc_width,gc_height,gc_stockid,marking_flag) select * from gmms_galss_task_stock where processcard_id=lck_num;
                
                set back_Num = 4;
                
                #更新任务数据
                update gmms_galss_task_2 set groups=pro_line,work_state='未优化',work_procedure='钢化上片',galss_id=0,start_time= ks_time    where processcard_id=lck_num;
                
                set back_Num = 5;
                
        else
            SET sum_count = sum_count + 1;
        end if;
 
    #退出重复条件
        UNTIL sum_count=drop_num
    END REPEAT;
    #关闭游标
    CLOSE lck_cursor;
    
    set back_Num=1;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for GlassTask_ganghuaqian_copy1
-- ----------------------------
DROP PROCEDURE IF EXISTS `GlassTask_ganghuaqian_copy1`;
delimiter ;;
CREATE PROCEDURE `GlassTask_ganghuaqian_copy1`(in pro_line BIGINT,out back_Num int,out back_Msg varchar(255))
BEGIN
    #生成钢化前玻璃上片任务
    Declare lck_num varchar(255);#记录流程卡号
    DECLARE sum_count int default 0;#记录累加的记录数
    DECLARE mlck_sum int default 0;#某流程卡数据总数
    DECLARE drop_num int default 0;#有流程卡的架位数量
    #定义游标
    Declare lck_cursor cursor for select processcard_id from gmms_drop_frame_2 where groups = pro_line and processcard_id is not null and processcard_id <>'' order by Id desc;
    
    select count(*) into drop_num from gmms_drop_frame_2 where groups = pro_line and processcard_id is not null and processcard_id <>'' order by Id desc;
    select drop_num;
    set back_Num = 0;#记录
    #打开游标
    Open lck_cursor;
    set back_Num = 6;#记录
    #重复
    REPEAT
    set back_Num = 7;#记录
        #使用游标---从游标中获取数据
        FETCH lck_cursor INTO lck_num;
        set back_Num = 2;
        Select count(*) into mlck_sum from gmms_galss_task_2 where processcard_id = lck_num;
        if mlck_sum =0
            then
                SET sum_count = sum_count + 1;
                set back_Num = 3;
                #插入玻璃任务数据
                insert into gmms_galss_task_2 (id,rank,type_id,galss_id,pattern_id,width,height,thickness,color,edg_width,edg_height,chamfer_size,galss_type,edg_speed1,edg_speed2,fine_throwing,work_state,work_procedure,slicecage_rank,drop_frame,slicecage_flag,out_rank,start_time,finsh_time,stop_position,processcard_id,engineering_id,broken_state,stop_rank,work_procedure_number,gc_number,gc_width,gc_height,gc_stockid,marking_flag) select * from gmms_galss_task_stock where processcard_id=lck_num;
                
                set back_Num = 4;
                
                #更新任务数据
                update gmms_galss_task_2 set groups=pro_line,work_state='未优化',work_procedure='钢化上片',galss_id=0    where processcard_id=lck_num;
                
                set back_Num = 5;
                
        else
            SET sum_count = sum_count + 1;
        end if;
 
    #退出重复条件
        UNTIL sum_count=drop_num
    END REPEAT;
    #关闭游标
    CLOSE lck_cursor;
    
    set back_Num=1;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for GlassTask_ghq_BindRack
-- ----------------------------
DROP PROCEDURE IF EXISTS `GlassTask_ghq_BindRack`;
delimiter ;;
CREATE PROCEDURE `GlassTask_ghq_BindRack`(in RId BIGINT,in lckNo varchar(50),out back_Num int,out back_Msg varchar(255))
BEGIN
    #逻辑流程:
    #1.判断流程卡是否已经绑定
    #2.判断流程卡小片是否已经完成冷加工部分
    #3.
    #生成钢化前玻璃上片任务
 
    Declare old_lck varchar(255);#旧流程卡号
    Declare lck_c int;#流程卡数量
    Declare lck_xc int;#流程卡小片数量
 
    #查询当前料架是否已经有流程卡
    select processcard_id into old_lck from gmms_drop_frame_2 where Id = RId;
    select old_lck;
    if old_lck is null
    then
            select count(*) into lck_c from gmms_drop_frame_2 where processcard_id = lckNo;
            select lck_c;
            if lck_c = 0
            then 
                select count(*) into lck_xc from gmms_galss_task_stock 
                where id>(select min(id) from (select * from gmms_galss_task_stock order by id desc limit 50000) as tbmin) and processcard_id = lckNo;
                if lck_xc = 0 then 
                    select count(*) into lck_xc from gmms_galss_task_buffer 
                    where id>(select min(id) from (select * from gmms_galss_task_stock order by id desc limit 50000) as tbmin) and processcard_id = lckNo;
                end if;
                
                if lck_xc = 0
                then 
                    set back_Num=4;
                    set back_Msg = "绑定失败:当前流程卡还在冷加工工艺段或输入错误,暂时无法绑定!";
                else    
                     Update gmms_drop_frame_2 set processcard_Id = lckNo ,state = '使用中',processcard_count = lck_xc,surplus_count= lck_xc where id= RId;
--               Update gmms_drop_frame_2 set processcard_Id = lckNo ,state = '使用中',processcard_count = (SELECT count(1) FROM gmms_galss_task_stock WHERE processcard_id = lckNo),surplus_count= (SELECT count(1)     FROM gmms_galss_task_stock WHERE processcard_id = lckNo) where id= RId;
                Update gmms_liuchengka set Occupied = RId where liuchengka = lckNo;
                set back_Num=1;
                set back_Msg = "绑定成功:流程卡绑定成功!";
                end if;
            else 
                set back_num = 2;
                set back_Msg = "绑定失败:当前流程卡已经被其他工位绑定,无法再次绑定!";
            end if;
            
    else 
            set back_num = 3;
            set back_Msg = "绑定失败:当前上片位已绑定流程卡,无法再次绑定!";
    end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for glass_log_new
-- ----------------------------
DROP PROCEDURE IF EXISTS `glass_log_new`;
delimiter ;;
CREATE PROCEDURE `glass_log_new`(in gid bigint,in work_segment varchar(50))
BEGIN
    DECLARE cr_work_name varchar(50);
    DECLARE done int default(0);
    #Routine body goes here...
    declare cur1 cursor for
              SELECT work_name from gmms_glass_log_config where segment=work_segment group by work_name;
                DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1;
    
      SELECT main_id,line,area into @p1,@p2,@p3 from gmms_glass_log where glass_id=gid and parent_id is null and segment_name=work_segment LIMIT 1;
        
        
             INSERT INTO gmms_glass_log (
main_id
,glass_id
,segment_name
,work_name
,line
,begin_time
,end_time
,`status`
,parent_id
,area)
values (@p1,gid,work_segment,null,@p2,null,null,0,null,@p3);
SET @zid=LAST_INSERT_ID();
 
open cur1;
loop1: loop
        FETCH  cur1 into cr_work_name;
            if done=1 then 
                LEAVE loop1;
            end if;
                     INSERT INTO gmms_glass_log (
main_id
,glass_id
,segment_name
,work_name
,line
,begin_time
,end_time
,`status`
,parent_id
,area)
values (@p1,gid,work_segment,cr_work_name,@p2,null,null,0,@zid,@p3);    
end loop loop1;
close cur1;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for HollowSlicecage
-- ----------------------------
DROP PROCEDURE IF EXISTS `HollowSlicecage`;
delimiter ;;
CREATE PROCEDURE `HollowSlicecage`(in sendMessageHex varchar(255),in machineids BIGINT,out messagedate varchar(255))
BEGIN
    #理片笼存储过程
    #找到当前机器标志位
    #查询机器逻辑表中对应的逻辑进行对应的步骤
    DECLARE machinedisposeids int DEFAULT 0;
    DECLARE dates varchar(255);
    DECLARE findplc varchar(255);
    DECLARE findmes varchar(255);
    DECLARE taskplc varchar(255);
    DECLARE taskmes varchar(255);
    DECLARE messagedates varchar(255) DEFAULT '';
    set messagedate=messagedates;
 
 
    select machine_type_id,remarks into @mtid,@remarks from gmms_machine where id=machineids;
    
 
    
    select mf.flag into @完成标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='完成字';
    
    select mf.flag into @请求标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='请求字';
    
    select mf.flag into @发送标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='发送字';
    
    select mf.flag into @完成确认标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='完成确认字';
    
    set findplc = substring(sendMessageHex,(cast(@完成标志位 as UNSIGNED INTEGER)*4)+19,4);
    set taskplc = substring(sendMessageHex,(cast(@请求标志位 as UNSIGNED INTEGER)*4)+19,4);
    set taskmes = substring(sendMessageHex,(cast(@发送标志位 as UNSIGNED INTEGER)*4)+19,4);
    set findmes = substring(sendMessageHex,(cast(@完成确认标志位 as UNSIGNED INTEGER)*4)+19,4);
    select taskplc;
    select taskmes;
    select findplc;
    select findmes;
    
    #完成逻辑查询
    select count(*),md.id into @完成数量,@完成逻辑编号 from gmms_machine_dispose md join gmms_machine_type mt on md.machine_type_id=mt.id where md.machine_type_id=@mtid  and md.plc_font_type='完成字' and md.mes_font_type='完成确认字' and md.plc_font_value=findplc and md.mes_font_value=findmes;
    
    #请求逻辑查询
    select count(*),md.id into @请求数量,@请求逻辑编号 from gmms_machine_dispose md join gmms_machine_type mt on md.machine_type_id=mt.id where md.machine_type_id=@mtid  and md.plc_font_type='请求字' and md.mes_font_type='发送字' and md.plc_font_value=taskplc and md.mes_font_value=taskmes;
    
    #判断逻辑是否存在
    if @完成数量=1 or @请求数量=1 then
    
        #判断完成逻辑是否为空
        if @完成逻辑编号!=0 then
            set machinedisposeids=@完成逻辑编号;
            
        #判断请求逻辑是否为空
        elseif @请求逻辑编号!=0 then
            set machinedisposeids=@请求逻辑编号;
        end if;
        #查询当前执行逻辑进行判断
        select logic,return_value into @ExecutionLogic,@returnvalue from gmms_machine_dispose where id=machinedisposeids;
        select @ExecutionLogic;
        if @ExecutionLogic='任务清空' then
                set dates=CONCAT(@returnvalue,"00000000000000000000");
                call message(dates,'000a',@date);
                set messagedate=@date;
        elseif @ExecutionLogic='完成清空' then
                call message(@returnvalue,'0014',@date);
                set messagedate=@date;
        elseif @ExecutionLogic='任务完成' then
                call HollowSlicecageFinsh(machineids,machinedisposeids,1,@messagedate);
                set messagedate=@messagedate;
         elseif @ExecutionLogic='任务失败' then
                call HollowSlicecageFinsh(machineids,machinedisposeids,2,@messagedate);
                set messagedate=@messagedate;        
        elseif @ExecutionLogic='任务请求' then
                call HollowSlicecageSend(machineids,@returnvalue,1,@messagedate);
                set messagedate=@messagedate;
         end if;
    end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for HollowSlicecageFinsh
-- ----------------------------
DROP PROCEDURE IF EXISTS `HollowSlicecageFinsh`;
delimiter ;;
CREATE PROCEDURE `HollowSlicecageFinsh`(in machineids BIGINT,in machinedisposeids BIGINT,in flag int,out messagedate varchar(255))
BEGIN
    #理片笼完成存储过程
    #判断完成,破损,直通
    DECLARE y int DEFAULT 0;
    DECLARE processcardid2 varchar(255);
    DECLARE messagedates varchar(255) DEFAULT '';
    DECLARE ischuku_ varchar(255) DEFAULT '';
    set messagedate=messagedates;
    
    select machine_type_id,work_id into @mtid,@work_groups from gmms_machine where id=machineids;
    
    
    select return_value into @returnvalue from gmms_machine_dispose where id=machinedisposeids;
    
    SELECT type_id,id,slicecage_rank,work_state,processcard_id into @type_id,@id,@slicecage_rank,@work_state,@processcard_id from gmms_galss_task_shelf 
    where work_procedure='理片' and (work_state='进库中' or work_state='出库中')  order by rank ASC limit 1;
    select ischu into ischuku_ from gmms_liuchengka where liuchengka=@processcard_id;
    #完成
    if flag=1 then
        if @work_state='出库中' then 
            #出库
            if ischuku_='出库' then
                update gmms_slicecage_tempering as st LEFT JOIN gmms_galss_task_shelf as gs on st.id=gs.slicecage_rank
                set gs.work_state='已出库',gs.finsh_time=now(),gs.slicecage_rank=null,
                st.state='空闲',st.count=0,st.type_id=null,st.processcard_id=null 
                where gs.slicecage_rank is not null and gs.id=@id;
            else
                update gmms_slicecage_tempering as st LEFT JOIN gmms_galss_task_shelf as gs on st.id=gs.slicecage_rank
                set gs.work_state='已出库',gs.finsh_time=now(),gs.slicecage_rank=null,gs.stop_rank=stop_position,
                st.state='空闲',st.count=0,st.type_id=null,st.processcard_id=null 
                where gs.slicecage_rank is not null and gs.id=@id;
            end if;        
        else 
            #进库
            update gmms_slicecage_tempering as st LEFT JOIN gmms_galss_task_shelf as gs on st.id=gs.slicecage_rank
            set gs.work_state='已进库',st.state='使用中',st.count=1 
            where gs.id=@id;
        end if;
        
         call message(@returnvalue,'0014',@date);
         set messagedate=@date;
        insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,"",NOW(),'收到完成',"",messagedate);
    #破损
    elseif flag=2 then
        if @work_state='出库中' then 
            #出库
            update gmms_slicecage_tempering as st LEFT JOIN gmms_galss_task_shelf as gs on st.id=gs.slicecage_rank
            set gs.work_state='已进库',st.state='使用中'
            where gs.slicecage_rank is not null and gs.id=@id;
        elseif @work_state='进库中' then 
            #进库
            update gmms_slicecage_tempering as st LEFT JOIN gmms_galss_task_shelf as gs on st.id=gs.slicecage_rank
            set gs.work_state='等待中',gs.finsh_time=now(),gs.slicecage_rank=null,
            st.state='空闲',st.count=0,st.type_id=null,st.processcard_id=null 
            where gs.id=@id;            
        end if;
--         UPDATE gmms_galss_task_shelf SET work_state='破损',slicecage_rank=null 
--         where id=@id;
        call message(@returnvalue,'0014',@date);
        set messagedate=@date;
        insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,"",NOW(),'收到失败',"",messagedate);
 
    end if;
    
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for HollowSlicecageSend
-- ----------------------------
DROP PROCEDURE IF EXISTS `HollowSlicecageSend`;
delimiter ;;
CREATE PROCEDURE `HollowSlicecageSend`(in machineids BIGINT,in returnvalue varchar(255),in flags int,out messagedate varchar(255))
BEGIN
    #理片笼请求存储过程
    #判断是进片还是出片还是进出片请求
    #发送数据:玻璃编号,理片笼架子
    DECLARE a int DEFAULT 0;
    DECLARE dates varchar(255);
    DECLARE messagedates varchar(255) DEFAULT '';
    DECLARE processcardid varchar(255) DEFAULT null;
    DECLARE waitingcount int DEFAULT 0;
    DECLARE notsliceagecount int DEFAULT 0;
    DECLARE nottaizi int DEFAULT 0;
    DECLARE Nullsliceagecount int DEFAULT 0;
    DECLARE rk int DEFAULT 0;
    DECLARE ischuku_ varchar(255) DEFAULT '';
    set messagedate=messagedates;
    
    SET @galss_id=NULL;
    select machine_type_id,work_id,remarks into @mtid,@work_groups,@remarks from gmms_machine where id=machineids;
    SET @lastpos=null;
    SELECT `value` into @lastpos from gmms_var where varname='last_pos' and groups=@work_groups;
        
    if flags=1 then
            #找到有任务的第一个工位,流程卡 默认B  A
            select lk.liuchengka,lk.ischu into processcardid,ischuku_ from gmms_drop_frame_5 as dr5 
            left join gmms_shelf_rack_2 as sr on dr5.rank=sr.id
            left join gmms_liuchengka as lk on sr.processcard_id=lk.liuchengka
            where groups_=3 and drop_groups=1 and dr5.sign=3 and sr.id is not null and lk.liuchengka is not null and 
            lk.current_status='正在工作' and lk.current_work_position='理片';
            
            #未配对的数量
            select count(*) into notsliceagecount from gmms_galss_task_shelf 
            where processcard_id=processcardid and (slicecage_rank<=0 or slicecage_rank is null) 
            and stop_position>0 and stop_position!=stop_rank and work_state!='破损';
            
            select count(*) into nottaizi from gmms_galss_task_shelf 
            where processcard_id=processcardid and (slicecage_rank<=0 or slicecage_rank is null) 
            and stop_position>0 and work_state!='破损' and work_procedure!='钢化后下片';
            
            SELECT count(*) into waitingcount from gmms_slicecage_tempering where state="等待中";
            select notsliceagecount,ischuku_,nottaizi;
            if notsliceagecount=0 or (ischuku_='出库' and nottaizi=0) then
                #出片
                if (ischuku_='出库' and nottaizi=0) then
                    SELECT  b.id,a.slicecage_rank,a.count,a.type_id,b.galss_id,b.edg_width,b.edg_height 
                    into @taskids,rk,@count,@type_id,@galss_id,@width,@height from gmms_slicecage_tempering a 
                    left join gmms_galss_task_shelf b on a.slicecage_rank=b.slicecage_rank 
                    where b.slicecage_rank is not null and a.processcard_id=processcardid and a.state='使用中' and a.flag=0 
                    order by stop_rank asc limit 0,1;
                else
                    SELECT  b.id,a.slicecage_rank,a.count,a.type_id,b.galss_id,b.edg_width,b.edg_height 
                    into @taskids,rk,@count,@type_id,@galss_id,@width,@height from gmms_slicecage_tempering a 
                    left join gmms_galss_task_shelf b on a.slicecage_rank=b.slicecage_rank 
                    where b.slicecage_rank is not null and a.processcard_id=processcardid and a.state='使用中' and a.flag=0 
                    order by stop_position asc limit 0,1;
                end if;
                
                if @galss_id is not null then                    
                    call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
                    call intTo2ByteHex10_16_4(rk,@rks);
                    call intTo2ByteHex10_16_4(@width,@widths);
                    call intTo2ByteHex10_16_4(@height,@heights);
                    set dates=CONCAT('0002',@galss_ids,@rks,@widths,@heights);
                    call message(dates,'000a',@date);
                    set messagedate=@date;                    
                    if messagedate is not null then
                        update gmms_slicecage_tempering as st LEFT JOIN gmms_galss_task_shelf as gs on st.id=gs.slicecage_rank
                        set gs.work_state='出库中',st.state='出库中'
                        where gs.slicecage_rank is not null and gs.id=@taskids;
                        UPDATE gmms_var SET Value=rk where varname='last_pos' and groups=@work_groups;
                        insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,"",NOW(),'发送出库任务',"",messagedate);
                    end if;
                end if;
            elseif waitingcount=0 then
                #提前移动
                select count(*) into Nullsliceagecount from gmms_slicecage_tempering 
                where state="空闲" and count=0 and flag=0 and gourp=@work_groups;
                SELECT id into rk from gmms_slicecage_tempering 
                where state="空闲" and count=0 and flag=0 and gourp=@work_groups  
                order by ABS(slicecage_rank-@lastpos)  limit 1;
                select rk;
                if rk>0 then
                    if Nullsliceagecount=80 then
                        UPDATE gmms_slicecage_tempering set state='等待中' where slicecage_rank=rk and gourp=@work_groups;
                        UPDATE gmms_var set value=rk where varname='last_pos' and groups=@work_groups;
                    else
                        call intTo2ByteHex10_16_4(rk,@rks);
                        set dates=CONCAT('0001','0000',@rks);
                        call message(dates,'000a',@date);
                        set messagedate=@date;
                        if messagedate is not null then
                            UPDATE gmms_slicecage_tempering set state='等待中' where slicecage_rank=rk and gourp=@work_groups;
                            UPDATE gmms_var set value=rk where varname='last_pos' and groups=@work_groups;
                            insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,"",NOW(),'发送提前移动任务',"",messagedate);
                        end if;
                    end if;                
                end if;
                    
            elseif waitingcount=1 then
                select id,stop_rank,type_id,galss_id,processcard_id,width,height 
                into @id,@rankid,@type_id,@galss_id,processcardid,@width,@height from gmms_galss_task_shelf 
                where work_procedure='理片' and work_state='等待中' and processcard_id= processcardid order by stop_rank desc limit 1;
                #进库
                if @rankid is not null then            
                    SET rk=0;
                    SELECT id into rk from gmms_slicecage_tempering where state="等待中" limit 1;                                                                    
                    call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
                    call intTo2ByteHex10_16_4(rk,@rks);
                    set dates=CONCAT('0001',@galss_ids,@rks);
                    call message(dates,'000a',@date);
                    set messagedate=@date;
                    if messagedate is not null then
                        UPDATE gmms_galss_task_shelf set slicecage_rank=rk,work_procedure='理片',work_state='进库中' 
                        WHERE id=@id and processcard_id=processcardid;
                        UPDATE gmms_slicecage_tempering set state='进库中',count=1,type_id=@type_id,processcard_id=processcardid 
                        where slicecage_rank=rk and gourp=@work_groups;
                        insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,"",NOW(),'发送理片任务',IFNULL(@galss_id,0),messagedate);
                    end if;
 
                end if;
            end if;            
    
    elseif flags=2 then
        select 1;
    end if;
        
select dates;
    
    
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for HollowTask
-- ----------------------------
DROP PROCEDURE IF EXISTS `HollowTask`;
delimiter ;;
CREATE PROCEDURE `HollowTask`()
BEGIN
DECLARE t_error INTEGER DEFAULT 0;
DECLARE c INTEGER DEFAULT 0;
DECLARE y int DEFAULT 0;
DECLARE processcardid2 varchar(255);
 
DECLARE _isSucess varchar(255);
 
DECLARE _Content varchar(255);
    DECLARE    CONTINUE HANDLER FOR SQLEXCEPTION SET t_error = 1;                                            
                        
#中空任务
select  count(*) into @count1 from 
(select count(*) as ccc,a.parent_liuchengka,b.child_count from gmms_liuchengka  a 
inner join gmms_liuchengka b on a.parent_liuchengka=b.liuchengka inner 
join  gmms_shelf_rack_2 c on 
a.liuchengka=c.processcard_id 
where c.sign=2 and b.gongyi='中空' 
group by a.parent_liuchengka ,b.child_count) aa
where aa.child_count=aa.ccc;
 
while c<@count1 do
    select  aa.parent_liuchengka into @parent_liuchengka from 
(select count(*) as ccc,a.parent_liuchengka,b.child_count from gmms_liuchengka  a inner join gmms_liuchengka b on a.parent_liuchengka=b.liuchengka inner join  gmms_shelf_rack_2 c on 
a.liuchengka=c.processcard_id where c.sign=2 and b.gongyi='中空' group by a.parent_liuchengka ,b.child_count) aa
where aa.child_count=aa.ccc limit c,1;
    set @parent_liuchengka1= substring(@parent_liuchengka, 2, 13);
    if @parent_liuchengka1 is not null then
        select count(*) into @count2 from gmms_raw_file_2 where file_name=@parent_liuchengka1;
        if @count2=0 then
            select count(*) into @count8 from gmms_shelf_rack_2 where processcard_id like CONCAT('%',@parent_liuchengka1,'%') and orientation='A';
            select count(*) into @count9 from gmms_shelf_rack_2 where processcard_id like CONCAT('%',@parent_liuchengka1,'%') and orientation='B';
            if @count8!=3 or @count9!=3 then
                insert into gmms_raw_file_2 (file_name,state,operator,create_time) values(@parent_liuchengka1,'未领取',0,NOW());
            else
                select number into @number from gmms_shelf_rack_2 where processcard_id like CONCAT('%',@parent_liuchengka1,'%') order by number limit 0,1;
                select noodles into @noodles from gmms_drop_frame_2 where groups=20 and flag=1;
                select count(*) into @count10 from gmms_shelf_task_2 where shelf_rack_id=@number and load_rack=@noodles and task_type='从仓位到旋转位' and groups=0 and line=3 and (task_state='正在工作' or task_state='等待中');
                if @count10=0 and @number is not null then
                    call y_TemperingAddShelftask(1,@number,@noodles,9, _isSucess, _Content);
                end if;
            end if;
            
        end if;
    end if;
    
set c=c+1;
end while;
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for Horizontal
-- ----------------------------
DROP PROCEDURE IF EXISTS `Horizontal`;
delimiter ;;
CREATE PROCEDURE `Horizontal`(in sendMessageHex varchar(255),in machineids BIGINT,out messagedate varchar(255),out msg varchar(255))
BEGIN
    #理片笼存储过程
    #找到当前机器标志位
    #查询机器逻辑表中对应的逻辑进行对应的步骤
    DECLARE machinedisposeids int DEFAULT 0;
    DECLARE dates varchar(255);
    DECLARE findplc1 varchar(255);
    DECLARE findmes1 varchar(255);
    DECLARE taskplc1 varchar(255);
    DECLARE taskmes1 varchar(255);
    DECLARE findplc2 varchar(255);
    DECLARE findmes2 varchar(255);
    DECLARE taskplc2 varchar(255);
    DECLARE taskmes2 varchar(255);
    DECLARE messagedates varchar(255) DEFAULT '';
    DECLARE texts varchar(255) DEFAULT '';
    DECLARE IsExistChu varchar(255);
    #2023/11/13   查看理片时间
    set @create_time1_=null;
    set @end_time1_=null;
    set @create_time1_=SYSDATE();
    
    
    
    set messagedate=messagedates;
    set @log_task="";
        SET msg:='Slicecage  查配置';    
    select machine_type_id,remarks into @mtid,@remarks from gmms_machine where id=machineids;
    
 
    
    select mf.flag into @进完成标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='进完成字';
    select mf.flag into @出完成标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='出完成字';
    
    select mf.flag into @进请求标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='进请求字';
    select mf.flag into @出请求标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='出请求字';
    
    select mf.flag into @进发送标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='进发送字';
    select mf.flag into @出发送标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='出发送字';
    
    select mf.flag into @进完成确认标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='进完成确认字';
    select mf.flag into @出完成确认标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='出完成确认字';
    
    set findplc1 = substring(sendMessageHex,(cast(@进完成标志位 as UNSIGNED INTEGER)*4)+19,4);
    set taskplc1 = substring(sendMessageHex,(cast(@进请求标志位 as UNSIGNED INTEGER)*4)+19,4);
    set taskmes1 = substring(sendMessageHex,(cast(@进发送标志位 as UNSIGNED INTEGER)*4)+19,4);
    set findmes1 = substring(sendMessageHex,(cast(@进完成确认标志位 as UNSIGNED INTEGER)*4)+19,4);
    
    set findplc2 = substring(sendMessageHex,(cast(@出完成标志位 as UNSIGNED INTEGER)*4)+19,4);
    set taskplc2 = substring(sendMessageHex,(cast(@出请求标志位 as UNSIGNED INTEGER)*4)+19,4);
    set taskmes2 = substring(sendMessageHex,(cast(@出发送标志位 as UNSIGNED INTEGER)*4)+19,4);
    set findmes2 = substring(sendMessageHex,(cast(@出完成确认标志位 as UNSIGNED INTEGER)*4)+19,4);
    -- 修改
    set IsExistChu = substring(sendMessageHex,(8*4)+19,4);  
 
    
--     select taskplc1;
--     select taskmes1;
--     select findplc1;
--     select findmes1;
--     
--     select taskplc2;
--     select taskmes2;
--     select findplc2;
--     select findmes2;
--     
 
    
    #完成逻辑查询
    select count(*),md.id into @进完成数量,@进完成逻辑编号 from gmms_machine_dispose md join gmms_machine_type mt on md.machine_type_id=mt.id where md.machine_type_id=@mtid  and md.plc_font_type='进完成字' and md.mes_font_type='进完成确认字' and md.plc_font_value=findplc1 and md.mes_font_value=findmes1;
    
    select count(*),md.id into @出完成数量,@出完成逻辑编号 from gmms_machine_dispose md join gmms_machine_type mt on md.machine_type_id=mt.id where md.machine_type_id=@mtid  and md.plc_font_type='出完成字' and md.mes_font_type='出完成确认字' and md.plc_font_value=findplc2 and md.mes_font_value=findmes2;
    
    #请求逻辑查询
    select count(*),md.id into @进请求数量,@进请求逻辑编号 from gmms_machine_dispose md join gmms_machine_type mt on md.machine_type_id=mt.id where md.machine_type_id=@mtid  and md.plc_font_type='进请求字' and md.mes_font_type='进发送字' and md.plc_font_value=taskplc1 and md.mes_font_value=taskmes1;
    
    select count(*),md.id into @出请求数量,@出请求逻辑编号 from gmms_machine_dispose md join gmms_machine_type mt on md.machine_type_id=mt.id where md.machine_type_id=@mtid  and md.plc_font_type='出请求字' and md.mes_font_type='出发送字' and md.plc_font_value=taskplc2 and md.mes_font_value=taskmes2;
    
    
    #判断逻辑是否存在
    if @进完成数量=1 or @出完成数量=1 or @进请求数量=1 or @出请求数量=1 then
    
        #判断完成逻辑是否为空
        if @进完成逻辑编号!=0 then
            set machinedisposeids=@进完成逻辑编号;
            
        elseif @出完成逻辑编号!=0 then
            set machinedisposeids=@出完成逻辑编号;
            
        #判断请求逻辑是否为空
        elseif @进请求逻辑编号!=0 then
            set machinedisposeids=@进请求逻辑编号;
            
        elseif @出请求逻辑编号!=0 then
            set machinedisposeids=@出请求逻辑编号;
            
        end if;
        select machinedisposeids;
        set @ExecutionLogic=null;
        select count(*) into @chuansong from gmms_galss_task  
        where work_state='传送中' and work_procedure='理片' and engineering_id=(select file_name from gmms_raw_file where operator=1 and state='已领取');
        
        select count(*) into @chuansong1 from gmms_horizontal as gh 
        left join gmms_galss_task as gt on gh.id =gt.slicecage_rank 
        where gh.processcard_id is not null and gh.gourp=1 and gt.work_state='传送中' and gt.work_procedure='理片' and gt.engineering_id=(select file_name from gmms_raw_file where operator=1         and state='已领取');
        
        #查询当前执行逻辑进行判断
        select logic,return_value into @ExecutionLogic,@returnvalue from gmms_machine_dispose where id=machinedisposeids;
        select @ExecutionLogic;
        if taskmes2="0001" then
                set dates=CONCAT("0000","00000000000000000000000000000000");
                call message(dates,'000d',@date);
                set messagedate=@date;
        elseif @ExecutionLogic='出片完成' then
                call HorizontalFinsh(machineids,machinedisposeids,1,@messagedate);
                set messagedate=@messagedate;
        elseif @ExecutionLogic='进片完成' then
                call HorizontalFinsh(machineids,machinedisposeids,2,@messagedate);
                set messagedate=@messagedate;        
        elseif @ExecutionLogic='进片完成破损1' then
                call HorizontalFinsh(machineids,machinedisposeids,3,@messagedate);
                set messagedate=@messagedate;
        elseif @ExecutionLogic='进片完成破损2' then
                call HorizontalFinsh(machineids,machinedisposeids,4,@messagedate);
                set messagedate=@messagedate;
        elseif @ExecutionLogic='进片完成破损3' then
                call HorizontalFinsh(machineids,machinedisposeids,5,@messagedate);
                set messagedate=@messagedate;
         elseif @ExecutionLogic='出片完成破损1' then
                call HorizontalFinsh(machineids,machinedisposeids,6,@messagedate);
                set messagedate=@messagedate;
        elseif @ExecutionLogic='出片完成破损2' then
                call HorizontalFinsh(machineids,machinedisposeids,7,@messagedate);
                set messagedate=@messagedate;
        elseif @ExecutionLogic='出片完成破损3' then
                call HorizontalFinsh(machineids,machinedisposeids,8,@messagedate);
                set messagedate=@messagedate;
        elseif @ExecutionLogic='进完成清空' then
                call message(@returnvalue,'0016',@date);
                set messagedate=@date;
         elseif @ExecutionLogic='出完成清空' then
                call message(@returnvalue,'0018',@date);
                set messagedate=@date;
        elseif taskplc1='0001' and taskplc2='0001' then        
                call HorizontalSend(machineids,0001,IsExistChu,3,@messagedate,texts);
                set messagedate=@messagedate;
        elseif @ExecutionLogic='进片请求' then
                 call HorizontalSend(machineids,@returnvalue,IsExistChu,1,@messagedate,texts);
                set messagedate=@messagedate;
        elseif @ExecutionLogic='出片请求' then        
                 call HorizontalSend(machineids,@returnvalue,IsExistChu,2,@messagedate,texts);
                set messagedate=@messagedate;
        elseif @ExecutionLogic='出任务清空' then
                set dates=CONCAT(@returnvalue,"00000000000000000000000000000000");
                call message(dates,'000d',@date);
                set messagedate=@date;
         elseif @ExecutionLogic='进任务清空' then
                set dates=CONCAT(@returnvalue,"00000000");
                call message(dates,'000a',@date);
                set messagedate=@date;
        end if;
    end if;
    
    
--         if taskmes2="0001" then
--                 set dates=CONCAT("0000","00000000000000000000000000000000");
--                 call message(dates,'000d',@date);
--                 set messagedate=@date;
--         elseif @ExecutionLogic='进片完成' then
--                 call HorizontalFinsh(machineids,machinedisposeids,2,@messagedate);
--                 set messagedate=@messagedate;        
--         elseif @ExecutionLogic='进片完成破损1' then
--                 call HorizontalFinsh(machineids,machinedisposeids,3,@messagedate);
--                 set messagedate=@messagedate;
--         elseif @ExecutionLogic='进片完成破损2' then
--                 call HorizontalFinsh(machineids,machinedisposeids,4,@messagedate);
--                 set messagedate=@messagedate;
--         elseif @ExecutionLogic='进片完成破损3' then
--                 call HorizontalFinsh(machineids,machinedisposeids,5,@messagedate);
--                 set messagedate=@messagedate;
--         elseif @ExecutionLogic='进完成清空' then
--                 call message(@returnvalue,'0016',@date);
--                 set messagedate=@date;
--          elseif @ExecutionLogic='进片请求' and taskplc2='0000' then
--                 call HorizontalSend(machineids,@returnvalue,IsExistChu,1,@messagedate,texts);
--                 set messagedate=@messagedate;
--         elseif @ExecutionLogic='进任务清空' then
--                 set dates=CONCAT(@returnvalue,"00000000");
--                 call message(dates,'000a',@date);
--                 set messagedate=@date;
--                 
--          elseif @ExecutionLogic='出片完成' then
--                 call HorizontalFinsh(machineids,machinedisposeids,1,@messagedate);
--                 set messagedate=@messagedate;
--         elseif @ExecutionLogic='出片完成破损1' then
--                 call HorizontalFinsh(machineids,machinedisposeids,6,@messagedate);
--                 set messagedate=@messagedate;
--         elseif @ExecutionLogic='出片完成破损2' then
--                 call HorizontalFinsh(machineids,machinedisposeids,7,@messagedate);
--                 set messagedate=@messagedate;
--         elseif @ExecutionLogic='出片完成破损3' then
--                 call HorizontalFinsh(machineids,machinedisposeids,8,@messagedate);
--                 set messagedate=@messagedate;
--         elseif @ExecutionLogic='出完成清空' then
--                 call message(@returnvalue,'0018',@date);
--                 set messagedate=@date;
--         elseif taskplc1='0001' and taskplc2='0001' then        
--                 call HorizontalSend(machineids,0001,IsExistChu,3,@messagedate,texts);
--                 set messagedate=@messagedate;
--         elseif @ExecutionLogic='出片请求' then        
--                  call HorizontalSend(machineids,@returnvalue,IsExistChu,2,@messagedate,texts);
--                 set messagedate=@messagedate;
--         elseif @ExecutionLogic='出任务清空' then
--                 set dates=CONCAT(@returnvalue,"00000000000000000000000000000000");
--                 call message(dates,'000d',@date);
--                 set messagedate=@date;
--          end if;
--     end if;
    
    
    set @end_time1_=SYSDATE();
    set texts=CONCAT(IFNULL(taskplc1,'-'),'   ',IFNULL(taskplc2,'-'),'   ',IFNULL(findplc1,'-'),'   ',IFNULL(findplc2,'-'),'   ',IFNULL(@ExecutionLogic,'-'),'   传送1:',IFNULL(@chuansong1,'-'),'   ','   传送2:',IFNULL(@chuansong,'-'),'   ',IFNULL(texts,'-'));
    insert into A_LengLipian_copy1(create_time,end_time,content) values (@create_time1_,@end_time1_,texts);
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for HorizontalFinsh
-- ----------------------------
DROP PROCEDURE IF EXISTS `HorizontalFinsh`;
delimiter ;;
CREATE PROCEDURE `HorizontalFinsh`(in machineids BIGINT,in machinedisposeids BIGINT,in flag int,out messagedate varchar(255))
BEGIN
    #理片笼完成存储过程
    #判断完成,破损,直通
    DECLARE dates varchar(255);
    DECLARE messagedates varchar(255) DEFAULT '';
    set messagedate=messagedates;
    
    select machine_type_id,work_id into @mtid,@work_groups from gmms_machine where id=machineids;
    
    select file_name into @engineering_id from gmms_raw_file where operator=@work_groups and state='已领取';
    
    select return_value into @returnvalue from gmms_machine_dispose where id=machinedisposeids;
    
    select galss_id into @galss_id from gmms_galss_task where work_state='出库中' and work_procedure='理片' and engineering_id=@engineering_id limit 1;
    select @returnvalue;
    
    SELECT type_id,id,slicecage_rank,work_state into @type_id,@id ,@slicecage_rank,@work_state from   gmms_galss_task where work_procedure='理片'  and (work_state='进库中'
 or work_state='出库中' or work_state='传送中') and engineering_id=@engineering_id order by rank ASC limit 1;
 
 
 select slicecage_rank into @slicecage_rank1 from gmms_horizontal where id=@slicecage_rank;
    if @id is not null then
    select flag;
    #出片完成
    if flag=1 then
        SELECT type_id,id,slicecage_rank,work_state into @type_id,@id ,@slicecage_rank,@work_state from   gmms_galss_task where work_procedure='理片' and (work_state='出库中' or work_state='传送中') and engineering_id=@engineering_id order by rank ASC limit 1;
        
        
        select slicecage_rank into @slicecage_rank1 from gmms_horizontal where id=@slicecage_rank;
                if @work_state='出库中' then 
                    select count(*) into @counts from gmms_galss_task where work_procedure='理片' and work_state='出库中' and slicecage_rank=@slicecage_rank and engineering_id=@engineering_id;
                    if @counts=1 then
                        select max(out_rank) into @maxrank from gmms_galss_task where engineering_id=@engineering_id;
                        UPDATE gmms_galss_task SET work_state='已出库',finsh_time=now(),slicecage_rank=null,out_rank=@maxrank+1  where slicecage_rank=@slicecage_rank and work_state='出库中' and engineering_id=@engineering_id;    
                    else 
                        select galss_id into @galss_id1 from gmms_galss_task where work_procedure='理片' and work_state='出库中' and engineering_id=@engineering_id order by rank limit 0,1;
                        select galss_id into @galss_id2 from gmms_galss_task where work_procedure='理片' and work_state='出库中' and engineering_id=@engineering_id order by rank limit 1,1;
                        select max(out_rank) into @maxrank from gmms_galss_task where engineering_id=@engineering_id;
                        UPDATE gmms_galss_task SET work_state='已出库',finsh_time=now(),slicecage_rank=null,out_rank=@maxrank+1  where galss_id=@galss_id1 and work_state='出库中' and engineering_id=@engineering_id;
                        UPDATE gmms_galss_task SET work_state='已出库',finsh_time=now(),slicecage_rank=null,out_rank=@maxrank+2  where galss_id=@galss_id2 and work_state='出库中' and engineering_id=@engineering_id;
                    end if;    
                    UPDATE gmms_horizontal SET state='空闲'  ,count=0,type_id=null,processcard_id=null where slicecage_rank=@slicecage_rank1 and gourp=2;
                    
                elseif @work_state='传送中' then
                        select id into @slicecage_rankid from gmms_horizontal where slicecage_rank=@slicecage_rank1 and gourp=2;
                        UPDATE gmms_galss_task SET work_state='已进库',slicecage_rank=@slicecage_rankid  where work_state='传送中' and engineering_id=@engineering_id;
                        UPDATE gmms_horizontal SET state='使用中'  where slicecage_rank=@slicecage_rank1 and gourp=2;
                elseif @work_state='直通' then
                        select max(out_rank) into @maxrank from gmms_galss_task where engineering_id=@engineering_id;
                        UPDATE gmms_galss_task SET work_state='已出库',out_rank=@maxrank+1  where work_state='直通' and engineering_id=@engineering_id;
                end if;
                
        
        call message(@returnvalue,'0018',@date);
        set messagedate=@date;
 
    #进片完成
    elseif flag=2 then
        if @id is not null then
        SELECT type_id,id,slicecage_rank,work_state into @type_id,@id ,@slicecage_rank,@work_state from   gmms_galss_task where work_procedure='理片' and (work_state='进库中' or work_state='传送中') and engineering_id=@engineering_id order by rank ASC limit 1;
        select slicecage_rank into @slicecage_rank1 from gmms_horizontal where id=@slicecage_rank;
            if @work_state='进库中' then
                SELECT count(*) into @count from gmms_galss_task WHERE  slicecage_rank=@slicecage_rank and engineering_id=@engineering_id;
                UPDATE gmms_galss_task SET work_state='已进库' where slicecage_rank=@slicecage_rank and work_state='进库中' and engineering_id=@engineering_id;
                UPDATE gmms_horizontal SET state='使用中' ,count=@count  where id=@slicecage_rank and gourp=1; 
            elseif @work_state='传送中' then
                UPDATE gmms_horizontal SET state='空闲'  ,count=0,type_id=null,processcard_id=null where slicecage_rank=@slicecage_rank1 and gourp=1;
            end if;        
        call message(@returnvalue,'0016',@date);
        set messagedate=@date;
        end if;
--     #传送完成
--     elseif flag=3 then
--         SELECT count(*) into @count from gmms_galss_task WHERE  slicecage_rank=@slicecage_rank and engineering_id=@engineering_id;
--         UPDATE gmms_galss_task SET work_state='已进库' where slicecage_rank=@slicecage_rank and work_state='传送中' and slicecage_rank=@slicecage_rank and engineering_id=@engineering_id;
--         UPDATE gmms_horizontal SET state='使用中'  ,count=@count  where slicecage_rank=@slicecage_rank1 and gourp=1;
--         UPDATE gmms_horizontal SET state='空闲'  ,count=0,type_id=null,processcard_id=null where slicecage_rank=@slicecage_rank1 and gourp=2;
--         set dates=CONCAT(@returnvalue,"0000",@returnvalue);
--         call message(dates,'0014',@date);
--         set messagedate=@date;
        
    #出片完成破损1
    elseif flag=6 then
        select slicecage_rank into @slicecage_rank from gmms_galss_task where work_state=@work_state and engineering_id=@engineering_id limit 1;
        UPDATE gmms_galss_task SET work_state='破损',broken_state=1,slicecage_rank=null  where type_id=@type_id and work_state=@work_state and engineering_id=@engineering_id limit 1;
        update gmms_horizontal set state='空闲',count=0,type_id=null,processcard_id=null where state=@work_state and slicecage_rank=@slicecage_rank1 and gourp=2;
        call message(@returnvalue,'0018',@date);
        set messagedate=@date;
        
    #出片完成破损2
    elseif flag=7 then
        select slicecage_rank into @slicecage_rank from gmms_galss_task where work_state=@work_state and engineering_id=@engineering_id limit 2;
        UPDATE gmms_galss_task SET work_state='破损',broken_state=1,slicecage_rank=null  where type_id=@type_id and work_state=@work_state and engineering_id=@engineering_id limit 2;
        update gmms_horizontal set state='空闲',count=0,type_id=null,processcard_id=null where state=@work_state and slicecage_rank=@slicecage_rank1 and gourp=2;
        call message(@returnvalue,'0018',@date);
        set messagedate=@date;
        
    #出片完成破损3
    elseif flag=8 then
        select slicecage_rank into @slicecage_rank from gmms_galss_task where work_state=@work_state and engineering_id=@engineering_id;
        UPDATE gmms_galss_task SET work_state='破损',broken_state=1,slicecage_rank=null  where type_id=@type_id and work_state=@work_state and engineering_id=@engineering_id;
        update gmms_horizontal set state='空闲',count=0,type_id=null,processcard_id=null where state=@work_state and slicecage_rank=@slicecage_rank1 and gourp=2;
        call message(@returnvalue,'0018',@date);
        set messagedate=@date;
        
        
    #进片完成破损1
    elseif flag=3 then
        select slicecage_rank into @slicecage_rank from gmms_galss_task where work_state=@work_state and engineering_id=@engineering_id limit 1;
        UPDATE gmms_galss_task SET work_state='破损',broken_state=1,slicecage_rank=null  where type_id=@type_id and work_state=@work_state and engineering_id=@engineering_id limit 1;
        update gmms_horizontal set state='空闲',count=0,type_id=null,processcard_id=null where state=@work_state and slicecage_rank=@slicecage_rank1 and gourp=1;
        call message(@returnvalue,'0016',@date);
        set messagedate=@date;
        
    #进片完成破损2
    elseif flag=4 then
        select slicecage_rank into @slicecage_rank from gmms_galss_task where work_state='传送中' and engineering_id=@engineering_id limit 2;
        UPDATE gmms_galss_task SET work_state='破损',broken_state=1,slicecage_rank=null  where type_id=@type_id and work_state='传送中' and engineering_id=@engineering_id limit 2;
        update gmms_horizontal set state='空闲',count=0,type_id=null,processcard_id=null where state='传送中' and slicecage_rank=@slicecage_rank1 and gourp=1;
        call message(@returnvalue,'0016',@date);
        set messagedate=@date;
        
    #进片完成破损3
    elseif flag=5 then
        select slicecage_rank into @slicecage_rank from gmms_galss_task where work_state='传送中' and engineering_id=@engineering_id;
        UPDATE gmms_galss_task SET work_state='破损',broken_state=1,slicecage_rank=null  where type_id=@type_id and work_state='传送中' and engineering_id=@engineering_id;
        update gmms_horizontal set state='空闲',count=0,type_id=null,processcard_id=null where state='传送中' and slicecage_rank=@slicecage_rank1 and gourp=1;
        call message(@returnvalue,'0016',@date);
        set messagedate=@date;
 
    end if;
    end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for HorizontalSend
-- ----------------------------
DROP PROCEDURE IF EXISTS `HorizontalSend`;
delimiter ;;
CREATE PROCEDURE `HorizontalSend`(in machineids BIGINT,in returnvalue varchar(255),in isexistChu varchar(255),in flags int,out messagedate varchar(255),out ResultText varchar(255))
BEGIN
    #理片笼请求存储过程
    #判断是进片还是出片还是进出片请求
    #发送数据:玻璃编号,理片笼架子
    DECLARE a int DEFAULT 0;
    DECLARE ranks int DEFAULT 0;
    DECLARE dates varchar(255);
    DECLARE messagedates varchar(255) DEFAULT '';
    DECLARE maxw int DEFAULT 0;
    DECLARE maxh int DEFAULT 0;
    DECLARE minw int DEFAULT 0;
    DECLARE minh int DEFAULT 0;
    DECLARE kaobian varchar(255) DEFAULT null;
    set @create_time_=null;
    set @end_time_=null;
    set @create_time_=SYSDATE();
    set messagedate=messagedates;
    
 
select machine_type_id,work_id into @mtid,@work_groups from gmms_machine where id=machineids;
 
select @work_groups;
    
select file_name into @engineering_id from gmms_raw_file where operator=@work_groups and state='已领取';
 
select @engineering_id;
 
select var into @var from gmms_slicecage_pattern where groups=@work_groups;
 
select @var;
set @counts6=0;
set @counts7=0;
set @counts8=0;
set @counts9=0;
set @counts10=0;
set @Lp_Mode=0;
SET @发送字=0;
 
 
 
select count(*) into @counts6 from gmms_galss_task  where work_state='直通' and work_procedure='理片' and engineering_id=@engineering_id;
select count(*) into @counts7 from gmms_galss_task  where work_state='进库中' and work_procedure='理片' and engineering_id=@engineering_id;
select count(*) into @counts8 from gmms_galss_task  where work_state='出库中' and work_procedure='理片' and engineering_id=@engineering_id;
select count(*) into @counts9 from gmms_galss_task  where work_state='传送中' and work_procedure='理片' and engineering_id=@engineering_id;
 
select count(*) into @counts10 from gmms_horizontal as gh 
left join gmms_galss_task as gt on gh.id =gt.slicecage_rank 
where gh.processcard_id is not null and gh.gourp=1 and gt.work_state='传送中' and gt.work_procedure='理片' and gt.engineering_id=@engineering_id;
 
set @conts=null;
set @conts=CONCAT(IFNULL(flags,'-'),',',IFNULL(isexistChu,'-'),' count6:',IFNULL(@counts6,'-'),' count7:',IFNULL(@counts7,'-'),' count8:',IFNULL(@counts8,'-'),' count9:',IFNULL(@counts9,'-'),' count10:',IFNULL(@counts10,'-'));
 
#进出片
if @var='1' then
        #传送
    if flags=3 then
        if a=0 and @counts8=0 and @counts9=0 and isexistChu='0000' then
            set @kuneishu=0;
            select 库内数 into @kuneishu from processcard1 where 工程号=@engineering_id and 库内数>0 order by 库内数 desc  limit 0,1;
            select @kuneishu;
            select @work_groups;
            select count(*) into @counts from gmms_horizontal where state='空闲' and gourp=2;
            
                if (@kuneishu>0 or @counts<=1) and @counts6=0 then
                #出片
                SET @processcardid=null;
                set @rkid=null;
                set @rk=null;
                set @galss_id=null;
                select `value` into @lastid from gmms_var where varname='last_out_glass_id'and groups=@work_groups;
                select `value` into @lastpos from gmms_var where varname='last_pos'and groups=@work_groups;
                if @lastid is not null then
                    select @lastid;
                    select @lastpos;
                    select '进入';
                    
                    SELECT a.id,a.slicecage_rank,a.type_id,a.count,galss_id into @rkid,@rk,@type_id,@count,@galss_id from gmms_horizontal a 
                    INNER JOIN gmms_galss_task b on a.id=b.slicecage_rank INNER JOIN gmms_drop_frame c on b.processcard_id=c.processcard_id 
                    where a.state='使用中' and a.count>0 and a.type_id=@lastid and a.flag=0 and b.engineering_id=@engineering_id and  c.processcard_id is not null and a.gourp=2 and b.stop_position>0 
                    order by a.count desc, ABS(a.slicecage_rank-@lastpos) asc LIMIT 1;
                    select @rkid;
                    if @rk is not null and @rk<>0 then
                    select @rk;
                        UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
                            UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
                            UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
                            UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
                            set @galss_ids=null;
                            call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
                            select @galss_ids;
                            call intTo2ByteHex10_16_4(@rk,@rks);
                            set dates=CONCAT("0001",@galss_ids,"0000",@rks);
                            call message(dates,'000d',@date);
                            set messagedate=@date;
                            insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼出库1',@rk,@date);
                            set @发送字=1;
                            set a=1;
                    end if;
                end if;
                if @发送字=0 then
                    SELECT 流程卡 into @processcardid from processcard_ex where 下片位置 is not null and 库内数>0 and 总数-切割数=0 and 工程号=@engineering_id order by  总数-下架数  asc LIMIT 1;
                    IF @processcardid is  null then
                        select 2;
                            #  后使用  未完全切完的
                            SELECT 流程卡 into @processcardid from processcard_ex where 下片位置 is not null and 库内数>0 and 工程号=@engineering_id order by 总数-下架数  asc LIMIT 1;    
                    end if;
                    -- 看看空架 有没有 ,如果有  就找一个库能玻璃最多的下架
 
                    IF @processcardid is null then 
 
                        SET @drop_pos=null;
                        
                        select name1 into @name1 from namess where groups=@work_groups;
                        SELECT 流程卡,架号,总数,工程号 into @processcardid,@drop_frame,@processcard_count,@engineering_ids from processcard_ex 
                        where  (库内数>=@name1 or (库内数>0 and 总数<@name1)) and 工程号=@engineering_id order by  总数-库内数 LIMIT 1;
                        
                        #得到最小的 和最大的玻璃数据  判断往哪里靠边  2023-8-30
                        select MAX(width),MAX(height),MIN(width),MIN(height) into maxw,maxh,minw,minh from gmms_galss_task where processcard_id=@processcardid;
                        #if maxw<2400 and maxh<1900 and minw>599 and minh>349 then
                        if maxw<2400 and maxh<1900 and minw>529 and minh>349 then
                            set kaobian='机器人';
                        else
                            set kaobian='下片机';    
                        end if;
                        select kaobian;
                        if kaobian='下片机' then
                            select id into @drop_pos from gmms_drop_frame where state='空架' and groups=@work_groups and (stops=1 or stops=2) limit 1;
                        elseif kaobian='机器人' then
                            select id into @drop_pos from gmms_drop_frame where state='空架' and groups=@work_groups and (stops=3 or stops=4 or stops=5) limit 1;
                        end if;
                        set kaobian=null;
                        if @processcardid is not null and @drop_pos  is not null then                         
                            #  流程卡占架子
                            select @processcardid;
                            select @drop_pos;
                            select count(*) into @counts2 from gmms_galss_task where processcard_id=@processcardid and engineering_id=@engineering_id;
                            if @counts2>0 then 
                                UPDATE gmms_drop_frame set state='使用中',drop_frame=@drop_frame,processcard_id=@processcardid,processcard_count=@processcard_count,engineering_id=@engineering_id where id=@drop_pos;
                                INSERT into hn_user(update_time,add_time) VALUES(@processcardid,@work_groups);
                                UPDATE gmms_galss_task set stop_position=@drop_pos where processcard_id=@processcardid and engineering_id=@engineering_id;                
                            end if;
                        else
                            set @processcardid=null;
                            set @drop_pos=null;
                        end if;
                    end if;
                    if @processcardid is not null then 
                            SELECT @processcardid;    
                            #  选定大小和槽
                            SELECT  a.id,a.slicecage_rank,a.count,a.type_id,galss_id into @rkid,@rk,@count,@type_id,@galss_id from gmms_horizontal a 
                            inner join gmms_galss_task b on a.id=b.slicecage_rank  where a.processcard_id=@processcardid and a.state='使用中' and a.gourp=2 and a.flag=0 and engineering_id=@engineering_id 
                            order by b.width*b.height desc ,a.count DESC  limit 1;
                            select @rkid;
                            select @count;
                            select a;
                            if @rk is not null and @rk<>0 then
                            UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
                            UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
                            UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
                            UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
                            call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
                            call intTo2ByteHex10_16_4(@rk,@rks);
                            select @galss_ids,@rks,@date;
                            set dates=CONCAT("0001",@galss_ids,"0000",@rks);
                            call message(dates,'000d',@date);
                            set messagedate=@date;
                            insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼出库2',@rk,@date);
                            set a=1;
                            end if;
                        end if;
                    
                end if;
 
                end if;
            
        end if;
        select a;
        if a=0 and @counts7=0 and @counts8=0 and @counts9=0 then
        
            set @rk=null;
            set @LastGalssid=null;
            set @ProcesscardA1=null;
            set @ProcesscardA2=null;
            
--             select slicecage_rank into @rk from gmms_horizontal  
--             where (gourp=1 and state='使用中' and count>0 and flag=0) or (gourp=2 and state='空闲')  group by slicecage_rank having count(*)=2 order by count desc limit 1;
            
            #2023-11-14  YZX更新
            select 
            (SELECT b.id from gmms_horizontal a 
            INNER JOIN gmms_galss_task b on a.id=b.slicecage_rank 
            INNER JOIN gmms_drop_frame c on b.processcard_id=c.processcard_id 
            where a.state='使用中' and a.count>0 and a.type_id=ls1.value and a.flag=0 and b.engineering_id=grf.file_name and  c.processcard_id is not null and a.gourp=1 and b.stop_position>0 
            order by a.count desc, ABS(a.slicecage_rank-ls2.value) asc LIMIT 1),
            (SELECT 流程卡 from processcard_ex where 下片位置 is not null and 库内数>0 and 工程号=grf.file_name order by 总数-下架数  asc LIMIT 1) ,
            (SELECT 流程卡 from processcard_ex where (库内数>=ns.name1 or (库内数>0 and 总数<ns.name2)) and 工程号=grf.file_name order by  总数-库内数 LIMIT 1)
            INTO @LastGalssid,@ProcesscardA1,@ProcesscardA2
            from gmms_machine as gm 
            LEFT JOIN gmms_raw_file as grf on gm.work_id=grf.operator and grf.state='已领取'
            LEFT JOIN gmms_var as ls1 on gm.work_id=ls1.groups and ls1.varname='last_out_glass_id'
            LEFT JOIN gmms_var as ls2 on gm.work_id=ls2.groups and ls2.varname='last_pos'
            LEFT JOIN namess as ns on gm.work_id=ns.groups
            where gm.id=27;
            
            if @LastGalssid is not null then
                select hl1.slicecage_rank into @rk from gmms_horizontal as hl1 
                left join gmms_horizontal as hl2 on hl1.slicecage_rank=hl2.slicecage_rank
                where hl1.gourp=1 and hl2.gourp=2 and hl1.state='使用中' and hl1.count>0 and hl1.flag=0 and hl2.gourp=2 and hl2.state='空闲' 
                and hl1.slicecage_rank=(select slicecage_rank from gmms_galss_task where id=@LastGalssid);
            elseif @ProcesscardA1 is not null then
                select hl1.slicecage_rank into @rk from gmms_horizontal as hl1 
                left join gmms_horizontal as hl2 on hl1.slicecage_rank=hl2.slicecage_rank
                where hl1.gourp=1 and hl2.gourp=2 and hl1.state='使用中' and hl1.count>0 and hl1.flag=0 and hl2.gourp=2 and hl2.state='空闲' 
                and hl1.processcard_id=@ProcesscardA1 order by hl1.count desc limit 1;
            elseif @ProcesscardA2 is not null then
                select hl1.slicecage_rank into @rk from gmms_horizontal as hl1 
                left join gmms_horizontal as hl2 on hl1.slicecage_rank=hl2.slicecage_rank
                where hl1.gourp=1 and hl2.gourp=2 and hl1.state='使用中' and hl1.count>0 and hl1.flag=0 and hl2.gourp=2 and hl2.state='空闲' 
                and hl1.processcard_id=@ProcesscardA2 order by hl1.count desc limit 1;
            end if;            
            
            if @rk is null then
                select slicecage_rank into @rk from gmms_horizontal  
                where (gourp=1 and state='使用中' and count>0 and flag=0) or (gourp=2 and state='空闲')  group by slicecage_rank having count(*)=2 order by count desc limit 1;
            end if;
            select @rk;
            
                    
            if @rk is not null and @rk<>0 then
                select count(*) into @countstate from gmms_horizontal where  (state='出库中' or state='进库中');
                if @countstate=0 then
                UPDATE gmms_galss_task SET work_state='传送中' where slicecage_rank=@rk and engineering_id=@engineering_id;
                UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=1;
                select count,type_id,processcard_id into @count,@type_id,@processcard_id from gmms_horizontal where slicecage_rank=@rk and gourp=1;
                UPDATE gmms_horizontal SET state='进库中',count=@count,type_id=@type_id,processcard_id=@processcard_id where slicecage_rank=@rk and gourp=2;
                select count(*) into @counts from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id;
                select count(*) into @count1 from gmms_galss_task where work_state='直通' and work_procedure='理片' and engineering_id=@engineering_id;
                if @counts=1 then
                    if @type_id <>0 and (@processcard_id is not null or @processcard_id<>'') then
                        select galss_id into @galss_id1 from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id;
                        call intTo2ByteHex10_16_4(@galss_id1,@galss_ids1);
                        call intTo2ByteHex10_16_4(@rk,@rks);
                        set dates=CONCAT("00020000",@rks,"000200000000",@rks,"000000000000",@galss_ids1);
                        call message(dates,'000a',@date);
                        insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                            values (machineids,@work_groups,NOW(),'理片笼传送1',@rk,@date);
                        set messagedate=@date;
                        set a=1;
                    end if;
                else 
                    select galss_id into @galss_id1 from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id limit 1;
                    select galss_id into @galss_id2 from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id limit 2;
                    call intTo2ByteHex10_16_4(@galss_id1,@galss_ids1);
                    call intTo2ByteHex10_16_4(@galss_id2,@galss_ids2);
                    call intTo2ByteHex10_16_4(@rk,@rks);
                    set dates=CONCAT("00020000",@rks,"000200000000",@rks,"000000000000",@galss_ids1,@galss_id2);
                    call message(dates,'000a',@date);
                    set a=1;
                    set messagedate=@date;
                    insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                            values (machineids,@work_groups,NOW(),'理片笼传送2',@rk,@date);
                end if;
                end if;
                
            elseif @count1>0 then
                    set dates=CONCAT("000300000003","0003000000000003");
                    call message(dates,'000a',@date);
                    set messagedate=@date;
                    set a=1;
            
            end if;
        end if;
        
        if a=0 and @counts7=0 and @counts10=0 then
                #进片
                set @type_id=0;
                set @processcardid=null;
                select rank,type_id,galss_id,processcard_id,width,height,slicecage_rank into @rankid,@type_id,@galss_id,@processcardid,@width,@height,@rk from gmms_galss_task where work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id order by rank limit 1;
                if @galss_id is not null and @rk<>0 and @rk is not null then
                UPDATE gmms_galss_task set work_state='进库中',finsh_time=now() WHERE rank=@rankid and work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id;
                UPDATE gmms_horizontal set state='进库中',count=1,type_id=@type_id,processcard_id=@processcardid where slicecage_rank=@rk and gourp=1;
                call intTo2ByteHex10_16_4(@rankid,@rankids);
                call intTo2ByteHex10_16_4(@rk,@rks);
                set dates=CONCAT("0001",@rankids,@rks);
                call message(dates,'000a',@date);
                set messagedate=@date;
                insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼进库1',@rk,@date);
                end if;
        end if;
 
        
    #出片
    elseif flags=2 and @counts6=0 and @counts8=0 and @counts9=0 and isexistChu='0000' then
                SET @processcardid=null;
                set @rkid=null;
                set @rk=null;
                set @galss_id=null;
                select `value` into @lastid from gmms_var where varname='last_out_glass_id'and groups=@work_groups;
                select `value` into @lastpos from gmms_var where varname='last_pos'and groups=@work_groups;
                if @lastid is not null then
                    select @lastid;
                    SELECT a.id,a.slicecage_rank,a.type_id,a.count,galss_id into @rkid,@rk,@type_id,@count,@galss_id from gmms_horizontal a 
                    INNER JOIN gmms_galss_task b on a.id=b.slicecage_rank INNER JOIN gmms_drop_frame c on b.processcard_id=c.processcard_id 
                    where a.state='使用中' and a.count>0 and a.type_id=@lastid and a.flag=0 and b.engineering_id=@engineering_id and  c.processcard_id is not null and a.gourp=2 and b.stop_position>0 
                    order by a.count desc, ABS(a.slicecage_rank-@lastpos) asc LIMIT 1;
                    if @rk is not null and @rk<>0 then
                    select @rk;
                        UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
                            UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
                            UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
                            UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
                            call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
                            call intTo2ByteHex10_16_4(@rk,@rks);
                            set dates=CONCAT("0001",@galss_ids,"0000",@rks);
                            call message(dates,'000d',@date);
                            set messagedate=@date;
                            insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼出库3',@rk,@date);
                            set @发送字=1;
                    end if;
                end if;
                if @发送字=0 then
                    SELECT 流程卡 into @processcardid from processcard_ex where 下片位置 is not null and 库内数>0 and 总数-切割数=0 and 工程号=@engineering_id order by  总数-下架数  asc LIMIT 1;
                    IF @processcardid is  null then
                        select 2;
                            #  后使用  未完全切完的
                            SELECT 流程卡 into @processcardid from processcard_ex where 下片位置 is not null and 库内数>0 and 工程号=@engineering_id order by 总数-下架数  asc LIMIT 1;    
                    end if;
                    -- 看看空架 有没有 ,如果有  就找一个库能玻璃最多的下架
                    IF @processcardid is null then 
 
                        SET @drop_pos=null;
                        SELECT 流程卡,架号,总数,工程号 into @processcardid,@drop_frame,@processcard_count,@engineering_ids from processcard_ex 
                        where  (库内数>=@name1 or (库内数>0 and 总数<@name1)) and 工程号=@engineering_id order by  总数-库内数 LIMIT 1;
                            
                        #得到最小的 和最大的玻璃数据  判断往哪里靠边  2023-8-30
                        select MAX(width),MAX(height),MIN(width),MIN(height) into maxw,maxh,minw,minh from gmms_galss_task where processcard_id=@processcardid;
                        if maxw<2400 and maxh<1900 and minw>599 and minh>349 then
                            set kaobian='机器人';
                        else
                            set kaobian='下片机';    
                        end if;
                        if kaobian='下片机' then
                            select id into @drop_pos from gmms_drop_frame where state='空架' and groups=@work_groups and (stops=1 or stops=2) limit 1;
                        elseif kaobian='机器人' then
                            select id into @drop_pos from gmms_drop_frame where state='空架' and groups=@work_groups and (stops=3 or stops=4 or stops=5) limit 1;
                        end if;
                        set kaobian=null;
                        
                        if @processcardid is not null and @drop_pos  is not null then 
                            select name1 into @name1 from namess where groups=@work_groups;
                            #  流程卡占架子
                            select count(*) into @counts2 from gmms_galss_task where processcard_id=@processcardid and engineering_id=@engineering_id;
                            if @counts2>0 then 
                                UPDATE gmms_drop_frame set state='使用中',drop_frame=@drop_frame,processcard_id=@processcardid,processcard_count=@processcard_count,engineering_id=@engineering_id where id=@drop_pos;
                                INSERT into hn_user(update_time,add_time) VALUES(@processcardid,@work_groups);
                                UPDATE gmms_galss_task set stop_position=@drop_pos where processcard_id=@processcardid and engineering_id=@engineering_id;                
                            end if;
                        else
                            set @processcardid=null;
                            set @drop_pos=null;
                        end if;
                    end if;
                    if @processcardid is not null then 
                            SELECT @processcardid;    
                            #  选定大小和槽
                            SELECT  a.id,a.slicecage_rank,a.count,a.type_id,galss_id into @rkid,@rk,@count,@type_id,@galss_id from gmms_horizontal a 
                            inner join gmms_galss_task b on a.id=b.slicecage_rank  
                            where a.processcard_id=@processcardid and a.state='使用中' and a.gourp=2 and a.flag=0 and engineering_id=@engineering_id 
                            order by b.width*b.height desc ,a.count DESC  limit 1;
                            select @count;
                            if @rk is not null and @rk<>0 then
                            UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
                            UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
                            UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
                            UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
                            call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
                            call intTo2ByteHex10_16_4(@rk,@rks);
                            set dates=CONCAT("0001",@galss_ids,"0000",@rks);
                            call message(dates,'000d',@date);
                            set messagedate=@date;
                            insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼出库4',@rk,@date);
                            end if;
                        end if;
                    
                end if;
 
                
    #进片
    elseif flags=1 and @counts7=0 and @counts10=0 then
                set @conts=CONCAT(IFNULL(@conts,'-'),' ','进片');
                set @rk=null;
                set @type_id=0;
                set @processcardid=null;
                select rank,type_id,galss_id,processcard_id,width,height,slicecage_rank into @rankid,@type_id,@galss_id,@processcardid,@width,@height,@rk from gmms_galss_task where work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id order by rank limit 1;
                if @galss_id is not null and @rk<>0 and @rk is not null then
                UPDATE gmms_galss_task set work_state='进库中',finsh_time=now() WHERE rank=@rankid and work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id;
                UPDATE gmms_horizontal set state='进库中',count=1,type_id=@type_id,processcard_id=@processcardid where slicecage_rank=@rk and gourp=1;
                call intTo2ByteHex10_16_4(@rankid,@rankids);
                call intTo2ByteHex10_16_4(@rk,@rks);
                set dates=CONCAT("0001",@rankids,@rks);
                call message(dates,'000a',@date);
                set messagedate=@date;
                insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼进库2',@rk,@date);
                end if;
                set @conts=CONCAT(IFNULL(@conts,'-'),' ',IFNULL(@rk,'无任务'));
    end if;
 
#直通
-- elseif @var='2' then
-- 
-- 
#存笼
elseif @var='3' then
    if flags=3 and @counts7=0 then
    set @type_id=null;
    set @count=null;
        select slicecage_rank into @rk from gmms_horizontal  where (gourp=1 and state='使用中' and count>0 and flag=0) or (gourp=2 and state='空闲')  group by slicecage_rank having count(*)=2 order by count desc limit 1;
        select @rk;
        if @rk is not null and @counts8=0 and @counts9=0  then
                select count(*) into @countstate from gmms_horizontal where  (state='出库中' or state='进库中');
                if @countstate=0 then
              UPDATE gmms_galss_task SET work_state='传送中' where slicecage_rank=@rk and engineering_id=@engineering_id;
              UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=1;
               select count,type_id,processcard_id into @count,@type_id,@processcard_id from gmms_horizontal where slicecage_rank=@rk and gourp=1;
                
              UPDATE gmms_horizontal SET state='进库中',count=@count,type_id=@type_id,processcard_id=@processcard_id where slicecage_rank=@rk and gourp=2;
            select count(*) into @counts from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id;
            select @counts;
            if @counts=1 then
                if @type_id <>0 and (@processcard_id is not null or @processcard_id<>'') then
                    select galss_id into @galss_id1 from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id;
                    call intTo2ByteHex10_16_4(@galss_id1,@galss_ids1);
                    call intTo2ByteHex10_16_4(@rk,@rks);
                    set dates=CONCAT("00020000",@rks,"000200000000",@rks,"000000000000",@galss_ids1);
                    call message(dates,'000a',@date);
                    set messagedate=@date;
                    insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼传送3',@rk,@date);
                end if;
            else 
                     select @counts;
                end if;
            else 
                
                select galss_id into @galss_id1 from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id limit 1;
                select galss_id into @galss_id2 from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id limit 2;
                select @galss_id1,@galss_id2;
                call intTo2ByteHex10_16_4(@galss_id1,@galss_ids1);
                call intTo2ByteHex10_16_4(@galss_id2,@galss_ids2);
                call intTo2ByteHex10_16_4(@rk,@rks);
                set dates=CONCAT("00020000",@rks,"000200000000",@rks,"000000000000",@galss_ids1,@galss_id2);
                call message(dates,'000a',@date);
                set messagedate=@date;
                insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼传送4',@rk,@date);
            end if;
        elseif @counts10=0 then
            set @type_id=0;
            set @processcardid=null;
            select rank,type_id,galss_id,processcard_id,width,height,slicecage_rank into @rankid,@type_id,@galss_id,@processcardid,@width,@height,@rk from gmms_galss_task where work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id order by rank limit 1;
            if @galss_id is not null and @rk<>0 and @rk is not null then
                #UPDATE gmms_galss_task set slicecage_rank=@rk,work_procedure='理片',work_state='进库中' WHERE rank=@rankid and engineering_id=@engineering_id;
                UPDATE gmms_galss_task set work_state='进库中',finsh_time=now() WHERE rank=@rankid and work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id;
                UPDATE gmms_horizontal set state='进库中',count=1,type_id=@type_id,processcard_id=@processcardid where slicecage_rank=@rk and gourp=1;
                UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
                UPDATE gmms_var SET Value=@rankid where varname='last_out_glass_id' and groups=@work_groups;
                select @rankid,@rk;
                call intTo2ByteHex10_16_4(@rankid,@rankids);
                call intTo2ByteHex10_16_4(@rk,@rks);
                set dates=CONCAT("0001",@rankids,@rks);
                call message(dates,'000a',@date);
                set messagedate=@date;
                insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼进库3',@rk,@date);
            end if;
 
            
        end if;
        
 
 
                
    #进片
    elseif flags=1 and @counts7=0 and @counts10=0 then
                
        set @type_id=0;
                set @processcardid=null;
                select rank,type_id,galss_id,processcard_id,width,height,slicecage_rank into @rankid,@type_id,@galss_id,@processcardid,@width,@height,@rk from gmms_galss_task where work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id order by rank limit 1;
                if @galss_id is not null and @rk<>0 and @rk is not null then
                UPDATE gmms_galss_task set work_state='进库中',finsh_time=now() WHERE rank=@rankid and work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id;
                UPDATE gmms_horizontal set state='进库中',count=1,type_id=@type_id,processcard_id=@processcardid where slicecage_rank=@rk and gourp=1;
                call intTo2ByteHex10_16_4(@rankid,@rankids);
                call intTo2ByteHex10_16_4(@rk,@rks);
                UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
                UPDATE gmms_var SET Value=@rankid where varname='last_out_glass_id' and groups=@work_groups;
                set dates=CONCAT("0001",@rankids,@rks);
                call message(dates,'000a',@date);
                set messagedate=@date;
                
                insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼进库4',@rk,@date);
                end if;
                
    end if;
        
#出片
elseif @var='4' then
 
    if (flags=3 or flags=2) and @counts6=0 and @counts8=0 and @counts9=0 then
    
        SET @processcardid=null;
                set @rkid=null;
                set @rk=null;
                set @galss_id=null;
                select @lastid;
                select `value` into @lastid from gmms_var where varname='last_out_glass_id'and groups=@work_groups;
                select `value` into @lastpos from gmms_var where varname='last_pos'and groups=@work_groups;
                if @lastid is not null then
                    select @lastid;
                    SELECT a.id,a.slicecage_rank,a.type_id,a.count,galss_id into @rkid,@rk,@type_id,@count,@galss_id from gmms_horizontal a 
                    INNER JOIN gmms_galss_task b on a.id=b.slicecage_rank INNER JOIN gmms_drop_frame c on b.processcard_id=c.processcard_id 
                    where a.state='使用中' and a.count>0 and a.type_id=@lastid and a.flag=0 and b.engineering_id=@engineering_id and  c.processcard_id is not null and a.gourp=2 and b.stop_position>0 
                    order by a.count desc, ABS(a.slicecage_rank-@lastpos) asc LIMIT 1;
                    if @rk is not null and @rk<>0 then
                    select @rk;
                        UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
                            UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
                            UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
                            UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
                            call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
                            call intTo2ByteHex10_16_4(@rk,@rks);
                            set dates=CONCAT("0001",@galss_ids,"0000",@rks);
                            call message(dates,'000d',@date);
                            set messagedate=@date;
                            insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼出库5',@rk,@date);
                            set @发送字=1;
                    end if;
                end if;
                if @发送字=0 then
                    SELECT 流程卡 into @processcardid from processcard_ex where 下片位置 is not null and 库内数>0 and 总数-切割数=0 and 工程号=@engineering_id order by  总数-下架数  asc LIMIT 1;
                    IF @processcardid is  null then
                        select 2;
                            #  后使用  未完全切完的
                            SELECT 流程卡 into @processcardid from processcard_ex where 下片位置 is not null and 库内数>0 and 工程号=@engineering_id order by 总数-下架数  asc LIMIT 1;    
                    end if;
                    -- 看看空架 有没有 ,如果有  就找一个库能玻璃最多的下架
                    IF @processcardid is null then 
 
                        SET @drop_pos=null;
                        SELECT 流程卡,架号,总数,工程号 into @processcardid,@drop_frame,@processcard_count,@engineering_ids from processcard_ex 
                        where  (库内数>=@name1 or (库内数>0 and 总数<@name1)) and 工程号=@engineering_id order by  总数-库内数 LIMIT 1;
                        
                        #得到最小的 和最大的玻璃数据  判断往哪里靠边  2023-8-30
                        select MAX(width),MAX(height),MIN(width),MIN(height) into maxw,maxh,minw,minh from gmms_galss_task where processcard_id=@processcardid;
                        if maxw<2400 and maxh<1900 and minw>599 and minh>349 then
                            set kaobian='机器人';
                        else
                            set kaobian='下片机';    
                        end if;
                        if kaobian='下片机' then
                            select id into @drop_pos from gmms_drop_frame where state='空架' and groups=@work_groups and (stops=1 or stops=2) limit 1;
                        elseif kaobian='机器人' then
                            select id into @drop_pos from gmms_drop_frame where state='空架' and groups=@work_groups and (stops=3 or stops=4 or stops=5) limit 1;
                        end if;
                        set kaobian=null;
                        
                        if @processcardid is not null and @drop_pos  is not null then 
                            select name1 into @name1 from namess where groups=@work_groups;
                            #  流程卡占架子
                            select count(*) into @counts2 from gmms_galss_task where processcard_id=@processcardid and engineering_id=@engineering_id;
                            if  @counts2>0 then 
                                UPDATE gmms_drop_frame set state='使用中',drop_frame=@drop_frame,processcard_id=@processcardid,processcard_count=@processcard_count,engineering_id=@engineering_id where id=@drop_pos;
                                INSERT into hn_user(update_time,add_time) VALUES(@processcardid,@work_groups);
                                UPDATE gmms_galss_task set stop_position=@drop_pos where processcard_id=@processcardid and engineering_id=@engineering_id;                
                            end if;            
                        else
                            set @processcardid=null;
                            set @drop_pos=null;
                        end if;
                    end if;
                    if @processcardid is not null then 
                            SELECT @processcardid;    
                            #  选定大小和槽
                            SELECT  a.id,a.slicecage_rank,a.count,a.type_id,galss_id into @rkid,@rk,@count,@type_id,@galss_id from gmms_horizontal a inner join gmms_galss_task b on a.id=b.slicecage_rank  where a.processcard_id=@processcardid and a.state='使用中' and a.gourp=2 and a.flag=0 and engineering_id=@engineering_id order by b.width*b.height desc ,a.count DESC  limit 1;
                            select @rkid;
                            select @count;
                            UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
                            UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
                            UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
                            UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
                            call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
                            call intTo2ByteHex10_16_4(@rk,@rks);
                            set dates=CONCAT("0001",@galss_ids,"0000",@rks);
                            call message(dates,'000d',@date);
                            set messagedate=@date;
                            insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼出库6',@rk,@date);
                            set a=1;
                        end if;
                    
                end if;
 
    
    end if;
    
end if;
-- 
--     #传送
--     if flag=3 then
--         SELECT a.slicecage_rank,a.type_id,a.count into @rk,@type_id,@count from gmms_horizontal a INNER JOIN gmms_galss_task b on a.id=b.slicecage_rank where a.state='使用中' and a.count>0  and a.flag=0 and engineering_id=@engineering_id and a.gourp=1  order by a.count desc,a.slicecage_rank LIMIT 1;
--         select count(*) into @count1 from gmms_galss_task where work_state='直通' and work_procedure='理片';
--         select @rk;
--         if @rk is not null then
--             UPDATE gmms_galss_task SET work_state='传送中' where slicecage_rank=@rk and engineering_id=@engineering_id;
--             UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=1;
--             select count,type_id,processcard_id into @count,@type_id,@processcard_id from gmms_horizontal where slicecage_rank=@rk and gourp=1;
--             UPDATE gmms_horizontal SET state='进库中',count=@count,type_id=@type_id,processcard_id=@processcard_id where slicecage_rank=@rk and gourp=2;
--             select count(*) into @counts from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id;
--             if @counts=1 then
--                 select galss_id into @galss_id1 from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id;
--                 call intTo2ByteHex10_16_4(@galss_id1,@galss_ids1);
--                 call intTo2ByteHex10_16_4(@rk,@rks);
--                 set dates=CONCAT("00020000",@rks,"000200000000",@rks,"000000000000",@galss_ids1);
--                 call message(dates,'000a',@date);
--                 set messagedate=@date;
--             else 
--                 select galss_id into @galss_id1 from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id limit 1;
--                 select galss_id into @galss_id2 from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id limit 2;
--                 call intTo2ByteHex10_16_4(@galss_id1,@galss_ids1);
--                 call intTo2ByteHex10_16_4(@galss_id2,@galss_ids2);
--                 call intTo2ByteHex10_16_4(@rk,@rks);
--                 set dates=CONCAT("00020000",@rks,"000200000000",@rks,"000000000000",@galss_ids1,@galss_id2);
--                 call message(dates,'000a',@date);
--                 set messagedate=@date;
--             end if;
--         elseif @count1>0 then
--                 set dates=CONCAT("000300000003","0003000000000003");
--                 call message(dates,'000a',@date);
--                 set messagedate=@date;
--         else
--             select 库内数 into @kuneishu from processcard1 where 工程号=@engineering_id limit 1;
--             select @work_groups;
--             select count(*) into @counts from gmms_horizontal where state='空闲' and gourp=2;
--             if a=0 then
--                 if @kuneishu>0 or @counts<=1 then
--                 #出片
--                 SET @processcardid=null;
--                 set @rkid=null;
--                 set @rk=null;
--                 set @galss_id=null;
--                 select `value` into @lastid from gmms_var where varname='last_out_glass_id'and groups=@work_groups;
--                 select `value` into @lastpos from gmms_var where varname='last_pos'and groups=@work_groups;
--                 if @lastid is not null then
--                     select @lastid;
--                     SELECT a.id,a.slicecage_rank,a.type_id,a.count,galss_id into @rkid,@rk,@type_id,@count,@galss_id from gmms_horizontal a INNER JOIN gmms_galss_task b on a.id=b.slicecage_rank where a.state='使用中' and a.count>0 and a.type_id=@lastid and a.flag=0 and engineering_id=@engineering_id and a.gourp=2 and b.stop_position>0 order by a.count desc, ABS(a.slicecage_rank-@lastpos) asc LIMIT 1;
--                     if @rk is not null then
--                     select @rk;
--                         UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
--                             UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
--                             UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
--                             UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
--                             call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
--                             call intTo2ByteHex10_16_4(@rk,@rks);
--                             set dates=CONCAT("0001",@galss_ids,"0000",@rks);
--                             call message(dates,'000d',@date);
--                             set messagedate=@date;
--                             set @发送字=1;
--                     end if;
--                 end if;
--                 if @发送字=0 then
--                     SELECT 流程卡 into @processcardid from processcard_ex1 where 下片位置 is not null and 库内数>0 and 总数-切割数=0 and 工程号=@engineering_id order by  总数-下架数  asc LIMIT 1;
--                     IF @processcardid is  null then
--                         select 2;
--                             #  后使用  未完全切完的
--                             SELECT 流程卡 into @processcardid from processcard_ex1 where 下片位置 is not null and 库内数>0 and 工程号=@engineering_id order by 总数-下架数  asc LIMIT 1;    
--                     end if;
--                     -- 看看空架 有没有 ,如果有  就找一个库能玻璃最多的下架
--                     IF @processcardid is null then 
-- 
--                         SET @drop_pos=null;
--                         SELECT id into @drop_pos from gmms_drop_frame where state='空架' and groups=@work_groups limit 1;
--                         if @drop_pos  is not null then 
--                             select name1 into @name1 from namess where groups=@work_groups;
--                             SELECT 流程卡,架号,总数,工程号 into @processcardid,@drop_frame,@processcard_count,@engineering_ids from processcard_ex1 where  (库内数>=@name1 or (库内数>0 and 总数<@name1)) order by  库内数 DESC LIMIT 1;
--                             #  流程卡占架子
--                             if @processcardid is not null then 
--                                 UPDATE gmms_drop_frame set state='使用中',drop_frame=@drop_frame,processcard_id=@processcardid,processcard_count=@processcard_count,engineering_id=@engineering_ids where id=@drop_pos;
--                                 UPDATE gmms_galss_task set stop_position=@drop_pos where processcard_id=@processcardid and engineering_id=@engineering_id;                
--                             end if;            
--                         end if;
--                     end if;
--                     if @processcardid is not null then 
--                             SELECT @processcardid;    
--                             #  选定大小和槽
--                             SELECT  a.id,a.slicecage_rank,a.count,a.type_id,galss_id into @rkid,@rk,@count,@type_id,@galss_id from gmms_horizontal a inner join gmms_galss_task b on a.type_id=b.type_id where a.processcard_id=@processcardid and a.state='使用中' and a.gourp=2 and a.flag=0 and engineering_id=@engineering_id order by b.width*b.height desc ,a.count DESC  limit 1;
--                             select @count;
--                             UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
--                             UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
--                             UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
--                             UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
--                             call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
--                             call intTo2ByteHex10_16_4(@rk,@rks);
--                             set dates=CONCAT("0001",@galss_ids,"0000",@rks);
--                             call message(dates,'000d',@date);
--                             set messagedate=@date;
--                             set a=1;
--                         end if;
--                     
--                 end if;
-- --                             SELECT  a.id,a.slicecage_rank,a.count,a.type_id,galss_id into @rkid,@rk,@count,@type_id,@galss_id from gmms_horizontal a inner join gmms_galss_task b on a.id=b.slicecage_rank where  a.state='使用中' and a.gourp=2 and a.flag=0 and engineering_id=@engineering_id order by b.width*b.height desc ,a.count DESC  limit 1;
-- --                             select @count;
-- --                             UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
-- --                             UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
-- --                             UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
-- --                             UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
-- --                             call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
-- --                             call intTo2ByteHex10_16_4(@rk,@rks);
-- --                             set dates=CONCAT("0001",@galss_ids,"0000",@rks);
-- --                             call message(dates,'000d',@date);
-- --                             set messagedate=@date;
-- --                             set a=1;
--                 end if;
--             end if;
--             
--             if a=0 then
--                 #进片
--                 select rank,type_id,galss_id,processcard_id,width,height,slicecage_rank into @rankid,@type_id,@galss_id,@processcardid,@width,@height,@rk from gmms_galss_task where work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id order by rank limit 1;
--                 UPDATE gmms_galss_task set slicecage_rank=@rk,work_procedure='理片',work_state='进库中' WHERE rank=@rankid and engineering_id=@engineering_id;
--                 UPDATE gmms_horizontal set state='进库中',count=1,type_id=@type_id,processcard_id=@processcardid where slicecage_rank=@rk and gourp=1;
--                 call intTo2ByteHex10_16_4(@rankid,@rankids);
--                 call intTo2ByteHex10_16_4(@rk,@rks);
--                 set dates=CONCAT("0001",@rankids,@rks);
--                 call message(dates,'000a',@date);
--                 set messagedate=@date;
--             end if;
--                 
--     
--         end if;
--         
--     #出片
--     elseif flag=2 then
--                 SET @processcardid=null;
--                 set @rkid=null;
--                 set @rk=null;
--                 set @galss_id=null;
--                 select `value` into @lastid from gmms_var where varname='last_out_glass_id'and groups=@work_groups;
--                 select `value` into @lastpos from gmms_var where varname='last_pos'and groups=@work_groups;
--                 if @lastid is not null then
--                     select @lastid;
--                     SELECT a.id,a.slicecage_rank,a.type_id,a.count,galss_id into @rkid,@rk,@type_id,@count,@galss_id from gmms_horizontal a INNER JOIN gmms_galss_task b on a.id=b.slicecage_rank where a.state='使用中' and a.count>0 and a.type_id=@lastid and a.flag=0 and engineering_id=@engineering_id and a.gourp=2 and b.stop_position>0 order by a.count desc, ABS(a.slicecage_rank-@lastpos) asc LIMIT 1;
--                     if @rk is not null then
--                     select @rk;
--                         UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
--                             UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
--                             UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
--                             UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
--                             call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
--                             call intTo2ByteHex10_16_4(@rk,@rks);
--                             set dates=CONCAT("0001",@galss_ids,"0000",@rks);
--                             call message(dates,'000d',@date);
--                             set messagedate=@date;
--                             set @发送字=1;
--                     end if;
--                 end if;
--                 if @发送字=0 then
--                     SELECT 流程卡 into @processcardid from processcard_ex1 where 下片位置 is not null and 库内数>0 and 总数-切割数=0 and 工程号=@engineering_id order by  总数-下架数  asc LIMIT 1;
--                     IF @processcardid is  null then
--                         select 2;
--                             #  后使用  未完全切完的
--                             SELECT 流程卡 into @processcardid from processcard_ex1 where 下片位置 is not null and 库内数>0 and 工程号=@engineering_id order by 总数-下架数  asc LIMIT 1;    
--                     end if;
--                     -- 看看空架 有没有 ,如果有  就找一个库能玻璃最多的下架
--                     IF @processcardid is null then 
-- 
--                         SET @drop_pos=null;
--                         SELECT id into @drop_pos from gmms_drop_frame where state='空架' and groups=@work_groups limit 1;
--                         if @drop_pos  is not null then 
--                             select name1 into @name1 from namess where groups=@work_groups;
--                             SELECT 流程卡,架号,总数,工程号 into @processcardid,@drop_frame,@processcard_count,@engineering_ids from processcard_ex1 where  (库内数>=@name1 or (库内数>0 and 总数<@name1)) order by  库内数 DESC LIMIT 1;
--                             #  流程卡占架子
--                             if @processcardid is not null then 
--                                 UPDATE gmms_drop_frame set state='使用中',drop_frame=@drop_frame,processcard_id=@processcardid,processcard_count=@processcard_count,engineering_id=@engineering_ids where id=@drop_pos;
--                                 UPDATE gmms_galss_task set stop_position=@drop_pos where processcard_id=@processcardid and engineering_id=@engineering_id;                
--                             end if;            
--                         end if;
--                     end if;
--                     if @processcardid is not null then 
--                             SELECT @processcardid;    
--                             #  选定大小和槽
--                             SELECT  a.id,a.slicecage_rank,a.count,a.type_id,galss_id into @rkid,@rk,@count,@type_id,@galss_id from gmms_horizontal a inner join gmms_galss_task b on a.type_id=b.type_id where a.processcard_id=@processcardid and a.state='使用中' and a.gourp=2 and a.flag=0 and engineering_id=@engineering_id order by b.width*b.height desc ,a.count DESC  limit 1;
--                             select @count;
--                             UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
--                             UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
--                             UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
--                             UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
--                             call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
--                             call intTo2ByteHex10_16_4(@rk,@rks);
--                             set dates=CONCAT("0001",@galss_ids,"0000",@rks);
--                             call message(dates,'000d',@date);
--                             set messagedate=@date;
--                         end if;
--                     
--                 end if;
-- --                         SELECT  a.id,a.slicecage_rank,a.count,a.type_id,galss_id into @rkid,@rk,@count,@type_id,@galss_id from gmms_horizontal a inner join gmms_galss_task b on a.id=b.slicecage_rank where  a.state='使用中' and a.gourp=2 and a.flag=0 and engineering_id=@engineering_id order by b.width*b.height desc ,a.count DESC  limit 1;
-- --                             select @count;
-- --                             UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
-- --                             UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
-- --                             UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
-- --                             UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
-- --                             call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
-- --                             call intTo2ByteHex10_16_4(@rk,@rks);
-- --                             set dates=CONCAT("0001",@galss_ids,"0000",@rks);
-- --                             call message(dates,'000d',@date);
-- --                             set messagedate=@date;
--                 
--     #进片
--     elseif flag=1 then
--         select rank,type_id,galss_id,processcard_id,width,height,slicecage_rank into @rankid,@type_id,@galss_id,@processcardid,@width,@height,@rk from gmms_galss_task where work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id order by rank limit 1;
--         UPDATE gmms_galss_task set slicecage_rank=@rk,work_procedure='理片',work_state='进库中' WHERE rank=@rankid and engineering_id=@engineering_id;
--         UPDATE gmms_horizontal set state='进库中',count=1,type_id=@type_id,processcard_id=@processcardid where slicecage_rank=@rk and gourp=1;
--         call intTo2ByteHex10_16_4(@rankid,@rankids);
--         call intTo2ByteHex10_16_4(@rk,@rks);
--         set dates=CONCAT("0001",@rankids,@rks);
--         call message(dates,'000a',@date);
--         set messagedate=@date;
--     
--     end if;
        
    set @conts=CONCAT(IFNULL(@conts,'-'),'   ',IFNULL(messagedate,'-'));
    set @end_time_=SYSDATE();
    set ResultText=@conts;
    insert into A_LengLipian(create_time,end_time,content) values (@create_time_,@end_time_,@conts);
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for HorizontalSend_copy1
-- ----------------------------
DROP PROCEDURE IF EXISTS `HorizontalSend_copy1`;
delimiter ;;
CREATE PROCEDURE `HorizontalSend_copy1`(in machineids BIGINT,in returnvalue varchar(255),in flags int,out messagedate varchar(255))
BEGIN
    #理片笼请求存储过程
    #判断是进片还是出片还是进出片请求
    #发送数据:玻璃编号,理片笼架子
    DECLARE a int DEFAULT 0;
    DECLARE ranks int DEFAULT 0;
    DECLARE dates varchar(255);
    DECLARE messagedates varchar(255) DEFAULT '';
    DECLARE maxw int DEFAULT 0;
    DECLARE maxh int DEFAULT 0;
    DECLARE minw int DEFAULT 0;
    DECLARE minh int DEFAULT 0;
    DECLARE kaobian varchar(255) DEFAULT null;
    set messagedate=messagedates;
    
 
select machine_type_id,work_id into @mtid,@work_groups from gmms_machine where id=machineids;
 
select @work_groups;
    
select file_name into @engineering_id from gmms_raw_file where operator=@work_groups and state='已领取';
 
select @engineering_id;
 
select var into @var from gmms_slicecage_pattern where groups=@work_groups;
 
select @var;
 
SET @发送字=0;
select count(*) into @counts6 from gmms_galss_task  where work_state='直通' and work_procedure='理片' and engineering_id=@engineering_id;
 
#进出片
if @var='1' then
        #传送
    if flags=3 then
        if a=0 then
            set @kuneishu=0;
            select 库内数 into @kuneishu from processcard1 where 工程号=@engineering_id and 库内数>0 order by 库内数 desc  limit 0,1;
            select @kuneishu;
            select @work_groups;
            select count(*) into @counts from gmms_horizontal where state='空闲' and gourp=2;
            
                if (@kuneishu>0 or @counts<=1) and @counts6=0 then
                #出片
                SET @processcardid=null;
                set @rkid=null;
                set @rk=null;
                set @galss_id=null;
                select `value` into @lastid from gmms_var where varname='last_out_glass_id'and groups=@work_groups;
                select `value` into @lastpos from gmms_var where varname='last_pos'and groups=@work_groups;
                if @lastid is not null then
                    select @lastid;
                    SELECT a.id,a.slicecage_rank,a.type_id,a.count,galss_id into @rkid,@rk,@type_id,@count,@galss_id from gmms_horizontal a 
                    INNER JOIN gmms_galss_task b on a.id=b.slicecage_rank INNER JOIN gmms_drop_frame c on b.processcard_id=c.processcard_id 
                    where a.state='使用中' and a.count>0 and a.type_id=@lastid and a.flag=0 and b.engineering_id=@engineering_id and  c.processcard_id is not null and a.gourp=2 and b.stop_position>0 
                    order by a.count desc, ABS(a.slicecage_rank-@lastpos) asc LIMIT 1;
                    if @rk is not null and @rk<>0 then
                    select @rk;
                        UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
                            UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
                            UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
                            UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
                            set @galss_ids=null;
                            call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
                            select @galss_ids;
                            call intTo2ByteHex10_16_4(@rk,@rks);
                            set dates=CONCAT("0001",@galss_ids,"0000",@rks);
                            call message(dates,'000d',@date);
                            set messagedate=@date;
                            insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼出库1',@rk,@date);
                            set @发送字=1;
                            set a=1;
                    end if;
                end if;
                if @发送字=0 then
                    SELECT 流程卡 into @processcardid from processcard_ex where 下片位置 is not null and 库内数>0 and 总数-切割数=0 and 工程号=@engineering_id order by  总数-下架数  asc LIMIT 1;
                    IF @processcardid is  null then
                        select 2;
                            #  后使用  未完全切完的
                            SELECT 流程卡 into @processcardid from processcard_ex where 下片位置 is not null and 库内数>0 and 工程号=@engineering_id order by 总数-下架数  asc LIMIT 1;    
                    end if;
                    -- 看看空架 有没有 ,如果有  就找一个库能玻璃最多的下架
 
                    IF @processcardid is null then 
 
                        SET @drop_pos=null;
                        
--                         #得到最小的 和最大的玻璃数据  判断往哪里靠边  2023-8-30
--                         select MAX(width),MAX(height),MIN(width),MIN(height) into maxw,maxh,minw,minh from gmms_galss_task where processcard_id=@processcard_id;
--                         select xiapianbiaoji into kaobian from gmms_liuchengka where liuchengka=@processcard_id;
--                         if kaobian is null then
--                             if maxw<2400 or maxh<1900 or minw>599 or minh>349 then
--                                 update gmms_liuchengka set xiapianbiaoji='下片机' where liuchengka=@processcard_id;
--                             else
--                                 update gmms_liuchengka set xiapianbiaoji='机器人' where liuchengka=@processcard_id;
--                             end if;
--                         elseif kaobian='下片机' then
--                             select id into @drop_pos from gmms_drop_frame where state='空架' and groups=@work_groups and (stops=1 or stops=2) limit 1;
--                         elseif kaobian='机器人' then
--                             select id into @drop_pos from gmms_drop_frame where state='空架' and groups=@work_groups and (stops=3 or stops=4 or stops=5) limit 1;
--                         end if;
                        
                        SELECT id into @drop_pos from gmms_drop_frame where state='空架' and groups=@work_groups limit 1;
                        if @drop_pos  is not null then 
                            select name1 into @name1 from namess where groups=@work_groups;
                            SELECT 流程卡,架号,总数,工程号 into @processcardid,@drop_frame,@processcard_count,@engineering_ids from processcard_ex where  (库内数>=@name1 or (库内数>0 and 总数<@name1)) and 工程号=@engineering_id order by  总数-库内数 LIMIT 1;
                            #  流程卡占架子
                            select @processcardid;
                            select @drop_pos;
                            select count(*) into @counts2 from gmms_galss_task where processcard_id=@processcardid and engineering_id=@engineering_id;
                            if @processcardid is not null and @counts2>0 then 
                                UPDATE gmms_drop_frame set state='使用中',drop_frame=@drop_frame,processcard_id=@processcardid,processcard_count=@processcard_count,engineering_id=@engineering_id where id=@drop_pos;
                                INSERT into hn_user(update_time,add_time) VALUES(@processcardid,@work_groups);
                                UPDATE gmms_galss_task set stop_position=@drop_pos where processcard_id=@processcardid and engineering_id=@engineering_id;                
                            end if;            
                        end if;
                    end if;
                    if @processcardid is not null then 
                            SELECT @processcardid;    
                            #  选定大小和槽
                            SELECT  a.id,a.slicecage_rank,a.count,a.type_id,galss_id into @rkid,@rk,@count,@type_id,@galss_id from gmms_horizontal a inner join gmms_galss_task b on a.id=b.slicecage_rank  where a.processcard_id=@processcardid and a.state='使用中' and a.gourp=2 and a.flag=0 and engineering_id=@engineering_id order by b.width*b.height desc ,a.count DESC  limit 1;
                            select @rkid;
                            select @count;
                            if @rk is not null and @rk<>0 then
                            UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
                            UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
                            UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
                            UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
                            call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
                            call intTo2ByteHex10_16_4(@rk,@rks);
                            select @galss_ids,@rks,@date;
                            set dates=CONCAT("0001",@galss_ids,"0000",@rks);
                            call message(dates,'000d',@date);
                            set messagedate=@date;
                            insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼出库2',@rk,@date);
                            set a=1;
                            end if;
                        end if;
                    
                end if;
 
                end if;
            
        end if;
        
        if a=0 then
        
                set @rk=null;
            select slicecage_rank into @rk from gmms_horizontal  
            where (gourp=1 and state='使用中' and count>0 and flag=0) or (gourp=2 and state='空闲')  group by slicecage_rank having count(*)=2 order by count desc limit 1;
            select @rk;
            if @rk is not null and @rk<>0 then
                select count(*) into @countstate from gmms_horizontal where  (state='出库中' or state='进库中');
                if @countstate=0 then
                UPDATE gmms_galss_task SET work_state='传送中' where slicecage_rank=@rk and engineering_id=@engineering_id;
                UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=1;
                select count,type_id,processcard_id into @count,@type_id,@processcard_id from gmms_horizontal where slicecage_rank=@rk and gourp=1;
                UPDATE gmms_horizontal SET state='进库中',count=@count,type_id=@type_id,processcard_id=@processcard_id where slicecage_rank=@rk and gourp=2;
                select count(*) into @counts from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id;
                select count(*) into @count1 from gmms_galss_task where work_state='直通' and work_procedure='理片' and engineering_id=@engineering_id;
                if @counts=1 then
                    if @type_id <>0 and (@processcard_id is not null or @processcard_id<>'') then
                        select galss_id into @galss_id1 from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id;
                        call intTo2ByteHex10_16_4(@galss_id1,@galss_ids1);
                        call intTo2ByteHex10_16_4(@rk,@rks);
                        set dates=CONCAT("00020000",@rks,"000200000000",@rks,"000000000000",@galss_ids1);
                        call message(dates,'000a',@date);
                        insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                            values (machineids,@work_groups,NOW(),'理片笼传送1',@rk,@date);
                        set messagedate=@date;
                        set a=1;
                    end if;
                else 
                    select galss_id into @galss_id1 from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id limit 1;
                    select galss_id into @galss_id2 from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id limit 2;
                    call intTo2ByteHex10_16_4(@galss_id1,@galss_ids1);
                    call intTo2ByteHex10_16_4(@galss_id2,@galss_ids2);
                    call intTo2ByteHex10_16_4(@rk,@rks);
                    set dates=CONCAT("00020000",@rks,"000200000000",@rks,"000000000000",@galss_ids1,@galss_id2);
                    call message(dates,'000a',@date);
                    set a=1;
                    set messagedate=@date;
                    insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                            values (machineids,@work_groups,NOW(),'理片笼传送2',@rk,@date);
                end if;
                end if;
                
            elseif @count1>0 then
                    set dates=CONCAT("000300000003","0003000000000003");
                    call message(dates,'000a',@date);
                    set messagedate=@date;
                    set a=1;
            
            end if;
        end if;
        
            
            
        if a=0 then
                #进片
                set @type_id=0;
                set @processcardid=null;
                select rank,type_id,galss_id,processcard_id,width,height,slicecage_rank into @rankid,@type_id,@galss_id,@processcardid,@width,@height,@rk from gmms_galss_task where work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id order by rank limit 1;
                if @galss_id is not null and @rk<>0 and @rk is not null then
                UPDATE gmms_galss_task set work_state='进库中',finsh_time=now() WHERE rank=@rankid and work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id;
                UPDATE gmms_horizontal set state='进库中',count=1,type_id=@type_id,processcard_id=@processcardid where slicecage_rank=@rk and gourp=1;
                call intTo2ByteHex10_16_4(@rankid,@rankids);
                call intTo2ByteHex10_16_4(@rk,@rks);
                set dates=CONCAT("0001",@rankids,@rks);
                call message(dates,'000a',@date);
                set messagedate=@date;
                insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼进库1',@rk,@date);
                end if;
            end if;
 
        
    #出片
    elseif flags=2 and @counts6=0 then
                SET @processcardid=null;
                set @rkid=null;
                set @rk=null;
                set @galss_id=null;
                select `value` into @lastid from gmms_var where varname='last_out_glass_id'and groups=@work_groups;
                select `value` into @lastpos from gmms_var where varname='last_pos'and groups=@work_groups;
                if @lastid is not null then
                    select @lastid;
                    SELECT a.id,a.slicecage_rank,a.type_id,a.count,galss_id into @rkid,@rk,@type_id,@count,@galss_id from gmms_horizontal a 
                    INNER JOIN gmms_galss_task b on a.id=b.slicecage_rank INNER JOIN gmms_drop_frame c on b.processcard_id=c.processcard_id 
                    where a.state='使用中' and a.count>0 and a.type_id=@lastid and a.flag=0 and b.engineering_id=@engineering_id and  c.processcard_id is not null and a.gourp=2 and b.stop_position>0 
                    order by a.count desc, ABS(a.slicecage_rank-@lastpos) asc LIMIT 1;
                    if @rk is not null and @rk<>0 then
                    select @rk;
                        UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
                            UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
                            UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
                            UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
                            call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
                            call intTo2ByteHex10_16_4(@rk,@rks);
                            set dates=CONCAT("0001",@galss_ids,"0000",@rks);
                            call message(dates,'000d',@date);
                            set messagedate=@date;
                            insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼出库3',@rk,@date);
                            set @发送字=1;
                    end if;
                end if;
                if @发送字=0 then
                    SELECT 流程卡 into @processcardid from processcard_ex where 下片位置 is not null and 库内数>0 and 总数-切割数=0 and 工程号=@engineering_id order by  总数-下架数  asc LIMIT 1;
                    IF @processcardid is  null then
                        select 2;
                            #  后使用  未完全切完的
                            SELECT 流程卡 into @processcardid from processcard_ex where 下片位置 is not null and 库内数>0 and 工程号=@engineering_id order by 总数-下架数  asc LIMIT 1;    
                    end if;
                    -- 看看空架 有没有 ,如果有  就找一个库能玻璃最多的下架
                    IF @processcardid is null then 
 
                        SET @drop_pos=null;
--                         select min(edg_width),min(edg_height) into @minwidth,@minheight from gmms_galss_task where processcard_id=@processcardid and engineering_id=@engineering_id;
--                         if @minwidth<=1200 or @minheight<=700 then
--                             SELECT id into @drop_pos from gmms_drop_frame where state='空架' and groups=@work_groups and (stops=3 or stops=4 or stops=5) limit 1;
--                         else
--                             SELECT id into @drop_pos from gmms_drop_frame where state='空架' and groups=@work_groups and (stops=1 or stops=2) limit 1;
--                         end if;
                        SELECT id into @drop_pos from gmms_drop_frame where state='空架' and groups=@work_groups limit 1;
                        if @drop_pos  is not null then 
                            select name1 into @name1 from namess where groups=@work_groups;
                            SELECT 流程卡,架号,总数,工程号 into @processcardid,@drop_frame,@processcard_count,@engineering_ids from processcard_ex where  (库内数>=@name1 or (库内数>0 and 总数<@name1)) and 工程号=@engineering_id order by  总数-库内数 LIMIT 1;
                            #  流程卡占架子
                            select count(*) into @counts2 from gmms_galss_task where processcard_id=@processcardid and engineering_id=@engineering_id;
                            if @processcardid is not null and @counts2>0 then 
                                UPDATE gmms_drop_frame set state='使用中',drop_frame=@drop_frame,processcard_id=@processcardid,processcard_count=@processcard_count,engineering_id=@engineering_id where id=@drop_pos;
                                INSERT into hn_user(update_time,add_time) VALUES(@processcardid,@work_groups);
                                UPDATE gmms_galss_task set stop_position=@drop_pos where processcard_id=@processcardid and engineering_id=@engineering_id;                
                            end if;            
                        end if;
                    end if;
                    if @processcardid is not null then 
                            SELECT @processcardid;    
                            #  选定大小和槽
                            SELECT  a.id,a.slicecage_rank,a.count,a.type_id,galss_id into @rkid,@rk,@count,@type_id,@galss_id from gmms_horizontal a inner join gmms_galss_task b on a.id=b.slicecage_rank  where a.processcard_id=@processcardid and a.state='使用中' and a.gourp=2 and a.flag=0 and engineering_id=@engineering_id order by b.width*b.height desc ,a.count DESC  limit 1;
                            select @count;
                            if @rk is not null and @rk<>0 then
                            UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
                            UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
                            UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
                            UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
                            call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
                            call intTo2ByteHex10_16_4(@rk,@rks);
                            set dates=CONCAT("0001",@galss_ids,"0000",@rks);
                            call message(dates,'000d',@date);
                            set messagedate=@date;
                            insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼出库4',@rk,@date);
                            end if;
                        end if;
                    
                end if;
 
                
    #进片
    elseif flags=1 then
        set @rk=null;
        set @type_id=0;
                set @processcardid=null;
                select rank,type_id,galss_id,processcard_id,width,height,slicecage_rank into @rankid,@type_id,@galss_id,@processcardid,@width,@height,@rk from gmms_galss_task where work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id order by rank limit 1;
                if @galss_id is not null and @rk<>0 and @rk is not null then
                UPDATE gmms_galss_task set work_state='进库中',finsh_time=now() WHERE rank=@rankid and work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id;
                UPDATE gmms_horizontal set state='进库中',count=1,type_id=@type_id,processcard_id=@processcardid where slicecage_rank=@rk and gourp=1;
                call intTo2ByteHex10_16_4(@rankid,@rankids);
                call intTo2ByteHex10_16_4(@rk,@rks);
                set dates=CONCAT("0001",@rankids,@rks);
                call message(dates,'000a',@date);
                set messagedate=@date;
                insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼进库2',@rk,@date);
                end if;
    
    end if;
 
#直通
-- elseif @var='2' then
-- 
-- 
#存笼
elseif @var='3' then
    if flags=3 then
    set @type_id=null;
    set @count=null;
        select slicecage_rank into @rk from gmms_horizontal  where (gourp=1 and state='使用中' and count>0 and flag=0) or (gourp=2 and state='空闲')  group by slicecage_rank having count(*)=2 order by count desc limit 1;
        select @rk;
        if @rk is not null  then
                select count(*) into @countstate from gmms_horizontal where  (state='出库中' or state='进库中');
                if @countstate=0 then
              UPDATE gmms_galss_task SET work_state='传送中' where slicecage_rank=@rk and engineering_id=@engineering_id;
              UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=1;
               select count,type_id,processcard_id into @count,@type_id,@processcard_id from gmms_horizontal where slicecage_rank=@rk and gourp=1;
                
              UPDATE gmms_horizontal SET state='进库中',count=@count,type_id=@type_id,processcard_id=@processcard_id where slicecage_rank=@rk and gourp=2;
            select count(*) into @counts from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id;
            select @counts;
            if @counts=1 then
                if @type_id <>0 and (@processcard_id is not null or @processcard_id<>'') then
                    select galss_id into @galss_id1 from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id;
                    call intTo2ByteHex10_16_4(@galss_id1,@galss_ids1);
                    call intTo2ByteHex10_16_4(@rk,@rks);
                    set dates=CONCAT("00020000",@rks,"000200000000",@rks,"000000000000",@galss_ids1);
                    call message(dates,'000a',@date);
                    set messagedate=@date;
                    insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼传送3',@rk,@date);
                end if;
            else 
                     select @counts;
                end if;
            else 
                
                select galss_id into @galss_id1 from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id limit 1;
                select galss_id into @galss_id2 from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id limit 2;
                select @galss_id1,@galss_id2;
                call intTo2ByteHex10_16_4(@galss_id1,@galss_ids1);
                call intTo2ByteHex10_16_4(@galss_id2,@galss_ids2);
                call intTo2ByteHex10_16_4(@rk,@rks);
                set dates=CONCAT("00020000",@rks,"000200000000",@rks,"000000000000",@galss_ids1,@galss_id2);
                call message(dates,'000a',@date);
                set messagedate=@date;
                insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼传送4',@rk,@date);
            end if;
        else
            set @type_id=0;
            set @processcardid=null;
            select rank,type_id,galss_id,processcard_id,width,height,slicecage_rank into @rankid,@type_id,@galss_id,@processcardid,@width,@height,@rk from gmms_galss_task where work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id order by rank limit 1;
            if @galss_id is not null and @rk<>0 and @rk is not null then
                #UPDATE gmms_galss_task set slicecage_rank=@rk,work_procedure='理片',work_state='进库中' WHERE rank=@rankid and engineering_id=@engineering_id;
                UPDATE gmms_galss_task set work_state='进库中',finsh_time=now() WHERE rank=@rankid and work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id;
                UPDATE gmms_horizontal set state='进库中',count=1,type_id=@type_id,processcard_id=@processcardid where slicecage_rank=@rk and gourp=1;
                UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
                UPDATE gmms_var SET Value=@rankid where varname='last_out_glass_id' and groups=@work_groups;
                select @rankid,@rk;
                call intTo2ByteHex10_16_4(@rankid,@rankids);
                call intTo2ByteHex10_16_4(@rk,@rks);
                set dates=CONCAT("0001",@rankids,@rks);
                call message(dates,'000a',@date);
                set messagedate=@date;
                insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼进库3',@rk,@date);
            end if;
 
            
        end if;
        
 
 
                
    #进片
    elseif flags=1 then
        set @type_id=0;
                set @processcardid=null;
                select rank,type_id,galss_id,processcard_id,width,height,slicecage_rank into @rankid,@type_id,@galss_id,@processcardid,@width,@height,@rk from gmms_galss_task where work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id order by rank limit 1;
                if @galss_id is not null and @rk<>0 and @rk is not null then
                UPDATE gmms_galss_task set work_state='进库中',finsh_time=now() WHERE rank=@rankid and work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id;
                UPDATE gmms_horizontal set state='进库中',count=1,type_id=@type_id,processcard_id=@processcardid where slicecage_rank=@rk and gourp=1;
                call intTo2ByteHex10_16_4(@rankid,@rankids);
                call intTo2ByteHex10_16_4(@rk,@rks);
                UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
                UPDATE gmms_var SET Value=@rankid where varname='last_out_glass_id' and groups=@work_groups;
                set dates=CONCAT("0001",@rankids,@rks);
                call message(dates,'000a',@date);
                set messagedate=@date;
                insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼进库4',@rk,@date);
                end if;
    end if;
        
#出片
elseif @var='4' then
 
    if (flags=3 or flags=2) and @counts6=0 then
    
        SET @processcardid=null;
                set @rkid=null;
                set @rk=null;
                set @galss_id=null;
                select @lastid;
                select `value` into @lastid from gmms_var where varname='last_out_glass_id'and groups=@work_groups;
                select `value` into @lastpos from gmms_var where varname='last_pos'and groups=@work_groups;
                if @lastid is not null then
                    select @lastid;
                    SELECT a.id,a.slicecage_rank,a.type_id,a.count,galss_id into @rkid,@rk,@type_id,@count,@galss_id from gmms_horizontal a 
                    INNER JOIN gmms_galss_task b on a.id=b.slicecage_rank INNER JOIN gmms_drop_frame c on b.processcard_id=c.processcard_id 
                    where a.state='使用中' and a.count>0 and a.type_id=@lastid and a.flag=0 and b.engineering_id=@engineering_id and  c.processcard_id is not null and a.gourp=2 and b.stop_position>0 
                    order by a.count desc, ABS(a.slicecage_rank-@lastpos) asc LIMIT 1;
                    if @rk is not null and @rk<>0 then
                    select @rk;
                        UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
                            UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
                            UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
                            UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
                            call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
                            call intTo2ByteHex10_16_4(@rk,@rks);
                            set dates=CONCAT("0001",@galss_ids,"0000",@rks);
                            call message(dates,'000d',@date);
                            set messagedate=@date;
                            insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼出库5',@rk,@date);
                            set @发送字=1;
                    end if;
                end if;
                if @发送字=0 then
                    SELECT 流程卡 into @processcardid from processcard_ex where 下片位置 is not null and 库内数>0 and 总数-切割数=0 and 工程号=@engineering_id order by  总数-下架数  asc LIMIT 1;
                    IF @processcardid is  null then
                        select 2;
                            #  后使用  未完全切完的
                            SELECT 流程卡 into @processcardid from processcard_ex where 下片位置 is not null and 库内数>0 and 工程号=@engineering_id order by 总数-下架数  asc LIMIT 1;    
                    end if;
                    -- 看看空架 有没有 ,如果有  就找一个库能玻璃最多的下架
                    IF @processcardid is null then 
 
                        SET @drop_pos=null;
--                         select min(edg_width),min(edg_height) into @minwidth,@minheight from gmms_galss_task where processcard_id=@processcardid and engineering_id=@engineering_id;
--                         if @minwidth<=1200 or @minheight<=700 then
--                             SELECT id into @drop_pos from gmms_drop_frame where state='空架' and groups=@work_groups and (stops=3 or stops=4 or stops=5) limit 1;
--                         else
--                             SELECT id into @drop_pos from gmms_drop_frame where state='空架' and groups=@work_groups and (stops=1 or stops=2) limit 1;
--                         end if;
                        SELECT id into @drop_pos from gmms_drop_frame where state='空架' and groups=@work_groups limit 1;
                        if @drop_pos  is not null then 
                            select name1 into @name1 from namess where groups=@work_groups;
                            SELECT 流程卡,架号,总数,工程号 into @processcardid,@drop_frame,@processcard_count,@engineering_ids from processcard_ex where  (库内数>=@name1 or (库内数>0 and 总数<@name1)) and 工程号=@engineering_id order by  总数-库内数 LIMIT 1;
                            #  流程卡占架子
                            select count(*) into @counts2 from gmms_galss_task where processcard_id=@processcardid and engineering_id=@engineering_id;
                            if @processcardid is not null and @counts2>0 then 
                                UPDATE gmms_drop_frame set state='使用中',drop_frame=@drop_frame,processcard_id=@processcardid,processcard_count=@processcard_count,engineering_id=@engineering_id where id=@drop_pos;
                                INSERT into hn_user(update_time,add_time) VALUES(@processcardid,@work_groups);
                                UPDATE gmms_galss_task set stop_position=@drop_pos where processcard_id=@processcardid and engineering_id=@engineering_id;                
                            end if;            
                        end if;
                    end if;
                    if @processcardid is not null then 
                            SELECT @processcardid;    
                            #  选定大小和槽
                            SELECT  a.id,a.slicecage_rank,a.count,a.type_id,galss_id into @rkid,@rk,@count,@type_id,@galss_id from gmms_horizontal a inner join gmms_galss_task b on a.id=b.slicecage_rank  where a.processcard_id=@processcardid and a.state='使用中' and a.gourp=2 and a.flag=0 and engineering_id=@engineering_id order by b.width*b.height desc ,a.count DESC  limit 1;
                            select @rkid;
                            select @count;
                            UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
                            UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
                            UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
                            UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
                            call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
                            call intTo2ByteHex10_16_4(@rk,@rks);
                            set dates=CONCAT("0001",@galss_ids,"0000",@rks);
                            call message(dates,'000d',@date);
                            set messagedate=@date;
                            insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼出库6',@rk,@date);
                            set a=1;
                        end if;
                    
                end if;
 
    
    end if;
    
end if;
-- 
--     #传送
--     if flag=3 then
--         SELECT a.slicecage_rank,a.type_id,a.count into @rk,@type_id,@count from gmms_horizontal a INNER JOIN gmms_galss_task b on a.id=b.slicecage_rank where a.state='使用中' and a.count>0  and a.flag=0 and engineering_id=@engineering_id and a.gourp=1  order by a.count desc,a.slicecage_rank LIMIT 1;
--         select count(*) into @count1 from gmms_galss_task where work_state='直通' and work_procedure='理片';
--         select @rk;
--         if @rk is not null then
--             UPDATE gmms_galss_task SET work_state='传送中' where slicecage_rank=@rk and engineering_id=@engineering_id;
--             UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=1;
--             select count,type_id,processcard_id into @count,@type_id,@processcard_id from gmms_horizontal where slicecage_rank=@rk and gourp=1;
--             UPDATE gmms_horizontal SET state='进库中',count=@count,type_id=@type_id,processcard_id=@processcard_id where slicecage_rank=@rk and gourp=2;
--             select count(*) into @counts from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id;
--             if @counts=1 then
--                 select galss_id into @galss_id1 from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id;
--                 call intTo2ByteHex10_16_4(@galss_id1,@galss_ids1);
--                 call intTo2ByteHex10_16_4(@rk,@rks);
--                 set dates=CONCAT("00020000",@rks,"000200000000",@rks,"000000000000",@galss_ids1);
--                 call message(dates,'000a',@date);
--                 set messagedate=@date;
--             else 
--                 select galss_id into @galss_id1 from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id limit 1;
--                 select galss_id into @galss_id2 from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id limit 2;
--                 call intTo2ByteHex10_16_4(@galss_id1,@galss_ids1);
--                 call intTo2ByteHex10_16_4(@galss_id2,@galss_ids2);
--                 call intTo2ByteHex10_16_4(@rk,@rks);
--                 set dates=CONCAT("00020000",@rks,"000200000000",@rks,"000000000000",@galss_ids1,@galss_id2);
--                 call message(dates,'000a',@date);
--                 set messagedate=@date;
--             end if;
--         elseif @count1>0 then
--                 set dates=CONCAT("000300000003","0003000000000003");
--                 call message(dates,'000a',@date);
--                 set messagedate=@date;
--         else
--             select 库内数 into @kuneishu from processcard1 where 工程号=@engineering_id limit 1;
--             select @work_groups;
--             select count(*) into @counts from gmms_horizontal where state='空闲' and gourp=2;
--             if a=0 then
--                 if @kuneishu>0 or @counts<=1 then
--                 #出片
--                 SET @processcardid=null;
--                 set @rkid=null;
--                 set @rk=null;
--                 set @galss_id=null;
--                 select `value` into @lastid from gmms_var where varname='last_out_glass_id'and groups=@work_groups;
--                 select `value` into @lastpos from gmms_var where varname='last_pos'and groups=@work_groups;
--                 if @lastid is not null then
--                     select @lastid;
--                     SELECT a.id,a.slicecage_rank,a.type_id,a.count,galss_id into @rkid,@rk,@type_id,@count,@galss_id from gmms_horizontal a INNER JOIN gmms_galss_task b on a.id=b.slicecage_rank where a.state='使用中' and a.count>0 and a.type_id=@lastid and a.flag=0 and engineering_id=@engineering_id and a.gourp=2 and b.stop_position>0 order by a.count desc, ABS(a.slicecage_rank-@lastpos) asc LIMIT 1;
--                     if @rk is not null then
--                     select @rk;
--                         UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
--                             UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
--                             UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
--                             UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
--                             call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
--                             call intTo2ByteHex10_16_4(@rk,@rks);
--                             set dates=CONCAT("0001",@galss_ids,"0000",@rks);
--                             call message(dates,'000d',@date);
--                             set messagedate=@date;
--                             set @发送字=1;
--                     end if;
--                 end if;
--                 if @发送字=0 then
--                     SELECT 流程卡 into @processcardid from processcard_ex1 where 下片位置 is not null and 库内数>0 and 总数-切割数=0 and 工程号=@engineering_id order by  总数-下架数  asc LIMIT 1;
--                     IF @processcardid is  null then
--                         select 2;
--                             #  后使用  未完全切完的
--                             SELECT 流程卡 into @processcardid from processcard_ex1 where 下片位置 is not null and 库内数>0 and 工程号=@engineering_id order by 总数-下架数  asc LIMIT 1;    
--                     end if;
--                     -- 看看空架 有没有 ,如果有  就找一个库能玻璃最多的下架
--                     IF @processcardid is null then 
-- 
--                         SET @drop_pos=null;
--                         SELECT id into @drop_pos from gmms_drop_frame where state='空架' and groups=@work_groups limit 1;
--                         if @drop_pos  is not null then 
--                             select name1 into @name1 from namess where groups=@work_groups;
--                             SELECT 流程卡,架号,总数,工程号 into @processcardid,@drop_frame,@processcard_count,@engineering_ids from processcard_ex1 where  (库内数>=@name1 or (库内数>0 and 总数<@name1)) order by  库内数 DESC LIMIT 1;
--                             #  流程卡占架子
--                             if @processcardid is not null then 
--                                 UPDATE gmms_drop_frame set state='使用中',drop_frame=@drop_frame,processcard_id=@processcardid,processcard_count=@processcard_count,engineering_id=@engineering_ids where id=@drop_pos;
--                                 UPDATE gmms_galss_task set stop_position=@drop_pos where processcard_id=@processcardid and engineering_id=@engineering_id;                
--                             end if;            
--                         end if;
--                     end if;
--                     if @processcardid is not null then 
--                             SELECT @processcardid;    
--                             #  选定大小和槽
--                             SELECT  a.id,a.slicecage_rank,a.count,a.type_id,galss_id into @rkid,@rk,@count,@type_id,@galss_id from gmms_horizontal a inner join gmms_galss_task b on a.type_id=b.type_id where a.processcard_id=@processcardid and a.state='使用中' and a.gourp=2 and a.flag=0 and engineering_id=@engineering_id order by b.width*b.height desc ,a.count DESC  limit 1;
--                             select @count;
--                             UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
--                             UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
--                             UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
--                             UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
--                             call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
--                             call intTo2ByteHex10_16_4(@rk,@rks);
--                             set dates=CONCAT("0001",@galss_ids,"0000",@rks);
--                             call message(dates,'000d',@date);
--                             set messagedate=@date;
--                             set a=1;
--                         end if;
--                     
--                 end if;
-- --                             SELECT  a.id,a.slicecage_rank,a.count,a.type_id,galss_id into @rkid,@rk,@count,@type_id,@galss_id from gmms_horizontal a inner join gmms_galss_task b on a.id=b.slicecage_rank where  a.state='使用中' and a.gourp=2 and a.flag=0 and engineering_id=@engineering_id order by b.width*b.height desc ,a.count DESC  limit 1;
-- --                             select @count;
-- --                             UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
-- --                             UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
-- --                             UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
-- --                             UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
-- --                             call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
-- --                             call intTo2ByteHex10_16_4(@rk,@rks);
-- --                             set dates=CONCAT("0001",@galss_ids,"0000",@rks);
-- --                             call message(dates,'000d',@date);
-- --                             set messagedate=@date;
-- --                             set a=1;
--                 end if;
--             end if;
--             
--             if a=0 then
--                 #进片
--                 select rank,type_id,galss_id,processcard_id,width,height,slicecage_rank into @rankid,@type_id,@galss_id,@processcardid,@width,@height,@rk from gmms_galss_task where work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id order by rank limit 1;
--                 UPDATE gmms_galss_task set slicecage_rank=@rk,work_procedure='理片',work_state='进库中' WHERE rank=@rankid and engineering_id=@engineering_id;
--                 UPDATE gmms_horizontal set state='进库中',count=1,type_id=@type_id,processcard_id=@processcardid where slicecage_rank=@rk and gourp=1;
--                 call intTo2ByteHex10_16_4(@rankid,@rankids);
--                 call intTo2ByteHex10_16_4(@rk,@rks);
--                 set dates=CONCAT("0001",@rankids,@rks);
--                 call message(dates,'000a',@date);
--                 set messagedate=@date;
--             end if;
--                 
--     
--         end if;
--         
--     #出片
--     elseif flag=2 then
--                 SET @processcardid=null;
--                 set @rkid=null;
--                 set @rk=null;
--                 set @galss_id=null;
--                 select `value` into @lastid from gmms_var where varname='last_out_glass_id'and groups=@work_groups;
--                 select `value` into @lastpos from gmms_var where varname='last_pos'and groups=@work_groups;
--                 if @lastid is not null then
--                     select @lastid;
--                     SELECT a.id,a.slicecage_rank,a.type_id,a.count,galss_id into @rkid,@rk,@type_id,@count,@galss_id from gmms_horizontal a INNER JOIN gmms_galss_task b on a.id=b.slicecage_rank where a.state='使用中' and a.count>0 and a.type_id=@lastid and a.flag=0 and engineering_id=@engineering_id and a.gourp=2 and b.stop_position>0 order by a.count desc, ABS(a.slicecage_rank-@lastpos) asc LIMIT 1;
--                     if @rk is not null then
--                     select @rk;
--                         UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
--                             UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
--                             UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
--                             UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
--                             call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
--                             call intTo2ByteHex10_16_4(@rk,@rks);
--                             set dates=CONCAT("0001",@galss_ids,"0000",@rks);
--                             call message(dates,'000d',@date);
--                             set messagedate=@date;
--                             set @发送字=1;
--                     end if;
--                 end if;
--                 if @发送字=0 then
--                     SELECT 流程卡 into @processcardid from processcard_ex1 where 下片位置 is not null and 库内数>0 and 总数-切割数=0 and 工程号=@engineering_id order by  总数-下架数  asc LIMIT 1;
--                     IF @processcardid is  null then
--                         select 2;
--                             #  后使用  未完全切完的
--                             SELECT 流程卡 into @processcardid from processcard_ex1 where 下片位置 is not null and 库内数>0 and 工程号=@engineering_id order by 总数-下架数  asc LIMIT 1;    
--                     end if;
--                     -- 看看空架 有没有 ,如果有  就找一个库能玻璃最多的下架
--                     IF @processcardid is null then 
-- 
--                         SET @drop_pos=null;
--                         SELECT id into @drop_pos from gmms_drop_frame where state='空架' and groups=@work_groups limit 1;
--                         if @drop_pos  is not null then 
--                             select name1 into @name1 from namess where groups=@work_groups;
--                             SELECT 流程卡,架号,总数,工程号 into @processcardid,@drop_frame,@processcard_count,@engineering_ids from processcard_ex1 where  (库内数>=@name1 or (库内数>0 and 总数<@name1)) order by  库内数 DESC LIMIT 1;
--                             #  流程卡占架子
--                             if @processcardid is not null then 
--                                 UPDATE gmms_drop_frame set state='使用中',drop_frame=@drop_frame,processcard_id=@processcardid,processcard_count=@processcard_count,engineering_id=@engineering_ids where id=@drop_pos;
--                                 UPDATE gmms_galss_task set stop_position=@drop_pos where processcard_id=@processcardid and engineering_id=@engineering_id;                
--                             end if;            
--                         end if;
--                     end if;
--                     if @processcardid is not null then 
--                             SELECT @processcardid;    
--                             #  选定大小和槽
--                             SELECT  a.id,a.slicecage_rank,a.count,a.type_id,galss_id into @rkid,@rk,@count,@type_id,@galss_id from gmms_horizontal a inner join gmms_galss_task b on a.type_id=b.type_id where a.processcard_id=@processcardid and a.state='使用中' and a.gourp=2 and a.flag=0 and engineering_id=@engineering_id order by b.width*b.height desc ,a.count DESC  limit 1;
--                             select @count;
--                             UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
--                             UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
--                             UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
--                             UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
--                             call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
--                             call intTo2ByteHex10_16_4(@rk,@rks);
--                             set dates=CONCAT("0001",@galss_ids,"0000",@rks);
--                             call message(dates,'000d',@date);
--                             set messagedate=@date;
--                         end if;
--                     
--                 end if;
-- --                         SELECT  a.id,a.slicecage_rank,a.count,a.type_id,galss_id into @rkid,@rk,@count,@type_id,@galss_id from gmms_horizontal a inner join gmms_galss_task b on a.id=b.slicecage_rank where  a.state='使用中' and a.gourp=2 and a.flag=0 and engineering_id=@engineering_id order by b.width*b.height desc ,a.count DESC  limit 1;
-- --                             select @count;
-- --                             UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
-- --                             UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
-- --                             UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
-- --                             UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
-- --                             call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
-- --                             call intTo2ByteHex10_16_4(@rk,@rks);
-- --                             set dates=CONCAT("0001",@galss_ids,"0000",@rks);
-- --                             call message(dates,'000d',@date);
-- --                             set messagedate=@date;
--                 
--     #进片
--     elseif flag=1 then
--         select rank,type_id,galss_id,processcard_id,width,height,slicecage_rank into @rankid,@type_id,@galss_id,@processcardid,@width,@height,@rk from gmms_galss_task where work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id order by rank limit 1;
--         UPDATE gmms_galss_task set slicecage_rank=@rk,work_procedure='理片',work_state='进库中' WHERE rank=@rankid and engineering_id=@engineering_id;
--         UPDATE gmms_horizontal set state='进库中',count=1,type_id=@type_id,processcard_id=@processcardid where slicecage_rank=@rk and gourp=1;
--         call intTo2ByteHex10_16_4(@rankid,@rankids);
--         call intTo2ByteHex10_16_4(@rk,@rks);
--         set dates=CONCAT("0001",@rankids,@rks);
--         call message(dates,'000a',@date);
--         set messagedate=@date;
--     
--     end if;
        
    
    
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for HorizontalSend_copy2
-- ----------------------------
DROP PROCEDURE IF EXISTS `HorizontalSend_copy2`;
delimiter ;;
CREATE PROCEDURE `HorizontalSend_copy2`(in machineids BIGINT,in returnvalue varchar(255),in flags int,out messagedate varchar(255))
BEGIN
    #理片笼请求存储过程
    #判断是进片还是出片还是进出片请求
    #发送数据:玻璃编号,理片笼架子
    DECLARE a int DEFAULT 0;
    DECLARE ranks int DEFAULT 0;
    DECLARE dates varchar(255);
    DECLARE messagedates varchar(255) DEFAULT '';
    DECLARE maxw int DEFAULT 0;
    DECLARE maxh int DEFAULT 0;
    DECLARE minw int DEFAULT 0;
    DECLARE minh int DEFAULT 0;
    DECLARE kaobian varchar(255) DEFAULT null;
    set @create_time_=null;
    set @end_time_=null;
    set @create_time_=SYSDATE();
    set messagedate=messagedates;
    
 
select machine_type_id,work_id into @mtid,@work_groups from gmms_machine where id=machineids;
 
select @work_groups;
    
select file_name into @engineering_id from gmms_raw_file where operator=@work_groups and state='已领取';
 
select @engineering_id;
 
select var into @var from gmms_slicecage_pattern where groups=@work_groups;
 
select @var;
set @counts6=0;
set @counts7=0;
set @counts8=0;
set @counts9=0;
SET @发送字=0;
select count(*) into @counts6 from gmms_galss_task  where work_state='直通' and work_procedure='理片' and engineering_id=@engineering_id;
select count(*) into @counts7 from gmms_galss_task  where work_state='进库中' and work_procedure='理片' and engineering_id=@engineering_id;
select count(*) into @counts8 from gmms_galss_task  where work_state='出库中' and work_procedure='理片' and engineering_id=@engineering_id;
select count(*) into @counts9 from gmms_galss_task  where work_state='传送中' and work_procedure='理片' and engineering_id=@engineering_id;
#select count(*) into @counts10 from gmms_galss_task  where work_state='传送中' and work_procedure='理片' and engineering_id=@engineering_id;
 
#进出片
if @var='1' then
        #传送
    if flags=3 and @counts9=0 then
        if a=0 and @counts8=0 then
            set @kuneishu=0;
            select 库内数 into @kuneishu from processcard1 where 工程号=@engineering_id and 库内数>0 order by 库内数 desc  limit 0,1;
            select @kuneishu;
            select @work_groups;
            select count(*) into @counts from gmms_horizontal where state='空闲' and gourp=2;
            
                if (@kuneishu>0 or @counts<=1) and @counts6=0 then
                #出片
                SET @processcardid=null;
                set @rkid=null;
                set @rk=null;
                set @galss_id=null;
                select `value` into @lastid from gmms_var where varname='last_out_glass_id'and groups=@work_groups;
                select `value` into @lastpos from gmms_var where varname='last_pos'and groups=@work_groups;
                if @lastid is not null then
                    select @lastid;
                    select @lastpos;
                    select '进入';
                    
                    SELECT a.id,a.slicecage_rank,a.type_id,a.count,galss_id into @rkid,@rk,@type_id,@count,@galss_id from gmms_horizontal a 
                    INNER JOIN gmms_galss_task b on a.id=b.slicecage_rank INNER JOIN gmms_drop_frame c on b.processcard_id=c.processcard_id 
                    where a.state='使用中' and a.count>0 and a.type_id=@lastid and a.flag=0 and b.engineering_id=@engineering_id and  c.processcard_id is not null and a.gourp=2 and b.stop_position>0 
                    order by a.count desc, ABS(a.slicecage_rank-@lastpos) asc LIMIT 1;
                    select @rkid;
                    if @rk is not null and @rk<>0 then
                    select @rk;
                        UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
                            UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
                            UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
                            UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
                            set @galss_ids=null;
                            call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
                            select @galss_ids;
                            call intTo2ByteHex10_16_4(@rk,@rks);
                            set dates=CONCAT("0001",@galss_ids,"0000",@rks);
                            call message(dates,'000d',@date);
                            set messagedate=@date;
                            insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼出库1',@rk,@date);
                            set @发送字=1;
                            set a=1;
                    end if;
                end if;
                if @发送字=0 then
                    SELECT 流程卡 into @processcardid from processcard_ex where 下片位置 is not null and 库内数>0 and 总数-切割数=0 and 工程号=@engineering_id order by  总数-下架数  asc LIMIT 1;
                    IF @processcardid is  null then
                        select 2;
                            #  后使用  未完全切完的
                            SELECT 流程卡 into @processcardid from processcard_ex where 下片位置 is not null and 库内数>0 and 工程号=@engineering_id order by 总数-下架数  asc LIMIT 1;    
                    end if;
                    -- 看看空架 有没有 ,如果有  就找一个库能玻璃最多的下架
 
                    IF @processcardid is null then 
 
                        SET @drop_pos=null;
                        
                        select name1 into @name1 from namess where groups=@work_groups;
                        SELECT 流程卡,架号,总数,工程号 into @processcardid,@drop_frame,@processcard_count,@engineering_ids from processcard_ex 
                        where  (库内数>=@name1 or (库内数>0 and 总数<@name1)) and 工程号=@engineering_id order by  总数-库内数 LIMIT 1;
                        
                        #得到最小的 和最大的玻璃数据  判断往哪里靠边  2023-8-30
                        select MAX(width),MAX(height),MIN(width),MIN(height) into maxw,maxh,minw,minh from gmms_galss_task where processcard_id=@processcardid;
                        #if maxw<2400 and maxh<1900 and minw>599 and minh>349 then
                        if maxw<2400 and maxh<1900 and minw>529 and minh>349 then
                            set kaobian='机器人';
                        else
                            set kaobian='下片机';    
                        end if;
                        select kaobian;
                        if kaobian='下片机' then
                            select id into @drop_pos from gmms_drop_frame where state='空架' and groups=@work_groups and (stops=1 or stops=2) limit 1;
                        elseif kaobian='机器人' then
                            select id into @drop_pos from gmms_drop_frame where state='空架' and groups=@work_groups and (stops=3 or stops=4 or stops=5) limit 1;
                        end if;
                        set kaobian=null;
                        if @processcardid is not null and @drop_pos  is not null then                         
                            #  流程卡占架子
                            select @processcardid;
                            select @drop_pos;
                            select count(*) into @counts2 from gmms_galss_task where processcard_id=@processcardid and engineering_id=@engineering_id;
                            if @counts2>0 then 
                                UPDATE gmms_drop_frame set state='使用中',drop_frame=@drop_frame,processcard_id=@processcardid,processcard_count=@processcard_count,engineering_id=@engineering_id where id=@drop_pos;
                                INSERT into hn_user(update_time,add_time) VALUES(@processcardid,@work_groups);
                                UPDATE gmms_galss_task set stop_position=@drop_pos where processcard_id=@processcardid and engineering_id=@engineering_id;                
                            end if;
                        else
                            set @processcardid=null;
                            set @drop_pos=null;
                        end if;
                    end if;
                    if @processcardid is not null then 
                            SELECT @processcardid;    
                            #  选定大小和槽
                            SELECT  a.id,a.slicecage_rank,a.count,a.type_id,galss_id into @rkid,@rk,@count,@type_id,@galss_id from gmms_horizontal a 
                            inner join gmms_galss_task b on a.id=b.slicecage_rank  where a.processcard_id=@processcardid and a.state='使用中' and a.gourp=2 and a.flag=0 and engineering_id=@engineering_id 
                            order by b.width*b.height desc ,a.count DESC  limit 1;
                            select @rkid;
                            select @count;
                            select a;
                            if @rk is not null and @rk<>0 then
                            UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
                            UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
                            UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
                            UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
                            call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
                            call intTo2ByteHex10_16_4(@rk,@rks);
                            select @galss_ids,@rks,@date;
                            set dates=CONCAT("0001",@galss_ids,"0000",@rks);
                            call message(dates,'000d',@date);
                            set messagedate=@date;
                            insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼出库2',@rk,@date);
                            set a=1;
                            end if;
                        end if;
                    
                end if;
 
                end if;
            
        end if;
        select a;
        if a=0 and @counts7=0 and @counts8=0 then
        
            #set @rk=null;
            #select slicecage_rank into @rk from gmms_horizontal  
            #where (gourp=1 and state='使用中' and count>0 and flag=0) or (gourp=2 and state='空闲')  group by slicecage_rank having count(*)=2 order by count desc limit 1;
            
                #尝试代码开始
                SET @processcardid=null;
                set @rkid=null;
                set @rk=null;
                set @galss_id=null;
                select `value` into @lastid from gmms_var where varname='last_out_glass_id'and groups=@work_groups;
                select `value` into @lastpos from gmms_var where varname='last_pos'and groups=@work_groups;
                if @lastid is not null then
                    select @lastid;
                    select @lastpos;
                    select '进入';
                    
                    SELECT a.id,a.slicecage_rank,a.type_id,a.count,galss_id into @rkid,@rk,@type_id,@count,@galss_id from gmms_horizontal a 
                    INNER JOIN gmms_galss_task b on a.id=b.slicecage_rank INNER JOIN gmms_drop_frame c on b.processcard_id=c.processcard_id 
                    where a.state='使用中' and a.count>0 and a.type_id=@lastid and a.flag=0 and b.engineering_id=@engineering_id and  c.processcard_id is not null and a.gourp=1 and b.stop_position>0 
                    order by a.count desc, ABS(a.slicecage_rank-@lastpos) asc LIMIT 1;
                  
                    select @rkid; 
                    if @rk is null then
                     select slicecage_rank into @rk from gmms_horizontal  
                 where (gourp=1 and state='使用中' and count>0 and flag=0) or (gourp=2 and state='空闲')  group by slicecage_rank having count(*)=2 order by count desc limit 1;
                    end if;
                end if;
            #尝试代码结束        
            
            
            select @rk;
            if @rk is not null and @rk<>0 then
                select count(*) into @countstate from gmms_horizontal where  (state='出库中' or state='进库中');
                if @countstate=0 then
                UPDATE gmms_galss_task SET work_state='传送中' where slicecage_rank=@rk and engineering_id=@engineering_id;
                UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=1;
                select count,type_id,processcard_id into @count,@type_id,@processcard_id from gmms_horizontal where slicecage_rank=@rk and gourp=1;
                UPDATE gmms_horizontal SET state='进库中',count=@count,type_id=@type_id,processcard_id=@processcard_id where slicecage_rank=@rk and gourp=2;
                select count(*) into @counts from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id;
                select count(*) into @count1 from gmms_galss_task where work_state='直通' and work_procedure='理片' and engineering_id=@engineering_id;
                if @counts=1 then
                    if @type_id <>0 and (@processcard_id is not null or @processcard_id<>'') then
                        select galss_id into @galss_id1 from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id;
                        call intTo2ByteHex10_16_4(@galss_id1,@galss_ids1);
                        call intTo2ByteHex10_16_4(@rk,@rks);
                        set dates=CONCAT("00020000",@rks,"000200000000",@rks,"000000000000",@galss_ids1);
                        call message(dates,'000a',@date);
                        insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                            values (machineids,@work_groups,NOW(),'理片笼传送1',@rk,@date);
                        set messagedate=@date;
                        set a=1;
                    end if;
                else 
                    select galss_id into @galss_id1 from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id limit 1;
                    select galss_id into @galss_id2 from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id limit 2;
                    call intTo2ByteHex10_16_4(@galss_id1,@galss_ids1);
                    call intTo2ByteHex10_16_4(@galss_id2,@galss_ids2);
                    call intTo2ByteHex10_16_4(@rk,@rks);
                    set dates=CONCAT("00020000",@rks,"000200000000",@rks,"000000000000",@galss_ids1,@galss_id2);
                    call message(dates,'000a',@date);
                    set a=1;
                    set messagedate=@date;
                    insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                            values (machineids,@work_groups,NOW(),'理片笼传送2',@rk,@date);
                end if;
                end if;
                
            elseif @count1>0 then
                    set dates=CONCAT("000300000003","0003000000000003");
                    call message(dates,'000a',@date);
                    set messagedate=@date;
                    set a=1;
            
            end if;
        end if;
        
        if a=0 and @counts7=0 then
                #进片
                set @type_id=0;
                set @processcardid=null;
                select rank,type_id,galss_id,processcard_id,width,height,slicecage_rank into @rankid,@type_id,@galss_id,@processcardid,@width,@height,@rk from gmms_galss_task where work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id order by rank limit 1;
                if @galss_id is not null and @rk<>0 and @rk is not null then
                UPDATE gmms_galss_task set work_state='进库中',finsh_time=now() WHERE rank=@rankid and work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id;
                UPDATE gmms_horizontal set state='进库中',count=1,type_id=@type_id,processcard_id=@processcardid where slicecage_rank=@rk and gourp=1;
                call intTo2ByteHex10_16_4(@rankid,@rankids);
                call intTo2ByteHex10_16_4(@rk,@rks);
                set dates=CONCAT("0001",@rankids,@rks);
                call message(dates,'000a',@date);
                set messagedate=@date;
                insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼进库1',@rk,@date);
                end if;
            end if;
 
        
    #出片
    elseif flags=2 and @counts6=0 and @counts8=0 and @counts9=0 then
                SET @processcardid=null;
                set @rkid=null;
                set @rk=null;
                set @galss_id=null;
                select `value` into @lastid from gmms_var where varname='last_out_glass_id'and groups=@work_groups;
                select `value` into @lastpos from gmms_var where varname='last_pos'and groups=@work_groups;
                if @lastid is not null then
                    select @lastid;
                    SELECT a.id,a.slicecage_rank,a.type_id,a.count,galss_id into @rkid,@rk,@type_id,@count,@galss_id from gmms_horizontal a 
                    INNER JOIN gmms_galss_task b on a.id=b.slicecage_rank INNER JOIN gmms_drop_frame c on b.processcard_id=c.processcard_id 
                    where a.state='使用中' and a.count>0 and a.type_id=@lastid and a.flag=0 and b.engineering_id=@engineering_id and  c.processcard_id is not null and a.gourp=2 and b.stop_position>0 
                    order by a.count desc, ABS(a.slicecage_rank-@lastpos) asc LIMIT 1;
                    if @rk is not null and @rk<>0 then
                    select @rk;
                        UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
                            UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
                            UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
                            UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
                            call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
                            call intTo2ByteHex10_16_4(@rk,@rks);
                            set dates=CONCAT("0001",@galss_ids,"0000",@rks);
                            call message(dates,'000d',@date);
                            set messagedate=@date;
                            insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼出库3',@rk,@date);
                            set @发送字=1;
                    end if;
                end if;
                if @发送字=0 then
                    SELECT 流程卡 into @processcardid from processcard_ex where 下片位置 is not null and 库内数>0 and 总数-切割数=0 and 工程号=@engineering_id order by  总数-下架数  asc LIMIT 1;
                    IF @processcardid is  null then
                        select 2;
                            #  后使用  未完全切完的
                            SELECT 流程卡 into @processcardid from processcard_ex where 下片位置 is not null and 库内数>0 and 工程号=@engineering_id order by 总数-下架数  asc LIMIT 1;    
                    end if;
                    -- 看看空架 有没有 ,如果有  就找一个库能玻璃最多的下架
                    IF @processcardid is null then 
 
                        SET @drop_pos=null;
                        SELECT 流程卡,架号,总数,工程号 into @processcardid,@drop_frame,@processcard_count,@engineering_ids from processcard_ex 
                        where  (库内数>=@name1 or (库内数>0 and 总数<@name1)) and 工程号=@engineering_id order by  总数-库内数 LIMIT 1;
                            
                        #得到最小的 和最大的玻璃数据  判断往哪里靠边  2023-8-30
                        select MAX(width),MAX(height),MIN(width),MIN(height) into maxw,maxh,minw,minh from gmms_galss_task where processcard_id=@processcardid;
                        if maxw<2400 and maxh<1900 and minw>599 and minh>349 then
                            set kaobian='机器人';
                        else
                            set kaobian='下片机';    
                        end if;
                        if kaobian='下片机' then
                            select id into @drop_pos from gmms_drop_frame where state='空架' and groups=@work_groups and (stops=1 or stops=2) limit 1;
                        elseif kaobian='机器人' then
                            select id into @drop_pos from gmms_drop_frame where state='空架' and groups=@work_groups and (stops=3 or stops=4 or stops=5) limit 1;
                        end if;
                        set kaobian=null;
                        
                        if @processcardid is not null and @drop_pos  is not null then 
                            select name1 into @name1 from namess where groups=@work_groups;
                            #  流程卡占架子
                            select count(*) into @counts2 from gmms_galss_task where processcard_id=@processcardid and engineering_id=@engineering_id;
                            if @counts2>0 then 
                                UPDATE gmms_drop_frame set state='使用中',drop_frame=@drop_frame,processcard_id=@processcardid,processcard_count=@processcard_count,engineering_id=@engineering_id where id=@drop_pos;
                                INSERT into hn_user(update_time,add_time) VALUES(@processcardid,@work_groups);
                                UPDATE gmms_galss_task set stop_position=@drop_pos where processcard_id=@processcardid and engineering_id=@engineering_id;                
                            end if;
                        else
                            set @processcardid=null;
                            set @drop_pos=null;
                        end if;
                    end if;
                    if @processcardid is not null then 
                            SELECT @processcardid;    
                            #  选定大小和槽
                            SELECT  a.id,a.slicecage_rank,a.count,a.type_id,galss_id into @rkid,@rk,@count,@type_id,@galss_id from gmms_horizontal a 
                            inner join gmms_galss_task b on a.id=b.slicecage_rank  
                            where a.processcard_id=@processcardid and a.state='使用中' and a.gourp=2 and a.flag=0 and engineering_id=@engineering_id 
                            order by b.width*b.height desc ,a.count DESC  limit 1;
                            select @count;
                            if @rk is not null and @rk<>0 then
                            UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
                            UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
                            UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
                            UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
                            call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
                            call intTo2ByteHex10_16_4(@rk,@rks);
                            set dates=CONCAT("0001",@galss_ids,"0000",@rks);
                            call message(dates,'000d',@date);
                            set messagedate=@date;
                            insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼出库4',@rk,@date);
                            end if;
                        end if;
                    
                end if;
 
                
    #进片
    elseif flags=1 and @counts7=0 and @counts9=0 then
        set @rk=null;
        set @type_id=0;
                set @processcardid=null;
                select rank,type_id,galss_id,processcard_id,width,height,slicecage_rank into @rankid,@type_id,@galss_id,@processcardid,@width,@height,@rk from gmms_galss_task where work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id order by rank limit 1;
                if @galss_id is not null and @rk<>0 and @rk is not null then
                UPDATE gmms_galss_task set work_state='进库中',finsh_time=now() WHERE rank=@rankid and work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id;
                UPDATE gmms_horizontal set state='进库中',count=1,type_id=@type_id,processcard_id=@processcardid where slicecage_rank=@rk and gourp=1;
                call intTo2ByteHex10_16_4(@rankid,@rankids);
                call intTo2ByteHex10_16_4(@rk,@rks);
                set dates=CONCAT("0001",@rankids,@rks);
                call message(dates,'000a',@date);
                set messagedate=@date;
                insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼进库2',@rk,@date);
                end if;
    
    end if;
 
#直通
-- elseif @var='2' then
-- 
-- 
#存笼
elseif @var='3' then
    if flags=3 and @counts7=0 and @counts8=0 and @counts9=0 then
    set @type_id=null;
    set @count=null;
        select slicecage_rank into @rk from gmms_horizontal  where (gourp=1 and state='使用中' and count>0 and flag=0) or (gourp=2 and state='空闲')  group by slicecage_rank having count(*)=2 order by count desc limit 1;
        select @rk;
        if @rk is not null  then
                select count(*) into @countstate from gmms_horizontal where  (state='出库中' or state='进库中');
                if @countstate=0 then
              UPDATE gmms_galss_task SET work_state='传送中' where slicecage_rank=@rk and engineering_id=@engineering_id;
              UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=1;
               select count,type_id,processcard_id into @count,@type_id,@processcard_id from gmms_horizontal where slicecage_rank=@rk and gourp=1;
                
              UPDATE gmms_horizontal SET state='进库中',count=@count,type_id=@type_id,processcard_id=@processcard_id where slicecage_rank=@rk and gourp=2;
            select count(*) into @counts from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id;
            select @counts;
            if @counts=1 then
                if @type_id <>0 and (@processcard_id is not null or @processcard_id<>'') then
                    select galss_id into @galss_id1 from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id;
                    call intTo2ByteHex10_16_4(@galss_id1,@galss_ids1);
                    call intTo2ByteHex10_16_4(@rk,@rks);
                    set dates=CONCAT("00020000",@rks,"000200000000",@rks,"000000000000",@galss_ids1);
                    call message(dates,'000a',@date);
                    set messagedate=@date;
                    insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼传送3',@rk,@date);
                end if;
            else 
                     select @counts;
                end if;
            else 
                
                select galss_id into @galss_id1 from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id limit 1;
                select galss_id into @galss_id2 from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id limit 2;
                select @galss_id1,@galss_id2;
                call intTo2ByteHex10_16_4(@galss_id1,@galss_ids1);
                call intTo2ByteHex10_16_4(@galss_id2,@galss_ids2);
                call intTo2ByteHex10_16_4(@rk,@rks);
                set dates=CONCAT("00020000",@rks,"000200000000",@rks,"000000000000",@galss_ids1,@galss_id2);
                call message(dates,'000a',@date);
                set messagedate=@date;
                insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼传送4',@rk,@date);
            end if;
        else
            set @type_id=0;
            set @processcardid=null;
            select rank,type_id,galss_id,processcard_id,width,height,slicecage_rank into @rankid,@type_id,@galss_id,@processcardid,@width,@height,@rk from gmms_galss_task where work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id order by rank limit 1;
            if @galss_id is not null and @rk<>0 and @rk is not null then
                #UPDATE gmms_galss_task set slicecage_rank=@rk,work_procedure='理片',work_state='进库中' WHERE rank=@rankid and engineering_id=@engineering_id;
                UPDATE gmms_galss_task set work_state='进库中',finsh_time=now() WHERE rank=@rankid and work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id;
                UPDATE gmms_horizontal set state='进库中',count=1,type_id=@type_id,processcard_id=@processcardid where slicecage_rank=@rk and gourp=1;
                UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
                UPDATE gmms_var SET Value=@rankid where varname='last_out_glass_id' and groups=@work_groups;
                select @rankid,@rk;
                call intTo2ByteHex10_16_4(@rankid,@rankids);
                call intTo2ByteHex10_16_4(@rk,@rks);
                set dates=CONCAT("0001",@rankids,@rks);
                call message(dates,'000a',@date);
                set messagedate=@date;
                insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼进库3',@rk,@date);
            end if;
 
            
        end if;
        
 
 
                
    #进片
    elseif flags=1 and @counts7=0 and @counts9=0 then
        set @type_id=0;
                set @processcardid=null;
                select rank,type_id,galss_id,processcard_id,width,height,slicecage_rank into @rankid,@type_id,@galss_id,@processcardid,@width,@height,@rk from gmms_galss_task where work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id order by rank limit 1;
                if @galss_id is not null and @rk<>0 and @rk is not null then
                UPDATE gmms_galss_task set work_state='进库中',finsh_time=now() WHERE rank=@rankid and work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id;
                UPDATE gmms_horizontal set state='进库中',count=1,type_id=@type_id,processcard_id=@processcardid where slicecage_rank=@rk and gourp=1;
                call intTo2ByteHex10_16_4(@rankid,@rankids);
                call intTo2ByteHex10_16_4(@rk,@rks);
                UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
                UPDATE gmms_var SET Value=@rankid where varname='last_out_glass_id' and groups=@work_groups;
                set dates=CONCAT("0001",@rankids,@rks);
                call message(dates,'000a',@date);
                set messagedate=@date;
                insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼进库4',@rk,@date);
                end if;
    end if;
        
#出片
elseif @var='4' then
 
    if (flags=3 or flags=2) and @counts6=0 and @counts8=0 and @counts9=0 then
    
        SET @processcardid=null;
                set @rkid=null;
                set @rk=null;
                set @galss_id=null;
                select @lastid;
                select `value` into @lastid from gmms_var where varname='last_out_glass_id'and groups=@work_groups;
                select `value` into @lastpos from gmms_var where varname='last_pos'and groups=@work_groups;
                if @lastid is not null then
                    select @lastid;
                    SELECT a.id,a.slicecage_rank,a.type_id,a.count,galss_id into @rkid,@rk,@type_id,@count,@galss_id from gmms_horizontal a 
                    INNER JOIN gmms_galss_task b on a.id=b.slicecage_rank INNER JOIN gmms_drop_frame c on b.processcard_id=c.processcard_id 
                    where a.state='使用中' and a.count>0 and a.type_id=@lastid and a.flag=0 and b.engineering_id=@engineering_id and  c.processcard_id is not null and a.gourp=2 and b.stop_position>0 
                    order by a.count desc, ABS(a.slicecage_rank-@lastpos) asc LIMIT 1;
                    if @rk is not null and @rk<>0 then
                    select @rk;
                        UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
                            UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
                            UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
                            UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
                            call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
                            call intTo2ByteHex10_16_4(@rk,@rks);
                            set dates=CONCAT("0001",@galss_ids,"0000",@rks);
                            call message(dates,'000d',@date);
                            set messagedate=@date;
                            insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼出库5',@rk,@date);
                            set @发送字=1;
                    end if;
                end if;
                if @发送字=0 then
                    SELECT 流程卡 into @processcardid from processcard_ex where 下片位置 is not null and 库内数>0 and 总数-切割数=0 and 工程号=@engineering_id order by  总数-下架数  asc LIMIT 1;
                    IF @processcardid is  null then
                        select 2;
                            #  后使用  未完全切完的
                            SELECT 流程卡 into @processcardid from processcard_ex where 下片位置 is not null and 库内数>0 and 工程号=@engineering_id order by 总数-下架数  asc LIMIT 1;    
                    end if;
                    -- 看看空架 有没有 ,如果有  就找一个库能玻璃最多的下架
                    IF @processcardid is null then 
 
                        SET @drop_pos=null;
                        SELECT 流程卡,架号,总数,工程号 into @processcardid,@drop_frame,@processcard_count,@engineering_ids from processcard_ex 
                        where  (库内数>=@name1 or (库内数>0 and 总数<@name1)) and 工程号=@engineering_id order by  总数-库内数 LIMIT 1;
                        
                        #得到最小的 和最大的玻璃数据  判断往哪里靠边  2023-8-30
                        select MAX(width),MAX(height),MIN(width),MIN(height) into maxw,maxh,minw,minh from gmms_galss_task where processcard_id=@processcardid;
                        if maxw<2400 and maxh<1900 and minw>599 and minh>349 then
                            set kaobian='机器人';
                        else
                            set kaobian='下片机';    
                        end if;
                        if kaobian='下片机' then
                            select id into @drop_pos from gmms_drop_frame where state='空架' and groups=@work_groups and (stops=1 or stops=2) limit 1;
                        elseif kaobian='机器人' then
                            select id into @drop_pos from gmms_drop_frame where state='空架' and groups=@work_groups and (stops=3 or stops=4 or stops=5) limit 1;
                        end if;
                        set kaobian=null;
                        
                        if @processcardid is not null and @drop_pos  is not null then 
                            select name1 into @name1 from namess where groups=@work_groups;
                            #  流程卡占架子
                            select count(*) into @counts2 from gmms_galss_task where processcard_id=@processcardid and engineering_id=@engineering_id;
                            if  @counts2>0 then 
                                UPDATE gmms_drop_frame set state='使用中',drop_frame=@drop_frame,processcard_id=@processcardid,processcard_count=@processcard_count,engineering_id=@engineering_id where id=@drop_pos;
                                INSERT into hn_user(update_time,add_time) VALUES(@processcardid,@work_groups);
                                UPDATE gmms_galss_task set stop_position=@drop_pos where processcard_id=@processcardid and engineering_id=@engineering_id;                
                            end if;            
                        else
                            set @processcardid=null;
                            set @drop_pos=null;
                        end if;
                    end if;
                    if @processcardid is not null then 
                            SELECT @processcardid;    
                            #  选定大小和槽
                            SELECT  a.id,a.slicecage_rank,a.count,a.type_id,galss_id into @rkid,@rk,@count,@type_id,@galss_id from gmms_horizontal a inner join gmms_galss_task b on a.id=b.slicecage_rank  where a.processcard_id=@processcardid and a.state='使用中' and a.gourp=2 and a.flag=0 and engineering_id=@engineering_id order by b.width*b.height desc ,a.count DESC  limit 1;
                            select @rkid;
                            select @count;
                            UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
                            UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
                            UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
                            UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
                            call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
                            call intTo2ByteHex10_16_4(@rk,@rks);
                            set dates=CONCAT("0001",@galss_ids,"0000",@rks);
                            call message(dates,'000d',@date);
                            set messagedate=@date;
                            insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼出库6',@rk,@date);
                            set a=1;
                        end if;
                    
                end if;
 
    
    end if;
    
end if;
-- 
--     #传送
--     if flag=3 then
--         SELECT a.slicecage_rank,a.type_id,a.count into @rk,@type_id,@count from gmms_horizontal a INNER JOIN gmms_galss_task b on a.id=b.slicecage_rank where a.state='使用中' and a.count>0  and a.flag=0 and engineering_id=@engineering_id and a.gourp=1  order by a.count desc,a.slicecage_rank LIMIT 1;
--         select count(*) into @count1 from gmms_galss_task where work_state='直通' and work_procedure='理片';
--         select @rk;
--         if @rk is not null then
--             UPDATE gmms_galss_task SET work_state='传送中' where slicecage_rank=@rk and engineering_id=@engineering_id;
--             UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=1;
--             select count,type_id,processcard_id into @count,@type_id,@processcard_id from gmms_horizontal where slicecage_rank=@rk and gourp=1;
--             UPDATE gmms_horizontal SET state='进库中',count=@count,type_id=@type_id,processcard_id=@processcard_id where slicecage_rank=@rk and gourp=2;
--             select count(*) into @counts from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id;
--             if @counts=1 then
--                 select galss_id into @galss_id1 from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id;
--                 call intTo2ByteHex10_16_4(@galss_id1,@galss_ids1);
--                 call intTo2ByteHex10_16_4(@rk,@rks);
--                 set dates=CONCAT("00020000",@rks,"000200000000",@rks,"000000000000",@galss_ids1);
--                 call message(dates,'000a',@date);
--                 set messagedate=@date;
--             else 
--                 select galss_id into @galss_id1 from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id limit 1;
--                 select galss_id into @galss_id2 from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id limit 2;
--                 call intTo2ByteHex10_16_4(@galss_id1,@galss_ids1);
--                 call intTo2ByteHex10_16_4(@galss_id2,@galss_ids2);
--                 call intTo2ByteHex10_16_4(@rk,@rks);
--                 set dates=CONCAT("00020000",@rks,"000200000000",@rks,"000000000000",@galss_ids1,@galss_id2);
--                 call message(dates,'000a',@date);
--                 set messagedate=@date;
--             end if;
--         elseif @count1>0 then
--                 set dates=CONCAT("000300000003","0003000000000003");
--                 call message(dates,'000a',@date);
--                 set messagedate=@date;
--         else
--             select 库内数 into @kuneishu from processcard1 where 工程号=@engineering_id limit 1;
--             select @work_groups;
--             select count(*) into @counts from gmms_horizontal where state='空闲' and gourp=2;
--             if a=0 then
--                 if @kuneishu>0 or @counts<=1 then
--                 #出片
--                 SET @processcardid=null;
--                 set @rkid=null;
--                 set @rk=null;
--                 set @galss_id=null;
--                 select `value` into @lastid from gmms_var where varname='last_out_glass_id'and groups=@work_groups;
--                 select `value` into @lastpos from gmms_var where varname='last_pos'and groups=@work_groups;
--                 if @lastid is not null then
--                     select @lastid;
--                     SELECT a.id,a.slicecage_rank,a.type_id,a.count,galss_id into @rkid,@rk,@type_id,@count,@galss_id from gmms_horizontal a INNER JOIN gmms_galss_task b on a.id=b.slicecage_rank where a.state='使用中' and a.count>0 and a.type_id=@lastid and a.flag=0 and engineering_id=@engineering_id and a.gourp=2 and b.stop_position>0 order by a.count desc, ABS(a.slicecage_rank-@lastpos) asc LIMIT 1;
--                     if @rk is not null then
--                     select @rk;
--                         UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
--                             UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
--                             UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
--                             UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
--                             call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
--                             call intTo2ByteHex10_16_4(@rk,@rks);
--                             set dates=CONCAT("0001",@galss_ids,"0000",@rks);
--                             call message(dates,'000d',@date);
--                             set messagedate=@date;
--                             set @发送字=1;
--                     end if;
--                 end if;
--                 if @发送字=0 then
--                     SELECT 流程卡 into @processcardid from processcard_ex1 where 下片位置 is not null and 库内数>0 and 总数-切割数=0 and 工程号=@engineering_id order by  总数-下架数  asc LIMIT 1;
--                     IF @processcardid is  null then
--                         select 2;
--                             #  后使用  未完全切完的
--                             SELECT 流程卡 into @processcardid from processcard_ex1 where 下片位置 is not null and 库内数>0 and 工程号=@engineering_id order by 总数-下架数  asc LIMIT 1;    
--                     end if;
--                     -- 看看空架 有没有 ,如果有  就找一个库能玻璃最多的下架
--                     IF @processcardid is null then 
-- 
--                         SET @drop_pos=null;
--                         SELECT id into @drop_pos from gmms_drop_frame where state='空架' and groups=@work_groups limit 1;
--                         if @drop_pos  is not null then 
--                             select name1 into @name1 from namess where groups=@work_groups;
--                             SELECT 流程卡,架号,总数,工程号 into @processcardid,@drop_frame,@processcard_count,@engineering_ids from processcard_ex1 where  (库内数>=@name1 or (库内数>0 and 总数<@name1)) order by  库内数 DESC LIMIT 1;
--                             #  流程卡占架子
--                             if @processcardid is not null then 
--                                 UPDATE gmms_drop_frame set state='使用中',drop_frame=@drop_frame,processcard_id=@processcardid,processcard_count=@processcard_count,engineering_id=@engineering_ids where id=@drop_pos;
--                                 UPDATE gmms_galss_task set stop_position=@drop_pos where processcard_id=@processcardid and engineering_id=@engineering_id;                
--                             end if;            
--                         end if;
--                     end if;
--                     if @processcardid is not null then 
--                             SELECT @processcardid;    
--                             #  选定大小和槽
--                             SELECT  a.id,a.slicecage_rank,a.count,a.type_id,galss_id into @rkid,@rk,@count,@type_id,@galss_id from gmms_horizontal a inner join gmms_galss_task b on a.type_id=b.type_id where a.processcard_id=@processcardid and a.state='使用中' and a.gourp=2 and a.flag=0 and engineering_id=@engineering_id order by b.width*b.height desc ,a.count DESC  limit 1;
--                             select @count;
--                             UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
--                             UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
--                             UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
--                             UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
--                             call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
--                             call intTo2ByteHex10_16_4(@rk,@rks);
--                             set dates=CONCAT("0001",@galss_ids,"0000",@rks);
--                             call message(dates,'000d',@date);
--                             set messagedate=@date;
--                             set a=1;
--                         end if;
--                     
--                 end if;
-- --                             SELECT  a.id,a.slicecage_rank,a.count,a.type_id,galss_id into @rkid,@rk,@count,@type_id,@galss_id from gmms_horizontal a inner join gmms_galss_task b on a.id=b.slicecage_rank where  a.state='使用中' and a.gourp=2 and a.flag=0 and engineering_id=@engineering_id order by b.width*b.height desc ,a.count DESC  limit 1;
-- --                             select @count;
-- --                             UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
-- --                             UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
-- --                             UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
-- --                             UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
-- --                             call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
-- --                             call intTo2ByteHex10_16_4(@rk,@rks);
-- --                             set dates=CONCAT("0001",@galss_ids,"0000",@rks);
-- --                             call message(dates,'000d',@date);
-- --                             set messagedate=@date;
-- --                             set a=1;
--                 end if;
--             end if;
--             
--             if a=0 then
--                 #进片
--                 select rank,type_id,galss_id,processcard_id,width,height,slicecage_rank into @rankid,@type_id,@galss_id,@processcardid,@width,@height,@rk from gmms_galss_task where work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id order by rank limit 1;
--                 UPDATE gmms_galss_task set slicecage_rank=@rk,work_procedure='理片',work_state='进库中' WHERE rank=@rankid and engineering_id=@engineering_id;
--                 UPDATE gmms_horizontal set state='进库中',count=1,type_id=@type_id,processcard_id=@processcardid where slicecage_rank=@rk and gourp=1;
--                 call intTo2ByteHex10_16_4(@rankid,@rankids);
--                 call intTo2ByteHex10_16_4(@rk,@rks);
--                 set dates=CONCAT("0001",@rankids,@rks);
--                 call message(dates,'000a',@date);
--                 set messagedate=@date;
--             end if;
--                 
--     
--         end if;
--         
--     #出片
--     elseif flag=2 then
--                 SET @processcardid=null;
--                 set @rkid=null;
--                 set @rk=null;
--                 set @galss_id=null;
--                 select `value` into @lastid from gmms_var where varname='last_out_glass_id'and groups=@work_groups;
--                 select `value` into @lastpos from gmms_var where varname='last_pos'and groups=@work_groups;
--                 if @lastid is not null then
--                     select @lastid;
--                     SELECT a.id,a.slicecage_rank,a.type_id,a.count,galss_id into @rkid,@rk,@type_id,@count,@galss_id from gmms_horizontal a INNER JOIN gmms_galss_task b on a.id=b.slicecage_rank where a.state='使用中' and a.count>0 and a.type_id=@lastid and a.flag=0 and engineering_id=@engineering_id and a.gourp=2 and b.stop_position>0 order by a.count desc, ABS(a.slicecage_rank-@lastpos) asc LIMIT 1;
--                     if @rk is not null then
--                     select @rk;
--                         UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
--                             UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
--                             UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
--                             UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
--                             call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
--                             call intTo2ByteHex10_16_4(@rk,@rks);
--                             set dates=CONCAT("0001",@galss_ids,"0000",@rks);
--                             call message(dates,'000d',@date);
--                             set messagedate=@date;
--                             set @发送字=1;
--                     end if;
--                 end if;
--                 if @发送字=0 then
--                     SELECT 流程卡 into @processcardid from processcard_ex1 where 下片位置 is not null and 库内数>0 and 总数-切割数=0 and 工程号=@engineering_id order by  总数-下架数  asc LIMIT 1;
--                     IF @processcardid is  null then
--                         select 2;
--                             #  后使用  未完全切完的
--                             SELECT 流程卡 into @processcardid from processcard_ex1 where 下片位置 is not null and 库内数>0 and 工程号=@engineering_id order by 总数-下架数  asc LIMIT 1;    
--                     end if;
--                     -- 看看空架 有没有 ,如果有  就找一个库能玻璃最多的下架
--                     IF @processcardid is null then 
-- 
--                         SET @drop_pos=null;
--                         SELECT id into @drop_pos from gmms_drop_frame where state='空架' and groups=@work_groups limit 1;
--                         if @drop_pos  is not null then 
--                             select name1 into @name1 from namess where groups=@work_groups;
--                             SELECT 流程卡,架号,总数,工程号 into @processcardid,@drop_frame,@processcard_count,@engineering_ids from processcard_ex1 where  (库内数>=@name1 or (库内数>0 and 总数<@name1)) order by  库内数 DESC LIMIT 1;
--                             #  流程卡占架子
--                             if @processcardid is not null then 
--                                 UPDATE gmms_drop_frame set state='使用中',drop_frame=@drop_frame,processcard_id=@processcardid,processcard_count=@processcard_count,engineering_id=@engineering_ids where id=@drop_pos;
--                                 UPDATE gmms_galss_task set stop_position=@drop_pos where processcard_id=@processcardid and engineering_id=@engineering_id;                
--                             end if;            
--                         end if;
--                     end if;
--                     if @processcardid is not null then 
--                             SELECT @processcardid;    
--                             #  选定大小和槽
--                             SELECT  a.id,a.slicecage_rank,a.count,a.type_id,galss_id into @rkid,@rk,@count,@type_id,@galss_id from gmms_horizontal a inner join gmms_galss_task b on a.type_id=b.type_id where a.processcard_id=@processcardid and a.state='使用中' and a.gourp=2 and a.flag=0 and engineering_id=@engineering_id order by b.width*b.height desc ,a.count DESC  limit 1;
--                             select @count;
--                             UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
--                             UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
--                             UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
--                             UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
--                             call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
--                             call intTo2ByteHex10_16_4(@rk,@rks);
--                             set dates=CONCAT("0001",@galss_ids,"0000",@rks);
--                             call message(dates,'000d',@date);
--                             set messagedate=@date;
--                         end if;
--                     
--                 end if;
-- --                         SELECT  a.id,a.slicecage_rank,a.count,a.type_id,galss_id into @rkid,@rk,@count,@type_id,@galss_id from gmms_horizontal a inner join gmms_galss_task b on a.id=b.slicecage_rank where  a.state='使用中' and a.gourp=2 and a.flag=0 and engineering_id=@engineering_id order by b.width*b.height desc ,a.count DESC  limit 1;
-- --                             select @count;
-- --                             UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
-- --                             UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
-- --                             UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
-- --                             UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
-- --                             call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
-- --                             call intTo2ByteHex10_16_4(@rk,@rks);
-- --                             set dates=CONCAT("0001",@galss_ids,"0000",@rks);
-- --                             call message(dates,'000d',@date);
-- --                             set messagedate=@date;
--                 
--     #进片
--     elseif flag=1 then
--         select rank,type_id,galss_id,processcard_id,width,height,slicecage_rank into @rankid,@type_id,@galss_id,@processcardid,@width,@height,@rk from gmms_galss_task where work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id order by rank limit 1;
--         UPDATE gmms_galss_task set slicecage_rank=@rk,work_procedure='理片',work_state='进库中' WHERE rank=@rankid and engineering_id=@engineering_id;
--         UPDATE gmms_horizontal set state='进库中',count=1,type_id=@type_id,processcard_id=@processcardid where slicecage_rank=@rk and gourp=1;
--         call intTo2ByteHex10_16_4(@rankid,@rankids);
--         call intTo2ByteHex10_16_4(@rk,@rks);
--         set dates=CONCAT("0001",@rankids,@rks);
--         call message(dates,'000a',@date);
--         set messagedate=@date;
--     
--     end if;
        
    set @end_time_=SYSDATE();
    insert into A_LengLipian(create_time,end_time,content) values (@create_time_,@end_time_,messagedate);
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for HorizontalSend_copy3
-- ----------------------------
DROP PROCEDURE IF EXISTS `HorizontalSend_copy3`;
delimiter ;;
CREATE PROCEDURE `HorizontalSend_copy3`(in machineids BIGINT,in IsExistChu VARCHAR(255),in returnvalue varchar(255),in flags int,out messagedate varchar(255))
BEGIN
    #理片笼请求存储过程
    #判断是进片还是出片还是进出片请求
    #发送数据:玻璃编号,理片笼架子
    DECLARE a int DEFAULT 0;
    DECLARE ranks int DEFAULT 0;
    DECLARE dates varchar(255);
    DECLARE messagedates varchar(255) DEFAULT '';
    DECLARE maxw int DEFAULT 0;
    DECLARE maxh int DEFAULT 0;
    DECLARE minw int DEFAULT 0;
    DECLARE minh int DEFAULT 0;
    DECLARE kaobian varchar(255) DEFAULT null;
    set @create_time_=null;
    set @end_time_=null;
    set @create_time_=SYSDATE();
    set messagedate=messagedates;
    
 
select machine_type_id,work_id into @mtid,@work_groups from gmms_machine where id=machineids;
 
select @work_groups;
    
select file_name into @engineering_id from gmms_raw_file where operator=@work_groups and state='已领取';
 
select @engineering_id;
 
select var into @var from gmms_slicecage_pattern where groups=@work_groups;
 
select @var;
set @counts6=0;
set @counts7=0;
set @counts8=0;
set @counts9=0;
set @counts10=0;
set @Lp_Mode=0;
SET @发送字=0;
select count(*) into @counts6 from gmms_galss_task  where work_state='直通' and work_procedure='理片' and engineering_id=@engineering_id;
select count(*) into @counts7 from gmms_galss_task  where work_state='进库中' and work_procedure='理片' and engineering_id=@engineering_id;
select count(*) into @counts8 from gmms_galss_task  where work_state='出库中' and work_procedure='理片' and engineering_id=@engineering_id;
select count(*) into @counts9 from gmms_galss_task  where work_state='传送中' and work_procedure='理片' and engineering_id=@engineering_id;
 
select count(*) into @counts10 from gmms_horizontal as gh left join gmms_galss_task as gt on gh.slicecage_rank =gt.slicecage_rank 
where gh.processcard_id is not null and gh.gourp=1 and work_state='传送中' and work_procedure='理片' and engineering_id=@engineering_id order by gh.slicecage_rank;
set @conts=null;
set @conts=CONCAT(IFNULL(flags,','),IFNULL(@counts6,','),IFNULL(@counts7,','),IFNULL(@counts8,','),IFNULL(@counts9,','),IFNULL(@counts10,','));
 
#进出片
if @var='1' then
        #传送
    if flags=3 then
        if a=0 and @counts8=0 and @counts9=0 then
            set @kuneishu=0;
            select 库内数 into @kuneishu from processcard1 where 工程号=@engineering_id and 库内数>0 order by 库内数 desc  limit 0,1;
            select @kuneishu;
            select @work_groups;
            select count(*) into @counts from gmms_horizontal where state='空闲' and gourp=2;
            
                if (@kuneishu>0 or @counts<=1) and @counts6=0 then
                #出片
                SET @processcardid=null;
                set @rkid=null;
                set @rk=null;
                set @galss_id=null;
                select `value` into @lastid from gmms_var where varname='last_out_glass_id'and groups=@work_groups;
                select `value` into @lastpos from gmms_var where varname='last_pos'and groups=@work_groups;
                if @lastid is not null then
                    select @lastid;
                    select @lastpos;
                    select '进入';
                    
                    SELECT a.id,a.slicecage_rank,a.type_id,a.count,galss_id into @rkid,@rk,@type_id,@count,@galss_id from gmms_horizontal a 
                    INNER JOIN gmms_galss_task b on a.id=b.slicecage_rank INNER JOIN gmms_drop_frame c on b.processcard_id=c.processcard_id 
                    where a.state='使用中' and a.count>0 and a.type_id=@lastid and a.flag=0 and b.engineering_id=@engineering_id and  c.processcard_id is not null and a.gourp=2 and b.stop_position>0 
                    order by a.count desc, ABS(a.slicecage_rank-@lastpos) asc LIMIT 1;
                    select @rkid;
                    if @rk is not null and @rk<>0 then
                    select @rk;
                        UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
                            UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
                            UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
                            UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
                            set @galss_ids=null;
                            call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
                            select @galss_ids;
                            call intTo2ByteHex10_16_4(@rk,@rks);
                            set dates=CONCAT("0001",@galss_ids,"0000",@rks);
                            call message(dates,'000d',@date);
                            set messagedate=@date;
                            insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼出库1',@rk,@date);
                            set @发送字=1;
                            set a=1;
                    end if;
                end if;
                if @发送字=0 then
                    SELECT 流程卡 into @processcardid from processcard_ex where 下片位置 is not null and 库内数>0 and 总数-切割数=0 and 工程号=@engineering_id order by  总数-下架数  asc LIMIT 1;
                    IF @processcardid is  null then
                        select 2;
                            #  后使用  未完全切完的
                            SELECT 流程卡 into @processcardid from processcard_ex where 下片位置 is not null and 库内数>0 and 工程号=@engineering_id order by 总数-下架数  asc LIMIT 1;    
                    end if;
                    -- 看看空架 有没有 ,如果有  就找一个库能玻璃最多的下架
 
                    IF @processcardid is null then 
 
                        SET @drop_pos=null;
                        
                        select name1 into @name1 from namess where groups=@work_groups;
                        SELECT 流程卡,架号,总数,工程号 into @processcardid,@drop_frame,@processcard_count,@engineering_ids from processcard_ex 
                        where  (库内数>=@name1 or (库内数>0 and 总数<@name1)) and 工程号=@engineering_id order by  总数-库内数 LIMIT 1;
                        
                        #得到最小的 和最大的玻璃数据  判断往哪里靠边  2023-8-30
                        select MAX(width),MAX(height),MIN(width),MIN(height) into maxw,maxh,minw,minh from gmms_galss_task where processcard_id=@processcardid;
                        #if maxw<2400 and maxh<1900 and minw>599 and minh>349 then
                        if maxw<2400 and maxh<1900 and minw>529 and minh>349 then
                            set kaobian='机器人';
                        else
                            set kaobian='下片机';    
                        end if;
                        select kaobian;
                        if kaobian='下片机' then
                            select id into @drop_pos from gmms_drop_frame where state='空架' and groups=@work_groups and (stops=1 or stops=2) limit 1;
                        elseif kaobian='机器人' then
                            select id into @drop_pos from gmms_drop_frame where state='空架' and groups=@work_groups and (stops=3 or stops=4 or stops=5) limit 1;
                        end if;
                        set kaobian=null;
                        if @processcardid is not null and @drop_pos  is not null then                         
                            #  流程卡占架子
                            select @processcardid;
                            select @drop_pos;
                            select count(*) into @counts2 from gmms_galss_task where processcard_id=@processcardid and engineering_id=@engineering_id;
                            if @counts2>0 then 
                                UPDATE gmms_drop_frame set state='使用中',drop_frame=@drop_frame,processcard_id=@processcardid,processcard_count=@processcard_count,engineering_id=@engineering_id where id=@drop_pos;
                                INSERT into hn_user(update_time,add_time) VALUES(@processcardid,@work_groups);
                                UPDATE gmms_galss_task set stop_position=@drop_pos where processcard_id=@processcardid and engineering_id=@engineering_id;                
                            end if;
                        else
                            set @processcardid=null;
                            set @drop_pos=null;
                        end if;
                    end if;
                    if @processcardid is not null then 
                            SELECT @processcardid;    
                            #  选定大小和槽
                            SELECT  a.id,a.slicecage_rank,a.count,a.type_id,galss_id into @rkid,@rk,@count,@type_id,@galss_id from gmms_horizontal a 
                            inner join gmms_galss_task b on a.id=b.slicecage_rank  where a.processcard_id=@processcardid and a.state='使用中' and a.gourp=2 and a.flag=0 and engineering_id=@engineering_id 
                            order by b.width*b.height desc ,a.count DESC  limit 1;
                            select @rkid;
                            select @count;
                            select a;
                            if @rk is not null and @rk<>0 then
                            UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
                            UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
                            UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
                            UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
                            call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
                            call intTo2ByteHex10_16_4(@rk,@rks);
                            select @galss_ids,@rks,@date;
                            set dates=CONCAT("0001",@galss_ids,"0000",@rks);
                            call message(dates,'000d',@date);
                            set messagedate=@date;
                            insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼出库2',@rk,@date);
                            set a=1;
                            end if;
                        end if;
                    
                end if;
 
                end if;
            
        end if;
        select a;
        if a=0 and @counts7=0 and @counts8=0 and @counts9=0 then
        
            set @rk=null;
            set @LastGalssid=null;
            set @ProcesscardA1=null;
            set @ProcesscardA2=null;
            
--             select slicecage_rank into @rk from gmms_horizontal  
--             where (gourp=1 and state='使用中' and count>0 and flag=0) or (gourp=2 and state='空闲')  group by slicecage_rank having count(*)=2 order by count desc limit 1;
            
            #2023-11-14  YZX更新
            select 
            (SELECT b.id from gmms_horizontal a 
            INNER JOIN gmms_galss_task b on a.id=b.slicecage_rank 
            INNER JOIN gmms_drop_frame c on b.processcard_id=c.processcard_id 
            where a.state='使用中' and a.count>0 and a.type_id=ls1.value and a.flag=0 and b.engineering_id=grf.file_name and  c.processcard_id is not null and a.gourp=1 and b.stop_position>0 
            order by a.count desc, ABS(a.slicecage_rank-ls2.value) asc LIMIT 1),
            (SELECT 流程卡 from processcard_ex where 下片位置 is not null and 库内数>0 and 工程号=grf.file_name order by 总数-下架数  asc LIMIT 1) ,
            (SELECT 流程卡 from processcard_ex where (库内数>=ns.name1 or (库内数>0 and 总数<ns.name2)) and 工程号=grf.file_name order by  总数-库内数 LIMIT 1)
            INTO @LastGalssid,@ProcesscardA1,@ProcesscardA2
            from gmms_machine as gm 
            LEFT JOIN gmms_raw_file as grf on gm.work_id=grf.operator and grf.state='已领取'
            LEFT JOIN gmms_var as ls1 on gm.work_id=ls1.groups and ls1.varname='last_out_glass_id'
            LEFT JOIN gmms_var as ls2 on gm.work_id=ls2.groups and ls2.varname='last_pos'
            LEFT JOIN namess as ns on gm.work_id=ns.groups
            where gm.id=27;
            
            if @LastGalssid is not null then
                select hl1.slicecage_rank into @rk from gmms_horizontal as hl1 
                left join gmms_horizontal as hl2 on hl1.slicecage_rank=hl2.slicecage_rank
                where hl1.gourp=1 and hl2.gourp=2 and hl1.state='使用中' and hl1.count>0 and hl1.flag=0 and hl2.gourp=2 and hl2.state='空闲' 
                and hl1.slicecage_rank=(select slicecage_rank from gmms_galss_task where id=@LastGalssid);
            elseif @ProcesscardA1 is not null then
                select hl1.slicecage_rank into @rk from gmms_horizontal as hl1 
                left join gmms_horizontal as hl2 on hl1.slicecage_rank=hl2.slicecage_rank
                where hl1.gourp=1 and hl2.gourp=2 and hl1.state='使用中' and hl1.count>0 and hl1.flag=0 and hl2.gourp=2 and hl2.state='空闲' 
                and hl1.processcard_id=@ProcesscardA1 order by hl1.count desc limit 1;
            elseif @ProcesscardA2 is not null then
                select hl1.slicecage_rank into @rk from gmms_horizontal as hl1 
                left join gmms_horizontal as hl2 on hl1.slicecage_rank=hl2.slicecage_rank
                where hl1.gourp=1 and hl2.gourp=2 and hl1.state='使用中' and hl1.count>0 and hl1.flag=0 and hl2.gourp=2 and hl2.state='空闲' 
                and hl1.processcard_id=@ProcesscardA2 order by hl1.count desc limit 1;
            end if;            
            
            if @rk is null then
                select slicecage_rank into @rk from gmms_horizontal  
                where (gourp=1 and state='使用中' and count>0 and flag=0) or (gourp=2 and state='空闲')  group by slicecage_rank having count(*)=2 order by count desc limit 1;
            end if;
            select @rk;
            
                    
            if @rk is not null and @rk<>0 then
                select count(*) into @countstate from gmms_horizontal where  (state='出库中' or state='进库中');
                if @countstate=0 then
                UPDATE gmms_galss_task SET work_state='传送中' where slicecage_rank=@rk and engineering_id=@engineering_id;
                UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=1;
                select count,type_id,processcard_id into @count,@type_id,@processcard_id from gmms_horizontal where slicecage_rank=@rk and gourp=1;
                UPDATE gmms_horizontal SET state='进库中',count=@count,type_id=@type_id,processcard_id=@processcard_id where slicecage_rank=@rk and gourp=2;
                select count(*) into @counts from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id;
                select count(*) into @count1 from gmms_galss_task where work_state='直通' and work_procedure='理片' and engineering_id=@engineering_id;
                if @counts=1 then
                    if @type_id <>0 and (@processcard_id is not null or @processcard_id<>'') then
                        select galss_id into @galss_id1 from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id;
                        call intTo2ByteHex10_16_4(@galss_id1,@galss_ids1);
                        call intTo2ByteHex10_16_4(@rk,@rks);
                        set dates=CONCAT("00020000",@rks,"000200000000",@rks,"000000000000",@galss_ids1);
                        call message(dates,'000a',@date);
                        insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                            values (machineids,@work_groups,NOW(),'理片笼传送1',@rk,@date);
                        set messagedate=@date;
                        set a=1;
                    end if;
                else 
                    select galss_id into @galss_id1 from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id limit 1;
                    select galss_id into @galss_id2 from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id limit 2;
                    call intTo2ByteHex10_16_4(@galss_id1,@galss_ids1);
                    call intTo2ByteHex10_16_4(@galss_id2,@galss_ids2);
                    call intTo2ByteHex10_16_4(@rk,@rks);
                    set dates=CONCAT("00020000",@rks,"000200000000",@rks,"000000000000",@galss_ids1,@galss_id2);
                    call message(dates,'000a',@date);
                    set a=1;
                    set messagedate=@date;
                    insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                            values (machineids,@work_groups,NOW(),'理片笼传送2',@rk,@date);
                end if;
                end if;
                
            elseif @count1>0 then
                    set dates=CONCAT("000300000003","0003000000000003");
                    call message(dates,'000a',@date);
                    set messagedate=@date;
                    set a=1;
            
            end if;
        end if;
        
        if a=0 and @counts7=0 and @counts10=0 then
                #进片
                set @type_id=0;
                set @processcardid=null;
                select rank,type_id,galss_id,processcard_id,width,height,slicecage_rank into @rankid,@type_id,@galss_id,@processcardid,@width,@height,@rk from gmms_galss_task where work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id order by rank limit 1;
                if @galss_id is not null and @rk<>0 and @rk is not null then
                UPDATE gmms_galss_task set work_state='进库中',finsh_time=now() WHERE rank=@rankid and work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id;
                UPDATE gmms_horizontal set state='进库中',count=1,type_id=@type_id,processcard_id=@processcardid where slicecage_rank=@rk and gourp=1;
                call intTo2ByteHex10_16_4(@rankid,@rankids);
                call intTo2ByteHex10_16_4(@rk,@rks);
                set dates=CONCAT("0001",@rankids,@rks);
                call message(dates,'000a',@date);
                set messagedate=@date;
                insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼进库1',@rk,@date);
                end if;
        end if;
 
        
    #出片
    elseif flags=2 and @counts6=0 and @counts8=0 and @counts9=0 then
                SET @processcardid=null;
                set @rkid=null;
                set @rk=null;
                set @galss_id=null;
                select `value` into @lastid from gmms_var where varname='last_out_glass_id'and groups=@work_groups;
                select `value` into @lastpos from gmms_var where varname='last_pos'and groups=@work_groups;
                if @lastid is not null then
                    select @lastid;
                    SELECT a.id,a.slicecage_rank,a.type_id,a.count,galss_id into @rkid,@rk,@type_id,@count,@galss_id from gmms_horizontal a 
                    INNER JOIN gmms_galss_task b on a.id=b.slicecage_rank INNER JOIN gmms_drop_frame c on b.processcard_id=c.processcard_id 
                    where a.state='使用中' and a.count>0 and a.type_id=@lastid and a.flag=0 and b.engineering_id=@engineering_id and  c.processcard_id is not null and a.gourp=2 and b.stop_position>0 
                    order by a.count desc, ABS(a.slicecage_rank-@lastpos) asc LIMIT 1;
                    if @rk is not null and @rk<>0 then
                    select @rk;
                        UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
                            UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
                            UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
                            UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
                            call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
                            call intTo2ByteHex10_16_4(@rk,@rks);
                            set dates=CONCAT("0001",@galss_ids,"0000",@rks);
                            call message(dates,'000d',@date);
                            set messagedate=@date;
                            insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼出库3',@rk,@date);
                            set @发送字=1;
                    end if;
                end if;
                if @发送字=0 then
                    SELECT 流程卡 into @processcardid from processcard_ex where 下片位置 is not null and 库内数>0 and 总数-切割数=0 and 工程号=@engineering_id order by  总数-下架数  asc LIMIT 1;
                    IF @processcardid is  null then
                        select 2;
                            #  后使用  未完全切完的
                            SELECT 流程卡 into @processcardid from processcard_ex where 下片位置 is not null and 库内数>0 and 工程号=@engineering_id order by 总数-下架数  asc LIMIT 1;    
                    end if;
                    -- 看看空架 有没有 ,如果有  就找一个库能玻璃最多的下架
                    IF @processcardid is null then 
 
                        SET @drop_pos=null;
                        SELECT 流程卡,架号,总数,工程号 into @processcardid,@drop_frame,@processcard_count,@engineering_ids from processcard_ex 
                        where  (库内数>=@name1 or (库内数>0 and 总数<@name1)) and 工程号=@engineering_id order by  总数-库内数 LIMIT 1;
                            
                        #得到最小的 和最大的玻璃数据  判断往哪里靠边  2023-8-30
                        select MAX(width),MAX(height),MIN(width),MIN(height) into maxw,maxh,minw,minh from gmms_galss_task where processcard_id=@processcardid;
                        if maxw<2400 and maxh<1900 and minw>599 and minh>349 then
                            set kaobian='机器人';
                        else
                            set kaobian='下片机';    
                        end if;
                        if kaobian='下片机' then
                            select id into @drop_pos from gmms_drop_frame where state='空架' and groups=@work_groups and (stops=1 or stops=2) limit 1;
                        elseif kaobian='机器人' then
                            select id into @drop_pos from gmms_drop_frame where state='空架' and groups=@work_groups and (stops=3 or stops=4 or stops=5) limit 1;
                        end if;
                        set kaobian=null;
                        
                        if @processcardid is not null and @drop_pos  is not null then 
                            select name1 into @name1 from namess where groups=@work_groups;
                            #  流程卡占架子
                            select count(*) into @counts2 from gmms_galss_task where processcard_id=@processcardid and engineering_id=@engineering_id;
                            if @counts2>0 then 
                                UPDATE gmms_drop_frame set state='使用中',drop_frame=@drop_frame,processcard_id=@processcardid,processcard_count=@processcard_count,engineering_id=@engineering_id where id=@drop_pos;
                                INSERT into hn_user(update_time,add_time) VALUES(@processcardid,@work_groups);
                                UPDATE gmms_galss_task set stop_position=@drop_pos where processcard_id=@processcardid and engineering_id=@engineering_id;                
                            end if;
                        else
                            set @processcardid=null;
                            set @drop_pos=null;
                        end if;
                    end if;
                    if @processcardid is not null then 
                            SELECT @processcardid;    
                            #  选定大小和槽
                            SELECT  a.id,a.slicecage_rank,a.count,a.type_id,galss_id into @rkid,@rk,@count,@type_id,@galss_id from gmms_horizontal a 
                            inner join gmms_galss_task b on a.id=b.slicecage_rank  
                            where a.processcard_id=@processcardid and a.state='使用中' and a.gourp=2 and a.flag=0 and engineering_id=@engineering_id 
                            order by b.width*b.height desc ,a.count DESC  limit 1;
                            select @count;
                            if @rk is not null and @rk<>0 then
                            UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
                            UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
                            UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
                            UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
                            call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
                            call intTo2ByteHex10_16_4(@rk,@rks);
                            set dates=CONCAT("0001",@galss_ids,"0000",@rks);
                            call message(dates,'000d',@date);
                            set messagedate=@date;
                            insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼出库4',@rk,@date);
                            end if;
                        end if;
                    
                end if;
 
                
    #进片
    elseif flags=1 and @counts7=0 and @counts10=0 then
        set @rk=null;
        set @type_id=0;
                set @processcardid=null;
                select rank,type_id,galss_id,processcard_id,width,height,slicecage_rank into @rankid,@type_id,@galss_id,@processcardid,@width,@height,@rk from gmms_galss_task where work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id order by rank limit 1;
                if @galss_id is not null and @rk<>0 and @rk is not null then
                UPDATE gmms_galss_task set work_state='进库中',finsh_time=now() WHERE rank=@rankid and work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id;
                UPDATE gmms_horizontal set state='进库中',count=1,type_id=@type_id,processcard_id=@processcardid where slicecage_rank=@rk and gourp=1;
                call intTo2ByteHex10_16_4(@rankid,@rankids);
                call intTo2ByteHex10_16_4(@rk,@rks);
                set dates=CONCAT("0001",@rankids,@rks);
                call message(dates,'000a',@date);
                set messagedate=@date;
                insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼进库2',@rk,@date);
                end if;
    
    end if;
 
#直通
-- elseif @var='2' then
-- 
-- 
#存笼
elseif @var='3' then
    if flags=3 and @counts7=0 then
    set @type_id=null;
    set @count=null;
        select slicecage_rank into @rk from gmms_horizontal  where (gourp=1 and state='使用中' and count>0 and flag=0) or (gourp=2 and state='空闲')  group by slicecage_rank having count(*)=2 order by count desc limit 1;
        select @rk;
        if @rk is not null and @counts8=0 and @counts9=0  then
                select count(*) into @countstate from gmms_horizontal where  (state='出库中' or state='进库中');
                if @countstate=0 then
              UPDATE gmms_galss_task SET work_state='传送中' where slicecage_rank=@rk and engineering_id=@engineering_id;
              UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=1;
               select count,type_id,processcard_id into @count,@type_id,@processcard_id from gmms_horizontal where slicecage_rank=@rk and gourp=1;
                
              UPDATE gmms_horizontal SET state='进库中',count=@count,type_id=@type_id,processcard_id=@processcard_id where slicecage_rank=@rk and gourp=2;
            select count(*) into @counts from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id;
            select @counts;
            if @counts=1 then
                if @type_id <>0 and (@processcard_id is not null or @processcard_id<>'') then
                    select galss_id into @galss_id1 from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id;
                    call intTo2ByteHex10_16_4(@galss_id1,@galss_ids1);
                    call intTo2ByteHex10_16_4(@rk,@rks);
                    set dates=CONCAT("00020000",@rks,"000200000000",@rks,"000000000000",@galss_ids1);
                    call message(dates,'000a',@date);
                    set messagedate=@date;
                    insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼传送3',@rk,@date);
                end if;
            else 
                     select @counts;
                end if;
            else 
                
                select galss_id into @galss_id1 from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id limit 1;
                select galss_id into @galss_id2 from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id limit 2;
                select @galss_id1,@galss_id2;
                call intTo2ByteHex10_16_4(@galss_id1,@galss_ids1);
                call intTo2ByteHex10_16_4(@galss_id2,@galss_ids2);
                call intTo2ByteHex10_16_4(@rk,@rks);
                set dates=CONCAT("00020000",@rks,"000200000000",@rks,"000000000000",@galss_ids1,@galss_id2);
                call message(dates,'000a',@date);
                set messagedate=@date;
                insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼传送4',@rk,@date);
            end if;
        elseif @counts10=0 then
            set @type_id=0;
            set @processcardid=null;
            select rank,type_id,galss_id,processcard_id,width,height,slicecage_rank into @rankid,@type_id,@galss_id,@processcardid,@width,@height,@rk from gmms_galss_task where work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id order by rank limit 1;
            if @galss_id is not null and @rk<>0 and @rk is not null then
                #UPDATE gmms_galss_task set slicecage_rank=@rk,work_procedure='理片',work_state='进库中' WHERE rank=@rankid and engineering_id=@engineering_id;
                UPDATE gmms_galss_task set work_state='进库中',finsh_time=now() WHERE rank=@rankid and work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id;
                UPDATE gmms_horizontal set state='进库中',count=1,type_id=@type_id,processcard_id=@processcardid where slicecage_rank=@rk and gourp=1;
                UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
                UPDATE gmms_var SET Value=@rankid where varname='last_out_glass_id' and groups=@work_groups;
                select @rankid,@rk;
                call intTo2ByteHex10_16_4(@rankid,@rankids);
                call intTo2ByteHex10_16_4(@rk,@rks);
                set dates=CONCAT("0001",@rankids,@rks);
                call message(dates,'000a',@date);
                set messagedate=@date;
                insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼进库3',@rk,@date);
            end if;
 
            
        end if;
        
 
 
                
    #进片
    elseif flags=1 and @counts7=0 and @counts10=0 then
        set @type_id=0;
                set @processcardid=null;
                select rank,type_id,galss_id,processcard_id,width,height,slicecage_rank into @rankid,@type_id,@galss_id,@processcardid,@width,@height,@rk from gmms_galss_task where work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id order by rank limit 1;
                if @galss_id is not null and @rk<>0 and @rk is not null then
                UPDATE gmms_galss_task set work_state='进库中',finsh_time=now() WHERE rank=@rankid and work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id;
                UPDATE gmms_horizontal set state='进库中',count=1,type_id=@type_id,processcard_id=@processcardid where slicecage_rank=@rk and gourp=1;
                call intTo2ByteHex10_16_4(@rankid,@rankids);
                call intTo2ByteHex10_16_4(@rk,@rks);
                UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
                UPDATE gmms_var SET Value=@rankid where varname='last_out_glass_id' and groups=@work_groups;
                set dates=CONCAT("0001",@rankids,@rks);
                call message(dates,'000a',@date);
                set messagedate=@date;
                insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼进库4',@rk,@date);
                end if;
    end if;
        
#出片
elseif @var='4' then
 
    if (flags=3 or flags=2) and @counts6=0 and @counts8=0 and @counts9=0 then
    
        SET @processcardid=null;
                set @rkid=null;
                set @rk=null;
                set @galss_id=null;
                select @lastid;
                select `value` into @lastid from gmms_var where varname='last_out_glass_id'and groups=@work_groups;
                select `value` into @lastpos from gmms_var where varname='last_pos'and groups=@work_groups;
                if @lastid is not null then
                    select @lastid;
                    SELECT a.id,a.slicecage_rank,a.type_id,a.count,galss_id into @rkid,@rk,@type_id,@count,@galss_id from gmms_horizontal a 
                    INNER JOIN gmms_galss_task b on a.id=b.slicecage_rank INNER JOIN gmms_drop_frame c on b.processcard_id=c.processcard_id 
                    where a.state='使用中' and a.count>0 and a.type_id=@lastid and a.flag=0 and b.engineering_id=@engineering_id and  c.processcard_id is not null and a.gourp=2 and b.stop_position>0 
                    order by a.count desc, ABS(a.slicecage_rank-@lastpos) asc LIMIT 1;
                    if @rk is not null and @rk<>0 then
                    select @rk;
                        UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
                            UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
                            UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
                            UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
                            call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
                            call intTo2ByteHex10_16_4(@rk,@rks);
                            set dates=CONCAT("0001",@galss_ids,"0000",@rks);
                            call message(dates,'000d',@date);
                            set messagedate=@date;
                            insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼出库5',@rk,@date);
                            set @发送字=1;
                    end if;
                end if;
                if @发送字=0 then
                    SELECT 流程卡 into @processcardid from processcard_ex where 下片位置 is not null and 库内数>0 and 总数-切割数=0 and 工程号=@engineering_id order by  总数-下架数  asc LIMIT 1;
                    IF @processcardid is  null then
                        select 2;
                            #  后使用  未完全切完的
                            SELECT 流程卡 into @processcardid from processcard_ex where 下片位置 is not null and 库内数>0 and 工程号=@engineering_id order by 总数-下架数  asc LIMIT 1;    
                    end if;
                    -- 看看空架 有没有 ,如果有  就找一个库能玻璃最多的下架
                    IF @processcardid is null then 
 
                        SET @drop_pos=null;
                        SELECT 流程卡,架号,总数,工程号 into @processcardid,@drop_frame,@processcard_count,@engineering_ids from processcard_ex 
                        where  (库内数>=@name1 or (库内数>0 and 总数<@name1)) and 工程号=@engineering_id order by  总数-库内数 LIMIT 1;
                        
                        #得到最小的 和最大的玻璃数据  判断往哪里靠边  2023-8-30
                        select MAX(width),MAX(height),MIN(width),MIN(height) into maxw,maxh,minw,minh from gmms_galss_task where processcard_id=@processcardid;
                        if maxw<2400 and maxh<1900 and minw>599 and minh>349 then
                            set kaobian='机器人';
                        else
                            set kaobian='下片机';    
                        end if;
                        if kaobian='下片机' then
                            select id into @drop_pos from gmms_drop_frame where state='空架' and groups=@work_groups and (stops=1 or stops=2) limit 1;
                        elseif kaobian='机器人' then
                            select id into @drop_pos from gmms_drop_frame where state='空架' and groups=@work_groups and (stops=3 or stops=4 or stops=5) limit 1;
                        end if;
                        set kaobian=null;
                        
                        if @processcardid is not null and @drop_pos  is not null then 
                            select name1 into @name1 from namess where groups=@work_groups;
                            #  流程卡占架子
                            select count(*) into @counts2 from gmms_galss_task where processcard_id=@processcardid and engineering_id=@engineering_id;
                            if  @counts2>0 then 
                                UPDATE gmms_drop_frame set state='使用中',drop_frame=@drop_frame,processcard_id=@processcardid,processcard_count=@processcard_count,engineering_id=@engineering_id where id=@drop_pos;
                                INSERT into hn_user(update_time,add_time) VALUES(@processcardid,@work_groups);
                                UPDATE gmms_galss_task set stop_position=@drop_pos where processcard_id=@processcardid and engineering_id=@engineering_id;                
                            end if;            
                        else
                            set @processcardid=null;
                            set @drop_pos=null;
                        end if;
                    end if;
                    if @processcardid is not null then 
                            SELECT @processcardid;    
                            #  选定大小和槽
                            SELECT  a.id,a.slicecage_rank,a.count,a.type_id,galss_id into @rkid,@rk,@count,@type_id,@galss_id from gmms_horizontal a inner join gmms_galss_task b on a.id=b.slicecage_rank  where a.processcard_id=@processcardid and a.state='使用中' and a.gourp=2 and a.flag=0 and engineering_id=@engineering_id order by b.width*b.height desc ,a.count DESC  limit 1;
                            select @rkid;
                            select @count;
                            UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
                            UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
                            UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
                            UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
                            call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
                            call intTo2ByteHex10_16_4(@rk,@rks);
                            set dates=CONCAT("0001",@galss_ids,"0000",@rks);
                            call message(dates,'000d',@date);
                            set messagedate=@date;
                            insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'理片笼出库6',@rk,@date);
                            set a=1;
                        end if;
                    
                end if;
 
    
    end if;
    
end if;
-- 
--     #传送
--     if flag=3 then
--         SELECT a.slicecage_rank,a.type_id,a.count into @rk,@type_id,@count from gmms_horizontal a INNER JOIN gmms_galss_task b on a.id=b.slicecage_rank where a.state='使用中' and a.count>0  and a.flag=0 and engineering_id=@engineering_id and a.gourp=1  order by a.count desc,a.slicecage_rank LIMIT 1;
--         select count(*) into @count1 from gmms_galss_task where work_state='直通' and work_procedure='理片';
--         select @rk;
--         if @rk is not null then
--             UPDATE gmms_galss_task SET work_state='传送中' where slicecage_rank=@rk and engineering_id=@engineering_id;
--             UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=1;
--             select count,type_id,processcard_id into @count,@type_id,@processcard_id from gmms_horizontal where slicecage_rank=@rk and gourp=1;
--             UPDATE gmms_horizontal SET state='进库中',count=@count,type_id=@type_id,processcard_id=@processcard_id where slicecage_rank=@rk and gourp=2;
--             select count(*) into @counts from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id;
--             if @counts=1 then
--                 select galss_id into @galss_id1 from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id;
--                 call intTo2ByteHex10_16_4(@galss_id1,@galss_ids1);
--                 call intTo2ByteHex10_16_4(@rk,@rks);
--                 set dates=CONCAT("00020000",@rks,"000200000000",@rks,"000000000000",@galss_ids1);
--                 call message(dates,'000a',@date);
--                 set messagedate=@date;
--             else 
--                 select galss_id into @galss_id1 from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id limit 1;
--                 select galss_id into @galss_id2 from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id limit 2;
--                 call intTo2ByteHex10_16_4(@galss_id1,@galss_ids1);
--                 call intTo2ByteHex10_16_4(@galss_id2,@galss_ids2);
--                 call intTo2ByteHex10_16_4(@rk,@rks);
--                 set dates=CONCAT("00020000",@rks,"000200000000",@rks,"000000000000",@galss_ids1,@galss_id2);
--                 call message(dates,'000a',@date);
--                 set messagedate=@date;
--             end if;
--         elseif @count1>0 then
--                 set dates=CONCAT("000300000003","0003000000000003");
--                 call message(dates,'000a',@date);
--                 set messagedate=@date;
--         else
--             select 库内数 into @kuneishu from processcard1 where 工程号=@engineering_id limit 1;
--             select @work_groups;
--             select count(*) into @counts from gmms_horizontal where state='空闲' and gourp=2;
--             if a=0 then
--                 if @kuneishu>0 or @counts<=1 then
--                 #出片
--                 SET @processcardid=null;
--                 set @rkid=null;
--                 set @rk=null;
--                 set @galss_id=null;
--                 select `value` into @lastid from gmms_var where varname='last_out_glass_id'and groups=@work_groups;
--                 select `value` into @lastpos from gmms_var where varname='last_pos'and groups=@work_groups;
--                 if @lastid is not null then
--                     select @lastid;
--                     SELECT a.id,a.slicecage_rank,a.type_id,a.count,galss_id into @rkid,@rk,@type_id,@count,@galss_id from gmms_horizontal a INNER JOIN gmms_galss_task b on a.id=b.slicecage_rank where a.state='使用中' and a.count>0 and a.type_id=@lastid and a.flag=0 and engineering_id=@engineering_id and a.gourp=2 and b.stop_position>0 order by a.count desc, ABS(a.slicecage_rank-@lastpos) asc LIMIT 1;
--                     if @rk is not null then
--                     select @rk;
--                         UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
--                             UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
--                             UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
--                             UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
--                             call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
--                             call intTo2ByteHex10_16_4(@rk,@rks);
--                             set dates=CONCAT("0001",@galss_ids,"0000",@rks);
--                             call message(dates,'000d',@date);
--                             set messagedate=@date;
--                             set @发送字=1;
--                     end if;
--                 end if;
--                 if @发送字=0 then
--                     SELECT 流程卡 into @processcardid from processcard_ex1 where 下片位置 is not null and 库内数>0 and 总数-切割数=0 and 工程号=@engineering_id order by  总数-下架数  asc LIMIT 1;
--                     IF @processcardid is  null then
--                         select 2;
--                             #  后使用  未完全切完的
--                             SELECT 流程卡 into @processcardid from processcard_ex1 where 下片位置 is not null and 库内数>0 and 工程号=@engineering_id order by 总数-下架数  asc LIMIT 1;    
--                     end if;
--                     -- 看看空架 有没有 ,如果有  就找一个库能玻璃最多的下架
--                     IF @processcardid is null then 
-- 
--                         SET @drop_pos=null;
--                         SELECT id into @drop_pos from gmms_drop_frame where state='空架' and groups=@work_groups limit 1;
--                         if @drop_pos  is not null then 
--                             select name1 into @name1 from namess where groups=@work_groups;
--                             SELECT 流程卡,架号,总数,工程号 into @processcardid,@drop_frame,@processcard_count,@engineering_ids from processcard_ex1 where  (库内数>=@name1 or (库内数>0 and 总数<@name1)) order by  库内数 DESC LIMIT 1;
--                             #  流程卡占架子
--                             if @processcardid is not null then 
--                                 UPDATE gmms_drop_frame set state='使用中',drop_frame=@drop_frame,processcard_id=@processcardid,processcard_count=@processcard_count,engineering_id=@engineering_ids where id=@drop_pos;
--                                 UPDATE gmms_galss_task set stop_position=@drop_pos where processcard_id=@processcardid and engineering_id=@engineering_id;                
--                             end if;            
--                         end if;
--                     end if;
--                     if @processcardid is not null then 
--                             SELECT @processcardid;    
--                             #  选定大小和槽
--                             SELECT  a.id,a.slicecage_rank,a.count,a.type_id,galss_id into @rkid,@rk,@count,@type_id,@galss_id from gmms_horizontal a inner join gmms_galss_task b on a.type_id=b.type_id where a.processcard_id=@processcardid and a.state='使用中' and a.gourp=2 and a.flag=0 and engineering_id=@engineering_id order by b.width*b.height desc ,a.count DESC  limit 1;
--                             select @count;
--                             UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
--                             UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
--                             UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
--                             UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
--                             call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
--                             call intTo2ByteHex10_16_4(@rk,@rks);
--                             set dates=CONCAT("0001",@galss_ids,"0000",@rks);
--                             call message(dates,'000d',@date);
--                             set messagedate=@date;
--                             set a=1;
--                         end if;
--                     
--                 end if;
-- --                             SELECT  a.id,a.slicecage_rank,a.count,a.type_id,galss_id into @rkid,@rk,@count,@type_id,@galss_id from gmms_horizontal a inner join gmms_galss_task b on a.id=b.slicecage_rank where  a.state='使用中' and a.gourp=2 and a.flag=0 and engineering_id=@engineering_id order by b.width*b.height desc ,a.count DESC  limit 1;
-- --                             select @count;
-- --                             UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
-- --                             UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
-- --                             UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
-- --                             UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
-- --                             call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
-- --                             call intTo2ByteHex10_16_4(@rk,@rks);
-- --                             set dates=CONCAT("0001",@galss_ids,"0000",@rks);
-- --                             call message(dates,'000d',@date);
-- --                             set messagedate=@date;
-- --                             set a=1;
--                 end if;
--             end if;
--             
--             if a=0 then
--                 #进片
--                 select rank,type_id,galss_id,processcard_id,width,height,slicecage_rank into @rankid,@type_id,@galss_id,@processcardid,@width,@height,@rk from gmms_galss_task where work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id order by rank limit 1;
--                 UPDATE gmms_galss_task set slicecage_rank=@rk,work_procedure='理片',work_state='进库中' WHERE rank=@rankid and engineering_id=@engineering_id;
--                 UPDATE gmms_horizontal set state='进库中',count=1,type_id=@type_id,processcard_id=@processcardid where slicecage_rank=@rk and gourp=1;
--                 call intTo2ByteHex10_16_4(@rankid,@rankids);
--                 call intTo2ByteHex10_16_4(@rk,@rks);
--                 set dates=CONCAT("0001",@rankids,@rks);
--                 call message(dates,'000a',@date);
--                 set messagedate=@date;
--             end if;
--                 
--     
--         end if;
--         
--     #出片
--     elseif flag=2 then
--                 SET @processcardid=null;
--                 set @rkid=null;
--                 set @rk=null;
--                 set @galss_id=null;
--                 select `value` into @lastid from gmms_var where varname='last_out_glass_id'and groups=@work_groups;
--                 select `value` into @lastpos from gmms_var where varname='last_pos'and groups=@work_groups;
--                 if @lastid is not null then
--                     select @lastid;
--                     SELECT a.id,a.slicecage_rank,a.type_id,a.count,galss_id into @rkid,@rk,@type_id,@count,@galss_id from gmms_horizontal a INNER JOIN gmms_galss_task b on a.id=b.slicecage_rank where a.state='使用中' and a.count>0 and a.type_id=@lastid and a.flag=0 and engineering_id=@engineering_id and a.gourp=2 and b.stop_position>0 order by a.count desc, ABS(a.slicecage_rank-@lastpos) asc LIMIT 1;
--                     if @rk is not null then
--                     select @rk;
--                         UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
--                             UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
--                             UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
--                             UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
--                             call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
--                             call intTo2ByteHex10_16_4(@rk,@rks);
--                             set dates=CONCAT("0001",@galss_ids,"0000",@rks);
--                             call message(dates,'000d',@date);
--                             set messagedate=@date;
--                             set @发送字=1;
--                     end if;
--                 end if;
--                 if @发送字=0 then
--                     SELECT 流程卡 into @processcardid from processcard_ex1 where 下片位置 is not null and 库内数>0 and 总数-切割数=0 and 工程号=@engineering_id order by  总数-下架数  asc LIMIT 1;
--                     IF @processcardid is  null then
--                         select 2;
--                             #  后使用  未完全切完的
--                             SELECT 流程卡 into @processcardid from processcard_ex1 where 下片位置 is not null and 库内数>0 and 工程号=@engineering_id order by 总数-下架数  asc LIMIT 1;    
--                     end if;
--                     -- 看看空架 有没有 ,如果有  就找一个库能玻璃最多的下架
--                     IF @processcardid is null then 
-- 
--                         SET @drop_pos=null;
--                         SELECT id into @drop_pos from gmms_drop_frame where state='空架' and groups=@work_groups limit 1;
--                         if @drop_pos  is not null then 
--                             select name1 into @name1 from namess where groups=@work_groups;
--                             SELECT 流程卡,架号,总数,工程号 into @processcardid,@drop_frame,@processcard_count,@engineering_ids from processcard_ex1 where  (库内数>=@name1 or (库内数>0 and 总数<@name1)) order by  库内数 DESC LIMIT 1;
--                             #  流程卡占架子
--                             if @processcardid is not null then 
--                                 UPDATE gmms_drop_frame set state='使用中',drop_frame=@drop_frame,processcard_id=@processcardid,processcard_count=@processcard_count,engineering_id=@engineering_ids where id=@drop_pos;
--                                 UPDATE gmms_galss_task set stop_position=@drop_pos where processcard_id=@processcardid and engineering_id=@engineering_id;                
--                             end if;            
--                         end if;
--                     end if;
--                     if @processcardid is not null then 
--                             SELECT @processcardid;    
--                             #  选定大小和槽
--                             SELECT  a.id,a.slicecage_rank,a.count,a.type_id,galss_id into @rkid,@rk,@count,@type_id,@galss_id from gmms_horizontal a inner join gmms_galss_task b on a.type_id=b.type_id where a.processcard_id=@processcardid and a.state='使用中' and a.gourp=2 and a.flag=0 and engineering_id=@engineering_id order by b.width*b.height desc ,a.count DESC  limit 1;
--                             select @count;
--                             UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
--                             UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
--                             UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
--                             UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
--                             call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
--                             call intTo2ByteHex10_16_4(@rk,@rks);
--                             set dates=CONCAT("0001",@galss_ids,"0000",@rks);
--                             call message(dates,'000d',@date);
--                             set messagedate=@date;
--                         end if;
--                     
--                 end if;
-- --                         SELECT  a.id,a.slicecage_rank,a.count,a.type_id,galss_id into @rkid,@rk,@count,@type_id,@galss_id from gmms_horizontal a inner join gmms_galss_task b on a.id=b.slicecage_rank where  a.state='使用中' and a.gourp=2 and a.flag=0 and engineering_id=@engineering_id order by b.width*b.height desc ,a.count DESC  limit 1;
-- --                             select @count;
-- --                             UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rkid and engineering_id=@engineering_id;
-- --                             UPDATE gmms_horizontal SET state='出库中' where slicecage_rank=@rk and gourp=2;
-- --                             UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
-- --                             UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
-- --                             call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
-- --                             call intTo2ByteHex10_16_4(@rk,@rks);
-- --                             set dates=CONCAT("0001",@galss_ids,"0000",@rks);
-- --                             call message(dates,'000d',@date);
-- --                             set messagedate=@date;
--                 
--     #进片
--     elseif flag=1 then
--         select rank,type_id,galss_id,processcard_id,width,height,slicecage_rank into @rankid,@type_id,@galss_id,@processcardid,@width,@height,@rk from gmms_galss_task where work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id order by rank limit 1;
--         UPDATE gmms_galss_task set slicecage_rank=@rk,work_procedure='理片',work_state='进库中' WHERE rank=@rankid and engineering_id=@engineering_id;
--         UPDATE gmms_horizontal set state='进库中',count=1,type_id=@type_id,processcard_id=@processcardid where slicecage_rank=@rk and gourp=1;
--         call intTo2ByteHex10_16_4(@rankid,@rankids);
--         call intTo2ByteHex10_16_4(@rk,@rks);
--         set dates=CONCAT("0001",@rankids,@rks);
--         call message(dates,'000a',@date);
--         set messagedate=@date;
--     
--     end if;
    set @conts=CONCAT(IFNULL(@conts,','),IFNULL(messagedate,','));
    set @end_time_=SYSDATE();
    insert into A_LengLipian(create_time,end_time,content) values (@create_time_,@end_time_,@conts);
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for Horizontal_copy1
-- ----------------------------
DROP PROCEDURE IF EXISTS `Horizontal_copy1`;
delimiter ;;
CREATE PROCEDURE `Horizontal_copy1`(in sendMessageHex varchar(255),in machineids BIGINT,out messagedate varchar(255),out msg varchar(255))
BEGIN
    #理片笼存储过程
    #找到当前机器标志位
    #查询机器逻辑表中对应的逻辑进行对应的步骤
    DECLARE machinedisposeids int DEFAULT 0;
    DECLARE dates varchar(255);
    DECLARE findplc1 varchar(255);
    DECLARE findmes1 varchar(255);
    DECLARE taskplc1 varchar(255);
    DECLARE taskmes1 varchar(255);
    DECLARE findplc2 varchar(255);
    DECLARE findmes2 varchar(255);
    DECLARE taskplc2 varchar(255);
    DECLARE taskmes2 varchar(255);
    DECLARE messagedates varchar(255) DEFAULT '';
    DECLARE IsExistChu varchar(255);
    #2023/11/13   查看理片时间
    set @create_time1_=null;
    set @end_time1_=null;
    set @create_time1_=SYSDATE();
    
    
    
    set messagedate=messagedates;
    set @log_task="";
        SET msg:='Slicecage  查配置';    
    select machine_type_id,remarks into @mtid,@remarks from gmms_machine where id=machineids;
    
 
    
    select mf.flag into @进完成标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='进完成字';
    select mf.flag into @出完成标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='出完成字';
    
    select mf.flag into @进请求标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='进请求字';
    select mf.flag into @出请求标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='出请求字';
    
    select mf.flag into @进发送标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='进发送字';
    select mf.flag into @出发送标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='出发送字';
    
    select mf.flag into @进完成确认标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='进完成确认字';
    select mf.flag into @出完成确认标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='出完成确认字';
    
    set findplc1 = substring(sendMessageHex,(cast(@进完成标志位 as UNSIGNED INTEGER)*4)+19,4);
    set taskplc1 = substring(sendMessageHex,(cast(@进请求标志位 as UNSIGNED INTEGER)*4)+19,4);
    set taskmes1 = substring(sendMessageHex,(cast(@进发送标志位 as UNSIGNED INTEGER)*4)+19,4);
    set findmes1 = substring(sendMessageHex,(cast(@进完成确认标志位 as UNSIGNED INTEGER)*4)+19,4);
    
    set findplc2 = substring(sendMessageHex,(cast(@出完成标志位 as UNSIGNED INTEGER)*4)+19,4);
    set taskplc2 = substring(sendMessageHex,(cast(@出请求标志位 as UNSIGNED INTEGER)*4)+19,4);
    set taskmes2 = substring(sendMessageHex,(cast(@出发送标志位 as UNSIGNED INTEGER)*4)+19,4);
    set findmes2 = substring(sendMessageHex,(cast(@出完成确认标志位 as UNSIGNED INTEGER)*4)+19,4);
    -- 修改
    set IsExistChu = substring(sendMessageHex,(8*4)+19,4);  
    
--     select taskplc1;
--     select taskmes1;
--     select findplc1;
--     select findmes1;
--     
--     select taskplc2;
--     select taskmes2;
--     select findplc2;
--     select findmes2;
--     
 
    
    #完成逻辑查询
    select count(*),md.id into @进完成数量,@进完成逻辑编号 from gmms_machine_dispose md join gmms_machine_type mt on md.machine_type_id=mt.id where md.machine_type_id=@mtid  and md.plc_font_type='进完成字' and md.mes_font_type='进完成确认字' and md.plc_font_value=findplc1 and md.mes_font_value=findmes1;
    
    select count(*),md.id into @出完成数量,@出完成逻辑编号 from gmms_machine_dispose md join gmms_machine_type mt on md.machine_type_id=mt.id where md.machine_type_id=@mtid  and md.plc_font_type='出完成字' and md.mes_font_type='出完成确认字' and md.plc_font_value=findplc2 and md.mes_font_value=findmes2;
    
    #请求逻辑查询
    select count(*),md.id into @进请求数量,@进请求逻辑编号 from gmms_machine_dispose md join gmms_machine_type mt on md.machine_type_id=mt.id where md.machine_type_id=@mtid  and md.plc_font_type='进请求字' and md.mes_font_type='进发送字' and md.plc_font_value=taskplc1 and md.mes_font_value=taskmes1;
    
    select count(*),md.id into @出请求数量,@出请求逻辑编号 from gmms_machine_dispose md join gmms_machine_type mt on md.machine_type_id=mt.id where md.machine_type_id=@mtid  and md.plc_font_type='出请求字' and md.mes_font_type='出发送字' and md.plc_font_value=taskplc2 and md.mes_font_value=taskmes2;
    
    
    #判断逻辑是否存在
    if @进完成数量=1 or @出完成数量=1 or @进请求数量=1 or @出请求数量=1 then
    
        #判断完成逻辑是否为空
        if @进完成逻辑编号!=0 then
            set machinedisposeids=@进完成逻辑编号;
            
        elseif @出完成逻辑编号!=0 then
            set machinedisposeids=@出完成逻辑编号;
            
        #判断请求逻辑是否为空
        elseif @进请求逻辑编号!=0 then
            set machinedisposeids=@进请求逻辑编号;
            
        elseif @出请求逻辑编号!=0 then
            set machinedisposeids=@出请求逻辑编号;
            
        end if;
        select machinedisposeids;
        #查询当前执行逻辑进行判断
        select logic,return_value into @ExecutionLogic,@returnvalue from gmms_machine_dispose where id=machinedisposeids;
        select @ExecutionLogic;
        if taskmes2="0001" then
                set dates=CONCAT("0000","00000000000000000000000000000000");
                call message(dates,'000d',@date);
                set messagedate=@date;
        elseif @ExecutionLogic='进片完成' then
                call HorizontalFinsh(machineids,machinedisposeids,2,@messagedate);
                set messagedate=@messagedate;        
        elseif @ExecutionLogic='出片完成' then
                call HorizontalFinsh(machineids,machinedisposeids,1,@messagedate);
                set messagedate=@messagedate;
        elseif @ExecutionLogic='进片完成破损1' then
                call HorizontalFinsh(machineids,machinedisposeids,3,@messagedate);
                set messagedate=@messagedate;
        elseif @ExecutionLogic='进片完成破损2' then
                call HorizontalFinsh(machineids,machinedisposeids,4,@messagedate);
                set messagedate=@messagedate;
        elseif @ExecutionLogic='进片完成破损3' then
                call HorizontalFinsh(machineids,machinedisposeids,5,@messagedate);
                set messagedate=@messagedate;
         elseif @ExecutionLogic='出片完成破损1' then
                call HorizontalFinsh(machineids,machinedisposeids,6,@messagedate);
                set messagedate=@messagedate;
        elseif @ExecutionLogic='出片完成破损2' then
                call HorizontalFinsh(machineids,machinedisposeids,7,@messagedate);
                set messagedate=@messagedate;
        elseif @ExecutionLogic='出片完成破损3' then
                call HorizontalFinsh(machineids,machinedisposeids,8,@messagedate);
                set messagedate=@messagedate;
        elseif @ExecutionLogic='进完成清空' then
                call message(@returnvalue,'0016',@date);
                set messagedate=@date;
         elseif @ExecutionLogic='出完成清空' then
                call message(@returnvalue,'0018',@date);
                set messagedate=@date;
        elseif taskplc1='0001' and taskplc2='0001' then        
                call HorizontalSend(machineids,0001,3,@messagedate);
                set messagedate=@messagedate;
        elseif @ExecutionLogic='进片请求' then
                 call HorizontalSend(machineids,@returnvalue,1,@messagedate);
                set messagedate=@messagedate;
        elseif @ExecutionLogic='出片请求' then        
                 call HorizontalSend(machineids,@returnvalue,2,@messagedate);
                set messagedate=@messagedate;
        elseif @ExecutionLogic='出任务清空' then
                set dates=CONCAT(@returnvalue,"00000000000000000000000000000000");
                call message(dates,'000d',@date);
                set messagedate=@date;
         elseif @ExecutionLogic='进任务清空' then
                set dates=CONCAT(@returnvalue,"00000000");
                call message(dates,'000a',@date);
                set messagedate=@date;
        end if;
    end if;
    set @end_time1_=SYSDATE();
    insert into A_LengLipian_copy1(create_time,end_time,content) values (@create_time1_,@end_time1_,messagedate);
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for Identify
-- ----------------------------
DROP PROCEDURE IF EXISTS `Identify`;
delimiter ;;
CREATE PROCEDURE `Identify`(in sendMessageHex varchar(255),in machineids BIGINT,out messagedate varchar(255))
BEGIN
    #测量台存储过程
    #找到当前机器标志位
    #查询机器逻辑表中对应的逻辑进行对应的步骤
    DECLARE machinedisposeids int DEFAULT 0;
    DECLARE dates varchar(255);
    DECLARE findplc varchar(255);
    DECLARE findmes varchar(255);
    DECLARE taskplc varchar(255);
    DECLARE taskmes varchar(255);
    DECLARE plcflag varchar(255);
    DECLARE mesflag varchar(255);
    DECLARE messagedates varchar(255) DEFAULT '';
    set messagedate=messagedates;
    set @log_task="";
    #此处修改,新版是没有gmms_machine表  为兼容当前,旧的代码依然可用,但是设备id 和gmms_machine已经没关系了强制给类型测量 
    #select machine_type_id into @mtid from gmms_machine where id=machineids;
    set @mtid=4;   
    
    
    select mf.flag into @完成标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='完成字';
    
    select mf.flag into @请求标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='请求字';
    
    select mf.flag into @发送标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='发送字';
    
    select mf.flag into @完成确认标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='完成确认字';
    
    set findplc = substring(sendMessageHex,(cast(@完成标志位 as UNSIGNED INTEGER)*4)+19,4);
    set taskplc = substring(sendMessageHex,(cast(@请求标志位 as UNSIGNED INTEGER)*4)+19,4);
    set taskmes = substring(sendMessageHex,(cast(@发送标志位 as UNSIGNED INTEGER)*4)+19,4);
    set findmes = substring(sendMessageHex,(cast(@完成确认标志位 as UNSIGNED INTEGER)*4)+19,4);
    
    set plcflag = substring(sendMessageHex,(cast(2 as UNSIGNED INTEGER)*4)+19,4);
    set mesflag = substring(sendMessageHex,(cast(23 as UNSIGNED INTEGER)*4)+19,4);
    
    select taskplc;
    select taskmes;
    select findplc;
    select findmes;
    
    #完成逻辑查询
    select count(*),md.id into @完成数量,@完成逻辑编号 from gmms_machine_dispose md join gmms_machine_type mt on md.machine_type_id=mt.id where md.machine_type_id=@mtid  and md.plc_font_type='完成字' and md.mes_font_type='完成确认字' and md.plc_font_value=findplc and md.mes_font_value=findmes;
    
    select *  from gmms_machine_dispose md join gmms_machine_type mt on md.machine_type_id=mt.id where md.machine_type_id=@mtid  and md.plc_font_type='完成字' and md.mes_font_type='完成确认字' and md.plc_font_value=findplc and md.mes_font_value=findmes;
    select machine_type_id,work_id,remarks into @mtid,@work_groups,@remarks from gmms_machine where id=machineids;
    select minwidths into @minwidth2 from gmms_preprocessing_glass where groups=@work_groups;
    select file_name into @engineering_id from gmms_raw_file where operator=@work_groups and state='已领取';
    select id into @patternid from gmms_pattern_task where groups=@work_groups and flag=0 order by rank limit 0,1;
    select count(*) into @counts from gmms_galss_task where work_state='待识别' and work_procedure='测量' and width>@minwidth2 and height>@minwidth2 and pattern_id=@patternid and engineering_id=@engineering_id;
    select @counts;
    if @counts=0 then
        update gmms_pattern_task set flag=1 where id=@patternid and groups=@work_groups;
    end if;
 
 
--     if plcflag='0000' and mesflag='0001' then
--             call message('0000','0017',@date);
--             set messagedate=@date;
--     elseif plcflag='0001' and mesflag='0000' then    
--             select id into @pattern_id from gmms_pattern_task where flag=0 order by rank limit 1;
--             update gmms_galss_task set work_procedure_number=100 where pattern_id=@pattern_id;
--             update gmms_pattern_task set flag=1 where id=@pattern_id;
--             call message('0001','0017',@date);
--             set messagedate=@date;
--     #判断逻辑是否存在
--     else
    if @完成数量=1 then
    
        #判断完成逻辑是否为空
            set machinedisposeids=@完成逻辑编号;
            
            
        
        #查询当前执行逻辑进行判断
        select logic,return_value into @ExecutionLogic,@returnvalue from gmms_machine_dispose where id=machinedisposeids;
        select @returnvalue;
        call log_key_value(@log_task, "@ExecutionLogic", @ExecutionLogic);
 
        if @ExecutionLogic='任务完成' then
                call IdentifyFinsh(sendMessageHex,machineids,@returnvalue,@messagedate);
                call log_key_value(@log_task, "@messagedate", @messagedate);
                set messagedate=@messagedate;
      elseif @ExecutionLogic='完成清空' then
                set dates=CONCAT(@returnvalue,'00000000000000000000');
                 call message(dates,'0014',@date);
                 set messagedate=@date;
        elseif @ExecutionLogic='失败清空' then
                 set dates=CONCAT(@returnvalue,'00000000000000000000');
                 call message(dates,'0014',@date);
                 set messagedate=@date;
--         elseif @ExecutionLogic='任务请求' then
--                 call LoadSend(machineids,@messagedate);
--                 set messagedate=@messagedate;
--          elseif @ExecutionLogic='任务清空' then
--                 set dates=CONCAT(@returnvalue,"0000000000000000");
--                 call message(dates,'0014',@date);
--                 set messagedate=@date;
        end if;
    end if;
    
            set @log_nm=concat("测量",machineids);
    set @exist_nm=null;
    
    select `var_value`,var_name into @var_value,@exist_nm from memory_var_table where var_name=@log_nm;
         if @exist_nm is null then 
            insert into memory_var_table (var_name,var_value,update_time) values (@log_nm,@log_task,now());
            else
                update memory_var_table set var_value=@log_task,update_time=now() where var_name=@log_nm;
         end if;
    
    
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for IdentifyFinsh
-- ----------------------------
DROP PROCEDURE IF EXISTS `IdentifyFinsh`;
delimiter ;;
CREATE PROCEDURE `IdentifyFinsh`(in sendMessageHex varchar(255),in machineids BIGINT,in returnvalue varchar(255),out messagedate varchar(255))
BEGIN
    #测量自动匹配存储过程
    #根据发送过来的数据进行转换,并算出宽高的误差最大值跟最小值
    #根据误差值查询最为匹配的第一条数据进行修改,并判断为直通或者是存笼然后发送匹配成功
    #@flag=0为自动匹配,@flag>0为绑定了数据进行手动匹配,@flag<0为匹配失败拿走
    #发送数据:序号,模式
    DECLARE findplc varchar(255);
    DECLARE findmes varchar(255);
    DECLARE widths varchar(255);
    DECLARE heigths varchar(255);
    DECLARE falgs varchar(255);
    DECLARE liuchengkas varchar(255);
    DECLARE maxwidth double;
    DECLARE minwidth double;
    DECLARE maxheigth double;
    DECLARE minheigth double;
    DECLARE maxwidth1 double;
    DECLARE minwidth1 double;
    DECLARE maxheigth1 double;
    DECLARE minheigth1 double;
    DECLARE match_error int default 0;
    DECLARE dates varchar(255);
    DECLARE s int DEFAULT 0;
    DECLARE x int DEFAULT 0;
    DECLARE counts int DEFAULT 0;
    DECLARE galssid BIGINT DEFAULT 0;
    DECLARE plcgalssid BIGINT DEFAULT 0;
    DECLARE messagedates varchar(255) DEFAULT '';
    DECLARE isFinsh_ varchar(255) DEFAULT null;
    set messagedate=messagedates;
    
    select machine_type_id,work_id,remarks into @mtid,@work_groups,@remarks from gmms_machine where id=machineids;
    
    if machineids=4 or machineids=23 or machineids=31 then
 
    select file_name into @engineering_id from gmms_raw_file where operator=@work_groups and state='已领取' limit 0,1;
    select @engineering_id;
    select widtherror,heigtherror into @widtherror,@heigtherror from gmms_identify_error where groups=@work_groups;
    select minwidths into @minwidth2 from gmms_preprocessing_glass where groups=@work_groups;
    
        
 
    set widths = substring(sendMessageHex,(cast(6 as UNSIGNED INTEGER)*4)+19,4);
    set heigths = substring(sendMessageHex,(cast(7 as UNSIGNED INTEGER)*4)+19,4);
    
    
    set widths=conv(widths,16,10)/10;
    set heigths=conv(heigths,16,10)/10;
    
    select widths;
    select heigths;
    
    set minwidth=widths-@widtherror;
    set maxwidth=widths+@widtherror;
    set minheigth=heigths-@heigtherror;
    set maxheigth=heigths+@heigtherror;
    
    select maxwidth;
    select maxheigth;
    
    select flag,marking into @flag,@marking from gmms_preprocessing_glass where groups=@work_groups limit 0,1;
    select @flag;
 
    set @patternid=null;
    set @counts=0;
    set @counts2=0;
    
    select id into @patternid from gmms_pattern_task where groups=@work_groups and flag=0 order by rank limit 0,1;
    select @patternid;
    call log_key_value(@log_task, "@patternid",  @patternid);
    if @patternid is not null then
    
        select count(*) into @counts from (select width,height,thickness,color from gmms_galss_task where work_procedure='测量' and work_state='待识别' and pattern_id=@patternid and engineering_id=@engineering_id and work_procedure_number=100 and width>@minwidth2 and height>@minwidth2 and (((width<=maxwidth and width>=minwidth) and (height<=maxheigth and height>=minheigth))or((width<=maxheigth and width>=minheigth) and (height<=maxwidth and height>=minwidth))) group by width,height,thickness,color) as rowss;
    
        select count(*) into @counts2 from (select width,height,thickness,color from gmms_galss_task where work_procedure='测量' and work_state='待识别' and pattern_id=@patternid and engineering_id=@engineering_id and work_procedure_number=100 and width>@minwidth2 and height>@minwidth2 and ((width<=maxwidth and width>=minwidth) and (height<=maxheigth and height>=minheigth)) group by width,height,thickness,color) as rowss;
        
    else
    
        select count(*) into @counts from (select width,height,thickness,color from gmms_galss_task where work_procedure='测量' and work_state='待识别' and engineering_id=@engineering_id and work_procedure_number=100  and (((width<=maxwidth and width>=minwidth) and (height<=maxheigth and height>=minheigth))or((width<=maxheigth and width>=minheigth) and (height<=maxwidth and height>=minwidth))) group by width,height,thickness,color) as rowss;
    
        select count(*) into @counts2 from (select width,height,thickness,color from gmms_galss_task where work_procedure='测量' and work_state='待识别' and engineering_id=@engineering_id and work_procedure_number=100 and ((width<=maxwidth and width>=minwidth) and (height<=maxheigth and height>=minheigth)) group by width,height,thickness,color) as rowss;
 
    end if;
    call log_key_value(@log_task, "@flag",  @flag);
    #自动匹配
    select @counts,@counts2;
    if @flag=0 then
    
        if @counts=1 then 
        if @counts2=1 then
        
            if machineids=31 then
                set @id=null;
                select processcard_id into liuchengkas from gmms_drop_frame where groups=1  limit 0,1;
                
                if liuchengkas is not null and 1>2 then
                    select id,width,height,marking_flag into @id,@width,@height,@marking_flag from gmms_galss_task 
                    where work_procedure='测量' and work_state='待识别' and processcard_id=liuchengkas and engineering_id=@engineering_id and work_procedure_number=100 
                    and (((width<=maxwidth and width>=minwidth) and (height<=maxheigth and height>=minheigth))or((width<=maxheigth and width>=minheigth) and (height<=maxwidth and height>=minwidth))) 
                    limit 0,1;
                    
                    if @id is null then
                        select id,width,height,marking_flag into @id,@width,@height,@marking_flag from gmms_galss_task 
                        where work_procedure='测量' and work_state='待识别' and engineering_id=@engineering_id and work_procedure_number=100 
                        and (((width<=maxwidth and width>=minwidth) and (height<=maxheigth and height>=minheigth))or((width<=maxheigth and width>=minheigth) and (height<=maxwidth and height>=minwidth))) 
                        ORDER BY pattern_id ASC limit 0,1;
                    end if;
                
                else
                
                    select id,width,height,marking_flag into @id,@width,@height,@marking_flag from gmms_galss_task as gt
          where work_procedure='测量' and work_state='待识别' and engineering_id=@engineering_id and work_procedure_number=100 
          and (((width<=maxwidth and width>=minwidth) and (height<=maxheigth and height>=minheigth))or((width<=maxheigth and width>=minheigth) and (height<=maxwidth and height>=minwidth)))            
          ORDER BY (select count(*) from gmms_galss_task as gt2 where gt2.work_procedure='测量' and gt2.work_state='待识别' and gt2.engineering_id=@engineering_id and gt2.work_procedure_number=100 and gt2.processcard_id=gt.processcard_id) ASC limit 0,1;
 
                end if;                                                
            else            
                select id,width,height,marking_flag into @id,@width,@height,@marking_flag from gmms_galss_task 
                where work_procedure='测量' and work_state='待识别' and engineering_id=@engineering_id and work_procedure_number=100 
                and (((width<=maxwidth and width>=minwidth) and (height<=maxheigth and height>=minheigth))or((width<=maxheigth and width>=minheigth) and (height<=maxwidth and height>=minwidth))) 
                ORDER BY pattern_id ASC limit 0,1;                        
            end if;
            select @id;
            
            call log_key_value(@log_task, "@id",  @id);
                ###
            #此处修改,添加一个更新动作标识的程序
            if @id is not null and @id<>0 then    
                if machineids=4 then 
                    if @marking_flag<10 then 
                        set @z_line=1;
                        if machineids=4 then 
                       set @z_line=3;
                        end if;
                        if machineids=23 then 
                        set @z_line=2;
                        end if; 
                    call dongzuo_get_number_copy1(@id,@z_line, @marking_flag);
                    update gmms_galss_task set marking_flag=@marking_flag where id=@id and engineering_id=@engineering_id;
                end if;
            end if;
            ###
            
            
            
            if @width>=2500 or @height>=2000 then
                set falgs='0002';
            else 
                set falgs='0001';
            end if;
                
                select max(rank) into @maxrank from gmms_galss_task where engineering_id=@engineering_id limit 0,1;
                select @id;
                update gmms_galss_task set work_state='等待中',rank=@maxrank+1,work_procedure='理片',work_procedure_number=200 where id=@id and engineering_id=@engineering_id;
                select @maxrank;
                select gt.galss_id,gt.width,gt.height,gt.thickness,pt.color into @glassid,@widths,@heights,@thicknesss,@colors from gmms_galss_task gt join gmms_pattern_task pt on gt.pattern_id=pt.id where gt.id=@id and engineering_id=@engineering_id limit 0,1;
                select @glassid;
                
                update gmms_preprocessing_glass set glass_id=@glassid,actual_length=widths,actual_width=heigths,length=@widths,width=@heights,statu='匹配成功',color=@colors,thickness=@thicknesss,flag=0 where groups=@work_groups;
                
                insert gmms_identify_error_details(galssid,width,heigth,error_width,error_heigth,groups,times,flag) values(@glassid,@width,@height,widths,heigths,@work_groups,NOW(),1);
                
            
 
            select rank,type_id,processcard_id,stop_position,drop_frame,engineering_id,galss_id into @rank,@type_id,@processcard_id,@stop_position,@drop_frame,@engineering_id,@galss_id from gmms_galss_task where id=@id and engineering_id=@engineering_id limit 0,1;
            
            if machineids=4 then
                if falgs='0001' then
                    call intTo2ByteHex10_16_4(@rank,@ranks);
                #    call intTo2ByteHex10_16_4(@marking_flag,@marking_flags);
                    
                #    set @marking=1;
                    
                    if @marking=1 then
                       select da_biao_mo_ban into @marking_flag from gmms_dongzuo_table where number=@marking_flag limit 0,1;
                     call intTo2ByteHex10_16_4(@marking_flag,@marking_flags);
                        set dates=CONCAT('0001',@ranks,falgs,'0000',@marking_flags);
                    elseif @marking=0 then
                        set dates=CONCAT('0001',@ranks,falgs);
                    end if;
                    call message(dates,'0014',@date);
                    set messagedate=@date;
                end if;
                
            elseif machineids=23 then
                if falgs='0001' then
                    call intTo2ByteHex10_16_4(@rank,@ranks);
                    set dates=CONCAT('0001',@ranks,falgs);
                    call message(dates,'0014',@date);
                    set messagedate=@date;
                end if;
            else 
                call log_key_value(@log_task, "@width",  @width);
                if @width>=2400 or @height>=2400 then
                    set falgs='0002';
                else 
                    set falgs='0001';
                end if;
            
                call log_key_value(@log_task, "@flags",  falgs);
                if falgs='0001' then
                    set @slicecage_rank=null;
                    select slicecage_rank into @ransk from gmms_galss_task where work_state='等待中' and work_procedure='理片' and engineering_id=@engineering_id order by rank limit 1;
                    if @ransk is not null or @ransk<>0 then
                    
                        
                        select slicecage_rank into @slicecage_rank from gmms_horizontal  where ((gourp=1 and state='空闲' ) or (gourp=2 and state='使用中' and type_id=@type_id and processcard_id=@processcard_id)) and flag=0 and slicecage_rank <>3 and slicecage_rank<>@ransk group by slicecage_rank having count(*)=2 order by id  limit 1;
 
                        if @slicecage_rank is  null then
                            select slicecage_rank into @slicecage_rank from gmms_horizontal  where ((gourp=1 and state='空闲' ) or (gourp=2 and state='空闲')) and flag=0 and slicecage_rank<>3 and slicecage_rank<>@ransk group by slicecage_rank having count(*)=2 order by id  limit 1;
                        end if;
                        if @slicecage_rank is not null then        
                            update gmms_galss_task set slicecage_rank=@slicecage_rank where id=@id and engineering_id=@engineering_id;
                        else
                        select 1;
                            update gmms_galss_task set work_state='待识别',work_procedure='测量',work_procedure_number=100,rank=0,broken_state=2 where id=@id and engineering_id=@engineering_id;
                        end if;
                        
                        
                    else
                        select slicecage_rank into @slicecage_rank from gmms_horizontal  where ((gourp=1 and state='空闲' ) or (gourp=2 and state='使用中' and type_id=@type_id and processcard_id=@processcard_id)) and flag=0 and slicecage_rank <>3 group by slicecage_rank having count(*)=2 order by id  limit 1;
                        
                        if @slicecage_rank is  null then
                            select slicecage_rank into @slicecage_rank from gmms_horizontal  where ((gourp=1 and state='空闲' ) or (gourp=2 and state='空闲')) and flag=0 and slicecage_rank <>3 group by slicecage_rank having count(*)=2 order by id  limit 1;
                        end if;
                        if @slicecage_rank is not null then        
                            update gmms_galss_task set slicecage_rank=@slicecage_rank where id=@id and engineering_id=@engineering_id;
                        else
                        select 1;
                            update gmms_galss_task set work_state='待识别',work_procedure='测量',work_procedure_number=100,slicecage_rank=null,rank=0,broken_state=2 where id=@id and engineering_id=@engineering_id;
                        end if;
                    end if;
                    
                    
                    select @slicecage_rank;
                    if @slicecage_rank is not null and @slicecage_rank<>0 then    
                        call intTo2ByteHex10_16_4(@rank,@ranks);
                        call intTo2ByteHex10_16_4(@slicecage_rank,@slicecage_ranks);
                        set dates=CONCAT('0001',@ranks,falgs,@slicecage_ranks);
                        call message(dates,'0014',@date);
                        insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
                        values (machineids,@work_groups,NOW(),'测量台发送',@slicecage_rank,@date);
                        set messagedate=@date;
                    end if;
                    
                else
--                   call log_key_value(@log_task, "@stop_position",  @stop_position);
                    #一线直通
                    if @stop_position > 0 then
                        update gmms_galss_task set work_state='直通' where id=@id and engineering_id=@engineering_id;
                        call intTo2ByteHex10_16_4(@rank,@ranks);
                        call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
                        set dates=CONCAT('0001',@galss_ids,falgs,'0003');
                        call message(dates,'0014',@date);
                        set messagedate=@date;    
                    else
 
                        select id into @drop_pos from gmms_drop_frame where state='空架' and groups=@work_groups and (stops=1 or stops=2) limit 1;
                        if @drop_pos is not null then
                            select 总数 into @processcard_count from processcard_ex1 where 流程卡=@processcard_id and `工程号`=@engineering_id;
                            UPDATE gmms_drop_frame set state='使用中',drop_frame=@drop_frame,processcard_id=@processcard_id,processcard_count=@processcard_count,engineering_id=@engineering_id where id=@drop_pos;
                            UPDATE gmms_galss_task set stop_position=@drop_pos where processcard_id=@processcard_id and engineering_id=@engineering_id;    
                            update gmms_galss_task set work_state='直通' where id=@id and engineering_id=@engineering_id;
                            call intTo2ByteHex10_16_4(@rank,@ranks);
                            call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
                            set dates=CONCAT('0001',@galss_ids,falgs,'0003');
                            call message(dates,'0014',@date);
                            set messagedate=@date;
                        else
                            update gmms_galss_task set work_state='待识别',work_procedure='测量',work_procedure_number=100,rank=0 where id=@id and engineering_id=@engineering_id;
                        end if;
                    end if;
                    
                end if;
            end if;
            end if;
        else
            update gmms_preprocessing_glass set statu='匹配失败1',actual_length=widths,actual_width=heigths,glass_id=null where groups=@work_groups;
            set  match_error=1;
            set messagedate=messagedates;
        end if;
        elseif @counts>1  then
            update gmms_preprocessing_glass set statu='多数据匹配',actual_length=widths,actual_width=heigths,glass_id=null where groups=@work_groups;
            set messagedate=messagedates;
        elseif  @counts=0 then
            update gmms_preprocessing_glass set statu='匹配失败',actual_length=widths,actual_width=heigths,glass_id=null where groups=@work_groups;
            set messagedate=messagedates;
            set  match_error=1;
        end if;
    
    #手动匹配,判断是否绑定玻璃信息
    elseif @flag>0 then        
        call Identifymanual(machineids,returnvalue,@messagedate);
        set messagedate=@messagedate;
    #人工拿走
    elseif @flag<0 then
        update gmms_preprocessing_glass set flag=0 where groups=@work_groups;
        set dates=CONCAT('00020000');
        call message(dates,'0014',@date);
        set messagedate=@date;
    end if;
    
    
    
    
elseif machineids=50 then
 
    select widtherror,heigtherror into @widtherror,@heigtherror from gmms_identify_error where groups=@work_groups;
    
    set widths = substring(sendMessageHex,(cast(6 as UNSIGNED INTEGER)*4)+19,4);
    set heigths = substring(sendMessageHex,(cast(7 as UNSIGNED INTEGER)*4)+19,4);
    set plcgalssid = conv(substring(sendMessageHex,(cast(5 as UNSIGNED INTEGER)*4)+19,4),16,10);
 
    set widths=conv(widths,16,10)/10;
    set heigths=conv(heigths,16,10)/10;
    #set plcgalssid=conv(plcgalssid,16,10);
    set minwidth=widths-@widtherror;
    set maxwidth=widths+@widtherror;
    set minheigth=heigths-@heigtherror;
    set maxheigth=heigths+@heigtherror;
    
--     set minwidth1=widths-2;
--     set maxwidth1=widths+2;
--     set minheigth1=heigths-2;
--     set maxheigth1=heigths+2;
    
    set @taskid=null;
    set @flag1=null;
    select flag,marking into @flag1,@marking from gmms_preprocessing_glass where groups=@work_groups;
    #找到有任务的第一个工位,流程卡 默认B  A
    select lk.liuchengka into @processcardid from gmms_drop_frame_5 as dr5 
    left join gmms_shelf_rack_2 as sr on dr5.rank=sr.id
    left join gmms_liuchengka as lk on sr.processcard_id=lk.liuchengka
    where groups_=3 and drop_groups=1 and dr5.sign=3 and sr.id is not null and lk.liuchengka is not null and 
    lk.current_status='正在工作' and lk.current_work_position='理片' limit 0,1;
    
    select @processcardid;
    select id,galss_id,edg_width,edg_height,thickness,color,stop_rank 
    into @taskid,@glassid,@widths,@heights,@thicknesss,@colors,@stop_rank from gmms_galss_task_shelf 
    where work_procedure='理片笼上片' and work_state='已完成' and processcard_id=@processcardid
    order by stop_rank desc limit 0,1;
    select @widths,@heights;
    
    select galss_id into isFinsh_ from gmms_galss_task_shelf 
    where work_procedure='理片' and galss_id=plcgalssid and processcard_id=@processcardid
    order by stop_rank desc limit 0,1;
  
    select isFinsh_,@flag1,widths,heigths,plcgalssid,minwidth,@taskid,@widtherror,@heigtherror,sendMessageHex;
    #自动匹配
    select  @flag1;
    if isFinsh_ is not null and @flag1=0 then
        set falgs='0001';
    call intTo2ByteHex10_16_4(isFinsh_,@ranks);
        set dates=CONCAT('0001',@ranks,falgs);
        call message(dates,'0014',@date);
        set messagedate=@date;
    elseif @flag1=0 and @widths is not null  then
        if (((@widths<=maxwidth and @widths>=minwidth) and (@heights<=maxheigth and @heights>=minheigth))
         or ((@widths<=maxheigth and @widths>=minheigth) and (@heights<=maxwidth and @heights>=minwidth)))  then 
            set falgs='0001';    
            update gmms_preprocessing_glass 
            set glass_id=@glassid,actual_length=widths,actual_width=heigths,length=@widths,width=@heights,statu='匹配成功',
            color=IFNULL(@colors,''),thickness=IFNULL(@thicknesss,0),flag=0 where groups=@work_groups;    
            update gmms_galss_task_shelf set work_state='等待中',work_procedure='理片' 
            where id=@taskid and processcard_id=@processcardid;    
            
            call intTo2ByteHex10_16_4(@glassid,@ranks);
            set dates=CONCAT('0001',@ranks,falgs);
            call message(dates,'0014',@date);
            set messagedate=@date;
        else
            update gmms_preprocessing_glass set flag=1,statu='匹配失败',actual_length=widths,actual_width=heigths,glass_id=IFNULL(@glassid,0),length=IFNULL(@widths,0),width=IFNULL(@heights,0) where groups=@work_groups;
            set messagedate=messagedates;
            set match_error=1;            
        end if;
    elseif @flag1=3 then
        
        set falgs='0001';    
        update gmms_preprocessing_glass 
        set glass_id=@glassid,actual_length=widths,actual_width=heigths,length=@widths,width=@heights,statu='匹配成功',
        color=IFNULL(@colors,''),thickness=IFNULL(@thicknesss,0),flag=0 where groups=@work_groups;    
        update gmms_galss_task_shelf set work_state='等待中',work_procedure='理片' 
        where id=@taskid and processcard_id=@processcardid;    
        call intTo2ByteHex10_16_4(@glassid,@ranks);
        set dates=CONCAT('0001',@ranks,falgs);
        call message(dates,'0014',@date);
        set messagedate=@date;
        
    elseif @flag1<0 then
        update gmms_preprocessing_glass set flag=0 where groups=@work_groups;
        set dates=CONCAT('00020000');
        call message(dates,'0014',@date);
        set messagedate=@date;
    end if;
end if;
    select match_error;
    
    if match_error=1 then 
         select int_value into match_error from gmms_globel_var where var_name='冷测量' and line=@work_groups;
         if match_error=0 then 
--             set dates=CONCAT('00030000');
--             call message(dates,'0014',@date);
--             set messagedate=@date;
            update gmms_globel_var set int_value=1 where var_name='冷测量' and line=@work_groups;
        end if;                
        set match_error=1;
  else 
    if messagedate is not null and messagedate<>"" then 
                    update gmms_globel_var set int_value=0 where var_name='冷测量' and line=@work_groups;
        end if;
    end if ;
    
        
--     select slicecage_rank into @slicecage_rank from gmms_horizontal  where ((gourp=1 and state='空闲' ) or (gourp=2 and state='空闲')) and flag=0 and slicecage_rank <>3 group by slicecage_rank having count(*)=2 order by id  limit 1;
-- 
--                     if @slicecage_rank is  null then
--                         select slicecage_rank into @slicecage_rank from gmms_horizontal where state="空闲" and flag=0 and slicecage_rank!=3  and gourp=1  order by id  limit 1;
--                     end if;
--                 end if;
--     
    
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for Identifymanual
-- ----------------------------
DROP PROCEDURE IF EXISTS `Identifymanual`;
delimiter ;;
CREATE PROCEDURE `Identifymanual`(in machineids BIGINT,in returnvalue varchar(255),out messagedate varchar(255))
BEGIN
    #测量台手动匹配存储过程
    #找到测量匹配表在界面绑定的数据进行修改
    DECLARE dates varchar(255);
    DECLARE falgs varchar(255);
    DECLARE messagedates varchar(255) DEFAULT '';
    set messagedate=messagedates;
    
    select machine_type_id,work_id,remarks into @mtid,@work_groups,@remarks from gmms_machine where id=machineids;
    
    if machineids=4 or machineids=23 or machineids=31 then
    
    select file_name into @engineering_id from gmms_raw_file where operator=@work_groups and state='已领取' limit 0,1;
    
    select flag,marking into @flag,@marking from gmms_preprocessing_glass where groups=@work_groups;
    select @flag;
    
    if @flag>0 then
       SELECT width,height into @z_width,@z_height from gmms_galss_task where id=@flag and engineering_id=@engineering_id;
    
    
        select width,height,galss_id into @width,@heigth,@galss_id from gmms_galss_task where id=@flag and engineering_id=@engineering_id;
        select actual_width,actual_length into @actual_width,@actual_length from gmms_preprocessing_glass  where groups=@work_groups;
        select @width;
        select @heigth;
        if @width>=35000 or    @heigth>=35000 then
            set falgs='0002';
        else
            set falgs='0001';
        end if;
        
        select max(rank) into @maxrank from gmms_galss_task where engineering_id=@engineering_id;
 
        update gmms_galss_task set work_state='等待中',work_procedure='理片',rank=@maxrank+1,work_procedure_number=200 where id=@flag and engineering_id=@engineering_id;
        
        update gmms_preprocessing_glass set statu='匹配成功',glass_id=@galss_id,length=@width,width=@heigth,flag=0 where groups=@work_groups;
        
        insert gmms_identify_error_details(galssid,width,heigth,error_width,error_heigth,groups,times,flag) values(@galss_id,@width,@heigth,@actual_length,@actual_width,@work_groups,NOW(),2);
 
        
        select rank,type_id,processcard_id,stop_position,drop_frame,engineering_id,galss_id into @rank,@type_id,@processcard_id,@stop_position,@drop_frame,@engineering_id,@galss_id from gmms_galss_task where id=@flag and engineering_id=@engineering_id limit 0,1;
        
        select @rank;
        
        
        
        if machineids =31 then
                if @width>=2500 or @height>=2500 then
                set falgs='0002';
            else 
                set falgs='0001';
            end if;
                if falgs='0001' then
                    select slicecage_rank into @ransk from gmms_galss_task where work_state='等待中' and work_procedure='理片' and engineering_id=@engineering_id order by rank limit 1;
                    if @ransk is not null or @ransk<>0 then
                    
                        
                        select slicecage_rank into @slicecage_rank from gmms_horizontal  where ((gourp=1 and state='空闲' ) or (gourp=2 and state='使用中' and type_id=@type_id and processcard_id=@processcard_id)) and flag=0 and slicecage_rank <>3 and slicecage_rank<>@ransk group by slicecage_rank having count(*)=2 order by id  limit 1;
 
                        if @slicecage_rank is  null then
                            select slicecage_rank into @slicecage_rank from gmms_horizontal  where ((gourp=1 and state='空闲' ) or (gourp=2 and state='空闲')) and flag=0 and slicecage_rank<>3 and slicecage_rank<>@ransk group by slicecage_rank having count(*)=2 order by id  limit 1;
                        end if;
                        if @slicecage_rank is not null then        
                            update gmms_galss_task set slicecage_rank=@slicecage_rank where id=@flag and engineering_id=@engineering_id;
                        else
                            update gmms_galss_task set work_state='待识别',work_procedure='测量',work_procedure_number=100,rank=0,broken_state=2 where id=@flag and engineering_id=@engineering_id;
                        end if;
                        
                    else
                    
                        
                        select slicecage_rank into @slicecage_rank from gmms_horizontal  where ((gourp=1 and state='空闲' ) or (gourp=2 and state='使用中' and type_id=@type_id and processcard_id=@processcard_id)) and flag=0 and slicecage_rank <>3 group by slicecage_rank having count(*)=2 order by id  limit 1;
                        
                        if @slicecage_rank is  null then
                            select slicecage_rank into @slicecage_rank from gmms_horizontal  where ((gourp=1 and state='空闲' ) or (gourp=2 and state='空闲')) and flag=0 and slicecage_rank <>3 group by slicecage_rank having count(*)=2 order by id  limit 1;
                        end if;
                        if @slicecage_rank is not null then        
                            update gmms_galss_task set slicecage_rank=@slicecage_rank where id=@flag and engineering_id=@engineering_id;
                        else
                            update gmms_galss_task set work_state='待识别',work_procedure='测量',work_procedure_number=100,rank=0,broken_state=2 where id=@flag and engineering_id=@engineering_id;
                        end if;
                    end if;
                    
                    
                    if @slicecage_rank is not null and @slicecage_rank<>0 then    
                        call intTo2ByteHex10_16_4(@rank,@ranks);
                        call intTo2ByteHex10_16_4(@slicecage_rank,@slicecage_ranks);
                        set dates=CONCAT('0001',@ranks,falgs,@slicecage_ranks);
                        call message(dates,'0014',@date);
                        set messagedate=@date;
                    end if;
                else
                
                    if @stop_position > 0 then
                        update gmms_galss_task set work_state='直通' where id=@flag and engineering_id=@engineering_id;
                        call intTo2ByteHex10_16_4(@rank,@ranks);
                        call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
                        set dates=CONCAT('0001',@galss_ids,falgs,'0003');
                        call message(dates,'0014',@date);
                        set messagedate=@date;    
                    else
                        select id into @drop_pos from gmms_drop_frame where state='空架' and groups=@work_groups limit 1;
                        if @drop_pos is not null then
                            select 总数 into @processcard_count from processcard_ex1 where 流程卡=@processcard_id and `工程号`=@engineering_id;
                            UPDATE gmms_drop_frame set state='使用中',drop_frame=@drop_frame,processcard_id=@processcard_id,processcard_count=@processcard_count,engineering_id=@engineering_id where id=@drop_pos;
                            UPDATE gmms_galss_task set stop_position=@drop_pos where processcard_id=@processcard_id and engineering_id=@engineering_id;    
                            update gmms_galss_task set work_state='直通' where id=@flag and engineering_id=@engineering_id;
                            call intTo2ByteHex10_16_4(@rank,@ranks);
                            call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
                            set dates=CONCAT('0001',@galss_ids,falgs,'0003');
                            call message(dates,'0014',@date);
                            set messagedate=@date;
                        else
                            update gmms_galss_task set work_state='待识别',work_procedure='测量',work_procedure_number=100,rank=0 where id=@id and engineering_id=@engineering_id;
                        end if;
                    end if;
                    end if;
        elseif machineids =4 then
                call intTo2ByteHex10_16_4(@rank,@ranks);
                set @z_mak=0;
                
                select marking_flag into @marking_flag from gmms_galss_task where id=@flag;
                
            select da_biao_mo_ban into @z_mak from gmms_dongzuo_table where number=@marking_flag LIMIT 1;
        
                
                call intTo2ByteHex10_16_4(@z_mak,@marking_flags);
                select @marking_flags;
                if @marking=1 then
                    set dates=CONCAT('0001',@ranks,falgs,'0000',@marking_flags);
                elseif @marking=0 then
                    set dates=CONCAT('0001',@ranks,falgs);
                end if;
                call message(dates,'0014',@date);
                set messagedate=@date;
        else
                call intTo2ByteHex10_16_4(@rank,@ranks);
                set dates=CONCAT('0001',@ranks,falgs);
                call message(dates,'0014',@date);
                set messagedate=@date;
        end if;
        end if;
        
        
    elseif machineids=50 then
    
    
    select flag into @flag from gmms_preprocessing_glass where groups=@work_groups;
    select @flag;
    
    if @flag>0 then
 
        select edg_width,edg_height,galss_id into @width,@heigth,@galss_id from gmms_galss_task_slicecage where id=@flag and processcard_id=@remarks;
        select @width;
        select @heigth;
 
        set falgs='0001';
 
        
        select max(rank) into @maxrank from gmms_galss_task_slicecage where processcard_id=@remarks;
            
        update gmms_galss_task_slicecage set work_state='等待中',work_procedure='理片',rank=@maxrank+1,work_procedure_number=900 where id=@flag and processcard_id=@remarks;
        
            update gmms_preprocessing_glass set statu='匹配成功',glass_id=@galss_id,length=@width,width=@heigth,flag=0 where groups=@work_groups;
        
        select rank into @rank from gmms_galss_task_slicecage where id=@flag and processcard_id=@remarks;
        
        
        
        
    
                call intTo2ByteHex10_16_4(@rank,@ranks);
                set dates=CONCAT('0001',@ranks,falgs);
                call message(dates,'0014',@date);
                set messagedate=@date;
        
 
    end if;
        end if;
        
        
            if messagedate is not null and messagedate<>"" then 
                    update gmms_globel_var set int_value=0 where var_name='冷测量' and line=@work_groups;
        end if;
--     elseif     @flag=2 then
--         update gmms_preprocessing_glass set statu='匹配失败',flag=0 where id=1;
 
                
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for Identify_Mark_UpdateModel
-- ----------------------------
DROP PROCEDURE IF EXISTS `Identify_Mark_UpdateModel`;
delimiter ;;
CREATE PROCEDURE `Identify_Mark_UpdateModel`(in line int ,in model int,out backMsg varchar(255))
BEGIN
# 函数名:测量-打标-更改打标模式
# 设置某线正在生产的工程中的钢化小片不激光打标
# 逻辑:传入值:线号,模式,输出值:返回信息
# 1. 根据线号查询当前生产线正在生产的工程
# 2. 根据工程修改小片打标标识
DECLARE gch varchar(255);
select file_name into gch from gmms_raw_file where operator = line and state = '已领取' order by create_time Desc limit 1;
select gch;
if gch is null then 
set backMsg =CONCAT("当前 ",line, " 号生产线没有正在生产的工程");
end if;
#if @gongchenghao is not null then
if gch is not null then
    if model = 1 then
#set gch = @gongchenghao;
update gmms_galss_task set marking_flag = 15 where marking_flag in (11,12,13,14,17,18) and engineering_id = gch;
insert into gmms_identify_mark_update (gongchenghao,DBMark,GHMark,line) Values (gch,0,0,line);
set backMsg = CONCAT("已成功设置",line,"号产线正在生产的 ",gch," 工程中需要钢化的小片不自动打标!");
    end if;
    if model = 0 then
    insert into gmms_identify_mark_update (gongchenghao,DBMark,GHMark,line) Values (gch,1,0,line);
    set backMsg = "非钢化打标已关闭";
    end if;
    end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for Inclinedroller
-- ----------------------------
DROP PROCEDURE IF EXISTS `Inclinedroller`;
delimiter ;;
CREATE PROCEDURE `Inclinedroller`(in sendMessageHex varchar(255),in machineids BIGINT,out messagedate varchar(255))
BEGIN
    #斜滚轮存储过程
    #找到当前机器标志位
    #查询机器逻辑表中对应的逻辑进行对应的步骤
    #根据发送过来的玻璃编号查找数据进行修改状态
    DECLARE machinedisposeids int DEFAULT 0;
    DECLARE dates varchar(255);
    DECLARE typeid BIGINT;
    DECLARE taskplc varchar(255);
    DECLARE taskmes varchar(255);
    DECLARE idflag varchar(255);
    DECLARE oldmessagedates varchar(255) DEFAULT sendMessageHex;
    DECLARE messagedates varchar(255) DEFAULT '';
    set messagedate=messagedates;
    
    select machine_type_id,work_id into @mtid,@work_groups from gmms_machine where id=machineids;
    select file_name into @engineering_id from gmms_raw_file where operator=@work_groups and state='已领取';
    
    
    select mf.flag into @请求标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='请求字';
    
    select mf.flag into @发送标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='发送字';
    
    set idflag=cast(@请求标志位 as UNSIGNED INTEGER)+1;
    
    set taskplc = substring(sendMessageHex,(cast(@请求标志位 as UNSIGNED INTEGER)*4)+19,4);
    set taskmes = substring(sendMessageHex,(cast(@发送标志位 as UNSIGNED INTEGER)*4)+19,4);
    set typeid = conv(substring(sendMessageHex,(cast(idflag as UNSIGNED INTEGER)*4)+19,4),16,10);
    
  select taskplc;
  select taskmes;
    select speed1 into @speed1 from gmms_edg_speed where groups=@work_groups;
 
    
    #请求逻辑查询
    select count(*),md.id into @请求数量,@请求逻辑编号 from gmms_machine_dispose md join gmms_machine_type mt on md.machine_type_id=mt.id where md.machine_type_id=@mtid  and md.plc_font_type='请求字' and md.mes_font_type='发送字' and md.plc_font_value=taskplc and md.mes_font_value=taskmes;
 
 
        if @请求逻辑编号!=0 then
            set machinedisposeids=@请求逻辑编号;
        end if;
        
        #查询当前执行逻辑进行判断
        select logic,return_value into @ExecutionLogic,@returnvalue from gmms_machine_dispose where id=machinedisposeids;
        select @ExecutionLogic;
        if @ExecutionLogic='任务请求' then
        select typeid;
        if machineids=34 then
             select count(*) into @count from gmms_galss_task where galss_id=typeid and work_procedure='理片' and work_state='已出库' and engineering_id=@engineering_id;
                select count(*) into @counts from gmms_galss_task where galss_id=typeid and work_procedure='理片' and work_state='直通' and engineering_id=@engineering_id;
                select speed1 into @speed1 from gmms_edg_speed where groups=@work_groups;
                select @count;
                if @count>0 then
                    update gmms_galss_task set work_state='等待中',work_procedure='磨边' where galss_id=typeid and  work_procedure='理片' and work_state='已出库' and engineering_id=@engineering_id;
                    call intTo2ByteHex10_16_4(@speed1,@speed1s);
                    set dates=CONCAT(@returnvalue,@speed1s);
                    call message(dates,'000a',@messagedate);
                    set messagedate=@messagedate;
                    insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,1,NOW(),'允许信号',oldmessagedates,messagedate);
                elseif @counts>0 then
                    select max(out_rank) into @maxrank from gmms_galss_task where engineering_id=@engineering_id; 
                    update gmms_galss_task set work_state='等待中',work_procedure='磨边',out_rank=@maxrank+1 
                    where galss_id=typeid and  work_procedure='理片' and work_state='直通' and engineering_id=@engineering_id;
                    call intTo2ByteHex10_16_4(@speed1,@speed1s);
                    set dates=CONCAT(@returnvalue,@speed1s);
                    call message(dates,'000a',@messagedate);
                    set messagedate=@messagedate;
                    insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,1,NOW(),'直通允许信号',oldmessagedates,messagedate);
                end if;
        elseif machineids=26 then
            select count(*) into @count from gmms_galss_task where galss_id=typeid and work_procedure='理片' and work_state='已出库' and engineering_id=@engineering_id;
                
                select speed1 into @speed1 from gmms_edg_speed where groups=@work_groups;
                select @count;
 
                    update gmms_galss_task set work_state='等待中',work_procedure='磨边' where galss_id=typeid and  work_procedure='理片' and work_state='已出库' and engineering_id=@engineering_id;
                    select count(*) into @count2 from gmms_galss_task where galss_id= typeid and work_procedure='磨边' and work_state='正在工作' and engineering_id=@engineering_id;
                    select @count2;
                    if @count2=1 then
                        call intTo2ByteHex10_16_4(@speed1,@speed1s);
                        set dates=CONCAT(@returnvalue,@speed1s);
                        call message(dates,'000a',@messagedate);
                        set messagedate=@messagedate;
                    end if;
                    
 
        else
            select count(*) into @count from gmms_galss_task where galss_id=typeid and work_procedure='理片' and work_state='已出库' and engineering_id=@engineering_id;
                
                select speed1 into @speed1 from gmms_edg_speed where groups=@work_groups;
                select @count;
                if @count>0 then
                    update gmms_galss_task set work_state='等待中',work_procedure='磨边' where galss_id=typeid and  work_procedure='理片' and work_state='已出库' and engineering_id=@engineering_id;
                    call intTo2ByteHex10_16_4(@speed1,@speed1s);
                    set dates=CONCAT(@returnvalue,@speed1s);
                    call message(dates,'000a',@messagedate);
                    set messagedate=@messagedate;
                end if;
        end if;
                
                
         elseif @ExecutionLogic='任务清空' then        
                call message(@returnvalue,'000a',@messagedate);
                set messagedate=@messagedate;
                insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,1,NOW(),'清空信号',oldmessagedates,messagedate);
        else 
                call intTo2ByteHex10_16_4(@speed1,@speed1s);
                    set dates=@speed1s;
                    #set dates=CONCAT('0000',@speed1s);
                    call message(dates,'000b',@messagedate);
                    set messagedate=@messagedate;
                    #insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,1,NOW(),'发送速度信号',oldmessagedates,messagedate);
        end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for input
-- ----------------------------
DROP PROCEDURE IF EXISTS `input`;
delimiter ;;
CREATE PROCEDURE `input`(in machineids BIGINT,out 发送字 int,out 发送ID int,out 格子 int,out err char(255))
label:BEGIN
    #理片笼进片逻辑
    #先判断玻璃是否直通,然后找到空闲的架子把玻璃放入
    #超过1000的玻璃,一个架子只能放一块
    #找类型相同的玻璃并且还能再放一块的架子,如果没有则重新找一个架子放入
 
    #这是一个日志变量,用来跟踪运行情况     
   DECLARE task_id int ;
     call log_msg(@log_task,"[input]");    
     SET 发送字=0;
     select machine_type_id,work_id into @mtid,@work_groups from gmms_machine where id=machineids;    
     select @work_groups;    
     select file_name into @engineering_id from gmms_raw_file where operator=@work_groups and state='已领取';    
   select @engineering_id;
        -- 获取最后一次行为里片库的位置
   SET @lastpos=null;
     SELECT `value` into @lastpos from gmms_var where varname='last_pos' and groups=@work_groups;
     SELECT `value` into @lastpos2 from gmms_var where varname='last_out_glass_id' and groups=@work_groups;    
     SELECT @lastpos2;    
     -- 通过小片任务ID查询小片任务尺寸
     SET @type_id=null;
     select rank,type_id,galss_id,processcard_id,width,height,id into @rankid,@type_id,@galss_id,@processcardid,@width,@height,@z_gid from gmms_galss_task 
     where work_procedure='理片' and work_state='等待中'  and engineering_id=@engineering_id order by rank limit 0,1;    
     select @rankid;
      call log_key_value(@log_task,"玻璃ID",@z_gid);
 
   if @type_id is null  then
     set     发送字=-1;
     SET err='玻璃ID不存在';
--  else
--          if @width<@height then
--        set @width=@height;
--    end if;
     
   end if;
 
--  这里判断是否发生队列错乱,错乱一定要报警,防止乱片
--  if 发送字=0 then
--             SET @id=null;
--             SELECT id ,processcard_id into @id,@processcardid FROM gmms_galss_task where work_procedure='理片' and work_state='等待中' order by rank ASC limit 1;
--             if @id<>请求ID or @id is null then
--                 SET 发送字=-2;    
--                 SET err='玻璃队列不匹配';
--             end if; 
--  end if;
      --  判断是否因为和最后磨边玻璃同架同尺寸 ,给直通标记直通
     SET @zhitong=0;        --  需要直通出库的标志
--         select count(*) into @counts from gmms_drop_frame where processcard_id=@processcardid and engineering_id=@engineering_id;
--         if @type_id=@lastpos2 and @counts>0 then
--             SET @zhitong=1;    
--         end if;
        
        -- 直通出库
   if ((@width>3500 or @height>=3500) or @zhitong=1) and 发送字=0 and false then 
        
            call log_key_value(@log_task,"直通模式",1);
        
      SET 发送字=3;
      SET 发送ID=@galss_id;
      SET 格子=1;
            UPDATE gmms_galss_task SET work_procedure='理片',work_state='出库中' where rank=@rankid and engineering_id=@engineering_id;
            UPDATE gmms_var set value=格子 where varname='last_pos' and groups=@work_groups;
          update gmms_machine set remarks='3' where id=machineids;
   end if;
            
--      if(@width<1000 and @height<1000) and 发送字=0 and @work_groups<>1 and flase   then 
--           set @rk=0;
--             call log_key_value(@log_task,"入库模式","小片");
--       SELECT slicecage_rank into @rk from gmms_slicecage 
--             where  count=1 and flag=0 and type_id=@type_id  and processcard_id=@processcardid and gourp=@work_groups and state='使用中' and id<>1
--       order by id-@last_pos asc limit 1;
--             
--             call log_key_value(@log_task,"入库位置",@rk);    
--       
--             if @rk>0 then 
--                     UPDATE gmms_galss_task set slicecage_rank=@rk,work_procedure='理片',work_state='进库中' WHERE rank=@rankid and engineering_id=@engineering_id;
--                     UPDATE gmms_slicecage set state='进库中',count=2,type_id=@type_id,processcard_id=@processcardid where slicecage_rank=@rk and gourp=@work_groups;
--                     select @type_id;
--                     UPDATE gmms_var set value=@rk where varname='last_pos' and groups=@work_groups;
--                     select @type_id;
--                     SET 发送ID=@type_id;
--                     SET 格子=@rk;
--                     SET 发送字=1;        
--             end if;
--      end if;
        
   
   
     
     
     #if(@Width<1000 and @height<1000) and (@Width>10 or @height>10) and 发送字=0 then
         
     if (@Width<=10 and @height<=10) and 发送字=0 then 
            SET @rk=0;
            -- 这里查找一个可放两片的槽
      SELECT slicecage_rank into @rk from gmms_slicecage 
            where count=1 and type_id=@type_id  and processcard_id=@processcardid and gourp=@work_groups and state='使用中' and id<>1
      order by id-@last_pos asc limit 1;
            select @rk;
      if @rk>0 then
                    UPDATE gmms_galss_task set slicecage_rank=@rk,work_procedure='理片',work_state='进库中' WHERE rank=@rankid and work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id;
                    UPDATE gmms_slicecage set count=2 where slicecage_rank=@rk and gourp=@work_groups;
                    UPDATE gmms_var set value=@rk where varname='last_pos' and groups=@work_groups;
          SET 发送字=1;
          SET 发送ID=@type_id;
          SET 格子=@rk;    
            end if;
            if @rk=0 then 
                    SET @rk=0;
                    SELECT slicecage_rank into @rk from gmms_slicecage where state="空闲" and count=0 and flag=0 and gourp=@work_groups and slicecage_rank<>1
          order by ABS(slicecage_rank-@last_pos)  asc limit 1;
                     SELECT @rk;
                    if @rk >0 then
                            UPDATE gmms_galss_task set slicecage_rank=@rk,work_procedure='理片',work_state='进库中' WHERE rank=@rankid and work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id;
                            UPDATE gmms_slicecage set state='进库中',count=1,type_id=@type_id,processcard_id=@processcardid where slicecage_rank=@rk and gourp=@work_groups;
                            UPDATE gmms_var set value=@rk where varname='last_pos' and groups=@work_groups;     
                            SET 发送字=1;
                            SET 发送ID=@type_id;
                            SET 格子=@rk;
                    else 
                            SET 发送字=-3;
                            SET err='发生暴笼';
                    end if;
            end if;
    end if;
    
    
    
    IF (@Width<2500 and @height<2500) and (@Width>10 or @height>10) and 发送字=0 then
            SET @rk=0;
              call log_key_value(@log_task,"入库模式","大片");
            SELECT slicecage_rank into @rk from gmms_slicecage where state="空闲" and count=0 and flag=0 and gourp=@work_groups and slicecage_rank<>1
      order by ABS(slicecage_rank-@last_pos)  asc limit 1;
            call log_key_value(@log_task,"入库位置",@rk);
            if @rk >0 then
                    select @type_id;
                    UPDATE gmms_galss_task set slicecage_rank=@rk,work_procedure='理片',work_state='进库中' WHERE rank=@rankid and work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id;
                    UPDATE gmms_slicecage set state='进库中',count=1,type_id=@type_id,processcard_id=@processcardid where slicecage_rank=@rk and gourp=@work_groups;
                    select @type_id;
                    UPDATE gmms_var set value=@rk where varname='last_pos' and groups=@work_groups;
                    select @type_id;
                    SET 发送ID=@type_id;
                    SET 格子=@rk;
                    SET 发送字=1;
            else 
                    SET 发送字=-3;
                    SET err='发生暴笼';
            end if;
   end if;
    
    
    
    
    IF 发送字=0 then 
            SET 发送字=-4;
            SET err='无任何相应';
    --  此处发送
  end if;
    if 格子 is null or 发送ID is null  then
            
            set  格子=0;
            set  发送ID=0;
    end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for insert_tempere_layout
-- ----------------------------
DROP PROCEDURE IF EXISTS `insert_tempere_layout`;
delimiter ;;
CREATE PROCEDURE `insert_tempere_layout`(_work_id int,_layout_number int,_layout_rate double,_glass_number int,_x int,_y int,_rotate int,pendulum int,_distance int,_row int,_col int,_glass_id long,_head_info text,out result int)
BEGIN
    #Routine body goes here...
 
set @width=0;
SELECT width,height,galss_id into @width,@height,@erp_glass_id from gmms_galss_task_2 where id=_glass_id;
 
if @width<>0 then 
 
INSERT INTO `gmms_tempere_layout`(`work_id`, `layout_number`, `insert_time`, `layout_rate`, `glass_number`, `x`, `y`, `width`, `height`, `rotate`, `row`, `column`, `glass_id`, `erp_glass_id`, `head_info`) VALUES (_work_id,_layout_number,now(),_layout_rate,_glass_number,_x,_y,@width,@height,_rotate,_row,_col,_glass_id,@erp_glass_id,_head_info);
 
 
 
UPDATE gmms_galss_task_2  set orders=_glass_number,grouporder=_row, furnace=_layout_number,angle=_rotate,distance=_distance,
pendulum_piece=pendulum,work_state="已优化" where id=_glass_id;
set result=1;
end if;
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for interrupttask
-- ----------------------------
DROP PROCEDURE IF EXISTS `interrupttask`;
delimiter ;;
CREATE PROCEDURE `interrupttask`(in rawfilename varchar(255),in line BIGINT)
BEGIN
    #Routine body goes here...
 
    select id into @raw_id from gmms_raw_file where file_name=rawfilename and operator=line;
    select count(*) into @count1 from gmms_pattern_task_interrupt where raw_id=@raw_id and groups=line;
    select count(*) into @count2 from gmms_galss_task_interrupt where engineering_id=rawfilename;
    if @count1>0 or @count2>0 then
        delete from gmms_pattern_task_interrupt where raw_id=@raw_id;
        delete from gmms_galss_task_interrupt where engineering_id=rawfilename;
    end if;
    insert into gmms_pattern_task_interrupt select * from gmms_pattern_task where raw_id=@raw_id and groups=line;
    insert into gmms_galss_task_interrupt select * from gmms_galss_task where engineering_id=rawfilename;
    
    
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for intoutfinish
-- ----------------------------
DROP PROCEDURE IF EXISTS `intoutfinish`;
delimiter ;;
CREATE PROCEDURE `intoutfinish`(in machineids BIGINT,in 确认字 int,out 完成字 int ,out err char(255))
BEGIN
    #理片笼完成存储过程
    #先判断为出库还是进库,分别进行对应的数据修改
    #出库则先判断是两片还是一片
    select machine_type_id,work_id into @mtid,@work_groups from gmms_machine where id=machineids;
    
    select file_name into @engineering_id from gmms_raw_file where operator=@work_groups and state='已领取';
        set 完成字=0;
       SET @id=null;
         SET @slicecage_rank=null;
        SELECT type_id,id,slicecage_rank,work_state into @type_id,@id ,@slicecage_rank,@work_state from   gmms_galss_task where work_procedure='理片'  and (work_state='进库中'
         or work_state='出库中') and engineering_id=@engineering_id order by rank ASC
         limit 1;
         
        if @id is null then 
             SET  完成字=-1;    # 一个异常的确认
             SET  err='没有待确认的进片任务';
        end if; 
        
        
        --  判断确认ID 是否队列正确
    /*
        if @id<>确认ID and 完成字=0 then 
            SET  完成字=-1;
            SET  err='确认ID不匹配';
        end if;
        */
 
     -- SELECT @slicecage_rank;
        if 确认字=1 and 完成字=0 then
                if @work_state='出库中' then 
                --  获取队列编号 代码   
                select count(*) into @counts from gmms_galss_task where work_procedure='理片' and work_state='出库中' and engineering_id=@engineering_id;
                    if @counts=1 then
                        select max(out_rank) into @maxrank from gmms_galss_task where engineering_id=@engineering_id;
                       UPDATE gmms_galss_task SET work_state='已出库',finsh_time=now(),slicecage_rank=null,out_rank=@maxrank+1,work_procedure_number=300  where slicecage_rank=@slicecage_rank and work_state='出库中' and engineering_id=@engineering_id;    
                    else 
                        select galss_id into @galss_id1 from gmms_galss_task where work_procedure='理片' and work_state='出库中' and engineering_id=@engineering_id order by rank limit 0,1;
                        select galss_id into @galss_id2 from gmms_galss_task where work_procedure='理片' and work_state='出库中' and engineering_id=@engineering_id order by rank limit 1,1;
                        select max(out_rank) into @maxrank from gmms_galss_task where engineering_id=@engineering_id;
                       UPDATE gmms_galss_task SET work_state='已出库',finsh_time=now(),slicecage_rank=null,out_rank=@maxrank+1,work_procedure_number=300  where galss_id=@galss_id1 and work_state='出库中' and engineering_id=@engineering_id;
                        UPDATE gmms_galss_task SET work_state='已出库',finsh_time=now(),slicecage_rank=null,out_rank=@maxrank+2,work_procedure_number=300  where galss_id=@galss_id2 and work_state='出库中' and engineering_id=@engineering_id;
                    end if;    
                 else 
                         UPDATE gmms_galss_task SET work_state='已进库' where slicecage_rank=@slicecage_rank and work_state='进库中' and engineering_id=@engineering_id;   
                end if;
                
                
                
                
                SET 完成字=1;
        end if;
        
        #破损
        if 确认字=2 and 完成字=0 then
            if @work_state='出库中' then 
                --  获取队列编号 代码   
                select count(*) into @counts from gmms_galss_task where work_procedure='理片' and work_state='出库中' and engineering_id=@engineering_id;
                    if @counts=1 then
                        select max(out_rank) into @maxrank from gmms_galss_task where engineering_id=@engineering_id;
                       UPDATE gmms_galss_task SET work_state='已进库',finsh_time=now()where slicecage_rank=@slicecage_rank and work_state='出库中' and engineering_id=@engineering_id;    
                    else 
                        select galss_id into @galss_id1 from gmms_galss_task where work_procedure='理片' and work_state='出库中' and engineering_id=@engineering_id order by rank limit 0,1;
                        select galss_id into @galss_id2 from gmms_galss_task where work_procedure='理片' and work_state='出库中' and engineering_id=@engineering_id order by rank limit 1,1;
                        select max(out_rank) into @maxrank from gmms_galss_task where engineering_id=@engineering_id;
                       UPDATE gmms_galss_task SET work_state='已出库',finsh_time=now() where galss_id=@galss_id1 and work_state='出库中' and engineering_id=@engineering_id;
                        UPDATE gmms_galss_task SET work_state='已出库',finsh_time=now()  where galss_id=@galss_id2 and work_state='出库中' and engineering_id=@engineering_id;
                    end if;    
                 else 
                         UPDATE gmms_galss_task SET work_state='等待中',slicecage_rank=null where slicecage_rank=@slicecage_rank and work_state='进库中' and engineering_id=@engineering_id;   
                end if;
          SET 完成字=1;
        end if;
--         if 确认字=2 and 完成字=0 then
--              UPDATE gmms_galss_task SET work_state='破损',broken_state=1,slicecage_rank=null  where type_id=@type_id and (work_state='进库中' or work_state='出库中') and engineering_id=@engineering_id;
--           SET 完成字=1;
--         end if;
        
        select 完成字;
        if 完成字>0 and @slicecage_rank is not null then 
                SET @count=0;
                SELECT count(*) into @count from gmms_galss_task WHERE  slicecage_rank=@slicecage_rank and engineering_id=@engineering_id;
                if @count>0 then 
                    UPDATE gmms_slicecage SET state='使用中'  ,count=@count  where slicecage_rank=@slicecage_rank and gourp=@work_groups; 
                else
                  UPDATE gmms_slicecage SET state='空闲'  ,count=0,type_id=null,processcard_id=null where slicecage_rank=@slicecage_rank and gourp=@work_groups; 
                end if;
        end if;
        
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for intTo2ByteHex10_16_2
-- ----------------------------
DROP PROCEDURE IF EXISTS `intTo2ByteHex10_16_2`;
delimiter ;;
CREATE PROCEDURE `intTo2ByteHex10_16_2`(in number int,out date VARCHAR(255))
BEGIN
    #10转2位16进制存储过程
    DECLARE numbers VARCHAR(255);
    DECLARE number4 VARCHAR(255);
    
    
    set numbers=conv(number,10,16);
    if char_length(numbers)='1' then
        set number4=CONCAT('0',numbers);
    else
        set number4=numbers;
    end if;
    set date=number4;
    
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for intTo2ByteHex10_16_4
-- ----------------------------
DROP PROCEDURE IF EXISTS `intTo2ByteHex10_16_4`;
delimiter ;;
CREATE PROCEDURE `intTo2ByteHex10_16_4`(in number int,out date VARCHAR(255))
BEGIN
    #10转4位16进制存储过程
    DECLARE numbers VARCHAR(255);
    DECLARE number4 VARCHAR(255);
    
    
    set numbers=conv(number,10,16);
    if char_length(numbers)='1' then
        set number4=CONCAT('000',numbers);
    elseif char_length(numbers)='2' then
        set number4=CONCAT('00',numbers);
    elseif char_length(numbers)='3' then
        set number4=CONCAT('0',numbers);
    elseif char_length(numbers)='4' then
        set number4=numbers;
    end if;
    set date=number4;
    
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for intTo2ByteHex2_16
-- ----------------------------
DROP PROCEDURE IF EXISTS `intTo2ByteHex2_16`;
delimiter ;;
CREATE PROCEDURE `intTo2ByteHex2_16`(in number VARCHAR(255),out date VARCHAR(255))
BEGIN
    #2转16进制存储过程
    DECLARE numbers VARCHAR(255);
    DECLARE number4 VARCHAR(255);
    
    
    set numbers=conv(number,2,16);
    if char_length(numbers)='1' then
        set number4=CONCAT('0',numbers);
    else
        set number4=numbers;
    end if;
    set date=number4;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for liuchengka_change
-- ----------------------------
DROP PROCEDURE IF EXISTS `liuchengka_change`;
delimiter ;;
CREATE PROCEDURE `liuchengka_change`(oldwk varchar(50),oldst varchar(50),newwk varchar(50),
newst varchar(50), stops int,line int, segment int)
BEGIN
 
 
 
    if segment=1 then 
            if oldwk<>newwk then 
                     if oldwk is not null then 
                        call    liuchengka_change_inner(oldwk,"切磨线","下架");
                     end if;
                     if newwk is not null then
                        call   liuchengka_change_inner(newwk,"切磨线","上架");
                     end if;
                end if;
    end if;
    if segment=2 then 
            if oldwk<>newwk then 
                     if oldwk is not null then 
                        call    liuchengka_change_inner(oldwk,"钢化前","下架");
                     end if;
                     if newwk is not null then
                        call   liuchengka_change_inner(newwk,"钢化前","上架");
                     end if;
                end if;
    end if;
    
        if segment=3 then 
            if oldwk<>newwk then 
                     if oldwk is not null then 
                        call    liuchengka_change_inner(oldwk,"钢化后","下架");
                     end if;
                     if newwk is not null then
                        call   liuchengka_change_inner(newwk,"钢化后","上架");
                     end if;
                end if;
    end if;
    
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for liuchengka_change_inner
-- ----------------------------
DROP PROCEDURE IF EXISTS `liuchengka_change_inner`;
delimiter ;;
CREATE PROCEDURE `liuchengka_change_inner`(in _liuchengka varchar(50),in _current_work varchar(50),in _status varchar(50))
BEGIN
    #Routine body goes here...
    # 先检查参数是否是有效参数...
    
    #    先检查是否可以修改...   
    #UPDATE gmms_liuchengka set current_work_position=_current_work,current_status=_status,last_changed_time=now() where current_frame=_liuchengka;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for liuchengka_change_qiemo
-- ----------------------------
DROP PROCEDURE IF EXISTS `liuchengka_change_qiemo`;
delimiter ;;
CREATE PROCEDURE `liuchengka_change_qiemo`(oldwk varchar(50),oldst varchar(50),newwk varchar(50),
newst varchar(50), line int, segment int)
BEGIN
 
    set @seg=null;
    
    if segment=1 then 
            if oldwk<>newwk then 
                     if oldwk is not null then 
                        call    liuchengka_change_inner(oldwk,"切割线","已完成");
                     end if;
                     if newwk is not null then
                        call   liuchengka_change_inner(newwk,"切割线","已开始");
                     end if;
                end if;
    end if;
    if segment=2 then 
            if oldwk<>newwk then 
                     if newwk is not null then 
                        call    liuchengka_change_inner(newwk,"切割线","已开始");
                     end if;
                end if;
    end if;
    if segment=3 then 
        if oldwk<>newwk then 
                     if oldwk is not null then 
                        call    liuchengka_change_inner(oldwk,"切割线","已完成");
                     end if;
                end if;
    end if;
    
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for liuchengka_create
-- ----------------------------
DROP PROCEDURE IF EXISTS `liuchengka_create`;
delimiter ;;
CREATE PROCEDURE `liuchengka_create`(in gongcheng varchar(50))
BEGIN
    #Routine body goes here...
        set @count=0;
        select count(*) into @count from gmms_liuchengka where gongchenghao=gongcheng;
        if @count=0 then
            set @gc=gongcheng;
            set @tm=now();
            insert into gmms_liuchengka 
            (
 
liuchengka
,gongchenghao
,parent_liuchengka
,is_single
,child_count
,current_status
,current_work_position
,current_frame
,last_changed_time
,piece_count
 
            )
                select processcard_id,@gc,null,1,1,'已完成','创建',processcard_id,@tm,count(id)  from gmms_galss_task_buffer where engineering_id=gongcheng group by processcard_id;
        end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for liuchengka_create_v1
-- ----------------------------
DROP PROCEDURE IF EXISTS `liuchengka_create_v1`;
delimiter ;;
CREATE PROCEDURE `liuchengka_create_v1`(gongcheng varchar(50))
BEGIN
    #Routine body goes here...
    DECLARE done int default 0;
    DECLARE card varchar(50);
 
   DECLARE cur CURSOR FOR
             select processcard_id from  gmms_galss_task_buffer where engineering_id=gongcheng group by processcard_id;
    DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1;
 
    OPEN cur;
    while done=0 do
        FETCH cur into card;
        CALL liuchengka_load_rel(card);
    end while;
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for liuchengka_load_rel
-- ----------------------------
DROP PROCEDURE IF EXISTS `liuchengka_load_rel`;
delimiter ;;
CREATE PROCEDURE `liuchengka_load_rel`(ka varchar(50))
BEGIN
    #Routine body goes here...
DECLARE id  int DEFAULT null;
        DECLARE i  int DEFAULT  0;
        DECLARE hao VARCHAR(50) DEFAULT null;
        DECLARE gy  VARCHAR(50) DEFAULT null;
        DECLARE ct int DEFAULT 0;
        DECLARE ys  varchar(50) DEFAULT null;
        DECLARE tk   double DEFAULT null;
    
        DECLARE tmpc int;
        DECLARE has_j int;
        DECLARE has_k int;
        set has_j=false;
        set has_k=false;
        
        #这里把ka 的后缀去掉,变成流程卡,并查询是否已经导入过了
        set tmpc=instr(ka,'/');
        
        if tmpc>0 then 
            set ka=SUBSTR(ka from 1 for tmpc-1);
        end if;
        
            set tmpc=0;
            select count(*) into tmpc from gmms_liuchengka where main_liuchengka=ka;
    
        
        
        if tmpc=0 then
            select count(a.ceng) into tmpc  from 
            (SELECT ceng  FROM gmms_liuchengka_buffer where liuchengkahao=ka group by ceng) a;
            
           
            
            if tmpc>0 then 
                    set i=0;
                    while i<tmpc do
                   set i=i+1;
                            
                            SELECT gongyiliucheng,liuchengkahaoceng,shuliang,moxi,houdu into 
                             gy,hao,ct,ys,tk
                             from gmms_liuchengka_buffer where liuchengkahao=ka and ceng=i limit 1;
    
                    INSERT INTO `gmms`.`gmms_liuchengka`(`liuchengka`, `main_liuchengka`,`parent_liuchengka`,`is_single`,`child_count`,`current_status`, `current_work_position`, `current_frame`, `last_changed_time`, `piece_count`,
                    gy_gang,gy_jiajiao,gy_zhongkong
                    ) VALUES
                     (concat(ka,'/',i),ka, null,b'1', 1, '已完成', '创建',concat(ka,'/',i),null, ct,
                        case when INSTR(gy,"钢化")>0 then b'1' else b'0' end,
                        case when INSTR(gy,"夹层")>0 then b'1' else b'0' end,
                        case when INSTR(gy,"中空")>0 then b'1' else b'0' end
                     );
                     if has_j=0 and INSTR(gy,"夹层")>0 then 
                       set has_j=1;                 
                     end if;
                     IF has_k=0 and INSTR(gy,"中空")>0 then 
                     
                       set has_k=1;    
                     end if;
                    end while;                    
        
    
        if tmpc>1 then 
                
                
                
                
            if has_j=1 then 
                set i=1;
                
                
                
                
                INSERT INTO `gmms`.`gmms_liuchengka`(`liuchengka`, `main_liuchengka`,`parent_liuchengka`,`is_single`,`child_count`,`current_status`, `current_work_position`, `current_frame`, `last_changed_time`, `piece_count`,
                    gy_gang,gy_jiajiao,gy_zhongkong,gongyi
                    ) VALUES
                     (concat('J',ka),ka,null, b'0', 1, '已完成', '创建',null,null, ct,
                        0,
                        0,
                        has_k,
                        "夹层"
                     );
                update `gmms`.`gmms_liuchengka` set parent_liuchengka=concat('J',ka) where main_liuchengka=ka and gy_jiajiao=1;
                
                select count(*) into @z_ct from gmms_liuchengka where parent_liuchengka=    concat('J',ka);
                update gmms_liuchengka set child_count=@z_ct where liuchengka=    concat('J',ka);
                        
            end if;
            
            if has_k=1 then
               
                                    INSERT INTO `gmms`.`gmms_liuchengka`(`liuchengka`, `main_liuchengka`,`parent_liuchengka`,`is_single`,`child_count`,`current_status`, `current_work_position`, `current_frame`, `last_changed_time`, `piece_count`,
                    gy_gang,gy_jiajiao,gy_zhongkong,gongyi
                    ) VALUES
                     (concat('K',ka),ka,null, b'0', 1, '已完成', '创建',null,null, ct,
                        0,
                        0,
                        0,
                        '中空'
                     );
                
                     update `gmms`.`gmms_liuchengka` set parent_liuchengka=concat('K',ka) where main_liuchengka=ka and parent_liuchengka is null and liuchengka<> concat('K',ka);     
                    select count(*) into @z_ct from gmms_liuchengka where parent_liuchengka=    concat('K',ka);
                update gmms_liuchengka set child_count=@z_ct where liuchengka=    concat('K',ka);
        
            end if;
            
            
            
        end if;        
        
        end if;
    end if;
    
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for LoadFinsh
-- ----------------------------
DROP PROCEDURE IF EXISTS `LoadFinsh`;
delimiter ;;
CREATE PROCEDURE `LoadFinsh`(in machineids BIGINT,in machinedisposeids BIGINT,in flag int,out messagedate varchar(255))
BEGIN
    #上片完成存储过程
    #循环上片位找到有架子正在工作的任务进行修改,flag=3为破损,flag=1为完成
    #如果为最后一个任务则自动生成退库任务
    DECLARE s int DEFAULT 0;
    DECLARE dates varchar(255);
        DECLARE width double;
        DECLARE height double;
        DECLARE thickness double;
        DECLARE leftpieces int;
        DECLARE messagedates varchar(255) DEFAULT '';
    set messagedate=messagedates;
        
         select count(*),r.groups into @料架表数量,@groups from gmms_machine m join gmms_load_rack r on m.id=r.machine_id join gmms_shelf_task st on st.id=r.shelf_task_id where machine_id=machineids;
         select id,color,raw_id into @id,@color,@raw_id from gmms_pattern_task where work_state='正在工作' and groups=@groups limit 1;
         #修改此句   修改班組
         select banzu into @dengluname from gmms_user_current where gongyi='磨边' and chanxian=@groups limit 0,1;
         #select `name` into @dengluname from gmms_user_details where groups=@groups;
         
         select file_name into @file_name from gmms_raw_file where id=@raw_id;
         
         
         select return_value into @returnvalue from gmms_machine_dispose where id=machinedisposeids;
        select @料架表数量;
            #循环上片位
                select r.id,r.falg_shelf,r.number,r.shelf_task_id,r.state,st.groups,st.file_id,st.shelf_rack_id,r.id into @料架序号,@料架标志位,@料架编号,@任务编号,@料架状态,@groups,@file_id,@shelf_rack_id,@load_rack_id from gmms_machine m join gmms_load_rack r on m.id=r.machine_id join gmms_shelf_task st on st.id=r.shelf_task_id  where machine_id=machineids limit 1;
                
 
                
                select rp.id,rp.left_pieces,rp.raw_width,rp.raw_height,rp.raw_thickness,rp.color,rp.production_time,rp.batch_id,rp.create_time into @包号编号,@剩余数量,@raw_width,@raw_height,@raw_thickness,@color,@production_time,@batch_id,@create_time from gmms_load_rack r join gmms_shelf_task st on st.id=r.shelf_task_id join gmms_shelf_rack sr on sr.id=st.shelf_rack_id join gmms_raw_package rp on rp.id=sr.raw_package_id1 where machine_id=machineids  and r.id=@料架序号 limit 1;
                
                select @剩余数量;
                select @料架标志位;
                select @料架状态;
                #判断上片位是否有架子
                if @料架标志位="1" then
                
                #判断上片位是否正在工作
                    if @料架状态="正在工作" then
 
                            
                            #破损
                            if flag=3 then
                                update gmms_pattern_task set work_state='破损',finsh_time=NOW() where work_state='正在工作' and groups=@groups limit 1;
                                set leftpieces=@剩余数量-1;
                                update gmms_raw_package set left_pieces=leftpieces where id=@包号编号;
                            
                            #完成
                            elseif flag=1 then
                            select @任务编号;
                            set @zz_gid=null;
                            select id into @zz_gid from gmms_pattern_task where work_state='正在工作' and groups=@groups limit 1;
                            if @zz_gid is not null then
                            #添加余料
                             call yuliao_create_task(@zz_gid,@zz_tmp1,@zz_tmp2);  
                                
                            end if;
                            
                            
                                update gmms_pattern_task set work_state='已完成',finsh_time=NOW() where work_state='正在工作' and groups=@groups limit 1;
                                set leftpieces=@剩余数量-1;
                                update gmms_raw_package set left_pieces=leftpieces where id=@包号编号;
                                insert into gmms_cutmanage (width,height,thickness,color,pieces,groups,statrtime,engineering_id,production_time,batch_id,warehousing_time,dengluname) values(@raw_width,@raw_height,@raw_thickness,@color,1,@groups,now(),@file_name,@production_time,@batch_id,@create_time,@dengluname);
                                update gmms_galss_task set chamfer_size=@batch_id where pattern_id=@id;
                                
                            #未完成    
                            elseif flag=4 then
                            
                            
                            
                                update gmms_pattern_task set work_state='等待中',finsh_time=NOW() where work_state='正在工作' and groups=@groups limit 1;
                            end if;
--                             if @color='白玻' or @color='超白' then
--                                 if leftpieces=0 then                        
--                                 select max(task_id) into @maxtask_id from gmms_shelf_task;
--                                 update gmms_machine set work_state='暂停' where id=machineids;
--                                 select id into @id from gmms_load_rack where shelf_task_id=@shelf_rack_id;
--                                  insert into gmms_shelf_task set task_type='从上片位到仓位',task_state='等待中',groups=@groups,shelf_rack_id=@shelf_rack_id,start_time=Now(),task_id=(@maxtask_id+1);
--                                 end if;
--                             else
--                                 if leftpieces=1 then                        
--                                 select max(task_id) into @maxtask_id from gmms_shelf_task;
--                                 update gmms_machine set work_state='暂停' where id=machineids;
--                                 select id into @id from gmms_load_rack where shelf_task_id=@shelf_rack_id;
--                                  insert into gmms_shelf_task set task_type='从上片位到仓位',task_state='等待中',groups=@groups,shelf_rack_id=@shelf_rack_id,start_time=Now(),task_id=(@maxtask_id+1);
--                                 end if;
--                             end if;
                            
                            
                            select count(*) into @finshnum from gmms_pattern_task where groups=@groups and work_state='已完成';
                            select count(*) into @posunnum from gmms_pattern_task where groups=@groups and work_state='破损';
                            select @returnvalue;
                            call message(@returnvalue,'0014',@date);
                            set messagedate=@date;
                    end if;
                end if;
 
            
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for Loadpullshelf
-- ----------------------------
DROP PROCEDURE IF EXISTS `Loadpullshelf`;
delimiter ;;
CREATE PROCEDURE `Loadpullshelf`(in machineids BIGINT)
BEGIN
    #Routine body goes here...
    
        select groups into @groups from gmms_load_rack r where machine_id=machineids GROUP BY groups;
        
        select r.falg_shelf,r.number,r.shelf_task_id into @料架标志one,@料架编号one,@任务编号one from gmms_load_rack r where machine_id=machineids limit 0,1;
        
        
        select r.falg_shelf,r.number,r.shelf_task_id into @料架标志two,@料架编号two,@任务编号two from gmms_load_rack r where machine_id=machineids limit 1,1;
        
        select @料架标志one;
        select @料架标志two;
        select count(*) into @counts from gmms_pattern_task where work_state='等待中' and groups=@groups;
        if @counts >0 then
            if @料架标志one=0 then
                if @料架标志two=0 then
                    select raw_width,raw_height,raw_thickness,color into @raw_width,@raw_height,@raw_thickness,@color from gmms_pattern_task where groups=@groups and work_state='等待中' group by raw_width,raw_height,raw_thickness,color order by rank limit 0,1;
                                
                else
                    select rp.left_pieces,rp.raw_width,rp.raw_height,rp.raw_thickness,rp.color,sr.id,sr.color_falg into @剩余片数,@宽度,@高度,@厚度,@颜色,@shelf_rack_id,@膜系标志 from gmms_load_rack r join gmms_shelf_task s on r.shelf_task_id=s.id join gmms_shelf_rack sr on s.shelf_rack_id=sr.id join gmms_raw_package rp on sr.raw_package_id1=rp.id where r.number=@料架编号two;
                    select raw_width,raw_height,raw_thickness,color into @raw_width,@raw_height,@raw_thickness,@color from gmms_pattern_task where groups=@groups and work_state='等待中' and (raw_width!=@宽度 or raw_height!=@高度 or raw_thickness!=@厚度) group by raw_width,raw_height,raw_thickness order by rank limit 0,1;
                end if;
                
                select count(*) into @counts2 from gmms_shelf_task where task_type='从仓位到上片位' and load_rack=@料架编号one and groups=@groups  and (task_state='等待中' or task_state='正在工作');
                select @counts2;
                if @counts2=0 then
                        select sr.number into @number from gmms_shelf_rack sr join gmms_raw_package rp on sr.raw_package_id1=rp.id where rp.raw_width=@raw_width and rp.raw_height=@raw_height and rp.raw_thickness=@raw_thickness and sr.state='使用中' and sr.falg='启用' and rp.left_pieces>0 and rp.color=@color order by rp.left_pieces limit 1;
                        
                        if @number is not null and @料架编号one is not null then
                        
                            select max(task_id) into @maxtask_id from gmms_shelf_task;
                            insert into gmms_shelf_task set task_type='从仓位到上片位',task_state='等待中',load_rack=@料架编号one,groups=@groups,shelf_rack_id=@number,start_time=Now(),task_id=(@maxtask_id+1);
                            update gmms_shelf_rack set state='正在使用' where number=@number;
                        end if;
                end if;
                
            
            elseif @料架标志two=0 then
            
                if @料架标志one=0 then
                    select raw_width,raw_height,raw_thickness,color into @raw_width,@raw_height,@raw_thickness,@color from gmms_pattern_task where groups=@groups and work_state='等待中' group by raw_width,raw_height,raw_thickness,color order by rank limit 0,1;
                                
                else
                    select rp.left_pieces,rp.raw_width,rp.raw_height,rp.raw_thickness,rp.color,sr.id,sr.color_falg into @剩余片数,@宽度,@高度,@厚度,@颜色,@shelf_rack_id,@膜系标志 from gmms_load_rack r join gmms_shelf_task s on r.shelf_task_id=s.id join gmms_shelf_rack sr on s.shelf_rack_id=sr.id join gmms_raw_package rp on sr.raw_package_id1=rp.id where r.number=@料架编号one;
                
                    select raw_width,raw_height,raw_thickness,color into @raw_width,@raw_height,@raw_thickness,@color from gmms_pattern_task where groups=@groups and work_state='等待中' and (raw_width!=@宽度 or raw_height!=@高度 or raw_thickness!=@厚度) group by raw_width,raw_height,raw_thickness order by rank limit 0,1;
                end if;
                
                select count(*) into @counts2 from gmms_shelf_task where task_type='从仓位到上片位' and load_rack=@料架编号two and groups=@groups  and (task_state='等待中' or task_state='正在工作');
                select @counts2;
                if @counts2=0 then
                        select sr.number into @number from gmms_shelf_rack sr join gmms_raw_package rp on sr.raw_package_id1=rp.id where rp.raw_width=@raw_width and rp.raw_height=@raw_height and rp.raw_thickness=@raw_thickness and sr.state='使用中' and sr.falg='启用' and rp.left_pieces>0 and rp.color=@color order by rp.left_pieces limit 1;
                        
                        if @number is not null and @料架编号two is not null then
                        
                            select max(task_id) into @maxtask_id from gmms_shelf_task;
                            insert into gmms_shelf_task set task_type='从仓位到上片位',task_state='等待中',load_rack=@料架编号two,groups=@groups,shelf_rack_id=@number,start_time=Now(),task_id=(@maxtask_id+1);
                            update gmms_shelf_rack set state='正在使用' where number=@number;
                        end if;
                end if;
            
            end if;
        end if;
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for Loads
-- ----------------------------
DROP PROCEDURE IF EXISTS `Loads`;
delimiter ;;
CREATE PROCEDURE `Loads`(in sendMessageHex varchar(255),in machineids BIGINT,out messagedate varchar(255))
BEGIN
    #上片存储过程
    #找到当前机器标志位
    #查询机器逻辑表中对应的逻辑进行对应的步骤
    DECLARE machinedisposeids int DEFAULT 0;
    DECLARE dates varchar(255);
    DECLARE findplc varchar(255);
    DECLARE findmes varchar(255);
    DECLARE taskplc varchar(255);
    DECLARE taskmes varchar(255);
    DECLARE messagedates varchar(255) DEFAULT '';
    set messagedate=messagedates;
    
    select machine_type_id into @mtid from gmms_machine where id=machineids;
    
    
    
    select mf.flag into @完成标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='完成字';
    
    select mf.flag into @请求标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='请求字';
    
    select mf.flag into @发送标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='发送字';
    
    select mf.flag into @完成确认标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='完成确认字';
    
    set findplc = substring(sendMessageHex,(cast(@完成标志位 as UNSIGNED INTEGER)*4)+19,4);
    set taskplc = substring(sendMessageHex,(cast(@请求标志位 as UNSIGNED INTEGER)*4)+19,4);
    set taskmes = substring(sendMessageHex,(cast(@发送标志位 as UNSIGNED INTEGER)*4)+19,4);
    set findmes = substring(sendMessageHex,(cast(@完成确认标志位 as UNSIGNED INTEGER)*4)+19,4);
     select taskplc;
     select taskmes;
     select findplc;
    select findmes;
    
    #完成逻辑查询
    select count(*),md.id into @完成数量,@完成逻辑编号 from gmms_machine_dispose md join gmms_machine_type mt on md.machine_type_id=mt.id where md.machine_type_id=@mtid  and md.plc_font_type='完成字' and md.mes_font_type='完成确认字' and md.plc_font_value=findplc and md.mes_font_value=findmes;
    
    #请求逻辑查询
    select count(*),md.id into @请求数量,@请求逻辑编号 from gmms_machine_dispose md join gmms_machine_type mt on md.machine_type_id=mt.id where md.machine_type_id=@mtid  and md.plc_font_type='请求字' and md.mes_font_type='发送字' and md.plc_font_value=taskplc and md.mes_font_value=taskmes;
    
 
    #判断逻辑是否存在
    if @完成数量=1 or @请求数量=1 then
    
        #判断完成逻辑是否为空
        if @完成逻辑编号!=0 then
            set machinedisposeids=@完成逻辑编号;
            
        #判断请求逻辑是否为空
        elseif @请求逻辑编号!=0 then
            set machinedisposeids=@请求逻辑编号;
            
        end if;
        select machinedisposeids;
        #查询当前执行逻辑进行判断
        select logic,return_value into @ExecutionLogic,@returnvalue from gmms_machine_dispose where id=machinedisposeids;
        select @ExecutionLogic;
        if @ExecutionLogic='任务完成' then
                call LoadFinsh(machineids,machinedisposeids,1,@messagedate);
                set messagedate=@messagedate;
        elseif @ExecutionLogic='任务未完成' then
                call LoadFinsh(machineids,machinedisposeids,4,@messagedate);
                set messagedate=@messagedate;
         elseif @ExecutionLogic='完成破损' then
                call LoadFinsh(machineids,machinedisposeids,3,@messagedate);
                set messagedate=@messagedate;
         elseif @ExecutionLogic='完成清空' then
--                 select count(*) into @counts from gmms_load_rack where machine_id=machineids and state='正在工作';
--                 if @counts!=0 then
--                     update gmms_load_rack set state='等待中' where machine_id=machineids and state='正在工作';
--                 end if;
                call message(@returnvalue,'0014',@date);
                set messagedate=@date;
        elseif @ExecutionLogic='任务请求' then
                call LoadSend(machineids,@returnvalue,@messagedate);
                set messagedate=@messagedate;
         elseif @ExecutionLogic='任务清空' then
                set dates=CONCAT(@returnvalue,"0000000000000000");
                call message(dates,'000a',@date);
                set messagedate=@date;
        end if;
    end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for LoadSend
-- ----------------------------
DROP PROCEDURE IF EXISTS `LoadSend`;
delimiter ;;
CREATE PROCEDURE `LoadSend`(in machineids BIGINT,in returnvalue varchar(255),out messagedate varchar(255))
BEGIN
    #上片请求存储过程
    #循环找到工位上面有架子并且剩余数量大于零并且没有完成的上片任务进行修改
        DECLARE s int DEFAULT 0;
        DECLARE dates varchar(255);
        DECLARE width int;
        DECLARE heigth int;
        DECLARE pgknum int;
        DECLARE locknum int;
        DECLARE messagedates varchar(255) DEFAULT '';
      set messagedate=messagedates;
        
        select count(*) into @数量 from gmms_load_rack r where machine_id=machineids;
        select groups into @groups from gmms_load_rack r where machine_id=machineids GROUP BY groups;
        
        select @数量;
        
        select id,raw_width,raw_height,raw_thickness,color into @pattern_id,@raw_width,@raw_height,@raw_thickness,@color from gmms_pattern_task where work_state='等待中'    and groups=@groups order by rank limit 1;
        select count(*) into @countss from gmms_pattern_task where work_state='等待中' and groups=@groups;
        select count(*) into @counts2 from gmms_pattern_task where work_state='正在工作' and groups=@groups;
        select @pattern_id;
        select r.falg_shelf,r.number,r.shelf_task_id into @料架标志one,@料架编号one,@任务编号one from gmms_load_rack r where machine_id=machineids limit 0,1;
        
        select @料架标志one;
        select @料架编号one;
        select @任务编号one;
        
        select r.falg_shelf,r.number,r.shelf_task_id into @料架标志two,@料架编号two,@任务编号two from gmms_load_rack r where machine_id=machineids limit 1,1;
        
        select @料架标志two;
        
        if @countss>0 and @counts2=0 then
        
            if @料架标志one="1" then
            
                select rp.left_pieces,rp.raw_width,rp.raw_height,rp.raw_thickness,rp.color,sr.id,sr.color_falg into @剩余片数,@宽度,@高度,@厚度,@颜色,@shelf_rack_id,@膜系标志 from gmms_load_rack r join gmms_shelf_task s on r.shelf_task_id=s.id join gmms_shelf_rack sr on s.shelf_rack_id=sr.id join gmms_raw_package rp on sr.raw_package_id1=rp.id where r.number=@料架编号one;
                
                #@color='白玻' or @color='超白' or @color='C' or @膜系标志=1
                if 1=1 then
                    if @raw_width=@宽度 and @raw_height=@高度 and @raw_thickness=@厚度 and @color=@颜色 and @剩余片数>0 then
                    
                        update gmms_machine a set work_state="正在工作" where id=machineids;
                        update gmms_load_rack set state="正在工作" where machine_id=machineids and number=@料架编号one;
                        update gmms_pattern_task set work_state="正在工作" where  work_state="等待中" and groups=@groups limit 1  ;
                        set width=cast(@宽度 as UNSIGNED INTEGER);
                        set heigth=cast(@高度 as UNSIGNED INTEGER);
    --                     set pgknum=cast(@完成任务数量 as UNSIGNED INTEGER);
    --                     set locknum=cast(@等待中任务数量 as UNSIGNED INTEGER);
                        call intTo2ByteHex10_16_4(width,@width);
                        call intTo2ByteHex10_16_4(heigth,@heigth);
    --                     call intTo2ByteHex10_16_4(pgknum,@pgknum);
    --                     call intTo2ByteHex10_16_4(locknum,@locknum);
                        set dates=CONCAT(returnvalue,"00000002",@width,@heigth);
                        call message(dates,'000a',@date);
                        set messagedate=@date;
                    else
                        if @料架编号one is not null and @groups is not null and @shelf_rack_id is not null then
                            select count(*) into @counts from gmms_shelf_task where task_type='从上片位到仓位' and load_rack=@料架编号one and groups=@groups and shelf_rack_id=@shelf_rack_id and (task_state='等待中' or task_state='正在工作');
                            if @counts=0 then
                            
                                select max(task_id) into @maxtask_id from gmms_shelf_task;
                                insert into gmms_shelf_task set task_type='从上片位到仓位',task_state='等待中',load_rack=@料架编号one,groups=@groups,shelf_rack_id=@shelf_rack_id,start_time=Now(),task_id=(@maxtask_id+1);    
 
                            end if;
                        end if;
                                    
                    end if;
                else
                    if @raw_width=@宽度 and @raw_height=@高度 and @raw_thickness=@厚度 and @color=@颜色 and @剩余片数>1 then
                    
                    
                        update gmms_machine a set work_state="正在工作" where id=machineids;
                        update gmms_load_rack set state="正在工作" where machine_id=machineids and number=@料架编号one;
                        update gmms_pattern_task set work_state="正在工作" where  work_state="等待中" and groups=@groups limit 1;
                        set width=cast(@宽度 as UNSIGNED INTEGER);
                        set heigth=cast(@高度 as UNSIGNED INTEGER);
    --                     set pgknum=cast(@完成任务数量 as UNSIGNED INTEGER);
    --                     set locknum=cast(@等待中任务数量 as UNSIGNED INTEGER);
                        call intTo2ByteHex10_16_4(width,@width);
                        call intTo2ByteHex10_16_4(heigth,@heigth);
    --                     call intTo2ByteHex10_16_4(pgknum,@pgknum);
    --                     call intTo2ByteHex10_16_4(locknum,@locknum);
                        set dates=CONCAT(returnvalue,"00000002",@width,@heigth);
                        call message(dates,'000a',@date);
                        set messagedate=@date;
                    else
                        if @料架编号one is not null and @groups is not null and @shelf_rack_id is not null then
                            select count(*) into @counts from gmms_shelf_task where task_type='从上片位到仓位' and load_rack=@料架编号one and groups=@groups and shelf_rack_id=@shelf_rack_id and (task_state='等待中' or task_state='正在工作');
                            if @counts=0 then
                            
                                select max(task_id) into @maxtask_id from gmms_shelf_task;
                                insert into gmms_shelf_task set task_type='从上片位到仓位',task_state='等待中',load_rack=@料架编号one,groups=@groups,shelf_rack_id=@shelf_rack_id,start_time=Now(),task_id=(@maxtask_id+1);    
 
                            end if;
                        end if;
                                    
                    end if;
                end if;
            
            elseif @料架标志two="1" then
            
                select rp.left_pieces,rp.raw_width,rp.raw_height,rp.raw_thickness,rp.color into @剩余片数,@宽度,@高度,@厚度,@颜色 from gmms_load_rack r join gmms_shelf_task s on r.shelf_task_id=s.id join gmms_shelf_rack sr on s.shelf_rack_id=sr.id join gmms_raw_package rp on sr.raw_package_id1=rp.id where r.number=@料架编号two;
                
                #@color='白玻' or @color='超白' or @color='C' or @膜系标志=1
                if 1=1 then
                select @raw_width,@宽度,@raw_height,@高度,@raw_thickness,@厚度,@color,@颜色,@剩余片数;
                    if @raw_width=@宽度 and @raw_height=@高度 and @raw_thickness=@厚度 and @color=@颜色 and @剩余片数>0 then
                        update gmms_machine a set work_state="正在工作" where id=machineids;
                        update gmms_load_rack set state="正在工作" where machine_id=machineids and number=@料架编号two;
                        update gmms_pattern_task set work_state="正在工作" where work_state="等待中" and groups=@groups limit 1;
                        set width=cast(@宽度 as UNSIGNED INTEGER);
                        set heigth=cast(@高度 as UNSIGNED INTEGER);
    --                     set pgknum=cast(@完成任务数量 as UNSIGNED INTEGER);
    --                     set locknum=cast(@等待中任务数量 as UNSIGNED INTEGER);
                        call intTo2ByteHex10_16_4(width,@width);
                        call intTo2ByteHex10_16_4(heigth,@heigth);
    --                     call intTo2ByteHex10_16_4(pgknum,@pgknum);
    --                     call intTo2ByteHex10_16_4(locknum,@locknum);
                        set dates=CONCAT(returnvalue,"00000002",@width,@heigth);
                        call message(dates,'000a',@date);
                        set messagedate=@date;
                    else
                        select 1;
--                         if @料架编号one is not null and @groups is not null then
--                             select count(*) into @counts1 from gmms_shelf_task where task_type='从仓位到上片位' and load_rack=@料架编号one and groups=@groups  and (task_state='等待中' or task_state='正在工作');
--                             select @counts1;
--                             if @counts1=0 then
--                             select sr.number into @number from gmms_shelf_rack sr join gmms_raw_package rp on sr.raw_package_id1=rp.id where rp.raw_width=@raw_width and rp.raw_height=@raw_height and rp.raw_thickness=@raw_thickness and sr.falg='启用' and sr.state='使用中' and rp.left_pieces>0    and rp.color=@color limit 1;
--                                 if @number is not null and @料架编号one is not null then
--                         
--                                     select max(task_id) into @maxtask_id from gmms_shelf_task;
--                                     insert into gmms_shelf_task set task_type='从仓位到上片位',task_state='等待中',load_rack=@料架编号one,groups=@groups,shelf_rack_id=@number,start_time=Now(),task_id=(@maxtask_id+1);
--                                     update gmms_shelf_rack set state='正在使用' where number=@shelf_rack_id;
--                                 end if;
--                             end if;
--                         end if;
                    
                    end if;
                else
                    if @raw_width=@宽度 and @raw_height=@高度 and @raw_thickness=@厚度 and @color=@颜色 and @剩余片数>1 then
                        update gmms_machine a set work_state="正在工作" where id=machineids;
                        update gmms_load_rack set state="正在工作" where machine_id=machineids and number=@料架编号two;
                        update gmms_pattern_task set work_state="正在工作" where work_state="等待中" and groups=@groups limit 1;
                        set width=cast(@宽度 as UNSIGNED INTEGER);
                        set heigth=cast(@高度 as UNSIGNED INTEGER);
    --                     set pgknum=cast(@完成任务数量 as UNSIGNED INTEGER);
    --                     set locknum=cast(@等待中任务数量 as UNSIGNED INTEGER);
                        call intTo2ByteHex10_16_4(width,@width);
                        call intTo2ByteHex10_16_4(heigth,@heigth);
    --                     call intTo2ByteHex10_16_4(pgknum,@pgknum);
    --                     call intTo2ByteHex10_16_4(locknum,@locknum);
                        set dates=CONCAT(returnvalue,"00000002",@width,@heigth);
                        call message(dates,'000a',@date);
                        set messagedate=@date;
                    else
                    select 1;
--                         if @料架编号one is not null and @groups is not null then
--                             select count(*) into @counts1 from gmms_shelf_task where task_type='从仓位到上片位' and load_rack=@料架编号one and groups=@groups  and (task_state='等待中' or task_state='正在工作');
--                             select @counts1;
--                             if @counts1=0 then
--                 
--                             /*
--                             #新修改 防止吊装位错误拉片 未实际装
--                                         select sr.number into @number from gmms_shelf_rack sr join gmms_raw_package rp on sr.raw_package_id1=rp.id 
--                                         left join gmms_load_rack c on sr.id=c.shelf_task_id 
--                                         where rp.raw_width=@raw_width and rp.raw_height=@raw_height and rp.raw_thickness=@raw_thickness and sr.falg='启用'  and sr.state='使用中' and rp.left_pieces>0 and rp.color=@color and c.id<>99 order by rp.left_pieces limit 1;
--                             */
--                             
--                                 select sr.number into @number from gmms_shelf_rack sr join gmms_raw_package rp on sr.raw_package_id1=rp.id where rp.raw_width=@raw_width and rp.raw_height=@raw_height and rp.raw_thickness=@raw_thickness and sr.falg='启用'  and sr.state='使用中' and rp.left_pieces>0 and rp.color=@color order by rp.left_pieces limit 1;
--                                 if @number is not null and @料架编号one is not null then
--                         
--                                     select max(task_id) into @maxtask_id from gmms_shelf_task;
--                                     insert into gmms_shelf_task set task_type='从仓位到上片位',task_state='等待中',load_rack=@料架编号one,groups=@groups,shelf_rack_id=@number,start_time=Now(),task_id=(@maxtask_id+1);
--                                     update gmms_shelf_rack set state='正在使用' where number=@shelf_rack_id;
--                                 end if;
--                             end if;
--                         end if;
                    
                    end if;
                end if;
 
            else
                select 1;
--                 if @料架编号one is not null and @groups is not null then
--                     select count(*) into @counts2 from gmms_shelf_task where task_type='从仓位到上片位' and load_rack=@料架编号one and groups=@groups  and (task_state='等待中' or task_state='正在工作');
--                     select @counts2;
--                     if @counts2=0 then
--                         select sr.number into @number from gmms_shelf_rack sr join gmms_raw_package rp on sr.raw_package_id1=rp.id where rp.raw_width=@raw_width and rp.raw_height=@raw_height and rp.raw_thickness=@raw_thickness and sr.state='使用中' and sr.falg='启用' and rp.left_pieces>0 and rp.color=@color order by rp.left_pieces limit 1;
--                         
--                         if @number is not null and @料架编号one is not null then
--                         
--                             select max(task_id) into @maxtask_id from gmms_shelf_task;
--                             insert into gmms_shelf_task set task_type='从仓位到上片位',task_state='等待中',load_rack=@料架编号one,groups=@groups,shelf_rack_id=@number,start_time=Now(),task_id=(@maxtask_id+1);
--                             update gmms_shelf_rack set state='正在使用' where number=@shelf_rack_id;
--                         end if;
--                     end if;
--                 end if;
                
            end if;
        end if;
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for LoadSend_copy1
-- ----------------------------
DROP PROCEDURE IF EXISTS `LoadSend_copy1`;
delimiter ;;
CREATE PROCEDURE `LoadSend_copy1`(in machineids BIGINT,in returnvalue varchar(255),out messagedate varchar(255))
BEGIN
    #上片请求存储过程
    #循环找到工位上面有架子并且剩余数量大于零并且没有完成的上片任务进行修改
        DECLARE s int DEFAULT 0;
        DECLARE dates varchar(255);
        DECLARE width int;
        DECLARE heigth int;
        DECLARE pgknum int;
        DECLARE locknum int;
        DECLARE messagedates varchar(255) DEFAULT '';
      set messagedate=messagedates;
        
        select count(*) into @数量 from gmms_load_rack r where machine_id=machineids;
        select groups into @groups from gmms_load_rack r where machine_id=machineids GROUP BY groups;
        
        select @数量;
        
        select id,raw_width,raw_height,raw_thickness,color into @pattern_id,@raw_width,@raw_height,@raw_thickness,@color from gmms_pattern_task where work_state='等待中'    and groups=@groups order by rank limit 1;
        select count(*) into @countss from gmms_pattern_task where work_state='等待中' and groups=@groups;
        select count(*) into @counts2 from gmms_pattern_task where work_state='正在工作' and groups=@groups;
        select @pattern_id;
        select r.falg_shelf,r.number,r.shelf_task_id into @料架标志one,@料架编号one,@任务编号one from gmms_load_rack r where machine_id=machineids limit 0,1;
        
        select @料架标志one;
        select @料架编号one;
        select @任务编号one;
        
        select r.falg_shelf,r.number,r.shelf_task_id into @料架标志two,@料架编号two,@任务编号two from gmms_load_rack r where machine_id=machineids limit 1,1;
        
        select @料架标志two;
        
        if @countss>0 and @counts2=0 then
        
            if @料架标志one="1" then
            
                select rp.left_pieces,rp.raw_width,rp.raw_height,rp.raw_thickness,rp.color,sr.id,sr.color_falg into @剩余片数,@宽度,@高度,@厚度,@颜色,@shelf_rack_id,@膜系标志 from gmms_load_rack r join gmms_shelf_task s on r.shelf_task_id=s.id join gmms_shelf_rack sr on s.shelf_rack_id=sr.id join gmms_raw_package rp on sr.raw_package_id1=rp.id where r.number=@料架编号one;
                
                #@color='白玻' or @color='超白' or @color='C' or @膜系标志=1
                if 1=1 then
                    if @raw_width=@宽度 and @raw_height=@高度 and @raw_thickness=@厚度 and @color=@颜色 and @剩余片数>0 then
                    
                        update gmms_machine a set work_state="正在工作" where id=machineids;
                        update gmms_load_rack set state="正在工作" where machine_id=machineids and number=@料架编号one;
                        update gmms_pattern_task set work_state="正在工作" where  work_state="等待中" and groups=@groups limit 1  ;
                        set width=cast(@宽度 as UNSIGNED INTEGER);
                        set heigth=cast(@高度 as UNSIGNED INTEGER);
    --                     set pgknum=cast(@完成任务数量 as UNSIGNED INTEGER);
    --                     set locknum=cast(@等待中任务数量 as UNSIGNED INTEGER);
                        call intTo2ByteHex10_16_4(width,@width);
                        call intTo2ByteHex10_16_4(heigth,@heigth);
    --                     call intTo2ByteHex10_16_4(pgknum,@pgknum);
    --                     call intTo2ByteHex10_16_4(locknum,@locknum);
                        set dates=CONCAT(returnvalue,"00000002",@width,@heigth);
                        call message(dates,'000a',@date);
                        set messagedate=@date;
                    else
                        if @料架编号one is not null and @groups is not null and @shelf_rack_id is not null then
                            select count(*) into @counts from gmms_shelf_task where task_type='从上片位到仓位' and load_rack=@料架编号one and groups=@groups and shelf_rack_id=@shelf_rack_id and (task_state='等待中' or task_state='正在工作');
                            if @counts=0 then
                            
                                select max(task_id) into @maxtask_id from gmms_shelf_task;
                                insert into gmms_shelf_task set task_type='从上片位到仓位',task_state='等待中',load_rack=@料架编号one,groups=@groups,shelf_rack_id=@shelf_rack_id,start_time=Now(),task_id=(@maxtask_id+1);    
 
                            end if;
                        end if;
                                    
                    end if;
                else
                    if @raw_width=@宽度 and @raw_height=@高度 and @raw_thickness=@厚度 and @color=@颜色 and @剩余片数>1 then
                    
                    
                        update gmms_machine a set work_state="正在工作" where id=machineids;
                        update gmms_load_rack set state="正在工作" where machine_id=machineids and number=@料架编号one;
                        update gmms_pattern_task set work_state="正在工作" where  work_state="等待中" and groups=@groups limit 1;
                        set width=cast(@宽度 as UNSIGNED INTEGER);
                        set heigth=cast(@高度 as UNSIGNED INTEGER);
    --                     set pgknum=cast(@完成任务数量 as UNSIGNED INTEGER);
    --                     set locknum=cast(@等待中任务数量 as UNSIGNED INTEGER);
                        call intTo2ByteHex10_16_4(width,@width);
                        call intTo2ByteHex10_16_4(heigth,@heigth);
    --                     call intTo2ByteHex10_16_4(pgknum,@pgknum);
    --                     call intTo2ByteHex10_16_4(locknum,@locknum);
                        set dates=CONCAT(returnvalue,"00000002",@width,@heigth);
                        call message(dates,'000a',@date);
                        set messagedate=@date;
                    else
                        if @料架编号one is not null and @groups is not null and @shelf_rack_id is not null then
                            select count(*) into @counts from gmms_shelf_task where task_type='从上片位到仓位' and load_rack=@料架编号one and groups=@groups and shelf_rack_id=@shelf_rack_id and (task_state='等待中' or task_state='正在工作');
                            if @counts=0 then
                            
                                select max(task_id) into @maxtask_id from gmms_shelf_task;
                                insert into gmms_shelf_task set task_type='从上片位到仓位',task_state='等待中',load_rack=@料架编号one,groups=@groups,shelf_rack_id=@shelf_rack_id,start_time=Now(),task_id=(@maxtask_id+1);    
 
                            end if;
                        end if;
                                    
                    end if;
                end if;
            
            elseif @料架标志two="1" then
            
                select rp.left_pieces,rp.raw_width,rp.raw_height,rp.raw_thickness,rp.color into @剩余片数,@宽度,@高度,@厚度,@颜色 from gmms_load_rack r join gmms_shelf_task s on r.shelf_task_id=s.id join gmms_shelf_rack sr on s.shelf_rack_id=sr.id join gmms_raw_package rp on sr.raw_package_id1=rp.id where r.number=@料架编号two;
                
                #@color='白玻' or @color='超白' or @color='C' or @膜系标志=1
                if 1=1 then
                select @raw_width,@宽度,@raw_height,@高度,@raw_thickness,@厚度,@color,@颜色,@剩余片数;
                    if @raw_width=@宽度 and @raw_height=@高度 and @raw_thickness=@厚度 and @color=@颜色 and @剩余片数>0 then
                        update gmms_machine a set work_state="正在工作" where id=machineids;
                        update gmms_load_rack set state="正在工作" where machine_id=machineids and number=@料架编号two;
                        update gmms_pattern_task set work_state="正在工作" where work_state="等待中" and groups=@groups limit 1;
                        set width=cast(@宽度 as UNSIGNED INTEGER);
                        set heigth=cast(@高度 as UNSIGNED INTEGER);
    --                     set pgknum=cast(@完成任务数量 as UNSIGNED INTEGER);
    --                     set locknum=cast(@等待中任务数量 as UNSIGNED INTEGER);
                        call intTo2ByteHex10_16_4(width,@width);
                        call intTo2ByteHex10_16_4(heigth,@heigth);
    --                     call intTo2ByteHex10_16_4(pgknum,@pgknum);
    --                     call intTo2ByteHex10_16_4(locknum,@locknum);
                        set dates=CONCAT(returnvalue,"00000002",@width,@heigth);
                        call message(dates,'000a',@date);
                        set messagedate=@date;
                    else
                        select 1;
                        #二工位不对 则生成一工位任务
                        if @料架编号one is not null and @groups is not null then
                            select count(*) into @counts1 from gmms_shelf_task where task_type='从仓位到上片位' and load_rack=@料架编号one and groups=@groups  and (task_state='等待中' or task_state='正在工作');
                            select @counts1;
                            if @counts1=0 then
                            select sr.number into @number from gmms_shelf_rack sr join gmms_raw_package rp on sr.raw_package_id1=rp.id where rp.raw_width=@raw_width and rp.raw_height=@raw_height and rp.raw_thickness=@raw_thickness and sr.falg='启用' and sr.state='使用中' and rp.left_pieces>0    and rp.color=@color limit 1;
                                if @number is not null and @料架编号one is not null then
                        
                                    select max(task_id) into @maxtask_id from gmms_shelf_task;
                                    insert into gmms_shelf_task set task_type='从仓位到上片位',task_state='等待中',load_rack=@料架编号one,groups=@groups,shelf_rack_id=@number,start_time=Now(),task_id=(@maxtask_id+1);
                                    update gmms_shelf_rack set state='正在使用' where number=@shelf_rack_id;
                                end if;
                            end if;
                        end if;
                    
                    end if;
                else
                    if @raw_width=@宽度 and @raw_height=@高度 and @raw_thickness=@厚度 and @color=@颜色 and @剩余片数>1 then
                        update gmms_machine a set work_state="正在工作" where id=machineids;
                        update gmms_load_rack set state="正在工作" where machine_id=machineids and number=@料架编号two;
                        update gmms_pattern_task set work_state="正在工作" where work_state="等待中" and groups=@groups limit 1;
                        set width=cast(@宽度 as UNSIGNED INTEGER);
                        set heigth=cast(@高度 as UNSIGNED INTEGER);
    --                     set pgknum=cast(@完成任务数量 as UNSIGNED INTEGER);
    --                     set locknum=cast(@等待中任务数量 as UNSIGNED INTEGER);
                        call intTo2ByteHex10_16_4(width,@width);
                        call intTo2ByteHex10_16_4(heigth,@heigth);
    --                     call intTo2ByteHex10_16_4(pgknum,@pgknum);
    --                     call intTo2ByteHex10_16_4(locknum,@locknum);
                        set dates=CONCAT(returnvalue,"00000002",@width,@heigth);
                        call message(dates,'000a',@date);
                        set messagedate=@date;
                    else
                    select 1;
                        if @料架编号one is not null and @groups is not null then
                            select count(*) into @counts1 from gmms_shelf_task where task_type='从仓位到上片位' and load_rack=@料架编号one and groups=@groups  and (task_state='等待中' or task_state='正在工作');
                            select @counts1;
                            if @counts1=0 then
                
                            /*
                            #新修改 防止吊装位错误拉片 未实际装
                                        select sr.number into @number from gmms_shelf_rack sr join gmms_raw_package rp on sr.raw_package_id1=rp.id 
                                        left join gmms_load_rack c on sr.id=c.shelf_task_id 
                                        where rp.raw_width=@raw_width and rp.raw_height=@raw_height and rp.raw_thickness=@raw_thickness and sr.falg='启用'  and sr.state='使用中' and rp.left_pieces>0 and rp.color=@color and c.id<>99 order by rp.left_pieces limit 1;
                            */
                            
                                select sr.number into @number from gmms_shelf_rack sr join gmms_raw_package rp on sr.raw_package_id1=rp.id where rp.raw_width=@raw_width and rp.raw_height=@raw_height and rp.raw_thickness=@raw_thickness and sr.falg='启用'  and sr.state='使用中' and rp.left_pieces>0 and rp.color=@color order by rp.left_pieces limit 1;
                                if @number is not null and @料架编号one is not null then
                        
                                    select max(task_id) into @maxtask_id from gmms_shelf_task;
                                    insert into gmms_shelf_task set task_type='从仓位到上片位',task_state='等待中',load_rack=@料架编号one,groups=@groups,shelf_rack_id=@number,start_time=Now(),task_id=(@maxtask_id+1);
                                    update gmms_shelf_rack set state='正在使用' where number=@shelf_rack_id;
                                end if;
                            end if;
                        end if;
                    
                    end if;
                end if;
 
            else
                select 1;
                if @料架编号one is not null and @groups is not null then
                    select count(*) into @counts2 from gmms_shelf_task where task_type='从仓位到上片位' and load_rack=@料架编号one and groups=@groups  and (task_state='等待中' or task_state='正在工作');
                    select @counts2;
                    if @counts2=0 then
                        select sr.number into @number from gmms_shelf_rack sr join gmms_raw_package rp on sr.raw_package_id1=rp.id where rp.raw_width=@raw_width and rp.raw_height=@raw_height and rp.raw_thickness=@raw_thickness and sr.state='使用中' and sr.falg='启用' and rp.left_pieces>0 and rp.color=@color order by rp.left_pieces limit 1;
                        
                        if @number is not null and @料架编号one is not null then
                        
                            select max(task_id) into @maxtask_id from gmms_shelf_task;
                            insert into gmms_shelf_task set task_type='从仓位到上片位',task_state='等待中',load_rack=@料架编号one,groups=@groups,shelf_rack_id=@number,start_time=Now(),task_id=(@maxtask_id+1);
                            update gmms_shelf_rack set state='正在使用' where number=@shelf_rack_id;
                        end if;
                    end if;
                end if;
                
            end if;
        end if;
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for LoadShelfTaskAdd
-- ----------------------------
DROP PROCEDURE IF EXISTS `LoadShelfTaskAdd`;
delimiter ;;
CREATE PROCEDURE `LoadShelfTaskAdd`(in machineids BIGINT)
BEGIN
    #上片仓储任务
    DECLARE FlagType_ BIGINT DEFAULT 1;            #工位类型
    DECLARE Groups_ BIGINT DEFAULT 99;             #工位线路
    
    DECLARE Number_ varchar(255) DEFAULT null;     #上片工位编号
    DECLARE Shelfid_ BIGINT DEFAULT 0;            #仓储任务料架ID
    DECLARE maxtaskid_ BIGINT DEFAULT 0;           #最大任务ID
    
    DECLARE TKNumber_ varchar(255) DEFAULT null;    #退库编号
    DECLARE TKShelfid_ BIGINT DEFAULT 0;            #退库编号料架ID
    
    DECLARE Rawwidth_ BIGINT DEFAULT 0;            #需要宽
    DECLARE Rawheight_ BIGINT DEFAULT 0;           #需要高
    DECLARE Rawtype_ varchar(255) DEFAULT null;    #需要类型
    DECLARE XuyaoPieces_ BIGINT DEFAULT 0;         #需要片数
    
    DECLARE RawwidthNext_ BIGINT DEFAULT 0;            #需要宽
    DECLARE RawheightNext_ BIGINT DEFAULT 0;           #需要高
    DECLARE RawtypeNext_ varchar(255) DEFAULT null;    #需要类型
    DECLARE XuyaoPiecesNext_ BIGINT DEFAULT 0;         #需要片数
    
    DECLARE Did_ BIGINT DEFAULT 0;                  #工位id
    DECLARE DRawwidth_ BIGINT DEFAULT 0;            #当前能吸到的工位1宽
    DECLARE DRawheight_ BIGINT DEFAULT 0;           #当前能吸到的工位1高
    DECLARE DRawtype_ varchar(255) DEFAULT null;    #当前能吸到的工位1类型
    DECLARE DPieces_ BIGINT DEFAULT 0;              #当前能吸到的工位1片数
    
    DECLARE IsExistcount_ BIGINT DEFAULT 0;         #需要片数
    
    #获取单工位/双工位  以及线路
    select gongwei_mode,gm.work_id into FlagType_,Groups_ from gmms_prod_line_state as gp left join gmms_machine as gm on gp.line=gm.work_id where gm.id=machineids;
    
    
    
    #获取此线路当前所需要的原片   into Rawwidth_,Rawheight_,Rawtype_,XuyaoPieces_    and pt.work_state!='已完成'
    select raw_width,raw_height,raw_type,count(*) as sumtkprices into Rawwidth_,Rawheight_,Rawtype_,XuyaoPieces_ from 
    (select pt.rank,pt.raw_width,pt.raw_height,pt.raw_type,
    @count:=IF(@last=CONCAT(pt.raw_width,pt.raw_height,pt.raw_type),@count,@count+1) as tkprices,@last:=CONCAT(pt.raw_width,pt.raw_height,pt.raw_type) as last  from gmms_raw_file as rf 
    left join gmms_pattern_task as pt on rf.id=pt.raw_id,(select @count:=0,@last:=null) as b
    where rf.operator=Groups_ and rf.state='已领取' and pt.work_state!='已完成') as result 
    group by tkprices order by rank asc limit 0,1;
    
    #获取此线路下一类型所需要的原片   into RawwidthNext_,RawheightNext_,RawtypeNext_,XuyaoPiecesNext_   
    select raw_width,raw_height,raw_type,count(*) as sumtkprices into RawwidthNext_,RawheightNext_,RawtypeNext_,XuyaoPiecesNext_ from 
    (select pt.rank,pt.raw_width,pt.raw_height,pt.raw_type,
    @count:=IF(@last=CONCAT(pt.raw_width,pt.raw_height,pt.raw_type),@count,@count+1) as tkprices,@last:=CONCAT(pt.raw_width,pt.raw_height,pt.raw_type) as last  from gmms_raw_file as rf 
    left join gmms_pattern_task as pt on rf.id=pt.raw_id,(select @count:=0,@last:=null) as b
    where rf.operator=Groups_ and rf.state='已领取' and pt.work_state!='已完成') as result 
    group by tkprices order by rank asc limit 1,1;
 
    #获取此线路当前已有的玻璃    into DRawwidth_,DRawheight_,DRawtype_,DPieces_
    select lr.id,rp.raw_width,rp.raw_height,rp.raw_type,rp.left_pieces into Did_,DRawwidth_,DRawheight_,DRawtype_,DPieces_ from
        (select *,IF(shelf_task_id is null,(select gst.id from gmms_shelf_task as gst  
                                where gst.load_rack=glr.number and gst.task_state!='已完成' and gst.task_type='从仓位到上片位'),glr.shelf_task_id) as shelftaskid from gmms_load_rack as glr
                                where glr.groups=Groups_ and number!='11') as lr 
    left join gmms_shelf_task as st on lr.shelftaskid=st.id 
    left join gmms_shelf_rack as sr on st.shelf_rack_id=sr.id 
    left join gmms_raw_package as rp on sr.raw_package_id1=rp.id
    where shelftaskid is not null and rp.raw_width=Rawwidth_ and rp.raw_height=Rawheight_ and rp.raw_type=Rawtype_ and rp.left_pieces>0 order by lr.id limit 0,1;
    
    select MIN(id) from gmms_load_rack where groups=Groups_;
    select '任务需要:',Rawwidth_,Rawheight_,Rawtype_,XuyaoPieces_,'有任务的第一工位:',Did_,DRawwidth_,DRawheight_,DRawtype_,DPieces_;
    #对比当前所需要的原片是否某 工位上有?  
    #            有:  1.且是一工位,2.二工位无任务,3.一工位玻璃完成后有多余任务   则:二工位补架  
    #   没有:  1.查找空位补架
    select max(task_id) into maxtaskid_ from gmms_shelf_task;
    #查找空位补架
    select lr.number into Number_ from 
                (select *,IF(shelf_task_id is null,(select gst.id from gmms_shelf_task as gst  
                                where gst.load_rack=glr.number and gst.task_state!='已完成' and gst.task_type='从仓位到上片位'),glr.shelf_task_id) as shelftaskid from gmms_load_rack as glr
                                where glr.groups=Groups_ and number!='11') as lr 
        where lr.shelftaskid is null order by id asc limit 0,1;
    
    #二工位编号和  架子号
    select lr.number,st.shelf_rack_id into TKNumber_,TKShelfid_ from 
                (select *,IF(shelf_task_id is null,(select gst.id from gmms_shelf_task as gst  
                                where gst.load_rack=glr.number and gst.task_state!='已完成'),glr.shelf_task_id) as shelftaskid from gmms_load_rack as glr
                                where glr.groups=Groups_ and number!='11' and glr.id=(select max(id) from gmms_load_rack where groups=Groups_ and number!='11')) as lr 
    left join gmms_shelf_task as st on lr.shelftaskid=st.id 
    order by lr.id asc limit 0,1;
    
    if (select MIN(id) from gmms_load_rack where groups=Groups_)=Did_ and Did_>0 then
        #补二工位
        if DPieces_>=XuyaoPieces_ and RawwidthNext_>0 then
            select sr.id into Shelfid_ from gmms_shelf_rack as sr LEFT JOIN gmms_raw_package as rp on sr.raw_package_id1=rp.id 
            where sr.state='使用中' and rp.left_pieces>0 and rp.raw_width=RawwidthNext_ and rp.raw_height=RawheightNext_ and rp.raw_type=RawtypeNext_ and sr.falg='启用' 
            order by rp.left_pieces asc limit 0,1;
            select '当前工位玻璃种类剩余数>任务所需数,补下一类型玻璃';
        else
            select sr.id into Shelfid_ from gmms_shelf_rack as sr LEFT JOIN gmms_raw_package as rp on sr.raw_package_id1=rp.id 
            where sr.state='使用中' and rp.left_pieces>0 and rp.raw_width=Rawwidth_ and rp.raw_height=Rawheight_ and rp.raw_type=Rawtype_ and sr.falg='启用'  
            order by rp.left_pieces asc limit 0,1;
            select '当前工位玻璃种类剩余数<任务所需数';
        end if;
    elseif Did_=0 then
        #没有工位符合所需玻璃 
        select sr.id into Shelfid_ from gmms_shelf_rack as sr LEFT JOIN gmms_raw_package as rp on sr.raw_package_id1=rp.id 
        where sr.state='使用中' and rp.left_pieces>0 and rp.raw_width=Rawwidth_ and rp.raw_height=Rawheight_ and rp.raw_type=Rawtype_  and sr.falg='启用' 
        order by rp.left_pieces asc limit 0,1;
        select '没有工位符合当前所需玻璃';
        if TKNumber_ is not null and TKShelfid_>0 and FlagType_=2 and 
            (select count(*) from gmms_shelf_task where (load_rack=TKNumber_ or shelf_rack_id=TKShelfid_) and (task_state='等待中' or task_state='正在工作'))=0    
        then
            select '二工位退库','从上片位到仓位','等待中',TKNumber_,Groups_,TKShelfid_,Now(),(maxtaskid_+1);
            insert into gmms_shelf_task set task_type='从上片位到仓位',task_state='等待中',load_rack=TKNumber_,groups=Groups_,shelf_rack_id=TKShelfid_,start_time=Now(),task_id=(maxtaskid_+1);    
        end if;
    end if;
    select '从仓位到上片位','等待中',Number_,Groups_,Shelfid_,Now(),(maxtaskid_+1);
    
    select count(*) into IsExistcount_ from gmms_shelf_task 
    where (load_rack=Number_ or shelf_rack_id=Shelfid_) and (task_state='等待中' or task_state='正在工作');
    
    if Number_ is not null and Shelfid_>0 and Shelfid_ is not null and IsExistcount_=0 and 
        (((select number from gmms_load_rack where groups=Groups_ and number!='11' order by  id desc LIMIT 0,1)!=Number_ and FlagType_=1) or FlagType_=2) then
        update gmms_shelf_rack set state='正在使用' where id=Shelfid_;
        insert into gmms_shelf_task set task_type='从仓位到上片位',task_state='等待中',load_rack=Number_,groups=Groups_,shelf_rack_id=Shelfid_,start_time=Now(),task_id=(maxtaskid_+1);
        select * from gmms_shelf_rack as sr LEFT JOIN gmms_raw_package as rp on sr.raw_package_id1=rp.id 
        where sr.id=Shelfid_;
        select '成功';
    end if;
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for LoadShelfTaskAdd_
-- ----------------------------
DROP PROCEDURE IF EXISTS `LoadShelfTaskAdd_`;
delimiter ;;
CREATE PROCEDURE `LoadShelfTaskAdd_`(in machineids BIGINT)
BEGIN
    #上片仓储任务
    DECLARE id_ varchar(255) DEFAULT null;         #id
    DECLARE Number_ varchar(255) DEFAULT null;     #编号
    DECLARE FlagShelf_ varchar(255) DEFAULT null;  #是否有架子
    DECLARE ShelfTaskId_ BIGINT DEFAULT 0;         #任务id
    DECLARE groups_ BIGINT DEFAULT 1;              #工位线路
    DECLARE maxtaskid_ BIGINT DEFAULT 0;           #最大任务ID
    
    DECLARE FlagType_ BIGINT DEFAULT 1;            #工位类型
    DECLARE count_ BIGINT DEFAULT 0;               #循环数量
    DECLARE kxcount_ BIGINT DEFAULT 0;             #当前线路有几个工位没有架子
    DECLARE rankcount_ BIGINT DEFAULT 0;           #第几个任务
    
    DECLARE rank_ BIGINT DEFAULT 0;                #第几个任务
    DECLARE width_ BIGINT DEFAULT 0;                #需要长
    DECLARE height_ BIGINT DEFAULT 0;               #需要宽
    DECLARE rawtype_ varchar(255) DEFAULT null;     #需要类型
    
    DECLARE shelfid_ BIGINT DEFAULT 0;              #第几个任务
    DECLARE leftpieces_ BIGINT DEFAULT 0;           #剩余片数
    DECLARE poor_ BIGINT DEFAULT 0;                 #差值
    
    DECLARE rank2_ BIGINT DEFAULT 0;                #第几个任务
    DECLARE taskcount_ BIGINT DEFAULT 0;            #任务连续数量
    
    DECLARE IsExistcount_ BIGINT DEFAULT 0;         #是否已经生成
    DECLARE IsExisttask_ BIGINT DEFAULT 0;          #当前线路生成了几个任务
    
    #获取单工位/双工位
    select gongwei_mode,gm.work_id into FlagType_,groups_ from gmms_prod_line_state as gp left join gmms_machine as gm on gp.line=gm.work_id where gm.id=machineids;
    select count(*) into kxcount_ from gmms_load_rack 
    where machine_id=machineids and number!='11' and falg_shelf=0;
    #当两工位都无架子时生成任务
    select count(*) into IsExisttask_ from gmms_load_rack as lr left join gmms_shelf_task as gt on lr.number=gt.load_rack 
    where (task_state='等待中' or task_state='正在工作') and lr.groups=groups_  and lr.number!='11';
    #and lr.falg_shelf=0
    WHILE FlagType_>count_ and kxcount_=2 and IsExisttask_=0 DO
        set rank_=0,width_=0,height_=0,rawtype_=0,shelfid_=0,leftpieces_=0,IsExistcount_=0,Number_=null,maxtaskid_=0;
        
        select id,number,falg_shelf,shelf_task_id 
        into id_,Number_,FlagShelf_,ShelfTaskId_ from gmms_load_rack 
        where machine_id=machineids and number!='11' limit count_,1;
        
        select count_,kxcount_,id_,Number_,FlagShelf_,ShelfTaskId_,groups_,FlagType_,rankcount_,'开始';
        #最新未完成任务
        select pt.rank,pt.raw_width,pt.raw_height,pt.raw_type into rank_,width_,height_,rawtype_ from gmms_raw_file as rf left join gmms_pattern_task as pt on rf.id=pt.raw_id 
        where rf.operator=groups_ and rf.state='已领取' and pt.work_state!='已完成' order by pt.rank asc limit rankcount_,1;
        #符合所需原片的最少玻璃
        select sr.id,rp.left_pieces into shelfid_,leftpieces_ from gmms_shelf_rack as sr LEFT JOIN gmms_raw_package as rp on sr.raw_package_id1=rp.id 
        where sr.state='使用中' and rp.left_pieces>0 and rp.raw_width=width_ and rp.raw_height=height_ and rp.raw_type=rawtype_ order by rp.left_pieces asc limit 0,1;
        
        #计算当前仓储任务后的下一个任务
        select pt.rank into rank2_ from gmms_raw_file as rf left join gmms_pattern_task as pt on rf.id=pt.raw_id 
        where rf.operator=groups_ and rf.state='已领取' and pt.work_state!='已完成' and (pt.raw_width!=width_ or pt.raw_height!=height_ or pt.raw_type!=rawtype_) 
        order by pt.rank asc limit 0,1;
        
        select count(*) into taskcount_ from gmms_raw_file as rf left join gmms_pattern_task as pt on rf.id=pt.raw_id 
        where rf.operator=groups_ and rf.state='已领取' and pt.work_state!='已完成' and rank<rank2_;
        
        select rank_,width_,height_,rawtype_,shelfid_,leftpieces_,rank2_,taskcount_,'计算';
        select * from gmms_raw_file as rf left join gmms_pattern_task as pt on rf.id=pt.raw_id 
        where rf.operator=groups_ and rf.state='已领取';
        
        #leftpieces_ 剩余片数=0停止任务生成
        if leftpieces_=0 then
            set FlagType_=0;
        elseif    leftpieces_>=taskcount_ then
            #剩余片数大于任务数
            set rankcount_=taskcount_;
        else
            #剩余片数大于任务数
            set rankcount_=leftpieces_;
        end if;
        
        select count(*) into IsExistcount_ from gmms_shelf_task 
        where task_type='从仓位到上片位' and load_rack=Number_ and groups=groups_ and (task_state='等待中' or task_state='正在工作');
        
        if FlagShelf_=0 and shelfid_>0 and leftpieces_>0 and IsExistcount_=0 and Number_ is not null then
            #添加任务
            select * from gmms_raw_file as rf left join gmms_pattern_task as pt on rf.id=pt.raw_id 
            where rf.operator=groups_ and rf.state='已领取';
            select max(task_id) into maxtaskid_ from gmms_shelf_task;
            select '从仓位到上片位','等待中',Number_,groups_,shelfid_,Now(),maxtaskid_+1;
            insert into gmms_shelf_task set task_type='从仓位到上片位',task_state='等待中',load_rack=Number_,groups=groups_,shelf_rack_id=shelfid_,start_time=Now(),task_id=(maxtaskid_+1);
            update gmms_shelf_rack set state='正在使用' where number=shelfid_;
        end if;
        
        
        set count_=count_+1;
    END WHILE;
 
    
    
    
    
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for log_glass
-- ----------------------------
DROP PROCEDURE IF EXISTS `log_glass`;
delimiter ;;
CREATE PROCEDURE `log_glass`(in gid bigint,proc varchar(50),stus varchar(50), ln int)
BEGIN
    #Routine body goes here...
        DECLARE st INT DEFAULT 0;
        DECLARE seg VARCHAR(50) DEFAULT NULL;
        DECLARE worknm VARCHAR(50) DEFAULT NULL;
        DECLARE segst INT DEFAULT NULL;
      DECLARE lid bigint DEFAULT NULL;
        DECLARE _w double DEFAULT 0;
        DECLARE _h double DEFAULT 0;
        DECLARE tk double default 0;
        DECLARE ys varchar(50);
        DECLARE cfg_id bigint;
        DECLARE done int DEFAULT 0;
        DECLARE sql_err int default 0;
        DECLARE cur CURSOR FOR 
         select id,segment,`status`,work_name,segment_status from gmms_glass_log_config where work_proc=proc and work_status=stus;
        DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1;
        DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET sql_err=1;
        
        
        set st=null;
        set segst=null;
        SET done=0;
            set ys=null;
            SELECT w,h,thickness,color into _w,_h,tk,ys from gmms_galss_task_buffer where id=gid;
            set st=null;
            set segst=null;
            if ys is not null then 
            set @z_area=_w*_h/1000/1000;
            open cur;
          FETCH cur into cfg_id,seg,st,worknm,segst;
         while done=0 do
            
                set lid=null;
                #对整个工艺流程进行日志记录
             if segst is not null then 
                             SELECT id,`status` into lid,@z_c_st from gmms_glass_log where segment_name=seg and glass_id=gid and work_name is null
                             and time_out is null  LIMIT 1;
 
            IF lid is not null then 
                    # 插入新条目 表示重新开始 插入新条目,作废旧条目
                    if segst=1 then 
                            UPDATE gmms_glass_log  SET time_out=1 where id=lid;
                            #插入新的
                            INSERT INTO `gmms`.`gmms_glass_log`( `main_id`, `glass_id`, `segment_name`, `work_name`, `line`, `begin_time`, `end_time`, `status`, `parent_id`, `area`, `freeze`) VALUES (cfg_id, gid,seg,NULL,ln, now(), NULL,segst, NULL, @z_area, b'0');                    
                    ELSE
                        #目前不是开始就是结束
                         UPDATE gmms_glass_log set end_time=now(),`status`=segst    where id=lid;    
                    end if;   #if segst=1 then 
            else 
                        if segst=1 then         
                     #插入新条目
                    INSERT INTO `gmms`.`gmms_glass_log`( `main_id`, `glass_id`, `segment_name`, `work_name`, `line`, `begin_time`, `end_time`, `status`, `parent_id`, `area`, `freeze`) VALUES (cfg_id, gid,seg,NULL,ln, now(), NULL,segst, NULL, @z_area, b'0');
                    else
                    INSERT INTO `gmms`.`gmms_glass_log`( `main_id`, `glass_id`, `segment_name`, `work_name`, `line`, `begin_time`, `end_time`, `status`, `parent_id`, `area`, `freeze`) VALUES (cfg_id, gid,seg,NULL,ln, now(), now(),segst, NULL, @z_area, b'0');                    
                        end if;        
            end if;  
       end if;
        set lid=null;
        #对单个工艺进行日志记录
                set segst=st;
                     if segst is not null then 
                             SELECT id,`status` into lid,@z_c_st from gmms_glass_log where segment_name=seg and glass_id=gid and work_name=worknm 
                                  and time_out is null  LIMIT 1;
 
            IF lid is not null then 
        
                    # 插入新条目 表示重新开始 插入新条目,作废旧条目
                    if segst=1 then 
                            UPDATE gmms_glass_log  SET time_out=1 where id=lid;
                            #插入新的
                            INSERT INTO `gmms`.`gmms_glass_log`( `main_id`, `glass_id`, `segment_name`, `work_name`, `line`, `begin_time`, `end_time`, `status`, `parent_id`, `area`, `freeze`) VALUES (cfg_id, gid,seg,worknm,ln, now(), NULL,segst, NULL, @z_area, b'0');                        
                    ELSE
                        #目前不是开始就是结束
                         UPDATE gmms_glass_log set end_time=now(),`status`=segst    where id=lid;    
                    end if; #if segst=1 then 
            else 
                    if segst=1 then         
                     #插入新条目
                    INSERT INTO `gmms`.`gmms_glass_log`( `main_id`, `glass_id`, `segment_name`, `work_name`, `line`, `begin_time`, `end_time`, `status`, `parent_id`, `area`, `freeze`) VALUES (cfg_id, gid,seg,worknm,ln, now(), NULL,segst, NULL, @z_area, b'0');
                    else
                    INSERT INTO `gmms`.`gmms_glass_log`( `main_id`, `glass_id`, `segment_name`, `work_name`, `line`, `begin_time`, `end_time`, `status`, `parent_id`, `area`, `freeze`) VALUES (cfg_id, gid,seg,worknm,ln, now(), now(),segst, NULL, @z_area, b'0');                    
                        end if;  
            end if;              
        end if;  
    FETCH cur into cfg_id,seg,st,worknm,segst; 
    end while;
  close cur;
             end if;
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for log_key_value
-- ----------------------------
DROP PROCEDURE IF EXISTS `log_key_value`;
delimiter ;;
CREATE PROCEDURE `log_key_value`(inout _var text,in _key varchar(50),in _value varchar(200))
BEGIN
    #Routine body goes here...
 set _var =  concat(_var,IFNULL(_key,""),":",IFNULL(_value,""),"\r\n");
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for log_msg
-- ----------------------------
DROP PROCEDURE IF EXISTS `log_msg`;
delimiter ;;
CREATE PROCEDURE `log_msg`(inout _var text,in _key varchar(50))
BEGIN
    #Routine body goes here...
 set _var =  concat(_var,IFNULL(_key,""),"\r\n");
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for machine_state_begin_update
-- ----------------------------
DROP PROCEDURE IF EXISTS `machine_state_begin_update`;
delimiter ;;
CREATE PROCEDURE `machine_state_begin_update`()
BEGIN
    #Routine body goes here...
            set @zzzz_update_state=null;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for machine_state_tick_update
-- ----------------------------
DROP PROCEDURE IF EXISTS `machine_state_tick_update`;
delimiter ;;
CREATE PROCEDURE `machine_state_tick_update`(in _device_id bigint)
BEGIN
    #Routine body goes here...
        DECLARE tk bigint default null;
        DECLARE _err int default 0;
        DECLARE CONTINUE  HANDLER FOR SQLEXCEPTION,SQLWARNING,NOT FOUND set _err=1;
        SELECT tick into tk from gmms_machine_state where device_id=_device_id and var_name='tick'  LIMIT 1;
        if tk is not null then 
            update gmms_machine_state set tick=tk+1 where device_id=_device_id;
        end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for machine_state_update_var
-- ----------------------------
DROP PROCEDURE IF EXISTS `machine_state_update_var`;
delimiter ;;
CREATE PROCEDURE `machine_state_update_var`(in _device bigint ,in _name varchar(100), in _value text)
BEGIN
    #Routine body goes here...
             DECLARE tk bigint default null;
          DECLARE cv text default null;
            DECLARE ex int default null;
            DECLARE _err int default 0;
            DECLARE n_tk bigint default null;
          DECLARE CONTINUE  HANDLER FOR SQLEXCEPTION,SQLWARNING,NOT FOUND set _err=1;
          SELECT tick,next_tick into tk,n_tk from gmms_machine_state where device_id=_device and var_name='tick'  LIMIT 1;
        
            if tk is not null then         #不用记录
                        if @zzzz_update_state is null then 
                            set @zzzz_update_state=1;
                            set tk=tk+1;                        
                            update gmms_machine_state set tick=tk where device_id=_device and var_name='tick';
                        end if;
                        if  _name<>'tick' then     #该变量不可修改
                        
                                SELECT count(*) into ex from gmms_machine_state where device_id=_device and var_name=_name;
                                if ex=0 then 
                                        insert into gmms_machine_state (device_id,
            tick,
            time_stamp,
            var_name,
            var_value)
            value (_device,tk,now(),_name,_value);
                            else
                            
                            update gmms_machine_state set var_value=_value,time_stamp=now(),tick=tk where device_id=_device and var_name=_name;
 
                                end if; 
                                
                        end if;
            end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for make_galss_task_typeid
-- ----------------------------
DROP PROCEDURE IF EXISTS `make_galss_task_typeid`;
delimiter ;;
CREATE PROCEDURE `make_galss_task_typeid`(in gongcheng varchar(30))
BEGIN
    #Routine body goes here..
    
    # 根据工程名更新小片的类型ID
        DECLARE typeid int;
         DECLARE done int;
         DECLARE _width double;
         DECLARE _height double ;
         DECLARE _color varchar(30);
         DECLARE _thickness int;
     
     DECLARE cur cursor for 
     SELECT width,height,color,thickness from gmms_galss_task_buffer where  engineering_id=gongcheng
     group by width,height,color,thickness;
     DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1;
     set done=0;
     set typeid=1;
      open cur;
      FETCH cur into _width,_height,_color,_thickness;
     while done<>1 do 
         UPDATE gmms_galss_task_buffer set type_id=typeid where engineering_id=gongcheng and 
             width=_width and height=_height and color=_color and thickness=_thickness;
                set typeid=typeid+1;
                FETCH cur into _width,_height,_color,_thickness;
      end while;    
     close cur;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for make_order
-- ----------------------------
DROP PROCEDURE IF EXISTS `make_order`;
delimiter ;;
CREATE PROCEDURE `make_order`(in gongcheng varchar(50))
BEGIN
DECLARE done int;
DECLARE w int;
 DECLARE h int;
 DECLARE count int;
 DECLARE color varchar(255);
 DECLARE  thickness double;
 DECLARE _name VARCHAR(50);
 DECLARE idx int;
 
 DECLARE nm varchar(50);
 DECLARE c varchar(255);
 DECLARE thick double;
 DECLARE width int;
 DECLARE height int;
 DECLARE stockid int;
    #Routine body goes here...
declare cur_test CURSOR FOR
SELECT gc_number,color,thickness,gc_width,gc_height,gc_stockid FROM gmms_galss_task_copy1
WHERE gc_number= gongcheng
GROUP BY gc_number,gc_width,gc_height,gc_stockid ,color,thickness
order by gc_stockid;
 DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1;
 open cur_test;  
 
 SET count:=0;
 SET idx=0;
 posLoop:LOOP  
-- 判断是否结束循环  
    
-- 取游标中的值  
    FETCH  cur_test into nm,c,thick,width,height,stockid;
         IF done=1 THEN    
      LEAVE posLoop;  
    END IF;  
        if count=0 then
                SET w:=width;
                SET h:=height;
                SET thickness:=thick;
                SET color:=c;
              SET    count:=1;
                SET _name:=nm;
                SET idx:=idx+1;
        else
            if (w=width and h=height) or (w=height and h=width) then 
                SET count:=    count+1;
            else 
                SELECT c,thick;
                    INSERT INTO gongcheng_raw (gc_name,order_index,color,thickness,width,height,count,state)
                    values (_name,idx,color,thickness,w,h,count,0);
                     SET count=0;                
                    SET w:=width;
                SET h:=height;
                SET thickness:=thick;
                SET color:=c;
              SET    count:=1;     
              SET _name:=nm;
                SET idx:=idx+1;
            end if;
        end if;
  END LOOP posLoop;
        if count>0 then 
                    INSERT INTO gongcheng_raw (gc_name,order_index,color,thickness,width,height,count,state)
                    values (_name,idx,color,thickness,w,h,count,0);                
        end if;          
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for make_pattern_task_buffer_data
-- ----------------------------
DROP PROCEDURE IF EXISTS `make_pattern_task_buffer_data`;
delimiter ;;
CREATE PROCEDURE `make_pattern_task_buffer_data`(in gongcheng varchar(30),in pA varchar(30),in sA varchar(30),in aU varchar(30),in currentColor varchar(30))
BEGIN
  declare w,h,t,pid int;
    declare cl varchar(30);
  declare done int default 0;
  declare cur cursor for
               select gc_width,gc_height,thickness,color,gc_stockid from gmms_galss_task_buffer where engineering_id=gongcheng
              GROUP BY gc_width,gc_height,thickness,color,gc_stockid
              order by gc_stockid  ASC;
                DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1;
    #Routine body goes here...
      set @count=0;
        SELECT count(*) into @count from gmms_pattern_task_buffer where engineering_id=gongcheng;
        
        if @count=0 then 
           open cur;
              loop1:loop 
                        
                    
                     FETCH cur into w,h,t,cl,pid;
                    if done=1 then 
                          select @count;
                       LEAVE loop1;
                     end if;
                 
            
                  INSERT INTO gmms_pattern_task_buffer
                     (rank,raw_type,raw_width,raw_height,raw_thickness,work_state,color,content,task_id,finsh_time,engineering_id)
                    VALUES 
                    (@count+1, CONCAT(cast(t as decimal(10,0)),currentColor),w,h,t,'等待中',currentColor,null,0,null,gongcheng);
                    set @zid=0;
                    SET @zid=LAST_INSERT_ID();
                    SELECT @zid;
                    update gmms_galss_task_buffer set pattern_id=@zid where gc_stockid=pid and engineering_id=gongcheng;
                    
                    SET @count=@count+1;
                end loop loop1;
                close cur;
 
                INSERT INTO gmms_raw_file (file_name,state,operator,create_time,galssmeasure,patternmeasure,cutting_rate) value (gongcheng,'已下发',0,now(),pA,sA,aU);
                                call liuchengka_create_v1(gongcheng);
        end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for Marking
-- ----------------------------
DROP PROCEDURE IF EXISTS `Marking`;
delimiter ;;
CREATE PROCEDURE `Marking`(in sendMessageHex varchar(255),in machineids BIGINT,out messagedate varchar(255))
BEGIN
    #加速台存储过程
    #找到当前机器标志位
    #查询机器逻辑表中对应的逻辑进行对应的步骤
    DECLARE machinedisposeids int DEFAULT 0;
    DECLARE ids int ;
    DECLARE plcfindid varchar(255);
    DECLARE dates varchar(255);
    DECLARE plcid varchar(255);
    DECLARE findplc varchar(255);
    DECLARE findmes varchar(255);
    DECLARE taskplc varchar(255);
    DECLARE taskmes varchar(255);
    DECLARE finsh_rankid BIGINT;
    DECLARE send_rankid BIGINT;
    DECLARE rankids varchar(255);
    DECLARE posunmes varchar(255);
    DECLARE messagedates varchar(255) DEFAULT '';
    set messagedate=messagedates;
    
    
    select machine_type_id,remarks into @mtid,@remarks from gmms_machine where id=machineids;
    set ids = cast(@remarks as UNSIGNED INTEGER);
    
    select mf.flag into @完成标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='完成字';
    
    select mf.flag into @请求标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='请求字';
    
    select mf.flag into @发送标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='发送字';
    
    select mf.flag into @完成确认标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='完成确认字';
    
    set finsh_rankid = cast(@完成标志位 as UNSIGNED INTEGER)+1;
    set send_rankid = cast(@请求标志位+1 as UNSIGNED INTEGER)+1;
    select send_rankid;
    
    set findplc = substring(sendMessageHex,(cast(@完成标志位 as UNSIGNED INTEGER)*4)+19,4);
    set taskplc = substring(sendMessageHex,(cast(@请求标志位 as UNSIGNED INTEGER)*4)+19,4);
    set taskmes = substring(sendMessageHex,(cast(@发送标志位 as UNSIGNED INTEGER)*4)+19,4);
    set findmes = substring(sendMessageHex,(cast(@完成确认标志位 as UNSIGNED INTEGER)*4)+19,4);
    
    select taskplc;
    select taskmes;
    select findplc;
    select findmes;
    select plcfindid;
    
    set rankids = conv(substring(sendMessageHex,(cast(1 as UNSIGNED INTEGER)*4)+19,4),16,10);
    select rankids;
 
    
    #请求逻辑查询
    select count(*),md.id into @请求数量,@请求逻辑编号 from gmms_machine_dispose md join gmms_machine_type mt on md.machine_type_id=mt.id where md.machine_type_id=@mtid  and md.plc_font_type='请求字' and md.mes_font_type='发送字' and md.plc_font_value=taskplc and md.mes_font_value=taskmes;
    
    
    #判断逻辑是否存在
    if  @请求数量=1  then
    
        if @请求逻辑编号!=0 then
            set machinedisposeids=@请求逻辑编号;
            
        end if;
        
        #查询当前执行逻辑进行判断
        select logic,return_value into @ExecutionLogic,@returnvalue from gmms_machine_dispose where id=machinedisposeids;
        select @ExecutionLogic;
        select @returnvalue;
        if @ExecutionLogic='任务请求' then
                call MarkingSend(machineids,@returnvalue,rankids,@messagedate);
                set messagedate=@messagedate;
                
         elseif @ExecutionLogic='任务清空' then
                set dates=CONCAT(@returnvalue,"0000");
                call message(dates,'000a',@date);
                set messagedate=@date;
        end if;
 
    end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for MarkingSend
-- ----------------------------
DROP PROCEDURE IF EXISTS `MarkingSend`;
delimiter ;;
CREATE PROCEDURE `MarkingSend`(in machineids BIGINT,in returnvalue varchar(255),in rankids varchar(255),out messagedate varchar(255))
BEGIN
    #加速台请求存储过程
    #找到当前对应的工序的玻璃信息
    #序号,高度,宽度,厚度发送给plc
    DECLARE number int DEFAULT 0;
    DECLARE out_ranks int;
    DECLARE widths int;
    DECLARE heigths int;
    DECLARE thicknesss int;
    DECLARE drop_frames int;
    DECLARE dates varchar(255);
    DECLARE messagedates varchar(255) DEFAULT '';
    set messagedate=messagedates;
    
    select machine_type_id,work_id into @mtid,@work_groups from gmms_machine where id=machineids;
    
    select file_name into @engineering_id from gmms_raw_file where operator=@work_groups and state='已领取';
    
    select rankids;
    if machineids=41 then
        select marking_flag into @marking_flag from gmms_galss_task where work_procedure='理片' and galss_id=rankids and engineering_id=@engineering_id;
        if @marking_flag is not null then
        
            select da_biao_mo_ban into  @marking_flag from gmms_dongzuo_table where gmms_dongzuo_table.number= @marking_flag LIMIT 1;
        
            call intTo2ByteHex10_16_4(@marking_flag,@marking_flags);
            set dates=CONCAT(returnvalue,@marking_flags);
            call message(dates,'000a',@date);
            set messagedate=@date;
        end if;
    else
        select marking_flag into @marking_flag from gmms_galss_task where work_procedure='理片' and galss_id=rankids and engineering_id=@engineering_id;
        if @marking_flag is not null then
            select da_biao_mo_ban into  @marking_flag from gmms_dongzuo_table where gmms_dongzuo_table.number= @marking_flag LIMIT 1;
            call intTo2ByteHex10_16_4(@marking_flag,@marking_flags);
            set dates=CONCAT(returnvalue,@marking_flags);
            call message(dates,'000a',@date);
            set messagedate=@date;
        end if;
    end if;
    
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for message
-- ----------------------------
DROP PROCEDURE IF EXISTS `message`;
delimiter ;;
CREATE PROCEDURE `message`(in senddate VARCHAR(255),in address VARCHAR(255),out date varchar(255))
BEGIN
    #返回报文进行处理存储过程
    DECLARE Herd varchar(255);
    DECLARE length int;
    DECLARE length1 int;
    DECLARE dates varchar(255);
    DECLARE lengths int;
    DECLARE lengths1 int;
    
    if senddate is null then
        set @softwareconnect=null;
--         select software_connect into @softwareconnect from gmms_machine where id=@div_machine;
--         update gmms_machine set software_connect=@softwareconnect+1 where id=@div_machine;
        
    end if;
    
    set Herd=CONCAT('0110',address);
    set length1 = char_length(senddate);
    set length = char_length(senddate) / 4;
    if length*4>length1 then
        set length=length-1;
    elseif length*4<length1 then
        set length=length+1;
    end if;
    
    call intTo2ByteHex10_16_4(length,@date);
    call intTo2ByteHex10_16_2(length*2,@date1);
    set dates=CONCAT(Herd,@date,@date1,senddate);
--     set lengths=char_length(dates)/2;
    
    set lengths1 = char_length(dates);
    set lengths = char_length(dates)/2;
    if lengths*2>lengths1 then
        set lengths=lengths-1;
    elseif lengths*2<lengths1 then
        set lengths=lengths+1;
    end if;
    call intTo2ByteHex10_16_4(lengths,@date2);
    set date =CONCAT('00000000',@date2,dates);
    
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for numberlength
-- ----------------------------
DROP PROCEDURE IF EXISTS `numberlength`;
delimiter ;;
CREATE PROCEDURE `numberlength`(in number int,out numbers int)
BEGIN
    #处理数据相除的存储过程
    DECLARE number1 int;
    DECLARE count int;
    DECLARE sum int;
    set number1=number;
    set count=0;
    set sum=1;
    
 
    while sum=1 do
        if number1/10>1 or number1/10=10 then
            set count=count+1;
            set number1=number1/10;
        elseif number1=0 then
            set count=count+1;
            set sum=0;
        else 
            set count=count+1;
            set sum=0;
        end if;
    end while;
    set numbers=count;
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for output
-- ----------------------------
DROP PROCEDURE IF EXISTS `output`;
delimiter ;;
CREATE PROCEDURE `output`(in machineids BIGINT,out 发送字 int ,out 发送ID1 int,out 发送ID2 int,out 格子 int,out err varchar(255))
BEGIN
    #理片笼出片存储过程
    #查找有下片位置,并且判断跟上一次出库类型是否相同,相同则出库
    #找到最优的出片方法,判断下片是否还有位置,有的话就绑定当前流程卡跟落架号
    #查找符合出库的玻璃根据玻璃大小依次出片
   DECLARE task_id int;
     DECLARE cur_id int;
     
    CALL log_msg(@log_task,"[output]");
     
     select machine_type_id,work_id into @mtid,@work_groups from gmms_machine where id=machineids;
    
    select file_name into @engineering_id from gmms_raw_file where operator=@work_groups and state='已领取';
    
    
     SET @rk=null;
        SET 发送字=0;
        SET @lastid=null;
        SET @lastpos=null;
     select `value` into @lastid from gmms_var where varname='last_out_glass_id'and groups=@work_groups;
     select `value` into @lastpos from gmms_var where varname='last_pos'and groups=@work_groups;
     if @lastpos=null then 
     SET     @lastpos=2;
     end if;
     SET @processcardid=null;
     #    判断同尺寸出库条件   去查找一个和最后一次磨边尺寸相同,并且可以下架的玻璃
     if @lastid is not null then
        
            CALL log_key_value(@log_task,"出库模式","同尺寸出库");
     
            SELECT a.slicecage_rank,a.type_id,a.count into @rk,@type_id,@count from gmms_slicecage a INNER JOIN gmms_galss_task b on a.slicecage_rank=b.slicecage_rank where a.state='使用中' and a.count>0 and a.type_id=@lastid and a.gourp=@work_groups and a.flag=0 and engineering_id=@engineering_id and b.stop_position>0 order by a.count desc,rank, ABS(a.slicecage_rank-@lastpos) asc LIMIT 1;
            CALL log_key_value(@log_task,"出库位置",@rk);
            
            
            if @rk is not null then
                    if @count=1 then
                    select galss_id into @galss_id from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id;
                    select @galss_id;
                        SET 发送字=2;
                        SET 格子=@rk;                    
                        SET 发送ID1=@galss_id;
                        SET 发送ID2=0;
                        CALL log_key_value(@log_task,"出一片",@rk);
                        UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rk and engineering_id=@engineering_id;
                        UPDATE gmms_slicecage SET state='出库中' where slicecage_rank=@rk and gourp=@work_groups;
                    else
                        select galss_id into @galss_id1 from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id order by rank limit 0,1;
                        select galss_id into @galss_id2 from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id order by rank limit 1,1;
                        SET 发送字=2;
                        SET 格子=@rk;                    
                        SET 发送ID1=@galss_id1;
                        SET 发送ID2=@galss_id2;
                        CALL log_key_value(@log_task,"出二片",@rk);
                        UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rk and engineering_id=@engineering_id;
                        UPDATE gmms_slicecage SET state='出库中' where slicecage_rank=@rk and gourp=@work_groups;
                    end if;
                    
            end if;
     end if;
 
        #   选定一个最符合出库条件的架子  1; 全部切割, 2. 剩余数量最少  3  优先有下片位置的
            if 发送字=0 then
              
                #先使用 全切完的,这样能保证尽快下完架子
                SELECT 流程卡 into @processcardid from processcard_ex where 下片位置 is not null and 库内数>0  and 工程号=@engineering_id order by  总数-下架数 asc LIMIT 1;
                       CALL log_key_value(@log_task,"流程卡",@processcardid);
                select @engineering_id;
select @processcardid;
                IF @processcardid is  null then
                select 2;
                    #  后使用  未完全切完的
                    SELECT 流程卡 into @processcardid from processcard_ex where 下片位置 is not null and 库内数>0 and 工程号=@engineering_id order by 总数-下架数 asc LIMIT 1;    
                end if;
 
                -- 看看空架 有没有 ,如果有  就找一个库能玻璃最多的下架
                IF @processcardid is null then 
                    select @processcardid;
                    SET @drop_pos=null;
                    SELECT id,stops into @drop_pos,@stops from gmms_drop_frame where state='空架' and groups=@work_groups limit 0,1;
                    select @drop_pos;
                    if @drop_pos  is not null then 
                        select name1 into @name1 from namess where groups=@work_groups;
                        select @name1;
                        SELECT 流程卡,架号,总数,工程号 into @processcardid,@drop_frame,@processcard_count,@engineering_ids from processcard_ex where  (库内数>=@name1 or (库内数>0 and 总数<@name1)) and 工程号=@engineering_id order by  总数-库内数 LIMIT 1;
                        #  流程卡占架子
                        select @processcardid;
                        if @processcardid is not null then 
                            UPDATE gmms_drop_frame set state='使用中',drop_frame=@drop_frame,processcard_id=@processcardid,processcard_count=@processcard_count,engineering_id=@engineering_ids where id=@drop_pos;
                            INSERT into hn_user(phone,idcard) VALUES(@processcardid,@work_groups);
                            UPDATE gmms_galss_task set stop_position=@stops where processcard_id=@processcardid and engineering_id=@engineering_id;                
                        end if;            
                    end if;
                end if;
       end if;
         #    确定出库流程卡后  确定出库尺寸   条件   面积最大
    if @processcardid is not null then 
                          SELECT @processcardid;    
                            
         #  选定大小和槽
         SELECT  a.slicecage_rank,a.count,a.type_id into @rk,@count,@type_id from gmms_slicecage a inner join gmms_galss_task b on a.slicecage_rank=b.slicecage_rank where a.processcard_id=@processcardid and a.state='使用中' and a.flag=0 and a.gourp=@work_groups and engineering_id=@engineering_id order by b.width*b.height desc ,a.count DESC  limit 1;
         select @count;
                    if @count=1 then
                        select galss_id into @galss_id from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id;
                        SET 发送字=2;
                        SET 格子=@rk;                    
                        SET 发送ID1=@galss_id;
                        SET 发送ID2=0;
                    else
                        select galss_id into @galss_id1 from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id order by rank limit 0,1;
                        select galss_id into @galss_id2 from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id order by rank limit 1,1;
                        SET 发送字=2;
                        SET 格子=@rk;                    
                        SET 发送ID1=@galss_id1;
                        SET 发送ID2=@galss_id2;
                    end if;
                    UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rk and engineering_id=@engineering_id;
                    UPDATE gmms_slicecage SET state='出库中' where slicecage_rank=@rk and gourp=@work_groups;
                    UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
                    UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups;
    end if;
    select @rk;
--     if 格子 is null or 发送ID1 is null or 发送ID2 is null then
--             
--             set  格子=0;
--             set  发送ID1=0;
--             set  发送ID2=0;
--     end if;
        
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for output2
-- ----------------------------
DROP PROCEDURE IF EXISTS `output2`;
delimiter ;;
CREATE PROCEDURE `output2`(in machineids BIGINT,out 发送字 int ,out 发送ID1 int,out 发送ID2 int,out 格子 int,out err varchar(255))
BEGIN
    #理片笼出片存储过程
    #查找有下片位置,并且判断跟上一次出库类型是否相同,相同则出库
    #找到最优的出片方法,判断下片是否还有位置,有的话就绑定当前流程卡跟落架号
    #查找符合出库的玻璃根据玻璃大小依次出片
   DECLARE task_id int;
     DECLARE cur_id int;
    #Routine body goes here...
     DECLARE gid long DEFAULT(null);
     DECLARE tmp int default(null);
     select machine_type_id,work_id into @mtid,@work_groups from gmms_machine where id=machineids;    
     select file_name into @engineering_id from gmms_raw_file where operator=@work_groups and state='已领取';
     
     select `value` into @lastid from gmms_var where varname='last_out_glass_id'and groups=@work_groups;
     select `value` into @lastpos from gmms_var where varname='last_pos'and groups=@work_groups;
 
    
             set @count=null;
             set 发送字=0;
     
     #更新出库锁(出库锁用来控制出笼玻璃范围)
    if  position("P" in @engineering_id)>0 then
             
     call output2_update_suo(@engineering_id,false,@work_groups);
             
    end if;     
             
             
     
     
     
     
     # 解锁状态1同规格(顺序落架)
        select @lastpos,@lastid;
        set @rk=null;
        set @lck=null;
        SELECT a.slicecage_rank,a.type_id,a.count into @rk,@type_id,@count from gmms_slicecage a INNER JOIN gmms_galss_task b on a.slicecage_rank=b.slicecage_rank where a.state='使用中' and a.count>0 and a.gourp=@work_groups and a.flag=0 and engineering_id=@engineering_id and b.stop_position>0
                    and b.gc_height=1
                     order by a.count desc,rank, ABS(a.slicecage_rank-@lastpos) asc LIMIT 1;    
 
  #  解锁状态2同规格(无序落架)
        select @rk;
    if @rk is null then 
 
        set @rk=null;
        set @lck=null;
        SELECT a.slicecage_rank,a.type_id,a.count into @rk,@type_id,@count from gmms_slicecage a INNER JOIN gmms_galss_task b on a.slicecage_rank=b.slicecage_rank where a.state='使用中' and a.count>0  and a.gourp=@work_groups and a.flag=0 and engineering_id=@engineering_id and b.stop_position>0
                    and b.gc_height>0
                     order by a.count desc,rank, ABS(a.slicecage_rank-@lastpos) asc LIMIT 1;    
    end if;
        
        
        #寻找合适的流程卡
    if @rk is null then 
 
                set @processcardid=null;
                SELECT 流程卡 into @processcardid from processcard_ex inner join gmms_galss_task b on processcard_ex.流程卡=b.processcard_id where 下片位置 is not null and 库内数>0  and 工程号=@engineering_id and b.gc_height<>0 and b.stop_position>0  and b.work_procedure='理片' and b.work_state='已进库' order by  总数-下架数 asc LIMIT 1;
                 CALL log_key_value(@log_task,"流程卡",@processcardid);
                
 
        set @countslieceage=0;
        set @countstop=0;    
        set @countsumgalss=0;        
        select count(*) into @countslieceage from  gmms_slicecage where gourp=@work_groups and flag=0 and slicecage_rank<>1 and `state`='空闲';        
        SELECT count(*) into @countstop from gmms_drop_frame where (state='空架' or state='空闲') and groups=@work_groups;
        select count(*) into @countsumgalss from gmms_galss_task where engineering_id=@engineering_id;
        if @countstop=5 or @countsumgalss<75 then
        
            if @countslieceage<=5  then
            
                IF @processcardid is null then 
                    select @processcardid;
                    SET @drop_pos=null;
            
                    SELECT id,stops into @drop_pos,@stops from gmms_drop_frame where state='空架' and groups=@work_groups limit 0,1;
                    select @drop_pos;
                    if @drop_pos  is not null then 
                        select name1 into @name1 from namess where groups=@work_groups;
                        select @name1;
                        SELECT 流程卡,架号,总数,工程号 into @processcardid,@drop_frame,@processcard_count,@engineering_ids from processcard_ex  inner join    gmms_galss_task b on processcard_ex.流程卡=b.processcard_id where b.gc_height>0 and b.work_procedure='理片' and b.work_state='已进库'  and 下片位置 is null and 库内数>0 and 工程号=@engineering_id order by  库内数 desc,总数-库内数 LIMIT 1;
                        #  流程卡占架子
                        select @processcardid;
                        if @processcardid is not null then 
                            UPDATE gmms_drop_frame set state='使用中',drop_frame=@drop_frame,processcard_id=@processcardid,processcard_count=@processcard_count,engineering_id=@engineering_ids where id=@drop_pos;
                            INSERT into hn_user(phone,idcard) VALUES(@processcardid,@work_groups);
                            UPDATE gmms_galss_task set stop_position=@stops where processcard_id=@processcardid and engineering_id=@engineering_id;                
                        end if;            
                    end if;
                end if;
                
            end if;
            
        else
            IF @processcardid is null then 
                    select @processcardid;
                    SET @drop_pos=null;
            
                    SELECT id,stops into @drop_pos,@stops from gmms_drop_frame where state='空架' and groups=@work_groups limit 0,1;
                    select @drop_pos;
                    if @drop_pos  is not null then 
                        select name1 into @name1 from namess where groups=@work_groups;
                        select @name1;
                        SELECT 流程卡,架号,总数,工程号 into @processcardid,@drop_frame,@processcard_count,@engineering_ids from processcard_ex  inner join    gmms_galss_task b on processcard_ex.流程卡=b.processcard_id where b.gc_height>0 and b.work_procedure='理片' and b.work_state='已进库'  and 下片位置 is null and 库内数>0 and 工程号=@engineering_id order by   库内数 desc,总数-库内数 LIMIT 1;
                        #  流程卡占架子
                        select @processcardid;
                        if @processcardid is not null then 
                            UPDATE gmms_drop_frame set state='使用中',drop_frame=@drop_frame,processcard_id=@processcardid,processcard_count=@processcard_count,engineering_id=@engineering_ids where id=@drop_pos;
                            INSERT into hn_user(phone,idcard) VALUES(@processcardid,@work_groups);
                            UPDATE gmms_galss_task set stop_position=@stops where processcard_id=@processcardid and engineering_id=@engineering_id;                
                        end if;            
                    end if;
                end if;
        end if;
    
    end if;
        
    if @processcardid is not null then         
                 SELECT  a.slicecage_rank,a.count,a.type_id into @rk,@count,@type_id from gmms_slicecage a inner join gmms_galss_task b on a.slicecage_rank=b.slicecage_rank where
            b.gc_height>0    and 
                    a.processcard_id=@processcardid and a.state='使用中' and a.flag=0 and a.gourp=@work_groups and engineering_id=@engineering_id order by b.width*b.height desc ,a.count DESC  limit 1;
    end if;
        
        
        if @rk is not null then 
            if @count=1 then
                        select galss_id into @galss_id from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id;
                        SET 发送字=2;
                        SET 格子=@rk;                    
                        SET 发送ID1=@galss_id;
                        SET 发送ID2=0;
                    else
                        select galss_id into @galss_id1 from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id order by rank limit 0,1;
                        select galss_id into @galss_id2 from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id order by rank limit 1,1;
                        SET 发送字=2;
                        SET 格子=@rk;                    
                        SET 发送ID1=@galss_id1;
                        SET 发送ID2=@galss_id2;
                    end if;
                    UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rk and engineering_id=@engineering_id;
                    UPDATE gmms_slicecage SET state='出库中' where slicecage_rank=@rk and gourp=@work_groups;
                    UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
                    UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups; 
 
        end if;
        #爆笼检测
        select 发送字;
        if 发送字=0 then
        set @count=null;
        select count(*) into @count from  gmms_slicecage where gourp=@work_groups and flag=0 and slicecage_rank<>1 and `state`='空闲';
        SELECT count(*) into @countstop2 from gmms_drop_frame where state='空架' and groups=@work_groups;
 
        if @count=0 and @countstop2>0 then 
          call output2_update_suo(@engineering_id,true,@work_groups);
 
        end if;
        end if;
 
 
 
 
 
--     #理片笼出片存储过程
--     #查找有下片位置,并且判断跟上一次出库类型是否相同,相同则出库
--     #找到最优的出片方法,判断下片是否还有位置,有的话就绑定当前流程卡跟落架号
--     #查找符合出库的玻璃根据玻璃大小依次出片
--    DECLARE task_id int;
--      DECLARE cur_id int;
--     #Routine body goes here...
--      DECLARE gid long DEFAULT(null);
--      DECLARE tmp int default(null);
--      select machine_type_id,work_id into @mtid,@work_groups from gmms_machine where id=machineids;    
--      select file_name into @engineering_id from gmms_raw_file where operator=@work_groups and state='已领取';
--      
--      select `value` into @lastid from gmms_var where varname='last_out_glass_id'and groups=@work_groups;
--      select `value` into @lastpos from gmms_var where varname='last_pos'and groups=@work_groups;
-- 
--     
--              set @count=null;
--              set 发送字=0;
--      
--      #更新出库锁(出库锁用来控制出笼玻璃范围)
--     if  position("P" in @engineering_id)>0 then
--              
--      call output2_update_suo(@engineering_id,false,@work_groups);
--              
--     end if;     
--              
--              
--      
--      
--      
--      
--      # 解锁状态1同规格(顺序落架)
-- select @lastpos,@lastid;
--             set @rk=null;
--             set @lck=null;
--                     SELECT a.slicecage_rank,a.type_id,a.count into @rk,@type_id,@count from gmms_slicecage a INNER JOIN gmms_galss_task b on a.slicecage_rank=b.slicecage_rank where a.state='使用中' and a.count>0 and a.gourp=@work_groups and a.flag=0 and engineering_id=@engineering_id and b.stop_position>0
--                     and b.gc_height=1
--                      order by a.count desc,rank, ABS(a.slicecage_rank-@lastpos) asc LIMIT 1;    
-- 
--   #  解锁状态2同规格(无序落架)
--     select @rk;
--       if @rk is null then 
-- 
--             set @rk=null;
--             set @lck=null;
--                     SELECT a.slicecage_rank,a.type_id,a.count into @rk,@type_id,@count from gmms_slicecage a INNER JOIN gmms_galss_task b on a.slicecage_rank=b.slicecage_rank where a.state='使用中' and a.count>0  and a.gourp=@work_groups and a.flag=0 and engineering_id=@engineering_id and b.stop_position>0
--                     and b.gc_height>0
--                      order by a.count desc,rank, ABS(a.slicecage_rank-@lastpos) asc LIMIT 1;    
--         end if;
--         
--         
--         #寻找合适的流程卡
--         if @rk is null then 
-- 
--         set @processcardid=null;
--                         SELECT 流程卡 into @processcardid from processcard_ex 
--                         inner join 
--                         gmms_galss_task b on processcard_ex.流程卡=b.processcard_id
--                         where 下片位置 is not null and 库内数>0  and 工程号=@engineering_id 
--                         and b.gc_height<>0  and b.work_procedure='理片' and b.work_state='已进库'
--                         order by  总数-下架数 asc LIMIT 1;
--                        CALL log_key_value(@log_task,"流程卡",@processcardid);
--                 
-- 
-- 
-- 
--                 IF @processcardid is  null then
--                 select 2;
--                     #  后使用  未完全切完的
--                     SELECT 流程卡 into @processcardid from processcard_ex
--                     inner join 
--                         gmms_galss_task b on processcard_ex.流程卡=b.processcard_id        
--                      where b.gc_height<>0 and b.work_procedure='理片' and b.work_state='已进库' and 下片位置 is not null and 库内数>0 and 工程号=@engineering_id order by 总数-下架数 asc LIMIT 1;    
--                 end if;
--                 
--                 
--                     IF @processcardid is null then 
--                     select @processcardid;
--                     SET @drop_pos=null;
--             
--                     SELECT id,stops into @drop_pos,@stops from gmms_drop_frame where state='空架' and groups=@work_groups limit 0,1;
--                     select @drop_pos;
--                     if @drop_pos  is not null then 
--                         select name1 into @name1 from namess where groups=@work_groups;
--                         select @name1;
--                         SELECT 流程卡,架号,总数,工程号 into @processcardid,@drop_frame,@processcard_count,@engineering_ids from processcard_ex  inner join    gmms_galss_task b on processcard_ex.流程卡=b.processcard_id where b.gc_height>0 and b.work_procedure='理片' and b.work_state='已进库'  and 下片位置 is null and 库内数>0 and 工程号=@engineering_id order by  总数-库内数 LIMIT 1;
--                         #  流程卡占架子
--                         select @processcardid;
--                         if @processcardid is not null then 
--                             UPDATE gmms_drop_frame set state='使用中',drop_frame=@drop_frame,processcard_id=@processcardid,processcard_count=@processcard_count,engineering_id=@engineering_ids where id=@drop_pos;
--                             INSERT into hn_user(phone,idcard) VALUES(@processcardid,@work_groups);
--                             UPDATE gmms_galss_task set stop_position=@stops where processcard_id=@processcardid and engineering_id=@engineering_id;                
--                         end if;            
--                     end if;
--                 end if;
--        end if;
--         
--     if @processcardid is not null then         
--                  SELECT  a.slicecage_rank,a.count,a.type_id into @rk,@count,@type_id from gmms_slicecage a inner join gmms_galss_task b on a.slicecage_rank=b.slicecage_rank where
--             b.gc_height>0    and 
--                     a.processcard_id=@processcardid and a.state='使用中' and a.flag=0 and a.gourp=@work_groups and engineering_id=@engineering_id order by b.width*b.height desc ,a.count DESC  limit 1;
--     end if;
--         
--         
--         if @rk is not null then 
--             if @count=1 then
--                         select galss_id into @galss_id from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id;
--                         SET 发送字=2;
--                         SET 格子=@rk;                    
--                         SET 发送ID1=@galss_id;
--                         SET 发送ID2=0;
--                     else
--                         select galss_id into @galss_id1 from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id order by rank limit 0,1;
--                         select galss_id into @galss_id2 from gmms_galss_task where slicecage_rank=@rk and engineering_id=@engineering_id order by rank limit 1,1;
--                         SET 发送字=2;
--                         SET 格子=@rk;                    
--                         SET 发送ID1=@galss_id1;
--                         SET 发送ID2=@galss_id2;
--                     end if;
--                     UPDATE gmms_galss_task SET work_state='出库中' where slicecage_rank=@rk and engineering_id=@engineering_id;
--                     UPDATE gmms_slicecage SET state='出库中' where slicecage_rank=@rk and gourp=@work_groups;
--                     UPDATE gmms_var SET Value=@rk where varname='last_pos' and groups=@work_groups;
--                     UPDATE gmms_var SET Value=@type_id where varname='last_out_glass_id' and groups=@work_groups; 
-- 
--         end if;
--         #爆笼检测
--         select 发送字;
--         if 发送字=0 then
--         set @count=null;
--         select count(*) into @count from  gmms_slicecage where gourp=@work_groups and flag=0 and slicecage_rank<>1 and `state`='空闲';
--         if @count=0 then 
--           call output2_update_suo(@engineering_id,true,@work_groups);
--         end if;
--         end if;
-- --         if 格子 is null or 发送ID1 is null or 发送ID2 is null then
-- -- 
-- --             
-- --             set  格子=0;
-- --             set  发送ID1=0;
-- --             set  发送ID2=0;
-- --         end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for output2_update_suo
-- ----------------------------
DROP PROCEDURE IF EXISTS `output2_update_suo`;
delimiter ;;
CREATE PROCEDURE `output2_update_suo`(in _gongcheng varchar(50), baolong int,in groups int(50))
BEGIN
    #Routine body goes here...
  
    DECLARE lck  varchar(50);
    DECLARE st  int;
    DECLARE max_h  int;
    DECLARE cur_h  int;
    DECLARE _suo   INT;
    DECLARE _break int ;
    DECLARE _flags int ;
    DECLARE cur cursor for
    SELECT  liuchengka,
state,
maxxuhao,
currentxuhao,
suo
  from liuchengka_output where gongcheng=_gongcheng;
    DECLARE CONTINUE HANDLER FOR NOT FOUND  SET _break=1;
    
    set _break=0;
    if baolong=false then
    open cur;
    while _break=0 do 
       fetch cur into lck,st,max_h,cur_h,_suo;
        if _break=0 then 
        
        if st=1 then 
            set @zcount=null;
            
            SELECT  count(*) into  @zcount     from gmms_galss_task 
                where processcard_id=lck and gc_width=cur_h and work_state<>'破损' and work_state<>'已出库' and (work_procedure='测量' or work_procedure='理片');
                
                if @zcount=0 then 
                     if cur_h<max_h then 
                            set cur_h=cur_h+1;
                                update liuchengka_output set currentxuhao=cur_h where liuchengka=lck;
                                update gmms_galss_task set gc_height=1 where processcard_id=lck and  gc_width=cur_h;
                         end if;
                end if;
        end if;            
        end if;    
     
    end while;
    close cur;
    
   else
     set @lck=null;
 
select     a.lck into @lck from 
     (SELECT 
count(case when a.gc_width=b.currentxuhao then 1 else null end) as c1,
count(*) as c2,a.processcard_id as lck
 from gmms_galss_task a inner join liuchengka_output b on a.processcard_id=b.liuchengka
where a.work_procedure='理片' and a.work_state='已进库' and a.engineering_id=_gongcheng and b.State=1) a
where c2>0
order by  c2-c1 desc LIMIT 1;
        set @counts=0;
        select count(*) into @counts from gmms_galss_task where engineering_id=_gongcheng and work_procedure='理片' and work_state='已进库' and gc_height=2;
      if @lck is not null and @counts=0 then
        
          update gmms_galss_task set gc_height=2 where processcard_id=@lck;
          update liuchengka_output set `state`=2 where liuchengka=@lck;
            insert into gmms_slicecage_details (processcard_id,groups,time) values(@lck,groups,now());
        end if;
    end if;
    
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for output_create
-- ----------------------------
DROP PROCEDURE IF EXISTS `output_create`;
delimiter ;;
CREATE PROCEDURE `output_create`(in gc varchar(50))
BEGIN
    #Routine body goes here...
    
     DECLARE w double ;
     declare h double;
     declare xh int;
     declare c int;
     declare lck varchar(50);
        declare _break int default(0);
 
        declare nxh int;
        declare lastlck varchar(50);
        declare lw double;
        declare lh double;
        declare tmp int;
        declare countsss int;
        
        
            declare o_err int default(0);
        
        DECLARE cur CURSOR FOR
        SELECT edg_width,edg_height,cast(edg_speed2 as signed) as xuhao,count(*),processcard_id FROM gmms_galss_task where engineering_id=gc group by processcard_id , edg_speed2,processcard_id
     ,edg_width,edg_height order by processcard_id,cast(edg_speed2 as signed);
     DECLARE  CONTINUE HANDLER FOR NOT FOUND SET _break=1;
     set _break=0;
 
set o_err =1;
 
     SELECT edg_width,edg_height,cast(edg_speed2 as signed) as xuhao,count(*),processcard_id FROM gmms_galss_task where engineering_id=gc group by processcard_id , edg_speed2,processcard_id
     ,edg_width,edg_height order by processcard_id,cast(edg_speed2 as signed);
     
     set o_err =2;
     
     open cur;
      set nxh=0;
     set tmp=0;
     select count(*) into tmp from liuchengka_output where gongcheng=gc; 
     if tmp>0 then 
       set _break=1;
     end if;
     set countsss=0;
     while _break=0 do
     
     set o_err =3;
     
        FETCH cur into w,h,xh,c,lck;    
            
            select o_err;
            
            if _break=0 then
                -- cselect 1;
                if nxh=0 then 
                
                set o_err =4;
                
                    set nxh=1;
                    set lastlck=lck;
                    set lw=w;
                    set lh=h;
                    update gmms_galss_task set gc_width=nxh where processcard_id=lck  and edg_speed2=xh;
                    select o_err;
                    
                else            
                                 set o_err =5;
                            
                    if lastlck=lck then 
                    
                         set o_err =6;
                    
                        if lw=w and lh=lh then 
                        set o_err =31;
                        
                            update gmms_galss_task set gc_width=nxh where processcard_id=lck  and edg_speed2=xh;
                        else
                        set o_err =32;
                            set nxh=nxh+1;
                            set   lw=w;
                            set   lh=h;
                            update gmms_galss_task set gc_width=nxh where processcard_id=lck  and edg_speed2=xh;                                             
                        end if;
                        select o_err;
                    else    
                        #    INSERT INTO liuchengka_output 
                        set tmp=1;
                        if nxh>3 then 
                            set    tmp=2;
                        end if;
set o_err=33;
-- select CONCAT(lastlck,',0;',tmp,',1;',gc,',2:',nxh,',0,3;',w,',4:',h,',0');
                        INSERT INTO `gmms`.`liuchengka_output`(`liuchengka`, `guige`, `state`, `gongcheng`, `maxxuhao`, `currentxuhao`, `width`, `height`, `suo`) VALUES (lastlck,NULL,tmp,gc,nxh,0,w,h,0);
                        select o_err;    
                            set o_err =7;
                        
                        if tmp=1 then 
                            set    tmp=0;
                        end if;
                        update gmms_galss_task set gc_height=tmp where processcard_id=lastlck;
                                    
                        set nxh=1;
                        set lastlck=lck;
                        set lw=w;
                        set lh=h;
                        update gmms_galss_task set gc_width=nxh where processcard_id=lck  and edg_speed2=xh;
                    
                    end if;            select o_err;
                    
                end if;
            else
                #结束
                     set o_err =8;
                if nxh<>0 then 
                    set tmp=1;
                    if nxh>3 then 
                        set    tmp=2;
                    end if;
                    if (SELECT count(*) from liuchengka_output where liuchengka=lastlck)=0 then
                        INSERT INTO `gmms`.`liuchengka_output`(`liuchengka`, `guige`, `state`, `gongcheng`, `maxxuhao`, `currentxuhao`, `width`, `height`, `suo`) VALUES (lastlck,NULL,tmp,gc,nxh,0,w,h,0);
                  end if;
                    if tmp=1 then 
                        set    tmp=0;
                    end if;
                    update gmms_galss_task set gc_height=tmp where processcard_id=lastlck;                                                           
                end if;
                
            end if;
                select o_err;
                 set o_err =9;
     end while;
     close cur;
     select o_err;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for PendulumPieceFinsh_2
-- ----------------------------
DROP PROCEDURE IF EXISTS `PendulumPieceFinsh_2`;
delimiter ;;
CREATE PROCEDURE `PendulumPieceFinsh_2`(in sendMessageHex varchar(255),in machineids BIGINT,in returnvalue varchar(255),in flag int,out messagedate varchar(255))
BEGIN
    #下片机完成存储过程
    #找到正在工作的任务进行完成
    DECLARE count1 int;
    DECLARE dates varchar(255);
    DECLARE messagedates varchar(255) DEFAULT '';
    set messagedate=messagedates;
    
    select machine_type_id,work_id into @mtid,@work_groups from gmms_machine where id=machineids;
    
    
    select count(*),galss_id,pendulum_piece,grouporder,furnace into @counts,@galssid,@pendulum_piece,@grouporder,@furnace from gmms_galss_task_2 gt  where gt.groups=@work_groups and  gt.work_state='正在工作' and work_procedure='钢化前摆片' and gt.orders is not null ORDER BY gt.orders limit 0,1;
    #原句
--     select count(*),galss_id,pendulum_piece,grouporder,furnace into @counts,@galssid,@pendulum_piece,@grouporder,@furnace from gmms_galss_task_2 gt  where  gt.work_state='正在工作' and work_procedure='钢化前摆片' and gt.orders is not null ORDER BY gt.orders limit 0,1;
    
    
    
    select @counts;
    if machineids=40 or machineids=65 then
        #任务完成
        if flag=1 then
            if @counts>0 then
              if @pendulum_piece=1 then
                  update gmms_galss_task_2 set work_state='已完成' where galss_id=@galssid and work_procedure='钢化前摆片' and work_state!='破损' and groups=@work_groups;
              elseif @pendulum_piece=2 then
                  update gmms_galss_task_2 set work_state='等待中',work_procedure='钢化' where grouporder=@grouporder and furnace=@furnace and work_procedure='钢化前摆片' and work_state!='破损' and groups=@work_groups;
              elseif @pendulum_piece=3 then
              
                    update gmms_galss_task_2 set work_state='正在工作',work_procedure='钢化' where  furnace=@furnace and (work_procedure='钢化前摆片' or work_procedure='钢化') and work_state!='破损' and groups=@work_groups;
                 
                    call message(returnvalue,'0014',@date);
                    set messagedate=@date;
                end if;            
            else
                call message(returnvalue,'0014',@date);
                set messagedate=@date;
            end if;
        #任务未完成
        elseif flag=2 then
        
            if @counts>0 then
            
                update gmms_galss_task_2 set work_state='等待中' where galss_id=@galssid and work_procedure='钢化前摆片' and groups=@work_groups;
                call message(returnvalue,'0014',@date);
                set messagedate=@date;
        
            end if;
            #任务破损
        elseif flag=3 then
        
            if @counts>0 then
            
                update gmms_galss_task_2 set work_state='破损' where galss_id=@galssid and work_procedure='钢化前摆片' and groups=@work_groups;
                call message(returnvalue,'0014',@date);
                set messagedate=@date;
        
            end if;
        
        end if;
    elseif machineids=42 or machineids=66 then
        select count(*),grouporder,furnace into @counts2,@grouporder,@furnace from gmms_galss_task_2 gt  where  gt.work_state='正在工作' and work_procedure='钢化后摆片' and groups=@work_groups limit 0,1;
        #任务完成
        if flag=1 then
        
            if @counts2>0 then
             
                update gmms_galss_task_2 set work_state='待复合',work_procedure='钢化后复合' where grouporder=@grouporder and work_state='正在工作' and work_procedure='钢化后摆片' and groups=@work_groups;
                call message(returnvalue,'0014',@date);
                set messagedate=@date;
                insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,@work_groups,NOW(),'摆片完成','',messagedate);
            end if;
        #任务破损
        elseif flag=2 then
        
            if @counts2>0 then
            
                update gmms_galss_task_2 set work_state='已完成',work_procedure='钢化' where grouporder=@grouporder and work_state='正在工作' and work_procedure='钢化后摆片' and groups=@work_groups;
                call message(returnvalue,'0014',@date);
                set messagedate=@date;
        
            end if;
            
        elseif flag=3 then
        
            if @counts2>0 then
            
                update gmms_galss_task_2 set work_state='破损' where grouporder=@grouporder and work_state='正在工作' and work_procedure='钢化后摆片' and groups=@work_groups;
                call message(returnvalue,'0014',@date);
                set messagedate=@date;
        
            end if;
        end if;
    end if;
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for PendulumPieceSend_2
-- ----------------------------
DROP PROCEDURE IF EXISTS `PendulumPieceSend_2`;
delimiter ;;
CREATE PROCEDURE `PendulumPieceSend_2`(in machineids BIGINT,in returnvalue varchar(255),in rankid BIGINT,out messagedate varchar(255))
BEGIN
    #下片机发送任务存储过程
    #找到等待中的任务,把下片位置,宽度,高度,厚度发送给plc
    DECLARE s int DEFAULT 0;
    DECLARE dates1 varchar(255) DEFAULT '';
    DECLARE dates varchar(255);
    DECLARE isjing varchar(255) DEFAULT null;
    DECLARE messagedates varchar(255) DEFAULT '';
    set messagedate=messagedates;
    
    select machine_type_id,work_id,state into @mtid,@work_groups,isjing from gmms_machine where id=machineids;
    
    set @furnace2=null;
    select count(*),galss_id,pendulum_piece,distance,grouporder,furnace,edg_width,edg_height,angle
    into @counts,@galssid,@pendulum_piece,@distance,@grouporder,@furnace,@width,@height,@angle from gmms_galss_task_2 gt  
    where  gt.work_state='等待中' and gt.work_procedure='钢化前摆片' and gt.groups=@work_groups and gt.orders is not null and gt.galss_id=rankid ORDER BY gt.orders limit 1;
    
    select galss_id,pendulum_piece,distance,grouporder,furnace 
    into @galssid2,@pendulum_piece2,@distance2,@grouporder2,@furnace2 from gmms_galss_task_2 gt  
    where  ((gt.work_state='已完成' and gt.work_procedure='钢化前摆片') or (gt.work_state='等待中' and gt.work_procedure='钢化')) 
    and gt.groups=@work_groups and gt.orders is not null ORDER BY furnace,gt.orders desc    limit 1;
    
    
    select galss_id,pendulum_piece,distance,grouporder,furnace 
    into @galssid3,@pendulum_piece3,@distance3,@grouporder3,@furnace3 from gmms_galss_task_2 gt  
    where gt.work_state='已完成' and gt.work_procedure='钢化前摆片' 
    and gt.groups=@work_groups and gt.orders is not null ORDER BY furnace,gt.orders desc limit 1;
    #select count(*) into @counts2 from gmms_galss_task_2 gt  where  ((gt.work_state='已完成' and gt.work_procedure='钢化前摆片') or (gt.work_state='等待中' and gt.work_procedure='钢化')) and gt.groups=@work_groups and gt.orders is not null ORDER BY furnace,gt.orders desc    ;
        
    
    #select count(*) into @counts3 from gmms_galss_task_2 gt  where  gt.work_state='已完成' and gt.work_procedure='钢化前摆片' and gt.groups=@work_groups and gt.orders is not null;
    
 
    select @counts;
    select @counts2;
    #判断是否有等待的任务
    if machineids=40 or machineids=65 then
    
    
    set messagedate=null;
    
    
        if @counts=1 then
            
            
          set @is_timing=true;
            
            if @pendulum_piece=3 then
              #select count(*) into @count5 from gmms_galss_task_2 where  work_procedure='钢化' and (work_state='已完成' or work_state='正在工作');
                    if isjing='正常' then
                        set @timer_name="ganghua_2";
                        set @timeinterval=16;#每一片的时间  默认22秒   15片以上25秒
                        if @work_groups=1 then
                            set @timer_name="ganghua_1";
                        end if;
                        select @timer_name;
                        call timer_ontime(@timer_name, @is_timing);
                        if @is_timing then
                            select count(*) into @t_count from gmms_galss_task_2 where groups=@work_groups and furnace=@furnace;
                            if @t_count>16 then
                                set @timeinterval=17;
                            end if;
                            set @z_time_out=@t_count*@timeinterval+40;
                            call timer_set(@timer_name,@z_time_out);
                        end if;
                    else
                        set @is_timing=false;
                    end if;        
           end if;
          select @is_timing;
            if @is_timing then
                if @furnace=@furnace2 or @furnace2 is null then
                    #上一片和当前片 属于同一炉
                    if @grouporder=@grouporder2 or @furnace2 is null or @galssid3 is null then
                        #上一片和当前片 属于同排 或此炉第一片   或摆片台无玻璃 
                        if (@pendulum_piece=3 or @pendulum_piece=2) then
                            if @work_groups=2 then
                                if (select count(*) from gmms_galss_task_2 where furnace=@furnace and grouporder=@grouporder and groups=2)>1 then
                                    #此排玻璃数量>1时   发送除了最后一片外的总长度
                                    set @distance=(select SUM(distance) from gmms_galss_task_2 
                                    where furnace=@furnace and grouporder=@grouporder and groups=2 and pendulum_piece<2);
                                else
                                    #此排玻璃数量=1时   发送最后一片-玻璃长度
                                    if @angle=0 then
                                        set @distance=@distance-@width+20;
                                    elseif @angle=1 then
                                        set @distance=@distance-@height+20;
                                    end if;
                                end if;
                            elseif @work_groups=1 then
                                if @angle=0 then
                                    set @distance=@width+20;
                                elseif @angle=1 then
                                    set @distance=@height+20;
                                end if;
                            end if;
                                                                            
                        end if;
                        update gmms_galss_task_2 set work_state='正在工作' 
                        where work_state='等待中' and work_procedure='钢化前摆片' and groups=@work_groups and galss_id=rankid order by orders limit 1;                        
                        call intTo2ByteHex10_16_4(@pendulum_piece,@pendulum_pieces);
                        call intTo2ByteHex10_16_4(@distance,@distances);
                        call intTo2ByteHex10_16_4(@galssid,@galssids);
                        set dates=CONCAT(returnvalue,'0000','00000000',@pendulum_pieces,@distances);
                        call message(dates,'000a',@date);
                        set messagedate=@date;
                        insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,@work_groups,NOW(),CONCAT('前摆片发1:',@distance),@galssid,@pendulum_pieces);
                    elseif @grouporder!=@grouporder2 and @galssid3 is not null then                        
                            #上一片和当前片 属于不同排 且摆片台上有玻璃   则进炉   4 送入  5 进炉        
                            if @work_groups=2 then
                                    set @distance=(select SUM(distance) from gmms_galss_task_2 
                                                        where furnace=@furnace and grouporder=@grouporder2 and groups=2 and pendulum_piece<2);
                                    set @pendulum_piece=4;    
                            elseif @work_groups=1 then 
                                set @distance=0;
                                set @pendulum_piece=2;
                            end if;    
                            update gmms_galss_task_2 set work_state='等待中',work_procedure='钢化' 
                            where work_state='已完成' and work_procedure='钢化前摆片' and grouporder=@grouporder2 and groups=@work_groups ;
                            call intTo2ByteHex10_16_4(@pendulum_piece,@pendulum_pieces);
                            call intTo2ByteHex10_16_4(@distance,@distances);
                            call intTo2ByteHex10_16_4(@galssid,@galssids);
                            set dates=CONCAT(returnvalue,'0000','00000000',@pendulum_pieces,@distances);
                            call message(dates,'000a',@date);
                            set messagedate=@date;
                            insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,@work_groups,NOW(),CONCAT('前摆片发2:',@distance),@galssid,@pendulum_pieces);
                    end if;
                else
                    #select furnace into @furnace3 from gmms_galss_task_2 where furnace<@furnace2 and groups=@work_groups group by furnace order by furnace desc limit 0,1;
                    if @furnace2 is not null and isjing='正常' then
                        if @work_groups=2 and @grouporder2 is not null then
                            #二线 当前片为新一炉   有上一炉玻璃未进炉
                            set @distance=(select IFNULL(SUM(distance),0) from gmms_galss_task_2 
                                                        where furnace=@furnace2 and grouporder=@grouporder2 and groups=2 and pendulum_piece<2 and work_procedure='钢化前摆片' and work_state='已完成');
                            set @pendulum_piece=5;
                        elseif @work_groups=1 then 
                            set @distance=0;
                            set @pendulum_piece=3;
                        end if;    
                        update gmms_galss_task_2 set work_state='正在工作',work_procedure='钢化' where  furnace=@furnace2 and groups=@work_groups and work_state!='破损';  
                        call intTo2ByteHex10_16_4(@pendulum_piece,@pendulum_pieces);
                        call intTo2ByteHex10_16_4(@distance,@distances);
                        call intTo2ByteHex10_16_4(@galssid,@galssids);
 
 
                        set dates=CONCAT(returnvalue,'0000','00000000',@pendulum_pieces,@distances);
                        call message(dates,'000a',@date);
                        set messagedate=@date;
                        insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,@work_groups,NOW(),CONCAT('前摆片发3:',@distance),@galssid,@pendulum_pieces);
                    end if;
                    
                end if;
        
            
        end if;
        
        end if;
    elseif  machineids=42 or machineids=66 then 
        select grouporder,furnace into @grouporder,@furnace from gmms_galss_task_2 gt 
        where  gt.work_state='已完成' and work_procedure='钢化' and groups=@work_groups  ORDER BY gt.grouporder  limit 0,1;
        select @grouporder;
        select count(*) into @count2 from gmms_galss_task_2 where grouporder=@grouporder and work_state='已完成' and work_procedure='钢化' and groups=@work_groups;
        select @count2;
        if @count2>0 then
            while s<@count2 do
            #原句:玻璃数据同行完全相反 select galss_id into @galss_id from gmms_galss_task_2 where grouporder=@grouporder and work_state='已完成' and work_procedure='钢化' and groups=@work_groups order by orders desc limit s,1;
            select galss_id into @galss_id from gmms_galss_task_2 where grouporder=@grouporder and work_state='已完成' and work_procedure='钢化' and groups=@work_groups order by orders asc limit s,1;
--             if @work_groups=2 then
--                 select galss_id into @galss_id from gmms_galss_task_2 where grouporder=@grouporder and work_state='已完成' and work_procedure='钢化' and groups=@work_groups order by orders desc limit s,1;
--             end if;
            set @maxrank=0;
            
            select max(fine_throwing) into @maxrank from gmms_galss_task_2 where furnace=@furnace and groups=@work_groups;
            update gmms_galss_task_2 set fine_throwing=@maxrank+1,slicecage_flag=@maxrank+1 where galss_id=@galss_id and grouporder=@grouporder and work_state='已完成' and work_procedure='钢化' and groups=@work_groups;
            
            select @galss_id;
            call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
            set dates1=CONCAT(dates1,@galss_ids);
            set s=s+1;
        end while;
        update gmms_galss_task_2 set work_state='正在工作',work_procedure='钢化后摆片' where grouporder=@grouporder and work_state='已完成' and work_procedure='钢化' and groups=@work_groups;
         
        select dates1;
        set dates=CONCAT(returnvalue,dates1);
        select dates;
        call message(dates,'000a',@date);
        set messagedate=@date;
        insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,@work_groups,NOW(),'摆片发送',@galss_id,messagedate);
        end if;
        
    end if;
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for PendulumPieceSend_2_copy1
-- ----------------------------
DROP PROCEDURE IF EXISTS `PendulumPieceSend_2_copy1`;
delimiter ;;
CREATE PROCEDURE `PendulumPieceSend_2_copy1`(in machineids BIGINT,in returnvalue varchar(255),in rankid BIGINT,out messagedate varchar(255))
BEGIN
    #下片机发送任务存储过程
    #找到等待中的任务,把下片位置,宽度,高度,厚度发送给plc
    DECLARE s int DEFAULT 0;
    DECLARE dates1 varchar(255) DEFAULT '';
    DECLARE dates varchar(255);
    DECLARE messagedates varchar(255) DEFAULT '';
    set messagedate=messagedates;
    
    select machine_type_id,work_id into @mtid,@work_groups from gmms_machine where id=machineids;
    
    set @furnace2=null;
    select count(*),galss_id,pendulum_piece,distance,grouporder,furnace into @counts,@galssid,@pendulum_piece,@distance,@grouporder,@furnace from gmms_galss_task_2 gt  where  gt.work_state='等待中' and gt.work_procedure='钢化前摆片' and gt.groups=@work_groups and gt.orders is not null and gt.galss_id=rankid ORDER BY gt.orders limit 1;
    
    select galss_id,pendulum_piece,distance,grouporder,furnace 
    into @galssid2,@pendulum_piece2,@distance2,@grouporder2,@furnace2 from gmms_galss_task_2 gt  
    where  ((gt.work_state='已完成' and gt.work_procedure='钢化前摆片') or (gt.work_state='等待中' and gt.work_procedure='钢化')) 
    and gt.groups=@work_groups and gt.orders is not null ORDER BY furnace,gt.orders desc    limit 1;
    
    
    select galss_id,pendulum_piece,distance,grouporder,furnace 
    into @galssid3,@pendulum_piece3,@distance3,@grouporder3,@furnace3 from gmms_galss_task_2 gt  
    where gt.work_state='已完成' and gt.work_procedure='钢化前摆片' 
    and gt.groups=@work_groups and gt.orders is not null ORDER BY furnace,gt.orders desc limit 1;
    #select count(*) into @counts2 from gmms_galss_task_2 gt  where  ((gt.work_state='已完成' and gt.work_procedure='钢化前摆片') or (gt.work_state='等待中' and gt.work_procedure='钢化')) and gt.groups=@work_groups and gt.orders is not null ORDER BY furnace,gt.orders desc    ;
        
    
    #select count(*) into @counts3 from gmms_galss_task_2 gt  where  gt.work_state='已完成' and gt.work_procedure='钢化前摆片' and gt.groups=@work_groups and gt.orders is not null;
    
 
    select @counts;
    select @counts2;
    #判断是否有等待的任务
    if machineids=40 or machineids=65 then
    
    
    set messagedate=null;
    
    
        if @counts=1 then
            
            
          set @is_timing=true;
            
            if @pendulum_piece=3 then
              #select count(*) into @count5 from gmms_galss_task_2 where  work_procedure='钢化' and (work_state='已完成' or work_state='正在工作');
                    set @timer_name="ganghua_2";
                    set @timeinterval=16;#每一片的时间  默认22秒   15片以上25秒
                    if @work_groups=1 then
                        set @timer_name="ganghua_1";
                    end if;
                    
                    select @timer_name;
                    
                    call timer_ontime(@timer_name, @is_timing);
                    if @is_timing then
                            select count(*) into @t_count from gmms_galss_task_2 where groups=@work_groups and furnace=@furnace;
                            if @t_count>16 then
                                set @timeinterval=17;
                            end if;
                            set @z_time_out=@t_count*@timeinterval+40;
                            call timer_set(@timer_name,@z_time_out);
                    end if;
                     
--                      
--                     #原程序
--                   set @timer_name="ganghua_1";                     
--                     select @timer_name;
--                     
--                     call timer_ontime(@timer_name, @is_timing);
--                      if @is_timing then 
--                                  select count(*) into @t_count from gmms_galss_task_2 where furnace=@furnace;
--                                  set @z_time_out=@t_count*22+40;
--                                     call timer_set(@timer_name,@z_time_out);
--                      end if;
           end if;
          select @is_timing;
            if @is_timing then
 
            
                if @furnace=@furnace2 or @furnace2 is null then
                    #上一片和当前片 属于同一炉
                    if @grouporder=@grouporder2 or @furnace2 is null or @galssid3 is null then
                        #上一片和当前片 属于同排 或此炉第一片   或摆片台无玻璃  
                        update gmms_galss_task_2 set work_state='正在工作' where work_state='等待中' and work_procedure='钢化前摆片' and groups=@work_groups and galss_id=rankid order by orders limit 1;                        
                        call intTo2ByteHex10_16_4(@pendulum_piece,@pendulum_pieces);
                        call intTo2ByteHex10_16_4(@distance,@distances);
                        call intTo2ByteHex10_16_4(@galssid,@galssids);
                        set dates=CONCAT(returnvalue,'0000','00000000',@pendulum_pieces,@distances);
                        call message(dates,'000a',@date);
                        set messagedate=@date;
                        insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,@work_groups,NOW(),'前摆片发1',@galssid,@pendulum_pieces);
                    elseif @grouporder!=@grouporder2 and @galssid3 is not null then    
                            #上一片和当前片 属于不同排 且摆片台上有玻璃   则进炉
                            update gmms_galss_task_2 set work_state='等待中',work_procedure='钢化' where work_state='已完成' and work_procedure='钢化前摆片' and grouporder=@grouporder2 and groups=@work_groups ;
                            call intTo2ByteHex10_16_4(@pendulum_piece,@pendulum_pieces);
                            call intTo2ByteHex10_16_4(@distance,@distances);
                            call intTo2ByteHex10_16_4(@galssid,@galssids);
                            set dates=CONCAT(returnvalue,'0000','00000000','0002','00000000');
                            call message(dates,'000a',@date);
                            set messagedate=@date;
                            insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,@work_groups,NOW(),'前摆片发2',@galssid,@pendulum_pieces);
                    end if;
                else
                    #select furnace into @furnace3 from gmms_galss_task_2 where furnace<@furnace2 and groups=@work_groups group by furnace order by furnace desc limit 0,1;
                    if @furnace2 is not null then
                        update gmms_galss_task_2 set work_state='正在工作',work_procedure='钢化' where  furnace=@furnace2 and groups=@work_groups and work_state!='破损';  
                        call intTo2ByteHex10_16_4(@pendulum_piece,@pendulum_pieces);
                        call intTo2ByteHex10_16_4(@distance,@distances);
                        call intTo2ByteHex10_16_4(@galssid,@galssids);
 
 
                        set dates=CONCAT(returnvalue,'0000','00000000','0003','00000000');
                        call message(dates,'000a',@date);
                        set messagedate=@date;
                        insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,@work_groups,NOW(),'前摆片发送3',@galssid,@pendulum_pieces);
                    end if;
                    
                end if;
        
            
        end if;
        
        end if;
    elseif  machineids=42 or machineids=66 then 
        select grouporder,furnace into @grouporder,@furnace from gmms_galss_task_2 gt 
        where  gt.work_state='已完成' and work_procedure='钢化' and groups=@work_groups  ORDER BY gt.grouporder  limit 0,1;
        select @grouporder;
        select count(*) into @count2 from gmms_galss_task_2 where grouporder=@grouporder and work_state='已完成' and work_procedure='钢化' and groups=@work_groups;
        select @count2;
        if @count2>0 then
            while s<@count2 do
            #原句:玻璃数据同行完全相反 select galss_id into @galss_id from gmms_galss_task_2 where grouporder=@grouporder and work_state='已完成' and work_procedure='钢化' and groups=@work_groups order by orders desc limit s,1;
            select galss_id into @galss_id from gmms_galss_task_2 where grouporder=@grouporder and work_state='已完成' and work_procedure='钢化' and groups=@work_groups order by orders asc limit s,1;
            if @work_groups=2 then
                select galss_id into @galss_id from gmms_galss_task_2 where grouporder=@grouporder and work_state='已完成' and work_procedure='钢化' and groups=@work_groups order by orders desc limit s,1;
            end if;
            set @maxrank=0;
            
            select max(fine_throwing) into @maxrank from gmms_galss_task_2 where furnace=@furnace and groups=@work_groups;
            update gmms_galss_task_2 set fine_throwing=@maxrank+1,slicecage_flag=@maxrank+1 where galss_id=@galss_id and grouporder=@grouporder and work_state='已完成' and work_procedure='钢化' and groups=@work_groups;
            
            select @galss_id;
            call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
            set dates1=CONCAT(dates1,@galss_ids);
            set s=s+1;
        end while;
        update gmms_galss_task_2 set work_state='正在工作',work_procedure='钢化后摆片' where grouporder=@grouporder and work_state='已完成' and work_procedure='钢化' and groups=@work_groups;
         
        select dates1;
        set dates=CONCAT(returnvalue,dates1);
        select dates;
        call message(dates,'000a',@date);
        set messagedate=@date;
        insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,@work_groups,NOW(),'摆片发送',@galss_id,messagedate);
        end if;
        
    end if;
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for PendulumPiece_2
-- ----------------------------
DROP PROCEDURE IF EXISTS `PendulumPiece_2`;
delimiter ;;
CREATE PROCEDURE `PendulumPiece_2`(in sendMessageHex varchar(255),in machineids BIGINT,out messagedate varchar(255))
BEGIN
    #下片机存储过程
    #找到当前机器标志位
    #查询机器逻辑表中对应的逻辑进行对应的步骤
    DECLARE machinedisposeids int DEFAULT 0;
    DECLARE ids int ;
    DECLARE plcfindid varchar(255);
    DECLARE dates varchar(255);
    DECLARE plcid varchar(255);
    DECLARE findplc varchar(255);
    DECLARE findmes varchar(255);
    DECLARE taskplc varchar(255);
    DECLARE taskmes varchar(255);
    DECLARE finsh_rankid BIGINT;
    DECLARE send_rankid BIGINT;
    DECLARE rankids varchar(255);
    DECLARE falgs varchar(255);
    DECLARE posunmes varchar(255);
    DECLARE messagedates varchar(255) DEFAULT '';
    set messagedate=messagedates;
    
    
    select machine_type_id,work_id into @mtid,@remarks from gmms_machine where id=machineids;
    set ids = cast(@remarks as UNSIGNED INTEGER);
    
    select mf.flag into @完成标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='完成字';
    
    select mf.flag into @请求标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='请求字';
    
    select mf.flag into @发送标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='发送字';
    
    select mf.flag into @完成确认标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='完成确认字';
    
    set finsh_rankid = cast(@完成标志位 as UNSIGNED INTEGER)+1;
    set send_rankid = cast(@请求标志位 as UNSIGNED INTEGER)+1;
    
    set findplc = substring(sendMessageHex,(cast(@完成标志位 as UNSIGNED INTEGER)*4)+19,4);
    set taskplc = substring(sendMessageHex,(cast(@请求标志位 as UNSIGNED INTEGER)*4)+19,4);
    set taskmes = substring(sendMessageHex,(cast(@发送标志位 as UNSIGNED INTEGER)*4)+19,4);
    set findmes = substring(sendMessageHex,(cast(@完成确认标志位 as UNSIGNED INTEGER)*4)+19,4);
    set falgs = substring(sendMessageHex,(cast(3 as UNSIGNED INTEGER)*4)+19,4);
    
    select taskplc;
    select taskmes;
    select findplc;
    select findmes;
    select plcfindid;
    
    if falgs='0001' then
        select count(*) into @counts from gmms_galss_task_2 where work_state='已完成' and work_procedure='钢化' and groups=@remarks ;
        select count(*) into @counts5 from gmms_galss_task_2 where work_state='正在工作' and work_procedure='钢化后摆片' and groups=@remarks ;
        if @counts=0 and @counts5=0 then
            select furnace into @furnace from gmms_galss_task_2 where work_state='正在工作' and work_procedure='钢化' and groups=@remarks  order by furnace limit 0,1;
            update gmms_galss_task_2 set  work_state='已完成'  where  work_state='正在工作' and work_procedure='钢化' and groups=@remarks  and furnace=@furnace;
        end if;
        
    end if;
    
    set rankids = conv(substring(sendMessageHex,(cast(send_rankid as UNSIGNED INTEGER)*4)+19,4),16,10);
    select rankids;
 
#完成逻辑查询
    select count(*),md.id into @完成数量,@完成逻辑编号 from gmms_machine_dispose md join gmms_machine_type mt on md.machine_type_id=mt.id where md.machine_type_id=@mtid  and md.plc_font_type='完成字' and md.mes_font_type='完成确认字' and md.plc_font_value=findplc and md.mes_font_value=findmes;
    
    #请求逻辑查询
    select count(*),md.id into @请求数量,@请求逻辑编号 from gmms_machine_dispose md join gmms_machine_type mt on md.machine_type_id=mt.id where md.machine_type_id=@mtid  and md.plc_font_type='请求字' and md.mes_font_type='发送字' and md.plc_font_value=taskplc and md.mes_font_value=taskmes;
    
    
    #判断逻辑是否存在
    if @完成数量=1 or @请求数量=1  then
        #判断请求逻辑是否为空
        if @请求逻辑编号!=0 then
            set machinedisposeids=@请求逻辑编号;
            #判断完成逻辑是否为空
        elseif @完成逻辑编号!=0 then
            set machinedisposeids=@完成逻辑编号;
        end if;
        
        #查询当前执行逻辑进行判断
        select logic,return_value into @ExecutionLogic,@returnvalue from gmms_machine_dispose where id=machinedisposeids;
        select @ExecutionLogic;
        select @returnvalue;
        if @ExecutionLogic='任务完成' then
                call     PendulumPieceFinsh_2(sendMessageHex,machineids,@returnvalue,1,@messagedate);
                set messagedate=@messagedate;
        elseif @ExecutionLogic='任务失败' then
                call     PendulumPieceFinsh_2(sendMessageHex,machineids,@returnvalue,2,@messagedate);
                set messagedate=@messagedate;    
        elseif @ExecutionLogic='玻璃破损' then
                call     PendulumPieceFinsh_2(sendMessageHex,machineids,@returnvalue,3,@messagedate);
                set messagedate=@messagedate;        
         elseif @ExecutionLogic='完成清空' then    
                set dates=CONCAT(@returnvalue,"0000");    
                call message(dates,'0014',@date);
                set messagedate=@date;
        elseif @ExecutionLogic='任务请求' then
                if machineids=40 then
                    insert names5 (name2) values(now());
                end if;
                call PendulumPieceSend_2(machineids,@returnvalue,rankids,@messagedate);
                set messagedate=@messagedate;
                select 1;
         elseif @ExecutionLogic='任务清空' then
                set dates=CONCAT(@returnvalue,"000000000000000000000000000000000000");
                call message(dates,'000a',@date);
                set messagedate=@date;
        end if;
 
    end if;
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for print_log
-- ----------------------------
DROP PROCEDURE IF EXISTS `print_log`;
delimiter ;;
CREATE PROCEDURE `print_log`(in _liuchengka varchar(50),in _line int,out result int,out msg varchar(255))
BEGIN
    #Routine body goes here...
    set msg="未知错误";
    set @a=null;
    set @z_count=null;
    select sum(shuliang),sum(mianji),liuchengkahaoceng into @a,@b,@c from  gmms_liuchengka_buffer where liuchengkahaoceng=_liuchengka  group by liuchengkahaoceng;
     if @a is null then 
                 set msg="没有该流程卡信息";
 else
                    select count(*) into @z_count from gmms_print_log where liuchengka=_liuchengka;
        if @z_count then 
                set msg="该流程卡已经打印过,继续打印不会再计入生产日报";
        else
                        insert into gmms_print_log (
            liuchengka,
            time_stamp,
            piece_count,
            piece_area,
            line)
            value (
                _liuchengka,
                now(),
                @a,
                @b,
                _line
            );
            set msg="ok";
 end if;        
end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for proc_ePiercedsByGlassIdSave
-- ----------------------------
DROP PROCEDURE IF EXISTS `proc_ePiercedsByGlassIdSave`;
delimiter ;;
CREATE PROCEDURE `proc_ePiercedsByGlassIdSave`(in gId BIGINT,in cpId int,in cpXh int,in gy varchar(50),in pline varchar(50),out back_Num int,out back_Msg varchar(255))
BEGIN
 
    #输入参数:gId-玻璃ID,cpId-次破类型Id,cpXh-次破原因序号,gy-工艺,pline-生产线
    #输出参数:back_Num 数值类型参数,back_Msg 字符串类型参数
 
    #设置玻璃破损
    Declare current_banzu varchar(50);#当前班组
    Declare cipo_leixing varchar(50);#次破类型
    Declare cipo_yuanyin varchar(50);#次破原因
    Declare shuliang varchar(50);#数量
 
    if gId is null or gId = '' then
            set back_Num = 3;
            set back_Msg="玻璃ID 为空!";
    else
            #判断当前玻璃是否已经报破损
            select count(*) into shuliang from e_pierceds where glass_id = gId;
            if shuliang = 1 then
                    set back_Num = 0;
                    set back_Msg = "当前玻璃已经报过破损";
            else
                    #查询当前班组
                    select banzu into current_banzu from gmms_user_current where gongyi = gy and chanxian = pline limit 0,1;
                    select gy;
                    select current_banzu;
                    
                    #查询破损类型及原因
                    select cipoleixing into cipo_leixing from cipoleixing where id = cpId;
                    select cipo_leixing;
                    
                    select cipoyuanyin into cipo_yuanyin from cipoyuanyin where xuhao = cpXh;
                    select cipo_yuanyin;
                        if gy = '钢化' then        
                            #修改玻璃状态
                            update gmms_galss_task_2 set work_state = '破损' where Id = gId;
                            #插入破损数据
                            INSERT INTO e_pierceds(processcard_id, type_num, pieces, pierced_type, pierced_cause, is_report, glass_id, create_time, process, line, gc_number, cs_number, team_name) 
                            select gs.processcard_id,gs.edg_speed2,1,cipo_leixing,cipo_yuanyin,0,gId,NOW(),'钢化',gs.groups,gs.engineering_id,0,current_banzu from gmms_galss_task_2 as gs where gs.id=gid;
                        elseif gy='中空' then
                            #修改玻璃状态
                            update gmms_galss_task_shelf set work_state = '破损' where Id = gId;
                            #插入破损数据
                            INSERT INTO e_pierceds(processcard_id, type_num, pieces, pierced_type, pierced_cause, is_report, glass_id, create_time, process, line, gc_number, cs_number, team_name) 
                            select gs.processcard_id,gs.edg_speed2,1,cipo_leixing,cipo_yuanyin,0,gId,NOW(),'中空',gs.groupsss,gs.engineering_id,0,current_banzu from gmms_galss_task_shelf as gs where gs.id=gid;
                        elseif gy = '仓储' then
                            #修改玻璃状态
                            update gmms_galss_task_shelf set work_state = '破损' where Id = gId;
                            select team_name into current_banzu from e_record_tempering where glass_id = gId limit 0,1;
                            #插入破损数据
                            INSERT INTO e_pierceds(processcard_id, type_num, pieces, pierced_type, pierced_cause, is_report, glass_id, create_time, process, line, gc_number, cs_number, team_name) 
                            select gs.processcard_id,gs.edg_speed2,1,cipo_leixing,cipo_yuanyin,0,gId,NOW(),'中空',gs.groupsss,gs.engineering_id,0,current_banzu from gmms_galss_task_shelf as gs where gs.id=gid;
                        elseif gy = '磨边' then
                            #插入破损数据
                            INSERT INTO e_pierceds(processcard_id, type_num, pieces, pierced_type, pierced_cause, is_report, glass_id, create_time, process, line, gc_number, cs_number, team_name) 
                            select gs.processcard_id,gs.edg_speed2,1,cipo_leixing,cipo_yuanyin,0,gId,NOW(),'磨边',pline,gs.engineering_id,0,current_banzu from gmms_galss_task_buffer as gs
                            left join e_pierceds as ep on gs.id=ep.glass_id    where gs.id=gId and ep.glass_id is null;
                        end if;
 
                select count(*) into shuliang from e_pierceds where glass_id = gId;
                if shuliang = 1 then
                    set back_Num = 1;
                    set back_Msg="成功";
                else
                    set back_Num = 2;
                    set back_Msg = "玻璃破损信息插入失败";
                END If;
        END if;
    end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for proc_eRecordStockByGlassIdSave
-- ----------------------------
DROP PROCEDURE IF EXISTS `proc_eRecordStockByGlassIdSave`;
delimiter ;;
CREATE PROCEDURE `proc_eRecordStockByGlassIdSave`(in lckh varchar(50),in pline varchar(50),out back_Num int,out back_Msg varchar(255))
BEGIN
 
    #输入参数:lckh-流程卡号,pline-生产产线
    #输出参数:back_Num 数值类型参数,back_Msg 字符串类型参数
 
    #设置玻璃破损
    Declare current_banzu varchar(50);#当前班组
    Declare GID varchar(20);
    Declare zNum int;#总数
    Declare fNum int  default 0;#循环数
    Declare drid_ int  default 0;#循环数
        Declare sNum int  default 0;#循环数
        Declare minarea_ double  default 0;#最小面积
    #定义游标
    Declare lck_cursor cursor for select id from gmms_galss_task_buffer where  processcard_id = lckh and id not in (select glass_id from e_pierceds where process ='磨边' and line = pline );#当前流程卡未破损的玻璃下片
    select lckh;
    select count(1) into zNum from gmms_galss_task_buffer where  processcard_id = lckh and id not in (select glass_id from e_pierceds where process ='磨边' and line = pline );
    select zNum;
    if zNum =0 then 
        set back_num = 0;
        set back_Msg = "没有当前流程卡完成数据";
    else
        if lckh is null or lckh = '' then
            set back_Num = 3;
            set back_Msg="流程卡号 为空";
        else
            select banzu into current_banzu from gmms_user_current where gongyi = '磨边' and chanxian = pline;
            select current_banzu;
            if current_banzu is null or current_banzu = '' then 
                set back_Num = 2;
                set back_Msg= concat("磨边",pline,"线班组为空");
            else
                open lck_cursor;
                    REPEAT
                    FETCH lck_cursor INTO GID;
                            set fNum = fNum+1;
                            select count(1) into sNum from e_record_stock where glass_id = gid;
                            if sNum = 0 then
                                INSERT INTO e_record_stock(processcard_id, glass_id, width, height,thinkess, color, sequence, create_time, line, team_name, is_report, rank,type_num) 
                                select gs.processcard_id,gs.id,gs.edg_width,gs.edg_height,gs.thickness,gs.color,gs.drop_frame,NOW(),pline,current_banzu,0,'',gs.edg_speed2 from gmms_galss_task_buffer as gs
                                left join e_record_stock as es on gs.id=es.glass_id 
                                where gs.id=gid and es.glass_id is null;
                            end if;
                            #select    fNum;
                    #退出重复条件
                    UNTIL fNum=zNum
                    END REPEAT;
                        set back_Num = 1;
                        set back_Msg= "成功";
                close lck_cursor;
            end if;
            select min(edg_width*edg_height)/1000000 into minarea_ from gmms_galss_task_buffer where processcard_id=lckh GROUP BY processcard_id;
            
            update gmms_liuchengka set minArea=minarea_,isgang="冷加工下片完成"                     
            where liuchengka=lckh and gy_gang=1  and Occupied=0 and isgang='';
            
            select id into drid_ from gmms_drop_frame where processcard_id=lckh limit 1;
            if pline='1' and drid_>12 then
                update gmms_drop_frame as df left join gmms_machine as gm on df.groups=gm.work_id 
                set df.state='空闲',df.drop_frame=null,df.processcard_count=0,df.processcard_id=null,df.engineering_id=null,df.finsh_count=0,gm.remarks=df.id
                where gm.id=75 and processcard_id=lckh;
            else
                update gmms_drop_frame as df left join gmms_machine as gm on df.groups=gm.work_id 
                set df.state='空闲',df.drop_frame=null,df.processcard_count=0,df.processcard_id=null,df.engineering_id=null,df.finsh_count=0,gm.remarks=df.id
                where (gm.id=5 or gm.id=22 or gm.id=17) and processcard_id=lckh;
            end if;
        end if;
    end if;
    
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for proc_eRecordStockByLineUpdata
-- ----------------------------
DROP PROCEDURE IF EXISTS `proc_eRecordStockByLineUpdata`;
delimiter ;;
CREATE PROCEDURE `proc_eRecordStockByLineUpdata`(in pline varchar(50),out back_Num int,out back_Msg varchar(255))
BEGIN
 
    #输入参数:pline-生产产线
    #输出参数:back_Num 数值类型参数,back_Msg 字符串类型参数
    DECLARE Dbanzu varchar(255) DEFAULT '';#当前班组
    #select banzu into current_banzu from gmms_user_current where gongyi = '磨边' and chanxian = pline;
--     update (select processcard_id from e_record_stock where is_report = 0 and line = pline group by processcard_id) as lck 
--     left join gmms_liuchengka as lk on lck.processcard_id=lk.liuchengka set lk.isgang="冷加工下片完成" where lk.gy_gang=1 and lk.Occupied=0;
    
    update e_record_stock set is_report = 1,report_time = now() where is_report = 0 and line = pline;
    
    
    update e_pierceds set is_report=1,report_time = now() where is_report = 0 and line = pline and process = '磨边';
    select banzu into Dbanzu from gmms_user_current where chanxian=pline and gongyi='磨边';
    
    update Y_Edg_Statistics set banzu=Dbanzu,report_time=NOW() where banzu is null and Line = pline;
--     update Y_Edg_Statistics AS ES LEFT JOIN (select * from e_record_stock where line=pline order by create_time desc limit 4500) AS ERS on ERS.glass_id=ES.Glassid
--     set ES.banzu=ERS.team_name,ES.report_time=ERS.report_time
--     where ERS.glass_id is not null and ES.banzu is null and ES.Line = pline;
    
--     update Y_Edg_Statistics AS ES LEFT JOIN e_pierceds AS ep on ep.glass_id=ES.Glassid
--     set ES.banzu=ep.team_name
--     where ep.is_report = 0 and ES.Line = 1 and ep.process = '磨边';
    #update gmms_cutmanage set BgTime=now() where BgTime is null and groups=pline;
    set back_Num = 1;
    set back_Msg = "成功";
    
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for read_event
-- ----------------------------
DROP PROCEDURE IF EXISTS `read_event`;
delimiter ;;
CREATE PROCEDURE `read_event`(in evt varchar(50),IN msg varchar(255),IN mid int,IN oldoffset int,IN newmsg int,in iswrite int)
BEGIN
  SET @a:=1;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for record_event
-- ----------------------------
DROP PROCEDURE IF EXISTS `record_event`;
delimiter ;;
CREATE PROCEDURE `record_event`(in evt varchar(50),in evtid int,IN msg varchar(255),IN mid int,IN oldoffset int,IN msgoffset int,in iswrite int)
BEGIN
        DECLARE _end int;
        DECLARE flag int;
        DECLARE _i int;
     
        SET flag:=0;
        SET oldoffset:=19+oldoffset*4;
        if iswrite then 
                /*
                set @addr:=substring(msg,11,4);
                SELECT CONV(@addr,16,10);
              if CONV(@addr,16,10)<>msgoffset then 
            
                set flag:=100;
              else 
                 SET    msgoffset:=(msgoffset-CONV(@addr,16,10))*4+27;      
                end if;
                */
                SET    msgoffset:=msgoffset*4+27;   
        
         
        else
         SET    msgoffset:=msgoffset*4+19;
        end if;
 
    #Routine body goes here...
        SET @lastmsg=null;
        SELECT message into @lastmsg from gmms_machine_message where  machine_id=mid;
     
      if @lastmsg is not null and flag=0 then
                SET @str1:=substring(@lastmsg,oldoffset,4);
                SET @str2:=substring(msg,msgoffset,4);
        
                if @str1<>@str2 then
                            
                          if @str1='0000' and flag=0 then 
                               set flag:=1;
                            end if;
                            if @str2='0000' and flag=0 then 
                                set flag:=2;
                            end if;
                            if flag=0 then 
                                SET flag:=3;
                            end if;
    /*
                else 
                
                       if @str1<>'0000' then 
                        SET @id=null;
                        SELECT id into @id from event_tab where machineid=mid and eventid=evtid;
                            if @id is not null then 
                               UPDATE event_tab SET invoke=invoke+1 where id=@id;
                            end if;
                     
                     end if;
                     */
                end if;
        end if;
    
if flag=1 then 
    INSERT INTO event_tab (
time_stamp,
eventname,
eventid,
machineid,
oldmsg,
newmsg,
flag,
invoke,
iswrite
)    VALUES
(
    now(),
    evt,
    evtid,
    mid,
    
    @lastmsg,
    msg,
    flag,
    1,
    iswrite
);
end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for Reset_Debug
-- ----------------------------
DROP PROCEDURE IF EXISTS `Reset_Debug`;
delimiter ;;
CREATE PROCEDURE `Reset_Debug`()
BEGIN
    #清空理片笼视图存储过程
    UPDATE gmms_slicecage SET State='空闲',COUNT=0 ,TYPE_ID=NULL ;
    UPDATE gmms_galss_task SET work_state='待识别', work_procedure='测量',work_procedure_number=100,finsh_time=null,stop_position=null,
    slicecage_rank=null,rank=0,out_rank=0;
    UPDATE gmms_drop_frame SET state='空架',engineering_id=null,drop_frame=null,processcard_id=null;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for RobotHandFinsh_2
-- ----------------------------
DROP PROCEDURE IF EXISTS `RobotHandFinsh_2`;
delimiter ;;
CREATE PROCEDURE `RobotHandFinsh_2`(in sendMessageHex varchar(255),in machineids BIGINT,in returnvalue varchar(255),in flag int,out messagedate varchar(255))
BEGIN
    #下片机完成存储过程
    #找到正在工作的任务进行完成
    DECLARE count1 int;
    DECLARE dates varchar(255);
    DECLARE messagedates varchar(255) DEFAULT '';
    
    
    DECLARE y int DEFAULT 0;
    DECLARE processcardid2 varchar(255);
    set messagedate=messagedates;
    set @finshcount=null;
    set @processcard_id=null;
    select machine_type_id,work_id,remarks into @mtid,@remarks,@flag1 from gmms_machine where id=machineids;
    
    
    #select @counts;
    #钢化前上片机器人
    if machineids=38 or machineids=63 then
        #任务完成
        select galss_id,dr.id into @galssid,@dropframeid from gmms_galss_task_2 gt INNER JOIN gmms_drop_frame_2 dr on gt.processcard_id=dr.processcard_id and gt.groups=dr.groups where work_state='正在工作' and work_procedure='钢化上片' and gt.groups=@remarks  limit 0,1;
        if flag=1 then
        
            if @galssid>0 then
            #select @galssid;
            #select @remarks;
                update gmms_galss_task_2 set work_state='正在工作',work_procedure='钢化前复合' where galss_id=@galssid and groups=@remarks;
                update gmms_drop_frame_2 set gmms_drop_frame_2.surplus_count=gmms_drop_frame_2.surplus_count-1 where gmms_drop_frame_2.id=@dropframeid;
                set messagedate='';
                if false then 
                    call `Robot_gangqian_finish_ex`(machineids, messagedate);           
                end if;
                if messagedate is null or messagedate='' then 
                   call message(returnvalue,'0014',@date);
                   set messagedate=@date;        
               end if;        
            end if;
        #任务未完成
        elseif flag=2 then        
            if @galssid>0 then            
                update gmms_galss_task_2 set work_state='已优化' where galss_id=@galssid and groups=@remarks;                    
            end if;
            call message(returnvalue,'0014',@date);
            set messagedate=@date;
        elseif flag=3 then        
            if @galssid>0 then        
                update gmms_galss_task_2 set work_state='破损' where galss_id=@galssid and groups=@remarks;
                update gmms_drop_frame_2 set surplus_count=surplus_count-1 where id=@dropframeid;
                call message(returnvalue,'0014',@date);
                set messagedate=@date;    
            end if;    
        end if;
        #查找此架是否已上完片
        update gmms_drop_frame_2 set surplus_count=0,state='空闲',processcard_id=null,processcard_count=0 
        where processcard_id is not null and processcard_count>0 and surplus_count=0 and (select count(1) from gmms_galss_task_2 
         where gmms_drop_frame_2.processcard_id=gmms_galss_task_2.processcard_id and (work_procedure='钢化上片' and work_state!='破损'))=0;
--          update gmms_drop_frame_2 set surplus_count=0,state='空闲',processcard_id=null,processcard_count=0 
--          where id=@dropframeid and (select count(1) from gmms_galss_task_2 
--          where gmms_drop_frame_2.processcard_id=gmms_galss_task_2.processcard_id and (work_procedure='钢化上片' and work_state!='破损'))=0;
    #中空理片笼上片机    
    elseif machineids=47 then
        call y_RobotHollowSlicecageFinsh(machineids,returnvalue,flag,dates);
        set messagedate=dates;
    elseif machineids=44 or machineids=68 then
        #钢化后机器人
        call y_RobotTemperingAfterFinsh(flag,machineids,returnvalue,dates);
        set messagedate=dates;    
    elseif machineids=52 or machineids=71 or machineids=73  then
        #中空机器人 
        call y_RobotHollowFinsh(flag,machineids,returnvalue,dates);
        set messagedate=dates;
    end if;
    
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for RobotHandSend_2
-- ----------------------------
DROP PROCEDURE IF EXISTS `RobotHandSend_2`;
delimiter ;;
CREATE PROCEDURE `RobotHandSend_2`(in rankid varchar(255),in machineids BIGINT,in returnvalue varchar(255),out messagedate varchar(255))
BEGIN
    #下片机发送任务存储过程
    #找到等待中的任务,把下片位置,宽度,高度,厚度发送给plc
        DECLARE s int DEFAULT 0;
    DECLARE finshcount1 int;
    
    
    DECLARE y int DEFAULT 0;
    DECLARE j int DEFAULT 0;
    DECLARE processcardid2 varchar(255);
    
    DECLARE dates varchar(255);
    DECLARE noodles1 varchar(255);
    DECLARE finshcount int;
    DECLARE messagedates varchar(255) DEFAULT '';
    set messagedate=messagedates;
    
        select machine_type_id,work_id,remarks into @mtid,@remarks,@flag1 from gmms_machine where id=machineids;
 
    
    
    
    /*
    select @counts;
    select @galssid;
    #判断是否有等待的任务
    select @loadfalg;
    */
    
    #select @remarks;
    #select machineids;
    if machineids=38 or machineids=63 then
    
    
        select count(*) into @counts from gmms_galss_task_2 gt INNER JOIN gmms_drop_frame_2 dr on gt.processcard_id=dr.processcard_id where dr.flag=1 and gt.work_state='已优化' and work_procedure='钢化上片' and gt.groups=@remarks and gt.orders is not null ;
        #select @counts;
        select count(*) into @counts3 from gmms_galss_task_2  where work_state='正在工作' and work_procedure='钢化上片' and groups=@remarks ;
    
 
    
    select gt.id,width,height,thickness,dr.surplus_count,angle,dr.stops,dr.noodles,gt.marking_flag,gt.galss_id,gt.processcard_id,gt.stop_position 
    into @id,@width,@height,@thickness,@surplus_count,@angle,@stops,@noodles,@marking_flag,@galss_id2,@gtprocesscard_id,@stop_position from gmms_galss_task_2 gt 
    INNER JOIN gmms_drop_frame_2 dr on gt.processcard_id=dr.processcard_id 
    where dr.flag=1 and dr.surplus_count>0 and gt.work_state='已优化' and work_procedure='钢化上片' and gt.groups=@remarks 
    and gt.orders is not null ORDER BY gt.furnace,gt.orders limit 0,1;
    #select @galss_id2;
    select count(*) into @processcardidsum from gmms_drop_frame_2 where groups=@remarks and processcard_id=@gtprocesscard_id;
    if @galss_id2=0 then
        select max(galss_id) into @galss1 from gmms_galss_task_2 where groups=@remarks;
        update gmms_galss_task_2 set galss_id=@galss1+1 where id=@id;
    end if;
    select galss_id into @galssid from gmms_galss_task_2 where id=@id;
    #旋转料架三个都有请求
    select count(*) into @counts2 from gmms_machine where state='允许' 
    and (id=35 or id=36 or id=37 or id=60 or id=61 or id=62) and remarks=@remarks;
    #旋转料架1  当前面无玻璃/背面有玻璃时 不吸片
    select surplus_count into @D_Taskcount from gmms_drop_frame_2 
    where stops=1 and flag=1 and groups=@remarks;
    select surplus_count into @B_Taskcount from gmms_drop_frame_2
    where stops=1 and flag=0 and groups=@remarks;
        if @counts>0 and @counts2=3 and @galssid!=0 and @counts3=0 and @processcardidsum=1 
                and !((@D_Taskcount=0 or @D_Taskcount is null) and @B_Taskcount>0) then
         if @flag1=1 then
         #select @galssid;
            update gmms_galss_task_2 set work_state='正在工作' where work_state='已优化' and work_procedure='钢化上片' and groups=@remarks and galss_id=@galssid;
            
            
            #修改 添加动作识别
            if @angle=1 then 
                select gang_qian_zhuan into @angle from gmms_dongzuo_table where number=@marking_flag;
            else 
                select gang_qian_bu_zhuan into @angle from gmms_dongzuo_table where number=@marking_flag ;
            end if;            
            select gang_qian_zhua into @zhua_qu from gmms_dongzuo_table where number=@marking_flag;
            
            if @stop_position>12 then
                if @angle=0 then
                    set @angle=3;
                elseif @angle=1 then
                    set @angle=2;
                elseif @angle=2 then
                    set @angle=1;
                elseif @angle=3 then
                    set @angle=0;
                end if;
            end if;
            #####
            
            call intTo2ByteHex10_16_4(@galssid,@galssids);
            call intTo2ByteHex10_16_4(@surplus_count,@surplus_counts);
            call intTo2ByteHex10_16_4(@stops,@stopss);
            call intTo2ByteHex10_16_4(@width,@widths);
            call intTo2ByteHex10_16_4(@height,@heights);
            call intTo2ByteHex10_16_4(@thickness,@thicknesss);
            call intTo2ByteHex10_16_4(@angle,@angles);
            /*
            select @widths;
            select @heights;
            select @thicknesss;
            select @angles;
            */
            if @noodles='A' then
                set noodles1='0001';
            else
                set noodles1='0002';
            end if;
 
            call intTo2ByteHex10_16_4(@angle,@angles);
            call intTo2ByteHex10_16_4(@zhua_qu,@z_zhuas);
            
            set dates=CONCAT(returnvalue,@galssids,noodles1,@z_zhuas,@stopss,@widths,@heights,@thicknesss,@angles,@surplus_counts);        
            
        #    set dates=CONCAT(returnvalue,@galssids,noodles1,'0000',@stopss,@widths,@heights,@thicknesss,@angles,@surplus_counts);
            call message(dates,'000a',@date);
            set messagedate=@date;
            insert into A_Robotlog(groups,glassid,beigntime,endtime,state,processcard_id)
            VALUES(@remarks,@id,NOW(),null,messagedate,@gtprocesscard_id);
         end if;
            
    
        end if;
    #中空理片机器人
    elseif machineids=47 then
      select @flag1;
        call y_RobotHollowSlicecage(machineids,returnvalue,dates);    
        set messagedate=dates;
    elseif machineids=44 or machineids=68 then
        #钢化后机械手
        call y_RobotTemperingAfter(rankid,machineids,returnvalue,dates);
        set messagedate=dates;
    elseif machineids=52 or machineids=71 or machineids=73 then
        #中空机器人
        call y_RobotHollow(machineids,returnvalue,dates);
        set messagedate=dates;
    end if;
    
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for RobotHandSend_2_copy1
-- ----------------------------
DROP PROCEDURE IF EXISTS `RobotHandSend_2_copy1`;
delimiter ;;
CREATE PROCEDURE `RobotHandSend_2_copy1`(in rankid varchar(255),in machineids BIGINT,in returnvalue varchar(255),out messagedate varchar(255))
BEGIN
    #下片机发送任务存储过程
    #找到等待中的任务,把下片位置,宽度,高度,厚度发送给plc
        DECLARE s int DEFAULT 0;
    DECLARE finshcount1 int;
    
    
    DECLARE y int DEFAULT 0;
    DECLARE j int DEFAULT 0;
    DECLARE processcardid2 varchar(255);
    
    DECLARE dates varchar(255);
    DECLARE noodles1 varchar(255);
    DECLARE finshcount int;
    DECLARE messagedates varchar(255) DEFAULT '';
    set messagedate=messagedates;
    
        select machine_type_id,work_id,remarks into @mtid,@remarks,@flag1 from gmms_machine where id=machineids;
 
    
    
    
    /*
    select @counts;
    select @galssid;
    #判断是否有等待的任务
    select @loadfalg;
    */
    
    #select @remarks;
    #select machineids;
    if machineids=38 or machineids=63 then
    
    
        select count(*) into @counts from gmms_galss_task_2 gt INNER JOIN gmms_drop_frame_2 dr on gt.processcard_id=dr.processcard_id where dr.flag=1 and gt.work_state='已优化' and work_procedure='钢化上片' and gt.groups=@remarks and gt.orders is not null ;
        #select @counts;
        select count(*) into @counts3 from gmms_galss_task_2  where work_state='正在工作' and work_procedure='钢化上片' and groups=@remarks ;
    
 
    
    select gt.id,width,height,thickness,dr.surplus_count,angle,dr.stops,dr.noodles,gt.marking_flag,gt.galss_id,gt.processcard_id into @id,@width,@height,@thickness,@surplus_count,@angle,@stops,@noodles,@marking_flag,@galss_id2,@gtprocesscard_id from gmms_galss_task_2 gt INNER JOIN gmms_drop_frame_2 dr on gt.processcard_id=dr.processcard_id where dr.flag=1 and dr.surplus_count>0 and gt.work_state='已优化' and work_procedure='钢化上片' and gt.groups=@remarks and gt.orders is not null ORDER BY gt.furnace,gt.orders limit 0,1;
    #select @galss_id2;
    if @galss_id2=0 then
        select max(galss_id) into @galss1 from gmms_galss_task_2 where groups=@remarks;
        update gmms_galss_task_2 set galss_id=@galss1+1 where id=@id;
    end if;
    select galss_id into @galssid from gmms_galss_task_2 where id=@id;
    select count(*) into @counts2 from gmms_machine where state='允许' and remarks=@remarks;
        if @counts>0 and @counts2=3 and @galssid!=0 and @counts3=0 then
         if @flag1=1 then
         #select @galssid;
            update gmms_galss_task_2 set work_state='正在工作' where work_state='已优化' and work_procedure='钢化上片' and groups=@remarks and galss_id=@galssid;
            
            
            #修改 添加动作识别
            if @angle=1 then 
                select gang_qian_zhuan into @angle from gmms_dongzuo_table where number=@marking_flag;
            else 
                select gang_qian_bu_zhuan into @angle from gmms_dongzuo_table where number=@marking_flag ;
            end if;            
               select gang_qian_zhua into @zhua_qu from gmms_dongzuo_table where number=@marking_flag;
            
            #####
            
            call intTo2ByteHex10_16_4(@galssid,@galssids);
            call intTo2ByteHex10_16_4(@surplus_count,@surplus_counts);
            call intTo2ByteHex10_16_4(@stops,@stopss);
            call intTo2ByteHex10_16_4(@width,@widths);
            call intTo2ByteHex10_16_4(@height,@heights);
            call intTo2ByteHex10_16_4(@thickness,@thicknesss);
            call intTo2ByteHex10_16_4(@angle,@angles);
            /*
            select @widths;
            select @heights;
            select @thicknesss;
            select @angles;
            */
            if @noodles='A' then
                set noodles1='0001';
            else
                set noodles1='0002';
            end if;
 
    
            call intTo2ByteHex10_16_4(@angle,@angles);
            call intTo2ByteHex10_16_4(@zhua_qu,@z_zhuas);
            
            set dates=CONCAT(returnvalue,@galssids,noodles1,@z_zhuas,@stopss,@widths,@heights,@thicknesss,@angles,@surplus_counts);
            
            
            
            
        #    set dates=CONCAT(returnvalue,@galssids,noodles1,'0000',@stopss,@widths,@heights,@thicknesss,@angles,@surplus_counts);
            call message(dates,'000a',@date);
            set messagedate=@date;
            insert into A_Robotlog(groups,glassid,beigntime,endtime,state,processcard_id)
            VALUES(@remarks,@id,NOW(),null,messagedate,@gtprocesscard_id);
         end if;
            
    
        end if;
    #中空理片机器人
    elseif machineids=47 then
      select @flag1;
        
        if @flag1=1 then
            select count(*) into @count1 from gmms_drop_frame_4 where groups=10;
            select remarks into @remarks from gmms_machine where id=50;
            select @count1;
            while s<@count1 do
                select stop_rank,stops into @stop_rank,@stops from gmms_drop_frame_4 where groups=10 limit s,1;
                select @stops;
                select @stop_rank;
                set @galss_id=null;
                if @remarks is not null then
                    select gt.id,galss_id,edg_width,edg_height,thickness,gt.stop_rank,gt.processcard_id,df.finsh_count,df.processcard_count,
                gt.edg_speed2 into @id,@galss_id,@edg_width,@edg_height,@thickness,@stop_ranks,@processcard_id,@finsh_count,@processcard_count,
                @edg_speed2 from gmms_drop_frame_4 df left join gmms_galss_task_slicecage gt on gt.processcard_id=df.processcard_id 
                where df.processcard_id is not null and work_state='已完成' and df.stop_rank=@stop_rank and sign=3 and work_procedure='钢化后下片' and df.processcard_id=@remarks and df.finsh_count >0 order by stop_rank desc limit 0,1;
                else
                    select gt.id,galss_id,edg_width,edg_height,thickness,gt.stop_rank,gt.processcard_id,df.finsh_count,df.processcard_count,
                gt.edg_speed2 into @id,@galss_id,@edg_width,@edg_height,@thickness,@stop_ranks,@processcard_id,@finsh_count,@processcard_count,
                @edg_speed2 from gmms_drop_frame_4 df left join gmms_galss_task_slicecage gt on gt.processcard_id=df.processcard_id 
                where df.processcard_id is not null and work_state='已完成' and df.stop_rank=@stop_rank and sign=3 and work_procedure='钢化后下片' and df.finsh_count >0 order by stop_rank desc limit 0,1;
                end if;
                
                                        
                        set @galss_id1=null;
                        select galss_id into @galss_id1 from gmms_galss_task_slicecage where galss_id=@galss_id and processcard_id=@processcard_id and stop_rank=out_rank;
                        if @galss_id1 is null then
                            
                            select remarks into @remarks from gmms_machine where id=machineids;
                            if @remarks!=2 then
                                
                                update gmms_machine set remarks=2 where id=machineids;
                                update gmms_drop_frame_4 set sign=3 where processcard_id=@processcard_id and groups=10;
 
                                set s=100;
                            end if;                            
 
                    end if;
                select @galss_id1;
                
                if @galss_id1 is not null then
                    select stop_rank into @laststoprank from (
                    select stop_rank from gmms_galss_task_shelf where processcard_id=@processcard_id or processcard_id=@liuchengka
                    group by stop_rank,edg_speed2) as g  group by g.stop_rank having count(*)>1 order by g.stop_rank limit 0,1;
                    
                    select stop_rank into @laststoprank2 from (
                    select stop_rank from gmms_galss_task_shelf where processcard_id=@processcard_id or processcard_id=@liuchengka
                    group by stop_rank,width,height) as g  group by g.stop_rank having count(*)>1 order by g.stop_rank limit 0,1;
                    update gmms_galss_task_slicecage set work_state='正在工作',work_procedure='理片笼上片' where galss_id=@galss_id1;
 
                    call intTo2ByteHex10_16_4(@galss_id1,@galss_ids);
                    call intTo2ByteHex10_16_4(@stops,@stopss);
                    call intTo2ByteHex10_16_4(@edg_width,@widths);
                    call intTo2ByteHex10_16_4(@edg_height,@heights);
                    call intTo2ByteHex10_16_4(@thickness,@thicknesss);
                    call intTo2ByteHex10_16_4(@stop_ranks,@stop_rankss);
                    call intTo2ByteHex10_16_4(@processcard_count,@processcard_counts);
                    if @laststoprank=@stop_ranks or @laststoprank2=@stop_ranks then
                        set dates=CONCAT(returnvalue,@galss_ids,@processcard_counts,'0001',@stopss,@widths,@heights,@thicknesss,@stop_rankss,"0000");
                    else
                        set dates=CONCAT(returnvalue,@galss_ids,@processcard_counts,'0001',@stopss,@widths,@heights,@thicknesss,@stop_rankss,"0001");
                    end if;    
                                    
                    call message(dates,'000a',@date);
                    set messagedate=@date;
                    set s=100;
                    insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,1,NOW(),'理片进任务',@stop_ranks,messagedate);
                end if;
                select s;
                set s=s+1;
            end while;
        elseif     @flag1=2 then
            select galss_id,edg_width,edg_height,thickness,gt.processcard_id into @galss_id,@edg_width,@edg_height,@thickness,@processcard_id from gmms_galss_task_slicecage gt join gmms_drop_frame_4 df on gt.processcard_id=df.processcard_id where work_state='已出库'  and sign=3 and work_procedure='理片'  order by gt.stop_rank  limit 0,1;
            select stops,finsh_count,processcard_count into @stops,@finsh_count,@processcard_count from gmms_drop_frame_4 where processcard_id=@processcard_id and groups=10;
            set finshcount1=@finsh_count+1;
            
                    
            if @galss_id is not null then
                
                    update gmms_galss_task_slicecage set work_state='正在工作',work_procedure='理片笼下片' where galss_id=@galss_id;
                    call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
                    call intTo2ByteHex10_16_4(@stops,@stopss);
                    call intTo2ByteHex10_16_4(@edg_width,@widths);
                    call intTo2ByteHex10_16_4(@edg_height,@heights);
                    call intTo2ByteHex10_16_4(@thickness,@thicknesss);
                    call intTo2ByteHex10_16_4(finshcount1,@stop_rankss);
                    if @processcard_count=finshcount1 then
                        set dates=CONCAT(returnvalue,@galss_ids,'00000002',@stopss,@widths,@heights,@thicknesss,@stop_rankss,'0000');
                    else
                        set dates=CONCAT(returnvalue,@galss_ids,'00000002',@stopss,@widths,@heights,@thicknesss,@stop_rankss,'0001');
                    end if;
                    
                    call message(dates,'000a',@date);
                    set messagedate=@date;
                    
                    insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,1,NOW(),'理片出任务',finshcount1,messagedate);
            end if;
        end if;
    elseif machineids=44 or machineids=68 then
        #钢化后机械手
        call y_RobotTemperingAfter(rankid,machineids,returnvalue,dates);
        set messagedate=dates;
    elseif machineids=52 or machineids=71 or machineids=73 or machineids=75 then
        #中空机器人
        call y_RobotHollow(machineids,returnvalue,dates);
        set messagedate=dates;
    end if;
    
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for RobotHand_2
-- ----------------------------
DROP PROCEDURE IF EXISTS `RobotHand_2`;
delimiter ;;
CREATE PROCEDURE `RobotHand_2`(in sendMessageHex varchar(255),in machineids BIGINT,out messagedate varchar(255),out falgs varchar(255))
BEGIN
    #下片机存储过程
    #找到当前机器标志位
    #查询机器逻辑表中对应的逻辑进行对应的步骤
    DECLARE machinedisposeids int DEFAULT 0;
    DECLARE ids int ;
    DECLARE plcfindid varchar(255);
    DECLARE dates varchar(255);
    DECLARE plcid varchar(255);
    DECLARE findplc varchar(255);
    DECLARE findmes varchar(255);
    DECLARE taskplc varchar(255);
    DECLARE taskmes varchar(255);
    DECLARE finsh_rankid BIGINT;
    DECLARE send_rankid BIGINT;
    DECLARE rankids varchar(255);
    DECLARE posunmes varchar(255);
    DECLARE messagedates varchar(255) DEFAULT '';
    set messagedate=messagedates;
    set falgs=0;
 
    select machine_type_id,work_id into @mtid,@remarks from gmms_machine where id=machineids;
    set ids = cast(@remarks as UNSIGNED INTEGER);
    
    select mf.flag into @完成标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='完成字';
    
    select mf.flag into @请求标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='请求字';
    
    select mf.flag into @发送标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='发送字';
    
    select mf.flag into @完成确认标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='完成确认字';
    
    set finsh_rankid = cast(@完成标志位 as UNSIGNED INTEGER)+1;
    set send_rankid = cast(@请求标志位 as UNSIGNED INTEGER)+1;
    
    #select @完成标志位;
    
    set findplc = substring(sendMessageHex,(cast(@完成标志位 as UNSIGNED INTEGER)*4)+19,4);
    set taskplc = substring(sendMessageHex,(cast(@请求标志位 as UNSIGNED INTEGER)*4)+19,4);
    set taskmes = substring(sendMessageHex,(cast(@发送标志位 as UNSIGNED INTEGER)*4)+19,4);
    set findmes = substring(sendMessageHex,(cast(@完成确认标志位 as UNSIGNED INTEGER)*4)+19,4);
    
    #select taskplc;
    #select taskmes;
    #select findplc;
    #select findmes;
    if findmes="0002" and machineids=63   then 
      set  findmes="0001";
    end if;
    
    set rankids = conv(substring(sendMessageHex,(cast(1 as UNSIGNED INTEGER)*4)+19,4),16,10);
    #select rankids;
 
set @完成数量=null;
set @完成逻辑编号=null;
#完成逻辑查询
    select count(*),md.id into @完成数量,@完成逻辑编号 from gmms_machine_dispose md join gmms_machine_type mt on md.machine_type_id=mt.id where md.machine_type_id=@mtid  and md.plc_font_type='完成字' and md.mes_font_type='完成确认字' and md.plc_font_value=findplc and md.mes_font_value=findmes;
    
    #请求逻辑查询
    select count(*),md.id into @请求数量,@请求逻辑编号 from gmms_machine_dispose md join gmms_machine_type mt on md.machine_type_id=mt.id where md.machine_type_id=@mtid  and md.plc_font_type='请求字' and md.mes_font_type='发送字' and md.plc_font_value=taskplc and md.mes_font_value=taskmes;
    
    
    #判断逻辑是否存在
    if @完成数量=1 or @请求数量=1  then
    
        #判断完成逻辑是否为空
        if @完成逻辑编号!=0 then
            set machinedisposeids=@完成逻辑编号;
            
        #判断请求逻辑是否为空
        elseif @请求逻辑编号!=0 then
            set machinedisposeids=@请求逻辑编号;
            
        end if;
        
        #查询当前执行逻辑进行判断
        select logic,return_value into @ExecutionLogic,@returnvalue from gmms_machine_dispose where id=machinedisposeids;
        #select @ExecutionLogic;
        #select @returnvalue;
        if @ExecutionLogic='任务完成' then
                call     RobotHandFinsh_2(sendMessageHex,machineids,@returnvalue,1,@messagedate);
                set messagedate=@messagedate;
        elseif @ExecutionLogic='任务失败' then
                call     RobotHandFinsh_2(sendMessageHex,machineids,@returnvalue,2,@messagedate);
                set messagedate=@messagedate;    
        elseif @ExecutionLogic='玻璃破损' then
                call     RobotHandFinsh_2(sendMessageHex,machineids,@returnvalue,3,@messagedate);
                set messagedate=@messagedate;    
         elseif @ExecutionLogic='完成清空' then    
                set dates=CONCAT(@returnvalue,"0000");    
                call message(dates,'0014',@date);
                set messagedate=@date;
        elseif @ExecutionLogic='任务请求' then
                if machineids=38 or machineids=63 then
                  #select @remarks;
                    select count(*) into @counts from gmms_galss_task_2  
                    where work_state='已优化' and work_procedure='钢化上片' and orders is not null and groups=@remarks;
                    select count(*) into @counts2 from gmms_drop_frame_2 
                    where flag=1 and groups=@remarks and surplus_count<>0;
                    #select @counts;
                    #select @counts2;
                    if @counts=0 and @counts2<>0 then
                    #select @remarks;
                        if @remarks=2 then
                            set falgs=2;
                        elseif @remarks=1 then 
                            set falgs=1;
                        end if;
                    else
                        set falgs=0;
                    end if;
                end if;
                
                call RobotHandSend_2(rankids,machineids,@returnvalue,@messagedate);
                set messagedate=@messagedate;
                
         elseif @ExecutionLogic='任务清空' then
            insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,"",NOW(),'发送清空任务',"","");
                set dates=CONCAT(@returnvalue,"000000000000000000000000000000000000");
                call message(dates,'000a',@date);
                set messagedate=@date;
        end if;
 
    end if;
 
 
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for Robot_gangqian_finish_ex
-- ----------------------------
DROP PROCEDURE IF EXISTS `Robot_gangqian_finish_ex`;
delimiter ;;
CREATE PROCEDURE `Robot_gangqian_finish_ex`(in machineids BIGINT,out messagedate varchar(255))
BEGIN
    #下片机发送任务存储过程
    #找到等待中的任务,把下片位置,宽度,高度,厚度发送给plc
        DECLARE s int DEFAULT 0;
    DECLARE finshcount1 int;
    
    
    DECLARE y int DEFAULT 0;
    DECLARE j int DEFAULT 0;
    DECLARE processcardid2 varchar(255);
    
    DECLARE dates varchar(255);
    DECLARE noodles1 varchar(255);
    DECLARE finshcount int;
    DECLARE messagedates varchar(255) DEFAULT '';
    set messagedate=messagedates;
    
        select machine_type_id,work_id,remarks into @mtid,@remarks,@flag1 from gmms_machine where id=machineids;
 
    
    
    
    /*
    select @counts;
    select @galssid;
    #判断是否有等待的任务
    select @loadfalg;
    */
    
    select @remarks;
    select machineids;
    if machineids=38 or machineids=63 then
    
    
        select count(*) into @counts from gmms_galss_task_2 gt INNER JOIN gmms_drop_frame_2 dr on gt.processcard_id=dr.processcard_id where dr.flag=1 and gt.work_state='已优化' and work_procedure='钢化上片' and gt.groups=@remarks and gt.orders is not null ;
        select @counts;
        select count(*) into @counts3 from gmms_galss_task_2  where work_state='正在工作' and work_procedure='钢化上片' and groups=@remarks ;
    
 
    
    select gt.id,width,height,thickness,dr.surplus_count,angle,dr.stops,dr.noodles,gt.marking_flag,gt.galss_id,gt.processcard_id into @id,@width,@height,@thickness,@surplus_count,@angle,@stops,@noodles,@marking_flag,@galss_id2,@gtprocesscard_id from gmms_galss_task_2 gt INNER JOIN gmms_drop_frame_2 dr on gt.processcard_id=dr.processcard_id where dr.flag=1 and dr.surplus_count>0 and gt.work_state='已优化' and work_procedure='钢化上片' and gt.groups=@remarks and gt.orders is not null ORDER BY gt.furnace,gt.orders limit 0,1;
    select @galss_id2;
    if @galss_id2=0 then
        select max(galss_id) into @galss1 from gmms_galss_task_2 where groups=@remarks;
        update gmms_galss_task_2 set galss_id=@galss1+1 where id=@id;
    end if;
    select galss_id into @galssid from gmms_galss_task_2 where id=@id;
    select count(*) into @counts2 from gmms_machine where state='允许' and remarks=@remarks;
        if @counts>0 and @counts2=3 and @galssid!=0 and @counts3=0 then
         if @flag1=1 then
         select @galssid;
            update gmms_galss_task_2 set work_state='正在工作' where work_state='已优化' and work_procedure='钢化上片' and groups=@remarks and galss_id=@galssid;
            
            
            #修改 添加动作识别
            if @angle=1 then 
                select gang_qian_zhuan into @angle from gmms_dongzuo_table where number=@marking_flag;
            else 
                select gang_qian_bu_zhuan into @angle from gmms_dongzuo_table where number=@marking_flag ;
            end if;            
               select gang_qian_zhua into @zhua_qu from gmms_dongzuo_table where number=@marking_flag;
            
            #####
            
            call intTo2ByteHex10_16_4(@galssid,@galssids);
            call intTo2ByteHex10_16_4(@surplus_count,@surplus_counts);
            call intTo2ByteHex10_16_4(@stops,@stopss);
            call intTo2ByteHex10_16_4(@width,@widths);
            call intTo2ByteHex10_16_4(@height,@heights);
            call intTo2ByteHex10_16_4(@thickness,@thicknesss);
            call intTo2ByteHex10_16_4(@angle,@angles);
            /*
            select @widths;
            select @heights;
            select @thicknesss;
            select @angles;
            */
            if @noodles='A' then
                set noodles1='0001';
            else
                set noodles1='0002';
            end if;
 
    
            call intTo2ByteHex10_16_4(@angle,@angles);
            call intTo2ByteHex10_16_4(@zhua_qu,@z_zhuas);
            
            set dates=CONCAT(@galssids,noodles1,@z_zhuas,@stopss,@widths,@heights,@thicknesss,@angles,@surplus_counts,'0002');
            
            
            
            
        #    set dates=CONCAT(returnvalue,@galssids,noodles1,'0000',@stopss,@widths,@heights,@thicknesss,@angles,@surplus_counts);
            call message(dates,'000b',@date);
            set messagedate=@date;
            insert into A_Robotlog(groups,glassid,beigntime,endtime,state,processcard_id)
            VALUES(@remarks,@id,NOW(),null,messagedate,@gtprocesscard_id);
         end if;
            
    
        end if;
    end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for RotatingRackFinsh_2
-- ----------------------------
DROP PROCEDURE IF EXISTS `RotatingRackFinsh_2`;
delimiter ;;
CREATE PROCEDURE `RotatingRackFinsh_2`(in sendMessageHex varchar(255),in machineids BIGINT,in returnvalue varchar(255),in flag int,out messagedate varchar(255))
BEGIN
    #下片机完成存储过程
    #找到正在工作的任务进行完成
    DECLARE count1 int DEFAULT 1;
    DECLARE dates varchar(255);
    DECLARE messagedates varchar(255) DEFAULT '';
    set messagedate=messagedates;
    
    select machine_type_id,work_id,remarks into @mtid,@work_groups,@remarks from gmms_machine where id=machineids;
    
    select flag;
 
    #任务完成
    if flag=1 then
        if machineids=55  then
            if (select count(*) from gmms_drop_frame_5 where groups_=2 and drop_groups=1 and sign=5)>0 then
                update gmms_drop_frame_5 set sign=6 where groups_=2 and drop_groups=1 and sign=5;
                call message(returnvalue,'0014',@date);
                set messagedate=@date;
                insert into aaaa(MachineName,groups,data1,Content,id,Sendtext)                 
                values (machineids,@work_groups,NOW(),'发送旋转完成',@date,messagedate);
            end if;                                
        else
            select noodles into @noodles from gmms_drop_frame_2 dr where stops=@work_groups and dr.flag=1 and groups=@remarks ;
            select @noodles;
            update gmms_drop_frame_2 set flag=0  where noodles=@noodles and groups=@remarks and stops=@work_groups;
            update gmms_drop_frame_2 set flag=1  where noodles!=@noodles and groups=@remarks and stops=@work_groups;
            call message(returnvalue,'0014',@date);
            set messagedate=@date;
        end if;        
    #任务破损
    elseif flag=2 then
        if machineids=55 then        
            update gmms_drop_frame_5 set sign=3 where groups_=2 and drop_groups=1 and sign=5;        
        end if;
        call message(returnvalue,'0014',@date);
        set messagedate=@date;
    
    end if;
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for RotatingRackSend_2
-- ----------------------------
DROP PROCEDURE IF EXISTS `RotatingRackSend_2`;
delimiter ;;
CREATE PROCEDURE `RotatingRackSend_2`(in machineids BIGINT,in sendMessageHex varchar(255),in returnvalue varchar(255),out messagedate varchar(255))
BEGIN
    #下片机发送任务存储过程
    #找到等待中的任务,把下片位置,宽度,高度,厚度发送给plc
    DECLARE dates varchar(255);
    DECLARE noodless varchar(255);
    DECLARE noodless2 varchar(255);
    DECLARE messagedates varchar(255) DEFAULT '';
    set messagedate=messagedates;
    select machine_type_id,work_id,remarks into @mtid,@work_groups,@remarks from gmms_machine where id=machineids;
if machineids=55 then
    set noodless2 = substring(sendMessageHex,(cast(45 as UNSIGNED INTEGER)*4)+19,4);
    select count(*) into @count2 from gmms_drop_frame_5 where groups_=2 and drop_groups=1 and sign=3;
    
    if @count2>0 then
        if noodless2='0001' then
            set dates=CONCAT(returnvalue,'0000','0002');
            call message(dates,'000a',@date);
            set messagedate=@date;
            update gmms_drop_frame_5 set sign=5 where groups_=2 and drop_groups=1 and sign=3;
        elseif noodless2='0002' then
            set dates=CONCAT(returnvalue,'0000','0001');
            call message(dates,'000a',@date);
            set messagedate=@date;
            update gmms_drop_frame_5 set sign=5 where groups_=2 and drop_groups=1 and sign=3;
        end if;        
        
--          insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) 
--          values (machineids,@work_groups,NOW(),'发送旋转',@date,sendMessageHex);
    end if;    
else
        select noodles,surplus_count into @noodles,@surplus_count from gmms_drop_frame_2 
        where stops=@work_groups and flag=1 and groups=@remarks;
        select noodles,surplus_count into @noodles2,@surplus_count2 from gmms_drop_frame_2
        where stops=@work_groups and flag=0 and groups=@remarks;
        
        select count(*) into @loadworkingcount from gmms_galss_task_2  where work_state='正在工作' and work_procedure='钢化上片' and groups=@remarks ;
        select @noodles;
        select @surplus_count;
        select @surplus_count2;
        if (@surplus_count=0 or @surplus_count is null) and @surplus_count2>0 and @loadworkingcount=0 then
                if @noodles='B' then
                    set noodless='0001';
                else
                    set noodless='0002';
                end if;            
                set dates=CONCAT(returnvalue,'0000',noodless);
                call message(dates,'000a',@date);
                set messagedate=@date;
        end if;    
end if;
    
    
    
    
    
    
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for RotatingRack_2
-- ----------------------------
DROP PROCEDURE IF EXISTS `RotatingRack_2`;
delimiter ;;
CREATE PROCEDURE `RotatingRack_2`(in sendMessageHex varchar(255),in machineids BIGINT,out messagedate varchar(255))
BEGIN
    #下片机存储过程
    #找到当前机器标志位
    #查询机器逻辑表中对应的逻辑进行对应的步骤
    DECLARE machinedisposeids int DEFAULT 0;
    DECLARE ids int ;
    DECLARE plcfindid varchar(255);
    DECLARE dates varchar(255);
    DECLARE plcid varchar(255);
    DECLARE findplc varchar(255);
    DECLARE findmes varchar(255);
    DECLARE taskplc varchar(255);
    DECLARE taskmes varchar(255);
    DECLARE finsh_rankid BIGINT;
    DECLARE send_rankid BIGINT;
    DECLARE noodless2 varchar(255);
    DECLARE rankids varchar(255);
    DECLARE posunmes varchar(255);
    DECLARE messagedates varchar(255) DEFAULT '';
    set messagedate=messagedates;
    
    
    select machine_type_id,remarks into @mtid,@remarks from gmms_machine where id=machineids;
    set ids = cast(@remarks as UNSIGNED INTEGER);
    
    select mf.flag into @完成标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='完成字';
    
    select mf.flag into @请求标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='请求字';
    
    select mf.flag into @发送标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='发送字';
    
    select mf.flag into @完成确认标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='完成确认字';
    
    set finsh_rankid = cast(@完成标志位 as UNSIGNED INTEGER)+1;
    set send_rankid = cast(@请求标志位 as UNSIGNED INTEGER)+1;
    
    set findplc = substring(sendMessageHex,(cast(@完成标志位 as UNSIGNED INTEGER)*4)+19,4);
    set taskplc = substring(sendMessageHex,(cast(@请求标志位 as UNSIGNED INTEGER)*4)+19,4);
    set taskmes = substring(sendMessageHex,(cast(@发送标志位 as UNSIGNED INTEGER)*4)+19,4);
    set findmes = substring(sendMessageHex,(cast(@完成确认标志位 as UNSIGNED INTEGER)*4)+19,4);
    set noodless2 = substring(sendMessageHex,(cast(45 as UNSIGNED INTEGER)*4)+19,4);
    
    select taskplc;
    select taskmes;
    select findplc;
    select findmes;
    select plcfindid;
    
--     if machineids=55 then
--         if noodless2='0001' then
--             update gmms_drop_frame_4 set falg=1 where noodles=98;
--             update gmms_drop_frame_4 set falg=0 where noodles=99;
--         elseif noodless2='0002' then
--             update gmms_drop_frame_4 set falg=0 where noodles=98;
--             update gmms_drop_frame_4 set falg=1 where noodles=99;
--         end if;
--     end if;
    if machineids=55 then
        if noodless2='0001' or noodless2='0002' then
            update gmms_machine set state='允许' where id=machineids;
        else 
            update gmms_machine set state='禁止' where id=machineids;
        end if;
    else
        if taskplc='0001' then
            update gmms_machine set state='允许' where id=machineids;
        else 
            update gmms_machine set state='禁止' where id=machineids;
        end if;
    end if;
    
    
    set rankids = conv(substring(sendMessageHex,(cast(send_rankid as UNSIGNED INTEGER)*4)+19,4),16,10);
    select rankids;
 
#完成逻辑查询
    select count(*),md.id into @完成数量,@完成逻辑编号 from gmms_machine_dispose md join gmms_machine_type mt on md.machine_type_id=mt.id where md.machine_type_id=@mtid  and md.plc_font_type='完成字' and md.mes_font_type='完成确认字' and md.plc_font_value=findplc and md.mes_font_value=findmes;
    
    #请求逻辑查询
    select count(*),md.id into @请求数量,@请求逻辑编号 from gmms_machine_dispose md join gmms_machine_type mt on md.machine_type_id=mt.id where md.machine_type_id=@mtid  and md.plc_font_type='请求字' and md.mes_font_type='发送字' and md.plc_font_value=taskplc and md.mes_font_value=taskmes;
    
    
    #判断逻辑是否存在
    if @完成数量=1 or @请求数量=1  then
    
        #判断完成逻辑是否为空
        if @完成逻辑编号!=0 then
            set machinedisposeids=@完成逻辑编号;
            
        #判断请求逻辑是否为空
        elseif @请求逻辑编号!=0 then
            set machinedisposeids=@请求逻辑编号;
            
        end if;
        #查询当前执行逻辑进行判断
        select logic,return_value into @ExecutionLogic,@returnvalue from gmms_machine_dispose where id=machinedisposeids;
        select @ExecutionLogic;
        select @returnvalue;
        if @ExecutionLogic='任务完成' then
                call     RotatingRackFinsh_2(sendMessageHex,machineids,@returnvalue,1,@messagedate);
                set messagedate=@messagedate;
        elseif @ExecutionLogic='任务失败' then
                call     RotatingRackFinsh_2(sendMessageHex,machineids,@returnvalue,2,@messagedate);
                set messagedate=@messagedate;        
         elseif @ExecutionLogic='完成清空' then    
                set dates=CONCAT(@returnvalue,"0000");    
                call message(dates,'0014',@date);
                set messagedate=@date;
        elseif @ExecutionLogic='任务请求' then
                call RotatingRackSend_2(machineids,sendMessageHex,@returnvalue,@messagedate);
                set messagedate=@messagedate;            
         elseif @ExecutionLogic='任务清空' then
                set dates=CONCAT(@returnvalue,"0000000000000000");
                call message(dates,'000a',@date);
                set messagedate=@date;
        end if;
 
    end if;
 
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for Shelf
-- ----------------------------
DROP PROCEDURE IF EXISTS `Shelf`;
delimiter ;;
CREATE PROCEDURE `Shelf`(in sendMessageHex varchar(255),in machineids BIGINT,out messagedate varchar(255))
BEGIN
    #仓储存储过程
    #找到当前机器标志位
    #查询机器逻辑表中对应的逻辑进行对应的步骤
    DECLARE machinedisposeids int DEFAULT 0;
    DECLARE dates varchar(255);
    DECLARE findplc varchar(255);
    DECLARE findmes varchar(255);
    DECLARE taskplc varchar(255);
    DECLARE taskmes varchar(255);
    DECLARE messagedates varchar(255) DEFAULT '';
    set messagedate=messagedates;
    
    select machine_type_id into @mtid from gmms_machine where id=machineids;
  call LoadShelfTaskAdd(1);
    call LoadShelfTaskAdd(12);
    call LoadShelfTaskAdd(13);
    
    
    select mf.flag into @完成标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='完成字';
    
    select mf.flag into @请求标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='请求字';
    
    select mf.flag into @发送标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='发送字';
    
    select mf.flag into @完成确认标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='完成确认字';
    
    set findplc = substring(sendMessageHex,(cast(@完成标志位 as UNSIGNED INTEGER)*4)+19,4);
    set taskplc = substring(sendMessageHex,(cast(@请求标志位 as UNSIGNED INTEGER)*4)+19,4);
    set taskmes = substring(sendMessageHex,(cast(@发送标志位 as UNSIGNED INTEGER)*4)+19,4);
    set findmes = substring(sendMessageHex,(cast(@完成确认标志位 as UNSIGNED INTEGER)*4)+19,4);
    select taskplc;
    select taskmes;
    select findplc;
    select findmes;
 
    #完成逻辑查询
    select count(*),md.id into @完成数量,@完成逻辑编号 from gmms_machine_dispose md join gmms_machine_type mt on md.machine_type_id=mt.id where md.machine_type_id=@mtid  and md.plc_font_type='完成字' and md.mes_font_type='完成确认字' and md.plc_font_value=findplc and md.mes_font_value=findmes;
    
    #请求逻辑查询
    select count(*),md.id into @请求数量,@请求逻辑编号 from gmms_machine_dispose md join gmms_machine_type mt on md.machine_type_id=mt.id where md.machine_type_id=@mtid  and md.plc_font_type='请求字' and md.mes_font_type='发送字' and md.plc_font_value=taskplc and md.mes_font_value=taskmes;
 
 
    #判断逻辑是否存在
    if @完成数量=1 or @请求数量=1 then
    
        #判断完成逻辑是否为空
        if @完成逻辑编号!=0 then
            set machinedisposeids=@完成逻辑编号;
            
        #判断请求逻辑是否为空
        elseif @请求逻辑编号!=0 then
            set machinedisposeids=@请求逻辑编号;
            
        end if;
        #查询当前执行逻辑进行判断
        select logic,return_value,mes_font_value into @ExecutionLogic,@returnvalue,@mes_font_value from gmms_machine_dispose where id=machinedisposeids;
        select @returnvalue;
        if @ExecutionLogic='任务完成' then
                call ShelfFinsh(sendMessageHex,machineids,@returnvalue,1,@messagedate);
                set messagedate=@messagedate;
         elseif @ExecutionLogic='任务失败' then
                call ShelfFinsh(sendMessageHex,machineids,@returnvalue,2,@messagedate);
                set messagedate=@messagedate;
        elseif @ExecutionLogic='手动完成' then
                call ShelfFinsh(sendMessageHex,machineids,@returnvalue,1,@messagedate);
                set messagedate=@messagedate;
         elseif @ExecutionLogic='完成清空' then
                select @returnvalue;
                call message(@returnvalue,'0014',@date);
                set messagedate=@date;
        elseif @ExecutionLogic='任务请求' then
                call ShelfSend(machineids,machinedisposeids,@messagedate);
                set messagedate=@messagedate;
         elseif @ExecutionLogic='任务清空' then
                set dates=CONCAT(@returnvalue,"0000000000000000");
                select dates;
                call message(dates,'000a',@date);
                set messagedate=@date;
        else
                set messagedate='';
        end if;
    end if;
    
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for ShelfFinsh
-- ----------------------------
DROP PROCEDURE IF EXISTS `ShelfFinsh`;
delimiter ;;
CREATE PROCEDURE `ShelfFinsh`(in sendMessageHex varchar(255),in machineids BIGINT,in returnvalue varchar(255),in flag int,out messagedate varchar(255))
BEGIN
    #仓储完成存储过程
    #找到正在工作的任务,判断是什么类型的仓储任务,分别进行什么处理
    DECLARE messagedates varchar(255) DEFAULT '';
    set messagedate=messagedates;
    
    
    
    select count(*) into @counts from gmms_shelf_task where task_state='正在工作';
    select id,task_type,shelf_rack_id,load_rack into @taskid,@task_type,@shelf_rack_id,@load_rack_id from gmms_shelf_task where task_state='正在工作' limit 1;
    select rp.color into @color from  gmms_shelf_rack sr join gmms_raw_package rp on sr.raw_package_id1=rp.id where sr.id=@shelf_rack_id;
    
    #任务完成
    if flag=1 then 
    select @counts;
        if @counts>0 then
        
            #仓位上片位之间类型的任务
            if @task_type='从仓位到上片位' or @task_type='从上片位到仓位' then
            
                if @task_type='从仓位到上片位' then
                select @load_rack_id;
                select @shelf_rack_id;
                    update gmms_shelf_rack set state='正在使用' where id=@shelf_rack_id;
                    update gmms_load_rack set shelf_task_id=@taskid,state='正在工作',falg_shelf='1' where number=@load_rack_id;
                    update gmms_shelf_task set task_state='已完成',finsh_time=NOW(),file_id=1 where id=@taskid;
                    select returnvalue;
                    call message(returnvalue,'0014',@date);
                    set messagedate=@date;
                else
                select @taskid;
                    select rp.left_pieces into @left_pieces from gmms_shelf_rack sr join gmms_raw_package rp on sr.raw_package_id1=rp.id where sr.id=@shelf_rack_id;
                    #判断架子上面是否还有玻璃
                    if @left_pieces=0 then
                        update gmms_shelf_rack set state='空闲',raw_package_id1=null,mod_time=now(),color_falg=0 where id=@shelf_rack_id;
                    else 
                    # @color='白玻' or @color='超白' or @color='C' 
                        if 1=1 then
                            update gmms_shelf_rack set state='使用中',mod_time=now() where id=@shelf_rack_id;
                        else
                            if @left_pieces=1 then
                                update gmms_shelf_rack set state='使用中',falg='禁用',mod_time=now() where id=@shelf_rack_id;
                            else
                                update gmms_shelf_rack set state='使用中',mod_time=now() where id=@shelf_rack_id;
                            end if;
                        end if;
                    end if;
                    update gmms_load_rack set state='空闲',shelf_task_id=Null,falg_shelf='0' where number=@load_rack_id;
                    update gmms_shelf_task set task_state='已完成',finsh_time=NOW(),file_id=1 where id=@taskid;
                    call message(returnvalue,'0014',@date);
                    set messagedate=@date;
                end if;
            
            #仓位吊装位之间类型的任务
            elseif  @task_type='从仓位到吊装位' or @task_type='从吊装位到仓位' then
            
                if  @task_type='从仓位到吊装位' then
                
                    update gmms_shelf_rack set state='正在使用' where id=@shelf_rack_id;
                    update gmms_load_rack set shelf_task_id=@taskid,state='正在使用',falg_shelf='1' where number='99';
                    update gmms_shelf_task set task_state='已完成',finsh_time=NOW(),file_id=1 where id=@taskid;
                    call message(returnvalue,'0014',@date);
                    set messagedate=@date;
                else 
                    select rp.left_pieces into @剩余片数 from gmms_shelf_rack sr join gmms_raw_package rp on rp.id=sr.raw_package_id1 where sr.number=@shelf_rack_id;
                    if @剩余片数=1 then
                        update gmms_shelf_rack set state='使用中',mod_time=now(),falg='启用',color_falg=1 where id=@shelf_rack_id;
                    elseif  @剩余片数>1 then
                        update gmms_shelf_rack set state='使用中',mod_time=now(),falg='启用' where id=@shelf_rack_id;
                    else
                        update gmms_shelf_rack set state='空闲',raw_package_id1=null,mod_time=now(),falg='启用' where id=@shelf_rack_id;
                    end if;
                    update gmms_load_rack set state='空闲',shelf_task_id=Null,falg_shelf='0' where number='99';
                    update gmms_shelf_task set task_state='已完成',finsh_time=NOW(),file_id=1 where id=@taskid;
                    call message(returnvalue,'0014',@date);
                    set messagedate=@date;
                end if;
            
            end if;
        else
            set messagedate='';
        end if;
        
        
        
    #任务失败,重新修改状态
    elseif flag=2 then
        if @counts=0 then
            update gmms_shelf_task set task_state='等待中' where id=@taskid;
        end if;
            call message(returnvalue,'0014',@date);
            set messagedate=@date;
        else
            set messagedate='';
    end if;
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for ShelfSend
-- ----------------------------
DROP PROCEDURE IF EXISTS `ShelfSend`;
delimiter ;;
CREATE PROCEDURE `ShelfSend`(in machineids BIGINT,in machinedisposeids BIGINT,out messagedate varchar(255))
BEGIN
    #仓储请求存储过程
    #循环等待中的仓储任务,循环上片位,判断是什么类型任务分别进行处理
    DECLARE s int DEFAULT 0;
    DECLARE x int DEFAULT 0;
    DECLARE load_racks int DEFAULT 0;
    DECLARE dates varchar(255);
    DECLARE messagedates varchar(255) DEFAULT '';
    set messagedate=messagedates;
    
    select return_value into @returnvalue from gmms_machine_dispose where id=machinedisposeids;
    
    set @shelfcount=null;
    set @shelfcounts=null;
 
    select count(*) into @shelfcount from gmms_shelf_task where task_state='等待中';
    select count(*) into @shelfcounts from gmms_shelf_task where task_state='正在工作';
    
        select id,task_id,task_state,task_type,groups,shelf_rack_id,load_rack into @id,@shelf_task_id,@task_state,@task_type,@groups,@shelf_rack_id,@load_rack from gmms_shelf_task where task_state='等待中' order by start_time limit 1;
    if @shelfcounts=0 then
        select @load_rack;
            select falg_shelf,falg into @falg_shelf,@falg from gmms_load_rack where number=@load_rack;
            select @falg_shelf;
            select @shelf_task_id;
            select @task_type;
            if @task_type='从上片位到仓位' then
                #判断上片位架子上面有玻璃,上片位是否启用
                if @falg='启用' and @falg_shelf='1' then
                    update gmms_shelf_task set task_state='正在工作' where task_state='等待中' and id=@id;
                    
                    call intTo2ByteHex10_16_4(@shelf_rack_id,@shelfrackid);
                    call intTo2ByteHex10_16_4(@load_rack,@loadrackid);
                    set dates=CONCAT(@returnvalue,"0000",@loadrackid,@shelfrackid,"0001");
                    call message(dates,'000a',@date);
                    set messagedate=@date;
                    
                end if;
            
            elseif @task_type='从仓位到上片位' then
                #判断上片位架子上面没有玻璃,上片位是否启用
                if @falg='启用' and @falg_shelf='0'  then
                    update gmms_shelf_task set task_state='正在工作' where task_state='等待中' and id=@id;
                    update gmms_shelf_rack set state='正在使用' where id=@shelf_rack_id;
                    call intTo2ByteHex10_16_4(@shelf_rack_id,@shelfrackid);
                    call intTo2ByteHex10_16_4(@load_rack,@loadrackid);
                    set dates=CONCAT(@returnvalue,"0000",@shelfrackid,@loadrackid,"0001");
                    select dates;
                    call message(dates,'000a',@date);
                    set messagedate=@date;
            
                end if;
                
            elseif @task_type='从吊装位到仓位' then
                #判断吊装位架子上面有玻璃,上片位是否启用
                if @falg='启用' and @falg_shelf='1'  then
                    update gmms_shelf_task set task_state='正在工作' where task_state='等待中' and id=@id;
                    call intTo2ByteHex10_16_4(@shelf_rack_id,@shelfrackid);
                    call intTo2ByteHex10_16_4(@load_rack,@loadrackid);
                    set dates=CONCAT(@returnvalue,"0000",@loadrackid,@shelfrackid,"0001");
                    call message(dates,'000a',@date);
                    set messagedate=@date;
            
                end if;
        
            elseif @task_type='从仓位到吊装位' then
            select @shelf_task_id;
                #判断吊装位架子上面没有玻璃,上片位是否启用,任务编号不等于null
                if @falg='启用' and @falg_shelf='0'  then
                    update gmms_shelf_task set task_state='正在工作' where task_state='等待中' and id=@id;
                    call intTo2ByteHex10_16_4(@shelf_rack_id,@shelfrackid);
                    call intTo2ByteHex10_16_4(@load_rack,@loadrackid);
                    set dates=CONCAT(@returnvalue,"0000",@shelfrackid,@loadrackid,"0001");
                    call message(dates,'000a',@date);
                    set messagedate=@date;
            
                end if;
            
            end if;
 
    end if;
    
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for Slicecage
-- ----------------------------
DROP PROCEDURE IF EXISTS `Slicecage`;
delimiter ;;
CREATE PROCEDURE `Slicecage`(in sendMessageHex varchar(255),in machineids BIGINT,out messagedate varchar(255),inout msg varchar(255))
BEGIN
    #理片笼存储过程
    #找到当前机器标志位
    #查询机器逻辑表中对应的逻辑进行对应的步骤
    DECLARE machinedisposeids int DEFAULT 0;
    DECLARE dates varchar(255);
    DECLARE findplc varchar(255);
    DECLARE findmes varchar(255);
    DECLARE taskplc varchar(255);
    DECLARE taskmes varchar(255);
    DECLARE messagedates varchar(255) DEFAULT '';
    set messagedate=messagedates;
    
    
             set @log_task="";
 
 
        SET msg:='Slicecage  查配置';    
    select machine_type_id,remarks into @mtid,@remarks from gmms_machine where id=machineids;
    
 
    
    select mf.flag into @完成标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='完成字';
    
    select mf.flag into @请求标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='请求字';
    
    select mf.flag into @发送标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='发送字';
    
    select mf.flag into @完成确认标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='完成确认字';
    
    set findplc = substring(sendMessageHex,(cast(@完成标志位 as UNSIGNED INTEGER)*4)+19,4);
    set taskplc = substring(sendMessageHex,(cast(@请求标志位 as UNSIGNED INTEGER)*4)+19,4);
    set taskmes = substring(sendMessageHex,(cast(@发送标志位 as UNSIGNED INTEGER)*4)+19,4);
    set findmes = substring(sendMessageHex,(cast(@完成确认标志位 as UNSIGNED INTEGER)*4)+19,4);
    select taskplc;
    select taskmes;
    select findplc;
    select findmes;
    call log_key_value(@log_task,"完成标志",findplc);
    call log_key_value(@log_task,"请求标志",taskplc);
    call log_key_value(@log_task,"发送标志",taskmes);
    call log_key_value(@log_task,"完成确认标志",findmes);
            
    #完成逻辑查询
    select count(*),md.id into @完成数量,@完成逻辑编号 from gmms_machine_dispose md join gmms_machine_type mt on md.machine_type_id=mt.id where md.machine_type_id=@mtid  and md.plc_font_type='完成字' and md.mes_font_type='完成确认字' and md.plc_font_value=findplc and md.mes_font_value=findmes;
    
    #请求逻辑查询
    select count(*),md.id into @请求数量,@请求逻辑编号 from gmms_machine_dispose md join gmms_machine_type mt on md.machine_type_id=mt.id where md.machine_type_id=@mtid  and md.plc_font_type='请求字' and md.mes_font_type='发送字' and md.plc_font_value=taskplc and md.mes_font_value=taskmes;
    
    #判断逻辑是否存在
    if @完成数量=1 or @请求数量=1 then
    
        #判断完成逻辑是否为空
        if @完成逻辑编号!=0 then
            set machinedisposeids=@完成逻辑编号;
            
        #判断请求逻辑是否为空
        elseif @请求逻辑编号!=0 then
            set machinedisposeids=@请求逻辑编号;
            
        end if;
            SET msg:='Slicecage  查逻辑标志';    
        #查询当前执行逻辑进行判断
        select logic,return_value into @ExecutionLogic,@returnvalue from gmms_machine_dispose where id=machinedisposeids;
        select @ExecutionLogic;
        
    
            call log_key_value(@log_task,"执行逻辑",@ExecutionLogic);
                call log_key_value(@log_task,"returnvalue",@returnvalue);
        
        if @ExecutionLogic='任务完成' then
            SET msg:='Slicecage      #直通模式';    
                #直通模式
                if @remarks='3' then
                    call SlicecageFinsh(machineids,machinedisposeids,3,@messagedate);
                    set messagedate=@messagedate;    
                else
                    call SlicecageFinsh(machineids,machinedisposeids,1,@messagedate);
                    set messagedate=@messagedate;
                end if;
                
         elseif @ExecutionLogic='完成破损' then
                call SlicecageFinsh(machineids,machinedisposeids,2,@messagedate);
                set messagedate=@messagedate;
         elseif @ExecutionLogic='完成清空' then
                call message(@returnvalue,'0014',@date);
                set messagedate=@date;
        elseif @ExecutionLogic='进片请求' then
            SET msg:='Slicecage      #进片请求';    
                call SlicecageSend(machineids,@returnvalue,1,@messagedate);
                set messagedate=@messagedate;
        elseif @ExecutionLogic='出片请求' then
        SET msg:='Slicecage      #出片请求';    
        
                call SlicecageSend(machineids,@returnvalue,2,@messagedate);
                set messagedate=@messagedate;
        elseif @ExecutionLogic='进出片请求' then
            SET msg:='Slicecage      #进出片请求';    
            call SlicecageSend(machineids,@returnvalue,3,@messagedate);
            set messagedate=@messagedate;
         elseif @ExecutionLogic='任务清空' then
             SET msg:='Slicecage      #任务清空';    
                set dates=CONCAT(@returnvalue,"0000000000000000");
                call message(dates,'000a',@date);
                set messagedate=@date;
        end if;
    end if;
        set @log_nm=concat("冷加工理片",machineids);
    set @exist_nm=null;
    
    select `var_value`,var_name into @var_value,@exist_nm from memory_var_table where var_name=@log_nm;
         if @exist_nm is null then 
            insert into memory_var_table (var_name,var_value,update_time) values (@log_nm,@log_task,now());
            else
                update memory_var_table set var_value=@log_task,update_time=now() where var_name=@log_nm;
         end if;
         
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for SlicecageFinsh
-- ----------------------------
DROP PROCEDURE IF EXISTS `SlicecageFinsh`;
delimiter ;;
CREATE PROCEDURE `SlicecageFinsh`(in machineids BIGINT,in machinedisposeids BIGINT,in flag int,out messagedate varchar(255))
BEGIN
    #理片笼完成存储过程
    #判断完成,破损,直通
    DECLARE messagedates varchar(255) DEFAULT '';
    set messagedate=messagedates;
    
    select machine_type_id,work_id into @mtid,@work_groups from gmms_machine where id=machineids;
    
    select file_name into @engineering_id from gmms_raw_file where operator=@work_groups and state='已领取';
    
    select return_value into @returnvalue from gmms_machine_dispose where id=machinedisposeids;
    
    select galss_id into @galss_id from gmms_galss_task where work_state='出库中' and work_procedure='理片' and engineering_id=@engineering_id limit 1;
    select @returnvalue;
    
    #完成
    if flag=1 then
        call intoutfinish(machineids,flag,@finsh,@err);
        call message('0001','0014',@date);
        set messagedate=@date;
    #破损
    elseif flag=2 then
        call intoutfinish(machineids,flag,@finsh,@err);
        call message('0001','0014',@date);
        set messagedate=@date;
    #直通
    elseif flag=3 then
        select max(out_rank) into @maxrank from gmms_galss_task where  engineering_id=@engineering_id;
        update gmms_galss_task set work_state='已出库',work_procedure='理片',finsh_time=NOW(),out_rank=@maxrank+1  where galss_id=@galss_id and work_state='出库中' and engineering_id=@engineering_id;
        update gmms_machine set remarks='' where id=machineids;
        call message(@returnvalue,'0014',@date);
        set messagedate=@date;
    end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for SlicecageSend
-- ----------------------------
DROP PROCEDURE IF EXISTS `SlicecageSend`;
delimiter ;;
CREATE PROCEDURE `SlicecageSend`(in machineids BIGINT,in returnvalue varchar(255),in flag int,out messagedate varchar(255))
BEGIN
    #理片笼请求存储过程
    #判断是进片还是出片还是进出片请求
    #发送数据:玻璃编号,理片笼架子
    DECLARE a int DEFAULT 0;
    DECLARE dates varchar(255);
    DECLARE messagedates varchar(255) DEFAULT '';
    set messagedate=messagedates;
    
    
        call log_msg(@log_task,"[SlicecageSend]");
 
 
-- select flag;
 
select machine_type_id,work_id into @mtid,@work_groups from gmms_machine where id=machineids;
 
-- select @work_groups;
    
select file_name into @engineering_id from gmms_raw_file where operator=@work_groups and state='已领取';
 
select @engineering_id;
 
select var into @var from gmms_slicecage_pattern where groups=@work_groups;
 
-- select @var;
-- select flag;
 
 
    call log_key_value(@log_task,"@var",@var);
        call log_key_value(@log_task,"flag",flag);
    
    
if @var='1' then
        
    if flag=1 then
                call input(machineids,@发送字,@发送ID,@格子,@err);
                call intTo2ByteHex10_16_4(@发送字,@returnvalue);
                call intTo2ByteHex10_16_4(@发送ID,@typeid);
                call intTo2ByteHex10_16_4(@格子,@slicecage_rank);
                set dates=CONCAT(@returnvalue,@typeid,@slicecage_rank);
                call message(dates,'000a',@date);
                set messagedate=@date;
    #出片
    elseif flag=2 then
                if @work_groups=3 and @work_groups=2 and position("P" in @engineering_id)>0 then
                    call output2(machineids,@发送字,@发送ID1,@发送ID2,@格子,@err);
                else
                    call output(machineids,@发送字,@发送ID1,@发送ID2,@格子,@err);
                end if;
                
                select @发送字,@发送ID1,@发送ID2,@格子;
                call intTo2ByteHex10_16_4(@发送字,@returnvalue);
                call intTo2ByteHex10_16_4(@发送ID1,@galssid1);
                call intTo2ByteHex10_16_4(@发送ID2,@galssid2);
                call intTo2ByteHex10_16_4(@格子,@slicecage_rank);
                set dates=CONCAT(@returnvalue,'0000',@slicecage_rank,'0000',@galssid1,@galssid2);
                call message(dates,'000a',@date);
                set messagedate=@date;
                
    #进出片
    elseif flag=3 then
                select a;
                #先出后进
                if a=0 then
                  select a;
                    set @kuneishu=0;
                    set @counts=0;
                    select 库内数 into @kuneishu from processcard where 工程号=@engineering_id order by 库内数 desc limit 1;
                    select @work_groups;
                    select count(*) into @counts from gmms_slicecage where state='空闲' and gourp=@work_groups;
                    select @kuneishu;
                    #判断理片笼里面是否有20片玻璃
                    if @kuneishu>10 or @counts<=1 then
                        if @work_groups=3 and @work_groups=2 and position("P" in @engineering_id)>0 then
 
                    call output2(machineids,@发送字,@发送ID1,@发送ID2,@格子,@err);
                else
                    call output(machineids,@发送字,@发送ID1,@发送ID2,@格子,@err);
                end if;
                        call log_key_value(@log_task,"发送子",@发送字);
                        call intTo2ByteHex10_16_4(@发送字,@returnvalue);
                        call intTo2ByteHex10_16_4(@发送ID1,@galssid1);
                        call intTo2ByteHex10_16_4(@发送ID2,@galssid2);
                        call intTo2ByteHex10_16_4(@格子,@slicecage_rank);                
                        set dates=CONCAT(@returnvalue,'0000',@slicecage_rank,'0000',@galssid1,@galssid2);
                        call message(dates,'000a',@date);
                        set messagedate=@date;
                        select @date;
                        call log_key_value(@log_task,"msg",@date);
                        if @date is not null then 
                            set a=1;
                        end if;
                    end if;
                end if;
        
                #进片
                if a=0 then
                select a;
                    call input(machineids,@发送字,@发送ID,@格子,@err);
                    call intTo2ByteHex10_16_4(@发送字,@returnvalue);
                    call intTo2ByteHex10_16_4(@发送ID,@typeid);
                    call intTo2ByteHex10_16_4(@格子,@slicecage_rank);
                    set dates=CONCAT(@returnvalue,@typeid,@slicecage_rank);
                    select @slicecage_rank;
                    select @returnvalue;
                    select @typeid;
                    call message(dates,'000a',@date);
                    set messagedate=@date;
                end if;
    
    end if;
        
elseif @var='3' then
        
    if flag=1 then
                call input(machineids,@发送字,@发送ID,@格子,@err);
                call intTo2ByteHex10_16_4(@发送字,@returnvalue);
                call intTo2ByteHex10_16_4(@发送ID,@typeid);
                call intTo2ByteHex10_16_4(@格子,@slicecage_rank);
                set dates=CONCAT(@returnvalue,@typeid,@slicecage_rank);
                call message(dates,'000a',@date);
                set messagedate=@date;
        
        
    #进出片
    elseif flag=3 then
        select @work_groups;
                    call input(machineids,@发送字,@发送ID,@格子,@err);
                    call intTo2ByteHex10_16_4(@发送字,@returnvalue);
                    call intTo2ByteHex10_16_4(@发送ID,@typeid);
                    call intTo2ByteHex10_16_4(@格子,@slicecage_rank);
                    set dates=CONCAT(@returnvalue,@typeid,@slicecage_rank);
                    call message(dates,'000a',@date);
                    set messagedate=@date;
    
    end if;
        
elseif @var='2' then
 
--     select rank,type_id,galss_id,processcard_id,width,height into @rankid,@type_id,@galss_id,@processcardid,@width,@height from gmms_galss_task where work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id order by rank limit 1;
--     UPDATE gmms_galss_task SET work_procedure='理片',work_state='出库中' where rank=@rankid and engineering_id=@engineering_id;
--     UPDATE gmms_var set value=格子 where varname='last_pos' and groups=@work_groups;
--     update gmms_machine set remarks='3' where id=machineids;
--     
--     call intTo2ByteHex10_16_4(3,@returnvalue);
--     call intTo2ByteHex10_16_4(@galss_id,@typeid);
--     call intTo2ByteHex10_16_4(1,@slicecage_rank);
--     set dates=CONCAT(@returnvalue,@typeid,@slicecage_rank);
--     call message(dates,'000a',@date);
--     set messagedate=@date;
    
    
    select rank,type_id,galss_id,processcard_id,width,height into @rankid,@type_id,@galss_id,@processcardids,@width,@height from gmms_galss_task where work_procedure='理片' and work_state='等待中' and engineering_id=@engineering_id order by rank limit 1;
    select @processcardids;
    if @processcardids is not null then
    
    select id into @drop_id from gmms_drop_frame where processcard_id=@processcardids;
    select @drop_id;
    if @drop_id is not null then
    
        UPDATE gmms_galss_task SET work_procedure='理片',work_state='出库中' where rank=@rankid and engineering_id=@engineering_id;
        UPDATE gmms_var set value=1 where varname='last_pos' and groups=@work_groups;
        update gmms_machine set remarks='3' where id=machineids;
        call intTo2ByteHex10_16_4(3,@returnvalue);
        call intTo2ByteHex10_16_4(@galss_id,@typeid);
        call intTo2ByteHex10_16_4(1,@slicecage_rank);
        set dates=CONCAT(@returnvalue,@typeid,@slicecage_rank);
        call message(dates,'000a',@date);
        set messagedate=@date;
    else
        SELECT id,stops into @drop_pos,@stops from gmms_drop_frame where state='空架' and groups=@work_groups limit 1;
        select @drop_pos;
        if @drop_pos  is not null then 
            SELECT 流程卡,架号,总数,工程号 into @processcardid,@drop_frame,@processcard_count,@engineering_ids from processcard_ex where  流程卡=@processcardids;
            UPDATE gmms_drop_frame set state='使用中',drop_frame=@drop_frame,processcard_id=@processcardid,processcard_count=@processcard_count,engineering_id=@engineering_ids where id=@drop_pos;
            UPDATE gmms_galss_task SET work_procedure='理片',work_state='出库中',stop_position=@stops where rank=@rankid and engineering_id=@engineering_id;
            UPDATE gmms_var set value=1 where varname='last_pos' and groups=@work_groups;
            update gmms_machine set remarks='3' where id=machineids;
            
            call intTo2ByteHex10_16_4(3,@returnvalue);
            call intTo2ByteHex10_16_4(@galss_id,@typeid);
            call intTo2ByteHex10_16_4(1,@slicecage_rank);
            set dates=CONCAT(@returnvalue,@typeid,@slicecage_rank);
            call message(dates,'000a',@date);
            set messagedate=@date;
        end if;
    end if;    
    end if;
    
    
elseif @var='4' then
            if @work_groups=3 and @work_groups=2  and position("P" in @engineering_id)>0 then
                    call output2(machineids,@发送字,@发送ID1,@发送ID2,@格子,@err);
                else
                    call output(machineids,@发送字,@发送ID1,@发送ID2,@格子,@err);
                end if;
                call intTo2ByteHex10_16_4(@发送字,@returnvalue);
                call intTo2ByteHex10_16_4(@发送ID1,@galssid1);
                call intTo2ByteHex10_16_4(@发送ID2,@galssid2);
                call intTo2ByteHex10_16_4(@格子,@slicecage_rank);
                set dates=CONCAT(@returnvalue,'0000',@slicecage_rank,'0000',@galssid1,@galssid2);
                call message(dates,'000a',@date);
                set messagedate=@date;
        
end if;
    
    
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for SteelAfterCompound
-- ----------------------------
DROP PROCEDURE IF EXISTS `SteelAfterCompound`;
delimiter ;;
CREATE PROCEDURE `SteelAfterCompound`()
BEGIN
    #Routine body goes here...
    #一号线钢化后复合台
    DECLARE dates varchar(255);
    DECLARE messagedate varchar(255);
    select count(*),edg_width,edg_height,thickness,angle,marking_flag 
    into @counts,@width,@height,@thickness,@angle,@marking_flag from gmms_galss_task_2 
    where galss_id=rankids and work_state='待复合' and work_procedure='钢化后复合' and groups=@work_groups;
    
    #此处修改                    
    if @angle=1 then 
        select gang_hou_zhuan into @z_angle from gmms_dongzuo_table where gmms_dongzuo_table.number=@marking_flag;
  else
        select gang_hou_bu_zhuan into @z_angle from gmms_dongzuo_table where gmms_dongzuo_table.number=@marking_flag;
    end if;
    
    call intTo2ByteHex10_16_4(@width,@widths);
    call intTo2ByteHex10_16_4(@height,@heights);
    call intTo2ByteHex10_16_4(@thickness,@thicknesss);
    call intTo2ByteHex10_16_4(@z_angle,@angles);
                    
    if @heights!=null and @heights!='' and 
         @widths!=null and @widths!='' and
         @thicknesss!=null and @thicknesss!='' and
       @angles!=null and @angles!=''     
    then
        if @angle=1 or @angle=3 then
            set dates=CONCAT(@heights,@widths,@thicknesss,@angles,'000000000001');
        else
            set dates=CONCAT(@widths,@heights,@thicknesss,@angles,'000000000001');
        end if;                    
        call message(dates,'000e',@date);
        set messagedate=@date;    
        update gmms_galss_task_2 set work_state='正在工作' 
        where  galss_id=rankids and work_state='待复合' and work_procedure='钢化后复合' and groups=@work_groups;    
    end if;    
        
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for StopFinshManual
-- ----------------------------
DROP PROCEDURE IF EXISTS `StopFinshManual`;
delimiter ;;
CREATE PROCEDURE `StopFinshManual`(in gId varchar(50))
BEGIN
-- 查询玻璃工程信息
select processcard_id into @processcard_id from gmms_galss_task where id=gId;
 
set @sRank_=null;
-- 查询下一个的落架顺序
select count(*) into @sRank_ From gmms_galss_task_stock where processcard_id =@processcard_id;
 
-- 更新玻璃状态
update gmms_galss_task set work_state='已完成',work_procedure='下片' ,stop_rank=@sRank_+1,finsh_time=now(),work_procedure_number=500,broken_state=999 where id=gId;
 
-- 插入玻璃
select count(*) into @c1 from gmms_galss_task_details where id = gId;
select count(*) into @c2 from gmms_galss_task_stock where id = gId;
 
if @c1=0 then
insert into gmms_galss_task_details select * from gmms_galss_task where id=gId;
end if;
if @c2=0 then
insert into gmms_galss_task_stock select * from gmms_galss_task where id=gId;
 
 
end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for Stops
-- ----------------------------
DROP PROCEDURE IF EXISTS `Stops`;
delimiter ;;
CREATE PROCEDURE `Stops`(in sendMessageHex varchar(255),in machineids BIGINT,out messagedate varchar(255))
BEGIN
    #下片机存储过程
    #找到当前机器标志位
    #查询机器逻辑表中对应的逻辑进行对应的步骤
    DECLARE machinedisposeids int DEFAULT 0;
    DECLARE ids int ;
    DECLARE plcfindid varchar(255);
    DECLARE dates varchar(255);
    DECLARE plcid varchar(255);
    DECLARE findplc varchar(255);
    DECLARE findmes varchar(255);
    DECLARE taskplc varchar(255);
    DECLARE taskmes varchar(255);
    DECLARE finsh_rankid BIGINT;
    DECLARE send_rankid BIGINT;
    DECLARE rankids varchar(255);
    DECLARE posunmes varchar(255);
    DECLARE messagedates varchar(255) DEFAULT '';
    
    set @begin_time = null;
    set @end_time = null;
    set @begin_time = SYSDATE();
    
    
    set messagedate=messagedates;
    set @stops=null;
    
    select machine_type_id,remarks into @mtid,@remarks from gmms_machine where id=machineids;
    
    set ids = cast(@remarks as UNSIGNED INTEGER);
    select stops into @stops from gmms_drop_frame where id=@remarks;
    
    select mf.flag into @完成标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='完成字';
    
    select mf.flag into @请求标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='请求字';
    
    select mf.flag into @发送标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='发送字';
    
    select mf.flag into @完成确认标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='完成确认字';
    
    if machineids=5 or machineids=8 then
        set @完成标志位=@完成标志位-1;
        set @完成确认标志位=@完成确认标志位-4;
    end if;
    
    set finsh_rankid = cast(@完成标志位 as UNSIGNED INTEGER)+1;
    set send_rankid = cast(@请求标志位 as UNSIGNED INTEGER)+1;
    
    set findplc = substring(sendMessageHex,(cast(@完成标志位 as UNSIGNED INTEGER)*4)+19,4);
    set taskplc = substring(sendMessageHex,(cast(@请求标志位 as UNSIGNED INTEGER)*4)+19,4);
    set taskmes = substring(sendMessageHex,(cast(@发送标志位 as UNSIGNED INTEGER)*4)+19,4);
    set findmes = substring(sendMessageHex,(cast(@完成确认标志位 as UNSIGNED INTEGER)*4)+19,4);
    set plcfindid = substring(sendMessageHex,(cast(8 as UNSIGNED INTEGER)*4)+19,4);
    
    
    
    select taskplc;
    select taskmes;
    select findplc;
    select findmes;
    select plcfindid;
    
    set rankids = conv(substring(sendMessageHex,(cast(send_rankid as UNSIGNED INTEGER)*4)+19,4),16,10);
    select rankids;
 
#完成逻辑查询
 
    select count(*),md.id into @完成数量,@完成逻辑编号 from gmms_machine_dispose md join gmms_machine_type mt on md.machine_type_id=mt.id where md.machine_type_id=@mtid  and md.plc_font_type='完成字' and md.mes_font_type='完成确认字' and md.plc_font_value=findplc and md.mes_font_value=findmes;
 
    
    
    #请求逻辑查询
    select count(*),md.id into @请求数量,@请求逻辑编号 from gmms_machine_dispose md join gmms_machine_type mt on md.machine_type_id=mt.id where md.machine_type_id=@mtid  and md.plc_font_type='请求字' and md.mes_font_type='发送字' and md.plc_font_value=taskplc and md.mes_font_value=taskmes;
    
    if machineids=5 then
        if @stops>0 then
                update gmms_machine set remarks=null where id=machineids;
                call intTo2ByteHex10_16_4(@stops,@id);
                call message(@id,'0024',@date);
                set messagedate=@date;
        end if;
    end if;
    
    
                
        select plcfindid,@完成数量,@请求数量,@stops,@remarks;
    if plcfindid="0001" then
                
                set dates=CONCAT("000000000000");    
                call message(dates,'001b',@date);
                set messagedate=@date;
    elseif @stops>0 then
        #界面点的
            update gmms_machine set remarks=null where id=machineids;
                call intTo2ByteHex10_16_4(@stops,@id);
                set dates=CONCAT("0001",@id);    
                call message(dates,'001b',@date);
                set messagedate=@date;
    #判断逻辑是否存在
    elseif @完成数量=1 or @请求数量=1  then
        #判断完成逻辑是否为空
        if @完成逻辑编号!=0 then
            set machinedisposeids=@完成逻辑编号;
            set rankids = conv(substring(sendMessageHex,(cast(finsh_rankid as UNSIGNED INTEGER)*4)+19,4),16,10);
        #判断请求逻辑是否为空
        elseif @请求逻辑编号!=0 then
            set machinedisposeids=@请求逻辑编号;
            set rankids = conv(substring(sendMessageHex,(cast(send_rankid as UNSIGNED INTEGER)*4)+19,4),16,10);
            
        end if;
        #查询当前执行逻辑进行判断
        select logic,return_value into @ExecutionLogic,@returnvalue from gmms_machine_dispose where id=machinedisposeids;
        if @ExecutionLogic='任务完成' then
                call     StopsFinsh(sendMessageHex,machineids,@returnvalue,1,rankids,@messagedate);
                set messagedate=@messagedate;
        elseif @ExecutionLogic='完成破损' then
                call     StopsFinsh(sendMessageHex,machineids,@returnvalue,2,rankids,@messagedate);
                set messagedate=@messagedate;        
         elseif @ExecutionLogic='完成清空' then    
 
                set dates=CONCAT(@returnvalue,"0000");    
                if machineids=5 or machineids=8 then 
                    call message(dates,'0014',@date);
                else
                    call message(dates,'0018',@date);
                end if;
                set messagedate=@date;
                
                
        elseif @ExecutionLogic='任务请求' then
                    call StopsSend(machineids,@returnvalue,rankids,@messagedate);
                    set messagedate=@messagedate;
                    select '请求';
                
         elseif @ExecutionLogic='任务清空' then
                
                set dates=CONCAT(@returnvalue,"000000000000000000000000000000000000");
                call message(dates,'000a',@date);
                set messagedate=@date;
 
                
        end if;
    #根据发送过来的id查找任务发送过去
--     elseif rankids>0 then
-- --             set rankids = conv(substring(sendMessageHex,(cast(send_rankid as UNSIGNED INTEGER)*4)+19,4),16,10);
-- --             select rankids;
--         if  machineids=22 then
--             call StopsSend(machineids,@returnvalue,rankids,@messagedate);
--             set messagedate=@messagedate;
--         end if;
    end if;
set @end_time = SYSDATE();
#  机器人id等于75时是一号线下片机的任务
if machineids=75 then
    insert into A_JiXieHand(begin_time,end_time,content)values
    # @ExecutionLogic 做拼接将这个任务拼接记录
    (@begin_time,@end_time,CONCAT(IFNULL(@ExecutionLogic,''),':',IFNULL(messagedate,'')));
end if;
 
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for StopsFinsh
-- ----------------------------
DROP PROCEDURE IF EXISTS `StopsFinsh`;
delimiter ;;
CREATE PROCEDURE `StopsFinsh`(in sendMessageHex varchar(255),in machineids BIGINT,in returnvalue varchar(255),in flag int,in rankid BIGINT,out messagedate varchar(255))
BEGIN
    #下片机完成存储过程
    #找到正在工作的任务进行完成
    DECLARE count1 int;
    DECLARE count2 int;
    DECLARE dates varchar(255);
    DECLARE messagedates varchar(255) DEFAULT '';
 
    
    set messagedate=messagedates;
 
    
    select machine_type_id,work_id into @mtid,@work_groups from gmms_machine where id=machineids;
    
    select file_name into @engineering_id from gmms_raw_file where operator=@work_groups and state='已领取';
    
    select rankid;
    
    select count(*),drop_frame,processcard_id,galss_type,id,stop_position into @counts,@drop_frame,@processcard_id,@galss_type,@id1,@stoppost from gmms_galss_task 
    where work_state='正在工作' and work_procedure='下片' and out_rank=rankid and engineering_id=@engineering_id;
    select stops,finsh_count,processcard_count into @id,@sum,@processcard_count from gmms_drop_frame where drop_frame=@drop_frame and processcard_id=@processcard_id and groups=@work_groups;
    
    select count(*) into @maxstoprank from gmms_galss_task_stock where id>(select min(id) from (select * from gmms_galss_task_stock order by id desc limit 40000) as tbmin) and processcard_id=@processcard_id;
    
    select @counts,1,flag;
    #任务完成
    if flag=1 then
         
        if machineids=5 or machineids=8 then
            if @counts>0 then
                set count1=@maxstoprank+1;
                set count2=@sum+1;
                if @stoppost>12 and false then
                    update gmms_galss_task set work_state='已完成',gc_stockid=@work_groups,stop_rank=count1,finsh_time=now(),work_procedure_number=500 
                    where work_state='等待中' and work_procedure='机器人下片' and out_rank=rankid and engineering_id=@engineering_id;
                else
                    update gmms_galss_task set work_state='已完成',gc_stockid=@work_groups,stop_rank=count1,finsh_time=now(),work_procedure_number=500 
                    where work_state='正在工作' and work_procedure='下片' and out_rank=rankid and engineering_id=@engineering_id;
                end if;
                
                update gmms_drop_frame set finsh_count=count2 where processcard_id=@processcard_id and groups=@work_groups;
                select count(*) into @count8    from gmms_galss_task_stock where id=@id1;
                if @galss_type=0 and @count8=0 and @stoppost<13 then
                    insert into gmms_galss_task_details select * from gmms_galss_task where engineering_id=@engineering_id and out_rank=rankid;
                    insert into gmms_galss_task_stock select * from gmms_galss_task where engineering_id=@engineering_id and out_rank=rankid;
                end if;
                select count(*) into @findcount from gmms_galss_task where processcard_id=@processcard_id and engineering_id=@engineering_id and work_state='已完成' and work_procedure='下片';
                select count(*) into @posuncount from gmms_galss_task where processcard_id=@processcard_id and engineering_id=@engineering_id and work_state='破损';
                if @processcard_count=@findcount+@posuncount then
                    call workmanships(@processcard_id);
                end if;
                if @processcard_count=count2 then
                    call intTo2ByteHex10_16_4(@id,@ids);
                    set dates=CONCAT(@ids,'0000',returnvalue);
                    call message(dates,'0012',@date);
                    set messagedate=@date;
                else
                    call message(returnvalue,'0014',@date);
                    set messagedate=@date;
                end if;
            else
                call message(returnvalue,'0014',@date);
                set messagedate=@date;
            end if;
        elseif machineids=75 then
            #新加机械手
            call y_RobotLengFinsh(flag,machineids,returnvalue,rankid,dates);
            set messagedate=dates;
        elseif machineids=17 or machineids=22 then 
            if @counts>0 then
                set count1=@maxstoprank+1;
                set count2=@sum+1;
                 update gmms_galss_task set work_state='已完成',gc_stockid=@work_groups,stop_rank=count1,finsh_time=now(),work_procedure_number=500 
                where work_state='正在工作' and work_procedure='下片' and out_rank=rankid and engineering_id=@engineering_id;
                update gmms_drop_frame set finsh_count=count2 where processcard_id=@processcard_id and groups=@work_groups;
                select count(*) into @count8    from gmms_galss_task_stock where id=@id1;
                if @galss_type=0 and @count8=0 then
                    insert into gmms_galss_task_details select * from gmms_galss_task where engineering_id=@engineering_id and out_rank=rankid;
                    insert into gmms_galss_task_stock select * from gmms_galss_task where engineering_id=@engineering_id and out_rank=rankid;
                end if;
                select count(*) into @findcount from gmms_galss_task where processcard_id=@processcard_id and engineering_id=@engineering_id and work_state='已完成' and work_procedure='下片';
                select count(*) into @posuncount from gmms_galss_task where processcard_id=@processcard_id and engineering_id=@engineering_id and work_state='破损';
                if @processcard_count=@findcount+@posuncount then
                    call workmanships(@processcard_id);
                end if;
                if @processcard_count=count2 then
                    call intTo2ByteHex10_16_4(@id,@ids);
                    set dates=CONCAT(returnvalue,'00000000000000000001');
                    call message(dates,'0018',@date);
                    set messagedate=@date;
                else
                    call message(returnvalue,'0018',@date);
                    set messagedate=@date;
                end if;
            
    
            end if;
        end if;
        
    #任务破损
    elseif flag=2 then
    
        if @counts>0 then
            if machineids=5 or machineids=8 then
                update gmms_galss_task set work_state='破损',work_procedure_number=500 where work_state='正在工作' and work_procedure='下片' and out_rank=rankid and engineering_id=@engineering_id;
                call message(returnvalue,'0014',@date);
                set messagedate=@date;
            elseif machineids=17 or machineids=22 then 
                update gmms_galss_task set work_state='破损',work_procedure_number=500 where work_state='正在工作' and work_procedure='下片' and out_rank=rankid and engineering_id=@engineering_id;
                call message(returnvalue,'0018',@date);
                set messagedate=@date;
            end if;
            
    
        end if;
    
    end if;
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for StopsSend
-- ----------------------------
DROP PROCEDURE IF EXISTS `StopsSend`;
delimiter ;;
CREATE PROCEDURE `StopsSend`(in machineids BIGINT,in returnvalue varchar(255),in rankid BIGINT,out messagedate varchar(255))
BEGIN
    #下片机发送任务存储过程
    #找到等待中的任务,把下片位置,宽度,高度,厚度发送给plc
    DECLARE dates varchar(255);
    DECLARE messagedates varchar(255) DEFAULT '';
    set messagedate=messagedates;
    
    select machine_type_id,work_id into @mtid,@work_groups from gmms_machine where id=machineids;
    
    select file_name into @engineering_id from gmms_raw_file where operator=@work_groups and state='已领取';
    select @engineering_id;
    
    if machineids=17 or machineids=22 then
        
        select count(*) into @counts from gmms_galss_task where work_state='等待中' and work_procedure='下片' and out_rank=rankid and engineering_id=@engineering_id;
        select drop_frame,width,height,thickness,processcard_id,galss_type,color into @drop_frame,@width,@height,@thickness,@processcard_id,@galss_type,@color from gmms_galss_task where work_state='等待中' and work_procedure='下片' and out_rank=rankid and engineering_id=@engineering_id; 
        select stops,finsh_count into @id,@finsh_count from gmms_drop_frame where drop_frame=@drop_frame and processcard_id=@processcard_id and groups=@work_groups;
        select @id,@processcard_id,@counts;
        #判断是否有等待的任务
        
        if @counts=1 then        
            call intTo2ByteHex10_16_4(@width,@widths);
            call intTo2ByteHex10_16_4(@height,@heights);
            call intTo2ByteHex10_16_4(@thickness,@thicknesss);
            call intTo2ByteHex10_16_4(@id,@ids);
            call intTo2ByteHex10_16_4(rankid,@rankids);
            select @widths,@heights,@thicknesss,@ids;
            
            if machineids=17 or machineids=22 then 
            select marking_flag into @z_mkk from gmms_galss_task  where work_state='等待中' and work_procedure='下片' and out_rank=rankid and engineering_id=@engineering_id; 
                select qing_xi_hou_zhua into @z_zhua from gmms_dongzuo_table where number=@z_mkk;
            set @z_zhua=CONCAT("000",@z_zhua);
                if @galss_type=0 and @color!='F' then
                    set dates=CONCAT(returnvalue,@rankids,'00000000',@ids,@heights,@widths,@thicknesss,@z_zhua);
                else
                    set dates=CONCAT(returnvalue,@rankids,'00000000',@ids,@heights,@widths,@thicknesss,'0001');
                end if;    
            #    set dates=CONCAT(returnvalue,@rankids,'00000000',@ids,@heights,@widths,@thicknesss,'0001');
            else         
                set dates=CONCAT(returnvalue,@rankids,'00000000',@ids,@heights,@widths,@thicknesss,'0001');
            end if;
            
            call message(dates,'000a',@date);                
            set messagedate=@date;
            if messagedate is not null then        
                update gmms_galss_task set work_state='正在工作' where work_state='等待中' and work_procedure='下片' and out_rank=rankid and     engineering_id=@engineering_id;
            end if;
            
        end if;
    elseif machineids=75 then
        #新加机械手
        
        call y_RobotLeng(machineids,returnvalue,rankid,dates);
        set messagedate=dates;
    elseif machineids=5 then
        #一号线 下片机
        select count(*) into @counts from gmms_galss_task 
        where work_state='等待中' and work_procedure='下片'  and engineering_id=@engineering_id order by out_rank limit 0,1;
        
        select out_rank,stop_position into @out_rank1,@stop_position from gmms_galss_task 
        where work_state='正在工作' and work_procedure='下片'  and engineering_id=@engineering_id limit 0,1;
        
--         select id,drop_frame,width,height,thickness,processcard_id,out_rank into @gid_,@drop_frame,@width,@height,@thickness,@processcard_id,@out_rank from gmms_galss_task 
--         where work_state='等待中' and work_procedure='下片'  and engineering_id=@engineering_id order by out_rank limit 0,1;
        #修改   发送磨边后的宽高   下片机精度从0.1mm>1mm  2024/1/19
        select id,drop_frame,edg_width,edg_height,thickness,processcard_id,out_rank into @gid_,@drop_frame,@width,@height,@thickness,@processcard_id,@out_rank from gmms_galss_task 
        where work_state='等待中' and work_procedure='下片'  and engineering_id=@engineering_id order by out_rank limit 0,1;
        
        
        select stops,finsh_count into @id,@finsh_count from gmms_drop_frame 
        where drop_frame=@drop_frame and processcard_id=@processcard_id and groups=@work_groups;
        
        
        select processcard_id into @processcard_id1 from gmms_drop_frame where  stops=1 and groups=@work_groups;
        select processcard_id into @processcard_id2 from gmms_drop_frame where  stops=2 and groups=@work_groups;
        select count(*) into @sumprocesscardid1 from gmms_galss_task where processcard_id=@processcard_id1 and work_state!='破损' and engineering_id=@engineering_id;
        select count(*) into @sumprocesscardid2 from gmms_galss_task where processcard_id=@processcard_id2 and work_state!='破损' and engineering_id=@engineering_id;
        if @id=3 or @id=4 or @id=5 then
            set @id=3;
            if @sumprocesscardid1=0 then
                set @sumprocesscardid1=88;
            end if;    
            if @sumprocesscardid2=0 then
                set @sumprocesscardid2=88;
            end if;
        end if;
        #判断是否有等待的任务
        select @counts,@out_rank1,@stop_position,@engineering_id,@id;
        
        #set @counts=1,@out_rank=1,@width=934,@height=483,@thickness=5,@id=3,@sumprocesscardid1=0,@sumprocesscardid2=0;
        
        if @counts=1 then 
            if @out_rank is not null then 
                    if @id=3 then
                        update gmms_galss_task set work_state='等待中',work_procedure='机器人下片' 
                        where work_state='等待中' and work_procedure='下片' and out_rank=@out_rank and engineering_id=@engineering_id;
                    else
                        update gmms_galss_task set work_state='正在工作' where work_state='等待中' and work_procedure='下片' and out_rank=@out_rank and engineering_id=@engineering_id;
                    end if;        
                    call intTo2ByteHex10_16_4(@out_rank,@out_ranks);
                    call intTo2ByteHex10_16_4(@width,@widths);
                    call intTo2ByteHex10_16_4(@height*10,@heights);
                    call intTo2ByteHex10_16_4(@thickness*10,@thicknesss);
                    call intTo2ByteHex10_16_4(@id,@ids);
                    call intTo2ByteHex10_16_4(@sumprocesscardid1,@sumprocesscardids1);
                    call intTo2ByteHex10_16_4(@sumprocesscardid2,@sumprocesscardids2);
                    select @widths;
                    select @heights;
                    select @thicknesss;
                    select @ids;
                    set dates=CONCAT(returnvalue,@out_ranks,@ids,@widths,@heights,@thicknesss,@sumprocesscardids1,@sumprocesscardids2);
                    call message(dates,'000a',@date);
                    set messagedate=@date;
                    insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,IFNULL(@id,0),NOW(),'发送下片机任务',IFNULL(@gid_,0),messagedate);
            end if;
        
        end if;
--         if (select software_connect from gmms_machine where id=5)=0 then
--             #set dates=CONCAT(returnvalue,'0001','0001','7fbc','3a98','003c');
--             set dates=CONCAT(returnvalue,'0001','0001','0ccf','5dc0','003c');
--             call message(dates,'000a',@date);
--             set messagedate=@date;
--             update gmms_machine set software_connect=10 where id=5;
--             insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,0,NOW(),'发送下片机测试任务',0,messagedate);
--         end if;
        
        if @counts=1 and false then
            if @out_rank1 is not null then
                if @stop_position=2 then
                    update gmms_galss_task set work_state='正在工作' 
                    where work_state='等待中' and work_procedure='下片' and out_rank=@out_rank and engineering_id=@engineering_id;                                                
                    call intTo2ByteHex10_16_4(@out_rank,@out_ranks);
                    call intTo2ByteHex10_16_4(@width*10,@widths);
                    call intTo2ByteHex10_16_4(@height*10,@heights);
                    call intTo2ByteHex10_16_4(@thickness*10,@thicknesss);
                    call intTo2ByteHex10_16_4(@id,@ids);
                    call intTo2ByteHex10_16_4(@sumprocesscardid1,@sumprocesscardids1);
                    call intTo2ByteHex10_16_4(@sumprocesscardid2,@sumprocesscardids2);
                    select @widths;
                    select @heights;
                    select @thicknesss;
                    select @ids;
                    set dates=CONCAT(returnvalue,@out_ranks,@ids,@widths,@heights,@thicknesss,@sumprocesscardids1,@sumprocesscardids2);
                    call message(dates,'000a',@date);
                    set messagedate=@date;
                end if;
            else
                select @counts,@out_rank1,@stop_position,@engineering_id ;
                update gmms_galss_task set work_state='正在工作' 
                where work_state='等待中' and work_procedure='下片' and out_rank=@out_rank and engineering_id=@engineering_id;
                call intTo2ByteHex10_16_4(@out_rank,@out_ranks);
                call intTo2ByteHex10_16_4(@width*10,@widths);
                call intTo2ByteHex10_16_4(@height*10,@heights);
                call intTo2ByteHex10_16_4(@thickness*10,@thicknesss);
                call intTo2ByteHex10_16_4(@id,@ids);
                call intTo2ByteHex10_16_4(@sumprocesscardid1,@sumprocesscardids1);
                call intTo2ByteHex10_16_4(@sumprocesscardid2,@sumprocesscardids2);
                select @widths;
                select @heights;
                select @thicknesss;
                select @ids;
                set dates=CONCAT(returnvalue,@out_ranks,@ids,@widths,@heights,@thicknesss,@sumprocesscardids1,@sumprocesscardids2);
                call message(dates,'000a',@date);
                set messagedate=@date;
            end if;
            
        end if;
    
    end if;
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for supplement_action
-- ----------------------------
DROP PROCEDURE IF EXISTS `supplement_action`;
delimiter ;;
CREATE PROCEDURE `supplement_action`(in action varchar(30),in ids text,out message varchar(255))
BEGIN
   DECLARE thick double;
     DECLARE color varchar(30);
     DECLARE p_id bigint;
     set thick=0;
  set message="nothing";
 
    #Routine body goes here...
   if action="cancel" then
           set @idx=0;
           set @id="";
            while @id is not null do  
              set @id=null;
                call getId(ids,@idx, @id);
               set @idx=@idx+1;
                 if @id is not null then 
                    update supplement_liuchengkafua set state="撤销" where id=@id and state="未领取";
                 end if;            
            end while;
            set message="success";
     end if;
     
     
     if action="create" then 
          set @id="";
            # 检查是否有不同磨系厚度
            set @idx=0;
            while @id is not null do
              set @id=null;
                call getId(ids,@idx, @id);
               set @idx=@idx+1;
                 if @id is not null then 
                     SET @thick=null;
                         SELECT houdu,yanse into @thick,@color from supplement_liuchengkafua where id=@id and state="未领取";
                     if @thick is null then 
                            set @id=null;
                                set thick=null;
                                set message="只有'未领取'的补片项才能创建补片工程";
                            else 
                             if thick=0 then 
                                 set thick=@thick;
                                       set color=@color;
                                  else 
                                       if thick!=@thick then 
                                           set @id=null;
                                             set thick=null;
                                             set message="只有相同厚度补片项才能创建工程";
                                         end if;
                              end if;
                         end if;     
                 end if;            
             end while;
        if thick is not null then 
            if thick>0 then 
                    set @inc_id=1;
                    set @firstcard=null;
                  set @gongcheng=null;
                    set @gongcheng_id=null;
                    call create_empty_raw_file("补片",@gongcheng_id, @gongcheng);
                    set @id=1;
                    set @idx=0;
                      while @id is not null do
                            set @id=null;
                            call getId(ids,@idx, @id);
                            if @id is not null then 
                                set @shuliang=0;
                              SELECT liuchengkahao,kuan,gao,houdu,yanse,shuliang into @card,@kuan,@gao,@houdu,@yanse,@shuliang  from supplement_liuchengkafua where id=@id and state='未领取';            
                                 set @marking_flag=1;
                                 if @kuan<@gao then 
                                    set @tmpw=@kuan;
                                        set @kuan=@gao;
                                        set @gao=@tmpw;
                                        set @marking_flag=2;
                                 end if;
                             
                             while @shuliang>0 do
 
                              if @firstcard is null then 
                                 set @firstcard=@card;
                                end if;
                                 INSERT INTO  gmms_galss_task_buffer
                                 (rank,type_id,galss_id,pattern_id,width,height
,thickness,color,edg_width,edg_height,chamfer_size,galss_type,edg_speed1,edg_speed2
,fine_throwing,work_state,work_procedure,slicecage_rank,drop_frame,slicecage_flag
,out_rank,start_time,finsh_time,stop_position,processcard_id,engineering_id
,broken_state,stop_rank,work_procedure_number,gc_number,gc_width,gc_height
,gc_stockid,marking_flag
)  
                                  VALUES
                                 (0,0,@inc_id,null,@kuan,@gao,@houdu,@yanse,@kuan,@gao,0,0,0,0
                                 ,0,'待识别','测量','0','A1','0',
                                 0,now(),null,0,@firstcard,@gongcheng,0,0,100,@gongcheng,0,0,0,@marking_flag
                                 );
                                set @inc_id=@inc_id+1;
                             
                               set @shuliang=@shuliang-1;
                             end while;
                                 update supplement_liuchengkafua set state='已领取' where id=@id;
                                set @idx=@idx+1;
                            end if;
                         
                      end while;
                        
                
                        call make_galss_task_typeid(@gongcheng);
                        insert into gmms_pattern_task_buffer (rank,raw_type,raw_thickness,raw_width,raw_height,color,work_state,engineering_id,task_id)
                        value (0,concat(thick,@color),thick,0,0,@color,'已完成',@gongcheng,0);
                        
                        set p_id=LAST_INSERT_ID();
                        update gmms_galss_task_buffer set pattern_id=p_id where engineering_id=@gongcheng;
                        
                        
                    set message="success";        
             else 
                set message="nopiece";
            end if;
             end if;
     end if;
      
        
     
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for task_changed
-- ----------------------------
DROP PROCEDURE IF EXISTS `task_changed`;
delimiter ;;
CREATE PROCEDURE `task_changed`(in _id bigint, in ow varchar(50),in os varchar(50),in nw varchar(50),in ns varchar(50) ,in work_seg varchar(50))
BEGIN
    #Routine body goes here...
    declare cr_w varchar(50);
    declare cr_st int;
    declare cr_ss int;
    declare done int default(0);
    #  日志状态查询游标
declare cur cursor for
              SELECT work_name,`status`,`segment_status` from gmms_glass_log_config where segment=work_seg  
                and work_proc=nw and work_status=ns order by  work_number asc;
                DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1;
        set @tm=now();        #日志时间
        set @ss=null;          #存玻璃在该工艺段的全局状态
        set @wk=null;            #存当前工艺段的名称
        open cur;
        loop1: loop
                FETCH cur into cr_w,cr_st,cr_ss;
                if done=1 then 
                       LEAVE loop1;
                end if;
                # 更新开始时间和状态
                if cr_st=1 then 
                        UPDATE gmms_glass_log  set `status`=cr_st ,begin_time=@tm where glass_id=_id and segment_name=work_seg and work_name=cr_w and freeze=false;
                end if;
                # 更新结束时间和状态
                if cr_st>=100 then 
                        UPDATE gmms_glass_log  set `status`=cr_st ,end_time=@tm where glass_id=_id and segment_name=work_seg and work_name=                cr_w and freeze=false;
                        end if;
                # 存最后一个工艺段全局状态
                if cr_ss is not null then 
                    set @ss=cr_ss;
                    set @wk=cr_w;
                end if;        
        end loop loop1;
        close cur;
 
            # 这是一个重置标记,要冻结就日志,创建新日志
            if @ss=0 then 
                    UPDATE gmms_glass_log set freeze=true where glass_id=_id  and segment_name=work_seg; 
                    call glass_log_new(_id,work_seg);
            end if;        
            if @ss=1 then 
                        UPDATE gmms_glass_log  set `status`=@ss ,begin_time=@tm,work_name=@wk where glass_id=_id and segment_name=work_seg                         and  freeze=false and parent_id is null;
            end if;
            if @ss>=100 then 
                        UPDATE gmms_glass_log  set `status`=@ss ,end_time=@tm,work_name=@wk where glass_id=_id and segment_name=work_seg                         and  freeze=false and parent_id is null;
            end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for TemperingDamaged
-- ----------------------------
DROP PROCEDURE IF EXISTS `TemperingDamaged`;
delimiter ;;
CREATE PROCEDURE `TemperingDamaged`(in Damagedid BIGINT,out count BIGINT,out msg varchar(255))
BEGIN
    #Routine body goes here...
    #钢化破损  传入任务ID  返回修改行数
    update gmms_galss_task_2 set work_state='破损' where id=Damagedid;
    
    INSERT INTO e_pierceds(processcard_id, type_num, pieces, pierced_type, pierced_cause, is_report, glass_id, create_time, process, line, gc_number, cs_number, team_name)
    select gt.processcard_id,gt.edg_speed2,1,null,null,0,gt.id,NOW(),'钢化',gt.groups,gt.engineering_id,0,guc.banzu from gmms_galss_task_2 as gt 
    INNER join gmms_user_current as guc on gt.groups=guc.chanxian 
    left join e_pierceds as et on gt.id=et.glass_id 
    where guc.gongyi='钢化' and gt.id=Damagedid and et.glass_id is null;
    
    select count(*) into @Damagedcount from gmms_galss_task_2 where id=Damagedid and work_state='破损'; 
    select count(*) into @count from gmms_galss_task_2 where id=Damagedid;
    set count=@Damagedcount;
    if @Damagedcount=1 then
        set msg='ok';
    elseif @count=0 then    
        set msg='不存在此id';
    elseif @count=1 and @Damagedcount=0 then
        set msg='failure';
    end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for TemperingRank
-- ----------------------------
DROP PROCEDURE IF EXISTS `TemperingRank`;
delimiter ;;
CREATE PROCEDURE `TemperingRank`(in sendMessageHex varchar(255),in machineids BIGINT,out messagedate varchar(255))
BEGIN
    #下片机存储过程
    #找到当前机器标志位
    #查询机器逻辑表中对应的逻辑进行对应的步骤
    DECLARE machinedisposeids int DEFAULT 0;
    DECLARE ids int ;
    DECLARE plcfindid varchar(255);
    DECLARE dates varchar(255);
    DECLARE plcid varchar(255);
    DECLARE findplc varchar(255);
    DECLARE findmes varchar(255);
    DECLARE taskplc varchar(255);
    DECLARE taskmes varchar(255);
    DECLARE finsh_rankid BIGINT;
    DECLARE send_rankid BIGINT;
    DECLARE rankids varchar(255);
    DECLARE posunmes varchar(255);
    DECLARE messagedates varchar(255) DEFAULT '';
    set messagedate=messagedates;
    
    
    select machine_type_id,work_id into @mtid,@remarks from gmms_machine where id=machineids;
    set ids = cast(@remarks as UNSIGNED INTEGER);
    
    select mf.flag into @完成标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='完成字';
    
    select mf.flag into @请求标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='请求字';
    
    select mf.flag into @发送标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='发送字';
    
    select mf.flag into @完成确认标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='完成确认字';
    
    set finsh_rankid = cast(@完成标志位 as UNSIGNED INTEGER)+1;
    set send_rankid = cast(@请求标志位 as UNSIGNED INTEGER)+1;
    
    select @完成标志位;
    
    set findplc = substring(sendMessageHex,(cast(@完成标志位 as UNSIGNED INTEGER)*4)+19,4);
    set taskplc = substring(sendMessageHex,(cast(@请求标志位 as UNSIGNED INTEGER)*4)+19,4);
    set taskmes = substring(sendMessageHex,(cast(@发送标志位 as UNSIGNED INTEGER)*4)+19,4);
    set findmes = substring(sendMessageHex,(cast(@完成确认标志位 as UNSIGNED INTEGER)*4)+19,4);
    
    select taskplc;
    select taskmes;
    select findplc;
    select findmes;
    
    set rankids = conv(substring(sendMessageHex,(cast(1 as UNSIGNED INTEGER)*4)+19,4),16,10);
    select rankids;
 
#完成逻辑查询
    select count(*),md.id into @完成数量,@完成逻辑编号 from gmms_machine_dispose md join gmms_machine_type mt on md.machine_type_id=mt.id where md.machine_type_id=@mtid  and md.plc_font_type='完成字' and md.mes_font_type='完成确认字' and md.plc_font_value=findplc and md.mes_font_value=findmes;
    
    #请求逻辑查询
    select count(*),md.id into @请求数量,@请求逻辑编号 from gmms_machine_dispose md join gmms_machine_type mt on md.machine_type_id=mt.id where md.machine_type_id=@mtid  and md.plc_font_type='请求字' and md.mes_font_type='发送字' and md.plc_font_value=taskplc and md.mes_font_value=taskmes;
    
    if taskplc='0000' and taskmes!='0000' then
        set dates=CONCAT('0000',"000000000000000000000000");
        call message(dates,'000a',@date);
        set messagedate=@date;
    elseif findplc='0000' and findmes!='0000' then
        set dates=CONCAT('0000',"0000");    
        call message(dates,'0014',@date);
        set messagedate=@date;
    else
        #判断逻辑是否存在
        if @完成数量=1 or @请求数量=1  then
            #判断完成逻辑是否为空
            if @完成逻辑编号!=0 then
                set machinedisposeids=@完成逻辑编号;
            #判断请求逻辑是否为空
            elseif @请求逻辑编号!=0 then
                set machinedisposeids=@请求逻辑编号;    
            end if;    
            #查询当前执行逻辑进行判断
            select logic,return_value into @ExecutionLogic,@returnvalue from gmms_machine_dispose where id=machinedisposeids;
            select @ExecutionLogic;
            select @returnvalue;
            if @ExecutionLogic='任务清空' then
                set dates=CONCAT(@returnvalue,"000000000000000000000000");
                call message(dates,'000a',@date);
                set messagedate=@date;
            elseif @ExecutionLogic='任务完成' then
                call y_RackFinsh(machineids,1,@returnvalue,@messagedate);
                #call     TemperingRankFinsh_2(sendMessageHex,machineids,@returnvalue,1,@messagedate);
                set messagedate=@messagedate;            
            elseif @ExecutionLogic='任务失败' then    
                call y_RackFinsh(machineids,2,@returnvalue,@messagedate);
            elseif @ExecutionLogic='完成清空' then    
                set dates=CONCAT(@returnvalue,"0000");    
                call message(dates,'0014',@date);
                set messagedate=@date;
            elseif @ExecutionLogic='任务请求' then    
                call y_RackSend(machineids,@returnvalue,@messagedate);
                #call TemperingRankSend_2(machineids,@returnvalue,@messagedate);
                set messagedate=@messagedate;
                if messagedate is not null then
                    insert into aaaa(Content,Sendtext)
                    select '任务发送',messagedate;
                end if;                    
            end if;
        end if;
    end if;
 
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for TemperingRankFinsh_2
-- ----------------------------
DROP PROCEDURE IF EXISTS `TemperingRankFinsh_2`;
delimiter ;;
CREATE PROCEDURE `TemperingRankFinsh_2`(in sendMessageHex varchar(255),in machineids BIGINT,in returnvalue varchar(255),in flags int,out messagedate varchar(255))
BEGIN
    #下片机完成存储过程
    #找到正在工作的任务进行完成
    #移动料架
    if machineids=45 or machineids=69 then
        #钢化后的料架
        call y_RankTemperingAfterFinsh(machineids,returnvalue,messagedate);
    elseif machineids=51 or machineids=70 or machineids=72 or machineids=74 then
        call y_RankHollowFinsh(machineids,returnvalue,messagedate);
    elseif machineids=49 then
        call y_RankSlicecageFinsh(machineids,returnvalue,messagedate);        
    end if;
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for TemperingRankSend_2
-- ----------------------------
DROP PROCEDURE IF EXISTS `TemperingRankSend_2`;
delimiter ;;
CREATE PROCEDURE `TemperingRankSend_2`(in machineids BIGINT,in returnvalue varchar(255),out messagedate varchar(255))
BEGIN
    #移动料架
    
    if machineids=45 or machineids=69 then
        #钢化后的料架
        call y_RankTemperingAfter(machineids,returnvalue,messagedate);
    elseif machineids=51 or machineids=70 or machineids=72 or machineids=74 then    
        call y_RankHollowSend(machineids,returnvalue,messagedate);
 elseif machineids=49 then
        call y_RankSlicecageSend(machineids,returnvalue,messagedate);
    end if;
    
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for TemperingShelfFinsh_2
-- ----------------------------
DROP PROCEDURE IF EXISTS `TemperingShelfFinsh_2`;
delimiter ;;
CREATE PROCEDURE `TemperingShelfFinsh_2`(in sendMessageHex varchar(255),in machineids BIGINT,in returnvalue varchar(255),in flag int,out messagedate varchar(255))
BEGIN
    #仓储完成存储过程
    #找到正在工作的任务,判断是什么类型的仓储任务,分别进行什么处理
    DECLARE processcardid1 varchar(255);
    DECLARE messagedates varchar(255) DEFAULT '';
    set messagedate=messagedates;
    
    select work_id into @line from gmms_machine where id=machineids;
    
    select count(*) into @counts from gmms_shelf_task_2 where task_state='正在工作';
    select id,task_type,shelf_rack_id,load_rack,groups into @taskid,@task_type,@shelf_rack_id,@load_rack_id,@groups from gmms_shelf_task_2 where task_state='正在工作 'and line=@line limit 1;
    
    #任务完成
    if flag=1 then 
    select @counts;
    select @task_type;
        if @counts>0 then
        
            #仓位上片位之间类型的任务
            if @task_type='从仓位到钢化位' or @task_type='从钢化位到仓位' then
            
                if @task_type='从仓位到钢化位' then
                
                    update gmms_shelf_rack_2 set state='正在使用' where number=@shelf_rack_id;
                    update gmms_drop_frame_3 set flag='仓储完成',rank=@shelf_rack_id where stop_rank=@load_rack_id and groups=@groups;
                    update gmms_shelf_task_2 set task_state='已完成',finsh_time=NOW() where id=@taskid;
                    call message(returnvalue,'0014',@date);
                    set messagedate=@date;
                else    
                    select processcard_id,orientation into @processcard_id,@orientation from gmms_drop_frame_3 where stop_rank=@load_rack_id and groups=@groups;
                    select @processcard_id;
                    select @orientation;
                    update gmms_shelf_rack_2 set state='使用中',processcard_id=@processcard_id,orientation=@orientation,mod_time=now(),sign=0 where number=@shelf_rack_id;
                    update gmms_drop_frame_3 set flag=null,rank=null,state='空闲',processcard_id=null,drop_frame=null,engineering_id=null,finsh_count=0,processcard_count=0 where stop_rank=@load_rack_id and groups=@groups;
                    update gmms_shelf_task_2 set task_state='已完成',finsh_time=NOW() where id=@taskid;
                    call Temperingss(@processcard_id);
                    call message(returnvalue,'0014',@date);
                    set messagedate=@date;
                end if;
            
            
            
            elseif @task_type='从仓位到理片笼位' or @task_type='从理片笼位到仓位' then
            
                if @task_type='从仓位到理片笼位' then
                    select processcard_id into @processcard_id from gmms_shelf_rack_2 where number=@shelf_rack_id;
                    select count(*),engineering_id,drop_frame into @count1,@engineering_id,@drop_frame from gmms_galss_task_shelf where processcard_id=@processcard_id;
                    update gmms_shelf_rack_2 set state='正在使用' where number=@shelf_rack_id;
                    update gmms_drop_frame_4 set rank=@shelf_rack_id,processcard_id=@processcard_id,engineering_id=@engineering_id,state='使用中',drop_frame=@drop_frame,processcard_count=@count1,finsh_count=@count1,sign=1 where stop_rank=@load_rack_id and groups=10;
                    insert into gmms_galss_task_slicecage select * from gmms_galss_task_shelf where processcard_id=@processcard_id;
                    update gmms_galss_task_slicecage set rank=0 where processcard_id=@processcard_id;
                    update gmms_shelf_task_2 set task_state='已完成',finsh_time=NOW() where id=@taskid;
                    update gmms_machine set remarks=@load_rack_id where id=49;
                    call message(returnvalue,'0014',@date);
                    set messagedate=@date;
                else    
                    select processcard_id into @processcard_id1 from gmms_shelf_rack_2 where number=@shelf_rack_id;
                    update gmms_shelf_rack_2 set state='使用中',sign=2,mod_time=now() where number=@shelf_rack_id;
                    update gmms_drop_frame_4 set flag=0,rank=null,state='空闲',processcard_id=null,drop_frame=null,engineering_id=null,finsh_count=0,processcard_count=0,sign=1 where stop_rank=@load_rack_id and groups=@groups;
                    select count(*) into @count6 from gmms_galss_task_slicecage where processcard_id=@processcard_id1 and work_state='破损';
                    delete from gmms_galss_task_slicecage where processcard_id=@processcard_id1;
                    update gmms_shelf_task_2 set task_state='已完成',finsh_time=NOW() where id=@taskid;
                    
                    set processcardid1 = left(@processcard_id1,13);
                    select count(*) into @count10 from gmms_shelf_rack_2 where sign=2 and  processcard_id like  CONCAT('%',processcardid1,'%');
                    select count(*)  from gmms_shelf_rack_2 where  processcard_id like  CONCAT('%',processcardid1,'%');
                    select count(*) into @count11 from gmms_liuchengka where current_frame like CONCAT('%',processcardid1,'%');
                    select @count11;
                    select @count10;
                    if (@count11-@count10)=1 and @count6=0  then
                    select @count11;
                         update gmms_shelf_rack_2 set sign=2 where  processcard_id like  CONCAT('%',processcardid1,'%');
                    elseif @count6>0  then
                        update gmms_shelf_rack_2 set sign=0 where  processcard_id like CONCAT('%',processcardid1,'%');
                    end if;
                    call message(returnvalue,'0014',@date);
                        
                    set messagedate=@date;
                end if;
            
            
            elseif @task_type='从仓位到中空位' or @task_type='从中空位到仓位' then
            
                if @task_type='从仓位到中空位' then
                    select processcard_id into @processcard_id from gmms_shelf_rack_2 where number=@shelf_rack_id;
                    
                    select count(*),engineering_id,drop_frame into @count1,@engineering_id,@drop_frame from gmms_galss_task_shelf where processcard_id=@processcard_id;
                    update gmms_shelf_rack_2 set state='正在使用' where number=@shelf_rack_id;
 
                    select id into @id from gmms_drop_frame_4 where stop_rank=@load_rack_id and groups=@groups order by stops desc limit 0,1;
                    
                    update gmms_drop_frame_4 set rank=@shelf_rack_id,processcard_id=@processcard_id,engineering_id=@engineering_id,state='使用中',drop_frame=@drop_frame,processcard_count=@count1,finsh_count=@count1,sign=1 where id=@id;
                    update gmms_shelf_task_2 set task_state='已完成',finsh_time=NOW() where id=@taskid;
                    insert into gmms_galss_task_hollow  select * from gmms_galss_task_shelf where processcard_id =@processcard_id;
                    
                    
 
                    call message(returnvalue,'0014',@date);
                    set messagedate=@date;
                else    
                    update gmms_shelf_rack_2 set state='空架',sign=0,processcard_id=null,mod_time=now() where number=@shelf_rack_id;
                    update gmms_drop_frame_4 set flag=0,rank=null,state='空闲',processcard_id=null,drop_frame=null,engineering_id=null,finsh_count=0,processcard_count=0,sign=0 where stop_rank=@load_rack_id and groups=@groups and sign=4;
                    update gmms_shelf_task_2 set task_state='已完成',finsh_time=NOW() where id=@taskid;
                    
                    
                    call message(returnvalue,'0014',@date);
                    set messagedate=@date;
                end if;
            
            
            elseif @task_type='从空仓位到仓位' or @task_type='从仓位到空仓位' then
                if @task_type='从仓位到空仓位' then
                     select processcard_id,orientation,sign into @processcard_id,@orientation,@sign from gmms_shelf_rack_2 where number=@shelf_rack_id;
                     update gmms_shelf_rack_2 set state='空闲',processcard_id=null,sign=@sign where number=@shelf_rack_id;
                     update gmms_shelf_rack_2 set state='使用中',processcard_id=@processcard_id,orientation=@orientation where number=@load_rack_id;
                    update gmms_shelf_task_2 set task_state='已完成',finsh_time=NOW() where id=@taskid;
                    call message(returnvalue,'0014',@date);
                    set messagedate=@date;
                else
                    select orientation,sign into @orientation,@sign from gmms_shelf_rack_2 where number=@shelf_rack_id;
                     update gmms_shelf_rack_2 set state='空闲' where number=@shelf_rack_id;
                     update gmms_shelf_rack_2 set state='空架',orientation=@orientation,sign=0 where number=@load_rack_id;
                    update gmms_shelf_task_2 set task_state='已完成',finsh_time=NOW() where id=@taskid;
                    call message(returnvalue,'0014',@date);
                    set messagedate=@date;
                end if;
                
            elseif @task_type='从仓位到旋转位' or @task_type='从旋转位到仓位' then
                if @task_type='从仓位到旋转位' then
                     select processcard_id into @processcard_id from gmms_shelf_rack_2 where number=@shelf_rack_id;
                    update gmms_drop_frame_2 set stops=@shelf_rack_id,processcard_id=@processcard_id where noodles=@load_rack_id and groups=20;
                     update gmms_shelf_rack_2 set state='正在使用' where number=@shelf_rack_id;
                    update gmms_shelf_task_2 set task_state='已完成',finsh_time=NOW() where id=@taskid;
                    call message(returnvalue,'0014',@date);
                    set messagedate=@date;
                else
                     update gmms_drop_frame_2 set stops=null,processcard_id=null where noodles=@load_rack_id and groups=20;
                    select orientation into @orientation from gmms_shelf_rack_2 where number=@shelf_rack_id;
                    if @orientation='A' then
                        set @orientation='B';
                    elseif @orientation='B' then
                        set @orientation='A';
                    end if;
                     update gmms_shelf_rack_2 set state='使用中',orientation=@orientation where number=@shelf_rack_id;
                    update gmms_shelf_task_2 set task_state='已完成',finsh_time=NOW() where id=@taskid;
                    call message(returnvalue,'0014',@date);
                    set messagedate=@date;
                end if;
                
            end if;
        else
            set messagedate='';
        end if;
        
        
        
    #任务失败,重新修改状态
    elseif flag=2 then
 
            update gmms_shelf_task_2 set task_state='等待中' where id=@taskid;
        
            call message(returnvalue,'0014',@date);
            set messagedate=@date;
 
 
    end if;
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for TemperingShelfSend_2
-- ----------------------------
DROP PROCEDURE IF EXISTS `TemperingShelfSend_2`;
delimiter ;;
CREATE PROCEDURE `TemperingShelfSend_2`(in machineids BIGINT,in machinedisposeids BIGINT,out messagedate varchar(255))
BEGIN
    #仓储请求存储过程
    #循环等待中的仓储任务,循环上片位,判断是什么类型任务分别进行处理
    DECLARE s int DEFAULT 0;
    DECLARE x int DEFAULT 0;
    DECLARE load_racks int DEFAULT 0;
    DECLARE orientations varchar(255) DEFAULT '';
    DECLARE dates varchar(255);
    DECLARE messagedates varchar(255) DEFAULT '';
    set messagedate=messagedates;
    
    select return_value into @returnvalue from gmms_machine_dispose where id=machinedisposeids;
    select work_id into @line from gmms_machine where id=machineids;
    
 
    set @task_type=null;
        select id,task_state,task_type,groups,shelf_rack_id,load_rack into @id,@task_state,@task_type,@groups,@shelf_rack_id,@load_rack from gmms_shelf_task_2 where task_state='等待中' and line=@line order by start_time limit 1;
        select count(*) into @count5 from gmms_shelf_task_2 where task_state='正在工作' and line=@line;
        if @count5=0 then
            if @task_type='从钢化位到仓位' then
                #判断上片位架子上面有玻璃,上片位是否启用
                    select orientation into @orientation from gmms_drop_frame_3 where stops=@load_rack and groups=@groups;
                    update gmms_shelf_task_2 set task_state='正在工作' where task_state='等待中' and id=@id;
                    if @orientation='A' then
                        set orientations='0001';
                    else
                        set orientations='0002';
                    end if;
                    if @shelf_rack_id=20 then
                        set orientations='0001';
                    end if;
                    call intTo2ByteHex10_16_4(@shelf_rack_id,@shelfrackid);
                    call intTo2ByteHex10_16_4(@load_rack,@loadrackid);
                    
                    set dates=CONCAT(@returnvalue,"0000",@loadrackid,@shelfrackid,orientations,'0001');
                    call message(dates,'000a',@date);
                    set messagedate=@date;
                    
            
            elseif @task_type='从仓位到钢化位' then
                #判断上片位架子上面没有玻璃,上片位是否启用
                    select orientation into @orientation from gmms_drop_frame_3 where stops=@load_rack and groups=@groups;
                    update gmms_shelf_task_2 set task_state='正在工作' where task_state='等待中' and id=@id;
                    if @orientation='A' then
                        set orientations='0001';
                    else
                        set orientations='0002';
                    end if;
                    if @shelf_rack_id=20 then
                        set orientations='0001';
                    end if;
                    call intTo2ByteHex10_16_4(@shelf_rack_id,@shelfrackid);
                    call intTo2ByteHex10_16_4(@load_rack,@loadrackid);
                    set dates=CONCAT(@returnvalue,"0000",@shelfrackid,@loadrackid,orientations,'0001');
                    select dates;
                    call message(dates,'000a',@date);
                    set messagedate=@date;
                    
            elseif @task_type='从仓位到理片笼位' then
    
                    select orientation into @orientation from gmms_drop_frame_4 where stops=@load_rack and groups=@groups;
                    update gmms_shelf_task_2 set task_state='正在工作' where task_state='等待中' and id=@id;
                    if @orientation='A' then
                        set orientations='0001';
                    else
                        set orientations='0002';
                    end if;
                    if @shelf_rack_id=21 then
                        set orientations='0002';
                    end if;
                    call intTo2ByteHex10_16_4(@shelf_rack_id,@shelfrackid);
                    call intTo2ByteHex10_16_4(@load_rack,@loadrackid);
                    set dates=CONCAT(@returnvalue,"0000",@shelfrackid,@loadrackid,orientations,'0001');
                    select dates;
                    call message(dates,'000a',@date);
                    set messagedate=@date;
                    
            elseif @task_type='从理片笼位到仓位' then
                    select orientation into @orientation from gmms_drop_frame_4 where stops=@load_rack and groups=@groups;
                    update gmms_shelf_task_2 set task_state='正在工作' where task_state='等待中' and id=@id;
                    if @orientation='A' then
                        set orientations='0001';
                    else
                        set orientations='0002';
                    end if;
                    if @shelf_rack_id=21 then
                        set orientations='0002';
                    end if;
                    call intTo2ByteHex10_16_4(@shelf_rack_id,@shelfrackid);
                    call intTo2ByteHex10_16_4(@load_rack,@loadrackid);
                    set dates=CONCAT(@returnvalue,"0000",@loadrackid,@shelfrackid,orientations,'0001');
                    select dates;
                    call message(dates,'000a',@date);
                    set messagedate=@date;
                    
                    
            elseif @task_type='从仓位到空仓位' or @task_type='从空仓位到仓位' then
                    select orientation into @orientation from gmms_shelf_rack_2 where number=@shelfrackid;
                    update gmms_shelf_task_2 set task_state='正在工作' where task_state='等待中' and id=@id;
                    update gmms_shelf_rack_2 set state='正在使用' where number=@shelf_rack_id or number=@load_rack;
                    if @orientation='A' then
                        set orientations='0001';
                    else
                        set orientations='0002';
                    end if;
                    if @shelf_rack_id=21 then
                        set orientations='0002';
                    elseif @shelf_rack_id=20 then
                        set orientations='0001';
                    end if;
                    call intTo2ByteHex10_16_4(@shelf_rack_id,@shelfrackid);
                    call intTo2ByteHex10_16_4(@load_rack,@loadrackid);
                    set dates=CONCAT(@returnvalue,"0000",@shelfrackid,@loadrackid,orientations,'0001');
                    select dates;
                    call message(dates,'000a',@date);
                    set messagedate=@date;
            
                
            elseif @task_type='从仓位到中空位' then
                    select orientation into @orientation from gmms_shelf_rack_2 where number=@shelfrackid;
                    update gmms_shelf_task_2 set task_state='正在工作' where task_state='等待中' and id=@id;
                    update gmms_shelf_rack_2 set state='正在使用' where number=@shelfrackid;
                    if @orientation='A' then
                        set orientations='0001';
                    else
                        set orientations='0002';
                    end if;
                    if @shelf_rack_id=21 then
                        set orientations='0002';
                    elseif @shelf_rack_id=20 then
                        set orientations='0001';
                    end if;
                    call intTo2ByteHex10_16_4(@shelf_rack_id,@shelfrackid);
                    call intTo2ByteHex10_16_4(@load_rack,@loadrackid);
                    set dates=CONCAT(@returnvalue,"0000",@shelfrackid,@loadrackid,orientations,'0001');
                    select dates;
                    call message(dates,'000a',@date);
                    set messagedate=@date;    
                    
            elseif @task_type='从中空位到仓位' then
                    select orientation into @orientation from gmms_shelf_rack_2 where number=@shelfrackid;
                    update gmms_shelf_task_2 set task_state='正在工作' where task_state='等待中' and id=@id;
                    update gmms_shelf_rack_2 set state='正在使用' where number=@shelfrackid;
                    if @orientation='A' then
                        set orientations='0001';
                    else
                        set orientations='0002';
                    end if;
                    if @shelf_rack_id=21 then
                        set orientations='0002';
                    elseif @shelf_rack_id=20 then
                        set orientations='0001';
                    end if;
                    call intTo2ByteHex10_16_4(@shelf_rack_id,@shelfrackid);
                    call intTo2ByteHex10_16_4(@load_rack,@loadrackid);
                    set dates=CONCAT(@returnvalue,"0000",@loadrackid,@shelfrackid,orientations,'0001');
                    select dates;
                    call message(dates,'000a',@date);
                    set messagedate=@date;    
                    
            elseif @task_type='从仓位到旋转位' or @task_type='从旋转位到仓位' then
                    select orientation into @orientation from gmms_shelf_rack_2 where number=@shelfrackid;
                    update gmms_shelf_task_2 set task_state='正在工作' where task_state='等待中' and id=@id;
                    update gmms_shelf_rack_2 set state='正在使用' where number=@shelfrackid;
                    if @orientation='A' then
                        set orientations='0001';
                    else
                        set orientations='0002';
                    end if;
                    if @shelf_rack_id=21 then
                        set orientations='0002';
                    elseif @shelf_rack_id=20 then
                        set orientations='0001';
                    end if;
                    call intTo2ByteHex10_16_4(@shelf_rack_id,@shelfrackid);
                    call intTo2ByteHex10_16_4(@load_rack,@loadrackid);
                    set dates=CONCAT(@returnvalue,"0000",@shelfrackid,@loadrackid,orientations,'0001');
                    select dates;
                    call message(dates,'000a',@date);
                    set messagedate=@date;    
                    
        
            
            end if;
 
 
    end if;
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for TemperingShelf_2
-- ----------------------------
DROP PROCEDURE IF EXISTS `TemperingShelf_2`;
delimiter ;;
CREATE PROCEDURE `TemperingShelf_2`(in sendMessageHex varchar(255),in machineids BIGINT,out messagedate varchar(255))
BEGIN
    #仓储存储过程
    #找到当前机器标志位
    #查询机器逻辑表中对应的逻辑进行对应的步骤
    DECLARE machinedisposeids int DEFAULT 0;
    DECLARE dates varchar(255);
    DECLARE findplc varchar(255);
    DECLARE findmes varchar(255);
    DECLARE taskplc varchar(255);
    DECLARE taskmes varchar(255);
    DECLARE processcardid1 varchar(255);
    DECLARE messagedates varchar(255) DEFAULT '';
    set messagedate=messagedates;
    
    select machine_type_id into @mtid from gmms_machine where id=machineids;
    
    
    
    select mf.flag into @完成标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='完成字';
    
    select mf.flag into @请求标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='请求字';
    
    select mf.flag into @发送标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='发送字';
    
    select mf.flag into @完成确认标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='完成确认字';
    
    set findplc = substring(sendMessageHex,(cast(@完成标志位 as UNSIGNED INTEGER)*4)+19,4);
    set taskplc = substring(sendMessageHex,(cast(@请求标志位 as UNSIGNED INTEGER)*4)+19,4);
    set taskmes = substring(sendMessageHex,(cast(@发送标志位 as UNSIGNED INTEGER)*4)+19,4);
    set findmes = substring(sendMessageHex,(cast(@完成确认标志位 as UNSIGNED INTEGER)*4)+19,4);
    select taskplc;
    select taskmes;
    select findplc;
    select findmes;
 
    #完成逻辑查询
    select count(*),md.id into @完成数量,@完成逻辑编号 from gmms_machine_dispose md join gmms_machine_type mt on md.machine_type_id=mt.id where md.machine_type_id=@mtid  and md.plc_font_type='完成字' and md.mes_font_type='完成确认字' and md.plc_font_value=findplc and md.mes_font_value=findmes;
    
    #请求逻辑查询
    select count(*),md.id into @请求数量,@请求逻辑编号 from gmms_machine_dispose md join gmms_machine_type mt on md.machine_type_id=mt.id where md.machine_type_id=@mtid  and md.plc_font_type='请求字' and md.mes_font_type='发送字' and md.plc_font_value=taskplc and md.mes_font_value=taskmes;
    #machineids=46,53,54
 
    #判断逻辑是否存在
    if @完成数量=1 or @请求数量=1 then
    
        #判断完成逻辑是否为空
        if @完成逻辑编号!=0 then
            set machinedisposeids=@完成逻辑编号;
 
        #判断请求逻辑是否为空
        elseif @请求逻辑编号!=0 then
            set machinedisposeids=@请求逻辑编号;
            
        end if;
        #查询当前执行逻辑进行判断
        select machinedisposeids;
        select logic,return_value,mes_font_value into @ExecutionLogic,@returnvalue,@mes_font_value from gmms_machine_dispose where id=machinedisposeids;
        select @returnvalue;
        select @ExecutionLogic;
        
        if @ExecutionLogic='任务完成' then
                call y_ShelfFinsh(machineids,1,@returnvalue,dates);
                set messagedate=dates;
         elseif @ExecutionLogic='任务失败' then
                call y_ShelfFinsh(machineids,2,@returnvalue,dates);
                set messagedate=dates;
        elseif @ExecutionLogic='手动完成' then
                call y_ShelfFinsh(machineids,3,@returnvalue,dates);
                set messagedate=dates;
         elseif @ExecutionLogic='完成清空' then
                select @returnvalue;
                call message(@returnvalue,'0014',@date);
                set messagedate=@date;
        elseif @ExecutionLogic='任务请求' then            
                call y_ShelfSend(machineids,@returnvalue,dates);
                call message(dates,'000a',@date);
                set messagedate=@date;
         elseif @ExecutionLogic='任务清空' then
                set dates=CONCAT(@returnvalue,"00000000000000000000");
                call message(dates,'000a',@date);
                set messagedate=@date;
        else
                set messagedate='';
        end if;
    end if;
    
    
        
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for Temperingss
-- ----------------------------
DROP PROCEDURE IF EXISTS `Temperingss`;
delimiter ;;
CREATE PROCEDURE `Temperingss`(in processcard_id1 varchar(255))
BEGIN
DECLARE s int DEFAULT 1;
DECLARE x int DEFAULT 0;
DECLARE countpisce double DEFAULT 0;
DECLARE processcardid1 varchar(255);
 
 
--     set @processcard_id=null;
--     select number,orientation,processcard_id into @number,@orientation,@processcard_id from gmms_shelf_rack_2 where sign=0 and state='使用中' order by number limit 0,1;
--     select @processcard_id;
--     set processcardid1 = left(@processcard_id,13);
--     
--     
-- 
--     select count(*) into @count1 from gmms_shelf_rack_2 where sign=0 and  processcard_id like  CONCAT('%',processcardid1,'%');
--     select count(*) into @count21 from gmms_shelf_rack_2 where (sign=1 or sign=0) and  processcard_id like  CONCAT('%',processcardid1,'%');
--     select count(*) into @count20 from gmms_galss_task_shelf where work_state='已完成' and work_procedure='钢化后下片' and processcard_id like  CONCAT('%',processcardid1,'%') ;
--     select count(*) into @count11 from gmms_shelf_rack_2 where   processcard_id like  CONCAT('%',processcardid1,'%');
--     set countpisce=@count20/@count11;
--     select countpisce;
--     select @count1;
--     if @count1>1 or @count21>1 then
--         set @count2=0;
--         set @processcard_id1=null;
--         select processcard_id into @processcard_id1 from gmms_shelf_rack_2 where  processcard_id like  CONCAT('%',processcardid1,'%') and sign=2 limit 0,1;
--         if @processcard_id1 is null then
--             select processcard_id into @processcard_id1 from gmms_galss_task_shelf where processcard_id like  CONCAT('%',processcardid1,'%') GROUP BY processcard_id limit 0,1;
--         end if;
--         select @processcard_id1;
--         select count(*) into @count2 from gmms_galss_task_shelf where processcard_id =@processcard_id1;
--         select @count2;
--         if countpisce=@count2 then
--         while x<=@count2 do
--             select max(stop_rank) into @maxstoprank from gmms_galss_task_shelf where processcard_id =@processcard_id1;
--             select stop_rank,width,height,edg_speed2 into @stop_rank,@width,@height,@edg_speed2 from gmms_galss_task_shelf where processcard_id =@processcard_id1 order by stop_rank limit x,1;
-- --             select @stop_rank;
-- --              select @width;
-- --              select @height;
-- --              select x;
--             while s<@count1 do
-- 
--                 select processcard_id into @processcard_id3 from gmms_galss_task_shelf where processcard_id like  CONCAT('%',processcardid1,'%') GROUP BY processcard_id order by processcard_id limit s,1;
--                 select count(*) into @count6 from gmms_galss_task_shelf where processcard_id =@processcard_id3;
--                 #select @count6;
--                 if @count2=@count6 then
-- --                     select @edg_speed2;
-- --                     select @stop_rank;
-- 
--                     select count(*) into @count3 from gmms_galss_task_shelf where processcard_id =@processcard_id3  and stop_rank=@stop_rank and (edg_speed2=@edg_speed2 or (width=@width and height=@height));
-- 
--                     #select @processcard_id3;
-- --                     select @count3;
-- --                     select @count9;
--                     if @count3!=1 then
--                         select @processcard_id1;
--                         select @stop_rank;
--                         select count(*) into @count4 from gmms_shelf_rack_2 where processcard_id =@processcard_id and state='使用中' and sign=0 ;
--                         select @processcard_id;
--                         if @count4=1 then
--                             select number,orientation,processcard_id into @number,@orientation,@processcard_id2 from gmms_shelf_rack_2 where processcard_id =@processcard_id and state='使用中' and sign=0;
--                             #select @number;
--                             set @load_rank=null;
--                             select stop_rank into @load_rank from gmms_drop_frame_4 where groups=10 and state='空闲' and flag=0 and orientation=@orientation;
--                             select @load_rank;
--                             if @load_rank is not null then
--                                 insert into gmms_shelf_task_2 (task_type,task_state,shelf_rack_id,load_rack,groups,start_time,line) values('从仓位到理片笼位','等待中',@number,@load_rank,10,now(),1);
--                                 select count(*) into @count5 from gmms_shelf_rack_2 where sign=0 and processcard_id like  CONCAT('%',processcardid1,'%');
--                                 if @count5=2 then
--                                     update gmms_shelf_rack_2 set sign=1 where processcard_id like  CONCAT('%',processcardid1,'%');
--                                 else 
--                                     update gmms_shelf_rack_2 set sign=1 where processcard_id =@processcard_id;
--                                 end if;
--                                 
--                                 update gmms_drop_frame_4 set flag=1 where stop_rank=@load_rank;
--                             end if;
--                         
--                         end if;
--                         
--                         set s=10000;
--                         set x=10000;
--                     elseif @maxstoprank=@stop_rank then
--                                  SELECT @maxstoprank;
--                                  SELECT @stop_rank;    
--                                 select count(*) into @count5 from gmms_shelf_rack_2 where sign=0 and processcard_id like  CONCAT('%',processcardid1,'%');
--                                 if @count5=2 then
--                                     update gmms_shelf_rack_2 set sign=2 where processcard_id like  CONCAT('%',processcardid1,'%');
--                                 else 
--                                     update gmms_shelf_rack_2 set sign=2 where processcard_id =@processcard_id;
--                                 end if;
--                     end if;
--                 end if;
--                 set s=s+1;
--             end while;
--             set s=0;
--             set x=x+1;
--         end while;
--         set x=0;
--         end if;
-- 
--     end if;
--     
    
    
    #set @processcard_id=null;
    #select number,orientation,processcard_id into @number,@orientation,@processcard_id from gmms_shelf_rack_2 where sign=0 and state='使用中' order by number limit 0,1;
--     
--     set @processcard_id=processcard_id1;
--     select @processcard_id;
--     #截取流程卡13位
--     set processcardid1 = left(@processcard_id,13);
--     
--     
--     #查询这个合片流程卡没有理片的流程卡数量
--     select count(*) into @count1 from gmms_shelf_rack_2 where sign=0 and  processcard_id like  CONCAT('%',processcardid1,'%');
--     select count(*) into @count21 from gmms_shelf_rack_2 where (sign=1 or sign=0) and  processcard_id like  CONCAT('%',processcardid1,'%');
--     #查询合片流程卡小片总数
--     select count(*) into @count20 from gmms_galss_task_shelf where work_state='已完成' and work_procedure='钢化后下片' and processcard_id like  CONCAT('%',processcardid1,'%') ;
--     #查询合片流程卡里有几个流程卡
--     select count(*) into @count11 from gmms_shelf_rack_2 where   processcard_id like  CONCAT('%',processcardid1,'%');
--     set countpisce=@count20/@count11;
--     select countpisce;
--     select @count1;
--     #判断没有理片的流程卡数量大于1
--     if @count1>0 or @count21>1 then
--         set @count2=0;
--         set @processcard_id1=null;
--         #查询合片流程卡里面已经理片的流程卡
--         select processcard_id into @processcard_id1 from gmms_shelf_rack_2 where  processcard_id like  CONCAT('%',processcardid1,'%') and sign=2 limit 0,1;
--         if @processcard_id1 is null then
--             #查询合片流程卡里不等于当前流程卡的流程卡
--             select processcard_id into @processcard_id1 from gmms_shelf_rack_2 where processcard_id like  CONCAT('%',processcardid1,'%') and state='使用中'  order by processcard_id limit 0,1;    
--         end if;
--         select processcard_id into @processcard_id from gmms_shelf_rack_2 where processcard_id like  CONCAT('%',processcardid1,'%') and state='使用中' and processcard_id!=@processcard_id1 and sign=0 order by processcard_id desc limit 0,1;    
--         select @processcard_id1;
--         select @processcard_id;
--         #查询当前流程卡的小片总数
--         select count(*) into @count2 from gmms_galss_task_shelf where processcard_id =@processcard_id1;
--         select @count2;
--         if countpisce=@count2 then
--                 select @processcard_id1;
--                 if @processcard_id1 is not null then
--                         #查询两个流程卡的对比结果集
--                         select GROUP_CONCAT(gtf.edg_speed2),GROUP_CONCAT(gtf.width),GROUP_CONCAT(gtf.height) into @stop_rank1,@width1,@height1 from (select edg_speed2,width,height from gmms_galss_task_shelf where processcard_id=@processcard_id1 order by stop_rank) as gtf;
--                         select GROUP_CONCAT(gtf.edg_speed2),GROUP_CONCAT(gtf.width),GROUP_CONCAT(gtf.height) into @stop_rank2,@width2,@height2 from (select edg_speed2,width,height from gmms_galss_task_shelf where processcard_id=@processcard_id  order by stop_rank) as gtf;    
--                         #判断是否相等
--                         if @stop_rank1=@stop_rank2 then
--                             #相等就把这个流程卡标记成2
--                                 select count(*) into @count5 from gmms_shelf_rack_2 where sign=2 and processcard_id like  CONCAT('%',processcardid1,'%');
--                                 select count(*) into @count11 from gmms_liuchengka where current_frame like CONCAT('%',processcardid1,'%');
--                                 if (@count11-@count5)=1 then
--                                     update gmms_shelf_rack_2 set sign=2 where processcard_id like  CONCAT('%',processcardid1,'%');
--                                 else 
--                                     update gmms_shelf_rack_2 set sign=2 where processcard_id =@processcard_id;
--                                 end if;
--                         elseif @width1=@width2 and @height1=@height2 then
--                                 select count(*) into @count5 from gmms_shelf_rack_2 where sign=2 and processcard_id like  CONCAT('%',processcardid1,'%');
--                                 select count(*) into @count11 from gmms_liuchengka where current_frame like CONCAT('%',processcardid1,'%');
--                                 SELECT @count11;
--                                 if (@count11-@count5)=1 then
--                                     update gmms_shelf_rack_2 set sign=2 where processcard_id like  CONCAT('%',processcardid1,'%');
--                                 else 
--                                     update gmms_shelf_rack_2 set sign=2 where processcard_id =@processcard_id;
--                                 end if;
--                         else
--                             #不相等就去仓储拉架子去理片笼
--                             select number,orientation,processcard_id into @number,@orientation,@processcard_id2 from gmms_shelf_rack_2 where processcard_id =@processcard_id and state='使用中' and sign=0;
--                             set @load_rank=null;
--                             select @processcard_id2;
--                             select stop_rank into @load_rank from gmms_drop_frame_4 where groups=10 and state='空闲' and flag=0 and orientation=@orientation;
--                             select @load_rank;
--                             if @load_rank is not null then
--                                 insert into gmms_shelf_task_2 (task_type,task_state,shelf_rack_id,load_rack,groups,start_time,line) values('从仓位到理片笼位','等待中',@number,@load_rank,10,now(),1);
--                                 select count(*) into @count5 from gmms_shelf_rack_2 where sign=0 and processcard_id like  CONCAT('%',processcardid1,'%');
--                                 if @count5=2 then
--                                     update gmms_shelf_rack_2 set sign=1 where processcard_id =@processcard_id;
-- --                                     update gmms_shelf_rack_2 set sign=1 where processcard_id like  CONCAT('%',processcardid1,'%');
--                                 else 
--                                     update gmms_shelf_rack_2 set sign=1 where processcard_id =@processcard_id;
--                                 end if;
--                                 
--                                 update gmms_drop_frame_4 set flag=1 where stop_rank=@load_rank;
--                             end if;
--                                 
-- 
--                         end if;
--                     end if;
--         
--         end if;
-- 
--     end if;
    
-- set @processcard_id=null;
-- select processcard_id into @processcard_id from gmms_galss_task_slicecage where work_procedure='理片' and work_state='已进库' limit 0,1;
-- select @processcard_id;
-- if @processcard_id is not null then
-- update gmms_galss_task_slicecage set stop_rank=0 where processcard_id=@processcard_id;
-- set processcardid2 = left(@processcard_id,13);
-- select count(*) into @count1 from gmms_galss_task_shelf where processcard_id=CONCAT(processcardid2,'/1');
-- while y<@count1 do
--     select width,height,stop_rank,gc_number into @width,@height,@stop_rank,@gc_number from gmms_galss_task_shelf where processcard_id=CONCAT(processcardid2,'/1') and stop_rank!=0 order by gc_number limit y,1;
-- 
--     select id into @id from gmms_galss_task_slicecage where gc_number=@gc_number and processcard_id=@processcard_id and stop_rank=0 limit 0,1;
--     if @id is not null then
--         update gmms_galss_task_slicecage set stop_rank=@stop_rank where id=@id;
--     end if;
-- set y=y+1;
-- end while;
-- end if;
 
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for Temperingss_1
-- ----------------------------
DROP PROCEDURE IF EXISTS `Temperingss_1`;
delimiter ;;
CREATE PROCEDURE `Temperingss_1`()
BEGIN
 
    
        select count(*) into @count1 from gmms_shelf_rack_2 where number>=1 and number<=20 and state='空闲';
        select count(*) into @count2 from gmms_shelf_rack_2 where number>=1 and number<=20 and state='使用中' and processcard_id is not null;
        select count(*) into @count3 from gmms_shelf_rack_2 where number>=21 and number<=35 and state='空架';
        select count(*) into @count4 from gmms_shelf_rack_2 where number>=21 and number<=35 and state='空闲';
        
        if @count3>0 and @count1>0 then
            select number,orientation into @number,@orientation from gmms_shelf_rack_2 where number>=21 and number<=35 and state='空架' order by number limit 0,1;
            select number into @number1 from gmms_shelf_rack_2 where number>=1 and number<=20 and state='空闲' order by number limit 0,1;
            select count(*) into @count10 from gmms_shelf_task_2 where shelf_rack_id=@number and load_rack=@number1 and task_type='从仓位到仓位' and line=3 and (task_state='正在工作' or task_state='等待中');
                if @count10=0 and @number is not null then
                    insert into gmms_shelf_task_2 (task_type,task_state,shelf_rack_id,load_rack,groups,start_time,line) values('从空仓位到仓位','等待中',@number,@number1,0,now(),3);
                end if;
        end if;
        
        
        if @count2>0 and @count4>0 then
            select number,orientation into @number,@orientation from gmms_shelf_rack_2 where number>=1 and number<=20 and state='使用中' and processcard_id is not null order by number limit 0,1;
            select number into @number1 from gmms_shelf_rack_2 where number>=21 and number<=35 and state='空闲' order by number limit 0,1;
            select count(*) into @count11 from gmms_shelf_task_2 where shelf_rack_id=@number and load_rack=@number1 and task_type='从仓位到仓位' and line=3 and (task_state='正在工作' or task_state='等待中');
                if @count11=0 and @number is not null then
                    insert into gmms_shelf_task_2 (task_type,task_state,shelf_rack_id,load_rack,groups,start_time,line) values('从仓位到空仓位','等待中',@number,@number1,0,now(),3);
                end if;
        end if;
        
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for test
-- ----------------------------
DROP PROCEDURE IF EXISTS `test`;
delimiter ;;
CREATE PROCEDURE `test`(id long)
BEGIN
 
set @i=1;
while @i<=50 do
 INSERT INTO `gmms`.`gmms_yuliao_slicecage`(`slicecage_number`, `slicecage_group`, `slicecage_status`, `ban`) VALUES (@i, 2, NULL, 0);
  set @i=@i+1;
    end while;
end
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for timer_ontime
-- ----------------------------
DROP PROCEDURE IF EXISTS `timer_ontime`;
delimiter ;;
CREATE PROCEDURE `timer_ontime`(_name varchar(50) ,out result int)
BEGIN
    #Routine body goes here...
        declare tm datetime DEFAULT null;
            select time_out into tm from gmms_timer where timer_name=_name;
            set result=-1;
            if tm is not null then 
               if NOW()>tm then
                        set result=1;
                 else
                      set result=0;
                 end if;
             else
             
                set    result=1;
            end if; 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for timer_set
-- ----------------------------
DROP PROCEDURE IF EXISTS `timer_set`;
delimiter ;;
CREATE PROCEDURE `timer_set`(_name varchar(50),in add_second int)
BEGIN
    #Routine body goes here...
        DECLARE  tm1 datetime DEFAULT  null;
        DECLARE  tm2 datetime default null;
        set tm1=NOW();
        set tm2=TIMESTAMPADD(SECOND,add_second,NOW());
        
        update gmms_timer  set time_stamp=tm1 ,time_out=tm2 where timer_name=_name;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for Total_method
-- ----------------------------
DROP PROCEDURE IF EXISTS `Total_method`;
delimiter ;;
CREATE PROCEDURE `Total_method`(in sendMessageHex varchar(255),in machineids BIGINT,out messagedate varchar(255),out falgs varchar(255))
BEGIN
  declare msg varchar(255);
    set falgs=0;
    
    set @div_machine=machineids;
    
    set @z_now=now();
    
    update gmms_machine_message set message=sendMessageHex,mod_time=now() where machine_id=machineids;
    
--     call DoEvent(0,machineids,sendMessageHex);
    #Routine body goes here...
    #传入参数sendMessageHex:机器通讯信息,machineids:机器编号,输出参数messagedate:返回机器通讯信息
    #根据传过来的机器判断调用某个存储过程
    #1为上片,2为存储,4为测量,6为磨边,10为加速台,11为复合台,12为斜滚轮,15为下片机,16为输送台
    select machine_type_id into @typeid from gmms_machine where id=machineids;
     UPDATE run_view SET tms=tms+1 where id=@typeid;
    if @typeid=1 then
        call Loads(sendMessageHex,machineids,@messagedate);
        set messagedate=@messagedate;
     elseif @typeid=2 then
         if machineids=46 or machineids=53 or machineids=54 then
          set messagedate=null;
            
            
            call TemperingShelf_2(sendMessageHex,machineids,@messagedate);
            set messagedate=@messagedate;
            
        else
            call Shelf(sendMessageHex,machineids,@messagedate);
            set messagedate=@messagedate;
        end if;
--     elseif @typeid=3 then
--         call Loads(sendMessageHex,machineids,@messagedate);
--         set messagedate=@messagedate;
    elseif @typeid=4 then
        call Identify(sendMessageHex,machineids,@messagedate);
        set messagedate=@messagedate;
     elseif @typeid=7 then
       set msg:='开始 Slicecage';
        
         call Slicecage(sendMessageHex,machineids,@messagedate,msg);
         set messagedate=@messagedate;
         UPDATE run_view SET msg=msg,t=now() where id=7;
     elseif @typeid=6 then
         call Edg(sendMessageHex,machineids,@messagedate);
         set messagedate=@messagedate;
    elseif @typeid=10 then
        call Accelerate(sendMessageHex,machineids,@messagedate);
        set messagedate=@messagedate;
    elseif @typeid=11 then
        call Compound(sendMessageHex,machineids,@messagedate);
        set messagedate=@messagedate;
    elseif @typeid=12 then
        call Inclinedroller(sendMessageHex,machineids,@messagedate);
        set messagedate=@messagedate;
    elseif @typeid=15 then
        call Stops(sendMessageHex,machineids,@messagedate);
        set messagedate=@messagedate;
    elseif @typeid=16 then
        call Transportation(sendMessageHex,machineids,@messagedate);
        set messagedate=@messagedate;
    elseif @typeid=18 then
        call Horizontal(sendMessageHex,machineids,@messagedate,msg);
        set messagedate=@messagedate;
    elseif @typeid=17 then
        call Marking(sendMessageHex,machineids,@messagedate);
        set messagedate=@messagedate;
    elseif @typeid=19 then
        call RotatingRack_2(sendMessageHex,machineids,@messagedate);
        set messagedate=@messagedate;
    elseif @typeid=20 then
        call PendulumPiece_2(sendMessageHex,machineids,@messagedate);
        set messagedate=@messagedate;
    elseif @typeid=21 then
        call RobotHand_2(sendMessageHex,machineids,@messagedate,@falgs);
        set messagedate=@messagedate;
        set falgs=@falgs;
    elseif @typeid=22 then
        call TemperingRank(sendMessageHex,machineids,@messagedate);
        set messagedate=@messagedate;
    elseif @typeid=23 then
        call HollowSlicecage(sendMessageHex,machineids,@messagedate);
        set messagedate=@messagedate;
    end if;
    
   if (machineids=31) and  length(messagedate)>5 then 
        insert into io_log  (device_id,begin_time,end_time,read_message,send_message)
        values 
        (machineids,@z_now,now(),sendMessageHex,messagedate);
    
    end if;
--   if messagedate is not null and messagedate<>'' then
--     call DoEvent(1,machineids,messagedate);
--  end if;
 
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for Transportation
-- ----------------------------
DROP PROCEDURE IF EXISTS `Transportation`;
delimiter ;;
CREATE PROCEDURE `Transportation`(in sendMessageHex varchar(255),in machineids BIGINT,out messagedate varchar(255))
BEGIN
    #输送台存储过程
    #找到当前机器标志位
    #查询机器逻辑表中对应的逻辑进行对应的步骤
    DECLARE machinedisposeids int DEFAULT 0;
    DECLARE dates varchar(255);
    DECLARE findplc varchar(255);
    DECLARE findmes varchar(255);
    DECLARE taskplc varchar(255);
    DECLARE taskmes varchar(255);
    DECLARE posunplc varchar(255);
    DECLARE posunmes varchar(255);
    DECLARE rankids varchar(255);
    DECLARE messagedates varchar(255) DEFAULT '';
    set messagedate=messagedates;
    
    select machine_type_id,work_id into @mtid,@work_groups from gmms_machine where id=machineids;
    
    select file_name into @engineering_id from gmms_raw_file where operator=@work_groups and state='已领取';
    
    
    
    select mf.flag into @完成标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='完成字';
    
    select mf.flag into @请求标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='请求字';
    
    select mf.flag into @发送标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='发送字';
    
    select mf.flag into @完成确认标志位  from gmms_machine_type mt join gmms_machine_font mf on mt.id=mf.machine_type_id where mf.machine_type_id=@mtid and mf.font_name='完成确认字';
    
    set findplc = substring(sendMessageHex,(cast(@完成标志位 as UNSIGNED INTEGER)*4)+19,4);
    set taskplc = substring(sendMessageHex,(cast(@请求标志位 as UNSIGNED INTEGER)*4)+19,4);
    set taskmes = substring(sendMessageHex,(cast(@发送标志位 as UNSIGNED INTEGER)*4)+19,4);
    set findmes = substring(sendMessageHex,(cast(@完成确认标志位 as UNSIGNED INTEGER)*4)+19,4);
    set rankids = conv(substring(sendMessageHex,(cast(@请求标志位+1 as UNSIGNED INTEGER)*4)+19,4),16,10);
    
 select taskplc;
 select taskmes;
    select findplc;
    select findmes;
 
 
    
    #请求逻辑查询
    select count(*),md.id into @请求数量,@请求逻辑编号 from gmms_machine_dispose md join gmms_machine_type mt on md.machine_type_id=mt.id where md.machine_type_id=@mtid  and md.plc_font_type='请求字' and md.mes_font_type='发送字' and md.plc_font_value=taskplc and md.mes_font_value=taskmes;
 
 
        if @请求逻辑编号!=0 then
            set machinedisposeids=@请求逻辑编号;
        end if;
        
        #查询当前执行逻辑进行判断
        select logic,return_value into @ExecutionLogic,@returnvalue from gmms_machine_dispose where id=machinedisposeids;
        
        if @ExecutionLogic='任务请求' then
                select count(*) into @counts from gmms_galss_task where engineering_id=@engineering_id and work_procedure='理片' and work_state='等待中' and rank=rankids;
                select rank into @rank from gmms_galss_task where engineering_id=@engineering_id and work_procedure='理片' and work_state='等待中' order by rank limit 0,1;
                if @counts=1 and @rank=rankids then
                    #update gmms_galss_task set work_procedure_number=200 where engineering_id=@engineering_id and work_procedure='理片' and work_state='等待中' and rank=rankids;
                    call message(@returnvalue,'000a',@messagedate);
                     set messagedate=@messagedate;
                end if;
         elseif @ExecutionLogic='任务清空' then        
                set dates=CONCAT(@returnvalue,'0000');    
                call message(dates,'000a',@messagedate);
                set messagedate=@messagedate;
        end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for Update_raw
-- ----------------------------
DROP PROCEDURE IF EXISTS `Update_raw`;
delimiter ;;
CREATE PROCEDURE `Update_raw`(in line varchar(255),out banzuname varchar(255))
BEGIN
    #根據綫路獲取當前班組
    select banzu into banzuname from gmms_user_current where gongyi='磨边' and chanxian=line limit 0,1;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for web_alter_rank
-- ----------------------------
DROP PROCEDURE IF EXISTS `web_alter_rank`;
delimiter ;;
CREATE PROCEDURE `web_alter_rank`(_type varchar(50),_liuchengka varchar(50),_ids text,out _result int ,out _msg varchar(50))
BEGIN
    #Routine body goes here...
   declare zid bigint;
     declare idx int;
     declare zstr varchar(200);
     set zid=0;
     set idx=0;
set global log_bin_trust_function_creators = 1;
     set zstr=get_str(_ids,idx);
 
     set _msg="nothing";
     #### 先检查玻璃是否和流程卡匹配,不匹配要报错,防止ID发错导致其他流程卡崩溃
     while  zstr is not null do
          set idx=idx+1;
           SET zid=zstr;
            set @z_lk=null;
        
            select processcard_id into @z_lk from gmms_galss_task_buffer where id=zid LIMIT 1;
 
            if @z_lk is null then 
                set zstr=null;
              set _msg="有玻璃不存在";
            else
                if @z_lk<>_liuchengka then 
                        set zstr=null;
                        set _msg="有玻璃流程卡不匹配";
                else
                      set zstr=get_str(_ids,idx);
        
                end if;
            end if;
     end while;
     
     ###### 流程卡没问题 允许修改
     if _msg="nothing" then 
            if _type="钢化前"  then
        
                update gmms_galss_task_stock set stop_rank=-1 where processcard_id=_liuchengka;
                 set idx=0;
                 set zstr=get_str(_ids,idx);
                 
                  while  zstr is not null do
                     set idx=idx+1;
          SET zid=zstr;
            set @z_lk=null;
            select processcard_id into @z_lk from gmms_galss_task_stock where id=zid LIMIT 1;
            if @z_lk is null then 
              
                    insert into gmms_galss_task_stock (id,rank,type_id,galss_id,pattern_id,width,height,thickness,color,edg_width,edg_height,chamfer_size,galss_type,edg_speed1,edg_speed2,fine_throwing,work_state,work_procedure,slicecage_rank,drop_frame,slicecage_flag,out_rank,start_time,finsh_time,stop_position,processcard_id,engineering_id,broken_state,stop_rank,work_procedure_number,gc_number,gc_width,gc_height,gc_stockid,marking_flag) select id,rank,type_id,MOD(galss_id,10000),pattern_id,width,height,thickness,color,edg_width,edg_height,chamfer_size,galss_type,edg_speed1,edg_speed2,fine_throwing,'已完成','下片',slicecage_rank,drop_frame,slicecage_flag,out_rank,start_time,finsh_time,stop_position,processcard_id,engineering_id,broken_state,idx,work_procedure_number,gc_number,gc_width,gc_height,gc_stockid,marking_flag_ex from gmms_galss_task_buffer where id=zid;
            else
            
                update gmms_galss_task_stock set stop_rank=idx     where id=zid;
            end if;
              set zstr=get_str(_ids,idx);
     end while;
            delete from gmms_galss_task_stock  where processcard_id=_liuchengka and stop_rank =-1;
                 
                 set _msg="ok";
            end if;
     
     end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for web_alter_rank_copy1
-- ----------------------------
DROP PROCEDURE IF EXISTS `web_alter_rank_copy1`;
delimiter ;;
CREATE PROCEDURE `web_alter_rank_copy1`(_type varchar(50),_liuchengka varchar(50),_ids text,out _result int ,out _msg varchar(50))
BEGIN
    #Routine body goes here...
   declare zid bigint;
     declare idx int;
     declare zstr varchar(200);
     declare parentprocesscard_ varchar(200) DEFAULT (select parent_liuchengka from gmms_liuchengka where liuchengka=_liuchengka limit 0,1);
     set zid=0;
     set idx=0;
     set zstr=get_str(_ids,idx);
     set _msg="nothing";
     #### 先检查玻璃是否和流程卡匹配,不匹配要报错,防止ID发错导致其他流程卡崩溃
     while  zstr is not null do
          set idx=idx+1;
           SET zid=zstr;
            set @z_lk=null;
            select processcard_id into @z_lk from gmms_galss_task_buffer where id=zid LIMIT 1;
        
            if @z_lk is null then 
                set zstr=null;
              set _msg="有玻璃不存在";
            else
                if @z_lk<>_liuchengka then 
                        set zstr=null;
                        set _msg="有玻璃流程卡不匹配";
                else
                      set zstr=get_str(_ids,idx);
        
                end if;
            end if;
     end while;
     
     ###### 流程卡没问题 允许修改
     if _msg="nothing" then 
            if _type="钢化后"  then
                update gmms_galss_task_shelf set stop_rank=-1 where processcard_id=_liuchengka;
                 set idx=0;
                 set zstr=get_str(_ids,idx);
                 
                  while  zstr is not null do
                     set idx=idx+1;
          SET zid=zstr;
            set @z_lk=null;
            select processcard_id into @z_lk from gmms_galss_task_shelf where id=zid LIMIT 1;
            if @z_lk is null then 
                    insert into gmms_galss_task_shelf (id,rank,type_id,galss_id,pattern_id,width,height,thickness,color,edg_width,edg_height,chamfer_size,galss_type,edg_speed1,edg_speed2,fine_throwing,work_state,work_procedure,slicecage_rank,drop_frame,slicecage_flag,out_rank,start_time,finsh_time,stop_position,processcard_id,engineering_id,broken_state,stop_rank,work_procedure_number,gc_number,gc_width,gc_height,gc_stockid,marking_flag) select id,rank,type_id,MOD(galss_id,10000),pattern_id,width,height,thickness,color,edg_width,edg_height,chamfer_size,galss_type,edg_speed1,edg_speed2,fine_throwing,'已完成','钢化后下片',slicecage_rank,drop_frame,slicecage_flag,0,start_time,finsh_time,0,processcard_id,engineering_id,broken_state,idx,work_procedure_number,parentprocesscard_,gc_width,gc_height,0,marking_flag_ex from gmms_galss_task_buffer where id=zid;
            else
            
                update gmms_galss_task_shelf set stop_rank=idx,work_state='已完成',work_procedure='钢化后下片' where id=zid and !(work_procedure='中空上片' and work_state='已完成');
            end if;
              set zstr=get_str(_ids,idx);
     end while;
            delete from gmms_galss_task_shelf  where processcard_id=_liuchengka and stop_rank =-1;                 
                 set _msg="ok";
            end if;
     end if;
     update gmms_galss_task_shelf set stop_position=0 where processcard_id=_liuchengka;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for workmanship
-- ----------------------------
DROP PROCEDURE IF EXISTS `workmanship`;
delimiter ;;
CREATE PROCEDURE `workmanship`(in line BIGINT)
BEGIN
    #Routine body goes here...
    DECLARE s int DEFAULT 1;
    DECLARE specificationss varchar(255) DEFAULT '';
    DECLARE engineering varchar(255) DEFAULT '';
    
    
    select file_name into @engineering_id from gmms_raw_file where state='已领取' and operator=line;
    set engineering= left(@engineering_id, 1);
  
    if engineering='P' then
        select count(aa.c) into @processcard_count from (select count(*) as c from gmms_galss_task where engineering_id=@engineering_id group by processcard_id,type_id) aa;
   
        while s<=@processcard_count  do
            select processcard_id,type_id into @processcard_id,@type_id from gmms_galss_task where engineering_id=@engineering_id group by processcard_id,type_id limit s,1;
            select count(*),edg_width,edg_height into @count5,@edg_width,@edg_height from gmms_galss_task where engineering_id=@engineering_id and processcard_id=@processcard_id and type_id=@type_id limit 0,1;
            select count(*) into @processcard_sum from gmms_galss_task where engineering_id=@engineering_id and processcard_id=@processcard_id and type_id=@type_id and work_procedure='下片' and work_state='已完成';
            set specificationss=CONCAT(@edg_width,"*",@edg_height);
            select count(*) into @count1 from gmms_workmanship where processcard_id=@processcard_id and specifications=specificationss;
 
            if @count1=0 then
                insert into gmms_workmanship (processcard_id,specifications,cuttingcount,edgingcount,processcard_count,starttime) values(@processcard_id,specificationss,@processcard_sum,@processcard_sum,@count5,now());
            else
                update gmms_workmanship set cuttingcount=@processcard_sum,edgingcount=@processcard_sum,processcard_count=@count5,starttime=now() where processcard_id=@processcard_id and specifications=specificationss;
            end if;
            select gy_gang into @gy_gang from gmms_liuchengka where liuchengka=@processcard_id;
            select gy_zhongkong into @gy_zhongkong from gmms_liuchengka where liuchengka=@processcard_id;
            if @gy_gang=1 then
                update gmms_workmanship set temperingcount=0 where processcard_id=@processcard_id and specifications=specificationss;
            end if;
            if @gy_zhongkong=1 then
                update gmms_workmanship set hollowcount=0 where processcard_id=@processcard_id and specifications=specificationss;
            end if;
            set s=s+1;
        end while;
    end if;
    
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for workmanships
-- ----------------------------
DROP PROCEDURE IF EXISTS `workmanships`;
delimiter ;;
CREATE PROCEDURE `workmanships`(in processcardid varchar(255))
BEGIN
    #Routine body goes here...
    DECLARE s int DEFAULT 0;
    DECLARE processcard_id_length int DEFAULT 0;
    DECLARE specificationss varchar(255) DEFAULT '';
    DECLARE engineering varchar(255) DEFAULT '';
    
    set processcard_id_length = char_length(processcardid);
    
    
    if processcard_id_length=13 then
    
        select count(aa.c) into @processcard_count from (select count(*) as c from gmms_galss_task_hollow where processcard_id like  CONCAT('%',processcardid,'%') group by processcard_id,type_id) aa;
        while s<@processcard_count  do
            select processcard_id,type_id into @processcard_id,@type_id from gmms_galss_task_hollow where processcard_id like  CONCAT('%',processcardid,'%') group by processcard_id,type_id limit s,1;
            
            select count(*),edg_width,edg_height into @count5,@edg_width,@edg_height from gmms_galss_task_hollow where processcard_id like  CONCAT('%',processcardid,'%') and processcard_id=@processcard_id and type_id=@type_id limit 0,1;
            
            select count(*) into @processcard_sum from gmms_galss_task_hollow where  processcard_id like  CONCAT('%',processcardid,'%') and processcard_id=@processcard_id and type_id=@type_id and work_procedure='中空上片' and work_state='已完成';
            
            set specificationss=CONCAT(@edg_width,"*",@edg_height);
            
            select count(*) into @count1 from gmms_workmanship where processcard_id=@processcard_id and specifications=specificationss;
 
            if @count1=1 then
                update gmms_workmanship set hollowcount=@processcard_sum where processcard_id=@processcard_id and specifications=specificationss;
                
            end if;
            
            set s=s+1;
        end while;
    elseif processcard_id_length=15 then
        select count(aa.c) into @processcard_count1 from (select count(*) as c from gmms_galss_task where processcard_id =processcardid group by processcard_id,type_id) aa;
        if @processcard_count1!=0 then
            
            while s<@processcard_count1  do
                select processcard_id,type_id into @processcard_id,@type_id from gmms_galss_task where processcard_id =processcardid group by processcard_id,type_id limit s,1;
                
                select count(*),edg_width,edg_height into @count5,@edg_width,@edg_height from gmms_galss_task where processcard_id =processcardid and processcard_id=@processcard_id and type_id=@type_id limit 0,1;
                
                select count(*) into @processcard_sum from gmms_galss_task where  processcard_id =processcardid and processcard_id=@processcard_id and type_id=@type_id and work_procedure='下片' and work_state='已完成';
                select @processcard_sum;
                
                set specificationss=CONCAT(@edg_width,"*",@edg_height);
                
                select count(*) into @count1 from gmms_workmanship where processcard_id=@processcard_id and specifications=specificationss;
 
                if @count1=0 then
                    insert into gmms_workmanship (processcard_id,specifications,cuttingcount,edgingcount,processcard_count,starttime) values(@processcard_id,specificationss,@processcard_sum,@processcard_sum,@count5,now());
                else
                    update gmms_workmanship set cuttingcount=@processcard_sum,edgingcount=@processcard_sum,processcard_count=@count5,starttime=now() where processcard_id=@processcard_id and specifications=specificationss;
                end if;
                select gy_gang into @gy_gang from gmms_liuchengka where liuchengka=@processcard_id;
                select gy_zhongkong into @gy_zhongkong from gmms_liuchengka where liuchengka=@processcard_id;
                if @gy_gang=1 then
                    update gmms_workmanship set temperingcount=0 where processcard_id=@processcard_id and specifications=specificationss;
                end if;
                if @gy_zhongkong=1 then
                    update gmms_workmanship set hollowcount=0 where processcard_id=@processcard_id and specifications=specificationss;
                end if;
                
                set s=s+1;
            end while;
        
        else
            
            select count(aa.c) into @processcard_count from (select count(*) as c from gmms_galss_task_2 where processcard_id =processcardid group by processcard_id,type_id) aa;
            while s<@processcard_count  do
                select processcard_id,type_id into @processcard_id,@type_id from gmms_galss_task_2 where processcard_id =processcardid group by processcard_id,type_id limit s,1;
                
                select count(*),edg_width,edg_height into @count5,@edg_width,@edg_height from gmms_galss_task_2 where processcard_id =processcardid and processcard_id=@processcard_id and type_id=@type_id limit 0,1;
                
                select count(*) into @processcard_sum from gmms_galss_task_2 where  processcard_id =processcardid and processcard_id=@processcard_id and type_id=@type_id and work_procedure='钢化后下片' and work_state='已完成';
                select @processcard_sum;
                
                set specificationss=CONCAT(@edg_width,"*",@edg_height);
                
                select count(*) into @count1 from gmms_workmanship where processcard_id=@processcard_id and specifications=specificationss;
 
                if @count1=1 then
                    update gmms_workmanship set temperingcount=@processcard_sum where processcard_id=@processcard_id and specifications=specificationss;
                    
                end if;
                
                set s=s+1;
            end while;
            
        end if;
    end if;
    
    
 
    
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for yuliao_create_task
-- ----------------------------
DROP PROCEDURE IF EXISTS `yuliao_create_task`;
delimiter ;;
CREATE PROCEDURE `yuliao_create_task`(_id bigint,out result int,out msg varchar(500))
BEGIN
 
   DECLARE m_count int DEFAULT(0);
   select count(    pattern_task_id) into m_count from gmms_yuliao_task where pattern_task_id =_id;
     set msg="nothing";
     set result=0;
     if m_count=0 then 
    #Routine body goes here...
   insert into gmms_yuliao_task
   (
      yuliao_id,
        pattern_task_id,
        state,
        lib_id,
        chanxian
 
     )     
    select c.id as gid,a.id as pid,0,null,b.operator from gmms_pattern_task a inner join gmms_raw_file b on a.raw_id=b.id
    inner join gmms_glass_yuliao c on c.gongchenghao=b.file_name and c.bantuxuhao=a.rank
    where a.id=_id and gao>300 and kuan>300;
    set result=100;
    set msg="ok";
    end if;
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for yuliao_input
-- ----------------------------
DROP PROCEDURE IF EXISTS `yuliao_input`;
delimiter ;;
CREATE PROCEDURE `yuliao_input`(in _yuliao_id bigint,in _target_id bigint,out result int,out msg varchar(200))
BEGIN
    #Routine body goes here...
    DECLARE d_count int default 0;
    DECLARE d_end bit default false;
    set result=0;
    set msg="nothing";
    
    if _target_id=0 then 
    
       update gmms_yuliao_task set `state`=3 ,lib_id=null where yuliao_id=_yuliao_id;
         set result=100;
         set msg="ok";
    end if;
    
    
    SELECT count(*) into d_count from gmms_yuliao_task where lib_id=_target_id;
    if d_count>0 then 
       set result=99;
         set msg="库位已经被占用";
    end if;
    
    if result=0 then 
         set    d_count=100;
         select ban into d_count from gmms_yuliao_slicecage where id=_target_id;
         if d_count<>0 then 
           set result=99;
             set msg="库位已经被占用";
         end if;
    end if;
    
    if result=0 then 
    
       update gmms_yuliao_task set `state`=1 ,lib_id=_target_id where yuliao_id=_yuliao_id;
         set result=100;
         set msg="ok";
    end if;
    
    
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for yuliao_output
-- ----------------------------
DROP PROCEDURE IF EXISTS `yuliao_output`;
delimiter ;;
CREATE PROCEDURE `yuliao_output`(in _yuliao_id bigint ,out result int,out msg varchar(255))
BEGIN
    #Routine body goes here...
        DECLARE d_count int default 0;
    DECLARE d_end bit default false;
    set msg="nothing";
    set d_count=null;
    SELECT lib_id into d_count from  gmms_yuliao_task where yuliao_id=_yuliao_id;
    if d_count is null then 
       set    d_end=true;
        set msg="无法出库:玻璃不在库中";
    end if;
    
    
    if d_end=false then 
        update gmms_yuliao_task set `state`=2 ,lib_id=null where yuliao_id=_yuliao_id;
        set msg="ok";
    end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for y_Diaozhuang
-- ----------------------------
DROP PROCEDURE IF EXISTS `y_Diaozhuang`;
delimiter ;;
CREATE PROCEDURE `y_Diaozhuang`(in RackId BIGINT,in lck varchar(50),in dropId BIGINT,out back_Num int,out back_Msg varchar(255))
BEGIN
        #吊装绑定架子  
        #参数:RackId 架子工位ID!    liuchengka流程卡号   dropId吊装工位ID
        #返回结果:back_Num 返回调用提示代码    back_Msg 返回调用提示内容
        #back_Num 失败=1 成功=2      back_Msg提示内容
        
        Declare isExistLck varchar(255) DEFAULT null;#此流程卡是否在其他架子上
        Declare isExistRack varchar(255) DEFAULT null; #吊装位上是否有架子
        #Declare isExistRackFlag varchar(255) DEFAULT null; #所需要的架子是否已经被其他任务占用
        Declare isUseRack varchar(255) DEFAULT null; #所需要的架子是否在某工位上
        Declare Rack_sign varchar(255) DEFAULT null;
        Declare Rack_falg varchar(255) DEFAULT null;
        
        #是否此流程卡已存在某一架子上
        select id into isExistLck from gmms_shelf_rack_2 where processcard_id=lck and id<42 limit 0,1;
        
        #是否此吊装位上有架子
        select rank into isExistRack from gmms_drop_frame_5
        where rank is not null and id=dropId and groups_=5;
        
        #此工位 信息
        select stop_rank,sign,flag into isUseRack,Rack_sign,Rack_falg from gmms_drop_frame_5
        where id=RackId and rank is not null and groups_=100 limit 0,1;
        
        if lck is null then
            set back_Num=1;
            set back_Msg=CONCAT(IFNULL(back_Msg,''),'流程卡号为空',IFNULL(lck,''));
        end if;
        if isExistLck is not null then
            set back_Num=1;
            set back_Msg=CONCAT(IFNULL(back_Msg,''),'此流程卡已存在',isExistLck,'号料架上; ');
        end if;
        if isExistRack is not null then
            set back_Num=1;        
            set back_Msg=CONCAT(IFNULL(back_Msg,''),'此吊装位上已有',isExistRack,'号料架; ');
        end if;
        if isUseRack is null then
            set back_Num=1;
            set back_Msg=CONCAT(IFNULL(back_Msg,''),'此库位无料架;');
        else
            if Rack_sign!=0 then
                set back_Num=1;
                set back_Msg=CONCAT(IFNULL(back_Msg,''),IFNULL(isUseRack,''),'库位被占用;');
            end if;
            if Rack_falg!=1 then
                set back_Num=1;
                set back_Msg=CONCAT(IFNULL(back_Msg,''),IFNULL(isUseRack,''),'库位被禁用;');
            end if;
        end if;
        if back_Msg is null then
        
            #(select processcard_id from gmms_galss_task_shelf where processcard_id='"+liuchengka+"' limit 0,1) 
            update gmms_drop_frame_5 as dr 
            left join gmms_drop_frame_5 as dr2 on dr.id=dropId and dr2.id=RackId
            left join gmms_shelf_rack_2 as sr on dr2.rank=sr.id
            set dr.rank=dr2.rank,dr.sign=0,dr2.sign=10,sr.processcard_id=lck
            where dr.id=dropId and dr2.id=RackId and dr.rank is null and dr2.rank is not null;
        
            insert into gmms_galss_task_shelf 
            (id,rank,type_id,galss_id,pattern_id,width,height,thickness,color,edg_width,edg_height,chamfer_size,
            galss_type,edg_speed1,edg_speed2,fine_throwing,work_state,work_procedure,slicecage_rank,drop_frame,
            slicecage_flag,out_rank,start_time,finsh_time,stop_position,processcard_id,engineering_id,broken_state,
            stop_rank,work_procedure_number,gc_number,gc_width,gc_height,gc_stockid,marking_flag) 
            select gt.id,gt.rank,gt.type_id,gt.galss_id,gt.pattern_id,gt.width,gt.height,gt.thickness,gt.color,gt.edg_width,gt.edg_height,
            gt.chamfer_size,gt.galss_type,gt.edg_speed1,gt.edg_speed2,gt.fine_throwing,'已完成','钢化后下片',gt.slicecage_rank,
            gt.drop_frame,gt.slicecage_flag,gt.out_rank,gt.start_time,gt.finsh_time,0,gt.processcard_id,gt.engineering_id,
            gt.broken_state,gt.stop_rank,gt.work_procedure_number,(select parent_liuchengka from gmms_liuchengka 
            where liuchengka=lck),gt.gc_width,gt.gc_height,gt.gc_stockid,gt.marking_flag 
            from gmms_galss_task_stock as gt left join gmms_galss_task_shelf as gs on gt.id=gs.id
            where gt.processcard_id=lck and gs.id is null;
            set back_Num=0;
            set back_Msg=CONCAT(IFNULL(back_Msg,''),lck,'流程卡绑定成功!');
        end if;
        
        
--         select * from gmms_drop_frame_5 as dr LEFT JOIN gmms_shelf_rack_2 as sr on dr.rank=sr.id 
--         where sr.processcard_id is not null and dr.id=dropId;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for y_optimize
-- ----------------------------
DROP PROCEDURE IF EXISTS `y_optimize`;
delimiter ;;
CREATE PROCEDURE `y_optimize`(in parentliuchengka varchar(255),in type int,out result int,out back_mag varchar(255))
BEGIN
    #y_optimize(父级流程卡)
    #优化  按架子上的顺序  与合片其他子流程卡进行优化  排序     
    DECLARE no_more_record DOUBLE DEFAULT 0;        #是否还有数据
    DECLARE typecount int DEFAULT 0;                 #玻璃类型
    DECLARE Carcount int DEFAULT 0;                 #流程卡数量
    DECLARE CarShefcount int DEFAULT 0;              #库内流程卡数量
    DECLARE Glasscount int DEFAULT 0;               #小片数量
    DECLARE count int DEFAULT 0;                        #计数
    DECLARE mincount int DEFAULT 0;                   #min计数
    DECLARE maxcount int DEFAULT 0;                   #min计数
    DECLARE width_ int DEFAULT 0;                   #min计数
    DECLARE height_ int DEFAULT 0;                   #min计数
    DECLARE Resultmaxcount int DEFAULT 0;                   #min计数
    DECLARE ResultmaxGalsscount int DEFAULT 0;                   #min计数
    DECLARE Resultbegincount int DEFAULT 0;                   #min计数
    DECLARE minglasscount int DEFAULT 0;                   #min计数
    DECLARE liuchengka_ varchar(255) DEFAULT null;                 #流程卡
    #此合片任务 初始化  重新 优化  stop_position=0
    update gmms_galss_task_shelf 
    set stop_position=0,slicecage_rank=0,gc_stockid=0 
    where gc_number=parentliuchengka; 
    #库内流程卡玻璃类型数量
    select count(*) into typecount from 
        (select count(*) from gmms_galss_task_shelf 
        where gc_number=parentliuchengka and work_state='已完成' and work_procedure='钢化后下片' 
        group by edg_width,edg_height) as a;
    #库内流程卡数量    
    select count(*) into CarShefcount from 
        (select count(*) from gmms_galss_task_shelf 
        where gc_number=parentliuchengka and work_state='已完成' and work_procedure='钢化后下片' 
        group by processcard_id) as a;
        
    set Carcount= (select count(*) from gmms_liuchengka where parent_liuchengka=parentliuchengka);
    set Glasscount= (select piece_count from gmms_liuchengka where parent_liuchengka=parentliuchengka limit 0,1);
    #拿到最少的流程卡  的玻璃数
    select count(*) into minglasscount from gmms_galss_task_shelf 
    where gc_number=parentliuchengka and work_state='已完成' and work_procedure='钢化后下片' 
    group by processcard_id order by count(*) asc LIMIT 0,1;
    select CarShefcount,Carcount,count,typecount;
    #得到最少的流程卡号
    select processcard_id,count(*) from gmms_galss_task_shelf 
    where gc_number=parentliuchengka and work_state='已完成' and work_procedure='钢化后下片' 
    group by processcard_id order by count(*) asc limit 0,1;
    if CarShefcount=Carcount then
        #流程卡数=库内流程卡数
        #多尺寸循环优化    
        while Glasscount>=count and typecount>1 do
            set count=count+1;
            #取出  子流程卡里 同位置 同尺寸多的
            set width_=0;
            set height_=0;
            set mincount=0;    
            select edg_width,edg_height into width_,height_ from gmms_galss_task_shelf
            where gc_number=parentliuchengka and work_state='已完成' and work_procedure='钢化后下片' and stop_rank=count 
            group by edg_width,edg_height ORDER BY count(*) desc LIMIT 0,1;
        
            select min(stop_position)-1,MAX(stop_position)+1 into mincount,maxcount from gmms_galss_task_shelf 
            where gc_number=parentliuchengka and work_state='已完成' and work_procedure='钢化后下片';        
            call y_optimize_setrank(parentliuchengka,width_,height_,maxcount,mincount,Carcount);
        end while;
        set count=0;    
        while count<Carcount do
            select liuchengka into liuchengka_ from gmms_liuchengka where parent_liuchengka=parentliuchengka limit count,1;
            select max(gc_stockid),max(stop_rank) 
            into Resultmaxcount,ResultmaxGalsscount from gmms_galss_task_shelf
            where processcard_id=liuchengka_ and work_state='已完成' and work_procedure='钢化后下片';
            if typecount=1 then
                #一种尺寸
                select typecount,minglasscount;
                set @Resultrank=0;
                update gmms_galss_task_shelf 
                set stop_position=stop_rank
                where processcard_id=liuchengka_ and work_state='已完成' and work_procedure='钢化后下片';
                
                set @Resultrank=minglasscount+1;
                update gmms_galss_task_shelf    
                set gc_stockid=(@Resultrank:=@Resultrank-1) 
                where processcard_id=liuchengka_ and work_state='已完成' and work_procedure='钢化后下片' 
                order by stop_rank desc limit minglasscount;
            else
                if Resultmaxcount>0 then
                    if type=1 then
                        #缺片放里
                        set @Resultrank=0;
                        
                        update gmms_galss_task_shelf set stop_position=(@Resultrank:=@Resultrank+1) 
                        where processcard_id=liuchengka_ and work_state='已完成' and work_procedure='钢化后下片' order by gc_stockid asc;        
                    elseif type=2 then
                        #缺片放外
                        update gmms_galss_task_shelf 
                        set stop_position=gc_stockid 
                        where processcard_id=liuchengka_ and work_state='已完成' and work_procedure='钢化后下片';
                        set @Resultrank=Resultmaxcount;
                        update gmms_galss_task_shelf set stop_position=(@Resultrank:=@Resultrank+1) 
                        where processcard_id=liuchengka_ and work_state='已完成' and work_procedure='钢化后下片' and gc_stockid<1 order by gc_stockid asc;
                    end if;        
                else
                    update gmms_galss_task_shelf set stop_position=0
                    where processcard_id=liuchengka_ and work_state='已完成' and work_procedure='钢化后下片';
                end if;
            end if;            
            set count=count+1;
        end while;
    end if;
    select * from gmms_galss_task_shelf 
            where gc_number=parentliuchengka and work_state='已完成' and work_procedure='钢化后下片'; 
    if (select count(*) from gmms_galss_task_shelf 
            where gc_number=parentliuchengka and work_state='已完成' and work_procedure='钢化后下片' and stop_position<1)>0
    then
        set result=0;
        set back_mag="失败";
    else
        set result=1;
        set back_mag="成功";
        update gmms_liuchengka set current_work_position='理片',current_status='等待中' 
        where parent_liuchengka=parentliuchengka and liuchengka in
        (select processcard_id from gmms_galss_task_shelf where gc_number=parentliuchengka and stop_position>0 group by processcard_id 
        HAVING GROUP_CONCAT(stop_rank order by stop_rank)!=GROUP_CONCAT(stop_position order by stop_rank));
        update gmms_liuchengka set current_work_position='理片',current_status='已完成' 
        where parent_liuchengka=parentliuchengka and liuchengka not in
        (select processcard_id from gmms_galss_task_shelf where gc_number=parentliuchengka and stop_position>0 group by processcard_id 
        HAVING GROUP_CONCAT(stop_rank order by stop_rank)!=GROUP_CONCAT(stop_position order by stop_rank));
        set @Resultrank=0;
        update gmms_galss_task_shelf 
        set galss_id=(@Resultrank:=@Resultrank+1) 
        where gc_number=parentliuchengka order by processcard_id asc,stop_position desc;
    end if;
    set @width=0;
    set @height=0;
    set mincount=0;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for y_optimize_GAI
-- ----------------------------
DROP PROCEDURE IF EXISTS `y_optimize_GAI`;
delimiter ;;
CREATE PROCEDURE `y_optimize_GAI`(in parentliuchengka varchar(255),in type int,out result int,out back_mag varchar(255))
BEGIN
    #y_optimize(父级流程卡)
    #优化  按架子上的顺序  与合片其他子流程卡进行优化  排序
    DECLARE typecount int DEFAULT 0;                 #玻璃类型数量
    DECLARE Carcount int DEFAULT 0;                 #流程卡数量
    DECLARE maxheight_ int DEFAULT 0;              #库内流程卡数量
    DECLARE CarShefcount int DEFAULT 0;              #库内流程卡数量
    
    
    
    
    if (select count(*) from gmms_liuchengka  where isyou='优化中' and liuchengka=parentliuchengka)=0 then
    #优化开始记录
 
    update gmms_liuchengka set isyou='优化中' 
    where liuchengka=parentliuchengka;
--     insert into gmms_galss_task_shelf_copy1 
--     select *,NOW(),'开始' from gmms_galss_task_shelf where gc_number=parentliuchengka;
            
    #此合片任务 初始化  重新 优化  stop_position=0
    update gmms_galss_task_shelf 
    set stop_position=0,slicecage_rank=0,out_rank=0 
    where gc_number=parentliuchengka; 
    #库内流程卡玻璃类型数量
 
    select count(*) into typecount from 
        (select count(*) from gmms_galss_task_shelf 
        where gc_number=parentliuchengka and work_state='已完成' and work_procedure='钢化后下片' 
        group by edg_width,edg_height) as a;
    #库内流程卡数量    
    select count(*) into CarShefcount from 
        (select count(*) from gmms_galss_task_shelf 
        where gc_number=parentliuchengka and work_state='已完成' and work_procedure='钢化后下片' 
        group by processcard_id) as a;
        #最大高度
    select MAX(height) into maxheight_ from gmms_galss_task_shelf 
        where gc_number=parentliuchengka and work_state='已完成' and work_procedure='钢化后下片';
        
    select child_count into Carcount from gmms_liuchengka where liuchengka=parentliuchengka;
    #玻璃全部到位
    if CarShefcount=Carcount and Carcount>0 then
        call y_optimize_not_same(parentliuchengka,Carcount,1);
    end if;
    #优化完成记录
--     insert into gmms_galss_task_shelf_copy1 
--     select *,NOW(),'完成' from gmms_galss_task_shelf where gc_number=parentliuchengka;
    if (select count(*) from gmms_galss_task_shelf 
            where gc_number=parentliuchengka and work_state='已完成' and work_procedure='钢化后下片' and stop_position<1)>0
    then
        set result=0;
        set back_mag="失败";
    elseif maxheight_>2000 then
        set result=1;
        set back_mag="成功";
        update gmms_liuchengka set current_work_position='理片',current_status='已完成' 
        where parent_liuchengka=parentliuchengka and liuchengka not in
        (select processcard_id from gmms_galss_task_shelf where gc_number=parentliuchengka and stop_position>0 group by processcard_id 
        HAVING GROUP_CONCAT(stop_rank order by stop_rank)!=GROUP_CONCAT(stop_position order by stop_rank));
        set @Resultrank=0;
        update gmms_galss_task_shelf 
        set galss_id=(@Resultrank:=@Resultrank+1) 
        where gc_number=parentliuchengka order by processcard_id asc,stop_position desc;
    else
        set result=1;
        set back_mag="成功";
        update gmms_liuchengka set current_work_position='理片',current_status='等待中' 
        where parent_liuchengka=parentliuchengka and liuchengka in
        (select processcard_id from gmms_galss_task_shelf where gc_number=parentliuchengka and stop_position>0 group by processcard_id 
        HAVING GROUP_CONCAT(stop_rank order by stop_rank)!=GROUP_CONCAT(stop_position order by stop_rank));
        
        update gmms_liuchengka set current_work_position='理片',current_status='已完成' 
        where parent_liuchengka=parentliuchengka and liuchengka not in
        (select processcard_id from gmms_galss_task_shelf where gc_number=parentliuchengka and stop_position>0 group by processcard_id 
        HAVING GROUP_CONCAT(stop_rank order by stop_rank)!=GROUP_CONCAT(stop_position order by stop_rank));
        set @Resultrank=0;
        update gmms_galss_task_shelf 
        set galss_id=(@Resultrank:=@Resultrank+1) 
        where gc_number=parentliuchengka order by processcard_id asc,stop_position desc;
    end if;
    update gmms_liuchengka set isyou='' 
    where liuchengka=parentliuchengka;
    end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for y_optimize_not_same
-- ----------------------------
DROP PROCEDURE IF EXISTS `y_optimize_not_same`;
delimiter ;;
CREATE PROCEDURE `y_optimize_not_same`(in parentliuchengka varchar(255),in CarCount int,in LocatPlace int)
BEGIN
    #不同尺寸优化-按片数最少的流程卡优化 (父级流程卡,子流程卡数量,摆放位置)
    #1.得到 父级流程卡下 片数最少的流程卡的片数 
    #2.理片优化不变stop_postion,中空优化根据最少片数N 从外往里数N个数 作为可配对数
    DECLARE Targetliuchengka_ varchar(255) DEFAULT null;  #目标流程卡
    DECLARE liuchengka_ varchar(255) DEFAULT null;        #子流程卡
    DECLARE minglasscount int DEFAULT 0;                            #父级流程卡下  最少片数子流程卡的片数
    DECLARE edgwidth_ int DEFAULT 0;                             #目标高
    DECLARE edgheight_ int DEFAULT 0;                           #目标宽
    DECLARE CountA int DEFAULT 0;                                       #循环次数
    DECLARE CountB int DEFAULT 0;                                       #循环次数
    DECLARE CountP int DEFAULT 0;                                       #匹配片数
    
    #拿到最少的流程卡的:玻璃数,流程卡号
    select count(*),processcard_id into minglasscount,Targetliuchengka_ from gmms_galss_task_shelf 
    where gc_number=parentliuchengka and work_state='已完成' and work_procedure='钢化后下片' 
    group by processcard_id order by count(*) asc,processcard_id asc LIMIT 0,1;
    
     while CountB<Carcount do
             set liuchengka_=null;
             #子流程   去除破损重新排序
             select liuchengka into liuchengka_ from gmms_liuchengka where parent_liuchengka=parentliuchengka limit CountB,1;        
             set @Resultrank=0;
             update gmms_galss_task_shelf 
             set stop_rank=(@Resultrank:=@Resultrank+1)
             where processcard_id=liuchengka_ and work_state='已完成' and work_procedure='钢化后下片'
             order by stop_rank asc;
             set @Resultrank=0;        
             set CountB=CountB+1;        
     end while;
     set CountB=0;
     set liuchengka_=null;
    #标记可以配对的玻璃
    while CountA<minglasscount do
        #得到目标流程卡从外 往里的尺寸
        set edgwidth_=0;
        set edgheight_=0;
        select edg_width,edg_height into edgwidth_,edgheight_ from gmms_galss_task_shelf 
        where gc_number=parentliuchengka and processcard_id=Targetliuchengka_ and work_state='已完成' and work_procedure='钢化后下片' 
        order by stop_rank desc limit CountA,1;
        set CountA=CountA+1;
        while CountB<Carcount do
            set liuchengka_=null;
            #子流程卡此尺寸 按架上顺序倒序取1
            select liuchengka into liuchengka_ from gmms_liuchengka where parent_liuchengka=parentliuchengka limit CountB,1;
             select stop_rank,stop_position,processcard_id  from gmms_galss_task_shelf 
              where gc_number=parentliuchengka and work_state='已完成' and work_procedure='钢化后下片' order by stop_position desc;
--             
             select stop_rank,stop_position,processcard_id  from gmms_galss_task_shelf
             where processcard_id=liuchengka_ and edg_width=edgwidth_ and edg_height=edgheight_ and stop_position=0
          order by stop_rank desc;
            
            update gmms_galss_task_shelf 
            set stop_position=1000-CountA,out_rank=1000-CountA
            where processcard_id=liuchengka_ and edg_width=edgwidth_ and edg_height=edgheight_ and stop_position=0 
            and work_state='已完成' and work_procedure='钢化后下片'
            order by stop_rank desc limit 1;        
            set CountB=CountB+1;        
        end while;
        set CountB=0;
        set CountP=0;
        select count(*) into CountP from gmms_galss_task_shelf 
        where gc_number=parentliuchengka and work_state='已完成' and work_procedure='钢化后下片' and stop_position=1000-CountA;
        if CountP<CarCount and CountP>0 then
            update gmms_galss_task_shelf 
            set stop_position=0,out_rank=0
            where gc_number=parentliuchengka and work_state='已完成' and work_procedure='钢化后下片' and stop_position=1000-CountA;    
        end if;    
    end while;
    #select * from gmms_galss_task_shelf where gc_number=parentliuchengka order by stop_position desc;
    set CountB=0;
    #二次排序
    while CountB<Carcount do
        set liuchengka_=null;
        select liuchengka into liuchengka_ from gmms_liuchengka where parent_liuchengka=parentliuchengka limit CountB,1;
        
        set @Resultrank=0;
        update gmms_galss_task_shelf 
        set out_rank=(@Resultrank:=@Resultrank+1)
        where processcard_id=liuchengka_ and stop_position>0 and work_state='已完成' and work_procedure='钢化后下片'
        order by stop_position asc;
        
        set @Resultrank=0;
        update gmms_galss_task_shelf 
        set stop_position=(@Resultrank:=@Resultrank+1)
        where processcard_id=liuchengka_ and work_state='已完成' and work_procedure='钢化后下片'
        order by stop_position asc,stop_rank asc;
        
            
        set CountB=CountB+1;
    end while;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for y_optimize_same
-- ----------------------------
DROP PROCEDURE IF EXISTS `y_optimize_same`;
delimiter ;;
CREATE PROCEDURE `y_optimize_same`(in parentliuchengka varchar(255),in CarCount int)
BEGIN
    #同尺寸优化 (父级流程卡,子流程卡数量)
    #1.得到 父级流程卡下 片数最少的流程卡的片数
    #2.理片优化不变stop_postion,中空优化根据最少片数N 从外往里数N个数 作为可配对数
    DECLARE liuchengka_ varchar(255) DEFAULT null;        #子流程卡
    DECLARE minglasscount int DEFAULT 0;                            #父级流程卡下  最少片数子流程卡的片数
    DECLARE Count int DEFAULT 0;                                       #循环次数
    
    #拿到最少的流程卡  的玻璃数
    select count(*) into minglasscount from gmms_galss_task_shelf 
    where gc_number=parentliuchengka and work_state='已完成' and work_procedure='钢化后下片' 
    group by processcard_id order by count(*) asc LIMIT 0,1;
    select minglasscount;
    while count<Carcount do
        set liuchengka_=null;
        select liuchengka into liuchengka_ from gmms_liuchengka where parent_liuchengka=parentliuchengka limit count,1;
        
        set @Resultrank=0;
        update gmms_galss_task_shelf 
        set stop_position=stop_rank
        where processcard_id=liuchengka_ and work_state='已完成' and work_procedure='钢化后下片';
        
        update gmms_galss_task_shelf    
        set out_rank=0
        where processcard_id=liuchengka_ and work_state='已完成' and work_procedure='钢化后下片';
        
        set @Resultrank=minglasscount+1;
        update gmms_galss_task_shelf    
        set out_rank=(@Resultrank:=@Resultrank-1) 
        where processcard_id=liuchengka_ and work_state='已完成' and work_procedure='钢化后下片' 
        order by stop_rank desc limit minglasscount;
        
        SET count=count+1;
    end while;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for y_optimize_setrank
-- ----------------------------
DROP PROCEDURE IF EXISTS `y_optimize_setrank`;
delimiter ;;
CREATE PROCEDURE `y_optimize_setrank`(in parentliuchengka varchar(255),in widths double,in heights double,in maxrank int,in minrank int,in Carcount int)
BEGIN
    #总优化 传入总流程卡,宽,高,顺序
    DECLARE no_more_record DOUBLE DEFAULT 0;  #是否还有数据
    DECLARE liuchengkas varchar(255);
     DECLARE Actualcount int DEFAULT 0;
    #遍历   此合片流程卡内的 子片流程卡 
    DECLARE y_optimize_setrank CURSOR FOR SELECT liuchengka FROM gmms_liuchengka 
    where parent_liuchengka=parentliuchengka;
    DECLARE CONTINUE HANDLER FOR NOT FOUND SET no_more_record = 1;
    OPEN y_optimize_setrank;
    FETCH y_optimize_setrank INTO liuchengkas;
        while no_more_record!=1 do
            
            update gmms_galss_task_shelf 
            set stop_position=maxrank,gc_stockid=maxrank
            where work_state='已完成' and work_procedure='钢化后下片' and processcard_id=liuchengkas 
            and stop_position=0 and edg_width=widths and edg_height=heights order by stop_rank ASC limit 1;
            
            set no_more_record=0;#重置  以防into 改变了 no_more_record值跳出游标            
            FETCH y_optimize_setrank INTO liuchengkas;
        end while;    
    #关闭游标
    CLOSE y_optimize_setrank;
    
    select count(*) into Actualcount from  gmms_galss_task_shelf   
    where gc_number=parentliuchengka and work_state='已完成' and work_procedure='钢化后下片' 
    and stop_position=maxrank and edg_width=widths and edg_height=heights;
    
    if Carcount!=Actualcount and Carcount!=0 then
        update gmms_galss_task_shelf          
        set stop_position=minrank,gc_stockid=0
        where gc_number=parentliuchengka and  work_state='已完成' and work_procedure='钢化后下片' 
        and stop_position=maxrank and edg_width=widths and edg_height=heights;
    end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for y_RackFinsh
-- ----------------------------
DROP PROCEDURE IF EXISTS `y_RackFinsh`;
delimiter ;;
CREATE PROCEDURE `y_RackFinsh`(in machineids BIGINT,in flag BIGINT,in returnvalue varchar(255),out messagedate varchar(255))
BEGIN
    #料架完成
    DECLARE dates varchar(255);
    DECLARE groups1_ int DEFAULT 0;
    set @work_id=null;
    set @workingcount=null;
    set @sign=null;
    set @dropid=null;
    select work_id,remarks,flag into @work_id,@remarks,@flag1 from gmms_machine where id=machineids;
    if machineids=45 or machineids=69 then
        #钢化
        set groups1_=1;        
    elseif machineids=49 then
        #理片
        set groups1_=3;            
    elseif    machineids=51 or machineids=70 or machineids=72 or machineids=74    then
        #中空
        set groups1_=4;
    end if;
    
    select count(*) into @workingcount from gmms_drop_frame_5 where groups_=groups1_ and drop_groups=@work_id and (sign=2 or sign=5);
    select id,sign into @dropid,@sign from gmms_drop_frame_5 where groups_=groups1_ and drop_groups=@work_id and (sign=2 or sign=5);
    
    call message(returnvalue,'0014',@date);
    set messagedate=@date;
    
    if @workingcount=1 and messagedate is not null then
        if flag=1 then
            if @sign=2 then
                update gmms_drop_frame_5 set sign=3 where id=@dropid;
            elseif @sign=5 then
                update gmms_drop_frame_5 set sign=6 where id=@dropid;
            end if;
            insert into aaaa(MachineName,groups,data1,Content,Sendtext) values (machineids,@work_id,NOW(),'料架完成',messagedate);
        elseif flag=2 then
            if @sign=2 then
                update gmms_drop_frame_5 set sign=1 where id=@dropid;
            elseif @sign=5 then
                update gmms_drop_frame_5 set sign=4 where id=@dropid;
            end if;
            insert into aaaa(MachineName,groups,data1,Content,Sendtext) values (machineids,@work_id,NOW(),'料架失败',messagedate);        
        end if;        
--         call message(returnvalue,'0014',@date);
--       set messagedate=@date;    
    end if;
    
    
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for y_RackSend
-- ----------------------------
DROP PROCEDURE IF EXISTS `y_RackSend`;
delimiter ;;
CREATE PROCEDURE `y_RackSend`(in machineids BIGINT,in returnvalue varchar(255),out messagedate varchar(255))
BEGIN
    #移动料架
    DECLARE dates varchar(255);
    DECLARE groups1_ int DEFAULT 0;
    set @work_id=null;
    set @workingcount=null;
    set @sign=null;
    set @dropid=null;
    
    select work_id,flag into @work_id,@flag1 from gmms_machine where id=machineids;
    if machineids=45 or machineids=69 then
        #钢化
        set groups1_=1;
        select id,stops,sign,stop_rank into @dropid,@dropstops,@sign,@stoprank from gmms_drop_frame_5 
        where groups_=groups1_ and drop_groups=@work_id and (sign=4 or sign=1) limit 0,1;
    elseif machineids=49 then
        #理片
        set groups1_=3;    
        select id,stops,sign,stop_rank into @dropid,@dropstops,@sign,@stoprank from gmms_drop_frame_5 
        where groups_=groups1_ and drop_groups=@work_id and (sign=4 or sign=1) limit 0,1;        
        select @work_id;
        select @dropid;
    elseif    machineids=51 or machineids=70 or machineids=72 or machineids=74    then
        #中空
        set groups1_=4;
        select df.id,df.stops,df.sign,df.stop_rank,st.sign into @dropid,@dropstops,@sign,@stoprank,@sign2 from gmms_drop_frame_5 as df 
        INNER JOIN  gmms_drop_frame_5 as st on df.stop_rank=st.stop_rank 
        where df.groups_=groups1_ and st.groups_=groups1_ 
        and df.drop_groups=@work_id and st.drop_groups=@work_id and df.stops<3 and (df.sign=4 or df.sign=1) and (st.sign=0 or st.sign=7)
        order by df.sign asc,df.stops desc limit 0,1;
        #3.4固定工位  
        update gmms_drop_frame_5 set sign=3 where groups_=groups1_ and drop_groups=@work_id and stops>2 and sign=1;
        update gmms_drop_frame_5 set sign=6 where groups_=groups1_ and drop_groups=@work_id and stops>2 and sign=4;
    end if;
    select machineids;
    #查看有没有正在工作的工位
    select count(*) into @workingcount from gmms_drop_frame_5 where groups_=groups1_ and drop_groups=@work_id and (sign=2 or sign=5);
    if @workingcount<1 and @dropid is not null and @dropstops is not null then
        if @sign=4 and (@sign2=0 or groups1_!=4) then
            update gmms_drop_frame_5 set sign=5 where id=@dropid;
            call intTo2ByteHex10_16_4(@dropstops,@stopss);
            set dates=CONCAT(returnvalue,"0000",@stopss,'0002');    
            call message(dates,'000a',@date);
            set messagedate=@date;
            insert into aaaa(MachineName,groups,data1,Content,Sendtext) values (machineids,@work_id,NOW(),'料架出',messagedate);
        elseif @sign=1 then
            update gmms_drop_frame_5 set sign=2 where id=@dropid;
            call intTo2ByteHex10_16_4(@dropstops,@stopss);
            set dates=CONCAT(returnvalue,"0000",@stopss,'0001');    
            call message(dates,'000a',@date);
            set messagedate=@date;    
            insert into aaaa(MachineName,groups,data1,Content,Sendtext) values (machineids,@work_id,NOW(),'料架进',messagedate);
        end if;
    end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for y_RankHollowFinsh
-- ----------------------------
DROP PROCEDURE IF EXISTS `y_RankHollowFinsh`;
delimiter ;;
CREATE PROCEDURE `y_RankHollowFinsh`(in machineids BIGINT,in returnvalue varchar(255),out messagedate varchar(255))
BEGIN
    #中空料架完成
    DECLARE dates varchar(255);
    set @work_id=null;
    set @workingcount=null;
    set @sign=null;
    set @dropid=null;
    select work_id,remarks,flag into @work_id,@remarks,@flag1 from gmms_machine where id=machineids;
    select count(*) into @workingcount from gmms_drop_frame_4 where groups=@work_id and (sign=2 or sign=5);
    select id,sign into @dropid,@sign from gmms_drop_frame_4 where groups=@work_id and (sign=2 or sign=5);
    if @workingcount=1 then
        if @sign=2 then
            update gmms_drop_frame_4 set sign=3 where id=@dropid;
        elseif @sign=5 then
            update gmms_drop_frame_4 set sign=6 where id=@dropid;
        end if;
        call message(returnvalue,'0014',@date);
      set messagedate=@date;
    end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for y_RankHollowSend
-- ----------------------------
DROP PROCEDURE IF EXISTS `y_RankHollowSend`;
delimiter ;;
CREATE PROCEDURE `y_RankHollowSend`(in machineids BIGINT,in returnvalue varchar(255),out messagedate varchar(255))
BEGIN
    #中空料架
    DECLARE dates varchar(255);
    set @work_id=null;
    set @workingcount=null;
    set @sign=null;
    set @dropid=null;
    select work_id,remarks,flag into @work_id,@remarks,@flag1 from gmms_machine where id=machineids;
    select df.id,df.stops,df.sign,df.stop_rank into @dropid,@dropstops,@sign,@stoprank from gmms_drop_frame_4 as df 
    INNER JOIN  gmms_drop_frame_4 as st on df.stop_rank=st.stop_rank 
    where df.groups=@work_id and st.groups=@work_id and df.stops<3 and (df.sign=4 or df.sign=1) and st.sign=0 
    order by df.sign desc,df.stops desc;
    #3.4固定工位  
    update gmms_drop_frame_4 set sign=3 where groups=@work_id and stops>2 and sign=1;
    update gmms_drop_frame_4 set sign=6 where groups=@work_id and stops>2 and sign=4;
    
    #查看有没有正在工作的工位
    select count(*) into @workingcount from gmms_drop_frame_4 where groups=@work_id and (sign=2 or sign=5);
    if @workingcount<1 and @dropid is not null then
        if @sign=4 then
            update gmms_drop_frame_4 set sign=5 where id=@dropid;
            call intTo2ByteHex10_16_4(@dropstops,@stopss);
            set dates=CONCAT(@returnvalue,"0000",@stopss,'0002');    
            call message(dates,'000a',@date);
            set messagedate=@date;
        elseif @sign=1 then
            update gmms_drop_frame_4 set sign=2 where id=@dropid;
            call intTo2ByteHex10_16_4(@dropstops,@stopss);
            set dates=CONCAT(@returnvalue,"0000",@stopss,'0001');    
            call message(dates,'000a',@date);
            set messagedate=@date;
        end if;
    end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for y_RobotHollow
-- ----------------------------
DROP PROCEDURE IF EXISTS `y_RobotHollow`;
delimiter ;;
CREATE PROCEDURE `y_RobotHollow`(in machineids BIGINT,in returnvalue varchar(255),out messagedate varchar(255))
BEGIN
    #中空
    DECLARE dates varchar(255);
    DECLARE parentliuchengka_ varchar(255) DEFAULT null;
    DECLARE prcount_ int DEFAULT 0;      #启用/禁用
    set @work_id=null;
    set @liuchengka=null;
    set @dropcount=null;
    set @id=null;
    set @color=null;
    set @processcount=null;
    set @stops=null;
    set @date=null;
    set @sign=null;
    set @processcard_id=null;
    set @cll=null;
    set @Occupieds=null;
    set @SuctionSheetMode=null;
    set @parent_liuchengka=null;
    select work_id,remarks,flag into @work_id,@remarks,@flag1 from gmms_machine where id=machineids;
    select @work_id;
    select lk.parent_liuchengka,lk.piece_count,lk2.Occupied,lk2.Suction_sheet_mode into @parent_liuchengka,@piececount,@Occupieds,@SuctionSheetMode from gmms_drop_frame_5 as dr5 
    left join gmms_shelf_rack_2 as sr on dr5.rank=sr.id
    left join gmms_liuchengka as lk on sr.processcard_id=lk.liuchengka
    left join gmms_liuchengka as lk2 on lk.parent_liuchengka=lk2.liuchengka
    where groups_=4 and drop_groups=@work_id and sr.id is not null and lk.liuchengka is not null and lk2.liuchengka is not null and
    lk2.current_status='正在工作' and lk2.current_work_position='中空' order by lk.liuchengka limit 0,1;
 
    if @parent_liuchengka is null then
        select lk.parent_liuchengka,lk2.Occupied into parentliuchengka_,@Occupieds from gmms_drop_frame_5 as dr5 
        left join gmms_shelf_rack_2 as sr on dr5.rank=sr.id
        left join gmms_liuchengka as lk on sr.processcard_id=lk.liuchengka
        left join gmms_liuchengka as lk2 on lk.parent_liuchengka=lk2.liuchengka
        where groups_=4 and drop_groups=@work_id and sr.id is not null and lk.liuchengka is not null and lk2.liuchengka is not null and
        lk2.current_status='等待中' and lk2.current_work_position='中空' order by lk.liuchengka limit 0,1;
        if @Occupieds=2 then
            #退库
            update gmms_drop_frame_5 as dr left join gmms_shelf_rack_2 as sr on dr.rank=sr.id
            left join gmms_liuchengka as lk on lk.liuchengka=sr.processcard_id
            set dr.sign=4
            where dr.rank is not null and sr.processcard_id is not null and lk.parent_liuchengka=parentliuchengka_ and dr.sign=3;
            #update gmms_liuchengka set current_status='等待中' where liuchengka=@parent_liuchengka;
        else
            update gmms_liuchengka set current_work_position='中空',current_status='正在工作' where liuchengka=parentliuchengka_;
        end if;        
    end if;
    
    #是否存在正在工作的任务  @workingcount
    select count(*) into @workingcount from gmms_galss_task_shelf 
    where work_state='正在工作' and work_procedure='中空上片' and gc_number=@parent_liuchengka;
 
    #吸片
    if @remarks=1 then
    if @workingcount<1 and @parent_liuchengka is not null then
        select @Occupieds;
        set @id=null;
        select @parent_liuchengka;
         if @SuctionSheetMode=0 then
             select id,galss_id,edg_width,edg_height,stop_rank,thickness,color,processcard_id,SUBSTR(processcard_id,LOCATE('/',processcard_id)+1) as cardrank 
             into @id,@galss_id,@edg_width,@edg_height,@stop_rank,@thickness,@color,@processcard_id,@cardrank from gmms_galss_task_shelf 
             where work_state='已完成' and work_procedure='钢化后下片' and gc_number=@parent_liuchengka and out_rank>0
             order by out_rank desc,cardrank desc limit 0,1;
         elseif @SuctionSheetMode=1 then
             select id,galss_id,edg_width,edg_height,stop_rank,thickness,color,processcard_id,SUBSTR(processcard_id,LOCATE('/',processcard_id)+1) as cardrank 
             into @id,@galss_id,@edg_width,@edg_height,@stop_rank,@thickness,@color,@processcard_id,@cardrank from gmms_galss_task_shelf 
             where work_state='已完成' and work_procedure='钢化后下片' and gc_number=@parent_liuchengka and out_rank>0
             order by out_rank desc,cardrank asc limit 0,1;
         end if;
        
--         select id,galss_id,edg_width,edg_height,stop_rank,thickness,color,processcard_id,SUBSTR(processcard_id,LOCATE('/',processcard_id)+1) as cardrank 
--         into @id,@galss_id,@edg_width,@edg_height,@stop_rank,@thickness,@color,@processcard_id,@cardrank from gmms_galss_task_shelf 
--         where work_state='已完成' and work_procedure='钢化后下片' and gc_number=@parent_liuchengka and out_rank>0
--         order by out_rank desc,cardrank desc limit 0,1;
        
        if @id is null and @Occupieds=1 then
            select id,galss_id,edg_width,edg_height,stop_rank,thickness,color,processcard_id,SUBSTR(processcard_id,LOCATE('/',processcard_id)+1) as cardrank 
            into @id,@galss_id,@edg_width,@edg_height,@stop_rank,@thickness,@color,@processcard_id,@cardrank from gmms_galss_task_shelf 
            where work_state='已完成' and work_procedure='钢化后下片' and gc_number=@parent_liuchengka and stop_position>0
            order by galss_id asc limit 0,1;
        elseif @Occupieds=2 then
            #退库
            update gmms_drop_frame_5 as dr left join gmms_shelf_rack_2 as sr on dr.rank=sr.id
            left join gmms_liuchengka as lk on lk.liuchengka=sr.processcard_id
            set dr.sign=4
            where dr.rank is not null and sr.processcard_id is not null and lk.parent_liuchengka=@parent_liuchengka and dr.sign=3;
            update gmms_liuchengka set current_status='等待中' where liuchengka=@parent_liuchengka;
        end if;
        select @id;
        
        select IFNULL(max(stop_rank),0) into prcount_ from gmms_galss_task_shelf 
        where processcard_id=@processcard_id and out_rank>0 and work_state!='破损' and (groupsss is null or groupsss=@work_id);
        
        select stops,dr5.sign into @stops,@sign from gmms_drop_frame_5 as dr5 left join gmms_shelf_rack_2 as sr on dr5.rank=sr.id
        where sr.processcard_id=@processcard_id and sr.id is not null;
        select @stops;
        if (select count(*) from galss_C where color=@color)>0 then
            set @cll='0000';
        else
            set @cll='0001';
        end if;    
        if @id is not null and @cll is not null and @stops is not null and @sign=3 then                    
            update gmms_galss_task_shelf set work_state='正在工作',work_procedure='中空上片',start_time=NOW() 
            where id=@id and work_procedure='钢化后下片';
            call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
            call intTo2ByteHex10_16_4(@stops,@stopss);
            call intTo2ByteHex10_16_4(@edg_width,@widths);
            call intTo2ByteHex10_16_4(@edg_height,@heights);
            call intTo2ByteHex10_16_4(@thickness,@thicknesss);
            call intTo2ByteHex10_16_4(@stop_rank,@stop_ranks);
            call intTo2ByteHex10_16_4(prcount_,@processcard_counts);                                
            set dates=CONCAT(returnvalue,@galss_ids,@processcard_counts,'0000',@stopss,@widths,@heights,@thicknesss,@stop_ranks,@cll);
            call message(dates,'000a',@date);
            set messagedate=@date;
        end if;
    end if;    
    end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for y_RobotHollowFinsh
-- ----------------------------
DROP PROCEDURE IF EXISTS `y_RobotHollowFinsh`;
delimiter ;;
CREATE PROCEDURE `y_RobotHollowFinsh`(in flag int,in machineids BIGINT,in returnvalue varchar(255),out messagedate varchar(255))
BEGIN
    #中空完成
    DECLARE dates varchar(255);
    set @work_id=null;
    set @liuchengka=null;
    set @id=null;
    set @workingcount=null;
    set @processcard_id=null;
    set @workcount=null;
    set @dropid=null;    
    set @date=null;
    set @worked=null;
    select work_id,remarks,flag into @work_id,@remarks,@flag1 from gmms_machine where id=machineids;
    
    select lk.parent_liuchengka,lk.piece_count into @parent_liuchengka,@piececount from gmms_drop_frame_5 as dr5 
    left join gmms_shelf_rack_2 as sr on dr5.rank=sr.id
    left join gmms_liuchengka as lk on sr.processcard_id=lk.liuchengka
    left join gmms_liuchengka as lk2 on lk.parent_liuchengka=lk2.liuchengka
    where groups_=4 and drop_groups=@work_id and sr.id is not null and lk.liuchengka is not null and lk2.liuchengka is not null and
    lk2.current_status='正在工作' and lk2.current_work_position='中空' order by lk.liuchengka limit 0,1;
    
    select count(*) into @workingcount from gmms_galss_task_shelf 
    where work_state='正在工作' and work_procedure='中空上片' and gc_number = @parent_liuchengka;        
    if @workingcount=1 then
        select id,processcard_id into @id,@processcard_id from gmms_galss_task_shelf 
        where work_state='正在工作' and work_procedure='中空上片' and gc_number = @parent_liuchengka;
        if @id is not null then
            if flag=1 then
                update gmms_galss_task_shelf set work_state='已完成',finsh_time=NOW(),groupsss=@work_id where id=@id;
                call message(returnvalue,'0014',@date);
                set messagedate=@date;
                INSERT INTO e_record_hollow(processcard_id, glass_id, width, height, thinkess, color, sequence, create_time, line, team_name, type_num, is_report) 
                        select gt.processcard_id,gt.id,gt.edg_width,gt.edg_height,gt.thickness,gt.color,gt.stop_rank,gt.finsh_time,@work_id,gt.banzu,gt.edg_speed2,1 from gmms_galss_task_shelf as gt 
                        left join e_record_hollow as et on gt.id=et.glass_id 
                        where et.glass_id is null and gt.id=@id and gt.work_state='已完成' and gt.work_procedure='中空上片';
            elseif flag=2 then
                update gmms_galss_task_shelf set work_state='已完成',work_procedure='钢化后下片' where id=@id;
                call message(returnvalue,'0014',@date);
                set messagedate=@date;
            elseif flag=3 then
                update gmms_galss_task_shelf set work_state='破损',groupsss=@work_id where id=@id;
                call message(returnvalue,'0014',@date);
                set messagedate=@date;
            end if;
            #查看此流程卡是否还有任务
            select count(*) into @workcount from gmms_galss_task_shelf 
            where processcard_id=@processcard_id and (work_state='已完成' or work_state='正在工作') and work_procedure='钢化后下片' and 
            out_rank>0;
            select count(*) into @worked from gmms_galss_task_shelf 
            where processcard_id=@processcard_id and (work_state='已完成' or work_state='正在工作') and work_procedure='钢化后下片';
            
            select dr5.id,stops into @dropid,@stops from gmms_drop_frame_5 as dr5 
            left join gmms_shelf_rack_2 as sr on dr5.rank=sr.id
            where sr.id is not null and sr.processcard_id=@processcard_id LIMIT 1;
            if @worked<1 then
              if @dropid is not null and (@stops=1 or @stops=2) then
                    update gmms_drop_frame_5 set sign=4 where id=@dropid;
                elseif @dropid is not null then
                    update gmms_drop_frame_5 set sign=6 where id=@dropid;
                end if;
                if @worked=0 then
                    update gmms_shelf_rack_2 as sr left join gmms_drop_frame_5 as dr on sr.id=dr.rank
                    set sr.processcard_id=null
                    where dr.rank is not null and dr.groups_=4 and dr.id=@dropid;
                end if;
            end if;
        end if;
    else
        call message(returnvalue,'0014',@date);
        set messagedate=@date;
    end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for y_RobotHollowSlicecage
-- ----------------------------
DROP PROCEDURE IF EXISTS `y_RobotHollowSlicecage`;
delimiter ;;
CREATE PROCEDURE `y_RobotHollowSlicecage`(in machineids BIGINT,in returnvalue varchar(255),out messagedate varchar(255))
BEGIN
    #中空理片机器手
    DECLARE dates varchar(255);
    DECLARE rankcount int DEFAULT 0;
    DECLARE signs_ int DEFAULT 0;
    DECLARE ranksumcount int DEFAULT 0;
    DECLARE maxpostoprank int DEFAULT 0;
    DECLARE stoprank int DEFAULT 0;
    DECLARE minstoprank int DEFAULT 0;
    DECLARE liuchengka_ varchar(255) DEFAULT null;
    DECLARE ischuku_ varchar(255) DEFAULT null;
    set @processcardid=null;
    set @id=null;
    set @sliceagecount=null;
    set @finshcount=null;
    set @piececount=null;
    set @dropid=null;
    set @outid=null;
  select remarks into @remarks from gmms_machine where id=machineids;
    #找到有任务的第一个工位,流程卡 默认B  A
    select dr5.id,lk.liuchengka,dr5.stops,lk.piece_count,dr5.sign,lk.ischu into @dropid,@processcardid,@stops,@piececount,signs_,ischuku_ from gmms_drop_frame_5 as dr5 
    left join gmms_shelf_rack_2 as sr on dr5.rank=sr.id
    left join gmms_liuchengka as lk on sr.processcard_id=lk.liuchengka
    where groups_=3 and drop_groups=1 and sr.id is not null and lk.liuchengka is not null and 
    lk.current_status='正在工作' and lk.current_work_position='理片';
  if @processcardid is null then
        select lk.liuchengka into liuchengka_ from gmms_drop_frame_5 as dr5 
        left join gmms_shelf_rack_2 as sr on dr5.rank=sr.id
        left join gmms_liuchengka as lk on sr.processcard_id=lk.liuchengka
        where groups_=3 and drop_groups=1 and dr5.sign=3 and sr.id is not null and lk.liuchengka is not null and 
        lk.current_status='等待中' and lk.current_work_position='理片' LIMIT 0,1;
        update gmms_liuchengka set current_work_position='理片',current_status='正在工作' where liuchengka=liuchengka_;
    end if;
    #未配对的数量,最小的玻璃顺序
    select count(*),min(stop_rank) into @sliceagecount,minstoprank from gmms_galss_task_shelf 
    where processcard_id=@processcardid and work_state='已完成' and work_procedure='钢化后下片' 
    and stop_position!=stop_rank and stop_position>0;
    
    #架子上的数量
    select count(*) into rankcount from gmms_galss_task_shelf 
    where processcard_id=@processcardid and ((work_state='已完成' and work_procedure='钢化后下片') or work_state='破损') and stop_position>0;
    
  #架子上的总数量
    select IFNULL(max(stop_rank),0) into ranksumcount from gmms_galss_task_shelf 
    where processcard_id=@processcardid and stop_position>0 and work_state!='破损';
    #优化结果中  架上最大的破损序号
    select IFNULL(max(stop_rank),0) into maxpostoprank from gmms_galss_task_shelf 
    where processcard_id=@processcardid and stop_position>0 and work_state='破损';
    
    select count(*) into @workcount from gmms_galss_task_shelf 
    where processcard_id=@processcardid and work_state='正在工作' and (work_procedure='理片笼上片' or work_procedure='理片笼下片');
    
    select @dropid,@workcount,@processcardid,signs_,@remarks,@sliceagecount,ischuku_;
    #and ranksumcount>=maxpostoprank
    if @dropid is not null and @workcount=0 and @processcardid is not null and signs_=3 and @remarks=1 then
        if @sliceagecount>0 and ischuku_ is null then
            #找到任务工位上 最外面的玻璃信息
            select id,galss_id,edg_width,edg_height,thickness,stop_rank,processcard_id,edg_speed2
            into @id,@galss_id,@edg_width,@edg_height,@thickness,stoprank,@processcard_id,@edg_speed2 from gmms_galss_task_shelf 
            where processcard_id=@processcardid and work_state='已完成' and work_procedure='钢化后下片'
            order by stop_rank desc limit 0,1;
            if @id is not null then                
                call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
                call intTo2ByteHex10_16_4(@stops,@stopss);
                call intTo2ByteHex10_16_4(@edg_width,@widths);
                call intTo2ByteHex10_16_4(@edg_height,@heights);
                call intTo2ByteHex10_16_4(@thickness,@thicknesss);
                call intTo2ByteHex10_16_4(stoprank,@stop_rankss);
                call intTo2ByteHex10_16_4(ranksumcount,@processcard_counts);
                if stoprank=minstoprank then
                    set dates=CONCAT(returnvalue,@galss_ids,@processcard_counts,'0001',@stopss,@widths,@heights,@thicknesss,@stop_rankss,'0000');
                else
                    set dates=CONCAT(returnvalue,@galss_ids,@processcard_counts,'0001',@stopss,@widths,@heights,@thicknesss,@stop_rankss,'0001');
                end if;
                if dates is not null then
                    update gmms_galss_task_shelf set work_state='正在工作',work_procedure='理片笼上片' where id=@id;
                end if;
                
                call message(dates,'000a',@date);
                set messagedate=@date;
                insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,IFNULL(@id,0),NOW(),'发送理片机器人上片任务',"",messagedate);
            end if;            
        else
            update gmms_liuchengka set ischu='出库' where liuchengka=@processcardid and ischu='待出库';
            select id,galss_id,edg_width,edg_height,thickness,stop_rank,processcard_id
            into @outid,@galss_id,@edg_width,@edg_height,@thickness,stoprank,@processcard_id from gmms_galss_task_shelf 
            where processcard_id=@processcardid and work_state='已出库' and work_procedure='理片'
            order by stop_rank asc limit 0,1;
            if @outid is not null then                
                call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
                call intTo2ByteHex10_16_4(@stops,@stopss);
                call intTo2ByteHex10_16_4(@edg_width,@widths);
                call intTo2ByteHex10_16_4(@edg_height,@heights);
                call intTo2ByteHex10_16_4(@thickness,@thicknesss);
                call intTo2ByteHex10_16_4(stoprank,@stop_rankss);
                if (ranksumcount-1)=rankcount then
                    set dates=CONCAT(returnvalue,@galss_ids,'00000002',@stopss,@widths,@heights,@thicknesss,@stop_rankss,'0000');
                else
                    set dates=CONCAT(returnvalue,@galss_ids,'00000002',@stopss,@widths,@heights,@thicknesss,@stop_rankss,'0001');
                end if;
                if dates is not null then
                    update gmms_galss_task_shelf set work_state='正在工作',work_procedure='理片笼下片' where id=@outid;        
                end if;
                call message(dates,'000a',@date);
                set messagedate=@date;
                insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,IFNULL(@outid,0),NOW(),'发送理片机器人下片任务',"",messagedate);
            end if;
            select '此时剩下玻璃片序相同,等待理片出片!';
        end if;
--     else
--         #标记  流程卡开始理片
--         update gmms_drop_frame_5 as dr5 
--         left join gmms_shelf_rack_2 as sr on dr5.rank=sr.id
--         left join gmms_liuchengka as lk on sr.processcard_id=lk.liuchengka
--         set lk.current_status='正在工作'
--         where groups_=3 and drop_groups=1 and sr.id is not null and lk.liuchengka is not null and 
--         lk.current_status='等待中' and lk.current_work_position='理片';
--     
end if;
    
    
    
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for y_RobotHollowSlicecageFinsh
-- ----------------------------
DROP PROCEDURE IF EXISTS `y_RobotHollowSlicecageFinsh`;
delimiter ;;
CREATE PROCEDURE `y_RobotHollowSlicecageFinsh`(in machineids BIGINT,in returnvalue varchar(255),in flag int,out messagedate varchar(255))
BEGIN
    DECLARE wordedcount int DEFAULT 0;      #启用/禁用
    DECLARE posuncount int DEFAULT 0;      #启用/禁用
    DECLARE zongcount int DEFAULT 0;      #启用/禁用
    set @id=null;
    set @workingcount=null;
    set @work_procedure=null;
    set @processcardid=null;
    set @date=null;
    #理片完成
    #找到有任务的第一个工位,流程卡 默认B  A
    select dr5.id,lk.liuchengka,dr5.stops,lk.piece_count into @dropid,@processcardid,@stops,@piececount from gmms_drop_frame_5 as dr5 
    left join gmms_shelf_rack_2 as sr on dr5.rank=sr.id
    left join gmms_liuchengka as lk on sr.processcard_id=lk.liuchengka
    where groups_=3 and drop_groups=1 and sr.id is not null and lk.liuchengka is not null and 
    lk.current_status='正在工作' and lk.current_work_position='理片';
    
    select count(*) into @workingcount from gmms_galss_task_shelf 
    where processcard_id=@processcardid and work_state='正在工作' and (work_procedure='理片笼上片' or work_procedure='理片笼下片');
    
    select id,work_procedure,processcard_id,out_rank into @id,@work_procedure,@processcard_id,@outrank from gmms_galss_task_shelf 
    where processcard_id=@processcardid and work_state='正在工作' and (work_procedure='理片笼上片' or work_procedure='理片笼下片') limit 0,1;
    
    if @workingcount=1 and @id is not null then
    #得到正在工作的 任务数据    
        if flag=1 then
        #任务完成
            if @work_procedure='理片笼上片' then
                update gmms_galss_task_shelf set work_state='已完成' where id=@id;
            elseif @work_procedure='理片笼下片' then
                update gmms_galss_task_shelf set work_procedure='钢化后下片',work_state='已完成' where id=@id;
                
                select count(*) into wordedcount from gmms_galss_task_shelf 
                where processcard_id=@processcard_id and work_procedure='钢化后下片' and work_state='已完成' and stop_position>0 and stop_rank=stop_position;
                select count(*) into posuncount from gmms_galss_task_shelf 
                where processcard_id=@processcard_id and work_state='破损' and stop_position>0;
                select count(*) into zongcount from gmms_galss_task_shelf 
                where processcard_id=@processcard_id and stop_position>0;
                if wordedcount+posuncount=zongcount then
                    #完成
                    update gmms_drop_frame_5 set sign=4 where id=@dropid;
                    update gmms_liuchengka set current_work_position='理片',current_status='已完成' where liuchengka=@processcardid;
                end if;    
            end if;
        elseif flag=2 then
        #任务失败
            if @work_procedure='理片笼上片' then
                update gmms_galss_task_shelf set work_state='已完成',work_procedure='钢化后下片' where id=@id;
            elseif @work_procedure='理片笼下片' then
                update gmms_galss_task_shelf set work_state='已出库',work_procedure='理片' where id=@id;        
            end if;
        end if;    
        call message(returnvalue,'0014',@date);
        set messagedate=@date;    
    end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for y_RobotLeng
-- ----------------------------
DROP PROCEDURE IF EXISTS `y_RobotLeng`;
delimiter ;;
CREATE PROCEDURE `y_RobotLeng`(in machineids BIGINT,in returnvalue varchar(255),in rankid BIGINT,out messagedate varchar(255))
BEGIN
    #中空
    DECLARE dates varchar(255);
    DECLARE filename_ varchar(255) DEFAULT null;
    DECLARE workcount_ int DEFAULT 0;      #启用/禁用
    select machine_type_id,work_id into @mtid,@work_groups from gmms_machine where id=machineids;
    set @work_groups=1;
    select file_name into filename_ from gmms_raw_file where operator=@work_groups and state='已领取' limit 0,1;
    select count(*) into workcount_ from gmms_galss_task 
    where work_state='正在工作' and work_procedure='机器人下片' and engineering_id=filename_;
    
    select dr.stops,out_rank,gs.drop_frame,width,height,thickness,gs.processcard_id into @stops,@galss_id,@drop_frame,@width,@height,@thickness,@processcard_id from gmms_galss_task as gs
    left join gmms_drop_frame as dr on gs.processcard_id=dr.processcard_id
    where gs.work_state='等待中' and gs.work_procedure='机器人下片' and gs.engineering_id=filename_ and dr.processcard_id is not null
    order by out_rank asc limit 0,1; 
    
    select returnvalue,@galss_id,@stops,@width,@height,@thickness;
    if @stops is not null then
        call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
        call intTo2ByteHex10_16_4(@stops,@stopss);
        call intTo2ByteHex10_16_4(@width,@widths);
        call intTo2ByteHex10_16_4(@height,@heights);
        call intTo2ByteHex10_16_4(@thickness,@thicknesss);
        set dates=CONCAT(returnvalue,@galss_ids,"00000000",@stopss,@widths,@heights,@thicknesss);
        call message(dates,'000a',@date);
        set messagedate=@date;
        if messagedate is not null then
            update gmms_galss_task set work_state='正在工作' 
            where work_state='等待中' and work_procedure='机器人下片' and out_rank=@galss_id and processcard_id=@processcard_id limit 1;
            insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,"",NOW(),'发送机器人下片任务',"",messagedate);
        end if;
        #无任务
    end if;
--     set @galss_id=1,@stops=4,@edg_width=934,@edg_height=483,@thickness=5;
--     
--     call intTo2ByteHex10_16_4(@galss_id,@galss_ids);
--     call intTo2ByteHex10_16_4(@stops,@stopss);
--     call intTo2ByteHex10_16_4(@edg_width,@widths);
--     call intTo2ByteHex10_16_4(@edg_height,@heights);
--     call intTo2ByteHex10_16_4(@thickness,@thicknesss);
--     insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,"",NOW(),'发送下片任务',"",@stops);
--     set dates=CONCAT(returnvalue,@galss_ids,"00000000",@stopss,@widths,@heights,@thicknesss);
--     call message(dates,'000a',@date);
--     set messagedate=@date;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for y_RobotLengFinsh
-- ----------------------------
DROP PROCEDURE IF EXISTS `y_RobotLengFinsh`;
delimiter ;;
CREATE PROCEDURE `y_RobotLengFinsh`(in flag int,in machineids BIGINT,in returnvalue varchar(255),in rankid BIGINT,out messagedate varchar(255))
BEGIN
    #冷加工一线完成
    DECLARE dates varchar(255);
    DECLARE filename_ varchar(255) DEFAULT null;
    DECLARE count1 int;
    DECLARE count2 int;
    set @mtid=null;
    set @work_groups=null;
    set @processcard_id=null;
    set @drop_frame=null;
    set @galss_type=null;
    set @id1=null;
    set @id=null;
    set @sum=null;
    set @processcard_count=null;
    set @findcount=null;
    set @posuncount=null;
    set @maxstoprank=null;
    
    select machine_type_id,work_id into @mtid,@work_groups from gmms_machine where id=machineids;
    set @work_groups=1;
    select file_name into filename_ from gmms_raw_file where operator=@work_groups and state='已领取' limit 0,1;        
 
    select drop_frame,processcard_id,galss_type,id into @drop_frame,@processcard_id,@galss_type,@id1 from gmms_galss_task 
    where work_state='正在工作' and work_procedure='机器人下片' and out_rank=rankid and engineering_id=filename_ limit 0,1;
    
    #获取流程卡 总数:@processcard_count 完成数量 @sum
    select stops,finsh_count,processcard_count into @id,@sum,@processcard_count from gmms_drop_frame 
    where drop_frame=@drop_frame and processcard_id=@processcard_id and groups=@work_groups;
    #完成数量和破损数量
    select count(*) into @findcount from gmms_galss_task where processcard_id=@processcard_id and engineering_id=filename_ and work_state='已完成' and work_procedure='机器人下片';
    select count(*) into @posuncount from gmms_galss_task where processcard_id=@processcard_id and engineering_id=filename_ and work_state='破损';
    
    #获取最大的机器人下片位
    select count(*) into @maxstoprank from gmms_galss_task_stock where id>(select min(id) from (select * from gmms_galss_task_stock order by id desc limit 40000) as tbmin) and processcard_id=@processcard_id;
    
    select @work_groups,@drop_frame,filename_;
    if @drop_frame is not null then
        set count1=@maxstoprank+1;
        set count2=@sum+1;
        
        #满架下完 记录手机APP使用
        if @processcard_count=@findcount+@posuncount then
            call workmanships(@processcard_id);
        end if;
        
        if @processcard_count=count2 then
            call intTo2ByteHex10_16_4(@id,@ids);
            set dates=CONCAT(returnvalue,'00000000000000000001');
            call message(dates,'0018',@date);
            set messagedate=@date;
        else
            call message(returnvalue,'0018',@date);
            set messagedate=@date;
        end if;
            if messagedate is not null then
                update gmms_galss_task set work_state='已完成',work_procedure='下片',gc_stockid=@work_groups,stop_rank=count1,finsh_time=now(),work_procedure_number=500 
                where work_state='正在工作' and work_procedure='机器人下片' and out_rank=rankid and engineering_id=filename_ limit 1;
                update gmms_drop_frame set finsh_count=count2 where processcard_id=@processcard_id and groups=@work_groups;
                insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,"",NOW(),'发送机器人下片任务完成',"",messagedate);
                #非手动任务添加进机器人下片表
                if @galss_type=0 and (select count(*)    from gmms_galss_task_stock where id=@id1)=0 then
                    insert into gmms_galss_task_details select * from gmms_galss_task where engineering_id=filename_ and id=@id1;
                    insert into gmms_galss_task_stock select * from gmms_galss_task where engineering_id=filename_ and id=@id1;
                end if;
            end if;
    else
        select 1;
--         call message(returnvalue,'0018',@date);
--         set messagedate=@date;
        #insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,"",NOW(),'无任务发送机器人下片任务完成',"",messagedate);
    end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for y_RobotTemperingAfter
-- ----------------------------
DROP PROCEDURE IF EXISTS `y_RobotTemperingAfter`;
delimiter ;;
CREATE PROCEDURE `y_RobotTemperingAfter`(in rankid varchar(255),in machineids BIGINT,in returnvalue varchar(255),out messagedate varchar(255))
BEGIN
    #钢化后下片机械手
    DECLARE dates varchar(255);
    
    set @id=null;
    set @processcard_id=null;
    set @dropid=null;
    set @stops=null;
    set @workedcount=null;
    set @shelfracid=null;
    set @date=null;
    set @width=null;
    set @height=null;
    select work_id,remarks,flag into @work_id,@remarks,@flag1 from gmms_machine where id=machineids;
 
    select count(*) into @workingcount from gmms_galss_task_2 
    where work_state='正在工作' and work_procedure='钢化后下片' and groups=@work_id;
        
    select id,width,height,thickness,processcard_id,engineering_id,drop_frame 
    into @id,@width,@height,@thickness,@processcard_id,@engineering_id,@drop_frame from gmms_galss_task_2 
    where work_state='等待中' and work_procedure='钢化后下片' and groups=@work_id and galss_id=rankid limit 0,1;
    
    select count(*) into @workcount from gmms_galss_task_2 
    where work_state='等待中' and work_procedure='钢化后下片' and groups=@work_id and processcard_id=@processcard_id;
    select count(*) into @workedcount from gmms_galss_task_2 
    where work_state='已完成' and work_procedure='钢化后下片' and groups=@work_id and processcard_id=@processcard_id;
    
    #无工作中任务  查找是否存在此ID任务    正在工作的数量:@workingcount  等待中的数量:@workcount  已完成的数量:@workedcount
    if @workingcount=0 and @processcard_id is not null and @workcount>0 and @id is not null then                    
        select stops into @stops from gmms_drop_frame_5 as dr5 left join gmms_shelf_rack_2 as sr on dr5.rank=sr.id
        where sr.processcard_id=@processcard_id and groups_=1 and drop_groups=@work_id and rank is not null;
        if @stops is not null then        
            set @workedcount=@workedcount+1;
            call intTo2ByteHex10_16_4(rankid,@galss_ids);
            call intTo2ByteHex10_16_4(@stops,@stopss);
            call intTo2ByteHex10_16_4(@width,@widths);
            call intTo2ByteHex10_16_4(@height,@heights);
            call intTo2ByteHex10_16_4(@thickness,@thicknesss);
            call intTo2ByteHex10_16_4(@workedcount,@finsh_counts);
            set dates=CONCAT(returnvalue,@galss_ids,'00000000',@stopss,@widths,@heights,@thicknesss,@finsh_counts);
            call message(dates,'000a',@date);
            set messagedate=@date;
            insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,@work_id,NOW(),'下片发送任务',@id,messagedate);
            update gmms_galss_task_2 set work_state='正在工作' where id=@id;
        else
            #自动绑架子  flag:1进入,2进入中,3到达指定位,4退出,5退出中,6等待退库
            select dr5.id,dr5.rank into @idrop,@shelfracid from gmms_drop_frame_5 as dr5 left join gmms_shelf_rack_2 as sr on dr5.rank=sr.id
            where  dr5.groups_=1 and dr5.drop_groups=@work_id and dr5.sign=3 and sr.processcard_id is null 
            and rank is not null and dr5.flag=1 limit 0,1;
            if @idrop is not null then
                update gmms_shelf_rack_2 set processcard_id=@processcard_id where id=@shelfracid;
                insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,@work_id,NOW(),'绑定新架子',rankid,@idrop);
            end if;
        end if;
    else 
        #当前正在工作
        select CONCAT('正在工作/此任务id不存在:',rankid);
    end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for y_RobotTemperingAfterFinsh
-- ----------------------------
DROP PROCEDURE IF EXISTS `y_RobotTemperingAfterFinsh`;
delimiter ;;
CREATE PROCEDURE `y_RobotTemperingAfterFinsh`(in flag int,in machineids BIGINT,in returnvalue varchar(255),out messagedate varchar(255))
BEGIN
    #钢化后下片机械手
    DECLARE dates varchar(255);
    DECLARE workedcounted INT DEFAULT 0; #记录总行数
    DECLARE workedcount INT DEFAULT 0;
    set @remarks=null;
    set @workingcount=null;
    set @id=null;
    set @rank=null;
    set @dropid=null;
    set @date=null;
    
    select work_id,remarks,flag into @work_id,@remarks,@flag1 from gmms_machine where id=machineids;
    
    select count(*) into @workingcount from gmms_galss_task_2
    where groups=@work_id and work_state='正在工作' and work_procedure='钢化后下片';
    
    if @workingcount=1 then
        select id,galss_id,processcard_id into @id,@galss_id,@processcardid from gmms_galss_task_2
        where groups=@work_id and work_state='正在工作' and work_procedure='钢化后下片' order by galss_id asc LIMIT 1;
        
        select count(*) into workedcount from gmms_galss_task_2
        where groups=@work_id and work_state='已完成' and work_procedure='钢化后下片' and processcard_id=@processcardid;
        
        select df.id,df.rank into @dropid,@rank from gmms_drop_frame_5 as df left join gmms_shelf_rack_2 as sr on df.rank=sr.id
        where sr.processcard_id=@processcardid and df.groups_=1 and df.drop_groups=@work_id;
        if flag=1 then
            set workedcount=workedcount+1;
--             update gmms_galss_task_2 set work_state='已完成',fine_throwing=@rank,stop_position=0,stop_rank=workedcount,finsh_time=NOW()     
--             where id=@id;
--             
            update gmms_galss_task_2 as gt INNER join gmms_user_current as guc on gt.groups=guc.chanxian
            set gt.work_state='已完成',gt.fine_throwing=@rank,gt.stop_position=0,gt.stop_rank=workedcount,gt.finsh_time=NOW(),gt.banzu=guc.banzu
            where guc.gongyi='钢化' and gt.id=@id;
            
            insert into TemperingFinsh(machineid,glassid,Finshtime,stoprank,shelfrankid,processcard) 
            values (machineids,@id,NOW(),workedcount,@rank,@processcardid);    
        elseif flag=2 then
            update gmms_galss_task_2 set work_state='等待中',finsh_time=NOW() where id=@id;
        elseif flag=3 then
            update gmms_galss_task_2 set work_state='破损',finsh_time=NOW() where id=@id;
        end if;
        set workedcounted=(workedcount)+
        (select count(*) from gmms_galss_task_2 where groups=@work_id and work_state='破损' and processcard_id=@processcardid);
        
        select count(*) into @worksum from gmms_galss_task_2
        where groups=@work_id and processcard_id=@processcardid;
        if @worksum=workedcounted then
            update gmms_drop_frame_5 set sign=4 where id=@dropid;
        end if;
        call message(returnvalue,'0014',@date);
        set messagedate=@date;
        insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,@work_id,NOW(),'任务完成',@id,messagedate);
    end if;    
    
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for y_Shelf
-- ----------------------------
DROP PROCEDURE IF EXISTS `y_Shelf`;
delimiter ;;
CREATE PROCEDURE `y_Shelf`()
BEGIN
    DECLARE pro_id int DEFAULT 0;  
    DECLARE pro_id_outtime int DEFAULT 0;     #
    #半成品仓储   定时检索
    #1.检查 钢化后是否要补架子,
    #2.是否有需要理片的任务
    #3.是否有要去中空的任务
    #4.是否有要去旋转的任务
    select id into pro_id from y_pro_timer where pro_timer='Shelf' and is_enable='开启' and is_run='空闲' limit 0,1;
    select id into pro_id_outtime from y_pro_timer where  adddate(run_end_time, interval 90 second)<NOW() and is_enable='开启' and id=1 limit 0,1;
    if pro_id>0 or pro_id_outtime>0 then
        update y_pro_timer set is_run='运行中',run_begin_time=NOW() where id=1;
        call y_ShelfTempering(); #(钢化+旋转+理片+中空)退库任务,钢化补架+理片任务
        call y_Shelfcheck();     #移库任务
 
        call y_ShelfHollow(1);
        call y_ShelfHollow(2);
        call y_ShelfHollow(3);
        call y_ShelfHollow(4);
        call y_ShelfXz();
    
        call y_Shelfoptimize();
        update y_pro_timer set is_run='空闲',run_end_time=NOW() where id=1;
    end if;
    
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for y_ShelfAddHollow
-- ----------------------------
DROP PROCEDURE IF EXISTS `y_ShelfAddHollow`;
delimiter ;;
CREATE PROCEDURE `y_ShelfAddHollow`(in parentliuchengka_ varchar(255),in dropgroups BIGINT)
BEGIN
    #中空  仓储任务
    DECLARE isEnd DOUBLE DEFAULT 0;    #是否还有数据
    DECLARE liuchengka_ varchar(255) DEFAULT null;  #起始地
    DECLARE rank_ BIGINT DEFAULT 0;          #料架id
    DECLARE orientation_ varchar(255) DEFAULT null;  #面朝向
    
    DECLARE dropid_ int DEFAULT 0;      #启用/禁用
    DECLARE drop_type_ varchar(255) DEFAULT null;  #起始地
    DECLARE stop_rank_ varchar(255) DEFAULT null;  #起始地
    DECLARE beginaddress_ varchar(255) DEFAULT null;  #起始地
    DECLARE endgroups_ BIGINT DEFAULT 0;     #目的线路
    DECLARE getgroups_ BIGINT DEFAULT 0;     #目的线路
    DECLARE CountCar_ BIGINT DEFAULT 0;     #目的线路
    DECLARE CountA_ BIGINT DEFAULT 0;     #目的线路
    DECLARE CountB_ BIGINT DEFAULT 0;     #目的线路
    DECLARE Carxuanze_ BIGINT DEFAULT 0;     #选择车子
 
    DECLARE ShelfAddHollow_cursor CURSOR FOR SELECT liuchengka,sr.id,sr.orientation FROM gmms_liuchengka as lk 
    left join gmms_shelf_rack_2 as sr on lk.liuchengka=sr.processcard_id
    where sr.processcard_id is not null and parent_liuchengka=parentliuchengka_;
    
    DECLARE CONTINUE HANDLER FOR NOT FOUND SET isEnd = 1;
    if dropgroups=1 then
        set Carxuanze_=1;
    elseif dropgroups=2 or dropgroups=3 or dropgroups=4 then
        set Carxuanze_=2;
    end if;
    OPEN ShelfAddHollow_cursor;
    FETCH ShelfAddHollow_cursor INTO liuchengka_,rank_,orientation_;
    
        select getgroups,child_count into getgroups_,CountCar_ from gmms_liuchengka where liuchengka=parentliuchengka_ LIMIT 0,1;
        #中空方向架数
      select count(*) into CountA_ from gmms_drop_frame_5 as dr left join gmms_shelf_rack_2 as sr on dr.rank=sr.id
        left join gmms_liuchengka as lk on sr.processcard_id=lk.liuchengka
        where sr.id is not null and lk.liuchengka is not null and lk.parent_liuchengka=parentliuchengka_ and dr.stops>20;
        #钢化方向架数
        select count(*) into CountB_ from gmms_drop_frame_5 as dr left join gmms_shelf_rack_2 as sr on dr.rank=sr.id
        left join gmms_liuchengka as lk on sr.processcard_id=lk.liuchengka
        where sr.id is not null and lk.liuchengka is not null and lk.parent_liuchengka=parentliuchengka_ and dr.stops<21;
        while isEnd!=1 and Carxuanze_>0 and ((getgroups_=1 and CountB_=CountCar_  and CountB_>0) or(getgroups_!=1 and CountA_=CountCar_ and CountA_>0)) do
            #查找 和此流程卡使用面一样的  中空工位
            select stop_rank into beginaddress_ from gmms_drop_frame_5 where rank=rank_;
            select id,drop_type,stop_rank,all_groups into dropid_,drop_type_,stop_rank_,EndGroups_ from gmms_drop_frame_5 
            where groups_=4 and drop_groups=dropgroups and rank is null and sign=0 and orientation=orientation_ limit 0,1;
            if dropid_>0 then
                insert into gmms_shelf_tasks2(groups,tasktype,taskphase,taskstatus,starttime,beginaddress,endaddress,rackid,endgroups)
                select Carxuanze_,drop_type_,'出库','等待上车',NOW(),beginaddress_,stop_rank_,rank_,EndGroups_;
                update gmms_drop_frame_5 set sign=7 where id=dropid_;
                update gmms_drop_frame_5 as dr left join gmms_shelf_rack_2 as sr on dr.rank=sr.id
                set dr.sign=7 where sr.id is not null and sr.processcard_id=liuchengka_;
            end if;                        
            set isEnd=0;#防止into 影响
            set dropid_=0;
            set stop_rank_=null;
            set endgroups_=0;
            set beginaddress_=0;
            set rank_=0;
            set orientation_=null;
            FETCH ShelfAddHollow_cursor INTO liuchengka_,rank_,orientation_;
        end while;
    
    #关闭游标
    CLOSE ShelfAddHollow_cursor;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for y_Shelfcheck
-- ----------------------------
DROP PROCEDURE IF EXISTS `y_Shelfcheck`;
delimiter ;;
CREATE PROCEDURE `y_Shelfcheck`()
BEGIN
    #钢化任务   +  中空+理片+旋转退库任务
    DECLARE isEnd DOUBLE DEFAULT 0;    #是否还有数据
    DECLARE id_ int DEFAULT 0;      #启用/禁用
    DECLARE drop_type_ varchar(255) DEFAULT null;  #类型线路
    DECLARE stops_ varchar(255) DEFAULT null;  #在线库序号
    DECLARE stops2_ varchar(255) DEFAULT null;  #在线库序号2
    DECLARE stop_rank_ varchar(255) DEFAULT null;  #起始地
    DECLARE endgroups_ BIGINT DEFAULT 0;     #目的线路
    DECLARE rank_ BIGINT DEFAULT 0;          #料架id
    DECLARE sign_ BIGINT DEFAULT 0;          #料架id
    DECLARE rank2_ BIGINT DEFAULT 0;          #料架id2
    DECLARE orientation_ varchar(255) DEFAULT null;  #面朝向
    DECLARE processcardid_ varchar(255) DEFAULT null;  #流程卡
    DECLARE workstate_ varchar(255) DEFAULT null;  #工作状态
    DECLARE workprocedure_ varchar(255) DEFAULT null;  #工作阶段
    DECLARE parentliuchengkaws_ varchar(255) DEFAULT null;  #父级工作状态
    DECLARE parentliuchengkawp_ varchar(255) DEFAULT null;  #父级工作阶段
    DECLARE getgroups_ BIGINT DEFAULT 0;  #领取线路
    DECLARE parentliuchengka_ varchar(255) DEFAULT null;  #父级流程卡
    DECLARE back_mag_ varchar(255) DEFAULT null;  #是否优化成功
    #定义游标 
    DECLARE ShelfTempering_cursor CURSOR FOR 
    select dr.id,dr.drop_type,dr.stop_rank,dr.rank,dr.sign,dr.all_groups,dr.stops,sr.orientation,sr.processcard_id,
    lk.current_status,lk.current_work_position,lk2.getgroups,lk.parent_liuchengka,lk2.current_status,lk2.current_work_position from gmms_drop_frame_5 as dr 
    left join gmms_shelf_rack_2 as sr on dr.rank=sr.id 
    left join gmms_liuchengka as lk on sr.processcard_id=lk.liuchengka
    left join gmms_liuchengka as lk2 on lk.parent_liuchengka=lk2.liuchengka
    where dr.groups_=100 and dr.sign=0 and dr.flag=1;
    DECLARE CONTINUE HANDLER FOR NOT FOUND SET isEnd = 1;
    OPEN ShelfTempering_cursor;
 
    FETCH ShelfTempering_cursor 
    INTO id_,drop_type_,stop_rank_,rank_,sign_,EndGroups_,stops_,orientation_,processcardid_,workstate_,workprocedure_,getgroups_,parentliuchengka_,parentliuchengkaws_,parentliuchengkawp_;
        while isEnd!=1 do
            select sign into sign_ from gmms_drop_frame_5 where groups_=100 and stops=stops_;
            #判断此工位是否需要调度或者        
            if workprocedure_='理片' and workstate_='等待中' and sign_=0 then    
                if stops_<21 then
                    #从1-20 调度到 21-41  已优化的理片任务
                    select dr.stops,dr.rank into stops2_,rank2_ from gmms_drop_frame_5 as dr LEFT JOIN gmms_shelf_rack_2 as sr on dr.rank=sr.id
                    left join gmms_liuchengka as lk on sr.processcard_id=lk.liuchengka
                    left join gmms_liuchengka as lk2 on lk.parent_liuchengka=lk2.liuchengka
                    where dr.groups_=100 and dr.sign=0 and dr.flag=1 and dr.stops>20 and dr.rank is not null and sr.processcard_id is not null
                    and lk2.getgroups=1    limit 0,1;
                    #查找 中空方向的 空架子 替换
                    if stops2_=0 or stops2_ is null then
                        select dr.stops,dr.rank into stops2_,rank2_ from gmms_drop_frame_5 as dr LEFT JOIN gmms_shelf_rack_2 as sr on dr.rank=sr.id
                        left join gmms_liuchengka as lk on sr.processcard_id=lk.liuchengka
                        left join gmms_liuchengka as lk2 on lk.parent_liuchengka=lk2.liuchengka
                        where dr.groups_=100 and dr.sign=0 and dr.flag=1 and dr.stops>20 and dr.rank is not null and sr.processcard_id is null limit 0,1;
                    end if;
                    #查找 中空方向的 无领取+不需要理片的 替换
                    if stops2_=0 or stops2_ is null then
                        select dr.stops,dr.rank into stops2_,rank2_ from gmms_drop_frame_5 as dr LEFT JOIN gmms_shelf_rack_2 as sr on dr.rank=sr.id
                        left join gmms_liuchengka as lk on sr.processcard_id=lk.liuchengka
                        left join gmms_liuchengka as lk2 on lk.parent_liuchengka=lk2.liuchengka
                        where dr.groups_=100 and dr.sign=0 and dr.flag=1 and dr.stops>20 and dr.rank is not null and sr.processcard_id is not null
                        and lk2.getgroups is null and !(lk.current_work_position='理片' and lk.current_status='等待中') order by dr.id asc limit 0,1;
                    end if;
                    if stops2_>0 and (select count(*) from gmms_shelf_tasks2 where (rackid=rank_ or rackid=rank2_) and isrepeal='正常' and taskstatus!='已完成')=0 then
                        insert into gmms_shelf_tasks2(groups,tasktype,taskphase,taskstatus,starttime,beginaddress,endaddress,rackid,endgroups)
                        select 3,drop_type_,'移库','等待上车',NOW(),stops_,stops2_,rank_,150;
                        insert into gmms_shelf_tasks2(groups,tasktype,taskphase,taskstatus,starttime,beginaddress,endaddress,rackid,endgroups)
                        select 3,drop_type_,'移库','等待上车',NOW(),stops2_,stops_,rank2_,150;
                        update gmms_drop_frame_5 as dr INNER join gmms_drop_frame_5 as dr1 
                        set dr.sign=7,dr1.sign=7 where dr.stops=stops2_ and dr.groups_=100 and dr1.id=id_;
                    end if;
                end if;
            elseif parentliuchengkawp_='中空' and parentliuchengkaws_='等待中' and getgroups_>0 and sign_=0 then
                if getgroups_=1 and stops_>20 then
                    #从21-41 调度到 1-20   已领取的中空任务
                    #找钢化方向  已领取 线路不等于1的
                    select dr.stops,dr.rank into stops2_,rank2_ from gmms_drop_frame_5 as dr LEFT JOIN gmms_shelf_rack_2 as sr on dr.rank=sr.id
                    left join gmms_liuchengka as lk on sr.processcard_id=lk.liuchengka
                    left join gmms_liuchengka as lk2 on lk.parent_liuchengka=lk2.liuchengka
                    where dr.groups_=100 and dr.sign=0 and dr.flag=1 and dr.stops<21 and dr.rank is not null and sr.processcard_id is not null
                  and lk2.getgroups>1 and lk2.getgroups is not null    limit 0,1;
                    #找钢化方向 有流程卡的
                    if stops2_=0 or stops2_ is null then
                        select dr.stops,dr.rank into stops2_,rank2_ from gmms_drop_frame_5 as dr LEFT JOIN gmms_shelf_rack_2 as sr on dr.rank=sr.id
                        left join gmms_liuchengka as lk on sr.processcard_id=lk.liuchengka
                        left join gmms_liuchengka as lk2 on lk.parent_liuchengka=lk2.liuchengka
                        where dr.groups_=100 and dr.sign=0 and dr.flag=1 and dr.stops<21 and dr.rank is not null and sr.processcard_id is not null and (lk2.getgroups is null or lk2.getgroups!=1)    limit 0,1;
                    end if;
                    #找钢化方向 有架子的    
                    if stops2_=0 or stops2_ is null then
                        select dr.stops,dr.rank into stops2_,rank2_ from gmms_drop_frame_5 as dr LEFT JOIN gmms_shelf_rack_2 as sr on dr.rank=sr.id
                        left join gmms_liuchengka as lk on sr.processcard_id=lk.liuchengka
                        left join gmms_liuchengka as lk2 on lk.parent_liuchengka=lk2.liuchengka
                        where dr.groups_=100 and dr.sign=0 and dr.flag=1 and dr.stops<21 and dr.rank is not null and (lk2.getgroups is null or lk2.getgroups!=1) limit 0,1;
                    end if;
                    if stops2_>0 and (select count(*) from gmms_shelf_tasks2 where (rackid=rank_ or rackid=rank2_) and isrepeal='正常' and taskstatus!='已完成')=0 then
                        insert into gmms_shelf_tasks2(groups,tasktype,taskphase,taskstatus,starttime,beginaddress,endaddress,rackid,endgroups)
                        select 3,drop_type_,'移库','等待上车',NOW(),stops_,stops2_,rank_,200;
                        insert into gmms_shelf_tasks2(groups,tasktype,taskphase,taskstatus,starttime,beginaddress,endaddress,rackid,endgroups)
                        select 3,drop_type_,'移库','等待上车',NOW(),stops2_,stops_,rank2_,200;
                        update gmms_drop_frame_5 as dr INNER join gmms_drop_frame_5 as dr1 
                        set dr.sign=7,dr1.sign=7 where dr.stops=stops2_ and dr.groups_=100 and dr1.id=id_;
                    end if;
                elseif (getgroups_=2 or getgroups_=3 or getgroups_=4) and stops_<21 and sign_=0 then
                    #从1-20 调度到 21-41   已领取的中空任务
                    #查找 中空方向的 已领的 1号中空线架子 替换
                    select dr.stops,dr.rank into stops2_,rank2_ from gmms_drop_frame_5 as dr LEFT JOIN gmms_shelf_rack_2 as sr on dr.rank=sr.id
                    left join gmms_liuchengka as lk on sr.processcard_id=lk.liuchengka
                    left join gmms_liuchengka as lk2 on lk.parent_liuchengka=lk2.liuchengka
                    where dr.groups_=100 and dr.sign=0 and dr.flag=1 and dr.stops>20 and dr.rank is not null and sr.processcard_id is not null
                    and lk2.getgroups=1    limit 0,1;
                    #查找 中空方向的 空架子 替换
                    if stops2_=0 or stops2_ is null then
                        select dr.stops,dr.rank into stops2_,rank2_ from gmms_drop_frame_5 as dr LEFT JOIN gmms_shelf_rack_2 as sr on dr.rank=sr.id
                        left join gmms_liuchengka as lk on sr.processcard_id=lk.liuchengka
                        left join gmms_liuchengka as lk2 on lk.parent_liuchengka=lk2.liuchengka
                        where dr.groups_=100 and dr.sign=0 and dr.flag=1 and dr.stops>20 and dr.rank is not null and sr.processcard_id is null limit 0,1;
                    end if;
                    #查找 中空方向的 无领取+不需要理片的 替换
                    if stops2_=0 or stops2_ is null then
                        select dr.stops,dr.rank into stops2_,rank2_ from gmms_drop_frame_5 as dr LEFT JOIN gmms_shelf_rack_2 as sr on dr.rank=sr.id
                        left join gmms_liuchengka as lk on sr.processcard_id=lk.liuchengka
                        left join gmms_liuchengka as lk2 on lk.parent_liuchengka=lk2.liuchengka
                        where dr.groups_=100 and dr.sign=0 and dr.flag=1 and dr.stops>20 and dr.rank is not null and sr.processcard_id is not null
                        and lk2.getgroups is null and !(lk.current_work_position='理片' and lk.current_status='等待中') order by dr.id asc limit 0,1;
                    end if;
                    select stops2_;
                    if stops2_>0 and (select count(*) from gmms_shelf_tasks2 where (rackid=rank_ or rackid=rank2_) and isrepeal='正常' and taskstatus!='已完成')=0 then
                        insert into gmms_shelf_tasks2(groups,tasktype,taskphase,taskstatus,starttime,beginaddress,endaddress,rackid,endgroups)
                        select 3,drop_type_,'移库','等待上车',NOW(),stops_,stops2_,rank_,200;
                        insert into gmms_shelf_tasks2(groups,tasktype,taskphase,taskstatus,starttime,beginaddress,endaddress,rackid,endgroups)
                        select 3,drop_type_,'移库','等待上车',NOW(),stops2_,stops_,rank2_,200;
                        update gmms_drop_frame_5 as dr INNER join gmms_drop_frame_5 as dr1 
                        set dr.sign=7,dr1.sign=7 where dr.stops=stops2_ and dr.groups_=100 and dr1.id=id_;
                    end if;
                end if;
            elseif processcardid_ is null and rank_>0 and stops_>20 and sign_=0  then
                #21-41 空架 调度到  1-20                        
                select dr.stops,dr.rank into stops2_,rank2_ from gmms_drop_frame_5 as dr 
                LEFT JOIN gmms_shelf_rack_2 as sr on dr.rank=sr.id            
                left join gmms_liuchengka as lk on sr.processcard_id=lk.liuchengka
                left join gmms_liuchengka as lk2 on lk.parent_liuchengka=lk2.liuchengka
                where dr.groups_=100 and dr.sign=0 and dr.flag=1 and dr.stops<21 and dr.rank is not null and sr.processcard_id is not null
            and lk.liuchengka is not null and lk2.liuchengka is not null and lk2.current_work_position!='中空' limit 0,1;                
                if stops2_>0 and (select count(*) from gmms_shelf_tasks2 where (rackid=rank_ or rackid=rank2_) and isrepeal='正常' and taskstatus!='已完成')=0 then
                    insert into gmms_shelf_tasks2(groups,tasktype,taskphase,taskstatus,starttime,beginaddress,endaddress,rackid,endgroups)
                    select 3,drop_type_,'移库','等待上车',NOW(),stops_,stops2_,rank_,EndGroups_;
                    insert into gmms_shelf_tasks2(groups,tasktype,taskphase,taskstatus,starttime,beginaddress,endaddress,rackid,endgroups)
                    select 3,drop_type_,'移库','等待上车',NOW(),stops2_,stops_,rank2_,EndGroups_;
                    update gmms_drop_frame_5 as dr INNER join gmms_drop_frame_5 as dr1 
                    set dr.sign=7,dr1.sign=7 where dr.stops=stops2_ and dr.groups_=100 and dr1.id=id_;
                end if;
            end if;
            set isEnd=0;#防止into 影响
            set stops_=0;
            set stops2_=0;
            set rank2_=0;
            set stop_rank_=null;
            set endgroups_=0;
            set rank_=0;
            set orientation_=null;
            set drop_type_=null;
            set processcardid_=null;
            set parentliuchengka_=null;
            set workstate_=null;
            set workprocedure_=null;
            set getgroups_=0;
            FETCH ShelfTempering_cursor INTO id_,drop_type_,stop_rank_,rank_,sign_,EndGroups_,stops_,orientation_,processcardid_,workstate_,workprocedure_,getgroups_,parentliuchengka_,parentliuchengkaws_,parentliuchengkawp_;
        end while;
    
    #关闭游标
    CLOSE ShelfTempering_cursor;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for y_ShelfFinsh
-- ----------------------------
DROP PROCEDURE IF EXISTS `y_ShelfFinsh`;
delimiter ;;
CREATE PROCEDURE `y_ShelfFinsh`(in machineids BIGINT,in flag int,in returnvalue varchar(255),out messagedate varchar(255))
BEGIN
    #仓储完成
    DECLARE parentliuchengka_ varchar(255) DEFAULT null;    #父级流程卡
    DECLARE liuchengka_ varchar(255) DEFAULT null;    #子流程卡
    DECLARE Taskid_ bigint DEFAULT 0;    #车上架子任务id
    DECLARE Taskphase_ varchar(255) DEFAULT null;    #任务进/出/移库
    DECLARE Taskstatus_ varchar(255) DEFAULT null;    #任务状态
    DECLARE Tasktype_ varchar(255) DEFAULT null;    #任务类型
    DECLARE Beginaddress_ varchar(255) DEFAULT null;    #起始地
    DECLARE Endaddress_ varchar(255) DEFAULT null;    #目的地
    DECLARE orientation_ varchar(255) DEFAULT null;    #朝向
    DECLARE rackid_ bigint DEFAULT 0;    #车上架子任务id
    DECLARE zknotFinsh bigint DEFAULT 0;    #中空未完成数量
    DECLARE groups_ BIGINT DEFAULT  
    (select work_id from gmms_machine where id=machineids);  #线路
    DECLARE isWorking bigint DEFAULT 
    (select count(id) from gmms_shelf_tasks2 where groups=groups_ and (taskstatus='正在上车' or taskstatus='正在下车') and isrepeal='正常');   #是否正在工作
 
    if isWorking=1 then
        #有正在工作的任务
        select id,taskphase,taskstatus,tasktype,rackid,beginaddress,endaddress 
        into Taskid_,Taskphase_,Taskstatus_,Tasktype_,rackid_,Beginaddress_,Endaddress_ from gmms_shelf_tasks2 
        where groups=groups_ and (taskstatus='正在上车' or taskstatus='正在下车') and isrepeal='正常';    
                        
        if flag=1 or flag=3 then
            if Taskstatus_='正在上车' then
                if Tasktype_='中空' and Taskphase_='入库' then
                    update gmms_shelf_tasks2 set taskstatus='已上车',updatetime=NOW(),finshtype1=flag where id=Taskid_;
                    update gmms_drop_frame_5 set rank=null,sign=0 where stop_rank=Beginaddress_ and rank is not null order by stops desc LIMIT 1;
                elseif Tasktype_='旋转' and Taskphase_='入库' then
                    if Beginaddress_='99' then
                        update gmms_shelf_tasks2 set taskstatus='已上车',updatetime=NOW(),finshtype1=flag where id=Taskid_;
                        update gmms_drop_frame_5 set rank=null,sign=0 where stop_rank=98;
                    elseif Beginaddress_='98' then
                        update gmms_shelf_tasks2 set taskstatus='已上车',updatetime=NOW(),finshtype1=flag where id=Taskid_;
                        update gmms_drop_frame_5 set rank=null,sign=0 where stop_rank=99;
                    end if;                    
                else
                    update gmms_shelf_tasks2 set taskstatus='已上车',updatetime=NOW(),finshtype1=flag where id=Taskid_;
                    update gmms_drop_frame_5 set rank=null,sign=0 where stop_rank=Beginaddress_;
                end if;            
            elseif Taskstatus_='正在下车' then                
                if Taskphase_='入库' then
                    if Tasktype_='钢化' then
                        select parent_liuchengka,liuchengka into parentliuchengka_,liuchengka_ from gmms_liuchengka 
                        where liuchengka=(select processcard_id from gmms_shelf_rack_2 where id=rackid_ limit 0,1);
                        insert into gmms_galss_task_shelf 
                        (id,rank,type_id,galss_id,pattern_id,width,height,thickness,color,edg_width,edg_height,chamfer_size,
                        galss_type,edg_speed1,edg_speed2,fine_throwing,work_state,work_procedure,slicecage_rank,drop_frame,
                        slicecage_flag,out_rank,start_time,finsh_time,stop_position,processcard_id,engineering_id,broken_state,
                        stop_rank,work_procedure_number,gc_number,gc_width,gc_height,gc_stockid,marking_flag) 
                        select gt.id,gt.rank,gt.type_id,gt.galss_id,gt.pattern_id,gt.width,gt.height,gt.thickness,gt.color,gt.edg_width,gt.edg_height,
                        gt.chamfer_size,gt.galss_type,gt.edg_speed1,gt.edg_speed2,gt.fine_throwing,gt.work_state,gt.work_procedure,gt.slicecage_rank,
                        gt.drop_frame,gt.slicecage_flag,gt.out_rank,gt.start_time,gt.finsh_time,0,gt.processcard_id,gt.engineering_id,
                        gt.broken_state,gt.stop_rank,gt.work_procedure_number,parentliuchengka_,gt.gc_width,gt.gc_height,gt.gc_stockid,gt.marking_flag 
                        from gmms_galss_task_2 as gt left join gmms_galss_task_shelf as gs on gt.id=gs.id
                        where gt.processcard_id=liuchengka_ and gt.work_state='已完成' and gt.work_procedure='钢化后下片' and gs.id is null;
                        #钢化后的报工
                        INSERT INTO e_record_tempering(processcard_id, glass_id, width, height, thinkess, color, sequence, create_time, line, team_name, type_num, is_report,rank,furnace) 
                        select gt.processcard_id,gt.id,gt.edg_width,gt.edg_height,gt.thickness,gt.color,gt.stop_rank,gt.finsh_time,gt.groups,gt.banzu,gt.edg_speed2,1,gt.fine_throwing,gt.furnace from gmms_galss_task_2 as gt 
                        left join e_record_tempering as et on gt.id=et.glass_id 
                        where et.glass_id is null and gt.processcard_id=liuchengka_ and gt.work_state='已完成' and gt.work_procedure='钢化后下片';
                        
--                         delete gt from gmms_galss_task_2 as gt 
--                         left join e_record_tempering as et on gt.id=et.glass_id 
--                         where et.glass_id is not null and gt.processcard_id=liuchengka_;
                        delete from gmms_galss_task_2 where processcard_id=liuchengka_;
                        #钢化后的破损
--                         INSERT INTO e_pierceds(processcard_id, type_num, pieces, pierced_type, pierced_cause, is_report, glass_id, create_time, process, line, gc_number, cs_number, team_name) 
--                         select gs.processcard_id,gs.edg_speed2,1,'刺破类型','刺破原因',1,gs.id,NOW(),'钢化',gs.groups,gs.engineering_id,0,gs.banzu from gmms_galss_task_2 as gs left join E_Pierceds as ep on gs.id=ep.glass_id
--                         where ep.glass_id is null and gs.processcard_id=liuchengka_ and gs.work_state='破损';
                        
                        update gmms_drop_frame_5 set rank=rackid_,sign=0,rankposition=Beginaddress_ where stop_rank=Endaddress_ limit 1;
                        update gmms_liuchengka set isgang='已钢化' where liuchengka=liuchengka_;
                    elseif Tasktype_='旋转' then                        
                        select orientation into orientation_ from gmms_shelf_rack_2 
                        where id=rackid_ limit 0,1;
                        if orientation_='A' then
                            update gmms_shelf_rack_2 set orientation='B' where id=rackid_;
                        elseif orientation_='B' then
                            update gmms_shelf_rack_2 set orientation='A' where id=rackid_;
                        end if;    
                        update gmms_drop_frame_5 set rank=rackid_,sign=0,rankposition=Beginaddress_ where stop_rank=Endaddress_ limit 1;
                    elseif Tasktype_='理片' then
                        select liuchengka into liuchengka_ from gmms_liuchengka 
                        where liuchengka=(select processcard_id from gmms_shelf_rack_2 where id=rackid_ limit 0,1);
                        update gmms_liuchengka set ischu=null where liuchengka=liuchengka_;
                        update gmms_drop_frame_5 set rank=rackid_,sign=0,rankposition=Beginaddress_ where stop_rank=Endaddress_ order by stops asc limit 1;
                        
                    elseif Tasktype_='中空' then
                        #保存数据  然后删除库存表  zknotFinsh
                        select liuchengka into liuchengka_ from gmms_liuchengka 
                        where liuchengka=(select processcard_id from gmms_shelf_rack_2 where id=rackid_ limit 0,1);
                        
                        set zknotFinsh=(select count(*) from gmms_galss_task_shelf where processcard_id=liuchengka_ and !(work_state='已完成' and work_procedure='中空上片'));
                        if zknotFinsh=0 then
                            insert into gmms_galss_task_shelf_log  
                            select gt.* from gmms_galss_task_shelf as gt left join gmms_galss_task_shelf_log as gs on gt.id=gs.id
                            where gt.processcard_id=liuchengka_  and gs.id is null and 
                            (select count(*) from gmms_galss_task_shelf where processcard_id=gt.processcard_id and !(work_state='已完成' and work_procedure='中空上片'))=0;
                            delete from gmms_galss_task_shelf where processcard_id=liuchengka_;
                        end if;
                        update gmms_galss_task_shelf set stop_position=0 where processcard_id=liuchengka_;
                        
                        update gmms_drop_frame_5 set rank=rackid_,sign=0,rankposition=Beginaddress_ where stop_rank=Endaddress_ order by stops asc limit 1;
                    else    
                        update gmms_drop_frame_5 set rank=rackid_,sign=0,rankposition=Beginaddress_ where stop_rank=Endaddress_ order by stops asc limit 1;
                    end if;                    
                elseif Taskphase_='出库' then
                    if Tasktype_='旋转' then
                        update gmms_drop_frame_5 set rank=rackid_,sign=3,rankposition=Beginaddress_ where stop_rank=Endaddress_ limit 1;
                    elseif Tasktype_='中空' then
                        update gmms_drop_frame_5 set rank=rackid_,sign=1,rankposition=Beginaddress_ where stop_rank=Endaddress_ and (sign=7 or sign=0)  limit 1;
                    else
                        update gmms_drop_frame_5 set rank=rackid_,sign=1,rankposition=Beginaddress_ where stop_rank=Endaddress_  limit 1;
                    end if;
                elseif Taskphase_='移库' then
                    update gmms_drop_frame_5 set rank=rackid_,sign=0,rankposition=Beginaddress_ where stop_rank=Endaddress_ limit 1;
                end if;
                update gmms_shelf_tasks2 set taskstatus='已完成',endtime=NOW(),finshtype2=flag where id=Taskid_;            
            end if;
            #call message(returnvalue,'0014',messagedate);
        elseif flag=2 then
            if Taskstatus_='正在上车' then
                update gmms_shelf_tasks2 set taskstatus='等待上车',cardlocation=null where id=Taskid_;
            elseif Taskstatus_='正在下车' then
                update gmms_shelf_tasks2 set taskstatus='已上车' where id=Taskid_;
            end if;
            #call message(returnvalue,'0014',messagedate);
        end if;
    end if;
    call message(returnvalue,'0014',messagedate);
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for y_ShelfHollow
-- ----------------------------
DROP PROCEDURE IF EXISTS `y_ShelfHollow`;
delimiter ;;
CREATE PROCEDURE `y_ShelfHollow`(in groupss_ BIGINT)
BEGIN
    #中空任务   是否能生成仓储任务
    DECLARE isEnd DOUBLE DEFAULT 0;    #是否还有数据
    DECLARE CountA_S int DEFAULT 0;      #启用/禁用
    DECLARE CountB_S int DEFAULT 0;      #启用/禁用
    DECLARE CountA_D int DEFAULT 0;      #启用/禁用
    DECLARE CountB_D int DEFAULT 0;      #启用/禁用
    
    DECLARE parentliuchengka_ varchar(255) DEFAULT null;  #面朝向
    
    DECLARE id_ int DEFAULT 0;      #启用/禁用
    DECLARE drop_type_ varchar(255) DEFAULT null;  #类型线路
    DECLARE stop_rank_ varchar(255) DEFAULT null;  #目的地
    DECLARE beginaddress_ varchar(255) DEFAULT null;  #起始地
    DECLARE endgroups_ BIGINT DEFAULT 0;     #目的线路
    DECLARE rank_ BIGINT DEFAULT 0;          #料架id
    DECLARE orientation_ varchar(255) DEFAULT null;  #面朝向
    DECLARE endstop_rank_ varchar(255) DEFAULT null;  #面朝向
    
 
    DECLARE childcount_ BIGINT DEFAULT 0;          #料架id
    #得到合片流程卡
    select ypl.zkliuchengka,lk.child_count into parentliuchengka_,childcount_ from y_parent_liuchengka as ypl 
    left join gmms_liuchengka as lk on ypl.zkliuchengka=lk.liuchengka
    where lk.liuchengka is not null and lk.current_work_position='中空' and lk.current_status='等待中' and 
    lk.getgroups=groupss_ order by lk.getdatatime asc limit 0,1;
    #得到合片流程卡   A/B面   架子数量
    select count(*) into CountA_S from gmms_drop_frame_5 as dr left join gmms_shelf_rack_2 as sr on dr.rank=sr.id
    left join gmms_liuchengka as lk on sr.processcard_id=lk.liuchengka
    where sr.id is not null and lk.liuchengka is not null and lk.parent_liuchengka=parentliuchengka_ and sr.orientation='A' and dr.sign=0;
    
    select count(*) into CountB_S from gmms_drop_frame_5 as dr left join gmms_shelf_rack_2 as sr on dr.rank=sr.id
    left join gmms_liuchengka as lk on sr.processcard_id=lk.liuchengka
    where sr.id is not null and lk.liuchengka is not null and lk.parent_liuchengka=parentliuchengka_ and sr.orientation='B' and dr.sign=0;
    #得到工位    A/B面   架子数量
    select count(stop_rank) into CountA_D from gmms_drop_frame_5 
    where groups_=4 and drop_groups=groupss_ and rank is null and sign=0 and flag=1 and orientation='A';
    select count(stop_rank) into CountB_D from gmms_drop_frame_5 
    where groups_=4 and drop_groups=groupss_ and rank is null and sign=0 and flag=1 and orientation='B';
    select CountA_D,CountB_D,CountA_S,CountB_S;
    #找到此合片流程卡 是否属于同一面
    if childcount_=2 and (CountA_S+CountB_S)=childcount_ then
        #两架合片
        if CountA_S=2 and CountA_D=2 then
            #两架都是A  且工位都是A
            call y_ShelfAddHollow(parentliuchengka_,groupss_);
        elseif CountB_S=2 and CountB_D=2 then
            #两架都是B  且工位都是B
            call y_ShelfAddHollow(parentliuchengka_,groupss_);
        elseif ( (CountB_D=2 and CountA_D<2 and CountA_S=2) or (CountA_D=2 and CountB_D<2 and CountB_S=2) ) and
            (select count(*) from gmms_drop_frame_5 where groups_=2 and sign=0)=2 and
            (select mode_type from y_mode_type where groups=groupss_ and number='ZKXZ0001')='自动' then
            #中空 1. B工位空闲2   A工位空闲<2  任务A面数2   2. A工位空闲2   B工位空闲<2  任务B面数2
            #找到此父级流程卡 中的一个架子去旋转
            select sr.id,dr.stop_rank into rank_,beginaddress_ from gmms_drop_frame_5 as dr 
            left join gmms_shelf_rack_2 as sr on dr.rank=sr.id
            left join gmms_liuchengka as lk on sr.processcard_id=lk.liuchengka
            where sr.id is not null and lk.liuchengka is not null 
            and lk.parent_liuchengka=parentliuchengka_ and dr.groups_=100 and dr.sign=0 limit 0,1;
        
            #空闲的旋转位
            select id,drop_type,stop_rank,all_groups 
            into id_,drop_type_,stop_rank_,EndGroups_ FROM gmms_drop_frame_5 
            where groups_=2 and rank is null and sign=0 and flag=1 limit 0,1;
            insert into gmms_shelf_tasks2(groups,tasktype,taskphase,taskstatus,starttime,beginaddress,endaddress,rackid,endgroups)
            select 3,drop_type_,'出库','等待上车',NOW(),beginaddress_,stop_rank_,rank_,300;
            
            update gmms_drop_frame_5 set sign=7 where id=id_ or rank=rank_;
        end if;
    elseif childcount_=3 and (CountA_S+CountB_S)=childcount_ then
        if ((CountA_S=2 and CountB_S=1) or (CountA_S=1 and CountB_S=2)) and CountA_D=2 and CountB_D=2 then 
            call y_ShelfAddHollow(parentliuchengka_,groupss_);
        end if;        
    elseif childcount_=4 and CountA_D=2 and CountB_D=2 then 
        #四架合片
        call y_ShelfAddHollow(parentliuchengka_,groupss_);
    end if;
    
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for y_Shelfoptimize
-- ----------------------------
DROP PROCEDURE IF EXISTS `y_Shelfoptimize`;
delimiter ;;
CREATE PROCEDURE `y_Shelfoptimize`()
BEGIN
    #仓储自动优化
    DECLARE isEnd DOUBLE DEFAULT 0;    #是否还有数据
    DECLARE Count_DZ DOUBLE DEFAULT 0;    #查找此父级流程卡在库内的数量
    DECLARE Count_S DOUBLE DEFAULT 0;    #查找此父级流程卡在库内的数量 
    DECLARE parentliuchengkaCount int DEFAULT 0;      #此父级流程卡下 的子流程卡数量
    DECLARE zkliuchengka_ varchar(255) DEFAULT null;  #父级流程卡
    DECLARE isMatchCount_ varchar(255) DEFAULT null;  #是否有未优化的
    DECLARE isWorkingCount_ varchar(255) DEFAULT 0;  #是否有正在工作的
    #定义游标
    DECLARE emp_cursor CURSOR FOR SELECT zkliuchengka FROM y_parent_liuchengka;
    DECLARE CONTINUE HANDLER FOR NOT FOUND SET isEnd = 1;
    #打开游标
    OPEN emp_cursor;
    #使用游标(从游标中获取数据)
    FETCH emp_cursor INTO zkliuchengka_;
        while isEnd!=1 do
            set isMatchCount_=0;
            set parentliuchengkaCount=0;
            set Count_S=0;
            set Count_DZ=0;
            #查找此父级流程卡在库内的数量    
--             select count(*) into Count_S from gmms_drop_frame_5 as dr left join gmms_shelf_rack_2 as sr on dr.rank=sr.id
--             left join gmms_liuchengka as lk on sr.processcard_id=lk.liuchengka
--             where sr.id is not null and lk.liuchengka is not null and lk.parent_liuchengka=zkliuchengka_ and dr.groups_=100 and 
--             lk.current_status='已完成' and lk.current_work_position='创建';
            
            select count(*) into Count_S from gmms_drop_frame_5 as dr left join gmms_shelf_rack_2 as sr on dr.rank=sr.id
            left join gmms_liuchengka as lk on sr.processcard_id=lk.liuchengka
            where sr.id is not null and lk.liuchengka is not null and lk.parent_liuchengka=zkliuchengka_ and dr.groups_=100 and dr.sign=0;
            
            select count(*) into Count_DZ from gmms_drop_frame_5 as dr left join gmms_shelf_rack_2 as sr on dr.rank=sr.id
            left join gmms_liuchengka as lk on sr.processcard_id=lk.liuchengka
            where sr.id is not null and lk.liuchengka is not null and lk.parent_liuchengka=zkliuchengka_ and dr.groups_=5;
            #此父级流程卡下 的子流程卡数量
            select child_count into parentliuchengkaCount from gmms_liuchengka where liuchengka=zkliuchengka_;
            
            select count(*) into isMatchCount_ from gmms_galss_task_shelf 
            where gc_number=zkliuchengka_ and ((work_state='已完成' and work_procedure='钢化后下片' and stop_position<1) or (stop_position>0 and work_state='破损'));
            
            select count(*) into isWorkingCount_ from gmms_galss_task_shelf 
            where gc_number=zkliuchengka_ and work_state='正在工作';
            
            if Count_S=parentliuchengkaCount and parentliuchengkaCount>0 and isMatchCount_>0 and Count_DZ=0 and isWorkingCount_=0 then
                insert into A_youhua(processcard_id,count,youhuashijian) values (zkliuchengka_,isMatchCount_,NOW());
                call y_optimize_GAI(zkliuchengka_,1,@h,@l);
            end if;        
            set zkliuchengka_=null;
            set isEnd=0;#防止into 影响        
            FETCH emp_cursor INTO zkliuchengka_;            
        end while;
    
    #关闭游标
    CLOSE emp_cursor;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for y_ShelfSend
-- ----------------------------
DROP PROCEDURE IF EXISTS `y_ShelfSend`;
delimiter ;;
CREATE PROCEDURE `y_ShelfSend`(in machineids BIGINT,in returnvalue varchar(255),out messagedate varchar(255))
BEGIN
    #仓储发送
    DECLARE isEnd DOUBLE DEFAULT 0;    #是否还有数据
    DECLARE Carid_ bigint DEFAULT 0;    #车上架子任务id
    DECLARE CarEndgroups_ bigint DEFAULT 0;    #车上架子目的地线路
    DECLARE CarCount bigint DEFAULT 0;    #车上有几个架子
    DECLARE PastCardlocation bigint DEFAULT 0;    #车上架子在什么位置
    DECLARE PastBeginaddress_ varchar(255) DEFAULT null;    #车上架子目的地
    DECLARE PastEndaddress_ varchar(255) DEFAULT null;    #车上架子目的地
    DECLARE Pastisout_ bigint DEFAULT 0;    #车上架子目的地
    DECLARE Taskid_ bigint DEFAULT 0;  #任务id
    DECLARE Taskphases_ varchar(255) DEFAULT null;  #任务阶段
    DECLARE Taskstatus_ varchar(255) DEFAULT null;  #任务类型
    DECLARE Rackid_ int DEFAULT 0;  #料架id
    DECLARE Beginaddress_ varchar(255) DEFAULT null;  #起始地
    DECLARE Endaddress_ varchar(255) DEFAULT null;    #目的地
    DECLARE Endgroups_ varchar(255) DEFAULT null; #目的线路
    DECLARE Cardlocation_ bigint DEFAULT 0;     #小车位置
    DECLARE groups_ BIGINT DEFAULT  
    (select work_id from gmms_machine where id=machineids);  #线路
    DECLARE isWorking bigint DEFAULT 
    (select count(id) from gmms_shelf_tasks2 where groups=groups_ and (taskstatus='正在上车' or taskstatus='正在下车') and isrepeal='正常');   #是否正在工作
    DECLARE ShelfSend_cursor CURSOR FOR
    select id,taskphase,taskstatus,rackid,beginaddress,endgroups,endaddress FROM gmms_shelf_tasks2 
    where groups=groups_ and taskstatus='等待上车' and isrepeal='正常' order by endgroups desc, id asc;
    DECLARE CONTINUE HANDLER FOR NOT FOUND SET isEnd = 1;
    #打开游标
    OPEN ShelfSend_cursor;
    set CarCount=(select count(id) from gmms_shelf_tasks2 where groups=groups_ and taskstatus='已上车' and isrepeal='正常');
    select id,endgroups,cardlocation,beginaddress,endaddress,isout 
    into Carid_,CarEndgroups_,PastCardlocation,PastBeginaddress_,PastEndaddress_,Pastisout_ from gmms_shelf_tasks2 
    where groups=groups_ and taskstatus='已上车' and isrepeal='正常' limit 0,1;
    #使用游标(从游标中获取数据)
    set isEnd=0;
    FETCH ShelfSend_cursor INTO Taskid_,Taskphases_,Taskstatus_,Rackid_,Beginaddress_,Endgroups_,Endaddress_;                    
      if (CarCount=0 or CarCount=1) and Pastisout_=0 then
            #车上没有任务    
            while isEnd!=1 and isWorking=0 do
                if (Taskid_=(select id from gmms_shelf_tasks2 
                                        where groups=groups_ and endgroups=Endgroups_ and taskstatus='等待上车' and isrepeal='正常' limit 0,1) and CarEndgroups_=0) or
                     Taskid_=(select id from gmms_shelf_tasks2 
                                        where groups=groups_ and endgroups=CarEndgroups_ and taskstatus='等待上车' and isrepeal='正常' limit 0,1)
                then
                    
                    call intTo2ByteHex10_16_4(Beginaddress_,@target);
                    #返回值+00000000+目标地+AB车+上下
                    if groups_=1 then
                        #钢化车 17/18/19/20/122工位 只能使用1拉
                        if PastCardlocation=1 and 
                            Beginaddress_!='17' and Beginaddress_!='18' and Beginaddress_!='19' and Beginaddress_!='20' and Beginaddress_!='122' and 
                            Endaddress_!='17' and Endaddress_!='18' and Endaddress_!='19' and Endaddress_!='20' and Endaddress_!='122'    then
                            set Cardlocation_=2;
                            set messagedate=CONCAT(returnvalue,"00000000",@target,'0002','0001');
                        elseif PastCardlocation!=1 then 
                            set Cardlocation_=1;
                            set messagedate=CONCAT(returnvalue,"00000000",@target,'0001','0001');
                        end if;
                    elseif groups_=2 then
                        #中空车 21/22/23/131工位 只能使用2拉
    
                        if PastCardlocation!=2 then
                            set Cardlocation_=2;
                            set messagedate=CONCAT(returnvalue,"00000000",@target,'0002','0001');
                        elseif Beginaddress_!='21' and Beginaddress_!='22' and Beginaddress_!='23' and Beginaddress_!='131' and 
                                     Endaddress_!='21' and Endaddress_!='22' and Endaddress_!='23' and Endaddress_!='131' then
                            set Cardlocation_=1;
                            set messagedate=CONCAT(returnvalue,"00000000",@target,'0001','0001');
                        end if;
                    elseif ((select state from gmms_machine where id=55)='允许' or (Endaddress_!=99 and Endaddress_!=98)) and groups_=3 then
                        if PastCardlocation=1 then
                            set Cardlocation_=2;
                            set messagedate=CONCAT(returnvalue,"00000000",@target,'0002','0001');
                        else
                            set Cardlocation_=1;
                            set messagedate=CONCAT(returnvalue,"00000000",@target,'0001','0001');
                        end if;
                    end if;    
                    #select * from gmms_drop_frame_5 where stop_rank=Endaddress_ and rank is null 0,1;
                    if messagedate is not null then
                        if PastCardlocation>0 then
                            update gmms_shelf_tasks2 set taskstatus='正在上车',cardlocation=Cardlocation_,isout=1 where id=Taskid_;
                            insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,groups_,NOW(),'发送正在上车',Taskid_,messagedate);
                      else
                            update gmms_shelf_tasks2 set taskstatus='正在上车',cardlocation=Cardlocation_ where id=Taskid_;        
                            insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,groups_,NOW(),'发送正在上车',Taskid_,messagedate);
                        end if;                                        
                    end if;
                end if;            
                set isWorking=(select count(id) from gmms_shelf_tasks2 where groups=groups_ and (taskstatus='正在上车' or taskstatus='正在下车') and isrepeal='正常');    
                set isEnd=0;#防止into 影响        
                FETCH ShelfSend_cursor INTO Taskid_,Taskphases_,Taskstatus_,Rackid_,Beginaddress_,Endgroups_,Endaddress_;            
            end while;
        end if;
    #关闭游标
    CLOSE ShelfSend_cursor;
    if isWorking=0 and CarCount>0 then
        #下车
        call intTo2ByteHex10_16_4(PastEndaddress_,@target);
        call intTo2ByteHex10_16_4(PastCardlocation,@PastCardlocation);
        set messagedate=CONCAT(returnvalue,"00000000",@target,@PastCardlocation,'0002');
        if messagedate is not null then
            update gmms_shelf_tasks2 set taskstatus='正在下车' where id=Carid_;
            insert into aaaa(MachineName,groups,data1,Content,id,Sendtext) values (machineids,groups_,NOW(),'发送正在下车',Carid_,messagedate);
        end if;
    end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for y_ShelfTempering
-- ----------------------------
DROP PROCEDURE IF EXISTS `y_ShelfTempering`;
delimiter ;;
CREATE PROCEDURE `y_ShelfTempering`()
BEGIN
    #钢化任务   +  中空+理片+旋转退库任务
    DECLARE isEnd DOUBLE DEFAULT 0;    #是否还有数据
    DECLARE id_ int DEFAULT 0;      #启用/禁用
    DECLARE drop_type_ varchar(255) DEFAULT null;  #类型线路
    DECLARE stops_ varchar(255) DEFAULT null;  #类型线路
    DECLARE stops2_ varchar(255) DEFAULT null;  #类型线路
    DECLARE flag_ int DEFAULT 0;      #启用/禁用
    DECLARE sign_ int DEFAULT 0;    #标志
    DECLARE signout_ int DEFAULT 0;    #退回标志(出库前的库位)
    DECLARE stop_rank_ varchar(255) DEFAULT null;  #起始地
    DECLARE endstop_rank_ varchar(255) DEFAULT null;  #起始地
    DECLARE endgroups_ BIGINT DEFAULT 0;     #目的线路
    DECLARE rank_ BIGINT DEFAULT 0;          #料架id
    DECLARE rank2_ BIGINT DEFAULT 0;          #料架id
    DECLARE rankposition_ varchar(255) DEFAULT null;    #车上架子任务 出库前库位
    DECLARE orientation_ varchar(255) DEFAULT null;  #面朝向
    DECLARE orientation2_ varchar(255) DEFAULT null;  #面朝向
    #定义游标 
    DECLARE ShelfTempering_cursor CURSOR FOR SELECT id,drop_type,flag,sign,stop_rank,rank,all_groups,orientation,rankposition FROM gmms_drop_frame_5 where groups_<100;
    DECLARE CONTINUE HANDLER FOR NOT FOUND SET isEnd = 1;
    OPEN ShelfTempering_cursor;
 
    FETCH ShelfTempering_cursor INTO id_,drop_type_,flag_,sign_,stop_rank_,rank_,EndGroups_,orientation_,rankposition_;
        while isEnd!=1 do        
            if sign_=6 and rank_ is not null then
                #退库     钢化+中空一线退库  1车
                if (drop_type_='钢化' or EndGroups_=5) and (select count(*) from gmms_shelf_tasks2 where rackid=rank_ and isrepeal='正常' and taskstatus!='已完成')=0 then
                    insert into gmms_shelf_tasks2(groups,tasktype,taskphase,taskstatus,starttime,beginaddress,endaddress,rackid,endgroups)
                    select 1,drop_type_,'入库','等待上车',NOW(),stop_rank_,rankposition_,rank_,EndGroups_;
                    update gmms_drop_frame_5 set sign=7 where id=id_;
                elseif drop_type_='旋转' then
                    if stop_rank_=99 then
                        set stop_rank_=98;
                    elseif stop_rank_=98 then
                        set stop_rank_=99;
                    end if;
                    insert into gmms_shelf_tasks2(groups,tasktype,taskphase,taskstatus,starttime,beginaddress,endaddress,rackid,endgroups)
                    select 3,drop_type_,'入库','等待上车',NOW(),stop_rank_,rankposition_,rank_,300;
                    update gmms_drop_frame_5 set sign=7 where id=id_;
                elseif flag_=1 and (select count(*) from gmms_shelf_tasks2 where rackid=rank_ and isrepeal='正常' and taskstatus!='已完成')=0 then   #中空二,三,四线退库  理片车
                    insert into gmms_shelf_tasks2(groups,tasktype,taskphase,taskstatus,starttime,beginaddress,endaddress,rackid,endgroups)
                    select 2,drop_type_,'入库','等待上车',NOW(),stop_rank_,rankposition_,rank_,EndGroups_;
                    update gmms_drop_frame_5 set sign=7 where id=id_;
                end if;                
            elseif sign_=0 and flag_=1 and rank_ is null  then
                if drop_type_='钢化' then
                    #补架子   (只补1-20号架子)
                    select dr.rank,dr.stops into rank_,stops_ from gmms_drop_frame_5 as dr 
                    left join gmms_shelf_rack_2 as sr on dr.rank=sr.id 
                    left join gmms_liuchengka as lk on sr.processcard_id=lk.liuchengka
                    where groups_=100 and dr.stops<21 and dr.flag=1 and dr.sign=0 and dr.rank is not null
                    and sr.processcard_id is null and sr.orientation=orientation_ limit 0,1;
                    if rank_ is null and (select count(*) from gmms_drop_frame_5 where groups_=2 and sign=0)=2 then
                        #旋转   无需要面的 空架    查找任意一空架进行旋转
                        select dr.rank,dr.stops into rank_,stops_ from gmms_drop_frame_5 as dr 
                        left join gmms_shelf_rack_2 as sr on dr.rank=sr.id
                        where groups_=100 and dr.stops<21 and dr.flag=1 and dr.sign=0 and dr.rank is not null
                        and sr.processcard_id is null limit 0,1;
                        select stop_rank into endstop_rank_ from gmms_drop_frame_5 where groups_=2 and sign=0 limit 1;
                        if rank_ is not null and (select count(*) from gmms_shelf_tasks2 where endaddress=endstop_rank_ and isrepeal='正常' and taskstatus!='已完成')=0 then
                            insert into gmms_shelf_tasks2(groups,tasktype,taskphase,taskstatus,starttime,beginaddress,endaddress,rackid,endgroups)
                            select 3,'旋转','出库','等待上车',NOW(),stops_,endstop_rank_,rank_,250;                        
                            update gmms_drop_frame_5 as dr INNER join gmms_drop_frame_5 as dr1 
                            set dr.sign=7,dr1.sign=7 where dr.stop_rank=endstop_rank_ and dr1.stops=stops_ and dr1.groups_=100;
                        end if;
                    elseif rank_ is not null and (select count(*) from gmms_shelf_tasks2 where endaddress=stop_rank_ and isrepeal='正常' and taskstatus!='已完成')=0 then
                        insert into gmms_shelf_tasks2(groups,tasktype,taskphase,taskstatus,starttime,beginaddress,endaddress,rackid,endgroups)
                        select 1,drop_type_,'出库','等待上车',NOW(),stops_,stop_rank_,rank_,EndGroups_;                        
                        update gmms_drop_frame_5 as dr INNER join gmms_drop_frame_5 as dr1 
                        set dr.sign=7,dr1.sign=7 where dr.id=id_ and dr1.rank=rank_;
                    end if;    
                elseif drop_type_='理片' then    
                    select dr.rank,dr.stops into rank_,stops_ from gmms_drop_frame_5 as dr 
                    left join gmms_shelf_rack_2 as sr on dr.rank=sr.id 
                    left join gmms_liuchengka as lk on sr.processcard_id=lk.liuchengka
                    where groups_=100 and dr.stops>20 and dr.flag=1 and dr.sign=0 
                    and lk.current_work_position='理片' and lk.current_status='等待中' and sr.orientation=orientation_ 
                    order by lk.getdatatime asc limit 0,1;    
                    if rank_ is not null and (select count(*) from gmms_shelf_tasks2 where endaddress=stop_rank_ and isrepeal='正常' and taskstatus!='已完成')=0 then
                        insert into gmms_shelf_tasks2(groups,tasktype,taskphase,taskstatus,starttime,beginaddress,endaddress,rackid,endgroups)
                        select 2,drop_type_,'出库','等待上车',NOW(),stops_,stop_rank_,rank_,EndGroups_;
                        update gmms_drop_frame_5 as dr INNER join gmms_drop_frame_5 as dr1 
                        set dr.sign=7,dr1.sign=7 where dr.id=id_ and dr1.rank=rank_;
                    end if;
                end if;             
            elseif sign_=0 and flag_=1 and rank_ is not null and drop_type_='吊装' then
                    #起始库位
                    select stops into stops_ from gmms_drop_frame_5 where groups_=100 and rank=rank_ and (sign=10 or sign=0) and flag=1 limit 0,1;
                    select stops_;
                    select stops_>20;
                    if stops_>20 then
                        insert into gmms_shelf_tasks2(groups,tasktype,taskphase,taskstatus,starttime,beginaddress,endaddress,rackid,endgroups)
                        select 2,drop_type_,'出库','等待上车',NOW(),stops_,stop_rank_,rank_,EndGroups_;
                        update gmms_drop_frame_5 as dr INNER join gmms_drop_frame_5 as dr1 
                        set dr.sign=7,dr1.sign=7 where dr.id=id_ and dr1.rank=rank_;
                    elseif stops_<21 and stops_>0 then 
                        #查找 中空方向的 已领取的1号线任务  
                        select dr.stops,dr.rank into stops2_,rank2_ from gmms_drop_frame_5 as dr LEFT JOIN gmms_shelf_rack_2 as sr on dr.rank=sr.id
                        left join gmms_liuchengka as lk on sr.processcard_id=lk.liuchengka
                        left join gmms_liuchengka as lk2 on lk.parent_liuchengka=lk2.liuchengka
                        where dr.groups_=100 and dr.sign=0 and dr.flag=1 and dr.stops>20 and dr.rank is not null and sr.processcard_id is not null
                        and lk2.getgroups=1    limit 0,1;
                        #查找 中空方向的 空架子 替换
                        if stops2_=0 or stops2_ is null then
                            select dr.stops,dr.rank into stops2_,rank2_ from gmms_drop_frame_5 as dr LEFT JOIN gmms_shelf_rack_2 as sr on dr.rank=sr.id
                            left join gmms_liuchengka as lk on sr.processcard_id=lk.liuchengka
                            left join gmms_liuchengka as lk2 on lk.parent_liuchengka=lk2.liuchengka
                            where dr.groups_=100 and dr.sign=0 and dr.flag=1 and dr.stops>20 and dr.rank is not null and sr.processcard_id is null limit 0,1;
                        end if;
                        #查找 中空方向的 无领取+不需要理片的 替换
                        if stops2_=0 or stops2_ is null then
                            select dr.stops,dr.rank into stops2_,rank2_ from gmms_drop_frame_5 as dr LEFT JOIN gmms_shelf_rack_2 as sr on dr.rank=sr.id
                            left join gmms_liuchengka as lk on sr.processcard_id=lk.liuchengka
                            left join gmms_liuchengka as lk2 on lk.parent_liuchengka=lk2.liuchengka
                            where dr.groups_=100 and dr.sign=0 and dr.flag=1 and dr.stops>20 and dr.rank is not null and sr.processcard_id is not null
                            and lk2.getgroups is null and !(lk.current_work_position='理片' and lk.current_status='等待中') order by dr.id asc limit 0,1;
                        end if;
                        if stops2_>0 and (select count(*) from gmms_shelf_tasks2 where rackid=rank_ and isrepeal='正常' and taskstatus!='已完成')=0 then
                            insert into gmms_shelf_tasks2(groups,tasktype,taskphase,taskstatus,starttime,beginaddress,endaddress,rackid,endgroups)
                            select 3,drop_type_,'移库','等待上车',NOW(),stops_,stops2_,rank_,400;
                            insert into gmms_shelf_tasks2(groups,tasktype,taskphase,taskstatus,starttime,beginaddress,endaddress,rackid,endgroups)
                            select 3,drop_type_,'移库','等待上车',NOW(),stops2_,stops_,rank2_,400;
                            update gmms_drop_frame_5 as dr INNER join gmms_drop_frame_5 as dr1 
                            set dr.sign=7,dr1.sign=7 where dr.stops=stops2_ and dr.groups_=100 and dr1.groups_=100 and dr1.stops=stops_;
                        end if;
                    end if;    
            end if;
            set isEnd=0;#防止into 影响
            set flag_=0;
            set sign_=0;
            set stops_=0;
            set stops2_=0;
            set stop_rank_=null;
            set endgroups_=0;
            set rank_=0;
            set rank2_=0;
            set orientation_=null;
            set orientation2_=null;
            set drop_type_=null;
            FETCH ShelfTempering_cursor INTO id_,drop_type_,flag_,sign_,stop_rank_,rank_,EndGroups_,orientation_,rankposition_;
        end while;
    
    #关闭游标
    CLOSE ShelfTempering_cursor;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for y_ShelfXz
-- ----------------------------
DROP PROCEDURE IF EXISTS `y_ShelfXz`;
delimiter ;;
CREATE PROCEDURE `y_ShelfXz`()
BEGIN
    #旋转任务 
    #1.查看是否两个旋转位都空  sign=0
    #2.查看3A 3B 的流程卡 创建旋转任务
    #3.查看1A 1B 的流程卡 创建旋转任务
    
    DECLARE parentliuchengka_ varchar(255) DEFAULT null;  #父级流程卡
    DECLARE orientation_ varchar(255) DEFAULT null;       #待旋转面朝向
    DECLARE rank_ varchar(255) DEFAULT null;                       #待旋转料架id
    DECLARE beginaddress_ varchar(255) DEFAULT null;      #待旋转料架所在库位编号
    
    DECLARE id_ BIGINT DEFAULT 0;                                    #库位id
    DECLARE drop_type_ varchar(255) DEFAULT null;         #库位类型
    DECLARE stop_rank_ varchar(255) DEFAULT null;         #库位编号
    DECLARE EndGroups_ varchar(255) DEFAULT null;         #库位线路
    
    #两个旋转位都为空
    if (select count(*) from gmms_drop_frame_5 where groups_=2 and sign=0)=2 then
        #得到同一父级流程卡下 库内 相同面>2的 父级流程卡
        select lk.parent_liuchengka,sr.orientation into parentliuchengka_,orientation_ from gmms_drop_frame_5 as dr 
        left join gmms_shelf_rack_2 as sr on dr.rank=sr.id
        left join gmms_liuchengka as lk on sr.processcard_id=lk.liuchengka
        where sr.id is not null and lk.liuchengka is not null and groups_=100 and dr.sign=0
        and lk.liuchengka!=(select IFNULL(srd.processcard_id,"1") from gmms_drop_frame_5 as drd left join gmms_shelf_rack_2 as srd on drd.rank=srd.id where drd.id=501)
        group by lk.parent_liuchengka,sr.orientation having count(*)>2 limit 0,1;
        
        if parentliuchengka_ is null then
            #查看1A 1B 的流程卡    1.拿到需要旋转的父级流程卡  2.拿到那一架去旋转(需要根据是否领取)
            select parent_liuchengka into parentliuchengka_ from (
            select lk.parent_liuchengka,sr.orientation  from gmms_drop_frame_5 as dr 
            left join gmms_shelf_rack_2 as sr on dr.rank=sr.id
            left join gmms_liuchengka as lk on sr.processcard_id=lk.liuchengka
            left join gmms_liuchengka as lk2 on lk.parent_liuchengka=lk2.liuchengka
            where sr.id is not null and lk.liuchengka is not null and lk2.liuchengka is not null and dr.groups_=100 and dr.sign=0 and lk2.child_count=2
            and lk.liuchengka!=(select IFNULL(srd.processcard_id,"1") from gmms_drop_frame_5 as drd left join gmms_shelf_rack_2 as srd on drd.rank=srd.id where drd.id=501)    
            group by lk.parent_liuchengka,sr.orientation having count(*)=1) AS R group by parent_liuchengka having count(*)=2 LIMIT 0,1;
            
            select orientation into orientation_ from gmms_drop_frame_5 as dr 
            left join gmms_liuchengka as lk on dr.drop_groups=lk.getgroups
            where dr.groups_=4 and rank is null and flag=1 and sign=0 and liuchengka=parentliuchengka_ 
            group by orientation  having count(*)=2 limit 0,1;
            #中空  A工位空闲把B转成A    B工位空闲把A转成B
            if orientation_='A' then
                set orientation_='B';
            elseif orientation_='B' then
                set orientation_='A';
            end if;
            if orientation_ is null then
                #表示 1.此任务未领取 / 2.领取线路无空工位    (规则:按不缺片的方向为准,即缺片的去旋转)
                select sr.orientation into orientation_ from gmms_drop_frame_5 as dr 
                left join gmms_shelf_rack_2 as sr on dr.rank=sr.id
                left join gmms_liuchengka as lk on sr.processcard_id=lk.liuchengka
                where sr.id is not null and lk.liuchengka is not null and dr.groups_=100 and dr.sign=0
                and lk.parent_liuchengka=parentliuchengka_ 
                ORDER BY (select count(*) from gmms_galss_task_shelf where processcard_id=sr.processcard_id and (work_state='已完成' and work_procedure='钢化后下片')) asc limit 0,1;
            end if;
        end if;
        
        if parentliuchengka_ is not null and orientation_ is not null then
            #待旋转料架信息
            select sr.id,dr.stop_rank into rank_,beginaddress_ from gmms_drop_frame_5 as dr 
            left join gmms_shelf_rack_2 as sr on dr.rank=sr.id
            left join gmms_liuchengka as lk on sr.processcard_id=lk.liuchengka
            where sr.id is not null and lk.liuchengka is not null 
            and lk.parent_liuchengka=parentliuchengka_ and sr.orientation=orientation_ and groups_=100 and dr.sign=0 limit 0,1;
        
            #空闲的旋转位
            select id,drop_type,stop_rank,all_groups 
            into id_,drop_type_,stop_rank_,EndGroups_ FROM gmms_drop_frame_5 
            where groups_=2 and rank is null and sign=0 and flag=1 limit 0,1;
            #select CONCAT(rank_,',',beginaddress_,',',stop_rank_);
            insert into gmms_shelf_tasks2(groups,tasktype,taskphase,taskstatus,starttime,beginaddress,endaddress,rackid,endgroups)
            select 3,drop_type_,'出库','等待上车',NOW(),beginaddress_,stop_rank_,rank_,300;
            
            update gmms_drop_frame_5 set sign=7 where id=id_ or rank=rank_ and groups_=100;
        end if;
        
        
    end if;
    
    
    
 
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for y_Shelf_copy1
-- ----------------------------
DROP PROCEDURE IF EXISTS `y_Shelf_copy1`;
delimiter ;;
CREATE PROCEDURE `y_Shelf_copy1`()
BEGIN
    DECLARE pro_id int DEFAULT 0;    #
    #半成品仓储   定时检索
    #1.检查 钢化后是否要补架子,
    #2.是否有需要理片的任务
    #3.是否有要去中空的任务
    #4.是否有要去旋转的任务
    select id into pro_id from y_pro_timer where pro_timer='Shelf' and is_enable='开启' and is_run='空闲' limit 0,1;
    select pro_id;
    if pro_id>0 then
        update y_pro_timer set is_run='运行中',run_begin_time=NOW() where id=pro_id;
        select '进';
        update y_pro_timer set is_run='空闲',run_end_time=NOW() where id=pro_id;
    end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Procedure structure for 测试入口
-- ----------------------------
DROP PROCEDURE IF EXISTS `测试入口`;
delimiter ;;
CREATE PROCEDURE `测试入口`()
BEGIN
    #Routine body goes here...
  call machine_state_begin_update();
    select @zzzz_update_state;
call machine_state_update_var(7,"工作状态","进库中");
call machine_state_update_var(7,"任务ID","1119");
select * from gmms_machine_state;
select @zzzz_update_state;
END
;;
delimiter ;
 
-- ----------------------------
-- Event structure for deleteshujujilu
-- ----------------------------
DROP EVENT IF EXISTS `deleteshujujilu`;
delimiter ;;
CREATE EVENT `deleteshujujilu`
ON SCHEDULE
EVERY '1' DAY STARTS '2023-02-28 08:39:00'
DO #call deleteshujujilu()
select 1
;;
delimiter ;
 
-- ----------------------------
-- Event structure for ShelfTasks
-- ----------------------------
DROP EVENT IF EXISTS `ShelfTasks`;
delimiter ;;
CREATE EVENT `ShelfTasks`
ON SCHEDULE
EVERY '5' SECOND STARTS '2023-03-09 21:43:00'
DO call y_Shelf()
;;
delimiter ;
 
-- ----------------------------
-- Triggers structure for table gmms_drop_frame
-- ----------------------------
DROP TRIGGER IF EXISTS `drop_change_trigger`;
delimiter ;;
CREATE TRIGGER `drop_change_trigger` AFTER UPDATE ON `gmms_drop_frame` FOR EACH ROW BEGIN
    set @oldk=OLD.processcard_id;
    set @olds=OLD.state;
    set @newk=NEW.processcard_id;
    set @news=NEW.state;
    if @oldk<>@newk or @olds<>@news  then 
        call liuchengka_change(@oldk,@olds,@newk,@news,NEW.stops,NEW.groups,1);
    end if;
END
;;
delimiter ;
 
-- ----------------------------
-- Triggers structure for table gmms_galss_task_interrupt
-- ----------------------------
DROP TRIGGER IF EXISTS `log_trigger_copy1`;
delimiter ;;
CREATE TRIGGER `log_trigger_copy1` BEFORE UPDATE ON `gmms_galss_task_interrupt` FOR EACH ROW if new.work_procedure<>old.work_procedure or old.work_state<>new.work_state  then 
    select operator into @z_line from gmms_raw_file where file_name=new.engineering_id;
    call log_glass(new.id,new.work_procedure,new.work_state,@z_line);
end if
;;
delimiter ;
 
SET FOREIGN_KEY_CHECKS = 1;