package com.ruoyi.web.controller;

import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import javax.servlet.http.HttpServletResponse;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.common.utils.file.FileUtils;
import io.swagger.annotations.ApiOperation;
import lombok.Cleanup;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.FileInfo;
import com.ruoyi.web.service.IFileInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 文件信息Controller
 * 
 * @author shenzx
 * @date 2025-09-26
 */
@RestController
@RequestMapping("/file/info")
public class FileInfoController extends BaseController
{
    private IFileInfoService fileInfoService;
    @Autowired
    public void setFileInfoService(IFileInfoService fileInfoService) {
        this.fileInfoService = fileInfoService;
    }

    /**
     * 查询文件信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(FileInfo fileInfo)
    {
        startPage();
        QueryWrapper<FileInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.setEntity(fileInfo);
        List<FileInfo> fileInfoList = fileInfoService.list(queryWrapper);
        return getDataTable(fileInfoList);
    }

    /**
     * 导出文件信息列表
     */
    @Log(title = "文件信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FileInfo fileInfo)
    {
        QueryWrapper<FileInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.setEntity(fileInfo);
        List<FileInfo> list = fileInfoService.list(queryWrapper);
        ExcelUtil<FileInfo> util = new ExcelUtil<>(FileInfo.class);
        util.exportExcel(response, list, "文件信息数据");
    }

    /**
     * 获取文件信息详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(fileInfoService.getById(id));
    }

    /**
     * 新增文件信息
     */
    @Log(title = "文件信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FileInfo fileInfo)
    {
        fileInfoService.save(fileInfo);
        return success(fileInfo);
    }

    /**
     * 修改文件信息
     */
    @Log(title = "文件信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FileInfo fileInfo)
    {
        fileInfoService.updateById(fileInfo);
        return success(fileInfo);
    }

    /**
     * 删除文件信息
     */
    @Log(title = "文件信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fileInfoService.removeByIds(Arrays.asList(ids)));
    }
}
