package com.ruoyi.kaohe.controller;

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.kaohe.domain.KhVoteRecard;
import com.ruoyi.kaohe.service.IKhVoteRecardService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 投票记录Controller
 * 
 * @author hs
 * @date 2025-06-17
 */
@RestController
@RequestMapping("/kaohe/vote_recard")
public class KhVoteRecardController extends BaseController
{
    @Autowired
    private IKhVoteRecardService khVoteRecardService;

    /**
     * 查询投票记录列表
     */
    @PreAuthorize("@ss.hasPermi('kaohe:vote_recard:list')")
    @GetMapping("/list")
    public TableDataInfo list(KhVoteRecard khVoteRecard)
    {
        startPage();
        List<KhVoteRecard> list = khVoteRecardService.selectKhVoteRecardList(khVoteRecard);
        return getDataTable(list);
    }

    /**
     * 导出投票记录列表
     */
    @PreAuthorize("@ss.hasPermi('kaohe:vote_recard:export')")
    @Log(title = "投票记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KhVoteRecard khVoteRecard)
    {
        List<KhVoteRecard> list = khVoteRecardService.selectKhVoteRecardList(khVoteRecard);
        ExcelUtil<KhVoteRecard> util = new ExcelUtil<KhVoteRecard>(KhVoteRecard.class);
        util.exportExcel(response, list, "投票记录数据");
    }

    /**
     * 获取投票记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('kaohe:vote_recard:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(khVoteRecardService.selectKhVoteRecardById(id));
    }

    /**
     * 新增投票记录
     */
    @PreAuthorize("@ss.hasPermi('kaohe:vote_recard:add')")
    @Log(title = "投票记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KhVoteRecard khVoteRecard)
    {
        return toAjax(khVoteRecardService.insertKhVoteRecard(khVoteRecard));
    }

    /**
     * 修改投票记录
     */
    @PreAuthorize("@ss.hasPermi('kaohe:vote_recard:edit')")
    @Log(title = "投票记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KhVoteRecard khVoteRecard)
    {
        return toAjax(khVoteRecardService.updateKhVoteRecard(khVoteRecard));
    }

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