Browse Source

Merge remote-tracking branch 'origin/main'

main
ZhaoYang 22 hours ago
parent
commit
2db708cdd3
  1. 29
      chenhai-system/src/main/java/com/chenhai/system/domain/MapFeatures.java
  2. 103
      chenhai-system/src/main/java/com/chenhai/system/service/impl/MapFeaturesServiceImpl.java
  3. 29
      chenhai-system/src/main/resources/mapper/system/MapFeaturesMapper.xml

29
chenhai-system/src/main/java/com/chenhai/system/domain/MapFeatures.java

@ -1,7 +1,7 @@
package com.chenhai.system.domain; package com.chenhai.system.domain;
import java.math.BigDecimal;
import java.util.Date; import java.util.Date;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle; import org.apache.commons.lang3.builder.ToStringStyle;
@ -31,11 +31,15 @@ public class MapFeatures extends BaseEntity
/** 经度 */ /** 经度 */
@Excel(name = "经度") @Excel(name = "经度")
private BigDecimal longitude;
private String longitude;
/** 纬度 */ /** 纬度 */
@Excel(name = "纬度") @Excel(name = "纬度")
private BigDecimal latitude;
private String latitude;
/** 经纬度坐标(合并存储,支持数组格式) */
@Excel(name = "经纬度坐标")
private Object coordinates; // 改为 Object 类型支持 String List
/** 创建时间 */ /** 创建时间 */
@JsonFormat(pattern = "yyyy-MM-dd") @JsonFormat(pattern = "yyyy-MM-dd")
@ -72,26 +76,36 @@ public class MapFeatures extends BaseEntity
return type; return type;
} }
public void setLongitude(BigDecimal longitude)
public void setLongitude(String longitude)
{ {
this.longitude = longitude; this.longitude = longitude;
} }
public BigDecimal getLongitude()
public String getLongitude()
{ {
return longitude; return longitude;
} }
public void setLatitude(BigDecimal latitude)
public void setLatitude(String latitude)
{ {
this.latitude = latitude; this.latitude = latitude;
} }
public BigDecimal getLatitude()
public String getLatitude()
{ {
return latitude; return latitude;
} }
public void setCoordinates(Object coordinates)
{
this.coordinates = coordinates;
}
public Object getCoordinates()
{
return coordinates;
}
public void setCreatedAt(Date createdAt) public void setCreatedAt(Date createdAt)
{ {
this.createdAt = createdAt; this.createdAt = createdAt;
@ -110,6 +124,7 @@ public class MapFeatures extends BaseEntity
.append("type", getType()) .append("type", getType())
.append("longitude", getLongitude()) .append("longitude", getLongitude())
.append("latitude", getLatitude()) .append("latitude", getLatitude())
.append("coordinates", getCoordinates())
.append("createdAt", getCreatedAt()) .append("createdAt", getCreatedAt())
.toString(); .toString();
} }

103
chenhai-system/src/main/java/com/chenhai/system/service/impl/MapFeaturesServiceImpl.java

@ -1,5 +1,6 @@
package com.chenhai.system.service.impl; package com.chenhai.system.service.impl;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -28,7 +29,9 @@ public class MapFeaturesServiceImpl implements IMapFeaturesService
@Override @Override
public MapFeatures selectMapFeaturesById(Long id) 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 @Override
public List<MapFeatures> selectMapFeaturesList(MapFeatures mapFeatures) 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 @Override
public int insertMapFeatures(MapFeatures mapFeatures) public int insertMapFeatures(MapFeatures mapFeatures)
{ {
// 如果是数组格式转换为逗号分隔的字符串存储
convertArrayToCoordinates(mapFeatures);
return mapFeaturesMapper.insertMapFeatures(mapFeatures); return mapFeaturesMapper.insertMapFeatures(mapFeatures);
} }
@ -64,6 +74,8 @@ public class MapFeaturesServiceImpl implements IMapFeaturesService
@Override @Override
public int updateMapFeatures(MapFeatures mapFeatures) public int updateMapFeatures(MapFeatures mapFeatures)
{ {
// 如果是数组格式转换为逗号分隔的字符串存储
convertArrayToCoordinates(mapFeatures);
return mapFeaturesMapper.updateMapFeatures(mapFeatures); return mapFeaturesMapper.updateMapFeatures(mapFeatures);
} }
@ -90,4 +102,91 @@ public class MapFeaturesServiceImpl implements IMapFeaturesService
{ {
return mapFeaturesMapper.deleteMapFeaturesById(id); 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());
}
}
}
} }

