MenuController.java 2.31 KB
Newer Older
Fred's avatar
Fred committed
1 2
package com.govmade.modules.system.controller;

刘弈臻's avatar
刘弈臻 committed
3
import java.util.List;
Fred's avatar
Fred committed
4
import java.util.Map;
刘弈臻's avatar
刘弈臻 committed
5
import java.util.Set;
Fred's avatar
Fred committed
6 7

import org.springframework.beans.factory.annotation.Autowired;
刘弈臻's avatar
刘弈臻 committed
8
import org.springframework.web.bind.annotation.DeleteMapping;
Fred's avatar
Fred committed
9 10 11
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
刘弈臻's avatar
刘弈臻 committed
12
import org.springframework.web.bind.annotation.RequestBody;
Fred's avatar
Fred committed
13
import org.springframework.web.bind.annotation.RequestMapping;
刘弈臻's avatar
刘弈臻 committed
14
import org.springframework.web.bind.annotation.RequestParam;
Fred's avatar
Fred committed
15
import org.springframework.web.bind.annotation.RestController;
刘弈臻's avatar
刘弈臻 committed
16 17

import com.govmade.common.utils.PageTreeUtils;
Fred's avatar
Fred committed
18
import com.govmade.common.utils.R;
刘弈臻's avatar
刘弈臻 committed
19
import com.govmade.common.validator.Assert;
Fred's avatar
Fred committed
20
import com.govmade.modules.basic.controller.AbstractController;
Fred's avatar
Fred committed
21 22
import com.govmade.modules.system.entity.MenuEntity;
import com.govmade.modules.system.service.MenuService;
Fred's avatar
Fred committed
23 24 25 26 27 28 29 30 31 32 33 34

/**
 * 系统管理 - 菜单设置
 * 
 * @author Fred
 * @email fangtaosh@qq.com
 * @date 2018年8月3日
 */
@RestController
@RequestMapping("/system/menu")
public class MenuController extends AbstractController {

Fred's avatar
Fred committed
35 36 37 38
	@Autowired
	private MenuService menuService;

	/**
刘弈臻's avatar
刘弈臻 committed
39
	 * 所有菜单数据树结构
Fred's avatar
Fred committed
40
	 */
刘弈臻's avatar
刘弈臻 committed
41 42 43 44
	@GetMapping("/listTree")
	public R listTree(@RequestParam Map<String, Object> params) {
		PageTreeUtils page = menuService.queryPage(params);
		return R.ok().put("page", page);
Fred's avatar
Fred committed
45
	}
Fred's avatar
Fred committed
46
	
刘弈臻's avatar
刘弈臻 committed
47 48 49 50 51 52 53
	@GetMapping("/menuList")
	public R queryMenuList() {
		List<MenuEntity> queryMenuList=menuService.queryMenuList();
		return R.ok().put("data", queryMenuList);
	}
	
	
刘弈臻's avatar
刘弈臻 committed
54
	
Fred's avatar
Fred committed
55
	/**
刘弈臻's avatar
刘弈臻 committed
56
	 * 保存或更新菜单
Fred's avatar
Fred committed
57 58 59 60 61 62 63 64 65
	 */
	@PostMapping("/save")
	public R save(MenuEntity menu) {

		if (null == menu.getId()) {
			if (this.menuService.checkMenu(menu.getName()) > 0) {
				return R.error(menu.getName() + " 已存在!");
			}
		}
刘弈臻's avatar
刘弈臻 committed
66
		menuService.save(menu);
Fred's avatar
Fred committed
67 68 69 70 71 72 73 74 75 76 77 78 79
		return R.ok();
	}

	/**
	 * 根据ID查询菜单
	 * 
	 * @param id
	 * @return
	 */
	@GetMapping("info/{id}")
	public R info(@PathVariable("id") Long id) {
		return R.ok().put("menu", menuService.queryById(id));
	}
刘弈臻's avatar
刘弈臻 committed
80 81 82 83 84 85 86 87
	
	/**
	 * 批量删除菜单
	 * 
	 * @param ids
	 * @return
	 */
	@DeleteMapping("/delete")
刘弈臻's avatar
刘弈臻 committed
88
	public R deleteMenu(@RequestBody Set<Long> ids) {
刘弈臻's avatar
刘弈臻 committed
89 90 91 92 93 94 95
		Assert.isNull(ids, "删除项不能为空");

		menuService.deleteBatch(ids);
		return R.ok();
	}
	
	
Fred's avatar
Fred committed
96
}