package com.ruoyi.web.controller.system;

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.system.domain.SysDeptfile;
import com.ruoyi.system.service.ISysDeptfileService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 部门文件Controller
 * 
 * @author ruoyi
 * @date 2023-08-23
 */
@RestController
@RequestMapping("/system/deptfile")
public class SysDeptfileController extends BaseController
{
    @Autowired
    private ISysDeptfileService sysDeptfileService;

    /**
     * 查询部门文件列表
     */
    @PreAuthorize("@ss.hasPermi('system:deptfile:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysDeptfile sysDeptfile)
    {
        startPage();
        List<SysDeptfile> list = sysDeptfileService.selectSysDeptfileList(sysDeptfile);
        return getDataTable(list);
    }

    /**
     * 导出部门文件列表
     */
    @PreAuthorize("@ss.hasPermi('system:deptfile:export')")
    @Log(title = "部门文件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysDeptfile sysDeptfile)
    {
        List<SysDeptfile> list = sysDeptfileService.selectSysDeptfileList(sysDeptfile);
        ExcelUtil<SysDeptfile> util = new ExcelUtil<SysDeptfile>(SysDeptfile.class);
        util.exportExcel(response, list, "部门文件数据");
    }

    /**
     * 获取部门文件详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:deptfile:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysDeptfileService.selectSysDeptfileById(id));
    }

    /**
     * 新增部门文件
     */
    @PreAuthorize("@ss.hasPermi('system:deptfile:add')")
    @Log(title = "部门文件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysDeptfile sysDeptfile)
    {
        return toAjax(sysDeptfileService.insertSysDeptfile(sysDeptfile));
    }

    /**
     * 修改部门文件
     */
    @PreAuthorize("@ss.hasPermi('system:deptfile:edit')")
    @Log(title = "部门文件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysDeptfile sysDeptfile)
    {
        return toAjax(sysDeptfileService.updateSysDeptfile(sysDeptfile));
    }

    /**
     * 删除部门文件
     */
    @PreAuthorize("@ss.hasPermi('system:deptfile:remove')")
    @Log(title = "部门文件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysDeptfileService.deleteSysDeptfileByIds(ids));
    }
}
