kimi
2020-05-27 c007f0ca1785db093d48f4846cda82fe8e955765
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
package com.highdatas.mdm.controller;
 
 
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.highdatas.mdm.entity.*;
import com.highdatas.mdm.mapper.MasterAuthorMapper;
import com.highdatas.mdm.pojo.CodeMsg;
import com.highdatas.mdm.pojo.MasterAuthorType;
import com.highdatas.mdm.pojo.Result;
import com.highdatas.mdm.service.*;
import com.highdatas.mdm.util.Constant;
import com.highdatas.mdm.util.DbUtils;
import com.highdatas.mdm.util.RedisClient;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletRequest;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author kimi
 * @since 2020-03-23
 */
@RestController
@RequestMapping("/masterAuthor")
public class MasterAuthorController {
 
    @Autowired
    IMasterAuthorService authorService;
    @Autowired
    IMasterAuthorDetailService authorDetailService;
 
    @Autowired
    IMenuMappingService menuMappingService;
    @Autowired
    ISysMenuService menuService;
    @Autowired
    MasterAuthorMapper masterAuthorMapper;
    @Autowired
    IMaintainFieldService maintainFieldService;
    @Autowired
    IMasterAuthorUnactiveService masterAuthorUnactiveService;
    @Autowired
    IMasterAuthorSubscribeService masterAuthorSubscribeService;
    @Autowired
    IMaintainService maintainService;
    @Autowired
    RedisClient redisClient;
 
    public static final String masterAuthorType = "masterAuthorType";
    public static final String masterId = "masterId";
    public static final String tableName = "table_name";
    public static final String characterId = "characterId";
    public static final String character_id = "character_id";
    public static final String fields = "fields";
    private String maintainFieldId = "maintainFieldId";
    private String maintain_field_id = "maintain_field_id";
 
    /**
     *
     * @description: 添加或者更新权限
     * @return 权限数据
     *
     */
    @RequestMapping(value = "/addOrUpdate", method = RequestMethod.POST)
    public Result deleteModel(@RequestBody MasterAuthor masterAuthor)  {
        if (StringUtils.isEmpty(masterAuthor.getMaintainFieldId())) {
            return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED);
        }
        if (!StringUtils.isEmpty(masterAuthor.getId())) {
            masterAuthor.setUpdateTime(new Date());
        }else {
            masterAuthor.setId(DbUtils.getUUID()).setCreateTime(new Date());
        }
        String menuId = masterAuthor.getMenuId();
        String tableName = menuMappingService.getTableNameByMenu(menuId);
        masterAuthor.setTableName(tableName);
        //delete pre
        boolean delete = authorDetailService.delete(new EntityWrapper<MasterAuthorDetail>().eq(Constant.PARENT_ID, masterAuthor.getId()));
        if (!delete){
            return Result.error(CodeMsg.DELETE_ERROR);
        }
 
        for (MasterAuthorDetail detail : masterAuthor.getFields()) {
            detail.setId(DbUtils.getUUID()).setParentId(masterAuthor.getId()).insert();
        }
 
