|
|
@@ -1,74 +1,61 @@
|
|
|
package cn.reghao.autodop.dmaster.view.controller;
|
|
|
|
|
|
-import cn.reghao.autodop.dmaster.auth.entity.GrantedAuthorityImpl;
|
|
|
+import cn.reghao.autodop.dmaster.auth.entity.DataStatus;
|
|
|
import cn.reghao.autodop.dmaster.auth.entity.Role;
|
|
|
-import cn.reghao.autodop.dmaster.auth.entity.User;
|
|
|
-import cn.reghao.autodop.dmaster.auth.repository.RoleRepository;
|
|
|
import cn.reghao.autodop.dmaster.utils.WebBody;
|
|
|
-import cn.reghao.autodop.dmaster.auth.repository.UserRepository;
|
|
|
import cn.reghao.autodop.dmaster.auth.entity.Menu;
|
|
|
-import cn.reghao.autodop.dmaster.auth.repository.MenuRepository;
|
|
|
+import cn.reghao.autodop.dmaster.view.service.ResourceService;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.ui.Model;
|
|
|
-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.ResponseBody;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.util.*;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author reghao
|
|
|
* @date 2021-04-04 21:24:18
|
|
|
*/
|
|
|
+@Api(tags = "资源页面")
|
|
|
@RequestMapping("/system/menu")
|
|
|
@Controller
|
|
|
public class ResourcePageController {
|
|
|
- private final UserRepository userRepository;
|
|
|
- private final RoleRepository roleRepository;
|
|
|
- private final MenuRepository menuRepository;
|
|
|
+ private ResourceService resourceService;
|
|
|
|
|
|
- public ResourcePageController(UserRepository userRepository,
|
|
|
- RoleRepository roleRepository,
|
|
|
- MenuRepository menuRepository) {
|
|
|
- this.userRepository = userRepository;
|
|
|
- this.roleRepository = roleRepository;
|
|
|
- this.menuRepository = menuRepository;
|
|
|
+ public ResourcePageController(ResourceService resourceService) {
|
|
|
+ this.resourceService = resourceService;
|
|
|
}
|
|
|
|
|
|
+ @ApiOperation(value = "获取资源页面")
|
|
|
@GetMapping
|
|
|
- public String systemMenu(Model model) {
|
|
|
+ public String systemMenu(@RequestParam(value = "status", required = false) String status, Model model) {
|
|
|
+ if (status == null) {
|
|
|
+ status = DataStatus.ENABLE.name();
|
|
|
+ }
|
|
|
+ model.addAttribute("status", status);
|
|
|
return "/system/menu/index";
|
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "获取所有的资源")
|
|
|
- @GetMapping(value = "/list", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
+ @GetMapping(value = "/list/{status}", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
@ResponseBody
|
|
|
- public String list() {
|
|
|
- List<Menu> menuList = menuRepository.findAll();
|
|
|
- Map<Integer, List<Menu>> map = menuList.stream()
|
|
|
- .collect(Collectors.groupingBy(Menu::getPid));
|
|
|
-
|
|
|
- List<Menu> list = new ArrayList<>();
|
|
|
- map.forEach((pid, menus) -> {
|
|
|
- list.addAll(menus.stream()
|
|
|
- .sorted(Comparator.comparing(Menu::getSort))
|
|
|
- .peek(menu -> menu.setChildren(null))
|
|
|
- .collect(Collectors.toList()));
|
|
|
- });
|
|
|
+ public String list(@PathVariable(value = "status", required = false) String status) {
|
|
|
+ if (status == null) {
|
|
|
+ status = DataStatus.ENABLE.name();
|
|
|
+ }
|
|
|
+ List<Menu> list = resourceService.getResourceByStatus(status);
|
|
|
return WebBody.success(list);
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value = "资源添加页面")
|
|
|
+ @ApiOperation(value = "获取资源添加页面")
|
|
|
@GetMapping({"/add", "/add/{pid}"})
|
|
|
public String toAdd(@PathVariable(value = "pid", required = false) Integer pid, Model model) {
|
|
|
// 父级菜单
|
|
|
Menu pMenu = null;
|
|
|
if (pid != null) {
|
|
|
- pMenu = menuRepository.findById(pid.intValue());
|
|
|
+ pMenu = resourceService.getResourceById(pid);
|
|
|
}
|
|
|
model.addAttribute("pMenu", pMenu);
|
|
|
return "/system/menu/add";
|
|
|
@@ -79,20 +66,61 @@ public class ResourcePageController {
|
|
|
@ResponseBody
|
|
|
public String sortList(@PathVariable(value = "pid") int pid,
|
|
|
@PathVariable(value = "notId", required = false) int notId) {
|
|
|
-
|
|
|
- List<Menu> menus = menuRepository.findByPid(pid);
|
|
|
- Map<Integer, String> map = new HashMap<>();
|
|
|
- menus.forEach(menu -> {
|
|
|
- map.put(menu.getSort(), menu.getTitle());
|
|
|
- });
|
|
|
- //map.put("1", "用户管理");
|
|
|
+ Map<Integer, String> map = resourceService.getMapByPid(pid);
|
|
|
return WebBody.success(map);
|
|
|
}
|
|
|
|
|
|
+ // TODO Hibernate 会根据传入的 id 自动查找相应的 Menu
|
|
|
@GetMapping("/roleList/{id}")
|
|
|
- public String roleListWithResource(@PathVariable("id") Role role, Model model) {
|
|
|
- List<Role> list = roleRepository.findAll();
|
|
|
+ public String roleListWithResource(@PathVariable("id") Menu menu, Model model) {
|
|
|
+ List<Role> list = new ArrayList<>(menu.getRoles());
|
|
|
model.addAttribute("list", list);
|
|
|
return "/system/menu/roleList";
|
|
|
}
|
|
|
+
|
|
|
+ @ApiOperation(value = "获取资源编辑页面")
|
|
|
+ @GetMapping("/edit/{id}")
|
|
|
+ public String toEdit(@PathVariable("id") Menu menu, Model model) {
|
|
|
+ int pid = menu.getPid();
|
|
|
+ Menu pMenu;
|
|
|
+ if (pid == 0) {
|
|
|
+ pMenu = new Menu(pid, "根菜单");
|
|
|
+ } else {
|
|
|
+ pMenu = resourceService.getResourceById(pid);
|
|
|
+ }
|
|
|
+
|
|
|
+ model.addAttribute("menu", menu);
|
|
|
+ model.addAttribute("pMenu", pMenu);
|
|
|
+ return "/system/menu/add";
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "获取资源详细页面")
|
|
|
+ @GetMapping("/detail/{id}")
|
|
|
+ public String toDetail(@PathVariable("id") Menu menu, Model model) {
|
|
|
+ model.addAttribute("menu", menu);
|
|
|
+ return "/system/menu/detail";
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "添加资源")
|
|
|
+ @PostMapping(value = "/save", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
+ @ResponseBody
|
|
|
+ public String addMenu(Menu menu) {
|
|
|
+ resourceService.addResource(menu);
|
|
|
+ return WebBody.success("ok");
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "修改资源状态")
|
|
|
+ @PostMapping(value = "/status/{status}", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
+ @ResponseBody
|
|
|
+ public String menuStatus(@PathVariable("status") String status,
|
|
|
+ @RequestParam("ids") List<Integer> ids) {
|
|
|
+ return WebBody.success("ok");
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "删除资源")
|
|
|
+ @DeleteMapping(value = "/status1/{ids}", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
+ @ResponseBody
|
|
|
+ public String deleteMenu(@PathVariable("ids") List<Integer> ids) {
|
|
|
+ return WebBody.success("ok");
|
|
|
+ }
|
|
|
}
|