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.enums.BusinessType;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.store.domain.FsHomeArticle;
import com.fs.store.service.IFsHomeArticleService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
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/homeArticle")
public class FsHomeArticleController extends BaseController {
    @Autowired
    private IFsHomeArticleService fsHomeArticleService;

    /**
     * 查询期刊列表
     */
    @PreAuthorize("@ss.hasPermi('store:homeArticle:list')")
    @GetMapping("/list")
    public R list(FsHomeArticle fsHomeArticle)
    {
        PageHelper.startPage(fsHomeArticle.getPageNum(), fsHomeArticle.getPageSize());
        List<FsHomeArticle> list = fsHomeArticleService.selectFsHomeArticleList(fsHomeArticle);
        PageInfo<FsHomeArticle> listPageInfo = new PageInfo<>(list);
        return R.ok().put("rows", listPageInfo);
    }

    /**
     * 导出期刊列表
     */
    @PreAuthorize("@ss.hasPermi('store:homeArticle:export')")
    @Log(title = "期刊", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsHomeArticle fsHomeArticle) {
        List<FsHomeArticle> list = fsHomeArticleService.selectFsHomeArticleList(fsHomeArticle);
        ExcelUtil<FsHomeArticle> util = new ExcelUtil<FsHomeArticle>(FsHomeArticle.class);
        return util.exportExcel(list, "homArticle");
    }

    /**
     * 获取期刊详细信息
     */
    @PreAuthorize("@ss.hasPermi('store:homeArticle:query')")
    @GetMapping(value = "/{articleId}")
    public AjaxResult getInfo(@PathVariable("articleId") Long articleId) {
        return AjaxResult.success(fsHomeArticleService.selectFsHomeArticleById(articleId));
    }

    /**
     * 新增期刊
     */
    @PreAuthorize("@ss.hasPermi('store:homeArticle:add')")
    @Log(title = "期刊", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsHomeArticle fsHomeArticle) {
        return toAjax(fsHomeArticleService.insertFsHomeArticle(fsHomeArticle));
    }

    /**
     * 修改期刊
     */
    @PreAuthorize("@ss.hasPermi('store:homeArticle:edit')")
    @Log(title = "期刊", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsHomeArticle fsHomeArticle) {
        return toAjax(fsHomeArticleService.updateFsHomeArticle(fsHomeArticle));
    }

    /**
     * 删除期刊
     */
    @PreAuthorize("@ss.hasPermi('store:homeArticle:remove')")
    @Log(title = "期刊", businessType = BusinessType.DELETE)
    @DeleteMapping("/{articleIds}")
    public AjaxResult remove(@PathVariable Long[] articleIds) {
        return toAjax(fsHomeArticleService.deleteFsHomeArticleByIds(articleIds));
    }
}
