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
package com.landtool.lanbase.modules.res.controller;
 
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
 
import javax.servlet.http.HttpServletRequest;
 
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.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
 
import com.alibaba.fastjson.JSONObject;
import com.landtool.lanbase.common.annotation.LogAction;
import com.landtool.lanbase.common.utils.DateUtils;
import com.landtool.lanbase.common.utils.HttpOperateUtils;
import com.landtool.lanbase.common.utils.JpinyinUtils;
import com.landtool.lanbase.config.SysTemPropertyConfig;
import com.landtool.lanbase.modules.api.utils.DeleteFileUtils;
import com.landtool.lanbase.modules.org.entity.OrgUnit;
import com.landtool.lanbase.modules.org.service.OrgUnitService;
import com.landtool.lanbase.modules.org.service.OrgUserService;
import com.landtool.lanbase.modules.res.entity.Res_Catalog;
import com.landtool.lanbase.modules.res.entity.Res_Ext3D;
import com.landtool.lanbase.modules.res.entity.Res_ExtBaseMap;
import com.landtool.lanbase.modules.res.entity.Res_ExtBusinessLayer;
import com.landtool.lanbase.modules.res.entity.Res_ExtDataBase;
import com.landtool.lanbase.modules.res.entity.Res_ExtDataSource;
import com.landtool.lanbase.modules.res.entity.Res_ExtFileSource;
import com.landtool.lanbase.modules.res.entity.Res_ExtIntegrate;
import com.landtool.lanbase.modules.res.entity.Res_ExtInterFaceService;
import com.landtool.lanbase.modules.res.entity.Res_ExtMapUrl;
import com.landtool.lanbase.modules.res.entity.Res_ExtSpaceServerWithBLOBs;
import com.landtool.lanbase.modules.res.entity.Res_ExtThemeMap;
import com.landtool.lanbase.modules.res.entity.Res_FileSource_Way;
import com.landtool.lanbase.modules.res.entity.Res_Files;
import com.landtool.lanbase.modules.res.entity.Res_MainInfo;
import com.landtool.lanbase.modules.res.entity.Res_SpacesParam;
import com.landtool.lanbase.modules.res.entity.UserDefined.MainInfoJoinRegister;
import com.landtool.lanbase.modules.res.service.ResCatalogService;
import com.landtool.lanbase.modules.res.service.ResExt3DService;
import com.landtool.lanbase.modules.res.service.ResExtBaseMapService;
import com.landtool.lanbase.modules.res.service.ResExtBusinessLayerService;
import com.landtool.lanbase.modules.res.service.ResExtDataBaseService;
import com.landtool.lanbase.modules.res.service.ResExtDataSourceService;
import com.landtool.lanbase.modules.res.service.ResExtFileSourceService;
import com.landtool.lanbase.modules.res.service.ResExtIntegrateService;
import com.landtool.lanbase.modules.res.service.ResExtInterFaceService;
import com.landtool.lanbase.modules.res.service.ResExtMapUrlService;
import com.landtool.lanbase.modules.res.service.ResExtSpaceServerService;
import com.landtool.lanbase.modules.res.service.ResExtThemeMapService;
import com.landtool.lanbase.modules.res.service.ResFileSourceWayService;
import com.landtool.lanbase.modules.res.service.ResFilesService;
import com.landtool.lanbase.modules.res.service.ResMainInfoService;
import com.landtool.lanbase.modules.res.service.ResSpacesParamService;
import com.landtool.lanbase.modules.sys.controller.AbstractController;
import com.landtool.lanbase.modules.sys.service.SysFieldvalueService;
 
/**
 * 功能描述:资源管理 - 资源注册
 */
@Controller
@RequestMapping("/res/ResManage/NewResRegister")
public class NewResRegisterController extends AbstractController {
    @Autowired
    private SysTemPropertyConfig sysConfig;
    @Autowired
    private ResMainInfoService resMainInfoService;
    @Autowired
    private ResExtDataBaseService resExtDataBaseService;
    @Autowired
    private ResExtDataSourceService resExtDataSourceService;
    @Autowired
    private ResExtInterFaceService resExtInterFaceService;
    @Autowired
    private ResExtFileSourceService resExtFileSourceService;
    @Autowired
    private ResExtIntegrateService resExtIntegrateService;
    @Autowired
    private ResExtBaseMapService resExtBaseMapService;
    @Autowired
    private ResExtMapUrlService resExtMapUrlService;
    @Autowired
    private ResExtThemeMapService resExtThemeMapService;
    @Autowired
    private ResExtSpaceServerService resExtSpaceServerService;
    @Autowired
    private ResExt3DService resExt3DService;
    @Autowired
    private ResExtBusinessLayerService resExtBusinessLayerService;
    @Autowired
    private ResFilesService resFilesService;
    @Autowired
    private ResFileSourceWayService resFileSourceWayService;
    
    @Autowired
    private ResCatalogService resCatalogService;
    
    @Autowired
    private OrgUserService orgUserService;
    
    @Autowired
    private OrgUnitService orgUnitService;
    
    @Autowired
    private SysFieldvalueService FieldUtils;
    
    @Autowired
    private ResSpacesParamService resSpacesParamService;
    
    /**
     * 数据库表资源拓展页面
     */
    @RequestMapping("/ExtDataBase")
    public String ExtDataBase(Model model) {
        model.addAttribute("backstageWebRoot", sysConfig.getApiServer() + "/");
        model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
        return "ResManage/NewResRegister/ExtDataBase";
    }
    
    /**
     * 接口服务资源拓展页面
     */
    @RequestMapping("/ExtInterFaceService")
    public String ExtInterFaceService(Integer resMainInfoId, Model model) {
        Res_ExtInterFaceService res_extInterFaceService;
        if (resMainInfoId != null) {
            res_extInterFaceService = resExtInterFaceService.selectByPrimaryKey(resMainInfoId);//获取接口服务拓展信息
            if (res_extInterFaceService != null) {
                model.addAttribute("Res_ExtInterFaceService", res_extInterFaceService);
                Res_MainInfo res_mainInfo = resMainInfoService.selectByPrimaryKey(resMainInfoId);
                model.addAttribute("resMainInfo", res_mainInfo);
            } else {
                res_extInterFaceService = new Res_ExtInterFaceService();
                model.addAttribute("Res_ExtInterFaceService", res_extInterFaceService);
                model.addAttribute("resMainInfo", new Res_MainInfo());
            }
        } else {
            res_extInterFaceService = new Res_ExtInterFaceService();
            model.addAttribute("Res_ExtInterFaceService", res_extInterFaceService);
            model.addAttribute("resMainInfo", new Res_MainInfo());
        }
        model.addAttribute("resMainInfoId", resMainInfoId);
        model.addAttribute("content", res_extInterFaceService.getHelpurl());
        
        if (SecurityUtils.getSubject().isPermitted("org_user_admin")) {
            //判断当前用户是否是管理员,是管理员或是未提交的资源才可以修改资源相关信息
            model.addAttribute("admin", true);
        } else {
            model.addAttribute("admin", false);
        }
        model.addAttribute("esbWebServiceHost", sysConfig.getEsbWebServiceHost());
        model.addAttribute("esbHost", sysConfig.getEsbHost());
        model.addAttribute("esbUrl", sysConfig.getEsbUrl());
        
        return "ResManage/NewResRegister/ExtInterFaceService";
    }
    
