From 26784989e73fc36c6315e54939d1b13a50eb5020 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期四, 26 三月 2026 21:03:00 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/network/real/ZyStationV4RealConnect.java |   94 +++++++++++++++++++----------------------------
 1 files changed, 38 insertions(+), 56 deletions(-)

diff --git a/src/main/java/com/zy/core/network/real/ZyStationV4RealConnect.java b/src/main/java/com/zy/core/network/real/ZyStationV4RealConnect.java
index d1f0431..6e91763 100644
--- a/src/main/java/com/zy/core/network/real/ZyStationV4RealConnect.java
+++ b/src/main/java/com/zy/core/network/real/ZyStationV4RealConnect.java
@@ -244,32 +244,6 @@
             return commandResponse;
         }
 
-        if (isDuplicateStationCommand(statusEntity, command)) {
-            log.info("杈撻�佺嚎鍛戒护閲嶅锛屽凡璺宠繃褰撳墠绔欑偣鍛戒护銆備换鍔″彿={}锛岀珯鐐瑰彿={}锛岀洰鏍囩珯={}锛宼askWriteIdx={}锛宑urrentTaskNo={}锛宑urrentTargetStaNo={}",
-                    command.getTaskNo(),
-                    command.getStationId(),
-                    command.getTargetStaNo(),
-                    taskWriteIdx,
-                    statusEntity == null ? null : statusEntity.getTaskNo(),
-                    statusEntity == null ? null : statusEntity.getTargetStaNo());
-            commandResponse.setResult(true);
-            commandResponse.setMessage("鍛戒护閲嶅锛屽凡璺宠繃涓嬪彂");
-            return commandResponse;
-        }
-
-        Integer duplicateSlotIdx = findDuplicateTaskAreaSlot(stationIdx, command);
-        if (duplicateSlotIdx != null) {
-            log.info("杈撻�佺嚎鍛戒护閲嶅锛屽凡璺宠繃浠诲姟鍐欏叆鍖洪噸澶嶅懡浠ゃ�備换鍔″彿={}锛岀珯鐐瑰彿={}锛岀洰鏍囩珯={}锛宼askWriteIdx={}锛宒uplicateSlotIdx={}",
-                    command.getTaskNo(),
-                    command.getStationId(),
-                    command.getTargetStaNo(),
-                    taskWriteIdx,
-                    duplicateSlotIdx);
-            commandResponse.setResult(true);
-            commandResponse.setMessage("浠诲姟鍖哄凡鏈夌浉鍚屽懡浠わ紝宸茶烦杩囦笅鍙�");
-            return commandResponse;
-        }
-
         int useTaskWriteIdx = getTaskWriteIdx(stationIdx, taskWriteIdx);
         if (useTaskWriteIdx == -1) {
             commandResponse.setMessage("鍛戒护涓嬪彂瓒呮椂锛屾棤娉曟壘鍒板彲鐢ㄤ笅鍙戝尯鍩�");
@@ -296,6 +270,44 @@
 
         log.info("鍐欏叆杈撻�佺嚎鍛戒护鎴愬姛銆備换鍔″彿={}锛岀珯鐐规暟鎹�={}", command.getTaskNo(), JSON.toJSON(command));
         commandResponse.setResult(true);
+        return commandResponse;
+    }
+
+    @Override
+    public CommandResponse clearTaskBufferSlot(Integer deviceNo, Integer stationId, Integer slotIdx) {
+        CommandResponse commandResponse = new CommandResponse(false);
+        if (stationId == null) {
+            commandResponse.setMessage("绔欑偣鍙蜂负绌�");
+            return commandResponse;
+        }
+        if (slotIdx == null || slotIdx <= 0 || slotIdx > TASK_AREA_SLOT_COUNT) {
+            commandResponse.setMessage("缂撳瓨鍖烘Ы浣嶆棤鏁�");
+            return commandResponse;
+        }
+
+        getStatus(deviceNo);
+
+        int stationIdx = findIndex(stationId);
+        if (stationIdx < 0) {
+            commandResponse.setMessage("鏈壘鍒扮珯鐐圭姸鎬�");
+            return commandResponse;
+        }
+
+        int slotBaseOffset = stationIdx * TASK_AREA_LENGTH + slotIdx * TASK_AREA_SLOT_SIZE;
+        CommandResponse clearTaskNo = sendOriginCommand("DB13." + slotBaseOffset, new short[]{0, 0});
+        if (clearTaskNo == null || !Boolean.TRUE.equals(clearTaskNo.getResult())) {
+            commandResponse.setMessage(clearTaskNo == null ? "娓呯┖浠诲姟鍙峰け璐�" : clearTaskNo.getMessage());
+            return commandResponse;
+        }
+
+        CommandResponse clearTarget = sendOriginCommand("DB13." + (slotBaseOffset + 6), new short[]{0});
+        if (clearTarget == null || !Boolean.TRUE.equals(clearTarget.getResult())) {
+            commandResponse.setMessage(clearTarget == null ? "娓呯┖鐩爣绔欏け璐�" : clearTarget.getMessage());
+            return commandResponse;
+        }
+
+        commandResponse.setResult(true);
+        commandResponse.setMessage("缂撳瓨鍖烘Ы浣嶆竻鐞嗘垚鍔�");
         return commandResponse;
     }
 
@@ -358,36 +370,6 @@
             }
         }
         return useIdx;
-    }
-
-    private boolean isDuplicateStationCommand(ZyStationStatusEntity statusEntity, StationCommand command) {
-        if (statusEntity == null || command == null) {
-            return false;
-        }
-        return command.getTaskNo() != null
-                && command.getTargetStaNo() != null
-                && command.getTaskNo().equals(statusEntity.getTaskNo())
-                && command.getTargetStaNo().equals(statusEntity.getTargetStaNo());
-    }
-
-    private Integer findDuplicateTaskAreaSlot(int stationIdx, StationCommand command) {
-        if (stationIdx < 0 || command == null || command.getTaskNo() == null || command.getTargetStaNo() == null) {
-            return null;
-        }
-        OperateResultExOne<byte[]> resultTask = siemensNet.Read("DB13." + (stationIdx * TASK_AREA_LENGTH), (short) TASK_AREA_LENGTH);
-        if (!resultTask.IsSuccess || resultTask.Content == null) {
-            return null;
-        }
-        for (int slotIdx = 1; slotIdx <= TASK_AREA_SLOT_COUNT; slotIdx++) {
-            int offset = slotIdx * TASK_AREA_SLOT_SIZE;
-            int taskNo = siemensNet.getByteTransform().TransInt32(resultTask.Content, offset);
-            int targetPoint = siemensNet.getByteTransform().TransInt16(resultTask.Content, offset + 6);
-            if (command.getTaskNo().equals(taskNo)
-                    && command.getTargetStaNo().equals(targetPoint)) {
-                return slotIdx;
-            }
-        }
-        return null;
     }
 
     private byte[] readTaskBufferRaw() {

--
Gitblit v1.9.1