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

/**
 * 投票项Controller
 * 
 * @author hs
 * @date 2025-06-24
 */
@RestController
@RequestMapping("/kaohe/vote_items")
public class KhVoteItemsController extends BaseController
{
    @Autowired
    private IKhVoteItemsService khVoteItemsService;

    /**
     * 查询投票项列表
     */
    @PreAuthorize("@ss.hasPermi('kaohe:vote_items:list')")
    @GetMapping("/list")
    public TableDataInfo list(KhVoteItems khVoteItems)
    {
        startPage();
        List<KhVoteItems> list = khVoteItemsService.selectKhVoteItemsList(khVoteItems);
        return getDataTable(list);
    }

    /**
     * 导出投票项列表
     */
    @PreAuthorize("@ss.hasPermi('kaohe:vote_items:export')")
    @Log(title = "投票项", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KhVoteItems khVoteItems)
    {
        List<KhVoteItems> list = khVoteItemsService.selectKhVoteItemsList(khVoteItems);
        ExcelUtil<KhVoteItems> util = new ExcelUtil<KhVoteItems>(KhVoteItems.class);
        util.exportExcel(response, list, "投票项数据");
    }

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

    /**
     * 新增投票项
     */
    @PreAuthorize("@ss.hasPermi('kaohe:vote_items:add')")
    @Log(title = "投票项", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KhVoteItems khVoteItems)
    {
        return toAjax(khVoteItemsService.insertKhVoteItems(khVoteItems));
    }

    /**
     * 修改投票项
     */
    @PreAuthorize("@ss.hasPermi('kaohe:vote_items:edit')")
    @Log(title = "投票项", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KhVoteItems khVoteItems)
    {
        return toAjax(khVoteItemsService.updateKhVoteItems(khVoteItems));
    }

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