Browse Source

新增评测时,清空paper的sheet字段的值。

CrazyIter_Bin 3 năm trước cách đây
mục cha
commit
b2901ba5a8

+ 4 - 18
TEAMModelOS/Controllers/Common/ExamController.cs

@@ -25,6 +25,7 @@ using TEAMModelOS.SDK.Models.Table;
 using Azure.Messaging.ServiceBus;
 using Microsoft.Extensions.Configuration;
 using TEAMModelOS.Filter;
+using TEAMModelOS.Services.Common;
 
 namespace TEAMModelOS.Controllers
 {
@@ -233,18 +234,14 @@ namespace TEAMModelOS.Controllers
                     var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
                     await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageBlob);
                     int n = 0;
+                    List<string> sheetIds = new List<string>();
                     foreach (PaperSimple simple in request.papers)
                     {
-                        simple.blob = "/exam/" + request.id + "/paper/" + request.subjects[n].id;
+                        simple.blob =$"/exam/{request.id}/paper/{request.subjects[n].id}";
                         n++;
+                        simple.sheet = null;
                     }
-                    //request.papers
-                    /*long SequenceNumber = await _serviceBus.GetServiceBusClient().SendLeamMessage<ExamInfo>(Constants.TopicName, request.id, request.code, request.startTime);
-                    request.sequenceNumber = SequenceNumber;*/
-                    //await _azureStorage.GetBlobContainerClient("hbcn").GetBlobsCatalogSize($"exam/{request.id}");
                     exam = await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(request, new PartitionKey($"{request.code}"));
-                    //await _serviceBus.GetServiceBusClient().SendLeamMessage<ExamInfo>(Constants.TopicName, request.id, request.code, request.startTime);
-                    //request.sequenceNumber = SequenceNumber;
                 }
                 else
                 {
@@ -276,19 +273,8 @@ namespace TEAMModelOS.Controllers
                         simple.blob = "/exam/" + request.id + "/paper/" + request.subjects[n].id;
                         n++;
                     }
-                    /*  await _serviceBus.GetServiceBusClient().cancelMessage(Constants.TopicName, info.sequenceNumber);
-                      long SequenceNumber = await _serviceBus.GetServiceBusClient().SendLeamMessage<ExamInfo>(Constants.TopicName, request.id, request.code, request.startTime);
-                      request.sequenceNumber = SequenceNumber;*/
                     exam = await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(request, request.id, new PartitionKey($"{request.code}"));
-
-
-                    //await _serviceBus.GetServiceBusClient().SendLeamMessage<ExamInfo>(Constants.TopicName, request.id, request.code, request.startTime);
                 }
-                //Survey homeWork = await _azureCosmos.SaveOrUpdate<Survey>(request.survey);
-
-                //设定结束时间
-                //string msgEndId = _snowflakeId.NextId() + "";
-                //await _serviceBus.GetServiceBusClient().SendLeamMessage<ExamInfo>(Constants.TopicName, request.id, request.code, request.endTime);
                 return Ok(new { exam });
             }
             catch (Exception ex)

+ 6 - 31
TEAMModelOS/Controllers/Paper/SheetConfigController.cs

