From 10dbf9aae07dcd7c569521613b072088abae1c2e Mon Sep 17 00:00:00 2001
From: skyouc
Date: 星期四, 22 五月 2025 17:18:32 +0800
Subject: [PATCH] 库存出库任务联调

---
 rsf-server/src/main/java/com/vincent/rsf/server/manager/schedules/TaskSchedules.java |   71 +++++++++++++++++++----------------
 1 files changed, 39 insertions(+), 32 deletions(-)

diff --git a/rsf-server/src/main/java/com/vincent/rsf/server/manager/schedules/TaskSchedules.java b/rsf-server/src/main/java/com/vincent/rsf/server/manager/schedules/TaskSchedules.java
index 2a17919..f35c3ab 100644
--- a/rsf-server/src/main/java/com/vincent/rsf/server/manager/schedules/TaskSchedules.java
+++ b/rsf-server/src/main/java/com/vincent/rsf/server/manager/schedules/TaskSchedules.java
@@ -16,6 +16,7 @@
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 import java.util.Objects;
 import java.util.stream.Collectors;
 
@@ -48,21 +49,22 @@
     private LocService locService;
     @Autowired
     private ConfigService configService;
+
     /**
-    * @author Ryan
-    * @description 瀹屾垚鍏ュ簱锛屾洿鏂板簱瀛�
-    * @param
-    * @return
-    * @time 2025/4/2 12:37
-    */
+     * @param
+     * @return
+     * @author Ryan
+     * @description 瀹屾垚鍏ュ簱锛屾洿鏂板簱瀛�
+     * @time 2025/4/2 12:37
+     */
     @Scheduled(cron = "0/3 * * * * ?")
-    @Transactional(rollbackFor = Exception.class)
+//    @Transactional(rollbackFor = Exception.class)
     public void completeInStock() throws Exception {
         List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>().eq(Task::getTaskStatus, TaskStsType.COMPLETE_IN.id));
         if (tasks.isEmpty()) {
             return;
         }
-        taskService.completeTask(tasks);
+        taskService.complateInTask(tasks);
     }
 
     /**
@@ -71,7 +73,7 @@
      * @description: 瀹屾垚鍑哄簱浠诲姟锛屾洿鏂板簱瀛�
      * @version 1.0
      */
-    @Scheduled(cron = "0/5 * * * * ?")
+    @Scheduled(cron = "0/30 * * * * ?  ")
     @Transactional(rollbackFor = Exception.class)
     public void complateOutStock() throws Exception {
         List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>().eq(Task::getTaskStatus, TaskStsType.COMPLETE_OUT.id));
@@ -82,12 +84,12 @@
     }
 
     /**
-    * @author Ryan
-    * @description 宸插畬鎴愪换鍔″姞鍏ュ巻鍙叉。
-    * @param
-    * @return
-    * @time 2025/4/3 12:54
-    */
+     * @param
+     * @return
+     * @author Ryan
+     * @description 宸插畬鎴愪换鍔″姞鍏ュ巻鍙叉。
+     * @time 2025/4/3 12:54
+     */
     @Scheduled(cron = "0 0/05 * * * ?  ")
     @Transactional(rollbackFor = Exception.class)
     public void taskLogUpdate() {
@@ -113,32 +115,37 @@
             return;
         }
 
-        List<TaskLog> taskLogs = new ArrayList<>();
+        Map<Long, List<TaskItem>> listMap = taskItems.stream().collect(Collectors.groupingBy(TaskItem::getTaskId));
+
         tasks.forEach(task -> {
             TaskLog taskLog = new TaskLog();
             BeanUtils.copyProperties(task, taskLog);
-            taskLog.setTaskId(task.getId()).setId(null);
-            taskLogs.add(taskLog);
-        });
-        if (!taskLogService.saveBatch(taskLogs)) {
-            throw new CoolException("浠诲姟鍘嗗彶妗d繚瀛樺け璐ワ紒锛�");
-        }
-        List<TaskItemLog >itemLogs = new ArrayList<>();
+            taskLog.setTaskId(task.getId())
+                    .setId(null);
+            if (!taskLogService.save(taskLog)) {
+                throw new CoolException("浠诲姟鍘嗗彶妗d繚瀛樺け璐ワ紒锛�");
+            }
 
-        taskItems.forEach(item -> {
-            TaskItemLog itemLog = new TaskItemLog();
-            BeanUtils.copyProperties(item, itemLog);
-            itemLog.setId(null).setTaskItemId(item.getId());
-            itemLogs.add(itemLog);
-        });
+            List<TaskItemLog> itemLogs = new ArrayList<>();
+            for (TaskItem item : listMap.get(task.getId())) {
+                TaskItemLog itemLog = new TaskItemLog();
+                BeanUtils.copyProperties(item, itemLog);
+                itemLog.setId(null)
+                        .setTaskId(task.getId())
+                        .setLogId(taskLog.getId())
+                        .setTaskItemId(item.getId());
+                itemLogs.add(itemLog);
+            }
 
-        if (!taskItemLogService.saveBatch(itemLogs)) {
-            throw new CoolException("浠诲姟鏄庣粏鍘嗗彶妗d繚瀛樺け璐ワ紒锛�");
-        }
+            if (!taskItemLogService.saveBatch(itemLogs)) {
+                throw new CoolException("浠诲姟鏄庣粏鍘嗗彶妗d繚瀛樺け璐ワ紒锛�");
+            }
+        });
 
         if (!taskService.removeByIds(list)) {
             throw new CoolException("鍘熷浠诲姟鍒犻櫎澶辫触锛侊紒");
         }
+
         List<Long> itemIds = taskItems.stream().map(TaskItem::getId).collect(Collectors.toList());
 
         if (!taskItemService.removeByIds(itemIds)) {

--
Gitblit v1.9.1