ludc
2024-12-13 9d92bb1d5698690bfd06fb93c668d9ae73300426
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
package com.vci.web.service.impl;
 
import com.alibaba.fastjson.JSONObject;
import com.vci.common.exception.VciException;
import com.vci.corba.common.PLException;
import com.vci.corba.common.data.UserEntityInfo;
import com.vci.corba.framework.data.*;
import com.vci.corba.omd.data.BusinessObject;
import com.vci.corba.portal.data.PLUILayout;
import com.vci.dto.RoleInfoDTO;
import com.vci.dto.RoleRightParamDTO;
import com.vci.model.SmFunctionForPlatform1;
import com.vci.model.SmRoleForPlatform1;
import com.vci.omd.utils.ObjectTool;
import com.vci.pagemodel.MenuVO;
import com.vci.pagemodel.SmFunctionVO;
import com.vci.pagemodel.UIContentVO;
import com.vci.starter.web.constant.QueryOptionConstant;
import com.vci.starter.web.exception.VciBaseException;
import com.vci.starter.web.pagemodel.*;
import com.vci.starter.web.util.VciBaseUtil;
import com.vci.starter.web.wrapper.VciQueryWrapperForDO;
import com.vci.web.enumpck.ResourceControlTypeEnum;
import com.vci.web.properties.JsonConfigReader;
import com.vci.web.service.ISmFunctionQueryService;
import com.vci.web.service.UIEngineServiceI;
import com.vci.web.service.WebBoServiceI;
import com.vci.starter.web.util.Lcm.Func;
import com.vci.web.util.PlatformClientUtil;
import com.vci.web.util.RightControlUtil;
import com.vci.web.util.WebUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * 老平台的权限服务
 * @author weidy
 * @date 2020/3/1
 */
@Service
public class SmFunctionQueryServicePlatformImpl implements ISmFunctionQueryService {
 
    /**
     * 日志
     */
    private Logger logger = LoggerFactory.getLogger(getClass());
 
    /**
     * 菜单的根节点主键,这个是平台定义的
     */
    private final String ROOT_MENU_ID  = "modelManagmentNode";
 
    /**
     * 管理功能模块菜单根节点
     */
    private final String SYSTEMMANAGMENTNODE = "systemManagmentNode";
 
    /**
     * 操作类型管理菜单根节点
     */
    private final String OPERATENODE = "operateNode";
 
    /**
     * 使用用户查询
     */
    public static final String QUERY_BY_USER = "select r.PLFUNCOID from plroleright r left join pluserrole u on r.PLROLEOID = u.PLROLEUID ";
 
    /**
     * 业务数据服务
     */
    @Autowired
    private WebBoServiceI boService;
 
    /**
     * 加载自身
     */
    @Autowired(required = false)
    @Lazy
    private ISmFunctionQueryService self;
 
    @Autowired
    private  UIEngineServiceI uiEngineServiceI;
 
    @Autowired
    private PlatformClientUtil platformClientUtil;
 
    @Autowired
    RightControlUtil rightControlUtil;
 
    /**
     * 查询所有的功能
     *
     * @return 功能的显示对象
     */
    @Override
    public List<SmFunctionVO> selectAllFunction() {
        VciQueryWrapperForDO queryWrapper = new VciQueryWrapperForDO(null, SmFunctionForPlatform1.class);
        List<SmFunctionForPlatform1> functions = boService.selectByQueryWrapper(queryWrapper, SmFunctionForPlatform1.class);
        return functionForPlatform1ToFunctionDOs(functions);
    }
 
    /**
     * 查询所有的功能映射
     *
     * @return 功能的显示对象
     */
    @Override
    public Map<String, SmFunctionVO> selectAllFunctionMap() {
        return Optional.ofNullable(self.selectAllFunction()).orElseGet(()->new ArrayList<>()).stream().collect(Collectors.toMap(s->s.getOid(),t->t));
    }
 
    /**
     * 根据用户查询关联的权限
     *
     * @param userOid             用户的主键
     * @param queryMap            查询条件,如果要用用户的属性查询,可以使用pkUser.xxx
     * @param resourceControlTypeEnum 角色控制区域,也是功能控制的区域
     * @return 权限的显示对象,未转化为上下级关系
     */
    @Override
    public List<SmFunctionVO> listFunctionByUserOid(String userOid, Map<String, String> queryMap, ResourceControlTypeEnum resourceControlTypeEnum) {
        if(StringUtils.isBlank(userOid)){
            return new ArrayList<>();
        }
        VciQueryWrapperForDO queryWrapper = new VciQueryWrapperForDO(queryMap,SmFunctionForPlatform1.class);
        queryWrapper.in("ploid",QUERY_BY_USER + " where u.pluseruid = '" + userOid.trim() + "'");
        List<SmFunctionForPlatform1> functions = boService.selectByQueryWrapper(queryWrapper, SmFunctionForPlatform1.class);
        if(CollectionUtils.isEmpty(functions)){
            return new ArrayList<>();
        }
        //TODO 密级的控制
        //超级管理员,一般不让登录,登录后可以看业务的功能,也可以看管理功能
        //三员的,只看管理的
        //普通的只看业务的
 
        if(resourceControlTypeEnum == null){
            resourceControlTypeEnum = ResourceControlTypeEnum.BS;
        }
        String controlType = resourceControlTypeEnum.getValue();
        List<SmFunctionVO> functionVOS = functionForPlatform1ToFunctionDOs(functions);
        return functionVOS.stream().filter(s->controlType.equalsIgnoreCase(s.getResourceControlType())).collect(Collectors.toList());
    }
 
    /**
     * 根据用户返回所有菜单下的按钮(树形结构)
     *
     * @param treeQueryObject
     * @return
     */
    @Override
    public List<MenuVO> buttons(TreeQueryObject treeQueryObject) {
        //1、先根据session判断当前用户类型
        SessionInfo sessionInfo = WebUtil.getCurrentUserSessionInfoNotException();
        boolean adminOrDeveloperOrRoot = rightControlUtil.isAdminOrDeveloperOrRoot(sessionInfo.getUserId());
        String parentId;
        //2、根据不同用户返回不同的节点下的菜单和按钮
        if (adminOrDeveloperOrRoot) {
            //系统菜单
            parentId = SYSTEMMANAGMENTNODE;
        } else if (rightControlUtil.isThreeAdminCurUser()) {
            //三员返回管理功能模块相关的菜单
            parentId = SYSTEMMANAGMENTNODE;
        } else {
            // 普通用户只返回业务功能模块相关的菜单,
            // 但可能存在普通用户分配系统功能的菜单和按钮权限,不过需要
            // 再业务功能模块下创建对应的管理功能模块的菜单并进行授权。
            parentId = ROOT_MENU_ID;
        }
        RoleRightInfo[] userRoleRights = rightControlUtil.getRoleRightByUserName(sessionInfo.getUserId());
        //3、根据角色查询出对应的父节点下的所有的菜单,然后再获取菜单下的所有按钮
        //List<FunctionInfo>  menuList = rightControlUtil.getMenusByPIdAndPermission(parentId, sessionInfo.getUserId(),userRoleRights);
        Map<String, List<FunctionInfo>> map = rightControlUtil.getAllChildrenFunctionsByUserName(
                parentId, sessionInfo.getUserId(), userRoleRights);
        List<MenuVO> functionVOList = new ArrayList<>();
        //4、先获取parentid对应的菜单,再获取每一层子节点,同时过滤掉按钮未启用的功能模块
        for (FunctionInfo menu : map.get(parentId)) {
            if(!menu.isValid){
                continue;
            }
            MenuVO functionVO = new MenuVO();
            functionVO.setId(menu.id);
            functionVO.setSource(menu.image);
            functionVO.setPath(menu.resourceB);
            functionVO.setParentId(menu.parentId);
            functionVO.setCode(menu.aliasName);
            functionVO.setAlias(menu.aliasName);
            functionVO.setName(menu.name);
            functionVO.setFunctionType(menu.functionType);
            functionVO.setIsValid(menu.isValid);
            functionVO.getMeta().put("keepAlive",false);
            functionVO.setSort((int) menu.seq);
            try {
                functionVO.setChildren(findChildFunctionVO(menu.id, map));
            } catch (PLException e) {
                e.printStackTrace();
                String errorMsg = "菜单查询时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e);
                logger.error(errorMsg);
                throw new VciBaseException(errorMsg);
            }
            if(functionVO.getChildren().size() > 0){
                functionVO.setHasChildren(true);
            }else {
                functionVO.setHasChildren(false);
            }
            functionVOList.add(functionVO);
        }
        //6、过滤出实际的菜单节点
        List<MenuVO> menuVOList = new ArrayList<>();
        recursionFunction(functionVOList,menuVOList);
        // 5、处理每一个菜单下需要返回的按钮
        menuVOList.stream().forEach(menuVO -> {
            try {
                //6、获取当前菜单下的按钮
                Map<String, Long> authMap = Arrays.stream(userRoleRights).collect(Collectors.toMap(e -> e.funcId, e -> e.rightValue,
                        (existing, replacement) -> existing));
                menuVO.setChildren(getButtonsByAuth(menuVO.getId(),adminOrDeveloperOrRoot,authMap));
            } catch (PLException e) {
                e.printStackTrace();
                String errorMsg = "按钮查询时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e);
                logger.error(errorMsg);
                throw new VciBaseException(errorMsg);
            }
        });
        return menuVOList;
    }
 
