1821349743@qq.com
2023-04-10 a81f40e2a09296aaf2ad144af571ea75c9c4504e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
package com.product.data.sync.util;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.product.admin.service.SystemMenusService;
import com.product.common.lang.StringUtils;
import com.product.core.cache.DataPoolCacheImpl;
import com.product.core.cache.DataPoolRefreshCache;
import com.product.core.config.Global;
import com.product.core.connection.ConnectionManager;
import com.product.core.dao.BaseDao;
import com.product.core.entity.DataTableEntity;
import com.product.core.entity.FieldMetaEntity;
import com.product.core.entity.FieldSetEntity;
import com.product.core.entity.RequestParameterEntity;
import com.product.core.exception.BaseException;
import com.product.core.service.support.AbstractBaseService;
import com.product.core.spring.context.SpringMVCContextHolder;
import com.product.core.util.CodeUtil;
import com.product.data.sync.config.CmnConst;
import com.product.data.sync.config.SystemCode;
import com.product.data.sync.service.FeDataDSService;
import com.product.data.sync.service.SyFeDataService;
import com.product.data.sync.service.media.GdMediaUtil;
import com.product.file.service.FileManagerService;
import com.product.util.BaseDaoServiceImpl;
import com.product.util.BaseUtil;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
 
import java.io.File;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.*;
 
/**
 * Copyright LX
 *
 * @Title: BusinessDataSync
 * @Project: product-server
 * @date: 2021-09-30 14:19
 * @author: lx
 * @Description: 线程同步业务数据
 */
public class BusinessDataSync extends AbstractBaseService implements Runnable {
    private static Logger logger = LoggerFactory.getLogger(SyFeDataService.class);
    @Autowired
    public BaseDao baseDao;
 
    @Override
    public BaseDao getBaseDao() {
        return baseDao;
    }
 
    @Override
    public void setBaseDao(BaseDao baseDao) {
        this.baseDao = baseDao;
    }
    @Autowired
    FileManagerService fileManagerService;
    public FileManagerService getFileManagerService() {
        return fileManagerService;
    }
    public void setFileManagerService(FileManagerService fileManagerService) {
        this.fileManagerService = fileManagerService;
    }
 
    @Autowired
    SystemMenusService systemMenusService;
 
    public SystemMenusService getSystemMenusService() {
        return systemMenusService;
    }
 
    public void setSystemMenusService(SystemMenusService systemMenusService) {
        this.systemMenusService = systemMenusService;
    }
    @Autowired
    private FeDataDSService feDataDSService;
 
    public FeDataDSService getFeDataDSService() {
        return feDataDSService;
    }
 
    public void setFeDataDSService(FeDataDSService feDataDSService) {
        this.feDataDSService = feDataDSService;
    }
    @Autowired
    public GdMediaUtil gdMediaUtil;
 
    public GdMediaUtil getGdMediaUtil() {
        return gdMediaUtil;
    }
 
    public void setGdMediaUtil(GdMediaUtil gdMediaUtil) {
        this.gdMediaUtil = gdMediaUtil;
    }
 
    //公司fe id 对应 产品uuid
    Map<String, FieldSetEntity> OrgIdUUIDmap = Maps.newHashMap();
 
    //fe 人员id 对应  userid
    private JSONObject userIdJson = new JSONObject();
    //user_id 与签名 uuid
    private JSONObject userIdSignature = new JSONObject();
    //用户userid 员工Fse
    private JSONObject userIdStaffFse = new JSONObject();
    //fe 部门id 对应 机构uuid
    private JSONObject groupJson = new JSONObject();
    //fe 部门id 对应 机构的公司uuid
    private JSONObject orgLevelJson = new JSONObject();
    //字段类型关联
    private JSONObject fieldTypeJson = new JSONObject();
    //流程nodes fe id 对应 产品uuid
    private JSONObject nodesIdUUID = new JSONObject();
    //源数据表名  本数据表名
    private JSONObject originalTable = new JSONObject();
    //源功能名称
    private String functionName;
    //唯一字段
    private String pk;
    //主表表名
    private String masterTableName;
    //源表名与uuid
    private Map<String,String> originalUuid = Maps.newHashMap();
    //协同办公 源流程数据PARENTGUID 对应本数据
    private Map<String,DataTableEntity>  parentGuidData = Maps.newHashMap();
    //表唯一标识   和本表uuid
    private JSONObject pxMap = new JSONObject();
    //岗位id 岗位uuid
    private JSONObject postJson = new JSONObject();
    //附件字段
    private String attachmentValue = "";
    //已开发公共功能 公告管理 问卷管理  考勤管理 协同办公
    private List<String> funTable = Lists.newArrayList("FE_APP5.PUB_NOTICE","FE_BASE5.RESEARCH_TOPIC","FE_APP5.APP_KQLRB","FE_BASE5.SYS_COLLABORATIVE","FE_APP5.BS_MEETING_FLOW");
 
    private String clientUUID;
 
    public String getClientUUID() {
        return clientUUID;
    }
 
    public void setClientUUID(String clientUUID) {
        this.clientUUID = clientUUID;
    }
    //方法Code
    private String tricode_funs;
 
    public BusinessDataSync(String tricode_funs){
        this.tricode_funs = tricode_funs;
    }
 
    public String TSPath =  Global.getSystemConfig("new.filePackage","");
 
    public Boolean isStr(String str) {
        boolean a = false;
        for (int i = 0; i < this.funTable.size(); i++) {
            if (str.equals(this.funTable.get(i))) {
                a = true;
            }
        }
        return a;
    }
    /**
     * 封装单位部门 人员对应Json
     */
    public void packageDepartmentPersonnel() {
        DataTableEntity staffsData = baseDao.listTable("product_sys_staffs");
        for (int i = 0; i < staffsData.getRows(); i++) {
            //数据源用户id
            userIdJson.put(staffsData.getString(i, "remark"), staffsData.getString(i, "user_id"));
            //用户user_id 对应staffs uuid
            userIdStaffFse.put(staffsData.getString(i, "user_id"), staffsData.getFieldSetEntity(i));
        }
        //查询有签名的用户
        DataTableEntity userSignatureData = baseDao.listTable("SELECT * FROM product_sys_users WHERE user_signature is not null", new String[]{});
        for (int i = 0; i < userSignatureData.getRows(); i++) {
            userIdSignature.put(userSignatureData.getString(i,"user_id"),userSignatureData.getString(i,"user_signature"));
        }
        DataTableEntity orgData = baseDao.listTable("product_sys_org_levels");
        for (int i = 0; i < orgData.getRows(); i++) {
            //源数据id 部门uuid
            groupJson.put(orgData.getString(i, "sequence"), orgData.getString(i, "uuid"));
            //公司uuid
            orgLevelJson.put(orgData.getString(i, "sequence"), orgData.getString(i, "org_level_uuid"));
        }
        DataTableEntity postData = baseDao.listTable("product_sys_job_posts");
        for (int i = 0; i < orgData.getRows(); i++) {
            //岗位id 岗位uuid
            postJson.put(postData.getString(i, "sequence"), postData.getString(i, "uuid"));
        }
    }
 
    /**
     * 同步表及表数据
     *
     * @param conn    连接
     * @param funCode 功能code
     * @throws SQLException
     */
    private String synchronizeTablesData(Connection conn, String funCode) throws SQLException {
        FieldSetEntity Orlfs = null;
        try {
            logger.info("功能code" + funCode);
            Orlfs = BaseDaoServiceImpl.getFieldSet(conn, "fe_base5.SYS_FUNCTION", "SF05=?", new Object[]{funCode});
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            throw e;
        }
        String sf28 = Orlfs.getString("sf28");
        //功能如果未关联基础表 查询流程表
        if (BaseUtil.strIsNull(sf28) || sf28.indexOf(".") == -1) {
            FieldSetEntity modelFse;
            try {
                //查询流程是否绑定表
                modelFse = BaseDaoServiceImpl.getFieldSet(conn, "fe_base5.wf_model", "wm05=(SELECT se16  FROM fe_base5.SYS_EVENT where se01=? and se08 = 1)", new Object[]{funCode
                });
            } catch (Exception e) {
                DataManipulationUtils.close(null, null, conn);
                throw e;
            }
            if (modelFse == null) {
                return null;
            }
            String wm04 = modelFse.getString("wm04");
            if (BaseUtil.strIsNull(wm04) || wm04.indexOf(".") == -1) {
                return null;
            } else {
                sf28 = wm04;
            }
        }
        //判断是否存在已开发功能的表
        //如果是已开发功能定义 通过自己定义的数据关联 同步数据
        String[] sf28s = sf28.split("\\.");
        try {
            this.syncTable(sf28s, !isStr(sf28), null, conn);
        }catch (Exception e){
            e.getStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
        }
 
        return sf28;
    }
 
    /**
     * 同步公告表数据
     *
     * @param conn
     * @param tableName
     * @throws SQLException
     */
    private void syncNotice(Connection conn, String tableName) throws SQLException {
        //判断是否是已经同步过的表
        DataTableEntity dataTable = baseDao.listTable("product_oa_announcement");
        if (!BaseUtil.dataTableIsEmpty(dataTable)) {
            return;
        }
        DataTableEntity noticeDt = null;
        try {
            noticeDt = BaseDaoServiceImpl.getDataTable(conn, tableName, "", new Object[]{});
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            throw e;
        }
        for (int i = 0; i < noticeDt.getRows(); i++) {
            FieldSetEntity feFs = noticeDt.getFieldSetEntity(i);
            FieldSetEntity fs = new FieldSetEntity();
            fs.setTableName("product_oa_announcement");
            fs.setValue("title", feFs.getString("title"));
            fs.setValue("content", feFs.getString("content"));
            fs.setValue("type", feFs.getString("notice_category"));
            //Set 转换为字符串逗号分隔
            //写方法判断是多人还是部门,若是部门转换为人
            fs.setValue("extent", this.getUserIds(conn,feFs.getString("receivers")));
            fs.setValue("expiration_date", feFs.getDate("displayed_date"));
            fs.setValue("status", feFs.getString("is_reminded"));
            fs.setValue("publish_status", feFs.getString("status"));
            String publisher = this.userIdJson.getString(feFs.getString("publisher"));
            if(BaseUtil.strIsNull(publisher)){
                continue;
            }
            fs.setValue("created_by", publisher);
            fs.setValue("created_utc_datetime", feFs.getDate("publish_date"));
 
            String uuid = baseDao.add(fs);
//            //重新获取jdbc连接
//            Connection connection = null;
//            try {
//                connection = this.getJDBC();
//            } catch (ClassNotFoundException e) {
//                e.printStackTrace();
//            }
            DataTableEntity subFeFs = getSubDt(conn, "FE_APP5.PUB_NOTICE_RECEIVER", "NOTICE_ID", feFs.getString("id"));
            DataTableEntity subData = new DataTableEntity();
            FieldMetaEntity f = new FieldMetaEntity();
            f.setTableName(new String[]{"product_oa_announcement_role"});
            subData.setMeta(f);
            for (int j = 0; j < subFeFs.getRows(); j++) {
                FieldSetEntity fsSubFe = subFeFs.getFieldSetEntity(j);
                FieldSetEntity fsSub = new FieldSetEntity();
                fsSub.setTableName("product_oa_announcement_role");
                String userId = userIdJson.getString(fsSubFe.getString("receiver"));
                if (null == userId) {
                    continue;
                }
                //获取所属部门
                fsSub.setValue("user_id", userId);
                fsSub.setValue("status", fsSubFe.getString("readed"));
                fsSub.setValue("announcement_uuid", uuid);
                subData.addFieldSetEntity(fsSub);
            }
            baseDao.add(subData);
//            DataManipulationUtils.close(null, null, connection);
        }
    }
 
    /**
     * 获取userId
     * 解析多选人员,部门,岗位
     * @param receivers 字段值
     */
    public String getUserIds(Connection conn,String receivers){
        String[] receiversArr = receivers.split(",");
        Set<String> extentArr = new HashSet<>();
        try {
            //查询公司部门表数据
            for (int j = 0; j < receiversArr.length; j++) {
                if (receiversArr[j].contains("[")) {
                    String companyId = receiversArr[j].replace("[", "").replace("]", "");
                    StringBuffer sql = new StringBuffer();
                    sql.append(" SELECT * FROM FE_BASE5.sys_users WHERE SU03 like CONCAT(CONCAT('%',(SELECT SG03 FROM fe_base5.sys_group WHERE SG00 = " + companyId + ")), '%') ");
                    //人员数据
                    DataTableEntity dataTableEntity = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new Object[]{});
                    String[] remark = new String[dataTableEntity.getRows()];
                    for (int i = 0; i < dataTableEntity.getRows(); i++) {
                        remark[i] = dataTableEntity.getString(i, "su00");
                    }
 
                    DataTableEntity userData = baseDao.listTable("product_sys_staffs", BaseUtil.buildQuestionMarkFilter("remark", remark.length, true), remark);
 
                    if (!BaseUtil.dataTableIsEmpty(userData)) {
                        for (int i = 0; i < userData.getRows(); i++) {
                            extentArr.add(userData.getString(i, "user_id"));
                        }
                    }
                    //{岗位}
                } else if (receiversArr[j].contains("{")) {
                    String postId = receiversArr[j].replace("{", "").replace("}", "");
                    StringBuffer sql = new StringBuffer();
                    sql.append(" SELECT * FROM FE_BASE5.sys_users WHERE SU34 = " + postId);
                    //人员数据
                    DataTableEntity dataTableEntity = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new Object[]{});
                    String[] remark = new String[dataTableEntity.getRows()];
                    for (int i = 0; i < dataTableEntity.getRows(); i++) {
                        remark[i] = dataTableEntity.getString(i, "su00");
                    }
 
                    DataTableEntity userData = baseDao.listTable("product_sys_staffs", BaseUtil.buildQuestionMarkFilter("remark", remark.length, true), remark);
 
                    if (!BaseUtil.dataTableIsEmpty(userData)) {
                        for (int i = 0; i < userData.getRows(); i++) {
                            extentArr.add(userData.getString(i, "user_id"));
                        }
                    }
                } else {
                    String userId = userIdJson.getString(receiversArr[j]);
                    if (null == userId) {
                        continue;
                    }
                    extentArr.add(userId);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new BaseException(e.getMessage(), e.toString());
        }
        return StringUtils.join(extentArr, ",");
    }
 
    /**
     * 查询子表信息
     *
     * @param conn
     * @param subTableName 子表名
     * @param fieldName    字段名
     * @param field        字段值
     * @return
     * @throws SQLException
     */
    private DataTableEntity getSubDt(Connection conn, String subTableName, String fieldName, String field) throws SQLException {
        DataTableEntity noticeDt = null;
        try {
            noticeDt = BaseDaoServiceImpl.getDataTable(conn, subTableName, fieldName + "=?", new Object[]{field});
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            throw e;
        }
        return noticeDt;
    }
 
    /**
     * 同步问卷调查 0
     *
     * @param conn
     * @param tableName
     * @throws SQLException
     */
    private void syncResearchTopic(Connection conn, String tableName) throws SQLException {
        //判断是否是已经同步过的表
        DataTableEntity dataTable = baseDao.listTable("product_oa_questionnaire");
        if (!BaseUtil.dataTableIsEmpty(dataTable)) {
            return;
        }
        DataTableEntity researchTopicDt = null;
        try {
            researchTopicDt = BaseDaoServiceImpl.getDataTable(conn, tableName, "", new Object[]{});
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            throw e;
        }
        JSONObject qSubIdUUIDMap = new JSONObject();
        JSONObject qSubOptionIdUUIDMap = new JSONObject();
 
        for (int i = 0; i < researchTopicDt.getRows(); i++) {
            FieldSetEntity feFs = researchTopicDt.getFieldSetEntity(i);
            FieldSetEntity fs = new FieldSetEntity();
            //问卷管理
            fs.setTableName("product_oa_questionnaire");
            //问卷标题
            fs.setValue("questionnaire_title", feFs.getString("rt01"));
            //问卷说明
            fs.setValue("questionnaire_explain", feFs.getString("rt01"));
            //问卷内容
            fs.setValue("questionnaire_content", feFs.getString("rt02"));
            //是否匿名(1.是、0.否)
            fs.setValue("is_anonymous", feFs.getString("rt06"));
            String[] RT13Arr = feFs.getString("rt13").split(",");
            ArrayList<String> votersArr = new ArrayList<>();
            for (int j = 0; j < RT13Arr.length; j++) {
                RT13Arr[j] = RT13Arr[j].replace("[", "");
                RT13Arr[j] = RT13Arr[j].replace("]", "");
                String userId = userIdJson.getString(RT13Arr[j]);
            }
            if (votersArr.size() == 0) {
                continue;
            }
            //参与投票人
            fs.setValue("voters", StringUtils.join(votersArr, ","));
            //调查截止日期
            fs.setValue("deadline", feFs.getString("rt04"));
            String[] RT15Arr = feFs.getString("rt15").split(",");
            String[] resultViewerArr = new String[RT15Arr.length];
            for (int j = 0; j < RT15Arr.length; j++) {
                resultViewerArr[j] = userIdJson.getString(RT15Arr[j]);
            }
            //结果查看人
            fs.setValue("result_viewer", StringUtils.join(resultViewerArr, ","));
            //发布人
            fs.setValue("publisher", userIdJson.getString(feFs.getString("rt08")));
            //发布时间
            fs.setValue("pubdate", feFs.getDate("rt03"));
            //是否发布
            fs.setValue("is_publish", feFs.getString("rt05"));
            fs.setValue("created_by", 1);
            fs.setValue("created_utc_datetime", new Date());
            //主表uuid
            String uuid = baseDao.add(fs);
            DataTableEntity subFeFs = getSubDt(conn, "FE_BASE5.RESEARCH_SUB", "RS01", feFs.getString("rt00"));
            for (int j = 0; j < subFeFs.getRows(); j++) {
                FieldSetEntity feSubFs = subFeFs.getFieldSetEntity(i);
                FieldSetEntity subFs = new FieldSetEntity();
                //问卷管理子表
                subFs.setTableName("product_oa_questionnaire_sub");
                // 主表uuid
                subFs.setValue("questionnaire_uuid", uuid);
                //内容类型(1.单选题目、2.复选题目、3.简答题)
                subFs.setValue("content_type", feSubFs.getInteger("rs04") + 1);
                //选项题目
                subFs.setValue("option_topic", feSubFs.getString("rs02"));
                //题目说明
                subFs.setValue("title_description", feSubFs.getString("rs03"));
                //多选择类型(1.最多、2.最少、3.必选)
                subFs.setValue("option_type", feSubFs.getString("rs07"));
                //可选择项数
                subFs.setValue("option_num", feSubFs.getString("rs06"));
                String subUUID = baseDao.add(subFs);
                qSubIdUUIDMap.put(subUUID, feSubFs.getString("rs00"));
                if (feSubFs.getInteger("rs04") != 2) {
                    DataTableEntity subFeFsto = getSubDt(conn, "fe_base5.RESEARCH_OPTION", "RO01", feSubFs.getString("RS00"));
                    for (int k = 0; k < subFeFsto.getRows(); k++) {
                        FieldSetEntity feSubFsto = subFeFsto.getFieldSetEntity(i);
                        FieldSetEntity subFsto = new FieldSetEntity();
                        subFsto.setTableName("product_oa_questionnaire_sub_option");
                        //问卷管理子表uuid
                        subFsto.setValue("parent_uuid", subUUID);
                        //选项内容
                        subFsto.setValue("option_content", feSubFsto.getString("ro02"));
                        //是否可填(1.是、0.否)
                        subFsto.setValue("is_write", feSubFsto.getString("ro04"));
                        //选项序号
                        subFsto.setValue("option_num", numberToLetter(k + 1));
                        String subUUIDto = baseDao.add(subFsto);
                        qSubOptionIdUUIDMap.put(feSubFsto.getString("ro00"), subUUIDto);
                    }
                }
            }
            DataTableEntity vFeFs = getSubDt(conn, "fe_base5.RESEARCH_VOTER", "rv01", feFs.getString("rt00"));
            for (int j = 0; j < vFeFs.getRows(); j++) {
                FieldSetEntity feSubFs = vFeFs.getFieldSetEntity(j);
                FieldSetEntity subFs = new FieldSetEntity();
                subFs.setTableName("product_oa_questionnaire_mine");
                subFs.setValue("questionnaire_uuid", uuid);
                subFs.setValue("voting_status", feSubFs.getString("rv06"));
                logger.info("用户user_id:" + userIdJson.getString(feSubFs.getString("rv04")));
                subFs.setValue("vote_user", userIdJson.getString(feSubFs.getString("rv04")));
                subFs.setValue("subject_uuid", qSubIdUUIDMap.getString(feSubFs.getString("rv02")));
                subFs.setValue("option_answer_uuid", qSubOptionIdUUIDMap.getString(feSubFs.getString("rv03")));
                subFs.setValue("answer_contents", feSubFs.getString("rv07"));
                baseDao.add(subFs);
            }
        }
    }
 
    //数字转字母 1-26 : A-Z
    private String numberToLetter(int num) {
        if (num <= 0) {
            return null;
        }
        String letter = "";
        num--;
        do {
            if (letter.length() > 0) {
                num--;
            }
            letter = ((char) (num % 26 + (int) 'A')) + letter;
            num = (int) ((num - num % 26) / 26);
        } while (num > 0);
 
        return letter;
    }
 
    //车辆基本信息表
    private void syncCarInfo(Connection conn, String tableName) throws SQLException {
        //判断是否是已经同步过的表
        DataTableEntity dataTable = baseDao.listTable("product_oa_car_driver_info");
        if (!BaseUtil.dataTableIsEmpty(dataTable)) {
            return;
        }
        //同步司机信息
        DataTableEntity driverInfoDt = null;
        try {
            driverInfoDt = BaseDaoServiceImpl.getDataTable(conn, "fe_app5.CHAUFFEUR_INFO", "", new Object[]{});
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            throw e;
        }
 
        JSONObject driverIdUUIDMap = new JSONObject();
 
        for (int i = 0; i < driverInfoDt.getRows(); i++) {
            FieldSetEntity fsFe = driverInfoDt.getFieldSetEntity(i);
            FieldSetEntity fs = new FieldSetEntity();
            fs.setTableName("product_oa_car_driver_info");
            fs.setValue("name", fsFe.getString("CHAUFFEUR_NAME"));
            fs.setValue("driver_license_num", fsFe.getString("LICENCE_NO"));
            fs.setValue("IDCard_num", fsFe.getString("IDENTITY_CARD_NO"));
            fs.setValue("driving_model", carType(fsFe.getString("DRIVE_CAR_MODEL")));
            fs.setValue("driving_experience", fsFe.getString("DRIVE_YEAR"));
            fs.setValue("phone_num", fsFe.getString("HANDSET_NO"));
            fs.setValue("address", fsFe.getString("ADDRESS"));
            fs.setValue("created_by", 1);
            fs.setValue("created_utc_datetime", new Date());
            String uuid = baseDao.add(fs);
            driverIdUUIDMap.put("ID", uuid);
        }
        //同步车辆基本信息
        DataTableEntity researchTopicDt = null;
        try {
            researchTopicDt = BaseDaoServiceImpl.getDataTable(conn, tableName, "", new Object[]{});
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            throw e;
        }
        JSONObject carBrandUUIDMap = new JSONObject();
        JSONObject carIdUUIDMap = new JSONObject();
 
        for (int i = 0; i < researchTopicDt.getRows(); i++) {
            FieldSetEntity fsFe = researchTopicDt.getFieldSetEntity(i);
            FieldSetEntity fs = new FieldSetEntity();
            fs.setTableName("product_oa_car_info");
            fs.setValue("plate_number", fsFe.getString("CAR_BRAND_NO"));
            fs.setValue("vehicle_status", fsFe.getString("CAR_STATE"));
//            fs.setValue("org_level_uuid", OrgIdUUIDmap.getString(fsFe.getString("CAR_BRAND_NO")));
            fs.setValue("vehicle_type", carType(fsFe.getString("CAR_TYPE")));
            fs.setValue("leaders", userIdJson.getString(fsFe.getString("FROM_LEADER")));
            fs.setValue("purchase_date", fsFe.getDate("BUY_DATE"));
            fs.setValue("brand_series", fsFe.getString("ROAD_BRIDGE_CHARGE"));
            fs.setValue("purchase_price", fsFe.getString("BUY_PRICE"));
            fs.setValue("vehicle_use", fsFe.getString("OIL_CHARGE"));
            fs.setValue("seats_num", fsFe.getString("SEAT_AMOUNT"));
            fs.setValue("fuel_type", fsFe.getString("OIL_TYPE"));
            fs.setValue("owner_name", fsFe.getString("MASTER_NAME"));
            fs.setValue("vehicle_certificate", fsFe.getString("CAR_PAPER"));
            //附件
//            fs.setValue("attachment_uuid",);
            if (!fsFe.getString("DRIVER").isEmpty()) {
                fs.setValue("driver_id", driverIdUUIDMap.getString(fsFe.getString("DRIVER")));
            }
            fs.setValue("created_by", 1);
            fs.setValue("created_utc_datetime", new Date());
            String uuid = baseDao.add(fs);
            carBrandUUIDMap.put(fsFe.getString("CAR_BRAND_NO"), uuid);
            carIdUUIDMap.put(fsFe.getString("ID"), uuid);
        }
        //同步车辆出险事故信息表
        DataTableEntity carSlipDt = null;
        try {
            carSlipDt = BaseDaoServiceImpl.getDataTable(conn, "fe_app5.CAR_SLIP", "", new Object[]{});
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            throw e;
        }
        for (int i = 0; i < carSlipDt.getRows(); i++) {
            FieldSetEntity fsFe = carSlipDt.getFieldSetEntity(i);
            FieldSetEntity fs = new FieldSetEntity();
            fs.setTableName("product_oa_car_accident_record");
            fs.setValue("vehicle_info_uuid", carBrandUUIDMap.getString(fsFe.getString("CAR_BRAND_NO")));
            fs.setValue("accident_time", fsFe.getDate("SLIP_DATE"));
            fs.setValue("driver_info_uuid", driverIdUUIDMap.getString(fsFe.getString("DRIVE_PERSON")));
            fs.setValue("accident_location", fsFe.getDate("SLIP_ADDRESS"));
            fs.setValue("accident_cause", fsFe.getDate("SLIP_REASON"));
            fs.setValue("created_by", 1);
            fs.setValue("created_utc_datetime", new Date());
            fs.setValue("flow_flag", 2);
            baseDao.add(fs);
        }
        //同步车辆申请信息表
        DataTableEntity carApplicationDt = null;
        try {
            carApplicationDt = BaseDaoServiceImpl.getDataTable(conn, "fe_app5.CAR_APPLICATION", "", new Object[]{});
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            throw e;
        }
        for (int i = 0; i < carApplicationDt.getRows(); i++) {
            FieldSetEntity fsFe = carApplicationDt.getFieldSetEntity(i);
            FieldSetEntity fs = new FieldSetEntity();
            fs.setTableName("product_oa_car_application");
            fs.setValue("applicant", userIdJson.getString(fsFe.getString("PROPOSER")));
//            fs.setValue("org_level_uuid", OrgIdUUIDmap.getString(fsFe.getString("SECTION_DEPARTMENT")));
            fs.setValue("applicattion_time", fsFe.getDate("APPLICATION_DATE"));
            fs.setValue("start_place", fsFe.getString("START_END_ADDRESS"));
            fs.setValue("person_board", fsFe.getString("FOLLOW_PERSON"));
            fs.setValue("vehicle_line", fsFe.getString("CAR_LINE"));
            fs.setValue("scheduled_start_time", fsFe.getDate("USE_START_DATE"));
            fs.setValue("scheduled_end_time", fsFe.getDate("USE_END_DATE"));
            fs.setValue("project_name", fsFe.getString("USE_END_DATE"));
            fs.setValue("use_reason", fsFe.getString("USE_REASON"));
            if (!fsFe.getString("DRIVER").isEmpty()) {
                fs.setValue("driver_info_uuid", driverIdUUIDMap.getString(fsFe.getString("DRIVER")));
            }
            fs.setValue("status", fsFe.getString("STATUS"));
            fs.setValue("driving_time", fsFe.getString("START_DATE"));
            fs.setValue("return_time", fsFe.getString("RETURN_DATE"));
            fs.setValue("actual_line", fsFe.getString("FACT_WAY"));
            fs.setValue("repair_cost", fsFe.getString("id04"));
            fs.setValue("fuel_charge", fsFe.getString("OIL_CHARGE"));
            fs.setValue("toll", fsFe.getString("id05"));
            fs.setValue("other_expenses", fsFe.getString("id01"));
            fs.setValue("total_cost", fsFe.getString("id02"));
            fs.setValue("manager_confirmation", fsFe.getString("id08"));
            fs.setValue("created_by", 1);
            fs.setValue("created_utc_datetime", new Date());
            fs.setValue("flow_flag", 2);
            baseDao.add(fs);
        }
    }
 