29
chenhai-system/src/main/resources/mapper/system/MapFeaturesMapper.xml

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper <!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.chenhai.system.mapper.MapFeaturesMapper"> <mapper namespace="com.chenhai.system.mapper.MapFeaturesMapper">
<resultMap type="MapFeatures" id="MapFeaturesResult"> <resultMap type="MapFeatures" id="MapFeaturesResult">
@ -10,11 +10,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="type" column="type" /> <result property="type" column="type" />
<result property="longitude" column="longitude" /> <result property="longitude" column="longitude" />
<result property="latitude" column="latitude" /> <result property="latitude" column="latitude" />
<result property="coordinates" column="coordinates" />
<result property="createdAt" column="created_at" /> <result property="createdAt" column="created_at" />
</resultMap> </resultMap>
<sql id="selectMapFeaturesVo"> <sql id="selectMapFeaturesVo">
select id, name, type, longitude, latitude, created_at from map_features
select id, name, type, longitude, latitude, coordinates, created_at from map_features
</sql> </sql>
<select id="selectMapFeaturesList" parameterType="MapFeatures" resultMap="MapFeaturesResult"> <select id="selectMapFeaturesList" parameterType="MapFeatures" resultMap="MapFeaturesResult">
@ -22,9 +23,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<where> <where>
<if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if> <if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if>
<if test="type != null and type != ''"> and type = #{type}</if> <if test="type != null and type != ''"> and type = #{type}</if>
<if test="longitude != null "> and longitude = #{longitude}</if>
<if test="latitude != null "> and latitude = #{latitude}</if>
<if test="createdAt != null "> and created_at = #{createdAt}</if>
<if test="longitude != null and longitude != ''"> and longitude = #{longitude}</if>
<if test="latitude != null and latitude != ''"> and latitude = #{latitude}</if>
<if test="coordinates != null and coordinates != ''"> and coordinates = #{coordinates}</if>
<if test="createdAt != null"> and created_at = #{createdAt}</if>
</where> </where>
</select> </select>
@ -38,15 +40,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
<if test="name != null and name != ''">name,</if> <if test="name != null and name != ''">name,</if>
<if test="type != null and type != ''">type,</if> <if test="type != null and type != ''">type,</if>
<if test="longitude != null">longitude,</if>
<if test="latitude != null">latitude,</if>
<if test="longitude != null and longitude != ''">longitude,</if>
<if test="latitude != null and latitude != ''">latitude,</if>
<if test="coordinates != null and coordinates != ''">coordinates,</if>
<if test="createdAt != null">created_at,</if> <if test="createdAt != null">created_at,</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="name != null and name != ''">#{name},</if> <if test="name != null and name != ''">#{name},</if>
<if test="type != null and type != ''">#{type},</if> <if test="type != null and type != ''">#{type},</if>
<if test="longitude != null">#{longitude},</if>
<if test="latitude != null">#{latitude},</if>
<if test="longitude != null and longitude != ''">#{longitude},</if>
<if test="latitude != null and latitude != ''">#{latitude},</if>
<if test="coordinates != null and coordinates != ''">#{coordinates},</if>
<if test="createdAt != null">#{createdAt},</if> <if test="createdAt != null">#{createdAt},</if>
</trim> </trim>
</insert> </insert>
@ -56,8 +60,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<trim prefix="SET" suffixOverrides=","> <trim prefix="SET" suffixOverrides=",">
<if test="name != null and name != ''">name = #{name},</if> <if test="name != null and name != ''">name = #{name},</if>
<if test="type != null and type != ''">type = #{type},</if> <if test="type != null and type != ''">type = #{type},</if>
<if test="longitude != null">longitude = #{longitude},</if>
<if test="latitude != null">latitude = #{latitude},</if>
<if test="longitude != null and longitude != ''">longitude = #{longitude},</if>
<if test="latitude != null and latitude != ''">latitude = #{latitude},</if>
<if test="coordinates != null and coordinates != ''">coordinates = #{coordinates},</if>
<if test="createdAt != null">created_at = #{createdAt},</if> <if test="createdAt != null">created_at = #{createdAt},</if>
</trim> </trim>
where id = #{id} where id = #{id}

Loading…
Cancel
Save