소스 검색

解决并统一处理serviceBus中间表pk

zhouj1203@hotmail.com 3 년 전
부모
커밋
2c3445f127

+ 14 - 11
TEAMModelFunction/TriggerCorrect.cs

@@ -40,9 +40,11 @@ namespace TEAMModelFunction
             }
             await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}阅卷配置【{tdata.name}-{tdata.id}-ttl={tdata.ttl}】正在执行", GroupNames.成都开发測試群組);
             Correct correct = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<Correct>(input.Id, new Azure.Cosmos.PartitionKey($"{tdata.code}"));
-            List<ChangeRecord> correctRecords = await _azureStorage.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", input.Id }, { "PartitionKey", correct.progress } });
+            
             if (correct != null)
             {
+                string PartitionKey = string.Format("{0}{1}{2}", correct.code, "-", correct.progress);
+                List<ChangeRecord> correctRecords = await _azureStorage.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", input.Id }, { "PartitionKey", PartitionKey } });
                 switch (correct.progress)
                 {
                     case "pending":
@@ -61,7 +63,7 @@ namespace TEAMModelFunction
                             ChangeRecord changeRecord = new ChangeRecord
                             {
                                 RowKey = input.Id,
-                                PartitionKey = "pending",
+                                PartitionKey = PartitionKey,
                                 sequenceNumber = start,
                                 msgId = messageCorrect.MessageId
                             };
@@ -69,6 +71,11 @@ namespace TEAMModelFunction
                         }
                         break;
                     case "going":
+                        //评测id
+                        string eid = correct.id;
+                        //评测的分区键
+                        string ecode = correct.scode;
+                        ExamInfo info = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ExamInfo>(input.Id, new Azure.Cosmos.PartitionKey($"{ecode}"));
                         if (correct.subs.IsNotEmpty())
                         {
 
@@ -110,7 +117,8 @@ namespace TEAMModelFunction
                                             //模块数
                                             model = sub.model,
                                             type = 1,
-                                            createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
+                                            createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
+                                            source = info.source
                                         };
                                         await client.GetContainer(Constant.TEAMModelOS, "Teacher").UpsertItemAsync<CorrectTask>(task, new Azure.Cosmos.PartitionKey(task.code));
                                     }
@@ -199,16 +207,11 @@ namespace TEAMModelFunction
 
 
                                 }
-                                //调用本次考试所涉及的所有已经作答的数据 并生成阅卷池,存入redis
-                                //评测id
-                                string eid = correct.id;
-                                //评测的分区键
-                                string ecode = correct.scode;
                                 //评测科目
                                 string subjectId = sub.id;
                                 //生成临时作答数据存放到redis
-                                var redisClient = _azureRedis.GetRedisClient(8);
-                                ExamInfo info = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ExamInfo>(eid, new Azure.Cosmos.PartitionKey(ecode));
+                                //var redisClient = _azureRedis.GetRedisClient(8);
+                                //ExamInfo info = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ExamInfo>(eid, new Azure.Cosmos.PartitionKey(ecode));
                                 List<ExamClassResult> classResults = new List<ExamClassResult>();
                                 //获取原题配分
                                 int paperIndex = 0;
@@ -342,7 +345,7 @@ namespace TEAMModelFunction
                             ChangeRecord changeRecord = new ChangeRecord
                             {
                                 RowKey = input.Id,
-                                PartitionKey = "going",
+                                PartitionKey = PartitionKey,
                                 sequenceNumber = end,
                                 msgId = messageCorrectEnd.MessageId
                             };

+ 396 - 388
TEAMModelFunction/TriggerExam.cs

