From 2e929cc5c44e4072520aae4c8a9f40029da27405 Mon Sep 17 00:00:00 2001
From: zc <zyzc>
Date: 星期二, 18 十一月 2025 17:29:13 +0800
Subject: [PATCH] 上报站点报异常 二次组托异常

---
 rsf-server/src/main/java/com/vincent/rsf/server/manager/schedules/TaskSchedules.java |  151 ++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 114 insertions(+), 37 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 0ce3eee..b2cca17 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
@@ -1,6 +1,5 @@
 package com.vincent.rsf.server.manager.schedules;
 
-import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
@@ -8,6 +7,7 @@
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.cfg.CoercionAction;
 import com.fasterxml.jackson.databind.cfg.CoercionInputShape;
+import com.vincent.rsf.framework.common.DateUtils;
 import com.vincent.rsf.framework.common.R;
 import com.vincent.rsf.framework.exception.CoolException;
 import com.vincent.rsf.server.api.config.RemotesInfoProperties;
@@ -18,6 +18,7 @@
 import com.vincent.rsf.server.api.service.ReportMsgService;
 import com.vincent.rsf.server.api.utils.LocUtils;
 import com.vincent.rsf.server.common.constant.Constants;
+import com.vincent.rsf.server.manager.controller.params.LocSiteParams;
 import com.vincent.rsf.server.manager.controller.params.LocToTaskParams;
 import com.vincent.rsf.server.manager.enums.*;
 import com.vincent.rsf.server.manager.entity.*;
@@ -240,7 +241,7 @@
     /**
      * 闈炲厜鐢电珯鐐逛换鍔′笅鍙�
      */
-    @Scheduled(cron = "0/5 * * * * ?  ")
+    @Scheduled(cron = "0/55 * * * * ?  ")
     @Transactional(rollbackFor = Exception.class)
     public void pubTaskToWcs() {
         Long loginUserId = SystemAuthUtils.getLoginUserId();
@@ -250,21 +251,35 @@
         List<Integer> integers = Arrays.asList(TaskStsType.GENERATE_IN.id, TaskStsType.GENERATE_OUT.id);
         List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>()
                 .in(Task::getTaskType, list)
-                .in(Task::getTaskStatus, integers).last("limit 1")
+                .in(Task::getTaskStatus, integers)
                 .orderByDesc(Task::getSort));
