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.AppSceneCostSapEine;
import com.zzsmart.qomo.kn.cost.manage.entity.AppSceneCostSapEkpo;
import com.zzsmart.qomo.kn.cost.manage.mapper.AppSceneCostSapEineMapper;
import com.zzsmart.qomo.kn.cost.manage.mapper.AppSceneCostSapEkpoMapper;
import com.zzsmart.qomo.kn.cost.manage.service.IAppSceneCostSapEkpoService;
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_sap_ekpo
 * @Author: jeecg-boot
 * @Date:   2024-09-22
 * @Version: V1.0
 */
@Service
public class AppSceneCostSapEkpoServiceImpl extends ServiceImpl<AppSceneCostSapEkpoMapper, AppSceneCostSapEkpo> implements IAppSceneCostSapEkpoService {

    @Autowired
    AppSceneCostSapEkpoMapper appSceneCostSapEkpoMapper;

    @Override
    public Map<String, BigDecimal> getPrices(List<String> materialNos){
        Map<String, BigDecimal> map = new HashMap<>();
        QueryWrapper<AppSceneCostSapEkpo> queryWrapper = new QueryWrapper();
        if (materialNos != null && materialNos.size() > 0) {
            queryWrapper.in("matnr", materialNos);
            List<AppSceneCostSapEkpo> costPurchasePrices = appSceneCostSapEkpoMapper.selectList(queryWrapper);
            for (int i = 0; i < costPurchasePrices.size(); i++) {
                AppSceneCostSapEkpo costPurchasePrice = costPurchasePrices.get(i);
                if(map.containsKey(costPurchasePrice.getMatnr())){
                    if(costPurchasePrice.getNetpr().doubleValue()<map.get(costPurchasePrice.getMatnr()).doubleValue()){
                        map.put(costPurchasePrice.getMatnr(), costPurchasePrice.getNetpr());
                    }
                }else{
                    map.put(costPurchasePrice.getMatnr(), costPurchasePrice.getNetpr());
                }
            }
        }
        return map;
    }
}
