Administrator
2023-03-31 0620759090646bf58a7e786c55cfe07ce1984e45
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
package com.mandi.fendan.service.impl;
 
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.mandi.basicconfig.penum.PrefixEnum;
import com.mandi.basicconfig.persist.Nckh;
import com.mandi.common.*;
import com.mandi.common.ParamFileter.Fileoperation;
import com.mandi.common.ParamFileter.RegexCheck;
import com.mandi.dao.common.Daomethod;
import com.mandi.dao.common.ObjectResult;
import com.mandi.dao.common.PageRequest;
import com.mandi.dao.common.PageResult;
import com.mandi.fendan.mapper.*;
import com.mandi.fendan.persist.*;
import com.mandi.fendan.service.IErpService;
import com.mandi.fendan.util.Contants;
import com.mandi.fendan.util.ConvertTool;
import com.mandi.fendan.util.FdtoNc;
import com.mandi.fendan.util.persist.*;
import com.mandi.springmvc.logs.OpLogs;
import com.mandi.system.persist.Login;
import com.mandi.system.persist.ModuleEnum;
import com.mandi.system.persist.UserType;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.log4j.Logger;
import org.apache.poi.util.StringUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Map.Entry;
import java.util.stream.Collectors;
 
@Service
public class ErpService implements IErpService {
    private Logger log = Logger.getLogger(ErpService.class);
 
    @Resource(name = "dtf")
    private SimpleDateFormat sdf;
    @Resource(name = "ydf")
    private SimpleDateFormat ydf;
    @Resource(name = "df")
    private SimpleDateFormat df;
    @Resource
    private Fd_BsheetMapper fdbsper;
    @Resource
    private Fd_VehicleMapper vhper;
    @Resource
    private VehicleXSTDMapper vhxper;
    @Resource
    private Fd_CompanyMapper fdcper;
    @Resource
    private Fd_ComVehicleMapper fdvcper;
    @Resource
    private Fd_XSTDMapper tdper;
    @Resource
    private Fd_XSTDMXMapper tdmxper;
    @Resource
    private Fd_GbxstdMapper gbtdper;
    @Resource
    private Fd_GbxstdmxMapper gbtdmxper;
    @Resource
    private Fd_fhdqMapper dqper;
 
    @Resource
    private BusinessMapper bsper;
    @Resource
    private Fd_YKTMapper yktmper;
    @Resource
    private FdtoNc fdtonc;
    @Resource
    private fd_errsheetMapper errPer;
    @Resource
    private FdMxWlgsMapper fdMxWlgsMapper;
 
    @Resource
    private SqlSessionFactory sqlSessionFactory;
 
    @Resource
    private FdVehicleRemarkMapper fdVehicleRemarkMapper;
 
