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.query.PageList;
import com.hotent.base.query.QueryFilter;
import com.hotent.base.util.BeanUtils;
import com.hotent.base.util.CommonResultUtil;
import com.hotent.base.util.StringUtil;
import com.hotent.uc.manager.TenantIgnoreMenuManager;
import com.hotent.uc.model.TenantIgnoreMenu;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 
 * <pre> 
 * 描述：租户禁用菜单 控制器类
 * 构建组：x7
 * 作者:zhangxw
 * 邮箱:zhangxw@jee-soft.cn
 * 日期:2020-04-20 17:00:53
 * 版权：广州宏天软件股份有限公司
 * </pre>
 */
@RestController
@RequestMapping(value="/uc/tenantIgnoreMenu/v2")
@Api(tags="租户禁用菜单管理2")
@ApiGroup(group= {ApiGroupConsts.GROUP_UC})
public class TenantIgnoreMenuController2 extends BaseController2<TenantIgnoreMenuManager,TenantIgnoreMenu> {
	@Resource
	TenantIgnoreMenuManager tenantIgnoreMenuManager;

	
	/**
	 * 获取租户禁用菜单
	 * @param id
	 * @return
	 * @throws Exception 
	 * ModelAndView
	 */
	@GetMapping(value="/getIgnoreMenuCodes")
	@ApiOperation(value="租户禁用菜单数据详情",httpMethod = "GET",notes = "租户禁用菜单数据详情")
	public CommonResult<List<String>> getIgnoreMenuCodes(@ApiParam(name="tenantId",value="租户id", required = true)@RequestParam String tenantId) throws Exception{
		List<TenantIgnoreMenu> ignoreMenus = tenantIgnoreMenuManager.getByTenantId(tenantId);
		List<String> ignoreCodes = new ArrayList<String>();
		if(BeanUtils.isNotEmpty(ignoreMenus)){
			for (TenantIgnoreMenu menu : ignoreMenus) {
				ignoreCodes.add(menu.getMenuCode());
			}
		}
		return CommonResult.<List<String>>ok().value(ignoreCodes);
	}

	
	@PostMapping(value="saveByTenantId")
	@ApiOperation(value = "新增,更新租户禁用菜单数据", httpMethod = "POST", notes = "新增,更新租户禁用菜单数据")
	public CommonResult<String> saveByTenantId(@ApiParam(name="tenantId",value="租户id", required = true)@RequestParam String tenantId,
			@ApiParam(name="ignoreMenus",value="需要禁用的菜单别名列表", required = true)@RequestBody List<String> ignoreMenus) throws Exception{
		CommonResult<String> commonResult = tenantIgnoreMenuManager.saveByTenantId(tenantId, ignoreMenus);
		return CommonResultUtil.<String>getResult(commonResult);
	}
}
