package com.sysu.admin.controller.city;

import com.sysu.admin.support.base.BaseService;
import com.xiesx.fastboot.core.jpa.JpaPlusRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class DistrictService extends BaseService<District, Integer> {

    @Autowired
    DistrictRepository districtRepository;

    public Map<Integer, String> getNames(String cityCode){
        List<District> list = districtRepository.findInfoList(cityCode.substring(0,4) + "%");
        Map<Integer, String> map = new HashMap<>();
        list.stream().forEach(town -> {
            map.put(Integer.valueOf(town.getCode()),town.getName());
        });
        return map;
    }

    @Override
    public JpaPlusRepository<District, Integer> r() {
        return districtRepository;
    }
}
