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

import com.xingxi.business.ProdInventory.domain.ProdInventoryOrder;
import com.xingxi.business.ProdInventory.service.IProdInventoryOrderService;
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.ProdInventoryOrderVo;
import com.xingxi.web.controller.business.ProdInventory.service.IProdInventoryOrderVoService;
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 ProdInventoryOrderController extends BaseController {
    private String prefix = "business/prodInventory";

    @Resource
    private IProdInventoryOrderService prodInventoryOrderService;
    @Resource
    private IProdInventoryOrderVoService prodInventoryOrderVoService;

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

    /**
     * 查询商品出入库单列表
     */
    @RequiresPermissions("business:prodInventory:list")
    @PostMapping("/inventoryOrder/list")
    @ResponseBody
    public TableDataInfo inventoryOrderList(ProdInventoryOrderVo prodInventoryOrderVo) {
        startPage();
        List<ProdInventoryOrderVo> list = prodInventoryOrderVoService.selectProdInventoryOrderVoList(prodInventoryOrderVo);
        return getDataTable(list);
    }

    /**
     * 新增商品出入库单
     */
    @GetMapping("/inventoryOrder/add")
    public String add() {
        return prefix + "/prodInventoryOrderAdd";
    }

    /**
     * 新增保存商品出入库单
     */
    @RequiresPermissions("business:prodInventory:add")
    @Log(title = "商品入出库单", businessType = BusinessType.INSERT)
    @PostMapping("/inventoryOrder/add")
    @ResponseBody
    public AjaxResult addSave(ProdInventoryOrder prodInventoryOrder) {
        return toAjax(prodInventoryOrderService.insertProdInventoryOrder(prodInventoryOrder));
    }

    /**
     * 修改商户
     */
    @RequiresPermissions("business:prodInventory:edit")
    @GetMapping("/inventoryOrder/edit/{inventoryOrderId}")
    public String edit(@PathVariable("inventoryOrderId") Long inventoryOrderId, ModelMap mMap) {
        ProdInventoryOrderVo prodInventoryOrderVo = prodInventoryOrderVoService.selectProdInventoryOrderVoById(inventoryOrderId);
        mMap.put("prodInventoryOrder", prodInventoryOrderVo);
        return prefix + "/prodInventoryOrderEdit";
    }

    /**
     * 修改保存商户
     */
    @RequiresPermissions("business:prodInventory:edit")
    @Log(title = "商品入出库单", businessType = BusinessType.UPDATE)
    @PostMapping("/inventoryOrder/edit")
    @ResponseBody
    public AjaxResult editSave(@RequestBody ProdInventoryOrderVo prodInventoryOrderVo) {
        return toAjax(prodInventoryOrderVoService.updateProdInventoryOrderVo(prodInventoryOrderVo));
    }
}
