package com.ruoyi.mall.controller;

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

import com.ruoyi.mall.domain.Vo.BusinessQuestionVo;
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.ruoyi.mall.domain.BusinessQuestion;
import com.ruoyi.mall.service.IBusinessQuestionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 助手问题Controller
 * 
 * @author ruoyi
 * @date 2023-10-24
 */
@RestController
@RequestMapping("/mall/question")
public class BusinessQuestionController extends BaseController
{
    @Autowired
    private IBusinessQuestionService businessQuestionService;

    /**
     * 查询助手问题列表
     */
    @PreAuthorize("@ss.hasPermi('mall:question:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusinessQuestion businessQuestion)
    {
        startPage();
        List<BusinessQuestionVo> list = businessQuestionService.selectBusinessQuestionList(businessQuestion);
        return getDataTable(list);
    }

    /**
     * 导出助手问题列表
     */
    @PreAuthorize("@ss.hasPermi('mall:question:export')")
    @Log(title = "助手问题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusinessQuestion businessQuestion)
    {
        List<BusinessQuestionVo> list = businessQuestionService.selectBusinessQuestionList(businessQuestion);
        ExcelUtil<BusinessQuestionVo> util = new ExcelUtil<BusinessQuestionVo>(BusinessQuestionVo.class);
        util.exportExcel(response, list, "助手问题数据");
    }

    /**
     * 获取助手问题详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:question:query')")
    @GetMapping(value = "/{questionId}")
    public AjaxResult getInfo(@PathVariable("questionId") Long questionId)
    {
        return AjaxResult.success(businessQuestionService.selectBusinessQuestionByQuestionId(questionId));
    }

    /**
     * 新增助手问题
     */
    @PreAuthorize("@ss.hasPermi('mall:question:add')")
    @Log(title = "助手问题", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusinessQuestion businessQuestion)
    {
        return toAjax(businessQuestionService.insertBusinessQuestion(businessQuestion));
    }

    /**
     * 修改助手问题
     */
    @PreAuthorize("@ss.hasPermi('mall:question:edit')")
    @Log(title = "助手问题", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusinessQuestion businessQuestion)
    {
        return toAjax(businessQuestionService.updateBusinessQuestion(businessQuestion));
    }

    /**
     * 删除助手问题
     */
    @PreAuthorize("@ss.hasPermi('mall:question:remove')")
    @Log(title = "助手问题", businessType = BusinessType.DELETE)
	@DeleteMapping("/{questionIds}")
    public AjaxResult remove(@PathVariable Long[] questionIds)
    {
        return toAjax(businessQuestionService.deleteBusinessQuestionByQuestionIds(questionIds));
    }
}
