From fdac93d134fa471bf4afb304407f506ba9e3a324 Mon Sep 17 00:00:00 2001
From: schangxiang@126.com <schangxiang@126.com>
Date: 周三, 02 4月 2025 19:02:34 +0800
Subject: [PATCH] 考虑并发的情况

---
 Api/Entity/AuthorizeFunRetEntity.cs        |   10 +++++-----
 Api/Controllers/WareAuthorizeController.cs |   19 ++++++++++++++++++-
 2 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/Api/Controllers/WareAuthorizeController.cs b/Api/Controllers/WareAuthorizeController.cs
index 747d139..9d480af 100644
--- a/Api/Controllers/WareAuthorizeController.cs
+++ b/Api/Controllers/WareAuthorizeController.cs
@@ -7,6 +7,10 @@
     [Route("[controller]")]
     public class WareAuthorizeController : ControllerBase
     {
+
+        private static bool isRuning_Fun_MianAgvFun = false;
+        private static readonly SemaphoreSlim semaphore_MianAgvFun = new SemaphoreSlim(1, 1);
+
         private readonly ILogger<WareAuthorizeController> _logger;
 
         public WareAuthorizeController(ILogger<WareAuthorizeController> logger)
@@ -20,10 +24,18 @@
         /// <param name="input"></param>
         /// <returns></returns>
         [HttpGet(Name = "ValidateLicense")]
-        public AuthorizeFunRetEntity ValidateLicense([FromQuery] ValidateLicenseInput input)
+        public async Task<AuthorizeFunRetEntity> ValidateLicense([FromQuery] ValidateLicenseInput input)
         {
+            if (isRuning_Fun_MianAgvFun)
+            {
+                //认为是验证成功,不要并发导致读取授权文件失败
+                return AuthorizeFunRetEntity.Success("成功", null);
+            }
             try
             {
+                await semaphore_MianAgvFun.WaitAsync();
+                isRuning_Fun_MianAgvFun = true;
+
                 //if (input == null)
                 //{
                 //    return AuthorizeFunRetEntity.Fail("参数不能为空");
@@ -39,6 +51,11 @@
             {
                 return AuthorizeFunRetEntity.Fail("异常:" + ex.Message);
             }
+            finally
+            {
+                semaphore_MianAgvFun.Release();
+                isRuning_Fun_MianAgvFun = false;
+            }
         }
     }
 }
\ No newline at end of file
diff --git a/Api/Entity/AuthorizeFunRetEntity.cs b/Api/Entity/AuthorizeFunRetEntity.cs
index 928135f..69ab548 100644
--- a/Api/Entity/AuthorizeFunRetEntity.cs
+++ b/Api/Entity/AuthorizeFunRetEntity.cs
@@ -71,11 +71,11 @@
                 result = true,
                 resMsg = _resMsg,
 
-                expiryDate = newFun.expiryDate,
-                issueDate = newFun.issueDate,
-                macAddress = newFun.macAddress,
-                projectId = newFun.projectId,
-                type = newFun.type
+                expiryDate = newFun?.expiryDate,
+                issueDate = newFun?.issueDate,
+                macAddress = newFun?.macAddress,
+                projectId = newFun?.projectId,
+                type = newFun?.type
             };
         }
         /// <summary>

--
Gitblit v1.9.3