package com.ruoyi.jarvis.service.impl;

import com.ruoyi.jarvis.domain.GoodsInfo;
import com.ruoyi.jarvis.mapper.GoodsInfoMapper;
import com.ruoyi.jarvis.service.IGoodsInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

@Service
public class GoodsInfoServiceImpl implements IGoodsInfoService {

    @Autowired
    private GoodsInfoMapper goodsInfoMapper;

    @Override
    public GoodsInfo selectGoodsInfoById(Long id) {
        if (id == null) {
            return null;
        }
        return goodsInfoMapper.selectGoodsInfoById(id);
    }

    @Override
    public Map<Long, GoodsInfo> selectGoodsInfoMapByIds(Set<Long> ids) {
        if (ids == null || ids.isEmpty()) {
            return Collections.emptyMap();
        }
        List<GoodsInfo> list = goodsInfoMapper.selectGoodsInfoByIds(ids.toArray(new Long[0]));
        Map<Long, GoodsInfo> map = new HashMap<>();
        if (list != null) {
            for (GoodsInfo goodsInfo : list) {
                if (goodsInfo != null && goodsInfo.getId() != null) {
                    map.put(goodsInfo.getId(), goodsInfo);
                }
            }
        }
        return map;
    }
}
