SystemService.cs 259 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686
  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. using System.Collections;
  22. using TEAMModelOS.SDK.Models.Cosmos.OpenEntity;
  23. using System.Globalization;
  24. using Microsoft.OData;
  25. using System.Configuration;
  26. using System.ServiceModel.Channels;
  27. using static System.Runtime.InteropServices.JavaScript.JSType;
  28. using System.Threading;
  29. using TEAMModelOS.SDK.Models.Cosmos;
  30. namespace TEAMModelOS.SDK.Models.Service
  31. {
  32. public static class SystemService
  33. {
  34. #region
  35. static string cn_wb = @"
  36. IES晚间报告:{tmdname}您好,以下是您的今日个人IES教学汇总报告,截至{sendTime}时,您已发布{examCount}次评测任务,{homeworkCount}次作业任务,并使用HiTeach教师端开设了{lessonCount}节课堂教学活动。
  37. 以下是报告的具体详细信息。
  38. {cn_examTitle}{cn_examList}
  39. {cn_lessonTitle}{cn_lessonList}
  40. {cn_groupTitle}{cn_groupList}
  41. 如有布置作业任务,将于次日8点通过早报方式发送。
  42. ";
  43. static string cn_examList = "【{examName}】已经有{submitCount}位学生提交,仍有{unsubmitCount}位学生未提交。";
  44. static string cn_lessonList = "【{lessonName}】课例应出席人数{memberCount},实际出席人数{attendCount},出席率{attendRate}%。";
  45. static string cn_groupListJoin = "【{grouplistName}】已有总人数{memberCount}位,有{joinCount}位加入。";
  46. static string cn_groupListLeave = "【{grouplistName}】已有总人数{memberCount}位,有{joinCount}位离开。";
  47. static string cn_zb = @"
  48. IES早间报告:{tmdname}您好,以下是您发布过的作业任务汇总报告。
  49. 以下是报告的具体详细信息。
  50. {cn_homeworkTitle}{cn_homeworkList}
  51. ";
  52. static string cn_homeworkList = "【{homeworkName}】已经有{submitCount}位学生提交,仍有{unsubmitCount}位学生未提交。";
  53. static string cn_homeworkTitle = "作业任务提交详情:";
  54. static string cn_examTitle = "评测任务提交详情:";
  55. static string cn_lessonTitle = "课堂教学出席详情:";
  56. static string cn_groupTitle = "个人课程名单变化详情:";
  57. static string cn_lessonDetail = @"</br>课例名称:{name},开课时间:{time},时长:{duration}分钟</br>
  58. 1.本节课名单{count}人,分成{groupCount}组,出席人数:{attendCount}人,缺席:{absentCount}人,出席率{attendRate}%</br>
  59. 2.学习参与度指数平均:{engagementIndexAverge} </br>
  60. 分组参与度:{grpEngagement}</br>
  61. 参与较多者:{highRankEngagement}</br>
  62. 3.记分:总记分:{totalPoint}分 </br>
  63. 个人记分较多者:{highRankPerPoint}</br>
  64. 小组记分较多的:{highRankGrpPoint}</br>
  65. 4.互动:{interactionCount}题,总互动分:{totalInteractPoint}分</br>
  66. 5.任务:{pushCount}次,作品总数:{collateTaskCount}件</br>
  67. 6.测验:{examCount}次,题数:{examQuizCount}题,平均得分率:{examPointRate}% </br>
  68. 表现较好者:{highRankExam}</br>
  69. 表现较弱者:{lowRankExam}</br>
  70. 7.互评:{smartRatingCount}次,合计参与:{clientSmartRatingCount}次</br>
  71. 8.协作:{coworkTaskCount}次,作品总数:{coworkGroupCount}件,总操作量:{coworkGroupCount}</br>";
  72. #endregion
  73. #region
  74. static string tw_wb = @"
  75. IES晚間報告:{tmdname}您好,以下是您的今日個人IES教學總結報告,截至{sendTime},您已發布{examCount}次測驗任務,{homeworkCount}次作業任務,並使用HiTeach上傳了{lessonCount}節課堂教學活動。
  76. 以下是詳細資訊。
  77. {tw_examTitle}{tw_examList}
  78. {tw_lessonTitle}{tw_lessonList}
  79. {tw_groupTitle}{tw_groupList}
  80. 如有佈署作業任務,將於隔天早上8點透過晨間報告方式發送。
  81. ";
  82. static string tw_examList = "【{examName}】已經有{submitCount}位學生繳交,仍有{unsubmitCount}位學生未繳交。";
  83. static string tw_lessonList = "【{lessonName}】課堂應出席人數{memberCount},實際出席人數{attendCount},出席率{attendRate}%。";
  84. static string tw_groupListJoin = "【{grouplistName}】已有總人數{memberCount}位,有{joinCount}位加入。";
  85. static string tw_groupListLeave = "【{grouplistName}】已有總人數{memberCount}位,有{joinCount}位離開。";
  86. static string tw_zb = @"
  87. IES晨間報告:{tmdname}您好,以下是您曾經發佈過的作業任務總結報告。
  88. 以下是具體詳細資訊。
  89. {tw_homeworkTitle}{tw_homeworkList}
  90. ";
  91. static string tw_homeworkList = "【{homeworkName}】已經有{submitCount}位學生繳交,仍有{unsubmitCount}位學生未繳交。";
  92. static string tw_homeworkTitle = "作業任務繳交詳情:";
  93. static string tw_examTitle = "測驗任務完成詳情:";
  94. static string tw_lessonTitle = "課堂教學出席詳情:";
  95. static string tw_groupTitle = "個人課程名單變動詳情:";
  96. static string tw_lessonDetail = @"</br>课例名称:{name},開課時間:{time},時長:{duration}分鐘</br>
  97. 1.本節課名單{count}人,分成{groupCount}組,出席人数:{attendCount}人,缺席:{absentCount}人,出席率{attendRate}%</br>
  98. 2.學習参與度指數平均:{engagementIndexAverge}</br>
  99. 分組参舆度:{grpEngagement}</br>
  100. 参與较多者:{highRankEngagement}</br>
  101. 3.記分:總記分:{totalPoint}分</br>
  102. 個人記分较多者:{highRankPerPoint}</br>
  103. 小組記分较多的:{highRankGrpPoint}</br>
  104. 4.互動:{interactionCount}题,總互動分:{totalInteractPoint}分</br>
  105. 5.任務:{pushCount}次,作品總数:{collateTaskCount}件</br>
  106. 6.測驗:{examCount}次,题數:{examQuizCount}题,平均得分率:{examPointRate}%</br>
  107. 表現较好者:{highRankExam}</br>
  108. 表現较弱者:{lowRankExam}</br>
  109. 7.互评:{smartRatingCount}次,合計参與:{clientSmartRatingCount}次</br>
  110. 8.協作:{coworkTaskCount}次,作品總數:{coworkGroupCount}件,總操作量:{coworkGroupCount}</br>";
  111. #endregion
  112. #region
  113. static string en_wb = @"
  114. 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.
  115. The following are the specific details.
  116. {en_examTitle}{en_examList}
  117. {en_lessonTitle}{en_lessonList}
  118. {en_groupTitle}{en_groupList}
  119. If there are homework tasks assigned, they will be sent through the morning report at 8 am the next day.
  120. ";
  121. static string en_examList = "[ {examName} ] has {submitCount} students submitted, and there are still {unsubmitCount} students who have not submitted.";
  122. static string en_lessonList = "[ {lessonName} ] lesson should have {memberCount} attendees, actual attendees {attendCount}, attendance rate {attendRate}%.";
  123. static string en_groupListJoin = "[ {grouplistName} ] has a total of {memberCount}, {joinCount} joined.";
  124. static string en_groupListLeave = "[ {grouplistName} ] has a total of {memberCount}, {joinCount} left.";
  125. static string en_zb = @"
  126. IES Morning Report:
  127. Hello {tmdname}, here is the summary report of the homework tasks you have posted.
  128. {en_homeworkTitle}{en_homeworkList}
  129. ";
  130. static string en_homeworkList = "[ {homeworkName} ] has {submitCount} students submitted, and there are still {unsubmitCount} students who have not submitted.";
  131. static string en_homeworkTitle = "Homework Submission Details:";
  132. static string en_examTitle = "Test task submission details:";
  133. static string en_lessonTitle = "Lesson attendance details:";
  134. static string en_groupTitle = "Personal course list change details:";
  135. static string en_lessonDetail = @"</br>Lesson Name: {name}, Start time: {time}, Duration: {duration} Minutes</br>
  136. 1. There are {count} people in this course, divided into {groupCount} groups, attendance: {attendCount} people, absences: 0 people, attendance rate {attendRate}%</br>
  137. 2. Learning Engagement : {engagementIndexAverge}</br>
  138. Engagement per group: {grpEngagement}</br>
  139. More engaged students: {highRankEngagement}</br>
  140. 3. Total Points: {totalPoint} points</br>
  141. Persons with more points: {highRankPerPoint}</br>
  142. Groups with more points: {highRankGrpPoint}</br>
  143. 4. IRS Interaction: {interactionCount} questions, total IRS interaction score: {totalInteractPoint} points</br>
  144. 5. Tasks: {pushCount} times, total number of collected works: {collateTaskCount} </br>
  145. 6. Test/Exam: {examCount} times, number of questions: {examQuizCount} questions, average scoring rate: {examPointRate}%</br>
  146. Better performers: {highRankExam}</br>
  147. Weaker performers: {lowRankExam}</br>
  148. 7. Smart Rating: {smartRatingCount} times, total participation: {clientSmartRatingCount} times</br>
  149. 8. Collaboration: {coworkTaskCount} times, total number of works: {coworkGroupCount}, total operation: {coworkGroupCount}</br>";
  150. #endregion
  151. // #region
  152. // static string cn_wb = @"
  153. //IES晚间报告:</br>{tmdname}您好,以下是您的今日个人IES教学汇总报告,截至{sendTime}时,您已发布{examCount}次评测任务,{homeworkCount}次作业任务,并使用HiTeach教师端开设了{lessonCount}节课堂教学活动。
  154. //</br>&nbsp;&nbsp;&nbsp;以下是报告的具体详细信息。
  155. //</br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{cn_examTitle}</br>{cn_examList}
  156. //</br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{cn_lessonTitle}</br>{cn_lessonList}
  157. //</br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{cn_groupTitle}</br>{cn_groupList}
  158. //</br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;如有布置作业任务,将于次日8点通过早报方式发送。
  159. //";
  160. // static string cn_examList = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;【{examName}】已经有{submitCount}位学生提交,仍有{unsubmitCount}位学生未提交。</br>";
  161. // static string cn_lessonList = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;【{lessonName}】课例应出席人数{memberCount},实际出席人数{attendCount},出席率{attendRate}%。</br>";
  162. // static string cn_groupListJoin = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;【{grouplistName}】已有总人数{memberCount}位,有{joinCount}位加入。</br>";
  163. // static string cn_groupListLeave = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;【{grouplistName}】已有总人数{memberCount}位,有{joinCount}位离开。</br>";
  164. // static string cn_zb = @"
  165. //IES早间报告:</br>{tmdname}您好,以下是您发布过的作业任务汇总报告。
  166. //</br>&nbsp;&nbsp;&nbsp;以下是报告的具体详细信息。
  167. //</br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{cn_homeworkTitle}</br>{cn_homeworkList}
  168. //";
  169. // static string cn_homeworkList = "【{homeworkName}】已经有{submitCount}位学生提交,仍有{unsubmitCount}位学生未提交。</br>";
  170. // static string cn_homeworkTitle = "作业任务提交详情:";
  171. // static string cn_examTitle = "评测任务提交详情:";
  172. // static string cn_lessonTitle = "课堂教学出席详情:";
  173. // static string cn_groupTitle = "个人课程名单变化详情:";
  174. // #endregion
  175. // #region
  176. // static string tw_wb = @"
  177. //IES晚間報告:</br>{tmdname}您好,以下是您的今日個人IES教學總結報告,截至{sendTime},您已發布{examCount}次測驗任務,{homeworkCount}次作業任務,並使用HiTeach上傳了{lessonCount}節課堂教學活動。
  178. //</br>&nbsp;&nbsp;&nbsp;以下是詳細資訊。
  179. //</br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{tw_examTitle}</br>{tw_examList}
  180. //</br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{tw_lessonTitle}</br>{tw_lessonList}
  181. //</br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{tw_groupTitle}</br>{tw_groupList}
  182. //</br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;如有佈署作業任務,將於隔天早上8點透過晨間報告方式發送。
  183. //";
  184. // static string tw_examList = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;【{examName}】已經有{submitCount}位學生繳交,仍有{unsubmitCount}位學生未繳交。</br>";
  185. // static string tw_lessonList = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;【{lessonName}】課堂應出席人數{memberCount},實際出席人數{attendCount},出席率{attendRate}%。</br>";
  186. // static string tw_groupListJoin = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;【{grouplistName}】已有總人數{memberCount}位,有{joinCount}位加入。</br>";
  187. // static string tw_groupListLeave = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;【{grouplistName}】已有總人數{memberCount}位,有{joinCount}位離開。</br>";
  188. // static string tw_zb = @"
  189. //IES晨間報告:</br>{tmdname}您好,以下是您曾經發佈過的作業任務總結報告。
  190. //</br>&nbsp;&nbsp;&nbsp;以下是具體詳細資訊。
  191. //</br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{tw_homeworkTitle}</br>{tw_homeworkList}
  192. //";
  193. // static string tw_homeworkList = "【{homeworkName}】已經有{submitCount}位學生繳交,仍有{unsubmitCount}位學生未繳交。</br>";
  194. // static string tw_homeworkTitle = "作業任務繳交詳情:";
  195. // static string tw_examTitle = "測驗任務完成詳情:";
  196. // static string tw_lessonTitle = "課堂教學出席詳情:";
  197. // static string tw_groupTitle = "個人課程名單變動詳情:";
  198. // #endregion
  199. // #region
  200. // static string en_wb = @"
  201. //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.
  202. //</br>&nbsp;&nbsp;&nbsp;The following are the specific details.
  203. //</br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{en_examTitle}</br>{en_examList}
  204. //</br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{en_lessonTitle}</br>{en_lessonList}
  205. //</br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{en_groupTitle}</br>{en_groupList}
  206. //</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.
  207. //";
  208. // 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>";
  209. // static string en_lessonList = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[ {lessonName} ] lesson should have {memberCount} attendees, actual attendees {attendCount}, attendance rate {attendRate}%.</br>";
  210. // static string en_groupListJoin = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[ {grouplistName} ] has a total of {memberCount}, {joinCount} joined.</br>";
  211. // static string en_groupListLeave = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[ {grouplistName} ] has a total of {memberCount}, {joinCount} left.</br>";
  212. // static string en_zb = @"
  213. //IES Morning Report:
  214. //</br>&nbsp;&nbsp;&nbsp;Hello {tmdname}, here is the summary report of the homework tasks you have posted.
  215. //</br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{en_homeworkTitle}</br>{en_homeworkList}
  216. //";
  217. // static string en_homeworkList = "[ {homeworkName} ] has {submitCount} students submitted, and there are still {unsubmitCount} students who have not submitted.</br>";
  218. // static string en_homeworkTitle = "Homework Submission Details:";
  219. // static string en_examTitle = "Test task submission details:";
  220. // static string en_lessonTitle = "Lesson attendance details:";
  221. // static string en_groupTitle = "Personal course list change details:";
  222. // #endregion
  223. public static string weeklyReportCN = @"<!DOCTYPE html>
  224. <html>
  225. <head>
  226. <title>HiTeach课堂数据周报</title>
  227. <meta charset=""UTF-8"">
  228. <style>
  229. </style>
  230. </head>
  231. <body>
  232. <div style=""margin: 0 0 20px 10px;"">
  233. <p style=""font-size: 20px;"">
  234. <span id=""tmdName"">{tmdName}</span>
  235. 教师您好,你于{year}第{Week}周({weekTime})创建了{lessonCount}节HiTeach5课堂教学活动,以下是报告总览信息,点击其中一行可查看报告详细信息
  236. </p>
  237. <div style=""margin-left: 10px;"">
  238. <table border=""1"" cellpadding=""10"" cellspacing=""0"" border=""1"" cellpadding=""10"" border=""1"" id=""acourseData"">
  239. <thead>
  240. <tr>
  241. <th>课程名称</th>
  242. <th>科目</th>
  243. <th>学校/个人</th>
  244. <th>名单</th>
  245. <th>课例数量</th>
  246. <th>查看详情</th>
  247. </tr>
  248. </thead>
  249. <tbody>
  250. {tableData}
  251. </tbody>
  252. </table>
  253. </div>
  254. </div>
  255. </body>
  256. </html>";
  257. public static string weeklyReportTW = @"<!DOCTYPE html>
  258. <html>
  259. <head>
  260. <title>HiTeach課堂數據週報</title>
  261. <meta charset=""UTF-8"">
  262. <style>
  263. </style>
  264. </head>
  265. <body>
  266. <div style=""margin: 0 0 20px 10px;"">
  267. <p style=""font-size: 20px;"">
  268. <span id=""tmdName"">{tmdName}</span>
  269. 老師您好,你於{year}第{Week}週({weekTime})上了{lessonCount}節HiTeach5課堂教學活動,以下是報告彙總資訊,點選其中一行可查看報告詳細內容
  270. </p>
  271. <div style=""margin-left: 10px;"">
  272. <table border=""1"" cellpadding=""10"" cellspacing=""0"" border=""1"" cellpadding=""10"" border=""1"" id=""acourseData"">
  273. <thead>
  274. <tr>
  275. <th>課程名稱</th>
  276. <th>學科</th>
  277. <th>學校/個人</th>
  278. <th>名單</th>
  279. <th>課堂數量</th>
  280. <th>詳細內容</th>
  281. </tr>
  282. </thead>
  283. <tbody>
  284. {tableData}
  285. </tbody>
  286. </table>
  287. </div>
  288. </div>
  289. </body>
  290. </html>";
  291. public static string weeklyReportEN = @"<!DOCTYPE html>
  292. <html>
  293. <head>
  294. <title>HiTeach Weekly Report</title>
  295. <meta charset=""UTF-8"">
  296. <style>
  297. </style>
  298. </head>
  299. <body>
  300. <div style=""margin: 0 0 20px 10px;"">
  301. <p style=""font-size: 20px;"">
  302. <span id=""tmdName"">{tmdName}</span>
  303. Hi, you have {lessonCount} HiTeach5 lesson activities in {Week} of {year} ({weekTime}). The following is the
  304. summary information. Click on one of the rows to view the report details.
  305. </p>
  306. <div style=""margin-left: 10px;"">
  307. <table border=""1"" cellpadding=""10"" cellspacing=""0"" border=""1"" cellpadding=""10"" border=""1"" id=""acourseData"">
  308. <thead>
  309. <tr>
  310. <th>Course name</th>
  311. <th>Subject</th>
  312. <th>School/Individual</th>
  313. <th>Name List</th>
  314. <th>Number of Lessons</th>
  315. <th>Details</th>
  316. </tr>
  317. </thead>
  318. <tbody>
  319. {tableData}
  320. </tbody>
  321. </table>
  322. </div>
  323. </div>
  324. </body>
  325. </html>";
  326. /// <summary>
  327. ///
  328. /// </summary>
  329. /// <param name="_azureRedis"></param>
  330. /// <param name="_azureCosmos"></param>
  331. /// <param name="coreAPIHttpService"></param>
  332. /// <param name="dingDing"></param>
  333. /// <param name="_httpClient"></param>
  334. /// <param name="_snowflakeId"></param>
  335. /// <param name="notifyUrl"></param>
  336. /// <param name="_mailFactory"></param>
  337. /// <param name="am"></param>
  338. /// <param name="pm"></param>
  339. /// <returns></returns>
  340. public static async Task<List<CodeValue> > AccumulateDaily(IConfiguration _configuration,AzureRedisFactory _azureRedis,AzureCosmosFactory _azureCosmos,AzureStorageFactory _azureStorage,
  341. CoreAPIHttpService coreAPIHttpService, DingDing dingDing,HttpClient _httpClient, SnowflakeId _snowflakeId,string notifyUrl, int am=0 ,int pm=0)
  342. {
  343. DateTimeOffset now = DateTimeOffset.Now;
  344. string day = now.ToString("yyyyMMdd");
  345. string homeworkYesterday = now.AddDays(-1).ToString("yyyyMMdd");
  346. HashSet<string> keys = new HashSet<string>();
  347. //当天评测发布的。
  348. //当天的个人评测提交数
  349. Dictionary<string, double?> exam_submit = new();
  350. SortedSetEntry[] exam_goingScores = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Accumulate:Daily:teacher:exam-going:{day}");
  351. // Dictionary<string, double?> exam_going = new();
  352. if (exam_goingScores != null)
  353. {
  354. foreach (var score in exam_goingScores)
  355. {
  356. double val = score.Score;
  357. string key = score.Element.ToString();
  358. // exam_going.Add(key, val);
  359. exam_submit.Add(key, val);
  360. keys.Add(key);
  361. }
  362. }
  363. ///需要再次获取 没有任何人提交的作业和评测任务。
  364. SortedSetEntry[] exam_submitScores = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Accumulate:Daily:private:exam-submit:{day}");
  365. if (exam_submitScores != null)
  366. {
  367. foreach (var score in exam_submitScores)
  368. {
  369. double val = score.Score;
  370. string key = score.Element.ToString();
  371. exam_submit.TryAdd(key, val);
  372. keys.Add(key);
  373. }
  374. }
  375. //今天发布的作业
  376. SortedSetEntry[] homework_goingScores_today = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Accumulate:Daily:teacher:homework-going:{day}");
  377. Dictionary<string, double?> homework_submit_today = new();
  378. //Dictionary<string, double?> homework_going = new();
  379. if (homework_goingScores_today != null)
  380. {
  381. foreach (var score in homework_goingScores_today)
  382. {
  383. double val = score.Score;
  384. string key = score.Element.ToString();
  385. //homework_going.Add(key, val);
  386. homework_submit_today.TryAdd(key, val);
  387. keys.Add(key);
  388. }
  389. }
  390. //昨天发布的作业
  391. SortedSetEntry[] homework_goingScores = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Accumulate:Daily:teacher:homework-going:{homeworkYesterday}");
  392. Dictionary<string, double?> homework_submit = new();
  393. //Dictionary<string, double?> homework_going = new();
  394. if (homework_goingScores != null)
  395. {
  396. foreach (var score in homework_goingScores)
  397. {
  398. double val = score.Score;
  399. string key = score.Element.ToString();
  400. //homework_going.Add(key, val);
  401. homework_submit.TryAdd(key, val);
  402. keys.Add(key);
  403. }
  404. }
  405. //昨天的个人作业提交数
  406. SortedSetEntry[] homework_submitScores = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Accumulate:Daily:teacher:homework-submit:{homeworkYesterday}");
  407. if (homework_submitScores != null)
  408. {
  409. foreach (var score in homework_submitScores)
  410. {
  411. double val = score.Score;
  412. string key = score.Element.ToString();
  413. homework_submit.TryAdd(key, val);
  414. keys.Add(key);
  415. }
  416. }
  417. //当天的个人名单加入人数
  418. Dictionary<string, double?> grouplist = new();
  419. SortedSetEntry[] grouplistScores = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Accumulate:Daily:teacher:grouplist:{day}");
  420. if (grouplistScores != null)
  421. {
  422. foreach (var score in grouplistScores)
  423. {
  424. double val = score.Score;
  425. string key = score.Element.ToString();
  426. grouplist.TryAdd(key, val);
  427. keys.Add(key);
  428. }
  429. }
  430. //当天教师的开课数量Accumulate:Daily:teacher:lesson-create:20240527
  431. Dictionary<string, double?> lessoncreate = new();
  432. SortedSetEntry[] llessoncreateScores = _azureRedis.GetRedisClient(8).SortedSetRangeByScoreWithScores($"Accumulate:Daily:teacher:lesson-create:{day}");
  433. if (llessoncreateScores != null)
  434. {
  435. foreach (var score in llessoncreateScores)
  436. {
  437. double val = score.Score;
  438. string key = score.Element.ToString();
  439. lessoncreate.TryAdd(key, val);
  440. keys.Add(key);
  441. }
  442. }
  443. List<string> ids = new List<string>();
  444. keys.ToList().ForEach(x => {
  445. ids.Add(x.Split("::")[0]);
  446. });
  447. List<CoreUser> coreUsers = new List<CoreUser>();
  448. List<Teacher> teachers= new List<Teacher>();
  449. if (ids.IsNotEmpty())
  450. {
  451. string sql = $"select value c from c where c.id in ({string.Join(",", ids.Select(x => $"'{x}'"))})";
  452. var result = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetList<Teacher>(sql, "Base");
  453. if (result.list.IsNotEmpty())
  454. {
  455. teachers.AddRange(result.list);
  456. }
  457. var content = new StringContent(ids.Distinct().ToJsonString(), Encoding.UTF8, "application/json");
  458. try
  459. {
  460. string json = await coreAPIHttpService.GetUserInfos(content);
  461. if (!string.IsNullOrWhiteSpace(json))
  462. {
  463. coreUsers = json.ToObject<List<CoreUser>>();
  464. }
  465. }
  466. catch (Exception ex)
  467. {
  468. await dingDing.SendBotMsg($"{coreAPIHttpService.options.location}用户转换失败:{coreAPIHttpService.options.coreUrl}", GroupNames.醍摩豆服務運維群組);
  469. }
  470. }
  471. List<CodeValue> notifys = new List<CodeValue>();
  472. foreach (var teacher in teachers)
  473. {
  474. //if (!(teacher.id.Equals("1535418750")))
  475. //{
  476. // continue;
  477. //}
  478. //if (!(teacher.id.Equals("1535418750")))
  479. //{
  480. // continue;
  481. //}
  482. StringBuilder notify = new StringBuilder();
  483. #if DEBUG
  484. int sendTime_pm = now.Hour;
  485. int sendTime_am = now.Hour;
  486. #else
  487. int sendTime_pm = 20;
  488. int sendTime_am =8;
  489. #endif
  490. if (am>0) {
  491. sendTime_am = am;
  492. }
  493. if (pm>0)
  494. {
  495. sendTime_pm = pm;
  496. }
  497. string lang = teacher.lang;
  498. var tzt = now.GetGMTTime((int)teacher.timezone);
  499. if (string.IsNullOrWhiteSpace(teacher.lang))
  500. {
  501. if (coreAPIHttpService.options.location.Contains("China", StringComparison.OrdinalIgnoreCase))
  502. {
  503. lang= "zh-cn";
  504. }
  505. if (coreAPIHttpService.options.location.Contains("Global",StringComparison.OrdinalIgnoreCase))
  506. {
  507. lang= "en-us";
  508. }
  509. }
  510. int examCount = 0,homeworkCount=0,lessonCount=0;
  511. StringBuilder examSB= new StringBuilder();
  512. foreach (var exam in exam_submit)
  513. {
  514. string[] ks = exam.Key.Split("::");
  515. string tid = ks[0];
  516. string examId = ks[1];
  517. string examName = ks[3];
  518. if (tid.Equals(teacher.id)) {
  519. if (tzt.Hour==sendTime_pm)
  520. {
  521. string sql = $"select c.status from c where c.examId='{examId}' and c.pk='ExamClassResult'";
  522. var result = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).GetList<ExamClassResult>(sql, $"ExamClassResult-{tid}");
  523. if (result.list.IsNotEmpty()) {
  524. var unsubmit = result.list.SelectMany(x => x.status).Where(x => x==1);
  525. var submit = result.list.SelectMany(x => x.status).Where(x => x==0);
  526. examCount++;
  527. switch (lang)
  528. {
  529. case "zh-cn":
  530. examSB.Append(cn_examList.Replace("{examName}", examName).Replace("{submitCount}", $"{submit.Count()}").Replace("{unsubmitCount}", $"{unsubmit.Count()}"));
  531. break;
  532. case "zh-tw":
  533. examSB.Append(tw_examList.Replace("{examName}", examName).Replace("{submitCount}", $"{submit.Count()}").Replace("{unsubmitCount}", $"{unsubmit.Count()}"));
  534. break;
  535. case "en-us":
  536. examSB.Append(en_examList.Replace("{examName}", examName).Replace("{submitCount}", $"{submit.Count()}").Replace("{unsubmitCount}", $"{unsubmit.Count()}"));
  537. break;
  538. }
  539. }
  540. }
  541. }
  542. }
  543. StringBuilder homeworkSB = new StringBuilder();
  544. foreach (var homeworksm in homework_submit_today)
  545. {
  546. string[] ks = homeworksm.Key.Split("::");
  547. string tid = ks[0];
  548. string homeworkId = ks[1];
  549. string homeworkName = ks[3];
  550. if (tid.Equals(teacher.id))
  551. {
  552. if (tzt.Hour==sendTime_pm)
  553. {
  554. homeworkCount++;
  555. }
  556. }
  557. }
  558. foreach (var homeworksm in homework_submit)
  559. {
  560. string[] ks = homeworksm.Key.Split("::");
  561. string tid = ks[0];
  562. string homeworkId = ks[1];
  563. string homeworkName = ks[3];
  564. if (tid.Equals(teacher.id))
  565. {
  566. if (tzt.Hour==sendTime_am)
  567. {
  568. var response = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Common).ReadItemStreamAsync(homeworkId, new PartitionKey($"Homework-{tid}"));
  569. if (response.StatusCode == System.Net.HttpStatusCode.OK) {
  570. Homework homework= JsonDocument.Parse(response.Content).RootElement.ToObject<Homework>();
  571. List<string > classes= new List<string>();
  572. classes.AddRange(homework.stuLists);
  573. classes.AddRange(homework.classes);
  574. List<HomeworkUser> homeworkUsers= await HomeworkService.AnswerRecordAll(_azureCosmos.GetCosmosClient(), coreAPIHttpService, dingDing, homework, tid, "Student", classes, "student");
  575. // homeworkCount++;
  576. switch (lang)
  577. {
  578. case "zh-cn":
  579. homeworkSB.Append(cn_homeworkList.Replace("{homeworkName}", homework.name).Replace("{submitCount}", $"{homeworkUsers.Where(x => x.submit).Count()}").Replace("{unsubmitCount}", $"{homeworkUsers.Where(x => !x.submit).Count()}"));
  580. break;
  581. case "zh-tw":
  582. homeworkSB.Append(tw_homeworkList.Replace("{homeworkName}", homework.name).Replace("{submitCount}", $"{homeworkUsers.Where(x => x.submit).Count()}").Replace("{unsubmitCount}", $"{homeworkUsers.Where(x => !x.submit).Count()}"));
  583. break;
  584. case "en-us":
  585. homeworkSB.Append(en_homeworkList.Replace("{homeworkName}", homework.name).Replace("{submitCount}", $"{homeworkUsers.Where(x => x.submit).Count()}").Replace("{unsubmitCount}", $"{homeworkUsers.Where(x => !x.submit).Count()}"));
  586. break;
  587. }
  588. }
  589. }
  590. }
  591. }
  592. StringBuilder lessonSB = new StringBuilder();
  593. StringBuilder lessonDetailSB = new StringBuilder();
  594. foreach (var lesson in lessoncreate)
  595. {
  596. string[] ks = lesson.Key.Split("::");
  597. string tid = ks[0];
  598. if (tid.Equals(teacher.id))
  599. {
  600. if (tzt.Hour==sendTime_pm)
  601. {
  602. long stime = now.AddHours(-20).ToUnixTimeMilliseconds();
  603. string sql = $"select value c from c where c.tmdid='{teacher.id}' and c.pk='LessonRecord' and c.startTime> {stime} ";
  604. List<LessonRecord>lessons = new List<LessonRecord>();
  605. var schoolResult= await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).GetList<LessonRecord>(sql);
  606. var teahcerResult = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetList<LessonRecord>(sql, "LessonRecord");
  607. lessons.AddRange(schoolResult.list);
  608. lessons.AddRange(teahcerResult.list);
  609. foreach (var lessonRecord in lessons)
  610. {
  611. LessonBase lessonBase = null;
  612. try
  613. {
  614. string owner = lessonRecord.scope.Equals("school") ? lessonRecord.school : lessonRecord.tmdid;
  615. BlobDownloadResult baseblobDownload = await _azureStorage.GetBlobContainerClient(owner).GetBlobClient($"/records/{lessonRecord.id}/IES/base.json").DownloadContentAsync();
  616. string basejson = baseblobDownload.Content.ToString().Replace("\"Uncall\"", "0").Replace("Uncall", "0");
  617. lessonBase = basejson.ToObject<LessonBase>();
  618. lessonCount++;
  619. var grpEngagement = string.Join(",", lessonBase.summary?.grpEngagement.Select((x, index) => $"G{index+1}({x})"));
  620. var highRankEngagement = string.Join(",", lessonBase.summary?.highRankEngagement?.Select((x, index) => $"{x}"));
  621. var highRankPerPoint = string.Join(",", lessonBase.summary?.highRankPerPoint?.Select((x, index) => $"{x}"));
  622. var highRankGrpPoint = string.Join(",", lessonBase.summary?.highRankGrpPoint?.Select((x, index) => $"{x}"));
  623. var highRankExam = string.Join(",", lessonBase.summary?.highRankExam?.Select((x, index) => $"{x}"));
  624. var lowRankExam = string.Join(",", lessonBase.summary?.lowRankExam?.Select((x, index) => $"{x}"));
  625. DateTimeOffset time = DateTimeOffset.FromUnixTimeMilliseconds(lessonRecord.startTime).GetGMTTime((int)teacher.timezone);
  626. switch (lang)
  627. {
  628. case "zh-cn":
  629. if (lessonBase!=null)
  630. {
  631. lessonDetailSB.Append(cn_lessonDetail.Replace("{name}", lessonRecord.name).Replace("{groupCount}",$"{lessonBase.group.Count()}").Replace("{time}",time.ToString("yyyy-MM-dd HH:mm:ss"))
  632. .Replace("{duration}", $"{Math.Round(lessonRecord.duration/60, 2)}").Replace("{count}", $"{lessonRecord.clientCount}").Replace("{attendCount}", $"{lessonRecord.attendCount}")
  633. .Replace("{absentCount}", $"{lessonRecord.clientCount-lessonRecord.attendCount}").Replace("{attendRate}", $"{lessonRecord.attendRate}").Replace("{engagementIndexAverge}", $"{lessonBase.summary?.engagementIndexAverge}")
  634. .Replace("{grpEngagement}", grpEngagement).Replace("{highRankEngagement}", highRankEngagement).Replace("{totalPoint}", $"{lessonBase.summary.totalPoint}").Replace("{highRankPerPoint}", highRankPerPoint)
  635. .Replace("{highRankGrpPoint}", highRankGrpPoint).Replace("{interactionCount}", $"{lessonBase.summary.interactionCount}").Replace("{totalInteractPoint}", $"{lessonBase.summary.totalInteractPoint}")
  636. .Replace("{pushCount}", $"{lessonBase.summary.pushCount}").Replace("{collateTaskCount}", $"{lessonBase.summary.collateTaskCount}").Replace("{examCount}", $"{lessonBase.summary.examCount}")
  637. .Replace("{examQuizCount}", $"{lessonBase.summary.examQuizCount}").Replace("{examPointRate}", $"{lessonBase.summary.examPointRate}").Replace("{highRankExam}", $"{highRankExam}")
  638. .Replace("{lowRankExam}", $"{lowRankExam}").Replace("{smartRatingCount}", $"{lessonBase.summary.smartRatingCount}").Replace("{clientSmartRatingCount}", $"{lessonBase.summary.clientSmartRatingCount}")
  639. .Replace("{coworkTaskCount}", $"{lessonBase.summary.coworkTaskCount}").Replace("{coworkGroupCount}", $"{lessonBase.summary.coworkGroupCount}").Replace("{coworkGroupCount}", $"{lessonBase.summary.coworkGroupCount}")
  640. .Replace("{avgcoworkGroupCount}", lessonRecord.attendCount>0 ? $"{lessonBase.summary.coworkGroupCount/lessonRecord.attendCount}" : "0"));
  641. }
  642. lessonSB.Append(cn_lessonList.Replace("{lessonName}", lessonRecord.name).Replace("{memberCount}", $"{lessonRecord.clientCount}").Replace("{attendCount}", $"{lessonRecord.attendCount}")).Replace("{attendRate}", $"{lessonRecord.attendRate}");
  643. break;
  644. case "zh-tw":
  645. if (lessonBase!=null)
  646. {
  647. lessonDetailSB.Append(tw_lessonDetail.Replace("{name}", lessonRecord.name).Replace("{groupCount}", $"{lessonBase.group.Count()}").Replace("{time}", time.ToString("yyyy-MM-dd HH:mm:ss"))
  648. .Replace("{duration}", $"{Math.Round(lessonRecord.duration/60, 2)}").Replace("{count}", $"{lessonRecord.clientCount}").Replace("{attendCount}", $"{lessonRecord.attendCount}")
  649. .Replace("{absentCount}", $"{lessonRecord.clientCount-lessonRecord.attendCount}").Replace("{attendRate}", $"{lessonRecord.attendRate}").Replace("{engagementIndexAverge}", $"{lessonBase.summary?.engagementIndexAverge}")
  650. .Replace("{grpEngagement}", grpEngagement).Replace("{highRankEngagement}", highRankEngagement).Replace("{totalPoint}", $"{lessonBase.summary.totalPoint}").Replace("{highRankPerPoint}", highRankPerPoint)
  651. .Replace("{highRankGrpPoint}", highRankGrpPoint).Replace("{interactionCount}", $"{lessonBase.summary.interactionCount}").Replace("{totalInteractPoint}", $"{lessonBase.summary.totalInteractPoint}")
  652. .Replace("{pushCount}", $"{lessonBase.summary.pushCount}").Replace("{collateTaskCount}", $"{lessonBase.summary.collateTaskCount}").Replace("{examCount}", $"{lessonBase.summary.examCount}")
  653. .Replace("{examQuizCount}", $"{lessonBase.summary.examQuizCount}").Replace("{examPointRate}", $"{lessonBase.summary.examPointRate}").Replace("{highRankExam}", $"{highRankExam}")
  654. .Replace("{lowRankExam}", $"{lowRankExam}").Replace("{smartRatingCount}", $"{lessonBase.summary.smartRatingCount}").Replace("{clientSmartRatingCount}", $"{lessonBase.summary.clientSmartRatingCount}")
  655. .Replace("{coworkTaskCount}", $"{lessonBase.summary.coworkTaskCount}").Replace("{coworkGroupCount}", $"{lessonBase.summary.coworkGroupCount}").Replace("{coworkGroupCount}", $"{lessonBase.summary.coworkGroupCount}")
  656. .Replace("{avgcoworkGroupCount}", lessonRecord.attendCount>0 ? $"{lessonBase.summary.coworkGroupCount/lessonRecord.attendCount}" : "0"));
  657. }
  658. lessonSB.Append(tw_lessonList.Replace("{lessonName}", lessonRecord.name).Replace("{memberCount}", $"{lessonRecord.clientCount}").Replace("{attendCount}", $"{lessonRecord.attendCount}")).Replace("{attendRate}", $"{lessonRecord.attendRate}");
  659. break;
  660. case "en-us":
  661. if (lessonBase!=null)
  662. {
  663. lessonDetailSB.Append(en_lessonDetail.Replace("{name}", lessonRecord.name).Replace("{groupCount}", $"{lessonBase.group.Count()}").Replace("{time}", time.ToString("yyyy-MM-dd HH:mm:ss"))
  664. .Replace("{duration}", $"{Math.Round(lessonRecord.duration/60, 2)}").Replace("{count}", $"{lessonRecord.clientCount}").Replace("{attendCount}", $"{lessonRecord.attendCount}")
  665. .Replace("{absentCount}", $"{lessonRecord.clientCount-lessonRecord.attendCount}").Replace("{attendRate}", $"{lessonRecord.attendRate}").Replace("{engagementIndexAverge}", $"{lessonBase.summary?.engagementIndexAverge}")
  666. .Replace("{grpEngagement}", grpEngagement).Replace("{highRankEngagement}", highRankEngagement).Replace("{totalPoint}", $"{lessonBase.summary.totalPoint}").Replace("{highRankPerPoint}", highRankPerPoint)
  667. .Replace("{highRankGrpPoint}", highRankGrpPoint).Replace("{interactionCount}", $"{lessonBase.summary.interactionCount}").Replace("{totalInteractPoint}", $"{lessonBase.summary.totalInteractPoint}")
  668. .Replace("{pushCount}", $"{lessonBase.summary.pushCount}").Replace("{collateTaskCount}", $"{lessonBase.summary.collateTaskCount}").Replace("{examCount}", $"{lessonBase.summary.examCount}")
  669. .Replace("{examQuizCount}", $"{lessonBase.summary.examQuizCount}").Replace("{examPointRate}", $"{lessonBase.summary.examPointRate}").Replace("{highRankExam}", $"{highRankExam}")
  670. .Replace("{lowRankExam}", $"{lowRankExam}").Replace("{smartRatingCount}", $"{lessonBase.summary.smartRatingCount}").Replace("{clientSmartRatingCount}", $"{lessonBase.summary.clientSmartRatingCount}")
  671. .Replace("{coworkTaskCount}", $"{lessonBase.summary.coworkTaskCount}").Replace("{coworkGroupCount}", $"{lessonBase.summary.coworkGroupCount}").Replace("{coworkGroupCount}", $"{lessonBase.summary.coworkGroupCount}")
  672. .Replace("{avgcoworkGroupCount}", lessonRecord.attendCount>0 ? $"{lessonBase.summary.coworkGroupCount/lessonRecord.attendCount}" : "0"));
  673. }
  674. lessonSB.Append(en_lessonList.Replace("{lessonName}", lessonRecord.name).Replace("{memberCount}", $"{lessonRecord.clientCount}").Replace("{attendCount}", $"{lessonRecord.attendCount}")).Replace("{attendRate}", $"{lessonRecord.attendRate}");
  675. break;
  676. }
  677. }
  678. catch (Exception ex)
  679. {
  680. }
  681. }
  682. }
  683. }
  684. }
  685. StringBuilder grouplistSB = new StringBuilder();
  686. List<string> grouplistIds=new List<string>();
  687. foreach (var group in grouplist)
  688. {
  689. string[] ks = group.Key.Split("::");
  690. grouplistIds.Add(ks[1]);
  691. }
  692. List<GroupListDto> groupListDtos= await GroupListService.GetGroupListByListids(_azureCosmos.GetCosmosClient(), dingDing, grouplistIds, null);
  693. foreach (var group in grouplist)
  694. {
  695. string[] ks = group.Key.Split("::");
  696. string tid = ks[0];
  697. string grouplistId = ks[1];
  698. string grouplistName = ks[3];
  699. var gpdto= groupListDtos.Find(x => x.id.Equals(grouplistId));
  700. if (gpdto!= null)
  701. {
  702. if (tid.Equals(teacher.id))
  703. {
  704. if (tzt.Hour==sendTime_pm)
  705. {
  706. switch (lang)
  707. {
  708. case "zh-cn":
  709. if (group.Value>=0)
  710. {
  711. grouplistSB.Append(cn_groupListJoin.Replace("{grouplistName}", grouplistName).Replace("{memberCount}", $"{gpdto.tcount+gpdto.scount}").Replace("{joinCount}", $"{group.Value}"));
  712. }
  713. else
  714. {
  715. grouplistSB.Append(cn_groupListLeave.Replace("{grouplistName}", grouplistName).Replace("{memberCount}", $"{gpdto.tcount+gpdto.scount}").Replace("{joinCount}", $"{group.Value}"));
  716. }
  717. break;
  718. case "zh-tw":
  719. if (group.Value>=0)
  720. {
  721. grouplistSB.Append(tw_groupListJoin.Replace("{grouplistName}", grouplistName).Replace("{memberCount}", $"{gpdto.tcount+gpdto.scount}").Replace("{joinCount}", $"{group.Value}"));
  722. }
  723. else
  724. {
  725. grouplistSB.Append(tw_groupListLeave.Replace("{grouplistName}", grouplistName).Replace("{memberCount}", $"{gpdto.tcount+gpdto.scount}").Replace("{joinCount}", $"{group.Value}"));
  726. }
  727. break;
  728. case "en-us":
  729. if (group.Value>=0)
  730. {
  731. grouplistSB.Append(en_groupListJoin.Replace("{grouplistName}", grouplistName).Replace("{memberCount}", $"{gpdto.tcount+gpdto.scount}").Replace("{joinCount}", $"{group.Value}"));
  732. }
  733. else
  734. {
  735. grouplistSB.Append(en_groupListLeave.Replace("{grouplistName}", grouplistName).Replace("{memberCount}", $"{gpdto.tcount+gpdto.scount}").Replace("{joinCount}", $"{group.Value}"));
  736. }
  737. break;
  738. }
  739. }
  740. }
  741. }
  742. }
  743. // await dingDing.SendBotMsg($"{teacher.name},{homework_submit_today.ToJsonString()},pm:{pm},am:{am},tztH:{tzt.Hour},sendPm:{sendTime_pm},sendAm:{sendTime_am},examCount:{examCount},lessonCount:{lessonCount},homeworkCount:{homeworkCount}", GroupNames.成都开发測試群組);
  744. if (tzt.Hour==sendTime_pm && (!string.IsNullOrWhiteSpace(lessonDetailSB.ToString()) || examCount>0 || lessonCount>0 || homeworkCount>0 || (grouplist.Count>0 && !string.IsNullOrWhiteSpace(grouplistSB.ToString()))))
  745. {
  746. string template=string.Empty;
  747. string title=string.Empty;
  748. switch (lang)
  749. {
  750. case "zh-cn":
  751. title="IES晚间报告";
  752. template=cn_wb.Replace("{tmdname}", teacher.name).Replace("{sendTime}", $"{now.ToString("yyyy-MM-dd")} {sendTime_pm}")
  753. .Replace("{examCount}", $"{examCount}").Replace("{homeworkCount}", $"{homeworkCount}").Replace("{lessonCount}", $"{lessonCount}")
  754. .Replace("{cn_examList}", examSB.ToString()).Replace("{cn_lessonList}", lessonSB.ToString()).Replace("{cn_groupList}", grouplistSB.ToString());
  755. if (examCount>0)
  756. {
  757. template= template.Replace("{cn_examTitle}", cn_examTitle);
  758. }
  759. else {
  760. template= template.Replace("{cn_examTitle}", "");
  761. }
  762. if (homeworkCount>0)
  763. {
  764. template= template.Replace("{cn_homeworkTitle}", cn_homeworkTitle);
  765. }
  766. else
  767. {
  768. template= template.Replace("{cn_homeworkTitle}", "");
  769. }
  770. if (lessonCount>0)
  771. {
  772. template= template.Replace("{cn_lessonTitle}", cn_lessonTitle);
  773. }
  774. else
  775. {
  776. template= template.Replace("{cn_lessonTitle}", "");
  777. }
  778. if (grouplist.Count>0 && !string.IsNullOrWhiteSpace(grouplistSB.ToString()))
  779. {
  780. template=template.Replace("{cn_groupTitle}", cn_groupTitle);
  781. }
  782. else
  783. {
  784. template= template.Replace("{cn_groupTitle}", "");
  785. }
  786. break;
  787. case "zh-tw":
  788. title="IES晚間報告";
  789. template=tw_wb.Replace("{tmdname}", teacher.name).Replace("{sendTime}", $"{now.ToString("yyyy-MM-dd")} {sendTime_pm}")
  790. .Replace("{examCount}", $"{examCount}").Replace("{homeworkCount}", $"{homeworkCount}").Replace("{lessonCount}", $"{lessonCount}")
  791. .Replace("{tw_examList}", examSB.ToString()).Replace("{tw_lessonList}", lessonSB.ToString()).Replace("{tw_groupList}", grouplistSB.ToString());
  792. if (examCount>0)
  793. {
  794. template= template.Replace("{tw_examTitle}", tw_examTitle);
  795. }
  796. else
  797. {
  798. template= template.Replace("{tw_examTitle}", "");
  799. }
  800. if (homeworkCount>0)
  801. {
  802. template= template.Replace("{tw_homeworkTitle}", tw_homeworkTitle);
  803. }
  804. else
  805. {
  806. template= template.Replace("{tw_homeworkTitle}", "");
  807. }
  808. if (lessonCount>0)
  809. {
  810. template= template.Replace("{tw_lessonTitle}", tw_lessonTitle);
  811. }
  812. else
  813. {
  814. template= template.Replace("{tw_lessonTitle}", "");
  815. }
  816. if (grouplist.Count>0)
  817. {
  818. template=template.Replace("{tw_groupTitle}", tw_groupTitle);
  819. }
  820. else
  821. {
  822. template= template.Replace("{tw_groupTitle}", "");
  823. }
  824. break;
  825. case "en-us":
  826. title ="IES Evening Report";
  827. template=en_wb.Replace("{tmdname}", teacher.name).Replace("{sendTime}", $"{now.ToString("yyyy-MM-dd")} {sendTime_pm}")
  828. .Replace("{examCount}", $"{examCount}").Replace("{homeworkCount}", $"{homeworkCount}").Replace("{lessonCount}", $"{lessonCount}")
  829. .Replace("{en_examList}", examSB.ToString()).Replace("{en_lessonList}", lessonSB.ToString()).Replace("{en_groupList}", grouplistSB.ToString());
  830. if (examCount>0)
  831. {
  832. template= template.Replace("{en_examTitle}", en_examTitle);
  833. }
  834. else
  835. {
  836. template= template.Replace("{en_examTitle}", "");
  837. }
  838. if (homeworkCount>0)
  839. {
  840. template= template.Replace("{en_homeworkTitle}", en_homeworkTitle);
  841. }
  842. else
  843. {
  844. template= template.Replace("{en_homeworkTitle}", "");
  845. }
  846. if (lessonCount>0)
  847. {
  848. template= template.Replace("{en_lessonTitle}", en_lessonTitle);
  849. }
  850. else
  851. {
  852. template= template.Replace("{en_lessonTitle}", "");
  853. }
  854. if (grouplist.Count>0)
  855. {
  856. template=template.Replace("{en_groupTitle}", en_groupTitle);
  857. }
  858. else
  859. {
  860. template= template.Replace("{en_groupTitle}", "");
  861. }
  862. break;
  863. }
  864. template= template.Replace("\r\n", "");
  865. string eventId = $"Evening_Report-{_snowflakeId.NextId()}";
  866. NotifyData notifyData = new NotifyData
  867. {
  868. hubName = "hita5",
  869. sender = "IES",
  870. tags = new List<string>() { $"{teacher.id}_{Constant.NotifyType_IES5_Course}" },
  871. title = title,
  872. eventId =eventId,
  873. eventName =title,
  874. data = "{\"value\":{}}",
  875. body=template,
  876. };
  877. HttpResponseMessage responseMessage = await _httpClient.PostAsJsonAsync($"{notifyUrl}/service/PushNotify", notifyData);
  878. var coreUser = coreUsers.Find(x => x.id.Equals(teacher.id) && !string.IsNullOrWhiteSpace(x.mail));
  879. if (coreUser!=null)
  880. {
  881. // var token = _mailFactory.GetSmtpClient().SendEmail(_azureCosmos, dingDing, eventId, title, template, coreUser.mail, teacher.id, teacher.name, sender: "TEAMModel");
  882. //var tid = lang.Equals("zh-cn") ? "d-136eddbd974046f1a721c8f4e210b9bf" : lang.Equals("zh-tw") ? "d-136eddbd974046f1a721c8f4e210b9bf" : "d-95ac2d657d1b4d9dbb7b79defc17f714";
  883. var tid = string.Empty;
  884. if (coreAPIHttpService.options.location.Contains("China"))
  885. {
  886. tid=lang.Equals("zh-cn") ? "IES5GeneralTemplateSC" : lang.Equals("zh-tw") ? "IES5GeneralTemplateTC" : "IES5GeneralTemplateEN";
  887. }
  888. else
  889. {
  890. tid=lang.Equals("zh-cn") ? "d-270b4ec690f541a9a4045d7a4032bc3b" : lang.Equals("zh-tw") ? "d-136eddbd974046f1a721c8f4e210b9bf" : "d-95ac2d657d1b4d9dbb7b79defc17f714";
  891. }
  892. await coreAPIHttpService.SendMail(new Dictionary<string, object> { { "to", coreUser.mail }, { "tid", tid }, { "vars", new { title = title, notificationcontent = $"{template}</br>{lessonDetailSB.ToString()}" } } }, coreAPIHttpService.options.location, _configuration);
  893. }
  894. notify.Append(template);
  895. }
  896. if (tzt.Hour==sendTime_am && !string.IsNullOrWhiteSpace(homeworkSB.ToString()))
  897. {
  898. string template = string.Empty;
  899. string title = string.Empty;
  900. switch (lang)
  901. {
  902. case "zh-cn":
  903. title ="IES早间报告";
  904. template= cn_zb.Replace("{tmdname}", teacher.name).Replace("{sendTime}", $"{now.ToString("yyyy-MM-dd")} {sendTime_am}")
  905. .Replace("{cn_homeworkList}", homeworkSB.ToString());
  906. template=template.Replace("{cn_homeworkTitle}", cn_homeworkTitle);
  907. break;
  908. case "zh-tw":
  909. title ="IES晨間報告";
  910. template= tw_zb.Replace("{tmdname}", teacher.name).Replace("{sendTime}", $"{now.ToString("yyyy-MM-dd")} {sendTime_am}")
  911. .Replace("{tw_homeworkList}", homeworkSB.ToString());
  912. template=template.Replace("{tw_homeworkTitle}", tw_homeworkTitle);
  913. break;
  914. case "en-us":
  915. title ="IES Morning Report";
  916. template=en_zb.Replace("{tmdname}", teacher.name).Replace("{sendTime}", $"{now.ToString("yyyy-MM-dd")} {sendTime_am}")
  917. .Replace("{en_homeworkList}", homeworkSB.ToString());
  918. template=template.Replace("{en_homeworkTitle}", en_homeworkTitle);
  919. break;
  920. }
  921. template= template.Replace("\r\n", "");
  922. string eventId = $"Morning_Report-{_snowflakeId.NextId()}";
  923. NotifyData notifyData = new NotifyData
  924. {
  925. hubName = "hita5",
  926. sender = "IES",
  927. tags = new List<string>() { $"{teacher.id}_{Constant.NotifyType_IES5_Course}" },
  928. title = title,
  929. eventId = eventId,
  930. eventName =title,
  931. data = "{\"value\":{}}",
  932. body=template,
  933. };
  934. HttpResponseMessage responseMessage = await _httpClient.PostAsJsonAsync($"{notifyUrl}/service/PushNotify", notifyData);
  935. var coreUser = coreUsers.Find(x => x.id.Equals(teacher.id) && !string.IsNullOrWhiteSpace(x.mail));
  936. if (coreUser!=null)
  937. {
  938. // var token = _mailFactory.GetSmtpClient().SendEmail(_azureCosmos, dingDing, eventId, title, template, coreUser.mail, teacher.id, teacher.name,sender:"TEAMModel");
  939. var tid = string.Empty ;
  940. if (coreAPIHttpService.options.location.Contains("China"))
  941. {
  942. tid=lang.Equals("zh-cn") ? "IES5GeneralTemplateSC" : lang.Equals("zh-tw") ? "IES5GeneralTemplateTC" : "IES5GeneralTemplateEN";
  943. }
  944. else {
  945. tid=lang.Equals("zh-cn")? "d-270b4ec690f541a9a4045d7a4032bc3b" : lang.Equals("zh-tw") ? "d-136eddbd974046f1a721c8f4e210b9bf" : "d-95ac2d657d1b4d9dbb7b79defc17f714";
  946. }
  947. await coreAPIHttpService.SendMail(new Dictionary<string, object> { { "to", coreUser.mail }, { "tid", tid }, { "vars", new { title = title, notificationcontent = template } } }, coreAPIHttpService.options.location, _configuration);
  948. }
  949. notify.Append(template);
  950. }
  951. notifys.Add(new CodeValue { code=teacher.id, value= notify.ToString() });
  952. }
  953. return notifys;
  954. }
  955. public static async Task RecordAccumulateData(AzureRedisFactory azureRedis, DingDing dingDing, Accumulate accumulate)
  956. {
  957. if (!string.IsNullOrWhiteSpace(accumulate.key) && !string.IsNullOrWhiteSpace(accumulate.target) &&
  958. !string.IsNullOrWhiteSpace(accumulate.id) && !string.IsNullOrWhiteSpace(accumulate.name) &&
  959. !string.IsNullOrWhiteSpace(accumulate.scope) && !string.IsNullOrWhiteSpace(accumulate.client))
  960. {
  961. await RecordAccumulateData(azureRedis, accumulate.key, accumulate.target, accumulate.id, accumulate.name, accumulate.scope, accumulate.client, accumulate.count);
  962. }
  963. else
  964. {
  965. await dingDing.SendBotMsg($"IES累计数据变更统计参数异常,{accumulate.ToJsonString()}", GroupNames.成都开发測試群組);
  966. }
  967. }
  968. public static async Task LessonWeekly( AzureRedisFactory _azureRedis, AzureCosmosFactory _azureCosmos, CoreAPIHttpService _coreAPIHttpService, DingDing _dingDing, IConfiguration _configuration)
  969. {
  970. var now = DateTimeOffset.Now;
  971. var nownf = DateTime.Now;
  972. // 使用当前文化设置的日历
  973. CultureInfo cultureInfo = CultureInfo.CurrentCulture;
  974. Calendar calendar = cultureInfo.Calendar;
  975. //表示如果一年的第一个星期至少有4天在同一年,则该星期被视为第一周,DayOfWeek.Monday和DayOfWeek.Sunday分别表示一周的第一天是星期一或星期日。
  976. var week = calendar.GetWeekOfYear(nownf, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
  977. string schoolKey = $"LessonWeekly:school:{now.Year}-{week}";
  978. string privateKey = $"LessonWeekly:private:{now.Year}-{week}";
  979. int currentDayOfWeek = (int)now.DayOfWeek;
  980. // 计算周一的日期
  981. DateTimeOffset startOfWeek = now.AddDays(1 - currentDayOfWeek);
  982. // 计算周日的日期
  983. DateTimeOffset endOfWeek = now.AddDays(7 - currentDayOfWeek);
  984. // 获取当前年份
  985. int currentYear = now.Year;
  986. // 获取当前年份的第一天
  987. DateTimeOffset firstDayOfYear = new DateTimeOffset(currentYear, 1, 1, 0, 0, 0,new TimeSpan(8,0,0));
  988. // 获取当前年份的最后一天
  989. DateTimeOffset lastDayOfYear = new DateTimeOffset(currentYear, 12, 31, 23, 59, 59, new TimeSpan(8, 0, 0));
  990. var schoolValues = await _azureRedis.GetRedisClient(8).HashGetAllAsync(schoolKey);
  991. var privateValues = await _azureRedis.GetRedisClient(8).HashGetAllAsync(privateKey);
  992. List<KeyValuePair<string, List<LessonWeek>>> datas = new List<KeyValuePair<string, List<LessonWeek>>>();
  993. HashSet<string> schoolId = new HashSet<string>();
  994. if (schoolValues!=default && schoolValues.Length>0)
  995. {
  996. foreach (var value in schoolValues)
  997. {
  998. var tmdid = value.Name.ToString().Split(":")[0];
  999. LessonWeek data = value.Value.ToString().ToObject<LessonWeek>();
  1000. if (!string.IsNullOrWhiteSpace(data.school))
  1001. {
  1002. schoolId.Add(data.school);
  1003. }
  1004. var tmdData = datas.Find(x => x.Key.Equals(tmdid));
  1005. if (tmdData.Key==null)
  1006. {
  1007. tmdData= new KeyValuePair<string, List<LessonWeek>>(tmdid, new List<LessonWeek> { data });
  1008. datas.Add(tmdData);
  1009. }
  1010. else
  1011. {
  1012. tmdData.Value.Add(data);
  1013. }
  1014. }
  1015. }
  1016. if (privateValues!=default && privateValues.Length>0)
  1017. {
  1018. foreach (var value in privateValues)
  1019. {
  1020. var tmdid = value.Name.ToString().Split(":")[0];
  1021. LessonWeek data = value.Value.ToString().ToObject<LessonWeek>();
  1022. var tmdData = datas.Find(x => x.Key.Equals(tmdid));
  1023. if (tmdData.Key==null)
  1024. {
  1025. tmdData= new KeyValuePair<string, List<LessonWeek>>(tmdid, new List<LessonWeek> { data });
  1026. datas.Add(tmdData);
  1027. }
  1028. else
  1029. {
  1030. tmdData.Value.Add(data);
  1031. }
  1032. }
  1033. }
  1034. if (datas.IsNotEmpty())
  1035. {
  1036. List<CoreUser> coreUsers= new List<CoreUser>();
  1037. List<Teacher> teachers = new List<Teacher>();
  1038. string sql = $"select value c from c where c.id in ({string.Join(",", datas.Select(x => $"'{x.Key}'"))})";
  1039. var result = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetList<Teacher>(sql, "Base");
  1040. if (result.list.IsNotEmpty())
  1041. {
  1042. teachers.AddRange(result.list);
  1043. }
  1044. var str = teachers.Select(x => $"{x.id}").ToJsonString();
  1045. var content = new StringContent(str, Encoding.UTF8, "application/json");
  1046. try
  1047. {
  1048. string json = await _coreAPIHttpService.GetUserInfos(content);
  1049. if (!string.IsNullOrWhiteSpace(json))
  1050. {
  1051. coreUsers = json.ToObject<List<CoreUser>>();
  1052. }
  1053. }
  1054. catch (Exception ex)
  1055. {
  1056. await _dingDing.SendBotMsg($"{_coreAPIHttpService.options.location}邮件用户转换失败:{_coreAPIHttpService.options.coreUrl}", GroupNames.醍摩豆服務運維群組);
  1057. }
  1058. List<School> schools = new List<School>();
  1059. if (schoolId.IsNotEmpty())
  1060. {
  1061. var schoolIds= datas.SelectMany(x => x.Value).Where(x => !string.IsNullOrWhiteSpace(x.school)).Select(x => x.school).Distinct();
  1062. string schsql = $"select value c from c where c.id in ({string.Join(",", schoolIds.Select(x => $"'{x}'"))})";
  1063. var schresult = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).GetList<School>(schsql, "Base");
  1064. if (schresult.list.IsNotEmpty())
  1065. {
  1066. schools.AddRange(schresult.list);
  1067. }
  1068. }
  1069. //个人和学校名单
  1070. List<GroupListDto> groupLists = new List<GroupListDto>();
  1071. //个人和学校课程
  1072. List<CourseBase> courseBases = new List<CourseBase>();
  1073. foreach (var data in datas)
  1074. {
  1075. var teacher = teachers.Find(x => x.id.Equals(data.Key));
  1076. if (teacher!=null)
  1077. {
  1078. var coreUser = coreUsers.Find(x => x.id.Equals(teacher.id) && !string.IsNullOrWhiteSpace(x.mail));
  1079. if (coreUser!=null)
  1080. {
  1081. if (!teacher.id.Equals("1535418750"))
  1082. {
  1083. continue;
  1084. }
  1085. string lang = teacher.lang;
  1086. var tzt = now.GetGMTTime((int)teacher.timezone);
  1087. if (string.IsNullOrWhiteSpace(teacher.lang))
  1088. {
  1089. if (_coreAPIHttpService.options.location.Contains("China", StringComparison.OrdinalIgnoreCase))
  1090. {
  1091. lang= "zh-cn";
  1092. }
  1093. if (_coreAPIHttpService.options.location.Contains("Global", StringComparison.OrdinalIgnoreCase))
  1094. {
  1095. lang= "en-us";
  1096. }
  1097. }
  1098. List<LessonRecord> lessonRecords = new List<LessonRecord>();
  1099. #region
  1100. //课例
  1101. //{
  1102. // var pid = data.Value.FindAll(x => !string.IsNullOrWhiteSpace(x.scope) && x.scope.Equals("private")).Select(x => x.id);
  1103. // var sid = data.Value.FindAll(x => !string.IsNullOrWhiteSpace(x.scope) && x.scope.Equals("school"))
  1104. // .Select(x => new CodeValue { code=x.school, value=x.id }).GroupBy(x => x.code).Select(x => new { key = x.Key, list = x.ToList() });
  1105. // if (pid!=null && pid.Count()>0)
  1106. // {
  1107. // var pg = pid.ExceptBy(groupLists.Select(x => x.id), y => y);
  1108. // if (pg!=null && pg.Count()>0)
  1109. // {
  1110. // string csql = $"select value c from c where c.id in ({string.Join(",", pg.Select(x => $"'{x}'"))})";
  1111. // var lresult = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetList<LessonRecord>(csql, "LessonRecord");
  1112. // if (lresult.list.IsNotEmpty())
  1113. // {
  1114. // lessonRecords.AddRange(lresult.list);
  1115. // }
  1116. // }
  1117. // }
  1118. // if (sid!=null && sid.Count()>0)
  1119. // {
  1120. // foreach (var item in sid)
  1121. // {
  1122. // var sg = item.list.Select(x => x.value).ToList().ExceptBy(groupLists.Where(x => x.school.Equals(item.key)).Select(x => x.id), y => y);
  1123. // if (sg!=null && sg.Count()>0)
  1124. // {
  1125. // string csql = $"select value c from c where c.id in ({string.Join(",", sg.Select(x => $"'{x}'"))})";
  1126. // var lresult = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetList<LessonRecord>(csql, $"LessonRecord-{item.key}");
  1127. // if (lresult.list.IsNotEmpty())
  1128. // {
  1129. // lessonRecords.AddRange(lresult.list);
  1130. // }
  1131. // }
  1132. // }
  1133. // }
  1134. //}
  1135. //名单
  1136. {
  1137. var pgid = data.Value.FindAll(x => !string.IsNullOrWhiteSpace(x.scope) && x.scope.Equals("private")).Select(x => x.gid);
  1138. var sgid = data.Value.FindAll(x => !string.IsNullOrWhiteSpace(x.scope) && x.scope.Equals("school"))
  1139. .Select(x => new CodeValue { code=x.school, value=x.gid }).GroupBy(x => x.code).Select(x => new { key = x.Key, list = x.ToList() });
  1140. if (pgid!=null && pgid.Count()>0)
  1141. {
  1142. var pg = pgid.ExceptBy(groupLists.Select(x => x.id), y => y);
  1143. if (pg!=null && pg.Count()>0)
  1144. {
  1145. var grouplist = await GroupListService.GetGroupListByListids(_azureCosmos.GetCosmosClient(), _dingDing, pg.ToList(), null);
  1146. if (grouplist.IsNotEmpty())
  1147. {
  1148. groupLists.AddRange(grouplist);
  1149. }
  1150. }
  1151. }
  1152. if (sgid!=null && sgid.Count()>0)
  1153. {
  1154. foreach (var item in sgid)
  1155. {
  1156. var sg = item.list.Select(x => x.value).ToList().ExceptBy(groupLists.Where(x => x.school.Equals(item.key)).Select(x => x.id), y => y);
  1157. if (sg!=null && sg.Count()>0)
  1158. {
  1159. var grouplist = await GroupListService.GetGroupListByListids(_azureCosmos.GetCosmosClient(), _dingDing, sg.ToList(), item.key);
  1160. if (grouplist.IsNotEmpty())
  1161. {
  1162. groupLists.AddRange(grouplist);
  1163. }
  1164. }
  1165. }
  1166. }
  1167. }
  1168. //课程
  1169. {
  1170. var pcid = data.Value.FindAll(x => !string.IsNullOrWhiteSpace(x.scope) && x.scope.Equals("private") && !string.IsNullOrWhiteSpace(x.cid)).Select(x => x.cid);
  1171. var scid = data.Value.FindAll(x => !string.IsNullOrWhiteSpace(x.scope) && x.scope.Equals("school") && !string.IsNullOrWhiteSpace(x.cid))
  1172. .Select(x => new CodeValue { code=x.school, value=x.cid }).GroupBy(x => x.code).Select(x => new { key = x.Key, list = x.ToList() });
  1173. if (pcid!=null && pcid.Count()>0)
  1174. {
  1175. var pg = pcid.ExceptBy(courseBases.Select(x => x.id), y => y);
  1176. if (pg!=null && pg.Count()>0)
  1177. {
  1178. string csql = $"select value c from c where c.id in ({string.Join(",", pg.Select(x => $"'{x}'"))})";
  1179. var cresult = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetList<CourseBase>(csql, "CourseBase");
  1180. if (cresult.list.IsNotEmpty())
  1181. {
  1182. courseBases.AddRange(cresult.list);
  1183. }
  1184. }
  1185. }
  1186. if (scid!=null && scid.Count()>0)
  1187. {
  1188. foreach (var item in scid)
  1189. {
  1190. var sg = item.list.Select(x => x.value).ToList().ExceptBy(courseBases.Where(x => x.school.Equals(item.key)).Select(x => x.id), y => y);
  1191. if (sg!=null && sg.Count()>0)
  1192. {
  1193. string csql = $"select value c from c where c.id in ({string.Join(",", sg.Select(x => $"'{x}'"))})";
  1194. var cresult = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).GetList<CourseBase>(csql, $"CourseBase-{item.key}");
  1195. if (cresult.list.IsNotEmpty())
  1196. {
  1197. courseBases.AddRange(cresult.list);
  1198. }
  1199. }
  1200. }
  1201. }
  1202. }
  1203. #endregion
  1204. StringBuilder sb = new StringBuilder();
  1205. var sdata = data.Value.Where(x => x.scope.Equals("school")).GroupBy(x => $"{x.scope}:{x.cid}:{x.gid}:{x.school}:{x.sid}").Select(x => new { key = x.Key, list = x.ToList() });
  1206. var pdata = data.Value.Where(x => x.scope.Equals("private")).GroupBy(x => $"{x.scope}:{x.cid}:{x.gid}:").Select(x => new { key = x.Key, list = x.ToList() }); ;
  1207. foreach (var s in sdata)
  1208. {
  1209. Dictionary<string, string> @params = new();
  1210. string[] ids = s.key.Split(":");
  1211. var course = courseBases.Find(x => x.id.Equals(ids[1]));
  1212. var group = groupLists.Find(x => x.id.Equals(ids[2]));
  1213. School school = null;
  1214. Subject subject = null;
  1215. Period period = null;
  1216. long stime = 0;
  1217. long etime = 0;
  1218. school = schools.Find(x => x.id.Equals(ids[3]));
  1219. if (school !=null)
  1220. {
  1221. period=school.period.FirstOrDefault();
  1222. subject = school.period.SelectMany(x => x.subjects).Where(x => x.id.Equals(ids[4])).FirstOrDefault();
  1223. var semester = SchoolService.GetSemester(period, DateTimeOffset.Now.ToUnixTimeMilliseconds());
  1224. stime = semester.currSemesterDate.ToUnixTimeMilliseconds();
  1225. etime = semester.nextSemester.ToUnixTimeMilliseconds();
  1226. }
  1227. if (stime==0)
  1228. {
  1229. stime= firstDayOfYear.ToUnixTimeMilliseconds();
  1230. }
  1231. if (etime==0)
  1232. {
  1233. etime= lastDayOfYear.ToUnixTimeMilliseconds();
  1234. }
  1235. @params.Add("tmdId", teacher.id);
  1236. @params.Add("school", school.id);
  1237. @params.Add("scope", "school");
  1238. @params.Add("courseId", course.id);
  1239. @params.Add("groupIds", group.id);
  1240. @params.Add("astime", $"{stime}");
  1241. @params.Add("aetime", $"{etime}");
  1242. @params.Add("stime", $"{startOfWeek.ToUnixTimeMilliseconds()}");
  1243. @params.Add("etime", $"{endOfWeek.ToUnixTimeMilliseconds()}");
  1244. @params.Add("srvAdr", _coreAPIHttpService.options.location);
  1245. string page = lang.Equals("zh-cn") ? "reprotCN.html" : lang.Equals("zh-tw") ? "reprotTW.html" : "reprotUS.html";
  1246. string opt = lang.Equals("zh-cn") ? "查看" : lang.Equals("zh-tw") ? "檢視" : "View";
  1247. var host = _coreAPIHttpService.options.location.Contains("China", StringComparison.OrdinalIgnoreCase) ? "https://www.teammodel.cn" : "https://www.teammodel.net";
  1248. string paramStr = string.Join("&", @params.Select(x => $"{x.Key}={x.Value}"));
  1249. string url = $"{host}/{page}?{paramStr}";
  1250. sb.Append($"<tr><td>{course.name}</td><td>{subject.name}</td><td>{school.name}</td><td>{group.name}</td><td>{s.list.Count()}</td><td><a href='{url}'>{opt}</td>");
  1251. }
  1252. foreach (var s in pdata)
  1253. {
  1254. Dictionary<string, string> @params = new();
  1255. string[] ids = s.key.Split(":");
  1256. var course = courseBases.Find(x => x.id.Equals(ids[1]));
  1257. var group = groupLists.Find(x => x.id.Equals(ids[2]));
  1258. long stime = firstDayOfYear.ToUnixTimeMilliseconds();
  1259. long etime = lastDayOfYear.ToUnixTimeMilliseconds();
  1260. @params.Add("tmdId", teacher.id);
  1261. @params.Add("school", "");
  1262. @params.Add("scope", "school");
  1263. @params.Add("courseId", course.id);
  1264. @params.Add("groupIds", group.id);
  1265. @params.Add("astime", $"{stime}");
  1266. @params.Add("aetime", $"{etime}");
  1267. @params.Add("stime", $"{startOfWeek.ToUnixTimeMilliseconds()}");
  1268. @params.Add("etime", $"{endOfWeek.ToUnixTimeMilliseconds()}");
  1269. @params.Add("srvAdr", _coreAPIHttpService.options.location);
  1270. string page = lang.Equals("zh-cn") ? "reprotCN.html" : lang.Equals("zh-tw") ? "reprotTW.html" : "reprotUS.html";
  1271. string opt = lang.Equals("zh-cn") ? "查看" : lang.Equals("zh-tw") ? "檢視" : "View";
  1272. string scopeStr = lang.Equals("zh-cn") ? "个人课程" : lang.Equals("zh-tw") ? "個人課程" : "Personal Course";
  1273. var host = _coreAPIHttpService.options.location.Contains("China", StringComparison.OrdinalIgnoreCase) ? "https://www.teammodel.cn" : "https://www.teammodel.net";
  1274. string paramStr = string.Join("&", @params.Select(x => $"{x.Key}={x.Value}"));
  1275. string url = $"{host}/{page}?{paramStr}";
  1276. sb.Append($"<tr><td>{course.name}</td><td>--</td><td>{scopeStr}</td><td>{group.name}</td><td>{s.list.Count()}</td><td><a href='{url}'>{opt}</td>");
  1277. }
  1278. string html = string.Empty;
  1279. string title = string.Empty;
  1280. switch (lang)
  1281. {
  1282. case "zh-cn":
  1283. title= $"课例周报{startOfWeek.ToString("yyyy/MM/dd")}-{endOfWeek.ToString("MM/dd")}";
  1284. html= weeklyReportCN.Replace("{tmdName}", teacher.name).Replace("{year}", $"{now.Year}").Replace("{Week}", $"{week}").Replace("{weekTime}", $"{startOfWeek.ToString("yyyy/MM/dd")}-{endOfWeek.ToString("MM/dd")}").Replace("{lessonCount}", $"{data.Value.Count()}").Replace("{tableData}", sb.ToString());
  1285. break;
  1286. case "zh-tw":
  1287. title= $"課例周報{startOfWeek.ToString("yyyy/MM/dd")}-{endOfWeek.ToString("MM/dd")}";
  1288. html= weeklyReportTW.Replace("{tmdName}", teacher.name).Replace("{year}", $"{now.Year}").Replace("{Week}", $"{week}").Replace("{weekTime}", $"{startOfWeek.ToString("yyyy/MM/dd")}-{endOfWeek.ToString("MM/dd")}").Replace("{lessonCount}", $"{data.Value.Count()}").Replace("{tableData}", sb.ToString());
  1289. break;
  1290. case "en-us":
  1291. title= $"Lesson record weekly report{startOfWeek.ToString("yyyy/MM/dd")}-{endOfWeek.ToString("MM/dd")}";
  1292. html= weeklyReportEN.Replace("{tmdName}", teacher.name).Replace("{year}", $"{now.Year}").Replace("{Week}", $"{week}").Replace("{weekTime}", $"{startOfWeek.ToString("yyyy/MM/dd")}-{endOfWeek.ToString("MM/dd")}").Replace("{lessonCount}", $"{data.Value.Count()}").Replace("{tableData}", sb.ToString());
  1293. break;
  1294. }
  1295. {
  1296. // var token = _mailFactory.GetSmtpClient().SendEmail(_azureCosmos, dingDing, eventId, title, template, coreUser.mail, teacher.id, teacher.name, sender: "TEAMModel");
  1297. //var tid = lang.Equals("zh-cn") ? "d-136eddbd974046f1a721c8f4e210b9bf" : lang.Equals("zh-tw") ? "d-136eddbd974046f1a721c8f4e210b9bf" : "d-95ac2d657d1b4d9dbb7b79defc17f714";
  1298. var tid = string.Empty;
  1299. if (_coreAPIHttpService.options.location.Contains("China"))
  1300. {
  1301. tid=lang.Equals("zh-cn") ? "IES5GeneralTemplateSC" : lang.Equals("zh-tw") ? "IES5GeneralTemplateTC" : "IES5GeneralTemplateEN";
  1302. }
  1303. else
  1304. {
  1305. tid=lang.Equals("zh-cn") ? "d-270b4ec690f541a9a4045d7a4032bc3b" : lang.Equals("zh-tw") ? "d-136eddbd974046f1a721c8f4e210b9bf" : "d-95ac2d657d1b4d9dbb7b79defc17f714";
  1306. }
  1307. await _coreAPIHttpService.SendMail(new Dictionary<string, object> { { "to", coreUser.mail }, { "tid", tid }, { "vars", new { title = title, notificationcontent = html } } }, _coreAPIHttpService.options.location, _configuration);
  1308. }
  1309. }
  1310. }
  1311. }
  1312. }
  1313. }
  1314. /// <summary>
  1315. /// 记录累计数据
  1316. /// </summary>
  1317. public static async Task RecordAccumulateData(AzureRedisFactory azureRedis, string key, string target, string id, string name, string scope, string client, int count)
  1318. {
  1319. if (!string.IsNullOrWhiteSpace(key) && !string.IsNullOrWhiteSpace(target) &&
  1320. !string.IsNullOrWhiteSpace(id) && !string.IsNullOrWhiteSpace(name) &&
  1321. !string.IsNullOrWhiteSpace(scope)&& !string.IsNullOrWhiteSpace(client))
  1322. {
  1323. //处理UTC时差
  1324. var nowTime = DateTimeOffset.UtcNow.GetGMTTime();
  1325. int difference = (DayOfWeek.Sunday - nowTime.DayOfWeek + 7) % 7; //1-7的结果0-6
  1326. var day = nowTime.ToString("yyyyMMdd");
  1327. string redisKey = $"Accumulate:Daily:{scope}:{key}:{day}";
  1328. string member = $"{target}::{id}::{client}::{name}";
  1329. await azureRedis.GetRedisClient(8).SortedSetIncrementAsync(redisKey, member, count);
  1330. await azureRedis.GetRedisClient(8).KeyExpireAsync(redisKey, new TimeSpan((difference+1)*24, 10, 0));
  1331. //if (key.Equals("lesson") || key.StartsWith("login_"))
  1332. //{
  1333. // redisKey = $"Accumulate:Daily:ies:{key}:{day}";
  1334. // if (scope.Equals("school"))
  1335. // {
  1336. // member = $"ies::{id}::{name}";
  1337. // }
  1338. // else {
  1339. // member = $"ies::ies::{name}";
  1340. // }
  1341. // await azureRedis.GetRedisClient(8).SortedSetIncrementAsync(redisKey, member, 1);
  1342. //}
  1343. }
  1344. }
  1345. public const double timeWeight = 0.7;
  1346. public const double countWeight = 0.3;
  1347. static double GetUserDuration(List<long> times)
  1348. {
  1349. if (times.IsNotEmpty())
  1350. {
  1351. if (times.Count>=2)
  1352. {
  1353. double totalDuration = 0;
  1354. // DateTime lastTime = DateTimeOffset.FromUnixTimeMilliseconds((long)jsonData[0]["time"]).UtcDateTime;
  1355. long ltime = times[0];
  1356. for (int i = 1; i < times.Count; i++)
  1357. {
  1358. long ctime = times[i];
  1359. //DateTime currentTime = DateTimeOffset.FromUnixTimeMilliseconds((long)jsonData[i]["time"]).UtcDateTime;
  1360. long timeDifference = ctime - ltime;
  1361. ///如果一小时内连续操作,则按真实时间累计
  1362. if (timeDifference < 3600000)
  1363. {
  1364. totalDuration += timeDifference;
  1365. }
  1366. else
  1367. { ///如果一小时内没有连续操作,则按象征性加10秒,以确保数据有效性。 如果因为一小时没有操作,则表示没有新的接口再次请求,当即就已经退出系统。否则后续仍然会有接口进入,并且带有时间戳
  1368. totalDuration += 10000;
  1369. }
  1370. ltime = ctime;
  1371. }
  1372. return totalDuration;
  1373. }
  1374. else { return 10000; }
  1375. }
  1376. else
  1377. {
  1378. return 0;
  1379. }
  1380. }
  1381. public static List<SchoolStick> CountSchoolStickiness(IEnumerable<IGrouping<string, ApiVisit>> schoolApiVisits, IEnumerable<ApiVisit> apiVisits, List<SchoolStick> bygoneStickiness)
  1382. {
  1383. List<SchoolStick> schoolStickiness = new List<SchoolStick>();
  1384. //用于做标准化值的最大最小度量值
  1385. double max_sch_hita_c = 0, max_sch_hiteach_c = 0, max_sch_ies5Tch_c = 0, max_sch_otherTch_c = 0, max_sch_ies5Stu_c = 0, max_sch_otherStu_c = 0;
  1386. double max_sch_hita_d = 0, max_sch_hiteach_d = 0, max_sch_ies5Tch_d = 0, max_sch_otherTch_d = 0, max_sch_ies5Stu_d = 0, max_sch_otherStu_d = 0;
  1387. double min_sch_hita_c = 0, min_sch_hiteach_c = 0, min_sch_ies5Tch_c = 0, min_sch_otherTch_c = 0, min_sch_ies5Stu_c = 0, min_sch_otherStu_c = 0;
  1388. double min_sch_hita_d = 0, min_sch_hiteach_d = 0, min_sch_ies5Tch_d = 0, min_sch_otherTch_d = 0, min_sch_ies5Stu_d = 0, min_sch_otherStu_d = 0;
  1389. double max_tch_hita_c = 0, max_tch_hiteach_c = 0, max_tch_ies5Tch_c = 0, max_tch_otherTch_c = 0;
  1390. double max_tch_hita_d = 0, max_tch_hiteach_d = 0, max_tch_ies5Tch_d = 0, max_tch_otherTch_d = 0;
  1391. double min_tch_hita_c = 0, min_tch_hiteach_c = 0, min_tch_ies5Tch_c = 0, min_tch_otherTch_c = 0;
  1392. double min_tch_hita_d = 0, min_tch_hiteach_d = 0, min_tch_ies5Tch_d = 0, min_tch_otherTch_d = 0;
  1393. foreach (var chinaSchoolKey in schoolApiVisits)
  1394. {
  1395. SchoolStick stickiness = new SchoolStick()
  1396. {
  1397. id = chinaSchoolKey.Key
  1398. };
  1399. var teachers = chinaSchoolKey.ToList().Where(x => !string.IsNullOrWhiteSpace(x.userId) && !string.IsNullOrWhiteSpace(x.scope) && x.scope.Equals("teacher")).GroupBy(x => x.userId);
  1400. double hitaTime = 0, hiteachTime = 0, ies5TchTime = 0, otherTchTime = 0, ies5StuTime = 0, otherStuTime = 0;
  1401. int hitaTch = 0, hiteachTch = 0, ies5Tch = 0, otherTch = 0, ies5Stu = 0, otherStu = 0;
  1402. double hitaCount = 0, hiteachCount = 0, ies5TchCount = 0, otherTchCount = 0, ies5StuCount = 0, otherStuCount = 0;
  1403. double lessonCount = chinaSchoolKey.ToList().Where(x => x.path.Contains("hiteach/create-lesson")).Count();
  1404. int teacherCount = teachers.Count();
  1405. double max_stu_ies5Stu_c = 0, max_stu_otherStu_c = 0;
  1406. double max_stu_ies5Stu_d = 0, max_stu_otherStu_d = 0;
  1407. double min_stu_ies5Stu_c = 0, min_stu_otherStu_c = 0;
  1408. double min_stu_ies5Stu_d = 0, min_stu_otherStu_d = 0;
  1409. foreach (var user in teachers)
  1410. {
  1411. TchStick tchStick = new TchStick()
  1412. {
  1413. id = user.Key,
  1414. school= chinaSchoolKey.Key
  1415. };
  1416. //HiTA
  1417. var teacherHitaVisit = apiVisits.Where(x => !string.IsNullOrWhiteSpace(x.userId) && x.userId.Equals(user.Key) && x.client.Equals("hita"));
  1418. var teacherHitaVisitCount = teacherHitaVisit.Count();
  1419. if (teacherHitaVisitCount>0)
  1420. { hitaTch+=1; }
  1421. var teacherHitaVisitTime = GetUserDuration(teacherHitaVisit.OrderBy(x => x.time).Select(x => x.time).ToList());
  1422. hitaCount+=teacherHitaVisitCount;
  1423. hitaTime+=teacherHitaVisitTime;
  1424. tchStick.hita.count.value=teacherHitaVisitCount;
  1425. tchStick.hita.duration.value=teacherHitaVisitTime;
  1426. //Other
  1427. var teacherOtherVisit = user.Where(x => !x.client.Equals("hita")&&!x.client.Equals("hiteach")&&!x.client.Equals("ies5"));
  1428. var teacherOtherVisitCount = teacherOtherVisit.Count();
  1429. var teacherOtherVisitTime = GetUserDuration(teacherOtherVisit.OrderBy(x => x.time).Select(x => x.time).ToList());
  1430. if (teacherOtherVisitCount>0)
  1431. { otherTch+=1; }
  1432. otherTchCount+=teacherOtherVisitCount;
  1433. otherTchTime+=teacherOtherVisitTime;
  1434. tchStick.otherTch.count.value=teacherOtherVisitCount;
  1435. tchStick.otherTch.duration.value=teacherOtherVisitTime;
  1436. //HiTeach
  1437. //教师访问hiteach 不带学校信息的
  1438. var teacherHiteachVisit = apiVisits.Where(x => !string.IsNullOrWhiteSpace(x.userId) && x.userId.Equals(user.Key) && x.client.Equals("hiteach") && string.IsNullOrWhiteSpace(x.school));
  1439. //教师访问hiteach 包含学校信息的
  1440. var teacherHiteachSchoolVisit = user.Where(x => x.client.Equals("hiteach"));
  1441. //教师所有的Hiteach访问
  1442. List<ApiVisit> teacherHiteachAllVisit = new List<ApiVisit>();
  1443. teacherHiteachAllVisit.AddRange(teacherHiteachVisit);
  1444. teacherHiteachAllVisit.AddRange(teacherHiteachSchoolVisit);
  1445. var teacherHiteachAllVisitCount = teacherHiteachAllVisit.Count();
  1446. if (teacherHiteachAllVisitCount>0)
  1447. { hiteachTch+=1; }
  1448. var teacherHiteachAllVisitTime = GetUserDuration(teacherHiteachAllVisit.OrderBy(x => x.time).Select(x => x.time).ToList());
  1449. hiteachCount+=teacherHiteachAllVisitCount;
  1450. hiteachTime+=teacherHiteachAllVisitTime;
  1451. tchStick.hiteach.count.value=teacherHiteachAllVisitCount;
  1452. tchStick.hiteach.duration.value=teacherHiteachAllVisitTime;
  1453. //IES5
  1454. var teacherIes5Visit = user.Where(x => x.client.Equals("ies5"));
  1455. var teacherIes5VisitCount = teacherIes5Visit.Count();
  1456. if (teacherIes5VisitCount>0)
  1457. { ies5Tch+=1; }
  1458. var teacherIes5VisitTime = GetUserDuration(teacherIes5Visit.OrderBy(x => x.time).Select(x => x.time).ToList());
  1459. ies5TchCount+=teacherIes5VisitCount;
  1460. ies5TchTime+=teacherIes5VisitTime;
  1461. tchStick.ies5Tch.count.value=teacherIes5VisitCount;
  1462. tchStick.ies5Tch.duration.value=teacherIes5VisitTime;
  1463. double lessonCountTch = chinaSchoolKey.ToList().Where(x => x.path.Contains("hiteach/create-lesson") && x.userId.Equals(user.Key)).Count();
  1464. tchStick.lesson.value=lessonCountTch;
  1465. tchStick.teacher.count.value=tchStick.hita.count.value+tchStick.hiteach.count.value+tchStick.ies5Tch.count.value+tchStick.otherTch.count.value;
  1466. tchStick.teacher.duration.value=tchStick.hita.duration.value+tchStick.hiteach.duration.value+tchStick.ies5Tch.duration.value+tchStick.otherTch.duration.value;
  1467. tchStick.hita.userCount=1;
  1468. tchStick.hiteach.userCount=1;
  1469. tchStick.ies5Tch.userCount=1;
  1470. tchStick.otherTch.userCount=1;
  1471. tchStick.teacher.userCount=1;
  1472. //if (tchStick.hita.count.value>0 && tchStick.hita.duration.value>0)
  1473. //{
  1474. // tchStick.hita.stick.value= (tchStick.hita.duration.value/1000/tchStick.hita.count.value * tchStick.hita.count.value/tchStick.teacher.count.value);
  1475. //}
  1476. //if (tchStick.ies5Tch.count.value>0 && tchStick.ies5Tch.duration.value>0)
  1477. //{
  1478. // tchStick.ies5Tch.stick.value= (tchStick.ies5Tch.duration.value/1000/tchStick.ies5Tch.count.value * tchStick.ies5Tch.count.value/tchStick.teacher.count.value);
  1479. //}
  1480. //if (tchStick.otherTch.count.value>0 && tchStick.otherTch.duration.value>0)
  1481. //{
  1482. // tchStick.otherTch.stick.value= (tchStick.otherTch.duration.value/1000/tchStick.otherTch.count.value);
  1483. //}
  1484. //if (tchStick.hiteach.count.value>0 && tchStick.hiteach.duration.value>0)
  1485. //{
  1486. // tchStick.hiteach.stick.value= (tchStick.hiteach.duration.value/1000/tchStick.hiteach.count.value)+(tchStick.lesson.value*100);
  1487. //}
  1488. //if (tchStick.teacher.count.value>0 && tchStick.teacher.duration.value>0)
  1489. //{
  1490. // tchStick.teacher.stick.value= (tchStick.teacher.duration.value/1000/tchStick.teacher.count.value)+ (tchStick.lesson.value*100);
  1491. //}
  1492. #region
  1493. if (tchStick.hita.count.value>0)
  1494. {
  1495. if (min_tch_hita_c ==0)
  1496. {
  1497. min_tch_hita_c= tchStick.hita.count.value;
  1498. }
  1499. else if (min_tch_hita_c>tchStick.hita.count.value)
  1500. {
  1501. min_tch_hita_c=tchStick.hita.count.value;
  1502. }
  1503. if (tchStick.hita.count.value>max_tch_hita_c)
  1504. {
  1505. max_tch_hita_c= tchStick.hita.count.value;
  1506. }
  1507. }
  1508. if (tchStick.hiteach.count.value>0)
  1509. {
  1510. if (min_tch_hiteach_c ==0)
  1511. {
  1512. min_tch_hiteach_c= tchStick.hiteach.count.value;
  1513. }
  1514. else if (min_tch_hiteach_c>tchStick.hiteach.count.value)
  1515. {
  1516. min_tch_hiteach_c=tchStick.hiteach.count.value;
  1517. }
  1518. if (tchStick.hiteach.count.value>max_tch_hiteach_c)
  1519. {
  1520. max_tch_hiteach_c= tchStick.hiteach.count.value;
  1521. }
  1522. }
  1523. if (tchStick.ies5Tch.count.value>0)
  1524. {
  1525. if (min_tch_ies5Tch_c ==0)
  1526. {
  1527. min_tch_ies5Tch_c= tchStick.ies5Tch.count.value;
  1528. }
  1529. else if (min_tch_ies5Tch_c>tchStick.ies5Tch.count.value)
  1530. {
  1531. min_tch_ies5Tch_c=tchStick.ies5Tch.count.value;
  1532. }
  1533. if (tchStick.ies5Tch.count.value>max_tch_ies5Tch_c)
  1534. {
  1535. max_tch_ies5Tch_c= tchStick.ies5Tch.count.value;
  1536. }
  1537. }
  1538. if (tchStick.otherTch.count.value>0)
  1539. {
  1540. if (min_tch_otherTch_c ==0)
  1541. {
  1542. min_tch_otherTch_c= tchStick.otherTch.count.value;
  1543. }
  1544. else if (min_tch_otherTch_c>tchStick.otherTch.count.value)
  1545. {
  1546. min_tch_otherTch_c=tchStick.otherTch.count.value;
  1547. }
  1548. if (tchStick.otherTch.count.value>max_tch_otherTch_c)
  1549. {
  1550. max_tch_otherTch_c= tchStick.otherTch.count.value;
  1551. }
  1552. }
  1553. if (tchStick.hita.duration.value>0)
  1554. {
  1555. if (min_tch_hita_d ==0)
  1556. {
  1557. min_tch_hita_d= tchStick.hita.duration.value;
  1558. }
  1559. else if (min_tch_hita_d>tchStick.hita.duration.value)
  1560. {
  1561. min_tch_hita_d=tchStick.hita.duration.value;
  1562. }
  1563. if (tchStick.hita.duration.value>max_tch_hita_d)
  1564. {
  1565. max_tch_hita_d= tchStick.hita.duration.value;
  1566. }
  1567. }
  1568. if (tchStick.hiteach.duration.value>0)
  1569. {
  1570. if (min_tch_hiteach_d ==0)
  1571. {
  1572. min_tch_hiteach_d= tchStick.hiteach.duration.value;
  1573. }
  1574. else if (min_tch_hiteach_d>tchStick.hiteach.duration.value)
  1575. {
  1576. min_tch_hiteach_d=tchStick.hiteach.duration.value;
  1577. }
  1578. if (tchStick.hiteach.duration.value>max_tch_hiteach_d)
  1579. {
  1580. max_tch_hiteach_d= tchStick.hiteach.duration.value;
  1581. }
  1582. }
  1583. if (tchStick.ies5Tch.duration.value>0)
  1584. {
  1585. if (min_tch_ies5Tch_d ==0)
  1586. {
  1587. min_tch_ies5Tch_d= tchStick.ies5Tch.duration.value;
  1588. }
  1589. else if (min_tch_ies5Tch_d>tchStick.ies5Tch.duration.value)
  1590. {
  1591. min_tch_ies5Tch_d=tchStick.ies5Tch.duration.value;
  1592. }
  1593. if (tchStick.ies5Tch.duration.value>max_tch_ies5Tch_d)
  1594. {
  1595. max_tch_ies5Tch_d= tchStick.ies5Tch.duration.value;
  1596. }
  1597. }
  1598. if (tchStick.otherTch.duration.value>0)
  1599. {
  1600. if (min_tch_otherTch_d ==0)
  1601. {
  1602. min_tch_otherTch_d= tchStick.otherTch.duration.value;
  1603. }
  1604. else if (min_tch_otherTch_d>tchStick.otherTch.duration.value)
  1605. {
  1606. min_tch_otherTch_d=tchStick.otherTch.duration.value;
  1607. }
  1608. if (tchStick.otherTch.duration.value>max_tch_otherTch_d)
  1609. {
  1610. max_tch_otherTch_d= tchStick.otherTch.duration.value;
  1611. }
  1612. }
  1613. #endregion
  1614. stickiness.tchSticks.Add(tchStick);
  1615. }
  1616. 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);
  1617. var studentCount = student.Count();
  1618. foreach (var user in student)
  1619. {
  1620. StuStick stuStick = new StuStick
  1621. {
  1622. id=user.Key,
  1623. school=chinaSchoolKey.Key
  1624. };
  1625. var studentOtherVisit = user.Where(x => !x.client.Equals("ies5"));
  1626. var studentOtherVisitCount = studentOtherVisit.Count();
  1627. if (studentOtherVisitCount>0)
  1628. { otherStu+=1; }
  1629. double studentOtherVisitTime = GetUserDuration(studentOtherVisit.OrderBy(x => x.time).Select(x => x.time).ToList());
  1630. var studentIes5Visit = user.Where(x => x.client.Equals("ies5"));
  1631. var studentIes5VisitCount = studentIes5Visit.Count();
  1632. if (studentIes5VisitCount>0)
  1633. { ies5Stu+=1; }
  1634. double studentIes5VisitTime = GetUserDuration(studentIes5Visit.OrderBy(x => x.time).Select(x => x.time).ToList());
  1635. ies5StuCount+=studentIes5VisitCount;
  1636. ies5StuTime+=studentIes5VisitTime;
  1637. otherStuCount+=studentOtherVisitCount;
  1638. otherStuTime+=studentOtherVisitTime;
  1639. stuStick.ies5Stu.count.value=studentIes5VisitCount;
  1640. stuStick.ies5Stu.duration.value=studentIes5VisitTime;
  1641. stuStick.otherStu.count.value=studentOtherVisitCount;
  1642. stuStick.otherStu.duration.value=studentOtherVisitTime;
  1643. stuStick.student.count.value= stuStick.ies5Stu.count.value+stuStick.otherStu.count.value;
  1644. stuStick.student.duration.value= stuStick.ies5Stu.duration.value+stuStick.otherStu.duration.value;
  1645. stuStick.ies5Stu.userCount=1;
  1646. stuStick.otherStu.userCount=1;
  1647. stuStick.student.userCount=1;
  1648. //if (stuStick.ies5Stu.count.value>0 && stuStick.ies5Stu.duration.value>0)
  1649. //{
  1650. // stuStick.ies5Stu.stick.value= (stuStick.ies5Stu.duration.value/1000/stuStick.ies5Stu.count.value);
  1651. //}
  1652. //if (stuStick.otherStu.count.value>0 && stuStick.otherStu.duration.value>0)
  1653. //{
  1654. // stuStick.otherStu.stick.value=(stuStick.otherStu.duration.value/1000/stuStick.otherStu.count.value);
  1655. //}
  1656. //if (stuStick.student.count.value>0 && stuStick.student.duration.value>0)
  1657. //{
  1658. // stuStick.student.stick.value=(stuStick.student.duration.value/1000/stuStick.student.count.value);
  1659. //}
  1660. #region
  1661. if (stuStick.otherStu.count.value>0)
  1662. {
  1663. if (min_stu_otherStu_c ==0)
  1664. {
  1665. min_stu_otherStu_c= stuStick.otherStu.count.value;
  1666. }
  1667. else if (min_stu_otherStu_c>stuStick.otherStu.count.value)
  1668. {
  1669. min_stu_otherStu_c=stuStick.otherStu.count.value;
  1670. }
  1671. if (stuStick.otherStu.count.value>max_stu_otherStu_c)
  1672. {
  1673. max_stu_otherStu_c= stuStick.otherStu.count.value;
  1674. }
  1675. }
  1676. if (stuStick.ies5Stu.count.value>0)
  1677. {
  1678. if (min_stu_ies5Stu_c ==0)
  1679. {
  1680. min_stu_ies5Stu_c= stuStick.ies5Stu.count.value;
  1681. }
  1682. else if (min_stu_ies5Stu_c>stuStick.ies5Stu.count.value)
  1683. {
  1684. min_stu_ies5Stu_c=stuStick.ies5Stu.count.value;
  1685. }
  1686. if (stuStick.ies5Stu.count.value>max_stu_ies5Stu_c)
  1687. {
  1688. max_stu_ies5Stu_c= stuStick.ies5Stu.count.value;
  1689. }
  1690. }
  1691. if (stuStick.otherStu.duration.value>0)
  1692. {
  1693. if (min_stu_otherStu_d ==0)
  1694. {
  1695. min_stu_otherStu_d= stuStick.otherStu.duration.value;
  1696. }
  1697. else if (min_stu_otherStu_d>stuStick.otherStu.duration.value)
  1698. {
  1699. min_stu_otherStu_d=stuStick.otherStu.duration.value;
  1700. }
  1701. if (stuStick.otherStu.duration.value>max_stu_otherStu_d)
  1702. {
  1703. max_stu_otherStu_d= stuStick.otherStu.duration.value;
  1704. }
  1705. }
  1706. if (stuStick.ies5Stu.duration.value>0)
  1707. {
  1708. if (min_stu_ies5Stu_d ==0)
  1709. {
  1710. min_stu_ies5Stu_d= stuStick.ies5Stu.duration.value;
  1711. }
  1712. else if (min_stu_ies5Stu_d>stuStick.ies5Stu.duration.value)
  1713. {
  1714. min_stu_ies5Stu_d=stuStick.ies5Stu.duration.value;
  1715. }
  1716. if (stuStick.ies5Stu.duration.value>max_stu_ies5Stu_d)
  1717. {
  1718. max_stu_ies5Stu_d= stuStick.ies5Stu.duration.value;
  1719. }
  1720. }
  1721. #endregion
  1722. stickiness.stuSticks.Add(stuStick);
  1723. }
  1724. //时长
  1725. stickiness.hita.duration.value=hitaTime;
  1726. stickiness.hiteach.duration.value=hiteachTime;
  1727. stickiness.otherTch.duration.value=otherTchTime;
  1728. stickiness.ies5Tch.duration.value=ies5TchTime;
  1729. stickiness.ies5Stu.duration.value=ies5StuTime;
  1730. stickiness.otherStu.duration.value=otherStuTime;
  1731. stickiness.teacher.duration.value=hitaTime+hiteachTime+otherTchTime+ies5TchTime;
  1732. stickiness.student.duration.value=otherStuTime+ies5StuTime;
  1733. //用户数
  1734. stickiness.hita.userCount=hitaTch;
  1735. stickiness.hiteach.userCount=hiteachTch;
  1736. stickiness.ies5Tch.userCount=ies5Tch;
  1737. stickiness.otherTch.userCount=otherTch;
  1738. stickiness.ies5Stu.userCount=ies5Stu;
  1739. stickiness.otherStu.userCount=otherStu;
  1740. stickiness.teacher.userCount=teacherCount;
  1741. stickiness.student.userCount=studentCount;
  1742. //访问数
  1743. stickiness.hita.count.value=hitaCount;
  1744. stickiness.hiteach.count.value=hiteachCount;
  1745. stickiness.ies5Tch.count.value=ies5TchCount;
  1746. stickiness.otherTch.count.value=otherTchCount;
  1747. stickiness.ies5Stu.count.value=ies5StuCount;
  1748. stickiness.otherStu.count.value=otherStuCount;
  1749. stickiness.teacher.count.value=hitaCount+hiteachCount+ies5TchCount+otherTchCount;
  1750. stickiness.student.count.value=ies5StuCount+otherStuCount;
  1751. //开课数
  1752. stickiness.lesson.value=lessonCount;
  1753. //if (stickiness.hita.count.value>0 && stickiness.hita.duration.value>0)
  1754. //{
  1755. // stickiness.hita.stick.value=(stickiness.hita.userCount* stickiness.hita.count.value)/(stickiness.hita.duration.value/1000/stickiness.hita.count.value);
  1756. //}
  1757. //if (stickiness.ies5Stu.count.value>0 && stickiness.ies5Stu.duration.value>0)
  1758. //{
  1759. // stickiness.ies5Stu.stick.value=(stickiness.ies5Stu.userCount* stickiness.ies5Stu.count.value)/(stickiness.ies5Stu.duration.value/1000/stickiness.ies5Stu.count.value);
  1760. //}
  1761. //if (stickiness.ies5Tch.count.value>0 && stickiness.ies5Tch.duration.value>0)
  1762. //{
  1763. // stickiness.ies5Tch.stick.value=(stickiness.ies5Tch.userCount* stickiness.ies5Tch.count.value)/(stickiness.ies5Tch.duration.value/1000/stickiness.ies5Tch.count.value);
  1764. //}
  1765. //if (stickiness.otherStu.count.value>0 && stickiness.otherStu.duration.value>0)
  1766. //{
  1767. // stickiness.otherStu.stick.value=(stickiness.otherStu.userCount* stickiness.otherStu.count.value)/(stickiness.otherStu.duration.value/1000/stickiness.otherStu.count.value);
  1768. //}
  1769. //if (stickiness.otherTch.count.value>0 && stickiness.otherTch.duration.value>0)
  1770. //{
  1771. // stickiness.otherTch.stick.value=(stickiness.otherTch.userCount* stickiness.otherTch.count.value)/(stickiness.otherTch.duration.value/1000/stickiness.otherTch.count.value);
  1772. //}
  1773. //if (stickiness.hiteach.count.value>0 && stickiness.hiteach.duration.value>0)
  1774. //{
  1775. // stickiness.hiteach.stick.value=(stickiness.hiteach.userCount* stickiness.hiteach.count.value)/(stickiness.hiteach.duration.value/1000/stickiness.hiteach.count.value)+stickiness.lesson.value;
  1776. //}
  1777. //if (stickiness.teacher.count.value>0 && stickiness.teacher.duration.value>0)
  1778. //{
  1779. // stickiness.teacher.stick.value=(stickiness.teacher.userCount* stickiness.teacher.count.value)/(stickiness.teacher.duration.value/1000/stickiness.teacher.count.value)+ stickiness.lesson.value;
  1780. //}
  1781. //if (stickiness.student.count.value>0 && stickiness.student.duration.value>0)
  1782. //{
  1783. // stickiness.student.stick.value=(stickiness.student.userCount* stickiness.student.count.value)/(stickiness.student.duration.value/1000/stickiness.student.count.value)+ stickiness.lesson.value;
  1784. //}
  1785. #region
  1786. if (stickiness.hita.count.value>0)
  1787. {
  1788. if (min_sch_hita_c ==0)
  1789. {
  1790. min_sch_hita_c= stickiness.hita.count.value;
  1791. }
  1792. else if (min_sch_hita_c>stickiness.hita.count.value)
  1793. {
  1794. min_sch_hita_c=stickiness.hita.count.value;
  1795. }
  1796. if (stickiness.hita.count.value>max_sch_hita_c)
  1797. {
  1798. max_sch_hita_c= stickiness.hita.count.value;
  1799. }
  1800. }
  1801. if (stickiness.hiteach.count.value>0)
  1802. {
  1803. if (min_sch_hiteach_c ==0)
  1804. {
  1805. min_sch_hiteach_c= stickiness.hiteach.count.value;
  1806. }
  1807. else if (min_sch_hiteach_c>stickiness.hiteach.count.value)
  1808. {
  1809. min_sch_hiteach_c=stickiness.hiteach.count.value;
  1810. }
  1811. if (stickiness.hiteach.count.value>max_sch_hiteach_c)
  1812. {
  1813. max_sch_hiteach_c= stickiness.hiteach.count.value;
  1814. }
  1815. }
  1816. if (stickiness.ies5Tch.count.value>0)
  1817. {
  1818. if (min_sch_ies5Tch_c ==0)
  1819. {
  1820. min_sch_ies5Tch_c= stickiness.ies5Tch.count.value;
  1821. }
  1822. else if (min_sch_ies5Tch_c>stickiness.ies5Tch.count.value)
  1823. {
  1824. min_sch_ies5Tch_c=stickiness.ies5Tch.count.value;
  1825. }
  1826. if (stickiness.ies5Tch.count.value>max_sch_ies5Tch_c)
  1827. {
  1828. max_sch_ies5Tch_c= stickiness.ies5Tch.count.value;
  1829. }
  1830. }
  1831. if (stickiness.otherTch.count.value>0)
  1832. {
  1833. if (min_sch_otherTch_c ==0)
  1834. {
  1835. min_sch_otherTch_c= stickiness.otherTch.count.value;
  1836. }
  1837. else if (min_sch_otherTch_c>stickiness.otherTch.count.value)
  1838. {
  1839. min_sch_otherTch_c=stickiness.otherTch.count.value;
  1840. }
  1841. if (stickiness.otherTch.count.value>max_sch_otherTch_c)
  1842. {
  1843. max_sch_otherTch_c= stickiness.otherTch.count.value;
  1844. }
  1845. }
  1846. if (stickiness.otherStu.count.value>0)
  1847. {
  1848. if (min_sch_otherStu_c ==0)
  1849. {
  1850. min_sch_otherStu_c= stickiness.otherStu.count.value;
  1851. }
  1852. else if (min_sch_otherStu_c>stickiness.otherStu.count.value)
  1853. {
  1854. min_sch_otherStu_c=stickiness.otherStu.count.value;
  1855. }
  1856. if (stickiness.otherStu.count.value>max_sch_otherStu_c)
  1857. {
  1858. max_sch_otherStu_c= stickiness.otherStu.count.value;
  1859. }
  1860. }
  1861. if (stickiness.ies5Stu.count.value>0)
  1862. {
  1863. if (min_sch_ies5Stu_c ==0)
  1864. {
  1865. min_sch_ies5Stu_c= stickiness.ies5Stu.count.value;
  1866. }
  1867. else if (min_sch_ies5Stu_c>stickiness.ies5Stu.count.value)
  1868. {
  1869. min_sch_ies5Stu_c=stickiness.ies5Stu.count.value;
  1870. }
  1871. if (stickiness.ies5Stu.count.value>max_sch_ies5Stu_c)
  1872. {
  1873. max_sch_ies5Stu_c= stickiness.ies5Stu.count.value;
  1874. }
  1875. }
  1876. if (stickiness.hita.duration.value>0)
  1877. {
  1878. if (min_sch_hita_d ==0)
  1879. {
  1880. min_sch_hita_d= stickiness.hita.duration.value;
  1881. }
  1882. else if (min_sch_hita_d>stickiness.hita.duration.value)
  1883. {
  1884. min_sch_hita_d=stickiness.hita.duration.value;
  1885. }
  1886. if (stickiness.hita.duration.value>max_sch_hita_d)
  1887. {
  1888. max_sch_hita_d= stickiness.hita.duration.value;
  1889. }
  1890. }
  1891. if (stickiness.hiteach.duration.value>0)
  1892. {
  1893. if (min_sch_hiteach_d ==0)
  1894. {
  1895. min_sch_hiteach_d= stickiness.hiteach.duration.value;
  1896. }
  1897. else if (min_sch_hiteach_d>stickiness.hiteach.duration.value)
  1898. {
  1899. min_sch_hiteach_d=stickiness.hiteach.duration.value;
  1900. }
  1901. if (stickiness.hiteach.duration.value>max_sch_hiteach_d)
  1902. {
  1903. max_sch_hiteach_d= stickiness.hiteach.duration.value;
  1904. }
  1905. }
  1906. if (stickiness.ies5Tch.duration.value>0)
  1907. {
  1908. if (min_sch_ies5Tch_d ==0)
  1909. {
  1910. min_sch_ies5Tch_d= stickiness.ies5Tch.duration.value;
  1911. }
  1912. else if (min_sch_ies5Tch_d>stickiness.ies5Tch.duration.value)
  1913. {
  1914. min_sch_ies5Tch_d=stickiness.ies5Tch.duration.value;
  1915. }
  1916. if (stickiness.ies5Tch.duration.value>max_sch_ies5Tch_d)
  1917. {
  1918. max_sch_ies5Tch_d= stickiness.ies5Tch.duration.value;
  1919. }
  1920. }
  1921. if (stickiness.otherTch.duration.value>0)
  1922. {
  1923. if (min_sch_otherTch_d ==0)
  1924. {
  1925. min_sch_otherTch_d= stickiness.otherTch.duration.value;
  1926. }
  1927. else if (min_sch_otherTch_d>stickiness.otherTch.duration.value)
  1928. {
  1929. min_sch_otherTch_d=stickiness.otherTch.duration.value;
  1930. }
  1931. if (stickiness.otherTch.duration.value>max_sch_otherTch_d)
  1932. {
  1933. max_sch_otherTch_d= stickiness.otherTch.duration.value;
  1934. }
  1935. }
  1936. if (stickiness.otherStu.duration.value>0)
  1937. {
  1938. if (min_sch_otherStu_d ==0)
  1939. {
  1940. min_sch_otherStu_d= stickiness.otherStu.duration.value;
  1941. }
  1942. else if (min_sch_otherStu_d>stickiness.otherStu.duration.value)
  1943. {
  1944. min_sch_otherStu_d=stickiness.otherStu.duration.value;
  1945. }
  1946. if (stickiness.otherStu.duration.value>max_sch_otherStu_d)
  1947. {
  1948. max_sch_otherStu_d= stickiness.otherStu.duration.value;
  1949. }
  1950. }
  1951. if (stickiness.ies5Stu.duration.value>0)
  1952. {
  1953. if (min_sch_ies5Stu_d ==0)
  1954. {
  1955. min_sch_ies5Stu_d= stickiness.ies5Stu.duration.value;
  1956. }
  1957. else if (min_sch_ies5Stu_d>stickiness.ies5Stu.duration.value)
  1958. {
  1959. min_sch_ies5Stu_d=stickiness.ies5Stu.duration.value;
  1960. }
  1961. if (stickiness.ies5Stu.duration.value>max_sch_ies5Stu_d)
  1962. {
  1963. max_sch_ies5Stu_d= stickiness.ies5Stu.duration.value;
  1964. }
  1965. }
  1966. #endregion
  1967. var bygoneStickinessSchool = bygoneStickiness?.Find(x => x.id.Equals(chinaSchoolKey.Key));
  1968. stickiness.tchSticks= OrderByTchStick(stickiness.tchSticks, bygoneStickinessSchool?.tchSticks);
  1969. stickiness.stuSticks= OrderByStuStick(stickiness.stuSticks, bygoneStickinessSchool?.stuSticks);
  1970. schoolStickiness.Add(stickiness);
  1971. }
  1972. return OrderBySchoolStick(schoolStickiness, bygoneStickiness);
  1973. }
  1974. private static List<StuStick> OrderByStuStick(List<StuStick> currentStickiness, List<StuStick>? bygoneStickiness)
  1975. {
  1976. // 假设visit已经填充了数据
  1977. #region
  1978. var rank_tmd_count = currentStickiness.Select(x => x.student.count.value).Distinct().OrderByDescending(v => v).ToList();
  1979. var rank_ies5Stu_count = currentStickiness.Select(x => x.ies5Stu.count.value).Distinct().OrderByDescending(v => v).ToList();
  1980. var rank_otherStu_count = currentStickiness.Select(x => x.otherStu.count.value).Distinct().OrderByDescending(v => v).ToList();
  1981. #endregion
  1982. #region
  1983. var rank_tmd_duration = currentStickiness.Select(x => x.student.duration.value).Distinct().OrderByDescending(v => v).ToList();
  1984. var rank_ies5Stu_duration = currentStickiness.Select(x => x.ies5Stu.duration.value).Distinct().OrderByDescending(v => v).ToList();
  1985. var rank_otherStu_duration = currentStickiness.Select(x => x.otherStu.duration.value).Distinct().OrderByDescending(v => v).ToList();
  1986. #endregion
  1987. #region
  1988. var rank_tmd_stick = currentStickiness.Select(x => x.student.stick.value).Distinct().OrderByDescending(v => v).ToList();
  1989. var rank_ies5Stu_stick = currentStickiness.Select(x => x.ies5Stu.stick.value).Distinct().OrderByDescending(v => v).ToList();
  1990. var rank_otherStu_stick = currentStickiness.Select(x => x.otherStu.stick.value).Distinct().OrderByDescending(v => v).ToList();
  1991. #endregion
  1992. currentStickiness.ForEach(x =>
  1993. {
  1994. #region
  1995. if (x.student.count.value>0)
  1996. {
  1997. int index_tmd_count = rank_tmd_count.FindIndex(i => i==x.student.count.value);
  1998. if (index_tmd_count!=-1)
  1999. {
  2000. x.student.count.rank = index_tmd_count + 1;
  2001. }
  2002. }
  2003. if (x.ies5Stu.count.value>0)
  2004. {
  2005. int index_ies5Stu_count = rank_ies5Stu_count.FindIndex(i => i==x.ies5Stu.count.value);
  2006. if (index_ies5Stu_count!=-1)
  2007. {
  2008. x.ies5Stu.count.rank = index_ies5Stu_count + 1;
  2009. }
  2010. }
  2011. if (x.otherStu.count.value>0)
  2012. {
  2013. int index_otherStu_count = rank_otherStu_count.FindIndex(i => i==x.otherStu.count.value);
  2014. if (index_otherStu_count!=-1)
  2015. {
  2016. x.otherStu.count.rank = index_otherStu_count + 1;
  2017. }
  2018. }
  2019. #endregion
  2020. #region
  2021. if (x.student.duration.value> 0)
  2022. {
  2023. int index_tmd_duration = rank_tmd_duration.FindIndex(i => i==x.student.duration.value);
  2024. if (index_tmd_duration!=-1)
  2025. {
  2026. x.student.duration.rank = index_tmd_duration + 1;
  2027. }
  2028. }
  2029. if (x.ies5Stu.duration.value>0)
  2030. {
  2031. int index_ies5Stu_duration = rank_ies5Stu_duration.FindIndex(i => i==x.ies5Stu.duration.value);
  2032. if (index_ies5Stu_duration!=-1)
  2033. {
  2034. x.ies5Stu.duration.rank = index_ies5Stu_duration + 1;
  2035. }
  2036. }
  2037. if (x.otherStu.duration.value>0)
  2038. {
  2039. int index_otherStu_duration = rank_otherStu_duration.FindIndex(i => i==x.otherStu.duration.value);
  2040. if (index_otherStu_duration!=-1)
  2041. {
  2042. x.otherStu.duration.rank = index_otherStu_duration + 1;
  2043. }
  2044. }
  2045. #endregion
  2046. #region
  2047. if (x.student.stick.value>0)
  2048. {
  2049. int index_tmd_stick = rank_tmd_stick.FindIndex(i => i==x.student.stick.value);
  2050. if (index_tmd_stick!=-1)
  2051. {
  2052. x.student.stick.rank = index_tmd_stick + 1;
  2053. }
  2054. }
  2055. if (x.ies5Stu.stick.value>0)
  2056. {
  2057. int index_ies5Stu_stick = rank_ies5Stu_stick.FindIndex(i => i==x.ies5Stu.stick.value);
  2058. if (index_ies5Stu_stick!=-1)
  2059. {
  2060. x.ies5Stu.stick.rank = index_ies5Stu_stick + 1;
  2061. }
  2062. }
  2063. if (x.otherStu.stick.value>0)
  2064. {
  2065. int index_otherStu_stick = rank_otherStu_stick.FindIndex(i => i==x.otherStu.stick.value);
  2066. if (index_otherStu_stick!=-1)
  2067. {
  2068. x.otherStu.stick.rank = index_otherStu_stick + 1;
  2069. }
  2070. }
  2071. #endregion
  2072. var bygone = bygoneStickiness?.Find(y => y.id.Equals(x.id));
  2073. if (bygone!=null)
  2074. {
  2075. #region tmd
  2076. //人数上升下降
  2077. x.student.userUpdown= x.student.userCount-bygone.student.userCount;
  2078. //访问数量上升下降
  2079. x.student.count.range= x.student.count.value-bygone.student.count.value;
  2080. //访问数量排名上升下降
  2081. x.student.count.updown= -(x.student.count.rank-bygone.student.count.rank);
  2082. //停留时长上升下降
  2083. x.student.duration.range=x.student.duration.value-bygone.student.duration.value;
  2084. //停留时长排名上升下降
  2085. x.student.duration.updown=-(x.student.duration.rank-bygone.student.duration.rank);
  2086. //访问指数上升下降
  2087. x.student.stick.range=x.student.stick.value-bygone.student.stick.value;
  2088. //访问指数排名上升下降
  2089. x.student.stick.updown=-(x.student.stick.rank-bygone.student.stick.rank);
  2090. #endregion
  2091. #region otherStu
  2092. //人数上升下降
  2093. x.otherStu.userUpdown= x.otherStu.userCount-bygone.otherStu.userCount;
  2094. //访问数量上升下降
  2095. x.otherStu.count.range= x.otherStu.count.value-bygone.otherStu.count.value;
  2096. //访问数量排名上升下降
  2097. x.otherStu.count.updown= -(x.otherStu.count.rank-bygone.otherStu.count.rank);
  2098. //停留时长上升下降
  2099. x.otherStu.duration.range=x.otherStu.duration.value-bygone.otherStu.duration.value;
  2100. //停留时长排名上升下降
  2101. x.otherStu.duration.updown=-(x.otherStu.duration.rank - bygone.otherStu.duration.rank);
  2102. //访问指数上升下降
  2103. x.otherStu.stick.range=x.otherStu.stick.value-bygone.otherStu.stick.value;
  2104. //访问指数排名上升下降
  2105. x.otherStu.stick.updown=-(x.otherStu.stick.rank - bygone.otherStu.stick.rank);
  2106. #endregion
  2107. #region ies5Stu
  2108. //人数上升下降
  2109. x.ies5Stu.userUpdown= x.ies5Stu.userCount-bygone.ies5Stu.userCount;
  2110. //访问数量上升下降
  2111. x.ies5Stu.count.range= x.ies5Stu.count.value-bygone.ies5Stu.count.value;
  2112. //访问数量排名上升下降
  2113. x.ies5Stu.count.updown= -(x.ies5Stu.count.rank - bygone.ies5Stu.count.rank);
  2114. //停留时长上升下降
  2115. x.ies5Stu.duration.range=x.ies5Stu.duration.value-bygone.ies5Stu.duration.value;
  2116. //停留时长排名上升下降
  2117. x.ies5Stu.duration.updown=-(x.ies5Stu.duration.rank - bygone.ies5Stu.duration.rank);
  2118. //访问指数上升下降
  2119. x.ies5Stu.stick.range=x.ies5Stu.stick.value-bygone.ies5Stu.stick.value;
  2120. //访问指数排名上升下降
  2121. x.ies5Stu.stick.updown=-(x.ies5Stu.stick.rank - bygone.ies5Stu.stick.rank);
  2122. #endregion
  2123. }
  2124. else
  2125. {
  2126. #region tmd
  2127. //人数上升下降
  2128. x.student.userUpdown= x.student.userCount;
  2129. //访问数量上升下降
  2130. x.student.count.range= x.student.count.value;
  2131. //访问数量排名上升下降
  2132. x.student.count.updown= x.student.count.rank;
  2133. //停留时长上升下降
  2134. x.student.duration.range=x.student.duration.value;
  2135. //停留时长排名上升下降
  2136. x.student.duration.updown=x.student.duration.rank;
  2137. //访问指数上升下降
  2138. x.student.stick.range=x.student.stick.value;
  2139. //访问指数排名上升下降
  2140. x.student.stick.updown=x.student.stick.rank;
  2141. #endregion
  2142. #region otherStu
  2143. //人数上升下降
  2144. x.otherStu.userUpdown= x.otherStu.userCount;
  2145. //访问数量上升下降
  2146. x.otherStu.count.range= x.otherStu.count.value;
  2147. //访问数量排名上升下降
  2148. x.otherStu.count.updown= x.otherStu.count.rank;
  2149. //停留时长上升下降
  2150. x.otherStu.duration.range=x.otherStu.duration.value;
  2151. //停留时长排名上升下降
  2152. x.otherStu.duration.updown=x.otherStu.duration.rank;
  2153. //访问指数上升下降
  2154. x.otherStu.stick.range=x.otherStu.stick.value;
  2155. //访问指数排名上升下降
  2156. x.otherStu.stick.updown=x.otherStu.stick.rank;
  2157. #endregion
  2158. #region ies5Stu
  2159. //人数上升下降
  2160. x.ies5Stu.userUpdown= x.ies5Stu.userCount;
  2161. //访问数量上升下降
  2162. x.ies5Stu.count.range= x.ies5Stu.count.value;
  2163. //访问数量排名上升下降
  2164. x.ies5Stu.count.updown= x.ies5Stu.count.rank;
  2165. //停留时长上升下降
  2166. x.ies5Stu.duration.range=x.ies5Stu.duration.value;
  2167. //停留时长排名上升下降
  2168. x.ies5Stu.duration.updown=x.ies5Stu.duration.rank;
  2169. //访问指数上升下降
  2170. x.ies5Stu.stick.range=x.ies5Stu.stick.value;
  2171. //访问指数排名上升下降
  2172. x.ies5Stu.stick.updown=x.ies5Stu.stick.rank;
  2173. #endregion
  2174. }
  2175. });
  2176. //当前时间没有的
  2177. var disappears = bygoneStickiness?.Where(x => x.student.stick.value!=0).ExceptBy(currentStickiness.Select(x => x.id), y => y.id);
  2178. if (disappears!=null && disappears.Count()>0)
  2179. {
  2180. double rank_tmd_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.student.stick.rank).Max() : 0;
  2181. double rank_tmd_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.student.count.rank).Max() : 0;
  2182. double rank_tmd_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.student.duration.rank).Max() : 0;
  2183. double rank_ies5Stu_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.ies5Stu.stick.rank).Max() : 0;
  2184. double rank_ies5Stu_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.ies5Stu.count.rank).Max() : 0;
  2185. double rank_ies5Stu_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.ies5Stu.duration.rank).Max() : 0;
  2186. double rank_otherStu_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.otherStu.stick.rank).Max() : 0;
  2187. double rank_otherStu_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.otherStu.count.rank).Max() : 0;
  2188. double rank_otherStu_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.otherStu.duration.rank).Max() : 0;
  2189. foreach (var disappear in disappears)
  2190. {
  2191. //下降
  2192. // y 5 t0
  2193. disappear.student.stick.updown= -disappear.student.stick.rank;
  2194. disappear.student.stick.range= -disappear.student.stick.value;
  2195. disappear.student.stick.value=0;
  2196. disappear.student.stick.rank=rank_tmd_stick_Max+1;
  2197. disappear.ies5Stu.stick.updown= -disappear.ies5Stu.stick.rank;
  2198. disappear.ies5Stu.stick.range= -disappear.ies5Stu.stick.value;
  2199. disappear.ies5Stu.stick.value=0;
  2200. disappear.ies5Stu.stick.rank=rank_ies5Stu_stick_Max+1;
  2201. disappear.otherStu.stick.updown= -disappear.otherStu.stick.rank;
  2202. disappear.otherStu.stick.range= -disappear.otherStu.stick.value;
  2203. disappear.otherStu.stick.value=0;
  2204. disappear.otherStu.stick.rank=rank_otherStu_stick_Max+1;
  2205. disappear.student.count.updown= -disappear.student.count.rank;
  2206. disappear.student.count.range= -disappear.student.count.value;
  2207. disappear.student.count.value=0;
  2208. disappear.student.count.rank=rank_tmd_count_Max+1;
  2209. disappear.ies5Stu.count.updown= -disappear.ies5Stu.count.rank;
  2210. disappear.ies5Stu.count.range= -disappear.ies5Stu.count.value;
  2211. disappear.ies5Stu.count.value=0;
  2212. disappear.ies5Stu.count.rank=rank_ies5Stu_count_Max+1;
  2213. disappear.otherStu.count.updown= -disappear.otherStu.count.rank;
  2214. disappear.otherStu.count.range= -disappear.otherStu.count.value;
  2215. disappear.otherStu.count.value=0;
  2216. disappear.otherStu.count.rank=rank_otherStu_count_Max+1;
  2217. disappear.student.duration.updown= -disappear.student.duration.rank;
  2218. disappear.student.duration.range= -disappear.student.duration.value;
  2219. disappear.student.duration.value=0;
  2220. disappear.student.duration.rank=rank_tmd_duration_Max+1;
  2221. disappear.ies5Stu.duration.updown= -disappear.ies5Stu.duration.rank;
  2222. disappear.ies5Stu.duration.range= -disappear.ies5Stu.duration.value;
  2223. disappear.ies5Stu.duration.value=0;
  2224. disappear.ies5Stu.duration.rank=rank_ies5Stu_duration_Max+1;
  2225. disappear.otherStu.duration.updown= -disappear.otherStu.duration.rank;
  2226. disappear.otherStu.duration.range= -disappear.otherStu.duration.value;
  2227. disappear.otherStu.duration.value=0;
  2228. disappear.otherStu.duration.rank=rank_otherStu_duration_Max+1;
  2229. currentStickiness.Add(disappear);
  2230. }
  2231. }
  2232. currentStickiness= currentStickiness.OrderByDescending(x => x.student.stick.value).ToList();
  2233. return currentStickiness;
  2234. }
  2235. private static List<TchStick> OrderByTchStick(List<TchStick> currentStickiness, List<TchStick>? bygoneStickiness)
  2236. {
  2237. // 假设visit已经填充了数据
  2238. #region
  2239. var rank_tmd_count = currentStickiness.Select(x => x.teacher.count.value).Distinct().OrderByDescending(v => v).ToList();
  2240. var rank_hita_count = currentStickiness.Select(x => x.hita.count.value).Distinct().OrderByDescending(v => v).ToList();
  2241. var rank_hiteach_count = currentStickiness.Select(x => x.hiteach.count.value).Distinct().OrderByDescending(v => v).ToList();
  2242. var rank_ies5Tch_count = currentStickiness.Select(x => x.ies5Tch.count.value).Distinct().OrderByDescending(v => v).ToList();
  2243. var rank_otherTch_count = currentStickiness.Select(x => x.otherTch.count.value).Distinct().OrderByDescending(v => v).ToList();
  2244. var rank_lesson_count = currentStickiness.Select(x => x.lesson.value).Distinct().OrderByDescending(v => v).ToList();
  2245. #endregion
  2246. #region
  2247. var rank_tmd_duration = currentStickiness.Select(x => x.teacher.duration.value).Distinct().OrderByDescending(v => v).ToList();
  2248. var rank_hita_duration = currentStickiness.Select(x => x.hita.duration.value).Distinct().OrderByDescending(v => v).ToList();
  2249. var rank_hiteach_duration = currentStickiness.Select(x => x.hiteach.duration.value).Distinct().OrderByDescending(v => v).ToList();
  2250. var rank_ies5Tch_duration = currentStickiness.Select(x => x.ies5Tch.duration.value).Distinct().OrderByDescending(v => v).ToList();
  2251. var rank_otherTch_duration = currentStickiness.Select(x => x.otherTch.duration.value).Distinct().OrderByDescending(v => v).ToList();
  2252. #endregion
  2253. #region
  2254. var rank_tmd_stick = currentStickiness.Select(x => x.teacher.stick.value).Distinct().OrderByDescending(v => v).ToList();
  2255. var rank_hita_stick = currentStickiness.Select(x => x.hita.stick.value).Distinct().OrderByDescending(v => v).ToList();
  2256. var rank_hiteach_stick = currentStickiness.Select(x => x.hiteach.stick.value).Distinct().OrderByDescending(v => v).ToList();
  2257. var rank_ies5Tch_stick = currentStickiness.Select(x => x.ies5Tch.stick.value).Distinct().OrderByDescending(v => v).ToList();
  2258. var rank_otherTch_stick = currentStickiness.Select(x => x.otherTch.stick.value).Distinct().OrderByDescending(v => v).ToList();
  2259. #endregion
  2260. currentStickiness.ForEach(x =>
  2261. {
  2262. #region
  2263. int index_tmd_count = rank_tmd_count.FindIndex(i => i==x.teacher.count.value);
  2264. if (index_tmd_count!=-1)
  2265. {
  2266. x.teacher.count.rank = index_tmd_count + 1;
  2267. }
  2268. int index_hita_count = rank_hita_count.FindIndex(i => i==x.hita.count.value);
  2269. if (index_hita_count!=-1)
  2270. {
  2271. x.hita.count.rank = index_hita_count + 1;
  2272. }
  2273. int index_hiteach_count = rank_hiteach_count.FindIndex(i => i==x.hiteach.count.value);
  2274. if (index_hiteach_count!=-1)
  2275. {
  2276. x.hiteach.count.rank = index_hiteach_count + 1;
  2277. }
  2278. int index_ies5Tch_count = rank_ies5Tch_count.FindIndex(i => i==x.ies5Tch.count.value);
  2279. if (index_ies5Tch_count!=-1)
  2280. {
  2281. x.ies5Tch.count.rank = index_ies5Tch_count + 1;
  2282. }
  2283. int index_otherTch_count = rank_otherTch_count.FindIndex(i => i==x.otherTch.count.value);
  2284. if (index_otherTch_count!=-1)
  2285. {
  2286. x.otherTch.count.rank = index_otherTch_count + 1;
  2287. }
  2288. int index_lesson_count = rank_lesson_count.FindIndex(i => i==x.lesson.value);
  2289. if (index_lesson_count!=-1)
  2290. {
  2291. x.lesson.rank = index_lesson_count + 1;
  2292. }
  2293. #endregion
  2294. #region
  2295. int index_tmd_duration = rank_tmd_duration.FindIndex(i => i==x.teacher.duration.value);
  2296. if (index_tmd_duration!=-1)
  2297. {
  2298. x.teacher.duration.rank = index_tmd_duration + 1;
  2299. }
  2300. int index_hita_duration = rank_hita_duration.FindIndex(i => i==x.hita.duration.value);
  2301. if (index_hita_duration!=-1)
  2302. {
  2303. x.hita.duration.rank = index_hita_duration + 1;
  2304. }
  2305. int index_hiteach_duration = rank_hiteach_duration.FindIndex(i => i==x.hiteach.duration.value);
  2306. if (index_hiteach_duration!=-1)
  2307. {
  2308. x.hiteach.duration.rank = index_hiteach_duration + 1;
  2309. }
  2310. int index_ies5Tch_duration = rank_ies5Tch_duration.FindIndex(i => i==x.ies5Tch.duration.value);
  2311. if (index_ies5Tch_duration!=-1)
  2312. {
  2313. x.ies5Tch.duration.rank = index_ies5Tch_duration + 1;
  2314. }
  2315. int index_otherTch_duration = rank_otherTch_duration.FindIndex(i => i==x.otherTch.duration.value);
  2316. if (index_otherTch_duration!=-1)
  2317. {
  2318. x.otherTch.duration.rank = index_otherTch_duration + 1;
  2319. }
  2320. #endregion
  2321. #region
  2322. int index_tmd_stick = rank_tmd_stick.FindIndex(i => i==x.teacher.stick.value);
  2323. if (index_tmd_stick!=-1)
  2324. {
  2325. x.teacher.stick.rank = index_tmd_stick + 1;
  2326. }
  2327. int index_hita_stick = rank_hita_stick.FindIndex(i => i==x.hita.stick.value);
  2328. if (index_hita_stick!=-1)
  2329. {
  2330. x.hita.stick.rank = index_hita_stick + 1;
  2331. }
  2332. int index_hiteach_stick = rank_hiteach_stick.FindIndex(i => i==x.hiteach.stick.value);
  2333. if (index_hiteach_stick!=-1)
  2334. {
  2335. x.hiteach.stick.rank = index_hiteach_stick + 1;
  2336. }
  2337. int index_ies5Tch_stick = rank_ies5Tch_stick.FindIndex(i => i==x.ies5Tch.stick.value);
  2338. if (index_ies5Tch_stick!=-1)
  2339. {
  2340. x.ies5Tch.stick.rank = index_ies5Tch_stick + 1;
  2341. }
  2342. int index_otherTch_stick = rank_otherTch_stick.FindIndex(i => i==x.otherTch.stick.value);
  2343. if (index_otherTch_stick!=-1)
  2344. {
  2345. x.otherTch.stick.rank = index_otherTch_stick + 1;
  2346. }
  2347. #endregion
  2348. var bygone = bygoneStickiness?.Find(y => y.id.Equals(x.id));
  2349. if (bygone!=null)
  2350. {
  2351. #region
  2352. x.lesson.range=x.lesson.value-bygone.lesson.value;
  2353. x.lesson.updown=x.lesson.rank-bygone.lesson.rank;
  2354. #endregion
  2355. #region tmd
  2356. //人数上升下降
  2357. x.teacher.userUpdown= x.teacher.userCount-bygone.teacher.userCount;
  2358. //访问数量上升下降
  2359. x.teacher.count.range= x.teacher.count.value-bygone.teacher.count.value;
  2360. //访问数量排名上升下降
  2361. x.teacher.count.updown= -(x.teacher.count.rank - bygone.teacher.count.rank);
  2362. //停留时长上升下降
  2363. x.teacher.duration.range=x.teacher.duration.value-bygone.teacher.duration.value;
  2364. //停留时长排名上升下降
  2365. x.teacher.duration.updown=-(x.teacher.duration.rank - bygone.teacher.duration.rank);
  2366. //访问指数上升下降
  2367. x.teacher.stick.range=x.teacher.stick.value-bygone.teacher.stick.value;
  2368. //访问指数排名上升下降
  2369. x.teacher.stick.updown=-(x.teacher.stick.rank - bygone.teacher.stick.rank);
  2370. #endregion
  2371. #region hita
  2372. //人数上升下降
  2373. x.hita.userUpdown= x.hita.userCount-bygone.hita.userCount;
  2374. //访问数量上升下降
  2375. x.hita.count.range= x.hita.count.value-bygone.hita.count.value;
  2376. //访问数量排名上升下降
  2377. x.hita.count.updown= -(x.hita.count.rank - bygone.hita.count.rank);
  2378. //停留时长上升下降
  2379. x.hita.duration.range=x.hita.duration.value-bygone.hita.duration.value;
  2380. //停留时长排名上升下降
  2381. x.hita.duration.updown=-(x.hita.duration.rank - bygone.hita.duration.rank);
  2382. //访问指数上升下降
  2383. x.hita.stick.range=x.hita.stick.value-bygone.hita.stick.value;
  2384. //访问指数排名上升下降
  2385. x.hita.stick.updown=-(x.hita.stick.rank - bygone.hita.stick.rank);
  2386. #endregion
  2387. #region hiteach
  2388. //人数上升下降
  2389. x.hiteach.userUpdown= x.hiteach.userCount-bygone.hiteach.userCount;
  2390. //访问数量上升下降
  2391. x.hiteach.count.range= x.hiteach.count.value-bygone.hiteach.count.value;
  2392. //访问数量排名上升下降
  2393. x.hiteach.count.updown= -(x.hiteach.count.rank - bygone.hiteach.count.rank);
  2394. //停留时长上升下降
  2395. x.hiteach.duration.range=x.hiteach.duration.value-bygone.hiteach.duration.value;
  2396. //停留时长排名上升下降
  2397. x.hiteach.duration.updown=-(x.hiteach.duration.rank - bygone.hiteach.duration.rank);
  2398. //访问指数上升下降
  2399. x.hiteach.stick.range=x.hiteach.stick.value-bygone.hiteach.stick.value;
  2400. //访问指数排名上升下降
  2401. x.hiteach.stick.updown=-(x.hiteach.stick.rank - bygone.hiteach.stick.rank);
  2402. #endregion
  2403. #region otherTch
  2404. //人数上升下降
  2405. x.otherTch.userUpdown= x.otherTch.userCount-bygone.otherTch.userCount;
  2406. //访问数量上升下降
  2407. x.otherTch.count.range= x.otherTch.count.value-bygone.otherTch.count.value;
  2408. //访问数量排名上升下降
  2409. x.otherTch.count.updown= -(x.otherTch.count.rank - bygone.otherTch.count.rank);
  2410. //停留时长上升下降
  2411. x.otherTch.duration.range=x.otherTch.duration.value-bygone.otherTch.duration.value;
  2412. //停留时长排名上升下降
  2413. x.otherTch.duration.updown=-(x.otherTch.duration.rank - bygone.otherTch.duration.rank);
  2414. //访问指数上升下降
  2415. x.otherTch.stick.range=x.otherTch.stick.value-bygone.otherTch.stick.value;
  2416. //访问指数排名上升下降
  2417. x.otherTch.stick.updown=-(x.otherTch.stick.rank - bygone.otherTch.stick.rank);
  2418. #endregion
  2419. #region ies5Tch
  2420. //人数上升下降
  2421. x.ies5Tch.userUpdown= x.ies5Tch.userCount-bygone.ies5Tch.userCount;
  2422. //访问数量上升下降
  2423. x.ies5Tch.count.range= x.ies5Tch.count.value-bygone.ies5Tch.count.value;
  2424. //访问数量排名上升下降
  2425. x.ies5Tch.count.updown= -(x.ies5Tch.count.rank - bygone.ies5Tch.count.rank);
  2426. //停留时长上升下降
  2427. x.ies5Tch.duration.range=x.ies5Tch.duration.value-bygone.ies5Tch.duration.value;
  2428. //停留时长排名上升下降
  2429. x.ies5Tch.duration.updown=-(x.ies5Tch.duration.rank - bygone.ies5Tch.duration.rank);
  2430. //访问指数上升下降
  2431. x.ies5Tch.stick.range=x.ies5Tch.stick.value-bygone.ies5Tch.stick.value;
  2432. //访问指数排名上升下降
  2433. x.ies5Tch.stick.updown=-(x.ies5Tch.stick.rank - bygone.ies5Tch.stick.rank);
  2434. #endregion
  2435. }
  2436. else
  2437. {
  2438. #region
  2439. x.lesson.range=x.lesson.value;
  2440. x.lesson.updown=x.lesson.rank;
  2441. #endregion
  2442. #region tmd
  2443. //人数上升下降
  2444. x.teacher.userUpdown= x.teacher.userCount;
  2445. //访问数量上升下降
  2446. x.teacher.count.range= x.teacher.count.value;
  2447. //访问数量排名上升下降
  2448. x.teacher.count.updown= x.teacher.count.rank;
  2449. //停留时长上升下降
  2450. x.teacher.duration.range=x.teacher.duration.value;
  2451. //停留时长排名上升下降
  2452. x.teacher.duration.updown=x.teacher.duration.rank;
  2453. //访问指数上升下降
  2454. x.teacher.stick.range=x.teacher.stick.value;
  2455. //访问指数排名上升下降
  2456. x.teacher.stick.updown=x.teacher.stick.rank;
  2457. #endregion
  2458. #region hita
  2459. //人数上升下降
  2460. x.hita.userUpdown= x.hita.userCount;
  2461. //访问数量上升下降
  2462. x.hita.count.range= x.hita.count.value;
  2463. //访问数量排名上升下降
  2464. x.hita.count.updown= x.hita.count.rank;
  2465. //停留时长上升下降
  2466. x.hita.duration.range=x.hita.duration.value;
  2467. //停留时长排名上升下降
  2468. x.hita.duration.updown=x.hita.duration.rank;
  2469. //访问指数上升下降
  2470. x.hita.stick.range=x.hita.stick.value;
  2471. //访问指数排名上升下降
  2472. x.hita.stick.updown=x.hita.stick.rank;
  2473. #endregion
  2474. #region hiteach
  2475. //人数上升下降
  2476. x.hiteach.userUpdown= x.hiteach.userCount;
  2477. //访问数量上升下降
  2478. x.hiteach.count.range= x.hiteach.count.value;
  2479. //访问数量排名上升下降
  2480. x.hiteach.count.updown= x.hiteach.count.rank;
  2481. //停留时长上升下降
  2482. x.hiteach.duration.range=x.hiteach.duration.value;
  2483. //停留时长排名上升下降
  2484. x.hiteach.duration.updown=x.hiteach.duration.rank;
  2485. //访问指数上升下降
  2486. x.hiteach.stick.range=x.hiteach.stick.value;
  2487. //访问指数排名上升下降
  2488. x.hiteach.stick.updown=x.hiteach.stick.rank;
  2489. #endregion
  2490. #region otherTch
  2491. //人数上升下降
  2492. x.otherTch.userUpdown= x.otherTch.userCount;
  2493. //访问数量上升下降
  2494. x.otherTch.count.range= x.otherTch.count.value;
  2495. //访问数量排名上升下降
  2496. x.otherTch.count.updown= x.otherTch.count.rank;
  2497. //停留时长上升下降
  2498. x.otherTch.duration.range=x.otherTch.duration.value;
  2499. //停留时长排名上升下降
  2500. x.otherTch.duration.updown=x.otherTch.duration.rank;
  2501. //访问指数上升下降
  2502. x.otherTch.stick.range=x.otherTch.stick.value;
  2503. //访问指数排名上升下降
  2504. x.otherTch.stick.updown=x.otherTch.stick.rank;
  2505. #endregion
  2506. #region ies5Tch
  2507. //人数上升下降
  2508. x.ies5Tch.userUpdown= x.ies5Tch.userCount;
  2509. //访问数量上升下降
  2510. x.ies5Tch.count.range= x.ies5Tch.count.value;
  2511. //访问数量排名上升下降
  2512. x.ies5Tch.count.updown= x.ies5Tch.count.rank;
  2513. //停留时长上升下降
  2514. x.ies5Tch.duration.range=x.ies5Tch.duration.value;
  2515. //停留时长排名上升下降
  2516. x.ies5Tch.duration.updown=x.ies5Tch.duration.rank;
  2517. //访问指数上升下降
  2518. x.ies5Tch.stick.range=x.ies5Tch.stick.value;
  2519. //访问指数排名上升下降
  2520. x.ies5Tch.stick.updown=x.ies5Tch.stick.rank;
  2521. #endregion
  2522. }
  2523. });
  2524. //当前时间没有的
  2525. var disappears = bygoneStickiness?.Where(x => x.teacher.stick.value!=0).ExceptBy(currentStickiness.Select(x => x.id), y => y.id);
  2526. if (disappears!=null && disappears.Count()>0)
  2527. {
  2528. double rank_tmd_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.teacher.stick.rank).Max() : 0;
  2529. double rank_tmd_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.teacher.count.rank).Max() : 0;
  2530. double rank_tmd_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.teacher.duration.rank).Max() : 0;
  2531. double rank_hiteach_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.hiteach.stick.rank).Max() : 0;
  2532. double rank_hiteach_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.hiteach.count.rank).Max() : 0;
  2533. double rank_hiteach_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.hiteach.duration.rank).Max() : 0;
  2534. double rank_hita_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.hita.stick.rank).Max() : 0;
  2535. double rank_hita_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.hita.count.rank).Max() : 0;
  2536. double rank_hita_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.hita.duration.rank).Max() : 0;
  2537. double rank_ies5Tch_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.ies5Tch.stick.rank).Max() : 0;
  2538. double rank_ies5Tch_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.ies5Tch.count.rank).Max() : 0;
  2539. double rank_ies5Tch_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.ies5Tch.duration.rank).Max() : 0;
  2540. double rank_otherTch_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.otherTch.stick.rank).Max() : 0;
  2541. double rank_otherTch_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.otherTch.count.rank).Max() : 0;
  2542. double rank_otherTch_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.otherTch.duration.rank).Max() : 0;
  2543. double rank_lesson_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.lesson.rank).Max() : 0;
  2544. foreach (var disappear in disappears)
  2545. {
  2546. disappear.lesson.updown=-disappear.lesson.rank;
  2547. disappear.lesson.range=-disappear.lesson.value;
  2548. disappear.lesson.value=0;
  2549. disappear.lesson.rank=rank_lesson_Max+1;
  2550. //下降
  2551. // y 5 t0
  2552. disappear.teacher.stick.updown= -disappear.teacher.stick.rank;
  2553. disappear.teacher.stick.range= -disappear.teacher.stick.value;
  2554. disappear.teacher.stick.value=0;
  2555. disappear.teacher.stick.rank=rank_tmd_stick_Max+1;
  2556. disappear.hiteach.stick.updown= -disappear.hiteach.stick.rank;
  2557. disappear.hiteach.stick.range= -disappear.hiteach.stick.value;
  2558. disappear.hiteach.stick.value=0;
  2559. disappear.hiteach.stick.rank=rank_hiteach_stick_Max+1;
  2560. disappear.hita.stick.updown= -disappear.hita.stick.rank;
  2561. disappear.hita.stick.range= -disappear.hita.stick.value;
  2562. disappear.hita.stick.value=0;
  2563. disappear.hita.stick.rank=rank_hita_stick_Max+1;
  2564. disappear.ies5Tch.stick.updown= -disappear.ies5Tch.stick.rank;
  2565. disappear.ies5Tch.stick.range= -disappear.ies5Tch.stick.value;
  2566. disappear.ies5Tch.stick.value=0;
  2567. disappear.ies5Tch.stick.rank=rank_ies5Tch_stick_Max+1;
  2568. disappear.otherTch.stick.updown= -disappear.otherTch.stick.rank;
  2569. disappear.otherTch.stick.range= -disappear.otherTch.stick.value;
  2570. disappear.otherTch.stick.value=0;
  2571. disappear.otherTch.stick.rank=rank_otherTch_stick_Max+1;
  2572. disappear.teacher.count.updown= -disappear.teacher.count.rank;
  2573. disappear.teacher.count.range= -disappear.teacher.count.value;
  2574. disappear.teacher.count.value=0;
  2575. disappear.teacher.count.rank=rank_tmd_count_Max+1;
  2576. disappear.hiteach.count.updown= -disappear.hiteach.count.rank;
  2577. disappear.hiteach.count.range= -disappear.hiteach.count.value;
  2578. disappear.hiteach.count.value=0;
  2579. disappear.hiteach.count.rank=rank_hiteach_count_Max+1;
  2580. disappear.hita.count.updown= -disappear.hita.count.rank;
  2581. disappear.hita.count.range= -disappear.hita.count.value;
  2582. disappear.hita.count.value=0;
  2583. disappear.hita.count.rank=rank_hita_count_Max+1;
  2584. disappear.ies5Tch.count.updown= -disappear.ies5Tch.count.rank;
  2585. disappear.ies5Tch.count.range= -disappear.ies5Tch.count.value;
  2586. disappear.ies5Tch.count.value=0;
  2587. disappear.ies5Tch.count.rank=rank_ies5Tch_count_Max+1;
  2588. disappear.otherTch.count.updown= -disappear.otherTch.count.rank;
  2589. disappear.otherTch.count.range= -disappear.otherTch.count.value;
  2590. disappear.otherTch.count.value=0;
  2591. disappear.otherTch.count.rank=rank_otherTch_count_Max+1;
  2592. disappear.teacher.duration.updown= -disappear.teacher.duration.rank;
  2593. disappear.teacher.duration.range= -disappear.teacher.duration.value;
  2594. disappear.teacher.duration.value=0;
  2595. disappear.teacher.duration.rank=rank_tmd_duration_Max+1;
  2596. disappear.hiteach.duration.updown= -disappear.hiteach.duration.rank;
  2597. disappear.hiteach.duration.range= -disappear.hiteach.duration.value;
  2598. disappear.hiteach.duration.value=0;
  2599. disappear.hiteach.duration.rank=rank_hiteach_duration_Max+1;
  2600. disappear.hita.duration.updown= -disappear.hita.duration.rank;
  2601. disappear.hita.duration.range= -disappear.hita.duration.value;
  2602. disappear.hita.duration.value=0;
  2603. disappear.hita.duration.rank=rank_hita_duration_Max+1;
  2604. disappear.ies5Tch.duration.updown= -disappear.ies5Tch.duration.rank;
  2605. disappear.ies5Tch.duration.range= -disappear.ies5Tch.duration.value;
  2606. disappear.ies5Tch.duration.value=0;
  2607. disappear.ies5Tch.duration.rank=rank_ies5Tch_duration_Max+1;
  2608. disappear.otherTch.duration.updown= -disappear.otherTch.duration.rank;
  2609. disappear.otherTch.duration.range= -disappear.otherTch.duration.value;
  2610. disappear.otherTch.duration.value=0;
  2611. disappear.otherTch.duration.rank=rank_otherTch_duration_Max+1;
  2612. currentStickiness.Add(disappear);
  2613. }
  2614. }
  2615. currentStickiness= currentStickiness.OrderByDescending(x => x.teacher.stick.value).ToList();
  2616. return currentStickiness;
  2617. }
  2618. /// <summary>
  2619. ///
  2620. /// </summary>
  2621. /// <param name="currentStickiness">现在的</param>
  2622. /// <param name="bygoneStickiness">过去的</param>
  2623. /// <returns></returns>
  2624. private static List<SchoolStick> OrderBySchoolStick(List<SchoolStick> currentStickiness, List<SchoolStick>? bygoneStickiness)
  2625. {
  2626. // 假设visit已经填充了数据
  2627. #region
  2628. var rank_teacher_count = currentStickiness.Select(x => x.teacher.count.value).Distinct().OrderByDescending(v => v).ToList();
  2629. var rank_student_count = currentStickiness.Select(x => x.student.count.value).Distinct().OrderByDescending(v => v).ToList();
  2630. var rank_hita_count = currentStickiness.Select(x => x.hita.count.value).Distinct().OrderByDescending(v => v).ToList();
  2631. var rank_hiteach_count = currentStickiness.Select(x => x.hiteach.count.value).Distinct().OrderByDescending(v => v).ToList();
  2632. var rank_ies5Tch_count = currentStickiness.Select(x => x.ies5Tch.count.value).Distinct().OrderByDescending(v => v).ToList();
  2633. var rank_otherTch_count = currentStickiness.Select(x => x.otherTch.count.value).Distinct().OrderByDescending(v => v).ToList();
  2634. var rank_ies5Stu_count = currentStickiness.Select(x => x.ies5Stu.count.value).Distinct().OrderByDescending(v => v).ToList();
  2635. var rank_otherStu_count = currentStickiness.Select(x => x.otherStu.count.value).Distinct().OrderByDescending(v => v).ToList();
  2636. var rank_lesson_count = currentStickiness.Select(x => x.lesson.value).Distinct().OrderByDescending(v => v).ToList();
  2637. #endregion
  2638. #region
  2639. var rank_teacher_duration = currentStickiness.Select(x => x.teacher.duration.value).Distinct().OrderByDescending(v => v).ToList();
  2640. var rank_student_duration = currentStickiness.Select(x => x.student.duration.value).Distinct().OrderByDescending(v => v).ToList();
  2641. var rank_hita_duration = currentStickiness.Select(x => x.hita.duration.value).Distinct().OrderByDescending(v => v).ToList();
  2642. var rank_hiteach_duration = currentStickiness.Select(x => x.hiteach.duration.value).Distinct().OrderByDescending(v => v).ToList();
  2643. var rank_ies5Tch_duration = currentStickiness.Select(x => x.ies5Tch.duration.value).Distinct().OrderByDescending(v => v).ToList();
  2644. var rank_otherTch_duration = currentStickiness.Select(x => x.otherTch.duration.value).Distinct().OrderByDescending(v => v).ToList();
  2645. var rank_ies5Stu_duration = currentStickiness.Select(x => x.ies5Stu.duration.value).Distinct().OrderByDescending(v => v).ToList();
  2646. var rank_otherStu_duration = currentStickiness.Select(x => x.otherStu.duration.value).Distinct().OrderByDescending(v => v).ToList();
  2647. #endregion
  2648. #region
  2649. var rank_teacher_stick = currentStickiness.Select(x => x.teacher.stick.value).Distinct().OrderByDescending(v => v).ToList();
  2650. var rank_student_stick = currentStickiness.Select(x => x.student.stick.value).Distinct().OrderByDescending(v => v).ToList();
  2651. var rank_hita_stick = currentStickiness.Select(x => x.hita.stick.value).Distinct().OrderByDescending(v => v).ToList();
  2652. var rank_hiteach_stick = currentStickiness.Select(x => x.hiteach.stick.value).Distinct().OrderByDescending(v => v).ToList();
  2653. var rank_ies5Tch_stick = currentStickiness.Select(x => x.ies5Tch.stick.value).Distinct().OrderByDescending(v => v).ToList();
  2654. var rank_otherTch_stick = currentStickiness.Select(x => x.otherTch.stick.value).Distinct().OrderByDescending(v => v).ToList();
  2655. var rank_ies5Stu_stick = currentStickiness.Select(x => x.ies5Stu.stick.value).Distinct().OrderByDescending(v => v).ToList();
  2656. var rank_otherStu_stick = currentStickiness.Select(x => x.otherStu.stick.value).Distinct().OrderByDescending(v => v).ToList();
  2657. #endregion
  2658. currentStickiness.ForEach(x =>
  2659. {
  2660. #region
  2661. if (x.teacher.count.value>0)
  2662. {
  2663. int index_teacher_count = rank_teacher_count.FindIndex(i => i==x.teacher.count.value);
  2664. if (index_teacher_count!=-1)
  2665. {
  2666. x.teacher.count.rank = index_teacher_count + 1;
  2667. }
  2668. }
  2669. if (x.student.count.value>0)
  2670. {
  2671. int index_student_count = rank_student_count.FindIndex(i => i==x.student.count.value);
  2672. if (index_student_count!=-1)
  2673. {
  2674. x.student.count.rank = index_student_count + 1;
  2675. }
  2676. }
  2677. if (x.hita.count.value>0)
  2678. {
  2679. int index_hita_count = rank_hita_count.FindIndex(i => i==x.hita.count.value);
  2680. if (index_hita_count!=-1)
  2681. {
  2682. x.hita.count.rank = index_hita_count + 1;
  2683. }
  2684. }
  2685. if (x.hiteach.count.value>0)
  2686. {
  2687. int index_hiteach_count = rank_hiteach_count.FindIndex(i => i==x.hiteach.count.value);
  2688. if (index_hiteach_count!=-1)
  2689. {
  2690. x.hiteach.count.rank = index_hiteach_count + 1;
  2691. }
  2692. }
  2693. if (x.ies5Tch.count.value>0)
  2694. {
  2695. int index_ies5Tch_count = rank_ies5Tch_count.FindIndex(i => i==x.ies5Tch.count.value);
  2696. if (index_ies5Tch_count!=-1)
  2697. {
  2698. x.ies5Tch.count.rank = index_ies5Tch_count + 1;
  2699. }
  2700. }
  2701. if (x.otherTch.count.value>0)
  2702. {
  2703. int index_otherTch_count = rank_otherTch_count.FindIndex(i => i==x.otherTch.count.value);
  2704. if (index_otherTch_count!=-1)
  2705. {
  2706. x.otherTch.count.rank = index_otherTch_count + 1;
  2707. }
  2708. }
  2709. if (x.ies5Stu.count.value>0)
  2710. {
  2711. int index_ies5Stu_count = rank_ies5Stu_count.FindIndex(i => i==x.ies5Stu.count.value);
  2712. if (index_ies5Stu_count!=-1)
  2713. {
  2714. x.ies5Stu.count.rank = index_ies5Stu_count + 1;
  2715. }
  2716. }
  2717. if (x.otherStu.count.value>0)
  2718. {
  2719. int index_otherStu_count = rank_otherStu_count.FindIndex(i => i==x.otherStu.count.value);
  2720. if (index_otherStu_count!=-1)
  2721. {
  2722. x.otherStu.count.rank = index_otherStu_count + 1;
  2723. }
  2724. }
  2725. if (x.lesson.value>0)
  2726. {
  2727. int index_lesson_count = rank_lesson_count.FindIndex(i => i==x.lesson.value);
  2728. if (index_lesson_count!=-1)
  2729. {
  2730. x.lesson.rank = index_lesson_count + 1;
  2731. }
  2732. }
  2733. #endregion
  2734. #region
  2735. if (x.teacher.duration.value>0)
  2736. {
  2737. int index_teacher_duration = rank_teacher_duration.FindIndex(i => i==x.teacher.duration.value);
  2738. if (index_teacher_duration!=-1)
  2739. {
  2740. x.teacher.duration.rank = index_teacher_duration + 1;
  2741. }
  2742. }
  2743. if (x.student.duration.value>0)
  2744. {
  2745. int index_student_duration = rank_student_duration.FindIndex(i => i==x.student.duration.value);
  2746. if (index_student_duration!=-1)
  2747. {
  2748. x.student.duration.rank = index_student_duration + 1;
  2749. }
  2750. }
  2751. if (x.hita.duration.value>0)
  2752. {
  2753. int index_hita_duration = rank_hita_duration.FindIndex(i => i==x.hita.duration.value);
  2754. if (index_hita_duration!=-1)
  2755. {
  2756. x.hita.duration.rank = index_hita_duration + 1;
  2757. }
  2758. }
  2759. if (x.hiteach.duration.value>0)
  2760. {
  2761. int index_hiteach_duration = rank_hiteach_duration.FindIndex(i => i==x.hiteach.duration.value);
  2762. if (index_hiteach_duration!=-1)
  2763. {
  2764. x.hiteach.duration.rank = index_hiteach_duration + 1;
  2765. }
  2766. }
  2767. if (x.ies5Tch.duration.value>0)
  2768. {
  2769. int index_ies5Tch_duration = rank_ies5Tch_duration.FindIndex(i => i==x.ies5Tch.duration.value);
  2770. if (index_ies5Tch_duration!=-1)
  2771. {
  2772. x.ies5Tch.duration.rank = index_ies5Tch_duration + 1;
  2773. }
  2774. }
  2775. if (x.otherTch.duration.value>0)
  2776. {
  2777. int index_otherTch_duration = rank_otherTch_duration.FindIndex(i => i==x.otherTch.duration.value);
  2778. if (index_otherTch_duration!=-1)
  2779. {
  2780. x.otherTch.duration.rank = index_otherTch_duration + 1;
  2781. }
  2782. }
  2783. if (x.ies5Stu.duration.value>0)
  2784. {
  2785. int index_ies5Stu_duration = rank_ies5Stu_duration.FindIndex(i => i==x.ies5Stu.duration.value);
  2786. if (index_ies5Stu_duration!=-1)
  2787. {
  2788. x.ies5Stu.duration.rank = index_ies5Stu_duration + 1;
  2789. }
  2790. }
  2791. if (x.otherStu.duration.value>0)
  2792. {
  2793. int index_otherStu_duration = rank_otherStu_duration.FindIndex(i => i==x.otherStu.duration.value);
  2794. if (index_otherStu_duration!=-1)
  2795. {
  2796. x.otherStu.duration.rank = index_otherStu_duration + 1;
  2797. }
  2798. }
  2799. #endregion
  2800. #region
  2801. if (x.teacher.stick.value>0)
  2802. {
  2803. int index_teacher_stick = rank_teacher_stick.FindIndex(i => i==x.teacher.stick.value);
  2804. if (index_teacher_stick!=-1)
  2805. {
  2806. x.teacher.stick.rank = index_teacher_stick + 1;
  2807. }
  2808. }
  2809. if (x.student.stick.value>0)
  2810. {
  2811. int index_student_stick = rank_student_stick.FindIndex(i => i==x.student.stick.value);
  2812. if (index_student_stick!=-1)
  2813. {
  2814. x.student.stick.rank = index_student_stick + 1;
  2815. }
  2816. }
  2817. if (x.hita.stick.value>0)
  2818. {
  2819. int index_hita_stick = rank_hita_stick.FindIndex(i => i==x.hita.stick.value);
  2820. if (index_hita_stick!=-1)
  2821. {
  2822. x.hita.stick.rank = index_hita_stick + 1;
  2823. }
  2824. }
  2825. if (x.hiteach.stick.value>0)
  2826. {
  2827. int index_hiteach_stick = rank_hiteach_stick.FindIndex(i => i==x.hiteach.stick.value);
  2828. if (index_hiteach_stick!=-1)
  2829. {
  2830. x.hiteach.stick.rank = index_hiteach_stick + 1;
  2831. }
  2832. }
  2833. if (x.ies5Tch.stick.value>0)
  2834. {
  2835. int index_ies5Tch_stick = rank_ies5Tch_stick.FindIndex(i => i==x.ies5Tch.stick.value);
  2836. if (index_ies5Tch_stick!=-1)
  2837. {
  2838. x.ies5Tch.stick.rank = index_ies5Tch_stick + 1;
  2839. }
  2840. }
  2841. if (x.otherTch.stick.value>0)
  2842. {
  2843. int index_otherTch_stick = rank_otherTch_stick.FindIndex(i => i==x.otherTch.stick.value);
  2844. if (index_otherTch_stick!=-1)
  2845. {
  2846. x.otherTch.stick.rank = index_otherTch_stick + 1;
  2847. }
  2848. }
  2849. if (x.ies5Stu.stick.value>0)
  2850. {
  2851. int index_ies5Stu_stick = rank_ies5Stu_stick.FindIndex(i => i==x.ies5Stu.stick.value);
  2852. if (index_ies5Stu_stick!=-1)
  2853. {
  2854. x.ies5Stu.stick.rank = index_ies5Stu_stick + 1;
  2855. }
  2856. }
  2857. if (x.otherStu.stick.value>0)
  2858. {
  2859. int index_otherStu_stick = rank_otherStu_stick.FindIndex(i => i==x.otherStu.stick.value);
  2860. if (index_otherStu_stick!=-1)
  2861. {
  2862. x.otherStu.stick.rank = index_otherStu_stick + 1;
  2863. }
  2864. }
  2865. #endregion
  2866. var bygone = bygoneStickiness?.Find(y => y.id.Equals(x.id));
  2867. if (bygone!=null)
  2868. {
  2869. #region
  2870. x.lesson.range=x.lesson.value-bygone.lesson.value;
  2871. x.lesson.updown=x.lesson.rank-bygone.lesson.rank;
  2872. #endregion
  2873. #region student
  2874. //人数上升下降
  2875. x.student.userUpdown= x.student.userCount-bygone.student.userCount;
  2876. //访问数量上升下降
  2877. x.student.count.range= x.student.count.value-bygone.student.count.value;
  2878. //访问数量排名上升下降
  2879. x.student.count.updown= -(x.student.count.rank - bygone.student.count.rank);
  2880. //停留时长上升下降
  2881. x.student.duration.range=x.student.duration.value-bygone.student.duration.value;
  2882. //停留时长排名上升下降
  2883. x.student.duration.updown=-(x.student.duration.rank - bygone.student.duration.rank);
  2884. //访问指数上升下降
  2885. x.student.stick.range=x.student.stick.value-bygone.student.stick.value;
  2886. //访问指数排名上升下降
  2887. x.student.stick.updown=-(x.student.stick.rank - bygone.student.stick.rank);
  2888. #endregion
  2889. #region teacher
  2890. //人数上升下降
  2891. x.teacher.userUpdown= x.teacher.userCount-bygone.teacher.userCount;
  2892. //访问数量上升下降
  2893. x.teacher.count.range= x.teacher.count.value-bygone.teacher.count.value;
  2894. //访问数量排名上升下降
  2895. x.teacher.count.updown= -(x.teacher.count.rank - bygone.teacher.count.rank);
  2896. //停留时长上升下降
  2897. x.teacher.duration.range=x.teacher.duration.value-bygone.teacher.duration.value;
  2898. //停留时长排名上升下降
  2899. x.teacher.duration.updown=-(x.teacher.duration.rank - bygone.teacher.duration.rank);
  2900. //访问指数上升下降
  2901. x.teacher.stick.range=x.teacher.stick.value-bygone.teacher.stick.value;
  2902. //访问指数排名上升下降
  2903. x.teacher.stick.updown=-(x.teacher.stick.rank - bygone.teacher.stick.rank);
  2904. #endregion
  2905. #region hita
  2906. //人数上升下降
  2907. x.hita.userUpdown= x.hita.userCount-bygone.hita.userCount;
  2908. //访问数量上升下降
  2909. x.hita.count.range= x.hita.count.value-bygone.hita.count.value;
  2910. //访问数量排名上升下降
  2911. x.hita.count.updown= -(x.hita.count.rank - bygone.hita.count.rank);
  2912. //停留时长上升下降
  2913. x.hita.duration.range=x.hita.duration.value-bygone.hita.duration.value;
  2914. //停留时长排名上升下降
  2915. x.hita.duration.updown=-(x.hita.duration.rank - bygone.hita.duration.rank);
  2916. //访问指数上升下降
  2917. x.hita.stick.range=x.hita.stick.value-bygone.hita.stick.value;
  2918. //访问指数排名上升下降
  2919. x.hita.stick.updown=-(x.hita.stick.rank - bygone.hita.stick.rank);
  2920. #endregion
  2921. #region hiteach
  2922. //人数上升下降
  2923. x.hiteach.userUpdown= x.hiteach.userCount-bygone.hiteach.userCount;
  2924. //访问数量上升下降
  2925. x.hiteach.count.range= x.hiteach.count.value-bygone.hiteach.count.value;
  2926. //访问数量排名上升下降
  2927. x.hiteach.count.updown= -(x.hiteach.count.rank - bygone.hiteach.count.rank);
  2928. //停留时长上升下降
  2929. x.hiteach.duration.range=x.hiteach.duration.value-bygone.hiteach.duration.value;
  2930. //停留时长排名上升下降
  2931. x.hiteach.duration.updown=-(x.hiteach.duration.rank - bygone.hiteach.duration.rank);
  2932. //访问指数上升下降
  2933. x.hiteach.stick.range=x.hiteach.stick.value-bygone.hiteach.stick.value;
  2934. //访问指数排名上升下降
  2935. x.hiteach.stick.updown=-(x.hiteach.stick.rank - bygone.hiteach.stick.rank);
  2936. #endregion
  2937. #region otherTch
  2938. //人数上升下降
  2939. x.otherTch.userUpdown= x.otherTch.userCount-bygone.otherTch.userCount;
  2940. //访问数量上升下降
  2941. x.otherTch.count.range= x.otherTch.count.value-bygone.otherTch.count.value;
  2942. //访问数量排名上升下降
  2943. x.otherTch.count.updown= -(x.otherTch.count.rank - bygone.otherTch.count.rank);
  2944. //停留时长上升下降
  2945. x.otherTch.duration.range=x.otherTch.duration.value-bygone.otherTch.duration.value;
  2946. //停留时长排名上升下降
  2947. x.otherTch.duration.updown=-(x.otherTch.duration.rank - bygone.otherTch.duration.rank);
  2948. //访问指数上升下降
  2949. x.otherTch.stick.range=x.otherTch.stick.value-bygone.otherTch.stick.value;
  2950. //访问指数排名上升下降
  2951. x.otherTch.stick.updown=-(x.otherTch.stick.rank - bygone.otherTch.stick.rank);
  2952. #endregion
  2953. #region otherStu
  2954. //人数上升下降
  2955. x.otherStu.userUpdown= x.otherStu.userCount-bygone.otherStu.userCount;
  2956. //访问数量上升下降
  2957. x.otherStu.count.range= x.otherStu.count.value-bygone.otherStu.count.value;
  2958. //访问数量排名上升下降
  2959. x.otherStu.count.updown= -(x.otherStu.count.rank - bygone.otherStu.count.rank);
  2960. //停留时长上升下降
  2961. x.otherStu.duration.range=x.otherStu.duration.value-bygone.otherStu.duration.value;
  2962. //停留时长排名上升下降
  2963. x.otherStu.duration.updown=-(x.otherStu.duration.rank - bygone.otherStu.duration.rank);
  2964. //访问指数上升下降
  2965. x.otherStu.stick.range=x.otherStu.stick.value-bygone.otherStu.stick.value;
  2966. //访问指数排名上升下降
  2967. x.otherStu.stick.updown=-(x.otherStu.stick.rank - bygone.otherStu.stick.rank);
  2968. #endregion
  2969. #region ies5Stu
  2970. //人数上升下降
  2971. x.ies5Stu.userUpdown= x.ies5Stu.userCount-bygone.ies5Stu.userCount;
  2972. //访问数量上升下降
  2973. x.ies5Stu.count.range= x.ies5Stu.count.value-bygone.ies5Stu.count.value;
  2974. //访问数量排名上升下降
  2975. x.ies5Stu.count.updown= -(x.ies5Stu.count.rank - bygone.ies5Stu.count.rank);
  2976. //停留时长上升下降
  2977. x.ies5Stu.duration.range=x.ies5Stu.duration.value-bygone.ies5Stu.duration.value;
  2978. //停留时长排名上升下降
  2979. x.ies5Stu.duration.updown=-(x.ies5Stu.duration.rank - bygone.ies5Stu.duration.rank);
  2980. //访问指数上升下降
  2981. x.ies5Stu.stick.range=x.ies5Stu.stick.value-bygone.ies5Stu.stick.value;
  2982. //访问指数排名上升下降
  2983. x.ies5Stu.stick.updown=-(x.ies5Stu.stick.rank - bygone.ies5Stu.stick.rank);
  2984. #endregion
  2985. #region ies5Tch
  2986. //人数上升下降
  2987. x.ies5Tch.userUpdown= x.ies5Tch.userCount-bygone.ies5Tch.userCount;
  2988. //访问数量上升下降
  2989. x.ies5Tch.count.range= x.ies5Tch.count.value-bygone.ies5Tch.count.value;
  2990. //访问数量排名上升下降
  2991. x.ies5Tch.count.updown= -(x.ies5Tch.count.rank - bygone.ies5Tch.count.rank);
  2992. //停留时长上升下降
  2993. x.ies5Tch.duration.range=x.ies5Tch.duration.value-bygone.ies5Tch.duration.value;
  2994. //停留时长排名上升下降
  2995. x.ies5Tch.duration.updown=-(x.ies5Tch.duration.rank - bygone.ies5Tch.duration.rank);
  2996. //访问指数上升下降
  2997. x.ies5Tch.stick.range=x.ies5Tch.stick.value-bygone.ies5Tch.stick.value;
  2998. //访问指数排名上升下降
  2999. x.ies5Tch.stick.updown=-(x.ies5Tch.stick.rank - bygone.ies5Tch.stick.rank);
  3000. #endregion
  3001. }
  3002. else
  3003. {
  3004. #region
  3005. x.lesson.range=x.lesson.value;
  3006. x.lesson.updown=x.lesson.rank;
  3007. #endregion
  3008. #region teacher
  3009. //人数上升下降
  3010. x.teacher.userUpdown= x.teacher.userCount;
  3011. //访问数量上升下降
  3012. x.teacher.count.range= x.teacher.count.value;
  3013. //访问数量排名上升下降
  3014. x.teacher.count.updown= x.teacher.count.rank;
  3015. //停留时长上升下降
  3016. x.teacher.duration.range=x.teacher.duration.value;
  3017. //停留时长排名上升下降
  3018. x.teacher.duration.updown=x.teacher.duration.rank;
  3019. //访问指数上升下降
  3020. x.teacher.stick.range=x.teacher.stick.value;
  3021. //访问指数排名上升下降
  3022. x.teacher.stick.updown=x.teacher.stick.rank;
  3023. #endregion
  3024. #region student
  3025. //人数上升下降
  3026. x.student.userUpdown= x.student.userCount;
  3027. //访问数量上升下降
  3028. x.student.count.range= x.student.count.value;
  3029. //访问数量排名上升下降
  3030. x.student.count.updown= x.student.count.rank;
  3031. //停留时长上升下降
  3032. x.student.duration.range=x.student.duration.value;
  3033. //停留时长排名上升下降
  3034. x.student.duration.updown=x.student.duration.rank;
  3035. //访问指数上升下降
  3036. x.student.stick.range=x.student.stick.value;
  3037. //访问指数排名上升下降
  3038. x.student.stick.updown=x.student.stick.rank;
  3039. #endregion
  3040. #region hita
  3041. //人数上升下降
  3042. x.hita.userUpdown= x.hita.userCount;
  3043. //访问数量上升下降
  3044. x.hita.count.range= x.hita.count.value;
  3045. //访问数量排名上升下降
  3046. x.hita.count.updown= x.hita.count.rank;
  3047. //停留时长上升下降
  3048. x.hita.duration.range=x.hita.duration.value;
  3049. //停留时长排名上升下降
  3050. x.hita.duration.updown=x.hita.duration.rank;
  3051. //访问指数上升下降
  3052. x.hita.stick.range=x.hita.stick.value;
  3053. //访问指数排名上升下降
  3054. x.hita.stick.updown=x.hita.stick.rank;
  3055. #endregion
  3056. #region hiteach
  3057. //人数上升下降
  3058. x.hiteach.userUpdown= x.hiteach.userCount;
  3059. //访问数量上升下降
  3060. x.hiteach.count.range= x.hiteach.count.value;
  3061. //访问数量排名上升下降
  3062. x.hiteach.count.updown= x.hiteach.count.rank;
  3063. //停留时长上升下降
  3064. x.hiteach.duration.range=x.hiteach.duration.value;
  3065. //停留时长排名上升下降
  3066. x.hiteach.duration.updown=x.hiteach.duration.rank;
  3067. //访问指数上升下降
  3068. x.hiteach.stick.range=x.hiteach.stick.value;
  3069. //访问指数排名上升下降
  3070. x.hiteach.stick.updown=x.hiteach.stick.rank;
  3071. #endregion
  3072. #region otherTch
  3073. //人数上升下降
  3074. x.otherTch.userUpdown= x.otherTch.userCount;
  3075. //访问数量上升下降
  3076. x.otherTch.count.range= x.otherTch.count.value;
  3077. //访问数量排名上升下降
  3078. x.otherTch.count.updown= x.otherTch.count.rank;
  3079. //停留时长上升下降
  3080. x.otherTch.duration.range=x.otherTch.duration.value;
  3081. //停留时长排名上升下降
  3082. x.otherTch.duration.updown=x.otherTch.duration.rank;
  3083. //访问指数上升下降
  3084. x.otherTch.stick.range=x.otherTch.stick.value;
  3085. //访问指数排名上升下降
  3086. x.otherTch.stick.updown=x.otherTch.stick.rank;
  3087. #endregion
  3088. #region otherStu
  3089. //人数上升下降
  3090. x.otherStu.userUpdown= x.otherStu.userCount;
  3091. //访问数量上升下降
  3092. x.otherStu.count.range= x.otherStu.count.value;
  3093. //访问数量排名上升下降
  3094. x.otherStu.count.updown= x.otherStu.count.rank;
  3095. //停留时长上升下降
  3096. x.otherStu.duration.range=x.otherStu.duration.value;
  3097. //停留时长排名上升下降
  3098. x.otherStu.duration.updown=x.otherStu.duration.rank;
  3099. //访问指数上升下降
  3100. x.otherStu.stick.range=x.otherStu.stick.value;
  3101. //访问指数排名上升下降
  3102. x.otherStu.stick.updown=x.otherStu.stick.rank;
  3103. #endregion
  3104. #region ies5Stu
  3105. //人数上升下降
  3106. x.ies5Stu.userUpdown= x.ies5Stu.userCount;
  3107. //访问数量上升下降
  3108. x.ies5Stu.count.range= x.ies5Stu.count.value;
  3109. //访问数量排名上升下降
  3110. x.ies5Stu.count.updown= x.ies5Stu.count.rank;
  3111. //停留时长上升下降
  3112. x.ies5Stu.duration.range=x.ies5Stu.duration.value;
  3113. //停留时长排名上升下降
  3114. x.ies5Stu.duration.updown=x.ies5Stu.duration.rank;
  3115. //访问指数上升下降
  3116. x.ies5Stu.stick.range=x.ies5Stu.stick.value;
  3117. //访问指数排名上升下降
  3118. x.ies5Stu.stick.updown=x.ies5Stu.stick.rank;
  3119. #endregion
  3120. #region ies5Tch
  3121. //人数上升下降
  3122. x.ies5Tch.userUpdown= x.ies5Tch.userCount;
  3123. //访问数量上升下降
  3124. x.ies5Tch.count.range= x.ies5Tch.count.value;
  3125. //访问数量排名上升下降
  3126. x.ies5Tch.count.updown= x.ies5Tch.count.rank;
  3127. //停留时长上升下降
  3128. x.ies5Tch.duration.range=x.ies5Tch.duration.value;
  3129. //停留时长排名上升下降
  3130. x.ies5Tch.duration.updown=x.ies5Tch.duration.rank;
  3131. //访问指数上升下降
  3132. x.ies5Tch.stick.range=x.ies5Tch.stick.value;
  3133. //访问指数排名上升下降
  3134. x.ies5Tch.stick.updown=x.ies5Tch.stick.rank;
  3135. #endregion
  3136. }
  3137. });
  3138. //当前时间没有的
  3139. var disappears = bygoneStickiness?.Where(x => x.teacher.stick.value!=0).ExceptBy(currentStickiness.Select(x => x.id), y => y.id);
  3140. if (disappears!=null && disappears.Count()>0)
  3141. {
  3142. double rank_student_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.student.stick.rank).Max() : 0;
  3143. double rank_student_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.student.count.rank).Max() : 0;
  3144. double rank_student_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.student.duration.rank).Max() : 0;
  3145. double rank_teacher_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.teacher.stick.rank).Max() : 0;
  3146. double rank_teacher_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.teacher.count.rank).Max() : 0;
  3147. double rank_teacher_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.teacher.duration.rank).Max() : 0;
  3148. double rank_hiteach_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.hiteach.stick.rank).Max() : 0;
  3149. double rank_hiteach_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.hiteach.count.rank).Max() : 0;
  3150. double rank_hiteach_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.hiteach.duration.rank).Max() : 0;
  3151. double rank_hita_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.hita.stick.rank).Max() : 0;
  3152. double rank_hita_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.hita.count.rank).Max() : 0;
  3153. double rank_hita_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.hita.duration.rank).Max() : 0;
  3154. double rank_ies5Stu_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.ies5Stu.stick.rank).Max() : 0;
  3155. double rank_ies5Stu_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.ies5Stu.count.rank).Max() : 0;
  3156. double rank_ies5Stu_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.ies5Stu.duration.rank).Max() : 0;
  3157. double rank_ies5Tch_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.ies5Tch.stick.rank).Max() : 0;
  3158. double rank_ies5Tch_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.ies5Tch.count.rank).Max() : 0;
  3159. double rank_ies5Tch_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.ies5Tch.duration.rank).Max() : 0;
  3160. double rank_otherStu_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.otherStu.stick.rank).Max() : 0;
  3161. double rank_otherStu_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.otherStu.count.rank).Max() : 0;
  3162. double rank_otherStu_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.otherStu.duration.rank).Max() : 0;
  3163. double rank_otherTch_stick_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.otherTch.stick.rank).Max() : 0;
  3164. double rank_otherTch_count_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.otherTch.count.rank).Max() : 0;
  3165. double rank_otherTch_duration_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.otherTch.duration.rank).Max() : 0;
  3166. double rank_lesson_Max = currentStickiness.Count()>0 ? currentStickiness.Select(x => x.lesson.rank).Max() : 0;
  3167. foreach (var disappear in disappears)
  3168. {
  3169. disappear.lesson.updown=-disappear.lesson.rank;
  3170. disappear.lesson.range=-disappear.lesson.value;
  3171. disappear.lesson.value=0;
  3172. disappear.lesson.rank=rank_lesson_Max+1;
  3173. //下降
  3174. // y 5 t0
  3175. disappear.teacher.stick.updown= -disappear.teacher.stick.rank;
  3176. disappear.teacher.stick.range= -disappear.teacher.stick.value;
  3177. disappear.teacher.stick.value=0;
  3178. disappear.teacher.stick.rank=rank_teacher_stick_Max+1;
  3179. disappear.student.stick.updown= -disappear.student.stick.rank;
  3180. disappear.student.stick.range= -disappear.student.stick.value;
  3181. disappear.student.stick.value=0;
  3182. disappear.student.stick.rank=rank_student_stick_Max+1;
  3183. disappear.hiteach.stick.updown= -disappear.hiteach.stick.rank;
  3184. disappear.hiteach.stick.range= -disappear.hiteach.stick.value;
  3185. disappear.hiteach.stick.value=0;
  3186. disappear.hiteach.stick.rank=rank_hiteach_stick_Max+1;
  3187. disappear.hita.stick.updown= -disappear.hita.stick.rank;
  3188. disappear.hita.stick.range= -disappear.hita.stick.value;
  3189. disappear.hita.stick.value=0;
  3190. disappear.hita.stick.rank=rank_hita_stick_Max+1;
  3191. disappear.ies5Stu.stick.updown= -disappear.ies5Stu.stick.rank;
  3192. disappear.ies5Stu.stick.range= -disappear.ies5Stu.stick.value;
  3193. disappear.ies5Stu.stick.value=0;
  3194. disappear.ies5Stu.stick.rank=rank_ies5Stu_stick_Max+1;
  3195. disappear.ies5Tch.stick.updown= -disappear.ies5Tch.stick.rank;
  3196. disappear.ies5Tch.stick.range= -disappear.ies5Tch.stick.value;
  3197. disappear.ies5Tch.stick.value=0;
  3198. disappear.ies5Tch.stick.rank=rank_ies5Tch_stick_Max+1;
  3199. disappear.otherStu.stick.updown= -disappear.otherStu.stick.rank;
  3200. disappear.otherStu.stick.range= -disappear.otherStu.stick.value;
  3201. disappear.otherStu.stick.value=0;
  3202. disappear.otherStu.stick.rank=rank_otherStu_stick_Max+1;
  3203. disappear.otherTch.stick.updown= -disappear.otherTch.stick.rank;
  3204. disappear.otherTch.stick.range= -disappear.otherTch.stick.value;
  3205. disappear.otherTch.stick.value=0;
  3206. disappear.otherTch.stick.rank=rank_otherTch_stick_Max+1;
  3207. disappear.teacher.count.updown= -disappear.teacher.count.rank;
  3208. disappear.teacher.count.range= -disappear.teacher.count.value;
  3209. disappear.teacher.count.value=0;
  3210. disappear.teacher.count.rank=rank_teacher_count_Max+1;
  3211. disappear.student.count.updown= -disappear.student.count.rank;
  3212. disappear.student.count.range= -disappear.student.count.value;
  3213. disappear.student.count.value=0;
  3214. disappear.student.count.rank=rank_student_count_Max+1;
  3215. disappear.hiteach.count.updown= -disappear.hiteach.count.rank;
  3216. disappear.hiteach.count.range= -disappear.hiteach.count.value;
  3217. disappear.hiteach.count.value=0;
  3218. disappear.hiteach.count.rank=rank_hiteach_count_Max+1;
  3219. disappear.hita.count.updown= -disappear.hita.count.rank;
  3220. disappear.hita.count.range= -disappear.hita.count.value;
  3221. disappear.hita.count.value=0;
  3222. disappear.hita.count.rank=rank_hita_count_Max+1;
  3223. disappear.ies5Stu.count.updown= -disappear.ies5Stu.count.rank;
  3224. disappear.ies5Stu.count.range= -disappear.ies5Stu.count.value;
  3225. disappear.ies5Stu.count.value=0;
  3226. disappear.ies5Stu.count.rank=rank_ies5Stu_count_Max+1;
  3227. disappear.ies5Tch.count.updown= -disappear.ies5Tch.count.rank;
  3228. disappear.ies5Tch.count.range= -disappear.ies5Tch.count.value;
  3229. disappear.ies5Tch.count.value=0;
  3230. disappear.ies5Tch.count.rank=rank_ies5Tch_count_Max+1;
  3231. disappear.otherStu.count.updown= -disappear.otherStu.count.rank;
  3232. disappear.otherStu.count.range= -disappear.otherStu.count.value;
  3233. disappear.otherStu.count.value=0;
  3234. disappear.otherStu.count.rank=rank_otherStu_count_Max+1;
  3235. disappear.otherTch.count.updown= -disappear.otherTch.count.rank;
  3236. disappear.otherTch.count.range= -disappear.otherTch.count.value;
  3237. disappear.otherTch.count.value=0;
  3238. disappear.otherTch.count.rank=rank_otherTch_count_Max+1;
  3239. disappear.teacher.duration.updown= -disappear.teacher.duration.rank;
  3240. disappear.teacher.duration.range= -disappear.teacher.duration.value;
  3241. disappear.teacher.duration.value=0;
  3242. disappear.teacher.duration.rank=rank_teacher_duration_Max+1;
  3243. disappear.student.duration.updown= -disappear.student.duration.rank;
  3244. disappear.student.duration.range= -disappear.student.duration.value;
  3245. disappear.student.duration.value=0;
  3246. disappear.student.duration.rank=rank_student_duration_Max+1;
  3247. disappear.hiteach.duration.updown= -disappear.hiteach.duration.rank;
  3248. disappear.hiteach.duration.range= -disappear.hiteach.duration.value;
  3249. disappear.hiteach.duration.value=0;
  3250. disappear.hiteach.duration.rank=rank_hiteach_duration_Max+1;
  3251. disappear.hita.duration.updown= -disappear.hita.duration.rank;
  3252. disappear.hita.duration.range= -disappear.hita.duration.value;
  3253. disappear.hita.duration.value=0;
  3254. disappear.hita.duration.rank=rank_hita_duration_Max+1;
  3255. disappear.ies5Stu.duration.updown= -disappear.ies5Stu.duration.rank;
  3256. disappear.ies5Stu.duration.range= -disappear.ies5Stu.duration.value;
  3257. disappear.ies5Stu.duration.value=0;
  3258. disappear.ies5Stu.duration.rank=rank_ies5Stu_duration_Max+1;
  3259. disappear.ies5Tch.duration.updown= -disappear.ies5Tch.duration.rank;
  3260. disappear.ies5Tch.duration.range= -disappear.ies5Tch.duration.value;
  3261. disappear.ies5Tch.duration.value=0;
  3262. disappear.ies5Tch.duration.rank=rank_ies5Tch_duration_Max+1;
  3263. disappear.otherStu.duration.updown= -disappear.otherStu.duration.rank;
  3264. disappear.otherStu.duration.range= -disappear.otherStu.duration.value;
  3265. disappear.otherStu.duration.value=0;
  3266. disappear.otherStu.duration.rank=rank_otherStu_duration_Max+1;
  3267. disappear.otherTch.duration.updown= -disappear.otherTch.duration.rank;
  3268. disappear.otherTch.duration.range= -disappear.otherTch.duration.value;
  3269. disappear.otherTch.duration.value=0;
  3270. disappear.otherTch.duration.rank=rank_otherTch_duration_Max+1;
  3271. currentStickiness.Add(disappear);
  3272. }
  3273. }
  3274. currentStickiness = currentStickiness.OrderByDescending(x => x.teacher.stick.value).ToList();
  3275. return currentStickiness;
  3276. }
  3277. /// <summary>
  3278. /// 结算访问日志
  3279. /// </summary>
  3280. public static async Task
  3281. VisitSettle(List<string> times, AzureStorageFactory _azureStorage, AzureRedisFactory _azureRedis, Region2LongitudeLatitudeTranslator _longitudeLatitudeTranslator, IPSearcher _ipSearcher, string force)
  3282. {
  3283. foreach (var timeDate in times)
  3284. {
  3285. List<Stick> chinaSticks = new List<Stick>();
  3286. List<Stick> globalSticks = new List<Stick>();
  3287. if (DateTimeOffset.TryParse(timeDate, out DateTimeOffset date))
  3288. {
  3289. var blobClientChina = _azureStorage.GetBlobContainerClient("0-service-log").GetBlobClient($"http-log/{date:yyyy}/{date:MM}/{date:dd}/cday.json");
  3290. var blobClientGlobal = _azureStorage.GetBlobContainerClient("0-service-log").GetBlobClient($"http-log/{date:yyyy}/{date:MM}/{date:dd}/gday.json");
  3291. bool g = true, c = true;
  3292. if (blobClientChina.Exists() && force.Equals("0"))
  3293. {
  3294. c=false;
  3295. BlobDownloadResult result = await _azureStorage.GetBlobContainerClient("0-service-log").GetBlobClient($"http-log/{date:yyyy}/{date:MM}/{date:dd}/cday.json").DownloadContentAsync();
  3296. var contentBygone = result.Content.ToString();
  3297. var chinaStick = contentBygone.ToObject<Stick>();
  3298. chinaSticks.Add(chinaStick);
  3299. }
  3300. if (blobClientGlobal.Exists()&& force.Equals("0"))
  3301. {
  3302. g=false;
  3303. BlobDownloadResult result = await _azureStorage.GetBlobContainerClient("0-service-log").GetBlobClient($"http-log/{date:yyyy}/{date:MM}/{date:dd}/gday.json").DownloadContentAsync();
  3304. var contentBygone = result.Content.ToString();
  3305. var globalStick = contentBygone.ToObject<Stick>();
  3306. globalSticks.Add(globalStick);
  3307. }
  3308. if (g||c)
  3309. {
  3310. BlobDownloadResult result = await _azureStorage.GetBlobContainerClient("0-service-log").GetBlobClient($"http-log/{date:yyyy}/{date:MM}/{date:dd}/index.log").DownloadContentAsync();
  3311. var content = result.Content.ToString();
  3312. content= content.Substring(0, content.Length-2);
  3313. if (content.EndsWith("}"))
  3314. {
  3315. content=$"[{content}]";
  3316. }
  3317. else
  3318. {
  3319. content=$"[{content}}}]";
  3320. }
  3321. List<ApiVisit> apiVisits = new List<ApiVisit>();
  3322. apiVisits.AddRange(content.ToObject<List<ApiVisit>>());
  3323. var dateNow = DateTimeOffset.Now.GetGMTTime(8);
  3324. if ($"{dateNow:yyyy-MM-dd}".Equals($"{date:yyyy-MM-dd}"))
  3325. { //当前小时一致的
  3326. BlobDownloadResult resultHour = await _azureStorage.GetBlobContainerClient("0-service-log").GetBlobClient($"http-log/{date:yyyy}/{date:MM}/{date:dd}/{date:HH}.log").DownloadContentAsync();
  3327. var contentHour = resultHour.Content.ToString();
  3328. contentHour= contentHour.Substring(0, contentHour.Length-2);
  3329. if (contentHour.EndsWith("}"))
  3330. {
  3331. contentHour=$"[{contentHour}]";
  3332. }
  3333. else
  3334. {
  3335. contentHour=$"[{contentHour}}}]";
  3336. }
  3337. var httpLog = contentHour.ToObject<List<HttpLog>>();
  3338. (ConcurrentBag<ApiVisit> visits, ConcurrentBag<(string uuid, HttpLog httpLog, List<string> tmdid, List<string> school)> uuidInfo) = await SystemService.ConvertHttpLog(httpLog, _azureRedis, _ipSearcher, _longitudeLatitudeTranslator, dateNow, false);
  3339. apiVisits.AddRange(visits);
  3340. }
  3341. if (c)
  3342. {
  3343. Stick apiVisitsBygone = await GetBygoneSettleData(_azureStorage, date, "China");
  3344. //大陆学校
  3345. var chinaApiVisits = apiVisits.Where(x => x.hostName.Equals("大陆站"));
  3346. var chinaSchoolVisits = apiVisits.Where(x => !string.IsNullOrWhiteSpace(x.school) && x.hostName.Equals("大陆站")).GroupBy(x => x.school);
  3347. List<SchoolStick> chinaStickiness = CountSchoolStickiness(chinaSchoolVisits, chinaApiVisits, apiVisitsBygone.schoolSticks);
  3348. Stick stickc = new Stick();
  3349. stickc.schoolSticks=chinaStickiness;
  3350. chinaSticks.Add(stickc);
  3351. if (!$"{dateNow:yyyy-MM-dd}".Equals($"{date:yyyy-MM-dd}"))
  3352. {
  3353. await _azureStorage.GetBlobContainerClient("0-service-log").UploadFileByContainer(stickc.ToJsonString(), "http-log", $"{date:yyyy}/{date:MM}/{date:dd}/cday.json", true);
  3354. }
  3355. }
  3356. if (g)
  3357. {
  3358. Stick apiVisitsBygone = await GetBygoneSettleData(_azureStorage, date, "Global");
  3359. //国际学校
  3360. var globalApiVisits = apiVisits.Where(x => x.hostName.Equals("国际站"));
  3361. var globalSchoolVisits = apiVisits.Where(x => !string.IsNullOrWhiteSpace(x.school) && x.hostName.Equals("国际站")).GroupBy(x => x.school);
  3362. List<SchoolStick> globalStickiness = CountSchoolStickiness(globalSchoolVisits, globalApiVisits, apiVisitsBygone.schoolSticks);
  3363. Stick stickg = new Stick();
  3364. stickg.schoolSticks=globalStickiness;
  3365. globalSticks.Add(stickg);
  3366. //如果是当天的 ,则不能保存
  3367. if (!$"{dateNow:yyyy-MM-dd}".Equals($"{date:yyyy-MM-dd}"))
  3368. {
  3369. await _azureStorage.GetBlobContainerClient("0-service-log").UploadFileByContainer(stickg.ToJsonString(), "http-log", $"{date:yyyy}/{date:MM}/{date:dd}/gday.json", true);
  3370. }
  3371. }
  3372. }
  3373. else
  3374. {
  3375. continue;
  3376. }
  3377. }
  3378. }
  3379. }
  3380. public static async Task<Stick> GetBygoneSettleData(AzureStorageFactory _azureStorage, DateTimeOffset date, string cg)
  3381. {
  3382. //过去一天的数据
  3383. var bygone = date.AddDays(-1);
  3384. Stick apiVisitsBygone = new Stick();
  3385. try
  3386. {
  3387. cg=cg.Contains("China", StringComparison.OrdinalIgnoreCase) ? "cday.json" : "gday.json";
  3388. BlobDownloadResult chinaResultBygone = await _azureStorage.GetBlobContainerClient("0-service-log").GetBlobClient($"http-log/{bygone:yyyy}/{bygone:MM}/{bygone:dd}/{cg}").DownloadContentAsync();
  3389. var contentBygone = chinaResultBygone.Content.ToString();
  3390. apiVisitsBygone= contentBygone.ToObject<Stick>();
  3391. }
  3392. catch
  3393. { //可能出现异常,因为文件不存在。第一次初始化,前一天的数据没有 }
  3394. }
  3395. return apiVisitsBygone;
  3396. }
  3397. public static async Task<(ConcurrentBag<ApiVisit> visits, ConcurrentBag<(string uuid, HttpLog httpLog, List<string> tmdid, List<string> school)> uuidInfo)>
  3398. ConvertHttpLog(List<HttpLog> logs, AzureRedisFactory _azureRedis, IPSearcher _ipSearcher, Region2LongitudeLatitudeTranslator _longitudeLatitudeTranslator, DateTimeOffset gmt8Time, bool test = false)
  3399. {
  3400. ConcurrentBag<ApiVisit> visits = new ConcurrentBag<ApiVisit>();
  3401. ConcurrentBag<(string uuid, HttpLog httpLog, List<string> tmdid, List<string> school)> uuidInfo = new ConcurrentBag<(string uuid, HttpLog httpLog, List<string> tmdid, List<string> school)>();
  3402. object lockObj = new object();
  3403. await Parallel.ForEachAsync(logs, async (log, _) =>
  3404. {
  3405. if (!log.path.Contains("."))
  3406. {
  3407. string uuid = Guid.NewGuid().ToString();
  3408. List<string> schoolMatch = new List<string>();
  3409. List<string> useridMatch = new List<string>();
  3410. var vist = new ApiVisit()
  3411. {
  3412. id=uuid,
  3413. ip=log.ip,
  3414. tid=log.tid,
  3415. time= log.time,
  3416. userId= log.id,
  3417. picture=log.picture,
  3418. school= log.school,
  3419. tname= log.name,
  3420. path = log.path,
  3421. client=log.p.Equals("os", StringComparison.OrdinalIgnoreCase) ? "ies5" : log.p,
  3422. scope=log.scope,
  3423. host= log.host,
  3424. hostName=log.hostName,
  3425. l=log.l,
  3426. year = $"{gmt8Time:yyyy}",
  3427. month = $"{gmt8Time:MM}",
  3428. day = $"{gmt8Time:dd}",
  3429. hour =$"{gmt8Time:HH}"
  3430. };
  3431. if (test)
  3432. {
  3433. var time = DateTimeOffset.FromUnixTimeMilliseconds(log.time);
  3434. //本地调试时间
  3435. if (vist.ip.Equals("0.0.0.1"))
  3436. {
  3437. time= time.AddHours(8);
  3438. }
  3439. vist.year = $"{time:yyyy}";
  3440. vist.month = $"{time:MM}";
  3441. vist.day = $"{time:dd}";
  3442. vist.hour =$"{time:HH}";
  3443. }
  3444. if (string.IsNullOrWhiteSpace(vist.userId))
  3445. {
  3446. //var jsonPathContext = new JsonPathContext();
  3447. //jsonPathContext.ValueSystem= new JsonTextValueSystem();
  3448. string path = "$..['id_token','idToken','idtoken','tmdid','id','teacherId','teacher','tid','tId','userid','userId','creatorId','creator','code','studentId','student','studentid']";
  3449. if (!log.param.ValueKind.Equals(JsonValueKind.Null))
  3450. {
  3451. JObject jsonObject = JObject.Parse(log.param.GetRawText());
  3452. //var nodes_path = jsonPathContext.SelectNodes(log.param, path);
  3453. var nodes_path = jsonObject.SelectTokens(path);
  3454. foreach (var node in nodes_path)
  3455. {
  3456. // 只获取是字符串的
  3457. if (node.Type.Equals(JTokenType.String))
  3458. {
  3459. switch (true)
  3460. {
  3461. case bool when node.Path.Contains("id_token")||node.Path.Contains("idToken")||node.Path.Contains("idtoken"):
  3462. {
  3463. try
  3464. {
  3465. var jwt = new JwtSecurityToken($"{node}");
  3466. string id = jwt.Payload.Sub;
  3467. var name = jwt.Claims.FirstOrDefault(claim => claim.Type.Equals("name"))?.Value;
  3468. var picture = jwt.Claims.FirstOrDefault(claim => claim.Type.Equals("picture"))?.Value;
  3469. if (!string.IsNullOrWhiteSpace(id) && long.TryParse(id, out long _id))
  3470. {
  3471. vist.userId=id;
  3472. vist.scope="teacher";
  3473. vist.tname=name;
  3474. vist.picture=picture;
  3475. useridMatch.Add(id);
  3476. }
  3477. }
  3478. catch (Exception ex) { }
  3479. break;
  3480. }
  3481. case bool when node.Path.Contains("tmdid")||node.Path.Contains("id")||node.Path.Contains("teacherId")
  3482. ||node.Path.Contains("teacher")||node.Path.Contains("tid")||node.Path.Contains("tId")||node.Path.Contains("userid")
  3483. ||node.Path.Contains("userId"):
  3484. {
  3485. if (!string.IsNullOrWhiteSpace($"{node}") && long.TryParse($"{node}", out long _id))
  3486. {
  3487. vist.userId=$"{node}";
  3488. vist.scope="teacher";
  3489. useridMatch.Add($"{node}");
  3490. }
  3491. break;
  3492. }
  3493. case bool when node.Path.Contains("studentId")||node.Path.Contains("student")||node.Path.Contains("studentid"):
  3494. {
  3495. if (!string.IsNullOrWhiteSpace($"{node}") && long.TryParse($"{node}", out long _id))
  3496. {
  3497. vist.userId=$"{node}";
  3498. vist.scope="student";
  3499. useridMatch.Add($"{node}");
  3500. }
  3501. break;
  3502. }
  3503. case bool when node.Path.Contains("code"):
  3504. {
  3505. if (!string.IsNullOrWhiteSpace($"{node}"))
  3506. {
  3507. if (long.TryParse($"{node}", out long _id))
  3508. {
  3509. vist.userId=$"{node}";
  3510. useridMatch.Add($"{node}");
  3511. }
  3512. else
  3513. {
  3514. string[] codes = $"{node}".Split("-");
  3515. foreach (var _code in codes)
  3516. {
  3517. if (long.TryParse(_code, out long _codeid))
  3518. {
  3519. vist.userId=$"{node}";
  3520. useridMatch.Add($"{_code}");
  3521. break;
  3522. }
  3523. }
  3524. }
  3525. }
  3526. break;
  3527. }
  3528. }
  3529. }
  3530. }
  3531. if (log.path.Contains("process-notify", StringComparison.OrdinalIgnoreCase))
  3532. {
  3533. string s = log.param.ToJsonString().Replace("\\", "");
  3534. Regex regextmdid = new Regex("\"tmdid\":\"(\\d+)\"");
  3535. Match matchtmdid = regextmdid.Match(s);
  3536. if (matchtmdid.Success)
  3537. {
  3538. var t = matchtmdid.Groups[1].Value;
  3539. if (!string.IsNullOrWhiteSpace(t))
  3540. {
  3541. vist.userId=t;
  3542. vist.scope="teacher";
  3543. useridMatch.Add(t);
  3544. }
  3545. }
  3546. Regex regexname = new Regex("\"tmdname\":\"(.+?)\"");
  3547. Match matchname = regexname.Match(s);
  3548. if (matchname.Success)
  3549. {
  3550. var t = matchname.Groups[1].Value;
  3551. if (!string.IsNullOrWhiteSpace(t))
  3552. {
  3553. vist.tname=t;
  3554. }
  3555. }
  3556. }
  3557. }
  3558. }
  3559. else
  3560. {
  3561. if (string.IsNullOrWhiteSpace($"{vist.scope}"))
  3562. {
  3563. vist.scope="teacher";
  3564. uuidInfo.Add((uuid, log, new List<string>() { vist.userId }, new List<string>()));
  3565. }
  3566. }
  3567. if (string.IsNullOrWhiteSpace(vist.school) || vist.school.Equals("true") || vist.school.Equals("false"))
  3568. {
  3569. vist.school="";
  3570. string path = "$..['school','id','schoolId','schoolid','schoolCode','school_code','schoolcode','code']";
  3571. if (!log.param.ValueKind.Equals(JsonValueKind.Null))
  3572. {
  3573. JObject jsonObject = JObject.Parse(log.param.GetRawText());
  3574. var nodes_path = jsonObject.SelectTokens(path);
  3575. foreach (var node in nodes_path)
  3576. {
  3577. // 只获取是字符串的
  3578. if (node.Type.Equals(JTokenType.String))
  3579. {
  3580. switch (true)
  3581. {
  3582. case bool when node.Path.Contains("school")||node.Path.Contains("id")||node.Path.Contains("schoolId")
  3583. ||node.Path.Contains("schoolid")||node.Path.Contains("schoolCode")||node.Path.Contains("school_code")||node.Path.Contains("schoolcode"):
  3584. {
  3585. if (!$"{node}".Contains("-")&& $"{node}".Length<=8 && $"{node}".Length>=1)
  3586. {
  3587. vist.school=$"{node}";
  3588. schoolMatch.Add($"{node}");
  3589. }
  3590. break;
  3591. }
  3592. case bool when node.Path.Contains("code"):
  3593. {
  3594. if (!$"{node}".Contains("-")&& $"{node}".Length<=8&& $"{node}".Length>=1)
  3595. {
  3596. vist.school=$"{node}";
  3597. schoolMatch.Add($"{node}");
  3598. }
  3599. else
  3600. {
  3601. string[] codes = $"{node}".Split("-");
  3602. foreach (var _code in codes)
  3603. {
  3604. if ($"{_code}".Length<=8 && $"{_code}".Length>=1)
  3605. {
  3606. vist.school=$"{_code}";
  3607. schoolMatch.Add($"{_code}");
  3608. break;
  3609. }
  3610. }
  3611. }
  3612. break;
  3613. }
  3614. }
  3615. }
  3616. }
  3617. if (log.path.Contains("process-notify", StringComparison.OrdinalIgnoreCase))
  3618. {
  3619. string s = log.param.ToJsonString().Replace("\\", "");
  3620. Regex regexname = new Regex("\"schoolId\":\"(.+?)\"");
  3621. Match matchname = regexname.Match(s);
  3622. if (matchname.Success)
  3623. {
  3624. var t = matchname.Groups[1].Value;
  3625. if (!string.IsNullOrWhiteSpace(t))
  3626. {
  3627. vist.school=t;
  3628. }
  3629. }
  3630. }
  3631. }
  3632. }
  3633. //处理 client
  3634. {
  3635. if (!string.IsNullOrWhiteSpace(log.client))
  3636. {
  3637. if (log.client.Equals("IES", StringComparison.OrdinalIgnoreCase))
  3638. {
  3639. vist.client="ies5";
  3640. }
  3641. if (log.client.Equals("AClassONE", StringComparison.OrdinalIgnoreCase))
  3642. {
  3643. vist.client="aclassone";
  3644. }
  3645. if (log.client.Equals("BB", StringComparison.OrdinalIgnoreCase))
  3646. {
  3647. vist.client="habb";
  3648. }
  3649. if (log.client.Equals("HiTool", StringComparison.OrdinalIgnoreCase) ||log.client.Equals("HiTools", StringComparison.OrdinalIgnoreCase))
  3650. {
  3651. vist.client="hiscan";
  3652. }
  3653. if (log.client.Equals("HiTA", StringComparison.OrdinalIgnoreCase))
  3654. {
  3655. vist.client="hita";
  3656. vist.scope="teacher";
  3657. }
  3658. if (log.client.Equals("HiTeachCC", StringComparison.OrdinalIgnoreCase))
  3659. {
  3660. vist.client="hiteachcc";
  3661. }
  3662. if (log.client.Equals("HiTeach", StringComparison.OrdinalIgnoreCase))
  3663. {
  3664. vist.scope="teacher";
  3665. vist.client="hiteach";
  3666. }
  3667. if (log.client.Equals("Open", StringComparison.OrdinalIgnoreCase))
  3668. {
  3669. vist.client="open";
  3670. }
  3671. }
  3672. }
  3673. //补全站点
  3674. {
  3675. if (
  3676. (log.host.Equals("wwww.teammodel.net")||log.host.Equals("ies5-rc.teammodel.net")))
  3677. {
  3678. vist.hostName="国际站";
  3679. vist.host="www.teammodel.net";
  3680. vist.client="ies5";
  3681. vist.l="Global";
  3682. }
  3683. else if (
  3684. log.host.Equals("teammodelos-yx.chinacloudsites.cn")||log.host.Equals("teammodelos.chinacloudsites.cn")
  3685. ||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"))
  3686. {
  3687. vist.hostName="大陆站";
  3688. vist.host="www.teammodel.cn";
  3689. vist.client="ies5"; vist.l="China";
  3690. }
  3691. else if ((log.host.Contains("localhost") && log.p.Equals("os"))|| log.host.Equals("teammodelos-test.chinacloudsites.cn") ||log.host.Equals("test.teammodel.cn"))
  3692. {
  3693. vist.hostName="测试站";
  3694. vist.host="test.teammodel.cn";
  3695. vist.client="ies5";
  3696. vist.l="China";
  3697. }
  3698. else if (
  3699. (log.host.Equals("scyx.teammodel.cn") ||log.host.Equals("jinniu.teammodel.cn")))
  3700. {
  3701. vist.hostName="研修2.0";
  3702. vist.host="scyx.teammodel.cn";
  3703. vist.client="ability"; vist.l="China";
  3704. }
  3705. else if (
  3706. log.host.Equals("open.teammodel.cn")||log.host.Equals("open-test.teammodel.cn") ||log.host.Equals("zhiyin-test.teammodel.cn"))
  3707. {
  3708. vist.hostName="开放平台";
  3709. vist.host="open.teammodel.cn";
  3710. vist.client="open";
  3711. vist.l="China";
  3712. }
  3713. else if ((log.host.Equals("bi-rc.teammodel.net") || log.host.Equals("bi.teammodel.net")))
  3714. {
  3715. vist.hostName="国际站";
  3716. vist.host="bi.teammodel.net";
  3717. vist.client="bi";
  3718. vist.scope="admin";
  3719. vist.l="Global";
  3720. }
  3721. else if (log.host.Equals("teammodelbi.chinacloudsites.cn") ||log.host.Equals("bi.teammodel.cn"))
  3722. {
  3723. vist.hostName="大陆站";
  3724. vist.host="bi.teammodel.cn";
  3725. vist.client="bi";
  3726. vist.scope="admin";
  3727. vist.l="China";
  3728. }
  3729. else if (log.host.Equals("bitest.teammodel.cn")||log.host.Equals("teammodelbi-test.chinacloudsites.cn")||(log.host.Contains("localhost") && (log.p.Equals("bi"))))
  3730. {
  3731. vist.hostName="测试站";
  3732. vist.host="testbi.teammodel.cn";
  3733. vist.client="bi";
  3734. vist.scope="admin";
  3735. vist.l="China";
  3736. }
  3737. else if (
  3738. log.host.Equals("teamcontest.chinacloudsites.cn")||log.host.Equals("contest.chinacloudsites.cn")||log.host.Equals("contest-test.chinacloudsites.cn"))
  3739. {
  3740. vist.hostName="大陆站";
  3741. vist.host="contest.teammodel.cn";
  3742. vist.client="contest"; vist.l="China";
  3743. }
  3744. else if (
  3745. log.host.Equals("hiteachcc.chinacloudsites.cn"))
  3746. {
  3747. vist.hostName="正式站";
  3748. vist.host="hiteachcc.teammodel.cn";
  3749. vist.client="hiteachcc";
  3750. vist.l="China";
  3751. }
  3752. else if (log.host.Equals("appraisal.chinacloudsites.cn"))
  3753. {
  3754. vist.hostName="大陆站";
  3755. vist.host="appraisal.teammodel.cn";
  3756. vist.client="appraisal";
  3757. vist.l="China";
  3758. }
  3759. else if ((log.host.Contains("localhost") && log.p.Equals("appraisal"))||log.host.Equals("appraisal-test.teammodel.cn") ||log.host.Equals("appraisal-test.chinacloudsites.cn"))
  3760. {
  3761. vist.hostName="测试站";
  3762. vist.host="appraisal-test.teammodel.cn";
  3763. vist.client="appraisal";
  3764. vist.l="China";
  3765. }
  3766. else
  3767. {
  3768. if (!string.IsNullOrWhiteSpace(log.p))
  3769. {
  3770. vist.client=log.p.Equals("os", StringComparison.OrdinalIgnoreCase) ? "ies5" : log.p;
  3771. }
  3772. else
  3773. {
  3774. vist.client="other";
  3775. }
  3776. if (log.host.EndsWith(".cn"))
  3777. {
  3778. vist.hostName="大陆站";
  3779. vist.l="China";
  3780. }
  3781. else if (log.host.EndsWith(".net"))
  3782. {
  3783. vist.hostName="国际站";
  3784. vist.l="Global";
  3785. }
  3786. else
  3787. {
  3788. vist.hostName="其他";
  3789. vist.l="其他";
  3790. }
  3791. }
  3792. }
  3793. //补全产品端
  3794. {
  3795. //研修2.0
  3796. if (log.path.Contains("research") || log.path.Contains("study") || log.path.Contains("standard-file"))
  3797. {
  3798. vist.client="ability";
  3799. }
  3800. if (log.path.Contains("teacher"))
  3801. {
  3802. vist.scope="teacher";
  3803. }
  3804. if (log.path.Contains("tmduser"))
  3805. {
  3806. vist.scope="tmduser";
  3807. }
  3808. if (log.path.Contains("student/login"))
  3809. {
  3810. vist.scope="student";
  3811. }
  3812. if (log.path.StartsWith("/activity"))
  3813. {
  3814. vist.client="contest";
  3815. }
  3816. //小程序
  3817. if (log.path.Contains("aclassone"))
  3818. {
  3819. vist.client="aclassone";
  3820. }
  3821. // /// <summary>
  3822. /// ExamInfo qamode 書面問答類型 0:書面問答 1:紙本測驗 2:艺术评测
  3823. /// </summary>
  3824. //艺术评测
  3825. 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"))
  3826. {
  3827. vist.client="art";
  3828. }
  3829. if (log.path.Contains("common/exam/upsert-record"))
  3830. {
  3831. JObject jobject = JObject.Parse(log.param.GetRawText());
  3832. var jtokens = jobject.SelectTokens("$..artId");
  3833. if (jtokens!=null && jtokens.Count()>0)
  3834. {
  3835. vist.client="art";
  3836. vist.scope="student";
  3837. }
  3838. }
  3839. if (log.path.Contains("habb"))
  3840. {
  3841. vist.client="habb";
  3842. }
  3843. //阅卷客户端
  3844. if (log.path.Contains("hiscan"))
  3845. {
  3846. vist.client="hiscan";
  3847. }
  3848. if (log.path.Contains("hita"))
  3849. {
  3850. vist.client="hita";
  3851. }
  3852. if (log.path.Contains("hiteachcc"))
  3853. {
  3854. vist.client="hiteachcc";
  3855. }
  3856. if (log.path.Contains("sokrate"))
  3857. {
  3858. vist.client="sokrate";
  3859. }
  3860. if (log.path.Contains("sokrate") || log.path.Contains("score"))
  3861. {
  3862. vist.client="sokrate";
  3863. }
  3864. if (log.path.Contains("hiteach"))
  3865. {
  3866. vist.client="hiteach";
  3867. }
  3868. ///IES开放平台
  3869. if (log.path.Contains("business") || log.path.Contains("biz") || log.path.Contains("openapi-config") || log.path.Contains("open-api"))
  3870. {
  3871. vist.client="open";
  3872. }
  3873. //从token的role 能否获取 开放平台
  3874. //单点登录及第三方接口
  3875. 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")
  3876. || log.path.Contains("oauth/check-bind")|| log.path.Contains("dingding") || log.path.Contains("wechat")
  3877. )
  3878. {
  3879. vist.client="sso-third";
  3880. }
  3881. }
  3882. //处理IP转地区
  3883. var region = await _ipSearcher.SearchIpAsync(vist.ip);
  3884. if (string.IsNullOrWhiteSpace(region))
  3885. {
  3886. region="未知IP·未知IP·未知IP";
  3887. }
  3888. if (!string.IsNullOrWhiteSpace(region))
  3889. {
  3890. region= region.Replace("省·", "·").Replace("市·", "·").Replace("特别行政区·", "·").Replace("藏族羌族自治州·", "·");
  3891. var regions = region.Split("·");
  3892. if (regions.Length==4)
  3893. {
  3894. vist.area= regions[0];
  3895. vist.province = regions[1];
  3896. vist.city = regions[2];
  3897. }
  3898. if (regions.Length==3)
  3899. {
  3900. vist.area= regions[0];
  3901. vist.province = regions[1];
  3902. }
  3903. if (regions.Length==2)
  3904. {
  3905. vist.area= regions[0];
  3906. vist.province = regions[1];
  3907. }
  3908. if (regions.Length==1)
  3909. {
  3910. vist.area= regions[0];
  3911. }
  3912. }
  3913. //处理地区转经纬度
  3914. {
  3915. IEnumerable<JToken> tokens = default;
  3916. if (!string.IsNullOrWhiteSpace(vist.city) && !string.IsNullOrWhiteSpace(vist.province) && !string.IsNullOrWhiteSpace(vist.area))
  3917. {
  3918. tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.province}/i && @.city=~ /.*{vist.city}/i)]");
  3919. if (!(tokens.Any() && tokens.Count()>0))
  3920. {
  3921. tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.city}/i && @.city=~ /.*{vist.province}/i)]");
  3922. if (!(tokens.Any() && tokens.Count()>0))
  3923. {
  3924. tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.city}/i || @.city=~ /.*{vist.city}/i)]");
  3925. }
  3926. if (!(tokens.Any() && tokens.Count()>0))
  3927. {
  3928. tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.province}/i||@.city=~ /.*{vist.province}/i)]");
  3929. }
  3930. }
  3931. }
  3932. else if (string.IsNullOrWhiteSpace(vist.city) && !string.IsNullOrWhiteSpace(vist.province) && !string.IsNullOrWhiteSpace(vist.area))
  3933. {
  3934. if (vist.area.Equals("中国"))
  3935. {
  3936. tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.province}/i)]");
  3937. if (!(tokens.Any() && tokens.Count()>0))
  3938. {
  3939. tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.city=~ /.*{vist.province}/i)]");
  3940. }
  3941. }
  3942. else
  3943. {
  3944. tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.city=~ /.*{vist.province}/i || @.province=~ /.*{vist.province}/i)]");
  3945. }
  3946. }
  3947. else if (!string.IsNullOrWhiteSpace(vist.city) && string.IsNullOrWhiteSpace(vist.province)&& !string.IsNullOrWhiteSpace(vist.area))
  3948. {
  3949. if (vist.area.Equals("中国"))
  3950. {
  3951. tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.province=~ /.*{vist.city}/i)]");
  3952. if (!(tokens.Any() && tokens.Count()>0))
  3953. {
  3954. tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.city=~ /.*{vist.province}/i)]");
  3955. }
  3956. }
  3957. else
  3958. {
  3959. tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.city=~ /.*{vist.city}/i || @.city=~ /.*{vist.province}/i)]");
  3960. }
  3961. }
  3962. else if (string.IsNullOrWhiteSpace(vist.city) && string.IsNullOrWhiteSpace(vist.province)&& !string.IsNullOrWhiteSpace(vist.area))
  3963. {
  3964. tokens= _longitudeLatitudeTranslator.regionJson.SelectTokens($"$..[?(@.country=~ /.*{vist.area}/i && @.m=='1')]");
  3965. }
  3966. if (tokens!=null && tokens.Any())
  3967. {
  3968. List<RegionLngLat> regionLngLats = new List<RegionLngLat>();
  3969. foreach (JToken token in tokens)
  3970. {
  3971. regionLngLats.Add(token.ToString().ToObject<RegionLngLat>());
  3972. }
  3973. var points = regionLngLats.FindAll(x => string.IsNullOrWhiteSpace(x.area));
  3974. if (!points.IsNotEmpty())
  3975. {
  3976. points= regionLngLats.FindAll(x => !string.IsNullOrWhiteSpace(x.m) && x.m.Equals("1"));
  3977. }
  3978. if (string.IsNullOrWhiteSpace(vist.city))
  3979. {
  3980. vist.city=points?.FirstOrDefault()?.city;
  3981. if (!string.IsNullOrWhiteSpace(vist.city) && vist.city.EndsWith("市"))
  3982. {
  3983. vist.city=vist.city.Replace("市", "");
  3984. }
  3985. }
  3986. vist.lat=points?.FirstOrDefault()?.lat;
  3987. vist.lng=points?.FirstOrDefault()?.lng;
  3988. }
  3989. else
  3990. {
  3991. if (vist.area.Equals("内网IP"))
  3992. {
  3993. if (vist.host.Contains(".cn") || vist.host.Contains("localhost"))
  3994. {
  3995. vist.lat="30.655821878416408";
  3996. vist.lng="104.08153351042463";
  3997. vist.area="中国";
  3998. vist.province="四川";
  3999. vist.city="成都";
  4000. }
  4001. else
  4002. {
  4003. vist.lat="25.044332";
  4004. vist.lng="121.509062";
  4005. vist.area="中国";
  4006. vist.province="台湾";
  4007. vist.city="台湾";
  4008. }
  4009. }
  4010. else
  4011. {
  4012. vist.lat="30.655821878416408";
  4013. vist.lng="104.08153351042463";
  4014. vist.area="中国";
  4015. vist.province="四川";
  4016. vist.city="成都";
  4017. }
  4018. }
  4019. }
  4020. uuidInfo.Add((uuid, log, useridMatch, schoolMatch));
  4021. visits.Add(vist);
  4022. }
  4023. }
  4024. );
  4025. List<(string tmd, bool exists, string scope)> tmdexists = new List<(string tmd, bool exists, string scope)>();
  4026. List<(string sch, bool exists)> schexists = new List<(string sch, bool exists)>();
  4027. var tmds = uuidInfo.SelectMany(x => x.tmdid).ToHashSet();
  4028. if (tmds.Any())
  4029. {
  4030. foreach (var tmd in tmds)
  4031. {
  4032. var exists = await _azureRedis.GetRedisClient(8).KeyExistsAsync($"Blob:Catalog:{tmd}");
  4033. if (exists)
  4034. {
  4035. tmdexists.Add((tmd, exists, "teacher"));
  4036. }
  4037. else
  4038. {
  4039. exists = await _azureRedis.GetRedisClient(8).KeyExistsAsync($"Login:School:hbcn:student:{tmd}");
  4040. tmdexists.Add((tmd, exists, "student"));
  4041. }
  4042. }
  4043. }
  4044. var schs = uuidInfo.SelectMany(x => x.school).ToHashSet();
  4045. if (schs.Any())
  4046. {
  4047. foreach (var sch in schs)
  4048. {
  4049. var exists = await _azureRedis.GetRedisClient(8).KeyExistsAsync($"Blob:Catalog:{sch}");
  4050. schexists.Add((sch, exists));
  4051. }
  4052. }
  4053. foreach (var item in uuidInfo)
  4054. {
  4055. foreach (var tmd in item.tmdid)
  4056. {
  4057. var tmdext = tmdexists.Find(x => x.tmd.Equals(tmd));
  4058. if (tmdext.tmd!= null && tmdext.exists)
  4059. {
  4060. var vist = visits.Where(x => x.id.Equals(item.uuid));
  4061. foreach (var vi in vist)
  4062. {
  4063. vi.userId=tmd;
  4064. if (string.IsNullOrWhiteSpace(vi.scope))
  4065. {
  4066. vi.scope=tmdext.scope;
  4067. }
  4068. }
  4069. break;
  4070. }
  4071. }
  4072. foreach (var sch in item.school)
  4073. {
  4074. var schext = schexists.Find(x => x.sch.Equals(sch));
  4075. if (schext.sch!= null && schext.exists)
  4076. {
  4077. var vist = visits.Where(x => x.id.Equals(item.uuid));
  4078. foreach (var vi in vist)
  4079. {
  4080. vi.school=sch;
  4081. }
  4082. break;
  4083. }
  4084. }
  4085. }
  4086. return (visits, uuidInfo);
  4087. }
  4088. public class ApiVisit
  4089. {
  4090. public string id { get; set; }
  4091. public string path { get; set; }
  4092. /// <summary>
  4093. /// 细分
  4094. /// ies5 ,hiteach,hita,cc,bi,contest,open,aclassone,sokrates,ability,art
  4095. /// 产品端
  4096. /// </summary>
  4097. public string client { get; set; }
  4098. /// <summary>
  4099. /// 具体功能
  4100. /// </summary>
  4101. // public string func { get; set; }
  4102. public string userId { get; set; }
  4103. public string picture { get; set; }
  4104. public string scope { get; set; }
  4105. public string tname { get; set; }
  4106. public string school { get; set; }
  4107. public string ip { get; set; }
  4108. //public string region { get; set; }
  4109. public string area { get; set; }
  4110. public string province { get; set; }
  4111. public string city { get; set; } = "";
  4112. public long time { get; set; }
  4113. /// <summary>
  4114. ///
  4115. /// </summary>
  4116. public string host { get; set; }
  4117. public string hostName { get; set; } = "其他";
  4118. /// <summary>
  4119. /// tokenid
  4120. /// </summary>
  4121. public string tid { get; set; }
  4122. public string year { get; set; }
  4123. public string month { get; set; }
  4124. public string day { get; set; }
  4125. public string hour { get; set; }
  4126. //public RegionLngLat point { get; set; }
  4127. public string lat { get; set; }
  4128. public string lng { get; set; }
  4129. public string l { get; set; }
  4130. }
  4131. public class HttpLog
  4132. {
  4133. public string ip { get; set; }
  4134. public long time { get; set; }
  4135. public string host { get; set; }
  4136. public string hostName = "其他";
  4137. public string tid { get; set; }
  4138. public string path { get; set; }
  4139. public string client { get; set; }
  4140. public JsonElement param { get; set; }
  4141. public string id { get; set; }
  4142. public string name { get; set; }
  4143. public string picture { get; set; }
  4144. public string school { get; set; }
  4145. public string p { get; set; }
  4146. // public string ua { get; set; }
  4147. // public string referer { get; set; }
  4148. public string scope { get; set; }
  4149. public string year { get; set; }
  4150. public string month { get; set; }
  4151. public string day { get; set; }
  4152. public string hour { get; set; }
  4153. public string l { get; set; }
  4154. }
  4155. public record RegionLngLat
  4156. {
  4157. public string country { get; set; }
  4158. public string province { get; set; }
  4159. public string city { get; set; }
  4160. public string lat { get; set; }
  4161. public string lng { get; set; }
  4162. public string area { get; set; }
  4163. public string m { get; set; } = "0";
  4164. }
  4165. public class CountData
  4166. {
  4167. public string pk { get; set; } = "";
  4168. public string sk { get; set; } = "";
  4169. public string sp { get; set; } = "";
  4170. public int count { get; set; }
  4171. }
  4172. public class SchoolStick
  4173. {
  4174. /// <summary>
  4175. /// 名字
  4176. /// </summary>
  4177. public string name { get; set; }
  4178. public string picture { get; set; }
  4179. /// <summary>
  4180. /// 编码
  4181. /// </summary>
  4182. public string id { get; set; }
  4183. public string last { get; set; }
  4184. #region teacher
  4185. public ClientStick teacher { get; set; } = new ClientStick();
  4186. #endregion
  4187. #region student
  4188. public ClientStick student { get; set; } = new ClientStick();
  4189. #endregion
  4190. #region hiteach
  4191. public ClientStick hiteach { get; set; } = new ClientStick();
  4192. public Indicator lesson { get; set; } = new Indicator();
  4193. #endregion
  4194. #region hita
  4195. public ClientStick hita { get; set; } = new ClientStick();
  4196. #endregion
  4197. #region ies5Teacher
  4198. public ClientStick ies5Tch { get; set; } = new ClientStick();
  4199. #endregion
  4200. #region otherTeacher
  4201. public ClientStick otherTch { get; set; } = new ClientStick();
  4202. #endregion
  4203. #region ies5Student
  4204. public ClientStick ies5Stu { get; set; } = new ClientStick();
  4205. #endregion
  4206. #region otherStudent
  4207. public ClientStick otherStu { get; set; } = new ClientStick();
  4208. #endregion
  4209. public List<TchStick> tchSticks { get; set; } = new List<TchStick>();
  4210. public List<StuStick> stuSticks { get; set; } = new List<StuStick>();
  4211. }
  4212. public class TchStick
  4213. {
  4214. public string school { get; set; }
  4215. /// <summary>
  4216. /// 名字
  4217. /// </summary>
  4218. public string name { get; set; }
  4219. public string picture { get; set; }
  4220. /// <summary>
  4221. /// 编码
  4222. /// </summary>
  4223. public string id { get; set; }
  4224. public string last { get; set; }
  4225. #region tmd
  4226. public ClientStick teacher { get; set; } = new ClientStick();
  4227. #endregion
  4228. #region hiteach
  4229. public ClientStick hiteach { get; set; } = new ClientStick();
  4230. public Indicator lesson { get; set; } = new Indicator();
  4231. #endregion
  4232. #region hita
  4233. public ClientStick hita { get; set; } = new ClientStick();
  4234. #endregion
  4235. #region ies5Teacher
  4236. public ClientStick ies5Tch { get; set; } = new ClientStick();
  4237. #endregion
  4238. #region otherTeacher
  4239. public ClientStick otherTch { get; set; } = new ClientStick();
  4240. #endregion
  4241. }
  4242. public class StuStick
  4243. {
  4244. public string school { get; set; }
  4245. /// <summary>
  4246. /// 名字
  4247. /// </summary>
  4248. public string name { get; set; }
  4249. public string picture { get; set; }
  4250. /// <summary>
  4251. /// 编码
  4252. /// </summary>
  4253. public string id { get; set; }
  4254. public string last { get; set; }
  4255. #region tmd
  4256. public ClientStick student { get; set; } = new ClientStick();
  4257. #endregion
  4258. #region ies5Student
  4259. public ClientStick ies5Stu { get; set; } = new ClientStick();
  4260. #endregion
  4261. #region otherStudent
  4262. public ClientStick otherStu { get; set; } = new ClientStick();
  4263. #endregion
  4264. }
  4265. public class ClientStick
  4266. {
  4267. public int userCount { get; set; }
  4268. public int userUpdown { get; set; }
  4269. public Indicator stick { get; set; } = new Indicator();
  4270. public Indicator duration { get; set; } = new Indicator();
  4271. public Indicator count { get; set; } = new Indicator();
  4272. }
  4273. public class Indicator
  4274. {
  4275. /// <summary>
  4276. /// 值
  4277. /// </summary>
  4278. public double value { get; set; } = 0;
  4279. /// <summary>
  4280. /// 值的增减浮动
  4281. /// </summary>
  4282. public double range { get; set; } = 0;
  4283. /// <summary>
  4284. /// 排名
  4285. /// </summary>
  4286. public double rank { get; set; } = 0;
  4287. /// <summary>
  4288. /// 排名的上升下降
  4289. /// </summary>
  4290. public double updown { get; set; } = 0;
  4291. }
  4292. public class Stick
  4293. {
  4294. public List<SchoolStick> schoolSticks { get; set; } = new List<SchoolStick>();
  4295. public List<TchStick> tchSticks { get; set; } = new List<TchStick>();
  4296. }
  4297. public class LessonWeek
  4298. {
  4299. /// <summary>
  4300. /// 第几周
  4301. /// </summary>
  4302. public int week { get; set; }
  4303. /// <summary>
  4304. /// 课例id
  4305. /// </summary>
  4306. public string? id { get; set; }
  4307. /// <summary>
  4308. /// 课程id
  4309. /// </summary>
  4310. public string? cid { get; set; }
  4311. /// <summary>
  4312. /// 科目id
  4313. /// </summary>
  4314. public string? sid { get; set; }
  4315. /// <summary>
  4316. /// 学校
  4317. /// </summary>
  4318. public string? school { get; set; }
  4319. /// <summary>
  4320. /// 名单id
  4321. /// </summary>
  4322. public string? gid { get; set; }
  4323. /// <summary>
  4324. /// 学段id
  4325. /// </summary>
  4326. //public string? pid { get; set; }
  4327. public string? scope { get; set; }
  4328. }
  4329. public class Product
  4330. {
  4331. public string Name { get; set; }
  4332. public double VisitDuration { get; set; }
  4333. public double VisitCount { get; set; }
  4334. public double CalculateProductIndex(double timeWeight, double countWeight, double minVisitDuration, double maxVisitDuration, double minVisitCount, double maxVisitCount)
  4335. {
  4336. // 计算访问时长的Min-Max标准化值
  4337. double standardizedVisitDuration = (maxVisitDuration - minVisitDuration)!=0 ? (VisitDuration - minVisitDuration) / (maxVisitDuration - minVisitDuration) : 0;
  4338. // 计算访问次数的Min-Max标准化值
  4339. double standardizedVisitCount = (maxVisitCount - minVisitCount)!=0 ? (VisitCount - minVisitCount) / (maxVisitCount - minVisitCount) : 0;
  4340. // 计算加权综合指数
  4341. double comprehensiveIndex = timeWeight * standardizedVisitDuration + countWeight * standardizedVisitCount;
  4342. return Math.Round(comprehensiveIndex, 4);
  4343. }
  4344. }
  4345. }
  4346. }