package com.ruoyi.file.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
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.file.domain.DownloadRecord;
import com.ruoyi.file.service.IDownloadRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 下载记录Controller
 * 
 * @author liangwen
 * @date 2025-09-12
 */
@RestController
@RequestMapping("/file/downloadRecord")
public class DownloadRecordController extends BaseController
{
    @Autowired
    private IDownloadRecordService downloadRecordService;

    /**
     * 查询下载记录列表
     */
    @PreAuthorize("@ss.hasPermi('file:downloadRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(DownloadRecord downloadRecord)
    {
        startPage();
        List<DownloadRecord> list = downloadRecordService.selectDownloadRecordList(downloadRecord);
        return getDataTable(list);
    }

    /**
     * 导出下载记录列表
     */
    @PreAuthorize("@ss.hasPermi('file:downloadRecord:export')")
    @Log(title = "下载记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DownloadRecord downloadRecord)
    {
        List<DownloadRecord> list = downloadRecordService.selectDownloadRecordList(downloadRecord);
        ExcelUtil<DownloadRecord> util = new ExcelUtil<DownloadRecord>(DownloadRecord.class);
        util.exportExcel(response, list, "下载记录数据");
    }

    /**
     * 获取下载记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('file:downloadRecord:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {
        return success(downloadRecordService.selectDownloadRecordByRecordId(recordId));
    }

    /**
     * 新增下载记录
     */
    @PreAuthorize("@ss.hasPermi('file:downloadRecord:add')")
    @Log(title = "下载记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DownloadRecord downloadRecord)
    {
        return toAjax(downloadRecordService.insertDownloadRecord(downloadRecord));
    }

    /**
     * 修改下载记录
     */
    @PreAuthorize("@ss.hasPermi('file:downloadRecord:edit')")
    @Log(title = "下载记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DownloadRecord downloadRecord)
    {
        return toAjax(downloadRecordService.updateDownloadRecord(downloadRecord));
    }

    /**
     * 删除下载记录
     */
    @PreAuthorize("@ss.hasPermi('file:downloadRecord:remove')")
    @Log(title = "下载记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(downloadRecordService.deleteDownloadRecordByRecordIds(recordIds));
    }
}
