package com.huatek.frame.base.menu.controller;

import java.util.Map;

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.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import com.huatek.frame.base.dto.PermissionDTO;
import com.huatek.frame.base.entity.Permission;
import com.huatek.frame.base.service.PermissionService;
import com.huatek.frame.base.vo.MenuVO;
import com.huatek.frame.base.vo.PermissionVO;
import com.huatek.torch.frame.log.KerLog;
import com.huatek.torch.frame.permission.KerPermission;
import com.huatek.torch.frame.validate.KerValid;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam; 

/**
 * 菜单管理
 * 
 * @author kevin_hou
 *
 */
@Api(tags={"菜单管理接口"})
@RestController
@RequestMapping("/api/menu")
public class MenuController {

	@Reference(check = false)
	PermissionService permissionService;

	/**
	 * 菜单列表
	 * 
	 * @return
	 */
	@ApiOperation(value = "菜单列表",httpMethod="POST", notes= "菜单列表", produces = "application/json;charset=utf-8",response=PermissionVO.class)
	@KerLog(projectName = "PROJECTNAME", modelName = "MUNE.MODELNAME", methodName = "MUNE.MODELNAME.MENULIST")
	@PostMapping(value="/menus", produces = { "application/json;charset=utf-8"})
	public  @KerPermission("10001") Map<String, Object> menus(@RequestBody PermissionDTO dto) {
		Map<String, Object> map = permissionService.findPermissionPage(dto);
		return map;
	}

	/**
	 * 修改保存
	 * 
	 * @param permission
	 * @return
	 */
	@ApiOperation(value = "修改保存",httpMethod="POST", notes= "修改保存", produces = "application/json;charset=utf-8",response=Map.class)
	@KerLog(projectName = "PROJECTNAME", modelName = "MUNE.MODELNAME", methodName = "MUNE.MODELNAME.UPDATEMENU")
	@PostMapping(value = "/modifyPermission", produces = { "application/json;charset=utf-8"})
	public  @KerPermission("10004") @KerValid Map<String, Object> modifyPermission(@RequestBody Permission permission) {
		Map<String, Object> map = permissionService.updatePermission(permission);
		return map;
	}

	/**
	 * 菜单详情
	 * 
	 * @param pid
	 * @return
	 */
	@ApiOperation(value = "菜单详情",httpMethod="GET", notes= "菜单详情", produces = "application/json;charset=utf-8",response=PermissionVO.class)
	@KerLog(projectName = "PROJECTNAME", modelName = "MUNE.MODELNAME", methodName = "MUNE.MODELNAME.MENUDETAIL")
	@GetMapping(value="/findPermission/{id}", produces = { "application/json;charset=utf-8"})
	public  @KerPermission("10002") Map<String, Object> findPermission(@ApiParam(value="菜单id") @PathVariable("id")String id) {
		Map<String, Object> map = permissionService.findPermission(id);
		return map;
	}

	/**
	 * 删除菜单
	 * 
	 * @param ids
	 *            菜单id
	 * @return
	 */
	@ApiOperation(value = "删除菜单",httpMethod="POST", notes= "删除菜单", produces = "application/json;charset=utf-8",response=Map.class)
	@KerLog(projectName = "PROJECTNAME", modelName = "MUNE.MODELNAME", methodName = "MUNE.MODELNAME.MENUDDELETE")
	@PostMapping(value = "/deletePermission", produces = { "application/json;charset=utf-8"})
	public  @KerPermission("10005") Map<String, Object> deletePermission(@ApiParam(value="菜单id集合") @RequestBody String[] ids) {
		Map<String, Object> map = permissionService.deletePermission(ids);
		return map;
	}  

	/**
	 * 新增菜单
	 * 
	 * @param permission
	 * @return
	 */
	@ApiOperation(value = "新增菜单",httpMethod="POST", notes= "新增菜单", produces = "application/json;charset=utf-8",response=Map.class)
	@KerLog(projectName = "PROJECTNAME", modelName = "MUNE.MODELNAME", methodName = "MUNE.MODELNAME.SAVEMENU")
	@PostMapping(value = "/addPermission", produces = { "application/json;charset=utf-8"})
	public  @KerPermission("10003") @KerValid  Map<String, Object> addPermission(@RequestBody Permission permission) {
		Map<String, Object> map = permissionService.addPermission(permission);
		return map;
	}
	
	/**
	 * 菜单集合
	 * 
	 * @param permission
	 * @return
	 */ 
	@ApiOperation(value = "菜单集合",httpMethod="GET", notes= "菜单集合", produces = "application/json;charset=utf-8",response=MenuVO.class)
	@GetMapping(value = "/findPermissions/{roleId}", produces = { "application/json;charset=utf-8"})
	public   Map<String, Object> findPermissions(@ApiParam(value="角色id") @PathVariable("roleId")String roleId) {
		Map<String, Object> map = permissionService.findPermissions(roleId);
		return map;
	}
}
