Browse Source

答题卡

CrazyIter_Bin 3 years ago
parent
commit
b7c5910962

+ 11 - 7
TEAMModelOS.SDK/Models/Cosmos/Common/SheetConfig.cs

@@ -3,10 +3,14 @@ using System.Collections.Generic;
 using System.Text;
 using System.Text.Json;
 
-namespace TEAMModelOS.SDK.Models.Cosmos.Common
+namespace TEAMModelOS.SDK.Models
 {
     public class SheetConfig :CosmosEntity
     {
+        /// <summary>
+        /// exam代表评测来源的答题卡,paper代表试卷来源的答题卡,sheet 代表直接创建答题卡的来源
+        /// </summary>
+        public string from { get; set; }
         /// <summary>
         /// 答题卡编号
         /// </summary>
@@ -60,27 +64,27 @@ namespace TEAMModelOS.SDK.Models.Cosmos.Common
         /// <summary>
         /// 二值化区间(pc)-->不同扫描仪的结果图像数据有差距, 按需调整
         /// </summary>
-        public List<int> threshValue { get; set; } = new List<int> { 190, 220, 10 };
+       // public List<int> threshValue { get; set; } = new List<int> { 190, 220, 10 };
         /// <summary>
         /// 二值化区间(手机)
         /// </summary>
-        public List<int> threshValuePhone { get; set; } = new List<int> { 190, 220, 10 };
+       // public List<int> threshValuePhone { get; set; } = new List<int> { 190, 220, 10 };
         /// <summary>
         /// 单个整体回字大小
         /// </summary>
-        public double huiSize { get; set; } = 70;
+        //public double huiSize { get; set; } = 70;
         /// <summary>
         /// 最小回字的大小比列, 以回字最中间的方块为最小
         /// </summary>
-        public double minHuiSize { get; set; } = 0.005;
+       // public double minHuiSize { get; set; } = 0.005;
         /// <summary>
         /// 最大回字的大小比列, 以回字最外层的方块为最大
         /// </summary>
-        public double maxHuiSize { get; set; } = 0.1;
+       // public double maxHuiSize { get; set; } = 0.1;
         /// <summary>
         /// 不检测回字区域(pc版辅助效果20%, 手机版50%)
         /// </summary>
-        public List<double> notHuisRect { get; set; } = new List<double> { 0.3, 0.3, 0.4, 0.4 };
+       //public List<double> notHuisRect { get; set; } = new List<double> { 0.3, 0.3, 0.4, 0.4 };
         /// <summary>
         /// 内容块 vblockCount为该模块竖向的方块数 hblockCount为该模块横向方块数
         /// </summary>

+ 1 - 0
TEAMModelOS.SDK/Models/Cosmos/School/ExamInfo.cs

@@ -135,6 +135,7 @@ namespace TEAMModelOS.SDK.Models
         public List<string> type { get; set; } = new List<string>();
         public List<int> field { get; set; } = new List<int>();
         public  string  sheet { get; set; }        //public long sequenceNumber { get; set; }
+        public string sheetNo { get; set; }        //public long sequenceNumber { get; set; }
 
         //public List<Dictionary<string, int>> record { get; set; } = new List<Dictionary<string, int>>();
 

+ 1 - 0
TEAMModelOS.SDK/Models/Cosmos/School/Paper.cs

@@ -61,6 +61,7 @@ namespace TEAMModelOS.SDK.Models
         public string scope { get; set; }
         public int multipleRule { get; set; }
         public string sheet { get; set; }
+        public string sheetNo { get; set; }
         //记录试卷大小
         public long? size { get; set; } = 0;
         

+ 2 - 2
TEAMModelOS/Controllers/Client/HiScanController.cs

@@ -304,13 +304,13 @@ namespace TEAMModelOS.Controllers.Core
                     {
                         if (exam.scope .Equals("school"))
                         {
-                            SheetConfig config = new SheetConfig { id = pap.sheet, scope = exam.scope, code = $"SheetConfig-{exam.school}" };
+                            SheetConfig config = new SheetConfig { id = pap.sheet,no=pap.sheetNo, scope = exam.scope, code = $"SheetConfig-{exam.school}" };
                             dys.Add(new PaperRcd { name = pap.name, answers = pap.answers, point = pap.point, sheet = config });
                             sheet.Add(config);
                         }
                         else
                         {
-                            SheetConfig config = new SheetConfig { id = pap.sheet, scope = exam.scope, code = $"SheetConfig-{code}" };
+                            SheetConfig config = new SheetConfig { id = pap.sheet,  no = pap.sheetNo, scope = exam.scope, code = $"SheetConfig-{code}" };
                             dys.Add(new PaperRcd { name = pap.name, answers = pap.answers, point = pap.point, sheet = config });
                             sheet.Add(config);
                         }

+ 20 - 99
TEAMModelOS/Controllers/Paper/SheetConfigController.cs

@@ -82,98 +82,14 @@ namespace TEAMModelOS.Controllers.Common
         /**
         @条件1 当examId有值,则paperId 和 owner必定有值,sheet代表一个评测下的某一个试卷的答题卡数据,且答题卡的scope对应为评测的scope,且school和creatorId 与评测保持一致,且sheet.id从前端传递来的无效,
             因为id需要根据当前评测examId的试卷绑定的答题卡覆写或者新建
-            如果检测到examId下对应的试卷绑定答题卡sheet为空则新生成一个答题卡id,并自动绑定。如果检测评测对应的试卷已经绑定答题卡,则只需要更新实时的答题卡数据。
-        
+            如果检测到examId下对应的试卷绑定答题卡sheet为空则新生成一个答题卡id,并自动绑定。
         @条件2 当examId没有值,且paperId有值,sheet代表一个试卷库的某一个试卷的答题卡数据,且答题卡的scope对应为试卷库paperId的scope,且school和creatorId 与评测保持一致,且sheet.id从前端传递来的无效,
             因为id需要根据试卷绑定的答题卡覆写或者新建
             如果检测到paperId的试卷绑定的答题卡sheett为空则新生成一个答题卡id,并自动绑定。如果检测aperId的试卷已经绑定答题卡,则只需要更新实时的答题卡数据。
-
         @条件3 当examId和paperId都没有值,sheet代表与评测,试卷库无关的答题卡数据,且答题卡的scope ,school和creatorId 根据当前创建者需要保存数据的规则有关。
             且sheet.id,如果有值则是更新答题卡内容数据。
             如果sheet.id,没有值则是新建保存答题卡数据。
-
         @条件4 其他情况的参数传递不予以考虑,直接返回400参数错误。
-{   "examId":"31d0c8e4-ab94-42a0-8b38-d22a0c02a083", 
-    "paperId":"6bf05899-8bc6-2d74-0f4c-e339da79fc33",
-    "owner":"teacher/shcool"
-    "sheet": {
-        "id": "2553744",
-        "code": "hbcn",
-        "school": "hbcn",
-        "creatorId": "1595321354",
-        "scope": "teacher",
-        "columns": 1,
-        "pageWidth": 2150,
-        "pageHeight": 3000,
-        "pageNumBlockCount": 3,
-        "pageNumStartValue": 1,
-        "threshValue": [
-            190,
-            220,
-            10
-        ],
-        "threshValuePhone": [
-            190,
-            220,
-            10
-        ],
-        "huiSize": 70,
-        "minHuiSize": 0.005,
-        "maxHuiSize": 0.1,
-        "notHuisRect": [
-            0.3,
-            0.3,
-            0.4,
-            0.4
-        ],
-        "contents": [
-            {
-                "type": 0,
-                "x": 200,
-                "y": 261,
-                "width": 1760,
-                "height": 610,
-                "pageNum": 1,
-                "vblockCount": 10,
-                "hblockCount": 10,
-                "id": "12dae-ea-daefgh-easa",
-                "isFix": false
-            },
-            {
-                "type": 1,
-                "x": 200,
-                "y": 1000,
-                "width": 1760,
-                "height": 520,
-                "pageNum": 1,
-                "vblockCount": 5,
-                "hblockCount": 25,
-                "id": "12dae-ea-daefgh-easa",
-                "isFix": false
-            },
-            {
-                "type": 2,
-                "x": 200,
-                "y": 1760,
-                "width": 1760,
-                "height": 430,
-                "pageNum": 1,
-                "id": "12dae-ea-daefgh-easa",
-                "isFix": false
-            },
-            {
-                "type": 2,
-                "x": 200,
-                "y": 2350,
-                "width": 1760,
-                "height": 430,
-                "pageNum": 1,
-                "id": "12dae-ea-daefgh-easa",
-                "isFix": false
-            }
-        ]
-    }
-}
          **/
         /// <summary>
         /// 新增 或 修改答题卡
@@ -198,12 +114,14 @@ namespace TEAMModelOS.Controllers.Common
                 if (!sheet.code.StartsWith("SheetConfig-")) {
                     sheet.code = $"SheetConfig-{sheet.code}";
                 }
+               
                 sheet.pk = $"SheetConfig";
                 sheet.ttl = -1;
                 string tbname = sheet.scope.Equals("school", StringComparison.OrdinalIgnoreCase)? "School": "Teacher";
                 // @条件1 代表需要更新评测的某一个试卷的答题卡
                 if (!_paperId.ValueKind.Equals(JsonValueKind.Null) && !_examId.ValueKind.Equals(JsonValueKind.Null) && !string.IsNullOrEmpty($"{ _examId}") && !string.IsNullOrEmpty($"{ _paperId}"))
                 {
+                    sheet.from = "exam";
                     string code = "";
                     if (!string.IsNullOrEmpty($"{_owner}") && $"{_owner}".Equals("school", StringComparison.OrdinalIgnoreCase)) {
                         code = $"Exam-{sheet.school}";
@@ -219,18 +137,18 @@ namespace TEAMModelOS.Controllers.Common
                         var ps = exam.papers.Where(p => p.id == $"{_paperId}").FirstOrDefault();
                         if (ps != null)
                         {
-                            if (!string.IsNullOrEmpty(ps.sheet))
+                            if (string.IsNullOrEmpty(ps.sheet))
                             {
-                                await client.GetContainer(Constant.TEAMModelOS, tbname).DeleteItemStreamAsync($"{ps.sheet}", new PartitionKey(sheet.code));
+                                sheet.id = Guid.NewGuid().ToString();
+                                ps.sheet = sheet.id;
                             }
-                            sheet.id = await SheetService.genSheetId(client, _dingDing, _option, sheet.code, tbname);
-                            exam.papers.ForEach(x =>
-                            {
-                                if (x.id.Equals($"{_paperId}"))
-                                {
-                                    x.sheet = sheet.id;
-                                }
-                            });
+                            else {
+                                sheet.id = ps.sheet;
+                            }
+                            if (string.IsNullOrEmpty(sheet.no)) { 
+                                sheet.no = await SheetService.genSheetNo(client, _dingDing, _option, sheet.code, tbname, sheet.from); 
+                            }
+                            ps.sheetNo = sheet.no;
                             exam = await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync<ExamInfo>(exam, $"{_examId}", new PartitionKey($"{code}"));
                         }
                         else
@@ -247,13 +165,14 @@ namespace TEAMModelOS.Controllers.Common
                 else if ((string.IsNullOrEmpty($"{ _examId}") || !_examId.ValueKind.Equals(JsonValueKind.Null))
                     && !_paperId.ValueKind.Equals(JsonValueKind.Null) && !string.IsNullOrEmpty($"{ _paperId}"))
                 {
+                    sheet.from = "paper";
                     string code = sheet.scope.Equals("school", StringComparison.OrdinalIgnoreCase) ? $"Paper-{sheet.school}": $"Paper-{sheet.creatorId}";
                     try
                     {
                         Paper paper = await client.GetContainer(Constant.TEAMModelOS, tbname).ReadItemAsync<Paper>($"{_paperId}", new PartitionKey($"{code}"));
                         if (string.IsNullOrEmpty(paper.sheet))
                         {
-                            sheet.id =await SheetService.genSheetId(client, _dingDing, _option, sheet.code, tbname);
+                            sheet.no = await SheetService.genSheetNo(client, _dingDing, _option, sheet.code, tbname, sheet.from);
                             paper.sheet = sheet.id;
                             paper = await client.GetContainer(Constant.TEAMModelOS, tbname).ReplaceItemAsync<Paper>(paper, $"{_paperId}", new PartitionKey($"{code}"));
                         }
@@ -261,6 +180,7 @@ namespace TEAMModelOS.Controllers.Common
                         {
                             sheet.id = paper.sheet;
                         }
+                        
                     }
                     catch (Exception ex)
                     {
@@ -270,17 +190,18 @@ namespace TEAMModelOS.Controllers.Common
                 //@条件3 代表需要直接产生一个答题卡
                 else if (string.IsNullOrEmpty($"{ _examId}") && string.IsNullOrEmpty($"{ _paperId}"))
                 {
+                    sheet.from = "sheet";
                     if (string.IsNullOrEmpty(sheet.id)) {
-                        sheet.id = await SheetService.genSheetId(client, _dingDing, _option, sheet.code, tbname);
+                        sheet.no = await SheetService.genSheetNo(client, _dingDing, _option, sheet.code, tbname, sheet.from);
                     }
                 }
                 else {
                     //@条件4
                     return BadRequest("params is error!");
                 }
-                if (string.IsNullOrEmpty(sheet.id))
+                if (string.IsNullOrEmpty(sheet.no))
                 {
-                    sheet.id = await SheetService.genSheetId(client, _dingDing, _option, sheet.code, tbname);
+                    sheet.no = await SheetService.genSheetNo(client, _dingDing, _option, sheet.code, tbname,sheet.from);
 
                 }
                 sheet = await client.GetContainer(Constant.TEAMModelOS, tbname).UpsertItemAsync(sheet, new PartitionKey($"{sheet.code}"));

+ 8 - 4
TEAMModelOS/Controllers/Teacher/CommentController.cs

@@ -473,13 +473,13 @@ namespace TEAMModelOS.Controllers
                         List<string> sqlListc = new List<string>();
                         classes.ForEach(x => { sqlListc.Add($" '{x}' "); });
                         string sqlc = string.Join(" , ", sqlListc);
-                        andSqlClasses = $"   A1 in ({sqlc}) ";
+                        andSqlClasses = $"    A1 in ({sqlc}) ";
                         //教学班
                         joinSqlStulist = " join A1 in c.stuLists ";
                         List<string> sqlListl = new List<string>();
                         classes.ForEach(x => { sqlListl.Add($" '{x}' "); });
                         string sqll = string.Join(" , ", sqlListl);
-                        andSqlStulist = $"   A1 in ({sqll}) ";
+                        andSqlStulist = $"    A1 in ({sqll}) ";
                     }
                 }
             }
@@ -490,7 +490,11 @@ namespace TEAMModelOS.Controllers
             {
                 classesSql = $" and    {andSqlClasses }  ";
             }
-            
+            string stuListsSql = "";
+            if (!string.IsNullOrWhiteSpace(joinSqlStulist))
+            {
+                stuListsSql = $" and    {andSqlStulist }  ";
+            }
             List<JsonElement> datas = new List<JsonElement>();
             var client = _azureCosmos.GetCosmosClient();
             //班主任 ,任课教师只需要查询两种校园活动 和班级活动 ,  不查询私人教室创建的活动。  
@@ -516,7 +520,7 @@ namespace TEAMModelOS.Controllers
                         }
                     }
                 }
-                string querySchoollist = $" SELECT distinct c.owner, c.id,c.code, c.classes,c.stuLists,c.subjects,c.progress,c.scope,c.startTime,c.school,c.creatorId,c.name,c.pk ,c.endTime   FROM c {joinSqlStulist}   where   {pksql}    {andSqlStulist}";
+                string querySchoollist = $" SELECT distinct c.owner, c.id,c.code, c.classes,c.stuLists,c.subjects,c.progress,c.scope,c.startTime,c.school,c.creatorId,c.name,c.pk ,c.endTime   FROM c {joinSqlStulist}   where   {pksql}    {stuListsSql}";
                 await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryStreamIterator(querySchoollist, continuationToken: continuationTokenSchool, requestOptions: new QueryRequestOptions() { MaxItemCount = topcout, PartitionKey = new PartitionKey($"{type}-{school}") }))
                 {
                     using var json = await JsonDocument.ParseAsync(item.ContentStream);

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

@@ -6,6 +6,8 @@ using System.Linq;
 using System.Threading.Tasks;
 using TEAMModelOS.SDK.DI;
 using TEAMModelOS.SDK.Extension;
+using TEAMModelOS.SDK.Models;
+using TEAMModelOS.SDK.Models.Cosmos.Common;
 
 namespace TEAMModelOS.Services.Common
 {
@@ -38,5 +40,43 @@ namespace TEAMModelOS.Services.Common
             }
             return id;
         }
