Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/2.7.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
li-xunhuan committed Dec 15, 2023
2 parents fc46171 + 81fc56a commit 79a2e0c
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6 deletions.
16 changes: 16 additions & 0 deletions mica-core/src/main/java/net/dreamlu/mica/core/geo/GeoUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
41 changes: 36 additions & 5 deletions mica-http/src/main/java/net/dreamlu/mica/http/ResponseSpec.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

Expand All @@ -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;
Expand Down Expand Up @@ -216,7 +215,18 @@ default JsonNode atJsonPath(String jsonPtrExpr) {
* @return JsonNode
*/
default <T> T atJsonPathValue(String jsonPtrExpr, Class<T> 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> T atJsonPathValue(String jsonPtrExpr, JavaType valueType) {
return JsonUtil.treeToValue(atJsonPath(jsonPtrExpr), valueType);
}

/**
Expand All @@ -238,8 +248,7 @@ default <T> T atJsonPathValue(String jsonPtrExpr, TypeReference<T> typeReference
* @return List
*/
default <T> List<T> atJsonPathList(String jsonPtrExpr, Class<T> valueType) {
CollectionLikeType collectionLikeType = JsonUtil.getListType(valueType);
return JsonUtil.convertValue(atJsonPath(jsonPtrExpr), collectionLikeType);
return atJsonPathValue(jsonPtrExpr, JsonUtil.getListType(valueType));
}

/**
Expand Down Expand Up @@ -285,6 +294,28 @@ default <T> List<T> atJsonPathList(String jsonPtrExpr, Class<T> valueType) {
*/
<V> Map<String, V> 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.
*
Expand Down

0 comments on commit 79a2e0c

Please sign in to comment.