package com.ruoyi.web.controller.iit;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.iit.domain.IitFileInfo;
import com.ruoyi.iit.service.IIitFileInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 文件管理Controller
 *
 * @author Hao Li
 * @date 2025-04-11
 */
@RestController
@RequestMapping("/iit/file")
public class IitFileInfoController extends BaseController {
    @Autowired
    private IIitFileInfoService iitFileInfoService;

    /**
     * 查询文件管理列表
     */
    @PreAuthorize("@ss.hasPermi('iit:file:list')")
    @GetMapping("/list")
    public TableDataInfo list(IitFileInfo iitFileInfo) {
        startPage();
        List<IitFileInfo> list = iitFileInfoService.selectIitFileInfoList(iitFileInfo);
        return getDataTable(list);
    }

    /**
     * 查询文件管理列表 - 我的文件
     */
    @PreAuthorize("@ss.hasPermi('iit:file:list')")
    @GetMapping("/myself/list")
    public TableDataInfo myselfList(IitFileInfo iitFileInfo) {
        startPage();
        List<IitFileInfo> list = iitFileInfoService.selectMyselfList(iitFileInfo);
        return getDataTable(list);
    }

    /**
     * 导出文件管理列表
     */
    @PreAuthorize("@ss.hasPermi('iit:file:export')")
    @Log(title = "文件管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IitFileInfo iitFileInfo) {
        List<IitFileInfo> list = iitFileInfoService.selectIitFileInfoList(iitFileInfo);
        ExcelUtil<IitFileInfo> util = new ExcelUtil<IitFileInfo>(IitFileInfo.class);
        util.exportExcel(response, list, "文件管理数据");
    }

    /**
     * 获取文件管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('iit:file:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(iitFileInfoService.selectIitFileInfoById(id));
    }

    /**
     * 新增文件管理
     */
    @PreAuthorize("@ss.hasPermi('iit:file:add')")
    @Log(title = "文件管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IitFileInfo iitFileInfo) {
        return toAjax(iitFileInfoService.insertIitFileInfo(iitFileInfo));
    }

    /**
     * 修改文件管理
     */
    @PreAuthorize("@ss.hasPermi('iit:file:edit')")
    @Log(title = "文件管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IitFileInfo iitFileInfo) {
        return toAjax(iitFileInfoService.updateIitFileInfo(iitFileInfo));
    }

    /**
     * 删除文件管理
     */
    @PreAuthorize("@ss.hasPermi('iit:file:remove')")
    @Log(title = "文件管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iitFileInfoService.deleteIitFileInfoByIds(ids));
    }
}
