SysMenuController.java 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package com.fdkankan.manage.controller;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.fdkankan.manage.common.ResultCode;
  4. import com.fdkankan.manage.config.MenuInit;
  5. import com.fdkankan.manage.exception.BusinessException;
  6. import com.fdkankan.manage.vo.request.RequestBase;
  7. import com.fdkankan.manage.common.ResultData;
  8. import com.fdkankan.common.util.DateUtil;
  9. import com.fdkankan.manage.entity.SysMenu;
  10. import com.fdkankan.manage.service.ISysMenuService;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.util.StringUtils;
  13. import org.springframework.web.bind.annotation.*;
  14. import java.util.Date;
  15. import java.util.List;
  16. /**
  17. * 系统菜单
  18. */
  19. @RestController
  20. @RequestMapping("/service/manage/sysMenu")
  21. public class SysMenuController extends BaseController{
  22. @Autowired
  23. ISysMenuService menuService;
  24. @Autowired
  25. MenuInit menuInit;
  26. @PostMapping("/add")
  27. public ResultData add(@RequestBody SysMenu param){
  28. param.setUpdateTime(DateUtil.date2String(new Date(),DateUtil.DEFAULT_DATE_FORMAT));
  29. menuService.saveOrUpdate(param);
  30. menuInit.initMenu();
  31. return ResultData.ok();
  32. }
  33. @PostMapping("/update")
  34. public ResultData update(@RequestBody SysMenu param){
  35. if(StringUtils.isEmpty(param.getId())){
  36. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  37. }
  38. param.setUpdateTime(DateUtil.date2String(new Date(),DateUtil.DEFAULT_DATE_FORMAT));
  39. menuService.saveOrUpdate(param);
  40. menuInit.initMenu();
  41. return ResultData.ok();
  42. }
  43. @PostMapping("/delete")
  44. public ResultData delete(@RequestBody SysMenu param){
  45. LambdaQueryWrapper<SysMenu> wrapper = new LambdaQueryWrapper<>();
  46. wrapper.eq(SysMenu::getParentId,param.getId());
  47. menuService.remove(wrapper);
  48. menuService.removeById(param.getId());
  49. menuInit.initMenu();
  50. return ResultData.ok();
  51. }
  52. @PostMapping("/list")
  53. public ResultData list(@RequestBody RequestBase param){
  54. return ResultData.ok(menuService.pageList(param));
  55. }
  56. @PostMapping("/allShowList")
  57. public ResultData allShowList(){
  58. return ResultData.ok(menuService.allShowList());
  59. }
  60. @GetMapping("/getByUserId")
  61. public ResultData getByUserId(){
  62. return ResultData.ok(menuService.getByUserId(getUserId()));
  63. }
  64. @GetMapping("/getButtonByUserId")
  65. public ResultData getButtonByUserId(){
  66. return ResultData.ok(menuService.getButtonByUserId(getUserId()));
  67. }
  68. @GetMapping("/getByRoleId")
  69. public ResultData getByRoleId(@RequestParam(required = false) Long roleId){
  70. return ResultData.ok(menuService.getByRoleId(null,roleId));
  71. }
  72. @GetMapping("/getMenuIdsByRoleId")
  73. public ResultData getMenuIdsByRoleId(@RequestParam(required = false) Long roleId){
  74. return ResultData.ok(menuService.getMenuIdsByRoleId(roleId));
  75. }
  76. }