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
package com.landtool.lanbase.modules.res.controller;
 
import java.io.File;
import java.io.IOException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
 
import javax.servlet.http.HttpServletRequest;
 
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
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 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.landtool.lanbase.common.annotation.LogAction;
import com.landtool.lanbase.common.annotation.SysLog;
import com.landtool.lanbase.common.map.EsbToken;
import com.landtool.lanbase.common.utils.AttachmentUtils;
import com.landtool.lanbase.common.utils.FileUtils;
import com.landtool.lanbase.common.utils.HttpOperateUtils;
import com.landtool.lanbase.common.utils.HttpUtils;
import com.landtool.lanbase.common.utils.JpinyinUtils;
import com.landtool.lanbase.common.utils.Result;
import com.landtool.lanbase.config.SysTemPropertyConfig;
import com.landtool.lanbase.modules.api.utils.PageBean;
import com.landtool.lanbase.modules.org.entity.OrgUser;
import com.landtool.lanbase.modules.res.entity.GraphicStyle;
import com.landtool.lanbase.modules.res.entity.Res_Catalog;
import com.landtool.lanbase.modules.res.entity.Res_EchartsConfing;
import com.landtool.lanbase.modules.res.entity.Res_ExtBusinessLayer;
import com.landtool.lanbase.modules.res.entity.Res_ExtMapUrl;
import com.landtool.lanbase.modules.res.entity.Res_ExtThemeMap;
import com.landtool.lanbase.modules.res.entity.Res_MainInfo;
import com.landtool.lanbase.modules.res.entity.Res_SymbolLibrary;
import com.landtool.lanbase.modules.res.entity.Res_Theme_Module;
import com.landtool.lanbase.modules.res.entity.JSONModels.ServiceConfig;
import com.landtool.lanbase.modules.res.service.ResBusinessRefService;
import com.landtool.lanbase.modules.res.service.ResEchartsCofingService;
import com.landtool.lanbase.modules.res.service.ResExtBusinessLayerService;
import com.landtool.lanbase.modules.res.service.ResExtMapUrlService;
import com.landtool.lanbase.modules.res.service.ResExtThemeMapService;
import com.landtool.lanbase.modules.res.service.ResMainInfoService;
import com.landtool.lanbase.modules.res.service.ResQueryAroundService;
import com.landtool.lanbase.modules.res.service.ResSymbolLibraryService;
import com.landtool.lanbase.modules.res.service.ResThemeModuleService;
import com.landtool.lanbase.modules.sys.controller.AbstractController;
import com.landtool.lanbase.modules.sys.service.SysFieldvalueService;
 
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
 
@Controller
@RequestMapping("res/common")
public class CommonController extends AbstractController {
    @Autowired
    private SysTemPropertyConfig sysConfig;
    @Autowired
    private SysFieldvalueService FieldUtils;
    @Autowired
    private ResMainInfoService resMainInfoService;
    @Autowired
    private ResQueryAroundService resQueryAroundService;
    @Autowired
    private ResBusinessRefService resBusinessRefService;
    @Autowired
    private ResSymbolLibraryService resSymbolLibraryService;
    @Autowired
    private ResExtMapUrlService resExtMapUrlService;
    @Autowired
    private ResExtThemeMapService resExtThemeMapService;
    @Autowired
    private ResExtBusinessLayerService resExtBusinessLayerService;
    @Autowired
    private ResEchartsCofingService resEchartsCofingService;
    @Autowired
    private ResThemeModuleService resThemeModuleService;
 
    @RequestMapping("/resource_set_zbcx")
    public String resource_set_zbcx(Integer resourceid, Model model) {
        model.addAttribute("resourceid", resourceid);
        model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
        return "common/resource_set_zbcx";
    }
 
    @RequestMapping("/resource_set_gltc")
    public String resource_set_gltc(Integer resourceid, Model model) {
        model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
        return "common/resource_set_gltc";
    }
 
    //图形设置
    @RequestMapping("/resource_set_TuXin")
    public String resource_set_TuXin(Integer resourceid, Model model) {
        model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
        Res_MainInfo res_mainInfo = resMainInfoService.selectByPrimaryKey(resourceid);
        model.addAttribute("resMainInfo", res_mainInfo);
        return "common/resource_set_TuXin";
    }
 
