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
package com.landtool.lanbase.modules.res.controller;
 
import java.io.File;
import java.io.IOException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.*;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import com.alibaba.druid.support.json.JSONUtils;
import com.google.gson.JsonObject;
import org.apache.commons.lang.time.DateUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
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.map.EsbToken;
import com.landtool.lanbase.common.utils.HttpOperateUtils;
import com.landtool.lanbase.common.utils.Result;
import com.landtool.lanbase.config.SysTemPropertyConfig;
import com.landtool.lanbase.modules.api.utils.Excel;
import com.landtool.lanbase.modules.api.utils.PageBean;
import com.landtool.lanbase.modules.org.entity.OrgUser;
import com.landtool.lanbase.modules.org.service.OrgUnitService;
import com.landtool.lanbase.modules.org.service.OrgUserService;
import com.landtool.lanbase.modules.res.entity.Res_ApplyRecommend;
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_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_ExtSpaceServer;
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.UserDefined.MainInfoJoinApplyRecommend;
import com.landtool.lanbase.modules.res.entity.UserDefined.MainInfoJoinApplyRecommendInfo;
import com.landtool.lanbase.modules.res.service.ResApplyRecommendService;
import com.landtool.lanbase.modules.res.service.ResCatalogService;
import com.landtool.lanbase.modules.res.service.ResExt3DService;
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.ResMainInfoService;
import com.landtool.lanbase.modules.sys.controller.AbstractController;
import com.landtool.lanbase.modules.sys.entity.SysSysteminfo;
import com.landtool.lanbase.modules.sys.service.SysFieldvalueService;
 
/**
 * 申请批复(推荐)
 */
@Controller
public class ResApplyRecommendController extends AbstractController {
    @Autowired
    private ResApplyRecommendService resApplyRecommendService;
 
    @Autowired
    public ResMainInfoService resMainInfoService;
 
    @Autowired
    private SysTemPropertyConfig sysConfig;
 
    @Autowired
    private OrgUserService orgUserService;
 
    @Autowired
    private SysFieldvalueService FieldUtils;
 
    @Autowired
    private OrgUnitService orgUnitService;
 
    @Autowired
    private ResCatalogService resCatalogService;
 
    @Autowired
    private ResExtMapUrlService resExtMapUrlService;
 
    @Autowired
    private ResExtThemeMapService resExtThemeMapService;
 
    @Autowired
    private ResExtInterFaceService resExtInterFaceService;
 
    @Autowired
    private ResExtFileSourceService resExtFileSourceService;
 
    @Autowired
    private ResExtIntegrateService resExtIntegrateService;
 
    @Autowired
    private ResExtSpaceServerService resExtSpaceServerService;
 
    @Autowired
    private ResExt3DService resExt3DService;
 
    public static String strMuLu = "";
 
    @ResponseBody
    @RequestMapping("/res/resApplyRecommend/insertSelectiveAndUpdate")
    public String insertSelectiveAndUpdate(Res_ApplyRecommend record, Long resourceid,Integer isSystem) {
        int result;
        Res_ApplyRecommend applyRecommend = new Res_ApplyRecommend();
        // 获取登录人姓名和登录人id和登录人部门id
        applyRecommend.setAppuserid(getUserId().toString());
        applyRecommend.setIsrecommend(0);
        applyRecommend.setResourceid(Integer.parseInt(resourceid + ""));
        // 判断 id是否存在 存在则删除原有记录,新增记录 不存在就 添加
        Integer isDelete = 0;
        Long timenum  = new Date().getTime();
        if(isSystem == null){
            Res_ApplyRecommend resApplyRecommend = resApplyRecommendService.selectByResApplyRecommend(applyRecommend);
            if(resApplyRecommend != null && !resApplyRecommend.getAuditresult().equals(0) && //批复后、过了申请有效截止时间
                    (resApplyRecommend.getEffendtime() == null || resApplyRecommend.getEffendtime().getTime() < timenum)){
                isDelete = 1;
            }
            if(isDelete == 1){
                resApplyRecommendService.deleteByPrimaryKey(resApplyRecommend.getAppid());
                record.setAppid(null);
            }
        }
        record.setIsrecommend(0);
        record.setAuditresult(0);
        record.setAppuserid(getUserId().toString());
        record.setAppdate(new Timestamp(new Date().getTime()));
        //TODO 用户插入
        Res_MainInfo res_mainInfo = resMainInfoService.selectByPrimaryKey(resourceid.intValue());
        record.setAudituserid(Math.toIntExact(res_mainInfo.getCreateuserid()));
        //算时间天数
        Integer effendday = record.getEffendday();
        Integer apptype = null==record.getApptype()?0:record.getApptype();
        if(effendday != null && effendday != 0){
            long time = record.getAppdate().getTime();
            long day = effendday * 24 * 60 * 60 * 1000;
            time += day;
            record.setEffendtime(new Timestamp(new Date(time).getTime()));
        }else  { //处理申请天数默认情况
            switch (apptype){
                case 0: //个人申请默认30天
                    effendday=30;
                    break;
                case 1: //单位申请默认360天
                    effendday=360;
                    break;
                case 3: //系统申请永久
                    effendday=0;
                    break;
            }
//            long time = record.getAppdate().getTime();
//            long day = Long.valueOf(effendday) * 24 * 60 * 60 * 1000;
//            time += day;
//            record.setEffendtime(new Timestamp(new Date(time).getTime()));
            record.setEffendtime(new Timestamp(DateUtils.addDays(record.getAppdate(), effendday).getTime()));
        }
        if(apptype==3&&effendday==0){ //系统申请永久 null
            record.setEffendtime(null);
        }
        int applyRecommendResult = resApplyRecommendService.insertSelective(record);
        if (applyRecommendResult == 1) {
            result = 1;
        } else {
            result = 0;
        }
        return "{\"result\":\"" + result + "\"}";
    }
 
