From f4d696baffce9c3bd8653a3598eb69f0962a5e92 Mon Sep 17 00:00:00 2001
From: zy <zy@123>
Date: 星期四, 17 七月 2025 13:56:42 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/model/param/UpdateFakeThreadStatusParam.java |   15 +++
 src/main/java/com/zy/core/model/param/GetFakeThreadStatusParam.java    |   13 ++
 src/main/java/com/zy/core/controller/OpenController.java               |   52 ++++++++++
 src/main/webapp/views/index.html                                       |  149 ++++++++++++++++++++++++++++-
 src/main/java/com/zy/core/thread/fake/FakeZyForkLiftThread.java        |   14 ++
 src/main/java/com/zy/core/thread/FakeThread.java                       |    3 
 src/main/java/com/zy/core/thread/fake/FakeNyShuttleThread.java         |   24 ++++
 7 files changed, 262 insertions(+), 8 deletions(-)

diff --git a/src/main/java/com/zy/core/controller/OpenController.java b/src/main/java/com/zy/core/controller/OpenController.java
index a13d9ba..f948742 100644
--- a/src/main/java/com/zy/core/controller/OpenController.java
+++ b/src/main/java/com/zy/core/controller/OpenController.java
@@ -1,10 +1,14 @@
 package com.zy.core.controller;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.zy.common.R;
 import com.zy.core.cache.SlaveConnection;
 import com.zy.core.enums.SlaveType;
 import com.zy.core.model.param.AddFakeDeviceParam;
 import com.zy.core.model.param.DeleteDeviceParam;
+import com.zy.core.model.param.GetFakeThreadStatusParam;
+import com.zy.core.model.param.UpdateFakeThreadStatusParam;
 import com.zy.core.properties.DeviceConfig;
 import com.zy.core.thread.FakeThread;
 import com.zy.core.thread.ForkLiftThread;
@@ -18,6 +22,7 @@
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
 
 @RestController
 @RequestMapping("/open")
@@ -41,8 +46,51 @@
         return R.ok().add(map);
     }
 