@@ -23,490 +23,498 @@ namespace TEAMModelFunction
         public static async void Trigger(AzureCosmosFactory _azureCosmos, AzureServiceBusFactory _serviceBus, AzureStorageFactory _azureStorage, DingDing _dingDing,
             CosmosClient client, Document input, string code, long stime, long etime, string school)
         {
-            ExamInfo info = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ExamInfo>(input.Id, new Azure.Cosmos.PartitionKey($"{code}"));
+
             List<ExamClassResult> examClassResults = new List<ExamClassResult>();
             List<ExamSubject> examSubjects = new List<ExamSubject>();
             try
             {
-                if (info.scope.Equals("teacher", StringComparison.OrdinalIgnoreCase) || info.scope.Equals("private", StringComparison.OrdinalIgnoreCase))
+                ExamInfo info = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ExamInfo>(input.Id, new Azure.Cosmos.PartitionKey($"{code}"));
+                if (info != null)
                 {
-                    await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryStreamIterator(queryText: $"select value(c) from c where c.examId = '{info.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"ExamClassResult-{info.creatorId}") }))
+                    if (info.scope.Equals("teacher", StringComparison.OrdinalIgnoreCase) || info.scope.Equals("private", StringComparison.OrdinalIgnoreCase))
                     {
-                        using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                        if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                        await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryStreamIterator(queryText: $"select value(c) from c where c.examId = '{info.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"ExamClassResult-{info.creatorId}") }))
                         {
-                            foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
+                            using var json = await JsonDocument.ParseAsync(item.ContentStream);
+                            if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
                             {
-                                examClassResults.Add(obj.ToObject<ExamClassResult>());
+                                foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
+                                {
+                                    examClassResults.Add(obj.ToObject<ExamClassResult>());
+                                }
                             }
                         }
                     }
-                }
-                else
-                {
-                    await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryStreamIterator(queryText: $"select value(c) from c where c.examId = '{info.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"ExamClassResult-{school}") }))
+                    else
                     {
-                        using var json = await JsonDocument.ParseAsync(item.ContentStream);
-                        if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                        await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryStreamIterator(queryText: $"select value(c) from c where c.examId = '{info.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"ExamClassResult-{school}") }))
                         {
-                            foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
+                            using var json = await JsonDocument.ParseAsync(item.ContentStream);
+                            if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
                             {
-                                examClassResults.Add(obj.ToObject<ExamClassResult>());
+                                foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
+                                {
+                                    examClassResults.Add(obj.ToObject<ExamClassResult>());
+                                }
                             }
                         }
                     }
-                }
 
-
-                List<ChangeRecord> records = await _azureStorage.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", input.Id }, { "PartitionKey", info.progress } });
-                //处理科目信息
-                List<string> sub = new List<string>();
-                foreach (ExamSubject subject in info.subjects)
-                {
-                    sub.Add(subject.id);
-                }
-                //ChangeRecord record = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ChangeRecord>(input.Id, new Azure.Cosmos.PartitionKey($"{info.progress}"));
-                switch (info.progress)
-                {
-                    case "pending":
-                        var message = new ServiceBusMessage(new { id = input.Id, progress = "going", code = code }.ToJsonString());
-                        message.ApplicationProperties.Add("name", "Exam");
-                        if (records.Count > 0)
-                        {
-                            await _serviceBus.GetServiceBusClient().cancelMessage(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), records[0].sequenceNumber);
-                            long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), message, DateTimeOffset.FromUnixTimeMilliseconds(stime));
-                            records[0].sequenceNumber = start;
-                            await _azureStorage.SaveOrUpdate<ChangeRecord>(records[0]);
-                            //await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(record, record.id, new Azure.Cosmos.PartitionKey($"{record.code}"));
-                        }
-                        else
-                        {
-                            long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), message, DateTimeOffset.FromUnixTimeMilliseconds(stime));
-                            ChangeRecord changeRecord = new ChangeRecord
+                    string PartitionKey = string.Format("{0}{1}{2}", info.code, "-", info.progress);
+                    List<ChangeRecord> records = await _azureStorage.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", input.Id }, { "PartitionKey", PartitionKey } });
+                    //处理科目信息
+                    List<string> sub = new List<string>();
+                    foreach (ExamSubject subject in info.subjects)
+                    {
+                        sub.Add(subject.id);
+                    }
+                    //ChangeRecord record = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<ChangeRecord>(input.Id, new Azure.Cosmos.PartitionKey($"{info.progress}"));
+                    switch (info.progress)
+                    {
+                        case "pending":
+                            var message = new ServiceBusMessage(new { id = input.Id, progress = "going", code = code }.ToJsonString());
+                            message.ApplicationProperties.Add("name", "Exam");
+                            if (records.Count > 0)
                             {
-                                RowKey = input.Id,
-                                PartitionKey = "pending",
-                                sequenceNumber = start,
-                                msgId = message.MessageId
-                            };
-                            await _azureStorage.Save<ChangeRecord>(changeRecord);
-                            //await client.GetContainer(Constant.TEAMModelOS, "Common").CreateItemAsync(changeRecord, new Azure.Cosmos.PartitionKey($"{changeRecord.code}"));
-                        }
-                        break;
-                    case "going":
-                        List<string> classes = ExamService.getClasses(info.classes,info.stuLists);
-                        (List<TmdInfo> tmdids, List<StuInfo> studentss,List<ClassListInfo> classLists) = await TriggerStuActivity.GetStuList(client, _dingDing, classes, info.school);
-                        List<StuActivity> stuActivities = new List<StuActivity>();
-                        List<StuActivity> tmdActivities = new List<StuActivity>();
-                        try
-                        {
-                            if (tmdids.IsNotEmpty())
+                                await _serviceBus.GetServiceBusClient().cancelMessage(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), records[0].sequenceNumber);
+                                long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), message, DateTimeOffset.FromUnixTimeMilliseconds(stime));
+                                records[0].sequenceNumber = start;
+                                await _azureStorage.SaveOrUpdate<ChangeRecord>(records[0]);
+                                //await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(record, record.id, new Azure.Cosmos.PartitionKey($"{record.code}"));
+                            }
+                            else
                             {
-                                tmdids.ForEach(x =>
+                                long start = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), message, DateTimeOffset.FromUnixTimeMilliseconds(stime));
+                                //string pk = String.Format("{0}{1}{2}", info.code, "-", "pending");
+                                ChangeRecord changeRecord = new ChangeRecord
                                 {
-                                    tmdActivities.Add(new StuActivity
-                                    {
-                                        pk = "Activity",
-                                        id = info.id,
-                                        code = $"Activity-{x.id}",
-                                        type = "Exam",
-                                        name = info.name,
-                                        source = info.source,
-                                        startTime = info.startTime,
-                                        endTime = info.endTime,
-                                        scode = info.code,
-                                        scope = info.scope,
-                                        school = info.school,
-                                        creatorId = info.creatorId,
-                                        subjects = sub,
-                                        blob = null,
-                                        owner = info.owner,
-                                        createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
-                                        taskStatus = -1,
-                                        classIds = classes
-
-                                    });
-                                });
+                                    RowKey = input.Id,
+                                    PartitionKey = PartitionKey,
+                                    sequenceNumber = start,
+                                    msgId = message.MessageId
+                                };
+                                await _azureStorage.Save<ChangeRecord>(changeRecord);
+                                //await client.GetContainer(Constant.TEAMModelOS, "Common").CreateItemAsync(changeRecord, new Azure.Cosmos.PartitionKey($"{changeRecord.code}"));
                             }
