|
|
@@ -42,14 +42,12 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.util.Comparator;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Objects;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 活动
|
|
|
+ *
|
|
|
* @author : codingliang
|
|
|
* @date : 2024-6-17
|
|
|
*/
|
|
|
@@ -168,21 +166,56 @@ public class ActivityServiceImpl extends ServiceImpl<ActivityDao, Activity> impl
|
|
|
removeByIds(activityIds);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据店铺ID和商品ID获取适用的活动列表
|
|
|
+ *
|
|
|
+ * @param shopId 店铺ID
|
|
|
+ * @param goodsId 商品ID
|
|
|
+ * @return 适用的活动列表
|
|
|
+ */
|
|
|
@Override
|
|
|
public List<ShopActivityBO> getActivityListByShopIdAndGoodsId(Long shopId, Long goodsId) {
|
|
|
- List<ShopActivityBO> shopActivityBOS = activityShopService.getShopActivityBOByShopId(shopId);
|
|
|
-
|
|
|
- // 满减活动过滤
|
|
|
- return shopActivityBOS.stream().filter(shopActivityBO -> {
|
|
|
- // 满减优惠
|
|
|
- if (ActivityTypeEnum.FULL.getTypeCode().equals(shopActivityBO.getType())) {
|
|
|
- // 查询符合条件的商品
|
|
|
- List<Long> applyGoodsIds = activityGoodsService.getByActivityShopId(shopActivityBO.getActivityShopId());
|
|
|
- return applyGoodsIds.contains(goodsId);
|
|
|
- } else {
|
|
|
- return true;
|
|
|
+ // 参数校验
|
|
|
+ if (shopId == null || goodsId == null) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ List<ShopActivityBO> shopActivityBOS = activityShopService.getShopActivityBOByShopId(shopId);
|
|
|
+ if (CollUtil.isEmpty(shopActivityBOS)) {
|
|
|
+ return Collections.emptyList();
|
|
|
}
|
|
|
- }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 提取所有满减活动的ID
|
|
|
+ List<Long> fullActivityIds = shopActivityBOS.stream()
|
|
|
+ .filter(shopActivityBO -> ActivityTypeEnum.FULL.getTypeCode().equals(shopActivityBO.getType()))
|
|
|
+ .map(ShopActivityBO::getActivityShopId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 批量查询满减活动的适用商品ID
|
|
|
+ Map<Long, List<Long>> activityGoodsMap = new HashMap<>();
|
|
|
+ if (!CollUtil.isEmpty(fullActivityIds)) {
|
|
|
+ // 假设有批量查询方法
|
|
|
+ activityGoodsMap = activityGoodsService.getByActivityShopIds(fullActivityIds);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 过滤活动
|
|
|
+ Map<Long, List<Long>> finalActivityGoodsMap = activityGoodsMap;
|
|
|
+ return shopActivityBOS.stream().filter(shopActivityBO -> {
|
|
|
+ // 满减优惠
|
|
|
+ if (ActivityTypeEnum.FULL.getTypeCode().equals(shopActivityBO.getType())) {
|
|
|
+ List<Long> applyGoodsIds = finalActivityGoodsMap.get(shopActivityBO.getActivityShopId());
|
|
|
+ return applyGoodsIds != null && applyGoodsIds.contains(goodsId);
|
|
|
+ } else {
|
|
|
+ // 其他类型的活动可以根据需要添加过滤逻辑
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 记录异常日志
|
|
|
+ log.error("获取活动列表失败,shopId: "+shopId+", goodsId: "+goodsId, e);
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -228,7 +261,8 @@ public class ActivityServiceImpl extends ServiceImpl<ActivityDao, Activity> impl
|
|
|
|
|
|
/**
|
|
|
* 根据id获取活动信息
|
|
|
- * 如id对应记录不存在,则抛出数据不存在异常
|
|
|
+ * 如id对应记录不存在,则抛出数据不存在异常
|
|
|
+ *
|
|
|
* @param id 活动id
|
|
|
* @return activity
|
|
|
*/
|
|
|
@@ -244,6 +278,7 @@ public class ActivityServiceImpl extends ServiceImpl<ActivityDao, Activity> impl
|
|
|
|
|
|
/**
|
|
|
* 获取活动配置
|
|
|
+ *
|
|
|
* @param activityDTO
|
|
|
* @return 活动config json串
|
|
|
*/
|
|
|
@@ -262,6 +297,7 @@ public class ActivityServiceImpl extends ServiceImpl<ActivityDao, Activity> impl
|
|
|
|
|
|
/**
|
|
|
* 校验活动参数
|
|
|
+ *
|
|
|
* @param activityDTO activityDTO
|
|
|
*/
|
|
|
private void checkParam(ActivityDTO activityDTO) {
|
|
|
@@ -279,8 +315,9 @@ public class ActivityServiceImpl extends ServiceImpl<ActivityDao, Activity> impl
|
|
|
|
|
|
/**
|
|
|
* 校验活动时间
|
|
|
+ *
|
|
|
* @param startTime 开始时间
|
|
|
- * @param endTime 结束时间
|
|
|
+ * @param endTime 结束时间
|
|
|
*/
|
|
|
private void checkActivityDate(Date startTime, Date endTime) {
|
|
|
// 结束时间必须在开始时间之后
|
|
|
@@ -291,6 +328,7 @@ public class ActivityServiceImpl extends ServiceImpl<ActivityDao, Activity> impl
|
|
|
|
|
|
/**
|
|
|
* 校验全局优惠活动参数信息
|
|
|
+ *
|
|
|
* @param globalDiscountsInfo 全局优惠信息
|
|
|
*/
|
|
|
private void checkGlobalActivityParam(ActivityOfGlobalDiscountDTO globalDiscountsInfo) {
|
|
|
@@ -305,6 +343,7 @@ public class ActivityServiceImpl extends ServiceImpl<ActivityDao, Activity> impl
|
|
|
|
|
|
/**
|
|
|
* 校验满减优惠活动参数信息
|
|
|
+ *
|
|
|
* @param fullReductionInfo 满减优惠信息
|
|
|
*/
|
|
|
private void checkFullActivityParam(ActivityOfFullReductionDTO fullReductionInfo) {
|
|
|
@@ -323,6 +362,7 @@ public class ActivityServiceImpl extends ServiceImpl<ActivityDao, Activity> impl
|
|
|
|
|
|
/**
|
|
|
* 校验时段优惠活动参数信息
|
|
|
+ *
|
|
|
* @param timeIntervalInfos 时段优惠信息
|
|
|
*/
|
|
|
private void checkTimeActivityParam(List<ActivityOfTimeIntervalDTO> timeIntervalInfos) {
|
|
|
@@ -346,8 +386,9 @@ public class ActivityServiceImpl extends ServiceImpl<ActivityDao, Activity> impl
|
|
|
|
|
|
/**
|
|
|
* 活动限制过滤
|
|
|
+ *
|
|
|
* @param shopActivityBO 店铺活动信息
|
|
|
- * @param order 订单信息
|
|
|
+ * @param order 订单信息
|
|
|
* @return 订单是否适用当前活动
|
|
|
*/
|
|
|
private boolean activityLimitFilter(ShopActivityBO shopActivityBO, TbOrder order) {
|
|
|
@@ -372,6 +413,7 @@ public class ActivityServiceImpl extends ServiceImpl<ActivityDao, Activity> impl
|
|
|
|
|
|
/**
|
|
|
* 计算当前订单商品适用的活动优惠价格
|
|
|
+ *
|
|
|
* @param shopActivityBO 店铺活动信息
|
|
|
* @param orderGoodsList 订单商品列表
|
|
|
* @return 订单适用活动信息
|