package com.yanzhu.jh.base.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.yanzhu.jh.base.domain.BasePeriodical;
import com.yanzhu.jh.base.service.IBasePeriodicalService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 期刊Controller
 * 
 * @author ruoyi
 * @date 2023-09-23
 */
@RestController
@RequestMapping("/base/periodical")
public class BasePeriodicalController extends BaseController
{
    @Autowired
    private IBasePeriodicalService basePeriodicalService;

    /**
     * 查询期刊列表
     */
    @PreAuthorize("@ss.hasPermi('base:periodical:list')")
    @GetMapping("/list")
    public TableDataInfo list(BasePeriodical basePeriodical)
    {
        startPage();
        List<BasePeriodical> list = basePeriodicalService.selectBasePeriodicalList(basePeriodical);
        return getDataTable(list);
    }

    /**
     * 导出期刊列表
     */
    @PreAuthorize("@ss.hasPermi('base:periodical:export')")
    @Log(title = "期刊", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BasePeriodical basePeriodical)
    {
        List<BasePeriodical> list = basePeriodicalService.selectBasePeriodicalList(basePeriodical);
        ExcelUtil<BasePeriodical> util = new ExcelUtil<BasePeriodical>(BasePeriodical.class);
        util.exportExcel(response, list, "期刊数据");
    }

    /**
     * 获取期刊详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:periodical:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(basePeriodicalService.selectBasePeriodicalById(id));
    }

    /**
     * 新增期刊
     */
    @PreAuthorize("@ss.hasPermi('base:periodical:add')")
    @Log(title = "期刊", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BasePeriodical basePeriodical)
    {
        return toAjax(basePeriodicalService.insertBasePeriodical(basePeriodical));
    }

    /**
     * 修改期刊
     */
    @PreAuthorize("@ss.hasPermi('base:periodical:edit')")
    @Log(title = "期刊", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BasePeriodical basePeriodical)
    {
        return toAjax(basePeriodicalService.updateBasePeriodical(basePeriodical));
    }

    /**
     * 删除期刊
     */
    @PreAuthorize("@ss.hasPermi('base:periodical:remove')")
    @Log(title = "期刊", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(basePeriodicalService.deleteBasePeriodicalByIds(ids));
    }
}
