package com.ruoyi.mall.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.ruoyi.mall.domain.BusinessTutorial;
import com.ruoyi.mall.service.IBusinessTutorialService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 使用教程Controller
 * 
 * @author ruoyi
 * @date 2023-10-23
 */
@RestController
@RequestMapping("/mall/tutorial")
public class BusinessTutorialController extends BaseController
{
    @Autowired
    private IBusinessTutorialService businessTutorialService;

    /**
     * 查询使用教程列表
     */
    @PreAuthorize("@ss.hasPermi('mall:tutorial:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusinessTutorial businessTutorial)
    {
        startPage();
        List<BusinessTutorial> list = businessTutorialService.selectBusinessTutorialList(businessTutorial);
        return getDataTable(list);
    }

    /**
     * 导出使用教程列表
     */
    @PreAuthorize("@ss.hasPermi('mall:tutorial:export')")
    @Log(title = "使用教程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusinessTutorial businessTutorial)
    {
        List<BusinessTutorial> list = businessTutorialService.selectBusinessTutorialList(businessTutorial);
        ExcelUtil<BusinessTutorial> util = new ExcelUtil<BusinessTutorial>(BusinessTutorial.class);
        util.exportExcel(response, list, "使用教程数据");
    }

    /**
     * 获取使用教程详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:tutorial:query')")
    @GetMapping(value = "/{tutorialId}")
    public AjaxResult getInfo(@PathVariable("tutorialId") Long tutorialId)
    {
        return AjaxResult.success(businessTutorialService.selectBusinessTutorialByTutorialId(tutorialId));
    }

    /**
     * 新增使用教程
     */
    @PreAuthorize("@ss.hasPermi('mall:tutorial:add')")
    @Log(title = "使用教程", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusinessTutorial businessTutorial)
    {
        return toAjax(businessTutorialService.insertBusinessTutorial(businessTutorial));
    }

    /**
     * 修改使用教程
     */
    @PreAuthorize("@ss.hasPermi('mall:tutorial:edit')")
    @Log(title = "使用教程", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusinessTutorial businessTutorial)
    {
        return toAjax(businessTutorialService.updateBusinessTutorial(businessTutorial));
    }

    /**
     * 删除使用教程
     */
    @PreAuthorize("@ss.hasPermi('mall:tutorial:remove')")
    @Log(title = "使用教程", businessType = BusinessType.DELETE)
	@DeleteMapping("/{tutorialIds}")
    public AjaxResult remove(@PathVariable Long[] tutorialIds)
    {
        return toAjax(businessTutorialService.deleteBusinessTutorialByTutorialIds(tutorialIds));
    }
}