+        public static async Task<string> genSheetNo(CosmosClient client, DingDing _dingDing, TEAMModelOS.Models.Option _option, string sheetCode, string tbname,string  from)
+        {
+            string _num09 = "0123456789";
+            string no = $"{Utils.CreatSaltString(7, _num09)}";
+            for (int i = 0; i < 10; i++)
+            {
+                List<SheetConfig> sheets = new List<SheetConfig>();
+                bool hasCurrFrom = false;
+                await foreach (var item  in  client.GetContainer(Constant.TEAMModelOS, tbname).GetItemQueryIterator<SheetConfig>(
+                    queryText: $"select value(c) from  c where c.no='{no}'",
+                    requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey(sheetCode) })) 
+                {
+                    sheets.Add(item);
+                    
+                }
+                foreach (var item in sheets) {
+                    if (from.Equals(item.from) )
+                    {
+                        hasCurrFrom = true;
+                    }
+                }
+                if (hasCurrFrom)
+                {
+                    if (i == 9)
+                    {
+                        string msg = "common/SheetConfig/upsert()\n id生成异常,重复生成次数超过10次";
+                        await _dingDing.SendBotMsg($"OS,{_option.Location},{msg}", GroupNames.醍摩豆服務運維群組);
+                        throw new Exception(msg);
+                    }
+                    else
+                    {
+                        no = $"{Utils.CreatSaltString(7, _num09)}";
+                    }
+                }
+                else { break; }
+            }
+            return no;
+        }
     }
 }

