package com.ruoyi.web.bst;

import com.ruoyi.bst.help.domain.Help;
import com.ruoyi.bst.help.domain.HelpQuery;
import com.ruoyi.bst.help.domain.HelpVO;
import com.ruoyi.bst.help.service.HelpService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.ValidGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 教程列表Controller
 *
 * @author ruoyi
 * @date 2025-04-29
 */
@RestController
@RequestMapping("/bst/help")
public class HelpController extends BaseController
{
    @Autowired
    private HelpService helpService;

    /**
     * 查询教程列表列表
     */
    @PreAuthorize("@ss.hasPermi('bst:help:list')")
    @GetMapping("/list")
    public TableDataInfo list(HelpQuery query)
    {
        startPage();
        startOrderBy();
        List<HelpVO> list = helpService.selectHelpList(query);
        return getDataTable(list);
    }

    /**
     * 导出教程列表列表
     */
    @PreAuthorize("@ss.hasPermi('bst:help:export')")
    @Log(title = "教程列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HelpQuery query)
    {
        List<HelpVO> list = helpService.selectHelpList(query);
        ExcelUtil<HelpVO> util = new ExcelUtil<HelpVO>(HelpVO.class);
        util.exportExcel(response, list, "教程列表数据");
    }

    /**
     * 获取教程列表详细信息
     */
    @PreAuthorize("@ss.hasPermi('bst:help:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(helpService.selectHelpById(id));
    }

    /**
     * 新增教程列表
     */
    @PreAuthorize("@ss.hasPermi('bst:help:add')")
    @Log(title = "教程列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody  @Validated(ValidGroup.Create.class) Help help)
    {
        return toAjax(helpService.insertHelp(help));
    }

    /**
     * 修改教程列表
     */
    @PreAuthorize("@ss.hasPermi('bst:help:edit')")
    @Log(title = "教程列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody@Validated(ValidGroup.Update.class)  Help help)
    {
        return toAjax(helpService.updateHelp(help));
    }

    /**
     * 删除教程列表
     */
    @PreAuthorize("@ss.hasPermi('bst:help:remove')")
    @Log(title = "教程列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(helpService.deleteHelpByIds(ids));
    }
}