-                            if (studentss.IsNotEmpty())
+                            break;
+                        case "going":
+
+                            try
                             {
-                                studentss.ForEach(x =>
+                                List<string> classes = ExamService.getClasses(info.classes, info.stuLists);
+                                (List<TmdInfo> tmdids, List<StuInfo> studentss, List<ClassListInfo> classLists) = await TriggerStuActivity.GetStuList(client, _dingDing, classes, info.school);
+                                List<StuActivity> stuActivities = new List<StuActivity>();
+                                List<StuActivity> tmdActivities = new List<StuActivity>();
+                                if (tmdids.IsNotEmpty())
                                 {
-                                    stuActivities.Add(new StuActivity
+                                    tmdids.ForEach(x =>
                                     {
-                                        pk = "Activity",
-                                        id = info.id,
-                                        code = $"Activity-{x.code.Replace("Base-", "")}-{x.id}",
-                                        type = "Exam",
-                                        name = info.name,
-                                        source = info.source,
-                                        startTime = info.startTime,
-                                        endTime = info.endTime,
-                                        scode = info.code,
-                                        scope = info.scope,
-                                        school = info.school,
-                                        creatorId = info.creatorId,
-                                        subjects = sub,
-                                        blob = null,
-                                        owner = info.owner,
-                                        classIds = classes,
-                                        createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
-                                        taskStatus = -1
+                                        tmdActivities.Add(new StuActivity
+                                        {
+                                            pk = "Activity",
+                                            id = info.id,
+                                            code = $"Activity-{x.id}",
+                                            type = "Exam",
+                                            name = info.name,
+                                            source = info.source,
+                                            startTime = info.startTime,
+                                            endTime = info.endTime,
+                                            scode = info.code,
+                                            scope = info.scope,
+                                            school = info.school,
+                                            creatorId = info.creatorId,
+                                            subjects = sub,
+                                            blob = null,
+                                            owner = info.owner,
+                                            createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
+                                            taskStatus = -1,
+                                            classIds = classes
+
+                                        });
                                     });
-                                });
-                            }
-                            await TriggerStuActivity.SaveStuActivity(client, _dingDing, stuActivities, tmdActivities,null);
-                            //向学生或醍摩豆账号发起通知
-                            #region
-                            //Notice notice = new Notice()
-                            //{
-                            //    msgId = info.id,
-                            //    creation = info.startTime,
-                            //    expire = info.endTime,
-                            //    creatorId = info.creatorId,
-                            //    stuids = studentss,
-                            //    tmdids = tmdids,
-                            //    type = "notice",//评测参加通知
-                            //    priority = "normal",
-                            //    school = info.school,
-                            //    scope = info.scope,
-                            //    //data = new { }.ToJsonString()
-                            //    body = new Body { sid = info.id, scode = info.code, spk = info.pk, biztype = "exam-join" }
-
-                            //};
-                            //var messageBlob = new ServiceBusMessage(notice.ToJsonString());
-                            //messageBlob.ApplicationProperties.Add("name", "Notice");
-                            //await _serviceBus.GetServiceBusClient().SendMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageBlob);
-                            #endregion
-                            if (examClassResults.Count == 0)
-                            {
-
-                                foreach (string cla in classes)
+                                }
+                                if (studentss.IsNotEmpty())
                                 {
-                                    int m = 0;
-                                    foreach (ExamSubject subject in info.subjects)
+                                    studentss.ForEach(x =>
                                     {
-                                        string classCode = "";
-                                        if (string.IsNullOrEmpty(info.school) || !info.scope.Equals("school", StringComparison.OrdinalIgnoreCase))
-                                        {
-                                            classCode = "ExamClassResult-" + info.creatorId;
-                                        }
-                                        else
-                                        {
-                                            classCode = "ExamClassResult-" + info.school;
-                                        }
-                                        ExamClassResult result = new ExamClassResult
-                                        {
-                                            code = classCode,
-                                            examId = info.id,
-                                            id = Guid.NewGuid().ToString(),
-                                            subjectId = subject.id,
-                                            year = info.year,
-                                            scope = info.scope
-                                        };
-                                        result.info.id = cla;
-                                        List<string> ans = new List<string>();
-                                        List<List<string>> anses = new List<List<string>>();
-                                        List<List<Details>> marks = new List<List<Details>>();
-                                        List<double> ansPoint = new List<double>();
-                                        List<string> ids = new List<string>();
-                                        foreach (double p in info.papers[m].point)
-                                        {
-                                            //Details details = new Details();
-                                            //ans.Add(new List<string>());
-                                            anses.Add(new List<string>());
-                                            marks.Add(new List<Details>());
-                                            ansPoint.Add(-1);
-                                        }
-                                        var sresponse = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(cla, new Azure.Cosmos.PartitionKey($"Class-{info.school}"));
-                                        if (sresponse.Status == 200)
+                                        stuActivities.Add(new StuActivity
                                         {
+                                            pk = "Activity",
+                                            id = info.id,
+                                            code = $"Activity-{x.code.Replace("Base-", "")}-{x.id}",
+                                            type = "Exam",
+                                            name = info.name,
+                                            source = info.source,
+                                            startTime = info.startTime,
+                                            endTime = info.endTime,
+                                            scode = info.code,
+                                            scope = info.scope,
+                                            school = info.school,
+                                            creatorId = info.creatorId,
+                                            subjects = sub,
+                                            blob = null,
+                                            owner = info.owner,
+                                            classIds = classes,
+                                            createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
+                                            taskStatus = -1
+                                        });
+                                    });
+                                }
+                                await TriggerStuActivity.SaveStuActivity(client, _dingDing, stuActivities, tmdActivities, null);
+                                //向学生或醍摩豆账号发起通知
+                                #region
+                                //Notice notice = new Notice()
+                                //{
+                                //    msgId = info.id,
+                                //    creation = info.startTime,
+                                //    expire = info.endTime,
+                                //    creatorId = info.creatorId,
+                                //    stuids = studentss,
+                                //    tmdids = tmdids,
+                                //    type = "notice",//评测参加通知
+                                //    priority = "normal",
+                                //    school = info.school,
+                                //    scope = info.scope,
+                                //    //data = new { }.ToJsonString()
+                                //    body = new Body { sid = info.id, scode = info.code, spk = info.pk, biztype = "exam-join" }
+
+                                //};
+                                //var messageBlob = new ServiceBusMessage(notice.ToJsonString());
+                                //messageBlob.ApplicationProperties.Add("name", "Notice");
+                                //await _serviceBus.GetServiceBusClient().SendMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageBlob);
+                                #endregion
+                                if (examClassResults.Count == 0)
+                                {
 
-                                            using var json = await JsonDocument.ParseAsync(sresponse.ContentStream);
-                                            Class classroom = json.ToObject<Class>();
-                                            School sc = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(info.school, new Azure.Cosmos.PartitionKey("Base"));
-                                            foreach (Period period in sc.period)
+                                    foreach (string cla in classes)
+                                    {
+                                        int m = 0;
+                                        foreach (ExamSubject subject in info.subjects)
+                                        {
+                                            string classCode = "";
+                                            if (string.IsNullOrEmpty(info.school) || !info.scope.Equals("school", StringComparison.OrdinalIgnoreCase))
+                                            {
+                                                classCode = "ExamClassResult-" + info.creatorId;
+                                            }
+                                            else
+                                            {
+                                                classCode = "ExamClassResult-" + info.school;
+                                            }
+                                            ExamClassResult result = new ExamClassResult
                                             {
-                                                if (period.id.Equals(classroom.periodId))
+                                                code = classCode,
+                                                examId = info.id,
+                                                id = Guid.NewGuid().ToString(),
+                                                subjectId = subject.id,
+                                                year = info.year,
+                                                scope = info.scope
+                                            };
+                                            result.info.id = cla;
+                                            List<string> ans = new List<string>();
+                                            List<List<string>> anses = new List<List<string>>();
+                                            List<List<Details>> marks = new List<List<Details>>();
+                                            List<double> ansPoint = new List<double>();
+                                            List<string> ids = new List<string>();
+                                            foreach (double p in info.papers[m].point)
+                                            {
+                                                //Details details = new Details();
+                                                //ans.Add(new List<string>());
+                                                anses.Add(new List<string>());
+                                                marks.Add(new List<Details>());
+                                                ansPoint.Add(-1);
+                                            }
+                                            var sresponse = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(cla, new Azure.Cosmos.PartitionKey($"Class-{info.school}"));
+                                            if (sresponse.Status == 200)
+                                            {
+
+                                                using var json = await JsonDocument.ParseAsync(sresponse.ContentStream);
+                                                Class classroom = json.ToObject<Class>();
+                                                School sc = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(info.school, new Azure.Cosmos.PartitionKey("Base"));
+                                                foreach (Period period in sc.period)
                                                 {
-                                                    foreach (Semester semester in period.semesters)
+                                                    if (period.id.Equals(classroom.periodId))
                                                     {
-                                                        if (semester.start == 1)
+                                                        foreach (Semester semester in period.semesters)
                                                         {
-                                                            int year = DateTimeOffset.UtcNow.Year;
-                                                            int month = DateTimeOffset.UtcNow.Month;
-                                                            int day = DateTimeOffset.UtcNow.Day;
-                                                            int time = 0;
-                                                            if (month == semester.month)
-                                                            {
-                                                                time = day >= semester.day ? 0 : 1;
-                                                            }
-                                                            else
+                                                            if (semester.start == 1)
                                                             {
-                                                                time = month > semester.month ? 0 : 1;
+                                                                int year = DateTimeOffset.UtcNow.Year;
+                                                                int month = DateTimeOffset.UtcNow.Month;
+                                                                int day = DateTimeOffset.UtcNow.Day;
+                                                                int time = 0;
+                                                                if (month == semester.month)
+                                                                {
+                                                                    time = day >= semester.day ? 0 : 1;
+                                                                }
+                                                                else
+                                                                {
+                                                                    time = month > semester.month ? 0 : 1;
+                                                                }
+                                                                int eyear = year - time;
+                                                                result.gradeId = (eyear - classroom.year).ToString();
                                                             }
-                                                            int eyear = year - time;
-                                                            result.gradeId = (eyear - classroom.year).ToString();
                                                         }
                                                     }
                                                 }
-                                            }
-                                            //result.info.id = classroom.id;
-                                            result.info.name = classroom.name;
-                                            //result.gradeId = classroom.year.ToString();
-                                            //处理班级人数
-                                            await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryStreamIterator(queryText: $"select c.id from c where c.classId = '{classroom.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Base-{info.school}") }))
-                                            {
-                                                using var json_stu = await JsonDocument.ParseAsync(item.ContentStream);
-                                                if (json_stu.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                                                //result.info.id = classroom.id;
+                                                result.info.name = classroom.name;
+                                                //result.gradeId = classroom.year.ToString();
+                                                //处理班级人数
+                                                await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Student").GetItemQueryStreamIterator(queryText: $"select c.id from c where c.classId = '{classroom.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"Base-{info.school}") }))
                                                 {
-                                                    var accounts = json_stu.RootElement.GetProperty("Documents").EnumerateArray();
-                                                    while (accounts.MoveNext())
+                                                    using var json_stu = await JsonDocument.ParseAsync(item.ContentStream);
+                                                    if (json_stu.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
                                                     {
-                                                        JsonElement account = accounts.Current;
-                                                        ids.Add(account.GetProperty("id").GetString());
+                                                        var accounts = json_stu.RootElement.GetProperty("Documents").EnumerateArray();
+                                                        while (accounts.MoveNext())
+                                                        {
+                                                            JsonElement account = accounts.Current;
+                                                            ids.Add(account.GetProperty("id").GetString());
+                                                        }
                                                     }
                                                 }
                                             }
-                                        }
-                                        if (info.scope.Equals("private", StringComparison.OrdinalIgnoreCase))
-                                        {
-                                            var stuResponse = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemStreamAsync(cla, new Azure.Cosmos.PartitionKey($"StuList"));
-                                            if (stuResponse.Status == 200)
+                                            if (info.scope.Equals("private", StringComparison.OrdinalIgnoreCase))
                                             {
-                                                using var json = await JsonDocument.ParseAsync(stuResponse.ContentStream);
-                                                StuList stuList = json.ToObject<StuList>();
-                                                //result.info.id = stuList.id;
-                                                result.info.name = stuList.name;
-                                                //处理发布对象为自选名单(个人)
-
-                                                foreach (Students stus in stuList.students)
+                                                var stuResponse = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemStreamAsync(cla, new Azure.Cosmos.PartitionKey($"StuList"));
+                                                if (stuResponse.Status == 200)
                                                 {
+                                                    using var json = await JsonDocument.ParseAsync(stuResponse.ContentStream);
+                                                    StuList stuList = json.ToObject<StuList>();
+                                                    //result.info.id = stuList.id;
+                                                    result.info.name = stuList.name;
+                                                    //处理发布对象为自选名单(个人)
 
-                                                    if (!ids.Contains(stus.id))
+                                                    foreach (Students stus in stuList.students)
                                                     {
-                                                        ids.Add(stus.id);
+
+                                                        if (!ids.Contains(stus.id))
+                                                        {
+                                                            ids.Add(stus.id);
+                                                        }
                                                     }
-                                                }
-                                                if (stuList.tmids.Count > 0)
-                                                {
-                                                    foreach (string tid in stuList.tmids)
+                                                    if (stuList.tmids.Count > 0)
                                                     {
-                                                        ids.Add(tid);
+                                                        foreach (string tid in stuList.tmids)
+                                                        {
+                                                            ids.Add(tid);
+                                                        }
                                                     }
                                                 }
                                             }
-                                        }
-                                        else
-                                        {
-                                            var stuResponse = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(cla, new Azure.Cosmos.PartitionKey($"StuList-{info.school}"));
-                                            if (stuResponse.Status == 200)
+                                            else
                                             {
-                                                using var json = await JsonDocument.ParseAsync(stuResponse.ContentStream);
-                                                StuList stuList = json.ToObject<StuList>();
-                                                //result.info.id = stuList.id;
-                                                result.info.name = stuList.name;
-                                                //处理发布对象为自选名单(校本)
-                                                foreach (Students stus in stuList.students)
+                                                var stuResponse = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(cla, new Azure.Cosmos.PartitionKey($"StuList-{info.school}"));
+                                                if (stuResponse.Status == 200)
                                                 {
-                                                    if (!ids.Contains(stus.id))
+                                                    using var json = await JsonDocument.ParseAsync(stuResponse.ContentStream);
+                                                    StuList stuList = json.ToObject<StuList>();
+                                                    //result.info.id = stuList.id;
+                                                    result.info.name = stuList.name;
+                                                    //处理发布对象为自选名单(校本)
+                                                    foreach (Students stus in stuList.students)
                                                     {
-                                                        ids.Add(stus.id);
+                                                        if (!ids.Contains(stus.id))
+                                                        {
+                                                            ids.Add(stus.id);
+                                                        }
                                                     }
                                                 }
                                             }
-                                        }
-                                        foreach (string stu in ids)
-                                        {
-                                            result.mark.Add(marks);
-                                            result.studentIds.Add(stu);
-                                            result.studentAnswers.Add(ans);
-                                            result.studentScores.Add(ansPoint);
-                                            result.ans.Add(anses);
-                                            result.sum.Add(0);
-                                        }
+                                            foreach (string stu in ids)
+                                            {
+                                                result.mark.Add(marks);
+                                                result.studentIds.Add(stu);
+                                                result.studentAnswers.Add(ans);
+                                                result.studentScores.Add(ansPoint);
+                                                result.ans.Add(anses);
+                                                result.sum.Add(0);
+                                            }
 
-                                        //result.progress = info.progress;
-                                        result.school = info.school;
-                                        m++;
-                                        await client.GetContainer(Constant.TEAMModelOS, "Common").CreateItemAsync(result, new Azure.Cosmos.PartitionKey($"{result.code}"));
+                                            //result.progress = info.progress;
+                                            result.school = info.school;
+                                            m++;
+                                            await client.GetContainer(Constant.TEAMModelOS, "Common").CreateItemAsync(result, new Azure.Cosmos.PartitionKey($"{result.code}"));
+                                        }
                                     }
