package com.ruoyi.frequency.votelike.controller;

import java.util.List;
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.frequency.votelike.entity.VoteLike;
import com.ruoyi.frequency.votelike.service.VoteLikeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 投票点赞Controller
 * 
 * @author liwenlong
 * @date 2024-04-10
 */
@RestController
@RequestMapping("/frequency/votelike")
public class VoteLikeController extends BaseController
{
    @Autowired
    private VoteLikeService voteLikeService;

    /**
     * 查询投票点赞列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:votelike:list')")
    @GetMapping("/list")
    public TableDataInfo<VoteLike> list(VoteLike voteLike)
    {
        startPage();
        List<VoteLike> list = voteLikeService.selectVoteLikeList(voteLike);
        return getDataTable(list);
    }

    /**
     * 导出投票点赞列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:votelike:export')")
    @Log(title = "投票点赞", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(VoteLike voteLike)
    {
        List<VoteLike> list = voteLikeService.selectVoteLikeList(voteLike);
        ExcelUtil<VoteLike> util = new ExcelUtil<VoteLike>(VoteLike.class);
        return util.exportExcel(list, "投票点赞数据");
    }

    /**
     * 获取投票点赞详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:votelike:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult<VoteLike> getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(voteLikeService.selectVoteLikeById(id));
    }

    /**
     * 新增投票点赞
     */
    @PreAuthorize("@ss.hasPermi('frequency:votelike:add')")
    @Log(title = "投票点赞", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VoteLike voteLike)
    {
        return toAjax(voteLikeService.insertVoteLike(voteLike));
    }

    /**
     * 修改投票点赞
     */
    @PreAuthorize("@ss.hasPermi('frequency:votelike:edit')")
    @Log(title = "投票点赞", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VoteLike voteLike)
    {
        return toAjax(voteLikeService.updateVoteLike(voteLike));
    }

    /**
     * 删除投票点赞
     */
    @PreAuthorize("@ss.hasPermi('frequency:votelike:remove')")
    @Log(title = "投票点赞", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}/{delFlag}")
    public AjaxResult remove(@PathVariable("ids") Long[] ids,@PathVariable("delFlag") Integer delFlag)
    {
        return toAjax(voteLikeService.deleteVoteLikeByIds(ids,delFlag));
    }
}