    private String carType(String type) {
        String reType = "";
        switch (type) {
            case "轿车":
                reType = "1";
                break;
            case "货车":
                reType = "2";
                break;
            default:
                reType = "3";
        }
        return reType;
    }
 
    /**
     * 同步已开发功能数据
     *
     * @param tableName 表名
     * @return
     * @throws SQLException
     */
    private void syncFunTable(Connection conn, String tableName) throws SQLException {
        //公告表
        if (tableName.equals("FE_APP5.PUB_NOTICE")) {
            //两个表建立关联
            this.originalTable.put("PUB_NOTICE", "product_oa_announcement");
            syncNotice(conn, tableName);
            //修改已同步附件 添加 module_uuid function_uuid
            baseDao.executeUpdate(" UPDATE product_sys_attachments SET module_uuid = ?, function_uuid = ? WHERE attachment_data_table = ? AND function_uuid is null ",new String[]{"036ccacd-47da-4f6e-9cf7-972211717e6e", "ed86d09a-23be-4d8c-8cb2-be8622fe50f4", "product_oa_announcement"});
        }
        //考勤表 需同步关联数据如请假表 外出表
        if (tableName.equals("FE_APP5.APP_KQLRB")) {
            this.originalTable.put("APP_KQLRB", "product_oa_punch_record");
            this.originalTable.put("PLEASELEAVE", "product_oa_ask_for_leave");
            this.originalTable.put("FT_1_WCDJB00", "product_oa_business_trip");
            //同步考勤
            this.synchronousClock(conn);
            System.out.println("=================考勤同步成功===============");
        }
        //协同办公
        if (tableName.equals("FE_BASE5.SYS_COLLABORATIVE")) {
            this.originalTable.put("SYS_COLLABORATIVE", "product_oa_cooperates");
            //协同办公数据
            this.syncCcooperates(conn, tableName);
            //协同模板数据
            this.syncCollaborativeTemplate(conn);
            baseDao.executeUpdate(" UPDATE product_sys_attachments SET module_uuid = ?, function_uuid = ? WHERE attachment_data_table = ? AND function_uuid is null ",new String[]{"127c3f55-a7b4-4a77-a097-a65ba95b76f0", "6e587365-8ebd-4ab5-bade-dd3b1bf640f8", "product_oa_cooperates"});
 
            baseDao.executeUpdate(" UPDATE product_sys_attachments SET module_uuid = ?, function_uuid = ? WHERE attachment_data_table = ? AND function_uuid is null ",new String[]{"127c3f55-a7b4-4a77-a097-a65ba95b76f0", "6e587365-8ebd-4ab5-bade-dd3b1bf640f8", "product_oa_cooperate_flow_node"});
 
            baseDao.executeUpdate(" UPDATE product_sys_attachments SET module_uuid = ?, function_uuid = ? WHERE attachment_data_table = ? AND function_uuid is null ",new String[]{"127c3f55-a7b4-4a77-a097-a65ba95b76f0", "6e587365-8ebd-4ab5-bade-dd3b1bf640f8", "product_oa_cooperate_flow_reply"});
            System.out.println("=================协同办公同步成功===============");
        }
        //会议同步
        if(tableName.equals("FE_APP5.BS_MEETING_FLOW")){
            //判断是否是已经同步过的表
            DataTableEntity dataTable = baseDao.listTable("product_oa_conference_room_config");
            if (!BaseUtil.dataTableIsEmpty(dataTable)) {
                return;
            }
            //会议室同步
            Map<String, String> map = this.meetingRoomSync(conn,"FE_APP5.BS_MEETINGROOM");
            this.originalTable.put("BS_MEETINGROOM", "product_oa_conference_room_config");
            //会议同步
            this.meetingSynchronous(conn,tableName,map);
            this.originalTable.put("BS_MEETING_FLOW", "product_oa_conference_apply");
            //单独同步会议流程  待调整
            FieldSetEntity user = baseDao.getFieldSetByFilter("product_sys_org_manager" , " manager_type = ? ", new String[]{"2"}, false);
            //同步会议流程
            try {
                this.attachmentValue = ",attachment,";
                //迁移 wf_model流程模块表
                String typeCode = this.syncModel("035-411-000", conn, "24917f78-c672-4432-b7a8-a7a2dbc9f45a", "FE_APP5.BS_MEETING_FLOW", null, 1, null,false);
                //根据要求流程要同步两次 相同流程的typeCode相同
                if(!BaseUtil.strIsNull(typeCode)){
                    this.syncModel("035-411-000", conn, "24917f78-c672-4432-b7a8-a7a2dbc9f45a", "FE_APP5.BS_MEETING_FLOW", "00000000-0000-0000-0000-000000000000", user.getInteger("user_id"), typeCode,true);
                }
                //mvc 会议页面绑定新的流程
                FieldSetEntity page = baseDao.getFieldSet("product_sys_mvc_page","5ab3ef19-ba6d-4d47-8082-3e21fa1f0a0f",false);
                page.setValue("flow_uuid",typeCode);
                baseDao.update(page);
            } catch (SQLException e) {
                e.printStackTrace();
            }
            System.out.println("=================会议管理同步成功===============");
        }
    }
 