    /**
     * 过滤出菜单只返回菜单节点
     * @param sourceList
     * @param targetList
     */
    private static void recursionFunction(List<MenuVO> sourceList, List<MenuVO> targetList) {
        for (MenuVO menu : sourceList) {
            // 检查functionType是否为0
            if (menu.getFunctionType() == 0) {
                targetList.add(menu);
            }
            // 递归处理children
            recursionFunction(menu.getChildren(), targetList);
        }
    }
 
    /**
     * 根据菜单主键和角色权限获取其下的按钮
     * @param parentOid
     * @return
     * @throws PLException
     */
    private List<MenuVO> getButtonsByAuth(String parentOid,boolean adminOrDeveloperOrRoot,Map<String, Long> authMap) throws PLException {
        List<MenuVO> buttonList = new ArrayList<>();
        if(Func.isBlank(parentOid)){
            return buttonList;
        }
        FuncOperationInfo[] funcOperates = platformClientUtil.getFrameworkService().getFuncOperationByModule(parentOid, "", true);
        List<FuncOperationInfo> funcOperationList = new ArrayList<>();
        if(!adminOrDeveloperOrRoot){
            for (int i = 0; i < funcOperates.length; i++) {
                if(authMap.containsKey(funcOperates[i].funcId)){
                    long rightValue = authMap.get(funcOperates[i].funcId);
                    long nodeValue = funcOperates[i].number;
                    long preValue = (rightValue >> nodeValue) & 1;
                    //进行位与操作,如果相等则表示具有当前操作的权限
                    if (preValue == 1) {
                        funcOperationList.add(funcOperates[i]);
                    }
                }
            }
        }else{
            funcOperationList = Arrays.asList(funcOperates);
        }
        if(Func.isNotEmpty(funcOperationList)){
            for(FuncOperationInfo info: funcOperationList){
                MenuVO menuVO = new MenuVO();
                menuVO.setChildType(0);
                menuVO.setId(info.id);
                menuVO.setFuncId(info.funcId);
                menuVO.setCode(info.operIndentify);
                menuVO.setOperId(info.operId);
                menuVO.setName(info.operName);
                menuVO.setAlias(info.operAlias);
                menuVO.setRemark(info.operDesc);
                menuVO.setSort((int) info.number);
                menuVO.setIsValid(info.isValid);
                menuVO.setHasChildren(false);
                menuVO.setCategory(1);
                menuVO.setFunctionType(2);
                buttonList.add(menuVO);
            }
        }
        return buttonList;
    }
 
    /**
     * 原平台功能转换为新平台的功能
     * @param functionForPlatform1List 原平台功能对象列表
     * @return 新平台功能对象
     */
    private List<SmFunctionVO> functionForPlatform1ToFunctionDOs(List<SmFunctionForPlatform1> functionForPlatform1List){
        List<SmFunctionVO> functionVOList = new ArrayList<SmFunctionVO>();
        if(!CollectionUtils.isEmpty(functionForPlatform1List)){
            for(int i = 0 ; i < functionForPlatform1List.size(); i ++ ) {
                functionVOList.add(functionForPlatform1ToFunctionVO(functionForPlatform1List.get(i)));
            }
        }
        return functionVOList;
    }
 
    /**
     * 原平台功能转换为新平台的功能
     *
     * @param functionForPlatform1 原平台功能对象
     * @return 新平台功能对象
     */
    private SmFunctionVO functionForPlatform1ToFunctionVO(SmFunctionForPlatform1 functionForPlatform1){
        SmFunctionVO functionVO = new SmFunctionVO();
        functionVO.setOid(functionForPlatform1.getPloid());
        //functionVO.setId(String.valueOf(functionForPlatform1.getPlmoduleno()));
        functionVO.setName(functionForPlatform1.getPlname());
        functionVO.setLogName(functionForPlatform1.getPlaliasname());
        if(StringUtils.isNotBlank(functionForPlatform1.getPlresourceb())){
            functionVO.setResourceControlType(ResourceControlTypeEnum.BS.getValue());
            functionVO.setUrl(functionForPlatform1.getPlresourceb());
        }else if(StringUtils.isNotBlank(functionForPlatform1.getPlresourcedotnet())) {
            functionVO.setResourceControlType(ResourceControlTypeEnum.DOTNET.getValue());
            functionVO.setUrl(functionForPlatform1.getPlresourcedotnet());
        }else if(StringUtils.isNotBlank(functionForPlatform1.getPlresourcemobil())) {
            functionVO.setResourceControlType(ResourceControlTypeEnum.MOBILE.getValue());
            functionVO.setUrl(functionForPlatform1.getPlresourcemobil());
        }else {
            functionVO.setResourceControlType(ResourceControlTypeEnum.CS.getValue());
            functionVO.setUrl(functionForPlatform1.getPlresourcec());
        }
        functionVO.setResourceControlTypeText(ResourceControlTypeEnum.getTextByValue(functionVO.getResourceControlType()));
        functionVO.setDisplayFlag((functionForPlatform1.getPlisvalid() !=null&& 1 == functionForPlatform1.getPlisvalid())? true:false);
        functionVO.setControlRightFlag(true);
        functionVO.setParentFunctionId(functionForPlatform1.getPlparentid());
        functionVO.setOrderNum(functionForPlatform1.getPlmodulesequence());
        if(StringUtils.isNotBlank(functionForPlatform1.getPlimage())) {
            functionVO.setIconCss(functionForPlatform1.getPlimage());
        }
        //以前的老图标没办法转换了,但是支持layui的图标
        if(StringUtils.isNotBlank(functionForPlatform1.getPldesc())){
            //需要在平台中设置菜单的图标路径,在描述字段中添加
            //{iconSrc:xxxx,desc:yyyy}
            try{
                JSONObject jo = JSONObject.parseObject(functionForPlatform1.getPldesc());
                if(jo!=null&&jo.containsKey("iconSrc")){
                    functionVO.setIconCss(jo.getString("iconSrc"));
                }
                if(jo!=null&&jo.containsKey("desc")){
                    functionVO.setDescription(jo.getString("desc"));
                }
            }catch(Exception e){
                functionVO.setDescription(functionForPlatform1.getPldesc());
            }
        }
 
        functionVO.setBtmname("function");
        //老的数据里创建人,最后修改人等都没有
        return functionVO;
    }
 
