package com.fjhx.supply.controller.supplier;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjhx.common.constant.SourceConstant;
import com.fjhx.supply.entity.supplier.dto.SupplierPriceDto;
import com.fjhx.supply.entity.supplier.dto.SupplierPriceSelectDto;
import com.fjhx.supply.entity.supplier.vo.SupplierPriceAddVo;
import com.fjhx.supply.entity.supplier.vo.SupplierPriceVo;
import com.fjhx.supply.service.supplier.SupplierPriceService;
import com.ruoyi.common.core.domain.BaseSelectDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
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 zlj
 * @since 2023-03-17
 */
//@DS(SourceConstant.SUPPLY)
@RestController
@RequestMapping("/supplierPrice")
public class SupplierPriceController {

    @Autowired
    private SupplierPriceService supplierPriceService;

    /**
     * 供应商价格分页
     */
    @PostMapping("/page")
    public Page<SupplierPriceVo> page(@RequestBody SupplierPriceSelectDto dto) {
        return supplierPriceService.getPage(dto);
    }

    /**
     * 供应商价格新增
     *
     * @return
     */
    @PostMapping("/add")
    public SupplierPriceAddVo add(@Validated @RequestBody SupplierPriceDto supplierPriceDto) {
        return supplierPriceService.add(supplierPriceDto);
    }

    /**
     * 供应商价格编辑
     */
    @PostMapping("/edit")
    public void edit(@RequestBody SupplierPriceDto supplierPriceDto) {
        supplierPriceService.edit(supplierPriceDto);
    }

    /**
     * 供应商价格删除
     */
    @PostMapping("/delete")
    public void delete(@RequestBody BaseSelectDto dto) {
        supplierPriceService.delete(dto.getId());
    }

    /**
     * 根据供应商id和产品列表获取价格
     *
     * @return
     */
    @PostMapping("/getSupplierPriceByProductIds")
    public Map<Long, BigDecimal> getSupplierPriceByProductIds(@RequestBody SupplierPriceDto dto) {
        return supplierPriceService.getSupplierPriceByProductIds(dto);
    }


}