    /**
     * 个人中心——申请资源
     */
    @ResponseBody
    @RequestMapping("/res/resApplyRecommend/shenQingZiYuan")
    public Result shenQingZiYuan(Res_ApplyRecommend recommend) {
        recommend.setAppuserid(getUserId().toString());
        List<MainInfoJoinApplyRecommend> list = resApplyRecommendService.shenQingZiYuan(recommend);
        StringBuilder str = new StringBuilder();
        str.append("[");
 
        List<Map<String, Object>> maps = new LinkedList<>();
        for (int i = 0; i < list.size(); i++) {
            Map<String, Object> map = new HashMap<>();
            map.put("appid", list.get(i).getAppid());
            map.put("title", list.get(i).getTitle());
            map.put("fulltitle", list.get(i).getTitle());
            map.put("auditresult", list.get(i).getAuditresult());
            map.put("resourceid", list.get(i).getResourceid());
            maps.add(map);
 
        }
        return Result.ok().put("result", maps);
    }
 
    /**
     * 个人中心——我的资源(未完成)
     */
    @ResponseBody
    @RequestMapping("/res/resApplyRecommend/woDeZiYuan")
    public String woDeZiYuan(Res_ApplyRecommend recommend) {
        recommend.setAppuserid(getUserId().toString());
        List<MainInfoJoinApplyRecommend> list = resApplyRecommendService.shenQingZiYuan(recommend);
        StringBuilder str = new StringBuilder();
        str.append("[");
        for (int i = 0; i < list.size(); i++) {
            if (i != 0) {
                str.append(",");
            }
            str.append("{");
            String title = list.get(i).getTitle();
            if(list.get(i).getTitle().length() > 15) {
                title = title.substring(0,15) + "...";
            }
            str.append("'title':'" + title + "',");
            str.append("'resourceid':'" + list.get(i).getResourceid() + "',");
            str.append("}");
        }
        str.append("]");
        return str.toString();
    }
 