+ 2 - 2
TEAMModelOS/appsettings.Development.json

@@ -24,8 +24,8 @@
       "ConnectionString": "DefaultEndpointsProtocol=https;AccountName=teammodelstorage;AccountKey=Yq7D4dE6cFuer2d2UZIccTA/i0c3sJ/6ITc8tNOyW+K5f+/lWw9GCos3Mxhj47PyWQgDL8YbVD63B9XcGtrMxQ==;EndpointSuffix=core.chinacloudapi.cn"
     },
     "Cosmos": {
-      "ConnectionString": "AccountEndpoint=https://cdhabookdep-free.documents.azure.cn:443/;AccountKey=JTUVk92Gjsx17L0xqxn0X4wX2thDPMKiw4daeTyV1HzPb6JmBeHdtFY1MF1jdctW1ofgzqkDMFOtcqS46by31A==;"
-      //"ConnectionString": "AccountEndpoint=https://teammodelos.documents.azure.cn:443/;AccountKey=clF73GwPECfP1lKZTCvs8gLMMyCZig1HODFbhDUsarsAURO7TcOjVz6ZFfPqr1HzYrfjCXpMuVD5TlEG5bFGGg==;"
+      //"ConnectionString": "AccountEndpoint=https://cdhabookdep-free.documents.azure.cn:443/;AccountKey=JTUVk92Gjsx17L0xqxn0X4wX2thDPMKiw4daeTyV1HzPb6JmBeHdtFY1MF1jdctW1ofgzqkDMFOtcqS46by31A==;"
+      "ConnectionString": "AccountEndpoint=https://teammodelos.documents.azure.cn:443/;AccountKey=clF73GwPECfP1lKZTCvs8gLMMyCZig1HODFbhDUsarsAURO7TcOjVz6ZFfPqr1HzYrfjCXpMuVD5TlEG5bFGGg==;"
     },
     "Redis": {
       "ConnectionString": "106.12.23.251:6379,password=habook,ssl=false,abortConnect=False,writeBuffer=10240"