package com.hotent.uc.controller;


import com.hotent.base.annotation.ApiGroup;
import com.hotent.base.constants.ApiGroupConsts;
import com.hotent.base.controller.BaseController;
import com.hotent.base.controller.BaseController2;
import com.hotent.base.model.CommonResult;
import com.hotent.base.util.CommonResultUtil;
import com.hotent.uc.manager.ResouceManager;
import com.hotent.uc.model.Resouce;
import com.hotent.uc.params.resouce.ResouceVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
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.RestController;

import javax.annotation.Resource;

/**
 * 维度模块接口
 * @author zhangxw
 *
 */
@RestController
@RequestMapping("/api/resouce/v2/")
@Api(tags="角色资源关系2")
@ApiGroup(group= {ApiGroupConsts.GROUP_UC})
public class ResouceController2 extends BaseController2<ResouceManager, Resouce> {
	
	@Resource
	ResouceManager resouceService;

	/**
	 * 添加维度
	 * @param dem
	 * @return
	 * @throws Exception
	 * 
	 */
	@RequestMapping(value="resouce/saveResouce",method=RequestMethod.POST, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "添加角色资源关系", httpMethod = "POST", notes = "添加角色资源关系")
	public CommonResult<String> saveResouce(@ApiParam(name="resouceVo",value="维度参数对象", required = true) @RequestBody ResouceVo resouceVo) throws Exception{
		CommonResult<String> commonResult = resouceService.saveResouce(resouceVo);
		return CommonResultUtil.<String>getResult(commonResult);
	}
	
	/**
	 * 添加维度
	 * @param dem
	 * @return
	 * @throws Exception
	 * 
	 */
	@RequestMapping(value="resouce/getByRoleCode",method=RequestMethod.GET, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "根据角色获取资源信息", httpMethod = "GET", notes = "根据角色获取资源信息")
	public CommonResult<Resouce> getByRoleCode(@ApiParam(name="roleCode",value="角色编码", required = true)  String roleCode) throws Exception{
		Resouce resouce = resouceService.getByRoleCode(roleCode);
		return CommonResult.<Resouce>ok().value(resouce);
	}
}
