Przeglądaj źródła

重复商品上下架问题

yuhongqi 4 dni temu
rodzic
commit
684f663f55

+ 13 - 11
fs-service-system/src/main/java/com/fs/live/service/impl/LiveServiceImpl.java

@@ -994,9 +994,9 @@ public class LiveServiceImpl implements ILiveService
         Map<Long, LiveAutoTask> goodsTaskMap = goodsTasks.stream()
                 .collect(Collectors.toMap(task -> parseIdFromContent(task.getContent(), "goodsId"),
                         Function.identity(), (existing, replacement) -> existing));
-        Map<Long, LiveAutoTask> shelfTaskMap = shelfTasks.stream()
-                .collect(Collectors.toMap(task -> parseIdFromContent(task.getContent(), "goodsId"),
-                        Function.identity(), (existing, replacement) -> existing));
+        // 使用 groupingBy 支持同一个商品有多个上下架任务(不同时间点的上架/下架操作)
+        Map<Long, List<LiveAutoTask>> shelfTaskMap = shelfTasks.stream()
+                .collect(Collectors.groupingBy(task -> parseIdFromContent(task.getContent(), "goodsId")));
 
         LiveGoods queryParam = new LiveGoods();
         queryParam.setLiveId(existLiveId);
@@ -1036,14 +1036,16 @@ public class LiveServiceImpl implements ILiveService
                     liveAutoTaskService.directInsertLiveAutoTask(newTask);
                 }
 
-                // 复制上下架任务(taskType=6)
-                LiveAutoTask shelfTask = shelfTaskMap.get(liveGoods.getGoodsId());
-                if (shelfTask != null) {
-                    JSONObject contentJson = JSON.parseObject(shelfTask.getContent());
-                    contentJson.put("goodsId", newGoods.getGoodsId());
-                    LiveAutoTask newTask = createAutoTaskEntity(shelfTask, newLiveId, now,
-                            contentJson.toJSONString());
-                    liveAutoTaskService.directInsertLiveAutoTask(newTask);
+                // 复制上下架任务(taskType=6)- 支持同一个商品有多个上下架任务
+                List<LiveAutoTask> shelfTaskList = shelfTaskMap.get(liveGoods.getGoodsId());
+                if (shelfTaskList != null && !shelfTaskList.isEmpty()) {
+                    for (LiveAutoTask shelfTask : shelfTaskList) {
+                        JSONObject contentJson = JSON.parseObject(shelfTask.getContent());
+                        contentJson.put("goodsId", newGoods.getGoodsId());
+                        LiveAutoTask newTask = createAutoTaskEntity(shelfTask, newLiveId, now,
+                                contentJson.toJSONString());
+                        liveAutoTaskService.directInsertLiveAutoTask(newTask);
+                    }
                 }
             }
         }