2
13693261870
2022-09-16 653761a31dfeb50dd3d007e892d69c90bf0cdafc
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
package com.landtool.lanbase.modules.res.controller;
 
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.google.gson.JsonObject;
import com.landtool.lanbase.common.annotation.LogAction;
import com.landtool.lanbase.common.map.EsbToken;
import com.landtool.lanbase.common.utils.*;
import com.landtool.lanbase.config.SysTemPropertyConfig;
import com.landtool.lanbase.modules.api.utils.Excel;
import com.landtool.lanbase.modules.api.utils.JDBCUtils;
import com.landtool.lanbase.modules.api.utils.PageBean;
import com.landtool.lanbase.modules.log.service.LogActionService;
import com.landtool.lanbase.modules.org.entity.OrgUnit;
import com.landtool.lanbase.modules.org.entity.OrgUser;
import com.landtool.lanbase.modules.org.service.OrgUnitService;
import com.landtool.lanbase.modules.org.service.OrgUserService;
import com.landtool.lanbase.modules.res.entity.DataBaseLeftDataSource.DataBaseLeftDataSource;
import com.landtool.lanbase.modules.res.entity.JSONModels.BiaoJieGou;
import com.landtool.lanbase.modules.res.entity.JSONModels.ZiDuanPeiZi;
import com.landtool.lanbase.modules.res.entity.*;
import com.landtool.lanbase.modules.res.entity.UserDefined.DingYue;
import com.landtool.lanbase.modules.res.entity.UserDefined.MainInfoJoinAudit;
import com.landtool.lanbase.modules.res.entity.UserDefined.MainInfoJoinJcdt;
import com.landtool.lanbase.modules.res.entity.UserDefined.UserDef_ZYML_ChaXunQu;
import com.landtool.lanbase.modules.res.entity.ViewModels.FileSourceList;
import com.landtool.lanbase.modules.res.entity.ZiYuanTongJi.*;
import com.landtool.lanbase.modules.res.service.*;
import com.landtool.lanbase.modules.sys.controller.AbstractController;
import com.landtool.lanbase.modules.sys.service.SysFieldvalueService;
import io.swagger.models.auth.In;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.spring.web.json.Json;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * @Date: 2018-03-02 11:34
 * @Description:主表逻辑操作
 */
@Controller
@RequestMapping("/res")
public class ResMainInfoController extends AbstractController {
    @Autowired
    private ResMainInfoService resMainInfoService;
 
    @Autowired
    private ResCatalogService resCatalogService;
 
    @Autowired
    private ResExtBaseMapService resExtBaseMapService;
 
    @Autowired
    private ResExtBusinessLayerService resExtBusinessLayerService;
 
    @Autowired
    private ResExtSpaceServerService resExtSpaceServerService;
 
    @Autowired
    private ResExtThemeMapService resExtThemeMapService;
 
    @Autowired
    private ResExtIntegrateService resExtIntegrateService;
 
    @Autowired
    private ResExtFileSourceService resExtFileSourceService;
 
    @Autowired
    private ResActionRecordService resActionRecordService;
 
    @Autowired
    private ResExtInterFaceService resExtInterFaceService;
 
    @Autowired
    private ResExtDataBaseService resExtDataBaseService;
 
    @Autowired
    private ResExt3DService resExt3DService;
 
    @Autowired
    private ResExtDataSourceService resExtDataSourceService;
 
    @Autowired
    private SysTemPropertyConfig sysConfig;
 
    @Autowired
    public ResApplyRecommendService resApplyRecommendService;
 
    @Autowired
    private SysFieldvalueService FieldUtils;
 
    @Autowired
    private OrgUserService orgUserService;
 
    @Autowired
    private OrgUnitService orgUnitService;
 
    @Autowired
    private ResFileSourceWayService resFileSourceWayService;
 
    @Autowired
    private ResSubscriptionsService resSubscriptionsService;
 
    @Autowired
    private ResExtMapUrlService resExtMapUrlService;
 
    @Autowired
    private ResAuditService resAuditService;
 
    @Autowired
    private ResBusinessRefService resBusinessRefService;
 
    @Autowired
    private ResQueryAroundService resQueryAroundService;
 
    @Autowired
    private ResEvaluationService resEvaluationService;
 
    @Autowired
    private ResDiyLayerInfoService resDiyLayerInfoService;
 
    @Autowired
    private Environment env;
 
    @Autowired
    private ResFilesService resFileService;
 
    @Autowired
    public ZiYuanMuLuService ziYuanMuLuService;
 
    @Autowired
    private ResProblemFeedbackService resProblemFeedbackService;
 
    @Autowired
    private LogActionService logActionService;
 
 
    private String wenjianjiaPath() {
        return sysConfig.getUploadPath() + "FileSource\\wenjianjia\\";
    }
 
    private String wenjianPath() {
        return sysConfig.getUploadPath() + "FileSource\\wenjian\\";
    }
 
    public static String strMuLu = "";
 
    /**
     * 访问资源编辑页面(ResRegister.Controller)
     */
    @RequestMapping("ZiYuan/AddZiYuanBasic")
    public String ziYuanEditJump(Model model, Long resMainInfoId) {
        if (resMainInfoId != null) {
            Res_MainInfo resMainInfo = resMainInfoService.selectByPrimaryKey(resMainInfoId.intValue());
            // 获取资源类型列表
            LinkedHashMap<String, String> ResourceTypeList = FieldUtils.getFieldListByKey("ResourceType");
            model.addAttribute("resourceclass", ResourceTypeList.get(resMainInfo.getResourceclass()));
        }
        model.addAttribute("resMainInfoId", resMainInfoId);
        return "FuWuZiYuan/ZiYuan_Edit";
    }
 
    /**
     * 访问资源基本信息新增页面
     */
    @RequestMapping("ZiYuan/AddZiYuanChildren")
    public String addZiYuanChildren(HttpServletRequest request, Model model, Long resMainInfoId) throws IOException {
        Res_MainInfo res_mainInfo = new Res_MainInfo();
        Res_Catalog res_catalog = new Res_Catalog();
        String Imagelujin = null;
        // 修改
        if (resMainInfoId != null) {
            res_mainInfo = resMainInfoService.selectByPrimaryKey(resMainInfoId.intValue());
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            String Pubdate = sdf.format(res_mainInfo.getPubdate());
            model.addAttribute("Pubdate", Pubdate);
            if (res_mainInfo.getCatlogid() != null) {
                res_catalog = resCatalogService.selectByPrimaryKey(res_mainInfo.getCatlogid());
            }
            if (res_mainInfo.getImgurl() != null && res_mainInfo.getImgurl() != "") {
                StringBuffer url = request.getRequestURL();
                String ip = "/ZiYuanIcon/";
                Imagelujin = ip + res_mainInfo.getImgurl();
            }
            // 数据覆盖范围--行政区划Id
            // modified by qufangxu 信创环境下,若 res_mainInfo.getAdministrativeid() = '        ',会返回单点登录页面,具体原因未知。 解决办法:提前去除空格、制表符
            String administrativeid = (String) res_mainInfo.getAdministrativeid();
            String finalValue = null;
            if (StringUtils.isNotEmpty(administrativeid)){
                finalValue = administrativeid.trim();
            }
            if (StringUtils.isNotEmpty(finalValue)) {
                String getRegionInfourl = sysConfig.getApiServer() + "/api/org/region/getById/" + administrativeid;
                String jsonStr = HttpOperateUtils.httpGet(getRegionInfourl.trim());
                if (jsonStr != null && !jsonStr.isEmpty()) {
                    JSONObject item = JSONObject.parseObject(jsonStr);
                    String regionname = item.getString("regionname");
                    model.addAttribute("administrativename", regionname);
                }
            }
        }
        // 获取资源类型列表
        LinkedHashMap<String, String> ResourceTypeList = FieldUtils.getFieldListByKey("ResourceType");
        model.addAttribute("mainInfo", res_mainInfo);
        model.addAttribute("rescatalog", res_catalog);
        model.addAttribute("resMainInfoId", resMainInfoId);
        model.addAttribute("ResourceTypeList", ResourceTypeList);
        model.addAttribute("Imagelujin", Imagelujin);
        return "FuWuZiYuan/AddZiYuanChildren";
    }
 
    /**
     * 访问查看页面
     */
    @RequestMapping("ZiYuan/ZiYuanSelect")
    public String ziYuanSelect(Model model, Long resMainInfoId) {
        model.addAttribute("resMainInfoId", resMainInfoId);
        model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
        model.addAttribute("systemName", sysConfig.getAppFullName());
        return "FuWuZiYuan/ZiYuanSelect";
    }
 
    /**
     * 访问资源元数据新增页面
     */
    @RequestMapping("ZiYuan/AddZiYuanYSJ")
    public String addZiYuanYSJ() {
        return "FuWuZiYuan/AddZiYuanYSJ";
    }
 
    /**
     * 插入资源编辑页面内容
     */
    @RequestMapping("ziYuanInsert")
    @ResponseBody
    @LogAction("资源管理,资源发布,资源新增,新增|zy")
    public String ziYuanInsert(Res_MainInfo resMainInfo, String GUANJIANZI) {
        // 获取拼音首字母
        String shortPinYin = JpinyinUtils.changeToGetShortPinYin((String) resMainInfo.getTitle());
        resMainInfo.setPingyinfiirst(shortPinYin);
        resMainInfo.setAuditstatus(0);// 设置资源状态为未提交
        resMainInfo.setResourcestatus(0);// 设置资源服务状态为正常
        resMainInfo.setEspproxy(0);// 设置是否代理为0:false
        resMainInfo.setDisplayby2d(0);// 设置是否支持二维展示为0:不支持
        resMainInfo.setDisplayby3d(0);// 设置是否支持三维展示为0“不支持
        resMainInfo.setPubdate(DateUtils.getFunllDate(resMainInfo.getPubdate()));
        //换地址
        if (resMainInfo.getDesurl() != null && resMainInfo.getDesurl().indexOf("diydes") != -1) {
            String url = resMainInfo.getDesurl().replace(sysConfig.getUploadRootPath(), "");
            resMainInfo.setDesurl(url);
        }
        int result = resMainInfoService.insertSelective(resMainInfo);
        resMainInfo.setOrderid(resMainInfo.getResourceid());
        resMainInfoService.updateByPrimaryKeySelective(resMainInfo);
 
        Object resourceClass = resMainInfo.getResourceclass();
        return "{'result':'" + result + "','ziyuanId':'" + resMainInfo.getResourceid() + "','ziyuanClass':'" + resourceClass.toString() + "'}";
    }
 
    /**
     * 更新资源编辑页面内容
     */
    @RequestMapping("ziYuanUpdaate")
    @ResponseBody
    @LogAction("资源管理,资源发布,资源修改,修改|zy")
    public String ziYuanUpdaate(Res_MainInfo resMainInfo) {
        // 获取拼音首字母
        String shortPinYin = JpinyinUtils.changeToGetShortPinYin((String) resMainInfo.getTitle());
        resMainInfo.setPingyinfiirst(shortPinYin);
        // 更新基本信息时间
        Timestamp audittime = new Timestamp(new Date().getTime());// 获取当前时间
        // 更新委托批复
        if (resMainInfo.getInsteadaudit() == null) {
            resMainInfo.setInsteadaudit(0);
        }
        //换地址
        if (resMainInfo.getDesurl() != null && resMainInfo.getDesurl().indexOf("diydes") != -1) {
            String url = resMainInfo.getDesurl().replace(sysConfig.getUploadRootPath(), "");
            resMainInfo.setDesurl(url);
        }
        resMainInfo.setPubdate(DateUtils.getFunllDate(resMainInfo.getPubdate()));
        resMainInfo.setLasteditdate(audittime);
        int result = resMainInfoService.updateByPrimaryKeySelective(resMainInfo);
 
        return "{'result':'" + result + "','ziyuanId':'" + resMainInfo.getResourceid() + "'}";
    }
 
    /**
     * 更新资源编辑页面内容
     */
    @RequestMapping("ziYuanSubmit")
    @ResponseBody
    @LogAction("资源管理,资源发布,资源修改,修改")
    public String ziYuanSubmit(Res_MainInfo resMainInfo) {
        int result;
        Res_MainInfo model = resMainInfoService.selectByPrimaryKey(resMainInfo.getResourceid());
        // 更新委托批复
        if (resMainInfo.getInsteadaudit() == null) {
            resMainInfo.setInsteadaudit(0);
        }
        if (model.getResourcestatus() == 3) { // 资源提交。如果资源状态为注销则改为正常
            resMainInfo.setResourcestatus(0);
        }
        boolean isExistExt = hasExistExtZiYuan(resMainInfo.getResourceid(), model.getResourceclass());// 是否存在扩展信息
        if (isExistExt) {
            String shortPinYin = JpinyinUtils.changeToGetShortPinYin((String) resMainInfo.getTitle());// 获取拼音首字母
            resMainInfo.setPingyinfiirst(shortPinYin);
            resMainInfo.setAuditstatus(1);
 
            result = resMainInfoService.updateByPrimaryKeySelective(resMainInfo);
        } else {// 如果不存在扩展信息提示填写扩展信息
            return "{'result':'" + 2 + "','ziyuanId':'" + resMainInfo.getResourceid() + "'}";
        }
        return "{'result':'" + result + "','ziyuanId':'" + resMainInfo.getResourceid() + "'}";
    }
 
    /**
     * 检测资源拓展信息是否存在
     *
     * @param resourceId
     * @param resourceClass
     * @return
     */
    public boolean hasExistExtZiYuan(Integer resourceId, String resourceClass) {
        // LinkedHashMap<String, String> ResourceTypeList =
        // FieldUtils.getFieldListByKey("ResourceType",
        // sysConfig.getApiServer();//获取资源类型列表
        // String resourceType = ResourceTypeList.get(resourceClass);
        if (resourceClass == null) resourceClass = "";
//        alert ykm 2019/02/26
        if (resourceClass.equals("KJ_SWMX") || resourceClass.equals("KJ_SWDX") || resourceClass.equals("KJ_SWYX"))
            resourceClass = "KJ_SW";
        switch (resourceClass) {
            case "KJ_JCDT":// 基础底图
                Res_ExtBaseMap res_ExtBaseMap = resExtBaseMapService.selectByPrimaryKey(resourceId);
                return res_ExtBaseMap != null;
            case "KJ_YWTC":// 业务图层
                Res_ExtBusinessLayer res_ExtBusinessLayer = resExtBusinessLayerService.selectByPrimaryKey((resourceId));
                return res_ExtBusinessLayer != null;
            case "KJ_KJFX":// 空间分析
                Res_ExtSpaceServer res_ExtSpaceServer = resExtSpaceServerService.selectByPrimaryKey(resourceId);
                return res_ExtSpaceServer != null;
            case "KJ_ZTDT":// 专题地图
                Res_ExtThemeMap res_ExtThemeMap = resExtThemeMapService.selectByPrimaryKey(resourceId);
                return res_ExtThemeMap != null;
            // case "专题应用程序":
            // Res_ExtApp res_ExtApp =
            // resExtAppService.selectByPrimaryKey(resourceId);
            // return res_ExtApp != null;
            case "YWJC":// 业务集成
                Res_ExtIntegrate res_ExtIntegrate = resExtIntegrateService.selectByPrimaryKey(resourceId);
                return res_ExtIntegrate != null;
            case "SJWJ":// 数据文件
                Res_ExtFileSource res_ExtFileSource = resExtFileSourceService.selectByPrimaryKey(resourceId);
                return res_ExtFileSource != null;
            case "SJKB":// 数据库表
                Res_ExtDataBase res_extDataBase = resExtDataBaseService.selectByMainInfoId(resourceId);
                return res_extDataBase != null;
            case "JKFW":// 接口服务
                Res_ExtInterFaceService res_extInterFaceService = resExtInterFaceService.selectByPrimaryKey(resourceId);
                return res_extInterFaceService != null;
//            case "KJ_SWMX":// 三维模型
            case "KJ_SW":// 三维类,三维模型、三维地形、三维影像
                Res_Ext3D res_ext3D = resExt3DService.selectByPrimaryKey(resourceId);
                return res_ext3D != null;
            default:
                return false;
        }
    }
 
