package com.fs.his.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.hisStore.domain.FsHomeArticleViewScrm;
import com.fs.hisStore.service.IFsHomeArticleViewScrmService;
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("/his/homeView")
public class FsHomeArticleViewController extends BaseController {
    @Autowired
    private IFsHomeArticleViewScrmService fsHomeArticleViewService;

    /**
     * 查询期刊阅读列表
     */
    @PreAuthorize("@ss.hasPermi('store:homeView:list')")
    @GetMapping("/list")
    public R list(FsHomeArticleViewScrm fsHomeArticleView) {
        PageHelper.startPage(fsHomeArticleView.getPageNum(), fsHomeArticleView.getPageSize());
        List<FsHomeArticleViewScrm> list = fsHomeArticleViewService.selectFsHomeArticleViewList(fsHomeArticleView);
        PageInfo<FsHomeArticleViewScrm> listPageInfo = new PageInfo<>(list);
        return R.ok().put("rows", listPageInfo);
    }

    /**
     * 导出期刊阅读列表
     */
    @PreAuthorize("@ss.hasPermi('store:homeView:export')")
    @Log(title = "期刊阅读", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsHomeArticleViewScrm fsHomeArticleView) {
        List<FsHomeArticleViewScrm> list = fsHomeArticleViewService.selectFsHomeArticleViewList(fsHomeArticleView);
        ExcelUtil<FsHomeArticleViewScrm> util = new ExcelUtil<FsHomeArticleViewScrm>(FsHomeArticleViewScrm.class);
        return util.exportExcel(list, "homeView");
    }

    /**
     * 获取期刊阅读详细信息
     */
    @PreAuthorize("@ss.hasPermi('store:homeView:query')")
    @GetMapping(value = "/{viewId}")
    public AjaxResult getInfo(@PathVariable("viewId") Long viewId) {
        return AjaxResult.success(fsHomeArticleViewService.selectFsHomeArticleViewById(viewId));
    }

    /**
     * 新增期刊阅读
     */
    @PreAuthorize("@ss.hasPermi('store:homeView:add')")
    @Log(title = "期刊阅读", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsHomeArticleViewScrm fsHomeArticleView) {
        return toAjax(fsHomeArticleViewService.insertFsHomeArticleView(fsHomeArticleView));
    }

    /**
     * 修改期刊阅读
     */
    @PreAuthorize("@ss.hasPermi('store:homeView:edit')")
    @Log(title = "期刊阅读", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsHomeArticleViewScrm fsHomeArticleView) {
        return toAjax(fsHomeArticleViewService.updateFsHomeArticleView(fsHomeArticleView));
    }

    /**
     * 删除期刊阅读
     */
    @PreAuthorize("@ss.hasPermi('store:homeView:remove')")
    @Log(title = "期刊阅读", businessType = BusinessType.DELETE)
    @DeleteMapping("/{viewIds}")
    public AjaxResult remove(@PathVariable Long[] viewIds) {
        return toAjax(fsHomeArticleViewService.deleteFsHomeArticleViewByIds(viewIds));
    }
}