    /**
     * 同步考勤
     * @param conn
     * @throws SQLException
     */
    private void synchronousClock(Connection conn)throws SQLException{
        //同步请假 PLEASELEAVE
        DataTableEntity pleaseleave = null;
        try {
            pleaseleave = BaseDaoServiceImpl.getDataTable(conn, "FE_APP5.PLEASELEAVE", "", new Object[]{});
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            throw e;
        }
        try {
            this.leaveApplyFor(pleaseleave);
        }catch (BaseException e){
            e.printStackTrace();
        }
        FieldSetEntity user = baseDao.getFieldSetByFilter("product_sys_org_manager" , " manager_type = ? ", new String[]{"2"}, false);
        //单独同步请假流程
        try {
            this.attachmentValue = ",accessory_uuid,";
            //迁移 wf_model流程模块表
            String typeCode = this.syncModel("019-015-000", conn, "66a6ff4b-1c60-4dfe-a544-4bac81d17efe", "FE_APP5.PLEASELEAVE", null, 1, null,false);
            //根据要求流程要同步两次 相同流程的typeCode相同
            if(!BaseUtil.strIsNull(typeCode)){
                this.syncModel("019-015-000", conn, "66a6ff4b-1c60-4dfe-a544-4bac81d17efe", "FE_APP5.PLEASELEAVE", "00000000-0000-0000-0000-000000000000", user.getInteger("user_id"), typeCode,true);
            }
            //mvc 会议页面绑定新的流程
            FieldSetEntity page = baseDao.getFieldSet("product_sys_mvc_page","77897853-4059-4b57-ac65-45ff8d6f4fe3",false);
            page.setValue("flow_uuid",typeCode);
            baseDao.update(page);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        //同步外出 FT_1_WCDJB00
        //同步外出里面的数据 含外出 出差 请假
        DataTableEntity wcdj = null;
        try {
            wcdj = BaseDaoServiceImpl.getDataTable(conn, "SELECT TO_NUMBER(to_date(to_char(A.F1W09,'yyyymmdd'),'yyyymmdd')- to_date(to_char(A.F1W08,'yyyymmdd'),'yyyymmdd')) + 1 as DAY,A.* FROM FE_APP5.FT_1_WCDJB00 A",  new Object[]{});
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            throw e;
        }
        this.goOutApplyFor(wcdj);
        //同步考勤
        DataTableEntity clockDt = null;
        try {
            clockDt = BaseDaoServiceImpl.getDataTable(conn, "FE_APP5.APP_KQLRB", "", new Object[]{});
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            throw e;
        }
        this.synchronousClock(clockDt);
    }
 
 
    /**
     * 同步请假申请
     * @param pleaseleave 请假data数据
     */
    private void leaveApplyFor(DataTableEntity pleaseleave) throws BaseException{
        //同步请假数据
        if(!BaseUtil.dataTableIsEmpty(pleaseleave)){
            for (int i = 0; i < pleaseleave.getRows(); i++) {
                FieldSetEntity leaveFse = pleaseleave.getFieldSetEntity(i);
                FieldSetEntity fieldSetEntity = new FieldSetEntity();
                fieldSetEntity.setTableName("product_oa_ask_for_leave");
                fieldSetEntity.setValue("id", leaveFse.getInteger("pl00"));
                //PL11    请休假开始时间            fill_in_time    填单时间
                String pl11 = leaveFse.getString("pl11");
                fieldSetEntity.setValue("fill_in_time",pl11);
                //PL11    请休假开始时间                 start_time    开始时间
                fieldSetEntity.setValue("start_time",pl11);
                //PL15    请休假结束时间                end_time    结束时间
                String pl15 = leaveFse.getString("pl15");
                if(BaseUtil.strIsNull(pl15)){
                    if(BaseUtil.strIsNull(pl11)){
                        continue;
                    }else {
                        pl15 = pl11;
                    }
                }
                fieldSetEntity.setValue("end_time",pl15);
                //PL12    请休假天数 day    请假天数
                fieldSetEntity.setValue("day",leaveFse.getString("pl12"));
                //PL09    请休假原因 cause    请假原因
                String pl09 = leaveFse.getString("pl09");
                //PL10    请休假类别 leave_type    请假类型
                String pl10 = leaveFse.getString("pl10");
                if(BaseUtil.strIsNull(pl09)){
                    if(BaseUtil.strIsNull(pl10)){
                        continue;
                    }else {
                        pl09 = pl10;
                    }
                }
                fieldSetEntity.setValue("cause",pl09);
                //PL01    申请人姓名 created_by    创建人
                String userId = userIdJson.getString(leaveFse.getString("pl01"));
                if(BaseUtil.strIsNull(userId)){
                    continue;
                }
                fieldSetEntity.setValue("created_by",userId);
                //staff_uuid    员工uuid
                FieldSetEntity staff = (FieldSetEntity)this.userIdStaffFse.get(userId);
                fieldSetEntity.setValue("staff_uuid",staff.getUUID());
                //PL14    科室 org_level_uuid    公司uuid
                String dept = leaveFse.getString("pl14");
                String org_level_uuid = this.orgLevelJson.getString(dept);
                if(BaseUtil.strIsNull(org_level_uuid)){
                    continue;
                }
                fieldSetEntity.setValue("org_level_uuid",org_level_uuid);
                //部门
                fieldSetEntity.setValue("department_uuid",this.groupJson.getString(dept));
 
                String leave_type;
                if(BaseUtil.strIsNull(pl10)){
                    //改为年假
                    leave_type = "7";
                }else {
                    switch (pl10) {
                        case "产假":
                            leave_type = "5";
                            break;
                            //改为年假
                        case "休假":
                            leave_type = "7";
                            break;
                        case "事假":
                            leave_type = "1";
                            break;
                        case "婚假":
                            leave_type = "9";
                            break;
                        case "病假":
                            leave_type = "2";
                            break;
                        default:
                            //休假  改为年假
                            leave_type = "7";
                    }
                }
                fieldSetEntity.setValue("leave_type", leave_type);
                fieldSetEntity.setValue("flow_flag", leaveFse.getString("status"));
                String uuid = baseDao.add(fieldSetEntity);
                pxMap.put("PLEASELEAVE"+leaveFse.getString("pl00"),uuid);
            }
        }
    }
 
    /**
     * 同步外出申请    分别同步到外出申请  出差申请 请假申请
     * @param wcdj 外出data数据
     */
    private void goOutApplyFor(DataTableEntity wcdj) throws SQLException {
        if(!BaseUtil.dataTableIsEmpty(wcdj)){
            for (int i = 0; i < wcdj.getRows(); i++) {
                FieldSetEntity fse = wcdj.getFieldSetEntity(i);
                //F1W05    外出类型
                String f1w05 = fse.getString("f1w05");
                if(!BaseUtil.strIsNull(f1w05)) {
                    switch (f1w05) {
                        //出差    同步外出里面出差数据
                        case "10":
                            this.syncEvection(fse);
                            break;
                        //外出开会 同步外出里面外出数据
                        case "11":
                            this.synchronousOut(fse, "0");
                            break;
                        //外勤
                        case "12":
                            this.synchronousOut(fse, "1");
                            break;
                        //调休
                        case "13":
                            this.synchronizationLeave(fse, "4", "调休");
                            break;
                        //休假
                        case "14":
                            this.synchronizationLeave(fse, "11", "休假");
                            break;
                        //病假
                        case "15":
                            this.synchronizationLeave(fse, "2", "病假");
                            break;
                        //事假
                        case "16":
                            this.synchronizationLeave(fse, "1", "事假");
                            break;
                        default:
                            break;
                    }
                }
            }
        }
        //同步外出数据
//        if(!BaseUtil.dataTableIsEmpty(qjsq)){
//            for (int i = 0; i < qjsq.getRows(); i++) {
 
//                F1W01    登记人
//                F1W02    送审标识
//                F1W03    公司编码
//                F1W04    申请人
 
//                F1W06    外出事由
//                F1W07    是否归来
//                F1W08    外出时间
//                F1W09    回来时间
//                F1W10    时段
//                F1W11    科室
//                F1W12    备用
//                fieldSetEntity.setTableName("product_oa_business_trip");
//            }
//        }
    }
 
    /**
     * 外出数据同步到请假
     * @param fse 请假数据
     * @param type 请假类型
     */
    private void synchronizationLeave(FieldSetEntity fse, String type, String typeString){
        FieldSetEntity fieldSetEntity = new FieldSetEntity();
        fieldSetEntity.setTableName("product_oa_ask_for_leave");
        String f1w08 = fse.getString("f1w08");
        //f1w08    请休假开始时间    fill_in_time    填单时间
        fieldSetEntity.setValue("fill_in_time",f1w08);
        //f1w08    请休假开始时间                 start_time    开始时间
        fieldSetEntity.setValue("start_time",f1w08);
        //f1w09    请休假结束时间                end_time    结束时间
        fieldSetEntity.setValue("end_time",fse.getString("f1w09"));
        //day    请休假天数 day    请假天数
        fieldSetEntity.setValue("day",fse.getString("day"));
        //f1w06    请休假原因 cause    请假原因
        String f1w06 = fse.getString("f1w06");
        //若请假原因为空就用请假类型
        if(BaseUtil.strIsNull(f1w06)){
            f1w06 = typeString;
        }
        fieldSetEntity.setValue("cause",f1w06);
        //f1w01    登记人 created_by    创建人
        String userId = userIdJson.getString(fse.getString("f1w01"));
        if(BaseUtil.strIsNull(userId)){
             userId = userIdJson.getString(fse.getString("f1w04"));
             if(BaseUtil.strIsNull(userId)){
                 return;
             }
        }
        fieldSetEntity.setValue("created_by",userId);
        //staff_uuid    员工uuid
        FieldSetEntity staff = (FieldSetEntity)this.userIdStaffFse.get(userId);
        fieldSetEntity.setValue("staff_uuid", staff.getUUID());
        //f1w11    科室 org_level_uuid    公司uuid
        String dept = fse.getString("f1w11");
        String org_level_uuid = this.orgLevelJson.getString(dept);
        if(BaseUtil.strIsNull(org_level_uuid)){
            org_level_uuid = staff.getString("org_level_uuid");
        }
        fieldSetEntity.setValue("org_level_uuid",org_level_uuid);
        //部门
        String dept_uuid = this.groupJson.getString(dept);
        if(BaseUtil.strIsNull(dept_uuid)){
            dept_uuid  = staff.getString("dept_uuid");
        }
        fieldSetEntity.setValue("department_uuid",dept_uuid);
        fieldSetEntity.setValue("leave_type", type);
        fieldSetEntity.setValue("flow_flag", fse.getString("f1w02"));
        try {
            baseDao.add(fieldSetEntity);
        }catch (BaseException e){
            e.printStackTrace();
        }
    }
 
    /**
     * 同步出差数据
     * @param fse 出差数据
     */
    private void syncEvection(FieldSetEntity fse){
        FieldSetEntity fieldSetEntity = new FieldSetEntity();
        fieldSetEntity.setTableName("product_oa_business_trip");
        //applicant    申请人员
        String user_id = this.userIdJson.getString(fse.getString("f1w01"));
        if(BaseUtil.strIsNull(user_id)){
            return;
        }
        fieldSetEntity.setValue("applicant",user_id);
        //申请日期
        String f1w08 = fse.getString("f1w08");
        fieldSetEntity.setValue("application_time",f1w08);
        //budget    预算金额
        fieldSetEntity.setValue("budget",0);
        //结束时间
        fieldSetEntity.setValue("business_last_time",fse.getString("f1w09"));
        //出差时间
        fieldSetEntity.setValue("business_start_time",f1w08);
        //business_trip_place    出差地点 空
        fieldSetEntity.setValue("business_trip_place","[无出差地点]");
        //创建人
        String f1w04 = this.userIdJson.getString(fse.getString("f1w04"));
        if(BaseUtil.strIsNull(f1w04)){
            f1w04 = user_id;
        }
        fieldSetEntity.setValue("created_by",f1w04);
        //创建时间
        fieldSetEntity.setValue("created_utc_datetime",f1w08);
        //    申请部门    string    1
        String dept = fse.getString("f1w11");
        String department = this.groupJson.getString(dept);
        FieldSetEntity staff = (FieldSetEntity)this.userIdStaffFse.get(user_id);
        if(BaseUtil.strIsNull(department)){
            department = staff.getString("dept_uuid");
        }
        fieldSetEntity.setValue("department",department);
        //documengt_number    单据编号
        fieldSetEntity.setValue("documengt_number","[无单据编号]");
        //流程标识
        fieldSetEntity.setValue("flow_flag",fse.getString("f1w02"));
        //org_level_uuid    关联公司
        String org_level_uuid = this.orgLevelJson.getString(dept);
        if(BaseUtil.strIsNull(org_level_uuid)){
            org_level_uuid = staff.getString("org_level_uuid");
        }
        fieldSetEntity.setValue("org_level_uuid",org_level_uuid);
        //post    职务(关联岗位信息表uuid)
        fieldSetEntity.setValue("post",staff.getString("job_post_uuid"));
        //出差天数
        fieldSetEntity.setValue("total_days",fse.getString("day"));
        //F1W06    外出事由
        String f1w06 = fse.getString("f1w06");
        if(BaseUtil.strIsNull(f1w06)){
            f1w06 = "出差";
        }
        fieldSetEntity.setValue("reasons_for_business",f1w06);
        try{
            baseDao.add(fieldSetEntity);
        }catch (BaseException e){
            e.printStackTrace();
        }
    }
    /**
     * 同步外出数据
     * @param fse 外出数据
     */
    private void synchronousOut(FieldSetEntity fse, String out_type){
        FieldSetEntity fieldSetEntity = new FieldSetEntity();
        fieldSetEntity.setTableName("product_oa_go_out_application");
        //actual_start_time    实际开始时间
        String f1w08 = fse.getString("f1w08");
        fieldSetEntity.setValue("actual_start_time",f1w08);
        //actual_end_time    实际结束时间
        fieldSetEntity.setValue("actual_end_time",fse.getString("f1w09"));
        //applicant    申请人
        String user_id = this.userIdJson.getString(fse.getString("f1w01"));
        //找不到员工直接退出
        if(BaseUtil.strIsNull(user_id)){
            return;
        }
        FieldSetEntity staff = (FieldSetEntity)this.userIdStaffFse.get(user_id);
        fieldSetEntity.setValue("applicant",user_id);
        //applicat_time 申请时间
        fieldSetEntity.setValue("applicat_time",f1w08);
        //atual_time 实际用时
        fieldSetEntity.setValue("applicat_time",fse.getString("day"));
        //created_by    创建者,lx_sys_users表user_id
        String f1w04 = this.userIdJson.getString(fse.getString("f1w04"));
        if(BaseUtil.strIsNull(f1w04)){
            f1w04 = user_id;
        }
        fieldSetEntity.setValue("created_by",f1w04);
        //created_utc_datetime    创建时间
        fieldSetEntity.setValue("created_utc_datetime",f1w08);
        //dept_uuid    部门
        String dept = fse.getString("f1w11");
        String dept_uuid = this.groupJson.getString(dept);
        if(BaseUtil.strIsNull(dept_uuid)){
            dept_uuid  = staff.getString("dept_uuid");
        }
        fieldSetEntity.setValue("dept_uuid",dept_uuid);
        //flow_flag    流程送办默认字段,0-待发,1-在办,2-办结
        fieldSetEntity.setValue("flow_flag",fse.getString("f1w02"));
        //org_level_uuid    组织机构,lx_sys_org_levels表uuid
        String org_level_uuid = this.orgLevelJson.getString(dept);
        if(BaseUtil.strIsNull(org_level_uuid)){
            org_level_uuid  = staff.getString("org_level_uuid");
        }
        fieldSetEntity.setValue("org_level_uuid",org_level_uuid);
        fieldSetEntity.setValue("reason",fse.getString("f1w06"));
        fieldSetEntity.setValue("out_type", out_type);
        try{
            baseDao.add(fieldSetEntity);
        }catch (BaseException e){
            e.printStackTrace();
        }
    }
    /**
     * 同步考勤数据
     * @param clockDt 外出data数据
     */
    private void synchronousClock(DataTableEntity clockDt) throws SQLException {
        //同步考勤数据
        if(!BaseUtil.dataTableIsEmpty(clockDt)){
            DataTableEntity dataTableEntity = new DataTableEntity();
            FieldMetaEntity f = new FieldMetaEntity();
            f.setTableName(new String[]{"product_oa_punch_record"});
            dataTableEntity.setMeta(f);
            for (int i = 0; i < clockDt.getRows(); i++) {
                FieldSetEntity fse = clockDt.getFieldSetEntity(i);
                FieldSetEntity fieldSetEntity = new FieldSetEntity();
                fieldSetEntity.setTableName("product_oa_punch_record");
                //部门id
                String dept = fse.getString("dept");
                fieldSetEntity.setValue("dept_uuid",this.groupJson.getString(dept));
                String org_level_uuid = this.orgLevelJson.getString(dept);
                if(BaseUtil.strIsNull(org_level_uuid)){
                    org_level_uuid = this.groupJson.getString(dept);
                }
                //公司uuid
                fieldSetEntity.setValue("org_level_uuid", org_level_uuid);
                //上午上班打卡时间
                String swdksj = fse.getString("swdksj");
                fieldSetEntity.setValue("punch_time_one",swdksj);
                //默认上午下班打卡时间
                if(!BaseUtil.strIsNull(swdksj)) {
                    String defaultTime = swdksj.substring(0, 11) + "12:00:00";
                    fieldSetEntity.setValue("punch_time_three", defaultTime);
                }
                //上班考勤结果
                fieldSetEntity.setValue("time_one_result",fse.getString("swkqjg"));
                //上午mac地址
                fieldSetEntity.setValue("mac_one",fse.getString("mac"));
                //下午上班打卡时间
                String xwdksj = fse.getString("xwdksj");
                fieldSetEntity.setValue("punch_time_three",xwdksj);
                //默认下午下班打卡时间
                if(!BaseUtil.strIsNull(xwdksj)) {
                    String defaultTime = xwdksj.substring(0, 11) + "18:00:00";
                    fieldSetEntity.setValue("punch_time_four", defaultTime);
                }
                //下午mac1地址
                fieldSetEntity.setValue("mac_two", fse.getString("mac1"));
                //姓名
                String userId = userIdJson.getString(fse.getString("name"));
                if(BaseUtil.strIsNull(userId)){
                    continue;
                }
                fieldSetEntity.setValue("created_by", userId);
                //姓名
                fieldSetEntity.setValue("created_utc_datetime", fse.getString("time01"));
 
                //上班考勤结果
                fieldSetEntity.setValue("time_one_result",fse.getString("swkqjg"));
//                String swkqjg = fse.getString("swkqjg");
                //下班考勤结果
                fieldSetEntity.setValue("time_four_result",fse.getString("xwkqjg"));
//                String xwkqjg = fse.getString("xwkqjg");
                dataTableEntity.addFieldSetEntity(fieldSetEntity);
                if(dataTableEntity.getRows() == 1000){
                    baseDao.add(dataTableEntity);
                    dataTableEntity = new DataTableEntity();
                    dataTableEntity.setMeta(f);
                }
                //请休假放到请假表里面
//                switch (xwkqjg){
//                        //正常
//                    case "0":
//                        //迟到
//                    case "1":
//                        //缺勤
//                    case "2":
//                        break;
//                        //出差 出差表
//                    case "10":
//                        break;
//                        //外出开会 外出表
//                    case "11":
//                        //外勤 外出表
//                    case "12":
//                        break;
//                        //调休 请假表
//                    case "13":
//                        //休假
//                    case "14":
//                        //病假
//                    case "15":
//                        //事假
//                    case "16":
//                        //请假
//                    case "3":
//                        //婚假
//                    case "4":
//                        //产假
//                    case "5":
//                        break;
//                }
            }
            if(!BaseUtil.dataTableIsEmpty(dataTableEntity)) {
                baseDao.add(dataTableEntity);
            }
        }
    }
 
    /**
     * 会议室同步
     *
     * @param conn
     * @param tableName
     */
    private Map<String, String> meetingRoomSync(Connection conn, String tableName) throws SQLException {
        //判断是否是已经同步过的表
        DataTableEntity dataTable = baseDao.listTable("product_oa_conference_room_config");
        Map<String, String> map = Maps.newHashMap();
        if (!BaseUtil.dataTableIsEmpty(dataTable)) {
            return map;
        }
        DataTableEntity meetingRoomDt = null;
        try {
            meetingRoomDt = BaseDaoServiceImpl.getDataTable(conn, tableName, "", new Object[]{});
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            throw e;
        }
        if(!BaseUtil.dataTableIsEmpty(meetingRoomDt)) {
            for (int i = 0; i < meetingRoomDt.getRows(); i++) {
                FieldSetEntity fse = meetingRoomDt.getFieldSetEntity(i);
                FieldSetEntity fieldSet = new FieldSetEntity();
                fieldSet.setTableName("product_oa_conference_room_config");
                //ADDRESS 地址
                fieldSet.setValue("address",fse.getString("address"));
                String recorded_man = userIdJson.getString(fse.getString("recorded_man"));
                if(BaseUtil.strIsNull(recorded_man)){
                    continue;
                }
                //ADMIN    管理员                manager_user 管理员
                String admin = userIdJson.getString(fse.getString("admin"));
                if(BaseUtil.strIsNull(admin)){
                    admin = recorded_man;
                }
                fieldSet.setValue("manager_user", admin);
                //APPLY_TIME_LIMIT    会议室申请时间限制 没有字段
                fse.getString("apply_time_limit");
                //ENABLED_TIME    启用时间
                String enabled_time = fse.getString("enabled_time");
                fieldSet.setValue("available_start_time",enabled_time);
                //启用时间
                fieldSet.setValue("enabled_time",enabled_time);
                //EQUIPMENT    配置信息
                fieldSet.setValue("equipment",fse.getString("equipment"));
                //ID    顺序号                id 主键
                String id = fse.getString("id");
                fieldSet.setValue("id",id);
                //RECORDED_DATE    录入时间    创建时间
                fieldSet.setValue("created_utc_datetime",fse.getString("recorded_date"));
                //RECORDED_MAN    录入人 created_by 创建人
                fieldSet.setValue("created_by",recorded_man);
                //REMARK    备注  remark 备注
                fieldSet.setValue("remark",fse.getString("remark"));
                //ROOMNAME    会议室名                 room_name 会议室名称
                fieldSet.setValue("room_name",fse.getString("roomname"));
                //SEATS    座位数
                fieldSet.setValue("seats",fse.getString("seats"));
                //STATUS    会议室状态
                int statusNum = 0;
                if("启用".equals(fse.getString("status"))){
                    statusNum = 1;
                }
                fieldSet.setValue("status",statusNum);
                FieldSetEntity staff = (FieldSetEntity)userIdStaffFse.get(recorded_man);
                //org_level_uuid 所属公司
                fieldSet.setValue("org_level_uuid", staff.getString("org_level_uuid"));
                //available_end_time 启用结束时间
                String uuid = baseDao.add(fieldSet);
                map.put(id,uuid);
 
            }
        }
        return map;
    }
 
    /**
     * 会议同步
     *
     * @param conn
     * @param tableName
     */
    private void meetingSynchronous(Connection conn, String tableName, Map<String, String> map) throws SQLException {
        //判断是否是已经同步过的表
        DataTableEntity dataTable = baseDao.listTable("product_oa_conference_apply");
        if (!BaseUtil.dataTableIsEmpty(dataTable)) {
            return;
        }
        DataTableEntity meetingDt = null;
        try {
            meetingDt = BaseDaoServiceImpl.getDataTable(conn, tableName, "", new Object[]{});
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            throw e;
        }
 
        Map<String, Integer> meetintTypeMap = Maps.newHashMap();
        meetintTypeMap.put("周例会", 1);
        meetintTypeMap.put("协调会", 2);
        meetintTypeMap.put("座谈会", 3);
        meetintTypeMap.put("培训", 4);
        meetintTypeMap.put("例会", 5);
        meetintTypeMap.put("研讨会", 6);
        meetintTypeMap.put("沟通会", 7);
        meetintTypeMap.put("局务会", 8);
        meetintTypeMap.put("征求意见会", 9);
        meetintTypeMap.put("工作洽谈会", 10);
        meetintTypeMap.put("项目对接会", 11);
        meetintTypeMap.put("拆迁纠纷协调会", 12);
        meetintTypeMap.put("讨论", 13);
        meetintTypeMap.put("物业管理", 14);
        meetintTypeMap.put("省对市考核", 15);
        meetintTypeMap.put("安排工作", 16);
        meetintTypeMap.put("创城半年督查", 17);
        meetintTypeMap.put("与郑州市征收办工作交流座谈", 18);
        meetintTypeMap.put("信访工作会议", 19);
        meetintTypeMap.put("业务讨论", 20);
        meetintTypeMap.put("前期物业招投标", 21);
        meetintTypeMap.put("会议、学习", 22);
        meetintTypeMap.put("交办会", 23);
        meetintTypeMap.put("审计汇总", 24);
        meetintTypeMap.put("物业企业星级服务座谈会", 25);
 
        if(!BaseUtil.dataTableIsEmpty(meetingDt)){
            DataTableEntity dataTableEntity = new DataTableEntity();
            FieldMetaEntity f = new FieldMetaEntity();
            f.setTableName(new String[]{"product_oa_conference_apply"});
            dataTableEntity.setMeta(f);
            for (int i = 0; i < meetingDt.getRows(); i++) {
              FieldSetEntity fse = meetingDt.getFieldSetEntity(i);
              FieldSetEntity applyFse = new FieldSetEntity();
                applyFse.setTableName("product_oa_conference_apply");
                //附件
                String annex = fse.getString("annex");
                //如果附件字段有值  同步附件
                if(!BaseUtil.strIsNull(annex)){
                    List<String> fileUuids = this.synchronizeCommonAccessories(conn, "attachment", "product_oa_conference_apply", annex);
                    //存入附件uuid
                    applyFse.setValue("attachment", StringUtils.join(fileUuids, ","));
                }
                //participator    参加者
                String attendee = fse.getString("attendee");
                applyFse.setValue("participator",this.getUserIds(conn, attendee));
                //会议简要 会议纪要
                applyFse.setValue("meeting_minutes", fse.getString("cotent"));
                //结束时间       结束时间
                applyFse.setValue("end_time", fse.getString("end_date"));
                //送审标志      流程送办默认字段,0-待发,1-在办,2-办结
                applyFse.setValue("flow_flag", fse.getString("flag"));
                //顺序号 id    主键
                String id = fse.getString("id");
                applyFse.setValue("id",id);
                //创建人
                String userId = userIdJson.getString(fse.getString("recorded_man"));
                if(BaseUtil.strIsNull(userId)){
                    continue;
                }
                //所属部门 暂无字段 取当前人部门
                FieldSetEntity staff = (FieldSetEntity)this.userIdStaffFse.get(userId);
                String id01 = fse.getString("id01");
                String dept_uuid  = groupJson.getString(id01);
                if(BaseUtil.strIsNull(dept_uuid)){
                    dept_uuid = staff.getString("dept_uuid");
                }
                //部门uuid
                applyFse.setValue("dept_uuid", dept_uuid);
                //申请人      创建人
                applyFse.setValue("created_by", userId);
                //外来参会人员 暂无字段
                applyFse.setValue("exotic_staff", fse.getString("id03"));
                //申请人id02
                applyFse.setValue("apply_user", userIdJson.getString(fse.getString("id02")));
                //主持人 record_master 主持人
                applyFse.setValue("record_master", userIdJson.getString(fse.getString("meeting_master")));
                //会议室
                applyFse.setValue("meeting_room",map.get(fse.getString("meeting_room")));
                //会议类型 暂无字段 组合为参照
                applyFse.setValue("meetint_type", meetintTypeMap.get(fse.getString("meetint_type")));
                //录入时间 created_utc_datetime    创建时间
                applyFse.setValue("created_utc_datetime", fse.getString("recorded_date"));
                //会议记录人 记录人
                applyFse.setValue("record_man",userIdJson.getString(fse.getString("record_man")));
                //提醒时间  reminder_time    提醒时间
                applyFse.setValue("reminder_time", fse.getString("remind_time"));
                //需要资源
                applyFse.setValue("meeting_resource", fse.getString("res"));
                //开始时间
                applyFse.setValue("start_time", fse.getString("start_date"));
                //会议状态 0、待发 1、已发
                applyFse.setValue("status",fse.getString("status"));
                //会议主题
                applyFse.setValue("meeting_topic",fse.getString("topics"));
                //所属公司
                applyFse.setValue("org_level_uuid",staff.getString("org_level_uuid"));
                String uuid = baseDao.add(applyFse);
                pxMap.put("BS_MEETING_FLOW"+id,uuid);
            }
 
        }
    }
 
 
 
    //同步协同办公
    private void syncCcooperates(Connection conn, String tableName) throws SQLException {
        //判断是否是已经同步过的表
        DataTableEntity dataTable = baseDao.listTable("product_oa_cooperates");
        if (!BaseUtil.dataTableIsEmpty(dataTable)) {
            return;
        }
        DataTableEntity ccooperatesDt = null;
        try {
            ccooperatesDt = BaseDaoServiceImpl.getDataTable(conn, " SELECT  A.*,(SELECT COUNT(*) FROM FE_BASE5.SYS_ATTACHMENT WHERE SA01 = A.RELATIONFLOW) AS FLOWS FROM FE_BASE5.SYS_COLLABORATIVE A ", new Object[]{});
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            throw e;
        }
        DataTableEntity accessoryData = this.getTableNameAttachment(conn, tableName);
        try {
            //获取扩展消息
            DataTableEntity ideamanageDt = BaseDaoServiceImpl.getDataTable(conn, "SELECT * FROM FE_BASE5.IDEAMANAGE ORDER BY ID06", new Object[]{});
            Map<String, DataTableEntity> dataMap = Maps.newHashMap();
            for (int i = 0; i < ideamanageDt.getRows(); i++) {
                FieldSetEntity fse = ideamanageDt.getFieldSetEntity(i);
                String id06 = fse.getString("id06");
                DataTableEntity dataTableEntity1 = dataMap.get(id06);
                if(BaseUtil.dataTableIsEmpty(dataTableEntity1)){
                    DataTableEntity dataTableEntity2 = new DataTableEntity();
                    dataTableEntity2.addFieldSetEntity(fse);
                    dataMap.put(id06, dataTableEntity2);
                }else {
                    dataTableEntity1.addFieldSetEntity(fse);
                }
            }
            Map<String, FieldSetEntity> ccooperatesMaps = Maps.newHashMap();
            for (int i = 0; i < ccooperatesDt.getRows(); i++) {
            FieldSetEntity feFs = ccooperatesDt.getFieldSetEntity(i);
            FieldSetEntity fs = new FieldSetEntity();
            fs.setTableName("product_oa_cooperates");
            //标题
            fs.setValue("title", feFs.getString("title"));
            String content = feFs.getString("content");
            if (BaseUtil.strIsNull(content)) {
                content = "";
            }
            //内容
            fs.setValue("content", content);
            String important = feFs.getString("important");
            if (!BaseUtil.strIsNull(important)) {
                //紧急程度(1.平件、2.急件、3.特急、4.特提)
                fs.setValue("emergency_degree", this.emergencyDegreeType(important));
            } else {
                //为空就放0
                fs.setValue("emergency_degree", 1);
            }
            //附件hiddenidea
            // fs.setValue("attachment",);
            //发起时间
            String stime = feFs.getString("stime");
            fs.setValue("start_time", feFs.getString("stime"));
            //是否允许转发(1.是、0.否)
            fs.setValue("is_forward", feFs.getString("repeating"));
            //是否允许加签(1.是、0.否)
            fs.setValue("is_countersign", feFs.getString("modifyflow"));
            //是否允许跟踪(1.是、0.否)
            fs.setValue("is_track", feFs.getString("track"));
            //是否隐藏回复意见(1.是、0.否)
            fs.setValue("is_hide_comments", feFs.getString("hiddenidea"));
            //状态(0.待发、1.已发)
             Integer spflag = feFs.getInteger("spflag");
            fs.setValue("status", (spflag == 0)?0:1);
            String sman = this.userIdJson.getString(feFs.getString("sman"));
            if(BaseUtil.strIsNull(sman)){
                continue;
            }
            //是否允许转邮件
            fs.setValue("is_transfer_mail", 0);
            fs.setValue("created_by",sman);
            fs.setValue("created_utc_datetime", stime);
            Map<String, List<String>> fileMaps = this.synchronizationAttachments(conn, accessoryData, feFs, fs.getTableName(), "attachment");
            List<String> value = fileMaps.get("attachment");
            //存入附件uuid
            fs.setValue("attachment", StringUtils.join(value, ","));
            String uuid = baseDao.add(fs);
            //保存业务数据id 与本表uuid
            String id = feFs.getString("id");
            pxMap.put("SYS_COLLABORATIVE" + id, uuid);
            ccooperatesMaps.put(id,fs);
            //同步正文补充
            this.synchronizeTextSupplement(conn, id, uuid);
            String flowcode  = feFs.getString("flowcode");
            if(BaseUtil.strIsNull(flowcode)) {
                //虚拟一个节点
                FieldSetEntity subfse = new FieldSetEntity();
                //源表名
                subfse.setTableName("product_oa_cooperate_flow_node");
                //办理人层级
                subfse.setValue("grade", 1);
                //关联协同表uuid
                subfse.setValue("cooperate_uuid", uuid);
                //接收人Id
                subfse.setValue("receiver", sman);
                //接收人姓名
                FieldSetEntity staffFse = (FieldSetEntity)userIdStaffFse.get(sman);
                String show_name = staffFse.getString("show_name");
                subfse.setValue("receiver_name",show_name);
                //0:暂存 1:加签 2:转发 3:退回4:送办 5:终止 6:撤销
                subfse.setValue("type", 0);
                subfse.setValue("sender", sman);
                subfse.setValue("sender_name", null);
                subfse.setValue("tricode",null);
                baseDao.add(subfse);
                //虚拟一个节点
                FieldSetEntity subfse2 = new FieldSetEntity();
                //源表名
                subfse2.setTableName("product_oa_cooperate_flow_node");
                //办理人层级
                subfse2.setValue("grade", 2);
                //关联协同表uuid
                subfse2.setValue("cooperate_uuid", uuid);
                //接收人Id
                subfse2.setValue("receiver", sman);
                //接收人姓名
                subfse2.setValue("receiver_name", show_name);
                //0:暂存 1:加签 2:转发 3:退回4:送办 5:终止 6:撤销
                subfse2.setValue("type", 0);
                subfse2.setValue("sender", sman);
                subfse2.setValue("sender_name", show_name);
                subfse2.setValue("tricode",sman);
                baseDao.add(subfse2);
                continue;
            }
            //同步协同流程
            this.synchronousCooperator(conn, flowcode, uuid);
            //同步infor
            DataTableEntity ccooperatesInforDt = null;
            ccooperatesInforDt = BaseDaoServiceImpl.getDataTable(conn, "SELECT * FROM FE_BASE5.WF_INFOR WHERE WI29 = ? AND WI28 = 'SYS_COLLABORATIVE' ORDER BY WI00",  new Object[]{id});
            Map<String, String[]> stateMap = this.syncCcooperatesInforDt(conn, ccooperatesInforDt, uuid, dataMap);
            //同步消息
                if(stateMap != null && stateMap.size() > 0){
                    this.syncCollaborativeNews(conn, id, stateMap);
                }
            }
            //同步关联事项  修改协同数据
            //获取关联事项的协同
            DataTableEntity relevanceTask = BaseDaoServiceImpl.getDataTable(conn, "SELECT * FROM FE_BASE5.WF_TASK WHERE WT03 = 'SYS_COLLABORATIVE'", new Object[]{});
            Map<String, FieldSetEntity> task_maps = Maps.newHashMap();
            for (int i = 0; i < relevanceTask.getRows(); i++) {
                task_maps.put(relevanceTask.getString(i, "wt00"), relevanceTask.getFieldSetEntity(i));
            }
            //获取已同步流程task的关联事项
            DataTableEntity flow_task = baseDao.listTable("select * from product_sys_flow_task", new String[]{});
            Map<String, FieldSetEntity> flow_task_maps = Maps.newHashMap();
            for (int i = 0; i < flow_task.getRows(); i++) {
                //k为原 taskId
                flow_task_maps.put(flow_task.getString(i, "id"), flow_task.getFieldSetEntity(i));
            }
            for (int i = 0; i < ccooperatesDt.getRows(); i++) {
                Integer flows = ccooperatesDt.getInt(i,"flows");
                //有关联事项
                if (flows > 0) {
                    String relationflow = ccooperatesDt.getString(i,"relationflow");
                    String id = ccooperatesDt.getString(i,"id");
                    DataTableEntity relationflowData = BaseDaoServiceImpl.getDataTable(conn, "SELECT * FROM FE_BASE5.SYS_ATTACHMENT WHERE SA01 = ?", new Object[]{relationflow});
                    JSONArray relationJson = new JSONArray();
                    if (!BaseUtil.dataTableIsEmpty(relationflowData)) {
                        for (int j = 0; j < relationflowData.getRows(); j++) {
                            String sa02 = relationflowData.getString(j, "sa02");
                            //本库流程task数据
                            FieldSetEntity fse = flow_task_maps.get(sa02);
                            if(fse != null){
                                JSONObject relationObject = new JSONObject();
                                String uuid = fse.getUUID();
                                String title = fse.getString("title");
                                relationObject.put("type", 0);
                                relationObject.put("uuid", uuid);
                                relationObject.put("label", title);
                                relationJson.add(relationObject);
                            }
                            //协同源数据
                            FieldSetEntity fse2 = task_maps.get(sa02);
                            if(fse2 != null){
                                JSONObject relationObject = new JSONObject();
                                String wt04 = fse2.getString("wt04");
                                FieldSetEntity fieldSetEntity = ccooperatesMaps.get(wt04);
                                if(fieldSetEntity != null){
                                    String uuid = fieldSetEntity.getUUID();
                                    String title = fieldSetEntity.getString("title");
                                    relationObject.put("type", 1);
                                    relationObject.put("uuid", uuid);
                                    relationObject.put("label", title);
                                    relationJson.add(relationObject);
                                }
                            }
                        }
                        if(relationJson.size() > 0){
                            FieldSetEntity updateFse = ccooperatesMaps.get(id);
                            if(updateFse != null){
                                updateFse.setValue("related_items", relationJson.toString());
                                baseDao.update(updateFse);
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            e.getStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
        }
    }
 
    /**
     * 同步协同正文补充
     */
    public void synchronizeTextSupplement(Connection conn,String id, String cooperate_uuid)throws Exception{
        try {
            DataTableEntity dataTable = BaseDaoServiceImpl.getDataTable(conn, "SELECT * FROM FE_BASE5.WF_DOC_ADDITIONAL WHERE WDA05 = (SELECT WT00 FROM FE_BASE5.WF_TASK WHERE WT04 = ? AND WT03 = 'SYS_COLLABORATIVE')",  new Object[]{id});
            DataTableEntity cooperate_sub = new DataTableEntity();
            FieldMetaEntity f = new FieldMetaEntity();
            f.setTableName(new String[]{"product_oa_cooperate_sub"});
            cooperate_sub.setMeta(f);
            if(!BaseUtil.dataTableIsEmpty(dataTable)){
                DataTableEntity accessoryData = this.getTableNameAttachment(conn, "FE_BASE5.WF_DOC_ADDITIONAL");
                for (int i = 0; i < dataTable.getRows(); i++) {
                  FieldSetEntity fse = dataTable.getFieldSetEntity(i);
                  FieldSetEntity fieldSetEntity = new FieldSetEntity();
                    fieldSetEntity.setTableName("product_oa_cooperate_sub");
                    //内容
                    String wda02 = fse.getString("wda02");
                    if(BaseUtil.strIsNull(wda02)){
                        wda02 = "空";
                    }
                    fieldSetEntity.setValue("contents", wda02);
//                    attachment    附件
                    Map<String, List<String>> fileMaps = this.synchronizationAttachments(conn, accessoryData, fse, fieldSetEntity.getTableName(), "attachment");
                    List<String> value = fileMaps.get("attachment");
                    //存入附件uuid
                    fieldSetEntity.setValue("attachment", StringUtils.join(value, ","));
                    //主表uuid
                    fieldSetEntity.setValue("cooperate_uuid", cooperate_uuid);
                    String user_id = userIdJson.getString(fse.getString("wda01"));
                    if(BaseUtil.strIsNull(user_id)){
                        continue;
                    }
                    //创建人
                    fieldSetEntity.setValue("created_by",user_id);
                    //创建时间
                    fieldSetEntity.setValue("created_utc_datetime", fse.getString("wda04"));
                    cooperate_sub.addFieldSetEntity(fieldSetEntity);
                }
                baseDao.add(cooperate_sub);
            }
        } catch (Exception e) {
                DataManipulationUtils.close(null, null, conn);
                e.getStackTrace();
                SpringMVCContextHolder.getSystemLogger().error(e);
        }
    }
 
    /**
     * 同步协同模板
     */
    public void syncCollaborativeTemplate(Connection conn) throws SQLException {
        try {
            DataTableEntity dataTable = BaseDaoServiceImpl.getDataTable(conn, "SELECT * FROM FE_BASE5.SYS_COLLABORATIVE_MOUDLE  WHERE COL_MDL_CONTENT_TYPE = 0", new Object[]{});
            if(!BaseUtil.dataTableIsEmpty(dataTable)){
                for (int i = 0; i < dataTable.getRows(); i++) {
                  FieldSetEntity fse = dataTable.getFieldSetEntity(i);
                  FieldSetEntity newFse = new FieldSetEntity();
                    newFse.setTableName("product_oa_cooperates_template");
                    //模板名称 也为协同名称
                    newFse.setValue("name",fse.getString("col_mdl_name"));
                    //创建人
                    String col_mdl_userid = fse.getString("col_mdl_userid");
                    String user_id = "";
                    //创建时间
                    String created_time = fse.getString("col_mdl_time");
                    //公共模板
                    if("1".equals(col_mdl_userid)){
                        newFse.setValue(CmnConst.CREATED_BY,1);
                        //创建时间
                        newFse.setValue(CmnConst.CREATED_UTC_DATETIME,created_time);
                        //模板html内容
                        newFse.setValue("content",fse.getString("col_mdl_content"));
                        baseDao.add(newFse);
                    }else {
                         user_id = userIdJson.getString(col_mdl_userid);
                        if(BaseUtil.strIsNull(user_id)){
                            continue;
                        }
                        newFse.setValue(CmnConst.CREATED_BY,user_id);
                        newFse.setValue(CmnConst.CREATED_UTC_DATETIME,created_time);
                        //模板html内容
                        newFse.setValue("content",fse.getString("col_mdl_content"));
                        //共享人员1 部门2 岗位3
                        String col_mdl_sharers = fse.getString("col_mdl_sharers");
                            if(!BaseUtil.strIsNull(col_mdl_sharers)){
                                Set<String> userSet = Sets.newHashSet();
                                String[] sharers = col_mdl_sharers.split(",");
                                for (int j = 0; j < sharers.length; j++) {
                                  String srt = sharers[j];
                                //人员
                                if(srt.contains("^_^1^_^")){
                                    String userId = srt.substring(0,srt.indexOf("^_^1^_^"));
                                    userId = userIdJson.getString(userId);
                                    if(!BaseUtil.strIsNull(userId)){
                                        userSet.add(userId);
                                    }
                                    //部门单位
                                }else if(srt.contains("^_^2^_^")){
                                    String levelId = srt.substring(0,srt.indexOf("^_^2^_^"));
                                    String deptUuid = groupJson.getString(levelId);
                                    DataTableEntity staffData = null;
                                    if(BaseUtil.strIsNull(deptUuid)){
                                        deptUuid = orgLevelJson.getString(levelId);
                                        if(!BaseUtil.strIsNull(deptUuid)){
                                            staffData = baseDao.listTable(CmnConst.PRODUCT_SYS_STAFFS, " org_level_uuid = ? ", new String[]{deptUuid});
                                        }
                                    }else {
                                        staffData = baseDao.listTable(CmnConst.PRODUCT_SYS_STAFFS, " dept_uuid = ? or org_level_uuid = ? ", new String[]{deptUuid,deptUuid});
                                    }
                                    if(!BaseUtil.dataTableIsEmpty(staffData)){
                                        for (int k = 0; k < staffData.getRows(); k++) {
                                            userSet.add(staffData.getString(k, "user_id"));
                                        }
                                    }
                                    //岗位
                                }else if(srt.contains("^_^3^_^")){
                                    String postId = srt.substring(0,srt.indexOf("_|"));
                                    String postUuid = postJson.getString(postId);
                                   DataTableEntity staffData = baseDao.listTable(CmnConst.PRODUCT_SYS_STAFFS, " job_post_uuid = ? ", new String[]{postUuid});
                                    if(!BaseUtil.dataTableIsEmpty(staffData)){
                                        for (int k = 0; k < staffData.getRows(); k++) {
                                            userSet.add(staffData.getString(k, "user_id"));
                                        }
                                    }
                                }
                            }
                            if(userSet.size() > 0) {
                                //解析并存入用户
                                newFse.setValue("share_user",StringUtils.join(userSet, ","));
                            }
                        }
                        String uuid = baseDao.add(newFse);
                        //关联流程code
                        String col_mdl_flowcode = fse.getString("col_mdl_flowcode");
                        FieldSetEntity staffFse = (FieldSetEntity)userIdStaffFse.get(user_id);
                        String org_level_uuid = staffFse.getString("org_level_uuid");
                        if(!BaseUtil.strIsNull(col_mdl_flowcode) && !BaseUtil.strIsNull(org_level_uuid)){
                            //同步协同模板流程
                            this.synchronousTemplateCooperator(conn, col_mdl_flowcode, uuid, user_id, created_time, org_level_uuid);
                        }
                    }
 
                }
            }
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            e.getStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
        }
    }
 
    /**
     * 同步协同模板人员 岗位 机构
     * @param conn jdbc连接
     * @param flowCode 流程节点标识
     * @param uuid 协同uuid
     * @return
     */
    public DataTableEntity synchronousTemplateCooperator(Connection conn, String flowCode, String uuid, String user_id, String created_time, String org_level_uuid) throws SQLException {
        DataTableEntity coNodeData = null;
        try {
            //flowcode 流程标识字段
            coNodeData = BaseDaoServiceImpl.getDataTable(conn, "SELECT * FROM FE_BASE5.WF_CO_NODE WHERE MGUID = ? ORDER BY CREATETIME",  new Object[]{flowCode});
 
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            throw e;
        }
        if(!BaseUtil.dataTableIsEmpty(coNodeData)) {
            FieldSetEntity fieldSetEntity = coNodeData.getFieldSetEntity(0);
            coNodeData.removeFieldSetEntity(0);
            DataTableEntity dataTable = new DataTableEntity();
            FieldMetaEntity f = new FieldMetaEntity();
            f.setTableName(new String[]{"product_oa_cooperate_flow_node_template"});
            dataTable.setMeta(f);
            String userId = userIdJson.getString(fieldSetEntity.getString("value"));
            if (BaseUtil.strIsNull(userId)) {
                return null;
            }
            FieldSetEntity subfse = new FieldSetEntity();
            //源表名
            subfse.setTableName("product_oa_cooperate_flow_node_template");
            //办理人层级
            subfse.setValue("grade", 1);
            //关联协同模板表uuid
            subfse.setValue("master_uuid", uuid);
            //接收人Id
            subfse.setValue("receiver", userId);
            subfse.setValue("sender", null);
            subfse.setValue("tricode",null);
            subfse.setValue("org_level_uuid", org_level_uuid);
            subfse.setValue(CmnConst.CREATED_BY, user_id);
            subfse.setValue(CmnConst.CREATED_UTC_DATETIME, created_time);
            dataTable.addFieldSetEntity(subfse);
            try {
                this.saveTemplateReceiver(fieldSetEntity, coNodeData, uuid, null, dataTable,2,user_id, created_time, org_level_uuid);
                baseDao.add(dataTable);
            }catch (Exception e){
                e.printStackTrace();
            }
            return dataTable;
        }
        return null;
    }
 
    /**
     * 递归循环同步模板人员 部门岗位 数据
     * @param fse 发送人fse
     * @param dataTableEntity 剩余人Data
     */
    private void saveTemplateReceiver(FieldSetEntity fse, DataTableEntity dataTableEntity, String uuid,String tricode, DataTableEntity dataTable, Integer grade,String user_id, String created_time, String org_level_uuid)throws Exception{
        DataTableEntity dataTableEntity1 = new DataTableEntity();
        DataTableEntity dataTableEntity2 = new DataTableEntity();
        String sender = "";
        //发送类型
        String type2 = fse.getString("type");
        if("1".equals(type2)){
            sender = userIdJson.getString(fse.getString("value"));
            if(BaseUtil.strIsNull(sender)){
                return;
            }
        }
        for (int i = 0; i < dataTableEntity.getRows(); i++) {
            FieldSetEntity fieldSetEntity = dataTableEntity.getFieldSetEntity(i);
            String guid = fse.getString("guid");
            String parentguid = fieldSetEntity.getString("parentguid");
            if(guid.equals(parentguid)){
                dataTableEntity1.addFieldSetEntity(fieldSetEntity);
                FieldSetEntity subfs = new FieldSetEntity();
                //协同办公流程表
                subfs.setTableName("product_oa_cooperate_flow_node_template");
                subfs.setValue("grade", grade);
                //关联协同表uuid
                subfs.setValue("master_uuid", uuid);
                //接收人(关联用户表id)  接收人一但是机构或部门节点   那就是最后节点
                String type = fieldSetEntity.getString("type");
                //发送人id
                subfs.setValue("sender", sender);
                //人员
                if("1".equals(type)){
                    String userId = userIdJson.getString(fieldSetEntity.getString("value"));
                    if(BaseUtil.strIsNull(userId)){
                        continue;
                    }
                    subfs.setValue("receiver", userId);
                    //若为部门公司
                }else if("2".equals(type)){
                    String orgUuid = orgLevelJson.getString(fieldSetEntity.getString("value"));
                    if(BaseUtil.strIsNull(orgUuid)){
                        continue;
                    }
                    if(!BaseUtil.strIsNull(orgUuid)){
                        DataTableEntity staff = baseDao.listTable(" product_sys_staffs ", " dept_uuid = ? ", new String[]{orgUuid});
                        if(BaseUtil.dataTableIsEmpty(staff)){
                            staff = baseDao.listTable(" product_sys_staffs ", " org_level_uuid = ? ", new String[]{orgUuid});
                        }
                        if(!BaseUtil.dataTableIsEmpty(staff)) {
                            tricode = dataTable.getString(dataTable.getRows()-1, "tricode");
                            if(BaseUtil.strIsNull(tricode)){
                                tricode = dataTable.getString(dataTable.getRows()-1, "receiver");
                            }
                            this.addUserTemplateFlowNode(staff, grade, uuid, tricode,sender,dataTable,user_id,created_time, org_level_uuid);
                        }
                        continue;
                    }
                    //岗位
                }else if("3".equals(type)){
                    String postUuid = postJson.getString(fieldSetEntity.getString("value"));
                    if(BaseUtil.strIsNull(postUuid)){
                        continue;
                    }
                    if(!BaseUtil.strIsNull(postUuid)){
                        DataTableEntity staff = baseDao.listTable(" product_sys_staffs ", " job_post_uuid = ? ", new String[]{postUuid});
                        if(!BaseUtil.dataTableIsEmpty(staff)) {
                            tricode = dataTable.getString(dataTable.getRows()-1, "tricode");
                            if(BaseUtil.strIsNull(tricode)){
                                tricode = dataTable.getString(dataTable.getRows()-1, "receiver");
                            }
                            this.addUserTemplateFlowNode(staff, grade, uuid,  tricode,sender,dataTable,user_id,created_time, org_level_uuid);
                        }
                        continue;
                    }
                }
                //triCode
                if(BaseUtil.strIsNull(tricode)){
                    subfs.setValue("tricode",sender);
                    fieldSetEntity.setValue("tricode",sender);
                }else {
                    subfs.setValue("tricode",tricode + "-" + sender);
                    fieldSetEntity.setValue("tricode",tricode + "-" + sender);
                }
 
                //公司uuid
                subfs.setValue("org_level_uuid", org_level_uuid);
                //创建人
                subfs.setValue(CmnConst.CREATED_BY, user_id);
                //创建时间
                subfs.setValue(CmnConst.CREATED_UTC_DATETIME, created_time);
                dataTable.addFieldSetEntity(subfs);
            }else {
                dataTableEntity2.addFieldSetEntity(fieldSetEntity);
            }
        }
 
        //办理人层级
        grade++;
        if(!BaseUtil.dataTableIsEmpty(dataTableEntity1) && !BaseUtil.dataTableIsEmpty(dataTableEntity2)) {
            for (int i = 0; i < dataTableEntity1.getRows(); i++) {
                this.saveTemplateReceiver(dataTableEntity1.getFieldSetEntity(i) ,dataTableEntity2, uuid, dataTableEntity1.getString(i, "tricode"),dataTable,grade, user_id, created_time, org_level_uuid);
            }
        }
    }
 
    /**
     * 解析同步的岗位部门 解析为人再批量保存
     * @param staff 通过部门岗位  查询出来的用户数据
     * @param grade 层级
     * @param uuid 主表uuid
     * @param tricode 本级code
     * @param user_id 发送人user_id
     */
    public void addUserTemplateFlowNode(DataTableEntity staff, Integer grade, String uuid, String tricode, String user_id,DataTableEntity data, String created_by, String created_time, String org_level_uuid){
        for (int f = 0; f < staff.getRows(); f++) {
            FieldSetEntity subfse = new FieldSetEntity();
            //源表名
            subfse.setTableName("product_oa_cooperate_flow_node_template");
            //办理人层级
            subfse.setValue("grade", grade);
            //关联协同表uuid
            subfse.setValue("master_uuid", uuid);
            //接收人id
            subfse.setValue("receiver", staff.getString(f,"user_id"));
            //code
            subfse.setValue("tricode", tricode);
            //发送人id
            subfse.setValue("sender", user_id);
            subfse.setValue(CmnConst.CREATED_BY, created_by);
            subfse.setValue(CmnConst.CREATED_UTC_DATETIME, created_time);
            data.addFieldSetEntity(subfse);
        }
    }
 
    /**
     * 同步协同消息
     * @param conn jdbc连接
     * @param id 协同数据id
     * @throws SQLException
     */
    public void syncCollaborativeNews(Connection conn, String id,  Map<String, String[]> stateMap) throws SQLException {
        try {
            DataTableEntity collaborativeNews = BaseDaoServiceImpl.getDataTable(conn, "SELECT * FROM FE_BASE5.MESSAGEINFOR WHERE ME14 IN ( SELECT WI00 FROM FE_BASE5.WF_INFOR WHERE  WI29 = ? AND WI28 = 'SYS_COLLABORATIVE' AND WI13 = 0 ) ORDER BY ME14",  new Object[]{id});
            if(!BaseUtil.dataTableIsEmpty(collaborativeNews)) {
                this.syncCollaborativeNews(collaborativeNews, stateMap, "product_oa_cooperates");
            }
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            e.getStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
        }
 
    }
 
    /**
     *     同步协同流程消息表
     */
    public void syncCollaborativeNews(DataTableEntity OrlDt, Map<String, String[]> stateMap, String tableName){
        String id = null;
        String message_uuid = null;
        String[] state = null;
        DataTableEntity dataTableEntity = new DataTableEntity();
        FieldMetaEntity f = new FieldMetaEntity();
        f.setTableName(new String[]{"product_sys_message_user"});
        dataTableEntity.setMeta(f);
        for (int i = 0; i < OrlDt.getRows(); i++) {
            FieldSetEntity fs = OrlDt.getFieldSetEntity(i);
            //流程节点id
            String me14 = fs.getString("me14");
            //获取当前节点状态
            state = stateMap.get(me14);
            if(state == null){
                continue;
            }
            String sendUserId;
            //相同说明是同一消息  发送多个人
            if(!me14.equals(id)){
                //不一样创建消息主表
                id = me14;
                FieldSetEntity message = new FieldSetEntity();
                //消息主表
                message.setTableName("product_sys_message");
                //消息主题
                message.setValue("title", fs.getString("me01"));
                //消息内容
                message.setValue("content", fs.getString("me02"));
                //是否需要发送邮件
                message.setValue("is_send_mail", 0);
                //消息类型21 流程消息都为任务消息
                message.setValue("message_type", 21);
                //是否需要发送短信 0不发;1为强制;2为被动
                message.setValue("is_send_sms","0".equals(fs.getString("me20")) ? 0:1);
                //发送时间
                String me07 = fs.getString("me07");
                message.setValue("send_time", me07);
                //创建时间
                message.setValue("created_utc_datetime", me07);
 
                //发送人
                sendUserId = userIdJson.getString(fs.getString("me03"));
                if(BaseUtil.strIsNull(sendUserId)){
                    //流程infor 数据创建人为发送人
                    sendUserId  = state[2];
                    if(BaseUtil.strIsNull(sendUserId)){
                        continue;
                    }
                }
                message.setValue("send_user_id", sendUserId);
                //创建人及发送人
                message.setValue("created_by", sendUserId);
                //    业务表
                message.setValue("source_table", tableName);
                //url 业务地址
 
                message.setValue("source_uuid", state[3]);
 
                //查看详情
                message.setValue("url", state[1]);
                message_uuid = baseDao.add(message);
            }
 
            FieldSetEntity message_user = new FieldSetEntity();
            message_user.setTableName("product_sys_message_user");
            //关联lx_sys_message表UUID
            message_user.setValue("message_uuid", message_uuid);
            //mail_send    是否发送邮件
            message_user.setValue("mail_send", 0);
            //     是否阅读  节点状态为未读
            //0未读
            if("0".equals(state[0])){
                message_user.setValue("read_type", 0);
            }else {
                message_user.setValue("read_type", 1);
            }
            //receive_time    接收时间 无字段
            //sms_send    是否发送短信
            message_user.setValue("sms_send", 0);
            //user_id    消息接收人
            String user_id = userIdJson.getString(fs.getString("me05"));
            //找不到发送人就放接收人
            if(BaseUtil.strIsNull(user_id)){
                user_id = userIdJson.getString(fs.getString("me03"));
                if(BaseUtil.strIsNull(user_id)){
                    continue;
                }
            }
            message_user.setValue("user_id",user_id);
            dataTableEntity.addFieldSetEntity(message_user);
        }
        baseDao.add(dataTableEntity);
    }
 
    /**
     * 同步协同留言数据
     * @param ccooperatesInforDt infor数据uuid
     */
    public Map<String, String[]> syncCcooperatesInforDt(Connection conn, DataTableEntity ccooperatesInforDt, String uuid, Map<String, DataTableEntity> dataMap)throws Exception{
        Map<String, String[]> stateMap = Maps.newHashMap();
        for (int i = 0; i < ccooperatesInforDt.getRows(); i++) {
          FieldSetEntity inforFse = ccooperatesInforDt.getFieldSetEntity(i);
          String userId = userIdJson.getString(inforFse.getString("wi05"));
            //wi62 与节点表parentguid对应
            DataTableEntity dataTableEntity = parentGuidData.get(inforFse.getString("wi62"));
            if(BaseUtil.dataTableIsEmpty(dataTableEntity) || BaseUtil.strIsNull(userId)){
                continue;
            }
            for (int j = 0; j < dataTableEntity.getRows(); j++) {
              FieldSetEntity fieldSetEntity = dataTableEntity.getFieldSetEntity(j);
                String receiver = fieldSetEntity.getString("receiver");
                fieldSetEntity.setValue("accept_time",inforFse.getString("wi08")); //接收时间
                //相同就是一个人 赋办理状态  和留言
                if(userId.equals(receiver)){
                    String wi00 = inforFse.getString("wi00");
                    String nodeState = nodeDealType(inforFse.getString("wi13"));
                    fieldSetEntity.setValue("status", nodeState);
                    String wi20 = inforFse.getString("wi20");
                    //已办消息  并且消息为空 加上已阅
                    if(BaseUtil.strIsNull(wi20) && "2".equals(nodeState)){
                        wi20 = "已阅";
                    }
                    //留言消息
                    fieldSetEntity.setValue("opinion", wi20);
                    fieldSetEntity.setValue("accept_time",inforFse.getString("wi08")); //接收时间
                    fieldSetEntity.setValue("handle_time", inforFse.getString("wi11")); //处理时间
                    String flow_node_uuid = fieldSetEntity.getUUID();
                    String created_by = userIdJson.getString(inforFse.getString("wi15"));
                    //扩展留言消息
                    String wi21 = inforFse.getString("wi21");
                    String attachmentsValue = inforFse.getString("attachment");
                    //如果附件字段有值  同步附件
                    if(!BaseUtil.strIsNull(attachmentsValue)){
                        List<String> fileUuids = this.synchronizeCommonAccessories(conn, "attachments", "product_oa_cooperate_flow_node", attachmentsValue);
                        //存入附件uuid
                        fieldSetEntity.setValue("attachments", StringUtils.join(fileUuids, ","));
                    }
                    String url = "1623059056339697NPbV881?uuid="+uuid+"&flow_node_uuid="+flow_node_uuid;
                    DataTableEntity dataTableEntity1 = dataMap.get(wi21);
                    stateMap.put(wi00,new String[] {nodeState,url,created_by,uuid});
                    //有扩展留言
                    if(!BaseUtil.dataTableIsEmpty(dataTableEntity1)) {
                        for (int k = 0; k < dataTableEntity1.getRows(); k++) {
                            FieldSetEntity ideFse = dataTableEntity1.getFieldSetEntity(k);
                            //同步附件
                            String id08 = ideFse.getString("id08");
                            String reply_attachment = null;
                            String id07 = ideFse.getString("id07");
                            //回复内容
                            String id04 = ideFse.getString("id04");
                            //有附件 不等于0说明未额外留言
                            if (!BaseUtil.strIsNull(id08) && !"0".equals(id07)) {
                                // reply_attachment    回复附件,关联附件表uuid
                                List<String> attachment = this.synchronizeCommonAccessories(conn, "reply_attachment", "product_oa_cooperate_flow_reply", id08);
                                reply_attachment = StringUtils.join(attachment, ",");
                                //等于0说明 为处理数据
                            }else if(!BaseUtil.strIsNull(id08) && "0".equals(id07)){
                                List<String> attachment = this.synchronizeCommonAccessories(conn, "attachments", "product_oa_cooperate_flow_node", id08);
                                reply_attachment = StringUtils.join(attachment, ",");
                                fieldSetEntity.setValue("opinion", id04);
                                fieldSetEntity.setValue("attachments", reply_attachment);
                                continue;
                            }
                            FieldSetEntity flowReply = new FieldSetEntity();
                            flowReply.setTableName("product_oa_cooperate_flow_reply");
 
                            //关联lx_oa_cooperate_flow_node表uuid
                            flowReply.setValue("parent_uuid", fieldSetEntity.getUUID());
                            //回复内容
                            flowReply.setValue("reply_content",id04);
                            //回复时间
                            flowReply.setValue("reply_datetime", ideFse.getString("id03"));
                            //回复人,关联user表id
                            String user_id = userIdJson.getString(ideFse.getString("id02"));
                            if (BaseUtil.strIsNull(user_id)) {
                                continue;
                            }
                            //回复人,关联user表id
                            flowReply.setValue("reply_user", user_id);
                            //上级id
                            flowReply.setValue("superior_id", ideFse.getString("id01"));
                            flowReply.setValue("reply_attachment", reply_attachment);
                            baseDao.add(flowReply);
                        }
                    }
                    baseDao.update(fieldSetEntity);
                }
            }
        }
        return stateMap;
    }
 
    /**
     * 同步协同人员 岗位 机构
     * @param conn jdbc连接
     * @param flowCode 流程节点标识
     * @param uuid 协同uuid
     * @return
     */
    public DataTableEntity synchronousCooperator(Connection conn, String flowCode, String uuid) throws SQLException {
        DataTableEntity coNodeData = null;
        try {
            //flowcode 流程标识字段
            coNodeData = BaseDaoServiceImpl.getDataTable(conn, "SELECT * FROM FE_BASE5.WF_CO_NODE WHERE MGUID = ? ORDER BY CREATETIME",  new Object[]{flowCode});
 
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            throw e;
        }
        if(!BaseUtil.dataTableIsEmpty(coNodeData)) {
            FieldSetEntity fieldSetEntity = coNodeData.getFieldSetEntity(0);
            coNodeData.removeFieldSetEntity(0);
            DataTableEntity dataTable = new DataTableEntity();
            FieldMetaEntity f = new FieldMetaEntity();
            f.setTableName(new String[]{"product_oa_cooperate_flow_node"});
            dataTable.setMeta(f);
                String userId = userIdJson.getString(fieldSetEntity.getString("value"));
                if (BaseUtil.strIsNull(userId)) {
                    return null;
                }
            FieldSetEntity subfse = new FieldSetEntity();
            //源表名
            subfse.setTableName("product_oa_cooperate_flow_node");
            //办理人层级
            subfse.setValue("grade", 1);
            //关联协同表uuid
            subfse.setValue("cooperate_uuid", uuid);
            //接收人Id
            subfse.setValue("receiver", userId);
            //接收人姓名
            subfse.setValue("receiver_name", fieldSetEntity.getString("name"));
            //0:暂存 1:加签 2:转发 3:退回4:送办 5:终止 6:撤销
            subfse.setValue("type", 0);
            subfse.setValue("sender", null);
            subfse.setValue("sender_name", null);
            subfse.setValue("tricode",null);
            DataTableEntity newDataTable = new DataTableEntity();
            FieldMetaEntity f2 = new FieldMetaEntity();
            f2.setTableName(new String[]{"product_oa_cooperate_flow_node"});
            newDataTable.setMeta(f2);
            newDataTable.addFieldSetEntity(subfse);
            parentGuidData.put(fieldSetEntity.getString("guid"), newDataTable);
            dataTable.addFieldSetEntity(subfse);
            try {
                this.saveReceiver(fieldSetEntity, coNodeData, uuid, null, dataTable,2);
                baseDao.add(dataTable);
            }catch (Exception e){
                e.printStackTrace();
            }
            return dataTable;
        }
        return null;
    }
 
    /**
     * 递归循环同步人员 部门岗位 数据
     * @param fse 发送人fse
     * @param dataTableEntity 剩余人Data
     */
    private void saveReceiver(FieldSetEntity fse, DataTableEntity dataTableEntity, String uuid,String tricode, DataTableEntity dataTable, Integer grade)throws Exception{
        DataTableEntity dataTableEntity1 = new DataTableEntity();
        DataTableEntity dataTableEntity2 = new DataTableEntity();
        String sender = "";
        //发送类型
        String type2 = fse.getString("type");
        if("1".equals(type2)){
            sender = userIdJson.getString(fse.getString("value"));
            if(BaseUtil.strIsNull(sender)){
                return;
            }
        }
        for (int i = 0; i < dataTableEntity.getRows(); i++) {
          FieldSetEntity fieldSetEntity = dataTableEntity.getFieldSetEntity(i);
          String guid = fse.getString("guid");
          String parentguid = fieldSetEntity.getString("parentguid");
            if(guid.equals(parentguid)){
                dataTableEntity1.addFieldSetEntity(fieldSetEntity);
                FieldSetEntity subfs = new FieldSetEntity();
                //协同办公流程表
                subfs.setTableName("product_oa_cooperate_flow_node");
                subfs.setValue("grade", grade);
                //关联协同表uuid
                subfs.setValue("cooperate_uuid", uuid);
                //接收人(关联用户表id)  接收人一但是机构或部门节点   那就是最后节点
                String type = fieldSetEntity.getString("type");
                //发送人id
                subfs.setValue("sender", sender);
                //人员
                if("1".equals(type)){
                    String userId = userIdJson.getString(fieldSetEntity.getString("value"));
                    if(BaseUtil.strIsNull(userId)){
                        continue;
                    }
                    subfs.setValue("receiver", userId);
                    //若为部门公司
                }else if("2".equals(type)){
                    String orgUuid = orgLevelJson.getString(fieldSetEntity.getString("value"));
                    if(BaseUtil.strIsNull(orgUuid)){
                        continue;
                    }
                    if(!BaseUtil.strIsNull(orgUuid)){
                        DataTableEntity staff = baseDao.listTable(" product_sys_staffs ", " dept_uuid = ? ", new String[]{orgUuid});
                        if(BaseUtil.dataTableIsEmpty(staff)){
                            staff = baseDao.listTable(" product_sys_staffs ", " org_level_uuid = ? ", new String[]{orgUuid});
                        }
                        if(!BaseUtil.dataTableIsEmpty(staff)) {
                            tricode = dataTable.getString(dataTable.getRows()-1, "tricode");
                            if(BaseUtil.strIsNull(tricode)){
                                tricode = dataTable.getString(dataTable.getRows()-1, "receiver");
                            }
                            this.addUserFlowNode(staff, grade, uuid,fse, tricode, fieldSetEntity,sender,dataTable);
                        }
                        continue;
                    }
                    //岗位
                }else if("3".equals(type)){
                    String postUuid = postJson.getString(fieldSetEntity.getString("value"));
                    if(BaseUtil.strIsNull(postUuid)){
                        continue;
                    }
                    if(!BaseUtil.strIsNull(postUuid)){
                        DataTableEntity staff = baseDao.listTable(" product_sys_staffs ", " job_post_uuid = ? ", new String[]{postUuid});
                        if(!BaseUtil.dataTableIsEmpty(staff)) {
                            tricode = dataTable.getString(dataTable.getRows()-1, "tricode");
                            if(BaseUtil.strIsNull(tricode)){
                                tricode = dataTable.getString(dataTable.getRows()-1, "receiver");
                            }
                            this.addUserFlowNode(staff, grade, uuid,fse,  tricode, fieldSetEntity,sender,dataTable);
                        }
                        continue;
                    }
                }
                //接收人姓名
                subfs.setValue("receiver_name", fieldSetEntity.getString("name"));
                //triCode
                if(BaseUtil.strIsNull(tricode)){
                    subfs.setValue("tricode",sender);
                    fieldSetEntity.setValue("tricode",sender);
                }else {
                    subfs.setValue("tricode",tricode + "-" + sender);
                    fieldSetEntity.setValue("tricode",tricode + "-" + sender);
                }
 
                //发送人姓名
                subfs.setValue("sender_name", fse.getString("name"));
                //0:暂存 1:加签 2:转发 3:退回4:送办 5:终止 6:撤销
                subfs.setValue("type", 0);
                DataTableEntity newDataTable = new DataTableEntity();
                FieldMetaEntity f2 = new FieldMetaEntity();
                f2.setTableName(new String[]{"product_oa_cooperate_flow_node"});
                newDataTable.setMeta(f2);
                newDataTable.addFieldSetEntity(subfs);
                parentGuidData.put(fieldSetEntity.getString("guid"), newDataTable);
                dataTable.addFieldSetEntity(subfs);
            }else {
                dataTableEntity2.addFieldSetEntity(fieldSetEntity);
            }
        }
 
        //办理人层级
        grade++;
        if(!BaseUtil.dataTableIsEmpty(dataTableEntity1) && !BaseUtil.dataTableIsEmpty(dataTableEntity2)) {
            for (int i = 0; i < dataTableEntity1.getRows(); i++) {
                this.saveReceiver(dataTableEntity1.getFieldSetEntity(i) ,dataTableEntity2, uuid, dataTableEntity1.getString(i, "tricode"),dataTable,grade);
            }
        }
    }
 
    /**
     * 解析同步的岗位部门 解析为人再批量保存
     * @param staff 通过部门岗位  查询出来的用户数据
     * @param grade 层级
     * @param uuid 主表uuid
     * @param fse 源数据发送人信息
     * @param tricode 本级code
     * @param fieldSetEntity 接收信息
     * @param user_id 发送人user_id
     */
    public void addUserFlowNode(DataTableEntity staff, Integer grade, String uuid, FieldSetEntity fse, String tricode, FieldSetEntity fieldSetEntity,String user_id,DataTableEntity data){
        DataTableEntity newDataTable = new DataTableEntity();
        FieldMetaEntity f2 = new FieldMetaEntity();
        f2.setTableName(new String[]{"product_oa_cooperate_flow_node"});
        newDataTable.setMeta(f2);
        String guid = fieldSetEntity.getString("guid");
        for (int f = 0; f < staff.getRows(); f++) {
                FieldSetEntity subfse = new FieldSetEntity();
                //源表名
                subfse.setTableName("product_oa_cooperate_flow_node");
                //办理人层级
                subfse.setValue("grade", grade);
                //关联协同表uuid
                subfse.setValue("cooperate_uuid", uuid);
                //接收人id
                subfse.setValue("receiver", staff.getString(f,"user_id"));
                //接收人姓名
                subfse.setValue("receiver_name", staff.getString(f,"show_name"));
                //code
                subfse.setValue("tricode", tricode);
                //发送人姓名
                subfse.setValue("sender_name", fse.getString("name"));
                //发送人id
                subfse.setValue("sender", user_id);
                //0:未收未办 1:已收未 2:已收已办
                subfse.setValue("status", fieldSetEntity.getInteger("status") == 1 ? 2 : 0);
                //0:暂存 1:加签 2:转发 3:退回4:送办 5:终止 6:撤销
                subfse.setValue("type", 0);
                //用于后面关联协同流程
                newDataTable.addFieldSetEntity(subfse);
                data.addFieldSetEntity(subfse);
            }
        //用于后面关联协同流程
        parentGuidData.put(guid, newDataTable);
    }
 
    public String emergencyDegreeType(String type) {
        String reType = "";
        switch (type) {
            case "平件":
                reType = "1";
                break;
            case "特急":
                reType = "2";
                break;
            case "加急":
                reType = "3";
                break;
            default:
                throw new BaseException(SystemCode.FIELD_TYPE_FIAL.getValue(), SystemCode.FIELD_TYPE_FIAL.getText() + "_" + type);
 
        }
        return reType;
    }
 
    /**
     * 迁移功能权限许可
     *
     * @param conn      JDBC连接
     * @param funUUID   方法uuid
     * @param funCode   功能code
     * @param buttonMap 按钮map
     * @throws SQLException
     */
    public void syncFunctionPermission(Connection conn, String funUUID, String funCode, JSONObject buttonMap) throws SQLException {
        DataTableEntity permissionDt = null;
        try {
            StringBuffer sql = new StringBuffer();
            sql.append(" select spt.SPT00 FU01,sfu.FU04 from fe_base5.SYS_POPEDOM_TEMPLET spt ")
                    .append(" LEFT JOIN fe_base5.SYS_FUNCTION_USER sfu on spt.SPT00 = sfu.FU01 OR spt.SPT03 = sfu.FU05 ")
                    .append(" WHERE sfu.FU02 = ? AND sfu.FU03 = 'R' GROUP BY sfu.FU04,spt.SPT00 ");
            permissionDt = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new Object[]{funCode});
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            throw e;
        }
        //循环关联的角色权限
        for (int i = 0; i < permissionDt.getRows(); i++) {
            FieldSetEntity permissionFs = permissionDt.getFieldSetEntity(i);
            //角色id
            String fu01 = permissionFs.getString("fu01");
            //获取角色数据
            FieldSetEntity roleFse = baseDao.getFieldSetEntityByFilter("product_sys_role", " sequence = ? ", new String[]{fu01}, true);
            //查不到就跳过
            if(roleFse == null){
                continue;
            }
            //源数据功能勾选号
            String fu04 = permissionFs.getString("fu04");
            //获取权限里的按钮
            this.buttonCheck(conn, funCode,funUUID,fu04,buttonMap,roleFse.getUUID());
        }
        //同步关联人的权限
        this.createPersonalRights(conn,funCode,funUUID,buttonMap);
        //同步每个功能权限后   还要同步客户权限
//        this.customerPermission(funUUID, buttonMap);
    }
    /**
     * 添加按钮勾选
     *
     * @param conn      JDBC连接
     * @param funCode   功能code
     * @param funUUID   方法uuid
     * @param fu04      源数据功能勾选号
     * @param buttonMap 按钮map
     * @param roleUuid
     * @throws SQLException
     */
    private void buttonCheck(Connection conn,String funCode,String funUUID,String fu04,JSONObject buttonMap,String roleUuid) throws SQLException {
        List<String> buttonIdType = new ArrayList<>();
        buttonIdType.add(funCode);
        FieldSetEntity fs = new FieldSetEntity();
        fs.setTableName("product_sys_function_permission");
        fs.setValue("role_uuid",roleUuid);
        fs.setValue("function_uuid", funUUID);
        for (int j = 0; j < fu04.length(); j++) {
            String type = String.valueOf(fu04.charAt(j));
            if (type.equals("1")) {
                //放入值的下标
                buttonIdType.add(this.buttonTypeRole(j));
            }
        }
        if (buttonIdType.size() == 1) {
            return;
        }
        DataTableEntity eventDt = null;
        try {
            StringBuffer where = new StringBuffer();
            where.append(" SE01=? ").append(" and ( ").append(BaseUtil.buildQuestionMarkFilter("SE12", buttonIdType.size() - 1, true)).append(" or SE08=1) ");
            eventDt = BaseDaoServiceImpl.getDataTable(conn, "fe_base5.SYS_EVENT", where.toString(), buttonIdType.toArray());
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            throw e;
        }
        List<String> buttonId = Lists.newArrayList();
        for (int j = 0; j < eventDt.getRows(); j++) {
            buttonId.add(buttonMap.getString(eventDt.getString(j, "se00")));
        }
        fs.setValue("button_uuid", StringUtils.join(buttonId, ","));
        fs.setValue("created_by", 1);
        fs.setValue("created_utc_datetime", new Date());
        try {
            baseDao.add(fs);
        }catch (BaseException e){
            e.printStackTrace();
        }
    }
 
    /**
     * 给单个人权限单独创建角色
     * @param conn
     * @param funCode
     * @throws SQLException
     */
    public void createPersonalRights(Connection conn,String funCode,String funUUID,JSONObject buttonMap) throws SQLException {
        DataTableEntity usePermissionDt;
        try {
            usePermissionDt = BaseDaoServiceImpl.getDataTable(conn, "FE_BASE5.SYS_FUNCTION_USER", " FU02 = ? AND FU03 = 'U' ", new Object[]{funCode});
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            throw e;
        }
        if(!BaseUtil.dataTableIsEmpty(usePermissionDt)){
            String fu04 = usePermissionDt.getFieldSetEntity(0).getString("fu04");
            //创建角色
            FieldSetEntity lxRoleFs = new FieldSetEntity();
            lxRoleFs.setTableName("product_sys_role");
            lxRoleFs.setValue("org_level_uuid","00000000-0000-0000-0000-000000000000");
            lxRoleFs.setValue("role_name",  this.functionName+"的个人权限");
            lxRoleFs.setValue("role_description", this.functionName+"的个人权限");
            lxRoleFs.setValue("is_used", 1);
            lxRoleFs.setValue("created_by",1);
            lxRoleFs.setValue("created_utc_datetime",new Date());
            String uuid = baseDao.add(lxRoleFs);
            //同步权限关联的按钮
            this.buttonCheck(conn, funCode,funUUID,fu04,buttonMap,uuid);
            //该权限管理的是用户表(SYS_USERS)  并非角色表
            List<String> userid = Lists.newArrayList();
            for (int i = 0; i < usePermissionDt.getRows(); i++) {
                FieldSetEntity permissionFs = usePermissionDt.getFieldSetEntity(i);
                //用户id
                String id = this.userIdJson.getString(permissionFs.getString("fu01"));
                if(!BaseUtil.strIsNull(id)){
                    userid.add(id);
                }
            }
            //人员绑定该权限
            if(userid.size() > 0){
                String[] user = new String[userid.size()];
                userid.toArray(user);
                String filter = BaseUtil.buildQuestionMarkFilter("user_id", user,true);
                baseDao.executeUpdate("UPDATE  product_sys_staffs SET role_uuids = CONCAT(role_uuids, ',"+uuid+"')  WHERE " + filter);
            }
        }
    }
 
    /**
     * 同步客户权限
     * @param funUUID 功能权限
     * @param buttonMap 案例uuid map
     */
    public void customerPermission(String funUUID,JSONObject buttonMap){
        FieldSetEntity fs = new FieldSetEntity();
        fs.setTableName("product_sys_function_permission");
        fs.setValue("function_uuid", funUUID);
        //客户uuid
        fs.setValue("role_uuid", "8dddd416-a790-4a4e-8418-8c032d5f2394");
        List<String> buttonUuid = new ArrayList<>();
        for (String key : buttonMap.keySet()) {
            buttonUuid.add(buttonMap.getString(key));
        }
        //若没有按钮 直接退出
        if(buttonUuid.size() == 0){
            return;
        }
        fs.setValue("button_uuid", StringUtils.join(buttonUuid, ","));
        fs.setValue("created_by", 1);
        fs.setValue("created_utc_datetime", new Date());
        try {
            baseDao.add(fs);
        }catch (BaseException e){
            e.printStackTrace();
        }
 
    }
 
    /**
     * 创建一个功能下的角色
     * 把直接关联功能的用户放入角色下
     *
     * @param conn         连接
     * @param map          k 为按钮权限,u 为关联用户权限的data
     * @param funUUID      功能uuid
     * @param funCode      功能code
     * @param buttonJson   按钮json
     * @param orgLevelUuid 公司uuid
     */
    public void newFunctionRole(Connection conn, Map<String, DataTableEntity> map, String funUUID, String funCode, JSONObject buttonJson, String orgLevelUuid) {
        for (Map.Entry<String, DataTableEntity> m : map.entrySet()) {
            List<String> buttonIdType = new ArrayList<>();
            buttonIdType.add(funCode);
            String key = m.getKey();
            for (int j = 0; j < key.length(); j++) {
                String type = String.valueOf(key.charAt(j));
                if (type.equals("1")) {
                    //放入值的下标
                    buttonIdType.add(this.buttonTypeRole(j));
                }
            }
            //查询这条功能数据
            FieldSetEntity funFse = baseDao.getFieldSetEntity("product_sys_function", funUUID, false);
            //功能名称
            String functionName = funFse.getString("function_name");
            //创建角色
            FieldSetEntity lxRoleFs = new FieldSetEntity();
            lxRoleFs.setTableName("product_sys_role");
            if (BaseUtil.strIsNull(orgLevelUuid)) {
                orgLevelUuid = SpringMVCContextHolder.getCurrentUser().getOrg_level_uuid();
            }
            lxRoleFs.setValue("org_level_uuid", orgLevelUuid);
 
            String name = functionName + "功能下角色";
            lxRoleFs.setValue("role_name", name);
            lxRoleFs.setValue("role_description", name);
            lxRoleFs.setValue("is_used", 1);
            feDataDSService.userAndTime(lxRoleFs);
            baseDao.add(lxRoleFs);
            FieldSetEntity fs = new FieldSetEntity();
            fs.setTableName("product_sys_function_permission");
            fs.setValue("function_uuid", funUUID);
            StringBuffer where = new StringBuffer();
            where.append(" SE01=? ").append(" and ( ").append(BaseUtil.buildQuestionMarkFilter("SE12", buttonIdType.size() - 1, true)).append(" or SE08=1) ");
            DataTableEntity eventDt = BaseDaoServiceImpl.getDataTable(conn, "fe_base5.SYS_EVENT", where.toString(), buttonIdType.toArray());
            List<String> buttonId = new ArrayList<>();
            for (int j = 0; j < eventDt.getRows(); j++) {
                buttonId.add(buttonJson.getString(eventDt.getString(j, "se00")));
            }
            fs.setValue("button_uuid", StringUtils.join(buttonId, ","));
            fs.setValue("created_by", 1);
            fs.setValue("created_utc_datetime", new Date());
            //创建角色
            String uuid = baseDao.add(fs);
            //角色关联用户uuid
            DataTableEntity dataTableEntity = map.get(key);
            //获取关联用户
            for (int i = 0; i < dataTableEntity.getRows(); i++) {
                String userId = dataTableEntity.getString(i, "fu01");
                //获取用户
                FieldSetEntity fieldSetEntity = baseDao.getFieldSetEntityByFilter("product_sys_staffs", " remark = ? ", new String[]{userId}, false);
                String roleUuids = fieldSetEntity.getString("role_uuids");
                if (BaseUtil.strIsNull(roleUuids)) {
                    fieldSetEntity.setValue("role_uuids", uuid);
                } else {
                    roleUuids = roleUuids + "," + uuid;
                    fieldSetEntity.setValue("role_uuids", roleUuids);
                }
                //保存修改角色权限后的用户
                baseDao.add(fieldSetEntity);
            }
 
        }
    }
 
    private String buttonTypeRole(int type) {
        String button_category_uuid = "";
        switch (type) {
            case 0:
                button_category_uuid = "01";
                break;
            case 1:
                button_category_uuid = "02";
                break;
            case 2:
                button_category_uuid = "03";
                break;
            case 3:
                button_category_uuid = "04";
                break;
            case 4:
                button_category_uuid = "05";
                break;
            case 5:
                button_category_uuid = "06";
                break;
            case 6:
                button_category_uuid = "07";
                break;
            case 7:
                button_category_uuid = "08";
                break;
            case 8:
                button_category_uuid = "09";
                break;
            case 9:
                button_category_uuid = "10";
                break;
            case 10:
                button_category_uuid = "11";
                break;
            case 11:
                button_category_uuid = "12";
                break;
            default:
                throw new BaseException(SystemCode.FIELD_TYPE_FIAL.getValue(), SystemCode.FIELD_TYPE_FIAL.getText() + "_" + type);
        }
        return button_category_uuid;
    }
 
    /**
     * 迁移功能下的按钮页面
     *
     * @param conn
     * @param funUUID
     * @param funCode
     * @throws SQLException
     */
    public JSONObject syncButtonsPage(Connection conn, String funUUID, String funCode) throws SQLException {
        DataTableEntity buttonsDt = null;
        try {//获取显示按钮
            buttonsDt = BaseDaoServiceImpl.getDataTable(conn, "fe_base5.SYS_EVENT", "SE30 = '1' AND SE01= ? ", new Object[]{funCode});
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            throw e;
        }
        String flow_uuid = null;
        String sendButton = null;
        JSONObject map = new JSONObject();
        //名字为k 的json
        Map<String, FieldSetEntity> nameButtonMap = Maps.newHashMap();
        for (int i = 0; i < buttonsDt.getRows(); i++) {
            FieldSetEntity buttonsFs = buttonsDt.getFieldSetEntity(i);
            FieldSetEntity fs = new FieldSetEntity();
            //按钮表
            fs.setTableName("product_sys_function_buttons");
            fs.setValue("function_uuid", funUUID);
            //按钮名称
            fs.setValue("button_name", buttonsFs.getString("se02"));
            //按钮标题 如果为空  就用描述
            String buttonsFsString = buttonsFs.getString("se31");
            if (BaseUtil.strIsNull(buttonsFsString) || " ".equals(buttonsFsString)) {
                buttonsFsString = buttonsFs.getString("se09");
            }
            fs.setValue("button_title", buttonsFsString);
            //按钮描述
            fs.setValue("button_description", buttonsFs.getString("se09"));
            //点击触发按钮事件的类型:1: 入口,2:普通按钮  若为入口可能会绑定流程
            if (buttonsFs.getInteger("se08") == 1) {
                fs.setValue("button_type", 1);
                //绑定的流程
                String se16 = buttonsFs.getString("se16");
                //不为空 单独处理流程关联
                if (!BaseUtil.strIsNull(se16)) {
                    flow_uuid = se16;
                }
            } else {
                fs.setValue("button_type", 2);
            }
            fs.setValue("button_type", buttonsFs.getInteger("se08") == 1 ? 1 : 2);
            //是否启用
            fs.setValue("status_uuid", 1);
            String type;
            if(buttonsFs.getInteger("se08") == 1){
                //是否为功能入口,1=是,0=否
                fs.setValue("is_main", 1);
                type = "main";
            }else {
                type = buttonType(buttonsFs.getString("se12"));
                fs.setValue("is_main", 0);
            }
            //按钮分类:关联字典表(新增,修改,删除,查看,列表,导入,导出,送审)
 
            fs.setValue("button_category_uuid", type);
            //是删除按钮   都多选
            if ("delete".equals(type)) {
                //是否多选  1 是
                fs.setValue("multiple_choice", 1);
                //是否提醒
                fs.setValue("is_warn", 1);
            } else {
                //是否多选  1 是
                fs.setValue("multiple_choice", 0);
                fs.setValue("is_warn", 0);
            }
            //客户端类型:关联数据字典
            fs.setValue("client_type_uuid", "Web");
            //位置top
            fs.setValue("top_location", buttonsFs.getInteger("se11") + "px");
            //位置left
            fs.setValue("left_location", buttonsFs.getInteger("se10") + "px");
            //事件前 fron_event 1000
            fs.setValue("fron_event", buttonsFs.getString("se03"));
            //逻辑方法 logical_method  800
            fs.setValue("logical_method", buttonsFs.getString("se04"));
            //事件后 event_after  900
            fs.setValue("event_after", buttonsFs.getString("se05"));
            //脚本类型 event_type 250
            fs.setValue("event_type", buttonsFs.getString("se15"));
            //引入脚本 script_method 暂不插入
//            System.out.println("se14:" + buttonsFs.getString("se14"));
//            fs.setValue("script_method", buttonsFs.getString("se14"));
            //路由名称
            fs.setValue("route_name", BaseUtil.getPageCode());
 
            String  uuid = baseDao.add(fs);
            //09为送办按钮
            if ("09".equals(buttonsFs.getString("se12")) && !BaseUtil.strIsNull(buttonsFs.getString("se14"))) {
                sendButton = uuid;
            }
            map.put(buttonsFs.getString("se00"), uuid);
            //名字唯一
            nameButtonMap.put(buttonsFs.getString("se09"), fs);
        }
 
        DataTableEntity pageDt = null;
        try {
            pageDt = BaseDaoServiceImpl.getDataTable(conn, "fe_base5.SYS_PAGE", "SP01=?", new Object[]{funCode});
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            throw e;
        }
        JSONObject pageMap = new JSONObject();
        Map<String, FieldSetEntity> pageNameMap = Maps.newHashMap();
        for (int i = 0; i < pageDt.getRows(); i++) {
            FieldSetEntity pageFs = pageDt.getFieldSetEntity(i);
            FieldSetEntity fs = new FieldSetEntity();
            //页面表
            fs.setTableName("product_sys_mvc_page");
            fs.setValue("function_uuid", funUUID);
            //页面名称
            String sp02 = pageFs.getString("sp02");
            fs.setValue("page_name", sp02);
            //禁用页面元素
            fs.setValue("page_element_disabled", 0);
            fs.setValue("created_by", 1);
            fs.setValue("created_utc_datetime", new Date());
            //位置top
            fs.setValue("top_location", pageFs.getString("sp07") + "px");
            //位置left
            fs.setValue("left_location", pageFs.getString("sp06") + "px");
            //表单类型 名称带有列表都是列表类型
            if (sp02.contains("列表")) {
                fs.setValue("page_type", 1);
            } else {
                fs.setValue("page_type", 0);
            }
            //页面是否可修改
            fs.setValue("page_element_disabled", pageFs.getInteger("sp08") == 1 ? 0 : 1);
            //页面路径暂存   fe引入js代码路径
            fs.setValue("page_url", pageFs.getString("sp09"));
            //先存入流程id    迁移流程后再替换
            fs.setValue("flow_uuid", pageFs.getString("sp09"));
            //打开方式
            fs.setValue("page_open_with", 0);
            String  uuid = baseDao.add(fs);
            pageMap.put(pageFs.getString("sp00"), uuid);
            pageNameMap.put(sp02, fs);
        }
        DataTableEntity pageButtonDt = null;
        try {
            pageButtonDt = BaseDaoServiceImpl.getDataTable(conn, "fe_base5.SYS_EVENT_PAGE", "SEP06=?", new Object[]{funCode});
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            throw e;
        }
        for (int i = 0; i < pageButtonDt.getRows(); i++) {
            FieldSetEntity pageButtonFs = pageButtonDt.getFieldSetEntity(i);
            FieldSetEntity fs = new FieldSetEntity();
            fs.setTableName("product_sys_link");
            fs.setValue("function_uuid", funUUID);
            //连线类型
            fs.setValue("link_type", 0);
            //起始uuid
            String pageUuid = pageMap.getString(pageButtonFs.getString("sep01"));
            fs.setValue("line_from", pageUuid);
            //起始类型 页面
            fs.setValue("from_type", 2);
            //截止uuid
            String buttonUuid = map.getString(pageButtonFs.getString("sep02"));
            //为空表示关联失效的按钮  ,就不搬
            if (BaseUtil.strIsNull(buttonUuid)) {
                continue;
            }
            fs.setValue("line_to", buttonUuid);
            //相等说明为送办   找到页面uuid存入流程
            if (!BaseUtil.strIsNull(flow_uuid) && buttonUuid != null && buttonUuid.equals(sendButton)) {
                if (pageUuid != null) {
                    FieldSetEntity fse = baseDao.getFieldSetEntity("product_sys_mvc_page", pageUuid, false);
                    fse.setValue("flow_uuid", flow_uuid);
                    baseDao.update(fse);
                }
            }
            //截止类型
            fs.setValue("to_type", 1);
            fs.setValue("created_by", 1);
            fs.setValue("created_utc_datetime", new Date());
            baseDao.add(fs);
        }
        DataTableEntity buttonPageDt = null;
        try {
            //按钮连页面   按钮连按钮
            buttonPageDt = BaseDaoServiceImpl.getDataTable(conn, "fe_base5.SYS_REDIRECT", "SR06=?", new Object[]{funCode});
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            throw e;
        }
        for (int i = 0; i < buttonPageDt.getRows(); i++) {
            FieldSetEntity buttonPageFs = buttonPageDt.getFieldSetEntity(i);
            FieldSetEntity fs = new FieldSetEntity();
            fs.setTableName("product_sys_link");
            fs.setValue("function_uuid", funUUID);
            fs.setValue("link_type", 0);
            //按钮与页面或者按钮与页面关系字段
            String sr05 = buttonPageFs.getString("sr05");
            String[] sr05s = sr05.split("-->");
            FieldSetEntity buttonFse = nameButtonMap.get(sr05s[0]);
            if (buttonFse == null) {
                continue;
            }
            //判断是否是入口
            if (1 == buttonFse.getInteger("is_main")) {
                //起始类型 0 入口 1 按钮 2 页面
                fs.setValue("from_type", 0);
            } else {
                //起始类型 0 入口 1 按钮 2 页面
                fs.setValue("from_type", 1);
            }
            fs.setValue("line_from", buttonFse.getUUID());
            //获取按钮信息
            //连接类型  1按钮连按钮   0按钮连页面
            Integer sr02 = buttonPageFs.getInteger("sr02");
            //连接的是按钮
            if (1 == sr02) {
                //获取按钮fse 1
                FieldSetEntity buttonFse2 = nameButtonMap.get(sr05s[1]);
                if (buttonFse2 == null) {
                    continue;
                }
                //判断是否是入口
                if (1 == buttonFse2.getInteger("is_main")) {
                    //结束类型 0 入口 1 按钮 2 页面
                    fs.setValue("to_type", 0);
                } else {
                    fs.setValue("to_type", 1);
                }
                fs.setValue("line_to", buttonFse2.getUUID());
            } else {
                //连接的是页面
                //获取页面fse 0
                FieldSetEntity pageFse = pageNameMap.get(sr05s[1]);
                if (pageFse == null) {
                    continue;
                }
                //页面类型
                fs.setValue("to_type", 2);
                //页面uuid
                fs.setValue("line_to", pageFse.getUUID());
            }
            fs.setValue("created_by", 1);
            fs.setValue("created_utc_datetime", new Date());
            baseDao.add(fs);
        }
        return map;
    }
 
    /**
     * 按钮类型转换
     *
     * @param type
     * @return
     */
    private String buttonType(String type) {
        String button_category_uuid = "";
        if (type == null) {
            button_category_uuid = "main";
            return button_category_uuid;
        }
        switch (type) {
            case "01":
                button_category_uuid = "add";
                break;
            case "02":
                button_category_uuid = "update";
                break;
            case "03":
                button_category_uuid = "delete";
                break;
            case "04":
                button_category_uuid = "view";
                break;
            case "05":
                button_category_uuid = "print";
                break;
            case "06":
                button_category_uuid = "import";
                break;
            case "07":
                button_category_uuid = "custom";
                break;
            case "08":
                button_category_uuid = "custom";
                break;
            case "09":
                button_category_uuid = "audit";
                break;
            case "10":
                button_category_uuid = "custom";
                break;
            case "11":
                button_category_uuid = "custom";
                break;
            case "12":
                button_category_uuid = "custom";
                break;
            default:
                button_category_uuid = "custom";
 
        }
        return button_category_uuid;
    }
 
    /**
     * @param funFs
     * @param moduleCode 模块code
     * @throws SQLException
     */
    public void syncFunctions(FieldSetEntity funFs, String moduleCode, String moduleUUID, String sf28) throws SQLException, ClassNotFoundException {
        if(!BaseUtil.strIsNull(funFs.getString("sf28"))){
            sf28 = funFs.getString("sf28");
        }
        FieldSetEntity product_sys_datamodel_table = new FieldSetEntity();
        String table = "";
        if(!BaseUtil.strIsNull(sf28)){
            table = sf28.split("\\.")[1].toLowerCase();
            product_sys_datamodel_table = baseDao.getFieldSetEntityByFilter("product_sys_datamodel_table", "table_name=?", new String[]{table}, false);
        }else {
            return;
        }
 
        //迁移功能
        FieldSetEntity fs = new FieldSetEntity();
        fs.setTableName("product_sys_functions");
        //表uuid
        fs.setValue("table_uuid",product_sys_datamodel_table.getString("uuid"));
        //功能名称
        this.functionName =  funFs.getString("sf03");
        fs.setValue("function_name", this.functionName);
        //功能描述
        fs.setValue("function_description", this.functionName);
        //上级code    上级模块code
        fs.setValue("tricode_parent", moduleCode);
        //功能code
        String funCode = CodeUtil.getNewCodeByTemp(CmnConst.PRODUCT_SYS_FUNCTIONS, CmnConst.TRICODE, moduleCode);
        fs.setValue("tricode", funCode);
        //功能短编码
        fs.setValue("function_shortcode", "feqy");
        fs.setValue("status_uuid", "1");
        fs.setValue("function_type_uuid", "1");
        fs.setValue("client_type_uuid", "Web");
        fs.setValue("version_uuid", "001");
        fs.setValue("created_by", 1);
        fs.setValue("created_utc_datetime", new Date());
        fs.setValue("data_type", 1);
        String funUUID = "";
        try {
            funUUID = baseDao.add(fs);
        }catch (BaseException e){
            e.printStackTrace();
        }
        //修改已同步附件 添加 module_uuid function_uuid
        baseDao.executeUpdate(" UPDATE product_sys_attachments SET module_uuid = ?, function_uuid = ? WHERE attachment_data_table = ? AND function_uuid is null ",new String[]{moduleUUID, funUUID, table});
        String sf05 = funFs.getString("sf05");
        //获取jdbc连接
        Connection conn = this.getJDBC();
        //迁移MVC
        JSONObject buttonMap = this.syncButtonsPage(conn, funUUID, sf05);
        //迁移菜单
        try {
            this.synchronizationMenu(conn, funFs.getString("sf05"), funUUID);
        }catch (Exception e){
            e.getStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
        }
        //迁移功能权限许可
        this.syncFunctionPermission(conn, funUUID, sf05, buttonMap);
        //关闭连接
        DataManipulationUtils.close(null, null, conn);
    }
 
    /**
     * 同步模块名称
     *
     * @param conn    连接
     * @param funCode 功能code
     */
    public String synchronizationModuleName(Connection conn, String funCode, String sf28) throws SQLException {
        FieldSetEntity funFse = null;
        try {
            //通过
            funFse = BaseDaoServiceImpl.getFieldSet(conn, "fe_base5.SYS_FUNCTION", "  SF05 = ? ", new Object[]{funCode});
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            e.getStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
            throw e;
        }
        if (funFse == null) {
            return null;
        }
        //模块名称
        String sf01 = funFse.getString("sf01");
 
        //同步模块名称
        FieldSetEntity moduleFs = baseDao.getFieldSetEntityByFilter("product_sys_functions", " function_name = ? ", new String[]{sf01}, false);
        String moduleCode = null;
        String moduleUUID = null;
        if (moduleFs == null) {
            moduleFs = new FieldSetEntity();
            moduleFs.setTableName("product_sys_functions");
            //产品uuid
            moduleFs.setValue("table_uuid", "ff44dc40-5fa6-4b99-a0c6-463fd5fb5c5b85");
            moduleFs.setValue("function_name", sf01);
            moduleFs.setValue("function_description", sf01);
            //产品code
            moduleFs.setValue("tricode_parent", "001");
            moduleCode = CodeUtil.getNewCodeByTemp(CmnConst.PRODUCT_SYS_FUNCTIONS, CmnConst.TRICODE, "001");
            moduleFs.setValue("tricode", moduleCode);
            moduleFs.setValue("function_shortcode", "feqymk");
            moduleFs.setValue("status_uuid", "1");
            moduleFs.setValue("function_type_uuid", "0");
            moduleFs.setValue("function_icon", "0");
            moduleFs.setValue("client_type_uuid", "Web");
            moduleFs.setValue("version_uuid", "001");
            moduleFs.setValue("created_by", 1);
            moduleFs.setValue("created_utc_datetime", new Date());
            moduleFs.setValue("data_type", 2);
            //新增一个fe迁移总模块
            try {
                moduleUUID = baseDao.add(moduleFs);
            }catch (BaseException e){
                e.printStackTrace();
            }
        } else {
            moduleCode = moduleFs.getString("tricode");
            moduleUUID = moduleFs.getUUID();
        }
        //同步模块下的功能
        try {
            this.syncFunctions(funFse, moduleCode, moduleUUID, sf28);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        //同步菜单
        return moduleUUID;
    }
 
    /**
     * 同步菜单 如果没有上级目录 创建上级目录
     * @param conn jdbc连接
     * @param funCode 同步code
     */
    public void synchronizationMenu(Connection conn, String funCode, String funUUID) throws SQLException,BaseException{
        //根据功能code获取菜单
        FieldSetEntity menuFse = null;
        try {
            //菜单信息
            menuFse = BaseDaoServiceImpl.getFieldSet(conn, "FE_BASE5.DESKTOP_MENU_MANAGEMENT", "  URL = ? ", new Object[]{funCode});
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            e.getStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
            throw e;
        }
        //查询是否有菜单和目录名称
        FieldSetEntity fieldSetEntity = baseDao.getFieldSetEntityByFilter("product_sys_menus"," menu_name = ? ",new String[] {menuFse.getString("temp")}, false);
        //创建菜单
        FieldSetEntity fieldSet = new FieldSetEntity();
        fieldSet.setTableName("product_sys_menus");
        //是否目录 0否、1是
        fieldSet.setValue("is_catalog", 0);
        //是否显示 0:不显示、 1:显示
        fieldSet.setValue("is_show", "1");
        //关联功能
        fieldSet.setValue("function_uuid", funUUID);
        //菜单描述
        fieldSet.setValue("menu_description", menuFse.getString("name"));
        //菜单名称
        fieldSet.setValue("menu_name",  menuFse.getString("name"));
        //排列顺序 方源菜单id
        fieldSet.setValue("sequence", menuFse.getString("id"));
        //图标
        fieldSet.setValue("menu_icon", "form");
        String menuCode;
        //没有就创建菜单目录
        if(fieldSetEntity == null){
            FieldSetEntity menuFieldSet = new FieldSetEntity();
            menuFieldSet.setTableName("product_sys_menus");
            //是否目录 0否、1是
            menuFieldSet.setValue("is_catalog", 1);
            //是否显示 0:不显示、 1:显示
            menuFieldSet.setValue("is_show", "1");
            //关联功能为空
            menuFieldSet.setValue("function_uuid", "");
            //图标
            menuFieldSet.setValue("menu_icon", "clipboard");
            //菜单描述
            menuFieldSet.setValue("menu_description",  menuFse.getString("temp"));
            //菜单名称
            menuFieldSet.setValue("menu_name", menuFse.getString("temp"));
            //排列顺序 方源菜单目录id
            menuFieldSet.setValue("sequence", menuFse.getString("fatherid"));
            menuCode = CodeUtil.getNewCodeByTemp("product_sys_menus", "tricode", "");
            //编码
            menuFieldSet.setValue("tricode", menuCode);
            //父级编码
            menuFieldSet.setValue("tricode_parent", "");
            try {
                baseDao.add(menuFieldSet);
            }catch (BaseException e){
                e.printStackTrace();
            }
 
        }else {
            menuCode = fieldSetEntity.getString("tricode");
        }
        //生成的菜单编码
        fieldSet.setValue("tricode", CodeUtil.getNewCodeByTemp("product_sys_menus", "tricode", menuCode));
        //父级编码
        fieldSet.setValue("tricode_parent", menuCode);
        try {
            baseDao.add(fieldSet);
        }catch (BaseException e){
            e.printStackTrace();
        }
    }
 
    /**
     * 迁移业务数据表
     *
     * @param sf28s 库名和表名
     * @param conn  连接
     * @return
     * @throws SQLException
     */
    public void syncTable(String[] sf28s, boolean isNew, String subField, Connection conn) throws Exception {
        FieldSetEntity Orlfs;
        //表名
        String taName = sf28s[1];
        //获取主表的表名
        if (sf28s.length == 3) {
            this.masterTableName = sf28s[2];
        }
        try {
            Orlfs = BaseDaoServiceImpl.getFieldSet(conn, "fe_base5.SYS_TABLE", "ST03=?", new Object[]{taName});
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            e.getStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
            throw e;
        }
        Map<String, String> map = null;
        Boolean syncAttachments = false;
        DataTableEntity accessoryData;
        //是否是新表
        if (isNew) {
            //判断是否是已经同步过的表
            FieldSetEntity fieldSetEntity = baseDao.getFieldSetEntityByFilter("product_sys_datamodel_table", " table_name = ? ", new String[]{taName.toLowerCase()}, false);
            if (fieldSetEntity == null) {
                //查询该表字有没有附件字段  media attachment
                accessoryData = this.getTableFieldAttachment(conn, Orlfs.getString("st00"));
                if (!BaseUtil.dataTableIsEmpty(accessoryData)) {
                    syncAttachments = true;
                    for (int i = 0; i < accessoryData.getRows(); i++) {
                        this.attachmentValue = this.attachmentValue + accessoryData.getString(i, "si04") + ",";
                    }
                    this.attachmentValue = "," + this.attachmentValue;
                }
                //同步表结构  及字段信息
                map = this.syncTableField(conn, Orlfs, sf28s, subField);
                //刷新table 表
                DataPoolCacheImpl.getInstance().cacheDataByTable("product_sys_datamodel_table");;
                //刷新field 表
                DataPoolCacheImpl.getInstance().cacheDataByTable("product_sys_datamodel_field");
                try {
                    Thread.sleep(7000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    SpringMVCContextHolder.getSystemLogger().error(e);
                }
            } else {
                return;
            }
        } else {
            //已有表
            this.syncFunTable(conn, sf28s[0] + '.' + sf28s[1]);
            return;
        }
        //迁移表里面数据
        DataTableEntity dataDt = null;
        try {
            dataDt = BaseDaoServiceImpl.getDataTable(conn, sf28s[0] + "." + sf28s[1], null, new String[]{});
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            e.printStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
            throw e;
        }
 
        //业务表 fe的id  对应UUID
        for (int i = 0; i < dataDt.getRows(); i++) {
            FieldSetEntity dataFs = dataDt.getFieldSetEntity(i);
            FieldSetEntity tableFs = new FieldSetEntity();
            tableFs.setTableName(this.originalTable.getString(taName));
            //key 为本表字段   value 为数据源字段
            for (String key : map.keySet()) {
                //单关联的用户user_id
                if ("USER".equals(fieldTypeJson.getString(key))) {
                    tableFs.setValue(key, userIdJson.getString(dataFs.getString(map.get(key))));
                    //单关联的组织架构uuid
                } else if ("GROUP".equals(fieldTypeJson.getString(key))) {
                    tableFs.setValue(key, groupJson.get(dataFs.getString(map.get(key))));
                    //多选组织架构  转换为用户user_ids
                } else if ("USERSGROUPS".equals(fieldTypeJson.getString(map.get(key)))) {
                    tableFs.setValue(key, this.getUserIds(conn,dataFs.getString(map.get(key))));
                } else {
                    //是否有字段关联主表
                    if (subField != null && subField.equals(map.get(key))) {
                        //表名加下标 唯一
                        tableFs.setValue(key, pxMap.getString(masterTableName + dataFs.getString(map.get(key))));
                    } else {
                        tableFs.setValue(key, dataFs.getString(map.get(key)));
                    }
                }
            }
            //同步附件
            if (syncAttachments) {
                Map<String, List<String>> fileMaps = this.synchronizationAttachments(conn, accessoryData, dataFs, tableFs.getTableName(), null);
                if (fileMaps.size() > 0) {
                    for (String fieldName : fileMaps.keySet()) {
                        List<String> value = fileMaps.get(fieldName);
                        tableFs.setValue(fieldName, StringUtils.join(value, ","));
                    }
                }
            }
            String uuid = "";
            try {
                uuid = baseDao.add(tableFs);
            }catch (BaseException e){
                e.printStackTrace();
                SpringMVCContextHolder.getSystemLogger().error(e);
            }
            //表唯一id  对应uuid
            pxMap.put(taName + dataFs.getString(this.pk), uuid);
        }
        //同步完一张表数据后清空json数据
        fieldTypeJson.clear();
        DataTableEntity subTble = null;
        try {
            //查询是否有子表
            subTble = BaseDaoServiceImpl.getDataTable(conn, "SELECT  a.SF01, a.SF10,b.ST02 ST02,b.ST03 ST03 FROM FE_BASE5.SYS_FIELD a INNER JOIN FE_BASE5.SYS_TABLE b on a.SF00=b.ST00 WHERE a.SF10 LIKE ? ", new String[]{"%." + taName + ".%"});
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            SpringMVCContextHolder.getSystemLogger().error(e);
            throw e;
        }
        for (int i = 0; i < subTble.getRows(); i++) {
            FieldSetEntity sf = subTble.getFieldSetEntity(i);
            String a[] = {sf.getString("st02"), sf.getString("st03"), taName};
            if (isStr(sf.getString("st02") + "\\." + sf.getString("st03"))) {
                isNew = false;
            }
            this.syncTable(a, isNew, sf.getString("sf01").toLowerCase(), conn);
        }
    }
 
    /**
     * 判断是否是引用数据 是就要转换(如人员id,机构id)
     *
     * @param tableName 表名点.字段名
     * @return
     */
    public String transformReferenceData(Connection conn, String tableName, String fieldName,FieldSetEntity fieldSetEntity) throws SQLException {
        DataTableEntity dataTable;
        try {
            StringBuffer sql = new StringBuffer();
            sql.append(" SELECT * FROM fe_base5.SYS_FACEITEM A FULL JOIN fe_base5.SYS_FACE B ")
                    .append(" ON A.SI01 = B.SF00 LEFT JOIN FE_BASE5.SYS_FACECTRLPROP C ON A.SI00 = C.SP00 ")
                    .append(" WHERE SI04 = ? AND B.SF01 = ( SELECT st00 FROM fe_base5.sys_table WHERE st03 = ?) AND C.SP01 = 'prompt' AND SP02 IN ('[100001]', '[100000]') ");
            dataTable = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new String[]{fieldName, tableName});
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            SpringMVCContextHolder.getSystemLogger().error(e);
            throw e;
        }
        //是否是关联单个人员控件
        if (BaseUtil.dataTableIsEmpty(dataTable)) {
            try {
                //是否是关联单个单位部门控件
                StringBuffer sql = new StringBuffer();
                sql.append(" SELECT * FROM fe_base5.SYS_FACEITEM A FULL JOIN fe_base5.SYS_FACE B ")
                        .append(" ON A.SI01 = B.SF00 LEFT JOIN FE_BASE5.SYS_FACECTRLPROP C ON A.SI00 = C.SP00 ")
                        .append(" WHERE SI04 = ? AND B.SF01 = ( SELECT st00 FROM fe_base5.sys_table WHERE st03 = ?) AND ((C.SP01 = 'orgtype' AND C.SP02 = 'A11') OR (C.SP01 = 'prompt' AND C.SP02 IN ('[010001]','[010000]'))) ");
 
                dataTable = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new String[]{fieldName, tableName});
            } catch (Exception e) {
                DataManipulationUtils.close(null, null, conn);
                SpringMVCContextHolder.getSystemLogger().error(e);
                throw e;
            }
            if (BaseUtil.dataTableIsEmpty(dataTable)) {
                try {
                    //是否是关联部门岗位人员多选控件
                    StringBuffer sql = new StringBuffer();
                    sql.append(" SELECT * FROM fe_base5.SYS_FACEITEM A FULL JOIN fe_base5.SYS_FACE B ")
                            .append(" ON A.SI01 = B.SF00 LEFT JOIN FE_BASE5.SYS_FACECTRLPROP C ON A.SI00 = C.SP00 ")
                            .append(" WHERE SI04 = ? AND B.SF01 = ( SELECT st00 FROM fe_base5.sys_table WHERE st03 = ?) AND C.SP01 = 'prompt' AND SP02 = '[111110]' ");
 
                    dataTable = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new String[]{fieldName, tableName});
                } catch (Exception e) {
                    DataManipulationUtils.close(null, null, conn);
                    SpringMVCContextHolder.getSystemLogger().error(e);
                    throw e;
                }
                //如果是多选控件
                if (!BaseUtil.dataTableIsEmpty(dataTable)) {
                    fieldTypeJson.put(fieldName.toLowerCase(), "USERSGROUPS");
                    return "800";
                }
            } else {
                fieldTypeJson.put(fieldName.toLowerCase(), "GROUP");
                //添加部门公司参照
                fieldSetEntity.setValue("field_reference", "levels");
                return "80";
            }
        } else {
            //添加人员参照
            fieldTypeJson.put(fieldName.toLowerCase(), "USER");
            fieldSetEntity.setValue("field_reference", "user_name_by_user_id");
        }
        return null;
    }
 
    /**
     * 同步附件
     *
     * @param accessoryData 附件字段data
     * @param tableFs       数据值
     */
    public Map<String, List<String>> synchronizationAttachments(Connection conn, DataTableEntity accessoryData, FieldSetEntity tableFs, String table,String myField) throws Exception {
        Map<String, List<String>> filesMap = Maps.newHashMap();
        for (int i = 0; i < accessoryData.getRows(); i++) {
            //类型
            String type = accessoryData.getString(i, "si02");
            //字段
            String field = accessoryData.getString(i, "si04").toLowerCase();
            //获取附件值
            String attachmentsValue = tableFs.getString(field);
            if(!BaseUtil.strIsNull(myField)){
                field = myField;
            }
            if (!BaseUtil.strIsNull(attachmentsValue)) {
                List<String> fileUuids = Lists.newArrayList();
                    //普通附件
                    if ("attachment".equals(type)) {
                        //取出附件表数据
                        fileUuids = this.synchronizeCommonAccessories(conn, field, table, attachmentsValue);
                        //金格附件
                    } else if ("media".equals(type)) {
                        //附件值
                        Map<String, File> mediaFiles = gdMediaUtil.getMediaFiles(attachmentsValue);
                        for (String name : mediaFiles.keySet()) {
                            File sourceFile = mediaFiles.get(name);
                            String newPath = this.TSPath + File.separator + name;
                            File isField = new File(newPath);
                            //如果已经有该文件   改变文件目录
                            Integer fileNum = 0;
                            while (isField.exists()) {
                                fileNum++;
                                newPath = this.TSPath + fileNum + File.separator + name;
                                isField = new File(newPath);
                            }
                            //源绝对路径
                            String path = sourceFile.getAbsolutePath();
                            if (feDataDSService.copyFile(path, newPath)) {
                                RequestParameterEntity rpe = new RequestParameterEntity();
                                Map<String, File> fileMap = Maps.newHashMap();
                                //通过路径获取File
                                File file = new File(newPath);
                                //文件名  文件file
                                fileMap.put(name, file);
                                FieldSetEntity fieldSetEntity = new FieldSetEntity();
                                FieldMetaEntity f = new FieldMetaEntity();
                                f.setTableName(new String[]{table});
                                fieldSetEntity.setMeta(f);
                                fieldSetEntity.setValue(field, name);
                                fieldSetEntity.setValue("~field_name~", field);
                                //放入客户uuid
                                fieldSetEntity.setValue("client_uuid", this.clientUUID);
                                rpe.setFiles(fileMap);
                                rpe.setFormData(fieldSetEntity);
                                try {
                                FieldSetEntity fileFse = fileManagerService.uploadFile(rpe);
                                fileUuids.add(fileFse.getString(field));
                                    }catch (Exception e){
                                        e.getStackTrace();
                                        SpringMVCContextHolder.getSystemLogger().error(e);
                                    }
                            }
                        }
                    }
                if(fileUuids != null && fileUuids.size() > 0){
                    filesMap.put(field, fileUuids);
                }
            }
        }
        return filesMap;
    }
 
    /**
     * 同步普通附件方法
     * @param conn 连接
     * @param field 本字段名
     * @param table 本表名
     * @param attachmentsValue 源关联值
     * @return
     */
    public List<String> synchronizeCommonAccessories(Connection conn, String field, String table, String attachmentsValue) {
        //取出附件表数据
        DataTableEntity attachmentsData = this.getOrdinaryAttachments(conn, attachmentsValue);
        if (!BaseUtil.dataTableIsEmpty(attachmentsData)) {
 
            List<String> fileUuids = Lists.newArrayList();
            for (int j = 0; j < attachmentsData.getRows(); j++) {
                //保存名称
                String sa02 = attachmentsData.getString(j, "sa02");
                //显示名称
                String sa03 = attachmentsData.getString(j, "sa03");
                //保存路径
                String sa04 = attachmentsData.getString(j, "sa04");
                String filePath = sa04 + File.separator + sa02;
                String newPath = this.TSPath + File.separator + sa03;
                File isField = new File(newPath);
                //如果已经有该文件   改变文件目录
                Integer fileNum = 0;
                while (isField.exists()){
                    fileNum++;
                    newPath = this.TSPath + fileNum + File.separator + sa03;
                    isField = new File(newPath);
                }
                //复制到临时目录下
                if (feDataDSService.copyFile(filePath, newPath)) {
                    RequestParameterEntity rpe = new RequestParameterEntity();
                    Map<String, File> fileMap = Maps.newHashMap();
                    //通过路径获取File
                    File file = new File(newPath);
                    //文件名  文件file
                    fileMap.put(sa03, file);
                    FieldSetEntity fieldSetEntity = new FieldSetEntity();
                    FieldMetaEntity f = new FieldMetaEntity();
                    f.setTableName(new String[]{table});
                    fieldSetEntity.setMeta(f);
                    fieldSetEntity.setValue(field, sa03);
                    fieldSetEntity.setValue("~field_name~", field);
                    //放入客户uuid
                    fieldSetEntity.setValue("client_uuid", this.clientUUID);
                    rpe.setFiles(fileMap);
                    rpe.setFormData(fieldSetEntity);
                    try {
                        FieldSetEntity fileFse = fileManagerService.uploadFile(rpe);
                        fileUuids.add(fileFse.getString(field));
                    }catch (Exception e){
                        e.getStackTrace();
                        SpringMVCContextHolder.getSystemLogger().error(e);
                    }
 
                    //成功之后删除临时文件
//                    feDataDSService.deleteFile(newPath);
                }
            }
            return fileUuids;
        } else {
            return null;
        }
    }
 
    /**
     * 获取普通附件信息
     *
     * @param value 附件标识
     * @return
     */
    public DataTableEntity getOrdinaryAttachments(Connection conn, String value) {
        DataTableEntity dataTableEntity = null;
        StringBuffer sql = new StringBuffer();
        sql.append(" SELECT * FROM FE_BASE5.SYS_ATTACHMENT WHERE SA01 = ? ");
        dataTableEntity = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new Object[]{value});
        return dataTableEntity;
    }
 
    /**
     * 获取金格附件信息
     *
     * @param value 附件标识
     * @return
     */
    public DataTableEntity getMediaSortInfo(Connection conn, String value) throws Exception {
        DataTableEntity dataTableEntity = null;
        StringBuffer sql = new StringBuffer();
        sql.append(" SELECT * FROM FE_APP5.WF_MEDIA_SORT WHERE WMS02 = ? ");
        dataTableEntity = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new Object[]{value});
        return dataTableEntity;
    }
 
    /**
     * 通过表名获取同步的附件字段
     *
     * @param tableName 表名
     * @return
     */
    public DataTableEntity getTableNameAttachment(Connection conn, String tableName) {
        DataTableEntity dataTableEntity = null;
        String[] names = tableName.split("\\.");
        StringBuffer sql = new StringBuffer();
        sql.append(" SELECT A.SI02,A.SI04 FROM fe_base5.SYS_FACEITEM A FULL JOIN fe_base5.SYS_FACE B ")
                .append(" ON A.SI01 = B.SF00 WHERE B.SF01 = ( SELECT st00 FROM fe_base5.sys_table WHERE st03 = ?) ")
                .append("AND (A.SI02 = 'media' OR A.SI02 = 'attachment') GROUP BY A.SI04,A.SI02 ");
 
        dataTableEntity = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new Object[]{names[1]});
        return dataTableEntity;
    }
 
    /**
     * 通过表id获取同步的附件字段
     *
     * @param tableId 表id
     * @return
     */
    public DataTableEntity getTableFieldAttachment(Connection conn,String tableId) throws Exception {
        DataTableEntity dataTableEntity = null;
        StringBuffer sql = new StringBuffer();
        sql.append(" SELECT A.SI02,A.SI04 FROM fe_base5.SYS_FACEITEM A FULL JOIN fe_base5.SYS_FACE B ")
                .append(" ON A.SI01 = B.SF00 WHERE B.SF01 = ? AND (A.SI02 = 'media' OR A.SI02 = 'attachment') GROUP BY A.SI04,A.SI02 ");
        dataTableEntity = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new Object[]{tableId});
        return dataTableEntity;
    }
 