@@ -230,7 +230,7 @@ namespace TEAMModelOS.Controllers.Common
                         {
                             if (string.IsNullOrEmpty(ps.sheet))
                             {
-                                sheet.id = await genSheetId(client, sheet.code, tbname);
+                                sheet.id = await SheetService.genSheetId(client,_dingDing,_option, sheet.code, tbname);
                                 exam.papers.ForEach(x =>
                                 {
                                     if (x.id.Equals($"{_paperId}"))
@@ -265,7 +265,7 @@ namespace TEAMModelOS.Controllers.Common
                         Paper paper = await client.GetContainer("TEAMModelOS", tbname).ReadItemAsync<Paper>($"{_paperId}", new PartitionKey($"{code}"));
                         if (string.IsNullOrEmpty(paper.sheet))
                         {
-                            sheet.id = await genSheetId(client, sheet.code, tbname);
+                            sheet.id =await SheetService.genSheetId(client, _dingDing, _option, sheet.code, tbname);
                             paper.sheet = sheet.id;
                             paper = await client.GetContainer("TEAMModelOS", tbname).ReplaceItemAsync<Paper>(paper, $"{_paperId}", new PartitionKey($"{code}"));
                         }
@@ -283,7 +283,7 @@ namespace TEAMModelOS.Controllers.Common
                 else if (string.IsNullOrEmpty($"{ _examId}") && string.IsNullOrEmpty($"{ _paperId}"))
                 {
                     if (string.IsNullOrEmpty(sheet.id)) {
-                        sheet.id = await genSheetId(client, sheet.code, tbname);
+                        sheet.id = await SheetService.genSheetId(client, _dingDing, _option, sheet.code, tbname);
                     }
                 }
                 else {
@@ -292,8 +292,8 @@ namespace TEAMModelOS.Controllers.Common
                 }
                 if (string.IsNullOrEmpty(sheet.id))
                 {
-                    sheet.id = await genSheetId(client, sheet.code, tbname);
-                    
+                    sheet.id = await SheetService.genSheetId(client, _dingDing, _option, sheet.code, tbname);
+
                 }
                 sheet = await client.GetContainer("TEAMModelOS", tbname).UpsertItemAsync(sheet, new PartitionKey($"{sheet.code}"));
                 return Ok(new { config = sheet, status=200 });
@@ -309,32 +309,7 @@ namespace TEAMModelOS.Controllers.Common
             }
         }
 
-        private async Task<string> genSheetId(CosmosClient client,string  sheetCode,string  tbname) {
-            string _num09 = "0123456789";
-            string id = $"{Utils.CreatSaltString(7, _num09)}";
-            for (int i = 0; i < 10; i++)
-            {
-                Response response = await client.GetContainer("TEAMModelOS", tbname).ReadItemStreamAsync($"{id}", new PartitionKey(sheetCode)); ;
-                if (response.Status == 404)
-                {
-                    break;
-                }
-                else
-                {
-                    if (i == 9)
-                    {  
-                        string  msg= "common/SheetConfig/upsert()\n id生成异常,重复生成次数超过10次";
-                        await _dingDing.SendBotMsg($"OS,{_option.Location},{msg}", GroupNames.醍摩豆服務運維群組);
-                        throw new Exception(msg);
-                    }
-                    else
-                    {
-                        id = $"{Utils.CreatSaltString(7, _num09)}";
-                    }
-                }
-            }
-            return id;
-        }
+        
         /// <summary>
         ///删除答题卡
         /// </summary>

+ 42 - 0
TEAMModelOS/Services/Common/SheetService.cs

@@ -0,0 +1,42 @@
+using Azure;
+using Azure.Cosmos;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using TEAMModelOS.SDK.DI;
+using TEAMModelOS.SDK.Extension;
+
+namespace TEAMModelOS.Services.Common
+{
+    public static class SheetService
+    {
+        public static async Task<string> genSheetId(CosmosClient client , DingDing _dingDing, TEAMModelOS.Models. Option _option, string sheetCode, string tbname)
+        {
+            string _num09 = "0123456789";
+            string id = $"{Utils.CreatSaltString(7, _num09)}";
+            for (int i = 0; i < 10; i++)
+            {
+                Response response = await client.GetContainer("TEAMModelOS", tbname).ReadItemStreamAsync($"{id}", new PartitionKey(sheetCode)); ;
+                if (response.Status == 404)
+                {
+                    break;
+                }
+                else
+                {
+                    if (i == 9)
+                    {
+                        string msg = "common/SheetConfig/upsert()\n id生成异常,重复生成次数超过10次";
+                        await _dingDing.SendBotMsg($"OS,{_option.Location},{msg}", GroupNames.醍摩豆服務運維群組);
+                        throw new Exception(msg);
+                    }
+                    else
+                    {
+                        id = $"{Utils.CreatSaltString(7, _num09)}";
+                    }
+                }
+            }
+            return id;
+        }
+    }
+}