SchoolService.cs 92 KB

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