package com.fs.store.controller;

import java.util.List;

import com.fs.store.vo.FsArticleVO;
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.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.enums.BusinessType;
import com.fs.store.domain.FsArticle;
import com.fs.store.service.IFsArticleService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 文章Controller
 * 
 * @author fs
 * @date 2022-03-25
 */
@RestController
@RequestMapping("/store/article")
public class FsArticleController extends BaseController
{
    @Autowired
    private IFsArticleService fsArticleService;

    /**
     * 查询文章列表
     */
    @PreAuthorize("@ss.hasPermi('store:article:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsArticle fsArticle)
    {
        startPage();
        List<FsArticleVO> list = fsArticleService.selectFsArticleListVO(fsArticle);
        return getDataTable(list);
    }

    /**
     * 导出文章列表
     */
    @PreAuthorize("@ss.hasPermi('store:article:export')")
    @Log(title = "文章", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsArticle fsArticle)
    {
        List<FsArticle> list = fsArticleService.selectFsArticleList(fsArticle);
        ExcelUtil<FsArticle> util = new ExcelUtil<FsArticle>(FsArticle.class);
        return util.exportExcel(list, "article");
    }

    /**
     * 获取文章详细信息
     */
    @PreAuthorize("@ss.hasPermi('store:article:query')")
    @GetMapping(value = "/{articleId}")
    public AjaxResult getInfo(@PathVariable("articleId") Integer articleId)
    {
        return AjaxResult.success(fsArticleService.selectFsArticleById(articleId));
    }

    /**
     * 新增文章
     */
    @PreAuthorize("@ss.hasPermi('store:article:add')")
    @Log(title = "文章", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsArticle fsArticle)
    {
        return toAjax(fsArticleService.insertFsArticle(fsArticle));
    }

    /**
     * 修改文章
     */
    @PreAuthorize("@ss.hasPermi('store:article:edit')")
    @Log(title = "文章", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsArticle fsArticle)
    {
        return toAjax(fsArticleService.updateFsArticle(fsArticle));
    }

    /**
     * 删除文章
     */
    @PreAuthorize("@ss.hasPermi('store:article:remove')")
    @Log(title = "文章", businessType = BusinessType.DELETE)
	@DeleteMapping("/{articleIds}")
    public AjaxResult remove(@PathVariable Integer[] articleIds)
    {
        return toAjax(fsArticleService.deleteFsArticleByIds(articleIds));
    }
}