    /**
     * 资源查询页面
     */
    @RequestMapping("ZiYuan/Index")
    public String index(String Message, Model model) {
        // 获取下拉框目录
        LinkedHashMap<String, String> ResourceTypeList = FieldUtils.getFieldListByKey("ResourceType");// 获取资源类型列表
        model.addAttribute("ResourceTypeList", ResourceTypeList);
        String ResourceTypeListJson = "";
        for (Map.Entry<String, String> entry : ResourceTypeList.entrySet()) {
            if (ResourceTypeListJson != "") ResourceTypeListJson += ",";
            ResourceTypeListJson += "{key:'" + entry.getKey() + "',value:'" + entry.getValue() + "'}";
        }
        if (Message != null) {
            model.addAttribute("Message", Message);
        }
        model.addAttribute("ResourceTypeListJson", "[" + ResourceTypeListJson + "]");
        model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
        model.addAttribute("systemName", sysConfig.getAppFullName());
        model.addAttribute("backstageWebRoot", sysConfig.getApiServer() + "/");
        // 资源类型饼状统计图
        List<GroupByZiYuanLeiXing> resourceclassList = resMainInfoService.selectResMainInfoGroupByLeiXing();
        String ZYLXJson = "";
        String ZYLXLend = "";
        int ZYLXCount = 0;
        // 多于4个类型的话数据显示前7个资源数量最多的类型,后面的都以其它统计
        if (resourceclassList.size() > 4) {
            int counter = 0;
            for (int i = 4; i < resourceclassList.size(); i++) {
                counter += resourceclassList.get(i).getCount();
            }
            for (int i = 0; i < 4; i++) {
                GroupByZiYuanLeiXing item = resourceclassList.get(i);
                String leixing = ResourceTypeList.get(item.getResourceclass());
                ZYLXJson += (ZYLXJson == "" ? "" : ",") + "{ value: " + item.getCount() + ", name: '" + leixing + "'}";
                ZYLXLend += (ZYLXLend == "" ? "" : ",") + "'" + leixing + "'";
                ZYLXCount += item.getCount();
            }
            ZYLXJson += (ZYLXJson == "" ? "" : ",") + "{ value: " + counter + ", name: '" + "其它" + "'}";
            ZYLXLend += (ZYLXLend == "" ? "" : ",") + " '" + "其它" + "'";
            ZYLXCount += counter;
        }
        // 少于等于4个类型就全部显示
        else {
            for (int i = 0; i < resourceclassList.size(); i++) {
                GroupByZiYuanLeiXing item = resourceclassList.get(i);
                String leixing = ResourceTypeList.get(item.getResourceclass());
                ZYLXJson += (ZYLXJson == "" ? "" : ",") + "{ value: " + item.getCount() + ", name: '" + leixing + "'}";
                ZYLXLend += (ZYLXLend == "" ? "" : ",") + "'" + leixing + "'";
                ZYLXCount += item.getCount();
            }
        }
        model.addAttribute("ZYLXJson", "[" + ZYLXJson + "]");
        model.addAttribute("ZYLXLend", "[" + ZYLXLend + "]");
        model.addAttribute("ZYLXCount", ZYLXCount);
 
        // 行政区划饼状统计图
        List<GroupByXingZhengQuHua> administrativeidList = resMainInfoService.selectResMainInfoGroupByXingZhengQuHua();
        String XZQHJson = "";
        String XZQHLend = "";
        int XZQHCount = 0;
        String jsonStr = "";
        String getRegionInfourl = sysConfig.getApiServer() + "/api/org/region/queryList";
        try {
            jsonStr = HttpOperateUtils.httpGet(getRegionInfourl.trim());
        } catch (IOException e) {
            e.printStackTrace();
        }
        JSONArray XZQHItem = JSONObject.parseArray(jsonStr);
        if (administrativeidList.size() > 5) {
            int XZcounter = 0;
            for (int i = 5; i < administrativeidList.size(); i++) {
                XZcounter += administrativeidList.get(i).getCount();
            }
            for (int i = 0; i < 5; i++) {
                GroupByXingZhengQuHua item = administrativeidList.get(i);
                String quhua = item.getAdministrativeid().trim();
                if (quhua.length() > 0) {
                    if (!quhua.substring(2, quhua.length()).equals("0000")) {
                        quhua = quhua.substring(0, 2) + "0000"; // 下级市区归属到省
                    }
                } else {
                    continue;
                } // 为空跳过
                for (int j = 0; j < XZQHItem.size(); j++) {
                    JSONObject temp = (JSONObject) XZQHItem.get(j);
                    String regionid = temp.getString("regionid");
                    if (regionid.equals(quhua)) {
                        quhua = temp.getString("regionname");
                        break;
                    }
                }
                XZQHJson += (XZQHJson == "" ? "" : ",") + "{ value: " + item.getCount() + ", name: '" + quhua + "'}";
                XZQHLend += (XZQHLend == "" ? "" : ",") + "'" + quhua + "'";
                XZQHCount += item.getCount();
            }
            XZQHJson += (XZQHJson == "" ? "" : ",") + "{ value: " + XZcounter + ", name: '" + "其它" + "'}";
            XZQHLend += (XZQHLend == "" ? "" : ",") + " '" + "其它" + "'";
            XZQHCount += XZcounter;
        } else {
            for (int i = 0; i < administrativeidList.size(); i++) {
                GroupByXingZhengQuHua item = administrativeidList.get(i);
                String quhua = item.getAdministrativeid().trim();
                if (quhua.length() > 0) {
                    if (!quhua.substring(2, quhua.length()).equals("0000")) {
                        quhua = quhua.substring(0, 2) + "0000"; // 下级市区归属到省
                    }
                } else {
                    continue;
                } // 为空跳过
                for (int j = 0; j < XZQHItem.size(); j++) {
                    JSONObject temp = (JSONObject) XZQHItem.get(j);
                    String regionid = temp.getString("regionid");
                    if (regionid.equals(quhua)) {
                        quhua = temp.getString("regionname");
                        break;
                    }
                }
                XZQHJson += (XZQHJson == "" ? "" : ",") + "{ value: " + item.getCount() + ", name: '" + quhua + "'}";
                XZQHLend += (XZQHLend == "" ? "" : ",") + "'" + quhua + "'";
                XZQHCount += item.getCount();
            }
        }
        model.addAttribute("XZQHJson", "[" + XZQHJson + "]");
        model.addAttribute("XZQHLend", "[" + XZQHLend + "]");
        model.addAttribute("XZQHCount", XZQHCount);
 
        // 共享协议饼状统计图
        LinkedHashMap<String, String> GongXiangXieYiList = FieldUtils.getFieldListByKey("SharProtocol");// 获取共享协议列表
        List<GroupByGongXiangXieYi> sharprotocolList = resMainInfoService.selectResMainInfoGroupByGongXiangXieYi();
        String GXXYJson = "";
        String GXXYLend = "";
        int GXXYCount = 0;
        for (int i = 0; i < sharprotocolList.size(); i++) {
            GroupByGongXiangXieYi item = sharprotocolList.get(i);
            String xieyi = item.getSharprotocol();
            GXXYJson += (GXXYJson == "" ? "" : ",") + "{ value: " + item.getCount() + ", name: '" + xieyi + "'}";
            GXXYLend += (GXXYLend == "" ? "" : ",") + "'" + xieyi + "'";
            GXXYCount += item.getCount();
        }
        model.addAttribute("GXXYJson", "[" + GXXYJson + "]");
        model.addAttribute("GXXYLend", "[" + GXXYLend + "]");
        model.addAttribute("GXXYCount", GXXYCount);
 
        // 按单位统计柱状图
        List<GroupByDanWei> pubunitidList = resMainInfoService.selectResMainInfoGroupByDanWei();
        String DWJson = "";
        String DWLend = "";
        String UnitStr = "";
        for (int i = 0; i < pubunitidList.size(); i++) {
            GroupByDanWei item = pubunitidList.get(i);
            String id = item.getPubunitid();
            String getUnitInfourl = sysConfig.getApiServer() + "/api/org/unit/getInfoById/" + id;
            try {
                UnitStr = HttpOperateUtils.httpGet(getUnitInfourl.trim());
            } catch (IOException e) {
                e.printStackTrace();
            }
            JSONObject UnitData = JSONObject.parseObject(UnitStr);
            String temp = UnitData.getString("unitname");
            DWJson += (DWJson == "" ? "" : ",") + item.getCount();
            DWLend += (DWLend == "" ? "" : ",") + "'" + temp + "'";
        }
        model.addAttribute("DWJson", "[" + DWJson + "]");
        model.addAttribute("DWLend", "[" + DWLend + "]");
        return "FuWuZiYuan/Index";
    }
 
    /**
     * 所属目录目录树
     */
    @RequestMapping("ZiYuan/MuLuShu")
    public String muLuShu() {
        return "ResManage/ResRegister/MuLuShu";
    }
 
    /**
     * 行政区划目录树
     */
    @RequestMapping("ZiYuan/AreaTree")
    public String areaTree(Model model) {
        model.addAttribute("backstageWebRoot", sysConfig.getApiServer() + "/");
        model.addAttribute("systemName", sysConfig.getAppFullName());
        return "FuWuZiYuan/AreaTree";
    }
 
    /**
     * 资源图文列表
     */
    @RequestMapping("ZiYuan/ZiYuanDataList")
    public String ziYuanDataList(Res_MainInfo resMainInfo, Model model, PageBean pageBean) {
        //update:dsh(2018/12/05)
        Page<Res_MainInfo> page = PageHelper.startPage(pageBean.getPage(), 15);
        List<Res_MainInfo> ziYuanMuLuList = resMainInfoService.selectResMainInfo(resMainInfo);
        int countNums = (int) ((Page) ziYuanMuLuList).getTotal();
        PageBean<Res_MainInfo> pageData = new PageBean<>(pageBean.getPage(), pageBean.getLimit(), countNums);
        pageData.setItems(ziYuanMuLuList);
        List<SimpleZiYuan> simpleZiYuans = new ArrayList<>();
        LinkedHashMap<String, String> ResourceTypeList = FieldUtils.getFieldListByKey("ResourceType");
        for (Integer j = 0; j < ziYuanMuLuList.size(); j++) {
            Res_MainInfo zy = ziYuanMuLuList.get(j);
            SimpleZiYuan model1 = new SimpleZiYuan();
            model1.setResourceid(zy.getResourceid());
            model1.setTitle(zy.getTitle());
            model1.setCreateuserid(zy.getCreateuserid());
            String chinesename = orgUserService.getChinesename(zy.getCreateuserid());// 查询发布人id对应的 name
            String unitname = orgUnitService.getUnitName((long) zy.getPubunitid());
            model1.setCreateusername(chinesename);
            model1.setDatasources(zy.getDatasources());
            model1.setPubunitid(zy.getPubunitid());
            model1.setPubunitname(unitname);
            model1.setKeywords(zy.getKeywords());
            model1.setSecuritylev(zy.getSecuritylev());
            model1.setResourceclass(ResourceTypeList.get(zy.getResourceclass()));
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            model1.setPubdate(sdf.format(zy.getPubdate()));
            simpleZiYuans.add(model1);
        }
        model.addAttribute("ZyList", simpleZiYuans);
        model.addAttribute("Count", countNums);
        model.addAttribute("Page", pageBean.getPage());
        return "FuWuZiYuan/ZiYuanDataList";
    }
 
    @RequestMapping("ZiYuan/JcdtDataList")
    public String jcdtDataList(MainInfoJoinJcdt resMainInfo, Model model, PageBean pageBean) {
        //update:dsh(2018/12/05)
        Page<MainInfoJoinJcdt> page = PageHelper.startPage(pageBean.getPage(), 15);
        List<MainInfoJoinJcdt> ziYuanMuLuList = resMainInfoService.selectJcdtList(resMainInfo);
        int countNums = (int) ((Page) ziYuanMuLuList).getTotal();
        PageBean<MainInfoJoinJcdt> pageData = new PageBean<>(pageBean.getPage(), pageBean.getLimit(), countNums);
        pageData.setItems(ziYuanMuLuList);
        List<SimpleZiYuan> simpleZiYuans = new ArrayList<>();
        for (Integer j = 0; j < ziYuanMuLuList.size(); j++) {
            MainInfoJoinJcdt zy = ziYuanMuLuList.get(j);
            SimpleZiYuan model1 = new SimpleZiYuan();
            model1.setResourceid(zy.getResourceid());
            model1.setTitle(zy.getTitle());
            model1.setCreateuserid(zy.getCreateuserid());
            model1.setDatasources(zy.getDatasources());
            model1.setPubunitid(zy.getPubunitid());
            model1.setKeywords(zy.getKeywords());
            model1.setSecuritylev(zy.getSecuritylev());
            LinkedHashMap<String, String> ResourceTypeList = FieldUtils.getFieldListByKey("ResourceType");
            model1.setResourceclass(ResourceTypeList.get(zy.getResourceclass()));
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            model1.setPubdate(sdf.format(zy.getPubdate()));
            simpleZiYuans.add(model1);
        }
        model.addAttribute("ZyList", simpleZiYuans);
        model.addAttribute("Count", countNums);
        model.addAttribute("Page", pageBean.getPage());
        return "FuWuZiYuan/JcdtDataList";
    }
 
    @RequestMapping("ZiYuan/ZiYuanList")
    public String ziYuanList(Model model) {
        // 获取下拉框目录
        LinkedHashMap<String, String> ResourceTypeList = FieldUtils.getFieldListByKey("ResourceType");// 获取资源类型列表
        List<String> DATASOURCES = resMainInfoService.selectDATASOURCES();
        Timestamp audittime = new Timestamp(new Date().getTime());
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
        List<Res_Catalog> MuLuList = resCatalogService.selectResCatalogToParentid(0);
        String year = sdf.format(audittime);
        model.addAttribute("year", year);
        model.addAttribute("DATASOURCESList", DATASOURCES);
        model.addAttribute("ResourceTypeList", ResourceTypeList);
        model.addAttribute("MuLuList", MuLuList);
        String ResourceTypeListJson = "";
        for (Map.Entry<String, String> entry : ResourceTypeList.entrySet()) {
            if (ResourceTypeListJson != "") ResourceTypeListJson += ",";
            ResourceTypeListJson += "{key:'" + entry.getKey() + "',value:'" + entry.getValue() + "'}";
        }
        model.addAttribute("ResourceTypeListJson", "[" + ResourceTypeListJson + "]");
        model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
        model.addAttribute("systemName", sysConfig.getAppFullName());
        model.addAttribute("backstageWebRoot", sysConfig.getApiServer() + "/");
        return "FuWuZiYuan/ZiYuanList";
    }
 
    @RequestMapping("ZiYuan/JcdtList")
    public String jcdtList(Model model) {
        // 获取下拉框目录
        LinkedHashMap<String, String> BaseMapTypeList = FieldUtils.getFieldListByKey("BaseMapType");// 获取底图类型字典列表
        List<String> DATASOURCES = resMainInfoService.selectDATASOURCES();
        Timestamp audittime = new Timestamp(new Date().getTime());
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
        List<Res_Catalog> MuLuList = resCatalogService.selectResCatalogToParentid(0);
 
        String year = sdf.format(audittime);
        model.addAttribute("year", year);
        model.addAttribute("DATASOURCESList", DATASOURCES);
        model.addAttribute("BaseMapTypeList", BaseMapTypeList);
        model.addAttribute("MuLuList", MuLuList);
        model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
        model.addAttribute("systemName", sysConfig.getAppFullName());
        model.addAttribute("backstageWebRoot", sysConfig.getApiServer() + "/");
        return "FuWuZiYuan/JcdtList";
    }
 
    /**
     * 查询资源目录id
     */
    @ResponseBody
    @RequestMapping("selectZiYuan")
    public Res_MainInfo selectZiYuan(int resMainInfoId) {
        return resMainInfoService.selectByPrimaryKey(resMainInfoId);
    }
 
    /**
     * 查询资源列表功能
     */
    @ResponseBody
    @RequestMapping("ZiYuan/selectResMainInfojoinCatalog")
    @LogAction("资源管理,资源发布,资源列表查询,查询")
    public Result selectResMainInfojoinCatalog(Res_MainInfo resMainInfo, PageBean pageBean) {
        Page<Res_MainInfo> page = PageHelper.startPage(pageBean.getPage(), pageBean.getLimit());
        if (!SecurityUtils.getSubject().isPermitted("org_user_admin")) {
            resMainInfo.setExistPermission(getUserId().toString());
        }
 
        //alert ykm 2019/01/14
        if (resMainInfo.getCreateuserid() == null && resMainInfo.getFaburen() != null && !resMainInfo.getFaburen().equals("")) {
            String name = getUserIds(resMainInfo.getFaburen());
            resMainInfo.setFaburen(name);
        }
        if (resMainInfo.getCreateuserid() != null) {
            resMainInfo.setFaburen(null);
        }
 
        List<Res_MainInfo> mainInfoJoinCatalogList = resMainInfoService.selectAllMainInfo(resMainInfo);
        int countNums = (int) ((Page) mainInfoJoinCatalogList).getTotal();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        PageBean<Res_MainInfo> pageData = new PageBean<>(pageBean.getPage(), pageBean.getLimit(), countNums);
        pageData.setItems(mainInfoJoinCatalogList);
        LinkedHashMap<String, String> ResourceTypeList = FieldUtils.getFieldListByKey("ResourceType");// 获取资源类型列表
        StringBuilder rsb = new StringBuilder();
        String leixin = "";
 
        //修改因英文单引号 '和双引号" 导致的错误 alert ykm 2019/01/08
        List<Map<String, Object>> maps = new LinkedList<>();
        for (Integer i = 0; i < mainInfoJoinCatalogList.size(); i++) {
            leixin = ResourceTypeList.get(mainInfoJoinCatalogList.get(i).getResourceclass());
            String chinesename = orgUserService.getChinesename(mainInfoJoinCatalogList.get(i).getCreateuserid());
            String unitname = orgUnitService.getUnitName((long) mainInfoJoinCatalogList.get(i).getPubunitid());
            String mulu = GetBianMu(mainInfoJoinCatalogList.get(i).getCatlogid() == null ? 0 : mainInfoJoinCatalogList.get(i).getCatlogid());
 
            Map<String, Object> map = new HashMap<>();
            map.put("resourceid", mainInfoJoinCatalogList.get(i).getResourceid());
            map.put("title", mainInfoJoinCatalogList.get(i).getTitle());
            map.put("mulu", mulu);
            map.put("resourceclass", leixin);
            map.put("pubdate", sdf.format(mainInfoJoinCatalogList.get(i).getPubdate()));
            map.put("unitname", unitname);
            map.put("chinesename", chinesename);
            map.put("auditstatus", mainInfoJoinCatalogList.get(i).getAuditstatus());
            //add by zsx 2020/10/11
            map.put("resourcestatus", mainInfoJoinCatalogList.get(i).getResourcestatus());
            maps.add(map);
        }
        return Result.ok().put("topics", maps).put("totalCount", countNums);
    }
 
    /**
     * 查询资源所属目录
     *
     * @param Catlogid
     * @return
     */
    private String GetBianMu(int Catlogid) {
        String str = "";
        strMuLu = "";
        if (Catlogid > 0) {
            Res_Catalog zymlBianMu = resCatalogService.selectByPrimaryKey(Catlogid);
            String str2 = CheckBianMu(zymlBianMu);
            String[] res = str2.split(">");
            for (int i = res.length - 1; i >= 0; i--) {
                if (i == 0) {
                    str += res[i];
                } else {
                    str += res[i] + " > ";
                }
            }
        }
        return str;
    }
 
    /**
     * 递归获取资源目录名称
     *
     * @param zymlBianMu
     * @return
     */
    private String CheckBianMu(Res_Catalog zymlBianMu) {
        if (zymlBianMu != null) {
            strMuLu += zymlBianMu.getTitle() + ">";
            if (zymlBianMu.getParentid() == 0) {
                return strMuLu;
            } else {
                zymlBianMu = resCatalogService.selectByPrimaryKey(zymlBianMu.getParentid());
                CheckBianMu(zymlBianMu);
            }
        }
        return strMuLu;
    }
 
    @ResponseBody
    @RequestMapping("ZiYuan/GetMuLu")
    public String getMuLu(int id) {
        List<Res_Catalog> List = resCatalogService.selectResCatalogToParentid(id);
        String result = "{";
        result += "Count:" + List.size() + ",list:[";
        for (Res_Catalog model : List) {
            result += "{ ZIYUANMULUID:" + model.getCatlogid() + ",ZIYUANMC:'" + model.getTitle() + "'},";
        }
        if (List.size() > 0) {
            result = result.substring(0, result.length() - 1);
        }
        result += "]}";
        return result;
    }
 
    /**
     * 资源编辑页面
     *
     * @return
     */
    @RequestMapping("ZiYuan_Edit")
    public String ZiYuan_Edit() {
        return "FuWuZiYuan/ZiYuan_Edit";
    }
 
    /**
     * 查询目录结构
     */
    @ResponseBody
    @RequestMapping("selectMuLu")
    public String selectDirectoryStructure(int id) {
        List<Res_Catalog> resCatalogList = resCatalogService.selectResCatalogToParentid(id);
        String resCatalogJson = "";
        for (Res_Catalog resCatalog : resCatalogList) {
            int childCount = resCatalogService.selectResCatalogIsExistsSon(resCatalog.getCatlogid(),null);
            resCatalogJson += (resCatalogJson.length() > 0 ? "," : "") + "{id:" + resCatalog.getCatlogid() + ", code: '" + resCatalog.getCatlogcode() + "', name:'" + resCatalog.getTitle() + "', pId:" + resCatalog.getParentid() + ", rpId:" + resCatalog.getParentid();
            if (resCatalog.getIcon() == null || resCatalog.getIcon().length() == 0) {
                resCatalogJson += (childCount > 0 ? ",isParent:true,iconOpen:'/image/classicons/folderOpen.png',iconClose:'/image/classicons/folder.png'" : ",icon:'/image/classicons/defaulticon.png'") + "}";
            } else {
                resCatalogJson += (",isParent:true,icon:'" + "/uploadPath/" + resCatalog.getIcon()) + "'}";
            }
        }
        return "[" + resCatalogJson + "]";
    }
 
