SchoolService.cs 43 KB

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