SystemService.cs 93 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857
  1. using Azure.Storage.Blobs.Models;
  2. using DocumentFormat.OpenXml.Bibliography;
  3. using DocumentFormat.OpenXml.Office2010.Excel;
  4. using DocumentFormat.OpenXml.Wordprocessing;
  5. using HTEXLib;
  6. using HTEXLib.COMM.Helpers;
  7. using Microsoft.Azure.Amqp.Framing;
  8. using Newtonsoft.Json.Linq;
  9. using OpenXmlPowerTools;
  10. using StackExchange.Redis;
  11. using System;
  12. using System.Collections.Concurrent;
  13. using System.Collections.Generic;
  14. using System.Diagnostics.PerformanceData;
  15. using System.IdentityModel.Tokens.Jwt;
  16. using System.Linq;
  17. using System.Text;
  18. using System.Text.Json;
  19. using System.Text.RegularExpressions;
  20. using System.Threading.Tasks;
  21. using TEAMModelOS.SDK.DI;
  22. using TEAMModelOS.SDK.Extension;
  23. using TEAMModelOS.SDK.Models.Cosmos.Common;
  24. using TEAMModelOS.SDK.Models.Dtos;
  25. using static Azure.Core.HttpHeader;
  26. using static OpenXmlPowerTools.RevisionProcessor;
  27. using static TEAMModelOS.SDK.Models.Service.SystemService;
  28. namespace TEAMModelOS.SDK.Models.Service
  29. {
  30. public static class SystemService
  31. {
  32. public static async Task AccumulateDaily(AzureRedisFactory _azureRedis,AzureCosmosFactory _azureCosmos)
  33. {
  34. DateTimeOffset now = DateTimeOffset.UtcNow;
  35. string day = now.ToString("yyyyMMdd");
  36. //当天的个人评测提交数
  37. Dictionary<string, double?> exam_submit = new();
  38. List<string> keys = new List<string>();
  39. SortedSetEntry[] exam_submitScores = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Accumulate:Daily:private:exam-submit:{day}");
  40. if (exam_submitScores != null)
  41. {
  42. foreach (var score in exam_submitScores)
  43. {
  44. double val = score.Score;
  45. string key = score.Element.ToString();
  46. exam_submit.Add(key, val);
  47. keys.Add(key);
  48. }
  49. }
  50. List<string> homeworkIds = new List<string>();
  51. //当天的个人作业提交数
  52. SortedSetEntry[] homework_submitScores = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Accumulate:Daily:teacher:homework-submit:{day}");
  53. Dictionary<string, double?> homework_submit = new();
  54. if (homework_submitScores != null)
  55. {
  56. foreach (var score in homework_submitScores)
  57. {
  58. double val = score.Score;
  59. string key = score.Element.ToString();
  60. homework_submit.Add(key, val);
  61. keys.Add(key);
  62. homeworkIds.Add(key.Split("::")[1]);
  63. }
  64. }
  65. //当天的个人名单加入人数
  66. Dictionary<string, double?> grouplist = new();
  67. SortedSetEntry[] grouplistScores = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Accumulate:Daily:teacher:grouplist:{day}");
  68. if (grouplistScores != null)
  69. {
  70. foreach (var score in grouplistScores)
  71. {
  72. double val = score.Score;
  73. string key = score.Element.ToString();
  74. grouplist.Add(key, val);
  75. keys.Add(key);
  76. }
  77. }
  78. List<string> ids = new List<string>();
  79. keys.ForEach(x => {
  80. ids.Add(x.Split("::")[0]);
  81. });
  82. List<Teacher> teachers= new List<Teacher>();
  83. if (ids.IsNotEmpty())
  84. {
  85. string sql = $"select value c from c where c.id in ({string.Join(",", ids.Select(x => $"'{x}'"))})";
  86. var result = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetList<Teacher>(sql, "Base");
  87. if (result.list.IsNotEmpty())
  88. {
  89. teachers.AddRange(result.list);
  90. }
  91. }
  92. }
  93. public static async Task RecordAccumulateData(AzureRedisFactory azureRedis, DingDing dingDing, Accumulate accumulate)
  94. {
  95. if (!string.IsNullOrWhiteSpace(accumulate.key) && !string.IsNullOrWhiteSpace(accumulate.target) &&
  96. !string.IsNullOrWhiteSpace(accumulate.id) && !string.IsNullOrWhiteSpace(accumulate.name) &&
  97. !string.IsNullOrWhiteSpace(accumulate.scope) && !string.IsNullOrWhiteSpace(accumulate.client))
  98. {
  99. await RecordAccumulateData(azureRedis, accumulate.key, accumulate.target, accumulate.id, accumulate.name, accumulate.scope, accumulate.client, accumulate.count);
  100. }
  101. else
  102. {
  103. await dingDing.SendBotMsg($"IES累计数据变更统计参数异常,{accumulate.ToJsonString()}", GroupNames.成都开发測試群組);
  104. }
  105. }
  106. /// <summary>
  107. /// 记录累计数据
  108. /// </summary>
  109. public static async Task RecordAccumulateData(AzureRedisFactory azureRedis, string key, string target, string id, string name, string scope, string client, int count)
  110. {
  111. if (!string.IsNullOrWhiteSpace(key) && !string.IsNullOrWhiteSpace(target) &&
  112. !string.IsNullOrWhiteSpace(id) && !string.IsNullOrWhiteSpace(name) &&
  113. !string.IsNullOrWhiteSpace(scope)&& !string.IsNullOrWhiteSpace(client))
  114. {
  115. //处理UTC时差
  116. var nowTime = DateTimeOffset.UtcNow.GetGMTTime();
  117. int difference = (DayOfWeek.Sunday - nowTime.DayOfWeek + 7) % 7; //1-7的结果0-6
  118. var day = nowTime.ToString("yyyyMMdd");
  119. string redisKey = $"Accumulate:Daily:{scope}:{key}:{day}";
  120. string member = $"{target}::{id}::{client}::{name}";
  121. await azureRedis.GetRedisClient(8).SortedSetIncrementAsync(redisKey, member, count);
  122. await azureRedis.GetRedisClient(8).KeyExpireAsync(redisKey, new TimeSpan((difference+1)*24, 10, 0));
  123. //if (key.Equals("lesson") || key.StartsWith("login_"))
  124. //{
  125. // redisKey = $"Accumulate:Daily:ies:{key}:{day}";
  126. // if (scope.Equals("school"))
  127. // {
  128. // member = $"ies::{id}::{name}";
  129. // }
  130. // else {
  131. // member = $"ies::ies::{name}";
  132. // }
  133. // await azureRedis.GetRedisClient(8).SortedSetIncrementAsync(redisKey, member, 1);
  134. //}
  135. }
  136. }
  137. static double GetUserDuration(List<long> times )
  138. {
  139. if (times.IsNotEmpty())
  140. {
  141. if (times.Count>=2)
  142. {
  143. double totalDuration = 0;
  144. // DateTime lastTime = DateTimeOffset.FromUnixTimeMilliseconds((long)jsonData[0]["time"]).UtcDateTime;
  145. long ltime = times[0];
  146. for (int i = 1; i < times.Count; i++)
  147. {
  148. long ctime = times[i];
  149. //DateTime currentTime = DateTimeOffset.FromUnixTimeMilliseconds((long)jsonData[i]["time"]).UtcDateTime;
  150. long timeDifference = ctime - ltime;
  151. ///如果一小时内连续操作,则按真实时间累计
  152. if (timeDifference < 3600000)
  153. {
  154. totalDuration += timeDifference;
  155. }
  156. else
  157. { ///如果一小时内没有连续操作,则按象征性加10秒,以确保数据有效性。 如果因为一小时没有操作,则表示没有新的接口再次请求,当即就已经退出系统。否则后续仍然会有接口进入,并且带有时间戳
  158. totalDuration += 10000;
  159. }
  160. ltime = ctime;
  161. }
  162. return totalDuration;
  163. }
  164. else { return 10000; }
  165. }
  166. else {
  167. return 0;
  168. }
  169. }
  170. public static List<SchoolStick> CountSchoolStickiness(IEnumerable<IGrouping<string,ApiVisit>> schoolApiVisits, IEnumerable<ApiVisit> apiVisits)
  171. {
  172. List<SchoolStick> schoolStickiness = new List<SchoolStick>();
  173. foreach (var chinaSchoolKey in schoolApiVisits)
  174. {
  175. SchoolStick stickiness = new SchoolStick()
  176. {
  177. id = chinaSchoolKey.Key
  178. };
  179. var teachers = chinaSchoolKey.ToList().Where(x => !string.IsNullOrWhiteSpace(x.userId) && !string.IsNullOrWhiteSpace(x.scope) && x.scope.Equals("teacher")).GroupBy(x => x.userId);
  180. double hitaTime = 0, hiteachTime = 0, ies5TchTime = 0, otherTchTime = 0, ies5StuTime = 0, otherStuTime = 0;
  181. int hitaTch= 0, hiteachTch = 0, ies5Tch = 0, otherTch = 0, ies5Stu = 0, otherStu = 0;
  182. double hitaCount = 0, hiteachCount = 0, ies5TchCount = 0, otherTchCount = 0, ies5StuCount = 0, otherStuCount = 0;
  183. double lessonCount= chinaSchoolKey.ToList().Where(x => x.path.Contains("hiteach/create-lesson")).Count() ;
  184. int teacherCount= teachers.Count() ;
  185. foreach (var user in teachers)
  186. {
  187. TchStick tchStick = new TchStick()
  188. {
  189. id = user.Key,
  190. school= chinaSchoolKey.Key
  191. };
  192. //HiTA
  193. var teacherHitaVisit = apiVisits.Where(x => !string.IsNullOrWhiteSpace(x.userId) && x.userId.Equals(user.Key) && x.client.Equals("hita"));
  194. var teacherHitaVisitCount = teacherHitaVisit.Count();
  195. if (teacherHitaVisitCount>0)
  196. { hitaTch+=1; }
  197. var teacherHitaVisitTime = GetUserDuration(teacherHitaVisit.OrderBy(x => x.time).Select(x => x.time).ToList());
  198. hitaCount+=teacherHitaVisitCount;
  199. hitaTime+=teacherHitaVisitTime;
  200. tchStick.hita.count.value=teacherHitaVisitCount;
  201. tchStick.hita.duration.value=teacherHitaVisitTime;
  202. //Other
  203. var teacherOtherVisit = user.Where(x => !x.client.Equals("hita")&&!x.client.Equals("hiteach")&&!x.client.Equals("ies5"));
  204. var teacherOtherVisitCount= teacherOtherVisit.Count();
  205. var teacherOtherVisitTime= GetUserDuration(teacherOtherVisit.OrderBy(x => x.time).Select(x => x.time).ToList());
  206. if (teacherOtherVisitCount>0)
  207. { otherTch+=1; }
  208. otherTchCount+=teacherOtherVisitCount;
  209. otherTchTime+=teacherOtherVisitTime;
  210. tchStick.otherTch.count.value=teacherOtherVisitCount;
  211. tchStick.otherTch.duration.value=teacherOtherVisitTime;
  212. //HiTeach
  213. //教师访问hiteach 不带学校信息的
  214. var teacherHiteachVisit = apiVisits.Where(x => !string.IsNullOrWhiteSpace(x.userId) && x.userId.Equals(user.Key) && x.client.Equals("hiteach") && string.IsNullOrWhiteSpace(x.school));
  215. //教师访问hiteach 包含学校信息的
  216. var teacherHiteachSchoolVisit = user.Where(x => x.client.Equals("hiteach"));
  217. //教师所有的Hiteach访问
  218. List<ApiVisit> teacherHiteachAllVisit = new List<ApiVisit>();
  219. teacherHiteachAllVisit.AddRange(teacherHiteachVisit);
  220. teacherHiteachAllVisit.AddRange(teacherHiteachSchoolVisit);
  221. var teacherHiteachAllVisitCount = teacherHiteachAllVisit.Count();
  222. if (teacherHiteachAllVisitCount>0)
  223. { hiteachTch+=1; }
  224. var teacherHiteachAllVisitTime = GetUserDuration(teacherHiteachAllVisit.OrderBy(x => x.time).Select(x => x.time).ToList());
  225. hiteachCount+=teacherHiteachAllVisitCount;
  226. hiteachTime+=teacherHiteachAllVisitTime;
  227. tchStick.hiteach.count.value=teacherHiteachAllVisitCount;
  228. tchStick.hiteach.duration.value=teacherHiteachAllVisitTime;
  229. //IES5
  230. var teacherIes5Visit = user.Where(x => x.client.Equals("ies5"));
  231. var teacherIes5VisitCount= teacherIes5Visit.Count();
  232. if (teacherIes5VisitCount>0)
  233. { ies5Tch+=1; }
  234. var teacherIes5VisitTime = GetUserDuration(teacherIes5Visit.OrderBy(x => x.time).Select(x => x.time).ToList());
  235. ies5TchCount+=teacherIes5VisitCount;
  236. ies5TchTime+=teacherIes5VisitTime;
  237. tchStick.ies5Tch.count.value=teacherIes5VisitCount;
  238. tchStick.ies5Tch.duration.value=teacherIes5VisitTime;
  239. double lessonCountTch = chinaSchoolKey.ToList().Where(x => x.path.Contains("hiteach/create-lesson") && x.userId.Equals(user.Key)).Count();
  240. tchStick.lesson.value=lessonCountTch;
  241. tchStick.tmd.count.value=tchStick.hita.count.value+tchStick.hiteach.count.value+tchStick.ies5Tch.count.value+tchStick.otherTch.count.value;
  242. tchStick.tmd.duration.value=tchStick.hita.duration.value+tchStick.hiteach.duration.value+tchStick.ies5Tch.duration.value+tchStick.otherTch.duration.value;
  243. tchStick.hita.userCount=1;
  244. tchStick.hiteach.userCount=1;
  245. tchStick.ies5Tch.userCount=1;
  246. tchStick.otherTch.userCount=1;
  247. tchStick.tmd.userCount=1;
  248. if (tchStick.hita.count.value>0 && tchStick.hita.duration.value>0)
  249. {
  250. tchStick.hita.stick.value= (tchStick.hita.duration.value/1000/tchStick.hita.count.value);
  251. }
  252. if (tchStick.ies5Tch.count.value>0 && tchStick.ies5Tch.duration.value>0)
  253. {
  254. tchStick.ies5Tch.stick.value= (tchStick.ies5Tch.duration.value/1000/tchStick.ies5Tch.count.value);
  255. }
  256. if (tchStick.otherTch.count.value>0 && tchStick.otherTch.duration.value>0)
  257. {
  258. tchStick.otherTch.stick.value= (tchStick.otherTch.duration.value/1000/tchStick.otherTch.count.value);
  259. }
  260. if (tchStick.hiteach.count.value>0 && tchStick.hiteach.duration.value>0)
  261. {
  262. tchStick.hiteach.stick.value= (tchStick.hiteach.duration.value/1000/tchStick.hiteach.count.value)+tchStick.lesson.value;
  263. }
  264. if (tchStick.tmd.count.value>0 && tchStick.tmd.duration.value>0)
  265. {
  266. tchStick.tmd.stick.value= (tchStick.tmd.duration.value/1000/tchStick.tmd.count.value)+ tchStick.lesson.value;
  267. }
  268. stickiness.tchSticks.Add(tchStick);
  269. }
  270. var student = chinaSchoolKey.ToList().Where(x => !string.IsNullOrWhiteSpace(x.userId) && !string.IsNullOrWhiteSpace(x.scope) && (x.scope.Equals("student")||x.scope.Equals("tmduser"))).GroupBy(x => x.userId);
  271. var studentCount = student.Count();
  272. foreach (var user in student)
  273. {
  274. StuStick stuStick = new StuStick
  275. {
  276. id=user.Key,
  277. school=chinaSchoolKey.Key
  278. };
  279. var studentOtherVisit = user.Where(x => !x.client.Equals("ies5"));
  280. var studentOtherVisitCount = studentOtherVisit.Count();
  281. if (studentOtherVisitCount>0)
  282. { otherStu+=1; }
  283. double studentOtherVisitTime = GetUserDuration(studentOtherVisit.OrderBy(x => x.time).Select(x => x.time).ToList()) ;
  284. var studentIes5Visit = user.Where(x => x.client.Equals("ies5"));
  285. var studentIes5VisitCount = studentIes5Visit.Count();
  286. if (studentIes5VisitCount>0)
  287. { ies5Stu+=1; }
  288. double studentIes5VisitTime = GetUserDuration(studentIes5Visit.OrderBy(x => x.time).Select(x => x.time).ToList());
  289. ies5StuCount+=studentIes5VisitCount;
  290. ies5StuTime+=studentIes5VisitTime;
  291. otherStuCount+=studentOtherVisitCount;
  292. otherStuTime+=studentOtherVisitTime;
  293. stuStick.ies5Stu.count.value=studentIes5VisitCount;
  294. stuStick.ies5Stu.duration.value=studentIes5VisitTime;
  295. stuStick.otherStu.count.value=studentOtherVisitCount;
  296. stuStick.otherStu.duration.value=studentOtherVisitTime;
  297. stuStick.tmd.count.value= stuStick.ies5Stu.count.value+stuStick.otherStu.count.value;
  298. stuStick.tmd.duration.value= stuStick.ies5Stu.duration.value+stuStick.otherStu.duration.value;
  299. stuStick.ies5Stu.userCount=1;
  300. stuStick.otherStu.userCount=1;
  301. stuStick.tmd.userCount=1;
  302. if (stuStick.ies5Stu.count.value>0 && stuStick.ies5Stu.duration.value>0)
  303. {
  304. stuStick.ies5Stu.stick.value= (stuStick.ies5Stu.duration.value/1000/stuStick.ies5Stu.count.value);
  305. }
  306. if (stuStick.otherStu.count.value>0 && stuStick.otherStu.duration.value>0)
  307. {
  308. stuStick.otherStu.stick.value=(stuStick.otherStu.duration.value/1000/stuStick.otherStu.count.value);
  309. }
  310. if (stuStick.tmd.count.value>0 && stuStick.tmd.duration.value>0)
  311. {
  312. stuStick.tmd.stick.value=(stuStick.tmd.duration.value/1000/stuStick.tmd.count.value);
  313. }
  314. stickiness.stuSticks.Add(stuStick);
  315. }
  316. stickiness.hita.duration.value=hitaTime;
  317. stickiness.hiteach.duration.value=hiteachTime;
  318. stickiness.otherTch.duration.value=otherTchTime;
  319. stickiness.ies5Tch.duration.value=ies5TchTime;
  320. stickiness.tmd.duration.value=hitaTime+hiteachTime+otherTchTime+ies5TchTime+otherStuTime+ies5StuTime;
  321. stickiness.hita.userCount=hitaTch;
  322. stickiness.hiteach.userCount=hiteachTch;
  323. stickiness.ies5Tch.userCount=ies5Tch;
  324. stickiness.otherTch.userCount=otherTch;
  325. stickiness.ies5Stu.userCount=ies5Stu;
  326. stickiness.otherStu.userCount=otherStu;
  327. stickiness.hita.count.value=hitaCount;
  328. stickiness.hiteach.count.value=hiteachCount;
  329. stickiness.ies5Tch.count.value=ies5TchCount;
  330. stickiness.otherTch.count.value=otherTchCount;
  331. stickiness.ies5Stu.count.value=ies5StuCount;
  332. stickiness.otherStu.count.value=otherStuCount;
  333. stickiness.tmd.count.value=hitaCount+hiteachCount+ies5TchCount+otherTchCount+ies5StuCount+otherStuCount;
  334. stickiness.lesson.value=lessonCount;
  335. stickiness.tmd.userCount=teacherCount+studentCount;
  336. if(stickiness.hita.count.value>0 && stickiness.hita.duration.value>0)
  337. {
  338. stickiness.hita.stick.value=(stickiness.hita.userCount* stickiness.hita.count.value)/(stickiness.hita.duration.value/1000/stickiness.hita.count.value);
  339. }
  340. if (stickiness.ies5Stu.count.value>0 && stickiness.ies5Stu.duration.value>0)
  341. {
  342. stickiness.ies5Stu.stick.value=(stickiness.ies5Stu.userCount* stickiness.ies5Stu.count.value)/(stickiness.ies5Stu.duration.value/1000/stickiness.ies5Stu.count.value);
  343. }
  344. if (stickiness.ies5Tch.count.value>0 && stickiness.ies5Tch.duration.value>0)
  345. {
  346. stickiness.ies5Tch.stick.value=(stickiness.ies5Tch.userCount* stickiness.ies5Tch.count.value)/(stickiness.ies5Tch.duration.value/1000/stickiness.ies5Tch.count.value);
  347. }
  348. if (stickiness.otherStu.count.value>0 && stickiness.otherStu.duration.value>0)
  349. {
  350. stickiness.otherStu.stick.value=(stickiness.otherStu.userCount* stickiness.otherStu.count.value)/(stickiness.otherStu.duration.value/1000/stickiness.otherStu.count.value);
  351. }
  352. if (stickiness.otherTch.count.value>0 && stickiness.otherTch.duration.value>0)
  353. {
  354. stickiness.otherTch.stick.value=(stickiness.otherTch.userCount* stickiness.otherTch.count.value)/(stickiness.otherTch.duration.value/1000/stickiness.otherTch.count.value);
  355. }
  356. if (stickiness.hiteach.count.value>0 && stickiness.hiteach.duration.value>0)
  357. {
  358. stickiness.hiteach.stick.value=(stickiness.hiteach.userCount* stickiness.hiteach.count.value)/(stickiness.hiteach.duration.value/1000/stickiness.hiteach.count.value)+stickiness.lesson.value;
  359. }
  360. if (stickiness.tmd.count.value>0 && stickiness.tmd.duration.value>0)
  361. {
  362. stickiness.tmd.stick.value=(stickiness.tmd.userCount* stickiness.tmd.count.value)/(stickiness.tmd.duration.value/1000/stickiness.tmd.count.value)+ stickiness.lesson.value;
  363. }
  364. stickiness.tchSticks= OrderByTchStick(stickiness.tchSticks);
  365. stickiness.stuSticks= OrderByStuStick(stickiness.stuSticks);
  366. schoolStickiness.Add(stickiness);
  367. }
  368. return OrderBySchoolStick(schoolStickiness);
  369. }
  370. private static List<StuStick> OrderByStuStick(List<StuStick> stuStickiness)
  371. {
  372. // 假设visit已经填充了数据
  373. #region
  374. var rank_tmd_count = stuStickiness.Select(x => x.tmd.count.value).Distinct().OrderByDescending(v => v).ToList();
  375. var rank_ies5Stu_count = stuStickiness.Select(x => x.ies5Stu.count.value).Distinct().OrderByDescending(v => v).ToList();
  376. var rank_otherStu_count = stuStickiness.Select(x => x.otherStu.count.value).Distinct().OrderByDescending(v => v).ToList();
  377. #endregion
  378. #region
  379. var rank_tmd_duration = stuStickiness.Select(x => x.tmd.duration.value).Distinct().OrderByDescending(v => v).ToList();
  380. var rank_ies5Stu_duration = stuStickiness.Select(x => x.ies5Stu.duration.value).Distinct().OrderByDescending(v => v).ToList();
  381. var rank_otherStu_duration = stuStickiness.Select(x => x.otherStu.duration.value).Distinct().OrderByDescending(v => v).ToList();
  382. #endregion
  383. #region
  384. var rank_tmd_stick = stuStickiness.Select(x => x.tmd.stick.value).Distinct().OrderByDescending(v => v).ToList();
  385. var rank_ies5Stu_stick = stuStickiness.Select(x => x.ies5Stu.stick.value).Distinct().OrderByDescending(v => v).ToList();
  386. var rank_otherStu_stick = stuStickiness.Select(x => x.otherStu.stick.value).Distinct().OrderByDescending(v => v).ToList();
  387. #endregion
  388. stuStickiness.ForEach(x =>
  389. {
  390. #region
  391. if (x.tmd.count.value>0)
  392. {
  393. int index_tmd_count = rank_tmd_count.FindIndex(i => i==x.tmd.count.value);
  394. if (index_tmd_count!=-1)
  395. {
  396. x.tmd.count.rank = index_tmd_count + 1;
  397. }
  398. }
  399. if (x.ies5Stu.count.value>0)
  400. {
  401. int index_ies5Stu_count = rank_ies5Stu_count.FindIndex(i => i==x.ies5Stu.count.value);
  402. if (index_ies5Stu_count!=-1)
  403. {
  404. x.ies5Stu.count.rank = index_ies5Stu_count + 1;
  405. }
  406. }
  407. if (x.otherStu.count.value>0)
  408. {
  409. int index_otherStu_count = rank_otherStu_count.FindIndex(i => i==x.otherStu.count.value);
  410. if (index_otherStu_count!=-1)
  411. {
  412. x.otherStu.count.rank = index_otherStu_count + 1;
  413. }
  414. }
  415. #endregion
  416. #region
  417. if (x.tmd.duration.value> 0) {
  418. int index_tmd_duration = rank_tmd_duration.FindIndex(i => i==x.tmd.duration.value);
  419. if (index_tmd_duration!=-1)
  420. {
  421. x.tmd.duration.rank = index_tmd_duration + 1;
  422. }
  423. }
  424. if (x.ies5Stu.duration.value>0) {
  425. int index_ies5Stu_duration = rank_ies5Stu_duration.FindIndex(i => i==x.ies5Stu.duration.value);
  426. if (index_ies5Stu_duration!=-1)
  427. {
  428. x.ies5Stu.duration.rank = index_ies5Stu_duration + 1;
  429. }
  430. }
  431. if (x.otherStu.duration.value>0) {
  432. int index_otherStu_duration = rank_otherStu_duration.FindIndex(i => i==x.otherStu.duration.value);
  433. if (index_otherStu_duration!=-1)
  434. {
  435. x.otherStu.duration.rank = index_otherStu_duration + 1;
  436. }
  437. }
  438. #endregion
  439. #region
  440. if (x.tmd.stick.value>0)
  441. {
  442. int index_tmd_stick = rank_tmd_stick.FindIndex(i => i==x.tmd.stick.value);
  443. if (index_tmd_stick!=-1)
  444. {
  445. x.tmd.stick.rank = index_tmd_stick + 1;
  446. }
  447. }
  448. if (x.ies5Stu.stick.value>0)
  449. {
  450. int index_ies5Stu_stick = rank_ies5Stu_stick.FindIndex(i => i==x.ies5Stu.stick.value);
  451. if (index_ies5Stu_stick!=-1)
  452. {
  453. x.ies5Stu.stick.rank = index_ies5Stu_stick + 1;
  454. }
  455. }
  456. if (x.otherStu.stick.value>0)
  457. {
  458. int index_otherStu_stick = rank_otherStu_stick.FindIndex(i => i==x.otherStu.stick.value);
  459. if (index_otherStu_stick!=-1)
  460. {
  461. x.otherStu.stick.rank = index_otherStu_stick + 1;
  462. }
  463. }
  464. #endregion
  465. });
  466. return stuStickiness;
  467. }
  468. private static List<TchStick> OrderByTchStick(List<TchStick> tchStickiness)
  469. {
  470. // 假设visit已经填充了数据
  471. #region
  472. var rank_tmd_count = tchStickiness.Select(x => x.tmd.count.value).Distinct().OrderByDescending(v => v).ToList();
  473. var rank_hita_count = tchStickiness.Select(x => x.hita.count.value).Distinct().OrderByDescending(v => v).ToList();
  474. var rank_hiteach_count = tchStickiness.Select(x => x.hiteach.count.value).Distinct().OrderByDescending(v => v).ToList();
  475. var rank_ies5Tch_count = tchStickiness.Select(x => x.ies5Tch.count.value).Distinct().OrderByDescending(v => v).ToList();
  476. var rank_otherTch_count = tchStickiness.Select(x => x.otherTch.count.value).Distinct().OrderByDescending(v => v).ToList();
  477. var rank_lesson_count = tchStickiness.Select(x => x.lesson.value).Distinct().OrderByDescending(v => v).ToList();
  478. #endregion
  479. #region
  480. var rank_tmd_duration = tchStickiness.Select(x => x.tmd.duration.value).Distinct().OrderByDescending(v => v).ToList();
  481. var rank_hita_duration = tchStickiness.Select(x => x.hita.duration.value).Distinct().OrderByDescending(v => v).ToList();
  482. var rank_hiteach_duration = tchStickiness.Select(x => x.hiteach.duration.value).Distinct().OrderByDescending(v => v).ToList();
  483. var rank_ies5Tch_duration = tchStickiness.Select(x => x.ies5Tch.duration.value).Distinct().OrderByDescending(v => v).ToList();
  484. var rank_otherTch_duration = tchStickiness.Select(x => x.otherTch.duration.value).Distinct().OrderByDescending(v => v).ToList();
  485. #endregion
  486. #region
  487. var rank_tmd_stick = tchStickiness.Select(x => x.tmd.stick.value).Distinct().OrderByDescending(v => v).ToList();
  488. var rank_hita_stick = tchStickiness.Select(x => x.hita.stick.value).Distinct().OrderByDescending(v => v).ToList();
  489. var rank_hiteach_stick = tchStickiness.Select(x => x.hiteach.stick.value).Distinct().OrderByDescending(v => v).ToList();
  490. var rank_ies5Tch_stick = tchStickiness.Select(x => x.ies5Tch.stick.value).Distinct().OrderByDescending(v => v).ToList();
  491. var rank_otherTch_stick = tchStickiness.Select(x => x.otherTch.stick.value).Distinct().OrderByDescending(v => v).ToList();
  492. #endregion
  493. tchStickiness.ForEach(x => {
  494. #region
  495. int index_tmd_count = rank_tmd_count.FindIndex(i => i==x.tmd.count.value);
  496. if (index_tmd_count!=-1)
  497. {
  498. x.tmd.count.rank = index_tmd_count + 1;
  499. }
  500. int index_hita_count = rank_hita_count.FindIndex(i => i==x.hita.count.value);
  501. if (index_hita_count!=-1)
  502. {
  503. x.hita.count.rank = index_hita_count + 1;
  504. }
  505. int index_hiteach_count = rank_hiteach_count.FindIndex(i => i==x.hiteach.count.value);
  506. if (index_hiteach_count!=-1)
  507. {
  508. x.hiteach.count.rank = index_hiteach_count + 1;
  509. }
  510. int index_ies5Tch_count = rank_ies5Tch_count.FindIndex(i => i==x.ies5Tch.count.value);
  511. if (index_ies5Tch_count!=-1)
  512. {
  513. x.ies5Tch.count.rank = index_ies5Tch_count + 1;
  514. }
  515. int index_otherTch_count = rank_otherTch_count.FindIndex(i => i==x.otherTch.count.value);
  516. if (index_otherTch_count!=-1)
  517. {
  518. x.otherTch.count.rank = index_otherTch_count + 1;
  519. }
  520. int index_lesson_count = rank_lesson_count.FindIndex(i => i==x.lesson.value);
  521. if (index_lesson_count!=-1)
  522. {
  523. x.lesson.rank = index_lesson_count + 1;
  524. }
  525. #endregion
  526. #region
  527. int index_tmd_duration = rank_tmd_duration.FindIndex(i => i==x.tmd.duration.value);
  528. if (index_tmd_duration!=-1)
  529. {
  530. x.tmd.duration.rank = index_tmd_duration + 1;
  531. }
  532. int index_hita_duration = rank_hita_duration.FindIndex(i => i==x.hita.duration.value);
  533. if (index_hita_duration!=-1)
  534. {
  535. x.hita.duration.rank = index_hita_duration + 1;
  536. }
  537. int index_hiteach_duration = rank_hiteach_duration.FindIndex(i => i==x.hiteach.duration.value);
  538. if (index_hiteach_duration!=-1)
  539. {
  540. x.hiteach.duration.rank = index_hiteach_duration + 1;
  541. }
  542. int index_ies5Tch_duration = rank_ies5Tch_duration.FindIndex(i => i==x.ies5Tch.duration.value);
  543. if (index_ies5Tch_duration!=-1)
  544. {
  545. x.ies5Tch.duration.rank = index_ies5Tch_duration + 1;
  546. }
  547. int index_otherTch_duration = rank_otherTch_duration.FindIndex(i => i==x.otherTch.duration.value);
  548. if (index_otherTch_duration!=-1)
  549. {
  550. x.otherTch.duration.rank = index_otherTch_duration + 1;
  551. }
  552. #endregion
  553. #region
  554. int index_tmd_stick = rank_tmd_stick.FindIndex(i => i==x.tmd.stick.value);
  555. if (index_tmd_stick!=-1)
  556. {
  557. x.tmd.stick.rank = index_tmd_stick + 1;
  558. }
  559. int index_hita_stick = rank_hita_stick.FindIndex(i => i==x.hita.stick.value);
  560. if (index_hita_stick!=-1)
  561. {
  562. x.hita.stick.rank = index_hita_stick + 1;
  563. }
  564. int index_hiteach_stick = rank_hiteach_stick.FindIndex(i => i==x.hiteach.stick.value);
  565. if (index_hiteach_stick!=-1)
  566. {
  567. x.hiteach.stick.rank = index_hiteach_stick + 1;
  568. }
  569. int index_ies5Tch_stick = rank_ies5Tch_stick.FindIndex(i => i==x.ies5Tch.stick.value);
  570. if (index_ies5Tch_stick!=-1)
  571. {
  572. x.ies5Tch.stick.rank = index_ies5Tch_stick + 1;
  573. }
  574. int index_otherTch_stick = rank_otherTch_stick.FindIndex(i => i==x.otherTch.stick.value);
  575. if (index_otherTch_stick!=-1)
  576. {
  577. x.otherTch.stick.rank = index_otherTch_stick + 1;
  578. }
  579. #endregion
  580. });
  581. return tchStickiness;
  582. }
  583. private static List<SchoolStick> OrderBySchoolStick(List<SchoolStick> schoolStickiness)
  584. {
  585. // 假设visit已经填充了数据
  586. #region
  587. var rank_tmd_count = schoolStickiness.Select(x => x.tmd.count.value).Distinct().OrderByDescending(v => v).ToList();
  588. var rank_hita_count = schoolStickiness.Select(x => x.hita.count.value).Distinct().OrderByDescending(v => v).ToList();
  589. var rank_hiteach_count = schoolStickiness.Select(x => x.hiteach.count.value).Distinct().OrderByDescending(v => v).ToList();
  590. var rank_ies5Tch_count = schoolStickiness.Select(x => x.ies5Tch.count.value).Distinct().OrderByDescending(v => v).ToList();
  591. var rank_otherTch_count = schoolStickiness.Select(x => x.otherTch.count.value).Distinct().OrderByDescending(v => v).ToList();
  592. var rank_ies5Stu_count = schoolStickiness.Select(x => x.ies5Stu.count.value).Distinct().OrderByDescending(v => v).ToList();
  593. var rank_otherStu_count = schoolStickiness.Select(x => x.otherStu.count.value).Distinct().OrderByDescending(v => v).ToList();
  594. var rank_lesson_count = schoolStickiness.Select(x => x.lesson.value).Distinct().OrderByDescending(v => v).ToList();
  595. #endregion
  596. #region
  597. var rank_tmd_duration = schoolStickiness.Select(x => x.tmd.duration.value).Distinct().OrderByDescending(v => v).ToList();
  598. var rank_hita_duration = schoolStickiness.Select(x => x.hita.duration.value).Distinct().OrderByDescending(v => v).ToList();
  599. var rank_hiteach_duration = schoolStickiness.Select(x => x.hiteach.duration.value).Distinct().OrderByDescending(v => v).ToList();
  600. var rank_ies5Tch_duration = schoolStickiness.Select(x => x.ies5Tch.duration.value).Distinct().OrderByDescending(v => v).ToList();
  601. var rank_otherTch_duration = schoolStickiness.Select(x => x.otherTch.duration.value).Distinct().OrderByDescending(v => v).ToList();
  602. var rank_ies5Stu_duration = schoolStickiness.Select(x => x.ies5Stu.duration.value).Distinct().OrderByDescending(v => v).ToList();
  603. var rank_otherStu_duration = schoolStickiness.Select(x => x.otherStu.duration.value).Distinct().OrderByDescending(v => v).ToList();
  604. #endregion
  605. #region
  606. var rank_tmd_stick = schoolStickiness.Select(x => x.tmd.stick.value).Distinct().OrderByDescending(v => v).ToList();
  607. var rank_hita_stick = schoolStickiness.Select(x => x.hita.stick.value).Distinct().OrderByDescending(v => v).ToList();
  608. var rank_hiteach_stick = schoolStickiness.Select(x => x.hiteach.stick.value).Distinct().OrderByDescending(v => v).ToList();
  609. var rank_ies5Tch_stick = schoolStickiness.Select(x => x.ies5Tch.stick.value).Distinct().OrderByDescending(v => v).ToList();
  610. var rank_otherTch_stick = schoolStickiness.Select(x => x.otherTch.stick.value).Distinct().OrderByDescending(v => v).ToList();
  611. var rank_ies5Stu_stick = schoolStickiness.Select(x => x.ies5Stu.stick.value).Distinct().OrderByDescending(v => v).ToList();
  612. var rank_otherStu_stick = schoolStickiness.Select(x => x.otherStu.stick.value).Distinct().OrderByDescending(v => v).ToList();
  613. #endregion
  614. schoolStickiness.ForEach(x => {
  615. #region
  616. if (x.tmd.count.value>0)
  617. {
  618. int index_tmd_count = rank_tmd_count.FindIndex(i => i==x.tmd.count.value);
  619. if (index_tmd_count!=-1)
  620. {
  621. x.tmd.count.rank = index_tmd_count + 1;
  622. }
  623. }
  624. if (x.hita.count.value>0)
  625. {
  626. int index_hita_count = rank_hita_count.FindIndex(i => i==x.hita.count.value);
  627. if (index_hita_count!=-1)
  628. {
  629. x.hita.count.rank = index_hita_count + 1;
  630. }
  631. }
  632. if (x.hiteach.count.value>0)
  633. {
  634. int index_hiteach_count = rank_hiteach_count.FindIndex(i => i==x.hiteach.count.value);
  635. if (index_hiteach_count!=-1)
  636. {
  637. x.hiteach.count.rank = index_hiteach_count + 1;
  638. }
  639. }
  640. if (x.ies5Tch.count.value>0)
  641. {
  642. int index_ies5Tch_count = rank_ies5Tch_count.FindIndex(i => i==x.ies5Tch.count.value);
  643. if (index_ies5Tch_count!=-1)
  644. {
  645. x.ies5Tch.count.rank = index_ies5Tch_count + 1;
  646. }
  647. }
  648. if (x.otherTch.count.value>0)
  649. {
  650. int index_otherTch_count = rank_otherTch_count.FindIndex(i => i==x.otherTch.count.value);
  651. if (index_otherTch_count!=-1)
  652. {
  653. x.otherTch.count.rank = index_otherTch_count + 1;
  654. }
  655. }
  656. if (x.ies5Stu.count.value>0)
  657. {
  658. int index_ies5Stu_count = rank_ies5Stu_count.FindIndex(i => i==x.ies5Stu.count.value);
  659. if (index_ies5Stu_count!=-1)
  660. {
  661. x.ies5Stu.count.rank = index_ies5Stu_count + 1;
  662. }
  663. }
  664. if (x.otherStu.count.value>0)
  665. {
  666. int index_otherStu_count = rank_otherStu_count.FindIndex(i => i==x.otherStu.count.value);
  667. if (index_otherStu_count!=-1)
  668. {
  669. x.otherStu.count.rank = index_otherStu_count + 1;
  670. }
  671. }
  672. if (x.lesson.value>0)
  673. {
  674. int index_lesson_count = rank_lesson_count.FindIndex(i => i==x.lesson.value);
  675. if (index_lesson_count!=-1)
  676. {
  677. x.lesson.rank = index_lesson_count + 1;
  678. }
  679. }
  680. #endregion
  681. #region
  682. if (x.tmd.duration.value>0)
  683. {
  684. int index_tmd_duration = rank_tmd_duration.FindIndex(i => i==x.tmd.duration.value);
  685. if (index_tmd_duration!=-1)
  686. {
  687. x.tmd.duration.rank = index_tmd_duration + 1;
  688. }
  689. }
  690. if (x.hita.duration.value>0)
  691. {
  692. int index_hita_duration = rank_hita_duration.FindIndex(i => i==x.hita.duration.value);
  693. if (index_hita_duration!=-1)
  694. {
  695. x.hita.duration.rank = index_hita_duration + 1;
  696. }
  697. }
  698. if (x.hiteach.duration.value>0)
  699. {
  700. int index_hiteach_duration = rank_hiteach_duration.FindIndex(i => i==x.hiteach.duration.value);
  701. if (index_hiteach_duration!=-1)
  702. {
  703. x.hiteach.duration.rank = index_hiteach_duration + 1;
  704. }
  705. }
  706. if (x.ies5Tch.duration.value>0) {
  707. int index_ies5Tch_duration = rank_ies5Tch_duration.FindIndex(i => i==x.ies5Tch.duration.value);
  708. if (index_ies5Tch_duration!=-1)
  709. {
  710. x.ies5Tch.duration.rank = index_ies5Tch_duration + 1;
  711. }
  712. }
  713. if (x.otherTch.duration.value>0)
  714. {
  715. int index_otherTch_duration = rank_otherTch_duration.FindIndex(i => i==x.otherTch.duration.value);
  716. if (index_otherTch_duration!=-1)
  717. {
  718. x.otherTch.duration.rank = index_otherTch_duration + 1;
  719. }
  720. }
  721. if (x.ies5Stu.duration.value>0)
  722. {
  723. int index_ies5Stu_duration = rank_ies5Stu_duration.FindIndex(i => i==x.ies5Stu.duration.value);
  724. if (index_ies5Stu_duration!=-1)
  725. {
  726. x.ies5Stu.duration.rank = index_ies5Stu_duration + 1;
  727. }
  728. }
  729. if (x.otherStu.duration.value>0)
  730. {
  731. int index_otherStu_duration = rank_otherStu_duration.FindIndex(i => i==x.otherStu.duration.value);
  732. if (index_otherStu_duration!=-1)
  733. {
  734. x.otherStu.duration.rank = index_otherStu_duration + 1;
  735. }
  736. }
  737. #endregion
  738. #region
  739. if (x.tmd.stick.value>0)
  740. {
  741. int index_tmd_stick = rank_tmd_stick.FindIndex(i => i==x.tmd.stick.value);
  742. if (index_tmd_stick!=-1)
  743. {
  744. x.tmd.stick.rank = index_tmd_stick + 1;
  745. }
  746. }
  747. if (x.hita.stick.value>0)
  748. {
  749. int index_hita_stick = rank_hita_stick.FindIndex(i => i==x.hita.stick.value);
  750. if (index_hita_stick!=-1)
  751. {
  752. x.hita.stick.rank = index_hita_stick + 1;
  753. }
  754. }
  755. if (x.hiteach.stick.value>0)
  756. {
  757. int index_hiteach_stick = rank_hiteach_stick.FindIndex(i => i==x.hiteach.stick.value);
  758. if (index_hiteach_stick!=-1)
  759. {
  760. x.hiteach.stick.rank = index_hiteach_stick + 1;
  761. }
  762. }
  763. if (x.ies5Tch.stick.value>0)
  764. {
  765. int index_ies5Tch_stick = rank_ies5Tch_stick.FindIndex(i => i==x.ies5Tch.stick.value);
  766. if (index_ies5Tch_stick!=-1)
  767. {
  768. x.ies5Tch.stick.rank = index_ies5Tch_stick + 1;
  769. }
  770. }
  771. if (x.otherTch.stick.value>0)
  772. {
  773. int index_otherTch_stick = rank_otherTch_stick.FindIndex(i => i==x.otherTch.stick.value);
  774. if (index_otherTch_stick!=-1)
  775. {
  776. x.otherTch.stick.rank = index_otherTch_stick + 1;
  777. }
  778. }
  779. if (x.ies5Stu.stick.value>0)
  780. {
  781. int index_ies5Stu_stick = rank_ies5Stu_stick.FindIndex(i => i==x.ies5Stu.stick.value);
  782. if (index_ies5Stu_stick!=-1)
  783. {
  784. x.ies5Stu.stick.rank = index_ies5Stu_stick + 1;
  785. }
  786. }
  787. if (x.otherStu.stick.value>0)
  788. {
  789. int index_otherStu_stick = rank_otherStu_stick.FindIndex(i => i==x.otherStu.stick.value);
  790. if (index_otherStu_stick!=-1)
  791. {
  792. x.otherStu.stick.rank = index_otherStu_stick + 1;
  793. }
  794. }
  795. #endregion
  796. });
  797. return schoolStickiness;
  798. }
  799. /// <summary>
  800. /// 结算访问日志
  801. /// </summary>
  802. public static async Task<(List<SchoolStick> chinaSchoolStickiness, List<SchoolStick> globalSchoolStickiness)> VisitSettle(List<string> times ,AzureStorageFactory _azureStorage,AzureRedisFactory _azureRedis, Region2LongitudeLatitudeTranslator _longitudeLatitudeTranslator, IPSearcher _ipSearcher) {
  803. List<SchoolStick> chinaSchoolStickiness = new List<SchoolStick>();
  804. List<SchoolStick> globalSchoolStickiness = new List<SchoolStick>();
  805. foreach (var timeDate in times)
  806. {
  807. List<ApiVisit> apiVisits = new List<ApiVisit>();
  808. if (DateTimeOffset.TryParse(timeDate, out DateTimeOffset date))
  809. {
  810. BlobDownloadResult result = await _azureStorage.GetBlobContainerClient("0-service-log").GetBlobClient($"http-log/{date:yyyy}/{date:MM}/{date:dd}/index.log").DownloadContentAsync();
  811. var content = result.Content.ToString();
  812. content= content.Substring(0, content.Length-2);
  813. if (content.EndsWith("}"))
  814. {
  815. content=$"[{content}]";
  816. }
  817. else
  818. {
  819. content=$"[{content}}}]";
  820. }
  821. apiVisits.AddRange(content.ToObject<List<ApiVisit>>());
  822. var dateNow = DateTimeOffset.Now.GetGMTTime(8);
  823. if ($"{dateNow:yyyy-MM-dd}".Equals($"{date:yyyy-MM-dd}"))
  824. { //当前小时一致的
  825. BlobDownloadResult resultHour = await _azureStorage.GetBlobContainerClient("0-service-log").GetBlobClient($"http-log/{date:yyyy}/{date:MM}/{date:dd}/{date:HH}.log").DownloadContentAsync();
  826. var contentHour = resultHour.Content.ToString();
  827. contentHour= contentHour.Substring(0, contentHour.Length-2);
  828. if (contentHour.EndsWith("}"))
  829. {
  830. contentHour=$"[{contentHour}]";
  831. }
  832. else
  833. {
  834. contentHour=$"[{contentHour}}}]";
  835. }
  836. var httpLog = contentHour.ToObject<List<HttpLog>>();
  837. (ConcurrentBag<ApiVisit> visits, ConcurrentBag<(string uuid, HttpLog httpLog, List<string> tmdid, List<string> school)> uuidInfo) = await SystemService.ConvertHttpLog(httpLog, _azureRedis, _ipSearcher, _longitudeLatitudeTranslator, dateNow, false);
  838. apiVisits.AddRange(visits);
  839. }
  840. }
  841. //大陆学校
  842. var chinaApiVisits = apiVisits.Where(x => x.hostName.Equals("大陆站"));
  843. var chinaSchoolVisits = apiVisits.Where(x => !string.IsNullOrWhiteSpace(x.school) && x.hostName.Equals("大陆站")).GroupBy(x => x.school);
  844. List<SchoolStick> chinaStickiness = CountSchoolStickiness(chinaSchoolVisits, chinaApiVisits);
  845. chinaSchoolStickiness.AddRange(chinaStickiness);
  846. //国际学校
  847. var globalApiVisits = apiVisits.Where(x => x.hostName.Equals("国际站"));
  848. var globalSchoolVisits = apiVisits.Where(x => !string.IsNullOrWhiteSpace(x.school) && x.hostName.Equals("国际站")).GroupBy(x => x.school);
  849. List<SchoolStick> globalStickiness = CountSchoolStickiness(globalSchoolVisits, globalApiVisits);
  850. globalSchoolStickiness.AddRange(globalStickiness);
  851. }
  852. return (chinaSchoolStickiness, globalSchoolStickiness);
  853. }
  854. public static async Task<(ConcurrentBag<ApiVisit> visits, ConcurrentBag<(string uuid, HttpLog httpLog, List<string> tmdid, List<string> school)> uuidInfo)>
  855. ConvertHttpLog(List<HttpLog> logs, AzureRedisFactory _azureRedis, IPSearcher _ipSearcher, Region2LongitudeLatitudeTranslator _longitudeLatitudeTranslator, DateTimeOffset gmt8Time, bool test = false)
  856. {
  857. ConcurrentBag<ApiVisit> visits = new ConcurrentBag<ApiVisit>();
  858. ConcurrentBag<(string uuid, HttpLog httpLog, List<string> tmdid, List<string> school)> uuidInfo = new ConcurrentBag<(string uuid, HttpLog httpLog, List<string> tmdid, List<string> school)>();
  859. object lockObj = new object();
  860. await Parallel.ForEachAsync(logs, async (log, _) =>
  861. {
  862. if (!log.path.Contains("."))
  863. {
  864. string uuid = Guid.NewGuid().ToString();
  865. List<string> schoolMatch = new List<string>();
  866. List<string> useridMatch = new List<string>();
  867. var vist = new ApiVisit()
  868. {
  869. id=uuid,
  870. ip=log.ip,
  871. tid=log.tid,
  872. time= log.time,
  873. userId= log.id,
  874. school= log.school,
  875. tname= log.name,
  876. path = log.path,
  877. client=log.p.Equals("os", StringComparison.OrdinalIgnoreCase) ? "ies5" : log.p,
  878. scope=log.scope,
  879. host= log.host,
  880. hostName=log.hostName,
  881. l=log.l,
  882. year = $"{gmt8Time:yyyy}",
  883. month = $"{gmt8Time:MM}",
  884. day = $"{gmt8Time:dd}",
  885. hour =$"{gmt8Time:HH}"
  886. };
  887. if (test)
  888. {
  889. var time = DateTimeOffset.FromUnixTimeMilliseconds(log.time);
  890. //本地调试时间
  891. if (vist.ip.Equals("0.0.0.1"))
  892. {
  893. time= time.AddHours(8);
  894. }
  895. vist.year = $"{time:yyyy}";
  896. vist.month = $"{time:MM}";
  897. vist.day = $"{time:dd}";
  898. vist.hour =$"{time:HH}";
  899. }
  900. if (string.IsNullOrWhiteSpace(vist.userId))
  901. {
  902. //var jsonPathContext = new JsonPathContext();
  903. //jsonPathContext.ValueSystem= new JsonTextValueSystem();
  904. string path = "$..['id_token','idToken','idtoken','tmdid','id','teacherId','teacher','tid','tId','userid','userId','code','studentId','student','studentid']";
  905. if (!log.param.ValueKind.Equals(JsonValueKind.Null)) {
  906. JObject jsonObject = JObject.Parse(log.param.GetRawText());
  907. //var nodes_path = jsonPathContext.SelectNodes(log.param, path);
  908. var nodes_path = jsonObject.SelectTokens(path);
  909. foreach (var node in nodes_path)
  910. {
  911. // 只获取是字符串的
  912. if (node.Type.Equals(JTokenType.String))
  913. {
  914. switch (true)
  915. {
  916. case bool when node.Path.Contains("id_token")||node.Path.Contains("idToken")||node.Path.Contains("idtoken"):
  917. {
  918. try
  919. {
  920. var jwt = new JwtSecurityToken($"{node}");
  921. string id = jwt.Payload.Sub;
  922. var name = jwt.Claims.FirstOrDefault(claim => claim.Type.Equals("name"))?.Value;
  923. if (!string.IsNullOrWhiteSpace(id) && long.TryParse(id, out long _id))
  924. {
  925. vist.userId=id;
  926. vist.scope="teacher";
  927. vist.tname=name;
  928. useridMatch.Add(id);
  929. }
  930. }
  931. catch (Exception ex) { }
  932. break;
  933. }
  934. case bool when node.Path.Contains("tmdid")||node.Path.Contains("id")||node.Path.Contains("teacherId")
  935. ||node.Path.Contains("teacher")||node.Path.Contains("tid")||node.Path.Contains("tId")||node.Path.Contains("userid")
  936. ||node.Path.Contains("userId"):
  937. {
  938. if (!string.IsNullOrWhiteSpace($"{node}") && long.TryParse($"{node}", out long _id))
  939. {
  940. vist.userId=$"{node}";
  941. vist.scope="teacher";
  942. useridMatch.Add($"{node}");
  943. }
  944. break;
  945. }
  946. case bool when node.Path.Contains("studentId")||node.Path.Contains("student")||node.Path.Contains("studentid"):
  947. {
  948. if (!string.IsNullOrWhiteSpace($"{node}") && long.TryParse($"{node}", out long _id))
  949. {
  950. vist.userId=$"{node}";
  951. vist.scope="student";
  952. useridMatch.Add($"{node}");
  953. }
  954. break;
  955. }
  956. case bool when node.Path.Contains("code"):
  957. {
  958. if (!string.IsNullOrWhiteSpace($"{node}"))
  959. {
  960. if (long.TryParse($"{node}", out long _id))
  961. {
  962. vist.userId=$"{node}";
  963. useridMatch.Add($"{node}");
  964. }
  965. else
  966. {
  967. string[] codes = $"{node}".Split("-");
  968. foreach (var _code in codes)
  969. {
  970. if (long.TryParse(_code, out long _codeid))
  971. {
  972. vist.userId=$"{node}";
  973. useridMatch.Add($"{_code}");
  974. break;
  975. }
  976. }
  977. }
  978. }
  979. break;
  980. }
  981. }
  982. }
  983. }
  984. if (log.path.Contains("process-notify", StringComparison.OrdinalIgnoreCase))
  985. {
  986. string s = log.param.ToJsonString().Replace("\\", "");
  987. Regex regextmdid = new Regex("\"tmdid\":\"(\\d+)\"");
  988. Match matchtmdid = regextmdid.Match(s);
  989. if (matchtmdid.Success)
  990. {
  991. var t = matchtmdid.Groups[1].Value;
  992. if (!string.IsNullOrWhiteSpace(t))
  993. {
  994. vist.userId=t;
  995. vist.scope="teacher";
  996. useridMatch.Add(t);
  997. }
  998. }
  999. Regex regexname = new Regex("\"tmdname\":\"(.+?)\"");
  1000. Match matchname = regexname.Match(s);
  1001. if (matchname.Success)
  1002. {
  1003. var t = matchname.Groups[1].Value;
  1004. if (!string.IsNullOrWhiteSpace(t))
  1005. {
  1006. vist.tname=t;
  1007. }
  1008. }
  1009. }
  1010. }
  1011. }
  1012. else
  1013. {
  1014. if (string.IsNullOrWhiteSpace($"{vist.scope}"))
  1015. {
  1016. vist.scope="teacher";
  1017. uuidInfo.Add((uuid, log, new List<string>() { vist.userId }, new List<string>()));
  1018. }
  1019. }
  1020. if (string.IsNullOrWhiteSpace(vist.school) || vist.school.Equals("true") || vist.school.Equals("false"))
  1021. {
  1022. vist.school="";
  1023. string path = "$..['school','id','schoolId','schoolid','schoolCode','school_code','schoolcode','code']";
  1024. if (!log.param.ValueKind.Equals(JsonValueKind.Null)) {
  1025. JObject jsonObject = JObject.Parse(log.param.GetRawText());
  1026. var nodes_path = jsonObject.SelectTokens(path);
  1027. foreach (var node in nodes_path)
  1028. {
  1029. // 只获取是字符串的
  1030. if (node.Type.Equals(JTokenType.String))
  1031. {
  1032. switch (true)
  1033. {
  1034. case bool when node.Path.Contains("school")||node.Path.Contains("id")||node.Path.Contains("schoolId")
  1035. ||node.Path.Contains("schoolid")||node.Path.Contains("schoolCode")||node.Path.Contains("school_code")||node.Path.Contains("schoolcode"):
  1036. {
  1037. if (!$"{node}".Contains("-")&& $"{node}".Length<=8 && $"{node}".Length>=1)
  1038. {
  1039. vist.school=$"{node}";
  1040. schoolMatch.Add($"{node}");
  1041. }
  1042. break;
  1043. }
  1044. case bool when node.Path.Contains("code"):
  1045. {
  1046. if (!$"{node}".Contains("-")&& $"{node}".Length<=8&& $"{node}".Length>=1)
  1047. {
  1048. vist.school=$"{node}";
  1049. schoolMatch.Add($"{node}");
  1050. }
  1051. else
  1052. {
  1053. string[] codes = $"{node}".Split("-");
  1054. foreach (var _code in codes)
  1055. {
  1056. if ($"{_code}".Length<=8 && $"{_code}".Length>=1)
  1057. {
  1058. vist.school=$"{_code}";
  1059. schoolMatch.Add($"{_code}");
  1060. break;
  1061. }
  1062. }
  1063. }
  1064. break;
  1065. }
  1066. }
  1067. }
  1068. }
  1069. if (log.path.Contains("process-notify", StringComparison.OrdinalIgnoreCase))
  1070. {
  1071. string s = log.param.ToJsonString().Replace("\\", "");
  1072. Regex regexname = new Regex("\"schoolId\":\"(.+?)\"");
  1073. Match matchname = regexname.Match(s);
  1074. if (matchname.Success)
  1075. {
  1076. var t = matchname.Groups[1].Value;
  1077. if (!string.IsNullOrWhiteSpace(t))
  1078. {
  1079. vist.school=t;
  1080. }
  1081. }
  1082. }
  1083. }
  1084. }
  1085. //处理 client
  1086. {
  1087. if (!string.IsNullOrWhiteSpace(log.client))
  1088. {
  1089. if (log.client.Equals("IES", StringComparison.OrdinalIgnoreCase))
  1090. {
  1091. vist.client="ies5";
  1092. }
  1093. if (log.client.Equals("AClassONE", StringComparison.OrdinalIgnoreCase))
  1094. {
  1095. vist.client="aclassone";
  1096. }
  1097. if (log.client.Equals("BB", StringComparison.OrdinalIgnoreCase))
  1098. {
  1099. vist.client="habb";
  1100. }
  1101. if (log.client.Equals("HiTool", StringComparison.OrdinalIgnoreCase) ||log.client.Equals("HiTools", StringComparison.OrdinalIgnoreCase))
  1102. {
  1103. vist.client="hiscan";
  1104. }
  1105. if (log.client.Equals("HiTA", StringComparison.OrdinalIgnoreCase))
  1106. {
  1107. vist.client="hita";
  1108. vist.scope="teacher";
  1109. }
  1110. if (log.client.Equals("HiTeachCC", StringComparison.OrdinalIgnoreCase))
  1111. {
  1112. vist.client="hiteachcc";
  1113. }
  1114. if (log.client.Equals("HiTeach", StringComparison.OrdinalIgnoreCase))
  1115. {
  1116. vist.scope="teacher";
  1117. vist.client="hiteach";
  1118. }
  1119. if (log.client.Equals("Open", StringComparison.OrdinalIgnoreCase))
  1120. {
  1121. vist.client="open";
  1122. }
  1123. }
  1124. }
  1125. //补全站点
  1126. {
  1127. if (
  1128. (log.host.Equals("wwww.teammodel.net")||log.host.Equals("ies5-rc.teammodel.net")))
  1129. {
  1130. vist.hostName="国际站";
  1131. vist.host="www.teammodel.net";
  1132. vist.client="ies5";
  1133. vist.l="Global";
  1134. }
  1135. else if (
  1136. log.host.Equals("teammodelos-yx.chinacloudsites.cn")||log.host.Equals("teammodelos.chinacloudsites.cn")
  1137. ||log.host.Equals("yx.teammodel.cn")||log.host.Equals("teammodelos-rc.chinacloudsites.cn")||log.host.Equals("rc.teammodel.cn")|| log.host.Equals("www.teammodel.cn"))
  1138. {
  1139. vist.hostName="大陆站";
  1140. vist.host="www.teammodel.cn";
  1141. vist.client="ies5"; vist.l="China";
  1142. }
  1143. else if ((log.host.Contains("localhost") && log.p.Equals("os"))|| log.host.Equals("teammodelos-test.chinacloudsites.cn") ||log.host.Equals("test.teammodel.cn"))
  1144. {
  1145. vist.hostName="测试站";
  1146. vist.host="test.teammodel.cn";
  1147. vist.client="ies5";
  1148. vist.l="China";
  1149. }
  1150. else if (
  1151. (log.host.Equals("scyx.teammodel.cn") ||log.host.Equals("jinniu.teammodel.cn")))
  1152. {
  1153. vist.hostName="研修2.0";
  1154. vist.host="scyx.teammodel.cn";
  1155. vist.client="ability"; vist.l="China";
  1156. }
  1157. else if (
  1158. log.host.Equals("open.teammodel.cn")||log.host.Equals("open-test.teammodel.cn") ||log.host.Equals("zhiyin-test.teammodel.cn"))
  1159. {
  1160. vist.hostName="开放平台";
  1161. vist.host="open.teammodel.cn";
  1162. vist.client="open";
  1163. vist.l="China";
  1164. }
  1165. else if ((log.host.Equals("bi-rc.teammodel.net") || log.host.Equals("bi.teammodel.net")))
  1166. {
  1167. vist.hostName="国际站";
  1168. vist.host="bi.teammodel.net";
  1169. vist.client="bi";
  1170. vist.scope="admin";
  1171. vist.l="Global";
  1172. }
  1173. else if (log.host.Equals("teammodelbi.chinacloudsites.cn") ||log.host.Equals("bi.teammodel.cn"))
  1174. {
  1175. vist.hostName="大陆站";
  1176. vist.host="bi.teammodel.cn";
  1177. vist.client="bi";
  1178. vist.scope="admin";
  1179. vist.l="China";
  1180. }
  1181. else if (log.host.Equals("bitest.teammodel.cn")||log.host.Equals("teammodelbi-test.chinacloudsites.cn")||(log.host.Contains("localhost") && (log.p.Equals("bi"))))
  1182. {
  1183. vist.hostName="测试站";
  1184. vist.host="testbi.teammodel.cn";
  1185. vist.client="bi";
  1186. vist.scope="admin";
  1187. vist.l="China";
  1188. }
  1189. else if (
  1190. log.host.Equals("teamcontest.chinacloudsites.cn")||log.host.Equals("contest.chinacloudsites.cn")||log.host.Equals("contest-test.chinacloudsites.cn"))
  1191. {
  1192. vist.hostName="大陆站";
  1193. vist.host="contest.teammodel.cn";
  1194. vist.client="contest"; vist.l="China";
  1195. }
  1196. else if (
  1197. log.host.Equals("hiteachcc.chinacloudsites.cn"))
  1198. {
  1199. vist.hostName="正式站";
  1200. vist.host="hiteachcc.teammodel.cn";
  1201. vist.client="hiteachcc";
  1202. vist.l="China";
  1203. }
  1204. else if (log.host.Equals("appraisal.chinacloudsites.cn"))
  1205. {
  1206. vist.hostName="大陆站";
  1207. vist.host="appraisal.teammodel.cn";
  1208. vist.client="appraisal";
  1209. vist.l="China";
  1210. }
  1211. else if ((log.host.Contains("localhost") && log.p.Equals("appraisal"))||log.host.Equals("appraisal-test.teammodel.cn") ||log.host.Equals("appraisal-test.chinacloudsites.cn"))
  1212. {
  1213. vist.hostName="测试站";
  1214. vist.host="appraisal-test.teammodel.cn";
  1215. vist.client="appraisal";
  1216. vist.l="China";
  1217. }
  1218. else
  1219. {
  1220. if (!string.IsNullOrWhiteSpace(log.p))
  1221. {
  1222. vist.client=log.p.Equals("os", StringComparison.OrdinalIgnoreCase) ? "ies5" : log.p;
  1223. }
  1224. else
  1225. {
  1226. vist.client="other";
  1227. }
  1228. if (log.host.EndsWith(".cn"))
  1229. {
  1230. vist.hostName="大陆站";
  1231. vist.l="China";
  1232. }
  1233. else if (log.host.EndsWith(".net"))
  1234. {
  1235. vist.hostName="国际站";
  1236. vist.l="Global";
  1237. }
  1238. else
  1239. {
  1240. vist.hostName="其他";
  1241. vist.l="其他";
  1242. }
  1243. }
  1244. }
  1245. //补全产品端
  1246. {
  1247. //研修2.0
  1248. if (log.path.Contains("research") || log.path.Contains("study") || log.path.Contains("standard-file"))
  1249. {
  1250. vist.client="ability";
  1251. }
  1252. if (log.path.Contains("teacher"))
  1253. {
  1254. vist.scope="teacher";
  1255. }
  1256. if (log.path.Contains("tmduser"))
  1257. {
  1258. vist.scope=Constant.ScopeTmdUser;
  1259. }
  1260. if (log.path.Contains("student/login"))
  1261. {
  1262. vist.scope=Constant.ScopeStudent;
  1263. }
  1264. if (log.path.StartsWith("/activity"))
  1265. {
  1266. vist.client="contest";
  1267. }
  1268. //小程序
  1269. if (log.path.Contains("aclassone"))
  1270. {
  1271. vist.client="aclassone";
  1272. }
  1273. // /// <summary>
  1274. /// ExamInfo qamode 書面問答類型 0:書面問答 1:紙本測驗 2:艺术评测
  1275. /// </summary>
  1276. //艺术评测
  1277. if (log.path.Contains("art") ||log.path.Contains("aclassone/find-children-activity") ||log.path.Contains("aclassone/find-teacher-activity") ||log.path.Contains("aclassone/find-summary-activity") ||log.path.Contains("aclassone/upload-all") ||log.path.Contains("aclassone/delete"))
  1278. {
  1279. vist.client="art";
  1280. }
  1281. if (log.path.Contains("common/exam/upsert-record"))
  1282. {
  1283. JObject jobject = JObject.Parse(log.param.GetRawText());
  1284. var jtokens = jobject.SelectTokens("$..artId");
  1285. if (jtokens!=null && jtokens.Count()>0)
  1286. {
  1287. vist.client="art";
  1288. vist.scope=Constant.ScopeStudent;
  1289. }
  1290. }
  1291. if (log.path.Contains("habb"))
  1292. {
  1293. vist.client="habb";
  1294. }
  1295. //阅卷客户端
  1296. if (log.path.Contains("hiscan"))
  1297. {
  1298. vist.client="hiscan";
  1299. }
  1300. if (log.path.Contains("hita"))
  1301. {
  1302. vist.client="hita";
  1303. }
  1304. if (log.path.Contains("hiteachcc"))
  1305. {
  1306. vist.client="hiteachcc";
  1307. }
  1308. if (log.path.Contains("sokrate"))
  1309. {
  1310. vist.client="sokrate";
  1311. }
  1312. if (log.path.Contains("sokrate") || log.path.Contains("score"))
  1313. {
  1314. vist.client="sokrate";
  1315. }
  1316. if (log.path.Contains("hiteach"))
  1317. {
  1318. vist.client="hiteach";
  1319. }
  1320. ///IES开放平台
  1321. if (log.path.Contains("business") || log.path.Contains("biz") || log.path.Contains("openapi-config") || log.path.Contains("open-api"))
  1322. {
  1323. vist.client="open";
  1324. }
  1325. //从token的role 能否获取 开放平台
  1326. //单点登录及第三方接口
  1327. if (log.path.Contains("lepei") || log.path.Contains("sc/") || log.path.Contains("/sso") || log.path.Contains("sc-init")|| log.path.Contains("moofen") || log.path.Contains("data-push") || log.path.Contains("xkw")|| log.path.Contains("tianbo")
  1328. || log.path.Contains("oauth/check-bind")|| log.path.Contains("dingding") || log.path.Contains("wechat")
  1329. )
  1330. {
  1331. vist.client="sso-third";
  1332. }
  1333. }
  1334. //处理IP转地区
  1335. var region = await _ipSearcher.SearchIpAsync(vist.ip);
  1336. if (string.IsNullOrWhiteSpace(region))
  1337. {
  1338. region="未知IP·未知IP·未知IP";
  1339. }
  1340. if (!string.IsNullOrWhiteSpace(region))
  1341. {
  1342. region= region.Replace("省·", "·").Replace("市·", "·").Replace("特别行政区·", "·").Replace("藏族羌族自治州·", "·");
  1343. var regions = region.Split("·");
  1344. if (regions.Length==4)
  1345. {
  1346. vist.area= regions[0];
  1347. vist.province = regions[1];
  1348. vist.city = regions[2];
  1349. }
  1350. if (regions.Length==3)
  1351. {
  1352. vist.area= regions[0];
  1353. vist.province = regions[1];
  1354. }
  1355. if (regions.Length==2)
  1356. {
  1357. vist.area= regions[0];
  1358. vist.province = regions[1];
  1359. }
  1360. if (regions.Length==1)
  1361. {
  1362. vist.area= regions[0];
  1363. }
  1364. }
  1365. //处理地区转经纬度
  1366. {
  1367. IEnumerable<JToken> tokens = default;
  1368. if (!string.IsNullOrWhiteSpace(vist.city) && !string.IsNullOrWhiteSpace(vist.province) && !string.IsNullOrWhiteSpace(vist.area))
  1369. {
  1370. tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.province}/i && @.city=~ /.*{vist.city}/i)]");
  1371. if (!(tokens.Any() && tokens.Count()>0))
  1372. {
  1373. tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.city}/i && @.city=~ /.*{vist.province}/i)]");
  1374. if (!(tokens.Any() && tokens.Count()>0))
  1375. {
  1376. tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.city}/i || @.city=~ /.*{vist.city}/i)]");
  1377. }
  1378. if (!(tokens.Any() && tokens.Count()>0))
  1379. {
  1380. tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.province}/i||@.city=~ /.*{vist.province}/i)]");
  1381. }
  1382. }
  1383. }
  1384. else if (string.IsNullOrWhiteSpace(vist.city) && !string.IsNullOrWhiteSpace(vist.province) && !string.IsNullOrWhiteSpace(vist.area))
  1385. {
  1386. if (vist.area.Equals("中国"))
  1387. {
  1388. tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.province}/i)]");
  1389. if (!(tokens.Any() && tokens.Count()>0))
  1390. {
  1391. tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.city=~ /.*{vist.province}/i)]");
  1392. }
  1393. }
  1394. else
  1395. {
  1396. tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.city=~ /.*{vist.province}/i || @.province=~ /.*{vist.province}/i)]");
  1397. }
  1398. }
  1399. else if (!string.IsNullOrWhiteSpace(vist.city) && string.IsNullOrWhiteSpace(vist.province)&& !string.IsNullOrWhiteSpace(vist.area))
  1400. {
  1401. if (vist.area.Equals("中国"))
  1402. {
  1403. tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.city}/i)]");
  1404. if (!(tokens.Any() && tokens.Count()>0))
  1405. {
  1406. tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.city=~ /.*{vist.province}/i)]");
  1407. }
  1408. }
  1409. else
  1410. {
  1411. tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.city=~ /.*{vist.city}/i || @.city=~ /.*{vist.province}/i)]");
  1412. }
  1413. }
  1414. else if (string.IsNullOrWhiteSpace(vist.city) && string.IsNullOrWhiteSpace(vist.province)&& !string.IsNullOrWhiteSpace(vist.area))
  1415. {
  1416. tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.country=~ /.*{vist.area}/i && @.m=='1')]");
  1417. }
  1418. if (tokens!=null && tokens.Any())
  1419. {
  1420. List<RegionLngLat> regionLngLats = new List<RegionLngLat>();
  1421. foreach (JToken token in tokens)
  1422. {
  1423. regionLngLats.Add(token.ToString().ToObject<RegionLngLat>());
  1424. }
  1425. var points = regionLngLats.FindAll(x => string.IsNullOrWhiteSpace(x.area));
  1426. if (!points.IsNotEmpty())
  1427. {
  1428. points= regionLngLats.FindAll(x => !string.IsNullOrWhiteSpace(x.m) && x.m.Equals("1"));
  1429. }
  1430. if (string.IsNullOrWhiteSpace(vist.city))
  1431. {
  1432. vist.city=points?.FirstOrDefault()?.city;
  1433. if (!string.IsNullOrWhiteSpace(vist.city) && vist.city.EndsWith("市"))
  1434. {
  1435. vist.city=vist.city.Replace("市", "");
  1436. }
  1437. }
  1438. vist.lat=points?.FirstOrDefault()?.lat;
  1439. vist.lng=points?.FirstOrDefault()?.lng;
  1440. }
  1441. else
  1442. {
  1443. if (vist.area.Equals("内网IP"))
  1444. {
  1445. if (vist.host.Contains(".cn") || vist.host.Contains("localhost"))
  1446. {
  1447. vist.lat="30.655821878416408";
  1448. vist.lng="104.08153351042463";
  1449. vist.area="中国";
  1450. vist.province="四川";
  1451. vist.city="成都";
  1452. }
  1453. else
  1454. {
  1455. vist.lat="25.044332";
  1456. vist.lng="121.509062";
  1457. vist.area="中国";
  1458. vist.province="台湾";
  1459. vist.city="台湾";
  1460. }
  1461. }
  1462. else
  1463. {
  1464. vist.lat="30.655821878416408";
  1465. vist.lng="104.08153351042463";
  1466. vist.area="中国";
  1467. vist.province="四川";
  1468. vist.city="成都";
  1469. }
  1470. }
  1471. }
  1472. uuidInfo.Add((uuid, log, useridMatch, schoolMatch));
  1473. visits.Add(vist);
  1474. }
  1475. }
  1476. );
  1477. List<(string tmd, bool exists, string scope)> tmdexists = new List<(string tmd, bool exists, string scope)>();
  1478. List<(string sch, bool exists)> schexists = new List<(string sch, bool exists)>();
  1479. var tmds = uuidInfo.SelectMany(x => x.tmdid).ToHashSet();
  1480. if (tmds.Any())
  1481. {
  1482. foreach (var tmd in tmds)
  1483. {
  1484. var exists = await _azureRedis.GetRedisClient(8).KeyExistsAsync($"Blob:Catalog:{tmd}");
  1485. if (exists)
  1486. {
  1487. tmdexists.Add((tmd, exists, "teacher"));
  1488. }
  1489. else
  1490. {
  1491. exists = await _azureRedis.GetRedisClient(8).KeyExistsAsync($"Login:School:hbcn:student:{tmd}");
  1492. tmdexists.Add((tmd, exists, "student"));
  1493. }
  1494. }
  1495. }
  1496. var schs = uuidInfo.SelectMany(x => x.school).ToHashSet();
  1497. if (schs.Any())
  1498. {
  1499. foreach (var sch in schs)
  1500. {
  1501. var exists = await _azureRedis.GetRedisClient(8).KeyExistsAsync($"Blob:Catalog:{sch}");
  1502. schexists.Add((sch, exists));
  1503. }
  1504. }
  1505. foreach (var item in uuidInfo)
  1506. {
  1507. foreach (var tmd in item.tmdid)
  1508. {
  1509. var tmdext = tmdexists.Find(x => x.tmd.Equals(tmd));
  1510. if (tmdext.tmd!= null && tmdext.exists)
  1511. {
  1512. var vist = visits.Where(x => x.id.Equals(item.uuid));
  1513. foreach (var vi in vist)
  1514. {
  1515. vi.userId=tmd;
  1516. if (string.IsNullOrWhiteSpace(vi.scope))
  1517. {
  1518. vi.scope=tmdext.scope;
  1519. }
  1520. }
  1521. break;
  1522. }
  1523. }
  1524. foreach (var sch in item.school)
  1525. {
  1526. var schext = schexists.Find(x => x.sch.Equals(sch));
  1527. if (schext.sch!= null && schext.exists)
  1528. {
  1529. var vist = visits.Where(x => x.id.Equals(item.uuid));
  1530. foreach (var vi in vist)
  1531. {
  1532. vi.school=sch;
  1533. }
  1534. break;
  1535. }
  1536. }
  1537. }
  1538. return (visits, uuidInfo);
  1539. }
  1540. public class ApiVisit
  1541. {
  1542. public string id { get; set; }
  1543. public string path { get; set; }
  1544. /// <summary>
  1545. /// 细分
  1546. /// ies5 ,hiteach,hita,cc,bi,contest,open,aclassone,sokrates,ability,art
  1547. /// 产品端
  1548. /// </summary>
  1549. public string client { get; set; }
  1550. /// <summary>
  1551. /// 具体功能
  1552. /// </summary>
  1553. // public string func { get; set; }
  1554. public string userId { get; set; }
  1555. public string scope { get; set; }
  1556. public string tname { get; set; }
  1557. public string school { get; set; }
  1558. public string ip { get; set; }
  1559. //public string region { get; set; }
  1560. public string area { get; set; }
  1561. public string province { get; set; }
  1562. public string city { get; set; } = "";
  1563. public long time { get; set; }
  1564. /// <summary>
  1565. ///
  1566. /// </summary>
  1567. public string host { get; set; }
  1568. public string hostName { get; set; } = "其他";
  1569. /// <summary>
  1570. /// tokenid
  1571. /// </summary>
  1572. public string tid { get; set; }
  1573. public string year { get; set; }
  1574. public string month { get; set; }
  1575. public string day { get; set; }
  1576. public string hour { get; set; }
  1577. //public RegionLngLat point { get; set; }
  1578. public string lat { get; set; }
  1579. public string lng { get; set; }
  1580. public string l { get; set; }
  1581. }
  1582. public class HttpLog
  1583. {
  1584. public string ip { get; set; }
  1585. public long time { get; set; }
  1586. public string host { get; set; }
  1587. public string hostName = "其他";
  1588. public string tid { get; set; }
  1589. public string path { get; set; }
  1590. public string client { get; set; }
  1591. public JsonElement param { get; set; }
  1592. public string id { get; set; }
  1593. public string name { get; set; }
  1594. public string school { get; set; }
  1595. public string p { get; set; }
  1596. // public string ua { get; set; }
  1597. // public string referer { get; set; }
  1598. public string scope { get; set; }
  1599. public string year { get; set; }
  1600. public string month { get; set; }
  1601. public string day { get; set; }
  1602. public string hour { get; set; }
  1603. public string l { get; set; }
  1604. }
  1605. public record RegionLngLat
  1606. {
  1607. public string country { get; set; }
  1608. public string province { get; set; }
  1609. public string city { get; set; }
  1610. public string lat { get; set; }
  1611. public string lng { get; set; }
  1612. public string area { get; set; }
  1613. public string m { get; set; } = "0";
  1614. }
  1615. public class CountData
  1616. {
  1617. public string pk { get; set; } = "";
  1618. public string sk { get; set; } = "";
  1619. public string sp { get; set; } = "";
  1620. public int count { get; set; }
  1621. }
  1622. public class SchoolStick
  1623. {
  1624. /// <summary>
  1625. /// 名字
  1626. /// </summary>
  1627. public string name { get; set; }
  1628. public string picture { get; set; }
  1629. /// <summary>
  1630. /// 编码
  1631. /// </summary>
  1632. public string id { get; set; }
  1633. public string last { get; set; }
  1634. #region tmd
  1635. public ClientStick tmd { get; set; } = new ClientStick();
  1636. #endregion
  1637. #region hiteach
  1638. public ClientStick hiteach { get; set; } = new ClientStick();
  1639. public Indicator lesson { get; set; } = new Indicator();
  1640. #endregion
  1641. #region hita
  1642. public ClientStick hita { get; set; } = new ClientStick();
  1643. #endregion
  1644. #region ies5Teacher
  1645. public ClientStick ies5Tch { get; set; } = new ClientStick();
  1646. #endregion
  1647. #region otherTeacher
  1648. public ClientStick otherTch { get; set; } = new ClientStick();
  1649. #endregion
  1650. #region ies5Student
  1651. public ClientStick ies5Stu { get; set; } = new ClientStick();
  1652. #endregion
  1653. #region otherStudent
  1654. public ClientStick otherStu { get; set; } = new ClientStick();
  1655. #endregion
  1656. public List<TchStick> tchSticks { get; set; } = new List<TchStick>();
  1657. public List<StuStick> stuSticks { get; set; } = new List<StuStick>();
  1658. }
  1659. public class TchStick {
  1660. public string school { get; set; }
  1661. /// <summary>
  1662. /// 名字
  1663. /// </summary>
  1664. public string name { get; set; }
  1665. public string picture { get; set; }
  1666. /// <summary>
  1667. /// 编码
  1668. /// </summary>
  1669. public string id { get; set; }
  1670. public string last { get; set; }
  1671. #region tmd
  1672. public ClientStick tmd { get; set; } = new ClientStick();
  1673. #endregion
  1674. #region hiteach
  1675. public ClientStick hiteach { get; set; } = new ClientStick();
  1676. public Indicator lesson { get; set; } = new Indicator();
  1677. #endregion
  1678. #region hita
  1679. public ClientStick hita { get; set; } = new ClientStick();
  1680. #endregion
  1681. #region ies5Teacher
  1682. public ClientStick ies5Tch { get; set; } = new ClientStick();
  1683. #endregion
  1684. #region otherTeacher
  1685. public ClientStick otherTch { get; set; } = new ClientStick();
  1686. #endregion
  1687. }
  1688. public class StuStick
  1689. {
  1690. public string school { get; set; }
  1691. /// <summary>
  1692. /// 名字
  1693. /// </summary>
  1694. public string name { get; set; }
  1695. public string picture { get; set; }
  1696. /// <summary>
  1697. /// 编码
  1698. /// </summary>
  1699. public string id { get; set; }
  1700. public string last { get; set; }
  1701. #region tmd
  1702. public ClientStick tmd { get; set; } = new ClientStick();
  1703. #endregion
  1704. #region ies5Student
  1705. public ClientStick ies5Stu { get; set; } = new ClientStick();
  1706. #endregion
  1707. #region otherStudent
  1708. public ClientStick otherStu { get; set; } = new ClientStick();
  1709. #endregion
  1710. }
  1711. public class ClientStick
  1712. {
  1713. public int userCount { get; set; }
  1714. public Indicator stick { get; set; } = new Indicator();
  1715. public Indicator duration { get; set; } = new Indicator();
  1716. public Indicator count { get; set; } = new Indicator();
  1717. }
  1718. public class Indicator
  1719. {
  1720. /// <summary>
  1721. /// 值
  1722. /// </summary>
  1723. public double value { get; set; } = 0;
  1724. /// <summary>
  1725. /// 值的增减浮动
  1726. /// </summary>
  1727. public double range { get; set; } = 0;
  1728. /// <summary>
  1729. /// 排名
  1730. /// </summary>
  1731. public double rank { get; set; } = 0;
  1732. /// <summary>
  1733. /// 排名的上升下降
  1734. /// </summary>
  1735. public double updown { get; set; } = 0;
  1736. }
  1737. }
  1738. }