xiejun
2024-01-23 f09e05514d9a9e2623cfa73c4de1ffa98bb30bf8
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
/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package com.vci.ubcs.system.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.vci.ubcs.code.feign.ICodeClassifyClient;
import com.vci.ubcs.starter.util.MybatisParameterUtil;
import com.vci.ubcs.starter.web.util.VciBaseUtil;
import com.vci.ubcs.system.cache.NacosConfigCache;
import com.vci.ubcs.system.cache.SysCache;
import com.vci.ubcs.system.dto.MenuDTO;
import com.vci.ubcs.system.entity.*;
import com.vci.ubcs.system.mapper.ClassifyAuthMapper;
import com.vci.ubcs.system.service.*;
import com.vci.ubcs.system.vo.MenuVO;
import com.vci.ubcs.system.mapper.MenuMapper;
import com.vci.ubcs.system.wrapper.MenuWrapper;
import lombok.AllArgsConstructor;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.constant.BladeConstant;
import org.springblade.core.tool.node.ForestNodeMerger;
import org.springblade.core.tool.node.TreeNode;
import org.springblade.core.tool.support.Kv;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringUtil;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
 
import java.util.*;
import java.util.stream.Collectors;
 
import static com.vci.ubcs.common.constant.CommonConstant.API_SCOPE_CATEGORY;
import static com.vci.ubcs.common.constant.CommonConstant.DATA_SCOPE_CATEGORY;
import static org.springblade.core.cache.constant.CacheConstant.MENU_CACHE;
 
/**
 * 服务实现类
 *
 * @author Chill
 */
