package com.yssh.service; import com.yssh.entity.Location; import com.yssh.mapper.LocationMapper; import com.yssh.utils.CalculateUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.ArrayList; import java.util.List; @Service public class LocationService { @Resource private LocationMapper mapper; private static List vocAddrs = null; public List query(String name, String type) { return mapper.query(name, type); } public List getAll() { return mapper.getAll(); } public int insertLocation(Location location) { return mapper.insertLocation(location); } public int deleteLocation(String id) { return mapper.deleteLocation(id); } public List selectVocAddrs(double x, double y) { if (null == vocAddrs) { vocAddrs = mapper.selectVocAddrs(); for (Location loc : vocAddrs) { double X = CalculateUtils.getLon((int) loc.getLon(), (int) loc.getLat()); double Y = CalculateUtils.getLat((int) loc.getLon(), (int) loc.getLat()); loc.setLon(X); loc.setLat(Y); } } List list = new ArrayList<>(); // 1米=0.0000089932 for (Location loc : vocAddrs) { if (Math.abs(loc.getLon() - x) <= 0.0009 && Math.abs(loc.getLat() - y) <= 0.0009) { list.add(loc); } } return list; } }