package com.ruoyi.szxc.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.szxc.domain.SzxcVoteResult;
import com.ruoyi.szxc.service.ISzxcVoteResultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 议事投票情况Controller
 * 
 * @author hs
 * @date 2024-03-20
 */
@RestController
@RequestMapping("/szxc/voteresut")
public class SzxcVoteResultController extends BaseController
{
    @Autowired
    private ISzxcVoteResultService szxcVoteResultService;

    /**
     * 查询议事投票情况列表
     */
    @PreAuthorize("@ss.hasPermi('szxc:voteresut:list')")
    @GetMapping("/list")
    public TableDataInfo list(SzxcVoteResult szxcVoteResult)
    {
        startPage();
        List<SzxcVoteResult> list = szxcVoteResultService.selectSzxcVoteResultList(szxcVoteResult);
        return getDataTable(list);
    }

    /**
     * 查询议事投票统计
     */
    @PreAuthorize("@ss.hasPermi('szxc:voteresut:count')")
    @GetMapping("/count")
    public Map<String,Object> ResultCount(SzxcVoteResult szxcVoteResult)
    {
        startPage();
        List<SzxcVoteResult> list = szxcVoteResultService.selectSzxcVoteResultList(szxcVoteResult);
        Map<String,Object>  result = new HashMap<String,Object>();
        result.put("data",getDataTable(list));
        result.put("result",szxcVoteResultService.selectSzxcVoteResultByDiscussId(szxcVoteResult.getYsId()));
        return result;
    }

    /**
     * 导出议事投票情况列表
     */
    @PreAuthorize("@ss.hasPermi('szxc:voteresut:export')")
    @Log(title = "议事投票情况", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SzxcVoteResult szxcVoteResult)
    {
        List<SzxcVoteResult> list = szxcVoteResultService.selectSzxcVoteResultList(szxcVoteResult);
        ExcelUtil<SzxcVoteResult> util = new ExcelUtil<SzxcVoteResult>(SzxcVoteResult.class);
        util.exportExcel(response, list, "议事投票情况数据");
    }

    /**
     * 获取议事投票情况详细信息
     */
    @PreAuthorize("@ss.hasPermi('szxc:voteresut:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(szxcVoteResultService.selectSzxcVoteResultById(id));
    }

    /**
     * 新增议事投票情况
     */
    @PreAuthorize("@ss.hasPermi('szxc:voteresut:add')")
    @Log(title = "议事投票情况", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SzxcVoteResult szxcVoteResult)
    {
        return toAjax(szxcVoteResultService.insertSzxcVoteResult(szxcVoteResult));
    }

    /**
     * 修改议事投票情况
     */
    @PreAuthorize("@ss.hasPermi('szxc:voteresut:edit')")
    @Log(title = "议事投票情况", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SzxcVoteResult szxcVoteResult)
    {
        return toAjax(szxcVoteResultService.updateSzxcVoteResult(szxcVoteResult));
    }

    /**
     * 删除议事投票情况
     */
    @PreAuthorize("@ss.hasPermi('szxc:voteresut:remove')")
    @Log(title = "议事投票情况", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(szxcVoteResultService.deleteSzxcVoteResultByIds(ids));
    }
}
