SystemService.cs 135 KB

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