    /**
     * 数据文件资源拓展页面
     */
    @RequestMapping("/ExtFileSource")
    public String ExtFileSource(Model model) {
        String unit = "";
        model.addAttribute("unitConvert", "5");
        unit = "KB";
        Res_ExtFileSource resExtFileSource1 = new Res_ExtFileSource();
        model.addAttribute("Res_ExtFileSource", resExtFileSource1);
        model.addAttribute("resMainInfo", new Res_MainInfo());
        
        model.addAttribute("unit", unit);
        // 获取文档类型列表
        LinkedHashMap<String, String> filetypelist = FieldUtils.getFieldListByKey("FileType");
        model.addAttribute("filetypelist", filetypelist);
        
        if (SecurityUtils.getSubject().isPermitted("org_user_admin")) {
            //判断当前用户是否是管理员,是管理员或是未提交的资源才可以修改资源相关信息
            model.addAttribute("admin", true);
        } else {
            model.addAttribute("admin", false);
        }
        model.addAttribute("ncSyncStorageUrl", sysConfig.getNcStorageUrl().substring(0, sysConfig.getNcStorageUrl().length() - 9) + "jobs/");
        model.addAttribute("readNcFileURL", sysConfig.getReadNcFileURL());
        
        return "ResManage/NewResRegister/ExtFileSource";
    }
    
    /**
     * 数据文件下的 展现方式
     */
    @RequestMapping("/ExtPresentationMode")
    public String ExtPresentationMode(Integer resMainInfoId, Model model) {
        model.addAttribute("resMainInfoId", resMainInfoId);
        List<Res_FileSource_Way> list = null;
        if (resMainInfoId != null) {
            resFileSourceWayService.selectById(resMainInfoId);
        }
        model.addAttribute("FileSourceWay", list);
        return "ResManage/NewResRegister/ExtPresentationMode";
    }
    
    /**
     * 业务集成资源拓展页面
     */
    @RequestMapping("/ExtIntegrate")
    public String ExtIntegrate(Model model) {
        Integer isSetChart = 0;//是否显示模型设置按钮(0不显示1显示)
        String serverUrl = "";
        String resolutionBen = "";
        String resolutionEnd = "";
        Res_ExtIntegrate resExtIntegrate1 = new Res_ExtIntegrate();
        model.addAttribute("Res_ExtIntegrate", resExtIntegrate1);
        model.addAttribute("resMainInfo", new Res_MainInfo());
        model.addAttribute("isSetChart", isSetChart);
        model.addAttribute("serverUrl", serverUrl);
        model.addAttribute("resolutionBen", resolutionBen);
        model.addAttribute("resolutionEnd", resolutionEnd);
        
        if (SecurityUtils.getSubject().isPermitted("org_user_admin")) {
            //判断当前用户是否是管理员,是管理员或是未提交的资源才可以修改资源相关信息
            model.addAttribute("admin", true);
        } else {
            model.addAttribute("admin", false);
        }
        
        return "ResManage/NewResRegister/ExtIntegrate";
    }
    
    /**
     * 基础底图资源拓展页面
     */
    @RequestMapping("/ExtBaseMap")
    public String ExtBaseMap(Integer resMainInfoId, Model model) {
        Res_ExtMapUrl resExtMapUrl = new Res_ExtMapUrl();
        Res_ExtBaseMap resExtBaseMap;
        
        LinkedHashMap<String, String> typeandurlList = FieldUtils.getFieldListByKey("TypeAndURL");//获取地理参考模型列表
        model.addAttribute("typeandurlList", typeandurlList);
        String typeandurlListJson = "";
        for (Map.Entry<String, String> entry : typeandurlList.entrySet()) {
            if (typeandurlListJson != "") typeandurlListJson += ",";
            typeandurlListJson += "{key:'" + entry.getKey() + "',value:'" + entry.getValue() + "'}";
        }
        model.addAttribute("typeandurlListJson", "[" + typeandurlListJson + "]");
        if (resMainInfoId != null) {
            List<Res_ExtMapUrl> resExtMapUrlList = resExtMapUrlService.selectByCondition(resMainInfoId);
            if (resExtMapUrlList.size() > 0) {
                resExtMapUrl = resExtMapUrlList.get(0);
            }
            resExtBaseMap = resExtBaseMapService.selectByPrimaryKey(resMainInfoId);
            if (resExtBaseMap != null) {
                if (resExtBaseMap.getRefmarkinfid() != null) {
                    Res_MainInfo title = resMainInfoService.selectByPrimaryKey(resExtBaseMap.getRefmarkinfid());
                    if (title != null) {
                        model.addAttribute("refmarkinfname", title.getTitle());
                    }
                }
                Res_MainInfo res_mainInfo = resMainInfoService.selectByPrimaryKey(resMainInfoId);
                model.addAttribute("resMainInfo", res_mainInfo);
                
                String[] arr = new String[2];
                arr[0] = "null";
                arr[1] = "null";
                if (resExtBaseMap.getDisplaylev() != null) {
                    arr = resExtBaseMap.getDisplaylev().split("-");
                }
                model.addAttribute("xianshibiliStart", (arr[0] == null || arr[0].trim().equals("null")) ? "" : arr[0]);
                model.addAttribute("xianshibiliEnd", (arr[1] == null || arr[1].trim().equals("null")) ? "" : arr[1]);
                model.addAttribute("resExtBaseMap", resExtBaseMap);
                model.addAttribute("resMainInfoId", resMainInfoId);
            } else {
                resExtBaseMap = new Res_ExtBaseMap();
                Res_MainInfo res_mainInfo = new Res_MainInfo();
                model.addAttribute("resMainInfo", res_mainInfo);
                model.addAttribute("resExtBaseMap", resExtBaseMap);
                model.addAttribute("xianshibiliStart", "");
                model.addAttribute("xianshibiliEnd", "");
            }
        } else {
            resExtBaseMap = new Res_ExtBaseMap();
            Res_MainInfo res_mainInfo = new Res_MainInfo();
            model.addAttribute("resMainInfo", res_mainInfo);
            model.addAttribute("resExtBaseMap", resExtBaseMap);
            model.addAttribute("xianshibiliStart", "");
            model.addAttribute("xianshibiliEnd", "");
        }
        
        model.addAttribute("resExtMapUrl", resExtMapUrl);
        LinkedHashMap<String, String> PublishSoftList = FieldUtils.getFieldListByKey("PublishSoft");// 获取发布平台字典列表
        LinkedHashMap<String, String> BaseMapTypeList = FieldUtils.getFieldListByKey("BaseMapType");// 获取底图类型字典列表
        LinkedHashMap<String, String> ImageAccuracyList = FieldUtils.getFieldListByKey("ImageAccuracy");// 获取影像精度字典列表
        model.addAttribute("PublishSoftList", PublishSoftList);
        model.addAttribute("BaseMapTypeList", BaseMapTypeList);
        model.addAttribute("ImageAccuracyList", ImageAccuracyList);
        model.addAttribute("esbHost", sysConfig.getEsbHost());
        model.addAttribute("esbUrl", sysConfig.getEsbUrl());
        if (SecurityUtils.getSubject().isPermitted("org_user_admin")) {
            //判断当前用户是否是管理员,是管理员或是未提交的资源才可以修改资源相关信息
            model.addAttribute("admin", true);
        } else {
            model.addAttribute("admin", false);
        }
        String oldesbids = resExtBaseMap != null ? resExtMapUrlService.queryRsbidsByResourceid(resMainInfoId) : "";
        model.addAttribute("oldesbids", oldesbids);
        model.addAttribute("ipHost", sysConfig.getIpHost());
        model.addAttribute("gisHost", sysConfig.getGisHost());
        
        return "ResManage/NewResRegister/ExtBaseMap";
    }
    
