فهرست منبع

调整研修接口、处理结算异常、调整多个API

zhouj1203@hotmail.com 3 سال پیش
والد
کامیت
fe62e968a5

+ 3 - 5
TEAMModelOS.SDK/Models/Cosmos/Common/Study.cs

@@ -43,7 +43,7 @@ namespace TEAMModelOS.SDK.Models
         /// 发布对象全部信息。由前端操作,用于前端回显发布对象的格式。
         /// </summary>
         public List<JsonElement> targets { get; set; } = new List<JsonElement>();
-        public List<Setting> teachers { get; set; } = new List<Setting>();
+        //public List<Setting> teachers { get; set; } = new List<Setting>();
         public string progress { get; set; }
         public string scope { get; set; }
         public int? status { get; set; } = 0;
@@ -67,17 +67,15 @@ namespace TEAMModelOS.SDK.Models
         public string surveyId { get; set; }
         public string examId { get; set; }
     }
-    public class Setting
+    /*public class Setting
     {
         public string id { get; set; }
         public string name { get; set; }
         public string groupName { get; set; }
         public string sign { get; set; }
         public long signTime { get; set; }
-/*        public string hw { get; set; }
-        public long hwTime { get; set; }*/
         //0未审核 1 通过 2 未通过
         public int status { get; set; }
         public long aTime { get; set; }
-    }
+    }*/
 }

+ 20 - 0
TEAMModelOS.SDK/Models/Cosmos/Teacher/StudyRecord.cs

@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace TEAMModelOS.SDK.Models.Cosmos.Teacher
+{
+    public class StudyRecord : CosmosEntity
+    {
+        public StudyRecord() {
+            pk = "StudyRecord";
+        }
+        public string tId { get; set; }
+        public string school { get; set; }
+        public string sign { get; set; }
+        public long signTime { get; set; }
+        //0未审核 1 通过 2 未通过
+        public int status { get; set; }
+        public long aTime { get; set; }
+    }
+}

+ 23 - 0
TEAMModelOS.SDK/Models/Service/ExamService.cs

@@ -2,6 +2,7 @@ using Azure.Cosmos;
 using System;
 using System.Collections.Generic;
 using System.Text;
+using System.Text.Json;
 using System.Threading.Tasks;
 using TEAMModelOS.SDK.DI;
 
@@ -35,6 +36,28 @@ namespace TEAMModelOS.SDK.Models.Service
                 return classes;
             }
         }
