package com.hzs.activity.wares.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.activity.wares.mapper.AcGiftConfigMapper;
import com.hzs.activity.wares.service.IAcGiftConfigService;
import com.hzs.common.domain.activity.base.AcGiftConfig;
import com.hzs.common.domain.activity.base.ext.AcGiftConfigExt;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 活动赠品配置 服务实现类
 *
 * @author hzs
 * @since 2023-04-20
 */
@Service
public class AcGiftConfigServiceImpl extends ServiceImpl<AcGiftConfigMapper, AcGiftConfig> implements IAcGiftConfigService {

    @Override
    public Map<Long, List<AcGiftConfigExt>> queryListByRuleIdList(List<Long> ruleIdList, Integer pkCountry) {
        // 返回数据map
        Map<Long, List<AcGiftConfigExt>> resultMap = new HashMap<>();

        List<AcGiftConfigExt> acGiftConfigExtList = baseMapper.queryListByRuleIdList(ruleIdList, pkCountry);
        if (CollectionUtil.isNotEmpty(acGiftConfigExtList)) {
            resultMap = acGiftConfigExtList.stream().collect(Collectors.groupingBy(AcGiftConfigExt::getPkRuleId));
        }

        return resultMap;
    }

    @Override
    public List<AcGiftConfigExt> queryListByRuleIdList(Long ruleId, Integer pkCountry) {
        return baseMapper.queryListByRuleIdList(Collections.singletonList(ruleId), pkCountry);
    }

}
