From 7b9f4be98cf585d0a1e3138da756f7c399b3c44c Mon Sep 17 00:00:00 2001 From: paulGao Date: Tue, 7 Jun 2022 12:16:08 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E5=8F=AF=E8=83=BD=E5=87=BA=E7=8E=B0=E7=9A=84=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E4=BF=83=E9=94=80=E4=BF=A1=E6=81=AF=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/promotion/tools/PromotionTools.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/framework/src/main/java/cn/lili/modules/promotion/tools/PromotionTools.java b/framework/src/main/java/cn/lili/modules/promotion/tools/PromotionTools.java index 125bde42..44aa15e9 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/tools/PromotionTools.java +++ b/framework/src/main/java/cn/lili/modules/promotion/tools/PromotionTools.java @@ -164,13 +164,16 @@ public class PromotionTools { } //移除无效促销活动 return map.entrySet().stream().filter(i -> { - JSONObject promotionsObj = JSONUtil.parseObj(i.getValue()); - BasePromotions basePromotions = promotionsObj.toBean(BasePromotions.class); - if (basePromotions.getStartTime() != null && basePromotions.getEndTime() != null) { - return basePromotions.getStartTime().getTime() <= System.currentTimeMillis() && basePromotions.getEndTime().getTime() >= System.currentTimeMillis(); + if (i != null) { + JSONObject promotionsObj = JSONUtil.parseObj(i.getValue()); + BasePromotions basePromotions = promotionsObj.toBean(BasePromotions.class); + if (basePromotions.getStartTime() != null && basePromotions.getEndTime() != null) { + return basePromotions.getStartTime().getTime() <= System.currentTimeMillis() && basePromotions.getEndTime().getTime() >= System.currentTimeMillis(); + } } + return true; - }).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + }).collect(Collectors.toMap(stringObjectEntry -> stringObjectEntry != null ? stringObjectEntry.getKey() : null, stringObjectEntry1 -> stringObjectEntry1 != null ? stringObjectEntry1.getValue() : new BasePromotions())); } } From 8f3ca8c28d401ec0f2d0d1acad7048a27eb9aec5 Mon Sep 17 00:00:00 2001 From: paulGao Date: Tue, 7 Jun 2022 12:30:29 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E5=8F=AF=E8=83=BD=E5=87=BA=E7=8E=B0=E7=9A=84=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E4=BF=83=E9=94=80=E4=BF=A1=E6=81=AF=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/lili/modules/promotion/tools/PromotionTools.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/framework/src/main/java/cn/lili/modules/promotion/tools/PromotionTools.java b/framework/src/main/java/cn/lili/modules/promotion/tools/PromotionTools.java index 44aa15e9..b0aa1544 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/tools/PromotionTools.java +++ b/framework/src/main/java/cn/lili/modules/promotion/tools/PromotionTools.java @@ -1,5 +1,6 @@ package cn.lili.modules.promotion.tools; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; import cn.hutool.core.text.CharSequenceUtil; @@ -159,7 +160,7 @@ public class PromotionTools { } public static Map filterInvalidPromotionsMap(Map map) { - if (map == null) { + if (CollUtil.isEmpty(map)) { return new HashMap<>(); } //移除无效促销活动 @@ -173,7 +174,7 @@ public class PromotionTools { } return true; - }).collect(Collectors.toMap(stringObjectEntry -> stringObjectEntry != null ? stringObjectEntry.getKey() : null, stringObjectEntry1 -> stringObjectEntry1 != null ? stringObjectEntry1.getValue() : new BasePromotions())); + }).collect(Collectors.toMap(stringObjectEntry -> stringObjectEntry != null ? stringObjectEntry.getKey() : null, stringObjectEntry1 -> stringObjectEntry1 != null ? stringObjectEntry1.getValue() : new BasePromotions(), (oldValue, newValue) -> newValue)); } } From 9ece357e39cc63738589d3bd3333f6f3651fb7e0 Mon Sep 17 00:00:00 2001 From: paulGao Date: Tue, 7 Jun 2022 15:07:14 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E8=BF=87=E6=BB=A4=E6=97=A0=E6=95=88?= =?UTF-8?q?=E4=BF=83=E9=94=80=E4=BF=A1=E6=81=AF=E5=BC=82=E5=B8=B8=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../promotion/tools/PromotionTools.java | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/framework/src/main/java/cn/lili/modules/promotion/tools/PromotionTools.java b/framework/src/main/java/cn/lili/modules/promotion/tools/PromotionTools.java index b0aa1544..851faef4 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/tools/PromotionTools.java +++ b/framework/src/main/java/cn/lili/modules/promotion/tools/PromotionTools.java @@ -13,6 +13,7 @@ import cn.lili.modules.promotion.entity.dos.BasePromotions; import cn.lili.modules.promotion.entity.dos.PromotionGoods; import cn.lili.modules.promotion.entity.enums.PromotionsStatusEnum; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import lombok.extern.slf4j.Slf4j; import java.util.*; import java.util.function.Consumer; @@ -25,6 +26,7 @@ import java.util.stream.Collectors; * @author paulG * @since 2020/8/18 **/ +@Slf4j public class PromotionTools { public static final String START_TIME_COLUMN = "start_time"; @@ -163,18 +165,23 @@ public class PromotionTools { if (CollUtil.isEmpty(map)) { return new HashMap<>(); } - //移除无效促销活动 - return map.entrySet().stream().filter(i -> { - if (i != null) { - JSONObject promotionsObj = JSONUtil.parseObj(i.getValue()); - BasePromotions basePromotions = promotionsObj.toBean(BasePromotions.class); - if (basePromotions.getStartTime() != null && basePromotions.getEndTime() != null) { - return basePromotions.getStartTime().getTime() <= System.currentTimeMillis() && basePromotions.getEndTime().getTime() >= System.currentTimeMillis(); + try { + //移除无效促销活动 + return map.entrySet().stream().filter(i -> { + if (i != null) { + JSONObject promotionsObj = JSONUtil.parseObj(i.getValue()); + BasePromotions basePromotions = promotionsObj.toBean(BasePromotions.class); + if (basePromotions.getStartTime() != null && basePromotions.getEndTime() != null) { + return basePromotions.getStartTime().getTime() <= System.currentTimeMillis() && basePromotions.getEndTime().getTime() >= System.currentTimeMillis(); + } } - } - return true; - }).collect(Collectors.toMap(stringObjectEntry -> stringObjectEntry != null ? stringObjectEntry.getKey() : null, stringObjectEntry1 -> stringObjectEntry1 != null ? stringObjectEntry1.getValue() : new BasePromotions(), (oldValue, newValue) -> newValue)); + return true; + }).collect(Collectors.toMap(stringObjectEntry -> stringObjectEntry != null ? stringObjectEntry.getKey() : null, stringObjectEntry1 -> stringObjectEntry1 != null ? stringObjectEntry1.getValue() : new BasePromotions(), (oldValue, newValue) -> newValue)); + } catch (Exception e) { + log.error("过滤无效促销活动出现异常。异常促销信息:{},异常信息:{} ", map, e); + return new HashMap<>(); + } } } From 5f6bae6fa9019b5a1a550e1386b95407dc6f6b4b Mon Sep 17 00:00:00 2001 From: paulGao Date: Tue, 7 Jun 2022 15:18:07 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E5=8F=AF=E8=83=BD=E5=87=BA=E7=8E=B0=E7=9A=84=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E4=BF=83=E9=94=80=E4=BF=A1=E6=81=AF=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/promotion/tools/PromotionTools.java | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/framework/src/main/java/cn/lili/modules/promotion/tools/PromotionTools.java b/framework/src/main/java/cn/lili/modules/promotion/tools/PromotionTools.java index 851faef4..8266a6b0 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/tools/PromotionTools.java +++ b/framework/src/main/java/cn/lili/modules/promotion/tools/PromotionTools.java @@ -167,17 +167,14 @@ public class PromotionTools { } try { //移除无效促销活动 - return map.entrySet().stream().filter(i -> { - if (i != null) { - JSONObject promotionsObj = JSONUtil.parseObj(i.getValue()); - BasePromotions basePromotions = promotionsObj.toBean(BasePromotions.class); - if (basePromotions.getStartTime() != null && basePromotions.getEndTime() != null) { - return basePromotions.getStartTime().getTime() <= System.currentTimeMillis() && basePromotions.getEndTime().getTime() >= System.currentTimeMillis(); - } + return map.entrySet().stream().filter(Objects::nonNull).filter(i -> { + JSONObject promotionsObj = JSONUtil.parseObj(i.getValue()); + BasePromotions basePromotions = promotionsObj.toBean(BasePromotions.class); + if (basePromotions != null && basePromotions.getStartTime() != null && basePromotions.getEndTime() != null) { + return basePromotions.getStartTime().getTime() <= System.currentTimeMillis() && basePromotions.getEndTime().getTime() >= System.currentTimeMillis(); } - - return true; - }).collect(Collectors.toMap(stringObjectEntry -> stringObjectEntry != null ? stringObjectEntry.getKey() : null, stringObjectEntry1 -> stringObjectEntry1 != null ? stringObjectEntry1.getValue() : new BasePromotions(), (oldValue, newValue) -> newValue)); + return i.getValue() != null; + }).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (oldValue, newValue) -> newValue)); } catch (Exception e) { log.error("过滤无效促销活动出现异常。异常促销信息:{},异常信息:{} ", map, e); return new HashMap<>();