MenuController.java 4.6 KB

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