    /**
     * 访问查看页面编辑
     */
    @RequestMapping("ZiYuan/ziYuanSelect_Edit")
    public String ziYuanSelect_Edit(Model model, int resMainInfoId) throws IOException {
        // 收藏,用来判断登录的用户是否有收藏这个资源
        Res_ActionRecord resActionRecord = new Res_ActionRecord();
 
        Long userId = getUserId();
 
        resActionRecord.setUserid(userId);
        resActionRecord.setResourceid(resMainInfoId);
        resActionRecord.setActiontype("收藏");
        Res_ActionRecord res_actionRecord = resActionRecordService.getUserActionRecord(resActionRecord);
        if (res_actionRecord != null) {
            model.addAttribute("actionid", res_actionRecord.getActionid());
        }
 
        // 统计该资源的收藏次数
        Res_ActionRecord resActionRecord1 = new Res_ActionRecord();
        resActionRecord1.setActiontype("收藏");
        resActionRecord1.setResourceid(resMainInfoId);
        int countResult = resActionRecordService.selectResourceCount(resActionRecord1);
        model.addAttribute("shoucangcount", countResult);
 
        // 统计该资源的浏览次数
        Res_ActionRecord resActionRecord2 = new Res_ActionRecord();
        resActionRecord2.setActiontype("浏览");
        resActionRecord2.setResourceid(resMainInfoId);
        int countResult1 = resActionRecordService.selectResourceCount(resActionRecord2);
        model.addAttribute("liulancount", countResult1);
 
        // 统计该资源的调用次数
        Res_ActionRecord resActionRecord3 = new Res_ActionRecord();
        resActionRecord3.setActiontype("调用");
        resActionRecord3.setResourceid(resMainInfoId);
        int countResult2 = resActionRecordService.selectResourceCount(resActionRecord3);
        model.addAttribute("diaoyongcount", countResult2);
 
        Res_MainInfo res_mainInfo = new Res_MainInfo();
        // 修改
        res_mainInfo = resMainInfoService.selectByPrimaryKey(resMainInfoId);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String Pubdate = sdf.format(res_mainInfo.getPubdate());
        // 判断所属目录
        strMuLu = "";
        res_mainInfo.setCatlogcode(GetBianMu(res_mainInfo.getCatlogid()));
        // 判断发布单位
        String unitname = orgUnitService.getUnitName((long) res_mainInfo.getPubunitid());
        model.addAttribute("unitname", unitname);
        // res_mainInfo.setPubunitid(unitid);
        // 判断数据覆盖范围
        // modified by qufangxu 信创环境下,若 res_mainInfo.getAdministrativeid() = '        ',会返回单点登录页面,具体原因未知。 解决办法:提前去除空格、制表符
        String administrativeid = (String) res_mainInfo.getAdministrativeid();
        String finalValue = null;
        if (StringUtils.isNotEmpty(administrativeid)){
            finalValue = administrativeid.trim();
        }
        if (StringUtils.isNotEmpty(finalValue)) {
            String getRegionInfourl = sysConfig.getApiServer() + "/api/org/region/getById/" + administrativeid;
            String jsonStr = HttpOperateUtils.httpGet(getRegionInfourl.trim());
            if (jsonStr != null && !jsonStr.isEmpty()) {
                JSONObject item = JSONObject.parseObject(jsonStr);
                String regionname = item.getString("regionname");
                res_mainInfo.setAdministrativeid(regionname);
            }
        }
        // LinkedHashMap<String, String> ResourceTypeList =
        // FieldUtils.getFieldListByKey("ResourceType",
        // sysConfig.getApiServer();//获取资源类型列表
        // 获取是否有在申请表有申请RES_APPLYRECOMMEND
        Res_ApplyRecommend res_applyRecommend = new Res_ApplyRecommend();
        res_applyRecommend.setAppuserid(getUserId().toString());
        res_applyRecommend.setIsrecommend(0);
        res_applyRecommend.setResourceid(resMainInfoId);
        Res_ApplyRecommend applyRecommend = resApplyRecommendService.selectByResApplyRecommend(res_applyRecommend);
        String isApply = "True";// 先设为True
        if (applyRecommend != null && applyRecommend.getAuditresult() == 1) {
            isApply = "False";
        }
 
        // 判断资源类型
        String leixin = res_mainInfo.getResourceclass();
        if (leixin == null) leixin = "";
        // 判断该类型对应那张表,然后查询对应的表的字段
        // alert ykm 2019/02/26
        if (leixin.equals("KJ_SWMX") || leixin.equals("KJ_SWDX") || leixin.equals("KJ_SWYX")) leixin = "KJ_SW";
        switch (leixin) {
            case "KJ_JCDT":// 基础底图
                Res_ExtBaseMap resExtBaseMap = resExtBaseMapService.selectByPrimaryKey(resMainInfoId);
                if (resExtBaseMap != null) {
                    model.addAttribute("resExtBaseMap", resExtBaseMap);
                } else {
                    Res_ExtBaseMap resExtBaseMap1 = new Res_ExtBaseMap();
                    model.addAttribute("resExtBaseMap", resExtBaseMap1);
                }
                break;
            case "KJ_YWTC":// 业务图层
                Res_ExtBusinessLayer resExtBusinessLayer = resExtBusinessLayerService.selectByPrimaryKey(resMainInfoId);
                if (resExtBusinessLayer != null) {
                    model.addAttribute("resExtBusinessLayer", resExtBusinessLayer);
                } else {
                    Res_ExtBusinessLayer resExtBusinessLayer1 = new Res_ExtBusinessLayer();
                    model.addAttribute("resExtBusinessLayer", resExtBusinessLayer1);
                }
                break;
            case "KJ_KJFX":// 空间分析
                Res_ExtSpaceServerWithBLOBs resExtSpaceServerWithBLOBs = resExtSpaceServerService.selectByPrimaryKey(resMainInfoId);
                if (resExtSpaceServerWithBLOBs != null) {
                    model.addAttribute("resExtSpaceServerWithBLOBs", resExtSpaceServerWithBLOBs);
                } else {
                    Res_ExtSpaceServerWithBLOBs resExtSpaceServerWithBLOBs1 = new Res_ExtSpaceServerWithBLOBs();
                    model.addAttribute("resExtSpaceServerWithBLOBs", resExtSpaceServerWithBLOBs1);
                }
                break;
            case "KJ_ZTDT":// 专题地图
                Res_ExtThemeMap resExtThemeMap = resExtThemeMapService.selectByPrimaryKey(resMainInfoId);
                if (resExtThemeMap != null) {
                    model.addAttribute("resExtThemeMap", resExtThemeMap);
                } else {
                    Res_ExtThemeMap resExtThemeMap1 = new Res_ExtThemeMap();
                    model.addAttribute("resExtThemeMap", resExtThemeMap1);
                }
                break;
            // case "专题应用程序":
            // Res_ExtApp resExtApp =
            // resExtAppService.selectByPrimaryKey(resMainInfoId);
            // if (resExtApp != null) {
            // model.addAttribute("resExtApp", resExtApp);
            // } else {
            // Res_ExtApp resExtApp1 = new Res_ExtApp();
            // model.addAttribute("resExtApp", resExtApp1);
            // }
            // break;
            case "YWJC":// 业务集成
                Res_ExtIntegrate resExtIntegrate = resExtIntegrateService.selectByPrimaryKey(resMainInfoId);
                if (resExtIntegrate != null) {
                    model.addAttribute("resExtIntegrate", resExtIntegrate);
                } else {
                    Res_ExtIntegrate resExtIntegrate1 = new Res_ExtIntegrate();
                    model.addAttribute("resExtIntegrate", resExtIntegrate1);
                }
                break;
            case "SJWJ":// 数据文件
                Res_ExtFileSource resExtFileSource = resExtFileSourceService.selectByPrimaryKey(resMainInfoId);
                if (resExtFileSource != null) {
                    LinkedHashMap<String, String> filetypelist = FieldUtils.getFieldListByKey("FileType");
                    resExtFileSource.setFiletype(filetypelist.get(resExtFileSource.getFiletype()));
                    model.addAttribute("resExtFileSource", resExtFileSource);
                } else {
                    Res_ExtFileSource resExtFileSource1 = new Res_ExtFileSource();
                    model.addAttribute("resExtFileSource", resExtFileSource1);
                }
                break;
            case "SJKB":// 数据库表
                Res_ExtDataBase res_extDataBase = resExtDataBaseService.selectByMainInfoId(resMainInfoId);
                if (res_extDataBase != null) {
                    Res_ExtDataSource res_extDataSource = resExtDataSourceService.selectByPrimaryKey(res_extDataBase.getDatasourceid());
                    model.addAttribute("resExtDataBase", res_extDataBase);
                    model.addAttribute("resExtDataSource", res_extDataSource);
                } else {
                    res_extDataBase = new Res_ExtDataBase();
                    Res_ExtDataSource res_extDataSource = new Res_ExtDataSource();
                    model.addAttribute("resExtDataBase", res_extDataBase);
                    model.addAttribute("resExtDataSource", res_extDataSource);
                }
                break;
            case "JKFW":// 接口服务
                Res_ExtInterFaceService res_extInterFaceService = resExtInterFaceService.selectByPrimaryKey(resMainInfoId);
                if (res_extInterFaceService != null) {
                    model.addAttribute("resExtInterFaceService", res_extInterFaceService);
                } else {
                    res_extInterFaceService = new Res_ExtInterFaceService();
                    model.addAttribute("resExtInterFaceService", res_extInterFaceService);
                }
                break;
//            case "KJ_SWMX":// 三维模型
            case "KJ_SW":// 三维,三维模型,三维影像,三维地形
                Res_Ext3D res_ext3D = resExt3DService.selectByPrimaryKey(resMainInfoId);
                if (res_ext3D != null) {
                    model.addAttribute("resExt3D", res_ext3D);
                } else {
                    res_ext3D = new Res_Ext3D();
                    model.addAttribute("resExt3D", res_ext3D);
                }
                break;
        }
        model.addAttribute("Pubdate", Pubdate);
        model.addAttribute("mainInfo", res_mainInfo);
        model.addAttribute("resMainInfoId", resMainInfoId);
        model.addAttribute("resourceType", leixin);
        model.addAttribute("WuQZ", isApply);
 
        return "FuWuZiYuan/ZiYuanSelect_Edit";
    }
 
    /**
     * 删除主表信息
     */
    @ResponseBody
    @RequestMapping("deleteByPrimaryKey")
    @LogAction("资源管理,资源发布,资源删除,删除|zy")
    public int deleteByPrimaryKey(int resourceid, String title) {
        // 先查询id对应的资源类型是哪一个
        Res_MainInfo resMainInfo = resMainInfoService.selectByPrimaryKey(resourceid);
        String leixin = resMainInfo.getResourceclass();
        if (leixin == null) leixin = "";
        // 判断该类型对应那张表,然后先删除从表在删除主表
        //alert ykm 2019/02/26
        if (leixin.equals("KJ_SWMX") || leixin.equals("KJ_SWDX") || leixin.equals("KJ_SWYX")) leixin = "KJ_SW";
        switch (leixin) {
            case "KJ_JCDT":// 基础底图
                Res_ExtBaseMap resExtBaseMap = resExtBaseMapService.selectByPrimaryKey(resourceid);
                if (resExtBaseMap != null) {
                    resExtBaseMapService.deleteByPrimaryKey(resourceid);
                }
                break;
            case "KJ_YWTC":// 业务图层
                Res_ExtBusinessLayer resExtBusinessLayer = resExtBusinessLayerService.selectByPrimaryKey(resourceid);
                if (resExtBusinessLayer != null) {
                    resExtBusinessLayerService.deleteByPrimaryKey(resourceid);
                }
                break;
            case "KJ_KJFX":// 空间分析
                Res_ExtSpaceServerWithBLOBs resExtSpaceServerWithBLOBs = resExtSpaceServerService.selectByPrimaryKey(resourceid);
                if (resExtSpaceServerWithBLOBs != null) {
                    resExtSpaceServerService.deleteByPrimaryKey(resourceid);
                }
                break;
            case "KJ_ZTDT":// 专题地图
                Res_ExtThemeMap resExtThemeMap = resExtThemeMapService.selectByPrimaryKey(resourceid);
                if (resExtThemeMap != null) {
                    resExtThemeMapService.deleteByPrimaryKey(resourceid);
                }
                break;
            // case "专题应用程序":
            // Res_ExtApp resExtApp =
            // resExtAppService.selectByPrimaryKey(resourceid);
            // if (resExtApp != null) {
            // resExtAppService.deleteByPrimaryKey(resourceid);
            // }
            // break;
            case "YWJC":// 业务集成
                Res_ExtIntegrate resExtIntegrate = resExtIntegrateService.selectByPrimaryKey(resourceid);
                if (resExtIntegrate != null) {
                    resExtIntegrateService.deleteByPrimaryKey(resourceid);
                }
                break;
            case "SJWJ":// 数据文件
                Res_ExtFileSource resExtFileSource = resExtFileSourceService.selectByPrimaryKey(resourceid);
                if (resExtFileSource != null) {
                    resExtFileSourceService.deleteByPrimaryKey(resourceid);
                }
                //展现方式
                List<Res_FileSource_Way> resFileSourceWay = resFileSourceWayService.selectById(resourceid);
                if (resFileSourceWay != null && resFileSourceWay.size() > 0) {
                    resFileSourceWayService.deleteByPrimaryKey(resourceid);
                }
                break;
            case "SJKB":// 数据库表
                Res_ExtDataBase res_extDataBase = resExtDataBaseService.selectByMainInfoId(resourceid);
                if (res_extDataBase != null) {
                    resExtDataBaseService.deleteByPrimaryKey(resourceid);
                }
                break;
            case "JKFW":// 接口服务
                Res_ExtInterFaceService res_extInterFaceService = resExtInterFaceService.selectByPrimaryKey(resourceid);
                if (res_extInterFaceService != null) {
                    resExtInterFaceService.deleteByPrimaryKey(resourceid);
                }
                break;
//            case "KJ_SWMX":// 三维模型
            case "KJ_SW":// 三维,三维模型,三维地形,三维影像
                Res_Ext3D res_ext3D = resExt3DService.selectByPrimaryKey(resourceid);
                if (res_ext3D != null) {
                    resExt3DService.deleteByPrimaryKey(resourceid);
                }
                break;
        }
        //资源附件
        List<Res_Files> resFileList = resFileService.selectDataListForResourceid(resourceid);
        if (resFileList != null && resFileList.size() > 0) {
            resFileService.deleteByResourceid(resourceid);
        }
        //资源协议与地址
        List<Res_ExtMapUrl> resExtMapUrlList = resExtMapUrlService.selectByCondition(resourceid);
        if (resExtMapUrlList != null && resExtMapUrlList.size() > 0) {
            resExtMapUrlService.deleteByResourceId(resourceid);
        }
        //资源操作记录
        int resActionRecordCount = resActionRecordService.selectCountByResourceid(resourceid);
        if (resActionRecordCount > 0) {
            resActionRecordService.deleteByResourceid(resourceid);
        }
        //资源申请/推荐
        int resApplyRecommendCount = resApplyRecommendService.selectCountByResourceid(resourceid);
        if (resApplyRecommendCount > 0) {
            resApplyRecommendService.deleteByResourceid(resourceid);
        }
        //资源发布注销变更审核
        int resAuditCount = resAuditService.selectCountByResourceid(resourceid);
        if (resAuditCount > 0) {
            resAuditService.deleteByResourceid(resourceid);
        }
        //业务关联分析
        int resBusinessrefCount = resBusinessRefService.selectCountByResourceid(resourceid);
        if (resBusinessrefCount > 0) {
            resBusinessRefService.deleteByResourceid(resourceid);
        }
        //业务关联周边查询
        int resQueryAroundCount = resQueryAroundService.selectCountByResourceid(resourceid);
        if (resQueryAroundCount > 0) {
            resQueryAroundService.deleteByResourceid(resourceid);
        }
        //资源评价
        int resEvaluationCount = resEvaluationService.selectCountByResourceid(resourceid);
        if (resEvaluationCount > 0) {
            resEvaluationService.deleteByResourceid(resourceid);
        }
 
        //删除资源操作日志表数据  alert ykm 2019/03/19
        int resaction = resActionRecordService.selectCountByResourceid(resourceid);
        if (resaction > 0) {
            resActionRecordService.deleteByResourceid(resourceid);
        }
 
        //自定义图层未实现
        return resMainInfoService.deleteByPrimaryKey(resourceid);
    }
 
    /**
     * 访问资源审核页面
     */
    /* 插入资源编辑页面内容 */
    @RequestMapping("ZiYuanShenHe/Index")
    public String ziYuanShenHeIndex(Model model) {
        // 获取下拉框目录
        LinkedHashMap<String, String> ResourceTypeList = FieldUtils.getFieldListByKey("ResourceType");// 获取资源类型列表
        model.addAttribute("ResourceTypeList", ResourceTypeList);
        return "ZiYuanShenHe/Index";
    }
 
    @RequestMapping("ziYuanLiuLanInsert")
    @ResponseBody
    public String ziYuanLiuLanInsert() {
        Res_ActionRecord resActionRecord = new Res_ActionRecord();
        resActionRecord.setResourceid(1);
        resActionRecord.setUserid(getUserId());
        resActionRecord.setAppid(1);
        Timestamp audittime = new Timestamp(new Date().getTime());
        resActionRecord.setActiontime(audittime);
        resActionRecord.setActiontype("浏览");
        int result = resActionRecordService.insertSelective(resActionRecord);
 
        return "" + result;
    }
 
    /**
     * 查询资源审核列表功能(修改请到ResAuditController)
     */
    @ResponseBody
    @RequestMapping("selectResMainInfojoinAudit")
    public String selectResMainInfojoinAudit(Res_MainInfo resMainInfo, PageBean pageBean) {
        PageHelper.startPage(pageBean.getPage(), pageBean.getLimit());
        List<MainInfoJoinAudit> mainInfoJoinAuditList = resMainInfoService.selectResMainInfojoinAudit(resMainInfo);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        int countNums = (int) ((Page) mainInfoJoinAuditList).getTotal();
        PageBean<MainInfoJoinAudit> pageData = new PageBean<>(pageBean.getPage(), pageBean.getLimit(), countNums);
        pageData.setItems(mainInfoJoinAuditList);
        LinkedHashMap<String, String> ResourceTypeList = FieldUtils.getFieldListByKey("ResourceType");// 获取资源类型列表
        StringBuilder rsb = new StringBuilder();
        rsb.append("{'totalCount':'" + countNums + "','topics':[");
        for (Integer i = 0; i < mainInfoJoinAuditList.size(); i++) {
            if (i != 0) {
                rsb.append(",");
            }
            String resourceclass = ResourceTypeList.get(mainInfoJoinAuditList.get(i).getResourceclass());
            if (resourceclass == null) {
                resourceclass = "";
            }
            rsb.append("{'resourceid':'" + mainInfoJoinAuditList.get(i).getResourceid() + "','title':'" + mainInfoJoinAuditList.get(i).getTitle() + "','resourceclass':'" + resourceclass + "','pubunitid':'" + mainInfoJoinAuditList.get(i).getPubunitid() + "','pubdate':'" + sdf.format(mainInfoJoinAuditList.get(i).getPubdate()) + "','audituserid':'" + mainInfoJoinAuditList.get(i).getAudituserid() + "','auditstatus':'" + mainInfoJoinAuditList.get(i).getAuditstatus() + "'}");
        }
        rsb.append("]}");
        return rsb.toString();
    }
 
    /**
     * 资源注销 审核状态,为提交审核通过,则资源服务状态改为正常;如是注销,则修改审核状态为未提交(可以修改保存、提交、审核);
     *
     * @param resourceid
     * @return
     */
    @ResponseBody
    @RequestMapping("ZiYuan/SignOutResource")
    @LogAction("资源管理,资源发布,资源修改(注销),修改")
    public String signOutResource(int resourceid) {
        Res_MainInfo resMainInfo = resMainInfoService.selectByPrimaryKey(resourceid);// 获取资源信息
        int resourcestatus = 3;// 资源服务状态(0正常/1异常/3注销)
        resMainInfo.setResourcestatus(resourcestatus);// 设置资源状态为注销
        resMainInfo.setAuditstatus(0); // 设置资源状态为未提交
        int auditResult = resMainInfoService.updateByPrimaryKeySelective(resMainInfo);// 更新数据
 
        return "{success:true,msg:\"注销成功!\"}";
    }
 
    /**
     * 处理文件上传
     *
     * @param request
     * @param file
     * @param model
     * @return
     */
    @ResponseBody
    @RequestMapping("testuploadimg")
    public String download(HttpServletRequest request, @RequestParam("myFile") MultipartFile file, Model model) {
        if (file.isEmpty()) {
            return "No File";
        }
        String[] imgTypeArr = new String[]{"jpg", "png", "gif", "bmp", "jpeg"};
        String imgType = file.getContentType();// 获取文件格式
        boolean IsImg = false;// 文件格式检查状态
        // 判断上传文件格式
        for (int i = 0; i < imgTypeArr.length; i++) {
            if (imgType.toLowerCase().endsWith(imgTypeArr[i])) {
                IsImg = true;
                break;
            }
        }
 
        if (IsImg) {
            String uuid = UUID.randomUUID().toString().replaceAll("-", "");
 
            String name = file.getOriginalFilename();
            System.out.println("FileName:" + name);
 
            String fileType = name.substring(name.lastIndexOf("."));
 
            // image的名称
            String Filename = uuid + fileType;
            System.out.println("FileType:" + Filename);
 
            String size = FileUtils.byteCountToDisplaySize(file.getSize());
            System.out.println("FileSize:" + size);
            //数据库保存 MainInfo/asdf.jpg
            //path是本地地址
            String path = sysConfig.getUploadPath() + "MainInfo\\";
            File desFile = new File(path + Filename);
 
            String info = desFile.getAbsolutePath();
            System.out.println("info:" + info);
            try {
                FileUtils.copyInputStreamToFile(file.getInputStream(), desFile);
                //返回网络地址,然后存储在数据库
                return "MainInfo/" + Filename;
            } catch (IOException e) {
                e.printStackTrace();
                return "0";
            }
        }
 
        return "-1";
    }
 
