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.CommentContent;
import com.ruoyi.system.service.ICommentContentService;
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/commentContent")
public class CommentContentController extends BaseController {
    @Autowired
    private ICommentContentService commentContentService;

    /**
     * 查询社区资讯评论内容列表
     */
    @PreAuthorize("@ss.hasPermi('wuYe:commentContent:list')")
    @GetMapping("/list")
    public TableDataInfo list(CommentContent commentContent) {
        startPage();
        List<CommentContent> list = commentContentService.selectCommentContentList(commentContent);
        return getDataTable(list);
    }

    /**
     * 导出社区资讯评论内容列表
     */
    @PreAuthorize("@ss.hasPermi('wuYe:commentContent:export')")
    @Log(title = "社区资讯评论内容", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CommentContent commentContent) {
        List<CommentContent> list = commentContentService.selectCommentContentList(commentContent);
        ExcelUtil<CommentContent> util = new ExcelUtil<CommentContent>(CommentContent.class);
        util.exportExcel(response, list, "社区资讯评论内容数据");
    }

    /**
     * 获取社区资讯评论内容详细信息
     */
    @PreAuthorize("@ss.hasPermi('wuYe:commentContent:query')")
    @GetMapping(value = "/{contentId}")
    public AjaxResult getInfo(@PathVariable("contentId") Long contentId) {
        return success(commentContentService.selectCommentContentByContentId(contentId));
    }

    /**
     * 新增社区资讯评论内容
     */
    @PreAuthorize("@ss.hasPermi('wuYe:commentContent:add')")
    @Log(title = "社区资讯评论内容", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CommentContent commentContent) {
        return toAjax(commentContentService.insertCommentContent(commentContent));
    }

    /**
     * 修改社区资讯评论内容
     */
    @PreAuthorize("@ss.hasPermi('wuYe:commentContent:edit')")
    @Log(title = "社区资讯评论内容", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody CommentContent commentContent) {
        return toAjax(commentContentService.updateCommentContent(commentContent));
    }

    /**
     * 删除社区资讯评论内容
     */
    @PreAuthorize("@ss.hasPermi('wuYe:commentContent:remove')")
    @Log(title = "社区资讯评论内容", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{contentIds}")
    public AjaxResult remove(@PathVariable Long[] contentIds) {
        return toAjax(commentContentService.deleteCommentContentByContentIds(contentIds));
    }
}
