SystemService.cs 111 KB

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