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_Tasks/RobotJob/RobotStateManager.cs | 34 +++++++++++++++-------------------
1 files changed, 15 insertions(+), 19 deletions(-)
diff --git a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotStateManager.cs b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotStateManager.cs
index 028305d..4aaae62 100644
--- a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotStateManager.cs
+++ b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotStateManager.cs
@@ -1,6 +1,5 @@
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
-using WIDESEAWCS_Common;
using WIDESEAWCS_Core.LogHelper;
using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_Model.Models;
@@ -12,7 +11,7 @@
/// </summary>
/// <remarks>
/// 鏍稿績鍔熻兘鏄�氳繃 IRobotStateRepository 绠$悊鏁版嵁搴撲腑鐨勬満姊版墜鐘舵�併��
- /// 鎻愪緵涔愯骞跺彂鎺у埗锛岄�氳繃 RowVersion 闃叉骞跺彂鏇存柊鏃剁殑鏁版嵁瑕嗙洊闂銆�
+ /// 鎻愪緵涔愯骞跺彂鎺у埗锛岄�氳繃 Version 瀛楁闃叉骞跺彂鏇存柊鏃剁殑鏁版嵁瑕嗙洊闂銆�
/// </remarks>
public class RobotStateManager
{
@@ -38,11 +37,11 @@
}
/// <summary>
- /// 瀹夊叏鏇存柊 RobotSocketState 缂撳瓨锛岄槻姝㈠苟鍙戣鐩�
+ /// 瀹夊叏鏇存柊 RobotSocketState锛岄槻姝㈠苟鍙戣鐩�
/// </summary>
/// <remarks>
- /// 浣跨敤涔愯骞跺彂妯″紡锛氬厛璇诲彇褰撳墠 RowVersion锛屾墽琛屾洿鏂版椂妫�鏌ョ増鏈槸鍚︿竴鑷淬��
- /// 濡傛灉 RowVersion 涓嶅尮閰嶏紙璇存槑鏈夊叾浠栫嚎绋嬪凡鏇存柊锛夛紝鍒欐洿鏂板け璐ヨ繑鍥� false銆�
+ /// 浣跨敤涔愯骞跺彂妯″紡锛氬厛璇诲彇褰撳墠 Version锛屾墽琛屾洿鏂版椂妫�鏌ョ増鏈槸鍚︿竴鑷淬��
+ /// 濡傛灉 Version 涓嶅尮閰嶏紙璇存槑鏈夊叾浠栫嚎绋嬪凡鏇存柊锛夛紝鍒欐洿鏂板け璐ヨ繑鍥� false銆�
/// </remarks>
/// <param name="ipAddress">璁惧 IP 鍦板潃</param>
/// <param name="updateAction">鏇存柊鐘舵�佺殑濮旀墭鍑芥暟锛屼紶鍏ュ綋鍓嶇姸鎬佸壇鏈紝杩斿洖淇敼鍚庣殑鏂扮姸鎬�</param>
@@ -57,8 +56,8 @@
return false;
}
- // 璁板綍褰撳墠瀛樺偍鐨� RowVersion锛屼綔涓烘洿鏂版椂鐨勬湡鏈涚増鏈�
- var expectedRowVersion = currentEntity.RowVersion;
+ // 璁板綍褰撳墠瀛樺偍鐨� Version锛屼綔涓烘洿鏂版椂鐨勬湡鏈涚増鏈�
+ var expectedVersion = currentEntity.Version;
// 鍒涘缓鐘舵�佺殑娣辨嫹璐濆壇鏈紙浣跨敤 JSON 搴忓垪鍖栧疄鐜帮級
var stateCopy = CloneState(_repository.ToSocketState(currentEntity));
@@ -68,12 +67,12 @@
// 灏嗘柊鐘舵�佽浆鎹负鏁版嵁搴撳疄浣�
var newEntity = _repository.ToEntity(newState);
- newEntity.RowVersion = Array.Empty<byte>(); // SqlSugar 浼氳嚜鍔ㄧ鐞�
newEntity.Id = currentEntity.Id;
+ newEntity.Version = expectedVersion + 1; // 鐗堟湰鑷
- // 璋冪敤浠撳偍鐨勫畨鍏ㄦ洿鏂版柟娉曪紝浼犲叆鏈熸湜 RowVersion
- // 濡傛灉 RowVersion 涓嶄竴鑷达紙宸茶鍏朵粬绾跨▼鏇存柊锛夛紝鍒欐洿鏂板け璐�
- return _repository.TryUpdate(ipAddress, newEntity, expectedRowVersion);
+ // 璋冪敤浠撳偍鐨勫畨鍏ㄦ洿鏂版柟娉曪紝浼犲叆鏈熸湜 Version
+ // 濡傛灉 Version 涓嶄竴鑷达紙宸茶鍏朵粬绾跨▼鏇存柊锛夛紝鍒欐洿鏂板け璐�
+ return _repository.TryUpdate(ipAddress, newEntity, expectedVersion);
}
/// <summary>
@@ -94,29 +93,26 @@
// 濡傛灉褰撳墠涓嶅瓨鍦ㄨ璁惧鐨勭姸鎬侊紝鍒涘缓鏂拌褰�
if (currentEntity == null)
{
- var entity = _repository.ToEntity(newState);
- entity.CreateTime = DateTime.Now;
- entity.UpdateTime = DateTime.Now;
_repository.GetOrCreate(newState.IPAddress, newState.RobotCrane ?? new RobotCraneDevice());
_logger.LogDebug("TryUpdateStateSafely锛氬垱寤烘柊鐘舵�侊紝IP: {IpAddress}", ipAddress);
QuartzLogger.Debug($"鍒涘缓鏂扮姸鎬侊紝IP: {ipAddress}", ipAddress);
return true;
}
- // 褰撳墠瀛樺湪鐘舵�侊紝璁板綍鏈熸湜 RowVersion 鐢ㄤ簬涔愯閿佹鏌�
- var expectedRowVersion = currentEntity.RowVersion;
+ // 褰撳墠瀛樺湪鐘舵�侊紝璁板綍鏈熸湜 Version 鐢ㄤ簬涔愯閿佹鏌�
+ var expectedVersion = currentEntity.Version;
// 灏嗘柊鐘舵�佽浆鎹负鏁版嵁搴撳疄浣�
var newEntity = _repository.ToEntity(newState);
newEntity.Id = currentEntity.Id;
- newEntity.RowVersion = Array.Empty<byte>();
+ newEntity.Version = expectedVersion + 1; // 鐗堟湰鑷
// 灏濊瘯瀹夊叏鏇存柊锛屽鏋滅増鏈啿绐佸垯杩斿洖 false
- bool success = _repository.TryUpdate(ipAddress, newEntity, expectedRowVersion);
+ bool success = _repository.TryUpdate(ipAddress, newEntity, expectedVersion);
if (!success)
{
- _logger.LogWarning("TryUpdateStateSafely锛氱増鏈啿绐侊紝鏇存柊澶辫触锛孖P: {IpAddress}锛屾湡鏈涚増鏈瓧鑺傞暱搴�: {ExpectedLength}", ipAddress, expectedRowVersion.Length);
+ _logger.LogWarning("TryUpdateStateSafely锛氱増鏈啿绐侊紝鏇存柊澶辫触锛孖P: {IpAddress}锛屾湡鏈涚増鏈�: {ExpectedVersion}", ipAddress, expectedVersion);
QuartzLogger.Warn($"鐗堟湰鍐茬獊锛屾洿鏂板け璐ワ紝IP: {ipAddress}", ipAddress);
}
--
Gitblit v1.9.3