SystemService.cs 129 KB

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