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.system.domain.communityNews.CommunityNews;
import com.ruoyi.system.domain.communityNews.vo.CommentInteractionVo;
import com.ruoyi.system.service.ICommunityNewsService;
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-14
 */
@RestController
@RequestMapping("/wuYe/news")
public class CommunityNewsController extends BaseController {
    @Autowired
    private ICommunityNewsService communityNewsService;

    /**
     * 查询社区资讯列表
     */
    @PreAuthorize("@ss.hasPermi('wuYe:news:list')")
    @GetMapping("/list")
    public TableDataInfo list(CommunityNews communityNews) {
        startPage();
        List<CommunityNews> list = communityNewsService.selectCommunityNewsList(communityNews);
        return getDataTable(list);
    }

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

    /**
     * 获取社区资讯详细信息
     */
    @PreAuthorize("@ss.hasPermi('wuYe:news:query')")
    @GetMapping(value = "/{communityId}")
    public AjaxResult getInfo(@PathVariable("communityId") Long communityId) {
        return success(communityNewsService.selectCommunityNewsByCommunityId(communityId));
    }

    /**
     * 新增社区资讯
     */
    @PreAuthorize("@ss.hasPermi('wuYe:news:add')")
    @Log(title = "社区资讯", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CommunityNews communityNews) {
        return toAjax(communityNewsService.insertCommunityNews(communityNews));
    }

    /**
     * 修改社区资讯
     */
    @PreAuthorize("@ss.hasPermi('wuYe:news:edit')")
    @Log(title = "社区资讯", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody CommunityNews communityNews) {
        return toAjax(communityNewsService.updateCommunityNews(communityNews));
    }

    /**
     * 删除社区资讯 等于把资讯关闭status = 2
     */
    @PreAuthorize("@ss.hasPermi('wuYe:news:remove')")
    @Log(title = "社区资讯", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{communityIds}")
    public AjaxResult remove(@PathVariable Long[] communityIds) {
        return toAjax(communityNewsService.deleteCommunityNewsByCommunityIds(communityIds));
    }


    /**
     * 获取未读互动数量
     */
    @PreAuthorize("@ss.hasPermi('wuYe:news:getCommentInteractionCount')")
    @PostMapping("/getCommentInteractionCount")
    public AjaxResult getCommentInteractionCount(@RequestBody CommentInteractionVo commentInteractionVo) {
        return communityNewsService.getCommentInteractionCount(commentInteractionVo);
    }
    /**
     * 获取未读互动列表
     */
    @PreAuthorize("@ss.hasPermi('wuYe:news:getCommentInteraction')")
    @PostMapping("/getCommentInteraction")
    public AjaxResult getCommentInteraction(@RequestBody CommentInteractionVo commentInteractionVo) {
        return communityNewsService.getCommentInteraction(commentInteractionVo);
    }
}
