package com.yanzhu.jh.work.controller;

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.yanzhu.jh.work.domain.WorkFile;
import com.yanzhu.jh.work.service.IWorkFileService;
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 JIangYuQi
 * @date 2023-08-06
 */
@RestController
@RequestMapping("/work/workFile")
public class WorkFileController extends BaseController
{
    @Autowired
    private IWorkFileService workFileService;

    /**
     * 查询文件传达列表
     */
    @PreAuthorize("@ss.hasPermi('work:workFile:list')")
    @GetMapping("/list")
    public TableDataInfo list(WorkFile workFile)
    {
        startPage();
        List<WorkFile> list = workFileService.selectWorkFileList(workFile);
        return getDataTable(list);
    }

    /**
     * 导出文件传达列表
     */
    @PreAuthorize("@ss.hasPermi('work:workFile:export')")
    @Log(title = "文件传达", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WorkFile workFile)
    {
        List<WorkFile> list = workFileService.selectWorkFileList(workFile);
        ExcelUtil<WorkFile> util = new ExcelUtil<WorkFile>(WorkFile.class);
        util.exportExcel(response, list, "文件传达数据");
    }

    /**
     * 获取文件传达详细信息
     */
    @PreAuthorize("@ss.hasPermi('work:workFile:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(workFileService.selectWorkFileById(id));
    }

    /**
     * 新增文件传达
     */
    @PreAuthorize("@ss.hasPermi('work:workFile:add')")
    @Log(title = "文件传达", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorkFile workFile)
    {
        return toAjax(workFileService.insertWorkFile(workFile));
    }

    /**
     * 修改文件传达
     */
    @PreAuthorize("@ss.hasPermi('work:workFile:edit')")
    @Log(title = "文件传达", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorkFile workFile)
    {
        return toAjax(workFileService.updateWorkFile(workFile));
    }

    /**
     * 删除文件传达
     */
    @PreAuthorize("@ss.hasPermi('work:workFile:remove')")
    @Log(title = "文件传达", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(workFileService.deleteWorkFileByIds(ids));
    }
}