-                                }
 
-                                                             
-                            }
-                            else
-                            {
-                                //处理单科结算时科目与试卷信息匹配的问题
-                                int gno = 0;
-                                foreach (ExamSubject subject in info.subjects)
+
+                                }
+                                else
                                 {
-                                    if (subject.classCount == classes.Count)
+                                    //处理单科结算时科目与试卷信息匹配的问题
+                                    int gno = 0;
+                                    foreach (ExamSubject subject in info.subjects)
                                     {
-                                        await createClassResultAsync(info, examClassResults, subject, gno, _azureCosmos, _dingDing, _azureStorage);
+                                        if (subject.classCount == classes.Count)
+                                        {
+                                            await createClassResultAsync(info, examClassResults, subject, gno, _azureCosmos, _dingDing, _azureStorage);
+                                        }
+                                        gno++;
                                     }
-                                    gno++;
                                 }
                             }
-                        }
-                        catch (Exception e)
-                        {
-                            await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测going状态异常{e.Message}\n{e.StackTrace}", GroupNames.成都开发測試群組);
-                        }
-                        finally
-                        {
-                            // 发送信息通知
-                            var messageEnd = new ServiceBusMessage(new { id = input.Id, progress = "finish", code = code }.ToJsonString());
-                            messageEnd.ApplicationProperties.Add("name", "Exam");
-                            if (records.Count > 0)
+                            catch (Exception e)
                             {
-                                long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageEnd, DateTimeOffset.FromUnixTimeMilliseconds(etime));
-                                await _serviceBus.GetServiceBusClient().cancelMessage(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), records[0].sequenceNumber);
-                                records[0].sequenceNumber = end;
-                                await _azureStorage.SaveOrUpdate<ChangeRecord>(records[0]);
-                                //await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(record, record.id, new Azure.Cosmos.PartitionKey($"{record.code}"));
+                                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测going状态异常{e.Message}\n{e.StackTrace}", GroupNames.成都开发測試群組);
                             }
