SchoolService.cs 77 KB

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