黄贺彬 5 ヶ月 前
コミット
84adb28b35

+ 17 - 2
TEAMModelOS.Extension/IES.Exam/IES.ExamServer/Controllers/ManageController.cs

@@ -1,4 +1,6 @@
-using Microsoft.AspNetCore.Mvc;
+using IES.ExamServer.DI;
+using IES.ExamServer.Models;
+using Microsoft.AspNetCore.Mvc;
 using Microsoft.Extensions.Caching.Memory;
 using Microsoft.Extensions.Configuration;
 using System.Net.Http;
@@ -15,12 +17,16 @@ namespace IES.ExamServer.Controllers
         private readonly IHttpClientFactory _httpClientFactory;
         private readonly IMemoryCache _memoryCache;
         private readonly ILogger<ManageController> _logger;
-        public ManageController(ILogger<ManageController> logger, IConfiguration configuration, IHttpClientFactory httpClientFactory, IMemoryCache memoryCache)
+        private readonly LiteDBFactory _liteDBFactory;
+        private readonly ConnectionService _connectionService;
+        public ManageController(LiteDBFactory liteDBFactory,ILogger<ManageController> logger, IConfiguration configuration, IHttpClientFactory httpClientFactory, IMemoryCache memoryCache, ConnectionService connectionService)
         {
             _logger = logger;
             _configuration=configuration;
             _httpClientFactory=httpClientFactory;
             _memoryCache=memoryCache;
+            _liteDBFactory=liteDBFactory;
+            _connectionService=connectionService;
         }
         [HttpPost("download-package")]
         public async Task<IActionResult> DownloadPackage(JsonNode json) 
@@ -28,6 +34,15 @@ namespace IES.ExamServer.Controllers
             //C#.NET 6 后端与前端流式通信
             //https://www.doubao.com/chat/collection/687687510791426?type=Thread
             //下载日志记录:1.步骤,检查,2.获取描述信息,3.分类型,4下载文件,5.前端处理,6.返回结果 , 正在下载...==> https://www.doubao.com/chat/collection/687687510791426?type=Thread  Ok...
+            string shortCode = $"{json["shortCode"]}";
+            if (string.IsNullOrWhiteSpace(shortCode)) 
+            {
+                EvaluationClient evaluationClient =  _liteDBFactory.GetLiteDatabase().GetCollection<EvaluationClient>().FindOne(x=>!string.IsNullOrWhiteSpace(x.shortCode) &&  x.shortCode.Equals(shortCode));
+                if (evaluationClient==null && _connectionService.dataCenterIsConnected) 
+                {
+                
+                }
+            }
             return Ok();
         }
     }

+ 7 - 0
TEAMModelOS.Extension/IES.Exam/IES.ExamServer/DI/ConnectionService.cs

@@ -0,0 +1,7 @@
+namespace IES.ExamServer.DI
+{
+    public class ConnectionService
+    {
+        public bool dataCenterIsConnected  { get; set; }
+    }
+}

+ 3 - 0
TEAMModelOS.Extension/IES.Exam/IES.ExamServer/IES.ExamServer.csproj

@@ -38,6 +38,9 @@
 		<PackageReference Include="VueCliMiddleware" Version="6.0.0" />
 		<PackageReference Include="ZXing.Net.Bindings.ZKWeb.System.Drawing" Version="0.16.7" />
 	</ItemGroup>
+	<ItemGroup>
+	  <ProjectReference Include="..\..\IES.ExamLib\IES.ExamLib.csproj" />
+	</ItemGroup>
 
 	<ItemGroup>
 	  <Content Update="wwwroot">

+ 5 - 1
TEAMModelOS.Extension/IES.Exam/IES.ExamServer/Program.cs

@@ -50,7 +50,8 @@ namespace IES.ExamServer
             };
             builder.Services.AddLiteDB(connections_LiteDB);
             builder.Services.AddMemoryCache();
