diff --git a/mica-core/src/main/java/net/dreamlu/mica/core/geo/GeoUtil.java b/mica-core/src/main/java/net/dreamlu/mica/core/geo/GeoUtil.java index 86e1ef7d3..2ee505138 100644 --- a/mica-core/src/main/java/net/dreamlu/mica/core/geo/GeoUtil.java +++ b/mica-core/src/main/java/net/dreamlu/mica/core/geo/GeoUtil.java @@ -34,6 +34,22 @@ public static double getDistance(double lng1, double lat1, double lng2, double l * EARTH_RADIUS; } + /** + * 将整数形式的经纬度转换为十进制度格式 + * + * @param coordinate 整数形式的经度或纬度 + * @return 十进制度格式的经纬度 + */ + public static double getGpsValue(int coordinate) { + int degrees = coordinate / (3600 * 100); + int remainder = coordinate % (3600 * 100); + int minutes = remainder / (60 * 100); + remainder = remainder % (60 * 100); + double seconds = remainder / 100.0; + // 将分和秒转换为度的小数部分 + return degrees + (minutes / 60.0) + (seconds / 3600.0); + } + private static double radian(double d) { return d * Math.PI / 180.0; } diff --git a/mica-http/src/main/java/net/dreamlu/mica/http/HttpConsoleLogger.java b/mica-http/src/main/java/net/dreamlu/mica/http/HttpConsoleLogger.java index 877def546..cf1804398 100644 --- a/mica-http/src/main/java/net/dreamlu/mica/http/HttpConsoleLogger.java +++ b/mica-http/src/main/java/net/dreamlu/mica/http/HttpConsoleLogger.java @@ -33,7 +33,7 @@ public enum HttpConsoleLogger implements HttpLoggingInterceptor.Logger { public void log(@Nonnull String message) { // 统一添加前缀,方便在茫茫日志中查看 - System.out.printf("HttpLogger: %s\n", message); + System.out.println("HttpLogger: " + message); } } diff --git a/mica-http/src/main/java/net/dreamlu/mica/http/ResponseSpec.java b/mica-http/src/main/java/net/dreamlu/mica/http/ResponseSpec.java index e284ebafd..0c8b94023 100644 --- a/mica-http/src/main/java/net/dreamlu/mica/http/ResponseSpec.java +++ b/mica-http/src/main/java/net/dreamlu/mica/http/ResponseSpec.java @@ -17,8 +17,8 @@ package net.dreamlu.mica.http; import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.type.CollectionLikeType; import net.dreamlu.mica.core.utils.JsonUtil; import okhttp3.*; @@ -29,7 +29,6 @@ import java.nio.file.Path; import java.util.List; import java.util.Map; -import java.util.function.BiPredicate; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Predicate; @@ -216,7 +215,18 @@ default JsonNode atJsonPath(String jsonPtrExpr) { * @return JsonNode */ default T atJsonPathValue(String jsonPtrExpr, Class valueType) { - return JsonUtil.convertValue(atJsonPath(jsonPtrExpr), valueType); + return JsonUtil.treeToValue(atJsonPath(jsonPtrExpr), valueType); + } + + /** + * jackson json path 语法读取节点 + * + * @param jsonPtrExpr json path 表达式 + * @param valueType value value type + * @return JsonNode + */ + default T atJsonPathValue(String jsonPtrExpr, JavaType valueType) { + return JsonUtil.treeToValue(atJsonPath(jsonPtrExpr), valueType); } /** @@ -238,8 +248,7 @@ default T atJsonPathValue(String jsonPtrExpr, TypeReference typeReference * @return List */ default List atJsonPathList(String jsonPtrExpr, Class valueType) { - CollectionLikeType collectionLikeType = JsonUtil.getListType(valueType); - return JsonUtil.convertValue(atJsonPath(jsonPtrExpr), collectionLikeType); + return atJsonPathValue(jsonPtrExpr, JsonUtil.getListType(valueType)); } /** @@ -285,6 +294,28 @@ default List atJsonPathList(String jsonPtrExpr, Class valueType) { */ Map asMap(Class valueType); + /** + * 转换成文件上传 part + * + * @param name 表单名 + * @return Part + */ + default MultipartBody.Part asPart(String name) { + return asPart(name, null); + } + + /** + * 转换成文件上传 part + * + * @param name 表单名 + * @param fileName 文件名 + * @return Part + */ + default MultipartBody.Part asPart(String name, @Nullable String fileName) { + RequestBody requestBody = RequestBody.create(asBytes(), contentType()); + return MultipartBody.Part.createFormData(name, fileName, requestBody); + } + /** * toFile. *