    public Connection getJDBC() throws SQLException, ClassNotFoundException {
        //获取jdbc连接
//        String diver = "oracle.jdbc.driver.OracleDriver";
//        String url = "jdbc:oracle:thin:@10.0.0.21:1521:orcl";
//        return DataManipulationUtils.getConnection(diver, url, "FE_BASE5", "fe123");
        //获取jdbc连接
        String diver = Global.getSystemConfig("data.synchronism.function.jdbc.diver", "");
        String url = Global.getSystemConfig("data.synchronism.function.jdbc.url", "");
        String name = Global.getSystemConfig("data.synchronism.function.jdbc.name", "");
        String password = Global.getSystemConfig("data.synchronism.function.jdbc.password", "");
        return DataManipulationUtils.getConnection(diver, url, name, password);
    }
 
    /**
     * 迁移"product_sys_datamodel_field 和"product_sys_datamodel_table表
     *
     * @throws SQLException
     */
    public Map<String, String> syncTableField(Connection conn, FieldSetEntity Orlfs, String[] tableName, String subField) throws SQLException {
        Map<String, String> map = Maps.newHashMap();
        FieldSetEntity tableFs = new FieldSetEntity();
        tableFs.setTableName("product_sys_datamodel_table");
        String table_name = Orlfs.getString("st03");
        this.originalTable.put(table_name, table_name.toLowerCase());
        tableFs.setValue("table_name", table_name.toLowerCase());
        tableFs.setValue("table_description", Orlfs.getString("st04"));
        tableFs.setValue("table_primary_key", "uuid");
        tableFs.setValue("table_type", "1");
        tableFs.setValue("created_by", 1);
        tableFs.setValue("created_utc_datetime", new Date());
        tableFs.setValue("sequence", 1);
        baseDao.saveFieldSetEntity(tableFs);
        DataTableEntity Orldt = null;
        try {
            Orldt = BaseDaoServiceImpl.getDataTable(conn, "select a.*,b.DATA_TYPE from SYS_FIELD a LEFT JOIN (select * from all_tab_columns where TABLE_NAME=? and OWNER =?) b on a.SF01=b.COLUMN_NAME where SF00=(select ST00 from SYS_TABLE where ST03=?)", new String[]{tableName[1], tableName[0], tableName[1]});
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            SpringMVCContextHolder.getSystemLogger().error(e);
            throw e;
        }
        DataTableEntity dt = new DataTableEntity();
        String table_uuid = tableFs.getString("uuid");
        //封装源表名与uuid
        originalUuid.put(table_name,table_uuid);
        boolean is_pk = false;
        for (int i = 0; i < Orldt.getRows(); i++) {
            FieldSetEntity rowFs = Orldt.getFieldSetEntity(i);
            FieldSetEntity fieldFs = new FieldSetEntity();
            fieldFs.setTableName("product_sys_datamodel_field");
            fieldFs.setValue("table_uuid", table_uuid);
            //判断字段是否引用了用户字段  或 单位部门字段
            String sf01 = rowFs.getString("sf01");
            // 判断是否是引用数据 是就要转换(如人员id,机构id)
            String length = transformReferenceData(conn, table_name, sf01, fieldFs);
            map.put(sf01.toLowerCase(), sf01.toLowerCase());
            fieldFs.setValue("field_name", sf01.toLowerCase());
            fieldFs.setValue("field_description", rowFs.getString("sf02"));
            fieldFs.setValue("field_show_name", rowFs.getString("sf02"));
            String sf03 = rowFs.getString("sf03");
            String type = this.fieldTypeFE(sf03);
            //是否有字段关联主表
            if ("pk".equals(type)) {
                //如果已经有pk
                if(is_pk){
                    type = "string";
                }else {
                    this.pk = sf01.toLowerCase();
                    is_pk = true;
                }
            }
            fieldFs.setValue("field_type", type);
            if ("GUID".equals(sf03)) {
                fieldFs.setValue("is_unique", 1);
            } else {
                fieldFs.setValue("is_unique", 0);
            }
            if ("NATIVE".equals(sf03)) {
                fieldFs.setValue("NATIVE", 1);
            }
            if ("UNITCODE".equals(sf03)) {
                fieldFs.setValue("UNITCODE", 1);
            }
            //如果是关联主表字段 长度改为64
            if (subField != null && subField.equals(sf01.toLowerCase())) {
                fieldFs.setValue("field_type", "string");
                fieldFs.setValue("field_length", 64);
            } else {
                //如果为附件字段长度500
                if("ATTACHMENT".equals(sf01) || "IMAGE".equals(sf03) || "MEDIA".equals(sf03)){
                    fieldFs.setValue("field_length", 500);
                    //时间字段长度赋0
                }else if("datetime".equals(type)){
                    fieldFs.setValue("field_length",0);
                //多选控件添额外加字段长度
                }else if(!BaseUtil.strIsNull(length)){
                    fieldFs.setValue("field_length",length);
                }else {
                    fieldFs.setValue("field_length", rowFs.getString("sf04"));
                }
            }
            //包含就为附件字段
            if(!BaseUtil.strIsNull(this.attachmentValue) && this.attachmentValue.contains(","+sf01+",")){
                fieldFs.setValue("field_type", "file");
                fieldFs.setValue("field_length", 500);
            }
            //特殊表  附件扩大
            if("FWGZ".equals(table_name) && "FW12".equals(sf01)){
                fieldFs.setValue("field_length", 5000);
            }
            fieldFs.setValue("field_unit", rowFs.getString("sf05"));
            fieldFs.setValue("is_required", 0);
            fieldFs.setValue("is_filter", 0);
            String sf10 = rowFs.getString("sf10");
            if(!BaseUtil.strIsNull(this.masterTableName)) {
                if (!BaseUtil.strIsNull(sf10) && sf10.contains(this.masterTableName)) {
                    fieldFs.setValue("field_type", "parentuuid");
                    fieldFs.setValue("field_relation_table", this.originalUuid.get(this.masterTableName));
                }
            }
            baseDao.saveFieldSetEntity(fieldFs);
            dt.addFieldSetEntity(fieldFs);
        }
 
        //如果没有自增主键  创建一个
        if (!is_pk) {
            //添加自增主键
            FieldSetEntity fieldFs = new FieldSetEntity();
            fieldFs.setTableName("product_sys_datamodel_field");
            fieldFs.setValue("table_uuid", table_uuid);
            fieldFs.setValue("field_name", tableFs.getString("table_name") + "_id");
            fieldFs.setValue("field_description", "自增主键");
            fieldFs.setValue("field_type", "pk");
            fieldFs.setValue("field_length", 11);
            fieldFs.setValue("is_required", 0);
            fieldFs.setValue("is_unique", 1);
            fieldFs.setValue("is_international", 0);
            fieldFs.setValue("created_by", 1);
            fieldFs.setValue("created_utc_datetime", new Date());
            fieldFs.setValue("field_show_name", "自增主键");
            baseDao.saveFieldSetEntity(fieldFs);
            dt.addFieldSetEntity(fieldFs);
        }
        //添加uuid唯一标识
        FieldSetEntity fieldFs = new FieldSetEntity();
        fieldFs.setTableName("product_sys_datamodel_field");
        fieldFs.setValue("table_uuid", table_uuid);
        fieldFs.setValue("field_name", "uuid");
        fieldFs.setValue("field_description", "唯一标识");
        fieldFs.setValue("field_type", "string");
        fieldFs.setValue("field_length", 80);
        fieldFs.setValue("field_unit", 0);
        fieldFs.setValue("is_required", 0);
        fieldFs.setValue("is_unique", 0);
        fieldFs.setValue("is_international", 0);
        fieldFs.setValue("created_by", 1);
        fieldFs.setValue("created_utc_datetime", new Date());
        fieldFs.setValue("field_show_name", "唯一标识");
 
        baseDao.saveFieldSetEntity(fieldFs);
        dt.addFieldSetEntity(fieldFs);
        //创建表方法
        StringBuilder createStatement = createTable(createFields(dt), Orlfs.getString("st03"), Orlfs.getString("st04"));
        //创建表方法
        execute(createStatement.toString());
        return map;
    }
 
