package com.sqx.modules.taskCenter.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sqx.modules.taskCenter.dao.TaskCenterRewardDao;
import com.sqx.modules.taskCenter.entity.TaskCenterReward;
import com.sqx.modules.taskCenter.service.TaskCenterRewardService;
import org.springframework.stereotype.Service;
import org.apache.commons.lang3.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class TaskCenterRewardServiceImpl extends ServiceImpl<TaskCenterRewardDao, TaskCenterReward> implements TaskCenterRewardService {


    @Override
    public Map<Integer, Integer> getRewardMap(Long taskId) {
        List<TaskCenterReward> rewards = baseMapper.getRewardMap(taskId);

        Map<Integer, Integer> map = rewards.stream()
                .collect(Collectors.groupingBy(
                        TaskCenterReward::getType,
                        Collectors.summingInt(TaskCenterReward::getNumber)
                ));
        return map;
    }
}

