package com.srs.web.controller.routine;

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

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.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.*;
import org.springframework.security.access.prepost.PreAuthorize;

import com.srs.routine.domain.SrsAttachResource;
import com.srs.routine.service.ISrsAttachResourceService;
import com.srs.common.core.controller.BaseController;
import com.srs.common.core.domain.AjaxResult;
import com.srs.common.utils.poi.ExcelUtil;
import com.srs.common.enums.BusinessType;
import com.srs.common.annotation.Log;
import com.srs.common.core.page.TableDataInfo;

/**
 * 附件资源Controller
 *
 * @author srs
 * @date 2024-05-18
 */
@RestController
@RequestMapping("/runtine/AttachResource")
@Api(value = "附件资源管理", tags = "附件资源管理")
public class SrsAttachResourceController extends BaseController {
    @Autowired
    private ISrsAttachResourceService srsAttachResourceService;

    /**
     * 查询附件资源列表
     */
    @PreAuthorize("@ss.hasPermi('runtine:AttachResource:list')")
    @GetMapping("/list")
    @ApiOperation("查询附件资源列表")
    public TableDataInfo list(SrsAttachResource srsAttachResource) {
        startPage();
        List<SrsAttachResource> list = srsAttachResourceService.selectSrsAttachResourceList(srsAttachResource);
        return getDataTable(list);
    }

    /**
     * 导出附件资源列表
     */
    @PreAuthorize("@ss.hasPermi('runtine:AttachResource:export')")
    @Log(title = "附件资源", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出附件资源列表")
    public void export(HttpServletResponse response, SrsAttachResource srsAttachResource) {
        List<SrsAttachResource> list = srsAttachResourceService.selectSrsAttachResourceList(srsAttachResource);
        ExcelUtil<SrsAttachResource> util = new ExcelUtil<SrsAttachResource>(SrsAttachResource.class);
        util.exportExcel(response, list, "附件资源数据");
    }

    /**
     * 获取附件资源详细信息
     */
    @PreAuthorize("@ss.hasPermi('runtine:AttachResource:query')")
    @GetMapping(value = "/{resId}")
    @ApiOperation("获取附件资源详细信息")
    public AjaxResult getInfo(@PathVariable("resId") Long resId) {
        return success(srsAttachResourceService.selectSrsAttachResourceByResId(resId));
    }

    /**
     * 新增附件资源
     */
    @PreAuthorize("@ss.hasPermi('runtine:AttachResource:add')")
    @Log(title = "附件资源", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("新增附件资源")
    public AjaxResult add(@RequestBody SrsAttachResource srsAttachResource) {
        return toAjax(srsAttachResourceService.insertSrsAttachResource(srsAttachResource));
    }

    /**
     * 修改附件资源
     */
    @PreAuthorize("@ss.hasPermi('runtine:AttachResource:edit')")
    @Log(title = "附件资源", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("修改附件资源")
    public AjaxResult edit(@RequestBody SrsAttachResource srsAttachResource) {
        return toAjax(srsAttachResourceService.updateSrsAttachResource(srsAttachResource));
    }

    /**
     * 删除附件资源
     */
    @PreAuthorize("@ss.hasPermi('runtine:AttachResource:remove')")
    @Log(title = "附件资源", businessType = BusinessType.DELETE)
    @PostMapping("/{resIds}")
    @ApiOperation("删除附件资源")
    public AjaxResult remove(@PathVariable Long[] resIds) {
        return toAjax(srsAttachResourceService.deleteSrsAttachResourceByResIds(resIds));
    }
}