    /**
     * 基础底图--关联标注图页面
     */
    @RequestMapping("/GuanLianBiaoZhuTu")
    public String GuanLianBiaoZhuTu(Model model) {
        model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
        return "/ResManage/NewResRegister/GuanLianBiaoZhuTu";
    }
    
    /**
     * 基础底图--获取关联标注图标注底图目录树
     * @param resMainInfo
     * @param parentid
     */
    @RequestMapping("/getBaseMapForBZTree")
    @ResponseBody
    public String getBaseMapForBZTree(Res_MainInfo resMainInfo, String parentid) {
        StringBuilder sb = new StringBuilder();
        Map<String, Object> map = new HashMap<>();
        map.put("title", resMainInfo.getTitle());
        map.put("parentid", parentid);
        List<Res_Catalog> resCatalogs = resExtBaseMapService.getBaseMapForBZNode(map);
        
        // 循环构造子目录节点
        for (Res_Catalog resCatalog : resCatalogs) {
            Map<String, Object> nodemap = new HashMap<>();
            nodemap.put("title", resMainInfo.getTitle());
            nodemap.put("parentid", resCatalog.getCatlogid());
            int childCount = resExtBaseMapService.getBaseMapForBZTree(nodemap).size();
            if (childCount > 0) {
                if (!"".equals(sb.toString())) {
                    sb.append(',');
                }
                sb.append("{id: " + resCatalog.getCatlogid() + ",name:'" + resCatalog.getTitle() + "',title:'" + resCatalog.getTitle() + "',isParent: true,iconOpen:'/image/classicons/folderOpen.png',iconClose:'/image/classicons/folder.png'}");
            } else {
                if (!getBaseMapForBZTreeNode(nodemap).isEmpty()) {
                    if (!"".equals(sb.toString())) {
                        sb.append(',');
                    }
                    sb.append("{id: " + resCatalog.getCatlogid() + ",name:'" + resCatalog.getTitle() + "',title:'" + resCatalog.getTitle() + "',isParent: true,iconOpen:'/image/classicons/folderOpen.png',iconClose:'/image/classicons/folder.png'}");
                    sb.append(getBaseMapForBZTreeNode(nodemap));
                }
            }
        }
        
        List<Res_MainInfo> list = resExtBaseMapService.getBaseMapForBZTree(map);
        // 循环构造资源节点
        for (Res_MainInfo resMainInfo1 : list) {
            if (!"".equals(sb.toString())) {
                sb.append(',');
            }
            sb.append("{id: 'ZiYuan_" + resMainInfo1.getResourceid() + "',name:'" + resMainInfo1.getTitle() + "', title: '" + resMainInfo1.getDatasources() + "',isParent:false,icon:'/image/classicons/KJ_JCDT.png'}");
        }
        System.out.println(sb.toString());
        return "[" + sb.toString() + "]";
    }
    
    public String getBaseMapForBZTreeNode(Map<String, Object> map) {
        StringBuilder sb = new StringBuilder();
        List<Res_Catalog> resCatalogs = resExtBaseMapService.getBaseMapForBZNode(map);
        // 循环构造子目录节点
        for (Res_Catalog resCatalog : resCatalogs) {
            Map<String, Object> nodemap = new HashMap<>();
            nodemap = map;
            nodemap.put("parentid", resCatalog.getCatlogid());
            int childCount = resExtBaseMapService.getBaseMapForBZTree(nodemap).size();
            if (childCount > 0) {
                if (!"".equals(sb.toString())) {
                    sb.append(',');
                }
                sb.append("{id: " + resCatalog.getCatlogid() + ",name:'" + resCatalog.getTitle() + "',title:'" + resCatalog.getTitle() + "',isParent: true}");
            } else {
                if (!getBaseMapForBZTreeNode(nodemap).isEmpty()) {
                    if (!"".equals(sb.toString())) {
                        sb.append(',');
                    }
                    sb.append("{id: " + resCatalog.getCatlogid() + ",name:'" + resCatalog.getTitle() + "',title:'" + resCatalog.getTitle() + "',isParent: true,icon:'/image/classicons/defaulticon.png'}");
                    sb.append(getBaseMapForBZTreeNode(nodemap));
                }
            }
        }
        System.out.println(sb.toString());
        return sb.toString();
    }
    
