123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271 |
- using Azure;
- using Azure.Core;
- using Azure.Cosmos;
- using Azure.Messaging.ServiceBus;
- using Azure.Storage.Blobs;
- using Azure.Storage.Blobs.Models;
- using Azure.Storage.Blobs.Specialized;
- using DinkToPdf;
- using DinkToPdf.Contracts;
- using DocumentFormat.OpenXml.Drawing.Wordprocessing;
- using DocumentFormat.OpenXml.Office2010.Excel;
- using DocumentFormat.OpenXml.Office2016.Excel;
- using DocumentFormat.OpenXml.Presentation;
- using DocumentFormat.OpenXml.Wordprocessing;
- using HTEXLib.COMM.Helpers;
- using HTEXLib.Helpers.ShapeHelpers;
- using MathNet.Numerics.Distributions;
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Configuration;
- using Microsoft.Extensions.Options;
- using Microsoft.International.Converters.PinYinConverter;
- using Microsoft.International.Converters.TraditionalChineseToSimplifiedConverter;
- using Newtonsoft.Json;
- using OpenXmlPowerTools;
- using StackExchange.Redis;
- using System;
- using System.Collections.Concurrent;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Net;
- using System.Net.Http;
- using System.Net.Http.Json;
- using System.Runtime.Intrinsics.X86;
- using System.Security.Policy;
- using System.Text;
- using System.Text.Json;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- using TEAMModelOS.Controllers.Analysis;
- using TEAMModelOS.Controllers.Core;
- using TEAMModelOS.Controllers.Third.LePei;
- using TEAMModelOS.Filter;
- using TEAMModelOS.Models;
- using TEAMModelOS.SDK;
- using TEAMModelOS.SDK.DI;
- using TEAMModelOS.SDK.Extension;
- using TEAMModelOS.SDK.Helper.Common.DateTimeHelper;
- using TEAMModelOS.SDK.Models;
- using TEAMModelOS.SDK.Models.Cosmos.Common;
- using TEAMModelOS.SDK.Models.Cosmos.OpenEntity;
- using TEAMModelOS.SDK.Models.Service;
- using TEAMModelOS.SDK.Models.Service.BI;
- using TEAMModelOS.SDK.Services;
- using Top.Api;
- using static TEAMModelOS.SDK.Models.Teacher;
- using static TEAMModelOS.SDK.SchoolService;
- namespace TEAMModelOS.Controllers
- {
- [Route("test")]
- [ApiController]
- public class TestController : ControllerBase
- {
- private readonly IHttpClientFactory _httpClient;
- public IWebHostEnvironment _environment { get; set; }
- private readonly AzureStorageFactory _azureStorage;
- private readonly AzureRedisFactory _azureRedis;
- private readonly AzureCosmosFactory _azureCosmos;
- private readonly DingDing _dingDing;
- private readonly AzureServiceBusFactory _serviceBus;
- private readonly CoreAPIHttpService _coreAPIHttpService;
- private readonly Option _option;
- private readonly IPSearcher _searcher;
- public IConfiguration _configuration { get; set; }
- private readonly IConverter _converter;
- private readonly HttpTrigger _httpTrigger;
- public TestController(HttpTrigger httpTrigger, IConverter converter, IPSearcher searcher, IOptionsSnapshot<Option> option, CoreAPIHttpService coreAPIHttpService, IHttpClientFactory httpClient, IWebHostEnvironment environment, AzureCosmosFactory azureCosmos, AzureRedisFactory azureRedis, AzureStorageFactory azureStorage, IConfiguration configuration, AzureServiceBusFactory serviceBus, DingDing dingDing)
- {
- _converter = converter;
- _azureCosmos = azureCosmos;
- _azureRedis = azureRedis;
- _azureStorage = azureStorage;
- _dingDing = dingDing;
- _serviceBus = serviceBus; _configuration = configuration;
- _environment = environment;
- _httpClient = httpClient;
- _option = option.Value;
- _coreAPIHttpService = coreAPIHttpService;
- _searcher = searcher;
- _httpTrigger = httpTrigger;
- }
- /// <summary>
- /// 测试五育画像数据推送
- /// </summary>
- /// <param name="json"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("import-table")]
- public async Task<IActionResult> ImportTable(JsonElement json)
- {
- List<LPSchool> schools = json.ToObject<List<LPSchool>>();
- var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
- await table.BatchInsertAsync (schools);
- return Ok(schools);
- }
- /// <summary>
- /// 测试五育画像数据推送
- /// </summary>
- /// <param name="json"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("test-upsert-student-portrait")]
- public async Task<IActionResult> TestUpsertStudentPortrait(JsonElement json) {
- var data = await _httpTrigger.RequestHttpTrigger(json, _option.Location, "upsert-student-portrait");
- return Ok(data.json.ToObject<JsonElement>());
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="json"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("transform-lessonrecord-overalleducation")]
- public async Task<IActionResult> TransformLessonrecordOveralleducation(JsonElement json) {
- //string msg = json.ToString();
- //var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
- //var messageChange = new ServiceBusMessage(msg);
- //messageChange.ApplicationProperties.Add("name", "LessonRecordEvent");
- //await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageChange);
- string sql = "select value c from c where c.pk='StudentScoreRecord' and c.userType='student' and c.school<>null and c.school<>'' ";
- List<StudentScoreRecord> studentScores = new List<StudentScoreRecord>();
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).GetItemQueryIterator<StudentScoreRecord>(sql)) {
- studentScores.Add(item);
- }
- var group = studentScores.GroupBy(z => z.school);
- string schoolSql = $"select value c from c where c.id in ({string.Join(",",group.Select(x=>$"'{x.Key}'"))})";
- var resultScool= await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).GetList<School>(schoolSql,"Base");
- foreach(var item in group)
- {
- var list = item.ToList();
- var stuids = list.Select(z => z.stuid);
- string studentSql = $"select value c from c where c.id in ({string.Join(",", stuids.Select(x => $"'{x}'"))})";
- var resultStuden = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).GetList<Student>(studentSql, $"Base-{item.Key}");
-
- foreach (var sturecord in list) {
- HashSet<OverallEducation> overallEducations = new HashSet<OverallEducation>();
- var studentBase = resultStuden.list.Find(x => x.id.Equals(sturecord.stuid, StringComparison.OrdinalIgnoreCase));
- var schoolBase = resultScool.list.Find(x => x.id.Equals(sturecord.school, StringComparison.OrdinalIgnoreCase));
- if (studentBase == null) {
- continue;
- }
- var period = schoolBase.period.Find(x => x.id.Equals($"{studentBase.periodId}"));
- foreach (var record in sturecord.lessonRecords) {
- if (record.time > 1000000000000) {
- (Semester currSemester, int studyYear, DateTimeOffset date, DateTimeOffset nextSemester) dataSemester = SchoolService.GetSemester(period, record.time);
- string oid = $"{dataSemester.studyYear}-{dataSemester.currSemester.id}-{sturecord.stuid}";
- string ocode = $"OverallEducation-{sturecord.school}";
- OverallEducation overallEducation = overallEducations.Where(o => o.id.Equals(oid, StringComparison.OrdinalIgnoreCase) && o.code.Equals(ocode, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
- if (overallEducation != null)
- {
- var hasrecord = overallEducation.lessonScore.Find(x => x.lessonId.Equals(record.lessonId));
- if (hasrecord != null)
- {
- hasrecord.gscore = record.gscore;
- hasrecord.pscore = record.pscore;
- hasrecord.tscore = record.tscore;
- hasrecord.tmdid = record.tmdid;
- hasrecord.school = record.school;
- hasrecord.scope = record.scope;
- hasrecord.lessonId = record.lessonId;
- hasrecord.courseId = record.courseId;
- hasrecord.periodId = record.periodId;
- hasrecord.subjectId = record.subjectId;
- hasrecord.time = record.time;
- }
- else
- {
- overallEducation.lessonScore.Add(
- new StudentLessonRecord
- {
- gscore = record.gscore,
- pscore = record.pscore,
- tscore = record.tscore,
- tmdid = record.tmdid,
- school = record.school,
- scope = record.scope,
- lessonId = record.lessonId,
- courseId = record.courseId,
- periodId = record.periodId,
- subjectId = record.subjectId,
- time = record.time
- }
- );
- }
- }
- else {
- Azure.Response response = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).ReadItemStreamAsync(oid, new PartitionKey(ocode));
- if (response.Status != 200)
- {
- overallEducation = new OverallEducation
- {
- id = oid,
- code = $"OverallEducation-{sturecord.school}",
- pk = "OverallEducation",
- ttl = -1,
- name = studentBase.name,
- classId = studentBase?.classId,
- schoolCode = $"{sturecord.school}",
- semesterId = dataSemester.currSemester.id,
- year = dataSemester.studyYear,
- periodId = $"{period.id}",
- stuYear = studentBase.year,
- studentId = studentBase.id,
- lessonScore = new List<StudentLessonRecord>
- {
- new StudentLessonRecord
- {
- gscore = record.gscore,
- pscore = record.pscore,
- tscore = record.tscore,
- tmdid = record.tmdid,
- school = record.school,
- scope = record.scope,
- lessonId = record.lessonId,
- courseId = record.courseId,
- periodId = record.periodId,
- subjectId = record.subjectId,
- time= record.time
- }
- }
- };
- }
- else
- {
- overallEducation = JsonDocument.Parse(response.Content).RootElement.ToObject<OverallEducation>();
- var hasrecord = overallEducation.lessonScore.Find(x => x.lessonId.Equals(record.lessonId));
- if (hasrecord != null)
- {
- hasrecord.gscore = record.gscore;
- hasrecord.pscore = record.pscore;
- hasrecord.tscore = record.tscore;
- hasrecord.tmdid = record.tmdid;
- hasrecord.school = record.school;
- hasrecord.scope = record.scope;
- hasrecord.lessonId = record.lessonId;
- hasrecord.courseId = record.courseId;
- hasrecord.periodId = record.periodId;
- hasrecord.subjectId = record.subjectId;
- hasrecord.time = record.time;
- }
- else
- {
- overallEducation.lessonScore.Add(
- new StudentLessonRecord
- {
- gscore = record.gscore,
- pscore = record.pscore,
- tscore = record.tscore,
- tmdid = record.tmdid,
- school = record.school,
- scope = record.scope,
- lessonId = record.lessonId,
- courseId = record.courseId,
- periodId = record.periodId,
- subjectId = record.subjectId,
- time = record.time
- }
- );
- }
- }
- overallEducations.Add(overallEducation);
- }
- }
- }
- foreach (var overallEducation in overallEducations) {
- await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).UpsertItemAsync(overallEducation, partitionKey: new PartitionKey(overallEducation.code));
- }
- }
- }
- return Ok();
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="json"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("check-art-result")]
- public async Task<IActionResult> CheckArtResult(JsonElement json)
- {
- List<StudentArtResult> art_idNames = new List<StudentArtResult>();
- string sqlSchool = "select value c from c where c.areaId='7a51072f-b329-4e74-99e0-ba0407ba8926'";
- List<School> schools = new List<School>();
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School)
- .GetItemQueryIterator<School>(sqlSchool, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
- {
- schools.Add(item);
- }
- string sql = @"SELECT value c FROM c where c.pk='ArtResult' and c.artId in('770fbaaa-a9e8-4d45-a322-3c6d6e50a8f7',
- '1e59bb5f-984f-406d-83a2-48ef1ce60a75',
- '33fc9276-60c1-4663-8c42-2e44a138a874',
- '4eada95b-a408-4a66-bd6c-c61c6057d505',
- 'f61b32c6-2f86-4ae6-ac25-1961df0f443a',
- '4d974b69-e104-45db-8047-b4cbc43ebc98',
- 'efb8f6ed-74b9-43b7-b8e5-c61d92441ed9',
- '070d8ce5-253c-404b-80b7-12cbc234ddae',
- 'fdd6c34b-44c2-42e9-9cd4-66c01b7103da',
- 'b1cf6fed-a4ea-4d06-b15d-3941fba973de',
- '67cd2be9-e307-4d35-8249-6d4e7380d15c',
- 'f0481d0e-ab74-4117-8600-a375a206e283',
- '7a809ab3-4081-4a23-8127-9a362f9af8ff',
- '673684e2-1dc3-48d9-a21f-207cc40a68ba',
- '35e4da67-0fb9-4683-9fac-9c9b1c197f24',
- '893b9871-8518-4f70-97e5-58ceb4c1b504',
- '0cd4ea92-4697-468a-a2fd-2f0e1cd53525',
- 'd9fec69f-2532-408b-bc25-98a33edf7200',
- '02b68eed-29f2-49c1-a91f-c1e35dd8ce64',
- 'edaf8c12-9b0b-4b31-baff-3e9b926b401a',
- '472bbdc9-c287-4b18-9502-7f34d15172a8',
- '41f67e3c-6c7f-46e9-bc39-ec8d6ae9a495',
- 'ffea1c6b-3fb7-40d4-921b-e1dc46d15410',
- '079fa190-fc18-46b9-bcb9-a4b6e2cd902d',
- 'a0e778e8-2590-431e-b761-4929fa143762',
- '374a571a-6d5c-4a8a-ab57-6e79b8b8ff0a',
- '1db3838e-d7cd-4c77-af70-d3854262d33e',
- '7b8a2f53-3b90-48f1-bd0b-bb5be843656a',
- 'e5c24756-1ea3-46cf-8f0f-357ec280e42c',
- '1b713f31-7e0b-4cb5-84f1-0342db618a6d',
- '1794bc46-d0fb-4ea9-8ff8-2f813affe495',
- 'b9d54179-7eaf-426b-a44f-9018e6c4ffa7',
- '3145e47a-21e5-4cdf-a992-72b9e47c7bad',
- 'bdaab0b2-f8d0-4c1b-821c-95b4a2371c42',
- 'd39f74df-dc65-44d4-8463-41af1a4b186d',
- '79e83de1-4e64-4ef3-b24e-fe4e877e683b',
- 'bf3aaff3-1a86-42c8-89d7-4b9d6147d37f',
- 'ad3742eb-9e46-43f8-9644-ecb498082810',
- '66a3d74b-3946-42c3-a2d2-0bc6704c86ec',
- 'ec75e499-f432-41d4-b6dd-5548358b657d',
- '70ef5724-f875-4e2e-bda8-58fd2457c2a7',
- '60c03852-8c97-4cb0-a232-e0734eaebe96',
- '4eefe05d-3df9-4f27-804b-53dd7bc5f4ab',
- 'b82ff879-5474-4b31-b3e6-3174361a4fd0',
- '09489fef-5490-4b5e-802b-74d1be2c5515',
- '1a7d8d51-f828-4f15-9859-33937b41b9e4',
- '9e591e75-538e-426d-862d-b043c13e822a',
- '71cd894a-e82d-49ff-a204-a64a2eb6f332',
- '70103a11-095b-4d01-b3ea-0ed2e388445f',
- 'b40d4952-396d-49f3-ba2d-6aeba1d940d9',
- '149a12ae-7c5d-444c-ac34-17af88cf653e',
- '8c1b2180-4a81-4f6b-989a-b971dbeae082',
- '079107f5-7bf5-4955-a39c-85dec9715e60',
- 'f9abe967-dbce-46d7-a60f-d9a2e6866ec6',
- 'b4684520-cf0c-473c-aa3a-ea5ba5d398d3',
- '0839abf0-07e7-4c0d-b818-54d451a6265a',
- '6abc82c7-928b-43bf-8c5d-f5a5d7c55a4d',
- '544577d3-c4b0-491f-a041-18cc07e711ca',
- '2efddd68-0bbc-4dba-a594-f7f8532f519d',
- '725f2665-1015-4563-9044-f4061accdf67',
- '739aa426-a359-4515-85ef-1efe605c0b73',
- '8dcde32c-3a77-4bf5-84a3-ec4d7a78413d',
- '4a396e8b-babb-47ee-b6ed-db2124d5c39d',
- '55f4594b-c13b-48b8-82f1-563751d48e9e',
- '3cc1bd57-bf4e-4933-ac6b-7cdb0e8e2dc1',
- '380511bf-2b15-4b90-b8c8-3464c2c6e18c',
- '12378c30-0c1d-4c84-8deb-5aaffaa2b45c',
- 'e247abc3-7083-4de5-a492-46e09e9bb341',
- 'ef826295-7a00-483d-945b-589c8fc0baf9',
- 'c1b056c5-0ebf-454a-bb56-3f6024e837d2',
- 'c513fe45-767c-4632-b6d3-9631c9bf8854',
- '9f7d087e-ba53-4167-9776-1e33a9a1cb61',
- 'b5f1a3f0-975f-441c-b6d0-3b8513b96d24',
- '92560ac8-a3a5-4aff-85e6-b7f72fc7e2fb',
- '898a7705-47f3-4f3b-a01e-1ec609ad4abf',
- '4c4349a0-ade4-4793-a435-15de7f3c299e',
- '473707f1-6f43-4611-adca-263604aa8e58',
- '88ee65ec-ec5c-4c5a-8539-8a8e931508ce',
- '4b12c255-5f44-4056-8ab6-d33721394ab2',
- '1f2f9ad3-e465-4152-afce-26715e3902af',
- 'bba7590c-735a-41c3-a501-ab4285fc36e8',
- '51c7426f-934f-4a18-bc1f-053e994969cc',
- '9ec15578-a78b-4f9d-ae8c-f15677d03d0a',
- '6fc632fe-5833-4c26-a079-70f9a3fa1957',
- '86a886f5-e540-4f57-abfd-cee4e3d328ab',
- '66e50efa-c3c4-4e3e-8892-5ebdec85a008',
- '2b66ee3b-e74a-446a-a92d-9cdc11a43123',
- '09533510-ec3a-4c45-8220-097a2a7e4237',
- 'be879d1f-1ccd-4e5f-9871-449a736a9279',
- '2371ba86-0598-44eb-99de-c73b7cca15db',
- '77f87528-e5c0-4ddf-80ea-43d383f5e58e',
- '9b7aa0c9-6393-4337-95cd-2bf0c57a662c',
- '93811e7f-fa3f-4487-9310-ef28ba3530f4',
- '43ecedc4-45fa-4ab7-b87b-357be07b19fa',
- 'a7fa4f17-9a9e-4d0b-bca7-2edfdcd75afb',
- '3682bc09-96ab-4d17-9010-b9fc31dc72bd',
- '04eff65e-3e19-4b57-b3ba-f1f63f52b8ba',
- '9eaea71a-97c8-456d-afc4-97d00e2e83bd',
- 'e3d846fd-c9e7-44b1-966d-ba74b4953f54',
- '2db6561b-3657-418a-ba18-b726a86d1fb1',
- '93b32d4b-a918-4940-bcef-00fbeceff525',
- '18e6f96a-c4d3-4cca-9248-f7c9099c6706',
- '3e1866ed-c9d0-415f-a080-ed1b34704110',
- 'd4ee5661-646b-4a58-b2b8-ad309666d64e',
- 'b678edb6-4717-423f-a8ac-6abc80eeab97',
- 'e8d68e11-d1e9-4bc7-8e22-e426f50f70a2',
- '8e96efbd-b990-4e2e-ad43-49e9dae73794',
- '72793b29-c939-4201-82b8-7ded1e6c6fe5',
- '59b5a6bc-ae2a-4157-b262-bf7a4858aace',
- 'e6b642ef-4239-4063-b471-da5b987b6aeb',
- 'f5ebf426-b4bc-4744-a2f3-a35a22c6c326',
- 'a7e80ecb-2a53-4879-a0f4-d313f78d3c01',
- 'cf32535a-b754-4cee-a51d-be4dc2220a2f',
- '521c66d6-00cc-4ec6-b391-0d9ce1995c42',
- '523b17d0-629f-44de-8f24-0c3915493fb0',
- '771b45c4-dde0-4d6a-ba69-6d8f537e4c1f',
- 'f9b374fd-1af4-4623-b117-c75fa4e7f4f8',
- '479f343e-51b7-49bd-8ebb-cb81af8ae7b0',
- 'cc992aae-2942-4836-9351-cedbd1cc4e61',
- '3f5d1192-4c56-43a6-9140-18043d6c41e5',
- 'dffad9b6-f3f2-4470-be45-94c81af04a02',
- '39289aa9-2506-4d04-866e-e6eec9b4d9db',
- '243299ec-6a98-43ac-b3db-272f5abbbd78',
- '9f715766-ef6a-479d-895d-945952a8ff6e',
- '2ff9bd86-8621-4f04-b560-abff5a202232',
- '75da24ed-8196-4eb1-8413-3916d7b271a3',
- '6adc96f3-c6e5-4a8d-a33f-5bbcbb92b296',
- '0b2dcfbc-d334-4032-b354-f6fa98a57d99',
- 'e2110a26-3af6-4c53-8b38-51ed4b415d48',
- '85e4c259-f531-43dd-a2b8-76cb750f8604',
- '1a6731a3-cc57-4463-84e1-bca0917c2399',
- 'd574dac8-4440-48f0-af37-b982db545ea3',
- '753ca661-d930-4f33-bce3-5385c310744f',
- 'e70800f3-836b-43e9-aa8c-c5e789d7054e',
- '32a94a0c-c14c-4208-8bd1-0d84c69d690e',
- 'f5d242b3-db25-4877-8a63-4d4dcf8f8f2c',
- '87399fcb-34fb-494b-b74f-02979a665dc0',
- '85796371-1079-4fff-947d-671720377e72',
- '40f04a01-e373-430a-a1f5-cbb8fbcff4cb',
- '6e6a3d09-c65d-4996-bd96-035f5d19e634',
- 'd340ea8f-e869-46d5-8813-5cce7991edea',
- '8a72592b-09fb-4910-b4e9-c76ef039b44f',
- '740b8b24-c7f5-4df5-a13a-92a1c37619bc',
- 'c19ef79f-d3f3-4125-8e1a-83cee110e03b',
- '1894992c-2575-4949-971d-c84669fcfd06',
- '4d51ace2-9f18-4f01-be7b-1ab4694e62dd',
- 'c1564967-890f-49e2-983a-933df4cbf8d0',
- 'aff088da-91e6-400a-ab84-c6cf300b361f',
- 'b0557e5e-41c5-4273-b793-dcb8a0613e6f',
- 'd0317e30-bcc4-4b03-9417-4dba3a216105',
- '86a28ef8-f3fc-44ef-942b-a9a658bb0731',
- '53623415-70e8-44f6-9ea6-bd709e40984c',
- '9ee23eee-850c-4cb0-8147-829ae0502705',
- 'd6fbfc1e-6093-4e70-8432-453246c80eb3',
- 'ac0e96dd-ec15-4b39-834d-1000ac3aa4c4',
- '1e8c9744-8054-405b-997c-de13e58967a4',
- 'c87c282c-6a83-40d1-86bc-af3045c0c41a',
- '4c221226-f490-4657-bd98-cf24bba48d7e',
- 'fd218bdd-7c18-41d6-a592-59a4c3ee98fe',
- '0c916db0-f7fa-4abc-a548-ca81cb416e59',
- '9f3c9615-3066-45d8-99a9-eacc8f6d692d',
- '6ed5074e-c7df-49f1-84c8-bb6276db9d1d',
- 'c2eb2c78-60d3-4616-9215-5ca810c58e4d',
- '4aef197d-5c62-4bce-aab2-804c87db5b28',
- '3231a06f-118a-437f-b863-4ffcba56d03a',
- 'a827a795-f86e-46eb-8369-f63b061d87d9',
- 'd4fd8c14-81d1-41b3-b652-f1dfb107d0d6',
- 'a0f2b207-0ef7-4ca4-b595-12f46b4b8434',
- '115f8e21-ebdb-4241-9c34-91fbef1b6fb9',
- '34c8923a-0230-448a-9d06-a8f2922520a3',
- '04803687-4689-45a6-b19e-4d3a39ccc348',
- '8bb657c9-7638-4ab9-af92-a4370d53960e',
- '1e766445-9971-4358-86be-fba295460866',
- '367c0575-b150-44eb-b447-5468d4d833fe',
- '2a379010-1f57-43f7-8f99-1f254ad93c26',
- '496adcc6-2897-4f16-9e9b-75fbcfd313a0',
- 'c32a4e86-637f-4c68-8824-2d4370eea5ee',
- 'b03b9f85-6d51-4c9c-a354-22bd3aa67462',
- '829a1242-f1e0-4154-aacf-362c021172f2',
- '4a451d51-b96c-4740-9018-7d22bbd842cf',
- '497a3b9a-55da-4991-af53-657c04edd0b3',
- 'b89b915f-f4ea-44f6-ae3a-e45af1942022',
- '781c4777-a869-4857-b052-71cbecbf6e35',
- '16a1d9aa-4bba-4c6f-86e5-7f7a281e7cd2',
- 'a5125445-cd2c-44b1-af19-addd25b8eeef',
- '81f574b9-9da2-43ae-ac6c-54ceb637c1fa',
- '1d469b5a-386c-4ace-9477-826c2d9d2b5d',
- '4fb0c252-5df1-44f9-a6e4-40078740a4e8',
- '1d7574e8-cf7c-460f-aad9-b4eec908121c',
- 'b0d23d24-a66f-4fb7-badc-980bebe0118d',
- 'e9570402-e4db-4a7c-9d5c-c5f95ad8ed0a',
- 'b08a57bc-6f1a-491c-a126-490ad5c8f90c',
- '583f3908-5caf-4703-84c6-e32cbbafca1e',
- '271cf872-cc61-493d-a595-be644bb2e098',
- 'a031cf56-0aa1-40c1-a325-14f6f1204cad',
- '3f492d1f-d95d-4947-8944-1e47fbe6abb4',
- '44d282b7-413f-4f1a-b5cf-5b9b81acbb6a',
- 'cef3a415-dc3f-4143-b905-5b1bac1b10c9',
- '37fe497b-1ba6-46e7-a9b9-fd70993b9753',
- 'c0db0c30-590c-42bd-bac7-d065a05843cd',
- '19532426-9ee6-4cc0-8d7b-7c5753b95b64',
- '7421dcb4-14d3-4656-9257-a2b287ff41a8',
- 'bd5805f7-a7eb-4189-8e48-9b3978d22362',
- '012861ec-8bbb-42e2-9e39-349a5b172c21',
- '731daff9-ccf2-48d3-88bc-ff02ec7ff2f9',
- '5b47d6c3-df81-4456-a165-4af6ee34c375',
- '2129126a-838f-4e3d-a8a4-1bf9e8d70ce8',
- 'acb84287-1cf7-4aa5-8892-e92beb6f6871',
- 'b2d337e4-16b4-459d-9d7f-922458e2671c',
- 'c63b9cd7-bce4-4c80-91c2-c305916d3d22',
- '1a7d052b-97b6-40ab-9b45-3e163710ea10',
- 'bd096e5e-0dc3-4b2e-9e4a-ffc3ac2a8e8b',
- '1afbab3e-193c-408c-b024-3365730d1698',
- '6e268ebe-aa65-4fa0-8fc1-877d0688cf8d',
- '89675ae3-9773-4b37-bc69-6a926f608b0e',
- 'd96a0716-89e1-4b5b-b02a-0cb438bd4933',
- '693e024a-1b71-4c9e-868e-ad9524728988',
- '5fb1ad4b-7a79-4a55-b627-3d1354a22754',
- 'c050b6d6-5f1a-4f3f-9385-521d9f992f11',
- '62051b3d-1a64-4509-914c-a382f573c050',
- '8b6c6a22-3a4c-48f4-bba4-57db1af2ec2e',
- 'ca5d3896-35ad-4848-ad2a-beb04263999d',
- '1bac6904-2f36-45f5-9e8e-894e28a5674d',
- '89f1a5f6-3c29-4338-8a00-5645dbaa80ad',
- 'def9d072-fee5-44f6-bc18-5b2750d4efc5',
- '032e2e84-6154-49ee-8d4d-e3b3b631595b',
- '6cb4e7ba-9be8-4c8a-bf4a-437faf96c084',
- 'd6df2ed5-8963-42c0-8832-537a210e900e',
- 'ec647fea-a650-4b18-b267-3f8d9d104c23',
- '10374436-b76b-4d73-853e-abe12b8f0079',
- '8b87190e-3fd1-40d3-9a7f-efb986cd7fa5',
- '30803959-1b88-4b8a-8716-d74e58f2eacd',
- 'b7c69c8d-b4c0-4523-ac73-f9629d2b5c37',
- 'da21dd7d-fe43-474f-bcd0-e2819b71ab40',
- 'ae97438f-afc8-4f01-90da-da5fbbc7b759',
- '95920cea-040e-40a0-a9fa-ea7e48945e5e',
- 'bf0ec2c2-b1b5-41a4-990b-ebd32e64bcc5',
- '06add3e9-8566-44b0-8962-6f1377410b48',
- '1a56021a-b4e5-45e0-83e5-7ec707097271',
- 'd35c54ea-3985-484f-9a3a-abc4be8fc774',
- 'a7c3bd26-ac43-4a61-99fe-428ea141a826',
- '414a46cb-4e88-4217-adfd-395f3f4cb12c',
- '241729ee-cfe7-4ee2-868e-3f617fd62bba',
- 'c05c28db-8b03-4d0c-8a37-c0e36c6fd0e8',
- '5b72fe37-3bc6-4563-9a1e-bfd62b692980',
- '73609b0e-1bc7-4c64-a39e-df52a34a5325',
- '477bba0c-d64f-4543-90eb-481183874bf8',
- 'd2d5be63-6e49-46d5-ae96-3b106b907902',
- '9091e31c-28c6-4a31-9958-36d0875ef8d7',
- '4fedd41a-d3d2-475d-8804-8c716ac4e160',
- '5d322e5c-ad86-42b2-a20d-1fa0e3279361',
- '99297e99-3b10-4353-a691-02492f2b88d1',
- '5b1206de-1b99-4b96-8e98-5c85ca630cea',
- '65d501e8-4663-4ae8-a07e-59b30b75a645',
- 'b53311e3-5276-45d6-87a1-36bf28b653be',
- '6bd75463-1dec-4001-ab24-cd2e07986759',
- '9b3201a9-ce44-41a7-8ad5-6769f726c2d0',
- '0acf8a5d-0feb-4497-9a0a-e95f86138157',
- '522597e8-bada-4c5b-bdf2-06af764a4bfe',
- '1fca91fb-3e03-438e-8f1b-a9b77b14634c',
- 'c8bd6ef8-ff2e-40c5-8f15-973caea0ed58',
- 'ba318882-7eeb-42a0-bfcb-09ac71fc0046',
- '0e1d09bd-f176-4e21-9f55-b821703a7b24',
- '3f58f289-a206-4fbd-93c6-0752d3d0a250',
- 'fd23121d-959d-443c-ac22-4cf7cac3751c',
- 'd3b4384a-290e-4cb0-bfda-b34097d5ca72',
- '2d7b5467-0e74-40ae-ab21-bf29ee3fe02c',
- 'd3db6faa-4b07-460a-bcbd-48dcc109fbc4',
- 'e5d14fe7-a5a0-4610-b1b7-87c9d936c7ff',
- 'f386b6f5-1fd2-4a2e-8ec0-6762ddd5c477',
- '60c09883-dff1-49ee-bafb-1991aab238aa',
- '6664e420-91ad-4c89-9955-313b163f722e',
- 'b81724c3-c045-436b-9d55-f528918de742',
- '5de09e10-e4bd-4df2-8628-9e432b17ec65',
- 'af93606e-5dbc-4401-99e6-adea66903418',
- 'fe7998e5-0a31-45a8-aab0-1867092d855c',
- 'd64bdffe-8388-4a9c-a3f9-bbd1b75ea224',
- 'c8845227-73ea-45fe-920c-be3e166b04c3',
- '6087c06a-10fc-4c92-adb3-95f85423fe2e',
- '6c64f697-21cf-4d58-8810-d0306e0c5dc4',
- 'bc2ee64e-cb01-4101-9d2d-fd37f31fd881',
- 'c076b996-1f81-4f4a-8c04-a1a69348863f',
- 'f2fab9c5-2a57-4f0a-8b48-000fc08eec98',
- 'b496b620-713e-4312-8d80-4f89d10187de',
- '6995deff-b9e8-479b-84fc-d981efab4d3b',
- 'cd7e8c81-231f-42ab-a30d-7665e9097a71',
- '38452e41-1ec3-40ca-ac3a-2579e47e5f16',
- '16e904e2-b77b-4723-86ee-ba85a9d3762f',
- '9e5e308a-c291-4feb-a225-336f0f949489',
- '8391694a-dccb-48eb-8d3b-56401e5fb030',
- 'f210dd0a-e288-477a-9a16-d622cc92a818',
- '17908451-473c-4fd8-848c-23ef7846fa43',
- 'cea1ec2e-02e6-4777-b931-b2042b3f1230',
- '70fd95b8-be8c-4545-a46f-6c050449a822',
- '057d4f31-3338-4d7b-869c-98fcb114153d',
- '8d032ab5-c7db-4ceb-9a37-f55f8a59416c',
- '5e8a8ffe-73ac-4a29-9bcc-a03c06b25b2e',
- '55fd11e2-047f-4acf-9533-22023684dd58',
- '45a4b0c1-dbbf-423e-b287-d44c71089f69',
- 'c52cd0d3-4385-4efb-8f33-f947564a70cb',
- '07d593c2-9ad7-4ae5-b471-b3e2622c940b',
- 'adf77ae2-63f7-4732-82d0-29d434f83445',
- 'bdee46ba-fab6-485d-ad89-fda5578859cc',
- 'f8b9bccc-1c4f-433d-9917-f4ad007f7105',
- '7d2bd01e-5435-4dbd-8e9b-897e777691f6',
- '56cacfd9-aeef-4477-abb9-2a22e0a92ae7',
- '891c7363-60c7-4aa5-846e-e7e3913e37d4',
- '376c26d3-8ebc-4c10-a5c1-aef9606318a8',
- '3efc8c68-3cee-4bc6-bdcd-ffc4c1a3437b',
- '1a7e5fda-eb4c-4f62-ad2d-b3e04e0e725a',
- 'dd4b0cd7-73d4-46fa-bf19-12e35f64be43',
- 'ccf206a1-fcc8-4552-b12f-ebed670cff73',
- 'c275d71f-cdb3-443c-82ab-821dd80500ea',
- 'e269c78b-2b0c-4fd1-bc0f-2ff671151030',
- '41e4371e-7495-4008-9951-7b3ab843429e',
- 'c54ac4b5-9267-4087-b724-6b0d44713162',
- 'e43fb790-aa3f-4209-838d-d830a9c5fd53',
- '982f3d88-bfe1-46c8-ac95-7adbd06a98f1',
- '8ded07a1-1dda-4dea-8e0d-05475693642c',
- 'edb7d6b2-4d86-486f-b4b6-bac71fe6c460',
- 'c3416899-550b-4e1a-93f5-690dcf67cd6b',
- '89a915cf-aee4-4472-91e6-7f33d5ef490b',
- 'c3587e4c-020a-4bef-8ad5-bcbb9a7ea485',
- '91e8d5b4-8b73-470b-b900-7cd8f5508e82'
- )";
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).GetItemQueryIterator<StudentArtResult>(sql))
- {
- art_idNames.Add(item);
- }
- List<dynamic> unfinish = new List<dynamic>();
- ConcurrentDictionary<string, int> schoolFinish = new ConcurrentDictionary<string, int>();
- ConcurrentDictionary<string, int> schoolUnFinish = new ConcurrentDictionary<string, int>();
- List<Class> classes = new List<Class>();
- foreach (var z in art_idNames)
- {
- var data = z.results.Where(x => (x.subjectId.Equals("subject_painting") && x.quotaId.Equals("quota_21") && x.score == -1)
- || (x.subjectId.Equals("subject_music") && x.quotaId.Equals("quota_21") && x.score == -1)
- || (x.subjectId.Equals("subject_music") && x.quotaId.Equals("quota_22") && x.score == -1)
- || (x.subjectId.Equals("subject_painting") && x.quotaId.Equals("quota_22") && x.files.IsEmpty())
- );
- if (data.Any())
- {
- var p21 = z.results.FindAll(x => x.subjectId.Equals("subject_painting") && x.quotaId.Equals("quota_21"))?.First();
- var p22 = z.results.FindAll(x => x.subjectId.Equals("subject_painting") && x.quotaId.Equals("quota_22"))?.First();
- int p22source = 0, p21source = 0, m21source = 0, m22source = 0;
- if (p21.score > -1)
- {
- p21source = 1;
- }
- if (p22.files.IsNotEmpty())
- {
- p22source = p22.files.Count;
- }
- var m21 = z.results.FindAll(x => x.subjectId.Equals("subject_music") && x.quotaId.Equals("quota_21"))?.First();
- if (m21.score > -1)
- {
- m21source = 1;
- }
- var m22 = z.results.FindAll(x => x.subjectId.Equals("subject_music") && x.quotaId.Equals("quota_22"))?.First();
- if (m22.score > -1)
- {
- m22source = 1;
- }
- string className = "";
- string periodName = "";
- string schoolName = "";
- School school = schools.Find(a => a.id.Equals(z.school));
- schoolName = school?.name;
- if (!string.IsNullOrWhiteSpace(z.classIds?.First()))
- {
- var clasz = classes.Find(x => x.id.Equals(z.classIds?.First()));
- if (clasz == null)
- {
- clasz = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemAsync<Class>(z.classIds.First(), new PartitionKey($"Class-{z.school}"));
- classes.Add(clasz);
- }
- className = clasz?.name;
- var period = school?.period?.Where(m => m.id.Equals(clasz.periodId));
- if (period.Any())
- {
- periodName = period.First().name + "-" + period.First().periodType;
- }
- }
- unfinish.Add(new { z.school, schoolName = schoolName, z.studentId, z.studentName, z.artId, periodName, classname = className, p21source, p22source, m21source, m22source, taskId = m22?.taskId });
- if (schoolUnFinish.ContainsKey(schoolName))
- {
- schoolUnFinish[schoolName]++;
- }
- else { schoolUnFinish.TryAdd(schoolName, 1); }
- }
- else
- {
- School school = schools.Find(a => a.id.Equals(z.school));
- string schoolName = school?.name;
- if (schoolFinish.ContainsKey(schoolName))
- {
- schoolFinish[schoolName]++;
- }
- else { schoolFinish.TryAdd(schoolName, 1); }
- }
- }
- return Ok(new { unfinish, schoolFinish , schoolUnFinish });
- }
- [ProducesDefaultResponseType]
- [HttpPost("check-ems")]
- public async Task<IActionResult> CheckPjx(JsonElement json)
- {
- var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
-
- List< ScTeacher > teachers = await table.FindListByDict<ScTeacher>(new Dictionary<string, object>() { { "PartitionKey", "ScTeacher" }, { "ProjectItemID", 1350 } });
- List<dynamic> unbind = new List<dynamic>();
- List<dynamic> unupload_rzcl = new List<dynamic>();
- List<dynamic> uploads_rzcl = new List<dynamic>();
- List<dynamic> unupload_video = new List<dynamic>();
- List<dynamic> uploads_video = new List<dynamic>();
-
- foreach (var teacher in teachers)
- {
- if (!string.IsNullOrWhiteSpace(teacher.schoolCode) && !string.IsNullOrWhiteSpace(teacher.tmdid))
- {
- int upcont = 0;
- string sql = "select value c from c where c.currency=1";
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher)
- .GetItemQueryIterator<AbilitySub>(queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"AbilitySub-{teacher.schoolCode}-{teacher.tmdid}") }))
- {
- if (item.uploads.IsNotEmpty())
- {
- upcont++;
- uploads_rzcl.Add(new { teacher.TeacherName,teacher.SchoolName,teacher.PXID,time= DateTimeOffset.FromUnixTimeMilliseconds(item.uploads.OrderByDescending(m => m.time).FirstOrDefault().time).ToString("yyyy-MM-dd HH:mm:ss"), teacher?.tmdid });
- }
- }
- if(upcont<3)
- {
- unupload_rzcl.Add(new { teacher.TeacherName, teacher.SchoolName, teacher.PXID ,teacher?.tmdid});
- }
- string sql_video =$"select value c from c where c.id='{teacher.tmdid}'";
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher)
- .GetItemQueryIterator<ClassVideo>(queryText: sql_video, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"ClassVideo-{teacher.schoolCode}") }))
- {
- if (item.files.IsNotEmpty())
- {
- uploads_video.Add(new { teacher.TeacherName, teacher.SchoolName, teacher.PXID, time = DateTimeOffset.FromUnixTimeMilliseconds(item.files.OrderByDescending(m => m.time).FirstOrDefault().time).ToString("yyyy-MM-dd HH:mm:ss"), teacher?.tmdid });
- }
- else
- {
- unupload_video.Add(new { teacher.TeacherName, teacher.SchoolName, teacher.PXID, teacher?.tmdid });
- }
- }
- }
- else {
- unbind.Add(new { teacher.TeacherName,teacher.SchoolName,teacher.PXID});
- }
- }
- Dictionary<string, object> dict = new Dictionary<string, object>();
- var tchs= teachers.GroupBy(z => z.areaId).Select(b => new { areaId = b.Key, schools = b.Select(v=>v.schoolCode).ToHashSet(), pushTeachers = b.Where(c=>!string.IsNullOrWhiteSpace(c.tmdid)).Select(d=>d.tmdid)});
- return Ok(new { unbind , unupload_rzcl, uploads_rzcl, uploads_video, unupload_video , tchs });
- }
- [ProducesDefaultResponseType]
- [HttpPost("sendmsg")]
- public async Task<IActionResult> Sendmsg(JsonElement json)
- {
- byte[] bytes = Encoding.UTF8.GetBytes(json.GetRawText());
- var memoryStream = new MemoryStream(bytes);
- Azure.Response res = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).CreateItemStreamAsync(memoryStream, new PartitionKey("Base12"));
- if (res.Status == 201)
- {
- return Ok(201);
- }
- //var messageBlobPDF = new ServiceBusMessage(new { userType = "tmdid", bizType = "OfflineRecord" }.ToJsonString());
- //await _serviceBus.GetServiceBusClient().SendMessageAsync("screenpdf", messageBlobPDF);
- return Ok();
- }
- [ProducesDefaultResponseType]
- [HttpPost("get-subTime")]
- public async Task<IActionResult> GetSubTime(JsonElement request) {
- if (!request.TryGetProperty("ids", out JsonElement id)) return BadRequest();
- List<string> ids = id.ToObject<List<string>>();
- var queryClass = $"select c.time from c ";
- var client = _azureCosmos.GetCosmosClient();
- List<(string td, long tt)> ht = new();
- foreach (string tmdId in ids) {
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIterator(queryText: queryClass,
- requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"HomeworkRecord-{tmdId}") }))
- {
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
- {
- var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
- while (accounts.MoveNext())
- {
- JsonElement account = accounts.Current;
- account.TryGetProperty("time", out JsonElement time);
- ht.Add((tmdId,time.GetInt64()));
- }
- }
- }
- }
- var home = ht.Select(x => new
- {
- id = x.td,
- time = DateTimeOffset.FromUnixTimeMilliseconds(x.tt).ToString("yyyy-MM-dd HH:mm")
- //time = DateTimeHelper.FromUnixTimestampOffSet(x.tt,8).ToString("yyyy-MM-dd HH:mm")
- });
- return Ok(home);
- }
- [ProducesDefaultResponseType]
- [HttpPost("get-semester")]
- public async Task<IActionResult> GetSemester(JsonElement json)
- {
- List<Semester> semesterList = new List<Semester>();
- semesterList.Add(
- new Semester
- {
- id = Guid.NewGuid().ToString(),
- name = "第二学期",
- start = 0,
- month = 3,
- day = 1
- });
- semesterList.Add(
- new Semester
- {
- id = Guid.NewGuid().ToString(),
- name = "第一学期",
- start = 1,
- month = 9,
- day = 1
- });
- //semesterList.Add(
- // new Semester
- // {
- // id = "q",
- // name = "第四学期",
- // start = 0,
- // month = 7,
- // day = 1
- // });
- //semesterList.Add(
- // new Semester
- // {
- // id = "q",
- // name = "第三学期",
- // start = 0,
- // month = 4,
- // day = 1
- // });
- semesterList = SortSemester(semesterList);
- return Ok(semesterList);
- }
- private List<Semester> SortSemester(List<Semester> semesterList)
- {
- int Year = DateTimeOffset.UtcNow.Year;
- List<KeyValuePair<int, Semester>> pairs = new List<KeyValuePair<int, Semester>>();
- semesterList.ForEach(se => {
- string sm = se.month >= 10 ? $"{se.month}" : $"0{se.month}";
- string sd = se.day >= 10 ? $"{se.day}" : $"0{se.day}";
- int order = int.Parse($"{Year}{sm}{sd}");
- pairs.Add(new KeyValuePair<int, Semester>(order, se));
- });
- var orderPairs = pairs.OrderBy(z => z.Key);
- semesterList = orderPairs.Select(z => z.Value).ToList();
- int startIndex = semesterList.FindIndex(z => z.start == 1);
- if (startIndex == -1)
- {
- //未设置学期的情况默认9月份开始的。
- startIndex = semesterList.FindIndex(z => z.month == 9);
- //如果还未找到,就以排序结果为准
- if (startIndex == -1)
- {
- startIndex = 0;
- }
- }
- if (startIndex > 0)
- {
- List<Semester> before = semesterList.Take(startIndex).ToList();
- List<Semester> after = semesterList.Skip(startIndex).ToList();
- semesterList = new List<Semester>();
- semesterList.AddRange(after);
- semesterList.AddRange(before);
- return semesterList;
- }
- else
- {
- return semesterList;
- }
- }
- /*
- [
- {"method":"台北市","params":{"CountryId":"TW","CityId":"30"}},1
- {"method":"新北市","params":{"CountryId":"TW","CityId":"01"}},1
- {"method":"桃园市","params":{"CountryId":"TW","CityId":"03"}},1
- {"method":"台中市","params":{"CountryId":"TW","CityId":"66"}},1
- {"method":"台南市","params":{"CountryId":"TW","CityId":"67"}},1
- {"method":"高雄市","params":{"CountryId":"TW","CityId":"64"}},1
- {"method":"基隆市","params":{"CountryId":"TW","CityId":"17"}},1
- {"method":"新竹市","params":{"CountryId":"TW","CityId":"18"}},1
- {"method":"嘉义市","params":{"CountryId":"TW","CityId":"20"}},1
- {"method":"新竹县","params":{"CountryId":"TW","CityId":"04"}},1
- {"method":"苗栗县","params":{"CountryId":"TW","CityId":"05"}},1
- {"method":"彰化县","params":{"CountryId":"TW","CityId":"07"}},1
- {"method":"南投县","params":{"CountryId":"TW","CityId":"08"}},1
- {"method":"云林县","params":{"CountryId":"TW","CityId":"09"}},1
- {"method":"嘉义县","params":{"CountryId":"TW","CityId":"10"}},1
- {"method":"屏东县","params":{"CountryId":"TW","CityId":"13"}},1
- {"method":"宜兰县","params":{"CountryId":"TW","CityId":"02"}},1
- {"method":"花莲县","params":{"CountryId":"TW","CityId":"15"}},1
- {"method":"台东县","params":{"CountryId":"TW","CityId":"14"}},1
- {"method":"澎湖县","params":{"CountryId":"TW","CityId":"16"}},1
- {"method":"金门县","params":{"CountryId":"TW","CityId":"71"}},
- {"method":"连江县","params":{"CountryId":"TW","CityId":"72"}}
- ]
-
- */
- /// <summary>
- /// 测试blob多线程写入同一个文件
- /// </summary>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("get-schools")]
- public async Task<IActionResult> GetSchools(JsonElement json)
- {
- string msg = "{\"standard\":\"standard3\",\"tmdids\":[\"1635136038\"],\"school\":\"pbjyey\",\"update\":[\"TeacherAbility\"],\"statistics\":0}";
- try
- {
- TeacherTrainChange change = msg.ToObject<TeacherTrainChange>();
- var client = _azureCosmos.GetCosmosClient();
- string insql = $"where c.id in ({string.Join(",", change.tmdids.Select(x => $"'{x}'"))})";
- string selsql = $"select value(c) from c {insql} ";
- List<TeacherTrain> teacherTrains = new List<TeacherTrain>();
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<TeacherTrain>(queryText: selsql,
- requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"TeacherTrain-{change.school}") }))
- {
- teacherTrains.Add(item);
- }
- if (change.statistics != 1)
- {
- List<Task<ItemResponse<TeacherTrain>>> task = new List<Task<ItemResponse<TeacherTrain>>>();
- teacherTrains.ForEach(x =>
- {
- x.update.UnionWith(change.update);
- task.Add(client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<TeacherTrain>(x, x.id, new PartitionKey($"TeacherTrain-{change.school}")));
- });
- await task.TaskPage(5);
- var unchange = change.tmdids.Except(teacherTrains.Select(x => x.id));
- if (unchange != null)
- {
- task.Clear();
- unchange.ToList().ForEach(x =>
- {
- TeacherTrain teacherTrain = new TeacherTrain
- {
- pk = "TeacherTrain",
- id = x,
- code = $"TeacherTrain-{change.school}",
- tmdid = x,
- school = change.school,
- update = new HashSet<string> { StatisticsService.TeacherAbility,
- StatisticsService.TeacherClass, StatisticsService.OfflineRecord }
- };
- teacherTrain.update.UnionWith(change.update);
- task.Add(client.GetContainer(Constant.TEAMModelOS, "Teacher").UpsertItemAsync<TeacherTrain>(teacherTrain, new PartitionKey($"TeacherTrain-{change.school}")));
- });
- await task.TaskPage(1);
- }
- }
- else
- {
- Area area = null;
- string sql = $"select value(c) from c where c.standard='{change.standard}'";
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<Area>(queryText: sql,
- requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-Area") }))
- {
- area = item;
- }
- AreaSetting setting = null;
- if (area != null)
- {
- try
- {
- //优先找校级
- setting = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<AreaSetting>(change.school, new PartitionKey("AreaSetting"));
- }
- catch (CosmosException)
- {
- try
- {
- setting = await client.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemAsync<AreaSetting>(area.id, new PartitionKey("AreaSetting"));
- }
- catch (CosmosException)
- {
- setting = null;
- }
- }
- }
- if (setting == null)
- {
- setting = new AreaSetting
- {
- allTime = 50,
- classTime = 5,
- submitTime = 15,
- onlineTime = 20,
- offlineTime = 10,
- lessonMinutes = 45,
- };
- }
- List<Task<TeacherTrain>> task = new List<Task<TeacherTrain>>();
- teacherTrains.ForEach(x =>
- {
- x.update.UnionWith(change.update);
- task.Add(StatisticsService.StatisticsTeacher(x, setting, area, client, null));
- });
- await task.TaskPage(1);
- var unchange = change.tmdids.Except(teacherTrains.Select(x => x.id));
- if (unchange != null)
- {
- task.Clear();
- unchange.ToList().ForEach(x =>
- {
- task.Add(StatisticsService.StatisticsTeacher(new TeacherTrain
- {
- pk = "TeacherTrain",
- id = x,
- code = $"TeacherTrain-{change.school}",
- tmdid = x,
- school = change.school,
- update = new HashSet<string> { StatisticsService.TeacherAbility,
- StatisticsService.TeacherClass, StatisticsService.OfflineRecord }
- }, setting, area, client, null));
- });
- await task.TaskPage(1);
- }
- }
- }
- catch (CosmosException ex)
- {
- await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-研修数据变更,重新统计-TeacherTrainChange\n{msg}\n{ex.Message}\n{ex.StackTrace}\nCosmosException{ex.Status}", GroupNames.醍摩豆服務運維群組);
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-研修数据变更,重新统计-TeacherTrainChange\n{msg}\n{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
- }
- /*
- string path = $"{_environment.ContentRootPath}/JsonFile/Core/city.json";
- StreamReader streamReader = new StreamReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.UTF8);
- StringBuilder stringBuilder = new StringBuilder();
- string text;
- while ((text = streamReader.ReadLine()) != null)
- {
- stringBuilder.Append(text.ToString());
- }
- streamReader.Close();
- string input = stringBuilder.ToString();
- List<string> region = new List<string>() {
- "110000", "110100", "110200",
- "120000", "120100", "120200",
- "310000", "310100", "310200",
- "500000", "500100", "810100",
- "810200", "810300", "820100",
- "820200", "820300"
- };
- List<string> cityids = new List<string>() {
- "30","01","03","66","67","64","17","18","20","04","05","07","08","09","10","13","02","15","14","16","71","72"
- };
- Dictionary<string, List<CodeName>> regions = input.ToObject<Dictionary<string, List<CodeName>>>();
- List<List<string>> datas = new List<List<string>>() { region };
- foreach (var r in regions)
- {
- if (!region.Contains(r.Key) && !r.Key.StartsWith("71"))
- {
- datas.Add(r.Value.Select(x => x.code).ToList());
- }
- }
- List<Task<List<SchoolInfo>>> tasks = new List<Task<List<SchoolInfo>>>();
- //datas.ForEach(x =>
- //{
- // tasks.Add(GetSchoolAsync(x));
- //});
- List<SchoolInfo> schoolInfos = new List<SchoolInfo>();
- //var schools = await Task.WhenAll(tasks);
- //var schools =await GetSchoolAsync(cityids);
- // schoolInfos.AddRange(schools);
- //foreach (var schs in schools)
- //{
- // schoolInfos.AddRange(schs);
- //}
- List<string> nodatas = new List<string>();
- foreach (var data in datas) {
- (List<SchoolInfo> schoolIn, List<string> nodata) = await GetSchoolAsync(data);
- schoolInfos.AddRange(schoolIn);
- nodatas.AddRange(nodata);
- }
- await _dingDing.SendBotMsg($"os,test,{nodatas.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
- return Ok(schoolInfos);
- */
- return Ok();
- }
- public async Task<(List<SchoolInfo> schoolInfos, List<string> nodata)> GetSchoolAsync(List<string> regions)
- {
- List<SchoolInfo> schools = new List<SchoolInfo>();
- List<string> nodata = new List<string>();
- foreach (var region in regions)
- {
- Dictionary<string, object> data = new Dictionary<string, object>();
- data.Add("method", "api/School/getSchool");
- data.Add("params", new { CountryId = "CN", CityId = region });
- HttpResponseMessage responseMessage = await _httpClient.CreateClient().PostAsJsonAsync("https://contest.teammodel.cn/api/School/getSchool", data);
- if (responseMessage.StatusCode == HttpStatusCode.OK)
- {
- string Content = await responseMessage.Content.ReadAsStringAsync();
- try
- {
- Content.ToObject<JsonElement>().TryGetProperty("result", out JsonElement content);
- if (content.ValueKind.Equals(JsonValueKind.Object) && content.TryGetProperty("data", out JsonElement _data))
- {
- if (_data.ValueKind.Equals(JsonValueKind.Array))
- {
- List<SchoolInfo> infos = _data.ToObject<List<SchoolInfo>>();
- if (infos.IsNotEmpty())
- {
- schools.AddRange(infos.Where(x => x.name != null && x.cityName != null).ToList());
- }
- }
- else
- {
- nodata.Add(data.ToJsonString());
- continue;
- }
- }
- else
- {
- nodata.Add(data.ToJsonString());
- continue;
- }
- }
- catch (Exception ex)
- {
- nodata.Add(data.ToJsonString());
- throw new Exception(ex.Message, ex.InnerException);
- }
- }
- }
- return (schools, nodata);
- }
- public class SchoolInfo
- {
- public string typeName { get; set; }
- public string provinceName { get; set; }
- public string provinceId { get; set; }
- public string id { get; set; }
- public string name { get; set; }
- public string cityId { get; set; }
- public string cityName { get; set; }
- public string address { get; set; }
- }
- public class CodeName
- {
- public string code { get; set; }
- public string name { get; set; }
- }
- /// <summary>
- /// 测试blob多线程写入同一个文件
- /// </summary>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("generate-school-codes")]
- public async Task<IActionResult> GenerateSchoolCodes(JsonElement json)
- {
- List<SchoolData> schoolss = json.GetProperty("schools").ToObject<List<SchoolData>>();
- dynamic data = await SchoolService.GenerateSchoolCode(schoolss, _dingDing, _environment);
- return Ok(data);
- }
- /// <summary>
- /// 测试blob多线程写入同一个文件
- /// </summary>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("blobroot")]
- public async Task<IActionResult> MultipleBlob(JsonElement jsonMsg)
- {
- if (jsonMsg.TryGetProperty("name", out JsonElement name) && name.ValueKind == JsonValueKind.String
- && jsonMsg.TryGetProperty("root", out JsonElement root) && root.ValueKind == JsonValueKind.String)
- {
- List<Dictionary<string, double?>> list = new List<Dictionary<string, double?>>();
- string u = System.Web.HttpUtility.UrlDecode($"{root}", Encoding.UTF8).Split("/")[0];
- var client = _azureStorage.GetBlobContainerClient($"{name}");
- var size = await client.GetBlobsSize(u);
- await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Blob:Catalog:{name}", u);
- await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{name}", u, size.HasValue ? size.Value : 0);
- var scores = await _azureRedis.GetRedisClient(8).SortedSetRangeByRankWithScoresAsync($"Blob:Catalog:{name}");
- double blobsize = 0;
- if (scores != default && scores != null)
- {
- foreach (var score in scores)
- {
- blobsize = blobsize + score.Score;
- list.Add(new Dictionary<string, double?>() { { score.Element.ToString(), score.Score } });
- }
- }
- await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", new RedisValue($"{name}"), new RedisValue($"{blobsize}"));
- await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,Blob() 容器:{name}使用:{root},文件分类:{list.ToJsonString()}", GroupNames.成都开发測試群組);
- return Ok(list);
- }
- else
- {
- return Ok();
- }
- }
- private async Task<int> SendNotification()
- {
- // _httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {token.AccessToken}");
- var pa = new { grant_type = "device", client_id = "9794e418-c4ef-4fd5-a42d-accaa2d96d6e", client_secret = "ruL?I79h0w1AZaZXtBaZeZuQLQXLa=:-" };
- HttpResponseMessage responseMessage = await _httpClient.CreateClient().PostAsJsonAsync("https://api2-rc.teammodel.net/oauth2/token", pa);
- if (responseMessage.StatusCode == HttpStatusCode.OK)
- {
- return 200;
- }
- else if (responseMessage.StatusCode == HttpStatusCode.Unauthorized)
- {
- return 401;
- }
- else
- {
- return 500;
- }
- }
- /// <summary>
- /// 测试redis通配符
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpGet("test-delete-read")]
- public async Task<IActionResult> TestDelete()
- {
- foreach (var cnt in _azureStorage.GetBlobServiceClient().GetBlobContainers())
- {
- Console.WriteLine(cnt.Name);
- }
- await SendNotification();
- var client = _azureCosmos.GetCosmosClient();
- string aaa = "0";
- try
- {
- ItemResponse<Student> a = await client.GetContainer(Constant.TEAMModelOS, "Student").DeleteItemAsync<Student>("1111111", new PartitionKey($"Course-111111"));
- Ok(a.GetRawResponse().Status);
- }
- catch (CosmosException ex)
- {
- if (ex.Response.Status == 404)
- {
- aaa = "404";
- }
- }
- try
- {
- ItemResponse<Student> a = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<Student>("1111111", new PartitionKey($"Course-111111"));
- Ok(a.GetRawResponse().Status);
- }
- catch (CosmosException ex)
- {
- if (ex.Response.Status == 404)
- {
- aaa = aaa + " 404";
- }
- }
- try
- {
- var a = await client.GetContainer(Constant.TEAMModelOS, "Student").DeleteItemStreamAsync("1111111", new PartitionKey($"Course-111111"));
- Ok(a.Status);
- }
- catch (CosmosException ex)
- {
- if (ex.Response.Status == 404)
- {
- aaa = "404";
- }
- }
- try
- {
- var a = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemStreamAsync("1111111", new PartitionKey($"Course-111111"));
- Ok(a.Status);
- }
- catch (CosmosException ex)
- {
- if (ex.Response.Status == 404)
- {
- aaa = aaa + " 404";
- }
- }
- return Ok(new { aaa });
- }
- /// <summary>
- /// 测试redis通配符
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpGet("test-redis")]
- public async Task<IActionResult> TestRedis()
- {
- try
- {
- var client = _azureCosmos.GetCosmosClient();
- List<ItemInfo> items = new List<ItemInfo>();
- var queryslt = $"SELECT value(c) FROM c where c.pid = null ";
- await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<ItemInfo>(queryText: queryslt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Item-hbcn") }))
- {
- items.Add(item);
- }
- List<ItemCond> itemConds = new List<ItemCond>();
- items.GroupBy(x => x.periodId).Select(y => new { key = y.Key, list = y.ToList() }).ToList().ForEach(z =>
- {
- ItemCond cond = new ItemCond() { id = z.key, code = $"ItemCond-hbcn", pk = "ItemCond", ttl = -1, count = z.list.Count, grades = new List<GradeCount>(), subjects = new List<SubjectItemCount>() };
- z.list.ForEach(y =>
- {
- ItemService.CountItemCond(y, null, cond);
- });
- itemConds.Add(cond);
- });
- itemConds.ForEach(async cond =>
- {
- await client.GetContainer(Constant.TEAMModelOS, "School").UpsertItemAsync<ItemCond>(cond, new PartitionKey(cond.code));
- });
- return Ok(new { itemConds });
- }
- catch (Exception ex) { await _dingDing.SendBotMsg($"TEAMModelFunction,ActivityHttpTrigger,fix-itemcond()\n{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組); }
- return Ok(new { });
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- //[AuthToken(Roles = "teacher")]
- [HttpPost("fix-blob-content")]
- public async Task<IActionResult> FixBlobContent(JsonElement request)
- {
- try
- {
- if (!request.TryGetProperty("name", out JsonElement name)) return BadRequest();
- if (!request.TryGetProperty("scope", out JsonElement _scope)) return BadRequest();
- var client = _azureCosmos.GetCosmosClient();
- List<string> prefixs = new List<string>() { "audio", "doc", "image", "other", "res", "video", "thum" };
- var ContainerClient = _azureStorage.GetBlobContainerClient($"{name}");
- string scope = "private";
- scope = $"{_scope}";
- var tb = "Teacher";
- if (scope != "private")
- {
- tb = "School";
- }
- long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
- foreach (var prefix in prefixs)
- {
- List<string> items = await ContainerClient.List(prefix);
- foreach (var item in items)
- {
- var urlsSize = await ContainerClient.GetBlobsSize(item);
- Bloblog bloblog = new Bloblog { id = Guid.NewGuid().ToString(), code = $"Bloblog-{name}", pk = "Bloblog", time = now, size = urlsSize != null && urlsSize.HasValue ? urlsSize.Value : 0, type = prefix };
- await client.GetContainer(Constant.TEAMModelOS, tb).UpsertItemAsync(bloblog, new Azure.Cosmos.PartitionKey(bloblog.code));
- }
- }
- return new OkObjectResult(new { });
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"TEAMModelFunction,ActivityHttpTrigger,fix-blob-content()\n{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
- return new BadRequestResult();
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- //[AuthToken(Roles = "teacher")]
- [HttpPost("get-DownloadContent-item")]
- public async Task<IActionResult> DownloadContentItem(JsonElement request)
- {
- ItemBlob itemBlob = null;
- try
- {
- BlobDownloadInfo blobDownloadResult = await _azureStorage.GetBlobContainerClient($"hbcn").GetBlobClient($"/item/12b865c9-a223-278a-2be1-e336b9ead99e/12b865c9-a223-278a-2be1-e336b9ead99e.json")
- .DownloadAsync();
- if (blobDownloadResult != null)
- {
- var json = JsonDocument.Parse(blobDownloadResult.Content);
- itemBlob = json.RootElement.ToObject<ItemBlob>();
- }
- }
- catch (Exception ex)
- {
- itemBlob = null;
- }
- return Ok(new { itemBlob });
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- //[AuthToken(Roles = "teacher")]
- [HttpPost("get-bind-data")]
- public async Task<IActionResult> GetData(JsonElement request)
- {
- var areaId = request.GetProperty("areaId");
- var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
- List<ScTeacher> teachers = await table.FindListByDict<ScTeacher>(new Dictionary<string, object> { { "PartitionKey", "ScTeacher" }, { "areaId", $"{areaId}" } });
- return Ok(teachers.Select(x => new { x.areaId, x.PXID, x.TID, x.TeacherName, x.tmdid, x.SchoolName, x.DisName }));
- }
- /// 删除
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [AuthToken(Roles = "admin,teacher")]
- [HttpPost("get-save-log")]
- public async Task<IActionResult> SaveLog(JsonElement request)
- {
- BlobDownloadResult Recording = await _azureStorage.GetBlobContainerClient("1595321354").GetBlobClient($"records/271528531841781760/Record/.Recording.json").DownloadContentAsync();
- var json = Recording.Content.ToString();
- var jsonByte = Encoding.UTF8.GetBytes(json);
- Stream stream = new MemoryStream(jsonByte);
- var doc = JsonDocument.Parse(stream);
- School school = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>("hbcn", new PartitionKey("Base"));
- _ = _azureStorage.SaveLog("find-school", school.ToJsonString(), httpContext: HttpContext, dingDing: _dingDing, scope: "school");
- return Ok(new { doc, school, });
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- //[AuthToken(Roles = "teacher")]
- [HttpPost("get-ip")]
- public async Task<IActionResult> GetIp(JsonElement request)
- {
- try
- {
- BlobDownloadResult baseblobDownload = await _azureStorage.GetBlobContainerClient("habook").GetBlobClient($"/records/299813002894381056/IES/Base.json").DownloadContentAsync();
- LessonBase lessonBase = baseblobDownload.Content.ToObjectFromJson<LessonBase>();
- return Ok(lessonBase);
- }
- catch (RequestFailedException ex) when (ex.Status == 404)
- {
- return BadRequest("文件不存在!");
- }
- LessonBase lessonBases = request.ToObject<LessonBase>();
- //List<TmdInfo> tmds= request.ToObject<List<TmdInfo>>();
- //var content = new StringContent(tmds.Select(x=>x.id).ToJsonString(), Encoding.UTF8, "application/json");
- //string json = await _coreAPIHttpService.GetUserInfos(content);
- //string _researchKey = Regex.Replace($"{request.GetProperty("key")}", "[ \\[ \\] \\^ \\-|()【】/' {}_*×――(^)$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]", " ");
- //string[] mm = Regex.Split(_researchKey, "\\s+", RegexOptions.IgnoreCase);
- //var token = await CoreTokenExtensions.CreateAccessToken("c7317f88-7cea-4e48-ac57-a16071f7b884", "kguxh:V.PLmxBdaI@jnrTrDSth]A3346", "China");
- //string ip = await _searcher.SearchIpAsync($"{request.GetProperty("ip")}");
- // return Ok(new { activity, ip, token.AccessToken,token.TokenType,token.IdToken, mm });
- return Ok(lessonBases);
- }
- /// 删除
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("check-online-record")]
- public async Task<IActionResult> CheckOnlinerecord(JsonElement request)
- {
- string sql = $"select c.id,c.name ,b.schoolId as code from c join b in c.schools where b.areaId='9ae614ba-0771-4502-a56e-0537bc5207c3'";
- List<IdNameCode> codes = new List<IdNameCode>();
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetItemQueryIterator<IdNameCode>(sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
- {
- codes.Add(item);
- }
- List<dynamic> data = new List<dynamic>(); ;
- foreach (IdNameCode code in codes)
- {
- try
- {
- TeacherTrain train = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<TeacherTrain>(code.id, new PartitionKey($"TeacherTrain-{code.code}"));
- data.Add(new { code.id, code.name, code.code, train.totalTime, train.onlineTime, train.classTime, train.offlineTime });
- }
- catch (Exception ex)
- {
- data.Add(new { code.id, code.name, code.code, totalTime = 0, onlineTime = 0, classTime = 0, offlineTime = 0 });
- }
- }
- return Ok(new { data });
- }
- [HttpPost("test-scteacher")]
- public async Task<IActionResult> TestScteacher(JsonElement json)
- {
- var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
- List<ScTeacher> teachers = await table.FindListByDict<ScTeacher>(new Dictionary<string, object>() { { "PartitionKey", "ScTeacher" }, { "areaId", "e6fb5d40-bd85-7327-cea8-ea5c642836d2" }, { "SchoolName", "岳池县大佛初级中学校" } });
- //var techs= teachers.Where(t => string.IsNullOrWhiteSpace(t.tmdid));
- return Ok(teachers);
- }
- [HttpPost("get-token")]
- public async Task<IActionResult> GetToken(JsonElement request)
- {
- if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
- if (!request.TryGetProperty("host", out JsonElement host)) return BadRequest();
- if (!request.TryGetProperty("name", out JsonElement name)) return BadRequest();
- if (!request.TryGetProperty("picture", out JsonElement picture)) return BadRequest();
- if (!request.TryGetProperty("areaId", out JsonElement areaId)) return BadRequest();
- if (!request.TryGetProperty("school", out JsonElement school)) return BadRequest();
- var auth_token = JwtAuthExtension.CreateAuthToken(host.ToString(), id.ToString(), name.ToString(),
- picture.ToString(), _option.JwtSecretKey,
- scope: "student", Website: "IES", areaId: areaId.ToString(),schoolID: school.ToString(), roles: new[] { "student" }, expire: 1);
- //var techs= teachers.Where(t => string.IsNullOrWhiteSpace(t.tmdid));
- return Ok(auth_token);
- }
- [HttpPost("test-scteacher-dn")]
- public async Task<IActionResult> TestScteacherDn(JsonElement json)
- {
- var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
- string sqls = "select distinct value(c.id )from c where c.code='Base' and IS_DEFINED(c.finalScore)=true ";
- //https://teammodelos.blob.core.chinacloudapi.cn/teammodelos
- //https://teammodelos.blob.core.chinacloudapi.cn/teammodelos/yxpt%2Fjinniu%2Fscbind%2F1647432004.json
- List<ScTeacher> teachers = await table.FindListByDict<ScTeacher>(new Dictionary<string, object>() { { "PartitionKey", "ScTeacher" }, { "areaId", "870a5a6b-1ab3-461a-bdeb-baec19780ddb" } });
- List<string> ids = new List<string>();
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher)
- .GetItemQueryIterator<string>(sqls, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
- {
- ids.Add(item);
- }
- long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
- List<string> erorr = new List<string>();
- List<ScTeacher> teachersUp = new List<ScTeacher>();
- foreach (var id in ids)
- {
- try
- {
- BlobDownloadResult baseblobDownload = await _azureStorage.GetBlobContainerClient("teammodelos").GetBlobClient($"/yxpt/jinniu/scbind/{id}.json").DownloadContentAsync();
- ScBindData scBindData = baseblobDownload.Content.ToObjectFromJson<ScBindData>();
- var tcd = teachers.Find(x => x.RowKey.Equals(scBindData.pxid));
- if (tcd != null)
- {
- Teacher teacher = new Teacher
- {
- createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
- pk = "Base",
- code = "Base",
- id = id,
- name = scBindData.username,
- size = 2,
- defaultSchool = tcd.schoolCode,
- schools = new List<TeacherSchool> {
- new TeacherSchool
- {
- schoolId = tcd.schoolCode, status = "join", time = now, name = scBindData.sn, areaId = tcd.areaId
- }
- },
- binds = new List<ThirdBind> {
- new ThirdBind
- {
- type= "scsyxpt",userid=scBindData.userid,username= scBindData.username,account=scBindData.account,data=new List<string>{ scBindData.ToJsonString()}
- }
- }
- };
- await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).UpsertItemAsync(teacher, new PartitionKey("Base"));
- tcd.tmdid = id;
- teachersUp.Add(tcd);
- }
- }
- catch (Exception)
- {
- erorr.Add(id);
- }
- }
- await table.SaveOrUpdateAll(teachersUp);
- return Ok();
- }
- [HttpPost("fix-jinniupujiang-teacher-videotime")]
- public async Task<IActionResult> GetScteacher(JsonElement json)
- {
- if (!json.TryGetProperty("areaId", out JsonElement _areaId)) { return BadRequest(); }
- Area area = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).ReadItemAsync<Area>($"{_areaId}", new PartitionKey("Base-Area"));
- AreaSetting setting = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).ReadItemAsync<AreaSetting>($"{_areaId}", new PartitionKey("AreaSetting"));
- List<string> teachers = new List<string>();
- //获取这个区的教师 //psywgy
- string schoolSql = $"SELECT value c.id FROM c join a in c.schools where a.areaId='{_areaId}' and c.code='Base' ";
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher)
- .GetItemQueryIterator<string>(schoolSql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
- {
- teachers.Add(item);
- }
- //获取这些老师的研修记录
- string tr = $"SELECT distinct value(c) FROM c join a in c.currency.teacherAilities where c.id in ({string.Join(",", teachers.Select(x => $"'{x}'"))}) and c.pk='TeacherTrain' and a.videoTime<300 ";
- List<TeacherTrain> teacherTrains = new List<TeacherTrain>();
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher)
- .GetItemQueryIterator<TeacherTrain>(tr, requestOptions: new QueryRequestOptions { }))
- {
- if (!item.tmdid.Equals("1528783259") || !item.tmdid.Equals("1530606136"))
- {
- teacherTrains.Add(item);
- }
- }
- //获取这个区的能力点树状结构
- string sql = $" select distinct value(b.id ) from c join b in c.children where c.code='AbilityTask-{area.standard}' ";
- List<string> nodeIdsDB = new List<string>();
- await foreach (var y in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).GetItemQueryIterator<string>
- (sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"AbilityTask-{area.standard}") }))
- {
- nodeIdsDB.Add(y);
- }
- List<AbilitySub> abilitySubs = new List<AbilitySub>();
- List<TeacherVideoTime> teacherVideoTimes = new List<TeacherVideoTime>();
- string ids = teacherTrains.Select(x => x.id).ToJsonString();
- string sqls = $" select value(c) from c where c.code='AbilityTask-{area.standard}'";
- List<AbilityTask> abilityTasks = new List<AbilityTask>();
- Dictionary<string, RecordFileAbility> valuePairs = new Dictionary<string, RecordFileAbility>();
- await foreach (var y in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).GetItemQueryIterator<AbilityTask>
- (sqls, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"AbilityTask-{area.standard}") }))
- {
- abilityTasks.Add(y);
- }
- foreach (var item in teacherTrains)
- {
- List<TeacherAbility> teacherAbility = new List<TeacherAbility>();
- if (item.currency.teacherAilities.Count() > 3)
- {
- //如果选择了大于三个能力点的教师,则优先获取上传了认证材料的的能力点,
- var uploadHas = item.currency.teacherAilities.FindAll(x => x.uploadHas == 1 && x.videoTime < 300);
- if (uploadHas.Any())
- {
- teacherAbility.AddRange(uploadHas);
- }
- if (teacherAbility.Count < 3)
- {
- // 如果仍然未满足数量。则再去获取 没有上传认证材料,但是又有学习时间长的能力点。
- var hasVideoTime = item.currency.teacherAilities.FindAll(x => x.uploadHas != 1 && x.videoTime < 300).OrderByDescending(o => o.videoTime);
- var disCount = 3 - teacherAbility.Count;
- teacherAbility.AddRange(hasVideoTime.Take(disCount));
- }
- }
- else
- {
- teacherAbility.AddRange(item.currency.teacherAilities.Where(ab => ab.videoTime < 300));
- }
- TeacherFile teacherFile = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<TeacherFile>(item.id, new PartitionKey($"TeacherFile-{item.code.Replace("TeacherTrain-", "")}"));
- foreach (var ability in teacherAbility)
- {
- TeacherVideoTime teacherVideoTime = new TeacherVideoTime { code = item.code.Replace("TeacherTrain-", ""), id = item.id, abilityId = ability.id, no = ability.no, train_time = ability.videoTime };
- double fileview = 0;
- var filerecord = teacherFile.fileRecords.FindAll(x => x.files.Where(y => y.abilityId.Equals(ability.id)).Count() > 0);
- filerecord.ForEach(x => {
- var file = x.files.FindAll(y => y.abilityId.Equals($"{ability.id}"));
- if (file.IsNotEmpty())
- {
- fileview += x.view;
- }
- });
- double fminut = fileview / 60;
- teacherVideoTime.files_time = fminut;
- var tech = abilityTasks.FindAll(x => x.abilityId.Equals(ability.id));
- // double limit = 0;
- tech.ForEach(task =>
- {
- task.children.ForEach(y =>
- {
- y.rnodes.ForEach(r =>
- {
- if (valuePairs.ContainsKey(r.hash))
- {
- valuePairs.TryGetValue(r.hash, out var value);
- var ablt = value.fileAbilities.Find(z => z.abilityId.Equals(task.abilityId) && z.taskId.Equals(task.id) && z.nodeId.Equals(y.id));
- if (ablt == null)
- {
- value.fileAbilities.Add(new FileAbility { url = r.link, abilityId = task.abilityId, taskId = task.id, nodeId = y.id });
- // limit = limit + r.duration;
- }
- }
- else
- {
- valuePairs.Add(r.hash, new RecordFileAbility
- {
- fileRecord =
- new FileRecord { hash = r.hash, size = r.size.Value, duration = r.duration, view = (int)r.duration, type = r.type, done = true },
- fileAbilities = new List<FileAbility> { new FileAbility { url = r.link, abilityId = task.abilityId, taskId = task.id, nodeId = y.id } }
- });
- // limit = limit + r.duration;
- }
- });
- });
- });
- HashSet<string> childIds = new HashSet<string>();
- foreach (var ps in valuePairs)
- {
- HashSet<string> abilityIds = teacherFile.fileRecords.SelectMany(x => x.files).Select(x => x.abilityId).Where(abid => abid.Equals(ability.id)).ToHashSet();
- double view = 0;
- foreach (var abid in abilityIds)
- {
- var record = teacherFile.fileRecords.FindAll(x => x.files.Where(y => y.abilityId.Equals(abid)).Count() > 0);
- record.ForEach(x => {
- var file = x.files.FindAll(y => y.abilityId.Equals($"{abid}"));
- if (file.IsNotEmpty())
- {
- view += x.view;
- }
- });
- }
- double minut = view / 60;
- teacherVideoTime.after_time = minut;
- if (minut < 300)
- {
- var fils = teacherFile.fileRecords.Find(x => x.hash.Equals(ps.Key));
- if (fils != null)
- {
- ps.Value.fileAbilities.ForEach(x =>
- {
- var a = fils.files.Find(z => z.nodeId.Equals(x.nodeId) && z.abilityId.Equals(x.abilityId));
- if (a == null)
- {
- childIds.Add(x.nodeId);
- fils.files.Add(new FileAbility { url = x.url, abilityId = x.abilityId, taskId = x.taskId, nodeId = x.nodeId });
- }
- });
- }
- else
- {
- ps.Value.fileAbilities.ForEach(x =>
- {
- childIds.Add(x.nodeId);
- });
- teacherFile.fileRecords.Add(new FileRecord
- {
- hash = ps.Value.fileRecord.hash,
- size = ps.Value.fileRecord.size,
- duration = ps.Value.fileRecord.duration,
- view = (int)ps.Value.fileRecord.view,
- type = ps.Value.fileRecord.type,
- done = true,
- files = ps.Value.fileAbilities
- });
- }
- }
- else
- {
- break;
- }
- }
- if (childIds.Any())
- {
- string code = teacherFile.code.Replace("TeacherFile-", "");
- if (!string.IsNullOrWhiteSpace(code))
- {
- try
- {
- AbilitySub abilitySub = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<AbilitySub>(ability.id, new PartitionKey($"AbilitySub-{code}-{teacherFile.id}"));
- var taskIds = abilitySub.taskRcds.Select(x => x.id);
- var notin = childIds.Except(taskIds);
- if (notin.Any())
- {
- abilitySub.taskRcds.AddRange(notin.Select(x => new AbilityTaskRcd { id = x, done = true }));
- abilitySubs.Add(abilitySub);
- }
- await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReplaceItemAsync(abilitySub, abilitySub.id, new PartitionKey($"AbilitySub-{code}-{teacherFile.id}"));
- }
- catch (Exception ex)
- {
- }
- }
- }
- teacherVideoTimes.Add(teacherVideoTime);
- }
- teacherFile = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReplaceItemAsync<TeacherFile>(teacherFile, teacherFile.id, new PartitionKey(teacherFile.code));
- item.update.Add(StatisticsService.TeacherAbility);
- await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReplaceItemAsync<TeacherTrain>(item, item.id, new PartitionKey(item.code));
- }
- var data = teacherVideoTimes.GroupBy(x => x.code).Select(x => new { x.Key, count = x.ToList().Count, list = x.ToList() }).OrderByDescending(x => x.count);
- return Ok(new { data, abilitySubs });
- }
- public class TeacherVideoTime
- {
- public string code { get; set; }
- public string id { get; set; }
- public string abilityId { get; set; }
- public string no { get; set; }
- public double train_time { get; set; }
- public double files_time { get; set; }
- public double after_time { get; set; }
- }
- [HttpPost("get-teacher-video")]
- public async Task<IActionResult> GetScteacherClassVideo(JsonElement json)
- {
- string sql = " SELECT c.id ,c.school as code FROM c where c.pk='ClassVideo' and c.school<>'SYSTEM_NO_SCHOOL' and ARRAY_LENGTH(c.files)>0 ";
- List<IdNameCode> idNameCodes = new List<IdNameCode>();
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetItemQueryIterator<IdNameCode>(sql, requestOptions: new QueryRequestOptions { }))
- {
- idNameCodes.Add(item);
- }
- foreach (var item in idNameCodes)
- {
- try
- {
- TeacherTrain teacherTrain = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<TeacherTrain>(item.id, new PartitionKey($"TeacherTrain-{item.code}"));
- if (!teacherTrain.teacherClasses.Any())
- {
- teacherTrain.update.Add("TeacherClass");
- await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReplaceItemAsync<TeacherTrain>(teacherTrain, teacherTrain.id, new PartitionKey($"TeacherTrain-{item.code}"));
- }
- }
- catch (Exception ex)
- {
- continue;
- }
- }
- return Ok();
- }
- [HttpPost("test-batch")]
- public async Task<IActionResult> TestBatchFUN(JsonElement json)
- {
- List<Task<ItemResponse<TestBatch>>> nameCodes = new List<Task<ItemResponse<TestBatch>>>();
- for (int i = 0; i < 10; i++)
- {
- nameCodes.Add(_azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).
- CreateItemAsync(new TestController.TestBatch { id = Guid.NewGuid().ToString(), code = $"TestBatch-{i}", pk = "TestBatch" }, new PartitionKey($"TestBatch-{i}")));
- }
- await Task.WhenAll(nameCodes);
- return Ok();
- }
- public class TestBatch : CosmosEntity
- {
- }
- [HttpPost("export-teacher")]
- public async Task<IActionResult> ExportTeacher(JsonElement json)
- {
- List<string> schools = new()
- {
- "dghznx",
- "cxhhlx",
- "xjaxx",
- "zjqxx",
- "xnygxx",
- "lxxcfx",
- "gxjrxx",
- "cdgxsx",
- "yzxx",
- "kjyxx",
- "wjylxx",
- "dsgjxx",
- "ydzt",
- "xndbxx",
- "sqtszx",
- "cdxczx",
- "ghsyzx",
- "lqsx",
- "cdxxps",
- "xcfx",
- "xyqxx",
- "xncbyy",
- "cdlqjk",
- "lqdmxx",
- "lqyx",
- "pclxxx",
- "cdfzx",
- "xnblxx",
- "ghsx",
- "khdycz",
- "khbmxx",
- "khdecz",
- "khzx",
- "khhbzx",
- "gxxcxx",
- "khhtxx",
- "khdxxx",
- "khsyxx"
- };
- var cosmosClient = _azureCosmos.GetCosmosClient();
- foreach (var item in schools)
- {
- School school = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemAsync<School>($"{item}", new PartitionKey("Base"));
- List<Teacher> teachers = new();
- await foreach (var tch in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<Teacher>(queryText:
- $"SELECT value(c) FROM c join s in c.schools where s.schoolId='{item}' and c.code='Base'",
- requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
- {
- teachers.Add(tch);
- }
- if (teachers.Count > 0)
- {
- foreach (var teacher in teachers)
- {
- teacher.schools.ForEach(tch => { if (tch.schoolId.Equals(item)) { tch.areaId = school.areaId; } });
- await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey("Base"));
- }
- }
- }
- return Ok();
- }
- public class RecordFileAbility
- {
- public FileRecord fileRecord { get; set; }
- public List<FileAbility> fileAbilities { get; set; }
- }
- [HttpPost("test-blob-folder")]
- public async Task<IActionResult> TestBlobFolder(JsonElement json)
- {
- string location = _option.Location;
- bool lockKey = await _azureRedis.GetRedisClient(8).KeyExistsAsync($"LessonRecord:Unused:Lock:{location}");
- //key不存在的时候 。
- if (!lockKey)
- {
- var schoolKeys = new List<IdCodeCount>();
- var teacherKeys = new List<IdCodeCount>();
- string sql = "select value c.id from c where c.code='Base'";
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).
- GetItemQueryIterator<string>(queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
- {
- teacherKeys.Add(new IdCodeCount { id = item, code = "Teacher" });
- }
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).
- GetItemQueryIterator<string>(queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
- {
- schoolKeys.Add(new IdCodeCount { id = item, code = "School" });
- }
- string sqlcount = "select value count(1) from c where c.pk='LessonRecord'";
- foreach (var key in schoolKeys)
- {
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).
- GetItemQueryIterator<int>(queryText: sqlcount, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"LessonRecord-{key.id}") }))
- {
- key.count = item;
- break;
- }
- }
- foreach (var key in teacherKeys)
- {
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).
- GetItemQueryIterator<int>(queryText: $"select value count(1) from c where c.pk='LessonRecord' and c.tmdid='{key.id}'",
- requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"LessonRecord") }))
- {
- key.count = item;
- break;
- }
- }
- schoolKeys.AddRange(teacherKeys);
- //以下代码作用,用于根据当前拥有的课例数判断区分学校和个人使用课例频率越多的,
- //并均分每次需要处理的学校和个人容器个数,避免每次处理批次花费时间相差太大。
- //将每个批次处理数量级控制在500-1000左右。
- List<IEnumerable<IdCodeCount>> counts = new List<IEnumerable<IdCodeCount>>();
- //501-∞
- var count501_ = schoolKeys.Where(x => x.count >= 501); //至少500条
- counts.AddRange(count501_.Page(1));//1个学校
- //201-500
- var count201_500 = schoolKeys.Where(x => x.count >= 201 && x.count <= 500); //至少402条-1000条
- counts.AddRange(count201_500.Page(2));//2个学校
- //100-200
- var count100_200 = schoolKeys.Where(x => x.count >= 100 && x.count <= 200);//至少500条-1000条
- counts.AddRange(count100_200.Page(5));//5个学校
- //51-99
- var count51_99 = schoolKeys.Where(x => x.count >= 51 && x.count <= 99);//至少500条-990条
- counts.AddRange(count51_99.Page(10));//10个学校
- //21-50
- var count21_50 = schoolKeys.Where(x => x.count >= 21 && x.count <= 50);//至少410条-1000条
- counts.AddRange(count21_50.Page(20));//20个学校
- //10-20
- var count10_20 = schoolKeys.Where(x => x.count >= 10 && x.count <= 20);//至少500条-1000条
- counts.AddRange(count10_20.Page(50));//50个学校
- //5-9
- var count0_9 = schoolKeys.Where(x => x.count >= 5 && x.count <= 9);//至少500条-900条
- counts.AddRange(count0_9.Page(100));//100个学校
- //2-4
- var count2_4 = schoolKeys.Where(x => x.count >= 2 && x.count <= 4);//至少500条-1000条
- counts.AddRange(count2_4.Page(250));
- //0-1
- var count0_1 = schoolKeys.Where(x => x.count >= 0 && x.count <= 1);//至少500,就算没有课例也算一次。
- counts.AddRange(count0_1.Page(500));
- int field = 1;
- counts.Count();
- foreach (var item in counts)
- {
- bool stuallstatus = await _azureRedis.GetRedisClient(8).HashSetAsync($"LessonRecord:Unused:Lock:{location}", field, new { status = 0, item }.ToJsonString());
- field += 1;
- }
- await _dingDing.SendBotMsg($"{location},获取到:{schoolKeys.Count} 个学校和个人的容器\n" +
- $"大概要处理:{schoolKeys.Sum(x => x.count) + schoolKeys.Where(x => x.count >= 0).Count()} 条数据\n" +
- $"将数据分为:{field - 1} 次处理,每次处理500-1000条数据。", GroupNames.醍摩豆服務運維群組);
- }
- return Ok(new { });
- }
- public class IdCodeCount
- {
- public string id { get; set; }
- public string code { get; set; }
- public int count { get; set; }
- }
- /// <summary>
- /// 随机获取三个不同类型的题目
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [HttpPost("gen-pdf")]
- //[Authorize(Roles = Constant.Role_Root)]
- public IActionResult GenPdf(JsonElement json)
- {
- //https://article.itxueyuan.com/JAxOnG
- //http://t.zoukankan.com/hsiang-p-14608694.html
- //https://github.com/rdvojmoc/DinkToPdf
- //https://blog.csdn.net/u011966339/article/details/114964016?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_baidulandingword~default-0-114964016-blog-118609642.pc_relevant_antiscanv2&spm=1001.2101.3001.4242.1&utm_relevant_index=3
- var html = @"
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset=""UTF-8"">
- <meta http-equiv=""X-UA-Compatible"" content=""IE=edge"">
- <meta name=""viewport"" content=""width=device-width, initial-scale=1.0"">
- <title>校本研修活动完成情况</title>
- <style>
- body {
- font-family: ""fangsong"";
- display: flex;
- flex-direction: column;
- align-items: center;
- }
- .tch-table,
- .details-table {
- width: 100%;
- }
- .tch-table table {
- width: 100%;
- margin: 15px 0;
- border: 0;
- }
- .tch-table th {
- background-color: #c5c5c5;
- color: #222222;
-
- }
- .tch-table,
- .tch-table th,
- .tch-table td {
- font-size: 0.95em;
- text-align: center;
- padding: 4px;
- border-collapse: collapse;
- font-weight: bolder;
- }
- .tch-table th,
- .tch-table td {
- border-bottom: 1px solid #918b8c;
- border-width: 1px 0 1px 0;
- }
- .tch-table tr {
- border: 1px solid #ffffff;
- height: 3.2em;
- }
- .title {
- font-weight: bold;
- align-self: flex-start;
- margin: 30px 5px;
- }
- .title::before {
- content: """";
- width: 10px;
- height: 10px;
- background: #3a3a3a;
- display: inline-block;
- margin-right: 10px;
- }
- </style>
- </head>
- <body>
- <h1 style=""text-align:center;font-weight: bold;"">校本研修活动完成情况</h1>
- <p class=""title"">教师信息</p>
- <table class=""tch-table"" id=""tchTable"">
- <tr>
- <th style=""width: 33.3%;"">教师姓名</th>
- <th style=""width: 33.3%;"">机构</th>
- <th style=""width: 33.3%;"">教研组</th>
- </tr>
- <tr>
- <td>张三</td>
- <td>四川省成都市盐道街中学</td>
- <td>高中政治教研组</td>
- </tr>
- </table>
- <p class=""title"">活动明细</p>
- <table class=""tch-table"" id=""acTable"">
- <tr>
- <th style=""width: 25%;"">活动主题</th>
- <th style=""width: 15%;"">活动类型</th>
- <th style=""width: 5%;"">任务学时</th>
- <th style=""width: 5%;"">完成学时</th>
- <th style=""width: 20%;"">活动时间</th>
- <th style=""width: 10%;"">活动内容</th>
- <th style=""width: 10%;"">活动任务</th>
- <th style=""width: 10%;"">状态</th>
- </tr>
- <tr>
- <td>语文学科如何在A1技术支持下进行学情分析</td>
- <td>信息化教学案例展示与分享</td>
- <td>1</td>
- <td>1</td>
- <td>2022-04-07 到 2022-04-14</td>
- <td></td>
- <td>扫码签到、作业提交、问卷反馈、评测活动</td>
- <td>已完成</td>
- </tr>
- </table>
- </body>
- </html>
- ";
- try
- {
- GlobalSettings globalSettings = new GlobalSettings();
- globalSettings.ColorMode = ColorMode.Color;
- globalSettings.Orientation = Orientation.Portrait;
- globalSettings.PaperSize = PaperKind.A4;
- globalSettings.Margins = new MarginSettings { Top = 25, Bottom = 25 };
- ObjectSettings objectSettings = new ObjectSettings();
- objectSettings.PagesCount = true;
- objectSettings.HtmlContent = html;
- //WebSettings webSettings = new WebSettings();
- //webSettings.DefaultEncoding = "utf-8";
- HeaderSettings headerSettings = new HeaderSettings();
- headerSettings.FontSize = 15;
- headerSettings.FontName = "fangsong";
- headerSettings.Right = "";
- // headerSettings.Line = true;
- FooterSettings footerSettings = new FooterSettings();
- footerSettings.FontSize = 12;
- footerSettings.FontName = "Ariel";
- footerSettings.Center = "校本研修活动完成情况([page]/[toPage])页";
- // footerSettings.Line = true;
- objectSettings.HeaderSettings = headerSettings;
- objectSettings.FooterSettings = footerSettings;
- //objectSettings.WebSettings = webSettings;
- HtmlToPdfDocument htmlToPdfDocument = new HtmlToPdfDocument()
- {
- GlobalSettings = globalSettings,
- Objects = { objectSettings },
- };
- var a = _converter.Convert(htmlToPdfDocument);
- MemoryStream m = new MemoryStream(a);
- FileStream fs = new FileStream("F:\\1111111111111\\SimplePdf1.pdf", FileMode.Create, FileAccess.Write, FileShare.Read);
- m.WriteTo(fs);
- m.Close();
- fs.Close();
- var doc = new HtmlToPdfDocument()
- {
- GlobalSettings = {
- ColorMode = ColorMode.Color,
- Orientation = Orientation.Portrait,
- PaperSize = PaperKind.A4,
- Margins = new MarginSettings() { Top = 10 },
- Out = @"F:\test.pdf",
- },
- Objects = {
- new ObjectSettings()
- {
- Page = "https://teammodelos.blob.core.chinacloudapi.cn/0-public/pie-borderRadius.html",
- },
- }
- };
- _converter.Convert(doc);
- return Ok();
- // return Ok(File(a, "application/octet-stream", "SimplePdf.pdf"));
- }
- catch (Exception ex)
- {
- return BadRequest(new { ex = ex.StackTrace, exmsg = ex.Message });
- }
- }
- }
- }
|