package com.ruoyi.frequency.voterecord.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.voterecord.entity.VoteRecord;
import com.ruoyi.frequency.voterecord.service.VoteRecordService;
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/voterecord")
public class VoteRecordController extends BaseController
{
    @Autowired
    private VoteRecordService voteRecordService;

    /**
     * 查询投票记录列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:voterecord:list')")
    @PostMapping("/list")
    public TableDataInfo<VoteRecord> list(@RequestBody VoteRecord voteRecord)
    {
        startPage();
        List<VoteRecord> list = voteRecordService.selectVoteRecordList(voteRecord);
        return getDataTable(list);
    }

    /**
     * 导出投票记录列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:voterecord:export')")
    @Log(title = "投票记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(VoteRecord voteRecord)
    {
        List<VoteRecord> list = voteRecordService.selectVoteRecordList(voteRecord);
        ExcelUtil<VoteRecord> util = new ExcelUtil<VoteRecord>(VoteRecord.class);
        return util.exportExcel(list, "投票记录数据");
    }

    /**
     * 获取投票记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:voterecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult<VoteRecord> getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(voteRecordService.selectVoteRecordById(id));
    }

    /**
     * 新增投票记录
     */
    @PreAuthorize("@ss.hasPermi('frequency:voterecord:add')")
    @Log(title = "投票记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VoteRecord voteRecord)
    {
        return toAjax(voteRecordService.insertVoteRecord(voteRecord));
    }

    /**
     * 修改投票记录
     */
    @PreAuthorize("@ss.hasPermi('frequency:voterecord:edit')")
    @Log(title = "投票记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VoteRecord voteRecord)
    {
        return toAjax(voteRecordService.updateVoteRecord(voteRecord));
    }

    /**
     * 删除投票记录
     */
    @PreAuthorize("@ss.hasPermi('frequency:voterecord:remove')")
    @Log(title = "投票记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(voteRecordService.deleteVoteRecordByIds(ids));
    }
}