    /**
     * 专题地图资源拓展页面
     */
    @RequestMapping("/ExtThemeMap")
    public String ExtThemeMap(Integer resMainInfoId, Model model) {
        Res_ExtMapUrl resExtMapUrl = new Res_ExtMapUrl();
        Res_ExtThemeMap resExtThemeMap;
        
        LinkedHashMap<String, String> typeandurlList = FieldUtils.getFieldListByKey("TypeAndURL");//获取地理参考模型列表
        model.addAttribute("typeandurlList", typeandurlList);
        String typeandurlListJson = "";
        for (Map.Entry<String, String> entry : typeandurlList.entrySet()) {
            if (typeandurlListJson != "") typeandurlListJson += ",";
            typeandurlListJson += "{key:'" + entry.getKey() + "',value:'" + entry.getValue() + "'}";
        }
        model.addAttribute("typeandurlListJson", "[" + typeandurlListJson + "]");
        
        if (resMainInfoId != null) {
            List<Res_ExtMapUrl> resExtMapUrlList = resExtMapUrlService.selectByCondition(resMainInfoId);
            if (resExtMapUrlList.size() > 0) {
                resExtMapUrl = resExtMapUrlList.get(0);
            }
            resExtThemeMap = resExtThemeMapService.selectByPrimaryKey(resMainInfoId);
            if (resExtThemeMap != null) {
                Res_MainInfo res_mainInfo = resMainInfoService.selectByPrimaryKey(resMainInfoId);
                model.addAttribute("resMainInfo", res_mainInfo);
                model.addAttribute("resExtThemeMap", resExtThemeMap);
                model.addAttribute("resMainInfoId", resMainInfoId);
                
                if (resExtThemeMap.getDefaultlayerset() != null) {
                    Res_MainInfo res_mainInfo1 = resMainInfoService.selectByPrimaryKey(resExtThemeMap.getDefaultlayerset());
                    String name = res_mainInfo1.getTitle();
                    model.addAttribute("baseMapLayerName", name);
                }
                
                LinkedHashMap<Integer, String> tucengList = new LinkedHashMap<Integer, String>();
                if (resExtThemeMap.getSublayerset() != null && !resExtThemeMap.getSublayerset().isEmpty()) {
                    String[] tuceng = resExtThemeMap.getSublayerset().split(",");
                    for (int i = 0; i < tuceng.length; i++) {
                        Res_MainInfo resMainInfo = resMainInfoService.selectByPrimaryKey(Integer.parseInt(tuceng[i]));
                        if (resMainInfo != null) {
                            tucengList.put(resMainInfo.getResourceid(), resMainInfo.getTitle());
                        }
                    }
                }
                model.addAttribute("tucengList", tucengList);
            } else {
                Res_MainInfo res_mainInfo = new Res_MainInfo();
                model.addAttribute("resMainInfo", res_mainInfo);
                resExtThemeMap = new Res_ExtThemeMap();
                model.addAttribute("resExtThemeMap", resExtThemeMap);
                model.addAttribute("tucengList", new LinkedHashMap<Integer, String>());
            }
        } else {
            Res_MainInfo res_mainInfo = new Res_MainInfo();
            model.addAttribute("resMainInfo", res_mainInfo);
            resExtThemeMap = new Res_ExtThemeMap();
            model.addAttribute("resExtThemeMap", resExtThemeMap);
            model.addAttribute("tucengList", new LinkedHashMap<Integer, String>());
        }
        
        model.addAttribute("resExtMapUrl", resExtMapUrl);
        LinkedHashMap<String, String> PublishSoftList = FieldUtils.getFieldListByKey("PublishSoft");//获取发布平台字典列表
        LinkedHashMap<String, String> typeList = FieldUtils.getFieldListByKey("ThemeMapType");//获取发布平台字典列表
        model.addAttribute("PublishSoftList", PublishSoftList);
        model.addAttribute("typeList", typeList);
        
        if (SecurityUtils.getSubject().isPermitted("org_user_admin")) {
            //判断当前用户是否是管理员,是管理员或是未提交的资源才可以修改资源相关信息
            model.addAttribute("admin", true);
        } else {
            model.addAttribute("admin", false);
        }
        model.addAttribute("esbHost", sysConfig.getEsbHost());
        model.addAttribute("esbUrl", sysConfig.getEsbUrl());
        String oldesbids = resExtThemeMap != null ? resExtMapUrlService.queryRsbidsByResourceid(resMainInfoId) : "";
        model.addAttribute("oldesbids", oldesbids);
        model.addAttribute("ipHost", sysConfig.getIpHost());
        model.addAttribute("gisHost", sysConfig.getGisHost());
        
        return "ResManage/NewResRegister/ExtThemeMap";
    }
    
    /**
     * 空间分析资源拓展页面
     */
    @RequestMapping("/ExtSpaceServer")
    public String ExtSpaceServer(Model model) {
        Res_ExtSpaceServerWithBLOBs resExtSpaceServer = new Res_ExtSpaceServerWithBLOBs();
        model.addAttribute("resExtSpaceServer", resExtSpaceServer);
        model.addAttribute("resMainInfo", new Res_MainInfo());
        model.addAttribute("content", resExtSpaceServer.getHelpurl());
        if (SecurityUtils.getSubject().isPermitted("org_user_admin")) {
            //判断当前用户是否是管理员,是管理员或是未提交的资源才可以修改资源相关信息
            model.addAttribute("admin", true);
        } else {
            model.addAttribute("admin", false);
        }
        
        model.addAttribute("backstageWebRoot", sysConfig.getApiServer() + "/");
        model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
        model.addAttribute("jspwebroot", sysConfig.getPubzyWebRoot().replace("javapubzy/", ""));
        return "ResManage/NewResRegister/ExtSpaceServer";
    }
    
    /**
     * 空间分析--空间服务参数页面
     */
    @RequestMapping("/ExtSpaceServerParams")
    public String ExtSpaceServerParams(Integer resMainInfoId, Model model) {
        List<Res_SpacesParam> res_spacesParams = new ArrayList<>();
        res_spacesParams = resSpacesParamService.selectByResSourceId(resMainInfoId);
        model.addAttribute("res_spacesParams", res_spacesParams);
        
        return "ResManage/NewResRegister/ExtSpaceServerParams";
    }
    
    /**
     * 空间服务参数查看页面
     * @param model
     * @param paramid
     * @param resourceid
     */
    @RequestMapping("/SpaceParameters")
    public String SpaceParameters(Model model, Integer paramid, Integer resourceid) {
        model.addAttribute("resourceid", resourceid);
        model.addAttribute("paramid", paramid);
        model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
        return "ResManage/ResRegister/SpaceParameters";
    }
    
    /**
     * 空间服务参数编辑页面
     * @param model
     * @param paramid
     * @param resourceid
     */
    @RequestMapping("/SpaceParameters_Edit")
    public String SpaceParametersEdit(Model model, Integer paramid, Integer resourceid) {
        Res_SpacesParam resSpacesParam = new Res_SpacesParam();
        resSpacesParam.setResourceid(resourceid);
        if (paramid != null) {
            resSpacesParam = resSpacesParamService.selectByPrimaryKey(paramid);
        }
        model.addAttribute("resSpacesParam", resSpacesParam);
        model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
        model.addAttribute("systemName", sysConfig.getAppFullName());
        return "ResManage/ResRegister/SpaceParameters_Edit";
    }
    
    /**
     * 三维模型资源拓展页面
     */
    @RequestMapping("/Ext3D")
    public String Ext3D(Model model) {
        Res_Ext3D res_ext3D1 = new Res_Ext3D();
        model.addAttribute("resExt3d", res_ext3D1);
        Res_MainInfo res_mainInfo = new Res_MainInfo();
        model.addAttribute("resMainInfo", res_mainInfo);
        
        if (SecurityUtils.getSubject().isPermitted("org_user_admin")) {
            //判断当前用户是否是管理员,是管理员或是未提交的资源才可以修改资源相关信息
            model.addAttribute("admin", true);
        } else {
            model.addAttribute("admin", false);
        }
        model.addAttribute("ipHost", sysConfig.getIpHost());
        model.addAttribute("gisHost", sysConfig.getGisHost());
        
        model.addAttribute("backstageWebRoot", sysConfig.getApiServer() + "/");
        model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
        model.addAttribute("ipHost", sysConfig.getIpHost());
        model.addAttribute("gisHost", sysConfig.getGisHost());
        return "ResManage/NewResRegister/Ext3D";
    }
    
