package com.zzsmart.qomo.kn.cost.manage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zzsmart.qomo.kn.cost.manage.entity.AppSceneCostPurchasePrice;
import com.zzsmart.qomo.kn.cost.manage.mapper.AppSceneCostPurchasePriceMapper;
import com.zzsmart.qomo.kn.cost.manage.service.IAppSceneCostPurchasePriceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: app_scene_cost_purchase_price
 * @Author: jeecg-boot
 * @Date:   2024-08-02
 * @Version: V1.0
 */
@Service
public class AppSceneCostPurchasePriceServiceImpl extends ServiceImpl<AppSceneCostPurchasePriceMapper, AppSceneCostPurchasePrice> implements IAppSceneCostPurchasePriceService {
    @Autowired
    AppSceneCostPurchasePriceMapper costPurchasePriceMapper;

    /**
     * 查询满足物料编号的最低采购价
     *
     * @param materialNos
     */
    @Override
    public Map<String, BigDecimal> getMinCostPurchasePriceByMaterialNo(List<String> materialNos) {
        Map<String, BigDecimal> map = new HashMap<>();
        QueryWrapper<AppSceneCostPurchasePrice> queryWrapper = new QueryWrapper();
        if (materialNos != null && materialNos.size() > 0) {
            queryWrapper.in("material_code", materialNos);
            List<AppSceneCostPurchasePrice> costPurchasePrices = costPurchasePriceMapper.selectList(queryWrapper);
            for (int i = 0; i < costPurchasePrices.size(); i++) {
                AppSceneCostPurchasePrice costPurchasePrice = costPurchasePrices.get(i);
                map.put(costPurchasePrice.getMaterialCode(), costPurchasePrice.getMinPurchasePrice());
            }
        }
        return map;
    }
}
