package com.hotent.uc.controller;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
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.exception.BaseException;
import com.hotent.base.feign.BpmRuntimeFeignService;
import com.hotent.base.model.CommonResult;
import com.hotent.base.query.FieldRelation;
import com.hotent.base.query.PageList;
import com.hotent.base.query.QueryFilter;
import com.hotent.base.query.QueryOP;
import com.hotent.base.util.BeanUtils;
import com.hotent.base.util.CommonResultUtil;
import com.hotent.base.util.StringUtil;
import com.hotent.uc.manager.TenantAuthManager;
import com.hotent.uc.manager.TenantManageManager;
import com.hotent.uc.manager.TenantTypeManager;
import com.hotent.uc.model.TenantAuth;
import com.hotent.uc.model.TenantManage;
import com.hotent.uc.model.User;
import com.hotent.uc.util.ContextUtil;
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-17 10:56:07
 * 版权：广州宏天软件股份有限公司
 * </pre>
 */
@RestController
@RequestMapping(value="/uc/tenantManage/v2")
@Api(tags="租户管理2 ")
@ApiGroup(group= {ApiGroupConsts.GROUP_UC})
public class TenantManageController2 extends BaseController2<TenantManageManager,TenantManage> {
	@Resource
	TenantManageManager tenantManageManager;
	@Resource
	TenantTypeManager tenantTypeManager;
	@Resource
	TenantAuthManager tenantAuthManager;
	@Resource
	BpmRuntimeFeignService bpmRuntimeFeignService;
	
	/**
	 * 租户管理 列表(分页条件查询)数据
	 * @param request
	 * @return
	 * @throws Exception 
	 * PageJson
	 * @exception 
	 */
	@PostMapping("/listJson")
	@ApiOperation(value="租户管理 数据列表", httpMethod = "POST", notes = "获取租户管理 列表")
	public CommonResult<PageList<TenantManage>> list(@ApiParam(name="queryFilter",value="查询对象")@RequestBody QueryFilter queryFilter) throws Exception{
		PageList<TenantManage> tenantManagePageList = tenantManageManager.listJson(queryFilter);
		return CommonResult.<PageList<TenantManage>>ok().value(tenantManagePageList);
	}

	
    /**
	 * 新增租户管理 
	 * @param tenantManage
	 * @throws Exception 
	 * @return
	 * @exception 
	 */
	@PostMapping(value="save")
	@ApiOperation(value = "新增,更新租户管理 数据", httpMethod = "POST", notes = "新增,更新租户管理 数据")
	public CommonResult<String> save(@ApiParam(name="tenantManage",value="租户管理 业务对象", required = true)@RequestBody TenantManage tenantManage) throws Exception{
		CommonResult<String> commonResult = tenantManageManager.saveTenantManage(tenantManage);
		return CommonResultUtil.<String>getResult(commonResult);
	}
	

	
	@RequestMapping(value="checkCode", method=RequestMethod.GET, produces={"application/json; charset=utf-8" })
	@ApiOperation(value = "检查租户类型编码是否存在", httpMethod = "GET", notes = "检查租户类型编码是否存在")
	public CommonResult<Boolean> checkCode(@ApiParam(name="code",value="租户类型编码") @RequestParam String code) throws Exception{
		TenantManage tenant = tenantManageManager.getByCode(code);
		boolean flag = BeanUtils.isNotEmpty(tenant);
		return CommonResult.<Boolean>ok().value(flag);
	}
	
	@RequestMapping(value="getTenantByCode", method=RequestMethod.GET, produces={"application/json; charset=utf-8" })
	@ApiOperation(value = "通过编码获取租户类型", httpMethod = "GET", notes = "通过编码获取租户类型")
	public CommonResult<TenantManage> getTenantByCode(@ApiParam(name="code",value="租户类型编码") @RequestParam String code) throws Exception{
		TenantManage tenantManage = tenantManageManager.getByCode(code);
		return CommonResult.<TenantManage>ok().value(tenantManage);

	}
}
