package com.usky.system.controller.web;


import com.usky.common.core.bean.ApiResult;
import com.usky.common.core.bean.CommonPage;
import com.usky.system.domain.SysPlatform;
import com.usky.system.domain.SysTenant;
import com.usky.system.service.SysPlatformService;
import com.usky.system.service.SysTenantService;
import com.usky.system.service.vo.SysTenantOneVo;
import com.usky.system.service.vo.SysTenantTwoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *
 * @author ya
 * @since 2022-05-05
 */
@RestController
@RequestMapping("/tenantConfig")
public class TenantConfigController {

    @Autowired
    private SysTenantService sysTenantService;

    @Autowired
    private SysPlatformService sysPlatformService;


    /**
     * 租户管理-租户单位配置-列表查询
     *
     * @param sysTenantOneVo
     * @return
     */
    @PostMapping("getTenantData")
    public ApiResult<CommonPage<SysTenantTwoVo>> getTenantData(@RequestBody SysTenantOneVo sysTenantOneVo) {
        return ApiResult.success(sysTenantService.getTenantData(sysTenantOneVo));
    }


    /**
     * 租户管理-租户单位配置-新增
     *
     * @param sysTenant
     * @return
     */
//    @Log(title = "租户管理-单位管理", businessType = BusinessType.INSERT)
    @PostMapping("addTenantData")
    public ApiResult<Void> addTenantData(@RequestBody SysTenant sysTenant) {
        sysTenantService.addTenantData(sysTenant);
        return ApiResult.success();
    }

    /**
     * 租户管理-租户单位配置-克隆
     * @param sysTenant
     * @return
     */
    @PostMapping("cloneTenantData")
    public ApiResult<Void> cloneTenantData(@RequestBody SysTenant sysTenant){
        sysTenantService.cloneTenantData(sysTenant);
        return ApiResult.success();
    }

    /**
     * 租户管理-租户单位配置-删除
     * @param tenantId
     * @return
     */
    @DeleteMapping("/delTenantData/{tenantId}")
    public ApiResult<Void> delTenantData(@PathVariable("tenantId") Integer tenantId){
        sysTenantService.delTenantData(tenantId);
        return ApiResult.success();
    }

    /**
     * 租户管理-租户单位配置-修改
     *
     * @param sysTenant
     * @return
     */
//    @Log(title = "租户管理-单位管理", businessType = BusinessType.UPDATE)
    @PostMapping("updateTenantData")
    public ApiResult<Void> updateTenantData(@RequestBody SysTenant sysTenant) {
        sysTenantService.updateTenantData(sysTenant);
        return ApiResult.success();
    }


    /**
     * 租户管理-租户单位配置-系统平台下拉框数据查询
     *
     * @return
     */
    @GetMapping("/getPlatformBoxList")
    public ApiResult<List<SysPlatform>> getPlatformBoxList() {
        return ApiResult.success(sysPlatformService.getPlatformBoxList());
    }

}