-    @GetMapping("/getFakeThreadList")
-    public R getFakeThreadList() {
+    @PostMapping("/updateFakeThreadStatus")
+    public R updateFakeThreadStatus(@RequestBody UpdateFakeThreadStatusParam param) {
+        FakeThread fakeThread = null;
+        if (param.getDeviceType().equals(String.valueOf(SlaveType.Shuttle))) {
+            fakeThread = (FakeThread) SlaveConnection.get(SlaveType.FakeThread, 1);
+        } else if (param.getDeviceType().equals(String.valueOf(SlaveType.ForkLift))) {
+            fakeThread = (FakeThread) SlaveConnection.get(SlaveType.FakeThread, 1);
+        }
+
+        if (fakeThread == null) {
+            return R.error("鎵句笉鍒拌澶囩嚎绋�");
+        }
+
+        boolean result = fakeThread.updateFakeStatus(param);
+        if (result) {
+            return R.ok();
+        }
+        return R.error("鏇存柊澶辫触");
+    }
+
+    @PostMapping("/getFakeThreadStatus")
+    public R getFakeThreadStatus(@RequestBody GetFakeThreadStatusParam param) {
+        FakeThread fakeThread = null;
+        if (param.getDeviceType().equals(String.valueOf(SlaveType.Shuttle))) {
+            fakeThread = (FakeThread) SlaveConnection.get(SlaveType.FakeThread, 1);
+        } else if (param.getDeviceType().equals(String.valueOf(SlaveType.ForkLift))) {
+            fakeThread = (FakeThread) SlaveConnection.get(SlaveType.FakeThread, 1);
+        }
+
+        if (fakeThread == null) {
+            return R.error("鎵句笉鍒拌澶囩嚎绋�");
+        }
+
+        ConcurrentHashMap<String, JSONObject> fakeStatusMap = fakeThread.getFakeStatusMap();
+
+        String key = param.getDeviceType() + param.getDeviceNo();
+        JSONObject result = fakeStatusMap.get(key);
+        if (result == null) {
+            return R.error("鏁版嵁涓嶅瓨鍦�");
+        }
+        return R.ok().add(result);
+    }
+
+    @GetMapping("/getFakeThreadStatusList")
+    public R getFakeThreadStatusList() {
         FakeThread fakeThread1 = (FakeThread) SlaveConnection.get(SlaveType.FakeThread, 1);
         FakeThread fakeThread2 = (FakeThread) SlaveConnection.get(SlaveType.FakeThread, 2);
 
diff --git a/src/main/java/com/zy/core/model/param/GetFakeThreadStatusParam.java b/src/main/java/com/zy/core/model/param/GetFakeThreadStatusParam.java
new file mode 100644
index 0000000..2f57835
--- /dev/null
+++ b/src/main/java/com/zy/core/model/param/GetFakeThreadStatusParam.java
@@ -0,0 +1,13 @@
+package com.zy.core.model.param;
+
+
+import lombok.Data;
+
+@Data
+public class GetFakeThreadStatusParam {
+
+    private Integer deviceNo;
+
+    private String deviceType;
+
+}
diff --git a/src/main/java/com/zy/core/model/param/UpdateFakeThreadStatusParam.java b/src/main/java/com/zy/core/model/param/UpdateFakeThreadStatusParam.java
new file mode 100644
index 0000000..40bf997
--- /dev/null
+++ b/src/main/java/com/zy/core/model/param/UpdateFakeThreadStatusParam.java
@@ -0,0 +1,15 @@
+package com.zy.core.model.param;
+
+
+import lombok.Data;
+
+@Data
+public class UpdateFakeThreadStatusParam {
+
+    private Integer deviceNo;
+
+    private String deviceType;
+
+    private String data;
+
+}
diff --git a/src/main/java/com/zy/core/thread/FakeThread.java b/src/main/java/com/zy/core/thread/FakeThread.java
index a06d946..57095bf 100644
--- a/src/main/java/com/zy/core/thread/FakeThread.java
+++ b/src/main/java/com/zy/core/thread/FakeThread.java
@@ -2,6 +2,7 @@
 
 import com.alibaba.fastjson.JSONObject;
 import com.zy.core.ThreadHandler;
+import com.zy.core.model.param.UpdateFakeThreadStatusParam;
 
 import java.util.concurrent.ConcurrentHashMap;
 
@@ -13,4 +14,6 @@
 
     ConcurrentHashMap<String, JSONObject> getFakeCommandMap();
 
+    boolean updateFakeStatus(UpdateFakeThreadStatusParam param);
+
 }
diff --git a/src/main/java/com/zy/core/thread/fake/FakeNyShuttleThread.java b/src/main/java/com/zy/core/thread/fake/FakeNyShuttleThread.java
index b49aaee..f1ddab6 100644
--- a/src/main/java/com/zy/core/thread/fake/FakeNyShuttleThread.java
+++ b/src/main/java/com/zy/core/thread/fake/FakeNyShuttleThread.java
@@ -3,11 +3,13 @@
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.zy.common.Cools;
+import com.zy.common.R;
 import com.zy.common.SpringUtils;
 import com.zy.common.utils.RedisUtil;
 import com.zy.core.News;
 import com.zy.core.cache.SlaveConnection;
 import com.zy.core.enums.SlaveType;
+import com.zy.core.model.param.UpdateFakeThreadStatusParam;
 import com.zy.core.properties.DeviceConfig;
 import com.zy.core.thread.FakeThread;
 import com.zy.core.thread.impl.NyShuttleThread;
@@ -334,6 +336,15 @@
                     String pathList = body.getString("path");
                     List<JSONObject> list = JSON.parseArray(pathList, JSONObject.class);
                     for (JSONObject path : list) {
+                        while (true) {
+                            JSONObject realFakeStatus = fakeStatusMap.get(key);
+                            Integer errorCode = realFakeStatus.getInteger("errorCode");
+                            if (errorCode > 0) {
+                                continue;
+                            }
+                            break;
+                        }
+
                         String currentCode = fakeStatus.getString("currentCode");
                         JSONObject point = JSON.parseObject(currentCode);
                         point.put("x", path.getInteger("xp"));
@@ -529,4 +540,17 @@
     public ConcurrentHashMap<String, JSONObject> getFakeCommandMap() {
         return this.fakeCommandMap;
     }
+
+    @Override
+    public boolean updateFakeStatus(UpdateFakeThreadStatusParam param) {
+        String key = param.getDeviceType() + param.getDeviceNo();
+        JSONObject result = fakeStatusMap.get(key);
+        if (result == null) {
+            return false;
+        }
+
+        JSONObject newData = JSON.parseObject(param.getData());
+        this.fakeStatusMap.put(key, newData);
+        return true;
+    }
 }
diff --git a/src/main/java/com/zy/core/thread/fake/FakeZyForkLiftThread.java b/src/main/java/com/zy/core/thread/fake/FakeZyForkLiftThread.java
index c26e5ce..1e08662 100644
--- a/src/main/java/com/zy/core/thread/fake/FakeZyForkLiftThread.java
+++ b/src/main/java/com/zy/core/thread/fake/FakeZyForkLiftThread.java
@@ -11,6 +11,7 @@
 import com.zy.core.enums.SlaveType;
 import com.zy.core.model.DeviceCommandMsgModel;
 import com.zy.core.model.DeviceMsgModel;
+import com.zy.core.model.param.UpdateFakeThreadStatusParam;
 import com.zy.core.properties.DeviceConfig;
 import com.zy.core.thread.FakeThread;
 import com.zy.core.thread.impl.ZyForkLiftThread;
@@ -376,4 +377,17 @@
     public ConcurrentHashMap<String, JSONObject> getFakeCommandMap() {
         return this.fakeCommandMap;
     }
+
+    @Override
+    public boolean updateFakeStatus(UpdateFakeThreadStatusParam param) {
+        String key = param.getDeviceType() + param.getDeviceNo();
+        JSONObject result = fakeStatusMap.get(key);
+        if (result == null) {
+            return false;
+        }
+
+        JSONObject newData = JSON.parseObject(param.getData());
+        this.fakeStatusMap.put(key, newData);
+        return true;
+    }
 }
