package com.hotent.uc.controller;

import com.hotent.base.annotation.ApiGroup;
import com.hotent.base.constants.ApiGroupConsts;
import com.hotent.base.context.BaseContext;
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.TenantMailServerManager;
import com.hotent.uc.manager.TenantManageManager;
import com.hotent.uc.model.TenantMailServer;
import com.hotent.uc.model.TenantManage;
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 11:01:30
 * 版权：广州宏天软件股份有限公司
 * </pre>
 */
@RestController
@RequestMapping(value="/uc/tenantMailServer/v2")
@Api(tags="租户邮件服务器信息2")
@ApiGroup(group= {ApiGroupConsts.GROUP_UC})
public class TenantMailServerController2 extends BaseController2<TenantMailServerManager,TenantMailServer> {
	@Resource
	TenantMailServerManager tenantMailServerManager;
	@Resource
	BaseContext baseContext;
	@Resource
	TenantManageManager tenantManageManager;
	
	@GetMapping(value="/getByCurrent")
	@ApiOperation(value="租户邮件服务器信息数据详情",httpMethod = "GET",notes = "租户邮件服务器信息数据详情")
	public CommonResult<TenantMailServer> getByCurrent(@ApiParam(name="tenantId",value="租户id", required = true)@RequestParam Optional<String> tenantId) throws Exception{
		String currentTenantId = StringUtil.isEmpty(tenantId.orElse(null))?baseContext.getCurrentTenantId():tenantId.get();
		TenantMailServer mailServer = tenantMailServerManager.getByTenantId(currentTenantId);
		if(BeanUtils.isEmpty(mailServer)){
			mailServer = new TenantMailServer();
			mailServer.setTenantId(currentTenantId);
		}
		return CommonResult.<TenantMailServer>ok().value(mailServer);
	}
	
    /**
	 * 新增租户邮件服务器信息
	 * @param tenantMailServer
	 * @throws Exception 
	 * @return
	 * @exception 
	 */
	@PostMapping(value="save")
	@ApiOperation(value = "新增,更新租户邮件服务器信息数据", httpMethod = "POST", notes = "新增,更新租户邮件服务器信息数据")
	public CommonResult<String> save(@ApiParam(name="tenantMailServer",value="租户邮件服务器信息业务对象", required = true)@RequestBody TenantMailServer tenantMailServer) throws Exception{
		CommonResult<String> commonResult = tenantMailServerManager.saveTenantMailServer(tenantMailServer);
		return CommonResultUtil.<String>getResult(commonResult);
	}
	
	/**
	 * 批量删除租户邮件服务器信息记录
	 * @param ids
	 * @throws Exception 
	 * @return
	 * @exception 
	 */
	@DeleteMapping(value="/remove")
	@ApiOperation(value = "批量删除租户邮件服务器信息记录", httpMethod = "DELETE", notes = "批量删除租户邮件服务器信息记录")
	public CommonResult<String> removes(@ApiParam(name="ids",value="业务主键数组,多个业务主键之间用逗号分隔", required = true)@RequestParam String...ids) throws Exception{
		tenantMailServerManager.removeByIds(ids);
		return CommonResult.<String>ok().message("删除成功");
	}
}
