SchoolService.cs 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951
  1. using Azure.Cosmos;
  2. using HTEXLib.COMM.Helpers;
  3. using Microsoft.AspNetCore.Hosting;
  4. using Microsoft.International.Converters.PinYinConverter;
  5. using Microsoft.International.Converters.TraditionalChineseToSimplifiedConverter;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Text.Json;
  12. using System.Text.RegularExpressions;
  13. using System.Threading.Tasks;
  14. using TEAMModelOS.Models;
  15. using TEAMModelOS.SDK.DI;
  16. using TEAMModelOS.SDK.Extension;
  17. using TEAMModelOS.SDK.Models;
  18. namespace TEAMModelOS.SDK
  19. {
  20. public class SchoolService
  21. {
  22. /// <summary>
  23. /// 处理学期排序
  24. /// </summary>
  25. /// <param name="semesterList"></param>
  26. /// <returns></returns>
  27. public static List<Semester> SortSemester(List<Semester> semesterList)
  28. {
  29. int Year = DateTimeOffset.UtcNow.Year;
  30. List<KeyValuePair<int, Semester>> pairs = new List<KeyValuePair<int, Semester>>();
  31. semesterList.ForEach(se => {
  32. string sm = se.month >= 10 ? $"{se.month}" : $"0{se.month}";
  33. string sd = se.day >= 10 ? $"{se.day}" : $"0{se.day}";
  34. int order = int.Parse($"{Year}{sm}{sd}");
  35. pairs.Add(new KeyValuePair<int, Semester>(order, se));
  36. });
  37. var orderPairs = pairs.OrderBy(z => z.Key);
  38. semesterList = orderPairs.Select(z => z.Value).ToList();
  39. int startIndex = semesterList.FindIndex(z => z.start == 1);
  40. if (startIndex == -1)
  41. {
  42. //未设置学期的情况默认9月份开始的。
  43. startIndex = semesterList.FindIndex(z => z.month == 9);
  44. //如果还未找到,就以排序结果为准
  45. if (startIndex == -1)
  46. {
  47. startIndex = 0;
  48. }
  49. }
  50. if (startIndex > 0)
  51. {
  52. List<Semester> before = semesterList.Take(startIndex).ToList();
  53. List<Semester> after = semesterList.Skip(startIndex).ToList();
  54. semesterList = new List<Semester>();
  55. semesterList.AddRange(after);
  56. semesterList.AddRange(before);
  57. return semesterList;
  58. }
  59. else
  60. {
  61. return semesterList;
  62. }
  63. }
  64. public static async Task<(List<Class> school_classes, List<Class> graduate_classes)> DoGraduateClasses(HttpTrigger _httpTrigger, AzureCosmosFactory _azureCosmos, List<string> periodIds, School school_base, Option _option,DingDing _dingDing, int waite = 0) {
  65. List<Class> school_classes = new List<Class>();
  66. List<Class> graduate_classes = new List<Class>();
  67. try
  68. {
  69. var client = _azureCosmos.GetCosmosClient();
  70. //取得班级
  71. int nowYear = DateTimeOffset.UtcNow.Year;
  72. int nowMonth = DateTimeOffset.UtcNow.Month;
  73. int nowDay = DateTimeOffset.UtcNow.Day;
  74. //因为修改年级,而导致取消的
  75. List<Class> cancel_graduate_classes = new List<Class>();
  76. string sql = $"SELECT value c FROM c where (c.graduate = 0 or IS_DEFINED(c.graduate) = false) ";
  77. if (periodIds.IsNotEmpty())
  78. {
  79. sql = $"SELECT value c FROM c where c.periodId in ({string.Join(",", periodIds.Select(x => $"'{x}'"))}) ";
  80. }
  81. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<Class>
  82. //(queryText: $"SELECT value c FROM c where (c.graduate = 0 or IS_DEFINED(c.graduate) = false)",
  83. (queryText: sql,
  84. requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Class-{school_base.id}") }))
  85. {
  86. bool isgraduate = false;
  87. if (!string.IsNullOrWhiteSpace(item.periodId))
  88. {
  89. var period = school_base.period.Find(x => x.id.Equals(item.periodId));
  90. if (period != null)
  91. {
  92. var gradeCount = period.grades.Count();
  93. //2022-2016=6(待判断月份日期是否是毕业) 2022-2017=5(未毕业)
  94. if (nowYear - item.year > gradeCount)
  95. {
  96. isgraduate = true;
  97. }
  98. else if (nowYear - item.year == gradeCount)
  99. {
  100. var semester = period.semesters.Find(x => x.start == 1);
  101. if (semester != null)
  102. {
  103. if (nowMonth > semester.month)
  104. {
  105. isgraduate = true;
  106. }
  107. else if (nowMonth == semester.month)
  108. {
  109. if (nowDay >= semester.day)
  110. {
  111. isgraduate = true;
  112. }
  113. else
  114. {
  115. }
  116. }
  117. else { isgraduate = false; }
  118. }
  119. }
  120. else
  121. {
  122. isgraduate = false;
  123. }
  124. }
  125. }
  126. if (isgraduate)
  127. {
  128. graduate_classes.Add(item);
  129. }
  130. else
  131. {
  132. if (item.graduate == 1)
  133. {
  134. item.graduate = 0;
  135. cancel_graduate_classes.Add(item);
  136. }
  137. school_classes.Add(item);
  138. }
  139. }
  140. if (graduate_classes.Any() || cancel_graduate_classes.Any())
  141. {
  142. if (waite == 0)
  143. {
  144. _ = _httpTrigger.RequestHttpTrigger(new { graduate_classes = graduate_classes, cancel_graduate_classes = cancel_graduate_classes, schoolId = $"{school_base.id}" }, _option.Location, "graduate-change");
  145. }
  146. else
  147. {
  148. await _httpTrigger.RequestHttpTrigger(new { graduate_classes = graduate_classes, cancel_graduate_classes = cancel_graduate_classes, schoolId = $"{school_base.id}" }, _option.Location, "graduate-change");
  149. }
  150. }
  151. } catch (Exception ex) {
  152. await _dingDing.SendBotMsg($"{_option.Location},{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
  153. }
  154. return (school_classes,graduate_classes);
  155. }
  156. public static async Task<object> DoScsApiSchool(HttpTrigger _httpTrigger,Dictionary<string,object> dict, Option _option, List<IdNameCode> ignore,
  157. string areaId,string city,string dist, AzureStorageFactory _azureStorage ,DingDing _dingDing, IWebHostEnvironment _environment
  158. )
  159. {
  160. List<ScSchool> tbschools = null;
  161. List<ScSchool> matchSchools = null;
  162. List<ScSchool> schools = null;
  163. List<ScSchool> saveschools = null;
  164. var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
  165. // 5.3.1.18根据机构ID、项目ID、子项目ID返回学校列表
  166. ( int status, string json) = await _httpTrigger.RequestHttpTrigger(dict, _option.Location, "GetSchoolList");
  167. if (status == 200)
  168. {
  169. schools = json.ToObject<List<ScSchool>>(new JsonSerializerOptions { PropertyNameCaseInsensitive = false });
  170. if (ignore.IsNotEmpty())
  171. {
  172. matchSchools = schools.FindAll(x => ignore.Select(y => y.name).Contains(x.schoolname));
  173. if (matchSchools.IsNotEmpty())
  174. {
  175. if (matchSchools.Count != ignore.Count)
  176. {
  177. var matched = matchSchools.Select(x => x.schoolname);
  178. var unmatch = ignore.Select(y => y.name).Except(matched);
  179. List<string> scschoolUnmatch = schools.Select(y => y.schoolname).Except(matched).ToList();
  180. if (scschoolUnmatch.IsNotEmpty())
  181. {
  182. return new { matched, unmatch, scschoolUnmatch };
  183. }
  184. }
  185. else
  186. {
  187. matchSchools.ForEach(x => {
  188. var exschool = ignore.Find(y => y.name.Equals(x.schoolname));
  189. if (exschool != null)
  190. {
  191. x.schoolCode = exschool.id;
  192. x.areaId = $"{areaId}";
  193. x.city = $"{city}";
  194. x.dist = $"{dist}";
  195. }
  196. });
  197. }
  198. }
  199. else
  200. {
  201. return new { unmatch = ignore, schools };
  202. }
  203. }
  204. //数据校验
  205. tbschools = await table.FindListByDict<ScSchool>(new Dictionary<string, object>() { { "PartitionKey", "ScSchool" } });
  206. if (tbschools.IsNotEmpty())
  207. {
  208. var a = tbschools.Select(y => $"{y.RowKey}").ToList();
  209. saveschools = schools.Where(x => !a.Exists(z => z.Equals($"{x.schoolid}"))).ToList();
  210. List<SchoolData> schoolDatas = new List<SchoolData>();
  211. saveschools.ForEach(x =>
  212. {
  213. x.RowKey = $"{x.schoolid}";
  214. x.PartitionKey = "ScSchool";
  215. x.areaId = $"{areaId}";
  216. x.city = $"{city}";
  217. x.dist = $"{dist}";
  218. if (string.IsNullOrEmpty(x.schoolCode))
  219. {
  220. if (string.IsNullOrEmpty(x.schoolCode))
  221. {
  222. schoolDatas.Add(new SchoolData { uid = $"{x.schoolid}", province = "四川省", city = $"{city}", name = x.schoolname });
  223. }
  224. }
  225. });
  226. schoolDatas = await SchoolService.GenerateSchoolCode(schoolDatas, _dingDing, _environment);
  227. saveschools.ForEach(x => {
  228. var schoolData = schoolDatas.Find(y => y.uid.Equals($"{x.schoolid}"));
  229. if (schoolData != null && !string.IsNullOrEmpty(schoolData.id))
  230. {
  231. x.schoolCode = schoolData.id;
  232. x.areaId = $"{areaId}";
  233. x.city = $"{city}";
  234. x.dist = $"{dist}";
  235. }
  236. });
  237. saveschools.RemoveAll(x => string.IsNullOrEmpty(x.schoolCode));
  238. saveschools.RemoveAll(x => tbschools.FindAll(z => !string.IsNullOrEmpty(z.schoolCode)).Exists(y => y.schoolCode.Equals(x.schoolCode)));
  239. saveschools = await table.SaveAll(saveschools);
  240. }
  241. else
  242. {
  243. List<SchoolData> schoolDatas = new List<SchoolData>();
  244. schools.ForEach(x =>
  245. {
  246. x.RowKey = $"{x.schoolid}";
  247. x.PartitionKey = "ScSchool";
  248. x.areaId = $"{areaId}";
  249. x.city = $"{city}";
  250. x.dist = $"{dist}";
  251. var a = ignore.Find(z => z.name.Equals(x.schoolname));
  252. if (a != null)
  253. {
  254. x.schoolCode = a.id;
  255. }
  256. else
  257. {
  258. if (string.IsNullOrEmpty(x.schoolCode))
  259. {
  260. schoolDatas.Add(new SchoolData { uid = $"{x.schoolid}", province = "四川省", city = $"{city}", name = x.schoolname });
  261. }
  262. }
  263. });
  264. schoolDatas = await SchoolService.GenerateSchoolCode(schoolDatas, _dingDing, _environment);
  265. schools.ForEach(x => {
  266. var schoolData = schoolDatas.Find(y => y.uid.Equals($"{x.schoolid}"));
  267. if (schoolData != null && !string.IsNullOrEmpty(schoolData.id))
  268. {
  269. x.schoolCode = schoolData.id;
  270. x.areaId = $"{areaId}";
  271. x.city = $"{city}";
  272. x.dist = $"{dist}";
  273. }
  274. });
  275. schools.RemoveAll(x => string.IsNullOrEmpty(x.schoolCode));
  276. saveschools = await table.SaveOrUpdateAll(schools);
  277. }
  278. }
  279. return null;
  280. }
  281. public static async Task<List<SchoolData>> GenerateSchoolCode(List<SchoolData> schools, DingDing _dingDing, IWebHostEnvironment _environment)
  282. {
  283. string path = $"{_environment.ContentRootPath}/JsonFile/Core/region.json";
  284. //var schools = jsonstr.ToObject<JsonElement>().GetProperty("schools").ToObject<List<SchoolData>>();
  285. schools = schools.Where((x, i) => schools.FindIndex(n => n.name.Equals(x.name)) == i).ToList();
  286. StreamReader streamReader = new StreamReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.UTF8);
  287. StringBuilder stringBuilder = new StringBuilder();
  288. string text;
  289. while ((text = streamReader.ReadLine()) != null)
  290. {
  291. stringBuilder.Append(text.ToString());
  292. }
  293. streamReader.Close();
  294. string input = stringBuilder.ToString();
  295. List<Region> region = input.ToObject<List<Region>>();
  296. try
  297. {
  298. schools.ForEach(x =>
  299. {
  300. x.province = ChineseConverter.Convert(x.province, ChineseConversionDirection.TraditionalToSimplified);
  301. if (String.IsNullOrEmpty(x.city))
  302. {
  303. x.city = x.province;
  304. }
  305. else
  306. {
  307. x.city = ChineseConverter.Convert(x.city, ChineseConversionDirection.TraditionalToSimplified);
  308. }
  309. x.name = ChineseConverter.Convert(x.name, ChineseConversionDirection.TraditionalToSimplified);
  310. comeRemoveStr.ForEach(c => { x.province = x.province.Replace(c, ""); });
  311. prvcRemoveStr.ForEach(c => { x.province = x.province.Replace(c, ""); });
  312. var province = region.Find(r => r.name.Contains(x.province));
  313. string tmpprovince = x.province;
  314. string tmpcity = x.city;
  315. if (province != null)
  316. {
  317. x.province = province.name;
  318. comeRemoveStr.ForEach(c => { x.city = x.city.Replace(c, ""); });
  319. cityRemoveStr.ForEach(c => { x.city = x.city.Replace(c, ""); });
  320. nationRemoveStr.ForEach(c => { x.city = x.city.Replace(c, ""); });
  321. tmpcity = x.city;
  322. var city = province.children.Find(r => r.name.Contains(x.city));
  323. if (city == null)
  324. {
  325. city = province.children.Find(r => r.name.Contains(x.city));
  326. if (city == null)
  327. {
  328. city = province.children.SelectMany(x => x.children).ToList().Find(r => r.name.Contains(x.city));
  329. }
  330. }
  331. if (city != null)
  332. {
  333. x.city = city.name;
  334. }
  335. }
  336. string name = x.name;
  337. //去除冗余的学校信息,只保留地名和校名关键信息
  338. schemoveStr.ForEach(str =>
  339. {
  340. name = name.Replace(str, "");
  341. });
  342. string[] names = name.Split("(");
  343. if (names.Length > 1)
  344. {
  345. name = $"{names[0]}";
  346. for (int index = 1; index < names.Length; index++)
  347. {
  348. name = $"{name}{names[index].Substring(0, 1)}";
  349. var afnames = names[index].Split(")");
  350. if (afnames.Length > 1)
  351. {
  352. for (int i = 1; i < afnames.Length; i++)
  353. {
  354. name = $"{name}{afnames[i]}";
  355. }
  356. }
  357. }
  358. }
  359. names = name.Split("(");
  360. if (names.Length > 1)
  361. {
  362. name = $"{names[0]}";
  363. for (int index = 1; index < names.Length; index++)
  364. {
  365. name = $"{name}{names[index].Substring(0, 1)}";
  366. var afnames = names[index].Split(")");
  367. if (afnames.Length > 1)
  368. {
  369. for (int i = 1; i < afnames.Length; i++)
  370. {
  371. name = $"{name}{afnames[i]}";
  372. }
  373. }
  374. }
  375. }
  376. name = Regex.Replace(name, "[ \\[ \\] \\^ \\-|()【】/' {}_*×――(^)$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]", " ");
  377. //检查是否有英文
  378. if (Regex.Matches(name, "[a-zA-Z]").Count > 0)
  379. {
  380. var array = Regex.Split(name, "\\s+", RegexOptions.IgnoreCase);
  381. StringBuilder tmpname = new StringBuilder();
  382. if (array.Length > 1)
  383. {
  384. foreach (var item in array)
  385. {
  386. var arr = item.Select(x => $"{x}");
  387. int index = 0;
  388. foreach (var stra in arr)
  389. {
  390. if (Regex.Matches(stra, "[a-zA-Z]").Count > 0)
  391. {
  392. if (index == 1|| index == 0)
  393. {
  394. tmpname.Append(stra);
  395. }
  396. else
  397. {
  398. }
  399. }
  400. else
  401. {
  402. tmpname.Append(stra);
  403. }
  404. index++;
  405. }
  406. }
  407. }
  408. else
  409. {
  410. var arr = name.Select(x => $"{x}");
  411. int index = 0;
  412. foreach (var stra in arr)
  413. {
  414. if (Regex.Matches(stra, "[A-Z]").Count > 0)
  415. {
  416. tmpname.Append(stra);
  417. }
  418. else if (Regex.Matches(stra, "[a-z]").Count > 0)
  419. {
  420. }
  421. else
  422. {
  423. tmpname.Append(stra);
  424. }
  425. index++;
  426. }
  427. }
  428. name = tmpname.ToString();
  429. }
  430. name = Regex.Replace(name, @"\s", "");
  431. name = name.Replace("\\", "");
  432. if (name.Length > 6)
  433. {
  434. //新区,高新,产业等非新政单位
  435. areaRemoveStr.ForEach(str =>
  436. {
  437. name = name.Replace(str.Key, str.Value);
  438. });
  439. //去除冗余的学校信息,只保留地名和校名关键信息
  440. schooRemoveStr.ForEach(str =>
  441. {
  442. name = name.Replace(str, "");
  443. });
  444. //替换民族信息词
  445. if (name.Length > 6)
  446. {
  447. nationRemoveStr.ForEach(str =>
  448. {
  449. name = name.Replace(str, "");
  450. });
  451. }
  452. //替换学校信息的副词
  453. if (name.Length > 6)
  454. {
  455. foreach (var str in schooReplaceStr)
  456. {
  457. if (name.Length <= 6)
  458. {
  459. break;
  460. }
  461. name = name.Replace(str.Key, str.Value);
  462. }
  463. }
  464. //替换省简称信息词
  465. string tmpname = name;
  466. if (name.Length > 6)
  467. {
  468. proReplaceStr.ForEach(str =>
  469. {
  470. name = name.Replace(str.Key, str.Value);
  471. });
  472. //如果替换后仍然大于6位,则取消,直接替换省份完整的词
  473. if (name.Length > 6)
  474. {
  475. name = tmpname.Replace(tmpprovince, "");
  476. }
  477. }
  478. //替换城市信息词
  479. if (name.Length > 6)
  480. {
  481. name = name.Replace(tmpcity, "");
  482. }
  483. }
  484. int len = name.Length;
  485. if (len > 6)
  486. {
  487. foreach (var str in afterSchoolRm)
  488. {
  489. if (name.Length <= 6)
  490. {
  491. break;
  492. }
  493. name = name.Replace(str, "");
  494. }
  495. }
  496. len = name.Length;
  497. if (len >= 6)
  498. {
  499. name = $"{name.Substring(0, 1)}{name.Substring(len - 5, 3)}{name.Substring(len - 2, 2)}";
  500. }
  501. //if (len <= 7 && len > 6)
  502. //{
  503. // name = name.Substring(len - 6);
  504. //}
  505. if (len <= 4)
  506. {
  507. name = $"{x.city.Substring(0, 2)}{name}";
  508. }
  509. if (len == 5)
  510. {
  511. name = $"{x.city.Substring(0, 1)}{name}";
  512. }
  513. string code = ToFirstPinYin(name);
  514. x.aname = name;
  515. x.id = code;
  516. });
  517. }
  518. catch (Exception ex)
  519. {
  520. await _dingDing.SendBotMsg($"{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  521. }
  522. string a_z = "abcdefghijklmnopqrstuvwxyz";
  523. 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();
  524. data.ForEach(x =>
  525. {
  526. if (x.count > 1)
  527. {
  528. var first = x.list.First();
  529. var same = x.list.Skip(1).Take(x.count - 1).ToList();
  530. var fs = first.aname.Select(x => x).ToArray();
  531. same.ForEach(z =>
  532. {
  533. var sp = z.aname.Select(x => x).ToArray();
  534. int len = sp.Length;
  535. if (sp.Length >= fs.Length)
  536. {
  537. len = fs.Count();
  538. }
  539. for (int index = 0; index < len; index++)
  540. {
  541. if (!$"{sp[index]}".Equals($"{fs[index]}"))
  542. {
  543. short st = ChineseChar.GetStrokeNumber(sp[index]);
  544. if (st > 0)
  545. {
  546. var ins = st % 27;
  547. var insch = a_z[ins];
  548. if (z.aname.EndsWith($"{insch}"))
  549. {
  550. ins = (st + 1) % 27;
  551. insch = a_z[ins];
  552. }
  553. z.id = z.id.Insert(index, $"{insch}").Remove(index + 1, 1);
  554. break;
  555. }
  556. }
  557. }
  558. });
  559. }
  560. });
  561. var dataz = data.SelectMany(y=>y.list).GroupBy(x => x.id).Select(x => new { key = x.Key, more = x.ToList().Count > 2, count = x.ToList().Count, list = x.ToList() }).ToList();
  562. dataz.ForEach(x =>
  563. {
  564. if (x.count > 1)
  565. {
  566. var first = x.list.First();
  567. var same = x.list.Skip(1).Take(x.count - 1).ToList();
  568. var fs = first.aname.Select(x => x).ToArray();
  569. same.ForEach(z =>
  570. {
  571. var sp = z.aname.Select(x => x).ToArray();
  572. int len = sp.Length;
  573. if (sp.Length >= fs.Length)
  574. {
  575. len = fs.Count();
  576. }
  577. for (int index = 0; index < len; index++)
  578. {
  579. if (!$"{sp[index]}".Equals($"{fs[index]}"))
  580. {
  581. var spstr = ToPinYin($"{sp[index]}" );
  582. var fsstr = ToPinYin($"{fs[index]}");
  583. var insch= spstr.Select(x => $"{x}").Except( fsstr.Select(z => $"{z}"));
  584. if (insch != null && insch.Count() > 0) {
  585. if (index > 1)
  586. {
  587. z.id = z.id.Insert(index - 1, insch.First()).Remove(index, 1);
  588. }
  589. else if (index == 1)
  590. {
  591. z.id = z.id.Insert(index, insch.First()).Remove(index - 1, 1);
  592. }
  593. }
  594. }
  595. }
  596. });
  597. }
  598. });
  599. var dataa = dataz.SelectMany(y => y.list).GroupBy(x => x.id).Select(x => new { key = x.Key, more = x.ToList().Count > 2, count = x.ToList().Count, list = x.ToList() }).ToList();
  600. Random random = new Random();
  601. List<SchoolData> list = new List<SchoolData>();
  602. dataa.ForEach(x =>
  603. {
  604. if (x.count > 1)
  605. {
  606. x.list.ForEach(y => {
  607. int r= random.Next(25);
  608. int index= random.Next(5);
  609. y.id = y.id.Insert(index - 1, $"{a_z[r]}").Remove(index, 1);
  610. });
  611. }
  612. list.AddRange(x.list);
  613. });
  614. return list;
  615. }
  616. public static string ToPinYin(string val)
  617. {
  618. StringBuilder sb = new StringBuilder();
  619. val.ToCharArray().ToList().ForEach(x =>
  620. {
  621. if (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z') || ('0' <= x && x <= '9'))
  622. {
  623. sb.Append(x);
  624. }
  625. else
  626. {
  627. try
  628. {
  629. ChineseChar cc = new ChineseChar(x);
  630. if (cc.Pinyins.Count > 0 && cc.Pinyins[0].Length > 0)
  631. {
  632. sb.Append(cc.Pinyins[0]);
  633. }
  634. }
  635. catch (Exception ex)
  636. {
  637. }
  638. }
  639. });
  640. return sb.ToString().ToLower();
  641. }
  642. public static string ToFirstPinYin(string val)
  643. {
  644. StringBuilder sb = new StringBuilder();
  645. val.ToCharArray().ToList().ForEach(x =>
  646. {
  647. if (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z') || ('0' <= x && x <= '9'))
  648. {
  649. sb.Append(x);
  650. }
  651. else
  652. {
  653. try
  654. {
  655. ChineseChar cc = new ChineseChar(x);
  656. if (cc.Pinyins.Count > 0 && cc.Pinyins[0].Length > 0)
  657. {
  658. sb.Append(cc.Pinyins[0][0]);
  659. }
  660. }
  661. catch (Exception ex)
  662. {
  663. }
  664. }
  665. });
  666. return sb.ToString().ToLower();
  667. }
  668. public class SchoolData
  669. {
  670. public string province { get; set; }
  671. public string id { get; set; }
  672. public string name { get; set; }
  673. public string city { get; set; }
  674. public string aname { get; set; }
  675. public string uid { get; set; }
  676. }
  677. public static List<string> comeRemoveStr = new List<string>() { "省", "市", "区", "州", "县", "旗", "盟", "自治" };
  678. public static List<string> prvcRemoveStr = new List<string>() { "回族", "维吾尔", "壮族", };
  679. public static List<string> cityRemoveStr = new List<string>() { "蒙古族", "地区", "壮族", "朝鲜族", "直辖" };
  680. public static List<string> nationRemoveStr = new List<string> {
  681. "维吾尔","回族", "自治", "满族", "蒙古", "壮族", "苗族" , "侗族", "瑶族",
  682. "达斡尔","鄂温克","朝鲜","畲族","土家","各族","仫佬","毛南","羌族","彝族","仡佬","布依","水族",
  683. "傣族","纳西","哈尼","拉祜","佤族","傈僳","独龙","怒族","白族","普米","固族","哈萨克","土族","撒拉","景颇","族"
  684. };
  685. public static List<string> schemoveStr = new List<string> { "第", "校区", "部", "楼", "与", "学校", "校园", };
  686. public static List<string> schooRemoveStr = new List<string>() {"省", "市", "区", "州", "县", "旗", "盟","办事处","街道", "自治",
  687. "镇","村","乡","街","路","站","馆"
  688. };
  689. public static List<string> afterSchoolRm = new List<string>() {"校","园","院", "湾","峡","沟","山","庄",
  690. "堡","江","屯","岭","溪","河","桥","营","铺","坡","寨","场","湖","巷","集","关","庙","寺","矿","塘"};
  691. public static List<KeyValuePair<string, string>> areaRemoveStr = new List<KeyValuePair<string, string>>{
  692. new KeyValuePair<string, string>("高新技术产业开发区", "高") ,
  693. new KeyValuePair<string, string>("经济技术开发区", "经") ,
  694. new KeyValuePair<string, string>("国际", "际") ,
  695. new KeyValuePair<string, string>("中国", ""),
  696. new KeyValuePair<string, string>("国家", ""),
  697. new KeyValuePair<string, string>("新区", ""),
  698. new KeyValuePair<string, string>("高新", "高"),
  699. new KeyValuePair<string, string>("园区", ""),
  700. new KeyValuePair<string, string>("产业", "产"),
  701. new KeyValuePair<string, string>("经济", "经"),
  702. new KeyValuePair<string, string>("开发", "开"),
  703. new KeyValuePair<string, string>("中心", "") ,
  704. new KeyValuePair<string, string>("集团", "") ,
  705. new KeyValuePair<string, string>("公司", "") ,
  706. new KeyValuePair<string, string>("有限", "") ,
  707. new KeyValuePair<string, string>("股份", "") ,
  708. new KeyValuePair<string, string>("服务", "") ,
  709. new KeyValuePair<string, string>("基地", "") ,
  710. new KeyValuePair<string, string>("社区", "社") ,
  711. new KeyValuePair<string, string>("职工", "") ,
  712. new KeyValuePair<string, string>("专修", ""),
  713. new KeyValuePair<string, string>("实验", "验"),
  714. new KeyValuePair<string, string>("完全", ""),
  715. new KeyValuePair<string, string>("一贯制", "") ,
  716. new KeyValuePair<string, string>("联办", ""),
  717. new KeyValuePair<string, string>("联合", ""),
  718. new KeyValuePair<string, string>("完小", "小"),
  719. new KeyValuePair<string, string>("义务", ""),
  720. new KeyValuePair<string, string>("基础", ""),
  721. new KeyValuePair<string, string>("制造", "")
  722. };
  723. public static List<KeyValuePair<string, string>> schooReplaceStr = new List<KeyValuePair<string, string>> {
  724. new KeyValuePair<string, string>("分校", "分") ,
  725. new KeyValuePair<string, string>("分园", "分") ,
  726. new KeyValuePair<string, string>("分院", "分") ,
  727. new KeyValuePair<string, string>("藏文", "藏"),
  728. new KeyValuePair<string, string>("职业技术学院", "职") ,
  729. new KeyValuePair<string, string>("创新创业", "创") ,
  730. new KeyValuePair<string, string>("就业创业", "就") ,
  731. new KeyValuePair<string, string>("应用核技术", "核") ,
  732. new KeyValuePair<string, string>("职业学院", "职") ,
  733. new KeyValuePair<string, string>("幼儿园", "幼") ,
  734. new KeyValuePair<string, string>("幼儿", "幼") ,
  735. new KeyValuePair<string, string>("小学", "小") ,
  736. new KeyValuePair<string, string>("中学", "中") ,
  737. new KeyValuePair<string, string>("中等", "中") ,
  738. new KeyValuePair<string, string>("双语", "双") ,
  739. new KeyValuePair<string, string>("初中", "初") ,
  740. new KeyValuePair<string, string>("初级", "初") ,
  741. new KeyValuePair<string, string>("广播", "广"),
  742. new KeyValuePair<string, string>("高中", "高") ,
  743. new KeyValuePair<string, string>("高级", "高") ,
  744. new KeyValuePair<string, string>("大学", "大") ,
  745. new KeyValuePair<string, string>("学院", "院") ,
  746. new KeyValuePair<string, string>("综合", "综") ,
  747. new KeyValuePair<string, string>("职业", "职") ,
  748. new KeyValuePair<string, string>("技术", "技") ,
  749. new KeyValuePair<string, string>("专科", "专") ,
  750. new KeyValuePair<string, string>("外国语", "外") ,
  751. new KeyValuePair<string, string>("九年", "九") ,
  752. new KeyValuePair<string, string>("五年", "五") ,
  753. new KeyValuePair<string, string>("年制", "制") ,
  754. new KeyValuePair<string, string>("高等", "高") ,
  755. new KeyValuePair<string, string>("院校", "院") ,
  756. new KeyValuePair<string, string>("初等", "小") ,
  757. new KeyValuePair<string, string>("附属", "附"),
  758. new KeyValuePair<string, string>("寄宿制", "寄") ,
  759. new KeyValuePair<string, string>("寄宿", "寄") ,
  760. new KeyValuePair<string, string>("卫生", "卫") ,
  761. new KeyValuePair<string, string>("创业", "创") ,
  762. new KeyValuePair<string, string>("继续", "继") ,
  763. new KeyValuePair<string, string>("开放", "开") ,
  764. new KeyValuePair<string, string>("技师", "技") ,
  765. new KeyValuePair<string, string>("成人", "成") ,
  766. new KeyValuePair<string, string>("教育", "教") ,
  767. new KeyValuePair<string, string>("科技", "科") ,
  768. new KeyValuePair<string, string>("行政", "政") ,
  769. new KeyValuePair<string, string>("生物", "生") ,
  770. new KeyValuePair<string, string>("美术", "美") ,
  771. new KeyValuePair<string, string>("设计", "设") ,
  772. new KeyValuePair<string, string>("传播", "传") ,
  773. new KeyValuePair<string, string>("计算机", "算") ,
  774. new KeyValuePair<string, string>("土木", "土") ,
  775. new KeyValuePair<string, string>("石油", "油") ,
  776. new KeyValuePair<string, string>("科普", "普") ,
  777. new KeyValuePair<string, string>("电信", "信") ,
  778. new KeyValuePair<string, string>("联合", "联") ,
  779. new KeyValuePair<string, string>("电商", "商") ,
  780. new KeyValuePair<string, string>("纺织", "织") ,
  781. new KeyValuePair<string, string>("服装", "服") ,
  782. new KeyValuePair<string, string>("新闻", "新") ,
  783. new KeyValuePair<string, string>("网络", "网") ,
  784. new KeyValuePair<string, string>("应用", "应") ,
  785. new KeyValuePair<string, string>("畜牧", "畜") ,
  786. new KeyValuePair<string, string>("兽医", "兽") ,
  787. new KeyValuePair<string, string>("师范", "师") ,
  788. new KeyValuePair<string, string>("人文", "文") ,
  789. new KeyValuePair<string, string>("创新", "创") ,
  790. new KeyValuePair<string, string>("法官", "法") ,
  791. new KeyValuePair<string, string>("邮电", "邮") ,
  792. new KeyValuePair<string, string>("文化", "文") ,
  793. new KeyValuePair<string, string>("函授", "函") ,
  794. new KeyValuePair<string, string>("科学", "科") ,
  795. new KeyValuePair<string, string>("信息", "息") ,
  796. new KeyValuePair<string, string>("水利", "利") ,
  797. new KeyValuePair<string, string>("水电", "电") ,
  798. new KeyValuePair<string, string>("电力", "力") ,
  799. new KeyValuePair<string, string>("环境", "环") ,
  800. new KeyValuePair<string, string>("建材", "材") ,
  801. new KeyValuePair<string, string>("机电", "机") ,
  802. new KeyValuePair<string, string>("航空", "空") ,
  803. new KeyValuePair<string, string>("航天", "天") ,
  804. new KeyValuePair<string, string>("警察", "警") ,
  805. new KeyValuePair<string, string>("警官", "警") ,
  806. new KeyValuePair<string, string>("财贸", "财") ,
  807. new KeyValuePair<string, string>("电子", "电") ,
  808. new KeyValuePair<string, string>("建筑", "筑") ,
  809. new KeyValuePair<string, string>("艺术", "艺") ,
  810. new KeyValuePair<string, string>("体育", "体") ,
  811. new KeyValuePair<string, string>("城市", "城") ,
  812. new KeyValuePair<string, string>("地质", "地") ,
  813. new KeyValuePair<string, string>("医药", "药") ,
  814. new KeyValuePair<string, string>("政法", "法") ,
  815. new KeyValuePair<string, string>("铁路", "铁") ,
  816. new KeyValuePair<string, string>("铁道", "道") ,
  817. new KeyValuePair<string, string>("轨道", "轨") ,
  818. new KeyValuePair<string, string>("交通", "通") ,
  819. new KeyValuePair<string, string>("医学院", "医") ,
  820. new KeyValuePair<string, string>("医学", "医") ,
  821. new KeyValuePair<string, string>("传媒", "媒") ,
  822. new KeyValuePair<string, string>("工程", "程") ,
  823. new KeyValuePair<string, string>("临床", "临") ,
  824. new KeyValuePair<string, string>("化工", "化") ,
  825. new KeyValuePair<string, string>("林业", "林") ,
  826. new KeyValuePair<string, string>("老年", "老") ,
  827. new KeyValuePair<string, string>("旅游", "游") ,
  828. new KeyValuePair<string, string>("护理", "护") ,
  829. new KeyValuePair<string, string>("贸易", "贸") ,
  830. new KeyValuePair<string, string>("中医药", "中医") ,
  831. new KeyValuePair<string, string>("资源", "源") ,
  832. new KeyValuePair<string, string>("冶金", "冶") ,
  833. new KeyValuePair<string, string>("能源", "能") ,
  834. new KeyValuePair<string, string>("汽车", "车") ,
  835. new KeyValuePair<string, string>("医科", "医") ,
  836. new KeyValuePair<string, string>("机械", "械") ,
  837. new KeyValuePair<string, string>("应用", "应") ,
  838. new KeyValuePair<string, string>("电气", "电") ,
  839. new KeyValuePair<string, string>("材料", "材") ,
  840. new KeyValuePair<string, string>("劳动", "劳") ,
  841. new KeyValuePair<string, string>("轻工", "轻") ,
  842. new KeyValuePair<string, string>("农业", "农") ,
  843. new KeyValuePair<string, string>("委员会", "委") ,
  844. new KeyValuePair<string, string>("专业", "专") ,
  845. new KeyValuePair<string, string>("广播", "广"),
  846. new KeyValuePair<string, string>("电视", "电") ,
  847. new KeyValuePair<string, string>("工商", "商") ,
  848. new KeyValuePair<string, string>("工业", "工") ,
  849. new KeyValuePair<string, string>("管理", "管") ,
  850. new KeyValuePair<string, string>("社会主义", "社") ,
  851. new KeyValuePair<string, string>("社会", "社") ,
  852. new KeyValuePair<string, string>("自动化", "自") ,
  853. };
  854. public static List<KeyValuePair<string, string>> proReplaceStr = new List<KeyValuePair<string, string>> {
  855. new KeyValuePair<string, string>("北京","京") ,
  856. new KeyValuePair<string, string>("天津","津") ,
  857. new KeyValuePair<string, string>("河北","冀") ,
  858. new KeyValuePair<string, string>("山西","晋") ,
  859. new KeyValuePair<string, string>("内蒙古","蒙") ,
  860. new KeyValuePair<string, string>("辽宁","辽") ,
  861. new KeyValuePair<string, string>("吉林","吉") ,
  862. new KeyValuePair<string, string>("黑龙江","黑") ,
  863. new KeyValuePair<string, string>("上海","沪") ,
  864. new KeyValuePair<string, string>("江苏","苏") ,
  865. new KeyValuePair<string, string>("浙江","浙") ,
  866. new KeyValuePair<string, string>("安徽","皖") ,
  867. new KeyValuePair<string, string>("福建","闽") ,
  868. new KeyValuePair<string, string>("江西","赣") ,
  869. new KeyValuePair<string, string>("山东","鲁") ,
  870. new KeyValuePair<string, string>("河南","豫") ,
  871. new KeyValuePair<string, string>("湖北","鄂") ,
  872. new KeyValuePair<string, string>("湖南","湘") ,
  873. new KeyValuePair<string, string>("广东","粤") ,
  874. new KeyValuePair<string, string>("广西","桂") ,
  875. new KeyValuePair<string, string>("海南","琼") ,
  876. new KeyValuePair<string, string>("四川","川") ,
  877. new KeyValuePair<string, string>("贵州","贵") ,
  878. new KeyValuePair<string, string>("云南","云") ,
  879. new KeyValuePair<string, string>("重庆","渝") ,
  880. new KeyValuePair<string, string>("西藏","藏") ,
  881. new KeyValuePair<string, string>("陕西","陕") ,
  882. new KeyValuePair<string, string>("甘肃","甘") ,
  883. new KeyValuePair<string, string>("青海","青") ,
  884. new KeyValuePair<string, string>("宁夏","宁") ,
  885. new KeyValuePair<string, string>("新疆","新") ,
  886. new KeyValuePair<string, string>("香港","港") ,
  887. new KeyValuePair<string, string>("澳门","澳") ,
  888. new KeyValuePair<string, string>("台湾","台")
  889. };
  890. /*
  891. [
  892. {"method":"台北市","params":{"CountryId":"TW","CityId":"30"}},1
  893. {"method":"新北市","params":{"CountryId":"TW","CityId":"01"}},1
  894. {"method":"桃园市","params":{"CountryId":"TW","CityId":"03"}},1
  895. {"method":"台中市","params":{"CountryId":"TW","CityId":"66"}},1
  896. {"method":"台南市","params":{"CountryId":"TW","CityId":"67"}},1
  897. {"method":"高雄市","params":{"CountryId":"TW","CityId":"64"}},1
  898. {"method":"基隆市","params":{"CountryId":"TW","CityId":"17"}},1
  899. {"method":"新竹市","params":{"CountryId":"TW","CityId":"18"}},1
  900. {"method":"嘉义市","params":{"CountryId":"TW","CityId":"20"}},1
  901. {"method":"新竹县","params":{"CountryId":"TW","CityId":"04"}},1
  902. {"method":"苗栗县","params":{"CountryId":"TW","CityId":"05"}},1
  903. {"method":"彰化县","params":{"CountryId":"TW","CityId":"07"}},1
  904. {"method":"南投县","params":{"CountryId":"TW","CityId":"08"}},1
  905. {"method":"云林县","params":{"CountryId":"TW","CityId":"09"}},1
  906. {"method":"嘉义县","params":{"CountryId":"TW","CityId":"10"}},1
  907. {"method":"屏东县","params":{"CountryId":"TW","CityId":"13"}},1
  908. {"method":"宜兰县","params":{"CountryId":"TW","CityId":"02"}},1
  909. {"method":"花莲县","params":{"CountryId":"TW","CityId":"15"}},1
  910. {"method":"台东县","params":{"CountryId":"TW","CityId":"14"}},1
  911. {"method":"澎湖县","params":{"CountryId":"TW","CityId":"16"}},1
  912. {"method":"金门县","params":{"CountryId":"TW","CityId":"71"}},
  913. {"method":"连江县","params":{"CountryId":"TW","CityId":"72"}}
  914. ]
  915. */
  916. }
  917. }