package com.xingxi.web.controller.business.ProdInventory.controller;

import com.xingxi.common.annotation.Log;
import com.xingxi.common.core.controller.BaseController;
import com.xingxi.common.core.domain.AjaxResult;
import com.xingxi.common.core.page.TableDataInfo;
import com.xingxi.common.enums.BusinessType;
import com.xingxi.web.controller.business.ProdInventory.domain.ProdInventoryVo;
import com.xingxi.web.controller.business.ProdInventory.service.IProdInventoryVoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 商品库存Controller
 *
 * @author ruoyi
 * @date 2025-03-09
 */
@Controller
@RequestMapping("/business/prodInventory")
public class ProdInventoryController extends BaseController {
    private String prefix = "business/prodInventory";

    @Resource
    private IProdInventoryVoService prodInventoryVoService;

    @RequiresPermissions("business:product:inventory:view")
    @GetMapping("/inventory")
    public String prodInventory() {
        return prefix + "/prodInventory";
    }

    @RequiresPermissions("business:product:inventory:view")
    @GetMapping("/mercInventory/{mercId}")
    public String inventory(@PathVariable("mercId") Long mercId, ModelMap mmap) {
        mmap.put("mercId", mercId);
        return prefix + "/mercProdInventory";
    }

    /**
     * 查询商品库存列表
     */
    @RequiresPermissions("business:prodInventory:list")
    @PostMapping("/mercInventory/list")
    @ResponseBody
    public TableDataInfo mercInventoryList(ProdInventoryVo prodInventoryVo) {
        startPage();
        List<ProdInventoryVo> list = prodInventoryVoService.selectProdInventoryVoList(prodInventoryVo);
        return getDataTable(list);
    }

    /**
     * 新增保存商品库存
     */
    @RequiresPermissions("business:prodInventory:add")
    @Log(title = "商品库存", businessType = BusinessType.INSERT)
    @PostMapping("/mercInventory/add")
    @ResponseBody
    public AjaxResult addSave(ProdInventoryVo prodInventoryVo) {
        return toAjax(prodInventoryVoService.insertProdInventoryVo(prodInventoryVo));
    }
}