        boolean b = masterAuthor.insertOrUpdate();
        if (b) {
            redisClient.delByCharacter(masterAuthor.getCharacterId());
            return Result.success(masterAuthor);
        }else {
            return Result.error(CodeMsg.UPDATE_ERROR);
        }
    }
    /**
     *
     * @description: 通过系统用户获取权限
     * @param characterId 系统用户
     * @param isGroup 是否为用户组数据
    *  @param type 用户类型
     * @return 具体数据
     *
     */
    @RequestMapping(value = "/get/{characterId}", method = RequestMethod.GET)
    public Result get(@PathVariable String characterId,@RequestParam boolean isGroup, @RequestParam MasterAuthorType type, HttpServletRequest request){
        List<MasterAuthor> masterAuthorList = authorService.selectList(new EntityWrapper<MasterAuthor>().eq("user_group", isGroup).eq("type", type.name()).eq("character_id", characterId));
        if (type.equals(MasterAuthorType.role) && masterAuthorList.isEmpty()) {
            return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED);
        }else if (type.equals(MasterAuthorType.user) && masterAuthorList.isEmpty()){
            //user 获取角色 多脚色混合
            String userId = characterId;
            Set<String> roleIdSet;
            if (isGroup) {
                roleIdSet = DbUtils.getRoleByGroup(userId);
            } else {
                roleIdSet = DbUtils.getRoleByUser(userId);
            }
            if (roleIdSet.isEmpty()) {
                return Result.success(null);
            }
            HashMap<String, MasterAuthor> tableMasterAuthor = authorService.merageRoleAuthor(roleIdSet);
            if (tableMasterAuthor == null) {
                Result.success(null);
            }
            JSONObject object = new JSONObject();
            ArrayList<MasterAuthor> list = new ArrayList(tableMasterAuthor.values());
 
            object.fluentPut("type", MasterAuthorType.role);
            object.fluentPut("author",list);
 
            Set<String> collect = list.stream().map(masterAuthor -> masterAuthor.getMenuId()).collect(Collectors.toSet());
            LinkedHashSet<String>  menuIds= new LinkedHashSet<>(collect);
            List<SysMenu> sysMenus = menuService.getMenuByParentId(menuIds);
            if (sysMenus == null) {
                return Result.success(object);
            }
            object.fluentPut("audit",sysMenus);
            return Result.success(object);
        }
 
        for (MasterAuthor masterAuthor : masterAuthorList) {
            List<MasterAuthorDetail> masterAuthorDetails = authorDetailService
                    .selectList(new EntityWrapper<MasterAuthorDetail>()
                            .eq(Constant.PARENT_ID, masterAuthor.getId()));
            masterAuthor.setFields(masterAuthorDetails);
        }
        JSONObject object = new JSONObject();
        object.fluentPut("type", type);
        object.fluentPut("author",masterAuthorList);
 
        Set<String> collect = masterAuthorList.stream().map(masterAuthor -> masterAuthor.getMenuId()).collect(Collectors.toSet());
        LinkedHashSet<String>  menuIds= new LinkedHashSet<>(collect);
        List<SysMenu> sysMenus = menuService.getMenuByParentId(menuIds);
        if (sysMenus == null) {
            return Result.success(object);
        }
 
        object.fluentPut("audit",sysMenus);
        return Result.success(object);
    }
    /**
     *
     * @description: 通过系统用户删除权限
     * @param characterId 系统用户
     *  @param type 用户类型
     * @return 是否删除成功
     *
     */
    @RequestMapping(value = "/delete/{characterId}", method = RequestMethod.GET)
    public Result delete(@PathVariable String characterId, @RequestParam MasterAuthorType type){
        List<MasterAuthor> masterAuthorList = authorService.selectList(new EntityWrapper<MasterAuthor>()
                .eq(Constant.TYPE, type).eq(this.character_id, characterId));
        if (masterAuthorList.isEmpty()) {
            return Result.success(null);
        }
        boolean delete = false;
        for (MasterAuthor masterAuthor : masterAuthorList) {
            delete = authorDetailService.delete(new EntityWrapper<MasterAuthorDetail>().eq(Constant.PARENT_ID, masterAuthor.getId()));
            if (delete) {
                delete = masterAuthor.deleteById();
            }
        }
 
        if (delete) {
            redisClient.delByCharacter(characterId);
            return Result.success(CodeMsg.DELETE_SUCCESS);
        }else  {
            return Result.error(CodeMsg.DELETE_ERROR);
        }
    }
 
    /**
     *
     * @description: 通过主题删除权限
     * @param characterId 系统用户
     * @param menuId 主题id
     *  @param type 用户类型
     * @return 具体数据
     *
     */
    @RequestMapping(value = "/delete/menu/{menuId}", method = RequestMethod.GET)
    public Result deleteTable(@PathVariable String menuId, @RequestParam String characterId, @RequestParam MasterAuthorType type, HttpServletRequest request){
        String maintainFieldId = request.getParameter(this.maintainFieldId);
        Wrapper<MasterAuthor> masterAuthorWrapper = new EntityWrapper<MasterAuthor>()
                .eq(Constant.TYPE, type)
                .eq(character_id, characterId)
                .eq("menu_id", menuId);
        Wrapper<MasterAuthor> menuWrapper = new EntityWrapper<MasterAuthor>()
                .eq(Constant.TYPE, type)
                .eq(character_id, characterId)
                .eq("menu_id", menuId);
        if (!StringUtils.isEmpty(maintainFieldId)) {
            masterAuthorWrapper.eq(this.maintain_field_id, maintainFieldId);
        }
        int count = authorService.selectCount(menuWrapper);
        boolean only = false;
        if (count == 1 && !StringUtils.isEmpty(maintainFieldId)) {
            only = true;
        }
        List<MasterAuthor> masterAuthors = authorService.selectList(masterAuthorWrapper);
        if (masterAuthors == null || masterAuthors.isEmpty()) {
            return Result.success(null);
        }
        boolean delete = false;
        for (MasterAuthor masterAuthor : masterAuthors) {
            delete = authorDetailService.delete(new EntityWrapper<MasterAuthorDetail>().eq(Constant.PARENT_ID, masterAuthor.getId()));
            if (delete) {
                if (only){
                    delete = masterAuthor.setMaintainFieldId(null).setFieldAuto(false).setMaintainAuto(false).setUpdateTime(new Date()).updateById();
                }else {
                    delete = masterAuthor.deleteById();
                }
            }
        }
        if (delete) {
            redisClient.delByCharacter(characterId);
            return Result.success(CodeMsg.DELETE_SUCCESS);
        }else  {
            return Result.error(CodeMsg.DELETE_ERROR);
        }
    }
    /**
     *
     * @description: 用户组添加角色关联
     * @param groupId 用户组id
     * @param roleId 角色id
     * @return 是否添加成功
     *
     */
    @RequestMapping(value = "/groupAddRole/{roleId}", method = RequestMethod.GET)
    public Result addGroupRole(@PathVariable String roleId, @RequestParam String groupId, HttpServletRequest request){
        TUser user = DbUtils.getUser(request);
        if (user == null){
            return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED);
        }
        ArrayList<String> addRoleList = new ArrayList<>();
        Set<String> roleIdSet = DbUtils.getRoleByGroup(groupId);
        addRoleList.addAll(roleIdSet);
        addRoleList.add(roleId);
        boolean b = DbUtils.groupAddOneRole(user.getUserId(),groupId, addRoleList);
        if (!b) {
            return Result.error(CodeMsg.INSERT_ERROR);
        }
 
       roleIdSet.add(roleId);
 
        HashMap<String, MasterAuthor> tableMasterAuthor = authorService.merageRoleAuthor(roleIdSet);
        if (tableMasterAuthor == null) {
            Result.success(null);
        }
        return Result.success(tableMasterAuthor.values());
    }
    /**
     *
     * @description: 用户添加角色关联
     * @param userId 用户id
     * @param roleId 角色id
     * @return 是否添加成功
     *
     */
    @RequestMapping(value = "/userAddRole/{roleId}", method = RequestMethod.GET)
    public Result addRole(@PathVariable String roleId, @RequestParam String userId, HttpServletRequest request){
        TUser user = DbUtils.getUserById(userId);
        if (user == null){
            return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED);
        }
        ArrayList<String> addRoleList = new ArrayList<>();
        Set<String> roleIdSet = DbUtils.getRoleByUser(userId);
        addRoleList.addAll(roleIdSet);
        addRoleList.add(roleId);
        boolean b = DbUtils.addOneRole(user, addRoleList);
        if (!b) {
            return Result.error(CodeMsg.INSERT_ERROR);
        }
 
        roleIdSet.add(roleId);
 
        HashMap<String, MasterAuthor> tableMasterAuthor = authorService.merageRoleAuthor(roleIdSet);
        if (tableMasterAuthor == null) {
            Result.success(null);
        }
        return Result.success(tableMasterAuthor.values());
    }
 
    /**
     *
     * @description: 用户删除角色关联
     * @param userId 用户id
     * @param roleId 角色id
     * @return 是否删除成功
     *
     */
    @RequestMapping(value = "/userDelRole/{roleId}", method = RequestMethod.GET)
    public Result delRole(@PathVariable String roleId, @RequestParam String userId, HttpServletRequest request){
        ArrayList<String> delRoleList = new ArrayList<>();
 
        delRoleList.add(roleId);
        boolean b = DbUtils.delOneRole(userId, delRoleList);
        if (!b) {
            return Result.error(CodeMsg.INSERT_ERROR);
        }
 
        Set<String> roleIdSet = DbUtils.getRoleByUser(userId);
        HashMap<String, MasterAuthor> tableMasterAuthor = authorService.merageRoleAuthor(roleIdSet);
        if (tableMasterAuthor == null) {
            Result.success(null);
        }
        return Result.success(tableMasterAuthor.values());
    }
    /**
     *
     * @description: 用户组删除角色关联
     * @param groupId 用户组id
     * @param roleId 角色id
     * @return 是否删除成功
     *
     */
    @RequestMapping(value = "/groupDelRole/{roleId}", method = RequestMethod.GET)
    public Result delGroupRole(@PathVariable String roleId, @RequestParam String groupId, HttpServletRequest request){
        ArrayList<String> delRoleList = new ArrayList<>();
 
        delRoleList.add(roleId);
        boolean b = DbUtils.groupDelOneRole(groupId, delRoleList);
        if (!b) {
            return Result.error(CodeMsg.INSERT_ERROR);
        }
 
        Set<String> roleIdSet = DbUtils.getRoleByGroup(groupId);
        HashMap<String, MasterAuthor> tableMasterAuthor = authorService.merageRoleAuthor(roleIdSet);
        if (tableMasterAuthor == null) {
            Result.success(null);
        }
        return Result.success(tableMasterAuthor.values());
    }
 
    /**
     *
     * @description: 通过用户id获取已经注册list
     * @param userId 用户id
     * @return 已注册list
     *
     */
    @RequestMapping(value = "/subscribeList/{userId}", method = RequestMethod.GET)
    public Result subscribeList(@PathVariable  String userId,  HttpServletRequest request){
        TUser user = DbUtils.getUserById(userId);
        if (user == null){
            return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED);
        }
 
        List<SysMenu> menuList = authorService.getMenuUnParent(user, true);
        if (menuList == null) {
            return Result.success(null);
        }
        List<MasterAuthor> userAuthor = authorService.getUserAuthor(userId, null);
 
        ArrayList<SysMenu> result = new ArrayList<>();
        for (SysMenu sysMenu : menuList) {
            long count = userAuthor.stream().filter(masterAuthor -> masterAuthor.getMenuId().equalsIgnoreCase(sysMenu.getId())).count();
            if (count > 0) {
                result.add(sysMenu);
            }
        }
        LinkedHashSet<String> parentSet = new LinkedHashSet<>();
 
        for (SysMenu menu : result) {
            menu.setShow(false);
            String menuId = menu.getId();
            String tableNameByMenu = menuMappingService.getTableNameByMenu(menuId);
            menu.setTableName(tableNameByMenu);
            parentSet.clear();
            parentSet.add(menuId);
            List<SysMenu> sysMenus = menuService.getMenuByParentId(parentSet);
 
            menu.setParentMenuList(sysMenus);
            int i = masterAuthorSubscribeService.selectCount(new EntityWrapper<MasterAuthorSubscribe>().eq("menu_id", menuId).eq("user_id", userId));
            if (i > 0) {
                menu.setSubscribe(true);
            }
        }
        return Result.success(result);
    }
 
