Ver código fonte

历史数据修复以及签到逻辑

zhouj1203@hotmail.com 3 anos atrás
pai
commit
207d460d9b

+ 29 - 0
TEAMModelOS.SDK/Models/Service/FixDataService.cs

@@ -614,5 +614,34 @@ namespace TEAMModelOS.SDK.Models.Service
 
             return ids;
         }
+
+
+        public static async Task<List<string>> FixSchoolType(CosmosClient client, JsonElement data, DingDing _dingDing, CoreAPIHttpService _coreAPIHttpService, Option _option)
+        {
+            List<Task<ItemResponse<School>>> tasks = new List<Task<ItemResponse<School>>>();
+            List<School> info = new List<School>() ;
+            try
+            {              
+                await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<School>(queryText: $"SELECT value(c) FROM c ",requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
+                {
+                    info.Add(item);
+                }
+                foreach (var item in info)
+                {
+                    foreach (var period in item.period) { 
+                    
+                    }
+                    tasks.Add(client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync<School>(item, item.id, new PartitionKey(item.code)));
+                }
+                //TODO 数据量过大的时候暂未处理
+                await Task.WhenAll(tasks);
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"OS,{_option.Location} /fix-data/fix-type \n {ex.Message}{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
+            }
+            var ids = info.Select(x => x.id).ToList();
+            return ids;
+        }
     }
 }

+ 18 - 8
TEAMModelOS/Controllers/Common/StudyController.cs

@@ -172,14 +172,15 @@ namespace TEAMModelOS.Controllers.Common
                     var sJson = await JsonDocument.ParseAsync(sresponse.ContentStream);
                     Study study = sJson.ToObject<Study>();
                     if (response.Status == (int)HttpStatusCode.OK)
-                    {                       
+                    {
                         var json = await JsonDocument.ParseAsync(response.ContentStream);
-                        StudyRecord record = json.ToObject<StudyRecord>();                        
+                        StudyRecord record = json.ToObject<StudyRecord>();
                         if (!string.IsNullOrEmpty(record.sign))
                         {
                             return Ok(new { code = 200, msg = "已经签到" });
                         }
-                        else {
+                        else
+                        {
                             record.sign = study.startTime < now ? "2" : "1";
                             record.signTime = now;
                         }
@@ -187,14 +188,15 @@ namespace TEAMModelOS.Controllers.Common
 
                     }
                     else
-                    {                       
+                    {
                         StudyRecord setting = new();
                         setting.id = id.GetString();
-                        setting.tId = tmdid;                       
+                        setting.tId = tmdid;
                         setting.signTime = now;
                         setting.code = "StudyRecord-" + tmdid;
                         setting.sign = study.startTime < now ? "2" : "1";
-                        if (string.IsNullOrEmpty(setting.sign) || setting.signTime == 0) {
+                        if (string.IsNullOrEmpty(setting.sign) || setting.signTime == 0)
+                        {
                             return Ok(new { code = 500, msg = "签到失败,请重新签到" });
                         }
                         await client.GetContainer("TEAMModelOS", "Teacher").CreateItemAsync(setting, new PartitionKey($"{setting.code}"));
@@ -204,14 +206,22 @@ namespace TEAMModelOS.Controllers.Common
                 {
                     return Ok(new { code = HttpStatusCode.NotFound });
                 }
+                var srecord = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemStreamAsync(id.ToString(), new PartitionKey($"StudyRecord-{tmdid}"));
+                if (srecord.Status == (int)HttpStatusCode.OK)
+                {
+                    return Ok();
+                }
+                else
+                {
+                    return Ok(new { code = 500, msg = "签到失败,请重新签到" });
+                }
 
-                return Ok();
             }
             catch (Exception ex)
             {
                 await _dingDing.SendBotMsg($"OS,{_option.Location},study/sign-in()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
                 return BadRequest();
-            }
+            }          
 
         }
 

+ 9 - 0
TEAMModelOS/Controllers/XTest/FixDataController.cs

@@ -1355,6 +1355,15 @@ namespace TEAMModelOS.Controllers
             List<string> infos = await FixDataService.FixExamClassResult(client, data, _dingDing, _coreAPIHttpService, _option);
             return Ok(new { infos });
         }
+        [ProducesDefaultResponseType]
+        //[AuthToken(Roles = "teacher")]
+        [HttpPost("fix-school-type")]
+        public async Task<IActionResult> FixSchoolType(JsonElement data)
+        {
+            var client = _azureCosmos.GetCosmosClient();
+            List<string> infos = await FixDataService.FixSchoolType(client, data, _dingDing, _coreAPIHttpService, _option);
+            return Ok(new { infos });
+        }
 
         [ProducesDefaultResponseType]
         //[AuthToken(Roles = "teacher")]