package com.fjhx.controller.common;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.fjhx.entity.common.CommonFile;
import com.fjhx.service.common.CommonFileService;
import org.springblade.core.tool.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 通用 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2022-08-08
 */
@RestController
@RequestMapping("/commonFile")
public class CommonFileController {

    @Autowired
    private CommonFileService commonFileService;

    @PostMapping("/upload")
    public R uploadFile(@RequestParam("file") MultipartFile file) {
        Map<String, String> result = commonFileService.uploadFile(file);
        return R.success(result);
    }

    @PostMapping("/list")
    public R list(@RequestBody CommonFile commonFile) {
        List<CommonFile> list = commonFileService.list(Wrappers.<CommonFile>lambdaQuery().eq(CommonFile::getBusinessId, commonFile.getBusinessId()));
        return R.success(list);
    }

}

