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.ArticleTag;
import com.ruoyi.mall.service.IArticleTagService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 帖子话题Controller
 * 
 * @author ruoyi
 * @date 2023-11-09
 */
@RestController
@RequestMapping("/mall/ArticleTag")
public class ArticleTagController extends BaseController
{
    @Autowired
    private IArticleTagService articleTagService;

    /**
     * 查询帖子话题列表
     */
    @PreAuthorize("@ss.hasPermi('mall:ArticleTag:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArticleTag articleTag)
    {
        startPage();
        List<ArticleTag> list = articleTagService.selectArticleTagList(articleTag);
        return getDataTable(list);
    }

    /**
     * 导出帖子话题列表
     */
    @PreAuthorize("@ss.hasPermi('mall:ArticleTag:export')")
    @Log(title = "帖子话题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArticleTag articleTag)
    {
        List<ArticleTag> list = articleTagService.selectArticleTagList(articleTag);
        ExcelUtil<ArticleTag> util = new ExcelUtil<ArticleTag>(ArticleTag.class);
        util.exportExcel(response, list, "帖子话题数据");
    }

    /**
     * 获取帖子话题详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:ArticleTag:query')")
    @GetMapping(value = "/{tagId}")
    public AjaxResult getInfo(@PathVariable("tagId") Long tagId)
    {
        return AjaxResult.success(articleTagService.selectArticleTagByTagId(tagId));
    }

    /**
     * 新增帖子话题
     */
    @PreAuthorize("@ss.hasPermi('mall:ArticleTag:add')")
    @Log(title = "帖子话题", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ArticleTag articleTag)
    {
        return toAjax(articleTagService.insertArticleTag(articleTag));
    }

    /**
     * 修改帖子话题
     */
    @PreAuthorize("@ss.hasPermi('mall:ArticleTag:edit')")
    @Log(title = "帖子话题", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ArticleTag articleTag)
    {
        return toAjax(articleTagService.updateArticleTag(articleTag));
    }

    /**
     * 删除帖子话题
     */
    @PreAuthorize("@ss.hasPermi('mall:ArticleTag:remove')")
    @Log(title = "帖子话题", businessType = BusinessType.DELETE)
	@DeleteMapping("/{tagIds}")
    public AjaxResult remove(@PathVariable Long[] tagIds)
    {
        return toAjax(articleTagService.deleteArticleTagByTagIds(tagIds));
    }
}
