Browse Source

代码修复

zhouj1203@hotmail.com 3 years ago
parent
commit
087d198d21

+ 18 - 0
TEAMModelFunction/ActivityHttpTrigger.cs

@@ -526,5 +526,23 @@ namespace TEAMModelFunction
             await FixDataService.FixStudentInfo(client, _dingDing, _azureStorage, data);
             return new OkObjectResult(new { });
         }
+
+        /// <summary>
+        /// 修复评测publish字段内容
+        /// </summary>
+        /// <param name="req"></param>
+        /// <param name="log"></param>
+        /// <returns></returns>
+        [FunctionName("fix-exam-publish")]
+        public async Task<IActionResult> FixExamPublish(
+            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
+            ILogger log)
+        {
+            var client = _azureCosmos.GetCosmosClient();
+            string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
+            var data = System.Text.Json.JsonSerializer.Deserialize<JsonElement>(requestBody);
+            List<string> infos = await FixDataService.FixExamPublish(client, data);
+            return new OkObjectResult(new { infos });
+        }
     }
 }

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

@@ -395,5 +395,26 @@ namespace TEAMModelOS.SDK.Models.Service
             return studentIdList;
         }
 
+        /// <summary>
+        /// 修復评测内容
+        /// </summary>
+        /// <param name="client"></param>
+        /// <param name="schoolCode"></param>
+        /// <param name="dataDic"></param>
+        /// <returns></returns>
+        public static async Task<List<string>> FixExamPublish(CosmosClient client, JsonElement data)
+        {
+            List<string> infos = new List<string>();
+            var dict = data.GetProperty("publish").GetInt32();
+            await foreach (ExamInfo info in client.GetContainer(Constant.TEAMModelOS, "Common").GetItemQueryIterator<ExamInfo>(queryText: $"SELECT value(c) FROM c where c.pk = 'Exam'"))
+            {
+
+                info.publish = dict;
+                await client.GetContainer(Constant.TEAMModelOS, "Common").ReplaceItemAsync<ExamInfo>(info, info.id, new PartitionKey(info.code));
+                infos.Add(info.id);
+            }
+            return infos;
+        }
+
     }
 }

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

@@ -765,12 +765,8 @@ namespace TEAMModelOS.Controllers
                     //List<(int index ,string content, double count)> acount = new List<(int index,string content, double count)>();
                     for (int i = 0; i < ans.Count; i++)
                     {
-                        //List<string> op = new List<string>();
-                        var ac = ans[i].Count;
+                        var ac = ans[i].Select(a => a.Trim()).ToList().Count;
                         var sc = standard[i].Count;
-                        //记录次数
-                        int n = 0;
-                        //result.studentAnswers[index][i] = ans[i];
                         //算分处理
                         if (sc > 0)
                         {

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

@@ -857,5 +857,20 @@ namespace TEAMModelOS.Controllers
                 return BadRequest();
             }
         }
+        /// <summary>
+        /// 修复评测publish字段内容
+        /// </summary>
+        /// <param name="req"></param>
+        /// <param name="log"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        //[AuthToken(Roles = "teacher")]
+        [HttpPost("fix-exam-publish")]
+        public async Task<IActionResult> FixExamPublish(JsonElement data)
+        {
+            var client = _azureCosmos.GetCosmosClient();
+            List<string> infos = await FixDataService.FixExamPublish(client, data);
+            return new OkObjectResult(new { infos });
+        }
     }
 }

+ 0 - 300
TEAMModelOS/Controllers/XTest/TestController.cs

@@ -436,306 +436,6 @@ namespace TEAMModelOS.Controllers
             return Ok(data);
         }
 
