package com.ruoyi.web.controller.system;

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.system.domain.DanganFile;
import com.ruoyi.system.service.IDanganFileService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 档案文件Controller
 * 
 * @author ruoyi
 * @date 2022-10-25
 */
@Controller
@RequestMapping("/system/danganFile")
public class DanganFileController extends BaseController
{
    private String prefix = "system/danganFile";

    @Autowired
    private IDanganFileService danganFileService;

    @RequiresPermissions("system:danganFile:view")
    @GetMapping()
    public String danganFile()
    {
        return prefix + "/danganFile";
    }

    /**
     * 查询档案文件列表
     */
    @RequiresPermissions("system:danganFile:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DanganFile danganFile)
    {
        startPage();
        List<DanganFile> list = danganFileService.selectDanganFileList(danganFile);
        return getDataTable(list);
    }

    /**
     * 导出档案文件列表
     */
    @RequiresPermissions("system:danganFile:export")
    @Log(title = "档案文件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DanganFile danganFile)
    {
        List<DanganFile> list = danganFileService.selectDanganFileList(danganFile);
        ExcelUtil<DanganFile> util = new ExcelUtil<DanganFile>(DanganFile.class);
        return util.exportExcel(list, "danganFile");
    }

    /**
     * 新增档案文件
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存档案文件
     */
    @RequiresPermissions("system:danganFile:add")
    @Log(title = "档案文件", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DanganFile danganFile)
    {
        return toAjax(danganFileService.insertDanganFile(danganFile));
    }

    /**
     * 修改档案文件
     */
    @GetMapping("/edit/{fileId}")
    public String edit(@PathVariable("fileId") Long fileId, ModelMap mmap)
    {
        DanganFile danganFile = danganFileService.selectDanganFileById(fileId);
        mmap.put("danganFile", danganFile);
        return prefix + "/edit";
    }

    /**
     * 修改保存档案文件
     */
    @RequiresPermissions("system:danganFile:edit")
    @Log(title = "档案文件", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DanganFile danganFile)
    {
        return toAjax(danganFileService.updateDanganFile(danganFile));
    }

    /**
     * 删除档案文件
     */
    @RequiresPermissions("system:danganFile:remove")
    @Log(title = "档案文件", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(danganFileService.deleteDanganFileByIds(ids));
    }
}
