package com.ruoyi.frequency.like.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.like.entity.Like;
import com.ruoyi.frequency.like.service.LikeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 点赞(新闻,活动)Controller
 * 
 * @author liwenlong
 * @date 2024-04-16
 */
@RestController
@RequestMapping("/frequency/like")
public class LikeController extends BaseController
{
    @Autowired
    private LikeService likeService;

    /**
     * 查询点赞(新闻,活动)列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:like:list')")
    @GetMapping("/list")
    public TableDataInfo<Like> list(Like like)
    {
        startPage();
        List<Like> list = likeService.selectLikeList(like);
        return getDataTable(list);
    }

    /**
     * 导出点赞(新闻,活动)列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:like:export')")
    @Log(title = "点赞(新闻,活动)", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Like like)
    {
        List<Like> list = likeService.selectLikeList(like);
        ExcelUtil<Like> util = new ExcelUtil<Like>(Like.class);
        return util.exportExcel(list, "点赞(新闻,活动)数据");
    }

    /**
     * 获取点赞(新闻,活动)详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:like:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult<Like> getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(likeService.selectLikeById(id));
    }

    /**
     * 新增点赞(新闻,活动)
     */
    @PreAuthorize("@ss.hasPermi('frequency:like:add')")
    @Log(title = "点赞(新闻,活动)", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Like like)
    {
        return toAjax(likeService.insertLike(like));
    }

    /**
     * 修改点赞(新闻,活动)
     */
    @PreAuthorize("@ss.hasPermi('frequency:like:edit')")
    @Log(title = "点赞(新闻,活动)", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Like like)
    {
        return toAjax(likeService.updateLike(like));
    }

    /**
     * 删除点赞(新闻,活动)
     */
    @PreAuthorize("@ss.hasPermi('frequency:like:remove')")
    @Log(title = "点赞(新闻,活动)", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}/{delFlag}")
    public AjaxResult remove(@PathVariable("ids") Long[] ids,@PathVariable("delFlag") Integer delFlag)
    {
        return toAjax(likeService.deleteLikeByIds(ids,delFlag));
    }
}
