package com.hzs.bonus.bonus.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.bonus.bonus.service.ICuMemberShareDetailService;
import com.hzs.common.core.utils.ComputeUtil;
import com.hzs.common.domain.member.bonus.CuMemberShareDetail;
import com.hzs.common.domain.member.ext.CuMemberShareDetailExt;
import com.hzs.bonus.bonus.mapper.CuMemberShareDetailMapper;
import org.springframework.stereotype.Service;

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

/**
 * 会员奖金-分红奖金配置明细 服务实现类
 *
 * @author hzs
 * @since 2023-07-03
 */
@Service
public class CuMemberShareDetailServiceImpl extends ServiceImpl<CuMemberShareDetailMapper, CuMemberShareDetail> implements ICuMemberShareDetailService {

    @Override
    public void saveMemberShareBonus(List<CuMemberShareDetailExt> cuMemberShareDetailList) {
        baseMapper.saveMemberShareBonus(cuMemberShareDetailList);
    }

    /*
     * @description: 根据期间查询奖衔设置的分红配置
     * @author: sui q
     * @date: 2023/8/11 15:35
     * @param: null null
     **/
    @Override
    public Map<String, CuMemberShareDetail> queryCuMemberShareBonusByPeriod(Integer period) {
        List<CuMemberShareDetail> cuMemberShareDetailList = baseMapper.queryCuMemberShareBonusByPeriod(period);
        Map<String, CuMemberShareDetail> cuMemberShareDetailMap = new HashMap<>(ComputeUtil.mapInitCapacity(cuMemberShareDetailList.size()));
        if (CollectionUtil.isNotEmpty(cuMemberShareDetailList)) {
            for (CuMemberShareDetail cuMemberShareDetail : cuMemberShareDetailList) {
                String key = cuMemberShareDetail.getPkCountry().toString() + cuMemberShareDetail.getPkAwards();
                cuMemberShareDetailMap.put(key, cuMemberShareDetail);
            }
        }
        return cuMemberShareDetailMap;
    }

}
