SchoolService.cs 77 KB

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