package com.fs.store.controller;

import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.domain.R;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.store.domain.FsHomeArticleCategory;
import com.fs.store.service.IFsHomeArticleCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 期刊分类Controller
 *
 * @author fs
 * @date 2025-05-21
 */
@RestController
@RequestMapping("/store/homeCategory")
public class FsHomeArticleCategoryController extends BaseController {
    @Autowired
    private IFsHomeArticleCategoryService fsHomeArticleCategoryService;

    /**
     * 查询期刊分类列表
     */
    @PreAuthorize("@ss.hasPermi('store:homeCategory:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsHomeArticleCategory fsHomeArticleCategory) {
        startPage();
        List<FsHomeArticleCategory> list = fsHomeArticleCategoryService.selectFsHomeArticleCategoryList(fsHomeArticleCategory);
        return getDataTable(list);
    }

    /**
     * 导出期刊分类列表
     */
    @PreAuthorize("@ss.hasPermi('store:homeCategory:export')")
    @Log(title = "期刊分类", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsHomeArticleCategory fsHomeArticleCategory) {
        List<FsHomeArticleCategory> list = fsHomeArticleCategoryService.selectFsHomeArticleCategoryList(fsHomeArticleCategory);
        ExcelUtil<FsHomeArticleCategory> util = new ExcelUtil<FsHomeArticleCategory>(FsHomeArticleCategory.class);
        return util.exportExcel(list, "homeCategory");
    }

    /**
     * 获取期刊分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('store:homeCategory:query')")
    @GetMapping(value = "/{categoryId}")
    public AjaxResult getInfo(@PathVariable("categoryId") Long categoryId) {
        return AjaxResult.success(fsHomeArticleCategoryService.selectFsHomeArticleCategoryById(categoryId));
    }

    /**
     * 新增期刊分类
     */
    @PreAuthorize("@ss.hasPermi('store:homeCategory:add')")
    @Log(title = "期刊分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsHomeArticleCategory fsHomeArticleCategory) {
        return toAjax(fsHomeArticleCategoryService.insertFsHomeArticleCategory(fsHomeArticleCategory));
    }

    /**
     * 修改期刊分类
     */
    @PreAuthorize("@ss.hasPermi('store:homeCategory:edit')")
    @Log(title = "期刊分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsHomeArticleCategory fsHomeArticleCategory) {
        return toAjax(fsHomeArticleCategoryService.updateFsHomeArticleCategory(fsHomeArticleCategory));
    }

    /**
     * 删除期刊分类
     */
    @PreAuthorize("@ss.hasPermi('store:homeCategory:remove')")
    @Log(title = "期刊分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{categoryIds}")
    public AjaxResult remove(@PathVariable Long[] categoryIds) {
        return toAjax(fsHomeArticleCategoryService.deleteFsHomeArticleCategoryByIds(categoryIds));
    }

    @GetMapping("/allList")
    public R getAllList(FsHomeArticleCategory fsHomeArticleCategory) {
        fsHomeArticleCategory.setStatus(1);
        List<FsHomeArticleCategory> list = fsHomeArticleCategoryService.selectFsHomeArticleCategoryList(fsHomeArticleCategory);
        return R.ok().put("rows", list);
    }

}
