From b690250002ee04f4309e6a90fd16fbfd9bd959e2 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期五, 01 五月 2026 23:11:23 +0800
Subject: [PATCH] feat(router): 添加托盘操作页面路由

---
 Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoRepository/RobotStateRepository.cs |   86 +++++++++++++++++++++++++++++-------------
 1 files changed, 59 insertions(+), 27 deletions(-)

diff --git a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoRepository/RobotStateRepository.cs b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoRepository/RobotStateRepository.cs
index 012d9ad..26b78d3 100644
--- a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoRepository/RobotStateRepository.cs
+++ b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoRepository/RobotStateRepository.cs
@@ -1,6 +1,7 @@
 using Newtonsoft.Json;
 using SqlSugar;
 using WIDESEAWCS_Core.BaseRepository;
+using WIDESEAWCS_Core.Helper;
 using WIDESEAWCS_ITaskInfoRepository;
 using WIDESEAWCS_Model.Models;
 
@@ -18,7 +19,7 @@
         public Dt_RobotState? GetByIp(string ipAddress)
         {
             return Db.Queryable<Dt_RobotState>()
-                .Where(x => x.IPAddress == ipAddress)
+                .Where(x => x.IpAddress == ipAddress)
                 .First();
         }
 
@@ -32,7 +33,7 @@
 
             var newState = new Dt_RobotState
             {
-                IPAddress = ipAddress,
+                IpAddress = ipAddress,
                 Version = DateTime.UtcNow.Ticks,
                 RobotCraneJson = JsonConvert.SerializeObject(robotCrane),
                 CreateDate = DateTime.Now,
@@ -47,10 +48,24 @@
         {
             newState.ModifyDate = DateTime.Now;
 
-            // 涔愯閿侊細WHERE IPAddress = @ip AND Version = @expectedVersion锛岀増鏈尮閰嶆墠鏇存柊
-            var affectedRows = Db.Updateable<Dt_RobotState>(newState)
-                .Where(x => x.IPAddress == ipAddress && x.Version == expectedVersion)
-                .ExecuteCommand();
+            // SqlSugar 鐨� Updateable(entity).Where(x => x.Version == param) 瀛樺湪鍙傛暟娣锋穯闂锛�
+            // 瀹炰綋鐨� Version 宸茶璁句负 expectedVersion+1锛�.Where() 涓� SqlSugar 鍙兘浣跨敤瀹炰綋鐨�
+            // Version 鍊硷紙expectedVersion+1锛夎�岄潪鍙傛暟鍊硷紙expectedVersion锛夛紝瀵艰嚧 WHERE 姘歌繙鍖归厤涓嶄笂銆�
+            // 淇锛氬皢鐗堟湰鏍¢獙鎷嗕负鐙珛鏌ヨ锛屾洿鏂颁粎閫氳繃涓婚敭鎵ц銆�
+
+            // 姝ラ1锛氭牎楠岀増鏈彿鏄惁涓庢湡鏈涗竴鑷�
+            var currentVersion = Db.Queryable<Dt_RobotState>()
+                .Where(x => x.IpAddress == ipAddress)
+                .Select(x => x.Version)
+                .First();
+
+            if (currentVersion != expectedVersion)
+            {
+                return false;
+            }
+
+            // 姝ラ2锛氱増鏈尮閰嶏紝閫氳繃涓婚敭鐩存帴鏇存柊
+            var affectedRows = Db.Updateable(newState).ExecuteCommand();
 
             return affectedRows > 0;
         }
@@ -59,7 +74,7 @@
         {
             var state = new RobotSocketState
             {
-                IPAddress = entity.IPAddress,
+                IPAddress = entity.IpAddress,
                 Version = entity.Version,
                 IsEventSubscribed = entity.IsEventSubscribed,
                 RobotRunMode = entity.RobotRunMode,
@@ -75,13 +90,19 @@
                 CurrentBatchIndex = entity.CurrentBatchIndex,
                 ChangePalletPhase = entity.ChangePalletPhase,
                 IsScanNG = entity.IsScanNG,
-                BatteryArrived = entity.BatteryArrived
+                BatteryArrived = entity.BatteryArrived,
+                CurrentTaskNum = entity.CurrentTaskNum,
             };
 
             // 鍙嶅簭鍒楀寲澶嶆潅 JSON 瀛楁
             if (!string.IsNullOrEmpty(entity.RobotCraneJson))
             {
                 state.RobotCrane = JsonConvert.DeserializeObject<RobotCraneDevice>(entity.RobotCraneJson);
+            }
+
+            if (!string.IsNullOrEmpty(entity.CurrentBatchBarcodes))
+            {
+                state.CurrentBatchBarcodes = JsonConvert.DeserializeObject<List<string>>(entity.CurrentBatchBarcodes) ?? new List<string>();
             }
 
             if (!string.IsNullOrEmpty(entity.CurrentTaskJson))
@@ -111,7 +132,7 @@
         {
             var entity = new Dt_RobotState
             {
-                IPAddress = state.IPAddress,
+                IpAddress = state.IPAddress,
                 IsEventSubscribed = state.IsEventSubscribed,
                 RobotRunMode = state.RobotRunMode,
                 RobotControlMode = state.RobotControlMode,
@@ -126,7 +147,13 @@
                 CurrentBatchIndex = state.CurrentBatchIndex,
                 ChangePalletPhase = state.ChangePalletPhase,
                 IsScanNG = state.IsScanNG,
-                BatteryArrived = state.BatteryArrived
+                BatteryArrived = state.BatteryArrived,
+                CellBarcodeJson = state.CellBarcode.ToJson(),
+                LastPickPositionsJson = state.LastPickPositions.ToJson(),
+                CurrentTaskJson = state.CurrentTask.ToJson(),
+                LastPutPositionsJson = state.LastPutPositions.ToJson(),
+                CurrentBatchBarcodes = state.CurrentBatchBarcodes.ToJson(),
+                CurrentTaskNum = state.CurrentTaskNum,
             };
 
             // 搴忓垪鍖栧鏉傚璞′负 JSON
@@ -135,27 +162,32 @@
                 entity.RobotCraneJson = JsonConvert.SerializeObject(state.RobotCrane);
             }
 
-            if (state.CurrentTask != null)
-            {
-                entity.CurrentTaskJson = JsonConvert.SerializeObject(state.CurrentTask);
-            }
+            //if (state.CurrentTask != null)
+            //{
+            //    entity.CurrentTaskJson = JsonConvert.SerializeObject(state.CurrentTask);
+            //}
 
-            if (state.LastPickPositions != null)
-            {
-                entity.LastPickPositionsJson = JsonConvert.SerializeObject(state.LastPickPositions);
-            }
+            //if (state.LastPickPositions != null)
+            //{
+            //    entity.LastPickPositionsJson = JsonConvert.SerializeObject(state.LastPickPositions);
+            //}
 
-            if (state.LastPutPositions != null)
-            {
-                entity.LastPutPositionsJson = JsonConvert.SerializeObject(state.LastPutPositions);
-            }
+            //if (state.LastPutPositions != null)
+            //{
+            //    entity.LastPutPositionsJson = JsonConvert.SerializeObject(state.LastPutPositions);
+            //}
 
-            if (state.CellBarcode != null && state.CellBarcode.Count > 0)
-            {
-                entity.CellBarcodeJson = JsonConvert.SerializeObject(state.CellBarcode);
-            }
+            //if (state.CellBarcode != null && state.CellBarcode.Count > 0)
+            //{
+            //    entity.CellBarcodeJson = JsonConvert.SerializeObject(state.CellBarcode);
+            //}
+
+            //if (state.CurrentBatchBarcodes != null && state.CurrentBatchBarcodes.Count > 0)
+            //{
+            //    entity.CurrentBatchBarcodes = JsonConvert.SerializeObject(state.CurrentBatchBarcodes);
+            //}
 
             return entity;
         }
     }
-}
+}
\ No newline at end of file

--
Gitblit v1.9.3