SchoolService.cs 85 KB

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