TestController.cs 108 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271
  1. using Azure;
  2. using Azure.Core;
  3. using Azure.Cosmos;
  4. using Azure.Messaging.ServiceBus;
  5. using Azure.Storage.Blobs;
  6. using Azure.Storage.Blobs.Models;
  7. using Azure.Storage.Blobs.Specialized;
  8. using DinkToPdf;
  9. using DinkToPdf.Contracts;
  10. using DocumentFormat.OpenXml.Drawing.Wordprocessing;
  11. using DocumentFormat.OpenXml.Office2010.Excel;
  12. using DocumentFormat.OpenXml.Office2016.Excel;
  13. using DocumentFormat.OpenXml.Presentation;
  14. using DocumentFormat.OpenXml.Wordprocessing;
  15. using HTEXLib.COMM.Helpers;
  16. using HTEXLib.Helpers.ShapeHelpers;
  17. using MathNet.Numerics.Distributions;
  18. using Microsoft.AspNetCore.Hosting;
  19. using Microsoft.AspNetCore.Http;
  20. using Microsoft.AspNetCore.Mvc;
  21. using Microsoft.Extensions.Configuration;
  22. using Microsoft.Extensions.Options;
  23. using Microsoft.International.Converters.PinYinConverter;
  24. using Microsoft.International.Converters.TraditionalChineseToSimplifiedConverter;
  25. using Newtonsoft.Json;
  26. using OpenXmlPowerTools;
  27. using StackExchange.Redis;
  28. using System;
  29. using System.Collections.Concurrent;
  30. using System.Collections.Generic;
  31. using System.IO;
  32. using System.Linq;
  33. using System.Net;
  34. using System.Net.Http;
  35. using System.Net.Http.Json;
  36. using System.Runtime.Intrinsics.X86;
  37. using System.Security.Policy;
  38. using System.Text;
  39. using System.Text.Json;
  40. using System.Text.RegularExpressions;
  41. using System.Threading.Tasks;
  42. using TEAMModelOS.Controllers.Analysis;
  43. using TEAMModelOS.Controllers.Core;
  44. using TEAMModelOS.Controllers.Third.LePei;
  45. using TEAMModelOS.Filter;
  46. using TEAMModelOS.Models;
  47. using TEAMModelOS.SDK;
  48. using TEAMModelOS.SDK.DI;
  49. using TEAMModelOS.SDK.Extension;
  50. using TEAMModelOS.SDK.Helper.Common.DateTimeHelper;
  51. using TEAMModelOS.SDK.Models;
  52. using TEAMModelOS.SDK.Models.Cosmos.Common;
  53. using TEAMModelOS.SDK.Models.Cosmos.OpenEntity;
  54. using TEAMModelOS.SDK.Models.Service;
  55. using TEAMModelOS.SDK.Models.Service.BI;
  56. using TEAMModelOS.SDK.Services;
  57. using Top.Api;
  58. using static TEAMModelOS.SDK.Models.Teacher;
  59. using static TEAMModelOS.SDK.SchoolService;
  60. namespace TEAMModelOS.Controllers
  61. {
  62. [Route("test")]
  63. [ApiController]
  64. public class TestController : ControllerBase
  65. {
  66. private readonly IHttpClientFactory _httpClient;
  67. public IWebHostEnvironment _environment { get; set; }
  68. private readonly AzureStorageFactory _azureStorage;
  69. private readonly AzureRedisFactory _azureRedis;
  70. private readonly AzureCosmosFactory _azureCosmos;
  71. private readonly DingDing _dingDing;
  72. private readonly AzureServiceBusFactory _serviceBus;
  73. private readonly CoreAPIHttpService _coreAPIHttpService;
  74. private readonly Option _option;
  75. private readonly IPSearcher _searcher;
  76. public IConfiguration _configuration { get; set; }
  77. private readonly IConverter _converter;
  78. private readonly HttpTrigger _httpTrigger;
  79. 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)
  80. {
  81. _converter = converter;
  82. _azureCosmos = azureCosmos;
  83. _azureRedis = azureRedis;
  84. _azureStorage = azureStorage;
  85. _dingDing = dingDing;
  86. _serviceBus = serviceBus; _configuration = configuration;
  87. _environment = environment;
  88. _httpClient = httpClient;
  89. _option = option.Value;
  90. _coreAPIHttpService = coreAPIHttpService;
  91. _searcher = searcher;
  92. _httpTrigger = httpTrigger;
  93. }
  94. /// <summary>
  95. /// 测试五育画像数据推送
  96. /// </summary>
  97. /// <param name="json"></param>
  98. /// <returns></returns>
  99. [ProducesDefaultResponseType]
  100. [HttpPost("import-table")]
  101. public async Task<IActionResult> ImportTable(JsonElement json)
  102. {
  103. List<LPSchool> schools = json.ToObject<List<LPSchool>>();
  104. var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
  105. await table.BatchInsertAsync (schools);
  106. return Ok(schools);
  107. }
  108. /// <summary>
  109. /// 测试五育画像数据推送
  110. /// </summary>
  111. /// <param name="json"></param>
  112. /// <returns></returns>
  113. [ProducesDefaultResponseType]
  114. [HttpPost("test-upsert-student-portrait")]
  115. public async Task<IActionResult> TestUpsertStudentPortrait(JsonElement json) {
  116. var data = await _httpTrigger.RequestHttpTrigger(json, _option.Location, "upsert-student-portrait");
  117. return Ok(data.json.ToObject<JsonElement>());
  118. }
  119. /// <summary>
  120. ///
  121. /// </summary>
  122. /// <param name="json"></param>
  123. /// <returns></returns>
  124. [ProducesDefaultResponseType]
  125. [HttpPost("transform-lessonrecord-overalleducation")]
  126. public async Task<IActionResult> TransformLessonrecordOveralleducation(JsonElement json) {
  127. //string msg = json.ToString();
  128. //var ActiveTask = _configuration.GetValue<string>("Azure:ServiceBus:ActiveTask");
  129. //var messageChange = new ServiceBusMessage(msg);
  130. //messageChange.ApplicationProperties.Add("name", "LessonRecordEvent");
  131. //await _serviceBus.GetServiceBusClient().SendMessageAsync(ActiveTask, messageChange);
  132. string sql = "select value c from c where c.pk='StudentScoreRecord' and c.userType='student' and c.school<>null and c.school<>'' ";
  133. List<StudentScoreRecord> studentScores = new List<StudentScoreRecord>();
  134. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).GetItemQueryIterator<StudentScoreRecord>(sql)) {
  135. studentScores.Add(item);
  136. }
  137. var group = studentScores.GroupBy(z => z.school);
  138. string schoolSql = $"select value c from c where c.id in ({string.Join(",",group.Select(x=>$"'{x.Key}'"))})";
  139. var resultScool= await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).GetList<School>(schoolSql,"Base");
  140. foreach(var item in group)
  141. {
  142. var list = item.ToList();
  143. var stuids = list.Select(z => z.stuid);
  144. string studentSql = $"select value c from c where c.id in ({string.Join(",", stuids.Select(x => $"'{x}'"))})";
  145. var resultStuden = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).GetList<Student>(studentSql, $"Base-{item.Key}");
  146. foreach (var sturecord in list) {
  147. HashSet<OverallEducation> overallEducations = new HashSet<OverallEducation>();
  148. var studentBase = resultStuden.list.Find(x => x.id.Equals(sturecord.stuid, StringComparison.OrdinalIgnoreCase));
  149. var schoolBase = resultScool.list.Find(x => x.id.Equals(sturecord.school, StringComparison.OrdinalIgnoreCase));
  150. if (studentBase == null) {
  151. continue;
  152. }
  153. var period = schoolBase.period.Find(x => x.id.Equals($"{studentBase.periodId}"));
  154. foreach (var record in sturecord.lessonRecords) {
  155. if (record.time > 1000000000000) {
  156. (Semester currSemester, int studyYear, DateTimeOffset date, DateTimeOffset nextSemester) dataSemester = SchoolService.GetSemester(period, record.time);
  157. string oid = $"{dataSemester.studyYear}-{dataSemester.currSemester.id}-{sturecord.stuid}";
  158. string ocode = $"OverallEducation-{sturecord.school}";
  159. OverallEducation overallEducation = overallEducations.Where(o => o.id.Equals(oid, StringComparison.OrdinalIgnoreCase) && o.code.Equals(ocode, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
  160. if (overallEducation != null)
  161. {
  162. var hasrecord = overallEducation.lessonScore.Find(x => x.lessonId.Equals(record.lessonId));
  163. if (hasrecord != null)
  164. {
  165. hasrecord.gscore = record.gscore;
  166. hasrecord.pscore = record.pscore;
  167. hasrecord.tscore = record.tscore;
  168. hasrecord.tmdid = record.tmdid;
  169. hasrecord.school = record.school;
  170. hasrecord.scope = record.scope;
  171. hasrecord.lessonId = record.lessonId;
  172. hasrecord.courseId = record.courseId;
  173. hasrecord.periodId = record.periodId;
  174. hasrecord.subjectId = record.subjectId;
  175. hasrecord.time = record.time;
  176. }
  177. else
  178. {
  179. overallEducation.lessonScore.Add(
  180. new StudentLessonRecord
  181. {
  182. gscore = record.gscore,
  183. pscore = record.pscore,
  184. tscore = record.tscore,
  185. tmdid = record.tmdid,
  186. school = record.school,
  187. scope = record.scope,
  188. lessonId = record.lessonId,
  189. courseId = record.courseId,
  190. periodId = record.periodId,
  191. subjectId = record.subjectId,
  192. time = record.time
  193. }
  194. );
  195. }
  196. }
  197. else {
  198. Azure.Response response = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).ReadItemStreamAsync(oid, new PartitionKey(ocode));
  199. if (response.Status != 200)
  200. {
  201. overallEducation = new OverallEducation
  202. {
  203. id = oid,
  204. code = $"OverallEducation-{sturecord.school}",
  205. pk = "OverallEducation",
  206. ttl = -1,
  207. name = studentBase.name,
  208. classId = studentBase?.classId,
  209. schoolCode = $"{sturecord.school}",
  210. semesterId = dataSemester.currSemester.id,
  211. year = dataSemester.studyYear,
  212. periodId = $"{period.id}",
  213. stuYear = studentBase.year,
  214. studentId = studentBase.id,
  215. lessonScore = new List<StudentLessonRecord>
  216. {
  217. new StudentLessonRecord
  218. {
  219. gscore = record.gscore,
  220. pscore = record.pscore,
  221. tscore = record.tscore,
  222. tmdid = record.tmdid,
  223. school = record.school,
  224. scope = record.scope,
  225. lessonId = record.lessonId,
  226. courseId = record.courseId,
  227. periodId = record.periodId,
  228. subjectId = record.subjectId,
  229. time= record.time
  230. }
  231. }
  232. };
  233. }
  234. else
  235. {
  236. overallEducation = JsonDocument.Parse(response.Content).RootElement.ToObject<OverallEducation>();
  237. var hasrecord = overallEducation.lessonScore.Find(x => x.lessonId.Equals(record.lessonId));
  238. if (hasrecord != null)
  239. {
  240. hasrecord.gscore = record.gscore;
  241. hasrecord.pscore = record.pscore;
  242. hasrecord.tscore = record.tscore;
  243. hasrecord.tmdid = record.tmdid;
  244. hasrecord.school = record.school;
  245. hasrecord.scope = record.scope;
  246. hasrecord.lessonId = record.lessonId;
  247. hasrecord.courseId = record.courseId;
  248. hasrecord.periodId = record.periodId;
  249. hasrecord.subjectId = record.subjectId;
  250. hasrecord.time = record.time;
  251. }
  252. else
  253. {
  254. overallEducation.lessonScore.Add(
  255. new StudentLessonRecord
  256. {
  257. gscore = record.gscore,
  258. pscore = record.pscore,
  259. tscore = record.tscore,
  260. tmdid = record.tmdid,
  261. school = record.school,
  262. scope = record.scope,
  263. lessonId = record.lessonId,
  264. courseId = record.courseId,
  265. periodId = record.periodId,
  266. subjectId = record.subjectId,
  267. time = record.time
  268. }
  269. );
  270. }
  271. }
  272. overallEducations.Add(overallEducation);
  273. }
  274. }
  275. }
  276. foreach (var overallEducation in overallEducations) {
  277. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).UpsertItemAsync(overallEducation, partitionKey: new PartitionKey(overallEducation.code));
  278. }
  279. }
  280. }
  281. return Ok();
  282. }
  283. /// <summary>
  284. ///
  285. /// </summary>
  286. /// <param name="json"></param>
  287. /// <returns></returns>
  288. [ProducesDefaultResponseType]
  289. [HttpPost("check-art-result")]
  290. public async Task<IActionResult> CheckArtResult(JsonElement json)
  291. {
  292. List<StudentArtResult> art_idNames = new List<StudentArtResult>();
  293. string sqlSchool = "select value c from c where c.areaId='7a51072f-b329-4e74-99e0-ba0407ba8926'";
  294. List<School> schools = new List<School>();
  295. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School)
  296. .GetItemQueryIterator<School>(sqlSchool, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
  297. {
  298. schools.Add(item);
  299. }
  300. string sql = @"SELECT value c FROM c where c.pk='ArtResult' and c.artId in('770fbaaa-a9e8-4d45-a322-3c6d6e50a8f7',
  301. '1e59bb5f-984f-406d-83a2-48ef1ce60a75',
  302. '33fc9276-60c1-4663-8c42-2e44a138a874',
  303. '4eada95b-a408-4a66-bd6c-c61c6057d505',
  304. 'f61b32c6-2f86-4ae6-ac25-1961df0f443a',
  305. '4d974b69-e104-45db-8047-b4cbc43ebc98',
  306. 'efb8f6ed-74b9-43b7-b8e5-c61d92441ed9',
  307. '070d8ce5-253c-404b-80b7-12cbc234ddae',
  308. 'fdd6c34b-44c2-42e9-9cd4-66c01b7103da',
  309. 'b1cf6fed-a4ea-4d06-b15d-3941fba973de',
  310. '67cd2be9-e307-4d35-8249-6d4e7380d15c',
  311. 'f0481d0e-ab74-4117-8600-a375a206e283',
  312. '7a809ab3-4081-4a23-8127-9a362f9af8ff',
  313. '673684e2-1dc3-48d9-a21f-207cc40a68ba',
  314. '35e4da67-0fb9-4683-9fac-9c9b1c197f24',
  315. '893b9871-8518-4f70-97e5-58ceb4c1b504',
  316. '0cd4ea92-4697-468a-a2fd-2f0e1cd53525',
  317. 'd9fec69f-2532-408b-bc25-98a33edf7200',
  318. '02b68eed-29f2-49c1-a91f-c1e35dd8ce64',
  319. 'edaf8c12-9b0b-4b31-baff-3e9b926b401a',
  320. '472bbdc9-c287-4b18-9502-7f34d15172a8',
  321. '41f67e3c-6c7f-46e9-bc39-ec8d6ae9a495',
  322. 'ffea1c6b-3fb7-40d4-921b-e1dc46d15410',
  323. '079fa190-fc18-46b9-bcb9-a4b6e2cd902d',
  324. 'a0e778e8-2590-431e-b761-4929fa143762',
  325. '374a571a-6d5c-4a8a-ab57-6e79b8b8ff0a',
  326. '1db3838e-d7cd-4c77-af70-d3854262d33e',
  327. '7b8a2f53-3b90-48f1-bd0b-bb5be843656a',
  328. 'e5c24756-1ea3-46cf-8f0f-357ec280e42c',
  329. '1b713f31-7e0b-4cb5-84f1-0342db618a6d',
  330. '1794bc46-d0fb-4ea9-8ff8-2f813affe495',
  331. 'b9d54179-7eaf-426b-a44f-9018e6c4ffa7',
  332. '3145e47a-21e5-4cdf-a992-72b9e47c7bad',
  333. 'bdaab0b2-f8d0-4c1b-821c-95b4a2371c42',
  334. 'd39f74df-dc65-44d4-8463-41af1a4b186d',
  335. '79e83de1-4e64-4ef3-b24e-fe4e877e683b',
  336. 'bf3aaff3-1a86-42c8-89d7-4b9d6147d37f',
  337. 'ad3742eb-9e46-43f8-9644-ecb498082810',
  338. '66a3d74b-3946-42c3-a2d2-0bc6704c86ec',
  339. 'ec75e499-f432-41d4-b6dd-5548358b657d',
  340. '70ef5724-f875-4e2e-bda8-58fd2457c2a7',
  341. '60c03852-8c97-4cb0-a232-e0734eaebe96',
  342. '4eefe05d-3df9-4f27-804b-53dd7bc5f4ab',
  343. 'b82ff879-5474-4b31-b3e6-3174361a4fd0',
  344. '09489fef-5490-4b5e-802b-74d1be2c5515',
  345. '1a7d8d51-f828-4f15-9859-33937b41b9e4',
  346. '9e591e75-538e-426d-862d-b043c13e822a',
  347. '71cd894a-e82d-49ff-a204-a64a2eb6f332',
  348. '70103a11-095b-4d01-b3ea-0ed2e388445f',
  349. 'b40d4952-396d-49f3-ba2d-6aeba1d940d9',
  350. '149a12ae-7c5d-444c-ac34-17af88cf653e',
  351. '8c1b2180-4a81-4f6b-989a-b971dbeae082',
  352. '079107f5-7bf5-4955-a39c-85dec9715e60',
  353. 'f9abe967-dbce-46d7-a60f-d9a2e6866ec6',
  354. 'b4684520-cf0c-473c-aa3a-ea5ba5d398d3',
  355. '0839abf0-07e7-4c0d-b818-54d451a6265a',
  356. '6abc82c7-928b-43bf-8c5d-f5a5d7c55a4d',
  357. '544577d3-c4b0-491f-a041-18cc07e711ca',
  358. '2efddd68-0bbc-4dba-a594-f7f8532f519d',
  359. '725f2665-1015-4563-9044-f4061accdf67',
  360. '739aa426-a359-4515-85ef-1efe605c0b73',
  361. '8dcde32c-3a77-4bf5-84a3-ec4d7a78413d',
  362. '4a396e8b-babb-47ee-b6ed-db2124d5c39d',
  363. '55f4594b-c13b-48b8-82f1-563751d48e9e',
  364. '3cc1bd57-bf4e-4933-ac6b-7cdb0e8e2dc1',
  365. '380511bf-2b15-4b90-b8c8-3464c2c6e18c',
  366. '12378c30-0c1d-4c84-8deb-5aaffaa2b45c',
  367. 'e247abc3-7083-4de5-a492-46e09e9bb341',
  368. 'ef826295-7a00-483d-945b-589c8fc0baf9',
  369. 'c1b056c5-0ebf-454a-bb56-3f6024e837d2',
  370. 'c513fe45-767c-4632-b6d3-9631c9bf8854',
  371. '9f7d087e-ba53-4167-9776-1e33a9a1cb61',
  372. 'b5f1a3f0-975f-441c-b6d0-3b8513b96d24',
  373. '92560ac8-a3a5-4aff-85e6-b7f72fc7e2fb',
  374. '898a7705-47f3-4f3b-a01e-1ec609ad4abf',
  375. '4c4349a0-ade4-4793-a435-15de7f3c299e',
  376. '473707f1-6f43-4611-adca-263604aa8e58',
  377. '88ee65ec-ec5c-4c5a-8539-8a8e931508ce',
  378. '4b12c255-5f44-4056-8ab6-d33721394ab2',
  379. '1f2f9ad3-e465-4152-afce-26715e3902af',
  380. 'bba7590c-735a-41c3-a501-ab4285fc36e8',
  381. '51c7426f-934f-4a18-bc1f-053e994969cc',
  382. '9ec15578-a78b-4f9d-ae8c-f15677d03d0a',
  383. '6fc632fe-5833-4c26-a079-70f9a3fa1957',
  384. '86a886f5-e540-4f57-abfd-cee4e3d328ab',
  385. '66e50efa-c3c4-4e3e-8892-5ebdec85a008',
  386. '2b66ee3b-e74a-446a-a92d-9cdc11a43123',
  387. '09533510-ec3a-4c45-8220-097a2a7e4237',
  388. 'be879d1f-1ccd-4e5f-9871-449a736a9279',
  389. '2371ba86-0598-44eb-99de-c73b7cca15db',
  390. '77f87528-e5c0-4ddf-80ea-43d383f5e58e',
  391. '9b7aa0c9-6393-4337-95cd-2bf0c57a662c',
  392. '93811e7f-fa3f-4487-9310-ef28ba3530f4',
  393. '43ecedc4-45fa-4ab7-b87b-357be07b19fa',
  394. 'a7fa4f17-9a9e-4d0b-bca7-2edfdcd75afb',
  395. '3682bc09-96ab-4d17-9010-b9fc31dc72bd',
  396. '04eff65e-3e19-4b57-b3ba-f1f63f52b8ba',
  397. '9eaea71a-97c8-456d-afc4-97d00e2e83bd',
  398. 'e3d846fd-c9e7-44b1-966d-ba74b4953f54',
  399. '2db6561b-3657-418a-ba18-b726a86d1fb1',
  400. '93b32d4b-a918-4940-bcef-00fbeceff525',
  401. '18e6f96a-c4d3-4cca-9248-f7c9099c6706',
  402. '3e1866ed-c9d0-415f-a080-ed1b34704110',
  403. 'd4ee5661-646b-4a58-b2b8-ad309666d64e',
  404. 'b678edb6-4717-423f-a8ac-6abc80eeab97',
  405. 'e8d68e11-d1e9-4bc7-8e22-e426f50f70a2',
  406. '8e96efbd-b990-4e2e-ad43-49e9dae73794',
  407. '72793b29-c939-4201-82b8-7ded1e6c6fe5',
  408. '59b5a6bc-ae2a-4157-b262-bf7a4858aace',
  409. 'e6b642ef-4239-4063-b471-da5b987b6aeb',
  410. 'f5ebf426-b4bc-4744-a2f3-a35a22c6c326',
  411. 'a7e80ecb-2a53-4879-a0f4-d313f78d3c01',
  412. 'cf32535a-b754-4cee-a51d-be4dc2220a2f',
  413. '521c66d6-00cc-4ec6-b391-0d9ce1995c42',
  414. '523b17d0-629f-44de-8f24-0c3915493fb0',
  415. '771b45c4-dde0-4d6a-ba69-6d8f537e4c1f',
  416. 'f9b374fd-1af4-4623-b117-c75fa4e7f4f8',
  417. '479f343e-51b7-49bd-8ebb-cb81af8ae7b0',
  418. 'cc992aae-2942-4836-9351-cedbd1cc4e61',
  419. '3f5d1192-4c56-43a6-9140-18043d6c41e5',
  420. 'dffad9b6-f3f2-4470-be45-94c81af04a02',
  421. '39289aa9-2506-4d04-866e-e6eec9b4d9db',
  422. '243299ec-6a98-43ac-b3db-272f5abbbd78',
  423. '9f715766-ef6a-479d-895d-945952a8ff6e',
  424. '2ff9bd86-8621-4f04-b560-abff5a202232',
  425. '75da24ed-8196-4eb1-8413-3916d7b271a3',
  426. '6adc96f3-c6e5-4a8d-a33f-5bbcbb92b296',
  427. '0b2dcfbc-d334-4032-b354-f6fa98a57d99',
  428. 'e2110a26-3af6-4c53-8b38-51ed4b415d48',
  429. '85e4c259-f531-43dd-a2b8-76cb750f8604',
  430. '1a6731a3-cc57-4463-84e1-bca0917c2399',
  431. 'd574dac8-4440-48f0-af37-b982db545ea3',
  432. '753ca661-d930-4f33-bce3-5385c310744f',
  433. 'e70800f3-836b-43e9-aa8c-c5e789d7054e',
  434. '32a94a0c-c14c-4208-8bd1-0d84c69d690e',
  435. 'f5d242b3-db25-4877-8a63-4d4dcf8f8f2c',
  436. '87399fcb-34fb-494b-b74f-02979a665dc0',
  437. '85796371-1079-4fff-947d-671720377e72',
  438. '40f04a01-e373-430a-a1f5-cbb8fbcff4cb',
  439. '6e6a3d09-c65d-4996-bd96-035f5d19e634',
  440. 'd340ea8f-e869-46d5-8813-5cce7991edea',
  441. '8a72592b-09fb-4910-b4e9-c76ef039b44f',
  442. '740b8b24-c7f5-4df5-a13a-92a1c37619bc',
  443. 'c19ef79f-d3f3-4125-8e1a-83cee110e03b',
  444. '1894992c-2575-4949-971d-c84669fcfd06',
  445. '4d51ace2-9f18-4f01-be7b-1ab4694e62dd',
  446. 'c1564967-890f-49e2-983a-933df4cbf8d0',
  447. 'aff088da-91e6-400a-ab84-c6cf300b361f',
  448. 'b0557e5e-41c5-4273-b793-dcb8a0613e6f',
  449. 'd0317e30-bcc4-4b03-9417-4dba3a216105',
  450. '86a28ef8-f3fc-44ef-942b-a9a658bb0731',
  451. '53623415-70e8-44f6-9ea6-bd709e40984c',
  452. '9ee23eee-850c-4cb0-8147-829ae0502705',
  453. 'd6fbfc1e-6093-4e70-8432-453246c80eb3',
  454. 'ac0e96dd-ec15-4b39-834d-1000ac3aa4c4',
  455. '1e8c9744-8054-405b-997c-de13e58967a4',
  456. 'c87c282c-6a83-40d1-86bc-af3045c0c41a',
  457. '4c221226-f490-4657-bd98-cf24bba48d7e',
  458. 'fd218bdd-7c18-41d6-a592-59a4c3ee98fe',
  459. '0c916db0-f7fa-4abc-a548-ca81cb416e59',
  460. '9f3c9615-3066-45d8-99a9-eacc8f6d692d',
  461. '6ed5074e-c7df-49f1-84c8-bb6276db9d1d',
  462. 'c2eb2c78-60d3-4616-9215-5ca810c58e4d',
  463. '4aef197d-5c62-4bce-aab2-804c87db5b28',
  464. '3231a06f-118a-437f-b863-4ffcba56d03a',
  465. 'a827a795-f86e-46eb-8369-f63b061d87d9',
  466. 'd4fd8c14-81d1-41b3-b652-f1dfb107d0d6',
  467. 'a0f2b207-0ef7-4ca4-b595-12f46b4b8434',
  468. '115f8e21-ebdb-4241-9c34-91fbef1b6fb9',
  469. '34c8923a-0230-448a-9d06-a8f2922520a3',
  470. '04803687-4689-45a6-b19e-4d3a39ccc348',
  471. '8bb657c9-7638-4ab9-af92-a4370d53960e',
  472. '1e766445-9971-4358-86be-fba295460866',
  473. '367c0575-b150-44eb-b447-5468d4d833fe',
  474. '2a379010-1f57-43f7-8f99-1f254ad93c26',
  475. '496adcc6-2897-4f16-9e9b-75fbcfd313a0',
  476. 'c32a4e86-637f-4c68-8824-2d4370eea5ee',
  477. 'b03b9f85-6d51-4c9c-a354-22bd3aa67462',
  478. '829a1242-f1e0-4154-aacf-362c021172f2',
  479. '4a451d51-b96c-4740-9018-7d22bbd842cf',
  480. '497a3b9a-55da-4991-af53-657c04edd0b3',
  481. 'b89b915f-f4ea-44f6-ae3a-e45af1942022',
  482. '781c4777-a869-4857-b052-71cbecbf6e35',
  483. '16a1d9aa-4bba-4c6f-86e5-7f7a281e7cd2',
  484. 'a5125445-cd2c-44b1-af19-addd25b8eeef',
  485. '81f574b9-9da2-43ae-ac6c-54ceb637c1fa',
  486. '1d469b5a-386c-4ace-9477-826c2d9d2b5d',
  487. '4fb0c252-5df1-44f9-a6e4-40078740a4e8',
  488. '1d7574e8-cf7c-460f-aad9-b4eec908121c',
  489. 'b0d23d24-a66f-4fb7-badc-980bebe0118d',
  490. 'e9570402-e4db-4a7c-9d5c-c5f95ad8ed0a',
  491. 'b08a57bc-6f1a-491c-a126-490ad5c8f90c',
  492. '583f3908-5caf-4703-84c6-e32cbbafca1e',
  493. '271cf872-cc61-493d-a595-be644bb2e098',
  494. 'a031cf56-0aa1-40c1-a325-14f6f1204cad',
  495. '3f492d1f-d95d-4947-8944-1e47fbe6abb4',
  496. '44d282b7-413f-4f1a-b5cf-5b9b81acbb6a',
  497. 'cef3a415-dc3f-4143-b905-5b1bac1b10c9',
  498. '37fe497b-1ba6-46e7-a9b9-fd70993b9753',
  499. 'c0db0c30-590c-42bd-bac7-d065a05843cd',
  500. '19532426-9ee6-4cc0-8d7b-7c5753b95b64',
  501. '7421dcb4-14d3-4656-9257-a2b287ff41a8',
  502. 'bd5805f7-a7eb-4189-8e48-9b3978d22362',
  503. '012861ec-8bbb-42e2-9e39-349a5b172c21',
  504. '731daff9-ccf2-48d3-88bc-ff02ec7ff2f9',
  505. '5b47d6c3-df81-4456-a165-4af6ee34c375',
  506. '2129126a-838f-4e3d-a8a4-1bf9e8d70ce8',
  507. 'acb84287-1cf7-4aa5-8892-e92beb6f6871',
  508. 'b2d337e4-16b4-459d-9d7f-922458e2671c',
  509. 'c63b9cd7-bce4-4c80-91c2-c305916d3d22',
  510. '1a7d052b-97b6-40ab-9b45-3e163710ea10',
  511. 'bd096e5e-0dc3-4b2e-9e4a-ffc3ac2a8e8b',
  512. '1afbab3e-193c-408c-b024-3365730d1698',
  513. '6e268ebe-aa65-4fa0-8fc1-877d0688cf8d',
  514. '89675ae3-9773-4b37-bc69-6a926f608b0e',
  515. 'd96a0716-89e1-4b5b-b02a-0cb438bd4933',
  516. '693e024a-1b71-4c9e-868e-ad9524728988',
  517. '5fb1ad4b-7a79-4a55-b627-3d1354a22754',
  518. 'c050b6d6-5f1a-4f3f-9385-521d9f992f11',
  519. '62051b3d-1a64-4509-914c-a382f573c050',
  520. '8b6c6a22-3a4c-48f4-bba4-57db1af2ec2e',
  521. 'ca5d3896-35ad-4848-ad2a-beb04263999d',
  522. '1bac6904-2f36-45f5-9e8e-894e28a5674d',
  523. '89f1a5f6-3c29-4338-8a00-5645dbaa80ad',
  524. 'def9d072-fee5-44f6-bc18-5b2750d4efc5',
  525. '032e2e84-6154-49ee-8d4d-e3b3b631595b',
  526. '6cb4e7ba-9be8-4c8a-bf4a-437faf96c084',
  527. 'd6df2ed5-8963-42c0-8832-537a210e900e',
  528. 'ec647fea-a650-4b18-b267-3f8d9d104c23',
  529. '10374436-b76b-4d73-853e-abe12b8f0079',
  530. '8b87190e-3fd1-40d3-9a7f-efb986cd7fa5',
  531. '30803959-1b88-4b8a-8716-d74e58f2eacd',
  532. 'b7c69c8d-b4c0-4523-ac73-f9629d2b5c37',
  533. 'da21dd7d-fe43-474f-bcd0-e2819b71ab40',
  534. 'ae97438f-afc8-4f01-90da-da5fbbc7b759',
  535. '95920cea-040e-40a0-a9fa-ea7e48945e5e',
  536. 'bf0ec2c2-b1b5-41a4-990b-ebd32e64bcc5',
  537. '06add3e9-8566-44b0-8962-6f1377410b48',
  538. '1a56021a-b4e5-45e0-83e5-7ec707097271',
  539. 'd35c54ea-3985-484f-9a3a-abc4be8fc774',
  540. 'a7c3bd26-ac43-4a61-99fe-428ea141a826',
  541. '414a46cb-4e88-4217-adfd-395f3f4cb12c',
  542. '241729ee-cfe7-4ee2-868e-3f617fd62bba',
  543. 'c05c28db-8b03-4d0c-8a37-c0e36c6fd0e8',
  544. '5b72fe37-3bc6-4563-9a1e-bfd62b692980',
  545. '73609b0e-1bc7-4c64-a39e-df52a34a5325',
  546. '477bba0c-d64f-4543-90eb-481183874bf8',
  547. 'd2d5be63-6e49-46d5-ae96-3b106b907902',
  548. '9091e31c-28c6-4a31-9958-36d0875ef8d7',
  549. '4fedd41a-d3d2-475d-8804-8c716ac4e160',
  550. '5d322e5c-ad86-42b2-a20d-1fa0e3279361',
  551. '99297e99-3b10-4353-a691-02492f2b88d1',
  552. '5b1206de-1b99-4b96-8e98-5c85ca630cea',
  553. '65d501e8-4663-4ae8-a07e-59b30b75a645',
  554. 'b53311e3-5276-45d6-87a1-36bf28b653be',
  555. '6bd75463-1dec-4001-ab24-cd2e07986759',
  556. '9b3201a9-ce44-41a7-8ad5-6769f726c2d0',
  557. '0acf8a5d-0feb-4497-9a0a-e95f86138157',
  558. '522597e8-bada-4c5b-bdf2-06af764a4bfe',
  559. '1fca91fb-3e03-438e-8f1b-a9b77b14634c',
  560. 'c8bd6ef8-ff2e-40c5-8f15-973caea0ed58',
  561. 'ba318882-7eeb-42a0-bfcb-09ac71fc0046',
  562. '0e1d09bd-f176-4e21-9f55-b821703a7b24',
  563. '3f58f289-a206-4fbd-93c6-0752d3d0a250',
  564. 'fd23121d-959d-443c-ac22-4cf7cac3751c',
  565. 'd3b4384a-290e-4cb0-bfda-b34097d5ca72',
  566. '2d7b5467-0e74-40ae-ab21-bf29ee3fe02c',
  567. 'd3db6faa-4b07-460a-bcbd-48dcc109fbc4',
  568. 'e5d14fe7-a5a0-4610-b1b7-87c9d936c7ff',
  569. 'f386b6f5-1fd2-4a2e-8ec0-6762ddd5c477',
  570. '60c09883-dff1-49ee-bafb-1991aab238aa',
  571. '6664e420-91ad-4c89-9955-313b163f722e',
  572. 'b81724c3-c045-436b-9d55-f528918de742',
  573. '5de09e10-e4bd-4df2-8628-9e432b17ec65',
  574. 'af93606e-5dbc-4401-99e6-adea66903418',
  575. 'fe7998e5-0a31-45a8-aab0-1867092d855c',
  576. 'd64bdffe-8388-4a9c-a3f9-bbd1b75ea224',
  577. 'c8845227-73ea-45fe-920c-be3e166b04c3',
  578. '6087c06a-10fc-4c92-adb3-95f85423fe2e',
  579. '6c64f697-21cf-4d58-8810-d0306e0c5dc4',
  580. 'bc2ee64e-cb01-4101-9d2d-fd37f31fd881',
  581. 'c076b996-1f81-4f4a-8c04-a1a69348863f',
  582. 'f2fab9c5-2a57-4f0a-8b48-000fc08eec98',
  583. 'b496b620-713e-4312-8d80-4f89d10187de',
  584. '6995deff-b9e8-479b-84fc-d981efab4d3b',
  585. 'cd7e8c81-231f-42ab-a30d-7665e9097a71',
  586. '38452e41-1ec3-40ca-ac3a-2579e47e5f16',
  587. '16e904e2-b77b-4723-86ee-ba85a9d3762f',
  588. '9e5e308a-c291-4feb-a225-336f0f949489',
  589. '8391694a-dccb-48eb-8d3b-56401e5fb030',
  590. 'f210dd0a-e288-477a-9a16-d622cc92a818',
  591. '17908451-473c-4fd8-848c-23ef7846fa43',
  592. 'cea1ec2e-02e6-4777-b931-b2042b3f1230',
  593. '70fd95b8-be8c-4545-a46f-6c050449a822',
  594. '057d4f31-3338-4d7b-869c-98fcb114153d',
  595. '8d032ab5-c7db-4ceb-9a37-f55f8a59416c',
  596. '5e8a8ffe-73ac-4a29-9bcc-a03c06b25b2e',
  597. '55fd11e2-047f-4acf-9533-22023684dd58',
  598. '45a4b0c1-dbbf-423e-b287-d44c71089f69',
  599. 'c52cd0d3-4385-4efb-8f33-f947564a70cb',
  600. '07d593c2-9ad7-4ae5-b471-b3e2622c940b',
  601. 'adf77ae2-63f7-4732-82d0-29d434f83445',
  602. 'bdee46ba-fab6-485d-ad89-fda5578859cc',
  603. 'f8b9bccc-1c4f-433d-9917-f4ad007f7105',
  604. '7d2bd01e-5435-4dbd-8e9b-897e777691f6',
  605. '56cacfd9-aeef-4477-abb9-2a22e0a92ae7',
  606. '891c7363-60c7-4aa5-846e-e7e3913e37d4',
  607. '376c26d3-8ebc-4c10-a5c1-aef9606318a8',
  608. '3efc8c68-3cee-4bc6-bdcd-ffc4c1a3437b',
  609. '1a7e5fda-eb4c-4f62-ad2d-b3e04e0e725a',
  610. 'dd4b0cd7-73d4-46fa-bf19-12e35f64be43',
  611. 'ccf206a1-fcc8-4552-b12f-ebed670cff73',
  612. 'c275d71f-cdb3-443c-82ab-821dd80500ea',
  613. 'e269c78b-2b0c-4fd1-bc0f-2ff671151030',
  614. '41e4371e-7495-4008-9951-7b3ab843429e',
  615. 'c54ac4b5-9267-4087-b724-6b0d44713162',
  616. 'e43fb790-aa3f-4209-838d-d830a9c5fd53',
  617. '982f3d88-bfe1-46c8-ac95-7adbd06a98f1',
  618. '8ded07a1-1dda-4dea-8e0d-05475693642c',
  619. 'edb7d6b2-4d86-486f-b4b6-bac71fe6c460',
  620. 'c3416899-550b-4e1a-93f5-690dcf67cd6b',
  621. '89a915cf-aee4-4472-91e6-7f33d5ef490b',
  622. 'c3587e4c-020a-4bef-8ad5-bcbb9a7ea485',
  623. '91e8d5b4-8b73-470b-b900-7cd8f5508e82'
  624. )";
  625. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).GetItemQueryIterator<StudentArtResult>(sql))
  626. {
  627. art_idNames.Add(item);
  628. }
  629. List<dynamic> unfinish = new List<dynamic>();
  630. ConcurrentDictionary<string, int> schoolFinish = new ConcurrentDictionary<string, int>();
  631. ConcurrentDictionary<string, int> schoolUnFinish = new ConcurrentDictionary<string, int>();
  632. List<Class> classes = new List<Class>();
  633. foreach (var z in art_idNames)
  634. {
  635. var data = z.results.Where(x => (x.subjectId.Equals("subject_painting") && x.quotaId.Equals("quota_21") && x.score == -1)
  636. || (x.subjectId.Equals("subject_music") && x.quotaId.Equals("quota_21") && x.score == -1)
  637. || (x.subjectId.Equals("subject_music") && x.quotaId.Equals("quota_22") && x.score == -1)
  638. || (x.subjectId.Equals("subject_painting") && x.quotaId.Equals("quota_22") && x.files.IsEmpty())
  639. );
  640. if (data.Any())
  641. {
  642. var p21 = z.results.FindAll(x => x.subjectId.Equals("subject_painting") && x.quotaId.Equals("quota_21"))?.First();
  643. var p22 = z.results.FindAll(x => x.subjectId.Equals("subject_painting") && x.quotaId.Equals("quota_22"))?.First();
  644. int p22source = 0, p21source = 0, m21source = 0, m22source = 0;
  645. if (p21.score > -1)
  646. {
  647. p21source = 1;
  648. }
  649. if (p22.files.IsNotEmpty())
  650. {
  651. p22source = p22.files.Count;
  652. }
  653. var m21 = z.results.FindAll(x => x.subjectId.Equals("subject_music") && x.quotaId.Equals("quota_21"))?.First();
  654. if (m21.score > -1)
  655. {
  656. m21source = 1;
  657. }
  658. var m22 = z.results.FindAll(x => x.subjectId.Equals("subject_music") && x.quotaId.Equals("quota_22"))?.First();
  659. if (m22.score > -1)
  660. {
  661. m22source = 1;
  662. }
  663. string className = "";
  664. string periodName = "";
  665. string schoolName = "";
  666. School school = schools.Find(a => a.id.Equals(z.school));
  667. schoolName = school?.name;
  668. if (!string.IsNullOrWhiteSpace(z.classIds?.First()))
  669. {
  670. var clasz = classes.Find(x => x.id.Equals(z.classIds?.First()));
  671. if (clasz == null)
  672. {
  673. clasz = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).ReadItemAsync<Class>(z.classIds.First(), new PartitionKey($"Class-{z.school}"));
  674. classes.Add(clasz);
  675. }
  676. className = clasz?.name;
  677. var period = school?.period?.Where(m => m.id.Equals(clasz.periodId));
  678. if (period.Any())
  679. {
  680. periodName = period.First().name + "-" + period.First().periodType;
  681. }
  682. }
  683. unfinish.Add(new { z.school, schoolName = schoolName, z.studentId, z.studentName, z.artId, periodName, classname = className, p21source, p22source, m21source, m22source, taskId = m22?.taskId });
  684. if (schoolUnFinish.ContainsKey(schoolName))
  685. {
  686. schoolUnFinish[schoolName]++;
  687. }
  688. else { schoolUnFinish.TryAdd(schoolName, 1); }
  689. }
  690. else
  691. {
  692. School school = schools.Find(a => a.id.Equals(z.school));
  693. string schoolName = school?.name;
  694. if (schoolFinish.ContainsKey(schoolName))
  695. {
  696. schoolFinish[schoolName]++;
  697. }
  698. else { schoolFinish.TryAdd(schoolName, 1); }
  699. }
  700. }
  701. return Ok(new { unfinish, schoolFinish , schoolUnFinish });
  702. }
  703. [ProducesDefaultResponseType]
  704. [HttpPost("check-ems")]
  705. public async Task<IActionResult> CheckPjx(JsonElement json)
  706. {
  707. var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
  708. List< ScTeacher > teachers = await table.FindListByDict<ScTeacher>(new Dictionary<string, object>() { { "PartitionKey", "ScTeacher" }, { "ProjectItemID", 1350 } });
  709. List<dynamic> unbind = new List<dynamic>();
  710. List<dynamic> unupload_rzcl = new List<dynamic>();
  711. List<dynamic> uploads_rzcl = new List<dynamic>();
  712. List<dynamic> unupload_video = new List<dynamic>();
  713. List<dynamic> uploads_video = new List<dynamic>();
  714. foreach (var teacher in teachers)
  715. {
  716. if (!string.IsNullOrWhiteSpace(teacher.schoolCode) && !string.IsNullOrWhiteSpace(teacher.tmdid))
  717. {
  718. int upcont = 0;
  719. string sql = "select value c from c where c.currency=1";
  720. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher)
  721. .GetItemQueryIterator<AbilitySub>(queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"AbilitySub-{teacher.schoolCode}-{teacher.tmdid}") }))
  722. {
  723. if (item.uploads.IsNotEmpty())
  724. {
  725. upcont++;
  726. 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 });
  727. }
  728. }
  729. if(upcont<3)
  730. {
  731. unupload_rzcl.Add(new { teacher.TeacherName, teacher.SchoolName, teacher.PXID ,teacher?.tmdid});
  732. }
  733. string sql_video =$"select value c from c where c.id='{teacher.tmdid}'";
  734. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher)
  735. .GetItemQueryIterator<ClassVideo>(queryText: sql_video, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"ClassVideo-{teacher.schoolCode}") }))
  736. {
  737. if (item.files.IsNotEmpty())
  738. {
  739. 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 });
  740. }
  741. else
  742. {
  743. unupload_video.Add(new { teacher.TeacherName, teacher.SchoolName, teacher.PXID, teacher?.tmdid });
  744. }
  745. }
  746. }
  747. else {
  748. unbind.Add(new { teacher.TeacherName,teacher.SchoolName,teacher.PXID});
  749. }
  750. }
  751. Dictionary<string, object> dict = new Dictionary<string, object>();
  752. 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)});
  753. return Ok(new { unbind , unupload_rzcl, uploads_rzcl, uploads_video, unupload_video , tchs });
  754. }
  755. [ProducesDefaultResponseType]
  756. [HttpPost("sendmsg")]
  757. public async Task<IActionResult> Sendmsg(JsonElement json)
  758. {
  759. byte[] bytes = Encoding.UTF8.GetBytes(json.GetRawText());
  760. var memoryStream = new MemoryStream(bytes);
  761. Azure.Response res = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).CreateItemStreamAsync(memoryStream, new PartitionKey("Base12"));
  762. if (res.Status == 201)
  763. {
  764. return Ok(201);
  765. }
  766. //var messageBlobPDF = new ServiceBusMessage(new { userType = "tmdid", bizType = "OfflineRecord" }.ToJsonString());
  767. //await _serviceBus.GetServiceBusClient().SendMessageAsync("screenpdf", messageBlobPDF);
  768. return Ok();
  769. }
  770. [ProducesDefaultResponseType]
  771. [HttpPost("get-subTime")]
  772. public async Task<IActionResult> GetSubTime(JsonElement request) {
  773. if (!request.TryGetProperty("ids", out JsonElement id)) return BadRequest();
  774. List<string> ids = id.ToObject<List<string>>();
  775. var queryClass = $"select c.time from c ";
  776. var client = _azureCosmos.GetCosmosClient();
  777. List<(string td, long tt)> ht = new();
  778. foreach (string tmdId in ids) {
  779. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIterator(queryText: queryClass,
  780. requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"HomeworkRecord-{tmdId}") }))
  781. {
  782. using var json = await JsonDocument.ParseAsync(item.ContentStream);
  783. if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
  784. {
  785. var accounts = json.RootElement.GetProperty("Documents").EnumerateArray();
  786. while (accounts.MoveNext())
  787. {
  788. JsonElement account = accounts.Current;
  789. account.TryGetProperty("time", out JsonElement time);
  790. ht.Add((tmdId,time.GetInt64()));
  791. }
  792. }
  793. }
  794. }
  795. var home = ht.Select(x => new
  796. {
  797. id = x.td,
  798. time = DateTimeOffset.FromUnixTimeMilliseconds(x.tt).ToString("yyyy-MM-dd HH:mm")
  799. //time = DateTimeHelper.FromUnixTimestampOffSet(x.tt,8).ToString("yyyy-MM-dd HH:mm")
  800. });
  801. return Ok(home);
  802. }
  803. [ProducesDefaultResponseType]
  804. [HttpPost("get-semester")]
  805. public async Task<IActionResult> GetSemester(JsonElement json)
  806. {
  807. List<Semester> semesterList = new List<Semester>();
  808. semesterList.Add(
  809. new Semester
  810. {
  811. id = Guid.NewGuid().ToString(),
  812. name = "第二学期",
  813. start = 0,
  814. month = 3,
  815. day = 1
  816. });
  817. semesterList.Add(
  818. new Semester
  819. {
  820. id = Guid.NewGuid().ToString(),
  821. name = "第一学期",
  822. start = 1,
  823. month = 9,
  824. day = 1
  825. });
  826. //semesterList.Add(
  827. // new Semester
  828. // {
  829. // id = "q",
  830. // name = "第四学期",
  831. // start = 0,
  832. // month = 7,
  833. // day = 1
  834. // });
  835. //semesterList.Add(
  836. // new Semester
  837. // {
  838. // id = "q",
  839. // name = "第三学期",
  840. // start = 0,
  841. // month = 4,
  842. // day = 1
  843. // });
  844. semesterList = SortSemester(semesterList);
  845. return Ok(semesterList);
  846. }
  847. private List<Semester> SortSemester(List<Semester> semesterList)
  848. {
  849. int Year = DateTimeOffset.UtcNow.Year;
  850. List<KeyValuePair<int, Semester>> pairs = new List<KeyValuePair<int, Semester>>();
  851. semesterList.ForEach(se => {
  852. string sm = se.month >= 10 ? $"{se.month}" : $"0{se.month}";
  853. string sd = se.day >= 10 ? $"{se.day}" : $"0{se.day}";
  854. int order = int.Parse($"{Year}{sm}{sd}");
  855. pairs.Add(new KeyValuePair<int, Semester>(order, se));
  856. });
  857. var orderPairs = pairs.OrderBy(z => z.Key);
  858. semesterList = orderPairs.Select(z => z.Value).ToList();
  859. int startIndex = semesterList.FindIndex(z => z.start == 1);
  860. if (startIndex == -1)
  861. {
  862. //未设置学期的情况默认9月份开始的。
  863. startIndex = semesterList.FindIndex(z => z.month == 9);
  864. //如果还未找到,就以排序结果为准
  865. if (startIndex == -1)
  866. {
  867. startIndex = 0;
  868. }
  869. }
  870. if (startIndex > 0)
  871. {
  872. List<Semester> before = semesterList.Take(startIndex).ToList();
  873. List<Semester> after = semesterList.Skip(startIndex).ToList();
  874. semesterList = new List<Semester>();
  875. semesterList.AddRange(after);
  876. semesterList.AddRange(before);
  877. return semesterList;
  878. }
  879. else
  880. {
  881. return semesterList;
  882. }
  883. }
  884. /*
  885. [
  886. {"method":"台北市","params":{"CountryId":"TW","CityId":"30"}},1
  887. {"method":"新北市","params":{"CountryId":"TW","CityId":"01"}},1
  888. {"method":"桃园市","params":{"CountryId":"TW","CityId":"03"}},1
  889. {"method":"台中市","params":{"CountryId":"TW","CityId":"66"}},1
  890. {"method":"台南市","params":{"CountryId":"TW","CityId":"67"}},1
  891. {"method":"高雄市","params":{"CountryId":"TW","CityId":"64"}},1
  892. {"method":"基隆市","params":{"CountryId":"TW","CityId":"17"}},1
  893. {"method":"新竹市","params":{"CountryId":"TW","CityId":"18"}},1
  894. {"method":"嘉义市","params":{"CountryId":"TW","CityId":"20"}},1
  895. {"method":"新竹县","params":{"CountryId":"TW","CityId":"04"}},1
  896. {"method":"苗栗县","params":{"CountryId":"TW","CityId":"05"}},1
  897. {"method":"彰化县","params":{"CountryId":"TW","CityId":"07"}},1
  898. {"method":"南投县","params":{"CountryId":"TW","CityId":"08"}},1
  899. {"method":"云林县","params":{"CountryId":"TW","CityId":"09"}},1
  900. {"method":"嘉义县","params":{"CountryId":"TW","CityId":"10"}},1
  901. {"method":"屏东县","params":{"CountryId":"TW","CityId":"13"}},1
  902. {"method":"宜兰县","params":{"CountryId":"TW","CityId":"02"}},1
  903. {"method":"花莲县","params":{"CountryId":"TW","CityId":"15"}},1
  904. {"method":"台东县","params":{"CountryId":"TW","CityId":"14"}},1
  905. {"method":"澎湖县","params":{"CountryId":"TW","CityId":"16"}},1
  906. {"method":"金门县","params":{"CountryId":"TW","CityId":"71"}},
  907. {"method":"连江县","params":{"CountryId":"TW","CityId":"72"}}
  908. ]
  909. */
  910. /// <summary>
  911. /// 测试blob多线程写入同一个文件
  912. /// </summary>
  913. /// <returns></returns>
  914. [ProducesDefaultResponseType]
  915. [HttpPost("get-schools")]
  916. public async Task<IActionResult> GetSchools(JsonElement json)
  917. {
  918. string msg = "{\"standard\":\"standard3\",\"tmdids\":[\"1635136038\"],\"school\":\"pbjyey\",\"update\":[\"TeacherAbility\"],\"statistics\":0}";
  919. try
  920. {
  921. TeacherTrainChange change = msg.ToObject<TeacherTrainChange>();
  922. var client = _azureCosmos.GetCosmosClient();
  923. string insql = $"where c.id in ({string.Join(",", change.tmdids.Select(x => $"'{x}'"))})";
  924. string selsql = $"select value(c) from c {insql} ";
  925. List<TeacherTrain> teacherTrains = new List<TeacherTrain>();
  926. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<TeacherTrain>(queryText: selsql,
  927. requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"TeacherTrain-{change.school}") }))
  928. {
  929. teacherTrains.Add(item);
  930. }
  931. if (change.statistics != 1)
  932. {
  933. List<Task<ItemResponse<TeacherTrain>>> task = new List<Task<ItemResponse<TeacherTrain>>>();
  934. teacherTrains.ForEach(x =>
  935. {
  936. x.update.UnionWith(change.update);
  937. task.Add(client.GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<TeacherTrain>(x, x.id, new PartitionKey($"TeacherTrain-{change.school}")));
  938. });
  939. await task.TaskPage(5);
  940. var unchange = change.tmdids.Except(teacherTrains.Select(x => x.id));
  941. if (unchange != null)
  942. {
  943. task.Clear();
  944. unchange.ToList().ForEach(x =>
  945. {
  946. TeacherTrain teacherTrain = new TeacherTrain
  947. {
  948. pk = "TeacherTrain",
  949. id = x,
  950. code = $"TeacherTrain-{change.school}",
  951. tmdid = x,
  952. school = change.school,
  953. update = new HashSet<string> { StatisticsService.TeacherAbility,
  954. StatisticsService.TeacherClass, StatisticsService.OfflineRecord }
  955. };
  956. teacherTrain.update.UnionWith(change.update);
  957. task.Add(client.GetContainer(Constant.TEAMModelOS, "Teacher").UpsertItemAsync<TeacherTrain>(teacherTrain, new PartitionKey($"TeacherTrain-{change.school}")));
  958. });
  959. await task.TaskPage(1);
  960. }
  961. }
  962. else
  963. {
  964. Area area = null;
  965. string sql = $"select value(c) from c where c.standard='{change.standard}'";
  966. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Normal").GetItemQueryIterator<Area>(queryText: sql,
  967. requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base-Area") }))
  968. {
  969. area = item;
  970. }
  971. AreaSetting setting = null;
  972. if (area != null)
  973. {
  974. try
  975. {
  976. //优先找校级
  977. setting = await client.GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<AreaSetting>(change.school, new PartitionKey("AreaSetting"));
  978. }
  979. catch (CosmosException)
  980. {
  981. try
  982. {
  983. setting = await client.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemAsync<AreaSetting>(area.id, new PartitionKey("AreaSetting"));
  984. }
  985. catch (CosmosException)
  986. {
  987. setting = null;
  988. }
  989. }
  990. }
  991. if (setting == null)
  992. {
  993. setting = new AreaSetting
  994. {
  995. allTime = 50,
  996. classTime = 5,
  997. submitTime = 15,
  998. onlineTime = 20,
  999. offlineTime = 10,
  1000. lessonMinutes = 45,
  1001. };
  1002. }
  1003. List<Task<TeacherTrain>> task = new List<Task<TeacherTrain>>();
  1004. teacherTrains.ForEach(x =>
  1005. {
  1006. x.update.UnionWith(change.update);
  1007. task.Add(StatisticsService.StatisticsTeacher(x, setting, area, client, null));
  1008. });
  1009. await task.TaskPage(1);
  1010. var unchange = change.tmdids.Except(teacherTrains.Select(x => x.id));
  1011. if (unchange != null)
  1012. {
  1013. task.Clear();
  1014. unchange.ToList().ForEach(x =>
  1015. {
  1016. task.Add(StatisticsService.StatisticsTeacher(new TeacherTrain
  1017. {
  1018. pk = "TeacherTrain",
  1019. id = x,
  1020. code = $"TeacherTrain-{change.school}",
  1021. tmdid = x,
  1022. school = change.school,
  1023. update = new HashSet<string> { StatisticsService.TeacherAbility,
  1024. StatisticsService.TeacherClass, StatisticsService.OfflineRecord }
  1025. }, setting, area, client, null));
  1026. });
  1027. await task.TaskPage(1);
  1028. }
  1029. }
  1030. }
  1031. catch (CosmosException ex)
  1032. {
  1033. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-研修数据变更,重新统计-TeacherTrainChange\n{msg}\n{ex.Message}\n{ex.StackTrace}\nCosmosException{ex.Status}", GroupNames.醍摩豆服務運維群組);
  1034. }
  1035. catch (Exception ex)
  1036. {
  1037. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-研修数据变更,重新统计-TeacherTrainChange\n{msg}\n{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
  1038. }
  1039. /*
  1040. string path = $"{_environment.ContentRootPath}/JsonFile/Core/city.json";
  1041. StreamReader streamReader = new StreamReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.UTF8);
  1042. StringBuilder stringBuilder = new StringBuilder();
  1043. string text;
  1044. while ((text = streamReader.ReadLine()) != null)
  1045. {
  1046. stringBuilder.Append(text.ToString());
  1047. }
  1048. streamReader.Close();
  1049. string input = stringBuilder.ToString();
  1050. List<string> region = new List<string>() {
  1051. "110000", "110100", "110200",
  1052. "120000", "120100", "120200",
  1053. "310000", "310100", "310200",
  1054. "500000", "500100", "810100",
  1055. "810200", "810300", "820100",
  1056. "820200", "820300"
  1057. };
  1058. List<string> cityids = new List<string>() {
  1059. "30","01","03","66","67","64","17","18","20","04","05","07","08","09","10","13","02","15","14","16","71","72"
  1060. };
  1061. Dictionary<string, List<CodeName>> regions = input.ToObject<Dictionary<string, List<CodeName>>>();
  1062. List<List<string>> datas = new List<List<string>>() { region };
  1063. foreach (var r in regions)
  1064. {
  1065. if (!region.Contains(r.Key) && !r.Key.StartsWith("71"))
  1066. {
  1067. datas.Add(r.Value.Select(x => x.code).ToList());
  1068. }
  1069. }
  1070. List<Task<List<SchoolInfo>>> tasks = new List<Task<List<SchoolInfo>>>();
  1071. //datas.ForEach(x =>
  1072. //{
  1073. // tasks.Add(GetSchoolAsync(x));
  1074. //});
  1075. List<SchoolInfo> schoolInfos = new List<SchoolInfo>();
  1076. //var schools = await Task.WhenAll(tasks);
  1077. //var schools =await GetSchoolAsync(cityids);
  1078. // schoolInfos.AddRange(schools);
  1079. //foreach (var schs in schools)
  1080. //{
  1081. // schoolInfos.AddRange(schs);
  1082. //}
  1083. List<string> nodatas = new List<string>();
  1084. foreach (var data in datas) {
  1085. (List<SchoolInfo> schoolIn, List<string> nodata) = await GetSchoolAsync(data);
  1086. schoolInfos.AddRange(schoolIn);
  1087. nodatas.AddRange(nodata);
  1088. }
  1089. await _dingDing.SendBotMsg($"os,test,{nodatas.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
  1090. return Ok(schoolInfos);
  1091. */
  1092. return Ok();
  1093. }
  1094. public async Task<(List<SchoolInfo> schoolInfos, List<string> nodata)> GetSchoolAsync(List<string> regions)
  1095. {
  1096. List<SchoolInfo> schools = new List<SchoolInfo>();
  1097. List<string> nodata = new List<string>();
  1098. foreach (var region in regions)
  1099. {
  1100. Dictionary<string, object> data = new Dictionary<string, object>();
  1101. data.Add("method", "api/School/getSchool");
  1102. data.Add("params", new { CountryId = "CN", CityId = region });
  1103. HttpResponseMessage responseMessage = await _httpClient.CreateClient().PostAsJsonAsync("https://contest.teammodel.cn/api/School/getSchool", data);
  1104. if (responseMessage.StatusCode == HttpStatusCode.OK)
  1105. {
  1106. string Content = await responseMessage.Content.ReadAsStringAsync();
  1107. try
  1108. {
  1109. Content.ToObject<JsonElement>().TryGetProperty("result", out JsonElement content);
  1110. if (content.ValueKind.Equals(JsonValueKind.Object) && content.TryGetProperty("data", out JsonElement _data))
  1111. {
  1112. if (_data.ValueKind.Equals(JsonValueKind.Array))
  1113. {
  1114. List<SchoolInfo> infos = _data.ToObject<List<SchoolInfo>>();
  1115. if (infos.IsNotEmpty())
  1116. {
  1117. schools.AddRange(infos.Where(x => x.name != null && x.cityName != null).ToList());
  1118. }
  1119. }
  1120. else
  1121. {
  1122. nodata.Add(data.ToJsonString());
  1123. continue;
  1124. }
  1125. }
  1126. else
  1127. {
  1128. nodata.Add(data.ToJsonString());
  1129. continue;
  1130. }
  1131. }
  1132. catch (Exception ex)
  1133. {
  1134. nodata.Add(data.ToJsonString());
  1135. throw new Exception(ex.Message, ex.InnerException);
  1136. }
  1137. }
  1138. }
  1139. return (schools, nodata);
  1140. }
  1141. public class SchoolInfo
  1142. {
  1143. public string typeName { get; set; }
  1144. public string provinceName { get; set; }
  1145. public string provinceId { get; set; }
  1146. public string id { get; set; }
  1147. public string name { get; set; }
  1148. public string cityId { get; set; }
  1149. public string cityName { get; set; }
  1150. public string address { get; set; }
  1151. }
  1152. public class CodeName
  1153. {
  1154. public string code { get; set; }
  1155. public string name { get; set; }
  1156. }
  1157. /// <summary>
  1158. /// 测试blob多线程写入同一个文件
  1159. /// </summary>
  1160. /// <returns></returns>
  1161. [ProducesDefaultResponseType]
  1162. [HttpPost("generate-school-codes")]
  1163. public async Task<IActionResult> GenerateSchoolCodes(JsonElement json)
  1164. {
  1165. List<SchoolData> schoolss = json.GetProperty("schools").ToObject<List<SchoolData>>();
  1166. dynamic data = await SchoolService.GenerateSchoolCode(schoolss, _dingDing, _environment);
  1167. return Ok(data);
  1168. }
  1169. /// <summary>
  1170. /// 测试blob多线程写入同一个文件
  1171. /// </summary>
  1172. /// <returns></returns>
  1173. [ProducesDefaultResponseType]
  1174. [HttpPost("blobroot")]
  1175. public async Task<IActionResult> MultipleBlob(JsonElement jsonMsg)
  1176. {
  1177. if (jsonMsg.TryGetProperty("name", out JsonElement name) && name.ValueKind == JsonValueKind.String
  1178. && jsonMsg.TryGetProperty("root", out JsonElement root) && root.ValueKind == JsonValueKind.String)
  1179. {
  1180. List<Dictionary<string, double?>> list = new List<Dictionary<string, double?>>();
  1181. string u = System.Web.HttpUtility.UrlDecode($"{root}", Encoding.UTF8).Split("/")[0];
  1182. var client = _azureStorage.GetBlobContainerClient($"{name}");
  1183. var size = await client.GetBlobsSize(u);
  1184. await _azureRedis.GetRedisClient(8).SortedSetRemoveAsync($"Blob:Catalog:{name}", u);
  1185. await _azureRedis.GetRedisClient(8).SortedSetIncrementAsync($"Blob:Catalog:{name}", u, size.HasValue ? size.Value : 0);
  1186. var scores = await _azureRedis.GetRedisClient(8).SortedSetRangeByRankWithScoresAsync($"Blob:Catalog:{name}");
  1187. double blobsize = 0;
  1188. if (scores != default && scores != null)
  1189. {
  1190. foreach (var score in scores)
  1191. {
  1192. blobsize = blobsize + score.Score;
  1193. list.Add(new Dictionary<string, double?>() { { score.Element.ToString(), score.Score } });
  1194. }
  1195. }
  1196. await _azureRedis.GetRedisClient(8).HashSetAsync($"Blob:Record", new RedisValue($"{name}"), new RedisValue($"{blobsize}"));
  1197. await _dingDing.SendBotMsg($"{Environment.GetEnvironmentVariable("Option:Location")}-ServiceBus,Blob() 容器:{name}使用:{root},文件分类:{list.ToJsonString()}", GroupNames.成都开发測試群組);
  1198. return Ok(list);
  1199. }
  1200. else
  1201. {
  1202. return Ok();
  1203. }
  1204. }
  1205. private async Task<int> SendNotification()
  1206. {
  1207. // _httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {token.AccessToken}");
  1208. var pa = new { grant_type = "device", client_id = "9794e418-c4ef-4fd5-a42d-accaa2d96d6e", client_secret = "ruL?I79h0w1AZaZXtBaZeZuQLQXLa=:-" };
  1209. HttpResponseMessage responseMessage = await _httpClient.CreateClient().PostAsJsonAsync("https://api2-rc.teammodel.net/oauth2/token", pa);
  1210. if (responseMessage.StatusCode == HttpStatusCode.OK)
  1211. {
  1212. return 200;
  1213. }
  1214. else if (responseMessage.StatusCode == HttpStatusCode.Unauthorized)
  1215. {
  1216. return 401;
  1217. }
  1218. else
  1219. {
  1220. return 500;
  1221. }
  1222. }
  1223. /// <summary>
  1224. /// 测试redis通配符
  1225. /// </summary>
  1226. /// <param name="request"></param>
  1227. /// <returns></returns>
  1228. [ProducesDefaultResponseType]
  1229. [HttpGet("test-delete-read")]
  1230. public async Task<IActionResult> TestDelete()
  1231. {
  1232. foreach (var cnt in _azureStorage.GetBlobServiceClient().GetBlobContainers())
  1233. {
  1234. Console.WriteLine(cnt.Name);
  1235. }
  1236. await SendNotification();
  1237. var client = _azureCosmos.GetCosmosClient();
  1238. string aaa = "0";
  1239. try
  1240. {
  1241. ItemResponse<Student> a = await client.GetContainer(Constant.TEAMModelOS, "Student").DeleteItemAsync<Student>("1111111", new PartitionKey($"Course-111111"));
  1242. Ok(a.GetRawResponse().Status);
  1243. }
  1244. catch (CosmosException ex)
  1245. {
  1246. if (ex.Response.Status == 404)
  1247. {
  1248. aaa = "404";
  1249. }
  1250. }
  1251. try
  1252. {
  1253. ItemResponse<Student> a = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemAsync<Student>("1111111", new PartitionKey($"Course-111111"));
  1254. Ok(a.GetRawResponse().Status);
  1255. }
  1256. catch (CosmosException ex)
  1257. {
  1258. if (ex.Response.Status == 404)
  1259. {
  1260. aaa = aaa + " 404";
  1261. }
  1262. }
  1263. try
  1264. {
  1265. var a = await client.GetContainer(Constant.TEAMModelOS, "Student").DeleteItemStreamAsync("1111111", new PartitionKey($"Course-111111"));
  1266. Ok(a.Status);
  1267. }
  1268. catch (CosmosException ex)
  1269. {
  1270. if (ex.Response.Status == 404)
  1271. {
  1272. aaa = "404";
  1273. }
  1274. }
  1275. try
  1276. {
  1277. var a = await client.GetContainer(Constant.TEAMModelOS, "Student").ReadItemStreamAsync("1111111", new PartitionKey($"Course-111111"));
  1278. Ok(a.Status);
  1279. }
  1280. catch (CosmosException ex)
  1281. {
  1282. if (ex.Response.Status == 404)
  1283. {
  1284. aaa = aaa + " 404";
  1285. }
  1286. }
  1287. return Ok(new { aaa });
  1288. }
  1289. /// <summary>
  1290. /// 测试redis通配符
  1291. /// </summary>
  1292. /// <param name="request"></param>
  1293. /// <returns></returns>
  1294. [ProducesDefaultResponseType]
  1295. [HttpGet("test-redis")]
  1296. public async Task<IActionResult> TestRedis()
  1297. {
  1298. try
  1299. {
  1300. var client = _azureCosmos.GetCosmosClient();
  1301. List<ItemInfo> items = new List<ItemInfo>();
  1302. var queryslt = $"SELECT value(c) FROM c where c.pid = null ";
  1303. await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIterator<ItemInfo>(queryText: queryslt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Item-hbcn") }))
  1304. {
  1305. items.Add(item);
  1306. }
  1307. List<ItemCond> itemConds = new List<ItemCond>();
  1308. items.GroupBy(x => x.periodId).Select(y => new { key = y.Key, list = y.ToList() }).ToList().ForEach(z =>
  1309. {
  1310. 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>() };
  1311. z.list.ForEach(y =>
  1312. {
  1313. ItemService.CountItemCond(y, null, cond);
  1314. });
  1315. itemConds.Add(cond);
  1316. });
  1317. itemConds.ForEach(async cond =>
  1318. {
  1319. await client.GetContainer(Constant.TEAMModelOS, "School").UpsertItemAsync<ItemCond>(cond, new PartitionKey(cond.code));
  1320. });
  1321. return Ok(new { itemConds });
  1322. }
  1323. catch (Exception ex) { await _dingDing.SendBotMsg($"TEAMModelFunction,ActivityHttpTrigger,fix-itemcond()\n{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組); }
  1324. return Ok(new { });
  1325. }
  1326. /// <summary>
  1327. /// 删除
  1328. /// </summary>
  1329. /// <param name="request"></param>
  1330. /// <returns></returns>
  1331. [ProducesDefaultResponseType]
  1332. //[AuthToken(Roles = "teacher")]
  1333. [HttpPost("fix-blob-content")]
  1334. public async Task<IActionResult> FixBlobContent(JsonElement request)
  1335. {
  1336. try
  1337. {
  1338. if (!request.TryGetProperty("name", out JsonElement name)) return BadRequest();
  1339. if (!request.TryGetProperty("scope", out JsonElement _scope)) return BadRequest();
  1340. var client = _azureCosmos.GetCosmosClient();
  1341. List<string> prefixs = new List<string>() { "audio", "doc", "image", "other", "res", "video", "thum" };
  1342. var ContainerClient = _azureStorage.GetBlobContainerClient($"{name}");
  1343. string scope = "private";
  1344. scope = $"{_scope}";
  1345. var tb = "Teacher";
  1346. if (scope != "private")
  1347. {
  1348. tb = "School";
  1349. }
  1350. long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  1351. foreach (var prefix in prefixs)
  1352. {
  1353. List<string> items = await ContainerClient.List(prefix);
  1354. foreach (var item in items)
  1355. {
  1356. var urlsSize = await ContainerClient.GetBlobsSize(item);
  1357. 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 };
  1358. await client.GetContainer(Constant.TEAMModelOS, tb).UpsertItemAsync(bloblog, new Azure.Cosmos.PartitionKey(bloblog.code));
  1359. }
  1360. }
  1361. return new OkObjectResult(new { });
  1362. }
  1363. catch (Exception ex)
  1364. {
  1365. await _dingDing.SendBotMsg($"TEAMModelFunction,ActivityHttpTrigger,fix-blob-content()\n{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
  1366. return new BadRequestResult();
  1367. }
  1368. }
  1369. /// <summary>
  1370. ///
  1371. /// </summary>
  1372. /// <param name="request"></param>
  1373. /// <returns></returns>
  1374. [ProducesDefaultResponseType]
  1375. //[AuthToken(Roles = "teacher")]
  1376. [HttpPost("get-DownloadContent-item")]
  1377. public async Task<IActionResult> DownloadContentItem(JsonElement request)
  1378. {
  1379. ItemBlob itemBlob = null;
  1380. try
  1381. {
  1382. BlobDownloadInfo blobDownloadResult = await _azureStorage.GetBlobContainerClient($"hbcn").GetBlobClient($"/item/12b865c9-a223-278a-2be1-e336b9ead99e/12b865c9-a223-278a-2be1-e336b9ead99e.json")
  1383. .DownloadAsync();
  1384. if (blobDownloadResult != null)
  1385. {
  1386. var json = JsonDocument.Parse(blobDownloadResult.Content);
  1387. itemBlob = json.RootElement.ToObject<ItemBlob>();
  1388. }
  1389. }
  1390. catch (Exception ex)
  1391. {
  1392. itemBlob = null;
  1393. }
  1394. return Ok(new { itemBlob });
  1395. }
  1396. /// <summary>
  1397. ///
  1398. /// </summary>
  1399. /// <param name="request"></param>
  1400. /// <returns></returns>
  1401. [ProducesDefaultResponseType]
  1402. //[AuthToken(Roles = "teacher")]
  1403. [HttpPost("get-bind-data")]
  1404. public async Task<IActionResult> GetData(JsonElement request)
  1405. {
  1406. var areaId = request.GetProperty("areaId");
  1407. var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
  1408. List<ScTeacher> teachers = await table.FindListByDict<ScTeacher>(new Dictionary<string, object> { { "PartitionKey", "ScTeacher" }, { "areaId", $"{areaId}" } });
  1409. return Ok(teachers.Select(x => new { x.areaId, x.PXID, x.TID, x.TeacherName, x.tmdid, x.SchoolName, x.DisName }));
  1410. }
  1411. /// 删除
  1412. /// </summary>
  1413. /// <param name="request"></param>
  1414. /// <returns></returns>
  1415. [ProducesDefaultResponseType]
  1416. [AuthToken(Roles = "admin,teacher")]
  1417. [HttpPost("get-save-log")]
  1418. public async Task<IActionResult> SaveLog(JsonElement request)
  1419. {
  1420. BlobDownloadResult Recording = await _azureStorage.GetBlobContainerClient("1595321354").GetBlobClient($"records/271528531841781760/Record/.Recording.json").DownloadContentAsync();
  1421. var json = Recording.Content.ToString();
  1422. var jsonByte = Encoding.UTF8.GetBytes(json);
  1423. Stream stream = new MemoryStream(jsonByte);
  1424. var doc = JsonDocument.Parse(stream);
  1425. School school = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>("hbcn", new PartitionKey("Base"));
  1426. _ = _azureStorage.SaveLog("find-school", school.ToJsonString(), httpContext: HttpContext, dingDing: _dingDing, scope: "school");
  1427. return Ok(new { doc, school, });
  1428. }
  1429. /// <summary>
  1430. ///
  1431. /// </summary>
  1432. /// <param name="request"></param>
  1433. /// <returns></returns>
  1434. [ProducesDefaultResponseType]
  1435. //[AuthToken(Roles = "teacher")]
  1436. [HttpPost("get-ip")]
  1437. public async Task<IActionResult> GetIp(JsonElement request)
  1438. {
  1439. try
  1440. {
  1441. BlobDownloadResult baseblobDownload = await _azureStorage.GetBlobContainerClient("habook").GetBlobClient($"/records/299813002894381056/IES/Base.json").DownloadContentAsync();
  1442. LessonBase lessonBase = baseblobDownload.Content.ToObjectFromJson<LessonBase>();
  1443. return Ok(lessonBase);
  1444. }
  1445. catch (RequestFailedException ex) when (ex.Status == 404)
  1446. {
  1447. return BadRequest("文件不存在!");
  1448. }
  1449. LessonBase lessonBases = request.ToObject<LessonBase>();
  1450. //List<TmdInfo> tmds= request.ToObject<List<TmdInfo>>();
  1451. //var content = new StringContent(tmds.Select(x=>x.id).ToJsonString(), Encoding.UTF8, "application/json");
  1452. //string json = await _coreAPIHttpService.GetUserInfos(content);
  1453. //string _researchKey = Regex.Replace($"{request.GetProperty("key")}", "[ \\[ \\] \\^ \\-|()【】/' {}_*×――(^)$%~!@#$…&%¥—+=<>《》!!???::•`·、。,;,.;\"‘’“”-]", " ");
  1454. //string[] mm = Regex.Split(_researchKey, "\\s+", RegexOptions.IgnoreCase);
  1455. //var token = await CoreTokenExtensions.CreateAccessToken("c7317f88-7cea-4e48-ac57-a16071f7b884", "kguxh:V.PLmxBdaI@jnrTrDSth]A3346", "China");
  1456. //string ip = await _searcher.SearchIpAsync($"{request.GetProperty("ip")}");
  1457. // return Ok(new { activity, ip, token.AccessToken,token.TokenType,token.IdToken, mm });
  1458. return Ok(lessonBases);
  1459. }
  1460. /// 删除
  1461. /// </summary>
  1462. /// <param name="request"></param>
  1463. /// <returns></returns>
  1464. [ProducesDefaultResponseType]
  1465. [HttpPost("check-online-record")]
  1466. public async Task<IActionResult> CheckOnlinerecord(JsonElement request)
  1467. {
  1468. 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'";
  1469. List<IdNameCode> codes = new List<IdNameCode>();
  1470. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetItemQueryIterator<IdNameCode>(sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
  1471. {
  1472. codes.Add(item);
  1473. }
  1474. List<dynamic> data = new List<dynamic>(); ;
  1475. foreach (IdNameCode code in codes)
  1476. {
  1477. try
  1478. {
  1479. TeacherTrain train = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<TeacherTrain>(code.id, new PartitionKey($"TeacherTrain-{code.code}"));
  1480. data.Add(new { code.id, code.name, code.code, train.totalTime, train.onlineTime, train.classTime, train.offlineTime });
  1481. }
  1482. catch (Exception ex)
  1483. {
  1484. data.Add(new { code.id, code.name, code.code, totalTime = 0, onlineTime = 0, classTime = 0, offlineTime = 0 });
  1485. }
  1486. }
  1487. return Ok(new { data });
  1488. }
  1489. [HttpPost("test-scteacher")]
  1490. public async Task<IActionResult> TestScteacher(JsonElement json)
  1491. {
  1492. var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
  1493. List<ScTeacher> teachers = await table.FindListByDict<ScTeacher>(new Dictionary<string, object>() { { "PartitionKey", "ScTeacher" }, { "areaId", "e6fb5d40-bd85-7327-cea8-ea5c642836d2" }, { "SchoolName", "岳池县大佛初级中学校" } });
  1494. //var techs= teachers.Where(t => string.IsNullOrWhiteSpace(t.tmdid));
  1495. return Ok(teachers);
  1496. }
  1497. [HttpPost("get-token")]
  1498. public async Task<IActionResult> GetToken(JsonElement request)
  1499. {
  1500. if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
  1501. if (!request.TryGetProperty("host", out JsonElement host)) return BadRequest();
  1502. if (!request.TryGetProperty("name", out JsonElement name)) return BadRequest();
  1503. if (!request.TryGetProperty("picture", out JsonElement picture)) return BadRequest();
  1504. if (!request.TryGetProperty("areaId", out JsonElement areaId)) return BadRequest();
  1505. if (!request.TryGetProperty("school", out JsonElement school)) return BadRequest();
  1506. var auth_token = JwtAuthExtension.CreateAuthToken(host.ToString(), id.ToString(), name.ToString(),
  1507. picture.ToString(), _option.JwtSecretKey,
  1508. scope: "student", Website: "IES", areaId: areaId.ToString(),schoolID: school.ToString(), roles: new[] { "student" }, expire: 1);
  1509. //var techs= teachers.Where(t => string.IsNullOrWhiteSpace(t.tmdid));
  1510. return Ok(auth_token);
  1511. }
  1512. [HttpPost("test-scteacher-dn")]
  1513. public async Task<IActionResult> TestScteacherDn(JsonElement json)
  1514. {
  1515. var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
  1516. string sqls = "select distinct value(c.id )from c where c.code='Base' and IS_DEFINED(c.finalScore)=true ";
  1517. //https://teammodelos.blob.core.chinacloudapi.cn/teammodelos
  1518. //https://teammodelos.blob.core.chinacloudapi.cn/teammodelos/yxpt%2Fjinniu%2Fscbind%2F1647432004.json
  1519. List<ScTeacher> teachers = await table.FindListByDict<ScTeacher>(new Dictionary<string, object>() { { "PartitionKey", "ScTeacher" }, { "areaId", "870a5a6b-1ab3-461a-bdeb-baec19780ddb" } });
  1520. List<string> ids = new List<string>();
  1521. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher)
  1522. .GetItemQueryIterator<string>(sqls, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
  1523. {
  1524. ids.Add(item);
  1525. }
  1526. long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
  1527. List<string> erorr = new List<string>();
  1528. List<ScTeacher> teachersUp = new List<ScTeacher>();
  1529. foreach (var id in ids)
  1530. {
  1531. try
  1532. {
  1533. BlobDownloadResult baseblobDownload = await _azureStorage.GetBlobContainerClient("teammodelos").GetBlobClient($"/yxpt/jinniu/scbind/{id}.json").DownloadContentAsync();
  1534. ScBindData scBindData = baseblobDownload.Content.ToObjectFromJson<ScBindData>();
  1535. var tcd = teachers.Find(x => x.RowKey.Equals(scBindData.pxid));
  1536. if (tcd != null)
  1537. {
  1538. Teacher teacher = new Teacher
  1539. {
  1540. createTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
  1541. pk = "Base",
  1542. code = "Base",
  1543. id = id,
  1544. name = scBindData.username,
  1545. size = 2,
  1546. defaultSchool = tcd.schoolCode,
  1547. schools = new List<TeacherSchool> {
  1548. new TeacherSchool
  1549. {
  1550. schoolId = tcd.schoolCode, status = "join", time = now, name = scBindData.sn, areaId = tcd.areaId
  1551. }
  1552. },
  1553. binds = new List<ThirdBind> {
  1554. new ThirdBind
  1555. {
  1556. type= "scsyxpt",userid=scBindData.userid,username= scBindData.username,account=scBindData.account,data=new List<string>{ scBindData.ToJsonString()}
  1557. }
  1558. }
  1559. };
  1560. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).UpsertItemAsync(teacher, new PartitionKey("Base"));
  1561. tcd.tmdid = id;
  1562. teachersUp.Add(tcd);
  1563. }
  1564. }
  1565. catch (Exception)
  1566. {
  1567. erorr.Add(id);
  1568. }
  1569. }
  1570. await table.SaveOrUpdateAll(teachersUp);
  1571. return Ok();
  1572. }
  1573. [HttpPost("fix-jinniupujiang-teacher-videotime")]
  1574. public async Task<IActionResult> GetScteacher(JsonElement json)
  1575. {
  1576. if (!json.TryGetProperty("areaId", out JsonElement _areaId)) { return BadRequest(); }
  1577. Area area = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).ReadItemAsync<Area>($"{_areaId}", new PartitionKey("Base-Area"));
  1578. AreaSetting setting = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).ReadItemAsync<AreaSetting>($"{_areaId}", new PartitionKey("AreaSetting"));
  1579. List<string> teachers = new List<string>();
  1580. //获取这个区的教师 //psywgy
  1581. string schoolSql = $"SELECT value c.id FROM c join a in c.schools where a.areaId='{_areaId}' and c.code='Base' ";
  1582. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher)
  1583. .GetItemQueryIterator<string>(schoolSql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
  1584. {
  1585. teachers.Add(item);
  1586. }
  1587. //获取这些老师的研修记录
  1588. 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 ";
  1589. List<TeacherTrain> teacherTrains = new List<TeacherTrain>();
  1590. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher)
  1591. .GetItemQueryIterator<TeacherTrain>(tr, requestOptions: new QueryRequestOptions { }))
  1592. {
  1593. if (!item.tmdid.Equals("1528783259") || !item.tmdid.Equals("1530606136"))
  1594. {
  1595. teacherTrains.Add(item);
  1596. }
  1597. }
  1598. //获取这个区的能力点树状结构
  1599. string sql = $" select distinct value(b.id ) from c join b in c.children where c.code='AbilityTask-{area.standard}' ";
  1600. List<string> nodeIdsDB = new List<string>();
  1601. await foreach (var y in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).GetItemQueryIterator<string>
  1602. (sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"AbilityTask-{area.standard}") }))
  1603. {
  1604. nodeIdsDB.Add(y);
  1605. }
  1606. List<AbilitySub> abilitySubs = new List<AbilitySub>();
  1607. List<TeacherVideoTime> teacherVideoTimes = new List<TeacherVideoTime>();
  1608. string ids = teacherTrains.Select(x => x.id).ToJsonString();
  1609. string sqls = $" select value(c) from c where c.code='AbilityTask-{area.standard}'";
  1610. List<AbilityTask> abilityTasks = new List<AbilityTask>();
  1611. Dictionary<string, RecordFileAbility> valuePairs = new Dictionary<string, RecordFileAbility>();
  1612. await foreach (var y in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Normal).GetItemQueryIterator<AbilityTask>
  1613. (sqls, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"AbilityTask-{area.standard}") }))
  1614. {
  1615. abilityTasks.Add(y);
  1616. }
  1617. foreach (var item in teacherTrains)
  1618. {
  1619. List<TeacherAbility> teacherAbility = new List<TeacherAbility>();
  1620. if (item.currency.teacherAilities.Count() > 3)
  1621. {
  1622. //如果选择了大于三个能力点的教师,则优先获取上传了认证材料的的能力点,
  1623. var uploadHas = item.currency.teacherAilities.FindAll(x => x.uploadHas == 1 && x.videoTime < 300);
  1624. if (uploadHas.Any())
  1625. {
  1626. teacherAbility.AddRange(uploadHas);
  1627. }
  1628. if (teacherAbility.Count < 3)
  1629. {
  1630. // 如果仍然未满足数量。则再去获取 没有上传认证材料,但是又有学习时间长的能力点。
  1631. var hasVideoTime = item.currency.teacherAilities.FindAll(x => x.uploadHas != 1 && x.videoTime < 300).OrderByDescending(o => o.videoTime);
  1632. var disCount = 3 - teacherAbility.Count;
  1633. teacherAbility.AddRange(hasVideoTime.Take(disCount));
  1634. }
  1635. }
  1636. else
  1637. {
  1638. teacherAbility.AddRange(item.currency.teacherAilities.Where(ab => ab.videoTime < 300));
  1639. }
  1640. TeacherFile teacherFile = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<TeacherFile>(item.id, new PartitionKey($"TeacherFile-{item.code.Replace("TeacherTrain-", "")}"));
  1641. foreach (var ability in teacherAbility)
  1642. {
  1643. TeacherVideoTime teacherVideoTime = new TeacherVideoTime { code = item.code.Replace("TeacherTrain-", ""), id = item.id, abilityId = ability.id, no = ability.no, train_time = ability.videoTime };
  1644. double fileview = 0;
  1645. var filerecord = teacherFile.fileRecords.FindAll(x => x.files.Where(y => y.abilityId.Equals(ability.id)).Count() > 0);
  1646. filerecord.ForEach(x => {
  1647. var file = x.files.FindAll(y => y.abilityId.Equals($"{ability.id}"));
  1648. if (file.IsNotEmpty())
  1649. {
  1650. fileview += x.view;
  1651. }
  1652. });
  1653. double fminut = fileview / 60;
  1654. teacherVideoTime.files_time = fminut;
  1655. var tech = abilityTasks.FindAll(x => x.abilityId.Equals(ability.id));
  1656. // double limit = 0;
  1657. tech.ForEach(task =>
  1658. {
  1659. task.children.ForEach(y =>
  1660. {
  1661. y.rnodes.ForEach(r =>
  1662. {
  1663. if (valuePairs.ContainsKey(r.hash))
  1664. {
  1665. valuePairs.TryGetValue(r.hash, out var value);
  1666. var ablt = value.fileAbilities.Find(z => z.abilityId.Equals(task.abilityId) && z.taskId.Equals(task.id) && z.nodeId.Equals(y.id));
  1667. if (ablt == null)
  1668. {
  1669. value.fileAbilities.Add(new FileAbility { url = r.link, abilityId = task.abilityId, taskId = task.id, nodeId = y.id });
  1670. // limit = limit + r.duration;
  1671. }
  1672. }
  1673. else
  1674. {
  1675. valuePairs.Add(r.hash, new RecordFileAbility
  1676. {
  1677. fileRecord =
  1678. new FileRecord { hash = r.hash, size = r.size.Value, duration = r.duration, view = (int)r.duration, type = r.type, done = true },
  1679. fileAbilities = new List<FileAbility> { new FileAbility { url = r.link, abilityId = task.abilityId, taskId = task.id, nodeId = y.id } }
  1680. });
  1681. // limit = limit + r.duration;
  1682. }
  1683. });
  1684. });
  1685. });
  1686. HashSet<string> childIds = new HashSet<string>();
  1687. foreach (var ps in valuePairs)
  1688. {
  1689. HashSet<string> abilityIds = teacherFile.fileRecords.SelectMany(x => x.files).Select(x => x.abilityId).Where(abid => abid.Equals(ability.id)).ToHashSet();
  1690. double view = 0;
  1691. foreach (var abid in abilityIds)
  1692. {
  1693. var record = teacherFile.fileRecords.FindAll(x => x.files.Where(y => y.abilityId.Equals(abid)).Count() > 0);
  1694. record.ForEach(x => {
  1695. var file = x.files.FindAll(y => y.abilityId.Equals($"{abid}"));
  1696. if (file.IsNotEmpty())
  1697. {
  1698. view += x.view;
  1699. }
  1700. });
  1701. }
  1702. double minut = view / 60;
  1703. teacherVideoTime.after_time = minut;
  1704. if (minut < 300)
  1705. {
  1706. var fils = teacherFile.fileRecords.Find(x => x.hash.Equals(ps.Key));
  1707. if (fils != null)
  1708. {
  1709. ps.Value.fileAbilities.ForEach(x =>
  1710. {
  1711. var a = fils.files.Find(z => z.nodeId.Equals(x.nodeId) && z.abilityId.Equals(x.abilityId));
  1712. if (a == null)
  1713. {
  1714. childIds.Add(x.nodeId);
  1715. fils.files.Add(new FileAbility { url = x.url, abilityId = x.abilityId, taskId = x.taskId, nodeId = x.nodeId });
  1716. }
  1717. });
  1718. }
  1719. else
  1720. {
  1721. ps.Value.fileAbilities.ForEach(x =>
  1722. {
  1723. childIds.Add(x.nodeId);
  1724. });
  1725. teacherFile.fileRecords.Add(new FileRecord
  1726. {
  1727. hash = ps.Value.fileRecord.hash,
  1728. size = ps.Value.fileRecord.size,
  1729. duration = ps.Value.fileRecord.duration,
  1730. view = (int)ps.Value.fileRecord.view,
  1731. type = ps.Value.fileRecord.type,
  1732. done = true,
  1733. files = ps.Value.fileAbilities
  1734. });
  1735. }
  1736. }
  1737. else
  1738. {
  1739. break;
  1740. }
  1741. }
  1742. if (childIds.Any())
  1743. {
  1744. string code = teacherFile.code.Replace("TeacherFile-", "");
  1745. if (!string.IsNullOrWhiteSpace(code))
  1746. {
  1747. try
  1748. {
  1749. AbilitySub abilitySub = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<AbilitySub>(ability.id, new PartitionKey($"AbilitySub-{code}-{teacherFile.id}"));
  1750. var taskIds = abilitySub.taskRcds.Select(x => x.id);
  1751. var notin = childIds.Except(taskIds);
  1752. if (notin.Any())
  1753. {
  1754. abilitySub.taskRcds.AddRange(notin.Select(x => new AbilityTaskRcd { id = x, done = true }));
  1755. abilitySubs.Add(abilitySub);
  1756. }
  1757. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReplaceItemAsync(abilitySub, abilitySub.id, new PartitionKey($"AbilitySub-{code}-{teacherFile.id}"));
  1758. }
  1759. catch (Exception ex)
  1760. {
  1761. }
  1762. }
  1763. }
  1764. teacherVideoTimes.Add(teacherVideoTime);
  1765. }
  1766. teacherFile = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReplaceItemAsync<TeacherFile>(teacherFile, teacherFile.id, new PartitionKey(teacherFile.code));
  1767. item.update.Add(StatisticsService.TeacherAbility);
  1768. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReplaceItemAsync<TeacherTrain>(item, item.id, new PartitionKey(item.code));
  1769. }
  1770. var data = teacherVideoTimes.GroupBy(x => x.code).Select(x => new { x.Key, count = x.ToList().Count, list = x.ToList() }).OrderByDescending(x => x.count);
  1771. return Ok(new { data, abilitySubs });
  1772. }
  1773. public class TeacherVideoTime
  1774. {
  1775. public string code { get; set; }
  1776. public string id { get; set; }
  1777. public string abilityId { get; set; }
  1778. public string no { get; set; }
  1779. public double train_time { get; set; }
  1780. public double files_time { get; set; }
  1781. public double after_time { get; set; }
  1782. }
  1783. [HttpPost("get-teacher-video")]
  1784. public async Task<IActionResult> GetScteacherClassVideo(JsonElement json)
  1785. {
  1786. 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 ";
  1787. List<IdNameCode> idNameCodes = new List<IdNameCode>();
  1788. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).GetItemQueryIterator<IdNameCode>(sql, requestOptions: new QueryRequestOptions { }))
  1789. {
  1790. idNameCodes.Add(item);
  1791. }
  1792. foreach (var item in idNameCodes)
  1793. {
  1794. try
  1795. {
  1796. TeacherTrain teacherTrain = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReadItemAsync<TeacherTrain>(item.id, new PartitionKey($"TeacherTrain-{item.code}"));
  1797. if (!teacherTrain.teacherClasses.Any())
  1798. {
  1799. teacherTrain.update.Add("TeacherClass");
  1800. await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).ReplaceItemAsync<TeacherTrain>(teacherTrain, teacherTrain.id, new PartitionKey($"TeacherTrain-{item.code}"));
  1801. }
  1802. }
  1803. catch (Exception ex)
  1804. {
  1805. continue;
  1806. }
  1807. }
  1808. return Ok();
  1809. }
  1810. [HttpPost("test-batch")]
  1811. public async Task<IActionResult> TestBatchFUN(JsonElement json)
  1812. {
  1813. List<Task<ItemResponse<TestBatch>>> nameCodes = new List<Task<ItemResponse<TestBatch>>>();
  1814. for (int i = 0; i < 10; i++)
  1815. {
  1816. nameCodes.Add(_azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Student).
  1817. CreateItemAsync(new TestController.TestBatch { id = Guid.NewGuid().ToString(), code = $"TestBatch-{i}", pk = "TestBatch" }, new PartitionKey($"TestBatch-{i}")));
  1818. }
  1819. await Task.WhenAll(nameCodes);
  1820. return Ok();
  1821. }
  1822. public class TestBatch : CosmosEntity
  1823. {
  1824. }
  1825. [HttpPost("export-teacher")]
  1826. public async Task<IActionResult> ExportTeacher(JsonElement json)
  1827. {
  1828. List<string> schools = new()
  1829. {
  1830. "dghznx",
  1831. "cxhhlx",
  1832. "xjaxx",
  1833. "zjqxx",
  1834. "xnygxx",
  1835. "lxxcfx",
  1836. "gxjrxx",
  1837. "cdgxsx",
  1838. "yzxx",
  1839. "kjyxx",
  1840. "wjylxx",
  1841. "dsgjxx",
  1842. "ydzt",
  1843. "xndbxx",
  1844. "sqtszx",
  1845. "cdxczx",
  1846. "ghsyzx",
  1847. "lqsx",
  1848. "cdxxps",
  1849. "xcfx",
  1850. "xyqxx",
  1851. "xncbyy",
  1852. "cdlqjk",
  1853. "lqdmxx",
  1854. "lqyx",
  1855. "pclxxx",
  1856. "cdfzx",
  1857. "xnblxx",
  1858. "ghsx",
  1859. "khdycz",
  1860. "khbmxx",
  1861. "khdecz",
  1862. "khzx",
  1863. "khhbzx",
  1864. "gxxcxx",
  1865. "khhtxx",
  1866. "khdxxx",
  1867. "khsyxx"
  1868. };
  1869. var cosmosClient = _azureCosmos.GetCosmosClient();
  1870. foreach (var item in schools)
  1871. {
  1872. School school = await cosmosClient.GetContainer("TEAMModelOS", "School").ReadItemAsync<School>($"{item}", new PartitionKey("Base"));
  1873. List<Teacher> teachers = new();
  1874. await foreach (var tch in cosmosClient.GetContainer("TEAMModelOS", "Teacher").GetItemQueryIterator<Teacher>(queryText:
  1875. $"SELECT value(c) FROM c join s in c.schools where s.schoolId='{item}' and c.code='Base'",
  1876. requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
  1877. {
  1878. teachers.Add(tch);
  1879. }
  1880. if (teachers.Count > 0)
  1881. {
  1882. foreach (var teacher in teachers)
  1883. {
  1884. teacher.schools.ForEach(tch => { if (tch.schoolId.Equals(item)) { tch.areaId = school.areaId; } });
  1885. await cosmosClient.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey("Base"));
  1886. }
  1887. }
  1888. }
  1889. return Ok();
  1890. }
  1891. public class RecordFileAbility
  1892. {
  1893. public FileRecord fileRecord { get; set; }
  1894. public List<FileAbility> fileAbilities { get; set; }
  1895. }
  1896. [HttpPost("test-blob-folder")]
  1897. public async Task<IActionResult> TestBlobFolder(JsonElement json)
  1898. {
  1899. string location = _option.Location;
  1900. bool lockKey = await _azureRedis.GetRedisClient(8).KeyExistsAsync($"LessonRecord:Unused:Lock:{location}");
  1901. //key不存在的时候 。
  1902. if (!lockKey)
  1903. {
  1904. var schoolKeys = new List<IdCodeCount>();
  1905. var teacherKeys = new List<IdCodeCount>();
  1906. string sql = "select value c.id from c where c.code='Base'";
  1907. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).
  1908. GetItemQueryIterator<string>(queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
  1909. {
  1910. teacherKeys.Add(new IdCodeCount { id = item, code = "Teacher" });
  1911. }
  1912. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).
  1913. GetItemQueryIterator<string>(queryText: sql, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey("Base") }))
  1914. {
  1915. schoolKeys.Add(new IdCodeCount { id = item, code = "School" });
  1916. }
  1917. string sqlcount = "select value count(1) from c where c.pk='LessonRecord'";
  1918. foreach (var key in schoolKeys)
  1919. {
  1920. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).
  1921. GetItemQueryIterator<int>(queryText: sqlcount, requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"LessonRecord-{key.id}") }))
  1922. {
  1923. key.count = item;
  1924. break;
  1925. }
  1926. }
  1927. foreach (var key in teacherKeys)
  1928. {
  1929. await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.Teacher).
  1930. GetItemQueryIterator<int>(queryText: $"select value count(1) from c where c.pk='LessonRecord' and c.tmdid='{key.id}'",
  1931. requestOptions: new QueryRequestOptions { PartitionKey = new PartitionKey($"LessonRecord") }))
  1932. {
  1933. key.count = item;
  1934. break;
  1935. }
  1936. }
  1937. schoolKeys.AddRange(teacherKeys);
  1938. //以下代码作用,用于根据当前拥有的课例数判断区分学校和个人使用课例频率越多的,
  1939. //并均分每次需要处理的学校和个人容器个数,避免每次处理批次花费时间相差太大。
  1940. //将每个批次处理数量级控制在500-1000左右。
  1941. List<IEnumerable<IdCodeCount>> counts = new List<IEnumerable<IdCodeCount>>();
  1942. //501-∞
  1943. var count501_ = schoolKeys.Where(x => x.count >= 501); //至少500条
  1944. counts.AddRange(count501_.Page(1));//1个学校
  1945. //201-500
  1946. var count201_500 = schoolKeys.Where(x => x.count >= 201 && x.count <= 500); //至少402条-1000条
  1947. counts.AddRange(count201_500.Page(2));//2个学校
  1948. //100-200
  1949. var count100_200 = schoolKeys.Where(x => x.count >= 100 && x.count <= 200);//至少500条-1000条
  1950. counts.AddRange(count100_200.Page(5));//5个学校
  1951. //51-99
  1952. var count51_99 = schoolKeys.Where(x => x.count >= 51 && x.count <= 99);//至少500条-990条
  1953. counts.AddRange(count51_99.Page(10));//10个学校
  1954. //21-50
  1955. var count21_50 = schoolKeys.Where(x => x.count >= 21 && x.count <= 50);//至少410条-1000条
  1956. counts.AddRange(count21_50.Page(20));//20个学校
  1957. //10-20
  1958. var count10_20 = schoolKeys.Where(x => x.count >= 10 && x.count <= 20);//至少500条-1000条
  1959. counts.AddRange(count10_20.Page(50));//50个学校
  1960. //5-9
  1961. var count0_9 = schoolKeys.Where(x => x.count >= 5 && x.count <= 9);//至少500条-900条
  1962. counts.AddRange(count0_9.Page(100));//100个学校
  1963. //2-4
  1964. var count2_4 = schoolKeys.Where(x => x.count >= 2 && x.count <= 4);//至少500条-1000条
  1965. counts.AddRange(count2_4.Page(250));
  1966. //0-1
  1967. var count0_1 = schoolKeys.Where(x => x.count >= 0 && x.count <= 1);//至少500,就算没有课例也算一次。
  1968. counts.AddRange(count0_1.Page(500));
  1969. int field = 1;
  1970. counts.Count();
  1971. foreach (var item in counts)
  1972. {
  1973. bool stuallstatus = await _azureRedis.GetRedisClient(8).HashSetAsync($"LessonRecord:Unused:Lock:{location}", field, new { status = 0, item }.ToJsonString());
  1974. field += 1;
  1975. }
  1976. await _dingDing.SendBotMsg($"{location},获取到:{schoolKeys.Count} 个学校和个人的容器\n" +
  1977. $"大概要处理:{schoolKeys.Sum(x => x.count) + schoolKeys.Where(x => x.count >= 0).Count()} 条数据\n" +
  1978. $"将数据分为:{field - 1} 次处理,每次处理500-1000条数据。", GroupNames.醍摩豆服務運維群組);
  1979. }
  1980. return Ok(new { });
  1981. }
  1982. public class IdCodeCount
  1983. {
  1984. public string id { get; set; }
  1985. public string code { get; set; }
  1986. public int count { get; set; }
  1987. }
  1988. /// <summary>
  1989. /// 随机获取三个不同类型的题目
  1990. /// </summary>
  1991. /// <param name="request"></param>
  1992. /// <returns></returns>
  1993. [HttpPost("gen-pdf")]
  1994. //[Authorize(Roles = Constant.Role_Root)]
  1995. public IActionResult GenPdf(JsonElement json)
  1996. {
  1997. //https://article.itxueyuan.com/JAxOnG
  1998. //http://t.zoukankan.com/hsiang-p-14608694.html
  1999. //https://github.com/rdvojmoc/DinkToPdf
  2000. //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
  2001. var html = @"
  2002. <!DOCTYPE html>
  2003. <html>
  2004. <head>
  2005. <meta charset=""UTF-8"">
  2006. <meta http-equiv=""X-UA-Compatible"" content=""IE=edge"">
  2007. <meta name=""viewport"" content=""width=device-width, initial-scale=1.0"">
  2008. <title>校本研修活动完成情况</title>
  2009. <style>
  2010. body {
  2011. font-family: ""fangsong"";
  2012. display: flex;
  2013. flex-direction: column;
  2014. align-items: center;
  2015. }
  2016. .tch-table,
  2017. .details-table {
  2018. width: 100%;
  2019. }
  2020. .tch-table table {
  2021. width: 100%;
  2022. margin: 15px 0;
  2023. border: 0;
  2024. }
  2025. .tch-table th {
  2026. background-color: #c5c5c5;
  2027. color: #222222;
  2028. }
  2029. .tch-table,
  2030. .tch-table th,
  2031. .tch-table td {
  2032. font-size: 0.95em;
  2033. text-align: center;
  2034. padding: 4px;
  2035. border-collapse: collapse;
  2036. font-weight: bolder;
  2037. }
  2038. .tch-table th,
  2039. .tch-table td {
  2040. border-bottom: 1px solid #918b8c;
  2041. border-width: 1px 0 1px 0;
  2042. }
  2043. .tch-table tr {
  2044. border: 1px solid #ffffff;
  2045. height: 3.2em;
  2046. }
  2047. .title {
  2048. font-weight: bold;
  2049. align-self: flex-start;
  2050. margin: 30px 5px;
  2051. }
  2052. .title::before {
  2053. content: """";
  2054. width: 10px;
  2055. height: 10px;
  2056. background: #3a3a3a;
  2057. display: inline-block;
  2058. margin-right: 10px;
  2059. }
  2060. </style>
  2061. </head>
  2062. <body>
  2063. <h1 style=""text-align:center;font-weight: bold;"">校本研修活动完成情况</h1>
  2064. <p class=""title"">教师信息</p>
  2065. <table class=""tch-table"" id=""tchTable"">
  2066. <tr>
  2067. <th style=""width: 33.3%;"">教师姓名</th>
  2068. <th style=""width: 33.3%;"">机构</th>
  2069. <th style=""width: 33.3%;"">教研组</th>
  2070. </tr>
  2071. <tr>
  2072. <td>张三</td>
  2073. <td>四川省成都市盐道街中学</td>
  2074. <td>高中政治教研组</td>
  2075. </tr>
  2076. </table>
  2077. <p class=""title"">活动明细</p>
  2078. <table class=""tch-table"" id=""acTable"">
  2079. <tr>
  2080. <th style=""width: 25%;"">活动主题</th>
  2081. <th style=""width: 15%;"">活动类型</th>
  2082. <th style=""width: 5%;"">任务学时</th>
  2083. <th style=""width: 5%;"">完成学时</th>
  2084. <th style=""width: 20%;"">活动时间</th>
  2085. <th style=""width: 10%;"">活动内容</th>
  2086. <th style=""width: 10%;"">活动任务</th>
  2087. <th style=""width: 10%;"">状态</th>
  2088. </tr>
  2089. <tr>
  2090. <td>语文学科如何在A1技术支持下进行学情分析</td>
  2091. <td>信息化教学案例展示与分享</td>
  2092. <td>1</td>
  2093. <td>1</td>
  2094. <td>2022-04-07 到 2022-04-14</td>
  2095. <td></td>
  2096. <td>扫码签到、作业提交、问卷反馈、评测活动</td>
  2097. <td>已完成</td>
  2098. </tr>
  2099. </table>
  2100. </body>
  2101. </html>
  2102. ";
  2103. try
  2104. {
  2105. GlobalSettings globalSettings = new GlobalSettings();
  2106. globalSettings.ColorMode = ColorMode.Color;
  2107. globalSettings.Orientation = Orientation.Portrait;
  2108. globalSettings.PaperSize = PaperKind.A4;
  2109. globalSettings.Margins = new MarginSettings { Top = 25, Bottom = 25 };
  2110. ObjectSettings objectSettings = new ObjectSettings();
  2111. objectSettings.PagesCount = true;
  2112. objectSettings.HtmlContent = html;
  2113. //WebSettings webSettings = new WebSettings();
  2114. //webSettings.DefaultEncoding = "utf-8";
  2115. HeaderSettings headerSettings = new HeaderSettings();
  2116. headerSettings.FontSize = 15;
  2117. headerSettings.FontName = "fangsong";
  2118. headerSettings.Right = "";
  2119. // headerSettings.Line = true;
  2120. FooterSettings footerSettings = new FooterSettings();
  2121. footerSettings.FontSize = 12;
  2122. footerSettings.FontName = "Ariel";
  2123. footerSettings.Center = "校本研修活动完成情况([page]/[toPage])页";
  2124. // footerSettings.Line = true;
  2125. objectSettings.HeaderSettings = headerSettings;
  2126. objectSettings.FooterSettings = footerSettings;
  2127. //objectSettings.WebSettings = webSettings;
  2128. HtmlToPdfDocument htmlToPdfDocument = new HtmlToPdfDocument()
  2129. {
  2130. GlobalSettings = globalSettings,
  2131. Objects = { objectSettings },
  2132. };
  2133. var a = _converter.Convert(htmlToPdfDocument);
  2134. MemoryStream m = new MemoryStream(a);
  2135. FileStream fs = new FileStream("F:\\1111111111111\\SimplePdf1.pdf", FileMode.Create, FileAccess.Write, FileShare.Read);
  2136. m.WriteTo(fs);
  2137. m.Close();
  2138. fs.Close();
  2139. var doc = new HtmlToPdfDocument()
  2140. {
  2141. GlobalSettings = {
  2142. ColorMode = ColorMode.Color,
  2143. Orientation = Orientation.Portrait,
  2144. PaperSize = PaperKind.A4,
  2145. Margins = new MarginSettings() { Top = 10 },
  2146. Out = @"F:\test.pdf",
  2147. },
  2148. Objects = {
  2149. new ObjectSettings()
  2150. {
  2151. Page = "https://teammodelos.blob.core.chinacloudapi.cn/0-public/pie-borderRadius.html",
  2152. },
  2153. }
  2154. };
  2155. _converter.Convert(doc);
  2156. return Ok();
  2157. // return Ok(File(a, "application/octet-stream", "SimplePdf.pdf"));
  2158. }
  2159. catch (Exception ex)
  2160. {
  2161. return BadRequest(new { ex = ex.StackTrace, exmsg = ex.Message });
  2162. }
  2163. }
  2164. }
  2165. }