/**
 * Copyright 2008-2009. Chongqing Communications Industry Services Co.,Ltd Information Technology Branch. All rights reserved. <a>http://www.cqcis.com</a>
 */
package com.crunii.micro.service.sysmgr.controller;

import com.crunii.micro.common.dto.Result;
import com.crunii.micro.domain.dto.sys.MenuExtend;
import com.crunii.micro.service.sysmgr.dto.sysmgr.MenuC;
import com.crunii.micro.service.sysmgr.dto.sysmgr.MenuU;
import com.crunii.micro.service.sysmgr.service.MenuService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author 田平 create 2023-02-21 10:48:08
 */
@Api(value = "菜单管理相关")
@Controller
@RequestMapping("/auth/MenuController")
public class MenuController {
	@Autowired
	private MenuService menuService;

	@ApiOperation(value = "创建菜单")
	@RequestMapping(path = "/createMenu", method = RequestMethod.POST)
	@ResponseBody
	public Result<String> createMenu(@RequestBody @ApiParam MenuC menuC) {
		Result<String> result = new Result<>();
		menuService.createMenu(menuC);
		return result;
	}

	@ApiOperation(value = "更新菜单")
	@RequestMapping(path = "/updateMenu", method = RequestMethod.POST)
	@ResponseBody
	public Result<String> updateMenu(@RequestBody @ApiParam MenuU menuU) {
		Result<String> result = new Result<>();
		menuService.updateMenu(menuU);
		return result;
	}

	@ApiOperation(value = "通过父菜单编码获取子菜单")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "parentMenuCode", value = "父菜单编码", required = true)
	})
	@RequestMapping(path = "/getChildren", method = RequestMethod.GET)
	@ResponseBody
	public Result<List<MenuExtend>> getChildren(String parentMenuCode,Integer menuType) {
		Result<List<MenuExtend>> result = new Result<>();
		result.setData(menuService.getChildren(parentMenuCode,menuType));
		return result;
	}

}
