MenuController.java 4.3 KB

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