package com.usky.system.controller.web;


import com.usky.common.core.bean.ApiResult;
import com.usky.common.core.bean.CommonPage;
import com.usky.common.log.annotation.Log;
import com.usky.common.log.enums.BusinessType;
import com.usky.system.domain.SysMenu;
import com.usky.system.domain.SysTenantConfig;
import com.usky.system.service.SysTenantConfigService;
import com.usky.system.service.SysTenantService;
import com.usky.system.service.vo.SysTenantConfigVo;
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 org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 登录中间页配置
 *
 * @author ya
 * @since 2022-05-06
 */
@RestController
@RequestMapping("/sysTenantConfig")
public class SysTenantConfigController {
    @Autowired
    private SysTenantConfigService sysTenantConfigService;

    @Autowired
    private SysTenantService sysTenantService;


    /**
     * 登录页-样式配置查询
     *
     * @param url 域名
     * @return
     */
    @GetMapping("/getTenantConfig")
    public ApiResult<List<SysTenantConfigVo>> getTenantConfig(@RequestParam String url) {
        return ApiResult.success(sysTenantConfigService.getTenantConfig(url));
    }


    /**
     * 中间页-样式配置查询
     */
    @GetMapping("/getMiddleConfig")
    public ApiResult<List<SysTenantConfig>> getMiddleConfig() {
        return ApiResult.success(sysTenantConfigService.getMiddleConfig());
    }


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

    /**
     * 租户管理-系统配置-租户配置查询
     *
     * @param tenantId 租户ID
     * @return
     */
    @GetMapping("/getMiddleConfigList")
    public ApiResult<List<SysTenantConfig>> getMiddleConfigList(@RequestParam Integer tenantId) {
        return ApiResult.success(sysTenantConfigService.getMiddleConfigList(tenantId));
    }

    /**
     * 租户管理-系统配置-租户配置新增
     *
     * @param sysTenantConfig
     * @return
     */
    @Log(title = "新增租户信息", businessType = BusinessType.INSERT)
    @PostMapping("addMiddleConfig")
    public ApiResult<Void> addMiddleConfig(@RequestBody SysTenantConfig sysTenantConfig) {
        sysTenantConfigService.addMiddleConfig(sysTenantConfig);
        return ApiResult.success();
    }

    /**
     * 租户管理-系统配置-租户配置修改
     *
     * @param sysTenantConfig
     * @return
     */
    @Log(title = "修改租户信息", businessType = BusinessType.UPDATE)
    @PostMapping("updaMiddleConfig")
    public ApiResult<Void> updaMiddleConfig(@RequestBody SysTenantConfig sysTenantConfig) {
        sysTenantConfigService.updaMiddleConfig(sysTenantConfig);
        return ApiResult.success();
    }

    /**
     * 租户管理-系统配置-图片上传
     *
     * @param file    图片
     * @param request
     * @return
     */
    @PostMapping("pictureUpload")
    public ApiResult<String> pictureUpload(@RequestParam(value = "file", required = false) MultipartFile file, HttpServletRequest request
    ) {
        return ApiResult.success(sysTenantConfigService.pictureUpload(file, request));
    }


    /**
     * 租户管理-系统配置-首页请求地址下拉框查询
     *
     * @param tenantId 租户ID
     * @return
     */
    @GetMapping("/getMenuBoxList")
    public ApiResult<List<SysMenu>> getMenuBoxList(@RequestParam Integer tenantId) {
        return ApiResult.success(sysTenantConfigService.getMenuBoxList(tenantId));
    }

}

