SchoolService.cs 82 KB

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