-        for (Task task : tasks) {
-            /**绉诲簱涓嶅仛绔欑偣鎿嶄綔*/
-            if (!task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) {
-                BasStation station = basStationService.getOne(new LambdaQueryWrapper<BasStation>()
-                        .eq(BasStation::getStationName,
-                        task.getTaskStatus().equals(TaskStsType.GENERATE_IN.id) ? task.getOrgSite() : task.getTargSite()));
-                if (station.getType().equals(StationTypeEnum.STATION_TYPE_MUTI.type)) {
-                    continue;
+        if (tasks.isEmpty()) {
+            return;
+        }
+        Config config = configService.getOne(new LambdaQueryWrapper<Config>().eq(Config::getFlag, GlobalConfigCode.ALLOW_PUB_TASK));
+        if (!Objects.isNull(config) && !Objects.isNull(config.getVal())) {
+            Integer val = Integer.parseInt(config.getVal());
+            if (val > 1) {
+                List<Task> tasks1 = tasks.stream().sorted(Comparator.comparing(Task::getCreateTime)).collect(Collectors.toList());
+                Task task = tasks1.stream().findFirst().get();
+                if (DateUtils.diffToSeconds(task.getCreateTime(), new Date()) < val) {
+                    return;
                 }
             }
-            /**涓嬪彂鏅�氱珯鐐逛换鍔★紝鎶ラ敊鍥炴粴锛屼笉鍐嶅線涓嬫墽琛�*/
-            pubTaskToWcs(tasks);
         }
+//        for (Task task : tasks) {
+//            /**绉诲簱涓嶅仛绔欑偣鎿嶄綔*/
+//            if (!task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) {
+//                BasStation station = basStationService.getOne(new LambdaQueryWrapper<BasStation>()
+//                        .eq(BasStation::getStationName,
+//                                task.getTaskStatus().equals(TaskStsType.GENERATE_IN.id) ? task.getOrgSite() : task.getTargSite()));
+//                if (station.getType().equals(StationTypeEnum.STATION_TYPE_MUTI.type)) {
+//                    continue;
+//                }
+//            }
+//        }
+        /**涓嬪彂鏅�氱珯鐐逛换鍔★紝鎶ラ敊鍥炴粴锛屼笉鍐嶅線涓嬫墽琛�*/
+        pubTaskToWcs(tasks);
     }
 
     /**
@@ -388,17 +403,11 @@
             /**鍒ゆ柇鏄惁鍏夌數绔欑偣锛岄潪鍏夊簵绔欑偣闇�绠℃帶绔欑偣鐘舵��*/
             if (!Objects.isNull(station) && station.getType().equals(StationTypeEnum.STATION_TYPE_NORMAL.type)) {
                 if (task.getTaskType() <= TaskType.TASK_TYPE_CHECK_IN.type && !task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) {
-//                if (!station.getUseStatus().equals(LocStsType.LOC_STS_TYPE_F.type)) {
-//                    throw new CoolException( "褰撳墠绔欑偣涓嶆槸F.鍦ㄥ簱鐘舵�佺姸鎬侊紒锛�");
-//                }
                     station.setUseStatus(LocStsType.LOC_STS_TYPE_R.type);
                     if (!basStationService.updateById(station)) {
                         throw new CoolException("绔欑偣鐘舵�佹洿鏂板け璐ワ紒锛�");
                     }
                 } else if (task.getTaskType() >= TaskType.TASK_TYPE_OUT.type) {
-                    if (!station.getUseStatus().equals(LocStsType.LOC_STS_TYPE_O.type)) {
-                        throw new CoolException("鐩爣绔欑偣涓嶅O.绌洪棽鐘舵�侊紝鏃犳硶棰勭害鍑哄簱銆�");
-                    }
                     station.setUseStatus(LocStsType.LOC_STS_TYPE_S.type);
                     if (!basStationService.updateById(station)) {
                         throw new CoolException("绔欑偣鐘舵�佹洿鏂板け璐ワ紒锛�");
@@ -469,16 +478,19 @@
                 CommonResponse result = objectMapper.readValue(exchange.getBody(), CommonResponse.class);
                 if (result.getCode() == 200) {
                     tasks.forEach(task -> {
-                        BasStation curSta = basStationService.getOne(new LambdaQueryWrapper<BasStation>().eq(BasStation::getStationName, task.getOrgSite()));
-                        if (Objects.isNull(curSta)) {
-                            throw new CoolException("绔欑偣涓嶅瓨鍦紒锛�");
-                        }
+
                         if (task.getTaskType().equals(TaskType.TASK_TYPE_IN.type)
                                 || task.getTaskType().equals(TaskType.TASK_TYPE_PICK_IN.type)
                                 || task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_IN.type)
                                 || task.getTaskType().equals(TaskType.TASK_TYPE_EMPITY_IN.type)
                                 || task.getTaskType().equals(TaskType.TASK_TYPE_MERGE_IN.type)
                                 || task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) {
+
+                            BasStation curSta = basStationService.getOne(new LambdaQueryWrapper<BasStation>().eq(BasStation::getStationName, task.getOrgSite()));
+                            if (Objects.isNull(curSta)) {
+                                throw new CoolException("绔欑偣涓嶅瓨鍦紒锛�");
+                            }
+
                             if (!taskService.update(new LambdaUpdateWrapper<Task>().eq(Task::getTaskCode, task.getTaskCode())
                                     .set(Task::getTaskStatus, TaskStsType.WCS_EXECUTE_IN.id))) {
                                 throw new CoolException("浠诲姟鐘舵�佷慨鏀瑰け璐ワ紒锛�");
@@ -498,6 +510,11 @@
                                 || 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)) {
+                            BasStation curSta = basStationService.getOne(new LambdaQueryWrapper<BasStation>().eq(BasStation::getStationName, task.getTargSite()));
+                            if (Objects.isNull(curSta)) {
+                                throw new CoolException("绔欑偣涓嶅瓨鍦紒锛�");
+                            }
+
                             if (!taskService.update(new LambdaUpdateWrapper<Task>().eq(Task::getTaskCode, task.getTaskCode())
                                     .set(Task::getTaskStatus, TaskStsType.WCS_EXECUTE_OUT.id))) {
                                 throw new CoolException("浠诲姟鐘舵�佷慨鏀瑰け璐ワ紒锛�");
@@ -512,7 +529,8 @@
                         }
                     });
                 } else {
-                    throw new CoolException("浠诲姟涓嬪彂澶辫触锛侊紒");
+                    log.error(JSONObject.toJSONString(result));
+//                    throw new CoolException("浠诲姟涓嬪彂澶辫触锛侊紒");
                 }
             } catch (JsonProcessingException e) {
                 throw new CoolException(e.getMessage());
@@ -522,7 +540,6 @@
     }
 
 
-
     /**
      * @param
      * @return
@@ -530,7 +547,7 @@
      * @description 宸插畬鎴愪换鍔″姞鍏ュ巻鍙叉。
      * @time 2025/4/3 12:54
      */
-    @Scheduled(cron = "0 0/01 * * * ?  ")
+    @Scheduled(cron = "0/15 * * * * ?  ")
     @Transactional(rollbackFor = Exception.class)
     public void taskLogUpdate() {
         LambdaQueryWrapper<Task> queryWrapper = new LambdaQueryWrapper<Task>();
@@ -552,19 +569,23 @@
         tasks.forEach(task -> {
             TaskLog taskLog = new TaskLog();
             BeanUtils.copyProperties(task, taskLog);
-            taskLog.setTaskId(task.getId())
-                    .setId(null);
+            taskLog.setTaskId(task.getId()).setId(null);
             if (!taskLogService.save(taskLog)) {
                 throw new CoolException("浠诲姟鍘嗗彶妗d繚瀛樺け璐ワ紒锛�");
             }
             List<TaskItem> taskItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, task.getId()));
+            //鍏ュ簱鍗曟嵁鏄庣粏涓婃姤
 
-            taskItems.forEach(taskItem -> {
-                WkOrder order = asnOrderService.getById(taskItem.getOrderId());
-                if (Objects.isNull(order)) {
-                    throw new CoolException("鏁版嵁閿欒锛屽崟鎹笉瀛樺湪锛侊紒");
-                }
-                if (order.getType().equals(OrderType.ORDER_IN.type)) {
+            if (task.getTaskType().equals(TaskType.TASK_TYPE_IN.type)) {
+                for (TaskItem taskItem : taskItems) {
+                    if (Objects.isNull(taskItem.getOrderId())) {
+                        continue;
+                    }
+                    WkOrder order = asnOrderService.getById(taskItem.getOrderId());
+                    if (Objects.isNull(order)) {
+                        continue;
+                    }
+                    //鍏ュ簱鍗曚换鍔℃槑缁嗕笂鎶�
                     WkOrderItem wkOrderItem = asnOrderItemService.getOne(new LambdaQueryWrapper<WkOrderItem>()
                             .eq(WkOrderItem::getOrderId, order.getId())
                             .eq(WkOrderItem::getFieldsIndex, taskItem.getFieldsIndex()));
@@ -573,9 +594,15 @@
                     }
                     /**鍏ュ簱鍗曟槑缁嗕笂鎶�*/
                     reportMsgService.reportOrderItem(wkOrderItem);
-                    //淇敼璁㈠崟涓婃姤娆℃暟
                 }
-            });
+            } else if (task.getTaskType() >= TaskType.TASK_TYPE_OUT.type && task.getTaskType() <= TaskType.TASK_TYPE_EMPITY_OUT.type) {
+                //鍑哄簱鍗曚笂鎶CS淇敼搴撲綅鐘舵��
+                try {
+                    reportStationStatus(task);
+                } catch (Exception e) {
+                    throw new CoolException(e.getMessage());
+                }
+            }
 
             List<TaskItemLog> itemLogs = new ArrayList<>();
             for (TaskItem item : taskItems) {
@@ -596,11 +623,61 @@
                 if (!taskItemLogService.saveBatch(itemLogs)) {
                     throw new CoolException("浠诲姟鏄庣粏鍘嗗彶妗d繚瀛樺け璐ワ紒锛�");
                 }
-
                 if (!taskItemService.remove(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, task.getId()))) {
                     throw new CoolException("鍘熷浠诲姟鏄庣粏鍒犻櫎澶辫触锛侊紒");
                 }
             }
         });
     }
+
+
+    /**
+     * @author Ryan
+     * @date 2025/11/10
+     * @description: 涓婃姤绔欑偣鐘舵��
+     * @version 1.0
+     */
+    public CommonResponse reportStationStatus(Task task) {
+        if (Objects.isNull(task.getTargSite())) {
+            throw new CoolException("鐩爣绔欑偣涓嶈兘涓虹┖锛侊紒");
+        }
+        BasStation station = basStationService.getOne(new LambdaQueryWrapper<BasStation>().eq(BasStation::getStationName, task.getTargSite()));
+        if (Objects.isNull(station)) {
+            throw new CoolException("鏁版嵁閿欒锛岀洰鏍囩珯鐐逛笉瀛樺湪锛侊紒");
+        }
+        station.setUseStatus(LocStsType.LOC_STS_TYPE_O.type);
+
+        if (!basStationService.updateById(station)) {
+            throw new CoolException("绔欑偣鐘舵�佷慨鏀瑰け璐ワ紒锛�");
+        }
+
+        LocSiteParams locSiteParams = new LocSiteParams();
+        locSiteParams.setStatus(LocStsType.getRcsLocSts(LocStsType.LOC_STS_TYPE_O.type))
+                .setType("site")
+                .setCode(station.getStationName());
+        /**WMS鍩虹閰嶇疆閾炬帴*/
+        String rcsUrl = rcsApi.getHost() + ":" + rcsApi.getPort() + RcsConstant.REPORT_SITE_STATUS;
+        log.info("涓婃姤宸插畬鎴愯鍗曪細{}锛� 璇锋眰鍙傛暟锛� {}", rcsUrl, JSONObject.toJSONString(locSiteParams));
+        HttpHeaders headers = new HttpHeaders();
+        headers.add("Content-Type", "application/json");
+        headers.add("api-version", "v2.0");
+
+        HttpEntity httpEntity = new HttpEntity(locSiteParams, headers);
+        ResponseEntity<String> exchange = restTemplate.exchange(rcsUrl, HttpMethod.POST, httpEntity, String.class);
+        log.info("涓婃姤宸插畬鎴愯鍗曪紝杩斿洖缁撴灉锛� {}", exchange);
+
+        if (Objects.isNull(exchange.getBody())) {
+            throw new CoolException("淇敼澶辫触锛侊紒");
+        } else {
+            ObjectMapper objectMapper = new ObjectMapper();
+            objectMapper.coercionConfigDefaults().setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsEmpty);
+            try {
+                CommonResponse result = objectMapper.readValue(exchange.getBody(), CommonResponse.class);
+                return result;
+            } catch (JsonProcessingException e) {
+                throw new CoolException(e.getMessage());
+            }
+        }
+    }
+
 }

--
Gitblit v1.9.1