SystemService.cs 129 KB

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