package com.ruoyi.mall.controller;

import java.util.List;
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.MallGoodsTag;
import com.ruoyi.mall.service.IMallGoodsTagService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品标签Controller
 *
 * @author ruoyi
 * @date 2022-06-28
 */
@RestController
@RequestMapping("/mall/mallGoodsTag")
public class MallGoodsTagController extends BaseController
{
    @Autowired
    private IMallGoodsTagService mallGoodsTagService;

    /**
     * 查询商品标签列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallGoodsTag:list')")
    @GetMapping("/list")
    public TableDataInfo list(MallGoodsTag mallGoodsTag)
    {
        startPage();
        List<MallGoodsTag> list = mallGoodsTagService.selectMallGoodsTagList(mallGoodsTag);
        return getDataTable(list);
    }

    /**
     * 查询商品标签下拉框列表
     */
    // @PreAuthorize("@ss.hasPermi('mall:mallGoodsTag:list')")
    @GetMapping("/selectList")
    public AjaxResult selectList()
    {
        MallGoodsTag mallGoodsTag = new MallGoodsTag();
        mallGoodsTag.setTagStatus(0);
        List<MallGoodsTag> list = mallGoodsTagService.selectMallGoodsTagList(mallGoodsTag);
        return AjaxResult.success(list);
    }

    /**
     * 导出商品标签列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallGoodsTag:export')")
    @Log(title = "商品标签", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MallGoodsTag mallGoodsTag)
    {
        List<MallGoodsTag> list = mallGoodsTagService.selectMallGoodsTagList(mallGoodsTag);
        ExcelUtil<MallGoodsTag> util = new ExcelUtil<MallGoodsTag>(MallGoodsTag.class);
        return util.exportExcel(list, "商品标签数据");
    }

    /**
     * 获取商品标签详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:mallGoodsTag:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(mallGoodsTagService.selectMallGoodsTagById(id));
    }

    /**
     * 新增商品标签
     */
    @PreAuthorize("@ss.hasPermi('mall:mallGoodsTag:add')")
    @Log(title = "商品标签", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallGoodsTag mallGoodsTag)
    {
        return toAjax(mallGoodsTagService.insertMallGoodsTag(mallGoodsTag));
    }

    /**
     * 修改商品标签
     */
    @PreAuthorize("@ss.hasPermi('mall:mallGoodsTag:edit')")
    @Log(title = "商品标签", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallGoodsTag mallGoodsTag)
    {
        return toAjax(mallGoodsTagService.updateMallGoodsTag(mallGoodsTag));
    }

    /**
     * 删除商品标签
     */
    @PreAuthorize("@ss.hasPermi('mall:mallGoodsTag:remove')")
    @Log(title = "商品标签", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(mallGoodsTagService.deleteMallGoodsTagByIds(ids));
    }
}