-                            else
+                            finally
                             {
-                                long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageEnd, DateTimeOffset.FromUnixTimeMilliseconds(etime));
-                                ChangeRecord changeRecord = new ChangeRecord
+                                // 发送信息通知
+                                var messageEnd = new ServiceBusMessage(new { id = input.Id, progress = "finish", code = code }.ToJsonString());
+                                messageEnd.ApplicationProperties.Add("name", "Exam");
+                                if (records.Count > 0)
                                 {
-                                    RowKey = input.Id,
-                                    PartitionKey = "going",
-                                    sequenceNumber = end,
-                                    msgId = messageEnd.MessageId
-                                };
-                                await _azureStorage.Save<ChangeRecord>(changeRecord);
-                                //await client.GetContainer(Constant.TEAMModelOS, "Common").CreateItemAsync(changeRecord, new Azure.Cosmos.PartitionKey($"{changeRecord.code}"));
+                                    long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageEnd, DateTimeOffset.FromUnixTimeMilliseconds(etime));
+                                    await _serviceBus.GetServiceBusClient().cancelMessage(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), records[0].sequenceNumber);
+                                    records[0].sequenceNumber = end;
+                                    await _azureStorage.SaveOrUpdate<ChangeRecord>(records[0]);
+                                    //await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(record, record.id, new Azure.Cosmos.PartitionKey($"{record.code}"));
+                                }
+                                else
+                                {
+                                    long end = await _serviceBus.GetServiceBusClient().SendScheduleMessageAsync(Environment.GetEnvironmentVariable("Azure:ServiceBus:ActiveTask"), messageEnd, DateTimeOffset.FromUnixTimeMilliseconds(etime));
+                                    //string pk = String.Format("{0}{1}{2}", info.code, "-", "going");
+                                    ChangeRecord changeRecord = new ChangeRecord
+                                    {
+                                        RowKey = input.Id,
+                                        PartitionKey = PartitionKey,
+                                        sequenceNumber = end,
+                                        msgId = messageEnd.MessageId
+                                    };
+                                    await _azureStorage.Save<ChangeRecord>(changeRecord);
+                                    //await client.GetContainer(Constant.TEAMModelOS, "Common").CreateItemAsync(changeRecord, new Azure.Cosmos.PartitionKey($"{changeRecord.code}"));
+                                }
                             }
