package com.cyl.manager.marketing.controller;

import java.util.List;

import com.cyl.manager.marketing.domain.WechatStock;
import com.cyl.manager.marketing.service.IWechatStockService;
import com.ruoyi.common.utils.poi.ExcelUtil;
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.common.core.page.TableDataInfo;

/**
 * 微信商家券Controller
 * 
 * @author daixiande
 * @date 2024-04-26
 */
@RestController
@RequestMapping("/mall/wechatStock")
public class WechatStockController extends BaseController {
    @Autowired
    private IWechatStockService wechatStockService;

    /**
     * 查询微信商家券列表
     */
    @PreAuthorize("@ss.hasPermi('mall:wechatStock:list')")
    @GetMapping("/list")
    public TableDataInfo list(WechatStock wechatStock) {
        startPage();
        List<WechatStock> list = wechatStockService.selectWechatStockList(wechatStock);
        return getDataTable(list);
    }

    /**
     * 导出微信商家券列表
     */
    @PreAuthorize("@ss.hasPermi('mall:wechatStock:export')")
    @Log(title = "微信商家券", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WechatStock wechatStock) {
        List<WechatStock> list = wechatStockService.selectWechatStockList(wechatStock);
        ExcelUtil<WechatStock> util = new ExcelUtil<WechatStock>(WechatStock.class);
        return util.exportExcel(list, "微信商家券数据");
    }

    /**
     * 获取微信商家券详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:wechatStock:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(wechatStockService.selectWechatStockById(id));
    }

    /**
     * 新增微信商家券
     */
    @PreAuthorize("@ss.hasPermi('mall:wechatStock:add')")
    @Log(title = "微信商家券", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WechatStock wechatStock) {
        return toAjax(wechatStockService.insertWechatStock(wechatStock));
    }

    /**
     * 修改微信商家券
     */
    @PreAuthorize("@ss.hasPermi('mall:wechatStock:edit')")
    @Log(title = "微信商家券", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WechatStock wechatStock) {
        return toAjax(wechatStockService.updateWechatStock(wechatStock));
    }

    /**
     * 删除微信商家券
     */
    @PreAuthorize("@ss.hasPermi('mall:wechatStock:remove')")
    @Log(title = "微信商家券", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(wechatStockService.deleteWechatStockByIds(ids));
    }
}
