package com.ym.mec.teacher.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ym.mec.auth.api.client.SysUserFeignService;
import com.ym.mec.auth.api.entity.SysUser;
import com.ym.mec.biz.dal.page.TenantAccountDetailQueryInfo;
import com.ym.mec.biz.service.SysTenantAccountDetailService;
import com.ym.mec.biz.service.SysTenantAccountService;
import com.ym.mec.common.controller.BaseController;

@RequestMapping("sysTenantAccount")
@Api(tags = "租客账户管理")
@RestController
public class SysTenantAccountController extends BaseController {

	@Autowired
	private SysTenantAccountService sysTenantAccountService;

	@Autowired
	private SysTenantAccountDetailService sysTenantAccountDetailService;

	@Autowired
	private SysUserFeignService sysUserFeignService;

	@ApiOperation(value = "获取账户信息")
	@GetMapping("/get")
	public Object get() {
		SysUser sysUser = sysUserFeignService.queryUserInfo();
		if (sysUser == null) {
			return failed(HttpStatus.FORBIDDEN, "请登录");
		}

		return succeed(sysTenantAccountService.get(sysUser.getId()));
	}

	@ApiOperation(value = "获取账户明细")
	@GetMapping("/queryTenantAccountDetail")
	public Object queryTenantAccountDetail(TenantAccountDetailQueryInfo queryInfo) {
		SysUser sysUser = sysUserFeignService.queryUserInfo();
		if (sysUser == null) {
			return failed(HttpStatus.FORBIDDEN, "请登录");
		}
		queryInfo.setUserId(sysUser.getId());

		return succeed(sysTenantAccountDetailService.queryPage(queryInfo));
	}

}
