SchoolService.cs 59 KB

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