    /**
     * 查询所有的资源
     */
    @ResponseBody
    @RequestMapping("ZiYuan/getAll")
    public String getAll() {
        List<Res_MainInfo> list = resMainInfoService.getAll();
        StringBuilder str = new StringBuilder();
        str.append("[");
        for (int i = 0; i < list.size(); i++) {
            if (i != 0) {
                str.append(",");
            }
            str.append("{");
            str.append("'title':'" + list.get(i).getTitle() + "',");
            str.append("'resourceid':'" + list.get(i).getResourceid() + "',");
            str.append("}");
        }
        str.append("]");
        return str.toString();
    }
 
    /**
     * 查询所有的资源,根据发布时间排序
     */
    @ResponseBody
    @RequestMapping("ZiYuan/getAllOrderByTime")
    public Result getAllOrderByTime() {
        List<Res_MainInfo> list = resMainInfoService.selectAllOrderByTime();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        List<Map<String, Object>> maps = new LinkedList<>();
        for (int i = 0; i < list.size(); i++) {
            Map<String, Object> map = new HashMap<>();
            map.put("title", list.get(i).getTitle());
            map.put("fulltitle", list.get(i).getTitle());
            map.put("resourceid", list.get(i).getResourceid());
            map.put("pubdate", sdf.format(list.get(i).getPubdate()));
            maps.add(map);
        }
        return Result.ok().put("result", maps);
    }
 
