package com.ruoyi.web.controller.file;

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.SnowFlake;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.file.domain.FilesStorage;
import com.ruoyi.file.service.IFilesStorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 存放表Controller
 * 
 * @author cmc
 * @date 2022-09-06
 */
@RestController
@RequestMapping("/file/storage")
public class FilesStorageController extends BaseController
{
    @Autowired
    private IFilesStorageService filesStorageService;

    /**
     * 查询存放表列表
     */
    @GetMapping("/list")
    public TableDataInfo list(FilesStorage filesStorage)
    {
        startPage();
        List<FilesStorage> list = filesStorageService.selectFilesStorageList(filesStorage);
        return getDataTable(list);
    }

    /**
     * 导出存放表列表
     */
    @Log(title = "存放表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FilesStorage filesStorage)
    {
        List<FilesStorage> list = filesStorageService.selectFilesStorageList(filesStorage);
        ExcelUtil<FilesStorage> util = new ExcelUtil<FilesStorage>(FilesStorage.class);
        util.exportExcel(response, list, "存放表数据");
    }

    /**
     * 获取存放表详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(filesStorageService.selectFilesStorageById(id));
    }

    /**
     * 新增存放表
     */
    @Log(title = "存放表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FilesStorage filesStorage)
    {
        filesStorage.setId(new SnowFlake().generateId());
        return toAjax(filesStorageService.insertFilesStorage(filesStorage));
    }

    /**
     * 修改存放表
     */
    @Log(title = "存放表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FilesStorage filesStorage)
    {
        return toAjax(filesStorageService.updateFilesStorage(filesStorage));
    }

    /**
     * 删除存放表
     */
    @Log(title = "存放表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(filesStorageService.deleteFilesStorageByIds(ids));
    }
}
