package com.fjhx.controller.stock;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjhx.base.Condition;
import com.fjhx.entity.stock.Stock;
import com.fjhx.params.stock.PageByCombinationVo;
import com.fjhx.params.stock.PageByProductVo;
import com.fjhx.params.stock.PageByWarehouseVo;
import com.fjhx.params.stock.StockVo;
import com.fjhx.service.stock.StockService;
import org.springblade.core.tool.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * <p>
 * 库存 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2022-11-24
 */
@RestController
@RequestMapping("/stock")
public class StockController {

    @Autowired
    private StockService stockService;

    @PostMapping("/page")
    public R page(@RequestBody Map<String, Object> condition) {
        Page<Stock> result = stockService.getPage(condition);
        return R.success(result);
    }

    @PostMapping("/add")
    public R add(@RequestBody StockVo stockVo) {
        stockService.add(stockVo);
        return R.success();
    }

    @PostMapping("/edit")
    public R edit(@RequestBody StockVo stockVo) {
        stockService.edit(stockVo);
        return R.success();
    }

    @PostMapping("/delete")
    public R delete(@RequestBody StockVo stockVo) {
        stockService.delete(stockVo);
        return R.success();
    }

    /**
     * 查询仓库库存
     */
    @PostMapping("/pageByWarehouseId")
    public R pageByWarehouseId(@RequestBody Condition condition) {
        Page<Map<String, Object>> result = stockService.pageByWarehouseId(condition);
        return R.success(result);
    }

    /**
     * 根据仓库查询库存
     */
    @PostMapping("/pageByWarehouse")
    public R pageByWarehouse(@RequestBody Condition condition) {
        Page<PageByWarehouseVo> result = stockService.pageByWarehouse(condition);
        return R.success(result);
    }

    /**
     * 根据产品查询库存
     */
    @PostMapping("/pageByProduct")
    public R pageByProduct(@RequestBody Condition condition) {
        Page<PageByProductVo> result = stockService.pageByProduct(condition);
        return R.success(result);
    }

    /**
     * 根据组合查询库存
     */
    @PostMapping("/pageByCombination")
    public R pageByCombination(@RequestBody Condition condition) {
        Page<PageByCombinationVo> result = stockService.pageByCombination(condition);
        return R.success(result);
    }


}