+        public static async Task deleteAsync(CosmosClient client, string id, string tId)
+        {
+            List<string> correctIds = new List<string>();
+            await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIterator(queryText: $"select c.id from c where c.cid = '{id}' ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"CorrectTask-{tId}") }))
+            {
+                using var jsonTask = await JsonDocument.ParseAsync(item.ContentStream);
+                if (jsonTask.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                {
+                    var accounts = jsonTask.RootElement.GetProperty("Documents").EnumerateArray();
+                    while (accounts.MoveNext())
+                    {
+                        JsonElement account = accounts.Current;
+                        correctIds.Add(account.GetProperty("id").GetString());
+                    }
+                }
+            }
+            if (correctIds.Count > 0)
+            {
+                await client.GetContainer(Constant.TEAMModelOS, "Teacher").DeleteItemsStreamAsync(correctIds, $"CorrectTask-{tId}");
+
+            }
+        }
         public static async Task<string> saveMoreAsync(CosmosClient client, DingDing _dingDing, ExamLite trExam)
         {
             try

+ 17 - 6
TEAMModelOS/Controllers/Analysis/AnalysisController.cs

@@ -1471,17 +1471,28 @@ namespace TEAMModelOS.Controllers.Analysis
                 {
                     for (int i = range.range[0]; i <= range.range[1]; i++)
                     {
-                        if (result.studentScores[i][num] < point) {
-                            if (result.studentScores[i][num] < p)
+                        if (result.studentScores[i].Count > 0)
+                        {
+                            if (result.studentScores[i][num] < point)
                             {
-                                wnum++;
+                                if (result.studentScores[i][num] < p)
+                                {
+                                    wnum++;
+                                }
+                                else
+                                {
+                                    continue;
+                                }
                             }
-                            else {
+                            else
+                            {
                                 continue;
                             }
-                        } else {
-                            continue;
                         }
+                        else {
+                            wnum++;
+                        }
+                        
                         
                     }
                 }

+ 38 - 20
TEAMModelOS/Controllers/Common/AreaController.cs

@@ -19,6 +19,7 @@ using TEAMModelOS.SDK.DI.AzureCosmos.Inner;
 using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Models;
 using TEAMModelOS.SDK.Models.Cosmos.Common;
+using TEAMModelOS.SDK.Models.Cosmos.Teacher;
 using TEAMModelOS.SDK.Models.Service;
 
 namespace TEAMModelOS.Controllers
@@ -335,7 +336,7 @@ namespace TEAMModelOS.Controllers
                             homework.targetType = "research";
                             //homework.blob = $"/{homework.areaId}/survey/{study.pId}/index.json";
                             await getMoreWork(pa, homework);
-                            string workId = await HomeworkService.saveMoreAsync(client, _dingDing, homework,_serviceBus,_azureStorage,_configuration);
+                            string workId = await HomeworkService.saveMoreAsync(client, _dingDing, homework, _serviceBus, _azureStorage, _configuration);
                             if (string.IsNullOrEmpty(workId))
                             {
                                 return Ok(new { code = (int)HttpStatusCode.BadRequest, msg = "作业活动异常" });
@@ -430,7 +431,7 @@ namespace TEAMModelOS.Controllers
                 List<(string id, string name)> ps = await getInfo(client, areaId.GetString());
                 //List<string> aName = new();
                 var query = $"select value(c) from c where c.pId = '{id}'";
-                foreach ((string code,string name) in baseIds)
+                foreach ((string code, string name) in baseIds)
                 {
                     await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryIterator<Study>(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Study-{code}") }))
                     {
@@ -447,6 +448,7 @@ namespace TEAMModelOS.Controllers
                     (List<RMember> tchList, List<RGroupList> classInfos) = await GroupListService.GetStutmdidListids(client, _dingDing, study.tchLists, study.school);
                     // (List<TmdInfo> tmdInfos, List<ClassListInfo> classInfos) = await TriggerStuActivity.GetTchList(client, _dingDing, ids, $"{school}");
                     //(List<TmdInfo> tchList, _) = await TriggerStuActivity.GetTchList(client, _dingDing, study.tchLists, study.school);
+
                     if (!string.IsNullOrEmpty(study.surveyId))
                     {
 
@@ -480,6 +482,22 @@ namespace TEAMModelOS.Controllers
                     }
                     moreInfo.Add((tchList, study));
                 };
+                //提取研修相关老师活动记录
+                List<StudyRecord> records = new();
+                foreach (var (teac, stu) in moreInfo)
+                {
+                    foreach (var member in teac)
+                    {
+                        var response = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemStreamAsync(id.ToString(), new PartitionKey($"StudyRecord-{member.id}"));
+                        if (response.Status == (int)HttpStatusCode.OK)
+                        {
+                            var json = await JsonDocument.ParseAsync(response.ContentStream);
+                            StudyRecord record = json.ToObject<StudyRecord>();
+                            records.Add(record);
+                        }
+                    }
+
+                }
                 var survey = trSurveys.Select(s => new
                 {
                     count = s.teac.Count,
@@ -501,11 +519,11 @@ namespace TEAMModelOS.Controllers
                     name = ps.FirstOrDefault(c => c.id == s.stu.id).name,
                     count = s.teac.Count,
                     //hwCount = s.teachers.Where(h => h.hwTime > 0).ToList().Count,
-                    signCount = s.stu.teachers.Where(h => h.signTime > 0).ToList().Count,
-                    lateCount = s.stu.teachers.Where(h => !string.IsNullOrEmpty(h.sign) && h.sign.Equals("1")).ToList().Count,
-                    acount = s.stu.teachers.Where(h => h.aTime > 0).ToList().Count
+                    signCount = records.Where(h => h.signTime > 0).ToList().Count,
+                    lateCount = records.Where(h => !string.IsNullOrEmpty(h.sign) && h.sign.Equals("1")).ToList().Count,
+                    acount = records.Where(h => h.aTime > 0).ToList().Count
                 });
-                return Ok(new { survey, work = twork,exam, info, studies = moreInfo.Select(m => new { m.teac, m.stu }) });
+                return Ok(new { survey, work = twork, exam, info, studies = moreInfo.Select(m => new { m.teac, m.stu }) });
             }
             catch (Exception e)
             {
@@ -568,7 +586,7 @@ namespace TEAMModelOS.Controllers
                 //List<string> aName = new();
                 List<Vote> votes = new List<Vote>();
                 Vote vote = null;
-                List<(string code,string name, string url, int count)> recordUrl = new List<(string code, string name, string url, int count)>();
+                List<(string code, string name, string url, int count)> recordUrl = new List<(string code, string name, string url, int count)>();
                 var response = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemStreamAsync(id.GetString(), new PartitionKey($"Vote-{areaId}"));
                 if (response.Status == 200)
                 {
@@ -590,7 +608,7 @@ namespace TEAMModelOS.Controllers
                                     (List<RMember> tchList, List<RGroupList> classInfos) = await GroupListService.GetStutmdidListids(client, _dingDing, tcs, code);
                                     // (List<TmdInfo> tmdInfos, List<ClassListInfo> classInfos) = await TriggerStuActivity.GetTchList(client, _dingDing, ids, $"{school}");
                                     //(List<TmdInfo> tchList, _) = await TriggerStuActivity.GetTchList(client, _dingDing, tcs, code);
-                                    recordUrl.Add((code,name, account.GetProperty("recordUrl").GetString(), tchList.Count));
+                                    recordUrl.Add((code, name, account.GetProperty("recordUrl").GetString(), tchList.Count));
                                 }
                             }
                         }
@@ -598,7 +616,7 @@ namespace TEAMModelOS.Controllers
                 }
 
                 //var info = ps.Select(p => new { p.id, p.name });
-                return Ok(new { vote, code = recordUrl.Select(r => new { r.code,r.name, r.url, r.count }) });
+                return Ok(new { vote, code = recordUrl.Select(r => new { r.code, r.name, r.url, r.count }) });
             }
             catch (Exception e)
             {
@@ -659,7 +677,7 @@ namespace TEAMModelOS.Controllers
                 List<(string id, string name)> baseIds = await getId(client, areaId.GetString());
                 List<object> surveys = new();
                 Survey survey = null;
-                List<(string code, string name,string url, int count)> recordUrl = new List<(string code, string name,string url, int count)>();
+                List<(string code, string name, string url, int count)> recordUrl = new List<(string code, string name, string url, int count)>();
                 var response = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemStreamAsync(id.GetString(), new PartitionKey($"Survey-{areaId}"));
                 if (response.Status == 200)
                 {
@@ -682,7 +700,7 @@ namespace TEAMModelOS.Controllers
                                     // (List<TmdInfo> tmdInfos, List<ClassListInfo> classInfos) = await TriggerStuActivity.GetTchList(client, _dingDing, ids, $"{school}");
                                     //(List<TmdInfo> tchList, _) = await TriggerStuActivity.GetTchList(client, _dingDing, tcs, code);
 
-                                    recordUrl.Add((code, name,account.GetProperty("recordUrl").GetString(), tchList.Count));
+                                    recordUrl.Add((code, name, account.GetProperty("recordUrl").GetString(), tchList.Count));
                                 }
                             }
                         }
@@ -690,7 +708,7 @@ namespace TEAMModelOS.Controllers
                 }
 
                 //var info = ps.Select(p => new { p.id, p.name });
-                return Ok(new { survey, code = recordUrl.Select(r => new { r.code,r.name, r.url, r.count }) });
+                return Ok(new { survey, code = recordUrl.Select(r => new { r.code, r.name, r.url, r.count }) });
             }
             catch (Exception e)
             {
@@ -1061,13 +1079,13 @@ namespace TEAMModelOS.Controllers
                     }
                     await getMoreSurvey(pa, trSurvey);
 
-                        trSurvey.id = Guid.NewGuid().ToString();
-                        trSurvey.recordUrl = $"/survey/{trSurvey.id}/record.json";
-                        var cods = new { records = new List<string>(), userids = new List<string>(), question = new List<QuestionRecord>() };
-                        await _azureStorage.UploadFileByContainer(code, cods.ToJsonString(), "survey", $"{trSurvey.id}/record.json");
-                        // trSurvey.blob = SurveyService.getBlob(trSurvey.id);
-                        await client.GetContainer("TEAMModelOS", "Common").UpsertItemAsync(trSurvey, new PartitionKey($"{trSurvey.code}"));
-                    
+                    trSurvey.id = Guid.NewGuid().ToString();
+                    trSurvey.recordUrl = $"/survey/{trSurvey.id}/record.json";
+                    var cods = new { records = new List<string>(), userids = new List<string>(), question = new List<QuestionRecord>() };
+                    await _azureStorage.UploadFileByContainer(code, cods.ToJsonString(), "survey", $"{trSurvey.id}/record.json");
+                    // trSurvey.blob = SurveyService.getBlob(trSurvey.id);
+                    await client.GetContainer("TEAMModelOS", "Common").UpsertItemAsync(trSurvey, new PartitionKey($"{trSurvey.code}"));
+
                     surveys.Add(trSurvey);
                 }
                 //areaSurvey.targets = allName;
