mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-23 23:45:08 +08:00
!545 完善 review 拼团、秒杀活动的实现提到的问题
Merge pull request !545 from puhui999/feature/mall_product
This commit is contained in:
@ -2,6 +2,7 @@ package cn.iocoder.yudao.framework.common.util.collection;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import java.util.*;
|
||||
@ -26,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<>();
|
||||
@ -149,6 +154,41 @@ public class CollectionUtils {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据划分为需要新增的、还是删除的、还是更新的。
|
||||
*
|
||||
* @param list1 需要处理的数据的相关编号列表
|
||||
* @param list2 数据库中存在的数据的相关编号列表
|
||||
* @param func 比较出哪些记录是新增,还是修改,还是删除
|
||||
* @return 包含需要新增、修改、删除的数据 Map 对象
|
||||
*/
|
||||
public static <D> Map<String, List<D>> convertCDUMap(Collection<Long> list1, Collection<Long> list2,
|
||||
Function<Map<String, List<Long>>, Map<String, List<D>>> func) {
|
||||
HashMap<String, List<Long>> mapData = MapUtil.newHashMap(3);
|
||||
if (CollUtil.isEmpty(list1)) {
|
||||
return func.apply(mapData);
|
||||
}
|
||||
if (CollUtil.isEmpty(list2)) {
|
||||
return func.apply(mapData);
|
||||
}
|
||||
// 后台存在的前端不存在的
|
||||
List<Long> d = CollectionUtils.filterList(list2, item -> !list1.contains(item));
|
||||
if (CollUtil.isNotEmpty(d)) {
|
||||
mapData.put("delete", d);
|
||||
}
|
||||
// 前端存在的后端不存在的
|
||||
List<Long> c = CollectionUtils.filterList(list1, item -> !list2.contains(item));
|
||||
if (CollUtil.isNotEmpty(c)) {
|
||||
mapData.put("create", c);
|
||||
}
|
||||
// 更新已存在的
|
||||
List<Long> u = CollectionUtils.filterList(list1, list2::contains);
|
||||
if (CollUtil.isNotEmpty(u)) {
|
||||
mapData.put("update", u);
|
||||
}
|
||||
return func.apply(mapData);
|
||||
}
|
||||
|
||||
public static boolean containsAny(Collection<?> source, Collection<?> candidates) {
|
||||
return org.springframework.util.CollectionUtils.containsAny(source, candidates);
|
||||
}
|
||||
|
@ -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 @puhui999:LocalDateTimeUtil.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);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user