AppMenuController.java 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. package jnpf.controller;
  2. import io.swagger.v3.oas.annotations.Operation;
  3. import io.swagger.v3.oas.annotations.tags.Tag;
  4. import jnpf.base.ActionResult;
  5. import jnpf.base.Page;
  6. import jnpf.base.UserInfo;
  7. import jnpf.base.model.base.SystemBaeModel;
  8. import jnpf.base.model.module.ModuleModel;
  9. import jnpf.base.service.SystemService;
  10. import jnpf.base.vo.ListVO;
  11. import jnpf.constant.JnpfConst;
  12. import jnpf.model.AppMenuListVO;
  13. import jnpf.model.UserMenuModel;
  14. import jnpf.model.login.UserSystemVO;
  15. import jnpf.permission.model.authorize.AuthorizeVO;
  16. import jnpf.permission.service.AuthorizeService;
  17. import jnpf.util.JsonUtil;
  18. import jnpf.util.StringUtil;
  19. import jnpf.util.UserProvider;
  20. import jnpf.util.context.RequestContext;
  21. import jnpf.util.treeutil.ListToTreeUtil;
  22. import jnpf.util.treeutil.SumTree;
  23. import jnpf.util.treeutil.newtreeutil.TreeDotUtils;
  24. import org.springframework.beans.factory.annotation.Autowired;
  25. import org.springframework.web.bind.annotation.GetMapping;
  26. import org.springframework.web.bind.annotation.PathVariable;
  27. import org.springframework.web.bind.annotation.RequestMapping;
  28. import org.springframework.web.bind.annotation.RestController;
  29. import java.util.ArrayList;
  30. import java.util.HashSet;
  31. import java.util.List;
  32. import java.util.Set;
  33. import java.util.stream.Collectors;
  34. /**
  35. * app应用
  36. *
  37. * @author JNPF开发平台组
  38. * @version V3.1.0
  39. * @copyright 引迈信息技术有限公司(https://www.jnpfsoft.com)
  40. * @date 2021-07-08
  41. */
  42. @Tag(name = "app应用", description = "Menu")
  43. @RestController
  44. @RequestMapping("/api/app/Menu")
  45. public class AppMenuController {
  46. @Autowired
  47. private AuthorizeService authorizeService;
  48. @Autowired
  49. private SystemService systemApi;
  50. /**
  51. * 获取菜单列表
  52. *
  53. * @param page 分页模型
  54. * @return
  55. */
  56. @Operation(summary = "获取菜单列表")
  57. @GetMapping
  58. public ActionResult<ListVO<AppMenuListVO>> list(Page page) {
  59. AuthorizeVO authorizeModel = authorizeService.getAuthorize(false, RequestContext.getAppCode(), 0);
  60. List<ModuleModel> buttonListAll = authorizeModel.getModuleList().stream().filter(t ->
  61. JnpfConst.APP.equals(t.getCategory()) && !JnpfConst.MODULE_CODE.contains(t.getEnCode())).collect(Collectors.toList());
  62. // 通过系统id捞取相应的菜单
  63. buttonListAll = buttonListAll.stream().filter(t -> UserProvider.getUser().getAppSystemId() != null && UserProvider.getUser().getAppSystemId().equals(t.getSystemId())).collect(Collectors.toList());
  64. List<ModuleModel> buttonList = buttonListAll;
  65. if (StringUtil.isNotEmpty(page.getKeyword())) {
  66. buttonList = buttonListAll.stream().filter(t -> t.getFullName().contains(page.getKeyword())).collect(Collectors.toList());
  67. }
  68. List<UserMenuModel> list = JsonUtil.getJsonToList(ListToTreeUtil.treeWhere(buttonList, buttonListAll), UserMenuModel.class);
  69. List<SumTree<UserMenuModel>> menuAll = TreeDotUtils.convertListToTreeDot(list, "-1");
  70. List<AppMenuListVO> data = JsonUtil.getJsonToList(menuAll, AppMenuListVO.class);
  71. ListVO listVO = new ListVO();
  72. listVO.setList(data);
  73. return ActionResult.success(listVO);
  74. }
  75. /**
  76. * 获取子集菜单
  77. *
  78. * @return
  79. */
  80. @Operation(summary = "获取子集菜单")
  81. @GetMapping("/getChildList/{id}")
  82. public ActionResult<List<AppMenuListVO>> getChildList(@PathVariable("id") String id) {
  83. AuthorizeVO authorizeModel = authorizeService.getAuthorize(false, RequestContext.getAppCode(), 0);
  84. List<ModuleModel> buttonListAll = authorizeModel.getModuleList().stream().filter(t -> JnpfConst.APP.equals(t.getCategory())).collect(Collectors.toList());
  85. // 通过系统id捞取相应的菜单
  86. buttonListAll = buttonListAll.stream().filter(t -> UserProvider.getUser().getAppSystemId() != null && UserProvider.getUser().getAppSystemId().equals(t.getSystemId())).collect(Collectors.toList());
  87. Set<ModuleModel> models = new HashSet<>();
  88. next(buttonListAll, id, models);
  89. List<UserMenuModel> list = JsonUtil.getJsonToList(models, UserMenuModel.class);
  90. List<SumTree<UserMenuModel>> menuAll = TreeDotUtils.convertListToTreeDot(list);
  91. List<AppMenuListVO> data = JsonUtil.getJsonToList(menuAll, AppMenuListVO.class);
  92. return ActionResult.success(data);
  93. }
  94. private void next(List<ModuleModel> buttonListAll, String parentId, Set<ModuleModel> list) {
  95. List<ModuleModel> menuList = buttonListAll.stream().filter(t -> t.getId().equals(parentId) || t.getParentId().equals(parentId)).collect(Collectors.toList());
  96. for (ModuleModel model : menuList) {
  97. if (!list.contains(model)) {
  98. list.add(model);
  99. next(buttonListAll, model.getId(), list);
  100. }
  101. }
  102. }
  103. @Operation(summary = "获取应用列表")
  104. @GetMapping("/sys")
  105. public ActionResult<List<UserSystemVO>> listSys() {
  106. AuthorizeVO authorizeModel = authorizeService.getAuthorizeByUser(false);
  107. List<SystemBaeModel> systemList = authorizeModel.getSystemList();
  108. UserInfo userInfo = UserProvider.getUser();
  109. List<UserSystemVO> jsonToList1 = new ArrayList<>();
  110. systemList.forEach(t -> {
  111. UserSystemVO systemVO = new UserSystemVO();
  112. systemVO.setId(t.getId());
  113. systemVO.setName(t.getFullName());
  114. systemVO.setIcon(t.getIcon());
  115. if (userInfo.getAppSystemId().equals(t.getId())) {
  116. systemVO.setCurrentSystem(true);
  117. }
  118. systemVO.setEnCode(t.getEnCode());
  119. jsonToList1.add(systemVO);
  120. });
  121. return ActionResult.success(jsonToList1);
  122. }
  123. }