diff --git a/src/main/webapp/views/index.html b/src/main/webapp/views/index.html
index 24726ec..6402c85 100644
--- a/src/main/webapp/views/index.html
+++ b/src/main/webapp/views/index.html
@@ -18,19 +18,20 @@
 
 <body>
 <div id="app" style="display: flex;justify-content: center;flex-wrap: wrap;">
-    <div style="width: 50%;">
+    <div style="width: 40%;">
         <el-card class="box-card">
             <div slot="header" class="clearfix">
                 <span>妯℃嫙璁惧 - {{ systemInfo.gatewayId }}鍙风綉鍏�</span>
-                <el-button style="float: right; padding: 3px 0" type="text" @click="addDeviceVisible = true">娣诲姞璁惧</el-button>
+<!--                <el-button style="float: right; padding: 3px 0" type="text" @click="addDeviceVisible = true">娣诲姞璁惧</el-button>-->
             </div>
 
             <div style="display: flex;flex-wrap: wrap;justify-content: space-between;">
                 <div v-for="item in deviceList" style="width: 49%;margin-top: 20px">
-                    <el-card  class="box-card">
+                    <el-card  class="box-card" >
                         <div slot="header" class="clearfix">
                             <span>{{ item.deviceType }} - {{ item.deviceNo }}</span>