-                        }
-                        break;
-                    case "finish":
-                        int fno = 0;
-                        try
-                        {
-                            foreach (ExamSubject subject in info.subjects)
+                            break;
+                        case "finish":
+                            int fno = 0;
+                            try
                             {
-                                await createClassResultAsync(info, examClassResults, subject, fno, _azureCosmos, _dingDing, _azureStorage);
-                                fno++;
-                            }
+                                foreach (ExamSubject subject in info.subjects)
+                                {
+                                    await createClassResultAsync(info, examClassResults, subject, fno, _azureCosmos, _dingDing, _azureStorage);
+                                    fno++;
+                                }
 
-                            //计算单次考试简易统计信息
-                            List<ExamResult> examResults = new List<ExamResult>();
-                            await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<ExamResult>(
-                                               queryText: $"select value(c) from c where c.examId  = '{info.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"ExamResult-{info.id}") }))
-                            {
-                                examResults.Add(item);
-                            }
-                            List<Task<ItemResponse<ExamClassResult>>> tasks = new List<Task<ItemResponse<ExamClassResult>>>();
-                            //结算单科单班的标准差和平均分
-                            foreach (ExamClassResult classResult in examClassResults)
-                            {
-                                //标记单科单班总得分
-                                double subScore = 0;
-                                //标准差
-                                double sPowSum = 0;
-                                var scount = classResult.studentIds.Count;
-                                foreach (List<double> sc in classResult.studentScores)
+                                //计算单次考试简易统计信息
+                                List<ExamResult> examResults = new List<ExamResult>();
+                                await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<ExamResult>(
+                                                   queryText: $"select value(c) from c where c.examId  = '{info.id}'", requestOptions: new QueryRequestOptions() { PartitionKey = new Azure.Cosmos.PartitionKey($"ExamResult-{info.id}") }))
+                                {
+                                    examResults.Add(item);
+                                }
+                                List<Task<ItemResponse<ExamClassResult>>> tasks = new List<Task<ItemResponse<ExamClassResult>>>();
+                                //结算单科单班的标准差和平均分
+                                foreach (ExamClassResult classResult in examClassResults)
                                 {
-                                    List<double> newSc = new List<double>();
-                                    foreach (double ssc in sc)
+                                    //标记单科单班总得分
+                                    double subScore = 0;
+                                    //标准差
+                                    double sPowSum = 0;
+                                    var scount = classResult.studentIds.Count;
+                                    foreach (List<double> sc in classResult.studentScores)
                                     {
-                                        if (ssc == -1)
-                                        {
-                                            newSc.Add(0);
-                                        }
-                                        else
+                                        List<double> newSc = new List<double>();
+                                        foreach (double ssc in sc)
                                         {
-                                            newSc.Add(ssc);
+                                            if (ssc == -1)
+                                            {
+                                                newSc.Add(0);
+                                            }
+                                            else
+                                            {
+                                                newSc.Add(ssc);
+                                            }
                                         }
+                                        subScore += newSc.Sum();
                                     }
-                                    subScore += newSc.Sum();
-                                }
-                                foreach (string sid in classResult.studentIds)
-                                {
-                                    double ssc = classResult.studentScores[classResult.studentIds.IndexOf(sid)].Sum();
-                                    sPowSum += Math.Pow(ssc - scount > 0 ? Math.Round(subScore * 1.0 / scount, 2) : 0, 2);
+                                    foreach (string sid in classResult.studentIds)
+                                    {
+                                        double ssc = classResult.studentScores[classResult.studentIds.IndexOf(sid)].Sum();
+                                        sPowSum += Math.Pow(ssc - scount > 0 ? Math.Round(subScore * 1.0 / scount, 2) : 0, 2);
 
+                                    }
+                                    classResult.standard = Math.Round(scount > 0 ? Math.Pow(sPowSum / scount, 0.5) : 0, 2);
+                                    classResult.average = scount > 0 ? Math.Round(subScore / scount, 2) : 0;
+                                    classResult.progress = true;
+                                    tasks.Add(client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(classResult, classResult.id, new Azure.Cosmos.PartitionKey($"{classResult.code}")));
                                 }
-                                classResult.standard = Math.Round(scount > 0 ? Math.Pow(sPowSum / scount, 0.5) : 0, 2);
-                                classResult.average = scount > 0 ? Math.Round(subScore / scount, 2) : 0;
-                                classResult.progress = true;
-                                tasks.Add(client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync(classResult, classResult.id, new Azure.Cosmos.PartitionKey($"{classResult.code}")));
-                            }
-                            await Task.WhenAll(tasks);
-                            //记录某次考试所有学生得分总分
-                            double score = 0;
-                            double allScore = 0;
-                            int stuCount = 0;
-                            //标准差
-                            double powSum = 0;
-                            List<string> losStu = new List<string>();
-                            //先与第一个值取并集
-                            if (examResults.Count > 0)
-                            {
-                                losStu = losStu.Union(examResults[0].lostStus).ToList();
-                                foreach (ExamResult examResult in examResults)
+                                await Task.WhenAll(tasks);
+                                //记录某次考试所有学生得分总分
+                                double score = 0;
+                                double allScore = 0;
+                                int stuCount = 0;
+                                //标准差
+                                double powSum = 0;
+                                List<string> losStu = new List<string>();
+                                //先与第一个值取并集
+                                if (examResults.Count > 0)
                                 {
-                                    if (info.id == examResult.examId)
+                                    losStu = losStu.Union(examResults[0].lostStus).ToList();
+                                    foreach (ExamResult examResult in examResults)
                                     {
-                                        foreach (List<double> sc in examResult.studentScores)
+                                        if (info.id == examResult.examId)
                                         {
-                                            score += sc.Sum();
+                                            foreach (List<double> sc in examResult.studentScores)
+                                            {
+                                                score += sc.Sum();
+                                            }
+                                            stuCount = examResult.studentIds.Count;
                                         }
-                                        stuCount = examResult.studentIds.Count;
+                                        //powSum += Math.Pow(score - examResult.studentIds.Count > 0 ? Math.Round(score * 1.0 / examResult.studentIds.Count, 2) : 0, 2);
+                                        //取交集
+                                        losStu = losStu.Intersect(examResult.lostStus).ToList();
                                     }
-                                    //powSum += Math.Pow(score - examResult.studentIds.Count > 0 ? Math.Round(score * 1.0 / examResult.studentIds.Count, 2) : 0, 2);
-                                    //取交集
-                                    losStu = losStu.Intersect(examResult.lostStus).ToList();
                                 }
-                            }
-                            double NewsRateScore = stuCount > 0 ? Math.Round(score * 1.0 / stuCount, 2) : 0;
-                            foreach (PaperSimple simple in info.papers)
-                            {
-                                allScore += simple.point.Sum();
-                            }
-                            //计算全科标准差
-                            foreach (string id in examResults[0].studentIds)
-                            {
-                                double sc = 0;
-                                foreach (ExamResult result in examResults)
+                                double NewsRateScore = stuCount > 0 ? Math.Round(score * 1.0 / stuCount, 2) : 0;
+                                foreach (PaperSimple simple in info.papers)
                                 {
-                                    sc += result.studentScores[result.studentIds.IndexOf(id)].Sum();
+                                    allScore += simple.point.Sum();
                                 }
-                                powSum += Math.Pow(sc - NewsRateScore, 2);
-                            }
-                            info.standard = Math.Round(examResults[0].studentIds.Count > 0 ? Math.Pow(powSum / examResults[0].studentIds.Count, 0.5) : 0, 2);
-                            double NewsRate = allScore > 0 ? Math.Round(NewsRateScore / allScore * 100, 2) : 0;
-                            info.lostStu = losStu;
-                            /*//补充历史数据的容器名称
-                            if (string.IsNullOrEmpty(info.cn)) {
-                                if (info.scope.Equals("school"))
+                                //计算全科标准差
+                                foreach (string id in examResults[0].studentIds)
                                 {
-                                    info.cn = info.school;
+                                    double sc = 0;
+                                    foreach (ExamResult result in examResults)
+                                    {
+                                        sc += result.studentScores[result.studentIds.IndexOf(id)].Sum();
+                                    }
+                                    powSum += Math.Pow(sc - NewsRateScore, 2);
                                 }
-                                else {
-                                    info.cn = info.creatorId;
+                                info.standard = Math.Round(examResults[0].studentIds.Count > 0 ? Math.Pow(powSum / examResults[0].studentIds.Count, 0.5) : 0, 2);
+                                double NewsRate = allScore > 0 ? Math.Round(NewsRateScore / allScore * 100, 2) : 0;
+                                info.lostStu = losStu;
+                                /*//补充历史数据的容器名称
+                                if (string.IsNullOrEmpty(info.cn)) {
+                                    if (info.scope.Equals("school"))
+                                    {
+                                        info.cn = info.school;
+                                    }
+                                    else {
+                                        info.cn = info.creatorId;
+                                    }
+                                }*/
+                                //判断均分是否发生变化,便于实时的更新评测基本信息
+                                if (info.sRate != NewsRate || info.average != NewsRateScore)
+                                {
+                                    info.sRate = NewsRate;
+                                    info.average = NewsRateScore;
+                                    await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync<ExamInfo>(info, info.id, new Azure.Cosmos.PartitionKey(info.code));
                                 }
-                            }*/
-                            //判断均分是否发生变化,便于实时的更新评测基本信息
-                            if (info.sRate != NewsRate || info.average != NewsRateScore)
+                            }
+                            catch (Exception e)
                             {
-                                info.sRate = NewsRate;
-                                info.average = NewsRateScore;
-                                await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync<ExamInfo>(info, info.id, new Azure.Cosmos.PartitionKey(info.code));
+                                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测finish状态异常{e.Message}\n{e.StackTrace}", GroupNames.成都开发測試群組);
                             }
