海南版本提交

This commit is contained in:
hzj
2024-03-13 18:24:38 +08:00
parent 1192b87083
commit 6288e6902c
37 changed files with 1918 additions and 473 deletions

View File

@@ -11,8 +11,8 @@ package com.njcn.advance.utils;
import cn.hutool.core.collection.CollectionUtil;
import java.lang.reflect.Field;
import java.time.Instant;
import java.time.LocalTime;
import java.time.*;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;
@@ -102,12 +102,27 @@ public class Utils {
}
return result;
}
// 辅助方法:检查时间是否在指定范围内
public static boolean isTimeInRange(Instant instant, LocalTime startTime, LocalTime endTime) {
LocalTime localTime = instant.atZone(Instant.now().atZone(java.time.ZoneId.systemDefault()).getZone()).toLocalTime();
return !localTime.isBefore(startTime) && !localTime.isAfter(endTime);
}
//辅助方法检查时间是否在指定范围内startTimeendTime
public static boolean isTimeInRange(Instant instant, LocalDate startTime, LocalDate endTime) {
// 将Instant对象转换为LocalDateTime对象
LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
// 检查LocalDateTime对象是否在startTime和endTime之间
boolean isInRange = !localDateTime.toLocalDate().isBefore(startTime) && !localDateTime.toLocalDate().isAfter(endTime.plus(1, ChronoUnit.DAYS));
// 返回结果
return isInRange;
}
public static <T> List<Double> getAttributeValueByPropertyName(List<T> list, String propertyName) {
List<Double> resultList = new ArrayList<>();
for (T item : list) {
@@ -121,15 +136,16 @@ public class Utils {
}
return resultList;
}
public static <T> Double getAttributeValueByPropertyName(T item, String propertyName) {
Double result = null;
try {
Field field = item.getClass().getDeclaredField(propertyName);
field.setAccessible(true);
result=(Double) field.get(item);
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
try {
Field field = item.getClass().getDeclaredField(propertyName);
field.setAccessible(true);
result=(Double) field.get(item);
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
return result;
}
}