@@ -1187,7 +1205,7 @@ namespace TEAMModelOS.Controllers
         private async Task<List<(string id, string name)>> getId(CosmosClient client, string id)
         {
             //获取区级以下所有学校编码和基础信息
-            List<(string id,string name)> baseIds = new();
+            List<(string id, string name)> baseIds = new();
             await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: $"select c.id,c.name from c where c.areaId = '{id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
             {
                 using var json = await JsonDocument.ParseAsync(item.ContentStream);

+ 5 - 5
TEAMModelOS/Controllers/Common/ExamController.cs

@@ -333,21 +333,21 @@ namespace TEAMModelOS.Controllers
                             {
                                 foreach (var marker in sub.markers)
                                 {
-                                    await deleteAsync(client, id.GetString(), marker.id);
+                                    await ExamService.deleteAsync(client, id.GetString(), marker.id);
                                 }
                             }
                             if (sub.err.Count > 0)
                             {
                                 foreach (var tId in sub.err)
                                 {
-                                    await deleteAsync(client, id.GetString(), tId);
+                                    await ExamService.deleteAsync(client, id.GetString(), tId);
                                 }
                             }
                             if (sub.arb.Count > 0)
                             {
                                 foreach (var tId in sub.arb)
                                 {
-                                    await deleteAsync(client, id.GetString(), tId);
+                                    await ExamService.deleteAsync(client, id.GetString(), tId);
                                 }
                             }
                         }
@@ -2928,7 +2928,7 @@ namespace TEAMModelOS.Controllers
             }
         }
 