    /**
     * //迁移 wf_model流程模块表
     *
     * @param conn
     * @throws SQLException
     */
    public String syncModel(String tricode_funs, Connection conn, String module_uuid, String sf28, String org_level_uuid, int created_by, String typeCode,boolean flag) throws SQLException {
        FieldSetEntity Orlfs = null;
        try {
            //通过
            Orlfs = BaseDaoServiceImpl.getFieldSet(conn, "fe_base5.wf_model", " wm05=(SELECT se16  FROM fe_base5.SYS_EVENT where se01=? and se08 = 1) ", new Object[]{tricode_funs
            });
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            SpringMVCContextHolder.getSystemLogger().error(e);
            throw e;
        }
        if (Orlfs == null) {
            //通过
            Orlfs = BaseDaoServiceImpl.getFieldSet(conn, "fe_base5.wf_model", " WM04 = ? ", new Object[]{sf28});
            if(Orlfs == null){
                return null;
            }
        }
        FieldSetEntity modelFs = new FieldSetEntity();
        //flow流程表
        modelFs.setTableName("product_sys_flow_model");
        //名称
        modelFs.setValue("title", Orlfs.getString("wm01"));
        //描述
        modelFs.setValue("flow_model_describe", Orlfs.getString("wm02"));
        //关联模块表
        modelFs.setValue("module_uuid", module_uuid);
        //流程关联主表名称
        String wm04 = Orlfs.getString("wm04");
        //流程表没有就从功能表里面查询
        if (BaseUtil.strIsNull(wm04) || wm04.indexOf(".") == -1) {
            try {
                //通过
                FieldSetEntity funFse = BaseDaoServiceImpl.getFieldSet(conn, "fe_base5.SYS_FUNCTION", "  SF05 = ? ", new Object[]{tricode_funs});
                wm04 = funFse.getString("sf28");
                if (BaseUtil.strIsNull(wm04) || wm04.indexOf(".") == -1) {
                    return null;
                }
            } catch (Exception e) {
                DataManipulationUtils.close(null, null, conn);
                SpringMVCContextHolder.getSystemLogger().error(e);
                throw e;
            }
            //如果功能表和流程表绑定的数据表不相同  以流程表为主
        } else if (!wm04.equals(sf28)) {
            String[] wm04s = wm04.split("\\.");
            try {
                this.syncTable(wm04s, false, null, conn);
            }catch (Exception e){
                e.getStackTrace();
                SpringMVCContextHolder.getSystemLogger().error(e);
            }
 
        }
 
        String[] wm04s = wm04.split("\\.");
        //主表表名
        modelFs.setValue("table_uuid",this.originalTable.getString(wm04s[1]));
        //生成uuid
        if(BaseUtil.strIsNull(typeCode)){
            typeCode = UUID.randomUUID().toString();
        }
        modelFs.setValue("type_code", typeCode);
 
        modelFs.setValue("org_level_uuid", org_level_uuid);
        modelFs.setValue("created_by", created_by);
        modelFs.setValue("created_utc_datetime", new Date());
 
        String modelUuid = baseDao.add(modelFs);
        //wm05 为流程编码    查询存有编码的mvc页面   改为流程uuid
        String wm05 = Orlfs.getString("wm05");
        FieldSetEntity mvcPageFse = baseDao.getFieldSetEntityByFilter("product_sys_mvc_page", " flow_uuid = ?", new String[]{wm05}, false);
        if (mvcPageFse != null) {
            //mvc页面绑定流程uuid
            mvcPageFse.setValue("flow_uuid", typeCode);
            baseDao.update(mvcPageFse);
        }
 
 
        String wm00 = Orlfs.getString("wm00");
        //迁移WF_NODES 流程节点表
        JSONObject nodesUUID = this.syncNodes(wm00, conn, modelUuid);
        //迁移WF_NODES 流程节点表 到"product_sys_flow_processor 处理器迁移
        this.syncProcessor(wm00, conn, modelUuid);
        //迁移WF_LINKS
        this.syncLinks(wm00, conn, modelUuid);
        if(flag) {
            try {
                //迁移 WF_TASK
                Map<String, FieldSetEntity> taskFseMap = this.syncTask(tricode_funs, conn, modelUuid);
                //迁移wf_infor 节点任务处理情况表
                Map<String, String> stateMap = this.syncDetail(tricode_funs, conn, nodesUUID, sf28, modelUuid, taskFseMap);
                //同步消息
                try {
                    this.synchronizingProcessMessages(conn, tricode_funs, stateMap);
                } catch (BaseException e) {
                    e.printStackTrace();
                    SpringMVCContextHolder.getSystemLogger().error(e);
                }
            }catch (Exception e){
                e.getStackTrace();
                SpringMVCContextHolder.getSystemLogger().error(e);
            }
        }
        return typeCode;
    }
 