    @Override
    public ObjectResult<String> tzPrint(Login lg, String bssNo, String ipadd) {
        ObjectResult<String> orr = new ObjectResult<String>();
        if (lg == null) {
            orr.setCode(1);
            orr.setErrmsg("请登录账号!");
            return orr;
        }
        if (StringUtils.isEmpty(bssNo)) {
            orr.setCode(1);
            orr.setErrmsg("业务参数为空!");
            return orr;
        }
        Fd_Bsheet fd_b = this.fdbsper.getbybsNo(bssNo);// this.fdbsper.getbyVehicleId(vehicleId, Serviceenum.在办);
        if (fd_b == null) {
            orr.setCode(1);
            orr.setErrmsg("车辆业务单未找到,不能打印!");
            return orr;
        }
        if (fd_b.getStatus() != Serviceenum.在办) {
            orr.setCode(1);
            orr.setErrmsg("车辆业务单不是在办状态,不能打印!");
            return orr;
        }
        String comNo = "";
        if (!UserType.admin.toString().equals(lg.getWorkerno())) {
            // List<Vehicle_XSTD>
            // ll=this.vhxper.getlistbyVehandcompanyNo(vehicleId,lg.getDepartno());
            // if(ll!=null){
            // for (Vehicle_XSTD vhx : ll) {
            // if(StringUtils.isEmpty(comNo)){
            // comNo+=vhx.getXstdNo();
            // }else{
            // comNo+=(","+vhx.getXstdNo());
            // }
            // }
            // }
            if (StringUtils.isNotBlank(lg.getDepartno())) {
                comNo = lg.getDepartno();
            }
        }
        // Map<String, Object> mp=this.bsper.getBsheet(fd_b.getBsNo());
        // if(mp==null){
        // orr.setCode(1);
        // orr.setErrmsg("业务单未找到!");
        // return orr;
        // }
        String dyAdd = this.bsper.getUsedbyAdd();
        if (StringUtils.isBlank(dyAdd)) {
            orr.setCode(1);
            orr.setErrmsg("系统未设置打印地址!");
            return orr;
        }
        try {
            orr.setItem("http://" + dyAdd + Contants.GYPrintAdd + "&vehicleId="
                    + URLEncoder.encode(fd_b.getVehicleId(), "utf-8") + "&bsNo=" + fd_b.getBsNo() + "&phone="
                    + fd_b.getPhone() + "&comNo=" + comNo);
            // log.info("::::::::::;"+orr.getItem());
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
 
        orr.setCode(0);
        return orr;
    }
    // 暂时没有使用
    public PageResult<Map<String, Object>> getBillofLadingList(Login lg, String type, String searchStr, String companyNo,
                                                               Date sdate, Date edate, int wcSign, PageRequest pr, String sortStr, String cqNo) {
        PageResult<Map<String, Object>> prr = new PageResult<Map<String, Object>>();
        // 销售提单查询值不为空
        if (lg == null) {
            prr.setCode(1);
            prr.setErrmsg("请登录账号!");
            return prr;
        }
        if (StringUtils.isEmpty(companyNo)) {
            if (!UserType.admin.toString().equals(lg.getWorkerno())) {
                companyNo = lg.getDepartno();
            }
        }
        if (pr == null) {
            pr = new PageRequest(0, 30, null);
            pr.setNeedPages(true);
        }
 
        // 查询参数
        Map<String, Object> pmp = new HashMap<String, Object>();
        // 查询值 type
        if (StringUtils.isNotBlank(searchStr)) {
            pmp.put(type, searchStr);
        }
        if (sdate != null) {
            Date now = new Date();
            Calendar theCa = Calendar.getInstance();
            theCa.setTime(now);
            theCa.add(Calendar.DATE, -Contants.XSTDlastSearchday);
            Date csdate = theCa.getTime();
            if (csdate.after(sdate)) {
                sdate = csdate;
            }
            pmp.put("sdate", df.format(sdate));
        } else {
            Date now = new Date();
            Calendar theCa = Calendar.getInstance();
            theCa.setTime(now);
            theCa.add(Calendar.DATE, -Contants.XSTDlastSearchday);
            sdate = theCa.getTime();
            pmp.put("sdate", df.format(sdate));
        }
        if (edate != null) {
            pmp.put("edate", df.format(edate));
        }
        if (!StringUtils.isEmpty(companyNo)) {
            pmp.put("companyNo", companyNo);
            Fd_Company fdc = this.fdcper.getByCompanyNo(companyNo);
            if (fdc != null) {
                pmp.put("ztbz", fdc.isHasSPR() ? 1 : 0);
            }
        }
        pmp.put("page", pr.getStart());
        pmp.put("pagesize", pr.getPageSize());
        pmp.put("wcSign", wcSign);
        if(StringUtils.isNotBlank(cqNo))
            pmp.put("cqV", cqNo);
        // 排序字段
        pmp.put("sort", sortStr);
        if (pr.isNeedPages()) {
            int count = this.tdper.countPage(pmp);
            int pages = Daomethod.countpages(count, pr.getPageSize());
            prr.setPages(pages);
        }
 
        List<WaitXSTD> l = this.tdper.getList(pmp);
        List<Map<String, Object>> rl = new ArrayList<Map<String, Object>>();
        if (l != null) {
            for (WaitXSTD wt : l) {
                String fhdqbh = wt.getTd_shddbh();
                String ztbz = wt.getTd_ztbz();
                Map<String, Object> mm = new HashMap<String, Object>();
                try {
                    mm = BeanUtils.describe(wt);
                } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
                    prr.setCode(1);
                    prr.setErrmsg("对象转Map出错,出错提单编号::" + wt.getTd_tdbh());
                    return prr;
                }
                if (!"自提".equals(ztbz)) {
                    /*List<Fd_Company> fcl = this.dqper.getCbyNoandsNo(fhdqbh, wt.getTd_ywdybh(),
                            *//*wt.getTd_ywdybh().equals(Contants.nc_ywdy_ZZ) ? Contants.nc_ywdy_ZZ :
                                wt.getTd_ywdybh().equals(Contants.nc_ywdy_MS) ? Contants.nc_ywdy_MS :
                                    Contants.nc_ywdy_KJ*//*
                            ConvertTool.ncGetDefault(wt.getTd_ywdybh())
                    );
                    if (fcl != null) {
                        for (Fd_Company fdc : fcl) {
                            if (StringUtils
                                    .isNotBlank(mm.get("companyNo") == null ? "" : mm.get("companyNo").toString())) {
                                mm.put("companyName", mm.get("companyName") + "," + fdc.getName());
                                mm.put("companyNo", mm.get("companyNo") + "," + fdc.getCompanyNo());
                            } else {
                                mm.put("companyName", fdc.getName());
                                mm.put("companyNo", fdc.getCompanyNo());
                            }
                        }
                    }*/
                }
                try {
                    mm.put("td_wfdsl", wt.getTd_wfdsl());
                    mm.put("td_wfdzl", BigDecimalfiter.addscal(0, wt.getTd_wfdzl(), Contants.scale));
                } catch (Exception e) {
                    // TODO: handle exception
                }
                rl.add(mm);
            }
        }
        prr.setCode(0);
        prr.setList(rl);
        return prr;
    }
    @Override
    public PageResult<Map<String, Object>> getXSTDList(Login lg, String type, String searchStr, String companyNo,
            Date sdate, Date edate, int wcSign, String fdAdmin,PageRequest pr, String sortStr, String cqNo) {
        PageResult<Map<String, Object>> prr = new PageResult<Map<String, Object>>();
        // 销售提单查询值不为空
        if (lg == null) {
            prr.setCode(1);
            prr.setErrmsg("请登录账号!");
            return prr;
        }
        // 如果是管理员或者非提单更物流公司的操作
        boolean isAdminOrFdAdmin = UserType.admin.toString().equals(lg.getWorkerno())  || StringUtils.isNotBlank(fdAdmin);
        if (StringUtils.isEmpty(companyNo)) {
            if (!isAdminOrFdAdmin) { // 如果不是更改车辆分单管理员和也不是系统管理员,需要加上公司no
                companyNo = lg.getDepartno();
            }
        }
        if (pr == null) {
            pr = new PageRequest(0, 30, null);
            pr.setNeedPages(true);
        }
 
        // 查询参数
        Map<String, Object> pmp = new HashMap<String, Object>();
        // 查询值 type
        if (StringUtils.isNotBlank(searchStr)) {
            pmp.put(type, searchStr);
        }
        if (sdate != null) {
            Date now = new Date();
            Calendar theCa = Calendar.getInstance();
            theCa.setTime(now);
            theCa.add(Calendar.DATE, -Contants.XSTDlastSearchday);
            Date csdate = theCa.getTime();
            if (csdate.after(sdate)) {
                sdate = csdate;
            }
            pmp.put("sdate", df.format(sdate));
        } else {
            Date now = new Date();
            Calendar theCa = Calendar.getInstance();
            theCa.setTime(now);
            theCa.add(Calendar.DATE, -Contants.XSTDlastSearchday);
            sdate = theCa.getTime();
            pmp.put("sdate", df.format(sdate));
        }
        if (edate != null) {
            pmp.put("edate", df.format(edate));
        }
        if (!StringUtils.isEmpty(companyNo)) {
            pmp.put("companyNo", companyNo);
            Fd_Company fdc = this.fdcper.getByCompanyNo(companyNo);
            if (fdc != null) {
                pmp.put("ztbz", fdc.isHasSPR() ? 1 : 0);
            }
        }
        pmp.put("page", pr.getStart());
        pmp.put("pagesize", pr.getPageSize());
        pmp.put("wcSign", wcSign);
        pmp.put("fdAdmin", fdAdmin);
 
        if(StringUtils.isNotBlank(cqNo))
            pmp.put("cqV", cqNo);
        // 排序字段
        pmp.put("sort", sortStr);
        if (pr.isNeedPages()) {
            int count = this.tdper.countPage(pmp);
            int pages = Daomethod.countpages(count, pr.getPageSize());
            prr.setPages(pages);
        }
 
        List<WaitXSTD> l = this.tdper.getList(pmp);
        List<Map<String, Object>> rl = new ArrayList<Map<String, Object>>();
        if (l != null) {
            for (WaitXSTD wt : l) {
                String fhdqbh = wt.getTd_shddbh();
                String ztbz = wt.getTd_ztbz();
                Map<String, Object> mm = new HashMap<String, Object>();
                try {
                    mm = BeanUtils.describe(wt);
                } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
                    prr.setCode(1);
                    prr.setErrmsg("对象转Map出错,出错提单编号::" + wt.getTd_tdbh());
                    return prr;
                }
                if (!"自提".equals(ztbz)) {
                    /*List<Fd_Company> fcl = this.dqper.getCbyNoandsNo(fhdqbh, wt.getTd_ywdybh(),
                            wt.getTd_ywdybh().equals(Contants.nc_ywdy_ZZ) ? Contants.nc_ywdy_ZZ :
                                *//*wt.getTd_ywdybh().equals(Contants.nc_ywdy_MS) ? Contants.nc_ywdy_MS :
                                    Contants.nc_ywdy_KJ*//*
                            ConvertTool.ncGetDefault(wt.getTd_ywdybh())
                    );
                    if (fcl != null) {
                        for (Fd_Company fdc : fcl) {
                            if (StringUtils
                                    .isNotBlank(mm.get("companyNo") == null ? "" : mm.get("companyNo").toString())) {
                                mm.put("companyName", mm.get("companyName") + "," + fdc.getName());
                                mm.put("companyNo", mm.get("companyNo") + "," + fdc.getCompanyNo());
                            } else {
                                mm.put("companyName", fdc.getName());
                                mm.put("companyNo", fdc.getCompanyNo());
                            }
                        }
                    }*/
                }
                try {
                    mm.put("td_wfdsl", wt.getTd_wfdsl());
                    mm.put("td_wfdzl", BigDecimalfiter.addscal(0, wt.getTd_wfdzl(), Contants.scale));
                } catch (Exception e) {
                    // TODO: handle exception
                }
                rl.add(mm);
            }
        }
        prr.setCode(0);
        prr.setList(rl);
        return prr;
    }
 
    @Override
    public PageResult<Map<String, Object>> getCloseXSTDlist(Login lg, String type, String searchStr, String companyNo,
            Date sdate, Date edate, int wcSign, PageRequest pr, List<String> sortc) {
        // type 只有两种类型 提单编号/关闭人 sdate 关闭开始时间 edate 关闭结束时间 companyNo 运输公司 查询值
        PageResult<Map<String, Object>> prr = new PageResult<Map<String, Object>>();
        if (lg == null) {
            prr.setCode(1);
            prr.setErrmsg("请登录账号!");
            return prr;
        }
        if (pr == null) {
            pr = new PageRequest(0, 30, null);
            pr.setNeedPages(true);
        }
        Map<String, Object> pmp = new HashMap<String, Object>();
        pmp.put("page", pr.getStart());
        pmp.put("pagesize", pr.getPageSize());
        if (sdate != null) {
            pmp.put("stime", sdate);
        }
        if (edate != null) {
            pmp.put("etime", edate);
        }
        if (UserType.admin.toString().equals(lg.getWorkerno())) {
            if (!StringUtils.isEmpty(companyNo)) {
                pmp.put("companyNo", companyNo);
            }
        } else {
            Fd_Company fdc = this.fdcper.getByCompanyNo(lg.getDepartno());
            if (fdc != null) {
                if (fdc.isHasSPR()) {
                    pmp.put("isHSR", true);
                } else {
                    pmp.put("companyNo", lg.getDepartno());
                }
            } else {
                pmp.put("companyNo", "aaaaa");
            }
 
        }
        // 提单号 模糊查询
        if (StringUtils.isNotBlank(searchStr)) {
            pmp.put(type, searchStr);
        }
        // if(!StringUtils.isEmpty(searchStr)&&"tdbh".equals(type)){
        // if(!StringUtils.isEmpty(searchStr)){
        // pmp.put("tdbh", searchStr);
        // }
        // }else if(){
        // if(!StringUtils.isEmpty(searchStr)){
        // pmp.put("td_gbr", searchStr);
        // }
        // }else
        if (pr.isNeedPages()) {
            int count = gbtdper.counts(pmp);
            int pages = Daomethod.countpages(count, pr.getPageSize());
            prr.setPages(pages);
        }
 
        List<Fd_Company> llc = this.fdcper.getall();
        Map<String, Object> fdcmp = new HashMap<String, Object>();
        if (llc != null) {
            for (Fd_Company fd_Company : llc) {
                fdcmp.put(fd_Company.getCompanyNo() + "", fd_Company.getName());
            }
        }
        List<Map<String, Object>> tdl = gbtdper.getList(pmp);
        // List<Map<String, Object>> rel=new ArrayList<Map<String,Object>>();
        // if(tdl!=null){
        // for (Fd_Gbxstd gbtd : tdl) {
        // Map<String, Object> rmp=this.tdper.getGBXSTD(gbtd.getXstdNo());
        // rel.add(rmp);
        // }
        // }
        List<Map<String, Object>> rl = new ArrayList<Map<String, Object>>();
        if (tdl != null) {
            for (Map<String, Object> wt : tdl) {
                String fhdqbh = wt.get("td_shddbh") == null ? "" : wt.get("td_shddbh").toString();
                String td_ywdybh = wt.get("td_ywdybh") == null ? "" : wt.get("td_ywdybh").toString();
                // String td_tdbh=wt.get("td_tdbh")==null?"":wt.get("td_tdbh").toString();
                String ztbz = wt.get("td_ztbz") == null ? "" : wt.get("td_ztbz").toString();
                Map<String, Object> mm = wt;
                mm.put("companyName", "");
                mm.put("companyNo", "");
                // try {
                // mm=BeanUtils.describe(wt);
                // } catch (IllegalAccessException | InvocationTargetException|
                // NoSuchMethodException e) {
                // prr.setCode(1);
                // prr.setErrmsg("对象转Map出错,出错提单编号::"+td_tdbh);
                // return prr;
                // }
                if (!"自提".equals(ztbz)) {
                    /*List<Fd_Company> fcl = this.dqper.getCbyNoandsNo(fhdqbh, td_ywdybh,
                            *//*td_ywdybh.equals(Contants.nc_ywdy_ZZ) ? Contants.nc_ywdy_ZZ :
                                td_ywdybh.equals(Contants.nc_ywdy_MS) ? Contants.nc_ywdy_MS :
                                    Contants.nc_ywdy_KJ*//*
                            ConvertTool.ncGetDefault(td_ywdybh)
                                );// getCbyNo(fhdqbh);
                    if (fcl != null) {
                        for (Fd_Company fdc : fcl) {
                            if (StringUtils
                                    .isNotBlank(mm.get("companyNo") == null ? "" : mm.get("companyNo").toString())) {
                                mm.put("companyName", mm.get("companyName") + "," + fdc.getName());
                                mm.put("companyNo", mm.get("companyNo") + "," + fdc.getCompanyNo());
                            } else {
                                mm.put("companyName", fdc.getName());
                                mm.put("companyNo", fdc.getCompanyNo());
                            }
                        }
                    }*/
                }
                // try {
                // mm.put("td_wfdsl",wt.getTd_wfdsl());
                // mm.put("td_wfdzl",BigDecimalfiter.addscal(0, wt.getTd_wfdzl(),
                // Contants.scale));
                // } catch (Exception e) {
                // // TODO: handle exception
                // }
                rl.add(mm);
            }
        }
        prr.setCode(0);
        prr.setList(rl);
        return prr;
    }
 
    /**
     * @param lg
     * @param XSTD
     * @return
     */
    @Override
    public Map<String, Object> getXSTD(Login lg, String XSTD) {
        Map<String, Object> mp = new HashMap<String, Object>();
        if (lg == null) {
            mp.put("code", 1);
            mp.put("errmsg", "请登录账号!");
            return mp;
        }
        if (StringUtils.isBlank(XSTD)) {
            mp.put("code", 1);
            mp.put("errmsg", "查询值:提单号 为空!");
            return mp;
        }
 
        Fd_XSTD xstd = this.tdper.getbyttdbh(XSTD);
        if (xstd == null) {
            mp.put("code", 1);
            mp.put("errmsg", "提单查询为空!");
            return mp;
        }
        String companyNo = null;
        if (!UserType.admin.toString().equals(lg.getWorkerno())) {
            Fd_Company fdc = this.fdcper.getByCompanyNo(lg.getDepartno());
            companyNo = fdc.getCompanyNo();
        }
 
        String shdqbh = xstd.getTd_shddbh();
        // 自提
        if (xstd.getTd_ztbz() == 2) {
            if (!UserType.admin.toString().equals(lg.getWorkerno())) {
                Fd_Company fdc = this.fdcper.getByCompanyNo(lg.getDepartno());
                if (fdc != null) {
                    if (!fdc.isHasSPR()) {
                        mp.put("code", 1);
                        mp.put("errmsg", "没有查看该提单的权限!");
                        return mp;
                    }
                } else {
                    mp.put("code", 1);
                    mp.put("errmsg", "物流公司未找到!");
                    return mp;
                }
            }
        } else {
            if (!UserType.admin.toString().equals(lg.getWorkerno())) {
                Fd_wlgs_fhdq ccr = this.dqper.getbyNos(lg.getDepartno(), shdqbh,
                        /*xstd.getTd_ywdybh().equals(Contants.nc_ywdy_ZZ) ? Contants.nc_ywdy_ZZ:
                                xstd.getTd_ywdybh().equals(Contants.nc_ywdy_MS) ? Contants.nc_ywdy_MS
                                : Contants.nc_ywdy_KJ*/
                        ConvertTool.ncGetDefault(xstd.getTd_ywdybh())
                );
                // 这个地方改一下,允许fd_mx_wlgs中存在的单查看
                int total = fdMxWlgsMapper.selectCountByTdTdls(xstd.getTd_tdls());
                if (ccr == null && total == 0) {
                    mp.put("code", 1);
                    mp.put("errmsg", "没有查看该提单的权限!");
                    return mp;
                }
            }
        }
 
        // 编号转名字
        // 转watiXSTD对象
        // 查找明细:未装车
        // 过滤掉已经配车并且配车车辆不是该公司的: 虽然两个物流公司可以使用同一个销售发货单,但是两个物流公司的分单时间是错开的
        WaitXSTD wxt = this.tdper.getWaitXSTD(XSTD);
 
        Map<String, Object> mxpmp = new HashMap<String, Object>();
 
        // 过滤条件
        mxpmp.put("tdls", wxt.getTd_tdls());
        mxpmp.put("zcbz", 0);
        mxpmp.put("pagesize", 0);
        mxpmp.put("page", 0);
        if(StringUtils.isNotBlank(companyNo)) {
            mxpmp.put("companyNo", companyNo);
        }
        List<Map<String, Object>> XSTDMX_list = this.tdmxper.getList(mxpmp);
 
        mp.put("code", 0);
        mp.put("item", wxt);
        mp.put("list", XSTDMX_list);
        return mp;
    }
    @Override
    public Map<String, Object>  getBillofLadingXSTD(Login lg,String XSTD){
        String companyNo = null;
        boolean isFdAdmin = lg.isFdAdmin();
        // 是否为管理员或分单管理员
        boolean isAdminOrFdAdmin = UserType.admin.toString().equals(lg.getWorkerno()) || isFdAdmin;
        if (!isAdminOrFdAdmin) {
            Fd_Company fdc = this.fdcper.getByCompanyNo(lg.getDepartno());
            companyNo = fdc.getCompanyNo();
        }
        Map<String, Object> mp = new HashMap<String, Object>();
        if (lg == null) {
            mp.put("code", 1);
            mp.put("errmsg", "请登录账号!");
            return mp;
        }
        if (StringUtils.isBlank(XSTD)) {
            mp.put("code", 1);
            mp.put("errmsg", "查询值:提单号 为空!");
            return mp;
        }
 
        Fd_XSTD xstd = this.tdper.getbyttdbh(XSTD);
        if (xstd == null) {
            mp.put("code", 1);
            mp.put("errmsg", "提单查询为空!");
            return mp;
        }
        String shdqbh = xstd.getTd_shddbh();
        // 自提
        if (xstd.getTd_ztbz() == 2) {
            if (!isAdminOrFdAdmin) {
                Fd_Company fdc = this.fdcper.getByCompanyNo(lg.getDepartno());
                if (fdc != null) {
                    if (!fdc.isHasSPR()) {
                        mp.put("code", 1);
                        mp.put("errmsg", "没有查看该提单的权限!");
                        return mp;
                    }
                } else {
                    mp.put("code", 1);
                    mp.put("errmsg", "物流公司未找到!");
                    return mp;
                }
            }
        } else {
            if (!isAdminOrFdAdmin) {
                Fd_wlgs_fhdq ccr = this.dqper.getbyNos(lg.getDepartno(), shdqbh,
                        /*xstd.getTd_ywdybh().equals(Contants.nc_ywdy_ZZ) ? Contants.nc_ywdy_ZZ:
                                xstd.getTd_ywdybh().equals(Contants.nc_ywdy_MS) ? Contants.nc_ywdy_MS
                                : Contants.nc_ywdy_KJ*/
                        ConvertTool.ncGetDefault(xstd.getTd_ywdybh())
                );
                int total = fdMxWlgsMapper.selectCountByTdTdls(xstd.getTd_tdls());
                if (ccr == null && total == 0) {
                    mp.put("code", 1);
                    mp.put("errmsg", "没有查看该提单的权限!");
                    return mp;
                }
            }
        }
 
        // 编号转名字
        // 转watiXSTD对象
        // 查找明细:未装车
        // 过滤掉已经配车并且配车车辆不是该公司的: 虽然两个物流公司可以使用同一个销售发货单,但是两个物流公司的分单时间是错开的
        WaitXSTD wxt = this.tdper.getWaitXSTD(XSTD);
 
        Map<String, Object> mxpmp = new HashMap<String, Object>();
 
        // 过滤条件
        mxpmp.put("tdls", wxt.getTd_tdls());
        // 已经装车的也要显示,方便调整
        // mxpmp.put("zcbz", 0);
        mxpmp.put("pagesize", 0);
        mxpmp.put("page", 0);
        if(StringUtils.isNotBlank(companyNo)) {
            mxpmp.put("companyNo", companyNo);
        }
        List<Map<String, Object>> XSTDMX_list = this.tdmxper.getList(mxpmp);
 
        mp.put("code", 0);
        mp.put("item", wxt);
        mp.put("list", XSTDMX_list);
        return mp;
    }
    @Override
    public PageResult<Map<String, Object>> getFdlist(Login lg, String companyNo, String vehicleId, PageRequest pr,
            String cqV) {
        PageResult<Map<String, Object>> prr = new PageResult<Map<String, Object>>();
        if (pr == null) {
            pr = new PageRequest(0, 30, null);
            pr.setNeedPages(true);
        }
        if (lg == null) {
            prr.setCode(1);
            prr.setErrmsg("请登录账号!");
            return prr;
        }
        Map<String, Object> mp = new HashMap<String, Object>();
        // 按公司划分
        String crc = "";
        if (StringUtils.isNotBlank(companyNo)) {
            mp.put("companyNo", companyNo);
            crc = companyNo;
        } else {
            if (lg.getWorkerno().equals(UserType.admin.toString())) {
                mp.put("companyNo", "");
                crc = "";
            } else {
                mp.put("companyNo", lg.getDepartno());
                crc = lg.getDepartno();
            }
        }
        if (!StringUtils.isEmpty(vehicleId)) {
            mp.put("vehicleId", vehicleId);
        }
        mp.put("pagesize", pr.getPageSize());
        mp.put("page", pr.getStart());
        if(StringUtils.isNotBlank(cqV)) {
            mp.put("cqV",/*Contants.nc_ywdy_ZZ.equals(cqV)?Contants.zzSdepartNo:
                Contants.nc_ywdy_MS.equals(cqV)?Contants.msSdepartNo:Contants.kjSdepartNo*/
                    ConvertTool.ncCovertToYkt(cqV)
            );
        }
        if (pr.isNeedPages()) {
            int count = bsper.getbspages(mp);
            int pages = Daomethod.countpages(count, pr.getPageSize());
            prr.setPages(pages);
        }
        List<Map<String, Object>> list = bsper.getbslist(mp);
        List<Map<String, Object>> relist = new ArrayList<Map<String, Object>>();
        if (list != null && list.size() > 0) {
            List<Vehicle_XSTD> vxlist = StringUtils.isBlank(crc) ? this.vhxper.getlistAll()
                    : this.vhxper.getlistbycomNo(crc);
            // List<Fd_Company> cl=this.vhxper.getAllCom();
            for (Map<String, Object> map : list) {
                Map<String, Object> remp = map;
                String bsNo = remp.get("bussinessNo") + "";
                String vc = remp.get("vehicleId") + "";
                // 销售分单值: 本单位分单数量和重量 其他单位分车数量和重量
                if (vxlist != null) {
                    for (Vehicle_XSTD vehicle_XSTD : vxlist) {
                        try {
                            if (vehicle_XSTD.getVehicleId().equals(vc)) {
                                remp.put("fdCnum",
                                        Integer.parseInt(
                                                remp.get("fdCnum") == null ? "0" : remp.get("fdCnum").toString())
                                                + vehicle_XSTD.getFd_num());
                                remp.put("fdCweight", BigDecimalfiter.addscal(
                                        Double.parseDouble(
                                                remp.get("fdCweight") == null ? "0" : remp.get("fdCweight").toString()),
                                        vehicle_XSTD.getFd_weight(), 4));
                                if (lg.getDepartno() != null && lg.getDepartno().equals(vehicle_XSTD.getCompanyNo())) {
                                    remp.put("fdnum",
                                            Double.parseDouble(
                                                    remp.get("fdnum") == null ? "0" : remp.get("fdnum").toString())
                                                    + vehicle_XSTD.getFd_num());
                                    remp.put("fdweight",
                                            BigDecimalfiter.addscal(
                                                    Double.parseDouble(remp.get("fdweight") == null ? "0"
                                                            : remp.get("fdweight").toString()),
                                                    vehicle_XSTD.getFd_weight(), 4));
                                }
                            }
                        } catch (Exception e) {
                            prr.setCode(1);
                            prr.setErrmsg("数据转换错误,请刷新页面重新获取数据!");
                            return prr;
                        }
                    }
                }
                // 销售分单单位值:
                List<Fd_Company> cl = vhxper.getCompany(vc, bsNo);
                if (cl != null && cl.size() > 1) {
                    remp.remove("companyName");
                    remp.remove("companyNo");
                    for (Fd_Company fd_Company : cl) {
                        remp.put("companyName", fd_Company.getName()
                                + (remp.get("companyName") == null ? "" : "," + remp.get("companyName").toString()));
                        remp.put("companyNo", fd_Company.getCompanyNo()
                                + (remp.get("companyNo") == null ? "" : "," + remp.get("companyNo").toString()));
                    }
                }
                relist.add(remp);
            }
        }
        prr.setCode(0);
        prr.setList(relist);
        return prr;
    }
 
    @Override
    @Transactional
    public ObjectResult<Boolean> delFdsheet(Login lg, String bsNo) throws Exception{
        ObjectResult<Boolean> or = new ObjectResult<Boolean>();
        if (lg == null) {
            or.setCode(1);
            or.setErrmsg("请登录账号!");
            return or;
        }
        if (UserType.admin.toString().equals(lg.getWorkerno())) {
            or.setCode(1);
            or.setErrmsg("管理员不能执行分单操作!");
            return or;
        }
        Fd_Company fdc = fdcper.getByCompanyNo(lg.getDepartno());
        if (fdc == null) {
            or.setCode(1);
            or.setErrmsg("登录账号所属的物流公司不存在!");
            return or;
        }
        Fd_Bsheet fb = fdbsper.getbybsNo(bsNo);
        if (fb == null) {
            or.setCode(1);
            or.setErrmsg("分单业务单未找到!");
            return or;
        }
        if (fb.getStatus() != Serviceenum.在办) {
            or.setCode(1);
            or.setErrmsg("分单业务单状态不是在办状态!");
            return or;
        }
        String vehicleId = fb.getVehicleId();
        Fd_Vehicle fdv = vhper.getByVehicleId(vehicleId);
        if (fdv == null) {
            or.setCode(1);
            or.setErrmsg("分单系统未找到车牌号:" + vehicleId + " 车辆信息!");
            return or;
        }
        int zcsl = this.tdmxper.getbyBsNowith(bsNo,vehicleId);
        if (zcsl > 0) {
            or.setCode(1);
            or.setErrmsg("该车已经扫码装车,请先联系成品库删除装车记录并解绑磅单!");
            return or;
        }
        int wdNum = this.bsper.getweightDoc(vehicleId, bsNo);
        if (wdNum > 0) {
            or.setCode(1);
            or.setErrmsg("车辆:" + vehicleId + " 已经过磅,请先联系成品库解绑磅单!");
            return or;
        }
        List<Vehicle_XSTD> fdvcl = this.vhxper.getlistbyVehicleIdandbsNoGp(vehicleId, bsNo);
 
        // 判断是否删除业务单:如果两个物流公司使用同一辆车,不删除业务单,只修改该物流公司分单的信息
        String sdNo = fb.getSdepartNo();
        boolean delYWD = true;
        List<Vehicle_XSTD> vxl = new ArrayList<Vehicle_XSTD>();
        if (fdvcl != null) {
            for (Vehicle_XSTD vhxstd : fdvcl) {
                // 同一个业务单
                if (bsNo.equals(vhxstd.getBsNo())) {
                    if (lg.getDepartno().equals(vhxstd.getCompanyNo())) {
                        vxl.add(vhxstd);
                    } else {
                        delYWD = false;
                    }
                }
            }
        } else {
            or.setCode(1);
            or.setErrmsg("该业务单未找到分单记录!");
            return or;
        }
 
        // 发送NC
        List<Fd_XSTD> tdl = new ArrayList<Fd_XSTD>();
        Map<String, List<Fd_XSTDMX>> mxMp = new HashMap<String, List<Fd_XSTDMX>>();
 
        if (vxl != null && vxl.size() > 0) {
            Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(),"取消配车业务单  vheicle_xstd ::" + Jacksonmethod.tojson(vxl, false));
            for (Vehicle_XSTD VX : vxl) {
                String xstdNo = VX.getXstdNo();
                List<Fd_XSTDMX> mxl = new ArrayList<Fd_XSTDMX>();
                Fd_XSTD xstd = this.tdper.getbyTDBH(xstdNo);
                List<Fd_XSTDMX> MXL = this.tdmxper.getbyBsNoandcmNo(xstd.getTd_tdls(), bsNo, lg.getDepartno());
                double ZZL = 0;
                int ZZS = 0;
                for (Fd_XSTDMX MX : MXL) {
//                    // 已经关闭的不做处理
//                    if (MX.getTdmx_gbbz() != 0) {
//                        continue;
//                    }
                    // 没有分单的跳过
//                    if (MX.getTdmx_fdbz() == 0) {
//                        MX.setTdmx_fdcph(null);
//                        MX.setTdmx_fdwlgsbh(null);
//                        MX.setTdmx_fdywbh(null);
//                        this.tdmxper.updateFD(MX);
//                        continue;
//                    }
                    // 已经装车的不做处理
//                    if (MX.getTdmx_zcbz() != 0) {
//                        or.setCode(1);
//                        or.setErrmsg("提单:" + xstd.getTd_tdbh() + " 明细:" + MX.getTdmx_pch() + " 已经装车不能取消配车!");
//                        return or;
//                    }
                    // 提单流水号
                    ZZL = BigDecimalfiter.addscal(ZZL, MX.getTdmx_mz(), Contants.scale);
                    ZZS++;
                    MX.setTdmx_fdbz(0);
                    MX.setTdmx_fdcph(null);
                    MX.setTdmx_fdwlgsbh(null);
                    MX.setTdmx_fdywbh(null);
//                    this.tdmxper.updateFD(MX);
                    mxl.add(MX);
                }
                this.tdmxper.updatebyBsNoandcmNo(xstd.getTd_tdls(), bsNo, lg.getDepartno());
 
                this.vhxper.delbyIDs(vehicleId, xstdNo, lg.getDepartno());
 
                xstd.setTd_wfdsl(xstd.getTd_wfdsl() + ZZS);
                xstd.setTd_wfdzl(BigDecimalfiter.addscal(xstd.getTd_wfdzl(), ZZL, Contants.scale));
                this.tdper.updateFD(xstd);
                if (ZZS > 0) {
                    tdl.add(xstd);
                    mxMp.put(xstdNo, mxl);
                }
            }
        } else {
            Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(),
                    "取消配车业务单  vehicleId ::" + vehicleId + "::::dNo::::" + lg.getDepartno());
            sdNo = fb.getSdepartNo();
        }
        if (StringUtils.isBlank(sdNo)) {
            or.setCode(1);
            or.setErrmsg("业务单元未找到不能删除一卡通业务单");
            return or;
        }
 
        this.fdvcper.del(vehicleId, lg.getDepartno(), fb.getSdepartNo());
 
        // 发送NC系统删除分单信息
        if (tdl != null && tdl.size() > 0) {
            Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(),
                    "取消配车业务单  请求提单 ::" + Jacksonmethod.tojson(tdl, false));
            Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(),
                    "取消配车业务单  请求提单明细 ::" + Jacksonmethod.tojson(mxMp, false));
            String fdhx = this.fdtonc.getNcdata(tdl, mxMp);
            Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "取消配车业务单  请求参数 ::" + fdhx);
            JsonObject joADDYWD = Wxhtmethod.postJsonStr(Contants.NCfdhx_url, fdhx);
            Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "取消配车业务单 返回值 ::" + joADDYWD);
            if (joADDYWD == null || JSONobj.getint(joADDYWD, "code") != 0) {
                throw new Exception(
                        (joADDYWD.get("msg")==null||StringUtils.isBlank(joADDYWD.get("msg").getAsString())) ? "分单回写NC系统出错!"
                        : joADDYWD.get("msg").getAsString());
            } else {
                String restult = joADDYWD.get("result").getAsString();
                JsonParser jp = new JsonParser();
                JsonObject jr = jp.parse(restult).getAsJsonObject();
                if (jr == null || JSONobj.getint(jr, "respcode") != 111) {
                    throw new Exception(jr.get("respmsg").getAsString());
                }
            }
        }
 
        if (delYWD) {
            if (fdv.getType() == VehicleType.临时车) {
                Fd_Bsheet fdbb=this.fdbsper.getbyVehicleWithNoSdepartNo(vehicleId, fb.getSdepartNo());
                if(fdbb==null)
                    this.vhper.delByVehicleId(vehicleId);
            } else {
                fdv.setStatus(VehicleStatus.未配车);
                this.vhper.update(fdv);
            }
            this.fdbsper.delbybsNo(bsNo);
 
            // 发送一卡通服务删除表头信息
            JsonObject jo = new JsonObject();
            jo.addProperty("bussinessNo", bsNo);
            jo.addProperty("sdepartNo", sdNo);
            JsonObject pfob = Wxhtmethod.postJsonStr(Contants.YKTdelYwd_url, jo.toString());
            int code = JSONobj.getint(pfob, "code");
            if (code != 0) {
                throw new Exception(JSONobj.getstring(pfob, "errmsg"));
            }
 
        }
        // 删除车辆分单的备注remark
        fdVehicleRemarkMapper.deleteByBusinessNo(bsNo);
        or.setCode(0);
        or.setItem(true);
        return or;
    }
 
    @Override
    public PageResult<WaitXSTDMX> getVehicleDetails(Login lg, String bsNo) {
        PageResult<WaitXSTDMX> pr = new PageResult<WaitXSTDMX>();
        if (lg == null) {
            pr.setCode(1);
            pr.setErrmsg("请登录账号!");
            return pr;
        }
        if (StringUtils.isBlank(bsNo)) {
            pr.setCode(1);
            pr.setErrmsg("查询参数不能为空!");
            return pr;
        }
        Fd_Bsheet fb = this.fdbsper.getbybsNo(bsNo);// fdbsper.getbyVehicleId(vehicleId,Serviceenum.在办);
        if (fb == null) {
            pr.setCode(1);
            pr.setErrmsg("该车辆没有在办的业务单!");
            return pr;
        }
        if (fb.getStatus() != Serviceenum.在办) {
            pr.setCode(1);
            pr.setErrmsg("车辆业务单不是在办状态,不能打印!");
            return pr;
        }
        Fd_Company fdc = null;
        List<WaitXSTDMX> mxl = new ArrayList<WaitXSTDMX>();
        if (!UserType.admin.toString().equals(lg.getWorkerno())) {
            fdc = fdcper.getByCompanyNo(lg.getDepartno());
            if (fdc == null) {
                pr.setCode(1);
                pr.setErrmsg("物流公司不存在!");
                return pr;
            }
            // 直接根据业务单号 车牌号 分单标志查找 fd_xstdmx表
            mxl = this.tdmxper.getwaitMXbyBsNoandcmNo(fb.getBsNo(), lg.getDepartno());
        } else {
            mxl = this.tdmxper.getwaitMXbyBsNo(fb.getBsNo());
        }
        pr.setCode(0);
        pr.setList(mxl);
        return pr;
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ObjectResult<Boolean> doBindByList(Login lg, String tdlist, String vehicleInfo) throws Exception {
        ObjectResult<Boolean> orr = new ObjectResult<Boolean>();
        if (StringUtils.isBlank(tdlist)) {
            orr.setCode(1);
            orr.setErrmsg("提单编号参数为空!");
            return orr;
        }
        if (StringUtils.isBlank(vehicleInfo)) {
            orr.setCode(1);
            orr.setErrmsg("车辆信息参数为空!");
            return orr;
        }
        if (lg == null) {
            orr.setCode(1);
            orr.setErrmsg("账号未登录,请登录账号!");
            return orr;
        }
        if (UserType.admin.toString().equals(lg.getWorkerno())) {
            orr.setCode(1);
            orr.setErrmsg("管理员账号没有分单权限!");
            return orr;
        }
        Fd_Company fdc = null;
        if (StringUtils.isNotBlank(lg.getDepartno())) {
            fdc = fdcper.getByCompanyNo(lg.getDepartno());
            if (fdc == null) {
                orr.setCode(1);
                orr.setErrmsg("登录账号没有配置物流公司,请联系管理员配置!");
                return orr;
            }
        }
        JsonParser jp = new JsonParser();
        Fd_Vehicle fdv1 = new Fd_Vehicle();
        // 检查车辆信息
        try {
            JsonElement je = jp.parse(vehicleInfo);
            JsonObject jo = je.getAsJsonObject();
            String vehicleId =JSONobj.getstring(jo, "vehicleId")==null?"":
                JSONobj.getstring(jo, "vehicleId").trim().toUpperCase();
            String driver = JSONobj.getstring(jo, "driver");
            String phone = JSONobj.getstring(jo, "phone");
            double vehicleweight = JSONobj.getdouble(jo, "vehicleweight");
            double loadweight = JSONobj.getdouble(jo, "loadweight");
            String feature = JSONobj.getstring(jo, "feature");
            String note = JSONobj.getstring(jo, "note");
            String IDNum = JSONobj.getstring(jo, "IDNum");
            if (StringUtils.isBlank(vehicleId) || StringUtils.isBlank(driver) || StringUtils.isBlank(IDNum)
                    || StringUtils.isBlank(phone)) {
                orr.setCode(1);
                orr.setErrmsg("车辆信息必填项:车牌号,司机姓名,身份证号,手机号不能为空!");
                return orr;
            }
            fdv1.setCompanyNo(lg.getDepartno());
            fdv1.setDriver(driver);
            fdv1.setFeature(feature);
            fdv1.setId(UUID.randomUUID() + "");
            fdv1.setIDNum(IDNum);
            fdv1.setLoadweight(loadweight);
            fdv1.setNote(note);
            fdv1.setPhone(phone);
            fdv1.setState(true);
            fdv1.setStatus(VehicleStatus.未配车);
            fdv1.setType(VehicleType.临时车);
            fdv1.setVehicleId(vehicleId);
            fdv1.setVehicleweight(vehicleweight);
        } catch (Exception e) {
            orr.setCode(1);
            orr.setErrmsg("车辆信息解析出错,请重新操作!");
            return orr;
        }
 
        String Rcompany = "";// 收货单位
        String bsDE = "";// 系统部门
        String ziti = "";// 是否自提
        List<Fd_XSTD> tdl = new ArrayList<Fd_XSTD>();
 
        //校验提单信息数据是否合法:1.提单是否存在 2.当前账号是否可以操作该提单
        JsonArray tdja = jp.parse(tdlist).getAsJsonArray();
        for (JsonElement tdje : tdja) {
            String tdNo = tdje.getAsString();
            if (StringUtils.isNotBlank(tdNo)) {
                Fd_XSTD td = this.tdper.getbyTDBH(tdNo);
                if (td == null || td.getTd_wfdsl()<=0 ) {
                    continue;
                }
 
                // 这一块是判断用户有没有这个提单的操作权限 :
                //1.在页面获取提单列表的时候已经加过校验,同一厂区的提单可以同时显示不同厂区的提单不能同时显示,用户只能同时操作同一厂区的提单
                //当前用户只能看到可以操作的提单  不可以操作的提单看不到
                //所有以下else操作去掉
                if (StringUtils.isBlank(bsDE)) {
                    bsDE = ConvertTool.ncCovertToYkt(td.getTd_cqNo());
                }
                if (StringUtils.isBlank(ziti)) {
                    ziti = td.getTd_ztbz() == 2 ? "自提" : "非自提";
                }
                if (StringUtils.isBlank(Rcompany)) {
                    Map<String, Object> mm = this.dqper.getKH(td.getTd_khbh());
                    /*
                    * 1、外贸有发票编号,内贸没有发票编号
                    * 2、内贸取实际公司名称,外贸取相应组织的公司简称+‘报关’
                    * */
                    if (StringUtils.isBlank(td.getTd_fpbh())) {
                        if (mm != null) {
                            Rcompany = mm.get("name") == null ? "" : mm.get("name").toString();
                        }
                        if(mm == null || mm.size() == 0) { // 客户必须存在,否则无法分单
                            orr.setCode(1);
                            orr.setErrmsg("该提单客户不存在,请检查数据!");
                            return orr;
                        }
                    } else {
                        Rcompany = ConvertTool.covertToCustoms(td.getTd_ywdybh());
                    }
                }
                tdl.add(td);
            }
        }
 
        // 系统部门未找到
        if (StringUtils.isBlank(bsDE)) {
            orr.setCode(1);
            orr.setErrmsg("提单未找到系统部门字段,请重新操作!");
            return orr;
        }
 
 
        boolean saveBT = false;// 保存一卡通业务单表头信息
        String bsNo="";
        // 保存表相关信息
        try {
            // 保存业务单
            Fd_Bsheet fb = this.fdbsper.getbyVehicleId(fdv1.getVehicleId(), Serviceenum.在办, bsDE);
            if (fb == null) {
//                // 获取业务单号  建议加上 记录一下开始时间和结束时间 判断地方的请求时间
                JsonObject pfob = Wxhtmethod.postJsonStr(Contants.YKTgetPrefix_url, PrefixEnum.productsale.toString());
                ObjectResult<String> pfor = new ObjectResult<String>();
                String bssNo = JSONobj.getstring(pfob, "item");
                int code = JSONobj.getint(pfob, "code");
                String errmsg = JSONobj.getstring(pfob, "errmsg");
                pfor.setCode(code);
                pfor.setErrmsg(errmsg);
                pfor.setItem(bssNo);
                if (pfor == null || pfor.getCode() != 0) {
                    orr.setCode(1);
                    orr.setErrmsg(pfor.getErrmsg());
                    return orr;
                }
                fb = new Fd_Bsheet();
                fb.setBsNo(pfor.getItem());
                fb.setCompanyName(lg.getDepartname());
                fb.setCompanyNo(lg.getDepartno());
                fb.setCreateid(lg.getUserid());
                fb.setCreateName(lg.getWorkername());
                fb.setCtime(new Date());
                fb.setDriver(fdv1.getDriver());
                fb.setFdsheetNo(pfor.getItem());
                fb.setId(UUID.randomUUID() + "");
                fb.setPhone(fdv1.getPhone());
                fb.setSendmsg(false);
                fb.setStatus(Serviceenum.在办);
                fb.setVehicleId(fdv1.getVehicleId());
                fb.setSdepartNo(bsDE);
                fb.setShdw(StringUtils.isBlank(Rcompany) ? "未知发货单位" : Rcompany);
                fb.setUpdateTime(new Date());
                this.fdbsper.insertAll(fb);
                saveBT=true;
                bsNo=bssNo;
            } else {
                fb.setDriver(fdv1.getDriver());
                fb.setPhone(fdv1.getPhone());
                fb.setUpdateTime(new Date());
                fdbsper.update(fb);
                bsNo=fb.getBsNo();
            }
 
            // 保存车辆信息
            Fd_Vehicle fdv = this.vhper.getByVehicleId(fdv1.getVehicleId());
            if (fdv == null) {
                vhper.insert(fdv1);
            } else {
                if (fdv.getType() == VehicleType.临时车) {
                    fdv.setDriver(fdv1.getDriver());
                    fdv.setPhone(fdv1.getPhone());
                    fdv.setIDNum(fdv1.getIDNum());
                    vhper.update(fdv);
                }
            }
            Fd_Company_Vehicle fdcv = fdvcper.getbyIDs(fdv1.getVehicleId(), lg.getDepartno(), bsDE);
            if (fdcv == null) {
                fdcv = new Fd_Company_Vehicle();
                fdcv.setCompanyNo(lg.getDepartno());
                fdcv.setVehicleId(fdv1.getVehicleId());
                fdcv.setSdepartNo(bsDE);
                fdvcper.insertIDs(fdcv);
            }
 
            // 保存分单表相关信息
            Map<String, List<Fd_XSTDMX>> mxMp = new HashMap<String, List<Fd_XSTDMX>>();
            if(tdl!=null&&!tdl.isEmpty()) {
                for (Fd_XSTD td : tdl) {
                    int fdsl = 0;
                    double fdmz = 0;
                    List<Fd_XSTDMX> mxl = this.tdmxper.getNOZCandFD(td.getTd_tdls());
                    if (mxl == null || mxl.isEmpty()) {
                        continue;
                    }
                    for (Fd_XSTDMX tdmx : mxl) {
                        fdsl++;
                        fdmz = BigDecimalfiter.addscal(fdmz, tdmx.getTdmx_mz(), Contants.scale);
                        tdmx.setTdmx_fdbz(1);
                        tdmx.setTdmx_fdcph(fdv1.getVehicleId());
                        tdmx.setTdmx_fdywbh(bsNo);
                        tdmx.setTdmx_fdwlgsbh(lg.getDepartno());
                    }
 
                    Fd_XSTDMX tdmx=mxl.get(0);
                    tdmx.setTdmx_fdbz(1);
                    tdmx.setTdmx_fdcph(fdv1.getVehicleId());
                    tdmx.setTdmx_fdywbh(bsNo);
                    tdmx.setTdmx_fdwlgsbh(lg.getDepartno());
                    tdmx.setTdmx_tdls(td.getTd_tdls());
                    this.tdmxper.updateFDBatch(tdmx);
 
                    Vehicle_XSTD vhx=this.vhxper.getbyIDs(fdv1.getVehicleId(), td.getTd_tdbh(),lg.getDepartno());
                    if(vhx==null){
                        vhx=new Vehicle_XSTD();
                        vhx.setBsNo(bsNo);
                        vhx.setCompanyNo(lg.getDepartno());
                        vhx.setFd_num(fdsl);
                        vhx.setFd_weight(fdmz);
                        vhx.setVehicleId(fdv1.getVehicleId());
                        vhx.setXstdNo(td.getTd_tdbh());
                         this.vhxper.insert(vhx);
                    }else{
                        vhx.setBsNo(bsNo);
                        vhx.setCompanyNo(lg.getDepartno());
                        vhx.setFd_num(vhx.getFd_num()+fdsl);
                        vhx.setFd_weight(BigDecimalfiter.add(vhx.getFd_weight(),fdmz));
                        vhx.setVehicleId(fdv1.getVehicleId());
                        vhx.setXstdNo(td.getTd_tdbh());
                        this.vhxper.updatewithIDs(vhx);
                    }
                    td.setTd_wfdsl(td.getTd_wfdsl() - fdsl);
                    td.setTd_wfdzl(BigDecimalfiter.subscal(td.getTd_wfdzl(), fdmz, Contants.scale));
                    this.tdper.updateFD(td);
                    mxMp.put(td.getTd_tdbh(), mxl);
                }
            }
 
            if (saveBT) {
                YktBsheet bs = new YktBsheet();
                bs.setSdepartNo(bsDE);
                /*bs.setDcompany(
                        bsDE.equals(Contants.kjSdepartNo) ? "明泰科技"
                        :bsDE.equals(Contants.msSdepartNo) ? "河南明晟新材料"
                        : "郑州眀泰");*/
                bs.setDcompany(ConvertTool.covertToFactoryName(bsDE));
                bs.setDriver(fdv1.getDriver());
 
                bs.setNumberplates(StringUtils.upperCase(fdv1.getVehicleId()));
                bs.setPhone(fdv1.getPhone());
                bs.setRcompany(StringUtils.isBlank(Rcompany) ? "未知发货单位" : Rcompany);
                bs.setBussinessNo(fb.getBsNo());
                bs.setNote(ziti + ";" + lg.getDepartname() + ":" + lg.getWorkername() + "; 分单系统自动生成");
                String bsStr = Jacksonmethod.tojson(bs, false);
                JsonObject joADDYWD = Wxhtmethod.postJsonStr(Contants.YKTaddYwd_url, bsStr);
                ObjectResult<String> ors = new ObjectResult<String>();
                ors = JSONobj.getobj(joADDYWD, ors);
                if (ors.getCode() != 0) {
                    throw new Exception(ors.getErrmsg());
                }
            }else {
                List<WaitXSTD> l=this.fdbsper.getAllKH(bsNo, fb.getId());
                if(l!=null) {
                    boolean iscz=false;//收货单位在明细中是否存在
                    WaitXSTD wt=null;
                    for (WaitXSTD waitXSTD : l) {
                        if(fb.getShdw().equals(waitXSTD.getTd_khmc())) {
                            iscz=true;
                            break;
                        }else {
                            if(wt==null&&StringUtils.isNotBlank(waitXSTD.getTd_khmc())) {
                                wt=waitXSTD;
                            }
                        }
                    }
                    if(!iscz&&wt!=null) {
                        fb.setShdw(wt.getTd_khmc());
                        this.yktmper.updateshcompany(bsNo, wt.getTd_khmc(),wt.getTd_shdd());
                    }
                }
 
            }
 
            if (tdl != null && tdl.size() > 0 ) {
                String fdhx = this.fdtonc.getNcdata(tdl, mxMp);
                Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "整单配车 请求参数 ::" + fdhx);
                JsonObject joADDYWD = Wxhtmethod.postJsonStr(Contants.NCfdhx_url, fdhx);
                Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "整单配车 返回值 ::" + joADDYWD);
                if (joADDYWD == null || JSONobj.getint(joADDYWD, "code") != 0) {
                    throw new Exception(
                            (joADDYWD.get("msg")==null||StringUtils.isBlank(joADDYWD.get("msg").getAsString())) ? "分单回写NC系统出错!"
                            : joADDYWD.get("msg").getAsString());
                } else {
                    String restult = joADDYWD.get("result").getAsString();
                    JsonObject jr = jp.parse(restult).getAsJsonObject();
                    if (jr == null || JSONobj.getint(jr, "respcode") != 111) {
                        throw new Exception(jr.get("respmsg").getAsString());
                    }
                }
            }
        } catch (Exception e) {
            if (saveBT) {
                JsonObject jo = new JsonObject();
                jo.addProperty("bussinessNo", bsNo);
                jo.addProperty("sdepartNo", bsDE);
                Wxhtmethod.postJsonStr(Contants.YKTdelYwd_url, jo.toString());
            }
            e.printStackTrace();
            throw new Exception(e.getMessage());
        }
        orr.setCode(0);
        orr.setItem(true);
        return orr;
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ObjectResult<Boolean> dounBindByList(Login lg, String tdbhlist) throws Exception {
        ObjectResult<Boolean> orr = new ObjectResult<Boolean>();
        if (lg == null) {
            orr.setCode(1);
            orr.setErrmsg("请登录账号!");
            return orr;
        }
        if (StringUtils.isBlank(tdbhlist)) {
            orr.setCode(1);
            orr.setErrmsg("业务参数为空,请选择提单!");
            return orr;
        }
        if (UserType.admin.toString().equals(lg.getWorkerno())) {
            orr.setCode(1);
            orr.setErrmsg("管理员不能操作分单!");
            return orr;
        }
        Fd_Company fdc = null;
        if (StringUtils.isNotBlank(lg.getDepartno())) {
            fdc = fdcper.getByCompanyNo(lg.getDepartno());
            if (fdc == null) {
                orr.setCode(1);
                orr.setErrmsg("账号没有配置物流公司,请联系管理员进行配置!");
                return orr;
            }
        }
 
        // for循环 tdbhlist
        // 查找td_xstd 对象 筛选是否有操作权限
        // 修改 td_xstdmx 表 修改 td_xstd 表 修改 vehicle_xstd表
        JsonParser jp = new JsonParser();
        JsonArray tdja = jp.parse(tdbhlist).getAsJsonArray();
        List<Fd_XSTD> tdl = new ArrayList<Fd_XSTD>();
        Map<String, List<Fd_XSTDMX>> mxMp = new HashMap<String, List<Fd_XSTDMX>>();
        for (JsonElement tdje : tdja) {
            String tdNo = tdje.getAsString();
            Fd_XSTD td = this.tdper.getbyTDBH(tdNo);
            if (td == null) {
                continue;
            }
            // 这一块是判断用户有没有这个提单的操作权限 :
            //页面获取提单里诶包信息的时候已经加过校验  当前用户只能看到可以操作的提单  不可以操作的提单看不到
            // 这一块可以省略
            // 自提
//            if (td.getTd_ztbz() == 2) {
//                if (fdc != null) {
//                    if (!fdc.isHasSPR()) {
//                        continue;
//                    }
//                }
//            } else {
//                Fd_wlgs_fhdq dq = this.dqper.getbyNos(lg.getDepartno(), td.getTd_shddbh(),
//                        td.getTd_ywdybh().equals(Contants.zzywdyNo) ? Contants.zzywdyNo : "103");
//                if (dq == null) {
//                    continue;
//                }
//            }
 
 
            // 如果该业务单已经装车 过滤掉不处理
            //这一块应该在页面中提示出来:提示:销售提单:XXXX 部分明细已经装车,请进入提单明细取消配车!
            List<Vehicle_XSTD> vxl = this.vhxper.getbyxstdNoandcmNo(tdNo, lg.getDepartno());
            if (vxl != null) {
                boolean sffd=false;
                for (Vehicle_XSTD vx : vxl) {
                    int zcsl = this.tdmxper.getbyBsNowithZC(vx.getBsNo(),td.getTd_tdls(),vx.getVehicleId());
                    if (zcsl > 0) {
                        sffd=true;
                        break;
                    }
                    Fd_Bsheet fb=this.fdbsper.getbyVehicleId(vx.getVehicleId(), Serviceenum.在办, lg.getSdepartNo());
                    if(fb !=null) {
                        fb.setUpdateTime(new Date());
                        this.fdbsper.update(fb);
                    }
                }
                if(sffd) {
                    continue;
                }
            } else {
                continue;
            }
 
 
            List<Fd_XSTDMX> mxl = this.tdmxper.getbytdlsandcmNo(td.getTd_tdls(), lg.getDepartno());
            List<Fd_XSTDMX> rels = new ArrayList<Fd_XSTDMX>();
            if (mxl != null) {
                int wfdsl = 0;
                double wfdzl = 0;
                for (Fd_XSTDMX mx : mxl) {
                    // 提单明细未关闭的做处理
                    wfdsl++;
                    wfdzl = BigDecimalfiter.addscal(wfdzl, mx.getTdmx_mz(), Contants.scale);
                    mx.setTdmx_fdbz(0);
                    mx.setTdmx_fdcph(null);
                    mx.setTdmx_fdwlgsbh(null);
                    mx.setTdmx_fdywbh(null);
                    rels.add(mx);
                }
 
                this.tdmxper.updatebytdlsandcmNo(td.getTd_tdls(), lg.getDepartno());
 
                this.vhxper.delbyIDandcomNo(td.getTd_tdbh(),lg.getDepartno());
 
                td.setTd_wfdsl(td.getTd_wfdsl() + wfdsl);
                td.setTd_wfdzl(BigDecimalfiter.addscal(td.getTd_wfdzl(), wfdzl, Contants.scale));
                this.tdper.updateFD(td);
                if (wfdsl > 0) {
                    tdl.add(td);
                    mxMp.put(tdNo, rels);
                }
            }
        }
 
 
        // 发送NC系统
        if (tdl != null && tdl.size() > 0) {
            String fdhx = this.fdtonc.getNcdata(tdl, mxMp);
            Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "整单取消配车 请求参数 ::" + fdhx);
            JsonObject joADDYWD = Wxhtmethod.postJsonStr(Contants.NCfdhx_url, fdhx);
            Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "整单取消配车 返回值 ::" + joADDYWD);
            if (joADDYWD == null || JSONobj.getint(joADDYWD, "code") != 0) {
                throw new Exception(
                        (joADDYWD.get("msg")==null||StringUtils.isBlank(joADDYWD.get("msg").getAsString())) ? "分单回写NC系统出错!"
                        : joADDYWD.get("msg").getAsString());
            } else {
                String restult = joADDYWD.get("result").getAsString();
                JsonObject jr = jp.parse(restult).getAsJsonObject();
                if (jr == null || JSONobj.getint(jr, "respcode") != 111) {
                    throw new Exception(jr.get("respmsg").getAsString());
                }
            }
        }
        orr.setCode(0);
        return orr;
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ObjectResult<Boolean> sxccCheck(String bsNo, String vehicleId, String ZZ) throws Exception {
        ObjectResult<Boolean> orr = new ObjectResult<Boolean>();
        Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(),"出门检查 业务参数:::: ::ZZ::" + ZZ + "::bsNo::" + bsNo + "::vehicleId::" + vehicleId);
        if (StringUtils.isBlank(vehicleId)) {
            orr.setCode(1);
            orr.setErrmsg("车牌号为空!");
            return orr;
        }
        if (StringUtils.isBlank(bsNo)) {
            orr.setCode(1);
            orr.setErrmsg("一卡通业务单号为空!");
            return orr;
        }
        //先删除错误信息
        errPer.delBybsNo(bsNo);
        try {
            Fd_Bsheet fdb = fdbsper.getbybsNo(bsNo);
            if (fdb != null) {
                fdb.setStatus(Serviceenum.结束);
                fdbsper.update(fdb);
            }
            Fd_Vehicle fdv = vhper.getByVehicleId(vehicleId);
            if (fdv != null) {
                if (fdv.getType() == VehicleType.临时车) {
                    Fd_Bsheet fdbb=this.fdbsper.getbyVehicleWithNoSdepartNo(vehicleId,fdb.getSdepartNo());
                    if(fdbb==null) {
                        vhper.delByVehicleId(vehicleId);
                    }
                    this.fdvcper.delbyID(vehicleId, fdb.getSdepartNo());
                } else {
                    fdv.setStatus(VehicleStatus.未配车);
                    vhper.update(fdv);
                    this.fdvcper.delIDandNoC(vehicleId, fdv.getCompanyNo(), fdb.getSdepartNo());
                }
            }
            // 查找fd_vehicle 判断车辆信息是否正确 修改 fd_vehicle 修改fd_vehicle_company
            // 查找fd_bsheet 判断业务状态 修改 fd_bsheet
            // 查找fd_xstdmx 表 按照业务单号,车牌号,查找已分单未装车的
            // 修改 fd_xstdmx fd_xstd fd_vehicle_xstd
 
            List<Fd_XSTDMX> mxl = this.tdmxper.getbybsNoandNOZCandFD(fdb == null ? "" : fdb.getBsNo());
            List<Fd_XSTD> tdl = new ArrayList<Fd_XSTD>();
            Map<String, Fd_XSTD> tdM = new HashMap<String, Fd_XSTD>();
            Map<String, List<Fd_XSTDMX>> mxMp = new HashMap<String, List<Fd_XSTDMX>>();
 
//            Map<String, Fd_XSTD> rmtd = new HashMap<String, Fd_XSTD>();
            if (mxl != null) {
                for (Fd_XSTDMX mx : mxl) {
                    // 已经关闭的明细不做处理
                    if (mx.getTdmx_gbbz() != 0) {
                        continue;
                    }
//                    Fd_XSTD td = this.tdper.get(mx.getTdmx_tdls());
//                    if (td != null) {
//                        td.setTd_wfdsl(td.getTd_wfdsl() + 1);
//                        td.setTd_wfdzl(BigDecimalfiter.addscal(td.getTd_wfdzl(), mx.getTdmx_mz(), Contants.scale));
//                        tdper.updateFD(td);
//                        tdM.put(td.getTd_tdbh(), td);
//                    }
                    Fd_XSTD tdtt=tdM.get(mx.getTdmx_tdls());
                    if(tdtt==null) {
                        tdtt = this.tdper.get(mx.getTdmx_tdls());
                        if(tdtt==null) {
                            continue;
                        }
                    }
                    tdtt.setTd_wfdsl(tdtt.getTd_wfdsl()+1);
                    tdtt.setTd_wfdzl(BigDecimalfiter.addscal(tdtt.getTd_wfdzl(), mx.getTdmx_mz(), Contants.scale));
                    tdM.put(mx.getTdmx_tdls(), tdtt);
 
                    mx.setTdmx_fdbz(0);
                    mx.setTdmx_fdcph(null);
                    mx.setTdmx_fdwlgsbh(null);
                    mx.setTdmx_fdywbh(null);
//                    this.tdmxper.updateFD(mx);
                    if (mxMp.get(tdtt.getTd_tdbh()) != null) {
                        List<Fd_XSTDMX> lr = mxMp.get(tdtt.getTd_tdbh());
                        lr.add(mx);
                        mxMp.put(tdtt.getTd_tdbh(), lr);
                    } else {
                        List<Fd_XSTDMX> lr = new ArrayList<Fd_XSTDMX>();
                        lr.add(mx);
                        mxMp.put(tdtt.getTd_tdbh(), lr);
                    }
                }
                this.tdmxper.updatebybsNoandNOZCandFD(fdb.getBsNo());
 
                this.vhxper.delbyVehicleId(vehicleId,fdb.getBsNo() );
 
                if (tdM != null && tdM.size() > 0) {
                    for (Entry<String, Fd_XSTD> ff : tdM.entrySet()) {
                        tdl.add(ff.getValue());
                        this.tdper.updateFD(ff.getValue());
                    }
                }
            }
 
 
//            List<Vehicle_XSTD> vxls = this.vhxper.getlistbyVehicleId(vehicleId);
//            if (vxls != null) {
//                for (Vehicle_XSTD vxx : vxls) {
//                    this.vhxper.delbyIDs(vehicleId, vxx.getXstdNo());
//                }
//            }
            // 发送NC系统
            if (tdl != null && tdl.size() > 0) {
                String fdhx = this.fdtonc.getNcdata(tdl, mxMp);
                Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "出门检查 请求参数 ::" + fdhx);
                JsonObject joADDYWD = Wxhtmethod.postJsonStr(Contants.NCfdhx_url, fdhx);
                Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "出门检查 返回值 ::" + joADDYWD);
                if (joADDYWD == null || JSONobj.getint(joADDYWD, "code") != 0) {
                    throw new Exception(
                            (joADDYWD.get("msg")==null||StringUtils.isBlank(joADDYWD.get("msg").getAsString())) ? "分单回写NC系统出错!"
                            : joADDYWD.get("msg").getAsString());
                } else {
                    String restult = joADDYWD.get("result").getAsString();
                    JsonParser jp = new JsonParser();
                    JsonObject jr = jp.parse(restult).getAsJsonObject();
                    if (jr == null || JSONobj.getint(jr, "respcode") != 111) {
                        throw new Exception(jr.get("respmsg").getAsString());
                    }
                }
            }
        } catch (Exception e) {
            log.error("销售业务车辆出厂程序" + e.getMessage(),e);
            throw new Exception(StringUtils.isEmpty(e.getMessage()) ? "销售业务车辆出厂程序出错!" : e.getMessage());
        }
        orr.setCode(0);
        return orr;
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ObjectResult<Boolean> doUnbind(Login lg, String mlist, String tdNo) throws Exception {
        ObjectResult<Boolean> orr = new ObjectResult<Boolean>();
        if (lg == null) {
            orr.setCode(1);
            orr.setErrmsg("请登录账号!");
            return orr;
        }
        if (StringUtils.isEmpty(mlist)) {
            orr.setCode(1);
            orr.setErrmsg("业务参数为空!");
            return orr;
        }
        if (StringUtils.isEmpty(tdNo)) {
            orr.setCode(1);
            orr.setErrmsg("提单编号为空!");
            return orr;
        }
        if (UserType.admin.toString().equals(lg.getWorkerno())) {
            orr.setCode(1);
            orr.setErrmsg("管理员没有分单权限!");
            return orr;
        }
        Fd_Company fdc = fdcper.getByCompanyNo(lg.getDepartno());
        if (fdc == null) {
            orr.setCode(1);
            orr.setErrmsg("该账号没有配置物流公司!");
            return orr;
        }
 
        // 查找fd_xstd表 判断物流公司是否有操作权限 如果有装车明细不让删除完
        // for循环mlist 判断 fd_xstdmx是否符合条件
        // 修改fd_xstdmx 表 修改 vehicle_xstd表 修改fd_company_xstd表:只在取消分单和出门的时候删除
        // 修改 fd_xstd 表
 
        Fd_XSTD td = this.tdper.getbyTDBH(tdNo);
        if (td == null) {
            orr.setCode(1);
            orr.setErrmsg("提单未找到!");
            return orr;
        }
        if (td.isTd_zcwcbz()) {
            orr.setCode(1);
            orr.setErrmsg("该提单已经完成装车,不能分单!");
            return orr;
        }
        // 自提
        if (td.getTd_ztbz() == 2) {
            if (fdc != null) {
                if (!fdc.isHasSPR()) {
                    orr.setCode(1);
                    orr.setErrmsg("该账号没有自提权限!");
                    return orr;
                }
            }
        } else {
            Fd_wlgs_fhdq wldq = this.dqper.getbyNos(lg.getDepartno(), td.getTd_shddbh(),
                    /*td.getTd_ywdybh().equals(Contants.nc_ywdy_ZZ) ? Contants.nc_ywdy_ZZ
                            :td.getTd_ywdybh().equals(Contants.nc_ywdy_MS) ? Contants.nc_ywdy_MS
                            : Contants.nc_ywdy_KJ*/
                    ConvertTool.ncGetDefault(td.getTd_ywdybh())
            );
 
            int total = fdMxWlgsMapper.selectCountByTdTdls(td.getTd_tdls());
            if (wldq == null && total == 0) {
                orr.setCode(1);
                orr.setErrmsg("当前账号所属物流公司没有配置该地区的分单权限!");
                return orr;
            }
        }
        JsonParser jp = new JsonParser();
        JsonArray mArr = jp.parse(mlist).getAsJsonArray();
        // 分单数量和毛重
        int fdsl = 0;
        double fdmz = 0;
        List<Fd_XSTD> tdl = new ArrayList<Fd_XSTD>();
        Map<String, List<Fd_XSTDMX>> mxMp = new HashMap<String, List<Fd_XSTDMX>>();
        List<Fd_XSTDMX> tdmxl = new ArrayList<Fd_XSTDMX>();
        Map<String, Fd_XSTD> rm=new HashMap<String, Fd_XSTD>();
        for (JsonElement mJe : mArr) {
            JsonObject jo = mJe.getAsJsonObject();
            // 提单分录号
            String tdfl = JSONobj.getstring(jo, "tdfl");
            String vehicleId = JSONobj.getstring(jo, "vehicleId");
            Fd_XSTDMX mx = this.tdmxper.get(tdfl);
            if (mx != null) {
                // 没有分单的跳过
                if (mx.getTdmx_fdbz() == 0) {
                    continue;
                }
                // 已经装车的报错
                if (mx.getTdmx_zcbz() != 0) {
                    continue;
                }
                // 没有关闭明细做处理
                if (mx.getTdmx_gbbz() == 0) {
                    fdsl++;
                    fdmz = BigDecimalfiter.addscal(fdmz, mx.getTdmx_mz(), Contants.scale);
 
                    Fd_XSTD ttr=rm.get(vehicleId+"_"+mx.getTdmx_fdwlgsbh());
                    if(ttr!=null) {
                        ttr.setTd_wfdsl(ttr.getTd_wfdsl()+1);
                        ttr.setTd_wfdzl(BigDecimalfiter.addscal(ttr.getTd_wfdzl(), mx.getTdmx_mz(), Contants.scale));
                        rm.put(vehicleId+"_"+mx.getTdmx_fdwlgsbh(), ttr);
                    }else {
                        ttr=new Fd_XSTD();
                        ttr.setTd_wfdsl(1);
                        ttr.setTd_wfdzl(BigDecimalfiter.addscal(0, mx.getTdmx_mz(), Contants.scale));
                        rm.put(vehicleId+"_"+mx.getTdmx_fdwlgsbh(), ttr);
                    }
                }
 
                mx.setTdmx_fdbz(0);
                mx.setTdmx_fdcph(null);
                mx.setTdmx_fdwlgsbh(null);
                mx.setTdmx_fdywbh(null);
                this.tdmxper.updateFD(mx);
                tdmxl.add(mx);
 
            }
        }
        Iterator<Entry<String, Fd_XSTD>> entries = rm.entrySet().iterator();
        while (entries.hasNext()) {
          Entry<String, Fd_XSTD> entry = entries.next();
          Vehicle_XSTD vxs = this.vhxper.getbyIDs(entry.getKey().split("_")[0], td.getTd_tdbh(),entry.getKey().split("_")[1]);
          if (vxs != null) {
              if (vxs.getFd_num() == 1) {
                  this.vhxper.delbyIDs(entry.getKey().split("_")[0], td.getTd_tdbh(),entry.getKey().split("_")[1]);
              } else {
                  vxs.setFd_num(vxs.getFd_num() - entry.getValue().getTd_wfdsl());
                  vxs.setFd_weight(BigDecimalfiter.subscal(vxs.getFd_weight(), entry.getValue().getTd_wfdzl(), Contants.scale));
                  this.vhxper.updatewithIDs(vxs);
              }
              Fd_Bsheet fb=this.fdbsper.getbyVehicleId(vxs.getVehicleId(), Serviceenum.在办, lg.getSdepartNo());
              if(fb !=null) {
                fb.setUpdateTime(new Date());
                this.fdbsper.update(fb);
             }
          }
        }
        td.setTd_wfdsl(td.getTd_wfdsl() + fdsl);
        td.setTd_wfdzl(BigDecimalfiter.addscal(td.getTd_wfdzl(), fdmz, Contants.scale));
        this.tdper.updateFD(td);
        if (fdsl > 0) {
            tdl.add(td);
            mxMp.put(td.getTd_tdbh(), tdmxl);
        }
 
        // 发送NC
        if (tdl != null && tdl.size() > 0) {
            String fdhx = this.fdtonc.getNcdata(tdl, mxMp);
            Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "明细取消配车 请求参数 ::" + fdhx);
            JsonObject joADDYWD = Wxhtmethod.postJsonStr(Contants.NCfdhx_url, fdhx);
            Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "明细取消配车 返回值 ::" + joADDYWD);
            if (joADDYWD == null || JSONobj.getint(joADDYWD, "code") != 0) {
                throw new Exception(
                        (joADDYWD.get("msg")==null||StringUtils.isBlank(joADDYWD.get("msg").getAsString())) ? "分单回写NC系统出错!"
                        : joADDYWD.get("msg").getAsString());
            } else {
                String restult = joADDYWD.get("result").getAsString();
                JsonObject jr = jp.parse(restult).getAsJsonObject();
                if (jr == null || JSONobj.getint(jr, "respcode") != 111) {
                    throw new Exception(jr.get("respmsg").getAsString());
                }
            }
        }
 
        orr.setCode(0);
        orr.setItem(true);
        return orr;
    }
 
    @Override
    public ObjectResult<String> tzPrint(String cardno, String ipadda,String cqNo) {
        ObjectResult<String> orr = new ObjectResult<String>();
        if (StringUtils.isBlank(cardno)) {
            orr.setCode(1);
            orr.setErrmsg("提单编号为空!");
            return orr;
        }
        if (StringUtils.isBlank(ipadda)) {
            orr.setCode(1);
            orr.setErrmsg("批次号为空!");
            return orr;
        }
        Map<String, Object> cardinuse = this.yktmper.getcardinuse(cardno);
        if (cardinuse == null) {
            orr.setCode(1);
            orr.setErrmsg("在用卡未找到!");
            return orr;
        }
        Fd_Vehicle fd_v = this.vhper.getByVehicleId(cardinuse.get("numberplates") + "");
        if (fd_v == null) {
            orr.setCode(1);
            orr.setErrmsg("车辆" + cardinuse.get("numberplates").toString() + "分单系统未找到!");
            return orr;
        }
        Fd_Bsheet fd_b = this.fdbsper.getbyVehicleId(fd_v.getVehicleId(), Serviceenum.在办, cqNo);
        if (fd_b == null) {
            orr.setCode(1);
            orr.setErrmsg("车辆未找到在办分单!");
            return orr;
        }
        String dyAdd = this.bsper.getUsedbyAdd();
        if (StringUtils.isBlank(dyAdd)) {
            orr.setCode(1);
            orr.setErrmsg("系统未设置打印地址!");
            return orr;
        }
        try {
            orr.setItem("http://" + dyAdd + Contants.GYPrintAdd + "&vehicleId="
                    + URLEncoder.encode(fd_v.getVehicleId(), "utf-8") + "&bsNo=" + fd_b.getBsNo() + "&phone="
                    + fd_b.getPhone() + "&comNo=");
            // log.info("::::::::::;"+orr.getItem());
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        // 存打印日志:方便以后查找
 
        orr.setCode(0);
        return orr;
 
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ObjectResult<Boolean> delbyPCH(Login lg, String tdNo, String pch, String cph,String bsNo) throws Exception {
        ObjectResult<Boolean> orr = new ObjectResult<Boolean>();
        if (lg == null) {
            orr.setCode(1);
            orr.setErrmsg("请登录账号!");
            return orr;
        }
        if (StringUtils.isEmpty(tdNo)) {
            orr.setCode(1);
            orr.setErrmsg("提单编号为空!");
            return orr;
        }
        if (StringUtils.isEmpty(pch)) {
            orr.setCode(1);
            orr.setErrmsg("批次号为空!");
            return orr;
        }
        Fd_Bsheet fdb = this.fdbsper.getbybsNo(bsNo);//getbyVehicleId(cph, Serviceenum.在办);
        if (fdb == null) {
            orr.setCode(1);
            orr.setErrmsg("车牌号:" + cph + " 业务单未找到!");
            return orr;
        }
        if (fdb.getStatus()!=Serviceenum.在办) {
            orr.setCode(1);
            orr.setErrmsg("车牌号:" + cph + " 业务单不是在办状态!");
            return orr;
        }
        Fd_Company fdc = fdcper.getByCompanyNo(lg.getDepartno());
        if (fdc == null) {
            orr.setCode(1);
            orr.setErrmsg("账号没有配置物流公司!");
            return orr;
        }
        // 根据提单号找到 fd_xstd 判断xstd数据
        // 根据批次号和提单流水号找到 fd_xstdmx 判断xstdmx数据
        // 如果是已经装车了 至少保留一件
        // 修改fd_xstdmx vehicle_xstd表
        Fd_XSTD td = this.tdper.getbyTDBH(tdNo);
        if (td == null) {
            orr.setCode(1);
            orr.setErrmsg("提单号:" + tdNo + " 未找到!");
            return orr;
        }
        // Fd_XSTDMX mx=this.tdmxper.getbyPCH(pch);
        Fd_XSTDMX mx = this.tdmxper.getbyPCHandTDNOONE(pch, td.getTd_tdbh());
        if (mx == null) {
            orr.setCode(1);
            orr.setErrmsg("提单明细未找到!");
            return orr;
        }
        if (mx.getTdmx_zcbz() != 0) {
            orr.setCode(1);
            orr.setErrmsg("明细已经装车不能删除!");
            return orr;
        }
        if (!mx.getTdmx_tdls().equals(td.getTd_tdls())) {
            orr.setCode(1);
            orr.setErrmsg("参数错误,明细不属于该提单!");
            return orr;
        }
        // 已经分单了未关闭
        if (mx.getTdmx_fdbz() != 0 && mx.getTdmx_gbbz() == 0) {
            fdb.setUpdateTime(new Date());
            this.fdbsper.update(fdb);
            List<Fd_XSTD> tdl = new ArrayList<Fd_XSTD>();
            Map<String, List<Fd_XSTDMX>> mxMp = new HashMap<String, List<Fd_XSTDMX>>();
            List<Fd_XSTDMX> mxl = new ArrayList<Fd_XSTDMX>();
 
            mx.setTdmx_fdbz(0);
            mx.setTdmx_fdcph(null);
            mx.setTdmx_fdwlgsbh(null);
            mx.setTdmx_fdywbh(null);
            this.tdmxper.updateFD(mx);
            Vehicle_XSTD vx = this.vhxper.getbyIDs(cph, tdNo,lg.getDepartno());
            if (vx != null) {
                if (vx.getFd_num() > 1) {
                    vx.setFd_num(vx.getFd_num() - 1);
                    vx.setFd_weight(BigDecimalfiter.subscal(vx.getFd_weight(), mx.getTdmx_mz(), Contants.scale));
                    this.vhxper.updatewithIDs(vx);
                } else {
                    this.vhxper.delbyIDs(cph, tdNo,lg.getDepartno());
                }
            }
            td.setTd_wfdsl(td.getTd_wfdsl() + 1);
            td.setTd_wfdzl(BigDecimalfiter.addscal(td.getTd_wfdzl(), mx.getTdmx_mz(), Contants.scale));
            this.tdper.updateFD(td);
            tdl.add(td);
            mxl.add(mx);
            mxMp.put(tdNo, mxl);
            // 发送NC
            if (tdl != null && tdl.size() > 0) {
                String fdhx = this.fdtonc.getNcdata(tdl, mxMp);
                Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "批次号取消配车 请求参数 ::" + fdhx);
                JsonObject joADDYWD = Wxhtmethod.postJsonStr(Contants.NCfdhx_url, fdhx);
                Fileoperation.AppendContentToFile(Fileoperation.gettestFileName(), "批次号取消配车 返回值 ::" + joADDYWD);
                if (joADDYWD == null || JSONobj.getint(joADDYWD, "code") != 0) {
                    throw new Exception(
                            (joADDYWD.get("msg")==null||StringUtils.isBlank(joADDYWD.get("msg").getAsString())) ? "分单回写NC系统出错!"
                            : joADDYWD.get("msg").getAsString());
                } else {
                    String restult = joADDYWD.get("result").getAsString();
                    JsonParser jp = new JsonParser();
                    JsonObject jr = jp.parse(restult).getAsJsonObject();
                    if (jr == null || JSONobj.getint(jr, "respcode") != 111) {
                        throw new Exception(jr.get("respmsg").getAsString());
                    }
                }
            }
 
        }
 
        orr.setCode(0);
        orr.setItem(true);
        return orr;
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ObjectResult<Boolean> closeXstd(String vehicleId, String driver, String phone, String xstdNo, Login lg)
            throws Exception {
        ObjectResult<Boolean> or = new ObjectResult<Boolean>();
        if (lg == null) {
            or.setCode(1);
            or.setErrmsg("请重新登录账号!");
            return or;
        }
        // 根据xstdNo查找fd_xstd信息 vehicle_xstd
        // 判断vehicle_xstd的销售提单的状态
        // 查找fd_xstdmx
        // for循环 list<fd_xstdmx> 获取未分单未装车
        // 修改fd_xstdmx 修改Fd_Gbxstd, Fd_Gbxstdmx,修改fd_xstd
        if (StringUtils.isEmpty(xstdNo)) {
            or.setCode(1);
            or.setErrmsg("销售提单号为空,不能执行该操作!");
            return or;
        }
        if (!StringUtils.isEmpty(vehicleId)) {
            if (!RegexCheck.isVehicleID(vehicleId)) {
                or.setCode(1);
                or.setErrmsg("请输入正确的车牌号!");
                return or;
            }
        }
        if (!StringUtils.isEmpty(phone)) {
            if (!RegexCheck.checkphone(phone)) {
                or.setCode(1);
                or.setErrmsg("请输入正确的手机号!");
                return or;
            }
        }
 
        Fd_Gbxstd gbtd = gbtdper.get(xstdNo);
        if (gbtd != null) {
            or.setCode(1);
            or.setErrmsg("销售提单:" + xstdNo + " 已经有关闭记录,不能保存重复的关闭记录!");
            return or;
        }
        List<Vehicle_XSTD> vxl = vhxper.getlistbytdNo(xstdNo);
        if (vxl != null && vxl.size() > 0) {
            or.setCode(1);
            or.setErrmsg("销售提单:" + xstdNo + " 已经分单给:" + vxl.get(0).getVehicleId() + ",不能执行该操作!");
            return or;
        }
        Fd_XSTD tdx = this.tdper.getbyttdbh(xstdNo);
        if (tdx == null) {
            or.setCode(1);
            or.setErrmsg("销售提单:" + xstdNo + "未找到,不能执行该操作!");
            return or;
        }
        Fd_Company fdc = new Fd_Company();
        if (!UserType.admin.toString().equals(lg.getWorkerno())) {
            fdc = fdcper.getByCompanyNo(lg.getDepartno());
            if (fdc == null) {
                or.setCode(1);
                or.setErrmsg("登录账号未指定物流公司!");
                return or;
            }
            // 自提
            if (tdx.getTd_ztbz() == 2) {
                if (!fdc.isHasSPR()) {
                    or.setCode(1);
                    or.setErrmsg("该账号没有操作该提单的权限!");
                    return or;
                }
            } else {
                String shdqbh = tdx.getTd_shddbh();
                Fd_wlgs_fhdq acb = this.dqper.getbyNos(lg.getDepartno(), shdqbh,
                        /*tdx.getTd_ywdybh().equals(Contants.nc_ywdy_ZZ) ? Contants.nc_ywdy_ZZ
                                :tdx.getTd_ywdybh().equals(Contants.nc_ywdy_MS) ? Contants.nc_ywdy_MS
                                : Contants.nc_ywdy_KJ*/
                    ConvertTool.ncGetDefault(tdx.getTd_ywdybh())
                );
 
                int total = fdMxWlgsMapper.selectCountByTdTdls(tdx.getTd_tdls());
                if (acb == null && total == 0) {
                    or.setCode(1);
                    or.setErrmsg("账号没有操作该提单的权限!");
                    return or;
                }
            }
        }
 
        List<Fd_XSTDMX> mxL = this.tdmxper.getforClose(tdx.getTd_tdls());
        int dd = 0;
        double cc = 0;
        if (mxL != null) {
            for (Fd_XSTDMX mx : mxL) {
                dd++;
                cc = BigDecimalfiter.addscal(cc, mx.getTdmx_mz(), Contants.scale);
                mx.setTdmx_zcbz(1);
                mx.setTdmx_zccph(vehicleId);
                mx.setTdmx_zcdriver(driver);
                mx.setTdmx_zcphone(phone);
                mx.setTdmx_zcwlgsName(lg.getDepartname());
                this.tdmxper.updateZCANDFD(mx);
                Fd_Gbxstdmx gb = this.gbtdmxper.get(mx.getTdmx_tdfl());
                if (gb == null) {
                    gb = new Fd_Gbxstdmx();
                    gb.setId(mx.getTdmx_tdfl());
                    gb.setTdfl(mx.getTdmx_tdfl());
                    gb.setPch(mx.getTdmx_pch());
                    gb.setTdNo(tdx.getTd_tdbh());
                    this.gbtdmxper.insert(gb);
                }
            }
        }
        tdx.setTd_wfdsl(0);
        tdx.setTd_wfdzl(0);
        this.tdper.updateFD(tdx);
        if (dd > 0) {
            gbtd = new Fd_Gbxstd();
            gbtd.setCompanyNo(lg.getDepartname() == null ? "管理员关闭" : lg.getDepartname());
            gbtd.setHSR(tdx.getTd_ztbz() == 2);
            gbtd.setTd_gbr(lg.getWorkername());
            gbtd.setTd_gbsj(new Date());
            gbtd.setTd_gbsl(dd);
            gbtd.setTd_gbzl(cc);
            gbtd.setVehicleId(vehicleId);
            gbtd.setXstdNo(xstdNo);
            this.gbtdper.insert(gbtd);
        }
 
        or.setCode(0);
        return or;
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ObjectResult<Boolean> openXstd(String xstdNo, Login lg) throws Exception {
 
        ObjectResult<Boolean> or = new ObjectResult<Boolean>();
        if (lg == null) {
            or.setCode(1);
            or.setErrmsg("请重新登录账号!");
            return or;
        }
        if (StringUtils.isEmpty(xstdNo)) {
            or.setCode(1);
            or.setErrmsg("销售提单号为空,不能执行该操作!");
            return or;
        }
        // 关闭之后不让打开了
 
        // 根据xstdNo查找fd_xstd信息 vehicle_xstd
        // 判断vehicle_xstd的销售提单的状态
        // 查找fd_xstdmx
        // for循环 list<fd_xstdmx> 获取未分单未装车
        // 修改fd_xstdmx 修改Fd_Gbxstd, Fd_Gbxstdmx,修改fd_xstd
 
        Fd_Gbxstd gbtd = gbtdper.get(xstdNo);
        if (gbtd == null) {
            or.setCode(1);
            or.setErrmsg("销售提单:" + xstdNo + " 未找到关闭记录,不能恢复销售提单!");
            return or;
        }
        if (BasicMethod.after(gbtd.getTd_gbsj(), 7)) {
            or.setCode(1);
            or.setErrmsg("已关闭超过7天,不能恢复提单!");
            return or;
        }
        List<Vehicle_XSTD> vxl = vhxper.getlistbytdNo(xstdNo);
        if (vxl != null && vxl.size() > 0) {
            or.setCode(1);
            or.setErrmsg("销售提单:" + xstdNo + " 有在办的分车单,不能执行该操作!");
            return or;
        }
        Fd_XSTD tdx = this.tdper.getbyttdbh(xstdNo);
        if (tdx == null) {
            or.setCode(1);
            or.setErrmsg("销售提单:" + xstdNo + "未找到,不能执行该操作!");
            return or;
        }
        Fd_Company fdc = new Fd_Company();
        if (!UserType.admin.toString().equals(lg.getWorkerno())) {
            fdc = fdcper.getByCompanyNo(lg.getDepartno());
            if (fdc == null) {
                or.setCode(1);
                or.setErrmsg("登录账号未指定物流公司!");
                return or;
            }
            // 自提
            if (tdx.getTd_ztbz() == 2) {
                if (!fdc.isHasSPR()) {
                    or.setCode(1);
                    or.setErrmsg("该账号没有操作该提单的权限!");
                    return or;
                }
            } else {
                String shdqbh = tdx.getTd_shddbh();
                Fd_wlgs_fhdq acb = this.dqper.getbyNos(lg.getDepartno(), shdqbh,
                        /*tdx.getTd_ywdybh().equals(Contants.nc_ywdy_ZZ) ? Contants.nc_ywdy_ZZ
                                :tdx.getTd_ywdybh().equals(Contants.nc_ywdy_MS) ? Contants.nc_ywdy_MS
                                : Contants.nc_ywdy_KJ*/
                        ConvertTool.ncGetDefault(tdx.getTd_ywdybh())
                );
                int total = fdMxWlgsMapper.selectCountByTdTdls(tdx.getTd_tdls());
                if (acb == null && total == 0) {
                    or.setCode(1);
                    or.setErrmsg("该账号没有操作该提单的权限!");
                    return or;
                }
            }
        }
 
        List<Fd_Gbxstdmx> mxL = this.gbtdmxper.getList(xstdNo);
        int dd = 0;
        if (mxL != null) {
            for (Fd_Gbxstdmx mx : mxL) {
                Fd_XSTDMX tdmx = this.tdmxper.getbytdflAndtdls(mx.getId(), tdx.getTd_tdls());
                tdmx.setTdmx_zcbz(0);
                tdmx.setTdmx_zccph(null);
                tdmx.setTdmx_zcdriver(null);
                tdmx.setTdmx_zcphone(null);
                tdmx.setTdmx_zcwlgsName(null);
                dd++;
                this.tdmxper.updateZCANDFD(tdmx);
                this.gbtdmxper.delbyId(mx.getId());
            }
        }
        if (dd > 0) {
            tdx.setTd_wfdsl(gbtd.getTd_gbsl());
            tdx.setTd_wfdzl(gbtd.getTd_gbzl());
            this.tdper.updateFD(tdx);
            this.gbtdper.del(xstdNo);
        }
 
        or.setCode(0);
        return or;
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    @Deprecated
    public ObjectResult<Boolean> changeVehicle(Login lg, String bsNo, String vehicleInfo) throws Exception {
        ObjectResult<Boolean> orr = new ObjectResult<Boolean>();
        if (lg == null) {
            orr.setCode(1);
            orr.setErrmsg("请登录账号!");
            return orr;
        }
        if (true) {
            orr.setCode(1);
            orr.setErrmsg("该方法不可用!");
            return orr;
        }
        if (UserType.admin.toString().equals(lg.getWorkerno())) {
            orr.setCode(1);
            orr.setErrmsg("管理员不能执行该操作!");
            return orr;
        }
        if (StringUtils.isEmpty(bsNo) || StringUtils.isEmpty(vehicleInfo)) {
            orr.setCode(1);
            orr.setErrmsg("业务参数为空!");
            return orr;
        }
        Fd_Bsheet fdb = fdbsper.getbybsNo(bsNo);
        if (fdb == null) {
            orr.setCode(1);
            orr.setErrmsg("业务单未找到!");
            return orr;
        }
        String vehicleId = fdb.getVehicleId();
        Fd_Vehicle fdv = vhper.getByVehicleId(vehicleId);
        if (fdv == null) {
            orr.setCode(1);
            orr.setErrmsg("原来的车牌未找到!");
            return orr;
        }
        JsonParser jp = new JsonParser();
        JsonElement je = jp.parse(vehicleInfo);
        JsonObject jo = je.getAsJsonObject();
        String nvehicleId = JSONobj.getstring(jo, "vehicleId");
        String driver = JSONobj.getstring(jo, "driver");
        String phone = JSONobj.getstring(jo, "phone");
        double vehicleweight = JSONobj.getdouble(jo, "vehicleweight");
        double loadweight = JSONobj.getdouble(jo, "loadweight");
        String feature = JSONobj.getstring(jo, "feature");
        String note = JSONobj.getstring(jo, "note");
        String IDNum = JSONobj.getstring(jo, "IDNum");
        if (StringUtils.isEmpty(vehicleId) || StringUtils.isEmpty(driver) || StringUtils.isEmpty(IDNum)
                || StringUtils.isEmpty(phone)) {
            orr.setCode(1);
            orr.setErrmsg("车辆必填信息不能为空!");
            return orr;
        }
        Fd_Vehicle nfdv = vhper.getByVehicleId(nvehicleId);
        if (nfdv != null && nfdv.getStatus() != VehicleStatus.未配车) {
            orr.setCode(1);
            orr.setErrmsg("车辆:" + nvehicleId + "状态不是未配车状态,不能使用!");
            return orr;
        }
 
        // 临时车直接删除
        if (fdv.getType() == VehicleType.临时车) {
            vhper.delByVehicleId(fdv.getVehicleId());
        } else {
            fdv.setStatus(VehicleStatus.未配车);
            vhper.update(fdv);
        }
 
        // 修改vehicle_xstd表
        List<Vehicle_XSTD> lc = vhxper.getlistbycomNo(lg.getDepartno());
        // List<Vehicle_XSTD> lc=vhxper.getlistbyVehicleId(fdv.getVehicleId());
        if (lc != null) {
            for (Vehicle_XSTD vx : lc) {
                if (vx.getVehicleId().equals(fdv.getVehicleId())) {
                    vx.setVehicleId(nvehicleId);
                    vhxper.updatewithIDs(vx);
                }
            }
        }
        if (nfdv == null) {
            nfdv = new Fd_Vehicle();
            nfdv.setCompanyNo(lg.getDepartno());
            nfdv.setDriver(driver);
            nfdv.setId(UUID.randomUUID() + "");
            nfdv.setLoadweight(loadweight);
            nfdv.setNote(note);
            nfdv.setPhone(phone);
            nfdv.setState(true);
            nfdv.setFeature(feature);
            nfdv.setStatus(VehicleStatus.已配车);
            nfdv.setType(VehicleType.临时车);
            nfdv.setVehicleId(nvehicleId);
            nfdv.setVehicleweight(vehicleweight);
            nfdv.setIDNum(IDNum);
            vhper.insert(nfdv);
        }
 
        // 换车用不用发送短信
 
        orr.setCode(0);
        orr.setItem(true);
        return orr;
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    @Deprecated
    public ObjectResult<Boolean> saveZcInfo(Scxt_zcInfo zc) throws Exception {
        ObjectResult<Boolean> orr = new ObjectResult<Boolean>();
        if (zc == null) {
            orr.setCode(1);
            orr.setErrmsg("参数为空不能保存!");
            return orr;
        }
        if (true) {
            orr.setCode(1);
            orr.setErrmsg("该方法已作废!");
            return orr;
        }
        String zcvehicleID = zc.getCph();// 车牌号
        String pch = zc.getPch();// 批次号
        String tdbh = zc.getTdbh();// 提单编号
        Fd_Vehicle fdv = vhper.getByVehicleId(zcvehicleID);
        if (fdv == null) {
            orr.setCode(1);
            orr.setErrmsg("分单系统未找到该车牌号!");
            return orr;
        }
        Map<String, Object> bsmp =null;// bsper.getbsbyBt(zcvehicleID, Contants.cpxsBtNo, Serviceenum.在办,Contants.kjSdepartNo);
        if (bsmp == null) {
            orr.setCode(1);
            orr.setErrmsg("该车辆没有找到一卡通业务单!");
            return orr;
        }
        String dbsign = tdbh.split("-")[0];
        // Fd_Erpconfig erpdb=erpper.getbySign(dbsign);
        // if(erpdb==null){
        // orr.setCode(1);
        // orr.setErrmsg("根据提单编号未找到配置的数据库数据源!");
        // return orr;
        // }
        // Map<String, Object> bsim=bsper.getbsi(pch, bsmp.get("bussinessNo")+"" );
        // if(bsim!=null){
        // orr.setCode(1);
        // orr.setErrmsg("该成品已经装车!");
        // return orr;
        // }
        // try {
        // String
        // url="jdbc:jtds:sqlserver://"+erpdb.getUri()+":"+erpdb.getPost()+";databaseName="+erpdb.getDb();
        // Connection con=ddbdao.open(url, erpdb.getUsername(),
        // erpdb.getPwd(),erpdb.getDbsign());
        // if(con==null){
        // ddbdao.close();
        // orr.setCode(1);
        // orr.setErrmsg("erp数据库链接失败,请查询erp配置是否正确!");
        // return orr;
        // }
        // String sql=SqlTxt.GYErpXSTDsql+" where EXISTS (SELECT 1 FROM XSTDMX WHERE
        // XSTDMX_TDLS=XSTD_TDLS AND XSTDMX_CKBZ='0') and a.XSTD_TDBH='"+tdbh+"' and
        // a.XSTD_SHBZ=1 and a.XSTD_TDBZ='LD' ";
        // Map<String, Object> tdmp=ddbdao.getmapnoclose(sql,erpdb.getDbsign());
        // if(tdmp==null){
        // orr.setCode(1);
        // orr.setErrmsg("销售提单未找到!");
        // ddbdao.close();
        // return orr;
        // }
        // WaitXSTD wt=new WaitXSTD();
        // BeanUtils.populate(wt, tdmp);
        //
        // //判断该车辆有没有操作该提单的权限
        // if(true){
        //
        // }
        // sql=SqlTxt.GYErpXSTDMXsql+" where b.XSTDMX_CKBZ='0' and
        // a.XSTD_TDBH='"+tdbh+"' and b.XSTDMX_PCH='"+pch+"' ";//销售提单明细
        // Map<String, Object> mxmp=ddbdao.getmapnoclose(sql,erpdb.getDbsign());
        // if(mxmp==null){
        // orr.setCode(1);
        // orr.setErrmsg("根据提单号和批次号Erp未找到销售提单明细!");
        // ddbdao.close();
        // return orr;
        // }
        // WaitXSTDMX wtdmx=new WaitXSTDMX();
        // BeanUtils.populate(wtdmx, mxmp);
        // String hj=mxmp.get("hj")==null?"":mxmp.get("hj")+"";
        // String zt=mxmp.get("zt")==null?"":mxmp.get("zt")+"";
        // wtdmx.setTdmx_hjzt(hj+"/"+zt);
        // //如果扫的是没有分单的
        // if(wtdmx.getTdmx_fdbz()==0){
        // sql=SqlTxt.XGGYErpXSTDMXsql+" where a.XSTDMX_CKBZ='0' and
        // b.XSTD_TDBH='"+tdbh+"' and a.XSTDMX_PCH='"+pch+"' ";//修改销售提单明细
        // List<Object> ll=new ArrayList<Object>();
        // ll.add(zcvehicleID);//车牌号
        // ll.add(2);//分单标志
        // ll.add(bsmp.get("bussinessNo")+"");//分单单据编号
        // ddbdao.modifySql(sql, ll,erpdb.getDbsign());
        //
        // sql=SqlTxt.XGGYErpXSTDsql;//修改销售提单
        // ll.clear();
        // ll.add(wt.getTd_wfdsl()-1);//未分单数量
        // ll.add(BigDecimalfiter.subscal(wt.getTd_wfdzl(), wtdmx.getTdmx_mz(),
        // Contants.scale));//未分单毛重
        // ll.add(tdbh);
        // ddbdao.modifySql(sql, ll,erpdb.getDbsign());
        // }
        //
        // if(fdv.getStatus()!=VehicleStatus.已装车){
        // fdv.setStatus(VehicleStatus.已装车);
        // vhper.update(fdv);
        // }
        // Fd_Bsheetitem fbi=bsiper.getbyLsandFl(wtdmx.getTdmx_tdls(),
        // wtdmx.getTdmx_tdfl(),tdbh);
        // //该车辆有没有添加
        // Vehicle_XSTD vhx=vhxper.getbyIDs(zcvehicleID, tdbh);
        // //已经分单
        // if(fbi!=null){
        // //未分到当前车辆
        // if(!fbi.getTdmx_cph().equals(zcvehicleID)){
        // Vehicle_XSTD vhx1=vhxper.getbyIDs(zcvehicleID, tdbh);
        // //该车辆已添加销售提单
        // if(vhx!=null){
        // vhx.setFd_num(vhx.getFd_num()+1);
        // vhx.setFd_weight(BigDecimalfiter.addscal(vhx.getFd_weight(),wtdmx.getTdmx_mz()
        // ,Contants.scale ));
        // vhxper.update(vhx);
        // }else{
        // vhx=new Vehicle_XSTD();
        // vhx.setFd_num(1);
        // vhx.setFd_weight(BigDecimalfiter.addscal(wtdmx.getTdmx_mz(), 0,
        // Contants.scale));
        // vhx.setVehicleId(zcvehicleID);
        // vhx.setXstdNo(tdbh);
        // vhx.setBsNo( bsmp.get("bussinessNo")+"");
        // vhxper.insert(vhx);
        // }
        // if(vhx1.getFd_num()==1){
        // vhxper.delbyIDs(vhx1.getVehicleId(), vhx1.getXstdNo());
        // }else{
        // vhx1.setFd_num(vhx1.getFd_num()-1);
        // vhx1.setFd_weight(BigDecimalfiter.subscal(vhx1.getFd_weight(),
        // wtdmx.getTdmx_mz(), Contants.scale));
        // vhxper.update(vhx1);
        // }
        // fbi.setTdmx_cph(zcvehicleID);
        // }
        //// fbi.setTdmx_cph(zcvehicleID);
        // fbi.setTdmx_tdbh(tdbh);
        // fbi.setTdmx_fdbz(2);
        // fbi.setTdmx_fdywbh(bsmp.get("bussinessNo")+"" );
        // fbi.setTdmx_zccph(zcvehicleID);
        // fbi.setTdmx_sfzc(1);
        // fbi.setBarcode(zc.getTmh());
        // bsiper.update(fbi);
        // }else{
        // fbi=new Fd_Bsheetitem();
        // fbi.setId(UUID.randomUUID()+"");
        // fbi.setCompanyName("");
        // fbi.setCompanyNo("");
        // fbi.setCreateid("");
        // fbi.setBarcode(zc.getTmh());
        // fbi.setCtime(new Date());
        // fbi.setTdmx_cph(zcvehicleID);
        // fbi.setTdmx_tdbh(tdbh);
        // fbi.setTdmx_fdbz(2);
        // fbi.setTdmx_fdywbh(bsmp.get("bussinessNo")+"" );
        // fbi.setTdmx_zccph(zcvehicleID);
        // fbi.setTdmx_sfzc(1);
        // bsiper.insert(fbi);
        // //该装车车辆添加了这个提单的分单
        // if(vhx!=null){
        // vhx.setFd_num(vhx.getFd_num()+1);
        // vhx.setFd_weight(BigDecimalfiter.addscal(vhx.getFd_weight(),wtdmx.getTdmx_mz()
        // ,Contants.scale ));
        // vhxper.update(vhx);
        // }else{
        // vhx=new Vehicle_XSTD();
        // vhx.setFd_num(1);
        // vhx.setFd_weight(BigDecimalfiter.addscal(wtdmx.getTdmx_mz(), 0,
        // Contants.scale));
        // vhx.setVehicleId(zcvehicleID);
        // vhx.setXstdNo(tdbh);
        // vhxper.insert(vhx);
        // }
        // }
        //
        //
        //
        // //添加一卡通明细;
        // Map<String, Object> mm=new HashMap<String, Object>();
        // mm.put("id", UUID.randomUUID()+"");
        // mm.put("bussinessNo",bsmp.get("bussinessNo")+"" );
        // mm.put("name", wtdmx.getTdmx_wlmc());
        // mm.put("materielNo",wtdmx.getTdmx_wlbh() );
        // mm.put("norms",wtdmx.getTdmx_ggxh() );
        // mm.put("unitname", "Kg");
        // mm.put("num", 1);
        // mm.put("note", null);
        // mm.put("weight", BigDecimalfiter.mulcon(wtdmx.getTdmx_jz(), 1000,
        // Contants.scale));
        // mm.put("price", 0);
        // mm.put("preweight",BigDecimalfiter.mulcon(wtdmx.getTdmx_jz(), 1000,
        // Contants.scale));
        // mm.put("pici", pch);
        // mm.put("hejin", wtdmx.getTdmx_hjzt());
        // mm.put("gross",BigDecimalfiter.mulcon(wtdmx.getTdmx_mz(), 1000,
        // Contants.scale) );
        // mm.put("taotong","" );
        // mm.put("taotongWeight", BigDecimalfiter.subscal(wtdmx.getTdmx_mz()*1000,
        // wtdmx.getTdmx_jz()*1000, Contants.scale));
        // mm.put("money", 0);
        //
        //// mm.put("createid", );
        //// mm.put("cname", );
        //// mm.put("createid", 0);
        // mm.put("cdepartid", 0);
        //// mm.put("cdepart", );
        // mm.put("ctime", new Date());
        //
        // mm.put("loadbuild", false);
        // mm.put("factory", false);
        // mm.put("fachang", true);
        // mm.put("fcnum", 0);
        // mm.put("product_billNo", tdbh);
        // mm.put("product_serialNo",wtdmx.getTdmx_tdls());
        // mm.put("product_otherNo", null);
        //// mm.put("product_ywrq",wtdmx.gettdmx_ );
        // mm.put("product_flh", wtdmx.getTdmx_tdfl());
        // mm.put("recompany",wtdmx.getTdmx_shdw() );
        //// mm.put("reID", "");
        // mm.put("decompany", wtdmx.getTdmx_fhdw()==null?"明泰科技":wtdmx.getTdmx_fhdw());
        //// mm.put("deID", "");
        // mm.put("rcompany",wtdmx.getTdmx_shdw() );
        //// mm.put("rID", );
        // mm.put("frombatch", "ERP系统");
        // mm.put("forshowindx",1 );
        // mm.put("barcode",zc.getTmh());
        // mm.put("reserved11",0 );
        // mm.put("reserved12",0 );
        // mm.put("reserved13",0 );
        // mm.put("jsnum",0 );
        //
        // bsper.insertBsi(mm);
        // } catch (Exception e) {
        // ddbdao.robackclose();
        // throw new
        // Exception(StringUtils.isEmpty(e.getMessage())?"添加装车信息出错!":e.getMessage());
        // }finally{
        // ddbdao.close();
        // }
 
        orr.setCode(0);
        orr.setItem(true);
        return orr;
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    @Deprecated
    public ObjectResult<Boolean> sxinCheck(String bsNo, String vehicleId) throws Exception {
        ObjectResult<Boolean> orr = new ObjectResult<Boolean>();
        if (StringUtils.isEmpty(vehicleId)) {
            orr.setCode(1);
            orr.setErrmsg("车牌号为空!");
            return orr;
        }
        if (StringUtils.isEmpty(bsNo)) {
            orr.setCode(1);
            orr.setErrmsg("一卡通业务单号为空!");
            return orr;
        }
        if (true) {
            orr.setCode(1);
            orr.setErrmsg("该方法已经弃用!");
            return orr;
        }
        Fd_Bsheet fdb = fdbsper.getbybsNo(bsNo);
        if (fdb == null) {
            orr.setCode(1);
            orr.setErrmsg("业务单未找到!");
            return orr;
        }
        Fd_Vehicle fdv = vhper.getByVehicleId(vehicleId);
        if (fdv == null) {
            orr.setCode(1);
            orr.setErrmsg("业务车辆未找到!");
            return orr;
        }
        try {
        } catch (Exception e) {
            throw new Exception(StringUtils.isEmpty(e.getMessage()) ? "销售业务车辆进厂程序出错!" : e.getMessage());
        }
        orr.setCode(0);
        orr.setItem(true);
        return orr;
    }
 
    @Override
    @Deprecated
    public ObjectResult<Boolean> delZcInfo(Scxt_zcInfo zc) throws Exception {
        ObjectResult<Boolean> orr = new ObjectResult<Boolean>();
        if (zc == null) {
            orr.setCode(1);
            orr.setErrmsg("业务参数为空!");
            return orr;
        }
        if (true) {
            orr.setCode(1);
            orr.setErrmsg("该方法已经弃用!");
            return orr;
        }
        String tmh = zc.getTmh();// 条码号
        String cph = zc.getCph();// 车牌号
        String cardno = zc.getYktkh();// 一卡通卡号
        Map<String, Object> cdi = yktmper.getcardinuse(cardno);
        if (cdi == null) {
            orr.setCode(1);
            orr.setErrmsg("该卡一卡通未找到,请确认该卡是否正确!");
            return orr;
        }
        if (cdi.get("numberplates") == null) {
            orr.setCode(1);
            orr.setErrmsg("该卡没有配置车牌号,请确认该卡是否可用!");
            return orr;
        }
        Fd_Vehicle fdv = vhper.getByVehicleId(cph);
        if (fdv == null) {
            orr.setCode(1);
            orr.setErrmsg("未找到该分单车牌号!");
            return orr;
        }
        Map<String, Object> bsmp = null;//bsper.getbsbyBt(cph, Contants.cpxsBtNo, Serviceenum.在办, Contants.kjSdepartNo);
        if (bsmp == null) {
            orr.setCode(1);
            orr.setErrmsg("该车辆没有找到在办的一卡通业务单!");
            return orr;
        }
        if (StringUtils.isEmpty(bsmp.get("bussinessNo") + "")) {
            orr.setCode(1);
            orr.setErrmsg("一卡通业务单未找到!");
            return orr;
        }
        int wdi = yktmper.getweight_doc(bsmp.get("bussinessNo") + "");
        if (wdi <= 0) {
            orr.setCode(1);
            orr.setErrmsg("该车辆还未称重,请先去磅房称重!");
            return orr;
        }
        // Fd_Bsheetitem fd_b=bsiper.getbyNoandCode(tmh, bsmp.get("bussinessNo")+"" );
        // if(fd_b!=null){
        // String tdNo=fd_b.getTdmx_tdbh();//提单编号
        // bsper.delbysibyBarcode(tmh, bsmp.get("bussinessNo")+"" );
        // Vehicle_XSTD v_x=vhxper.getbyIDs(cph, tdNo);
        // if(v_x!=null){
        // if(v_x.getFd_num()>1){
        // v_x.setFd_num(v_x.getFd_num()-1);
        // v_x.setFd_weight(BigDecimalfiter.subscal(v_x.getFd_weight(),
        // fd_b.getTdmx_mz(), Contants.scale));
        // vhxper.update(v_x);
        // fdv.setStatus(VehicleStatus.已装车);
        // vhper.update(fdv);
        // }else{
        // Map<String, Object> cc=vhxper.getbyVehcleId(cph, v_x.getBsNo());
        // if(cc!=null){
        // if(cc.get("fd_nums")!=null){
        // int fd_nums=Integer.parseInt(cc.get("fd_nums")+"");
        // if(fd_nums>1){
        // fdv.setStatus(VehicleStatus.已装车);
        // vhper.update(fdv);
        // }else{
        // vhxper.delbyIDs(cph, tdNo);
        // fdv.setStatus(VehicleStatus.已进厂);
        // vhper.update(fdv);
        // }
        // }else{
        // vhxper.delbyIDs(cph, tdNo);
        // fdv.setStatus(VehicleStatus.已进厂);
        // vhper.update(fdv);
        // }
        // }else{
        // vhxper.delbyIDs(cph, tdNo);
        // fdv.setStatus(VehicleStatus.已进厂);
        // vhper.update(fdv);
        // }
        // }
        // }else{
        // fdv.setStatus(VehicleStatus.已进厂);
        // vhper.update(fdv);
        // }
        // }
 
        orr.setCode(0);
        orr.setItem(true);
        return orr;
    }
 
    @Override
    @Deprecated
    public Map<String, Object> getClInfo(String cardno) {
        Map<String, Object> mp = new HashMap<String, Object>();
        Map<String, Object> cdi = yktmper.getcardinuse(cardno);
        if (cdi == null) {
            mp.put("code", 1);
            mp.put("errmsg", "该卡一卡通未找到,请确认该卡是否发放!");
            return mp;
        }
        if (cdi.get("numberplates") == null) {
            mp.put("code", 1);
            mp.put("errmsg", "该卡没有配置车牌号,请确认该卡是否可用!");
            return mp;
        }
        String vehicleId = cdi.get("numberplates") + "";
        Map<String, Object> bsmap = yktmper.getBsheet(vehicleId, Contants.cpxsBtNo, Serviceenum.在办, "04");
        if (bsmap == null) {
            mp.put("code", 1);
            mp.put("errmsg", "该卡没有在办的一卡通销售业务单!");
            return mp;
        }
        Fd_Bsheet fb =null ;//fdbsper.getbyVehicleId(vehicleId, Serviceenum.在办);
        if (fb == null) {
            mp.put("code", 1);
            mp.put("errmsg", "在办分车业务单未找到!");
            return mp;
        }
        int c = this.yktmper.getweight_doc(fb.getBsNo());
        if (c <= 0) {
            mp.put("code", 1);
            mp.put("errmsg", "业务单未找到磅单,请先去过磅!");
            return mp;
        }
        List<Vehicle_XSTD> vxl = new ArrayList<Vehicle_XSTD>();
        // List<Vehicle_XSTD> vxl=this.vhxper.getlistbyVehicleId(vehicleId);
        mp.put("tdbhs", null);
        if (vxl == null || vxl.size() <= 0) {
            mp.put("code", 1);
            mp.put("errmsg", "未找到销售提单!");
            return mp;
        } else {
            String cc = "";
            for (Vehicle_XSTD vx : vxl) {
                if (StringUtils.isEmpty(cc)) {
                    cc += vx.getXstdNo();
                } else {
                    cc += "," + vx.getXstdNo();
                }
            }
            mp.put("tdbhs", cc);
        }
 
        mp.put("code", 0);
        mp.put("cph", fb.getVehicleId());
        mp.put("sjmc", fb.getDriver());
        mp.put("dh", fb.getPhone());
        mp.put("ywdh", fb.getBsNo());
        return mp;
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    @Deprecated
    public ObjectResult<Boolean> batchSaveZcInfo(String zclist) throws Exception {
 
        ObjectResult<Boolean> orr = new ObjectResult<Boolean>();
        if (StringUtils.isEmpty(zclist)) {
            orr.setCode(1);
            orr.setErrmsg("参数为空不能保存!");
            return orr;
        }
        if (true) {
            orr.setCode(1);
            orr.setErrmsg("方法已经弃用!");
            return orr;
        }
        // String Lcuuid=UUID.randomUUID()+"";
        // try {
        // JsonParser jp=new JsonParser();
        // JsonArray ja=jp.parse(zclist).getAsJsonArray();
        // int eachline=0;
        // //是否检查车辆
        // boolean checkVehicle=true;
        // String bussinessNo="";
        // Fd_Vehicle fdv=null;
        // Fd_Bsheet fdb=null;
        // Map<String, Fd_Erpconfig> dberpmp=new HashMap<String, Fd_Erpconfig>();
        // double mzweight=0;
        // String instanceID="";
        // Map<String, Object> lm=new HashMap<String, Object>();
        // for (JsonElement tdje : ja) {
        // if(lm.size()>1){
        // break;
        // }
        // JsonObject jo=tdje.getAsJsonObject();
        // Scxt_zcInfo zc=new Scxt_zcInfo();
        // eachline++;
        // zc=JSONobj.getobj(jo, zc);
        // if(zc==null){
        // continue;
        // }
        // String tdNo=zc.getTdbh();
        // if(!StringUtils.isEmpty(tdNo)){
        // String tdsign=tdNo.split("-")[0];
        // if(lm.get(tdsign)==null){
        // lm.put(tdsign, "abc");
        // }
        // }
        // }
        // if(lm.size()>1){
        //// boolean lcboo=ddbdao.getLcmps(Lcuuid);
        // String dbcheck=DBchecksingleton.setDbc(Lcuuid,false);
        // if(!Lcuuid.equals(dbcheck)){
        // throw new Exception("ERP数据库正在被占用,请重新操作!");
        // }
        // }
        // List<Fd_Company> fdcl=this.fdcper.getall();
        // Map<String, String> fdcm=new HashMap<String, String>();
        // if(fdcl!=null){
        // for (Fd_Company fdc : fdcl) {
        // if(!fdc.isHasSPR()){
        // fdcm.put(fdc.getCompanyNo(), fdc.getName());
        // }
        // }
        // }
        // for (JsonElement je : ja) {
        // JsonObject jo=je.getAsJsonObject();
        // Scxt_zcInfo zc=new Scxt_zcInfo();
        // eachline++;
        // zc=JSONobj.getobj(jo, zc);
        // if(zc==null){
        // continue;
        // }
        //
        //
        // if(StringUtils.isEmpty(zc.getCph())||StringUtils.isEmpty(zc.getTdbh())||StringUtils.isEmpty(zc.getPch())){
        // continue;
        // }
        // String dbsign=zc.getTdbh().split("-")[0];
        // Fd_Erpconfig erpdb=null;
        // if(dberpmp.get(dbsign)==null){
        // erpdb=erpper.getbySign(dbsign);
        // if(erpdb==null){
        // throw new Exception("提单编号是"+dbsign+"-******* 类型的未配置ERP数据库!");
        // }
        // dberpmp.put(dbsign, erpdb);
        // }else{
        // erpdb=dberpmp.get(dbsign);
        // }
        // if(checkVehicle){
        // fdv=vhper.getByVehicleId(zc.getCph());
        // if(fdv==null){
        // throw new Exception("分单系统车牌号:"+zc.getCph()+" 未找到,请确认车辆信息是否正确!");
        // }
        // Map<String, Object> bsmp=bsper.getbsbyBt(zc.getCph(), Contants.cpxsBtNo,
        // Serviceenum.在办, Contants.ssdepartNo);
        // if(bsmp==null){
        // throw new Exception("车牌号:"+zc.getCph()+" 未找到一卡通业务单!");
        // }
        // bussinessNo=bsmp.get("bussinessNo")+"";
        // instanceID=bsmp.get("instanceID")==null?"":bsmp.get("instanceID")+"";
        // fdb=fdbsper.getbybsNo(bussinessNo);
        // if(fdb==null){
        // throw new Exception("车牌号:"+zc.getCph()+" 未找到分单业务单!");
        // }else{
        // if(!fdb.getVehicleId().equals(zc.getCph())){
        // throw new Exception("车牌号:"+zc.getCph()+"与 分单车牌号不一致!");
        // }
        // }
        // checkVehicle=false;
        // }
        //
        // Vehicle_XSTD vhx=vhxper.getbyIDs(zc.getCph(), zc.getTdbh());
        // if(vhx==null){
        // throw new Exception("提单编号:"+zc.getTdbh()+"没有分单给车牌号:"+zc.getCph()+" !");
        // }
        // String
        // url="jdbc:jtds:sqlserver://"+erpdb.getUri()+":"+erpdb.getPost()+";databaseName="+erpdb.getDb();
        // Connection con=ddbdao.open(url, erpdb.getUsername(),
        // erpdb.getPwd(),erpdb.getDbsign());
        // if(con==null){
        // throw new Exception("ERP数据库链接失败,请检查分单系统ERP配置是否正确!");
        // }
        // String sql=SqlTxt.GYErpXSTDsql+" where EXISTS (SELECT 1 FROM XSTDMX WHERE
        // XSTDMX_TDLS=XSTD_TDLS AND XSTDMX_CKBZ='0') and a.XSTD_TDBH='"+zc.getTdbh()+"'
        // and a.XSTD_SHBZ=1 and a.XSTD_TDBZ='LD' ";
        // Map<String, Object> tdmp=ddbdao.getmapnoclose(sql,erpdb.getDbsign());
        // if(tdmp==null){
        // throw new Exception("第"+eachline+"行 ,销售提单未找到!");
        // }
        // WaitXSTD wt=new WaitXSTD();
        // BeanUtils.populate(wt, tdmp);
        //
        // sql=SqlTxt.GYErpXSTDMXsql+" where b.XSTDMX_CKBZ='0' and
        // a.XSTD_TDBH='"+zc.getTdbh()+"' and b.XSTDMX_PCH='"+zc.getPch()+"' ";//销售提单明细
        // Map<String, Object> mxmp=ddbdao.getmapnoclose(sql,erpdb.getDbsign());
        // if(mxmp==null){
        // throw new Exception("第"+eachline+"行 根据提单号和批次号Erp未找到销售提单明细!");
        // }
        // WaitXSTDMX wtdmx=new WaitXSTDMX();
        // BeanUtils.populate(wtdmx, mxmp);
        // String hj=mxmp.get("hj")==null?"":mxmp.get("hj")+"";
        // String zt=mxmp.get("zt")==null?"":mxmp.get("zt")+"";
        // wtdmx.setTdmx_hjzt(hj+"/"+zt);
        // //如果扫的是没有分单的
        // if(wtdmx.getTdmx_fdbz()==0){
        // sql=SqlTxt.XGGYErpXSTDMXsql1+" where a.XSTDMX_CKBZ='0' and
        // b.XSTD_TDBH='"+zc.getTdbh()+"' and a.XSTDMX_PCH='"+zc.getPch()+"'
        // ";//修改销售提单明细
        // List<Object> ll=new ArrayList<Object>();
        // ll.add(zc.getCph());//车牌号
        // ll.add(2);//分单标志
        // ll.add(bussinessNo);//分单单据编号
        // ll.add(fdv.getDriver());//司机姓名
        // ll.add(fdv.getPhone());//司机联系方式
        // ll.add(fdcm.get(vhx.getCompanyNo())==null?"":fdcm.get(vhx.getCompanyNo()));//物流公司名称
        //// ll.add(fdcm.get(fdv.getCompanyNo())==null?"":fdcm.get(fdv.getCompanyNo()));//物流公司名称
        // ddbdao.modifySql(sql, ll,erpdb.getDbsign());
        //
        // sql=SqlTxt.XGGYErpXSTDsql;//修改销售提单
        // ll.clear();
        // ll.add(wt.getTd_wfdsl()-1);//未分单数量
        // ll.add(BigDecimalfiter.subscal(wt.getTd_wfdzl(), wtdmx.getTdmx_mz(),
        // Contants.scale));//未分单毛重
        // ll.add(zc.getTdbh());
        // ddbdao.modifySql(sql, ll,erpdb.getDbsign());
        //
        // //修改vhx
        // vhx.setFd_num(vhx.getFd_num()+1);
        // vhx.setFd_weight(BigDecimalfiter.addscal(vhx.getFd_weight(),
        // wtdmx.getTdmx_mz(), Contants.scale));
        // vhxper.update(vhx);
        // }else{
        // sql=SqlTxt.XGGYErpXSTDMXsql2+" where a.XSTDMX_CKBZ='0' and
        // b.XSTD_TDBH='"+zc.getTdbh()+"' and a.XSTDMX_PCH='"+zc.getPch()+"'
        // ";//修改销售提单明细
        // List<Object> ll=new ArrayList<Object>();
        // ll.add(fdv.getDriver());//司机姓名
        // ll.add(fdv.getPhone());//司机联系方式
        // ll.add(fdcm.get(vhx.getCompanyNo())==null?"":fdcm.get(vhx.getCompanyNo()));//物流公司名称
        //// ll.add(fdcm.get(fdv.getCompanyNo())==null?"":fdcm.get(fdv.getCompanyNo()));//物流公司名称
        // ddbdao.modifySql(sql, ll,erpdb.getDbsign());
        //
        // if(!zc.getCph().equals(wtdmx.getTdmx_cph())){
        // Vehicle_XSTD vhx1=this.vhxper.getbyIDs(wtdmx.getTdmx_cph(), zc.getTdbh());
        // if(vhx1!=null){
        // vhx1.setFd_num(vhx1.getFd_num()-1);
        // vhx1.setFd_weight(BigDecimalfiter.subscal(vhx1.getFd_weight(),
        // wtdmx.getTdmx_mz(), Contants.scale));
        // vhxper.update(vhx1);
        // }
        // //修改vhx
        // vhx.setFd_num(vhx.getFd_num()+1);
        // vhx.setFd_weight(BigDecimalfiter.addscal(vhx.getFd_weight(),
        // wtdmx.getTdmx_mz(), Contants.scale));
        // vhxper.update(vhx);
        // }
        // }
        // //修改fbi
        // Fd_Bsheetitem fbi=bsiper.getbyLsandFl(wtdmx.getTdmx_tdls(),
        // wtdmx.getTdmx_tdfl(),zc.getTdbh());
        // if(fbi!=null){
        // fbi.setTdmx_cph(zc.getCph());
        // fbi.setTdmx_tdbh(zc.getTdbh());
        // fbi.setTdmx_fdbz(2);
        // fbi.setTdmx_fdywbh(fdb.getFdsheetNo());
        // fbi.setTdmx_zccph(zc.getCph());
        // fbi.setTdmx_sfzc(1);
        // fbi.setBarcode(zc.getTmh());
        // bsiper.update(fbi);
        // }else{
        // fbi=new Fd_Bsheetitem();
        // fbi.setId(UUID.randomUUID()+"");
        // fbi.setCompanyName(fdb.getCompanyName());
        // fbi.setCompanyNo(fdb.getCompanyNo());
        // fbi.setCreateid(fdb.getCreateid());
        // fbi.setBarcode(zc.getTmh());
        // fbi.setCtime(new Date());
        // fbi.setTdmx_cph(zc.getCph());
        // fbi.setTdmx_tdbh(zc.getTdbh());
        // fbi.setTdmx_fdbz(2);
        // fbi.setTdmx_fdywbh(fdb.getFdsheetNo());
        // fbi.setTdmx_zccph(zc.getCph());
        // fbi.setTdmx_sfzc(1);
        // bsiper.insert(fbi);
        // }
        // if(fdv.getStatus()!=VehicleStatus.已进厂){
        // fdv.setStatus(VehicleStatus.已进厂);
        // vhper.update(fdv);
        // }
        //
        // //添加一卡通明细;
        // Map<String, Object> mm=new HashMap<String, Object>();
        // mm.put("id", UUID.randomUUID()+"");
        // mm.put("bussinessNo",bussinessNo);
        // mm.put("name", wtdmx.getTdmx_wlmc());
        // mm.put("materielNo",wtdmx.getTdmx_wlbh() );
        // mm.put("norms",wtdmx.getTdmx_ggxh() );
        // mm.put("unitname", "Kg");
        // mm.put("num", 1);
        // mm.put("note", null);
        // mm.put("weight", BigDecimalfiter.mulcon(wtdmx.getTdmx_jz(), 1000,
        // Contants.scale));
        // mm.put("price", 0);
        // mm.put("preweight",BigDecimalfiter.mulcon(wtdmx.getTdmx_jz(), 1000,
        // Contants.scale));
        // mm.put("pici", zc.getPch());
        // mm.put("hejin", wtdmx.getTdmx_hjzt());
        // mm.put("gross",BigDecimalfiter.mulcon(wtdmx.getTdmx_mz(), 1000,
        // Contants.scale) );
        // mm.put("taotong","" );
        // mm.put("taotongWeight", BigDecimalfiter.subscal(wtdmx.getTdmx_mz()*1000,
        // wtdmx.getTdmx_jz()*1000, Contants.scale));
        // mm.put("money", 0);
        //// mm.put("createid", );
        //// mm.put("cname", );
        //// mm.put("createid", 0);
        // mm.put("cdepartid", 0);
        //// mm.put("cdepart", );
        // mm.put("ctime", new Date());
        // mm.put("loadbuild", false);
        // mm.put("factory", false);
        // mm.put("fachang", true);
        // mm.put("fcnum", 0);
        // mm.put("product_billNo", zc.getTdbh());
        // mm.put("product_serialNo",wtdmx.getTdmx_tdls());
        // mm.put("product_otherNo", null);
        //// mm.put("product_ywrq",wtdmx.gettdmx_ );
        // mm.put("product_flh", wtdmx.getTdmx_tdfl());
        // mm.put("recompany",wtdmx.getTdmx_shdw() );
        //// mm.put("reID", "");
        // mm.put("decompany", wtdmx.getTdmx_fhdw()==null?"明泰科技":wtdmx.getTdmx_fhdw());
        //// mm.put("deID", "");
        // mm.put("rcompany",wtdmx.getTdmx_shdw() );
        //// mm.put("rID", );
        // mm.put("frombatch", "ERP系统");
        // mm.put("forshowindx",1 );
        // mm.put("barcode",zc.getTmh());
        // mm.put("reserved11",0 );
        // mm.put("reserved12",0 );
        // mm.put("reserved13",0 );
        // mm.put("jsnum",0 );
        // Map<String, Object> mrc=this.bsper.getbsi(zc.getPch(), bussinessNo);
        // if(mrc==null){
        // bsper.insertBsi(mm);
        // }else{
        // mm.put("id", mrc.get("id")+"");
        // bsper.updateBsi(mm);
        // }
        // mzweight=BigDecimalfiter.addscal(mzweight,
        // BigDecimalfiter.mulcon(wtdmx.getTdmx_mz(), 1000, Contants.scale),
        // Contants.scale);
        // }
        //
        // if(mzweight>0&&!StringUtils.isEmpty(instanceID)){
        // Map<String, Object> mm=this.yktmper.getweight_docgt(bussinessNo);
        // if(mm!=null){
        // double gross=Double.parseDouble(mm.get("gross")+"");
        // double tare=Double.parseDouble(mm.get("tare")+"");
        // if(gross>0&& tare>0){
        // Task tk=this.acpser.findTaskByInstanceID(instanceID,
        // Contants.weightTaskName);
        // Map<String, Object> mcm=new HashMap<String,Object>();
        // if(tk!=null){
        // if(((gross-tare)-mzweight>Contants.upweight)||(mzweight-(gross-tare))<Contants.loawweight){
        // mcm.put("ckbc",1);
        // }else{
        // mcm.put("ckbc",0);
        // }
        // this.acpser.completeTask(tk.getId(), "admin", mcm);
        // }
        // }
        // }
        //
        // }
        //
        //
        // } catch (Exception e) {
        // ddbdao.robackclose();
        // throw new
        // Exception(StringUtils.isEmpty(e.getMessage())?"装车批量保存出错!":e.getMessage());
        // }finally{
        // ddbdao.close();
        //// ddbdao.removeLc(Lcuuid);
        // DBchecksingleton.setDbc(Lcuuid,true);
        // }
 
        orr.setCode(0);
        orr.setItem(true);
        return orr;
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    @Deprecated
    public ObjectResult<Boolean> batchdelZcInfo(String zcist) throws Exception {
        ObjectResult<Boolean> orr = new ObjectResult<Boolean>();
        if (zcist == null) {
            orr.setCode(1);
            orr.setErrmsg("业务参数为空!");
            return orr;
        }
        if (true) {
            orr.setCode(1);
            orr.setErrmsg("该方法已经弃用!");
            return orr;
        }
 
        // try {
        // JsonParser jp=new JsonParser();
        // JsonArray ja=jp.parse(zcist).getAsJsonArray();
        // boolean checkvehicle=true;
        // Fd_Vehicle fdv=null;
        // String bussinessNo="";
        // Fd_Bsheet fdb=null;
        // for (JsonElement je : ja) {
        // JsonObject jo=je.getAsJsonObject();
        // Scxt_zcInfo zc=new Scxt_zcInfo();
        // zc=JSONobj.getobj(jo, zc);
        // if(zc==null){
        // continue;
        // }
        // if(StringUtils.isEmpty(zc.getCph())||StringUtils.isEmpty(zc.getYktkh())||StringUtils.isEmpty(zc.getPch())){
        // continue;
        // }
        // String vehicleId=zc.getCph();//车牌号
        // String cardno=zc.getYktkh();//卡号
        // String pch=zc.getPch();//批次号
        // if(checkvehicle){
        // Map<String, Object> cdi=yktmper.getcardinuse(cardno);
        // if(cdi==null){
        // throw new Exception("卡号一卡通未找到,请确认该卡是否正确!");
        // }else if(!vehicleId.equals(cdi.get("numberplates"+""))){
        // throw new Exception("卡号与车牌号不对应,请确认卡号或者车牌号是否正确!");
        // }
        // fdv=vhper.getByVehicleId(zc.getCph());
        // if(fdv==null){
        // throw new Exception("分单系统车牌号:"+zc.getCph()+" 未找到,请确认车辆信息是否正确!");
        // }
        // Map<String, Object> bsmp=bsper.getbsbyBt(zc.getCph(), Contants.cpxsBtNo,
        // Serviceenum.在办, Contants.ssdepartNo);
        // if(bsmp==null){
        // throw new Exception("车牌号:"+zc.getCph()+" 未找到一卡通业务单!");
        // }
        // bussinessNo=bsmp.get("bussinessNo")+"";
        // fdb=fdbsper.getbybsNo(bussinessNo);
        // if(fdb==null){
        // throw new Exception("车牌号:"+zc.getCph()+" 未找到分单业务单!");
        // }else{
        // if(!fdb.getVehicleId().equals(zc.getCph())){
        // throw new Exception("车牌号:"+zc.getCph()+"与 分单车牌号不一致!");
        // }
        // }
        // checkvehicle=false;
        // }
        // bsper.delbypchandNo(pch, bussinessNo);
        // Fd_Bsheetitem fdbi=bsiper.getbypchandNo(bussinessNo, pch);
        // if(fdbi!=null){
        // fdbi.setTdmx_sfzc(0);
        // fdbi.setTdmx_zccph("");
        // bsiper.update(fdbi);
        // }
        // }
        //
        // //修改车辆信息
        // List<Map<String, Object>> bsill=bsper.getbsibyNo(bussinessNo);
        // if(bsill==null||bsill.size()<=0){
        // fdv.setStatus(VehicleStatus.已进厂);
        // vhper.update(fdv);
        // }
        // } catch (Exception e) {
        // throw new
        // Exception(StringUtils.isEmpty(e.getMessage())?"分单系统批量删除装车出错!":e.getMessage());
        // }
        orr.setCode(0);
        orr.setItem(true);
        return orr;
    }
 
    @Override
    public void changeMxWlgs(List<FdMxWlgs> fdMxWlgsList) throws Exception {
        // if(1==1) throw new Exception("就是一个提示!---");
        if(fdMxWlgsList!=null) {
            List<Fd_XSTDMX> updateFd_XSTDMX = new ArrayList<>();
            String tdmx_tdfls = fdMxWlgsList.stream().map(FdMxWlgs::getTdmxTdfl).collect(Collectors.joining("','"));
            List<Fd_XSTDMX>  fd_xstdmxes = null;
            // 提单流水为主键的Map,存放去掉的数量和重量,需要还回去
            Map<String,Map<String,Object>> tdlsMap = new HashedMap();
            if(StringUtils.isNotBlank(tdmx_tdfls)) {
                // 根据单号查找已派车的业务单,判断业务单是否发卡,已发卡不能修改,返回错误;前端应该也做限制
                tdmx_tdfls = "'" + tdmx_tdfls + "'";
                fd_xstdmxes = fd_xstdmxMapper.gets(tdmx_tdfls);
                String fdywbhs = fd_xstdmxes.stream().map(Fd_XSTDMX::getTdmx_fdywbh).collect(Collectors.joining("','"));
                if(StringUtils.isNotBlank(fdywbhs) && !"'null'".equals(fdywbhs))  {
                    fdywbhs =  "'" + fdywbhs + "'";
                    // 如果已经发卡,请联系一卡通
                    Map<String, Object> map = businessMapper.existsIssueCardByNos(fdywbhs);
                    if (map != null) {
                        throw  new Exception("存在已发卡单,请刷新页面后重试!");
                    }
                }
                // 删了单,要把重量和数量还回去;在此遍历一下,下面在session中统一更新
                fd_xstdmxes.forEach(fd_xstdmx -> {
                    // 装车标志都是 0
                    // if(fd_xstdmx.getTdmx_zcbz() == 0)  return;
                    // 不存在业务号,则任务没有分单;采用装车标志有问题,不采用。
                    if(StringUtils.isBlank(fd_xstdmx.getTdmx_fdywbh()))   return;
                    if(tdlsMap.get(fd_xstdmx.getTdmx_tdls())  == null ) {
                        tdlsMap.put(fd_xstdmx.getTdmx_tdls(), new HashedMap());
                        tdlsMap.get(fd_xstdmx.getTdmx_tdls()).put("addFdsl",0);
                        tdlsMap.get(fd_xstdmx.getTdmx_tdls()).put("addFdmz",0d);
                    }
                    Map map = tdlsMap.get(fd_xstdmx.getTdmx_tdls());
                    int addFdsl = (Integer) map.get("addFdsl");
                    double addFdmz = (Double) map.get("addFdmz");
 
                    addFdsl ++;
                    addFdmz = BigDecimalfiter.addscal(addFdmz, fd_xstdmx.getTdmx_mz(), Contants.scale);
                    map.put("addFdsl",addFdsl);
                    map.put("addFdmz",addFdmz);
                });
            }
            fdMxWlgsList.forEach(fdMxWlgs -> {
                Fd_XSTDMX  fd_xstdmx = new Fd_XSTDMX();
                fd_xstdmx.setTdmx_fdcph(null);
                fd_xstdmx.setTdmx_zcwlgsName(null);
                fd_xstdmx.setTdmx_zcphone(null);
                fd_xstdmx.setTdmx_zcdriver(null);
                fd_xstdmx.setTdmx_fdwlgsbh(null);
                fd_xstdmx.setTdmx_fdywbh(null);
                fd_xstdmx.setTdmx_fdbz(0);
                fd_xstdmx.setTdmx_zcbz(0);
                fd_xstdmx.setTdmx_tdfl(fdMxWlgs.getTdmxTdfl());
                fd_xstdmx.setTdmx_fdwlgsbh(fdMxWlgs.getWlgsNo());
                updateFd_XSTDMX.add(fd_xstdmx);
            });
            try(SqlSession sqlSession =  sqlSessionFactory.openSession(ExecutorType.BATCH,false)){
                // 删除明细和物流公司关系,并新增
                FdMxWlgsMapper mapper = sqlSession.getMapper(FdMxWlgsMapper.class);
                fdMxWlgsList.forEach(fdMxWlgs -> { // 需要删除相关信息(删除该业务单、删除车辆提单)
                    mapper.delete(fdMxWlgs.getTdmxTdfl());
                    mapper.insert(fdMxWlgs);
                });
                if(updateFd_XSTDMX != null) {
                    // 更新分单明细项为未分单
                    Fd_XSTDMXMapper fd_xstdmxMapper = sqlSession.getMapper(Fd_XSTDMXMapper.class);
                    updateFd_XSTDMX.forEach(fd_xstdmx -> fd_xstdmxMapper.updateZCnoFD(fd_xstdmx));
                }
                if(fd_xstdmxes!=null && fd_xstdmxes.size() > 0 ) {
                    Fd_BsheetMapper fd_bsheetMapper = sqlSession.getMapper(Fd_BsheetMapper.class);
                    VehicleXSTDMapper vehicleXSTDMapper =  sqlSession.getMapper(VehicleXSTDMapper.class);
                    for (Fd_XSTDMX fd_xstdmx : fd_xstdmxes) {
                        // 根据车牌号和业务号删除分单车辆,如果是拼单的情况;是否是拼单,取消这个就行,其他不管。
                        // 如果配车数量为0可以删除,其他情况,可以-1,把重量也减掉
                        if(StringUtils.isNotBlank(fd_xstdmx.getTdmx_fdcph()) && StringUtils.isNotBlank(fd_xstdmx.getTdmx_fdywbh())) {
                            List<Vehicle_XSTD> vehicleXSTDs = vehicleXSTDMapper.getlistbyVehicleIdandbsNoGp(fd_xstdmx.getTdmx_fdcph(), fd_xstdmx.getTdmx_fdywbh());
                            if (vehicleXSTDs != null && vehicleXSTDs.size() == 1) {
                                Vehicle_XSTD vehicleXSTD = vehicleXSTDs.get(0);
                                int num = vehicleXSTD.getFd_num();
                                if (num <= 1) {
                                    vehicleXSTDMapper.delbyVehicleId(fd_xstdmx.getTdmx_fdcph(), fd_xstdmx.getTdmx_fdywbh());
                                } else {
                                    vehicleXSTD.setFd_num(vehicleXSTD.getFd_num() - 1);
                                    vehicleXSTD.setFd_weight(BigDecimalfiter.subscal(vehicleXSTD.getFd_weight(), fd_xstdmx.getTdmx_mz(), Contants.scale));
                                    vehicleXSTDMapper.updatewithIDs(vehicleXSTD);
                                }
                            } else {
                                throw new Exception("出现同一辆车的同一业务单出现多个,请检查数据");
                            }
                        }
                        // vehicleXSTDMapper.delbyVehicleId(fd_xstdmx.getTdmx_fdcph(), fd_xstdmx.getTdmx_fdywbh());
                        Fd_Bsheet fd_bsheet = fd_bsheetMapper.getbybsNo(fd_xstdmx.getTdmx_fdywbh());
                        // 删除分单业务
                        fd_bsheetMapper.delbybsNo(fd_xstdmx.getTdmx_fdywbh());
                        // 远程删除数量
                        if(fd_bsheet!=null) {
                            JsonObject jo = new JsonObject();
                            jo.addProperty("bussinessNo", fd_xstdmx.getTdmx_fdywbh());
                            jo.addProperty("sdepartNo", fd_bsheet.getSdepartNo());
                            // 通过接口删除业务单
                            JsonObject pfob = Wxhtmethod.postJsonStr(Contants.YKTdelYwd_url, jo.toString());
                            int code = JSONobj.getint(pfob, "code");
                            if (code != 0) {
                                throw new Exception(JSONobj.getstring(pfob, "errmsg"));
                            }
                        }
                    }
                    // 需要更新提单的重量和数量
                    Fd_XSTDMapper fdXstdMapper = sqlSession.getMapper(Fd_XSTDMapper.class);
                    tdlsMap.forEach((k, v) -> {
                        Fd_XSTD xstd =  fdXstdMapper.get(k);
                        int addFdsl_1 = (Integer) v.get("addFdsl");
                        double addFdmz_1 = (Double) v.get("addFdmz");
                        xstd.setTd_tdls(k);
                        xstd.setTd_wfdsl(xstd.getTd_wfdsl() + addFdsl_1);
                        xstd.setTd_wfdzl(BigDecimalfiter.addscal(xstd.getTd_wfdzl(), addFdmz_1, Contants.scale));
                        fdXstdMapper.updateFD(xstd);
                    });
                }
                sqlSession.commit();
            }
        }
    }
 
 
    @Resource
    Fd_XSTDMXMapper fd_xstdmxMapper;
    @Resource
    BusinessMapper businessMapper;
 
 
}