package com.ruoyi.web.controller.communityNews;

import com.ruoyi.common.annotation.Anonymous;
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.framework.manager.AsyncManager;
import com.ruoyi.framework.manager.factory.AsyncFactory;
import com.ruoyi.system.domain.communityNews.CommentLikes;
import com.ruoyi.system.service.ICommentLikesService;
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.List;

/**
 * 社区资讯点赞Controller
 *
 * @author boman
 * @date 2025-02-25
 */
@RestController
@RequestMapping("/wuYe/commentLikes")
public class CommentLikesController extends BaseController {
    @Autowired
    private ICommentLikesService commentLikesService;

    /**
     * 查询社区资讯点赞列表
     */
    @PreAuthorize("@ss.hasPermi('wuYe:commentLikes:list')")
    @GetMapping("/list")
    public TableDataInfo list(CommentLikes commentLikes) {
        startPage();
        List<CommentLikes> list = commentLikesService.selectCommentLikesList(commentLikes);
        return getDataTable(list);
    }

    /**
     * 导出社区资讯点赞列表
     */
    @PreAuthorize("@ss.hasPermi('wuYe:commentLikes:export')")
    @Log(title = "社区资讯点赞", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CommentLikes commentLikes) {
        List<CommentLikes> list = commentLikesService.selectCommentLikesList(commentLikes);
        ExcelUtil<CommentLikes> util = new ExcelUtil<CommentLikes>(CommentLikes.class);
        util.exportExcel(response, list, "社区资讯点赞数据");
    }

    /**
     * 获取社区资讯点赞详细信息
     */
    @PreAuthorize("@ss.hasPermi('wuYe:commentLikes:query')")
    @GetMapping(value = "/{likesId}")
    public AjaxResult getInfo(@PathVariable("likesId") Long likesId) {
        return success(commentLikesService.selectCommentLikesByLikesId(likesId));
    }

    /**
     * 新增社区资讯点赞
     */
    @PreAuthorize("@ss.hasPermi('wuYe:commentLikes:add')")
    @Log(title = "社区资讯点赞", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CommentLikes commentLikes) {
        return toAjax(commentLikesService.insertCommentLikes(commentLikes));
    }

    /**
     * 修改社区资讯点赞
     */
    @PreAuthorize("@ss.hasPermi('wuYe:commentLikes:edit')")
    @Log(title = "社区资讯点赞", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody CommentLikes commentLikes) {
        return toAjax(commentLikesService.updateCommentLikes(commentLikes));
    }

    /**
     * 删除社区资讯点赞
     */
    @PreAuthorize("@ss.hasPermi('wuYe:commentLikes:remove')")
    @Log(title = "社区资讯点赞", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{likesIds}")
    public AjaxResult remove(@PathVariable Long[] likesIds) {
        return toAjax(commentLikesService.deleteCommentLikesByLikesIds(likesIds));
    }


    /**
     * 进行点赞操作
     */
    @PostMapping("/giveTheThumbs")
    @Anonymous
    public AjaxResult giveTheThumbs(@RequestBody CommentLikes commentLikes) {
        AsyncManager.me().execute(AsyncFactory.giveTheThumbs(commentLikes));
        System.out.println("点赞返回");
        return  AjaxResult.success();
    }
}
