From ceab656e93edafbdaa0d908a2f723336af811b5a Mon Sep 17 00:00:00 2001
From: skyouc <958836976@qq.com>
Date: 星期三, 03 九月 2025 12:47:23 +0800
Subject: [PATCH] 站点任务功能优化

---
 rsf-server/src/main/java/com/vincent/rsf/server/manager/schedules/TaskSchedules.java |   99 ++++++++++++++++++++++++++-----------------------
 1 files changed, 53 insertions(+), 46 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 d96d3df..33a663a 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
@@ -173,10 +173,10 @@
                 }
 
                 orderItems.forEach(orderItem -> {
-                   orderItem.setOrderId(order.getId()).setOrderCode(order.getCode()).setId(null);
-                   if (!asnOrderItemService.save(orderItem)) {
-                       throw new CoolException("鍏ュ簱鍗曟槑缁嗕繚瀛樺け璐ワ紒锛�");
-                   }
+                    orderItem.setOrderId(order.getId()).setOrderCode(order.getCode()).setId(null);
+                    if (!asnOrderItemService.save(orderItem)) {
+                        throw new CoolException("鍏ュ簱鍗曟槑缁嗕繚瀛樺け璐ワ紒锛�");
+                    }
                 });
 
                 Transfer transfer = transferService.getById(order.getPoId());
@@ -240,11 +240,11 @@
      * @throws Exception
      */
     @Scheduled(cron = "0/5 * * * * ?  ")
-    @Transactional(rollbackFor = Exception.class)
-    public void taskToWCS() throws Exception {
+
+    public void taskToWCS() {
         Long loginUserId = SystemAuthUtils.getLoginUserId();
         List<Integer> list = Arrays.asList(TaskType.TASK_TYPE_IN.type, TaskType.TASK_TYPE_OUT.type, TaskType.TASK_TYPE_LOC_MOVE.type, TaskType.TASK_TYPE_EMPITY_IN.type
-        ,TaskType.TASK_TYPE_CHECK_IN.type, TaskType.TASK_TYPE_MERGE_IN.type, TaskType.TASK_TYPE_EMPITY_OUT.type,
+                , TaskType.TASK_TYPE_CHECK_IN.type, TaskType.TASK_TYPE_MERGE_IN.type, TaskType.TASK_TYPE_EMPITY_OUT.type,
                 TaskType.TASK_TYPE_PICK_AGAIN_OUT.type, TaskType.TASK_TYPE_CHECK_OUT.type, TaskType.TASK_TYPE_MERGE_OUT.type);
         List<Integer> integers = Arrays.asList(TaskStsType.GENERATE_IN.id, TaskStsType.GENERATE_OUT.id);
         List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>()
@@ -252,33 +252,37 @@
                 .in(Task::getTaskStatus, integers)
                 .orderByDesc(Task::getSort));
         for (Task task : tasks) {
-            Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getBarcode, task.getBarcode()));
-            if (Objects.isNull(loc)) {
-                continue;
-            }
-            //鍒ゆ柇鏄惁娣卞簱浣�
-            if (!LocUtils.isShallowLoc(loc.getCode())) {
-                //鑾峰彇娣卞簱浣嶅搴旂殑娴呭簱浣�
-                String shallowLoc = LocUtils.getShallowLoc(loc.getCode());
-                if (StringUtils.isBlank(shallowLoc)) {
-                    continue;
-                }
-                Loc shalloc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, shallowLoc));
-                if (Objects.isNull(shalloc) || !shalloc.getUseStatus().equals(LocStsType.LOC_STS_TYPE_F.type)) {
-                    //濡傛灉娴呭簱浣嶄笉鍦ㄥ簱璺冲嚭寰幆
-                    continue;
-                }
-                LocToTaskParams params = new LocToTaskParams();
-                params.setOrgLoc(shallowLoc).setType(TaskType.TASK_TYPE_LOC_MOVE.type + "");
-                //鐢熸垚绉诲簱浠诲姟
-                Task moveTask = locItemService.genMoveTask(params, loginUserId);
-                moveTask.setSort(!Objects.isNull(task.getSort()) ? task.getSort() + 1 : Constants.TASK_SORT_DEFAULT_VALUE + 1);
-                if (!taskService.updateById(moveTask)) {
-                    throw new Exception("浠诲姟浼樺厛绾ф洿鏂板け璐ワ紒锛�");
-                }
-            }
+//            Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getBarcode, task.getBarcode()));
+//            if (Objects.isNull(loc)) {
+//                continue;
+//            }
+//            //鍒ゆ柇鏄惁娣卞簱浣�
+//            if (!LocUtils.isShallowLoc(loc.getCode())) {
+//                //鑾峰彇娣卞簱浣嶅搴旂殑娴呭簱浣�
+//                String shallowLoc = LocUtils.getShallowLoc(loc.getCode());
+//                if (StringUtils.isBlank(shallowLoc)) {
+//                    continue;
+//                }
+//                Loc shalloc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, shallowLoc));
+//                if (Objects.isNull(shalloc) || !shalloc.getUseStatus().equals(LocStsType.LOC_STS_TYPE_F.type)) {
+//                    //濡傛灉娴呭簱浣嶄笉鍦ㄥ簱璺冲嚭寰幆
+//                    continue;
+//                }
+//                LocToTaskParams params = new LocToTaskParams();
+//                params.setOrgLoc(shallowLoc).setType(TaskType.TASK_TYPE_LOC_MOVE.type + "");
+//                //鐢熸垚绉诲簱浠诲姟
+//                Task moveTask = locItemService.genMoveTask(params, loginUserId);
+//                moveTask.setSort(!Objects.isNull(task.getSort()) ? task.getSort() + 1 : Constants.TASK_SORT_DEFAULT_VALUE + 1);
+//                if (!taskService.updateById(moveTask)) {
+//                    throw new Exception("浠诲姟浼樺厛绾ф洿鏂板け璐ワ紒锛�");
+//                }
+//            }
             //TODO 璋冪敤涓嬪彂浠诲姟鎺ュ彛
