package com.ruoyi.web.controller.communityNews;

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.CommentStars;
import com.ruoyi.system.service.ICommentStarsService;
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/commentStars")
public class CommentStarsController extends BaseController {
    @Autowired
    private ICommentStarsService commentStarsService;

    /**
     * 查询社区资讯收藏列表
     */
    @PreAuthorize("@ss.hasPermi('wuYe:commentStars:list')")
    @GetMapping("/list")
    public TableDataInfo list(CommentStars commentStars) {
        startPage();
        List<CommentStars> list = commentStarsService.selectCommentStarsList(commentStars);
        return getDataTable(list);
    }

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

    /**
     * 获取社区资讯收藏详细信息
     */
    @PreAuthorize("@ss.hasPermi('wuYe:commentStars:query')")
    @GetMapping(value = "/{starsId}")
    public AjaxResult getInfo(@PathVariable("starsId") Long starsId) {
        return success(commentStarsService.selectCommentStarsByStarsId(starsId));
    }

    /**
     * 新增社区资讯收藏
     */
    @PreAuthorize("@ss.hasPermi('wuYe:commentStars:add')")
    @Log(title = "社区资讯收藏", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CommentStars commentStars) {
        return toAjax(commentStarsService.insertCommentStars(commentStars));
    }

    /**
     * 修改社区资讯收藏
     */
    @PreAuthorize("@ss.hasPermi('wuYe:commentStars:edit')")
    @Log(title = "社区资讯收藏", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody CommentStars commentStars) {
        return toAjax(commentStarsService.updateCommentStars(commentStars));
    }

    /**
     * 删除社区资讯收藏
     */
    @PreAuthorize("@ss.hasPermi('wuYe:commentStars:remove')")
    @Log(title = "社区资讯收藏", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{starsIds}")
    public AjaxResult remove(@PathVariable Long[] starsIds) {
        return toAjax(commentStarsService.deleteCommentStarsByStarsIds(starsIds));
    }


    /**
     * 社区资讯收藏或取消收藏
     */
    @Log(title = "社区资讯收藏", businessType = BusinessType.INSERT)
    @PostMapping("/getStars")
    public AjaxResult getStars(@RequestBody CommentStars commentStars) {
        AsyncManager.me().execute(AsyncFactory.getStars(commentStars));
        return AjaxResult.success();
    }

    /**
     * 党建收藏或取消收藏
     */
    @PostMapping("/getPartyNewsStars")
    public AjaxResult getPartyNewsStars(@RequestBody CommentStars commentStars) {
        AsyncManager.me().execute(AsyncFactory.getPartyNewsStars(commentStars));
        return AjaxResult.success();
    }
}