-                        }
-                        catch (Exception e)
-                        {
-                            await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测finish状态异常{e.Message}\n{e.StackTrace}", GroupNames.成都开发測試群組);
-                        }
-                        break;
+                            break;
+                    }
                 }
+
             }
             catch (Exception e)
             {
-                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-{info.id}-评测结算异常{e.Message}\n{e.StackTrace}", GroupNames.成都开发測試群組);
+                await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-评测结算异常{e.Message}\n{e.StackTrace}", GroupNames.成都开发測試群組);
             }
 
         }
@@ -527,7 +535,7 @@ namespace TEAMModelFunction
                 //确定低分组 最高分数
                 //scores.Sort((s1, s2) => { return s1.CompareTo(s2); });
                 double rhlCount = Math.Ceiling(scores.Count * 0.73);
-                double rhl = rhlCount > 0 ? scores[int.Parse(rhlCount.ToString("0"))-1] : 0;
+                double rhl = rhlCount > 0 ? scores[int.Parse(rhlCount.ToString("0")) - 1] : 0;
                 //存放高分组学生ID
                 List<string> phId = new List<string>();
                 List<string> plId = new List<string>();
@@ -960,6 +968,6 @@ namespace TEAMModelFunction
 
             await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Common").UpsertItemAsync(result, new Azure.Cosmos.PartitionKey($"ExamResult-{info.id}"));
 
-        }       
+        }
     }
 }

+ 5 - 3
TEAMModelFunction/TriggerExamLite.cs

@@ -39,9 +39,11 @@ namespace TEAMModelFunction
                 }
                 await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}研修评测活动【{tdata.name}-{tdata.id}-ttl={tdata.ttl}】正在操作", GroupNames.成都开发測試群組);
                 ExamLite lite = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<ExamLite>(input.Id, new Azure.Cosmos.PartitionKey($"{tdata.code}"));
-                List<ChangeRecord> changeRecords = await _azureStorage.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", input.Id }, { "PartitionKey", lite.progress } });
+                
                 if (lite != null)
                 {
+                    string PartitionKey = string.Format("{0}{1}{2}", lite.code, "-", lite.progress);
+                    List<ChangeRecord> changeRecords = await _azureStorage.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", input.Id }, { "PartitionKey", PartitionKey } });
                     switch (lite.progress)
                     {
                         case "pending":
@@ -60,7 +62,7 @@ namespace TEAMModelFunction
                                 ChangeRecord changeRecord = new ChangeRecord
                                 {
                                     RowKey = input.Id,
-                                    PartitionKey = "pending",
+                                    PartitionKey = PartitionKey,
                                     sequenceNumber = start,
                                     msgId = messageWork.MessageId
                                 };
@@ -113,7 +115,7 @@ namespace TEAMModelFunction
                                 ChangeRecord changeRecord = new ChangeRecord
                                 {
                                     RowKey = input.Id,
-                                    PartitionKey = "going",
+                                    PartitionKey = PartitionKey,
                                     sequenceNumber = end,
                                     msgId = messageWorkEnd.MessageId
                                 };

+ 5 - 3
TEAMModelFunction/TriggerHomework.cs

@@ -40,9 +40,11 @@ namespace TEAMModelFunction
                 }
                 await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}作业活动【{tdata.name}-{tdata.id}-ttl={tdata.ttl}】正在操作", GroupNames.成都开发測試群組);
                 Homework work = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Homework>(input.Id, new Azure.Cosmos.PartitionKey($"{tdata.code}"));