    /**
     * 获取当前角色的菜单
     *
     * @param treeQueryObject     属性查询对象
     * @param resourceControlTypeEnum 角色控制区域,也是功能控制的区域
     * @return 菜单,包含上下级
     */
    @Override
    public List<MenuVO> treeCurrentUserMenu(TreeQueryObject treeQueryObject, ResourceControlTypeEnum resourceControlTypeEnum) throws PLException {
        SessionInfo sessionInfo = WebUtil.getCurrentUserSessionInfoNotException();
        String parentId;
        boolean adminOrDeveloperOrRoot = rightControlUtil.isAdminOrDeveloperOrRoot(sessionInfo.getUserId());
        if (adminOrDeveloperOrRoot) {
            //系统菜单
            parentId = SYSTEMMANAGMENTNODE;
        } else if (rightControlUtil.isThreeAdminCurUser()) {
            //三员返回管理功能模块相关的菜单
            parentId = SYSTEMMANAGMENTNODE;
        } else {
            //普通用户只返回业务功能模块相关的菜单
            parentId = ROOT_MENU_ID;
        }
        RoleRightInfo[] userRoleRights = rightControlUtil.getRoleRightByUserName(sessionInfo.getUserId());
        Map<String, List<FunctionInfo>> map = rightControlUtil.getAllChildrenFunctionsByUserName(
                parentId, sessionInfo.getUserId(), userRoleRights);
 
        List<MenuVO> functionVOList = new ArrayList<>();
        if(Func.isEmpty(map.get(parentId))) {
            return functionVOList;
        }
        for (FunctionInfo menu : map.get(parentId)) {
            if(!menu.isValid){
                continue;
            }
            MenuVO functionVO = new MenuVO();
            functionVO.setId(menu.id);
            functionVO.setSource(menu.image);
            //if(StringUtils.isBlank(menu.resourceB)){
            //    continue;
            //}
            functionVO.setPath(menu.resourceB);
            functionVO.setParentId(menu.parentId);
            functionVO.setCode(menu.aliasName);
            functionVO.setAlias(menu.aliasName);
            functionVO.setName(menu.name);
            functionVO.getMeta().put("keepAlive",false);
            functionVO.setSort((int) menu.seq);
            try {
                functionVO.setChildren(findChildFunctionVO(menu.id, map));
            } catch (PLException e) {
                e.printStackTrace();
                String errorMsg = "菜单查询时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e);
                logger.error(errorMsg);
                throw new VciBaseException(errorMsg);
            }
            if(functionVO.getChildren().size() > 0){
                functionVO.setHasChildren(true);
            }else {
                functionVO.setHasChildren(false);
            }
            functionVOList.add(functionVO);
        }
        //如果是开发或者测试用户,需要获取系统模块配置菜单
        if(adminOrDeveloperOrRoot){
            //获取首页系统模块配置菜单
            MenuVO menuVO = JsonConfigReader.getSysModuleConf().getSysModuleNode();
            if(Func.isNotEmpty(menuVO)){
                functionVOList.add(menuVO);
            }
        }
        return functionVOList.stream().sorted(Comparator.comparing(s -> s.getSort())).collect(Collectors.toList());
    }
 
