MenuController.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. package com.xintong.visualinspection.controller;
  2. import java.util.List;
  3. import org.springframework.beans.factory.annotation.Autowired;
  4. import org.springframework.security.access.prepost.PreAuthorize;
  5. import org.springframework.web.bind.annotation.PathVariable;
  6. import org.springframework.web.bind.annotation.RequestBody;
  7. import org.springframework.web.bind.annotation.RequestMapping;
  8. import org.springframework.web.bind.annotation.RequestMethod;
  9. import org.springframework.web.bind.annotation.RestController;
  10. import com.github.pagehelper.PageHelper;
  11. import com.github.pagehelper.PageInfo;
  12. import com.xintong.system.err.BusinessException;
  13. import com.xintong.visualinspection.bean.Menu;
  14. import com.xintong.visualinspection.service.MenuService;
  15. /**
  16. * 文件名:TestController
  17. * 版本信息:日期:2017/3/30 Copyright 江苏省交通规划设计院 Corporation 2017 版权所有.
  18. */
  19. /**
  20. * @author wenhongquan
  21. *
  22. */
  23. @RestController
  24. @RequestMapping("/menu")
  25. public class MenuController extends BaseController {
  26. @Autowired
  27. private MenuService menuService;
  28. /**
  29. * 添加菜单
  30. * @return
  31. * String
  32. * @exception
  33. * @since 1.0.0
  34. */
  35. // @PreAuthorize("hasRole('ADMIN')")
  36. @RequestMapping(value = "/addMenu",method=RequestMethod.POST,produces="application/json;charset=UTF-8")
  37. public String addMenu(@RequestBody Menu menu) throws Exception{
  38. menu.setStatus(0);
  39. menuService.insert(menu);
  40. return returnResult(0, "添加成功", null);
  41. }
  42. /**
  43. * 修改菜单
  44. * @return
  45. * String
  46. * @exception
  47. * @since 1.0.0
  48. */
  49. @RequestMapping(value = "/updateMenu/{menuid}",produces="application/json;charset=UTF-8")
  50. public String updateMenu(@RequestBody Menu menu,@PathVariable int menuid){
  51. try{
  52. menu.setId(menuid);
  53. menuService.update(menu);
  54. return super.returnResult(0, "修改成功", null);
  55. }catch(Exception e){
  56. throw new BusinessException(20003);
  57. }
  58. }
  59. /**
  60. * 删除菜单(软删除)
  61. * @return
  62. * String
  63. * @exception
  64. * @since 1.0.0
  65. */
  66. @RequestMapping(value = "/deleteMenu/{menuid}",produces="application/json;charset=UTF-8")
  67. public String deleteMenu(@PathVariable Integer menuid){
  68. try{
  69. menuService.delete((menuid));
  70. return returnResult(0, "删除成功", null);
  71. }catch(Exception e){
  72. throw new BusinessException(20002);
  73. }
  74. }
  75. /**
  76. * 获取所有菜单
  77. * @param page
  78. * @param size
  79. * @return
  80. */
  81. @RequestMapping(value = "/get/all",method=RequestMethod.GET,produces="application/json;charset=UTF-8")
  82. public String getAllMenu(){
  83. try{
  84. List<Menu> menus= menuService.getMenus(new Menu());
  85. return returnResult(0, "获取成功", menus);
  86. }catch(Exception e){
  87. throw new BusinessException(20001);
  88. }
  89. }
  90. @RequestMapping(value = "/getMenuByParent/{pid}/{page}/{size}",produces="application/json;charset=UTF-8")
  91. public String getMenuByParent(@PathVariable Integer pid,@PathVariable Integer page,@PathVariable Integer size){
  92. try{
  93. PageHelper.startPage(page, size);
  94. Menu menu =new Menu();
  95. menu.setParentId(pid);
  96. List<Menu> menus= menuService.getMenuByParent(menu);
  97. return returnResult(0, "获取成功", new PageInfo(menus));
  98. }catch(Exception e){
  99. throw new BusinessException(20001);
  100. }
  101. }
  102. @RequestMapping(value = "/getMenuById/{menuid}",method=RequestMethod.GET,produces="application/json;charset=UTF-8")
  103. public String getMenuById(@PathVariable Integer menuid){
  104. try{
  105. Menu menu = new Menu();
  106. menu.setId(menuid);
  107. List<Menu> menus = menuService.getMenus(menu);
  108. if(menus==null||menus.size()<1 ) throw new BusinessException(20001);
  109. return returnResult(0, "获取成功", menus.get(0));
  110. }catch(Exception e){
  111. throw new BusinessException(20001);
  112. }
  113. }
  114. }