SystemService.cs 128 KB

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