package com.ruoyi.api.controller.clock;

import cn.hutool.core.util.ObjectUtil;
import com.ruoyi.api.controller.common.AbstractApiController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.system.domain.SysOss;
import com.ruoyi.system.service.ISysOssService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.HashMap;
import java.util.Map;

/**
 * 公共Controller
 *
 * @author pengc
 * @date 2026-03-11
 */
@Validated
@Api(value = "公共", tags = {"公共管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/common")
public class ApiCommonController extends AbstractApiController {

    private final ISysOssService iSysOssService;

    /**
     * 上传到本地 OSS对象存储
     */
    @PostMapping("/local-upload")
    public R<Map<String, String>> localUpload(@RequestPart("file") MultipartFile file) {
        if (ObjectUtil.isNull(file)) {
            throw new ServiceException("上传文件不能为空");
        }
        SysOss oss = iSysOssService.localUpload(file);
        Map<String, String> map = new HashMap<>(2);
        map.put("url", oss.getUrl());
        map.put("fileName", oss.getFileName());
        return R.ok(map);
    }

}