    /**
     * 业务图层资源拓展页面
     */
    @RequestMapping("/ExtBusinessLayer")
    public String ExtBusinessLayer(Integer resMainInfoId, Model model) {
        Res_ExtMapUrl resExtMapUrl = new Res_ExtMapUrl();
        Res_ExtBusinessLayer resExtBusinessLayer;
        
        LinkedHashMap<String, String> typeandurlList = FieldUtils.getFieldListByKey("TypeAndURL");// 获取地理参考模型列表
        model.addAttribute("typeandurlList", typeandurlList);
        String typeandurlListJson = "";
        
        for (Map.Entry<String, String> entry : typeandurlList.entrySet()) {
            if (typeandurlListJson != "") typeandurlListJson += ",";
            typeandurlListJson += "{key:'" + entry.getKey() + "',value:'" + entry.getValue() + "'}";
        }
        model.addAttribute("typeandurlListJson", "[" + typeandurlListJson + "]");
        
        if (resMainInfoId != null) {
            List<Res_ExtMapUrl> resExtMapUrlList = resExtMapUrlService.selectByCondition(resMainInfoId);
            if (resExtMapUrlList.size() > 0) {
                resExtMapUrl = resExtMapUrlList.get(0);
            }
            resExtBusinessLayer = resExtBusinessLayerService.selectByPrimaryKey(resMainInfoId);
            if (resExtBusinessLayer != null) {
                Res_MainInfo res_mainInfo = resMainInfoService.selectByPrimaryKey(resMainInfoId);
                model.addAttribute("resMainInfo", res_mainInfo);
                model.addAttribute("resExtBusinessLayer", resExtBusinessLayer);
                model.addAttribute("resMainInfoId", resMainInfoId);
            } else {
                resExtBusinessLayer = new Res_ExtBusinessLayer();
                Res_MainInfo res_mainInfo = new Res_MainInfo();
                model.addAttribute("resMainInfo", res_mainInfo);
                model.addAttribute("resExtBusinessLayer", resExtBusinessLayer);
            }
        } else {
            resExtBusinessLayer = new Res_ExtBusinessLayer();
            Res_MainInfo res_mainInfo = new Res_MainInfo();
            model.addAttribute("resMainInfo", res_mainInfo);
            model.addAttribute("resExtBusinessLayer", resExtBusinessLayer);
        }
        
        model.addAttribute("resExtMapUrl", resExtMapUrl);
        LinkedHashMap<String, String> PublishSoftList = FieldUtils.getFieldListByKey("PublishSoft");// 获取发布平台字典列表
        model.addAttribute("PublishSoftList", PublishSoftList);
        
        if (SecurityUtils.getSubject().isPermitted("org_user_admin")) {
            //判断当前用户是否是管理员,是管理员或是未提交的资源才可以修改资源相关信息
            model.addAttribute("admin", true);
        } else {
            model.addAttribute("admin", false);
        }
        model.addAttribute("esbHost", sysConfig.getEsbHost());
        model.addAttribute("esbUrl", sysConfig.getEsbUrl());
        String oldesbids = resExtBusinessLayer != null ? resExtMapUrlService.queryRsbidsByResourceid(resMainInfoId) : "";
        model.addAttribute("oldesbids", oldesbids);
        model.addAttribute("ipHost", sysConfig.getIpHost());
        model.addAttribute("gisHost", sysConfig.getGisHost());
        
        return "ResManage/NewResRegister/ExtBusinessLayer";
    }
    
    /**
     * ESB代理通用页面
     */
    @RequestMapping("/ExtMapUrl")
    public String ExtMapUrl(Integer resMainInfoId, Model model) {
        Res_ExtMapUrl resExtMapUrl = resExtMapUrlService.selectByCondition(resMainInfoId).size() > 0 ? resExtMapUrlService.selectByCondition(resMainInfoId).get(0) : new Res_ExtMapUrl();
        model.addAttribute("resExtMapUrl", resExtMapUrl);
        if (resMainInfoId != null) {
            Res_MainInfo res_mainInfo = resMainInfoService.selectByPrimaryKey(resMainInfoId);
            model.addAttribute("resMainInfo", res_mainInfo);
        } else {
            Res_MainInfo res_mainInfo = new Res_MainInfo();
            model.addAttribute("resMainInfo", res_mainInfo);
        }
        return "ResManage/NewResRegister/ExtMapUrl";
    }
    
    /**
     * 资源向导编辑页面
     */
    @RequestMapping("/ResEdit")
    public String Edit(Model model, Long resMainInfoId) {
        if (resMainInfoId != null) {
            Res_MainInfo resMainInfo = resMainInfoService.selectByPrimaryKey(resMainInfoId.intValue());
            HashMap<String, String> ResourceTypeList = FieldUtils.getFieldListByKey("ResourceType");// 获取资源类型列表
            model.addAttribute("resourceclass", ResourceTypeList.get(resMainInfo.getResourceclass()));
        }
        String pubzyWebRoot = sysConfig.getPubzyWebRoot();
        model.addAttribute("resMainInfoId", resMainInfoId);
        model.addAttribute("pubzyWebRoot", pubzyWebRoot);
        model.addAttribute("systemName", sysConfig.getAppFullName());
        model.addAttribute("jspwebroot", pubzyWebRoot.replace("javapubzy/", ""));// 临时处理
        
        return "ResManage/NewResRegister/Edit";
    }
    
    /**
     * 资源类型选择页面
     */
    @RequestMapping("/ResResourceClass")
    public String ResResourceClass(Model model) {
        String pubzyWebRoot = sysConfig.getPubzyWebRoot();
        model.addAttribute("pubzyWebRoot", pubzyWebRoot);
        model.addAttribute("systemName", sysConfig.getAppFullName());
        model.addAttribute("jspwebroot", pubzyWebRoot.replace("javapubzy/", ""));// 临时处理
        return "ResManage/NewResRegister/ResResourceClass";
    }
    
