package com.fjhx.controller.supplier;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjhx.entity.supplier.GetSupplierPriceByProductIdsDto;
import com.fjhx.params.supplier.SupplierPriceVo;
import com.fjhx.service.supplier.SupplierPriceService;
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.math.BigDecimal;
import java.util.Map;

/**
 * <p>
 * 供应商价格 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2022-11-25
 */
@RestController
@RequestMapping("/supplierPrice")
public class SupplierPriceController {

    @Autowired
    private SupplierPriceService supplierPriceService;

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

    @PostMapping("/add")
    public R add(@RequestBody SupplierPriceVo supplierPriceVo) {
        supplierPriceService.add(supplierPriceVo);
        return R.success();
    }

    @PostMapping("/edit")
    public R edit(@RequestBody SupplierPriceVo supplierPriceVo) {
        supplierPriceService.edit(supplierPriceVo);
        return R.success();
    }

    @PostMapping("/delete")
    public R delete(@RequestBody SupplierPriceVo supplierPriceVo) {
        supplierPriceService.delete(supplierPriceVo);
        return R.success();
    }

    @PostMapping("/list")
    public R list(@RequestBody Map<String, Object> condition) {
        return R.success(supplierPriceService.getList(condition));
    }

    /**
     * 查看产品价格
     */
    @PostMapping("/getSupplierPriceByProductIds")
    public R getSupplierPriceByProductIds(@RequestBody GetSupplierPriceByProductIdsDto dto) {
        Map<Long, BigDecimal> result = supplierPriceService.getSupplierPriceByProductIds(dto);
        return R.success(result);
    }

}

