ny
昨天 b6f169fe43a2b13f351aefc152374fc7f0bc8cb7
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
package jnpf.controller;
 
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jnpf.base.ActionResult;
import jnpf.base.Page;
import jnpf.base.SystemApi;
import jnpf.base.UserInfo;
import jnpf.base.model.base.SystemBaeModel;
import jnpf.base.model.module.ModuleModel;
import jnpf.base.vo.ListVO;
import jnpf.constant.JnpfConst;
import jnpf.model.AppMenuListVO;
import jnpf.model.UserMenuModel;
import jnpf.model.login.UserSystemVO;
import jnpf.permission.AuthorizeApi;
import jnpf.permission.model.authorize.AuthorizeVO;
import jnpf.util.JsonUtil;
import jnpf.util.StringUtil;
import jnpf.util.UserProvider;
import jnpf.util.context.RequestContext;
import jnpf.util.treeutil.ListToTreeUtil;
import jnpf.util.treeutil.SumTree;
import jnpf.util.treeutil.newtreeutil.TreeDotUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
 
/**
 * app应用
 *
 * @author JNPF开发平台组
 * @version V3.1.0
 * @copyright 引迈信息技术有限公司(https://www.jnpfsoft.com)
 * @date 2021-07-08
 */
@Tag(name = "app应用", description = "Menu")
@RestController
@RequestMapping("/Menu")
public class AppMenuController {
    @Autowired
    private AuthorizeApi authorizeService;
    @Autowired
    private SystemApi systemApi;
 
    /**
     * 获取菜单列表
     *
     * @param page 分页模型
     * @return
     */
    @Operation(summary = "获取菜单列表")
    @GetMapping
    public ActionResult<ListVO<AppMenuListVO>> list(Page page) {
        AuthorizeVO authorizeModel = authorizeService.getAuthorize(false, RequestContext.getAppCode(), 0);
        List<ModuleModel> buttonListAll = authorizeModel.getModuleList().stream().filter(t ->
                JnpfConst.APP.equals(t.getCategory()) && !JnpfConst.MODULE_CODE.contains(t.getEnCode())).collect(Collectors.toList());
        // 通过系统id捞取相应的菜单
        buttonListAll = buttonListAll.stream().filter(t -> UserProvider.getUser().getAppSystemId() != null && UserProvider.getUser().getAppSystemId().equals(t.getSystemId())).collect(Collectors.toList());
        List<ModuleModel> buttonList = buttonListAll;
        if (StringUtil.isNotEmpty(page.getKeyword())) {
            buttonList = buttonListAll.stream().filter(t -> t.getFullName().contains(page.getKeyword())).collect(Collectors.toList());
        }
        List<UserMenuModel> list = JsonUtil.getJsonToList(ListToTreeUtil.treeWhere(buttonList, buttonListAll), UserMenuModel.class);
        List<SumTree<UserMenuModel>> menuAll = TreeDotUtils.convertListToTreeDot(list, "-1");
        List<AppMenuListVO> data = JsonUtil.getJsonToList(menuAll, AppMenuListVO.class);
        ListVO listVO = new ListVO();
        listVO.setList(data);
        return ActionResult.success(listVO);
    }
 
    /**
     * 获取子集菜单
     *
     * @return
     */
    @Operation(summary = "获取子集菜单")
    @GetMapping("/getChildList/{id}")
    public ActionResult<List<AppMenuListVO>> getChildList(@PathVariable("id") String id) {
        AuthorizeVO authorizeModel = authorizeService.getAuthorize(false, RequestContext.getAppCode(), 0);
        List<ModuleModel> buttonListAll = authorizeModel.getModuleList().stream().filter(t -> JnpfConst.APP.equals(t.getCategory())).collect(Collectors.toList());
        // 通过系统id捞取相应的菜单
        buttonListAll = buttonListAll.stream().filter(t -> UserProvider.getUser().getAppSystemId() != null && UserProvider.getUser().getAppSystemId().equals(t.getSystemId())).collect(Collectors.toList());
        Set<ModuleModel> models = new HashSet<>();
        next(buttonListAll, id, models);
        List<UserMenuModel> list = JsonUtil.getJsonToList(models, UserMenuModel.class);
        List<SumTree<UserMenuModel>> menuAll = TreeDotUtils.convertListToTreeDot(list);
        List<AppMenuListVO> data = JsonUtil.getJsonToList(menuAll, AppMenuListVO.class);
        return ActionResult.success(data);
    }
 
    private void next(List<ModuleModel> buttonListAll, String parentId, Set<ModuleModel> list) {
        List<ModuleModel> menuList = buttonListAll.stream().filter(t -> t.getId().equals(parentId) || t.getParentId().equals(parentId)).collect(Collectors.toList());
        for (ModuleModel model : menuList) {
            if (!list.contains(model)) {
                list.add(model);
                next(buttonListAll, model.getId(), list);
            }
        }
    }
 
    @Operation(summary = "获取应用列表")
    @GetMapping("/sys")
    public ActionResult<List<UserSystemVO>> listSys() {
        AuthorizeVO authorizeModel = authorizeService.getAuthorizeByUser(false);
        List<SystemBaeModel> systemList = authorizeModel.getSystemList();
        UserInfo userInfo = UserProvider.getUser();
        List<UserSystemVO> jsonToList1 = new ArrayList<>();
        systemList.forEach(t -> {
            UserSystemVO systemVO = new UserSystemVO();
            systemVO.setId(t.getId());
            systemVO.setName(t.getFullName());
            systemVO.setIcon(t.getIcon());
            if (userInfo.getAppSystemId().equals(t.getId())) {
                systemVO.setCurrentSystem(true);
            }
            systemVO.setEnCode(t.getEnCode());
            jsonToList1.add(systemVO);
        });
        return ActionResult.success(jsonToList1);
    }
 
}