package com.community.huiju.controller;

import com.community.commom.constant.Constant;
import com.community.commom.mode.ResponseBean;
import com.community.commom.session.UserElement;
import com.community.huiju.model.TaSysMenu;
import com.community.huiju.service.MenuServiceI;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

/**
 * @author FXF
 * @date 2018-11-05
 */
@RestController
@RefreshScope
@RequestMapping("/")
@Api(value = "菜单API", description = "菜单API")
public class MenuController extends BaseController {
	
	@Autowired
	private MenuServiceI menuService;
	
	@ApiOperation(value = "按小区获取菜单列表", notes = "按小区获取菜单列表")
	@ApiImplicitParams({ @ApiImplicitParam(paramType = "path", dataType = "String", name = "communityId", value = "小区Id")})
	@RequestMapping(value = "/menus/{communityId}",method = RequestMethod.GET)
	public ResponseBean getMenuList(@PathVariable Integer communityId, HttpSession session){
		ResponseBean responseBean = new ResponseBean();

		if (!check(communityId)) {
			responseBean.addError("小区不存在");
			return responseBean;
		}

		List<TaSysMenu> list = menuService.getMenuList(communityId);
		responseBean.addSuccess(list);
		return responseBean;
	}
}
