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.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.store.domain.FsQuestions;
import com.fs.store.service.IFsQuestionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 问答专区Controller
 *
 * @author fs
 * @date 2023-10-23
 */
@RestController
@RequestMapping("/his/questions")
public class FsQuestionsController extends BaseController
{
    @Autowired
    private IFsQuestionsService fsQuestionsService;

    /**
     * 查询问答专区列表
     */
    @PreAuthorize("@ss.hasPermi('his:questions:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsQuestions fsQuestions)
    {
        startPage();
        List<FsQuestions> list = fsQuestionsService.selectFsQuestionsList(fsQuestions);
        return getDataTable(list);
    }

    @GetMapping("/importTemplate")
    public AjaxResult importTemplate()
    {
        ExcelUtil<FsQuestions> util = new ExcelUtil<>(FsQuestions.class);
        return util.importTemplateExcel("导入模板");
    }


    @Log(title = "导入", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<FsQuestions> util = new ExcelUtil<>(FsQuestions.class);
        List<FsQuestions> list = util.importExcel(file.getInputStream());
        String message = fsQuestionsService.importData(list);
        return AjaxResult.success(message);
    }

    /**
     * 导出问答专区列表
     */
    @PreAuthorize("@ss.hasPermi('his:questions:export')")
    @Log(title = "问答专区", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsQuestions fsQuestions)
    {
        List<FsQuestions> list = fsQuestionsService.selectFsQuestionsList(fsQuestions);
        ExcelUtil<FsQuestions> util = new ExcelUtil<FsQuestions>(FsQuestions.class);
        return util.exportExcel(list, "问答专区数据");
    }

    /**
     * 获取问答专区详细信息
     */
    @PreAuthorize("@ss.hasPermi('his:questions:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(fsQuestionsService.selectFsQuestionsById(id));
    }

    /**
     * 新增问答专区
     */
    @PreAuthorize("@ss.hasPermi('his:questions:add')")
    @Log(title = "问答专区", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsQuestions fsQuestions)
    {
        return toAjax(fsQuestionsService.insertFsQuestions(fsQuestions));
    }

    /**
     * 修改问答专区
     */
    @PreAuthorize("@ss.hasPermi('his:questions:edit')")
    @Log(title = "问答专区", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsQuestions fsQuestions)
    {
        return toAjax(fsQuestionsService.updateFsQuestions(fsQuestions));
    }

    /**
     * 删除问答专区
     */
    @PreAuthorize("@ss.hasPermi('his:questions:remove')")
    @Log(title = "问答专区", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fsQuestionsService.deleteFsQuestionsByIds(ids));
    }
}
