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.VipGuide;
import com.ruoyi.mall.service.IVipGuideService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会员指南Controller
 *
 * @author ruoyi
 * @date 2023-10-25
 */
@RestController
@RequestMapping("/mall/guide")
public class VipGuideController extends BaseController
{
    @Autowired
    private IVipGuideService vipGuideService;

    /**
     * 查询会员指南列表
     */
    @PreAuthorize("@ss.hasPermi('mall:guide:list')")
    @GetMapping("/list")
    public TableDataInfo list(VipGuide vipGuide)
    {
        startPage();
        List<VipGuide> list = vipGuideService.selectVipGuideList(vipGuide);
        return getDataTable(list);
    }

    /**
     * 导出会员指南列表
     */
    @PreAuthorize("@ss.hasPermi('mall:guide:export')")
    @Log(title = "会员指南", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VipGuide vipGuide)
    {
        List<VipGuide> list = vipGuideService.selectVipGuideList(vipGuide);
        ExcelUtil<VipGuide> util = new ExcelUtil<VipGuide>(VipGuide.class);
        util.exportExcel(response, list, "会员指南数据");
    }

    /**
     * 获取会员指南详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:guide:query')")
    @GetMapping(value = "/{guideId}")
    public AjaxResult getInfo(@PathVariable("guideId") Long guideId)
    {
        return AjaxResult.success(vipGuideService.selectVipGuideByGuideId(guideId));
    }

    /**
     * 新增会员指南
     */
    @PreAuthorize("@ss.hasPermi('mall:guide:add')")
    @Log(title = "会员指南", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VipGuide vipGuide)
    {
        return toAjax(vipGuideService.insertVipGuide(vipGuide));
    }

    /**
     * 修改会员指南
     */
    @PreAuthorize("@ss.hasPermi('mall:guide:edit')")
    @Log(title = "会员指南", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VipGuide vipGuide)
    {
        return toAjax(vipGuideService.updateVipGuide(vipGuide));
    }

    /**
     * 删除会员指南
     */
    @PreAuthorize("@ss.hasPermi('mall:guide:remove')")
    @Log(title = "会员指南", businessType = BusinessType.DELETE)
	@DeleteMapping("/{guideIds}")
    public AjaxResult remove(@PathVariable Long[] guideIds)
    {
        return toAjax(vipGuideService.deleteVipGuideByGuideIds(guideIds));
    }
}
