SystemService.cs 216 KB

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