package com.ruoyi.mall.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mall.domain.BusinessArticleComment;
import com.ruoyi.mall.service.IBusinessArticleCommentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 帖子评论Controller
 * 
 * @author ruoyi
 * @date 2023-10-18
 */
@RestController
@RequestMapping("/mall/ArticleComment")
public class BusinessArticleCommentController extends BaseController
{
    @Autowired
    private IBusinessArticleCommentService businessArticleCommentService;

    /**
     * 查询帖子评论列表
     */
    @PreAuthorize("@ss.hasPermi('mall:ArticleComment:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusinessArticleComment businessArticleComment)
    {
        startPage();
        List<BusinessArticleComment> list = businessArticleCommentService.selectBusinessArticleCommentList(businessArticleComment);
        return getDataTable(list);
    }

    /**
     * 导出帖子评论列表
     */
    @PreAuthorize("@ss.hasPermi('mall:ArticleComment:export')")
    @Log(title = "帖子评论", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusinessArticleComment businessArticleComment)
    {
        List<BusinessArticleComment> list = businessArticleCommentService.selectBusinessArticleCommentList(businessArticleComment);
        ExcelUtil<BusinessArticleComment> util = new ExcelUtil<BusinessArticleComment>(BusinessArticleComment.class);
        util.exportExcel(response, list, "帖子评论数据");
    }

    /**
     * 获取帖子评论详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:ArticleComment:query')")
    @GetMapping(value = "/{commentId}")
    public AjaxResult getInfo(@PathVariable("commentId") Long commentId)
    {
        return AjaxResult.success(businessArticleCommentService.selectBusinessArticleCommentByCommentId(commentId));
    }

    /**
     * 新增帖子评论
     */
    @PreAuthorize("@ss.hasPermi('mall:ArticleComment:add')")
    @Log(title = "帖子评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusinessArticleComment businessArticleComment)
    {
        return toAjax(businessArticleCommentService.insertBusinessArticleComment(businessArticleComment));
    }

    /**
     * 修改帖子评论
     */
    @PreAuthorize("@ss.hasPermi('mall:ArticleComment:edit')")
    @Log(title = "帖子评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusinessArticleComment businessArticleComment)
    {
        return toAjax(businessArticleCommentService.updateBusinessArticleComment(businessArticleComment));
    }

    /**
     * 删除帖子评论
     */
    @PreAuthorize("@ss.hasPermi('mall:ArticleComment:remove')")
    @Log(title = "帖子评论", businessType = BusinessType.DELETE)
	@DeleteMapping("/{commentIds}")
    public AjaxResult remove(@PathVariable Long[] commentIds)
    {
        return toAjax(businessArticleCommentService.deleteBusinessArticleCommentByCommentIds(commentIds));
    }
}
