package com.ruoyi.app.user;

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

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
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.ruoyi.system.domain.SysHelp;
import com.ruoyi.system.service.ISysHelpService;
import com.ruoyi.common.utils.MessageUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * helpController
 * 
 * @author ruoyi
 * @date 2023-06-09
 */
@RestController
@RequestMapping("/system/help")
public class SysHelpController extends BaseController
{
    @Autowired
    private ISysHelpService sysHelpService;

    /**
     * 获取问题详情
     * @param id
     * @return
     */
    @Anonymous
    @GetMapping("/gethelpxq")
    public AjaxResult gethelpxq(@RequestParam Integer id){

        SysHelp help = sysHelpService.getById(id);
        return success(help);
    }

    /**
     * 获取问题列表
     * @return
     */
    @Anonymous
    @GetMapping("/gethelplist")
    public AjaxResult gethelplist(){
        List<SysHelp> list = sysHelpService.list();
        return success(list);
    }
    /**
     * 查询help列表
     */
    @PreAuthorize("@ss.hasPermi('system:help:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysHelp sysHelp)
    {
        startPage();
        List<SysHelp> list = sysHelpService.selectSysHelpList(sysHelp);
        return getDataTable(list);
    }

    /**
     * 导出help列表
     */
    @PreAuthorize("@ss.hasPermi('system:help:export')")
    @Log(title = "help", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysHelp sysHelp)
    {
        List<SysHelp> list = sysHelpService.selectSysHelpList(sysHelp);
        ExcelUtil<SysHelp> util = new ExcelUtil<SysHelp>(SysHelp.class);
        util.exportExcel(response, list, MessageUtils.message("no.export.excel.help"));
    }

    /**
     * 获取help详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:help:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysHelpService.selectSysHelpById(id));
    }

    /**
     * 新增help
     */
    @PreAuthorize("@ss.hasPermi('system:help:add')")
    @Log(title = "help", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysHelp sysHelp)
    {
        return toAjax(sysHelpService.insertSysHelp(sysHelp));
    }

    /**
     * 修改help
     */
    @PreAuthorize("@ss.hasPermi('system:help:edit')")
    @Log(title = "help", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysHelp sysHelp)
    {
        return toAjax(sysHelpService.updateSysHelp(sysHelp));
    }

    /**
     * 删除help
     */
    @PreAuthorize("@ss.hasPermi('system:help:remove')")
    @Log(title = "help", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysHelpService.deleteSysHelpByIds(ids));
    }
}
