package com.ruoyi.web.controller.brewery;

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

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.brewery.domain.WyActivity;
import com.ruoyi.brewery.service.IWyActivityService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 营销活动Controller
 * 
 * @author kxl
 * @date 2024-12-21
 */
@Api(tags = "营销活动")
@RestController
@RequestMapping("/system/brewery/activity")
public class WyActivityController extends BaseController
{
    @Autowired
    private IWyActivityService wyActivityService;

    /**
     * 查询营销活动列表
     */
    @ApiOperation("查询营销活动列表")
    @PreAuthorize("@ss.hasPermi('brewery:activity:list')")
    @GetMapping("/list")
    public TableDataInfo list(WyActivity wyActivity)
    {
        startPage();
        List<WyActivity> list = wyActivityService.selectWyActivityList(wyActivity);
        return getDataTable(list);
    }

    /**
     * 导出营销活动列表
     */
    @ApiOperation("导出营销活动列表")
    @PreAuthorize("@ss.hasPermi('brewery:activity:export')")
    @Log(title = "营销活动", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WyActivity wyActivity)
    {
        List<WyActivity> list = wyActivityService.selectWyActivityList(wyActivity);
        ExcelUtil<WyActivity> util = new ExcelUtil<WyActivity>(WyActivity.class);
        util.exportExcel(response, list, "营销活动数据");
    }

    /**
     * 获取营销活动详细信息
     */
    @ApiOperation("获取营销活动详细信息")
    @PreAuthorize("@ss.hasPermi('brewery:activity:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(wyActivityService.selectWyActivityById(id));
    }

    /**
     * 新增营销活动
     */
    @ApiOperation("新增营销活动")
    @PreAuthorize("@ss.hasPermi('brewery:activity:add')")
    @Log(title = "营销活动", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WyActivity wyActivity)
    {
        return toAjax(wyActivityService.insertWyActivity(wyActivity));
    }

    /**
     * 修改营销活动
     */
    @ApiOperation("修改营销活动")
    @PreAuthorize("@ss.hasPermi('brewery:activity:edit')")
    @Log(title = "营销活动", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WyActivity wyActivity)
    {
        return toAjax(wyActivityService.updateWyActivity(wyActivity));
    }

    /**
     * 删除营销活动
     */
    @ApiOperation("删除营销活动")
    @PreAuthorize("@ss.hasPermi('brewery:activity:remove')")
    @Log(title = "营销活动", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wyActivityService.deleteWyActivityByIds(ids));
    }
}
