package com.ruoyi.web.bst;

import com.ruoyi.bst.articleCategory.domain.ArticleCategory;
import com.ruoyi.bst.articleCategory.domain.ArticleCategoryQuery;
import com.ruoyi.bst.articleCategory.domain.ArticleCategoryVO;
import com.ruoyi.bst.articleCategory.service.ArticleCategoryService;
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.validate.ValidGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.enums.LogBizType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 文章分类Controller
 *
 * @author ruoyi
 * @date 2025-03-27
 */
@RestController
@RequestMapping("/bst/articleCategory")
public class ArticleCategoryController extends BaseController
{
    @Autowired
    private ArticleCategoryService articleCategoryService;

    /**
     * 查询文章分类列表
     */
    @PreAuthorize("@ss.hasPermi('bst:articleCategory:list')")
    @GetMapping("/list")
    public AjaxResult list(ArticleCategoryQuery articleCategoryQuery)
    {
        articleCategoryQuery.setScope(true);
        List<ArticleCategoryVO> list = articleCategoryService.selectArticleCategoryList(articleCategoryQuery);
        return success(list);
    }

    /**
     * 导出文章分类列表
     */
    @PreAuthorize("@ss.hasPermi('bst:articleCategory:export')")
    @Log(title = "文章分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArticleCategoryQuery query)
    {
        List<ArticleCategoryVO> list = articleCategoryService.selectArticleCategoryList(query);
        ExcelUtil<ArticleCategoryVO> util = new ExcelUtil<ArticleCategoryVO>(ArticleCategoryVO.class);
        util.exportExcel(response, list, "文章分类数据");
    }

    /**
     * 获取文章分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('bst:articleCategory:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(articleCategoryService.selectArticleCategoryById(id));
    }

    /**
     * 新增文章分类
     */
    @PreAuthorize("@ss.hasPermi('bst:articleCategory:add')")
    @Log(title = "新增文章分类", businessType = BusinessType.INSERT, bizIdName = "arg0", bizType = LogBizType.ARTICLE_CATEGORY)
    @PostMapping
    public AjaxResult add(@RequestBody @Validated(ValidGroup.Create.class) ArticleCategory articleCategory )
    {
        return toAjax(articleCategoryService.insertArticleCategory(articleCategory));
    }



    /**
     * 修改文章分类
     */
    @PreAuthorize("@ss.hasPermi('bst:articleCategory:edit')")
    @Log(title = "修改文章分类", businessType = BusinessType.UPDATE, bizIdName = "arg0", bizType = LogBizType.ARTICLE_CATEGORY)
    @PutMapping
    public AjaxResult edit(@RequestBody @Validated(ValidGroup.Update.class) ArticleCategory articleCategory)
    {
        return toAjax(articleCategoryService.updateArticleCategory(articleCategory));
    }

    /**
     * 删除文章分类
     */
    @PreAuthorize("@ss.hasPermi('bst:articleCategory:remove')")
    @Log(title = "删除文章分类", businessType = BusinessType.DELETE, bizIdName = "arg0", bizType = LogBizType.ARTICLE_CATEGORY)
	@DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return success(articleCategoryService.deleteArticleCategoryById(id));
    }
}
