influxORM代码调整
This commit is contained in:
35
src/main/java/com/njcn/influx/utils/InstantUtil.java
Normal file
35
src/main/java/com/njcn/influx/utils/InstantUtil.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package com.njcn.influx.utils;
|
||||
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2023年04月26日 10:54
|
||||
*/
|
||||
public class InstantUtil {
|
||||
|
||||
public static Instant stringToInstant(String time) {
|
||||
if (time.length() > 22) {
|
||||
return LocalDateTime.parse(time, DateTimeFormatter.ofPattern(DatePattern.UTC_MS_PATTERN)
|
||||
.withZone(ZoneId.systemDefault())
|
||||
.withLocale(Locale.CHINA))
|
||||
.toInstant(ZoneOffset.UTC);
|
||||
} else {
|
||||
return LocalDateTime.parse(time, DateTimeFormatter.ofPattern(DatePattern.UTC_PATTERN)
|
||||
.withZone(ZoneId.systemDefault())
|
||||
.withLocale(Locale.CHINA))
|
||||
.toInstant(ZoneOffset.UTC);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
47
src/main/java/com/njcn/influx/utils/LambdaUtil.java
Normal file
47
src/main/java/com/njcn/influx/utils/LambdaUtil.java
Normal file
@@ -0,0 +1,47 @@
|
||||
package com.njcn.influx.utils;
|
||||
|
||||
import com.njcn.influx.support.ICFunction;
|
||||
|
||||
import java.lang.invoke.SerializedLambda;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2023年04月25日 14:14
|
||||
*/
|
||||
public class LambdaUtil {
|
||||
|
||||
/***
|
||||
* 将函数接口信息转为属性名
|
||||
* @author hongawen
|
||||
* @return String 属性名
|
||||
* 将getXxxx 转义为 xxxx
|
||||
*/
|
||||
public static <T, R> String columnToString(ICFunction<T, R> columnName) {
|
||||
SerializedLambda serializedLambda = null;
|
||||
try {
|
||||
serializedLambda = doSFunction(columnName);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("函数式接口获取类信息异常");
|
||||
}
|
||||
String methodName = serializedLambda.getImplMethodName();
|
||||
String properties = methodName.substring(3);
|
||||
String firstLetter = String.valueOf(properties.charAt(0)).toLowerCase();
|
||||
properties=properties.substring(1);
|
||||
return firstLetter.concat(properties);
|
||||
}
|
||||
|
||||
/***
|
||||
* 反射获取接口信息
|
||||
*/
|
||||
public static <T, R> SerializedLambda doSFunction(ICFunction<T, R> func) throws Exception {
|
||||
// 直接调用writeReplace
|
||||
Method writeReplace = func.getClass().getDeclaredMethod("writeReplace");
|
||||
writeReplace.setAccessible(true);
|
||||
//反射调用
|
||||
Object sl = writeReplace.invoke(func);
|
||||
SerializedLambda serializedLambda = (SerializedLambda) sl;
|
||||
return serializedLambda;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user