package com.ruoyi.frequency.mallgoodstype.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.frequency.mallgoodstype.entity.MallGoodsType;
import com.ruoyi.frequency.mallgoodstype.service.MallGoodsTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品类型Controller
 *
 * @author liwenlong
 * @date 2024-01-25
 */
@RestController
@RequestMapping("/frequency/mallgoodstype")
public class MallGoodsTypeController extends BaseController
{
    @Autowired
    private MallGoodsTypeService mallGoodsTypeService;

    /**
     * 查询商品类型列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:mallgoodstype:list')")
    @PostMapping("/list")
    public TableDataInfo<MallGoodsType> list(@RequestBody MallGoodsType mallGoodsType)
    {
        startPage();
        List<MallGoodsType> list = mallGoodsTypeService.selectMallGoodsTypeList(mallGoodsType);
        return getDataTable(list);
    }

    /**
     * 导出商品类型列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:mallgoodstype:export')")
    @Log(title = "商品类型", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MallGoodsType mallGoodsType)
    {
        List<MallGoodsType> list = mallGoodsTypeService.selectMallGoodsTypeList(mallGoodsType);
        ExcelUtil<MallGoodsType> util = new ExcelUtil<MallGoodsType>(MallGoodsType.class);
        return util.exportExcel(list, "商品类型数据");
    }

    /**
     * 获取商品类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:mallgoodstype:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult<MallGoodsType> getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(mallGoodsTypeService.selectMallGoodsTypeById(id));
    }

    /**
     * 新增商品类型
     */
    @PreAuthorize("@ss.hasPermi('frequency:mallgoodstype:add')")
    @Log(title = "商品类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallGoodsType mallGoodsType)
    {
        return toAjax(mallGoodsTypeService.insertMallGoodsType(mallGoodsType));
    }

    /**
     * 修改商品类型
     */
    @PreAuthorize("@ss.hasPermi('frequency:mallgoodstype:edit')")
    @Log(title = "商品类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallGoodsType mallGoodsType)
    {
        return toAjax(mallGoodsTypeService.updateMallGoodsType(mallGoodsType));
    }

    /**
     * 删除商品类型
     */
    @PreAuthorize("@ss.hasPermi('frequency:mallgoodstype:remove')")
    @Log(title = "商品类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}/{delFlag}")
    public AjaxResult remove(@PathVariable("ids") Long[] ids,@PathVariable("delFlag") Integer delFlag)
    {
        return toAjax(mallGoodsTypeService.deleteMallGoodsTypeByIds(ids,delFlag));
    }
}
