SchoolService.cs 93 KB

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