    /**
     * 资源申请信息填写页面
     */
    @RequestMapping("/res/resApplyRecommend/ziYuanShenQing")
    public String ziYuanShenQing(Model model, Integer resourceid) {
        // 获取登录人姓名和登录人id和登录人部门id
        OrgUser user = getUser();
 
        String unitid = orgUserService.getDefaultUnit(user.getUserid()).getUnitid().toString();// user.getOrguserunits().get(0).getUnitid().toString();
        String chinesename = user.getChinesename();// entity.getChinesename();
        Long userid = user.getUserid();// entity.getUserid();
 
        Res_ApplyRecommend applyRecommend = new Res_ApplyRecommend();
        applyRecommend.setIsrecommend(0);
        applyRecommend.setAppuserid(userid.toString());
        applyRecommend.setResourceid(resourceid);
 
        Res_ApplyRecommend res_applyRecommend = resApplyRecommendService.selectByResApplyRecommend(applyRecommend);
 
        // 获取当前时间并转化为yyyy-MM-dd格式
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String newDate = sdf.format(new Date());
 
        // 新增页面
        //if (res_applyRecommend == null) {
 
        res_applyRecommend = new Res_ApplyRecommend();
        res_applyRecommend.setResourceid(resourceid);
        res_applyRecommend.setAppuserid(userid.toString());
        res_applyRecommend.setAppunitid((unitid));
        model.addAttribute("Appdate", newDate);
//        } else {
//            String appdate = sdf.format(res_applyRecommend.getAppdate());
//            model.addAttribute("Appdate", appdate);
//            if (res_applyRecommend.getEffendtime() != null) {
//                String effendtime = sdf.format(res_applyRecommend.getEffendtime());
//                model.addAttribute("EffEndtime", effendtime);
//            }
//        }
 
        // 获取资源信息名称
        Res_MainInfo record = resMainInfoService.selectByPrimaryKey(resourceid);
        String title = record.getTitle();
 
        // 获取申请类型列表
        LinkedHashMap<String, String> AppStatusList = FieldUtils.getFieldListByKey("ApplyStatus");
        // 获取用户对负责应用系统的资源申请,如果系统已经有该资源的权限,保存时提示
        LinkedHashMap<String, String> sysList =  getUserManagerSystemList(userid);
        if(sysList.size() > 0){
            AppStatusList.put("3","应用申请");
        }
        model.addAttribute("shenqin", sysList);
        //有效天数
        if(res_applyRecommend != null && res_applyRecommend.getEffendtime() != null && res_applyRecommend.getAppdate() != null){
            int day = (int)((res_applyRecommend.getEffendtime().getTime() - res_applyRecommend.getAppdate().getTime()) /1000*3600*24);
            res_applyRecommend.setEffendday(day);
        }
        // 获取资源使用方式列表
        LinkedHashMap<String, String> ResUseTypeList = FieldUtils.getFieldListByKey("ResUseType");
        model.addAttribute("resApplyRecommend", res_applyRecommend);
        model.addAttribute("AppStatusList", AppStatusList);
        model.addAttribute("ResUseTypeList", ResUseTypeList);
        model.addAttribute("title", title);
        model.addAttribute("appuser", chinesename);
        model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
        model.addAttribute("systemName", sysConfig.getAppFullName());
        return "ResManage/ResApplyRecommend/ZiYuanShenQing";
    }
 
 
    /**
     * 获取后台用户对负责应用系统列表
     * @param userid
     * @return
     */
    private LinkedHashMap<String, String> getUserManagerSystemList(Long userid) {
        LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
        List<SysSysteminfo> systemList = new ArrayList<SysSysteminfo>();
        try {
            String url = sysConfig.getApiServer() + "/api/sys/systeminfo/getSysListByUserId/" + userid;
            systemList = HttpOperateUtils.getJsonObjectArray(url, SysSysteminfo.class);
            if (systemList != null) {
                for (int i = 0; i < systemList.size(); i++) {
                    SysSysteminfo item = systemList.get(i);
                    map.put(item.getAppid().toString(), item.getAppfullname());
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return map;
    }
 
    /**
     * 查询申请资源列表功能
     */
    @ResponseBody
    @RequestMapping("/res/resApplyRecommend/selectShenQingZiYuanGD")
    public Result selectShenQingZiYuanGD(Res_MainInfo resMainInfo, PageBean pageBean, Integer auditresult) {
        Page<Res_MainInfo> page = PageHelper.startPage(pageBean.getPage(), pageBean.getLimit());
        MainInfoJoinApplyRecommend record = new MainInfoJoinApplyRecommend();
 
        record.setAppuserid(getUserId().toString());
        record.setTitle(resMainInfo.getTitle());
        record.setResourceclass(resMainInfo.getResourceclass());
        record.setPubdateBegin(resMainInfo.getPubdateBegin());
        record.setPubdatefinish(resMainInfo.getPubdatefinish());
        record.setAuditresult(auditresult);
        List<MainInfoJoinApplyRecommend> mainInfoJoinCatalogList = resApplyRecommendService.selectResMainInfoShenQingZiYuan(record);
        int countNums = (int) ((Page) mainInfoJoinCatalogList).getTotal();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        PageBean<MainInfoJoinApplyRecommend> pageData = new PageBean<>(pageBean.getPage(), pageBean.getLimit(),
                countNums);
        pageData.setItems(mainInfoJoinCatalogList);
        LinkedHashMap<String, String> ResourceTypeList = FieldUtils.getFieldListByKey("ResourceType");// 获取资源类型列表
        StringBuilder rsb = new StringBuilder();
        String leixin = "";
 
        List<Map<String, Object>> maps = new LinkedList<>();
        for (Integer i = 0; i < mainInfoJoinCatalogList.size(); i++) {
            leixin = ResourceTypeList.get(mainInfoJoinCatalogList.get(i).getResourceclass());
            Integer shenqingStatus = mainInfoJoinCatalogList.get(i).getAuditresult();
            String shenqingStatusStr = "";
            if(shenqingStatus != null) {
                switch (shenqingStatus) {
                    case 0:
                        shenqingStatusStr = "未批复";
                        break;
                    case 1:
                        shenqingStatusStr = "已通过";
                        break;
                    case 2:
                        shenqingStatusStr = "未通过";
                        break;
                }
            }
            else {
                shenqingStatusStr = "未批复";
            }
            String unitname = orgUnitService.getUnitName((long) mainInfoJoinCatalogList.get(i).getPubunitid());
            Map<String, Object> map = new HashMap<>();
            map.put("resourceid", mainInfoJoinCatalogList.get(i).getResourceid());
            map.put("appid", mainInfoJoinCatalogList.get(i).getAppid());
            map.put("title", mainInfoJoinCatalogList.get(i).getTitle());
            map.put("resourceclass", leixin);
            map.put("shenqingdate", sdf.format(mainInfoJoinCatalogList.get(i).getAppdate()));
            map.put("pubunitid", unitname);
            map.put("shenqingstatus", shenqingStatusStr);
            maps.add(map);
        }
        return Result.ok().put("totalCount", countNums).put("topics", maps);
    }
 
    // 申请资源导出
    @ResponseBody
    @RequestMapping("/res/resApplyRecommend/ShenQingZiYuanexcel")
    public String ShenQingZiYuanexcel(HttpServletResponse response, MainInfoJoinApplyRecommend resMainInfo) {
        MainInfoJoinApplyRecommend record = new MainInfoJoinApplyRecommend();
        record.setAppuserid(getUserId().toString());
        record.setTitle(resMainInfo.getTitle());
        record.setResourceclass(resMainInfo.getResourceclass());
        record.setPubdateBegin(resMainInfo.getPubdateBegin());
        record.setPubdatefinish(resMainInfo.getPubdatefinish());
        record.setAuditresult(resMainInfo.getAuditresult());
        List<MainInfoJoinApplyRecommend> mainInfoJoinCatalogList = resApplyRecommendService
                .selectResMainInfoShenQingZiYuan(record);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        LinkedHashMap<String, String> ResourceTypeList = FieldUtils.getFieldListByKey("ResourceType");// 获取资源类型列表
        StringBuilder rsb = new StringBuilder();
        String leixin = "";
        List<Map<String, Object>> maps = new LinkedList<>();
        for (Integer i = 0; i < mainInfoJoinCatalogList.size(); i++) {
            leixin = ResourceTypeList.get(mainInfoJoinCatalogList.get(i).getResourceclass());
            Integer shenqingStatus = mainInfoJoinCatalogList.get(i).getAuditresult();
            String shenqingStatusStr = "";
            if(shenqingStatus != null) {
                switch (shenqingStatus) {
                    case 0:
                        shenqingStatusStr = "未批复";
                        break;
                    case 1:
                        shenqingStatusStr = "已通过";
                        break;
                    case 2:
                        shenqingStatusStr = "未通过";
                        break;
                }
            }
            else {
                shenqingStatusStr = "未批复";
            }
            String unitname = orgUnitService.getUnitName((long) mainInfoJoinCatalogList.get(i).getPubunitid());
            Map<String, Object> map = new HashMap<>();
            map.put("resourceid", mainInfoJoinCatalogList.get(i).getResourceid());
            map.put("appid", mainInfoJoinCatalogList.get(i).getAppid());
            map.put("title", mainInfoJoinCatalogList.get(i).getTitle());
            map.put("resourceclass", leixin);
            map.put("shenqingdate", sdf.format(mainInfoJoinCatalogList.get(i).getAppdate()));
            map.put("pubunitid", unitname);
            map.put("shenqingstatus", shenqingStatusStr);
            maps.add(map);
        }
//        rsb.append("]}");
 
        String a[] = { "资源id", "资源名称", "资源类型", "发布单位", "申请时间", "批复状态" };
        try {
            String Filename = Excel.SQgoing(response, a, JSON.toJSONString(maps, SerializerFeature.WriteMapNullValue),sysConfig.getUploadPath()+"excel\\");
            String path2 = "/uploadPath/excel/";
            String desFile = path2 + Filename;
            System.out.println(desFile);
            return desFile;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
 
    /**
     * 资源推荐(个人、单位)
     * @param resourceid     资源ID
     * @param RecommendType  推荐方式(个人、单位)
     * @param idStr          推荐ID列表(个人、单位)
     * @return
     */
    @ResponseBody
    @RequestMapping("/res/resApplyRecommend/ResourceRecommend")
    public String resourceRecommend(int resourceid, int RecommendType, String idStr) {
        try {
            String[] idList = idStr.split("\\|");
            String[] list = new String[idList.length];
            // 获取当前时间
            Timestamp audittime = new Timestamp(new Date().getTime());
            // 删除已有推荐
            Res_ApplyRecommend entity = new Res_ApplyRecommend();
            entity.setResourceid(resourceid);
            entity.setApptype(RecommendType);
            List<Res_ApplyRecommend> res_applyRecommendList = resApplyRecommendService
                    .getRecommendListByResourceid(entity);
            for (Res_ApplyRecommend resApplyRecommend : res_applyRecommendList) {
                resApplyRecommendService.deleteByPrimaryKey(resApplyRecommend.getAppid());
            }
            // 新增现有推荐
            for (int i = 0; i < idList.length; i++) {
                if (list.equals(idList[i])) {
                    continue;
                } else {
                    list[i] = idList[i];
                    Res_ApplyRecommend resApplyRecommend = new Res_ApplyRecommend();
                    resApplyRecommend.setResourceid(resourceid);// 资源ID
                    if (RecommendType == 0) {
                        resApplyRecommend.setAppuserid(idList[i]); // 用户ID
                        resApplyRecommend.setAppunitid("-1"); // 单位ID(非空)
                    } else if (RecommendType == 1) {
                        resApplyRecommend.setAppuserid("-1"); // 用户ID(非空)
                        resApplyRecommend.setAppunitid(idList[i]); // 单位ID
                    }
                    resApplyRecommend.setApptype(RecommendType); // 推荐方式
                    resApplyRecommend.setAppdate(audittime); // 推荐时间
                    resApplyRecommend.setIsrecommend(1); // 是否推荐
 
                    resApplyRecommendService.insertSelective(resApplyRecommend);// 插入数据库
                }
            }
            // 获取推荐记录
            String userIds = "";
            String unitIds = "";
            Res_ApplyRecommend entitys = new Res_ApplyRecommend();
            entitys.setResourceid(resourceid);
            List<Res_ApplyRecommend> resApplyRecommendList = resApplyRecommendService
                    .getRecommendListByResourceid(entitys);
            for (Res_ApplyRecommend resApplyRecommend : resApplyRecommendList) {
                if (resApplyRecommend.getApptype() == 0) {
                    if (!userIds.isEmpty())
                        userIds += ",";
                    userIds += resApplyRecommend.getAppuserid();
                } else if (resApplyRecommend.getApptype() == 1) {
                    if (!unitIds.isEmpty())
                        unitIds += ",";
                    unitIds += resApplyRecommend.getAppunitid();
                }
            }
 
            return "{'success': true, 'msg': '', 'userIds': '" + userIds + "', 'unitIds': '" + unitIds + "'}";
        } catch (Exception e) {
            return "{'success': false, 'msg': '" + e.getMessage() + "'}";
        }
    }
 
    // ============================================================================
    // 后台管理
    // ============================================================================
 
    /**
     * 后台管理 - 列表页面
     */
    @RequestMapping("/res/manage/applyrecommend/index")
    public String index(Model model) {
        LinkedHashMap<String, String> applyStatusList = FieldUtils.getFieldListByKey("ApplyStatus");// 获取申请类型列表
        model.addAttribute("applyStatusList", applyStatusList);
        model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
        model.addAttribute("systemName", sysConfig.getAppFullName());
        return "manage/applyrecommend/index";
    }
 
    /**
     * 后台管理 - 获取列表
     */
    @ResponseBody
    @RequestMapping("/res/manage/applyrecommend/getlist")
    @LogAction("资源管理,申请批复,申请批复列表查询,查询")
    public Result getList(Res_ApplyRecommend resApplyRecommend, PageBean pageBean) throws IOException {
        PageHelper.startPage(pageBean.getPage(), pageBean.getLimit());
        // 查询当前登陆用户是否是超级管理员 是:查所有 不是:查自己的
        Boolean adminFlag=true;
        Subject subject = SecurityUtils.getSubject();
        if (!SecurityUtils.getSubject().isPermitted("org_user_admin")) {
            // 如果是超级管理员,不添加用户id,查询所有。如果不是 添加id 查询单个
            adminFlag=false;
            resApplyRecommend.setExistPermission(getUserId().toString());
//            resApplyRecommend.setExistPermission("4");
        }
        resApplyRecommend.setCreateuserid(Math.toIntExact(getUserId()));
        resApplyRecommend.setAudituserid(Math.toIntExact(getUserId()));
        List<MainInfoJoinApplyRecommendInfo> list = resApplyRecommendService.selectResApplyreCommend(resApplyRecommend);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        int countNums = (int) ((Page) list).getTotal();
        PageBean<MainInfoJoinApplyRecommendInfo> pageData = new PageBean<>(pageBean.getPage(), pageBean.getLimit(), countNums);
        pageData.setItems(list);
        LinkedHashMap<String, String> ApplyStatusList = FieldUtils.getFieldListByKey("ApplyStatus");// 获取申请类型列表
        OrgUser orgUser = getUser();
        Long userid = orgUser.getUserid();
        userid=null==userid?-1:userid;
        List<Map<String, Object>> maps = new LinkedList<>();
        for (Integer i = 0; i < list.size(); i++) {
            // 查询id对应的name
            String appusername = "";
            MainInfoJoinApplyRecommendInfo recommendInfo = list.get(i);
            if (recommendInfo.getAppuserid() != null) {
                OrgUser eobj = orgUserService.queryObject(Long.parseLong(recommendInfo.getAppuserid()));
                appusername = eobj != null ? (eobj.getChinesename() != null ?eobj.getChinesename():"") : "";
            }
            // 判断当前用户 与 资源用户是否一致 如果一致那么显示 是否批复
            Integer isDangQianYongHu = 0;
            Integer createuserid = recommendInfo.getCreateuserid();
            if (null!=createuserid && userid.toString().equals(createuserid.toString())) {
                isDangQianYongHu = 1;
            }
            if(adminFlag&&isDangQianYongHu==0){
                isDangQianYongHu=1;
            }
            Integer apptype = recommendInfo.getApptype();
            String apptypename = ApplyStatusList.get(apptype.toString());
            Map<String, Object> map = new HashMap<>();
            map.put("resourceid", recommendInfo.getResourceid());
            map.put("appid", recommendInfo.getAppid());
            map.put("title", recommendInfo.getTitle());
            map.put("appuserid", appusername);
            map.put("applycount", recommendInfo.getApplycount());
            map.put("auditresult", recommendInfo.getAuditresult());
            map.put("replycount", recommendInfo.getReplycount());
            map.put("insteadaudit", recommendInfo.getInsteadaudit());
            map.put("appdate", sdf.format(recommendInfo.getAppdate()));
            map.put("isDangQianYongHu", isDangQianYongHu);
            map.put("apptype", apptypename);
            map.put("appreason", (recommendInfo.getAppreason() != null ? recommendInfo.getAppreason() :""));
            String appDays = recommendInfo.getAppDays();
            if(null==appDays){
                if(apptype==0){
                    appDays="30";
                }
                if(apptype==1){
                    appDays="360";
                }if(apptype==3){
                    appDays="永久";
                }
            }
            //系统申请的特殊处理
            if(apptype==3){
                SysSysteminfo info=null;
                String sysId = recommendInfo.getSysId();
                if(StringUtils.isNotEmpty(sysId)){
                    String url = sysConfig.getApiServer() + "/api/sys/systeminfo/getSysteminfoById/" + sysId;
                    info = HttpOperateUtils.getJsonObject(url, SysSysteminfo.class);
                    map.put("insteadaudit",1); //委托管理员申请
                    map.put("isDangQianYongHu", isDangQianYongHu);
                    if(!StringUtils.equals(info.toString(),"{}")){
                        map.put("appSys", info.getAppfullname());
                    }else {
                        map.put("appSys",recommendInfo.getSysName());
                    }
                }else {
                    map.put("appSys",recommendInfo.getSysName());
                }
            }
            map.put("appDays",appDays);
            maps.add(map);
 
        }
        return Result.ok().put("totalCount", countNums).put("topics", maps);
    }
 
    /**
     * 后台管理 - 保存批复
     */
    @ResponseBody
    @RequestMapping("/res/manage/applyrecommend/save")
    @LogAction("资源管理,申请批复,申请批复信息新增,新增")
    public String save(Res_ApplyRecommend resApplyRecommend) {
        int result = 0;
        Timestamp audittime = new Timestamp(new Date().getTime());
        resApplyRecommend.setAudittime(audittime);
        resApplyRecommend.setAudituserid(getUserId().intValue());
        int updateresult = resApplyRecommendService.updateResApplyreCommendResult(resApplyRecommend);
        if (updateresult == 1) {
            result = 1;
        }
        return String.valueOf(result);
    }
 
    /**
     * 后台管理 - 查看申请理由
     */
    @RequestMapping("/res/manage/applyrecommend/content")
    public String content(Integer appid, Model model) {
        Res_ApplyRecommend applyRecommend = resApplyRecommendService.selectByPrimaryKey(appid);
        model.addAttribute("apply_ecommend", applyRecommend);
        return "manage/applyrecommend/content";
    }
 
    /**
     * 资源中心-查看资源申请详情
     */
    @RequestMapping("/res/resApplyRecommend/applyRecommendInfo")
    public String applyRecommendInfo(Integer appid, Model model) {
        Res_ApplyRecommend applyRecommend = resApplyRecommendService.selectByPrimaryKey(appid);
        //有效天数
        if(applyRecommend != null && applyRecommend.getEffendtime() != null && applyRecommend.getAppdate() != null){
            int day = (int)((applyRecommend.getEffendtime().getTime() - applyRecommend.getAppdate().getTime()) /(1000*3600*24));
            applyRecommend.setEffendday(day);
        }
        //申请日期
        String dateStr = "";
        if(applyRecommend != null && applyRecommend.getAppdate() != null){
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            dateStr = sdf.format(applyRecommend.getAppdate());
        }
        model.addAttribute("dateStr",dateStr);
        model.addAttribute("resApplyRecommend", applyRecommend);
        // 获取申请类型列表
        LinkedHashMap<String, String> AppStatusList = FieldUtils.getFieldListByKey("ApplyStatus");
        // 获取用户对负责应用系统的资源申请,如果系统已经有该资源的权限,保存时提示
        Long userid = getUser().getUserid();
        LinkedHashMap<String, String> sysList =  getUserManagerSystemList(userid);
        if(sysList.size() > 0){
            AppStatusList.put("3","应用申请");
        }
        model.addAttribute("sysList", sysList);
        model.addAttribute("AppStatusList", AppStatusList);
        model.addAttribute("appuser", getUser().getChinesename());
        model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
        model.addAttribute("systemName", sysConfig.getAppFullName());
        return "ResManage/ResApplyRecommend/ApplyRecommendInfo";
    }
 
    /**
     * 后台管理 - 对应应用程序的资源列表页面
     */
    @RequestMapping("/res/manage/applyrecommend/indexbysystem")
    public String indexbysystem(Model model, Integer appid) {
        LinkedHashMap<String, String> resourceTypeList = FieldUtils.getFieldListByKey("ResourceType");// 获取资源类型列表
        model.addAttribute("resourceTypeList", resourceTypeList);
        model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
        model.addAttribute("systemName", sysConfig.getAppFullName());
 
        //获取应用程序系统地址
        String systemUrl = "";
        try {
            String url = sysConfig.getApiServer() + "/api/sys/systeminfo/getSysteminfoById/" + appid;
            SysSysteminfo info = HttpOperateUtils.getJsonObject(url, SysSysteminfo.class);
            if (info != null) {
                systemUrl = info.getSysaddress();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        model.addAttribute("systemUrl",systemUrl);
        return "manage/applyrecommend/indexbysystem";
    }
 
    /**
     * 后台管理 - 获取对应应用程序的资源列表
     */
    @ResponseBody
    @RequestMapping("/res/manage/applyrecommend/getlistbysystem")
    public Result getlistbysystem(MainInfoJoinApplyRecommend mainInfoJoinApplyRecommend, PageBean pageBean) {
        PageHelper.startPage(pageBean.getPage(), pageBean.getLimit());
        // 查询当前登陆用户是否是超级管理员 是:查所有 不是:查自己的
        if (!SecurityUtils.getSubject().isPermitted("org_user_admin")) {
            // 如果是超级管理员,不添加用户id,查询所有。如果不是 添加id 查询单个
            mainInfoJoinApplyRecommend.setExistPermission( getUserId().toString());
        }
        List<MainInfoJoinApplyRecommend> list = resApplyRecommendService.selectResMainInfoBySysid(mainInfoJoinApplyRecommend);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        int countNums = (int) ((Page) list).getTotal();
        PageBean<MainInfoJoinApplyRecommend> pageData = new PageBean<>(pageBean.getPage(), pageBean.getLimit(),
                countNums);
        pageData.setItems(list);
        LinkedHashMap<String, String> ResourceTypeList = FieldUtils.getFieldListByKey("ResourceType");// 获取资源类型列表
        StringBuilder rsb = new StringBuilder();
        String leixin = "";
        rsb.append("{'totalCount':'" + countNums);
        rsb.append("','topics':[");
 
        List<Map<String, Object>> maps = new LinkedList<>();
        for (Integer i = 0; i < list.size(); i++) {
            leixin = ResourceTypeList.get(list.get(i).getResourceclass());
            String chinesename = orgUserService.getChinesename(list.get(i).getCreateuserid());
            String unitname = orgUnitService.getUnitName((long) list.get(i).getPubunitid());
            String appusername = "";
            if (list.get(i).getAppuserid() != null) {
                OrgUser eobj = orgUserService.queryObject(Long.parseLong(list.get(i).getAppuserid()));
                appusername = eobj != null ? eobj.getChinesename() : "";
            }
            String auditresult = "";
            if(list.get(i).getAuditresult() != null){
                if(list.get(i).getAuditresult() == 0){
                    auditresult = "待批复";
                }else if(list.get(i).getAuditresult() == 1){
                    auditresult = "已通过";
                }else{
                    auditresult = "未通过";
                }
            }
 
            Map<String, Object> map = new HashMap<>();
            map.put("resourceid", list.get(i).getResourceid());
            map.put("title", list.get(i).getTitle());
            map.put("mulu", GetBianMu(list.get(i).getCatlogid() == null ?
                    0 : list.get(i).getCatlogid()));
            map.put("resourceclass", leixin);
            map.put("pubdate", sdf.format(list.get(i).getPubdate()));
            map.put("pubunitid", unitname);
            map.put("createuserid", chinesename);
            map.put("appuserid", appusername);
            map.put("appdate", sdf.format(list.get(i).getAppdate()));
            map.put("auditresult", auditresult);
            map.put("audit", list.get(i).getAuditresult());
            maps.add(map);
        }
        return Result.ok().put("totalCount", countNums).put("topics", maps);
    }
 
    /**
     * 查询资源所属目录
     *
     * @param Catlogid
     * @return
     */
    private String GetBianMu(int Catlogid) {
        String str = "";
        strMuLu = "";
        if (Catlogid > 0) {
            Res_Catalog zymlBianMu = resCatalogService.selectByPrimaryKey(Catlogid);
            String str2 = CheckBianMu(zymlBianMu);
            String[] res = str2.split(">");
            for (int i = res.length - 1; i >= 0; i--) {
                if (i == 0) {
                    str += res[i];
                } else {
                    str += res[i] + " > ";
                }
            }
        }
        return str;
    }
 
    /**
     * 递归获取资源目录名称
     *
     * @param zymlBianMu
     * @return
     */
    private String CheckBianMu(Res_Catalog zymlBianMu) {
        if (zymlBianMu != null) {
            strMuLu += zymlBianMu.getTitle() + ">";
            if (zymlBianMu.getParentid() == 0) {
                return strMuLu;
            } else {
                zymlBianMu = resCatalogService.selectByPrimaryKey(zymlBianMu.getParentid());
                CheckBianMu(zymlBianMu);
            }
        }
        return strMuLu;
    }
 
    //选择资源
    @RequestMapping("/res/manage/applyrecommend/getSelectZiYuan")
    @ResponseBody
    public String getSelectZiYuan(String parentid, HttpServletRequest request,Integer sysid){
        Map<String, Object> map = new HashMap<>();
 
        List<Map<String, Object>> maps = new LinkedList<>();
        List<Map<String, Object>> chmaps = new LinkedList<>();
        if (parentid.indexOf("ZiYuan_") == -1) {
            map.put("parentid", Integer.valueOf(parentid));
            map.put("sysid", sysid);
            List<Res_Catalog> resCatalogList = resApplyRecommendService.selectCatalog(map);// 获取子目录列表
            // 循环构造子目录节点
 
            for (Res_Catalog resCatalog : resCatalogList) {
                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");
 
                // 获取资源类型列表
                List<Map<String, Object>> maps2 = new LinkedList<>();
                map.replace("parentid", resCatalog.getCatlogid());
                int isparent = resApplyRecommendService.selectCatalog(map).size();
                if(isparent > 0) {
//                    getSelectZiYuan(resCatalog.getCatlogid().toString(), request, sysid);
                    chmaps = (List) JSONArray.parseArray(getSelectZiYuan(resCatalog.getCatlogid().toString(), request, sysid));
                    if(chmaps.size() > 0) {
                        maps2.addAll(chmaps);
                    }
                }
                List<Res_MainInfo> resMainInfo = resApplyRecommendService.selectCatalogZiYuanList(map); // 获取目录下业务图层资源列表
                // 循环构造资源节点
                for (Res_MainInfo resMainInfo1 : resMainInfo) {
                    String unitname = orgUnitService.getUnitName((long) resMainInfo1.getPubunitid());
 
                    Map<String, Object> catlogmap2  = new HashMap<>();
                    catlogmap2.put("id", "ZiYuan_" + resMainInfo1.getResourceid());
                    catlogmap2.put("name", resMainInfo1.getTitle()+(unitname != null && unitname.length()>0?("("+unitname+")"):"" ));
                    catlogmap2.put("title", resMainInfo1.getTitle());
                    catlogmap2.put("isParent", false);
                    catlogmap2.put("icon", "/image/classicons/"+ resMainInfo1.getResourceclass() +".png");
                    maps2.add(catlogmap2);
                }
                catlogmap.put("children", maps2);
                maps.add(catlogmap);
            }
        }
        return JSON.toJSONString(maps, SerializerFeature.WriteMapNullValue);
    }
 
    /**
     * 获取选中的资源的地址
     */
    @RequestMapping("/res/manage/applyrecommend/getResourcesUrl")
    @ResponseBody
    public String getResourcesUrl(HttpServletResponse response, String resourceids,String sysUrl,Integer appid) {
        String[] ids = resourceids.split(",");
        StringBuilder rsb = new StringBuilder();
        String leixin = "";
 
        List<Map<String, Object>> maps = new LinkedList<>();
        for (Integer i = 0; i < ids.length; i++) {
            Res_MainInfo resMainInfo = resMainInfoService.selectByPrimaryKey(Integer.parseInt(ids[i]));
 
            //获取资源地址,多个默认取第一个
            String firstMapUrl = "";
            List<Res_ExtMapUrl> urlList = resExtMapUrlService.selectByCondition(resMainInfo.getResourceid());
            if (urlList != null && urlList.size() > 0 && urlList.get(0).getServerurl() != null) {
                firstMapUrl = urlList.get(0).getServerurl();
            }
            else {
                if(resMainInfo.getResourceclass().equals("JKFW")) {
                    Res_ExtInterFaceService res_extInterFaceService = resExtInterFaceService.selectByPrimaryKey(resMainInfo.getResourceid());
                    if(res_extInterFaceService != null) {
                        firstMapUrl = res_extInterFaceService.getServerurl() == null ? "null" : "\"" + res_extInterFaceService.getServerurl() + "\"";
                    }
                }
                if(resMainInfo.getResourceclass().equals("SJWJ")) {
                    Res_ExtFileSource resExtFileSource = resExtFileSourceService.selectByPrimaryKey(resMainInfo.getResourceid());
                    if(resExtFileSource != null) {
                        firstMapUrl = resExtFileSource.getServerurl() == null ? "null" : "\"" + resExtFileSource.getServerurl() + "\"";
                    }
                }
                if(resMainInfo.getResourceclass().equals("YWJC")) {
                    Res_ExtIntegrate resExtIntegrate = resExtIntegrateService.selectByPrimaryKey(resMainInfo.getResourceid());
                    if(resExtIntegrate != null) {
                        firstMapUrl = resExtIntegrate.getServerurl() == null ? "null" : "\"" + resExtIntegrate.getServerurl() + "\"";
                    }
                }
                if(resMainInfo.getResourceclass().equals("KJ_KJFX")) {
                    Res_ExtSpaceServer resExtSpaceServer = resExtSpaceServerService.selectByPrimaryKey(resMainInfo.getResourceid());
                    if(resExtSpaceServer != null) {
                        firstMapUrl = resExtSpaceServer.getServerurl() == null ? "null" : "\"" + resExtSpaceServer.getServerurl() + "\"";
                    }
                }
//                添加三维地形和三维影像 alert 2019/08/01
                if(resMainInfo.getResourceclass().equals("KJ_SWMX") || resMainInfo.getResourceclass().equals("KJ_SWDX") || resMainInfo.getResourceclass().equals("KJ_SWYX")) {
                    Res_Ext3D resExt3D = resExt3DService.selectByPrimaryKey(resMainInfo.getResourceid());
                    if(resExt3D != null) {
                        firstMapUrl = resExt3D.getServerurl() == null ? "null" : "\"" + resExt3D.getServerurl() + "\"";
                    }
                }
            }
 
            //获取Token值
            String token = "";
            String subzyids = "";
            String serverUrl = "null";
            //查询是否是专题地图,是专题地图则获取相关子图层ID
            if(resMainInfo.getResourceclass().equals("KJ_ZTDT")) {
                Res_ExtThemeMap resExtThemeMap = resExtThemeMapService.selectByPrimaryKey(Integer.parseInt(ids[i]));
                if (resExtThemeMap != null) {
                    subzyids = resExtThemeMap.getSublayerset();
                }
            }
            token = EsbToken.getAppEsbToken(getUserId().intValue(),appid,sysUrl,Integer.parseInt(ids[i]),resMainInfo.getEspproxy(),sysConfig,subzyids,resMainInfo.getToken());
            Map<String, Object> map = new HashMap<>();
            map.put("resourceid", resMainInfo.getResourceid());
            map.put("title", resMainInfo.getTitle());
            map.put("firstMapUrl", firstMapUrl);
            map.put("token", token);
            maps.add(map);
        }
 
        String a[] = {"资源id", "资源名称", "资源地址","Token"};
        try {
            String route = sysConfig.getUploadPath()+"excel\\";
            File file = new File(route);
            if(!file.exists()) {
                file.mkdirs();
            }
            String Filename = Excel.SystemUrlgoing(response, a, JSON.toJSONString(maps, SerializerFeature.WriteMapNullValue),route);
            String path2 = "/uploadPath/excel/";
            String desFile = path2 + Filename;
            return desFile;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
    @RequestMapping("/res/manage/applyrecommend/ziyuanapply")
    public String ziyuanapply(Model model, String ids,Integer sysid) {
        // 获取登录人姓名和登录人id和登录人部门id
        OrgUser user = getUser();
        String unitid = orgUserService.getDefaultUnit(user.getUserid()).getUnitid().toString();// user.getOrguserunits().get(0).getUnitid().toString();
        String chinesename = user.getChinesename();// entity.getChinesename();
        Long userid = user.getUserid();// entity.getUserid();
        Res_ApplyRecommend applyRecommend = new Res_ApplyRecommend();
        applyRecommend.setAppuserid(getUserId().toString());
        applyRecommend.setAppunitid((unitid));
        // 获取当前时间并转化为yyyy-MM-dd格式
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String newDate = sdf.format(new Date());
        model.addAttribute("Appdate", newDate);
        // 获取资源信息名称
        String[] idList = ids.split(",");
        String titles = "";
        if(idList!= null && idList.length >0){
            for (int i = 0; i < idList.length; i++) {
                if (titles != "") titles += ",";
                Res_MainInfo record = resMainInfoService.selectByPrimaryKey(Integer.valueOf(idList[i]));
                if (record != null) titles += record.getTitle();
            }
        }
        // 获取申请类型列表
        LinkedHashMap<String, String> AppStatusList = FieldUtils.getFieldListByKey("ApplyStatus");
        // 获取用户对负责应用系统的资源申请,如果系统已经有该资源的权限,保存时提示
        LinkedHashMap<String, String> sysList =  getUserManagerSystemList(userid);
        if(sysList.size() > 0){
            AppStatusList.put("3","应用申请");
        }
        model.addAttribute("shenqin", sysList);
        // 获取资源使用方式列表
        LinkedHashMap<String, String> ResUseTypeList = FieldUtils.getFieldListByKey("ResUseType");
        model.addAttribute("resApplyRecommend", applyRecommend);
        model.addAttribute("AppStatusList", AppStatusList);
        model.addAttribute("titles", titles);
        model.addAttribute("resourceids", ids);
        model.addAttribute("appuser", chinesename);
        model.addAttribute("sysid", sysid);
        model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot());
        model.addAttribute("systemName", sysConfig.getAppFullName());
        return "manage/applyrecommend/ziyuanapply";
    }
 
    @ResponseBody
    @RequestMapping("/res/manage/applyrecommend/saveZiYuansApply")
    public String saveZiYuansApply(Res_ApplyRecommend record, String resourceids) {
        String result = "";
        String[] idList = resourceids.split(",");
        if(idList!= null && idList.length >0){
            for (int i = 0; i < idList.length; i++) {
                record.setResourceid(Integer.valueOf(idList[i]));
                result = insertSelectiveAndUpdate(record,Long.parseLong(idList[i]),1);
            }
        }
        return result;
    }
 
    @ResponseBody
    @RequestMapping("/res/manage/applyrecommend/saveSysApply")
    public String saveSysApply(Res_ApplyRecommend record) throws IOException {
        record.setResourceid(0);
        record.setAppunitid("0");
        record.setAudituserid(4);
        String url = sysConfig.getApiServer() + "/api/sys/systeminfo/getSysteminfoById/" + record.getSysid();
        SysSysteminfo info = HttpOperateUtils.getJsonObject(url, SysSysteminfo.class);
        if(null!=info){
            record.setAudituserid(info.getMaguser());
        }
        insertSelectiveAndUpdate(record,0L,record.getSysid());
 
        return JSONUtils.toJSONString(Result.ok());
    }
 
    public static void main(String[] args) {
 
    }
 
}