package com.ruoyi.web.controller.business;

import java.util.List;
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.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.SysOss;
import com.ruoyi.business.service.ISysOssService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 文件上传Controller
 * 
 * @author xiatao
 * @date 2022-01-18
 */
@Controller
@RequestMapping("/business/oss")
public class SysOssController extends BaseController
{
    private String prefix = "business/oss";

    @Autowired
    private ISysOssService sysOssService;

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

    /**
     * 查询文件上传列表
     */
    @RequiresPermissions("business:oss:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysOss sysOss)
    {
        startPage();
        List<SysOss> list = sysOssService.selectSysOssList(sysOss);
        return getDataTable(list);
    }

    /**
     * 导出文件上传列表
     */
    @RequiresPermissions("business:oss:export")
    @Log(title = "文件上传", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysOss sysOss)
    {
        List<SysOss> list = sysOssService.selectSysOssList(sysOss);
        ExcelUtil<SysOss> util = new ExcelUtil<SysOss>(SysOss.class);
        return util.exportExcel(list, "文件上传数据");
    }

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

    /**
     * 新增保存文件上传
     */
    @RequiresPermissions("business:oss:add")
    @Log(title = "文件上传", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysOss sysOss)
    {
        return toAjax(sysOssService.insertSysOss(sysOss));
    }

    /**
     * 修改文件上传
     */
    @RequiresPermissions("business:oss:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SysOss sysOss = sysOssService.selectSysOssById(id);
        mmap.put("sysOss", sysOss);
        return prefix + "/edit";
    }

    /**
     * 修改保存文件上传
     */
    @RequiresPermissions("business:oss:edit")
    @Log(title = "文件上传", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysOss sysOss)
    {
        return toAjax(sysOssService.updateSysOss(sysOss));
    }

    /**
     * 删除文件上传
     */
    @RequiresPermissions("business:oss:remove")
    @Log(title = "文件上传", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysOssService.deleteSysOssByIds(ids));
    }
}