    /**
     * 通过模块ID获取子级列表
     * @param parentId
     * @param modeType 模块类型
     * @param isAll 是否包括无效的模块,true则包括
     * @return
     * @throws VciBaseException
     */
    @Override
    public List<MenuVO> getSysModelTreeMenuByPID(String parentId,String modeType,boolean isAll) throws VciBaseException{
        List<MenuVO> menuVOList = new ArrayList<>();
        if(Func.isBlank(parentId)){
            return menuVOList;
        }
        boolean isFunctionObject = Func.isNotBlank(modeType) && modeType.equalsIgnoreCase("FunctionObject");
        if(parentId.equals("systemManagmentNode") || parentId.equals("modelManagmentNode") || isFunctionObject){
            int childType = this.checkChildObject(parentId);
            if(isFunctionObject){
                try {
                    /**判断该模块下子对象是模块还是操作,0表示无子节点,1表示是模块,2表示是操作**/
                    if(childType == 2){
                        try{
                            FuncOperationInfo[] infos = platformClientUtil.getFrameworkService().getFuncOperationByModule(parentId, "", false);
                            if(Func.isNotEmpty(infos)){
                                childType = this.checkChildObject(infos[0].id); //都是同一层所以取第一个即可查询是什么类型
                                for(int i = 0;i < infos.length ;i++){
                                    FuncOperationInfo info = infos[i];
                                    MenuVO menuVO = new MenuVO();
                                    menuVO.setChildType(childType);
                                    menuVO.setId(info.id);
                                    menuVO.setFuncId(info.funcId);
                                    menuVO.setCode(info.operIndentify);
                                    menuVO.setOperId(info.operId);
                                    menuVO.setName(info.operName);
                                    menuVO.setAlias(info.operAlias);
                                    menuVO.setRemark(info.operDesc);
                                    menuVO.setSort((int) info.number);
                                    menuVO.setModeType("FunctionObject");
                                    menuVO.setIsValid(info.isValid);
                                    menuVO.setHasChildren(false);
                                    menuVO.setCategory(1);
                                    menuVO.setFunctionType(3);
                                    menuVOList.add(menuVO);
                                }
                            }
                        }catch (PLException e) {
                            e.printStackTrace();
                            throw new VciBaseException(String.valueOf(e.code), e.messages);
                        }
                    }else if(childType == 1){
                        try{
                            FunctionInfo[] funcInfos = platformClientUtil.getFrameworkService().getModuleListByParentId(parentId, isAll);
                            if(Func.isNotEmpty(funcInfos.length)){
                                childType = this.checkChildObject(funcInfos[0].id); //都是同一层所以取第一个即可查询是什么类型
                                for(int i = 0;i < funcInfos.length; i++){
                                    FunctionInfo funcInfo = funcInfos[i];
                                    MenuVO menuVO = this.functionInfoToMenuVO(funcInfo);
                                    menuVO.setChildType(childType);
                                    menuVO.setModeType("FunctionObject");
                                    menuVO.setCategory(0);
                                    menuVOList.add(menuVO);
                                }
                            }
                        }catch (PLException e) {
                            e.printStackTrace();
                            throw new VciBaseException(String.valueOf(e.code),e.messages);
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    throw new VciBaseException("模块查询时出现错误,原因:"+VciBaseUtil.getExceptionMessage(e));
                }
            }else{
                try{
                    MenuVO parentNode = null;
                    //将返回的节点外层套上当前父节点
                    if("systemManagmentNode".equals(parentId)){
                        parentNode = JsonConfigReader.getSysModuleConf().getSystemManagmentNode();
                    }else if("modelManagmentNode".equals(parentId)){
                        parentNode = JsonConfigReader.getSysModuleConf().getModelManagmentNode();
                    }
                    //如果查询的是第一层节点就需要直接返回systemManagmentNode或modelManagmentNode节点
                    if(Func.isNotBlank(modeType) && modeType.equals("firstNode")){
                        menuVOList.add(parentNode);
                        return menuVOList;
                    }
                    //查询的三级节点
                    FunctionInfo[] funcInfos = platformClientUtil.getFrameworkService().getModuleListByParentId(parentId, isAll);
                    for(int i = 0;i < funcInfos.length; i++){
                        FunctionInfo funcInfo = funcInfos[i];
                        MenuVO menuVO = this.functionInfoToMenuVO(funcInfo);
                        menuVO.setModeType("FunctionObject");
                        childType = this.checkChildObject(funcInfos[i].id);
                        menuVO.setChildType(childType);
                        menuVO.setCategory(0);
                        menuVOList.add(menuVO);
                    }
                    return menuVOList;
                }catch (PLException e) {
                    e.printStackTrace();
                    throw new VciBaseException(String.valueOf(e.code),e.messages);
                }
            }
        }else if(parentId.equals("operateNode")){
            //加载所有操作
            try{
                //将返回的节点外层套上当前父节点
                MenuVO parentNode = JsonConfigReader.getSysModuleConf().getOperateNode();
                //如果查询的是第一层节点就需要直接返回sysOptionNode节点
                if(Func.isNotBlank(modeType) && modeType.equals("firstNode")){
                    menuVOList.add(parentNode);
                    return menuVOList;
                }
                OperateInfo[] operateInfos = platformClientUtil.getFrameworkService().getOperateTreeList(parentId);
                for(int i = 0; i < operateInfos.length;i++ ){
                    OperateInfo operateInfo = operateInfos[i];
                    MenuVO menuVO = new MenuVO();
                    menuVO.setId(operateInfo.id);
                    menuVO.setName(operateInfo.name);
                    menuVO.setCode(operateInfo.identify);
                    menuVO.setAlias(operateInfo.alias);
                    menuVO.setCategory(1);
                    menuVO.setFunctionType(2);
                    menuVO.setChildType(0);
                    menuVO.setRemark(operateInfo.desc);
                    menuVO.getMeta().put("keepAlive",false);
                    menuVO.setSort((int) operateInfo.seq);
                    menuVO.setModeType("operateObject");
                    menuVO.setHasChildren(false);
                    menuVOList.add(menuVO);
                }
            }catch (PLException e) {
                e.printStackTrace();
                throw new VciBaseException(String.valueOf(e.code),new String[]{VciBaseUtil.getExceptionMessage(e)});
            }
        }
        return menuVOList.stream().sorted(Comparator.comparing(s -> s.getSort())).collect(Collectors.toList());
    }
 
    /**
     * functionInfo转VO对象
     * @param funcInfo
     * @return
     */
    private MenuVO functionInfoToMenuVO(FunctionInfo funcInfo) {
        MenuVO menuVO = new MenuVO();
        menuVO.setId(funcInfo.id);
        menuVO.setIsValid(funcInfo.isValid);
        menuVO.setSource(funcInfo.image);
        menuVO.setFunctionType(funcInfo.functionType);
        menuVO.setPathC(funcInfo.resourceC);
        menuVO.setResourceDotNet(funcInfo.resourceDotNet);
        menuVO.setResourceMobile(funcInfo.resourceMobile);
        menuVO.setPath(funcInfo.resourceB);
        menuVO.setParentId(funcInfo.parentId);
        menuVO.setCode(funcInfo.aliasName);
        menuVO.setAlias(funcInfo.aliasName);
        menuVO.setName(funcInfo.name);
        menuVO.getMeta().put("keepAlive",false);
        menuVO.setSort((int) funcInfo.seq);
        if(this.checkChildObject(menuVO.getId()) == 0){
            menuVO.setHasChildren(false);
        }else{
            menuVO.setHasChildren(true);
        }
        return menuVO;
    }
 
    /**
     * 通过模块ID检查该模块子级对象是模块还是操作
     * @param moduleId
     * @return 0表示没有模块也没有操作,1表示有模块,2表示有操作
     * @throws VciException
     */
    @Override
    public int checkChildObject(String moduleId) throws VciBaseException {
        long res = 0;
        try{
            res = platformClientUtil.getFrameworkService().checkChildObject(moduleId);
        }catch (PLException e) {
            e.printStackTrace();
            throw new VciBaseException(String.valueOf(e.code),e.messages);
        }
        return (int)res;
    }
 
    public List<MenuVO> findChildFunctionVO(String parentOid,Map<String, List<FunctionInfo>> map) throws PLException {
        List<FunctionInfo> menus = map.get(parentOid);
        List<MenuVO> functionVOList = new ArrayList<>();
        if(menus == null){
            return functionVOList;
        }
        for (FunctionInfo menu : menus) {
            if(!menu.isValid){
                continue;
            }
            MenuVO functionVO = new MenuVO();
            functionVO.setId(menu.id);
            functionVO.setSource(menu.image);
            functionVO.setFunctionType(menu.functionType);
            functionVO.setIsValid(menu.isValid);
            functionVO.setPath(menu.resourceB);
            functionVO.setCode(menu.aliasName);
            functionVO.setAlias(menu.aliasName);
            functionVO.setParentId(menu.parentId);
            functionVO.setName(menu.name);
            functionVO.getMeta().put("keepAlive",false);
            functionVO.setSort((int) menu.seq);
            functionVO.setChildren(findChildFunctionVO(menu.id,map));
            if(functionVO.getChildren().size() > 0){
                functionVO.setHasChildren(true);
            }else {
                functionVO.setHasChildren(false);
            }
            functionVOList.add(functionVO);
        }
        return functionVOList.stream().sorted(Comparator.comparing(s -> s.getSort())).collect(Collectors.toList());
    }
 
    public void findChildAuthFunctionVO(MenuVO functionVO, boolean isAll) throws PLException {
        //0表示没有模块也没有操作,1表示有模块,2表示有操作
        long type = platformClientUtil.getFrameworkService().checkChildObject(functionVO.getId());
        if(type == 1){
            FunctionInfo[] funcObjs = platformClientUtil.getFrameworkService().getModuleListByParentId(functionVO.getId(), isAll);
            for (FunctionInfo funcObj : funcObjs) {
                MenuVO menuVO = new MenuVO();
                menuVO.setId(funcObj.id);
                menuVO.setSource(funcObj.image);
                menuVO.setPath(funcObj.resourceB);
                menuVO.setCode(funcObj.aliasName);
                menuVO.setAlias(funcObj.aliasName);
                menuVO.setParentId(funcObj.parentId);
                menuVO.setChildType((int) type);
                menuVO.setName(funcObj.name);
                menuVO.getMeta().put("keepAlive",false);
                menuVO.setSort((int) funcObj.seq);
                findChildAuthFunctionVO(menuVO, isAll);
                functionVO.getChildren().add(menuVO);
                functionVO.setHasChildren(true);
            }
        }else if(type == 2){
            FuncOperationInfo[] infos = platformClientUtil.getFrameworkService().getFuncOperationByModule(functionVO.getId(), "", true);
            for (FuncOperationInfo info : infos) {
                MenuVO menuVO = new MenuVO();
                menuVO.setChildType((int) type);
                menuVO.setId(info.id);
                menuVO.setFuncId(info.funcId);
                menuVO.setCode(info.operIndentify);
                menuVO.setOperId(info.operId);
                menuVO.setName(info.operName);
                menuVO.setAlias(info.operAlias);
                menuVO.setRemark(info.operDesc);
                menuVO.setSort((int) info.number);
                menuVO.setModeType("FunctionObject");
                menuVO.setIsValid(info.isValid);
                menuVO.setHasChildren(false);
                functionVO.getChildren().add(menuVO);
                functionVO.setHasChildren(true);
            }
        }else{
            functionVO.setHasChildren(false);
        }
    }
 
    @Override
    public UIContentVO getUIContentByBtmTypeAndId(TreeQueryObject treeQueryObject, ResourceControlTypeEnum resourceControlTypeEnum) throws PLException {
        SessionInfo sessionInfo = WebUtil.getCurrentUserSessionInfoNotException();
        if(resourceControlTypeEnum == null){
            resourceControlTypeEnum = ResourceControlTypeEnum.BS;
        }
        for (PLUILayout allPLUILayout : platformClientUtil.getUIService().getAllPLUILayouts()) {
            if(treeQueryObject.getConditionMap().getOrDefault("type","").equals(allPLUILayout.plRelatedType)
                    && treeQueryObject.getConditionMap().getOrDefault("context","").equals(allPLUILayout.plCode)){
                return uiEngineServiceI.UIContentDO2VO(allPLUILayout,true);
            }
        }
        return null;
    }
 
    /**
     * 获取授权的模块
     * @param roleId 角色主键
     * @return 所具有权限的主键
     * @throws PLException
     */
    @Override
    public List<String> getSysModelAuth(String roleId) throws PLException {
 
        RoleRightInfo[] roleRightList = platformClientUtil.getFrameworkService().getRoleRightList(roleId, WebUtil.getCurrentUserId());
        Map<String, Long> authMap = Arrays.stream(roleRightList).collect(Collectors.toMap(e -> e.funcId, e -> e.rightValue,
                (existing, replacement) -> existing));
        String parentId;
        SessionInfo sessionInfo = WebUtil.getCurrentUserSessionInfoNotException();
        boolean adminOrDeveloperOrRoot = rightControlUtil.isAdminOrDeveloperOrRoot(sessionInfo.getUserId());
        if (adminOrDeveloperOrRoot) {
            //系统菜单
            parentId = SYSTEMMANAGMENTNODE;
        } else {
            //普通用户只返回业务功能模块相关的菜单
            parentId = ROOT_MENU_ID;
        }
        FunctionInfo[] moduleListByParentId = getModuleListByParentId(parentId, false);
        List<String> authList = new ArrayList<>();
        for (FunctionInfo functionInfo : moduleListByParentId) {
            if(authMap.containsKey(functionInfo.id)){
                // authList.add(functionInfo.id);
                getChildAuthNode(functionInfo, authMap, authList);
            }
        }
        return authList;
    }
 
    public BaseResult saveRoleRight(List<RoleRightParamDTO> roleRightDTOS, String roleId) throws PLException {
        /**
         * 存储需要保存的权限
         */
        Map<String,RoleRightInfo> rightMap = new HashMap<String,RoleRightInfo>();
 
        Map<String, List<RoleRightParamDTO>> parentMap = roleRightDTOS.stream().collect(Collectors.groupingBy(e -> e.parentId));
 
        for (RoleRightParamDTO dto : roleRightDTOS) {
            RoleRightInfo obj = null;
            //判断类型
            if(dto.getType() == 1 && !dto.getParentId().equals(ROOT_MENU_ID)
                    && !dto.getParentId().equals(SYSTEMMANAGMENTNODE)
                    && !dto.getParentId().equals(OPERATENODE)){
                if(!rightMap.containsKey(dto.getParentId())){
                    obj = new RoleRightInfo();
                    obj.funcId = dto.getParentId();
                    obj.rightType = (short)1;
                    obj.rightValue = 1;//没有操作的模块权限值存储为0
                    obj.roleId = roleId;
                    obj.createUser = WebUtil.getCurrentUserId();
                    obj.createTime = new Date().getTime();
                    obj.modifyUser = WebUtil.getCurrentUserId();
                    obj.modifyTime = new Date().getTime();
                    obj.licensor = "";
                }else{
                    obj = rightMap.get(dto.getParentId());
                    if (obj == null) {
                        obj = new RoleRightInfo();
                        obj.funcId = dto.getParentId();
                        obj.rightType = (short)1;
                        obj.rightValue = 1;//没有操作的模块权限值存储为0
                        obj.roleId = roleId;
                        obj.createUser = WebUtil.getCurrentUserId();
                        obj.createTime = new Date().getTime();
                        obj.modifyUser = WebUtil.getCurrentUserId();
                        obj.modifyTime = new Date().getTime();
                        obj.licensor = "";
                    }else {
                        obj.rightValue = 1;
                    }
                }
                rightMap.put(dto.getParentId(), obj);
            }else if (dto.getType() == 2){
//                RoleRightInfo roleRightObj = new RoleRightInfo();
                if(!rightMap.containsKey(dto.getParentId())) {
                    obj = new RoleRightInfo();
                    obj.funcId = dto.getParentId();
                    obj.rightType = (short)1;
                    obj.rightValue = countRightValue(parentMap.get(dto.getParentId()));//没有操作的模块权限值存储为0
                    obj.roleId = roleId;
                    obj.createUser = WebUtil.getCurrentUserId();
                    obj.createTime = new Date().getTime();
                    obj.modifyUser = WebUtil.getCurrentUserId();
                    obj.modifyTime = new Date().getTime();
                    obj.licensor = "";
                    rightMap.put(dto.getParentId(), obj);
                }
 
            }
        }
        /**上面处理完成后,循环遍历取出MAP里的对象进行保存**/
        RoleRightInfo[] roleRightObjs =    new RoleRightInfo[rightMap.size()];
        Set<String> objSet = rightMap.keySet();
        Iterator<String> it = objSet.iterator();
        int i = 0;
        while(it.hasNext()){
            roleRightObjs[i++] = rightMap.get(it.next());
        }
        UserEntityInfo userEntityInfo = new UserEntityInfo();
        userEntityInfo.setModules("com.vci.client.framework.rightdistribution.roleRight.RoleRightPanel");
        userEntityInfo.setUserName(WebUtil.getCurrentUserId());
        boolean res =  platformClientUtil.getFrameworkService()
                .saveRoleRight(roleRightObjs,roleId,WebUtil.getCurrentUserId(), userEntityInfo);
        if(!res){
            throw new PLException("500", new String[]{"功能模块授权失败!"});
        }
        return BaseResult.success();
    }
 
    /**
     * 获取所授权的模块权限
     * @param roleName 搜索的角色
     * @return 角色列表
     */
    @Override
    public List<RoleInfoDTO> getRoleList(String roleName) throws PLException {
        RoleInfo[] roleInfos = platformClientUtil.getFrameworkService().fetchRoleInfoByUserType(WebUtil.getCurrentUserId());
        List<RoleInfoDTO> dtos = new ArrayList<>();
        for (RoleInfo roleInfo : roleInfos) {
            if(StringUtils.isBlank(roleName) || roleInfo.name.indexOf(roleName) != -1) {
                RoleInfoDTO dto = new RoleInfoDTO();
                dto.setName(roleInfo.name);
                dto.setDescription(roleInfo.description);
                dto.setId(roleInfo.id);
                dto.setGrantor(roleInfo.grantor);
                dto.setType(roleInfo.type);
                dto.setCreateTime(roleInfo.createTime);
                dto.setCreateUser(roleInfo.createUser);
                dto.setUpdateTime(roleInfo.updateTime);
                dto.setUpdateUser(roleInfo.updateUser);
                dtos.add(dto);
            }
        }
        return dtos;
    }
 
    private long countRightValue(List<RoleRightParamDTO> dtos){
        long value = 0;
        for (RoleRightParamDTO dto : dtos) {
            value += (long)Math.pow(2, dto.getNumber());//累计加上各个操作的权限值
        }
        return value;
    }
 
    /**
     *
     * @param funcObj 模块对象
     * @param authMap 该角色下所有的权限数据
     * @param authList 该角色下所具有的权限
     * @throws PLException
     */
    private void getChildAuthNode(FunctionInfo funcObj, Map<String, Long> authMap, List<String> authList) throws PLException {
        /**0表示该模块下什么都没有,1表示有模块,2表示有操作**/
        long funcType = platformClientUtil.getFrameworkService().checkChildObject(funcObj.id);
        if(funcType == 1){
            FunctionInfo[] funcInfos = platformClientUtil.getFrameworkService().getModuleListByParentId(funcObj.id, false);
            for(int i=0;i<funcInfos.length;i++){
                if(authMap.containsKey(funcInfos[i].id)){
//                    authList.add(funcInfos[i].id);
                    getChildAuthNode(funcInfos[i], authMap, authList);
                }
            }
        }else if(funcType == 2){
            FuncOperationInfo[] funcOperates = platformClientUtil.getFrameworkService().getFuncOperationByModule(funcObj.id, "", true);
            for (int j = 0; j < funcOperates.length; j++) {
                if(authMap.containsKey(funcOperates[j].funcId)){
                    long rightValue = authMap.get(funcOperates[j].funcId);
                    long nodeValue = funcOperates[j].number;
                    long preValue = (rightValue >> nodeValue) & 1;
                    //进行位与操作,如果相等则表示具有当前操作的权限
                    if (preValue == 1) {
                        authList.add(funcOperates[j].id);
                    }
                }
            }
        }
    }
 
    /**
     * 获取所有的功能菜单
     *
     * @param treeQueryObject     树查询对象
     * @param resourceControlTypeEnum 角色控制区域,也是功能控制的区域
     * @return 树节点,出现错误会在异常处理器中统一返回Json
     */
    @Override
    public List<Tree> treeAllMenu(TreeQueryObject treeQueryObject, ResourceControlTypeEnum resourceControlTypeEnum) {
        List<SmFunctionVO> functionVOList = self.selectAllFunction().stream().filter(s -> s.isDisplayFlag() && resourceControlTypeEnum.getValue().equalsIgnoreCase(s.getResourceControlType())).collect(Collectors.toList());
        if(!treeQueryObject.isQueryAllLevel() && StringUtils.isNotBlank(treeQueryObject.getParentOid())){
            functionVOList = functionVOList.stream().filter(s->treeQueryObject.getParentOid().equalsIgnoreCase(s.getParentFunctionId())).collect(Collectors.toList());
        }
        return dos2Trees(functionVOList.stream().sorted(Comparator.comparing(s -> s.getOrderNum())).collect(Collectors.toList()),treeQueryObject == null?null:treeQueryObject.getParentOid());
    }
 
    /**
     * 批量将数据对象转换为树节点
     * @param functionVOList 数据对象列表
     * @param rootId 根节点的主键,最顶层使用null或者""
     * @return 树节点列表,不存在数据时返回空列表
     */
    public List<Tree> dos2Trees(List<SmFunctionVO> functionVOList,String rootId){
        if(!CollectionUtils.isEmpty(functionVOList)) {
            List<Tree> rootList = new ArrayList<>();
            List<Tree> childList = new ArrayList<>();
            functionVOList.stream().forEach(s -> {
                Tree tree = DO2Tree(s);
                if (tree.getParentId() == null || tree.getParentId().equals(rootId) || ROOT_MENU_ID.equalsIgnoreCase(tree.getParentId())) {
                    rootList.add(tree);
                } else {
                    childList.add(tree);
                }
            });
            return Tree.getChildList(rootList, childList);
        }else{
            return  new ArrayList<>();
        }
    }
 
    /**
     * 数据对象转换为树节点
     * @param functionVO 数据显示对象
     * @return 树节点对象
     */
    public Tree DO2Tree(SmFunctionVO functionVO){
        Tree tree = new Tree();
        tree.setOid(functionVO.getOid());
        tree.setText(functionVO.getName());
        tree.setIndex(functionVO.getOrderNum() + "");
        tree.setParentId(functionVO.getParentFunctionId());
        tree.setIconCls(functionVO.getIconCss());
        tree.setHref(functionVO.getUrl());
        try {
            tree.setAttributes(WebUtil.objectToMapString(functionVO));
        } catch (Throwable e) {
            logger.error("拷贝信息",e);
        }
        return tree;
    }
 
    /**
     * 通过上级节点获取下级的所有的菜单节点
     *
     * @param treeQueryObject     树查询对象
     * @param resourceControlTypeEnum 角色控制区域,也是功能控制的区域
     * @return 树节点,出现错误会在异常处理器中统一返回Json
     */
    @Override
    public List<Tree> treeFunctionByParent(TreeQueryObject treeQueryObject, ResourceControlTypeEnum resourceControlTypeEnum) {
         List<SmFunctionVO> functionVOList = self.selectAllFunction().stream().filter(s -> s.isDisplayFlag() && resourceControlTypeEnum.getValue().equalsIgnoreCase(s.getResourceControlType())).collect(Collectors.toList());
         if(!treeQueryObject.isQueryAllLevel() && StringUtils.isNotBlank(treeQueryObject.getParentOid())){
             functionVOList = functionVOList.stream().filter(s->treeQueryObject.getParentOid().equalsIgnoreCase(s.getParentFunctionId())).collect(Collectors.toList());
         }
         return dos2Trees(functionVOList,treeQueryObject == null?null:treeQueryObject.getParentOid());
    }
 
    /**
     * 通过上级节点获取当前角色有权限的下级的所有的菜单节点
     *
     * @param treeQueryObject     树查询对象
     * @param resourceControlTypeEnum 角色控制区域,也是功能控制的区域
     * @return 树节点,出现错误会在异常处理器中统一返回Json
     */
    @Override
    public List<Tree> treeCurrentFunctionByParent(TreeQueryObject treeQueryObject, ResourceControlTypeEnum resourceControlTypeEnum) {
        SessionInfo sessionInfo = WebUtil.getCurrentUserSessionInfo();
         List<SmFunctionVO> functionVOList =self.selectAllFunction().stream().filter(s -> s.isDisplayFlag()
                 && resourceControlTypeEnum.getValue().equalsIgnoreCase(s.getResourceControlType())
                 && !CollectionUtils.isEmpty(sessionInfo.getFunctionOids())
                 && sessionInfo.getFunctionOids().contains(s.getOid())
                 ).collect(Collectors.toList());
         if(!treeQueryObject.isQueryAllLevel() && StringUtils.isNotBlank(treeQueryObject.getParentOid())){
             functionVOList = functionVOList.stream().filter(s->treeQueryObject.getParentOid().equalsIgnoreCase(s.getParentFunctionId())).collect(Collectors.toList());
         }
         return dos2Trees(functionVOList,treeQueryObject == null?null:treeQueryObject.getParentOid());
    }
 
    /**
     * 获取系统功能列表
     *
     * @param queryMap   查询条件
     * @param pageHelper 排序和分页对象
     * @return DataGrid 系统功能列表
     */
    @Override
    public DataGrid<SmFunctionVO> dataGrid(Map<String, String> queryMap, PageHelper pageHelper) {
        VciQueryWrapperForDO queryWrapperForDO = new VciQueryWrapperForDO(queryMap,SmFunctionForPlatform1.class,pageHelper);
        List<SmFunctionForPlatform1> functionForPlatform1s = boService.selectByQueryWrapper(queryWrapperForDO, SmFunctionForPlatform1.class);
        List<SmFunctionVO> functionVOS = functionForPlatform1ToFunctionDOs(functionForPlatform1s);
        DataGrid dataGrid = new DataGrid();
        dataGrid.setData(functionVOS);
        if(!CollectionUtils.isEmpty(functionVOS)){
            dataGrid.setTotal(boService.countByQueryWrapper(queryWrapperForDO,SmFunctionForPlatform1.class));
        }
        return dataGrid;
    }
 
    /**
     * 根据角色主键获取关联的权限
     *
     * @param roleOid             角色主键
     * @param queryMap            查询条件,如果需要使用角色的属性来查询可以使用pkUser.xxxx
     * @param resourceControlTypeEnum 角色控制区域,也是功能控制的区域
     * @return 权限的显示对象
     */
    @Override
    public List<SmFunctionVO> listFunctionByRoleOid(String roleOid, Map<String, String> queryMap, ResourceControlTypeEnum resourceControlTypeEnum) {
        String controlType = resourceControlTypeEnum == null? ResourceControlTypeEnum.BS.getValue(): resourceControlTypeEnum.getValue();
        return Optional.ofNullable(listFunctionByRoleOid(roleOid,queryMap,false)).orElseGet(()->new ArrayList<>()).stream().filter(s->controlType.equalsIgnoreCase(s.getResourceControlType())).collect(Collectors.toList());
    }
 
    /**
     * 获取未关联某个角色的权限
     *
     * @param roleOid             角色主键
     * @param queryMap            查询条件,如果需要使用角色的属性来查询可以使用pkUser.xxxx
     * @param resourceControlTypeEnum 角色控制区域,也是功能控制的区域
     * @return 权限的显示对象
     */
    @Override
    public List<SmFunctionVO> listFunctionUnInRoleOid(String roleOid, Map<String, String> queryMap, ResourceControlTypeEnum resourceControlTypeEnum) {
        String controlType = resourceControlTypeEnum == null? ResourceControlTypeEnum.BS.getValue(): resourceControlTypeEnum.getValue();
        return Optional.ofNullable(listFunctionByRoleOid(roleOid,queryMap,true)).orElseGet(()->new ArrayList<>()).stream().filter(s->controlType.equalsIgnoreCase(s.getResourceControlType())).collect(Collectors.toList());
    }
 
    /**
     * 使用角色主键查询权限
     * @param roleOid 用户主键
     * @param queryMap 查询条件
     * @param notIn 是否为不包含
     * @return 角色的显示对象
     */
    private List<SmFunctionVO> listFunctionByRoleOid(String roleOid, Map<String,String> queryMap, boolean notIn){
        if(StringUtils.isBlank(roleOid)){
            return new ArrayList<>();
        }
        if(queryMap == null){
            queryMap = new HashMap<>();
        }
        List<SmFunctionForPlatform1> functions = new ArrayList<>();
        if(roleOid.contains(",")){
            Map<String, String> finalQueryMap = queryMap;
            WebUtil.switchCollectionForOracleIn(WebUtil.str2List(roleOid)).stream().forEach(roleOids->{
                Map<String,String> conditionMap = new HashMap<>();
                finalQueryMap.forEach((key,value)->{
                    conditionMap.put(key,value);
                });
                conditionMap.put("ploid", notIn ? QueryOptionConstant.NOTIN : QueryOptionConstant.IN + "select plfuncoid from plroleright where plroleoid in (" + WebUtil.toInSql(roleOids.toArray(new String[0])) + ")");
                VciQueryWrapperForDO queryWrapper = new VciQueryWrapperForDO(conditionMap, SmRoleForPlatform1.class);
                List<SmFunctionForPlatform1> functionForPlatform1s = boService.selectByQueryWrapper(queryWrapper, SmFunctionForPlatform1.class);
                if(!CollectionUtils.isEmpty(functionForPlatform1s)){
                    functions.addAll(functionForPlatform1s);
                }
            });
        }else {
            queryMap.put("ploid", notIn ? QueryOptionConstant.NOTIN : QueryOptionConstant.IN + "select plfuncoid from plroleright where plroleoid ='" + roleOid.trim() + "'");
        }
        VciQueryWrapperForDO queryWrapper = new VciQueryWrapperForDO(queryMap,SmRoleForPlatform1.class);
        List<SmFunctionForPlatform1> roleForPlatform1s = boService.selectByQueryWrapper(queryWrapper, SmFunctionForPlatform1.class);
        if(!CollectionUtils.isEmpty(roleForPlatform1s)){
            functions.addAll(roleForPlatform1s);
        }
        return functionForPlatform1ToFunctionDOs(functions);
    }
 
    /**
     * 获取未关联某个角色的权限
     *
     * @param roleOid             角色主键
     * @param queryMap            查询条件,如果需要使用角色的属性来查询可以使用pkUser.xxxx
     * @param pageHelper          分页和排序对象,老平台不支持使用权限编号来排序
     * @param resourceControlTypeEnum 角色控制区域,也是功能控制的区域
     * @return 权限的显示对象
     */
    @Override
    public DataGrid<SmFunctionVO> gridFunctionUninRoleOid(String roleOid, Map<String, String> queryMap, PageHelper pageHelper, ResourceControlTypeEnum resourceControlTypeEnum) {
        return gridFunctionByRoleOid(roleOid,queryMap,pageHelper,resourceControlTypeEnum,true);
    }
 
    /**
     * 批量根据角色的主键来获取权限
     *
     * @param roleOidCollection   角色主键集合
     * @param queryMap            查询条件,如果需要使用角色的属性来查询可以使用pkRole.xxxx
     * @param resourceControlTypeEnum 角色控制区域,也是功能控制的区域
     * @return 权限的显示对象,key是角色主键,value是这个角色关联的权限
     */
    @Override
    public Map<String, List<SmFunctionVO>> batchListFunctionByRoleOids(Collection<String> roleOidCollection, Map<String, String> queryMap, ResourceControlTypeEnum resourceControlTypeEnum) {
        if(CollectionUtils.isEmpty(roleOidCollection)){
            return new HashMap<>();
        }
        List<SmFunctionVO> functionVOList = new ArrayList<>();
        Map<String,List<String>>  roleFunctionOidMap = new HashMap<>();
        String roleContoll = resourceControlTypeEnum == null?ResourceControlTypeEnum.BS.getValue():resourceControlTypeEnum.getValue();
        WebUtil.switchCollectionForOracleIn(roleOidCollection).stream().forEach(roleOids->{
            List<SmFunctionVO> functionVOS = Optional.ofNullable(listFunctionByRoleOid(roleOids.stream().collect(Collectors.joining(",")), queryMap, false)).orElseGet(()->new ArrayList<>()).stream().filter(s->roleContoll.equalsIgnoreCase(s.getResourceControlType())).collect(Collectors.toList());
            if(!CollectionUtils.isEmpty(functionVOS)){
                functionVOList.addAll(functionVOS);
                String sql = "select plfuncoid,plroleoid from plroleright where plroleoid in (" + WebUtil.toInSql(roleOids.toArray(new String[0])) + ")";
                List<BusinessObject> cbos = boService.queryBySql(sql, null);
                if(!CollectionUtils.isEmpty(cbos)){
                    cbos.stream().forEach(cbo->{
                        String roleOid = ObjectTool.getBOAttributeValue(cbo,"plroleoid");
                        List<String> functionOids = roleFunctionOidMap.getOrDefault(roleOid,new ArrayList<>());
                        functionOids.add(ObjectTool.getBOAttributeValue(cbo,"plfuncoid"));
                        roleFunctionOidMap.put(roleOid,functionOids);
                    });
                }
            }
        });
        if(!CollectionUtils.isEmpty(functionVOList)){
            Map<String, SmFunctionVO> functionVOMap = functionVOList.stream().collect(Collectors.toMap(s -> s.getOid(), t -> t));
            Map<String, List<SmFunctionVO>> roleFunctionVOMap = new HashMap<>();
            roleFunctionOidMap.forEach((roleOid,functionOids)->{
                List<SmFunctionVO> functionVOS = new ArrayList<>();
                functionOids.forEach(functionOid->{
                    if(functionVOMap.containsKey(functionOid)){
                        functionVOS.add(functionVOMap.get(functionOid));
                    }
                });
                roleFunctionVOMap.put(roleOid,functionVOS);
            });
            return roleFunctionVOMap;
        }
        return  new HashMap<>();
    }
 
    /**
     * 使用角色查询权限表
     * @param roleOid 角色的主键
     * @param queryMap 查询条件
     * @param pageHelper 分页对象
     * @param notIn 不包含
     * @return 列表数据
     */
    private DataGrid<SmFunctionVO> gridFunctionByRoleOid(String roleOid,Map<String,String> queryMap,PageHelper pageHelper,ResourceControlTypeEnum resourceControlTypeEnum,boolean notIn){
        if(queryMap == null){
            queryMap = new HashMap<>();
        }
        if(StringUtils.isBlank(roleOid)){
            return new DataGrid<>();
        }
        if(roleOid.contains(",")){
            String[] roleOids = roleOid.trim().split(",");
            if(roleOids.length>1000){
                //这个方法不支持超过1000个的用户查询
                throw new VciBaseException("这个方法不支持超过1000个角色的主键来查询");
            }
            queryMap.put("ploid", notIn ? QueryOptionConstant.NOTIN : QueryOptionConstant.IN + "select plfuncoid from plroleright where plroleoid in (" + WebUtil.toInSql(roleOid) + ")");
        }else {
            queryMap.put("ploid", notIn ? QueryOptionConstant.NOTIN : QueryOptionConstant.IN + "select plfuncoid from plroleright where plroleoid ='" + roleOid.trim() + "'");
        }
        if(resourceControlTypeEnum == null){
            resourceControlTypeEnum = ResourceControlTypeEnum.BS;
        }
        switch (resourceControlTypeEnum){
            case BS:
                queryMap.put("plresourceb",QueryOptionConstant.ISNOTNULL);
                break;
            case DOTNET:
                queryMap.put("plresourcedotnet",QueryOptionConstant.ISNOTNULL);
                break;
            case MOBILE:
                queryMap.put("plresourcemobil",QueryOptionConstant.ISNOTNULL);
                break;
            default:
                queryMap.put("plsuffixc",QueryOptionConstant.ISNOTNULL);
        }
        return dataGrid(queryMap,pageHelper);
    }
 
    /**
     * 批量根据角色的主键获取关联的权限
     *
     * @param roleOidCollection   角色的主键集合
     * @param queryMap            查询条件,如果需要使用角色的属性来查询可以使用pkRole.xxxx
     * @param resourceControlTypeEnum 角色控制区域,也是功能控制的区域
     * @return 权限的显示对象, 会去除重复的项
     */
    @Override
    public List<SmFunctionVO> listFunctionByRoleOids(Collection<String> roleOidCollection, Map<String, String> queryMap, ResourceControlTypeEnum resourceControlTypeEnum) {
        if(CollectionUtils.isEmpty(roleOidCollection)){
            return new ArrayList<>();
        }
        return listFunctionByRoleOid(roleOidCollection.stream().collect(Collectors.joining(",")),queryMap,false);
    }
 
    /**
     * 批量根据角色的主键获取关联的权限
     *
     * @param roleOidCollection   角色的主键集合
     * @param queryMap            查询条件,如果需要使用角色的属性来查询可以使用pkRole.xxxx
     * @param pageHelper          分页对象
     * @param resourceControlTypeEnum 角色控制区域,也是功能控制的区域
     * @return 权限的显示对象, 会去除重复的项
     */
    @Override
    public DataGrid<SmFunctionVO> gridFunctionByRoleOids(Collection<String> roleOidCollection, Map<String, String> queryMap, PageHelper pageHelper, ResourceControlTypeEnum resourceControlTypeEnum) {
        if(CollectionUtils.isEmpty(roleOidCollection)){
            return new DataGrid<>();
        }
        return gridFunctionByRoleOid(roleOidCollection.stream().collect(Collectors.joining(",")), queryMap,pageHelper,resourceControlTypeEnum,false);
    }
 
    /**
     * 清除缓存
     */
    @Override
    public void clearCache() {
 
    }
 
    /**
     * 通过模块ID获取子级列表
     * @param isAll 是否包括无效的模块,true则包括
     * @return
     * @throws VciBaseException
     */
    @Override
    public List<MenuVO> getSysModelAuthTreeMenuByPID(boolean isAll) throws VciBaseException, PLException {
        SessionInfo sessionInfo = WebUtil.getCurrentUserSessionInfoNotException();
        boolean adminOrDeveloperOrRoot = rightControlUtil.isAdminOrDeveloperOrRoot(sessionInfo.getUserId());
        String parentId;
        if (adminOrDeveloperOrRoot) {
            //系统菜单
            parentId = SYSTEMMANAGMENTNODE;
        } else {
            //普通用户只返回业务功能模块相关的菜单
            parentId = ROOT_MENU_ID;
        }
        List<MenuVO> functionVOList = new ArrayList<>();
        FunctionInfo[] moduleListByParentId = getModuleListByParentId(parentId, isAll);
        for (FunctionInfo menu : moduleListByParentId) {
            if(!menu.isValid){
                continue;
            }
            MenuVO functionVO = new MenuVO();
            functionVO.setId(menu.id);
            functionVO.setSource(menu.image);
            functionVO.setPath(menu.resourceB);
            functionVO.setParentId(menu.parentId);
            functionVO.setCode(menu.aliasName);
            functionVO.setAlias(menu.aliasName);
            functionVO.setName(menu.name);
            functionVO.getMeta().put("keepAlive",false);
            functionVO.setSort((int) menu.seq);
            findChildAuthFunctionVO(functionVO, isAll);
            if(functionVO.getChildren().size() > 0){
                functionVO.setHasChildren(true);
            }else {
                functionVO.setHasChildren(false);
            }
            functionVOList.add(functionVO);
        }
        return functionVOList;
    }
 
    /**
     * 通过模块ID获取子级列表
     * @param parentId
     * @param isAll 是否包括无效的模块,true则包括
     * @return
     * @throws VciException
     */
    public FunctionInfo[] getModuleListByParentId(String parentId,boolean isAll) throws PLException {
        FunctionInfo[] funcInfos = null;
        funcInfos = platformClientUtil.getFrameworkService().getModuleListByParentId(parentId, isAll);
        return funcInfos;
    }
 
}