    /**
     * 迁移 flow处理器
     *
     * @throws SQLException
     */
    public void syncProcessor(String wm00, Connection conn, String modelUUID) throws SQLException {
        DataTableEntity OrlDt = null;
        try {
            OrlDt = BaseDaoServiceImpl.getDataTable(conn, "fe_base5.wf_nodes", " WN01= ? and WN04 ='5'", new Object[]{wm00
            });
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            SpringMVCContextHolder.getSystemLogger().error(e);
            throw e;
        }
        for (int i = 0; i < OrlDt.getRows(); i++) {
            FieldSetEntity Orlfs = OrlDt.getFieldSetEntity(i);
            FieldSetEntity processorFs = new FieldSetEntity();
            // flow处理器
            processorFs.setTableName("product_sys_flow_processor");
            processorFs.setValue("created_by", 1);
            processorFs.setValue("created_utc_datetime", new Date());
            //标题
            processorFs.setValue("title", Orlfs.getString("wn02"));
            //类型:1-java,2-sql     WN47   1 sql   2 java
            processorFs.setValue("processor_type", Orlfs.getInteger("wn47") == 1 ? 2 : 1);
            //详细内容
            processorFs.setValue("content", Orlfs.getString("wn48"));
            //关联"product_sys_flow_model
            processorFs.setValue("flow_uuid", modelUUID);
            //坐标,节点到上边界的垂直距离
            processorFs.setValue("location_top", Orlfs.getInteger("wn38") + "px");
            //坐标,节点到左边界的垂直距离
            processorFs.setValue("location_left", Orlfs.getInteger("wn37") + "px");
            String uuid = baseDao.add(processorFs);
            //顺序号
            nodesIdUUID.put(Orlfs.getString("wn00"), uuid);
        }
    }
 
