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

import javax.annotation.Resource;

/**
 * app商品单位Controller
 *
 * @author ruoyi
 * @date 2024-07-02
 */
@RestController
@RequestMapping("/mall/mallAppGoodsUnit")
public class MallAppGoodsUnitController extends BaseController
{
    @Resource
    private IMallAppGoodsUnitService mallAppGoodsUnitService;

    /**
     * 查询app商品单位列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallAppGoodsUnit:list')")
    @GetMapping("/list")
    public TableDataInfo list(MallAppGoodsUnit mallAppGoodsUnit)
    {
        startPage();
        mallAppGoodsUnit.setDelFlag("0");
        List<MallAppGoodsUnit> list = mallAppGoodsUnitService.selectMallAppGoodsUnitList(mallAppGoodsUnit);
        return getDataTable(list);
    }

    /**
     * 导出app商品单位列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallAppGoodsUnit:export')")
    @Log(title = "app商品单位", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MallAppGoodsUnit mallAppGoodsUnit)
    {
        List<MallAppGoodsUnit> list = mallAppGoodsUnitService.selectMallAppGoodsUnitList(mallAppGoodsUnit);
        ExcelUtil<MallAppGoodsUnit> util = new ExcelUtil<MallAppGoodsUnit>(MallAppGoodsUnit.class);
        return util.exportExcel(list, "app商品单位数据");
    }

    /**
     * 获取app商品单位详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:mallAppGoodsUnit:query')")
    @GetMapping(value = "/{goodsUnitId}")
    public AjaxResult getInfo(@PathVariable("goodsUnitId") Long goodsUnitId)
    {
        return AjaxResult.success(mallAppGoodsUnitService.selectMallAppGoodsUnitByGoodsUnitId(goodsUnitId));
    }

    /**
     * 新增app商品单位
     */
    @PreAuthorize("@ss.hasPermi('mall:mallAppGoodsUnit:add')")
    @Log(title = "app商品单位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallAppGoodsUnit mallAppGoodsUnit)
    {
        return toAjax(mallAppGoodsUnitService.insertMallAppGoodsUnit(mallAppGoodsUnit));
    }

    /**
     * 修改app商品单位
     */
    @PreAuthorize("@ss.hasPermi('mall:mallAppGoodsUnit:edit')")
    @Log(title = "app商品单位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallAppGoodsUnit mallAppGoodsUnit)
    {
        return toAjax(mallAppGoodsUnitService.updateMallAppGoodsUnit(mallAppGoodsUnit));
    }

    /**
     * 删除app商品单位
     */
    @PreAuthorize("@ss.hasPermi('mall:mallAppGoodsUnit:remove')")
    @Log(title = "app商品单位", businessType = BusinessType.DELETE)
	@DeleteMapping("/{goodsUnitIds}")
    public AjaxResult remove(@PathVariable Long[] goodsUnitIds)
    {
        return toAjax(mallAppGoodsUnitService.deleteMallAppGoodsUnitByGoodsUnitIds(goodsUnitIds));
    }
}
