package cn.com.ctop.kuaishou.modules.dimension.service.impl;

import cn.com.ctop.kuaishou.modules.dimension.entity.KuaiShouDimensionAgeConfig;
import cn.com.ctop.kuaishou.modules.dimension.mapper.KuaiShouDimensionAgeConfigMapper;
import cn.com.ctop.kuaishou.modules.dimension.service.IKuaiShouDimensionAgeConfigService;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

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

/**
 * 素材多维度年龄配置
 *
 * @author jeecg-boot
 * 2021-07-29
 * @version V1.0
 */
@Service
public class KuaiShouDimensionAgeConfigServiceImpl extends ServiceImpl<KuaiShouDimensionAgeConfigMapper, KuaiShouDimensionAgeConfig> implements IKuaiShouDimensionAgeConfigService {

    @Override
    public Map<String, JSONArray> getAgeMap() {
        Map<String, JSONArray> map = new HashMap<>();
        QueryWrapper<KuaiShouDimensionAgeConfig> ageConfigQueryWrapper = new QueryWrapper<>();
        List<KuaiShouDimensionAgeConfig> list = this.list(ageConfigQueryWrapper);
        for (KuaiShouDimensionAgeConfig ageConfig : list) {
            map.put(ageConfig.getAgeGroupId(), JSONArray.parseArray(ageConfig.getAgeGroupValue()));

        }

        return map;
    }

    @Override
    public Map<String, String> getAgeNameMap() {
        Map<String, String> map = new HashMap<>();
        QueryWrapper<KuaiShouDimensionAgeConfig> ageConfigQueryWrapper = new QueryWrapper<>();
        List<KuaiShouDimensionAgeConfig> list = this.list(ageConfigQueryWrapper);
        for (KuaiShouDimensionAgeConfig ageConfig : list) {
            map.put(ageConfig.getAgeGroupId(), ageConfig.getAgeGroupName());
        }

        return map;
    }
}