    /**
     * 同步流程节点
     * @param wm00 流程主表id
     * @param conn
     * @param modelUUID 模块uuid
     * @return
     * @throws SQLException
     */
    public JSONObject syncNodes(String wm00, Connection conn, String modelUUID) throws SQLException {
        DataTableEntity OrlDt = null;
        try {
            OrlDt = BaseDaoServiceImpl.getDataTable(conn, "fe_base5.wf_nodes", " WN01 = ? and WN04 !='5' ", new Object[]{wm00
            });
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            SpringMVCContextHolder.getSystemLogger().error(e);
            throw e;
        }
        JSONObject map = new JSONObject();
        nodesIdUUID = new JSONObject();
        try{
            for (int i = 0; i < OrlDt.getRows(); i++) {
                FieldSetEntity Orlfs = OrlDt.getFieldSetEntity(i);
                FieldSetEntity nodeFs = new FieldSetEntity();
 
 
    //            WN62 关联表单字段  WN63 1 人员  2岗位
                //flow节点表
                nodeFs.setTableName("product_sys_flow_node");
                //创建人
                nodeFs.setValue("created_by", 1);
                //创建时间
                nodeFs.setValue("created_utc_datetime", new Date());
                //标题
                nodeFs.setValue("title", Orlfs.getString("wn02"));
                //描述
                nodeFs.setValue("flow_node_describe", Orlfs.getString("wn03"));
                //组件类型:1-开始节点,2-处理节点,0-结束节点
                //1开始 99结束; 3普通 4子任务  5处理器 6或处理7与处理8 会签
                String module_type = "2";
                if ("1".equals(Orlfs.getString("wn04"))) {
                    module_type = "1";
                } else if ("99".equals(Orlfs.getString("wn04"))) {
                    module_type = "0";
                }
                nodeFs.setValue("module_type", module_type);
                //是否多人处理
                String wn26 = Orlfs.getString("wn26");
                nodeFs.setValue("is_multiperson", wn26);
                if ("1".equals(wn26)) {
                    //处理类型
                    String wn25 = Orlfs.getString("wn25");
                    // 类型:0-等待处理,1-竞争处理,2-顺序处理 先A 后b  。。。下一个节点
                    //  WN25 0 无  1多人办理等待   2 竞争处理
                    if (!BaseUtil.strIsNull(wn25)) {
                        if ("2".equals(wn25)) {
                            nodeFs.setValue("deal_type", 1);
                        } else {
                            nodeFs.setValue("deal_type", 0);
                        }
                    }
                } else if ("0".equals(wn26)) {
                    nodeFs.setValue("deal_type", 0);
                }
 
                //默认送直属领导
                nodeFs.setValue("is_default_direct_supervisor", Orlfs.getString("wn34"));
                //是否允许加签
                nodeFs.setValue("is_allow_add", Orlfs.getString("wn15"));
                //是否允许退回
                nodeFs.setValue("is_allow_back", Orlfs.getString("wn13"));
 
                //wn48 结束节点调用的方法
                String wn48 = Orlfs.getString("wn48");
                if (!BaseUtil.strIsNull(wn48)) {
                    //其他消息推送方法,调用java代码   暂存于此
                    nodeFs.setValue("msg_push_sp_func", wn48);
                }
                //节点权限关联表单字段同步
                //WN62 关联表单字段
                String wn62 = Orlfs.getString("wn62");
                if (!BaseUtil.strIsNull(wn62)) {
                    //WN63 1 人员  2岗位
                    String wn63 = Orlfs.getString("wn63");
                    if (BaseUtil.strIsNull(wn63)) {
                        if ("1".equals(wn63)) {
                            //人员
                            nodeFs.setValue("default_form_field_user", wn62.toLowerCase());
                        } else {
                            //岗位
                            nodeFs.setValue("default_form_field_post", wn62.toLowerCase());
                        }
                    }
                }
                //获取人员岗位单位部门   存入流程节点的人员 岗位 单位部门权限设置
                Map<String, String> map1 = this.syncNodeInstitutions(conn,Orlfs);
                if (map1 != null && map1.size() > 0) {
                    String userSet = map1.get("userSet");
                    //人员id
                    if (!BaseUtil.strIsNull(userSet)) {
                        nodeFs.setValue("default_users", userSet);
                    }
                    String postSet = map1.get("postSet");
                    //岗位uuid
                    if (!BaseUtil.strIsNull(postSet)) {
                        nodeFs.setValue("default_posts", postSet);
                    }
                    String deptSet = map1.get("deptList");
                    //单位部门uuid
                    if (!BaseUtil.strIsNull(deptSet)) {
                        nodeFs.setValue("default_depts", deptSet);
                    }
                }
                //需要在数据源表里面插入一个部门  所有直接关联单位都改为这个部门
                //坐标,节点到上边界的垂直距离
                nodeFs.setValue("location_top", Orlfs.getInteger("wn38") + "px");
                //坐标,节点到左边界的水平距离
                nodeFs.setValue("location_left", Orlfs.getInteger("wn37") + "px");
                //关联"product_sys_flow_model
                nodeFs.setValue("flow_uuid", modelUUID);
                //关联附件
                nodeFs.setValue("node_attachment_upload", 1);
                //下载附件
                nodeFs.setValue("node_attachment_download", 0);
                //预览附件
                nodeFs.setValue("node_attachment_preview", 1);
                //允许打印
                nodeFs.setValue("allow_print", 1);
                //如果有附件字段 添加下载预览权限
                if(!BaseUtil.strIsNull(this.attachmentValue)){
                    //允许删除
                    nodeFs.setValue("allow_delete", 0);
                    //允许下载
                    nodeFs.setValue("allow_download", 1);
                    //允许预览
                    nodeFs.setValue("allow_preview", 1);
                    //附件字段
                    String field = this.attachmentValue.substring(1,this.attachmentValue.length()-1);
                    nodeFs.setValue("editable_field", field.toLowerCase());
                }
                String uuid = baseDao.add(nodeFs);
                //节点唯一号
                map.put(Orlfs.getString("wn53"), uuid);
                //顺序号
                nodesIdUUID.put(Orlfs.getString("wn00"), uuid);
            }
        }catch (BaseException e){
            e.printStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
        }
        return map;
    }
 
    /**
     * 同步节点配置的组织架构
     *
     * @param fieldSetEntity
     */
    public Map<String, String> syncNodeInstitutions(Connection conn,FieldSetEntity fieldSetEntity) {
        String wn00 = fieldSetEntity.getString("wn00");
        DataTableEntity OrlDt = null;
        try {
            OrlDt = BaseDaoServiceImpl.getDataTable(conn, "fe_base5.WF_ROLES", " WR01 = ? ", new Object[]{wn00});
        } catch (Exception e) {
            e.getStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
        }
        if (BaseUtil.dataTableIsEmpty(OrlDt)) {
            return null;
        }
        //用户
        Set<String> userSet = Sets.newHashSet();
        //部门
        Set<String> deptSet = Sets.newHashSet();
        //岗位
        Set<String> postSet = Sets.newHashSet();
        for (int i = 0; i < OrlDt.getRows(); i++) {
            FieldSetEntity fse = OrlDt.getFieldSetEntity(i);
            String wr04 = fse.getString("wr04");
            String wr03 = fse.getString("wr03");
            //用户
            if ("X".equals(wr04)) {
                userSet.add(wr03);
                //角色 岗位
            } else if ("Y".equals(wr04)) {
                postSet.add(wr03);
                //机构
            } else if ("Z".equals(wr04)) {
                deptSet.add(wr03);
            }
        }
        Map<String, String> map = Maps.newHashMap();
        //查询人员
        if (userSet.size() > 0) {
            DataTableEntity staffData = baseDao.listTable("product_sys_staffs", BaseUtil.buildQuestionMarkFilter("remark", userSet.toArray(), true));
            if (!BaseUtil.dataTableIsEmpty(staffData)) {
                userSet.clear();
                for (int i = 0; i < staffData.getRows(); i++) {
                    userSet.add(staffData.getString(i, "user_id"));
                }
                map.put("userSet", StringUtils.join(userSet, ","));
            }
        }
        //查询岗位
        if (postSet.size() > 0) {
            DataTableEntity postData = baseDao.listTable("product_sys_job_posts", BaseUtil.buildQuestionMarkFilter("sequence", postSet.toArray(), true));
            if (!BaseUtil.dataTableIsEmpty(postData)) {
                //如果岗位uuid总计超过2000就取出岗位下的人
                if((postData.getRows() * 37) > 2000){
                  DataTableEntity staffData = baseDao.listTable(" SELECT a.user_id FROM product_sys_staffs a LEFT JOIN product_sys_job_posts b on a.job_post_uuid = b.uuid where " +  BaseUtil.buildQuestionMarkFilter("b.sequence", postSet.toArray(), true), new String[]{});
                    postSet.clear();
                    if(!BaseUtil.dataTableIsEmpty(staffData)) {
                        for (int i = 0; i < staffData.getRows(); i++) {
                            userSet.add(staffData.getString(i, "user_id"));
                        }
                        map.put("userSet", StringUtils.join(userSet, ","));
                    }
                }else {
                    postSet.clear();
                    for (int i = 0; i < postData.getRows(); i++) {
                        postSet.add(postData.getString(i, "uuid"));
                    }
                    map.put("postSet", StringUtils.join(postSet, ","));
                }
            }
        }
        //查询机构(单位部门)
        if (deptSet.size() > 0) {
            DataTableEntity orgData = baseDao.listTable("product_sys_org_levels", BaseUtil.buildQuestionMarkFilter("sequence", deptSet.toArray(), true));
            if (!BaseUtil.dataTableIsEmpty(orgData)) {
                deptSet.clear();
                for (int i = 0; i < orgData.getRows(); i++) {
                    deptSet.add(orgData.getString(i, "uuid"));
                }
                map.put("deptSet", StringUtils.join(deptSet, ","));
            }
        }
        return map;
    }
 