//    @RequestMapping(value = "/canLoadData/{userId}", method = RequestMethod.GET)
//    public Result canLoadData(@PathVariable String userId, @RequestParam String tableName, HttpServletRequest request) {
//        TUser user = DbUtils.getUserById(userId);
//        if (user == null) {
//            return Result.error(CodeMsg.USER_NOT_MATHED);
//        }
//    }
 
    /**
     *
     * @description: 通过userid获取有权限的主题
     * @param userId 用户id
     * @return 主题列表
     *
     */
    @RequestMapping(value = "/menu/{userId}", method = RequestMethod.GET)
    public Result<List<SysMenu>> menuList(@PathVariable String userId, HttpServletRequest request) {
        TUser user = DbUtils.getUserById(userId);
        if (user == null) {
            return Result.error(CodeMsg.USER_NOT_MATHED);
        }
 
        List<SysMenu> menu = authorService.getMenu(user, true);
        return Result.success(menu) ;
    }
 
    /**
     *
     * @description: 通过userid获取有权限的主题数据
     * @param userId 用户id
     * @return 获取有权限的数据数
     *
     */
    @RequestMapping(value = "/getCnt/{userId}",  method = RequestMethod.GET)
    public Result cnt(@PathVariable String userId, HttpServletRequest request) {
        //TODO active
        TUser user = DbUtils.getUserById(userId);
        if (user == null) {
            return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED);
        }
        List<MasterAuthor> userAuthor = authorService.getUserAuthor(userId, null);
 
        List<SysMenu> menuList = authorService.getMenuUnParent(user, true);
        int totalCnt = 0;
        int subscribeCnt = 0;
        int activeCnt = 0;
        if (menuList == null) {
            JSONObject object = new JSONObject();
            object.fluentPut("totalCnt", 0);
            object.fluentPut("activeCnt", 0);
            object.fluentPut("subscribeCnt", 0);
            return Result.success(object);
        }
        for (SysMenu sysMenu : menuList) {
            List<MasterAuthor> authorMaintainFieldList = userAuthor.stream()
                    .filter(masterAuthor -> masterAuthor.getMenuId().equalsIgnoreCase(sysMenu.getId()))
                    .collect(Collectors.toList());
            int count = authorMaintainFieldList.size();
            if (count > 0) {
              totalCnt++;
                HashSet<Maintain> maintainSet = new HashSet<>();
                for (MasterAuthor masterAuthor : authorMaintainFieldList) {
                    String maintainFieldId = masterAuthor.getMaintainFieldId();
                    String tableName = masterAuthor.getTableName();
                    List<Maintain> maintainByMaintainField = maintainFieldService.getMaintainByMaintainField(maintainFieldId, tableName);
                    if (maintainByMaintainField != null) {
                        maintainSet.addAll(maintainByMaintainField);
                    }
 
                }
                int unActiveCnt = masterAuthorUnactiveService.selectCount(new EntityWrapper<MasterAuthorUnactive>().in("maintain_id", maintainSet).eq("user_id", userId));
                if (maintainSet.size() != unActiveCnt) {
                    activeCnt++;
                }
                int oneSubscribeCnt = masterAuthorSubscribeService.selectCount(new EntityWrapper<MasterAuthorSubscribe>().eq("user_id", userId).eq("menu_id", sysMenu.getId()));
                if (oneSubscribeCnt > 0){
                    subscribeCnt++;
                }
            }
 
        }
 
 
        JSONObject object = new JSONObject();
        object.fluentPut("totalCnt", totalCnt);
        object.fluentPut("activeCnt", activeCnt);
        object.fluentPut("subscribeCnt", subscribeCnt);
        return Result.success(object);
    }
    /**
     *
     * @description: 通过版本获取激活的主题
     * @param maintainId 主题id
     * @param userId 用户id
     * @param active 激活状态
     * @return 已激活的主题数
     *
     */
    @RequestMapping(value = "/active/{maintainId}",  method = RequestMethod.GET)
    public Result active(@PathVariable String maintainId, @RequestParam String userId, @RequestParam Boolean active) {
        TUser user = DbUtils.getUserById(userId);
        if (user == null) {
            return Result.error(CodeMsg.USER_NOT_MATHED);
        }
        MasterAuthorUnactive masterAuthorUnactive = masterAuthorUnactiveService.selectOne(new EntityWrapper<MasterAuthorUnactive>().eq(Constant.USERID, userId).eq("maintain_id", maintainId));
        if (masterAuthorUnactive == null && active) {
            return Result.success(null);
        } else if (masterAuthorUnactive == null && !active) {
            boolean insert = new MasterAuthorUnactive().setId(DbUtils.getUUID()).setMaintainId(maintainId).setUserId(userId).insert();
            if (insert) {
                return Result.success(null);
            } else {
                return Result.error(null);
            }
        } else if (active) {
            boolean delete = masterAuthorUnactive.deleteById();
            if (delete) {
                return Result.success(null);
            } else {
                return Result.error(null);
            }
        } else {
            return Result.success(null);
        }
    }
 
    /**
     *
     * @description: 获取有权限的list和用户map
     * @return list和用户map列表
     *
     */
    @RequestMapping(value = "/cntList",  method = RequestMethod.GET)
    public Result cntList() {
        HashMap<String, Long> result = new HashMap<>();
        //user
 
        Set<TUser> allUser = DbUtils.getAllUser();
        for (TUser user : allUser) {
            int activeCnt = 0;
            List<MasterAuthor> userAuthor = authorService.getUserAuthor(user.getUserId(), null);
 
            List<SysMenu> menuList = authorService.getMenuUnParent(user, true);
 
            if (menuList == null) {
                continue;
            }
            for (SysMenu sysMenu : menuList) {
                List<MasterAuthor> authorMaintainFieldList = userAuthor.stream()
                        .filter(masterAuthor -> masterAuthor.getMenuId().equalsIgnoreCase(sysMenu.getId()))
                        .collect(Collectors.toList());
                int count = authorMaintainFieldList.size();
                if (count > 0) {
                    HashSet<Maintain> maintainSet = new HashSet<>();
                    for (MasterAuthor masterAuthor : authorMaintainFieldList) {
                        String maintainFieldId = masterAuthor.getMaintainFieldId();
                        String tableName = masterAuthor.getTableName();
                        List<Maintain> maintainByMaintainField = maintainFieldService.getMaintainByMaintainField(maintainFieldId, tableName);
                        maintainSet.addAll(maintainByMaintainField);
                    }
                    int unActiveCnt = masterAuthorUnactiveService.selectCount(new EntityWrapper<MasterAuthorUnactive>().in("maintain_id", maintainSet).eq("user_id", user.getUserId()));
                    if (maintainSet.size() != unActiveCnt) {
                        activeCnt++;
                    }
 
                }
                result.put(user.getUserId(), Long.valueOf(activeCnt));
            }
        }
 
        List<Map<String, Object>> userMapList = masterAuthorMapper.selectViewCnt();
        merageUserCnt(result, userMapList);
        if (result.isEmpty()) {
            return Result.success(null);
        }
        return Result.success(result);
    }
    /**
     *
     * @description: 通过表名获取有权限的版本list
     * @param userId 用户id
     * @param tableName 表名
     * @return 获取有权限的版本list
     *
     */
    @RequestMapping(value = "/maintainList/{userId}",  method = RequestMethod.GET)
    public Result maintainList(@PathVariable String userId, @RequestParam String tableName) {
        TUser user = DbUtils.getUserById(userId);
        if (user == null) {
            return Result.error(CodeMsg.USER_NOT_MATHED);
        }
        Set<Maintain> maintainSet = authorService.getMaintainSet(tableName, user);
        List<MasterAuthorUnactive> masterAuthorUnactives = masterAuthorUnactiveService.selectList(new EntityWrapper<MasterAuthorUnactive>().eq(Constant.USERID, userId));
        for (Maintain maintain : maintainSet) {
            long count = masterAuthorUnactives.stream()
                    .filter(masterAuthorUnactive -> !StringUtils.isEmpty(masterAuthorUnactive.getMaintainId()))
                    .filter(masterAuthorUnactive -> masterAuthorUnactive.getMaintainId().equalsIgnoreCase(maintain.getId()))
                    .count();
            if (count > 0) {
                maintain.setActive(false);
            } else {
                maintain.setActive(true);
            }
        }
        return Result.success(maintainSet);
    }
 
    /**
     *
     * @description: 通过版本获取激活的主题
     * @param result 组装用户id, 数据的  map
     * @param masterUserMapList 视图的数据list map
     * @return result 用户id, 权限数据量的  map
     *
     */
    private void merageUserCnt(HashMap<String, Long> result, List<Map<String, Object>> masterUserMapList) {
        for (Map<String, Object> stringStringMap : masterUserMapList) {
            String user = stringStringMap.get(Constant.USERID).toString();
            long cnt = (long)(stringStringMap.get(Constant.CNT));
 
            Long val = result.get(user);
            if (val == null) {
                result.put(user, Long.valueOf(cnt));
            } else {
                val += Long.valueOf(cnt);
                result.put(user, val);
            }
        }
    }
}