-        /// <summary>
-        /// 测试blob多线程写入同一个文件
-        /// </summary>
-        /// <returns></returns>
-        [ProducesDefaultResponseType]
-        [HttpPost("generate-school-code")]
-        public async Task<IActionResult> GenerateSchoolCode(JsonElement json)
-        {
-            string path = $"{_environment.ContentRootPath}/JsonFile/Core/region.json";
-            var schools = json.GetProperty("schools").ToObject<List<SchoolData>>();
-            schools= schools.Where((x, i) => schools.FindIndex(n => n.name.Equals(x.name)) == i).ToList();
-            StreamReader streamReader = new StreamReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.UTF8);
-            StringBuilder stringBuilder = new StringBuilder();
-            string text;
-            while ((text = streamReader.ReadLine()) != null)
-            {
-                stringBuilder.Append(text.ToString());
-            }
-
-            streamReader.Close();
-            string input = stringBuilder.ToString();
-            List<Region> region = input.ToObject<List<Region>>(); 
-            try
-            {
-                schools.ForEach(x =>
-                {
-                    x.province=  ChineseConverter.Convert(x.province, ChineseConversionDirection.TraditionalToSimplified);
-                    if (String.IsNullOrEmpty(x.city))
-                    {
-                        x.city = x.province;
-                    }
-                    else {
-                        x.city = ChineseConverter.Convert(x.city, ChineseConversionDirection.TraditionalToSimplified);
-                    }
-                   
-                    x.name = ChineseConverter.Convert(x.name, ChineseConversionDirection.TraditionalToSimplified);
-                    //处理英文名字的学校
-                    if (!string.IsNullOrEmpty(x.address)) {
-                        x.address = ChineseConverter.Convert(x.address, ChineseConversionDirection.TraditionalToSimplified);
-                    }
-                 
-                    comeRemoveStr.ForEach(c => { x.province = x.province.Replace(c, ""); });
-                    prvcRemoveStr.ForEach(c => { x.province = x.province.Replace(c, ""); });
-                    var province = region.Find(r => r.name.Contains(x.province));
-                    string tmpprovince = x.province;
-                    string tmpcity = x.city;
-                    if (province != null)
-                    {
-                        x.province = province.name;
-                        comeRemoveStr.ForEach(c => { x.city = x.city.Replace(c, ""); });
-                        cityRemoveStr.ForEach(c => { x.city = x.city.Replace(c, ""); });
-                        nationRemoveStr.ForEach(c => { x.city = x.city.Replace(c, ""); });
-                        tmpcity = x.city;
-                        var city = province.children.Find(r => r.name.Contains(x.city));
-
-                        if (city == null)
-                        {
-                            city = province.children.Find(r => r.name.Contains(x.city));
-                            if (city == null)
-                            {
-                                city = province.children.SelectMany(x => x.children).ToList().Find(r => r.name.Contains(x.city));
-                            }
-                        }
-                        if (city != null)
-                        {
-                            x.city = city.name;
-                        }
-                    }
-
-                    string name = x.name;
-                    //去除冗余的学校信息,只保留地名和校名关键信息
-                    schemoveStr.ForEach(str =>
-                    {
-                        name = name.Replace(str, "");
-                    });
-                    string[] names = name.Split("(");
-                    if (names.Length > 1)
-                    {
-                        name = $"{names[0]}";
-                        for (int index = 1; index< names.Length; index++) 
-                        {
-                            name = $"{name}{names[index].Substring(0, 1)}";
-                            var afnames= names[index].Split(")");
-                            if (afnames.Length > 1) {
-                                for (int i = 1; i < afnames.Length; i++) {
-                                    name = $"{name}{afnames[i]}";
-                                }
-                            }
-                        }
-                    }
-                    names = name.Split("(");
-                    if (names.Length > 1)
-                    {
-                        name = $"{names[0]}";
-                        for (int index = 1; index  < names.Length; index++)
-                        {
-                            name = $"{name}{names[index].Substring(0, 1)}";
-                            var afnames = names[index].Split(")");
-                            if (afnames.Length > 1)
-                            {
-                                for (int i = 1; i < afnames.Length; i++)
-                                {
-                                    name = $"{name}{afnames[i]}";
-                                }
-                            }
-                        }
-                    }
-                    name = Regex.Replace(name, "[ \\[ \\] \\^ \\-|()【】/' {}_*×――(^)$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]", " ");
-                    //检查是否有英文
-                    if (Regex.Matches(name, "[a-zA-Z]").Count > 0)
-                    {
-                        var array = Regex.Split(name, "\\s+", RegexOptions.IgnoreCase);
-                        StringBuilder tmpname = new StringBuilder();
-                        if (array.Length > 1)
-                        {
-                            foreach (var item in array)
-                            {
-                                var arr = item.Select(x => $"{x}");
-                                int index = 0;
-                                foreach (var stra in arr)
-                                {
-                                    if (Regex.Matches(stra, "[a-zA-Z]").Count > 0)
-                                    {
-                                        if (index == 0)
-                                        {
-                                            tmpname.Append(stra);
-                                        }
-                                        else
-                                        {
-
-                                        }
-                                    }
-                                    else
-                                    {
-                                        tmpname.Append(stra);
-                                    }
-                                    index++;
-                                }
-                            }
-                        }
-                        else
-                        {
-                            var arr = name.Select(x => $"{x}");
-                            int index = 0;
-                            foreach (var stra in arr)
-                            {
-                                if (Regex.Matches(stra, "[A-Z]").Count > 0)
-                                {
-                                    tmpname.Append(stra);
-                                }
-                                else if (Regex.Matches(stra, "[a-z]").Count > 0)
-                                {
-                                }
-                                else
-                                {
-                                    tmpname.Append(stra);
-                                }
-                                index++;
-                            }
-
-                        }
-                        name = tmpname.ToString();
-                    }
-                    name = Regex.Replace(name, @"\s", "");
-                    name = name.Replace("\\", "");
-                    if (name.Length > 6)
-                    {
-                        //新区,高新,产业等非新政单位
-                        areaRemoveStr.ForEach(str =>
-                        {
-                            name = name.Replace(str.Key, str.Value);
-                        });
-                        //去除冗余的学校信息,只保留地名和校名关键信息
-                        schooRemoveStr.ForEach(str =>
-                        {
-                            name = name.Replace(str, "");
-                        });
-                       
-                        //替换民族信息词
-                        if (name.Length > 6)
-                        {
-                            nationRemoveStr.ForEach(str =>
-                            {
-                                name = name.Replace(str, "");
-                            });
-                        }
-                        //替换学校信息的副词
-                        if (name.Length > 6)
-                        {
-                            foreach (var str in schooReplaceStr) {
-                                if (name.Length <= 6)
-                                {
-                                    break;
-                                }
-                                name = name.Replace(str.Key, str.Value);
-                                
-                            }
-                        }
-                        //替换省简称信息词
-                        string tmpname = name;
-                        if (name.Length > 6)
-                        {
-                            proReplaceStr.ForEach(str =>
-                            {
-                                name = name.Replace(str.Key, str.Value);
-                            });
-                            //如果替换后仍然大于6位,则取消,直接替换省份完整的词
-                            if (name.Length > 6)
-                            {
-                                name = tmpname.Replace(tmpprovince, "");
-                            }
-                        }
-                        //替换城市信息词
-                        if (name.Length > 6)
-                        {
-                            name = name.Replace(tmpcity, "");
-                        }
-
-                    }
-                    int len = name.Length;
-                    if (len > 6) {
-                        foreach (var str in afterSchoolRm)
-                        {
-                            if (name.Length <= 6)
-                            {
-                                break;
-                            }
-                            name = name.Replace(str, "");
-                        }
-                    }
-
-                    len = name.Length;
-                    if (len >= 6)
-                    {
-                        name = $"{name.Substring(0, 1)}{name.Substring(len-5, 3)}{name.Substring(len - 2, 2)}";
-                    }
-                    //if (len <= 7 && len > 6)
-                    //{
-                    //    name = name.Substring(len - 6);
-                    //}
-                    if (len <= 4)
-                    {
-                        name = $"{x.city.Substring(0, 2)}{name}";
-                    }
-                    if (len == 5)
-                    {
-                        name = $"{x.city.Substring(0, 1)}{name}";
-                    }
-                    string code = PingYinHelper.GetFirstSpell(name);
-                    x.address = name;
-                    x.id = code;
-                    
-                });
-            }
-            catch (Exception ex)
-            {
-                await _dingDing.SendBotMsg($"{ex.Message}\n{ex.StackTrace}", GroupNames.成都开发測試群組);
-            }
-            string a_z = "abcdefghijklmnopqrstuvwxyz";
-            var data= schools.GroupBy(x=>x.id).Select(x=>new {key= x.Key,more=x.ToList().Count>2, count = x.ToList().Count, list= x.ToList()}).ToList();
-            data.ForEach(x =>
-            {
-                if (x.count > 1)
-                {
-                    var first = x.list.First();
-                    var same = x.list.Skip(1).Take(x.count - 1).ToList();
-                    var fs = first.name.Select(x => x).ToArray();
-                    same.ForEach(z =>
-                    {
-                        var sp = z.name.Select(x => x).ToArray();
-                        int len = sp.Length;
-                        if (sp.Length >= fs.Length)
-                        {
-                            len = fs.Count();
-                        }
-                        for (int index = 0; index < len; index++)
-                        {
-                            if (!$"{sp[index]}".Equals($"{fs[index]}"))
-                            {
-                                short st = ChineseChar.GetStrokeNumber(sp[index]);
-                                if (st > 0)
-                                {
-                                    var ins = st % 27;
-                                    var insch = a_z[ins];
-                                    if (z.name.EndsWith($"{insch}"))
-                                    {
-                                        ins = (st + 1) % 27;
-                                        insch = a_z[ins];
-                                    }
-                                    z.id = $"{z.id.Substring(0, z.id.Length - 1)}{insch}";
-                                    break;
-                                }
-                            }
-                        }
-                    });
-                }
-            });
-            var rdata = data.Where(x => x.count > 1);
-            return Ok(rdata);
-        }
       
         /// <summary>
         /// 测试blob多线程写入同一个文件