SystemService.cs 134 KB

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