package com.ruoyi.frequency.voteoption.controller;

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.poi.ExcelUtil;
import com.ruoyi.frequency.voteoption.entity.VoteOption;
import com.ruoyi.frequency.voteoption.service.VoteOptionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 投票选项Controller
 * 
 * @author liwenlong
 * @date 2023-10-12
 */
@RestController
@RequestMapping("/frequency/voteoption")
public class VoteOptionController extends BaseController
{
    @Autowired
    private VoteOptionService voteOptionService;

    /**
     * 查询投票选项列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:voteoption:list')")
    @GetMapping("/list")
    public TableDataInfo<VoteOption> list(VoteOption voteOption)
    {
        startPage();
        List<VoteOption> list = voteOptionService.selectVoteOptionList(voteOption);
        return getDataTable(list);
    }

    /**
     * 导出投票选项列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:voteoption:export')")
    @Log(title = "投票选项", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(VoteOption voteOption)
    {
        List<VoteOption> list = voteOptionService.selectVoteOptionList(voteOption);
        ExcelUtil<VoteOption> util = new ExcelUtil<VoteOption>(VoteOption.class);
        return util.exportExcel(list, "投票选项数据");
    }

    /**
     * 获取投票选项详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:voteoption:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult<VoteOption> getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(voteOptionService.selectVoteOptionById(id));
    }

    /**
     * 新增投票选项
     */
    @PreAuthorize("@ss.hasPermi('frequency:voteoption:add')")
    @Log(title = "投票选项", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VoteOption voteOption)
    {
        return toAjax(voteOptionService.insertVoteOption(voteOption));
    }

    /**
     * 修改投票选项
     */
    @PreAuthorize("@ss.hasPermi('frequency:voteoption:edit')")
    @Log(title = "投票选项", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VoteOption voteOption)
    {
        return toAjax(voteOptionService.updateVoteOption(voteOption));
    }

    /**
     * 删除投票选项
     */
    @PreAuthorize("@ss.hasPermi('frequency:voteoption:remove')")
    @Log(title = "投票选项", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(voteOptionService.deleteVoteOptionByIds(ids));
    }
}