    //添加图形设置面板
    //id表示 要编辑的行,如果有id的话,那么表示编辑
    @RequestMapping("/resource_add_TuXin")
    public String resource_add_TuXin(Integer resourceid, Model model, Integer id) {
        model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
        List<Res_ExtMapUrl> resExtMapUrlList = resExtMapUrlService.selectByCondition(resourceid);
        String url = "";
        List<String> List = new ArrayList<String>();
        for (int i = 0; i < resExtMapUrlList.size(); i++) {
            url = resExtMapUrlList.get(0).getServerurl();
        }
        try {
            String TokenResponse = HttpOperateUtils.httpGet(url + "?f=pjson");
            JSONObject jsStr = JSONObject.parseObject(TokenResponse);
            JSONArray obj = JSONArray.parseArray(jsStr.get("fields").toString());
            for (int i = 0; i < obj.size(); i++) {
                List.add(obj.getJSONObject(i).getString("name"));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        model.addAttribute("list", List);
        GraphicStyle graphicStyle = new GraphicStyle();
        if (id != null) {
            Res_MainInfo res_mainInfo = resMainInfoService.selectByPrimaryKey(resourceid);
            String[] Graphic = res_mainInfo.getGraphicStyle().split("\\|");
            JSONObject jsStr = JSONObject.parseObject(Graphic[id - 1]);
            graphicStyle.setType(jsStr.getString("type"));
            graphicStyle.setDisplayMode(jsStr.getString("displayMode"));
            graphicStyle.setClassfield(jsStr.getString("classfield"));
            graphicStyle.setValueField(jsStr.getString("ValueField"));
            graphicStyle.setStatisticalMethod(jsStr.getString("StatisticalMethod"));
        }
        model.addAttribute("graphicStyle", graphicStyle);
        model.addAttribute("hangshu", id);
        model.addAttribute("resourceid", resourceid);
        return "common/resource_add_TuXin";
    }
 
    //图形保存设置
    @ResponseBody
    @RequestMapping("/TuXingConfigAdd")
    public String TuXingConfigAdd(Integer resourceid, Model model, GraphicStyle graphicStyle, Integer hangshu) {
        model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
        Res_MainInfo res_mainInfo = resMainInfoService.selectByPrimaryKey(resourceid);
        //新增
        int count = 0;
        if (hangshu == null) {
            String graphic = "";
            if (res_mainInfo.getGraphicStyle() == null || !res_mainInfo.getGraphicStyle().equals("")) {
                graphic += "|";
            }
            graphic += "{'type':" + "'" + graphicStyle.getType() + "'" + ",";
            graphic += "'displayMode':" + "'" + graphicStyle.getDisplayMode() + "'" + ",";
            graphic += "'classfield':" + "'" + graphicStyle.getClassfield() + "'" + ",";
            graphic += "'ValueField':" + "'" + graphicStyle.getValueField() + "'" + ",";
            graphic += "'StatisticalMethod':" + "'" + graphicStyle.getStatisticalMethod() + "'}";
            Res_MainInfo res_mainInfo1 = new Res_MainInfo();
            res_mainInfo1.setResourceid(resourceid);
            if (res_mainInfo.getGraphicStyle() == null) {
                res_mainInfo1.setGraphicStyle(graphic);
            } else {
                res_mainInfo1.setGraphicStyle(res_mainInfo.getGraphicStyle() + graphic);
            }
            count = resMainInfoService.updateByPrimaryKeySelective(res_mainInfo1);
        } else {
            String[] Graphic = res_mainInfo.getGraphicStyle().split("\\|");
            String graphic = "";
            graphic += "{'type':" + "'" + graphicStyle.getType() + "'" + ",";
            graphic += "'displayMode':" + "'" + graphicStyle.getDisplayMode() + "'" + ",";
            graphic += "'classfield':" + "'" + graphicStyle.getClassfield() + "'" + ",";
            graphic += "'ValueField':" + "'" + graphicStyle.getValueField() + "'" + ",";
            graphic += "'StatisticalMethod':" + "'" + graphicStyle.getStatisticalMethod() + "'}";
            //对应行数里面的值替换
            Graphic[hangshu - 1] = graphic;
            StringBuilder rsb = new StringBuilder();
            //然后对数组进行循环,拼接成字符串
            for (int i = 0; i < Graphic.length; i++) {
                JSONObject jsStr = JSONObject.parseObject(Graphic[i]);
                if (i != 0) {
                    rsb.append("|");
                }
                int id = i + 1;
                rsb.append("{");
                rsb.append("'type':'" + jsStr.getString("type") + "'");
                rsb.append(",'id':'" + id + "'");
                rsb.append(",'displayMode':'" + jsStr.getString("displayMode") + "'");
                rsb.append(",'classfield':'" + jsStr.getString("classfield") + "'");
                rsb.append(",'ValueField':'" + jsStr.getString("ValueField") + "'");
                rsb.append(",'StatisticalMethod':'" + jsStr.getString("StatisticalMethod") + "'");//资源类型
                rsb.append("}");
            }
            Res_MainInfo res_mainInfo1 = new Res_MainInfo();
            res_mainInfo1.setResourceid(resourceid);
            res_mainInfo1.setGraphicStyle(rsb.toString());
            count = resMainInfoService.updateByPrimaryKeySelective(res_mainInfo1);
 
        }
        model.addAttribute("resMainInfo", res_mainInfo);
        return "{'count':'" + count + "'}";
    }
 
    //图形删除设置
    @ResponseBody
    @RequestMapping("/TuXinCongiDelect")
    public String TuXinCongiDelect(Integer resourceid, Model model, Integer hangshu) {
        model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
        Res_MainInfo res_mainInfo = resMainInfoService.selectByPrimaryKey(resourceid);
        int count = 0;
        String[] Graphic = res_mainInfo.getGraphicStyle().split("\\|");
        Graphic = deleteMethod(hangshu - 1, Graphic);
        StringBuilder rsb = new StringBuilder();
        //然后对数组进行循环,拼接成字符串
        for (int i = 0; i < Graphic.length; i++) {
            JSONObject jsStr = JSONObject.parseObject(Graphic[i]);
            if (i != 0) {
                rsb.append("|");
            }
            int id = i + 1;
            rsb.append("{");
            rsb.append("'type':'" + jsStr.getString("type") + "'");
            rsb.append(",'id':'" + id + "'");
            rsb.append(",'displayMode':'" + jsStr.getString("displayMode") + "'");
            rsb.append(",'classfield':'" + jsStr.getString("classfield") + "'");
            rsb.append(",'ValueField':'" + jsStr.getString("ValueField") + "'");
            rsb.append(",'StatisticalMethod':'" + jsStr.getString("StatisticalMethod") + "'");//资源类型
            rsb.append("}");
        }
        Res_MainInfo res_mainInfo1 = new Res_MainInfo();
        res_mainInfo1.setResourceid(resourceid);
        res_mainInfo1.setGraphicStyle(rsb.toString());
        count = resMainInfoService.updateByPrimaryKeySelective(res_mainInfo1);
        model.addAttribute("resMainInfo", res_mainInfo);
        return "{'count':'" + count + "'}";
    }
 
    public String[] deleteMethod(int index, String array[]) {
        //数组的删除其实就是覆盖前一位
        String[] arrNew = new String[array.length - 1];
        for (int i = index; i < array.length - 1; i++) {
            array[i] = array[i + 1];
        }
        System.arraycopy(array, 0, arrNew, 0, arrNew.length);
        return arrNew;
    }
 
    //读取图形设置
    @ResponseBody
    @RequestMapping("/TuXingConfigSelectAll")
    public String TuXingConfigSelectAll(Integer resourceid) {
        Res_MainInfo res_mainInfo = resMainInfoService.selectByPrimaryKey(resourceid);
        String[] Graphic = {};
        if (res_mainInfo != null && res_mainInfo.getGraphicStyle() != null) {
            Graphic = res_mainInfo.getGraphicStyle().split("\\|");
        }
        //查询arg url.
        List<Res_ExtMapUrl> resExtMapUrlList = resExtMapUrlService.selectByCondition(resourceid);
        String url = "";
        List<String> List = new ArrayList<String>();
        for (int i = 0; i < resExtMapUrlList.size(); i++) {
            url = resExtMapUrlList.get(0).getServerurl();
        }
        // http://192.168.0.140:6080/arcgis/rest/services/onemapjm/MapServer/26/query 加上query才能查询地图字段
        url = url + "/query";
        StringBuilder rsb = new StringBuilder();
        rsb.append("{'totalCount':'" + Graphic.length + "','url':'" + url + "");
        rsb.append("','topics':[");
        for (int i = 0; i < Graphic.length; i++) {
            JSONObject jsStr = JSONObject.parseObject(Graphic[i]);
            if (i != 0) {
                rsb.append(",");
            }
            int id = i + 1;
            rsb.append("{");
            rsb.append("'type':'" + jsStr.getString("type") + "'");
            rsb.append(",'id':'" + id + "'");
            rsb.append(",'displayMode':'" + jsStr.getString("displayMode") + "'");
            rsb.append(",'classfield':'" + jsStr.getString("classfield") + "'");
            rsb.append(",'ValueField':'" + jsStr.getString("ValueField") + "'");
            rsb.append(",'StatisticalMethod':'" + jsStr.getString("StatisticalMethod") + "'");//资源类型
            rsb.append("}");
        }
        rsb.append("]}");
        return rsb.toString();
    }
 
    //读取图形配置
    //http://127.0.0.1:8082/res/common/TuXingConfig
    @RequestMapping("/TuXingConfig")
    public String TuXingConfig(Integer resourceid, Model model) {
        List<Res_ExtMapUrl> resExtMapUrlList = resExtMapUrlService.selectByCondition(resourceid);
        String url = "";
        List<String> List = new ArrayList<String>();
        for (int i = 0; i < resExtMapUrlList.size(); i++) {
            url = resExtMapUrlList.get(0).getServerurl();
        }
        // http://192.168.0.140:6080/arcgis/rest/services/onemapjm/MapServer/26/query 加上query才能查询地图字段
        url = url + "/query";
        model.addAttribute("url", url);
        model.addAttribute("resourceid", resourceid);
        model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
        return "common/TuXingConfig";
    }
 
    //添加资源 - 多选
    @RequestMapping("/resource_select")
    public String resource_select(Model model, String flag, Integer resourceid) {
        model.addAttribute("flag", flag);
        model.addAttribute("resourceid", resourceid);
        model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
        model.addAttribute("lanbaseurl", sysConfig.getApiServer());
        // 获取数据来源表
        HashMap<String, String> DataSourceList = FieldUtils.getDataSourceList();// 获取数据来源列表
        model.addAttribute("DataSourceList", DataSourceList);
        return "common/resource_select";
    }
 
    /**
     * 添加关联图层列表(弃用,改用树)
     *
     * @param flag
     * @param resMainInfo
     * @param pageBean
     * @return
     */
    @ResponseBody
    @RequestMapping("/getResourceSelect")
    public String getResourceSelect(String flag, Res_MainInfo resMainInfo, PageBean pageBean) {
        Page<Res_MainInfo> page = PageHelper.startPage(pageBean.getPage(), pageBean.getLimit());
        List<Res_MainInfo> res_mainInfos = null;
        if (flag.equals("zbcx")) {
            res_mainInfos = resQueryAroundService.getResourceSelectZBCX(resMainInfo);
        } else if (flag.equals("gltc")) {
            res_mainInfos = resBusinessRefService.getResourceSelectGLTC(resMainInfo);
        }
        int countNums = (int) ((Page) res_mainInfos).getTotal();
        PageBean<Res_MainInfo> pageData = new PageBean<>(pageBean.getPage(), pageBean.getLimit(), countNums);
        pageData.setItems(res_mainInfos);
        LinkedHashMap<String, String> resourceTypeList = FieldUtils.getFieldListByKey("ResourceType");//获取资源类型列表
        StringBuilder rsb = new StringBuilder();
        rsb.append("{'totalCount':'" + countNums);
        rsb.append("','topics':[");
        for (int i = 0; i < res_mainInfos.size(); i++) {
            if (i != 0) {
                rsb.append(",");
            }
            rsb.append("{");
            rsb.append("'TITLE':'" + res_mainInfos.get(i).getTitle() + "'");
            rsb.append(",'DATASOURCES':'" + res_mainInfos.get(i).getDatasources() + "'");
            rsb.append(",'RESOURCEID':'" + res_mainInfos.get(i).getResourceid() + "'");
            rsb.append(",'RESOURCECLASS':'" + resourceTypeList.get(res_mainInfos.get(i).getResourceclass()) + "'");//资源类型
            rsb.append("}");
        }
        rsb.append("]}");
        return rsb.toString();
    }
 
    /**
     * 获取资源设置树
     */
    @ResponseBody
    @RequestMapping("/getResourceSelectTree")
    public String getResourceSelectTree(String flag, Res_MainInfo resMainInfo, String parentid) {
        StringBuilder resCatalogJson = new StringBuilder();
        Map<String, Object> map = new HashMap<>();
        map.put("resourceid", resMainInfo.getResourceid());
        map.put("title", resMainInfo.getTitle());
        map.put("resourceclass", resMainInfo.getResourceclass());
        map.put("datasources", resMainInfo.getDatasources());
        map.put("parentid", parentid);
        List<Res_MainInfo> res_mainInfos = null;
        List<Res_Catalog> resCatalogList = null;
        if (flag.equals("zbcx")) {
            resCatalogList = resQueryAroundService.getResourceZBCXCatalog(map);
            res_mainInfos = resQueryAroundService.getResourceZBCXCatalogList(map);
        } else if (flag.equals("gltc")) {
            resCatalogList = resBusinessRefService.getResourceGLTCCatalog(map);
            res_mainInfos = resBusinessRefService.getResourceGLTCCatalogList(map);
        }
        // 循环构造子目录节点
        List<Map<String, Object>> maps = new LinkedList<>();
        for (Res_Catalog resCatalog : resCatalogList) {
            if (!"".equals(resCatalogJson.toString())) {
                resCatalogJson.append(',');
            }
            Map<String, Object> catlogmap = new HashMap<>();
            catlogmap.put("id", resCatalog.getCatlogid());
            catlogmap.put("name", resCatalog.getTitle());
            catlogmap.put("title", resCatalog.getTitle());
            catlogmap.put("isParent", true);
            catlogmap.put("iconOpen", "/image/classicons/folderOpen.png");
            catlogmap.put("iconClose", "/image/classicons/folder.png");
            maps.add(catlogmap);
//            resCatalogJson.append("{id: " + resCatalog.getCatlogid() + ",name:'" + resCatalog.getTitle() + "',title:'" + resCatalog.getTitle() + "',isParent: true,iconOpen:'/image/classicons/folderOpen.png',iconClose:'/image/classicons/folder.png'}");
        }
        // 循环构造资源节点
        for (Res_MainInfo resMainInfo1 : res_mainInfos) {
            if (!"".equals(resCatalogJson.toString())) {
                resCatalogJson.append(',');
            }
            Map<String, Object> ctalogmap = new HashMap<>();
            ctalogmap.put("id", "ZiYuan_" + resMainInfo1.getResourceid());
            ctalogmap.put("name", resMainInfo1.getTitle());
            ctalogmap.put("title", resMainInfo1.getTitle());
            ctalogmap.put("isParent", false);
            ctalogmap.put("icon", "/image/classicons/"+ resMainInfo1.getResourceclass() +".png");
            maps.add(ctalogmap);
//            resCatalogJson.append("{id: 'ZiYuan_" + resMainInfo1.getResourceid() + "',name:'" + resMainInfo1.getTitle() + "', title: '" + resMainInfo1.getDatasources() + "',isParent:false,icon:'/image/classicons/"+ resMainInfo1.getResourceclass() +".png'}");
        }
        return JSON.toJSONString(maps, SerializerFeature.WriteMapNullValue);
    }
 
    /**
     * 自动补全输入首字母查询
     *
     * @param keyWord
     * @return
     */
    @ResponseBody
    @GetMapping("/findPinyinByKeyWord")
    public String[] findpinyinByKeyWord(@RequestParam(name = "keyWord") String keyWord, String flag, Integer resourceid) {
        keyWord = URLDecoder.decode(keyWord);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("resourceid", resourceid);
        map.put("keyWord", keyWord);
        List<Res_MainInfo> list = null;
        if (flag.equals("zbcx")) {
            list = resQueryAroundService.getResourceZBCXCatalogList(map);
        } else if (flag.equals("gltc")) {
            list = resBusinessRefService.getResourceGLTCCatalogList(map);
        }
        String[] arr = new String[list.size()];
        for (int i = 0; i < list.size(); i++) {
            String title = list.get(i).getTitle();
            arr[i] = title;
        }
        return arr;
    }
 
    /**
     * 地图范围框选
     *
     * @param drawType    地图绘制类型(point: 点 extent: 范围)
     * @param callbackFun 绘制回调类型(处理同一页面多个调用类型区分)
     * @param model
     * @return
     */
    @RequestMapping("/obtainExtentMapViewer")
    public String obtainExtentMapViewer(String drawType, String callbackFun, Model model) {
        model.addAttribute("drawType", drawType);//绘制类型
        model.addAttribute("callbackFun", callbackFun);//回调类型
        model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
        model.addAttribute("obtainExtentMapUrl", sysConfig.getObtainExtentMapUrl());//框选地图底图URL
        return "common/obtainExtentMapViewer";
    }
 
    /**
     * 符号库风格更新
     *
     * @return
     */
    @ResponseBody
    @RequestMapping("/updateSymbolLibrary")
    public String updateSymbolLibrary() {
        String pointSymbolUrl = "http://ocean-data.nmdis.com/arcgis/rest/services/JCDL/fuhao2/MapServer/0";    //点符号服务地址
        String polylineSymbolUrl = "http://ocean-data.nmdis.com/arcgis/rest/services/JCDL/fuhao2/MapServer/1"; //线符号服务地址
        String polygonSymbolUrl = "http://ocean-data.nmdis.com/arcgis/rest/services/JCDL/fuhao2/MapServer/2";  //面符号服务地址
        String[][] arr = new String[][]{{pointSymbolUrl, "点"}, {polylineSymbolUrl, "线"}, {polygonSymbolUrl, "面"}};
        String resultMsg = "更新成功!";
        String errorMsg = "";
 
        for (int i = 0; i < arr.length; i++) {
            try {
                String ResultJsonStr = HttpOperateUtils.httpGet(arr[i][0].trim() + "?f=json");
                JSONObject drawingInfo = JSONObject.parseObject(ResultJsonStr).getJSONObject("drawingInfo");
                if (drawingInfo != null) {
                    JSONObject renderer = drawingInfo.getJSONObject("renderer");
                    if (renderer != null) {
                        JSONArray uniqueValueInfos = renderer.getJSONArray("uniqueValueInfos");
                        if (uniqueValueInfos != null) {
                            for (int j = 0; j < uniqueValueInfos.size(); j++) {
                                String FHID = uniqueValueInfos.getJSONObject(j).getString("label");
                                String SYMBOL = uniqueValueInfos.getJSONObject(j).getString("symbol");
                                Res_SymbolLibrary resSymbolLibrary = new Res_SymbolLibrary();
                                resSymbolLibrary.setFhid(FHID);
                                resSymbolLibrary.setGeotype(arr[i][1]);
                                Res_SymbolLibrary res_symbolLibrary = resSymbolLibraryService.getByIdAndGeoType(resSymbolLibrary);//获取符号库对应记录
                                if (res_symbolLibrary != null) {
                                    res_symbolLibrary.setSymbol(SYMBOL);
                                    resSymbolLibraryService.updateByPrimaryKey(res_symbolLibrary);//更新符号库对应记录符号风格
                                }
                            }
                        }
                    }
                }
            } catch (IOException e) {
                errorMsg += arr[i][1] + ":" + e.getMessage() + "\r\n";
                continue;
            }
        }
 
        if (errorMsg.isEmpty()) {
            return resultMsg;
        } else {
            return errorMsg;
        }
    }
 
    /**
     * 符号库管理
     *
     * @return
     */
    @RequestMapping("symbolLibrary/index")
    public String symbolLibraryIndex(Model model) {
        List<String> mc = resSymbolLibraryService.getMC();
        model.addAttribute("mclist", mc);
        model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
        model.addAttribute("systemName", sysConfig.getAppFullName());
        return "manage/symbolLibrary/index";
    }
 
    /**
     * 获取符号库列表
     *
     * @param resSymbolLibrary
     * @param pageBean
     * @return
     */
    @ResponseBody
    @RequestMapping("symbolLibrary/getlist")
    @RequiresPermissions("res:symbolLibrary:edit")
    @LogAction("资源管理,符号库管理,符号库列表查询,查询")
    public Result getList(Res_SymbolLibrary resSymbolLibrary, PageBean pageBean) {
        PageHelper.startPage(pageBean.getPage(), pageBean.getLimit());
        List<Res_SymbolLibrary> resSymbolLibraryList = resSymbolLibraryService.getList(resSymbolLibrary);
        int countNums = (int) ((Page) resSymbolLibraryList).getTotal();
        PageBean<Res_SymbolLibrary> pageData = new PageBean<>(pageBean.getPage(), pageBean.getLimit(), countNums);
        pageData.setItems(resSymbolLibraryList);
        StringBuilder rsb = new StringBuilder();
        rsb.append("{'totalCount':'" + countNums + "','topics':[");
        List<Map<String, Object>> maps = new LinkedList<>();
        for (int i = 0; i < resSymbolLibraryList.size(); i++) {
            Map<String, Object> map = new HashMap<>();
            map.put("objectid", resSymbolLibraryList.get(i).getObjectid());
            map.put("fhid", resSymbolLibraryList.get(i).getFhid());
            map.put("mc", resSymbolLibraryList.get(i).getMc());
            map.put("geotype", resSymbolLibraryList.get(i).getGeotype());
            maps.add(map);
 
//            if (i != 0) rsb.append(",");
//            rsb.append("{'objectid':'" + resSymbolLibraryList.get(i).getObjectid() + "','fhid':'" + resSymbolLibraryList.get(i).getFhid() + "','mc':'" + resSymbolLibraryList.get(i).getMc() + "','geotype':'" + resSymbolLibraryList.get(i).getGeotype() + "'}");
        }
//        rsb.append("]}");
        return Result.ok().put("totalCount", countNums).put("topics", maps);
    }
 
    /**
     * 符号编辑页面
     *
     * @param OBJECTID
     * @return
     */
    @RequestMapping("symbolLibrary/edit")
    public String edit(Model model, int OBJECTID) {
        Res_SymbolLibrary resSymbolLibrary = resSymbolLibraryService.getById(OBJECTID);//获取符号信息
        if (resSymbolLibrary == null) {
            resSymbolLibrary = new Res_SymbolLibrary();
        }
        model.addAttribute("resSymbolLibrary", resSymbolLibrary);
        model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
 
        return "manage/symbolLibrary/edit";
    }
 
    /**
     * 符号编辑保存
     *
     * @param entity
     * @return
     */
    @ResponseBody
    @RequestMapping("symbolLibrary/save")
    @LogAction("资源管理,符号库管理,符号库列表修改,修改")
    public String edit(Model model, Res_SymbolLibrary entity) {
        try {
            Res_SymbolLibrary resSymbolLibrary = resSymbolLibraryService.getById(entity.getObjectid());//获取符号信息
            resSymbolLibrary.setSymbol(entity.getSymbol());
            resSymbolLibraryService.updateByPrimaryKey(resSymbolLibrary);
 
            return "{success: true, msg: '保存成功!'}";
        } catch (Exception e) {
            return "{success: false, msg: '" + e.getMessage() + "'}";
        }
    }
 
    /**
     * 符号库符号展示地图页面
     *
     * @param model
     * @param symbol
     * @param geotype
     * @return
     */
    @RequestMapping("symbolLibrary/symbolmap")
    public String symbolmap(Model model, String symbol, String geotype) {
        model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
        model.addAttribute("obtainExtentMapUrl", sysConfig.getObtainExtentMapUrl());//框选地图底图URL
        model.addAttribute("symbol", symbol);
        model.addAttribute("geotype", geotype);
 
        return "manage/symbolLibrary/symbolmap";
    }
 
    //编辑器上传图片
    @RequestMapping("/uploadueditorfile")
    public ResponseEntity<Map<String, Object>> uploadueditorfile(@RequestParam(value = "upfile", required = false) MultipartFile file, HttpServletRequest request) {//value的名字一定要叫upfile,这是ueditor写好的参数名称
        String fileName = file.getOriginalFilename();
        String[] types = fileName.split("\\.");
        String type = types[types.length - 1];
        String root = sysConfig.getUploadPath().replace("/", "\\");
        String LinShiUrl = root + "\\ueditor";
        String suffix = FileUtils.getSuffix(file.getOriginalFilename());
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        String timePath = sdf.format(new Date().getTime());
        timePath = timePath.replace("-", "");
        String newFileName = AttachmentUtils.newFileName(suffix, LinShiUrl, timePath);
        File newFile = new File(newFileName);
        //临时文件处理
        try {
            file.transferTo(newFile);
        } catch (Exception e) {
            e.printStackTrace();
        }
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("state", "SUCCESS");// UEDITOR的规则:不为SUCCESS则显示state的内容
        result.put("url", sysConfig.getUploadRootPath() + FileUtils.removePrefix(newFile.getAbsolutePath(), root).replace("\\", "/"));
        result.put("title", file.getOriginalFilename());
        result.put("original", file.getOriginalFilename());
        result.put("size", file.getSize());
        result.put("type", type);
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.TEXT_PLAIN);
        return new ResponseEntity<Map<String, Object>>(result, headers, HttpStatus.OK);
    }
 
    /**
     * 客户端获取Token
     *
     * @param resourceId 资源ID
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping("/getToken")
    public String getToken(int resourceId, HttpServletRequest request) {
        String result = "";
        String callbackFunName = request.getParameter("callback");
        if (callbackFunName == null || callbackFunName.isEmpty()) {
            callbackFunName = "callback";
        }
        try {
            Long userid = ((OrgUser) SecurityUtils.getSubject().getPrincipal()).getUserid();
            Res_MainInfo resMainInfo = resMainInfoService.selectByPrimaryKey(resourceId);//获取资源主表信息
            if (resMainInfo != null) {
                boolean isPubzy = false;
                if (resMainInfo != null && resMainInfo.getSharprotocol().equals("完全公开")) {
                    isPubzy = true;
                }
                String subzyids = "";
                String serverUrl = "null";
                //查询是否是专题地图,是专题地图则获取相关子图层ID
                if (resMainInfo.getResourceclass().equals("KJ_ZTDT")) {
                    Res_ExtThemeMap resExtThemeMap = resExtThemeMapService.selectByPrimaryKey(resourceId);
                    if (resExtThemeMap != null) {
                        subzyids = resExtThemeMap.getSublayerset();
                    }
                }
                Res_ExtMapUrl resExtMapUrl = resExtMapUrlService.queryFirstOrderByResId(resourceId);
                if (resExtMapUrl != null) {
                    serverUrl = resExtMapUrl.getServerurl() == null || resExtMapUrl.getServerurl().isEmpty() ? "null" : "\"" + resExtMapUrl.getServerurl() + "\"";
                }
                String token = EsbToken.getEsbUrl(serverUrl, userid.intValue(), request.getRemoteAddr(), resourceId, resMainInfo.getEspproxy(), sysConfig, subzyids, isPubzy, resMainInfo.getToken(), true);
                result = "{ \"success\": true, \"serverUrl\": " + serverUrl + ", \"token\": " + (token.isEmpty() ? "null" : "\"" + token + "\"") + "}";
            } else {
                result = "{ \"success\": false, \"msg\": \"资源不存在!\" }";
            }
        } catch (Exception e) {
            result = "{ \"success\": false, \"msg\": \"" + e.getMessage() + "\" }";
        }
        return callbackFunName + "(" + result + ")";
    }
 
 
    /**
     * 业务图层 - 图表设置页面
     *
     * @param resourceid 资源ID
     * @param model
     * @param name       变量 如:var1,table1
     * @param type       所属类别 如:vars,tables
     * @return
     */
    @RequestMapping("/serviceconfig")
    public String setServiceConfig(Integer resourceid, Model model, String name, String type) {
        List<Res_ExtMapUrl> resExtMapUrlList = resExtMapUrlService.selectByCondition(resourceid);
        model.addAttribute("resourceid", resourceid);
        model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
        model.addAttribute("jspwebroot", sysConfig.getPubzyWebRoot().replace("javapubzy/", ""));// 临时处理
 
        //获取list
        JSONArray chartsList = new JSONArray();
        JSONArray tablesList = new JSONArray();
        JSONArray varsList = new JSONArray();
        Res_ExtBusinessLayer resExtBusinessLayer = resExtBusinessLayerService.selectByPrimaryKey(resourceid);
        if (resExtBusinessLayer != null && resExtBusinessLayer.getServiceConfig() != null && !resExtBusinessLayer.getServiceConfig().equals("")) {
            JSONObject obj = JSONObject.parseObject(resExtBusinessLayer.getServiceConfig());
            for (int i = 0; i < obj.size(); i++) {
                JSONArray object = null;
                //每次只取一个类
                if (i == 0) {
                    if (obj.getJSONArray("vars") != null) { //常量
                        object = obj.getJSONArray("vars");
                        if (object != null) {
                            for (int j = 0; j < object.size(); j++) {
                                String key = object.getJSONObject(j).getString("name");
                                String explain = object.getJSONObject(j).getJSONObject(key).getString("explain");
                                if(explain == null) {
                                    explain = "";
                                }
                                String listKey = "{\"key\":\"" + key + "\",\"explain\":\"" + explain + "\"}";
                                varsList.add(JSONObject.parseObject(listKey));
                            }
                        }
                    }
                }
                if (i == 1) {
                    if (obj.getJSONArray("tables") != null) { //表格
                        object = obj.getJSONArray("tables");
                        if (object != null) {
                            for (int j = 0; j < object.size(); j++) {
                                String key = object.getJSONObject(j).getString("name");
                                String explain = object.getJSONObject(j).getJSONObject(key).getString("explain");
                                if(explain == null) {
                                    explain = "";
                                }
                                String listKey = "{\"key\":\"" + key + "\",\"explain\":\"" + explain + "\"}";
                                tablesList.add(JSONObject.parseObject(listKey));
                            }
                        }
                    }
                }
                if (i == 2) {
                    if (obj.getJSONArray("charts") != null) { //图表
                        object = obj.getJSONArray("charts");
                        if (object != null) {
                            for (int j = 0; j < object.size(); j++) {
                                String key = object.getJSONObject(j).getString("name");
                                String explain = object.getJSONObject(j).getJSONObject(key).getString("explain");
                                if(explain == null) {
                                    explain = "";
                                }
                                String listKey = "{\"key\":\"" + key + "\",\"explain\":\"" + explain + "\"}";
                                chartsList.add(JSONObject.parseObject(listKey));
                            }
                        }
                    }
                }
            }
        }
        model.addAttribute("chartsList", chartsList);
        model.addAttribute("tablesList", tablesList);
        model.addAttribute("varsList", varsList);
 
        String serviceHTML = "";
        if(resExtBusinessLayer != null && resExtBusinessLayer.getServiceHTML() != null && !resExtBusinessLayer.getServiceHTML().equals("")) {
            serviceHTML = replaceServiceHTML(resExtBusinessLayer.getServiceHTML(), resourceid, "htmlToChar");
        }
        model.addAttribute("serviceHTML", serviceHTML);
        model.addAttribute("systemName", sysConfig.getAppFullName());
        return "common/ServiceConfig";
    }
 
    // settype0是表示业务图层的 1是表示一张图的
    @RequestMapping("/addserviceconfig")
    public String addSetServiceConfig(Integer resourceid, Model model, String name, String type,Integer moduleid,Integer settype,String associationlayer) {
        String url = "";
        List<String> List = new ArrayList<String>();
        Res_ExtBusinessLayer resExtBusinessLayer = null;
        Res_Theme_Module resThemeModule = null;
        Integer thismoduleid = moduleid != null?moduleid:0;
 
        String token = "";
        if(settype != null && settype == 0) { //业务图层
            resExtBusinessLayer = resExtBusinessLayerService.selectByPrimaryKey(resourceid);
            List<Res_ExtMapUrl> resExtMapUrlList = resExtMapUrlService.selectByCondition(resourceid);
            if (resExtMapUrlList.size() > 0) {
                url = resExtMapUrlList.get(0).getServerurl();
                Res_MainInfo resMainInfo = resMainInfoService.selectByPrimaryKey(resourceid);
                boolean isPubzy = false;
                if (resMainInfo != null && !resMainInfo.getSharprotocol().equals("完全公开")) {
                    token = EsbToken.getEsbUrl(url, getUserId().intValue(), sysConfig.getIpHost(), resourceid, resMainInfo.getEspproxy(), sysConfig, null, isPubzy, resMainInfo.getToken(), true);
                }
            }
        }else { //一张图
            resThemeModule = resThemeModuleService.selectByid(moduleid);
            if(resThemeModule != null && resThemeModule.getServiceconfig() !=null && !resThemeModule.getServiceconfig().trim().equals("")){
                if(type.equals("tables")){
                    name = "table1";
                }else{
                    name = "chart1";
                }
            }
            url = java.net.URLDecoder.decode(associationlayer);
        }
        if (url != null && !"".equals(url)) {
            try {
                if(url.indexOf("?")!=-1){
                    if(!"".equals(token)) {
                        url += "&f=pjson&token=" + token;
                    }
                    else {
                        url += "&f=pjson";
                    }
                }else{
                    if(!"".equals(token)) {
                        url +="?f=pjson&token=" + token;
                    }
                    else {
                        url += "?f=pjson";
                    }
                }
                String TokenResponse = "";
                //ESB代理的地址需要解密
                if(HttpOperateUtils.isgzip(url)) {
                    TokenResponse = HttpUtils.getGZip(url);
                }
                else {
                    TokenResponse = HttpOperateUtils.httpGet(url);
                }
                JSONObject jsStr = JSONObject.parseObject(TokenResponse);
                if(jsStr.containsKey("fields")) {
                    JSONArray obj = JSONArray.parseArray(jsStr.get("fields").toString());
                    for (int i = 0; i < obj.size(); i++) {
                        List.add(obj.getJSONObject(i).getString("name"));
                    }
                }
            } catch (IOException e) {
                e.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        model.addAttribute("list", List);
        model.addAttribute("resourceid", resourceid);
        model.addAttribute("moduleid", thismoduleid);
        model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
        model.addAttribute("jspwebroot", sysConfig.getPubzyWebRoot().replace("javapubzy/", ""));// 临时处理
        model.addAttribute("settype", settype);
        ServiceConfig serviceConfig = new ServiceConfig();
        String key = "";
        List fieldsList = new ArrayList();
        StringBuilder str = new StringBuilder();
        String fileds = "[]";
        //编辑配置相关信息
        if (name != null && !name.equals("")) {
            //判断是属于哪一项,获取对应的json
            if (name.substring(0, 1).equals("v")) {
                key = "vars";
            }
            if (name.substring(0, 1).equals("t")) {
                key = "tables";
            }
            if (name.substring(0, 1).equals("c")) {
                key = "charts";
            }
            if ((settype == 0 && resExtBusinessLayer != null && resExtBusinessLayer.getServiceConfig() != null) || (settype == 1 && resThemeModule != null && resThemeModule.getServiceconfig() != null && !resThemeModule.getServiceconfig().trim().equals(""))) {
                JSONObject obj = JSONObject.parseObject(settype == 0 ?resExtBusinessLayer.getServiceConfig():resThemeModule.getServiceconfig());
                JSONObject newobj = null;
                boolean flag = false;
                if (obj.getJSONArray(key) != null) {
                    //获取所要编辑的项所在的json数组
                    JSONArray jsonArray = obj.getJSONArray(key);
                    if (jsonArray != null) {
                        //遍历数组,如果key一致则取出相关配置信息,退出循环
                        for (int j = 0; j < jsonArray.size(); j++) {
                            org.json.JSONObject jsonObject = new org.json.JSONObject(jsonArray.getJSONObject(j));
                            Iterator iterator = jsonObject.keys();
                            while (iterator.hasNext()) {
                                String skey = (String) iterator.next();
                                if (skey.equals(name)) {
                                    newobj = JSONObject.parseObject(jsonArray.getString(j));
                                    newobj = JSONObject.parseObject(newobj.getString(name));
                                    if (key.equals("vars")) {
                                        serviceConfig.setField(newobj.getString("field"));
                                        serviceConfig.setFunc(newobj.getString("StatisticalMethod"));
                                        serviceConfig.setWhere(newobj.getString("where"));
                                        serviceConfig.setExplain(newobj.getString("explain"));
                                        serviceConfig.setDecimalDigits(newobj.getString("DecimalDigits"));
                                        serviceConfig.setUnitConversion(newobj.getString("UnitConversion"));
                                    }
                                    if (key.equals("tables")) {
                                        serviceConfig.setGroupby(newobj.getString("groupby"));
                                        serviceConfig.setGroupbyalias(newobj.getString("groupbyalias"));
                                        serviceConfig.setWhere(newobj.getString("where"));
                                        serviceConfig.setExplain(newobj.getString("explain"));
                                        serviceConfig.setDecimalDigits(newobj.getString("DecimalDigits"));
                                        serviceConfig.setUnitConversion(newobj.getString("UnitConversion"));
                                        JSONArray tableArray = newobj.getJSONArray("list");
                                        fileds  =newobj.getString("list");
                                    }
                                    if (key.equals("charts")) {
                                        serviceConfig.setId(newobj.getString("id"));
                                        serviceConfig.setClassfield(newobj.getString("classField"));
                                        serviceConfig.setStatisticalmethod(newobj.getString("StatisticalMethod"));
                                        serviceConfig.setTitle(newobj.getString("title"));
                                        serviceConfig.setType(newobj.getString("type"));
                                        serviceConfig.setDisplaymode(newobj.getString("displayMode"));
                                        serviceConfig.setOption(newobj.getString("option"));
                                        serviceConfig.setValuefield(newobj.getString("ValueField"));
                                        serviceConfig.setWhere(newobj.getString("where"));
                                        serviceConfig.setExplain(newobj.getString("explain"));
                                        serviceConfig.setDecimalDigits(newobj.getString("DecimalDigits"));
                                        serviceConfig.setUnitConversion(newobj.getString("UnitConversion"));
                                    }
                                    flag = true;
                                    break;
                                }
                            }
                            if (flag) break;
                        }
                    }
                }
            }
        }
        model.addAttribute("jsonconfig", serviceConfig);
        if (key.equals("") && type != null) {
            key = type;
        }
        model.addAttribute("jsontype", key);
        model.addAttribute("jsonname", name);
        model.addAttribute("fieldsList", fileds);
 
        List<Res_EchartsConfing> resEchartsConfingList = resEchartsCofingService.selectAllChart(settype);
        JSONArray echarts = new JSONArray();
        for (int i=0;i<resEchartsConfingList.size();i++) {
            String echart = "{\"id\":\"" + resEchartsConfingList.get(i).getEchartsid() +
                    "\",\"type\":\"" + resEchartsConfingList.get(i).getEchartstype() + "\",\"key\":\"" + resEchartsConfingList.get(i).getEchartstitle() + "\"}";
            echarts.add(JSONObject.parseObject(echart));
        }
        model.addAttribute("echarts",echarts);
        return "common/add_ServiceConfig";
    }
 
    /**
     * 保存相关配置
     *
     * @param resourceid    资源 ID
     * @param contype       保存所属类别 如:vars,tables
     * @param serviceConfig 相关配置字段信息
     * @param serviceHTML   编辑器HTML内容
     * @return
     */
    @ResponseBody
    @RequestMapping("saveconfig")
    public String saveconfig(Integer resourceid, String contype, ServiceConfig serviceConfig, String serviceHTML, Integer moduleid,Integer settype) {
        Res_ExtBusinessLayer resExtBusinessLayer = null;
        Res_Theme_Module resThemeModule = new Res_Theme_Module();
        if (settype == 0) {
            resExtBusinessLayer = resExtBusinessLayerService.selectByPrimaryKey(resourceid);
        }
        String id = "";
        if (contype != null && !contype.equals("")) {
            //数据库存在对应的配置
            if ((settype == 0 && resExtBusinessLayer != null && resExtBusinessLayer.getServiceConfig() != null)) {
                JSONObject obj = JSONObject.parseObject(resExtBusinessLayer.getServiceConfig());
                StringBuilder sb = new StringBuilder();
                //新增常量配置,直接往已有的数据插入数据
                if (contype.equals("vars")) {
//                    Integer i = obj.getJSONArray("vars").size() + 1;
                    JSONArray varsObj = JSONArray.parseArray(obj.getString("vars"));
                    String i = getConfigNum("vars", varsObj); //获取list最大一个名称的数值,避免因删除出现重名
                    sb.append("{");
                    sb.append("\"field\":\"" + serviceConfig.getField() + "\"");
                    sb.append(",\"StatisticalMethod\":\"" + serviceConfig.getFunc() + "\"");
                    sb.append(",\"where\":\"" + serviceConfig.getWhere() + "\"");
                    sb.append(",\"explain\":\"" + serviceConfig.getExplain() + "\"");
                    sb.append(",\"DecimalDigits\":\"" + serviceConfig.getDecimalDigits() + "\"");
                    sb.append(",\"UnitConversion\":\"" + serviceConfig.getUnitConversion() + "\"");
                    sb.append("}");
                    String vars = "{'name':'var" + i + "'," + "'var" + i + "':" + sb.toString() + "}";
                    //往vars插入新增数据
                    String ff = jsonString(vars);
                    varsObj.add(JSONObject.parseObject(ff));
//                    替换
                    obj.replace("vars", varsObj);
                    id = "var" + i;
                } else if (contype.equals("tables")) {
//                    Integer i = obj.getJSONArray("tables").size() + 1;
                    JSONArray tablesObj = JSONArray.parseArray(obj.getString("tables"));
                    String i = getConfigNum("tables", tablesObj);
                    sb.append("{");
                    sb.append("\"groupby\":\"" + serviceConfig.getGroupby() + "\"");
                    sb.append(",\"groupbyalias\":\"" + serviceConfig.getGroupbyalias() + "\"");
                    sb.append(",\"where\":\"" + serviceConfig.getWhere() + "\"");
                    sb.append(",\"explain\":\"" + serviceConfig.getExplain() + "\"");
                    sb.append(",\"DecimalDigits\":\"" + serviceConfig.getDecimalDigits() + "\"");
                    sb.append(",\"UnitConversion\":\"" + serviceConfig.getUnitConversion() + "\"");
                    sb.append(",\"list\":[");
                    sb.append(serviceConfig.getFields());
                    sb.append("]");
                    sb.append("}");
                    String tables = "{'name':'table" + i + "'," + "'table" + i + "':" + sb.toString() + "}";
                    //往vars插入新增数据
                    String ff = jsonString(tables);
                    tablesObj.add(JSONObject.parseObject(ff));
                    //替换
                    obj.replace("tables", tablesObj);
                    id = "table" + i;
                } else if (contype.equals("charts")) {
//                    Integer i = obj.getJSONArray("charts").size() + 1;
                    JSONArray chartsObj = JSONArray.parseArray(obj.getString("charts"));
                    String i = getConfigNum("tables", chartsObj);
                    sb.append("{");
                    sb.append("\"id\":\"" + serviceConfig.getId() + "\"");
                    sb.append(",\"title\":\"" + serviceConfig.getTitle() + "\"");
                    sb.append(",\"type\":\"" + serviceConfig.getType() + "\"");
                    sb.append(",\"displayMode\":\"" + serviceConfig.getDisplaymode() + "\"");
                    sb.append(",\"classField\":\"" + serviceConfig.getClassfield() + "\"");
                    sb.append(",\"ValueField\":\"" + serviceConfig.getValuefield() + "\"");
                    sb.append(",\"StatisticalMethod\":\"" + serviceConfig.getStatisticalmethod() + "\"");
                    sb.append(",\"option\":\"" + serviceConfig.getOption() + "\"");
                    sb.append(",\"where\":\"" + serviceConfig.getWhere() + "\"");
                    sb.append(",\"explain\":\"" + serviceConfig.getExplain() + "\"");
                    sb.append(",\"DecimalDigits\":\"" + serviceConfig.getDecimalDigits() + "\"");
                    sb.append(",\"UnitConversion\":\"" + serviceConfig.getUnitConversion() + "\"");
                    sb.append("}");
                    String charts = "{'name':'chart" + i + "'," + "'chart" + i + "':" + sb.toString() + "}";
                    //往vars插入新增数据
                    String ff = jsonString(charts);
                    chartsObj.add(JSONObject.parseObject(ff));
                    //替换
                    obj.replace("charts", chartsObj);
                    id = "chart" + i;
                }
                resExtBusinessLayer.setServiceConfig(obj.toString());
            } else {
                StringBuilder sb = new StringBuilder();
                sb.append("{");
 
                if (contype.equals("vars")) {
                    sb.append("\"vars\":[{");
                    sb.append("\"name\":\"var1\",");
                    sb.append("\"var1\":{");
                    sb.append("\"field\":\"" + serviceConfig.getField() + "\"");
                    sb.append(",\"StatisticalMethod\":\"" + serviceConfig.getFunc() + "\"");
                    sb.append(",\"where\":\"" + serviceConfig.getWhere() + "\"");
                    sb.append(",\"explain\":\"" + serviceConfig.getExplain() + "\"");
                    sb.append(",\"DecimalDigits\":\"" + serviceConfig.getDecimalDigits() + "\"");
                    sb.append(",\"UnitConversion\":\"" + serviceConfig.getUnitConversion() + "\"");
                    sb.append("}");
                    sb.append("}],");
                    sb.append("\"tables\":[],");
                    sb.append("\"charts\":[]");
                    id = "var1";
                } else if (contype.equals("tables")) {
                    sb.append("\"vars\":[],");
                    sb.append("\"tables\":[{");
                    sb.append("\"name\":\"table1\",");
                    sb.append("\"table1\":{");
                    sb.append("\"groupby\":\"" + serviceConfig.getGroupby() + "\"");
                    sb.append(",\"groupbyalias\":\"" + serviceConfig.getGroupbyalias() + "\"");
                    sb.append(",\"where\":\"" + serviceConfig.getWhere() + "\"");
                    sb.append(",\"explain\":\"" + serviceConfig.getExplain() + "\"");
                    sb.append(",\"DecimalDigits\":\"" + serviceConfig.getDecimalDigits() + "\"");
                    sb.append(",\"UnitConversion\":\"" + serviceConfig.getUnitConversion() + "\"");
                    sb.append(",\"list\":[");
                    sb.append(serviceConfig.getFields());
                    sb.append("]");
                    sb.append("}");
                    sb.append("}],");
                    sb.append("\"charts\":[]");
                    id = "table1";
                } else if (contype.equals("charts")) {
                    sb.append("\"vars\":[],");
                    sb.append("\"tables\":[],");
                    sb.append("\"charts\":[{");
                    sb.append("\"name\":\"chart1\",");
                    sb.append("\"chart1\":{");
                    sb.append("\"id\":\"" + serviceConfig.getId() + "\"");
                    sb.append(",\"title\":\"" + serviceConfig.getTitle() + "\"");
                    sb.append(",\"type\":\"" + serviceConfig.getType() + "\"");
                    sb.append(",\"displayMode\":\"" + serviceConfig.getDisplaymode() + "\"");
                    sb.append(",\"classField\":\"" + serviceConfig.getClassfield() + "\"");
                    sb.append(",\"ValueField\":\"" + serviceConfig.getValuefield() + "\"");
                    sb.append(",\"StatisticalMethod\":\"" + serviceConfig.getStatisticalmethod() + "\"");
                    sb.append(",\"option\":\"" + serviceConfig.getOption() + "\"");
                    sb.append(",\"where\":\"" + serviceConfig.getWhere() + "\"");
                    sb.append(",\"explain\":\"" + serviceConfig.getExplain() + "\"");
                    sb.append(",\"DecimalDigits\":\"" + serviceConfig.getDecimalDigits() + "\"");
                    sb.append(",\"UnitConversion\":\"" + serviceConfig.getUnitConversion() + "\"");
                    sb.append("}");
                    sb.append("}]");
                    id = "chart1";
                }
 
                sb.append("}");
                String ff = jsonString(sb.toString());
                if (settype == 0) {
                    resExtBusinessLayer.setServiceConfig(ff);
                } else {
                    resThemeModule.setServiceconfig(ff);
                }
            }
        }
        if (settype == 0) {
            int count = resExtBusinessLayerService.updateByPrimaryKeySelective(resExtBusinessLayer);
            if (count > 0) {
                return "{'success':'success','id':'" + id + "'}";
            } else {
                return "{'success':'erro'}";
            }
        } else {
            return "{'success':'success','charttitle':'" + (contype.equals("tables") ? serviceConfig.getGroupbyalias() : serviceConfig.getTitle()) + "','serviceconfig':" + (resThemeModule.getServiceconfig() != null ? resThemeModule.getServiceconfig() : "") + "}";
        }
    }
 
    /**
     * 编辑配置信息
     *
     * @param name          需要修改的变量 如:var1,table1
     * @param resourceid    资源ID
     * @param serviceConfig 相关配置字段信息
     * @param serviceHTML   编辑器HTML内容
     * @return
     */
    @RequestMapping("editserviceconfig")
    @ResponseBody
    public String editServiceConfig(String name, Integer resourceid, ServiceConfig serviceConfig, String serviceHTML,Integer moduleid,Integer settype) {
        Res_ExtBusinessLayer resExtBusinessLayer = null;
        Res_Theme_Module resThemeModule = null;
        if (moduleid == 0) {
            resExtBusinessLayer = resExtBusinessLayerService.selectByPrimaryKey(resourceid);
        } else {
            resThemeModule = resThemeModuleService.selectByid(moduleid);
        }
        String key = "";
        if (name != null && !name.equals("")) {
            if (name.substring(0, 1).equals("v")) {
                key = "vars";
            }
            if (name.substring(0, 1).equals("t")) {
                key = "tables";
            }
            if (name.substring(0, 1).equals("c")) {
                key = "charts";
            }
            StringBuilder sb = new StringBuilder();
 
            if ((settype == 0 && resExtBusinessLayer != null && resExtBusinessLayer.getServiceConfig() != null) || (settype == 1 &&resThemeModule != null && resThemeModule.getServiceconfig() != null && !resThemeModule.getServiceconfig().trim().equals(""))) {
                JSONObject obj = JSONObject.parseObject(settype == 0 ? resExtBusinessLayer.getServiceConfig() : resThemeModule.getServiceconfig());
                boolean flag = false;
                if (obj.getJSONArray(key) != null) {
                    JSONArray jsonArray = obj.getJSONArray(key);
                    if (jsonArray != null) {
                        for (int j = 0; j < jsonArray.size(); j++) {
                            org.json.JSONObject jsonObject = new org.json.JSONObject(jsonArray.getJSONObject(j));
                            Iterator iterator = jsonObject.keys();
                            while (iterator.hasNext()) {
                                String skey = (String) iterator.next();
                                if (skey.equals(name)) {
                                    //找到编辑的项则替换掉旧的
                                    if (key.equals("vars")) {
                                        sb.append("{");
                                        sb.append("\"field\":\"" + serviceConfig.getField() + "\"");
                                        sb.append(",\"StatisticalMethod\":\"" + serviceConfig.getFunc() + "\"");
                                        sb.append(",\"where\":\"" + serviceConfig.getWhere() + "\"");
                                        sb.append(",\"explain\":\"" + serviceConfig.getExplain() + "\"");
                                        sb.append(",\"DecimalDigits\":\"" + serviceConfig.getDecimalDigits() + "\"");
                                        sb.append(",\"UnitConversion\":\"" + serviceConfig.getUnitConversion() + "\"");
                                        sb.append("}");
                                    } else if (key.equals("tables")) {
                                        sb.append("{");
                                        sb.append("\"groupby\":\"" + serviceConfig.getGroupby() + "\"");
                                        sb.append(",\"groupbyalias\":\"" + serviceConfig.getGroupbyalias() + "\"");
                                        sb.append(",\"where\":\"" + serviceConfig.getWhere() + "\"");
                                        sb.append(",\"explain\":\"" + serviceConfig.getExplain() + "\"");
                                        sb.append(",\"DecimalDigits\":\"" + serviceConfig.getDecimalDigits() + "\"");
                                        sb.append(",\"UnitConversion\":\"" + serviceConfig.getUnitConversion() + "\"");
                                        sb.append(",\"list\":[");
                                        sb.append(serviceConfig.getFields());
                                        sb.append("]");
                                        sb.append("}");
                                    } else if (key.equals("charts")) {
                                        sb.append("{");
                                        sb.append("\"id\":\"" + serviceConfig.getId() + "\"");
                                        sb.append(",\"title\":\"" + serviceConfig.getTitle() + "\"");
                                        sb.append(",\"type\":\"" + serviceConfig.getType() + "\"");
                                        sb.append(",\"displayMode\":\"" + serviceConfig.getDisplaymode() + "\"");
                                        sb.append(",\"classField\":\"" + serviceConfig.getClassfield() + "\"");
                                        sb.append(",\"ValueField\":\"" + serviceConfig.getValuefield() + "\"");
                                        sb.append(",\"StatisticalMethod\":\"" + serviceConfig.getStatisticalmethod() + "\"");
                                        sb.append(",\"option\":\"" + serviceConfig.getOption() + "\"");
                                        sb.append(",\"where\":\"" + serviceConfig.getWhere() + "\"");
                                        sb.append(",\"explain\":\"" + serviceConfig.getExplain() + "\"");
                                        sb.append(",\"DecimalDigits\":\"" + serviceConfig.getDecimalDigits() + "\"");
                                        sb.append(",\"UnitConversion\":\"" + serviceConfig.getUnitConversion() + "\"");
                                        sb.append("}");
                                    }
                                    String ff = jsonString(sb.toString());
                                    jsonArray.getJSONObject(j).replace(name, JSONObject.parseObject(ff));
                                    flag = true;
                                    break;
                                }
                            }
                            if (flag) break;
                        }
                    }
                }
                if (settype == 0) {
                    resExtBusinessLayer.setServiceConfig(obj.toString());
                } else {
                    resThemeModule.setServiceconfig(obj.toString());
                }
            }
        }
//        String replaceHTML = replaceServiceHTML(serviceHTML, resourceid, "charToHTML");
//        resExtBusinessLayer.setServiceHTML(replaceHTML);
        if (settype == 0) {
            int count = resExtBusinessLayerService.updateByPrimaryKeySelective(resExtBusinessLayer);
            if (count > 0) {
                return "{'success':'success'}";
            }
            return "{'success':'erro'}";
        } else {
            return "{'success':'success','charttitle':'" + (key.equals("tables") ? serviceConfig.getGroupbyalias() : serviceConfig.getTitle()) + "','serviceconfig':" + (resThemeModule.getServiceconfig() != null ? resThemeModule.getServiceconfig() :"") + "}";
        }
    }
 
    @RequestMapping("saveHtmlConfig")
    @ResponseBody
    public String saveHtmlConfig(String serviceHTML,Integer resourceid) {
        Res_ExtBusinessLayer resExtBusinessLayer = resExtBusinessLayerService.selectByPrimaryKey(resourceid);
        if(resExtBusinessLayer != null) {
            String replaceHTML = replaceServiceHTML(serviceHTML, resourceid, "charToHTML");
            resExtBusinessLayer.setServiceHTML(replaceHTML);
            resExtBusinessLayer.setCache("");
            int count = resExtBusinessLayerService.updateByPrimaryKeySelective(resExtBusinessLayer);
            if (count > 0) {
                return "success";
            }
            else {
                return "error";
            }
        }
        else {
            return "error";
        }
    }
 
    @ResponseBody
    @RequestMapping("matchKeyNotInHTML")
    public String matchKeyNotInHTML(String serviceHTML,Integer resourceid) {
        Res_ExtBusinessLayer resExtBusinessLayer = resExtBusinessLayerService.selectByPrimaryKey(resourceid);
        String notkey = "";
        if (resExtBusinessLayer.getServiceConfig() != null && !resExtBusinessLayer.getServiceConfig().equals("")) {
            JSONObject obj = JSONObject.parseObject(resExtBusinessLayer.getServiceConfig());
            for (int i = 0; i < obj.size(); i++) {
                JSONArray object = null;
                //每次只取一个类
                if (i == 0) {
                    if (obj.getJSONArray("vars") != null) {
                        object = obj.getJSONArray("vars");
                    }
                }
                if (i == 1) {
                    if (obj.getJSONArray("tables") != null) {
                        object = obj.getJSONArray("tables");
                    }
                }
                if (i == 2) {
                    if (obj.getJSONArray("charts") != null) {
                        object = obj.getJSONArray("charts");
                    }
                }
                if (object != null) {
                    for (int j = 0; j < object.size(); j++) {
                        String key = object.getJSONObject(j).getString("name");
                        Pattern p = Pattern.compile(key);
                        Matcher m = p.matcher(serviceHTML);
                        boolean flag = false;
                        if(m.find()) {
                            flag = true;
                            if(flag) continue;
                        }
                        if (!flag) {
                            if(notkey != "") notkey += ",";
                            String keyString = "{" + key + "}";
                            notkey += keyString;
                        }
                    }
                }
            }
        }
        return notkey;
    }
 
 
    /**
     * 删除配置信息
     */
    @RequestMapping("delserviceconfig")
    @ResponseBody
    public String delServiceConfig(String name, Integer resourceid) {
        String key = "";
        String type = "";
        //判断是属于哪一项,获取对应的json
        if (name.substring(0, 1).equals("v")) {
            key = "vars";
            type = "var";
        }
        if (name.substring(0, 1).equals("t")) {
            key = "tables";
            type = "table";
        }
        if (name.substring(0, 1).equals("c")) {
            key = "charts";
            type = "chart";
        }
        Res_ExtBusinessLayer resExtBusinessLayer = resExtBusinessLayerService.selectByPrimaryKey(resourceid);
        if (resExtBusinessLayer.getServiceConfig() != null) {
            JSONObject obj = JSONObject.parseObject(resExtBusinessLayer.getServiceConfig());
            boolean flag = false;
            if (obj.getJSONArray(key) != null) {
                //获取所要删除的项所在的json数组
                JSONArray jsonArray = obj.getJSONArray(key);
                if (jsonArray != null) {
                    //遍历数组,如果name一致则直接删除,退出循环
                    for (int j = 0; j < jsonArray.size(); j++) {
                        org.json.JSONObject jsonObject = new org.json.JSONObject(jsonArray.getJSONObject(j));
                        Iterator iterator = jsonObject.keys();
                        while (iterator.hasNext()) {
                            String skey = (String) iterator.next();
                            if (skey.equals(name)) {
                                //找到删除该项
                                jsonArray.remove(j);
                                flag = true;
                                break;
                            }
                        }
                        if (flag) break;
                    }
                }
//                jsonArray = newSortJson(jsonArray, type);
            }
            resExtBusinessLayer.setServiceConfig(obj.toString());
            int count = resExtBusinessLayerService.updateByPrimaryKeySelective(resExtBusinessLayer);
            if (count > 0) {
                return "success";
            }
        }
        return "error";
    }
 
    /**
     * 获取配置的变量键,用来命名变量值 如:var + 返回值
     *
     * @param type      类别
     * @param jsonArray json数组
     * @return
     */
    public String getConfigNum(String type, JSONArray jsonArray) {
        String i = "";
        if (jsonArray != null && jsonArray.size() > 0) {
            int max = 1;
            for (int j = 0; j < jsonArray.size(); j++) {
                String key = jsonArray.getJSONObject(j).getString("name");
                if (type.equals("vars")) {
                    int t = Integer.parseInt(key.substring(3, key.length())) + 1;
                    if (max < t) {
                        max = t;
                    }
                } else if (type.equals("tables") || type.equals("charts")) {
                    int t = Integer.parseInt(key.substring(5, key.length())) + 1;
                    if (max < t) {
                        max = t;
                    }
                }
            }
            i = String.valueOf(max);
        } else {
            i = "1";
        }
        return i;
    }
 
    //替换占位符
    public String replaceServiceHTML(String serviceHTML, Integer resourceid, String type) {
        //获取list
        Res_ExtBusinessLayer resExtBusinessLayer = resExtBusinessLayerService.selectByPrimaryKey(resourceid);
        if (resExtBusinessLayer.getServiceConfig() != null && !resExtBusinessLayer.getServiceConfig().equals("")) {
            JSONObject obj = JSONObject.parseObject(resExtBusinessLayer.getServiceConfig());
            for (int i = 0; i < obj.size(); i++) {
                JSONArray object = null;
                String replaceString = "";
                String contype = "";
                //每次只取一个类
                if (i == 0) {
                    if (obj.getJSONArray("vars") != null) {
                        object = obj.getJSONArray("vars");
                        contype = "vars";
                    }
                }
                if (i == 1) {
                    if (obj.getJSONArray("tables") != null) {
                        object = obj.getJSONArray("tables");
                        contype = "tables";
                    }
                }
                if (i == 2) {
                    if (obj.getJSONArray("charts") != null) {
                        object = obj.getJSONArray("charts");
                        contype = "charts";
                    }
                }
                if (object != null) {
                    for (int j = 0; j < object.size(); j++) {
                        org.json.JSONObject jsonObject = new org.json.JSONObject(object.getJSONObject(j));
                        Iterator iterator = jsonObject.keys();
                        while (iterator.hasNext()) {
                            if (contype.equals("vars")) {
                                replaceString = "<span id='var'></span>";
                            } else if (contype.equals("tables")) {
                                replaceString = "<div id='var' class='radius'></div>";
                            } else if (contype.equals("charts")) {
                                replaceString = "<div id='var' class='radius top-border chart'></div>";
                            }
                            String key = (String) iterator.next();
                            replaceString = replaceString.replace("var", key);
                            String keyString = '{' + key + '}';
                            if (type.equals("charToHTML")) {
                                serviceHTML = serviceHTML.replace(keyString, replaceString);
                            }
                            if (type.equals("htmlToChar")) {
                                serviceHTML = serviceHTML.replace(replaceString, keyString);
                            }
                        }
 
                    }
                }
            }
        }
        return serviceHTML;
    }
 
    //删除 后重新组合排序(暂不使用重新排序)
    public JSONArray newSortJson(JSONArray jsonArray, String type) {
        JSONArray array = new JSONArray();
        for (int i = 0; i < jsonArray.size(); i++) {
            //循环获取第i个值,重新拼接
            JSONObject jsonObject = JSONObject.parseObject(jsonArray.getString(i));
            StringBuilder sb = new StringBuilder();
            org.json.JSONObject obj = new org.json.JSONObject(jsonArray.getJSONObject(i));
            Iterator iterator = obj.keys();
            while (iterator.hasNext()) {
                String skey = (String) iterator.next();
                JSONObject object = JSONObject.parseObject(jsonObject.getString(skey));
                sb.append("{");
                Integer nameNum = i + 1;
                sb.append("'name':'" + type + nameNum + "',");
                sb.append("'" + type + nameNum + "':");
                sb.append(jsonObject.getString(skey));
            }
            sb.append("}");
            System.out.println(sb.toString());
            array.add(JSONObject.parseObject(sb.toString()));
        }
        return array;
    }
 
    //切换图表样式时获取对应样式的echarts默认模板代码
    @ResponseBody
    @RequestMapping("getEchartsCode")
    public String getEchartsCode(Integer echartsid, String jsonname, Integer resourceid,Integer settype,Integer moduleid) {
        //编辑配置相关信息
        String key = "";
        String code = "";
        if (jsonname != null && !jsonname.equals("") && resourceid != null) {
            Res_ExtBusinessLayer resExtBusinessLayer = null;
            Res_Theme_Module resThemeModule = null;
            if(settype == 0 ){
                resExtBusinessLayer = resExtBusinessLayerService.selectByPrimaryKey(resourceid);
            }else{
                resThemeModule = resThemeModuleService.selectByid(moduleid);
            }
            //判断是属于哪一项,获取对应的json
            if (jsonname.substring(0, 1).equals("v")) {
                key = "vars";
            }
            if (jsonname.substring(0, 1).equals("t")) {
                key = "tables";
            }
            if (jsonname.substring(0, 1).equals("c")) {
                key = "charts";
            }
            if ((settype == 0&&resExtBusinessLayer.getServiceConfig() != null && key.equals("charts"))||
                    (settype != 0 &&resThemeModule.getServiceconfig() != null && key.equals("charts"))) {
                JSONObject obj = JSONObject.parseObject(settype==0?resExtBusinessLayer.getServiceConfig():resThemeModule.getServiceconfig());
                JSONObject newobj = null;
                boolean flag = false;
                if (obj.getJSONArray(key) != null) {
                    //获取所要获取的项所在的json数组
                    JSONArray jsonArray = obj.getJSONArray(key);
                    if (jsonArray != null) {
                        //遍历数组,如果key一致则取出相关配置信息,退出循环
                        for (int j = 0; j < jsonArray.size(); j++) {
                            org.json.JSONObject jsonObject = new org.json.JSONObject(jsonArray.getJSONObject(j));
                            Iterator iterator = jsonObject.keys();
                            while (iterator.hasNext()) {
                                String skey = (String) iterator.next();
                                if (skey.equals(jsonname)) {
                                    //如果切换的类型与数据库存的类型一致则取配置过的echarta代码
                                    if (echartsid.equals(jsonArray.getJSONObject(j).getJSONObject(jsonname).getString("id"))) {
                                        code = jsonArray.getJSONObject(j).getJSONObject(jsonname).getString("option");
                                    } else {
                                        Res_EchartsConfing resEchartsCofing = resEchartsCofingService.selectByPrimaryKey(echartsid);
                                        if (resEchartsCofing != null) {
                                            code = resEchartsCofing.getEchartsoption();
                                        }
                                    }
                                    flag = true;
                                    break;
                                }
                                else continue;
                            }
                            if (flag) break;
                        }
                    }
                }
            }
        } else {
            Res_EchartsConfing resEchartsCofing = resEchartsCofingService.selectByPrimaryKey(echartsid);
            if (resEchartsCofing != null) {
                code = resEchartsCofing.getEchartsoption();
            }
        }
        return code;
    }
 
    //把json化的字符串的键值中的英文双引号转化为单引号,避免因用户输入的英文双引号导致无法json化字符串
    private static String jsonString(String s){
        char[] temp = s.toCharArray();
        int n = temp.length;
        for(int i =0;i<n;i++){
            if(temp[i]==':'&&temp[i+1]=='"'){
                for(int j =i+2;j<n;j++){
                    if(temp[j]=='"'){
                        if(temp[j+1]!=',' &&  temp[j+1]!='}'){
                            temp[j]='\'';
                        }else if(temp[j+1]==',' ||  temp[j+1]=='}'){
                            break ;
                        }
                    }
                }
            }
        }
        return new String(temp);
    }
 
    //选择图形
    @RequestMapping("/SelectOfChart")
    public String SelectOfChart( Model model,Integer settype){
        model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
        model.addAttribute("settype",settype);
        return "common/SelectOfChart";
    }
    /**
     * 文件上传
     */
    @ResponseBody
    @RequestMapping("/uploadfile")
    public String uploadfile(@RequestParam("my" +
            "File") MultipartFile file) {
        File desFile = null;
        if (file.isEmpty()) {
            return "No File";
        }
        String uuid = UUID.randomUUID().toString().replaceAll("-", "");
        String name = file.getOriginalFilename();
        String fileType = name.substring(name.lastIndexOf("."));
        String Filename = uuid + fileType;
        String size = org.apache.commons.io.FileUtils.byteCountToDisplaySize(file.getSize());
 
        String webpath="";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        String timePath = sdf.format(new Date().getTime());
        timePath = timePath.replace("-", "");
        Filename = uuid + fileType;
        String path = null;
        path = sysConfig.getUploadPath() + "ECharts\\"+timePath + "\\";
        File filePath = new File(path); // 创建对应的年月文件夹
        if (!filePath.exists()) {
            filePath.mkdirs();
        }
        //文件网络地址
        webpath ="ECharts/"+ timePath + "/" + Filename; // 类型为文件指向文件
        desFile = new File(path + Filename);
        String info = desFile.getAbsolutePath();
        System.out.println("info:" + info);
        System.out.println("info:" + webpath);
        try {
            org.apache.commons.io.FileUtils.copyInputStreamToFile(file.getInputStream(), desFile);
            return "{'result':'1','Path':'"+webpath+"','Filename':'"+name.substring(name.lastIndexOf("\\")+1,name.lastIndexOf("."))+"','size':'"+size.substring(0,size.lastIndexOf(" "))+"','unit':'"+size.substring(size.lastIndexOf(" ")+1,size.length())+"','FileType':'"+fileType+"'}";
        } catch (IOException e) {
            e.printStackTrace();
            return "{'result':'0'}";
        }
    }
 
    /**
     * @Author: lizhao
     * @Date: 2018-09-29 9:44
     * @param null
     * @Description:根据type查询,对应的类型
     *
     */
    @ResponseBody
    @RequestMapping("/SelectEchartsType")
    public String SelectEchartsType(Res_EchartsConfing echartsConfing){
        Res_EchartsConfing res_echartsConfing=resEchartsCofingService.selectEchartsType(echartsConfing);
        return res_echartsConfing.getEchartstype();
    }
 
 
    /**
     * 门户用户信息栏页面
     * @param model
     * @return
     */
    @RequestMapping("liferay/userinfo")
    public String userinfo(Model model) {
        model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
        model.addAttribute("loginname", getUser().getChinesename());
        model.addAttribute("lanbaseRoot", sysConfig.getApiServer());
        return "liferay_userinfo";
    }
 
 
    /**
     * 根据单位名称获取首字母值
     */
    @SysLog("根据名称获取首字母值")
    @GetMapping("/changeToPinYin")
    @ResponseBody
    @ApiOperation(
            value = "根据单位获取首字母值",
            notes = ""
    )
    public Result changeToPinYin(@ApiParam(name="pinyin",value="字段pinyin",required=true)@RequestParam String name){
        name = name.replaceAll("%(?![0-9a-fA-F]{2})", "%25");
        String namepinyin = JpinyinUtils.changeToGetShortPinYin(URLDecoder.decode(name));
        //首字母小写转化大写
        String pinyin = namepinyin.toUpperCase();
        String patt="[^a-z|A-Z]";
        pinyin = pinyin.replaceAll(patt,"");
        return Result.ok().put("pinyin", URLEncoder.encode(pinyin));
    }
 
}