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.AppSceneCostInvoice;
import com.zzsmart.qomo.kn.cost.manage.entity.AppSceneCostSapEine;
import com.zzsmart.qomo.kn.cost.manage.mapper.AppSceneCostInvoiceMapper;
import com.zzsmart.qomo.kn.cost.manage.mapper.AppSceneCostSapEineMapper;
import com.zzsmart.qomo.kn.cost.manage.service.IAppSceneCostInvoiceService;
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_invoice
 * @Author: jeecg-boot
 * @Date:   2024-09-22
 * @Version: V1.0
 */
@Service
public class AppSceneCostInvoiceServiceImpl extends ServiceImpl<AppSceneCostInvoiceMapper, AppSceneCostInvoice> implements IAppSceneCostInvoiceService {
    @Autowired
    AppSceneCostInvoiceMapper appSceneCostInvoiceMapper;

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