@Service
@AllArgsConstructor
public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IMenuService {
 
    private final IRoleMenuService roleMenuService;
    private final IRoleScopeService roleScopeService;
    private final MenuMapper menuMapper;
    private final ITopMenuSettingService topMenuSettingService;
    private final ICodeClassifyClient codeClassifyClient;
    private final ClassifyAuthMapper classifyAuthMapper;
    private final static String PARENT_ID = "parentId";
    private final static Integer MENU_CATEGORY = 1;
 
    @Override
    public List<MenuVO> lazyList(Long parentId, Map<String, Object> param) {
        //int i = 1 / 0;
        if (Func.isEmpty(Func.toStr(param.get(PARENT_ID)))) {
            parentId = null;
        }
        return baseMapper.lazyList(parentId, param);
    }
 
    @Override
    public IPage<MenuVO> lazyMenuPage(Long parentId, Map<String, Object> param, Query query) {
        if (Func.isEmpty(Func.toStr(param.get(PARENT_ID)))) {
            parentId = null;
        }
        return baseMapper.lazyMenuPage(parentId, param, Condition.getPage(query));
    }
 
    @Override
    public List<MenuVO> routes(String roleId, Long topMenuId) {
        if (StringUtil.isBlank(roleId)) {
            return null;
        }
        List<Menu> allMenus = baseMapper.allMenu();
        List<Menu> roleMenus;
        // 超级管理员并且不是顶部菜单请求则返回全部菜单
        if (VciBaseUtil.checkAdminTenant() && Func.isEmpty(topMenuId)) {
            roleMenus = allMenus;
        }
        // 非超级管理员并且不是顶部菜单请求则返回对应角色权限菜单
        else if (!VciBaseUtil.checkAdminTenant() && Func.isEmpty(topMenuId)) {
            roleMenus = tenantPackageMenu(baseMapper.roleMenuByRoleId(Func.toLongList(roleId)));
        }
        // 顶部菜单请求返回对应角色权限菜单
        else {
            // 角色配置对应菜单
            List<Menu> roleIdMenus = baseMapper.roleMenuByRoleId(Func.toLongList(roleId));
            // 反向递归角色菜单所有父级
            List<Menu> routes = new LinkedList<>(roleIdMenus);
            roleIdMenus.forEach(roleMenu -> recursion(allMenus, routes, roleMenu));
            // 顶部配置对应菜单
            List<Menu> topIdMenus = baseMapper.roleMenuByTopMenuId(topMenuId);
            // 筛选匹配角色对应的权限菜单
            roleMenus = topIdMenus.stream().filter(x ->
                routes.stream().anyMatch(route -> route.getId().longValue() == x.getId().longValue())
            ).collect(Collectors.toList());
        }
        return buildRoutes(allMenus, roleMenus);
    }
 
    private List<MenuVO> buildRoutes(List<Menu> allMenus, List<Menu> roleMenus) {
        List<Menu> routes = new LinkedList<>(roleMenus);
        roleMenus.forEach(roleMenu -> recursion(allMenus, routes, roleMenu));
        routes.sort(Comparator.comparing(Menu::getSort));
        MenuWrapper menuWrapper = new MenuWrapper();
        List<Menu> collect = routes.stream().filter(x -> Func.equals(x.getCategory(), 1)).collect(Collectors.toList());
        return menuWrapper.listNodeVO(collect);
    }
 
    private void recursion(List<Menu> allMenus, List<Menu> routes, Menu roleMenu) {
        Optional<Menu> menu = allMenus.stream().filter(x -> Func.equals(x.getId(), roleMenu.getParentId())).findFirst();
        if (menu.isPresent() && !routes.contains(menu.get())) {
            routes.add(menu.get());
            recursion(allMenus, routes, menu.get());
        }
    }
 
    @Override
    public List<MenuVO> buttons(String roleId) {
        List<Menu> buttons = (VciBaseUtil.checkAdminTenant()) ? baseMapper.allButtons() : baseMapper.buttons(Func.toLongList(roleId));
        MenuWrapper menuWrapper = new MenuWrapper();
        return menuWrapper.listNodeVO(buttons);
    }
 
    @Override
    public List<TreeNode> tree() {
        return ForestNodeMerger.merge(baseMapper.tree());
    }
 
    @Override
    public List<TreeNode> grantTree(BladeUser user) {
        /*List<TreeNode> menuTree = user.getTenantId().equals(nacosConfigCache.getAdminUserInfo().getTenantId())
            && user.getUserId().equals(nacosConfigCache.getAdminUserInfo().getUserId())
            ? baseMapper.grantTree() : baseMapper.grantTreeByRole(Func.toLongList(user.getRoleId()));*/
        // 修改为所有用户都能查询所有,因为没权限的用户不具备这个菜单页面的权限,也就没必要限制用户查自己的
        List<TreeNode> menuTree = baseMapper.grantTree();
        return ForestNodeMerger.merge(tenantPackageTree(menuTree, user.getTenantId()));
    }
 
    /**
     * 根据角色id获取菜单树形结构
     * @param roleId
     * @return
     */
    @Override
    public List<TreeNode> grantTreeByRoleIds(List<Long> roleId) {
        List<TreeNode> menuTree = baseMapper.grantTreeByRole(roleId);
        return ForestNodeMerger.merge(menuTree);
    }
 
    @Override
    public List<TreeNode> grantTopTree(BladeUser user) {
        List<TreeNode> menuTree = user.getTenantId().equals(NacosConfigCache.getAdminUserInfo().getTenantId()) ? baseMapper.grantTopTree() : baseMapper.grantTopTreeByRole(Func.toLongList(user.getRoleId()));
        return ForestNodeMerger.merge(tenantPackageTree(menuTree, user.getTenantId()));
    }
 
    /**
     * 租户菜单权限自定义筛选
     */
    private List<TreeNode> tenantPackageTree(List<TreeNode> menuTree, String tenantId) {
        TenantPackage tenantPackage = SysCache.getTenantPackage(tenantId);
        if (!AuthUtil.isAdministrator() && Func.isNotEmpty(tenantPackage) && tenantPackage.getId() > 0L) {
            List<Long> menuIds = Func.toLongList(tenantPackage.getMenuId());
            // 筛选出两者菜单交集集合
            List<TreeNode> collect = menuTree.stream().filter(x -> menuIds.contains(x.getId())).collect(Collectors.toList());
            // 创建递归基础集合
            List<TreeNode> packageTree = new LinkedList<>(collect);
            // 递归筛选出菜单集合所有父级
            collect.forEach(treeNode -> recursionParent(menuTree, packageTree, treeNode));
            // 递归筛选出菜单集合所有子级
            collect.forEach(treeNode -> recursionChild(menuTree, packageTree, treeNode));
            // 合并在一起返回最终集合
            return packageTree;
        }
        return menuTree;
    }
 
    /**
     * 父节点递归
     */
    public void recursionParent(List<TreeNode> menuTree, List<TreeNode> packageTree, TreeNode treeNode) {
        Optional<TreeNode> node = menuTree.stream().filter(x -> Func.equals(x.getId(), treeNode.getParentId())).findFirst();
        if (node.isPresent() && !packageTree.contains(node.get())) {
            packageTree.add(node.get());
            recursionParent(menuTree, packageTree, node.get());
        }
    }
 
    /**
     * 子节点递归
     */
    public void recursionChild(List<TreeNode> menuTree, List<TreeNode> packageTree, TreeNode treeNode) {
        List<TreeNode> nodes = menuTree.stream().filter(x -> Func.equals(x.getParentId(), treeNode.getId())).collect(Collectors.toList());
        nodes.forEach(node -> {
            if (!packageTree.contains(node)) {
                packageTree.add(node);
                recursionChild(menuTree, packageTree, node);
            }
        });
    }
 
    /**
     * 租户菜单权限自定义筛选
     */
    private List<Menu> tenantPackageMenu(List<Menu> menu) {
        // 租户包配置查询
        TenantPackage tenantPackage = SysCache.getTenantPackage(AuthUtil.getTenantId());
        if (Func.isNotEmpty(tenantPackage) && tenantPackage.getId() > 0L) {
            List<Long> menuIds = Func.toLongList(tenantPackage.getMenuId());
            menu = menu.stream().filter(x -> menuIds.contains(x.getId())).collect(Collectors.toList());
        }
        return menu;
    }
 
    @Override
    public List<TreeNode> grantDataScopeTree(BladeUser user) {
        return ForestNodeMerger.merge(user.getTenantId().equals(NacosConfigCache.getAdminUserInfo().getTenantId()) ? baseMapper.grantDataScopeTree() : baseMapper.grantDataScopeTreeByRole(Func.toLongList(user.getRoleId())));
    }
 
    @Override
    public List<TreeNode> grantApiScopeTree(BladeUser user) {
        return ForestNodeMerger.merge(user.getTenantId().equals(NacosConfigCache.getAdminUserInfo().getTenantId()) ? baseMapper.grantApiScopeTree() : baseMapper.grantApiScopeTreeByRole(Func.toLongList(user.getRoleId())));
    }
 
    @Override
    public List<String> roleTreeKeys(String roleIds) {
        List<RoleMenu> roleMenus = roleMenuService.list(Wrappers.<RoleMenu>query().lambda().in(RoleMenu::getRoleId, Func.toLongList(roleIds)));
        return roleMenus.stream().map(roleMenu -> Func.toStr(roleMenu.getMenuId())).collect(Collectors.toList());
    }
 
    @Override
    public List<String> topTreeKeys(String topMenuIds) {
        List<TopMenuSetting> settings = topMenuSettingService.list(Wrappers.<TopMenuSetting>query().lambda().in(TopMenuSetting::getTopMenuId, Func.toLongList(topMenuIds)));
        return settings.stream().map(setting -> Func.toStr(setting.getMenuId())).collect(Collectors.toList());
    }
 
    @Override
    public List<String> dataScopeTreeKeys(String roleIds) {
        List<RoleScope> roleScopes = roleScopeService.list(Wrappers.<RoleScope>query().lambda().eq(RoleScope::getScopeCategory, DATA_SCOPE_CATEGORY).in(RoleScope::getRoleId, Func.toLongList(roleIds)));
        return roleScopes.stream().map(roleScope -> Func.toStr(roleScope.getScopeId())).collect(Collectors.toList());
    }
 
    @Override
    public List<String> apiScopeTreeKeys(String roleIds) {
        List<RoleScope> roleScopes = roleScopeService.list(Wrappers.<RoleScope>query().lambda().eq(RoleScope::getScopeCategory, API_SCOPE_CATEGORY).in(RoleScope::getRoleId, Func.toLongList(roleIds)));
        return roleScopes.stream().map(roleScope -> Func.toStr(roleScope.getScopeId())).collect(Collectors.toList());
    }
 
    @Override
    @Cacheable(cacheNames = MENU_CACHE, key = "'auth:routes:' + #user.roleId")
    public List<Kv> authRoutes(BladeUser user) {
        List<MenuDTO> routes = baseMapper.authRoutes(Func.toLongList(user.getRoleId()));
        List<Kv> list = new ArrayList<>();
        routes.forEach(route -> list.add(Kv.create().set(route.getPath(), Kv.create().set("authority", Func.toStrArray(route.getAlias())))));
        return list;
    }
 
    @Override
    public boolean removeMenu(String ids) {
        Long cnt = baseMapper.selectCount(Wrappers.<Menu>query().lambda().in(Menu::getParentId, Func.toLongList(ids)));
        if (cnt > 0L) {
            throw new ServiceException("请先删除子节点!");
        }
        return removeByIds(Func.toLongList(ids));
    }
 
    @Override
    public boolean submit(Menu menu) {
        LambdaQueryWrapper<Menu> menuQueryWrapper = Wrappers.lambdaQuery();
        // 新增
        if (menu.getId() == null) {
            //检验是否重复菜单别名,只校验同一父分类菜单下的编号是否重复
            menuQueryWrapper.eq(Menu::getParentId,menu.getParentId()!=null ? menu.getParentId():BladeConstant.TOP_PARENT_ID)
                .eq(Menu::getCode, menu.getCode())
                .or(wrapper -> wrapper.eq(Menu::getName, menu.getName()).eq(Menu::getCategory, MENU_CATEGORY))
            ;
        } else {
            // 修改
            menuQueryWrapper.ne(Menu::getId, menu.getId()).and(
                wrapper -> wrapper.eq(Menu::getCode, menu.getCode())
                    .eq(Menu::getParentId,menu.getParentId())
                    .or(o -> o.eq(Menu::getName, menu.getName()).eq(Menu::getCategory, MENU_CATEGORY))
            );
        }
        Long cnt = baseMapper.selectCount(menuQueryWrapper);
        if (cnt > 0L) {
            throw new ServiceException("菜单名或编号已存在!");
        }
        if (menu.getParentId() == null && menu.getId() == null) {
            menu.setParentId(BladeConstant.TOP_PARENT_ID);
        }
        if (menu.getParentId() != null && menu.getId() == null) {
            Menu parentMenu = baseMapper.selectById(menu.getParentId());
            if (parentMenu != null && parentMenu.getCategory() != 1) {
                throw new ServiceException("父节点只可选择菜单类型!");
            }
        }
        menu.setIsDeleted(BladeConstant.DB_NOT_DELETED);
        return saveOrUpdate(menu);
    }
 
    /**
     * 获取菜单下面的按钮,别乱调用,这个方法是针对主数据管理按钮查询的
     * @param classifyId
     * @param btmType 业务类型
     * @param authType
     * @return
     */
    @Override
    //@Cacheable(cacheNames = MENU_CACHE, key = "'auth:menuButton:'+ #btmType +':'+ #userId ")
    public List<Menu> getMenuButtonByType(String classifyId,String btmType,String authType) {
        // baseMapper.selectMenuChildByBtnType(btmType,roleIds);
        if(Func.isBlank(classifyId)){
            throw new ServiceException("必传参数分类oid不能为空!");
        }
        //查询分类节点的所有父级节点
        R<List<String>> listR = codeClassifyClient.selectAllParentOid(classifyId);
        if (!listR.isSuccess() && !listR.getData().isEmpty()) {
            throw new ServiceException("获取分类信息失败!");
        }
        // 返回的分类oid是当前节点为第一个,后面依次是他的上层节点
        List<String> classifyOidList = listR.getData();
        final String roleIds = AuthUtil.getUser().getRoleId();
        // 先查询按钮id列表
        LambdaQueryWrapper<ClassifyAuth> wrapper = Wrappers.<ClassifyAuth>query()
            .lambda().eq(ClassifyAuth::getClassifyId, classifyId)
            .eq(ClassifyAuth::getAuthType,authType)
            .in(ClassifyAuth::getRoleId, roleIds);
        List<ClassifyAuth> classifyAuths = classifyAuthMapper.selectList(wrapper);
        //如果当前分类没有找到授权配置,就依次从当前节点往上层节点找授权配置,找到了就停止,没找到就一直找到最后
        if(classifyAuths.isEmpty()){
            // 下标从1开始因为当前节点0已经查询过
            for (int i = 1; i < classifyOidList.size(); i++) {
                classifyAuths = classifyAuthMapper.selectList(
                    Wrappers.<ClassifyAuth>query()
                        .lambda().eq(ClassifyAuth::getClassifyId, classifyOidList.get(i))
                        .in(ClassifyAuth::getRoleId, roleIds)
                );
                if(!classifyAuths.isEmpty()){
                    break;
                }
            }
        }
        //出现了错误数据,同一个角色和同一个分类id存在多条授权记录
        if(classifyAuths.size()>1){
            throw new ServiceException("角色和分类配置存在多条记录,请联系管理人员清理错误配置!");
        }
        // 是否为超管
        Boolean isAdmin = VciBaseUtil.checkAdminTenant();
        // 未配置按钮权限
        if(!isAdmin && (classifyAuths.isEmpty() || Func.isBlank(classifyAuths.get(0).getButtonIds()))){
            return new ArrayList<>();
        }
        List<String> ids = new ArrayList<>();
        // 如果不是超管用户
        if(!isAdmin){
            ids.addAll(Arrays.asList(classifyAuths.get(0).getButtonIds().split(",")));
        }
        return this.getMenuListByCode(ids,btmType,roleIds);
    }
 
    /**
     * 根据code查询菜单信息
     * @param codes
     * @param userId
     * @return
     */
    @Override
    public List<Menu> getMenuByCodes(List<String> codes,Long userId) {
        if(codes.isEmpty()){
            return new ArrayList<>();
        }
        // 查询菜单信息
        LambdaQueryWrapper<Menu> wrapper = Wrappers.<Menu>query()
            .lambda()
            .in(Menu::getCode, codes)
            .eq(Menu::getIsDeleted,BladeConstant.DB_NOT_DELETED) /*未被删除*/
            .eq(Menu::getCategory,1) /*菜单类型不能为按钮*/
            .orderByAsc(Menu::getCode);  /*根据code排序与classify的btmtypeid对应*/
        // 超管不用根据角色来查询
        if(!VciBaseUtil.checkAdminTenant()){
            if(Func.isBlank(userId.toString()) && Func.isBlank(AuthUtil.getUserId().toString())){
                throw new ServiceException("获取用户id失败");
            }
            List<Long> menuIds = roleMenuService.getMenuIdByUserId(userId);
            if(menuIds.isEmpty()){
                return new ArrayList<>();
            }
            if(menuIds.size()>=1000){
                MybatisParameterUtil.cutInParameter(wrapper,Menu::getId,menuIds);
            }else {
                wrapper.in(Menu::getId,menuIds);
            }
        }
        return this.list(wrapper);
    }
 
    /**
     * 根据父级菜单的code查询按钮信息
     * @param code
     * @return
     */
    @Override
    public List<Menu> getButtonByParentCode(String code) {
        return menuMapper.getButtonsByRoleIdAndCode(null,code);
    }
 
    /**
     * 对KeepAlive值转换成布尔类型进行封装
     *
     * @param childMenu
     * @return
     */
    @Override
    public void handleKeepAlive(List<MenuVO> childMenu) {
        childMenu.forEach(list->{
            list.getMeta().put("keepAlive","true".equals(list.getKeepAlive()));
            if(list.getChildren().size()>0){
                handleKeepAlive(list.getChildren());
            }
        });
    }
 
    /**
     * 克隆其他菜单下按钮
     * @param menuId 要克隆的菜单按钮主键
     * @param buttonIds 被克隆的按钮主键
     * @return
     */
    @Override
    public R cloneMenuButton(Long menuId, List<String> buttonIds) {
        if(Func.isEmpty(menuId)){
            return R.fail("要克隆的菜单主键不能为空!");
        }
        if(buttonIds.isEmpty() || buttonIds.size() <= 0){
            return R.fail("被克隆的按钮主键不能为空!");
        }
        // 先根据主键查询出所有按钮的信息
        List<Menu> buttons = this.listByIds(buttonIds);
        List<Menu> newButtons = new ArrayList<>();
        List<String> addButtonCodes = new ArrayList();
        buttons.parallelStream().forEach(item->{
            // 判断是否为按钮,非按钮不处理
            if(item.getCategory().equals(2)){
                // 改变父节点信息
                item.setParentId(menuId);
                // 将主键赋空
                item.setId(null);
                addButtonCodes.add(item.getCode());
                newButtons.add(item);
            }
        });
        //检验是否重复菜单别名,只校验同一父分类菜单下的编号是否重复
        LambdaQueryWrapper<Menu> menuQueryWrapper = Wrappers.<Menu>lambdaQuery()
            .eq(Menu::getParentId,menuId)
            .and(a -> a.in( Menu::getCode, addButtonCodes));
        Long cnt = baseMapper.selectCount(menuQueryWrapper);
        if (cnt > 0L) {
            return R.fail("该菜单下已存在的编号与要克隆的按钮编号存在重复!");
        }
        return this.saveBatch(newButtons) ? R.success("按钮克隆成功!"):R.fail("按钮克隆失败!");
    }
 
    /**
     * 根据主键获取菜单信息
     * @param ids
     * @param menuCode
     * @param roleIds
     * @return
     */
    @Override
    public List<Menu> getMenuListByCode(List<String> ids,String menuCode,String roleIds){
        List<Menu> menuButtonList = null;
        if(VciBaseUtil.checkAdminTenant()){
            // 正常情况下来说这个不存在为空的情况
            // 查询该菜单下的所有按钮
            menuButtonList = menuMapper.getButtonByIdsOrByParentCode(null, menuCode, null);
        }else {
            menuButtonList = menuMapper.getButtonByIdsOrByParentCode(roleIds,null,ids);
        }
        return menuButtonList;
    }
 
    /**
     * 根据角色id获取已授权的按钮信息
     * @param roleId
     * @return
     */
    @Override
    public List<Menu> getButtonsByRoleId(String roleId, String menuCode) {
        return menuMapper.getButtonsByRoleIdAndCode(roleId,menuCode);
    }
 
}