package com.hzs.system.base.provider;

import com.hzs.common.core.domain.R;
import com.hzs.common.domain.system.base.BdArea;
import com.hzs.common.domain.system.base.ext.AreaCache;
import com.hzs.system.base.IAreaServiceApi;
import com.hzs.system.base.service.IBdAreaService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

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

/**
 * 行政区划dubbo服务
 */
@DubboService
public class AreaServiceProvider implements IAreaServiceApi {

    @Autowired
    private IBdAreaService iBdAreaService;

    @Override
    public R<Map<Integer, String>> getAreaMap(Integer pkCountry) {
        Map<Integer, String> resultMap = new HashMap<>();
        List<AreaCache> list = iBdAreaService.getAreaList(pkCountry);
        for (AreaCache areaCache : list) {
            resultMap.put(areaCache.getPkId(), areaCache.getName());
        }
        return R.ok(resultMap);
    }

    @Override
    public R<Map<Integer, String>> getAreaMap(List<Integer> pkCountryList) {
        Map<Integer, String> resultMap = new HashMap<>();
        for (Integer pkCountry : pkCountryList) {
            List<AreaCache> list = iBdAreaService.getAreaList(pkCountry);
            for (AreaCache areaCache : list) {
                resultMap.put(areaCache.getPkId(), areaCache.getName());
            }
        }
        return R.ok(resultMap);
    }

    @Override
    public R<BdArea> getArea(Integer pkId) {
        return R.ok(iBdAreaService.getById(pkId));
    }
}
