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

Commit 4fa42401 authored by stonepy's avatar stonepy

修正json格式校验

parent 13cae844
......@@ -15,7 +15,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.Map;
@Service
public class SweetManualExtConfigServiceImpl implements ISweetManualExtConfigService {
......@@ -46,22 +45,18 @@ public class SweetManualExtConfigServiceImpl implements ISweetManualExtConfigSer
if (exist == null) {
return ResponseDto.failure("手册不存在");
}
try {
SweetManual update = SweetManual.getNew();
update.setFoodGuideUrl(nullToEmpty(param.getFoodGuideUrl()));
update.setAlbumUrl(nullToEmpty(param.getAlbumUrl()));
update.setLostFoundWjxId(nullToEmpty(param.getLostFoundWjxId()));
if (param.getMapGeojson() != null) {
update.setMapGeojson(serializeGeojson(param.getMapGeojson()));
}
update.setUpdatedAt(LocalDateTime.now());
sweetManualMapper.update(update, Wrappers.lambdaUpdate(SweetManual.class)
.eq(SweetManual::getManualId, param.getManualId()));
redisDataUtils.setManualExtConfigRedisData(param.getManualId(), toDto(exist, param));
return ResponseDto.success(true);
} catch (IllegalArgumentException e) {
return ResponseDto.failure(e.getMessage());
SweetManual update = SweetManual.getNew();
update.setFoodGuideUrl(nullToEmpty(param.getFoodGuideUrl()));
update.setAlbumUrl(nullToEmpty(param.getAlbumUrl()));
update.setLostFoundWjxId(nullToEmpty(param.getLostFoundWjxId()));
if (param.getMapGeojson() != null) {
update.setMapGeojson(serializeGeojson(param.getMapGeojson()));
}
update.setUpdatedAt(LocalDateTime.now());
sweetManualMapper.update(update, Wrappers.lambdaUpdate(SweetManual.class)
.eq(SweetManual::getManualId, param.getManualId()));
redisDataUtils.setManualExtConfigRedisData(param.getManualId(), toDto(exist, param));
return ResponseDto.success(true);
}
@Override
......@@ -87,20 +82,16 @@ public class SweetManualExtConfigServiceImpl implements ISweetManualExtConfigSer
if (exist == null) {
return ResponseDto.failure("手册不存在");
}
try {
String geojson = serializeGeojson(param.getMapGeojson());
SweetManual update = SweetManual.getNew();
update.setMapGeojson(geojson);
update.setUpdatedAt(LocalDateTime.now());
sweetManualMapper.update(update, Wrappers.lambdaUpdate(SweetManual.class)
.eq(SweetManual::getManualId, param.getManualId()));
SweetManualExtConfigDto cacheDto = toDto(exist);
cacheDto.setMapGeojson(parseGeojson(geojson));
redisDataUtils.setManualExtConfigRedisData(param.getManualId(), cacheDto);
return ResponseDto.success(true);
} catch (IllegalArgumentException e) {
return ResponseDto.failure(e.getMessage());
}
String geojson = serializeGeojson(param.getMapGeojson());
SweetManual update = SweetManual.getNew();
update.setMapGeojson(geojson);
update.setUpdatedAt(LocalDateTime.now());
sweetManualMapper.update(update, Wrappers.lambdaUpdate(SweetManual.class)
.eq(SweetManual::getManualId, param.getManualId()));
SweetManualExtConfigDto cacheDto = toDto(exist);
cacheDto.setMapGeojson(parseGeojson(geojson));
redisDataUtils.setManualExtConfigRedisData(param.getManualId(), cacheDto);
return ResponseDto.success(true);
}
private SweetManualExtConfigDto toDto(SweetManual manual) {
......@@ -138,27 +129,11 @@ public class SweetManualExtConfigServiceImpl implements ISweetManualExtConfigSer
if (geojson == null) {
return null;
}
String json;
if (geojson instanceof String) {
json = ((String) geojson).trim();
if (json.isEmpty()) {
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格式");
String json = ((String) geojson).trim();
return json.isEmpty() ? null : json;
}
return JsonUtils.toJson(geojson);
}
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