package com.fs.store.controller;

import java.util.List;

import com.fs.common.core.domain.R;
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.FsArticleCate;
import com.fs.store.service.IFsArticleCateService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 文章分类Controller
 * 
 * @author fs
 * @date 2022-03-25
 */
@RestController
@RequestMapping("/store/articleCate")
public class FsArticleCateController extends BaseController
{
    @Autowired
    private IFsArticleCateService fsArticleCateService;

    /**
     * 查询文章分类列表
     */
    @PreAuthorize("@ss.hasPermi('store:articleCate:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsArticleCate fsArticleCate)
    {
        fsArticleCate.setIsDel(0);
        startPage();
        List<FsArticleCate> list = fsArticleCateService.selectFsArticleCateList(fsArticleCate);
        return getDataTable(list);
    }

    /**
     * 导出文章分类列表
     */
    @PreAuthorize("@ss.hasPermi('store:articleCate:export')")
    @Log(title = "文章分类", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsArticleCate fsArticleCate)
    {

        List<FsArticleCate> list = fsArticleCateService.selectFsArticleCateList(fsArticleCate);
        ExcelUtil<FsArticleCate> util = new ExcelUtil<FsArticleCate>(FsArticleCate.class);
        return util.exportExcel(list, "articleCate");
    }

    /**
     * 获取文章分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('store:articleCate:query')")
    @GetMapping(value = "/{cateId}")
    public AjaxResult getInfo(@PathVariable("cateId") Long cateId)
    {
        return AjaxResult.success(fsArticleCateService.selectFsArticleCateById(cateId));
    }

    /**
     * 新增文章分类
     */
    @PreAuthorize("@ss.hasPermi('store:articleCate:add')")
    @Log(title = "文章分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsArticleCate fsArticleCate)
    {
        fsArticleCate.setIsDel(0);
        return toAjax(fsArticleCateService.insertFsArticleCate(fsArticleCate));
    }

    /**
     * 修改文章分类
     */
    @PreAuthorize("@ss.hasPermi('store:articleCate:edit')")
    @Log(title = "文章分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsArticleCate fsArticleCate)
    {
        return toAjax(fsArticleCateService.updateFsArticleCate(fsArticleCate));
    }

    /**
     * 删除文章分类
     */
    @PreAuthorize("@ss.hasPermi('store:articleCate:remove')")
    @Log(title = "文章分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cateIds}")
    public AjaxResult remove(@PathVariable Long[] cateIds)
    {
        return toAjax(fsArticleCateService.deleteFsArticleCateByIds(cateIds));
    }

    @GetMapping("/getArticleCates")
    public R getArticleCates(FsArticleCate fsArticleCate)
    {
        fsArticleCate.setStatus(1);
        fsArticleCate.setIsDel(0);
        List<FsArticleCate> list = fsArticleCateService.selectFsArticleCateList(fsArticleCate);
        return R.ok().put("data",list);
    }
}
