package com.ym.mec.student.controller;

import javax.annotation.Resource;

import com.ym.mec.auth.api.client.SysUserFeignService;
import com.ym.mec.auth.api.entity.SysUser;
import com.ym.mec.biz.service.TenantInfoService;
import com.ym.mec.common.controller.BaseController;

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

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.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author hgw
 * Created by 2021-12-07
 */
@RequestMapping("/tenantInfo")
@Api(tags = "机构管理")
@RestController
public class TenantInfoController extends BaseController {

    @Autowired
    private TenantInfoService tenantInfoService;

    @Resource
    private SysUserFeignService sysUserFeignService;

    @ApiOperation("查询单个机构详情")
    @GetMapping(value = "/info/{id}")
    public Object queryTenantInfo(@ApiParam(value = "机构ID", required = true) @PathVariable("id") Integer id) {
        return succeed(tenantInfoService.queryTenantInfo(id));
    }

    @ApiOperation("查询用户机构信息")
    @GetMapping(value = "/queryUserTenantInfo")
    public Object queryUserTenantInfo() {
    	SysUser user = sysUserFeignService.queryUserInfo();
        if (user == null || user.getId() == null) {
            return failed(HttpStatus.FORBIDDEN, "请登录");
        }
        return succeed(tenantInfoService.queryTenantInfo(user.getTenantId()));
    }

    @ApiOperation("查询单个机构详情")
    @GetMapping(value = "/checkInfo/{id}")
    public Object queryTenantInfoCheck(@ApiParam(value = "机构ID", required = true) @PathVariable("id") Integer id) {
        return succeed(tenantInfoService.queryTenantInfoCheck(id));
    }

    @ApiOperation("查询单个机构详情按分部Id")
    @GetMapping(value = "/queryTenantInfoByOrgan/{organId}")
    public Object queryTenantInfoByOrgan(@ApiParam(value = "分部ID", required = true) @PathVariable("organId") Integer organId) {
        return succeed(tenantInfoService.queryTenantInfoByOrgan(organId));
    }
}