-        private async Task deleteAsync(CosmosClient client, string id, string tId)
+        /*private async Task deleteAsync(CosmosClient client, string id, string tId)
         {
             List<string> correctIds = new List<string>();
             await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIterator(queryText: $"select c.id from c where c.cid = '{id}' ", requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"CorrectTask-{tId}") }))
@@ -2948,7 +2948,7 @@ namespace TEAMModelOS.Controllers
             {
                 await client.GetContainer(Constant.TEAMModelOS, "Teacher").DeleteItemsStreamAsync(correctIds, $"CorrectTask-{tId}");
             }
-        }
+        }*/
         private async Task<(string blob,List<double>)> getMoreStuInfo(CosmosClient client, string stuId, string examId,string subjectId,string code) {
             var queryClass = $"select c.studentAnswers,c.studentIds,c.studentScores from c where array_contains(c.studentIds,'{stuId}') and c.examId = '{examId}' and c.subjectId = '{subjectId}'";
             List<List<string>> ans = new List<List<string>>();

+ 64 - 72
TEAMModelOS/Controllers/Common/StudyController.cs

@@ -15,6 +15,7 @@ using TEAMModelOS.SDK;
 using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
 using TEAMModelOS.SDK.Models;
+using TEAMModelOS.SDK.Models.Cosmos.Teacher;
 
 namespace TEAMModelOS.Controllers.Common
 {
@@ -68,14 +69,7 @@ namespace TEAMModelOS.Controllers.Common
                 study.createTime = now;
                 if (string.IsNullOrEmpty(study.id))
                 {
-                    if (study.startTime > now)
-                    {
-                        study.progress = "pending";
-                    }
-                    else
-                    {
-                        study.progress = "going";
-                    }
+                    study.progress = "going";
                     study.id = Guid.NewGuid().ToString();
                     await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(study, new PartitionKey($"{study.code}"));
                 }
@@ -112,62 +106,53 @@ namespace TEAMModelOS.Controllers.Common
                 if (!request.TryGetProperty("tId", out JsonElement tId)) return BadRequest();
                 var client = _azureCosmos.GetCosmosClient();
                 long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
-                var response = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(id.ToString(), new PartitionKey($"Study-{code}"));
-                if (response.Status == (int)HttpStatusCode.OK)
+                var response = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemStreamAsync(id.ToString(), new PartitionKey($"StudyRecord-{tId}"));
+                var sresponse = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(id.ToString(), new PartitionKey($"Study-{code}"));
+                if (sresponse.Status == (int)HttpStatusCode.OK)
                 {
-                    var json = await JsonDocument.ParseAsync(response.ContentStream);
-                    Study study = json.ToObject<Study>();
-                    //bool flag = false;
-                    bool flag = study.teachers.Exists(s => s.id.Equals(tId.GetString()) && string.IsNullOrEmpty(s.sign));
-                    if (flag)
+                    var sJson = await JsonDocument.ParseAsync(response.ContentStream);
+                    Study study = sJson.ToObject<Study>();
+                    if (response.Status == (int)HttpStatusCode.OK)
                     {
+                        var json = await JsonDocument.ParseAsync(response.ContentStream);
+                        StudyRecord record = json.ToObject<StudyRecord>();
                         if (study.startTime < now)
                         {
-                            foreach (Setting setting in study.teachers)
-                            {
-                                if (setting.id.Equals(tId.GetString()))
-                                {
-                                    setting.sign = "2";
-                                    setting.signTime = now;
-                                }
-                            }
+                            record.sign = "2";
+                            record.signTime = now;
                         }
                         else
                         {
-                            foreach (Setting setting in study.teachers)
-                            {
-                                if (setting.id.Equals(tId.GetString()))
-                                {
-                                    setting.sign = "1";
-                                    setting.signTime = now;
-                                }
-                            }
+                            record.sign = "1";
+                            record.signTime = now;
                         }
+                        await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync(record, record.id, new PartitionKey($"{record.code}"));
                     }
-                    else {
+                    else
+                    {
+                        StudyRecord setting = new();
                         if (study.startTime < now)
                         {
-
-                            Setting setting = new Setting();
                             setting.id = tId.GetString();
                             setting.sign = "2";
                             setting.signTime = now;
-                            study.teachers.Add(setting);
+                            setting.code = "StudyRecord-" + tId.GetString();
                         }
-                        else {
-                            Setting setting = new Setting();
+                        else
+                        {
                             setting.id = tId.GetString();
                             setting.sign = "1";
                             setting.signTime = now;
-                            study.teachers.Add(setting);
+                            setting.code = "StudyRecord-" + tId.GetString();
                         }
+                        await client.GetContainer("TEAMModelOS", "Teacher").CreateItemAsync(setting, new PartitionKey($"{setting.code}"));
                     }
-                    await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(study, study.id, new PartitionKey($"{study.code}"));
                 }
-                else {
-                    return Ok(new { code = HttpStatusCode.NotFound});
+                else
+                {
+                    return Ok(new { code = HttpStatusCode.NotFound });
                 }
-               
+
                 return Ok();
             }
             catch (Exception ex)
@@ -253,10 +238,12 @@ namespace TEAMModelOS.Controllers.Common
                 {
                     using var json = await JsonDocument.ParseAsync(sresponse.ContentStream);
                     Study study = json.ToObject<Study>();
-                    if (!string.IsNullOrEmpty(study.examId)) {
+                    if (!string.IsNullOrEmpty(study.examId))
+                    {
                         await client.GetContainer("TEAMModelOS", "Common").DeleteItemStreamAsync(study.examId, new PartitionKey($"ExamLite-{code}"));
                     }
-                    if (!string.IsNullOrEmpty(study.surveyId)) {
+                    if (!string.IsNullOrEmpty(study.surveyId))
+                    {
                         await client.GetContainer("TEAMModelOS", "Common").DeleteItemStreamAsync(study.surveyId, new PartitionKey($"Survey-{code}"));
                     }
                     if (!string.IsNullOrEmpty(study.workId))
@@ -345,24 +332,37 @@ namespace TEAMModelOS.Controllers.Common
                 if (!requert.TryGetProperty("id", out JsonElement id)) return BadRequest();
                 if (!requert.TryGetProperty("code", out JsonElement code)) return BadRequest();
                 var client = _azureCosmos.GetCosmosClient();
-                List<string> teachers = new List<string>();
                 Study study = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<Study>(id.GetString(), new PartitionKey($"Study-{code}"));
                 if (study != null)
                 {
                     (List<RMember> tchList, List<RGroupList> classInfo) = await GroupListService.GetStutmdidListids(client, _dingDing, study.tchLists, study.school);
+                    List<StudyRecord> records = new();
+
+                    foreach (var member in tchList)
+                    {
+                        var response = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemStreamAsync(id.ToString(), new PartitionKey($"StudyRecord-{member.id}"));
+                        if (response.Status == (int)HttpStatusCode.OK)
+                        {
+                            var json = await JsonDocument.ParseAsync(response.ContentStream);
+                            StudyRecord record = json.ToObject<StudyRecord>();
+                            records.Add(record);
+                        }
+                    }
+
+
                     // (List<TmdInfo> tmdInfos, List<ClassListInfo> classInfos) = await TriggerStuActivity.GetTchList(client, _dingDing, ids, $"{school}");
                     //(List<TmdInfo> tchList, _) = await TriggerStuActivity.GetTchList(client, _dingDing, study.tchLists, study.school);
-                    return Ok(new { study, teachers = tchList.Select(t => t.id).ToList(), status = 200 });
+                    return Ok(new { study, records, status = 200 });
                 }
                 else
                 {
                     return Ok(new { study, status = 404 });
-                }              
+                }
             }
             catch (Exception e)
             {
                 await _dingDing.SendBotMsg($"OS,{_option.Location},study/FindSummary()\n{e.Message}", GroupNames.醍摩豆服務運維群組);
-                return Ok(new {status = 404 });
+                return Ok(new { status = 404 });
             }
 
         }
@@ -445,42 +445,34 @@ namespace TEAMModelOS.Controllers.Common
             try
             {
                 if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
-                if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
+                //if (!request.TryGetProperty("code", out JsonElement code)) return BadRequest();
                 if (!request.TryGetProperty("tId", out JsonElement tId)) return BadRequest();
                 if (!request.TryGetProperty("type", out JsonElement type)) return BadRequest();
                 var client = _azureCosmos.GetCosmosClient();
                 long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
-                var response = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(id.ToString(), new PartitionKey($"Study-{code}"));
+                var response = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemStreamAsync(id.ToString(), new PartitionKey($"StudyRecord-{tId}"));
                 if (response.Status == (int)HttpStatusCode.OK)
                 {
                     var json = await JsonDocument.ParseAsync(response.ContentStream);
-                    Study study = json.ToObject<Study>();
-                    bool flag = study.teachers.Exists(s => s.id.Equals(tId.GetString()));
-                    if (flag)
+                    StudyRecord study = json.ToObject<StudyRecord>();
+                    if (study.id.Equals(tId.GetString()))
                     {
-                        foreach (Setting setting in study.teachers)
-                        {
-                            if (setting.id.Equals(tId.GetString()))
-                            {
-                                setting.status = type.GetInt32();
-                                setting.aTime = now;
-                            }
-                        }
-
-
-                    }
-                    else {
-                        Setting setting = new Setting();
-                        setting.id = tId.GetString();
-                        setting.status = type.GetInt32();
-                        setting.aTime = now;
-                        study.teachers.Add(setting);
+                        study.status = type.GetInt32();
+                        study.aTime = now;
                     }
-                    await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(study, study.id, new PartitionKey($"{study.code}"));
+                    await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync(study, study.id, new PartitionKey($"{study.code}"));
                 }
                 else
                 {
-                    return Ok(new { code = HttpStatusCode.NotFound });
+                    StudyRecord setting = new()
+                    {
+                        id = id.GetString(),
+                        tId = tId.GetString(),
+                        code = "StudyRecord-" + tId.GetString(),
+                        status = type.GetInt32(),
+                        aTime = now
+                    };
+                    await client.GetContainer("TEAMModelOS", "Teacher").CreateItemAsync(setting, new PartitionKey($"{setting.code}"));
                 }
 
                 return Ok(new { code = HttpStatusCode.OK });

+ 75 - 0
TEAMModelOS/Controllers/School/CorrectController.cs

@@ -25,6 +25,7 @@ using TEAMModelOS.SDK.Models.Cosmos.Common.Inner;
 using TEAMModelOS.Services.Common;
 using TEAMModelOS.SDK.Models.Service;
 using Microsoft.Extensions.Configuration;
+using HTEXLib.COMM.Helpers;
 
 namespace TEAMModelOS.Controllers
 {
@@ -275,5 +276,79 @@ namespace TEAMModelOS.Controllers
             }
 
         }
+        [ProducesDefaultResponseType]
+        [HttpPost("delete-task")]
+        public async Task<IActionResult> delete(JsonElement requert)
+        {
+            try
+            {
+
+                //活动id
+                if (!requert.TryGetProperty("id", out JsonElement id)) return BadRequest();
+                //活动分区
+                if (!requert.TryGetProperty("code", out JsonElement code)) return BadRequest();
+                var client = _azureCosmos.GetCosmosClient();
+                List<SDK.Models.Cosmos.Common.Scoring> attr = new();
+                await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<SDK.Models.Cosmos.Common.Scoring>(
+                                    queryText: $"select value(c) from c where c.examId = '{id}'",
+                                    requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Scoring-{code}") }))
+                {
+                    attr.Add(item);
+                }
+                await client.GetContainer(Constant.TEAMModelOS, "Teacher").DeleteItemsAsync<SDK.Models.Cosmos.Common.Scoring>(attr.Select(a =>a.id).ToList(), $"Scoring-{code}");
+                //var cresponse = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemStreamAsync(id.ToString(), new PartitionKey($"Scoring-{code}"));
+                //删除阅卷配置
+                var cresponse = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemStreamAsync(id.ToString(), new PartitionKey($"Correct-{code}"));
+                if (cresponse.Status == 200)
+                {
+                    using var json = await JsonDocument.ParseAsync(cresponse.ContentStream);
+                    Correct correct = json.ToObject<Correct>();
+                    if (correct.subs.IsNotEmpty())
+                    {
+                        foreach (var sub in correct.subs)
+                        {
+                            //List<string> correctIds = new List<string>();
+                            if (sub.markers.IsNotEmpty())
+                            {
+                                foreach (var marker in sub.markers)
+                                {
+                                    await ExamService.deleteAsync(client, id.GetString(), marker.id);
+                                }
+                            }
+                            if (sub.err.Count > 0)
+                            {
+                                foreach (var tId in sub.err)
+                                {
+                                    await ExamService.deleteAsync(client, id.GetString(), tId);
+                                }
+                            }
+                            if (sub.arb.Count > 0)
+                            {
+                                foreach (var tId in sub.arb)
+                                {
+                                    await ExamService.deleteAsync(client, id.GetString(), tId);
+                                }
+                            }
+                        }
+                    }
+                    return Ok(new { correct });
+                }
+                else {
+                    return Ok(new { code = 404});
+                }
+            }
+            catch (CosmosException ex)
+            {
+                Correct correct = null;
+                return Ok(new { correct, status = ex.Status });
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"OS,{_option.Location},common/Correct/find-id()\n{ex.Message}", GroupNames.醍摩豆服務運維群組);
+                Correct correct = null;
+                return Ok(new { correct });
+            }
+
+        }
     }
 }