|
@@ -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多线程写入同一个文件
|