From f288ccc545f8cc32bc922c96dfb3cab9a1f92ec6 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期一, 20 四月 2026 00:49:55 +0800
Subject: [PATCH] feat: 初始化WMS前端项目并实现基础功能

---
 Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoRepository/RobotStateRepository.cs |   39 +++++++++++++--------------------------
 1 files changed, 13 insertions(+), 26 deletions(-)

diff --git a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoRepository/RobotStateRepository.cs b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoRepository/RobotStateRepository.cs
index d282af4..012d9ad 100644
--- a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoRepository/RobotStateRepository.cs
+++ b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoRepository/RobotStateRepository.cs
@@ -1,7 +1,6 @@
 using Newtonsoft.Json;
 using SqlSugar;
 using WIDESEAWCS_Core.BaseRepository;
-using WIDESEAWCS_Core.UnitOfWork;
 using WIDESEAWCS_ITaskInfoRepository;
 using WIDESEAWCS_Model.Models;
 
@@ -10,20 +9,15 @@
     /// <summary>
     /// 鏈烘鎵嬬姸鎬� SqlSugar 浠撳偍瀹炵幇
     /// </summary>
-    public class RobotStateRepository : IUnitOfWork, IRobotStateRepository
+    public class RobotStateRepository : RepositoryBase<Dt_RobotState>, IRobotStateRepository
     {
-        private readonly IUnitOfWorkManage _unitOfWork;
-        private readonly SqlSugarClient _db;
-
-        public RobotStateRepository(IUnitOfWorkManage unitOfWork)
+        public RobotStateRepository(IUnitOfWorkManage unitOfWork) : base(unitOfWork)
         {
-            _unitOfWork = unitOfWork;
-            _db = unitOfWork.GetDbClient();
         }
 
         public Dt_RobotState? GetByIp(string ipAddress)
         {
-            return _db.Queryable<Dt_RobotState>()
+            return Db.Queryable<Dt_RobotState>()
                 .Where(x => x.IPAddress == ipAddress)
                 .First();
         }
@@ -39,22 +33,23 @@
             var newState = new Dt_RobotState
             {
                 IPAddress = ipAddress,
+                Version = DateTime.UtcNow.Ticks,
                 RobotCraneJson = JsonConvert.SerializeObject(robotCrane),
-                CreateTime = DateTime.Now,
-                UpdateTime = DateTime.Now
+                CreateDate = DateTime.Now,
+                ModifyDate = DateTime.Now
             };
 
-            _db.Insertable(newState).ExecuteCommand();
+            Db.Insertable(newState).ExecuteCommand();
             return newState;
         }
 
-        public bool TryUpdate(string ipAddress, Dt_RobotState newState, byte[] expectedRowVersion)
+        public bool TryUpdate(string ipAddress, Dt_RobotState newState, long expectedVersion)
         {
-            newState.UpdateTime = DateTime.Now;
+            newState.ModifyDate = DateTime.Now;
 
-            var affectedRows = _db.Updateable<Dt_RobotState>(newState)
-                .Where(x => x.IPAddress == ipAddress)
-                .WhereRowVersion(x => x.RowVersion, expectedRowVersion)
+            // 涔愯閿侊細WHERE IPAddress = @ip AND Version = @expectedVersion锛岀増鏈尮閰嶆墠鏇存柊
+            var affectedRows = Db.Updateable<Dt_RobotState>(newState)
+                .Where(x => x.IPAddress == ipAddress && x.Version == expectedVersion)
                 .ExecuteCommand();
 
             return affectedRows > 0;
@@ -65,7 +60,7 @@
             var state = new RobotSocketState
             {
                 IPAddress = entity.IPAddress,
-                Version = BitConverter.ToInt64(entity.RowVersion.Length >= 8 ? entity.RowVersion.Take(8).ToArray() : new byte[8], 0),
+                Version = entity.Version,
                 IsEventSubscribed = entity.IsEventSubscribed,
                 RobotRunMode = entity.RobotRunMode,
                 RobotControlMode = entity.RobotControlMode,
@@ -162,13 +157,5 @@
 
             return entity;
         }
-
-        public SqlSugarClient GetDbClient() => _db;
-
-        public void BeginTran() => _unitOfWork.BeginTran();
-
-        public void CommitTran() => _unitOfWork.CommitTran();
-
-        public void RollbackTran() => _unitOfWork.RollbackTran();
     }
 }

--
Gitblit v1.9.3