    // 导出excel
    @ResponseBody
    @RequestMapping("ZiYuan/excel")
    public String excel(HttpServletResponse response, Res_MainInfo resMainInfo) {
        List<Res_MainInfo> mainInfoJoinCatalogList = resMainInfoService.selectResMainInfojoinCatalog(resMainInfo);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        LinkedHashMap<String, String> ResourceTypeList = FieldUtils.getFieldListByKey("ResourceType");// 获取资源类型列表
        StringBuilder rsb = new StringBuilder();
        String leixin = "";
//        rsb.append("{'totalCount':'" + "");
//        rsb.append("','topics':[");
 
        List<Map<String, Object>> maps = new LinkedList<>();
        for (Integer i = 0; i < mainInfoJoinCatalogList.size(); i++) {
            leixin = ResourceTypeList.get(mainInfoJoinCatalogList.get(i).getResourceclass());
            String chinesename = orgUserService.getChinesename(mainInfoJoinCatalogList.get(i).getCreateuserid()); // obj.getString("chinesename");
            String unitname = orgUnitService.getUnitName((long) mainInfoJoinCatalogList.get(i).getPubunitid()); // obj1.getString("unitname");
            String mulu = GetBianMu(mainInfoJoinCatalogList.get(i).getCatlogid() == null ? 0 : mainInfoJoinCatalogList.get(i).getCatlogid());
 
            Map<String, Object> map = new HashMap<>();
            map.put("resourceid", mainInfoJoinCatalogList.get(i).getResourceid());
            map.put("title", mainInfoJoinCatalogList.get(i).getTitle());
            map.put("mulu", mulu);
            map.put("resourceclass", leixin);
            map.put("pubdate", sdf.format(mainInfoJoinCatalogList.get(i).getPubdate()));
            map.put("pubunitid", unitname);
            map.put("createuserid", chinesename);
            maps.add(map);
        }
 
        String a[] = {"资源id", "资源名称", "所属目录编码", "资源类型", "发布时间", "发布单位", "发布添加人"};
        try {
            String Filename = Excel.going(response, a, JSON.toJSONString(maps, SerializerFeature.WriteMapNullValue), sysConfig.getUploadPath() + "excel\\");
            String path2 = "/uploadPath/excel/";
            String desFile = path2 + Filename;
            System.out.println(desFile);
            return desFile;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
 
    // 获取最新的6条热门搜索
    @ResponseBody
    @GetMapping("/getTopHotSearch")
    public Result getTopHotSearch() {
        StringBuilder str = new StringBuilder();
        List<String> list = resMainInfoService.selectTopHotSearch();
        str.append("[");
 
        List<Map<String, Object>> maps = new LinkedList<>();
 
        for (int i = 0; i < list.size(); i++) {
            Map<String, Object> map = new HashMap<>();
            map.put("keyword", list.get(i));
            maps.add(map);
        }
        return Result.ok().put("result", maps);
    }
 
    /**
     * 发布时间 http://127.0.0.1:8082/res/ziyuanmulu/index?Menu=ZYZX&menuId=07在这个页面当中调用了
     */
    @ResponseBody
    @RequestMapping("/ZiYuan/getZiYuanFaBuQingKuangChartData")
    public String getZiYuanFaBuQingKuangChartData(String Method) {
        String ResultJson = "";
        String preJcdtSeries = "";
        String preYwtcSeries = "";
        String preZtdtSeries = "";
        String preWdcgSeries = "";
        String preQtSeries = "";
        String nowJcdtSeries = "";
        String nowYwtcSeries = "";
        String nowZtdtSeries = "";
        String nowWdcgSeries = "";
        String nowQtSeries = "";
        String Legend = "[{\"name\":\"基础底图\", \"icon\": \"rect\"},{\"name\":\"业务图层\", \"icon\": \"rect\"},{\"name\":\"专题地图\", \"icon\": \"rect\"},{\"name\":\"数据文件\", \"icon\": \"rect\"},{\"name\":\"其它\", \"icon\": \"rect\"}]";
        if (Method.equals("Month")) {
            String monstr = "[";
            Date nowDate = new Date();
            int nowmon = nowDate.getMonth(); // 记录当前的月份,并且生成X轴的字符
            int lastmon = 0;
            if (nowmon == 12) {
                lastmon = 13;
            } else {
                lastmon = nowmon + 1;
            }
            for (int j = nowmon; j >= 1; j--) {
                monstr = monstr + "\"" + j + "月\"" + ",";
            }
            for (int i = 12; i >= lastmon; i--) {
                monstr = monstr + "\"去年" + i + "月\"" + ",";
            }
 
            monstr = monstr.substring(0, monstr.length() - 1);
            monstr = monstr + "]";
            int Year = nowDate.getYear();
            int LastYear = Year - 1;
            List<GroupByPubDate> preMonthList = resMainInfoService.selectResMainInfoGroupByPubDate(LastYear);
            List<GroupByPubDate> nowMonthList = resMainInfoService.selectResMainInfoGroupByPubDate(Year);
            String[] zylxList = new String[]{"KJ_JCDT", "KJ_YWTC", "KJ_ZTDT", "SJWJ", "QT"};
            // 去年的月份资源拼接
            if (nowmon != 12) {
                // 去年资源发布数据统计,如果现在是12月则不统计去年的
                for (int i = 0; i < zylxList.length; i++) {
                    int j = 0;
                    switch (zylxList[i]) {
                        case "KJ_JCDT":
                            preJcdtSeries = Screen(preJcdtSeries, lastmon, preMonthList, "KJ_JCDT");
                            break;
                        case "KJ_YWTC":
                            preJcdtSeries = Screen(preJcdtSeries, lastmon, preMonthList, "KJ_YWTC");
                            break;
                        case "KJ_ZTDT":
                            preJcdtSeries = Screen(preJcdtSeries, lastmon, preMonthList, "KJ_ZTDT");
                            break;
                        case "SJWJ":
                            preJcdtSeries = Screen(preJcdtSeries, lastmon, preMonthList, "SJWJ");
                            break;
                        default:
                            preQtSeries = ScreenOther(preQtSeries, lastmon, preMonthList);
                            break;
                    }
                }
            }
            // 今年的资源拼接
            for (int i = 0; i < zylxList.length; i++) {
                String item = zylxList[i];
                // 今年的资源发布情况数据统计
                int j = 0;
                switch (item) {
                    case "KJ_JCDT":
                        nowJcdtSeries = MontageResource(nowJcdtSeries, nowmon, nowMonthList, "KJ_JCDT");
                        break;
                    case "KJ_YWTC":
                        nowJcdtSeries = MontageResource(nowJcdtSeries, nowmon, nowMonthList, "KJ_YWTC");
                        break;
                    case "KJ_ZTDT":
                        nowJcdtSeries = MontageResource(nowJcdtSeries, nowmon, nowMonthList, "KJ_ZTDT");
                        break;
                    case "SJWJ":
                        nowJcdtSeries = MontageResource(nowJcdtSeries, nowmon, nowMonthList, "SJWJ");
                        break;
                    default:
                        nowQtSeries = MontageResourceOther(nowQtSeries, nowmon, nowMonthList);
                        break;
                }
            }
            ResultJson = "{\"Legend\": " + Legend + ", \"xAxis\": " + monstr + ", \"Series\": {\"JcdtSeries\":[" + preJcdtSeries + nowJcdtSeries + "], \"YwtcSeries\": [" + preYwtcSeries + nowYwtcSeries + "], \"ZtdtSeries\": [" + preZtdtSeries + nowZtdtSeries + "],\"WdcgSeries\": [" + preWdcgSeries + nowWdcgSeries + "], \"prenowQtSeries\": [" + preQtSeries + nowQtSeries + "]}}";
        }
        return ResultJson;
    }
 
    //拼接资源(其他的)
    private String MontageResourceOther(String nowQtSeries, int nowmon, List<GroupByPubDate> nowMonthList) {
        int j;
        List<GroupByPubDate> qt = nowMonthList.stream().filter((GroupByPubDate b) -> b.getResourceclass() != "KJ_JCDT" && b.getResourceclass() != "KJ_YWTC" && b.getResourceclass() != "KJ_ZTDT" && b.getResourceclass() != "SJWJ").collect(Collectors.toList());
        // 降序是否正确
        Collections.sort(qt, new Comparator() {
            @Override
            public int compare(Object o1, Object o2) {
                if (o1 instanceof GroupByPubDate && o2 instanceof GroupByPubDate) {
                    GroupByPubDate e1 = (GroupByPubDate) o1;
                    GroupByPubDate e2 = (GroupByPubDate) o2;
                    return e2.getMonth() - e1.getMonth();
                }
                throw new ClassCastException("不能转换为GroupByPubDate类型");
            }
        });
        j = 0;
        for (int k = nowmon; k >= 1; k--) {
            List<GroupByPubDate> monList = null;
            switch (k) {
                case 1:
                    monList = qt.stream().filter((GroupByPubDate b) -> b.getMonth() == 1).collect(Collectors.toList());
                    break;
                case 2:
                    monList = qt.stream().filter((GroupByPubDate b) -> b.getMonth() == 2).collect(Collectors.toList());
                    break;
                case 3:
                    monList = qt.stream().filter((GroupByPubDate b) -> b.getMonth() == 3).collect(Collectors.toList());
                    break;
                case 4:
                    monList = qt.stream().filter((GroupByPubDate b) -> b.getMonth() == 4).collect(Collectors.toList());
                    break;
                case 5:
                    monList = qt.stream().filter((GroupByPubDate b) -> b.getMonth() == 5).collect(Collectors.toList());
                    break;
                case 6:
                    monList = qt.stream().filter((GroupByPubDate b) -> b.getMonth() == 6).collect(Collectors.toList());
                    break;
                case 7:
                    monList = qt.stream().filter((GroupByPubDate b) -> b.getMonth() == 7).collect(Collectors.toList());
                    break;
                case 8:
                    monList = qt.stream().filter((GroupByPubDate b) -> b.getMonth() == 8).collect(Collectors.toList());
                    break;
                case 9:
                    monList = qt.stream().filter((GroupByPubDate b) -> b.getMonth() == 9).collect(Collectors.toList());
                    break;
                case 10:
                    monList = qt.stream().filter((GroupByPubDate b) -> b.getMonth() == 10).collect(Collectors.toList());
                    break;
                case 11:
                    monList = qt.stream().filter((GroupByPubDate b) -> b.getMonth() == 11).collect(Collectors.toList());
                    break;
                case 12:
                    monList = qt.stream().filter((GroupByPubDate b) -> b.getMonth() == 12).collect(Collectors.toList());
                    break;
            }
            int total = 0;
            if (monList.size() > 0) {
                for (int z = 0; z < monList.size(); z++) {
                    total = total + monList.get(z).getCount();
                }
            }
 
            nowQtSeries += (nowQtSeries == "" ? "" : ",") + total;
            j++;
        }
        if (nowmon != 12) {
            nowQtSeries = nowQtSeries + ",";
        }
        return nowQtSeries;
    }
 
    //拼接资源(特定类型的)
    private String MontageResource(String nowJcdtSeries, int nowmon, List<GroupByPubDate> nowMonthList, String type) {
        int j;// 筛选类型为基础底图的集合
        List<GroupByPubDate> jcdt = nowMonthList.stream().filter((GroupByPubDate b) -> b.getResourceclass() == type).collect(Collectors.toList());
        // 降序是否正确
        Collections.sort(jcdt, new Comparator() {
            @Override
            public int compare(Object o1, Object o2) {
                if (o1 instanceof GroupByPubDate && o2 instanceof GroupByPubDate) {
                    GroupByPubDate e1 = (GroupByPubDate) o1;
                    GroupByPubDate e2 = (GroupByPubDate) o2;
                    return e2.getMonth() - e1.getMonth();
                }
                throw new ClassCastException("不能转换为GroupByPubDate类型");
            }
        });
        j = 0;
        for (int k = nowmon; k >= 1; k--) {
            if (k == nowmon) {
                if (jcdt.size() > 0) {
                    for (int x = k; x < jcdt.get(j).getMonth(); j++) {
                        // 由于分组采用倒序排序,此处保证开始统计的月份是当前月份
                    }
                }
            }
            if (j >= jcdt.size() || jcdt.get(j).getMonth() != k) {
                nowJcdtSeries += (nowJcdtSeries == "" ? "" : ",") + 0;
 
            } else {
                nowJcdtSeries += (nowJcdtSeries == "" ? "" : ",") + jcdt.get(j).getCount();
                j++;
            }
        }
        if (nowmon != 12) {
            nowJcdtSeries = nowJcdtSeries + ",";
        }
        return nowJcdtSeries;
    }
 
    // 筛选不同类型的集合(其他的)
    private String ScreenOther(String preQtSeries, int lastmon, List<GroupByPubDate> preMonthList) {
        List<GroupByPubDate> qt = preMonthList.stream().filter((GroupByPubDate b) -> b.getResourceclass() != "KJ_JCDT" && b.getResourceclass() != "KJ_YWTC" && b.getResourceclass() != "KJ_ZTDT" && b.getResourceclass() != "SJWJ").collect(Collectors.toList());
        // 降序是否正确
        Collections.sort(qt, new Comparator() {
            @Override
            public int compare(Object o1, Object o2) {
                if (o1 instanceof GroupByPubDate && o2 instanceof GroupByPubDate) {
                    GroupByPubDate e1 = (GroupByPubDate) o1;
                    GroupByPubDate e2 = (GroupByPubDate) o2;
                    return e2.getMonth() - e1.getMonth();
                }
                throw new ClassCastException("不能转换为GroupByPubDate类型");
            }
        });
        for (int k = 12; k >= lastmon; k--) {
            List<GroupByPubDate> monList = null;
            switch (k) {
                case 1:
                    monList = qt.stream().filter((GroupByPubDate b) -> b.getMonth() == 1).collect(Collectors.toList());
                    break;
                case 2:
                    monList = qt.stream().filter((GroupByPubDate b) -> b.getMonth() == 2).collect(Collectors.toList());
                    break;
                case 3:
                    monList = qt.stream().filter((GroupByPubDate b) -> b.getMonth() == 3).collect(Collectors.toList());
                    break;
                case 4:
                    monList = qt.stream().filter((GroupByPubDate b) -> b.getMonth() == 4).collect(Collectors.toList());
                    break;
                case 5:
                    monList = qt.stream().filter((GroupByPubDate b) -> b.getMonth() == 5).collect(Collectors.toList());
                    break;
                case 6:
                    monList = qt.stream().filter((GroupByPubDate b) -> b.getMonth() == 6).collect(Collectors.toList());
                    break;
                case 7:
                    monList = qt.stream().filter((GroupByPubDate b) -> b.getMonth() == 7).collect(Collectors.toList());
                    break;
                case 8:
                    monList = qt.stream().filter((GroupByPubDate b) -> b.getMonth() == 8).collect(Collectors.toList());
                    break;
                case 9:
                    monList = qt.stream().filter((GroupByPubDate b) -> b.getMonth() == 9).collect(Collectors.toList());
                    break;
                case 10:
                    monList = qt.stream().filter((GroupByPubDate b) -> b.getMonth() == 10).collect(Collectors.toList());
                    break;
                case 11:
                    monList = qt.stream().filter((GroupByPubDate b) -> b.getMonth() == 11).collect(Collectors.toList());
                    break;
                case 12:
                    monList = qt.stream().filter((GroupByPubDate b) -> b.getMonth() == 12).collect(Collectors.toList());
                    break;
            }
 
            int total = 0;
            if (monList.size() > 0) {
                for (int z = 0; z < monList.size(); z++) {
                    total = total + monList.get(z).getCount();
                }
            }
 
            preQtSeries += (preQtSeries == "" ? "" : ",") + total;
        }
        return preQtSeries;
    }
 
    // 筛选不同类型的集合(特定类型的)
    private String Screen(String preJcdtSeries, int lastmon, List<GroupByPubDate> preMonthList, String type) {
        int j;
        List<GroupByPubDate> jcdt = preMonthList.stream().filter((GroupByPubDate b) -> b.getResourceclass() == type).collect(Collectors.toList());
        // 降序是否正确
        Collections.sort(jcdt, new Comparator() {
            @Override
            public int compare(Object o1, Object o2) {
                if (o1 instanceof GroupByPubDate && o2 instanceof GroupByPubDate) {
                    GroupByPubDate e1 = (GroupByPubDate) o1;
                    GroupByPubDate e2 = (GroupByPubDate) o2;
                    return e2.getMonth() - e1.getMonth();
                }
                throw new ClassCastException("不能转换为GroupByPubDate类型");
            }
        });
        j = 0;
        for (int k = 12; k >= lastmon; k--) {
            if (j >= jcdt.size() || jcdt.get(j).getMonth() != k) {
                preJcdtSeries += (preJcdtSeries == "" ? "" : ",") + 0;
            } else {
                preJcdtSeries += (preJcdtSeries == "" ? "" : ",") + jcdt.get(j).getCount();
                j++;            }
        }
        return preJcdtSeries;
    }
 
    /**
     * 获取最新6笔资源推荐
     */
    @ResponseBody
    @RequestMapping("ZiYuan/getTopRecommend")
    public Result getTopRecommend(boolean isDiTuFuwu) {
        Long userid = getUserId();
        Long unitId = orgUserService.getDefaultUnit(userid).getUnitid();
        Res_ApplyRecommend resApplyRecommend = new Res_ApplyRecommend();
        resApplyRecommend.setAppuserid(userid.toString());
        resApplyRecommend.setAppunitid(unitId.toString());
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("appuserid", userid);
        paramMap.put("appunitid", unitId);
        if (isDiTuFuwu == true) {
            paramMap.put("isDiTuFuwu", getMapResourceClass());
        } else {
            paramMap.put("isDiTuFuwu", null);
        }
        List<Res_MainInfo> resMainInfoList = resApplyRecommendService.getTopRecommend(paramMap);
 
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        StringBuilder str = new StringBuilder();
        str.append("[");
 
        List<Map<String, Object>> maps = new LinkedList<>();
        for (int i = 0; i < resMainInfoList.size(); i++) {
            Map<String, Object> map = new HashMap<>();
            String description = resMainInfoList.get(i).getDescription();
            if (description != null && description.length() > 60) {
                description = description.substring(0, 60) + "...";
                try {
                    description = URLEncoder.encode(description, "utf-8").replace("+", "%20");
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
                map.put("description", description);
//                str.append("'description':'" + description + "',");
            } else {
                try {
                    if (description != null) {
                        description = URLEncoder.encode(description, "utf-8").replace("+", "%20");
                    } else description = "";
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
                map.put("description", description);
//                str.append("'description':'" + description + "',");
            }
            String fulldescription = resMainInfoList.get(i).getDescription();
            try {
                if (fulldescription != null)
                    fulldescription = URLEncoder.encode(fulldescription, "utf-8").replace("+", "%20");
                else fulldescription = "";
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            String path = null;
            if (resMainInfoList.get(i).getImgurl() != null && !resMainInfoList.get(i).getImgurl().isEmpty()) {
                if (resMainInfoList.get(i).getImgurl().startsWith("Atkas")) {//图集
                    path = "/image/" + resMainInfoList.get(i).getImgurl();
                    File file = new File(System.getProperty("user.dir") + "\\src\\main\\resources\\static" + ("/image/" + resMainInfoList.get(i).getImgurl()).replace("/", "\\"));
                    if (!file.exists()) {  //判断物理路径是否存在,不存在则默认
                        path = "/image/classimg/" + resMainInfoList.get(i).getResourceclass() + ".gif";
                    }
                } else {
                    path = "/uploadPath/" + resMainInfoList.get(i).getImgurl();
                    String filepath = sysConfig.getUploadPath() + resMainInfoList.get(i).getImgurl();
                    File file = new File(filepath);
                    if (!file.exists()) {  //判断物理路径是否存在,不存在则默认
                        path = "/image/classimg/" + resMainInfoList.get(i).getResourceclass() + ".gif";
                    }
                }
            } else {
                path = "/image/classimg/" + resMainInfoList.get(i).getResourceclass() + ".gif";
            }
            map.put("title", resMainInfoList.get(i).getTitle());
            map.put("fulldescription", fulldescription);
            map.put("resourceclass", resMainInfoList.get(i).getResourceclass());
            map.put("imgurl", path);
            map.put("pubdate", sdf.format(resMainInfoList.get(i).getPubdate()));
            map.put("resourceid", resMainInfoList.get(i).getResourceid());
 
            //判断是否有权限
            Map<String, Object> smap = new HashMap<>();
            smap.put("resourceid", resMainInfoList.get(i).getResourceid());
            smap.put("userid", getUserId());
            smap.put("unitid", unitId);
            int count = resMainInfoService.checkZiYuanQuanXian(smap);
            //有权限查看(1有,0没有)
            Integer isquanxian = 0;
            if (count > 0) {
                isquanxian = 1;
            }
            map.put("isquanxian", isquanxian);
            map.put("firstMapUrl", getZTDTByPortalMapUrl(resMainInfoList.get(i).getResourceid(), resMainInfoList.get(i).getResourceclass()));
            maps.add(map);
 
        }
//        str.append("]");
        //        String jsonEncoder = new sun.misc.BASE64Encoder().encode(str.toString().getBytes());
        return Result.ok().put("result", maps);
    }
 
    /**
     * 获取所有资源推荐
     *
     * @return
     */
    @ResponseBody
    @RequestMapping("ZiYuan/getAllRecommend")
    public Result getAllRecommend(boolean isDiTuFuwu) {
        Long userid = getUserId();
        Long unitId = orgUserService.getDefaultUnit(userid).getUnitid();
 
        Res_ApplyRecommend resApplyRecommend = new Res_ApplyRecommend();
        resApplyRecommend.setAppuserid(userid.toString());
        resApplyRecommend.setAppunitid(unitId.toString());
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("appuserid", userid);
        paramMap.put("appunitid", unitId);
        if (isDiTuFuwu) {
            paramMap.put("isDiTuFuwu", getMapResourceClass());
        } else {
            paramMap.put("isDiTuFuwu", null);
        }
        List<Res_MainInfo> resMainInfoList = resApplyRecommendService.getAllRecommend(paramMap);
 
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        StringBuilder str = new StringBuilder();
        str.append("[");
 
        List<Map<String, Object>> maps = new LinkedList<>();
        for (int i = 0; i < resMainInfoList.size(); i++) {
            Map<String, Object> map = new HashMap<>();
            map.put("title", resMainInfoList.get(i).getTitle());
            map.put("resourceid", resMainInfoList.get(i).getResourceid());
 
            if (resMainInfoList.get(i).getDescription().length() > 60) {
                String description = resMainInfoList.get(i).getDescription().substring(0, 60) + "...";
//                str.append("'description':'" + description + "',");
                map.put("description", description);
            } else {
                map.put("description", resMainInfoList.get(i).getDescription());
//                str.append("'description':'" + resMainInfoList.get(i).getDescription() + "',");
            }
            map.put("resourceclass", resMainInfoList.get(i).getResourceclass());
            String path = null;
            if (!resMainInfoList.get(i).getImgurl().isEmpty()) {
                path = "/uploadPath/" + resMainInfoList.get(i).getImgurl();
                String filepath = sysConfig.getUploadPath() + resMainInfoList.get(i).getImgurl();
                File file = new File(filepath);
                if (!file.exists()) {  //判断物理路径是否存在,不存在则默认
                    path = "/image/classimg/" + resMainInfoList.get(i).getResourceclass() + ".gif";
                }
            } else {
                path = "/image/classimg/" + resMainInfoList.get(i).getResourceclass() + ".gif";
            }
            map.put("imgurl", path);
            map.put("pubdate", sdf.format(resMainInfoList.get(i).getPubdate()));
            maps.add(map);
        }
        return Result.ok().put("result", maps);
    }
 
    // 获取地图服务的类型代码
    private String getMapResourceClass() {
        LinkedHashMap<String, String> resourceTypeList = FieldUtils.getFieldListByKey("ResourceType");
        Iterator<Map.Entry<String, String>> iter = resourceTypeList.entrySet().iterator();
        String dituTypes = "";
        while (iter.hasNext()) {
            Map.Entry entry = (Map.Entry) iter.next();
            Object key = entry.getKey();
            if (key.toString().startsWith("KJ_")) {
                dituTypes += "'" + key.toString() + "',";
            }
        }
        dituTypes = dituTypes.length() > 0 ? dituTypes.substring(0, dituTypes.length() - 1) : dituTypes;
        return dituTypes;
    }
 
    /**
     * 资源目录左侧面板目录结构
     *
     * @param id       节点ID
     * @param treeType 目录树类型(0:资源目录 4:资源类型)
     * @param XZQHID   区域ID
     * @param NF       时间
     * @param IsSC     是否收藏
     * @return String
     */
    @ResponseBody
    @RequestMapping("GetMuLuTreeData")
    public String getMuLuTreeData(Integer id, int treeType, String XZQHID, String NF, int IsSC, String catalogName, String ResourceClass,String spcStatus) {
        String result = "";
        if (id == null) id = 0;
        Map<String, Object> map = new HashMap<>();
        map.put("parentid", id);
        map.put("xzqhid", XZQHID);
        if (NF != null && !NF.isEmpty()) {
            map.put("nf", NF);
        }
        map.put("shoucang", IsSC);
        // added by qfx at 2021-09-15
        if(StringUtils.isNotEmpty(ResourceClass)){
            map.put("resourceclass",ResourceClass);
        }else{
            map.put("resourceclass","");
        }
        if (treeType == 0) {// 资源目录
            if (catalogName != null && !catalogName.isEmpty()) {
                catalogName = catalogName.replaceAll("%(?![0-9a-fA-F]{2})", "%25");//编码需要处理%号,判断%是否是十六进制编码后的%号
                //dsh 2018/12/12
                map.put("catalogName", URLDecoder.decode(catalogName));
            }
            map.put("spcStatus",spcStatus);
            List<Res_Catalog> resCatalogList = resCatalogService.getMuLuTreeData(map);
            for (Res_Catalog resCatalog : resCatalogList) {
                int childCount = resCatalogService.selectResCatalogIsExistsSon(resCatalog.getCatlogid(),spcStatus);
                result += (result.length() > 0 ? "," : "") + "{id:" + resCatalog.getCatlogid() + ", code: '" + resCatalog.getCatlogcode() + "', name:'" + resCatalog.getTitle() + "(" + GetZYCountByClassNew(0, resCatalog.getCatlogcode(), catalogName , ResourceClass,spcStatus) + ")', pId:" + resCatalog.getParentid() + ", rpId:" + resCatalog.getParentid() + (childCount > 0 ? ",isParent:true,iconOpen:'/image/classicons/folderOpen.png',iconClose:'/image/classicons/folder.png'" : ",icon:'/image/classicons/defaulticon.png'") + "}";
            }
        } else if (treeType == 4) {// 资源类型
            LinkedHashMap<String, String> ResourceTypeList = FieldUtils.getFieldListByKey("ResourceType");// 获取资源类型列表
            String kj = "";
            if (ResourceTypeList.size() > 0) {
                int count = 0;
                for (Map.Entry<String, String> entry : ResourceTypeList.entrySet()) {
                    if (entry.getKey().length() > 3 && entry.getKey().substring(0, 3).equals("KJ_")) {
                        kj += (kj.length() > 0 ? "," : "") + "{id:'" + entry.getKey() + "', code: '" + entry.getKey() + "', name:'" + entry.getValue() + "(" + GetZYCountByClassNew(4, "", "", entry.getKey(),spcStatus) + ")'" + ",icon:'/image/classicons/" + entry.getKey() + ".png'" + " }";
                    }
                }
                for (Map.Entry<String, String> entry : ResourceTypeList.entrySet()) {
                    if (entry.getKey().equals("KJ_")) {
                        result += (result.length() > 0 ? "," : "") + "{id:'" + entry.getKey() + "', code: '" + entry.getKey() + "', name:'" + entry.getValue() + "(" + GetZYCountByClassNew(4, "", "", entry.getKey(),spcStatus) + ")',open:true,children:[" + kj + "],iconOpen:'/image/classicons/folderOpen.png',iconClose:'/image/classicons/folder.png'}";
                    } else if (entry.getKey().length() > 3 && entry.getKey().substring(0, 3).equals("KJ_")) {
                        continue;
                    } else {
                        result += (result.length() > 0 ? "," : "") + "{id:'" + entry.getKey() + "', code: '" + entry.getKey() + "', name:'" + entry.getValue() + "(" + GetZYCountByClassNew(4, "", "", entry.getKey(),spcStatus) + ")'" + ",icon:'/image/classicons/" + entry.getKey() + ".png'" + "}";
                    }
                }
                System.out.println(result);
            }
        }
        if (id == 0 && treeType == 4) {
            result = "{id:0,name:'" + (treeType == 4 ? "资源类型" : "资源目录") + "(" + GetZYCountByClassNew(0, "", "", ResourceClass,spcStatus) + ")',pId:-1,isParent:true,open:true,children:[" + result + "],iconOpen:'/image/classicons/folderOpen.png',iconClose:'/image/classicons/folder.png' }";
        }
        return "[" + result + "]";
    }
 
    /**
     * 根据名称拼音 显示名字
     */
    @ResponseBody
    @RequestMapping("/user/findUserByWord")
    public String findUserByWord(String keyWord, HttpServletRequest request) {
        String callbackFunName = request.getParameter("callback");
        if (callbackFunName == null || callbackFunName.isEmpty()) {
            callbackFunName = "callback";
        }
        String url = sysConfig.getApiServer() + "/api/org/user/findUserByWord/" + URLEncoder.encode(keyWord);
        String username = null;
        try {
            username = HttpOperateUtils.httpGet(url);
        } catch (IOException e) {
            e.printStackTrace();
        }
        StringBuilder Json = new StringBuilder();
        Json.append(username);
        //System.out.print("test:==============" + Json.toString());
        //return Json.toString();
        return callbackFunName + "(" + Json.toString() + ")";
    }
 
    /**
     * 资源查看页面新版
     */
    @RequestMapping("ZiYuan/ZiYuanBaseInfo")
    public String ziYuanBaseInfo(Integer resourceid, Model model, HttpServletRequest request) {
        Long userId = getUserId();  //获取用户ID
        OrgUnit orgUnit = getUnit();//获取用户单位信息
        model.addAttribute("backstageWebRoot", sysConfig.getApiServer() + "/"); // 后台服务路径
        model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot()); // 公共资源库路径
        model.addAttribute("systemName", sysConfig.getAppFullName());
        model.addAttribute("gisPortal", sysConfig.getGisPortal());
        model.addAttribute("userId", String.valueOf(userId));
        Res_MainInfo res_mainInfo = new Res_MainInfo();
        String integratetype = "";
        String integrateurl = "";
        // 修改
        res_mainInfo = resMainInfoService.selectByPrimaryKey(resourceid);
        if (res_mainInfo == null) {
            model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
            model.addAttribute("systemName", sysConfig.getAppFullName());
            model.addAttribute("message", "资源已被删除,无法查看!");
            return "ResManage/ResRegister/ZiYuanErrorPage";
        }
        if (res_mainInfo != null) {
            //判断显示是否未提交、未审核、审核未通过
            if (res_mainInfo.getAuditstatus() == 0) {
                String html = "";
                html += "<span style='font-size: 14px;'>【<font style='color:white;' '>未提交</font>】</span>";
                model.addAttribute("shenhe", html);
            } else if (res_mainInfo.getAuditstatus() == 1) {
                String html = "";
                html += "<span style='font-size: 14px;'>【<font style='color:white;' '>未审核</font>】</span>";
                model.addAttribute("shenhe", html);
            } else if (res_mainInfo.getAuditstatus() == 3) {
                String html = "";
                html += "<span style='font-size: 14px;'>【<font style='color:white;' '>审核未通过</font>】</span>";
                model.addAttribute("shenhe", html);
            }
 
            // 收藏,用来判断登录的用户是否有收藏这个资源
            Res_ActionRecord resActionRecord = new Res_ActionRecord();
            resActionRecord.setUserid(userId);
            resActionRecord.setResourceid(resourceid);
            resActionRecord.setActiontype("收藏");
            Res_ActionRecord res_actionRecord = resActionRecordService.getUserActionRecord(resActionRecord);
            if (res_actionRecord != null) {
                model.addAttribute("actionid", res_actionRecord.getActionid());//已收藏
            } else {
                model.addAttribute("actionid", 0);//未收藏
            }
 
            // 统计该资源的收藏次数
            Res_ActionRecord resActionRecord1 = new Res_ActionRecord();
            resActionRecord1.setActiontype("收藏");
            resActionRecord1.setResourceid(resourceid);
            int countResult = resActionRecordService.selectResourceCount(resActionRecord1);
            model.addAttribute("shoucangcount", countResult);
 
            // 统计该资源的浏览次数
            Res_ActionRecord resActionRecord2 = new Res_ActionRecord();
            resActionRecord2.setActiontype("浏览");
            resActionRecord2.setResourceid(resourceid);
            int countResult1 = resActionRecordService.selectResourceCount(resActionRecord2);
            model.addAttribute("liulancount", countResult1);
 
            // 统计该资源的调用次数
            Res_ActionRecord resActionRecord3 = new Res_ActionRecord();
            resActionRecord3.setActiontype("调用");
            resActionRecord3.setResourceid(resourceid);
            int countResult2 = resActionRecordService.selectResourceCount(resActionRecord3);
            model.addAttribute("diaoyongcount", countResult2);
 
            // 统计该资源的申请次数
            Res_ApplyRecommend resApplyRecommend = new Res_ApplyRecommend();
            resApplyRecommend.setResourceid(resourceid);
            //alter: Xxx 资源申请数量统计完善 20181227
            int shenqingcount = resApplyRecommendService.getApplyCount(resourceid);
            model.addAttribute("shenqingcount", shenqingcount);
 
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            SimpleDateFormat sdfmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String Pubdate = sdf.format(res_mainInfo.getPubdate());
            // 判断所属目录
            strMuLu = "";
            res_mainInfo.setCatlogcode(GetBianMu(res_mainInfo.getCatlogid()));
            // 判断发布单位
            String unitname = orgUnitService.getUnitById((long) res_mainInfo.getPubunitid()).getUnitname();
            model.addAttribute("unitname", unitname);
            // res_mainInfo.setPubunitid(unitid);
            // 判断数据覆盖范围
            // modified by qufangxu 信创环境下,若 res_mainInfo.getAdministrativeid() = '        ',会返回单点登录页面,具体原因未知。 解决办法:提前去除空格、制表符
            String administrativeid = (String) res_mainInfo.getAdministrativeid();
            String finalValue = null;
            if (StringUtils.isNotEmpty(administrativeid)){
                finalValue = administrativeid.trim();
            }
            if (StringUtils.isNotEmpty(finalValue)) {
                String getRegionInfourl = sysConfig.getApiServer() + "/api/org/region/getById/" + administrativeid;
                String jsonStr = "";
                try {
                    jsonStr = HttpOperateUtils.httpGet(getRegionInfourl.trim());
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (jsonStr != null && !jsonStr.isEmpty()) {
                    JSONObject item = JSONObject.parseObject(jsonStr);
                    String regionname = item.getString("regionname");
                    res_mainInfo.setAdministrativeid(regionname);
                }
            }
 
            //申请按钮控制
            Integer isApply = -1;//-1 发布人、完全公开、已有记录且审核过且未超过有效截止时间,不显示申请按钮  1 已申请未批复
            //如果当前用户是管理员则不显示申请按钮
            if (!SecurityUtils.getSubject().isPermitted("org_user_admin")) {
                if (!res_mainInfo.getCreateuserid().equals(userId) && !res_mainInfo.getSharprotocol().equals("完全公开") && !(res_mainInfo.getSharprotocol().equals("单位内公开") && res_mainInfo.getPubunitid() == orgUnit.getUnitid().intValue())) {
                    // 获取是否有在申请表有申请RES_APPLYRECOMMEND
                    Map<String, Object> map = new HashMap<>();
                    map.put("resourceid", resourceid);
                    map.put("userid", userId);
                    map.put("unitid", orgUnit.getUnitid());
                    Res_ApplyRecommend recommend = resApplyRecommendService.checkZiYuanShenQing(map);
                    if (recommend != null) {
                        if (recommend.getAuditresult().equals(0)) {//已申请未批复
                            isApply = 1;
                        }else if(recommend.getAuditresult().equals(2)){//已批复未通过
                            isApply = 0;
                        }
                        else {//申请批复后时间没有过
                            Long timenum = new Date().getTime();
                            if (recommend.getEffendtime() != null && timenum < recommend.getEffendtime().getTime()) {
                                isApply = -1;
                            } else if (recommend.getEffendtime() == null) {//批复时间为空,代表永久
                                isApply = -1;
                            } else {
                                isApply = 0;
                            }
                        }
                    } else {
                        isApply = 0;
                    }
                }
            }
 
            //订阅按钮控制
            Integer isDingYue = -1;
            if (res_mainInfo.getResourceclass().equals("SJKB")) {
                isDingYue = 0;  //2018.08.01  自己也可以订阅自己发布的资源,亦可多次订阅同一个资源
                //                Res_Subscriptions sub = new Res_Subscriptions();
                //                sub.setAppuserid(getUserId().toString());
                //                sub.setResourceid(resourceid);
                //                Res_Subscriptions subscriptions = resSubscriptionsService.selectSubscriptionsByUser(sub);
                //                if(subscriptions != null){
                //                    isDingYue = 1;
                //                }
            }
            model.addAttribute("dingyue", isDingYue);
 
            // 判断资源类型
            String leixin = res_mainInfo.getResourceclass();
            if (leixin == null) leixin = "";
            // 判断该类型对应那张表,然后查询对应的表的字段
            switch (leixin) {
                case "SJWJ":// 数据文件(有用误删)
                    Res_ExtFileSource resExtFileSource = resExtFileSourceService.selectByPrimaryKey(resourceid);
                    if (resExtFileSource != null) {
                        LinkedHashMap<String, String> filetypelist = FieldUtils.getFieldListByKey("FileType");
                        resExtFileSource.setFiletype(filetypelist.get(resExtFileSource.getFiletype()));
                        //判断是否有权限
                        Map<String, Object> map = new HashMap<>();
                        map.put("resourceid", resourceid);
                        map.put("userid", userId);
                        OrgUser user = getUser();
                        map.put("unitid", orgUserService.getDefaultUnit(user.getUserid()).getUnitid());
                        int count = resMainInfoService.checkZiYuanQuanXian(map);
                        //有权限查看
                        if (count > 0) {
                            SelectFileUrl(resourceid, model, request, resExtFileSource);
                            model.addAttribute("XianShiWenJian", 1);//1代表可以显示
                        } else {
                            model.addAttribute("XianShiWenJian", 0);//0代表不可以显示
                        }
 
                        model.addAttribute("resExtFileSource", resExtFileSource);
                    } else {
                        Res_ExtFileSource resExtFileSource1 = new Res_ExtFileSource();
                        model.addAttribute("resExtFileSource", resExtFileSource1);
                    }
                    break;
                case "SJKB":// 数据库表(有用误删)
 
                    //查询该笔资源的订阅次数,订阅的相关信息
                    Map<String, Object> smap = new HashMap<String, Object>();
                    smap.put("resourceid", resourceid);
                    if (!SecurityUtils.getSubject().isPermitted("org_user_admin") && userId != res_mainInfo.getCreateuserid()) {
                        smap.put("appuserid", getUserId());
                    }
                    List<Res_Subscriptions> subscriptionsList = resSubscriptionsService.selectByResourceIdList(smap);
                    model.addAttribute("dingyuecount", subscriptionsList.size());
                    boolean isDingYueList = false;
                    if (subscriptionsList.size() > 0) {
                        List<DingYue> dingYues = new ArrayList<DingYue>();
                        for (int i = 0; i < subscriptionsList.size(); i++) {
                            DingYue dingYue = new DingYue();
                            OrgUser user = orgUserService.queryObject(Long.parseLong(subscriptionsList.get(i).getAppuserid()));
                            OrgUnit unit = orgUserService.getDefaultUnit(Long.parseLong(subscriptionsList.get(i).getAppuserid()));
                            dingYue.setUsername(user.getChinesename());
                            dingYue.setUnit(unit.getUnitname());
                            Res_ExtDataSource dataSource = resExtDataSourceService.selectByPrimaryKey(subscriptionsList.get(i).getDatasourceid());
                            if (dataSource != null) {
                                dingYue.setDatabasetype(dataSource.getDatabasetype());
                            }
                            dingYue.setSyncmessage(subscriptionsList.get(i).getSyncmessage());
                            dingYue.setHangup(subscriptionsList.get(i).getHangup());
                            dingYue.setTablename(subscriptionsList.get(i).getTablename());
                            dingYue.setLastupdate(sdfmt.format(subscriptionsList.get(i).getLastupdate()));
                            dingYue.setAppdate(sdfmt.format(subscriptionsList.get(i).getAppdate()));
                            dingYue.setId(subscriptionsList.get(i).getAppid());
                            dingYue.setSyncresult(subscriptionsList.get(i).getSyncresult());
                            dingYue.setAuditresult(subscriptionsList.get(i).getAuditresult());
                            if (userId == res_mainInfo.getCreateuserid() && !SecurityUtils.getSubject().isPermitted("org_user_admin")) {
                                dingYue.setFlag("1");
                            } else {
                                dingYue.setFlag("0");
                            }
                            dingYues.add(dingYue);
                        }
                        isDingYueList = true;
                        model.addAttribute("dingYues", dingYues);
                    }
                    model.addAttribute("isDingYueList", isDingYueList);
 
                    Res_ExtDataBase res_extDataBase = resExtDataBaseService.selectByMainInfoId(resourceid);
                    if (res_extDataBase != null) {
                        Res_ExtDataSource resExtDataSource = resExtDataSourceService.selectByPrimaryKey(res_extDataBase.getDatasourceid());
                        //开始拼接sql,然后判断是哪个数据库
                        String leirong = null;
                        JSONArray leirongjson = null;
                        JSONArray leirongjsonTwo = null;
                        if (resExtDataSource != null) { //缺少null值处理 alert 2018/12/27
                            if (resExtDataSource.getDatabasetype().equalsIgnoreCase("SQLServer")) {
                                String sql = "SELECT  convert(varchar(100),col.name) AS name , " + "convert(varchar(100),ISNULL(ep.[value], '') ) AS ColumnDescription ," + "t.name AS DataType,col.length AS ColLength, " + "convert(varchar(100),ISNULL(COLUMNPROPERTY(col.id, col.name, 'Scale'), 0) )  AS XiaoShuNum," + "CASE WHEN col.isnullable = 1 THEN '否' ELSE '是'  END AS Required " + "FROM dbo.syscolumns col  LEFT  JOIN dbo.systypes t " + "ON col.xtype = t.xusertype  inner JOIN dbo.sysobjects obj " + "ON col.id = obj.id AND obj.xtype = 'U' AND obj.status >= 0  LEFT  JOIN dbo.syscomments comm " + "ON col.cdefault = comm.id  LEFT  JOIN sys.extended_properties ep " + "ON col.id = ep.major_id " + "AND col.colid = ep.minor_id  " + "AND ep.name = 'MS_Description' LEFT  JOIN sys.extended_properties epTwo " + "ON obj.id = epTwo.major_id AND epTwo.minor_id = 0  AND epTwo.name = 'MS_Description'  " + "WHERE   obj.name = '" + res_extDataBase.getTablename() + "' ORDER BY col.name";
                                leirong = JDBCUtils.SqlServerConnUtils(resExtDataSource.getServeraddress(), resExtDataSource.getDatabasename(), resExtDataSource.getUsername(), resExtDataSource.getPassword(), sql);
                                leirongjson = JSONArray.parseArray(leirong);
                                //获取我设置的别名
                                DataBaseLeftDataSource database = resExtDataBaseService.selectBaseLeftSource(resourceid);
                                JSONObject sqlObj = JSON.parseObject(database.getFieldconfig());
                                //sqlObj 为 null 报错,缺少空值处理。ccr add
                                if (sqlObj != null) {
                                    if (leirongjson.getJSONObject(0).get("success").toString().equals("true")) {
                                        JSONArray jsarr = JSONArray.parseArray(sqlObj.getString("sql"));
                                        leirongjsonTwo = new JSONArray();
                                        JSONArray obj = JSONArray.parseArray(leirongjson.getJSONObject(0).get("data").toString());
                                        int k = 0;
//                                    for (int j = 0; j < obj.size(); j++) {
//                                        BiaoJieGou biaoJieGou = JSONUtil.toBean(obj.get(j).toString(), BiaoJieGou.class);
//                                        biaoJieGou.setColumnDescription("");
//                                        for (int i = 0; i < jsarr.size(); i++) {
//                                            ZiDuanPeiZi ziDuanPeiZi = JSONUtil.toBean(jsarr.get(i).toString(), ZiDuanPeiZi.class);
//                                            if (ziDuanPeiZi.getZiDuanName().equals(biaoJieGou.getName())) {
//                                                biaoJieGou.setColumnDescription(ziDuanPeiZi.getZiDuanBieMing());
//                                            }
//                                        }
//                                        JSONObject Json = (JSONObject) JSONObject.toJSON(biaoJieGou);
//                                        if (!biaoJieGou.getColumnDescription().equals("")) {
//                                            leirongjsonTwo.set(k, Json);
//                                            k++;
//                                        }
//                                    }
                                        //update dsh 2018/12/28
                                        for (int i = 0; i < jsarr.size(); i++) {
                                            for (int j = 0; j < obj.size(); j++) {
                                                BiaoJieGou biaoJieGou = JSONUtil.toBean(obj.get(j).toString(), BiaoJieGou.class);
                                                ZiDuanPeiZi ziDuanPeiZi = JSONUtil.toBean(jsarr.get(i).toString(), ZiDuanPeiZi.class);
                                                if (ziDuanPeiZi.getZiDuanName().equals(biaoJieGou.getName())) {
                                                    biaoJieGou.setColumnDescription(ziDuanPeiZi.getZiDuanBieMing());
                                                    JSONObject Json = (JSONObject) JSONObject.toJSON(biaoJieGou);
                                                    leirongjsonTwo.set(k, Json);
                                                    k++;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            if (resExtDataSource.getDatabasetype().equalsIgnoreCase("Oracle")) {
                                String sql = "select" + "    A.column_name as \"name\"," + " B.comments \"ColumnDescription\"," + " A.data_type \"DataType\"," + " A.data_length \"ColLength\"," + " nvl(A.Data_Scale,0)  \"XiaoShuNum\"," + " CASE WHEN A.nullable = 'Y' THEN '否' ELSE '是'  END AS \"Required\" " + " from" + "    user_tab_columns A,user_col_comments B" + " where" + "    A.Table_Name = B.Table_Name" + "    and A.Column_Name = B.Column_Name" + "    and A.Table_Name = '" + res_extDataBase.getTablename() + "'";
                                leirong = JDBCUtils.OracleConnUtils(resExtDataSource.getServeraddress(), resExtDataSource.getDatabasename(), resExtDataSource.getUsername(), resExtDataSource.getPassword(), resExtDataSource.getPort(), sql);
                                leirongjson = JSONArray.parseArray(leirong);
                                //获取我设置的别名
                                DataBaseLeftDataSource database = resExtDataBaseService.selectBaseLeftSource(resourceid);
                                JSONObject sqlObj = JSON.parseObject(database.getFieldconfig());
                                //sqlObj 为 null 报错,缺少空值处理。ccr add
                                if (sqlObj != null) {
                                    if (leirongjson.getJSONObject(0).get("success").toString().equals("true")) {
                                        JSONArray jsarr = JSONArray.parseArray(sqlObj.getString("sql"));
                                        leirongjsonTwo = new JSONArray();
                                        JSONArray obj = JSONArray.parseArray(leirongjson.getJSONObject(0).get("data").toString());
                                        int k = 0;
//                                    for (int j = 0; j < obj.size(); j++) {
//                                        BiaoJieGou biaoJieGou = JSONUtil.toBean(obj.get(j).toString(), BiaoJieGou.class);
//                                        biaoJieGou.setColumnDescription("");
//                                        for (int i = 0; i < jsarr.size(); i++) {
//                                            ZiDuanPeiZi ziDuanPeiZi = JSONUtil.toBean(jsarr.get(i).toString(), ZiDuanPeiZi.class);
//                                            if (ziDuanPeiZi.getZiDuanName().equals(biaoJieGou.getName())) {
//                                                biaoJieGou.setColumnDescription(ziDuanPeiZi.getZiDuanBieMing());
//                                            }
//                                        }
//                                        JSONObject Json = (JSONObject) JSONObject.toJSON(biaoJieGou);
//                                        if (!biaoJieGou.getColumnDescription().equals("")) {
//                                            leirongjsonTwo.set(k, Json);
//                                            k++;
//                                        }
//                                    }
                                        //update dsh 2018/12/28
                                        for (int i = 0; i < jsarr.size(); i++) {
                                            for (int j = 0; j < obj.size(); j++) {
                                                BiaoJieGou biaoJieGou = JSONUtil.toBean(obj.get(j).toString(), BiaoJieGou.class);
                                                ZiDuanPeiZi ziDuanPeiZi = JSONUtil.toBean(jsarr.get(i).toString(), ZiDuanPeiZi.class);
                                                if (ziDuanPeiZi.getZiDuanName().equals(biaoJieGou.getName())) {
                                                    biaoJieGou.setColumnDescription(ziDuanPeiZi.getZiDuanBieMing());
                                                    JSONObject Json = (JSONObject) JSONObject.toJSON(biaoJieGou);
                                                    leirongjsonTwo.set(k, Json);
                                                    k++;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        model.addAttribute("leirongjson", leirongjsonTwo);
                        model.addAttribute("resExtDataBase", res_extDataBase);
                        model.addAttribute("resExtDataSource", resExtDataSource);
                    } else {
                        res_extDataBase = new Res_ExtDataBase();
                        JSONArray leirongjsonTwo = null;
                        Res_ExtDataSource res_extDataSource = new Res_ExtDataSource();
                        model.addAttribute("leirongjson", leirongjsonTwo);
                        model.addAttribute("resExtDataBase", res_extDataBase);
                        model.addAttribute("resExtDataSource", res_extDataSource);
                    }
                    break;
                case "JKFW":// 接口服务(有用误删)
                    Res_ExtInterFaceService res_extInterFaceService = resExtInterFaceService.selectByPrimaryKey(resourceid);
                    model.addAttribute("show", 0);
                    //接口说明是否显示 1为显示
                    model.addAttribute("ShuoMing", 0);
                    if (res_extInterFaceService != null) {
                        if (res_extInterFaceService.getServertype().equals("WebService")) {
                            //判断是否有权限
                            Map<String, Object> map = new HashMap<>();
                            map.put("resourceid", resourceid);
                            map.put("userid", userId);
                            OrgUser user = getUser();
                            map.put("unitid", orgUserService.getDefaultUnit(user.getUserid()).getUnitid());
                            int count = resMainInfoService.checkZiYuanQuanXian(map);
                            //>0就是有权限
                            if (count > 0) {
                                res_extInterFaceService.setHelpurl(StringEscapeUtils.unescapeHtml(res_extInterFaceService.getHelpurl()));
                                model.addAttribute("helpurl", res_extInterFaceService.getHelpurl());
                                model.addAttribute("resExtInterFaceService", res_extInterFaceService);
                                model.addAttribute("show", 1);
                                model.addAttribute("ShuoMing", 0);
 
                                //查询相关的附件
                                List<Res_Files> res_filesList = resFileService.selectDataListForResourceid(resourceid);
                                model.addAttribute("resFileList", res_filesList);
                            } else {
                                res_extInterFaceService.setHelpurl(StringEscapeUtils.unescapeHtml(res_extInterFaceService.getHelpurl()));
                                model.addAttribute("helpurl", res_extInterFaceService.getHelpurl());
                                model.addAttribute("resExtInterFaceService", res_extInterFaceService);
                                model.addAttribute("show", 0);
                                model.addAttribute("ShuoMing", 0);
                            }
                        } else {
                            res_extInterFaceService.setHelpurl(StringEscapeUtils.unescapeHtml(res_extInterFaceService.getHelpurl()));
                            model.addAttribute("helpurl", res_extInterFaceService.getHelpurl());
                            model.addAttribute("show", 0);
                            model.addAttribute("ShuoMing", 1);
                            model.addAttribute("resExtInterFaceService", res_extInterFaceService);
                        }
                    } else {
                        res_extInterFaceService = new Res_ExtInterFaceService();
                        model.addAttribute("show", 0);
                        model.addAttribute("resExtInterFaceService", res_extInterFaceService);
                    }
                    break;
                case "YWJC":
                    Res_ExtIntegrate resExtIntegrate = resExtIntegrateService.selectByPrimaryKey(resourceid);
                    integratetype = resExtIntegrate.getIntegratetype() != null ? resExtIntegrate.getIntegratetype() : "";
                    //判断是否有权限
                    Map<String, Object> map = new HashMap<>();
                    map.put("resourceid", resourceid);
                    map.put("userid", getUserId());
                    map.put("unitid", orgUnit.getUnitid());
                    if (resMainInfoService.checkZiYuanQuanXian(map) > 0) {
                        integrateurl = resExtIntegrate.getServerurl() != null ? resExtIntegrate.getServerurl() : "";
                    }
                    break;
                case "KJ_KJFX": //空间分析
                    Res_ExtSpaceServer res_extSpaceServer = resExtSpaceServerService.selectByPrimaryKey(resourceid);
                    //判断是否有权限
                    if (res_extSpaceServer != null) {
                        if (checkZiYuanQuanXian(resourceid) > 0) {
                            model.addAttribute("helpurl", res_extSpaceServer.getHelpurl());
                            model.addAttribute("show", 1);
 
                            //查询相关的附件
                            List<Res_Files> res_filesList = resFileService.selectDataListForResourceid(resourceid);
                            model.addAttribute("resFileList", res_filesList);
                        } else {
                            model.addAttribute("helpurl", res_extSpaceServer.getHelpurl());
                            model.addAttribute("show", 1);
                        }
                    }
                    break;
            }
            model.addAttribute("Pubdate", Pubdate);
            model.addAttribute("resourceType", leixin);
            model.addAttribute("apply", isApply);
            ProblemFeedback(resourceid, model);
            GetProblemStatus(res_mainInfo, model);
        }
        //换地址
        if (res_mainInfo != null && res_mainInfo.getDesurl() != null && res_mainInfo.getDesurl().indexOf("diydes") != -1 && res_mainInfo.getDesurl().indexOf(res_mainInfo.getResourceid().toString()) != -1) {
            String url = sysConfig.getUploadRootPath() + res_mainInfo.getDesurl();
            res_mainInfo.setDesurl(url);
        }
        model.addAttribute("mainInfo", res_mainInfo);
        model.addAttribute("resMainInfoId", resourceid);
        model.addAttribute("isMyZy", res_mainInfo.getCreateuserid() != getUserId() ? false : true);//判断是否是自己申请的资源(申请按钮)
        //编辑按钮
        boolean isEdit = false;
        if (res_mainInfo.getCreateuserid() == getUserId() || SecurityUtils.getSubject().isPermitted("org_user_admin")) {
            isEdit = true;
        }
        model.addAttribute("isEdit", isEdit);
        model.addAttribute("integratetype", integratetype);
        model.addAttribute("integrateurl", integrateurl);
        model.addAttribute("firstMapUrl", getZTDTByPortalMapUrl(res_mainInfo.getResourceid(), res_mainInfo.getResourceclass()));
        String imgurl = "";
        String defClassImg = "/image/classimg/" + res_mainInfo.getResourceclass() + ".gif";
        if (res_mainInfo.getImgurl() != null && !res_mainInfo.getImgurl().isEmpty()) {
            if (res_mainInfo.getImgurl().startsWith("Atkas")) {//图集
                imgurl = "/image/" + res_mainInfo.getImgurl();
                File file = new File(System.getProperty("user.dir") + "\\src\\main\\resources\\static" + ("/image/" + res_mainInfo.getImgurl()).replace("/", "\\"));
                if (!file.exists()) {  //判断物理路径是否存在,不存在则默认
                    imgurl = defClassImg;
                }
            } else {
                imgurl = "/uploadPath/" + res_mainInfo.getImgurl();
                File file = new File(sysConfig.getUploadPath() + res_mainInfo.getImgurl());
                if (!file.exists()) {  //判断物理路径是否存在,不存在则默认
                    imgurl = defClassImg;
                }
            }
        } else {
            imgurl = defClassImg;
        }
        model.addAttribute("imgurl", imgurl);
 
        if (checkZiYuanQuanXian(resourceid) > 0 || SecurityUtils.getSubject().isPermitted("org_user_admin")) {
            model.addAttribute("resourceChaKan", 1);
        } else {
            model.addAttribute("resourceChaKan", 0);
        }
 
        boolean del = false;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        //自定义风格列表
        List<Res_DiyLayerInfo> res_diyLayerInfos = resDiyLayerInfoService.selectByResourceid(resourceid);
        for (int i = 0; i < res_diyLayerInfos.size(); i++) {
            res_diyLayerInfos.get(i).setDiydate(sdf.format(res_diyLayerInfos.get(i).getDiytime()));
            if (res_diyLayerInfos.get(i).getDiyuserid() == 0) { //定义风格用户ID为0时,管理员和发布该资源的用户可以删除该风格
                if (SecurityUtils.getSubject().isPermitted("org_user_admin") || getUserId() == res_mainInfo.getCreateuserid()) {
                    del = true;
                }
            }
            if (getUserId() == res_diyLayerInfos.get(i).getDiyuserid().longValue()) {  //当前登录用户是定义人则可以删除自己定义的风格
                del = true;
            }
            res_diyLayerInfos.get(i).setDel(del);
        }
        model.addAttribute("diyLayerInfos", res_diyLayerInfos);
        return "ResManage/ResRegister/ZiYuanBaseInfo";
    }
 
    /**
     * 删除自定义风格
     */
    @RequestMapping("diylayer/deleteDiyLayerInfo")
    @ResponseBody
    public String deleteDiyLayerInfo(Integer diyid) {
        resDiyLayerInfoService.deleteDiyLayerInfo(diyid);
        return "1";
    }
 
    private void SelectFileUrl(Integer resourceid, Model model, HttpServletRequest request, Res_ExtFileSource resExtFileSource) {
        if (resExtFileSource.getSourcetype() != null && resExtFileSource.getSourcetype().equals("文件夹")) {
            if (resExtFileSource.getServerurl() != null && resExtFileSource.getStoragemode().equals("本地")) {
                File file = new File(sysConfig.getUploadPath() + resExtFileSource.getServerurl());
                String ip = "/uploadPath/";
                String webUrl = ip + resExtFileSource.getServerurl();
                String httpurl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + webUrl;
                List<Res_FileSource_Way> res_fileSource_way = null;
                if (file.isDirectory()) {
                    System.out.println(resExtFileSource.getServerurl());
                    String[] fileLists = file.list();
                    File[] files = file.listFiles();
                    List<FileSourceList> fileSourceLists = new ArrayList<>();
                    List list = new ArrayList();
                    for (int i = 0; i < fileLists.length; i++) {
                        File file1 = new File(fileLists[i]);
                        File file2 = new File(files[i].getAbsolutePath());
                        String size = FileUtils.byteCountToDisplaySize(file2.length());
                        String path2 = wenjianjiaPath() + file1.getName(); // 文件映射路径
                        FileSourceList sourceList = new FileSourceList();
                        sourceList.setName(file1.getName());
                        sourceList.setPath(webUrl + "/" + file1.getName());
                        sourceList.setSize(size);
                        //查看 展现方式
                        res_fileSource_way = resFileSourceWayService.selectById(resourceid);
                        List<Res_FileSource_Way> ways = new ArrayList<Res_FileSource_Way>();
                        for (int j = 0; j < res_fileSource_way.size(); j++) {
                            Res_FileSource_Way way = res_fileSource_way.get(j);
                            if (!(StringUtils.isEmpty(way.getUrl()) || StringUtils.equals(way.getUrl(), "--"))) {
                                ways.add(0, way);
                            }
                        }
                        sourceList.setList(ways);
                        fileSourceLists.add(sourceList);
                    }
                    if (res_fileSource_way != null) {
                        for (int j = 0; j < res_fileSource_way.size(); j++) {
                            if (!res_fileSource_way.get(j).getUrl().equals("") && !res_fileSource_way.get(j).getRemark().equals("")) {
                                Res_FileSource_Way way = res_fileSource_way.get(j);
                                String PathUrl = way.getRemark();
                                if (!StringUtils.isEmpty(PathUrl)) {
                                    PathUrl += URLEncoder.encode(httpurl);
                                    way.setRemark(PathUrl);
                                }
 
                                list.add(way);
                            }
                        }
                    }
                    model.addAttribute("res_fileSource_way", list);
                    System.out.println(fileSourceLists);
                    System.out.println(request.getServerName());
                    //model.addAttribute("webUrl",request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+webUrl);
                    model.addAttribute("webUrl", httpurl);
                    model.addAttribute("filelist", fileSourceLists);
                    //model.addAttribute("zhanxian",zhanxian);
                }
            }
        }
        if (resExtFileSource.getSourcetype() != null && resExtFileSource.getSourcetype().equals("文件")) {
            if (resExtFileSource.getServerurl() != null && resExtFileSource.getStoragemode().equals("本地")) {
                File file = new File(sysConfig.getUploadPath() + resExtFileSource.getServerurl());
                String ip = "/uploadPath/";
                String webUrl = ip + resExtFileSource.getServerurl();
                FileSourceList sourceList = new FileSourceList();
                List<FileSourceList> fileSourceLists = new ArrayList<>();
                sourceList.setName(file.getName());
                sourceList.setPath(webUrl);
                sourceList.setSize(FileUtils.byteCountToDisplaySize(file.length()));
                List<Res_FileSource_Way> res_fileSource_way = resFileSourceWayService.selectById(resourceid);
                sourceList.setList(res_fileSource_way);
                fileSourceLists.add(sourceList);
                model.addAttribute("webUrlWenJian", request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + webUrl);
                model.addAttribute("filelist", fileSourceLists);
            }
        }
    }
 
    private LinkedHashMap<String, String> queryUserOrUnitList(String gettype) {
        String url = sysConfig.getApiServer() + (gettype == "unit" ? "/api/org/unit/queryAllList" : "/api/org/user/queryAllList");
        LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
        try {
            String jsonStr = HttpOperateUtils.httpGet(url.trim());
            if (jsonStr.length() != 0) {
                JSONArray list = JSON.parseArray(jsonStr);
                for (int i = 0; i < list.size(); i++) {
                    Map maps = (Map) JSON.parse(list.get(i).toString());
                    map.put(maps.get("id").toString(), maps.get("name").toString());
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return map;
    }
 
    @RequestMapping("ZiYuan/BaseInfoExtBaseMap")//基础底图
    public String BaseInfoExtBaseMap(Integer resourceid, Model model, HttpServletRequest request) {
        GetMainInfo(resourceid, model, request);
        return "ResManage/ResRegister/BaseInfoExtBaseMap";
    }
 
    @RequestMapping("ZiYuan/BaseInfoExtBusinessLayer")
    public String BaseInfoExtBusinessLayer(Integer resourceid, Model model, HttpServletRequest request) {
        GetMainInfo(resourceid, model, request);
        return "ResManage/ResRegister/BaseInfoExtBusinessLayer";
    }
 
    @RequestMapping("ZiYuan/BaseInfoExtSpaceServer")
    public String BaseInfoExtSpaceServer(Integer resourceid, Model model, HttpServletRequest request) {
        if (checkZiYuanQuanXian(resourceid) > 0) {
            model.addAttribute("isReadUrl", 1);
        } else {
            model.addAttribute("isReadUrl", 0);
        }
        Res_ExtSpaceServer res_extSpaceServer = resExtSpaceServerService.selectByPrimaryKey(resourceid);
        if (res_extSpaceServer != null) {
            model.addAttribute("ResExtSpaceServer", res_extSpaceServer);
            String UrlAndToken = getUrlAndToken(resourceid, res_extSpaceServer.getServerurl(), request);
            model.addAttribute("urlAndToken", UrlAndToken);
        } else {
            res_extSpaceServer = new Res_ExtSpaceServer();
            model.addAttribute("ResExtSpaceServer", res_extSpaceServer);
        }
        GetMainInfo(resourceid, model, request);
        return "ResManage/ResRegister/BaseInfoExtSpaceServer";
    }
 
    @RequestMapping("ZiYuan/BaseInfoExtThemeMap")
    public String BaseInfoExtThemeMap(Integer resourceid, Model model, HttpServletRequest request) {
        GetMainInfo(resourceid, model, request);
        return "ResManage/ResRegister/BaseInfoExtThemeMap";
    }
 
    @RequestMapping("ZiYuan/BaseInfoExtIntegrate")
    public String BaseInfoExtIntegrate(Integer resourceid, Model model, HttpServletRequest request) {
        if (checkZiYuanQuanXian(resourceid) > 0) {
            model.addAttribute("isReadUrl", 1);
        } else {
            model.addAttribute("isReadUrl", 0);
        }
        Res_ExtIntegrate res_extIntegrate = resExtIntegrateService.selectByPrimaryKey(resourceid);
        if (res_extIntegrate != null) {
            model.addAttribute("res_extIntegrate", res_extIntegrate);
            String UrlAndToken = getUrlAndToken(resourceid, res_extIntegrate.getServerurl(), request);
            model.addAttribute("urlAndToken", UrlAndToken);
        } else {
            res_extIntegrate = new Res_ExtIntegrate();
            model.addAttribute("res_extIntegrate", res_extIntegrate);
        }
        GetMainInfo(resourceid, model, request);
 
        return "ResManage/ResRegister/BaseInfoExtIntegrate";
    }
 
    @RequestMapping("ZiYuan/BaseInfoExtFileSource")
    public String BaseInfoExtFileSource(Integer resourceid, Model model, HttpServletRequest request) {
        Res_ExtFileSource res_extFileSource = resExtFileSourceService.selectByPrimaryKey(resourceid);
        if (res_extFileSource != null) {
 
            model.addAttribute("resExtFileSource", res_extFileSource);
        } else {
            res_extFileSource = new Res_ExtFileSource();
            model.addAttribute("resExtFileSource", res_extFileSource);
        }
        GetMainInfo(resourceid, model, request);
        return "ResManage/ResRegister/BaseInfoExtFileSource";
    }
 
    @RequestMapping("ZiYuan/BaseInfoExtDataBase")
    public String BaseInfoExtDataBase(Integer resourceid, Model model, HttpServletRequest request) {
        GetMainInfo(resourceid, model, request);
        DataBaseLeftDataSource database = resExtDataBaseService.selectBaseLeftSource(resourceid);
        String databasetype = "";
        if (database != null) {
            databasetype = database.getDatabasetype();
        }
        model.addAttribute("databasetype", databasetype);
        return "ResManage/ResRegister/BaseInfoExtDataBase";
    }
 
    @RequestMapping("ZiYuan/BaseInfoEextInterFace")
    public String BaseInfoEextInterFace(Integer resourceid, Model model, HttpServletRequest request) {
        GetMainInfo(resourceid, model, request);
        if (checkZiYuanQuanXian(resourceid) > 0) {
            model.addAttribute("isReadUrl", 1);
        } else {
            model.addAttribute("isReadUrl", 0);
        }
        Res_ExtInterFaceService res_extInterFaceService = resExtInterFaceService.selectByPrimaryKey(resourceid);
        if (res_extInterFaceService != null) {
 
            model.addAttribute("resExtInterFaceService", res_extInterFaceService);
            String UrlAndToken = getUrlAndToken(resourceid, res_extInterFaceService.getServerurl(), request);
            model.addAttribute("urlAndToken", UrlAndToken);
        } else {
            res_extInterFaceService = new Res_ExtInterFaceService();
            model.addAttribute("resExtInterFaceService", res_extInterFaceService);
        }
        return "ResManage/ResRegister/BaseInfoEextInterFace";
    }
 
    @RequestMapping("ZiYuan/BaseInfoExt3D")
    public String BaseInfoExt3D(Integer resourceid, Model model, HttpServletRequest request) {
        if (checkZiYuanQuanXian(resourceid) > 0) {
            model.addAttribute("isReadUrl", 1);
        } else {
            model.addAttribute("isReadUrl", 0);
        }
        Res_Ext3D res_ext3D = resExt3DService.selectByPrimaryKey(resourceid);
        if (res_ext3D != null) {
            model.addAttribute("resExt3D", res_ext3D);
            String UrlAndToken = getUrlAndToken(resourceid, res_ext3D.getServerurl(), request);
            model.addAttribute("urlAndToken", UrlAndToken);
        } else {
            res_ext3D = new Res_Ext3D();
            model.addAttribute("resExt3D", res_ext3D);
        }
        GetMainInfo(resourceid, model, request);
        return "ResManage/ResRegister/BaseInfoExt3D";
    }
 
    private Model GetMainInfo(Integer resourceid, Model model, HttpServletRequest request) {
        String UrlAndToken = "";//复制地址
        Res_MainInfo res_mainInfo = new Res_MainInfo();
        OrgUnit orgUnit = getUnit();//获取用户单位信息
        // 修改
        res_mainInfo = resMainInfoService.selectByPrimaryKey(resourceid);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String Pubdate = sdf.format(res_mainInfo.getPubdate());
        String Productiontime = res_mainInfo.getProductiontime() != null ? sdf.format(res_mainInfo.getProductiontime()) : "";
        // 判断所属目录
        strMuLu = "";
        res_mainInfo.setCatlogcode(GetBianMu(res_mainInfo.getCatlogid()));
        // 判断发布单位
        String unitname = orgUnitService.getUnitById((long) res_mainInfo.getPubunitid()).getUnitname();
        model.addAttribute("unitname", unitname);
        // 判断数据覆盖范围
        // modified by qufangxu 信创环境下,若 res_mainInfo.getAdministrativeid() = '        ',会返回单点登录页面,具体原因未知。 解决办法:提前去除空格、制表符
        String administrativeid = (String) res_mainInfo.getAdministrativeid();
        String finalValue = null;
        if (StringUtils.isNotEmpty(administrativeid)){
            finalValue = administrativeid.trim();
        }
        if (StringUtils.isNotEmpty(finalValue)) {
            String getRegionInfourl = sysConfig.getApiServer() + "/api/org/region/getById/" + administrativeid;
            String jsonStr = "";
            try {
                jsonStr = HttpOperateUtils.httpGet(getRegionInfourl.trim());
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (jsonStr != null && !jsonStr.isEmpty()) {
                JSONObject item = JSONObject.parseObject(jsonStr);
                String regionname = item.getString("regionname");
                res_mainInfo.setAdministrativeid(regionname);
            }
        }
        List list = new ArrayList();
        if (res_mainInfo.getKeywords() != "") {
            String keywords = res_mainInfo.getKeywords();
            if (keywords != null && !keywords.equals("")) {
                String key[] = keywords.split(",");
                for (int i = 0; i < key.length; i++) {
                    String s = key[i];
                    list.add(s);
                }
            }
        }
        model.addAttribute("Pubdate", Pubdate);
        model.addAttribute("Productiontime", Productiontime);
        //换地址
        if (res_mainInfo != null && res_mainInfo.getDesurl() != null && res_mainInfo.getDesurl().indexOf("diydes") != -1 && res_mainInfo.getDesurl().indexOf(res_mainInfo.getResourceid().toString()) != -1) {
            String url = sysConfig.getUploadRootPath() + res_mainInfo.getDesurl();
            res_mainInfo.setDesurl(url);
        }
 
        model.addAttribute("list", list);
        model.addAttribute("createusername", res_mainInfo.getCreateuserid() != null ? orgUserService.getChinesename(res_mainInfo.getCreateuserid()) : "");//发布人
        //资源类型
        switch (res_mainInfo.getResourceclass()) {
            case "KJ_JCDT"://基础底图
                Res_ExtBaseMap resExtBaseMap = resExtBaseMapService.selectByPrimaryKey(resourceid);
                if (resExtBaseMap == null) {
                    resExtBaseMap = new Res_ExtBaseMap();
                }
                model.addAttribute("resExtBaseMap", resExtBaseMap);
                break;
            case "KJ_ZTDT":// 专题地图
                Res_ExtThemeMap resExtThemeMap = resExtThemeMapService.selectByPrimaryKey(resourceid);
                if (resExtThemeMap == null) {
                    resExtThemeMap = new Res_ExtThemeMap();
                }
                model.addAttribute("resExtThemeMap", resExtThemeMap);
                break;
            case "KJ_YWTC":// 业务图层
                Res_ExtBusinessLayer resExtBusinessLayer = resExtBusinessLayerService.selectByPrimaryKey(resourceid);
                if (resExtBusinessLayer == null) {
                    resExtBusinessLayer = new Res_ExtBusinessLayer();
                }
                model.addAttribute("resExtBusinessLayer", resExtBusinessLayer);
                break;
        }
        //服务地址链接
        List<Res_ExtMapUrl> resExtMapUrls = resExtMapUrlService.selectByCondition(resourceid);
        String serviceUrl = "";//服务地址
        String layername = "";
        List<String> urltokens = new ArrayList<>();
        Integer isReadUrl = 0;//是否有权限查看服务地址
        if (resExtMapUrls.size() > 0) {
            //判断是否有权限
            Map<String, Object> map = new HashMap<>();
            Long userId = getUserId();  //获取用户ID
            map.put("resourceid", resourceid);
            map.put("userid", userId);
            OrgUser user = getUser();
            map.put("unitid", orgUserService.getDefaultUnit(user.getUserid()).getUnitid());
            int count = resMainInfoService.checkZiYuanQuanXian(map);
            if (count > 0) {
                isReadUrl = 1;
                serviceUrl = (resExtMapUrls != null && resExtMapUrls.size() > 0) ? resExtMapUrls.get(0).getServerurl() : "";//暂时先取第一个地址
                layername = (resExtMapUrls != null && resExtMapUrls.size() > 0) ? resExtMapUrls.get(0).getLayername() : "";
            }
            UrlAndToken = getUrlAndToken(resourceid, serviceUrl, request);
            // resExtMapUrls.remove(0);
            //TODO  获取服务代理地址
            for (Res_ExtMapUrl res : resExtMapUrls) {
                String urltoken = getUrlAndToken(resourceid, res.getServerurl(), request);
                res.setUrlandtoken(urltoken);
            }
            model.addAttribute("urlAndToken", UrlAndToken);
            model.addAttribute("isReadUrl", isReadUrl);
        }
 
        model.addAttribute("serviceUrl", serviceUrl);
        model.addAttribute("firstlayername", layername);
        //   resExtMapUrls.remove(0);
        model.addAttribute("serviceUrls", resExtMapUrls);
 
        model.addAttribute("mainInfo", res_mainInfo);
        GetProblemStatus(res_mainInfo, model);
 
        ProblemFeedback(resourceid, model);
        logger.error(model.toString());
        return model;
    }
 
    private int checkZiYuanQuanXian(Integer resourceid) {
        Map<String, Object> map = new HashMap<>();
        Long userId = getUserId();  //获取用户ID
        map.put("resourceid", resourceid);
        map.put("userid", userId);
        OrgUser user = getUser();
        map.put("unitid", orgUserService.getDefaultUnit(user.getUserid()).getUnitid());
        return resMainInfoService.checkZiYuanQuanXian(map);
    }
 
    /**
     * 复制
     */
    @ResponseBody
    @RequestMapping("/ZiYuan/copyMainInfoAndKZ")
    public int copyMainInfoAndKZ(int resourceid, String copyname, String copyurl, String type) {
        int resultId = 0;
        Timestamp nowtime = new Timestamp(new Date().getTime());// 获取当前时间
        Res_MainInfo mainInfo = resMainInfoService.selectByPrimaryKey(resourceid);
        if (mainInfo != null) {
            mainInfo.setResourceid(null);
            mainInfo.setAuditstatus(0);
            mainInfo.setCreatedate(nowtime);
            mainInfo.setLasteditdate(nowtime);
            mainInfo.setTitle(copyname);
            resultId = resMainInfoService.insertSelective(mainInfo);
            if (resultId == 1) {
                resultId = resMainInfoService.queryResMainInfoIdentCurrent();
                int isExitsUrl = 0;
                switch (type) {
                    case "ExtBaseMap"://基础底图
                        Res_ExtBaseMap baseMapInfo = resExtBaseMapService.selectByPrimaryKey(resourceid);
                        if (baseMapInfo != null) {
                            baseMapInfo.setResourceid(resultId);
                            resExtBaseMapService.insertSelective(baseMapInfo);
                            isExitsUrl = 1;
                        }
                        break;
                    case "ExtSpaceServer"://空间分析不用复制扩展信息
                        break;
                    case "ExtBusinessLayer"://业务图层
                        Res_ExtBusinessLayer businessInfo = resExtBusinessLayerService.selectByPrimaryKey(resourceid);
                        if (businessInfo != null) {
                            businessInfo.setResourceid(resultId);
                            resExtBusinessLayerService.insertSelective(businessInfo);
                            isExitsUrl = 1;
                        }
                        break;
                    case "ExtThemeMap"://专题地图
                        Res_ExtThemeMap themeInfo = resExtThemeMapService.selectByPrimaryKey(resourceid);
                        if (themeInfo != null) {
                            themeInfo.setResourceid(resultId);
                            resExtThemeMapService.insertSelective(themeInfo);
                            isExitsUrl = 1;
                        }
                        break;
                    case "ExtFileSource"://数据文件不用复制扩展信息
                        break;
                    case "ExtIntegrate"://业务集成
                        Res_ExtIntegrate integerInfo = resExtIntegrateService.selectByPrimaryKey(resourceid);
                        if (integerInfo != null) {
                            integerInfo.setResourceid(resultId);
                            integerInfo.setServerurl(copyurl);
                            resExtIntegrateService.insertSelective(integerInfo);
                        }
                        break;
                    case "ExtInterFaceService"://接口服务
                        Res_ExtInterFaceService faceInfo = resExtInterFaceService.selectByPrimaryKey(resourceid);
                        if (faceInfo != null) {
                            faceInfo.setResourceid(resultId);
                            faceInfo.setServerurl(copyurl);
                            resExtInterFaceService.insertSelective(faceInfo);
                        }
                        break;
                    case "Ext3D"://3D模型
                        Res_Ext3D threeDInfo = resExt3DService.selectByPrimaryKey(resourceid);
                        if (threeDInfo != null) {
                            threeDInfo.setResourceid(resultId);
                            threeDInfo.setServerurl(copyurl);
                            resExt3DService.insertSelective(threeDInfo);
                        }
                        break;
                    case "ExtDataBase"://数据库表不用复制扩展信息
                        break;
                }
                //复制服务地址
                if (isExitsUrl == 1) {
                    List<Res_ExtMapUrl> extMapUrlList = resExtMapUrlService.selectByCondition(resourceid);
                    if (extMapUrlList != null && extMapUrlList.size() > 0) {
                        for (int i = 0; i < extMapUrlList.size(); i++) {
                            Res_ExtMapUrl urlmodel = extMapUrlList.get(i);
                            urlmodel.setUrlid(null);
                            urlmodel.setResourceid(resultId);
                            if (i == 0) {//填写的服务地址替换第一个
                                urlmodel.setServerurl(copyurl);
                            }
                            resExtMapUrlService.insertSelective(urlmodel);
                        }
                    }
                }
            }
        }
        return resultId;
    }
 
    //类型为专题地图portal专题类型获取首笔协议服务路径
    private String getZTDTByPortalMapUrl(Integer resourceid, String resourceclass) {
        String firstMapUrl = "";
        if (resourceid != null && resourceclass != null) {
            if (resourceclass.equals("KJ_ZTDT")) {
                Res_ExtThemeMap resExtThemeMap = resExtThemeMapService.selectByPrimaryKey(resourceid);
                if (resExtThemeMap != null && resExtThemeMap.getType() != null && resExtThemeMap.getType().equals("Portal专题")) {
                    List<Res_ExtMapUrl> urlList = resExtMapUrlService.selectByCondition(resourceid);
                    if (urlList != null && urlList.size() > 0 && urlList.get(0).getServerurl() != null)
                        firstMapUrl = urlList.get(0).getServerurl();
                }
            }
        }
        return firstMapUrl;
    }
 
    /**
     * 自动补全输入首字母查询
     *
     * @param keyWord
     * @return
     */
    @ResponseBody
    @GetMapping("/findPinyinByKeyWord")
    public String[] findpinyinByKeyWord(@RequestParam(name = "keyWord") String keyWord) {
        List<String> titles = resMainInfoService.pingyin(URLDecoder.decode(keyWord.toLowerCase()));
 
        if (org.springframework.util.StringUtils.isEmpty(titles)) {
            return null;
        }
 
        int size = titles.size();
 
        String[] arr = titles.toArray(new String[size]);
 
        return arr;
    }
 
    /** 文件上传 */
    /**
     * @Description:
     * @author dsh
     * 文件资源类型
     * @date 2018/6/28
     */
    @ResponseBody
    @RequestMapping("/ZiYuan/uploadfile")
    public String uploadfile(@RequestParam("myFile") MultipartFile[] file, String resourceid) {
        String res = "";
        for (int i = 0; i < file.length; i++) {
            if (file[i].isEmpty()) {
                return "No File";
            }
            // 判断文件夹是否存在(resource/diydes/resourceid/文件)
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
            String timePath = sdf.format(new Date().getTime());
            timePath = timePath.replace("-", "");
            String thisPath = sysConfig.getUploadPath() + "diydes\\" + timePath + "\\" + resourceid;
            String paths[] = {""};
            try {
                String tempPath = new File(thisPath).getCanonicalPath();
//                paths = tempPath.split("\\\\");
            } catch (Exception e) {
                e.printStackTrace();
            }
            //创建文件夹
            String dir = paths[0];
            for (int j = 0; j < paths.length - 1; j++) {
                try {
                    dir = dir + "/" + paths[j + 1];
                    File dirFile = new File(dir);
                    if (!dirFile.exists()) {
                        dirFile.mkdirs();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            //判断文件是否存在
            String filename = file[0].getOriginalFilename().indexOf("\\") != -1
                    ? file[0].getOriginalFilename().substring(file[0].getOriginalFilename().lastIndexOf("\\") + 1, file[0].getOriginalFilename().length())
                    : file[0].getOriginalFilename();
            File thisfile = new File(thisPath + "\\" + filename);
            File thisdir = new File(thisPath);
            String webpath = "";
            if (!thisfile.exists()) {
                try {
                    //删除已有的文件
                    File[] childrens = thisdir.listFiles();
                    if (childrens != null) {
                        for (int j = 0; j < childrens.length; j++) {
                            File temp = childrens[i];
                            temp.delete();
                        }
                    }
                    //文件网络地址
                    webpath = "diydes/" + timePath + "/" + resourceid + "/" + filename; // 类型为文件指向文件
                    FileUtils.copyInputStreamToFile(file[i].getInputStream(), thisfile);
                    res = "{'result':'1','name':'" + file[i].getOriginalFilename() + "','Path':'" + sysConfig.getUploadRootPath() + webpath + "'}";
                } catch (Exception e) {
                    e.printStackTrace();
                    res = "{'result':'0'}";
                }
            } else {
                res = "{'result':'3'}";
            }
        }
        return res;
    }
 
    /**
     * 获取复制地址
     *
     * @param resourceid
     * @param url
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping("mainInfo/getUrlAndToken")
    public String getUrlAndToken(Integer resourceid, String url, HttpServletRequest request) {
        Res_MainInfo resMainInfo = resMainInfoService.selectByPrimaryKey(resourceid);
        if (resMainInfo.getEspproxy() == 1) {
            Res_ExtThemeMap resExtThemeMap = resExtThemeMapService.selectByPrimaryKey(resourceid);
            String subzyids = "";
            if (resExtThemeMap != null) {
                subzyids = resExtThemeMap.getSublayerset();
            }
            boolean isPubzy = false;
            if (resMainInfo != null && resMainInfo.getSharprotocol().equals("完全公开")) {
                isPubzy = true;
            }
            String serviceUrl = url;
            //获取token拼接url
            //String path= TerraToken.getToken(serviceUrl, getUserId().intValue(), request.getRemoteAddr(), resourceid, resMainInfo.getEspproxy(), sysConfig, subzyids, isPubzy, resMainInfo.getToken(), false);
            String remoteAddr = request.getRemoteAddr();
            String path = EsbToken.getEsbUrl(serviceUrl, 163, request.getRemoteAddr(), resourceid, resMainInfo.getEspproxy(), sysConfig, subzyids, isPubzy, resMainInfo.getToken(), false);
            return path;
        } else {
            if (resMainInfo.getToken() != null && !resMainInfo.getToken().isEmpty()) {
                if (url.indexOf("?") > -1) {
                    return url + "&token=" + resMainInfo.getToken();
                } else {
                    return url + "?token=" + resMainInfo.getToken();
                }
            } else {
                return url;
            }
        }
    }
 
    //检查服务地址是否异常,异常则插入记录
    @ResponseBody
    @RequestMapping("ZiYuan/CheckServerurl")
    public String CheckServerurl(Integer resourceid, String urlStr) {
        Integer status = -1;//不成功
        if (urlStr == null || urlStr.trim().equals("")) {
            return "";
        }
        Res_MainInfo res_mainInfo = resMainInfoService.selectByPrimaryKey(resourceid);
        //检查:pingIP或域名是否成功
        //1.先查最新一笔记录是否为异常,异常则不检查
        //2.最新一笔记录为网络异常,再次检查,如果正常则插入正常消息
        //3.没有异常消息,检查
        List<Res_ProblemFeedback> problemFeedbacks = resProblemFeedbackService.selectByResourceid(resourceid);
        Integer lastServerStatus = (problemFeedbacks != null && problemFeedbacks.size() > 0 && problemFeedbacks.get(0).getServerstatus() != null) ? problemFeedbacks.get(0).getServerstatus() : -1;
        String lastStatus = (problemFeedbacks != null && problemFeedbacks.size() > 0 && problemFeedbacks.get(0).getFeedbackstatus() != null) ? problemFeedbacks.get(0).getFeedbackstatus() : "";
        String lastType = (problemFeedbacks != null && problemFeedbacks.size() > 0 && problemFeedbacks.get(0).getFeedbacktype() != null) ? problemFeedbacks.get(0).getFeedbacktype() : "";
        boolean res = false;
        if (problemFeedbacks == null || problemFeedbacks.size() == 0 || lastServerStatus.equals(1) || (lastStatus.equals("网络问题") && lastServerStatus.equals(0) && lastType.equals("系统"))) {
            try {
                Runtime runtime = Runtime.getRuntime();
                Process process = null;
                String line = null;
                InputStream is = null;
                InputStreamReader isr = null;
                BufferedReader br = null;
                URL url = new URL(urlStr);
                String ip = url.getHost();
                res = false;
                process = runtime.exec("ping " + ip);
                is = process.getInputStream();
                isr = new InputStreamReader(is);
                br = new BufferedReader(isr);
                while ((line = br.readLine()) != null) {
                    if (line.contains("TTL")) {
                        res = true;
                        break;
                    }
                }
                is.close();
                isr.close();
                br.close();
                br.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
            /** add ykm 2019-04-17 判断服务地址
             * 如果IP不通,则判断服务地址是否通
             * 如果服务地址正常,则认为网络也正常
             * */
            if (!res) {
                boolean isTrue = isConnect(urlStr);
                if (isTrue) {
                    res = true;
                }
            }
            //插入正常信息
            if (res && (lastStatus.equals("网络问题") && lastServerStatus.equals(0) && lastType.equals("系统"))) {
                InsertProblem(resourceid, 1, 0);
                if (res_mainInfo != null) res_mainInfo.setResourcestatus(0);
                status = 0;
            }
            //插入异常
            if (!res && (lastServerStatus.equals(1) || lastServerStatus.equals(-1))) {
                InsertProblem(resourceid, 0, 1);
                if (res_mainInfo != null) res_mainInfo.setResourcestatus(1);
                status = 1;
            }
        }
        return "{result:" + status + "}";
    }
 
    //插入问题消息
    private void InsertProblem(Integer resourceid, Integer status, Integer resourcestatus) {
        Res_ProblemFeedback model = new Res_ProblemFeedback();
        java.sql.Timestamp time = new java.sql.Timestamp(new Date().getTime());
        model.setResourceid(resourceid);
        model.setCreateuserid(getUserId().intValue());
        model.setAddtime(time);
        model.setFeedbacktype("系统");
        model.setServerstatus(status);
        model.setFeedbackstatus("网络问题");
        model.setRemark("无法连接服务器");
        resProblemFeedbackService.insertSelective(model);
        Res_MainInfo mainInfo = new Res_MainInfo();
        mainInfo.setResourceid(resourceid);
        mainInfo.setResourcestatus(resourcestatus);
        resMainInfoService.updateByPrimaryKeySelective(mainInfo);
    }
 
    //获取问题类型
    private Model GetProblemStatus(Res_MainInfo mainInfo, Model model) {
        String status = "";
        if (mainInfo != null) {
            List<Res_ProblemFeedback> problemFeedbacks = resProblemFeedbackService.selectByResourceid(mainInfo.getResourceid());
            if (problemFeedbacks != null && problemFeedbacks.size() > 0 && problemFeedbacks.get(0).getServerstatus().equals(0)) {
                status = problemFeedbacks.get(0).getFeedbackstatus();
            }
        }
        model.addAttribute("problemStatus", status.equals("") ? "" : status.substring(0, 2));
        return model;
    }
 
    //根据类型获取资源条数
    private int GetZYCountByClass(Integer treeType, String search, String catalogname) {
        catalogname = URLDecoder.decode(catalogname);
        UserDef_ZYML_ChaXunQu userDefZymlChaXunQu = new UserDef_ZYML_ChaXunQu();
        if (!search.equals("") && treeType == 4) userDefZymlChaXunQu.setResourceclass(search);
        if (!search.equals("") && treeType == 0) {
            userDefZymlChaXunQu.setCatlogcode(search);
            userDefZymlChaXunQu.setCatalogName(catalogname);
        }
        int count = ziYuanMuLuService.selectZiYuanMuLuList(userDefZymlChaXunQu).size();
        return count;
    }
 
    private int GetZYCountByClassNew(Integer treeType, String catalogcode, String catalogname, String resourceclass,String spcStatus) {
        UserDef_ZYML_ChaXunQu userDefZymlChaXunQu = new UserDef_ZYML_ChaXunQu();
 
        catalogname = URLDecoder.decode(catalogname);
        // 按资源目录划分
        if(treeType == 0){
            userDefZymlChaXunQu.setCatlogcode(catalogcode);
            userDefZymlChaXunQu.setCatalogName(catalogname);
            userDefZymlChaXunQu.setResourceclass(resourceclass);
        }
        if(treeType == 4){
            userDefZymlChaXunQu.setResourceclass(resourceclass);
        }
        userDefZymlChaXunQu.setSpcStatus(spcStatus);
        int count = ziYuanMuLuService.selectZiYuanMuLuList(userDefZymlChaXunQu).size();
        return count;
    }
 
    private Model ProblemFeedback(Integer resourceid, Model model) {
        //获取资源最后一笔问题反馈的状态
        Res_ProblemFeedback problemFeedback = resProblemFeedbackService.selectTopByResourceid(resourceid);
        String result = "";
        if (problemFeedback != null) {
            if (problemFeedback.getServerstatus() == 1) {
                result = "正常";
            } else {
                result = "异常";
            }
        }
        model.addAttribute("ProblemFeedback", result);
        return model;
    }
 
    //根据输入的用户名获取用户ID
    private String getUserIds(String name) {
        String url = sysConfig.getApiServer() + "/api/org/user/findUserByWord/" + URLEncoder.encode(URLEncoder.encode(name));
 
        String username = null;
        try {
            username = HttpOperateUtils.httpGet(url);
        } catch (IOException e) {
            e.printStackTrace();
        }
        JSONArray object = JSONArray.parseArray(username);
        StringBuilder t = new StringBuilder();
        if (!name.equals("%")) {
            for (int i = 0; i < object.size(); i++) {
                if (i != 0) t.append(",");
                t.append(object.getJSONObject(i).getString("id"));
            }
        }
        if (t.toString().equals("") && !name.equals("%")) {
            t.append("-1");
        }
        return t.toString();
    }
 
    public boolean isConnect(String urlStr) {
        boolean status = false;
        int counts = 0;
        if (urlStr == null || urlStr.length() <= 0) {
            return false;
        }
        while (counts < 2) {
            try {
                URL url = new URL(urlStr);
                HttpURLConnection con = (HttpURLConnection) url.openConnection();
                int state = con.getResponseCode();
                if (state == 200) {
                    status = true;
                }
                break;
            } catch (Exception ex) {
                status = false;
                counts++;
                System.out.println("URL不可用,连接第 " + counts + " 次");
                continue;
            }
        }
        return status;
    }
 
 
    /**
     * 资源目录左侧面板目录结构(由资源类型分类)
     * @return String
     */
    @ResponseBody
    @RequestMapping("getMuLuTreeDataByResourceType")
    public String getMuLuTreeDataByResourceType() {
        // 获取资源类型列表
        LinkedHashMap<String, String> resourceTypes = FieldUtils.getFieldListByKey("ResourceType");
        Map<String, Object> map = new HashMap<>();
        map.put("parentid", 0);
        //获取资源目录节点数据
        List<Res_Catalog> resCatalogList = resCatalogService.getMuLuTreeDataByResourceType(map);
        ArrayList<TreeDataByResourceType> arrayList = new ArrayList<>();
        //获取资源目录父节点id集合
        List<Integer> countList=resCatalogService.selectResCatalogExistsSon();
        int id=1;
        for (Map.Entry<String, String> entry : resourceTypes.entrySet()) {
            String key = entry.getKey();
            //查询对应resourceClass对应的资源总数
            int count = resMainInfoService.getCountByResourceClass(key);
            if(count==0) continue;
            TreeDataByResourceType resourceType = new TreeDataByResourceType();
            resourceType.setName(entry.getValue()+"("+count+")");
            resourceType.setPid(String.valueOf(0));
            resourceType.setId(String.valueOf(id));
            for (Res_Catalog resCatalog : resCatalogList) {
                if (!resCatalog.getResourceClass().equals(key)) continue;
                map.put("catlogcode",resCatalog.getCatlogcode());
                map.put("key",key);
                Integer countId = resMainInfoService.getCountByresCatalogId(map);
                if(null==countId) continue;
                resCatalog.setParent(false);
                if (countList.contains(resCatalog.getCatlogid())) resCatalog.setParent(true);
                resCatalog.setIconOpen("/image/classicons/folderOpen.png");
                resCatalog.setIconClose("/image/classicons/folder.png");
                resCatalog.setIcon("/image/classicons/defaulticon.png");
                resCatalog.setName(resCatalog.getTitle()+"("+countId+")");
                resCatalog.setPid(Integer.valueOf(resourceType.getId()));
                resourceType.getChildren().add(resCatalog);
 
            }
            arrayList.add(resourceType);
            id++;
        }
        return JSONObject.toJSONString(arrayList);
    }
 
 
    /**
     * 资源目录左侧面板目录结构(与专题数据混合)
     * @return String
     */
    @ResponseBody
    @RequestMapping("getMuLuTreeDataForSpcData")
    public String getMuLuTreeDataForSpcData(Integer id,  String XZQHID, String NF,  String catalogName, String ResourceClass,String spcStatus) {
        catalogName=null==catalogName?"":catalogName;
        ResourceClass=null==ResourceClass?"":ResourceClass;
        spcStatus=null==spcStatus?"1":spcStatus;
        return getMuLuTreeData( id,  0,  XZQHID,  NF,  0,  catalogName,  ResourceClass, spcStatus);
    }
 
 
 
 
    @ResponseBody
    @GetMapping(path = "/genTokenForApply")
    public String genTokenForApply(String resourceid) throws Exception {
        Long userid = getUser().getUserid();  // TODO:管理员判断
        Map<String,Object> param=  new HashMap<>();
        String proxyUrl = sysConfig.getProxyUrl();
        JSONObject json = new JSONObject();
        param.put("resourceid",resourceid);
        param.put("userid",userid);
        param.put("applyuserid",userid);
        param.put("appId",0);
        param.put("isPubzy",1);
        param.put("identyinfo",orgUserService.getChinesename(userid));
        Map<String,String> resultMap=resMainInfoService.queryForApply(param);
        //资源公开则直接返回
        String sharprotocol = resultMap.get("SHARPROTOCOL");
        String url = resultMap.get("SERVERURL");
        if(StringUtils.equals(sharprotocol,"完全公开")){
            param.put("isNever","1"); //系统申请永久
            if(url!=null&&url.contains(":8066")){
                json.put("code", 200);
                json.put("data", url);
                json.put("message", "获取成功");
                return json.toJSONString();
            }
            return HttpUtils.get(proxyUrl +"/genTokenForApply", param);
        }else {
            Res_ApplyRecommend applyRecommend = resApplyRecommendService.getApplyDate(param);
            if (null != applyRecommend) {
                //获取申请有效期的天数 -针对申请的资源
                Integer sysid = applyRecommend.getSysid();
                param.put("appId",sysid ==null?0:sysid);
                String appDays = applyRecommend.getAppDays();
                Integer apptype = applyRecommend.getApptype();
                if (appDays == null) {
                    switch (apptype) {
                        case 0:
                            appDays = "30"; // 个人申请30天
                            break;
                        case 1:
                            appDays = "360"; //单位申请360
                            break;
                        case 3:
                            param.put("isNever", "1"); //系统申请永久
                            appDays = "0";
                            break;
                    }
                }
                param.put("expiration", Integer.parseInt(appDays) * 24 * 3600);
                return HttpUtils.get(proxyUrl + "/genTokenForApply", param);
            }else {
                param.put("isNever", "1"); // 其它情况也是永久
                return HttpUtils.get(proxyUrl + "/genTokenForApply", param);
            }
        }
 
    }
 
    public static void main(String[] args) throws Exception {
        String test= "             ";
        String sda = test.trim();
        String url="http://71.3.110.202:6080/arcgis/rest/services/HYHD/HYQS/MapServer/0";
        String[] split = url.split("/MapServer");
        System.out.println("split = " + split);
    }
}