|
|
|
@ -1,5 +1,6 @@ |
|
|
|
package com.chenhai.system.service.impl; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
@ -28,7 +29,9 @@ public class MapFeaturesServiceImpl implements IMapFeaturesService |
|
|
|
@Override |
|
|
|
public MapFeatures selectMapFeaturesById(Long id) |
|
|
|
{ |
|
|
|
return mapFeaturesMapper.selectMapFeaturesById(id); |
|
|
|
MapFeatures mapFeatures = mapFeaturesMapper.selectMapFeaturesById(id); |
|
|
|
convertCoordinatesToArray(mapFeatures); |
|
|
|
return mapFeatures; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
@ -40,7 +43,12 @@ public class MapFeaturesServiceImpl implements IMapFeaturesService |
|
|
|
@Override |
|
|
|
public List<MapFeatures> selectMapFeaturesList(MapFeatures mapFeatures) |
|
|
|
{ |
|
|
|
return mapFeaturesMapper.selectMapFeaturesList(mapFeatures); |
|
|
|
List<MapFeatures> list = mapFeaturesMapper.selectMapFeaturesList(mapFeatures); |
|
|
|
// 转换每条记录的坐标格式 |
|
|
|
for (MapFeatures item : list) { |
|
|
|
convertCoordinatesToArray(item); |
|
|
|
} |
|
|
|
return list; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
@ -52,6 +60,8 @@ public class MapFeaturesServiceImpl implements IMapFeaturesService |
|
|
|
@Override |
|
|
|
public int insertMapFeatures(MapFeatures mapFeatures) |
|
|
|
{ |
|
|
|
// 如果是数组格式,转换为逗号分隔的字符串存储 |
|
|
|
convertArrayToCoordinates(mapFeatures); |
|
|
|
return mapFeaturesMapper.insertMapFeatures(mapFeatures); |
|
|
|
} |
|
|
|
|
|
|
|
@ -64,6 +74,8 @@ public class MapFeaturesServiceImpl implements IMapFeaturesService |
|
|
|
@Override |
|
|
|
public int updateMapFeatures(MapFeatures mapFeatures) |
|
|
|
{ |
|
|
|
// 如果是数组格式,转换为逗号分隔的字符串存储 |
|
|
|
convertArrayToCoordinates(mapFeatures); |
|
|
|
return mapFeaturesMapper.updateMapFeatures(mapFeatures); |
|
|
|
} |
|
|
|
|
|
|
|
@ -90,4 +102,91 @@ public class MapFeaturesServiceImpl implements IMapFeaturesService |
|
|
|
{ |
|
|
|
return mapFeaturesMapper.deleteMapFeaturesById(id); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 将逗号分隔的坐标字符串转换为数组格式 |
|
|
|
* 输入: "105.70587,38.83020,105.73710,38.83981" |
|
|
|
* 输出: [[105.70587, 38.83020], [105.73710, 38.83981]] |
|
|
|
* |
|
|
|
* @param mapFeatures 地图标注对象 |
|
|
|
*/ |
|
|
|
private void convertCoordinatesToArray(MapFeatures mapFeatures) { |
|
|
|
if (mapFeatures == null || mapFeatures.getCoordinates() == null) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
Object coordinates = mapFeatures.getCoordinates(); |
|
|
|
|
|
|
|
// 如果是字符串格式 |
|
|
|
if (coordinates instanceof String) { |
|
|
|
String coordStr = (String) coordinates; |
|
|
|
if (coordStr == null || coordStr.trim().isEmpty()) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// 按逗号分割(支持中英文逗号) |
|
|
|
String[] parts = coordStr.split("[,,]+"); |
|
|
|
|
|
|
|
// 检查坐标数量是否为偶数(经度、纬度成对出现) |
|
|
|
if (parts.length >= 2 && parts.length % 2 == 0) { |
|
|
|
List<List<Double>> coordArray = new ArrayList<>(); |
|
|
|
for (int i = 0; i < parts.length; i += 2) { |
|
|
|
try { |
|
|
|
double lng = Double.parseDouble(parts[i].trim()); |
|
|
|
double lat = Double.parseDouble(parts[i + 1].trim()); |
|
|
|
List<Double> point = new ArrayList<>(); |
|
|
|
point.add(lng); |
|
|
|
point.add(lat); |
|
|
|
coordArray.add(point); |
|
|
|
} catch (NumberFormatException e) { |
|
|
|
// 解析失败,保持原样 |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
mapFeatures.setCoordinates(coordArray); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 将数组格式的坐标转换为逗号分隔的字符串 |
|
|
|
* 输入: [[105.70587, 38.83020], [105.73710, 38.83981]] |
|
|
|
* 输出: "105.70587,38.83020,105.73710,38.83981" |
|
|
|
* |
|
|
|
* @param mapFeatures 地图标注对象 |
|
|
|
*/ |
|
|
|
private void convertArrayToCoordinates(MapFeatures mapFeatures) { |
|
|
|
if (mapFeatures == null || mapFeatures.getCoordinates() == null) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
Object coordinates = mapFeatures.getCoordinates(); |
|
|
|
|
|
|
|
// 如果是 List 格式(数组) |
|
|
|
if (coordinates instanceof List) { |
|
|
|
List<?> coordList = (List<?>) coordinates; |
|
|
|
if (coordList.isEmpty()) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder(); |
|
|
|
for (Object item : coordList) { |
|
|
|
if (item instanceof List) { |
|
|
|
List<?> point = (List<?>) item; |
|
|
|
if (point.size() >= 2) { |
|
|
|
Object lng = point.get(0); |
|
|
|
Object lat = point.get(1); |
|
|
|
if (sb.length() > 0) { |
|
|
|
sb.append(","); |
|
|
|
} |
|
|
|
sb.append(lng).append(",").append(lat); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (sb.length() > 0) { |
|
|
|
mapFeatures.setCoordinates(sb.toString()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |