package com.unis.biz.modular.test.controller;

import com.unis.auth.core.pojo.SaBaseLoginUser;
import com.unis.auth.core.util.StpLoginUserUtil;
import com.unis.biz.modular.test.service.TestService;
import com.unis.common.pojo.CommonResult;
import com.unis.dev.api.DevFileApi;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * 测试
 *
 * @author ybw
 * @version V1.0
 * @className TestController
 * @date 2024/4/8
 **/
@RestController
public class TestController {

    @Resource
    private DevFileApi devFileApi;
    @Resource
    private TestService testService;


    /**
     * C端测试
     *
     * @methodName: get
     * @return: com.unis.common.pojo.CommonResult<java.lang.String>
     * @author: ybw
     * @date: 2024/4/8
     **/
    @GetMapping("/client/c/get")
    public CommonResult<String> get() {
        return CommonResult.data("OK");
    }


    /**
     * 测试上传minio，返回访问地址
     *
     * @param file
     * @methodName: storageFileWithReturnUrlMinio
     * @return: java.lang.String
     * @author: ybw
     * @date: 2024/4/11
     **/
    @PostMapping("/test/storageFileWithReturnUrlMinio")
    public String storageFileWithReturnUrlMinio(MultipartFile file) {
        return devFileApi.storageFileWithReturnUrlMinio(file);
    }


    /**
     * 测试登录
     *
     * @methodName: getLoginUser
     * @return: com.unis.auth.core.pojo.SaBaseLoginUser
     * @author: ybw
     * @date: 2024/4/18
     **/
    @PostMapping("/auth/getLoginUser")
    public SaBaseLoginUser getLoginUser() {
        return StpLoginUserUtil.getLoginUser();
    }

    /**
     * 导入excel
     *
     * @param file
     * @methodName: importExcel
     * @return: com.unis.common.pojo.CommonResult<String>
     * @author: ybw
     * @date: 2024/4/25
     **/
    @PostMapping("/test/import/excel")
    public CommonResult<String> importExcel(@RequestPart("file") MultipartFile file) {
        return CommonResult.data(testService.importExcel(file));
    }
}
