package com.hzs.system.sys.controller.manage;

import com.hzs.common.core.annotation.Log;
import com.hzs.common.core.enums.EOperationBusiness;
import com.hzs.common.core.enums.EOperationMethod;
import com.hzs.common.core.enums.EOperationModule;
import com.hzs.common.core.utils.UploadFileUtil;
import com.hzs.common.core.web.domain.AjaxResult;
import com.hzs.common.core.domain.FileResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 文件请求处理
 *
 * @author hzs
 */
@Slf4j
@RestController("manage")
public class SysFileController {

    /**
     * 文件上传请求
     */
    @Log(module = EOperationModule.COMMON_FILE, business = EOperationBusiness.COMMON_FILE, method = EOperationMethod.INSERT)
    @PostMapping("/upload")
    public AjaxResult upload(MultipartFile file, String path) {
        FileResult fileResult = UploadFileUtil.upload(file, path);
        if (null != fileResult) {
            return AjaxResult.success(fileResult);
        }
        return AjaxResult.error();
    }

}
