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.TenantParamsManager;
import com.hotent.uc.model.TenantParams;
import com.hotent.uc.params.params.ParamObject;
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.List;

/**
 * 
 * <pre> 
 * 描述：租户扩展参数值 控制器类
 * 构建组：x7
 * 作者:zhangxw
 * 邮箱:zhangxw@jee-soft.cn
 * 日期:2020-04-17 14:54:36
 * 版权：广州宏天软件股份有限公司
 * </pre>
 */
@RestController
@RequestMapping(value="/uc/tenantParams/v2")
@Api(tags="租户扩展参数值2")
@ApiGroup(group= {ApiGroupConsts.GROUP_UC})
public class TenantParamsController2 extends BaseController2<TenantParamsManager, TenantParams> {
	@Resource
	TenantParamsManager tenantParamsManager;


    /**
	 * 新增租户扩展参数值
	 * @param tenantParams
	 * @throws Exception 
	 * @return
	 * @exception 
	 */
	@PostMapping(value="save")
	@ApiOperation(value = "新增,更新租户扩展参数值数据", httpMethod = "POST", notes = "新增,更新租户扩展参数值数据")
	public CommonResult<String> save(@ApiParam(name="tenantParams",value="租户扩展参数值业务对象", required = true)@RequestBody TenantParams tenantParams) throws Exception{
		String msg = "添加租户扩展参数值成功";
		if(StringUtil.isEmpty(tenantParams.getId())){
			tenantParamsManager.create(tenantParams);
		}else{
			tenantParamsManager.update(tenantParams);
			 msg = "更新租户扩展参数值成功";
		}
		return CommonResult.<String>ok().message(msg);
	}

	
	@RequestMapping(value="getParamsValue",method=RequestMethod.GET, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "获取租户参数值列表", httpMethod = "GET", notes = "获取租户参数值列表")
	public CommonResult<List<TenantParams>> getParamsValue(@ApiParam(name="tenantId",value="租户id", required = true)@RequestParam String tenantId) throws Exception{
		List<TenantParams> tenantParamsList = tenantParamsManager.getByTenantId(tenantId);
		return CommonResult.<List<TenantParams>>ok().value(tenantParamsList);
	}
	
	@RequestMapping(value="saveTenantParams",method=RequestMethod.POST, produces = {
	"application/json; charset=utf-8" })
	@ApiOperation(value = "保存租户扩展参数值", httpMethod = "POST", notes = "保存租户扩展参数值")
	public CommonResult<String> saveTenantParams(@ApiParam(name="tenantId",value="租户id",required=true)  @RequestParam String tenantId,
			@ApiParam(name="params",value="租户参数值",required=true) @RequestBody List<ParamObject> params) throws Exception{
		CommonResult<String> commonResult = tenantParamsManager.saveUserParams(tenantId, params);
		return CommonResultUtil.<String>getResult(commonResult);
	}
}
