记得上下班打卡 | git大法好,push需谨慎

Commit 4fa42401 authored by stonepy's avatar stonepy

修正json格式校验

parent 13cae844
...@@ -15,7 +15,6 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -15,7 +15,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Map;
@Service @Service
public class SweetManualExtConfigServiceImpl implements ISweetManualExtConfigService { public class SweetManualExtConfigServiceImpl implements ISweetManualExtConfigService {
...@@ -46,7 +45,6 @@ public class SweetManualExtConfigServiceImpl implements ISweetManualExtConfigSer ...@@ -46,7 +45,6 @@ public class SweetManualExtConfigServiceImpl implements ISweetManualExtConfigSer
if (exist == null) { if (exist == null) {
return ResponseDto.failure("手册不存在"); return ResponseDto.failure("手册不存在");
} }
try {
SweetManual update = SweetManual.getNew(); SweetManual update = SweetManual.getNew();
update.setFoodGuideUrl(nullToEmpty(param.getFoodGuideUrl())); update.setFoodGuideUrl(nullToEmpty(param.getFoodGuideUrl()));
update.setAlbumUrl(nullToEmpty(param.getAlbumUrl())); update.setAlbumUrl(nullToEmpty(param.getAlbumUrl()));
...@@ -59,9 +57,6 @@ public class SweetManualExtConfigServiceImpl implements ISweetManualExtConfigSer ...@@ -59,9 +57,6 @@ public class SweetManualExtConfigServiceImpl implements ISweetManualExtConfigSer
.eq(SweetManual::getManualId, param.getManualId())); .eq(SweetManual::getManualId, param.getManualId()));
redisDataUtils.setManualExtConfigRedisData(param.getManualId(), toDto(exist, param)); redisDataUtils.setManualExtConfigRedisData(param.getManualId(), toDto(exist, param));
return ResponseDto.success(true); return ResponseDto.success(true);
} catch (IllegalArgumentException e) {
return ResponseDto.failure(e.getMessage());
}
} }
@Override @Override
...@@ -87,7 +82,6 @@ public class SweetManualExtConfigServiceImpl implements ISweetManualExtConfigSer ...@@ -87,7 +82,6 @@ public class SweetManualExtConfigServiceImpl implements ISweetManualExtConfigSer
if (exist == null) { if (exist == null) {
return ResponseDto.failure("手册不存在"); return ResponseDto.failure("手册不存在");
} }
try {
String geojson = serializeGeojson(param.getMapGeojson()); String geojson = serializeGeojson(param.getMapGeojson());
SweetManual update = SweetManual.getNew(); SweetManual update = SweetManual.getNew();
update.setMapGeojson(geojson); update.setMapGeojson(geojson);
...@@ -98,9 +92,6 @@ public class SweetManualExtConfigServiceImpl implements ISweetManualExtConfigSer ...@@ -98,9 +92,6 @@ public class SweetManualExtConfigServiceImpl implements ISweetManualExtConfigSer
cacheDto.setMapGeojson(parseGeojson(geojson)); cacheDto.setMapGeojson(parseGeojson(geojson));
redisDataUtils.setManualExtConfigRedisData(param.getManualId(), cacheDto); redisDataUtils.setManualExtConfigRedisData(param.getManualId(), cacheDto);
return ResponseDto.success(true); return ResponseDto.success(true);
} catch (IllegalArgumentException e) {
return ResponseDto.failure(e.getMessage());
}
} }
private SweetManualExtConfigDto toDto(SweetManual manual) { private SweetManualExtConfigDto toDto(SweetManual manual) {
...@@ -138,27 +129,11 @@ public class SweetManualExtConfigServiceImpl implements ISweetManualExtConfigSer ...@@ -138,27 +129,11 @@ public class SweetManualExtConfigServiceImpl implements ISweetManualExtConfigSer
if (geojson == null) { if (geojson == null) {
return null; return null;
} }
String json;
if (geojson instanceof String) { if (geojson instanceof String) {
json = ((String) geojson).trim(); String json = ((String) geojson).trim();
if (json.isEmpty()) { return json.isEmpty() ? null : json;
return null;
}
} else {
json = JsonUtils.toJson(geojson);
}
validateGeojson(json);
return json;
}
private void validateGeojson(String json) {
Map<?, ?> map = JsonUtils.fromJson(json, Map.class);
if (map == null) {
throw new IllegalArgumentException("地图GeoJSON格式不正确");
}
if (!"FeatureCollection".equals(map.get("type"))) {
throw new IllegalArgumentException("地图GeoJSON必须为FeatureCollection格式");
} }
return JsonUtils.toJson(geojson);
} }
private String nullToEmpty(String value) { private String nullToEmpty(String value) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment