package com.yunfeiyun.agmp.common.web.system.controller;

import com.yunfeiyun.agmp.common.core.domain.AjaxResult;
import com.yunfeiyun.agmp.common.core.page.TableDataInfo;
import com.yunfeiyun.agmp.common.web.system.domain.SysRes;
import com.yunfeiyun.agmp.common.web.system.service.ISysResService;
import com.yunfeiyun.agmp.common.annotation.Log;
import com.yunfeiyun.agmp.common.core.controller.BaseController;
import com.yunfeiyun.agmp.common.enums.BusinessType;
import com.yunfeiyun.agmp.common.utils.poi.ExcelUtil;
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 杨晓辉
 * @date 2023-05-08
 */
@RestController
@RequestMapping("/system/res")
public class SysResController extends BaseController
{
    @Autowired
    private ISysResService sysResService;

    /**
     * 查询资源列表
     */
    @PreAuthorize("@ss.hasPermi('system:sysres:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysRes sysRes)
    {
        startPage();
        List<SysRes> list = sysResService.selectSysResList(sysRes);
        return getDataTable(list);
    }

    /**
     * 导出资源列表
     */
    @PreAuthorize("@ss.hasPermi('system:sysres:export')")
    @Log(title = "资源", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysRes sysRes)
    {
        List<SysRes> list = sysResService.selectSysResList(sysRes);
        ExcelUtil<SysRes> util = new ExcelUtil<SysRes>(SysRes.class);
        util.exportExcel(response, list, "资源数据");
    }

    /**
     * 获取资源详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:sysres:query')")
    @GetMapping("/info")
    public AjaxResult getInfo(String resId)
    {
        return success(sysResService.selectSysResByResId(resId));
    }

    /**
     * 新增资源
     */
    @PreAuthorize("@ss.hasPermi('system:sysres:add')")
    @Log(title = "资源", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody SysRes sysRes)
    {
        return toAjax(sysResService.insertSysRes(sysRes));
    }

    /**
     * 修改资源
     */
    @PreAuthorize("@ss.hasPermi('system:sysres:edit')")
    @Log(title = "资源", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody SysRes sysRes)
    {
        return toAjax(sysResService.updateSysRes(sysRes));
    }

    /**
     * 删除资源
     */
    @PreAuthorize("@ss.hasPermi('system:sysres:remove')")
    @Log(title = "资源", businessType = BusinessType.DELETE)
	@DeleteMapping("/delete/{resIds}")
    public AjaxResult remove(@PathVariable String[] resIds)
    {
        return toAjax(sysResService.deleteSysResByResIds(resIds));
    }
}
