123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965 |
- using Microsoft.Azure.Cosmos;
- using Azure.Storage.Blobs.Models;
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.Extensions.Configuration;
- using Microsoft.Extensions.Hosting;
- using Microsoft.International.Converters.PinYinConverter;
- using Microsoft.International.Converters.TraditionalChineseToSimplifiedConverter;
- using System;
- using System.Collections.Generic;
- using System.Configuration;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Text.Json;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- using TEAMModelOS.Models;
- using TEAMModelOS.SDK.DI;
- using TEAMModelOS.SDK.Extension;
- using TEAMModelOS.SDK.Models;
- using Period = TEAMModelOS.SDK.Models.Period;
- namespace TEAMModelOS.SDK
- {
- public class SchoolService
- {
- public static async Task<School> ModifySchool(School school, AzureCosmosFactory _azureCosmos) {
- //修补科目关联
- var subjects = school.period.SelectMany(x => x.subjects).Where(y => (!string.IsNullOrWhiteSpace(y.bindId) &&
- (y.bindId.Equals("subject_painting") || y.bindId.Equals("subject_sport")
- || y.bindId.Equals("subject_labour") || y.bindId.Equals("subject_virtue") || y.bindId.Equals("subject_music")
- || y.bindId.Equals("subject_chinese") || y.bindId.Equals("subject_math") || y.bindId.Equals("subject_english")
- || y.bindId.Equals("subject_physics") || y.bindId.Equals("subject_chemistry") || y.bindId.Equals("subject_biology")
- || y.bindId.Equals("subject_politics") || y.bindId.Equals("subject_history") || y.bindId.Equals("subject_geography")
- ))
- || y.name.Contains("音乐") || y.name.Contains("美术") || y.name.Contains("劳动") || y.name.Contains("德育") || y.name.Contains("体育")
- || y.name.Contains("语文") || y.name.Contains("数学") || y.name.Contains("英语") || y.name.Contains("物理") || y.name.Contains("化学")
- || y.name.Contains("生物") || y.name.Contains("政治") || y.name.Contains("历史") || y.name.Contains("地理")
- );
- if (subjects.Any())
- {
- bool change = false;
- foreach (var subject in subjects)
- {
- if (string.IsNullOrWhiteSpace(subject.bindId) && subject.name.Contains("语文"))
- {
- subject.bindId="subject_chinese";
- change= true;
- }
- if (string.IsNullOrWhiteSpace(subject.bindId) && subject.name.Contains("数学"))
- {
- subject.bindId="subject_math";
- change= true;
- }
- if (string.IsNullOrWhiteSpace(subject.bindId) && subject.name.Contains("英语"))
- {
- subject.bindId="subject_english";
- change= true;
- }
- if (string.IsNullOrWhiteSpace(subject.bindId) && subject.name.Contains("物理"))
- {
- subject.bindId="subject_physics";
- change= true;
- }
- if (string.IsNullOrWhiteSpace(subject.bindId) && subject.name.Contains("化学"))
- {
- subject.bindId="subject_chemistry";
- change= true;
- }
- if (string.IsNullOrWhiteSpace(subject.bindId) && subject.name.Contains("生物"))
- {
- subject.bindId="subject_biology";
- change= true;
- }
- if (string.IsNullOrWhiteSpace(subject.bindId) && subject.name.Contains("政治"))
- {
- subject.bindId="subject_politics";
- change= true;
- }
- if (string.IsNullOrWhiteSpace(subject.bindId) && subject.name.Contains("历史"))
- {
- subject.bindId="subject_history";
- change= true;
- }
- if (string.IsNullOrWhiteSpace(subject.bindId) && subject.name.Contains("地理"))
- {
- subject.bindId="subject_geography";
- change= true;
- }
- if (string.IsNullOrWhiteSpace(subject.bindId) && subject.name.Contains("音乐"))
- {
- subject.bindId="subject_music";
- change= true;
- }
- if (string.IsNullOrWhiteSpace(subject.bindId) && subject.name.Contains("美术"))
- {
- subject.bindId="subject_painting";
- change= true;
- }
- if (string.IsNullOrWhiteSpace(subject.bindId) && subject.name.Contains("劳动"))
- {
- subject.bindId="subject_labour";
- change= true;
- }
- if (string.IsNullOrWhiteSpace(subject.bindId) && subject.name.Contains("德育"))
- {
- subject.bindId="subject_virtue";
- change= true;
- }
- if (string.IsNullOrWhiteSpace(subject.bindId) && subject.name.Contains("体育"))
- {
- subject.bindId="subject_sport";
- change= true;
- }
- }
- {
- foreach (var period in school.period)
- {
- if (string.IsNullOrWhiteSpace(period.periodType))
- {
- if (period.name.Contains("小学"))
- {
- change= true;
- period.periodType= "primary";
- }
- if (period.name.Contains("初中"))
- {
- change= true;
- period.periodType = "junior";
- }
- if (period.name.Contains("高中"))
- {
- change= true;
- period.periodType = "senior";
- }
- }
- if (string.IsNullOrWhiteSpace(period.periodType) && school.period.Count == 1)
- {
- if (school.name.Contains("幼儿园"))
- {
- change= true;
- period.periodType = "pre";
- }
- if (school.name.Contains("小学"))
- {
- change= true;
- period.periodType = "primary";
- }
- if (school.name.Contains("初中"))
- {
- change= true;
- period.periodType = "junior";
- }
- if (school.name.Contains("高中"))
- {
- change= true;
- period.periodType = "senior";
- }
- }
-
- }
- }
- if (change)
- {
- School schoolSelf = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).UpsertItemAsync<School>(school, new PartitionKey("Base"));
- }
- }
- return school;
- }
- public static async Task<(int code, string msg, object data)> JoinScool(string school, string id, string name, string picture, long ts,
- AzureCosmosFactory _azureCosmos,AzureStorageFactory _azureStorage,CoreAPIHttpService _coreAPIHttpService,DingDing _dingDing,Option _option,IConfiguration _configuration, IWebHostEnvironment _environment)
- {
- SchoolTeacher schoolTeacher = null;
- School schoolInfo = null;
- long nowTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
- try
- {
- if (nowTime - ts > 3600000)
- {
- return (1, "超时!", null);
- }
- var client = _azureCosmos.GetCosmosClient();
- try
- {
- schoolInfo = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>($"{school}", new PartitionKey("Base"));
- }
- catch (CosmosException ex)
- {
- if (ex.StatusCode == System.Net.HttpStatusCode.NotFound)
- {
- return (2, "该学校不存在!", null);
- }
- }
- Teacher teacher = null;
- try
- {
- teacher = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Teacher>($"{id}", new PartitionKey("Base"));
- var sch = teacher.schools.Find(x => x.schoolId.Equals($"{school}"));
- if (sch != null)
- {
- if (sch.status.Equals("join"))
- {
- return (3, "该教师之前已经加入学校!", null);
- }
- else
- {
- sch.status = "join";
- sch.time = nowTime;
- sch.name = schoolInfo?.name;
- sch.picture = schoolInfo?.picture;
- sch.areaId = schoolInfo?.areaId;
- }
- }
- else
- {
- teacher.schools.Add(new Teacher.TeacherSchool { areaId = schoolInfo?.areaId, schoolId = schoolInfo.id, status = "join", name = schoolInfo.name, picture = schoolInfo.picture, time = nowTime });
- }
- if (teacher.size < 2)
- {
- teacher.size = 2;
- }
- await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey($"Base"));
- }
- catch (CosmosException ex)
- {
- if (ex.StatusCode == System.Net.HttpStatusCode.NotFound)
- {
- //如果沒有,則初始化Teacher基本資料到Cosmos
- teacher = new Teacher
- {
- createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
- id = id,
- pk = "Base",
- code = "Base",
- name = name?.ToString(),
- // picture = picture?.ToString(),
- //创建账号并第一次登录IES5则默认赠送1G
- defaultSchool = null,
- size = 2,
- schools = new List<Teacher.TeacherSchool>() { new Teacher.TeacherSchool { areaId = schoolInfo?.areaId, schoolId = schoolInfo.id, status = "join", name = schoolInfo.name, picture = schoolInfo.picture, time = nowTime } }
- };
- var container = _azureStorage.GetBlobContainerClient(id);
- await container.CreateIfNotExistsAsync(PublicAccessType.None); //嘗試創建Teacher私有容器,如存在則不做任何事,保障容器一定存在
- await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<Teacher>(teacher, new PartitionKey("Base"));
- }
- }
- ResponseMessage response = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync(teacher.id, new PartitionKey($"Teacher-{schoolInfo.id}"));
- if (response.StatusCode != System.Net.HttpStatusCode.OK)
- {
- schoolTeacher = new SchoolTeacher
- {
- id = teacher.id,
- pk = "Teacher",
- name = teacher.name,
- picture = teacher.picture,
- size = 0,
- roles = new List<string> { "teacher" },
- permissions = new List<string>(),
- status = "join",
- createTime = nowTime,
- code = $"Teacher-{schoolInfo.id}",
- ttl = -1
- };
- await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<SchoolTeacher>(schoolTeacher, new PartitionKey($"Teacher-{schoolInfo.id}"));
- }
- else
- {
- JsonElement data = JsonDocument.Parse(response.Content).RootElement;
- schoolTeacher = data.ToObject<SchoolTeacher>();
- schoolTeacher.status = "join";
- schoolTeacher.name = schoolInfo.name;
- schoolTeacher.picture = schoolInfo.picture;
- await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReplaceItemAsync<SchoolTeacher>(schoolTeacher, schoolTeacher.id, new PartitionKey($"Teacher-{schoolInfo.id}"));
- }
- //通知管理员
- string sql = "select distinct value(c.id) from c where array_contains(c.roles,'admin')";
- List<string> ids = new List<string>();
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIteratorSql<string>(queryText: sql,
- requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Teacher-{school}") }))
- {
- ids.Add(item);
- }
- string bizcode = "scan-join";
- string tsql = $"select c.id, c.name ,c.lang as code from c where c.id in ({string.Join(",", ids.Select(x => $"'{x}'"))})";
- List<IdNameCode> idNameCodes = new List<IdNameCode>();
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher)
- .GetItemQueryIteratorSql<IdNameCode>(queryText: tsql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
- {
- idNameCodes.Add(item);
- }
- _coreAPIHttpService.PushNotify(idNameCodes, $"{bizcode}_school", Constant.NotifyType_IES5_Management,
- new Dictionary<string, object> { { "tmdname", teacher.name }, { "schoolName", schoolInfo.name }, { "schoolId", $"{school}" }, { "tmdid", teacher.id } }, _option.Location, _configuration, _dingDing, _environment.ContentRootPath);
- }
- catch (Exception ae)
- {
- await _dingDing.SendBotMsg($"HiTA扫码加入学校失败!{ae.Message},{ae.StackTrace}", GroupNames.成都开发測試群組);
- }
- return (200, "ok", new { schoolTeacher.roles, schoolTeacher.status, school = $"{school}", schoolInfo.name, schoolInfo.picture });
- }
- /// <summary>
- /// 根据年级获取入学年
- /// </summary>
- /// <param name="semesterList"></param>
- /// <returns></returns>
- public static (List<KeyValuePair<int, int>> gradeYear, HashSet<int> years) GetYears(School school, string periodId, IEnumerable<int> grades,long timestamp=0, string time = null) {
- var date = DateTimeOffset.UtcNow;
- //2001-09-09 09:46:40
- bool hasData = false;
- if (timestamp > 1000000000)
- {
- //毫秒级
- if (timestamp > 1000000000000)
- {
- date = DateTimeOffset.FromUnixTimeMilliseconds(timestamp);
- hasData = true;
- }
- //秒级
- else
- {
- date = DateTimeOffset.FromUnixTimeSeconds(timestamp);
- hasData =true;
- }
- }
- if (hasData==false)
- {
- if (!string.IsNullOrWhiteSpace(time))
- {
- if (DateTimeOffset.TryParse(time, out date))
- {
- if (date.ToUnixTimeMilliseconds()<1514736000000)
- {
- date = DateTimeOffset.UtcNow;
- }
- }
- else
- {
- date = DateTimeOffset.UtcNow;
- }
- }
- else
- {
- date = DateTimeOffset.UtcNow;
- }
- }
- //年级算法
- var period = school.period.Find(x => x.id.Equals(periodId));
-
- int Day = date.Day;
- int Month = date.Month;
- int Year = date.Year;
- int start = int.Parse($"{Year}0901");
- var se = period.semesters.Find(x => x.start == 1);
- if (se == null)
- {
- se = period.semesters.First();
- }
- string sm = "09";
- string sd = "01";
- if (se != null)
- {
- sm = se.month >= 10 ? $"{se.month}" : $"0{se.month}";
- sd = se.day >= 10 ? $"{se.day}" : $"0{se.day}";
- start = int.Parse($"{Year}{sm}{sd}");
- }
- int curr = int.Parse(date.ToString("yyyyMMdd"));
- //新学年开学时间大于当前时间,计算年级需要减1 20220901-20220408 > 0 则当前20220408是2021年入学的,
- //当前时间大于新学年开学时间,计算年级则不需要 20220901-20221203 < 1 则当前20221203是2022年入学的,
- //20230901-20230101 > 0 则当前20230101是2022年入学的,
- int dis = start - curr;
- List<int > years= new List<int>();
- List<KeyValuePair<int, int>> gradeYear = new List<KeyValuePair<int, int>>();
- foreach (int grade in grades) {
- int year = 0;
- if (dis > 0)
- {
- year = Year - grade -1;
- }
- else {
- year= Year - grade ;
- }
- years.Add(year);
- gradeYear.Add(new KeyValuePair<int, int>(grade,year ));
- }
- return (gradeYear,years.ToHashSet());
- }
- /// <summary>
- /// 根据年份获取年级,只返回time 或当前时间以前入学的学生年级。
- /// </summary>
- /// <param name="semesterList"></param>
- /// <returns></returns>
- public static (List<KeyValuePair<int, string>> yearGrade,HashSet<string> grades) GetGrades(School school,string periodId , IEnumerable<int> years,long timestamp = 0,string time =null) {
-
- var date = DateTimeOffset.UtcNow;
- //2001-09-09 09:46:40
- bool hasData = false;
- if (timestamp > 1000000000)
- {
- //毫秒级
- if (timestamp > 1000000000000)
- {
- date = DateTimeOffset.FromUnixTimeMilliseconds(timestamp);
- hasData = true;
- }
- //秒级
- else
- {
- date = DateTimeOffset.FromUnixTimeSeconds(timestamp);
- hasData =true;
- }
- }
- if (hasData==false)
- {
- if (!string.IsNullOrWhiteSpace(time))
- {
- if (DateTimeOffset.TryParse(time, out date))
- {
- if (date.ToUnixTimeMilliseconds()<1514736000000)
- {
- date = DateTimeOffset.UtcNow;
- }
- }
- else
- {
- date = DateTimeOffset.UtcNow;
- }
- }
- else
- {
- date = DateTimeOffset.UtcNow;
- }
- }
- //年级算法
- var period = school.period.Find(x => x.id.Equals(periodId));
- int? Count = period?.grades?.Count;
- List<KeyValuePair<int, string>> yearGrades = new List<KeyValuePair<int, string>>();
- if (Count.HasValue)
- {
- int Day = date.Day;
- int Month = date.Month;
- int Year = date.Year;
- int start = int.Parse($"{Year}0901");
- var se = period.semesters.Find(x => x.start == 1);
- if (se == null)
- {
- se = period.semesters.First();
- }
- string sm = "09";
- string sd = "01";
- if (se != null)
- {
- sm = se.month >= 10 ? $"{se.month}" : $"0{se.month}";
- sd = se.day >= 10 ? $"{se.day}" : $"0{se.day}";
- start = int.Parse($"{Year}{sm}{sd}");
- }
- int curr = int.Parse(date.ToString("yyyyMMdd"));
- //新学年开学时间大于当前时间,计算年级需要减1 20220901-20220408 > 0 则当前20220408是2021年入学的,
- //当前时间大于新学年开学时间,计算年级则不需要 20220901-20221203 < 1 则当前20221203是2022年入学的,
- //20230901-20230101 > 0 则当前20230101是2022年入学的,
- int dis = start - curr;
- foreach (int year in years)
- {
- if (int.Parse($"{year}{sm}{sd}") < curr) {
- int grade;
- if (dis > 0)
- {
- grade = Math.Abs((Year - year - 1)) % Count.Value;
- }
- else
- {
- grade = Math.Abs((Year - year)) % Count.Value;
- }
- yearGrades.Add(new KeyValuePair<int, string>(year, $"{grade}"));
- }
- }
- }
- return (yearGrades, yearGrades.Select(z=>z.Value).ToHashSet());
- }
- public static (Semester currSemester, int studyYear, DateTimeOffset date, DateTimeOffset nextSemester) GetSemesterNew(Period period, long timestamp = 0, string time = null)
- {
- //string time = "2023/05-11";
- DateTimeOffset date = DateTimeOffset.Now;
- bool hasData = false;
- if (timestamp > 1000000000)
- {
- //毫秒级
- if (timestamp > 1000000000000)
- {
- date = DateTimeOffset.FromUnixTimeMilliseconds(timestamp);
- hasData = true;
- }
- //秒级
- else
- {
- date = DateTimeOffset.FromUnixTimeSeconds(timestamp);
- hasData =true;
- }
- }
- if (hasData==false)
- {
- if (!string.IsNullOrWhiteSpace(time))
- {
- if (DateTimeOffset.TryParse(time, out date))
- {
- if (date.ToUnixTimeMilliseconds()<1514736000000) {
- date = DateTimeOffset.UtcNow;
- }
- }
- else
- {
- date = DateTimeOffset.UtcNow;
- }
- }
- else
- {
- date = DateTimeOffset.UtcNow;
- }
- }
- int Day = date.Day;
- int Month = date.Month;
- int Year = date.Year;
- string sm = "09";
- string sd = "01";
- int start = int.Parse($"{Year}{sm}{sd}");
- var se = period.semesters.Find(x => x.start == 1);
- if (se == null)
- {
- se = period.semesters.First();
- }
- if (se != null)
- {
- sm = se.month >= 10 ? $"{se.month}" : $"0{se.month}";
- sd = se.day >= 10 ? $"{se.day}" : $"0{se.day}";
- start = int.Parse($"{Year}{sm}{sd}");
- }
- int curr = int.Parse(date.ToString("yyyyMMdd"));
- //新学年开学时间大于当前时间,计算年级需要减1 20220901-20220408 > 0 则当前20220408是2021年入学的,
- //当前时间大于新学年开学时间,计算年级则不需要 20220901-20221203 < 0 则当前20221203是2022年入学的,
- //20230901-20230101 > 0 则当前20230101是2022年入学的,
- int dis = start - curr;
- //学年
- int studyYear = date.Year;
- if (dis > 0)
- {
- studyYear = Year - 1;
- }
- else
- {
- studyYear = Year;
- }
- Semester semester = null;
- //当前学期的下一个学期,默认加180天
- DateTimeOffset nextSemester = date.AddDays(180);
- var sortSemesters = SortSemester(period.semesters);
- int len = sortSemesters.Count;
- for (int i = 0; i < len; i++)
- {
- int next = i + 1;
- if (next>= len)
- {
- semester = sortSemesters[i];
- nextSemester = DateTimeOffset.Parse($"{studyYear+1}/{sortSemesters[0].month}/{sortSemesters[0].day}");
- break;
- }
- else
- {
- var fdate = DateTimeOffset.Parse($"{studyYear}/{sortSemesters[i].month}/{sortSemesters[i].day}");
- long lf = fdate.ToUnixTimeSeconds();
- var ndate = DateTimeOffset.Parse($"{studyYear}/{sortSemesters[next].month}/{sortSemesters[next].day}");
- long ln = ndate.ToUnixTimeSeconds();
- //代表有跨年
- if (lf > ln)
- {
- ndate = DateTimeOffset.Parse($"{studyYear+1}/{sortSemesters[next].month}/{sortSemesters[next].day}");
- ln = ndate.ToUnixTimeSeconds();
- }
- var cdate = DateTimeOffset.Parse($"{Year}/{Month}/{Day}");
- long lc = cdate.ToUnixTimeSeconds();
- if (lc >= lf && lc < ln)
- {
- semester = sortSemesters[i];
- nextSemester = DateTimeOffset.Parse($"{studyYear+1}/{sortSemesters[next].month}/{sortSemesters[next].day}");
- //nextSemester = sortSemesters[next];
- break;
- }
- //if (sortSemesters[i].month <=Month && sortSemesters[i].day >= Day && sortSemesters[next].month < Month && sortSemesters[next].day < Day)
- //{
- // semester = sortSemesters[i];
- // nextSemester = DateTimeOffset.Parse($"{studyYear}/{sortSemesters[next].month}/{sortSemesters[next].day}");
- // break;
- //}
- }
- }
- return (semester, studyYear, date, nextSemester);
- }
- /// <summary>
- /// 根据指定时间或者当前时间获取学期信息
- /// </summary>
- /// <param name="semesterList"></param>
- /// <returns></returns>
- public static (Semester currSemester, int studyYear, DateTimeOffset currSemesterDate, DateTimeOffset date, DateTimeOffset nextSemester) GetSemester( Period period, long timestamp = 0, string time =null) {
- //string time = "2023/05-11";
- DateTimeOffset date = default;
- bool hasData=false;
- if (timestamp > 1000000000) {
- //毫秒级
- if (timestamp > 1000000000000)
- {
- date = DateTimeOffset.FromUnixTimeMilliseconds(timestamp);
- hasData=true;
- }
- //秒级
- else {
- date = DateTimeOffset.FromUnixTimeSeconds(timestamp);
- hasData=true;
- }
- }
- if (hasData==false) {
- if (!string.IsNullOrWhiteSpace(time))
- {
- if (DateTimeOffset.TryParse(time, out date))
- {
- if (date.ToUnixTimeMilliseconds()<1514736000000)
- {
- date = DateTimeOffset.UtcNow;
- }
- }
- else
- {
- date = DateTimeOffset.UtcNow;
- }
- }
- else
- {
- date = DateTimeOffset.UtcNow;
- }
- }
-
- //年级算法
- //var period = school.period.Find(x => x.id.Equals(periodId));
- List<KeyValuePair<int, string>> yearGrades = new List<KeyValuePair<int, string>>();
- int Day = date.Day;
- int Month = date.Month;
- int Year = date.Year;
- string sm = "09";
- string sd = "01";
- int start = int.Parse($"{Year}{sm}{sd}");
- var se = period.semesters.Find(x => x.start == 1);
- if (se == null)
- {
- se = period.semesters.First();
- }
-
- if (se != null)
- {
- sm = se.month >= 10 ? $"{se.month}" : $"0{se.month}";
- sd = se.day >= 10 ? $"{se.day}" : $"0{se.day}";
- start = int.Parse($"{Year}{sm}{sd}");
- }
- int curr = int.Parse(date.ToString("yyyyMMdd"));
- //新学年开学时间大于当前时间,计算年级需要减1 20220901-20220408 > 0 则当前20220408是2021年入学的,
- //当前时间大于新学年开学时间,计算年级则不需要 20220901-20221203 < 0 则当前20221203是2022年入学的,
- //20230901-20230101 > 0 则当前20230101是2022年入学的,
- int dis = start - curr;
- //学年
- int studyYear= date.Year;
- if (dis > 0)
- {
- studyYear = Year - 1;
- }
- else
- {
- studyYear = Year;
- }
- Semester semester= null;
- //当前学期的下一个学期,默认加180天
- DateTimeOffset nextSemester = date.AddDays(180);
- DateTimeOffset currSemesterDate = default;
- var sortSemesters= SortSemester(period.semesters);
- int len = sortSemesters.Count;
- int currSemesterYear = studyYear;
- for (int i = 0; i < len; i++) {
- int next= i + 1;
- if (next>= len)
- {
- semester = sortSemesters[i];
-
- nextSemester = DateTimeOffset.Parse($"{studyYear+1}/{sortSemesters[0].month}/{sortSemesters[0].day}");
- currSemesterDate=DateTimeOffset.Parse($"{currSemesterYear}/{semester.month}/{semester.day}");
- if (currSemesterDate.Subtract(nextSemester).TotalDays>0) {
- currSemesterDate=DateTimeOffset.Parse($"{currSemesterYear-1}/{semester.month}/{semester.day}");
- }
- break;
- }
- else {
- var fdate= DateTimeOffset.Parse($"{studyYear}/{sortSemesters[i].month}/{sortSemesters[i].day}");
- long lf = fdate.ToUnixTimeSeconds();
- var ndate = DateTimeOffset.Parse($"{studyYear}/{sortSemesters[next].month}/{sortSemesters[next].day}");
- long ln = ndate.ToUnixTimeSeconds();
- //代表有跨年
- if (lf > ln) {
- currSemesterYear=studyYear+1;
- ndate = DateTimeOffset.Parse($"{studyYear+1}/{sortSemesters[next].month}/{sortSemesters[next].day}");
- ln = ndate.ToUnixTimeSeconds();
- }
- var cdate = DateTimeOffset.Parse($"{Year}/{Month}/{Day}");
- long lc = cdate.ToUnixTimeSeconds();
- if (lc >= lf && lc < ln) {
- semester = sortSemesters[i];
- nextSemester = DateTimeOffset.Parse($"{studyYear+1}/{sortSemesters[next].month}/{sortSemesters[next].day}");
- currSemesterDate=DateTimeOffset.Parse($"{currSemesterYear}/{semester.month}/{semester.day}");
- if (currSemesterDate.Subtract(nextSemester).TotalDays>0)
- {
- currSemesterDate=DateTimeOffset.Parse($"{currSemesterYear-1}/{semester.month}/{semester.day}");
- }
- break;
- }
- //if (sortSemesters[i].month <=Month && sortSemesters[i].day >= Day && sortSemesters[next].month < Month && sortSemesters[next].day < Day)
- //{
- // semester = sortSemesters[i];
- // nextSemester = DateTimeOffset.Parse($"{studyYear}/{sortSemesters[next].month}/{sortSemesters[next].day}");
- // break;
- //}
- }
- }
- return (semester,studyYear, currSemesterDate, date, nextSemester);
- }
- /// <summary>
- /// 处理学期排序
- /// </summary>
- /// <param name="semesterList"></param>
- /// <returns></returns>
- public static List<Semester> SortSemester(List<Semester> semesterList)
- {
- int Year = DateTimeOffset.UtcNow.Year;
- List<KeyValuePair<int, Semester>> pairs = new List<KeyValuePair<int, Semester>>();
- semesterList.ForEach(se => {
- string sm = se.month >= 10 ? $"{se.month}" : $"0{se.month}";
- string sd = se.day >= 10 ? $"{se.day}" : $"0{se.day}";
- int order = int.Parse($"{Year}{sm}{sd}");
- pairs.Add(new KeyValuePair<int, Semester>(order, se));
- });
- var orderPairs = pairs.OrderBy(z => z.Key);
- semesterList = orderPairs.Select(z => z.Value).ToList();
- int startIndex = semesterList.FindIndex(z => z.start == 1);
- if (startIndex == -1)
- {
- //未设置学期的情况默认9月份开始的。
- startIndex = semesterList.FindIndex(z => z.month == 9);
- //如果还未找到,就以排序结果为准
- if (startIndex == -1)
- {
- startIndex = 0;
- }
- }
- if (startIndex > 0)
- {
- List<Semester> before = semesterList.Take(startIndex).ToList();
- List<Semester> after = semesterList.Skip(startIndex).ToList();
- semesterList = new List<Semester>();
- semesterList.AddRange(after);
- semesterList.AddRange(before);
- return semesterList;
- }
- else
- {
- return semesterList;
- }
- }
- /// <summary>
- /// 获取指定学年,指定学期的开学时间。
- /// </summary>
- /// <param name="semesterList"></param>
- /// <returns></returns>
- public static string GetOpensByStudyYearAndSemester(List<Semester> semesterList,int year ,string semesterId)
- {
- int Year = DateTimeOffset.UtcNow.Year;
- List<KeyValuePair<int, Semester>> pairs = new List<KeyValuePair<int, Semester>>();
- semesterList.ForEach(se => {
- string sm = se.month >= 10 ? $"{se.month}" : $"0{se.month}";
- string sd = se.day >= 10 ? $"{se.day}" : $"0{se.day}";
- int order = int.Parse($"{Year}{sm}{sd}");
- pairs.Add(new KeyValuePair<int, Semester>(order, se));
- });
- var orderPairs = pairs.OrderBy(z => z.Key);
- semesterList = orderPairs.Select(z => z.Value).ToList();
- int startIndex = semesterList.FindIndex(z => z.start == 1);
- if (startIndex == -1)
- {
- //未设置学期的情况默认9月份开始的。
- startIndex = semesterList.FindIndex(z => z.month == 9);
- //如果还未找到,就以排序结果为准
- if (startIndex == -1)
- {
- startIndex = 0;
- }
- }
- if (startIndex > 0)
- {
- List<Semester> before = semesterList.Take(startIndex).ToList();
- List<Semester> after = semesterList.Skip(startIndex).ToList();
- semesterList = new List<Semester>();
- semesterList.AddRange(after);
- semesterList.AddRange(before);
-
- }
- string time = string.Empty;
- for (int i = 0; i<semesterList.Count; i++) {
- if (semesterList[i].id.Equals(semesterId)) {
- if (i==0)
- {
- time=$"{year}-{semesterList[i].month}-{semesterList[i].day}";
- }
- else {
- string sm1 = semesterList[i-1].month >= 10 ? $"{semesterList[i-1].month}" : $"0{semesterList[i-1].month}";
- string sd1 = semesterList[i-1].day >= 10 ? $"{semesterList[i-1].day}" : $"0{semesterList[i - 1].day}";
- int order1 = int.Parse($"{Year}{sm1}{sd1}");
- string sm2 = semesterList[i].month >= 10 ? $"{semesterList[i].month}" : $"0{semesterList[i].month}";
- string sd2 = semesterList[i].day >= 10 ? $"{semesterList[i].day}" : $"0{semesterList[i].day}";
- int order2 = int.Parse($"{Year}{sm2}{sd2}");
- if (order2<order1)
- {
- time=$"{(year+1)}-{semesterList[i].month}-{semesterList[i].day}";
- }
- else {
- time=$"{year}-{semesterList[i].month}-{semesterList[i].day}";
- }
- }
- }
- }
- return time;
- }
- /// <summary>
- /// 校验
- /// </summary>
- /// <param name="courseTaskInsert"></param>
- public static ScheduleTaskDto CheckCourseTask(string scope, ScheduleTaskDto courseTaskInsert, string school, List<GroupListDto> groupListDtos, List<Room> rooms,
- List<SchoolTeacher> schoolTeachers, List<Teacher> teachers)
- {
- if (scope.Equals("school", StringComparison.OrdinalIgnoreCase))
- {
- //教师
- var schoolteachers = schoolTeachers.Where(z => z.id.Equals(courseTaskInsert.teacherId));
- if (!schoolteachers.Any())
- {
- courseTaskInsert.invalidCode = 2;//教师不存在
- return courseTaskInsert;
- }
- var invalidAssistants= courseTaskInsert.assistants.Except(schoolTeachers.Select(x => x.id));
- if (invalidAssistants != null && invalidAssistants.Any())
- {
- courseTaskInsert.invalidCode = 21;
- courseTaskInsert.invalidMsg = $"{string.Join(",", invalidAssistants)}";
- return courseTaskInsert;
- }
- }
- else
- {
- //教师
- var teachersbase = teachers.Where(z => z.id.Equals(courseTaskInsert.teacherId));
- if (!teachersbase.Any())
- {
- courseTaskInsert.invalidCode = 2;//教师不存在
- return courseTaskInsert;
- }
- var invalidAssistants = courseTaskInsert.assistants.Except(teachers.Select(x => x.id));
- if (invalidAssistants != null && invalidAssistants.Any())
- {
- courseTaskInsert.invalidCode = 21;
- courseTaskInsert.invalidMsg = $"{string.Join(",", invalidAssistants)}";
- return courseTaskInsert;
- }
- }
-
- //名单
- var groupList = groupListDtos.Where(z => z.id.Equals(courseTaskInsert.groupId) && z.type.Equals(courseTaskInsert.type));
- if (!groupList.Any())
- {
- courseTaskInsert.invalidCode = 3;//名单不存在
- return courseTaskInsert;
- }
- else
- {
- if (scope.Equals("private", StringComparison.OrdinalIgnoreCase))
- {
- if (!groupList.First().scope.Equals("private", StringComparison.OrdinalIgnoreCase) && !string.IsNullOrWhiteSpace(school) && school.Equals(groupList.First().school))
- {
- courseTaskInsert.school = school;
- }
- }
- else
- {
- courseTaskInsert.school = school;
- }
- }
- //教室
- if (!string.IsNullOrWhiteSpace(courseTaskInsert.roomId))
- {
- var room = rooms.Where(z => z.id.Equals(courseTaskInsert.roomId));
- if (!room.Any())
- {
- courseTaskInsert.invalidCode = 4;//教室不存在
- return courseTaskInsert;
- }
- }
-
- courseTaskInsert.invalidCode = 0;
- return courseTaskInsert;
- }
- /// <summary>
- /// 校验
- /// </summary>
- /// <param name="courseTaskInsert"></param>
- public static CourseTaskChanged CheckCourseTaskInsertOrChanged(string grant_type, string scope , CourseTaskChanged courseTaskInsert,string school,Period period, List<CourseBase> courseBases, List<GroupListDto> groupListDtos, List<Room> rooms,
- List<SchoolTeacher> schoolTeachers,List<Teacher> teachers)
- {
- if (scope.Equals("school", StringComparison.OrdinalIgnoreCase))
- { //学年
- if (courseTaskInsert.year < 2000)
- {
- courseTaskInsert.invalidCode = 17;//学年应大于2000
- return courseTaskInsert;
- }
- //学期
- var semester = period.semesters.Where(z => z.id.Equals(courseTaskInsert.semesterId));
- if (!semester.Any())
- {
- courseTaskInsert.invalidCode = 16;//学期不存在
- return courseTaskInsert;
- }
- //教师
- var schoolteachers = schoolTeachers.Where(z => z.id.Equals(courseTaskInsert.teacherId));
- if (!schoolteachers.Any())
- {
- courseTaskInsert.invalidCode = 2;//教师不存在
- return courseTaskInsert;
- }
- }
- else {
- //教师
- var teachersbase = teachers.Where(z => z.id.Equals(courseTaskInsert.teacherId));
- if (!teachersbase.Any())
- {
- courseTaskInsert.invalidCode = 2;//教师不存在
- return courseTaskInsert;
- }
- }
- //课程
- var courseBase = courseBases.Where(z => z.id.Equals(courseTaskInsert.courseId));
- if (!courseBase.Any())
- {
- courseTaskInsert.invalidCode = 1;//课程不存在
- return courseTaskInsert;
- }
- //名单
- var groupList = groupListDtos.Where(z => z.id.Equals(courseTaskInsert.groupId) && z.type.Equals(courseTaskInsert.type));
- if (!groupList.Any())
- {
- courseTaskInsert.invalidCode = 3;//名单不存在
- return courseTaskInsert;
- }
- else {
- if (scope.Equals("private", StringComparison.OrdinalIgnoreCase))
- {
- if (!groupList.First().scope.Equals("private", StringComparison.OrdinalIgnoreCase) && !string.IsNullOrWhiteSpace(school) && school.Equals(groupList.First().school))
- {
- courseTaskInsert.school = school;
- }
- }
- else {
- courseTaskInsert.school = school;
- }
- }
- //教室
- if (!string.IsNullOrWhiteSpace(courseTaskInsert.roomId))
- {
- var room = rooms.Where(z => z.id.Equals(courseTaskInsert.roomId));
- if (!room.Any())
- {
- courseTaskInsert.invalidCode = 4;//教室不存在
- return courseTaskInsert;
- }
- }
- if (grant_type.Equals("change-scheduleTask", StringComparison.OrdinalIgnoreCase)) {
- if (!string.IsNullOrWhiteSpace(courseTaskInsert.teacherIdChanged) || (!string.IsNullOrWhiteSpace(courseTaskInsert.groupIdChanged) && !string.IsNullOrWhiteSpace(courseTaskInsert.typeChanged)))
- {
- if (!string.IsNullOrWhiteSpace(courseTaskInsert.teacherIdChanged)) {
- if (scope.Equals("school", StringComparison.OrdinalIgnoreCase))
- {
- //教师
- var schoolteachers = schoolTeachers.Where(z => z.id.Equals(courseTaskInsert.teacherIdChanged));
- if (!schoolteachers.Any())
- {
- courseTaskInsert.invalidCode = 19;//教师不存在
- return courseTaskInsert;
- }
- }
- else {
- //教师
- var teachersbase = teachers.Where(z => z.id.Equals(courseTaskInsert.teacherIdChanged));
- if (!teachersbase.Any())
- {
- courseTaskInsert.invalidCode = 19;//教师不存在
- return courseTaskInsert;
- }
- }
- }
- if (!string.IsNullOrWhiteSpace(courseTaskInsert.groupIdChanged) && !string.IsNullOrWhiteSpace(courseTaskInsert.typeChanged)) {
- //名单
- var groupListChanged = groupListDtos.Where(z => z.id.Equals(courseTaskInsert.groupIdChanged) && z.type.Equals(courseTaskInsert.typeChanged));
- if (!groupListChanged.Any())
- {
- courseTaskInsert.invalidCode = 18;//名单不存在
- return courseTaskInsert;
- }
- else
- {
- if (scope.Equals("private", StringComparison.OrdinalIgnoreCase))
- {
- if (!groupListChanged.First().scope.Equals("private", StringComparison.OrdinalIgnoreCase) && !string.IsNullOrWhiteSpace(school) && school.Equals(groupList.First().school))
- {
- courseTaskInsert.school = school;
- }
- }
- else
- {
- courseTaskInsert.school = school;
- }
- }
- }
- }
- else {
- courseTaskInsert.invalidCode = 17;
- }
- }
- courseTaskInsert.invalidCode = 0;
- return courseTaskInsert;
- }
- 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) {
- List<Class> school_classes = new List<Class>();
- List<Class> graduate_classes = new List<Class>();
- try
- {
- var client = _azureCosmos.GetCosmosClient();
- //取得班级
-
- int nowYear = DateTimeOffset.UtcNow.Year;
- int nowMonth = DateTimeOffset.UtcNow.Month;
- int nowDay = DateTimeOffset.UtcNow.Day;
-
- //因为修改年级,而导致取消的
- List<Class> cancel_graduate_classes = new List<Class>();
- string sql = $"SELECT value c FROM c where (c.graduate = 0 or IS_DEFINED(c.graduate) = false) ";
- if (periodIds.IsNotEmpty())
- {
- sql = $"SELECT value c FROM c where c.periodId in ({string.Join(",", periodIds.Select(x => $"'{x}'"))}) ";
- }
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIteratorSql<Class>
- //(queryText: $"SELECT value c FROM c where (c.graduate = 0 or IS_DEFINED(c.graduate) = false)",
- (queryText: sql,
- requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Class-{school_base.id}") }))
- {
- bool isgraduate = false;
- if (!string.IsNullOrWhiteSpace(item.periodId))
- {
- var period = school_base.period.Find(x => x.id.Equals(item.periodId));
- if (period != null)
- {
- var gradeCount = period.grades.Count();
- //2022-2016=6(待判断月份日期是否是毕业) 2022-2017=5(未毕业)
- if (nowYear - item.year > gradeCount)
- {
- isgraduate = true;
- }
- else if (nowYear - item.year == gradeCount)
- {
- var semester = period.semesters.Find(x => x.start == 1);
- if (semester != null)
- {
- if (nowMonth > semester.month)
- {
- isgraduate = true;
- }
- else if (nowMonth == semester.month)
- {
- if (nowDay >= semester.day)
- {
- isgraduate = true;
- }
- else
- {
- }
- }
- else { isgraduate = false; }
- }
- }
- else
- {
- isgraduate = false;
- }
- }
- }
- if (isgraduate)
- {
- graduate_classes.Add(item);
- }
- else
- {
- if (item.graduate == 1)
- {
- item.graduate = 0;
- cancel_graduate_classes.Add(item);
- }
- school_classes.Add(item);
- }
- }
- if (graduate_classes.Any() || cancel_graduate_classes.Any())
- {
- if (waite == 0)
- {
- _ = _httpTrigger.RequestHttpTrigger(new { graduate_classes = graduate_classes, cancel_graduate_classes = cancel_graduate_classes, schoolId = $"{school_base.id}" }, _option.Location, "graduate-change");
- }
- else
- {
- await _httpTrigger.RequestHttpTrigger(new { graduate_classes = graduate_classes, cancel_graduate_classes = cancel_graduate_classes, schoolId = $"{school_base.id}" }, _option.Location, "graduate-change");
- }
- }
- } catch (Exception ex) {
- await _dingDing.SendBotMsg($"{_option.Location},{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
- }
- return (school_classes,graduate_classes);
- }
- public static async Task<object> DoScsApiSchool(HttpTrigger _httpTrigger,Dictionary<string,object> dict, Option _option, List<IdNameCode> ignore,
- string areaId,string city,string dist, AzureStorageFactory _azureStorage ,DingDing _dingDing, IWebHostEnvironment _environment
- )
- {
- List<ScSchool> tbschools = null;
- List<ScSchool> matchSchools = null;
- List<ScSchool> schools = null;
- List<ScSchool> saveschools = null;
- var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
- // 5.3.1.18根据机构ID、项目ID、子项目ID返回学校列表
- ( int status, string json) = await _httpTrigger.RequestHttpTrigger(dict, _option.Location, "GetSchoolList");
- if (status == 200)
- {
- schools = json.ToObject<List<ScSchool>>(new JsonSerializerOptions { PropertyNameCaseInsensitive = false });
- if (ignore.IsNotEmpty())
- {
- matchSchools = schools.FindAll(x => ignore.Select(y => y.name).Contains(x.schoolname));
- if (matchSchools.IsNotEmpty())
- {
- if (matchSchools.Count != ignore.Count)
- {
- var matched = matchSchools.Select(x => x.schoolname);
- var unmatch = ignore.Select(y => y.name).Except(matched);
- List<string> scschoolUnmatch = schools.Select(y => y.schoolname).Except(matched).ToList();
- if (scschoolUnmatch.IsNotEmpty())
- {
- return new { matched, unmatch, scschoolUnmatch };
- }
- }
- else
- {
- matchSchools.ForEach(x => {
- var exschool = ignore.Find(y => y.name.Equals(x.schoolname));
- if (exschool != null)
- {
- x.schoolCode = exschool.id;
- x.areaId = $"{areaId}";
- x.city = $"{city}";
- x.dist = $"{dist}";
- }
- });
- }
- }
- else
- {
- return new { unmatch = ignore, schools };
- }
- }
- //数据校验
- tbschools = await table.FindListByDict<ScSchool>(new Dictionary<string, object>() { { "PartitionKey", "ScSchool" } });
- if (tbschools.IsNotEmpty())
- {
- var a = tbschools.Select(y => $"{y.RowKey}").ToList();
- saveschools = schools.Where(x => !a.Exists(z => z.Equals($"{x.schoolid}"))).ToList();
- List<SchoolData> schoolDatas = new List<SchoolData>();
- saveschools.ForEach(x =>
- {
- x.RowKey = $"{x.schoolid}";
- x.PartitionKey = "ScSchool";
- x.areaId = $"{areaId}";
- x.city = $"{city}";
- x.dist = $"{dist}";
- if (string.IsNullOrEmpty(x.schoolCode))
- {
- if (string.IsNullOrEmpty(x.schoolCode))
- {
- schoolDatas.Add(new SchoolData { uid = $"{x.schoolid}", province = "四川省", city = $"{city}", name = x.schoolname });
- }
-
- }
- });
- schoolDatas = await SchoolService.GenerateSchoolCode(schoolDatas, _dingDing, _environment);
- saveschools.ForEach(x => {
- var schoolData = schoolDatas.Find(y => y.uid.Equals($"{x.schoolid}"));
- if (schoolData != null && !string.IsNullOrEmpty(schoolData.id))
- {
- x.schoolCode = schoolData.id;
- x.areaId = $"{areaId}";
- x.city = $"{city}";
- x.dist = $"{dist}";
- }
- });
- saveschools.RemoveAll(x => string.IsNullOrEmpty(x.schoolCode));
- saveschools.RemoveAll(x => tbschools.FindAll(z => !string.IsNullOrEmpty(z.schoolCode)).Exists(y => y.schoolCode.Equals(x.schoolCode)));
- saveschools = await table.SaveAll(saveschools);
- }
- else
- {
- List<SchoolData> schoolDatas = new List<SchoolData>();
- schools.ForEach(x =>
- {
- x.RowKey = $"{x.schoolid}";
- x.PartitionKey = "ScSchool";
- x.areaId = $"{areaId}";
- x.city = $"{city}";
- x.dist = $"{dist}";
- var a = ignore.Find(z => z.name.Equals(x.schoolname));
- if (a != null)
- {
- x.schoolCode = a.id;
- }
- else
- {
- if (string.IsNullOrEmpty(x.schoolCode))
- {
- schoolDatas.Add(new SchoolData { uid = $"{x.schoolid}", province = "四川省", city = $"{city}", name = x.schoolname });
- }
- }
- });
- schoolDatas = await SchoolService.GenerateSchoolCode(schoolDatas, _dingDing, _environment);
- schools.ForEach(x => {
- var schoolData = schoolDatas.Find(y => y.uid.Equals($"{x.schoolid}"));
- if (schoolData != null && !string.IsNullOrEmpty(schoolData.id))
- {
- x.schoolCode = schoolData.id;
- x.areaId = $"{areaId}";
- x.city = $"{city}";
- x.dist = $"{dist}";
- }
- });
- schools.RemoveAll(x => string.IsNullOrEmpty(x.schoolCode));
- saveschools = await table.SaveOrUpdateAll(schools);
- }
- }
- return null;
- }
- public static async Task<List<SchoolData>> GenerateSchoolCode(List<SchoolData> schools, DingDing _dingDing, IWebHostEnvironment _environment)
- {
- string path = $"{_environment.ContentRootPath}/JsonFile/Core/region.json";
- //var schools = jsonstr.ToObject<JsonElement>().GetProperty("schools").ToObject<List<SchoolData>>();
- schools = schools.Where((x, i) => schools.FindIndex(n => n.name.Equals(x.name)) == i).ToList();
- StreamReader streamReader = new StreamReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.UTF8);
- StringBuilder stringBuilder = new StringBuilder();
- string text;
- while ((text = streamReader.ReadLine()) != null)
- {
- stringBuilder.Append(text.ToString());
- }
- streamReader.Close();
- string input = stringBuilder.ToString();
- List<Region> region = input.ToObject<List<Region>>();
- try
- {
- schools.ForEach(x =>
- {
- x.province = ChineseConverter.Convert(x.province, ChineseConversionDirection.TraditionalToSimplified);
- if (String.IsNullOrEmpty(x.city))
- {
- x.city = x.province;
- }
- else
- {
- x.city = ChineseConverter.Convert(x.city, ChineseConversionDirection.TraditionalToSimplified);
- }
- x.name = ChineseConverter.Convert(x.name, ChineseConversionDirection.TraditionalToSimplified);
- comeRemoveStr.ForEach(c => { x.province = x.province.Replace(c, ""); });
- prvcRemoveStr.ForEach(c => { x.province = x.province.Replace(c, ""); });
- var province = region.Find(r => r.name.Contains(x.province));
- string tmpprovince = x.province;
- string tmpcity = x.city;
- if (province != null)
- {
- x.province = province.name;
- comeRemoveStr.ForEach(c => { x.city = x.city.Replace(c, ""); });
- cityRemoveStr.ForEach(c => { x.city = x.city.Replace(c, ""); });
- nationRemoveStr.ForEach(c => { x.city = x.city.Replace(c, ""); });
- tmpcity = x.city;
- var city = province.children.Find(r => r.name.Contains(x.city));
- if (city == null)
- {
- city = province.children.Find(r => r.name.Contains(x.city));
- if (city == null)
- {
- city = province.children.SelectMany(x => x.children).ToList().Find(r => r.name.Contains(x.city));
- }
- }
- if (city != null)
- {
- x.city = city.name;
- }
- }
- string name = x.name;
- //去除冗余的学校信息,只保留地名和校名关键信息
- schemoveStr.ForEach(str =>
- {
- name = name.Replace(str, "");
- });
- string[] names = name.Split("(");
- if (names.Length > 1)
- {
- name = $"{names[0]}";
- for (int index = 1; index < names.Length; index++)
- {
- name = $"{name}{names[index].Substring(0, 1)}";
- var afnames = names[index].Split(")");
- if (afnames.Length > 1)
- {
- for (int i = 1; i < afnames.Length; i++)
- {
- name = $"{name}{afnames[i]}";
- }
- }
- }
- }
- names = name.Split("(");
- if (names.Length > 1)
- {
- name = $"{names[0]}";
- for (int index = 1; index < names.Length; index++)
- {
- name = $"{name}{names[index].Substring(0, 1)}";
- var afnames = names[index].Split(")");
- if (afnames.Length > 1)
- {
- for (int i = 1; i < afnames.Length; i++)
- {
- name = $"{name}{afnames[i]}";
- }
- }
- }
- }
- name = Regex.Replace(name, "[ \\[ \\] \\^ \\-|()【】/' {}_*×――(^)$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]", " ");
- //检查是否有英文
- if (Regex.Matches(name, "[a-zA-Z]").Count > 0)
- {
- var array = Regex.Split(name, "\\s+", RegexOptions.IgnoreCase);
- StringBuilder tmpname = new StringBuilder();
- if (array.Length > 1)
- {
- foreach (var item in array)
- {
- var arr = item.Select(x => $"{x}");
- int index = 0;
- foreach (var stra in arr)
- {
- if (Regex.Matches(stra, "[a-zA-Z]").Count > 0)
- {
- if (index == 1|| index == 0)
- {
- tmpname.Append(stra);
- }
- else
- {
- }
- }
- else
- {
- tmpname.Append(stra);
- }
- index++;
- }
- }
- }
- else
- {
- var arr = name.Select(x => $"{x}");
- int index = 0;
- foreach (var stra in arr)
- {
- if (Regex.Matches(stra, "[A-Z]").Count > 0)
- {
- tmpname.Append(stra);
- }
- else if (Regex.Matches(stra, "[a-z]").Count > 0)
- {
- }
- else
- {
- tmpname.Append(stra);
- }
- index++;
- }
- }
- name = tmpname.ToString();
- }
- name = Regex.Replace(name, @"\s", "");
- name = name.Replace("\\", "");
- if (name.Length > 6)
- {
- //新区,高新,产业等非新政单位
- areaRemoveStr.ForEach(str =>
- {
- name = name.Replace(str.Key, str.Value);
- });
- //去除冗余的学校信息,只保留地名和校名关键信息
- schooRemoveStr.ForEach(str =>
- {
- name = name.Replace(str, "");
- });
- //替换民族信息词
- if (name.Length > 6)
- {
- nationRemoveStr.ForEach(str =>
- {
- name = name.Replace(str, "");
- });
- }
- //替换学校信息的副词
- if (name.Length > 6)
- {
- foreach (var str in schooReplaceStr)
- {
- if (name.Length <= 6)
- {
- break;
- }
- name = name.Replace(str.Key, str.Value);
- }
- }
- //替换省简称信息词
- string tmpname = name;
- if (name.Length > 6)
- {
- proReplaceStr.ForEach(str =>
- {
- name = name.Replace(str.Key, str.Value);
- });
- //如果替换后仍然大于6位,则取消,直接替换省份完整的词
- if (name.Length > 6)
- {
- name = tmpname.Replace(tmpprovince, "");
- }
- }
- //替换城市信息词
- if (name.Length > 6)
- {
- name = name.Replace(tmpcity, "");
- }
- }
- int len = name.Length;
- if (len > 6)
- {
- foreach (var str in afterSchoolRm)
- {
- if (name.Length <= 6)
- {
- break;
- }
- name = name.Replace(str, "");
- }
- }
- len = name.Length;
- if (len >= 6)
- {
- name = $"{name.Substring(0, 1)}{name.Substring(len - 5, 3)}{name.Substring(len - 2, 2)}";
- }
- //if (len <= 7 && len > 6)
- //{
- // name = name.Substring(len - 6);
- //}
- if (len <= 4)
- {
- name = $"{x.city.Substring(0, 2)}{name}";
- }
- if (len == 5)
- {
- name = $"{x.city.Substring(0, 1)}{name}";
- }
- string code = ToFirstPinYin(name);
- x.aname = name;
- x.id = code;
- });
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
- }
- string a_z = "abcdefghijklmnopqrstuvwxyz";
- 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();
- data.ForEach(x =>
- {
- if (x.count > 1)
- {
- var first = x.list.First();
- var same = x.list.Skip(1).Take(x.count - 1).ToList();
- var fs = first.aname.Select(x => x).ToArray();
- same.ForEach(z =>
- {
- var sp = z.aname.Select(x => x).ToArray();
- int len = sp.Length;
- if (sp.Length >= fs.Length)
- {
- len = fs.Count();
- }
- for (int index = 0; index < len; index++)
- {
- if (!$"{sp[index]}".Equals($"{fs[index]}"))
- {
- short st = ChineseChar.GetStrokeNumber(sp[index]);
- if (st > 0)
- {
- var ins = st % 27;
- var insch = a_z[ins];
- if (z.aname.EndsWith($"{insch}"))
- {
- ins = (st + 1) % 27;
- insch = a_z[ins];
- }
- z.id = z.id.Insert(index, $"{insch}").Remove(index + 1, 1);
- break;
- }
- }
- }
- });
- }
- });
- 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();
- dataz.ForEach(x =>
- {
- if (x.count > 1)
- {
- var first = x.list.First();
- var same = x.list.Skip(1).Take(x.count - 1).ToList();
- var fs = first.aname.Select(x => x).ToArray();
- same.ForEach(z =>
- {
- var sp = z.aname.Select(x => x).ToArray();
- int len = sp.Length;
- if (sp.Length >= fs.Length)
- {
- len = fs.Count();
- }
- for (int index = 0; index < len; index++)
- {
- if (!$"{sp[index]}".Equals($"{fs[index]}"))
- {
- var spstr = ToPinYin($"{sp[index]}" );
- var fsstr = ToPinYin($"{fs[index]}");
- var insch= spstr.Select(x => $"{x}").Except( fsstr.Select(z => $"{z}"));
- if (insch != null && insch.Count() > 0) {
- if (index > 1)
- {
- z.id = z.id.Insert(index - 1, insch.First()).Remove(index, 1);
- }
- else if (index == 1)
- {
- z.id = z.id.Insert(index, insch.First()).Remove(index - 1, 1);
- }
- }
- }
- }
- });
- }
- });
- 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();
- Random random = new Random();
- List<SchoolData> list = new List<SchoolData>();
- dataa.ForEach(x =>
- {
- if (x.count > 1)
- {
-
- x.list.ForEach(y => {
- int r= random.Next(25);
- int index= random.Next(5);
- y.id = y.id.Insert(index - 1, $"{a_z[r]}").Remove(index, 1);
- });
- }
- list.AddRange(x.list);
- });
- return list;
- }
- public static string ToPinYin(string val)
- {
- StringBuilder sb = new StringBuilder();
- val.ToCharArray().ToList().ForEach(x =>
- {
- if (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z') || ('0' <= x && x <= '9'))
- {
- sb.Append(x);
- }
- else
- {
- try
- {
- ChineseChar cc = new ChineseChar(x);
- if (cc.Pinyins.Count > 0 && cc.Pinyins[0].Length > 0)
- {
- sb.Append(cc.Pinyins[0]);
- }
- }
- catch (Exception ex)
- {
- }
- }
- });
- return sb.ToString().ToLower();
- }
- public static string ToFirstPinYin(string val)
- {
- StringBuilder sb = new StringBuilder();
- val.ToCharArray().ToList().ForEach(x =>
- {
- if (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z') || ('0' <= x && x <= '9'))
- {
- sb.Append(x);
- }
- else
- {
- try
- {
- ChineseChar cc = new ChineseChar(x);
- if (cc.Pinyins.Count > 0 && cc.Pinyins[0].Length > 0)
- {
- sb.Append(cc.Pinyins[0][0]);
- }
- }
- catch (Exception ex)
- {
- }
- }
- });
- return sb.ToString().ToLower();
- }
- public class SchoolData
- {
- public string province { get; set; }
- public string id { get; set; }
- public string name { get; set; }
- public string city { get; set; }
- public string aname { get; set; }
- public string uid { get; set; }
- }
- public static List<string> comeRemoveStr = new List<string>() { "省", "市", "区", "州", "县", "旗", "盟", "自治" };
- public static List<string> prvcRemoveStr = new List<string>() { "回族", "维吾尔", "壮族", };
- public static List<string> cityRemoveStr = new List<string>() { "蒙古族", "地区", "壮族", "朝鲜族", "直辖" };
- public static List<string> nationRemoveStr = new List<string> {
- "维吾尔","回族", "自治", "满族", "蒙古", "壮族", "苗族" , "侗族", "瑶族",
- "达斡尔","鄂温克","朝鲜","畲族","土家","各族","仫佬","毛南","羌族","彝族","仡佬","布依","水族",
- "傣族","纳西","哈尼","拉祜","佤族","傈僳","独龙","怒族","白族","普米","固族","哈萨克","土族","撒拉","景颇","族"
- };
- public static List<string> schemoveStr = new List<string> { "第", "校区", "部", "楼", "与", "学校", "校园", };
- public static List<string> schooRemoveStr = new List<string>() {"省", "市", "区", "州", "县", "旗", "盟","办事处","街道", "自治",
- "镇","村","乡","街","路","站","馆"
- };
- public static List<string> afterSchoolRm = new List<string>() {"校","园","院", "湾","峡","沟","山","庄",
- "堡","江","屯","岭","溪","河","桥","营","铺","坡","寨","场","湖","巷","集","关","庙","寺","矿","塘"};
- public static List<KeyValuePair<string, string>> areaRemoveStr = new List<KeyValuePair<string, string>>{
- new KeyValuePair<string, string>("高新技术产业开发区", "高") ,
- new KeyValuePair<string, string>("经济技术开发区", "经") ,
- new KeyValuePair<string, string>("国际", "际") ,
- new KeyValuePair<string, string>("中国", ""),
- new KeyValuePair<string, string>("国家", ""),
- new KeyValuePair<string, string>("新区", ""),
- new KeyValuePair<string, string>("高新", "高"),
- new KeyValuePair<string, string>("园区", ""),
- new KeyValuePair<string, string>("产业", "产"),
- new KeyValuePair<string, string>("经济", "经"),
- new KeyValuePair<string, string>("开发", "开"),
- new KeyValuePair<string, string>("中心", "") ,
- new KeyValuePair<string, string>("集团", "") ,
- new KeyValuePair<string, string>("公司", "") ,
- new KeyValuePair<string, string>("有限", "") ,
- new KeyValuePair<string, string>("股份", "") ,
- new KeyValuePair<string, string>("服务", "") ,
- new KeyValuePair<string, string>("基地", "") ,
- new KeyValuePair<string, string>("社区", "社") ,
- new KeyValuePair<string, string>("职工", "") ,
- new KeyValuePair<string, string>("专修", ""),
- new KeyValuePair<string, string>("实验", "验"),
- new KeyValuePair<string, string>("完全", ""),
- new KeyValuePair<string, string>("一贯制", "") ,
- new KeyValuePair<string, string>("联办", ""),
- new KeyValuePair<string, string>("联合", ""),
- new KeyValuePair<string, string>("完小", "小"),
- new KeyValuePair<string, string>("义务", ""),
- new KeyValuePair<string, string>("基础", ""),
- new KeyValuePair<string, string>("制造", "")
- };
- public static List<KeyValuePair<string, string>> schooReplaceStr = new List<KeyValuePair<string, string>> {
- new KeyValuePair<string, string>("分校", "分") ,
- new KeyValuePair<string, string>("分园", "分") ,
- new KeyValuePair<string, string>("分院", "分") ,
- new KeyValuePair<string, string>("藏文", "藏"),
- new KeyValuePair<string, string>("职业技术学院", "职") ,
- new KeyValuePair<string, string>("创新创业", "创") ,
- new KeyValuePair<string, string>("就业创业", "就") ,
- new KeyValuePair<string, string>("应用核技术", "核") ,
- new KeyValuePair<string, string>("职业学院", "职") ,
- new KeyValuePair<string, string>("幼儿园", "幼") ,
- new KeyValuePair<string, string>("幼儿", "幼") ,
- new KeyValuePair<string, string>("小学", "小") ,
- new KeyValuePair<string, string>("中学", "中") ,
- new KeyValuePair<string, string>("中等", "中") ,
- new KeyValuePair<string, string>("双语", "双") ,
- new KeyValuePair<string, string>("初中", "初") ,
- new KeyValuePair<string, string>("初级", "初") ,
- new KeyValuePair<string, string>("广播", "广"),
- new KeyValuePair<string, string>("高中", "高") ,
- new KeyValuePair<string, string>("高级", "高") ,
- new KeyValuePair<string, string>("大学", "大") ,
- new KeyValuePair<string, string>("学院", "院") ,
- new KeyValuePair<string, string>("综合", "综") ,
- new KeyValuePair<string, string>("职业", "职") ,
- new KeyValuePair<string, string>("技术", "技") ,
- new KeyValuePair<string, string>("专科", "专") ,
- new KeyValuePair<string, string>("外国语", "外") ,
- new KeyValuePair<string, string>("九年", "九") ,
- new KeyValuePair<string, string>("五年", "五") ,
- new KeyValuePair<string, string>("年制", "制") ,
- new KeyValuePair<string, string>("高等", "高") ,
- new KeyValuePair<string, string>("院校", "院") ,
- new KeyValuePair<string, string>("初等", "小") ,
- new KeyValuePair<string, string>("附属", "附"),
- new KeyValuePair<string, string>("寄宿制", "寄") ,
- new KeyValuePair<string, string>("寄宿", "寄") ,
- new KeyValuePair<string, string>("卫生", "卫") ,
- new KeyValuePair<string, string>("创业", "创") ,
- new KeyValuePair<string, string>("继续", "继") ,
- new KeyValuePair<string, string>("开放", "开") ,
- new KeyValuePair<string, string>("技师", "技") ,
- new KeyValuePair<string, string>("成人", "成") ,
- new KeyValuePair<string, string>("教育", "教") ,
- new KeyValuePair<string, string>("科技", "科") ,
- new KeyValuePair<string, string>("行政", "政") ,
- new KeyValuePair<string, string>("生物", "生") ,
- new KeyValuePair<string, string>("美术", "美") ,
- new KeyValuePair<string, string>("设计", "设") ,
- new KeyValuePair<string, string>("传播", "传") ,
- new KeyValuePair<string, string>("计算机", "算") ,
- new KeyValuePair<string, string>("土木", "土") ,
- new KeyValuePair<string, string>("石油", "油") ,
- new KeyValuePair<string, string>("科普", "普") ,
- new KeyValuePair<string, string>("电信", "信") ,
- new KeyValuePair<string, string>("联合", "联") ,
- new KeyValuePair<string, string>("电商", "商") ,
- new KeyValuePair<string, string>("纺织", "织") ,
- new KeyValuePair<string, string>("服装", "服") ,
- new KeyValuePair<string, string>("新闻", "新") ,
- new KeyValuePair<string, string>("网络", "网") ,
- new KeyValuePair<string, string>("应用", "应") ,
- new KeyValuePair<string, string>("畜牧", "畜") ,
- new KeyValuePair<string, string>("兽医", "兽") ,
- new KeyValuePair<string, string>("师范", "师") ,
- new KeyValuePair<string, string>("人文", "文") ,
- new KeyValuePair<string, string>("创新", "创") ,
- new KeyValuePair<string, string>("法官", "法") ,
- new KeyValuePair<string, string>("邮电", "邮") ,
- new KeyValuePair<string, string>("文化", "文") ,
- new KeyValuePair<string, string>("函授", "函") ,
- new KeyValuePair<string, string>("科学", "科") ,
- new KeyValuePair<string, string>("信息", "息") ,
- new KeyValuePair<string, string>("水利", "利") ,
- new KeyValuePair<string, string>("水电", "电") ,
- new KeyValuePair<string, string>("电力", "力") ,
- new KeyValuePair<string, string>("环境", "环") ,
- new KeyValuePair<string, string>("建材", "材") ,
- new KeyValuePair<string, string>("机电", "机") ,
- new KeyValuePair<string, string>("航空", "空") ,
- new KeyValuePair<string, string>("航天", "天") ,
- new KeyValuePair<string, string>("警察", "警") ,
- new KeyValuePair<string, string>("警官", "警") ,
- new KeyValuePair<string, string>("财贸", "财") ,
- new KeyValuePair<string, string>("电子", "电") ,
- new KeyValuePair<string, string>("建筑", "筑") ,
- new KeyValuePair<string, string>("艺术", "艺") ,
- new KeyValuePair<string, string>("体育", "体") ,
- new KeyValuePair<string, string>("城市", "城") ,
- new KeyValuePair<string, string>("地质", "地") ,
- new KeyValuePair<string, string>("医药", "药") ,
- new KeyValuePair<string, string>("政法", "法") ,
- new KeyValuePair<string, string>("铁路", "铁") ,
- new KeyValuePair<string, string>("铁道", "道") ,
- new KeyValuePair<string, string>("轨道", "轨") ,
- new KeyValuePair<string, string>("交通", "通") ,
- new KeyValuePair<string, string>("医学院", "医") ,
- new KeyValuePair<string, string>("医学", "医") ,
- new KeyValuePair<string, string>("传媒", "媒") ,
- new KeyValuePair<string, string>("工程", "程") ,
- new KeyValuePair<string, string>("临床", "临") ,
- new KeyValuePair<string, string>("化工", "化") ,
- new KeyValuePair<string, string>("林业", "林") ,
- new KeyValuePair<string, string>("老年", "老") ,
- new KeyValuePair<string, string>("旅游", "游") ,
- new KeyValuePair<string, string>("护理", "护") ,
- new KeyValuePair<string, string>("贸易", "贸") ,
- new KeyValuePair<string, string>("中医药", "中医") ,
- new KeyValuePair<string, string>("资源", "源") ,
- new KeyValuePair<string, string>("冶金", "冶") ,
- new KeyValuePair<string, string>("能源", "能") ,
- new KeyValuePair<string, string>("汽车", "车") ,
- new KeyValuePair<string, string>("医科", "医") ,
- new KeyValuePair<string, string>("机械", "械") ,
- new KeyValuePair<string, string>("应用", "应") ,
- new KeyValuePair<string, string>("电气", "电") ,
- new KeyValuePair<string, string>("材料", "材") ,
- new KeyValuePair<string, string>("劳动", "劳") ,
- new KeyValuePair<string, string>("轻工", "轻") ,
- new KeyValuePair<string, string>("农业", "农") ,
- new KeyValuePair<string, string>("委员会", "委") ,
- new KeyValuePair<string, string>("专业", "专") ,
- new KeyValuePair<string, string>("广播", "广"),
- new KeyValuePair<string, string>("电视", "电") ,
- new KeyValuePair<string, string>("工商", "商") ,
- new KeyValuePair<string, string>("工业", "工") ,
- new KeyValuePair<string, string>("管理", "管") ,
- new KeyValuePair<string, string>("社会主义", "社") ,
- new KeyValuePair<string, string>("社会", "社") ,
- new KeyValuePair<string, string>("自动化", "自") ,
- };
- public static List<KeyValuePair<string, string>> proReplaceStr = new List<KeyValuePair<string, string>> {
- new KeyValuePair<string, string>("北京","京") ,
- new KeyValuePair<string, string>("天津","津") ,
- new KeyValuePair<string, string>("河北","冀") ,
- new KeyValuePair<string, string>("山西","晋") ,
- new KeyValuePair<string, string>("内蒙古","蒙") ,
- new KeyValuePair<string, string>("辽宁","辽") ,
- new KeyValuePair<string, string>("吉林","吉") ,
- new KeyValuePair<string, string>("黑龙江","黑") ,
- new KeyValuePair<string, string>("上海","沪") ,
- new KeyValuePair<string, string>("江苏","苏") ,
- new KeyValuePair<string, string>("浙江","浙") ,
- new KeyValuePair<string, string>("安徽","皖") ,
- new KeyValuePair<string, string>("福建","闽") ,
- new KeyValuePair<string, string>("江西","赣") ,
- new KeyValuePair<string, string>("山东","鲁") ,
- new KeyValuePair<string, string>("河南","豫") ,
- new KeyValuePair<string, string>("湖北","鄂") ,
- new KeyValuePair<string, string>("湖南","湘") ,
- new KeyValuePair<string, string>("广东","粤") ,
- new KeyValuePair<string, string>("广西","桂") ,
- new KeyValuePair<string, string>("海南","琼") ,
- new KeyValuePair<string, string>("四川","川") ,
- new KeyValuePair<string, string>("贵州","贵") ,
- new KeyValuePair<string, string>("云南","云") ,
- new KeyValuePair<string, string>("重庆","渝") ,
- new KeyValuePair<string, string>("西藏","藏") ,
- new KeyValuePair<string, string>("陕西","陕") ,
- new KeyValuePair<string, string>("甘肃","甘") ,
- new KeyValuePair<string, string>("青海","青") ,
- new KeyValuePair<string, string>("宁夏","宁") ,
- new KeyValuePair<string, string>("新疆","新") ,
- new KeyValuePair<string, string>("香港","港") ,
- new KeyValuePair<string, string>("澳门","澳") ,
- new KeyValuePair<string, string>("台湾","台")
- };
- /*
- [
- {"method":"台北市","params":{"CountryId":"TW","CityId":"30"}},1
- {"method":"新北市","params":{"CountryId":"TW","CityId":"01"}},1
- {"method":"桃园市","params":{"CountryId":"TW","CityId":"03"}},1
- {"method":"台中市","params":{"CountryId":"TW","CityId":"66"}},1
- {"method":"台南市","params":{"CountryId":"TW","CityId":"67"}},1
- {"method":"高雄市","params":{"CountryId":"TW","CityId":"64"}},1
- {"method":"基隆市","params":{"CountryId":"TW","CityId":"17"}},1
- {"method":"新竹市","params":{"CountryId":"TW","CityId":"18"}},1
- {"method":"嘉义市","params":{"CountryId":"TW","CityId":"20"}},1
- {"method":"新竹县","params":{"CountryId":"TW","CityId":"04"}},1
- {"method":"苗栗县","params":{"CountryId":"TW","CityId":"05"}},1
- {"method":"彰化县","params":{"CountryId":"TW","CityId":"07"}},1
- {"method":"南投县","params":{"CountryId":"TW","CityId":"08"}},1
- {"method":"云林县","params":{"CountryId":"TW","CityId":"09"}},1
- {"method":"嘉义县","params":{"CountryId":"TW","CityId":"10"}},1
- {"method":"屏东县","params":{"CountryId":"TW","CityId":"13"}},1
- {"method":"宜兰县","params":{"CountryId":"TW","CityId":"02"}},1
- {"method":"花莲县","params":{"CountryId":"TW","CityId":"15"}},1
- {"method":"台东县","params":{"CountryId":"TW","CityId":"14"}},1
- {"method":"澎湖县","params":{"CountryId":"TW","CityId":"16"}},1
- {"method":"金门县","params":{"CountryId":"TW","CityId":"71"}},
- {"method":"连江县","params":{"CountryId":"TW","CityId":"72"}}
- ]
- */
- }
- }
|