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

/**
 * 计算公式数据Controller
 * 
 * @author ruoyi
 * @date 2023-10-25
 */
@RestController
@RequestMapping("/mall/method")
public class MallCountMethodController extends BaseController
{
    @Autowired
    private IMallCountMethodService mallCountMethodService;

    /**
     * 查询计算公式数据列表
     */
    @PreAuthorize("@ss.hasPermi('mall:method:list')")
    @GetMapping("/list")
    public TableDataInfo list(MallCountMethod mallCountMethod)
    {
        startPage();
        List<MallCountMethod> list = mallCountMethodService.selectMallCountMethodList(mallCountMethod);
        return getDataTable(list);
    }

    /**
     * 导出计算公式数据列表
     */
    @PreAuthorize("@ss.hasPermi('mall:method:export')")
    @Log(title = "计算公式数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MallCountMethod mallCountMethod)
    {
        List<MallCountMethod> list = mallCountMethodService.selectMallCountMethodList(mallCountMethod);
        ExcelUtil<MallCountMethod> util = new ExcelUtil<MallCountMethod>(MallCountMethod.class);
        util.exportExcel(response, list, "计算公式数据数据");
    }

    /**
     * 获取计算公式数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:method:query')")
    @GetMapping(value = "/{countMethodId}")
    public AjaxResult getInfo(@PathVariable("countMethodId") Long countMethodId)
    {
        return AjaxResult.success(mallCountMethodService.selectMallCountMethodByCountMethodId(countMethodId));
    }

    /**
     * 新增计算公式数据
     */
    @PreAuthorize("@ss.hasPermi('mall:method:add')")
    @Log(title = "计算公式数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallCountMethod mallCountMethod)
    {
        return toAjax(mallCountMethodService.insertMallCountMethod(mallCountMethod));
    }

    /**
     * 修改计算公式数据
     */
    @PreAuthorize("@ss.hasPermi('mall:method:edit')")
    @Log(title = "计算公式数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallCountMethod mallCountMethod)
    {
        return toAjax(mallCountMethodService.updateMallCountMethod(mallCountMethod));
    }

    /**
     * 删除计算公式数据
     */
    @PreAuthorize("@ss.hasPermi('mall:method:remove')")
    @Log(title = "计算公式数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{countMethodIds}")
    public AjaxResult remove(@PathVariable Long[] countMethodIds)
    {
        return toAjax(mallCountMethodService.deleteMallCountMethodByCountMethodIds(countMethodIds));
    }
}