-                List<ChangeRecord> changeRecords = await _azureStorage.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", input.Id }, { "PartitionKey", work.progress } });
+                
                 if (work != null)
                 {
+                    string PartitionKey = string.Format("{0}{1}{2}", work.code, "-", work.progress);
+                    List<ChangeRecord> changeRecords = await _azureStorage.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", input.Id }, { "PartitionKey", PartitionKey } });
                     switch (work.progress)
                     {
                         case "pending":
@@ -61,7 +63,7 @@ namespace TEAMModelFunction
                                 ChangeRecord changeRecord = new ChangeRecord
                                 {
                                     RowKey = input.Id,
-                                    PartitionKey = "pending",
+                                    PartitionKey = PartitionKey,
                                     sequenceNumber = start,
                                     msgId = messageWork.MessageId
                                 };
@@ -171,7 +173,7 @@ namespace TEAMModelFunction
                                 ChangeRecord changeRecord = new ChangeRecord
                                 {
                                     RowKey = input.Id,
-                                    PartitionKey = "going",
+                                    PartitionKey = PartitionKey,
                                     sequenceNumber = end,
                                     msgId = messageWorkEnd.MessageId
                                 };

+ 5 - 3
TEAMModelFunction/TriggerStudy.cs

@@ -39,9 +39,11 @@ namespace TEAMModelFunction
                 }
                 await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}研修活动【{tdata.name}-{tdata.id}-ttl={tdata.ttl}】正在操作", GroupNames.成都开发測試群組);
                 Study study = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Study>(input.Id, new Azure.Cosmos.PartitionKey($"{tdata.code}"));
-                List<ChangeRecord> changeRecords = await _azureStorage.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", input.Id }, { "PartitionKey", study.progress } });
+                
                 if (study != null)
                 {
+                    string PartitionKey = string.Format("{0}{1}{2}", study.code, "-", study.progress);
+                    List<ChangeRecord> changeRecords = await _azureStorage.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", input.Id }, { "PartitionKey", PartitionKey } });
                     switch (study.progress)
                     {
                         case "pending":
@@ -60,7 +62,7 @@ namespace TEAMModelFunction
                                 ChangeRecord changeRecord = new ChangeRecord
                                 {
                                     RowKey = input.Id,
-                                    PartitionKey = "pending",
+                                    PartitionKey = PartitionKey,
                                     sequenceNumber = start,
                                     msgId = messageWork.MessageId
                                 };
@@ -113,7 +115,7 @@ namespace TEAMModelFunction
                                 ChangeRecord changeRecord = new ChangeRecord
                                 {
                                     RowKey = input.Id,
-                                    PartitionKey = "going",
+                                    PartitionKey = PartitionKey,
                                     sequenceNumber = end,
                                     msgId = messageWorkEnd.MessageId
                                 };

+ 5 - 3
TEAMModelFunction/TriggerSurvey.cs

@@ -48,9 +48,11 @@ namespace TEAMModelFunction
                     blobcntr = tdata.creatorId;
                 }
                 Survey survey = await client.GetContainer(Constant.TEAMModelOS, "Common").ReadItemAsync<Survey>(input.Id, new Azure.Cosmos.PartitionKey($"{tdata.code}"));
-                List<ChangeRecord> changeRecords = await _azureStorage.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", input.Id }, { "PartitionKey", survey.progress } });
+                
                 if (survey != null)
                 {
+                    string PartitionKey = string.Format("{0}{1}{2}", survey.code, "-", survey.progress);
+                    List<ChangeRecord> changeRecords = await _azureStorage.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", input.Id }, { "PartitionKey", PartitionKey } });
                     switch (survey.progress)
                     {
                         case "pending":
@@ -69,7 +71,7 @@ namespace TEAMModelFunction
                                 ChangeRecord changeRecord = new ChangeRecord
                                 {
                                     RowKey = input.Id,
-                                    PartitionKey = "pending",
+                                    PartitionKey = PartitionKey,
                                     sequenceNumber = start,
                                     msgId = messageSurvey.MessageId
                                 };
@@ -203,7 +205,7 @@ namespace TEAMModelFunction
                                 ChangeRecord changeRecord = new ChangeRecord
                                 {
                                     RowKey = input.Id,
-                                    PartitionKey = "going",
+                                    PartitionKey = PartitionKey,
                                     sequenceNumber = end,
                                     msgId = messageSurveyEnd.MessageId
                                 };

+ 5 - 3
TEAMModelFunction/TriggerVote.cs

@@ -48,9 +48,11 @@ namespace TEAMModelFunction
                 }
                 await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}投票活动【{tdata.name}-{tdata.id}-ttl={tdata.ttl}】正在操作", GroupNames.成都开发測試群組);
                 Vote vote = await client.GetContainer("TEAMModelOS", "Common").ReadItemAsync<Vote>(input.Id, new Azure.Cosmos.PartitionKey($"{tdata.code}"));
-                List<ChangeRecord> voteRecords = await _azureStorage.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", input.Id }, { "PartitionKey", vote.progress } });
+                
                 if (vote != null)
                 {
+                    string PartitionKey = string.Format("{0}{1}{2}", vote.code, "-", vote.progress);
+                    List<ChangeRecord> voteRecords = await _azureStorage.FindListByDict<ChangeRecord>(new Dictionary<string, object>() { { "RowKey", input.Id }, { "PartitionKey", PartitionKey } });
                     switch (vote.progress)
                     {
                         case "pending":
@@ -69,7 +71,7 @@ namespace TEAMModelFunction
                                 ChangeRecord changeRecord = new ChangeRecord
                                 {
                                     RowKey = input.Id,
-                                    PartitionKey = "pending",
+                                    PartitionKey = PartitionKey,
                                     sequenceNumber = start,
                                     msgId = messageVote.MessageId
                                 };
@@ -212,7 +214,7 @@ namespace TEAMModelFunction
                                 ChangeRecord changeRecord = new ChangeRecord
                                 {
                                     RowKey = input.Id,
-                                    PartitionKey = "going",
+                                    PartitionKey = PartitionKey,
                                     sequenceNumber = end,
                                     msgId = messageVoteEnd.MessageId
                                 };

+ 2 - 0
TEAMModelOS.SDK/Models/Cosmos/Teacher/CorrectTask.cs

@@ -47,5 +47,7 @@ namespace TEAMModelOS.SDK.Models
         public int model { get; set; }
         public long createTime { get; set; } = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
         public string progress { get; set; }
+        //评测类型
+        public string source { get; set; }
     }
 }