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

import cn.com.ctop.kuaishou.modules.dimension.entity.KuaiShouDimensionRegionConfig;
import cn.com.ctop.kuaishou.modules.dimension.entity.KuaiShouDimensionRegionDetail;
import cn.com.ctop.kuaishou.modules.dimension.mapper.KuaiShouDimensionRegionDetailMapper;
import cn.com.ctop.kuaishou.modules.dimension.service.IKuaiShouDimensionRegionConfigService;
import cn.com.ctop.kuaishou.modules.dimension.service.IKuaiShouDimensionRegionDetailService;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * 地域
 *
 * @author jeecg-boot
 * 2021-07-21
 * @version V1.0
 */
@Service
public class KuaiShouDimensionRegionDetailServiceImpl extends ServiceImpl<KuaiShouDimensionRegionDetailMapper, KuaiShouDimensionRegionDetail> implements IKuaiShouDimensionRegionDetailService {
    @Autowired
    KuaiShouDimensionRegionDetailMapper dimensionRegionDetailMapper;
    @Autowired
    private IKuaiShouDimensionRegionConfigService dimensionRegionConfigService;


    @Override
    public Map<String, JSONArray> getRegionList() {
        Map<String, JSONArray> regionMap = new HashMap<>();

        List<KuaiShouDimensionRegionConfig> configs = dimensionRegionConfigService.getConfigList();
        for (KuaiShouDimensionRegionConfig config : configs) {
            String regionGroupId = config.getRegionGroupId();
            List<Long> regionList = dimensionRegionDetailMapper.getRegionList(regionGroupId);
            regionMap.put(regionGroupId, JSONArray.parseArray(regionList.toString()));
        }

        return regionMap;
    }

    @Override
    public Map<String, String> getRegionNameList() {
        Map<String, String> nameMap = new HashMap<>();
        List<KuaiShouDimensionRegionConfig> configs = dimensionRegionConfigService.getConfigList();
        for (KuaiShouDimensionRegionConfig config : configs) {
            String regionGroupId = config.getRegionGroupId();
            nameMap.put(regionGroupId, config.getRegionGroupName());
        }
        return nameMap;
    }


}
