package com.ruoyi.kaohe.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.kaohe.domain.KhVoteRecardParam;
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.KhVoteEmp;
import com.ruoyi.kaohe.service.IKhVoteEmpService;
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_emp")
public class KhVoteEmpController extends BaseController
{
    @Autowired
    private IKhVoteEmpService khVoteEmpService;

    /**
     * 查询投票选项列表
     */
    @PreAuthorize("@ss.hasPermi('kaohe:vote_emp:list')")
    @GetMapping("/list")
    public TableDataInfo list(KhVoteEmp khVoteEmp)
    {
        startPage();
        List<KhVoteEmp> list = khVoteEmpService.selectKhVoteEmpList(khVoteEmp);
        return getDataTable(list);
    }

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

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

    /**
     * 新增投票选项
     */
    @PreAuthorize("@ss.hasPermi('kaohe:vote_emp:add')")
    @Log(title = "投票选项", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KhVoteEmp khVoteEmp)
    {
        return toAjax(khVoteEmpService.insertKhVoteEmp(khVoteEmp));
    }

    /**
     * 修改投票选项
     */
    @PreAuthorize("@ss.hasPermi('kaohe:vote_emp:edit')")
    @Log(title = "投票选项", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KhVoteEmp khVoteEmp)
    {
        return toAjax(khVoteEmpService.updateKhVoteEmp(khVoteEmp));
    }

    /**
     * 进行投票——修改并计算对应的分值
     */
    @PreAuthorize("@ss.hasPermi('kaohe:vote_emp:edit')")
    @Log(title = "投票选项", businessType = BusinessType.UPDATE)
    @PutMapping("/voteSubmit")
    public AjaxResult voteSubmit(@RequestBody KhVoteRecardParam param)
    {
        return khVoteEmpService.voteSubmit(param);
    }

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