SystemService.cs 129 KB

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