package com.ruoyi.mall.controller;

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

import com.ruoyi.mall.domain.Vo.BusinessArticleVo;
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.BusinessArticle;
import com.ruoyi.mall.service.IBusinessArticleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 帖子管理Controller
 * 
 * @author ruoyi
 * @date 2023-10-17
 */
@RestController
@RequestMapping("/mall/article")
public class BusinessArticleController extends BaseController
{
    @Resource
    private IBusinessArticleService businessArticleService;

    /**
     * 查询帖子管理列表
     */
    @PreAuthorize("@ss.hasPermi('mall:article:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusinessArticle businessArticle)
    {
        startPage();
        List<BusinessArticleVo> list = businessArticleService.selectBusinessArticleList(businessArticle);
        return getDataTable(list);
    }

    /**
     * 导出帖子管理列表
     */
    @PreAuthorize("@ss.hasPermi('mall:article:export')")
    @Log(title = "帖子管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusinessArticle businessArticle)
    {
        List<BusinessArticleVo> list = businessArticleService.selectBusinessArticleList(businessArticle);
        ExcelUtil<BusinessArticleVo> util = new ExcelUtil<BusinessArticleVo>(BusinessArticleVo.class);
        util.exportExcel(response, list, "帖子管理数据");
    }

    /**
     * 获取帖子管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:article:query')")
    @GetMapping(value = "/{articleId}")
    public AjaxResult getInfo(@PathVariable("articleId") Long articleId)
    {
        return AjaxResult.success(businessArticleService.selectBusinessArticleByArticleId(articleId));
    }

    /**
     * 新增帖子管理
     */
    @PreAuthorize("@ss.hasPermi('mall:article:add')")
    @Log(title = "帖子管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusinessArticle businessArticle)
    {
        return toAjax(businessArticleService.insertBusinessArticle(businessArticle));
    }

    /**
     * 修改帖子管理
     */
    @PreAuthorize("@ss.hasPermi('mall:article:edit')")
    @Log(title = "帖子管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusinessArticle businessArticle)
    {
        return toAjax(businessArticleService.updateBusinessArticle(businessArticle));
    }

    /**
     * 逻辑删除帖子管理
     */
    @PreAuthorize("@ss.hasPermi('mall:article:remove')")
    @Log(title = "帖子管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{articleIds}")
    public AjaxResult remove(@PathVariable Long[] articleIds)
    {
        return toAjax(businessArticleService.deleteBusinessArticleByArticleIds(articleIds));
    }
}
