package com.ruoyi.web.controller.annex;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
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.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
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 com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BomanAnnex;
import com.ruoyi.system.service.IBomanAnnexService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 附件Controller
 * 
 * @author boman
 * @date 2023-11-13
 */
@RestController
@RequestMapping("/system/annex")
public class BomanAnnexController extends BaseController
{
    @Autowired
    private IBomanAnnexService bomanAnnexService;

    /**
     * 查询附件列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BomanAnnex bomanAnnex)
    {
        startPage();
        List<BomanAnnex> list = bomanAnnexService.selectBomanAnnexList(bomanAnnex);
        return getDataTable(list);
    }

    /**
     * 查询附件列表
     */
    @GetMapping("/listNo")
    public TableDataInfo listNo(BomanAnnex bomanAnnex)
    {

        List<BomanAnnex> list = bomanAnnexService.selectBomanAnnexList(bomanAnnex);
        return getDataTable(list);
    }

    /**
     * 导出附件列表
     */
    @PreAuthorize("@ss.hasPermi('system:annex:export')")
    @Log(title = "附件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BomanAnnex bomanAnnex)
    {
        List<BomanAnnex> list = bomanAnnexService.selectBomanAnnexList(bomanAnnex);
        ExcelUtil<BomanAnnex> util = new ExcelUtil<BomanAnnex>(BomanAnnex.class);
        util.exportExcel(response, list, "附件数据");
    }

    /**
     * 获取附件详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:annex:query')")
    @GetMapping(value = "/{annexId}")
    public AjaxResult getInfo(@PathVariable("annexId") Long annexId)
    {
        return success(bomanAnnexService.selectBomanAnnexByAnnexId(annexId));
    }

    /**
     * 新增附件
     */
    @PreAuthorize("@ss.hasPermi('system:annex:add')")
    @Log(title = "附件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BomanAnnex bomanAnnex)
    {

        return toAjax(bomanAnnexService.insertBomanAnnex(bomanAnnex));
    }

    /**
     * 修改附件
     */
    @PreAuthorize("@ss.hasPermi('system:annex:edit')")
    @Log(title = "附件", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody BomanAnnex bomanAnnex)
    {
        return toAjax(bomanAnnexService.updateBomanAnnex(bomanAnnex));
    }

    /**
     * 删除附件
     */
    @PreAuthorize("@ss.hasPermi('system:annex:remove')")
    @Log(title = "附件", businessType = BusinessType.DELETE)
	@GetMapping("/delete/{annexIds}")
    public AjaxResult remove(@PathVariable Long[] annexIds)
    {
        return toAjax(bomanAnnexService.deleteBomanAnnexByAnnexIds(annexIds));
    }
}
