package org.dromara.controller.communityNews;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.domain.communityNews.bo.CommentContentBo;
import org.dromara.domain.communityNews.vo.CommentContentVo;
import org.dromara.service.ICommentContentService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 社区资讯评论内容
 *
 * @author boman
 * @date 2025-04-11
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/wuYe/commentContent")
public class CommentContentController extends BaseController {

    private final ICommentContentService commentContentService;

    /**
     * 查询社区资讯评论内容列表
     */
    @SaCheckPermission("wuYe:commentContent:list")
    @GetMapping("/list")
    public TableDataInfo<CommentContentVo> list(CommentContentBo bo, PageQuery pageQuery) {
        return commentContentService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出社区资讯评论内容列表
     */
    @SaCheckPermission("wuYe:commentContent:export")
    @Log(title = "社区资讯评论内容", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(CommentContentBo bo, HttpServletResponse response) {
        List<CommentContentVo> list = commentContentService.queryList(bo);
        ExcelUtil.exportExcel(list, "社区资讯评论内容", CommentContentVo.class, response);
    }

    /**
     * 获取社区资讯评论内容详细信息
     *
     * @param contentId 主键
     */
    @SaCheckPermission("wuYe:commentContent:query")
    @GetMapping("/{contentId}")
    public R<CommentContentVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long contentId) {
        return R.ok(commentContentService.queryById(contentId));
    }

    /**
     * 新增社区资讯评论内容
     */
    @SaCheckPermission("wuYe:commentContent:add")
    @Log(title = "社区资讯评论内容", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody CommentContentBo bo) {
        return toAjax(commentContentService.insertByBo(bo));
    }

    /**
     * 修改社区资讯评论内容
     */
    @SaCheckPermission("wuYe:commentContent:edit")
    @Log(title = "社区资讯评论内容", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/put")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody CommentContentBo bo) {
        return toAjax(commentContentService.updateByBo(bo));
    }

    /**
     * 删除社区资讯评论内容
     *
     * @param contentIds 主键串
     */
    @SaCheckPermission("wuYe:commentContent:remove")
    @Log(title = "社区资讯评论内容", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{contentIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] contentIds) {
        return toAjax(commentContentService.deleteWithValidByIds(List.of(contentIds), true));
    }
}
