package com.fjhx.feign;

import com.fjhx.entity.FileInfo;
import com.fjhx.service.FileInfoService;
import org.springblade.core.tool.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
public class FileClient implements IFileClient {

    @Autowired
    private FileInfoService fileInfoService;

    @PostMapping(BINDING_FILE)
    @Override
    public R bindingFile(String applicationName, Long businessId, Integer businessType, List<FileInfo> paramList) {
        fileInfoService.bindingFile(applicationName, businessId, businessType, paramList);
        return R.success();
    }

    @PostMapping(AGAIN_BINDING_FILE)
    @Override
    public R againBindingFile(String applicationName, Long businessId, Integer businessType, List<FileInfo> paramList) {
        fileInfoService.againBindingFile(applicationName, businessId, businessType, paramList);
        return R.success();
    }

    @PostMapping(RELIEVE_BINDING_FILE)
    @Override
    public R relieveBindingFile(Long businessId) {
        fileInfoService.relieveBindingFile(businessId);
        return R.success();
    }

    @PostMapping(GET_FILE_INFO)
    @Override
    public R<List<FileInfo>> getFileInfo(List<Long> businessIdList) {
        List<FileInfo> list = fileInfoService.getFileInfo(businessIdList);
        return R.success(list);
    }

    @PostMapping(value = UPLOAD_FILE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public R<FileInfo> uploadFile(@RequestPart("file") MultipartFile file) {
        FileInfo result = fileInfoService.uploadFile(file);
        return R.success(result);
    }

}