-          
+            // 注册 ConnectionService 为单例
+            builder.Services.AddSingleton<ConnectionService>();
             builder.Services.AddCors(options =>
             {
                 options.AddDefaultPolicy(
@@ -144,6 +145,9 @@ namespace IES.ExamServer
                 //云端服务连接失败
                 hybrid = 0;
             }
+            //单例模式存储云端数据中心连接状态
+            ConnectionService connectionService=  app.Services.GetRequiredService<ConnectionService>();
+            connectionService.dataCenterIsConnected = hybrid==1?true:false;
             var lifetime = app.Services.GetRequiredService<IHostApplicationLifetime>();
             lifetime.ApplicationStarted.Register(() =>
             {

+ 4 - 0
TEAMModelOS.Extension/IES.ExamLib/Models/EvaluationCommon.cs

@@ -117,6 +117,10 @@ namespace IES.ExamServer.Models
         /// 记录地址
         /// </summary>
         public string? recordUrl { get; set; }
+        /// <summary>
+        /// 激活状态
+        /// </summary>
+        public int activate {  get; set; }
 
     }
     public class SubjectExam

+ 4 - 5
TEAMModelOS.SDK/Models/Service/EvaluationSyncInfoService.cs

@@ -30,7 +30,7 @@ namespace TEAMModelOS.SDK.Models.Service
         /// <param name="type"></param>
         /// <param name="azureCosmos"></param>
         /// <param name="azureStorage"></param>
-        public static async Task PackageEvaluation( string id,string scope, string owner, string type, AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage,CoreAPIHttpService _coreAPIHttpService, DingDing _dingDing)
+        public static async Task<EvaluationSyncInfo> PackageEvaluation( string id,string scope, string owner, string type, AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage,CoreAPIHttpService _coreAPIHttpService, DingDing _dingDing)
         {
             EvaluationSource evaluationSource = new EvaluationSource() { type=type,id=id};
             EvaluationSyncInfo evaluationSyncInfo= null;
@@ -302,13 +302,12 @@ namespace TEAMModelOS.SDK.Models.Service
                     //recordUrl = evaluationSyncInfo.recordUrl
                 };
                 var groupList = new { members = listInfo.rmembers, groupList= listInfo.groups };
-
                 await azureStorage.GetBlobContainerClient(owner).UploadFileByContainer(evaluationSource.ToJsonString(),$"package/{id}", "source.json");
                 await azureStorage.GetBlobContainerClient(owner).UploadFileByContainer(groupList.ToJsonString(), $"package/{id}", "groupList.json");
+                await azureStorage.GetBlobContainerClient(owner).UploadFileByContainer(new { evaluationClient, evaluationExams }.ToJsonString(), $"package/{id}", "evaluation.json");
+                await azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).UpsertItemAsync<EvaluationSyncInfo>(evaluationSyncInfo, new PartitionKey("EvaluationSyncInfo"));
+                return evaluationSyncInfo;
 
-
-
-                
                 // await azureStorage.GetBlobContainerClient(owner).UploadFileByContainer(evaluationSyncInfo.ToJsonString(), $"package/{id}", "syncinfo.json");
             }
         }

+ 8 - 5
TEAMModelOS/Controllers/Both/EvaluationSyncInfoController.cs

@@ -66,7 +66,7 @@ namespace TEAMModelOS.Controllers.Both
                 "type":"Art/Exam"
             }
              */
-
+            List<EvaluationSyncInfo> infos = new List<EvaluationSyncInfo>();
             if (!string.IsNullOrWhiteSpace($"{request["pid"]}")) 
             {
                 //区级发布的活动
@@ -75,7 +75,8 @@ namespace TEAMModelOS.Controllers.Both
                 {
                     foreach (var item in result.list) 
                     {
-                        await EvaluationSyncInfoService.PackageEvaluation(item.id, item.scope, item.school, "Art", _azureCosmos, _azureStorage, _coreAPIHttpService, _dingDing);
+                        EvaluationSyncInfo syncInfo = await EvaluationSyncInfoService.PackageEvaluation(item.id, item.scope, item.school, "Art", _azureCosmos, _azureStorage, _coreAPIHttpService, _dingDing);
+                        infos.Add(syncInfo);
                     }
                 }
             }
@@ -85,12 +86,14 @@ namespace TEAMModelOS.Controllers.Both
                 ValidResult validResult = activity.Valid();
                 if (!validResult.isVaild) 
                 {
-                    await EvaluationSyncInfoService.PackageEvaluation(activity.id, activity.scope, activity.owner, activity.type, _azureCosmos, _azureStorage, _coreAPIHttpService,_dingDing);
+                    
                     return BadRequest(validResult);
                 }
-                
+
+                EvaluationSyncInfo syncInfo = await EvaluationSyncInfoService.PackageEvaluation(activity.id, activity.scope, activity.owner, activity.type, _azureCosmos, _azureStorage, _coreAPIHttpService, _dingDing);
+                infos.Add(syncInfo);
             }
-            return Ok();
+            return Ok(new { infos });
         }
     }
 }