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
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.erp.mapper.pp.FlowCardMapper">
    <resultMap id="flowCardMap" type="com.example.erp.entity.pp.FlowCard">
        <result column="order_id" property="orderId"/>
        <result column="process_Id" property="processId"/>
        <result column="quantity" property="quantity"/>
        <result column="founder" property="founder"/>
        <result column="create_time" property="createTime"/>
        <result column="layout_status" property="layoutStatus"/>
        <result column="merge" property="merge"/>
        <result column="rack" property="rack"/>
        <!--接收其他外键实体类数据-->
        <association property="order" javaType="com.example.erp.entity.sd.Order">
            <result column="project" property="project"/>
            <result column="order_id" property="orderId"/>
            <result column="customer_name" property="customerName"/>
            <result column="batch" property="batch"/>
            <result column="other_remarks" property="otherRemarks"/>
            <result column="icon" property="icon"/>
            <result column="order_type" property="orderType"/>
            <result column="salesman" property="salesman"/>
            <result column="processing_note" property="processingNote"/>
            <result column="delivery_address" property="deliveryAddress"/>
        </association>
        <association property="orderDetail" javaType="com.example.erp.entity.sd.OrderDetail">
            <result column="product_id" property="productId"/>
            <result column="product_name" property="productName"/>
            <result column="compute_gross_area" property="computeGrossArea"/>
            <result column="processing_note" property="processingNote"/>
            <result column="quantity" property="quantity"/>
            <result column="compute_gross_area" property="computeGrossArea"/>
            <result column="perimeter" property="perimeter"/>
            <result column="order_number" property="orderNumber"/>
            <result column="width" property="width"/>
            <result column="height" property="height"/>
            <result column="shape" property="shape"/>
            <result column="weight" property="weight"/>
        </association>
        <association property="orderGlassDetail" javaType="com.example.erp.entity.sd.OrderGlassDetail">
            <result column="production_id" property="productionId"/>
        </association>
        <association property="product" javaType="com.example.erp.entity.sd.Product">
            <result column="total_thickness" property="totalThickness"/>
            <result column="thickness" property="thickness"/>
        </association>
 
        <!--<result column="g_typeId" property="glassTypes.typeId"/>
        <result column="g_type" property="glassTypes.type"/>-->
 
    </resultMap>
 
 
    <!--    流程卡管理查询-->
    <select id="selectFlowCard" resultMap="flowCardMap">
        select
        a.order_Id,
        a.process_Id,
        c.product_id,
        c.product_name,
        b.project,
        sum(a.quantity) as quantity,
        sum(a.quantity) * c.area as compute_gross_area,
        a.founder,
        c.processing_note,
        b.customer_name,
        layout_status as layout_status,
        a.merge,
        a.rack,
        b.batch
        from (select id,order_id,process_id,order_number, quantity,founder,max(layout_status) as layout_status,create_time,max(merge) as merge,rack from flow_card
        group by process_Id,order_number) as a
        left join sd.`order` as b on a.order_Id=b.order_id
        left join sd.order_detail as c on a.order_Id=c.order_id and a.order_Number=c.order_number
        where date(a.create_time)>=#{selectTime1} and date(a.create_time) &lt;= #{selectTime2}
        and b.create_order>0
        <if test="flowCard.orderId != null and flowCard.orderId != ''">
            and a.order_id regexp #{flowCard.orderId}
        </if>
        <if test="flowCard.processId != null and flowCard.processId != ''">
            and a.process_Id regexp #{flowCard.processId}
        </if>
        <if test="flowCard.orderDetail.productId != null and flowCard.orderDetail.productId != ''">
            and c.product_id regexp #{flowCard.orderDetail.productId}
        </if>
        <if test="flowCard.orderDetail.productName != null and flowCard.orderDetail.productName!= ''">
            and c.product_name regexp #{flowCard.orderDetail.productName}
        </if>
 
        <if test="flowCard.order.project != null and flowCard.order.project!= ''">
            and b.project regexp #{flowCard.order.project}
        </if>
        <if test="flowCard.layoutStatus != null and flowCard.layoutStatus != '' and  flowCard.layoutStatus == '不可排版'">
            and a.layout_status regexp 0
        </if>
        <if test="flowCard.layoutStatus != null and flowCard.layoutStatus != '' and  flowCard.layoutStatus == '可排版'">
            and a.layout_status regexp 1
        </if>
        <if test="flowCard.layoutStatus != null and flowCard.layoutStatus != '' and  flowCard.layoutStatus == '已排版'">
            and a.layout_status regexp 2
        </if>
        <if test="flowCard.merge != null">
            and a.merge regexp #{flowCard.merge}
        </if>
        <if test="flowCard.rack != null and flowCard.rack != ''">
            and a.rack regexp #{flowCard.rack}
        </if>
        <if test="flowCard.order.customerName != null and flowCard.order.customerName!= ''">
            and b.customer_name regexp #{flowCard.order.customerName}
        </if>
        group by a.process_Id
        ORDER BY a.id desc
        limit #{offset},#{pageSize};
    </select>
 
 
    <select id="getPageTotal">
        select
        CEILING(count(a.process_Id)/#{pageSize}) as 'pageTotal',
        count(distinct a.process_Id) as 'total'
        from flow_card as a left join sd.`order` as b on a.order_Id=b.order_id
        left join sd.order_detail as c on a.order_Id=c.order_id and a.order_Number=c.order_number
        where date(a.create_time)>=#{selectTime1} and date(a.create_time) &lt;= #{selectTime2}
        and b.create_order>0
        <if test="flowCard.orderId != null and flowCard.orderId != ''">
            and a.order_id regexp #{flowCard.orderId}
        </if>
        <if test="flowCard.processId != null and flowCard.processId != ''">
            and a.process_Id regexp #{flowCard.processId}
        </if>
        <if test="flowCard.orderDetail.productId != null and flowCard.orderDetail.productId != ''">
            and c.product_id regexp #{flowCard.orderDetail.productId}
        </if>
        <if test="flowCard.orderDetail.productName != null and flowCard.orderDetail.productName!= ''">
            and c.product_name regexp #{flowCard.orderDetail.productName}
        </if>
 
        <if test="flowCard.order.project != null and flowCard.order.project!= ''">
            and b.project regexp #{flowCard.order.project}
        </if>
        <if test="flowCard.layoutStatus != null and flowCard.layoutStatus != '' and  flowCard.layoutStatus == '不可排版'">
            and a.layout_status regexp 0
        </if>
        <if test="flowCard.layoutStatus != null and flowCard.layoutStatus != '' and  flowCard.layoutStatus == '可排版'">
            and a.layout_status regexp 1
        </if>
        <if test="flowCard.layoutStatus != null and flowCard.layoutStatus != '' and  flowCard.layoutStatus == '已排版'">
            and a.layout_status regexp 2
        </if>
        <if test="flowCard.merge != null">
            and a.merge regexp #{flowCard.merge}
        </if>
 
        ORDER BY a.id desc
        limit #{offset},#{pageSize};
    </select>
 
    <!--分架查询-->
    <select id="selectFlowCardMp" resultMap="flowCardMap">
        select o.order_id,
        o.customer_name,
        o.project,
        o.batch,
        o.other_remarks,
        o.icon,
        o.order_type,
        o.salesman,
        o.processing_note,
        o.delivery_address
        from sd.`order` as o
        left join sd.order_glass_detail ogd on o.order_id = ogd.order_id
        where o.production_order=2 and ogd.splitting_status=0 and
        date(o.create_time)>=#{selectTime1} and date(o.create_time) &lt;= #{selectTime2}
 
        <if test="flowCard.order.orderId != null and flowCard.order.orderId != ''">
            and o.order_id regexp #{flowCard.order.orderId}
        </if>
        <if test="flowCard.order.customerName != null and flowCard.order.customerName != ''">
            and o.customer_name regexp #{flowCard.order.customerName}
        </if>
        <if test="flowCard.order.project != null and flowCard.order.project != ''">
            and o.project regexp #{flowCard.order.project}
        </if>
        <if test="flowCard.order.batch != null and flowCard.order.batch!= ''">
            and o.batch regexp #{flowCard.order.batch}
        </if>
 
        <if test="flowCard.order.otherRemarks != null and flowCard.order.otherRemarks!= ''">
            and o.other_remarks regexp #{flowCard.order.otherRemarks}
        </if>
 
        <if test="flowCard.order.icon != null and flowCard.order.icon!= ''">
            and o.icon regexp #{flowCard.order.icon}
        </if>
        <if test="flowCard.order.orderType != null and flowCard.order.orderType!= ''">
            and o.order_type regexp #{flowCard.order.orderType}
        </if>
        <if test="flowCard.order.salesman != null and flowCard.order.salesman!= ''">
            and o.salesman regexp #{flowCard.order.salesman}
        </if>
        group by o.order_id
        order by o.id desc
 
        ;
    </select>
 
    <!--    分架明细查询-->
    <select id="detailsSelectMp">
        SELECT
            od.order_id,
            ogd.production_id,
            od.product_id,
            od.product_name,
            ROUND(SUM(od.quantity) - IFNULL(SUM(fc.quantity), 0)) AS quantity,
            SUM(od.compute_gross_area) AS compute_gross_area,
            ROUND(SUM(od.perimeter), 2) AS perimeter
        FROM sd.order_detail AS od
                 LEFT JOIN (
            SELECT order_id, order_number, production_id, splitting_status,
                   technology_number
            FROM sd.order_glass_detail
            GROUP BY order_id, order_number, production_id, splitting_status
        ) AS ogd
                           ON od.order_id = ogd.order_id
                               AND od.order_number = ogd.order_number
                 LEFT JOIN (
            SELECT order_id, order_number, technology_number, SUM(quantity) AS quantity, layers_number
            FROM flow_card
            GROUP BY order_id, order_number, technology_number
        ) AS fc
                           ON fc.order_id = od.order_id
                               AND fc.order_number = od.order_number
                               AND fc.technology_number = ogd.technology_number
        WHERE od.order_id = #{orderId}
          AND ogd.splitting_status = 0
        GROUP BY od.order_id, ogd.production_id, od.product_id, od.product_name
        ORDER BY od.order_id DESC;
 
    </select>
 
    <!--    更新分架状态-->
    <update id="updateDeleteState">
        update
            sd.order_glass_detail as ogd left join pp.flow_card as fc
                on ogd.order_id = fc.order_id and ogd.order_number = fc.order_number
        set ogd.splitting_status=0
        where
        <if test="processId=='all'">
            ogd.order_id = #{orderId}
        </if>
        <if test="processId!='all'">
            fc.process_id = #{processId}
        </if>
 
 
    </update>
 
    <!--    删除流程卡-->
    <update id="deleteFlowCardMp">
        delete
        from pp.flow_card as fc
        where
        <if test="processId=='all'">
            fc.order_id = #{orderId}
        </if>
        <if test="processId!='all'">
            fc.process_id = #{processId}
        </if>
    </update>
 
    <!--    分架新增明细查询-->
 
    <!--resultMap="flowCardMap"-->
    <select id="selectNoCardMp">
 
        select od.order_number,
               od.order_number       AS 'orderNumber',
               od.width,
               od.height,
               od.shape,
               od.quantity,
               od.compute_gross_area,
               p.total_thickness,
               ROUND(od.quantity-IFNULL(sum(fc.quantity)/fc.layers_number,0))           as baiscQuantity,
               od.compute_gross_area as 'computeGrossArea',
               p.total_thickness     AS 'totalThickness',
               ifnull(p.thickness,'') as thickness,
               od.weight,
               od.remarks,
               od.processing_note,
               ifnull(od.bend_radius,'') as bend_radius,
               ods.S01,
               ods.S02,
               ods.S03,
               ods.S04,
               ods.S05,
               od.building_number
        from sd.order_detail as od
                 left join sd.order_glass_detail as ogd
                           on od.order_id = ogd.order_id and od.order_number = ogd.order_number
                 left join sd.product as p on od.product_id = p.id
                 left join (SELECT order_id,
                                   order_number,
                                   JSON_UNQUOTE(JSON_EXTRACT(other_columns, '$.S01')) AS S01,
                                   JSON_UNQUOTE(JSON_EXTRACT(other_columns, '$.S02')) AS S02,
                                   JSON_UNQUOTE(JSON_EXTRACT(other_columns, '$.S03')) AS S03,
                                   JSON_UNQUOTE(JSON_EXTRACT(other_columns, '$.S04')) AS S04,
                                   JSON_UNQUOTE(JSON_EXTRACT(other_columns, '$.S05')) AS S05
                            FROM sd.order_detail
                            WHERE order_id = #{orderId}) as ods
                           on ods.order_id = od.order_id and ods.order_number = od.order_number
                 left join flow_card as fc on fc.order_id = od.order_id and fc.order_number = od.order_number
                           and fc.technology_number=ogd.technology_number
        where od.order_id = #{orderId}
          and ogd.production_id = #{productionId}
          and ogd.splitting_status = 0
        GROUP BY od.order_number
        order by od.id
 
    </select>
 
    <!--修改排版状态-->
    <update id="updateLayoutStatusMp">
        update flow_card as fc
        set fc.layout_status=#{state}
        where fc.process_id = #{processId}
    </update>
 
    <!--    查询对应流程卡号排版状态-->
    <select id="selectLayoutStatus">
        select fc.layout_status
        from flow_card as fc
        where fc.process_id = #{processId}
        LIMIT 1
    </select>
 
    <!--    查询报工表内是否有对应流程卡-->
    <select id="reportingWorkCount">
        select COUNT(rw.process_id)
        from reporting_work as rw
        where rw.process_id = #{processId} and reviewed_state>=0
    </select>
    <!--    查询报工表内是否有对应流程卡-->
    <select id="reportingWorkCountByOrderId">
        select COUNT(rw.process_id)
        from pp.reporting_work as rw
        where rw.order_id = #{orderId} and reviewed_state>=0
    </select>
 
    <!--    插入Flow_card表-->
    <insert id="addFlowCardMp">
        insert into flow_card (order_id,
                               production_id,
                               process_id,
                               landing_sequence,
                               order_number,
                               technology_number,
                               quantity,
                               founder,
                               layers_number,
                               splitFrame_time,
                               create_time)
        select ogd.order_id,
               ogd.production_id,
               #{processId},
               #{landingSequence},
               ogd.order_number,
               ogd.technology_number,
               #{quantity},
               #{userName},
               #{layer},
               NOW(),
               NOW()
 
 
        from sd.order_glass_detail as ogd
        where ogd.production_id = #{productionId}
          and ogd.order_number = #{orderNumber}
        GROUP BY ogd.technology_number
    </insert>
 
    <!--    更新分架状态-->
    <update id="updateFlowState">
        update sd.order_glass_detail as ogd
        set ogd.splitting_status=1
        where ogd.production_id = #{productionId}
          and ogd.order_number = #{orderNumber}
    </update>
    <!--    查询未分架的条数-->
    <select id="selectFlowCount">
        select COUNT(*)
        from sd.order_glass_detail as ogd
        where ogd.order_id = #{orderId}
          and ogd.splitting_status = 0
    </select>
    <!--   修改订单表分架状态-->
    <update id="updateProcessingCard">
        update sd.`order` as o
        set o.processing_card=#{state}
        where o.order_id = #{productionId}
    </update>
 
    <!--    查询已排版数据-->
    <select id="selectOkSchedulingMp">
        select od.order_id,
               o.customer_name,
               o.project,
               od.order_number,
               od.width,
               od.height,
               od.quantity,
               round(od.width * od.height * od.quantity / 1000000, 2),
               (od.quantity - IFNULL(ps.scheduling_quantity, 0)),
               round(od.width * od.height * (od.quantity - IFNULL(ps.scheduling_quantity, 0)) / 1000000, 2),
               IFNULL(ps.scheduling_quantity, 0),
               round(od.width * od.height * (IFNULL(ps.scheduling_quantity, 0)) / 1000000, 2),
               od.product_name,
               od.shape
        from sd.order_detail as od
                 left join sd.order as o on od.order_id = o.order_id
                 left join production_scheduling as ps
                           on ps.order_id = od.order_id and ps.order_number = od.order_number
        where od.order_id = #{orderId}
          and ps.processes = #{processes}
          and ps.scheduling_id IS NOT NULL
        order by ps.id desc
    </select>
    <!--    查询未排版数据-->
    <select id="selectNoSchedulingMp">
 
    </select>
    <!--    首次查询排版数据-->
    <select id="selectLastSchedulingMp">
        select od.order_id,
               o.customer_name,
               o.project,
               od.order_number,
               od.width,
               od.height,
               od.quantity,
               round(od.width * od.height * od.quantity / 1000000, 2) as area,
               (od.quantity - IFNULL(ps.scheduling_quantity, 0))      as pendingProductionQuantity,
               round(od.width * od.height * (od.quantity - IFNULL(ps.scheduling_quantity, 0)) / 1000000,
                     2)                                               as pendingProductionArea,
               IFNULL(ps.scheduling_quantity, 0)                      as productionScheduledQuantity,
               round(od.width * od.height * (IFNULL(ps.scheduling_quantity, 0)) / 1000000,
                     2)                                               as productionScheduledArea,
               od.product_name,
               od.shape
        from sd.order_detail as od
                 left join sd.order as o on od.order_id = o.order_id
                 left join production_scheduling as ps
                           on ps.order_id = od.order_id and ps.order_number = od.order_number
        where  date(od.create_time)>=#{selectTime1} and date(od.create_time) &lt;= #{selectTime2}
    </select>
 
    <!--   查询对应序号的层数-->
    <select id="selectLayer">
        select COUNT(ogd.order_number)
        from sd.order_glass_detail as ogd
        where ogd.production_id = #{productionId}
          and ogd.order_number = #{orderNumber}
    </select>
    <!--  查询该订单流程卡条数  -->
    <select id="selectFlowCardCount">
        select COUNT(*)
        from flow_card
        where order_id = #{orderId}
    </select>
 
    <select id="flowCardDetailMp">
        select fc.order_id,
               fc.process_id,
               fc.order_number,
               fc.technology_number,
               fc.quantity,
               ogd.child_width,
               ogd.child_height,
               round(ogd.child_width * ogd.child_height * fc.quantity / 1000000, 2) as area,
               od.product_name,
               ogd.glass_child,
               fc.founder,
               date(fc.splitFrame_time)                                             as splitFrame_time,
               ogd.process,
               c.concatNumber
        from flow_card as fc
                 left join sd.order_glass_detail as ogd
                           on fc.order_id = ogd.order_id and fc.order_number = ogd.order_number and
                              fc.technology_number = ogd.technology_number
                 left join sd.order_detail as od on od.order_id = ogd.order_id and od.order_number = ogd.order_number
                 left join (
            select process_id,technology_number, GROUP_CONCAT(order_number) as concatNumber from
            flow_card where process_id = #{processId} GROUP BY process_id,technology_number
                 ) as c on c.process_id=fc.process_id
        where fc.process_id = #{processId}
        GROUP BY fc.order_id, fc.process_id, fc.order_number, fc.technology_number
        order by fc.order_number, fc.technology_number
    </select>
 
    <delete id="deleteReportingWork">
        delete
        from sd.order_process_detail
        where process_id = #{processId}
    </delete>
 
    <delete id="deleteReportingWorkByOrderId">
        delete
        from sd.order_process_detail
        where order_id = #{orderId}
    </delete>
 
 
 
    <select id="selectPrintFlowCardMp">
        select order_id,
               project,
               customer_name,
               quantity,
               area,
               order_type,
               pack_type,
               batch
        from sd.order
        where date(create_time)>=#{selectTime1} and date(create_time) &lt;= #{selectTime2}
          and position(#{orderId} in order_id)
          and position(#{project} in project)
          and if(#{state}=0,(order_review >0 and processing_card =0),processing_card >0)
        order by create_time desc
    </select>
 
    <select id="selectPrintFlowCard">
        select op.project_no,glass_total,glass_total_area,labelPrintNum,processPrintNum,glass_type,glass_thickness
        from pp.optimize_project as op
                 left join pp.flow_card as fc on op.project_no=fc.project_no
                 left join sd.`order` as o on o.order_id=fc.order_id
        where date(op.create_time)>=#{selectTime1} and date(op.create_time) &lt;= #{selectTime2}
          and state >= 20 and (o.create_order>0   or o.create_order is null)
        GROUP BY op.project_no
        order by op.create_time desc
    </select>
 
    <select id="selectPrintMp">
        SELECT result.*,fcc.print_status from ( select *
        from ((select fc.id,
                      fc.order_id,
                      fc.process_id,
                      o.customer_name,
                      o.project,
                      ogdss.technology_number,
                      ogd.glass_address,
                      ROUND(sum(fc.quantity) / (count(DISTINCT fc.technology_number))) as quantity,
                      # sum(ogd.total_area)                                              as total_area,
                      ROUND(SUM(ogd.child_width*ogd.child_height*fc.quantity)/1000000/(count(DISTINCT fc.technology_number)),2) as total_area,
                      od.product_name,
                      ogdss.concatenated_glass_child                                   as glass_child,
                      fc.founder,
                      date(fc.splitFrame_time)                                         as splitFrame_time,
                      processed_part                                                   as process,
                      merge
 
               from flow_card as fc
                        left join sd.order_glass_detail as ogd
                                  on ogd.order_id = fc.order_id and ogd.order_number = fc.order_number and
                                     ogd.technology_number = fc.technology_number
                        left join sd.order_detail as od
                                  on od.order_id = fc.order_id and od.order_number = fc.order_number
                        left join sd.`order` as o on o.order_id = fc.order_id
                        left join (select ogds.order_id,
                                          ogds.order_number,
                                          GROUP_CONCAT(ogds.technology_number SEPARATOR '') AS technology_number,
                                          ogds.glass_child                                  AS concatenated_glass_child,
                                          process                                           AS processed_part,
                                          ogds.child_width,
                                          ogds.child_height,
                                          ogds.group
                                   from sd.order_glass_detail as ogds
                                   where ogds.order_id = #{orderId}
                                   GROUP BY order_id, order_number, ogds.glass_child, process,ogds.group) as ogdss
                                  on fc.order_id = ogdss.order_id and ogdss.order_number = fc.order_number
               where fc.order_id = #{orderId}
               GROUP BY fc.process_id, ogdss.concatenated_glass_child, ogdss.processed_part,ogdss.group
               order by fc.process_id, ogdss.technology_number)
 
              UNION
 
              (select fc.id,
                      fc.order_id,
                      fc.process_id,
                      o.customer_name,
                      o.project,
                      ogdss.technology_number,
                      ogd.glass_address,
                      ROUND(sum(fc.quantity) / (count(DISTINCT fc.technology_number))) as quantity,
                     #  sum(ogd.total_area)                                              as total_area,
                      ROUND(SUM(ogd.child_width*ogd.child_height*fc.quantity)/1000000/(count(DISTINCT fc.technology_number)),2) as total_area,
                      od.product_name,
                      ogdss.concatenated_glass_child                                   as glass_child,
                      fc.founder,
                      date(fc.splitFrame_time)                                         as splitFrame_time,
                      processed_part                                                   as process,
                      merge
 
               from flow_card as fc
                        left join sd.order_glass_detail as ogd
                                  on ogd.order_id = fc.order_id and ogd.order_number = fc.order_number and
                                     ogd.technology_number = fc.technology_number
                        left join sd.order_detail as od
                                  on od.order_id = fc.order_id and od.order_number = fc.order_number
                        left join sd.`order` as o on o.order_id = fc.order_id
                        left join (select ogds.order_id,
                                          ogds.order_number,
                                          GROUP_CONCAT(ogds.technology_number SEPARATOR '') AS technology_number,
                                          ogds.glass_child,
                                          GROUP_CONCAT(ogds.glass_child SEPARATOR '+')      AS concatenated_glass_child,
                                          SUBSTRING(process, LOCATE(bd.basic_name, process))       AS processed_part
                                   from sd.order_glass_detail as ogds
                                   left join sd.basic_data as bd on bd.nickname='stepC'
                                   where ogds.order_id = #{orderId}
                                     and LOCATE(bd.basic_name, ogds.process) > 0
                                   GROUP BY order_id, order_number, ogds.group) as ogdss
                                  on fc.order_id = ogdss.order_id and ogdss.order_number = fc.order_number
               where fc.order_id = #{orderId}
               GROUP BY fc.process_id, ogdss.technology_number
               order by fc.process_id)
              UNION
              (select fc.id,
                      fc.order_id,
                      fc.process_id,
                      o.customer_name,
                      o.project,
                      ogdss.technology_number,
                      ogd.glass_address,
                      ROUND(sum(fc.quantity) / (count(DISTINCT fc.technology_number))) as quantity,
                      ROUND(SUM(ogd.child_width*ogd.child_height*fc.quantity)/1000000/(count(DISTINCT fc.technology_number)),2) as total_area,
                      od.product_name,
                      ogdss.concatenated_glass_child                                   as glass_child,
                      fc.founder,
                      date(fc.splitFrame_time)                                         as splitFrame_time,
                      processed_part                                                   as process,
                      merge
 
               from flow_card as fc
                        left join sd.order_glass_detail as ogd
                                  on ogd.order_id = fc.order_id and ogd.order_number = fc.order_number and
                                     ogd.technology_number = fc.technology_number
                        left join sd.order_detail as od
                                  on od.order_id = fc.order_id and od.order_number = fc.order_number
                        left join sd.`order` as o on o.order_id = fc.order_id
                        left join (select ogds.order_id,
                                          ogds.order_number,
                                          GROUP_CONCAT(pds.glass_sort SEPARATOR '')           AS technology_number,
                                          ogds.glass_child,
                                          GROUP_CONCAT(ogds.glass_child SEPARATOR '+')        AS concatenated_glass_child,
                                          SUBSTRING(ogds.process, LOCATE(bd.basic_name, ogds.process)) AS processed_part
                                   from sd.order_glass_detail as ogds
                                            left join sd.order_detail as ods
                                                      on ods.order_id = ogds.order_id and ods.order_number = ogds.order_number
                                            left join sd.product_detail as pds on pds.prod_id = ods.product_id and
                                                                                  pds.glass_sort =
                                                                                  ogds.technology_number
                                            left join sd.basic_data as bd on bd.nickname='stepD'
                                   where ogds.order_id = #{orderId}
                                   GROUP BY order_id, order_number) as ogdss
                                  on fc.order_id = ogdss.order_id and ogdss.order_number = fc.order_number
               where fc.order_id = #{orderId}
               GROUP BY fc.process_id
               order by fc.process_id)) AS combined_results
        where process is not null
          and process != ""
        GROUP BY order_id, process_id, technology_number, process
        order by order_id, process_id, length(technology_number)) as result
        LEFT JOIN (SELECT * from flow_card GROUP BY process_id,technology_number) as fcc
        on result.process_id = fcc.process_id and result.technology_number = fcc.technology_number
    </select>
 
    <select id="getPrimaryList">
        select o.customer_name,
               o.project,
               #{process}                                         process,
               od.edging_type,
               #{glassChild}                                   as glass_child,
               od.product_name,
               o.processing_note,
               fc.process_id,
               SUM(od.quantity)                                as quantity,
               round(SUM(ogd.total_area), 2)                   as gross_area,
               sum(od.weight)                                  as weight,
               #{technologyNumber}                             as technologyNumber,
               concat(fc.process_id, '/', #{technologyNumber}) as processIdNumber,
               concat('对应我司单号', o.batch)                 AS otherRemarks,
               ''                                              as qrcode,
               ifnull(rack,"")                                  as rack
        from flow_card as fc
                 left join sd.order_glass_detail as ogd
                           on fc.order_id = ogd.order_id and fc.order_number = ogd.order_number and
                              fc.technology_number = ogd.technology_number
                 left join sd.order_detail as od on od.order_id = fc.order_id and od.order_number = fc.order_number
                 left join sd.`order` as o on o.order_id = fc.order_id
                 left join sd.product as p on p.id = od.product_id
                 left join (select ogd.order_id,
                                   ogd.order_number,
                                   ogd.technology_number,
                                   ogd.glass_child,
                                   GROUP_CONCAT(glass_child SEPARATOR ' ') AS concatenated_glass_child
                            from sd.order_glass_detail as ogd
                            where ogd.order_id = #{orderId}
                              and position(ogd.technology_number in #{technologyNumber})
                            GROUP BY order_id, order_number) as ogdc
                           on ogdc.order_id = ogd.order_id and ogdc.order_number = ogd.order_number and
                              ogdc.technology_number = ogd.technology_number
        where fc.process_id = #{processId}
          and position(fc.technology_number in #{technologyNumber})
        group by fc.process_id
    </select>
 
    <select id="getPrimaryLists">
        select o.customer_name,
               o.project,
               #{process}                                         process,
               od.edging_type,
               #{glassChild}                                   as glass_child,
               od.product_name,
               o.processing_note,
               fc.process_id,
               #{quantity}                                                      as quantity,
               round(od.width*od.height*#{quantity}/1000000, 2)                   as gross_area,
               sum(od.weight)                                  as weight,
               #{technologyNumber}                             as technologyNumber,
               concat(fc.process_id, '/', #{technologyNumber}) as processIdNumber,
               concat('对应我司单号', o.batch)                 AS otherRemarks,
               ''                                              as qrcode
        from flow_card as fc
                 left join sd.order_glass_detail as ogd
                           on fc.order_id = ogd.order_id and fc.order_number = ogd.order_number and
                              fc.technology_number = ogd.technology_number
                 left join sd.order_detail as od on od.order_id = fc.order_id and od.order_number = fc.order_number
                 left join sd.`order` as o on o.order_id = fc.order_id
                 left join sd.product as p on p.id = od.product_id
                 left join (select ogd.order_id,
                                   ogd.order_number,
                                   ogd.technology_number,
                                   ogd.glass_child,
                                   GROUP_CONCAT(glass_child SEPARATOR ' ') AS concatenated_glass_child
                            from sd.order_glass_detail as ogd
                            where ogd.order_id = #{orderId}
                              and position(ogd.technology_number in #{technologyNumber})
                            GROUP BY order_id, order_number) as ogdc
                           on ogdc.order_id = ogd.order_id and ogdc.order_number = ogd.order_number and
                              ogdc.technology_number = ogd.technology_number
        where fc.process_id = #{processId}
          and position(fc.technology_number in #{technologyNumber})
        group by fc.process_id
    </select>
 
    <select id="getDetailList">
        select fc.order_number,
               concat(IF(ROUND(ogd.child_width, 1) = FLOOR(ogd.child_width), FLOOR(ogd.child_width), ROUND(ogd.child_width, 1)), "*", IF(ROUND(child_height, 1) = FLOOR(child_height), FLOOR(child_height), ROUND(child_height, 1)))   as child_width,
               fc.quantity,
               round(ogd.total_area, 2)                                       as total_area,
               od.perimeter,
               if(od.bend_radius!=null || od.bend_radius!='',od.bend_radius,if(od.shape=2,JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S04')),'')) as bend_radius,
               concat(IFNULL(od.processing_note, ''), IFNULL(od.remarks, '')) as remarks,
               od.other_columns,
               round(ogd.child_width)                                         as width,
               round(ogd.child_height)                                        as height,
               pd.separation,
               fc.technology_number,
               IFNULL(JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S02')),'') as mapNumber,
               od.building_number
        from flow_card as fc
                 left join sd.order_glass_detail as ogd
                           on fc.order_id = ogd.order_id and fc.order_number = ogd.order_number and
                              fc.technology_number = ogd.technology_number
                 left join sd.order_detail as od on od.order_id = fc.order_id and od.order_number = fc.order_number
                 left join sd.product_detail as pd
                           on pd.prod_id = od.product_id and pd.glass_sort = ogd.technology_number
                 left join flow_card_sort as fcs
                           on fcs.process_id = fc.process_id and fcs.order_number = fc.order_number and
                              fcs.technology_number = fc.technology_number
                               and fcs.process = #{process}
        where fc.process_id = #{processId}
          and position(fc.technology_number in #{technologyNumber})
        group by fc.process_id, fc.order_number
        <choose>
            <!-- flashback = 1 时正序 -->
            <when test="flashback == 1">
                ORDER BY
                CASE
                WHEN fcs.sort IS NOT NULL AND fcs.sort &lt;&gt;  '' THEN fcs.sort
                ELSE fc.order_number
                END ASC
            </when>
            <!-- flashback != 1 时倒序 -->
            <otherwise>
                ORDER BY
                CASE
                WHEN fcs.sort IS NOT NULL AND fcs.sort &lt;&gt;  '' THEN fcs.sort
                ELSE fc.order_number
                END DESC
            </otherwise>
        </choose>
    </select>
 
    <select id="getDetailLists">
        select fc.order_number,
               concat(round(ogd.child_width), "*", round(ogd.child_height))   as child_width,
               fc.quantity,
               round(ogd.total_area, 2)                                       as total_area,
               od.perimeter,
               if(od.shape=2,JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S04')),od.bend_radius) as bend_radius,
               concat(IFNULL(od.processing_note, ''), IFNULL(od.remarks, '')) as remarks,
               od.other_columns,
               round(ogd.child_width)                                         as width,
               round(ogd.child_height)                                        as height,
               pd.separation,
               fc.technology_number,
               IFNULL(JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S02')),'') as mapNumber,
               od.building_number
        from flow_card as fc
                 left join sd.order_glass_detail as ogd
                           on fc.order_id = ogd.order_id and fc.order_number = ogd.order_number and
                              fc.technology_number = ogd.technology_number
                 left join sd.order_detail as od on od.order_id = fc.order_id and od.order_number = fc.order_number
                 left join sd.product_detail as pd
                           on pd.prod_id = od.product_id and pd.glass_sort = ogd.technology_number
                 left join flow_card_sort as fcs
                           on fcs.process_id = fc.process_id and fcs.order_number = fc.order_number and
                              fcs.technology_number = fc.technology_number
                               and fcs.process = #{process}
        where fc.process_id = #{processId}
          and position(fc.technology_number in #{technologyNumber})
        and fc.order_sort = #{orderNumber}
        group by fc.process_id, fc.order_number
        order by IF(fcs.sort != NULL or fcs.sort != '', fcs.sort, fc.order_number)
    </select>
 
    <select id="getProcessList">
        select *
        from sd.order_process_detail
        where process_id = #{processId}
          and technology_number = #{technologyNumber}
        group by process
    </select>
 
    <update id="updateInventory">
        update flow_card
        set inventory_quantity=#{completedQuantity}
        where process_id = #{processId}
          and order_number = #{orderNumber}
          and technology_number = #{technologyNumber}
    </update>
 
    <!--    复选框修改排版状态-->
    <update id="updateComposing">
        update flow_card as fc
        set fc.layout_status=1
        where fc.process_id = #{processId}
    </update>
 
    <!--    复选框修改流程卡合架-->
    <update id="updateProcessCardRack">
        update flow_card as fc
        set fc.rack=#{rack}
        where fc.process_id = #{processId} and fc.technology_number=#{technologyNumber}
    </update>
 
    <select id="getPrintLabel">
        select o.order_id,
               c.customer_abbreviation as customer_name,
               o.project,
               od.building_number,
               od.processing_note,
               opd.o_width         as width,
               opd.o_height        as height,
               ogd.glass_child,
               ogd.process,
               e.type_name,
               opd.stock_id,
               opd.polys_id,
               IFNULL(od.quantity,1) as quantity,
               od.other_columns,
               od.bend_radius,
               ifnull(od.order_number,0) as heat_layout_id,
               ifnull(a.id,0) as heat_layout_sort,
               od.product_name,
               opd.process_id
        from pp.optimize_detail opd
                 left join sd.`order` o on SUBSTR(opd.process_id, 1, 10) = o.order_id
                 left join sd.order_detail od
                           on SUBSTR(opd.process_id, 1, 10) = od.order_id and opd.order_sort = od.order_number
                 left join sd.order_glass_detail ogd
                           on SUBSTR(opd.process_id, 1, 10) = ogd.order_id and opd.order_sort = ogd.order_number and
                              opd.layer = ogd.technology_number
                 left join sd.product p on od.product_id = p.id
                 left join sd.basic_glass_type e on e.type_id = p.type_id
                 left join sd.customer c on c.id = o.customer_id
        left join
        (select (@row_number := @row_number + 1) as id,process_id as process_id from (select process_id from pp.optimize_detail tt where project_no =#{projectNo} group by process_id) tt,(select @row_number := 0) as t) a
        on a.process_id=opd.process_id
        where opd.project_no = #{projectNo}
        order by opd.stock_id,opd.polys_id
    </select>
 
    <select id="getPrintLabel2">
        select o.order_id,
               c.customer_abbreviation as customer_name,
               o.project,
               od.building_number,
               od.processing_note,
               ogd.child_width         as width,
               ogd.child_height        as height,
               ogd.glass_child,
               ogd.process,
               e.type_name,
               opd.stock_id,
               opd.polys_id,
               od.quantity,
               od.other_columns,
               od.bend_radius,
               opd.heat_layout_id,
               opd.heat_layout_sort,
               od.product_name,
               opd.process_id
        from pp.optimize_detail opd
                 left join sd.`order` o on SUBSTR(opd.process_id, 1, 10) = o.order_id
                 left join sd.order_detail od
                           on SUBSTR(opd.process_id, 1, 10) = od.order_id and opd.order_sort = od.order_number
                 left join sd.order_glass_detail ogd
                           on SUBSTR(opd.process_id, 1, 10) = ogd.order_id and opd.order_sort = ogd.order_number and
                              opd.layer = ogd.technology_number
                 left join sd.product p on od.product_id = p.id
                 left join sd.basic_glass_type e on e.type_id = p.type_id
                 left join sd.customer c on c.id = o.customer_id
        where opd.project_no = #{projectNo} and o.order_id is not null
        order by opd.heat_layout_id, opd.heat_layout_sort desc
    </select>
 
    <select id="getPrintLabel1">
        select o.order_id,
               o.project,
               o.customer_id,
               ogd.child_width                as width,
               ogd.child_height               as height,
               fc.quantity,
               od.order_number                as orderNumber,
               fc.technology_number           as technologyNumber,
               ogd.glass_child,
               ogd.process,
               c.customer_abbreviation        as customer_name,
               ifnull(od.processing_note, '') as processing_note,
               bgt.type_name,
               od.other_columns,
               od.building_number,
               od.bend_radius
        from sd.order as o
                 left join sd.order_detail as od on o.order_id = od.order_id
                 left join sd.order_glass_detail as ogd
                           on ogd.order_id = od.order_id and ogd.order_number = od.order_number
                 left join pp.flow_card as fc on o.order_id = fc.order_id and
                                                 od.order_number = fc.order_number and
                                                 fc.technology_number = ogd.technology_number
                 left join sd.product pt on pt.id = od.product_id
                 left join sd.customer c on c.id = o.customer_id
                 left join sd.basic_glass_type bgt on bgt.type_id = pt.type_id
        where fc.process_id = #{processId}
          and fc.technology_number = #{technologyNumber}
        group by od.order_number, od.width, od.height
    </select>
 
    <select id="getPrintLabelDetail">
        select o.order_id,
               o.project,
               o.customer_id,
               ogd.child_width                as width,
               ogd.child_height               as height,
               fc.quantity,
               od.order_number                as orderNumber,
               fc.technology_number           as technologyNumber,
               ogd.glass_child,
               ogd.process,
               c.customer_abbreviation        as customer_name,
               ifnull(od.processing_note, '') as processing_note,
               bgt.type_name,
               od.other_columns,
               od.building_number,
               od.bend_radius
        from sd.order as o
                 left join sd.order_detail as od on o.order_id = od.order_id
                 left join sd.order_glass_detail as ogd
                           on ogd.order_id = od.order_id and ogd.order_number = od.order_number
                 left join pp.flow_card as fc on o.order_id = fc.order_id and
                                                 od.order_number = fc.order_number and
                                                 fc.technology_number = ogd.technology_number
                 left join sd.product pt on pt.id = od.product_id
                 left join sd.customer c on c.id = o.customer_id
                 left join sd.basic_glass_type bgt on bgt.type_id = pt.type_id
        <where>
            and fc.process_id = #{flowCard.processId}
            and fc.order_number = #{flowCard.orderNumber}
            <if test="flowCard.technologyNumber != null and flowCard.technologyNumber != ''">
                and fc.technology_number = #{flowCard.technologyNumber}
            </if>
        </where>
        group by od.order_number,fc.technology_number, od.width, od.height
    </select>
 
    <select id="printFlowCardDetailsMp">
        SELECT fc.process_id,
               fc.order_number,
               fc.technology_number,
               ogd.glass_address,
               ogd.child_width,
               ogd.child_height,
               fc.quantity,
               ROUND(ogd.child_width * ogd.child_height * fc.quantity / 1000000, 2) as area,
               ifnull(fcs.sort, '')                                                 as sort,
               ogd.glass_child,
               #{process}                                                           as process,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S01'))                AS glassNumber,
               if(od.shape=2,JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S04')),od.bend_radius) as bend_radius
        FROM flow_card AS fc
                 LEFT JOIN sd.order_glass_detail AS ogd ON fc.order_id = ogd.order_id
            AND fc.order_number = ogd.order_number
            AND fc.technology_number = ogd.technology_number
                 left join flow_card_sort as fcs
                           on fcs.process_id = fc.process_id and fcs.order_number = fc.order_number and
                              fcs.technology_number = fc.technology_number
                               and fcs.process = #{process}
                 left join sd.order_detail as od on od.order_id = fc.order_id and od.order_number = fc.order_number
        where fc.process_id = #{processId}
          and position(fc.technology_number in #{technologyNumber})
        GROUP BY fc.process_id,fc.order_number,fc.technology_number
        order by IF(fcs.sort != NULL or fcs.sort != '', fcs.sort, fc.order_number)
    </select>
 
    <update id="printSortMp">
        update flow_card
        set sort = #{sort}
        where process_id = #{processId}
          and order_number = #{orderNumber}
          and technology_number = #{technologyNumber}
    </update>
 
    <select id="selectType">
        select *
        from pp.tag_style
    </select>
    <select id="getPrintTitle">
        select value
        from pp.tag_style as a
        where a.name = #{type}
    </select>
 
    <select id="getCustomLabelDetailMp">
        select #{name}
        from #{form}
        where order_id = #{id}
    </select>
 
    <resultMap id="orderDetial" type="com.example.erp.entity.sd.OrderDetail">
        <result column="width" property="width"/>
        <result column="height" property="height"/>
        <result column="order_id" property="order.orderId"/>
        <result column="project" property="order.project"/>
        <result column="customer_id" property="order.customerId"/>
        <result column="customer_name" property="order.customerName"/>
        <result column="order_type" property="order.orderType"/>
        <result column="order_classify" property="order.orderClassify"/>
        <result column="batch" property="order.batch"/>
        <result column="icon" property="order.icon"/>
        <result column="pack_type" property="order.packType"/>
        <result column="delivery_date" property="order.deliveryDate"/>
        <result column="al_type" property="order.alType"/>
        <result column="money" property="order.money"/>
        <result column="contract_id" property="order.contractId"/>
        <result column="customer_batch" property="order.customerBatch"/>
        <result column="contacts" property="order.contacts"/>
        <result column="delivery_address" property="order.deliveryAddress"/>
        <result column="processing_note" property="processingNote"/>
        <result column="quantity" property="quantity"/>
        <result column="edging_type" property="edgingType"/>
        <result column="product_name" property="productName"/>
        <result column="building_number" property="buildingNumber"/>
    </resultMap>
 
    <select id="getPrintCustomData">
        select o.order_id                                            as orderId,
               project,
               customer_id                                           as customerId,
               o.customer_name                                       as customerName,
               order_type                                            as orderType,
               order_classify                                        as orderClassify,
               batch,
               o.icon,
               pack_type                                             as packType,
               delivery_date                                         as deliveryDate,
               al_type                                               as alType,
               money,
               contract_id                                           as contractId,
               customer_batch                                           customerBatch,
               contacts,
               delivery_address                                      as deliveryAddress,
               od.processing_note                                    as processingNote,
               width,
               height,
               fc.quantity,
               od.order_number                                       as orderNumber,
               fc.technology_number                                  as technologyNumber,
               od.building_number                                    as buildingNumber,
               od.product_name                                       as productName,
               od.edging_type                                        as edgingType,
               od.remarks,
               c.customer_abbreviation                               as customerAbbreviation,
               p.product_abbreviation                                as productAbbreviation,
               fc.process_id                                         as processId,
               o.create_time                                         as createTime,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S01')) AS glassNumber,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S02')) AS figureNumber,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S03')) AS colourCeramicGlaze,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S04')) AS remarks1,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S05')) AS remarks2,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S06')) AS remarks3,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S07')) AS remarks4,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S08')) AS remarks5,
               p.remarks                                             as filmNumber,
               od.bend_radius                                        as bendRadius,
               od.other_columns,
               ogd.glass_child                                       as glassChild,
               ogd.glass_address                                     as glassAddress,
               JSON_UNQUOTE(JSON_EXTRACT(pd.separation, '$.color'))  AS color
        from sd.order as o
                 left join sd.order_detail as od on o.order_id = od.order_id
                 left join flow_card as fc on o.order_id = fc.order_id and
                                              od.order_number = fc.order_number
                 left join sd.product as p on p.id = od.product_id
                 left join sd.customer as c on c.id = o.customer_id
                 left join sd.product_detail as pd on pd.prod_id = p.id and pd.sort_num = od.order_number and
                                                      pd.glass_sort = fc.technology_number
                 left join sd.order_glass_detail as ogd
                           on ogd.order_id = fc.order_id and ogd.order_number = fc.order_number and
                              ogd.technology_number = fc.technology_number
        where fc.process_id = #{processId}
          and fc.order_number = #{orderNumber}
        group by od.order_number, width, height
        order by fc.process_id
    </select>
 
    <select id="getPrintCustomData2">
        select o.order_id                                            as orderId,
               project,
               customer_id                                           as customerId,
               o.customer_name                                       as customerName,
               order_type                                            as orderType,
               order_classify                                        as orderClassify,
               batch,
               o.icon,
               pack_type                                             as packType,
               delivery_date                                         as deliveryDate,
               al_type                                               as alType,
               money,
               contract_id                                           as contractId,
               customer_batch                                           customerBatch,
               contacts,
               delivery_address                                      as deliveryAddress,
               od.processing_note                                    as processingNote,
               width,
               height,
               fc.quantity,
               od.order_number                                       as orderNumber,
               fc.technology_number                                  as technologyNumber,
               od.building_number                                    as buildingNumber,
               od.product_name                                       as productName,
               od.edging_type                                        as edgingType,
               od.remarks,
               c.customer_abbreviation                               as customerAbbreviation,
               p.product_abbreviation                                as productAbbreviation,
               fc.process_id                                         as processId,
               o.create_time                                         as createTime,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S01')) AS glassNumber,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S02')) AS figureNumber,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S03')) AS colourCeramicGlaze,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S04')) AS remarks1,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S05')) AS remarks2,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S06')) AS remarks3,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S07')) AS remarks4,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S08')) AS remarks5,
               p.remarks                                             as filmNumber,
               od.bend_radius                                        as bendRadius,
               od.other_columns,
               ogd.glass_child                                       as glassChild,
               ogd.glass_address                                     as glassAddress,
               JSON_UNQUOTE(JSON_EXTRACT(pd.separation, '$.color'))  AS color
        from sd.order as o
                 left join sd.order_detail as od on o.order_id = od.order_id
                 left join flow_card as fc on o.order_id = fc.order_id and
                                              od.order_number = fc.order_number
                 left join sd.product as p on p.id = od.product_id
                 left join sd.customer as c on c.id = o.customer_id
                 left join sd.product_detail as pd on pd.prod_id = p.id and pd.sort_num = od.order_number and
                                                      pd.glass_sort = fc.technology_number
                 left join sd.order_glass_detail as ogd
                           on ogd.order_id = fc.order_id and ogd.order_number = fc.order_number and
                              ogd.technology_number = fc.technology_number
        where fc.process_id = #{processId}
        group by od.order_number
        order by fc.process_id
    </select>
 
    <select id="selectReplenishPrintMp">
        select fc.id,
               fc.order_id,
               fc.process_id,
               o.customer_name,
               o.project,
               fc.order_number,
               ogd.technology_number,
               ogd.glass_address,
               pl.patch_num,
               pl.patch_area,
               pl.responsible_team,
               pl.responsible_equipment,
               pl.responsible_personnel,
               pl.patch_type,
               pl.patch_reason,
               pl.patch_processes,
               od.product_name,
               ogd.glass_child,
               fc.print_status,
               pl.reporting_work_id,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S01'))                AS glassNumber,
               pl.patch_id
 
        from flow_card as fc
                 left join sd.order_glass_detail as ogd
                           on ogd.order_id = fc.order_id and ogd.order_number = fc.order_number and
                              ogd.technology_number = fc.technology_number
                 left join sd.order_detail as od on od.order_id = fc.order_id and od.order_number = fc.order_number
                 left join sd.`order` as o on o.order_id = fc.order_id
                 left join patch_log as pl on pl.order_id = fc.order_id and pl.process_id = fc.process_id and
                                              pl.order_sort = fc.order_number and
                                              pl.technology_number = fc.technology_number
        where date(pl.create_time)>=#{selectTime1} and date(pl.create_time) &lt;= #{selectTime2}
          and pl.review_status > 0
        GROUP BY pl.id, fc.process_id, ogd.technology_number
        order by pl.id desc, fc.process_id, ogd.technology_number
    </select>
 
    <select id="getRepairPrintCustomData">
        select o.order_id                                            as orderId,
               o.project,
               o.customer_id                                         as customerId,
               o.customer_name                                       as customerName,
               o.order_type                                          as orderType,
               o.order_classify                                      as orderClassify,
               o.batch,
               o.icon,
               o.pack_type                                           as packType,
               o.delivery_date                                       as deliveryDate,
               o.al_type                                             as alType,
               o.money,
               contract_id                                           as contractId,
               customer_batch                                           customerBatch,
               contacts,
               o.delivery_address                                    as deliveryAddress,
               od.processing_note                                    as processingNote,
               od.width,
               od.height,
               pl.patch_num                                          as quantity,
               pl.order_sort                                         as orderNumber,
               pl.technology_number                                  as technologyNumber,
               od.building_number                                    as buildingNumber,
               od.product_name                                       as productName,
               od.edging_type                                        as edgingType,
               p.remarks,
               c.customer_abbreviation                               as customerAbbreviation,
               p.product_abbreviation                                as productAbbreviation,
               fc.process_id                                         as processId,
               o.create_time                                         as createTime,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S01')) AS glassNumber,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S02')) AS figureNumber,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S03')) AS colourCeramicGlaze,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S04')) AS remarks1,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S05')) AS remarks2,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S06')) AS remarks3,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S07')) AS remarks4,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S08')) AS remarks5,
               p.remarks                                             as filmNumber,
               od.bend_radius                                        as bendRadius,
               CONCAT(
                       TRIM(TRAILING '.' FROM TRIM(TRAILING '0' FROM CAST(width AS CHAR))),
                       ' X ',
                       TRIM(TRAILING '.' FROM TRIM(TRAILING '0' FROM CAST(height AS CHAR))),
                       ' = ',pl.patch_num   )      as size,
 
               CONCAT(
                       od.order_number,')  ',
                       TRIM(TRAILING '.' FROM TRIM(TRAILING '0' FROM CAST(width AS CHAR))),
                       ' X ',
                       TRIM(TRAILING '.' FROM TRIM(TRAILING '0' FROM CAST(height AS CHAR))),
                       ' = ',pl.patch_num   )      as numberSize
        from sd.order as o
                 left join sd.order_detail as od on o.order_id = od.order_id
                 left join flow_card as fc on o.order_id = fc.order_id and
                                              od.order_number = fc.order_number
                 left join patch_log as pl on pl.process_id = fc.process_id and pl.order_sort = fc.order_number and
                                              pl.technology_number = fc.technology_number
                 left join sd.product as p on p.id = od.product_id
                 left join sd.customer as c on c.id = o.customer_id
                 left join sd.product_detail as pd on pd.prod_id = p.id and pd.sort_num = od.order_number
        where pl.process_id = #{processId}
            and pl.order_sort=#{orderNumber}
          and pl.technology_number = #{technologyNumber}
          and pl.reporting_work_id = #{reportingWorkId}
        group by od.order_number, width, height
        order by IF(fc.sort != NULL or fc.sort != '', fc.sort, pl.order_sort)
    </select>
 
    <select id="getGlassNumber">
        select other_columns
        from sd.order_detail as od
                 left join flow_card as fc on od.order_id = fc.order_id and od.order_number = fc.order_number
        where fc.process_id = #{processId}
          and POSITION(fc.technology_number in #{technologyNumber})
        GROUP BY other_columns
        order by IF(fc.sort != NULL or fc.sort != '', fc.sort, fc.order_number)
    </select>
 
    <update id="updatePrintStateMp">
        update pp.flow_card
        set print_status = print_status + 1
        where process_id = #{processId}
          and technology_number = #{technologyNumber}
    </update>
 
    <select id="printFlowCardOrderSortMp">
        SELECT fc.process_id,
               fc.order_number,
               fc.technology_number,
               ogd.glass_address,
               ogd.child_width,
               ogd.child_height,
               fc.quantity,
               ROUND(ogd.child_width * ogd.child_height * fc.quantity / 1000000, 2) as area,
               fc.sort,
               ogd.process,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S01'))                AS glassNumber
        FROM flow_card AS fc
                 LEFT JOIN sd.order_glass_detail AS ogd ON fc.order_id = ogd.order_id
            AND fc.order_number = ogd.order_number
            AND fc.technology_number = ogd.technology_number
                 left join sd.order_detail as od on fc.order_id = od.order_id and fc.order_number = od.order_number
        where fc.order_id = #{orderId}
        order by IF(fc.sort != NULL or fc.sort != '', fc.sort, fc.technology_number)
    </select>
 
    <update id="printOrderSortMp">
        update flow_card
        set sort = #{sort}
        where process_id = #{processId}
          and order_number = #{orderNumber}
          and technology_number = #{technologyNumber}
    </update>
 
    <select id="getPrimaryListMerge">
        select o.customer_name,
               o.project,
               ogd.process,
               od.edging_type,
               ogdc.concatenated_glass_child                   as glass_child,
               od.product_name,
               o.processing_note,
               fc.process_id,
               SUM(od.quantity)                                as quantity,
               round(SUM(ogd.total_area), 2)                   as gross_area,
               sum(od.weight)                                  as weight,
               #{technologyNumber}                             as technologyNumber,
               concat(fc.process_id, '/', #{technologyNumber}) as processIdNumber,
               concat('对应我司单号', o.batch)                 AS otherRemarks
        from flow_card as fc
                 left join sd.order_glass_detail as ogd
                           on fc.order_id = ogd.order_id and fc.order_number = ogd.order_number and
                              fc.technology_number = ogd.technology_number
                 left join sd.order_detail as od on od.order_id = fc.order_id and od.order_number = fc.order_number
                 left join sd.`order` as o on o.order_id = fc.order_id
                 left join sd.product as p on p.id = od.product_id
                 left join (select ogd.order_id,
                                   ogd.order_number,
                                   ogd.technology_number,
                                   ogd.glass_child,
                                   GROUP_CONCAT(glass_child SEPARATOR ' ') AS concatenated_glass_child
                            from sd.order_glass_detail as ogd
                            where ogd.order_id = #{orderId}
                              and position(ogd.technology_number in #{technologyNumber})
                            GROUP BY order_id, order_number) as ogdc
                           on ogdc.order_id = ogd.order_id and ogdc.order_number = ogd.order_number and
                              ogdc.technology_number = ogd.technology_number
        where fc.process_id = #{processId}
          and position(fc.technology_number in #{technologyNumber})
          and ogdc.concatenated_glass_child is NOT null
        group by fc.process_id, fc.technology_number
    </select>
 
    <select id="selectorderOtherMoney">
        select *
        from sd.basic_other_money
        where id between 21 and 35
    </select>
 
    <select id="selectReworkPrintMp">
        select fc.id,
               fc.order_id,
               fc.process_id,
               o.customer_name,
               o.project,
               fc.order_number,
               ogd.technology_number,
               ogd.glass_address,
               pl.rework_num,
               pl.rework_area,
               pl.rework_team,
               pl.responsible_equipment,
               pl.responsible_personnel,
               pl.rework_type,
               pl.rework_reason,
               pl.rework_processes,
               od.product_name,
               ogd.glass_child,
               pl.reporting_work_id,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S01')) AS glassNumber
        from flow_card as fc
                 left join sd.order_glass_detail as ogd
                           on ogd.order_id = fc.order_id and ogd.order_number = fc.order_number and
                              ogd.technology_number = fc.technology_number
                 left join sd.order_detail as od on od.order_id = fc.order_id and od.order_number = fc.order_number
                 left join sd.`order` as o on o.order_id = fc.order_id
                 left join rework as pl on pl.order_id = fc.order_id and pl.process_id = fc.process_id and
                                           pl.order_sort = fc.order_number and
                                           pl.technology_number = fc.technology_number
        where  date(pl.create_time)>=#{selectTime1} and date(pl.create_time) &lt;= #{selectTime2}
        GROUP BY fc.process_id,fc.order_number, ogd.technology_number, pl.reporting_work_id
        order by pl.id desc, fc.process_id, ogd.technology_number
    </select>
 
    <select id="getDetailListLike">
        select fc.order_number,
               concat(IF(ROUND(ogd.child_width, 1) = FLOOR(ogd.child_width), FLOOR(ogd.child_width), ROUND(ogd.child_width, 1)), "*", IF(ROUND(child_height, 1) = FLOOR(child_height), FLOOR(child_height), ROUND(child_height, 1)))   as child_width,
               fc.quantity,
               round(ogd.total_area, 2)                                       as total_area,
               od.perimeter,
               if(od.bend_radius!=null || od.bend_radius!='',od.bend_radius,if(od.shape=2,JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S04')),'')) as bend_radius,
               concat(IFNULL(od.processing_note, ''), IFNULL(od.remarks, '')) as remarks,
               od.other_columns,
               round(ogd.child_width)                                         as width,
               round(ogd.child_height)                                        as height,
               pd.separation,
               fc.technology_number,
               IFNULL(JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S02')),'') as mapNumber,
               od.building_number
        from flow_card as fc
                 left join sd.order_glass_detail as ogd
                           on fc.order_id = ogd.order_id and fc.order_number = ogd.order_number and
                              fc.technology_number = ogd.technology_number
                 left join sd.order_detail as od on od.order_id = fc.order_id and od.order_number = fc.order_number
                 left join sd.product_detail as pd
                           on pd.prod_id = od.product_id and pd.glass_sort = ogd.technology_number
                 left join flow_card_sort as fcs
                           on fcs.process_id = fc.process_id and fcs.order_number = fc.order_number and
                              fcs.technology_number = fc.technology_number
                               and fcs.process = #{process}
        where fc.process_id = #{processId}
          and position(fc.technology_number in #{technologyNumber})
        group by fc.process_id, fc.order_number, fc.technology_number
        <choose>
            <!-- flashback = 1 时正序 -->
            <when test="flashback == 1">
                ORDER BY
                CASE
                WHEN fcs.sort IS NOT NULL AND fcs.sort &lt;&gt;  '' THEN fcs.sort
                ELSE fc.order_number
                END ASC
            </when>
            <!-- flashback != 1 时倒序 -->
            <otherwise>
                ORDER BY
                CASE
                WHEN fcs.sort IS NOT NULL AND fcs.sort &lt;&gt;  '' THEN fcs.sort
                ELSE fc.order_number
                END DESC
            </otherwise>
        </choose>
    </select>
 
    <select id="getDetailListMerge">
        select fc.order_number,
               concat(IF(ROUND(ogd.child_width, 1) = FLOOR(ogd.child_width), FLOOR(ogd.child_width), ROUND(ogd.child_width, 1)), "*", IF(ROUND(child_height, 1) = FLOOR(child_height), FLOOR(child_height), ROUND(child_height, 1)))   as child_width,
               sum(fc.quantity) as quantity,
               round(ogd.total_area, 2)                                       as total_area,
               od.perimeter,
               if(od.bend_radius!=null || od.bend_radius!='',od.bend_radius,if(od.shape=2,JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S04')),'')) as bend_radius,
               concat(IFNULL(od.processing_note, ''), IFNULL(od.remarks, '')) as remarks,
               od.other_columns,
               round(ogd.child_width)                                         as width,
               round(ogd.child_height)                                        as height,
               pd.separation,
               fc.technology_number,
               IFNULL(JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S02')),'') as mapNumber,
               od.building_number,
               fc.merge                                                         as merge
        from flow_card as fc
                 left join sd.order_glass_detail as ogd
                           on fc.order_id = ogd.order_id and fc.order_number = ogd.order_number and
                              fc.technology_number = ogd.technology_number
                 left join sd.order_detail as od on od.order_id = fc.order_id and od.order_number = fc.order_number
                 left join sd.product_detail as pd
                           on pd.prod_id = od.product_id and pd.glass_sort = ogd.technology_number
                 left join flow_card_sort as fcs
                           on fcs.process_id = fc.process_id and fcs.order_number = fc.order_number and
                              fcs.technology_number = fc.technology_number
                               and fcs.process = #{process}
        where fc.process_id = #{processId} and fc.`merge`=1
        group by fc.process_id, fc.order_number
        <choose>
            <!-- flashback = 1 时正序 -->
            <when test="flashback == 1">
                ORDER BY
                CASE
                WHEN fcs.sort IS NOT NULL AND fcs.sort &lt;&gt;  '' THEN fcs.sort
                ELSE fc.order_number
                END ASC
            </when>
            <!-- flashback != 1 时倒序 -->
            <otherwise>
                ORDER BY
                CASE
                WHEN fcs.sort IS NOT NULL AND fcs.sort &lt;&gt;  '' THEN fcs.sort
                ELSE fc.order_number
                END DESC
            </otherwise>
        </choose>
    </select>
 
    <select id="getDetailListLikes">
        select fc.order_number,
               concat(round(ogd.child_width), "*", round(ogd.child_height))   as child_width,
               count(*) as quantity,
               round(ogd.child_width*ogd.child_height*count(*)/1000000, 2)                                       as total_area,
               round((ogd.child_width+ogd.child_height)*2*count(*)/1000, 2)    as perimeter,
               if(od.shape=2,JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S04')),od.bend_radius) as bend_radius,
               concat(IFNULL(od.processing_note, ''), IFNULL(od.remarks, '')) as remarks,
               od.other_columns,
               round(ogd.child_width)                                         as width,
               round(ogd.child_height)                                        as height,
               pd.separation,
               fc.technology_number,
               IFNULL(JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S02')),'') as mapNumber,
               od.building_number
        from optimize_detail opt left join flow_card as fc on opt.process_id = fc.process_id and opt.order_sort = fc.order_number and
                                                              opt.layer = fc.technology_number
                                 left join sd.order_glass_detail as ogd
                                           on fc.order_id = ogd.order_id and fc.order_number = ogd.order_number and
                                              fc.technology_number = ogd.technology_number
                                 left join sd.order_detail as od on od.order_id = fc.order_id and od.order_number = fc.order_number
                                 left join sd.product_detail as pd
                                           on pd.prod_id = od.product_id and pd.glass_sort = ogd.technology_number
                                 left join flow_card_sort as fcs
                                           on fcs.process_id = fc.process_id and fcs.order_number = fc.order_number and
                                              fcs.technology_number = fc.technology_number
                                               and fcs.process = #{process}
        where opt.process_id = #{processId} and opt.project_no=#{printProject}
          and position(fc.technology_number in #{technologyNumber})
        group by fc.process_id, fc.order_number, fc.technology_number
        order by IF(fcs.sort != NULL or fcs.sort != '', fcs.sort, fc.order_number)
    </select>
 
    <select id="getPrimaryListMergeRefund">
        select o.customer_name,
               o.project,
               ogd.process,
               od.edging_type,
               ogdc.concatenated_glass_child                   as glass_child,
               od.product_name,
               o.processing_note,
               fc.process_id,
               pl.patch_num                                    as quantity,
               round(SUM(ogd.total_area), 2)                   as gross_area,
               sum(od.weight)                                  as weight,
               #{technologyNumber}                             as technologyNumber,
               concat(fc.process_id, '/', #{technologyNumber}) as processIdNumber
        from flow_card as fc
                 left join sd.order_glass_detail as ogd
                           on fc.order_id = ogd.order_id and fc.order_number = ogd.order_number and
                              fc.technology_number = ogd.technology_number
                 left join sd.order_detail as od on od.order_id = fc.order_id and od.order_number = fc.order_number
                 left join sd.`order` as o on o.order_id = fc.order_id
                 left join sd.product as p on p.id = od.product_id
                 left join (select ogd.order_id,
                                   ogd.order_number,
                                   ogd.technology_number,
                                   ogd.glass_child,
                                   GROUP_CONCAT(glass_child SEPARATOR ' ') AS concatenated_glass_child
                            from sd.order_glass_detail as ogd
                            where ogd.order_id = #{orderId}
                              and ogd.order_number = #{orderNumber}
                              and position(ogd.technology_number in #{technologyNumber})
                            GROUP BY order_id, order_number) as ogdc
                           on ogdc.order_id = ogd.order_id and ogdc.order_number = ogd.order_number and
                              ogdc.technology_number = ogd.technology_number
                 left join patch_log as pl on pl.process_id = fc.process_id and pl.order_sort = fc.order_number and
                                              pl.technology_number = fc.technology_number
        where fc.process_id = #{processId}
          and fc.order_number = #{orderNumber}
          and position(fc.technology_number in #{technologyNumber})
          and ogdc.concatenated_glass_child is NOT null
        group by fc.process_id, fc.technology_number
    </select>
 
    <select id="getDetailListRefund">
        select fc.order_number,
               concat(round(ogd.child_width), "*", round(ogd.child_height))   as child_width,
               sum(pl.patch_num)                                                 as quantity,
               round(ogd.total_area, 2)                                       as total_area,
               od.perimeter,
               if(od.bend_radius!=null || od.bend_radius!='',od.bend_radius,if(od.shape=2,JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S04')),'')) as bend_radius,
               concat(IFNULL(od.processing_note, ''), IFNULL(od.remarks, '')) as remarks,
               od.other_columns,
               round(ogd.child_width)                                         as width,
               round(ogd.child_height)                                        as height,
               pd.separation,
               fc.technology_number,
               pl.patch_type,
               pl.patch_reason,
               pl.patch_processes,
               pl.responsible_team,
               pl.responsible_personnel
        from flow_card as fc
                 left join sd.order_glass_detail as ogd
                           on fc.order_id = ogd.order_id and fc.order_number = ogd.order_number and
                              fc.technology_number = ogd.technology_number
                 left join sd.order_detail as od on od.order_id = fc.order_id and od.order_number = fc.order_number
                 left join sd.product_detail as pd
                           on pd.prod_id = od.product_id and pd.glass_sort = ogd.technology_number
                 left join patch_log as pl on pl.process_id = fc.process_id and pl.order_sort = fc.order_number and
                                              pl.technology_number = fc.technology_number
        where fc.process_id = #{processId}
          and fc.order_number = #{orderNumber}
          and position(fc.technology_number in #{technologyNumber})
          and pl.reporting_work_id = #{reportingWorkId}
        and pl.patch_reason = #{patchReason}
        group by fc.process_id, fc.order_number, fc.technology_number,pl.id
        order by IF(sort != NULL and sort != '', sort, fc.order_number)
    </select>
 
    <select id="getPrimaryListRefund">
        select o.customer_name,
               o.project,
               ogd.process,
               od.edging_type,
               ogd.glass_child,
               od.product_name,
               o.processing_note,
               fc.process_id,
               pl.patch_num                                    as quantity,
               round(SUM(ogd.total_area), 2)                   as gross_area,
               sum(od.weight)                                  as weight,
               #{technologyNumber}                             as technologyNumber,
               concat(fc.process_id, '/', #{technologyNumber}) as processIdNumber,
               dd.breakage_type,
               dd.breakage_reason,
               dd.responsible_process,
               dd.responsible_team,
               concat('对应我司单号', o.batch)                 AS otherRemarks,
               dd.responsible_personnel,
               #{mergeTechnologyNumber} as  mergeTechnologyNumber,
               pl.patch_id
        from flow_card as fc
                 left join sd.order_glass_detail as ogd
                           on fc.order_id = ogd.order_id and fc.order_number = ogd.order_number and
                              fc.technology_number = ogd.technology_number
                 left join sd.order_detail as od on od.order_id = fc.order_id and od.order_number = fc.order_number
                 left join sd.`order` as o on o.order_id = fc.order_id
                 left join sd.product as p on p.id = od.product_id
                 left join (select ogd.order_id,
                                   ogd.order_number,
                                   ogd.technology_number,
                                   ogd.glass_child,
                                   GROUP_CONCAT(glass_child SEPARATOR ' ') AS concatenated_glass_child
                            from sd.order_glass_detail as ogd
                            where ogd.order_id = #{orderId}
                              and ogd.order_number = #{orderNumber}
                              and position(ogd.technology_number in #{technologyNumber})
                            GROUP BY order_id, order_number) as ogdc
                           on ogdc.order_id = ogd.order_id and ogdc.order_number = ogd.order_number and
                              ogdc.technology_number = ogd.technology_number
                 left join patch_log as pl on pl.process_id = fc.process_id and pl.order_sort = fc.order_number and
                                              pl.technology_number = fc.technology_number
                 left join pp.reporting_work as rw on rw.order_id = fc.order_id and rw.process_id = fc.process_id
                 left join pp.damage_details as dd
                           on rw.reporting_work_id = dd.reporting_work_id and dd.order_number = fc.order_number and
                              dd.technology_number = fc.technology_number
        where fc.process_id = #{processId}
          and fc.order_number = #{orderNumber}
          and fc.technology_number = #{technologyNumber}
          and pl.reporting_work_id = #{reportingWorkId}
          and dd.breakage_reason = #{patchReason}
        group by fc.process_id, fc.technology_number
    </select>
 
    <select id="getDetailListLikeRefund">
        select fc.order_number,
               concat(round(ogd.child_width), "*", round(ogd.child_height))   as child_width,
               pl.patch_num                                                   as quantity,
               round(ogd.total_area, 2)                                       as total_area,
               od.perimeter,
               od.bend_radius,
               concat(IFNULL(od.processing_note, ''), IFNULL(od.remarks, '')) as remarks,
               od.other_columns,
               round(ogd.child_width)                                         as width,
               round(ogd.child_height)                                        as height,
               pd.separation,
               fc.technology_number
        from flow_card as fc
                 left join sd.order_glass_detail as ogd
                           on fc.order_id = ogd.order_id and fc.order_number = ogd.order_number and
                              fc.technology_number = ogd.technology_number
                 left join sd.order_detail as od on od.order_id = fc.order_id and od.order_number = fc.order_number
                 left join sd.product_detail as pd
                           on pd.prod_id = od.product_id and pd.glass_sort = ogd.technology_number
                 left join patch_log as pl on pl.process_id = fc.process_id and pl.order_sort = fc.order_number and
                                              pl.technology_number = fc.technology_number
        where fc.process_id = #{processId}
          and fc.order_number = #{orderNumber}
          and position(fc.technology_number in #{technologyNumber})
          and pl.reporting_work_id = #{reportingWorkId}
        group by fc.process_id, fc.order_number, fc.technology_number
        order by IF(sort != NULL and sort != '', sort, fc.order_number)
    </select>
 
    <select id="getPrimaryListRework">
        select o.customer_name,
               o.project,
               ogd.process,
               od.edging_type,
               ogd.glass_child,
               od.product_name,
               o.processing_note,
               fc.process_id,
               pl.rework_num                                   as quantity,
               round(SUM(ogd.total_area), 2)                   as gross_area,
               sum(od.weight)                                  as weight,
               #{technologyNumber}                             as technologyNumber,
               concat(fc.process_id, '/', #{technologyNumber}) as processIdNumber,
               dd.breakage_type,
               dd.breakage_reason,
               dd.responsible_process,
               dd.responsible_team,
               concat('对应我司单号', o.batch)                 AS otherRemarks,
               dd.responsible_personnel,
               pl.rework_id as  patch_id
        from flow_card as fc
                 left join sd.order_glass_detail as ogd
                           on fc.order_id = ogd.order_id and fc.order_number = ogd.order_number and
                              fc.technology_number = ogd.technology_number
                 left join sd.order_detail as od on od.order_id = fc.order_id and od.order_number = fc.order_number
                 left join sd.`order` as o on o.order_id = fc.order_id
                 left join sd.product as p on p.id = od.product_id
                 left join (select ogd.order_id,
                                   ogd.order_number,
                                   ogd.technology_number,
                                   ogd.glass_child,
                                   GROUP_CONCAT(glass_child SEPARATOR ' ') AS concatenated_glass_child
                            from sd.order_glass_detail as ogd
                            where ogd.order_id = #{orderId}
                              and ogd.order_number = #{orderNumber}
                              and position(ogd.technology_number in #{technologyNumber})
                            GROUP BY order_id, order_number) as ogdc
                           on ogdc.order_id = ogd.order_id and ogdc.order_number = ogd.order_number and
                              ogdc.technology_number = ogd.technology_number
                 left join rework as pl on pl.process_id = fc.process_id and pl.order_sort = fc.order_number and
                                           pl.technology_number = fc.technology_number
                 left join pp.reporting_work as rw on rw.order_id = fc.order_id and rw.process_id = fc.process_id
                 left join pp.damage_details as dd
                           on rw.reporting_work_id = dd.reporting_work_id and dd.order_number = fc.order_number and
                              dd.technology_number = fc.technology_number
        where fc.process_id = #{processId}
          and fc.order_number = #{orderNumber}
          and fc.technology_number = #{technologyNumber}
          and rw.reporting_work_id = #{reportingWorkId}
        group by fc.process_id, fc.technology_number
    </select>
 
    <select id="getDetailListRework">
        select fc.order_number,
               concat(round(ogd.child_width), "*", round(ogd.child_height)) as child_width,
               (pl.rework_num)                                              as quantity,
               round(ogd.total_area, 2)                                     as total_area,
               od.perimeter,
               if(od.shape=2,JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S04')),od.bend_radius) as bend_radius,
               concat(od.processing_note, od.remarks)                       as remarks,
               od.other_columns,
               round(ogd.child_width)                                       as width,
               round(ogd.child_height)                                      as height,
               pd.separation,
               fc.technology_number,
               pl.rework_type as patch_type,
               pl.rework_reason as patch_reason,
               pl.rework_processes as patch_processes,
               pl.responsible_team,
               pl.rework_team,
               pl.responsible_personnel
        from flow_card as fc
                 left join sd.order_glass_detail as ogd
                           on fc.order_id = ogd.order_id and fc.order_number = ogd.order_number and
                              fc.technology_number = ogd.technology_number
                 left join sd.order_detail as od on od.order_id = fc.order_id and od.order_number = fc.order_number
                 left join sd.product_detail as pd
                           on pd.prod_id = od.product_id and pd.glass_sort = ogd.technology_number
                 left join rework as pl on pl.process_id = fc.process_id and pl.order_sort = fc.order_number and
                                           pl.technology_number = fc.technology_number
        where fc.process_id = #{processId}
          and fc.order_number = #{orderNumber}
          and position(fc.technology_number in #{technologyNumber})
          and pl.reporting_work_id = #{reportingWorkId}
        group by fc.process_id, fc.order_number, fc.technology_number
        order by IF(sort != NULL and sort != '', sort, fc.order_number)
    </select>
 
    <select id="getPrimaryListMergeRework">
        select o.customer_name,
               o.project,
               ogd.process,
               od.edging_type,
               ogdc.concatenated_glass_child                   as glass_child,
               od.product_name,
               o.processing_note,
               fc.process_id,
               pl.rework_num                                   as quantity,
               round(SUM(ogd.total_area), 2)                   as gross_area,
               sum(od.weight)                                  as weight,
               #{technologyNumber}                             as technologyNumber,
               concat(fc.process_id, '/', #{technologyNumber}) as processIdNumber
        from flow_card as fc
                 left join sd.order_glass_detail as ogd
                           on fc.order_id = ogd.order_id and fc.order_number = ogd.order_number and
                              fc.technology_number = ogd.technology_number
                 left join sd.order_detail as od on od.order_id = fc.order_id and od.order_number = fc.order_number
                 left join sd.`order` as o on o.order_id = fc.order_id
                 left join sd.product as p on p.id = od.product_id
                 left join (select ogd.order_id,
                                   ogd.order_number,
                                   ogd.technology_number,
                                   ogd.glass_child,
                                   GROUP_CONCAT(glass_child SEPARATOR ' ') AS concatenated_glass_child
                            from sd.order_glass_detail as ogd
                            where ogd.order_id = #{orderId}
                              and ogd.order_number = #{orderNumber}
                              and position(ogd.technology_number in #{technologyNumber})
                            GROUP BY order_id, order_number) as ogdc
                           on ogdc.order_id = ogd.order_id and ogdc.order_number = ogd.order_number and
                              ogdc.technology_number = ogd.technology_number
                 left join rework as pl on pl.process_id = fc.process_id and pl.order_sort = fc.order_number and
                                           pl.technology_number = fc.technology_number
        where fc.process_id = #{processId}
          and fc.order_number = #{orderNumber}
          and position(fc.technology_number in #{technologyNumber})
          and ogdc.concatenated_glass_child is NOT null
        group by fc.process_id, fc.technology_number
    </select>
 
    <select id="getDetailListLikeRework">
        select fc.order_number,
               concat(round(ogd.child_width), "*", round(ogd.child_height)) as child_width,
               pl.rework_num                                                as quantity,
               round(ogd.total_area, 2)                                     as total_area,
               od.perimeter,
               od.bend_radius,
               concat(od.processing_note, od.remarks)                       as remarks,
               od.other_columns,
               round(ogd.child_width)                                       as width,
               round(ogd.child_height)                                      as height,
               pd.separation,
               fc.technology_number
        from flow_card as fc
                 left join sd.order_glass_detail as ogd
                           on fc.order_id = ogd.order_id and fc.order_number = ogd.order_number and
                              fc.technology_number = ogd.technology_number
                 left join sd.order_detail as od on od.order_id = fc.order_id and od.order_number = fc.order_number
                 left join sd.product_detail as pd
                           on pd.prod_id = od.product_id and pd.glass_sort = ogd.technology_number
                 left join rework as pl on pl.process_id = fc.process_id and pl.order_sort = fc.order_number and
                                           pl.technology_number = fc.technology_number
        where fc.process_id = #{processId}
          and fc.order_number = #{orderNumber}
          and position(fc.technology_number in #{technologyNumber})
          and pl.reporting_work_id = #{reportingWorkId}
        group by fc.process_id, fc.order_number, fc.technology_number
        order by IF(sort != NULL or sort != '', sort, fc.order_number)
    </select>
 
    <select id="getPrintCustomDataSemi">
        select o.order_id                                            as orderId,
               project,
               customer_id                                           as customerId,
               o.customer_name                                       as customerName,
               order_type                                            as orderType,
               order_classify                                        as orderClassify,
               batch,
               o.icon,
               pack_type                                             as packType,
               delivery_date                                         as deliveryDate,
               al_type                                               as alType,
               money,
               contract_id                                           as contractId,
               customer_batch                                           customerBatch,
               contacts,
               delivery_address                                      as deliveryAddress,
               od.processing_note                                    as processingNote,
               round(ogd.child_width)                                as width,
               round(ogd.child_height)                               as height,
               fc.quantity,
               CONCAT(round(ogd.child_width)  , ' X ', round(ogd.child_height)   ,' = ',fc.quantity )           as size,
               od.order_number                                       as orderNumber,
               fc.technology_number                                  as technologyNumber,
               od.building_number                                    as buildingNumber,
               od.product_name                                       as productName,
               od.edging_type                                        as edgingType,
               od.remarks,
               c.customer_abbreviation                               as customerAbbreviation,
               p.product_abbreviation                                as productAbbreviation,
               CONCAT(fc.process_id, '/', fc.technology_number)      as processId,
               o.create_time                                         as createTime,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S01')) AS glassNumber,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S02')) AS figureNumber,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S03')) AS colourCeramicGlaze,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S04')) AS remarks1,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S05')) AS remarks2,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S06')) AS remarks3,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S07')) AS remarks4,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S08')) AS remarks5,
               p.remarks                                             as filmNumber,
               od.bend_radius                                        as bendRadius,
               ogd.glass_child                                       as glassChild,
               ogd.glass_address                                     as glassAddress,
               JSON_UNQUOTE(JSON_EXTRACT(pd.separation, '$.color'))  AS color
        from sd.order as o
                 left join sd.order_detail as od on o.order_id = od.order_id
                 left join flow_card as fc on o.order_id = fc.order_id and
                                              od.order_number = fc.order_number
                 left join sd.product as p on p.id = od.product_id
                 left join sd.customer as c on c.id = o.customer_id
                 left join sd.product_detail as pd on pd.prod_id = p.id and pd.sort_num = od.order_number
                 left join sd.order_glass_detail ogd
                           on ogd.order_id = o.order_id and ogd.order_number = od.order_number and
                              ogd.technology_number = fc.technology_number
                 left join flow_card_sort as fcs
                           on fcs.process_id = fc.process_id and fcs.order_number = fc.order_number and
                              fcs.technology_number = fc.technology_number
                               and fcs.process = #{process}
        where fc.process_id = #{processId}
          and position(fc.technology_number in #{technologyNumber})
        group by fc.process_id,od.order_number, ogd.technology_number, ogd.child_width, ogd.child_height
        order by IF(fcs.sort != NULL or fcs.sort != '', fcs.sort, fc.order_number)
    </select>
 
    <select id="selectPrintNotMp">
        select fc.id,
               fc.order_id,
               fc.process_id,
               o.customer_name,
               o.project,
               fc.order_number,
               ogd.technology_number,
               ogd.glass_address,
               sum(fc.quantity)                                                          as quantity,
               round(sum(ogd.child_width * ogd.child_height * fc.quantity / 1000000), 2) as total_area,
               od.product_name,
               ogd.glass_child,
               fc.founder,
               date(fc.splitFrame_time) as splitFrame_time,
            /* if(fc.print_status=0,'未打印','已打印') as  print_status*/
               fc.print_status,
               ogd.process,
               merge
        from flow_card as fc
                 left join sd.order_glass_detail as ogd
                           on ogd.order_id = fc.order_id and ogd.order_number = fc.order_number and
                              ogd.technology_number = fc.technology_number
                 left join sd.order_detail as od on od.order_id = fc.order_id and od.order_number = fc.order_number
                 left join sd.`order` as o on o.order_id = fc.order_id
        where fc.order_id = #{orderId}
        GROUP BY fc.process_id, ogd.technology_number
        order by fc.process_id, ogd.technology_number
    </select>
 
    <select id="selectPrintNotMergeMp">
        select *
        from ((select fc.id,
                      fc.order_id,
                      fc.process_id,
                      o.customer_name,
                      o.project,
                      fc.order_number,
                      ogd.technology_number,
                      ogd.glass_address,
                      sum(od.quantity)         as quantity,
                      sum(ogd.total_area)      as total_area,
                      od.product_name,
                      ogd.glass_child,
                      fc.founder,
                      date(fc.splitFrame_time) as splitFrame_time,
                   /* if(fc.print_status=0,'未打印','已打印') as  print_status*/
                      fc.print_status,
                      ogd.process
               from flow_card as fc
                        left join sd.order_glass_detail as ogd
                                  on ogd.order_id = fc.order_id and ogd.order_number = fc.order_number and
                                     ogd.technology_number = fc.technology_number
                        left join sd.order_detail as od
                                  on od.order_id = fc.order_id and od.order_number = fc.order_number
                        left join sd.`order` as o on o.order_id = fc.order_id
               where fc.order_id = #{orderId}
               GROUP BY fc.process_id, ogd.technology_number
               order by fc.process_id, ogd.technology_number)
 
              UNION
 
              (select fc.id,
                      fc.order_id,
                      fc.process_id,
                      o.customer_name,
                      o.project,
                      ogdss.technology_number,
                      ogd.glass_address,
                      ROUND(sum(fc.quantity) / (count(DISTINCT fc.technology_number))) as quantity,
                      sum(ogd.total_area)                                              as total_area,
                      # SUM(ogd.child_width*child_height*fc.quantity/(count(DISTINCT ogd.technology_number))) as total_area,
                      od.product_name,
                      ogdss.concatenated_glass_child                                   as glass_child,
                      fc.founder,
                      date(fc.splitFrame_time)                                         as splitFrame_time,
                      fc.print_status,
                      processed_part                                                   as process
 
               from flow_card as fc
                        left join sd.order_glass_detail as ogd
                                  on ogd.order_id = fc.order_id and ogd.order_number = fc.order_number and
                                     ogd.technology_number = fc.technology_number
                        left join sd.order_detail as od
                                  on od.order_id = fc.order_id and od.order_number = fc.order_number
                        left join sd.`order` as o on o.order_id = fc.order_id
                        left join (select ogds.order_id,
                                          ogds.order_number,
                                          GROUP_CONCAT(ogds.technology_number SEPARATOR '') AS technology_number,
                                          ogds.glass_child,
                                          GROUP_CONCAT(ogds.glass_child SEPARATOR ' ')      AS concatenated_glass_child,
                                          SUBSTRING(process, LOCATE('夹胶', process))       AS processed_part
                                   from sd.order_glass_detail as ogds
                                   where ogds.order_id = #{orderId}
                                     and LOCATE('夹胶', ogds.process) > 0
                                   GROUP BY order_id, order_number, ogds.group) as ogdss
                                  on fc.order_id = ogdss.order_id and ogdss.order_number = fc.order_number
               where fc.order_id = #{orderId}
               GROUP BY fc.process_id, ogdss.technology_number
               order by fc.process_id)
              UNION
              (select fc.id,
                      fc.order_id,
                      fc.process_id,
                      o.customer_name,
                      o.project,
                      ogdss.technology_number,
                      ogd.glass_address,
                      ROUND(sum(fc.quantity) / (count(DISTINCT fc.technology_number))) as quantity,
                      sum(ogd.total_area)                                              as total_area,
                      od.product_name,
                      ogdss.concatenated_glass_child                                   as glass_child,
                      fc.founder,
                      date(fc.splitFrame_time)                                         as splitFrame_time,
                      fc.print_status,
                      processed_part                                                   as process
 
               from flow_card as fc
                        left join sd.order_glass_detail as ogd
                                  on ogd.order_id = fc.order_id and ogd.order_number = fc.order_number and
                                     ogd.technology_number = fc.technology_number
                        left join sd.order_detail as od
                                  on od.order_id = fc.order_id and od.order_number = fc.order_number
                        left join sd.`order` as o on o.order_id = fc.order_id
                        left join (select ogds.order_id,
                                          ogds.order_number,
                                          GROUP_CONCAT(pds.glass_sort SEPARATOR '')           AS technology_number,
                                          ogds.glass_child,
                                          GROUP_CONCAT(ogds.glass_child SEPARATOR ' ')        AS concatenated_glass_child,
                                          SUBSTRING(pds.process, LOCATE('中空', pds.process)) AS processed_part
                                   from sd.order_glass_detail as ogds
                                            left join sd.order_detail as ods
                                                      on ods.order_id = ogds.order_id and ods.order_number = ogds.order_number
                                            left join sd.product_detail as pds on pds.prod_id = ods.product_id and
                                                                                  pds.glass_sort =
                                                                                  ogds.technology_number
                                   where ogds.order_id = #{orderId}
                                   GROUP BY order_id, order_number) as ogdss
                                  on fc.order_id = ogdss.order_id and ogdss.order_number = fc.order_number
               where fc.order_id = #{orderId}
               GROUP BY fc.process_id
               order by fc.process_id)) AS combined_results
        where process is not null
          and process != ""
    </select>
 
    <select id="getRepairPrintCustomDataSemi">
        select o.order_id                                            as orderId,
               o.project,
               o.customer_id                                         as customerId,
               o.customer_name                                       as customerName,
               o.order_type                                          as orderType,
               o.order_classify                                      as orderClassify,
               o.batch,
               o.icon,
               o.pack_type                                           as packType,
               o.delivery_date                                       as deliveryDate,
               o.al_type                                             as alType,
               o.money,
               contract_id                                           as contractId,
               customer_batch                                           customerBatch,
               contacts,
               o.delivery_address                                    as deliveryAddress,
               od.processing_note                                    as processingNote,
               round(ogd.child_width)                                as width,
               round(ogd.child_height)                               as height,
               pl.patch_num                                          as quantity,
               pl.order_sort                                         as orderNumber,
               pl.technology_number                                  as technologyNumber,
               od.building_number                                    as buildingNumber,
               od.product_name                                       as productName,
               od.edging_type                                        as edgingType,
               p.remarks,
               c.customer_abbreviation                               as customerAbbreviation,
               p.product_abbreviation                                as productAbbreviation,
               CONCAT(fc.process_id, '/', fc.technology_number)      as processId,
               o.create_time                                         as createTime,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S01')) AS glassNumber,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S02')) AS figureNumber,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S03')) AS colourCeramicGlaze,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S04')) AS remarks1,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S05')) AS remarks2,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S06')) AS remarks3,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S07')) AS remarks4,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S08')) AS remarks5,
               p.remarks                                             as filmNumber,
               od.bend_radius                                        as bendRadius,
               ogd.glass_child                                       as glassChild,
               ogd.glass_address                                     as glassAddress,
               JSON_UNQUOTE(JSON_EXTRACT(pd.separation, '$.color'))  AS color,
               CONCAT(
                       TRIM(TRAILING '.' FROM TRIM(TRAILING '0' FROM CAST(ogd.child_width AS CHAR))),
                       ' X ',
                       TRIM(TRAILING '.' FROM TRIM(TRAILING '0' FROM CAST(ogd.child_height AS CHAR))),
                       ' = ',pl.patch_num   )      as size,
 
               CONCAT(
                       od.order_number,')  ',
                       TRIM(TRAILING '.' FROM TRIM(TRAILING '0' FROM CAST(ogd.child_width AS CHAR))),
                       ' X ',
                       TRIM(TRAILING '.' FROM TRIM(TRAILING '0' FROM CAST(ogd.child_height AS CHAR))),
                       ' = ',pl.patch_num   )      as numberSize
        from sd.order as o
                 left join sd.order_detail as od on o.order_id = od.order_id
                 left join flow_card as fc on o.order_id = fc.order_id and
                                              od.order_number = fc.order_number
                 left join patch_log as pl on pl.process_id = fc.process_id and pl.order_sort = fc.order_number and
                                              pl.technology_number = fc.technology_number
                 left join sd.product as p on p.id = od.product_id
                 left join sd.customer as c on c.id = o.customer_id
                 left join sd.product_detail as pd on pd.prod_id = p.id and pd.sort_num = od.order_number
                 left join sd.order_glass_detail ogd
                           on ogd.order_id = o.order_id and ogd.order_number = od.order_number and
                              ogd.technology_number = fc.technology_number
        where pl.process_id = #{processId}
          and pl.order_sort=#{orderNumber}
          and pl.technology_number = #{technologyNumber}
          and pl.reporting_work_id = #{reportingWorkId}
        group by od.order_number, width, height
        order by IF(fc.sort != NULL or fc.sort != '', fc.sort, pl.order_sort)
    </select>
 
    <select id="selectPrintAllMp">
        select *
        from ((select fc.id,
                      fc.order_id,
                      fc.process_id,
                      o.customer_name,
                      o.project,
                      ogd.technology_number,
                      ogd.glass_address,
                      sum(fc.quantity)                                                          as quantity,
                      round(sum(ogd.child_width * ogd.child_height * fc.quantity / 1000000), 2) as total_area,
                      od.product_name,
                      ogd.glass_child,
                      fc.founder,
                      date(fc.splitFrame_time)                                                  as splitFrame_time,
                   /* if(fc.print_status=0,'未打印','已打印') as  print_status*/
                      fc.print_status,
                      ogd.process,
                      merge
               from flow_card as fc
                        left join sd.order_glass_detail as ogd
                                  on ogd.order_id = fc.order_id and ogd.order_number = fc.order_number and
                                     ogd.technology_number = fc.technology_number
                        left join sd.order_detail as od
                                  on od.order_id = fc.order_id and od.order_number = fc.order_number
                        left join sd.`order` as o on o.order_id = fc.order_id
               where fc.order_id = #{orderId}
               GROUP BY fc.process_id, ogd.technology_number
               order by fc.process_id, ogd.technology_number)
 
              UNION
 
              (select fc.id,
                      fc.order_id,
                      fc.process_id,
                      o.customer_name,
                      o.project,
                      ogdss.technology_number,
                      ogd.glass_address,
                      ROUND(sum(fc.quantity) / (count(DISTINCT fc.technology_number))) as quantity,
                      sum(ogd.total_area)                                              as total_area,
                      # SUM(ogd.child_width*child_height*fc.quantity/(count(DISTINCT ogd.technology_number))) as total_area,
                      od.product_name,
                      ogdss.concatenated_glass_child                                   as glass_child,
                      fc.founder,
                      date(fc.splitFrame_time)                                         as splitFrame_time,
                      fc.print_status,
                      processed_part                                                   as process,
                      merge
 
               from flow_card as fc
                        left join sd.order_glass_detail as ogd
                                  on ogd.order_id = fc.order_id and ogd.order_number = fc.order_number and
                                     ogd.technology_number = fc.technology_number
                        left join sd.order_detail as od
                                  on od.order_id = fc.order_id and od.order_number = fc.order_number
                        left join sd.`order` as o on o.order_id = fc.order_id
                        left join (select ogds.order_id,
                                          ogds.order_number,
                                          GROUP_CONCAT(ogds.technology_number SEPARATOR '') AS technology_number,
                                          ogds.glass_child,
                                          GROUP_CONCAT(ogds.glass_child SEPARATOR '+')      AS concatenated_glass_child,
                                          SUBSTRING(process, LOCATE(bd.basic_name, process))       AS processed_part
                                   from sd.order_glass_detail as ogds
                                  left join sd.basic_data as bd on bd.nickname='stepC'
                                   where ogds.order_id = #{orderId}
                                     and LOCATE(bd.basic_name, ogds.process) > 0
                                   GROUP BY order_id, order_number, ogds.group) as ogdss
                                  on fc.order_id = ogdss.order_id and ogdss.order_number = fc.order_number
               where fc.order_id = #{orderId}
               GROUP BY fc.process_id, ogdss.technology_number
               order by fc.process_id)
              UNION
              (select fc.id,
                      fc.order_id,
                      fc.process_id,
                      o.customer_name,
                      o.project,
                      ogdss.technology_number,
                      ogd.glass_address,
                      ROUND(sum(fc.quantity) / (count(DISTINCT fc.technology_number))) as quantity,
                      sum(ogd.total_area)                                              as total_area,
                      od.product_name,
                      ogdss.concatenated_glass_child                                   as glass_child,
                      fc.founder,
                      date(fc.splitFrame_time)                                         as splitFrame_time,
                      fc.print_status,
                      processed_part                                                   as process,
                      merge
 
               from flow_card as fc
                        left join sd.order_glass_detail as ogd
                                  on ogd.order_id = fc.order_id and ogd.order_number = fc.order_number and
                                     ogd.technology_number = fc.technology_number
                        left join sd.order_detail as od
                                  on od.order_id = fc.order_id and od.order_number = fc.order_number
                        left join sd.`order` as o on o.order_id = fc.order_id
                        left join (select ogds.order_id,
                                          ogds.order_number,
                                          GROUP_CONCAT(pds.glass_sort SEPARATOR '')           AS technology_number,
                                          ogds.glass_child,
                                          GROUP_CONCAT(ogds.glass_child SEPARATOR '+')        AS concatenated_glass_child,
                                          SUBSTRING(pds.process, LOCATE(bd.basic_name, pds.process)) AS processed_part
                                   from sd.order_glass_detail as ogds
                                            left join sd.order_detail as ods
                                                      on ods.order_id = ogds.order_id and ods.order_number = ogds.order_number
                                            left join sd.product_detail as pds on pds.prod_id = ods.product_id and
                                                                                  pds.glass_sort =
                                                                                  ogds.technology_number
                                            left join sd.basic_data as bd on bd.nickname='stepD'
                                   where ogds.order_id = #{orderId}
                                   GROUP BY order_id, order_number) as ogdss
                                  on fc.order_id = ogdss.order_id and ogdss.order_number = fc.order_number
               where fc.order_id = #{orderId}
               GROUP BY fc.process_id
               order by fc.process_id)) AS combined_results
        where process is not null
          and process != ""
        GROUP BY order_id, process_id, technology_number, process
        order by order_id, process_id, length(technology_number)
    </select>
 
    <insert id="printAddSortMp">
        insert into flow_card_sort (process_id, order_number, technology_number, process, sort, create_time)
        values (#{processId}, #{orderNumber}, #{technologyNumber}, #{process}, #{sort}, now())
    </insert>
    <select id="printAddSortCountMp">
        select count(*)
        from flow_card_sort
        where process_id = #{processId}
          and order_number = #{orderNumber}
          and technology_number = #{technologyNumber}
          and process = #{process}
    </select>
    <update id="printUpdateSortMp">
        update flow_card_sort
        set sort = #{sort}
        where process_id = #{processId}
          and order_number = #{orderNumber}
          and technology_number = #{technologyNumber}
          and process = #{process}
    </update>
 
    <select id="getPrimaryListLimt">
        select o.customer_name,
               o.project,
               #{process}                                         process,
               od.edging_type,
               #{glassChild}                                   as glass_child,
               od.product_name,
               o.processing_note,
               fc.process_id,
               SUM(od.quantity)                                as quantity,
               round(SUM(ogd.total_area), 2)                   as gross_area,
               sum(od.weight)                                  as weight,
               #{technologyNumber}                             as technologyNumber,
               concat(fc.process_id, '/', #{technologyNumber}) as processIdNumber,
               concat('对应我司单号', o.batch)                 AS otherRemarks,
               fc.technology_number                            as qrcode
        from flow_card as fc
                 left join sd.order_glass_detail as ogd
                           on fc.order_id = ogd.order_id and fc.order_number = ogd.order_number and
                              fc.technology_number = ogd.technology_number
                 left join sd.order_detail as od on od.order_id = fc.order_id and od.order_number = fc.order_number
                 left join sd.`order` as o on o.order_id = fc.order_id
                 left join sd.product as p on p.id = od.product_id
                 left join (select ogd.order_id,
                                   ogd.order_number,
                                   ogd.technology_number,
                                   ogd.glass_child,
                                   GROUP_CONCAT(glass_child SEPARATOR ' ') AS concatenated_glass_child
                            from sd.order_glass_detail as ogd
                            where ogd.order_id = #{orderId}
                              and position(ogd.technology_number in #{technologyNumber})
                            GROUP BY order_id, order_number) as ogdc
                           on ogdc.order_id = ogd.order_id and ogdc.order_number = ogd.order_number and
                              ogdc.technology_number = ogd.technology_number
        where fc.process_id = #{processId}
          and position(fc.technology_number in #{technologyNumber})
        group by fc.process_id
        limit 1
    </select>
 
    <select id="selectPrintDetailsMp">
        select fc.id,
               fc.order_id,
               fc.process_id,
               o.customer_name,
               o.project,
               /*ogd.technology_number,*/
               ogd.glass_address,
               (fc.quantity)                                                          as quantity,
               (fc.quantity)                                                          as printQuantity,
               round((ogd.child_width * ogd.child_height * fc.quantity / 1000000), 2) as total_area,
               od.product_name,
               ogd.glass_child,
               fc.founder,
               date(fc.splitFrame_time)                                               as splitFrame_time,
            /* if(fc.print_status=0,'未打印','已打印') as  print_status*/
               ifnull(fc.print_number,0) as  print_status,
               ogd.process,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S01'))                  AS glassNumber,
               od.order_number,
               od.width,
               od.height
        from flow_card as fc
                 left join sd.order_glass_detail as ogd
                           on ogd.order_id = fc.order_id and ogd.order_number = fc.order_number and
                              ogd.technology_number = fc.technology_number
                 left join sd.order_detail as od on od.order_id = fc.order_id and od.order_number = fc.order_number
                 left join sd.`order` as o on o.order_id = fc.order_id
        where fc.order_id = #{orderId}
        GROUP BY fc.process_id, od.order_number
        order by fc.process_id, od.order_number
    </select>
 
    <select id="selectPrintDetailsMp1">
        select fc.id,
               fc.order_id,
               fc.process_id,
               o.customer_name,
               o.project,
               ogd.technology_number,
               ogd.glass_address,
               (fc.quantity)                                                          as quantity,
               (fc.quantity)                                                          as printQuantity,
               round((ogd.child_width * ogd.child_height * fc.quantity / 1000000), 2) as total_area,
               od.product_name,
               ogd.glass_child,
               fc.founder,
               date(fc.splitFrame_time)                                               as splitFrame_time,
            /* if(fc.print_status=0,'未打印','已打印') as  print_status*/
               ifnull(fc.print_number,0) as  print_status,
               ogd.process,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S01'))                  AS glassNumber,
               od.order_number,
               ogd.child_width as width,
               ogd.child_height as height,
                ifnull(JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S01')),'') AS glassNumber,
                JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S01')) AS S01,
                JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S02')) AS S02,
                JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S03')) AS S03,
                JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S04')) AS S04,
                JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S05')) AS S05
        from flow_card as fc
                 left join sd.order_glass_detail as ogd
                           on ogd.order_id = fc.order_id and ogd.order_number = fc.order_number and
                              ogd.technology_number = fc.technology_number
                 left join sd.order_detail as od on od.order_id = fc.order_id and od.order_number = fc.order_number
                 left join sd.`order` as o on o.order_id = fc.order_id
        where fc.order_id = #{orderId}
        GROUP BY fc.process_id, od.order_number,fc.technology_number
        order by fc.process_id, od.order_number,fc.technology_number
    </select>
 
    <select id="getPrintCustomDataDetails">
        select o.order_id                                            as orderId,
               project,
               customer_id                                           as customerId,
               o.customer_name                                       as customerName,
               order_type                                            as orderType,
               order_classify                                        as orderClassify,
               batch,
               o.icon,
               pack_type                                             as packType,
               delivery_date                                         as deliveryDate,
               al_type                                               as alType,
               money,
               contract_id                                           as contractId,
               customer_batch                                           customerBatch,
               contacts,
               delivery_address                                      as deliveryAddress,
               od.processing_note                                    as processingNote,
               width,
               height,
               #{printQuantity}                                      as quantity,
               CONCAT(
                   TRIM(TRAILING '.' FROM TRIM(TRAILING '0' FROM CAST(width AS CHAR))),
                   ' X ',
                   TRIM(TRAILING '.' FROM TRIM(TRAILING '0' FROM CAST(height AS CHAR))),
                   ' = ',#{printQuantity} )      as size,
 
               CONCAT(
                   od.order_number,')      ',
                       TRIM(TRAILING '.' FROM TRIM(TRAILING '0' FROM CAST(width AS CHAR))),
                       ' X ',
                       TRIM(TRAILING '.' FROM TRIM(TRAILING '0' FROM CAST(height AS CHAR))),
                       ' = ',#{printQuantity} )      as numberSize,
               CONCAT(
                       od.order_number,')','   ',
                       TRIM(TRAILING '.' FROM TRIM(TRAILING '0' FROM CAST(width AS CHAR))),
                       ' X ',
                       TRIM(TRAILING '.' FROM TRIM(TRAILING '0' FROM CAST(height AS CHAR))))      as numberSizeQuantity,
               od.order_number                                       as orderNumber,
               fc.technology_number                                  as technologyNumber,
               od.building_number                                    as buildingNumber,
               od.product_name                                       as productName,
               od.edging_type                                        as edgingType,
               od.remarks,
               c.customer_abbreviation                               as customerAbbreviation,
               p.product_abbreviation                                as productAbbreviation,
               fc.process_id                                         as processId,
               SUBSTRING(fc.process_id,12  )                                        as processIdAD ,/*-流程卡简写-*/
               o.create_time                                         as createTime,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S01')) AS glassNumber,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S02')) AS figureNumber,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S03')) AS colourCeramicGlaze,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S04')) AS remarks1,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S05')) AS remarks2,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S06')) AS remarks3,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S07')) AS remarks4,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S08')) AS remarks5,
               p.remarks                                             as filmNumber,
               od.bend_radius                                        as bendRadius,
               od.other_columns,
               ogd.glass_child                                       as glassChild,
               ogd.glass_address                                     as glassAddress,
               JSON_UNQUOTE(JSON_EXTRACT(pd.separation, '$.color'))  AS color,
               '文本' as custom1,
               '文本' as custom2,
               '文本' as custom3,
               '文本' as custom4,
               '文本' as custom5,
               od.quantity
        from sd.order as o
                 left join sd.order_detail as od on o.order_id = od.order_id
                 left join flow_card as fc on o.order_id = fc.order_id and
                                              od.order_number = fc.order_number
                 left join sd.product as p on p.id = od.product_id
                 left join sd.customer as c on c.id = o.customer_id
                 left join sd.product_detail as pd on pd.prod_id = p.id and pd.sort_num = od.order_number and
                                                      pd.glass_sort = fc.technology_number
                 left join sd.order_glass_detail as ogd
                           on ogd.order_id = fc.order_id and ogd.order_number = fc.order_number and
                              ogd.technology_number = fc.technology_number
        where fc.process_id = #{processId}
          and fc.order_number = #{orderNumber}
        group by fc.process_id,od.order_number, width, height
        order by fc.process_id
    </select>
 
    <select id="getPrintCustomDataProjectNo">
        select
            o.order_id                                            as orderId,
            project,
            customer_id                                           as customerId,
            o.customer_name                                       as customerName,
            order_type                                            as orderType,
            order_classify                                        as orderClassify,
            batch,
            o.icon,
            pack_type                                             as packType,
            delivery_date                                         as deliveryDate,
            al_type                                               as alType,
            money,
            contract_id                                           as contractId,
            customer_batch                                           customerBatch,
            contacts,
            delivery_address                                      as deliveryAddress,
            od.processing_note                                    as processingNote,
            od.width,
            od.height,
            fc.quantity as flowQuantity,
            od.order_number                                       as orderNumber,
            fc.technology_number                                  as technologyNumber,
            od.building_number                                    as buildingNumber,
            od.product_name                                       as productName,
            od.edging_type                                        as edgingType,
            od.remarks,
            c.customer_abbreviation                               as customerAbbreviation,
            p.product_abbreviation                                as productAbbreviation,
            fc.process_id                                 as processId,
            o.create_time                                         as createTime,
            JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S01')) AS glassNumber,
            JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S02')) AS figureNumber,
            JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S03')) AS colourCeramicGlaze,
            JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S04')) AS remarks1,
            JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S05')) AS remarks2,
            JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S06')) AS remarks3,
            JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S07')) AS remarks4,
            JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S08')) AS remarks5,
            p.remarks                                             as filmNumber,
            od.bend_radius                                        as bendRadius,
            od.other_columns,
            JSON_UNQUOTE(JSON_EXTRACT(pd.separation, '$.color'))  AS color,
            '文本' as custom1,
            '文本' as custom2,
            '文本' as custom3,
            '文本' as custom4,
            '文本' as custom5,
            od.quantity
        from optimize_detail as opt
                 left join flow_card as fc on opt.project_no=fc.project_no and opt.process_id=fc.process_id and opt.layer=fc.technology_number and opt.order_sort=fc.order_number
                 left join sd.order as o on o.order_id=fc.order_id
                 left join sd.order_detail as od on fc.order_id = od.order_id and od.order_number = fc.order_number
                 left join sd.product as p on p.id = od.product_id
                 left join sd.customer as c on c.id = o.customer_id
                 left join sd.product_detail as pd on pd.prod_id = p.id and pd.sort_num = od.order_number and
                                                      pd.glass_sort = fc.technology_number
        where opt.project_no=#{projectNo}
        order by opt.stock_id,opt.polys_id
    </select>
 
    <select id="selectUserMp">
        select role_id
        from erp_user_info.`user` as u
                 left join erp_user_info.user_role as ur on u.id = ur.user_id
        where u.login_name = #{userId}
    </select>
 
    <select id="selectSortTableMp">
        select fcs.sort,
               fcs.process_id,
               fcs.order_number,
               fcs.technology_number,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S01')) AS glassNumber,
               fcs.process
        from
            flow_card as fc
                left join  flow_card_sort as fcs on fcs.process_id=fc.process_id
                and fcs.order_number=fc.order_number and fcs.technology_number=fc.technology_number
                left join sd.order_detail as od
                          on od.order_id = fc.order_id and od.order_number = fcs.order_number
        where fc.order_id = #{orderId}
        GROUP BY fcs.process_id,
                 fcs.order_number,
                 fcs.technology_number,
                 fcs.process
        ORDER BY fcs.sort,process_id,
                 fcs.order_number,
                 fcs.technology_number
    </select>
 
    <select id="countFlowCard">
        select count(distinct process_id) from flow_card where order_id = #{orderId}
    </select>
 
    <select id="remakList">
        SELECT
            ifnull(JSON_UNQUOTE(JSON_EXTRACT(other_columns, '$.S01')),'') AS S01,
            ifnull(JSON_UNQUOTE(JSON_EXTRACT(other_columns, '$.S04')),'') AS S02,
            ifnull(JSON_UNQUOTE(JSON_EXTRACT(other_columns, '$.S05')),'') AS S03,
            ifnull(JSON_UNQUOTE(JSON_EXTRACT(other_columns, '$.S06')),'') AS S04,
            ifnull(JSON_UNQUOTE(JSON_EXTRACT(other_columns, '$.S07')),'') AS S05
        FROM flow_card as fc left join sd.order_detail as od on  fc.order_id = od.order_id
        and fc.order_number = od.order_number
        WHERE fc.process_id=#{processId}
        GROUP BY fc.order_number
    </select>
 
    <select id="selectMaxFlowCard">
        select ifnull((select fc.process_id
                       from sd.order_detail as od
                                left join sd.order_glass_detail as ogd
                                          on od.order_id = ogd.order_id and od.order_number = ogd.order_number
                                left join flow_card as fc on fc.order_id=od.order_id and fc.order_number=od.order_number and fc.technology_number=ogd.technology_number
                       where od.order_id = #{orderId}
                         and ogd.production_id = #{productionId}
                       GROUP BY od.order_number
                       order by fc.process_id desc LIMIT 1),'') as process_id
    </select>
 
    <select id="selectFlowCardMerge">
        select *,GROUP_CONCAT(DISTINCT fc.technology_number) as count1,count(DISTINCT fc.technology_number)  as count2
        from pp.flow_card as fc
                 left join sd.order_glass_detail as ogd
                           on fc.order_id = ogd.order_id and fc.order_number = ogd.order_number and
                              fc.technology_number = ogd.technology_number
                 left join sd.order_detail as od on od.order_id = ogd.order_id and od.order_number = ogd.order_number
        where fc.process_id = #{processId}
        GROUP BY fc.order_id, fc.process_id, ogd.glass_child
    </select>
 
    <update id="updateFlowCardMerge">
        update  pp.flow_card fc set fc.merge=#{index}
        where fc.process_id = #{processId} and fc.technology_number  in
        <foreach item="technologyNumber" collection="technologyNumbers" open="(" separator="," close=")">
            #{technologyNumber}
        </foreach>
    </update>
 
    <delete id="deleteflowCardSort">
        delete from flow_card_sort where process_id = #{processId}
    </delete>
 
    <delete id="deleteflowCardSortByOrderId">
        delete from pp.flow_card_sort
               where process_id =(
                                  select process_id from pp.flow_card
                                  where order_id=#{orderId}
                                  group by process_id
                )
    </delete>
 
    <select id="getPrintProjectDetailsMp">
        SELECT opd.project_no,opd.stock_id,opl.glass_count FROM optimize_detail as opd left join optimize_layout as opl on opl.project_no=opd.project_no and opl.stock_id=opd.stock_id
        where opd.project_no=#{projectNo}
        GROUP BY opd.stock_id
        ORDER BY opd.stock_id
    </select>
 
    <select id="getPrintCustomDataProjectDetail">
        select
            o.order_id                                            as orderId,
            project,
            customer_id                                           as customerId,
            o.customer_name                                       as customerName,
            order_type                                            as orderType,
            order_classify                                        as orderClassify,
            batch,
            o.icon,
            pack_type                                             as packType,
            delivery_date                                         as deliveryDate,
            al_type                                               as alType,
            money,
            contract_id                                           as contractId,
            customer_batch                                           customerBatch,
            contacts,
            delivery_address                                      as deliveryAddress,
            od.processing_note                                    as processingNote,
            od.width,
            od.height,
            fc.quantity as flowQuantity,
            od.order_number                                       as orderNumber,
            fc.technology_number                                  as technologyNumber,
            od.building_number                                    as buildingNumber,
            od.product_name                                       as productName,
            od.edging_type                                        as edgingType,
            od.remarks,
            c.customer_abbreviation                               as customerAbbreviation,
            p.product_abbreviation                                as productAbbreviation,
            fc.process_id                                 as processId,
            o.create_time                                         as createTime,
            JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S01')) AS glassNumber,
            JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S02')) AS figureNumber,
            JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S03')) AS colourCeramicGlaze,
            JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S04')) AS remarks1,
            JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S05')) AS remarks2,
            JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S06')) AS remarks3,
            JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S07')) AS remarks4,
            JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S08')) AS remarks5,
            p.remarks                                             as filmNumber,
            od.bend_radius                                        as bendRadius,
            od.other_columns,
            JSON_UNQUOTE(JSON_EXTRACT(pd.separation, '$.color'))  AS color,
            '文本' as custom1,
            '文本' as custom2,
            '文本' as custom3,
            '文本' as custom4,
            '文本' as custom5,
            od.quantity
        from optimize_detail as opt
                 left join flow_card as fc on opt.project_no=fc.project_no and opt.process_id=fc.process_id and opt.layer=fc.technology_number and opt.order_sort=fc.order_number
                 left join sd.order as o on o.order_id=fc.order_id
                 left join sd.order_detail as od on fc.order_id = od.order_id and od.order_number = fc.order_number
                 left join sd.product as p on p.id = od.product_id
                 left join sd.customer as c on c.id = o.customer_id
                 left join sd.product_detail as pd on pd.prod_id = p.id and pd.sort_num = od.order_number and
                                                      pd.glass_sort = fc.technology_number
        where opt.project_no=#{projectNo} and opt.stock_id=#{stockId}
        order by opt.stock_id,opt.polys_id
    </select>
 
    <select id="getPrintCustomDataProject">
        select
            o.order_id                                            as orderId,
            project,
            customer_id                                           as customerId,
            o.customer_name                                       as customerName,
            order_type                                            as orderType,
            order_classify                                        as orderClassify,
            batch,
            o.icon,
            pack_type                                             as packType,
            delivery_date                                         as deliveryDate,
            al_type                                               as alType,
            money,
            contract_id                                           as contractId,
            customer_batch                                           customerBatch,
            contacts,
            delivery_address                                      as deliveryAddress,
            od.processing_note                                    as processingNote,
            od.width,
            od.height,
            fc.quantity as flowQuantity,
            od.order_number                                       as orderNumber,
            fc.technology_number                                  as technologyNumber,
            od.building_number                                    as buildingNumber,
            od.product_name                                       as productName,
            od.edging_type                                        as edgingType,
            od.remarks,
            c.customer_abbreviation                               as customerAbbreviation,
            p.product_abbreviation                                as productAbbreviation,
            fc.process_id                                 as processId,
            o.create_time                                         as createTime,
            JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S01')) AS glassNumber,
            JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S02')) AS figureNumber,
            JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S03')) AS colourCeramicGlaze,
            JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S04')) AS remarks1,
            JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S05')) AS remarks2,
            JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S06')) AS remarks3,
            JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S07')) AS remarks4,
            JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S08')) AS remarks5,
            p.remarks                                             as filmNumber,
            od.bend_radius                                        as bendRadius,
            od.other_columns,
            JSON_UNQUOTE(JSON_EXTRACT(pd.separation, '$.color'))  AS color,
            '文本' as custom1,
            '文本' as custom2,
            '文本' as custom3,
            '文本' as custom4,
            '文本' as custom5,
            od.quantity,
            o.order_id,
            c.customer_abbreviation as customer_name,
            od.building_number,
            od.processing_note,
            ogd.child_width         as childWidth,
            ogd.child_height        as childHeight,
            ogd.glass_child as  glassChild,
            ogd.process,
            e.type_name,
            opt.stock_id,
            od.bend_radius,
            a.id as flow_card_sort,
            concat(opt.heat_layout_id,'') as heat_layout_id ,
            opt.heat_layout_sort
        from optimize_detail as opt
                 left join flow_card as fc on opt.project_no=fc.project_no and opt.process_id=fc.process_id and opt.layer=fc.technology_number and opt.order_sort=fc.order_number
                 left join sd.order as o on o.order_id=fc.order_id
                 left join sd.order_detail as od on fc.order_id = od.order_id and od.order_number = fc.order_number
                 left join sd.order_glass_detail as ogd on ogd.order_id=o.order_id and ogd.order_number=od.order_number and ogd.technology_number=fc.technology_number
                 left join sd.product as p on p.id = od.product_id
                 left join sd.basic_glass_type e on e.type_id = p.type_id
                 left join sd.customer as c on c.id = o.customer_id
                 left join sd.product_detail as pd on pd.prod_id = p.id and pd.sort_num = od.order_number and
                                                      pd.glass_sort = fc.technology_number
                 left join (select (@row_number := @row_number + 1) as id,process_id as process_id from (select process_id from pp.optimize_detail tt where project_no =#{projectNo} group by process_id) tt,(select @row_number := 0) as t) a
                           on a.process_id=opt.process_id
        where opt.project_no=#{projectNo}
        order by opt.heat_layout_id, opt.heat_layout_sort desc
    </select>
 
    <select id="getPrintLabel3">
        select o.order_id,
               c.customer_abbreviation as customer_name,
               o.project,
               od.building_number,
               od.processing_note,
               ogd.child_width         as width,
               ogd.child_height        as height,
               od.product_name  as glass_child,
               ogd.process,
               e.type_name,
               opd.stock_id,
               opd.polys_id,
               od.quantity,
               od.other_columns,
               od.bend_radius,
               od.order_number as heat_layout_id,
               a.id as heat_layout_sort
        from pp.optimize_detail opd
                 left join sd.`order` o on SUBSTR(opd.process_id, 1, 10) = o.order_id
                 left join sd.order_detail od
                           on SUBSTR(opd.process_id, 1, 10) = od.order_id and opd.order_sort = od.order_number
                 left join sd.order_glass_detail ogd
                           on SUBSTR(opd.process_id, 1, 10) = ogd.order_id and opd.order_sort = ogd.order_number and
                              opd.layer = ogd.technology_number
                 left join sd.product p on od.product_id = p.id
                 left join sd.basic_glass_type e on e.type_id = p.type_id
                 left join sd.customer c on c.id = o.customer_id
                 left join
             (select (@row_number := @row_number + 1) as id,process_id as process_id from (select process_id from pp.optimize_detail tt where project_no =#{projectNo} group by process_id) tt,(select @row_number := 0) as t) a
             on a.process_id=opd.process_id
        where opd.project_no = #{projectNo} and o.order_id is not null
        group by  order_id,od.order_number
        order by ogd.child_width desc,ogd.child_height desc
    </select>
 
    <delete id="deleteProcessMp">
        delete from sd.order_process_detail where process_id = #{processId} and technology_number= #{technologyNumber}
    </delete>
 
    <insert id="updateProcessMp">
        insert into sd.order_process_detail (order_id,
                                             process_id,
                                             order_number,
                                             technology_number,
                                             process,
                                             create_time)
        select fc.order_id,
               fc.process_id,
               fc.order_number,
               #{technologyNumber},
               #{process},
               NOW()
        from pp.flow_card as fc
        where fc.process_id = #{processId}
          and fc.order_number = #{number}
          and fc.technology_number = #{technologyNumber}
        GROUP BY fc.order_number
    </insert>
 
    <update id="updateOrderProcessMp">
        update sd.order_glass_detail set process=#{orderprocess}
        where order_id=#{orderId} and order_number=#{number} and technology_number=#{technologyNumber}
    </update>
 
    <select id="getFlowCardListPrintProject">
        select
            od.order_id,
            fc.process_id,
            o.customer_name,
            o.project,
            od.order_number,
            ogd.technology_number,
            ogd.glass_address,
            fc.quantity ,
            round(sum(ogd.child_width * ogd.child_height * fc.quantity / 1000000), 2) as total_area,
            od.product_name,
            ogd.glass_child,
            fc.patch_state,
            ogd.process,
            fcd.merge
        from  (select process_id,count(*) as quantity,order_sort,project_no,layer,patch_state from pp.optimize_detail where project_no = #{printProject} group by process_id,layer) as fc
                  left join sd.order_glass_detail as ogd
                            on ogd.order_id = SUBSTRING(fc.process_id,1,10)  and ogd.order_number = fc.order_sort and
                               ogd.technology_number = fc.layer
                  left join sd.order_detail as od on od.order_id = SUBSTRING(fc.process_id,1,10)  and od.order_number = fc.order_sort
                  left join sd.`order` as o on o.order_id = SUBSTRING(fc.process_id,1,10)
                  left join pp.`flow_card` as fcd on fcd.process_id=fc.process_id and fcd.technology_number=ogd.technology_number and fcd.order_number=od.order_number
        where fc.project_no = #{printProject} and fc.process_id is not null and fc.process_id!=""
        GROUP BY fc.process_id, ogd.technology_number
        order by fc.process_id, ogd.technology_number
    </select>
 
    <update id="updateProjectLabelPrintCount">
       update optimize_project set labelPrintNum=labelPrintNum+1 where project_no=#{projectNo}
    </update>
    
    <select id="selectProjectLabelPrintCount">
        select labelPrintNum from optimize_project where project_no=#{projectNo}
    </select>
 
    <update id="updateProjectProcessPrintCount">
        update optimize_project set processPrintNum=processPrintNum+1 where project_no=#{projectNo}
    </update>
 
    <select id="selectProjectProcessPrintCount">
        select processPrintNum from optimize_project where project_no=#{projectNo}
    </select>
 
    <select id="flowCardToOptimizeCount">
        select count(*) from pp.flow_card where order_id = #{orderId} and project_no is not null
    </select>
 
    <select id="getFlowCardDetail" >
        select
        a.order_id,
        a.process_id,
        a.technology_number,
        a.order_number,
        c.product_id,
        c.product_name,
        b.project,
        sum(a.quantity) as quantity,
        sum(c.compute_gross_area) as compute_gross_area,
        a.founder,
        c.processing_note,
        b.customer_name,
        a.merge,
        a.rack
        from  pp.flow_card a
        left join sd.`order` as b on a.order_id=b.order_id
        left join sd.order_detail as c on a.order_id=c.order_id and a.order_number=c.order_number
        where
             a.process_id regexp #{processId}
        group by a.process_id,a.technology_number
 
    </select>
    
    <select id="getGlassThicknessByProdutionId">
        select total_thickness as 'totalThickness',thickness as 'thickness' from sd.product
        where id = (
            select distinct b.product_id from sd.order_glass_detail as a
                    left join sd.order_detail as b
                    on a.order_id = b.order_id and a.order_number = b.order_number
                    where a.order_id = #{orderId}
                    and a.production_id = #{productionId}
            )
    </select>
    
    <select id="getOrderDetailByProductionId">
        select * from (select a.*,
                              a.quantity as 'baiscQuantity',
                              #{glassThickness} as 'thickness',
        IF(a.height >= a.width, a.height, a.width) as 'long',
        IF(a.height &lt; a.width, a.height, a.width) as 'short'
        from sd.order_detail as a
        left join sd.order_glass_detail as b
        on a.order_id = b.order_id and a.order_number = b.order_number
        where a.order_id = #{orderId} and b.production_id = #{productionId}
 
        group by a.order_number) as c
        <if test="type=='scope'">
            where  c.`long` &lt;= #{inLenMax}
                and c.`long` >= #{inLenMin}
                and c.`short` >= #{inShortMin}
                and c.`short` &lt;= #{inShortMax}
        </if>
        <if test="type=='notScope'">
            where  !(c.`long` &lt;= #{inLenMax}
            and c.`long` >= #{inLenMin}
            and c.`short` >= #{inShortMin}
            and c.`short` &lt;= #{inShortMax})
        </if>
        order by c.`long` desc
    </select>
 
    <!--    复选框修改排版状态-->
    <update id="revokeComposing">
        update flow_card as fc
        set fc.layout_status=0
        where fc.process_id = #{processId}
    </update>
 
    <select id="selectProjectNo">
        SELECT COUNT(*)
        FROM flow_card
        WHERE process_id= #{processId} and project_no IS not NULL;
    </select>
 
    <select id="selectPrintDetailsMp2">
        select ogd.id,
               ogd.order_id,
               o.customer_name,
               o.project,
               ogd.technology_number,
               ogd.glass_address,
               (od.quantity)                                                          as quantity,
               (od.quantity)                                                          as printQuantity,
               round((ogd.child_width * ogd.child_height * od.quantity / 1000000), 2) as total_area,
               od.product_name,
               ogd.glass_child,
               ogd.process,
               JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S01'))                  AS glassNumber,
               od.order_number,
               ogd.child_width as width,
               ogd.child_height as height
        from sd.order_glass_detail as ogd
                 left join sd.order_detail as od on od.order_id = ogd.order_id and od.order_number = ogd.order_number
                 left join sd.`order` as o on o.order_id = ogd.order_id
        where ogd.order_id = #{orderId}
        GROUP BY od.order_number
        order by od.order_number
    </select>
 
    <select id="getPrintOrderDataDetails">
        select o.order_id                                            as orderId,
               project,
               customer_id                                           as customerId,
               o.customer_name                                       as customerName,
               order_type                                            as orderType,
               order_classify                                        as orderClassify,
               batch,
               o.icon,
               pack_type                                             as packType,
               delivery_date                                         as deliveryDate,
               al_type                                               as alType,
               money,
               contract_id                                           as contractId,
               customer_batch                                           customerBatch,
               contacts,
               delivery_address                                      as deliveryAddress,
               od.processing_note                                    as processingNote,
               width,
               height,
               #{printQuantity}                                      as quantity,
               CONCAT(
                       TRIM(TRAILING '.' FROM TRIM(TRAILING '0' FROM CAST(width AS CHAR))),
                       ' X ',
                       TRIM(TRAILING '.' FROM TRIM(TRAILING '0' FROM CAST(height AS CHAR))),
                       ' = ',#{printQuantity} )      as size,
 
               CONCAT(
                   od.order_number,')  ',
                       TRIM(TRAILING '.' FROM TRIM(TRAILING '0' FROM CAST(width AS CHAR))),
                       ' X ',
                       TRIM(TRAILING '.' FROM TRIM(TRAILING '0' FROM CAST(height AS CHAR))),
                       ' = ',#{printQuantity} )      as numberSize,
            od.order_number                                       as orderNumber,
            ogd.technology_number                                  as technologyNumber,
            od.building_number                                    as buildingNumber,
            od.product_name                                       as productName,
            od.edging_type                                        as edgingType,
            od.remarks,
            c.customer_abbreviation                               as customerAbbreviation,
            p.product_abbreviation                                as productAbbreviation,
            ''                                         as processId,
            o.create_time                                         as createTime,
            JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S01')) AS glassNumber,
            JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S02')) AS figureNumber,
            JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S03')) AS colourCeramicGlaze,
            JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S04')) AS remarks1,
            JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S05')) AS remarks2,
            JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S06')) AS remarks3,
            JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S07')) AS remarks4,
            JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S08')) AS remarks5,
            p.remarks                                             as filmNumber,
            od.bend_radius                                        as bendRadius,
            od.other_columns,
            ogd.glass_child                                       as glassChild,
            ogd.glass_address                                     as glassAddress,
            JSON_UNQUOTE(JSON_EXTRACT(pd.separation, '$.color'))  AS color,
            '文本' as custom1,
            '文本' as custom2,
            '文本' as custom3,
            '文本' as custom4,
            '文本' as custom5,
            od.quantity
        from sd.order as o
            left join sd.order_detail as od on o.order_id = od.order_id
            left join sd.product as p on p.id = od.product_id
            left join sd.customer as c on c.id = o.customer_id
            left join sd.order_glass_detail as ogd
            on ogd.order_id = od.order_id and ogd.order_number = od.order_number
            left join sd.product_detail as pd on pd.prod_id = p.id and pd.sort_num = od.order_number and
            pd.glass_sort = ogd.technology_number
 
        where od.order_id = #{orderId}
          and od.order_number = #{orderNumber}
        group by od.order_number, width, height
        order by od.order_id
    </select>
 
    <select id="updatePrintNumberMp">
        update pp.flow_card
        set print_number = ifnull(print_number,0) + 1
        where process_id = #{processId}
          and order_number = #{orderNumber}
    </select>
 
    <select id="getOrderIdByProcessId">
        select order_id from pp.flow_card  where process_id = #{processId} limit 1;
    </select>
 
    <select id="flowCardDetailMergeMp">
        select merge from pp.flow_card where process_id = #{processId}  group by id ORDER BY merge desc LIMIT 1
    </select>
 
    <update id="updateFlowCardIsMerge">
        update  pp.flow_card fc set fc.merge=0
        where fc.process_id = #{processId}
    </update>
 
    <select id="getProcessName">
        select IFNULL(nickname,'') from sd.basic_data where basic_category='process' and basic_name=#{processSub}
    </select>
 
    <select id="getProcessNameList">
        SELECT id,basic_name,IFNULL(nickname,"") as nickname FROM sd.`basic_data` where basic_category='process'
    </select>
 
    <select id="exportDateProcessMp">
        select
        a.order_Id,
        a.process_Id,
        c.product_id,
        c.product_name,
        b.project,
        sum(a.quantity) as quantity,
        sum(a.quantity) * c.area as compute_gross_area,
        a.founder,
        c.processing_note,
        b.customer_name,
        layout_status as layout_status,
        a.merge,
        a.rack,
        b.batch
        from (select id,order_id,process_id,order_number, quantity,founder,max(layout_status) as layout_status,create_time,max(merge) as merge,rack from flow_card
        group by process_Id,order_number) as a
        left join sd.`order` as b on a.order_Id=b.order_id
        left join sd.order_detail as c on a.order_Id=c.order_id and a.order_Number=c.order_number
        where date(a.create_time) >= #{date[0]}
          and date(a.create_time) &lt;= #{date[1]}
        and b.create_order>0
        group by a.process_Id
        ORDER BY a.id desc
    </select>
 
    <select id="getSumQuantity">
        select quantity from  sd.`order` where order_id=#{orderId}
    </select>
 
    <select id="getDetailCompoundList">
        select fc.order_number,
        concat(IF(ROUND(ogd.child_width, 1) = FLOOR(ogd.child_width), FLOOR(ogd.child_width), ROUND(ogd.child_width, 1)), "*", IF(ROUND(child_height, 1) = FLOOR(child_height), FLOOR(child_height), ROUND(child_height, 1)))   as child_width,
        SUM(fc.quantity) as quantity,
        round(SUM(ogd.total_area), 2)                                       as total_area,
        SUM(od.perimeter) as perimeter,
        if(od.bend_radius!=null || od.bend_radius!='',od.bend_radius,if(od.shape=2,JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S04')),'')) as bend_radius,
        concat(IFNULL(od.processing_note, ''), IFNULL(od.remarks, '')) as remarks,
        od.other_columns,
        round(ogd.child_width)                                         as width,
        round(ogd.child_height)                                        as height,
        pd.separation,
        #{compound} as technology_number,
        IFNULL(JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S02')),'') as mapNumber,
        od.building_number
        from flow_card as fc
        left join sd.order_glass_detail as ogd
        on fc.order_id = ogd.order_id and fc.order_number = ogd.order_number and
        fc.technology_number = ogd.technology_number
        left join sd.order_detail as od on od.order_id = fc.order_id and od.order_number = fc.order_number
        left join sd.product_detail as pd
        on pd.prod_id = od.product_id and pd.glass_sort = ogd.technology_number
        left join flow_card_sort as fcs
        on fcs.process_id = fc.process_id and fcs.order_number = fc.order_number and
        fcs.technology_number = fc.technology_number
        and fcs.process = #{process}
        where fc.process_id = #{processId}
        and position(fc.technology_number in #{compound})
        group by fc.process_id, fc.order_number
        <choose>
            <!-- flashback = 1 时正序 -->
            <when test="flashback == 1">
                ORDER BY
                CASE
                WHEN fcs.sort IS NOT NULL AND fcs.sort &lt;&gt;  '' THEN fcs.sort
                ELSE fc.order_number
                END ASC
            </when>
            <!-- flashback != 1 时倒序 -->
            <otherwise>
                ORDER BY
                CASE
                WHEN fcs.sort IS NOT NULL AND fcs.sort &lt;&gt;  '' THEN fcs.sort
                ELSE fc.order_number
                END DESC
            </otherwise>
        </choose>
    </select>
 
    <select id="getDetailListLikeCompound">
        select fc.order_number,
        concat(IF(ROUND(ogd.child_width, 1) = FLOOR(ogd.child_width), FLOOR(ogd.child_width), ROUND(ogd.child_width, 1)), "*", IF(ROUND(child_height, 1) = FLOOR(child_height), FLOOR(child_height), ROUND(child_height, 1)))   as child_width,
        sum(fc.quantity) as quantity,
        round(sum(ogd.total_area), 2)                                       as total_area,
        sum(od.perimeter) as perimeter,
        if(od.bend_radius!=null || od.bend_radius!='',od.bend_radius,if(od.shape=2,JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S04')),'')) as bend_radius,
        concat(IFNULL(od.processing_note, ''), IFNULL(od.remarks, '')) as remarks,
        od.other_columns,
        round(ogd.child_width)                                         as width,
        round(ogd.child_height)                                        as height,
        pd.separation,
        #{compound} as technology_number,
        IFNULL(JSON_UNQUOTE(JSON_EXTRACT(od.other_columns, '$.S02')),'') as mapNumber,
        od.building_number
        from flow_card as fc
        left join sd.order_glass_detail as ogd
        on fc.order_id = ogd.order_id and fc.order_number = ogd.order_number and
        fc.technology_number = ogd.technology_number
        left join sd.order_detail as od on od.order_id = fc.order_id and od.order_number = fc.order_number
        left join sd.product_detail as pd
        on pd.prod_id = od.product_id and pd.glass_sort = ogd.technology_number
        left join flow_card_sort as fcs
        on fcs.process_id = fc.process_id and fcs.order_number = fc.order_number and
        fcs.technology_number = fc.technology_number
        and fcs.process = #{process}
        where fc.process_id = #{processId}
        and position(fc.technology_number in #{compound})
        group by fc.process_id, fc.order_number
        <choose>
            <!-- flashback = 1 时正序 -->
            <when test="flashback == 1">
                ORDER BY
                CASE
                WHEN fcs.sort IS NOT NULL AND fcs.sort &lt;&gt;  '' THEN fcs.sort
                ELSE fc.order_number
                END ASC
            </when>
            <!-- flashback != 1 时倒序 -->
            <otherwise>
                ORDER BY
                CASE
                WHEN fcs.sort IS NOT NULL AND fcs.sort &lt;&gt;  '' THEN fcs.sort
                ELSE fc.order_number
                END DESC
            </otherwise>
        </choose>
    </select>
</mapper>