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.AppSceneCostPurchaseRecord;
import com.zzsmart.qomo.kn.cost.manage.entity.AppSceneCostSapEine;
import com.zzsmart.qomo.kn.cost.manage.mapper.AppSceneCostPurchaseRecordMapper;
import com.zzsmart.qomo.kn.cost.manage.mapper.AppSceneCostSapEineMapper;
import com.zzsmart.qomo.kn.cost.manage.service.IAppSceneCostSapEineService;
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_eine
 * @Author: jeecg-boot
 * @Date:   2024-09-21
 * @Version: V1.0
 */
@Service
public class AppSceneCostSapEineServiceImpl extends ServiceImpl<AppSceneCostSapEineMapper, AppSceneCostSapEine> implements IAppSceneCostSapEineService {

    @Autowired
    AppSceneCostSapEineMapper appSceneCostSapEineMapper;

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