    /**
     * 基本信息
     */
    @RequestMapping("/MainInfo")
    public String MainInfo(HttpServletRequest request, Model model, Long resMainInfoId) throws IOException {
        Res_MainInfo res_mainInfo = new Res_MainInfo();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Res_Catalog res_catalog = new Res_Catalog();
        String newDate = sdf.format(new Date());
        String Imagelujin = null;
        int auditstatus = -1;// 审核状态
        // 获取当前登录人id name 还有对应的单位id name
        Long userid = getUserId();
        
        // 修改
        if (resMainInfoId != null) {
            res_mainInfo = resMainInfoService.selectByPrimaryKey(resMainInfoId.intValue());
            String Pubdate = sdf.format(res_mainInfo.getPubdate());
            if (res_mainInfo.getProductiontime() != null) {
                String productiontimes = sdf.format(res_mainInfo.getProductiontime());
                model.addAttribute("productiontime", productiontimes);
            }
            model.addAttribute("Pubdate", Pubdate);
            if (res_mainInfo.getCatlogid() != null) {
                res_catalog = resCatalogService.selectByPrimaryKey(res_mainInfo.getCatlogid());
                if (res_catalog != null) {
                    model.addAttribute("catlogtitle", res_catalog.getTitle());
                }
            }
            if (res_mainInfo.getImgurl() != null && res_mainInfo.getImgurl() != "") {
                if (res_mainInfo.getImgurl().startsWith("Atkas")) {//图集
                    Imagelujin = "/image/" + res_mainInfo.getImgurl();
                } else {
                    StringBuffer url = request.getRequestURL();
                    String ip = "/uploadPath/";
                    Imagelujin = ip + res_mainInfo.getImgurl();
                }
            }
            // modified by qufangxu 信创环境下,若 res_mainInfo.getAdministrativeid() = '        ',会返回单点登录页面,具体原因未知。 解决办法:提前去除空格、制表符
            String administrativeid = (String) res_mainInfo.getAdministrativeid();// 数据覆盖范围--行政区划Id
            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);
                }
            }
            // 审核状态
            if (res_mainInfo.getAuditstatus() != null) {
                auditstatus = res_mainInfo.getAuditstatus();
            }
            model.addAttribute("chinesename", orgUserService.queryObject(res_mainInfo.getCreateuserid()).getChinesename());
            if (res_mainInfo.getPubunitid() == 0) {
                OrgUnit orgunit = orgUserService.getDefaultUnit(res_mainInfo.getCreateuserid());
                model.addAttribute("unitname", orgunit.getUnitname());
                res_mainInfo.setPubunitid(orgunit.getUnitid().intValue());
            } else {
                OrgUnit orgunit = orgUnitService.getUnitById(res_mainInfo.getPubunitid().longValue());
                model.addAttribute("unitname", orgunit.getUnitname());
            }
        } else {
            //新增
            OrgUnit orgunit = orgUserService.getDefaultUnit(userid);
            String unitname = "";
            if (orgunit.getUnitid() != null) {
                res_mainInfo.setPubunitid(orgunit.getUnitid().intValue());
                unitname = orgunit.getUnitname();
            }
            res_mainInfo.setCreateuserid(userid);
            // modified by qufangxu
            res_mainInfo.setInsteadaudit(0);
            model.addAttribute("loginname", getUser().getLoginname());
            model.addAttribute("unitname", unitname);
            model.addAttribute("Pubdate", newDate);
            model.addAttribute("chinesename", getUser().getChinesename());
        }
        HashMap<String, String> ResourceTypeList = FieldUtils.getFieldListByKey("ResourceType");// 获取资源类型列表
        //获取数据来源列表
        LinkedHashMap<String, String> DataSourceList = FieldUtils.getDataSourceList();
        HashMap<String, String> SharProtocolList = FieldUtils.getFieldListByKey("SharProtocol");// 获取共享协议列表
        List<String> list = resMainInfoService.selectTopHotSearch();
        String[] KeywordsList = new String[list.size()];// 获取关键字列表
        for (int i = 0; i < list.size(); i++) {
            KeywordsList[i] = list.get(i);
        }
        //换地址
        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("datasourcelist", DataSourceList);
        model.addAttribute("mainInfo", res_mainInfo);
        model.addAttribute("resMainInfoId", resMainInfoId);
        model.addAttribute("ResourceTypeList", ResourceTypeList);
        model.addAttribute("Imagelujin", Imagelujin);
        model.addAttribute("auditstatus", auditstatus);
        model.addAttribute("SharProtocolList", SharProtocolList);
        model.addAttribute("KeywordsList", KeywordsList);
        
        HashMap<String, String> UpdateTimesList = FieldUtils.getFieldListByKey("UpdateTimes");// 获取更新频率列表
        model.addAttribute("UpdateTimesList", UpdateTimesList);
        
        if (SecurityUtils.getSubject().isPermitted("org_user_admin")) {
            //判断当前用户是否是管理员,是管理员或是未提交的资源才可以修改资源相关信息
            model.addAttribute("admin", true);
        } else {
            model.addAttribute("admin", false);
        }
        return "ResManage/NewResRegister/MainInfo";
    }
    
    /**
     * 访问附件管理数据图层信息页面
     */
    @RequestMapping("/ResFiles")
    public String ResFiles(int resMainInfoId, Model datamodel) {
        List<Res_Files> List = resFilesService.selectDataListForResourceid(resMainInfoId);
        return "ResManage/NewResRegister/ResFiles";
    }
    
    /**
     * 插入资源编辑页面内容
     */
    @RequestMapping("ziYuanInsert")
    @ResponseBody
    @LogAction("资源管理,资源发布,资源新增,新增|zy")
    public String ziYuanInsert(MainInfoJoinRegister mainInfoJoinRegister) {
        Res_MainInfo resMainInfo = mainInfoJoinRegister.getResMainInfo();
        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);
        if (result == 1) {//新增成功,插入拓展表信息
            String leixin = resMainInfo.getResourceclass();
            //alert ykm 2019/02/26
            if(leixin.equals("KJ_SWMX") || leixin.equals("KJ_SWDX") || leixin.equals("KJ_SWYX")) leixin = "KJ_SW";
            switch (leixin) {
                case "SJKB":
                    saveDataBase(mainInfoJoinRegister.getResExtDataBase());
                    break;
                case "JKFW":
                    saveInterFaceService(mainInfoJoinRegister.getResExtInterFaceService());
                    saveFileData(mainInfoJoinRegister.getResFiles(), mainInfoJoinRegister.getSavedsizenum(), mainInfoJoinRegister.getFiletype());
                    break;
                case "SJWJ":
                    saveExtFileSource(mainInfoJoinRegister.getResExtFileSource(), mainInfoJoinRegister.getSavedsizenum());
                    saveFileSourceWay(mainInfoJoinRegister.getResMainInfo(), mainInfoJoinRegister.getExtMapUrlStr());
                    break;
                case "YWJC":
                    saveExtIntegrate(mainInfoJoinRegister.getResExtIntegrate());
                    break;
                case "KJ_JCDT":
                    saveBaseMap(mainInfoJoinRegister.getResExtBaseMap(), mainInfoJoinRegister.getXianshibiliStart(), mainInfoJoinRegister.getXianshibiliEnd(), mainInfoJoinRegister.getExtMapUrlStr());
                    break;
                case "KJ_ZTDT":
                    saveThemeMap(mainInfoJoinRegister.getResExtThemeMap(), mainInfoJoinRegister.getExtMapUrlStr());
                    break;
                case "KJ_KJFX":
                    saveSpaceServer(mainInfoJoinRegister.getResExtSpaceServerWithBLOBs());
                    saveFileData(mainInfoJoinRegister.getResFiles(), mainInfoJoinRegister.getSavedsizenum(), mainInfoJoinRegister.getFiletype());
                    break;
//                case "KJ_SWMX":
                case "KJ_SW": //三维类型,三维模型,三维地形,三维影像
                    save3D(mainInfoJoinRegister.getResExt3D());
                    break;
                case "KJ_YWTC":
                    saveBusinessLayer(mainInfoJoinRegister.getResExtBusinessLayer(), mainInfoJoinRegister.getExtMapUrlStr());
                    break;
            }
            resMainInfo.setOrderid(resMainInfo.getResourceid());
            resMainInfoService.updateByPrimaryKeySelective(resMainInfo);
            Object resourceClass = resMainInfo.getResourceclass();
        }
        return "{'result':'" + result + "','ziyuanId':'" + resMainInfo.getResourceid() + "','ziyuanClass':'" + resMainInfo.getResourceclass() + "'}";
    }
    
    //保存数据文件
    @ResponseBody
    public int saveDataBase(Res_ExtDataBase record) {
        Res_ExtDataBase resExtDataBase = resExtDataBaseService.selectByMainInfoId(record.getResourceid());
        if (resExtDataBase == null) {
            //添加
            Res_ExtDataSource res_extDataSource = resExtDataSourceService.selectByPrimaryKey(record.getDatasourceid());
            if (!res_extDataSource.getDatabasetype().equals("Oracle")) {
                if (record.getSpacename() != null) {
                    record.setSpacename(null);
                }
            }
            return resExtDataBaseService.insertSelective(record);
        } else {
            //更新
            Res_ExtDataSource res_extDataSource = resExtDataSourceService.selectByPrimaryKey(record.getDatasourceid());
            if (!res_extDataSource.getDatabasetype().equals("Oracle")) {
                if (record.getSpacename() != null) {
                    record.setSpacename(null);
                }
            }
            return resExtDataBaseService.updateByPrimaryKey(record);
        }
    }
    
    //保存接口服务
    @ResponseBody
    public int saveInterFaceService(Res_ExtInterFaceService entity) {
        Res_ExtInterFaceService res_extInterFaceService = resExtInterFaceService.selectByPrimaryKey(entity.getResourceid());
        int result = 0;
        if (res_extInterFaceService == null) {
            resExtInterFaceService.insertSelective(entity);//添加
        } else {
            resExtInterFaceService.updateByPrimaryKeySelective(entity);//更新
        }
        return result;
    }
    
    //保存数据文件
    @ResponseBody
    public int saveExtFileSource(Res_ExtFileSource record, double savedsizenum) {
        record.setFilesize(savedsizenum);
        record.setServerurl(StringEscapeUtils.unescapeHtml(record.getServerurl()));
        Res_ExtFileSource resExtFileSource = resExtFileSourceService.selectByPrimaryKey(record.getResourceid());
        if (resExtFileSource == null) {
            // 添加
            if (record.getDownloadmodel().equals("FTP")) { // 把不属于FTP的字段设置为空
                record.setGettype(null);
            } else if (record.getDownloadmodel().equals("HTTP")) {
                record.setFtpusername(null);
                record.setFtppwd(null);
            }
            if (record.getSourcetype().equals("文件")) {
                replaceRoute(record.getServerurl(), "temp");
                record.setServerurl(record.getServerurl().replace("temp/", ""));
            }
            return resExtFileSourceService.insertSelective(record);
        } else {
            // 更新
            if (record.getSourcetype().equals("文件")) {
                replaceRoute(record.getServerurl(), "temp");
                if (!record.getServerurl().equals("") && !resExtFileSource.getServerurl().equals("") && resExtFileSource.getStoragemode().equals("本地")) {
                    String path = resExtFileSource.getServerurl();
                    path = sysConfig.getUploadPath() + path;
                    File file = new File(path);
                    if (file.exists()) {
                        DelectEquealFile(record.getServerurl(), resExtFileSource.getServerurl());
                    }
                }
                record.setServerurl(record.getServerurl().replace("temp/", ""));
            }
            if (record.getDownloadmodel().equals("FTP")) {
                record.setGettype(null);
            } else if (record.getDownloadmodel().equals("HTTP")) {
                record.setFtpusername(null);
                record.setFtppwd(null);
            }
            // 如果文件资源类型改变则把原有的文件删除
            if (!record.getSourcetype().equals(resExtFileSource.getSourcetype()) || record.getStoragemode().equals("远程")) {
                String path = resExtFileSource.getServerurl();
                if (resExtFileSource.getSourcetype().equals("文件夹") && resExtFileSource.getStoragemode().equals("本地")) {
                    path = sysConfig.getUploadPath() + path;
                    File file = new File(path);
                    if (file.exists()) {
                        DeleteFileUtils.deletefileUtils(path);
                    }
                }
                if (resExtFileSource.getSourcetype().equals("文件") && resExtFileSource.getStoragemode().equals("本地")) {
                    path = sysConfig.getUploadPath() + path;
                    File file = new File(path);
                    if (file.exists()) {
                        DeleteFileUtils.deletefileUtils(path);
                    }
                }
            }
            return resExtFileSourceService.updateByPrimaryKey(record);
        }
    }
    
    //保存业务集成
    @ResponseBody
    public int saveExtIntegrate(Res_ExtIntegrate record) {
        Res_ExtIntegrate resExtIntegrate = resExtIntegrateService.selectByPrimaryKey(record.getResourceid());
        if (record.getServerurl() != null && record.getServerurl().length() > 0) {
            record.setServerurl(StringEscapeUtils.unescapeHtml(record.getServerurl()));
        }
        if (resExtIntegrate == null) {
            //添加
            if (record.getIntegratetype().equals("页面集成")) {
                String showmodel = record.getShowmodel();
                int id = record.getResourceid();
                String url = record.getServerurl();
                String type = record.getIntegratetype();
                Res_ExtIntegrate res_extIntegrate = new Res_ExtIntegrate();
                res_extIntegrate.setResourceid(id);
                res_extIntegrate.setIntegratetype(type);
                res_extIntegrate.setServerurl(url);
                res_extIntegrate.setShowmodel(showmodel);
                res_extIntegrate.setResolution(record.getResolution());
                return resExtIntegrateService.insertSelective(res_extIntegrate);
            }
            if (record.getIntegratetype().equals("数据集成")) {
                if (record.getShowmodel() != null) {
                    record.setShowmodel(null);
                    record.setResolution(null);
                }
                return resExtIntegrateService.insertSelective(record);
            }
        } else {
            //更新
            if (record.getIntegratetype().equals("页面集成")) {
                String showmodel = record.getShowmodel();
                int id = record.getResourceid();
                String url = record.getServerurl();
                String type = record.getIntegratetype();
                Res_ExtIntegrate res_extIntegrate = new Res_ExtIntegrate();
                res_extIntegrate.setResourceid(id);
                res_extIntegrate.setIntegratetype(type);
                res_extIntegrate.setServerurl(url);
                res_extIntegrate.setShowmodel(showmodel);
                res_extIntegrate.setResolution(record.getResolution());
                return resExtIntegrateService.updateByPrimaryKeyWithBLOBs(res_extIntegrate);
            }
            if (record.getIntegratetype().equals("数据集成")) {
                if (resExtIntegrate.getShowmodel() != null) {  //集成类型改变,如果数据库的值不为空则清空
                    record.setShowmodel(null);
                    record.setResolution(null);
                }
                if (resExtIntegrate.getChartmodel() != null) {
                    record.setChartmodel(resExtIntegrate.getChartmodel());
                }
                if (resExtIntegrate.getChartheight() != null) {
                    record.setChartheight(resExtIntegrate.getChartheight());
                }
                if (resExtIntegrate.getChartwidth() != null) {
                    record.setChartwidth(resExtIntegrate.getChartwidth());
                }
                return resExtIntegrateService.updateByPrimaryKeyWithBLOBs(record);
            }
        }
        return 0;
    }
    
    //保存基础底图
    @ResponseBody
    public int saveBaseMap(Res_ExtBaseMap record, String xianshibiliStart, String xianshibiliEnd, String extMapUrlStr) {
        // 插入资源支持协议与地址表
        resExtMapUrlService.deleteAndInsertMapUrlArray(record.getResourceid(), extMapUrlStr);
        // 判断 id是否存在 存在就更新 不存在就 添加
        Res_ExtBaseMap resExtBaseMap = resExtBaseMapService.selectByPrimaryKey(record.getResourceid());
        if (!xianshibiliStart.isEmpty() && !xianshibiliEnd.isEmpty()) {
            record.setDisplaylev(xianshibiliStart + "-" + xianshibiliEnd);
        }
        record.setResourceid(record.getResourceid());
        if (resExtBaseMap == null) {
            // 添加
            if (!record.getBasemaptype().equals("影像")) { // 判断底图类型是否是影像,不是则令影像精度为空
                record.setImageaccuracy(null);
            }
            return resExtBaseMapService.insertSelective(record);
        } else {
            // 更新
            if (!record.getBasemaptype().equals("影像")) { // 判断底图类型是否是影像,不是则令影像精度为空
                record.setImageaccuracy(null);
            }
            return resExtBaseMapService.updateByPrimaryKey(record);
        }
    }
    
    //保存专题地图
    @ResponseBody
    public int saveThemeMap(Res_ExtThemeMap record, String extMapUrlStr) {
        // 插入资源支持协议与地址表
        resExtMapUrlService.deleteAndInsertMapUrlArray(record.getResourceid(), extMapUrlStr);
        Res_ExtThemeMap resExtThemeMap = resExtThemeMapService.selectByPrimaryKey(record.getResourceid());
        if (resExtThemeMap == null) {
            //添加
            if (!record.getLegendurl().isEmpty()) {
                replaceRoute("temp/ResExtThemMapServer/" + record.getLegendurl(), "temp/");
            }
            return resExtThemeMapService.insertSelective(record);
        } else {
            //更新
            String path = sysConfig.getUploadPath() + "ResExtThemMapServer/" + resExtThemeMap.getLegendurl();
            File file = new File(path);
            if (file.exists()) {
                file.delete();
            }
            if (!record.getLegendurl().isEmpty()) {
                replaceRoute("temp/ResExtThemMapServer/" + record.getLegendurl(), "temp/");
            }
            return resExtThemeMapService.updateByPrimaryKeyWithBLOBs(record);
        }
    }
    
    //保存空间分析
    @ResponseBody
    public int saveSpaceServer(Res_ExtSpaceServerWithBLOBs record) {
        Res_ExtSpaceServerWithBLOBs resExtSpaceServerWithBLOBs = resExtSpaceServerService.selectByPrimaryKey(record.getResourceid());
        if (record.getHelpurl().length() != 0) {
            record.setHelpurl(StringEscapeUtils.unescapeHtml(record.getHelpurl()));
        }
        if (resExtSpaceServerWithBLOBs == null) {
            //添加
            return resExtSpaceServerService.insertSelective(record);
        } else {
            //更新
            return resExtSpaceServerService.updateByPrimaryKeyWithBLOBs(record);
        }
    }
    
    //保存三维模型
    @ResponseBody
    public int save3D(Res_Ext3D record) {
        Res_Ext3D res_ext3D = resExt3DService.selectByPrimaryKey(record.getResourceid());
        if (res_ext3D == null) {
            //添加
            return resExt3DService.insertSelective(record);
        } else {
            //更新
            return resExt3DService.updateByPrimaryKeySelective(record);
        }
    }
    
    //保存业务图层
    @ResponseBody
    public int saveBusinessLayer(Res_ExtBusinessLayer record, String extMapUrlStr) {
        // 插入资源支持协议与地址表
        resExtMapUrlService.deleteAndInsertMapUrlArray(record.getResourceid(), extMapUrlStr);
        // 判断 id是否存在 存在就更新 不存在就 添加
        Res_ExtBusinessLayer resExtBusinessLayer = resExtBusinessLayerService.selectByPrimaryKey(record.getResourceid());
        if (resExtBusinessLayer == null) {
            // 添加
            return resExtBusinessLayerService.insertSelective(record);
        } else {
            // 更新
            return resExtBusinessLayerService.updateByPrimaryKeySelective(record);
        }
    }
    
    //保存相关附件
    @ResponseBody
    public int saveFileData(Res_Files record, double savedsizenum, String filetype) {
        record.setFilesize(savedsizenum);
        record.setFiletype(filetype);
        replaceRoute(record.getServerurl(), "temp");
        record.setServerurl(record.getServerurl().replace("temp/", ""));
        return resFilesService.insertSelective(record);
    }
    
    //保存数据文件展现方式
    @ResponseBody
    public int saveFileSourceWay(Res_MainInfo resMainInfo, String extMapUrlStr) {
        // 删除id 对应的所有文件展示方式
        try {
            if (resMainInfo.getResourceid() != null) {
                resFileSourceWayService.deleteByPrimaryKey(resMainInfo.getResourceid());
            }
            if (!extMapUrlStr.equals("")) {
                String[] extMapUrlArray = extMapUrlStr.split("\\|");
                // 插入资源支持协议与地址表
                for (int i = 0; i < extMapUrlArray.length; i++) {
                    String[] extMapUrlArray2 = extMapUrlArray[i].split(",");
                    String Showway = extMapUrlArray2[0];
                    String url = extMapUrlArray2[1];
                    String remark = extMapUrlArray2[2];
                    Res_FileSource_Way resFileSourceWay = new Res_FileSource_Way();
                    resFileSourceWay.setShowway(Showway);
                    resFileSourceWay.setUrl(url);
                    resFileSourceWay.setRemark(remark);
                    resFileSourceWay.setResourceid(resMainInfo.getResourceid());
                    resFileSourceWay.setCreatedate(new Date());
                    resFileSourceWayService.insertSelective(resFileSourceWay);
                }
            }
            return 1;
        } catch (Exception e) {
            return 0;
        }
    }
    
    //替换路径
    private void replaceRoute(@RequestBody String lujin, String replaceStr) {
        String oldFileUrl = sysConfig.getUploadPath() + lujin.replace("/", "\\");
        File oldFile = new File(oldFileUrl);
        String NewFileUrl = sysConfig.getUploadPath() + lujin.replace(replaceStr, "").replace("/", "\\");
        NewFileUrl = NewFileUrl.substring(0, NewFileUrl.lastIndexOf("\\")) + "\\";
        File NewFile = new File(NewFileUrl);
        if (!NewFile.exists()) { // 当前地址不为空,判断该路径是否存在,不存在则创建新的文件夹
            File newfilePath = new File(NewFile + "\\"); // 创建对应的年月文件夹
            newfilePath.mkdirs();
        }
        com.landtool.lanbase.common.utils.FileUtils.moveTotherFolders(oldFileUrl, NewFileUrl);
        if (oldFile.exists()) {
            oldFile.delete();
        }
    }
    
    //删除相同文件
    private void DelectEquealFile(@RequestBody String NEWString, String OLDString) {
        String oldourl = OLDString.substring(OLDString.lastIndexOf("/"), OLDString.length());
        String newurl = NEWString.substring(NEWString.lastIndexOf("/"), NEWString.length());
        if (!oldourl.equals(newurl)) {
            File OLDFile = new File(sysConfig.getUploadPath() + OLDString.replace("/", "\\"));
            System.out.println(OLDFile);
            OLDFile.delete();
        }
    }
    
    /**
     * 地图范围框选页面
     *
     * @param ResourceClass 资源类型(KJ_JCDT: 基础底图 KJ_ZTDT: 专题地图)
     */
    @RequestMapping("/obtainExtentMapViewer")
    public String obtainExtentMapViewer(String ResourceClass, Model model) {
        model.addAttribute("ResourceClass", ResourceClass);//资源类型
        model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
        model.addAttribute("obtainExtentMapUrl", sysConfig.getObtainExtentMapUrl());//框选地图底图URL
        return "ResManage/NewResRegister/obtainExtentMapViewer";
    }
}