-            pubTaskToWcs(task);
+            try {
+                pubTaskToWcs(task);
+            } catch (Exception e) {
+                log.error(e.getMessage());
+            }
         }
     }
 
@@ -307,10 +311,11 @@
 
     /**
      * 涓嬪彂浠诲姟鑷砏CS
+     *
      * @param task
      */
     @Transactional(rollbackFor = Exception.class)
-    public void pubTaskToWcs(Task task) throws Exception{
+    public void pubTaskToWcs(Task task) {
         WcsTaskParams taskParams = new WcsTaskParams();
         TaskItemParam itemParam = new TaskItemParam();
         //浠诲姟绫诲瀷锛屼换鍔$紪鐮�
@@ -321,20 +326,18 @@
         taskParams.setBatch(task.getBarcode());
 
         if (task.getTaskType().equals(TaskType.TASK_TYPE_IN.type)
-                || task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_IN.type )
-                || task.getTaskType().equals(TaskType.TASK_TYPE_PICK_IN.type)
                 || task.getTaskType().equals(TaskType.TASK_TYPE_MERGE_IN.type)
                 || task.getTaskType().equals(TaskType.TASK_TYPE_EMPITY_IN.type)) {
-
             itemParam.setDestLoc(task.getTargLoc())
                     .setOriSta(task.getOrgSite());
+        } else if (task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_IN.type) || task.getTaskType().equals(TaskType.TASK_TYPE_PICK_IN.type)) {
+            itemParam.setDestLoc(task.getTargLoc())
+                    .setOriSta(task.getTargSite());
         } else if (task.getTaskType().equals(TaskType.TASK_TYPE_OUT.type)
-
                 || task.getTaskType().equals(TaskType.TASK_TYPE_PICK_AGAIN_OUT.type)
                 || task.getTaskType().equals(TaskType.TASK_TYPE_EMPITY_OUT.type)
                 || task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_OUT.type)
-                || task.getTaskType().equals(TaskType.TASK_TYPE_MERGE_OUT.type)
-        ) {
+                || task.getTaskType().equals(TaskType.TASK_TYPE_MERGE_OUT.type)) {
 
             itemParam.setOriLoc(task.getOrgLoc())
                     .setDestSta(task.getTargSite());
@@ -352,7 +355,7 @@
         String pubTakUrl = rcsApi.getHost() + ":" + rcsApi.getPort() + RcsConstant.pubTask;
 
         /**RCS鍩虹閰嶇疆閾炬帴*/
-        log.info("浠诲姟涓嬪彂锛岃姹傚湴鍧�锛� {}锛� 璇锋眰鍙傛暟锛� {}", pubTakUrl , JSONObject.toJSONString(taskParams));
+        log.info("浠诲姟涓嬪彂锛岃姹傚湴鍧�锛� {}锛� 璇锋眰鍙傛暟锛� {}", pubTakUrl, JSONObject.toJSONString(taskParams));
         HttpHeaders headers = new HttpHeaders();
         headers.add("Content-Type", "application/json");
         headers.add("api-version", "v2.0");
@@ -362,10 +365,10 @@
         if (Objects.isNull(exchange.getBody())) {
             throw new CoolException("浠诲姟涓嬪彂澶辫触锛侊紒");
         } else {
-            ObjectMapper objectMapper = new ObjectMapper();
-            objectMapper.coercionConfigDefaults()
-                    .setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsEmpty);
             try {
+                ObjectMapper objectMapper = new ObjectMapper();
+                objectMapper.coercionConfigDefaults()
+                        .setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsEmpty);
                 CommonResponse result = objectMapper.readValue(exchange.getBody(), CommonResponse.class);
                 if (result.getCode() == 200) {
                     if (task.getTaskType().equals(TaskType.TASK_TYPE_IN.type)
@@ -378,13 +381,17 @@
                                 .set(Task::getTaskStatus, TaskStsType.WCS_EXECUTE_IN.id))) {
                             throw new CoolException("浠诲姟鐘舵�佷慨鏀瑰け璐ワ紒锛�");
                         }
-                    } else if (task.getTaskType().equals(TaskType.TASK_TYPE_OUT.type)) {
+                    } else if (task.getTaskType().equals(TaskType.TASK_TYPE_OUT.type)
+                            || task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_OUT.type)
+                            || task.getTaskType().equals(TaskType.TASK_TYPE_MERGE_OUT.type)
+                            || task.getTaskType().equals(TaskType.TASK_TYPE_EMPITY_OUT.type)
+                            || task.getTaskType().equals(TaskType.TASK_TYPE_PICK_AGAIN_OUT.type)
+                    ) {
                         if (!taskService.update(new LambdaUpdateWrapper<Task>().eq(Task::getTaskCode, task.getTaskCode())
                                 .set(Task::getTaskStatus, TaskStsType.WCS_EXECUTE_OUT.id))) {
                             throw new CoolException("浠诲姟鐘舵�佷慨鏀瑰け璐ワ紒锛�");
                         }
                     }
-
                 } else {
                     throw new CoolException("浠诲姟涓嬪彂澶辫触锛侊紒");
                 }

--
Gitblit v1.9.1