SchoolService.cs 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356
  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 > 1000000000000) {
  220. date = DateTimeOffset.FromUnixTimeMilliseconds(time);
  221. }
  222. //年级算法
  223. var period = school.period.Find(x => x.id.Equals(periodId));
  224. int? Count = period?.grades?.Count;
  225. List<KeyValuePair<int, string>> yearGrades = new List<KeyValuePair<int, string>>();
  226. if (Count.HasValue)
  227. {
  228. int Day = date.Day;
  229. int Month = date.Month;
  230. int Year = date.Year;
  231. int start = int.Parse($"{Year}0901");
  232. var se = period.semesters.Find(x => x.start == 1);
  233. if (se == null)
  234. {
  235. se = period.semesters.First();
  236. }
  237. string sm = "09";
  238. string sd = "01";
  239. if (se != null)
  240. {
  241. sm = se.month >= 10 ? $"{se.month}" : $"0{se.month}";
  242. sd = se.day >= 10 ? $"{se.day}" : $"0{se.day}";
  243. start = int.Parse($"{Year}{sm}{sd}");
  244. }
  245. int curr = int.Parse(date.ToString("yyyyMMdd"));
  246. //新学年开学时间大于当前时间,计算年级需要减1 20220901-20220408 > 0 则当前20220408是2021年入学的,
  247. //当前时间大于新学年开学时间,计算年级则不需要 20220901-20221203 < 1 则当前20221203是2022年入学的,
  248. //20230901-20230101 > 0 则当前20230101是2022年入学的,
  249. int dis = start - curr;
  250. foreach (int year in years)
  251. {
  252. if (int.Parse($"{year}{sm}{sd}") < curr) {
  253. int grade;
  254. if (dis > 0)
  255. {
  256. grade = Math.Abs((Year - year - 1)) % Count.Value;
  257. }
  258. else
  259. {
  260. grade = Math.Abs((Year - year)) % Count.Value;
  261. }
  262. yearGrades.Add(new KeyValuePair<int, string>(year, $"{grade}"));
  263. }
  264. }
  265. }
  266. return (yearGrades, yearGrades.Select(z=>z.Value).ToHashSet());
  267. }
  268. /// <summary>
  269. /// 根据指定时间或者当前时间获取学期信息
  270. /// </summary>
  271. /// <param name="semesterList"></param>
  272. /// <returns></returns>
  273. public static (Semester currSemester, int studyYear, DateTimeOffset date, DateTimeOffset nextSemester) GetSemester( Period period, string time =null) {
  274. //string time = "2023/05-11";
  275. DateTimeOffset date = default;
  276. if (!(!string.IsNullOrWhiteSpace(time) && DateTimeOffset.TryParse(time, out date)))
  277. {
  278. //date = DateTimeOffset.FromUnixTimeSeconds(1672506061);
  279. //date = DateTimeOffset.UtcNow;
  280. date = DateTimeOffset.FromUnixTimeSeconds(1662688000);
  281. }
  282. //年级算法
  283. //var period = school.period.Find(x => x.id.Equals(periodId));
  284. List<KeyValuePair<int, string>> yearGrades = new List<KeyValuePair<int, string>>();
  285. int Day = date.Day;
  286. int Month = date.Month;
  287. int Year = date.Year;
  288. string sm = "09";
  289. string sd = "01";
  290. int start = int.Parse($"{Year}{sm}{sd}");
  291. var se = period.semesters.Find(x => x.start == 1);
  292. if (se == null)
  293. {
  294. se = period.semesters.First();
  295. }
  296. if (se != null)
  297. {
  298. sm = se.month >= 10 ? $"{se.month}" : $"0{se.month}";
  299. sd = se.day >= 10 ? $"{se.day}" : $"0{se.day}";
  300. start = int.Parse($"{Year}{sm}{sd}");
  301. }
  302. int curr = int.Parse(date.ToString("yyyyMMdd"));
  303. //新学年开学时间大于当前时间,计算年级需要减1 20220901-20220408 > 0 则当前20220408是2021年入学的,
  304. //当前时间大于新学年开学时间,计算年级则不需要 20220901-20221203 < 0 则当前20221203是2022年入学的,
  305. //20230901-20230101 > 0 则当前20230101是2022年入学的,
  306. int dis = start - curr;
  307. //学年
  308. int studyYear= date.Year;
  309. if (dis > 0)
  310. {
  311. studyYear = Year - 1;
  312. }
  313. else
  314. {
  315. studyYear = Year;
  316. }
  317. Semester semester= null;
  318. //当前学期的下一个学期,默认加180天
  319. DateTimeOffset nextSemester = date.AddDays(180);
  320. var sortSemesters= SortSemester(period.semesters);
  321. int len = sortSemesters.Count;
  322. for (int i = 0; i < len; i++) {
  323. int next= i + 1;
  324. if (next>= len)
  325. {
  326. semester = sortSemesters[i];
  327. nextSemester = DateTimeOffset.Parse($"{studyYear+1}/{sortSemesters[0].month}/{sortSemesters[0].day}");
  328. break;
  329. }
  330. else {
  331. var fdate= DateTimeOffset.Parse($"{studyYear}/{sortSemesters[i].month}/{sortSemesters[i].day}");
  332. long lf = fdate.ToUnixTimeSeconds();
  333. var ndate = DateTimeOffset.Parse($"{studyYear}/{sortSemesters[next].month}/{sortSemesters[next].day}");
  334. long ln = ndate.ToUnixTimeSeconds();
  335. //代表有跨年
  336. if (lf > ln) {
  337. ndate = DateTimeOffset.Parse($"{studyYear+1}/{sortSemesters[next].month}/{sortSemesters[next].day}");
  338. ln = ndate.ToUnixTimeSeconds();
  339. }
  340. var cdate = DateTimeOffset.Parse($"{Year}/{Month}/{Day}");
  341. long lc = fdate.ToUnixTimeSeconds();
  342. if (lc >= lf && lc < ln) {
  343. semester = sortSemesters[i];
  344. nextSemester = DateTimeOffset.Parse($"{studyYear}/{sortSemesters[next].month}/{sortSemesters[next].day}");
  345. //nextSemester = sortSemesters[next];
  346. break;
  347. }
  348. //if (sortSemesters[i].month <=Month && sortSemesters[i].day >= Day && sortSemesters[next].month < Month && sortSemesters[next].day < Day)
  349. //{
  350. // semester = sortSemesters[i];
  351. // nextSemester = DateTimeOffset.Parse($"{studyYear}/{sortSemesters[next].month}/{sortSemesters[next].day}");
  352. // break;
  353. //}
  354. }
  355. }
  356. return (semester,studyYear,date, nextSemester);
  357. }
  358. /// <summary>
  359. /// 处理学期排序
  360. /// </summary>
  361. /// <param name="semesterList"></param>
  362. /// <returns></returns>
  363. public static List<Semester> SortSemester(List<Semester> semesterList)
  364. {
  365. int Year = DateTimeOffset.UtcNow.Year;
  366. List<KeyValuePair<int, Semester>> pairs = new List<KeyValuePair<int, Semester>>();
  367. semesterList.ForEach(se => {
  368. string sm = se.month >= 10 ? $"{se.month}" : $"0{se.month}";
  369. string sd = se.day >= 10 ? $"{se.day}" : $"0{se.day}";
  370. int order = int.Parse($"{Year}{sm}{sd}");
  371. pairs.Add(new KeyValuePair<int, Semester>(order, se));
  372. });
  373. var orderPairs = pairs.OrderBy(z => z.Key);
  374. semesterList = orderPairs.Select(z => z.Value).ToList();
  375. int startIndex = semesterList.FindIndex(z => z.start == 1);
  376. if (startIndex == -1)
  377. {
  378. //未设置学期的情况默认9月份开始的。
  379. startIndex = semesterList.FindIndex(z => z.month == 9);
  380. //如果还未找到,就以排序结果为准
  381. if (startIndex == -1)
  382. {
  383. startIndex = 0;
  384. }
  385. }
  386. if (startIndex > 0)
  387. {
  388. List<Semester> before = semesterList.Take(startIndex).ToList();
  389. List<Semester> after = semesterList.Skip(startIndex).ToList();
  390. semesterList = new List<Semester>();
  391. semesterList.AddRange(after);
  392. semesterList.AddRange(before);
  393. return semesterList;
  394. }
  395. else
  396. {
  397. return semesterList;
  398. }
  399. }
  400. /// <summary>
  401. /// 校验
  402. /// </summary>
  403. /// <param name="courseTaskInsert"></param>
  404. public static CourseTaskInsert CheckCourseTaskInsert(CourseTaskInsert courseTaskInsert,School school,Period period, List<CourseBase> courseBases, List<GroupListDto> groupListDtos, List<Room> rooms, List<SchoolTeacher> schoolTeachers)
  405. {
  406. //学年
  407. if (courseTaskInsert.year < 2000)
  408. {
  409. courseTaskInsert.invalidCode = 17;//学年应大于2000
  410. return courseTaskInsert;
  411. }
  412. //学期
  413. var semester = period.semesters.Where(z => z.id.Equals(courseTaskInsert.semesterId));
  414. if (!semester.Any()) {
  415. courseTaskInsert.invalidCode = 16;//学期不存在
  416. return courseTaskInsert;
  417. }
  418. //课程
  419. var courseBase = courseBases.Where(z => z.id.Equals(courseTaskInsert.courseId));
  420. if (!courseBase.Any())
  421. {
  422. courseTaskInsert.invalidCode = 1;//课程不存在
  423. return courseTaskInsert;
  424. }
  425. //名单
  426. var groupList = groupListDtos.Where(z => z.id.Equals(courseTaskInsert.groupId) && z.type.Equals(courseTaskInsert.type));
  427. if (!groupList.Any())
  428. {
  429. courseTaskInsert.invalidCode = 3;//名单不存在
  430. return courseTaskInsert;
  431. }
  432. //教室
  433. if (!string.IsNullOrWhiteSpace(courseTaskInsert.roomId)) {
  434. var room = rooms.Where(z => z.id.Equals(courseTaskInsert.roomId));
  435. if (!room.Any())
  436. {
  437. courseTaskInsert.invalidCode = 4;//教室不存在
  438. return courseTaskInsert;
  439. }
  440. }
  441. //教师
  442. var teachers = schoolTeachers.Where(z => z.id.Equals(courseTaskInsert.teacherId));
  443. if (!teachers.Any())
  444. {
  445. courseTaskInsert.invalidCode = 2;//教师不存在
  446. return courseTaskInsert;
  447. }
  448. courseTaskInsert.invalidCode = 0;
  449. return courseTaskInsert;
  450. }
  451. 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) {
  452. List<Class> school_classes = new List<Class>();
  453. List<Class> graduate_classes = new List<Class>();
  454. try
  455. {
  456. var client = _azureCosmos.GetCosmosClient();
  457. //取得班级
  458. int nowYear = DateTimeOffset.UtcNow.Year;
  459. int nowMonth = DateTimeOffset.UtcNow.Month;
  460. int nowDay = DateTimeOffset.UtcNow.Day;
  461. //因为修改年级,而导致取消的
  462. List<Class> cancel_graduate_classes = new List<Class>();
  463. string sql = $"SELECT value c FROM c where (c.graduate = 0 or IS_DEFINED(c.graduate) = false) ";
  464. if (periodIds.IsNotEmpty())
  465. {
  466. sql = $"SELECT value c FROM c where c.periodId in ({string.Join(",", periodIds.Select(x => $"'{x}'"))}) ";
  467. }
  468. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<Class>
  469. //(queryText: $"SELECT value c FROM c where (c.graduate = 0 or IS_DEFINED(c.graduate) = false)",
  470. (queryText: sql,
  471. requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Class-{school_base.id}") }))
  472. {
  473. bool isgraduate = false;
  474. if (!string.IsNullOrWhiteSpace(item.periodId))
  475. {
  476. var period = school_base.period.Find(x => x.id.Equals(item.periodId));
  477. if (period != null)
  478. {
  479. var gradeCount = period.grades.Count();
  480. //2022-2016=6(待判断月份日期是否是毕业) 2022-2017=5(未毕业)
  481. if (nowYear - item.year > gradeCount)
  482. {
  483. isgraduate = true;
  484. }
  485. else if (nowYear - item.year == gradeCount)
  486. {
  487. var semester = period.semesters.Find(x => x.start == 1);
  488. if (semester != null)
  489. {
  490. if (nowMonth > semester.month)
  491. {
  492. isgraduate = true;
  493. }
  494. else if (nowMonth == semester.month)
  495. {
  496. if (nowDay >= semester.day)
  497. {
  498. isgraduate = true;
  499. }
  500. else
  501. {
  502. }
  503. }
  504. else { isgraduate = false; }
  505. }
  506. }
  507. else
  508. {
  509. isgraduate = false;
  510. }
  511. }
  512. }
  513. if (isgraduate)
  514. {
  515. graduate_classes.Add(item);
  516. }
  517. else
  518. {
  519. if (item.graduate == 1)
  520. {
  521. item.graduate = 0;
  522. cancel_graduate_classes.Add(item);
  523. }
  524. school_classes.Add(item);
  525. }
  526. }
  527. if (graduate_classes.Any() || cancel_graduate_classes.Any())
  528. {
  529. if (waite == 0)
  530. {
  531. _ = _httpTrigger.RequestHttpTrigger(new { graduate_classes = graduate_classes, cancel_graduate_classes = cancel_graduate_classes, schoolId = $"{school_base.id}" }, _option.Location, "graduate-change");
  532. }
  533. else
  534. {
  535. await _httpTrigger.RequestHttpTrigger(new { graduate_classes = graduate_classes, cancel_graduate_classes = cancel_graduate_classes, schoolId = $"{school_base.id}" }, _option.Location, "graduate-change");
  536. }
  537. }
  538. } catch (Exception ex) {
  539. await _dingDing.SendBotMsg($"{_option.Location},{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
  540. }
  541. return (school_classes,graduate_classes);
  542. }
  543. public static async Task<object> DoScsApiSchool(HttpTrigger _httpTrigger,Dictionary<string,object> dict, Option _option, List<IdNameCode> ignore,
  544. string areaId,string city,string dist, AzureStorageFactory _azureStorage ,DingDing _dingDing, IWebHostEnvironment _environment
  545. )
  546. {
  547. List<ScSchool> tbschools = null;
  548. List<ScSchool> matchSchools = null;
  549. List<ScSchool> schools = null;
  550. List<ScSchool> saveschools = null;
  551. var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
  552. // 5.3.1.18根据机构ID、项目ID、子项目ID返回学校列表
  553. ( int status, string json) = await _httpTrigger.RequestHttpTrigger(dict, _option.Location, "GetSchoolList");
  554. if (status == 200)
  555. {
  556. schools = json.ToObject<List<ScSchool>>(new JsonSerializerOptions { PropertyNameCaseInsensitive = false });
  557. if (ignore.IsNotEmpty())
  558. {
  559. matchSchools = schools.FindAll(x => ignore.Select(y => y.name).Contains(x.schoolname));
  560. if (matchSchools.IsNotEmpty())
  561. {
  562. if (matchSchools.Count != ignore.Count)
  563. {
  564. var matched = matchSchools.Select(x => x.schoolname);
  565. var unmatch = ignore.Select(y => y.name).Except(matched);
  566. List<string> scschoolUnmatch = schools.Select(y => y.schoolname).Except(matched).ToList();
  567. if (scschoolUnmatch.IsNotEmpty())
  568. {
  569. return new { matched, unmatch, scschoolUnmatch };
  570. }
  571. }
  572. else
  573. {
  574. matchSchools.ForEach(x => {
  575. var exschool = ignore.Find(y => y.name.Equals(x.schoolname));
  576. if (exschool != null)
  577. {
  578. x.schoolCode = exschool.id;
  579. x.areaId = $"{areaId}";
  580. x.city = $"{city}";
  581. x.dist = $"{dist}";
  582. }
  583. });
  584. }
  585. }
  586. else
  587. {
  588. return new { unmatch = ignore, schools };
  589. }
  590. }
  591. //数据校验
  592. tbschools = await table.FindListByDict<ScSchool>(new Dictionary<string, object>() { { "PartitionKey", "ScSchool" } });
  593. if (tbschools.IsNotEmpty())
  594. {
  595. var a = tbschools.Select(y => $"{y.RowKey}").ToList();
  596. saveschools = schools.Where(x => !a.Exists(z => z.Equals($"{x.schoolid}"))).ToList();
  597. List<SchoolData> schoolDatas = new List<SchoolData>();
  598. saveschools.ForEach(x =>
  599. {
  600. x.RowKey = $"{x.schoolid}";
  601. x.PartitionKey = "ScSchool";
  602. x.areaId = $"{areaId}";
  603. x.city = $"{city}";
  604. x.dist = $"{dist}";
  605. if (string.IsNullOrEmpty(x.schoolCode))
  606. {
  607. if (string.IsNullOrEmpty(x.schoolCode))
  608. {
  609. schoolDatas.Add(new SchoolData { uid = $"{x.schoolid}", province = "四川省", city = $"{city}", name = x.schoolname });
  610. }
  611. }
  612. });
  613. schoolDatas = await SchoolService.GenerateSchoolCode(schoolDatas, _dingDing, _environment);
  614. saveschools.ForEach(x => {
  615. var schoolData = schoolDatas.Find(y => y.uid.Equals($"{x.schoolid}"));
  616. if (schoolData != null && !string.IsNullOrEmpty(schoolData.id))
  617. {
  618. x.schoolCode = schoolData.id;
  619. x.areaId = $"{areaId}";
  620. x.city = $"{city}";
  621. x.dist = $"{dist}";
  622. }
  623. });
  624. saveschools.RemoveAll(x => string.IsNullOrEmpty(x.schoolCode));
  625. saveschools.RemoveAll(x => tbschools.FindAll(z => !string.IsNullOrEmpty(z.schoolCode)).Exists(y => y.schoolCode.Equals(x.schoolCode)));
  626. saveschools = await table.SaveAll(saveschools);
  627. }
  628. else
  629. {
  630. List<SchoolData> schoolDatas = new List<SchoolData>();
  631. schools.ForEach(x =>
  632. {
  633. x.RowKey = $"{x.schoolid}";
  634. x.PartitionKey = "ScSchool";
  635. x.areaId = $"{areaId}";
  636. x.city = $"{city}";
  637. x.dist = $"{dist}";
  638. var a = ignore.Find(z => z.name.Equals(x.schoolname));
  639. if (a != null)
  640. {
  641. x.schoolCode = a.id;
  642. }
  643. else
  644. {
  645. if (string.IsNullOrEmpty(x.schoolCode))
  646. {
  647. schoolDatas.Add(new SchoolData { uid = $"{x.schoolid}", province = "四川省", city = $"{city}", name = x.schoolname });
  648. }
  649. }
  650. });
  651. schoolDatas = await SchoolService.GenerateSchoolCode(schoolDatas, _dingDing, _environment);
  652. schools.ForEach(x => {
  653. var schoolData = schoolDatas.Find(y => y.uid.Equals($"{x.schoolid}"));
  654. if (schoolData != null && !string.IsNullOrEmpty(schoolData.id))
  655. {
  656. x.schoolCode = schoolData.id;
  657. x.areaId = $"{areaId}";
  658. x.city = $"{city}";
  659. x.dist = $"{dist}";
  660. }
  661. });
  662. schools.RemoveAll(x => string.IsNullOrEmpty(x.schoolCode));
  663. saveschools = await table.SaveOrUpdateAll(schools);
  664. }
  665. }
  666. return null;
  667. }
  668. public static async Task<List<SchoolData>> GenerateSchoolCode(List<SchoolData> schools, DingDing _dingDing, IWebHostEnvironment _environment)
  669. {
  670. string path = $"{_environment.ContentRootPath}/JsonFile/Core/region.json";
  671. //var schools = jsonstr.ToObject<JsonElement>().GetProperty("schools").ToObject<List<SchoolData>>();
  672. schools = schools.Where((x, i) => schools.FindIndex(n => n.name.Equals(x.name)) == i).ToList();
  673. StreamReader streamReader = new StreamReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.UTF8);
  674. StringBuilder stringBuilder = new StringBuilder();
  675. string text;
  676. while ((text = streamReader.ReadLine()) != null)
  677. {
  678. stringBuilder.Append(text.ToString());
  679. }
  680. streamReader.Close();
  681. string input = stringBuilder.ToString();
  682. List<Region> region = input.ToObject<List<Region>>();
  683. try
  684. {
  685. schools.ForEach(x =>
  686. {
  687. x.province = ChineseConverter.Convert(x.province, ChineseConversionDirection.TraditionalToSimplified);
  688. if (String.IsNullOrEmpty(x.city))
  689. {
  690. x.city = x.province;
  691. }
  692. else
  693. {
  694. x.city = ChineseConverter.Convert(x.city, ChineseConversionDirection.TraditionalToSimplified);
  695. }
  696. x.name = ChineseConverter.Convert(x.name, ChineseConversionDirection.TraditionalToSimplified);
  697. comeRemoveStr.ForEach(c => { x.province = x.province.Replace(c, ""); });
  698. prvcRemoveStr.ForEach(c => { x.province = x.province.Replace(c, ""); });
  699. var province = region.Find(r => r.name.Contains(x.province));
  700. string tmpprovince = x.province;
  701. string tmpcity = x.city;
  702. if (province != null)
  703. {
  704. x.province = province.name;
  705. comeRemoveStr.ForEach(c => { x.city = x.city.Replace(c, ""); });
  706. cityRemoveStr.ForEach(c => { x.city = x.city.Replace(c, ""); });
  707. nationRemoveStr.ForEach(c => { x.city = x.city.Replace(c, ""); });
  708. tmpcity = x.city;
  709. var city = province.children.Find(r => r.name.Contains(x.city));
  710. if (city == null)
  711. {
  712. city = province.children.Find(r => r.name.Contains(x.city));
  713. if (city == null)
  714. {
  715. city = province.children.SelectMany(x => x.children).ToList().Find(r => r.name.Contains(x.city));
  716. }
  717. }
  718. if (city != null)
  719. {
  720. x.city = city.name;
  721. }
  722. }
  723. string name = x.name;
  724. //去除冗余的学校信息,只保留地名和校名关键信息
  725. schemoveStr.ForEach(str =>
  726. {
  727. name = name.Replace(str, "");
  728. });
  729. string[] names = name.Split("(");
  730. if (names.Length > 1)
  731. {
  732. name = $"{names[0]}";
  733. for (int index = 1; index < names.Length; index++)
  734. {
  735. name = $"{name}{names[index].Substring(0, 1)}";
  736. var afnames = names[index].Split(")");
  737. if (afnames.Length > 1)
  738. {
  739. for (int i = 1; i < afnames.Length; i++)
  740. {
  741. name = $"{name}{afnames[i]}";
  742. }
  743. }
  744. }
  745. }
  746. names = name.Split("(");
  747. if (names.Length > 1)
  748. {
  749. name = $"{names[0]}";
  750. for (int index = 1; index < names.Length; index++)
  751. {
  752. name = $"{name}{names[index].Substring(0, 1)}";
  753. var afnames = names[index].Split(")");
  754. if (afnames.Length > 1)
  755. {
  756. for (int i = 1; i < afnames.Length; i++)
  757. {
  758. name = $"{name}{afnames[i]}";
  759. }
  760. }
  761. }
  762. }
  763. name = Regex.Replace(name, "[ \\[ \\] \\^ \\-|()【】/' {}_*×――(^)$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]", " ");
  764. //检查是否有英文
  765. if (Regex.Matches(name, "[a-zA-Z]").Count > 0)
  766. {
  767. var array = Regex.Split(name, "\\s+", RegexOptions.IgnoreCase);
  768. StringBuilder tmpname = new StringBuilder();
  769. if (array.Length > 1)
  770. {
  771. foreach (var item in array)
  772. {
  773. var arr = item.Select(x => $"{x}");
  774. int index = 0;
  775. foreach (var stra in arr)
  776. {
  777. if (Regex.Matches(stra, "[a-zA-Z]").Count > 0)
  778. {
  779. if (index == 1|| index == 0)
  780. {
  781. tmpname.Append(stra);
  782. }
  783. else
  784. {
  785. }
  786. }
  787. else
  788. {
  789. tmpname.Append(stra);
  790. }
  791. index++;
  792. }
  793. }
  794. }
  795. else
  796. {
  797. var arr = name.Select(x => $"{x}");
  798. int index = 0;
  799. foreach (var stra in arr)
  800. {
  801. if (Regex.Matches(stra, "[A-Z]").Count > 0)
  802. {
  803. tmpname.Append(stra);
  804. }
  805. else if (Regex.Matches(stra, "[a-z]").Count > 0)
  806. {
  807. }
  808. else
  809. {
  810. tmpname.Append(stra);
  811. }
  812. index++;
  813. }
  814. }
  815. name = tmpname.ToString();
  816. }
  817. name = Regex.Replace(name, @"\s", "");
  818. name = name.Replace("\\", "");
  819. if (name.Length > 6)
  820. {
  821. //新区,高新,产业等非新政单位
  822. areaRemoveStr.ForEach(str =>
  823. {
  824. name = name.Replace(str.Key, str.Value);
  825. });
  826. //去除冗余的学校信息,只保留地名和校名关键信息
  827. schooRemoveStr.ForEach(str =>
  828. {
  829. name = name.Replace(str, "");
  830. });
  831. //替换民族信息词
  832. if (name.Length > 6)
  833. {
  834. nationRemoveStr.ForEach(str =>
  835. {
  836. name = name.Replace(str, "");
  837. });
  838. }
  839. //替换学校信息的副词
  840. if (name.Length > 6)
  841. {
  842. foreach (var str in schooReplaceStr)
  843. {
  844. if (name.Length <= 6)
  845. {
  846. break;
  847. }
  848. name = name.Replace(str.Key, str.Value);
  849. }
  850. }
  851. //替换省简称信息词
  852. string tmpname = name;
  853. if (name.Length > 6)
  854. {
  855. proReplaceStr.ForEach(str =>
  856. {
  857. name = name.Replace(str.Key, str.Value);
  858. });
  859. //如果替换后仍然大于6位,则取消,直接替换省份完整的词
  860. if (name.Length > 6)
  861. {
  862. name = tmpname.Replace(tmpprovince, "");
  863. }
  864. }
  865. //替换城市信息词
  866. if (name.Length > 6)
  867. {
  868. name = name.Replace(tmpcity, "");
  869. }
  870. }
  871. int len = name.Length;
  872. if (len > 6)
  873. {
  874. foreach (var str in afterSchoolRm)
  875. {
  876. if (name.Length <= 6)
  877. {
  878. break;
  879. }
  880. name = name.Replace(str, "");
  881. }
  882. }
  883. len = name.Length;
  884. if (len >= 6)
  885. {
  886. name = $"{name.Substring(0, 1)}{name.Substring(len - 5, 3)}{name.Substring(len - 2, 2)}";
  887. }
  888. //if (len <= 7 && len > 6)
  889. //{
  890. // name = name.Substring(len - 6);
  891. //}
  892. if (len <= 4)
  893. {
  894. name = $"{x.city.Substring(0, 2)}{name}";
  895. }
  896. if (len == 5)
  897. {
  898. name = $"{x.city.Substring(0, 1)}{name}";
  899. }
  900. string code = ToFirstPinYin(name);
  901. x.aname = name;
  902. x.id = code;
  903. });
  904. }
  905. catch (Exception ex)
  906. {
  907. await _dingDing.SendBotMsg($"{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  908. }
  909. string a_z = "abcdefghijklmnopqrstuvwxyz";
  910. 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();
  911. data.ForEach(x =>
  912. {
  913. if (x.count > 1)
  914. {
  915. var first = x.list.First();
  916. var same = x.list.Skip(1).Take(x.count - 1).ToList();
  917. var fs = first.aname.Select(x => x).ToArray();
  918. same.ForEach(z =>
  919. {
  920. var sp = z.aname.Select(x => x).ToArray();
  921. int len = sp.Length;
  922. if (sp.Length >= fs.Length)
  923. {
  924. len = fs.Count();
  925. }
  926. for (int index = 0; index < len; index++)
  927. {
  928. if (!$"{sp[index]}".Equals($"{fs[index]}"))
  929. {
  930. short st = ChineseChar.GetStrokeNumber(sp[index]);
  931. if (st > 0)
  932. {
  933. var ins = st % 27;
  934. var insch = a_z[ins];
  935. if (z.aname.EndsWith($"{insch}"))
  936. {
  937. ins = (st + 1) % 27;
  938. insch = a_z[ins];
  939. }
  940. z.id = z.id.Insert(index, $"{insch}").Remove(index + 1, 1);
  941. break;
  942. }
  943. }
  944. }
  945. });
  946. }
  947. });
  948. 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();
  949. dataz.ForEach(x =>
  950. {
  951. if (x.count > 1)
  952. {
  953. var first = x.list.First();
  954. var same = x.list.Skip(1).Take(x.count - 1).ToList();
  955. var fs = first.aname.Select(x => x).ToArray();
  956. same.ForEach(z =>
  957. {
  958. var sp = z.aname.Select(x => x).ToArray();
  959. int len = sp.Length;
  960. if (sp.Length >= fs.Length)
  961. {
  962. len = fs.Count();
  963. }
  964. for (int index = 0; index < len; index++)
  965. {
  966. if (!$"{sp[index]}".Equals($"{fs[index]}"))
  967. {
  968. var spstr = ToPinYin($"{sp[index]}" );
  969. var fsstr = ToPinYin($"{fs[index]}");
  970. var insch= spstr.Select(x => $"{x}").Except( fsstr.Select(z => $"{z}"));
  971. if (insch != null && insch.Count() > 0) {
  972. if (index > 1)
  973. {
  974. z.id = z.id.Insert(index - 1, insch.First()).Remove(index, 1);
  975. }
  976. else if (index == 1)
  977. {
  978. z.id = z.id.Insert(index, insch.First()).Remove(index - 1, 1);
  979. }
  980. }
  981. }
  982. }
  983. });
  984. }
  985. });
  986. 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();
  987. Random random = new Random();
  988. List<SchoolData> list = new List<SchoolData>();
  989. dataa.ForEach(x =>
  990. {
  991. if (x.count > 1)
  992. {
  993. x.list.ForEach(y => {
  994. int r= random.Next(25);
  995. int index= random.Next(5);
  996. y.id = y.id.Insert(index - 1, $"{a_z[r]}").Remove(index, 1);
  997. });
  998. }
  999. list.AddRange(x.list);
  1000. });
  1001. return list;
  1002. }
  1003. public static string ToPinYin(string val)
  1004. {
  1005. StringBuilder sb = new StringBuilder();
  1006. val.ToCharArray().ToList().ForEach(x =>
  1007. {
  1008. if (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z') || ('0' <= x && x <= '9'))
  1009. {
  1010. sb.Append(x);
  1011. }
  1012. else
  1013. {
  1014. try
  1015. {
  1016. ChineseChar cc = new ChineseChar(x);
  1017. if (cc.Pinyins.Count > 0 && cc.Pinyins[0].Length > 0)
  1018. {
  1019. sb.Append(cc.Pinyins[0]);
  1020. }
  1021. }
  1022. catch (Exception ex)
  1023. {
  1024. }
  1025. }
  1026. });
  1027. return sb.ToString().ToLower();
  1028. }
  1029. public static string ToFirstPinYin(string val)
  1030. {
  1031. StringBuilder sb = new StringBuilder();
  1032. val.ToCharArray().ToList().ForEach(x =>
  1033. {
  1034. if (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z') || ('0' <= x && x <= '9'))
  1035. {
  1036. sb.Append(x);
  1037. }
  1038. else
  1039. {
  1040. try
  1041. {
  1042. ChineseChar cc = new ChineseChar(x);
  1043. if (cc.Pinyins.Count > 0 && cc.Pinyins[0].Length > 0)
  1044. {
  1045. sb.Append(cc.Pinyins[0][0]);
  1046. }
  1047. }
  1048. catch (Exception ex)
  1049. {
  1050. }
  1051. }
  1052. });
  1053. return sb.ToString().ToLower();
  1054. }
  1055. public class SchoolData
  1056. {
  1057. public string province { get; set; }
  1058. public string id { get; set; }
  1059. public string name { get; set; }
  1060. public string city { get; set; }
  1061. public string aname { get; set; }
  1062. public string uid { get; set; }
  1063. }
  1064. public static List<string> comeRemoveStr = new List<string>() { "省", "市", "区", "州", "县", "旗", "盟", "自治" };
  1065. public static List<string> prvcRemoveStr = new List<string>() { "回族", "维吾尔", "壮族", };
  1066. public static List<string> cityRemoveStr = new List<string>() { "蒙古族", "地区", "壮族", "朝鲜族", "直辖" };
  1067. public static List<string> nationRemoveStr = new List<string> {
  1068. "维吾尔","回族", "自治", "满族", "蒙古", "壮族", "苗族" , "侗族", "瑶族",
  1069. "达斡尔","鄂温克","朝鲜","畲族","土家","各族","仫佬","毛南","羌族","彝族","仡佬","布依","水族",
  1070. "傣族","纳西","哈尼","拉祜","佤族","傈僳","独龙","怒族","白族","普米","固族","哈萨克","土族","撒拉","景颇","族"
  1071. };
  1072. public static List<string> schemoveStr = new List<string> { "第", "校区", "部", "楼", "与", "学校", "校园", };
  1073. public static List<string> schooRemoveStr = new List<string>() {"省", "市", "区", "州", "县", "旗", "盟","办事处","街道", "自治",
  1074. "镇","村","乡","街","路","站","馆"
  1075. };
  1076. public static List<string> afterSchoolRm = new List<string>() {"校","园","院", "湾","峡","沟","山","庄",
  1077. "堡","江","屯","岭","溪","河","桥","营","铺","坡","寨","场","湖","巷","集","关","庙","寺","矿","塘"};
  1078. public static List<KeyValuePair<string, string>> areaRemoveStr = new List<KeyValuePair<string, string>>{
  1079. new KeyValuePair<string, string>("高新技术产业开发区", "高") ,
  1080. new KeyValuePair<string, string>("经济技术开发区", "经") ,
  1081. new KeyValuePair<string, string>("国际", "际") ,
  1082. new KeyValuePair<string, string>("中国", ""),
  1083. new KeyValuePair<string, string>("国家", ""),
  1084. new KeyValuePair<string, string>("新区", ""),
  1085. new KeyValuePair<string, string>("高新", "高"),
  1086. new KeyValuePair<string, string>("园区", ""),
  1087. new KeyValuePair<string, string>("产业", "产"),
  1088. new KeyValuePair<string, string>("经济", "经"),
  1089. new KeyValuePair<string, string>("开发", "开"),
  1090. new KeyValuePair<string, string>("中心", "") ,
  1091. new KeyValuePair<string, string>("集团", "") ,
  1092. new KeyValuePair<string, string>("公司", "") ,
  1093. new KeyValuePair<string, string>("有限", "") ,
  1094. new KeyValuePair<string, string>("股份", "") ,
  1095. new KeyValuePair<string, string>("服务", "") ,
  1096. new KeyValuePair<string, string>("基地", "") ,
  1097. new KeyValuePair<string, string>("社区", "社") ,
  1098. new KeyValuePair<string, string>("职工", "") ,
  1099. new KeyValuePair<string, string>("专修", ""),
  1100. new KeyValuePair<string, string>("实验", "验"),
  1101. new KeyValuePair<string, string>("完全", ""),
  1102. new KeyValuePair<string, string>("一贯制", "") ,
  1103. new KeyValuePair<string, string>("联办", ""),
  1104. new KeyValuePair<string, string>("联合", ""),
  1105. new KeyValuePair<string, string>("完小", "小"),
  1106. new KeyValuePair<string, string>("义务", ""),
  1107. new KeyValuePair<string, string>("基础", ""),
  1108. new KeyValuePair<string, string>("制造", "")
  1109. };
  1110. public static List<KeyValuePair<string, string>> schooReplaceStr = new List<KeyValuePair<string, string>> {
  1111. new KeyValuePair<string, string>("分校", "分") ,
  1112. new KeyValuePair<string, string>("分园", "分") ,
  1113. new KeyValuePair<string, string>("分院", "分") ,
  1114. new KeyValuePair<string, string>("藏文", "藏"),
  1115. new KeyValuePair<string, string>("职业技术学院", "职") ,
  1116. new KeyValuePair<string, string>("创新创业", "创") ,
  1117. new KeyValuePair<string, string>("就业创业", "就") ,
  1118. new KeyValuePair<string, string>("应用核技术", "核") ,
  1119. new KeyValuePair<string, string>("职业学院", "职") ,
  1120. new KeyValuePair<string, string>("幼儿园", "幼") ,
  1121. new KeyValuePair<string, string>("幼儿", "幼") ,
  1122. new KeyValuePair<string, string>("小学", "小") ,
  1123. new KeyValuePair<string, string>("中学", "中") ,
  1124. new KeyValuePair<string, string>("中等", "中") ,
  1125. new KeyValuePair<string, string>("双语", "双") ,
  1126. new KeyValuePair<string, string>("初中", "初") ,
  1127. new KeyValuePair<string, string>("初级", "初") ,
  1128. new KeyValuePair<string, string>("广播", "广"),
  1129. new KeyValuePair<string, string>("高中", "高") ,
  1130. new KeyValuePair<string, string>("高级", "高") ,
  1131. new KeyValuePair<string, string>("大学", "大") ,
  1132. new KeyValuePair<string, string>("学院", "院") ,
  1133. new KeyValuePair<string, string>("综合", "综") ,
  1134. new KeyValuePair<string, string>("职业", "职") ,
  1135. new KeyValuePair<string, string>("技术", "技") ,
  1136. new KeyValuePair<string, string>("专科", "专") ,
  1137. new KeyValuePair<string, string>("外国语", "外") ,
  1138. new KeyValuePair<string, string>("九年", "九") ,
  1139. new KeyValuePair<string, string>("五年", "五") ,
  1140. new KeyValuePair<string, string>("年制", "制") ,
  1141. new KeyValuePair<string, string>("高等", "高") ,
  1142. new KeyValuePair<string, string>("院校", "院") ,
  1143. new KeyValuePair<string, string>("初等", "小") ,
  1144. new KeyValuePair<string, string>("附属", "附"),
  1145. new KeyValuePair<string, string>("寄宿制", "寄") ,
  1146. new KeyValuePair<string, string>("寄宿", "寄") ,
  1147. new KeyValuePair<string, string>("卫生", "卫") ,
  1148. new KeyValuePair<string, string>("创业", "创") ,
  1149. new KeyValuePair<string, string>("继续", "继") ,
  1150. new KeyValuePair<string, string>("开放", "开") ,
  1151. new KeyValuePair<string, string>("技师", "技") ,
  1152. new KeyValuePair<string, string>("成人", "成") ,
  1153. new KeyValuePair<string, string>("教育", "教") ,
  1154. new KeyValuePair<string, string>("科技", "科") ,
  1155. new KeyValuePair<string, string>("行政", "政") ,
  1156. new KeyValuePair<string, string>("生物", "生") ,
  1157. new KeyValuePair<string, string>("美术", "美") ,
  1158. new KeyValuePair<string, string>("设计", "设") ,
  1159. new KeyValuePair<string, string>("传播", "传") ,
  1160. new KeyValuePair<string, string>("计算机", "算") ,
  1161. new KeyValuePair<string, string>("土木", "土") ,
  1162. new KeyValuePair<string, string>("石油", "油") ,
  1163. new KeyValuePair<string, string>("科普", "普") ,
  1164. new KeyValuePair<string, string>("电信", "信") ,
  1165. new KeyValuePair<string, string>("联合", "联") ,
  1166. new KeyValuePair<string, string>("电商", "商") ,
  1167. new KeyValuePair<string, string>("纺织", "织") ,
  1168. new KeyValuePair<string, string>("服装", "服") ,
  1169. new KeyValuePair<string, string>("新闻", "新") ,
  1170. new KeyValuePair<string, string>("网络", "网") ,
  1171. new KeyValuePair<string, string>("应用", "应") ,
  1172. new KeyValuePair<string, string>("畜牧", "畜") ,
  1173. new KeyValuePair<string, string>("兽医", "兽") ,
  1174. new KeyValuePair<string, string>("师范", "师") ,
  1175. new KeyValuePair<string, string>("人文", "文") ,
  1176. new KeyValuePair<string, string>("创新", "创") ,
  1177. new KeyValuePair<string, string>("法官", "法") ,
  1178. new KeyValuePair<string, string>("邮电", "邮") ,
  1179. new KeyValuePair<string, string>("文化", "文") ,
  1180. new KeyValuePair<string, string>("函授", "函") ,
  1181. new KeyValuePair<string, string>("科学", "科") ,
  1182. new KeyValuePair<string, string>("信息", "息") ,
  1183. new KeyValuePair<string, string>("水利", "利") ,
  1184. new KeyValuePair<string, string>("水电", "电") ,
  1185. new KeyValuePair<string, string>("电力", "力") ,
  1186. new KeyValuePair<string, string>("环境", "环") ,
  1187. new KeyValuePair<string, string>("建材", "材") ,
  1188. new KeyValuePair<string, string>("机电", "机") ,
  1189. new KeyValuePair<string, string>("航空", "空") ,
  1190. new KeyValuePair<string, string>("航天", "天") ,
  1191. new KeyValuePair<string, string>("警察", "警") ,
  1192. new KeyValuePair<string, string>("警官", "警") ,
  1193. new KeyValuePair<string, string>("财贸", "财") ,
  1194. new KeyValuePair<string, string>("电子", "电") ,
  1195. new KeyValuePair<string, string>("建筑", "筑") ,
  1196. new KeyValuePair<string, string>("艺术", "艺") ,
  1197. new KeyValuePair<string, string>("体育", "体") ,
  1198. new KeyValuePair<string, string>("城市", "城") ,
  1199. new KeyValuePair<string, string>("地质", "地") ,
  1200. new KeyValuePair<string, string>("医药", "药") ,
  1201. new KeyValuePair<string, string>("政法", "法") ,
  1202. new KeyValuePair<string, string>("铁路", "铁") ,
  1203. new KeyValuePair<string, string>("铁道", "道") ,
  1204. new KeyValuePair<string, string>("轨道", "轨") ,
  1205. new KeyValuePair<string, string>("交通", "通") ,
  1206. new KeyValuePair<string, string>("医学院", "医") ,
  1207. new KeyValuePair<string, string>("医学", "医") ,
  1208. new KeyValuePair<string, string>("传媒", "媒") ,
  1209. new KeyValuePair<string, string>("工程", "程") ,
  1210. new KeyValuePair<string, string>("临床", "临") ,
  1211. new KeyValuePair<string, string>("化工", "化") ,
  1212. new KeyValuePair<string, string>("林业", "林") ,
  1213. new KeyValuePair<string, string>("老年", "老") ,
  1214. new KeyValuePair<string, string>("旅游", "游") ,
  1215. new KeyValuePair<string, string>("护理", "护") ,
  1216. new KeyValuePair<string, string>("贸易", "贸") ,
  1217. new KeyValuePair<string, string>("中医药", "中医") ,
  1218. new KeyValuePair<string, string>("资源", "源") ,
  1219. new KeyValuePair<string, string>("冶金", "冶") ,
  1220. new KeyValuePair<string, string>("能源", "能") ,
  1221. new KeyValuePair<string, string>("汽车", "车") ,
  1222. new KeyValuePair<string, string>("医科", "医") ,
  1223. new KeyValuePair<string, string>("机械", "械") ,
  1224. new KeyValuePair<string, string>("应用", "应") ,
  1225. new KeyValuePair<string, string>("电气", "电") ,
  1226. new KeyValuePair<string, string>("材料", "材") ,
  1227. new KeyValuePair<string, string>("劳动", "劳") ,
  1228. new KeyValuePair<string, string>("轻工", "轻") ,
  1229. new KeyValuePair<string, string>("农业", "农") ,
  1230. new KeyValuePair<string, string>("委员会", "委") ,
  1231. new KeyValuePair<string, string>("专业", "专") ,
  1232. new KeyValuePair<string, string>("广播", "广"),
  1233. new KeyValuePair<string, string>("电视", "电") ,
  1234. new KeyValuePair<string, string>("工商", "商") ,
  1235. new KeyValuePair<string, string>("工业", "工") ,
  1236. new KeyValuePair<string, string>("管理", "管") ,
  1237. new KeyValuePair<string, string>("社会主义", "社") ,
  1238. new KeyValuePair<string, string>("社会", "社") ,
  1239. new KeyValuePair<string, string>("自动化", "自") ,
  1240. };
  1241. public static List<KeyValuePair<string, string>> proReplaceStr = new List<KeyValuePair<string, string>> {
  1242. new KeyValuePair<string, string>("北京","京") ,
  1243. new KeyValuePair<string, string>("天津","津") ,
  1244. new KeyValuePair<string, string>("河北","冀") ,
  1245. new KeyValuePair<string, string>("山西","晋") ,
  1246. new KeyValuePair<string, string>("内蒙古","蒙") ,
  1247. new KeyValuePair<string, string>("辽宁","辽") ,
  1248. new KeyValuePair<string, string>("吉林","吉") ,
  1249. new KeyValuePair<string, string>("黑龙江","黑") ,
  1250. new KeyValuePair<string, string>("上海","沪") ,
  1251. new KeyValuePair<string, string>("江苏","苏") ,
  1252. new KeyValuePair<string, string>("浙江","浙") ,
  1253. new KeyValuePair<string, string>("安徽","皖") ,
  1254. new KeyValuePair<string, string>("福建","闽") ,
  1255. new KeyValuePair<string, string>("江西","赣") ,
  1256. new KeyValuePair<string, string>("山东","鲁") ,
  1257. new KeyValuePair<string, string>("河南","豫") ,
  1258. new KeyValuePair<string, string>("湖北","鄂") ,
  1259. new KeyValuePair<string, string>("湖南","湘") ,
  1260. new KeyValuePair<string, string>("广东","粤") ,
  1261. new KeyValuePair<string, string>("广西","桂") ,
  1262. new KeyValuePair<string, string>("海南","琼") ,
  1263. new KeyValuePair<string, string>("四川","川") ,
  1264. new KeyValuePair<string, string>("贵州","贵") ,
  1265. new KeyValuePair<string, string>("云南","云") ,
  1266. new KeyValuePair<string, string>("重庆","渝") ,
  1267. new KeyValuePair<string, string>("西藏","藏") ,
  1268. new KeyValuePair<string, string>("陕西","陕") ,
  1269. new KeyValuePair<string, string>("甘肃","甘") ,
  1270. new KeyValuePair<string, string>("青海","青") ,
  1271. new KeyValuePair<string, string>("宁夏","宁") ,
  1272. new KeyValuePair<string, string>("新疆","新") ,
  1273. new KeyValuePair<string, string>("香港","港") ,
  1274. new KeyValuePair<string, string>("澳门","澳") ,
  1275. new KeyValuePair<string, string>("台湾","台")
  1276. };
  1277. /*
  1278. [
  1279. {"method":"台北市","params":{"CountryId":"TW","CityId":"30"}},1
  1280. {"method":"新北市","params":{"CountryId":"TW","CityId":"01"}},1
  1281. {"method":"桃园市","params":{"CountryId":"TW","CityId":"03"}},1
  1282. {"method":"台中市","params":{"CountryId":"TW","CityId":"66"}},1
  1283. {"method":"台南市","params":{"CountryId":"TW","CityId":"67"}},1
  1284. {"method":"高雄市","params":{"CountryId":"TW","CityId":"64"}},1
  1285. {"method":"基隆市","params":{"CountryId":"TW","CityId":"17"}},1
  1286. {"method":"新竹市","params":{"CountryId":"TW","CityId":"18"}},1
  1287. {"method":"嘉义市","params":{"CountryId":"TW","CityId":"20"}},1
  1288. {"method":"新竹县","params":{"CountryId":"TW","CityId":"04"}},1
  1289. {"method":"苗栗县","params":{"CountryId":"TW","CityId":"05"}},1
  1290. {"method":"彰化县","params":{"CountryId":"TW","CityId":"07"}},1
  1291. {"method":"南投县","params":{"CountryId":"TW","CityId":"08"}},1
  1292. {"method":"云林县","params":{"CountryId":"TW","CityId":"09"}},1
  1293. {"method":"嘉义县","params":{"CountryId":"TW","CityId":"10"}},1
  1294. {"method":"屏东县","params":{"CountryId":"TW","CityId":"13"}},1
  1295. {"method":"宜兰县","params":{"CountryId":"TW","CityId":"02"}},1
  1296. {"method":"花莲县","params":{"CountryId":"TW","CityId":"15"}},1
  1297. {"method":"台东县","params":{"CountryId":"TW","CityId":"14"}},1
  1298. {"method":"澎湖县","params":{"CountryId":"TW","CityId":"16"}},1
  1299. {"method":"金门县","params":{"CountryId":"TW","CityId":"71"}},
  1300. {"method":"连江县","params":{"CountryId":"TW","CityId":"72"}}
  1301. ]
  1302. */
  1303. }
  1304. }