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