-                            <el-button style="float: right; padding: 3px 0" type="text" @click="delDevice(item)">鍒犻櫎璁惧</el-button>
+<!--                            <el-button style="float: right; padding: 3px 0" type="text" @click="delDevice(item)">鍒犻櫎璁惧</el-button>-->
+                            <el-button style="float: right; padding: 3px 0" type="text" @click="setCurrentDeviceConfig(item)">鐘舵��</el-button>
                         </div>
 
                         <div>
@@ -45,6 +46,58 @@
         </el-card>
     </div>
 
+    <div v-if="currentDeviceConfig != null" style="width: 30%;margin-left: 30px;">
+        <el-card class="box-card">
+            <div slot="header" class="clearfix">
+                <span>妯℃嫙璁惧鐘舵��</span>
+            </div>
+
+            <div style="display: flex;flex-wrap: wrap;justify-content: space-between;">
+                <div v-if="currentDeviceData != null" style="width: 100%;margin-top: 20px">
+                    <el-card class="box-card" >
+                        <div slot="header" class="clearfix">
+                            <span>{{ currentDeviceData.deviceType }} - {{ currentDeviceData.deviceNo }}</span>
+                            <el-button v-if="currentDeviceDataForm == null" style="float: right; padding: 3px 0" type="text" @click="updateCurrentDeviceStatus(currentDeviceData)">鏇存柊鐘舵��</el-button>
+                            <el-button v-else style="float: right; padding: 3px 0" type="text" @click="submitUpdateCurrentDeviceStatus(currentDeviceDataForm)">鎻愪氦鏇存柊</el-button>
+                        </div>
+
+                        <div v-if="currentDeviceDataForm == null">
+                            <div>妯″紡: {{ currentDeviceData.data.mode }}</div>
+                            <div>鐘舵��: {{ currentDeviceData.data.deviceStatus }}</div>
+                            <div>椤跺崌: {{ currentDeviceData.data.hasLift }}</div>
+                            <div>鎵樼洏: {{ currentDeviceData.data.hasPallet }}</div>
+                            <div>鍧愭爣: {{ currentDeviceData.data.currentCode }}</div>
+                            <div>寮傚父: {{ currentDeviceData.data.errorCode }}</div>
+                            <div>鍏呯數: {{ currentDeviceData.data.hasCharge }}</div>
+                            <div>鐢甸噺: {{ currentDeviceData.data.batteryPower }}</div>
+                            <div>鐢靛帇: {{ currentDeviceData.data.batteryVoltage }}</div>
+                            <div>杩愯鏂瑰悜: {{ currentDeviceData.data.runDirection }}</div>
+                            <div>閫熷害: {{ currentDeviceData.data.speed }}</div>
+                        </div>
+
+                        <div v-else>
+                            <div>妯″紡: <el-input v-model="currentDeviceDataForm.data.mode"></el-input></div>
+                            <div>鐘舵��: <el-input v-model="currentDeviceDataForm.data.deviceStatus"></el-input></div>
+                            <div>椤跺崌: <el-input v-model="currentDeviceDataForm.data.hasLift"></el-input></div>
+                            <div>鎵樼洏: <el-input v-model="currentDeviceDataForm.data.hasPallet"></el-input></div>
+                            <div>鍧愭爣: <el-input v-model="currentDeviceDataForm.data.currentCode"></el-input></div>
+                            <div>寮傚父: <el-input v-model="currentDeviceDataForm.data.errorCode"></el-input></div>
+                            <div>鍏呯數: <el-input v-model="currentDeviceDataForm.data.hasCharge"></el-input></div>
+                            <div>鐢甸噺: <el-input v-model="currentDeviceDataForm.data.batteryPower"></el-input></div>
+                            <div>鐢靛帇: <el-input v-model="currentDeviceDataForm.data.batteryVoltage"></el-input></div>
+                            <div>杩愯鏂瑰悜: <el-input v-model="currentDeviceDataForm.data.runDirection"></el-input></div>
+                            <div>閫熷害: <el-input v-model="currentDeviceDataForm.data.speed"></el-input></div>
+                        </div>
+
+                        <div>
+                            鍘熷鏁版嵁锛�
+                            {{ currentDeviceData }}
+                        </div>
+                    </el-card>
+                </div>
+            </div>
+        </el-card>
+    </div>
 
     <el-dialog title="娣诲姞妯℃嫙璁惧" :visible.sync="addDeviceVisible">
         <el-form :model="addDeviceParam">
