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.CommonResultUtil;
import com.hotent.base.util.StringUtil;
import com.hotent.uc.manager.TenantAuthManager;
import com.hotent.uc.model.TenantAuth;
import com.hotent.uc.params.tenant.TenantAuthAddObject;
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.Optional;

/**
 * 
 * <pre> 
 * 描述：租户分类管理员 控制器类
 * 构建组：x7
 * 作者:zhangxw
 * 邮箱:zhangxw@jee-soft.cn
 * 日期:2020-04-17 10:55:39
 * 版权：广州宏天软件股份有限公司
 * </pre>
 */
@RestController
@RequestMapping(value="/uc/tenantAuth/v2")
@Api(tags="租户分类管理员2")
@ApiGroup(group= {ApiGroupConsts.GROUP_UC})
public class TenantAuthController2 extends BaseController2<TenantAuthManager,TenantAuth> {
	@Resource
	TenantAuthManager tenantAuthManager;

	
	/**
	 * 租户管理员列表(分页条件查询)数据
	 * @param request
	 * @return
	 * @throws Exception 
	 * PageJson
	 * @exception 
	 */
	@PostMapping("/queryByTypeOrTenant")
	@ApiOperation(value="租户管理员数据列表", httpMethod = "POST", notes = "获取租户管理员列表")
	public CommonResult<PageList<TenantAuth>> queryByTypeOrTenant(@ApiParam(name="queryFilter",value="查询对象")@RequestBody QueryFilter queryFilter) throws Exception{
		PageList<TenantAuth> tenantAuthPageList = tenantAuthManager.queryByTypeAndTenantId(queryFilter);
		return CommonResult.<PageList<TenantAuth>>ok().value(tenantAuthPageList);
	}
	
	@RequestMapping(value="/saveTenantAuth",method=RequestMethod.POST, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "分配租户管理员（按用户）", httpMethod = "POST", notes = "分配租户管理员（按用户）")
	public CommonResult<String> saveTenantAuth(@ApiParam(name="authAddObject",value="authAddObject", required = true) @RequestBody TenantAuthAddObject authAddObject) throws Exception{
		CommonResult<String> commonResult = tenantAuthManager.saveTenantAuth(authAddObject);
		return CommonResultUtil.<String>getResult(commonResult);
	}
	
	@RequestMapping(value="deleteTenantAuth",method=RequestMethod.DELETE, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "移除租户管理员", httpMethod = "DELETE", notes = "移除租户管理员")
	public CommonResult<String> deleteUserRole(@ApiParam(name="typeId",value="租户类型id", required = true) @RequestParam String typeId,
			@ApiParam(name="tenantId",value="租户id", required = false) @RequestParam Optional<String> tenantId,
			@ApiParam(name="userIds",value="用户ID，多个用“,”号隔开", required = true) @RequestParam String userIds) throws Exception{
		CommonResult<String> commonResult = tenantAuthManager.removeTenantAuth(typeId, tenantId.orElse(""), userIds);
		return CommonResultUtil.<String>getResult(commonResult);
	}
}
