houzhongjian
2024-10-16 7da8f196dee8e3c526c009a4bc7f5983ece6bb97
提交 | 用户 | 时间
818a01 1 package com.iailab.module.system.api.app;
H 2
3 import cn.hutool.core.collection.CollUtil;
4 import com.iailab.framework.common.pojo.CommonResult;
5 import com.iailab.framework.common.util.object.BeanUtils;
6 import com.iailab.module.system.api.app.dto.AppMenuRespDTO;
7 import com.iailab.module.system.api.app.dto.AppRespDTO;
8 import com.iailab.module.system.controller.admin.app.vo.AppRespVO;
9 import com.iailab.module.system.convert.app.AppConvert;
10 import com.iailab.module.system.dal.dataobject.app.AppDO;
11 import com.iailab.module.system.dal.dataobject.app.AppMenuDO;
12 import com.iailab.module.system.service.app.AppMenuService;
13 import com.iailab.module.system.service.app.AppService;
14 import org.springframework.validation.annotation.Validated;
15 import org.springframework.web.bind.annotation.RestController;
16
17 import javax.annotation.Resource;
18 import java.util.*;
19
20 import static com.iailab.framework.common.pojo.CommonResult.success;
21 import static com.iailab.framework.common.util.collection.CollectionUtils.convertSet;
22
23 @RestController // 提供 RESTful API 接口,给 Feign 调用
24 @Validated
25 public class AppMenuApiImpl implements AppMenuApi {
26
27     @Resource
28     private AppMenuService appMenuService;
29
30     @Resource
31     private AppService appService;
32
33     @Override
34     public CommonResult<List<AppMenuRespDTO>> getAppMenuList(Long id) {
35         List<AppMenuDO> children = new LinkedList<>();
36         // 遍历每一层
37         Collection<Long> parentIds = Collections.singleton(id);
38         for (int i = 0; i < Short.MAX_VALUE; i++) { // 使用 Short.MAX_VALUE 避免 bug 场景下,存在死循环
39             // 查询当前层,所有的子应用菜单
40             List<AppMenuDO> menus = appMenuService.selectListByParentId(parentIds);
41             // 1. 如果没有子菜单,则结束遍历
42             if (CollUtil.isEmpty(menus)) {
43                 break;
44             }
45             // 2. 如果有子应用菜单,继续遍历
46             children.addAll(menus);
47             parentIds = convertSet(menus, AppMenuDO::getId);
48         }
49 //        children = appMenuService.filterDisableMenus(children);
50         return success(AppConvert.INSTANCE.buildMenuTree(id, children));
51     }
52
53     @Override
54     public CommonResult<List<AppRespDTO>> getAppList() {
55         List<AppDO> list = appService.getList();
56         list.sort(Comparator.comparing(AppDO::getOrderNum));
57         return success(BeanUtils.toBean(list, AppRespDTO.class));
58     }
59 }