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.CostMaterialProcessHours;
import com.zzsmart.qomo.kn.cost.manage.entity.CostPurchasePrice;
import com.zzsmart.qomo.kn.cost.manage.mapper.CostPurchasePriceMapper;
import com.zzsmart.qomo.kn.cost.manage.service.CostPurchasePriceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * <p>
 * 物料采购单价 服务实现类
 * </p>
 *
 * @author
 * @since 2024-06-19
 */
@Service
public class CostPurchasePriceServiceImpl extends ServiceImpl<CostPurchasePriceMapper, CostPurchasePrice> implements CostPurchasePriceService {
    @Autowired
    CostPurchasePriceMapper costPurchasePriceMapper;

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