@@ -88,7 +141,10 @@
                 gatewayPort: 0
             },
             formLabelWidth: '120px',
-            deviceList: []
+            deviceList: [],
+            currentDeviceConfig: null,
+            currentDeviceData: null,
+            currentDeviceDataForm: null
         },
         created() {
             this.init()
@@ -99,7 +155,8 @@
 
                 setInterval(() => {
                     this.getDeviceList()
-                }, 100);
+                    this.getFakeThreadStatus()
+                }, 1000);
             },
             getSystemInfo() {
                 let that = this;
@@ -125,6 +182,86 @@
                     }
                 });
             },
+            setCurrentDeviceConfig(deviceConfig) {
+                this.currentDeviceConfig = deviceConfig
+                this.currentDeviceDataForm = null;
+            },
+            updateCurrentDeviceStatus(currentDeviceData) {
+                if (this.currentDeviceDataForm == null) {
+                    this.currentDeviceDataForm = currentDeviceData;
+                }else {
+                    this.currentDeviceDataForm = null;
+                }
+            },
+            submitUpdateCurrentDeviceStatus(currentDeviceDataForm) {
+                let that = this;
+                $.ajax({
+                    url: baseUrl + "/open/updateFakeThreadStatus",
+                    headers: {
+                        'token': localStorage.getItem('token')
+                    },
+                    data: JSON.stringify({
+                        deviceType: currentDeviceDataForm.deviceType,
+                        deviceNo: currentDeviceDataForm.deviceNo,
+                        data: JSON.stringify(currentDeviceDataForm.data)
+                    }),
+                    dataType: 'json',
+                    contentType: 'application/json;charset=UTF-8',
+                    method: 'POST',
+                    success: function (res) {
+                        if (res.code == 200) {
+                            that.currentDeviceDataForm = null;
+                            that.$message({
+                                message: res.msg,
+                                type: 'success'
+                            });
+                        } else {
+                            that.$message({
+                                message: res.msg,
+                                type: 'error'
+                            });
+                        }
+                    }
+                });
+            },
+            getFakeThreadStatus() {
+                let that = this;
+                if (this.currentDeviceConfig == null) {
+                    return;
+                }
+
+                $.ajax({
+                    url: baseUrl + "/open/getFakeThreadStatus",
+                    headers: {
+                        'token': localStorage.getItem('token')
+                    },
+                    data: JSON.stringify({
+                        deviceType: this.currentDeviceConfig.deviceType,
+                        deviceNo: this.currentDeviceConfig.deviceNo
+                    }),
+                    dataType: 'json',
+                    contentType: 'application/json;charset=UTF-8',
+                    method: 'POST',
+                    success: function (res) {
+                        if (res.code == 200) {
+                            let data = res.data;
+                            let result = {
+                                deviceType: that.currentDeviceConfig.deviceType,
+                                deviceNo: that.currentDeviceConfig.deviceNo,
+                                data: data
+                            }
+
+                            that.currentDeviceData = result
+                        } else {
+                            that.currentDeviceConfig = null;
+                            that.$message({
+                                message: res.msg,
+                                type: 'error'
+                            });
+                        }
+                    }
+                });
+            },
             addDevice() {
                 //娣诲姞璁惧
                 let that = this;

--
Gitblit v1.9.1