package com.vetti.web.controller.hotake;


import com.vetti.common.annotation.Log;
import com.vetti.common.core.controller.BaseController;
import com.vetti.common.core.domain.AjaxResult;
import com.vetti.common.core.domain.R;
import com.vetti.common.core.page.TableDataInfo;
import com.vetti.common.enums.BusinessType;
import com.vetti.common.utils.poi.ExcelUtil;
import com.vetti.hotake.domain.HotakeSysFile;
import com.vetti.hotake.domain.dto.HotakeSysFileDto;
import com.vetti.hotake.domain.vo.HotakeSysFileVo;
import com.vetti.hotake.service.IHotakeSysFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 文件管理Controller
 *
 * @author ID
 * @date 2025-09-06
 */
@Api(tags = "文件管理")
@RestController
@RequestMapping("/hotake/sysFile")
public class HotakeSysFileController extends BaseController {

    @Autowired
    private IHotakeSysFileService hotakeSysFileService;

    /**
     * 查询文件管理列表
     */
    @ApiOperation("查询文件管理列表")
    @GetMapping("/list")
    public TableDataInfo list(HotakeSysFile HotakeSysFile) {
        startPage();
        List<HotakeSysFileDto> list = hotakeSysFileService.selectHotakeSysFileList(HotakeSysFile);
        return getDataTable(list);
    }

    /**
     * 导出文件管理列表
     */
    @ApiOperation("导出文件管理列表")
    @Log(title = "文件管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HotakeSysFile HotakeSysFile) {
        List<HotakeSysFileDto> list = hotakeSysFileService.selectHotakeSysFileList(HotakeSysFile);
        ExcelUtil<HotakeSysFileDto> util = new ExcelUtil<HotakeSysFileDto>(HotakeSysFileDto.class);
        return util.exportExcel(list, "文件管理数据");
    }

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

    /**
     * 新增文件管理
     */
    @ApiOperation("新增文件管理")
    @Log(title = "文件管理", businessType = BusinessType.INSERT)
    @PostMapping
    public R<HotakeSysFile> add(@RequestPart("file") MultipartFile file, HotakeSysFileVo fileVo) {
        HotakeSysFile sysFile = hotakeSysFileService.insertHotakeSysFile(file, fileVo);
        return R.ok(sysFile);
    }

    /**
     * 修改文件管理
     */
    @ApiOperation("修改文件管理")
    @Log(title = "文件管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestPart(name = "file", required = false) MultipartFile file, HotakeSysFile HotakeSysFile) {
        return toAjax(hotakeSysFileService.updateHotakeSysFile(file, HotakeSysFile));
    }

    /**
     * 删除文件管理
     */
    @ApiOperation("删除文件管理")
    @Log(title = "文件管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(hotakeSysFileService.deleteHotakeSysFileByIds(ids));
    }

    @ApiOperation("禁用文件管理")
    @Log(title = "文件管理", businessType = BusinessType.UPDATE)
    @PutMapping("/available/{id}")
    public AjaxResult availableSysFile(@PathVariable Long id) {
        return toAjax(hotakeSysFileService.availableSysFile(id));
    }
}
