SchoolService.cs 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908
  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. 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, int waite = 0) {
  23. var client = _azureCosmos.GetCosmosClient();
  24. //取得班级
  25. List<Class> school_classes = new List<Class>();
  26. int nowYear = DateTimeOffset.UtcNow.Year;
  27. int nowMonth = DateTimeOffset.UtcNow.Month;
  28. int nowDay = DateTimeOffset.UtcNow.Day;
  29. List<Class> graduate_classes = new List<Class>();
  30. //因为修改年级,而导致取消的
  31. List<Class> cancel_graduate_classes = new List<Class>();
  32. string sql = $"SELECT value c FROM c where (c.graduate = 0 or IS_DEFINED(c.graduate) = false) ";
  33. if (periodIds.IsNotEmpty()) {
  34. sql = $"SELECT value c FROM c where c.periodId in ({string.Join(",",periodIds.Select(x=>$"'{x}'"))}) ";
  35. }
  36. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<Class>
  37. //(queryText: $"SELECT value c FROM c where (c.graduate = 0 or IS_DEFINED(c.graduate) = false)",
  38. (queryText: sql,
  39. requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Class-{school_base.id}") }))
  40. {
  41. bool isgraduate = false;
  42. if (!string.IsNullOrWhiteSpace(item.periodId))
  43. {
  44. var period = school_base.period.Find(x => x.id.Equals(item.periodId));
  45. if (period != null)
  46. {
  47. var gradeCount = period.grades.Count();
  48. //2022-2016=6(待判断月份日期是否是毕业) 2022-2017=5(未毕业)
  49. if (nowYear - item.year > gradeCount)
  50. {
  51. isgraduate = true;
  52. }
  53. else if (nowYear - item.year == gradeCount)
  54. {
  55. var semester = period.semesters.Find(x => x.start == 1);
  56. if (semester != null)
  57. {
  58. if (nowMonth > semester.month)
  59. {
  60. isgraduate = true;
  61. }
  62. else if (nowMonth == semester.month)
  63. {
  64. if (nowDay >= semester.day)
  65. {
  66. isgraduate = true;
  67. }
  68. else
  69. {
  70. }
  71. }
  72. else { isgraduate = false; }
  73. }
  74. }
  75. else {
  76. isgraduate =false;
  77. }
  78. }
  79. }
  80. if (isgraduate)
  81. {
  82. graduate_classes.Add(item);
  83. }
  84. else
  85. {
  86. if (item.graduate == 1)
  87. {
  88. item.graduate = 0;
  89. cancel_graduate_classes.Add(item);
  90. }
  91. school_classes.Add(item);
  92. }
  93. }
  94. if (graduate_classes.Any() || cancel_graduate_classes.Any())
  95. {
  96. try
  97. {
  98. if (waite == 0)
  99. {
  100. _ = _httpTrigger.RequestHttpTrigger(new { graduate_classes = graduate_classes, cancel_graduate_classes = cancel_graduate_classes, schoolId = $"{school_base.id}" }, _option.Location, "graduate-change");
  101. }
  102. else {
  103. await _httpTrigger.RequestHttpTrigger(new { graduate_classes = graduate_classes, cancel_graduate_classes = cancel_graduate_classes, schoolId = $"{school_base.id}" }, _option.Location, "graduate-change");
  104. }
  105. }
  106. catch (Exception ex)
  107. {
  108. //暂不处理
  109. }
  110. }
  111. return (school_classes,graduate_classes);
  112. }
  113. public static async Task<object> DoScsApiSchool(HttpTrigger _httpTrigger,Dictionary<string,object> dict, Option _option, List<IdNameCode> ignore,
  114. string areaId,string city,string dist, AzureStorageFactory _azureStorage ,DingDing _dingDing, IWebHostEnvironment _environment
  115. )
  116. {
  117. List<ScSchool> tbschools = null;
  118. List<ScSchool> matchSchools = null;
  119. List<ScSchool> schools = null;
  120. List<ScSchool> saveschools = null;
  121. var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
  122. // 5.3.1.18根据机构ID、项目ID、子项目ID返回学校列表
  123. ( int status, string json) = await _httpTrigger.RequestHttpTrigger(dict, _option.Location, "GetSchoolList");
  124. if (status == 200)
  125. {
  126. schools = json.ToObject<List<ScSchool>>(new JsonSerializerOptions { PropertyNameCaseInsensitive = false });
  127. if (ignore.IsNotEmpty())
  128. {
  129. matchSchools = schools.FindAll(x => ignore.Select(y => y.name).Contains(x.schoolname));
  130. if (matchSchools.IsNotEmpty())
  131. {
  132. if (matchSchools.Count != ignore.Count)
  133. {
  134. var matched = matchSchools.Select(x => x.schoolname);
  135. var unmatch = ignore.Select(y => y.name).Except(matched);
  136. List<string> scschoolUnmatch = schools.Select(y => y.schoolname).Except(matched).ToList();
  137. if (scschoolUnmatch.IsNotEmpty())
  138. {
  139. return new { matched, unmatch, scschoolUnmatch };
  140. }
  141. }
  142. else
  143. {
  144. matchSchools.ForEach(x => {
  145. var exschool = ignore.Find(y => y.name.Equals(x.schoolname));
  146. if (exschool != null)
  147. {
  148. x.schoolCode = exschool.id;
  149. x.areaId = $"{areaId}";
  150. x.city = $"{city}";
  151. x.dist = $"{dist}";
  152. }
  153. });
  154. }
  155. }
  156. else
  157. {
  158. return new { unmatch = ignore, schools };
  159. }
  160. }
  161. //数据校验
  162. tbschools = await table.FindListByDict<ScSchool>(new Dictionary<string, object>() { { "PartitionKey", "ScSchool" } });
  163. if (tbschools.IsNotEmpty())
  164. {
  165. var a = tbschools.Select(y => $"{y.RowKey}").ToList();
  166. saveschools = schools.Where(x => !a.Exists(z => z.Equals($"{x.schoolid}"))).ToList();
  167. List<SchoolData> schoolDatas = new List<SchoolData>();
  168. saveschools.ForEach(x =>
  169. {
  170. x.RowKey = $"{x.schoolid}";
  171. x.PartitionKey = "ScSchool";
  172. x.areaId = $"{areaId}";
  173. x.city = $"{city}";
  174. x.dist = $"{dist}";
  175. if (string.IsNullOrEmpty(x.schoolCode))
  176. {
  177. if (string.IsNullOrEmpty(x.schoolCode))
  178. {
  179. schoolDatas.Add(new SchoolData { uid = $"{x.schoolid}", province = "四川省", city = $"{city}", name = x.schoolname });
  180. }
  181. }
  182. });
  183. schoolDatas = await SchoolService.GenerateSchoolCode(schoolDatas, _dingDing, _environment);
  184. saveschools.ForEach(x => {
  185. var schoolData = schoolDatas.Find(y => y.uid.Equals($"{x.schoolid}"));
  186. if (schoolData != null && !string.IsNullOrEmpty(schoolData.id))
  187. {
  188. x.schoolCode = schoolData.id;
  189. x.areaId = $"{areaId}";
  190. x.city = $"{city}";
  191. x.dist = $"{dist}";
  192. }
  193. });
  194. saveschools.RemoveAll(x => string.IsNullOrEmpty(x.schoolCode));
  195. saveschools.RemoveAll(x => tbschools.FindAll(z => !string.IsNullOrEmpty(z.schoolCode)).Exists(y => y.schoolCode.Equals(x.schoolCode)));
  196. saveschools = await table.SaveAll(saveschools);
  197. }
  198. else
  199. {
  200. List<SchoolData> schoolDatas = new List<SchoolData>();
  201. schools.ForEach(x =>
  202. {
  203. x.RowKey = $"{x.schoolid}";
  204. x.PartitionKey = "ScSchool";
  205. x.areaId = $"{areaId}";
  206. x.city = $"{city}";
  207. x.dist = $"{dist}";
  208. var a = ignore.Find(z => z.name.Equals(x.schoolname));
  209. if (a != null)
  210. {
  211. x.schoolCode = a.id;
  212. }
  213. else
  214. {
  215. if (string.IsNullOrEmpty(x.schoolCode))
  216. {
  217. schoolDatas.Add(new SchoolData { uid = $"{x.schoolid}", province = "四川省", city = $"{city}", name = x.schoolname });
  218. }
  219. }
  220. });
  221. schoolDatas = await SchoolService.GenerateSchoolCode(schoolDatas, _dingDing, _environment);
  222. schools.ForEach(x => {
  223. var schoolData = schoolDatas.Find(y => y.uid.Equals($"{x.schoolid}"));
  224. if (schoolData != null && !string.IsNullOrEmpty(schoolData.id))
  225. {
  226. x.schoolCode = schoolData.id;
  227. x.areaId = $"{areaId}";
  228. x.city = $"{city}";
  229. x.dist = $"{dist}";
  230. }
  231. });
  232. schools.RemoveAll(x => string.IsNullOrEmpty(x.schoolCode));
  233. saveschools = await table.SaveOrUpdateAll(schools);
  234. }
  235. }
  236. return null;
  237. }
  238. public static async Task<List<SchoolData>> GenerateSchoolCode(List<SchoolData> schools, DingDing _dingDing, IWebHostEnvironment _environment)
  239. {
  240. string path = $"{_environment.ContentRootPath}/JsonFile/Core/region.json";
  241. //var schools = jsonstr.ToObject<JsonElement>().GetProperty("schools").ToObject<List<SchoolData>>();
  242. schools = schools.Where((x, i) => schools.FindIndex(n => n.name.Equals(x.name)) == i).ToList();
  243. StreamReader streamReader = new StreamReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.UTF8);
  244. StringBuilder stringBuilder = new StringBuilder();
  245. string text;
  246. while ((text = streamReader.ReadLine()) != null)
  247. {
  248. stringBuilder.Append(text.ToString());
  249. }
  250. streamReader.Close();
  251. string input = stringBuilder.ToString();
  252. List<Region> region = input.ToObject<List<Region>>();
  253. try
  254. {
  255. schools.ForEach(x =>
  256. {
  257. x.province = ChineseConverter.Convert(x.province, ChineseConversionDirection.TraditionalToSimplified);
  258. if (String.IsNullOrEmpty(x.city))
  259. {
  260. x.city = x.province;
  261. }
  262. else
  263. {
  264. x.city = ChineseConverter.Convert(x.city, ChineseConversionDirection.TraditionalToSimplified);
  265. }
  266. x.name = ChineseConverter.Convert(x.name, ChineseConversionDirection.TraditionalToSimplified);
  267. comeRemoveStr.ForEach(c => { x.province = x.province.Replace(c, ""); });
  268. prvcRemoveStr.ForEach(c => { x.province = x.province.Replace(c, ""); });
  269. var province = region.Find(r => r.name.Contains(x.province));
  270. string tmpprovince = x.province;
  271. string tmpcity = x.city;
  272. if (province != null)
  273. {
  274. x.province = province.name;
  275. comeRemoveStr.ForEach(c => { x.city = x.city.Replace(c, ""); });
  276. cityRemoveStr.ForEach(c => { x.city = x.city.Replace(c, ""); });
  277. nationRemoveStr.ForEach(c => { x.city = x.city.Replace(c, ""); });
  278. tmpcity = x.city;
  279. var city = province.children.Find(r => r.name.Contains(x.city));
  280. if (city == null)
  281. {
  282. city = province.children.Find(r => r.name.Contains(x.city));
  283. if (city == null)
  284. {
  285. city = province.children.SelectMany(x => x.children).ToList().Find(r => r.name.Contains(x.city));
  286. }
  287. }
  288. if (city != null)
  289. {
  290. x.city = city.name;
  291. }
  292. }
  293. string name = x.name;
  294. //去除冗余的学校信息,只保留地名和校名关键信息
  295. schemoveStr.ForEach(str =>
  296. {
  297. name = name.Replace(str, "");
  298. });
  299. string[] names = name.Split("(");
  300. if (names.Length > 1)
  301. {
  302. name = $"{names[0]}";
  303. for (int index = 1; index < names.Length; index++)
  304. {
  305. name = $"{name}{names[index].Substring(0, 1)}";
  306. var afnames = names[index].Split(")");
  307. if (afnames.Length > 1)
  308. {
  309. for (int i = 1; i < afnames.Length; i++)
  310. {
  311. name = $"{name}{afnames[i]}";
  312. }
  313. }
  314. }
  315. }
  316. names = name.Split("(");
  317. if (names.Length > 1)
  318. {
  319. name = $"{names[0]}";
  320. for (int index = 1; index < names.Length; index++)
  321. {
  322. name = $"{name}{names[index].Substring(0, 1)}";
  323. var afnames = names[index].Split(")");
  324. if (afnames.Length > 1)
  325. {
  326. for (int i = 1; i < afnames.Length; i++)
  327. {
  328. name = $"{name}{afnames[i]}";
  329. }
  330. }
  331. }
  332. }
  333. name = Regex.Replace(name, "[ \\[ \\] \\^ \\-|()【】/' {}_*×――(^)$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]", " ");
  334. //检查是否有英文
  335. if (Regex.Matches(name, "[a-zA-Z]").Count > 0)
  336. {
  337. var array = Regex.Split(name, "\\s+", RegexOptions.IgnoreCase);
  338. StringBuilder tmpname = new StringBuilder();
  339. if (array.Length > 1)
  340. {
  341. foreach (var item in array)
  342. {
  343. var arr = item.Select(x => $"{x}");
  344. int index = 0;
  345. foreach (var stra in arr)
  346. {
  347. if (Regex.Matches(stra, "[a-zA-Z]").Count > 0)
  348. {
  349. if (index == 1|| index == 0)
  350. {
  351. tmpname.Append(stra);
  352. }
  353. else
  354. {
  355. }
  356. }
  357. else
  358. {
  359. tmpname.Append(stra);
  360. }
  361. index++;
  362. }
  363. }
  364. }
  365. else
  366. {
  367. var arr = name.Select(x => $"{x}");
  368. int index = 0;
  369. foreach (var stra in arr)
  370. {
  371. if (Regex.Matches(stra, "[A-Z]").Count > 0)
  372. {
  373. tmpname.Append(stra);
  374. }
  375. else if (Regex.Matches(stra, "[a-z]").Count > 0)
  376. {
  377. }
  378. else
  379. {
  380. tmpname.Append(stra);
  381. }
  382. index++;
  383. }
  384. }
  385. name = tmpname.ToString();
  386. }
  387. name = Regex.Replace(name, @"\s", "");
  388. name = name.Replace("\\", "");
  389. if (name.Length > 6)
  390. {
  391. //新区,高新,产业等非新政单位
  392. areaRemoveStr.ForEach(str =>
  393. {
  394. name = name.Replace(str.Key, str.Value);
  395. });
  396. //去除冗余的学校信息,只保留地名和校名关键信息
  397. schooRemoveStr.ForEach(str =>
  398. {
  399. name = name.Replace(str, "");
  400. });
  401. //替换民族信息词
  402. if (name.Length > 6)
  403. {
  404. nationRemoveStr.ForEach(str =>
  405. {
  406. name = name.Replace(str, "");
  407. });
  408. }
  409. //替换学校信息的副词
  410. if (name.Length > 6)
  411. {
  412. foreach (var str in schooReplaceStr)
  413. {
  414. if (name.Length <= 6)
  415. {
  416. break;
  417. }
  418. name = name.Replace(str.Key, str.Value);
  419. }
  420. }
  421. //替换省简称信息词
  422. string tmpname = name;
  423. if (name.Length > 6)
  424. {
  425. proReplaceStr.ForEach(str =>
  426. {
  427. name = name.Replace(str.Key, str.Value);
  428. });
  429. //如果替换后仍然大于6位,则取消,直接替换省份完整的词
  430. if (name.Length > 6)
  431. {
  432. name = tmpname.Replace(tmpprovince, "");
  433. }
  434. }
  435. //替换城市信息词
  436. if (name.Length > 6)
  437. {
  438. name = name.Replace(tmpcity, "");
  439. }
  440. }
  441. int len = name.Length;
  442. if (len > 6)
  443. {
  444. foreach (var str in afterSchoolRm)
  445. {
  446. if (name.Length <= 6)
  447. {
  448. break;
  449. }
  450. name = name.Replace(str, "");
  451. }
  452. }
  453. len = name.Length;
  454. if (len >= 6)
  455. {
  456. name = $"{name.Substring(0, 1)}{name.Substring(len - 5, 3)}{name.Substring(len - 2, 2)}";
  457. }
  458. //if (len <= 7 && len > 6)
  459. //{
  460. // name = name.Substring(len - 6);
  461. //}
  462. if (len <= 4)
  463. {
  464. name = $"{x.city.Substring(0, 2)}{name}";
  465. }
  466. if (len == 5)
  467. {
  468. name = $"{x.city.Substring(0, 1)}{name}";
  469. }
  470. string code = ToFirstPinYin(name);
  471. x.aname = name;
  472. x.id = code;
  473. });
  474. }
  475. catch (Exception ex)
  476. {
  477. await _dingDing.SendBotMsg($"{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  478. }
  479. string a_z = "abcdefghijklmnopqrstuvwxyz";
  480. 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();
  481. data.ForEach(x =>
  482. {
  483. if (x.count > 1)
  484. {
  485. var first = x.list.First();
  486. var same = x.list.Skip(1).Take(x.count - 1).ToList();
  487. var fs = first.aname.Select(x => x).ToArray();
  488. same.ForEach(z =>
  489. {
  490. var sp = z.aname.Select(x => x).ToArray();
  491. int len = sp.Length;
  492. if (sp.Length >= fs.Length)
  493. {
  494. len = fs.Count();
  495. }
  496. for (int index = 0; index < len; index++)
  497. {
  498. if (!$"{sp[index]}".Equals($"{fs[index]}"))
  499. {
  500. short st = ChineseChar.GetStrokeNumber(sp[index]);
  501. if (st > 0)
  502. {
  503. var ins = st % 27;
  504. var insch = a_z[ins];
  505. if (z.aname.EndsWith($"{insch}"))
  506. {
  507. ins = (st + 1) % 27;
  508. insch = a_z[ins];
  509. }
  510. z.id = z.id.Insert(index, $"{insch}").Remove(index + 1, 1);
  511. break;
  512. }
  513. }
  514. }
  515. });
  516. }
  517. });
  518. 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();
  519. dataz.ForEach(x =>
  520. {
  521. if (x.count > 1)
  522. {
  523. var first = x.list.First();
  524. var same = x.list.Skip(1).Take(x.count - 1).ToList();
  525. var fs = first.aname.Select(x => x).ToArray();
  526. same.ForEach(z =>
  527. {
  528. var sp = z.aname.Select(x => x).ToArray();
  529. int len = sp.Length;
  530. if (sp.Length >= fs.Length)
  531. {
  532. len = fs.Count();
  533. }
  534. for (int index = 0; index < len; index++)
  535. {
  536. if (!$"{sp[index]}".Equals($"{fs[index]}"))
  537. {
  538. var spstr = ToPinYin($"{sp[index]}" );
  539. var fsstr = ToPinYin($"{fs[index]}");
  540. var insch= spstr.Select(x => $"{x}").Except( fsstr.Select(z => $"{z}"));
  541. if (insch != null && insch.Count() > 0) {
  542. if (index > 1)
  543. {
  544. z.id = z.id.Insert(index - 1, insch.First()).Remove(index, 1);
  545. }
  546. else if (index == 1)
  547. {
  548. z.id = z.id.Insert(index, insch.First()).Remove(index - 1, 1);
  549. }
  550. }
  551. }
  552. }
  553. });
  554. }
  555. });
  556. 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();
  557. Random random = new Random();
  558. List<SchoolData> list = new List<SchoolData>();
  559. dataa.ForEach(x =>
  560. {
  561. if (x.count > 1)
  562. {
  563. x.list.ForEach(y => {
  564. int r= random.Next(25);
  565. int index= random.Next(5);
  566. y.id = y.id.Insert(index - 1, $"{a_z[r]}").Remove(index, 1);
  567. });
  568. }
  569. list.AddRange(x.list);
  570. });
  571. return list;
  572. }
  573. public static string ToPinYin(string val)
  574. {
  575. StringBuilder sb = new StringBuilder();
  576. val.ToCharArray().ToList().ForEach(x =>
  577. {
  578. if (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z') || ('0' <= x && x <= '9'))
  579. {
  580. sb.Append(x);
  581. }
  582. else
  583. {
  584. try
  585. {
  586. ChineseChar cc = new ChineseChar(x);
  587. if (cc.Pinyins.Count > 0 && cc.Pinyins[0].Length > 0)
  588. {
  589. sb.Append(cc.Pinyins[0]);
  590. }
  591. }
  592. catch (Exception ex)
  593. {
  594. }
  595. }
  596. });
  597. return sb.ToString().ToLower();
  598. }
  599. public static string ToFirstPinYin(string val)
  600. {
  601. StringBuilder sb = new StringBuilder();
  602. val.ToCharArray().ToList().ForEach(x =>
  603. {
  604. if (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z') || ('0' <= x && x <= '9'))
  605. {
  606. sb.Append(x);
  607. }
  608. else
  609. {
  610. try
  611. {
  612. ChineseChar cc = new ChineseChar(x);
  613. if (cc.Pinyins.Count > 0 && cc.Pinyins[0].Length > 0)
  614. {
  615. sb.Append(cc.Pinyins[0][0]);
  616. }
  617. }
  618. catch (Exception ex)
  619. {
  620. }
  621. }
  622. });
  623. return sb.ToString().ToLower();
  624. }
  625. public class SchoolData
  626. {
  627. public string province { get; set; }
  628. public string id { get; set; }
  629. public string name { get; set; }
  630. public string city { get; set; }
  631. public string aname { get; set; }
  632. public string uid { get; set; }
  633. }
  634. public static List<string> comeRemoveStr = new List<string>() { "省", "市", "区", "州", "县", "旗", "盟", "自治" };
  635. public static List<string> prvcRemoveStr = new List<string>() { "回族", "维吾尔", "壮族", };
  636. public static List<string> cityRemoveStr = new List<string>() { "蒙古族", "地区", "壮族", "朝鲜族", "直辖" };
  637. public static List<string> nationRemoveStr = new List<string> {
  638. "维吾尔","回族", "自治", "满族", "蒙古", "壮族", "苗族" , "侗族", "瑶族",
  639. "达斡尔","鄂温克","朝鲜","畲族","土家","各族","仫佬","毛南","羌族","彝族","仡佬","布依","水族",
  640. "傣族","纳西","哈尼","拉祜","佤族","傈僳","独龙","怒族","白族","普米","固族","哈萨克","土族","撒拉","景颇","族"
  641. };
  642. public static List<string> schemoveStr = new List<string> { "第", "校区", "部", "楼", "与", "学校", "校园", };
  643. public static List<string> schooRemoveStr = new List<string>() {"省", "市", "区", "州", "县", "旗", "盟","办事处","街道", "自治",
  644. "镇","村","乡","街","路","站","馆"
  645. };
  646. public static List<string> afterSchoolRm = new List<string>() {"校","园","院", "湾","峡","沟","山","庄",
  647. "堡","江","屯","岭","溪","河","桥","营","铺","坡","寨","场","湖","巷","集","关","庙","寺","矿","塘"};
  648. public static List<KeyValuePair<string, string>> areaRemoveStr = new List<KeyValuePair<string, string>>{
  649. new KeyValuePair<string, string>("高新技术产业开发区", "高") ,
  650. new KeyValuePair<string, string>("经济技术开发区", "经") ,
  651. new KeyValuePair<string, string>("国际", "际") ,
  652. new KeyValuePair<string, string>("中国", ""),
  653. new KeyValuePair<string, string>("国家", ""),
  654. new KeyValuePair<string, string>("新区", ""),
  655. new KeyValuePair<string, string>("高新", "高"),
  656. new KeyValuePair<string, string>("园区", ""),
  657. new KeyValuePair<string, string>("产业", "产"),
  658. new KeyValuePair<string, string>("经济", "经"),
  659. new KeyValuePair<string, string>("开发", "开"),
  660. new KeyValuePair<string, string>("中心", "") ,
  661. new KeyValuePair<string, string>("集团", "") ,
  662. new KeyValuePair<string, string>("公司", "") ,
  663. new KeyValuePair<string, string>("有限", "") ,
  664. new KeyValuePair<string, string>("股份", "") ,
  665. new KeyValuePair<string, string>("服务", "") ,
  666. new KeyValuePair<string, string>("基地", "") ,
  667. new KeyValuePair<string, string>("社区", "社") ,
  668. new KeyValuePair<string, string>("职工", "") ,
  669. new KeyValuePair<string, string>("专修", ""),
  670. new KeyValuePair<string, string>("实验", "验"),
  671. new KeyValuePair<string, string>("完全", ""),
  672. new KeyValuePair<string, string>("一贯制", "") ,
  673. new KeyValuePair<string, string>("联办", ""),
  674. new KeyValuePair<string, string>("联合", ""),
  675. new KeyValuePair<string, string>("完小", "小"),
  676. new KeyValuePair<string, string>("义务", ""),
  677. new KeyValuePair<string, string>("基础", ""),
  678. new KeyValuePair<string, string>("制造", "")
  679. };
  680. public static List<KeyValuePair<string, string>> schooReplaceStr = new List<KeyValuePair<string, string>> {
  681. new KeyValuePair<string, string>("分校", "分") ,
  682. new KeyValuePair<string, string>("分园", "分") ,
  683. new KeyValuePair<string, string>("分院", "分") ,
  684. new KeyValuePair<string, string>("藏文", "藏"),
  685. new KeyValuePair<string, string>("职业技术学院", "职") ,
  686. new KeyValuePair<string, string>("创新创业", "创") ,
  687. new KeyValuePair<string, string>("就业创业", "就") ,
  688. new KeyValuePair<string, string>("应用核技术", "核") ,
  689. new KeyValuePair<string, string>("职业学院", "职") ,
  690. new KeyValuePair<string, string>("幼儿园", "幼") ,
  691. new 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. new KeyValuePair<string, string>("成人", "成") ,
  723. new 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. };
  811. public static List<KeyValuePair<string, string>> proReplaceStr = new List<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. };
  847. /*
  848. [
  849. {"method":"台北市","params":{"CountryId":"TW","CityId":"30"}},1
  850. {"method":"新北市","params":{"CountryId":"TW","CityId":"01"}},1
  851. {"method":"桃园市","params":{"CountryId":"TW","CityId":"03"}},1
  852. {"method":"台中市","params":{"CountryId":"TW","CityId":"66"}},1
  853. {"method":"台南市","params":{"CountryId":"TW","CityId":"67"}},1
  854. {"method":"高雄市","params":{"CountryId":"TW","CityId":"64"}},1
  855. {"method":"基隆市","params":{"CountryId":"TW","CityId":"17"}},1
  856. {"method":"新竹市","params":{"CountryId":"TW","CityId":"18"}},1
  857. {"method":"嘉义市","params":{"CountryId":"TW","CityId":"20"}},1
  858. {"method":"新竹县","params":{"CountryId":"TW","CityId":"04"}},1
  859. {"method":"苗栗县","params":{"CountryId":"TW","CityId":"05"}},1
  860. {"method":"彰化县","params":{"CountryId":"TW","CityId":"07"}},1
  861. {"method":"南投县","params":{"CountryId":"TW","CityId":"08"}},1
  862. {"method":"云林县","params":{"CountryId":"TW","CityId":"09"}},1
  863. {"method":"嘉义县","params":{"CountryId":"TW","CityId":"10"}},1
  864. {"method":"屏东县","params":{"CountryId":"TW","CityId":"13"}},1
  865. {"method":"宜兰县","params":{"CountryId":"TW","CityId":"02"}},1
  866. {"method":"花莲县","params":{"CountryId":"TW","CityId":"15"}},1
  867. {"method":"台东县","params":{"CountryId":"TW","CityId":"14"}},1
  868. {"method":"澎湖县","params":{"CountryId":"TW","CityId":"16"}},1
  869. {"method":"金门县","params":{"CountryId":"TW","CityId":"71"}},
  870. {"method":"连江县","params":{"CountryId":"TW","CityId":"72"}}
  871. ]
  872. */
  873. }
  874. }