fix:完善 review 拼团、秒杀活动的实现提到的问题

This commit is contained in:
puhui999
2023-07-31 18:34:56 +08:00
parent 446951bd11
commit d156d43d63
43 changed files with 391 additions and 695 deletions

View File

@ -27,6 +27,10 @@ public class CollectionUtils {
return Arrays.stream(collections).anyMatch(CollectionUtil::isEmpty);
}
public static <T> boolean isAny(Collection<T> from, Predicate<T> predicate) {
return from.stream().anyMatch(predicate);
}
public static <T> List<T> filterList(Collection<T> from, Predicate<T> predicate) {
if (CollUtil.isEmpty(from)) {
return new ArrayList<>();

View File

@ -3,6 +3,7 @@ package cn.iocoder.yudao.framework.common.util.date;
import cn.hutool.core.date.LocalDateTimeUtil;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
@ -70,7 +71,7 @@ public class LocalDateTimeUtils {
* @param endTime2 校验所需的结束时间
* @return 是否重叠
*/
// TODO @puhui999LocalDateTimeUtil.isOverlap() 是不是可以满足呀?
@Deprecated
public static boolean checkTimeOverlap(LocalTime startTime1, LocalTime endTime1, LocalTime startTime2, LocalTime endTime2) {
// 判断时间是否重叠
// 开始时间在已配置时段的结束时间之前 且 结束时间在已配置时段的开始时间之后 []
@ -81,4 +82,14 @@ public class LocalDateTimeUtils {
|| startTime1.isBefore(endTime2) && endTime1.isAfter(endTime2);
}
public static boolean isOverlap(LocalTime startTime1, LocalTime endTime1, LocalTime startTime2, LocalTime endTime2) {
// 日期部分使用了当前日期LocalDate.now()
LocalDateTime startDateTime1 = LocalDateTime.of(LocalDate.now(), startTime1);
LocalDateTime endDateTime1 = LocalDateTime.of(LocalDate.now(), endTime1);
LocalDateTime startDateTime2 = LocalDateTime.of(LocalDate.now(), startTime2);
LocalDateTime endDateTime2 = LocalDateTime.of(LocalDate.now(), endTime2);
return LocalDateTimeUtil.isOverlap(startDateTime1, endDateTime1, startDateTime2, endDateTime2);
}
}