    /**
     * @param conn
     * @param UUIDMap   流程节点node表fe uuid 对应 产品uuid
     * @param tableName 表名
     * @return
     * @throws SQLException
     */
    public Map<String, String> syncDetail(String tricode_funs, Connection conn, JSONObject UUIDMap, String tableName, String modelUUID, Map<String, FieldSetEntity> taskFseMap) throws SQLException {
        tableName = tableName.split("\\.")[1];
        OrgIdUUIDmap = Maps.newHashMap();
        DataTableEntity OrlDt = null;
 
        try {
            StringBuffer sql = new StringBuffer();
            sql.append(" SELECT * FROM fe_base5.wf_infor where WI01 in (SELECT WT00 FROM fe_base5.wf_task where WT13= " +
                    "(SELECT se16 FROM fe_base5.SYS_EVENT WHERE SE08 = 1 AND SE01 = ?))  ORDER BY WI01,WI00 ");
            OrlDt = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new String[]{tricode_funs});
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            SpringMVCContextHolder.getSystemLogger().error(e);
            throw e;
        }
        Map<String, String> stateMap = Maps.newHashMap();
        DataTableEntity DetailData = new DataTableEntity();
        FieldMetaEntity f = new FieldMetaEntity();
        f.setTableName(new String[]{"product_sys_flow_detail"});
        DetailData.setMeta(f);
        for (int i = 0; i < OrlDt.getRows(); i++) {
            FieldSetEntity Orlfs = OrlDt.getFieldSetEntity(i);
            FieldSetEntity DetailFs = new FieldSetEntity();
            //flow明细表
            DetailFs.setTableName("product_sys_flow_detail");
 
            if (null == Orlfs.getString("wi02")) {
                //标题
                DetailFs.setValue("title", "无标题");
            } else {
                DetailFs.setValue("title", Orlfs.getString("wi02"));
            }
            String wi00 = Orlfs.getString("wi00");
            //id一致
            DetailFs.setValue("id",  wi00);
            //节点名称
            DetailFs.setValue("node_title", Orlfs.getString("wi04"));
            //预期处理人
            DetailFs.setValue("expect_person", userIdJson.getString(Orlfs.getString("wi05")));
            //接收时间
            Date wi08 = Orlfs.getDate("wi08");
            DetailFs.setValue("accept_time",wi08);
            //创建时间
            DetailFs.setValue("created_utc_datetime", wi08);
            String wi12 = userIdJson.getString(Orlfs.getString("wi12"));
            //实际处理人
            DetailFs.setValue("actual_person", wi12);
            //修改人为实际处理人
            DetailFs.setValue("updated_by", wi12);
            //处理时间
            Date wi11 = Orlfs.getDate("wi11");
            DetailFs.setValue("deal_time",wi11);
            DetailFs.setValue("updated_utc_datetime", wi11);
            //节点标识(0-普通,1-加签,2-退回)
            DetailFs.setValue("node_sign", 0);
            String node_uuid = UUIDMap.getString(Orlfs.getString("wi62"));
            if (BaseUtil.strIsNull(node_uuid)) {
                continue;
            }
            //源uuid,关联本表
            String wi14 = Orlfs.getString("wi14");
            //为空表示没有上一级节点
            if(BaseUtil.strIsNull(wi14)){
                if(i > 0){
                  FieldSetEntity priorFes = OrlDt.getFieldSetEntity(i - 1);
                  String priorWi00 = priorFes.getString("wi00");
                  FieldSetEntity priorFieldSet = OrgIdUUIDmap.get(priorWi00);
                  if(priorFieldSet != null){
                      FieldSetEntity taskFse = taskFseMap.get(priorFes.getString("wi01"));
                      if(taskFse != null){
                          taskFse.setValue("cur_node_uuid",  node_uuid);
                          //添加当前节点记录
                          baseDao.update(taskFse);
                      }
                  }
                }
            }else {
                FieldSetEntity fieldSetEntity = OrgIdUUIDmap.get(wi14);
                if (fieldSetEntity != null) {
                    DetailFs.setValue("source_uuid", fieldSetEntity.getUUID());
                }
            }
            //创建人 上个节点处理人
            DetailFs.setValue("created_by", userIdJson.getString(Orlfs.getString("wi15")));
 
            //关联节点表
            DetailFs.setValue("node_uuid", node_uuid);
            //预期处理时间(小时)
            DetailFs.setValue("expect_deal_time", Orlfs.getString("wi09"));
            //完成标识(0-未收,1-已收未办,2-已办,3-终止,4-竞争失败)
//            DetailFs.setValue("node_deal_sign", nodeDealType(Orlfs.getString("wi07")));
            //办理状态(0-未收,1-已收未办,2-已办,3-终止,4-竞争失败)
            String nodeState = nodeDealType(Orlfs.getString("wi13"));
            DetailFs.setValue("node_deal_sign", nodeState);
            //意见
            String wi20 = Orlfs.getString("wi20");
            if("2".equals(nodeState)) {
                if(BaseUtil.strIsNull(wi20)){
                    DetailFs.setValue("opinion", "已阅");
                }else {
                    DetailFs.setValue("opinion", wi20);
                }
                //添加签名
                String sign = userIdSignature.getString(wi12);
                DetailFs.setValue("sign_attachment_uuid", sign);
            }
            //关联表
            DetailFs.setValue("table_name", this.originalTable.getString(tableName));
            //关联业务UUID
            DetailFs.setValue("record_uuid", this.pxMap.getString(tableName + Orlfs.getString("wi29")));
            //关联流程表uuid
            DetailFs.setValue("flow_uuid", modelUUID);
            FieldSetEntity taskFse =  taskFseMap.get(Orlfs.getString("wi01"));
            if(taskFse == null){
                continue;
            }
            String attachmentsValue = Orlfs.getString("attachment");
            //如果附件字段有值  同步附件
            if(!BaseUtil.strIsNull(attachmentsValue)){
                List<String> fileUuids = this.synchronizeCommonAccessories(conn, "flow_attachment", DetailFs.getTableName(), attachmentsValue);
                //存入附件uuid
                DetailFs.setValue("flow_attachment", StringUtils.join(fileUuids, ","));
            }
            //关联流程任务表
            DetailFs.setValue("task_uuid", taskFse.getUUID());
            baseDao.add(DetailFs);
            OrgIdUUIDmap.put(wi00, DetailFs);
            stateMap.put(wi00, nodeState);
        }
        return stateMap;
    }
 
 
    /**
     * 查询流程消息表
     * @param conn
     * @param tricode_funs
     * @param stateMap
     * @throws SQLException
     */
    public void synchronizingProcessMessages(Connection conn,String tricode_funs, Map<String, String> stateMap) throws SQLException {
        try {
            StringBuffer sql = new StringBuffer();
            sql.append(" SELECT * FROM FE_BASE5.MESSAGEINFOR WHERE ME14 IN ( ")
                    .append("SELECT WI00 FROM fe_base5.wf_infor where WI01 in (SELECT WT00 FROM fe_base5.wf_task where WT13= ")
                    .append("(SELECT se16 FROM fe_base5.SYS_EVENT WHERE SE08 = 1 AND SE01 = ?))) ORDER BY ME14");
 
            DataTableEntity OrlDt = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new String[]{tricode_funs});
            if(!BaseUtil.dataTableIsEmpty(OrlDt)) {
                this.synchronizingProcessMessages(OrlDt, stateMap,"product_sys_flow_detail");
            }
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            SpringMVCContextHolder.getSystemLogger().error(e);
            throw e;
        }
 
    }
 
    /**
     *     同步流程消息表
     */
    public void synchronizingProcessMessages(DataTableEntity OrlDt, Map<String, String> stateMap, String tableName){
        String id = null;
        String message_uuid = null;
        String state = null;
        DataTableEntity dataTableEntity = new DataTableEntity();
        FieldMetaEntity f = new FieldMetaEntity();
        f.setTableName(new String[]{"product_sys_message"});
        dataTableEntity.setMeta(f);
        for (int i = 0; i < OrlDt.getRows(); i++) {
            FieldSetEntity fs = OrlDt.getFieldSetEntity(i);
            //流程节点id
            String me14 = fs.getString("me14");
            String sendUserId;
            //业务uuid
            FieldSetEntity fieldSet = OrgIdUUIDmap.get(fs.getString("me14"));
            String source_uuid = null;
            if(fieldSet != null){
                source_uuid = fieldSet.getUUID();
            }else {
                continue;
            }
            //相同说明是同一消息  发送多个人
            if(!me14.equals(id)){
                //不一样创建消息主表
                id = me14;
                FieldSetEntity message = new FieldSetEntity();
                //消息主表
                message.setTableName("product_sys_message");
                //消息主题
                message.setValue("title", fs.getString("me01"));
                //消息内容
                message.setValue("content", fs.getString("me02"));
                //是否需要发送邮件
                message.setValue("is_send_mail", 0);
                //消息类型21 流程消息都为任务消息
                message.setValue("message_type", 21);
                //是否需要发送短信 0不发;1为强制;2为被动
                message.setValue("is_send_sms","0".equals(fs.getString("me20")) ? 0:1);
                //发送时间
                String me07 = fs.getString("me07");
                message.setValue("send_time", me07);
                //创建时间
                message.setValue("created_utc_datetime", me07);
                //发送人
                sendUserId = userIdJson.getString(fs.getString("me03"));
                if(BaseUtil.strIsNull(sendUserId)){
                    //流程infor 数据创建人为发送人
                    sendUserId  = fieldSet.getString("created_by");
                    if(BaseUtil.strIsNull(sendUserId)){
                        continue;
                    }
                }
                message.setValue("send_user_id", sendUserId);
                //创建人及发送人
                message.setValue("created_by", sendUserId);
                //    业务表
                message.setValue("source_table", tableName);
 
                message.setValue("source_uuid",source_uuid);
                //url 业务地址
                //获取当前节点状态
                state = stateMap.get(fs.getString("me14"));
                //办理页面
                if("0".equals(state) || "1".equals(state)){
                    message.setValue("url", "162132180172861usZ0N439?uuid="+source_uuid);
                    //查询原文页面
                }else if("2".equals(state)){
                    message.setValue("url", "1621321824686868oKWL726?uuid="+source_uuid);
                }
                message_uuid = baseDao.add(message);
            }
 
            FieldSetEntity message_user = new FieldSetEntity();
            message_user.setTableName("product_sys_message_user");
            //关联lx_sys_message表UUID
            message_user.setValue("message_uuid", message_uuid);
            //mail_send    是否发送邮件
            message_user.setValue("mail_send", 0);
            //     是否阅读  节点状态为未读
            //0未读
            if("0".equals(state)){
                message_user.setValue("read_type", 0);
            }else {
                message_user.setValue("read_type", 1);
            }
            //read_time    阅读时间 暂时为空
 
            //receive_time    接收时间 无字段
            //sms_send    是否发送短信
            message_user.setValue("sms_send", 0);
            //user_id    消息接收人
            String user_id = userIdJson.getString(fs.getString("me05"));
            //找不到发送人就放接收人
            if(BaseUtil.strIsNull(user_id)){
                user_id = userIdJson.getString(fs.getString("me03"));
                if(BaseUtil.strIsNull(user_id)){
                    continue;
                }
            }
            message_user.setValue("user_id",user_id);
            dataTableEntity.addFieldSetEntity(message_user);
            if(dataTableEntity.getRows() == 1000){
                baseDao.add(dataTableEntity);
                dataTableEntity = new DataTableEntity();
                dataTableEntity.setMeta(f);
            }
        }
        if(!BaseUtil.dataTableIsEmpty(dataTableEntity)) {
            baseDao.add(dataTableEntity);
        }
    }
 
 
    //迁移WF_LINKS  连线表
    public void syncLinks(String wm00, Connection conn, String modelUUID) throws SQLException {
        DataTableEntity OrlDt = null;
        try {
            StringBuilder sql = new StringBuilder();
            sql.append("select a.WL04 WL04,a.WL05 WL05,a.WL06 WL06,(SELECT WN04 FROM fe_base5.WF_NODES where WN00=a.WL05) source_type,");
            sql.append("(select wa01 from fe_base5.WF_ACTION  where wa00=a.WL03) WL03S,(SELECT WN04 FROM fe_base5.WF_NODES where WN00=(select wa01 from fe_base5.WF_ACTION  where wa00=a.WL03)) ");
            sql.append(" target_type from fe_base5.wf_links a  where WL05 in (select wn00 from fe_base5.wf_nodes where WN01= ? )");
 
            OrlDt = BaseDaoServiceImpl.getDataTable(conn, sql.toString(), new Object[]{wm00
            });
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            SpringMVCContextHolder.getSystemLogger().error(e);
            throw e;
        }
        for (int i = 0; i < OrlDt.getRows(); i++) {
            FieldSetEntity Orlfs = OrlDt.getFieldSetEntity(i);
            FieldSetEntity linksFs = new FieldSetEntity();
            linksFs.setTableName("product_sys_flow_link");
            linksFs.setValue("created_by", 1);
            linksFs.setValue("created_utc_datetime", new Date());
            //标题
            linksFs.setValue("title", Orlfs.getString("wl04"));
            //连线起始位置uuid"product_sys_flow_node uuid 若为空则跳过
            if(Orlfs.getString("wl03s") == null){
                continue;
            }
            linksFs.setValue("source_uuid", nodesIdUUID.getString(Orlfs.getString("wl03s")));
            //连线起点类型:1-节点,2-处理器
            linksFs.setValue("source_type", "5".equals(Orlfs.getString("target_type")) ? 2 : 1);
            //连线截止位置uuid"product_sys_flow_node uuid
            linksFs.setValue("target_uuid", nodesIdUUID.getString(Orlfs.getString("wl05")));
            //连线截止类型:1-节点,2-处理器
            linksFs.setValue("target_type", "5".equals(Orlfs.getString("source_type")) ? 2 : 1);
            //线的判定条件
            linksFs.setValue("judge", Orlfs.getString("wl06"));
            //关联"product_sys_flow_model
            linksFs.setValue("flow_uuid", modelUUID);
            baseDao.add(linksFs);
        }
    }
 
    /**
     * 通过数据源表序列号   获取当前员工user_id
     */
//    public Integer getUserId(Integer id){
//        FieldSetEntity userFse = baseDao.getFieldSetEntityByFilter("product_sys_staffs", " remark = ? ",new Integer[]{id},false);
//        if(userFse == null){
//            return null;
//        }
//        return userFse.getInteger("user_id");
//    }
 
    /**
     * 同步task 表
     *
     * @param conn
     * @param modelUUID 流程模块uuid
     * @return
     * @throws SQLException
     */
    public Map<String, FieldSetEntity> syncTask(String tricode_funs, Connection conn, String modelUUID) throws SQLException,BaseException {
        DataTableEntity OrlDt = null;
        try {
            OrlDt = BaseDaoServiceImpl.getDataTable(conn, "fe_base5.WF_TASK", "WT13=(SELECT se16  FROM fe_base5.SYS_EVENT where se01=? and se08 = 1)", new Object[]{tricode_funs
            });
        } catch (Exception e) {
            DataManipulationUtils.close(null, null, conn);
            SpringMVCContextHolder.getSystemLogger().error(e);
            throw e;
        }
        Map<String, FieldSetEntity> map = Maps.newHashMap();
 
        for (int i = 0; i < OrlDt.getRows(); i++) {
            FieldSetEntity Orlfs = OrlDt.getFieldSetEntity(i);
            FieldSetEntity taskFs = new FieldSetEntity();
            taskFs.setTableName("product_sys_flow_task");
            if (null == Orlfs.getString("wt05")) {
                //标题
                taskFs.setValue("title", "无标题");
            } else {
                taskFs.setValue("title", Orlfs.getString("wt05"));
            }
            // 发起人
            //wt07用户id  获取用户id
            String id = userIdJson.getString(Orlfs.getString("wt07"));
            //发送人为空   就跳过
            if (id == null) {
                continue;
            }
            taskFs.setValue("sender", id);
            //发起时间
            Date wt09 = Orlfs.getDate("wt09");
            taskFs.setValue("send_time", wt09);
            //结束时间
            taskFs.setValue("finish_time", Orlfs.getDate("wt10"));
            //关联流程表
            taskFs.setValue("flow_uuid", modelUUID);
            //完成标识(1-在办,2-正常结束,3-终止)
            taskFs.setValue("finish_type", this.finishType(Orlfs.getString("wt16")));
            //关联表
            String tbName = Orlfs.getString("wt03").split("\\.")[1];
 
            taskFs.setValue("table_name", this.originalTable.getString(tbName));
            //当前环节节点uuid
            taskFs.setValue("id", Orlfs.getString("wt00"));
            //关联业务UUID
            String record_uuid = pxMap.getString(tbName + Orlfs.getString("wt04"));
            if (BaseUtil.strIsNull(record_uuid)) {
                continue;
            }
            taskFs.setValue("record_uuid", record_uuid);
            taskFs.setValue("created_by", id);
            taskFs.setValue("created_utc_datetime", wt09);
            baseDao.add(taskFs);
            map.put(Orlfs.getString("wt00"), taskFs);
        }
        return map;
    }
 
    /**
     * 创建表语句
     *
     * @param sb
     * @param table_name
     * @param table_description
     * @return
     * @throws BaseException
     */
    private StringBuilder createTable(StringBuilder sb, String table_name, String table_description) throws BaseException {
        StringBuilder createStatement = new StringBuilder();
        createStatement.append(" create table `" + table_name + "` ( ");
        createStatement.append("\n");
        createStatement.append(sb);
        createStatement.append("\n");
        createStatement.append(" ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='" + table_description + "'");
        return createStatement;
    }
 
    /**
     * 组装字段信息
     *
     * @param dt
     * @throws BaseException
     */
    private StringBuilder createFields(DataTableEntity dt) throws BaseException {
        StringBuilder table = new StringBuilder();
        if (!BaseUtil.dataTableIsEmpty(dt)) {
            for (int i = 0; i < dt.getRows(); i++) {
                FieldSetEntity fse = dt.getFieldSetEntity(i);
                //字段类型
                String field_type = fse.getString(CmnConst.FIELD_TYPE);
                //字段名
                String field_name = fse.getString(CmnConst.FIELD_NAME);
                //字段描述
                String field_description = fse.getString(CmnConst.FIELD_DESCRIPTION);
                //字段长度
                Integer field_length = fse.getInteger(CmnConst.FIELD_LENGTH);
                //小数位数
                Integer field_unit = fse.getInteger(CmnConst.FIELD_UNIT);
                //是否必填
                Boolean is_required = fse.getBoolean(CmnConst.IS_REQUIRED);
                //是否唯一
                Boolean is_unique = fse.getBoolean(CmnConst.IS_UNIQUE);
 
                //是否为主键
                Boolean is_primary_key = "pk".equals(field_type) ? true : false;
                String field = newField(field_name, field_description, field_type, is_required, field_length, field_unit, is_primary_key, is_unique);
                if (table.length() > 0) {
                    table.append(",\n\t");
                }
                table.append(field);
            }
        }
        return table;
    }
 
    /**
     * 新字段组装
     *
     * @param field_name        字段名称
     * @param field_description 字段描述
     * @param field_type        字段类型
     * @param is_required       是否必填
     * @param field_length      字段长度
     * @param field_unit        小数长度
     * @param is_primary_key    是否自增主键
     * @param is_unique         是否唯一
     * @return
     */
    private String newField(String field_name, String field_description, String field_type, boolean is_required, Integer field_length, Integer field_unit, boolean is_primary_key, boolean is_unique) {
        StringBuilder sql = new StringBuilder();
        sql.append(" `" + field_name + "` ");
        sql.append(" " + fieldType(field_type));
        sql.append(" (" + field_length);
        if ("decimal".equals(field_type) && field_unit != null && field_unit > 0) {
            sql.append("," + field_unit);
        }
        sql.append(") " + (!is_required && !is_primary_key ? " DEFAULT NULL " : " NOT NULL "));
        if (is_primary_key) {
            sql.append(" AUTO_INCREMENT ");
        }
        sql.append(" COMMENT '" + (field_description == null ? "" : field_description)).append("'");
        if (is_primary_key) {
            sql.append(" ,\t\n PRIMARY KEY (`" + field_name + "`) USING BTREE ");
        } else if (CmnConst.UUID.equals(field_name) || is_unique) {
            sql.append(" ,\t\nUNIQUE KEY `" + field_name + "` (`" + field_name + "`) USING BTREE");
        }
        return sql.toString();
    }
 
    /**
     * 流程节点类型 1、开始 2、处理节点 0、结束
     *
     * @param field_type
     * @return
     */
    private String nodeType(String field_type) {
        String type = "";
        switch (field_type) {
            case "1":
                type = "1";
                break;
            case "99":
                type = "0";
                break;
            case "5":
                type = "2";
                break;
            case "3":
                type = "3";
            case "4":
                type = "3";
                break;
            case "6":
                type = "3";
                break;
            case "7":
                type = "3";
                break;
            case "8":
                type = "3";
                break;
            default:
                throw new BaseException(SystemCode.FIELD_TYPE_FIAL.getValue(), SystemCode.FIELD_TYPE_FIAL.getText() + "_" + field_type);
        }
        return type;
    }
 
    /**
     * 流程完成状态
     *
     * @param field_type
     * @return
     */
    private String finishType(String field_type) {
        String finishType = "";
        switch (field_type) {
            case "0":
                finishType = "1";
                break;
            case "1":
                finishType = "2";
                break;
            case "2":
                finishType = "3";
                break;
            case "3":
                finishType = "3";
                break;
 
            default:
                throw new BaseException(SystemCode.FIELD_TYPE_FIAL.getValue(), SystemCode.FIELD_TYPE_FIAL.getText() + "_" + field_type);
        }
        return finishType;
    }
 
    /**
     * 办理状态
     *
     * @param field_type
     * @return
     */
    private String nodeDealType(String field_type) {
        //源数据        0:已办;1:已收在办;2:未收未办;3 终止;4 冻结
        //本数据 完成标识(0-未收,1-已收未办,2-已办,3-终止,4-竞争失败)
        String finishType = "";
        switch (field_type) {
            case "0":
                finishType = "2";
                break;
            case "1":
                finishType = "1";
                break;
            case "2":
                finishType = "0";
                break;
            case "3":
                finishType = "3";
                break;
            case "4":
                finishType = "3";
                break;
            default:
                throw new BaseException(SystemCode.FIELD_TYPE_FIAL.getValue(), SystemCode.FIELD_TYPE_FIAL.getText() + "_" + field_type);
        }
        return finishType;
    }
 
    /**
     * 字段类型对照
     *
     * @param field_type
     * @return
     */
    private String fieldType(String field_type) {
        String mysql_field_type = "";
        switch (field_type) {
            case "string":
                mysql_field_type = "varchar";
                break;
            case "code":
                mysql_field_type = "varchar";
                break;
            case "flowsign":
                mysql_field_type = "int";
                break;
            case "datetime":
                mysql_field_type = "datetime";
                break;
            case "file":
                mysql_field_type = "varchar";
                break;
            case "int":
                mysql_field_type = "int";
                break;
            case "pk":
                mysql_field_type = "bigint";
                break;
            case "parentuuid":
                mysql_field_type = "varchar";
                break;
            case "uuid":
                mysql_field_type = "varchar";
                break;
            case "userid":
                mysql_field_type = "bigint";
                break;
            case "orgUuid":
                mysql_field_type = "varchar";
                break;
            case "number":
                mysql_field_type = "decimal";
                break;
            case "serialNumber":
                mysql_field_type = "varchar";
                break;
            case "email":
                mysql_field_type = "varchar";
                break;
            case "idcard":
                mysql_field_type = "int";
                break;
            case "url":
                mysql_field_type = "varchar";
                break;
            case "mac":
                mysql_field_type = "varchar";
                break;
            case "table_name":
                mysql_field_type = "varchar";
                break;
            case "field_name":
                mysql_field_type = "varchar";
                break;
            case "text":
                mysql_field_type = "text";
                break;
            default:
                throw new BaseException(SystemCode.FIELD_TYPE_FIAL.getValue(), SystemCode.FIELD_TYPE_FIAL.getText() + "_" + field_type);
        }
        return mysql_field_type;
    }
 
    /**
     * 字段类型对照
     *
     * @param field_type
     * @return
     */
    private String fieldTypeFE(String field_type) {
        String mysql_field_type = "";
        switch (field_type) {
            //主键不设唯一不舍必填
            case "AUTO":
                mysql_field_type = "pk";
                break;
            case "NUMERIC":
                mysql_field_type = "number";
                break;
            case "DATETIME":
                mysql_field_type = "datetime";
                break;
            case "STRING":
                mysql_field_type = "string";
                break;
            case "NATIVE":
                mysql_field_type = "string";
                break;
            case "CDATETIME":
                mysql_field_type = "datetime";
                break;
            case "PROMPT":
                mysql_field_type = "string";
                break;
            case "SORT":
                mysql_field_type = "string";
                break;
            case "MEDIA":
                mysql_field_type = "file";
                break;
            case "SPFLAG":
                mysql_field_type = "flowsign";
                break;
            case "IMAGE":
                mysql_field_type = "file";
                break;
            case "TEXT":
                mysql_field_type = "text";
                break;
            case "UNITCODE":
                mysql_field_type = "string";
                break;
            case "FLOWCODE":
                mysql_field_type = "string";
                break;
            case "GUID":
                mysql_field_type = "string";
                break;
            default:
                throw new BaseException(SystemCode.FIELD_TYPE_FIAL.getValue(), SystemCode.FIELD_TYPE_FIAL.getText() + "_" + field_type);
        }
        return mysql_field_type;
    }
 
    private synchronized void execute(String sql) throws BaseException {
        try {
            Connection connection = ConnectionManager.getInstance().getConnection();
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            preparedStatement.execute();
        } catch (Exception e) {
            e.getStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
            throw new BaseException(SystemCode.SQL_START_FAILED.getValue(), SystemCode.SQL_START_FAILED.getText() + e.getMessage());
        }
    }
 
    @Override
    public void run() {
        //封装两边人员关联和部门关联
        this.packageDepartmentPersonnel();
        nodesIdUUID = new JSONObject();
        //同步表及基础数据
        String sf28 = null;
        Connection conn = null;
        try {
            conn = this.getJDBC();
        } catch (SQLException e) {
            e.printStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
        }
        String moduleUUID = null;
        //若已有表同步  mvc标识 表示从功能开始同步
        if(tricode_funs.indexOf("mvc") != -1){ //mvc 要带上同表的多个功能
            //只同步mvc
            String[] funs = this.tricode_funs.split("mvc");
            try {
                sf28 = this.synchronizeTablesData(conn, funs[0]);
                String tableName = sf28.split("\\.")[1];
                this.originalTable.put(tableName, tableName.toLowerCase());
                for (int i = 0; i < funs.length; i++) {
                    //当前功能
                    this.tricode_funs = funs[i];
                    //同步功能
                    moduleUUID = this.synchronizationModuleName(conn, funs[i], sf28);
                    //表名查询功能
                    FieldSetEntity fse =  baseDao.getFieldSetBySQL("SELECT a.* FROM product_sys_functions a LEFT JOIN product_sys_datamodel_table b on a.table_uuid = b.uuid WHERE b.table_name = ?", new String[]{ tableName.toLowerCase()}, false);
                    String functionUuid = fse.getUUID();
                    //修改已同步附件 添加 module_uuid function_uuid
                    baseDao.executeUpdate(" UPDATE product_sys_attachments SET module_uuid = ?, function_uuid = ? WHERE attachment_data_table = ? AND function_uuid is null ",new String[]{moduleUUID, functionUuid,  tableName.toLowerCase()});
                    //同步流程
                    this.syncFlow(conn, moduleUUID, sf28);
                }
 
            } catch (SQLException e) {
                e.printStackTrace();
                SpringMVCContextHolder.getSystemLogger().error(e);
            }
        }else {
            try {
                sf28 = this.synchronizeTablesData(conn, this.tricode_funs);
            } catch (SQLException e) {
                e.printStackTrace();
                SpringMVCContextHolder.getSystemLogger().error(e);
            }
            String table_name = sf28.split("\\.")[1];
            String myTableName = this.originalTable.getString(table_name);
            if (!isStr(sf28)) {
                //同步mvc
                try {
                    moduleUUID = this.synchronizationModuleName(conn, this.tricode_funs, sf28);
                } catch (SQLException e) {
                    e.printStackTrace();
                    SpringMVCContextHolder.getSystemLogger().error(e);
                }
            } else {
                //已有功能的表就不同步mvc  查询该功能的模块uuid
                StringBuffer sql = new StringBuffer();
                sql.append(" tricode = (\n")
                        .append("SELECT tricode_parent FROM product_sys_functions a LEFT JOIN \n")
                        .append("product_sys_datamodel_table b on a.table_uuid = b.uuid \n")
                        .append("WHERE b.table_name = ? GROUP BY tricode_parent\n")
                        .append(") AND function_type_uuid = 0");
 
                FieldSetEntity fieldSetEntity = baseDao.getFieldSetEntityByFilter("product_sys_functions", sql.toString(), new String[]{myTableName}, false);
                moduleUUID = fieldSetEntity.getUUID();
            }
            if (!isStr(sf28))  {
                this.syncFlow(conn, moduleUUID, sf28);
            }
            //表名查询功能
            FieldSetEntity fse =  baseDao.getFieldSetBySQL("SELECT a.* FROM product_sys_functions a LEFT JOIN product_sys_datamodel_table b on a.table_uuid = b.uuid WHERE b.table_name = ?", new String[]{myTableName}, false);
            String functionUuid = fse.getUUID();
            //修改已同步附件 添加 module_uuid function_uuid
            baseDao.executeUpdate(" UPDATE product_sys_attachments SET module_uuid = ?, function_uuid = ? WHERE attachment_data_table = ? AND function_uuid is null ",new String[]{moduleUUID, functionUuid, myTableName});
        }
        try {
            DataManipulationUtils.close(null, null, conn);
        } catch (SQLException e) {
            e.printStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
        }
    }
 
    /**
     * 同步流程
     * @param conn jdbc连接
     * @param moduleUUID 模块uuid
     * @param sf28 表名
     */
    public void syncFlow(Connection conn, String moduleUUID, String sf28){
 
        //查询主公司uuid
        FieldSetEntity fieldSetEntity = baseDao.getFieldSetByFilter(CmnConst.PRODUCT_SYS_ORG_LEVELS, " org_level_code = ? ", new String[]{"001"},false);
        FieldSetEntity user = baseDao.getFieldSetByFilter("product_sys_org_manager" , " manager_type = ? ", new String[]{"2"}, false);
        try {
            //迁移 wf_model流程模块表
            String typeCode = this.syncModel(tricode_funs, conn, moduleUUID, sf28, null, 1, null,false);
            //根据要求流程要同步两次 相同流程的typeCode相同
            if(!BaseUtil.strIsNull(typeCode)){
                this.syncModel(tricode_funs, conn, moduleUUID, sf28, fieldSetEntity.getUUID(), user.getInteger("user_id"), typeCode,true);
            }
        } catch (SQLException e) {
            e.printStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
        }
        //初始化菜单缓存
//        systemMenusService.initSystemMenu();
        System.out.println("================="+tricode_funs+"同步成功===============");
    }
 
}