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 TownService extends BaseService<Town,Integer> {
    @Autowired
    TownRepository townRepository;

    public Map<Integer, String> getNames(String districtCode){
        List<Town> list = townRepository.findInfoList(districtCode);
        Map<Integer, String> map = new HashMap<>();
        list.stream().forEach(town -> {
            map.put(town.getId(),town.getName());
        });
        return map;
    }

    public String findWktById(Integer id){
        return townRepository.findWktById(id);
    }

    @Override
    public JpaPlusRepository<Town, Integer> r() {
        return townRepository;
    }
}
