MenuController.java 2.31 KB
package com.govmade.modules.system.controller;

import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.govmade.common.utils.PageTreeUtils;
import com.govmade.common.utils.R;
import com.govmade.common.validator.Assert;
import com.govmade.modules.basic.controller.AbstractController;
import com.govmade.modules.system.entity.MenuEntity;
import com.govmade.modules.system.service.MenuService;

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

	@Autowired
	private MenuService menuService;

	/**
	 * 所有菜单数据树结构
	 */
	@GetMapping("/listTree")
	public R listTree(@RequestParam Map<String, Object> params) {
		PageTreeUtils page = menuService.queryPage(params);
		return R.ok().put("page", page);
	}
	
	@GetMapping("/menuList")
	public R queryMenuList() {
		List<MenuEntity> queryMenuList=menuService.queryMenuList();
		return R.ok().put("data", queryMenuList);
	}
	
	
	
	/**
	 * 保存或更新菜单
	 */
	@PostMapping("/save")
	public R save(MenuEntity menu) {

		if (null == menu.getId()) {
			if (this.menuService.checkMenu(menu.getName()) > 0) {
				return R.error(menu.getName() + " 已存在!");
			}
		}
		menuService.save(menu);
		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));
	}
	
	/**
	 * 批量删除菜单
	 * 
	 * @param ids
	 * @return
	 */
	@DeleteMapping("/delete")
	public R deleteMenu(@RequestBody Set<Long> ids) {
		Assert.isNull(ids, "删除项不能为空");

		menuService.deleteBatch(ids);
		return R.ok();
	}
	
	
}